io.h revision b666bb7f2fe2bdc0309b0d58afb48eae85d92221
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 45struct wl1271; 46 47void wlcore_disable_interrupts(struct wl1271 *wl); 48void wlcore_disable_interrupts_nosync(struct wl1271 *wl); 49void wlcore_enable_interrupts(struct wl1271 *wl); 50 51void wl1271_io_reset(struct wl1271 *wl); 52void wl1271_io_init(struct wl1271 *wl); 53int wlcore_translate_addr(struct wl1271 *wl, int addr); 54 55/* Raw target IO, address is not translated */ 56static inline void wl1271_raw_write(struct wl1271 *wl, int addr, void *buf, 57 size_t len, bool fixed) 58{ 59 wl->if_ops->write(wl->dev, addr, buf, len, fixed); 60} 61 62static inline void wl1271_raw_read(struct wl1271 *wl, int addr, void *buf, 63 size_t len, bool fixed) 64{ 65 wl->if_ops->read(wl->dev, addr, buf, len, fixed); 66} 67 68static inline void wlcore_raw_read_data(struct wl1271 *wl, int reg, void *buf, 69 size_t len, bool fixed) 70{ 71 wl1271_raw_read(wl, wl->rtable[reg], buf, len, fixed); 72} 73 74static inline void wlcore_raw_write_data(struct wl1271 *wl, int reg, void *buf, 75 size_t len, bool fixed) 76{ 77 wl1271_raw_write(wl, wl->rtable[reg], buf, len, fixed); 78} 79 80static inline u32 wl1271_raw_read32(struct wl1271 *wl, int addr) 81{ 82 wl1271_raw_read(wl, addr, &wl->buffer_32, 83 sizeof(wl->buffer_32), false); 84 85 return le32_to_cpu(wl->buffer_32); 86} 87 88static inline void wl1271_raw_write32(struct wl1271 *wl, int addr, u32 val) 89{ 90 wl->buffer_32 = cpu_to_le32(val); 91 wl1271_raw_write(wl, addr, &wl->buffer_32, 92 sizeof(wl->buffer_32), false); 93} 94 95static inline void wl1271_read(struct wl1271 *wl, int addr, void *buf, 96 size_t len, bool fixed) 97{ 98 int physical; 99 100 physical = wlcore_translate_addr(wl, addr); 101 102 wl1271_raw_read(wl, physical, buf, len, fixed); 103} 104 105static inline void wl1271_write(struct wl1271 *wl, int addr, void *buf, 106 size_t len, bool fixed) 107{ 108 int physical; 109 110 physical = wlcore_translate_addr(wl, addr); 111 112 wl1271_raw_write(wl, physical, buf, len, fixed); 113} 114 115static inline void wlcore_write_data(struct wl1271 *wl, int reg, void *buf, 116 size_t len, bool fixed) 117{ 118 wl1271_write(wl, wl->rtable[reg], buf, len, fixed); 119} 120 121static inline void wlcore_read_data(struct wl1271 *wl, int reg, void *buf, 122 size_t len, bool fixed) 123{ 124 wl1271_read(wl, wl->rtable[reg], buf, len, fixed); 125} 126 127static inline void wl1271_read_hwaddr(struct wl1271 *wl, int hwaddr, 128 void *buf, size_t len, bool fixed) 129{ 130 int physical; 131 int addr; 132 133 /* Addresses are stored internally as addresses to 32 bytes blocks */ 134 addr = hwaddr << 5; 135 136 physical = wlcore_translate_addr(wl, addr); 137 138 wl1271_raw_read(wl, physical, buf, len, fixed); 139} 140 141static inline u32 wl1271_read32(struct wl1271 *wl, int addr) 142{ 143 return wl1271_raw_read32(wl, wlcore_translate_addr(wl, addr)); 144} 145 146static inline void wl1271_write32(struct wl1271 *wl, int addr, u32 val) 147{ 148 wl1271_raw_write32(wl, wlcore_translate_addr(wl, addr), val); 149} 150 151static inline u32 wlcore_read_reg(struct wl1271 *wl, int reg) 152{ 153 return wl1271_raw_read32(wl, 154 wlcore_translate_addr(wl, wl->rtable[reg])); 155} 156 157static inline void wlcore_write_reg(struct wl1271 *wl, int reg, u32 val) 158{ 159 wl1271_raw_write32(wl, wlcore_translate_addr(wl, wl->rtable[reg]), val); 160} 161 162static inline void wl1271_power_off(struct wl1271 *wl) 163{ 164 int ret; 165 166 if (!test_bit(WL1271_FLAG_GPIO_POWER, &wl->flags)) 167 return; 168 169 ret = wl->if_ops->power(wl->dev, false); 170 if (!ret) 171 clear_bit(WL1271_FLAG_GPIO_POWER, &wl->flags); 172} 173 174static inline int wl1271_power_on(struct wl1271 *wl) 175{ 176 int ret = wl->if_ops->power(wl->dev, true); 177 if (ret == 0) 178 set_bit(WL1271_FLAG_GPIO_POWER, &wl->flags); 179 180 return ret; 181} 182 183void wlcore_set_partition(struct wl1271 *wl, 184 const struct wlcore_partition_set *p); 185 186bool wl1271_set_block_size(struct wl1271 *wl); 187 188/* Functions from wl1271_main.c */ 189 190int wl1271_tx_dummy_packet(struct wl1271 *wl); 191 192void wlcore_select_partition(struct wl1271 *wl, u8 part); 193 194#endif 195