ARM: dts: NSP: Fixed QSPI compatible string
[linux/fpc-iii.git] / drivers / ssb / embedded.c
blob8254ed25e0637a1592ca8c6497a1793a3eda288a
1 /*
2 * Sonics Silicon Backplane
3 * Embedded systems support code
5 * Copyright 2005-2008, Broadcom Corporation
6 * Copyright 2006-2008, Michael Buesch <m@bues.ch>
7 * Copyright 2012, Hauke Mehrtens <hauke@hauke-m.de>
9 * Licensed under the GNU/GPL. See COPYING for details.
12 #include "ssb_private.h"
14 #include <linux/export.h>
15 #include <linux/platform_device.h>
16 #include <linux/ssb/ssb.h>
17 #include <linux/ssb/ssb_embedded.h>
18 #include <linux/ssb/ssb_driver_pci.h>
19 #include <linux/ssb/ssb_driver_gige.h>
20 #include <linux/pci.h>
23 int ssb_watchdog_timer_set(struct ssb_bus *bus, u32 ticks)
25 if (ssb_chipco_available(&bus->chipco)) {
26 ssb_chipco_watchdog_timer_set(&bus->chipco, ticks);
27 return 0;
29 if (ssb_extif_available(&bus->extif)) {
30 ssb_extif_watchdog_timer_set(&bus->extif, ticks);
31 return 0;
33 return -ENODEV;
35 EXPORT_SYMBOL(ssb_watchdog_timer_set);
37 int ssb_watchdog_register(struct ssb_bus *bus)
39 struct bcm47xx_wdt wdt = {};
40 struct platform_device *pdev;
42 if (ssb_chipco_available(&bus->chipco)) {
43 wdt.driver_data = &bus->chipco;
44 wdt.timer_set = ssb_chipco_watchdog_timer_set_wdt;
45 wdt.timer_set_ms = ssb_chipco_watchdog_timer_set_ms;
46 wdt.max_timer_ms = bus->chipco.max_timer_ms;
47 } else if (ssb_extif_available(&bus->extif)) {
48 wdt.driver_data = &bus->extif;
49 wdt.timer_set = ssb_extif_watchdog_timer_set_wdt;
50 wdt.timer_set_ms = ssb_extif_watchdog_timer_set_ms;
51 wdt.max_timer_ms = SSB_EXTIF_WATCHDOG_MAX_TIMER_MS;
52 } else {
53 return -ENODEV;
56 pdev = platform_device_register_data(NULL, "bcm47xx-wdt",
57 bus->busnumber, &wdt,
58 sizeof(wdt));
59 if (IS_ERR(pdev)) {
60 pr_debug("can not register watchdog device, err: %li\n",
61 PTR_ERR(pdev));
62 return PTR_ERR(pdev);
65 bus->watchdog = pdev;
66 return 0;
69 u32 ssb_gpio_in(struct ssb_bus *bus, u32 mask)
71 unsigned long flags;
72 u32 res = 0;
74 spin_lock_irqsave(&bus->gpio_lock, flags);
75 if (ssb_chipco_available(&bus->chipco))
76 res = ssb_chipco_gpio_in(&bus->chipco, mask);
77 else if (ssb_extif_available(&bus->extif))
78 res = ssb_extif_gpio_in(&bus->extif, mask);
79 else
80 WARN_ON(1);
81 spin_unlock_irqrestore(&bus->gpio_lock, flags);
83 return res;
85 EXPORT_SYMBOL(ssb_gpio_in);
87 u32 ssb_gpio_out(struct ssb_bus *bus, u32 mask, u32 value)
89 unsigned long flags;
90 u32 res = 0;
92 spin_lock_irqsave(&bus->gpio_lock, flags);
93 if (ssb_chipco_available(&bus->chipco))
94 res = ssb_chipco_gpio_out(&bus->chipco, mask, value);
95 else if (ssb_extif_available(&bus->extif))
96 res = ssb_extif_gpio_out(&bus->extif, mask, value);
97 else
98 WARN_ON(1);
99 spin_unlock_irqrestore(&bus->gpio_lock, flags);
101 return res;
103 EXPORT_SYMBOL(ssb_gpio_out);
105 u32 ssb_gpio_outen(struct ssb_bus *bus, u32 mask, u32 value)
107 unsigned long flags;
108 u32 res = 0;
110 spin_lock_irqsave(&bus->gpio_lock, flags);
111 if (ssb_chipco_available(&bus->chipco))
112 res = ssb_chipco_gpio_outen(&bus->chipco, mask, value);
113 else if (ssb_extif_available(&bus->extif))
114 res = ssb_extif_gpio_outen(&bus->extif, mask, value);
115 else
116 WARN_ON(1);
117 spin_unlock_irqrestore(&bus->gpio_lock, flags);
119 return res;
121 EXPORT_SYMBOL(ssb_gpio_outen);
123 u32 ssb_gpio_control(struct ssb_bus *bus, u32 mask, u32 value)
125 unsigned long flags;
126 u32 res = 0;
128 spin_lock_irqsave(&bus->gpio_lock, flags);
129 if (ssb_chipco_available(&bus->chipco))
130 res = ssb_chipco_gpio_control(&bus->chipco, mask, value);
131 spin_unlock_irqrestore(&bus->gpio_lock, flags);
133 return res;
135 EXPORT_SYMBOL(ssb_gpio_control);
137 u32 ssb_gpio_intmask(struct ssb_bus *bus, u32 mask, u32 value)
139 unsigned long flags;
140 u32 res = 0;
142 spin_lock_irqsave(&bus->gpio_lock, flags);
143 if (ssb_chipco_available(&bus->chipco))
144 res = ssb_chipco_gpio_intmask(&bus->chipco, mask, value);
145 else if (ssb_extif_available(&bus->extif))
146 res = ssb_extif_gpio_intmask(&bus->extif, mask, value);
147 else
148 WARN_ON(1);
149 spin_unlock_irqrestore(&bus->gpio_lock, flags);
151 return res;
153 EXPORT_SYMBOL(ssb_gpio_intmask);
155 u32 ssb_gpio_polarity(struct ssb_bus *bus, u32 mask, u32 value)
157 unsigned long flags;
158 u32 res = 0;
160 spin_lock_irqsave(&bus->gpio_lock, flags);
161 if (ssb_chipco_available(&bus->chipco))
162 res = ssb_chipco_gpio_polarity(&bus->chipco, mask, value);
163 else if (ssb_extif_available(&bus->extif))
164 res = ssb_extif_gpio_polarity(&bus->extif, mask, value);
165 else
166 WARN_ON(1);
167 spin_unlock_irqrestore(&bus->gpio_lock, flags);
169 return res;
171 EXPORT_SYMBOL(ssb_gpio_polarity);
173 #ifdef CONFIG_SSB_DRIVER_GIGE
174 static int gige_pci_init_callback(struct ssb_bus *bus, unsigned long data)
176 struct pci_dev *pdev = (struct pci_dev *)data;
177 struct ssb_device *dev;
178 unsigned int i;
179 int res;
181 for (i = 0; i < bus->nr_devices; i++) {
182 dev = &(bus->devices[i]);
183 if (dev->id.coreid != SSB_DEV_ETHERNET_GBIT)
184 continue;
185 if (!dev->dev ||
186 !dev->dev->driver ||
187 !device_is_registered(dev->dev))
188 continue;
189 res = ssb_gige_pcibios_plat_dev_init(dev, pdev);
190 if (res >= 0)
191 return res;
194 return -ENODEV;
196 #endif /* CONFIG_SSB_DRIVER_GIGE */
198 int ssb_pcibios_plat_dev_init(struct pci_dev *dev)
200 int err;
202 err = ssb_pcicore_plat_dev_init(dev);
203 if (!err)
204 return 0;
205 #ifdef CONFIG_SSB_DRIVER_GIGE
206 err = ssb_for_each_bus_call((unsigned long)dev, gige_pci_init_callback);
207 if (err >= 0)
208 return err;
209 #endif
210 /* This is not a PCI device on any SSB device. */
212 return -ENODEV;
215 #ifdef CONFIG_SSB_DRIVER_GIGE
216 static int gige_map_irq_callback(struct ssb_bus *bus, unsigned long data)
218 const struct pci_dev *pdev = (const struct pci_dev *)data;
219 struct ssb_device *dev;
220 unsigned int i;
221 int res;
223 for (i = 0; i < bus->nr_devices; i++) {
224 dev = &(bus->devices[i]);
225 if (dev->id.coreid != SSB_DEV_ETHERNET_GBIT)
226 continue;
227 if (!dev->dev ||
228 !dev->dev->driver ||
229 !device_is_registered(dev->dev))
230 continue;
231 res = ssb_gige_map_irq(dev, pdev);
232 if (res >= 0)
233 return res;
236 return -ENODEV;
238 #endif /* CONFIG_SSB_DRIVER_GIGE */
240 int ssb_pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
242 int res;
244 /* Check if this PCI device is a device on a SSB bus or device
245 * and return the IRQ number for it. */
247 res = ssb_pcicore_pcibios_map_irq(dev, slot, pin);
248 if (res >= 0)
249 return res;
250 #ifdef CONFIG_SSB_DRIVER_GIGE
251 res = ssb_for_each_bus_call((unsigned long)dev, gige_map_irq_callback);
252 if (res >= 0)
253 return res;
254 #endif
255 /* This is not a PCI device on any SSB device. */
257 return -ENODEV;