Commit ae52af090835c6e43c1b06853c937f8b01ab8cf6

Authored by Ye Li
1 parent 2f0dc4c503

MLK-17821-3 imx8qxp/qm: Add board codes to adapt CDNS3 USB gadget driver

All iMX8QM/iMX8QXP MEK ARM2 boards have typec port for CDNS3 USB. This patch
addes board level codes to init and clean up CDNS3 USB gadget driver.

Signed-off-by: Ye Li <ye.li@nxp.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>

Showing 4 changed files with 292 additions and 62 deletions Side-by-side Diff

board/freescale/imx8qm_arm2/imx8qm_arm2.c
1 1 /*
2   - * Copyright 2017 NXP
  2 + * Copyright 2017-2018 NXP
3 3 *
4 4 * SPDX-License-Identifier: GPL-2.0+
5 5 */
... ... @@ -28,6 +28,7 @@
28 28 #include <asm/imx-common/video.h>
29 29 #include <asm/arch/video_common.h>
30 30 #include <power-domain.h>
  31 +#include <cdns3-uboot.h>
31 32  
32 33 DECLARE_GLOBAL_DATA_PTR;
33 34  
... ... @@ -499,6 +500,82 @@
499 500 }
500 501 #endif
501 502  
  503 +#ifdef CONFIG_USB_CDNS3_GADGET
  504 +
  505 +static struct cdns3_device cdns3_device_data = {
  506 + .none_core_base = 0x5B110000,
  507 + .xhci_base = 0x5B130000,
  508 + .dev_base = 0x5B140000,
  509 + .phy_base = 0x5B160000,
  510 + .otg_base = 0x5B120000,
  511 + .dr_mode = USB_DR_MODE_PERIPHERAL,
  512 + .index = 1,
  513 +};
  514 +
  515 +int usb_gadget_handle_interrupts(void)
  516 +{
  517 + cdns3_uboot_handle_interrupt(1);
  518 + return 0;
  519 +}
  520 +
  521 +int board_usb_init(int index, enum usb_init_type init)
  522 +{
  523 + int ret = 0;
  524 +
  525 + if (index == 1) {
  526 + if (init == USB_INIT_DEVICE) {
  527 + struct power_domain pd;
  528 + int ret;
  529 +
  530 + /* Power on usb */
  531 + if (!power_domain_lookup_name("conn_usb2", &pd)) {
  532 + ret = power_domain_on(&pd);
  533 + if (ret)
  534 + printf("conn_usb2 Power up failed! (error = %d)\n", ret);
  535 + }
  536 +
  537 + if (!power_domain_lookup_name("conn_usb2_phy", &pd)) {
  538 + ret = power_domain_on(&pd);
  539 + if (ret)
  540 + printf("conn_usb2_phy Power up failed! (error = %d)\n", ret);
  541 + }
  542 +
  543 + ret = cdns3_uboot_init(&cdns3_device_data);
  544 + printf("%d cdns3_uboot_initmode %d\n", index, ret);
  545 + }
  546 + }
  547 + return ret;
  548 +}
  549 +
  550 +int board_usb_cleanup(int index, enum usb_init_type init)
  551 +{
  552 + int ret = 0;
  553 +
  554 + if (index == 1) {
  555 + if (init == USB_INIT_DEVICE) {
  556 + struct power_domain pd;
  557 + int ret;
  558 +
  559 + cdns3_uboot_exit(1);
  560 +
  561 + /* Power off usb */
  562 + if (!power_domain_lookup_name("conn_usb2", &pd)) {
  563 + ret = power_domain_off(&pd);
  564 + if (ret)
  565 + printf("conn_usb2 Power up failed! (error = %d)\n", ret);
  566 + }
  567 +
  568 + if (!power_domain_lookup_name("conn_usb2_phy", &pd)) {
  569 + ret = power_domain_off(&pd);
  570 + if (ret)
  571 + printf("conn_usb2_phy Power up failed! (error = %d)\n", ret);
  572 + }
  573 + }
  574 + }
  575 + return ret;
  576 +}
  577 +#endif
  578 +
