All of lore.kernel.org
 help / color / mirror / Atom feed
From: <sean.wang@mediatek.com>
To: linus.walleij@linaro.org, linux-mediatek@lists.infradead.org
Cc: linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org,
	linux-kernel@vger.kernel.org, Sean Wang <sean.wang@mediatek.com>
Subject: [PATCH v2 13/22] pinctrl: mediatek: use pin descriptor all in pinctrl-mtk-common-v2.c
Date: Sat, 8 Sep 2018 19:07:29 +0800	[thread overview]
Message-ID: <f7d9fa1721c8d75509682a20c014ceb461495f1c.1536404280.git.sean.wang@mediatek.com> (raw)
In-Reply-To: <cover.1536404280.git.sean.wang@mediatek.com>

From: Sean Wang <sean.wang@mediatek.com>

all use pin descriptor instead in pinctrl-mtk-common-v2.c for the
consistency and extensibility.

Signed-off-by: Sean Wang <sean.wang@mediatek.com>
---
 drivers/pinctrl/mediatek/pinctrl-moore.c         | 66 +++++++++++++-------
 drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c | 76 +++++++++++++-----------
 drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h |  6 +-
 3 files changed, 88 insertions(+), 60 deletions(-)

diff --git a/drivers/pinctrl/mediatek/pinctrl-moore.c b/drivers/pinctrl/mediatek/pinctrl-moore.c
index 219cfce..2f3e3b5 100644
--- a/drivers/pinctrl/mediatek/pinctrl-moore.c
+++ b/drivers/pinctrl/mediatek/pinctrl-moore.c
@@ -54,9 +54,13 @@ static int mtk_pinmux_set_mux(struct pinctrl_dev *pctldev,
 		func->name, grp->name);
 
 	for (i = 0; i < grp->num_pins; i++) {
+		const struct mtk_pin_desc *desc;
 		int *pin_modes = grp->data;
+		int pin = grp->pins[i];
 
-		mtk_hw_set_value(hw, grp->pins[i], PINCTRL_PIN_REG_MODE,
+		desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
+
+		mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_MODE,
 				 pin_modes[i]);
 	}
 
@@ -68,8 +72,12 @@ static int mtk_pinmux_gpio_request_enable(struct pinctrl_dev *pctldev,
 					  unsigned int pin)
 {
 	struct mtk_pinctrl *hw = pinctrl_dev_get_drvdata(pctldev);
+	const struct mtk_pin_desc *desc;
+
+	desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
 
-	return mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_MODE, hw->soc->gpio_m);
+	return mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_MODE,
+				hw->soc->gpio_m);
 }
 
 static int mtk_pinmux_gpio_set_direction(struct pinctrl_dev *pctldev,
@@ -77,9 +85,12 @@ static int mtk_pinmux_gpio_set_direction(struct pinctrl_dev *pctldev,
 					 unsigned int pin, bool input)
 {
 	struct mtk_pinctrl *hw = pinctrl_dev_get_drvdata(pctldev);
+	const struct mtk_pin_desc *desc;
+
+	desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
 
 	/* hardware would take 0 as input direction */
-	return mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_DIR, !input);
+	return mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR, !input);
 }
 
 static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
@@ -121,7 +132,7 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
 		}
 		break;
 	case PIN_CONFIG_SLEW_RATE:
-		err = mtk_hw_get_value(hw, pin, PINCTRL_PIN_REG_SR, &val);
+		err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_SR, &val);
 		if (err)
 			return err;
 
@@ -131,7 +142,7 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
 		break;
 	case PIN_CONFIG_INPUT_ENABLE:
 	case PIN_CONFIG_OUTPUT_ENABLE:
-		err = mtk_hw_get_value(hw, pin, PINCTRL_PIN_REG_DIR, &val);
+		err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DIR, &val);
 		if (err)
 			return err;
 
@@ -142,11 +153,11 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
 
 		break;
 	case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
-		err = mtk_hw_get_value(hw, pin, PINCTRL_PIN_REG_DIR, &val);
+		err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DIR, &val);
 		if (err)
 			return err;
 
-		err = mtk_hw_get_value(hw, pin, PINCTRL_PIN_REG_SMT, &val2);
+		err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_SMT, &val2);
 		if (err)
 			return err;
 
@@ -168,7 +179,7 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
 		reg = (param == MTK_PIN_CONFIG_TDSEL) ?
 		       PINCTRL_PIN_REG_TDSEL : PINCTRL_PIN_REG_RDSEL;
 
-		err = mtk_hw_get_value(hw, pin, reg, &val);
+		err = mtk_hw_get_value(hw, desc, reg, &val);
 		if (err)
 			return err;
 
@@ -240,12 +251,12 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
 			}
 			break;
 		case PIN_CONFIG_OUTPUT_ENABLE:
-			err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_SMT,
+			err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT,
 					       MTK_DISABLE);
 			if (err)
 				goto err;
 
-			err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_DIR,
+			err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
 					       MTK_OUTPUT);
 			if (err)
 				goto err;
@@ -253,29 +264,29 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
 		case PIN_CONFIG_INPUT_ENABLE:
 
 			if (hw->soc->ies_present) {
-				mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_IES,
+				mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_IES,
 						 MTK_ENABLE);
 			}
 
-			err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_DIR,
+			err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
 					       MTK_INPUT);
 			if (err)
 				goto err;
 			break;
 		case PIN_CONFIG_SLEW_RATE:
-			err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_SR,
+			err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SR,
 					       arg);
 			if (err)
 				goto err;
 
 			break;
 		case PIN_CONFIG_OUTPUT:
-			err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_DIR,
+			err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
 					       MTK_OUTPUT);
 			if (err)
 				goto err;
 
-			err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_DO,
+			err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DO,
 					       arg);
 			if (err)
 				goto err;
@@ -285,12 +296,12 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
 			 * arg = 0: Output mode & SMT disable
 			 */
 			arg = arg ? 2 : 1;
-			err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_DIR,
+			err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
 					       arg & 1);
 			if (err)
 				goto err;
 
-			err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_SMT,
+			err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT,
 					       !!(arg & 2));
 			if (err)
 				goto err;
@@ -309,7 +320,7 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
 			reg = (param == MTK_PIN_CONFIG_TDSEL) ?
 			       PINCTRL_PIN_REG_TDSEL : PINCTRL_PIN_REG_RDSEL;
 
-			err = mtk_hw_set_value(hw, pin, reg, arg);
+			err = mtk_hw_set_value(hw, desc, reg, arg);
 			if (err)
 				goto err;
 			break;
@@ -419,9 +430,12 @@ static struct pinctrl_desc mtk_desc = {
 static int mtk_gpio_get(struct gpio_chip *chip, unsigned int gpio)
 {
 	struct mtk_pinctrl *hw = gpiochip_get_data(chip);
+	const struct mtk_pin_desc *desc;
 	int value, err;
 
-	err = mtk_hw_get_value(hw, gpio, PINCTRL_PIN_REG_DI, &value);
+	desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio];
+
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DI, &value);
 	if (err)
 		return err;
 
@@ -431,8 +445,11 @@ static int mtk_gpio_get(struct gpio_chip *chip, unsigned int gpio)
 static void mtk_gpio_set(struct gpio_chip *chip, unsigned int gpio, int value)
 {
 	struct mtk_pinctrl *hw = gpiochip_get_data(chip);
+	const struct mtk_pin_desc *desc;
 
-	mtk_hw_set_value(hw, gpio, PINCTRL_PIN_REG_DO, !!value);
+	desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio];
+
+	mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DO, !!value);
 }
 
 static int mtk_gpio_direction_input(struct gpio_chip *chip, unsigned int gpio)
@@ -620,6 +637,7 @@ static int mtk_xt_get_gpio_state(void *data, unsigned long eint_n)
 static int mtk_xt_set_gpio_as_eint(void *data, unsigned long eint_n)
 {
 	struct mtk_pinctrl *hw = (struct mtk_pinctrl *)data;
+	const struct mtk_pin_desc *desc;
 	struct gpio_chip *gpio_chip;
 	unsigned int gpio_n;
 	int err;
@@ -628,16 +646,18 @@ static int mtk_xt_set_gpio_as_eint(void *data, unsigned long eint_n)
 	if (err)
 		return err;
 
-	err = mtk_hw_set_value(hw, gpio_n, PINCTRL_PIN_REG_MODE,
+	desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio_n];
+
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_MODE,
 			       hw->soc->eint_m);
 	if (err)
 		return err;
 
