diff options
author | Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> | 2013-02-14 11:36:56 -0500 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> | 2013-03-15 08:33:39 -0400 |
commit | a68fdca9b0447a0e7a85ee378510509be8b70d90 (patch) | |
tree | 2818288e43d82e8c6c7f829775800da3b59c3930 /drivers/pinctrl | |
parent | 17dffe48d18f9c31ba7499af385e10bc02d7c7d9 (diff) |
sh-pfc: Use pinmux identifiers in the pin muxing API
The PFC core exposes a sh_pfc_config_gpio() function that configures
pinmuxing for a given GPIO (either a real GPIO or a function GPIO).
Handling of real and function GPIOs belong to the GPIO layer, move the
GPIO number to mark translation to the caller and rename the function to
sh_pfc_config_mux().
Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/pinctrl')
-rw-r--r-- | drivers/pinctrl/sh-pfc/core.c | 32 | ||||
-rw-r--r-- | drivers/pinctrl/sh-pfc/core.h | 4 | ||||
-rw-r--r-- | drivers/pinctrl/sh-pfc/gpio.c | 14 | ||||
-rw-r--r-- | drivers/pinctrl/sh-pfc/pinctrl.c | 12 |
4 files changed, 21 insertions, 41 deletions
diff --git a/drivers/pinctrl/sh-pfc/core.c b/drivers/pinctrl/sh-pfc/core.c index 22f299993a36..3387f824920b 100644 --- a/drivers/pinctrl/sh-pfc/core.c +++ b/drivers/pinctrl/sh-pfc/core.c | |||
@@ -95,13 +95,6 @@ static bool sh_pfc_gpio_is_pin(struct sh_pfc *pfc, unsigned int gpio) | |||
95 | (pfc->info->pins[gpio].enum_id != 0); | 95 | (pfc->info->pins[gpio].enum_id != 0); |
96 | } | 96 | } |
97 | 97 | ||
98 | static bool sh_pfc_gpio_is_function(struct sh_pfc *pfc, unsigned int gpio) | ||
99 | { | ||
100 | return (gpio >= pfc->info->nr_pins) && | ||
101 | (gpio < pfc->info->nr_pins + pfc->info->nr_func_gpios) && | ||
102 | (pfc->info->func_gpios[gpio - pfc->info->nr_pins].enum_id != 0); | ||
103 | } | ||
104 | |||
105 | static unsigned long sh_pfc_read_raw_reg(void __iomem *mapped_reg, | 98 | static unsigned long sh_pfc_read_raw_reg(void __iomem *mapped_reg, |
106 | unsigned long reg_width) | 99 | unsigned long reg_width) |
107 | { | 100 | { |
@@ -350,41 +343,30 @@ static int sh_pfc_get_config_reg(struct sh_pfc *pfc, pinmux_enum_t enum_id, | |||
350 | return -1; | 343 | return -1; |
351 | } | 344 | } |
352 | 345 | ||
353 | static int sh_pfc_gpio_to_enum(struct sh_pfc *pfc, unsigned gpio, int pos, | 346 | static int sh_pfc_mark_to_enum(struct sh_pfc *pfc, pinmux_enum_t mark, int pos, |
354 | pinmux_enum_t *enum_idp) | 347 | pinmux_enum_t *enum_idp) |
355 | { | 348 | { |
356 | pinmux_enum_t *data = pfc->info->gpio_data; | 349 | pinmux_enum_t *data = pfc->info->gpio_data; |
357 | pinmux_enum_t enum_id; | ||
358 | int k; | 350 | int k; |
359 | 351 | ||
360 | if (sh_pfc_gpio_is_pin(pfc, gpio)) { | ||
361 | enum_id = pfc->info->pins[gpio].enum_id; | ||
362 | } else if (sh_pfc_gpio_is_function(pfc, gpio)) { | ||
363 | unsigned int offset = gpio - pfc->info->nr_pins; | ||
364 | enum_id = pfc->info->func_gpios[offset].enum_id; | ||
365 | } else { | ||
366 | pr_err("non data/mark enum_id for gpio %d\n", gpio); | ||
367 | return -1; | ||
368 | } | ||
369 | |||
370 | if (pos) { | 352 | if (pos) { |
371 | *enum_idp = data[pos + 1]; | 353 | *enum_idp = data[pos + 1]; |
372 | return pos + 1; | 354 | return pos + 1; |
373 | } | 355 | } |
374 | 356 | ||
375 | for (k = 0; k < pfc->info->gpio_data_size; k++) { | 357 | for (k = 0; k < pfc->info->gpio_data_size; k++) { |
376 | if (data[k] == enum_id) { | 358 | if (data[k] == mark) { |
377 | *enum_idp = data[k + 1]; | 359 | *enum_idp = data[k + 1]; |
378 | return k + 1; | 360 | return k + 1; |
379 | } | 361 | } |
380 | } | 362 | } |
381 | 363 | ||
382 | pr_err("cannot locate data/mark enum_id for gpio %d\n", gpio); | 364 | pr_err("cannot locate data/mark enum_id for mark %d\n", mark); |
383 | return -1; | 365 | return -1; |
384 | } | 366 | } |
385 | 367 | ||
386 | int sh_pfc_config_gpio(struct sh_pfc *pfc, unsigned gpio, int pinmux_type, | 368 | int sh_pfc_config_mux(struct sh_pfc *pfc, unsigned mark, int pinmux_type, |
387 | int cfg_mode) | 369 | int cfg_mode) |
388 | { | 370 | { |
389 | struct pinmux_cfg_reg *cr = NULL; | 371 | struct pinmux_cfg_reg *cr = NULL; |
390 | pinmux_enum_t enum_id; | 372 | pinmux_enum_t enum_id; |
@@ -423,7 +405,7 @@ int sh_pfc_config_gpio(struct sh_pfc *pfc, unsigned gpio, int pinmux_type, | |||
423 | field = 0; | 405 | field = 0; |
424 | value = 0; | 406 | value = 0; |
425 | while (1) { | 407 | while (1) { |
426 | pos = sh_pfc_gpio_to_enum(pfc, gpio, pos, &enum_id); | 408 | pos = sh_pfc_mark_to_enum(pfc, mark, pos, &enum_id); |
427 | if (pos <= 0) | 409 | if (pos <= 0) |
428 | goto out_err; | 410 | goto out_err; |
429 | 411 | ||
diff --git a/drivers/pinctrl/sh-pfc/core.h b/drivers/pinctrl/sh-pfc/core.h index f22d03f1e503..ab816b7fddfb 100644 --- a/drivers/pinctrl/sh-pfc/core.h +++ b/drivers/pinctrl/sh-pfc/core.h | |||
@@ -49,8 +49,8 @@ void sh_pfc_write_bit(struct pinmux_data_reg *dr, unsigned long in_pos, | |||
49 | unsigned long value); | 49 | unsigned long value); |
50 | int sh_pfc_get_data_reg(struct sh_pfc *pfc, unsigned gpio, | 50 | int 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 | int sh_pfc_config_gpio(struct sh_pfc *pfc, unsigned gpio, int pinmux_type, | 52 | int sh_pfc_config_mux(struct sh_pfc *pfc, unsigned mark, int pinmux_type, |
53 | int cfg_mode); | 53 | int cfg_mode); |
54 | 54 | ||
55 | extern struct sh_pfc_soc_info r8a7740_pinmux_info; | 55 | extern struct sh_pfc_soc_info r8a7740_pinmux_info; |
56 | extern struct sh_pfc_soc_info r8a7779_pinmux_info; | 56 | extern struct sh_pfc_soc_info r8a7779_pinmux_info; |
diff --git a/drivers/pinctrl/sh-pfc/gpio.c b/drivers/pinctrl/sh-pfc/gpio.c index 454c965ea555..3ad938fd7ecc 100644 --- a/drivers/pinctrl/sh-pfc/gpio.c +++ b/drivers/pinctrl/sh-pfc/gpio.c | |||
@@ -135,23 +135,21 @@ static void gpio_pin_setup(struct sh_pfc_chip *chip) | |||
135 | static int gpio_function_request(struct gpio_chip *gc, unsigned offset) | 135 | static int gpio_function_request(struct gpio_chip *gc, unsigned offset) |
136 | { | 136 | { |
137 | struct sh_pfc *pfc = gpio_to_pfc(gc); | 137 | struct sh_pfc *pfc = gpio_to_pfc(gc); |
138 | unsigned int gpio = gc->base + offset; | 138 | unsigned int mark = pfc->info->func_gpios[offset].enum_id; |
139 | unsigned long flags; | 139 | unsigned long flags; |
140 | int ret = -EINVAL; | 140 | int ret = -EINVAL; |
141 | 141 | ||
142 | pr_notice_once("Use of GPIO API for function requests is deprecated, convert to pinctrl\n"); | 142 | pr_notice_once("Use of GPIO API for function requests is deprecated, convert to pinctrl\n"); |
143 | 143 | ||
144 | if (pfc->info->func_gpios[offset].enum_id == 0) | 144 | if (mark == 0) |
145 | return ret; | 145 | return ret; |
146 | 146 | ||
147 | spin_lock_irqsave(&pfc->lock, flags); | 147 | spin_lock_irqsave(&pfc->lock, flags); |
148 | 148 | ||
149 | if (sh_pfc_config_gpio(pfc, gpio, PINMUX_TYPE_FUNCTION, | 149 | if (sh_pfc_config_mux(pfc, mark, PINMUX_TYPE_FUNCTION, GPIO_CFG_DRYRUN)) |
150 | GPIO_CFG_DRYRUN)) | ||
151 | goto done; | 150 | goto done; |
152 | 151 | ||
153 | if (sh_pfc_config_gpio(pfc, gpio, PINMUX_TYPE_FUNCTION, | 152 | if (sh_pfc_config_mux(pfc, mark, PINMUX_TYPE_FUNCTION, GPIO_CFG_REQ)) |
154 | GPIO_CFG_REQ)) | ||
155 | goto done; | 153 | goto done; |
156 | 154 | ||
157 | ret = 0; | 155 | ret = 0; |
@@ -164,12 +162,12 @@ done: | |||
164 | static void gpio_function_free(struct gpio_chip *gc, unsigned offset) | 162 | static void gpio_function_free(struct gpio_chip *gc, unsigned offset) |
165 | { | 163 | { |
166 | struct sh_pfc *pfc = gpio_to_pfc(gc); | 164 | struct sh_pfc *pfc = gpio_to_pfc(gc); |
167 | unsigned int gpio = gc->base + offset; | 165 | unsigned int mark = pfc->info->func_gpios[offset].enum_id; |
168 | unsigned long flags; | 166 | unsigned long flags; |
169 | 167 | ||
170 | spin_lock_irqsave(&pfc->lock, flags); | 168 | spin_lock_irqsave(&pfc->lock, flags); |
171 | 169 | ||
172 | sh_pfc_config_gpio(pfc, gpio, PINMUX_TYPE_FUNCTION, GPIO_CFG_FREE); | 170 | sh_pfc_config_mux(pfc, mark, PINMUX_TYPE_FUNCTION, GPIO_CFG_FREE); |
173 | 171 | ||
174 | spin_unlock_irqrestore(&pfc->lock, flags); | 172 | spin_unlock_irqrestore(&pfc->lock, flags); |
175 | } | 173 | } |
diff --git a/drivers/pinctrl/sh-pfc/pinctrl.c b/drivers/pinctrl/sh-pfc/pinctrl.c index d420d9981725..a83f40070b3b 100644 --- a/drivers/pinctrl/sh-pfc/pinctrl.c +++ b/drivers/pinctrl/sh-pfc/pinctrl.c | |||
@@ -119,6 +119,7 @@ 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 | unsigned long flags; | 123 | unsigned long flags; |
123 | int pinmux_type; | 124 | int pinmux_type; |
124 | int ret = -EINVAL; | 125 | int ret = -EINVAL; |
@@ -137,7 +138,7 @@ static int sh_pfc_reconfig_pin(struct sh_pfc *pfc, unsigned offset, | |||
137 | case PINMUX_TYPE_INPUT: | 138 | case PINMUX_TYPE_INPUT: |
138 | case PINMUX_TYPE_INPUT_PULLUP: | 139 | case PINMUX_TYPE_INPUT_PULLUP: |
139 | case PINMUX_TYPE_INPUT_PULLDOWN: | 140 | case PINMUX_TYPE_INPUT_PULLDOWN: |
140 | sh_pfc_config_gpio(pfc, offset, pinmux_type, GPIO_CFG_FREE); | 141 | sh_pfc_config_mux(pfc, mark, pinmux_type, GPIO_CFG_FREE); |
141 | break; | 142 | break; |
142 | default: | 143 | default: |
143 | goto err; | 144 | goto err; |
@@ -146,15 +147,13 @@ static int sh_pfc_reconfig_pin(struct sh_pfc *pfc, unsigned offset, | |||
146 | /* | 147 | /* |
147 | * Dry run | 148 | * Dry run |
148 | */ | 149 | */ |
149 | if (sh_pfc_config_gpio(pfc, offset, new_type, | 150 | if (sh_pfc_config_mux(pfc, mark, new_type, GPIO_CFG_DRYRUN) != 0) |
150 | GPIO_CFG_DRYRUN) != 0) | ||
151 | goto err; | 151 | goto err; |
152 | 152 | ||
153 | /* | 153 | /* |
154 | * Request | 154 | * Request |
155 | */ | 155 | */ |
156 | if (sh_pfc_config_gpio(pfc, offset, new_type, | 156 | if (sh_pfc_config_mux(pfc, mark, new_type, GPIO_CFG_REQ) != 0) |
157 | GPIO_CFG_REQ) != 0) | ||
158 | goto err; | 157 | goto err; |
159 | 158 | ||
160 | pfc->info->pins[offset].flags &= ~PINMUX_FLAG_TYPE; | 159 | pfc->info->pins[offset].flags &= ~PINMUX_FLAG_TYPE; |
@@ -214,7 +213,8 @@ static void sh_pfc_gpio_disable_free(struct pinctrl_dev *pctldev, | |||
214 | 213 | ||
215 | pinmux_type = pfc->info->pins[offset].flags & PINMUX_FLAG_TYPE; | 214 | pinmux_type = pfc->info->pins[offset].flags & PINMUX_FLAG_TYPE; |
216 | 215 | ||
217 | sh_pfc_config_gpio(pfc, offset, pinmux_type, GPIO_CFG_FREE); | 216 | sh_pfc_config_mux(pfc, pfc->info->pins[offset].enum_id, pinmux_type, |
217 | GPIO_CFG_FREE); | ||
218 | 218 | ||
219 | spin_unlock_irqrestore(&pfc->lock, flags); | 219 | spin_unlock_irqrestore(&pfc->lock, flags); |
220 | } | 220 | } |