~ubuntu-branches/ubuntu/saucy/linux-ti-omap4/saucy-proposed

« back to all changes in this revision

Viewing changes to drivers/gpio/gpio-langwell.c

  • Committer: Package Import Robot
  • Author(s): Paolo Pisati, Paolo Pisati, Stefan Bader, Upstream Kernel Changes
  • Date: 2012-08-15 17:17:43 UTC
  • Revision ID: package-import@ubuntu.com-20120815171743-h5wnuf51xe7pvdid
Tags: 3.5.0-207.13
[ Paolo Pisati ]

* Start new release

[ Stefan Bader ]

* (config) Enable getabis to use local package copies

[ Upstream Kernel Changes ]

* fixup: gargabe collect iva_seq[0|1] init
* [Config] enable all SND_OMAP_SOC_*s
* fixup: cm2xxx_3xxx.o is needed for omap2_cm_read|write_reg
* fixup: add some snd_soc_dai* helper functions
* fixup: s/snd_soc_dpcm_params/snd_soc_dpcm/g
* fixup: typo, no_host_mode and useless SDP4430 init
* fixup: enable again aess hwmod

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
#include <linux/gpio.h>
37
37
#include <linux/slab.h>
38
38
#include <linux/pm_runtime.h>
 
39
#include <linux/irqdomain.h>
39
40
 
40
41
/*
41
42
 * Langwell chip has 64 pins and thus there are 2 32bit registers to control
66
67
        struct gpio_chip                chip;
67
68
        void                            *reg_base;
68
69
        spinlock_t                      lock;
69
 
        unsigned                        irq_base;
70
70
        struct pci_dev                  *pdev;
 
71
        struct irq_domain               *domain;
71
72
};
72
73
 
73
74
static void __iomem *gpio_reg(struct gpio_chip *chip, unsigned offset,
176
177
static int lnw_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
177
178
{
178
179
        struct lnw_gpio *lnw = container_of(chip, struct lnw_gpio, chip);
179
 
        return lnw->irq_base + offset;
 
180
        return irq_create_mapping(lnw->domain, offset);
180
181
}
181
182
 
182
183
static int lnw_irq_type(struct irq_data *d, unsigned type)
183
184
{
184
185
        struct lnw_gpio *lnw = irq_data_get_irq_chip_data(d);
185
 
        u32 gpio = d->irq - lnw->irq_base;
 
186
        u32 gpio = irqd_to_hwirq(d);
186
187
        unsigned long flags;
187
188
        u32 value;
188
189
        void __iomem *grer = gpio_reg(&lnw->chip, gpio, GRER);
249
250
        /* check GPIO controller to check which pin triggered the interrupt */
250
251
        for (base = 0; base < lnw->chip.ngpio; base += 32) {
251
252
                gedr = gpio_reg(&lnw->chip, base, GEDR);
252
 
                pending = readl(gedr);
253
 
                while (pending) {
 
253
                while ((pending = readl(gedr))) {
254
254
                        gpio = __ffs(pending);
255
255
                        mask = BIT(gpio);
256
 
                        pending &= ~mask;
257
256
                        /* Clear before handling so we can't lose an edge */
258
257
                        writel(mask, gedr);
259
 
                        generic_handle_irq(lnw->irq_base + base + gpio);
 
258
                        generic_handle_irq(irq_find_mapping(lnw->domain,
 
259
                                                            base + gpio));
260
260
                }
261
261
        }
262
262
 
263
263
        chip->irq_eoi(data);
264
264
}
265
265
 
 
266
static void lnw_irq_init_hw(struct lnw_gpio *lnw)
 
267
{
 
268
        void __iomem *reg;
 
269
        unsigned base;
 
270
 
 
271
        for (base = 0; base < lnw->chip.ngpio; base += 32) {
 
272
                /* Clear the rising-edge detect register */
 
273
                reg = gpio_reg(&lnw->chip, base, GRER);
 
274
                writel(0, reg);
 
275
                /* Clear the falling-edge detect register */
 
276
                reg = gpio_reg(&lnw->chip, base, GFER);
 
277
                writel(0, reg);
 
278
                /* Clear the edge detect status register */
 
279
                reg = gpio_reg(&lnw->chip, base, GEDR);
 
280
                writel(~0, reg);
 
281
        }
 
282
}
 
283
 
 
284
static int lnw_gpio_irq_map(struct irq_domain *d, unsigned int virq,
 
285
                            irq_hw_number_t hw)
 
286
{
 
287
        struct lnw_gpio *lnw = d->host_data;
 
288
 
 
289
        irq_set_chip_and_handler_name(virq, &lnw_irqchip, handle_simple_irq,
 
290
                                      "demux");
 
291
        irq_set_chip_data(virq, lnw);
 
292
        irq_set_irq_type(virq, IRQ_TYPE_NONE);
 
293
 
 
294
        return 0;
 
295
}
 
296
 
 
297
static const struct irq_domain_ops lnw_gpio_irq_ops = {
 
298
        .map = lnw_gpio_irq_map,
 
299
        .xlate = irq_domain_xlate_twocell,
 
300
};
 