-	err = mtk_hw_set_value(hw, gpio_n, PINCTRL_PIN_REG_DIR, MTK_INPUT);
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR, MTK_INPUT);
 	if (err)
 		return err;
 
-	err = mtk_hw_set_value(hw, gpio_n, PINCTRL_PIN_REG_SMT, MTK_ENABLE);
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT, MTK_ENABLE);
 	if (err)
 		return err;
 
diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
index 86eefe8..ed88b96 100644
--- a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
+++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
@@ -59,7 +59,8 @@ void mtk_rmw(struct mtk_pinctrl *pctl, u32 reg, u32 mask, u32 set)
 	mtk_w32(pctl, reg, val);
 }
 
-static int mtk_hw_pin_field_lookup(struct mtk_pinctrl *hw, int pin,
+static int mtk_hw_pin_field_lookup(struct mtk_pinctrl *hw,
+				   const struct mtk_pin_desc *desc,
 				   const struct mtk_pin_reg_calc *rc,
 				   struct mtk_pin_field *pfd)
 {
@@ -70,13 +71,14 @@ static int mtk_hw_pin_field_lookup(struct mtk_pinctrl *hw, int pin,
 	e = c + rc->nranges;
 
 	while (c < e) {
-		if (pin >= c->s_pin && pin <= c->e_pin)
+		if (desc->number >= c->s_pin && desc->number <= c->e_pin)
 			break;
 		c++;
 	}
 
 	if (c >= e) {
-		dev_err(hw->dev, "Out of range for pin = %d\n", pin);
+		dev_err(hw->dev, "Out of range for pin = %d (%s)\n",
+			desc->number, desc->name);
 		return -EINVAL;
 	}
 
@@ -84,7 +86,8 @@ static int mtk_hw_pin_field_lookup(struct mtk_pinctrl *hw, int pin,
 	 * if c->fixed is held, that determines the all the pins in the
 	 * range use the same field with the s_pin.
 	 */
-	bits = c->fixed ? c->s_bit : c->s_bit + (pin - c->s_pin) * (c->x_bits);
+	bits = c->fixed ? c->s_bit : c->s_bit +
+	       (desc->number - c->s_pin) * (c->x_bits);
 
 	/* Fill pfd from bits. For example 32-bit register applied is assumed
 	 * when c->sz_reg is equal to 32.
@@ -102,7 +105,8 @@ static int mtk_hw_pin_field_lookup(struct mtk_pinctrl *hw, int pin,
 	return 0;
 }
 
-static int mtk_hw_pin_field_get(struct mtk_pinctrl *hw, int pin,
+static int mtk_hw_pin_field_get(struct mtk_pinctrl *hw,
+				const struct mtk_pin_desc *desc,
 				int field, struct mtk_pin_field *pfd)
 {
 	const struct mtk_pin_reg_calc *rc;
@@ -119,7 +123,7 @@ static int mtk_hw_pin_field_get(struct mtk_pinctrl *hw, int pin,
 		return -EINVAL;
 	}
 
-	return mtk_hw_pin_field_lookup(hw, pin, rc, pfd);
+	return mtk_hw_pin_field_lookup(hw, desc, rc, pfd);
 }
 
 static void mtk_hw_bits_part(struct mtk_pin_field *pf, int *h, int *l)
@@ -155,12 +159,13 @@ static void mtk_hw_read_cross_field(struct mtk_pinctrl *hw,
 	*value = (h << nbits_l) | l;
 }
 
-int mtk_hw_set_value(struct mtk_pinctrl *hw, int pin, int field, int value)
+int mtk_hw_set_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc,
+		     int field, int value)
 {
 	struct mtk_pin_field pf;
 	int err;
 
-	err = mtk_hw_pin_field_get(hw, pin, field, &pf);
+	err = mtk_hw_pin_field_get(hw, desc, field, &pf);
 	if (err)
 		return err;
 
@@ -173,12 +178,13 @@ int mtk_hw_set_value(struct mtk_pinctrl *hw, int pin, int field, int value)
 	return 0;
 }
 
-int mtk_hw_get_value(struct mtk_pinctrl *hw, int pin, int field, int *value)
+int mtk_hw_get_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc,
+		     int field, int *value)
 {
 	struct mtk_pin_field pf;
 	int err;
 
-	err = mtk_hw_pin_field_get(hw, pin, field, &pf);
+	err = mtk_hw_pin_field_get(hw, desc, field, &pf);
 	if (err)
 		return err;
 
@@ -196,12 +202,12 @@ int mtk_pinconf_bias_disable_set(struct mtk_pinctrl *hw,
 {
 	int err;
 
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PU,
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PU,
 			       MTK_DISABLE);
 	if (err)
 		return err;
 
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PD,
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PD,
 			       MTK_DISABLE);
 	if (err)
 		return err;
@@ -215,11 +221,11 @@ int mtk_pinconf_bias_disable_get(struct mtk_pinctrl *hw,
 	int v, v2;
 	int err;
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_PU, &v);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PU, &v);
 	if (err)
 		return err;
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_PD, &v2);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PD, &v2);
 	if (err)
 		return err;
 
@@ -238,11 +244,11 @@ int mtk_pinconf_bias_set(struct mtk_pinctrl *hw,
 
 	arg = pullup ? 1 : 2;
 
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PU, arg & 1);
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PU, arg & 1);
 	if (err)
 		return err;
 
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PD,
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PD,
 			       !!(arg & 2));
 	if (err)
 		return err;
@@ -257,7 +263,7 @@ int mtk_pinconf_bias_get(struct mtk_pinctrl *hw,
 
 	reg = pullup ? PINCTRL_PIN_REG_PU : PINCTRL_PIN_REG_PD;
 
-	err = mtk_hw_get_value(hw, desc->number, reg, &v);
+	err = mtk_hw_get_value(hw, desc, reg, &v);
 	if (err)
 		return err;
 
@@ -275,7 +281,7 @@ int mtk_pinconf_bias_disable_set_rev1(struct mtk_pinctrl *hw,
 {
 	int err;
 
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PULLEN,
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLEN,
 			       MTK_DISABLE);
 	if (err)
 		return err;
@@ -288,7 +294,7 @@ int mtk_pinconf_bias_disable_get_rev1(struct mtk_pinctrl *hw,
 {
 	int v, err;
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_PULLEN, &v);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLEN, &v);
 	if (err)
 		return err;
 
@@ -307,12 +313,12 @@ int mtk_pinconf_bias_set_rev1(struct mtk_pinctrl *hw,
 
 	arg = pullup ? MTK_PULLUP : MTK_PULLDOWN;
 
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PULLEN,
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLEN,
 			       MTK_ENABLE);
 	if (err)
 		return err;
 
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PULLSEL, arg);
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLSEL, arg);
 	if (err)
 		return err;
 
@@ -325,14 +331,14 @@ int mtk_pinconf_bias_get_rev1(struct mtk_pinctrl *hw,
 {
 	int err, v;
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_PULLEN, &v);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLEN, &v);
 	if (err)
 		return err;
 
 	if (v == MTK_DISABLE)
 		return -EINVAL;
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_PULLSEL, &v);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLSEL, &v);
 	if (err)
 		return err;
 
@@ -359,12 +365,12 @@ int mtk_pinconf_drive_set(struct mtk_pinctrl *hw,
 	 */
 	if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) {
 		arg = (arg / tb->step - 1) * tb->scal;
-		err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_E4,
+		err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_E4,
 				       arg & 0x1);
 		if (err)
 			return err;
 
-		err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_E8,
+		err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_E8,
 				       (arg & 0x2) >> 1);
 		if (err)
 			return err;
@@ -381,11 +387,11 @@ int mtk_pinconf_drive_get(struct mtk_pinctrl *hw,
 
 	tb = &mtk_drive[desc->drv_n];
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_E4, &val1);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_E4, &val1);
 	if (err)
 		return err;
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_E8, &val2);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_E8, &val2);
 	if (err)
 		return err;
 
@@ -409,7 +415,7 @@ int mtk_pinconf_drive_set_rev1(struct mtk_pinctrl *hw,
 	if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) {
 		arg = (arg / tb->step - 1) * tb->scal;
 
-		err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_DRV,
+		err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DRV,
 				       arg);
 		if (err)
 			return err;
@@ -426,7 +432,7 @@ int mtk_pinconf_drive_get_rev1(struct mtk_pinctrl *hw,
 
 	tb = &mtk_drive[desc->drv_n];
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_DRV, &val1);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DRV, &val1);
 	if (err)
 		return err;
 
