Linux Audio

Check our new training course

Loading...
v6.8
  1/* SPDX-License-Identifier: GPL-2.0-only */
  2/*
  3 * This file is part of wl1271
  4 *
  5 * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
  6 * Copyright (C) 2008-2010 Nokia Corporation
  7 *
  8 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  9 */
 10
 11#ifndef __IO_H__
 12#define __IO_H__
 13
 14#include <linux/irqreturn.h>
 15
 16#define HW_ACCESS_MEMORY_MAX_RANGE	0x1FFC0
 17
 18#define HW_PARTITION_REGISTERS_ADDR     0x1FFC0
 19#define HW_PART0_SIZE_ADDR              (HW_PARTITION_REGISTERS_ADDR)
 20#define HW_PART0_START_ADDR             (HW_PARTITION_REGISTERS_ADDR + 4)
 21#define HW_PART1_SIZE_ADDR              (HW_PARTITION_REGISTERS_ADDR + 8)
 22#define HW_PART1_START_ADDR             (HW_PARTITION_REGISTERS_ADDR + 12)
 23#define HW_PART2_SIZE_ADDR              (HW_PARTITION_REGISTERS_ADDR + 16)
 24#define HW_PART2_START_ADDR             (HW_PARTITION_REGISTERS_ADDR + 20)
 25#define HW_PART3_SIZE_ADDR              (HW_PARTITION_REGISTERS_ADDR + 24)
 26#define HW_PART3_START_ADDR             (HW_PARTITION_REGISTERS_ADDR + 28)
 27
 28#define HW_ACCESS_REGISTER_SIZE         4
 29
 30#define HW_ACCESS_PRAM_MAX_RANGE	0x3c000
 31
 32struct wl1271;
 33
 34void wlcore_disable_interrupts(struct wl1271 *wl);
 35void wlcore_disable_interrupts_nosync(struct wl1271 *wl);
 36void wlcore_enable_interrupts(struct wl1271 *wl);
 37void wlcore_synchronize_interrupts(struct wl1271 *wl);
 38
 39void wl1271_io_reset(struct wl1271 *wl);
 40void wl1271_io_init(struct wl1271 *wl);
 41int wlcore_translate_addr(struct wl1271 *wl, int addr);
 42
 43/* Raw target IO, address is not translated */
 44static inline int __must_check wlcore_raw_write(struct wl1271 *wl, int addr,
 45						void *buf, size_t len,
 46						bool fixed)
 47{
 48	int ret;
 49
 50	if (test_bit(WL1271_FLAG_IO_FAILED, &wl->flags) ||
 51	    WARN_ON((test_bit(WL1271_FLAG_IN_ELP, &wl->flags) &&
 52		     addr != HW_ACCESS_ELP_CTRL_REG)))
 53		return -EIO;
 54
 55	ret = wl->if_ops->write(wl->dev, addr, buf, len, fixed);
 56	if (ret && wl->state != WLCORE_STATE_OFF)
 57		set_bit(WL1271_FLAG_IO_FAILED, &wl->flags);
 58
 59	return ret;
 60}
 61
 62static inline int __must_check wlcore_raw_read(struct wl1271 *wl, int addr,
 63					       void *buf, size_t len,
 64					       bool fixed)
 65{
 66	int ret;
 67
 68	if (test_bit(WL1271_FLAG_IO_FAILED, &wl->flags) ||
 69	    WARN_ON((test_bit(WL1271_FLAG_IN_ELP, &wl->flags) &&
 70		     addr != HW_ACCESS_ELP_CTRL_REG)))
 71		return -EIO;
 72
 73	ret = wl->if_ops->read(wl->dev, addr, buf, len, fixed);
 74	if (ret && wl->state != WLCORE_STATE_OFF)
 75		set_bit(WL1271_FLAG_IO_FAILED, &wl->flags);
 76
 77	return ret;
 78}
 79
 80static inline int __must_check wlcore_raw_read_data(struct wl1271 *wl, int reg,
 81						    void *buf, size_t len,
 82						    bool fixed)
 83{
 84	return wlcore_raw_read(wl, wl->rtable[reg], buf, len, fixed);
 85}
 86
 87static inline int __must_check wlcore_raw_write_data(struct wl1271 *wl, int reg,
 88						     void *buf, size_t len,
 89						     bool fixed)
 90{
 91	return wlcore_raw_write(wl, wl->rtable[reg], buf, len, fixed);
 92}
 93
 94static inline int __must_check wlcore_raw_read32(struct wl1271 *wl, int addr,
 95						 u32 *val)
 96{
 97	int ret;
 98
 99	ret = wlcore_raw_read(wl, addr, wl->buffer_32,
100			      sizeof(*wl->buffer_32), false);
101	if (ret < 0)
102		return ret;
103
104	if (val)
105		*val = le32_to_cpu(*wl->buffer_32);
106
107	return 0;
108}
109
110static inline int __must_check wlcore_raw_write32(struct wl1271 *wl, int addr,
111						  u32 val)
112{
113	*wl->buffer_32 = cpu_to_le32(val);
114	return wlcore_raw_write(wl, addr, wl->buffer_32,
115				sizeof(*wl->buffer_32), false);
116}
117
118static inline int __must_check wlcore_read(struct wl1271 *wl, int addr,
119					   void *buf, size_t len, bool fixed)
120{
121	int physical;
122
123	physical = wlcore_translate_addr(wl, addr);
124
125	return wlcore_raw_read(wl, physical, buf, len, fixed);
126}
127
128static inline int __must_check wlcore_write(struct wl1271 *wl, int addr,
129					    void *buf, size_t len, bool fixed)
130{
131	int physical;
132
133	physical = wlcore_translate_addr(wl, addr);
134
135	return wlcore_raw_write(wl, physical, buf, len, fixed);
136}
137
138static inline int __must_check wlcore_write_data(struct wl1271 *wl, int reg,
139						 void *buf, size_t len,
140						 bool fixed)
141{
142	return wlcore_write(wl, wl->rtable[reg], buf, len, fixed);
143}
144
145static inline int __must_check wlcore_read_data(struct wl1271 *wl, int reg,
146						void *buf, size_t len,
147						bool fixed)
148{
149	return wlcore_read(wl, wl->rtable[reg], buf, len, fixed);
150}
151
152static inline int __must_check wlcore_read_hwaddr(struct wl1271 *wl, int hwaddr,
153						  void *buf, size_t len,
154						  bool fixed)
155{
156	int physical;
157	int addr;
158
159	/* Convert from FW internal address which is chip arch dependent */
160	addr = wl->ops->convert_hwaddr(wl, hwaddr);
161
162	physical = wlcore_translate_addr(wl, addr);
163
164	return wlcore_raw_read(wl, physical, buf, len, fixed);
165}
166
167static inline int __must_check wlcore_read32(struct wl1271 *wl, int addr,
168					     u32 *val)
169{
170	return wlcore_raw_read32(wl, wlcore_translate_addr(wl, addr), val);
171}
172
173static inline int __must_check wlcore_write32(struct wl1271 *wl, int addr,
174					      u32 val)
175{
176	return wlcore_raw_write32(wl, wlcore_translate_addr(wl, addr), val);
177}
178
179static inline int __must_check wlcore_read_reg(struct wl1271 *wl, int reg,
180					       u32 *val)
181{
182	return wlcore_raw_read32(wl,
183				 wlcore_translate_addr(wl, wl->rtable[reg]),
184				 val);
185}
186
187static inline int __must_check wlcore_write_reg(struct wl1271 *wl, int reg,
188						u32 val)
189{
190	return wlcore_raw_write32(wl,
191				  wlcore_translate_addr(wl, wl->rtable[reg]),
192				  val);
193}
194
195static inline void wl1271_power_off(struct wl1271 *wl)
196{
197	int ret = 0;
198
199	if (!test_bit(WL1271_FLAG_GPIO_POWER, &wl->flags))
200		return;
201
202	if (wl->if_ops->power)
203		ret = wl->if_ops->power(wl->dev, false);
204	if (!ret)
205		clear_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
206}
207
208static inline int wl1271_power_on(struct wl1271 *wl)
209{
210	int ret = 0;
211
212	if (wl->if_ops->power)
213		ret = wl->if_ops->power(wl->dev, true);
214	if (ret == 0)
215		set_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
216
217	return ret;
218}
219
220int wlcore_set_partition(struct wl1271 *wl,
221			 const struct wlcore_partition_set *p);
222
223bool wl1271_set_block_size(struct wl1271 *wl);
224
225/* Functions from wl1271_main.c */
226
227int wl1271_tx_dummy_packet(struct wl1271 *wl);
228
229#endif
v4.10.11
 
  1/*
  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 __IO_H__
 26#define __IO_H__
 27
 28#include <linux/irqreturn.h>
 29
 30#define HW_ACCESS_MEMORY_MAX_RANGE	0x1FFC0
 31
 32#define HW_PARTITION_REGISTERS_ADDR     0x1FFC0
 33#define HW_PART0_SIZE_ADDR              (HW_PARTITION_REGISTERS_ADDR)
 34#define HW_PART0_START_ADDR             (HW_PARTITION_REGISTERS_ADDR + 4)
 35#define HW_PART1_SIZE_ADDR              (HW_PARTITION_REGISTERS_ADDR + 8)
 36#define HW_PART1_START_ADDR             (HW_PARTITION_REGISTERS_ADDR + 12)
 37#define HW_PART2_SIZE_ADDR              (HW_PARTITION_REGISTERS_ADDR + 16)
 38#define HW_PART2_START_ADDR             (HW_PARTITION_REGISTERS_ADDR + 20)
 39#define HW_PART3_SIZE_ADDR              (HW_PARTITION_REGISTERS_ADDR + 24)
 40#define HW_PART3_START_ADDR             (HW_PARTITION_REGISTERS_ADDR + 28)
 41
 42#define HW_ACCESS_REGISTER_SIZE         4
 43
 44#define HW_ACCESS_PRAM_MAX_RANGE	0x3c000
 45
 46struct wl1271;
 47
 48void wlcore_disable_interrupts(struct wl1271 *wl);
 49void wlcore_disable_interrupts_nosync(struct wl1271 *wl);
 50void wlcore_enable_interrupts(struct wl1271 *wl);
 51void wlcore_synchronize_interrupts(struct wl1271 *wl);
 52
 53void wl1271_io_reset(struct wl1271 *wl);
 54void wl1271_io_init(struct wl1271 *wl);
 55int wlcore_translate_addr(struct wl1271 *wl, int addr);
 56
 57/* Raw target IO, address is not translated */
 58static inline int __must_check wlcore_raw_write(struct wl1271 *wl, int addr,
 59						void *buf, size_t len,
 60						bool fixed)
 61{
 62	int ret;
 63
 64	if (test_bit(WL1271_FLAG_IO_FAILED, &wl->flags) ||
 65	    WARN_ON((test_bit(WL1271_FLAG_IN_ELP, &wl->flags) &&
 66		     addr != HW_ACCESS_ELP_CTRL_REG)))
 67		return -EIO;
 68
 69	ret = wl->if_ops->write(wl->dev, addr, buf, len, fixed);
 70	if (ret && wl->state != WLCORE_STATE_OFF)
 71		set_bit(WL1271_FLAG_IO_FAILED, &wl->flags);
 72
 73	return ret;
 74}
 75
 76static inline int __must_check wlcore_raw_read(struct wl1271 *wl, int addr,
 77					       void *buf, size_t len,
 78					       bool fixed)
 79{
 80	int ret;
 81
 82	if (test_bit(WL1271_FLAG_IO_FAILED, &wl->flags) ||
 83	    WARN_ON((test_bit(WL1271_FLAG_IN_ELP, &wl->flags) &&
 84		     addr != HW_ACCESS_ELP_CTRL_REG)))
 85		return -EIO;
 86
 87	ret = wl->if_ops->read(wl->dev, addr, buf, len, fixed);
 88	if (ret && wl->state != WLCORE_STATE_OFF)
 89		set_bit(WL1271_FLAG_IO_FAILED, &wl->flags);
 90
 91	return ret;
 92}
 93
 94static inline int __must_check wlcore_raw_read_data(struct wl1271 *wl, int reg,
 95						    void *buf, size_t len,
 96						    bool fixed)
 97{
 98	return wlcore_raw_read(wl, wl->rtable[reg], buf, len, fixed);
 99}
