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);
29 if (ssb_extif_available(&bus->extif)) {
30 ssb_extif_watchdog_timer_set(&bus->extif, ticks);
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;
56 pdev = platform_device_register_data(NULL, "bcm47xx-wdt",
60 pr_debug("can not register watchdog device, err: %li\n",
69 u32 ssb_gpio_in(struct ssb_bus *bus, u32 mask)
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);
81 spin_unlock_irqrestore(&bus->gpio_lock, flags);
85 EXPORT_SYMBOL(ssb_gpio_in);
87 u32 ssb_gpio_out(struct ssb_bus *bus, u32 mask, u32 value)
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);
99 spin_unlock_irqrestore(&bus->gpio_lock, flags);
103 EXPORT_SYMBOL(ssb_gpio_out);
105 u32 ssb_gpio_outen(struct ssb_bus *bus, u32 mask, u32 value)
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);
117 spin_unlock_irqrestore(&bus->gpio_lock, flags);
121 EXPORT_SYMBOL(ssb_gpio_outen);
123 u32 ssb_gpio_control(struct ssb_bus *bus, u32 mask, u32 value)
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);
135 EXPORT_SYMBOL(ssb_gpio_control);
137 u32 ssb_gpio_intmask(struct ssb_bus *bus, u32 mask, u32 value)
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);
149 spin_unlock_irqrestore(&bus->gpio_lock, flags);
153 EXPORT_SYMBOL(ssb_gpio_intmask);
155 u32 ssb_gpio_polarity(struct ssb_bus *bus, u32 mask, u32 value)
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);
167 spin_unlock_irqrestore(&bus->gpio_lock, flags);
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;
181 for (i = 0; i < bus->nr_devices; i++) {
182 dev = &(bus->devices[i]);
183 if (dev->id.coreid != SSB_DEV_ETHERNET_GBIT)
187 !device_is_registered(dev->dev))
189 res = ssb_gige_pcibios_plat_dev_init(dev, pdev);
196 #endif /* CONFIG_SSB_DRIVER_GIGE */
198 int ssb_pcibios_plat_dev_init(struct pci_dev *dev)
202 err = ssb_pcicore_plat_dev_init(dev);
205 #ifdef CONFIG_SSB_DRIVER_GIGE
206 err = ssb_for_each_bus_call((unsigned long)dev, gige_pci_init_callback);
210 /* This is not a PCI device on any SSB device. */
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;
223 for (i = 0; i < bus->nr_devices; i++) {
224 dev = &(bus->devices[i]);
225 if (dev->id.coreid != SSB_DEV_ETHERNET_GBIT)
229 !device_is_registered(dev->dev))
231 res = ssb_gige_map_irq(dev, pdev);
238 #endif /* CONFIG_SSB_DRIVER_GIGE */
240 int ssb_pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
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);
250 #ifdef CONFIG_SSB_DRIVER_GIGE
251 res = ssb_for_each_bus_call((unsigned long)dev, gige_map_irq_callback);
255 /* This is not a PCI device on any SSB device. */