blob: 8501898950db83795b0ace67a3b9e6319ab6dc32 [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
25#ifndef __WL1271_IO_H__
26#define __WL1271_IO_H__
27
28struct wl1271;
29
Teemu Paasikivi54f7e502010-02-22 08:38:22 +020030void wl1271_disable_interrupts(struct wl1271 *wl);
31void wl1271_enable_interrupts(struct wl1271 *wl);
32
Teemu Paasikivi9b280722010-02-18 13:25:56 +020033void wl1271_io_reset(struct wl1271 *wl);
34void wl1271_io_init(struct wl1271 *wl);
Teemu Paasikivi521a5b22010-02-18 13:25:54 +020035
Teemu Paasikivib42f91b2010-02-22 08:38:24 +020036static inline struct device *wl1271_wl_to_dev(struct wl1271 *wl)
37{
38 return wl->if_ops->dev(wl);
39}
40
Teemu Paasikivi8197b712010-02-22 08:38:23 +020041
Teemu Paasikivi521a5b22010-02-18 13:25:54 +020042/* Raw target IO, address is not translated */
Teemu Paasikivib42f91b2010-02-22 08:38:24 +020043static inline void wl1271_raw_write(struct wl1271 *wl, int addr, void *buf,
44 size_t len, bool fixed)
45{
46 wl->if_ops->write(wl, addr, buf, len, fixed);
47}
Teemu Paasikivi521a5b22010-02-18 13:25:54 +020048
Teemu Paasikivib42f91b2010-02-22 08:38:24 +020049static inline void wl1271_raw_read(struct wl1271 *wl, int addr, void *buf,
50 size_t len, bool fixed)
51{
52 wl->if_ops->read(wl, addr, buf, len, fixed);
53}
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020054
55static inline u32 wl1271_raw_read32(struct wl1271 *wl, int addr)
56{
57 wl1271_raw_read(wl, addr, &wl->buffer_32,
58 sizeof(wl->buffer_32), false);
59
60 return wl->buffer_32;
61}
62
63static inline void wl1271_raw_write32(struct wl1271 *wl, int addr, u32 val)
64{
65 wl->buffer_32 = val;
66 wl1271_raw_write(wl, addr, &wl->buffer_32,
67 sizeof(wl->buffer_32), false);
68}
Teemu Paasikivi2d5e82b2010-02-22 08:38:21 +020069
Teemu Paasikivib42f91b2010-02-22 08:38:24 +020070/* Translated target IO */
71static inline int wl1271_translate_addr(struct wl1271 *wl, int addr)
72{
73 /*
74 * To translate, first check to which window of addresses the
75 * particular address belongs. Then subtract the starting address
76 * of that window from the address. Then, add offset of the
77 * translated region.
78 *
79 * The translated regions occur next to each other in physical device
80 * memory, so just add the sizes of the preceeding address regions to
81 * get the offset to the new region.
82 *
83 * Currently, only the two first regions are addressed, and the
84 * assumption is that all addresses will fall into either of those
85 * two.
86 */
87 if ((addr >= wl->part.reg.start) &&
88 (addr < wl->part.reg.start + wl->part.reg.size))
89 return addr - wl->part.reg.start + wl->part.mem.size;
90 else
91 return addr - wl->part.mem.start;
92}
93
94static inline void wl1271_read(struct wl1271 *wl, int addr, void *buf,
95 size_t len, bool fixed)
96{
97 int physical;
98
99 physical = wl1271_translate_addr(wl, addr);
100
101 wl1271_raw_read(wl, physical, buf, len, fixed);
102}
103
104static inline void wl1271_write(struct wl1271 *wl, int addr, void *buf,
105 size_t len, bool fixed)
106{
107 int physical;
108
109 physical = wl1271_translate_addr(wl, addr);
110
111 wl1271_raw_write(wl, physical, buf, len, fixed);
112}
113
114static inline u32 wl1271_read32(struct wl1271 *wl, int addr)
115{
116 return wl1271_raw_read32(wl, wl1271_translate_addr(wl, addr));
117}
118
119static inline void wl1271_write32(struct wl1271 *wl, int addr, u32 val)
120{
121 wl1271_raw_write32(wl, wl1271_translate_addr(wl, addr), val);
122}
123
124
125/* Top Register IO */
126void wl1271_top_reg_write(struct wl1271 *wl, int addr, u16 val);
127u16 wl1271_top_reg_read(struct wl1271 *wl, int addr);
128
129int wl1271_set_partition(struct wl1271 *wl,
130 struct wl1271_partition_set *p);
131
Teemu Paasikivi2d5e82b2010-02-22 08:38:21 +0200132/* Functions from wl1271_main.c */
133
134int wl1271_register_hw(struct wl1271 *wl);
135int wl1271_init_ieee80211(struct wl1271 *wl);
136struct ieee80211_hw *wl1271_alloc_hw(void);
137int wl1271_free_hw(struct wl1271 *wl);
138
Teemu Paasikivi521a5b22010-02-18 13:25:54 +0200139#endif