driver_extif.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 void 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. }
  31. #ifdef CONFIG_SSB_SERIAL
  32. static bool serial_exists(u8 *regs)
  33. {
  34. u8 save_mcr, msr = 0;
  35. if (regs) {
  36. save_mcr = regs[UART_MCR];
  37. regs[UART_MCR] = (UART_MCR_LOOP | UART_MCR_OUT2 | UART_MCR_RTS);
  38. msr = regs[UART_MSR] & (UART_MSR_DCD | UART_MSR_RI
  39. | UART_MSR_CTS | UART_MSR_DSR);
  40. regs[UART_MCR] = save_mcr;
  41. }
  42. return (msr == (UART_MSR_DCD | UART_MSR_CTS));
  43. }
  44. int ssb_extif_serial_init(struct ssb_extif *extif, struct ssb_serial_port *ports)
  45. {
  46. u32 i, nr_ports = 0;
  47. /* Disable GPIO interrupt initially */
  48. extif_write32(extif, SSB_EXTIF_GPIO_INTPOL, 0);
  49. extif_write32(extif, SSB_EXTIF_GPIO_INTMASK, 0);
  50. for (i = 0; i < 2; i++) {
  51. void __iomem *uart_regs;
  52. uart_regs = ioremap_nocache(SSB_EUART, 16);
  53. if (uart_regs) {
  54. uart_regs += (i * 8);
  55. if (serial_exists(uart_regs) && ports) {
  56. extif_write32(extif, SSB_EXTIF_GPIO_INTMASK, 2);
  57. nr_ports++;
  58. ports[i].regs = uart_regs;
  59. ports[i].irq = 2;
  60. ports[i].baud_base = 13500000;
  61. ports[i].reg_shift = 0;
  62. }
  63. iounmap(uart_regs);
  64. }
  65. }
  66. return nr_ports;
  67. }
  68. #endif /* CONFIG_SSB_SERIAL */
  69. void ssb_extif_timing_init(struct ssb_extif *extif, unsigned long ns)
  70. {
  71. u32 tmp;
  72. /* Initialize extif so we can get to the LEDs and external UART */
  73. extif_write32(extif, SSB_EXTIF_PROG_CFG, SSB_EXTCFG_EN);
  74. /* Set timing for the flash */
  75. tmp = DIV_ROUND_UP(10, ns) << SSB_PROG_WCNT_3_SHIFT;
  76. tmp |= DIV_ROUND_UP(40, ns) << SSB_PROG_WCNT_1_SHIFT;
  77. tmp |= DIV_ROUND_UP(120, ns);
  78. extif_write32(extif, SSB_EXTIF_PROG_WAITCNT, tmp);
  79. /* Set programmable interface timing for external uart */
  80. tmp = DIV_ROUND_UP(10, ns) << SSB_PROG_WCNT_3_SHIFT;
  81. tmp |= DIV_ROUND_UP(20, ns) << SSB_PROG_WCNT_2_SHIFT;
  82. tmp |= DIV_ROUND_UP(100, ns) << SSB_PROG_WCNT_1_SHIFT;
  83. tmp |= DIV_ROUND_UP(120, ns);
  84. extif_write32(extif, SSB_EXTIF_PROG_WAITCNT, tmp);
  85. }
  86. void ssb_extif_get_clockcontrol(struct ssb_extif *extif,
  87. u32 *pll_type, u32 *n, u32 *m)
  88. {
  89. *pll_type = SSB_PLLTYPE_1;
  90. *n = extif_read32(extif, SSB_EXTIF_CLOCK_N);
  91. *m = extif_read32(extif, SSB_EXTIF_CLOCK_SB);
  92. }
  93. u32 ssb_extif_gpio_in(struct ssb_extif *extif, u32 mask)
  94. {
  95. return extif_read32(extif, SSB_EXTIF_GPIO_IN) & mask;
  96. }
  97. void ssb_extif_gpio_out(struct ssb_extif *extif, u32 mask, u32 value)
  98. {
  99. return extif_write32_masked(extif, SSB_EXTIF_GPIO_OUT(0),
  100. mask, value);
  101. }
  102. void ssb_extif_gpio_outen(struct ssb_extif *extif, u32 mask, u32 value)
  103. {
  104. return extif_write32_masked(extif, SSB_EXTIF_GPIO_OUTEN(0),
  105. mask, value);
  106. }