driver_extif.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Sonics Silicon Backplane
  3. * Broadcom EXTIF core driver
  4. *
  5. * Copyright 2005, Broadcom Corporation
  6. * Copyright 2006, 2007, Michael Buesch <mb@bu3sch.de>
  7. * Copyright 2006, 2007, Felix Fietkau <nbd@openwrt.org>
  8. * Copyright 2007, Aurelien Jarno <aurelien@aurel32.net>
  9. *
  10. * Licensed under the GNU/GPL. See COPYING for details.
  11. */
  12. #include <linux/serial.h>
  13. #include <linux/serial_core.h>
  14. #include <linux/serial_reg.h>
  15. #include "ssb_private.h"
  16. static inline u32 extif_read32(struct ssb_extif *extif, u16 offset)
  17. {
  18. return ssb_read32(extif->dev, offset);
  19. }
  20. static inline void extif_write32(struct ssb_extif *extif, u16 offset, u32 value)
  21. {
  22. ssb_write32(extif->dev, offset, value);
  23. }
  24. static inline u32 extif_write32_masked(struct ssb_extif *extif, u16 offset,
  25. u32 mask, u32 value)
  26. {
  27. value &= mask;
  28. value |= extif_read32(extif, offset) & ~mask;
  29. extif_write32(extif, offset, value);
  30. return value;
  31. }
  32. #ifdef CONFIG_SSB_SERIAL
  33. static bool serial_exists(u8 *regs)
  34. {
  35. u8 save_mcr, msr = 0;
  36. if (regs) {
  37. save_mcr = regs[UART_MCR];
  38. regs[UART_MCR] = (UART_MCR_LOOP | UART_MCR_OUT2 | UART_MCR_RTS);
  39. msr = regs[UART_MSR] & (UART_MSR_DCD | UART_MSR_RI
  40. | UART_MSR_CTS | UART_MSR_DSR);
  41. regs[UART_MCR] = save_mcr;
  42. }
  43. return (msr == (UART_MSR_DCD | UART_MSR_CTS));
  44. }
  45. int ssb_extif_serial_init(struct ssb_extif *extif, struct ssb_serial_port *ports)
  46. {
  47. u32 i, nr_ports = 0;
  48. /* Disable GPIO interrupt initially */
  49. extif_write32(extif, SSB_EXTIF_GPIO_INTPOL, 0);
  50. extif_write32(extif, SSB_EXTIF_GPIO_INTMASK, 0);
  51. for (i = 0; i < 2; i++) {
  52. void __iomem *uart_regs;
  53. uart_regs = ioremap_nocache(SSB_EUART, 16);
  54. if (uart_regs) {
  55. uart_regs += (i * 8);
  56. if (serial_exists(uart_regs) && ports) {
  57. extif_write32(extif, SSB_EXTIF_GPIO_INTMASK, 2);
  58. nr_ports++;
  59. ports[i].regs = uart_regs;
  60. ports[i].irq = 2;
  61. ports[i].baud_base = 13500000;
  62. ports[i].reg_shift = 0;
  63. }
  64. iounmap(uart_regs);
  65. }
  66. }
  67. return nr_ports;
  68. }
  69. #endif /* CONFIG_SSB_SERIAL */
  70. void ssb_extif_timing_init(struct ssb_extif *extif, unsigned long ns)
  71. {
  72. u32 tmp;
  73. /* Initialize extif so we can get to the LEDs and external UART */
  74. extif_write32(extif, SSB_EXTIF_PROG_CFG, SSB_EXTCFG_EN);
  75. /* Set timing for the flash */
  76. tmp = DIV_ROUND_UP(10, ns) << SSB_PROG_WCNT_3_SHIFT;
  77. tmp |= DIV_ROUND_UP(40, ns) << SSB_PROG_WCNT_1_SHIFT;
  78. tmp |= DIV_ROUND_UP(120, ns);
  79. extif_write32(extif, SSB_EXTIF_PROG_WAITCNT, tmp);
  80. /* Set programmable interface timing for external uart */
  81. tmp = DIV_ROUND_UP(10, ns) << SSB_PROG_WCNT_3_SHIFT;
  82. tmp |= DIV_ROUND_UP(20, ns) << SSB_PROG_WCNT_2_SHIFT;
  83. tmp |= DIV_ROUND_UP(100, ns) << SSB_PROG_WCNT_1_SHIFT;
  84. tmp |= DIV_ROUND_UP(120, ns);
  85. extif_write32(extif, SSB_EXTIF_PROG_WAITCNT, tmp);
  86. }
  87. void ssb_extif_get_clockcontrol(struct ssb_extif *extif,
  88. u32 *pll_type, u32 *n, u32 *m)
  89. {
  90. *pll_type = SSB_PLLTYPE_1;
  91. *n = extif_read32(extif, SSB_EXTIF_CLOCK_N);
  92. *m = extif_read32(extif, SSB_EXTIF_CLOCK_SB);
  93. }
  94. void ssb_extif_watchdog_timer_set(struct ssb_extif *extif,
  95. u32 ticks)
  96. {
  97. extif_write32(extif, SSB_EXTIF_WATCHDOG, ticks);
  98. }
  99. u32 ssb_extif_gpio_in(struct ssb_extif *extif, u32 mask)
  100. {
  101. return extif_read32(extif, SSB_EXTIF_GPIO_IN) & mask;
  102. }
  103. u32 ssb_extif_gpio_out(struct ssb_extif *extif, u32 mask, u32 value)
  104. {
  105. return extif_write32_masked(extif, SSB_EXTIF_GPIO_OUT(0),
  106. mask, value);
  107. }
  108. u32 ssb_extif_gpio_outen(struct ssb_extif *extif, u32 mask, u32 value)
  109. {
  110. return extif_write32_masked(extif, SSB_EXTIF_GPIO_OUTEN(0),
  111. mask, value);
  112. }
  113. u32 ssb_extif_gpio_polarity(struct ssb_extif *extif, u32 mask, u32 value)
  114. {
  115. return extif_write32_masked(extif, SSB_EXTIF_GPIO_INTPOL, mask, value);
  116. }
  117. u32 ssb_extif_gpio_intmask(struct ssb_extif *extif, u32 mask, u32 value)
  118. {
  119. return extif_write32_masked(extif, SSB_EXTIF_GPIO_INTMASK, mask, value);
  120. }