aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pinctrl/sh-pfc/gpio.c
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>2013-03-08 11:43:54 -0500
committerLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>2013-03-15 08:33:53 -0400
commit1a0039dce269317a843d4fc85c4a3430b484bc2d (patch)
treecb22db8e8b78b04c9ce13891a1685244b1c0cbac /drivers/pinctrl/sh-pfc/gpio.c
parent51cb226b359bc48fed4a92b9bbd9af34640b1be8 (diff)
sh-pfc: Don't modify sh_pfc_pin SoC data
The sh_pfc_pin structure supplied in SoC data contains information about pin configuration and name. It's abused to store GPIO data registers information and pin config type. Move those fields out of the pinmux_data_reg structure into the new sh_pfc_gpio_pin and sh_pfc_pin_config structures. 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/gpio.c')
-rw-r--r--drivers/pinctrl/sh-pfc/gpio.c47
1 files changed, 28 insertions, 19 deletions
diff --git a/drivers/pinctrl/sh-pfc/gpio.c b/drivers/pinctrl/sh-pfc/gpio.c
index 55eaf75decff..ce074b22f426 100644
--- a/drivers/pinctrl/sh-pfc/gpio.c
+++ b/drivers/pinctrl/sh-pfc/gpio.c
@@ -26,12 +26,18 @@ struct sh_pfc_gpio_data_reg {
26 unsigned long shadow; 26 unsigned long shadow;
27}; 27};
28 28
29struct sh_pfc_gpio_pin {
30 u8 dbit;
31 u8 dreg;
32};
33
29struct sh_pfc_chip { 34struct sh_pfc_chip {
30 struct sh_pfc *pfc; 35 struct sh_pfc *pfc;
31 struct gpio_chip gpio_chip; 36 struct gpio_chip gpio_chip;
32 37
33 struct sh_pfc_window *mem; 38 struct sh_pfc_window *mem;
34 struct sh_pfc_gpio_data_reg *regs; 39 struct sh_pfc_gpio_data_reg *regs;
40 struct sh_pfc_gpio_pin *pins;
35}; 41};
36 42
37static struct sh_pfc_chip *gpio_to_pfc_chip(struct gpio_chip *gc) 43static struct sh_pfc_chip *gpio_to_pfc_chip(struct gpio_chip *gc)
@@ -48,13 +54,11 @@ static void gpio_get_data_reg(struct sh_pfc_chip *chip, unsigned int gpio,
48 struct sh_pfc_gpio_data_reg **reg, 54 struct sh_pfc_gpio_data_reg **reg,
49 unsigned int *bit) 55 unsigned int *bit)
50{ 56{
51 struct sh_pfc_pin *gpiop = sh_pfc_get_pin(chip->pfc, gpio); 57 int idx = sh_pfc_get_pin_index(chip->pfc, gpio);
52 unsigned int reg_idx; 58 struct sh_pfc_gpio_pin *gpio_pin = &chip->pins[idx];
53 59
54 reg_idx = (gpiop->flags & PINMUX_FLAG_DREG) >> PINMUX_FLAG_DREG_SHIFT; 60 *reg = &chip->regs[gpio_pin->dreg];
55 61 *bit = gpio_pin->dbit;
56 *reg = &chip->regs[reg_idx];
57 *bit = (gpiop->flags & PINMUX_FLAG_DBIT) >> PINMUX_FLAG_DBIT_SHIFT;
58} 62}
59 63
60static unsigned long gpio_read_data_reg(struct sh_pfc_chip *chip, 64static unsigned long gpio_read_data_reg(struct sh_pfc_chip *chip,
@@ -74,20 +78,20 @@ static void gpio_write_data_reg(struct sh_pfc_chip *chip,
74 sh_pfc_write_raw_reg(mem, dreg->reg_width, value); 78 sh_pfc_write_raw_reg(mem, dreg->reg_width, value);
75} 79}
76 80
77static void gpio_setup_data_reg(struct sh_pfc *pfc, unsigned gpio) 81static void gpio_setup_data_reg(struct sh_pfc_chip *chip, unsigned gpio)
78{ 82{
79 struct sh_pfc_pin *gpiop = &pfc->info->pins[gpio]; 83 struct sh_pfc *pfc = chip->pfc;
84 struct sh_pfc_gpio_pin *gpio_pin = &chip->pins[gpio];
85 struct sh_pfc_pin *pin = &pfc->info->pins[gpio];
80 const struct pinmux_data_reg *dreg; 86 const struct pinmux_data_reg *dreg;
81 unsigned int bit; 87 unsigned int bit;
82 unsigned int i; 88 unsigned int i;
83 89
84 for (i = 0, dreg = pfc->info->data_regs; dreg->reg; ++i, ++dreg) { 90 for (i = 0, dreg = pfc->info->data_regs; dreg->reg; ++i, ++dreg) {
85 for (bit = 0; bit < dreg->reg_width; bit++) { 91 for (bit = 0; bit < dreg->reg_width; bit++) {
86 if (dreg->enum_ids[bit] == gpiop->enum_id) { 92 if (dreg->enum_ids[bit] == pin->enum_id) {
87 gpiop->flags &= ~PINMUX_FLAG_DREG; 93 gpio_pin->dreg = i;
88 gpiop->flags |= i << PINMUX_FLAG_DREG_SHIFT; 94 gpio_pin->dbit = bit;
89 gpiop->flags &= ~PINMUX_FLAG_DBIT;
90 gpiop->flags |= bit << PINMUX_FLAG_DBIT_SHIFT;
91 return; 95 return;
92 } 96 }
93 } 97 }
@@ -137,7 +141,7 @@ static int gpio_setup_data_regs(struct sh_pfc_chip *chip)
137 if (pfc->info->pins[i].enum_id == 0) 141 if (pfc->info->pins[i].enum_id == 0)
138 continue; 142 continue;
139 143
140 gpio_setup_data_reg(pfc, i); 144 gpio_setup_data_reg(chip, i);
141 } 145 }
142 146
143 return 0; 147 return 0;
@@ -150,9 +154,9 @@ static int gpio_setup_data_regs(struct sh_pfc_chip *chip)
150static int gpio_pin_request(struct gpio_chip *gc, unsigned offset) 154static int gpio_pin_request(struct gpio_chip *gc, unsigned offset)
151{ 155{
152 struct sh_pfc *pfc = gpio_to_pfc(gc); 156 struct sh_pfc *pfc = gpio_to_pfc(gc);
153 struct sh_pfc_pin *pin = sh_pfc_get_pin(pfc, offset); 157 int idx = sh_pfc_get_pin_index(pfc, offset);
154 158
155 if (pin == NULL || pin->enum_id == 0) 159 if (idx < 0 || pfc->info->pins[idx].enum_id == 0)
156 return -EINVAL; 160 return -EINVAL;
157 161
158 return pinctrl_request_gpio(offset); 162 return pinctrl_request_gpio(offset);
@@ -237,6 +241,11 @@ static int gpio_pin_setup(struct sh_pfc_chip *chip)
237 struct gpio_chip *gc = &chip->gpio_chip; 241 struct gpio_chip *gc = &chip->gpio_chip;
238 int ret; 242 int ret;
239 243
244 chip->pins = devm_kzalloc(pfc->dev, pfc->nr_pins * sizeof(*chip->pins),
245 GFP_KERNEL);
246 if (chip->pins == NULL)
247 return -ENOMEM;
248
240 ret = gpio_setup_data_regs(chip); 249 ret = gpio_setup_data_regs(chip);
241 if (ret < 0) 250 if (ret < 0)
242 return ret; 251 return ret;