blob: a2fe4f506adaf88335b47c5806507ca3a7310b91 [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
Teemu Paasikivib42f91b2010-02-22 08:38:24 +020054static inline struct device *wl1271_wl_to_dev(struct wl1271 *wl)
55{
56 return wl->if_ops->dev(wl);
57}
58
Teemu Paasikivi8197b712010-02-22 08:38:23 +020059
Teemu Paasikivi521a5b22010-02-18 13:25:54 +020060/* Raw target IO, address is not translated */
Teemu Paasikivib42f91b2010-02-22 08:38:24 +020061static inline void wl1271_raw_write(struct wl1271 *wl, int addr, void *buf,
62 size_t len, bool fixed)
63{
64 wl->if_ops->write(wl, addr, buf, len, fixed);
65}
Teemu Paasikivi521a5b22010-02-18 13:25:54 +020066
Teemu Paasikivib42f91b2010-02-22 08:38:24 +020067static inline void wl1271_raw_read(struct wl1271 *wl, int addr, void *buf,
68 size_t len, bool fixed)
69{
70 wl->if_ops->read(wl, addr, buf, len, fixed);
71}
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020072
73static inline u32 wl1271_raw_read32(struct wl1271 *wl, int addr)
74{
75 wl1271_raw_read(wl, addr, &wl->buffer_32,
76 sizeof(wl->buffer_32), false);
77
Juuso Oikarinen554d7202010-05-07 11:38:59 +030078 return le32_to_cpu(wl->buffer_32);
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020079}
80
81static inline void wl1271_raw_write32(struct wl1271 *wl, int addr, u32 val)
82{
Juuso Oikarinen554d7202010-05-07 11:38:59 +030083 wl->buffer_32 = cpu_to_le32(val);
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020084 wl1271_raw_write(wl, addr, &wl->buffer_32,
85 sizeof(wl->buffer_32), false);
86}
Teemu Paasikivi2d5e82b2010-02-22 08:38:21 +020087
Teemu Paasikivib42f91b2010-02-22 08:38:24 +020088/* Translated target IO */
89static inline int wl1271_translate_addr(struct wl1271 *wl, int addr)
90{
91 /*
92 * To translate, first check to which window of addresses the
93 * particular address belongs. Then subtract the starting address
94 * of that window from the address. Then, add offset of the
95 * translated region.
96 *
97 * The translated regions occur next to each other in physical device
Lucas De Marchi25985ed2011-03-30 22:57:33 -030098 * memory, so just add the sizes of the preceding address regions to
Teemu Paasikivib42f91b2010-02-22 08:38:24 +020099 * get the offset to the new region.
100 *
101 * Currently, only the two first regions are addressed, and the
102 * assumption is that all addresses will fall into either of those
103 * two.
104 */
105 if ((addr >= wl->part.reg.start) &&
106 (addr < wl->part.reg.start + wl->part.reg.size))
107 return addr - wl->part.reg.start + wl->part.mem.size;
108 else
109 return addr - wl->part.mem.start;
110}
111
112static inline void wl1271_read(struct wl1271 *wl, int addr, void *buf,
113 size_t len, bool fixed)
114{
115 int physical;
116
117 physical = wl1271_translate_addr(wl, addr);
118
119 wl1271_raw_read(wl, physical, buf, len, fixed);
120}
121
122static inline void wl1271_write(struct wl1271 *wl, int addr, void *buf,
123 size_t len, bool fixed)
124{
125 int physical;
126
127 physical = wl1271_translate_addr(wl, addr);
128
129 wl1271_raw_write(wl, physical, buf, len, fixed);
130}
131
Ido Yariv95dac04f2011-06-06 14:57:06 +0300132static inline void wl1271_read_hwaddr(struct wl1271 *wl, int hwaddr,
133 void *buf, size_t len, bool fixed)
134{
135 int physical;
136 int addr;
137
138 /* Addresses are stored internally as addresses to 32 bytes blocks */
139 addr = hwaddr << 5;
140
141 physical = wl1271_translate_addr(wl, addr);
142
143 wl1271_raw_read(wl, physical, buf, len, fixed);
144}
145
Teemu Paasikivib42f91b2010-02-22 08:38:24 +0200146static inline u32 wl1271_read32(struct wl1271 *wl, int addr)
147{
148 return wl1271_raw_read32(wl, wl1271_translate_addr(wl, addr));
149}
150
151static inline void wl1271_write32(struct wl1271 *wl, int addr, u32 val)
152{
153 wl1271_raw_write32(wl, wl1271_translate_addr(wl, addr), val);
154}
155
Teemu Paasikivibecd5512010-03-18 12:26:27 +0200156static inline void wl1271_power_off(struct wl1271 *wl)
157{
158 wl->if_ops->power(wl, false);
159 clear_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
160}
161
Ohad Ben-Cohen2cc78ff2010-09-16 01:22:04 +0200162static inline int wl1271_power_on(struct wl1271 *wl)
Teemu Paasikivibecd5512010-03-18 12:26:27 +0200163{
Ohad Ben-Cohen2cc78ff2010-09-16 01:22:04 +0200164 int ret = wl->if_ops->power(wl, true);
165 if (ret == 0)
166 set_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
167
168 return ret;
Teemu Paasikivibecd5512010-03-18 12:26:27 +0200169}
170
Teemu Paasikivib42f91b2010-02-22 08:38:24 +0200171
172/* Top Register IO */
173void wl1271_top_reg_write(struct wl1271 *wl, int addr, u16 val);
174u16 wl1271_top_reg_read(struct wl1271 *wl, int addr);
175
176int wl1271_set_partition(struct wl1271 *wl,
177 struct wl1271_partition_set *p);
178
Teemu Paasikivi2d5e82b2010-02-22 08:38:21 +0200179/* Functions from wl1271_main.c */
180
181int wl1271_register_hw(struct wl1271 *wl);
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +0200182void wl1271_unregister_hw(struct wl1271 *wl);
Teemu Paasikivi2d5e82b2010-02-22 08:38:21 +0200183int wl1271_init_ieee80211(struct wl1271 *wl);
184struct ieee80211_hw *wl1271_alloc_hw(void);
185int wl1271_free_hw(struct wl1271 *wl);
Ido Yariva6208652011-03-01 15:14:41 +0200186irqreturn_t wl1271_irq(int irq, void *data);
Shahar Levi48a61472011-03-06 16:32:08 +0200187bool wl1271_set_block_size(struct wl1271 *wl);
Shahar Leviae47c452011-03-06 16:32:14 +0200188int wl1271_tx_dummy_packet(struct wl1271 *wl);
Ohad Ben-Cohenc5745182011-03-30 16:35:59 +0200189void wl1271_configure_filters(struct wl1271 *wl, unsigned int filters);
Teemu Paasikivi2d5e82b2010-02-22 08:38:21 +0200190
Teemu Paasikivi521a5b22010-02-18 13:25:54 +0200191#endif