1 // SPDX-License-Identifier: GPL-2.0
3 * R8A66597 HCD (Host Controller Driver) for u-boot
5 * Copyright (C) 2008 Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com>
14 #include <dm/device_compat.h>
15 #include <linux/delay.h>
16 #include <linux/iopoll.h>
17 #include <power/regulator.h>
22 #define R8A66597_DPRINT printf
24 #define R8A66597_DPRINT(...)
27 static inline struct usb_device *usb_dev_get_parent(struct usb_device *udev)
29 struct udevice *parent = udev->dev->parent;
32 * When called from usb-uclass.c: usb_scan_device() udev->dev points
33 * to the parent udevice, not the actual udevice belonging to the
34 * udev as the device is not instantiated yet.
36 * If dev is an usb-bus, then we are called from usb_scan_device() for
37 * an usb-device plugged directly into the root port, return NULL.
39 if (device_get_uclass_id(udev->dev) == UCLASS_USB)
43 * If these 2 are not the same we are being called from
44 * usb_scan_device() and udev itself is the parent.
46 if (dev_get_parent_priv(udev->dev) != udev)
49 /* We are being called normally, use the parent pointer */
50 if (device_get_uclass_id(parent) == UCLASS_USB_HUB)
51 return dev_get_parent_priv(parent);
56 static void get_hub_data(struct usb_device *dev, u16 *hub_devnum, u16 *hubport)
58 struct usb_device *parent = usb_dev_get_parent(dev);
63 /* check a device connected to root_hub */
64 if ((parent && parent->devnum == 1) ||
68 *hub_devnum = (u8)parent->devnum;
69 *hubport = parent->portnr - 1;
72 static void set_devadd(struct r8a66597 *r8a66597, u8 r8a66597_address,
73 struct usb_device *dev, int port)
75 u16 val, usbspd, upphub, hubport;
76 unsigned long devadd_reg = get_devadd_addr(r8a66597_address);
78 get_hub_data(dev, &upphub, &hubport);
79 usbspd = r8a66597->speed;
80 val = (upphub << 11) | (hubport << 8) | (usbspd << 6) | (port & 0x0001);
81 r8a66597_write(r8a66597, val, devadd_reg);
84 static int r8a66597_clock_enable(struct r8a66597 *r8a66597)
90 r8a66597_write(r8a66597, USBE, SYSCFG0);
91 tmp = r8a66597_read(r8a66597, SYSCFG0);
93 printf("register access fail.\n");
96 } while ((tmp & USBE) != USBE);
97 r8a66597_bclr(r8a66597, USBE, SYSCFG0);
100 * Bits XTAL(UCKSEL) and UPLLE in SYSCFG0 for USB0 controls both USB0
101 * and USB1, so we must always set the USB0 register
103 #if (CONFIG_R8A66597_XTAL == 1)
104 r8a66597_bset(r8a66597, XTAL, SYSCFG0);
107 r8a66597_bset(r8a66597, UPLLE, SYSCFG0);
109 r8a66597_bset(r8a66597, SUSPM, SUSPMODE0);
114 static void r8a66597_clock_disable(struct r8a66597 *r8a66597)
116 r8a66597_bclr(r8a66597, SUSPM, SUSPMODE0);
118 r8a66597_bclr(r8a66597, UPLLE, SYSCFG0);
120 r8a66597_bclr(r8a66597, USBE, SYSCFG0);
124 static void r8a66597_enable_port(struct r8a66597 *r8a66597, int port)
128 val = port ? DRPD : DCFM | DRPD;
129 r8a66597_bset(r8a66597, val, get_syscfg_reg(port));
130 r8a66597_bset(r8a66597, HSE, get_syscfg_reg(port));
133 static void r8a66597_disable_port(struct r8a66597 *r8a66597, int port)
137 r8a66597_write(r8a66597, 0, get_intenb_reg(port));
138 r8a66597_write(r8a66597, 0, get_intsts_reg(port));
140 r8a66597_port_power(r8a66597, port, 0);
143 tmp = r8a66597_read(r8a66597, SOFCFG) & EDGESTS;
145 } while (tmp == EDGESTS);
147 val = port ? DRPD : DCFM | DRPD;
148 r8a66597_bclr(r8a66597, val, get_syscfg_reg(port));
149 r8a66597_bclr(r8a66597, HSE, get_syscfg_reg(port));
152 static int enable_controller(struct r8a66597 *r8a66597)
156 ret = r8a66597_clock_enable(r8a66597);
160 r8a66597_bset(r8a66597, USBE, SYSCFG0);
162 r8a66597_bset(r8a66597, INTL, SOFCFG);
163 r8a66597_write(r8a66597, 0, INTENB0);
164 for (port = 0; port < R8A66597_MAX_ROOT_HUB; port++)
165 r8a66597_write(r8a66597, 0, get_intenb_reg(port));
167 r8a66597_bclr(r8a66597, BIGEND, CFIFOSEL);
168 r8a66597_bclr(r8a66597, BIGEND, D0FIFOSEL);
169 r8a66597_bclr(r8a66597, BIGEND, D1FIFOSEL);
170 r8a66597_bset(r8a66597, TRNENSEL, SOFCFG);
172 for (port = 0; port < R8A66597_MAX_ROOT_HUB; port++)
173 r8a66597_enable_port(r8a66597, port);
178 static void disable_controller(struct r8a66597 *r8a66597)
182 if (!(r8a66597_read(r8a66597, SYSCFG0) & USBE))
185 r8a66597_write(r8a66597, 0, INTENB0);
186 r8a66597_write(r8a66597, 0, INTSTS0);
188 r8a66597_write(r8a66597, 0, D0FIFOSEL);
189 r8a66597_write(r8a66597, 0, D1FIFOSEL);
190 r8a66597_write(r8a66597, 0, DCPCFG);
191 r8a66597_write(r8a66597, 0x40, DCPMAXP);
192 r8a66597_write(r8a66597, 0, DCPCTR);
194 for (i = 0; i <= 10; i++)
195 r8a66597_write(r8a66597, 0, get_devadd_addr(i));
196 for (i = 1; i <= 5; i++) {
197 r8a66597_write(r8a66597, 0, get_pipetre_addr(i));
198 r8a66597_write(r8a66597, 0, get_pipetrn_addr(i));
200 for (i = 1; i < R8A66597_MAX_NUM_PIPE; i++) {
201 r8a66597_write(r8a66597, 0, get_pipectr_addr(i));
202 r8a66597_write(r8a66597, i, PIPESEL);
203 r8a66597_write(r8a66597, 0, PIPECFG);
204 r8a66597_write(r8a66597, 0, PIPEBUF);
205 r8a66597_write(r8a66597, 0, PIPEMAXP);
206 r8a66597_write(r8a66597, 0, PIPEPERI);
209 for (i = 0; i < R8A66597_MAX_ROOT_HUB; i++)
210 r8a66597_disable_port(r8a66597, i);
212 r8a66597_clock_disable(r8a66597);
215 static void r8a66597_reg_wait(struct r8a66597 *r8a66597, unsigned long reg,
222 tmp = r8a66597_read(r8a66597, reg);
224 printf("register%lx, loop %x is timeout\n", reg, loop);
227 } while ((tmp & mask) != loop);
230 static void pipe_buffer_setting(struct r8a66597 *r8a66597,
231 struct usb_device *dev, unsigned long pipe)
234 u16 pipenum, bufnum, maxpacket;
236 if (usb_pipein(pipe)) {
237 pipenum = BULK_IN_PIPENUM;
238 bufnum = BULK_IN_BUFNUM;
239 maxpacket = dev->epmaxpacketin[usb_pipeendpoint(pipe)];
241 pipenum = BULK_OUT_PIPENUM;
242 bufnum = BULK_OUT_BUFNUM;
243 maxpacket = dev->epmaxpacketout[usb_pipeendpoint(pipe)];
246 if (r8a66597->pipe_config & (1 << pipenum))
248 r8a66597->pipe_config |= (1 << pipenum);
250 r8a66597_bset(r8a66597, ACLRM, get_pipectr_addr(pipenum));
251 r8a66597_bclr(r8a66597, ACLRM, get_pipectr_addr(pipenum));
252 r8a66597_write(r8a66597, pipenum, PIPESEL);
254 /* FIXME: This driver support bulk transfer only. */
255 if (!usb_pipein(pipe))
258 val |= R8A66597_SHTNAK;
259 val |= R8A66597_BULK | R8A66597_DBLB | usb_pipeendpoint(pipe);
260 r8a66597_write(r8a66597, val, PIPECFG);
262 r8a66597_write(r8a66597, (8 << 10) | bufnum, PIPEBUF);
263 r8a66597_write(r8a66597, make_devsel(usb_pipedevice(pipe)) |
264 maxpacket, PIPEMAXP);
265 r8a66597_write(r8a66597, 0, PIPEPERI);
266 r8a66597_write(r8a66597, SQCLR, get_pipectr_addr(pipenum));
269 static int send_setup_packet(struct r8a66597 *r8a66597, struct usb_device *dev,
270 struct devrequest *setup)
273 unsigned short *p = (unsigned short *)setup;
274 unsigned long setup_addr = USBREQ;
278 u16 devsel = setup->request == USB_REQ_SET_ADDRESS ? 0 : dev->devnum;
280 r8a66597_write(r8a66597, make_devsel(devsel) |
281 (8 << dev->maxpacketsize), DCPMAXP);
282 r8a66597_write(r8a66597, ~(SIGN | SACK), INTSTS1);
284 dcpctr = r8a66597_read(r8a66597, DCPCTR);
285 if ((dcpctr & PID) == PID_BUF) {
286 if (readw_poll_timeout(r8a66597->reg + DCPCTR, dcpctr,
287 dcpctr & BSTS, 1000) < 0) {
288 printf("DCPCTR BSTS timeout!\n");
293 for (i = 0; i < 4; i++) {
294 r8a66597_write(r8a66597, le16_to_cpu(p[i]), setup_addr);
297 r8a66597_write(r8a66597, ~0x0001, BRDYSTS);
298 r8a66597_write(r8a66597, SUREQ, DCPCTR);
301 intsts1 = r8a66597_read(r8a66597, INTSTS1);
304 if (intsts1 & SIGN) {
305 printf("setup packet send error\n");
309 printf("setup packet timeout\n");
318 static int send_bulk_packet(struct r8a66597 *r8a66597, struct usb_device *dev,
319 unsigned long pipe, void *buffer, int transfer_len)
325 R8A66597_DPRINT("%s\n", __func__);
327 r8a66597_mdfy(r8a66597, MBW | BULK_OUT_PIPENUM,
328 MBW | CURPIPE, CFIFOSEL);
329 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, BULK_OUT_PIPENUM);
330 tmp = r8a66597_read(r8a66597, CFIFOCTR);
331 if ((tmp & FRDY) == 0) {
332 printf("%s FRDY is not set (%x)\n", __func__, tmp);
336 /* prepare parameters */
337 bufsize = dev->epmaxpacketout[usb_pipeendpoint(pipe)];
338 buf = (u16 *)(buffer + dev->act_len);
339 size = min((int)bufsize, transfer_len - dev->act_len);
342 r8a66597_write(r8a66597, ~(1 << BULK_OUT_PIPENUM), BEMPSTS);
344 r8a66597_write_fifo(r8a66597, CFIFO, buf, size);
345 r8a66597_write(r8a66597, BVAL, CFIFOCTR);
348 /* update parameters */
349 dev->act_len += size;
351 r8a66597_mdfy(r8a66597, PID_BUF, PID,
352 get_pipectr_addr(BULK_OUT_PIPENUM));
354 while (!(r8a66597_read(r8a66597, BEMPSTS) & (1 << BULK_OUT_PIPENUM)))
357 r8a66597_write(r8a66597, ~(1 << BULK_OUT_PIPENUM), BEMPSTS);
359 if (dev->act_len >= transfer_len)
360 r8a66597_mdfy(r8a66597, PID_NAK, PID,
361 get_pipectr_addr(BULK_OUT_PIPENUM));
366 static int receive_bulk_packet(struct r8a66597 *r8a66597,
367 struct usb_device *dev,
369 void *buffer, int transfer_len)
373 const u16 pipenum = BULK_IN_PIPENUM;
375 int maxpacket = dev->epmaxpacketin[usb_pipeendpoint(pipe)];
377 R8A66597_DPRINT("%s\n", __func__);
380 if (dev->act_len == 0) {
381 r8a66597_mdfy(r8a66597, PID_NAK, PID,
382 get_pipectr_addr(pipenum));
383 r8a66597_write(r8a66597, ~(1 << pipenum), BRDYSTS);
385 r8a66597_write(r8a66597, TRCLR, get_pipetre_addr(pipenum));
386 r8a66597_write(r8a66597,
387 (transfer_len + maxpacket - 1) / maxpacket,
388 get_pipetrn_addr(pipenum));
389 r8a66597_bset(r8a66597, TRENB, get_pipetre_addr(pipenum));
391 r8a66597_mdfy(r8a66597, PID_BUF, PID,
392 get_pipectr_addr(pipenum));
395 r8a66597_mdfy(r8a66597, MBW | pipenum, MBW | CURPIPE, CFIFOSEL);
396 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, pipenum);
398 while (!(r8a66597_read(r8a66597, BRDYSTS) & (1 << pipenum)))
401 r8a66597_write(r8a66597, ~(1 << pipenum), BRDYSTS);
403 tmp = r8a66597_read(r8a66597, CFIFOCTR);
404 if ((tmp & FRDY) == 0) {
405 printf("%s FRDY is not set. (%x)\n", __func__, tmp);
409 buf = (u16 *)(buffer + dev->act_len);
410 rcv_len = tmp & DTLN;
411 dev->act_len += rcv_len;
415 r8a66597_write(r8a66597, BCLR, CFIFOCTR);
417 r8a66597_read_fifo(r8a66597, CFIFO, buf, rcv_len);
423 static int receive_control_packet(struct r8a66597 *r8a66597,
424 struct usb_device *dev,
425 void *buffer, int transfer_len)
430 /* FIXME: limit transfer size : 64byte or less */
432 r8a66597_bclr(r8a66597, R8A66597_DIR, DCPCFG);
433 r8a66597_mdfy(r8a66597, 0, ISEL | CURPIPE, CFIFOSEL);
434 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0);
435 r8a66597_bset(r8a66597, SQSET, DCPCTR);
436 r8a66597_write(r8a66597, BCLR, CFIFOCTR);
437 r8a66597_mdfy(r8a66597, PID_BUF, PID, DCPCTR);
439 while (!(r8a66597_read(r8a66597, BRDYSTS) & 0x0001))
442 r8a66597_write(r8a66597, ~0x0001, BRDYSTS);
444 r8a66597_mdfy(r8a66597, MBW, MBW | CURPIPE, CFIFOSEL);
445 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0);
447 tmp = r8a66597_read(r8a66597, CFIFOCTR);
448 if ((tmp & FRDY) == 0) {
449 printf("%s FRDY is not set. (%x)\n", __func__, tmp);
453 rcv_len = tmp & DTLN;
454 dev->act_len += rcv_len;
456 r8a66597_mdfy(r8a66597, PID_NAK, PID, DCPCTR);
460 r8a66597_write(r8a66597, BCLR, DCPCTR);
462 r8a66597_read_fifo(r8a66597, CFIFO, buffer, rcv_len);
468 static int send_status_packet(struct r8a66597 *r8a66597,
471 r8a66597_bset(r8a66597, SQSET, DCPCTR);
472 r8a66597_mdfy(r8a66597, PID_NAK, PID, DCPCTR);
474 if (usb_pipein(pipe)) {
475 r8a66597_bset(r8a66597, R8A66597_DIR, DCPCFG);
476 r8a66597_mdfy(r8a66597, ISEL, ISEL | CURPIPE, CFIFOSEL);
477 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0);
478 r8a66597_write(r8a66597, ~BEMP0, BEMPSTS);
479 r8a66597_write(r8a66597, BCLR | BVAL, CFIFOCTR);
481 r8a66597_bclr(r8a66597, R8A66597_DIR, DCPCFG);
482 r8a66597_mdfy(r8a66597, 0, ISEL | CURPIPE, CFIFOSEL);
483 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0);
484 r8a66597_write(r8a66597, BCLR, CFIFOCTR);
486 r8a66597_mdfy(r8a66597, PID_BUF, PID, DCPCTR);
488 while (!(r8a66597_read(r8a66597, BEMPSTS) & 0x0001))
495 static void r8a66597_check_syssts(struct r8a66597 *r8a66597, int port)
497 int count = R8A66597_MAX_SAMPLING;
498 unsigned short syssts, old_syssts;
500 R8A66597_DPRINT("%s\n", __func__);
502 old_syssts = r8a66597_read(r8a66597, get_syssts_reg(port) & LNST);
504 mdelay(R8A66597_RH_POLL_TIME);
506 syssts = r8a66597_read(r8a66597, get_syssts_reg(port) & LNST);
507 if (syssts == old_syssts) {
510 count = R8A66597_MAX_SAMPLING;
516 static void r8a66597_bus_reset(struct r8a66597 *r8a66597, int port)
519 r8a66597_mdfy(r8a66597, USBRST, USBRST | UACT, get_dvstctr_reg(port));
521 r8a66597_mdfy(r8a66597, UACT, USBRST | UACT, get_dvstctr_reg(port));
525 static int check_usb_device_connecting(struct r8a66597 *r8a66597)
527 int timeout = 10000; /* 100usec * 10000 = 1sec */
530 for (i = 0; i < 5; i++) {
531 /* check a usb cable connect */
532 while (!(r8a66597_read(r8a66597, INTSTS1) & ATTCH)) {
534 printf("%s timeout.\n", __func__);
540 /* check a data line */
541 r8a66597_check_syssts(r8a66597, 0);
543 r8a66597_bus_reset(r8a66597, 0);
544 r8a66597->speed = get_rh_usb_speed(r8a66597, 0);
546 if (!(r8a66597_read(r8a66597, INTSTS1) & DTCH)) {
547 r8a66597->port_change = USB_PORT_STAT_C_CONNECTION;
548 r8a66597->port_status = USB_PORT_STAT_CONNECTION |
549 USB_PORT_STAT_ENABLE;
550 return 0; /* success */
553 R8A66597_DPRINT("USB device has detached. retry = %d\n", i);
554 r8a66597_write(r8a66597, ~DTCH, INTSTS1);
557 return -1; /* fail */
560 /* Virtual Root Hub */
562 #include <usbroothubdes.h>
564 static int r8a66597_submit_rh_msg(struct udevice *udev, struct usb_device *dev,
565 unsigned long pipe, void *buffer,
566 int transfer_len, struct devrequest *cmd)
568 struct r8a66597 *r8a66597 = dev_get_priv(udev);
569 int leni = transfer_len;
575 unsigned char data[32];
577 R8A66597_DPRINT("%s\n", __func__);
579 if (usb_pipeint(pipe)) {
580 printf("Root-Hub submit IRQ: NOT implemented");
584 bmRType_bReq = cmd->requesttype | (cmd->request << 8);
585 wValue = cpu_to_le16 (cmd->value);
586 wLength = cpu_to_le16 (cmd->length);
588 switch (bmRType_bReq) {
590 *(__u16 *)buffer = cpu_to_le16(1);
593 case RH_GET_STATUS | RH_INTERFACE:
594 *(__u16 *)buffer = cpu_to_le16(0);
597 case RH_GET_STATUS | RH_ENDPOINT:
598 *(__u16 *)buffer = cpu_to_le16(0);
601 case RH_GET_STATUS | RH_CLASS:
602 *(__u32 *)buffer = cpu_to_le32(0);
605 case RH_GET_STATUS | RH_OTHER | RH_CLASS:
606 *(__u32 *)buffer = cpu_to_le32(r8a66597->port_status |
607 (r8a66597->port_change << 16));
610 case RH_CLEAR_FEATURE | RH_ENDPOINT:
611 case RH_CLEAR_FEATURE | RH_CLASS:
614 case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS:
616 case RH_C_PORT_CONNECTION:
617 r8a66597->port_change &= ~USB_PORT_STAT_C_CONNECTION;
622 case RH_SET_FEATURE | RH_OTHER | RH_CLASS:
624 case (RH_PORT_SUSPEND):
626 case (RH_PORT_RESET):
627 r8a66597_bus_reset(r8a66597, 0);
629 case (RH_PORT_POWER):
631 case (RH_PORT_ENABLE):
636 r8a66597->rh_devnum = wValue;
638 case RH_GET_DESCRIPTOR:
639 switch ((wValue & 0xff00) >> 8) {
640 case (0x01): /* device descriptor */
641 len = min_t(unsigned int,
644 sizeof(root_hub_dev_des),
646 memcpy(buffer, root_hub_dev_des, len);
648 case (0x02): /* configuration descriptor */
649 len = min_t(unsigned int,
652 sizeof(root_hub_config_des),
654 memcpy(buffer, root_hub_config_des, len);
656 case (0x03): /* string descriptors */
657 if (wValue == 0x0300) {
658 len = min_t(unsigned int,
661 sizeof(root_hub_str_index0),
663 memcpy(buffer, root_hub_str_index0, len);
665 if (wValue == 0x0301) {
666 len = min_t(unsigned int,
669 sizeof(root_hub_str_index1),
671 memcpy(buffer, root_hub_str_index1, len);
675 stat = USB_ST_STALLED;
679 case RH_GET_DESCRIPTOR | RH_CLASS:
681 __u32 temp = 0x00000001;
683 data[0] = 9; /* min length; */
685 data[2] = temp & RH_A_NDP;
689 if (temp & RH_A_NOCP)
691 else if (temp & RH_A_OCPM)
694 /* corresponds to data[4-7] */
695 data[5] = (temp & RH_A_POTPGT) >> 24;
696 data[7] = temp & RH_B_DR;
701 data[8] = (temp & RH_B_DR) >> 8;
706 len = min_t(unsigned int, leni,
707 min_t(unsigned int, data[0], wLength));
708 memcpy(buffer, data, len);
712 case RH_GET_CONFIGURATION:
713 *(__u8 *)buffer = 0x01;
716 case RH_SET_CONFIGURATION:
719 R8A66597_DPRINT("unsupported root hub command");
720 stat = USB_ST_STALLED;
725 len = min_t(int, len, leni);
733 static int r8a66597_submit_control_msg(struct udevice *udev,
734 struct usb_device *dev,
735 unsigned long pipe, void *buffer,
736 int length, struct devrequest *setup)
738 struct r8a66597 *r8a66597 = dev_get_priv(udev);
739 u16 r8a66597_address = setup->request == USB_REQ_SET_ADDRESS ?
742 debug("%s: dev='%s', udev=%p, udev->dev='%s', portnr=%d\n", __func__,
743 udev->name, dev, dev->dev->name, dev->portnr);
745 R8A66597_DPRINT("%s\n", __func__);
746 if (usb_pipedevice(pipe) == r8a66597->rh_devnum)
747 return r8a66597_submit_rh_msg(udev, dev, pipe, buffer,
750 R8A66597_DPRINT("%s: setup\n", __func__);
751 set_devadd(r8a66597, r8a66597_address, dev, 0);
753 if (send_setup_packet(r8a66597, dev, setup) < 0) {
754 printf("setup packet send error\n");
759 if (usb_pipein(pipe))
760 if (receive_control_packet(r8a66597, dev, buffer,
764 if (send_status_packet(r8a66597, pipe) < 0)
772 static int r8a66597_submit_bulk_msg(struct udevice *udev,
773 struct usb_device *dev, unsigned long pipe,
774 void *buffer, int length)
776 struct r8a66597 *r8a66597 = dev_get_priv(udev);
779 debug("%s: dev='%s', udev=%p\n", __func__, udev->name, dev);
781 R8A66597_DPRINT("%s\n", __func__);
782 R8A66597_DPRINT("pipe = %08x, buffer = %p, len = %d, devnum = %d\n",
783 pipe, buffer, length, dev->devnum);
785 set_devadd(r8a66597, dev->devnum, dev, 0);
787 pipe_buffer_setting(r8a66597, dev, pipe);
790 while (dev->act_len < length && ret == 0) {
794 if (usb_pipein(pipe))
795 ret = receive_bulk_packet(r8a66597, dev, pipe, buffer,
798 ret = send_bulk_packet(r8a66597, dev, pipe, buffer,
808 static int r8a66597_usb_ofdata_to_platdata(struct udevice *dev)
810 struct r8a66597 *priv = dev_get_priv(dev);
813 addr = dev_read_addr(dev);
814 if (addr == FDT_ADDR_T_NONE)
821 static int r8a66597_usb_probe(struct udevice *dev)
823 struct r8a66597 *priv = dev_get_priv(dev);
824 struct usb_bus_priv *bus_priv = dev_get_uclass_priv(dev);
827 bus_priv->desc_before_addr = true;
829 if (CONFIG_IS_ENABLED(DM_REGULATOR)) {
830 ret = device_get_supply_regulator(dev, "vbus-supply",
834 "can't get VBUS supply\n");
838 ret = regulator_set_enable(priv->vbus_supply, true);
841 "can't enable VBUS supply\n");
846 disable_controller(priv);
849 enable_controller(priv);
850 r8a66597_port_power(priv, 0, 1);
852 /* check usb device */
853 check_usb_device_connecting(priv);
860 static int r8a66597_usb_remove(struct udevice *dev)
862 struct r8a66597 *priv = dev_get_priv(dev);
865 disable_controller(priv);
867 if (CONFIG_IS_ENABLED(DM_REGULATOR)) {
868 ret = regulator_set_enable(priv->vbus_supply, false);
871 "can't disable VBUS supply\n");
879 struct dm_usb_ops r8a66597_usb_ops = {
880 .control = r8a66597_submit_control_msg,
881 .bulk = r8a66597_submit_bulk_msg,
884 static const struct udevice_id r8a66597_usb_ids[] = {
885 { .compatible = "renesas,rza1-usbhs" },
889 U_BOOT_DRIVER(usb_r8a66597) = {
890 .name = "r8a66597_usb",
892 .of_match = r8a66597_usb_ids,
893 .ofdata_to_platdata = r8a66597_usb_ofdata_to_platdata,
894 .probe = r8a66597_usb_probe,
895 .remove = r8a66597_usb_remove,
896 .ops = &r8a66597_usb_ops,
897 .priv_auto = sizeof(struct r8a66597),
898 .flags = DM_FLAG_ALLOC_PRIV_DMA,