Bluetooth: btintel: Add btintel data struct
[linux-2.6-microblaze.git] / drivers / bluetooth / btintel.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  *
4  *  Bluetooth support for Intel devices
5  *
6  *  Copyright (C) 2015  Intel Corporation
7  */
8
9 /* List of tlv type */
10 enum {
11         INTEL_TLV_CNVI_TOP = 0x10,
12         INTEL_TLV_CNVR_TOP,
13         INTEL_TLV_CNVI_BT,
14         INTEL_TLV_CNVR_BT,
15         INTEL_TLV_CNVI_OTP,
16         INTEL_TLV_CNVR_OTP,
17         INTEL_TLV_DEV_REV_ID,
18         INTEL_TLV_USB_VENDOR_ID,
19         INTEL_TLV_USB_PRODUCT_ID,
20         INTEL_TLV_PCIE_VENDOR_ID,
21         INTEL_TLV_PCIE_DEVICE_ID,
22         INTEL_TLV_PCIE_SUBSYSTEM_ID,
23         INTEL_TLV_IMAGE_TYPE,
24         INTEL_TLV_TIME_STAMP,
25         INTEL_TLV_BUILD_TYPE,
26         INTEL_TLV_BUILD_NUM,
27         INTEL_TLV_FW_BUILD_PRODUCT,
28         INTEL_TLV_FW_BUILD_HW,
29         INTEL_TLV_FW_STEP,
30         INTEL_TLV_BT_SPEC,
31         INTEL_TLV_MFG_NAME,
32         INTEL_TLV_HCI_REV,
33         INTEL_TLV_LMP_SUBVER,
34         INTEL_TLV_OTP_PATCH_VER,
35         INTEL_TLV_SECURE_BOOT,
36         INTEL_TLV_KEY_FROM_HDR,
37         INTEL_TLV_OTP_LOCK,
38         INTEL_TLV_API_LOCK,
39         INTEL_TLV_DEBUG_LOCK,
40         INTEL_TLV_MIN_FW,
41         INTEL_TLV_LIMITED_CCE,
42         INTEL_TLV_SBE_TYPE,
43         INTEL_TLV_OTP_BDADDR,
44         INTEL_TLV_UNLOCKED_STATE
45 };
46
47 struct intel_tlv {
48         u8 type;
49         u8 len;
50         u8 val[];
51 } __packed;
52
53 struct intel_version_tlv {
54         u32     cnvi_top;
55         u32     cnvr_top;
56         u32     cnvi_bt;
57         u32     cnvr_bt;
58         u16     dev_rev_id;
59         u8      img_type;
60         u16     timestamp;
61         u8      build_type;
62         u32     build_num;
63         u8      secure_boot;
64         u8      otp_lock;
65         u8      api_lock;
66         u8      debug_lock;
67         u8      min_fw_build_nn;
68         u8      min_fw_build_cw;
69         u8      min_fw_build_yy;
70         u8      limited_cce;
71         u8      sbe_type;
72         bdaddr_t otp_bd_addr;
73 };
74
75 struct intel_version {
76         u8 status;
77         u8 hw_platform;
78         u8 hw_variant;
79         u8 hw_revision;
80         u8 fw_variant;
81         u8 fw_revision;
82         u8 fw_build_num;
83         u8 fw_build_ww;
84         u8 fw_build_yy;
85         u8 fw_patch_num;
86 } __packed;
87
88 struct intel_boot_params {
89         __u8     status;
90         __u8     otp_format;
91         __u8     otp_content;
92         __u8     otp_patch;
93         __le16   dev_revid;
94         __u8     secure_boot;
95         __u8     key_from_hdr;
96         __u8     key_type;
97         __u8     otp_lock;
98         __u8     api_lock;
99         __u8     debug_lock;
100         bdaddr_t otp_bdaddr;
101         __u8     min_fw_build_nn;
102         __u8     min_fw_build_cw;
103         __u8     min_fw_build_yy;
104         __u8     limited_cce;
105         __u8     unlocked_state;
106 } __packed;
107
108 struct intel_bootup {
109         __u8     zero;
110         __u8     num_cmds;
111         __u8     source;
112         __u8     reset_type;
113         __u8     reset_reason;
114         __u8     ddc_status;
115 } __packed;
116
117 struct intel_secure_send_result {
118         __u8     result;
119         __le16   opcode;
120         __u8     status;
121 } __packed;
122
123 struct intel_reset {
124         __u8     reset_type;
125         __u8     patch_enable;
126         __u8     ddc_reload;
127         __u8     boot_option;
128         __le32   boot_param;
129 } __packed;
130
131 struct intel_debug_features {
132         __u8    page1[16];
133 } __packed;
134
135 #define INTEL_HW_PLATFORM(cnvx_bt)      ((u8)(((cnvx_bt) & 0x0000ff00) >> 8))
136 #define INTEL_HW_VARIANT(cnvx_bt)       ((u8)(((cnvx_bt) & 0x003f0000) >> 16))
137 #define INTEL_CNVX_TOP_TYPE(cnvx_top)   ((cnvx_top) & 0x00000fff)
138 #define INTEL_CNVX_TOP_STEP(cnvx_top)   (((cnvx_top) & 0x0f000000) >> 24)
139 #define INTEL_CNVX_TOP_PACK_SWAB(t, s)  __swab16(((__u16)(((t) << 4) | (s))))
140
141 enum {
142         INTEL_BOOTLOADER,
143         INTEL_DOWNLOADING,
144         INTEL_FIRMWARE_LOADED,
145         INTEL_FIRMWARE_FAILED,
146         INTEL_BOOTING,
147
148         __INTEL_NUM_FLAGS,
149 };
150
151 struct btintel_data {
152         DECLARE_BITMAP(flags, __INTEL_NUM_FLAGS);
153 };
154
155 #define btintel_set_flag(hdev, nr)                                      \
156         do {                                                            \
157                 struct btintel_data *intel = hci_get_priv((hdev));      \
158                 set_bit((nr), intel->flags);                            \
159         } while (0)
160
161 #define btintel_clear_flag(hdev, nr)                                    \
162         do {                                                            \
163                 struct btintel_data *intel = hci_get_priv((hdev));      \
164                 clear_bit((nr), intel->flags);                          \
165         } while (0)
166
167 #define btintel_wake_up_flag(hdev, nr)                                  \
168         do {                                                            \
169                 struct btintel_data *intel = hci_get_priv((hdev));      \
170                 wake_up_bit(intel->flags, (nr));                        \
171         } while (0)
172
173 #define btintel_get_flag(hdev)                                          \
174         (((struct btintel_data *)hci_get_priv(hdev))->flags)
175
176 #define btintel_test_flag(hdev, nr)     test_bit((nr), btintel_get_flag(hdev))
177 #define btintel_test_and_clear_flag(hdev, nr) test_and_clear_bit((nr), btintel_get_flag(hdev))
178 #define btintel_wait_on_flag_timeout(hdev, nr, m, to)                   \
179                 wait_on_bit_timeout(btintel_get_flag(hdev), (nr), m, to)
180
181 #if IS_ENABLED(CONFIG_BT_INTEL)
182
183 int btintel_check_bdaddr(struct hci_dev *hdev);
184 int btintel_enter_mfg(struct hci_dev *hdev);
185 int btintel_exit_mfg(struct hci_dev *hdev, bool reset, bool patched);
186 int btintel_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr);
187 int btintel_set_diag(struct hci_dev *hdev, bool enable);
188 void btintel_hw_error(struct hci_dev *hdev, u8 code);
189
190 int btintel_version_info(struct hci_dev *hdev, struct intel_version *ver);
191 int btintel_version_info_tlv(struct hci_dev *hdev, struct intel_version_tlv *version);
192 int btintel_secure_send(struct hci_dev *hdev, u8 fragment_type, u32 plen,
193                         const void *param);
194 int btintel_load_ddc_config(struct hci_dev *hdev, const char *ddc_name);
195 int btintel_set_event_mask(struct hci_dev *hdev, bool debug);
196 int btintel_set_event_mask_mfg(struct hci_dev *hdev, bool debug);
197 int btintel_read_version(struct hci_dev *hdev, struct intel_version *ver);
198 int btintel_read_version_tlv(struct hci_dev *hdev, struct intel_version_tlv *ver);
199
200 struct regmap *btintel_regmap_init(struct hci_dev *hdev, u16 opcode_read,
201                                    u16 opcode_write);
202 int btintel_send_intel_reset(struct hci_dev *hdev, u32 boot_param);
203 int btintel_read_boot_params(struct hci_dev *hdev,
204                              struct intel_boot_params *params);
205 int btintel_download_firmware(struct hci_dev *dev, struct intel_version *ver,
206                               const struct firmware *fw, u32 *boot_param);
207 int btintel_download_firmware_newgen(struct hci_dev *hdev,
208                                      struct intel_version_tlv *ver,
209                                      const struct firmware *fw,
210                                      u32 *boot_param, u8 hw_variant,
211                                      u8 sbe_type);
212 void btintel_reset_to_bootloader(struct hci_dev *hdev);
213 int btintel_read_debug_features(struct hci_dev *hdev,
214                                 struct intel_debug_features *features);
215 int btintel_set_debug_features(struct hci_dev *hdev,
216                                const struct intel_debug_features *features);
217 int btintel_configure_setup(struct hci_dev *hdev);
218 #else
219
220 static inline int btintel_check_bdaddr(struct hci_dev *hdev)
221 {
222         return -EOPNOTSUPP;
223 }
224
225 static inline int btintel_enter_mfg(struct hci_dev *hdev)
226 {
227         return -EOPNOTSUPP;
228 }
229
230 static inline int btintel_exit_mfg(struct hci_dev *hdev, bool reset, bool patched)
231 {
232         return -EOPNOTSUPP;
233 }
234
235 static inline int btintel_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
236 {
237         return -EOPNOTSUPP;
238 }
239
240 static inline int btintel_set_diag(struct hci_dev *hdev, bool enable)
241 {
242         return -EOPNOTSUPP;
243 }
244
245 static inline void btintel_hw_error(struct hci_dev *hdev, u8 code)
246 {
247 }
248
249 static inline int btintel_version_info(struct hci_dev *hdev,
250                                        struct intel_version *ver)
251 {
252         return -EOPNOTSUPP;
253 }
254
255 static inline int btintel_version_info_tlv(struct hci_dev *hdev,
256                                            struct intel_version_tlv *version)
257 {
258         return -EOPNOTSUPP;
259 }
260
261 static inline int btintel_secure_send(struct hci_dev *hdev, u8 fragment_type,
262                                       u32 plen, const void *param)
263 {
264         return -EOPNOTSUPP;
265 }
266
267 static inline int btintel_load_ddc_config(struct hci_dev *hdev,
268                                           const char *ddc_name)
269 {
270         return -EOPNOTSUPP;
271 }
272
273 static inline int btintel_set_event_mask(struct hci_dev *hdev, bool debug)
274 {
275         return -EOPNOTSUPP;
276 }
277
278 static inline int btintel_set_event_mask_mfg(struct hci_dev *hdev, bool debug)
279 {
280         return -EOPNOTSUPP;
281 }
282
283 static inline int btintel_read_version(struct hci_dev *hdev,
284                                        struct intel_version *ver)
285 {
286         return -EOPNOTSUPP;
287 }
288
289 static inline int btintel_read_version_tlv(struct hci_dev *hdev,
290                                            struct intel_version_tlv *ver)
291 {
292         return -EOPNOTSUPP;
293 }
294
295 static inline struct regmap *btintel_regmap_init(struct hci_dev *hdev,
296                                                  u16 opcode_read,
297                                                  u16 opcode_write)
298 {
299         return ERR_PTR(-EINVAL);
300 }
301
302 static inline int btintel_send_intel_reset(struct hci_dev *hdev,
303                                            u32 reset_param)
304 {
305         return -EOPNOTSUPP;
306 }
307
308 static inline int btintel_read_boot_params(struct hci_dev *hdev,
309                                            struct intel_boot_params *params)
310 {
311         return -EOPNOTSUPP;
312 }
313
314 static inline int btintel_download_firmware(struct hci_dev *dev,
315                                             const struct firmware *fw,
316                                             u32 *boot_param)
317 {
318         return -EOPNOTSUPP;
319 }
320
321 static inline int btintel_download_firmware_newgen(struct hci_dev *hdev,
322                                                    const struct firmware *fw,
323                                                    u32 *boot_param,
324                                                    u8 hw_variant, u8 sbe_type)
325 {
326         return -EOPNOTSUPP;
327 }
328
329 static inline void btintel_reset_to_bootloader(struct hci_dev *hdev)
330 {
331 }
332
333 static inline int btintel_read_debug_features(struct hci_dev *hdev,
334                                               struct intel_debug_features *features)
335 {
336         return -EOPNOTSUPP;
337 }
338
339 static inline int btintel_set_debug_features(struct hci_dev *hdev,
340                                              const struct intel_debug_features *features)
341 {
342         return -EOPNOTSUPP;
343 }
344
345 static inline int btintel_configure_setup(struct hci_dev *hdev)
346 {
347         return -ENODEV;
348 }
349
350 #endif