embedded.c 5.2 KB

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