gpio-mmio.c (616d1c1b98ac79f30216a57a170dd7cea19b3df3) gpio-mmio.c (e698613ada5896a42d2f352296fd999d7dcaf4f3)
1/*
2 * Generic driver for memory-mapped GPIO controllers.
3 *
4 * Copyright 2008 MontaVista Software, Inc.
5 * Copyright 2008,2010 Anton Vorontsov <cbouatmailru@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the

--- 47 unchanged lines hidden (view full) ---

56#include <linux/log2.h>
57#include <linux/ioport.h>
58#include <linux/io.h>
59#include <linux/gpio/driver.h>
60#include <linux/slab.h>
61#include <linux/bitops.h>
62#include <linux/platform_device.h>
63#include <linux/mod_devicetable.h>
1/*
2 * Generic driver for memory-mapped GPIO controllers.
3 *
4 * Copyright 2008 MontaVista Software, Inc.
5 * Copyright 2008,2010 Anton Vorontsov <cbouatmailru@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the

--- 47 unchanged lines hidden (view full) ---

56#include <linux/log2.h>
57#include <linux/ioport.h>
58#include <linux/io.h>
59#include <linux/gpio/driver.h>
60#include <linux/slab.h>
61#include <linux/bitops.h>
62#include <linux/platform_device.h>
63#include <linux/mod_devicetable.h>
64#include <linux/of.h>
65#include <linux/of_device.h>
64
65static void bgpio_write8(void __iomem *reg, unsigned long data)
66{
67 writeb(data, reg);
68}
69
70static unsigned long bgpio_read8(void __iomem *reg)
71{

--- 492 unchanged lines hidden (view full) ---

564
565 sz = resource_size(r);
566 if (sz != sane_sz)
567 return IOMEM_ERR_PTR(-EINVAL);
568
569 return devm_ioremap_resource(&pdev->dev, r);
570}
571
66
67static void bgpio_write8(void __iomem *reg, unsigned long data)
68{
69 writeb(data, reg);
70}
71
72static unsigned long bgpio_read8(void __iomem *reg)
73{

--- 492 unchanged lines hidden (view full) ---

566
567 sz = resource_size(r);
568 if (sz != sane_sz)
569 return IOMEM_ERR_PTR(-EINVAL);
570
571 return devm_ioremap_resource(&pdev->dev, r);
572}
573
574#ifdef CONFIG_OF
575static const struct of_device_id bgpio_of_match[] = {
576 { }
577};
578MODULE_DEVICE_TABLE(of, bgpio_of_match);
579
580static struct bgpio_pdata *bgpio_parse_dt(struct platform_device *pdev,
581 unsigned long *flags)
582{
583 struct bgpio_pdata *pdata;
584
585 if (!of_match_device(bgpio_of_match, &pdev->dev))
586 return NULL;
587
588 pdata = devm_kzalloc(&pdev->dev, sizeof(struct bgpio_pdata),
589 GFP_KERNEL);
590 if (!pdata)
591 return ERR_PTR(-ENOMEM);
592
593 pdata->base = -1;
594
595 return pdata;
596}
597#else
598static struct bgpio_pdata *bgpio_parse_dt(struct platform_device *pdev,
599 unsigned long *flags)
600{
601 return NULL;
602}
603#endif /* CONFIG_OF */
604
572static int bgpio_pdev_probe(struct platform_device *pdev)
573{
574 struct device *dev = &pdev->dev;
575 struct resource *r;
576 void __iomem *dat;
577 void __iomem *set;
578 void __iomem *clr;
579 void __iomem *dirout;
580 void __iomem *dirin;
581 unsigned long sz;
605static int bgpio_pdev_probe(struct platform_device *pdev)
606{
607 struct device *dev = &pdev->dev;
608 struct resource *r;
609 void __iomem *dat;
610 void __iomem *set;
611 void __iomem *clr;
612 void __iomem *dirout;
613 void __iomem *dirin;
614 unsigned long sz;
582 unsigned long flags = pdev->id_entry->driver_data;
615 unsigned long flags = 0;
583 int err;
584 struct gpio_chip *gc;
616 int err;
617 struct gpio_chip *gc;
585 struct bgpio_pdata *pdata = dev_get_platdata(dev);
618 struct bgpio_pdata *pdata;
586
619
620 pdata = bgpio_parse_dt(pdev, &flags);
621 if (IS_ERR(pdata))
622 return PTR_ERR(pdata);
623
624 if (!pdata) {
625 pdata = dev_get_platdata(dev);
626 flags = pdev->id_entry->driver_data;
627 }
628
587 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat");
588 if (!r)
589 return -EINVAL;
590
591 sz = resource_size(r);
592
593 dat = bgpio_map(pdev, "dat", sz);
594 if (IS_ERR(dat))

--- 46 unchanged lines hidden (view full) ---

641 },
642 { }
643};
644MODULE_DEVICE_TABLE(platform, bgpio_id_table);
645
646static struct platform_driver bgpio_driver = {
647 .driver = {
648 .name = "basic-mmio-gpio",
629 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat");
630 if (!r)
631 return -EINVAL;
632
633 sz = resource_size(r);
634
635 dat = bgpio_map(pdev, "dat", sz);
636 if (IS_ERR(dat))

--- 46 unchanged lines hidden (view full) ---

683 },
684 { }
685};
686MODULE_DEVICE_TABLE(platform, bgpio_id_table);
687
688static struct platform_driver bgpio_driver = {
689 .driver = {
690 .name = "basic-mmio-gpio",
691 .of_match_table = of_match_ptr(bgpio_of_match),
649 },
650 .id_table = bgpio_id_table,
651 .probe = bgpio_pdev_probe,
652};
653
654module_platform_driver(bgpio_driver);
655
656#endif /* CONFIG_GPIO_GENERIC_PLATFORM */
657
658MODULE_DESCRIPTION("Driver for basic memory-mapped GPIO controllers");
659MODULE_AUTHOR("Anton Vorontsov <cbouatmailru@gmail.com>");
660MODULE_LICENSE("GPL");
692 },
693 .id_table = bgpio_id_table,
694 .probe = bgpio_pdev_probe,
695};
696
697module_platform_driver(bgpio_driver);
698
699#endif /* CONFIG_GPIO_GENERIC_PLATFORM */
700
701MODULE_DESCRIPTION("Driver for basic memory-mapped GPIO controllers");
702MODULE_AUTHOR("Anton Vorontsov <cbouatmailru@gmail.com>");
703MODULE_LICENSE("GPL");