GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / net / wireless / wl12xx / wl1251_io.c
blobf338701305bdb99e2b36ac89e69f3c9a03986769
1 /*
2 * This file is part of wl12xx
4 * Copyright (C) 2008 Nokia Corporation
6 * Contact: Kalle Valo <kalle.valo@nokia.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
24 #include "wl1251.h"
25 #include "wl1251_reg.h"
26 #include "wl1251_io.h"
28 static enum wl12xx_acx_int_reg wl1251_io_reg_table[ACX_REG_TABLE_LEN] = {
29 [ACX_REG_INTERRUPT_TRIG] = (REGISTERS_BASE + 0x0474),
30 [ACX_REG_INTERRUPT_TRIG_H] = (REGISTERS_BASE + 0x0478),
31 [ACX_REG_INTERRUPT_MASK] = (REGISTERS_BASE + 0x0494),
32 [ACX_REG_HINT_MASK_SET] = (REGISTERS_BASE + 0x0498),
33 [ACX_REG_HINT_MASK_CLR] = (REGISTERS_BASE + 0x049C),
34 [ACX_REG_INTERRUPT_NO_CLEAR] = (REGISTERS_BASE + 0x04B0),
35 [ACX_REG_INTERRUPT_CLEAR] = (REGISTERS_BASE + 0x04A4),
36 [ACX_REG_INTERRUPT_ACK] = (REGISTERS_BASE + 0x04A8),
37 [ACX_REG_SLV_SOFT_RESET] = (REGISTERS_BASE + 0x0000),
38 [ACX_REG_EE_START] = (REGISTERS_BASE + 0x080C),
39 [ACX_REG_ECPU_CONTROL] = (REGISTERS_BASE + 0x0804)
42 static int wl1251_translate_reg_addr(struct wl1251 *wl, int addr)
44 /* If the address is lower than REGISTERS_BASE, it means that this is
45 * a chip-specific register address, so look it up in the registers
46 * table */
47 if (addr < REGISTERS_BASE) {
48 /* Make sure we don't go over the table */
49 if (addr >= ACX_REG_TABLE_LEN) {
50 wl1251_error("address out of range (%d)", addr);
51 return -EINVAL;
53 addr = wl1251_io_reg_table[addr];
56 return addr - wl->physical_reg_addr + wl->virtual_reg_addr;
59 static int wl1251_translate_mem_addr(struct wl1251 *wl, int addr)
61 return addr - wl->physical_mem_addr + wl->virtual_mem_addr;
64 void wl1251_mem_read(struct wl1251 *wl, int addr, void *buf, size_t len)
66 int physical;
68 physical = wl1251_translate_mem_addr(wl, addr);
70 wl->if_ops->read(wl, physical, buf, len);
73 void wl1251_mem_write(struct wl1251 *wl, int addr, void *buf, size_t len)
75 int physical;
77 physical = wl1251_translate_mem_addr(wl, addr);
79 wl->if_ops->write(wl, physical, buf, len);
82 u32 wl1251_mem_read32(struct wl1251 *wl, int addr)
84 return wl1251_read32(wl, wl1251_translate_mem_addr(wl, addr));
87 void wl1251_mem_write32(struct wl1251 *wl, int addr, u32 val)
89 wl1251_write32(wl, wl1251_translate_mem_addr(wl, addr), val);
92 u32 wl1251_reg_read32(struct wl1251 *wl, int addr)
94 return wl1251_read32(wl, wl1251_translate_reg_addr(wl, addr));
97 void wl1251_reg_write32(struct wl1251 *wl, int addr, u32 val)
99 wl1251_write32(wl, wl1251_translate_reg_addr(wl, addr), val);
102 /* Set the partitions to access the chip addresses.
104 * There are two VIRTUAL partitions (the memory partition and the
105 * registers partition), which are mapped to two different areas of the
106 * PHYSICAL (hardware) memory. This function also makes other checks to
107 * ensure that the partitions are not overlapping. In the diagram below, the
108 * memory partition comes before the register partition, but the opposite is
109 * also supported.
111 * PHYSICAL address
112 * space
114 * | |
115 * ...+----+--> mem_start
116 * VIRTUAL address ... | |
117 * space ... | | [PART_0]
118 * ... | |
119 * 0x00000000 <--+----+... ...+----+--> mem_start + mem_size
120 * | | ... | |
121 * |MEM | ... | |
122 * | | ... | |
123 * part_size <--+----+... | | {unused area)
124 * | | ... | |
125 * |REG | ... | |
126 * part_size | | ... | |
127 * + <--+----+... ...+----+--> reg_start
128 * reg_size ... | |
129 * ... | | [PART_1]
130 * ... | |
131 * ...+----+--> reg_start + reg_size
132 * | |
135 void wl1251_set_partition(struct wl1251 *wl,
136 u32 mem_start, u32 mem_size,
137 u32 reg_start, u32 reg_size)
139 struct wl1251_partition partition[2];
141 wl1251_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
142 mem_start, mem_size);
143 wl1251_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
144 reg_start, reg_size);
146 /* Make sure that the two partitions together don't exceed the
147 * address range */
148 if ((mem_size + reg_size) > HW_ACCESS_MEMORY_MAX_RANGE) {
149 wl1251_debug(DEBUG_SPI, "Total size exceeds maximum virtual"
150 " address range. Truncating partition[0].");
151 mem_size = HW_ACCESS_MEMORY_MAX_RANGE - reg_size;
152 wl1251_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
153 mem_start, mem_size);
154 wl1251_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
155 reg_start, reg_size);
158 if ((mem_start < reg_start) &&
159 ((mem_start + mem_size) > reg_start)) {
160 /* Guarantee that the memory partition doesn't overlap the
161 * registers partition */
162 wl1251_debug(DEBUG_SPI, "End of partition[0] is "
163 "overlapping partition[1]. Adjusted.");
164 mem_size = reg_start - mem_start;
165 wl1251_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
166 mem_start, mem_size);
167 wl1251_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
168 reg_start, reg_size);
169 } else if ((reg_start < mem_start) &&
170 ((reg_start + reg_size) > mem_start)) {
171 /* Guarantee that the register partition doesn't overlap the
172 * memory partition */
173 wl1251_debug(DEBUG_SPI, "End of partition[1] is"
174 " overlapping partition[0]. Adjusted.");
175 reg_size = mem_start - reg_start;
176 wl1251_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
177 mem_start, mem_size);
178 wl1251_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
179 reg_start, reg_size);
182 partition[0].start = mem_start;
183 partition[0].size = mem_size;
184 partition[1].start = reg_start;
185 partition[1].size = reg_size;
187 wl->physical_mem_addr = mem_start;
188 wl->physical_reg_addr = reg_start;
190 wl->virtual_mem_addr = 0;
191 wl->virtual_reg_addr = mem_size;
193 wl->if_ops->write(wl, HW_ACCESS_PART0_SIZE_ADDR, partition,
194 sizeof(partition));