aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpio-davinci.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-11-11 03:05:37 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-11-11 03:05:37 -0500
commit53575aa99dc1584484b99c8173042d8370f6ed88 (patch)
tree06fd13c8847c1e97cd5080ea31cec47c4ad54963 /drivers/gpio/gpio-davinci.c
parentd5aabbcaee6bb5fb57ea8c67714516af4d8238ce (diff)
parent3316dee245ef297155fa45b8d14263dfd6a9164b (diff)
Merge tag 'drivers-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc
Pull ARM driver updates from Olof Johansson: "Updates of SoC-near drivers and other driver updates that makes more sense to take through our tree. In this case it's involved: - Some Davinci driver updates that has required corresponding platform code changes (gpio mostly) - CCI bindings and a few driver updates - Marvell mvebu patches for PCI MSI support (could have gone through the PCI tree for this release, but they were acked by Bjorn for 3.12 so we kept them through arm-soc). - Marvell dove switch-over to DT-based PCIe configuration - Misc updates for Samsung platform dmaengine drivers" * tag 'drivers-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc: (32 commits) ARM: S3C24XX: add dma pdata for s3c2410, s3c2440 and s3c2442 dmaengine: s3c24xx-dma: add support for the s3c2410 type of controller ARM: S3C24XX: Fix possible dma selection warning PCI: mvebu: make local functions static PCI: mvebu: add I/O access wrappers PCI: mvebu: Dynamically detect if the PEX link is up to enable hot plug ARM: mvebu: fix gated clock documentation ARM: dove: remove legacy pcie and clock init ARM: dove: switch to DT probed mbus address windows ARM: SAMSUNG: set s3c24xx_dma_filter for s3c64xx-spi0 device ARM: S3C24XX: add platform-devices for new dma driver for s3c2412 and s3c2443 dmaengine: add driver for Samsung s3c24xx SoCs ARM: S3C24XX: number the dma clocks PCI: mvebu: add support for Marvell Dove SoCs PCI: mvebu: add support for reset on GPIO PCI: mvebu: remove subsys_initcall PCI: mvebu: increment nports only for registered ports PCI: mvebu: move clock enable before register access PCI: mvebu: add support for MSI irqchip: armada-370-xp: implement MSI support ...
Diffstat (limited to 'drivers/gpio/gpio-davinci.c')
-rw-r--r--drivers/gpio/gpio-davinci.c132
1 files changed, 90 insertions, 42 deletions
diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c
index 17df6db5dca7..8847adf392b7 100644
--- a/drivers/gpio/gpio-davinci.c
+++ b/drivers/gpio/gpio-davinci.c
@@ -15,8 +15,9 @@
15#include <linux/clk.h> 15#include <linux/clk.h>
16#include <linux/err.h> 16#include <linux/err.h>
17#include <linux/io.h> 17#include <linux/io.h>
18 18#include <linux/irq.h>
19#include <asm/mach/irq.h> 19#include <linux/platform_device.h>
20#include <linux/platform_data/gpio-davinci.h>
20 21
21struct davinci_gpio_regs { 22struct davinci_gpio_regs {
22 u32 dir; 23 u32 dir;
@@ -31,13 +32,14 @@ struct davinci_gpio_regs {
31 u32 intstat; 32 u32 intstat;
32}; 33};
33 34
35#define BINTEN 0x8 /* GPIO Interrupt Per-Bank Enable Register */
36
34#define chip2controller(chip) \ 37#define chip2controller(chip) \
35 container_of(chip, struct davinci_gpio_controller, chip) 38 container_of(chip, struct davinci_gpio_controller, chip)
36 39
37static struct davinci_gpio_controller chips[DIV_ROUND_UP(DAVINCI_N_GPIO, 32)];
38static void __iomem *gpio_base; 40static void __iomem *gpio_base;
39 41
40static struct davinci_gpio_regs __iomem __init *gpio2regs(unsigned gpio) 42static struct davinci_gpio_regs __iomem *gpio2regs(unsigned gpio)
41{ 43{
42 void __iomem *ptr; 44 void __iomem *ptr;
43 45
@@ -65,7 +67,7 @@ static inline struct davinci_gpio_regs __iomem *irq2regs(int irq)
65 return g; 67 return g;
66} 68}
67 69
68static int __init davinci_gpio_irq_setup(void); 70static int davinci_gpio_irq_setup(struct platform_device *pdev);
69 71
70/*--------------------------------------------------------------------------*/ 72/*--------------------------------------------------------------------------*/
71 73
@@ -131,33 +133,53 @@ davinci_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
131 __raw_writel((1 << offset), value ? &g->set_data : &g->clr_data); 133 __raw_writel((1 << offset), value ? &g->set_data : &g->clr_data);
132} 134}
133 135
134static int __init davinci_gpio_setup(void) 136static int davinci_gpio_probe(struct platform_device *pdev)
135{ 137{
136 int i, base; 138 int i, base;
137 unsigned ngpio; 139 unsigned ngpio;
138 struct davinci_soc_info *soc_info = &davinci_soc_info; 140 struct davinci_gpio_controller *chips;
139 struct davinci_gpio_regs *regs; 141 struct davinci_gpio_platform_data *pdata;
140 142 struct davinci_gpio_regs __iomem *regs;
141 if (soc_info->gpio_type != GPIO_TYPE_DAVINCI) 143 struct device *dev = &pdev->dev;
142 return 0; 144 struct resource *res;
145
146 pdata = dev->platform_data;
147 if (!pdata) {
148 dev_err(dev, "No platform data found\n");
149 return -EINVAL;
150 }
143 151
144 /* 152 /*
145 * The gpio banks conceptually expose a segmented bitmap, 153 * The gpio banks conceptually expose a segmented bitmap,
146 * and "ngpio" is one more than the largest zero-based 154 * and "ngpio" is one more than the largest zero-based
147 * bit index that's valid. 155 * bit index that's valid.
148 */ 156 */
149 ngpio = soc_info->gpio_num; 157 ngpio = pdata->ngpio;
150 if (ngpio == 0) { 158 if (ngpio == 0) {
151 pr_err("GPIO setup: how many GPIOs?\n"); 159 dev_err(dev, "How many GPIOs?\n");
152 return -EINVAL; 160 return -EINVAL;
153 } 161 }
154 162
155 if (WARN_ON(DAVINCI_N_GPIO < ngpio)) 163 if (WARN_ON(DAVINCI_N_GPIO < ngpio))
156 ngpio = DAVINCI_N_GPIO; 164 ngpio = DAVINCI_N_GPIO;
157 165
158 gpio_base = ioremap(soc_info->gpio_base, SZ_4K); 166 chips = devm_kzalloc(dev,
159 if (WARN_ON(!gpio_base)) 167 ngpio * sizeof(struct davinci_gpio_controller),
168 GFP_KERNEL);
169 if (!chips) {
170 dev_err(dev, "Memory allocation failed\n");
160 return -ENOMEM; 171 return -ENOMEM;
172 }
173
174 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
175 if (!res) {
176 dev_err(dev, "Invalid memory resource\n");
177 return -EBUSY;
178 }
179
180 gpio_base = devm_ioremap_resource(dev, res);
181 if (IS_ERR(gpio_base))
182 return PTR_ERR(gpio_base);
161 183
162 for (i = 0, base = 0; base < ngpio; i++, base += 32) { 184 for (i = 0, base = 0; base < ngpio; i++, base += 32) {
163 chips[i].chip.label = "DaVinci"; 185 chips[i].chip.label = "DaVinci";
@@ -183,13 +205,10 @@ static int __init davinci_gpio_setup(void)
183 gpiochip_add(&chips[i].chip); 205 gpiochip_add(&chips[i].chip);
184 } 206 }
185 207
186 soc_info->gpio_ctlrs = chips; 208 platform_set_drvdata(pdev, chips);
187 soc_info->gpio_ctlrs_num = DIV_ROUND_UP(ngpio, 32); 209 davinci_gpio_irq_setup(pdev);
188
189 davinci_gpio_irq_setup();
190 return 0; 210 return 0;
191} 211}
192pure_initcall(davinci_gpio_setup);
193 212
194/*--------------------------------------------------------------------------*/ 213/*--------------------------------------------------------------------------*/
195/* 214/*
@@ -302,13 +321,14 @@ static int gpio_to_irq_banked(struct gpio_chip *chip, unsigned offset)
302 321
303static int gpio_to_irq_unbanked(struct gpio_chip *chip, unsigned offset) 322static int gpio_to_irq_unbanked(struct gpio_chip *chip, unsigned offset)
304{ 323{
305 struct davinci_soc_info *soc_info = &davinci_soc_info; 324 struct davinci_gpio_controller *d = chip2controller(chip);
306 325
307 /* NOTE: we assume for now that only irqs in the first gpio_chip 326 /*
327 * NOTE: we assume for now that only irqs in the first gpio_chip
308 * can provide direct-mapped IRQs to AINTC (up to 32 GPIOs). 328 * can provide direct-mapped IRQs to AINTC (up to 32 GPIOs).
309 */ 329 */
310 if (offset < soc_info->gpio_unbanked) 330 if (offset < d->irq_base)
311 return soc_info->gpio_irq + offset; 331 return d->gpio_irq + offset;
312 else 332 else
313 return -ENODEV; 333 return -ENODEV;
314} 334}
@@ -317,12 +337,11 @@ static int gpio_irq_type_unbanked(struct irq_data *data, unsigned trigger)
317{ 337{
318 struct davinci_gpio_controller *d; 338 struct davinci_gpio_controller *d;
319 struct davinci_gpio_regs __iomem *g; 339 struct davinci_gpio_regs __iomem *g;
320 struct davinci_soc_info *soc_info = &davinci_soc_info;
321 u32 mask; 340 u32 mask;
322 341
323 d = (struct davinci_gpio_controller *)data->handler_data; 342 d = (struct davinci_gpio_controller *)data->handler_data;
324 g = (struct davinci_gpio_regs __iomem *)d->regs; 343 g = (struct davinci_gpio_regs __iomem *)d->regs;
325 mask = __gpio_mask(data->irq - soc_info->gpio_irq); 344 mask = __gpio_mask(data->irq - d->gpio_irq);
326 345
327 if (trigger & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) 346 if (trigger & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
328 return -EINVAL; 347 return -EINVAL;
@@ -343,24 +362,33 @@ static int gpio_irq_type_unbanked(struct irq_data *data, unsigned trigger)
343 * (dm6446) can be set appropriately for GPIOV33 pins. 362 * (dm6446) can be set appropriately for GPIOV33 pins.
344 */ 363 */
345 364
346static int __init davinci_gpio_irq_setup(void) 365static int davinci_gpio_irq_setup(struct platform_device *pdev)
347{ 366{
348 unsigned gpio, irq, bank; 367 unsigned gpio, irq, bank;
349 struct clk *clk; 368 struct clk *clk;
350 u32 binten = 0; 369 u32 binten = 0;
351 unsigned ngpio, bank_irq; 370 unsigned ngpio, bank_irq;
352 struct davinci_soc_info *soc_info = &davinci_soc_info; 371 struct device *dev = &pdev->dev;
353 struct davinci_gpio_regs __iomem *g; 372 struct resource *res;
373 struct davinci_gpio_controller *chips = platform_get_drvdata(pdev);
374 struct davinci_gpio_platform_data *pdata = dev->platform_data;
375 struct davinci_gpio_regs __iomem *g;
354 376
355 ngpio = soc_info->gpio_num; 377 ngpio = pdata->ngpio;
378 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
379 if (!res) {
380 dev_err(dev, "Invalid IRQ resource\n");
381 return -EBUSY;
382 }
356 383
357 bank_irq = soc_info->gpio_irq; 384 bank_irq = res->start;
358 if (bank_irq == 0) { 385
359 printk(KERN_ERR "Don't know first GPIO bank IRQ.\n"); 386 if (!bank_irq) {
360 return -EINVAL; 387 dev_err(dev, "Invalid IRQ resource\n");
388 return -ENODEV;
361 } 389 }
362 390
363 clk = clk_get(NULL, "gpio"); 391 clk = devm_clk_get(dev, "gpio");
364 if (IS_ERR(clk)) { 392 if (IS_ERR(clk)) {
365 printk(KERN_ERR "Error %ld getting gpio clock?\n", 393 printk(KERN_ERR "Error %ld getting gpio clock?\n",
366 PTR_ERR(clk)); 394 PTR_ERR(clk));
@@ -368,16 +396,17 @@ static int __init davinci_gpio_irq_setup(void)
368 } 396 }
369 clk_prepare_enable(clk); 397 clk_prepare_enable(clk);
370 398
371 /* Arrange gpio_to_irq() support, handling either direct IRQs or 399 /*
400 * Arrange gpio_to_irq() support, handling either direct IRQs or
372 * banked IRQs. Having GPIOs in the first GPIO bank use direct 401 * banked IRQs. Having GPIOs in the first GPIO bank use direct
373 * IRQs, while the others use banked IRQs, would need some setup 402 * IRQs, while the others use banked IRQs, would need some setup
374 * tweaks to recognize hardware which can do that. 403 * tweaks to recognize hardware which can do that.
375 */ 404 */
376 for (gpio = 0, bank = 0; gpio < ngpio; bank++, gpio += 32) { 405 for (gpio = 0, bank = 0; gpio < ngpio; bank++, gpio += 32) {
377 chips[bank].chip.to_irq = gpio_to_irq_banked; 406 chips[bank].chip.to_irq = gpio_to_irq_banked;
378 chips[bank].irq_base = soc_info->gpio_unbanked 407 chips[bank].irq_base = pdata->gpio_unbanked
379 ? -EINVAL 408 ? -EINVAL
380 : (soc_info->intc_irq_num + gpio); 409 : (pdata->intc_irq_num + gpio);
381 } 410 }
382 411
383 /* 412 /*
@@ -385,7 +414,7 @@ static int __init davinci_gpio_irq_setup(void)
385 * controller only handling trigger modes. We currently assume no 414 * controller only handling trigger modes. We currently assume no
386 * IRQ mux conflicts; gpio_irq_type_unbanked() is only for GPIOs. 415 * IRQ mux conflicts; gpio_irq_type_unbanked() is only for GPIOs.
387 */ 416 */
388 if (soc_info->gpio_unbanked) { 417 if (pdata->gpio_unbanked) {
389 static struct irq_chip_type gpio_unbanked; 418 static struct irq_chip_type gpio_unbanked;
390 419
391 /* pass "bank 0" GPIO IRQs to AINTC */ 420 /* pass "bank 0" GPIO IRQs to AINTC */
@@ -405,7 +434,7 @@ static int __init davinci_gpio_irq_setup(void)
405 __raw_writel(~0, &g->set_rising); 434 __raw_writel(~0, &g->set_rising);
406 435
407 /* set the direct IRQs up to use that irqchip */ 436 /* set the direct IRQs up to use that irqchip */
408 for (gpio = 0; gpio < soc_info->gpio_unbanked; gpio++, irq++) { 437 for (gpio = 0; gpio < pdata->gpio_unbanked; gpio++, irq++) {
409 irq_set_chip(irq, &gpio_unbanked.chip); 438 irq_set_chip(irq, &gpio_unbanked.chip);
410 irq_set_handler_data(irq, &chips[gpio / 32]); 439 irq_set_handler_data(irq, &chips[gpio / 32]);
411 irq_set_status_flags(irq, IRQ_TYPE_EDGE_BOTH); 440 irq_set_status_flags(irq, IRQ_TYPE_EDGE_BOTH);
@@ -450,12 +479,31 @@ static int __init davinci_gpio_irq_setup(void)
450 } 479 }
451 480
452done: 481done:
453 /* BINTEN -- per-bank interrupt enable. genirq would also let these 482 /*
483 * BINTEN -- per-bank interrupt enable. genirq would also let these
454 * bits be set/cleared dynamically. 484 * bits be set/cleared dynamically.
455 */ 485 */
456 __raw_writel(binten, gpio_base + 0x08); 486 __raw_writel(binten, gpio_base + BINTEN);
457 487
458 printk(KERN_INFO "DaVinci: %d gpio irqs\n", irq - gpio_to_irq(0)); 488 printk(KERN_INFO "DaVinci: %d gpio irqs\n", irq - gpio_to_irq(0));
459 489
460 return 0; 490 return 0;
461} 491}
492
493static struct platform_driver davinci_gpio_driver = {
494 .probe = davinci_gpio_probe,
495 .driver = {
496 .name = "davinci_gpio",
497 .owner = THIS_MODULE,
498 },
499};
500
501/**
502 * GPIO driver registration needs to be done before machine_init functions
503 * access GPIO. Hence davinci_gpio_drv_reg() is a postcore_initcall.
504 */
505static int __init davinci_gpio_drv_reg(void)
506{
507 return platform_driver_register(&davinci_gpio_driver);
508}
509postcore_initcall(davinci_gpio_drv_reg);