100
101static inline int __must_check wlcore_raw_write_data(struct wl1271 *wl, int reg,
102						     void *buf, size_t len,
103						     bool fixed)
104{
105	return wlcore_raw_write(wl, wl->rtable[reg], buf, len, fixed);
106}
107
108static inline int __must_check wlcore_raw_read32(struct wl1271 *wl, int addr,
109						 u32 *val)
110{
111	int ret;
112
113	ret = wlcore_raw_read(wl, addr, wl->buffer_32,
114			      sizeof(*wl->buffer_32), false);
115	if (ret < 0)
116		return ret;
117
118	if (val)
119		*val = le32_to_cpu(*wl->buffer_32);
120
121	return 0;
122}
123
124static inline int __must_check wlcore_raw_write32(struct wl1271 *wl, int addr,
125						  u32 val)
126{
127	*wl->buffer_32 = cpu_to_le32(val);
128	return wlcore_raw_write(wl, addr, wl->buffer_32,
129				sizeof(*wl->buffer_32), false);
130}
131
132static inline int __must_check wlcore_read(struct wl1271 *wl, int addr,
133					   void *buf, size_t len, bool fixed)
134{
135	int physical;
136
137	physical = wlcore_translate_addr(wl, addr);
138
139	return wlcore_raw_read(wl, physical, buf, len, fixed);
140}
141
142static inline int __must_check wlcore_write(struct wl1271 *wl, int addr,
143					    void *buf, size_t len, bool fixed)
144{
145	int physical;
146
147	physical = wlcore_translate_addr(wl, addr);
148
149	return wlcore_raw_write(wl, physical, buf, len, fixed);
150}
151
152static inline int __must_check wlcore_write_data(struct wl1271 *wl, int reg,
153						 void *buf, size_t len,
154						 bool fixed)
155{
156	return wlcore_write(wl, wl->rtable[reg], buf, len, fixed);
157}
158
159static inline int __must_check wlcore_read_data(struct wl1271 *wl, int reg,
160						void *buf, size_t len,
161						bool fixed)
162{
163	return wlcore_read(wl, wl->rtable[reg], buf, len, fixed);
164}
165
166static inline int __must_check wlcore_read_hwaddr(struct wl1271 *wl, int hwaddr,
167						  void *buf, size_t len,
168						  bool fixed)
169{
170	int physical;
171	int addr;
172
173	/* Convert from FW internal address which is chip arch dependent */
174	addr = wl->ops->convert_hwaddr(wl, hwaddr);
175
176	physical = wlcore_translate_addr(wl, addr);
177
178	return wlcore_raw_read(wl, physical, buf, len, fixed);
179}
180
181static inline int __must_check wlcore_read32(struct wl1271 *wl, int addr,
182					     u32 *val)
183{
184	return wlcore_raw_read32(wl, wlcore_translate_addr(wl, addr), val);
185}
186
187static inline int __must_check wlcore_write32(struct wl1271 *wl, int addr,
188					      u32 val)
189{
190	return wlcore_raw_write32(wl, wlcore_translate_addr(wl, addr), val);
191}
192
193static inline int __must_check wlcore_read_reg(struct wl1271 *wl, int reg,
194					       u32 *val)
195{
196	return wlcore_raw_read32(wl,
197				 wlcore_translate_addr(wl, wl->rtable[reg]),
198				 val);
199}
200
201static inline int __must_check wlcore_write_reg(struct wl1271 *wl, int reg,
202						u32 val)
203{
204	return wlcore_raw_write32(wl,
205				  wlcore_translate_addr(wl, wl->rtable[reg]),
206				  val);
207}
208
209static inline void wl1271_power_off(struct wl1271 *wl)
210{
211	int ret = 0;
212
213	if (!test_bit(WL1271_FLAG_GPIO_POWER, &wl->flags))
214		return;
215
216	if (wl->if_ops->power)
217		ret = wl->if_ops->power(wl->dev, false);
218	if (!ret)
219		clear_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
220}
221
222static inline int wl1271_power_on(struct wl1271 *wl)
223{
224	int ret = 0;
225
226	if (wl->if_ops->power)
227		ret = wl->if_ops->power(wl->dev, true);
228	if (ret == 0)
229		set_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
230
231	return ret;
232}
233
234int wlcore_set_partition(struct wl1271 *wl,
235			 const struct wlcore_partition_set *p);
236
237bool wl1271_set_block_size(struct wl1271 *wl);
238
239/* Functions from wl1271_main.c */
240
241int wl1271_tx_dummy_packet(struct wl1271 *wl);
242
243#endif