blob: da5c1ad942a45d81c08de332f1c0a7871e9c546b [file] [log] [blame]
Teemu Paasikivi521a5b22010-02-18 13:25:54 +02001/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2008-2010 Nokia Corporation
5 *
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7 *
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.
11 *
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.
16 *
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
21 *
22 */
23
24#include <linux/module.h>
25#include <linux/platform_device.h>
26#include <linux/crc7.h>
27#include <linux/spi/spi.h>
28
Shahar Levi00d20102010-11-08 11:20:10 +000029#include "wl12xx.h"
Teemu Paasikivi521a5b22010-02-18 13:25:54 +020030#include "wl12xx_80211.h"
Shahar Levi00d20102010-11-08 11:20:10 +000031#include "io.h"
Ido Yariv0da13da2011-03-31 10:06:58 +020032#include "tx.h"
Teemu Paasikivi521a5b22010-02-18 13:25:54 +020033
Teemu Paasikivi760d9692010-02-22 08:38:25 +020034#define OCP_CMD_LOOP 32
35
36#define OCP_CMD_WRITE 0x1
37#define OCP_CMD_READ 0x2
38
39#define OCP_READY_MASK BIT(18)
40#define OCP_STATUS_MASK (BIT(16) | BIT(17))
41
42#define OCP_STATUS_NO_RESP 0x00000
43#define OCP_STATUS_OK 0x10000
44#define OCP_STATUS_REQ_FAILED 0x20000
45#define OCP_STATUS_RESP_ERROR 0x30000
46
Shahar Levi48a61472011-03-06 16:32:08 +020047bool wl1271_set_block_size(struct wl1271 *wl)
48{
49 if (wl->if_ops->set_block_size) {
Ido Yariv0da13da2011-03-31 10:06:58 +020050 wl->if_ops->set_block_size(wl, WL12XX_BUS_BLOCK_SIZE);
Shahar Levi48a61472011-03-06 16:32:08 +020051 return true;
52 }
53
54 return false;
55}
56
Teemu Paasikivi54f7e502010-02-22 08:38:22 +020057void wl1271_disable_interrupts(struct wl1271 *wl)
58{
Teemu Paasikivi8197b712010-02-22 08:38:23 +020059 wl->if_ops->disable_irq(wl);
Teemu Paasikivi54f7e502010-02-22 08:38:22 +020060}
61
62void wl1271_enable_interrupts(struct wl1271 *wl)
63{
Teemu Paasikivi8197b712010-02-22 08:38:23 +020064 wl->if_ops->enable_irq(wl);
Teemu Paasikivi54f7e502010-02-22 08:38:22 +020065}
66
Teemu Paasikivi521a5b22010-02-18 13:25:54 +020067/* Set the SPI partitions to access the chip addresses
68 *
69 * To simplify driver code, a fixed (virtual) memory map is defined for
70 * register and memory addresses. Because in the chipset, in different stages
71 * of operation, those addresses will move around, an address translation
72 * mechanism is required.
73 *
74 * There are four partitions (three memory and one register partition),
75 * which are mapped to two different areas of the hardware memory.
76 *
77 * Virtual address
78 * space
79 *
80 * | |
81 * ...+----+--> mem.start
82 * Physical address ... | |
83 * space ... | | [PART_0]
84 * ... | |
85 * 00000000 <--+----+... ...+----+--> mem.start + mem.size
86 * | | ... | |
87 * |MEM | ... | |
88 * | | ... | |
89 * mem.size <--+----+... | | {unused area)
90 * | | ... | |
91 * |REG | ... | |
92 * mem.size | | ... | |
93 * + <--+----+... ...+----+--> reg.start
94 * reg.size | | ... | |
95 * |MEM2| ... | | [PART_1]
96 * | | ... | |
97 * ...+----+--> reg.start + reg.size
98 * | |
99 *
100 */
101int wl1271_set_partition(struct wl1271 *wl,
102 struct wl1271_partition_set *p)
103{
104 /* copy partition info */
105 memcpy(&wl->part, p, sizeof(*p));
106
107 wl1271_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
108 p->mem.start, p->mem.size);
109 wl1271_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
110 p->reg.start, p->reg.size);
111 wl1271_debug(DEBUG_SPI, "mem2_start %08X mem2_size %08X",
112 p->mem2.start, p->mem2.size);
113 wl1271_debug(DEBUG_SPI, "mem3_start %08X mem3_size %08X",
114 p->mem3.start, p->mem3.size);
115
116 /* write partition info to the chipset */
117 wl1271_raw_write32(wl, HW_PART0_START_ADDR, p->mem.start);
118 wl1271_raw_write32(wl, HW_PART0_SIZE_ADDR, p->mem.size);
119 wl1271_raw_write32(wl, HW_PART1_START_ADDR, p->reg.start);
120 wl1271_raw_write32(wl, HW_PART1_SIZE_ADDR, p->reg.size);
121 wl1271_raw_write32(wl, HW_PART2_START_ADDR, p->mem2.start);
122 wl1271_raw_write32(wl, HW_PART2_SIZE_ADDR, p->mem2.size);
123 wl1271_raw_write32(wl, HW_PART3_START_ADDR, p->mem3.start);
124
125 return 0;
126}
Roger Quadros870c3672010-11-29 16:24:57 +0200127EXPORT_SYMBOL_GPL(wl1271_set_partition);
Teemu Paasikivi521a5b22010-02-18 13:25:54 +0200128
Teemu Paasikivi9b280722010-02-18 13:25:56 +0200129void wl1271_io_reset(struct wl1271 *wl)
130{
Teemu Paasikivi8197b712010-02-22 08:38:23 +0200131 wl->if_ops->reset(wl);
Teemu Paasikivi9b280722010-02-18 13:25:56 +0200132}
133
134void wl1271_io_init(struct wl1271 *wl)
135{
Teemu Paasikivi8197b712010-02-22 08:38:23 +0200136 wl->if_ops->init(wl);
Teemu Paasikivi9b280722010-02-18 13:25:56 +0200137}
138
Teemu Paasikivi521a5b22010-02-18 13:25:54 +0200139void wl1271_top_reg_write(struct wl1271 *wl, int addr, u16 val)
140{
141 /* write address >> 1 + 0x30000 to OCP_POR_CTR */
142 addr = (addr >> 1) + 0x30000;
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200143 wl1271_write32(wl, OCP_POR_CTR, addr);
Teemu Paasikivi521a5b22010-02-18 13:25:54 +0200144
145 /* write value to OCP_POR_WDATA */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200146 wl1271_write32(wl, OCP_DATA_WRITE, val);
Teemu Paasikivi521a5b22010-02-18 13:25:54 +0200147
148 /* write 1 to OCP_CMD */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200149 wl1271_write32(wl, OCP_CMD, OCP_CMD_WRITE);
Teemu Paasikivi521a5b22010-02-18 13:25:54 +0200150}
151
152u16 wl1271_top_reg_read(struct wl1271 *wl, int addr)
153{
154 u32 val;
155 int timeout = OCP_CMD_LOOP;
156
157 /* write address >> 1 + 0x30000 to OCP_POR_CTR */
158 addr = (addr >> 1) + 0x30000;
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200159 wl1271_write32(wl, OCP_POR_CTR, addr);
Teemu Paasikivi521a5b22010-02-18 13:25:54 +0200160
161 /* write 2 to OCP_CMD */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200162 wl1271_write32(wl, OCP_CMD, OCP_CMD_READ);
Teemu Paasikivi521a5b22010-02-18 13:25:54 +0200163
164 /* poll for data ready */
165 do {
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200166 val = wl1271_read32(wl, OCP_DATA_READ);
Teemu Paasikivi521a5b22010-02-18 13:25:54 +0200167 } while (!(val & OCP_READY_MASK) && --timeout);
168
169 if (!timeout) {
170 wl1271_warning("Top register access timed out.");
171 return 0xffff;
172 }
173
174 /* check data status and return if OK */
175 if ((val & OCP_STATUS_MASK) == OCP_STATUS_OK)
176 return val & 0xffff;
177 else {
178 wl1271_warning("Top register access returned error.");
179 return 0xffff;
180 }
181}
182