• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/components/opensource/linux/linux-2.6.36/drivers/net/wireless/wl12xx/
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (C) 2008 Nokia Corporation
5 *
6 * Contact: Kalle Valo <kalle.valo@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 "wl1251.h"
25#include "wl1251_reg.h"
26#include "wl1251_io.h"
27
28static 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)
40};
41
42static int wl1251_translate_reg_addr(struct wl1251 *wl, int addr)
43{
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;
52		}
53		addr = wl1251_io_reg_table[addr];
54	}
55
56	return addr - wl->physical_reg_addr + wl->virtual_reg_addr;
57}
58
59static int wl1251_translate_mem_addr(struct wl1251 *wl, int addr)
60{
61	return addr - wl->physical_mem_addr + wl->virtual_mem_addr;
62}
63
64void wl1251_mem_read(struct wl1251 *wl, int addr, void *buf, size_t len)
65{
66	int physical;
67
68	physical = wl1251_translate_mem_addr(wl, addr);
69
70	wl->if_ops->read(wl, physical, buf, len);
71}
72
73void wl1251_mem_write(struct wl1251 *wl, int addr, void *buf, size_t len)
74{
75	int physical;
76
77	physical = wl1251_translate_mem_addr(wl, addr);
78
79	wl->if_ops->write(wl, physical, buf, len);
80}
81
82u32 wl1251_mem_read32(struct wl1251 *wl, int addr)
83{
84	return wl1251_read32(wl, wl1251_translate_mem_addr(wl, addr));
85}
86
87void wl1251_mem_write32(struct wl1251 *wl, int addr, u32 val)
88{
89	wl1251_write32(wl, wl1251_translate_mem_addr(wl, addr), val);
90}
91
92u32 wl1251_reg_read32(struct wl1251 *wl, int addr)
93{
94	return wl1251_read32(wl, wl1251_translate_reg_addr(wl, addr));
95}
96
97void wl1251_reg_write32(struct wl1251 *wl, int addr, u32 val)
98{
99	wl1251_write32(wl, wl1251_translate_reg_addr(wl, addr), val);
100}
101
102/* Set the partitions to access the chip addresses.
103 *
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.
110 *
111 *                               PHYSICAL address
112 *                                     space
113 *
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 *                                    |    |
133 *
134 */
135void wl1251_set_partition(struct wl1251 *wl,
136			  u32 mem_start, u32 mem_size,
137			  u32 reg_start, u32 reg_size)
138{
139	struct wl1251_partition partition[2];
140
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);
145
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);
156	}
157
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);
180	}
181
182	partition[0].start = mem_start;
183	partition[0].size  = mem_size;
184	partition[1].start = reg_start;
185	partition[1].size  = reg_size;
186
187	wl->physical_mem_addr = mem_start;
188	wl->physical_reg_addr = reg_start;
189
190	wl->virtual_mem_addr = 0;
191	wl->virtual_reg_addr = mem_size;
192
193	wl->if_ops->write(wl, HW_ACCESS_PART0_SIZE_ADDR, partition,
194		sizeof(partition));
195}
196