@@ -446,18 +452,18 @@ int mtk_pinconf_adv_pull_set(struct mtk_pinctrl *hw,
 	 * 10K on & 50K (75K) off, when (R0, R1) = (1, 0);
 	 * 10K on & 50K (75K) on, when (R0, R1) = (1, 1)
 	 */
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_R0, arg & 1);
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_R0, arg & 1);
 	if (err)
 		return 0;
 
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_R1,
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_R1,
 			       !!(arg & 2));
 	if (err)
 		return 0;
 
 	arg = pullup ? 0 : 1;
 
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PUPD, arg);
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PUPD, arg);
 
 	return err;
 }
@@ -469,7 +475,7 @@ int mtk_pinconf_adv_pull_get(struct mtk_pinctrl *hw,
 	u32 t, t2;
 	int err;
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_PUPD, &t);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PUPD, &t);
 	if (err)
 		return err;
 
@@ -477,11 +483,11 @@ int mtk_pinconf_adv_pull_get(struct mtk_pinctrl *hw,
 	if (pullup ^ !t)
 		return -EINVAL;
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_R0, &t);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_R0, &t);
 	if (err)
 		return err;
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_R1, &t2);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_R1, &t2);
 	if (err)
 		return err;
 
diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h
index d90788b..6e66bdc 100644
--- a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h
+++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h
@@ -192,8 +192,10 @@ struct mtk_pinctrl {
 
 void mtk_rmw(struct mtk_pinctrl *pctl, u32 reg, u32 mask, u32 set);
 
-int mtk_hw_set_value(struct mtk_pinctrl *hw, int pin, int field, int value);
-int mtk_hw_get_value(struct mtk_pinctrl *hw, int pin, int field, int *value);
+int mtk_hw_set_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc,
+		     int field, int value);
+int mtk_hw_get_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc,
+		     int field, int *value);
 
 int mtk_pinconf_bias_disable_set(struct mtk_pinctrl *hw,
 				 const struct mtk_pin_desc *desc);
-- 
2.7.4

WARNING: multiple messages have this Message-ID (diff)
From: <sean.wang@mediatek.com>
To: <linus.walleij@linaro.org>, <linux-mediatek@lists.infradead.org>
Cc: <linux-arm-kernel@lists.infradead.org>,
	<linux-gpio@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	Sean Wang <sean.wang@mediatek.com>
Subject: [PATCH v2 13/22] pinctrl: mediatek: use pin descriptor all in pinctrl-mtk-common-v2.c
Date: Sat, 8 Sep 2018 19:07:29 +0800	[thread overview]
Message-ID: <f7d9fa1721c8d75509682a20c014ceb461495f1c.1536404280.git.sean.wang@mediatek.com> (raw)
In-Reply-To: <cover.1536404280.git.sean.wang@mediatek.com>

From: Sean Wang <sean.wang@mediatek.com>

all use pin descriptor instead in pinctrl-mtk-common-v2.c for the
consistency and extensibility.

Signed-off-by: Sean Wang <sean.wang@mediatek.com>
---
 drivers/pinctrl/mediatek/pinctrl-moore.c         | 66 +++++++++++++-------
 drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c | 76 +++++++++++++-----------
 drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h |  6 +-
 3 files changed, 88 insertions(+), 60 deletions(-)

diff --git a/drivers/pinctrl/mediatek/pinctrl-moore.c b/drivers/pinctrl/mediatek/pinctrl-moore.c
index 219cfce..2f3e3b5 100644
--- a/drivers/pinctrl/mediatek/pinctrl-moore.c
+++ b/drivers/pinctrl/mediatek/pinctrl-moore.c
@@ -54,9 +54,13 @@ static int mtk_pinmux_set_mux(struct pinctrl_dev *pctldev,
 		func->name, grp->name);
 
 	for (i = 0; i < grp->num_pins; i++) {
+		const struct mtk_pin_desc *desc;
 		int *pin_modes = grp->data;
+		int pin = grp->pins[i];
 
-		mtk_hw_set_value(hw, grp->pins[i], PINCTRL_PIN_REG_MODE,
+		desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
+
+		mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_MODE,
 				 pin_modes[i]);
 	}
 
@@ -68,8 +72,12 @@ static int mtk_pinmux_gpio_request_enable(struct pinctrl_dev *pctldev,
 					  unsigned int pin)
 {
 	struct mtk_pinctrl *hw = pinctrl_dev_get_drvdata(pctldev);
+	const struct mtk_pin_desc *desc;
+
+	desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
 
-	return mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_MODE, hw->soc->gpio_m);
+	return mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_MODE,
+				hw->soc->gpio_m);
 }
 
 static int mtk_pinmux_gpio_set_direction(struct pinctrl_dev *pctldev,
@@ -77,9 +85,12 @@ static int mtk_pinmux_gpio_set_direction(struct pinctrl_dev *pctldev,
 					 unsigned int pin, bool input)
 {
 	struct mtk_pinctrl *hw = pinctrl_dev_get_drvdata(pctldev);
+	const struct mtk_pin_desc *desc;
+
+	desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
 
 	/* hardware would take 0 as input direction */
-	return mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_DIR, !input);
+	return mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR, !input);
 }
 
 static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
@@ -121,7 +132,7 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
 		}
 		break;
 	case PIN_CONFIG_SLEW_RATE:
-		err = mtk_hw_get_value(hw, pin, PINCTRL_PIN_REG_SR, &val);
+		err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_SR, &val);
 		if (err)
 			return err;
 
@@ -131,7 +142,7 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
 		break;
 	case PIN_CONFIG_INPUT_ENABLE:
 	case PIN_CONFIG_OUTPUT_ENABLE:
-		err = mtk_hw_get_value(hw, pin, PINCTRL_PIN_REG_DIR, &val);
+		err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DIR, &val);
 		if (err)
 			return err;
 
@@ -142,11 +153,11 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
 
 		break;
 	case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
-		err = mtk_hw_get_value(hw, pin, PINCTRL_PIN_REG_DIR, &val);
+		err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DIR, &val);
 		if (err)
 			return err;
 
-		err = mtk_hw_get_value(hw, pin, PINCTRL_PIN_REG_SMT, &val2);
+		err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_SMT, &val2);
 		if (err)
 			return err;
 
@@ -168,7 +179,7 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
 		reg = (param == MTK_PIN_CONFIG_TDSEL) ?
 		       PINCTRL_PIN_REG_TDSEL : PINCTRL_PIN_REG_RDSEL;
 
-		err = mtk_hw_get_value(hw, pin, reg, &val);
+		err = mtk_hw_get_value(hw, desc, reg, &val);
 		if (err)
 			return err;
 
@@ -240,12 +251,12 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
 			}
 			break;
 		case PIN_CONFIG_OUTPUT_ENABLE:
-			err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_SMT,
+			err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT,
 					       MTK_DISABLE);
 			if (err)
 				goto err;
 
-			err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_DIR,
+			err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
 					       MTK_OUTPUT);
 			if (err)
 				goto err;
@@ -253,29 +264,29 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
 		case PIN_CONFIG_INPUT_ENABLE:
 
 			if (hw->soc->ies_present) {
-				mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_IES,
+				mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_IES,
 						 MTK_ENABLE);
 			}
 
-			err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_DIR,
+			err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
 					       MTK_INPUT);
 			if (err)
 				goto err;
 			break;
 		case PIN_CONFIG_SLEW_RATE:
-			err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_SR,
+			err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SR,
 					       arg);
 			if (err)
 				goto err;
 
 			break;
 		case PIN_CONFIG_OUTPUT:
-			err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_DIR,
+			err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
 					       MTK_OUTPUT);
 			if (err)
 				goto err;
 
-			err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_DO,
+			err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DO,
 					       arg);
 			if (err)
 				goto err;
@@ -285,12 +296,12 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
 			 * arg = 0: Output mode & SMT disable
 			 */
 			arg = arg ? 2 : 1;
-			err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_DIR,
+			err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
 					       arg & 1);
 			if (err)
 				goto err;
 
-			err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_SMT,
+			err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT,
 					       !!(arg & 2));
 			if (err)
 				goto err;
@@ -309,7 +320,7 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
 			reg = (param == MTK_PIN_CONFIG_TDSEL) ?
 			       PINCTRL_PIN_REG_TDSEL : PINCTRL_PIN_REG_RDSEL;
 
-			err = mtk_hw_set_value(hw, pin, reg, arg);
+			err = mtk_hw_set_value(hw, desc, reg, arg);
 			if (err)
 				goto err;
 			break;
