aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio
diff options
context:
space:
mode:
authorJamie Iles <jamie@jamieiles.com>2011-05-20 02:40:15 -0400
committerGrant Likely <grant.likely@secretlab.ca>2011-05-20 02:40:15 -0400
commit924e7a9fc6da124588e27c611841d07047c157b4 (patch)
tree7f886a9e10666ba3fc0e39b1976e50eb52274178 /drivers/gpio
parent4ddb8ae217ad2aae888d00d97c5160f677dd38f4 (diff)
basic_mmio_gpio: allow overriding number of gpio
Some platforms may have a number of GPIO that is less than the register width of the peripheral. 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')
-rw-r--r--drivers/gpio/basic_mmio_gpio.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/drivers/gpio/basic_mmio_gpio.c b/drivers/gpio/basic_mmio_gpio.c
index 5db5de43832..2b2d3845446 100644
--- a/drivers/gpio/basic_mmio_gpio.c
+++ b/drivers/gpio/basic_mmio_gpio.c
@@ -239,6 +239,7 @@ static int __devinit bgpio_probe(struct platform_device *pdev)
239 resource_size_t dat_sz; 239 resource_size_t dat_sz;
240 int bits; 240 int bits;
241 int ret; 241 int ret;
242 int ngpio;
242 243
243 res_dat = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat"); 244 res_dat = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat");
244 if (!res_dat) 245 if (!res_dat)
@@ -249,6 +250,7 @@ static int __devinit bgpio_probe(struct platform_device *pdev)
249 return -EINVAL; 250 return -EINVAL;
250 251
251 bits = dat_sz * 8; 252 bits = dat_sz * 8;
253 ngpio = bits;
252 if (bits > BITS_PER_LONG) 254 if (bits > BITS_PER_LONG)
253 return -EINVAL; 255 return -EINVAL;
254 256
@@ -277,13 +279,22 @@ static int __devinit bgpio_probe(struct platform_device *pdev)
277 279
278 spin_lock_init(&bgc->lock); 280 spin_lock_init(&bgc->lock);
279 281
282 if (pdata) {
283 bgc->gc.base = pdata->base;
284 if (pdata->ngpio > 0)
285 ngpio = pdata->ngpio;
286 } else {
287 bgc->gc.base = -1;
288 }
289
280 bgc->bits = bits; 290 bgc->bits = bits;
281 ret = bgpio_setup_accessors(pdev, bgc); 291 ret = bgpio_setup_accessors(pdev, bgc);
282 if (ret) 292 if (ret)
283 return ret; 293 return ret;
284 294
285 bgc->data = bgc->read_reg(bgc->reg_dat); 295 bgc->data = bgc->read_reg(bgc->reg_dat);
286 bgc->gc.ngpio = bits; 296
297 bgc->gc.ngpio = ngpio;
287 bgc->gc.direction_input = bgpio_dir_in; 298 bgc->gc.direction_input = bgpio_dir_in;
288 bgc->gc.direction_output = bgpio_dir_out; 299 bgc->gc.direction_output = bgpio_dir_out;
289 bgc->gc.get = bgpio_get; 300 bgc->gc.get = bgpio_get;
@@ -291,11 +302,6 @@ static int __devinit bgpio_probe(struct platform_device *pdev)
291 bgc->gc.dev = dev; 302 bgc->gc.dev = dev;
292 bgc->gc.label = dev_name(dev); 303 bgc->gc.label = dev_name(dev);
293 304
294 if (pdata)
295 bgc->gc.base = pdata->base;
296 else
297 bgc->gc.base = -1;
298
299 platform_set_drvdata(pdev, bgc); 305 platform_set_drvdata(pdev, bgc);
300 306
301 ret = gpiochip_add(&bgc->gc); 307 ret = gpiochip_add(&bgc->gc);