Prabhu Jayakumar | c4c0122 | 2016-05-03 18:19:18 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | #ifndef _ATHEROS_H |
| 16 | #define _ATHEROS_H |
| 17 | |
| 18 | /* |
| 19 | * Set everything to zero. The corresponding header will |
| 20 | * undef and re-define the appropriate ones |
| 21 | */ |
| 22 | #define is_ar7100() (0) |
| 23 | |
| 24 | #define is_ar7240() (0) |
| 25 | #define is_ar7241() (0) |
| 26 | #define is_ar7242() (0) |
| 27 | |
| 28 | #define is_ar9330() (0) |
| 29 | #define is_ar933x() (0) |
| 30 | #define is_hornet() (0) |
| 31 | |
| 32 | #define is_ar934x() (0) |
| 33 | #define is_wasp() (0) |
| 34 | |
| 35 | #define is_qca955x() (0) |
| 36 | #define is_sco() (0) |
| 37 | |
| 38 | #define is_qca953x() (0) |
| 39 | #define is_hb() (0) |
| 40 | |
| 41 | #define is_qca956x() (0) |
| 42 | |
| 43 | #define ATH_CONSOLE_BAUD 115200 |
| 44 | |
| 45 | #define AR7240_REV_1_2 0xc2 |
| 46 | |
| 47 | #ifdef CONFIG_ATH_EMULATION |
| 48 | #define is_emu() (1) |
| 49 | #else |
| 50 | #define is_emu() (0) |
| 51 | #endif |
| 52 | |
| 53 | #ifdef CONFIG_F1E_PHY |
| 54 | #define is_f1e() 1 |
| 55 | #else |
| 56 | #define is_f1e() 0 |
| 57 | #endif |
| 58 | #ifdef CONFIG_F2E_PHY |
| 59 | #define is_f2e() 1 |
| 60 | #else |
| 61 | #define is_f2e() 0 |
| 62 | #endif |
| 63 | #ifdef CONFIG_ATHRS16_PHY |
| 64 | #define is_s16() 1 |
| 65 | #else |
| 66 | #define is_s16() 0 |
| 67 | #endif |
| 68 | |
| 69 | #ifdef CONFIG_ATHRS17_PHY |
| 70 | #define is_s17() 1 |
| 71 | #else |
| 72 | #define is_s17() 0 |
| 73 | #endif |
| 74 | |
| 75 | #ifdef CONFIG_ATHR_8033_PHY |
| 76 | #define is_ar8033() 1 |
| 77 | #else |
| 78 | #define is_ar8033() 0 |
| 79 | #endif |
| 80 | |
| 81 | #ifdef CONFIG_VIR_PHY |
| 82 | #define is_vir_phy() 1 |
| 83 | #else |
| 84 | #define is_vir_phy() 0 |
| 85 | #endif |
| 86 | |
| 87 | #ifdef CFG_ATHRS27_PHY |
| 88 | #define is_s27() 1 |
| 89 | #else |
| 90 | #define is_s27() 0 |
| 91 | #endif |
| 92 | |
| 93 | #define ath_arch_init_irq() /* nothing */ |
| 94 | |
| 95 | #ifndef __ASSEMBLY__ |
| 96 | |
| 97 | int ath_uart_freq(void); |
| 98 | |
| 99 | typedef unsigned int ath_reg_t; |
| 100 | |
Prabhu Jayakumar | 32be07e | 2017-01-06 18:58:22 +0530 | [diff] [blame] | 101 | #if COMPRESSED_UBOOT |
Prabhu Jayakumar | c4c0122 | 2016-05-03 18:19:18 +0530 | [diff] [blame] | 102 | # define prmsg(...) |
| 103 | #else |
| 104 | # define prmsg printf |
| 105 | #endif |
| 106 | |
| 107 | #endif /* __ASSEMBLY__ */ |
| 108 | |
| 109 | #define ath_reg_rd(_phys) (*(volatile ath_reg_t *)KSEG1ADDR(_phys)) |
| 110 | |
| 111 | #define ath_reg_wr_nf(_phys, _val) \ |
| 112 | ((*(volatile ath_reg_t *)KSEG1ADDR(_phys)) = (_val)) |
| 113 | |
| 114 | #define ath_reg_wr(_phys, _val) do { \ |
| 115 | ath_reg_wr_nf(_phys, _val); \ |
| 116 | ath_reg_rd(_phys); \ |
| 117 | } while(0) |
| 118 | |
| 119 | #define ath_reg_rmw_set(_reg, _mask) do { \ |
| 120 | ath_reg_wr((_reg), (ath_reg_rd((_reg)) | (_mask))); \ |
| 121 | ath_reg_rd((_reg)); \ |
| 122 | } while(0) |
| 123 | |
| 124 | #define ath_reg_rmw_clear(_reg, _mask) do { \ |
| 125 | ath_reg_wr((_reg), (ath_reg_rd((_reg)) & ~(_mask))); \ |
| 126 | ath_reg_rd((_reg)); \ |
| 127 | } while(0) |
| 128 | |
| 129 | #define ath_uart_rd(y) ath_reg_rd((ATH_UART_BASE+y)) |
| 130 | #define ath_uart_wr(x, z) ath_reg_wr((ATH_UART_BASE+x), z) |
| 131 | |
| 132 | #define REG_OFFSET 4 |
| 133 | |
| 134 | #define OFS_RCV_BUFFER (0 * REG_OFFSET) |
| 135 | #define OFS_TRANS_HOLD (0 * REG_OFFSET) |
| 136 | #define OFS_SEND_BUFFER (0 * REG_OFFSET) |
| 137 | #define OFS_INTR_ENABLE (1 * REG_OFFSET) |
| 138 | #define OFS_INTR_ID (2 * REG_OFFSET) |
| 139 | #define OFS_DATA_FORMAT (3 * REG_OFFSET) |
| 140 | #define OFS_LINE_CONTROL (3 * REG_OFFSET) |
| 141 | #define OFS_MODEM_CONTROL (4 * REG_OFFSET) |
| 142 | #define OFS_RS232_OUTPUT (4 * REG_OFFSET) |
| 143 | #define OFS_LINE_STATUS (5 * REG_OFFSET) |
| 144 | #define OFS_MODEM_STATUS (6 * REG_OFFSET) |
| 145 | #define OFS_RS232_INPUT (6 * REG_OFFSET) |
| 146 | #define OFS_SCRATCH_PAD (7 * REG_OFFSET) |
| 147 | |
| 148 | #define OFS_DIVISOR_LSB (0 * REG_OFFSET) |
| 149 | #define OFS_DIVISOR_MSB (1 * REG_OFFSET) |
| 150 | |
| 151 | /* |
| 152 | * PLL Config for different CPU/DDR/AHB frequencies |
| 153 | */ |
| 154 | #define CFG_PLL_720_600_200 0x01 |
| 155 | #define CFG_PLL_720_680_240 0x02 |
| 156 | #define CFG_PLL_720_600_240 0x03 |
| 157 | #define CFG_PLL_680_680_226 0x04 |
| 158 | #define CFG_PLL_720_600_300 0x05 |
| 159 | #define CFG_PLL_400_400_200 0x06 |
| 160 | #define CFG_PLL_560_450_220 0x07 |
| 161 | #define CFG_PLL_550_400_200 0x08 |
| 162 | #define CFG_PLL_550_600_200 0x09 |
| 163 | #define CFG_PLL_600_600_200 0x0a |
| 164 | #define CFG_PLL_750_400_250 0x0b |
| 165 | #define CFG_PLL_800_400_266 0x0c |
| 166 | #define CFG_PLL_750_667_250 0x0d |
| 167 | #define CFG_PLL_800_600_266 0x0e |
| 168 | #define CFG_PLL_800_667_266 0x0f |
| 169 | #define CFG_PLL_810_700_270 0x10 |
| 170 | #define CFG_PLL_810_666_270 0x11 |
| 171 | #define CFG_PLL_775_650_258 0x12 |
| 172 | #define CFG_PLL_650_400_200 0x13 |
| 173 | #define CFG_PLL_650_600_200 0x14 |
| 174 | |
| 175 | #define UBOOT_SIZE (256 * 1024) |
| 176 | #define PLL_FLASH_ADDR (CFG_FLASH_BASE + UBOOT_SIZE) |
| 177 | #define PLL_CONFIG_VAL_F (PLL_FLASH_ADDR + CFG_FLASH_SECTOR_SIZE - 0x20) |
| 178 | #define PLL_MAGIC 0xaabbccdd |
| 179 | #define SRIF_PLL_CONFIG_VAL_F (PLL_CONFIG_VAL_F - 12) |
| 180 | #define SRIF_PLL_MAGIC 0x73726966 /* srif */ |
| 181 | |
| 182 | #include <config.h> |
| 183 | |
| 184 | #if defined(CONFIG_MACH_AR724x) |
| 185 | # include <724x.h> |
| 186 | #elif defined(CONFIG_MACH_AR933x) |
| 187 | # include <933x.h> |
| 188 | #elif defined(CONFIG_MACH_AR934x) |
| 189 | # include <934x.h> |
| 190 | #elif defined(CONFIG_MACH_QCA955x) |
| 191 | # include <955x.h> |
| 192 | #elif defined(CONFIG_MACH_QCA953x) |
| 193 | # include <953x.h> |
| 194 | #elif defined(CONFIG_MACH_QCA956x) |
| 195 | # include <956x.h> |
| 196 | #else |
| 197 | # error "Building U-Boot for unknown device" |
| 198 | #endif |
| 199 | |
| 200 | #ifndef __ASSEMBLY__ |
| 201 | |
| 202 | #define ATH_MEM_SDRAM 1 |
| 203 | #define ATH_MEM_DDR1 2 |
| 204 | #define ATH_MEM_DDR2 3 |
| 205 | /* |
| 206 | * GPIO Access & Control |
| 207 | */ |
| 208 | void ath_gpio_init(void); |
| 209 | void ath_gpio_down(void); |
| 210 | void ath_gpio_up(void); |
| 211 | |
| 212 | void ath_gpio_irq_init(int); |
| 213 | /* |
| 214 | * GPIO Helper Functions |
| 215 | */ |
| 216 | void ath_gpio_enable_slic(void); |
| 217 | |
| 218 | /* enable UART block, takes away GPIO 10 and 9 */ |
| 219 | void ath_gpio_enable_uart(void); |
| 220 | |
| 221 | /* enable STEREO block, takes away GPIO 11,8,7, and 6 */ |
| 222 | void ath_gpio_enable_stereo(void); |
| 223 | |
| 224 | /* allow CS0/CS1 to be controlled via SPI register, takes away GPIO0/GPIO1 */ |
| 225 | void ath_gpio_enable_spi_cs1_cs0(void); |
| 226 | |
| 227 | /* allow GPIO0/GPIO1 to be used as SCL/SDA for software based i2c */ |
| 228 | void ath_gpio_enable_i2c_on_gpio_0_1(void); |
| 229 | |
| 230 | /* |
| 231 | * GPIO General Functions |
| 232 | */ |
| 233 | void ath_gpio_drive_low(unsigned int mask); |
| 234 | void ath_gpio_drive_high(unsigned int mask); |
| 235 | |
| 236 | unsigned int ath_gpio_float_high_test(unsigned int mask); |
| 237 | |
| 238 | /* Functions to access SPI through software. Example: |
| 239 | * |
| 240 | * ath_spi_down(); ---------------------- disable others from accessing SPI bus taking semaphore |
| 241 | * ath_spi_enable_soft_access(); -------- disable HW control of SPI |
| 242 | * |
| 243 | * <board specific chip select routine> |
| 244 | * |
| 245 | * <read/write SPI using using custom routine or general purposeflash routines |
| 246 | * Custom routine may use: |
| 247 | * |
| 248 | * ath_spi_raw_output_u8(unsigned char) |
| 249 | * ath_spi_raw_output_u32(unsigned int) |
| 250 | * ath_spi_raw_input_u32() |
| 251 | * |
| 252 | * General purpose flash routines: |
| 253 | * ath_spi_flash_read_page(unsigned int addr, unsigned char *data, int len); |
| 254 | * ath_spi_flash_write_page(unsigned int addr, unsigned char *data, int len); |
| 255 | * ath_spi_flash_sector_erase(unsigned int addr); |
| 256 | * > |
| 257 | * |
| 258 | * <board specific chip deselect routine> |
| 259 | * |
| 260 | * ath_spi_disable_soft_acess(); ------- enable HW control of SPI bus |
| 261 | * ath_spi_up(); ----------------------- enable others to access SPI bus releasing semaphore |
| 262 | */ |
| 263 | void ath_spi_init(void); |
| 264 | void ath_spi_down(void); |
| 265 | void ath_spi_up(void); |
| 266 | |
| 267 | static inline void |
| 268 | ath_spi_enable_soft_access(void) |
| 269 | { |
| 270 | ath_reg_wr_nf(ATH_SPI_FS, 1); |
| 271 | } |
| 272 | |
| 273 | static inline void |
| 274 | ath_spi_disable_soft_access(void) |
| 275 | { |
| 276 | ath_reg_wr_nf(ATH_SPI_WRITE, ATH_SPI_CS_DIS); |
| 277 | ath_reg_wr_nf(ATH_SPI_FS, 0); |
| 278 | } |
| 279 | |
| 280 | void ath_spi_raw_output_u8(unsigned char val); |
| 281 | void ath_spi_raw_output_u32(unsigned int val); |
| 282 | unsigned int ath_spi_raw_input_u8(void); |
| 283 | unsigned int ath_spi_raw_input_u32(void); |
| 284 | |
| 285 | void ath_spi_flash_read_page(unsigned int addr, unsigned char *data, int len); |
| 286 | void ath_spi_flash_write_page(unsigned int addr, unsigned char *data, int len); |
| 287 | void ath_spi_flash_sector_erase(unsigned int addr); |
| 288 | |
| 289 | /* |
| 290 | * Allow access to cs0-2 when GPIO Function enables cs0-2 through SPI register. |
| 291 | */ |
| 292 | static inline void |
| 293 | ath_spi_enable_cs0(void) |
| 294 | { |
| 295 | unsigned int cs; |
| 296 | ath_spi_down(); |
| 297 | ath_spi_enable_soft_access(); |
| 298 | cs = ath_reg_rd(ATH_SPI_WRITE) & ~ATH_SPI_CS_DIS; |
| 299 | ath_reg_wr_nf(ATH_SPI_WRITE, ATH_SPI_CS_ENABLE_0 | cs); |
| 300 | } |
| 301 | |
| 302 | static inline void |
| 303 | ath_spi_enable_cs1(void) |
| 304 | { |
| 305 | unsigned int cs; |
| 306 | #if defined(CONFIG_MACH_AR934x) || \ |
| 307 | defined(CONFIG_MACH_QCA955x) |
| 308 | ath_spi_down(); |
| 309 | ath_spi_init(); |
| 310 | ath_spi_enable_soft_access(); |
| 311 | cs = ath_reg_rd(ATH_SPI_WRITE) & ATH_SPI_CS_DIS; |
| 312 | ath_reg_wr_nf(ATH_SPI_WRITE, cs | ATH_SPI_CLK_HIGH); |
| 313 | cs = ath_reg_rd(ATH_SPI_WRITE) & ~ATH_SPI_CS_DIS; |
| 314 | ath_reg_wr_nf(ATH_SPI_WRITE, ATH_SPI_CS_ENABLE_1 | cs | ATH_SPI_CLK_HIGH); |
| 315 | ath_reg_wr_nf(ATH_SPI_WRITE, ATH_SPI_CS_ENABLE_1 | cs); |
| 316 | #else |
| 317 | ath_spi_down(); |
| 318 | ath_spi_enable_soft_access(); |
| 319 | cs = ath_reg_rd(ATH_SPI_WRITE) & ~ATH_SPI_CS_DIS; |
| 320 | ath_reg_wr_nf(ATH_SPI_WRITE, ATH_SPI_CS_ENABLE_1 | cs); |
| 321 | #endif |
| 322 | } |
| 323 | |
| 324 | static inline void |
| 325 | ath_spi_disable_cs(void) |
| 326 | { |
| 327 | unsigned int cs = ath_reg_rd(ATH_SPI_WRITE) | ATH_SPI_CS_DIS; |
| 328 | ath_reg_wr_nf(ATH_SPI_WRITE, cs); |
| 329 | ath_spi_disable_soft_access(); |
| 330 | ath_spi_up(); |
| 331 | } |
| 332 | |
| 333 | /* |
| 334 | * Example usage to access BOOT flash |
| 335 | */ |
| 336 | static inline void |
| 337 | ath_spi_flash_cs0_sector_erase(unsigned int addr) |
| 338 | { |
| 339 | ath_spi_enable_cs0(); |
| 340 | ath_spi_flash_sector_erase(addr); |
| 341 | ath_spi_disable_cs(); |
| 342 | } |
| 343 | |
| 344 | static inline void |
| 345 | ath_spi_flash_cs0_write_page(unsigned int addr, unsigned char *data, int len) |
| 346 | { |
| 347 | ath_spi_enable_cs0(); |
| 348 | ath_spi_flash_write_page(addr, data, len); |
| 349 | ath_spi_disable_cs(); |
| 350 | } |
| 351 | |
| 352 | #endif /* __ASSEMBLY__ */ |
| 353 | |
| 354 | |
| 355 | #endif /* _ATHEROS_H */ |