@@ -419,9 +430,12 @@ static struct pinctrl_desc mtk_desc = {
 static int mtk_gpio_get(struct gpio_chip *chip, unsigned int gpio)
 {
 	struct mtk_pinctrl *hw = gpiochip_get_data(chip);
+	const struct mtk_pin_desc *desc;
 	int value, err;
 
-	err = mtk_hw_get_value(hw, gpio, PINCTRL_PIN_REG_DI, &value);
+	desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio];
+
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DI, &value);
 	if (err)
 		return err;
 
@@ -431,8 +445,11 @@ static int mtk_gpio_get(struct gpio_chip *chip, unsigned int gpio)
 static void mtk_gpio_set(struct gpio_chip *chip, unsigned int gpio, int value)
 {
 	struct mtk_pinctrl *hw = gpiochip_get_data(chip);
+	const struct mtk_pin_desc *desc;
 
-	mtk_hw_set_value(hw, gpio, PINCTRL_PIN_REG_DO, !!value);
+	desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio];
+
+	mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DO, !!value);
 }
 
 static int mtk_gpio_direction_input(struct gpio_chip *chip, unsigned int gpio)
@@ -620,6 +637,7 @@ static int mtk_xt_get_gpio_state(void *data, unsigned long eint_n)
 static int mtk_xt_set_gpio_as_eint(void *data, unsigned long eint_n)
 {
 	struct mtk_pinctrl *hw = (struct mtk_pinctrl *)data;
+	const struct mtk_pin_desc *desc;
 	struct gpio_chip *gpio_chip;
 	unsigned int gpio_n;
 	int err;
@@ -628,16 +646,18 @@ static int mtk_xt_set_gpio_as_eint(void *data, unsigned long eint_n)
 	if (err)
 		return err;
 
-	err = mtk_hw_set_value(hw, gpio_n, PINCTRL_PIN_REG_MODE,
+	desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio_n];
+
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_MODE,
 			       hw->soc->eint_m);
 	if (err)
 		return err;
 
-	err = mtk_hw_set_value(hw, gpio_n, PINCTRL_PIN_REG_DIR, MTK_INPUT);
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR, MTK_INPUT);
 	if (err)
 		return err;
 
-	err = mtk_hw_set_value(hw, gpio_n, PINCTRL_PIN_REG_SMT, MTK_ENABLE);
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT, MTK_ENABLE);
 	if (err)
 		return err;
 
diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
index 86eefe8..ed88b96 100644
--- a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
+++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
@@ -59,7 +59,8 @@ void mtk_rmw(struct mtk_pinctrl *pctl, u32 reg, u32 mask, u32 set)
 	mtk_w32(pctl, reg, val);
 }
 
-static int mtk_hw_pin_field_lookup(struct mtk_pinctrl *hw, int pin,
+static int mtk_hw_pin_field_lookup(struct mtk_pinctrl *hw,
+				   const struct mtk_pin_desc *desc,
 				   const struct mtk_pin_reg_calc *rc,
 				   struct mtk_pin_field *pfd)
 {
@@ -70,13 +71,14 @@ static int mtk_hw_pin_field_lookup(struct mtk_pinctrl *hw, int pin,
 	e = c + rc->nranges;
 
 	while (c < e) {
-		if (pin >= c->s_pin && pin <= c->e_pin)
+		if (desc->number >= c->s_pin && desc->number <= c->e_pin)
 			break;
 		c++;
 	}
 
 	if (c >= e) {
-		dev_err(hw->dev, "Out of range for pin = %d\n", pin);
+		dev_err(hw->dev, "Out of range for pin = %d (%s)\n",
+			desc->number, desc->name);
 		return -EINVAL;
 	}
 
@@ -84,7 +86,8 @@ static int mtk_hw_pin_field_lookup(struct mtk_pinctrl *hw, int pin,
 	 * if c->fixed is held, that determines the all the pins in the
 	 * range use the same field with the s_pin.
 	 */
-	bits = c->fixed ? c->s_bit : c->s_bit + (pin - c->s_pin) * (c->x_bits);
+	bits = c->fixed ? c->s_bit : c->s_bit +
+	       (desc->number - c->s_pin) * (c->x_bits);
 
 	/* Fill pfd from bits. For example 32-bit register applied is assumed
 	 * when c->sz_reg is equal to 32.
@@ -102,7 +105,8 @@ static int mtk_hw_pin_field_lookup(struct mtk_pinctrl *hw, int pin,
 	return 0;
 }
 
-static int mtk_hw_pin_field_get(struct mtk_pinctrl *hw, int pin,
+static int mtk_hw_pin_field_get(struct mtk_pinctrl *hw,
+				const struct mtk_pin_desc *desc,
 				int field, struct mtk_pin_field *pfd)
 {
 	const struct mtk_pin_reg_calc *rc;
@@ -119,7 +123,7 @@ static int mtk_hw_pin_field_get(struct mtk_pinctrl *hw, int pin,
 		return -EINVAL;
 	}
 
-	return mtk_hw_pin_field_lookup(hw, pin, rc, pfd);
+	return mtk_hw_pin_field_lookup(hw, desc, rc, pfd);
 }
 
 static void mtk_hw_bits_part(struct mtk_pin_field *pf, int *h, int *l)
@@ -155,12 +159,13 @@ static void mtk_hw_read_cross_field(struct mtk_pinctrl *hw,
 	*value = (h << nbits_l) | l;
 }
 
-int mtk_hw_set_value(struct mtk_pinctrl *hw, int pin, int field, int value)
+int mtk_hw_set_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc,
+		     int field, int value)
 {
 	struct mtk_pin_field pf;
 	int err;
 
-	err = mtk_hw_pin_field_get(hw, pin, field, &pf);
+	err = mtk_hw_pin_field_get(hw, desc, field, &pf);
 	if (err)
 		return err;
 
@@ -173,12 +178,13 @@ int mtk_hw_set_value(struct mtk_pinctrl *hw, int pin, int field, int value)
 	return 0;
 }
 
-int mtk_hw_get_value(struct mtk_pinctrl *hw, int pin, int field, int *value)
+int mtk_hw_get_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc,
+		     int field, int *value)
 {
 	struct mtk_pin_field pf;
 	int err;
 
-	err = mtk_hw_pin_field_get(hw, pin, field, &pf);
+	err = mtk_hw_pin_field_get(hw, desc, field, &pf);
 	if (err)
 		return err;
 
@@ -196,12 +202,12 @@ int mtk_pinconf_bias_disable_set(struct mtk_pinctrl *hw,
 {
 	int err;
 
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PU,
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PU,
 			       MTK_DISABLE);
 	if (err)
 		return err;
 
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PD,
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PD,
 			       MTK_DISABLE);
 	if (err)
 		return err;
@@ -215,11 +221,11 @@ int mtk_pinconf_bias_disable_get(struct mtk_pinctrl *hw,
 	int v, v2;
 	int err;
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_PU, &v);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PU, &v);
 	if (err)
 		return err;
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_PD, &v2);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PD, &v2);
 	if (err)
 		return err;
 
@@ -238,11 +244,11 @@ int mtk_pinconf_bias_set(struct mtk_pinctrl *hw,
 
 	arg = pullup ? 1 : 2;
 
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PU, arg & 1);
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PU, arg & 1);
 	if (err)
 		return err;
 
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PD,
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PD,
 			       !!(arg & 2));
 	if (err)
 		return err;
@@ -257,7 +263,7 @@ int mtk_pinconf_bias_get(struct mtk_pinctrl *hw,
 
 	reg = pullup ? PINCTRL_PIN_REG_PU : PINCTRL_PIN_REG_PD;
 
-	err = mtk_hw_get_value(hw, desc->number, reg, &v);
+	err = mtk_hw_get_value(hw, desc, reg, &v);
 	if (err)
 		return err;
 
@@ -275,7 +281,7 @@ int mtk_pinconf_bias_disable_set_rev1(struct mtk_pinctrl *hw,
 {
 	int err;
 
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PULLEN,
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLEN,
 			       MTK_DISABLE);
 	if (err)
 		return err;
@@ -288,7 +294,7 @@ int mtk_pinconf_bias_disable_get_rev1(struct mtk_pinctrl *hw,
 {
 	int v, err;
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_PULLEN, &v);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLEN, &v);
 	if (err)
 		return err;
 
@@ -307,12 +313,12 @@ int mtk_pinconf_bias_set_rev1(struct mtk_pinctrl *hw,
 
 	arg = pullup ? MTK_PULLUP : MTK_PULLDOWN;
 
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PULLEN,
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLEN,
 			       MTK_ENABLE);
 	if (err)
 		return err;
 
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PULLSEL, arg);
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLSEL, arg);
 	if (err)
 		return err;
 
@@ -325,14 +331,14 @@ int mtk_pinconf_bias_get_rev1(struct mtk_pinctrl *hw,
 {
 	int err, v;
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_PULLEN, &v);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLEN, &v);
 	if (err)
 		return err;
 
 	if (v == MTK_DISABLE)
 		return -EINVAL;
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_PULLSEL, &v);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLSEL, &v);
 	if (err)
 		return err;
 
@@ -359,12 +365,12 @@ int mtk_pinconf_drive_set(struct mtk_pinctrl *hw,
 	 */
 	if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) {
 		arg = (arg / tb->step - 1) * tb->scal;
-		err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_E4,
+		err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_E4,
 				       arg & 0x1);
 		if (err)
 			return err;
 
-		err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_E8,
+		err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_E8,
 				       (arg & 0x2) >> 1);
 		if (err)
 			return err;
@@ -381,11 +387,11 @@ int mtk_pinconf_drive_get(struct mtk_pinctrl *hw,
 
 	tb = &mtk_drive[desc->drv_n];
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_E4, &val1);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_E4, &val1);
 	if (err)
 		return err;
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_E8, &val2);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_E8, &val2);
 	if (err)
 		return err;
 
