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 25 #ifndef __IO_H__ 26 #define __IO_H__ 27 28 #include <linux/irqreturn.h> 29 30 #define HW_ACCESS_MEMORY_MAX_RANGE 0x1FFC0 31 32 #define HW_PARTITION_REGISTERS_ADDR 0x1FFC0 33 #define HW_PART0_SIZE_ADDR (HW_PARTITION_REGISTERS_ADDR) 34 #define HW_PART0_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 4) 35 #define HW_PART1_SIZE_ADDR (HW_PARTITION_REGISTERS_ADDR + 8) 36 #define HW_PART1_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 12) 37 #define HW_PART2_SIZE_ADDR (HW_PARTITION_REGISTERS_ADDR + 16) 38 #define HW_PART2_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 20) 39 #define HW_PART3_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 24) 40 41 #define HW_ACCESS_REGISTER_SIZE 4 42 43 #define HW_ACCESS_PRAM_MAX_RANGE 0x3c000 44 45 struct wl1271; 46 47 void wlcore_disable_interrupts(struct wl1271 *wl); 48 void wlcore_disable_interrupts_nosync(struct wl1271 *wl); 49 void wlcore_enable_interrupts(struct wl1271 *wl); 50 void wlcore_synchronize_interrupts(struct wl1271 *wl); 51 52 void wl1271_io_reset(struct wl1271 *wl); 53 void wl1271_io_init(struct wl1271 *wl); 54 int wlcore_translate_addr(struct wl1271 *wl, int addr); 55 56 /* Raw target IO, address is not translated */ 57 static inline int __must_check wlcore_raw_write(struct wl1271 *wl, int addr, 58 void *buf, size_t len, 59 bool fixed) 60 { 61 int ret; 62 63 if (test_bit(WL1271_FLAG_IO_FAILED, &wl->flags)) 64 return -EIO; 65 66 ret = wl->if_ops->write(wl->dev, addr, buf, len, fixed); 67 if (ret && wl->state != WLCORE_STATE_OFF) 68 set_bit(WL1271_FLAG_IO_FAILED, &wl->flags); 69 70 return ret; 71 } 72 73 static inline int __must_check wlcore_raw_read(struct wl1271 *wl, int addr, 74 void *buf, size_t len, 75 bool fixed) 76 { 77 int ret; 78 79 if (test_bit(WL1271_FLAG_IO_FAILED, &wl->flags)) 80 return -EIO; 81 82 ret = wl->if_ops->read(wl->dev, addr, buf, len, fixed); 83 if (ret && wl->state != WLCORE_STATE_OFF) 84 set_bit(WL1271_FLAG_IO_FAILED, &wl->flags); 85 86 return ret; 87 } 88 89 static inline int __must_check wlcore_raw_read_data(struct wl1271 *wl, int reg, 90 void *buf, size_t len, 91 bool fixed) 92 { 93 return wlcore_raw_read(wl, wl->rtable[reg], buf, len, fixed); 94 } 95 96 static inline int __must_check wlcore_raw_write_data(struct wl1271 *wl, int reg, 97 void *buf, size_t len, 98 bool fixed) 99 { 100 return wlcore_raw_write(wl, wl->rtable[reg], buf, len, fixed); 101 } 102 103 static inline int __must_check wlcore_raw_read32(struct wl1271 *wl, int addr, 104 u32 *val) 105 { 106 int ret; 107 108 ret = wlcore_raw_read(wl, addr, wl->buffer_32, 109 sizeof(*wl->buffer_32), false); 110 if (ret < 0) 111 return ret; 112 113 if (val) 114 *val = le32_to_cpu(*wl->buffer_32); 115 116 return 0; 117 } 118 119 static inline int __must_check wlcore_raw_write32(struct wl1271 *wl, int addr, 120 u32 val) 121 { 122 *wl->buffer_32 = cpu_to_le32(val); 123 return wlcore_raw_write(wl, addr, wl->buffer_32, 124 sizeof(*wl->buffer_32), false); 125 } 126 127 static inline int __must_check wlcore_read(struct wl1271 *wl, int addr, 128 void *buf, size_t len, bool fixed) 129 { 130 int physical; 131 132 physical = wlcore_translate_addr(wl, addr); 133 134 return wlcore_raw_read(wl, physical, buf, len, fixed); 135 } 136 137 static inline int __must_check wlcore_write(struct wl1271 *wl, int addr, 138 void *buf, size_t len, bool fixed) 139 { 140 int physical; 141 142 physical = wlcore_translate_addr(wl, addr); 143 144 return wlcore_raw_write(wl, physical, buf, len, fixed); 145 } 146 147 static inline int __must_check wlcore_write_data(struct wl1271 *wl, int reg, 148 void *buf, size_t len, 149 bool fixed) 150 { 151 return wlcore_write(wl, wl->rtable[reg], buf, len, fixed); 152 } 153 154 static inline int __must_check wlcore_read_data(struct wl1271 *wl, int reg, 155 void *buf, size_t len, 156 bool fixed) 157 { 158 return wlcore_read(wl, wl->rtable[reg], buf, len, fixed); 159 } 160 161 static inline int __must_check wlcore_read_hwaddr(struct wl1271 *wl, int hwaddr, 162 void *buf, size_t len, 163 bool fixed) 164 { 165 int physical; 166 int addr; 167 168 /* Addresses are stored internally as addresses to 32 bytes blocks */ 169 addr = hwaddr << 5; 170 171 physical = wlcore_translate_addr(wl, addr); 172 173 return wlcore_raw_read(wl, physical, buf, len, fixed); 174 } 175 176 static inline int __must_check wlcore_read32(struct wl1271 *wl, int addr, 177 u32 *val) 178 { 179 return wlcore_raw_read32(wl, wlcore_translate_addr(wl, addr), val); 180 } 181 182 static inline int __must_check wlcore_write32(struct wl1271 *wl, int addr, 183 u32 val) 184 { 185 return wlcore_raw_write32(wl, wlcore_translate_addr(wl, addr), val); 186 } 187 188 static inline int __must_check wlcore_read_reg(struct wl1271 *wl, int reg, 189 u32 *val) 190 { 191 return wlcore_raw_read32(wl, 192 wlcore_translate_addr(wl, wl->rtable[reg]), 193 val); 194 } 195 196 static inline int __must_check wlcore_write_reg(struct wl1271 *wl, int reg, 197 u32 val) 198 { 199 return wlcore_raw_write32(wl, 200 wlcore_translate_addr(wl, wl->rtable[reg]), 201 val); 202 } 203 204 static inline void wl1271_power_off(struct wl1271 *wl) 205 { 206 int ret; 207 208 if (!test_bit(WL1271_FLAG_GPIO_POWER, &wl->flags)) 209 return; 210 211 ret = wl->if_ops->power(wl->dev, false); 212 if (!ret) 213 clear_bit(WL1271_FLAG_GPIO_POWER, &wl->flags); 214 } 215 216 static inline int wl1271_power_on(struct wl1271 *wl) 217 { 218 int ret = wl->if_ops->power(wl->dev, true); 219 if (ret == 0) 220 set_bit(WL1271_FLAG_GPIO_POWER, &wl->flags); 221 222 return ret; 223 } 224 225 int wlcore_set_partition(struct wl1271 *wl, 226 const struct wlcore_partition_set *p); 227 228 bool wl1271_set_block_size(struct wl1271 *wl); 229 230 /* Functions from wl1271_main.c */ 231 232 int wl1271_tx_dummy_packet(struct wl1271 *wl); 233 234 #endif 235