driver_chipcommon.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. * Broadcom specific AMBA
  3. * ChipCommon core driver
  4. *
  5. * Copyright 2005, Broadcom Corporation
  6. * Copyright 2006, 2007, Michael Buesch <m@bues.ch>
  7. *
  8. * Licensed under the GNU/GPL. See COPYING for details.
  9. */
  10. #include "bcma_private.h"
  11. #include <linux/export.h>
  12. #include <linux/bcma/bcma.h>
  13. static inline u32 bcma_cc_write32_masked(struct bcma_drv_cc *cc, u16 offset,
  14. u32 mask, u32 value)
  15. {
  16. value &= mask;
  17. value |= bcma_cc_read32(cc, offset) & ~mask;
  18. bcma_cc_write32(cc, offset, value);
  19. return value;
  20. }
  21. void bcma_core_chipcommon_init(struct bcma_drv_cc *cc)
  22. {
  23. u32 leddc_on = 10;
  24. u32 leddc_off = 90;
  25. if (cc->setup_done)
  26. return;
  27. spin_lock_init(&cc->gpio_lock);
  28. if (cc->core->id.rev >= 11)
  29. cc->status = bcma_cc_read32(cc, BCMA_CC_CHIPSTAT);
  30. cc->capabilities = bcma_cc_read32(cc, BCMA_CC_CAP);
  31. if (cc->core->id.rev >= 35)
  32. cc->capabilities_ext = bcma_cc_read32(cc, BCMA_CC_CAP_EXT);
  33. if (cc->core->id.rev >= 20) {
  34. bcma_cc_write32(cc, BCMA_CC_GPIOPULLUP, 0);
  35. bcma_cc_write32(cc, BCMA_CC_GPIOPULLDOWN, 0);
  36. }
  37. if (cc->capabilities & BCMA_CC_CAP_PMU)
  38. bcma_pmu_init(cc);
  39. if (cc->capabilities & BCMA_CC_CAP_PCTL)
  40. bcma_err(cc->core->bus, "Power control not implemented!\n");
  41. if (cc->core->id.rev >= 16) {
  42. if (cc->core->bus->sprom.leddc_on_time &&
  43. cc->core->bus->sprom.leddc_off_time) {
  44. leddc_on = cc->core->bus->sprom.leddc_on_time;
  45. leddc_off = cc->core->bus->sprom.leddc_off_time;
  46. }
  47. bcma_cc_write32(cc, BCMA_CC_GPIOTIMER,
  48. ((leddc_on << BCMA_CC_GPIOTIMER_ONTIME_SHIFT) |
  49. (leddc_off << BCMA_CC_GPIOTIMER_OFFTIME_SHIFT)));
  50. }
  51. cc->setup_done = true;
  52. }
  53. /* Set chip watchdog reset timer to fire in 'ticks' backplane cycles */
  54. void bcma_chipco_watchdog_timer_set(struct bcma_drv_cc *cc, u32 ticks)
  55. {
  56. /* instant NMI */
  57. bcma_cc_write32(cc, BCMA_CC_WATCHDOG, ticks);
  58. }
  59. void bcma_chipco_irq_mask(struct bcma_drv_cc *cc, u32 mask, u32 value)
  60. {
  61. bcma_cc_write32_masked(cc, BCMA_CC_IRQMASK, mask, value);
  62. }
  63. u32 bcma_chipco_irq_status(struct bcma_drv_cc *cc, u32 mask)
  64. {
  65. return bcma_cc_read32(cc, BCMA_CC_IRQSTAT) & mask;
  66. }
  67. u32 bcma_chipco_gpio_in(struct bcma_drv_cc *cc, u32 mask)
  68. {
  69. return bcma_cc_read32(cc, BCMA_CC_GPIOIN) & mask;
  70. }
  71. u32 bcma_chipco_gpio_out(struct bcma_drv_cc *cc, u32 mask, u32 value)
  72. {
  73. unsigned long flags;
  74. u32 res;
  75. spin_lock_irqsave(&cc->gpio_lock, flags);
  76. res = bcma_cc_write32_masked(cc, BCMA_CC_GPIOOUT, mask, value);
  77. spin_unlock_irqrestore(&cc->gpio_lock, flags);
  78. return res;
  79. }
  80. u32 bcma_chipco_gpio_outen(struct bcma_drv_cc *cc, u32 mask, u32 value)
  81. {
  82. unsigned long flags;
  83. u32 res;
  84. spin_lock_irqsave(&cc->gpio_lock, flags);
  85. res = bcma_cc_write32_masked(cc, BCMA_CC_GPIOOUTEN, mask, value);
  86. spin_unlock_irqrestore(&cc->gpio_lock, flags);
  87. return res;
  88. }
  89. u32 bcma_chipco_gpio_control(struct bcma_drv_cc *cc, u32 mask, u32 value)
  90. {
  91. unsigned long flags;
  92. u32 res;
  93. spin_lock_irqsave(&cc->gpio_lock, flags);
  94. res = bcma_cc_write32_masked(cc, BCMA_CC_GPIOCTL, mask, value);
  95. spin_unlock_irqrestore(&cc->gpio_lock, flags);
  96. return res;
  97. }
  98. EXPORT_SYMBOL_GPL(bcma_chipco_gpio_control);
  99. u32 bcma_chipco_gpio_intmask(struct bcma_drv_cc *cc, u32 mask, u32 value)
  100. {
  101. unsigned long flags;
  102. u32 res;
  103. spin_lock_irqsave(&cc->gpio_lock, flags);
  104. res = bcma_cc_write32_masked(cc, BCMA_CC_GPIOIRQ, mask, value);
  105. spin_unlock_irqrestore(&cc->gpio_lock, flags);
  106. return res;
  107. }
  108. u32 bcma_chipco_gpio_polarity(struct bcma_drv_cc *cc, u32 mask, u32 value)
  109. {
  110. unsigned long flags;
  111. u32 res;
  112. spin_lock_irqsave(&cc->gpio_lock, flags);
  113. res = bcma_cc_write32_masked(cc, BCMA_CC_GPIOPOL, mask, value);
  114. spin_unlock_irqrestore(&cc->gpio_lock, flags);
  115. return res;
  116. }
  117. u32 bcma_chipco_gpio_pullup(struct bcma_drv_cc *cc, u32 mask, u32 value)
  118. {
  119. unsigned long flags;
  120. u32 res;
  121. if (cc->core->id.rev < 20)
  122. return 0;
  123. spin_lock_irqsave(&cc->gpio_lock, flags);
  124. res = bcma_cc_write32_masked(cc, BCMA_CC_GPIOPULLUP, mask, value);
  125. spin_unlock_irqrestore(&cc->gpio_lock, flags);
  126. return res;
  127. }
  128. u32 bcma_chipco_gpio_pulldown(struct bcma_drv_cc *cc, u32 mask, u32 value)
  129. {
  130. unsigned long flags;
  131. u32 res;
  132. if (cc->core->id.rev < 20)
  133. return 0;
  134. spin_lock_irqsave(&cc->gpio_lock, flags);
  135. res = bcma_cc_write32_masked(cc, BCMA_CC_GPIOPULLDOWN, mask, value);
  136. spin_unlock_irqrestore(&cc->gpio_lock, flags);
  137. return res;
  138. }
  139. #ifdef CONFIG_BCMA_DRIVER_MIPS
  140. void bcma_chipco_serial_init(struct bcma_drv_cc *cc)
  141. {
  142. unsigned int irq;
  143. u32 baud_base;
  144. u32 i;
  145. unsigned int ccrev = cc->core->id.rev;
  146. struct bcma_serial_port *ports = cc->serial_ports;
  147. if (ccrev >= 11 && ccrev != 15) {
  148. /* Fixed ALP clock */
  149. baud_base = bcma_pmu_alp_clock(cc);
  150. if (ccrev >= 21) {
  151. /* Turn off UART clock before switching clocksource. */
  152. bcma_cc_write32(cc, BCMA_CC_CORECTL,
  153. bcma_cc_read32(cc, BCMA_CC_CORECTL)
  154. & ~BCMA_CC_CORECTL_UARTCLKEN);
  155. }
  156. /* Set the override bit so we don't divide it */
  157. bcma_cc_write32(cc, BCMA_CC_CORECTL,
  158. bcma_cc_read32(cc, BCMA_CC_CORECTL)
  159. | BCMA_CC_CORECTL_UARTCLK0);
  160. if (ccrev >= 21) {
  161. /* Re-enable the UART clock. */
  162. bcma_cc_write32(cc, BCMA_CC_CORECTL,
  163. bcma_cc_read32(cc, BCMA_CC_CORECTL)
  164. | BCMA_CC_CORECTL_UARTCLKEN);
  165. }
  166. } else {
  167. bcma_err(cc->core->bus, "serial not supported on this device ccrev: 0x%x\n", ccrev);
  168. return;
  169. }
  170. irq = bcma_core_mips_irq(cc->core);
  171. /* Determine the registers of the UARTs */
  172. cc->nr_serial_ports = (cc->capabilities & BCMA_CC_CAP_NRUART);
  173. for (i = 0; i < cc->nr_serial_ports; i++) {
  174. ports[i].regs = cc->core->io_addr + BCMA_CC_UART0_DATA +
  175. (i * 256);
  176. ports[i].irq = irq;
  177. ports[i].baud_base = baud_base;
  178. ports[i].reg_shift = 0;
  179. }
  180. }
  181. #endif /* CONFIG_BCMA_DRIVER_MIPS */