@@ -409,7 +415,7 @@ int mtk_pinconf_drive_set_rev1(struct mtk_pinctrl *hw,
 	if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) {
 		arg = (arg / tb->step - 1) * tb->scal;
 
-		err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_DRV,
+		err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DRV,
 				       arg);
 		if (err)
 			return err;
@@ -426,7 +432,7 @@ int mtk_pinconf_drive_get_rev1(struct mtk_pinctrl *hw,
 
 	tb = &mtk_drive[desc->drv_n];
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_DRV, &val1);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DRV, &val1);
 	if (err)
 		return err;
 
@@ -446,18 +452,18 @@ int mtk_pinconf_adv_pull_set(struct mtk_pinctrl *hw,
 	 * 10K on & 50K (75K) off, when (R0, R1) = (1, 0);
 	 * 10K on & 50K (75K) on, when (R0, R1) = (1, 1)
 	 */
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_R0, arg & 1);
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_R0, arg & 1);
 	if (err)
 		return 0;
 
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_R1,
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_R1,
 			       !!(arg & 2));
 	if (err)
 		return 0;
 
 	arg = pullup ? 0 : 1;
 
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PUPD, arg);
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PUPD, arg);
 
 	return err;
 }
@@ -469,7 +475,7 @@ int mtk_pinconf_adv_pull_get(struct mtk_pinctrl *hw,
 	u32 t, t2;
 	int err;
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_PUPD, &t);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PUPD, &t);
 	if (err)
 		return err;
 
@@ -477,11 +483,11 @@ int mtk_pinconf_adv_pull_get(struct mtk_pinctrl *hw,
 	if (pullup ^ !t)
 		return -EINVAL;
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_R0, &t);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_R0, &t);
 	if (err)
 		return err;
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_R1, &t2);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_R1, &t2);
 	if (err)
 		return err;
 
diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h
index d90788b..6e66bdc 100644
--- a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h
+++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h
@@ -192,8 +192,10 @@ struct mtk_pinctrl {
 
 void mtk_rmw(struct mtk_pinctrl *pctl, u32 reg, u32 mask, u32 set);
 
-int mtk_hw_set_value(struct mtk_pinctrl *hw, int pin, int field, int value);
-int mtk_hw_get_value(struct mtk_pinctrl *hw, int pin, int field, int *value);
+int mtk_hw_set_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc,
+		     int field, int value);
+int mtk_hw_get_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc,
+		     int field, int *value);
 
 int mtk_pinconf_bias_disable_set(struct mtk_pinctrl *hw,
 				 const struct mtk_pin_desc *desc);
-- 
2.7.4


WARNING: multiple messages have this Message-ID (diff)
From: sean.wang@mediatek.com (sean.wang at mediatek.com)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 13/22] pinctrl: mediatek: use pin descriptor all in pinctrl-mtk-common-v2.c
Date: Sat, 8 Sep 2018 19:07:29 +0800	[thread overview]
Message-ID: <f7d9fa1721c8d75509682a20c014ceb461495f1c.1536404280.git.sean.wang@mediatek.com> (raw)
In-Reply-To: <cover.1536404280.git.sean.wang@mediatek.com>

From: Sean Wang <sean.wang@mediatek.com>

all use pin descriptor instead in pinctrl-mtk-common-v2.c for the
consistency and extensibility.

Signed-off-by: Sean Wang <sean.wang@mediatek.com>
---
 drivers/pinctrl/mediatek/pinctrl-moore.c         | 66 +++++++++++++-------
 drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c | 76 +++++++++++++-----------
 drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h |  6 +-
 3 files changed, 88 insertions(+), 60 deletions(-)

diff --git a/drivers/pinctrl/mediatek/pinctrl-moore.c b/drivers/pinctrl/mediatek/pinctrl-moore.c
index 219cfce..2f3e3b5 100644
--- a/drivers/pinctrl/mediatek/pinctrl-moore.c
+++ b/drivers/pinctrl/mediatek/pinctrl-moore.c
@@ -54,9 +54,13 @@ static int mtk_pinmux_set_mux(struct pinctrl_dev *pctldev,
 		func->name, grp->name);
 
 	for (i = 0; i < grp->num_pins; i++) {
+		const struct mtk_pin_desc *desc;
 		int *pin_modes = grp->data;
+		int pin = grp->pins[i];
 
-		mtk_hw_set_value(hw, grp->pins[i], PINCTRL_PIN_REG_MODE,
+		desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
+
+		mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_MODE,
 				 pin_modes[i]);
 	}
 
@@ -68,8 +72,12 @@ static int mtk_pinmux_gpio_request_enable(struct pinctrl_dev *pctldev,
 					  unsigned int pin)
 {
 	struct mtk_pinctrl *hw = pinctrl_dev_get_drvdata(pctldev);
+	const struct mtk_pin_desc *desc;
+
+	desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
 
-	return mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_MODE, hw->soc->gpio_m);
+	return mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_MODE,
+				hw->soc->gpio_m);
 }
 
 static int mtk_pinmux_gpio_set_direction(struct pinctrl_dev *pctldev,
@@ -77,9 +85,12 @@ static int mtk_pinmux_gpio_set_direction(struct pinctrl_dev *pctldev,
 					 unsigned int pin, bool input)
 {
 	struct mtk_pinctrl *hw = pinctrl_dev_get_drvdata(pctldev);
+	const struct mtk_pin_desc *desc;
+
+	desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
 
 	/* hardware would take 0 as input direction */
-	return mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_DIR, !input);
+	return mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR, !input);
 }
 
 static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
@@ -121,7 +132,7 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
 		}
 		break;
 	case PIN_CONFIG_SLEW_RATE:
-		err = mtk_hw_get_value(hw, pin, PINCTRL_PIN_REG_SR, &val);
+		err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_SR, &val);
 		if (err)
 			return err;
 
@@ -131,7 +142,7 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
 		break;
 	case PIN_CONFIG_INPUT_ENABLE:
 	case PIN_CONFIG_OUTPUT_ENABLE:
-		err = mtk_hw_get_value(hw, pin, PINCTRL_PIN_REG_DIR, &val);
+		err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DIR, &val);
 		if (err)
 			return err;
 
@@ -142,11 +153,11 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
 
 		break;
 	case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
-		err = mtk_hw_get_value(hw, pin, PINCTRL_PIN_REG_DIR, &val);
+		err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DIR, &val);
 		if (err)
 			return err;
 
-		err = mtk_hw_get_value(hw, pin, PINCTRL_PIN_REG_SMT, &val2);
+		err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_SMT, &val2);
 		if (err)
 			return err;
 
@@ -168,7 +179,7 @@ static int mtk_pinconf_get(struct pinctrl_dev *pctldev,
 		reg = (param == MTK_PIN_CONFIG_TDSEL) ?
 		       PINCTRL_PIN_REG_TDSEL : PINCTRL_PIN_REG_RDSEL;
 
-		err = mtk_hw_get_value(hw, pin, reg, &val);
+		err = mtk_hw_get_value(hw, desc, reg, &val);
 		if (err)
 			return err;
 
@@ -240,12 +251,12 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
 			}
 			break;
 		case PIN_CONFIG_OUTPUT_ENABLE:
