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 | |
| 25 | #ifndef __WL1271_IO_H__ |
| 26 | #define __WL1271_IO_H__ |
| 27 | |
| 28 | struct wl1271; |
| 29 | |
Teemu Paasikivi | 54f7e50 | 2010-02-22 08:38:22 +0200 | [diff] [blame] | 30 | void wl1271_disable_interrupts(struct wl1271 *wl); |
| 31 | void wl1271_enable_interrupts(struct wl1271 *wl); |
| 32 | |
Teemu Paasikivi | 9b28072 | 2010-02-18 13:25:56 +0200 | [diff] [blame] | 33 | void wl1271_io_reset(struct wl1271 *wl); |
| 34 | void wl1271_io_init(struct wl1271 *wl); |
Teemu Paasikivi | 521a5b2 | 2010-02-18 13:25:54 +0200 | [diff] [blame] | 35 | |
Teemu Paasikivi | b42f91b | 2010-02-22 08:38:24 +0200 | [diff] [blame^] | 36 | static inline struct device *wl1271_wl_to_dev(struct wl1271 *wl) |
| 37 | { |
| 38 | return wl->if_ops->dev(wl); |
| 39 | } |
| 40 | |
Teemu Paasikivi | 8197b71 | 2010-02-22 08:38:23 +0200 | [diff] [blame] | 41 | |
Teemu Paasikivi | 521a5b2 | 2010-02-18 13:25:54 +0200 | [diff] [blame] | 42 | /* Raw target IO, address is not translated */ |
Teemu Paasikivi | b42f91b | 2010-02-22 08:38:24 +0200 | [diff] [blame^] | 43 | static inline void wl1271_raw_write(struct wl1271 *wl, int addr, void *buf, |
| 44 | size_t len, bool fixed) |
| 45 | { |
| 46 | wl->if_ops->write(wl, addr, buf, len, fixed); |
| 47 | } |
Teemu Paasikivi | 521a5b2 | 2010-02-18 13:25:54 +0200 | [diff] [blame] | 48 | |
Teemu Paasikivi | b42f91b | 2010-02-22 08:38:24 +0200 | [diff] [blame^] | 49 | static inline void wl1271_raw_read(struct wl1271 *wl, int addr, void *buf, |
| 50 | size_t len, bool fixed) |
| 51 | { |
| 52 | wl->if_ops->read(wl, addr, buf, len, fixed); |
| 53 | } |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 54 | |
| 55 | static inline u32 wl1271_raw_read32(struct wl1271 *wl, int addr) |
| 56 | { |
| 57 | wl1271_raw_read(wl, addr, &wl->buffer_32, |
| 58 | sizeof(wl->buffer_32), false); |
| 59 | |
| 60 | return wl->buffer_32; |
| 61 | } |
| 62 | |
| 63 | static inline void wl1271_raw_write32(struct wl1271 *wl, int addr, u32 val) |
| 64 | { |
| 65 | wl->buffer_32 = val; |
| 66 | wl1271_raw_write(wl, addr, &wl->buffer_32, |
| 67 | sizeof(wl->buffer_32), false); |
| 68 | } |
Teemu Paasikivi | 2d5e82b | 2010-02-22 08:38:21 +0200 | [diff] [blame] | 69 | |
Teemu Paasikivi | b42f91b | 2010-02-22 08:38:24 +0200 | [diff] [blame^] | 70 | /* Translated target IO */ |
| 71 | static inline int wl1271_translate_addr(struct wl1271 *wl, int addr) |
| 72 | { |
| 73 | /* |
| 74 | * To translate, first check to which window of addresses the |
| 75 | * particular address belongs. Then subtract the starting address |
| 76 | * of that window from the address. Then, add offset of the |
| 77 | * translated region. |
| 78 | * |
| 79 | * The translated regions occur next to each other in physical device |
| 80 | * memory, so just add the sizes of the preceeding address regions to |
| 81 | * get the offset to the new region. |
| 82 | * |
| 83 | * Currently, only the two first regions are addressed, and the |
| 84 | * assumption is that all addresses will fall into either of those |
| 85 | * two. |
| 86 | */ |
| 87 | if ((addr >= wl->part.reg.start) && |
| 88 | (addr < wl->part.reg.start + wl->part.reg.size)) |
| 89 | return addr - wl->part.reg.start + wl->part.mem.size; |
| 90 | else |
| 91 | return addr - wl->part.mem.start; |
| 92 | } |
| 93 | |
| 94 | static inline void wl1271_read(struct wl1271 *wl, int addr, void *buf, |
| 95 | size_t len, bool fixed) |
| 96 | { |
| 97 | int physical; |
| 98 | |
| 99 | physical = wl1271_translate_addr(wl, addr); |
| 100 | |
| 101 | wl1271_raw_read(wl, physical, buf, len, fixed); |
| 102 | } |
| 103 | |
| 104 | static inline void wl1271_write(struct wl1271 *wl, int addr, void *buf, |
| 105 | size_t len, bool fixed) |
| 106 | { |
| 107 | int physical; |
| 108 | |
| 109 | physical = wl1271_translate_addr(wl, addr); |
| 110 | |
| 111 | wl1271_raw_write(wl, physical, buf, len, fixed); |
| 112 | } |
| 113 | |
| 114 | static inline u32 wl1271_read32(struct wl1271 *wl, int addr) |
| 115 | { |
| 116 | return wl1271_raw_read32(wl, wl1271_translate_addr(wl, addr)); |
| 117 | } |
| 118 | |
| 119 | static inline void wl1271_write32(struct wl1271 *wl, int addr, u32 val) |
| 120 | { |
| 121 | wl1271_raw_write32(wl, wl1271_translate_addr(wl, addr), val); |
| 122 | } |
| 123 | |
| 124 | |
| 125 | /* Top Register IO */ |
| 126 | void wl1271_top_reg_write(struct wl1271 *wl, int addr, u16 val); |
| 127 | u16 wl1271_top_reg_read(struct wl1271 *wl, int addr); |
| 128 | |
| 129 | int wl1271_set_partition(struct wl1271 *wl, |
| 130 | struct wl1271_partition_set *p); |
| 131 | |
Teemu Paasikivi | 2d5e82b | 2010-02-22 08:38:21 +0200 | [diff] [blame] | 132 | /* Functions from wl1271_main.c */ |
| 133 | |
| 134 | int wl1271_register_hw(struct wl1271 *wl); |
| 135 | int wl1271_init_ieee80211(struct wl1271 *wl); |
| 136 | struct ieee80211_hw *wl1271_alloc_hw(void); |
| 137 | int wl1271_free_hw(struct wl1271 *wl); |
| 138 | |
Teemu Paasikivi | 521a5b2 | 2010-02-18 13:25:54 +0200 | [diff] [blame] | 139 | #endif |