pinctrl: mediatek: Fixes and minor improvements
Subsystems (4)
v2 cover pinctrl: mediatek: Fixes and minor improvements
Hi everyone,
Here are some fixes and minor improvements to generic pinconf and the Mediatek Paris pinctrl driver.
Changes since v1:
- Correct PIN_CONFIG_BIAS_* read back for all cases
- Add patch 7 that reworks switch/case logic to make the code in mtk_pinconf_{get,set} cleaner
- Handle case where PIN_CONFIG_DRIVE_STRENGTH_UA is not given and the advanced mode needs to be disabled
- Also make the vendor specific MTK_PIN_CONFIG_DRV_ADV config override PIN_CONFIG_DRIVE_STRENGTH_UA (or lack of) if the former is present.
Patch 1 makes the generic pinconf library print out arguments for PIN_CONFIG_BIAS_PULL_* in debugfs.
Patch 2 fixes bogus readback of PIN_CONFIG_BIAS_DISABLE being always present.
Patch 3 fixes the type of the "argument" argument in mtk_pinconf_get(). This was erroneously typed as an enum when it should have been u32.
Patch 4 fixes the pingroup config state readback to actually do readback.
Patch 5 drops an extra newline in the pinconf debugfs output.
Patch 6 cleans up the debugfs output, skipping the custom hardware state output on the virtual GPIOs, which have no corresponding hardware.
Patch 7 inverts the switch/case logic in mtk_pinconf_{get,set}() so the code has a default error code, breaks out on error, and has the indentation reduced.
Patch 8 adds support for PIN_CONFIG_DRIVE_STRENGTH_UA (drive-strength-uA) to the Mediatek Paris pinctrl library. The goal is to replace the vendor specific "mtk,drive-strength-adv" property with the generic one.
Patches 9 through 11 are from Angelo [1], rebased onto next-20220308.
Later on we might want to deprecate "mtk,drive-strength-adv".
Please have a look.
Regards
ChenYu
[1] https://lore.kernel.org/linux-gpio/[email protected]/
AngeloGioacchino Del Regno (3):
pinctrl: mediatek: pinctrl-moore: Simplify with dev_err_probe()
pinctrl: mediatek: pinctrl-paris: Simplify with dev_err_probe()
pinctrl: mediatek: pinctrl-mtk-common: Simplify with dev_err_probe()
Chen-Yu Tsai (8):
pinctrl: pinconf-generic: Print arguments for bias-pull-*
pinctrl: mediatek: paris: Fix PIN_CONFIG_BIAS_* readback
pinctrl: mediatek: paris: Fix "argument" argument type for
mtk_pinconf_get()
pinctrl: mediatek: paris: Fix pingroup pin config state readback
pinctrl: mediatek: paris: Drop extra newline in
mtk_pctrl_show_one_pin()
pinctrl: mediatek: paris: Skip custom extra pin config dump for
virtual GPIOs
pinctrl: mediatek: paris: Rework mtk_pinconf_{get,set} switch/case
logic
pinctrl: mediatek: paris: Support generic PIN_CONFIG_DRIVE_STRENGTH_UA
drivers/pinctrl/mediatek/pinctrl-moore.c | 25 +- drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 25 +- drivers/pinctrl/mediatek/pinctrl-paris.c | 290 +++++++++++------- drivers/pinctrl/pinconf-generic.c | 6 +- 4 files changed, 200 insertions(+), 146 deletions(-)
Signature · 1 line
2.35.1.616.g0bdcbb4464-goog
PATCH v2 1/11 pinctrl: pinconf-generic: Print arguments for bias-pull-*
The bias-pull-* properties, or PIN_CONFIG_BIAS_PULL_* pin config parameters, accept optional arguments in ohms denoting the strength of the pin bias.
Print these values out in debugfs as well.
--- drivers/pinctrl/pinconf-generic.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/pinctrl/pinconf-generic.c +3 -3
@@ -30,10 +30,10 @@ static const struct pin_config_item conf_items[] = {PCONFDUMP (PIN_CONFIG_BIAS_BUS_HOLD ,"input bias bus hold" ,NULL , false),PCONFDUMP (PIN_CONFIG_BIAS_DISABLE ,"input bias disabled" ,NULL , false),PCONFDUMP (PIN_CONFIG_BIAS_HIGH_IMPEDANCE ,"input bias high impedance" ,NULL , false), -PCONFDUMP (PIN_CONFIG_BIAS_PULL_DOWN ,"input bias pull down" ,NULL , false), +PCONFDUMP (PIN_CONFIG_BIAS_PULL_DOWN ,"input bias pull down" ,"ohms" , true),PCONFDUMP (PIN_CONFIG_BIAS_PULL_PIN_DEFAULT , -"input bias pull to pin specific state" ,NULL , false), -PCONFDUMP (PIN_CONFIG_BIAS_PULL_UP ,"input bias pull up" ,NULL , false), +"input bias pull to pin specific state" ,"ohms" , true), +PCONFDUMP (PIN_CONFIG_BIAS_PULL_UP ,"input bias pull up" ,"ohms" , true),PCONFDUMP (PIN_CONFIG_DRIVE_OPEN_DRAIN ,"output drive open drain" ,NULL , false),PCONFDUMP (PIN_CONFIG_DRIVE_OPEN_SOURCE ,"output drive open source" ,NULL , false), PCONFDUMP(PIN_CONFIG_DRIVE_PUSH_PULL, "output drive push pull", NULL, false),
Signature · 1 line
2.35.1.616.g0bdcbb4464-goog
PATCH v2 2/11 pinctrl: mediatek: paris: Fix PIN_CONFIG_BIAS_* readback
In reply to Chen-Yu TsaiWhen reading back pin bias settings, if the pin is not in the corresponding bias state, the function should return -EINVAL.
Fix this in the mediatek-paris pinctrl library so that the read back state is not littered with bogus a "input bias disabled" combined with "pull up" or "pull down" states.
--- drivers/pinctrl/mediatek/pinctrl-paris.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
drivers/pinctrl/mediatek/pinctrl-paris.c +6 -10
@@ -96,20 +96,16 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev, err = hw->soc->bias_get_combo (hw, desc, &pullup, &ret);if (err) goto out; +if (ret ==MTK_PUPD_SET_R1R0_00 ) + ret =MTK_DISABLE ;if (param ==PIN_CONFIG_BIAS_DISABLE ) { -if (ret ==MTK_PUPD_SET_R1R0_00 ) - ret =MTK_DISABLE ; +if (ret !=MTK_DISABLE ) + err = -EINVAL ; }else if (param ==PIN_CONFIG_BIAS_PULL_UP ) { -/* When desire to get pull-up value, return -* error if current setting is pull-down -*/ -if (!pullup) +if (!pullup || ret ==MTK_DISABLE ) err = -EINVAL ; }else if (param ==PIN_CONFIG_BIAS_PULL_DOWN ) { -/* When desire to get pull-down value, return -* error if current setting is pull-up -*/ -if (pullup) +if (pullup || ret ==MTK_DISABLE ) err = -EINVAL ; } }else {
Signature · 1 line
2.35.1.616.g0bdcbb4464-goog
Re: [PATCH v2 02/11] pinctrl: mediatek: paris: Fix PIN_CONFIG_BIAS_* readback
Il 08/03/22 11:09, Chen-Yu Tsai ha scritto:
Quoted 9 lines
When reading back pin bias settings, if the pin is not in the corresponding bias state, the function should return
-EINVAL.Fix this in the mediatek-paris pinctrl library so that the read back state is not littered with bogus a "input bias disabled" combined with "pull up" or "pull down" states.
Fixes 805250982bb5 ("pinctrl: mediatek: add pinctrl-paris that implements the vendor dt-bindings")Signed-off-by Chen-Yu Tsai <[email protected]>
Quoted 35 lines
--- drivers/pinctrl/mediatek/pinctrl-paris.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)drivers/pinctrl/mediatek/pinctrl-paris.c +6
-10@@ -96,20 +96,16 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev, err = hw->soc->bias_get_combo (hw, desc, &pullup, &ret);if (err) goto out; +if (ret ==MTK_PUPD_SET_R1R0_00 ) + ret =MTK_DISABLE ;if (param ==PIN_CONFIG_BIAS_DISABLE ) { -if (ret ==MTK_PUPD_SET_R1R0_00 ) - ret =MTK_DISABLE ; +if (ret !=MTK_DISABLE ) + err = -EINVAL ; }else if (param ==PIN_CONFIG_BIAS_PULL_UP ) { -/* When desire to get pull-up value, return -* error if current setting is pull-down -*/ -if (!pullup) +if (!pullup || ret ==MTK_DISABLE ) err = -EINVAL ; }else if (param ==PIN_CONFIG_BIAS_PULL_DOWN ) { -/* When desire to get pull-down value, return -* error if current setting is pull-up -*/ -if (pullup) +if (pullup || ret ==MTK_DISABLE ) err = -EINVAL ; } }else {
PATCH v2 3/11 pinctrl: mediatek: paris: Fix "argument" argument type for mtk_pinconf_get()
In reply to Chen-Yu TsaiFor mtk_pinconf_get(), the "argument" argument is typically returned by pinconf_to_config_argument(), which holds the value for a given pinconf parameter. It certainly should not have the type of "enum pin_config_param", which describes the type of the pinconf parameter itself.
Change the type to u32, which matches the return type of pinconf_to_config_argument().
--- drivers/pinctrl/mediatek/pinctrl-paris.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/pinctrl/mediatek/pinctrl-paris.c +1 -2
@@ -184,8 +184,7 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev, }static int mtk_pinconf_set (struct pinctrl_dev *pctldev,unsigned int pin, -enum pin_config_param param, -enum pin_config_param arg) +enum pin_config_param param,u32 arg) {struct mtk_pinctrl *hw =pinctrl_dev_get_drvdata (pctldev);const struct mtk_pin_desc *desc;
Signature · 1 line
2.35.1.616.g0bdcbb4464-goog
PATCH v2 4/11 pinctrl: mediatek: paris: Fix pingroup pin config state readback
In reply to Chen-Yu Tsaimtk_pconf_group_get(), used to read back pingroup pin config state, simply returns a set of configs saved from a previous invocation of mtk_pconf_group_set(). This is an unfiltered, unvalidated set passed in from the pinconf core, which does not match the current hardware state.
Since the driver library is designed to have one pin per group, pass through mtk_pconf_group_get() to mtk_pinconf_get(), to read back the current pin config state of the only pin in the group.
Also drop the assignment of pin config state to the group.
--- drivers/pinctrl/mediatek/pinctrl-paris.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/pinctrl/mediatek/pinctrl-paris.c +3 -5
@@ -732,10 +732,10 @@ static int mtk_pconf_group_get(struct pinctrl_dev *pctldev, unsigned group, unsigned long *config) {struct mtk_pinctrl *hw =pinctrl_dev_get_drvdata (pctldev); +struct mtk_pinctrl_group *grp = &hw->groups[group]; - *config = hw->groups[group].config; - -return 0 ; +/* One pin per group only */ +return mtk_pinconf_get (pctldev, grp->pin, config); } static int mtk_pconf_group_set(struct pinctrl_dev *pctldev, unsigned group,
@@ -751,8 +751,6 @@ static int mtk_pconf_group_set(struct pinctrl_dev *pctldev, unsigned group, pinconf_to_config_argument(configs[i]));if (ret <0 )return ret; - - grp->config = configs[i]; }return 0 ;
Signature · 1 line
2.35.1.616.g0bdcbb4464-goog
PATCH v2 5/11 pinctrl: mediatek: paris: Drop extra newline in mtk_pctrl_show_one_pin()
In reply to Chen-Yu TsaiThe caller of mtk_pctrl_show_one_pin() is responsible for printing the full line. mtk_pctrl_show_one_pin(), called through mtk_pctrl_dbg_show(), should only produce a string containing the extra information the driver wants included.
Drop the extra newlines. Also unbreak the line that is only slightly over 80 characters to make it easier on the eye, and get rid of the braces now that each block in the conditionals is just one line.
--- drivers/pinctrl/mediatek/pinctrl-paris.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/pinctrl/mediatek/pinctrl-paris.c +4 -8
@@ -634,14 +634,10 @@ ssize_t mtk_pctrl_show_one_pin(struct mtk_pinctrl *hw, pullen, pullup); -if (r1 !=-1 ) { - len +=scnprintf (buf + len, buf_len - len," (%1d %1d)\n" , - r1, r0); - }else if (rsel !=-1 ) { - len +=scnprintf (buf + len, buf_len - len," (%1d)\n" , rsel); - }else { - len +=scnprintf (buf + len, buf_len - len,"\n" ); - } +if (r1 !=-1 ) + len +=scnprintf (buf + len, buf_len - len," (%1d %1d)" , r1, r0); +else if (rsel !=-1 ) + len +=scnprintf (buf + len, buf_len - len," (%1d)" , rsel);return len; }
Signature · 1 line
2.35.1.616.g0bdcbb4464-goog
Re: [PATCH v2 05/11] pinctrl: mediatek: paris: Drop extra newline in mtk_pctrl_show_one_pin()
Quoted 4 lines · Chen-Yu Tsai
The caller of
mtk_pctrl_show_one_pin()is responsible for printing the full line.mtk_pctrl_show_one_pin(), called throughmtk_pctrl_dbg_show(), should only produce a string containing the extra information the driver wants included.
Does this function have another caller?
It looks as if this function doesn't need to be EXPORT_SYMBOL_GPL and could just be declared static in the file instead.
btw: using %1d is mostly senseless as a control, but has some
documentary use as a value < 0 or >= 10 will be always be fully emitted anyway.
drivers/pinctrl/mediatek/pinctrl-paris.c
Quoted 1 line
drivers/pinctrl/mediatek/pinctrl-paris.c +0
-0
[]
Quoted 19 lines
drivers/pinctrl/mediatek/pinctrl-paris.c +4
-8@@ -634,14 +634,10 @@ ssize_t mtk_pctrl_show_one_pin(struct mtk_pinctrl *hw, pullen, pullup); -if (r1 !=-1 ) { - len +=scnprintf (buf + len, buf_len - len," (%1d %1d)\n" , - r1, r0); - }else if (rsel !=-1 ) { - len +=scnprintf (buf + len, buf_len - len," (%1d)\n" , rsel); - }else { - len +=scnprintf (buf + len, buf_len - len,"\n" ); - } +if (r1 !=-1 ) + len +=scnprintf (buf + len, buf_len - len," (%1d %1d)" , r1, r0); +else if (rsel !=-1 ) + len +=scnprintf (buf + len, buf_len - len," (%1d)" , rsel);return len; }
Re: [PATCH v2 05/11] pinctrl: mediatek: paris: Drop extra newline in mtk_pctrl_show_one_pin()
Quoted 11 lines · Joe Perches
Quoted 4 lines · Chen-Yu Tsai
The caller of
mtk_pctrl_show_one_pin()is responsible for printing the full line.mtk_pctrl_show_one_pin(), called throughmtk_pctrl_dbg_show(), should only produce a string containing the extra information the driver wants included.Does this function have another caller?
It looks as if this function doesn't need to be
EXPORT_SYMBOL_GPLand could just be declared static in the file instead.
Judging from the commit history, I suspect there might have been plans for using this in another module?
I can do a patch to make it static until that ever happens.
Quoted 3 lines
btw: using %1d is mostly senseless as a control, but has some
documentary use as a value < 0 or >= 10 will be always be fully emitted anyway.
Ack. But we could just leave it be.
Regards
ChenYu
Quoted 23 lines
drivers/pinctrl/mediatek/pinctrl-paris.c
Quoted 1 line
drivers/pinctrl/mediatek/pinctrl-paris.c +0
-0[]
Quoted 19 lines
drivers/pinctrl/mediatek/pinctrl-paris.c +4
-8@@ -634,14 +634,10 @@ ssize_t mtk_pctrl_show_one_pin(struct mtk_pinctrl *hw, pullen, pullup); -if (r1 !=-1 ) { - len +=scnprintf (buf + len, buf_len - len," (%1d %1d)\n" , - r1, r0); - }else if (rsel !=-1 ) { - len +=scnprintf (buf + len, buf_len - len," (%1d)\n" , rsel); - }else { - len +=scnprintf (buf + len, buf_len - len,"\n" ); - } +if (r1 !=-1 ) + len +=scnprintf (buf + len, buf_len - len," (%1d %1d)" , r1, r0); +else if (rsel !=-1 ) + len +=scnprintf (buf + len, buf_len - len," (%1d)" , rsel);return len; }
PATCH v2 6/11 pinctrl: mediatek: paris: Skip custom extra pin config dump for virtual GPIOs
In reply to Chen-Yu TsaiVirtual GPIOs do not have any hardware state associated with them. Any attempt to read back hardware state for these pins result in error codes.
Skip dumping extra pin config information for these virtual GPIOs.
--- drivers/pinctrl/mediatek/pinctrl-paris.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/pinctrl/mediatek/pinctrl-paris.c +3 -0
@@ -581,6 +581,9 @@ ssize_t mtk_pctrl_show_one_pin(struct mtk_pinctrl *hw,if (gpio >= hw->soc->npins)return -EINVAL ; +if (mtk_is_virt_gpio (hw, gpio)) +return -EINVAL ; + desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio]; pinmux =mtk_pctrl_get_pinmux (hw, gpio);if (pinmux >= hw->soc->nfuncs)
Signature · 1 line
2.35.1.616.g0bdcbb4464-goog
PATCH v2 7/11 pinctrl: mediatek: paris: Rework mtk_pinconf_{get,set} switch/case logic
In reply to Chen-Yu TsaiThe current code deals with optional features by testing for the function pointers and returning -ENOTSUPP if it is not valid. This is done for multiple pin config settings and results in the code that handles the supporting cases to get indented by one level. This is aggrevated by the fact that some features require another level of conditionals.
Instead of assigning the same error code in all unsupported optional feature cases, simply have that error code as the default, and break out of the switch/case block whenever a feature is unsupported, or an error is returned. This reduces indentation by one level for the useful code.
Also replace the goto statements with break statements. The result is the same, as the gotos simply exit the switch/case block, which can also be achieved with a break statement. With the latter the intent is clear and easier to understand.
--- drivers/pinctrl/mediatek/pinctrl-paris.c | 144 ++++++++++------------- 1 file changed, 61 insertions(+), 83 deletions(-)
drivers/pinctrl/mediatek/pinctrl-paris.c +61 -83
@@ -79,37 +79,34 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev, {struct mtk_pinctrl *hw =pinctrl_dev_get_drvdata (pctldev);u32 param =pinconf_to_config_param (*config); -int pullup, err, reg, ret =1 ; +int pullup, reg, err = -ENOTSUPP , ret =1 ;const struct mtk_pin_desc *desc; -if (pin >= hw->soc->npins) { - err = -EINVAL ; - goto out; - } +if (pin >= hw->soc->npins) +return -EINVAL ; + desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];switch (param) {case PIN_CONFIG_BIAS_DISABLE :case PIN_CONFIG_BIAS_PULL_UP :case PIN_CONFIG_BIAS_PULL_DOWN : -if (hw->soc->bias_get_combo) { - err = hw->soc->bias_get_combo (hw, desc, &pullup, &ret); -if (err) - goto out; -if (ret ==MTK_PUPD_SET_R1R0_00 ) - ret =MTK_DISABLE ; -if (param ==PIN_CONFIG_BIAS_DISABLE ) { -if (ret !=MTK_DISABLE ) - err = -EINVAL ; - }else if (param ==PIN_CONFIG_BIAS_PULL_UP ) { -if (!pullup || ret ==MTK_DISABLE ) - err = -EINVAL ; - }else if (param ==PIN_CONFIG_BIAS_PULL_DOWN ) { -if (pullup || ret ==MTK_DISABLE ) - err = -EINVAL ; - } - }else { - err = -ENOTSUPP ; +if (!hw->soc->bias_get_combo) +break ; + err = hw->soc->bias_get_combo (hw, desc, &pullup, &ret); +if (err) +break ; +if (ret ==MTK_PUPD_SET_R1R0_00 ) + ret =MTK_DISABLE ; +if (param ==PIN_CONFIG_BIAS_DISABLE ) { +if (ret !=MTK_DISABLE ) + err = -EINVAL ; + }else if (param ==PIN_CONFIG_BIAS_PULL_UP ) { +if (!pullup || ret ==MTK_DISABLE ) + err = -EINVAL ; + }else if (param ==PIN_CONFIG_BIAS_PULL_DOWN ) { +if (pullup || ret ==MTK_DISABLE ) + err = -EINVAL ; }break ;case PIN_CONFIG_SLEW_RATE :
@@ -119,7 +116,7 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,case PIN_CONFIG_OUTPUT_ENABLE : err =mtk_hw_get_value (hw, desc,PINCTRL_PIN_REG_DIR , &ret);if (err) - goto out; +break ;/* CONFIG Current direction return value * ------------- ----------------- ---------------------- * OUTPUT_ENABLE output 1 (= HW value)
@@ -134,23 +131,21 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,case PIN_CONFIG_INPUT_SCHMITT_ENABLE : err =mtk_hw_get_value (hw, desc,PINCTRL_PIN_REG_DIR , &ret);if (err) - goto out; +break ;/* return error when in output mode * because schmitt trigger only work in input mode */ if (ret) { err = -EINVAL ; - goto out; +break ; } err =mtk_hw_get_value (hw, desc,PINCTRL_PIN_REG_SMT , &ret); -break ;case PIN_CONFIG_DRIVE_STRENGTH : -if (hw->soc->drive_get) - err = hw->soc->drive_get (hw, desc, &ret); -else - err = -ENOTSUPP ; +if (!hw->soc->drive_get) +break ; + err = hw->soc->drive_get (hw, desc, &ret);break ;case MTK_PIN_CONFIG_TDSEL :case MTK_PIN_CONFIG_RDSEL :
@@ -160,23 +155,18 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,break ;case MTK_PIN_CONFIG_PU_ADV :case MTK_PIN_CONFIG_PD_ADV : -if (hw->soc->adv_pull_get) { - pullup = param ==MTK_PIN_CONFIG_PU_ADV ; - err = hw->soc->adv_pull_get (hw, desc, pullup, &ret); - }else - err = -ENOTSUPP ; +if (!hw->soc->adv_pull_get) +break ; + pullup = param ==MTK_PIN_CONFIG_PU_ADV ; + err = hw->soc->adv_pull_get (hw, desc, pullup, &ret);break ;case MTK_PIN_CONFIG_DRV_ADV : -if (hw->soc->adv_drive_get) - err = hw->soc->adv_drive_get (hw, desc, &ret); -else - err = -ENOTSUPP ; +if (!hw->soc->adv_drive_get) +break ; + err = hw->soc->adv_drive_get (hw, desc, &ret);break ; -default : - err = -ENOTSUPP ; } -out:if (!err) *config =pinconf_to_config_packed (param, ret);
@@ -188,33 +178,29 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin, {struct mtk_pinctrl *hw =pinctrl_dev_get_drvdata (pctldev);const struct mtk_pin_desc *desc; -int err =0 ; +int err = -ENOTSUPP ;u32 reg; -if (pin >= hw->soc->npins) { - err = -EINVAL ; - goto err; - } +if (pin >= hw->soc->npins) +return -EINVAL ; + desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];switch ((u32 )param) {case PIN_CONFIG_BIAS_DISABLE : -if (hw->soc->bias_set_combo) - err = hw->soc->bias_set_combo (hw, desc,0 ,MTK_DISABLE ); -else - err = -ENOTSUPP ; +if (!hw->soc->bias_set_combo) +break ; + err = hw->soc->bias_set_combo (hw, desc,0 ,MTK_DISABLE );break ;case PIN_CONFIG_BIAS_PULL_UP : -if (hw->soc->bias_set_combo) - err = hw->soc->bias_set_combo (hw, desc,1 , arg); -else - err = -ENOTSUPP ; +if (!hw->soc->bias_set_combo) +break ; + err = hw->soc->bias_set_combo (hw, desc,1 , arg);break ;case PIN_CONFIG_BIAS_PULL_DOWN : -if (hw->soc->bias_set_combo) - err = hw->soc->bias_set_combo (hw, desc,0 , arg); -else - err = -ENOTSUPP ; +if (!hw->soc->bias_set_combo) +break ; + err = hw->soc->bias_set_combo (hw, desc,0 , arg);break ;case PIN_CONFIG_OUTPUT_ENABLE : err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT,
@@ -223,7 +209,7 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,* does not have SMT control */ if (err != -ENOTSUPP ) - goto err; +break ; err =mtk_hw_set_value (hw, desc,PINCTRL_PIN_REG_DIR ,MTK_OUTPUT );
@@ -232,7 +218,7 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,/* regard all non-zero value as enable */ err =mtk_hw_set_value (hw, desc,PINCTRL_PIN_REG_IES , !!arg);if (err) - goto err; +break ; err =mtk_hw_set_value (hw, desc,PINCTRL_PIN_REG_DIR ,MTK_INPUT );
@@ -245,7 +231,7 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin, err =mtk_hw_set_value (hw, desc,PINCTRL_PIN_REG_DO , arg);if (err) - goto err; +break ; err =mtk_hw_set_value (hw, desc,PINCTRL_PIN_REG_DIR ,MTK_OUTPUT );
@@ -257,15 +243,14 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,*/ err =mtk_hw_set_value (hw, desc,PINCTRL_PIN_REG_DIR , !arg);if (err) - goto err; +break ; err =mtk_hw_set_value (hw, desc,PINCTRL_PIN_REG_SMT , !!arg);break ;case PIN_CONFIG_DRIVE_STRENGTH : -if (hw->soc->drive_set) - err = hw->soc->drive_set (hw, desc, arg); -else - err = -ENOTSUPP ; +if (!hw->soc->drive_set) +break ; + err = hw->soc->drive_set (hw, desc, arg);break ;case MTK_PIN_CONFIG_TDSEL :case MTK_PIN_CONFIG_RDSEL :
@@ -275,26 +260,19 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,break ;case MTK_PIN_CONFIG_PU_ADV :case MTK_PIN_CONFIG_PD_ADV : -if (hw->soc->adv_pull_set) { -bool pullup; - - pullup = param ==MTK_PIN_CONFIG_PU_ADV ; - err = hw->soc->adv_pull_set (hw, desc, pullup, - arg); - }else - err = -ENOTSUPP ; +if (!hw->soc->adv_pull_set) +break ; + err = hw->soc->adv_pull_set (hw, desc, + (param ==MTK_PIN_CONFIG_PU_ADV ), + arg);break ;case MTK_PIN_CONFIG_DRV_ADV : -if (hw->soc->adv_drive_set) - err = hw->soc->adv_drive_set (hw, desc, arg); -else - err = -ENOTSUPP ; +if (!hw->soc->adv_drive_set) +break ; + err = hw->soc->adv_drive_set (hw, desc, arg);break ; -default : - err = -ENOTSUPP ; } -err:return err; }
Signature · 1 line
2.35.1.616.g0bdcbb4464-goog
Re: [PATCH v2 07/11] pinctrl: mediatek: paris: Rework mtk_pinconf_{get,set} switch/case logic
Il 08/03/22 11:09, Chen-Yu Tsai ha scritto:
Quoted 13 lines
The current code deals with optional features by testing for the function pointers and returning
-ENOTSUPPif it is not valid. This is done for multiple pin config settings and results in the code that handles the supporting cases to get indented by one level. This is aggrevated by the fact that some features require another level of conditionals.Instead of assigning the same error code in all unsupported optional feature cases, simply have that error code as the default, and break out of the switch/case block whenever a feature is unsupported, or an error is returned. This reduces indentation by one level for the useful code.
Quoted 6 lines
Also replace the goto statements with break statements. The result is the same, as the gotos simply exit the switch/case block, which can also be achieved with a break statement. With the latter the intent is clear and easier to understand.
Signed-off-by Chen-Yu Tsai <[email protected]>
Quoted 4 lines
--- drivers/pinctrl/mediatek/pinctrl-paris.c | 144 ++++++++++------------- 1 file changed, 61 insertions(+), 83 deletions(-)
PATCH v2 8/11 pinctrl: mediatek: paris: Support generic PIN_CONFIG_DRIVE_STRENGTH_UA
In reply to Chen-Yu TsaiSome of the MediaTek chips that utilize the Paris pinctrl driver library support a lower drive strength (<= 1mA) than the standard drive strength settings (2~16 mA) on certain pins. This was previously supported by the custom MTK_PIN_CONFIG_DRV_ADV parameter along with the "mediatek,drive-strength-adv" device tree property.
The drive strength values for this hardware are 125, 250, 500, and 1000 mA, and can be readily described by the existing "drive-strength-microamp" property, which then gets parsed by the generic pinconf library into the parameter PIN_CONFIG_DRIVE_STRENGTH_UA.
Add support for PIN_CONFIG_DRIVE_STRENGTH_UA while keeping the old custom parameter around for backward compatibility.
--- drivers/pinctrl/mediatek/pinctrl-paris.c | 99 ++++++++++++++++++++++++ 1 file changed, 99 insertions(+)
drivers/pinctrl/mediatek/pinctrl-paris.c +99 -0
@@ -48,6 +48,53 @@ static const char * const mtk_gpio_functions[] = { "func12", "func13", "func14", "func15", }; +/* +* This section supports converting to/from custom MTK_PIN_CONFIG_DRV_ADV +* and standard PIN_CONFIG_DRIVE_STRENGTH_UA pin configs. +* +* The custom value encodes three hardware bits as follows: +* +* | Bits | +* | 2 (E1) | 1 (E0) | 0 (EN) | drive strength (uA) +* ------------------------------------------------ +* | x | x | 0 | disabled, use standard drive strength +* ------------------------------------- +* | 0 | 0 | 1 | 125 uA +* | 0 | 1 | 1 | 250 uA +* | 1 | 0 | 1 | 500 uA +* | 1 | 1 | 1 | 1000 uA +*/ +static const int mtk_drv_adv_uA[] = {125 ,250 ,500 ,1000 }; + +static int mtk_drv_adv_to_uA (int val) +{ +/* This should never happen. */ +if (WARN_ON_ONCE (val <0 || val >7 )) +return -EINVAL ; + +/* Bit 0 simply enables this hardware part */ +if (!(val &BIT (0 ))) +return -EINVAL ; + +return mtk_drv_adv_uA[(val >>1 )]; +} + +static int mtk_drv_uA_to_adv (int val) +{ +switch (val) { +case 125 : +return 0x1 ; +case 250 : +return 0x3 ; +case 500 : +return 0x5 ; +case 1000 : +return 0x7 ; + } + +return -EINVAL ; +} +static int mtk_pinmux_gpio_request_enable (struct pinctrl_dev *pctldev,struct pinctrl_gpio_range *range,unsigned int pin)
@@ -145,8 +192,35 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,case PIN_CONFIG_DRIVE_STRENGTH :if (!hw->soc->drive_get)break ; + +if (hw->soc->adv_drive_get) { + err = hw->soc->adv_drive_get (hw, desc, &ret); +if (!err) { + err =mtk_drv_adv_to_uA (ret); +if (err >0 ) { +/* PIN_CONFIG_DRIVE_STRENGTH_UA used */ + err = -EINVAL ; +break ; + } + } + } + err = hw->soc->drive_get (hw, desc, &ret);break ; +case PIN_CONFIG_DRIVE_STRENGTH_UA : +if (!hw->soc->adv_drive_get) +break ; + + err = hw->soc->adv_drive_get (hw, desc, &ret); +if (err) +break ; + err =mtk_drv_adv_to_uA (ret); +if (err <0 ) +break ; + + ret = err; + err =0 ; +break ;case MTK_PIN_CONFIG_TDSEL :case MTK_PIN_CONFIG_RDSEL : reg = (param == MTK_PIN_CONFIG_TDSEL) ?
@@ -252,6 +326,15 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,break ; err = hw->soc->drive_set (hw, desc, arg);break ; +case PIN_CONFIG_DRIVE_STRENGTH_UA : +if (!hw->soc->adv_drive_set) +break ; + + err =mtk_drv_uA_to_adv (arg); +if (err <0 ) +break ; + err = hw->soc->adv_drive_set (hw, desc, err); +break ;case MTK_PIN_CONFIG_TDSEL :case MTK_PIN_CONFIG_RDSEL : reg = (param == MTK_PIN_CONFIG_TDSEL) ?
@@ -720,6 +803,8 @@ static int mtk_pconf_group_set(struct pinctrl_dev *pctldev, unsigned group, {struct mtk_pinctrl *hw =pinctrl_dev_get_drvdata (pctldev);struct mtk_pinctrl_group *grp = &hw->groups[group]; +bool drive_strength_uA_found = false; +bool adv_drve_strength_found = false;int i, ret;for (i =0 ; i < num_configs; i++) {
@@ -728,8 +813,22 @@ static int mtk_pconf_group_set(struct pinctrl_dev *pctldev, unsigned group, pinconf_to_config_argument(configs[i]));if (ret <0 )return ret; + +if (pinconf_to_config_param (configs[i]) ==PIN_CONFIG_DRIVE_STRENGTH_UA ) + drive_strength_uA_found = true; +if (pinconf_to_config_param (configs[i]) ==MTK_PIN_CONFIG_DRV_ADV ) + adv_drve_strength_found = true; } +/* +* Disable advanced drive strength mode if drive-strength-microamp +* is not set. However, mediatek,drive-strength-adv takes precedence +* as its value can explicitly request the mode be enabled or not. +*/ +if (hw->soc->adv_drive_set && !drive_strength_uA_found && + !adv_drve_strength_found) + hw->soc->adv_drive_set (hw, &hw->soc->pins[grp->pin],0 ); +return 0 ; }
Signature · 1 line
2.35.1.616.g0bdcbb4464-goog
Re: [PATCH v2 08/11] pinctrl: mediatek: paris: Support generic PIN_CONFIG_DRIVE_STRENGTH_UA
Il 08/03/22 11:09, Chen-Yu Tsai ha scritto:
Quoted 11 lines
Some of the MediaTek chips that utilize the Paris pinctrl driver library support a lower drive strength (<= 1mA) than the standard drive strength settings (2~16 mA) on certain pins. This was previously supported by the custom
MTK_PIN_CONFIG_DRV_ADVparameter along with the "mediatek,drive-strength-adv" device tree property.The drive strength values for this hardware are 125, 250, 500, and 1000 mA, and can be readily described by the existing "drive-strength-microamp" property, which then gets parsed by the generic pinconf library into the parameter
PIN_CONFIG_DRIVE_STRENGTH_UA.
Quoted 4 lines
Add support for
PIN_CONFIG_DRIVE_STRENGTH_UAwhile keeping the old custom parameter around for backward compatibility.Signed-off-by Chen-Yu Tsai <[email protected]>
Quoted 4 lines
--- drivers/pinctrl/mediatek/pinctrl-paris.c | 99 ++++++++++++++++++++++++ 1 file changed, 99 insertions(+)
PATCH v2 9/11 pinctrl: mediatek: pinctrl-moore: Simplify with dev_err_probe()
In reply to Chen-Yu TsaiFrom: AngeloGioacchino Del Regno <[email protected]>
Use the dev_err_probe() helper to simplify error handling during probe.
--- drivers/pinctrl/mediatek/pinctrl-moore.c | 25 +++++++++--------------- 1 file changed, 9 insertions(+), 16 deletions(-)
drivers/pinctrl/mediatek/pinctrl-moore.c +9 -16
@@ -605,6 +605,7 @@ static int mtk_build_functions(struct mtk_pinctrl *hw)int mtk_moore_pinctrl_probe (struct platform_device *pdev,const struct mtk_pin_soc *soc) { +struct device *dev = &pdev->dev;struct pinctrl_pin_desc *pins;struct mtk_pinctrl *hw;int err, i;
@@ -616,11 +617,9 @@ int mtk_moore_pinctrl_probe(struct platform_device *pdev, hw->soc = soc; hw->dev = &pdev->dev; -if (!hw->soc->nbase_names) { -dev_err (&pdev->dev, +if (!hw->soc->nbase_names) +return dev_err_probe (dev, -EINVAL ,"SoC should be assigned at least one register base\n" ); -return -EINVAL ; - } hw->base =devm_kmalloc_array (&pdev->dev, hw->soc->nbase_names,sizeof (*hw->base),GFP_KERNEL );
@@ -665,17 +664,13 @@ int mtk_moore_pinctrl_probe(struct platform_device *pdev,/* Setup groups descriptions per SoC types */ err =mtk_build_groups (hw); -if (err) { -dev_err (&pdev->dev,"Failed to build groups\n" ); -return err; - } +if (err) +return dev_err_probe (dev, err,"Failed to build groups\n" );/* Setup functions descriptions per SoC types */ err =mtk_build_functions (hw); -if (err) { -dev_err (&pdev->dev,"Failed to build functions\n" ); -return err; - } +if (err) +return dev_err_probe (dev, err,"Failed to build functions\n" );/* For able to make pinctrl_claim_hogs, we must not enable pinctrl * until all groups and functions are being added one.
@@ -691,10 +686,8 @@ int mtk_moore_pinctrl_probe(struct platform_device *pdev,/* Build gpiochip should be after pinctrl_enable is done */ err =mtk_build_gpiochip (hw); -if (err) { -dev_err (&pdev->dev,"Failed to add gpio_chip\n" ); -return err; - } +if (err) +return dev_err_probe (dev, err,"Failed to add gpio_chip\n" );platform_set_drvdata (pdev, hw);
Signature · 1 line
2.35.1.616.g0bdcbb4464-goog
PATCH v2 10/11 pinctrl: mediatek: pinctrl-paris: Simplify with dev_err_probe()
In reply to Chen-Yu TsaiFrom: AngeloGioacchino Del Regno <[email protected]>
Use the dev_err_probe() helper to simplify error handling during probe.
--- drivers/pinctrl/mediatek/pinctrl-paris.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)
drivers/pinctrl/mediatek/pinctrl-paris.c +7 -12
@@ -1024,6 +1024,7 @@ static int mtk_pctrl_build_state(struct platform_device *pdev)int mtk_paris_pinctrl_probe (struct platform_device *pdev,const struct mtk_pin_soc *soc) { +struct device *dev = &pdev->dev;struct pinctrl_pin_desc *pins;struct mtk_pinctrl *hw;int err, i;
@@ -1036,11 +1037,9 @@ int mtk_paris_pinctrl_probe(struct platform_device *pdev, hw->soc = soc; hw->dev = &pdev->dev; -if (!hw->soc->nbase_names) { -dev_err (&pdev->dev, +if (!hw->soc->nbase_names) +return dev_err_probe (dev, -EINVAL ,"SoC should be assigned at least one register base\n" ); -return -EINVAL ; - } hw->base =devm_kmalloc_array (&pdev->dev, hw->soc->nbase_names,sizeof (*hw->base),GFP_KERNEL );
@@ -1065,10 +1064,8 @@ int mtk_paris_pinctrl_probe(struct platform_device *pdev,spin_lock_init (&hw->lock); err =mtk_pctrl_build_state (pdev); -if (err) { -dev_err (&pdev->dev,"build state failed: %d\n" , err); -return -EINVAL ; - } +if (err) +return dev_err_probe (dev, err,"build state failed\n" );/* Copy from internal struct mtk_pin_desc to register to the core */ pins = devm_kmalloc_array(&pdev->dev, hw->soc->npins, sizeof(*pins),
@@ -1106,10 +1103,8 @@ int mtk_paris_pinctrl_probe(struct platform_device *pdev,/* Build gpiochip should be after pinctrl_enable is done */ err =mtk_build_gpiochip (hw); -if (err) { -dev_err (&pdev->dev,"Failed to add gpio_chip\n" ); -return err; - } +if (err) +return dev_err_probe (dev, err,"Failed to add gpio_chip\n" );platform_set_drvdata (pdev, hw);
Signature · 1 line
2.35.1.616.g0bdcbb4464-goog
PATCH v2 11/11 pinctrl: mediatek: pinctrl-mtk-common: Simplify with dev_err_probe()
In reply to Chen-Yu TsaiFrom: AngeloGioacchino Del Regno <[email protected]>
Use the dev_err_probe() helper to simplify error handling during probe.
--- drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-)
drivers/pinctrl/mediatek/pinctrl-mtk-common.c +11 -14
@@ -1013,10 +1013,12 @@ static int mtk_eint_init(struct mtk_pinctrl *pctl, struct platform_device *pdev)return mtk_eint_do_init (pctl->eint); } +/* This is used as a common probe function */ int mtk_pctrl_init (struct platform_device *pdev,const struct mtk_pinctrl_devdata *data,struct regmap *regmap) { +struct device *dev = &pdev->dev;struct pinctrl_pin_desc *pins;struct mtk_pinctrl *pctl;struct device_node *np = pdev->dev.of_node, *node;
@@ -1030,10 +1032,9 @@ int mtk_pctrl_init(struct platform_device *pdev,platform_set_drvdata (pdev, pctl); prop =of_find_property (np,"pins-are-numbered" ,NULL ); -if (!prop) { -dev_err (&pdev->dev,"only support pins-are-numbered format\n" ); -return -EINVAL ; - } +if (!prop) +return dev_err_probe (dev, -EINVAL , +"only support pins-are-numbered format\n" ); node =of_parse_phandle (np,"mediatek,pctl-regmap" ,0 );if (node) {
@@ -1043,8 +1044,7 @@ int mtk_pctrl_init(struct platform_device *pdev, }else if (regmap) { pctl->regmap1 = regmap; }else { -dev_err (&pdev->dev,"Pinctrl node has not register regmap.\n" ); -return -EINVAL ; +return dev_err_probe (dev, -EINVAL ,"Cannot find pinctrl regmap.\n" ); }/* Only 8135 has two base addr, other SoCs have only one. */
@@ -1057,10 +1057,8 @@ int mtk_pctrl_init(struct platform_device *pdev, pctl->devdata = data; ret =mtk_pctrl_build_state (pdev); -if (ret) { -dev_err (&pdev->dev,"build state failed: %d\n" , ret); -return -EINVAL ; - } +if (ret) +return dev_err_probe (dev, ret,"build state failed\n" ); pins =devm_kcalloc (&pdev->dev, pctl->devdata->npins,sizeof (*pins),GFP_KERNEL );
@@ -1081,10 +1079,9 @@ int mtk_pctrl_init(struct platform_device *pdev, pctl->pctl_dev =devm_pinctrl_register (&pdev->dev, &pctl->pctl_desc, pctl); -if (IS_ERR (pctl->pctl_dev)) { -dev_err (&pdev->dev,"couldn't register pinctrl driver\n" ); -return PTR_ERR (pctl->pctl_dev); - } +if (IS_ERR (pctl->pctl_dev)) +return dev_err_probe (dev,PTR_ERR (pctl->pctl_dev), +"Couldn't register pinctrl driver\n" ); pctl->chip =devm_kzalloc (&pdev->dev,sizeof (*pctl->chip),GFP_KERNEL );if (!pctl->chip)
Signature · 1 line
2.35.1.616.g0bdcbb4464-goog
Quoted 2 lines · Chen-Yu Tsai
Here are some fixes and minor improvements to generic pinconf and the Mediatek Paris pinctrl driver.
Nobody seems to be against so I just applied all patches for v5.18.
Yours,
Linus Walleij