.. | .. |
---|
1 | | -// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) |
---|
| 1 | +/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */ |
---|
2 | 2 | /* |
---|
3 | 3 | * core.h - DesignWare HS OTG Controller common declarations |
---|
4 | 4 | * |
---|
.. | .. |
---|
68 | 68 | /* Maximum number of Endpoints/HostChannels */ |
---|
69 | 69 | #define MAX_EPS_CHANNELS 16 |
---|
70 | 70 | |
---|
71 | | -/* Maximum number of dwc2 clocks */ |
---|
72 | | -#define DWC2_MAX_CLKS 3 |
---|
73 | | - |
---|
74 | 71 | /* dwc2-hsotg declarations */ |
---|
75 | 72 | static const char * const dwc2_hsotg_supply_names[] = { |
---|
76 | 73 | "vusb_d", /* digital USB supply, 1.2V */ |
---|
.. | .. |
---|
138 | 135 | * @target_frame: Targeted frame num to setup next ISOC transfer |
---|
139 | 136 | * @frame_overrun: Indicates SOF number overrun in DSTS |
---|
140 | 137 | * |
---|
141 | | - * This is the driver's state for each registered enpoint, allowing it |
---|
| 138 | + * This is the driver's state for each registered endpoint, allowing it |
---|
142 | 139 | * to keep track of transactions that need doing. Each endpoint has a |
---|
143 | 140 | * lock to protect the state, to try and avoid using an overall lock |
---|
144 | 141 | * for the host controller as much as possible. |
---|
.. | .. |
---|
398 | 395 | * 0 - No |
---|
399 | 396 | * 1 - Yes |
---|
400 | 397 | * @hird_threshold: Value of BESL or HIRD Threshold. |
---|
| 398 | + * @ref_clk_per: Indicates in terms of pico seconds the period |
---|
| 399 | + * of ref_clk. |
---|
| 400 | + * 62500 - 16MHz |
---|
| 401 | + * 58823 - 17MHz |
---|
| 402 | + * 52083 - 19.2MHz |
---|
| 403 | + * 50000 - 20MHz |
---|
| 404 | + * 41666 - 24MHz |
---|
| 405 | + * 33333 - 30MHz (default) |
---|
| 406 | + * 25000 - 40MHz |
---|
| 407 | + * @sof_cnt_wkup_alert: Indicates in term of number of SOF's after which |
---|
| 408 | + * the controller should generate an interrupt if the |
---|
| 409 | + * device had been in L1 state until that period. |
---|
| 410 | + * This is used by SW to initiate Remote WakeUp in the |
---|
| 411 | + * controller so as to sync to the uF number from the host. |
---|
401 | 412 | * @activate_stm_fs_transceiver: Activate internal transceiver using GGPIO |
---|
402 | 413 | * register. |
---|
403 | 414 | * 0 - Deactivate the transceiver (default) |
---|
404 | 415 | * 1 - Activate the transceiver |
---|
| 416 | + * @activate_stm_id_vb_detection: Activate external ID pin and Vbus level |
---|
| 417 | + * detection using GGPIO register. |
---|
| 418 | + * 0 - Deactivate the external level detection (default) |
---|
| 419 | + * 1 - Activate the external level detection |
---|
405 | 420 | * @g_dma: Enables gadget dma usage (default: autodetect). |
---|
406 | 421 | * @g_dma_desc: Enables gadget descriptor DMA (default: autodetect). |
---|
407 | 422 | * @g_rx_fifo_size: The periodic rx fifo size for the device, in |
---|
.. | .. |
---|
421 | 436 | * back to DWC2_SPEED_PARAM_HIGH while device is gone. |
---|
422 | 437 | * 0 - No (default) |
---|
423 | 438 | * 1 - Yes |
---|
| 439 | + * @service_interval: Enable service interval based scheduling. |
---|
| 440 | + * 0 - No |
---|
| 441 | + * 1 - Yes |
---|
424 | 442 | * |
---|
425 | 443 | * The following parameters may be specified when starting the module. These |
---|
426 | 444 | * parameters define how the DWC_otg controller should be configured. A |
---|
.. | .. |
---|
466 | 484 | bool lpm_clock_gating; |
---|
467 | 485 | bool besl; |
---|
468 | 486 | bool hird_threshold_en; |
---|
| 487 | + bool service_interval; |
---|
469 | 488 | u8 hird_threshold; |
---|
470 | 489 | bool activate_stm_fs_transceiver; |
---|
| 490 | + bool activate_stm_id_vb_detection; |
---|
471 | 491 | bool ipg_isoc_en; |
---|
472 | 492 | u16 max_packet_count; |
---|
473 | 493 | u32 max_transfer_size; |
---|
474 | 494 | u32 ahbcfg; |
---|
| 495 | + |
---|
| 496 | + /* GREFCLK parameters */ |
---|
| 497 | + u32 ref_clk_per; |
---|
| 498 | + u16 sof_cnt_wkup_alert; |
---|
475 | 499 | |
---|
476 | 500 | /* Host parameters */ |
---|
477 | 501 | bool host_dma; |
---|
.. | .. |
---|
610 | 634 | * FIFO sizing is enabled 16 to 32768 |
---|
611 | 635 | * Actual maximum value is autodetected and also |
---|
612 | 636 | * the default. |
---|
| 637 | + * @service_interval_mode: For enabling service interval based scheduling in the |
---|
| 638 | + * controller. |
---|
| 639 | + * 0 - Disable |
---|
| 640 | + * 1 - Enable |
---|
613 | 641 | */ |
---|
614 | 642 | struct dwc2_hw_params { |
---|
615 | 643 | unsigned op_mode:3; |
---|
.. | .. |
---|
640 | 668 | unsigned utmi_phy_data_width:2; |
---|
641 | 669 | unsigned lpm_mode:1; |
---|
642 | 670 | unsigned ipg_isoc_en:1; |
---|
| 671 | + unsigned service_interval_mode:1; |
---|
643 | 672 | u32 snpsid; |
---|
644 | 673 | u32 dev_ep_dirs; |
---|
645 | 674 | u32 g_tx_fifo_size[MAX_EPS_CHANNELS]; |
---|
.. | .. |
---|
833 | 862 | * - USB_DR_MODE_PERIPHERAL |
---|
834 | 863 | * - USB_DR_MODE_HOST |
---|
835 | 864 | * - USB_DR_MODE_OTG |
---|
| 865 | + * @role_sw: usb_role_switch handle |
---|
836 | 866 | * @hcd_enabled: Host mode sub-driver initialization indicator. |
---|
837 | 867 | * @gadget_enabled: Peripheral mode sub-driver initialization indicator. |
---|
838 | 868 | * @ll_hw_enabled: Status of low-level hardware resources. |
---|
839 | 869 | * @ll_phy_enabled Status of low-level PHY resources. |
---|
840 | 870 | * @hibernated: True if core is hibernated |
---|
| 871 | + * @reset_phy_on_wake: Quirk saying that we should assert PHY reset on a |
---|
| 872 | + * remote wakeup. |
---|
| 873 | + * @phy_off_for_suspend: Status of whether we turned the PHY off at suspend. |
---|
| 874 | + * @need_phy_for_wake: Quirk saying that we should keep the PHY on at |
---|
| 875 | + * suspend if we need USB to wake us up. |
---|
841 | 876 | * @frame_number: Frame number read from the core. For both device |
---|
842 | 877 | * and host modes. The value ranges are from 0 |
---|
843 | 878 | * to HFNUM_MAX_FRNUM. |
---|
.. | .. |
---|
848 | 883 | * removed once all SoCs support usb transceiver. |
---|
849 | 884 | * @supplies: Definition of USB power supplies |
---|
850 | 885 | * @vbus_supply: Regulator supplying vbus. |
---|
851 | | - * @phyif: PHY interface width |
---|
| 886 | + * @usb33d: Optional 3.3v regulator used on some stm32 devices to |
---|
| 887 | + * supply ID and VBUS detection hardware. |
---|
852 | 888 | * @lock: Spinlock that protects all the driver data structures |
---|
853 | 889 | * @priv: Stores a pointer to the struct usb_hcd |
---|
854 | 890 | * @queuing_high_bandwidth: True if multiple packets of a high-bandwidth |
---|
.. | .. |
---|
951 | 987 | * @status_buf_dma: DMA address for status_buf |
---|
952 | 988 | * @start_work: Delayed work for handling host A-cable connection |
---|
953 | 989 | * @reset_work: Delayed work for handling a port reset |
---|
| 990 | + * @phy_reset_work: Work structure for doing a PHY reset |
---|
954 | 991 | * @otg_port: OTG port number |
---|
955 | 992 | * @frame_list: Frame list |
---|
956 | 993 | * @frame_list_dma: Frame list DMA address |
---|
.. | .. |
---|
970 | 1007 | * @ctrl_buff: Buffer for EP0 control requests. |
---|
971 | 1008 | * @ctrl_req: Request for EP0 control packets. |
---|
972 | 1009 | * @ep0_state: EP0 control transfers state |
---|
| 1010 | + * @delayed_status: true when gadget driver asks for delayed status |
---|
973 | 1011 | * @test_mode: USB test mode requested by the host |
---|
974 | 1012 | * @remote_wakeup_allowed: True if device is allowed to wake-up host by |
---|
975 | 1013 | * remote-wakeup signalling |
---|
.. | .. |
---|
1002 | 1040 | * @fifo_mem: Total internal RAM for FIFOs (bytes) |
---|
1003 | 1041 | * @fifo_map: Each bit intend for concrete fifo. If that bit is set, |
---|
1004 | 1042 | * then that fifo is used |
---|
1005 | | - * @gadget: Represents a usb slave device |
---|
| 1043 | + * @gadget: Represents a usb gadget device |
---|
1006 | 1044 | * @connected: Used in slave mode. True if device connected with host |
---|
1007 | 1045 | * @eps_in: The IN endpoints being supplied to the gadget framework |
---|
1008 | 1046 | * @eps_out: The OUT endpoints being supplied to the gadget framework |
---|
.. | .. |
---|
1020 | 1058 | struct dwc2_core_params params; |
---|
1021 | 1059 | enum usb_otg_state op_state; |
---|
1022 | 1060 | enum usb_dr_mode dr_mode; |
---|
| 1061 | + struct usb_role_switch *role_sw; |
---|
1023 | 1062 | unsigned int hcd_enabled:1; |
---|
1024 | 1063 | unsigned int gadget_enabled:1; |
---|
1025 | 1064 | unsigned int ll_hw_enabled:1; |
---|
1026 | 1065 | unsigned int ll_phy_enabled:1; |
---|
1027 | 1066 | unsigned int hibernated:1; |
---|
1028 | | - bool bus_suspended; |
---|
| 1067 | + unsigned int reset_phy_on_wake:1; |
---|
| 1068 | + unsigned int need_phy_for_wake:1; |
---|
| 1069 | + unsigned int phy_off_for_suspend:1; |
---|
1029 | 1070 | u16 frame_number; |
---|
1030 | 1071 | |
---|
1031 | 1072 | struct phy *phy; |
---|
1032 | | - struct work_struct phy_rst_work; |
---|
1033 | 1073 | struct usb_phy *uphy; |
---|
1034 | 1074 | struct dwc2_hsotg_plat *plat; |
---|
1035 | 1075 | struct regulator_bulk_data supplies[DWC2_NUM_SUPPLIES]; |
---|
1036 | 1076 | struct regulator *vbus_supply; |
---|
1037 | | - u32 phyif; |
---|
| 1077 | + struct regulator *usb33d; |
---|
1038 | 1078 | |
---|
1039 | 1079 | spinlock_t lock; |
---|
1040 | 1080 | void *priv; |
---|
1041 | 1081 | int irq; |
---|
1042 | | - struct clk *clks[DWC2_MAX_CLKS]; |
---|
| 1082 | + struct clk_bulk_data *clks; |
---|
| 1083 | + int num_clks; |
---|
1043 | 1084 | struct reset_control *reset; |
---|
1044 | 1085 | struct reset_control *reset_ecc; |
---|
1045 | 1086 | |
---|
.. | .. |
---|
1069 | 1110 | #define DWC2_CORE_REV_3_00a 0x4f54300a |
---|
1070 | 1111 | #define DWC2_CORE_REV_3_10a 0x4f54310a |
---|
1071 | 1112 | #define DWC2_CORE_REV_4_00a 0x4f54400a |
---|
| 1113 | +#define DWC2_CORE_REV_4_20a 0x4f54420a |
---|
1072 | 1114 | #define DWC2_FS_IOT_REV_1_00a 0x5531100a |
---|
1073 | 1115 | #define DWC2_HS_IOT_REV_1_00a 0x5532100a |
---|
| 1116 | +#define DWC2_CORE_REV_MASK 0x0000ffff |
---|
1074 | 1117 | |
---|
1075 | 1118 | /* DWC OTG HW Core ID */ |
---|
1076 | 1119 | #define DWC2_OTG_ID 0x4f540000 |
---|
.. | .. |
---|
1105 | 1148 | unsigned long hs_periodic_bitmap[ |
---|
1106 | 1149 | DIV_ROUND_UP(DWC2_HS_SCHEDULE_US, BITS_PER_LONG)]; |
---|
1107 | 1150 | u16 periodic_qh_count; |
---|
| 1151 | + bool bus_suspended; |
---|
1108 | 1152 | bool new_connection; |
---|
1109 | 1153 | |
---|
1110 | 1154 | u16 last_frame_num; |
---|
.. | .. |
---|
1128 | 1172 | |
---|
1129 | 1173 | struct delayed_work start_work; |
---|
1130 | 1174 | struct delayed_work reset_work; |
---|
| 1175 | + struct work_struct phy_reset_work; |
---|
1131 | 1176 | u8 otg_port; |
---|
1132 | 1177 | u32 *frame_list; |
---|
1133 | 1178 | dma_addr_t frame_list_dma; |
---|
.. | .. |
---|
1153 | 1198 | void *ep0_buff; |
---|
1154 | 1199 | void *ctrl_buff; |
---|
1155 | 1200 | enum dwc2_ep0_state ep0_state; |
---|
| 1201 | + unsigned delayed_status : 1; |
---|
1156 | 1202 | u8 test_mode; |
---|
1157 | 1203 | |
---|
1158 | 1204 | dma_addr_t setup_desc_dma[2]; |
---|
.. | .. |
---|
1264 | 1310 | int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg, int is_host); |
---|
1265 | 1311 | int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, int rem_wakeup, |
---|
1266 | 1312 | int reset, int is_host); |
---|
| 1313 | +void dwc2_init_fs_ls_pclk_sel(struct dwc2_hsotg *hsotg); |
---|
| 1314 | +int dwc2_phy_init(struct dwc2_hsotg *hsotg, bool select_phy); |
---|
1267 | 1315 | |
---|
1268 | 1316 | void dwc2_force_mode(struct dwc2_hsotg *hsotg, bool host); |
---|
1269 | 1317 | void dwc2_force_dr_mode(struct dwc2_hsotg *hsotg); |
---|
1270 | 1318 | |
---|
1271 | 1319 | bool dwc2_is_controller_alive(struct dwc2_hsotg *hsotg); |
---|
| 1320 | + |
---|
| 1321 | +int dwc2_check_core_version(struct dwc2_hsotg *hsotg); |
---|
1272 | 1322 | |
---|
1273 | 1323 | /* |
---|
1274 | 1324 | * Common core Functions. |
---|
.. | .. |
---|
1336 | 1386 | return (dwc2_readl(hsotg, GINTSTS) & GINTSTS_CURMODE_HOST) == 0; |
---|
1337 | 1387 | } |
---|
1338 | 1388 | |
---|
| 1389 | +int dwc2_drd_init(struct dwc2_hsotg *hsotg); |
---|
| 1390 | +void dwc2_drd_suspend(struct dwc2_hsotg *hsotg); |
---|
| 1391 | +void dwc2_drd_resume(struct dwc2_hsotg *hsotg); |
---|
| 1392 | +void dwc2_drd_exit(struct dwc2_hsotg *hsotg); |
---|
| 1393 | + |
---|
1339 | 1394 | /* |
---|
1340 | 1395 | * Dump core registers and SPRAM |
---|
1341 | 1396 | */ |
---|
.. | .. |
---|
1352 | 1407 | int dwc2_gadget_init(struct dwc2_hsotg *hsotg); |
---|
1353 | 1408 | void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2, |
---|
1354 | 1409 | bool reset); |
---|
| 1410 | +void dwc2_hsotg_core_disconnect(struct dwc2_hsotg *hsotg); |
---|
1355 | 1411 | void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg); |
---|
1356 | 1412 | void dwc2_hsotg_disconnect(struct dwc2_hsotg *dwc2); |
---|
1357 | 1413 | int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, int testmode); |
---|
1358 | 1414 | #define dwc2_is_device_connected(hsotg) (hsotg->connected) |
---|
| 1415 | +#define dwc2_is_device_enabled(hsotg) (hsotg->enabled) |
---|
1359 | 1416 | int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg); |
---|
1360 | 1417 | int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg, int remote_wakeup); |
---|
1361 | 1418 | int dwc2_gadget_enter_hibernation(struct dwc2_hsotg *hsotg); |
---|
.. | .. |
---|
1365 | 1422 | int dwc2_hsotg_tx_fifo_total_depth(struct dwc2_hsotg *hsotg); |
---|
1366 | 1423 | int dwc2_hsotg_tx_fifo_average_depth(struct dwc2_hsotg *hsotg); |
---|
1367 | 1424 | void dwc2_gadget_init_lpm(struct dwc2_hsotg *hsotg); |
---|
| 1425 | +void dwc2_gadget_program_ref_clk(struct dwc2_hsotg *hsotg); |
---|
1368 | 1426 | #else |
---|
1369 | 1427 | static inline int dwc2_hsotg_remove(struct dwc2_hsotg *dwc2) |
---|
1370 | 1428 | { return 0; } |
---|
.. | .. |
---|
1376 | 1434 | { return 0; } |
---|
1377 | 1435 | static inline void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2, |
---|
1378 | 1436 | bool reset) {} |
---|
| 1437 | +static inline void dwc2_hsotg_core_disconnect(struct dwc2_hsotg *hsotg) {} |
---|
1379 | 1438 | static inline void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg) {} |
---|
1380 | 1439 | static inline void dwc2_hsotg_disconnect(struct dwc2_hsotg *dwc2) {} |
---|
1381 | 1440 | static inline int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, |
---|
1382 | 1441 | int testmode) |
---|
1383 | 1442 | { return 0; } |
---|
1384 | 1443 | #define dwc2_is_device_connected(hsotg) (0) |
---|
| 1444 | +#define dwc2_is_device_enabled(hsotg) (0) |
---|
1385 | 1445 | static inline int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg) |
---|
1386 | 1446 | { return 0; } |
---|
1387 | 1447 | static inline int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg, |
---|
.. | .. |
---|
1399 | 1459 | static inline int dwc2_hsotg_tx_fifo_average_depth(struct dwc2_hsotg *hsotg) |
---|
1400 | 1460 | { return 0; } |
---|
1401 | 1461 | static inline void dwc2_gadget_init_lpm(struct dwc2_hsotg *hsotg) {} |
---|
| 1462 | +static inline void dwc2_gadget_program_ref_clk(struct dwc2_hsotg *hsotg) {} |
---|
1402 | 1463 | #endif |
---|
1403 | 1464 | |
---|
1404 | 1465 | #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) |
---|
.. | .. |
---|
1413 | 1474 | int dwc2_host_enter_hibernation(struct dwc2_hsotg *hsotg); |
---|
1414 | 1475 | int dwc2_host_exit_hibernation(struct dwc2_hsotg *hsotg, |
---|
1415 | 1476 | int rem_wakeup, int reset); |
---|
| 1477 | +bool dwc2_host_can_poweroff_phy(struct dwc2_hsotg *dwc2); |
---|
| 1478 | +static inline void dwc2_host_schedule_phy_reset(struct dwc2_hsotg *hsotg) |
---|
| 1479 | +{ schedule_work(&hsotg->phy_reset_work); } |
---|
1416 | 1480 | #else |
---|
1417 | 1481 | static inline int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg) |
---|
1418 | 1482 | { return 0; } |
---|
.. | .. |
---|
1436 | 1500 | static inline int dwc2_host_exit_hibernation(struct dwc2_hsotg *hsotg, |
---|
1437 | 1501 | int rem_wakeup, int reset) |
---|
1438 | 1502 | { return 0; } |
---|
| 1503 | +static inline bool dwc2_host_can_poweroff_phy(struct dwc2_hsotg *dwc2) |
---|
| 1504 | +{ return false; } |
---|
| 1505 | +static inline void dwc2_host_schedule_phy_reset(struct dwc2_hsotg *hsotg) {} |
---|
1439 | 1506 | |
---|
1440 | 1507 | #endif |
---|
1441 | 1508 | |
---|