diff options
author | Jamie Iles <jamie@jamieiles.com> | 2011-05-20 02:40:16 -0400 |
---|---|---|
committer | Grant Likely <grant.likely@secretlab.ca> | 2011-05-20 02:40:16 -0400 |
commit | dd86a0cc5e35161538c10e35eb85e2ad0adfe14d (patch) | |
tree | 4a6f57831bc7b1a471bfe74b726498fce057fc0c /drivers/gpio/basic_mmio_gpio.c | |
parent | e027d6f9d52d9ccabb307d0cb0265de3481b1e9e (diff) |
basic_mmio_gpio: support different input/output registers
Some controllers have separate input and output registers. For these
controllers, use "set" for the output and "dat" for the input.
Changes since v2: reuse "set" for output and "dat" for input rather than
adding a new "in" register.
Signed-off-by: Jamie Iles <jamie@jamieiles.com>
Acked-by: Anton Vorontsov <cbouatmailru@gmail.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'drivers/gpio/basic_mmio_gpio.c')
-rw-r--r-- | drivers/gpio/basic_mmio_gpio.c | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/drivers/gpio/basic_mmio_gpio.c b/drivers/gpio/basic_mmio_gpio.c index 728bc67ee08b..6b99489e0ebb 100644 --- a/drivers/gpio/basic_mmio_gpio.c +++ b/drivers/gpio/basic_mmio_gpio.c | |||
@@ -185,6 +185,24 @@ static void bgpio_set_with_clear(struct gpio_chip *gc, unsigned int gpio, | |||
185 | bgc->write_reg(bgc->reg_clr, mask); | 185 | bgc->write_reg(bgc->reg_clr, mask); |
186 | } | 186 | } |
187 | 187 | ||
188 | static void bgpio_set_set(struct gpio_chip *gc, unsigned int gpio, int val) | ||
189 | { | ||
190 | struct bgpio_chip *bgc = to_bgpio_chip(gc); | ||
191 | unsigned long mask = bgc->pin2mask(bgc, gpio); | ||
192 | unsigned long flags; | ||
193 | |||
194 | spin_lock_irqsave(&bgc->lock, flags); | ||
195 | |||
196 | if (val) | ||
197 | bgc->data |= mask; | ||
198 | else | ||
199 | bgc->data &= ~mask; | ||
200 | |||
201 | bgc->write_reg(bgc->reg_set, bgc->data); | ||
202 | |||
203 | spin_unlock_irqrestore(&bgc->lock, flags); | ||
204 | } | ||
205 | |||
188 | static int bgpio_dir_in(struct gpio_chip *gc, unsigned int gpio) | 206 | static int bgpio_dir_in(struct gpio_chip *gc, unsigned int gpio) |
189 | { | 207 | { |
190 | return 0; | 208 | return 0; |
@@ -245,10 +263,12 @@ static int bgpio_setup_accessors(struct platform_device *pdev, | |||
245 | 263 | ||
246 | /* | 264 | /* |
247 | * Create the device and allocate the resources. For setting GPIO's there are | 265 | * Create the device and allocate the resources. For setting GPIO's there are |
248 | * two supported configurations: | 266 | * three supported configurations: |
249 | * | 267 | * |
250 | * - single output register resource (named "dat"). | 268 | * - single input/output register resource (named "dat"). |
251 | * - set/clear pair (named "set" and "clr"). | 269 | * - set/clear pair (named "set" and "clr"). |
270 | * - single output register resource and single input resource ("set" and | ||
271 | * dat"). | ||
252 | * | 272 | * |
253 | * For the single output register, this drives a 1 by setting a bit and a zero | 273 | * For the single output register, this drives a 1 by setting a bit and a zero |
254 | * by clearing a bit. For the set clr pair, this drives a 1 by setting a bit | 274 | * by clearing a bit. For the set clr pair, this drives a 1 by setting a bit |
@@ -292,12 +312,21 @@ static int bgpio_setup_io(struct platform_device *pdev, | |||
292 | return -ENOMEM; | 312 | return -ENOMEM; |
293 | 313 | ||
294 | bgc->gc.set = bgpio_set_with_clear; | 314 | bgc->gc.set = bgpio_set_with_clear; |
295 | } else if (res_set || res_clr) { | 315 | } else if (res_set && !res_clr) { |
296 | return -EINVAL; | 316 | if (resource_size(res_set) != resource_size(res_dat)) |
317 | return -EINVAL; | ||
318 | |||
319 | bgc->reg_set = bgpio_request_and_map(&pdev->dev, res_set); | ||
320 | if (!bgc->reg_set) | ||
321 | return -ENOMEM; | ||
322 | |||
323 | bgc->gc.set = bgpio_set_set; | ||
297 | } else { | 324 | } else { |
298 | bgc->gc.set = bgpio_set; | 325 | bgc->gc.set = bgpio_set; |
299 | } | 326 | } |
300 | 327 | ||
328 | bgc->gc.get = bgpio_get; | ||
329 | |||
301 | return 0; | 330 | return 0; |
302 | } | 331 | } |
303 | 332 | ||
@@ -336,7 +365,6 @@ static int __devinit bgpio_probe(struct platform_device *pdev) | |||
336 | bgc->gc.ngpio = ngpio; | 365 | bgc->gc.ngpio = ngpio; |
337 | bgc->gc.direction_input = bgpio_dir_in; | 366 | bgc->gc.direction_input = bgpio_dir_in; |
338 | bgc->gc.direction_output = bgpio_dir_out; | 367 | bgc->gc.direction_output = bgpio_dir_out; |
339 | bgc->gc.get = bgpio_get; | ||
340 | bgc->gc.dev = dev; | 368 | bgc->gc.dev = dev; |
341 | bgc->gc.label = dev_name(dev); | 369 | bgc->gc.label = dev_name(dev); |
342 | 370 | ||