driver_chipcommon.c 4.5 KB

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