502 579 int board_init(void)
503 580 {
504 581 #ifdef CONFIG_MXC_GPIO
... ... @@ -590,30 +667,6 @@
590 667 }
591 668 #endif /*CONFIG_ANDROID_RECOVERY*/
592 669 #endif /*CONFIG_FSL_FASTBOOT*/
593   -
594   -/* Only Enable USB3 resources currently */
595   -int board_usb_init(int index, enum usb_init_type init)
596   -{
597   -#ifndef CONFIG_DM_USB
598   - struct power_domain pd;
599   - int ret;
600   -
601   - /* Power on usb */
602   - if (!power_domain_lookup_name("conn_usb2", &pd)) {
603   - ret = power_domain_on(&pd);
604   - if (ret)
605   - printf("conn_usb2 Power up failed! (error = %d)\n", ret);
606   - }
607   -
608   - if (!power_domain_lookup_name("conn_usb2_phy", &pd)) {
609   - ret = power_domain_on(&pd);
610   - if (ret)
611   - printf("conn_usb2_phy Power up failed! (error = %d)\n", ret);
612   - }
613   -#endif
614   -
615   - return 0;
616   -}
617 670  
618 671 #if defined(CONFIG_VIDEO_IMXDPUV1)
619 672 static void enable_lvds(struct display_info_t const *dev)
board/freescale/imx8qm_mek/imx8qm_mek.c
1 1 /*
2   - * Copyright 2017 NXP
  2 + * Copyright 2017-2018 NXP
3 3 *
4 4 * SPDX-License-Identifier: GPL-2.0+
5 5 */
... ... @@ -28,6 +28,7 @@
28 28 #include <asm/arch/video_common.h>
29 29 #include <power-domain.h>
30 30 #include "../common/tcpc.h"
  31 +#include <cdns3-uboot.h>
31 32  
32 33 DECLARE_GLOBAL_DATA_PTR;
33 34  
34 35  
35 36  
... ... @@ -314,13 +315,53 @@
314 315 tcpc_init(&port, port_config, &ss_mux_select);
315 316 }
316 317  
  318 +static struct cdns3_device cdns3_device_data = {
  319 + .none_core_base = 0x5B110000,
  320 + .xhci_base = 0x5B130000,
  321 + .dev_base = 0x5B140000,
  322 + .phy_base = 0x5B160000,
  323 + .otg_base = 0x5B120000,
  324 + .dr_mode = USB_DR_MODE_PERIPHERAL,
  325 + .index = 1,
  326 +};
  327 +
  328 +int usb_gadget_handle_interrupts(void)
  329 +{
  330 + cdns3_uboot_handle_interrupt(1);
  331 + return 0;
  332 +}
  333 +
317 334 int board_usb_init(int index, enum usb_init_type init)
318 335 {
319 336 int ret = 0;
320 337  
321   - if (init == USB_INIT_HOST)
322   - ret = tcpc_setup_dfp_mode(&port);
  338 + if (index == 1) {
  339 + if (init == USB_INIT_HOST) {
  340 + ret = tcpc_setup_dfp_mode(&port);
  341 + } else {
  342 + struct power_domain pd;
  343 + int ret;
323 344  
  345 + /* Power on usb */
  346 + if (!power_domain_lookup_name("conn_usb2", &pd)) {
  347 + ret = power_domain_on(&pd);
  348 + if (ret)
  349 + printf("conn_usb2 Power up failed! (error = %d)\n", ret);
  350 + }
  351 +
  352 + if (!power_domain_lookup_name("conn_usb2_phy", &pd)) {
  353 + ret = power_domain_on(&pd);
  354 + if (ret)
  355 + printf("conn_usb2_phy Power up failed! (error = %d)\n", ret);
  356 + }
  357 +
  358 + ret = tcpc_setup_ufp_mode(&port);
  359 + printf("%d setufp mode %d\n", index, ret);
  360 +
  361 + ret = cdns3_uboot_init(&cdns3_device_data);
  362 + printf("%d cdns3_uboot_initmode %d\n", index, ret);
  363 + }
  364 + }
324 365 return ret;
325 366 }
326 367  
327 368  
... ... @@ -328,9 +369,29 @@
328 369 {
329 370 int ret = 0;
330 371  
331   - if (init == USB_INIT_HOST)
332   - ret = tcpc_disable_src_vbus(&port);
  372 + if (index == 1) {
  373 + if (init == USB_INIT_HOST) {
  374 + ret = tcpc_disable_src_vbus(&port);
  375 + } else {
  376 + struct power_domain pd;
  377 + int ret;
333 378  
  379 + cdns3_uboot_exit(1);
  380 +
  381 + /* Power off usb */
  382 + if (!power_domain_lookup_name("conn_usb2", &pd)) {
  383 + ret = power_domain_off(&pd);
  384 + if (ret)
  385 + printf("conn_usb2 Power up failed! (error = %d)\n", ret);
  386 + }
  387 +
  388 + if (!power_domain_lookup_name("conn_usb2_phy", &pd)) {
  389 + ret = power_domain_off(&pd);
  390 + if (ret)
  391 + printf("conn_usb2_phy Power up failed! (error = %d)\n", ret);
  392 + }
  393 + }
  394 + }
334 395 return ret;
335 396 }
336 397 #endif
board/freescale/imx8qxp_arm2/imx8qxp_arm2.c
1 1 /*
2   - * Copyright 2017 NXP
  2 + * Copyright 2017-2018 NXP
3 3 *
4 4 * SPDX-License-Identifier: GPL-2.0+
5 5 */
... ... @@ -29,6 +29,7 @@
29 29 #include <asm/imx-common/dma.h>
30 30 #include <asm/arch/video_common.h>
31 31 #include <power-domain.h>
  32 +#include <cdns3-uboot.h>
