Skip to content

Commit 3599cc5

Browse files
Light Hsiehlinusw
authored andcommitted
pinctrl: mediatek: Refine mtk_pinconf_get() and mtk_pinconf_set()
1.Refine mtk_pinconf_get(): Use only one occurrence of return at end of this function. 2.Refine mtk_pinconf_set(): 2.1 Use only one occurrence of return at end of this function. 2.2 Modify case of PIN_CONFIG_INPUT_ENABLE - 2.2.1 Regard all non-zero setting value as enable, instead of always enable. 2.2.2 Remove check of ies_present flag and always invoke mtk_hw_set_value() since mtk_hw_pin_field_lookup() invoked inside mtk_hw_set_value() has the same effect of checking if ies control is supported. [The rationale is that: available of a control is always checked in mtk_hw_pin_field_lookup() and no need to add ies_present flag specially for ies control.] 2.3 Simply code logic for case of PIN_CONFIG_INPUT_SCHMITT. 2.4 Add case for PIN_CONFIG_INPUT_SCHMITT_ENABLE and process it with the same code for case of PIN_CONFIG_INPUT_SCHMITT. Signed-off-by: Light Hsieh <[email protected]> Link: https://lore.kernel.org/r/[email protected] Acked-by: Sean Wang <[email protected]> Signed-off-by: Linus Walleij <[email protected]>
1 parent 5f755e1 commit 3599cc5

File tree

3 files changed

+65
-108
lines changed

3 files changed

+65
-108
lines changed

