embedded.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*
  2. * Sonics Silicon Backplane
  3. * Embedded systems support code
  4. *
  5. * Copyright 2005-2008, Broadcom Corporation
  6. * Copyright 2006-2008, Michael Buesch <m@bues.ch>
  7. * Copyright 2012, Hauke Mehrtens <hauke@hauke-m.de>
  8. *
  9. * Licensed under the GNU/GPL. See COPYING for details.
  10. */
  11. #include <linux/export.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/ssb/ssb.h>
  14. #include <linux/ssb/ssb_embedded.h>
  15. #include <linux/ssb/ssb_driver_pci.h>
  16. #include <linux/ssb/ssb_driver_gige.h>
  17. #include <linux/pci.h>
  18. #include "ssb_private.h"
  19. int ssb_watchdog_timer_set(struct ssb_bus *bus, u32 ticks)
  20. {
  21. if (ssb_chipco_available(&bus->chipco)) {
  22. ssb_chipco_watchdog_timer_set(&bus->chipco, ticks);
  23. return 0;
  24. }
  25. if (ssb_extif_available(&bus->extif)) {
  26. ssb_extif_watchdog_timer_set(&bus->extif, ticks);
  27. return 0;
  28. }
  29. return -ENODEV;
  30. }
  31. EXPORT_SYMBOL(ssb_watchdog_timer_set);
  32. int ssb_watchdog_register(struct ssb_bus *bus)
  33. {
  34. struct bcm47xx_wdt wdt = {};
  35. struct platform_device *pdev;
  36. if (ssb_chipco_available(&bus->chipco)) {
  37. wdt.driver_data = &bus->chipco;
  38. wdt.timer_set = ssb_chipco_watchdog_timer_set_wdt;
  39. wdt.timer_set_ms = ssb_chipco_watchdog_timer_set_ms;
  40. wdt.max_timer_ms = bus->chipco.max_timer_ms;
  41. } else if (ssb_extif_available(&bus->extif)) {
  42. wdt.driver_data = &bus->extif;
  43. wdt.timer_set = ssb_extif_watchdog_timer_set_wdt;
  44. wdt.timer_set_ms = ssb_extif_watchdog_timer_set_ms;
  45. wdt.max_timer_ms = SSB_EXTIF_WATCHDOG_MAX_TIMER_MS;
  46. } else {
  47. return -ENODEV;
  48. }
  49. pdev = platform_device_register_data(NULL, "bcm47xx-wdt",
  50. bus->busnumber, &wdt,
  51. sizeof(wdt));
  52. if (IS_ERR(pdev)) {
  53. ssb_dprintk(KERN_INFO PFX
  54. "can not register watchdog device, err: %li\n",
  55. PTR_ERR(pdev));
  56. return PTR_ERR(pdev);
  57. }
  58. bus->watchdog = pdev;
  59. return 0;
  60. }
  61. u32 ssb_gpio_in(struct ssb_bus *bus, u32 mask)
  62. {
  63. unsigned long flags;
  64. u32 res = 0;
  65. spin_lock_irqsave(&bus->gpio_lock, flags);
  66. if (ssb_chipco_available(&bus->chipco))
  67. res = ssb_chipco_gpio_in(&bus->chipco, mask);
  68. else if (ssb_extif_available(&bus->extif))
  69. res = ssb_extif_gpio_in(&bus->extif, mask);
  70. else
  71. SSB_WARN_ON(1);
  72. spin_unlock_irqrestore(&bus->gpio_lock, flags);
  73. return res;
  74. }
  75. EXPORT_SYMBOL(ssb_gpio_in);
  76. u32 ssb_gpio_out(struct ssb_bus *bus, u32 mask, u32 value)
  77. {
  78. unsigned long flags;
  79. u32 res = 0;
  80. spin_lock_irqsave(&bus->gpio_lock, flags);
  81. if (ssb_chipco_available(&bus->chipco))
  82. res = ssb_chipco_gpio_out(&bus->chipco, mask, value);
  83. else if (ssb_extif_available(&bus->extif))
  84. res = ssb_extif_gpio_out(&bus->extif, mask, value);
  85. else
  86. SSB_WARN_ON(1);
  87. spin_unlock_irqrestore(&bus->gpio_lock, flags);
  88. return res;
  89. }
  90. EXPORT_SYMBOL(ssb_gpio_out);
  91. u32 ssb_gpio_outen(struct ssb_bus *bus, u32 mask, u32 value)
  92. {
  93. unsigned long flags;
  94. u32 res = 0;
  95. spin_lock_irqsave(&bus->gpio_lock, flags);
  96. if (ssb_chipco_available(&bus->chipco))
  97. res = ssb_chipco_gpio_outen(&bus->chipco, mask, value);
  98. else if (ssb_extif_available(&bus->extif))
  99. res = ssb_extif_gpio_outen(&bus->extif, mask, value);
  100. else
  101. SSB_WARN_ON(1);
  102. spin_unlock_irqrestore(&bus->gpio_lock, flags);
  103. return res;
  104. }
  105. EXPORT_SYMBOL(ssb_gpio_outen);
  106. u32 ssb_gpio_control(struct ssb_bus *bus, u32 mask, u32 value)
  107. {
  108. unsigned long flags;
  109. u32 res = 0;
  110. spin_lock_irqsave(&bus->gpio_lock, flags);
  111. if (ssb_chipco_available(&bus->chipco))
  112. res = ssb_chipco_gpio_control(&bus->chipco, mask, value);
  113. spin_unlock_irqrestore(&bus->gpio_lock, flags);
  114. return res;
  115. }
  116. EXPORT_SYMBOL(ssb_gpio_control);
  117. u32 ssb_gpio_intmask(struct ssb_bus *bus, u32 mask, u32 value)
  118. {
  119. unsigned long flags;
  120. u32 res = 0;
  121. spin_lock_irqsave(&bus->gpio_lock, flags);
  122. if (ssb_chipco_available(&bus->chipco))
  123. res = ssb_chipco_gpio_intmask(&bus->chipco, mask, value);
  124. else if (ssb_extif_available(&bus->extif))
  125. res = ssb_extif_gpio_intmask(&bus->extif, mask, value);
  126. else
  127. SSB_WARN_ON(1);
  128. spin_unlock_irqrestore(&bus->gpio_lock, flags);
  129. return res;
  130. }
  131. EXPORT_SYMBOL(ssb_gpio_intmask);
  132. u32 ssb_gpio_polarity(struct ssb_bus *bus, u32 mask, u32 value)
  133. {
  134. unsigned long flags;
  135. u32 res = 0;
  136. spin_lock_irqsave(&bus->gpio_lock, flags);
  137. if (ssb_chipco_available(&bus->chipco))
  138. res = ssb_chipco_gpio_polarity(&bus->chipco, mask, value);
  139. else if (ssb_extif_available(&bus->extif))
  140. res = ssb_extif_gpio_polarity(&bus->extif, mask, value);
  141. else
  142. SSB_WARN_ON(1);
  143. spin_unlock_irqrestore(&bus->gpio_lock, flags);
  144. return res;
  145. }
  146. EXPORT_SYMBOL(ssb_gpio_polarity);
  147. #ifdef CONFIG_SSB_DRIVER_GIGE
  148. static int gige_pci_init_callback(struct ssb_bus *bus, unsigned long data)
  149. {
  150. struct pci_dev *pdev = (struct pci_dev *)data;
  151. struct ssb_device *dev;
  152. unsigned int i;
  153. int res;
  154. for (i = 0; i < bus->nr_devices; i++) {
  155. dev = &(bus->devices[i]);
  156. if (dev->id.coreid != SSB_DEV_ETHERNET_GBIT)
  157. continue;
  158. if (!dev->dev ||
  159. !dev->dev->driver ||
  160. !device_is_registered(dev->dev))
  161. continue;
  162. res = ssb_gige_pcibios_plat_dev_init(dev, pdev);
  163. if (res >= 0)
  164. return res;
  165. }
  166. return -ENODEV;
  167. }
  168. #endif /* CONFIG_SSB_DRIVER_GIGE */
  169. int ssb_pcibios_plat_dev_init(struct pci_dev *dev)
  170. {
  171. int err;
  172. err = ssb_pcicore_plat_dev_init(dev);
  173. if (!err)
  174. return 0;
  175. #ifdef CONFIG_SSB_DRIVER_GIGE
  176. err = ssb_for_each_bus_call((unsigned long)dev, gige_pci_init_callback);
  177. if (err >= 0)
  178. return err;
  179. #endif
  180. /* This is not a PCI device on any SSB device. */
  181. return -ENODEV;
  182. }
  183. #ifdef CONFIG_SSB_DRIVER_GIGE
  184. static int gige_map_irq_callback(struct ssb_bus *bus, unsigned long data)
  185. {
  186. const struct pci_dev *pdev = (const struct pci_dev *)data;
  187. struct ssb_device *dev;
  188. unsigned int i;
  189. int res;
  190. for (i = 0; i < bus->nr_devices; i++) {
  191. dev = &(bus->devices[i]);
  192. if (dev->id.coreid != SSB_DEV_ETHERNET_GBIT)
  193. continue;
  194. if (!dev->dev ||
  195. !dev->dev->driver ||
  196. !device_is_registered(dev->dev))
  197. continue;
  198. res = ssb_gige_map_irq(dev, pdev);
  199. if (res >= 0)
  200. return res;
  201. }
  202. return -ENODEV;
  203. }
  204. #endif /* CONFIG_SSB_DRIVER_GIGE */
  205. int ssb_pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  206. {
  207. int res;
  208. /* Check if this PCI device is a device on a SSB bus or device
  209. * and return the IRQ number for it. */
  210. res = ssb_pcicore_pcibios_map_irq(dev, slot, pin);
  211. if (res >= 0)
  212. return res;
  213. #ifdef CONFIG_SSB_DRIVER_GIGE
  214. res = ssb_for_each_bus_call((unsigned long)dev, gige_map_irq_callback);
  215. if (res >= 0)
  216. return res;
  217. #endif
  218. /* This is not a PCI device on any SSB device. */
  219. return -ENODEV;
  220. }