| .. | .. |
|---|
| 1 | | -// SPDX-License-Identifier: GPL-2.0 |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0 */ |
|---|
| 2 | 2 | /* |
|---|
| 3 | 3 | * mtu3.h - MediaTek USB3 DRD header |
|---|
| 4 | 4 | * |
|---|
| .. | .. |
|---|
| 61 | 61 | |
|---|
| 62 | 62 | #define MTU3_U3_IP_SLOT_DEFAULT 2 |
|---|
| 63 | 63 | #define MTU3_U2_IP_SLOT_DEFAULT 1 |
|---|
| 64 | + |
|---|
| 65 | +/** |
|---|
| 66 | + * IP TRUNK version |
|---|
| 67 | + * from 0x1003 version, USB3 Gen2 is supported, two changes affect driver: |
|---|
| 68 | + * 1. MAXPKT and MULTI bits layout of TXCSR1 and RXCSR1 are adjusted, |
|---|
| 69 | + * but not backward compatible |
|---|
| 70 | + * 2. QMU extend buffer length supported |
|---|
| 71 | + */ |
|---|
| 72 | +#define MTU3_TRUNK_VERS_1003 0x1003 |
|---|
| 64 | 73 | |
|---|
| 65 | 74 | /** |
|---|
| 66 | 75 | * Normally the device works on HS or SS, to simplify fifo management, |
|---|
| .. | .. |
|---|
| 135 | 144 | * The format of TX GPD is a little different from RX one. |
|---|
| 136 | 145 | * And the size of GPD is 16 bytes. |
|---|
| 137 | 146 | * |
|---|
| 138 | | - * @flag: |
|---|
| 147 | + * @dw0_info: |
|---|
| 139 | 148 | * bit0: Hardware Own (HWO) |
|---|
| 140 | 149 | * bit1: Buffer Descriptor Present (BDP), always 0, BD is not supported |
|---|
| 141 | 150 | * bit2: Bypass (BPS), 1: HW skips this GPD if HWO = 1 |
|---|
| 151 | + * bit6: [EL] Zero Length Packet (ZLP), moved from @dw3_info[29] |
|---|
| 142 | 152 | * bit7: Interrupt On Completion (IOC) |
|---|
| 143 | | - * @chksum: This is used to validate the contents of this GPD; |
|---|
| 144 | | - * If TXQ_CS_EN / RXQ_CS_EN bit is set, an interrupt is issued |
|---|
| 145 | | - * when checksum validation fails; |
|---|
| 146 | | - * Checksum value is calculated over the 16 bytes of the GPD by default; |
|---|
| 147 | | - * @data_buf_len (RX ONLY): This value indicates the length of |
|---|
| 148 | | - * the assigned data buffer |
|---|
| 149 | | - * @tx_ext_addr (TX ONLY): [3:0] are 4 extension bits of @buffer, |
|---|
| 150 | | - * [7:4] are 4 extension bits of @next_gpd |
|---|
| 153 | + * bit[31:16]: ([EL] bit[31:12]) allow data buffer length (RX ONLY), |
|---|
| 154 | + * the buffer length of the data to receive |
|---|
| 155 | + * bit[23:16]: ([EL] bit[31:24]) extension address (TX ONLY), |
|---|
| 156 | + * lower 4 bits are extension bits of @buffer, |
|---|
| 157 | + * upper 4 bits are extension bits of @next_gpd |
|---|
| 151 | 158 | * @next_gpd: Physical address of the next GPD |
|---|
| 152 | 159 | * @buffer: Physical address of the data buffer |
|---|
| 153 | | - * @buf_len: |
|---|
| 154 | | - * (TX): This value indicates the length of the assigned data buffer |
|---|
| 155 | | - * (RX): The total length of data received |
|---|
| 156 | | - * @ext_len: reserved |
|---|
| 157 | | - * @rx_ext_addr(RX ONLY): [3:0] are 4 extension bits of @buffer, |
|---|
| 158 | | - * [7:4] are 4 extension bits of @next_gpd |
|---|
| 159 | | - * @ext_flag: |
|---|
| 160 | | - * bit5 (TX ONLY): Zero Length Packet (ZLP), |
|---|
| 160 | + * @dw3_info: |
|---|
| 161 | + * bit[15:0]: ([EL] bit[19:0]) data buffer length, |
|---|
| 162 | + * (TX): the buffer length of the data to transmit |
|---|
| 163 | + * (RX): The total length of data received |
|---|
| 164 | + * bit[23:16]: ([EL] bit[31:24]) extension address (RX ONLY), |
|---|
| 165 | + * lower 4 bits are extension bits of @buffer, |
|---|
| 166 | + * upper 4 bits are extension bits of @next_gpd |
|---|
| 167 | + * bit29: ([EL] abandoned) Zero Length Packet (ZLP) (TX ONLY) |
|---|
| 161 | 168 | */ |
|---|
| 162 | 169 | struct qmu_gpd { |
|---|
| 163 | | - __u8 flag; |
|---|
| 164 | | - __u8 chksum; |
|---|
| 165 | | - union { |
|---|
| 166 | | - __le16 data_buf_len; |
|---|
| 167 | | - __le16 tx_ext_addr; |
|---|
| 168 | | - }; |
|---|
| 170 | + __le32 dw0_info; |
|---|
| 169 | 171 | __le32 next_gpd; |
|---|
| 170 | 172 | __le32 buffer; |
|---|
| 171 | | - __le16 buf_len; |
|---|
| 172 | | - union { |
|---|
| 173 | | - __u8 ext_len; |
|---|
| 174 | | - __u8 rx_ext_addr; |
|---|
| 175 | | - }; |
|---|
| 176 | | - __u8 ext_flag; |
|---|
| 173 | + __le32 dw3_info; |
|---|
| 177 | 174 | } __packed; |
|---|
| 178 | 175 | |
|---|
| 179 | 176 | /** |
|---|
| .. | .. |
|---|
| 202 | 199 | * @id_nb : notifier for iddig(idpin) detection |
|---|
| 203 | 200 | * @id_work : work of iddig detection notifier |
|---|
| 204 | 201 | * @id_event : event of iddig detecion notifier |
|---|
| 202 | +* @role_sw : use USB Role Switch to support dual-role switch, can't use |
|---|
| 203 | +* extcon at the same time, and extcon is deprecated. |
|---|
| 204 | +* @role_sw_used : true when the USB Role Switch is used. |
|---|
| 205 | 205 | * @is_u3_drd: whether port0 supports usb3.0 dual-role device or not |
|---|
| 206 | 206 | * @manual_drd_enabled: it's true when supports dual-role device by debugfs |
|---|
| 207 | 207 | * to switch host/device modes depending on user input. |
|---|
| .. | .. |
|---|
| 215 | 215 | struct notifier_block id_nb; |
|---|
| 216 | 216 | struct work_struct id_work; |
|---|
| 217 | 217 | unsigned long id_event; |
|---|
| 218 | + struct usb_role_switch *role_sw; |
|---|
| 219 | + bool role_sw_used; |
|---|
| 218 | 220 | bool is_u3_drd; |
|---|
| 219 | 221 | bool manual_drd_enabled; |
|---|
| 220 | 222 | }; |
|---|
| .. | .. |
|---|
| 291 | 293 | const struct usb_endpoint_descriptor *desc; |
|---|
| 292 | 294 | |
|---|
| 293 | 295 | int flags; |
|---|
| 294 | | - u8 wedged; |
|---|
| 295 | | - u8 busy; |
|---|
| 296 | 296 | }; |
|---|
| 297 | 297 | |
|---|
| 298 | 298 | struct mtu3_request { |
|---|
| .. | .. |
|---|
| 316 | 316 | * @may_wakeup: means device's remote wakeup is enabled |
|---|
| 317 | 317 | * @is_self_powered: is reported in device status and the config descriptor |
|---|
| 318 | 318 | * @delayed_status: true when function drivers ask for delayed status |
|---|
| 319 | + * @gen2cp: compatible with USB3 Gen2 IP |
|---|
| 319 | 320 | * @ep0_req: dummy request used while handling standard USB requests |
|---|
| 320 | 321 | * for GET_STATUS and SET_SEL |
|---|
| 321 | 322 | * @setup_buf: ep0 response buffer for GET_STATUS and SET_SEL requests |
|---|
| .. | .. |
|---|
| 345 | 346 | struct usb_gadget_driver *gadget_driver; |
|---|
| 346 | 347 | struct mtu3_request ep0_req; |
|---|
| 347 | 348 | u8 setup_buf[EP0_RESPONSE_BUF]; |
|---|
| 348 | | - u32 max_speed; |
|---|
| 349 | + enum usb_device_speed max_speed; |
|---|
| 350 | + enum usb_device_speed speed; |
|---|
| 349 | 351 | |
|---|
| 350 | 352 | unsigned is_active:1; |
|---|
| 351 | 353 | unsigned may_wakeup:1; |
|---|
| .. | .. |
|---|
| 356 | 358 | unsigned u2_enable:1; |
|---|
| 357 | 359 | unsigned is_u3_ip:1; |
|---|
| 358 | 360 | unsigned delayed_status:1; |
|---|
| 361 | + unsigned gen2cp:1; |
|---|
| 359 | 362 | |
|---|
| 360 | 363 | u8 address; |
|---|
| 361 | 364 | u8 test_mode_nr; |
|---|
| .. | .. |
|---|
| 365 | 368 | static inline struct mtu3 *gadget_to_mtu3(struct usb_gadget *g) |
|---|
| 366 | 369 | { |
|---|
| 367 | 370 | return container_of(g, struct mtu3, g); |
|---|
| 368 | | -} |
|---|
| 369 | | - |
|---|
| 370 | | -static inline int is_first_entry(const struct list_head *list, |
|---|
| 371 | | - const struct list_head *head) |
|---|
| 372 | | -{ |
|---|
| 373 | | - return list_is_last(head, list); |
|---|
| 374 | 371 | } |
|---|
| 375 | 372 | |
|---|
| 376 | 373 | static inline struct mtu3_request *to_mtu3_request(struct usb_request *req) |
|---|
| .. | .. |
|---|
| 429 | 426 | void mtu3_start(struct mtu3 *mtu); |
|---|
| 430 | 427 | void mtu3_stop(struct mtu3 *mtu); |
|---|
| 431 | 428 | void mtu3_dev_on_off(struct mtu3 *mtu, int is_on); |
|---|
| 429 | +void mtu3_set_speed(struct mtu3 *mtu, enum usb_device_speed speed); |
|---|
| 432 | 430 | |
|---|
| 433 | 431 | int mtu3_gadget_setup(struct mtu3 *mtu); |
|---|
| 434 | 432 | void mtu3_gadget_cleanup(struct mtu3 *mtu); |
|---|