drivers/pinctrl/mediatek/pinctrl-mt6765.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,6 @@ static const struct mtk_pin_soc mt6765_data = {
10701070
.ngrps = ARRAY_SIZE(mtk_pins_mt6765),
10711071
.eint_hw = &mt6765_eint_hw,
10721072
.gpio_m = 0,
1073-
.ies_present = true,
10741073
.base_names = mt6765_pinctrl_register_base_names,
10751074
.nbase_names = ARRAY_SIZE(mt6765_pinctrl_register_base_names),
10761075
.bias_disable_set = mtk_pinconf_bias_disable_set,

drivers/pinctrl/mediatek/pinctrl-mt8183.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,6 @@ static const struct mtk_pin_soc mt8183_data = {
554554
.ngrps = ARRAY_SIZE(mtk_pins_mt8183),
555555
.eint_hw = &mt8183_eint_hw,
556556
.gpio_m = 0,
557-
.ies_present = true,
558557
.base_names = mt8183_pinctrl_register_base_names,
559558
.nbase_names = ARRAY_SIZE(mt8183_pinctrl_register_base_names),
560559
.bias_disable_set = mtk_pinconf_bias_disable_set_rev1,

drivers/pinctrl/mediatek/pinctrl-paris.c

Lines changed: 65 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -81,37 +81,30 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
8181
int val, val2, err, reg, ret = 1;
8282
const struct mtk_pin_desc *desc;
8383

84-
if (pin >= hw->soc->npins)
85-
return -EINVAL;
84+
if (pin >= hw->soc->npins) {
85+
err = -EINVAL;
86+
goto out;
87+
}
8688
desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
8789

8890
switch (param) {
8991
case PIN_CONFIG_BIAS_DISABLE:
90-
if (hw->soc->bias_disable_get) {
92+
if (hw->soc->bias_disable_get)
9193
err = hw->soc->bias_disable_get(hw, desc, &ret);
92-
if (err)
93-
return err;
94-
} else {
95-
return -ENOTSUPP;
96-
}
94+
else
95+
err = -ENOTSUPP;
9796
break;
9897
case PIN_CONFIG_BIAS_PULL_UP:
99-
if (hw->soc->bias_get) {
98+
if (hw->soc->bias_get)
10099
err = hw->soc->bias_get(hw, desc, 1, &ret);
101-
if (err)
102-
return err;
103-
} else {
104-
return -ENOTSUPP;
105-
}
100+
else
101+
err = -ENOTSUPP;
106102
break;
107103
case PIN_CONFIG_BIAS_PULL_DOWN:
108-
if (hw->soc->bias_get) {
104+
if (hw->soc->bias_get)
109105
err = hw->soc->bias_get(hw, desc, 0, &ret);
110-
if (err)
111-
return err;
112-
} else {
113-
return -ENOTSUPP;
114-
}
106+
else
107+
err = -ENOTSUPP;
115108
break;
116109
case PIN_CONFIG_SLEW_RATE:
117110
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_SR, &val);
@@ -126,12 +119,16 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
126119
case PIN_CONFIG_OUTPUT_ENABLE:
127120
err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DIR, &val);
128121
if (err)
129-
return err;
130-
131-
/* HW takes input mode as zero; output mode as non-zero */
132-
if ((val && param == PIN_CONFIG_INPUT_ENABLE) ||
133-
(!val && param == PIN_CONFIG_OUTPUT_ENABLE))
134-
return -EINVAL;
122+
goto out;
123+
/* CONFIG Current direction return value
124+
* ------------- ----------------- ----------------------
125+
* OUTPUT_ENABLE output 1 (= HW value)
126+
* input 0 (= HW value)
127+
* INPUT_ENABLE output 0 (= reverse HW value)
128+
* input 1 (= reverse HW value)
129+
*/
130+
if (param == PIN_CONFIG_INPUT_ENABLE)
131+
val = !val;
135132

136133
break;
137134
case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
@@ -148,13 +145,10 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
148145

149146
break;
150147
case PIN_CONFIG_DRIVE_STRENGTH:
151-
if (hw->soc->drive_get) {
148+
if (hw->soc->drive_get)
152149
err = hw->soc->drive_get(hw, desc, &ret);
153-
if (err)
154-
return err;
155-
} else {
150+
else
156151
err = -ENOTSUPP;
157-
}
158152
break;
159153
case MTK_PIN_CONFIG_TDSEL:
160154
case MTK_PIN_CONFIG_RDSEL:
@@ -175,28 +169,24 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
175169

176170
pullup = param == MTK_PIN_CONFIG_PU_ADV;
177171
err = hw->soc->adv_pull_get(hw, desc, pullup, &ret);
178-
if (err)
179-
return err;
180-
} else {
181-
return -ENOTSUPP;
182-
}
172+
} else
173+
err = -ENOTSUPP;
183174
break;
184175
case MTK_PIN_CONFIG_DRV_ADV:
185-
if (hw->soc->adv_drive_get) {
176+
if (hw->soc->adv_drive_get)
186177
err = hw->soc->adv_drive_get(hw, desc, &ret);
187-
if (err)
188-
return err;
189-
} else {
190-
return -ENOTSUPP;
191-
}
178+
else
179+
err = -ENOTSUPP;
192180
break;
193181
default:
194-
return -ENOTSUPP;
182+
err = -ENOTSUPP;
195183
}
196184

197-
*config = pinconf_to_config_packed(param, ret);
185+
out:
186+
if (!err)
187+
*config = pinconf_to_config_packed(param, ret);
198188

199-
return 0;
189+
return err;
200190
}
201191

202192
static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
@@ -216,60 +206,47 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
216206

217207
switch ((u32)param) {
218208
case PIN_CONFIG_BIAS_DISABLE:
219-
if (hw->soc->bias_disable_set) {
209+
if (hw->soc->bias_disable_set)
220210
err = hw->soc->bias_disable_set(hw, desc);
221-
if (err)
222-
return err;
223-
} else {
224-
return -ENOTSUPP;
225-
}
211+
else
212+
err = -ENOTSUPP;
226213
break;
227214
case PIN_CONFIG_BIAS_PULL_UP:
228-
if (hw->soc->bias_set) {
215+
if (hw->soc->bias_set)
229216
err = hw->soc->bias_set(hw, desc, 1);
230-
if (err)
231-
return err;
232-
} else {
233-
return -ENOTSUPP;
234-
}
217+
else
218+
err = -ENOTSUPP;
235219
break;
236220
case PIN_CONFIG_BIAS_PULL_DOWN:
237-
if (hw->soc->bias_set) {
221+
if (hw->soc->bias_set)
238222
err = hw->soc->bias_set(hw, desc, 0);
239-
if (err)
240-
return err;
241-
} else {
242-
return -ENOTSUPP;
243-
}
223+
else
224+
err = -ENOTSUPP;
244225
break;
245226
case PIN_CONFIG_OUTPUT_ENABLE:
246227
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT,
247228
MTK_DISABLE);
248-
if (err)
229+
/* Keep set direction to consider the case that a GPIO pin
230+
* does not have SMT control
231+
*/
232+
if (err != -ENOTSUPP)
249233
goto err;
250234

