gpio-mmio.c (3bf3e21c15d4386a5f15118ec39bbc1b67ea5759) gpio-mmio.c (001cf2dec38c85d2fa123c0c4e75145cdfc6486d)
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Generic driver for memory-mapped GPIO controllers.
4 *
5 * Copyright 2008 MontaVista Software, Inc.
6 * Copyright 2008,2010 Anton Vorontsov <cbouatmailru@gmail.com>
7 *
8 * ....``.```~~~~````.`.`.`.`.```````'',,,.........`````......`.......

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

53#include <linux/ioport.h>
54#include <linux/io.h>
55#include <linux/gpio/driver.h>
56#include <linux/slab.h>
57#include <linux/bitops.h>
58#include <linux/platform_device.h>
59#include <linux/property.h>
60#include <linux/mod_devicetable.h>
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Generic driver for memory-mapped GPIO controllers.
4 *
5 * Copyright 2008 MontaVista Software, Inc.
6 * Copyright 2008,2010 Anton Vorontsov <cbouatmailru@gmail.com>
7 *
8 * ....``.```~~~~````.`.`.`.`.```````'',,,.........`````......`.......

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

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

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

683
684 sz = resource_size(r);
685 if (sz != sane_sz)
686 return IOMEM_ERR_PTR(-EINVAL);
687
688 return devm_ioremap_resource(&pdev->dev, r);
689}
690
61
62#include "gpiolib.h"
63
64static void bgpio_write8(void __iomem *reg, unsigned long data)
65{
66 writeb(data, reg);
67}
68

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

682
683 sz = resource_size(r);
684 if (sz != sane_sz)
685 return IOMEM_ERR_PTR(-EINVAL);
686
687 return devm_ioremap_resource(&pdev->dev, r);
688}
689
691#ifdef CONFIG_OF
692static const struct of_device_id bgpio_of_match[] = {
693 { .compatible = "brcm,bcm6345-gpio" },
694 { .compatible = "wd,mbl-gpio" },
695 { .compatible = "ni,169445-nand-gpio" },
696 { }
697};
698MODULE_DEVICE_TABLE(of, bgpio_of_match);
699
690static const struct of_device_id bgpio_of_match[] = {
691 { .compatible = "brcm,bcm6345-gpio" },
692 { .compatible = "wd,mbl-gpio" },
693 { .compatible = "ni,169445-nand-gpio" },
694 { }
695};
696MODULE_DEVICE_TABLE(of, bgpio_of_match);
697
700static struct bgpio_pdata *bgpio_parse_dt(struct platform_device *pdev,
701 unsigned long *flags)
698static struct bgpio_pdata *bgpio_parse_fw(struct device *dev, unsigned long *flags)
702{
703 struct bgpio_pdata *pdata;
704
699{
700 struct bgpio_pdata *pdata;
701
705 if (!pdev->dev.of_node)
702 if (!dev_fwnode(dev))
706 return NULL;
707
703 return NULL;
704
708 pdata = devm_kzalloc(&pdev->dev, sizeof(struct bgpio_pdata),
709 GFP_KERNEL);
705 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
710 if (!pdata)
711 return ERR_PTR(-ENOMEM);
712
713 pdata->base = -1;
714
706 if (!pdata)
707 return ERR_PTR(-ENOMEM);
708
709 pdata->base = -1;
710
715 if (of_device_is_big_endian(pdev->dev.of_node))
711 if (device_is_big_endian(dev))
716 *flags |= BGPIOF_BIG_ENDIAN_BYTE_ORDER;
717
712 *flags |= BGPIOF_BIG_ENDIAN_BYTE_ORDER;
713
718 if (of_property_read_bool(pdev->dev.of_node, "no-output"))
714 if (device_property_read_bool(dev, "no-output"))
719 *flags |= BGPIOF_NO_OUTPUT;
720
721 return pdata;
722}
715 *flags |= BGPIOF_NO_OUTPUT;
716
717 return pdata;
718}
723#else
724static struct bgpio_pdata *bgpio_parse_dt(struct platform_device *pdev,
725 unsigned long *flags)
726{
727 return NULL;
728}
729#endif /* CONFIG_OF */
730
731static int bgpio_pdev_probe(struct platform_device *pdev)
732{
733 struct device *dev = &pdev->dev;
734 struct resource *r;
735 void __iomem *dat;
736 void __iomem *set;
737 void __iomem *clr;
738 void __iomem *dirout;
739 void __iomem *dirin;
740 unsigned long sz;
741 unsigned long flags = 0;
742 int err;
743 struct gpio_chip *gc;
744 struct bgpio_pdata *pdata;
745
719
720static int bgpio_pdev_probe(struct platform_device *pdev)
721{
722 struct device *dev = &pdev->dev;
723 struct resource *r;
724 void __iomem *dat;
725 void __iomem *set;
726 void __iomem *clr;
727 void __iomem *dirout;
728 void __iomem *dirin;
729 unsigned long sz;
730 unsigned long flags = 0;
731 int err;
732 struct gpio_chip *gc;
733 struct bgpio_pdata *pdata;
734
746 pdata = bgpio_parse_dt(pdev, &flags);
735 pdata = bgpio_parse_fw(dev, &flags);
747 if (IS_ERR(pdata))
748 return PTR_ERR(pdata);
749
750 if (!pdata) {
751 pdata = dev_get_platdata(dev);
752 flags = pdev->id_entry->driver_data;
753 }
754

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

809 },
810 { }
811};
812MODULE_DEVICE_TABLE(platform, bgpio_id_table);
813
814static struct platform_driver bgpio_driver = {
815 .driver = {
816 .name = "basic-mmio-gpio",
736 if (IS_ERR(pdata))
737 return PTR_ERR(pdata);
738
739 if (!pdata) {
740 pdata = dev_get_platdata(dev);
741 flags = pdev->id_entry->driver_data;
742 }
743

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

798 },
799 { }
800};
801MODULE_DEVICE_TABLE(platform, bgpio_id_table);
802
803static struct platform_driver bgpio_driver = {
804 .driver = {
805 .name = "basic-mmio-gpio",
817 .of_match_table = of_match_ptr(bgpio_of_match),
806 .of_match_table = bgpio_of_match,
818 },
819 .id_table = bgpio_id_table,
820 .probe = bgpio_pdev_probe,
821};
822
823module_platform_driver(bgpio_driver);
824
825#endif /* CONFIG_GPIO_GENERIC_PLATFORM */
826
827MODULE_DESCRIPTION("Driver for basic memory-mapped GPIO controllers");
828MODULE_AUTHOR("Anton Vorontsov <cbouatmailru@gmail.com>");
829MODULE_LICENSE("GPL");
807 },
808 .id_table = bgpio_id_table,
809 .probe = bgpio_pdev_probe,
810};
811
812module_platform_driver(bgpio_driver);
813
814#endif /* CONFIG_GPIO_GENERIC_PLATFORM */
815
816MODULE_DESCRIPTION("Driver for basic memory-mapped GPIO controllers");
817MODULE_AUTHOR("Anton Vorontsov <cbouatmailru@gmail.com>");
818MODULE_LICENSE("GPL");