-			err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_SMT,
+			err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT,
 					       MTK_DISABLE);
 			if (err)
 				goto err;
 
-			err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_DIR,
+			err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
 					       MTK_OUTPUT);
 			if (err)
 				goto err;
@@ -253,29 +264,29 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
 		case PIN_CONFIG_INPUT_ENABLE:
 
 			if (hw->soc->ies_present) {
-				mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_IES,
+				mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_IES,
 						 MTK_ENABLE);
 			}
 
-			err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_DIR,
+			err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
 					       MTK_INPUT);
 			if (err)
 				goto err;
 			break;
 		case PIN_CONFIG_SLEW_RATE:
-			err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_SR,
+			err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SR,
 					       arg);
 			if (err)
 				goto err;
 
 			break;
 		case PIN_CONFIG_OUTPUT:
-			err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_DIR,
+			err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
 					       MTK_OUTPUT);
 			if (err)
 				goto err;
 
-			err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_DO,
+			err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DO,
 					       arg);
 			if (err)
 				goto err;
@@ -285,12 +296,12 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
 			 * arg = 0: Output mode & SMT disable
 			 */
 			arg = arg ? 2 : 1;
-			err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_DIR,
+			err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR,
 					       arg & 1);
 			if (err)
 				goto err;
 
-			err = mtk_hw_set_value(hw, pin, PINCTRL_PIN_REG_SMT,
+			err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT,
 					       !!(arg & 2));
 			if (err)
 				goto err;
@@ -309,7 +320,7 @@ static int mtk_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
 			reg = (param == MTK_PIN_CONFIG_TDSEL) ?
 			       PINCTRL_PIN_REG_TDSEL : PINCTRL_PIN_REG_RDSEL;
 
-			err = mtk_hw_set_value(hw, pin, reg, arg);
+			err = mtk_hw_set_value(hw, desc, reg, arg);
 			if (err)
 				goto err;
 			break;
@@ -419,9 +430,12 @@ static struct pinctrl_desc mtk_desc = {
 static int mtk_gpio_get(struct gpio_chip *chip, unsigned int gpio)
 {
 	struct mtk_pinctrl *hw = gpiochip_get_data(chip);
+	const struct mtk_pin_desc *desc;
 	int value, err;
 
-	err = mtk_hw_get_value(hw, gpio, PINCTRL_PIN_REG_DI, &value);
+	desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio];
+
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DI, &value);
 	if (err)
 		return err;
 
@@ -431,8 +445,11 @@ static int mtk_gpio_get(struct gpio_chip *chip, unsigned int gpio)
 static void mtk_gpio_set(struct gpio_chip *chip, unsigned int gpio, int value)
 {
 	struct mtk_pinctrl *hw = gpiochip_get_data(chip);
+	const struct mtk_pin_desc *desc;
 
-	mtk_hw_set_value(hw, gpio, PINCTRL_PIN_REG_DO, !!value);
+	desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio];
+
+	mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DO, !!value);
 }
 
 static int mtk_gpio_direction_input(struct gpio_chip *chip, unsigned int gpio)
@@ -620,6 +637,7 @@ static int mtk_xt_get_gpio_state(void *data, unsigned long eint_n)
 static int mtk_xt_set_gpio_as_eint(void *data, unsigned long eint_n)
 {
 	struct mtk_pinctrl *hw = (struct mtk_pinctrl *)data;
+	const struct mtk_pin_desc *desc;
 	struct gpio_chip *gpio_chip;
 	unsigned int gpio_n;
 	int err;
@@ -628,16 +646,18 @@ static int mtk_xt_set_gpio_as_eint(void *data, unsigned long eint_n)
 	if (err)
 		return err;
 
-	err = mtk_hw_set_value(hw, gpio_n, PINCTRL_PIN_REG_MODE,
+	desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio_n];
+
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_MODE,
 			       hw->soc->eint_m);
 	if (err)
 		return err;
 
-	err = mtk_hw_set_value(hw, gpio_n, PINCTRL_PIN_REG_DIR, MTK_INPUT);
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DIR, MTK_INPUT);
 	if (err)
 		return err;
 
-	err = mtk_hw_set_value(hw, gpio_n, PINCTRL_PIN_REG_SMT, MTK_ENABLE);
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_SMT, MTK_ENABLE);
 	if (err)
 		return err;
 
diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
index 86eefe8..ed88b96 100644
--- a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
+++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
@@ -59,7 +59,8 @@ void mtk_rmw(struct mtk_pinctrl *pctl, u32 reg, u32 mask, u32 set)
 	mtk_w32(pctl, reg, val);
 }
 
-static int mtk_hw_pin_field_lookup(struct mtk_pinctrl *hw, int pin,
+static int mtk_hw_pin_field_lookup(struct mtk_pinctrl *hw,
+				   const struct mtk_pin_desc *desc,
 				   const struct mtk_pin_reg_calc *rc,
 				   struct mtk_pin_field *pfd)
 {
@@ -70,13 +71,14 @@ static int mtk_hw_pin_field_lookup(struct mtk_pinctrl *hw, int pin,
 	e = c + rc->nranges;
 
 	while (c < e) {
-		if (pin >= c->s_pin && pin <= c->e_pin)
+		if (desc->number >= c->s_pin && desc->number <= c->e_pin)
 			break;
 		c++;
 	}
 
 	if (c >= e) {
-		dev_err(hw->dev, "Out of range for pin = %d\n", pin);
+		dev_err(hw->dev, "Out of range for pin = %d (%s)\n",
+			desc->number, desc->name);
 		return -EINVAL;
 	}
 
@@ -84,7 +86,8 @@ static int mtk_hw_pin_field_lookup(struct mtk_pinctrl *hw, int pin,
 	 * if c->fixed is held, that determines the all the pins in the
 	 * range use the same field with the s_pin.
 	 */
-	bits = c->fixed ? c->s_bit : c->s_bit + (pin - c->s_pin) * (c->x_bits);
+	bits = c->fixed ? c->s_bit : c->s_bit +
+	       (desc->number - c->s_pin) * (c->x_bits);
 
 	/* Fill pfd from bits. For example 32-bit register applied is assumed
 	 * when c->sz_reg is equal to 32.
@@ -102,7 +105,8 @@ static int mtk_hw_pin_field_lookup(struct mtk_pinctrl *hw, int pin,
 	return 0;
 }
 
-static int mtk_hw_pin_field_get(struct mtk_pinctrl *hw, int pin,
+static int mtk_hw_pin_field_get(struct mtk_pinctrl *hw,
+				const struct mtk_pin_desc *desc,
 				int field, struct mtk_pin_field *pfd)
 {
 	const struct mtk_pin_reg_calc *rc;
@@ -119,7 +123,7 @@ static int mtk_hw_pin_field_get(struct mtk_pinctrl *hw, int pin,
 		return -EINVAL;
 	}
 
-	return mtk_hw_pin_field_lookup(hw, pin, rc, pfd);
+	return mtk_hw_pin_field_lookup(hw, desc, rc, pfd);
 }
 
 static void mtk_hw_bits_part(struct mtk_pin_field *pf, int *h, int *l)
@@ -155,12 +159,13 @@ static void mtk_hw_read_cross_field(struct mtk_pinctrl *hw,
 	*value = (h << nbits_l) | l;
 }
 
-int mtk_hw_set_value(struct mtk_pinctrl *hw, int pin, int field, int value)
+int mtk_hw_set_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc,
+		     int field, int value)
 {
 	struct mtk_pin_field pf;
 	int err;
 
-	err = mtk_hw_pin_field_get(hw, pin, field, &pf);
+	err = mtk_hw_pin_field_get(hw, desc, field, &pf);
 	if (err)
 		return err;
 
@@ -173,12 +178,13 @@ int mtk_hw_set_value(struct mtk_pinctrl *hw, int pin, int field, int value)
 	return 0;
 }
 
-int mtk_hw_get_value(struct mtk_pinctrl *hw, int pin, int field, int *value)
+int mtk_hw_get_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc,
+		     int field, int *value)
 {
 	struct mtk_pin_field pf;
 	int err;
 
-	err = mtk_hw_pin_field_get(hw, pin, field, &pf);
+	err = mtk_hw_pin_field_get(hw, desc, field, &pf);
 	if (err)
 		return err;
 
@@ -196,12 +202,12 @@ int mtk_pinconf_bias_disable_set(struct mtk_pinctrl *hw,
 {
 	int err;
 
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PU,
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PU,
 			       MTK_DISABLE);
 	if (err)
 		return err;
 
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PD,
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PD,
 			       MTK_DISABLE);
 	if (err)
 		return err;
@@ -215,11 +221,11 @@ int mtk_pinconf_bias_disable_get(struct mtk_pinctrl *hw,
 	int v, v2;
 	int err;
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_PU, &v);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PU, &v);
 	if (err)
 		return err;
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_PD, &v2);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PD, &v2);
 	if (err)
 		return err;
 
@@ -238,11 +244,11 @@ int mtk_pinconf_bias_set(struct mtk_pinctrl *hw,
 
 	arg = pullup ? 1 : 2;
 
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PU, arg & 1);
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PU, arg & 1);
 	if (err)
 		return err;
 
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PD,
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PD,
 			       !!(arg & 2));
 	if (err)
 		return err;
@@ -257,7 +263,7 @@ int mtk_pinconf_bias_get(struct mtk_pinctrl *hw,
 
 	reg = pullup ? PINCTRL_PIN_REG_PU : PINCTRL_PIN_REG_PD;
 
-	err = mtk_hw_get_value(hw, desc->number, reg, &v);
+	err = mtk_hw_get_value(hw, desc, reg, &v);
 	if (err)
 		return err;
 
@@ -275,7 +281,7 @@ int mtk_pinconf_bias_disable_set_rev1(struct mtk_pinctrl *hw,
 {
 	int err;
 
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PULLEN,
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLEN,
 			       MTK_DISABLE);
 	if (err)
 		return err;
@@ -288,7 +294,7 @@ int mtk_pinconf_bias_disable_get_rev1(struct mtk_pinctrl *hw,
 {
 	int v, err;
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_PULLEN, &v);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLEN, &v);
 	if (err)
 		return err;
 
@@ -307,12 +313,12 @@ int mtk_pinconf_bias_set_rev1(struct mtk_pinctrl *hw,
 
 	arg = pullup ? MTK_PULLUP : MTK_PULLDOWN;
 
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PULLEN,
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLEN,
 			       MTK_ENABLE);
 	if (err)
 		return err;
 
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PULLSEL, arg);
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLSEL, arg);
 	if (err)
 		return err;
 
@@ -325,14 +331,14 @@ int mtk_pinconf_bias_get_rev1(struct mtk_pinctrl *hw,
 {
 	int err, v;
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_PULLEN, &v);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLEN, &v);
 	if (err)
 		return err;
 
 	if (v == MTK_DISABLE)
 		return -EINVAL;
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_PULLSEL, &v);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLSEL, &v);
 	if (err)
 		return err;
 
@@ -359,12 +365,12 @@ int mtk_pinconf_drive_set(struct mtk_pinctrl *hw,
 	 */
 	if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) {
 		arg = (arg / tb->step - 1) * tb->scal;
-		err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_E4,
+		err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_E4,
 				       arg & 0x1);
 		if (err)
 			return err;
 
-		err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_E8,
+		err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_E8,
 				       (arg & 0x2) >> 1);
 		if (err)
 			return err;
@@ -381,11 +387,11 @@ int mtk_pinconf_drive_get(struct mtk_pinctrl *hw,
 
 	tb = &mtk_drive[desc->drv_n];
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_E4, &val1);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_E4, &val1);
 	if (err)
 		return err;
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_E8, &val2);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_E8, &val2);
 	if (err)
 		return err;
 