251235
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
252236
MTK_OUTPUT);
253-
if (err)
254-
goto err;
255237
break;
256238
case PIN_CONFIG_INPUT_ENABLE:
257-
if (hw->soc->ies_present) {
258-
mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_IES,
259-
MTK_ENABLE);
260-
}
239+
/* regard all non-zero value as enable */
240+
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_IES, !!arg);
241+
if (err)
242+
goto err;
261243

262244
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
263245
MTK_INPUT);
264-
if (err)
265-
goto err;
266246
break;
267247
case PIN_CONFIG_SLEW_RATE:
268-
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SR,
269-
arg);
270-
if (err)
271-
goto err;
272-
248+
/* regard all non-zero value as enable */
249+
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SR, !!arg);
273250
break;
274251
case PIN_CONFIG_OUTPUT:
275252
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
@@ -279,41 +256,29 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
279256

280257
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DO,
281258
arg);
282-
if (err)
283-
goto err;
284259
break;
260+
case PIN_CONFIG_INPUT_SCHMITT:
285261
case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
286262
/* arg = 1: Input mode & SMT enable ;
287263
* arg = 0: Output mode & SMT disable
288264
*/
289-
arg = arg ? 2 : 1;
290-
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
291-
arg & 1);
265+
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR, !arg);
292266
if (err)
293267
goto err;
294268

295-
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT,
296-
!!(arg & 2));
297-
if (err)
298-
goto err;
269+
err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT, !!arg);
299270
break;
300271
case PIN_CONFIG_DRIVE_STRENGTH:
301-
if (hw->soc->drive_set) {
272+
if (hw->soc->drive_set)
302273
err = hw->soc->drive_set(hw, desc, arg);
303-
if (err)
304-
return err;
305-
} else {
306-
return -ENOTSUPP;
307-
}
274+
else
275+
err = -ENOTSUPP;
308276
break;
309277
case MTK_PIN_CONFIG_TDSEL:
310278
case MTK_PIN_CONFIG_RDSEL:
311279
reg = (param == MTK_PIN_CONFIG_TDSEL) ?
312280
PINCTRL_PIN_REG_TDSEL : PINCTRL_PIN_REG_RDSEL;
313-
314281
err = mtk_hw_set_value(hw, desc, reg, arg);
315-
if (err)
316-
goto err;
317282
break;
318283
case MTK_PIN_CONFIG_PU_ADV:
319284
case MTK_PIN_CONFIG_PD_ADV:
@@ -323,20 +288,14 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
323288
pullup = param == MTK_PIN_CONFIG_PU_ADV;
324289
err = hw->soc->adv_pull_set(hw, desc, pullup,
325290
arg);
326-
if (err)
327-
return err;
328-
} else {
329-
return -ENOTSUPP;
330-
}
291+
} else
292+
err = -ENOTSUPP;
331293
break;
332294
case MTK_PIN_CONFIG_DRV_ADV:
333-
if (hw->soc->adv_drive_set) {
295+
if (hw->soc->adv_drive_set)
334296
err = hw->soc->adv_drive_set(hw, desc, arg);
335-
if (err)
336-
return err;
337-
} else {
338-
return -ENOTSUPP;
339-
}
297+
else
298+
err = -ENOTSUPP;
340299
break;
341300
default:
342301
err = -ENOTSUPP;

0 commit comments

Comments
 (0)