301
 
266
302
#ifdef CONFIG_PM
267
303
static int lnw_gpio_runtime_resume(struct device *dev)
268
304
{
300
336
                        const struct pci_device_id *id)
301
337
{
302
338
        void *base;
303
 
        int i;
304
339
        resource_size_t start, len;
305
340
        struct lnw_gpio *lnw;
306
 
        u32 irq_base;
307
341
        u32 gpio_base;
308
342
        int retval = 0;
 
343
        int ngpio = id->driver_data;
309
344
 
310
345
        retval = pci_enable_device(pdev);
311
346
        if (retval)
312
 
                goto done;
 
347
                return retval;
313
348
 
314
349
        retval = pci_request_regions(pdev, "langwell_gpio");
315
350
        if (retval) {
316
351
                dev_err(&pdev->dev, "error requesting resources\n");
317
352
                goto err2;
318
353
        }
319
 
        /* get the irq_base from bar1 */
 
354
        /* get the gpio_base from bar1 */
320
355
        start = pci_resource_start(pdev, 1);
321
356
        len = pci_resource_len(pdev, 1);
322
357
        base = ioremap_nocache(start, len);
324
359
                dev_err(&pdev->dev, "error mapping bar1\n");
325
360
                goto err3;
326
361
        }
327
 
        irq_base = *(u32 *)base;
328
362
        gpio_base = *((u32 *)base + 1);
329
363
        /* release the IO mapping, since we already get the info from bar1 */
330
364
        iounmap(base);
331
365
        /* get the register base from bar0 */
332
366
        start = pci_resource_start(pdev, 0);
333
367
        len = pci_resource_len(pdev, 0);
334
 
        base = ioremap_nocache(start, len);
 
368
        base = devm_ioremap_nocache(&pdev->dev, start, len);
335
369
        if (!base) {
336
370
                dev_err(&pdev->dev, "error mapping bar0\n");
337
371
                retval = -EFAULT;
338
372
                goto err3;
339
373
        }
340
374
 
341
 
        lnw = kzalloc(sizeof(struct lnw_gpio), GFP_KERNEL);
 
375
        lnw = devm_kzalloc(&pdev->dev, sizeof(struct lnw_gpio), GFP_KERNEL);
342
376
        if (!lnw) {
343
377
                dev_err(&pdev->dev, "can't allocate langwell_gpio chip data\n");
344
378
                retval = -ENOMEM;
345
 
                goto err4;
 
379
                goto err3;
346
380
        }
 
381
 
 
382
        lnw->domain = irq_domain_add_linear(pdev->dev.of_node, ngpio,
 
383
                                            &lnw_gpio_irq_ops, lnw);
 
384
        if (!lnw->domain)
 
385
                goto err3;
 
386
 
347
387
        lnw->reg_base = base;
348
 
        lnw->irq_base = irq_base;
349
388
        lnw->chip.label = dev_name(&pdev->dev);
350
389
        lnw->chip.request = lnw_gpio_request;
351
390
        lnw->chip.direction_input = lnw_gpio_direction_input;
354
393
        lnw->chip.set = lnw_gpio_set;
355
394
        lnw->chip.to_irq = lnw_gpio_to_irq;
356
395
        lnw->chip.base = gpio_base;
357
 
        lnw->chip.ngpio = id->driver_data;
 
396
        lnw->chip.ngpio = ngpio;
358
397
        lnw->chip.can_sleep = 0;
359
398
        lnw->pdev = pdev;
360
399
        pci_set_drvdata(pdev, lnw);
361
400
        retval = gpiochip_add(&lnw->chip);
362
401
        if (retval) {
363
402
                dev_err(&pdev->dev, "langwell gpiochip_add error %d\n", retval);
364
 
                goto err5;
 
403
                goto err3;
365
404
        }
 
405
 
 
406
        lnw_irq_init_hw(lnw);
 
407
 
366
408
        irq_set_handler_data(pdev->irq, lnw);
367
409
        irq_set_chained_handler(pdev->irq, lnw_irq_handler);
368
 
        for (i = 0; i < lnw->chip.ngpio; i++) {
369
 
                irq_set_chip_and_handler_name(i + lnw->irq_base, &lnw_irqchip,
370
 
                                              handle_simple_irq, "demux");
371
 
                irq_set_chip_data(i + lnw->irq_base, lnw);
372
 
        }
373
410
 
374
411
        spin_lock_init(&lnw->lock);
375
412
 
376
413
        pm_runtime_put_noidle(&pdev->dev);
377
414
        pm_runtime_allow(&pdev->dev);
378
415
 
379
 
        goto done;
380
 
err5:
381
 
        kfree(lnw);
382
 
err4:
383
 
        iounmap(base);
 
416
        return 0;
 
417
 
384
418
err3:
385
419
        pci_release_regions(pdev);
386
420
err2:
387
421
        pci_disable_device(pdev);
388
 
done:
389
422
        return retval;
390
423
}
391
424