32 33  
33 34 DECLARE_GLOBAL_DATA_PTR;
34 35  
... ... @@ -506,6 +507,82 @@
506 507  
507 508 #endif
508 509  
  510 +#if defined(CONFIG_USB_CDNS3_GADGET)
  511 +
  512 +static struct cdns3_device cdns3_device_data = {
  513 + .none_core_base = 0x5B110000,
  514 + .xhci_base = 0x5B130000,
  515 + .dev_base = 0x5B140000,
  516 + .phy_base = 0x5B160000,
  517 + .otg_base = 0x5B120000,
  518 + .dr_mode = USB_DR_MODE_PERIPHERAL,
  519 + .index = 1,
  520 +};
  521 +
  522 +int usb_gadget_handle_interrupts(void)
  523 +{
  524 + cdns3_uboot_handle_interrupt(1);
  525 + return 0;
  526 +}
  527 +
  528 +int board_usb_init(int index, enum usb_init_type init)
  529 +{
  530 + int ret = 0;
  531 +
  532 + if (index == 1) {
  533 + if (init == USB_INIT_DEVICE) {
  534 + struct power_domain pd;
  535 + int ret;
  536 +
  537 + /* Power on usb */
  538 + if (!power_domain_lookup_name("conn_usb2", &pd)) {
  539 + ret = power_domain_on(&pd);
  540 + if (ret)
  541 + printf("conn_usb2 Power up failed! (error = %d)\n", ret);
  542 + }
  543 +
  544 + if (!power_domain_lookup_name("conn_usb2_phy", &pd)) {
  545 + ret = power_domain_on(&pd);
  546 + if (ret)
  547 + printf("conn_usb2_phy Power up failed! (error = %d)\n", ret);
  548 + }
  549 +
  550 + ret = cdns3_uboot_init(&cdns3_device_data);
  551 + printf("%d cdns3_uboot_initmode %d\n", index, ret);
  552 + }
  553 + }
  554 + return ret;
  555 +}
  556 +
  557 +int board_usb_cleanup(int index, enum usb_init_type init)
  558 +{
  559 + int ret = 0;
  560 +
  561 + if (index == 1) {
  562 + if (init == USB_INIT_DEVICE) {
  563 + struct power_domain pd;
  564 + int ret;
  565 +
  566 + cdns3_uboot_exit(1);
  567 +
  568 + /* Power off usb */
  569 + if (!power_domain_lookup_name("conn_usb2", &pd)) {
  570 + ret = power_domain_off(&pd);
  571 + if (ret)
  572 + printf("conn_usb2 Power up failed! (error = %d)\n", ret);
  573 + }
  574 +
  575 + if (!power_domain_lookup_name("conn_usb2_phy", &pd)) {
  576 + ret = power_domain_off(&pd);
  577 + if (ret)
  578 + printf("conn_usb2_phy Power up failed! (error = %d)\n", ret);
  579 + }
  580 + }
  581 + }
  582 + return ret;
  583 +}
  584 +#endif
  585 +
