gpio: rcar: Fix runtime PM imbalance on error
[linux/fpc-iii.git] / drivers / net / wireless / ti / wlcore / io.h
blobe0b54a34762b97edf723b1b8a4cb53aec88f12b3
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * This file is part of wl1271
5 * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
6 * Copyright (C) 2008-2010 Nokia Corporation
8 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
9 */
11 #ifndef __IO_H__
12 #define __IO_H__
14 #include <linux/irqreturn.h>
16 #define HW_ACCESS_MEMORY_MAX_RANGE 0x1FFC0
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)
28 #define HW_ACCESS_REGISTER_SIZE 4
30 #define HW_ACCESS_PRAM_MAX_RANGE 0x3c000
32 struct wl1271;
34 void wlcore_disable_interrupts(struct wl1271 *wl);
35 void wlcore_disable_interrupts_nosync(struct wl1271 *wl);
36 void wlcore_enable_interrupts(struct wl1271 *wl);
37 void wlcore_synchronize_interrupts(struct wl1271 *wl);
39 void wl1271_io_reset(struct wl1271 *wl);
40 void wl1271_io_init(struct wl1271 *wl);
41 int wlcore_translate_addr(struct wl1271 *wl, int addr);
43 /* Raw target IO, address is not translated */
44 static inline int __must_check wlcore_raw_write(struct wl1271 *wl, int addr,
45 void *buf, size_t len,
46 bool fixed)
48 int ret;
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;
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);
59 return ret;
62 static inline int __must_check wlcore_raw_read(struct wl1271 *wl, int addr,
63 void *buf, size_t len,
64 bool fixed)
66 int ret;
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;
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);
77 return ret;
80 static inline int __must_check wlcore_raw_read_data(struct wl1271 *wl, int reg,
81 void *buf, size_t len,
82 bool fixed)
84 return wlcore_raw_read(wl, wl->rtable[reg], buf, len, fixed);
87 static inline int __must_check wlcore_raw_write_data(struct wl1271 *wl, int reg,
88 void *buf, size_t len,
89 bool fixed)
91 return wlcore_raw_write(wl, wl->rtable[reg], buf, len, fixed);
94 static inline int __must_check wlcore_raw_read32(struct wl1271 *wl, int addr,
95 u32 *val)
97 int ret;
99 ret = wlcore_raw_read(wl, addr, wl->buffer_32,
100 sizeof(*wl->buffer_32), false);
101 if (ret < 0)
102 return ret;
104 if (val)
105 *val = le32_to_cpu(*wl->buffer_32);
107 return 0;
110 static inline int __must_check wlcore_raw_write32(struct wl1271 *wl, int addr,
111 u32 val)
113 *wl->buffer_32 = cpu_to_le32(val);
114 return wlcore_raw_write(wl, addr, wl->buffer_32,
115 sizeof(*wl->buffer_32), false);
118 static inline int __must_check wlcore_read(struct wl1271 *wl, int addr,
119 void *buf, size_t len, bool fixed)
121 int physical;
123 physical = wlcore_translate_addr(wl, addr);
125 return wlcore_raw_read(wl, physical, buf, len, fixed);
128 static inline int __must_check wlcore_write(struct wl1271 *wl, int addr,
129 void *buf, size_t len, bool fixed)
131 int physical;
133 physical = wlcore_translate_addr(wl, addr);
135 return wlcore_raw_write(wl, physical, buf, len, fixed);
138 static inline int __must_check wlcore_write_data(struct wl1271 *wl, int reg,
139 void *buf, size_t len,
140 bool fixed)
142 return wlcore_write(wl, wl->rtable[reg], buf, len, fixed);
145 static inline int __must_check wlcore_read_data(struct wl1271 *wl, int reg,
146 void *buf, size_t len,
147 bool fixed)
149 return wlcore_read(wl, wl->rtable[reg], buf, len, fixed);
152 static inline int __must_check wlcore_read_hwaddr(struct wl1271 *wl, int hwaddr,
153 void *buf, size_t len,
154 bool fixed)
156 int physical;
157 int addr;
159 /* Convert from FW internal address which is chip arch dependent */
160 addr = wl->ops->convert_hwaddr(wl, hwaddr);
162 physical = wlcore_translate_addr(wl, addr);
164 return wlcore_raw_read(wl, physical, buf, len, fixed);
167 static inline int __must_check wlcore_read32(struct wl1271 *wl, int addr,
168 u32 *val)
170 return wlcore_raw_read32(wl, wlcore_translate_addr(wl, addr), val);
173 static inline int __must_check wlcore_write32(struct wl1271 *wl, int addr,
174 u32 val)
176 return wlcore_raw_write32(wl, wlcore_translate_addr(wl, addr), val);
179 static inline int __must_check wlcore_read_reg(struct wl1271 *wl, int reg,
180 u32 *val)
182 return wlcore_raw_read32(wl,
183 wlcore_translate_addr(wl, wl->rtable[reg]),
184 val);
187 static inline int __must_check wlcore_write_reg(struct wl1271 *wl, int reg,
188 u32 val)
190 return wlcore_raw_write32(wl,
191 wlcore_translate_addr(wl, wl->rtable[reg]),
192 val);
195 static inline void wl1271_power_off(struct wl1271 *wl)
197 int ret = 0;
199 if (!test_bit(WL1271_FLAG_GPIO_POWER, &wl->flags))
200 return;
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);
208 static inline int wl1271_power_on(struct wl1271 *wl)
210 int ret = 0;
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);
217 return ret;
220 int wlcore_set_partition(struct wl1271 *wl,
221 const struct wlcore_partition_set *p);
223 bool wl1271_set_block_size(struct wl1271 *wl);
225 /* Functions from wl1271_main.c */
227 int wl1271_tx_dummy_packet(struct wl1271 *wl);
229 #endif