driver_chipcommon.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. #ifdef CONFIG_BCMA_DRIVER_MIPS
  118. void bcma_chipco_serial_init(struct bcma_drv_cc *cc)
  119. {
  120. unsigned int irq;
  121. u32 baud_base;
  122. u32 i;
  123. unsigned int ccrev = cc->core->id.rev;
  124. struct bcma_serial_port *ports = cc->serial_ports;
  125. if (ccrev >= 11 && ccrev != 15) {
  126. /* Fixed ALP clock */
  127. baud_base = bcma_pmu_alp_clock(cc);
  128. if (ccrev >= 21) {
  129. /* Turn off UART clock before switching clocksource. */
  130. bcma_cc_write32(cc, BCMA_CC_CORECTL,
  131. bcma_cc_read32(cc, BCMA_CC_CORECTL)
  132. & ~BCMA_CC_CORECTL_UARTCLKEN);
  133. }
  134. /* Set the override bit so we don't divide it */
  135. bcma_cc_write32(cc, BCMA_CC_CORECTL,
  136. bcma_cc_read32(cc, BCMA_CC_CORECTL)
  137. | BCMA_CC_CORECTL_UARTCLK0);
  138. if (ccrev >= 21) {
  139. /* Re-enable the UART clock. */
  140. bcma_cc_write32(cc, BCMA_CC_CORECTL,
  141. bcma_cc_read32(cc, BCMA_CC_CORECTL)
  142. | BCMA_CC_CORECTL_UARTCLKEN);
  143. }
  144. } else {
  145. bcma_err(cc->core->bus, "serial not supported on this device ccrev: 0x%x\n", ccrev);
  146. return;
  147. }
  148. irq = bcma_core_mips_irq(cc->core);
  149. /* Determine the registers of the UARTs */
  150. cc->nr_serial_ports = (cc->capabilities & BCMA_CC_CAP_NRUART);
  151. for (i = 0; i < cc->nr_serial_ports; i++) {
  152. ports[i].regs = cc->core->io_addr + BCMA_CC_UART0_DATA +
  153. (i * 256);
  154. ports[i].irq = irq;
  155. ports[i].baud_base = baud_base;
  156. ports[i].reg_shift = 0;
  157. }
  158. }
  159. #endif /* CONFIG_BCMA_DRIVER_MIPS */