diff options
author | Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> | 2013-02-14 16:35:09 -0500 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> | 2013-03-15 08:33:39 -0400 |
commit | 934cb02bab9003bf65afe73e9146a1ea63b26c40 (patch) | |
tree | 4388d27ec6313aa85bf0f9829eb05fbf89dfae4b /drivers/pinctrl/sh-pfc | |
parent | 0b73ee5d534cc6dcb96efb9eac4cf96b40910911 (diff) |
sh-pfc: Add function to retrieve a pin instance from its pin number
This prepares support for sparse pin numbering. The function currently
just performs and indexed lookup in the pins array.
Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/pinctrl/sh-pfc')
-rw-r--r-- | drivers/pinctrl/sh-pfc/core.c | 7 | ||||
-rw-r--r-- | drivers/pinctrl/sh-pfc/core.h | 1 | ||||
-rw-r--r-- | drivers/pinctrl/sh-pfc/gpio.c | 3 | ||||
-rw-r--r-- | drivers/pinctrl/sh-pfc/pinctrl.c | 23 |
4 files changed, 22 insertions, 12 deletions
diff --git a/drivers/pinctrl/sh-pfc/core.c b/drivers/pinctrl/sh-pfc/core.c index 9b5c0319eb77..667db99fb510 100644 --- a/drivers/pinctrl/sh-pfc/core.c +++ b/drivers/pinctrl/sh-pfc/core.c | |||
@@ -78,6 +78,11 @@ static void __iomem *sh_pfc_phys_to_virt(struct sh_pfc *pfc, | |||
78 | return (void __iomem *)address; | 78 | return (void __iomem *)address; |
79 | } | 79 | } |
80 | 80 | ||
81 | struct sh_pfc_pin *sh_pfc_get_pin(struct sh_pfc *pfc, unsigned int pin) | ||
82 | { | ||
83 | return &pfc->info->pins[pin]; | ||
84 | } | ||
85 | |||
81 | static int sh_pfc_enum_in_range(pinmux_enum_t enum_id, struct pinmux_range *r) | 86 | static int sh_pfc_enum_in_range(pinmux_enum_t enum_id, struct pinmux_range *r) |
82 | { | 87 | { |
83 | if (enum_id < r->begin) | 88 | if (enum_id < r->begin) |
@@ -278,7 +283,7 @@ static void sh_pfc_setup_data_regs(struct sh_pfc *pfc) | |||
278 | void sh_pfc_get_data_reg(struct sh_pfc *pfc, unsigned gpio, | 283 | void sh_pfc_get_data_reg(struct sh_pfc *pfc, unsigned gpio, |
279 | struct pinmux_data_reg **drp, int *bitp) | 284 | struct pinmux_data_reg **drp, int *bitp) |
280 | { | 285 | { |
281 | struct sh_pfc_pin *gpiop = &pfc->info->pins[gpio]; | 286 | struct sh_pfc_pin *gpiop = sh_pfc_get_pin(pfc, gpio); |
282 | int k, n; | 287 | int k, n; |
283 | 288 | ||
284 | k = (gpiop->flags & PINMUX_FLAG_DREG) >> PINMUX_FLAG_DREG_SHIFT; | 289 | k = (gpiop->flags & PINMUX_FLAG_DREG) >> PINMUX_FLAG_DREG_SHIFT; |
diff --git a/drivers/pinctrl/sh-pfc/core.h b/drivers/pinctrl/sh-pfc/core.h index a3111b73fb94..6ea3d4f3d05e 100644 --- a/drivers/pinctrl/sh-pfc/core.h +++ b/drivers/pinctrl/sh-pfc/core.h | |||
@@ -49,6 +49,7 @@ void sh_pfc_write_bit(struct pinmux_data_reg *dr, unsigned long in_pos, | |||
49 | unsigned long value); | 49 | unsigned long value); |
50 | void sh_pfc_get_data_reg(struct sh_pfc *pfc, unsigned gpio, | 50 | void sh_pfc_get_data_reg(struct sh_pfc *pfc, unsigned gpio, |
51 | struct pinmux_data_reg **drp, int *bitp); | 51 | struct pinmux_data_reg **drp, int *bitp); |
52 | struct sh_pfc_pin *sh_pfc_get_pin(struct sh_pfc *pfc, unsigned int pin); | ||
52 | int sh_pfc_config_mux(struct sh_pfc *pfc, unsigned mark, int pinmux_type, | 53 | int sh_pfc_config_mux(struct sh_pfc *pfc, unsigned mark, int pinmux_type, |
53 | int cfg_mode); | 54 | int cfg_mode); |
54 | 55 | ||
diff --git a/drivers/pinctrl/sh-pfc/gpio.c b/drivers/pinctrl/sh-pfc/gpio.c index db9af4e548a0..45090d8381a2 100644 --- a/drivers/pinctrl/sh-pfc/gpio.c +++ b/drivers/pinctrl/sh-pfc/gpio.c | |||
@@ -43,8 +43,9 @@ static struct sh_pfc *gpio_to_pfc(struct gpio_chip *gc) | |||
43 | static int gpio_pin_request(struct gpio_chip *gc, unsigned offset) | 43 | static int gpio_pin_request(struct gpio_chip *gc, unsigned offset) |
44 | { | 44 | { |
45 | struct sh_pfc *pfc = gpio_to_pfc(gc); | 45 | struct sh_pfc *pfc = gpio_to_pfc(gc); |
46 | struct sh_pfc_pin *pin = sh_pfc_get_pin(pfc, offset); | ||
46 | 47 | ||
47 | if (pfc->info->pins[offset].enum_id == 0) | 48 | if (pin->enum_id == 0) |
48 | return -EINVAL; | 49 | return -EINVAL; |
49 | 50 | ||
50 | return pinctrl_request_gpio(offset); | 51 | return pinctrl_request_gpio(offset); |
diff --git a/drivers/pinctrl/sh-pfc/pinctrl.c b/drivers/pinctrl/sh-pfc/pinctrl.c index a83f40070b3b..78bd277c01d9 100644 --- a/drivers/pinctrl/sh-pfc/pinctrl.c +++ b/drivers/pinctrl/sh-pfc/pinctrl.c | |||
@@ -119,14 +119,15 @@ static void sh_pfc_noop_disable(struct pinctrl_dev *pctldev, unsigned func, | |||
119 | static int sh_pfc_reconfig_pin(struct sh_pfc *pfc, unsigned offset, | 119 | static int sh_pfc_reconfig_pin(struct sh_pfc *pfc, unsigned offset, |
120 | int new_type) | 120 | int new_type) |
121 | { | 121 | { |
122 | unsigned int mark = pfc->info->pins[offset].enum_id; | 122 | struct sh_pfc_pin *pin = sh_pfc_get_pin(pfc, offset); |
123 | unsigned int mark = pin->enum_id; | ||
123 | unsigned long flags; | 124 | unsigned long flags; |
124 | int pinmux_type; | 125 | int pinmux_type; |
125 | int ret = -EINVAL; | 126 | int ret = -EINVAL; |
126 | 127 | ||
127 | spin_lock_irqsave(&pfc->lock, flags); | 128 | spin_lock_irqsave(&pfc->lock, flags); |
128 | 129 | ||
129 | pinmux_type = pfc->info->pins[offset].flags & PINMUX_FLAG_TYPE; | 130 | pinmux_type = pin->flags & PINMUX_FLAG_TYPE; |
130 | 131 | ||
131 | /* | 132 | /* |
132 | * See if the present config needs to first be de-configured. | 133 | * See if the present config needs to first be de-configured. |
@@ -156,8 +157,8 @@ static int sh_pfc_reconfig_pin(struct sh_pfc *pfc, unsigned offset, | |||
156 | if (sh_pfc_config_mux(pfc, mark, new_type, GPIO_CFG_REQ) != 0) | 157 | if (sh_pfc_config_mux(pfc, mark, new_type, GPIO_CFG_REQ) != 0) |
157 | goto err; | 158 | goto err; |
158 | 159 | ||
159 | pfc->info->pins[offset].flags &= ~PINMUX_FLAG_TYPE; | 160 | pin->flags &= ~PINMUX_FLAG_TYPE; |
160 | pfc->info->pins[offset].flags |= new_type; | 161 | pin->flags |= new_type; |
161 | 162 | ||
162 | ret = 0; | 163 | ret = 0; |
163 | 164 | ||
@@ -173,12 +174,13 @@ static int sh_pfc_gpio_request_enable(struct pinctrl_dev *pctldev, | |||
173 | { | 174 | { |
174 | struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); | 175 | struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); |
175 | struct sh_pfc *pfc = pmx->pfc; | 176 | struct sh_pfc *pfc = pmx->pfc; |
177 | struct sh_pfc_pin *pin = sh_pfc_get_pin(pfc, offset); | ||
176 | unsigned long flags; | 178 | unsigned long flags; |
177 | int ret, pinmux_type; | 179 | int ret, pinmux_type; |
178 | 180 | ||
179 | spin_lock_irqsave(&pfc->lock, flags); | 181 | spin_lock_irqsave(&pfc->lock, flags); |
180 | 182 | ||
181 | pinmux_type = pfc->info->pins[offset].flags & PINMUX_FLAG_TYPE; | 183 | pinmux_type = pin->flags & PINMUX_FLAG_TYPE; |
182 | 184 | ||
183 | switch (pinmux_type) { | 185 | switch (pinmux_type) { |
184 | case PINMUX_TYPE_GPIO: | 186 | case PINMUX_TYPE_GPIO: |
@@ -206,15 +208,15 @@ static void sh_pfc_gpio_disable_free(struct pinctrl_dev *pctldev, | |||
206 | { | 208 | { |
207 | struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); | 209 | struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); |
208 | struct sh_pfc *pfc = pmx->pfc; | 210 | struct sh_pfc *pfc = pmx->pfc; |
211 | struct sh_pfc_pin *pin = sh_pfc_get_pin(pfc, offset); | ||
209 | unsigned long flags; | 212 | unsigned long flags; |
210 | int pinmux_type; | 213 | int pinmux_type; |
211 | 214 | ||
212 | spin_lock_irqsave(&pfc->lock, flags); | 215 | spin_lock_irqsave(&pfc->lock, flags); |
213 | 216 | ||
214 | pinmux_type = pfc->info->pins[offset].flags & PINMUX_FLAG_TYPE; | 217 | pinmux_type = pin->flags & PINMUX_FLAG_TYPE; |
215 | 218 | ||
216 | sh_pfc_config_mux(pfc, pfc->info->pins[offset].enum_id, pinmux_type, | 219 | sh_pfc_config_mux(pfc, pin->enum_id, pinmux_type, GPIO_CFG_FREE); |
217 | GPIO_CFG_FREE); | ||
218 | 220 | ||
219 | spin_unlock_irqrestore(&pfc->lock, flags); | 221 | spin_unlock_irqrestore(&pfc->lock, flags); |
220 | } | 222 | } |
@@ -240,13 +242,14 @@ static const struct pinmux_ops sh_pfc_pinmux_ops = { | |||
240 | .gpio_set_direction = sh_pfc_gpio_set_direction, | 242 | .gpio_set_direction = sh_pfc_gpio_set_direction, |
241 | }; | 243 | }; |
242 | 244 | ||
243 | static int sh_pfc_pinconf_get(struct pinctrl_dev *pctldev, unsigned pin, | 245 | static int sh_pfc_pinconf_get(struct pinctrl_dev *pctldev, unsigned _pin, |
244 | unsigned long *config) | 246 | unsigned long *config) |
245 | { | 247 | { |
246 | struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); | 248 | struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); |
247 | struct sh_pfc *pfc = pmx->pfc; | 249 | struct sh_pfc *pfc = pmx->pfc; |
250 | struct sh_pfc_pin *pin = sh_pfc_get_pin(pfc, _pin); | ||
248 | 251 | ||
249 | *config = pfc->info->pins[pin].flags & PINMUX_FLAG_TYPE; | 252 | *config = pin->flags & PINMUX_FLAG_TYPE; |
250 | 253 | ||
251 | return 0; | 254 | return 0; |
252 | } | 255 | } |