1 /*
2 * Copyright (c) 2016-2021 The Linux Foundation. All rights reserved.
3 * Copyright (c) 2021-2024 Qualcomm Innovation Center, Inc. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for
6 * any purpose with or without fee is hereby granted, provided that the
7 * above copyright notice and this permission notice appear in all
8 * copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
18 */
19
20 #define pr_fmt(fmt) "wlan_pld:%s:%d:: " fmt, __func__, __LINE__
21
22 #include <linux/printk.h>
23 #include <linux/err.h>
24 #include <linux/string.h>
25 #include <linux/list.h>
26 #include <linux/slab.h>
27 #include <linux/pm.h>
28
29 #ifdef CONFIG_PLD_SDIO_CNSS
30 #include <net/cnss.h>
31 #endif
32 #ifdef CONFIG_PLD_PCIE_CNSS
33 #ifdef CONFIG_CNSS_OUT_OF_TREE
34 #include "cnss2.h"
35 #else
36 #include <net/cnss2.h>
37 #endif
38 #endif
39
40 #ifdef CONFIG_CNSS_OUT_OF_TREE
41 #ifdef CONFIG_PLD_SNOC_ICNSS
42 #ifdef CONFIG_PLD_SNOC_ICNSS2
43 #include "icnss2.h"
44 #else
45 #include "icnss.h"
46 #endif
47 #endif
48 #ifdef CONFIG_PLD_IPCI_ICNSS
49 #include "icnss2.h"
50 #endif
51 #else
52 #ifdef CONFIG_PLD_SNOC_ICNSS
53 #ifdef CONFIG_PLD_SNOC_ICNSS2
54 #include <soc/qcom/icnss2.h>
55 #else
56 #include <soc/qcom/icnss.h>
57 #endif
58 #endif
59 #ifdef CONFIG_PLD_IPCI_ICNSS
60 #include <soc/qcom/icnss2.h>
61 #endif
62 #endif
63
64 #include "pld_pcie.h"
65 #include "pld_ipci.h"
66 #include "pld_pcie_fw_sim.h"
67 #include "pld_snoc_fw_sim.h"
68 #include "pld_snoc.h"
69 #include "pld_sdio.h"
70 #include "pld_usb.h"
71 #include "qwlan_version.h"
72
73 #define PLD_PCIE_REGISTERED BIT(0)
74 #define PLD_SNOC_REGISTERED BIT(1)
75 #define PLD_SDIO_REGISTERED BIT(2)
76 #define PLD_USB_REGISTERED BIT(3)
77 #define PLD_SNOC_FW_SIM_REGISTERED BIT(4)
78 #define PLD_PCIE_FW_SIM_REGISTERED BIT(5)
79 #define PLD_IPCI_REGISTERED BIT(6)
80
81 #define PLD_BUS_MASK 0xf
82
83 static struct pld_context *pld_ctx;
84
pld_init(void)85 int pld_init(void)
86 {
87 struct pld_context *pld_context;
88
89 pld_context = kzalloc(sizeof(*pld_context), GFP_KERNEL);
90 if (!pld_context)
91 return -ENOMEM;
92
93 spin_lock_init(&pld_context->pld_lock);
94
95 INIT_LIST_HEAD(&pld_context->dev_list);
96
97 pld_ctx = pld_context;
98
99 return 0;
100 }
101
pld_deinit(void)102 void pld_deinit(void)
103 {
104 struct dev_node *dev_node;
105 struct pld_context *pld_context;
106 unsigned long flags;
107
108 pld_context = pld_ctx;
109 if (!pld_context) {
110 pld_ctx = NULL;
111 return;
112 }
113
114 spin_lock_irqsave(&pld_context->pld_lock, flags);
115 while (!list_empty(&pld_context->dev_list)) {
116 dev_node = list_first_entry(&pld_context->dev_list,
117 struct dev_node, list);
118 list_del(&dev_node->list);
119 kfree(dev_node);
120 }
121 spin_unlock_irqrestore(&pld_context->pld_lock, flags);
122
123 kfree(pld_context);
124
125 pld_ctx = NULL;
126 }
127
pld_set_mode(u8 mode)128 int pld_set_mode(u8 mode)
129 {
130 if (!pld_ctx)
131 return -ENOMEM;
132
133 pld_ctx->mode = mode;
134 return 0;
135 }
136
pld_get_global_context(void)137 struct pld_context *pld_get_global_context(void)
138 {
139 return pld_ctx;
140 }
141
pld_add_dev(struct pld_context * pld_context,struct device * dev,struct device * ifdev,enum pld_bus_type type)142 int pld_add_dev(struct pld_context *pld_context,
143 struct device *dev, struct device *ifdev,
144 enum pld_bus_type type)
145 {
146 unsigned long flags;
147 struct dev_node *dev_node;
148
149 dev_node = kzalloc(sizeof(*dev_node), GFP_KERNEL);
150 if (!dev_node)
151 return -ENOMEM;
152
153 dev_node->dev = dev;
154 dev_node->ifdev = ifdev;
155 dev_node->bus_type = type;
156
157 spin_lock_irqsave(&pld_context->pld_lock, flags);
158 list_add_tail(&dev_node->list, &pld_context->dev_list);
159 spin_unlock_irqrestore(&pld_context->pld_lock, flags);
160
161 return 0;
162 }
163
pld_del_dev(struct pld_context * pld_context,struct device * dev)164 void pld_del_dev(struct pld_context *pld_context,
165 struct device *dev)
166 {
167 unsigned long flags;
168 struct dev_node *dev_node, *tmp;
169
170 spin_lock_irqsave(&pld_context->pld_lock, flags);
171 list_for_each_entry_safe(dev_node, tmp, &pld_context->dev_list, list) {
172 if (dev_node->dev == dev) {
173 list_del(&dev_node->list);
174 kfree(dev_node);
175 }
176 }
177 spin_unlock_irqrestore(&pld_context->pld_lock, flags);
178 }
179
pld_get_dev_node(struct device * dev)180 static struct dev_node *pld_get_dev_node(struct device *dev)
181 {
182 struct pld_context *pld_context;
183 struct dev_node *dev_node;
184 unsigned long flags;
185
186 pld_context = pld_get_global_context();
187
188 if (!dev || !pld_context) {
189 pr_err("Invalid info: dev %pK, context %pK\n",
190 dev, pld_context);
191 return NULL;
192 }
193
194 spin_lock_irqsave(&pld_context->pld_lock, flags);
195 list_for_each_entry(dev_node, &pld_context->dev_list, list) {
196 if (dev_node->dev == dev) {
197 spin_unlock_irqrestore(&pld_context->pld_lock, flags);
198 return dev_node;
199 }
200 }
201 spin_unlock_irqrestore(&pld_context->pld_lock, flags);
202
203 return NULL;
204 }
205
pld_get_bus_type(struct device * dev)206 enum pld_bus_type pld_get_bus_type(struct device *dev)
207 {
208 struct dev_node *dev_node = pld_get_dev_node(dev);
209
210 if (dev_node)
211 return dev_node->bus_type;
212 else
213 return PLD_BUS_TYPE_NONE;
214 }
215
216 /**
217 * pld_get_if_dev() - Bus interface/pipe dev of the device
218 * @dev: device
219 *
220 * Return: Bus sub-interface or pipe dev.
221 */
pld_get_if_dev(struct device * dev)222 static struct device *pld_get_if_dev(struct device *dev)
223 {
224 struct dev_node *dev_node = pld_get_dev_node(dev);
225
226 if (dev_node)
227 return dev_node->ifdev;
228 else
229 return NULL;
230 }
231
pld_register_driver(struct pld_driver_ops * ops)232 int pld_register_driver(struct pld_driver_ops *ops)
233 {
234 int ret = 0;
235 struct pld_context *pld_context;
236
237 pld_context = pld_get_global_context();
238
239 if (!pld_context) {
240 pr_err("global context is NULL\n");
241 ret = -ENODEV;
242 goto out;
243 }
244
245 if (pld_context->ops) {
246 pr_err("driver already registered\n");
247 ret = -EEXIST;
248 goto out;
249 }
250
251 if (!ops || !ops->probe || !ops->remove ||
252 !ops->suspend || !ops->resume) {
253 pr_err("Required callback functions are missing\n");
254 ret = -EINVAL;
255 goto out;
256 }
257
258 pld_context->ops = ops;
259 pld_context->pld_driver_state = 0;
260
261 ret = pld_pcie_register_driver();
262 if (ret) {
263 pld_err_rl("Fail to register pcie driver\n");
264 goto fail_pcie;
265 }
266 pld_context->pld_driver_state |= PLD_PCIE_REGISTERED;
267
268 ret = pld_snoc_register_driver();
269 if (ret) {
270 pld_err_rl("Fail to register snoc driver\n");
271 goto fail_snoc;
272 }
273 pld_context->pld_driver_state |= PLD_SNOC_REGISTERED;
274
275 ret = pld_sdio_register_driver();
276 if (ret) {
277 pr_err("Fail to register sdio driver\n");
278 goto fail_sdio;
279 }
280 pld_context->pld_driver_state |= PLD_SDIO_REGISTERED;
281
282 ret = pld_snoc_fw_sim_register_driver();
283 if (ret) {
284 pr_err("Fail to register snoc fw sim driver\n");
285 goto fail_snoc_fw_sim;
286 }
287 pld_context->pld_driver_state |= PLD_SNOC_FW_SIM_REGISTERED;
288
289 ret = pld_pcie_fw_sim_register_driver();
290 if (ret) {
291 pr_err("Fail to register pcie fw sim driver\n");
292 goto fail_pcie_fw_sim;
293 }
294 pld_context->pld_driver_state |= PLD_PCIE_FW_SIM_REGISTERED;
295
296 ret = pld_usb_register_driver();
297 if (ret) {
298 pr_err("Fail to register usb driver\n");
299 goto fail_usb;
300 }
301 pld_context->pld_driver_state |= PLD_USB_REGISTERED;
302
303 ret = pld_ipci_register_driver();
304 if (ret) {
305 pld_err_rl("Fail to register ipci driver\n");
306 goto fail_ipci;
307 }
308 pld_context->pld_driver_state |= PLD_IPCI_REGISTERED;
309
310 return ret;
311
312 fail_ipci:
313 pld_usb_unregister_driver();
314 fail_usb:
315 pld_pcie_fw_sim_unregister_driver();
316 fail_pcie_fw_sim:
317 pld_snoc_fw_sim_unregister_driver();
318 fail_snoc_fw_sim:
319 pld_sdio_unregister_driver();
320 fail_sdio:
321 pld_snoc_unregister_driver();
322 fail_snoc:
323 pld_pcie_unregister_driver();
324 fail_pcie:
325 pld_context->pld_driver_state = 0;
326 pld_context->ops = NULL;
327 out:
328 return ret;
329 }
330
pld_unregister_driver(void)331 void pld_unregister_driver(void)
332 {
333 struct pld_context *pld_context;
334
335 pld_context = pld_get_global_context();
336
337 if (!pld_context) {
338 pr_err("global context is NULL\n");
339 return;
340 }
341
342 if (!pld_context->ops) {
343 pr_err("driver not registered\n");
344 return;
345 }
346
347 pld_pcie_unregister_driver();
348 pld_snoc_fw_sim_unregister_driver();
349 pld_pcie_fw_sim_unregister_driver();
350 pld_snoc_unregister_driver();
351 pld_sdio_unregister_driver();
352 pld_usb_unregister_driver();
353 pld_ipci_unregister_driver();
354
355 pld_context->pld_driver_state = 0;
356
357 pld_context->ops = NULL;
358 }
359
pld_wlan_enable(struct device * dev,struct pld_wlan_enable_cfg * config,enum pld_driver_mode mode)360 int pld_wlan_enable(struct device *dev, struct pld_wlan_enable_cfg *config,
361 enum pld_driver_mode mode)
362 {
363 int ret = 0;
364 struct device *ifdev;
365
366 switch (pld_get_bus_type(dev)) {
367 case PLD_BUS_TYPE_PCIE:
368 ret = pld_pcie_wlan_enable(dev, config, mode, QWLAN_VERSIONSTR);
369 break;
370 case PLD_BUS_TYPE_SNOC:
371 ret = pld_snoc_wlan_enable(dev, config, mode, QWLAN_VERSIONSTR);
372 break;
373 case PLD_BUS_TYPE_SNOC_FW_SIM:
374 ret = pld_snoc_fw_sim_wlan_enable(dev, config, mode,
375 QWLAN_VERSIONSTR);
376 break;
377 case PLD_BUS_TYPE_PCIE_FW_SIM:
378 case PLD_BUS_TYPE_IPCI_FW_SIM:
379 ret = pld_pcie_fw_sim_wlan_enable(dev, config, mode,
380 QWLAN_VERSIONSTR);
381 break;
382 case PLD_BUS_TYPE_SDIO:
383 ret = pld_sdio_wlan_enable(dev, config, mode, QWLAN_VERSIONSTR);
384 break;
385 case PLD_BUS_TYPE_USB:
386 ifdev = pld_get_if_dev(dev);
387 ret = pld_usb_wlan_enable(ifdev, config, mode,
388 QWLAN_VERSIONSTR);
389 break;
390 case PLD_BUS_TYPE_IPCI:
391 ret = pld_ipci_wlan_enable(dev, config, mode, QWLAN_VERSIONSTR);
392 break;
393 default:
394 ret = -EINVAL;
395 break;
396 }
397
398 return ret;
399 }
400
pld_wlan_disable(struct device * dev,enum pld_driver_mode mode)401 int pld_wlan_disable(struct device *dev, enum pld_driver_mode mode)
402 {
403 int ret = 0;
404
405 switch (pld_get_bus_type(dev)) {
406 case PLD_BUS_TYPE_PCIE:
407 ret = pld_pcie_wlan_disable(dev, mode);
408 break;
409 case PLD_BUS_TYPE_SNOC:
410 ret = pld_snoc_wlan_disable(dev, mode);
411 break;
412 case PLD_BUS_TYPE_SNOC_FW_SIM:
413 ret = pld_snoc_fw_sim_wlan_disable(dev, mode);
414 break;
415 case PLD_BUS_TYPE_PCIE_FW_SIM:
416 case PLD_BUS_TYPE_IPCI_FW_SIM:
417 ret = pld_pcie_fw_sim_wlan_disable(dev, mode);
418 break;
419 case PLD_BUS_TYPE_SDIO:
420 break;
421 case PLD_BUS_TYPE_IPCI:
422 ret = pld_ipci_wlan_disable(dev, mode);
423 break;
424 default:
425 ret = -EINVAL;
426 break;
427 }
428
429 return ret;
430 }
431
pld_wlan_hw_enable(void)432 int pld_wlan_hw_enable(void)
433 {
434 return pld_pcie_wlan_hw_enable();
435 }
436
pld_set_fw_log_mode(struct device * dev,u8 fw_log_mode)437 int pld_set_fw_log_mode(struct device *dev, u8 fw_log_mode)
438 {
439 int ret = 0;
440
441 switch (pld_get_bus_type(dev)) {
442 case PLD_BUS_TYPE_PCIE:
443 ret = pld_pcie_set_fw_log_mode(dev, fw_log_mode);
444 break;
445 case PLD_BUS_TYPE_SNOC:
446 ret = pld_snoc_set_fw_log_mode(dev, fw_log_mode);
447 break;
448 case PLD_BUS_TYPE_PCIE_FW_SIM:
449 case PLD_BUS_TYPE_IPCI_FW_SIM:
450 case PLD_BUS_TYPE_SNOC_FW_SIM:
451 case PLD_BUS_TYPE_SDIO:
452 break;
453 case PLD_BUS_TYPE_IPCI:
454 ret = pld_ipci_set_fw_log_mode(dev, fw_log_mode);
455 break;
456 default:
457 ret = -EINVAL;
458 break;
459 }
460
461 return ret;
462 }
463
pld_get_default_fw_files(struct pld_fw_files * pfw_files)464 void pld_get_default_fw_files(struct pld_fw_files *pfw_files)
465 {
466 memset(pfw_files, 0, sizeof(*pfw_files));
467
468 strlcpy(pfw_files->image_file, PREFIX PLD_IMAGE_FILE,
469 PLD_MAX_FILE_NAME);
470 strlcpy(pfw_files->board_data, PREFIX PLD_BOARD_DATA_FILE,
471 PLD_MAX_FILE_NAME);
472 strlcpy(pfw_files->otp_data, PREFIX PLD_OTP_FILE,
473 PLD_MAX_FILE_NAME);
474 strlcpy(pfw_files->utf_file, PREFIX PLD_UTF_FIRMWARE_FILE,
475 PLD_MAX_FILE_NAME);
476 strlcpy(pfw_files->utf_board_data, PREFIX PLD_BOARD_DATA_FILE,
477 PLD_MAX_FILE_NAME);
478 strlcpy(pfw_files->epping_file, PREFIX PLD_EPPING_FILE,
479 PLD_MAX_FILE_NAME);
480 strlcpy(pfw_files->setup_file, PREFIX PLD_SETUP_FILE,
481 PLD_MAX_FILE_NAME);
482 }
483
pld_get_fw_files_for_target(struct device * dev,struct pld_fw_files * pfw_files,u32 target_type,u32 target_version)484 int pld_get_fw_files_for_target(struct device *dev,
485 struct pld_fw_files *pfw_files,
486 u32 target_type, u32 target_version)
487 {
488 int ret = 0;
489
490 switch (pld_get_bus_type(dev)) {
491 case PLD_BUS_TYPE_PCIE:
492 ret = pld_pcie_get_fw_files_for_target(dev, pfw_files,
493 target_type,
494 target_version);
495 break;
496 case PLD_BUS_TYPE_PCIE_FW_SIM:
497 case PLD_BUS_TYPE_IPCI_FW_SIM:
498 case PLD_BUS_TYPE_SNOC_FW_SIM:
499 case PLD_BUS_TYPE_SNOC:
500 case PLD_BUS_TYPE_IPCI:
501 break;
502 case PLD_BUS_TYPE_SDIO:
503 ret = pld_sdio_get_fw_files_for_target(pfw_files,
504 target_type,
505 target_version);
506 break;
507 case PLD_BUS_TYPE_USB:
508 ret = pld_usb_get_fw_files_for_target(pfw_files,
509 target_type,
510 target_version);
511 break;
512 default:
513 ret = -EINVAL;
514 break;
515 }
516
517 return ret;
518 }
519
pld_prevent_l1(struct device * dev)520 int pld_prevent_l1(struct device *dev)
521 {
522 int ret = 0;
523
524 switch (pld_get_bus_type(dev)) {
525 case PLD_BUS_TYPE_PCIE:
526 ret = pld_pcie_prevent_l1(dev);
527 break;
528 case PLD_BUS_TYPE_PCIE_FW_SIM:
529 case PLD_BUS_TYPE_IPCI_FW_SIM:
530 case PLD_BUS_TYPE_SNOC_FW_SIM:
531 case PLD_BUS_TYPE_SNOC:
532 case PLD_BUS_TYPE_SDIO:
533 case PLD_BUS_TYPE_USB:
534 break;
535 case PLD_BUS_TYPE_IPCI:
536 ret = pld_ipci_prevent_l1(dev);
537 break;
538 default:
539 ret = -EINVAL;
540 pr_err("Invalid device type\n");
541 break;
542 }
543
544 return ret;
545 }
546
pld_allow_l1(struct device * dev)547 void pld_allow_l1(struct device *dev)
548 {
549 switch (pld_get_bus_type(dev)) {
550 case PLD_BUS_TYPE_PCIE:
551 pld_pcie_allow_l1(dev);
552 break;
553 case PLD_BUS_TYPE_PCIE_FW_SIM:
554 case PLD_BUS_TYPE_IPCI_FW_SIM:
555 case PLD_BUS_TYPE_SNOC_FW_SIM:
556 case PLD_BUS_TYPE_SNOC:
557 case PLD_BUS_TYPE_SDIO:
558 case PLD_BUS_TYPE_USB:
559 break;
560 case PLD_BUS_TYPE_IPCI:
561 pld_ipci_allow_l1(dev);
562 break;
563 default:
564 pr_err("Invalid device type\n");
565 break;
566 }
567 }
568
pld_get_mhi_state(struct device * dev)569 int pld_get_mhi_state(struct device *dev)
570 {
571 int ret = 0;
572
573 switch (pld_get_bus_type(dev)) {
574 case PLD_BUS_TYPE_PCIE:
575 case PLD_BUS_TYPE_PCIE_FW_SIM:
576 case PLD_BUS_TYPE_IPCI_FW_SIM:
577 case PLD_BUS_TYPE_SNOC_FW_SIM:
578 case PLD_BUS_TYPE_SNOC:
579 case PLD_BUS_TYPE_SDIO:
580 case PLD_BUS_TYPE_USB:
581 ret = PLD_MHI_STATE_L0;
582 break;
583 case PLD_BUS_TYPE_IPCI:
584 ret = pld_ipci_mhi_state(dev);
585 break;
586 default:
587 pr_err("Invalid device type\n");
588 break;
589 }
590 return ret;
591 }
592
pld_set_pcie_gen_speed(struct device * dev,u8 pcie_gen_speed)593 int pld_set_pcie_gen_speed(struct device *dev, u8 pcie_gen_speed)
594 {
595 int ret = -EINVAL;
596
597 switch (pld_get_bus_type(dev)) {
598 case PLD_BUS_TYPE_PCIE:
599 ret = pld_pcie_set_gen_speed(dev, pcie_gen_speed);
600 break;
601 default:
602 pr_err("Invalid device type\n");
603 break;
604 }
605 return ret;
606 }
607
pld_is_pci_link_down(struct device * dev)608 void pld_is_pci_link_down(struct device *dev)
609 {
610 switch (pld_get_bus_type(dev)) {
611 case PLD_BUS_TYPE_PCIE_FW_SIM:
612 case PLD_BUS_TYPE_IPCI_FW_SIM:
613 break;
614 case PLD_BUS_TYPE_PCIE:
615 pld_pcie_link_down(dev);
616 break;
617 case PLD_BUS_TYPE_SNOC_FW_SIM:
618 case PLD_BUS_TYPE_SNOC:
619 case PLD_BUS_TYPE_IPCI:
620 break;
621 default:
622 pr_err("Invalid device type\n");
623 break;
624 }
625 }
626
pld_get_bus_reg_dump(struct device * dev,uint8_t * buf,uint32_t len)627 void pld_get_bus_reg_dump(struct device *dev, uint8_t *buf, uint32_t len)
628 {
629 switch (pld_get_bus_type(dev)) {
630 case PLD_BUS_TYPE_PCIE_FW_SIM:
631 break;
632 case PLD_BUS_TYPE_PCIE:
633 pld_pcie_get_reg_dump(dev, buf, len);
634 break;
635 case PLD_BUS_TYPE_SNOC_FW_SIM:
636 case PLD_BUS_TYPE_SNOC:
637 case PLD_BUS_TYPE_IPCI:
638 break;
639 default:
640 pr_err("Invalid device type\n");
641 break;
642 }
643 }
644
pld_schedule_recovery_work(struct device * dev,enum pld_recovery_reason reason)645 void pld_schedule_recovery_work(struct device *dev,
646 enum pld_recovery_reason reason)
647 {
648 switch (pld_get_bus_type(dev)) {
649 case PLD_BUS_TYPE_PCIE:
650 pld_pcie_schedule_recovery_work(dev, reason);
651 break;
652 case PLD_BUS_TYPE_PCIE_FW_SIM:
653 case PLD_BUS_TYPE_IPCI_FW_SIM:
654 case PLD_BUS_TYPE_SNOC_FW_SIM:
655 case PLD_BUS_TYPE_SNOC:
656 case PLD_BUS_TYPE_IPCI:
657 break;
658 default:
659 pr_err("Invalid device type\n");
660 break;
661 }
662 }
663
pld_wlan_pm_control(struct device * dev,bool vote)664 int pld_wlan_pm_control(struct device *dev, bool vote)
665 {
666 int ret = 0;
667
668 switch (pld_get_bus_type(dev)) {
669 case PLD_BUS_TYPE_PCIE:
670 ret = pld_pcie_wlan_pm_control(dev, vote);
671 break;
672 case PLD_BUS_TYPE_PCIE_FW_SIM:
673 case PLD_BUS_TYPE_IPCI_FW_SIM:
674 case PLD_BUS_TYPE_SNOC_FW_SIM:
675 case PLD_BUS_TYPE_SNOC:
676 break;
677 case PLD_BUS_TYPE_SDIO:
678 break;
679 case PLD_BUS_TYPE_IPCI:
680 break;
681 default:
682 ret = -EINVAL;
683 break;
684 }
685
686 return ret;
687 }
688
pld_get_virt_ramdump_mem(struct device * dev,unsigned long * size)689 void *pld_get_virt_ramdump_mem(struct device *dev, unsigned long *size)
690 {
691 void *mem = NULL;
692
693 switch (pld_get_bus_type(dev)) {
694 case PLD_BUS_TYPE_PCIE:
695 mem = pld_pcie_get_virt_ramdump_mem(dev, size);
696 break;
697 case PLD_BUS_TYPE_PCIE_FW_SIM:
698 case PLD_BUS_TYPE_IPCI_FW_SIM:
699 case PLD_BUS_TYPE_SNOC_FW_SIM:
700 case PLD_BUS_TYPE_SNOC:
701 case PLD_BUS_TYPE_IPCI:
702 break;
703 case PLD_BUS_TYPE_SDIO:
704 mem = pld_sdio_get_virt_ramdump_mem(dev, size);
705 break;
706 default:
707 pr_err("Invalid device type\n");
708 break;
709 }
710
711 return mem;
712 }
713
pld_release_virt_ramdump_mem(struct device * dev,void * address)714 void pld_release_virt_ramdump_mem(struct device *dev, void *address)
715 {
716 switch (pld_get_bus_type(dev)) {
717 case PLD_BUS_TYPE_PCIE:
718 pld_pcie_release_virt_ramdump_mem(address);
719 break;
720 case PLD_BUS_TYPE_PCIE_FW_SIM:
721 case PLD_BUS_TYPE_IPCI_FW_SIM:
722 case PLD_BUS_TYPE_SNOC_FW_SIM:
723 case PLD_BUS_TYPE_SNOC:
724 case PLD_BUS_TYPE_IPCI:
725 break;
726 case PLD_BUS_TYPE_SDIO:
727 pld_sdio_release_virt_ramdump_mem(address);
728 break;
729 default:
730 pr_err("Invalid device type\n");
731 break;
732 }
733 }
734
pld_device_crashed(struct device * dev)735 void pld_device_crashed(struct device *dev)
736 {
737 switch (pld_get_bus_type(dev)) {
738 case PLD_BUS_TYPE_PCIE:
739 pld_pcie_device_crashed(dev);
740 break;
741 case PLD_BUS_TYPE_PCIE_FW_SIM:
742 case PLD_BUS_TYPE_IPCI_FW_SIM:
743 case PLD_BUS_TYPE_SNOC_FW_SIM:
744 case PLD_BUS_TYPE_SNOC:
745 break;
746 case PLD_BUS_TYPE_IPCI:
747 break;
748 case PLD_BUS_TYPE_SDIO:
749 pld_sdio_device_crashed(dev);
750 break;
751 default:
752 pr_err("Invalid device type\n");
753 break;
754 }
755 }
756
pld_device_self_recovery(struct device * dev,enum pld_recovery_reason reason)757 void pld_device_self_recovery(struct device *dev,
758 enum pld_recovery_reason reason)
759 {
760 switch (pld_get_bus_type(dev)) {
761 case PLD_BUS_TYPE_PCIE:
762 pld_pcie_device_self_recovery(dev, reason);
763 break;
764 case PLD_BUS_TYPE_PCIE_FW_SIM:
765 case PLD_BUS_TYPE_IPCI_FW_SIM:
766 case PLD_BUS_TYPE_SNOC_FW_SIM:
767 case PLD_BUS_TYPE_SNOC:
768 break;
769 case PLD_BUS_TYPE_IPCI:
770 break;
771 case PLD_BUS_TYPE_SDIO:
772 pld_sdio_device_self_recovery(dev);
773 break;
774 default:
775 pr_err("Invalid device type\n");
776 break;
777 }
778 }
779
pld_intr_notify_q6(struct device * dev)780 void pld_intr_notify_q6(struct device *dev)
781 {
782 switch (pld_get_bus_type(dev)) {
783 case PLD_BUS_TYPE_PCIE:
784 pld_pcie_intr_notify_q6(dev);
785 break;
786 case PLD_BUS_TYPE_PCIE_FW_SIM:
787 case PLD_BUS_TYPE_IPCI_FW_SIM:
788 case PLD_BUS_TYPE_SNOC_FW_SIM:
789 case PLD_BUS_TYPE_SNOC:
790 case PLD_BUS_TYPE_IPCI:
791 break;
792 default:
793 pr_err("Invalid device type\n");
794 break;
795 }
796 }
797
pld_request_pm_qos(struct device * dev,u32 qos_val)798 void pld_request_pm_qos(struct device *dev, u32 qos_val)
799 {
800 switch (pld_get_bus_type(dev)) {
801 case PLD_BUS_TYPE_PCIE:
802 pld_pcie_request_pm_qos(dev, qos_val);
803 break;
804 case PLD_BUS_TYPE_PCIE_FW_SIM:
805 case PLD_BUS_TYPE_IPCI_FW_SIM:
806 case PLD_BUS_TYPE_SNOC_FW_SIM:
807 case PLD_BUS_TYPE_SNOC:
808 break;
809 case PLD_BUS_TYPE_IPCI:
810 break;
811 case PLD_BUS_TYPE_SDIO:
812 /* To do Add call cns API */
813 break;
814 case PLD_BUS_TYPE_USB:
815 break;
816 default:
817 pr_err("Invalid device type\n");
818 break;
819 }
820 }
821
pld_remove_pm_qos(struct device * dev)822 void pld_remove_pm_qos(struct device *dev)
823 {
824 switch (pld_get_bus_type(dev)) {
825 case PLD_BUS_TYPE_PCIE:
826 pld_pcie_remove_pm_qos(dev);
827 break;
828 case PLD_BUS_TYPE_PCIE_FW_SIM:
829 case PLD_BUS_TYPE_IPCI_FW_SIM:
830 case PLD_BUS_TYPE_SNOC_FW_SIM:
831 case PLD_BUS_TYPE_SNOC:
832 break;
833 case PLD_BUS_TYPE_IPCI:
834 break;
835 case PLD_BUS_TYPE_SDIO:
836 /* To do Add call cns API */
837 break;
838 default:
839 pr_err("Invalid device type\n");
840 break;
841 }
842 }
843
pld_request_bus_bandwidth(struct device * dev,int bandwidth)844 int pld_request_bus_bandwidth(struct device *dev, int bandwidth)
845 {
846 int ret = 0;
847
848 switch (pld_get_bus_type(dev)) {
849 case PLD_BUS_TYPE_PCIE:
850 ret = pld_pcie_request_bus_bandwidth(dev, bandwidth);
851 break;
852 case PLD_BUS_TYPE_PCIE_FW_SIM:
853 case PLD_BUS_TYPE_IPCI_FW_SIM:
854 case PLD_BUS_TYPE_SNOC_FW_SIM:
855 case PLD_BUS_TYPE_SNOC:
856 break;
857 case PLD_BUS_TYPE_IPCI:
858 break;
859 case PLD_BUS_TYPE_SDIO:
860 /* To do Add call cns API */
861 break;
862 default:
863 ret = -EINVAL;
864 break;
865 }
866
867 return ret;
868 }
869
pld_is_direct_link_supported(struct device * dev)870 bool pld_is_direct_link_supported(struct device *dev)
871 {
872 bool ret = false;
873
874 switch (pld_get_bus_type(dev)) {
875 case PLD_BUS_TYPE_PCIE:
876 ret = pld_pcie_is_direct_link_supported(dev);
877 break;
878 case PLD_BUS_TYPE_PCIE_FW_SIM:
879 case PLD_BUS_TYPE_IPCI_FW_SIM:
880 case PLD_BUS_TYPE_SNOC_FW_SIM:
881 case PLD_BUS_TYPE_SNOC:
882 case PLD_BUS_TYPE_IPCI:
883 case PLD_BUS_TYPE_SDIO:
884 default:
885 break;
886 }
887
888 return ret;
889 }
890
pld_get_platform_cap(struct device * dev,struct pld_platform_cap * cap)891 int pld_get_platform_cap(struct device *dev, struct pld_platform_cap *cap)
892 {
893 int ret = 0;
894
895 switch (pld_get_bus_type(dev)) {
896 case PLD_BUS_TYPE_PCIE:
897 ret = pld_pcie_get_platform_cap(dev, cap);
898 break;
899 case PLD_BUS_TYPE_PCIE_FW_SIM:
900 case PLD_BUS_TYPE_IPCI_FW_SIM:
901 ret = pld_pcie_fw_sim_get_platform_cap(dev, cap);
902 break;
903 case PLD_BUS_TYPE_SNOC_FW_SIM:
904 case PLD_BUS_TYPE_SNOC:
905 break;
906 case PLD_BUS_TYPE_IPCI:
907 break;
908 case PLD_BUS_TYPE_SDIO:
909 break;
910 default:
911 ret = -EINVAL;
912 break;
913 }
914
915 return ret;
916 }
917
pld_get_sha_hash(struct device * dev,const u8 * data,u32 data_len,u8 * hash_idx,u8 * out)918 int pld_get_sha_hash(struct device *dev, const u8 *data,
919 u32 data_len, u8 *hash_idx, u8 *out)
920 {
921 int ret = 0;
922
923 switch (pld_get_bus_type(dev)) {
924 case PLD_BUS_TYPE_PCIE:
925 ret = pld_pcie_get_sha_hash(dev, data, data_len,
926 hash_idx, out);
927 break;
928 case PLD_BUS_TYPE_PCIE_FW_SIM:
929 case PLD_BUS_TYPE_IPCI_FW_SIM:
930 case PLD_BUS_TYPE_SNOC_FW_SIM:
931 case PLD_BUS_TYPE_SNOC:
932 break;
933 case PLD_BUS_TYPE_IPCI:
934 break;
935 case PLD_BUS_TYPE_SDIO:
936 break;
937 default:
938 ret = -EINVAL;
939 break;
940 }
941
942 return ret;
943 }
944
pld_get_fw_ptr(struct device * dev)945 void *pld_get_fw_ptr(struct device *dev)
946 {
947 void *ptr = NULL;
948
949 switch (pld_get_bus_type(dev)) {
950 case PLD_BUS_TYPE_PCIE:
951 ptr = pld_pcie_get_fw_ptr(dev);
952 break;
953 case PLD_BUS_TYPE_PCIE_FW_SIM:
954 case PLD_BUS_TYPE_IPCI_FW_SIM:
955 case PLD_BUS_TYPE_SNOC_FW_SIM:
956 case PLD_BUS_TYPE_SNOC:
957 case PLD_BUS_TYPE_IPCI:
958 break;
959 case PLD_BUS_TYPE_SDIO:
960 break;
961 default:
962 pr_err("Invalid device type\n");
963 break;
964 }
965
966 return ptr;
967 }
968
pld_auto_suspend(struct device * dev)969 int pld_auto_suspend(struct device *dev)
970 {
971 int ret = 0;
972
973 switch (pld_get_bus_type(dev)) {
974 case PLD_BUS_TYPE_PCIE:
975 ret = pld_pcie_auto_suspend(dev);
976 break;
977 case PLD_BUS_TYPE_PCIE_FW_SIM:
978 case PLD_BUS_TYPE_IPCI_FW_SIM:
979 case PLD_BUS_TYPE_SNOC_FW_SIM:
980 case PLD_BUS_TYPE_SNOC:
981 break;
982 case PLD_BUS_TYPE_IPCI:
983 break;
984 case PLD_BUS_TYPE_SDIO:
985 break;
986 default:
987 ret = -EINVAL;
988 break;
989 }
990
991 return ret;
992 }
993
pld_auto_resume(struct device * dev)994 int pld_auto_resume(struct device *dev)
995 {
996 int ret = 0;
997
998 switch (pld_get_bus_type(dev)) {
999 case PLD_BUS_TYPE_PCIE:
1000 ret = pld_pcie_auto_resume(dev);
1001 break;
1002 case PLD_BUS_TYPE_PCIE_FW_SIM:
1003 case PLD_BUS_TYPE_IPCI_FW_SIM:
1004 case PLD_BUS_TYPE_SNOC_FW_SIM:
1005 case PLD_BUS_TYPE_SNOC:
1006 break;
1007 case PLD_BUS_TYPE_IPCI:
1008 break;
1009 case PLD_BUS_TYPE_SDIO:
1010 break;
1011 default:
1012 ret = -EINVAL;
1013 break;
1014 }
1015
1016 return ret;
1017 }
1018
pld_force_wake_request(struct device * dev)1019 int pld_force_wake_request(struct device *dev)
1020 {
1021 int ret = 0;
1022 enum pld_bus_type type = pld_get_bus_type(dev);
1023
1024 switch (type) {
1025 case PLD_BUS_TYPE_PCIE:
1026 ret = pld_pcie_force_wake_request(dev);
1027 break;
1028 case PLD_BUS_TYPE_PCIE_FW_SIM:
1029 case PLD_BUS_TYPE_IPCI_FW_SIM:
1030 case PLD_BUS_TYPE_SNOC_FW_SIM:
1031 case PLD_BUS_TYPE_SNOC:
1032 case PLD_BUS_TYPE_SDIO:
1033 case PLD_BUS_TYPE_USB:
1034 break;
1035 case PLD_BUS_TYPE_IPCI:
1036 ret = pld_ipci_force_wake_request(dev);
1037 break;
1038 default:
1039 pr_err("Invalid device type %d\n", type);
1040 ret = -EINVAL;
1041 break;
1042 }
1043
1044 return ret;
1045 }
1046
pld_force_wake_request_sync(struct device * dev,int timeout_us)1047 int pld_force_wake_request_sync(struct device *dev, int timeout_us)
1048 {
1049 int ret = 0;
1050 enum pld_bus_type type = pld_get_bus_type(dev);
1051
1052 switch (type) {
1053 case PLD_BUS_TYPE_PCIE:
1054 ret = pld_pcie_force_wake_request_sync(dev, timeout_us);
1055 break;
1056 case PLD_BUS_TYPE_PCIE_FW_SIM:
1057 case PLD_BUS_TYPE_IPCI_FW_SIM:
1058 case PLD_BUS_TYPE_SNOC_FW_SIM:
1059 case PLD_BUS_TYPE_SNOC:
1060 case PLD_BUS_TYPE_SDIO:
1061 case PLD_BUS_TYPE_USB:
1062 case PLD_BUS_TYPE_IPCI:
1063 break;
1064 default:
1065 pr_err("Invalid device type %d\n", type);
1066 ret = -EINVAL;
1067 break;
1068 }
1069
1070 return ret;
1071 }
1072
pld_exit_power_save(struct device * dev)1073 int pld_exit_power_save(struct device *dev)
1074 {
1075 int ret = 0;
1076 enum pld_bus_type type = pld_get_bus_type(dev);
1077
1078 switch (type) {
1079 case PLD_BUS_TYPE_PCIE:
1080 case PLD_BUS_TYPE_PCIE_FW_SIM:
1081 case PLD_BUS_TYPE_SNOC_FW_SIM:
1082 case PLD_BUS_TYPE_SNOC:
1083 case PLD_BUS_TYPE_SDIO:
1084 case PLD_BUS_TYPE_USB:
1085 break;
1086 case PLD_BUS_TYPE_IPCI_FW_SIM:
1087 ret = pld_pcie_fw_sim_exit_power_save(dev);
1088 break;
1089 case PLD_BUS_TYPE_IPCI:
1090 ret = pld_ipci_exit_power_save(dev);
1091 break;
1092 default:
1093 pr_err("Invalid device type %d\n", type);
1094 ret = -EINVAL;
1095 break;
1096 }
1097
1098 return ret;
1099 }
1100
pld_is_device_awake(struct device * dev)1101 int pld_is_device_awake(struct device *dev)
1102 {
1103 int ret = true;
1104 enum pld_bus_type type = pld_get_bus_type(dev);
1105
1106 switch (type) {
1107 case PLD_BUS_TYPE_PCIE:
1108 ret = pld_pcie_is_device_awake(dev);
1109 break;
1110 case PLD_BUS_TYPE_PCIE_FW_SIM:
1111 case PLD_BUS_TYPE_IPCI_FW_SIM:
1112 case PLD_BUS_TYPE_SNOC_FW_SIM:
1113 case PLD_BUS_TYPE_SNOC:
1114 case PLD_BUS_TYPE_SDIO:
1115 case PLD_BUS_TYPE_USB:
1116 break;
1117 case PLD_BUS_TYPE_IPCI:
1118 ret = pld_ipci_is_device_awake(dev);
1119 break;
1120 default:
1121 pr_err("Invalid device type %d\n", type);
1122 ret = -EINVAL;
1123 break;
1124 }
1125
1126 return ret;
1127 }
1128
pld_is_pci_ep_awake(struct device * dev)1129 int pld_is_pci_ep_awake(struct device *dev)
1130 {
1131 int ret = true;
1132 enum pld_bus_type type = pld_get_bus_type(dev);
1133
1134 switch (type) {
1135 case PLD_BUS_TYPE_PCIE:
1136 case PLD_BUS_TYPE_PCIE_FW_SIM:
1137 case PLD_BUS_TYPE_IPCI_FW_SIM:
1138 case PLD_BUS_TYPE_SNOC_FW_SIM:
1139 case PLD_BUS_TYPE_SNOC:
1140 case PLD_BUS_TYPE_SDIO:
1141 case PLD_BUS_TYPE_USB:
1142 ret = -ENOTSUPP;
1143 break;
1144 case PLD_BUS_TYPE_IPCI:
1145 ret = pld_ipci_is_pci_ep_awake(dev);
1146 break;
1147 default:
1148 pr_err("Invalid device type %d\n", type);
1149 ret = -EINVAL;
1150 break;
1151 }
1152
1153 return ret;
1154 }
1155
pld_force_wake_release(struct device * dev)1156 int pld_force_wake_release(struct device *dev)
1157 {
1158 int ret = 0;
1159 enum pld_bus_type type = pld_get_bus_type(dev);
1160
1161 switch (type) {
1162 case PLD_BUS_TYPE_PCIE:
1163 ret = pld_pcie_force_wake_release(dev);
1164 break;
1165 case PLD_BUS_TYPE_PCIE_FW_SIM:
1166 case PLD_BUS_TYPE_IPCI_FW_SIM:
1167 case PLD_BUS_TYPE_SNOC_FW_SIM:
1168 case PLD_BUS_TYPE_SNOC:
1169 case PLD_BUS_TYPE_SDIO:
1170 case PLD_BUS_TYPE_USB:
1171 break;
1172 case PLD_BUS_TYPE_IPCI:
1173 ret = pld_ipci_force_wake_release(dev);
1174 break;
1175 default:
1176 pr_err("Invalid device type %d\n", type);
1177 ret = -EINVAL;
1178 break;
1179 }
1180
1181 return ret;
1182 }
1183
pld_ce_request_irq(struct device * dev,unsigned int ce_id,irqreturn_t (* handler)(int,void *),unsigned long flags,const char * name,void * ctx)1184 int pld_ce_request_irq(struct device *dev, unsigned int ce_id,
1185 irqreturn_t (*handler)(int, void *),
1186 unsigned long flags, const char *name, void *ctx)
1187 {
1188 int ret = 0;
1189
1190 switch (pld_get_bus_type(dev)) {
1191 case PLD_BUS_TYPE_SNOC:
1192 ret = pld_snoc_ce_request_irq(dev, ce_id,
1193 handler, flags, name, ctx);
1194 break;
1195 case PLD_BUS_TYPE_SNOC_FW_SIM:
1196 ret = pld_snoc_fw_sim_ce_request_irq(dev, ce_id,
1197 handler, flags, name, ctx);
1198 break;
1199 case PLD_BUS_TYPE_PCIE_FW_SIM:
1200 case PLD_BUS_TYPE_IPCI_FW_SIM:
1201 case PLD_BUS_TYPE_PCIE:
1202 break;
1203 case PLD_BUS_TYPE_IPCI:
1204 break;
1205 default:
1206 ret = -EINVAL;
1207 break;
1208 }
1209
1210 return ret;
1211 }
1212
pld_ce_free_irq(struct device * dev,unsigned int ce_id,void * ctx)1213 int pld_ce_free_irq(struct device *dev, unsigned int ce_id, void *ctx)
1214 {
1215 int ret = 0;
1216
1217 switch (pld_get_bus_type(dev)) {
1218 case PLD_BUS_TYPE_SNOC:
1219 ret = pld_snoc_ce_free_irq(dev, ce_id, ctx);
1220 break;
1221 case PLD_BUS_TYPE_SNOC_FW_SIM:
1222 ret = pld_snoc_fw_sim_ce_free_irq(dev, ce_id, ctx);
1223 break;
1224 case PLD_BUS_TYPE_PCIE_FW_SIM:
1225 case PLD_BUS_TYPE_IPCI_FW_SIM:
1226 case PLD_BUS_TYPE_PCIE:
1227 break;
1228 case PLD_BUS_TYPE_IPCI:
1229 break;
1230 default:
1231 ret = -EINVAL;
1232 break;
1233 }
1234
1235 return ret;
1236 }
1237
pld_enable_irq(struct device * dev,unsigned int ce_id)1238 void pld_enable_irq(struct device *dev, unsigned int ce_id)
1239 {
1240 switch (pld_get_bus_type(dev)) {
1241 case PLD_BUS_TYPE_SNOC:
1242 pld_snoc_enable_irq(dev, ce_id);
1243 break;
1244 case PLD_BUS_TYPE_SNOC_FW_SIM:
1245 pld_snoc_fw_sim_enable_irq(dev, ce_id);
1246 break;
1247 case PLD_BUS_TYPE_PCIE_FW_SIM:
1248 case PLD_BUS_TYPE_IPCI_FW_SIM:
1249 case PLD_BUS_TYPE_PCIE:
1250 case PLD_BUS_TYPE_IPCI:
1251 break;
1252 case PLD_BUS_TYPE_SDIO:
1253 break;
1254 default:
1255 pr_err("Invalid device type\n");
1256 break;
1257 }
1258 }
1259
pld_disable_irq(struct device * dev,unsigned int ce_id)1260 void pld_disable_irq(struct device *dev, unsigned int ce_id)
1261 {
1262 switch (pld_get_bus_type(dev)) {
1263 case PLD_BUS_TYPE_SNOC:
1264 pld_snoc_disable_irq(dev, ce_id);
1265 break;
1266 case PLD_BUS_TYPE_SNOC_FW_SIM:
1267 pld_snoc_fw_sim_disable_irq(dev, ce_id);
1268 break;
1269 case PLD_BUS_TYPE_PCIE_FW_SIM:
1270 case PLD_BUS_TYPE_IPCI_FW_SIM:
1271 case PLD_BUS_TYPE_PCIE:
1272 case PLD_BUS_TYPE_IPCI:
1273 break;
1274 case PLD_BUS_TYPE_SDIO:
1275 break;
1276 default:
1277 pr_err("Invalid device type\n");
1278 break;
1279 }
1280 }
1281
pld_get_soc_info(struct device * dev,struct pld_soc_info * info)1282 int pld_get_soc_info(struct device *dev, struct pld_soc_info *info)
1283 {
1284 int ret = 0;
1285 memset(info, 0, sizeof(*info));
1286
1287 switch (pld_get_bus_type(dev)) {
1288 case PLD_BUS_TYPE_SNOC:
1289 ret = pld_snoc_get_soc_info(dev, info);
1290 break;
1291 case PLD_BUS_TYPE_SNOC_FW_SIM:
1292 ret = pld_snoc_fw_sim_get_soc_info(dev, info);
1293 break;
1294 case PLD_BUS_TYPE_PCIE_FW_SIM:
1295 case PLD_BUS_TYPE_IPCI_FW_SIM:
1296 ret = pld_pcie_fw_sim_get_soc_info(dev, info);
1297 break;
1298 case PLD_BUS_TYPE_PCIE:
1299 ret = pld_pcie_get_soc_info(dev, info);
1300 break;
1301 case PLD_BUS_TYPE_SDIO:
1302 break;
1303 case PLD_BUS_TYPE_IPCI:
1304 ret = pld_ipci_get_soc_info(dev, info);
1305 break;
1306 default:
1307 ret = -EINVAL;
1308 break;
1309 }
1310
1311 return ret;
1312 }
1313
pld_get_ce_id(struct device * dev,int irq)1314 int pld_get_ce_id(struct device *dev, int irq)
1315 {
1316 int ret = 0;
1317
1318 switch (pld_get_bus_type(dev)) {
1319 case PLD_BUS_TYPE_SNOC:
1320 ret = pld_snoc_get_ce_id(dev, irq);
1321 break;
1322 case PLD_BUS_TYPE_SNOC_FW_SIM:
1323 ret = pld_snoc_fw_sim_get_ce_id(dev, irq);
1324 break;
1325 case PLD_BUS_TYPE_PCIE:
1326 ret = pld_pcie_get_ce_id(dev, irq);
1327 break;
1328 case PLD_BUS_TYPE_PCIE_FW_SIM:
1329 case PLD_BUS_TYPE_IPCI_FW_SIM:
1330 break;
1331 case PLD_BUS_TYPE_IPCI:
1332 break;
1333 default:
1334 ret = -EINVAL;
1335 break;
1336 }
1337
1338 return ret;
1339 }
1340
pld_get_irq(struct device * dev,int ce_id)1341 int pld_get_irq(struct device *dev, int ce_id)
1342 {
1343 int ret = 0;
1344
1345 switch (pld_get_bus_type(dev)) {
1346 case PLD_BUS_TYPE_SNOC:
1347 ret = pld_snoc_get_irq(dev, ce_id);
1348 break;
1349 case PLD_BUS_TYPE_SNOC_FW_SIM:
1350 ret = pld_snoc_fw_sim_get_irq(dev, ce_id);
1351 break;
1352 case PLD_BUS_TYPE_IPCI:
1353 ret = pld_ipci_get_irq(dev, ce_id);
1354 break;
1355 case PLD_BUS_TYPE_PCIE_FW_SIM:
1356 case PLD_BUS_TYPE_IPCI_FW_SIM:
1357 ret = pld_pcie_fw_sim_get_irq(dev, ce_id);
1358 break;
1359 case PLD_BUS_TYPE_PCIE:
1360 default:
1361 ret = -EINVAL;
1362 break;
1363 }
1364
1365 return ret;
1366 }
1367
pld_lock_reg_window(struct device * dev,unsigned long * flags)1368 void pld_lock_reg_window(struct device *dev, unsigned long *flags)
1369 {
1370 switch (pld_get_bus_type(dev)) {
1371 case PLD_BUS_TYPE_PCIE:
1372 pld_pcie_lock_reg_window(dev, flags);
1373 break;
1374 case PLD_BUS_TYPE_PCIE_FW_SIM:
1375 case PLD_BUS_TYPE_IPCI_FW_SIM:
1376 case PLD_BUS_TYPE_SNOC_FW_SIM:
1377 case PLD_BUS_TYPE_SNOC:
1378 case PLD_BUS_TYPE_IPCI:
1379 break;
1380 case PLD_BUS_TYPE_SDIO:
1381 break;
1382 case PLD_BUS_TYPE_USB:
1383 break;
1384 default:
1385 pr_err("Invalid device type\n");
1386 break;
1387 }
1388 }
1389
pld_unlock_reg_window(struct device * dev,unsigned long * flags)1390 void pld_unlock_reg_window(struct device *dev, unsigned long *flags)
1391 {
1392 switch (pld_get_bus_type(dev)) {
1393 case PLD_BUS_TYPE_PCIE:
1394 pld_pcie_unlock_reg_window(dev, flags);
1395 break;
1396 case PLD_BUS_TYPE_PCIE_FW_SIM:
1397 case PLD_BUS_TYPE_IPCI_FW_SIM:
1398 case PLD_BUS_TYPE_SNOC_FW_SIM:
1399 case PLD_BUS_TYPE_SNOC:
1400 case PLD_BUS_TYPE_IPCI:
1401 break;
1402 case PLD_BUS_TYPE_SDIO:
1403 break;
1404 case PLD_BUS_TYPE_USB:
1405 break;
1406 default:
1407 pr_err("Invalid device type\n");
1408 break;
1409 }
1410 }
1411
pld_get_pci_slot(struct device * dev)1412 int pld_get_pci_slot(struct device *dev)
1413 {
1414 int ret = 0;
1415
1416 switch (pld_get_bus_type(dev)) {
1417 case PLD_BUS_TYPE_PCIE:
1418 ret = pld_pcie_get_pci_slot(dev);
1419 break;
1420 case PLD_BUS_TYPE_PCIE_FW_SIM:
1421 case PLD_BUS_TYPE_IPCI_FW_SIM:
1422 case PLD_BUS_TYPE_SNOC_FW_SIM:
1423 case PLD_BUS_TYPE_SNOC:
1424 case PLD_BUS_TYPE_IPCI:
1425 break;
1426 default:
1427 pr_err("Invalid device type\n");
1428 ret = -EINVAL;
1429 break;
1430 }
1431
1432 return ret;
1433 }
1434
pld_power_on(struct device * dev)1435 int pld_power_on(struct device *dev)
1436 {
1437 int ret = 0;
1438
1439 switch (pld_get_bus_type(dev)) {
1440 case PLD_BUS_TYPE_PCIE:
1441 /* cnss platform driver handles PCIe SoC
1442 * power on/off sequence so let CNSS driver
1443 * handle the power on sequence for PCIe SoC
1444 */
1445 break;
1446 case PLD_BUS_TYPE_PCIE_FW_SIM:
1447 case PLD_BUS_TYPE_IPCI_FW_SIM:
1448 case PLD_BUS_TYPE_SNOC_FW_SIM:
1449 break;
1450 case PLD_BUS_TYPE_SNOC:
1451 ret = pld_snoc_power_on(dev);
1452 break;
1453 case PLD_BUS_TYPE_IPCI:
1454 ret = pld_ipci_power_on(dev);
1455 break;
1456 default:
1457 pr_err("Invalid device type\n");
1458 break;
1459 }
1460
1461 return ret;
1462 }
1463
pld_power_off(struct device * dev)1464 int pld_power_off(struct device *dev)
1465 {
1466 int ret = 0;
1467
1468 switch (pld_get_bus_type(dev)) {
1469 case PLD_BUS_TYPE_PCIE:
1470 /* cnss platform driver handles PCIe SoC
1471 * power on/off sequence so let CNSS driver
1472 * handle the power off sequence for PCIe SoC
1473 */
1474 break;
1475 case PLD_BUS_TYPE_PCIE_FW_SIM:
1476 case PLD_BUS_TYPE_IPCI_FW_SIM:
1477 case PLD_BUS_TYPE_SNOC_FW_SIM:
1478 break;
1479 case PLD_BUS_TYPE_SNOC:
1480 ret = pld_snoc_power_off(dev);
1481 break;
1482 case PLD_BUS_TYPE_IPCI:
1483 ret = pld_ipci_power_off(dev);
1484 break;
1485 default:
1486 pr_err("Invalid device type\n");
1487 break;
1488 }
1489
1490 return ret;
1491 }
1492
pld_athdiag_read(struct device * dev,uint32_t offset,uint32_t memtype,uint32_t datalen,uint8_t * output)1493 int pld_athdiag_read(struct device *dev, uint32_t offset,
1494 uint32_t memtype, uint32_t datalen,
1495 uint8_t *output)
1496 {
1497 int ret = 0;
1498
1499 switch (pld_get_bus_type(dev)) {
1500 case PLD_BUS_TYPE_SNOC:
1501 ret = pld_snoc_athdiag_read(dev, offset, memtype,
1502 datalen, output);
1503 break;
1504 case PLD_BUS_TYPE_PCIE:
1505 ret = pld_pcie_athdiag_read(dev, offset, memtype,
1506 datalen, output);
1507 break;
1508 case PLD_BUS_TYPE_SDIO:
1509 break;
1510 case PLD_BUS_TYPE_USB:
1511 ret = pld_usb_athdiag_read(dev, offset, memtype,
1512 datalen, output);
1513 break;
1514 case PLD_BUS_TYPE_IPCI:
1515 ret = pld_ipci_athdiag_read(dev, offset, memtype,
1516 datalen, output);
1517 break;
1518 case PLD_BUS_TYPE_PCIE_FW_SIM:
1519 case PLD_BUS_TYPE_IPCI_FW_SIM:
1520 case PLD_BUS_TYPE_SNOC_FW_SIM:
1521 break;
1522 default:
1523 ret = -EINVAL;
1524 break;
1525 }
1526
1527 return ret;
1528 }
1529
pld_athdiag_write(struct device * dev,uint32_t offset,uint32_t memtype,uint32_t datalen,uint8_t * input)1530 int pld_athdiag_write(struct device *dev, uint32_t offset,
1531 uint32_t memtype, uint32_t datalen,
1532 uint8_t *input)
1533 {
1534 int ret = 0;
1535
1536 switch (pld_get_bus_type(dev)) {
1537 case PLD_BUS_TYPE_SNOC:
1538 ret = pld_snoc_athdiag_write(dev, offset, memtype,
1539 datalen, input);
1540 break;
1541 case PLD_BUS_TYPE_PCIE:
1542 ret = pld_pcie_athdiag_write(dev, offset, memtype,
1543 datalen, input);
1544 break;
1545 case PLD_BUS_TYPE_SDIO:
1546 break;
1547 case PLD_BUS_TYPE_USB:
1548 ret = pld_usb_athdiag_write(dev, offset, memtype,
1549 datalen, input);
1550 break;
1551 case PLD_BUS_TYPE_IPCI:
1552 ret = pld_ipci_athdiag_write(dev, offset, memtype,
1553 datalen, input);
1554 break;
1555 case PLD_BUS_TYPE_PCIE_FW_SIM:
1556 case PLD_BUS_TYPE_IPCI_FW_SIM:
1557 case PLD_BUS_TYPE_SNOC_FW_SIM:
1558 break;
1559 default:
1560 ret = -EINVAL;
1561 break;
1562 }
1563
1564 return ret;
1565 }
1566
1567 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0))
pld_smmu_get_domain(struct device * dev)1568 void *pld_smmu_get_domain(struct device *dev)
1569 {
1570 void *ptr = NULL;
1571 enum pld_bus_type type = pld_get_bus_type(dev);
1572
1573 switch (type) {
1574 case PLD_BUS_TYPE_SNOC:
1575 ptr = pld_snoc_smmu_get_domain(dev);
1576 break;
1577 case PLD_BUS_TYPE_PCIE:
1578 ptr = pld_pcie_smmu_get_domain(dev);
1579 break;
1580 case PLD_BUS_TYPE_PCIE_FW_SIM:
1581 case PLD_BUS_TYPE_IPCI_FW_SIM:
1582 case PLD_BUS_TYPE_SNOC_FW_SIM:
1583 break;
1584 case PLD_BUS_TYPE_IPCI:
1585 ptr = pld_ipci_smmu_get_domain(dev);
1586 break;
1587 case PLD_BUS_TYPE_SDIO:
1588 case PLD_BUS_TYPE_USB:
1589 pr_err("Not supported on type %d\n", type);
1590 break;
1591 default:
1592 pr_err("Invalid device type %d\n", type);
1593 break;
1594 }
1595
1596 return ptr;
1597 }
1598 #else
pld_smmu_get_mapping(struct device * dev)1599 void *pld_smmu_get_mapping(struct device *dev)
1600 {
1601 void *ptr = NULL;
1602 enum pld_bus_type type = pld_get_bus_type(dev);
1603
1604 switch (type) {
1605 case PLD_BUS_TYPE_SNOC:
1606 ptr = pld_snoc_smmu_get_mapping(dev);
1607 break;
1608 case PLD_BUS_TYPE_PCIE_FW_SIM:
1609 case PLD_BUS_TYPE_IPCI_FW_SIM:
1610 case PLD_BUS_TYPE_SNOC_FW_SIM:
1611 break;
1612 case PLD_BUS_TYPE_IPCI:
1613 break;
1614 case PLD_BUS_TYPE_PCIE:
1615 ptr = pld_pcie_smmu_get_mapping(dev);
1616 break;
1617 default:
1618 pr_err("Invalid device type %d\n", type);
1619 break;
1620 }
1621
1622 return ptr;
1623 }
1624 #endif
1625
1626 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0))
pld_get_wifi_kobj(struct device * dev)1627 struct kobject *pld_get_wifi_kobj(struct device *dev)
1628 {
1629 struct kobject *wifi_kobj = NULL;
1630
1631 wifi_kobj = pld_pcie_get_wifi_kobj(dev);
1632
1633 return wifi_kobj;
1634 }
1635 #endif
1636
pld_smmu_map(struct device * dev,phys_addr_t paddr,uint32_t * iova_addr,size_t size)1637 int pld_smmu_map(struct device *dev, phys_addr_t paddr,
1638 uint32_t *iova_addr, size_t size)
1639 {
1640 int ret = 0;
1641 enum pld_bus_type type = pld_get_bus_type(dev);
1642
1643 switch (type) {
1644 case PLD_BUS_TYPE_SNOC:
1645 ret = pld_snoc_smmu_map(dev, paddr, iova_addr, size);
1646 break;
1647 case PLD_BUS_TYPE_PCIE_FW_SIM:
1648 case PLD_BUS_TYPE_IPCI_FW_SIM:
1649 case PLD_BUS_TYPE_SNOC_FW_SIM:
1650 break;
1651 case PLD_BUS_TYPE_IPCI:
1652 ret = pld_ipci_smmu_map(dev, paddr, iova_addr, size);
1653 break;
1654 case PLD_BUS_TYPE_PCIE:
1655 ret = pld_pcie_smmu_map(dev, paddr, iova_addr, size);
1656 break;
1657 default:
1658 pr_err("Invalid device type %d\n", type);
1659 ret = -EINVAL;
1660 break;
1661 }
1662
1663 return ret;
1664 }
1665
1666 #ifdef CONFIG_SMMU_S1_UNMAP
pld_smmu_unmap(struct device * dev,uint32_t iova_addr,size_t size)1667 int pld_smmu_unmap(struct device *dev,
1668 uint32_t iova_addr, size_t size)
1669 {
1670 int ret = 0;
1671 enum pld_bus_type type = pld_get_bus_type(dev);
1672
1673 switch (type) {
1674 case PLD_BUS_TYPE_SNOC:
1675 ret = pld_snoc_smmu_unmap(dev, iova_addr, size);
1676 break;
1677 case PLD_BUS_TYPE_PCIE:
1678 ret = pld_pcie_smmu_unmap(dev, iova_addr, size);
1679 break;
1680 case PLD_BUS_TYPE_IPCI:
1681 ret = pld_ipci_smmu_unmap(dev, iova_addr, size);
1682 break;
1683 case PLD_BUS_TYPE_PCIE_FW_SIM:
1684 case PLD_BUS_TYPE_IPCI_FW_SIM:
1685 case PLD_BUS_TYPE_SNOC_FW_SIM:
1686 pr_err("Not supported on type %d\n", type);
1687 break;
1688 default:
1689 pr_err("Invalid device type %d\n", type);
1690 ret = -EINVAL;
1691 break;
1692 }
1693
1694 return ret;
1695 }
1696 #endif
1697
pld_get_user_msi_assignment(struct device * dev,char * user_name,int * num_vectors,uint32_t * user_base_data,uint32_t * base_vector)1698 int pld_get_user_msi_assignment(struct device *dev, char *user_name,
1699 int *num_vectors, uint32_t *user_base_data,
1700 uint32_t *base_vector)
1701 {
1702 int ret = 0;
1703 enum pld_bus_type type = pld_get_bus_type(dev);
1704
1705 switch (type) {
1706 case PLD_BUS_TYPE_PCIE:
1707 ret = pld_pcie_get_user_msi_assignment(dev, user_name,
1708 num_vectors,
1709 user_base_data,
1710 base_vector);
1711 break;
1712 case PLD_BUS_TYPE_PCIE_FW_SIM:
1713 case PLD_BUS_TYPE_IPCI_FW_SIM:
1714 ret = pld_pcie_fw_sim_get_user_msi_assignment(dev, user_name,
1715 num_vectors,
1716 user_base_data,
1717 base_vector);
1718 break;
1719 case PLD_BUS_TYPE_SNOC:
1720 case PLD_BUS_TYPE_SDIO:
1721 case PLD_BUS_TYPE_USB:
1722 case PLD_BUS_TYPE_SNOC_FW_SIM:
1723 pr_err("Not supported on type %d\n", type);
1724 ret = -ENODEV;
1725 break;
1726 case PLD_BUS_TYPE_IPCI:
1727 ret = pld_ipci_get_user_msi_assignment(dev, user_name,
1728 num_vectors,
1729 user_base_data,
1730 base_vector);
1731 break;
1732 default:
1733 pr_err("Invalid device type %d\n", type);
1734 ret = -EINVAL;
1735 break;
1736 }
1737
1738 return ret;
1739 }
1740
pld_srng_devm_request_irq(struct device * dev,int irq,irq_handler_t handler,unsigned long irqflags,const char * devname,void * dev_data)1741 int pld_srng_devm_request_irq(struct device *dev, int irq,
1742 irq_handler_t handler,
1743 unsigned long irqflags,
1744 const char *devname,
1745 void *dev_data)
1746 {
1747 int ret = 0;
1748 enum pld_bus_type type = pld_get_bus_type(dev);
1749
1750 switch (type) {
1751 case PLD_BUS_TYPE_PCIE:
1752 ret = devm_request_irq(dev, irq, handler, irqflags,
1753 devname, dev_data);
1754 break;
1755 case PLD_BUS_TYPE_PCIE_FW_SIM:
1756 case PLD_BUS_TYPE_IPCI_FW_SIM:
1757 ret = pld_pcie_fw_sim_request_irq(dev, irq, handler,
1758 irqflags, devname,
1759 dev_data);
1760 break;
1761 case PLD_BUS_TYPE_SNOC:
1762 case PLD_BUS_TYPE_SDIO:
1763 case PLD_BUS_TYPE_USB:
1764 case PLD_BUS_TYPE_SNOC_FW_SIM:
1765 pr_err("Not supported on type %d\n", type);
1766 ret = -ENODEV;
1767 break;
1768 case PLD_BUS_TYPE_IPCI:
1769 ret = devm_request_irq(dev, irq, handler, irqflags,
1770 devname, dev_data);
1771 break;
1772 default:
1773 pr_err("Invalid device type %d\n", type);
1774 ret = -EINVAL;
1775 break;
1776 }
1777
1778 return ret;
1779 }
1780
pld_srng_request_irq(struct device * dev,int irq,irq_handler_t handler,unsigned long irqflags,const char * devname,void * dev_data)1781 int pld_srng_request_irq(struct device *dev, int irq, irq_handler_t handler,
1782 unsigned long irqflags,
1783 const char *devname,
1784 void *dev_data)
1785 {
1786 int ret = 0;
1787 enum pld_bus_type type = pld_get_bus_type(dev);
1788
1789 switch (type) {
1790 case PLD_BUS_TYPE_PCIE:
1791 ret = request_irq(irq, handler, irqflags, devname, dev_data);
1792 break;
1793 case PLD_BUS_TYPE_PCIE_FW_SIM:
1794 case PLD_BUS_TYPE_IPCI_FW_SIM:
1795 ret = pld_pcie_fw_sim_request_irq(dev, irq, handler,
1796 irqflags, devname,
1797 dev_data);
1798 break;
1799 case PLD_BUS_TYPE_SNOC:
1800 case PLD_BUS_TYPE_SDIO:
1801 case PLD_BUS_TYPE_USB:
1802 case PLD_BUS_TYPE_SNOC_FW_SIM:
1803 pr_err("Not supported on type %d\n", type);
1804 ret = -ENODEV;
1805 break;
1806 case PLD_BUS_TYPE_IPCI:
1807 ret = request_irq(irq, handler, irqflags, devname, dev_data);
1808 break;
1809 default:
1810 pr_err("Invalid device type %d\n", type);
1811 ret = -EINVAL;
1812 break;
1813 }
1814
1815 return ret;
1816 }
1817
pld_srng_free_irq(struct device * dev,int irq,void * dev_data)1818 int pld_srng_free_irq(struct device *dev, int irq, void *dev_data)
1819 {
1820 int ret = 0;
1821 enum pld_bus_type type = pld_get_bus_type(dev);
1822
1823 switch (type) {
1824 case PLD_BUS_TYPE_PCIE:
1825 free_irq(irq, dev_data);
1826 break;
1827 case PLD_BUS_TYPE_PCIE_FW_SIM:
1828 case PLD_BUS_TYPE_IPCI_FW_SIM:
1829 ret = pld_pcie_fw_sim_free_irq(dev, irq, dev_data);
1830 break;
1831 case PLD_BUS_TYPE_SNOC:
1832 case PLD_BUS_TYPE_SDIO:
1833 case PLD_BUS_TYPE_USB:
1834 case PLD_BUS_TYPE_SNOC_FW_SIM:
1835 pr_err("Not supported on type %d\n", type);
1836 ret = -ENODEV;
1837 break;
1838 case PLD_BUS_TYPE_IPCI:
1839 free_irq(irq, dev_data);
1840 break;
1841 default:
1842 pr_err("Invalid device type %d\n", type);
1843 ret = -EINVAL;
1844 break;
1845 }
1846
1847 return ret;
1848 }
1849
pld_srng_enable_irq(struct device * dev,int irq)1850 void pld_srng_enable_irq(struct device *dev, int irq)
1851 {
1852 switch (pld_get_bus_type(dev)) {
1853 case PLD_BUS_TYPE_SNOC:
1854 case PLD_BUS_TYPE_SNOC_FW_SIM:
1855 break;
1856 case PLD_BUS_TYPE_PCIE_FW_SIM:
1857 case PLD_BUS_TYPE_IPCI_FW_SIM:
1858 pld_pcie_fw_sim_enable_irq(dev, irq);
1859 break;
1860 case PLD_BUS_TYPE_PCIE:
1861 enable_irq(irq);
1862 break;
1863 case PLD_BUS_TYPE_SDIO:
1864 break;
1865 case PLD_BUS_TYPE_IPCI:
1866 enable_irq(irq);
1867 break;
1868 default:
1869 pr_err("Invalid device type\n");
1870 break;
1871 }
1872 }
1873
pld_srng_disable_irq(struct device * dev,int irq)1874 void pld_srng_disable_irq(struct device *dev, int irq)
1875 {
1876 switch (pld_get_bus_type(dev)) {
1877 case PLD_BUS_TYPE_SNOC:
1878 case PLD_BUS_TYPE_SNOC_FW_SIM:
1879 break;
1880 case PLD_BUS_TYPE_PCIE_FW_SIM:
1881 case PLD_BUS_TYPE_IPCI_FW_SIM:
1882 pld_pcie_fw_sim_disable_irq(dev, irq);
1883 break;
1884 case PLD_BUS_TYPE_PCIE:
1885 disable_irq_nosync(irq);
1886 break;
1887 case PLD_BUS_TYPE_SDIO:
1888 break;
1889 case PLD_BUS_TYPE_IPCI:
1890 disable_irq_nosync(irq);
1891 break;
1892 default:
1893 pr_err("Invalid device type\n");
1894 break;
1895 }
1896 }
1897
pld_srng_disable_irq_sync(struct device * dev,int irq)1898 void pld_srng_disable_irq_sync(struct device *dev, int irq)
1899 {
1900 switch (pld_get_bus_type(dev)) {
1901 case PLD_BUS_TYPE_SNOC:
1902 case PLD_BUS_TYPE_SNOC_FW_SIM:
1903 break;
1904 case PLD_BUS_TYPE_PCIE_FW_SIM:
1905 case PLD_BUS_TYPE_IPCI_FW_SIM:
1906 pld_pcie_fw_sim_disable_irq(dev, irq);
1907 break;
1908 case PLD_BUS_TYPE_PCIE:
1909 case PLD_BUS_TYPE_IPCI:
1910 disable_irq(irq);
1911 break;
1912 case PLD_BUS_TYPE_SDIO:
1913 break;
1914 default:
1915 pr_err("Invalid device type\n");
1916 break;
1917 }
1918 }
1919
pld_pci_read_config_word(struct pci_dev * pdev,int offset,uint16_t * val)1920 int pld_pci_read_config_word(struct pci_dev *pdev, int offset, uint16_t *val)
1921 {
1922 int ret = 0;
1923
1924 switch (pld_get_bus_type(&pdev->dev)) {
1925 case PLD_BUS_TYPE_SNOC:
1926 case PLD_BUS_TYPE_SNOC_FW_SIM:
1927 break;
1928 case PLD_BUS_TYPE_PCIE_FW_SIM:
1929 case PLD_BUS_TYPE_IPCI_FW_SIM:
1930 ret = pld_pcie_fw_sim_read_config_word(&pdev->dev, offset, val);
1931 break;
1932 case PLD_BUS_TYPE_IPCI:
1933 break;
1934 case PLD_BUS_TYPE_PCIE:
1935 ret = pci_read_config_word(pdev, offset, val);
1936 break;
1937 case PLD_BUS_TYPE_SDIO:
1938 break;
1939 default:
1940 pr_err("Invalid device type\n");
1941 break;
1942 }
1943
1944 return ret;
1945 }
1946
pld_pci_write_config_word(struct pci_dev * pdev,int offset,uint16_t val)1947 int pld_pci_write_config_word(struct pci_dev *pdev, int offset, uint16_t val)
1948 {
1949 int ret = 0;
1950
1951 switch (pld_get_bus_type(&pdev->dev)) {
1952 case PLD_BUS_TYPE_SNOC:
1953 case PLD_BUS_TYPE_SNOC_FW_SIM:
1954 break;
1955 case PLD_BUS_TYPE_PCIE_FW_SIM:
1956 case PLD_BUS_TYPE_IPCI_FW_SIM:
1957 break;
1958 case PLD_BUS_TYPE_PCIE:
1959 ret = pci_write_config_word(pdev, offset, val);
1960 break;
1961 case PLD_BUS_TYPE_SDIO:
1962 break;
1963 case PLD_BUS_TYPE_IPCI:
1964 break;
1965 default:
1966 pr_err("Invalid device type\n");
1967 break;
1968 }
1969
1970 return ret;
1971 }
1972
pld_pci_read_config_dword(struct pci_dev * pdev,int offset,uint32_t * val)1973 int pld_pci_read_config_dword(struct pci_dev *pdev, int offset, uint32_t *val)
1974 {
1975 int ret = 0;
1976
1977 switch (pld_get_bus_type(&pdev->dev)) {
1978 case PLD_BUS_TYPE_SNOC:
1979 case PLD_BUS_TYPE_SNOC_FW_SIM:
1980 break;
1981 case PLD_BUS_TYPE_PCIE_FW_SIM:
1982 case PLD_BUS_TYPE_IPCI_FW_SIM:
1983 break;
1984 case PLD_BUS_TYPE_PCIE:
1985 ret = pci_read_config_dword(pdev, offset, val);
1986 break;
1987 case PLD_BUS_TYPE_SDIO:
1988 break;
1989 case PLD_BUS_TYPE_IPCI:
1990 break;
1991 default:
1992 pr_err("Invalid device type\n");
1993 break;
1994 }
1995
1996 return ret;
1997 }
1998
pld_pci_write_config_dword(struct pci_dev * pdev,int offset,uint32_t val)1999 int pld_pci_write_config_dword(struct pci_dev *pdev, int offset, uint32_t val)
2000 {
2001 int ret = 0;
2002
2003 switch (pld_get_bus_type(&pdev->dev)) {
2004 case PLD_BUS_TYPE_SNOC:
2005 case PLD_BUS_TYPE_SNOC_FW_SIM:
2006 break;
2007 case PLD_BUS_TYPE_PCIE_FW_SIM:
2008 case PLD_BUS_TYPE_IPCI_FW_SIM:
2009 break;
2010 case PLD_BUS_TYPE_PCIE:
2011 ret = pci_write_config_dword(pdev, offset, val);
2012 break;
2013 case PLD_BUS_TYPE_SDIO:
2014 break;
2015 case PLD_BUS_TYPE_IPCI:
2016 break;
2017 default:
2018 pr_err("Invalid device type\n");
2019 break;
2020 }
2021
2022 return ret;
2023 }
2024
pld_get_msi_irq(struct device * dev,unsigned int vector)2025 int pld_get_msi_irq(struct device *dev, unsigned int vector)
2026 {
2027 int ret = 0;
2028 enum pld_bus_type type = pld_get_bus_type(dev);
2029
2030 switch (type) {
2031 case PLD_BUS_TYPE_PCIE:
2032 ret = pld_pcie_get_msi_irq(dev, vector);
2033 break;
2034 case PLD_BUS_TYPE_PCIE_FW_SIM:
2035 case PLD_BUS_TYPE_IPCI_FW_SIM:
2036 ret = pld_pcie_fw_sim_get_msi_irq(dev, vector);
2037 break;
2038 case PLD_BUS_TYPE_SNOC:
2039 case PLD_BUS_TYPE_SDIO:
2040 case PLD_BUS_TYPE_USB:
2041 case PLD_BUS_TYPE_SNOC_FW_SIM:
2042 pr_err("Not supported on type %d\n", type);
2043 ret = -ENODEV;
2044 break;
2045 case PLD_BUS_TYPE_IPCI:
2046 ret = pld_ipci_get_msi_irq(dev, vector);
2047 break;
2048 default:
2049 pr_err("Invalid device type %d\n", type);
2050 ret = -EINVAL;
2051 break;
2052 }
2053
2054 return ret;
2055 }
2056
pld_get_msi_address(struct device * dev,uint32_t * msi_addr_low,uint32_t * msi_addr_high)2057 void pld_get_msi_address(struct device *dev, uint32_t *msi_addr_low,
2058 uint32_t *msi_addr_high)
2059 {
2060 enum pld_bus_type type = pld_get_bus_type(dev);
2061
2062 switch (type) {
2063 case PLD_BUS_TYPE_PCIE:
2064 pld_pcie_get_msi_address(dev, msi_addr_low, msi_addr_high);
2065 break;
2066 case PLD_BUS_TYPE_PCIE_FW_SIM:
2067 case PLD_BUS_TYPE_IPCI_FW_SIM:
2068 pld_pcie_fw_sim_get_msi_address(dev, msi_addr_low,
2069 msi_addr_high);
2070 break;
2071 case PLD_BUS_TYPE_SNOC:
2072 case PLD_BUS_TYPE_SDIO:
2073 case PLD_BUS_TYPE_USB:
2074 case PLD_BUS_TYPE_SNOC_FW_SIM:
2075 pr_err("Not supported on type %d\n", type);
2076 break;
2077 case PLD_BUS_TYPE_IPCI:
2078 pld_ipci_get_msi_address(dev, msi_addr_low, msi_addr_high);
2079 break;
2080 default:
2081 pr_err("Invalid device type %d\n", type);
2082 break;
2083 }
2084 }
2085
pld_is_drv_connected(struct device * dev)2086 int pld_is_drv_connected(struct device *dev)
2087 {
2088 enum pld_bus_type type = pld_get_bus_type(dev);
2089 int ret = 0;
2090
2091 switch (type) {
2092 case PLD_BUS_TYPE_PCIE:
2093 ret = pld_pcie_is_drv_connected(dev);
2094 break;
2095 case PLD_BUS_TYPE_PCIE_FW_SIM:
2096 case PLD_BUS_TYPE_IPCI_FW_SIM:
2097 case PLD_BUS_TYPE_SNOC_FW_SIM:
2098 case PLD_BUS_TYPE_SNOC:
2099 case PLD_BUS_TYPE_SDIO:
2100 case PLD_BUS_TYPE_USB:
2101 case PLD_BUS_TYPE_IPCI:
2102 break;
2103 default:
2104 pr_err("Invalid device type %d\n", type);
2105 ret = -EINVAL;
2106 break;
2107 }
2108
2109 return ret;
2110 }
2111
pld_socinfo_get_serial_number(struct device * dev)2112 unsigned int pld_socinfo_get_serial_number(struct device *dev)
2113 {
2114 unsigned int ret = 0;
2115 enum pld_bus_type type = pld_get_bus_type(dev);
2116
2117 switch (type) {
2118 case PLD_BUS_TYPE_SNOC:
2119 ret = pld_snoc_socinfo_get_serial_number(dev);
2120 break;
2121 case PLD_BUS_TYPE_PCIE_FW_SIM:
2122 case PLD_BUS_TYPE_IPCI_FW_SIM:
2123 case PLD_BUS_TYPE_PCIE:
2124 pr_err("Not supported on type %d\n", type);
2125 break;
2126 case PLD_BUS_TYPE_SNOC_FW_SIM:
2127 break;
2128 case PLD_BUS_TYPE_IPCI:
2129 break;
2130 default:
2131 pr_err("Invalid device type %d\n", type);
2132 break;
2133 }
2134
2135 return ret;
2136 }
2137
pld_is_qmi_disable(struct device * dev)2138 int pld_is_qmi_disable(struct device *dev)
2139 {
2140 int ret = 0;
2141 enum pld_bus_type type = pld_get_bus_type(dev);
2142
2143 switch (type) {
2144 case PLD_BUS_TYPE_SNOC:
2145 ret = pld_snoc_is_qmi_disable(dev);
2146 break;
2147 case PLD_BUS_TYPE_SNOC_FW_SIM:
2148 break;
2149 case PLD_BUS_TYPE_IPCI:
2150 break;
2151 case PLD_BUS_TYPE_PCIE_FW_SIM:
2152 case PLD_BUS_TYPE_IPCI_FW_SIM:
2153 case PLD_BUS_TYPE_PCIE:
2154 case PLD_BUS_TYPE_SDIO:
2155 pr_err("Not supported on type %d\n", type);
2156 ret = -EINVAL;
2157 break;
2158 default:
2159 pr_err("Invalid device type %d\n", type);
2160 ret = -EINVAL;
2161 break;
2162 }
2163
2164 return ret;
2165 }
2166
pld_is_fw_down(struct device * dev)2167 int pld_is_fw_down(struct device *dev)
2168 {
2169 int ret = 0;
2170 enum pld_bus_type type = pld_get_bus_type(dev);
2171 struct device *ifdev;
2172
2173 switch (type) {
2174 case PLD_BUS_TYPE_SNOC:
2175 ret = pld_snoc_is_fw_down(dev);
2176 break;
2177 case PLD_BUS_TYPE_SNOC_FW_SIM:
2178 ret = pld_snoc_fw_sim_is_fw_down(dev);
2179 break;
2180 case PLD_BUS_TYPE_PCIE_FW_SIM:
2181 case PLD_BUS_TYPE_IPCI_FW_SIM:
2182 break;
2183 case PLD_BUS_TYPE_PCIE:
2184 ret = pld_pcie_is_fw_down(dev);
2185 break;
2186 case PLD_BUS_TYPE_SDIO:
2187 break;
2188 case PLD_BUS_TYPE_USB:
2189 ifdev = pld_get_if_dev(dev);
2190 ret = pld_usb_is_fw_down(ifdev);
2191 break;
2192 case PLD_BUS_TYPE_IPCI:
2193 ret = pld_ipci_is_fw_down(dev);
2194 break;
2195 default:
2196 pr_err("Invalid device type %d\n", type);
2197 ret = -EINVAL;
2198 break;
2199 }
2200
2201 return ret;
2202 }
2203
2204 #ifdef CONFIG_ENABLE_LOW_POWER_MODE
pld_is_low_power_mode(struct device * dev)2205 int pld_is_low_power_mode(struct device *dev)
2206 {
2207 int ret = 0;
2208 enum pld_bus_type type = pld_get_bus_type(dev);
2209
2210 switch (type) {
2211 case PLD_BUS_TYPE_SNOC:
2212 ret = pld_snoc_is_low_power_mode(dev);
2213 break;
2214 case PLD_BUS_TYPE_PCIE_FW_SIM:
2215 case PLD_BUS_TYPE_IPCI_FW_SIM:
2216 case PLD_BUS_TYPE_SNOC_FW_SIM:
2217 case PLD_BUS_TYPE_IPCI:
2218 default:
2219 break;
2220 }
2221 return ret;
2222 }
2223 #endif
2224
pld_force_assert_target(struct device * dev)2225 int pld_force_assert_target(struct device *dev)
2226 {
2227 enum pld_bus_type type = pld_get_bus_type(dev);
2228
2229 switch (type) {
2230 case PLD_BUS_TYPE_SNOC:
2231 return pld_snoc_force_assert_target(dev);
2232 case PLD_BUS_TYPE_PCIE:
2233 return pld_pcie_force_assert_target(dev);
2234 case PLD_BUS_TYPE_PCIE_FW_SIM:
2235 case PLD_BUS_TYPE_IPCI_FW_SIM:
2236 return -EOPNOTSUPP;
2237 case PLD_BUS_TYPE_SNOC_FW_SIM:
2238 case PLD_BUS_TYPE_SDIO:
2239 return -EINVAL;
2240 case PLD_BUS_TYPE_IPCI:
2241 return pld_ipci_force_assert_target(dev);
2242 default:
2243 pr_err("Invalid device type %d\n", type);
2244 return -EINVAL;
2245 }
2246 }
2247
pld_force_collect_target_dump(struct device * dev)2248 int pld_force_collect_target_dump(struct device *dev)
2249 {
2250 enum pld_bus_type type = pld_get_bus_type(dev);
2251
2252 switch (type) {
2253 case PLD_BUS_TYPE_PCIE:
2254 return pld_pcie_collect_rddm(dev);
2255 case PLD_BUS_TYPE_PCIE_FW_SIM:
2256 case PLD_BUS_TYPE_IPCI_FW_SIM:
2257 case PLD_BUS_TYPE_SNOC_FW_SIM:
2258 case PLD_BUS_TYPE_SNOC:
2259 case PLD_BUS_TYPE_SDIO:
2260 case PLD_BUS_TYPE_USB:
2261 case PLD_BUS_TYPE_IPCI:
2262 return -EOPNOTSUPP;
2263 default:
2264 pr_err("Invalid device type %d\n", type);
2265 return -EINVAL;
2266 }
2267 }
2268
pld_qmi_send_get(struct device * dev)2269 int pld_qmi_send_get(struct device *dev)
2270 {
2271 enum pld_bus_type type = pld_get_bus_type(dev);
2272
2273 switch (type) {
2274 case PLD_BUS_TYPE_PCIE:
2275 return pld_pcie_qmi_send_get(dev);
2276 case PLD_BUS_TYPE_SNOC:
2277 case PLD_BUS_TYPE_SDIO:
2278 case PLD_BUS_TYPE_USB:
2279 case PLD_BUS_TYPE_IPCI:
2280 return 0;
2281 default:
2282 pr_err("Invalid device type %d\n", type);
2283 return -EINVAL;
2284 }
2285 }
2286
pld_qmi_send_put(struct device * dev)2287 int pld_qmi_send_put(struct device *dev)
2288 {
2289 enum pld_bus_type type = pld_get_bus_type(dev);
2290
2291 switch (type) {
2292 case PLD_BUS_TYPE_PCIE:
2293 return pld_pcie_qmi_send_put(dev);
2294 case PLD_BUS_TYPE_SNOC:
2295 case PLD_BUS_TYPE_SDIO:
2296 case PLD_BUS_TYPE_USB:
2297 case PLD_BUS_TYPE_IPCI:
2298 return 0;
2299 default:
2300 pr_err("Invalid device type %d\n", type);
2301 return -EINVAL;
2302 }
2303 }
2304
pld_qmi_send(struct device * dev,int type,void * cmd,int cmd_len,void * cb_ctx,int (* cb)(void * ctx,void * event,int event_len))2305 int pld_qmi_send(struct device *dev, int type, void *cmd,
2306 int cmd_len, void *cb_ctx,
2307 int (*cb)(void *ctx, void *event, int event_len))
2308 {
2309 enum pld_bus_type bus_type = pld_get_bus_type(dev);
2310
2311 switch (bus_type) {
2312 case PLD_BUS_TYPE_PCIE:
2313 return pld_pcie_qmi_send(dev, type, cmd, cmd_len, cb_ctx, cb);
2314 case PLD_BUS_TYPE_SNOC:
2315 case PLD_BUS_TYPE_SDIO:
2316 case PLD_BUS_TYPE_USB:
2317 return -EINVAL;
2318 case PLD_BUS_TYPE_IPCI:
2319 return pld_ipci_qmi_send(dev, type, cmd, cmd_len, cb_ctx, cb);
2320 default:
2321 pr_err("Invalid device type %d\n", bus_type);
2322 return -EINVAL;
2323 }
2324 }
2325
pld_qmi_indication(struct device * dev,void * cb_ctx,int (* cb)(void * ctx,uint16_t type,void * event,int event_len))2326 int pld_qmi_indication(struct device *dev, void *cb_ctx,
2327 int (*cb)(void *ctx, uint16_t type,
2328 void *event, int event_len))
2329 {
2330 enum pld_bus_type bus_type = pld_get_bus_type(dev);
2331
2332 switch (bus_type) {
2333 case PLD_BUS_TYPE_PCIE:
2334 return pld_pcie_register_qmi_ind(dev, cb_ctx, cb);
2335 case PLD_BUS_TYPE_SNOC:
2336 case PLD_BUS_TYPE_SDIO:
2337 case PLD_BUS_TYPE_USB:
2338 case PLD_BUS_TYPE_IPCI:
2339 return -EINVAL;
2340 default:
2341 pr_err("Invalid device type %d\n", bus_type);
2342 return -EINVAL;
2343 }
2344 }
2345
pld_is_fw_dump_skipped(struct device * dev)2346 bool pld_is_fw_dump_skipped(struct device *dev)
2347 {
2348 bool ret = false;
2349 enum pld_bus_type type = pld_get_bus_type(dev);
2350
2351 switch (type) {
2352 case PLD_BUS_TYPE_SDIO:
2353 ret = pld_sdio_is_fw_dump_skipped();
2354 break;
2355 case PLD_BUS_TYPE_PCIE_FW_SIM:
2356 case PLD_BUS_TYPE_IPCI_FW_SIM:
2357 case PLD_BUS_TYPE_SNOC_FW_SIM:
2358 case PLD_BUS_TYPE_IPCI:
2359 default:
2360 break;
2361 }
2362 return ret;
2363 }
2364
pld_is_pdr(struct device * dev)2365 int pld_is_pdr(struct device *dev)
2366 {
2367 int ret = 0;
2368 enum pld_bus_type type = pld_get_bus_type(dev);
2369
2370 switch (type) {
2371 case PLD_BUS_TYPE_SNOC:
2372 ret = pld_snoc_is_pdr();
2373 break;
2374 case PLD_BUS_TYPE_PCIE_FW_SIM:
2375 case PLD_BUS_TYPE_IPCI_FW_SIM:
2376 case PLD_BUS_TYPE_SNOC_FW_SIM:
2377 case PLD_BUS_TYPE_IPCI:
2378 default:
2379 break;
2380 }
2381 return ret;
2382 }
2383
pld_is_fw_rejuvenate(struct device * dev)2384 int pld_is_fw_rejuvenate(struct device *dev)
2385 {
2386 int ret = 0;
2387 enum pld_bus_type type = pld_get_bus_type(dev);
2388
2389 switch (type) {
2390 case PLD_BUS_TYPE_SNOC:
2391 ret = pld_snoc_is_fw_rejuvenate();
2392 break;
2393 case PLD_BUS_TYPE_PCIE_FW_SIM:
2394 case PLD_BUS_TYPE_IPCI_FW_SIM:
2395 case PLD_BUS_TYPE_SNOC_FW_SIM:
2396 case PLD_BUS_TYPE_IPCI:
2397 default:
2398 break;
2399 }
2400 return ret;
2401 }
2402
pld_have_platform_driver_support(struct device * dev)2403 bool pld_have_platform_driver_support(struct device *dev)
2404 {
2405 bool ret = false;
2406
2407 switch (pld_get_bus_type(dev)) {
2408 case PLD_BUS_TYPE_PCIE:
2409 ret = pld_pcie_platform_driver_support();
2410 break;
2411 case PLD_BUS_TYPE_PCIE_FW_SIM:
2412 case PLD_BUS_TYPE_IPCI_FW_SIM:
2413 ret = true;
2414 break;
2415 case PLD_BUS_TYPE_SNOC_FW_SIM:
2416 case PLD_BUS_TYPE_SNOC:
2417 break;
2418 case PLD_BUS_TYPE_IPCI:
2419 ret = true;
2420 break;
2421 case PLD_BUS_TYPE_SDIO:
2422 ret = pld_sdio_platform_driver_support();
2423 break;
2424 default:
2425 pr_err("Invalid device type\n");
2426 break;
2427 }
2428
2429 return ret;
2430 }
2431
pld_idle_shutdown(struct device * dev,int (* shutdown_cb)(struct device * dev))2432 int pld_idle_shutdown(struct device *dev,
2433 int (*shutdown_cb)(struct device *dev))
2434 {
2435 int errno = -EINVAL;
2436 enum pld_bus_type type;
2437
2438 if (!shutdown_cb)
2439 return -EINVAL;
2440
2441 type = pld_get_bus_type(dev);
2442 switch (type) {
2443 case PLD_BUS_TYPE_SDIO:
2444 case PLD_BUS_TYPE_USB:
2445 errno = shutdown_cb(dev);
2446 break;
2447 case PLD_BUS_TYPE_SNOC:
2448 errno = pld_snoc_idle_shutdown(dev);
2449 break;
2450 case PLD_BUS_TYPE_PCIE:
2451 errno = pld_pcie_idle_shutdown(dev);
2452 break;
2453 case PLD_BUS_TYPE_PCIE_FW_SIM:
2454 case PLD_BUS_TYPE_IPCI_FW_SIM:
2455 errno = pld_pcie_fw_sim_idle_shutdown(dev);
2456 break;
2457 case PLD_BUS_TYPE_SNOC_FW_SIM:
2458 errno = pld_snoc_fw_sim_idle_shutdown(dev);
2459 break;
2460 case PLD_BUS_TYPE_IPCI:
2461 errno = pld_ipci_idle_shutdown(dev);
2462 break;
2463 default:
2464 pr_err("Invalid device type %d\n", type);
2465 break;
2466 }
2467
2468 return errno;
2469 }
2470
pld_idle_restart(struct device * dev,int (* restart_cb)(struct device * dev))2471 int pld_idle_restart(struct device *dev,
2472 int (*restart_cb)(struct device *dev))
2473 {
2474 int errno = -EINVAL;
2475 enum pld_bus_type type;
2476
2477 if (!restart_cb)
2478 return -EINVAL;
2479
2480 type = pld_get_bus_type(dev);
2481 switch (type) {
2482 case PLD_BUS_TYPE_SDIO:
2483 case PLD_BUS_TYPE_USB:
2484 errno = restart_cb(dev);
2485 break;
2486 case PLD_BUS_TYPE_SNOC:
2487 errno = pld_snoc_idle_restart(dev);
2488 break;
2489 case PLD_BUS_TYPE_PCIE:
2490 errno = pld_pcie_idle_restart(dev);
2491 break;
2492 case PLD_BUS_TYPE_PCIE_FW_SIM:
2493 case PLD_BUS_TYPE_IPCI_FW_SIM:
2494 errno = pld_pcie_fw_sim_idle_restart(dev);
2495 break;
2496 case PLD_BUS_TYPE_SNOC_FW_SIM:
2497 errno = pld_snoc_fw_sim_idle_restart(dev);
2498 break;
2499 case PLD_BUS_TYPE_IPCI:
2500 errno = pld_ipci_idle_restart(dev);
2501 break;
2502 default:
2503 pr_err("Invalid device type %d\n", type);
2504 break;
2505 }
2506
2507 return errno;
2508 }
2509
pld_thermal_register(struct device * dev,unsigned long max_state,int mon_id)2510 int pld_thermal_register(struct device *dev,
2511 unsigned long max_state, int mon_id)
2512 {
2513 int errno = -EINVAL;
2514 enum pld_bus_type type;
2515
2516 type = pld_get_bus_type(dev);
2517 switch (type) {
2518 case PLD_BUS_TYPE_SDIO:
2519 case PLD_BUS_TYPE_USB:
2520 case PLD_BUS_TYPE_SNOC:
2521 break;
2522 case PLD_BUS_TYPE_PCIE:
2523 errno = pld_pci_thermal_register(dev, max_state, mon_id);
2524 break;
2525 case PLD_BUS_TYPE_PCIE_FW_SIM:
2526 break;
2527 case PLD_BUS_TYPE_IPCI_FW_SIM:
2528 errno = pld_pcie_fw_sim_thermal_register(dev, max_state,
2529 mon_id);
2530 break;
2531 case PLD_BUS_TYPE_SNOC_FW_SIM:
2532 break;
2533 case PLD_BUS_TYPE_IPCI:
2534 errno = pld_ipci_thermal_register(dev, max_state, mon_id);
2535 break;
2536 default:
2537 pr_err("Invalid device type %d\n", type);
2538 break;
2539 }
2540
2541 return errno;
2542 }
2543
pld_thermal_unregister(struct device * dev,int mon_id)2544 void pld_thermal_unregister(struct device *dev, int mon_id)
2545 {
2546 enum pld_bus_type type;
2547
2548 type = pld_get_bus_type(dev);
2549 switch (type) {
2550 case PLD_BUS_TYPE_SDIO:
2551 case PLD_BUS_TYPE_USB:
2552 case PLD_BUS_TYPE_SNOC:
2553 break;
2554 case PLD_BUS_TYPE_PCIE:
2555 pld_pci_thermal_unregister(dev, mon_id);
2556 break;
2557 case PLD_BUS_TYPE_PCIE_FW_SIM:
2558 break;
2559 case PLD_BUS_TYPE_IPCI_FW_SIM:
2560 pld_pcie_fw_sim_thermal_unregister(dev, mon_id);
2561 break;
2562 case PLD_BUS_TYPE_SNOC_FW_SIM:
2563 break;
2564 case PLD_BUS_TYPE_IPCI:
2565 pld_ipci_thermal_unregister(dev, mon_id);
2566 break;
2567 default:
2568 pr_err("Invalid device type %d\n", type);
2569 break;
2570 }
2571 }
2572
pld_set_wfc_mode(struct device * dev,enum pld_wfc_mode wfc_mode)2573 int pld_set_wfc_mode(struct device *dev, enum pld_wfc_mode wfc_mode)
2574 {
2575 int errno = -ENOTSUPP;
2576 enum pld_bus_type type;
2577
2578 type = pld_get_bus_type(dev);
2579 switch (type) {
2580 case PLD_BUS_TYPE_SDIO:
2581 case PLD_BUS_TYPE_USB:
2582 case PLD_BUS_TYPE_SNOC:
2583 case PLD_BUS_TYPE_IPCI_FW_SIM:
2584 case PLD_BUS_TYPE_SNOC_FW_SIM:
2585 case PLD_BUS_TYPE_IPCI:
2586 case PLD_BUS_TYPE_PCIE_FW_SIM:
2587 break;
2588 case PLD_BUS_TYPE_PCIE:
2589 errno = pld_pcie_set_wfc_mode(dev, wfc_mode);
2590 break;
2591 default:
2592 pr_err("Invalid device type %d\n", type);
2593 break;
2594 }
2595
2596 return errno;
2597 }
pld_bus_width_type_to_str(enum pld_bus_width_type level)2598 const char *pld_bus_width_type_to_str(enum pld_bus_width_type level)
2599 {
2600 switch (level) {
2601 /* initialize the wlan sub system */
2602 case PLD_BUS_WIDTH_NONE:
2603 return "NONE";
2604 case PLD_BUS_WIDTH_IDLE:
2605 return "IDLE";
2606 case PLD_BUS_WIDTH_LOW:
2607 return "LOW";
2608 case PLD_BUS_WIDTH_MEDIUM:
2609 return "MEDIUM";
2610 case PLD_BUS_WIDTH_HIGH:
2611 return "HIGH";
2612 case PLD_BUS_WIDTH_MID_HIGH:
2613 return "MID_HIGH";
2614 case PLD_BUS_WIDTH_VERY_HIGH:
2615 return "VERY_HIGH";
2616 case PLD_BUS_WIDTH_ULTRA_HIGH:
2617 return "ULTRA_HIGH";
2618 case PLD_BUS_WIDTH_LOW_LATENCY:
2619 return "LOW_LAT";
2620 default:
2621 if (level > PLD_BUS_WIDTH_ULTRA_HIGH)
2622 return "SUPER_HIGH";
2623 else
2624 return "INVAL";
2625 }
2626 }
2627
pld_get_thermal_state(struct device * dev,unsigned long * thermal_state,int mon_id)2628 int pld_get_thermal_state(struct device *dev, unsigned long *thermal_state,
2629 int mon_id)
2630 {
2631 int errno = -EINVAL;
2632 enum pld_bus_type type;
2633
2634 type = pld_get_bus_type(dev);
2635 switch (type) {
2636 case PLD_BUS_TYPE_SDIO:
2637 case PLD_BUS_TYPE_USB:
2638 case PLD_BUS_TYPE_SNOC:
2639 break;
2640 case PLD_BUS_TYPE_PCIE:
2641 errno = pld_pci_get_thermal_state(dev, thermal_state, mon_id);
2642 break;
2643 case PLD_BUS_TYPE_PCIE_FW_SIM:
2644 break;
2645 case PLD_BUS_TYPE_IPCI_FW_SIM:
2646 errno = pld_pcie_fw_sim_get_thermal_state(dev, thermal_state,
2647 mon_id);
2648 break;
2649 case PLD_BUS_TYPE_SNOC_FW_SIM:
2650 break;
2651 case PLD_BUS_TYPE_IPCI:
2652 errno = pld_ipci_get_thermal_state(dev, thermal_state, mon_id);
2653 break;
2654 default:
2655 pr_err("Invalid device type %d\n", type);
2656 break;
2657 }
2658
2659 return errno;
2660 }
2661
2662 #ifdef CNSS_UTILS_VENDOR_UNSAFE_CHAN_API_SUPPORT
pld_get_wlan_unsafe_channel_sap(struct device * dev,struct pld_ch_avoid_ind_type * ch_avoid_ranges)2663 int pld_get_wlan_unsafe_channel_sap(
2664 struct device *dev, struct pld_ch_avoid_ind_type *ch_avoid_ranges)
2665 {
2666 struct cnss_ch_avoid_ind_type cnss_ch_avoid;
2667 int ret;
2668 int i;
2669
2670 if (!ch_avoid_ranges)
2671 return -EINVAL;
2672 cnss_ch_avoid.ch_avoid_range_cnt = 0;
2673 ret = cnss_utils_get_wlan_unsafe_channel_sap(dev, &cnss_ch_avoid);
2674 if (ret)
2675 return ret;
2676
2677 for (i = 0;
2678 i < PLD_CH_AVOID_MAX_RANGE &&
2679 i < cnss_ch_avoid.ch_avoid_range_cnt; i++) {
2680 ch_avoid_ranges->avoid_freq_range[i].start_freq =
2681 cnss_ch_avoid.avoid_freq_range[i].start_freq;
2682 ch_avoid_ranges->avoid_freq_range[i].end_freq =
2683 cnss_ch_avoid.avoid_freq_range[i].end_freq;
2684 }
2685 ch_avoid_ranges->ch_avoid_range_cnt = i;
2686 if (i < cnss_ch_avoid.ch_avoid_range_cnt)
2687 pr_err("unexpected cnss ch_avoid_range_cnt %d",
2688 cnss_ch_avoid.ch_avoid_range_cnt);
2689
2690 return 0;
2691 }
2692 #endif
2693
pld_set_tsf_sync_period(struct device * dev,u32 val)2694 void pld_set_tsf_sync_period(struct device *dev, u32 val)
2695 {
2696 switch (pld_get_bus_type(dev)) {
2697 case PLD_BUS_TYPE_PCIE:
2698 pld_pcie_set_tsf_sync_period(dev, val);
2699 break;
2700 case PLD_BUS_TYPE_PCIE_FW_SIM:
2701 case PLD_BUS_TYPE_IPCI_FW_SIM:
2702 case PLD_BUS_TYPE_SNOC_FW_SIM:
2703 case PLD_BUS_TYPE_SNOC:
2704 case PLD_BUS_TYPE_IPCI:
2705 case PLD_BUS_TYPE_SDIO:
2706 case PLD_BUS_TYPE_USB:
2707 break;
2708 default:
2709 pr_err("Invalid device type\n");
2710 break;
2711 }
2712 }
2713
pld_reset_tsf_sync_period(struct device * dev)2714 void pld_reset_tsf_sync_period(struct device *dev)
2715 {
2716 switch (pld_get_bus_type(dev)) {
2717 case PLD_BUS_TYPE_PCIE:
2718 pld_pcie_reset_tsf_sync_period(dev);
2719 break;
2720 case PLD_BUS_TYPE_PCIE_FW_SIM:
2721 case PLD_BUS_TYPE_IPCI_FW_SIM:
2722 case PLD_BUS_TYPE_SNOC_FW_SIM:
2723 case PLD_BUS_TYPE_SNOC:
2724 case PLD_BUS_TYPE_IPCI:
2725 case PLD_BUS_TYPE_SDIO:
2726 case PLD_BUS_TYPE_USB:
2727 break;
2728 default:
2729 pr_err("Invalid device type\n");
2730 break;
2731 }
2732 }
2733
2734 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0))
pld_is_ipa_offload_disabled(struct device * dev)2735 int pld_is_ipa_offload_disabled(struct device *dev)
2736 {
2737 unsigned long dev_cfg = 0;
2738
2739 enum pld_bus_type type = pld_get_bus_type(dev);
2740
2741 switch (type) {
2742 case PLD_BUS_TYPE_SNOC:
2743 dev_cfg = pld_snoc_get_device_config();
2744 break;
2745 case PLD_BUS_TYPE_IPCI:
2746 case PLD_BUS_TYPE_PCIE:
2747 case PLD_BUS_TYPE_SDIO:
2748 case PLD_BUS_TYPE_USB:
2749 case PLD_BUS_TYPE_SNOC_FW_SIM:
2750 case PLD_BUS_TYPE_PCIE_FW_SIM:
2751 case PLD_BUS_TYPE_IPCI_FW_SIM:
2752 pr_err("Not supported on type %d\n", type);
2753 break;
2754 default:
2755 pr_err("Invalid device type %d\n", type);
2756 break;
2757 }
2758
2759 return test_bit(PLD_IPA_DISABLED, &dev_cfg);
2760 }
2761 #endif
2762
2763 #ifdef FEATURE_WLAN_TIME_SYNC_FTM
pld_get_audio_wlan_timestamp(struct device * dev,enum pld_wlan_time_sync_trigger_type type,uint64_t * ts)2764 int pld_get_audio_wlan_timestamp(struct device *dev,
2765 enum pld_wlan_time_sync_trigger_type type,
2766 uint64_t *ts)
2767 {
2768 int ret = 0;
2769 enum pld_bus_type bus_type;
2770
2771 bus_type = pld_get_bus_type(dev);
2772 switch (bus_type) {
2773 case PLD_BUS_TYPE_SNOC:
2774 ret = pld_snoc_get_audio_wlan_timestamp(dev, type, ts);
2775 break;
2776 case PLD_BUS_TYPE_PCIE:
2777 case PLD_BUS_TYPE_SNOC_FW_SIM:
2778 case PLD_BUS_TYPE_PCIE_FW_SIM:
2779 case PLD_BUS_TYPE_IPCI_FW_SIM:
2780 case PLD_BUS_TYPE_SDIO:
2781 case PLD_BUS_TYPE_USB:
2782 case PLD_BUS_TYPE_IPCI:
2783 break;
2784 default:
2785 ret = -EINVAL;
2786 break;
2787 }
2788 return ret;
2789 }
2790 #endif /* FEATURE_WLAN_TIME_SYNC_FTM */
2791
pld_is_one_msi(struct device * dev)2792 bool pld_is_one_msi(struct device *dev)
2793 {
2794 bool ret = false;
2795 enum pld_bus_type type = pld_get_bus_type(dev);
2796
2797 switch (type) {
2798 case PLD_BUS_TYPE_PCIE:
2799 ret = pld_pcie_is_one_msi(dev);
2800 break;
2801 default:
2802 break;
2803 }
2804
2805 return ret;
2806 }
2807
2808 #ifdef CONFIG_AFC_SUPPORT
pld_send_buffer_to_afcmem(struct device * dev,const uint8_t * afcdb,uint32_t len,uint8_t slotid)2809 int pld_send_buffer_to_afcmem(struct device *dev, const uint8_t *afcdb,
2810 uint32_t len, uint8_t slotid)
2811 {
2812 return cnss_send_buffer_to_afcmem(dev, afcdb, len, slotid);
2813 }
2814
pld_reset_afcmem(struct device * dev,uint8_t slotid)2815 int pld_reset_afcmem(struct device *dev, uint8_t slotid)
2816 {
2817 return cnss_reset_afcmem(dev, slotid);
2818 }
2819 #endif
2820
2821 #ifdef FEATURE_DIRECT_LINK
pld_audio_smmu_map(struct device * dev,phys_addr_t paddr,dma_addr_t iova,size_t size)2822 int pld_audio_smmu_map(struct device *dev, phys_addr_t paddr, dma_addr_t iova,
2823 size_t size)
2824 {
2825 int ret;
2826
2827 switch (pld_get_bus_type(dev)) {
2828 case PLD_BUS_TYPE_PCIE:
2829 ret = pld_pcie_audio_smmu_map(dev, paddr, iova, size);
2830 break;
2831 default:
2832 ret = -EINVAL;
2833 break;
2834 }
2835
2836 return ret;
2837 }
2838
pld_audio_smmu_unmap(struct device * dev,dma_addr_t iova,size_t size)2839 void pld_audio_smmu_unmap(struct device *dev, dma_addr_t iova, size_t size)
2840 {
2841 switch (pld_get_bus_type(dev)) {
2842 case PLD_BUS_TYPE_PCIE:
2843 pld_pcie_audio_smmu_unmap(dev, iova, size);
2844 break;
2845 default:
2846 break;
2847 }
2848 }
2849 #endif
2850