Teemu Paasikivi | 521a5b2 | 2010-02-18 13:25:54 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of wl1271 |
| 3 | * |
| 4 | * Copyright (C) 1998-2009 Texas Instruments. All rights reserved. |
| 5 | * Copyright (C) 2008-2010 Nokia Corporation |
| 6 | * |
| 7 | * Contact: Luciano Coelho <luciano.coelho@nokia.com> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License |
| 11 | * version 2 as published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 21 | * 02110-1301 USA |
| 22 | * |
| 23 | */ |
| 24 | |
Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 25 | #ifndef __IO_H__ |
| 26 | #define __IO_H__ |
Teemu Paasikivi | 521a5b2 | 2010-02-18 13:25:54 +0200 | [diff] [blame] | 27 | |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 28 | #include <linux/irqreturn.h> |
Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 29 | #include "reg.h" |
Teemu Paasikivi | 760d969 | 2010-02-22 08:38:25 +0200 | [diff] [blame] | 30 | |
| 31 | #define HW_ACCESS_MEMORY_MAX_RANGE 0x1FFC0 |
| 32 | |
| 33 | #define HW_PARTITION_REGISTERS_ADDR 0x1FFC0 |
| 34 | #define HW_PART0_SIZE_ADDR (HW_PARTITION_REGISTERS_ADDR) |
| 35 | #define HW_PART0_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 4) |
| 36 | #define HW_PART1_SIZE_ADDR (HW_PARTITION_REGISTERS_ADDR + 8) |
| 37 | #define HW_PART1_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 12) |
| 38 | #define HW_PART2_SIZE_ADDR (HW_PARTITION_REGISTERS_ADDR + 16) |
| 39 | #define HW_PART2_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 20) |
| 40 | #define HW_PART3_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 24) |
| 41 | |
| 42 | #define HW_ACCESS_REGISTER_SIZE 4 |
| 43 | |
| 44 | #define HW_ACCESS_PRAM_MAX_RANGE 0x3c000 |
| 45 | |
Luciano Coelho | 0becb14 | 2012-01-12 14:45:34 +0200 | [diff] [blame] | 46 | extern struct wl1271_partition_set wl12xx_part_table[PART_TABLE_LEN]; |
| 47 | |
Teemu Paasikivi | 521a5b2 | 2010-02-18 13:25:54 +0200 | [diff] [blame] | 48 | struct wl1271; |
| 49 | |
Teemu Paasikivi | 54f7e50 | 2010-02-22 08:38:22 +0200 | [diff] [blame] | 50 | void wl1271_disable_interrupts(struct wl1271 *wl); |
| 51 | void wl1271_enable_interrupts(struct wl1271 *wl); |
| 52 | |
Teemu Paasikivi | 9b28072 | 2010-02-18 13:25:56 +0200 | [diff] [blame] | 53 | void wl1271_io_reset(struct wl1271 *wl); |
| 54 | void wl1271_io_init(struct wl1271 *wl); |
Teemu Paasikivi | 521a5b2 | 2010-02-18 13:25:54 +0200 | [diff] [blame] | 55 | |
| 56 | /* Raw target IO, address is not translated */ |
Teemu Paasikivi | b42f91b | 2010-02-22 08:38:24 +0200 | [diff] [blame] | 57 | static inline void wl1271_raw_write(struct wl1271 *wl, int addr, void *buf, |
| 58 | size_t len, bool fixed) |
| 59 | { |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 60 | wl->if_ops->write(wl->dev, addr, buf, len, fixed); |
Teemu Paasikivi | b42f91b | 2010-02-22 08:38:24 +0200 | [diff] [blame] | 61 | } |
Teemu Paasikivi | 521a5b2 | 2010-02-18 13:25:54 +0200 | [diff] [blame] | 62 | |
Teemu Paasikivi | b42f91b | 2010-02-22 08:38:24 +0200 | [diff] [blame] | 63 | static inline void wl1271_raw_read(struct wl1271 *wl, int addr, void *buf, |
| 64 | size_t len, bool fixed) |
| 65 | { |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 66 | wl->if_ops->read(wl->dev, addr, buf, len, fixed); |
Teemu Paasikivi | b42f91b | 2010-02-22 08:38:24 +0200 | [diff] [blame] | 67 | } |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 68 | |
| 69 | static inline u32 wl1271_raw_read32(struct wl1271 *wl, int addr) |
| 70 | { |
| 71 | wl1271_raw_read(wl, addr, &wl->buffer_32, |
| 72 | sizeof(wl->buffer_32), false); |
| 73 | |
Juuso Oikarinen | 554d720 | 2010-05-07 11:38:59 +0300 | [diff] [blame] | 74 | return le32_to_cpu(wl->buffer_32); |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | static inline void wl1271_raw_write32(struct wl1271 *wl, int addr, u32 val) |
| 78 | { |
Juuso Oikarinen | 554d720 | 2010-05-07 11:38:59 +0300 | [diff] [blame] | 79 | wl->buffer_32 = cpu_to_le32(val); |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 80 | wl1271_raw_write(wl, addr, &wl->buffer_32, |
| 81 | sizeof(wl->buffer_32), false); |
| 82 | } |
Teemu Paasikivi | 2d5e82b | 2010-02-22 08:38:21 +0200 | [diff] [blame] | 83 | |
Teemu Paasikivi | b42f91b | 2010-02-22 08:38:24 +0200 | [diff] [blame] | 84 | /* Translated target IO */ |
| 85 | static inline int wl1271_translate_addr(struct wl1271 *wl, int addr) |
| 86 | { |
| 87 | /* |
| 88 | * To translate, first check to which window of addresses the |
| 89 | * particular address belongs. Then subtract the starting address |
| 90 | * of that window from the address. Then, add offset of the |
| 91 | * translated region. |
| 92 | * |
| 93 | * The translated regions occur next to each other in physical device |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 94 | * memory, so just add the sizes of the preceding address regions to |
Teemu Paasikivi | b42f91b | 2010-02-22 08:38:24 +0200 | [diff] [blame] | 95 | * get the offset to the new region. |
| 96 | * |
| 97 | * Currently, only the two first regions are addressed, and the |
| 98 | * assumption is that all addresses will fall into either of those |
| 99 | * two. |
| 100 | */ |
| 101 | if ((addr >= wl->part.reg.start) && |
| 102 | (addr < wl->part.reg.start + wl->part.reg.size)) |
| 103 | return addr - wl->part.reg.start + wl->part.mem.size; |
| 104 | else |
| 105 | return addr - wl->part.mem.start; |
| 106 | } |
| 107 | |
| 108 | static inline void wl1271_read(struct wl1271 *wl, int addr, void *buf, |
| 109 | size_t len, bool fixed) |
| 110 | { |
| 111 | int physical; |
| 112 | |
| 113 | physical = wl1271_translate_addr(wl, addr); |
| 114 | |
| 115 | wl1271_raw_read(wl, physical, buf, len, fixed); |
| 116 | } |
| 117 | |
| 118 | static inline void wl1271_write(struct wl1271 *wl, int addr, void *buf, |
| 119 | size_t len, bool fixed) |
| 120 | { |
| 121 | int physical; |
| 122 | |
| 123 | physical = wl1271_translate_addr(wl, addr); |
| 124 | |
| 125 | wl1271_raw_write(wl, physical, buf, len, fixed); |
| 126 | } |
| 127 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 128 | static inline void wl1271_read_hwaddr(struct wl1271 *wl, int hwaddr, |
| 129 | void *buf, size_t len, bool fixed) |
| 130 | { |
| 131 | int physical; |
| 132 | int addr; |
| 133 | |
| 134 | /* Addresses are stored internally as addresses to 32 bytes blocks */ |
| 135 | addr = hwaddr << 5; |
| 136 | |
| 137 | physical = wl1271_translate_addr(wl, addr); |
| 138 | |
| 139 | wl1271_raw_read(wl, physical, buf, len, fixed); |
| 140 | } |
| 141 | |
Teemu Paasikivi | b42f91b | 2010-02-22 08:38:24 +0200 | [diff] [blame] | 142 | static inline u32 wl1271_read32(struct wl1271 *wl, int addr) |
| 143 | { |
| 144 | return wl1271_raw_read32(wl, wl1271_translate_addr(wl, addr)); |
| 145 | } |
| 146 | |
| 147 | static inline void wl1271_write32(struct wl1271 *wl, int addr, u32 val) |
| 148 | { |
| 149 | wl1271_raw_write32(wl, wl1271_translate_addr(wl, addr), val); |
| 150 | } |
| 151 | |
Teemu Paasikivi | becd551 | 2010-03-18 12:26:27 +0200 | [diff] [blame] | 152 | static inline void wl1271_power_off(struct wl1271 *wl) |
| 153 | { |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 154 | wl->if_ops->power(wl->dev, false); |
Teemu Paasikivi | becd551 | 2010-03-18 12:26:27 +0200 | [diff] [blame] | 155 | clear_bit(WL1271_FLAG_GPIO_POWER, &wl->flags); |
| 156 | } |
| 157 | |
Ohad Ben-Cohen | 2cc78ff | 2010-09-16 01:22:04 +0200 | [diff] [blame] | 158 | static inline int wl1271_power_on(struct wl1271 *wl) |
Teemu Paasikivi | becd551 | 2010-03-18 12:26:27 +0200 | [diff] [blame] | 159 | { |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 160 | int ret = wl->if_ops->power(wl->dev, true); |
Ohad Ben-Cohen | 2cc78ff | 2010-09-16 01:22:04 +0200 | [diff] [blame] | 161 | if (ret == 0) |
| 162 | set_bit(WL1271_FLAG_GPIO_POWER, &wl->flags); |
| 163 | |
| 164 | return ret; |
Teemu Paasikivi | becd551 | 2010-03-18 12:26:27 +0200 | [diff] [blame] | 165 | } |
| 166 | |
Teemu Paasikivi | b42f91b | 2010-02-22 08:38:24 +0200 | [diff] [blame] | 167 | |
| 168 | /* Top Register IO */ |
| 169 | void wl1271_top_reg_write(struct wl1271 *wl, int addr, u16 val); |
| 170 | u16 wl1271_top_reg_read(struct wl1271 *wl, int addr); |
| 171 | |
| 172 | int wl1271_set_partition(struct wl1271 *wl, |
| 173 | struct wl1271_partition_set *p); |
| 174 | |
Felipe Balbi | 4b32a2c | 2011-10-06 10:46:20 +0300 | [diff] [blame] | 175 | bool wl1271_set_block_size(struct wl1271 *wl); |
| 176 | |
Teemu Paasikivi | 2d5e82b | 2010-02-22 08:38:21 +0200 | [diff] [blame] | 177 | /* Functions from wl1271_main.c */ |
| 178 | |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 179 | int wl1271_tx_dummy_packet(struct wl1271 *wl); |
Teemu Paasikivi | 2d5e82b | 2010-02-22 08:38:21 +0200 | [diff] [blame] | 180 | |
Teemu Paasikivi | 521a5b2 | 2010-02-18 13:25:54 +0200 | [diff] [blame] | 181 | #endif |