blob: aa40c98e8fd32d203747029a79bf1b843ac85f78 [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"
Teemu Paasikivi521a5b22010-02-18 13:25:54 +020032
Teemu Paasikivi760d9692010-02-22 08:38:25 +020033#define OCP_CMD_LOOP 32
34
35#define OCP_CMD_WRITE 0x1
36#define OCP_CMD_READ 0x2
37
38#define OCP_READY_MASK BIT(18)
39#define OCP_STATUS_MASK (BIT(16) | BIT(17))
40
41#define OCP_STATUS_NO_RESP 0x00000
42#define OCP_STATUS_OK 0x10000
43#define OCP_STATUS_REQ_FAILED 0x20000
44#define OCP_STATUS_RESP_ERROR 0x30000
45
Shahar Levi48a61472011-03-06 16:32:08 +020046bool wl1271_set_block_size(struct wl1271 *wl)
47{
48 if (wl->if_ops->set_block_size) {
49 wl->if_ops->set_block_size(wl);
50 return true;
51 }
52
53 return false;
54}
55
Teemu Paasikivi54f7e502010-02-22 08:38:22 +020056void wl1271_disable_interrupts(struct wl1271 *wl)
57{
Teemu Paasikivi8197b712010-02-22 08:38:23 +020058 wl->if_ops->disable_irq(wl);
Teemu Paasikivi54f7e502010-02-22 08:38:22 +020059}
60
61void wl1271_enable_interrupts(struct wl1271 *wl)
62{
Teemu Paasikivi8197b712010-02-22 08:38:23 +020063 wl->if_ops->enable_irq(wl);
Teemu Paasikivi54f7e502010-02-22 08:38:22 +020064}
65
Teemu Paasikivi521a5b22010-02-18 13:25:54 +020066/* Set the SPI partitions to access the chip addresses
67 *
68 * To simplify driver code, a fixed (virtual) memory map is defined for
69 * register and memory addresses. Because in the chipset, in different stages
70 * of operation, those addresses will move around, an address translation
71 * mechanism is required.
72 *
73 * There are four partitions (three memory and one register partition),
74 * which are mapped to two different areas of the hardware memory.
75 *
76 * Virtual address
77 * space
78 *
79 * | |
80 * ...+----+--> mem.start
81 * Physical address ... | |
82 * space ... | | [PART_0]
83 * ... | |
84 * 00000000 <--+----+... ...+----+--> mem.start + mem.size
85 * | | ... | |
86 * |MEM | ... | |
87 * | | ... | |
88 * mem.size <--+----+... | | {unused area)
89 * | | ... | |
90 * |REG | ... | |
91 * mem.size | | ... | |
92 * + <--+----+... ...+----+--> reg.start
93 * reg.size | | ... | |
94 * |MEM2| ... | | [PART_1]
95 * | | ... | |
96 * ...+----+--> reg.start + reg.size
97 * | |
98 *
99 */
100int wl1271_set_partition(struct wl1271 *wl,
101 struct wl1271_partition_set *p)
102{
103 /* copy partition info */
104 memcpy(&wl->part, p, sizeof(*p));
105
106 wl1271_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
107 p->mem.start, p->mem.size);
108 wl1271_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
109 p->reg.start, p->reg.size);
110 wl1271_debug(DEBUG_SPI, "mem2_start %08X mem2_size %08X",
111 p->mem2.start, p->mem2.size);
112 wl1271_debug(DEBUG_SPI, "mem3_start %08X mem3_size %08X",
113 p->mem3.start, p->mem3.size);
114
115 /* write partition info to the chipset */
116 wl1271_raw_write32(wl, HW_PART0_START_ADDR, p->mem.start);
117 wl1271_raw_write32(wl, HW_PART0_SIZE_ADDR, p->mem.size);
118 wl1271_raw_write32(wl, HW_PART1_START_ADDR, p->reg.start);
119 wl1271_raw_write32(wl, HW_PART1_SIZE_ADDR, p->reg.size);
120 wl1271_raw_write32(wl, HW_PART2_START_ADDR, p->mem2.start);
121 wl1271_raw_write32(wl, HW_PART2_SIZE_ADDR, p->mem2.size);
122 wl1271_raw_write32(wl, HW_PART3_START_ADDR, p->mem3.start);
123
124 return 0;
125}
Roger Quadros870c3672010-11-29 16:24:57 +0200126EXPORT_SYMBOL_GPL(wl1271_set_partition);
Teemu Paasikivi521a5b22010-02-18 13:25:54 +0200127
Teemu Paasikivi9b280722010-02-18 13:25:56 +0200128void wl1271_io_reset(struct wl1271 *wl)
129{
Teemu Paasikivi8197b712010-02-22 08:38:23 +0200130 wl->if_ops->reset(wl);
Teemu Paasikivi9b280722010-02-18 13:25:56 +0200131}
132
133void wl1271_io_init(struct wl1271 *wl)
134{
Teemu Paasikivi8197b712010-02-22 08:38:23 +0200135 wl->if_ops->init(wl);
Teemu Paasikivi9b280722010-02-18 13:25:56 +0200136}
137
Teemu Paasikivi521a5b22010-02-18 13:25:54 +0200138void wl1271_top_reg_write(struct wl1271 *wl, int addr, u16 val)
139{
140 /* write address >> 1 + 0x30000 to OCP_POR_CTR */
141 addr = (addr >> 1) + 0x30000;
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200142 wl1271_write32(wl, OCP_POR_CTR, addr);
Teemu Paasikivi521a5b22010-02-18 13:25:54 +0200143
144 /* write value to OCP_POR_WDATA */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200145 wl1271_write32(wl, OCP_DATA_WRITE, val);
Teemu Paasikivi521a5b22010-02-18 13:25:54 +0200146
147 /* write 1 to OCP_CMD */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200148 wl1271_write32(wl, OCP_CMD, OCP_CMD_WRITE);
Teemu Paasikivi521a5b22010-02-18 13:25:54 +0200149}
150
151u16 wl1271_top_reg_read(struct wl1271 *wl, int addr)
152{
153 u32 val;
154 int timeout = OCP_CMD_LOOP;
155
156 /* write address >> 1 + 0x30000 to OCP_POR_CTR */
157 addr = (addr >> 1) + 0x30000;
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200158 wl1271_write32(wl, OCP_POR_CTR, addr);
Teemu Paasikivi521a5b22010-02-18 13:25:54 +0200159
160 /* write 2 to OCP_CMD */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200161 wl1271_write32(wl, OCP_CMD, OCP_CMD_READ);
Teemu Paasikivi521a5b22010-02-18 13:25:54 +0200162
163 /* poll for data ready */
164 do {
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200165 val = wl1271_read32(wl, OCP_DATA_READ);
Teemu Paasikivi521a5b22010-02-18 13:25:54 +0200166 } while (!(val & OCP_READY_MASK) && --timeout);
167
168 if (!timeout) {
169 wl1271_warning("Top register access timed out.");
170 return 0xffff;
171 }
172
173 /* check data status and return if OK */
174 if ((val & OCP_STATUS_MASK) == OCP_STATUS_OK)
175 return val & 0xffff;
176 else {
177 wl1271_warning("Top register access returned error.");
178 return 0xffff;
179 }
180}
181