driver_chipcommon.c 4.2 KB

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