blob: d398cbcea98677ae4b2c952b3077ed7d10c8920d [file] [log] [blame]
Teemu Paasikivi521a5b22010-02-18 13:25:54 +02001/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
5 * Copyright (C) 2008-2010 Nokia Corporation
6 *
7 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
Shahar Levi00d20102010-11-08 11:20:10 +000025#ifndef __IO_H__
26#define __IO_H__
Teemu Paasikivi521a5b22010-02-18 13:25:54 +020027
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000028#include <linux/irqreturn.h>
Shahar Levi00d20102010-11-08 11:20:10 +000029#include "reg.h"
Teemu Paasikivi760d9692010-02-22 08:38:25 +020030
31#define HW_ACCESS_MEMORY_MAX_RANGE 0x1FFC0
32
33#define HW_PARTITION_REGISTERS_ADDR 0x1FFC0
34#define HW_PART0_SIZE_ADDR (HW_PARTITION_REGISTERS_ADDR)
35#define HW_PART0_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 4)
36#define HW_PART1_SIZE_ADDR (HW_PARTITION_REGISTERS_ADDR + 8)
37#define HW_PART1_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 12)
38#define HW_PART2_SIZE_ADDR (HW_PARTITION_REGISTERS_ADDR + 16)
39#define HW_PART2_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 20)
40#define HW_PART3_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 24)
41
42#define HW_ACCESS_REGISTER_SIZE 4
43
44#define HW_ACCESS_PRAM_MAX_RANGE 0x3c000
45
Teemu Paasikivi521a5b22010-02-18 13:25:54 +020046struct wl1271;
47
Teemu Paasikivi54f7e502010-02-22 08:38:22 +020048void wl1271_disable_interrupts(struct wl1271 *wl);
49void wl1271_enable_interrupts(struct wl1271 *wl);
50
Teemu Paasikivi9b280722010-02-18 13:25:56 +020051void wl1271_io_reset(struct wl1271 *wl);
52void wl1271_io_init(struct wl1271 *wl);
Teemu Paasikivi521a5b22010-02-18 13:25:54 +020053
54/* Raw target IO, address is not translated */
Teemu Paasikivib42f91b2010-02-22 08:38:24 +020055static inline void wl1271_raw_write(struct wl1271 *wl, int addr, void *buf,
56 size_t len, bool fixed)
57{
Felipe Balbia390e852011-10-06 10:07:44 +030058 wl->if_ops->write(wl->dev, addr, buf, len, fixed);
Teemu Paasikivib42f91b2010-02-22 08:38:24 +020059}
Teemu Paasikivi521a5b22010-02-18 13:25:54 +020060
Teemu Paasikivib42f91b2010-02-22 08:38:24 +020061static inline void wl1271_raw_read(struct wl1271 *wl, int addr, void *buf,
62 size_t len, bool fixed)
63{
Felipe Balbia390e852011-10-06 10:07:44 +030064 wl->if_ops->read(wl->dev, addr, buf, len, fixed);
Teemu Paasikivib42f91b2010-02-22 08:38:24 +020065}
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020066
67static inline u32 wl1271_raw_read32(struct wl1271 *wl, int addr)
68{
69 wl1271_raw_read(wl, addr, &wl->buffer_32,
70 sizeof(wl->buffer_32), false);
71
Juuso Oikarinen554d7202010-05-07 11:38:59 +030072 return le32_to_cpu(wl->buffer_32);
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020073}
74
75static inline void wl1271_raw_write32(struct wl1271 *wl, int addr, u32 val)
76{
Juuso Oikarinen554d7202010-05-07 11:38:59 +030077 wl->buffer_32 = cpu_to_le32(val);
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020078 wl1271_raw_write(wl, addr, &wl->buffer_32,
79 sizeof(wl->buffer_32), false);
80}
Teemu Paasikivi2d5e82b2010-02-22 08:38:21 +020081
Teemu Paasikivib42f91b2010-02-22 08:38:24 +020082/* Translated target IO */
83static inline int wl1271_translate_addr(struct wl1271 *wl, int addr)
84{
85 /*
86 * To translate, first check to which window of addresses the
87 * particular address belongs. Then subtract the starting address
88 * of that window from the address. Then, add offset of the
89 * translated region.
90 *
91 * The translated regions occur next to each other in physical device
Lucas De Marchi25985ed2011-03-30 22:57:33 -030092 * memory, so just add the sizes of the preceding address regions to
Teemu Paasikivib42f91b2010-02-22 08:38:24 +020093 * get the offset to the new region.
94 *
95 * Currently, only the two first regions are addressed, and the
96 * assumption is that all addresses will fall into either of those
97 * two.
98 */
99 if ((addr >= wl->part.reg.start) &&
100 (addr < wl->part.reg.start + wl->part.reg.size))
101 return addr - wl->part.reg.start + wl->part.mem.size;
102 else
103 return addr - wl->part.mem.start;
104}
105
106static inline void wl1271_read(struct wl1271 *wl, int addr, void *buf,
107 size_t len, bool fixed)
108{
109 int physical;
110
111 physical = wl1271_translate_addr(wl, addr);
112
113 wl1271_raw_read(wl, physical, buf, len, fixed);
114}
115
116static inline void wl1271_write(struct wl1271 *wl, int addr, void *buf,
117 size_t len, bool fixed)
118{
119 int physical;
120
121 physical = wl1271_translate_addr(wl, addr);
122
123 wl1271_raw_write(wl, physical, buf, len, fixed);
124}
125
Ido Yariv95dac04f2011-06-06 14:57:06 +0300126static inline void wl1271_read_hwaddr(struct wl1271 *wl, int hwaddr,
127 void *buf, size_t len, bool fixed)
128{
129 int physical;
130 int addr;
131
132 /* Addresses are stored internally as addresses to 32 bytes blocks */
133 addr = hwaddr << 5;
134
135 physical = wl1271_translate_addr(wl, addr);
136
137 wl1271_raw_read(wl, physical, buf, len, fixed);
138}
139
Teemu Paasikivib42f91b2010-02-22 08:38:24 +0200140static inline u32 wl1271_read32(struct wl1271 *wl, int addr)
141{
142 return wl1271_raw_read32(wl, wl1271_translate_addr(wl, addr));
143}
144
145static inline void wl1271_write32(struct wl1271 *wl, int addr, u32 val)
146{
147 wl1271_raw_write32(wl, wl1271_translate_addr(wl, addr), val);
148}
149
Teemu Paasikivibecd5512010-03-18 12:26:27 +0200150static inline void wl1271_power_off(struct wl1271 *wl)
151{
Felipe Balbia390e852011-10-06 10:07:44 +0300152 wl->if_ops->power(wl->dev, false);
Teemu Paasikivibecd5512010-03-18 12:26:27 +0200153 clear_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
154}
155
Ohad Ben-Cohen2cc78ff2010-09-16 01:22:04 +0200156static inline int wl1271_power_on(struct wl1271 *wl)
Teemu Paasikivibecd5512010-03-18 12:26:27 +0200157{
Felipe Balbia390e852011-10-06 10:07:44 +0300158 int ret = wl->if_ops->power(wl->dev, true);
Ohad Ben-Cohen2cc78ff2010-09-16 01:22:04 +0200159 if (ret == 0)
160 set_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
161
162 return ret;
Teemu Paasikivibecd5512010-03-18 12:26:27 +0200163}
164
Teemu Paasikivib42f91b2010-02-22 08:38:24 +0200165
166/* Top Register IO */
167void wl1271_top_reg_write(struct wl1271 *wl, int addr, u16 val);
168u16 wl1271_top_reg_read(struct wl1271 *wl, int addr);
169
170int wl1271_set_partition(struct wl1271 *wl,
171 struct wl1271_partition_set *p);
172
Felipe Balbi4b32a2c2011-10-06 10:46:20 +0300173bool wl1271_set_block_size(struct wl1271 *wl);
174
Teemu Paasikivi2d5e82b2010-02-22 08:38:21 +0200175/* Functions from wl1271_main.c */
176
Shahar Leviae47c452011-03-06 16:32:14 +0200177int wl1271_tx_dummy_packet(struct wl1271 *wl);
Teemu Paasikivi2d5e82b2010-02-22 08:38:21 +0200178
Teemu Paasikivi521a5b22010-02-18 13:25:54 +0200179#endif