@@ -409,7 +415,7 @@ int mtk_pinconf_drive_set_rev1(struct mtk_pinctrl *hw,
 	if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) {
 		arg = (arg / tb->step - 1) * tb->scal;
 
-		err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_DRV,
+		err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DRV,
 				       arg);
 		if (err)
 			return err;
@@ -426,7 +432,7 @@ int mtk_pinconf_drive_get_rev1(struct mtk_pinctrl *hw,
 
 	tb = &mtk_drive[desc->drv_n];
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_DRV, &val1);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DRV, &val1);
 	if (err)
 		return err;
 
@@ -446,18 +452,18 @@ int mtk_pinconf_adv_pull_set(struct mtk_pinctrl *hw,
 	 * 10K on & 50K (75K) off, when (R0, R1) = (1, 0);
 	 * 10K on & 50K (75K) on, when (R0, R1) = (1, 1)
 	 */
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_R0, arg & 1);
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_R0, arg & 1);
 	if (err)
 		return 0;
 
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_R1,
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_R1,
 			       !!(arg & 2));
 	if (err)
 		return 0;
 
 	arg = pullup ? 0 : 1;
 
-	err = mtk_hw_set_value(hw, desc->number, PINCTRL_PIN_REG_PUPD, arg);
+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PUPD, arg);
 
 	return err;
 }
@@ -469,7 +475,7 @@ int mtk_pinconf_adv_pull_get(struct mtk_pinctrl *hw,
 	u32 t, t2;
 	int err;
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_PUPD, &t);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PUPD, &t);
 	if (err)
 		return err;
 
@@ -477,11 +483,11 @@ int mtk_pinconf_adv_pull_get(struct mtk_pinctrl *hw,
 	if (pullup ^ !t)
 		return -EINVAL;
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_R0, &t);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_R0, &t);
 	if (err)
 		return err;
 
-	err = mtk_hw_get_value(hw, desc->number, PINCTRL_PIN_REG_R1, &t2);
+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_R1, &t2);
 	if (err)
 		return err;
 
diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h
index d90788b..6e66bdc 100644
--- a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h
+++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h
@@ -192,8 +192,10 @@ struct mtk_pinctrl {
 
 void mtk_rmw(struct mtk_pinctrl *pctl, u32 reg, u32 mask, u32 set);
 
-int mtk_hw_set_value(struct mtk_pinctrl *hw, int pin, int field, int value);
-int mtk_hw_get_value(struct mtk_pinctrl *hw, int pin, int field, int *value);
+int mtk_hw_set_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc,
+		     int field, int value);
+int mtk_hw_get_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc,
+		     int field, int *value);
 
 int mtk_pinconf_bias_disable_set(struct mtk_pinctrl *hw,
 				 const struct mtk_pin_desc *desc);
-- 
2.7.4

  parent reply	other threads:[~2018-09-08 11:07 UTC|newest]

