embedded.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. *
  8. * Licensed under the GNU/GPL. See COPYING for details.
  9. */
  10. #include <linux/export.h>
  11. #include <linux/ssb/ssb.h>
  12. #include <linux/ssb/ssb_embedded.h>
  13. #include <linux/ssb/ssb_driver_pci.h>
  14. #include <linux/ssb/ssb_driver_gige.h>
  15. #include <linux/pci.h>
  16. #include "ssb_private.h"
  17. int ssb_watchdog_timer_set(struct ssb_bus *bus, u32 ticks)
  18. {
  19. if (ssb_chipco_available(&bus->chipco)) {
  20. ssb_chipco_watchdog_timer_set(&bus->chipco, ticks);
  21. return 0;
  22. }
  23. if (ssb_extif_available(&bus->extif)) {
  24. ssb_extif_watchdog_timer_set(&bus->extif, ticks);
  25. return 0;
  26. }
  27. return -ENODEV;
  28. }
  29. EXPORT_SYMBOL(ssb_watchdog_timer_set);
  30. u32 ssb_gpio_in(struct ssb_bus *bus, u32 mask)
  31. {
  32. unsigned long flags;
  33. u32 res = 0;
  34. spin_lock_irqsave(&bus->gpio_lock, flags);
  35. if (ssb_chipco_available(&bus->chipco))
  36. res = ssb_chipco_gpio_in(&bus->chipco, mask);
  37. else if (ssb_extif_available(&bus->extif))
  38. res = ssb_extif_gpio_in(&bus->extif, mask);
  39. else
  40. SSB_WARN_ON(1);
  41. spin_unlock_irqrestore(&bus->gpio_lock, flags);
  42. return res;
  43. }
  44. EXPORT_SYMBOL(ssb_gpio_in);
  45. u32 ssb_gpio_out(struct ssb_bus *bus, u32 mask, u32 value)
  46. {
  47. unsigned long flags;
  48. u32 res = 0;
  49. spin_lock_irqsave(&bus->gpio_lock, flags);
  50. if (ssb_chipco_available(&bus->chipco))
  51. res = ssb_chipco_gpio_out(&bus->chipco, mask, value);
  52. else if (ssb_extif_available(&bus->extif))
  53. res = ssb_extif_gpio_out(&bus->extif, mask, value);
  54. else
  55. SSB_WARN_ON(1);
  56. spin_unlock_irqrestore(&bus->gpio_lock, flags);
  57. return res;
  58. }
  59. EXPORT_SYMBOL(ssb_gpio_out);
  60. u32 ssb_gpio_outen(struct ssb_bus *bus, u32 mask, u32 value)
  61. {
  62. unsigned long flags;
  63. u32 res = 0;
  64. spin_lock_irqsave(&bus->gpio_lock, flags);
  65. if (ssb_chipco_available(&bus->chipco))
  66. res = ssb_chipco_gpio_outen(&bus->chipco, mask, value);
  67. else if (ssb_extif_available(&bus->extif))
  68. res = ssb_extif_gpio_outen(&bus->extif, mask, value);
  69. else
  70. SSB_WARN_ON(1);
  71. spin_unlock_irqrestore(&bus->gpio_lock, flags);
  72. return res;
  73. }
  74. EXPORT_SYMBOL(ssb_gpio_outen);
  75. u32 ssb_gpio_control(struct ssb_bus *bus, u32 mask, u32 value)
  76. {
  77. unsigned long flags;
  78. u32 res = 0;
  79. spin_lock_irqsave(&bus->gpio_lock, flags);
  80. if (ssb_chipco_available(&bus->chipco))
  81. res = ssb_chipco_gpio_control(&bus->chipco, mask, value);
  82. spin_unlock_irqrestore(&bus->gpio_lock, flags);
  83. return res;
  84. }
  85. EXPORT_SYMBOL(ssb_gpio_control);
  86. u32 ssb_gpio_intmask(struct ssb_bus *bus, u32 mask, u32 value)
  87. {
  88. unsigned long flags;
  89. u32 res = 0;
  90. spin_lock_irqsave(&bus->gpio_lock, flags);
  91. if (ssb_chipco_available(&bus->chipco))
  92. res = ssb_chipco_gpio_intmask(&bus->chipco, mask, value);
  93. else if (ssb_extif_available(&bus->extif))
  94. res = ssb_extif_gpio_intmask(&bus->extif, mask, value);
  95. else
  96. SSB_WARN_ON(1);
  97. spin_unlock_irqrestore(&bus->gpio_lock, flags);
  98. return res;
  99. }
  100. EXPORT_SYMBOL(ssb_gpio_intmask);
  101. u32 ssb_gpio_polarity(struct ssb_bus *bus, u32 mask, u32 value)
  102. {
  103. unsigned long flags;
  104. u32 res = 0;
  105. spin_lock_irqsave(&bus->gpio_lock, flags);
  106. if (ssb_chipco_available(&bus->chipco))
  107. res = ssb_chipco_gpio_polarity(&bus->chipco, mask, value);
  108. else if (ssb_extif_available(&bus->extif))
  109. res = ssb_extif_gpio_polarity(&bus->extif, mask, value);
  110. else
  111. SSB_WARN_ON(1);
  112. spin_unlock_irqrestore(&bus->gpio_lock, flags);
  113. return res;
  114. }
  115. EXPORT_SYMBOL(ssb_gpio_polarity);
  116. #ifdef CONFIG_SSB_DRIVER_GIGE
  117. static int gige_pci_init_callback(struct ssb_bus *bus, unsigned long data)
  118. {
  119. struct pci_dev *pdev = (struct pci_dev *)data;
  120. struct ssb_device *dev;
  121. unsigned int i;
  122. int res;
  123. for (i = 0; i < bus->nr_devices; i++) {
  124. dev = &(bus->devices[i]);
  125. if (dev->id.coreid != SSB_DEV_ETHERNET_GBIT)
  126. continue;
  127. if (!dev->dev ||
  128. !dev->dev->driver ||
  129. !device_is_registered(dev->dev))
  130. continue;
  131. res = ssb_gige_pcibios_plat_dev_init(dev, pdev);
  132. if (res >= 0)
  133. return res;
  134. }
  135. return -ENODEV;
  136. }
  137. #endif /* CONFIG_SSB_DRIVER_GIGE */
  138. int ssb_pcibios_plat_dev_init(struct pci_dev *dev)
  139. {
  140. int err;
  141. err = ssb_pcicore_plat_dev_init(dev);
  142. if (!err)
  143. return 0;
  144. #ifdef CONFIG_SSB_DRIVER_GIGE
  145. err = ssb_for_each_bus_call((unsigned long)dev, gige_pci_init_callback);
  146. if (err >= 0)
  147. return err;
  148. #endif
  149. /* This is not a PCI device on any SSB device. */
  150. return -ENODEV;
  151. }
  152. #ifdef CONFIG_SSB_DRIVER_GIGE
  153. static int gige_map_irq_callback(struct ssb_bus *bus, unsigned long data)
  154. {
  155. const struct pci_dev *pdev = (const struct pci_dev *)data;
  156. struct ssb_device *dev;
  157. unsigned int i;
  158. int res;
  159. for (i = 0; i < bus->nr_devices; i++) {
  160. dev = &(bus->devices[i]);
  161. if (dev->id.coreid != SSB_DEV_ETHERNET_GBIT)
  162. continue;
  163. if (!dev->dev ||
  164. !dev->dev->driver ||
  165. !device_is_registered(dev->dev))
  166. continue;
  167. res = ssb_gige_map_irq(dev, pdev);
  168. if (res >= 0)
  169. return res;
  170. }
  171. return -ENODEV;
  172. }
  173. #endif /* CONFIG_SSB_DRIVER_GIGE */
  174. int ssb_pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  175. {
  176. int res;
  177. /* Check if this PCI device is a device on a SSB bus or device
  178. * and return the IRQ number for it. */
  179. res = ssb_pcicore_pcibios_map_irq(dev, slot, pin);
  180. if (res >= 0)
  181. return res;
  182. #ifdef CONFIG_SSB_DRIVER_GIGE
  183. res = ssb_for_each_bus_call((unsigned long)dev, gige_map_irq_callback);
  184. if (res >= 0)
  185. return res;
  186. #endif
  187. /* This is not a PCI device on any SSB device. */
  188. return -ENODEV;
  189. }