ar7.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (C) 2006,2007 Felix Fietkau <[email protected]>
  4. * Copyright (C) 2006,2007 Eugene Konev <[email protected]>
  5. */
  6. #ifndef __AR7_H__
  7. #define __AR7_H__
  8. #include <linux/delay.h>
  9. #include <linux/io.h>
  10. #include <linux/errno.h>
  11. #include <asm/addrspace.h>
  12. #define AR7_SDRAM_BASE 0x14000000
  13. #define AR7_REGS_BASE 0x08610000
  14. #define AR7_REGS_MAC0 (AR7_REGS_BASE + 0x0000)
  15. #define AR7_REGS_GPIO (AR7_REGS_BASE + 0x0900)
  16. /* 0x08610A00 - 0x08610BFF (512 bytes, 128 bytes / clock) */
  17. #define AR7_REGS_POWER (AR7_REGS_BASE + 0x0a00)
  18. #define AR7_REGS_CLOCKS (AR7_REGS_POWER + 0x80)
  19. #define UR8_REGS_CLOCKS (AR7_REGS_POWER + 0x20)
  20. #define AR7_REGS_UART0 (AR7_REGS_BASE + 0x0e00)
  21. #define AR7_REGS_USB (AR7_REGS_BASE + 0x1200)
  22. #define AR7_REGS_RESET (AR7_REGS_BASE + 0x1600)
  23. #define AR7_REGS_PINSEL (AR7_REGS_BASE + 0x160C)
  24. #define AR7_REGS_VLYNQ0 (AR7_REGS_BASE + 0x1800)
  25. #define AR7_REGS_DCL (AR7_REGS_BASE + 0x1a00)
  26. #define AR7_REGS_VLYNQ1 (AR7_REGS_BASE + 0x1c00)
  27. #define AR7_REGS_MDIO (AR7_REGS_BASE + 0x1e00)
  28. #define AR7_REGS_IRQ (AR7_REGS_BASE + 0x2400)
  29. #define AR7_REGS_MAC1 (AR7_REGS_BASE + 0x2800)
  30. #define AR7_REGS_WDT (AR7_REGS_BASE + 0x1f00)
  31. #define UR8_REGS_WDT (AR7_REGS_BASE + 0x0b00)
  32. #define UR8_REGS_UART1 (AR7_REGS_BASE + 0x0f00)
  33. /* Titan registers */
  34. #define TITAN_REGS_ESWITCH_BASE (0x08640000)
  35. #define TITAN_REGS_MAC0 (TITAN_REGS_ESWITCH_BASE)
  36. #define TITAN_REGS_MAC1 (TITAN_REGS_ESWITCH_BASE + 0x0800)
  37. #define TITAN_REGS_MDIO (TITAN_REGS_ESWITCH_BASE + 0x02000)
  38. #define TITAN_REGS_VLYNQ0 (AR7_REGS_BASE + 0x1c00)
  39. #define TITAN_REGS_VLYNQ1 (AR7_REGS_BASE + 0x1300)
  40. #define AR7_RESET_PERIPHERAL 0x0
  41. #define AR7_RESET_SOFTWARE 0x4
  42. #define AR7_RESET_STATUS 0x8
  43. #define AR7_RESET_BIT_CPMAC_LO 17
  44. #define AR7_RESET_BIT_CPMAC_HI 21
  45. #define AR7_RESET_BIT_MDIO 22
  46. #define AR7_RESET_BIT_EPHY 26
  47. #define TITAN_RESET_BIT_EPHY1 28
  48. /* GPIO control registers */
  49. #define AR7_GPIO_INPUT 0x0
  50. #define AR7_GPIO_OUTPUT 0x4
  51. #define AR7_GPIO_DIR 0x8
  52. #define AR7_GPIO_ENABLE 0xc
  53. #define TITAN_GPIO_INPUT_0 0x0
  54. #define TITAN_GPIO_INPUT_1 0x4
  55. #define TITAN_GPIO_OUTPUT_0 0x8
  56. #define TITAN_GPIO_OUTPUT_1 0xc
  57. #define TITAN_GPIO_DIR_0 0x10
  58. #define TITAN_GPIO_DIR_1 0x14
  59. #define TITAN_GPIO_ENBL_0 0x18
  60. #define TITAN_GPIO_ENBL_1 0x1c
  61. #define AR7_CHIP_7100 0x18
  62. #define AR7_CHIP_7200 0x2b
  63. #define AR7_CHIP_7300 0x05
  64. #define AR7_CHIP_TITAN 0x07
  65. #define TITAN_CHIP_1050 0x0f
  66. #define TITAN_CHIP_1055 0x0e
  67. #define TITAN_CHIP_1056 0x0d
  68. #define TITAN_CHIP_1060 0x07
  69. /* Interrupts */
  70. #define AR7_IRQ_UART0 15
  71. #define AR7_IRQ_UART1 16
  72. /* Clocks */
  73. #define AR7_AFE_CLOCK 35328000
  74. #define AR7_REF_CLOCK 25000000
  75. #define AR7_XTAL_CLOCK 24000000
  76. /* DCL */
  77. #define AR7_WDT_HW_ENA 0x10
  78. struct plat_cpmac_data {
  79. int reset_bit;
  80. int power_bit;
  81. u32 phy_mask;
  82. char dev_addr[6];
  83. };
  84. struct plat_dsl_data {
  85. int reset_bit_dsl;
  86. int reset_bit_sar;
  87. };
  88. static inline int ar7_is_titan(void)
  89. {
  90. return (readl((void *)KSEG1ADDR(AR7_REGS_GPIO + 0x24)) & 0xffff) ==
  91. AR7_CHIP_TITAN;
  92. }
  93. static inline u16 ar7_chip_id(void)
  94. {
  95. return ar7_is_titan() ? AR7_CHIP_TITAN : (readl((void *)
  96. KSEG1ADDR(AR7_REGS_GPIO + 0x14)) & 0xffff);
  97. }
  98. static inline u16 titan_chip_id(void)
  99. {
  100. unsigned int val = readl((void *)KSEG1ADDR(AR7_REGS_GPIO +
  101. TITAN_GPIO_INPUT_1));
  102. return ((val >> 12) & 0x0f);
  103. }
  104. static inline u8 ar7_chip_rev(void)
  105. {
  106. return (readl((void *)KSEG1ADDR(AR7_REGS_GPIO + (ar7_is_titan() ? 0x24 :
  107. 0x14))) >> 16) & 0xff;
  108. }
  109. static inline int ar7_has_high_cpmac(void)
  110. {
  111. u16 chip_id = ar7_chip_id();
  112. switch (chip_id) {
  113. case AR7_CHIP_7100:
  114. case AR7_CHIP_7200:
  115. return 0;
  116. case AR7_CHIP_7300:
  117. return 1;
  118. default:
  119. return -ENXIO;
  120. }
  121. }
  122. #define ar7_has_high_vlynq ar7_has_high_cpmac
  123. #define ar7_has_second_uart ar7_has_high_cpmac
  124. static inline void ar7_device_enable(u32 bit)
  125. {
  126. void *reset_reg =
  127. (void *)KSEG1ADDR(AR7_REGS_RESET + AR7_RESET_PERIPHERAL);
  128. writel(readl(reset_reg) | (1 << bit), reset_reg);
  129. msleep(20);
  130. }
  131. static inline void ar7_device_disable(u32 bit)
  132. {
  133. void *reset_reg =
  134. (void *)KSEG1ADDR(AR7_REGS_RESET + AR7_RESET_PERIPHERAL);
  135. writel(readl(reset_reg) & ~(1 << bit), reset_reg);
  136. msleep(20);
  137. }
  138. static inline void ar7_device_reset(u32 bit)
  139. {
  140. ar7_device_disable(bit);
  141. ar7_device_enable(bit);
  142. }
  143. static inline void ar7_device_on(u32 bit)
  144. {
  145. void *power_reg = (void *)KSEG1ADDR(AR7_REGS_POWER);
  146. writel(readl(power_reg) | (1 << bit), power_reg);
  147. msleep(20);
  148. }
  149. static inline void ar7_device_off(u32 bit)
  150. {
  151. void *power_reg = (void *)KSEG1ADDR(AR7_REGS_POWER);
  152. writel(readl(power_reg) & ~(1 << bit), power_reg);
  153. msleep(20);
  154. }
  155. int __init ar7_gpio_init(void);
  156. void __init ar7_init_clocks(void);
  157. /* Board specific GPIO functions */
  158. int ar7_gpio_enable(unsigned gpio);
  159. int ar7_gpio_disable(unsigned gpio);
  160. #endif /* __AR7_H__ */