aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pinctrl/sh-pfc/gpio.c
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>2013-02-16 12:34:32 -0500
committerLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>2013-03-15 08:33:53 -0400
commit51cb226b359bc48fed4a92b9bbd9af34640b1be8 (patch)
tree6e87c674c80c7ee9e1135bdca5fd8209346cb669 /drivers/pinctrl/sh-pfc/gpio.c
parentbee9f22ba196b0fa3b07507f685eb92b2075e1d1 (diff)
sh-pfc: Don't modify pinmux_data_reg SoC data
The pinmux_data_reg structure supplied in SoC data contains information about data registers. It's abused to store per-device mapped iomem and shadow values. Move those fields out of the pinmux_data_reg structure into the per-device sh_pfc_chip structure. 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.c58
1 files changed, 40 insertions, 18 deletions
diff --git a/drivers/pinctrl/sh-pfc/gpio.c b/drivers/pinctrl/sh-pfc/gpio.c
index b370d2865041..55eaf75decff 100644
--- a/drivers/pinctrl/sh-pfc/gpio.c
+++ b/drivers/pinctrl/sh-pfc/gpio.c
@@ -21,11 +21,17 @@
21 21
22#include "core.h" 22#include "core.h"
23 23
24struct sh_pfc_gpio_data_reg {
25 const struct pinmux_data_reg *info;
26 unsigned long shadow;
27};
28
24struct sh_pfc_chip { 29struct sh_pfc_chip {
25 struct sh_pfc *pfc; 30 struct sh_pfc *pfc;
26 struct gpio_chip gpio_chip; 31 struct gpio_chip gpio_chip;
27 32
28 struct sh_pfc_window *mem; 33 struct sh_pfc_window *mem;
34 struct sh_pfc_gpio_data_reg *regs;
29}; 35};
30 36
31static struct sh_pfc_chip *gpio_to_pfc_chip(struct gpio_chip *gc) 37static struct sh_pfc_chip *gpio_to_pfc_chip(struct gpio_chip *gc)
@@ -38,13 +44,16 @@ static struct sh_pfc *gpio_to_pfc(struct gpio_chip *gc)
38 return gpio_to_pfc_chip(gc)->pfc; 44 return gpio_to_pfc_chip(gc)->pfc;
39} 45}
40 46
41static void gpio_get_data_reg(struct sh_pfc *pfc, unsigned int gpio, 47static void gpio_get_data_reg(struct sh_pfc_chip *chip, unsigned int gpio,
42 struct pinmux_data_reg **dr, unsigned int *bit) 48 struct sh_pfc_gpio_data_reg **reg,
49 unsigned int *bit)
43{ 50{
44 struct sh_pfc_pin *gpiop = sh_pfc_get_pin(pfc, gpio); 51 struct sh_pfc_pin *gpiop = sh_pfc_get_pin(chip->pfc, gpio);
52 unsigned int reg_idx;
45 53
46 *dr = pfc->info->data_regs 54 reg_idx = (gpiop->flags & PINMUX_FLAG_DREG) >> PINMUX_FLAG_DREG_SHIFT;
47 + ((gpiop->flags & PINMUX_FLAG_DREG) >> PINMUX_FLAG_DREG_SHIFT); 55
56 *reg = &chip->regs[reg_idx];
48 *bit = (gpiop->flags & PINMUX_FLAG_DBIT) >> PINMUX_FLAG_DBIT_SHIFT; 57 *bit = (gpiop->flags & PINMUX_FLAG_DBIT) >> PINMUX_FLAG_DBIT_SHIFT;
49} 58}
50 59
@@ -91,7 +100,7 @@ static int gpio_setup_data_regs(struct sh_pfc_chip *chip)
91{ 100{
92 struct sh_pfc *pfc = chip->pfc; 101 struct sh_pfc *pfc = chip->pfc;
93 unsigned long addr = pfc->info->data_regs[0].reg; 102 unsigned long addr = pfc->info->data_regs[0].reg;
94 struct pinmux_data_reg *dreg; 103 const struct pinmux_data_reg *dreg;
95 unsigned int i; 104 unsigned int i;
96 105
97 /* Find the window that contain the GPIO registers. */ 106 /* Find the window that contain the GPIO registers. */
@@ -108,8 +117,21 @@ static int gpio_setup_data_regs(struct sh_pfc_chip *chip)
108 /* GPIO data registers must be in the first memory resource. */ 117 /* GPIO data registers must be in the first memory resource. */
109 chip->mem = &pfc->window[i]; 118 chip->mem = &pfc->window[i];
110 119
111 for (dreg = pfc->info->data_regs; dreg->reg; ++dreg) 120 /* Count the number of data registers, allocate memory and initialize
112 dreg->reg_shadow = gpio_read_data_reg(chip, dreg); 121 * them.
122 */
123 for (i = 0; pfc->info->data_regs[i].reg_width; ++i)
124 ;
125
126 chip->regs = devm_kzalloc(pfc->dev, i * sizeof(*chip->regs),
127 GFP_KERNEL);
128 if (chip->regs == NULL)
129 return -ENOMEM;
130
131 for (i = 0, dreg = pfc->info->data_regs; dreg->reg_width; ++i, ++dreg) {
132 chip->regs[i].info = dreg;
133 chip->regs[i].shadow = gpio_read_data_reg(chip, dreg);
134 }
113 135
114 for (i = 0; i < pfc->info->nr_pins; i++) { 136 for (i = 0; i < pfc->info->nr_pins; i++) {
115 if (pfc->info->pins[i].enum_id == 0) 137 if (pfc->info->pins[i].enum_id == 0)
@@ -144,20 +166,20 @@ static void gpio_pin_free(struct gpio_chip *gc, unsigned offset)
144static void gpio_pin_set_value(struct sh_pfc_chip *chip, unsigned offset, 166static void gpio_pin_set_value(struct sh_pfc_chip *chip, unsigned offset,
145 int value) 167 int value)
146{ 168{
147 struct pinmux_data_reg *dreg; 169 struct sh_pfc_gpio_data_reg *reg;
148 unsigned long pos; 170 unsigned long pos;
149 unsigned int bit; 171 unsigned int bit;
150 172
151 gpio_get_data_reg(chip->pfc, offset, &dreg, &bit); 173 gpio_get_data_reg(chip, offset, &reg, &bit);
152 174
153 pos = dreg->reg_width - (bit + 1); 175 pos = reg->info->reg_width - (bit + 1);
154 176
155 if (value) 177 if (value)
156 set_bit(pos, &dreg->reg_shadow); 178 set_bit(pos, &reg->shadow);
157 else 179 else
158 clear_bit(pos, &dreg->reg_shadow); 180 clear_bit(pos, &reg->shadow);
159 181
160 gpio_write_data_reg(chip, dreg, dreg->reg_shadow); 182 gpio_write_data_reg(chip, reg->info, reg->shadow);
161} 183}
162 184
163static int gpio_pin_direction_input(struct gpio_chip *gc, unsigned offset) 185static int gpio_pin_direction_input(struct gpio_chip *gc, unsigned offset)
@@ -176,15 +198,15 @@ static int gpio_pin_direction_output(struct gpio_chip *gc, unsigned offset,
176static int gpio_pin_get(struct gpio_chip *gc, unsigned offset) 198static int gpio_pin_get(struct gpio_chip *gc, unsigned offset)
177{ 199{
178 struct sh_pfc_chip *chip = gpio_to_pfc_chip(gc); 200 struct sh_pfc_chip *chip = gpio_to_pfc_chip(gc);
179 struct pinmux_data_reg *dreg; 201 struct sh_pfc_gpio_data_reg *reg;
180 unsigned long pos; 202 unsigned long pos;
181 unsigned int bit; 203 unsigned int bit;
182 204
183 gpio_get_data_reg(chip->pfc, offset, &dreg, &bit); 205 gpio_get_data_reg(chip, offset, &reg, &bit);
184 206
185 pos = dreg->reg_width - (bit + 1); 207 pos = reg->info->reg_width - (bit + 1);
186 208
187 return (gpio_read_data_reg(chip, dreg) >> pos) & 1; 209 return (gpio_read_data_reg(chip, reg->info) >> pos) & 1;
188} 210}
189 211
190static void gpio_pin_set(struct gpio_chip *gc, unsigned offset, int value) 212static void gpio_pin_set(struct gpio_chip *gc, unsigned offset, int value)