blob: 1fa26749af3286f81875b55cb58c3fbba2e8e3a6 [file] [log] [blame]
Bob Copeland0764de62009-08-07 13:32:56 +03001/*
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 "reg.h"
26#include "wl1251_io.h"
27
28static int wl1251_translate_reg_addr(struct wl1251 *wl, int addr)
29{
30 /* If the address is lower than REGISTERS_BASE, it means that this is
31 * a chip-specific register address, so look it up in the registers
32 * table */
33 if (addr < REGISTERS_BASE) {
34 /* Make sure we don't go over the table */
35 if (addr >= ACX_REG_TABLE_LEN) {
36 wl1251_error("address out of range (%d)", addr);
37 return -EINVAL;
38 }
39 addr = wl->chip.acx_reg_table[addr];
40 }
41
42 return addr - wl->physical_reg_addr + wl->virtual_reg_addr;
43}
44
45static int wl1251_translate_mem_addr(struct wl1251 *wl, int addr)
46{
47 return addr - wl->physical_mem_addr + wl->virtual_mem_addr;
48}
49
50void wl1251_mem_read(struct wl1251 *wl, int addr, void *buf, size_t len)
51{
52 int physical;
53
54 physical = wl1251_translate_mem_addr(wl, addr);
55
56 wl1251_spi_read(wl, physical, buf, len);
57}
58
59void wl1251_mem_write(struct wl1251 *wl, int addr, void *buf, size_t len)
60{
61 int physical;
62
63 physical = wl1251_translate_mem_addr(wl, addr);
64
65 wl1251_spi_write(wl, physical, buf, len);
66}
67
68u32 wl1251_mem_read32(struct wl1251 *wl, int addr)
69{
70 return wl1251_read32(wl, wl1251_translate_mem_addr(wl, addr));
71}
72
73void wl1251_mem_write32(struct wl1251 *wl, int addr, u32 val)
74{
75 wl1251_write32(wl, wl1251_translate_mem_addr(wl, addr), val);
76}
77
78u32 wl1251_reg_read32(struct wl1251 *wl, int addr)
79{
80 return wl1251_read32(wl, wl1251_translate_reg_addr(wl, addr));
81}
82
83void wl1251_reg_write32(struct wl1251 *wl, int addr, u32 val)
84{
85 wl1251_write32(wl, wl1251_translate_reg_addr(wl, addr), val);
86}