Thread overview: 140+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-08 11:07 [PATCH v2 00/22] Unify MediaTek pinctrl in preparation for MT8183 and MT6765 sean.wang
2018-09-08 11:07 ` sean.wang at mediatek.com
2018-09-08 11:07 ` sean.wang
2018-09-08 11:07 ` [PATCH v2 03/22] pinctrl: mediatek: extend struct mtk_pin_field_calc to pinctrl-mtk-common-v2.c sean.wang
2018-09-08 11:07   ` sean.wang at mediatek.com
2018-09-08 11:07   ` sean.wang
2018-09-18 19:43   ` Linus Walleij
2018-09-18 19:43     ` Linus Walleij
2018-09-18 19:43     ` Linus Walleij
     [not found] ` <cover.1536404280.git.sean.wang-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
2018-09-08 11:07   ` [PATCH v2 01/22] pinctrl: mediatek: add pinctrl-mtk-common-v2 for all MediaTek pinctrls sean.wang-NuS5LvNUpcJWk0Htik3J/w
2018-09-08 11:07     ` sean.wang at mediatek.com
2018-09-18 19:36     ` Linus Walleij
2018-09-18 19:36       ` Linus Walleij
2018-09-18 19:36       ` Linus Walleij
2018-09-08 11:07   ` [PATCH v2 02/22] pinctrl: mediatek: add pinctrl-moore that implements the generic pinctrl dt-bindings sean.wang-NuS5LvNUpcJWk0Htik3J/w
2018-09-08 11:07     ` sean.wang at mediatek.com
2018-09-18 19:42     ` Linus Walleij
2018-09-18 19:42       ` Linus Walleij
2018-09-18 19:42       ` Linus Walleij
2018-09-08 11:07   ` [PATCH v2 04/22] pinctrl: mediatek: extend struct mtk_pin_desc to pinctrl-mtk-common-v2.c sean.wang-NuS5LvNUpcJWk0Htik3J/w
2018-09-08 11:07     ` sean.wang at mediatek.com
2018-09-18 19:44     ` Linus Walleij
2018-09-18 19:44       ` Linus Walleij
2018-09-18 19:44       ` Linus Walleij
2018-09-08 11:07   ` [PATCH v2 05/22] pinctrl: mediatek: extend struct mtk_pin_soc " sean.wang-NuS5LvNUpcJWk0Htik3J/w
2018-09-08 11:07     ` sean.wang at mediatek.com
2018-09-18 19:45     ` Linus Walleij
2018-09-18 19:45       ` Linus Walleij
2018-09-18 19:45       ` Linus Walleij
2018-09-08 11:07   ` [PATCH v2 06/22] pinctrl: mediatek: add driving strength related support " sean.wang-NuS5LvNUpcJWk0Htik3J/w
2018-09-08 11:07     ` sean.wang at mediatek.com
2018-09-18 19:46     ` Linus Walleij
2018-09-18 19:46       ` Linus Walleij
2018-09-18 19:46       ` Linus Walleij
2018-09-08 11:07   ` [PATCH v2 07/22] pinctrl: mediatek: add drv register " sean.wang-NuS5LvNUpcJWk0Htik3J/w
2018-09-08 11:07     ` sean.wang at mediatek.com
2018-09-18 19:47     ` Linus Walleij
2018-09-18 19:47       ` Linus Walleij
2018-09-18 19:47       ` Linus Walleij
2018-09-08 11:07   ` [PATCH v2 08/22] pinctrl: mediatek: add pull related " sean.wang-NuS5LvNUpcJWk0Htik3J/w
2018-09-08 11:07     ` sean.wang at mediatek.com
2018-09-18 19:48     ` Linus Walleij
2018-09-18 19:48       ` Linus Walleij
2018-09-18 19:48       ` Linus Walleij
2018-09-08 11:07   ` [PATCH v2 09/22] pinctrl: mediatek: add advanced " sean.wang-NuS5LvNUpcJWk0Htik3J/w
2018-09-08 11:07     ` sean.wang at mediatek.com
2018-09-18 19:49     ` Linus Walleij
2018-09-18 19:49       ` Linus Walleij
2018-09-18 19:49       ` Linus Walleij
2018-09-08 11:07   ` [PATCH v2 10/22] pinctrl: mediatek: add ies register " sean.wang-NuS5LvNUpcJWk0Htik3J/w
2018-09-08 11:07     ` sean.wang at mediatek.com
2018-09-18 19:50     ` Linus Walleij
2018-09-18 19:50       ` Linus Walleij
2018-09-18 19:50       ` Linus Walleij
2018-09-08 11:07   ` [PATCH v2 11/22] pinctrl: mediatek: add pullen, pullsel " sean.wang-NuS5LvNUpcJWk0Htik3J/w
2018-09-08 11:07     ` sean.wang at mediatek.com
2018-09-18 19:51     ` Linus Walleij
2018-09-18 19:51       ` Linus Walleij
2018-09-18 19:51       ` Linus Walleij
2018-09-08 11:07 ` [PATCH v2 12/22] pinctrl: mediatek: add MT7623 pinctrl driver based on generic pinctrl binding sean.wang
2018-09-08 11:07   ` sean.wang at mediatek.com
2018-09-08 11:07   ` sean.wang
2018-09-18 19:52   ` Linus Walleij
2018-09-18 19:52     ` Linus Walleij
2018-09-18 19:52     ` Linus Walleij
2018-09-08 11:07 ` sean.wang [this message]
2018-09-08 11:07   ` [PATCH v2 13/22] pinctrl: mediatek: use pin descriptor all in pinctrl-mtk-common-v2.c sean.wang at mediatek.com
2018-09-08 11:07   ` sean.wang
2018-09-18 19:53   ` Linus Walleij
2018-09-18 19:53     ` Linus Walleij
2018-09-18 19:53     ` Linus Walleij
2018-09-08 11:07 ` [PATCH v2 14/22] pinctrl: mediatek: add multiple register bases support to pinctrl-mtk-common-v2.c sean.wang
2018-09-08 11:07   ` sean.wang at mediatek.com
2018-09-08 11:07   ` sean.wang
2018-09-18 19:56   ` Linus Walleij
2018-09-18 19:56     ` Linus Walleij
2018-09-18 19:56     ` Linus Walleij
2018-09-08 11:07 ` [PATCH v2 15/22] pinctrl: mediatek: adjust error code and message when some register not supported is found sean.wang
2018-09-08 11:07   ` sean.wang at mediatek.com
2018-09-08 11:07   ` sean.wang
2018-09-18 19:57   ` Linus Walleij
2018-09-18 19:57     ` Linus Walleij
2018-09-18 19:57     ` Linus Walleij
2018-09-08 11:07 ` [PATCH v2 16/22] pinctrl: mediatek: extend struct mtk_pin_desc which per-pin driver depends on sean.wang
2018-09-08 11:07   ` sean.wang at mediatek.com
2018-09-08 11:07   ` sean.wang
2018-09-18 19:58   ` Linus Walleij
2018-09-18 19:58     ` Linus Walleij
2018-09-18 19:58     ` Linus Walleij
2018-09-08 11:07 ` [PATCH v2 17/22] pinctrl: mediatek: add pinctrl-paris that implements the vendor dt-bindings sean.wang
2018-09-08 11:07   ` sean.wang at mediatek.com
2018-09-08 11:07   ` sean.wang
2018-09-18 19:59   ` Linus Walleij
2018-09-18 19:59     ` Linus Walleij
2018-09-18 19:59     ` Linus Walleij
2018-09-08 11:07 ` [PATCH v2 18/22] pinctrl: mediatek: add MT8183 pinctrl driver sean.wang
2018-09-08 11:07   ` sean.wang at mediatek.com
2018-09-08 11:07   ` sean.wang
2018-09-18 20:01   ` Linus Walleij
2018-09-18 20:01     ` Linus Walleij
2018-09-18 20:01     ` Linus Walleij
2018-09-08 11:07 ` [PATCH v2 19/22] pinctrl: mediatek: extend advanced pull support in pinctrl-mtk-common-v2.c sean.wang
2018-09-08 11:07   ` sean.wang at mediatek.com
2018-09-08 11:07   ` sean.wang
2018-09-18 20:02   ` Linus Walleij
2018-09-18 20:02     ` Linus Walleij
2018-09-18 20:02     ` Linus Walleij
2018-09-08 11:07 ` [PATCH v2 20/22] pintcrl: mediatek: add pull tweaks for I2C related pins on MT8183 sean.wang
2018-09-08 11:07   ` sean.wang at mediatek.com
2018-09-08 11:07   ` sean.wang
2018-09-18 20:03   ` Linus Walleij
2018-09-18 20:03     ` Linus Walleij
2018-09-18 20:03     ` Linus Walleij
2018-09-08 11:07 ` [PATCH v2 21/22] pinctrl: mediatek: extend eint build to pinctrl-mtk-common-v2.c sean.wang
2018-09-08 11:07   ` sean.wang at mediatek.com
2018-09-08 11:07   ` sean.wang
2018-09-08 11:07 ` [PATCH v2 22/22] pinctrl: mediatek: add eint support to MT8183 pinctrl driver sean.wang
2018-09-08 11:07   ` sean.wang at mediatek.com
2018-09-08 11:07   ` sean.wang
2018-09-18 22:07 ` [PATCH v2 00/22] Unify MediaTek pinctrl in preparation for MT8183 and MT6765 Linus Walleij
2018-09-18 22:07   ` Linus Walleij
2018-09-18 22:07   ` Linus Walleij
2018-09-19  2:54   ` Sean Wang
2018-09-19  2:54     ` Sean Wang
2018-09-19  2:54     ` Sean Wang
2018-09-19  4:37     ` Manivannan Sadhasivam
2018-09-19  4:37       ` Manivannan Sadhasivam
2018-09-19  4:37       ` Manivannan Sadhasivam
2018-09-21  4:22       ` Sean Wang
2018-09-21  4:22         ` Sean Wang
2018-09-21  4:22         ` Sean Wang
2018-09-25 10:48         ` Matthias Brugger
2018-09-25 10:48           ` Matthias Brugger
2018-09-25 10:48           ` Matthias Brugger
2018-09-25 13:07           ` Manivannan Sadhasivam
2018-09-25 13:07             ` Manivannan Sadhasivam
2018-09-25 13:07             ` Manivannan Sadhasivam
2018-09-25 13:09             ` Manivannan Sadhasivam
2018-09-25 13:09               ` Manivannan Sadhasivam
2018-09-25 13:09               ` Manivannan Sadhasivam

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f7d9fa1721c8d75509682a20c014ceb461495f1c.1536404280.git.sean.wang@mediatek.com \
    --to=sean.wang@mediatek.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.