gpio: rcar: Fix runtime PM imbalance on error
[linux/fpc-iii.git] / drivers / net / wireless / realtek / rtw88 / hci.h
blob2cba327e6218f171e103ac664c769d262ea9ae0c
1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /* Copyright(c) 2018-2019 Realtek Corporation
3 */
5 #ifndef __RTW_HCI_H__
6 #define __RTW_HCI_H__
8 /* ops for PCI, USB and SDIO */
9 struct rtw_hci_ops {
10 int (*tx_write)(struct rtw_dev *rtwdev,
11 struct rtw_tx_pkt_info *pkt_info,
12 struct sk_buff *skb);
13 void (*tx_kick_off)(struct rtw_dev *rtwdev);
14 int (*setup)(struct rtw_dev *rtwdev);
15 int (*start)(struct rtw_dev *rtwdev);
16 void (*stop)(struct rtw_dev *rtwdev);
17 void (*deep_ps)(struct rtw_dev *rtwdev, bool enter);
18 void (*link_ps)(struct rtw_dev *rtwdev, bool enter);
19 void (*interface_cfg)(struct rtw_dev *rtwdev);
21 int (*write_data_rsvd_page)(struct rtw_dev *rtwdev, u8 *buf, u32 size);
22 int (*write_data_h2c)(struct rtw_dev *rtwdev, u8 *buf, u32 size);
24 u8 (*read8)(struct rtw_dev *rtwdev, u32 addr);
25 u16 (*read16)(struct rtw_dev *rtwdev, u32 addr);
26 u32 (*read32)(struct rtw_dev *rtwdev, u32 addr);
27 void (*write8)(struct rtw_dev *rtwdev, u32 addr, u8 val);
28 void (*write16)(struct rtw_dev *rtwdev, u32 addr, u16 val);
29 void (*write32)(struct rtw_dev *rtwdev, u32 addr, u32 val);
32 static inline int rtw_hci_tx_write(struct rtw_dev *rtwdev,
33 struct rtw_tx_pkt_info *pkt_info,
34 struct sk_buff *skb)
36 return rtwdev->hci.ops->tx_write(rtwdev, pkt_info, skb);
39 static inline void rtw_hci_tx_kick_off(struct rtw_dev *rtwdev)
41 return rtwdev->hci.ops->tx_kick_off(rtwdev);
44 static inline int rtw_hci_setup(struct rtw_dev *rtwdev)
46 return rtwdev->hci.ops->setup(rtwdev);
49 static inline int rtw_hci_start(struct rtw_dev *rtwdev)
51 return rtwdev->hci.ops->start(rtwdev);
54 static inline void rtw_hci_stop(struct rtw_dev *rtwdev)
56 rtwdev->hci.ops->stop(rtwdev);
59 static inline void rtw_hci_deep_ps(struct rtw_dev *rtwdev, bool enter)
61 rtwdev->hci.ops->deep_ps(rtwdev, enter);
64 static inline void rtw_hci_link_ps(struct rtw_dev *rtwdev, bool enter)
66 rtwdev->hci.ops->link_ps(rtwdev, enter);
69 static inline void rtw_hci_interface_cfg(struct rtw_dev *rtwdev)
71 rtwdev->hci.ops->interface_cfg(rtwdev);
74 static inline int
75 rtw_hci_write_data_rsvd_page(struct rtw_dev *rtwdev, u8 *buf, u32 size)
77 return rtwdev->hci.ops->write_data_rsvd_page(rtwdev, buf, size);
80 static inline int
81 rtw_hci_write_data_h2c(struct rtw_dev *rtwdev, u8 *buf, u32 size)
83 return rtwdev->hci.ops->write_data_h2c(rtwdev, buf, size);
86 static inline u8 rtw_read8(struct rtw_dev *rtwdev, u32 addr)
88 return rtwdev->hci.ops->read8(rtwdev, addr);
91 static inline u16 rtw_read16(struct rtw_dev *rtwdev, u32 addr)
93 return rtwdev->hci.ops->read16(rtwdev, addr);
96 static inline u32 rtw_read32(struct rtw_dev *rtwdev, u32 addr)
98 return rtwdev->hci.ops->read32(rtwdev, addr);
101 static inline void rtw_write8(struct rtw_dev *rtwdev, u32 addr, u8 val)
103 rtwdev->hci.ops->write8(rtwdev, addr, val);
106 static inline void rtw_write16(struct rtw_dev *rtwdev, u32 addr, u16 val)
108 rtwdev->hci.ops->write16(rtwdev, addr, val);
111 static inline void rtw_write32(struct rtw_dev *rtwdev, u32 addr, u32 val)
113 rtwdev->hci.ops->write32(rtwdev, addr, val);
116 static inline void rtw_write8_set(struct rtw_dev *rtwdev, u32 addr, u8 bit)
118 u8 val;
120 val = rtw_read8(rtwdev, addr);
121 rtw_write8(rtwdev, addr, val | bit);
124 static inline void rtw_write16_set(struct rtw_dev *rtwdev, u32 addr, u16 bit)
126 u16 val;
128 val = rtw_read16(rtwdev, addr);
129 rtw_write16(rtwdev, addr, val | bit);
132 static inline void rtw_write32_set(struct rtw_dev *rtwdev, u32 addr, u32 bit)
134 u32 val;
136 val = rtw_read32(rtwdev, addr);
137 rtw_write32(rtwdev, addr, val | bit);
140 static inline void rtw_write8_clr(struct rtw_dev *rtwdev, u32 addr, u8 bit)
142 u8 val;
144 val = rtw_read8(rtwdev, addr);
145 rtw_write8(rtwdev, addr, val & ~bit);
148 static inline void rtw_write16_clr(struct rtw_dev *rtwdev, u32 addr, u16 bit)
150 u16 val;
152 val = rtw_read16(rtwdev, addr);
153 rtw_write16(rtwdev, addr, val & ~bit);
156 static inline void rtw_write32_clr(struct rtw_dev *rtwdev, u32 addr, u32 bit)
158 u32 val;
160 val = rtw_read32(rtwdev, addr);
161 rtw_write32(rtwdev, addr, val & ~bit);
164 static inline u32
165 rtw_read_rf(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path,
166 u32 addr, u32 mask)
168 unsigned long flags;
169 u32 val;
171 spin_lock_irqsave(&rtwdev->rf_lock, flags);
172 val = rtwdev->chip->ops->read_rf(rtwdev, rf_path, addr, mask);
173 spin_unlock_irqrestore(&rtwdev->rf_lock, flags);
175 return val;
178 static inline void
179 rtw_write_rf(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path,
180 u32 addr, u32 mask, u32 data)
182 unsigned long flags;
184 spin_lock_irqsave(&rtwdev->rf_lock, flags);
185 rtwdev->chip->ops->write_rf(rtwdev, rf_path, addr, mask, data);
186 spin_unlock_irqrestore(&rtwdev->rf_lock, flags);
189 static inline u32
190 rtw_read32_mask(struct rtw_dev *rtwdev, u32 addr, u32 mask)
192 u32 shift = __ffs(mask);
193 u32 orig;
194 u32 ret;
196 orig = rtw_read32(rtwdev, addr);
197 ret = (orig & mask) >> shift;
199 return ret;
202 static inline u16
203 rtw_read16_mask(struct rtw_dev *rtwdev, u32 addr, u32 mask)
205 u32 shift = __ffs(mask);
206 u32 orig;
207 u32 ret;
209 orig = rtw_read16(rtwdev, addr);
210 ret = (orig & mask) >> shift;
212 return ret;
215 static inline u8
216 rtw_read8_mask(struct rtw_dev *rtwdev, u32 addr, u32 mask)
218 u32 shift = __ffs(mask);
219 u32 orig;
220 u32 ret;
222 orig = rtw_read8(rtwdev, addr);
223 ret = (orig & mask) >> shift;
225 return ret;
228 static inline void
229 rtw_write32_mask(struct rtw_dev *rtwdev, u32 addr, u32 mask, u32 data)
231 u32 shift = __ffs(mask);
232 u32 orig;
233 u32 set;
235 WARN(addr & 0x3, "should be 4-byte aligned, addr = 0x%08x\n", addr);
237 orig = rtw_read32(rtwdev, addr);
238 set = (orig & ~mask) | ((data << shift) & mask);
239 rtw_write32(rtwdev, addr, set);
242 static inline void
243 rtw_write8_mask(struct rtw_dev *rtwdev, u32 addr, u32 mask, u8 data)
245 u32 shift;
246 u8 orig, set;
248 mask &= 0xff;
249 shift = __ffs(mask);
251 orig = rtw_read8(rtwdev, addr);
252 set = (orig & ~mask) | ((data << shift) & mask);
253 rtw_write8(rtwdev, addr, set);
256 static inline enum rtw_hci_type rtw_hci_type(struct rtw_dev *rtwdev)
258 return rtwdev->hci.type;
261 #endif