driver_chipcommon.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. * Copyright 2012, Hauke Mehrtens <hauke@hauke-m.de>
  8. *
  9. * Licensed under the GNU/GPL. See COPYING for details.
  10. */
  11. #include "bcma_private.h"
  12. #include <linux/export.h>
  13. #include <linux/bcma/bcma.h>
  14. static inline u32 bcma_cc_write32_masked(struct bcma_drv_cc *cc, u16 offset,
  15. u32 mask, u32 value)
  16. {
  17. value &= mask;
  18. value |= bcma_cc_read32(cc, offset) & ~mask;
  19. bcma_cc_write32(cc, offset, value);
  20. return value;
  21. }
  22. static u32 bcma_chipco_alp_clock(struct bcma_drv_cc *cc)
  23. {
  24. if (cc->capabilities & BCMA_CC_CAP_PMU)
  25. return bcma_pmu_alp_clock(cc);
  26. return 20000000;
  27. }
  28. void bcma_core_chipcommon_early_init(struct bcma_drv_cc *cc)
  29. {
  30. if (cc->early_setup_done)
  31. return;
  32. if (cc->core->id.rev >= 11)
  33. cc->status = bcma_cc_read32(cc, BCMA_CC_CHIPSTAT);
  34. cc->capabilities = bcma_cc_read32(cc, BCMA_CC_CAP);
  35. if (cc->core->id.rev >= 35)
  36. cc->capabilities_ext = bcma_cc_read32(cc, BCMA_CC_CAP_EXT);
  37. if (cc->capabilities & BCMA_CC_CAP_PMU)
  38. bcma_pmu_early_init(cc);
  39. cc->early_setup_done = true;
  40. }
  41. void bcma_core_chipcommon_init(struct bcma_drv_cc *cc)
  42. {
  43. u32 leddc_on = 10;
  44. u32 leddc_off = 90;
  45. if (cc->setup_done)
  46. return;
  47. bcma_core_chipcommon_early_init(cc);
  48. if (cc->core->id.rev >= 20) {
  49. bcma_cc_write32(cc, BCMA_CC_GPIOPULLUP, 0);
  50. bcma_cc_write32(cc, BCMA_CC_GPIOPULLDOWN, 0);
  51. }
  52. if (cc->capabilities & BCMA_CC_CAP_PMU)
  53. bcma_pmu_init(cc);
  54. if (cc->capabilities & BCMA_CC_CAP_PCTL)
  55. bcma_err(cc->core->bus, "Power control not implemented!\n");
  56. if (cc->core->id.rev >= 16) {
  57. if (cc->core->bus->sprom.leddc_on_time &&
  58. cc->core->bus->sprom.leddc_off_time) {
  59. leddc_on = cc->core->bus->sprom.leddc_on_time;
  60. leddc_off = cc->core->bus->sprom.leddc_off_time;
  61. }
  62. bcma_cc_write32(cc, BCMA_CC_GPIOTIMER,
  63. ((leddc_on << BCMA_CC_GPIOTIMER_ONTIME_SHIFT) |
  64. (leddc_off << BCMA_CC_GPIOTIMER_OFFTIME_SHIFT)));
  65. }
  66. cc->setup_done = true;
  67. }
  68. /* Set chip watchdog reset timer to fire in 'ticks' backplane cycles */
  69. void bcma_chipco_watchdog_timer_set(struct bcma_drv_cc *cc, u32 ticks)
  70. {
  71. /* instant NMI */
  72. bcma_cc_write32(cc, BCMA_CC_WATCHDOG, ticks);
  73. }
  74. void bcma_chipco_irq_mask(struct bcma_drv_cc *cc, u32 mask, u32 value)
  75. {
  76. bcma_cc_write32_masked(cc, BCMA_CC_IRQMASK, mask, value);
  77. }
  78. u32 bcma_chipco_irq_status(struct bcma_drv_cc *cc, u32 mask)
  79. {
  80. return bcma_cc_read32(cc, BCMA_CC_IRQSTAT) & mask;
  81. }
  82. u32 bcma_chipco_gpio_in(struct bcma_drv_cc *cc, u32 mask)
  83. {
  84. return bcma_cc_read32(cc, BCMA_CC_GPIOIN) & mask;
  85. }
  86. u32 bcma_chipco_gpio_out(struct bcma_drv_cc *cc, u32 mask, u32 value)
  87. {
  88. return bcma_cc_write32_masked(cc, BCMA_CC_GPIOOUT, mask, value);
  89. }
  90. u32 bcma_chipco_gpio_outen(struct bcma_drv_cc *cc, u32 mask, u32 value)
  91. {
  92. return bcma_cc_write32_masked(cc, BCMA_CC_GPIOOUTEN, mask, value);
  93. }
  94. u32 bcma_chipco_gpio_control(struct bcma_drv_cc *cc, u32 mask, u32 value)
  95. {
  96. return bcma_cc_write32_masked(cc, BCMA_CC_GPIOCTL, mask, value);
  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. return bcma_cc_write32_masked(cc, BCMA_CC_GPIOIRQ, mask, value);
  102. }
  103. u32 bcma_chipco_gpio_polarity(struct bcma_drv_cc *cc, u32 mask, u32 value)
  104. {
  105. return bcma_cc_write32_masked(cc, BCMA_CC_GPIOPOL, mask, value);
  106. }
  107. #ifdef CONFIG_BCMA_DRIVER_MIPS
  108. void bcma_chipco_serial_init(struct bcma_drv_cc *cc)
  109. {
  110. unsigned int irq;
  111. u32 baud_base;
  112. u32 i;
  113. unsigned int ccrev = cc->core->id.rev;
  114. struct bcma_serial_port *ports = cc->serial_ports;
  115. if (ccrev >= 11 && ccrev != 15) {
  116. baud_base = bcma_chipco_alp_clock(cc);
  117. if (ccrev >= 21) {
  118. /* Turn off UART clock before switching clocksource. */
  119. bcma_cc_write32(cc, BCMA_CC_CORECTL,
  120. bcma_cc_read32(cc, BCMA_CC_CORECTL)
  121. & ~BCMA_CC_CORECTL_UARTCLKEN);
  122. }
  123. /* Set the override bit so we don't divide it */
  124. bcma_cc_write32(cc, BCMA_CC_CORECTL,
  125. bcma_cc_read32(cc, BCMA_CC_CORECTL)
  126. | BCMA_CC_CORECTL_UARTCLK0);
  127. if (ccrev >= 21) {
  128. /* Re-enable the UART clock. */
  129. bcma_cc_write32(cc, BCMA_CC_CORECTL,
  130. bcma_cc_read32(cc, BCMA_CC_CORECTL)
  131. | BCMA_CC_CORECTL_UARTCLKEN);
  132. }
  133. } else {
  134. bcma_err(cc->core->bus, "serial not supported on this device ccrev: 0x%x\n", ccrev);
  135. return;
  136. }
  137. irq = bcma_core_mips_irq(cc->core);
  138. /* Determine the registers of the UARTs */
  139. cc->nr_serial_ports = (cc->capabilities & BCMA_CC_CAP_NRUART);
  140. for (i = 0; i < cc->nr_serial_ports; i++) {
  141. ports[i].regs = cc->core->io_addr + BCMA_CC_UART0_DATA +
  142. (i * 256);
  143. ports[i].irq = irq;
  144. ports[i].baud_base = baud_base;
  145. ports[i].reg_shift = 0;
  146. }
  147. }
  148. #endif /* CONFIG_BCMA_DRIVER_MIPS */