ar7.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * Copyright (C) 2006,2007 Felix Fietkau <nbd@openwrt.org>
  3. * Copyright (C) 2006,2007 Eugene Konev <ejka@openwrt.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #ifndef __AR7_H__
  20. #define __AR7_H__
  21. #include <linux/delay.h>
  22. #include <linux/io.h>
  23. #include <linux/errno.h>
  24. #include <asm/addrspace.h>
  25. #define AR7_SDRAM_BASE 0x14000000
  26. #define AR7_REGS_BASE 0x08610000
  27. #define AR7_REGS_MAC0 (AR7_REGS_BASE + 0x0000)
  28. #define AR7_REGS_GPIO (AR7_REGS_BASE + 0x0900)
  29. /* 0x08610A00 - 0x08610BFF (512 bytes, 128 bytes / clock) */
  30. #define AR7_REGS_POWER (AR7_REGS_BASE + 0x0a00)
  31. #define AR7_REGS_CLOCKS (AR7_REGS_POWER + 0x80)
  32. #define UR8_REGS_CLOCKS (AR7_REGS_POWER + 0x20)
  33. #define AR7_REGS_UART0 (AR7_REGS_BASE + 0x0e00)
  34. #define AR7_REGS_USB (AR7_REGS_BASE + 0x1200)
  35. #define AR7_REGS_RESET (AR7_REGS_BASE + 0x1600)
  36. #define AR7_REGS_PINSEL (AR7_REGS_BASE + 0x160C)
  37. #define AR7_REGS_VLYNQ0 (AR7_REGS_BASE + 0x1800)
  38. #define AR7_REGS_DCL (AR7_REGS_BASE + 0x1a00)
  39. #define AR7_REGS_VLYNQ1 (AR7_REGS_BASE + 0x1c00)
  40. #define AR7_REGS_MDIO (AR7_REGS_BASE + 0x1e00)
  41. #define AR7_REGS_IRQ (AR7_REGS_BASE + 0x2400)
  42. #define AR7_REGS_MAC1 (AR7_REGS_BASE + 0x2800)
  43. #define AR7_REGS_WDT (AR7_REGS_BASE + 0x1f00)
  44. #define UR8_REGS_WDT (AR7_REGS_BASE + 0x0b00)
  45. #define UR8_REGS_UART1 (AR7_REGS_BASE + 0x0f00)
  46. /* Titan registers */
  47. #define TITAN_REGS_ESWITCH_BASE (0x08640000)
  48. #define TITAN_REGS_MAC0 (TITAN_REGS_ESWITCH_BASE)
  49. #define TITAN_REGS_MAC1 (TITAN_REGS_ESWITCH_BASE + 0x0800)
  50. #define TITAN_REGS_MDIO (TITAN_REGS_ESWITCH_BASE + 0x02000)
  51. #define TITAN_REGS_VLYNQ0 (AR7_REGS_BASE + 0x1c00)
  52. #define TITAN_REGS_VLYNQ1 (AR7_REGS_BASE + 0x1300)
  53. #define AR7_RESET_PERIPHERAL 0x0
  54. #define AR7_RESET_SOFTWARE 0x4
  55. #define AR7_RESET_STATUS 0x8
  56. #define AR7_RESET_BIT_CPMAC_LO 17
  57. #define AR7_RESET_BIT_CPMAC_HI 21
  58. #define AR7_RESET_BIT_MDIO 22
  59. #define AR7_RESET_BIT_EPHY 26
  60. #define TITAN_RESET_BIT_EPHY1 28
  61. /* GPIO control registers */
  62. #define AR7_GPIO_INPUT 0x0
  63. #define AR7_GPIO_OUTPUT 0x4
  64. #define AR7_GPIO_DIR 0x8
  65. #define AR7_GPIO_ENABLE 0xc
  66. #define TITAN_GPIO_INPUT_0 0x0
  67. #define TITAN_GPIO_INPUT_1 0x4
  68. #define TITAN_GPIO_OUTPUT_0 0x8
  69. #define TITAN_GPIO_OUTPUT_1 0xc
  70. #define TITAN_GPIO_DIR_0 0x10
  71. #define TITAN_GPIO_DIR_1 0x14
  72. #define TITAN_GPIO_ENBL_0 0x18
  73. #define TITAN_GPIO_ENBL_1 0x1c
  74. #define AR7_CHIP_7100 0x18
  75. #define AR7_CHIP_7200 0x2b
  76. #define AR7_CHIP_7300 0x05
  77. #define AR7_CHIP_TITAN 0x07
  78. #define TITAN_CHIP_1050 0x0f
  79. #define TITAN_CHIP_1055 0x0e
  80. #define TITAN_CHIP_1056 0x0d
  81. #define TITAN_CHIP_1060 0x07
  82. /* Interrupts */
  83. #define AR7_IRQ_UART0 15
  84. #define AR7_IRQ_UART1 16
  85. /* Clocks */
  86. #define AR7_AFE_CLOCK 35328000
  87. #define AR7_REF_CLOCK 25000000
  88. #define AR7_XTAL_CLOCK 24000000
  89. /* DCL */
  90. #define AR7_WDT_HW_ENA 0x10
  91. struct plat_cpmac_data {
  92. int reset_bit;
  93. int power_bit;
  94. u32 phy_mask;
  95. char dev_addr[6];
  96. };
  97. struct plat_dsl_data {
  98. int reset_bit_dsl;
  99. int reset_bit_sar;
  100. };
  101. extern int ar7_cpu_clock, ar7_bus_clock, ar7_dsp_clock;
  102. static inline int ar7_is_titan(void)
  103. {
  104. return (readl((void *)KSEG1ADDR(AR7_REGS_GPIO + 0x24)) & 0xffff) ==
  105. AR7_CHIP_TITAN;
  106. }
  107. static inline u16 ar7_chip_id(void)
  108. {
  109. return ar7_is_titan() ? AR7_CHIP_TITAN : (readl((void *)
  110. KSEG1ADDR(AR7_REGS_GPIO + 0x14)) & 0xffff);
  111. }
  112. static inline u16 titan_chip_id(void)
  113. {
  114. unsigned int val = readl((void *)KSEG1ADDR(AR7_REGS_GPIO +
  115. TITAN_GPIO_INPUT_1));
  116. return ((val >> 12) & 0x0f);
  117. }
  118. static inline u8 ar7_chip_rev(void)
  119. {
  120. return (readl((void *)KSEG1ADDR(AR7_REGS_GPIO + (ar7_is_titan() ? 0x24 :
  121. 0x14))) >> 16) & 0xff;
  122. }
  123. struct clk {
  124. unsigned int rate;
  125. };
  126. static inline int ar7_has_high_cpmac(void)
  127. {
  128. u16 chip_id = ar7_chip_id();
  129. switch (chip_id) {
  130. case AR7_CHIP_7100:
  131. case AR7_CHIP_7200:
  132. return 0;
  133. case AR7_CHIP_7300:
  134. return 1;
  135. default:
  136. return -ENXIO;
  137. }
  138. }
  139. #define ar7_has_high_vlynq ar7_has_high_cpmac
  140. #define ar7_has_second_uart ar7_has_high_cpmac
  141. static inline void ar7_device_enable(u32 bit)
  142. {
  143. void *reset_reg =
  144. (void *)KSEG1ADDR(AR7_REGS_RESET + AR7_RESET_PERIPHERAL);
  145. writel(readl(reset_reg) | (1 << bit), reset_reg);
  146. msleep(20);
  147. }
  148. static inline void ar7_device_disable(u32 bit)
  149. {
  150. void *reset_reg =
  151. (void *)KSEG1ADDR(AR7_REGS_RESET + AR7_RESET_PERIPHERAL);
  152. writel(readl(reset_reg) & ~(1 << bit), reset_reg);
  153. msleep(20);
  154. }
  155. static inline void ar7_device_reset(u32 bit)
  156. {
  157. ar7_device_disable(bit);
  158. ar7_device_enable(bit);
  159. }
  160. static inline void ar7_device_on(u32 bit)
  161. {
  162. void *power_reg = (void *)KSEG1ADDR(AR7_REGS_POWER);
  163. writel(readl(power_reg) | (1 << bit), power_reg);
  164. msleep(20);
  165. }
  166. static inline void ar7_device_off(u32 bit)
  167. {
  168. void *power_reg = (void *)KSEG1ADDR(AR7_REGS_POWER);
  169. writel(readl(power_reg) & ~(1 << bit), power_reg);
  170. msleep(20);
  171. }
  172. int __init ar7_gpio_init(void);
  173. void __init ar7_init_clocks(void);
  174. /* Board specific GPIO functions */
  175. int ar7_gpio_enable(unsigned gpio);
  176. int ar7_gpio_disable(unsigned gpio);
  177. #endif /* __AR7_H__ */