dwc2_udc_otg_phy.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * drivers/usb/gadget/dwc2_udc_otg.c
  3. * Designware DWC2 on-chip full/high speed USB OTG 2.0 device controllers
  4. *
  5. * Copyright (C) 2008 for Samsung Electronics
  6. *
  7. * BSP Support for Samsung's UDC driver
  8. * available at:
  9. * git://git.kernel.org/pub/scm/linux/kernel/git/kki_ap/linux-2.6-samsung.git
  10. *
  11. * State machine bugfixes:
  12. * Marek Szyprowski <m.szyprowski@samsung.com>
  13. *
  14. * Ported to u-boot:
  15. * Marek Szyprowski <m.szyprowski@samsung.com>
  16. * Lukasz Majewski <l.majewski@samsumg.com>
  17. *
  18. * SPDX-License-Identifier: GPL-2.0+
  19. */
  20. #include <common.h>
  21. #include <asm/errno.h>
  22. #include <linux/list.h>
  23. #include <malloc.h>
  24. #include <linux/usb/ch9.h>
  25. #include <linux/usb/gadget.h>
  26. #include <asm/byteorder.h>
  27. #include <asm/unaligned.h>
  28. #include <asm/io.h>
  29. #include <asm/mach-types.h>
  30. #include "dwc2_udc_otg_regs.h"
  31. #include "dwc2_udc_otg_priv.h"
  32. #include <usb/lin_gadget_compat.h>
  33. #include <usb/dwc2_udc.h>
  34. void otg_phy_init(struct dwc2_udc *dev)
  35. {
  36. unsigned int usb_phy_ctrl = dev->pdata->usb_phy_ctrl;
  37. struct dwc2_usbotg_phy *phy =
  38. (struct dwc2_usbotg_phy *)dev->pdata->regs_phy;
  39. dev->pdata->phy_control(1);
  40. /* USB PHY0 Enable */
  41. printf("USB PHY0 Enable\n");
  42. /* Enable PHY */
  43. writel(readl(usb_phy_ctrl) | USB_PHY_CTRL_EN0, usb_phy_ctrl);
  44. if (dev->pdata->usb_flags == PHY0_SLEEP) /* C210 Universal */
  45. writel((readl(&phy->phypwr)
  46. &~(PHY_0_SLEEP | OTG_DISABLE_0 | ANALOG_PWRDOWN)
  47. &~FORCE_SUSPEND_0), &phy->phypwr);
  48. else /* C110 GONI */
  49. writel((readl(&phy->phypwr) &~(OTG_DISABLE_0 | ANALOG_PWRDOWN)
  50. &~FORCE_SUSPEND_0), &phy->phypwr);
  51. if (s5p_cpu_id == 0x4412)
  52. writel((readl(&phy->phyclk) & ~(EXYNOS4X12_ID_PULLUP0 |
  53. EXYNOS4X12_COMMON_ON_N0)) | EXYNOS4X12_CLK_SEL_24MHZ,
  54. &phy->phyclk); /* PLL 24Mhz */
  55. else
  56. writel((readl(&phy->phyclk) & ~(ID_PULLUP0 | COMMON_ON_N0)) |
  57. CLK_SEL_24MHZ, &phy->phyclk); /* PLL 24Mhz */
  58. writel((readl(&phy->rstcon) &~(LINK_SW_RST | PHYLNK_SW_RST))
  59. | PHY_SW_RST0, &phy->rstcon);
  60. udelay(10);
  61. writel(readl(&phy->rstcon)
  62. &~(PHY_SW_RST0 | LINK_SW_RST | PHYLNK_SW_RST), &phy->rstcon);
  63. udelay(10);
  64. }
  65. void otg_phy_off(struct dwc2_udc *dev)
  66. {
  67. unsigned int usb_phy_ctrl = dev->pdata->usb_phy_ctrl;
  68. struct dwc2_usbotg_phy *phy =
  69. (struct dwc2_usbotg_phy *)dev->pdata->regs_phy;
  70. /* reset controller just in case */
  71. writel(PHY_SW_RST0, &phy->rstcon);
  72. udelay(20);
  73. writel(readl(&phy->phypwr) &~PHY_SW_RST0, &phy->rstcon);
  74. udelay(20);
  75. writel(readl(&phy->phypwr) | OTG_DISABLE_0 | ANALOG_PWRDOWN
  76. | FORCE_SUSPEND_0, &phy->phypwr);
  77. writel(readl(usb_phy_ctrl) &~USB_PHY_CTRL_EN0, usb_phy_ctrl);
  78. writel((readl(&phy->phyclk) & ~(ID_PULLUP0 | COMMON_ON_N0)),
  79. &phy->phyclk);
  80. udelay(10000);
  81. dev->pdata->phy_control(0);
  82. }