embedded.c 5.2 KB

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