| 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 |  | 
| Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 28 | #include "reg.h" | 
| Teemu Paasikivi | 760d969 | 2010-02-22 08:38:25 +0200 | [diff] [blame] | 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 |  | 
| Teemu Paasikivi | 521a5b2 | 2010-02-18 13:25:54 +0200 | [diff] [blame] | 45 | struct wl1271; | 
|  | 46 |  | 
| Teemu Paasikivi | 54f7e50 | 2010-02-22 08:38:22 +0200 | [diff] [blame] | 47 | void wl1271_disable_interrupts(struct wl1271 *wl); | 
|  | 48 | void wl1271_enable_interrupts(struct wl1271 *wl); | 
|  | 49 |  | 
| Teemu Paasikivi | 9b28072 | 2010-02-18 13:25:56 +0200 | [diff] [blame] | 50 | void wl1271_io_reset(struct wl1271 *wl); | 
|  | 51 | void wl1271_io_init(struct wl1271 *wl); | 
| Teemu Paasikivi | 521a5b2 | 2010-02-18 13:25:54 +0200 | [diff] [blame] | 52 |  | 
| Teemu Paasikivi | b42f91b | 2010-02-22 08:38:24 +0200 | [diff] [blame] | 53 | static inline struct device *wl1271_wl_to_dev(struct wl1271 *wl) | 
|  | 54 | { | 
|  | 55 | return wl->if_ops->dev(wl); | 
|  | 56 | } | 
|  | 57 |  | 
| Teemu Paasikivi | 8197b71 | 2010-02-22 08:38:23 +0200 | [diff] [blame] | 58 |  | 
| Teemu Paasikivi | 521a5b2 | 2010-02-18 13:25:54 +0200 | [diff] [blame] | 59 | /* Raw target IO, address is not translated */ | 
| Teemu Paasikivi | b42f91b | 2010-02-22 08:38:24 +0200 | [diff] [blame] | 60 | static inline void wl1271_raw_write(struct wl1271 *wl, int addr, void *buf, | 
|  | 61 | size_t len, bool fixed) | 
|  | 62 | { | 
|  | 63 | wl->if_ops->write(wl, addr, buf, len, fixed); | 
|  | 64 | } | 
| Teemu Paasikivi | 521a5b2 | 2010-02-18 13:25:54 +0200 | [diff] [blame] | 65 |  | 
| Teemu Paasikivi | b42f91b | 2010-02-22 08:38:24 +0200 | [diff] [blame] | 66 | static inline void wl1271_raw_read(struct wl1271 *wl, int addr, void *buf, | 
|  | 67 | size_t len, bool fixed) | 
|  | 68 | { | 
|  | 69 | wl->if_ops->read(wl, addr, buf, len, fixed); | 
|  | 70 | } | 
| Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 71 |  | 
|  | 72 | static inline u32 wl1271_raw_read32(struct wl1271 *wl, int addr) | 
|  | 73 | { | 
|  | 74 | wl1271_raw_read(wl, addr, &wl->buffer_32, | 
|  | 75 | sizeof(wl->buffer_32), false); | 
|  | 76 |  | 
| Juuso Oikarinen | 554d720 | 2010-05-07 11:38:59 +0300 | [diff] [blame] | 77 | return le32_to_cpu(wl->buffer_32); | 
| Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 78 | } | 
|  | 79 |  | 
|  | 80 | static inline void wl1271_raw_write32(struct wl1271 *wl, int addr, u32 val) | 
|  | 81 | { | 
| Juuso Oikarinen | 554d720 | 2010-05-07 11:38:59 +0300 | [diff] [blame] | 82 | wl->buffer_32 = cpu_to_le32(val); | 
| Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 83 | wl1271_raw_write(wl, addr, &wl->buffer_32, | 
|  | 84 | sizeof(wl->buffer_32), false); | 
|  | 85 | } | 
| Teemu Paasikivi | 2d5e82b | 2010-02-22 08:38:21 +0200 | [diff] [blame] | 86 |  | 
| Teemu Paasikivi | b42f91b | 2010-02-22 08:38:24 +0200 | [diff] [blame] | 87 | /* Translated target IO */ | 
|  | 88 | static inline int wl1271_translate_addr(struct wl1271 *wl, int addr) | 
|  | 89 | { | 
|  | 90 | /* | 
|  | 91 | * To translate, first check to which window of addresses the | 
|  | 92 | * particular address belongs. Then subtract the starting address | 
|  | 93 | * of that window from the address. Then, add offset of the | 
|  | 94 | * translated region. | 
|  | 95 | * | 
|  | 96 | * The translated regions occur next to each other in physical device | 
|  | 97 | * memory, so just add the sizes of the preceeding address regions to | 
|  | 98 | * get the offset to the new region. | 
|  | 99 | * | 
|  | 100 | * Currently, only the two first regions are addressed, and the | 
|  | 101 | * assumption is that all addresses will fall into either of those | 
|  | 102 | * two. | 
|  | 103 | */ | 
|  | 104 | if ((addr >= wl->part.reg.start) && | 
|  | 105 | (addr < wl->part.reg.start + wl->part.reg.size)) | 
|  | 106 | return addr - wl->part.reg.start + wl->part.mem.size; | 
|  | 107 | else | 
|  | 108 | return addr - wl->part.mem.start; | 
|  | 109 | } | 
|  | 110 |  | 
|  | 111 | static inline void wl1271_read(struct wl1271 *wl, int addr, void *buf, | 
|  | 112 | size_t len, bool fixed) | 
|  | 113 | { | 
|  | 114 | int physical; | 
|  | 115 |  | 
|  | 116 | physical = wl1271_translate_addr(wl, addr); | 
|  | 117 |  | 
|  | 118 | wl1271_raw_read(wl, physical, buf, len, fixed); | 
|  | 119 | } | 
|  | 120 |  | 
|  | 121 | static inline void wl1271_write(struct wl1271 *wl, int addr, void *buf, | 
|  | 122 | size_t len, bool fixed) | 
|  | 123 | { | 
|  | 124 | int physical; | 
|  | 125 |  | 
|  | 126 | physical = wl1271_translate_addr(wl, addr); | 
|  | 127 |  | 
|  | 128 | wl1271_raw_write(wl, physical, buf, len, fixed); | 
|  | 129 | } | 
|  | 130 |  | 
|  | 131 | static inline u32 wl1271_read32(struct wl1271 *wl, int addr) | 
|  | 132 | { | 
|  | 133 | return wl1271_raw_read32(wl, wl1271_translate_addr(wl, addr)); | 
|  | 134 | } | 
|  | 135 |  | 
|  | 136 | static inline void wl1271_write32(struct wl1271 *wl, int addr, u32 val) | 
|  | 137 | { | 
|  | 138 | wl1271_raw_write32(wl, wl1271_translate_addr(wl, addr), val); | 
|  | 139 | } | 
|  | 140 |  | 
| Teemu Paasikivi | becd551 | 2010-03-18 12:26:27 +0200 | [diff] [blame] | 141 | static inline void wl1271_power_off(struct wl1271 *wl) | 
|  | 142 | { | 
|  | 143 | wl->if_ops->power(wl, false); | 
|  | 144 | clear_bit(WL1271_FLAG_GPIO_POWER, &wl->flags); | 
|  | 145 | } | 
|  | 146 |  | 
| Ohad Ben-Cohen | 2cc78ff | 2010-09-16 01:22:04 +0200 | [diff] [blame] | 147 | static inline int wl1271_power_on(struct wl1271 *wl) | 
| Teemu Paasikivi | becd551 | 2010-03-18 12:26:27 +0200 | [diff] [blame] | 148 | { | 
| Ohad Ben-Cohen | 2cc78ff | 2010-09-16 01:22:04 +0200 | [diff] [blame] | 149 | int ret = wl->if_ops->power(wl, true); | 
|  | 150 | if (ret == 0) | 
|  | 151 | set_bit(WL1271_FLAG_GPIO_POWER, &wl->flags); | 
|  | 152 |  | 
|  | 153 | return ret; | 
| Teemu Paasikivi | becd551 | 2010-03-18 12:26:27 +0200 | [diff] [blame] | 154 | } | 
|  | 155 |  | 
| Teemu Paasikivi | b42f91b | 2010-02-22 08:38:24 +0200 | [diff] [blame] | 156 |  | 
|  | 157 | /* Top Register IO */ | 
|  | 158 | void wl1271_top_reg_write(struct wl1271 *wl, int addr, u16 val); | 
|  | 159 | u16 wl1271_top_reg_read(struct wl1271 *wl, int addr); | 
|  | 160 |  | 
|  | 161 | int wl1271_set_partition(struct wl1271 *wl, | 
|  | 162 | struct wl1271_partition_set *p); | 
|  | 163 |  | 
| Teemu Paasikivi | 2d5e82b | 2010-02-22 08:38:21 +0200 | [diff] [blame] | 164 | /* Functions from wl1271_main.c */ | 
|  | 165 |  | 
|  | 166 | int wl1271_register_hw(struct wl1271 *wl); | 
| Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 167 | void wl1271_unregister_hw(struct wl1271 *wl); | 
| Teemu Paasikivi | 2d5e82b | 2010-02-22 08:38:21 +0200 | [diff] [blame] | 168 | int wl1271_init_ieee80211(struct wl1271 *wl); | 
|  | 169 | struct ieee80211_hw *wl1271_alloc_hw(void); | 
|  | 170 | int wl1271_free_hw(struct wl1271 *wl); | 
| Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 171 | irqreturn_t wl1271_irq(int irq, void *data); | 
| Teemu Paasikivi | 2d5e82b | 2010-02-22 08:38:21 +0200 | [diff] [blame] | 172 |  | 
| Teemu Paasikivi | 521a5b2 | 2010-02-18 13:25:54 +0200 | [diff] [blame] | 173 | #endif |