Norman James | 6a58a27 | 2015-10-07 14:34:16 -0500 | [diff] [blame] | 1 | #ifndef __IO_H
|
| 2 | #define __IO_H
|
| 3 |
|
| 4 | #include <assert.h>
|
| 5 | #include <stdint.h>
|
| 6 | #include <stdbool.h>
|
| 7 |
|
| 8 | #include <libflash/libflash.h>
|
| 9 |
|
| 10 | /* AST AHB register base */
|
| 11 | #define AHB_REGS_BASE 0x1E600000
|
| 12 | #define AHB_REGS_SIZE 0x00200000
|
| 13 |
|
| 14 | /* AST GPIO control regs */
|
| 15 | #define GPIO_CTRL_BASE 0x1E780000
|
| 16 | #define GPIO_CTRL_SIZE 0x1000
|
| 17 |
|
| 18 | /* AST AHB mapping of PNOR */
|
| 19 | #define PNOR_FLASH_BASE 0x30000000
|
| 20 | #define PNOR_FLASH_SIZE 0x04000000
|
| 21 |
|
| 22 | /* AST AHB mapping of BMC flash */
|
| 23 | #define BMC_FLASH_BASE 0x20000000
|
| 24 | #define BMC_FLASH_SIZE 0x04000000
|
| 25 |
|
| 26 | /* Address of flash mapping on LPC FW space */
|
| 27 | #define LPC_FLASH_BASE 0x0e000000
|
| 28 | #define LPC_CTRL_BASE 0x1e789000
|
| 29 |
|
| 30 | extern void open_devs(bool use_lpc, bool bmc_flash);
|
| 31 | extern bool set_wrprotect(bool protect);
|
| 32 |
|
| 33 | #ifdef __powerpc__
|
| 34 |
|
| 35 | extern void close_devs(void);
|
| 36 |
|
| 37 | /* AST access functions */
|
| 38 | extern uint32_t (*ast_ahb_readl)(uint32_t offset);
|
| 39 | extern void (*ast_ahb_writel)(uint32_t val, uint32_t offset);
|
| 40 | extern int (*ast_copy_to_ahb)(uint32_t reg, const void *src, uint32_t len);
|
| 41 | extern int (*ast_copy_from_ahb)(void *dst, uint32_t reg, uint32_t len);
|
| 42 |
|
| 43 | /* SFC LPC access functions (big endian) */
|
| 44 | extern int lpc_fw_write32(uint32_t val, uint32_t addr);
|
| 45 | extern int lpc_fw_read32(uint32_t *val, uint32_t addr);
|
| 46 |
|
| 47 | extern void check_platform(bool *has_sfc, bool *has_ast);
|
| 48 |
|
| 49 | #else
|
| 50 |
|
| 51 | static inline void close_devs(void) { }
|
| 52 |
|
| 53 | static inline uint8_t readb(void *addr)
|
| 54 | {
|
| 55 | asm volatile("" : : : "memory");
|
| 56 | return *(volatile uint8_t *)addr;
|
| 57 | }
|
| 58 |
|
| 59 | static inline uint16_t readw(void *addr)
|
| 60 | {
|
| 61 | asm volatile("" : : : "memory");
|
| 62 | return *(volatile uint16_t *)addr;
|
| 63 | }
|
| 64 |
|
| 65 | static inline uint32_t readl(void *addr)
|
| 66 | {
|
| 67 | asm volatile("" : : : "memory");
|
| 68 | return *(volatile uint32_t *)addr;
|
| 69 | }
|
| 70 |
|
| 71 | static inline void writeb(uint8_t val, void *addr)
|
| 72 | {
|
| 73 | asm volatile("" : : : "memory");
|
| 74 | *(volatile uint8_t *)addr = val;
|
| 75 | }
|
| 76 |
|
| 77 | static inline void writew(uint16_t val, void *addr)
|
| 78 | {
|
| 79 | asm volatile("" : : : "memory");
|
| 80 | *(volatile uint16_t *)addr = val;
|
| 81 | }
|
| 82 |
|
| 83 | static inline void writel(uint32_t val, void *addr)
|
| 84 | {
|
| 85 | asm volatile("" : : : "memory");
|
| 86 | *(volatile uint32_t *)addr = val;
|
| 87 | }
|
| 88 |
|
| 89 | /*
|
| 90 | * AHB register and flash access
|
| 91 | */
|
| 92 |
|
| 93 | extern void *ahb_reg_map;
|
| 94 |
|
| 95 | static inline uint32_t ast_ahb_readl(uint32_t offset)
|
| 96 | {
|
| 97 | assert(((offset ^ AHB_REGS_BASE) & ~(AHB_REGS_SIZE - 1)) == 0);
|
| 98 |
|
| 99 | return readl(ahb_reg_map + (offset - AHB_REGS_BASE));
|
| 100 | }
|
| 101 |
|
| 102 | static inline void ast_ahb_writel(uint32_t val, uint32_t offset)
|
| 103 | {
|
| 104 | assert(((offset ^ AHB_REGS_BASE) & ~(AHB_REGS_SIZE - 1)) == 0);
|
| 105 |
|
| 106 | writel(val, ahb_reg_map + (offset - AHB_REGS_BASE));
|
| 107 | }
|
| 108 |
|
| 109 | extern int ast_copy_to_ahb(uint32_t reg, const void *src, uint32_t len);
|
| 110 | extern int ast_copy_from_ahb(void *dst, uint32_t reg, uint32_t len);
|
| 111 |
|
| 112 | static inline void check_platform(bool *has_sfc, bool *has_ast)
|
| 113 | {
|
| 114 | *has_sfc = false;
|
| 115 | *has_ast = true;
|
| 116 | }
|
| 117 |
|
| 118 | #endif
|
| 119 |
|
| 120 | #endif /* __IO_H */
|
| 121 |
|