2 * This file is part of wl1271
4 * Copyright (C) 2008-2010 Nokia Corporation
6 * Contact: Luciano Coelho <luciano.coelho@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
24 #include <linux/module.h>
25 #include <linux/platform_device.h>
26 #include <linux/spi/spi.h>
27 #include <linux/interrupt.h>
31 #include "wl12xx_80211.h"
35 #define OCP_CMD_LOOP 32
37 #define OCP_CMD_WRITE 0x1
38 #define OCP_CMD_READ 0x2
40 #define OCP_READY_MASK BIT(18)
41 #define OCP_STATUS_MASK (BIT(16) | BIT(17))
43 #define OCP_STATUS_NO_RESP 0x00000
44 #define OCP_STATUS_OK 0x10000
45 #define OCP_STATUS_REQ_FAILED 0x20000
46 #define OCP_STATUS_RESP_ERROR 0x30000
48 struct wl1271_partition_set wl12xx_part_table[PART_TABLE_LEN] = {
55 .start = REGISTERS_BASE,
74 .start = REGISTERS_BASE,
107 bool wl1271_set_block_size(struct wl1271 *wl)
109 if (wl->if_ops->set_block_size) {
110 wl->if_ops->set_block_size(wl->dev, WL12XX_BUS_BLOCK_SIZE);
117 void wl1271_disable_interrupts(struct wl1271 *wl)
119 disable_irq(wl->irq);
122 void wl1271_enable_interrupts(struct wl1271 *wl)
127 /* Set the SPI partitions to access the chip addresses
129 * To simplify driver code, a fixed (virtual) memory map is defined for
130 * register and memory addresses. Because in the chipset, in different stages
131 * of operation, those addresses will move around, an address translation
132 * mechanism is required.
134 * There are four partitions (three memory and one register partition),
135 * which are mapped to two different areas of the hardware memory.
141 * ...+----+--> mem.start
142 * Physical address ... | |
143 * space ... | | [PART_0]
145 * 00000000 <--+----+... ...+----+--> mem.start + mem.size
149 * mem.size <--+----+... | | {unused area)
152 * mem.size | | ... | |
153 * + <--+----+... ...+----+--> reg.start
154 * reg.size | | ... | |
155 * |MEM2| ... | | [PART_1]
157 * ...+----+--> reg.start + reg.size
161 int wl1271_set_partition(struct wl1271 *wl,
162 struct wl1271_partition_set *p)
164 /* copy partition info */
165 memcpy(&wl->part, p, sizeof(*p));
167 wl1271_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
168 p->mem.start, p->mem.size);
169 wl1271_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
170 p->reg.start, p->reg.size);
171 wl1271_debug(DEBUG_SPI, "mem2_start %08X mem2_size %08X",
172 p->mem2.start, p->mem2.size);
173 wl1271_debug(DEBUG_SPI, "mem3_start %08X mem3_size %08X",
174 p->mem3.start, p->mem3.size);
176 /* write partition info to the chipset */
177 wl1271_raw_write32(wl, HW_PART0_START_ADDR, p->mem.start);
178 wl1271_raw_write32(wl, HW_PART0_SIZE_ADDR, p->mem.size);
179 wl1271_raw_write32(wl, HW_PART1_START_ADDR, p->reg.start);
180 wl1271_raw_write32(wl, HW_PART1_SIZE_ADDR, p->reg.size);
181 wl1271_raw_write32(wl, HW_PART2_START_ADDR, p->mem2.start);
182 wl1271_raw_write32(wl, HW_PART2_SIZE_ADDR, p->mem2.size);
183 wl1271_raw_write32(wl, HW_PART3_START_ADDR, p->mem3.start);
187 EXPORT_SYMBOL_GPL(wl1271_set_partition);
189 void wl1271_io_reset(struct wl1271 *wl)
191 if (wl->if_ops->reset)
192 wl->if_ops->reset(wl->dev);
195 void wl1271_io_init(struct wl1271 *wl)
197 if (wl->if_ops->init)
198 wl->if_ops->init(wl->dev);
201 void wl1271_top_reg_write(struct wl1271 *wl, int addr, u16 val)
203 /* write address >> 1 + 0x30000 to OCP_POR_CTR */
204 addr = (addr >> 1) + 0x30000;
205 wl1271_write32(wl, OCP_POR_CTR, addr);
207 /* write value to OCP_POR_WDATA */
208 wl1271_write32(wl, OCP_DATA_WRITE, val);
210 /* write 1 to OCP_CMD */
211 wl1271_write32(wl, OCP_CMD, OCP_CMD_WRITE);
214 u16 wl1271_top_reg_read(struct wl1271 *wl, int addr)
217 int timeout = OCP_CMD_LOOP;
219 /* write address >> 1 + 0x30000 to OCP_POR_CTR */
220 addr = (addr >> 1) + 0x30000;
221 wl1271_write32(wl, OCP_POR_CTR, addr);
223 /* write 2 to OCP_CMD */
224 wl1271_write32(wl, OCP_CMD, OCP_CMD_READ);
226 /* poll for data ready */
228 val = wl1271_read32(wl, OCP_DATA_READ);
229 } while (!(val & OCP_READY_MASK) && --timeout);
232 wl1271_warning("Top register access timed out.");
236 /* check data status and return if OK */
237 if ((val & OCP_STATUS_MASK) == OCP_STATUS_OK)
240 wl1271_warning("Top register access returned error.");