add gpio sysfs entries
[oweals/openwrt.git] / target / linux / brcm47xx / patches-3.3 / 501-bcma-add-gpio-driver.patch
1 --- a/drivers/bcma/Kconfig
2 +++ b/drivers/bcma/Kconfig
3 @@ -39,6 +39,11 @@ config BCMA_HOST_SOC
4         depends on BCMA_DRIVER_MIPS
5         select USB_HCD_BCMA if USB_EHCI_HCD || USB_OHCI_HCD
6  
7 +config BCMA_DRIVER_GPIO
8 +       bool
9 +       depends on BCMA_DRIVER_MIPS
10 +       default y
11 +
12  config BCMA_SFLASH
13         bool
14         depends on BCMA_DRIVER_MIPS
15 --- a/drivers/bcma/Makefile
16 +++ b/drivers/bcma/Makefile
17 @@ -6,6 +6,7 @@ bcma-y                                  += driver_pci.o
18  bcma-$(CONFIG_BCMA_DRIVER_PCI_HOSTMODE)        += driver_pci_host.o
19  bcma-$(CONFIG_BCMA_DRIVER_MIPS)                += driver_mips.o
20  bcma-$(CONFIG_BCMA_DRIVER_GMAC_CMN)    += driver_gmac_cmn.o
21 +bcma-$(CONFIG_BCMA_DRIVER_GPIO)                += driver_gpio.o
22  bcma-$(CONFIG_BCMA_HOST_PCI)           += host_pci.o
23  bcma-$(CONFIG_BCMA_HOST_SOC)           += host_soc.o
24  obj-$(CONFIG_BCMA)                     += bcma.o
25 --- /dev/null
26 +++ b/drivers/bcma/driver_gpio.c
27 @@ -0,0 +1,90 @@
28 +/*
29 + * Broadcom specific AMBA
30 + * GPIO driver for SoCs
31 + *
32 + * Copyright 2012, Hauke Mehrtens <hauke@hauke-m.de>
33 + *
34 + * Licensed under the GNU/GPL. See COPYING for details.
35 + */
36 +
37 +#include <linux/export.h>
38 +#include <linux/bcma/bcma.h>
39 +#include <linux/bcma/bcma_driver_gpio.h>
40 +
41 +u32 bcma_gpio_in(struct bcma_bus *bus, u32 mask)
42 +{
43 +       unsigned long flags;
44 +       u32 res = 0;
45 +
46 +       spin_lock_irqsave(&bus->gpio_lock, flags);
47 +       res = bcma_chipco_gpio_in(&bus->drv_cc, mask);
48 +       spin_unlock_irqrestore(&bus->gpio_lock, flags);
49 +
50 +       return res;
51 +}
52 +EXPORT_SYMBOL(bcma_gpio_in);
53 +
54 +u32 bcma_gpio_out(struct bcma_bus *bus, u32 mask, u32 value)
55 +{
56 +       unsigned long flags;
57 +       u32 res = 0;
58 +
59 +       spin_lock_irqsave(&bus->gpio_lock, flags);
60 +       res = bcma_chipco_gpio_out(&bus->drv_cc, mask, value);
61 +       spin_unlock_irqrestore(&bus->gpio_lock, flags);
62 +
63 +       return res;
64 +}
65 +EXPORT_SYMBOL(bcma_gpio_out);
66 +
67 +u32 bcma_gpio_outen(struct bcma_bus *bus, u32 mask, u32 value)
68 +{
69 +       unsigned long flags;
70 +       u32 res = 0;
71 +
72 +       spin_lock_irqsave(&bus->gpio_lock, flags);
73 +       res = bcma_chipco_gpio_outen(&bus->drv_cc, mask, value);
74 +       spin_unlock_irqrestore(&bus->gpio_lock, flags);
75 +
76 +       return res;
77 +}
78 +EXPORT_SYMBOL(bcma_gpio_outen);
79 +
80 +u32 bcma_gpio_control(struct bcma_bus *bus, u32 mask, u32 value)
81 +{
82 +       unsigned long flags;
83 +       u32 res = 0;
84 +
85 +       spin_lock_irqsave(&bus->gpio_lock, flags);
86 +       res = bcma_chipco_gpio_control(&bus->drv_cc, mask, value);
87 +       spin_unlock_irqrestore(&bus->gpio_lock, flags);
88 +
89 +       return res;
90 +}
91 +EXPORT_SYMBOL(bcma_gpio_control);
92 +
93 +u32 bcma_gpio_intmask(struct bcma_bus *bus, u32 mask, u32 value)
94 +{
95 +       unsigned long flags;
96 +       u32 res = 0;
97 +
98 +       spin_lock_irqsave(&bus->gpio_lock, flags);
99 +       res = bcma_chipco_gpio_intmask(&bus->drv_cc, mask, value);
100 +       spin_unlock_irqrestore(&bus->gpio_lock, flags);
101 +
102 +       return res;
103 +}
104 +EXPORT_SYMBOL(bcma_gpio_intmask);
105 +
106 +u32 bcma_gpio_polarity(struct bcma_bus *bus, u32 mask, u32 value)
107 +{
108 +       unsigned long flags;
109 +       u32 res = 0;
110 +
111 +       spin_lock_irqsave(&bus->gpio_lock, flags);
112 +       res = bcma_chipco_gpio_polarity(&bus->drv_cc, mask, value);
113 +       spin_unlock_irqrestore(&bus->gpio_lock, flags);
114 +
115 +       return res;
116 +}
117 +EXPORT_SYMBOL(bcma_gpio_polarity);
118 --- a/drivers/bcma/scan.c
119 +++ b/drivers/bcma/scan.c
120 @@ -422,6 +422,10 @@ void bcma_init_bus(struct bcma_bus *bus)
121         if (bus->init_done)
122                 return;
123  
124 +#ifdef CONFIG_BCMA_DRIVER_GPIO
125 +       spin_lock_init(&bus->gpio_lock);
126 +#endif
127 +
128         INIT_LIST_HEAD(&bus->cores);
129         bus->nr_cores = 0;
130  
131 --- a/include/linux/bcma/bcma.h
132 +++ b/include/linux/bcma/bcma.h
133 @@ -255,6 +255,11 @@ struct bcma_bus {
134         struct bcma_drv_mips drv_mips;
135         struct bcma_drv_gmac_cmn drv_gmac_cmn;
136  
137 +#ifdef CONFIG_BCMA_DRIVER_GPIO
138 +       /* Lock for GPIO register access. */
139 +       spinlock_t gpio_lock;
140 +#endif /* CONFIG_BCMA_DRIVER_GPIO */
141 +
142         /* We decided to share SPROM struct with SSB as long as we do not need
143          * any hacks for BCMA. This simplifies drivers code. */
144         struct ssb_sprom sprom;
145 --- /dev/null
146 +++ b/include/linux/bcma/bcma_driver_gpio.h
147 @@ -0,0 +1,21 @@
148 +#ifndef LINUX_BCMA_DRIVER_GPIO_H_
149 +#define LINUX_BCMA_DRIVER_GPIO_H_
150 +
151 +#include <linux/types.h>
152 +#include <linux/bcma/bcma.h>
153 +
154 +#define BCMA_GPIO_CC_LINES     16
155 +
156 +u32 bcma_gpio_in(struct bcma_bus *bus, u32 mask);
157 +u32 bcma_gpio_out(struct bcma_bus *bus, u32 mask, u32 value);
158 +u32 bcma_gpio_outen(struct bcma_bus *bus, u32 mask, u32 value);
159 +u32 bcma_gpio_control(struct bcma_bus *bus, u32 mask, u32 value);
160 +u32 bcma_gpio_intmask(struct bcma_bus *bus, u32 mask, u32 value);
161 +u32 bcma_gpio_polarity(struct bcma_bus *bus, u32 mask, u32 value);
162 +
163 +static inline int bcma_gpio_count(struct bcma_bus *bus)
164 +{
165 +       return BCMA_GPIO_CC_LINES;
166 +}
167 +
168 +#endif /* LINUX_BCMA_DRIVER_GPIO_H_ */