phy-exynos4210-usb2.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*
  2. * Samsung SoC USB 1.1/2.0 PHY driver - Exynos 4210 support
  3. *
  4. * Copyright (C) 2013 Samsung Electronics Co., Ltd.
  5. * Author: Kamil Debski <k.debski@samsung.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/delay.h>
  12. #include <linux/io.h>
  13. #include <linux/phy/phy.h>
  14. #include <linux/regmap.h>
  15. #include "phy-samsung-usb2.h"
  16. /* Exynos USB PHY registers */
  17. /* PHY power control */
  18. #define EXYNOS_4210_UPHYPWR 0x0
  19. #define EXYNOS_4210_UPHYPWR_PHY0_SUSPEND BIT(0)
  20. #define EXYNOS_4210_UPHYPWR_PHY0_PWR BIT(3)
  21. #define EXYNOS_4210_UPHYPWR_PHY0_OTG_PWR BIT(4)
  22. #define EXYNOS_4210_UPHYPWR_PHY0_SLEEP BIT(5)
  23. #define EXYNOS_4210_UPHYPWR_PHY0 ( \
  24. EXYNOS_4210_UPHYPWR_PHY0_SUSPEND | \
  25. EXYNOS_4210_UPHYPWR_PHY0_PWR | \
  26. EXYNOS_4210_UPHYPWR_PHY0_OTG_PWR | \
  27. EXYNOS_4210_UPHYPWR_PHY0_SLEEP)
  28. #define EXYNOS_4210_UPHYPWR_PHY1_SUSPEND BIT(6)
  29. #define EXYNOS_4210_UPHYPWR_PHY1_PWR BIT(7)
  30. #define EXYNOS_4210_UPHYPWR_PHY1_SLEEP BIT(8)
  31. #define EXYNOS_4210_UPHYPWR_PHY1 ( \
  32. EXYNOS_4210_UPHYPWR_PHY1_SUSPEND | \
  33. EXYNOS_4210_UPHYPWR_PHY1_PWR | \
  34. EXYNOS_4210_UPHYPWR_PHY1_SLEEP)
  35. #define EXYNOS_4210_UPHYPWR_HSIC0_SUSPEND BIT(9)
  36. #define EXYNOS_4210_UPHYPWR_HSIC0_SLEEP BIT(10)
  37. #define EXYNOS_4210_UPHYPWR_HSIC0 ( \
  38. EXYNOS_4210_UPHYPWR_HSIC0_SUSPEND | \
  39. EXYNOS_4210_UPHYPWR_HSIC0_SLEEP)
  40. #define EXYNOS_4210_UPHYPWR_HSIC1_SUSPEND BIT(11)
  41. #define EXYNOS_4210_UPHYPWR_HSIC1_SLEEP BIT(12)
  42. #define EXYNOS_4210_UPHYPWR_HSIC1 ( \
  43. EXYNOS_4210_UPHYPWR_HSIC1_SUSPEND | \
  44. EXYNOS_4210_UPHYPWR_HSIC1_SLEEP)
  45. /* PHY clock control */
  46. #define EXYNOS_4210_UPHYCLK 0x4
  47. #define EXYNOS_4210_UPHYCLK_PHYFSEL_MASK (0x3 << 0)
  48. #define EXYNOS_4210_UPHYCLK_PHYFSEL_OFFSET 0
  49. #define EXYNOS_4210_UPHYCLK_PHYFSEL_48MHZ (0x0 << 0)
  50. #define EXYNOS_4210_UPHYCLK_PHYFSEL_24MHZ (0x3 << 0)
  51. #define EXYNOS_4210_UPHYCLK_PHYFSEL_12MHZ (0x2 << 0)
  52. #define EXYNOS_4210_UPHYCLK_PHY0_ID_PULLUP BIT(2)
  53. #define EXYNOS_4210_UPHYCLK_PHY0_COMMON_ON BIT(4)
  54. #define EXYNOS_4210_UPHYCLK_PHY1_COMMON_ON BIT(7)
  55. /* PHY reset control */
  56. #define EXYNOS_4210_UPHYRST 0x8
  57. #define EXYNOS_4210_URSTCON_PHY0 BIT(0)
  58. #define EXYNOS_4210_URSTCON_OTG_HLINK BIT(1)
  59. #define EXYNOS_4210_URSTCON_OTG_PHYLINK BIT(2)
  60. #define EXYNOS_4210_URSTCON_PHY1_ALL BIT(3)
  61. #define EXYNOS_4210_URSTCON_PHY1_P0 BIT(4)
  62. #define EXYNOS_4210_URSTCON_PHY1_P1P2 BIT(5)
  63. #define EXYNOS_4210_URSTCON_HOST_LINK_ALL BIT(6)
  64. #define EXYNOS_4210_URSTCON_HOST_LINK_P0 BIT(7)
  65. #define EXYNOS_4210_URSTCON_HOST_LINK_P1 BIT(8)
  66. #define EXYNOS_4210_URSTCON_HOST_LINK_P2 BIT(9)
  67. /* Isolation, configured in the power management unit */
  68. #define EXYNOS_4210_USB_ISOL_DEVICE_OFFSET 0x704
  69. #define EXYNOS_4210_USB_ISOL_DEVICE BIT(0)
  70. #define EXYNOS_4210_USB_ISOL_HOST_OFFSET 0x708
  71. #define EXYNOS_4210_USB_ISOL_HOST BIT(0)
  72. /* USBYPHY1 Floating prevention */
  73. #define EXYNOS_4210_UPHY1CON 0x34
  74. #define EXYNOS_4210_UPHY1CON_FLOAT_PREVENTION 0x1
  75. /* Mode switching SUB Device <-> Host */
  76. #define EXYNOS_4210_MODE_SWITCH_OFFSET 0x21c
  77. #define EXYNOS_4210_MODE_SWITCH_MASK 1
  78. #define EXYNOS_4210_MODE_SWITCH_DEVICE 0
  79. #define EXYNOS_4210_MODE_SWITCH_HOST 1
  80. enum exynos4210_phy_id {
  81. EXYNOS4210_DEVICE,
  82. EXYNOS4210_HOST,
  83. EXYNOS4210_HSIC0,
  84. EXYNOS4210_HSIC1,
  85. EXYNOS4210_NUM_PHYS,
  86. };
  87. /*
  88. * exynos4210_rate_to_clk() converts the supplied clock rate to the value that
  89. * can be written to the phy register.
  90. */
  91. static int exynos4210_rate_to_clk(unsigned long rate, u32 *reg)
  92. {
  93. switch (rate) {
  94. case 12 * MHZ:
  95. *reg = EXYNOS_4210_UPHYCLK_PHYFSEL_12MHZ;
  96. break;
  97. case 24 * MHZ:
  98. *reg = EXYNOS_4210_UPHYCLK_PHYFSEL_24MHZ;
  99. break;
  100. case 48 * MHZ:
  101. *reg = EXYNOS_4210_UPHYCLK_PHYFSEL_48MHZ;
  102. break;
  103. default:
  104. return -EINVAL;
  105. }
  106. return 0;
  107. }
  108. static void exynos4210_isol(struct samsung_usb2_phy_instance *inst, bool on)
  109. {
  110. struct samsung_usb2_phy_driver *drv = inst->drv;
  111. u32 offset;
  112. u32 mask;
  113. switch (inst->cfg->id) {
  114. case EXYNOS4210_DEVICE:
  115. offset = EXYNOS_4210_USB_ISOL_DEVICE_OFFSET;
  116. mask = EXYNOS_4210_USB_ISOL_DEVICE;
  117. break;
  118. case EXYNOS4210_HOST:
  119. offset = EXYNOS_4210_USB_ISOL_HOST_OFFSET;
  120. mask = EXYNOS_4210_USB_ISOL_HOST;
  121. break;
  122. default:
  123. return;
  124. };
  125. regmap_update_bits(drv->reg_pmu, offset, mask, on ? 0 : mask);
  126. }
  127. static void exynos4210_phy_pwr(struct samsung_usb2_phy_instance *inst, bool on)
  128. {
  129. struct samsung_usb2_phy_driver *drv = inst->drv;
  130. u32 rstbits = 0;
  131. u32 phypwr = 0;
  132. u32 rst;
  133. u32 pwr;
  134. u32 clk;
  135. switch (inst->cfg->id) {
  136. case EXYNOS4210_DEVICE:
  137. phypwr = EXYNOS_4210_UPHYPWR_PHY0;
  138. rstbits = EXYNOS_4210_URSTCON_PHY0;
  139. break;
  140. case EXYNOS4210_HOST:
  141. phypwr = EXYNOS_4210_UPHYPWR_PHY1;
  142. rstbits = EXYNOS_4210_URSTCON_PHY1_ALL |
  143. EXYNOS_4210_URSTCON_PHY1_P0 |
  144. EXYNOS_4210_URSTCON_PHY1_P1P2 |
  145. EXYNOS_4210_URSTCON_HOST_LINK_ALL |
  146. EXYNOS_4210_URSTCON_HOST_LINK_P0;
  147. writel(on, drv->reg_phy + EXYNOS_4210_UPHY1CON);
  148. break;
  149. case EXYNOS4210_HSIC0:
  150. phypwr = EXYNOS_4210_UPHYPWR_HSIC0;
  151. rstbits = EXYNOS_4210_URSTCON_PHY1_P1P2 |
  152. EXYNOS_4210_URSTCON_HOST_LINK_P1;
  153. break;
  154. case EXYNOS4210_HSIC1:
  155. phypwr = EXYNOS_4210_UPHYPWR_HSIC1;
  156. rstbits = EXYNOS_4210_URSTCON_PHY1_P1P2 |
  157. EXYNOS_4210_URSTCON_HOST_LINK_P2;
  158. break;
  159. };
  160. if (on) {
  161. clk = readl(drv->reg_phy + EXYNOS_4210_UPHYCLK);
  162. clk &= ~EXYNOS_4210_UPHYCLK_PHYFSEL_MASK;
  163. clk |= drv->ref_reg_val << EXYNOS_4210_UPHYCLK_PHYFSEL_OFFSET;
  164. writel(clk, drv->reg_phy + EXYNOS_4210_UPHYCLK);
  165. pwr = readl(drv->reg_phy + EXYNOS_4210_UPHYPWR);
  166. pwr &= ~phypwr;
  167. writel(pwr, drv->reg_phy + EXYNOS_4210_UPHYPWR);
  168. rst = readl(drv->reg_phy + EXYNOS_4210_UPHYRST);
  169. rst |= rstbits;
  170. writel(rst, drv->reg_phy + EXYNOS_4210_UPHYRST);
  171. udelay(10);
  172. rst &= ~rstbits;
  173. writel(rst, drv->reg_phy + EXYNOS_4210_UPHYRST);
  174. /* The following delay is necessary for the reset sequence to be
  175. * completed */
  176. udelay(80);
  177. } else {
  178. pwr = readl(drv->reg_phy + EXYNOS_4210_UPHYPWR);
  179. pwr |= phypwr;
  180. writel(pwr, drv->reg_phy + EXYNOS_4210_UPHYPWR);
  181. }
  182. }
  183. static int exynos4210_power_on(struct samsung_usb2_phy_instance *inst)
  184. {
  185. /* Order of initialisation is important - first power then isolation */
  186. exynos4210_phy_pwr(inst, 1);
  187. exynos4210_isol(inst, 0);
  188. return 0;
  189. }
  190. static int exynos4210_power_off(struct samsung_usb2_phy_instance *inst)
  191. {
  192. exynos4210_isol(inst, 1);
  193. exynos4210_phy_pwr(inst, 0);
  194. return 0;
  195. }
  196. static const struct samsung_usb2_common_phy exynos4210_phys[] = {
  197. {
  198. .label = "device",
  199. .id = EXYNOS4210_DEVICE,
  200. .power_on = exynos4210_power_on,
  201. .power_off = exynos4210_power_off,
  202. },
  203. {
  204. .label = "host",
  205. .id = EXYNOS4210_HOST,
  206. .power_on = exynos4210_power_on,
  207. .power_off = exynos4210_power_off,
  208. },
  209. {
  210. .label = "hsic0",
  211. .id = EXYNOS4210_HSIC0,
  212. .power_on = exynos4210_power_on,
  213. .power_off = exynos4210_power_off,
  214. },
  215. {
  216. .label = "hsic1",
  217. .id = EXYNOS4210_HSIC1,
  218. .power_on = exynos4210_power_on,
  219. .power_off = exynos4210_power_off,
  220. },
  221. };
  222. const struct samsung_usb2_phy_config exynos4210_usb2_phy_config = {
  223. .has_mode_switch = 0,
  224. .num_phys = EXYNOS4210_NUM_PHYS,
  225. .phys = exynos4210_phys,
  226. .rate_to_clk = exynos4210_rate_to_clk,
  227. };