1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /* Copyright(c) 2018-2019 Realtek Corporation
8 /* ops for PCI, USB and SDIO */
10 int (*tx_write
)(struct rtw_dev
*rtwdev
,
11 struct rtw_tx_pkt_info
*pkt_info
,
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
,
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
);
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
);
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
)
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
)
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
)
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
)
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
)
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
)
160 val
= rtw_read32(rtwdev
, addr
);
161 rtw_write32(rtwdev
, addr
, val
& ~bit
);
165 rtw_read_rf(struct rtw_dev
*rtwdev
, enum rtw_rf_path rf_path
,
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
);
179 rtw_write_rf(struct rtw_dev
*rtwdev
, enum rtw_rf_path rf_path
,
180 u32 addr
, u32 mask
, u32 data
)
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
);
190 rtw_read32_mask(struct rtw_dev
*rtwdev
, u32 addr
, u32 mask
)
192 u32 shift
= __ffs(mask
);
196 orig
= rtw_read32(rtwdev
, addr
);
197 ret
= (orig
& mask
) >> shift
;
203 rtw_read16_mask(struct rtw_dev
*rtwdev
, u32 addr
, u32 mask
)
205 u32 shift
= __ffs(mask
);
209 orig
= rtw_read16(rtwdev
, addr
);
210 ret
= (orig
& mask
) >> shift
;
216 rtw_read8_mask(struct rtw_dev
*rtwdev
, u32 addr
, u32 mask
)
218 u32 shift
= __ffs(mask
);
222 orig
= rtw_read8(rtwdev
, addr
);
223 ret
= (orig
& mask
) >> shift
;
229 rtw_write32_mask(struct rtw_dev
*rtwdev
, u32 addr
, u32 mask
, u32 data
)
231 u32 shift
= __ffs(mask
);
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
);
243 rtw_write8_mask(struct rtw_dev
*rtwdev
, u32 addr
, u32 mask
, u8 data
)
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
;