509 586 int board_init(void)
510 587 {
511 588 #ifdef CONFIG_MXC_GPIO
... ... @@ -585,30 +662,6 @@
585 662 }
586 663 #endif /*CONFIG_ANDROID_RECOVERY*/
587 664 #endif /*CONFIG_FSL_FASTBOOT*/
588   -
589   -/* Only Enable USB3 resources currently */
590   -int board_usb_init(int index, enum usb_init_type init)
591   -{
592   -#ifndef CONFIG_DM_USB
593   - struct power_domain pd;
594   - int ret;
595   -
596   - /* Power on usb */
597   - if (!power_domain_lookup_name("conn_usb2", &pd)) {
598   - ret = power_domain_on(&pd);
599   - if (ret)
600   - printf("conn_usb2 Power up failed! (error = %d)\n", ret);
601   - }
602   -
603   - if (!power_domain_lookup_name("conn_usb2_phy", &pd)) {
604   - ret = power_domain_on(&pd);
605   - if (ret)
606   - printf("conn_usb2_phy Power up failed! (error = %d)\n", ret);
607   - }
608   -#endif
609   -
610   - return 0;
611   -}
612 665  
613 666 #if defined(CONFIG_VIDEO_IMXDPUV1)
614 667 static void enable_lvds(struct display_info_t const *dev)
board/freescale/imx8qxp_mek/imx8qxp_mek.c
1 1 /*
2   - * Copyright 2017 NXP
  2 + * Copyright 2017-2018 NXP
3 3 *
4 4 * SPDX-License-Identifier: GPL-2.0+
5 5 */
... ... @@ -29,6 +29,7 @@
29 29 #include <asm/arch/video_common.h>
30 30 #include <power-domain.h>
31 31 #include "../common/tcpc.h"
  32 +#include <cdns3-uboot.h>
32 33  
33 34 DECLARE_GLOBAL_DATA_PTR;
34 35  
35 36  
36 37  
... ... @@ -462,13 +463,54 @@
462 463 tcpc_init(&port, port_config, &ss_mux_select);
463 464 }
464 465  
  466 +static struct cdns3_device cdns3_device_data = {
  467 + .none_core_base = 0x5B110000,
  468 + .xhci_base = 0x5B130000,
  469 + .dev_base = 0x5B140000,
  470 + .phy_base = 0x5B160000,
  471 + .otg_base = 0x5B120000,
  472 + .dr_mode = USB_DR_MODE_PERIPHERAL,
  473 + .index = 1,
  474 +};
  475 +
  476 +int usb_gadget_handle_interrupts(void)
  477 +{
  478 + cdns3_uboot_handle_interrupt(1);
  479 + return 0;
  480 +}
  481 +
465 482 int board_usb_init(int index, enum usb_init_type init)
466 483 {
467 484 int ret = 0;
468 485  
469   - if (init == USB_INIT_HOST)
470   - ret = tcpc_setup_dfp_mode(&port);
  486 + if (index == 1) {
  487 + if (init == USB_INIT_HOST) {
  488 + ret = tcpc_setup_dfp_mode(&port);
  489 + } else {
  490 + struct power_domain pd;
  491 + int ret;
471 492  
  493 + /* Power on usb */
  494 + if (!power_domain_lookup_name("conn_usb2", &pd)) {
  495 + ret = power_domain_on(&pd);
  496 + if (ret)
  497 + printf("conn_usb2 Power up failed! (error = %d)\n", ret);
  498 + }
  499 +
  500 + if (!power_domain_lookup_name("conn_usb2_phy", &pd)) {
  501 + ret = power_domain_on(&pd);
  502 + if (ret)
  503 + printf("conn_usb2_phy Power up failed! (error = %d)\n", ret);
  504 + }
  505 +
  506 + ret = tcpc_setup_ufp_mode(&port);
  507 + printf("%d setufp mode %d\n", index, ret);
  508 +
  509 + ret = cdns3_uboot_init(&cdns3_device_data);
  510 + printf("%d cdns3_uboot_initmode %d\n", index, ret);
  511 + }
  512 + }
  513 +
472 514 return ret;
473 515  
474 516 }
... ... @@ -477,8 +519,29 @@
477 519 {
478 520 int ret = 0;
479 521  
480   - if (init == USB_INIT_HOST)
481   - ret = tcpc_disable_src_vbus(&port);
  522 + if (index == 1) {
  523 + if (init == USB_INIT_HOST) {
  524 + ret = tcpc_disable_src_vbus(&port);
  525 + } else {
  526 + struct power_domain pd;
  527 + int ret;
  528 +
  529 + cdns3_uboot_exit(1);
  530 +
  531 + /* Power off usb */
  532 + if (!power_domain_lookup_name("conn_usb2", &pd)) {
  533 + ret = power_domain_off(&pd);
  534 + if (ret)
  535 + printf("conn_usb2 Power up failed! (error = %d)\n", ret);
  536 + }
  537 +
  538 + if (!power_domain_lookup_name("conn_usb2_phy", &pd)) {
  539 + ret = power_domain_off(&pd);
  540 + if (ret)
  541 + printf("conn_usb2_phy Power up failed! (error = %d)\n", ret);
  542 + }
  543 + }
  544 + }
482 545  
483 546 return ret;
484 547 }