powertv-usb.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. /*
  2. * powertv-usb.c
  3. *
  4. * Description: ASIC-specific USB device setup and shutdown
  5. *
  6. * Copyright (C) 2005-2009 Scientific-Atlanta, Inc.
  7. * Copyright (C) 2009 Cisco Systems, Inc.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Author: Ken Eppinett
  24. * David Schleef <ds@schleef.org>
  25. *
  26. * NOTE: The bootloader allocates persistent memory at an address which is
  27. * 16 MiB below the end of the highest address in KSEG0. All fixed
  28. * address memory reservations must avoid this region.
  29. */
  30. #include <linux/kernel.h>
  31. #include <linux/export.h>
  32. #include <linux/ioport.h>
  33. #include <linux/platform_device.h>
  34. #include <asm/mach-powertv/asic.h>
  35. #include <asm/mach-powertv/interrupts.h>
  36. /* misc_clk_ctl1 values */
  37. #define MCC1_30MHZ_POWERUP_SELECT (1 << 14)
  38. #define MCC1_DIV9 (1 << 13)
  39. #define MCC1_ETHMIPS_POWERUP_SELECT (1 << 11)
  40. #define MCC1_USB_POWERUP_SELECT (1 << 1)
  41. #define MCC1_CLOCK108_POWERUP_SELECT (1 << 0)
  42. /* Possible values for clock select */
  43. #define MCC1_USB_CLOCK_HIGH_Z (0 << 4)
  44. #define MCC1_USB_CLOCK_48MHZ (1 << 4)
  45. #define MCC1_USB_CLOCK_24MHZ (2 << 4)
  46. #define MCC1_USB_CLOCK_6MHZ (3 << 4)
  47. #define MCC1_CONFIG (MCC1_30MHZ_POWERUP_SELECT | \
  48. MCC1_DIV9 | \
  49. MCC1_ETHMIPS_POWERUP_SELECT | \
  50. MCC1_USB_POWERUP_SELECT | \
  51. MCC1_CLOCK108_POWERUP_SELECT)
  52. /* misc_clk_ctl2 values */
  53. #define MCC2_GMII_GCLK_TO_PAD (1 << 31)
  54. #define MCC2_ETHER125_0_CLOCK_SELECT (1 << 29)
  55. #define MCC2_RMII_0_CLOCK_SELECT (1 << 28)
  56. #define MCC2_GMII_TX0_CLOCK_SELECT (1 << 27)
  57. #define MCC2_GMII_RX0_CLOCK_SELECT (1 << 26)
  58. #define MCC2_ETHER125_1_CLOCK_SELECT (1 << 24)
  59. #define MCC2_RMII_1_CLOCK_SELECT (1 << 23)
  60. #define MCC2_GMII_TX1_CLOCK_SELECT (1 << 22)
  61. #define MCC2_GMII_RX1_CLOCK_SELECT (1 << 21)
  62. #define MCC2_ETHER125_2_CLOCK_SELECT (1 << 19)
  63. #define MCC2_RMII_2_CLOCK_SELECT (1 << 18)
  64. #define MCC2_GMII_TX2_CLOCK_SELECT (1 << 17)
  65. #define MCC2_GMII_RX2_CLOCK_SELECT (1 << 16)
  66. #define ETHER_CLK_CONFIG (MCC2_GMII_GCLK_TO_PAD | \
  67. MCC2_ETHER125_0_CLOCK_SELECT | \
  68. MCC2_RMII_0_CLOCK_SELECT | \
  69. MCC2_GMII_TX0_CLOCK_SELECT | \
  70. MCC2_GMII_RX0_CLOCK_SELECT | \
  71. MCC2_ETHER125_1_CLOCK_SELECT | \
  72. MCC2_RMII_1_CLOCK_SELECT | \
  73. MCC2_GMII_TX1_CLOCK_SELECT | \
  74. MCC2_GMII_RX1_CLOCK_SELECT | \
  75. MCC2_ETHER125_2_CLOCK_SELECT | \
  76. MCC2_RMII_2_CLOCK_SELECT | \
  77. MCC2_GMII_TX2_CLOCK_SELECT | \
  78. MCC2_GMII_RX2_CLOCK_SELECT)
  79. /* misc_clk_ctl2 definitions for Gaia */
  80. #define FSX4A_REF_SELECT (1 << 16)
  81. #define FSX4B_REF_SELECT (1 << 17)
  82. #define FSX4C_REF_SELECT (1 << 18)
  83. #define DDR_PLL_REF_SELECT (1 << 19)
  84. #define MIPS_PLL_REF_SELECT (1 << 20)
  85. /* Definitions for the QAM frequency select register FS432X4A4_QAM_CTL */
  86. #define QAM_FS_SDIV_SHIFT 29
  87. #define QAM_FS_MD_SHIFT 24
  88. #define QAM_FS_MD_MASK 0x1f /* Cut down to 5 bits */
  89. #define QAM_FS_PE_SHIFT 8
  90. #define QAM_FS_DISABLE_DIVIDE_BY_3 (1 << 5)
  91. #define QAM_FS_ENABLE_PROGRAM (1 << 4)
  92. #define QAM_FS_ENABLE_OUTPUT (1 << 3)
  93. #define QAM_FS_SELECT_TEST_BYPASS (1 << 2)
  94. #define QAM_FS_DISABLE_DIGITAL_STANDBY (1 << 1)
  95. #define QAM_FS_CHOOSE_FS (1 << 0)
  96. /* Definitions for fs432x4a_ctl register */
  97. #define QAM_FS_NSDIV_54MHZ (1 << 2)
  98. /* Definitions for bcm1_usb2_ctl register */
  99. #define BCM1_USB2_CTL_BISTOK (1 << 11)
  100. #define BCM1_USB2_CTL_PORT2_SHIFT_JK (1 << 7)
  101. #define BCM1_USB2_CTL_PORT1_SHIFT_JK (1 << 6)
  102. #define BCM1_USB2_CTL_PORT2_FAST_EDGE (1 << 5)
  103. #define BCM1_USB2_CTL_PORT1_FAST_EDGE (1 << 4)
  104. #define BCM1_USB2_CTL_EHCI_PRT_PWR_ACTIVE_HIGH (1 << 1)
  105. #define BCM1_USB2_CTL_APP_PRT_OVRCUR_IN_ACTIVE_HIGH (1 << 0)
  106. /* Definitions for crt_spare register */
  107. #define CRT_SPARE_PORT2_SHIFT_JK (1 << 21)
  108. #define CRT_SPARE_PORT1_SHIFT_JK (1 << 20)
  109. #define CRT_SPARE_PORT2_FAST_EDGE (1 << 19)
  110. #define CRT_SPARE_PORT1_FAST_EDGE (1 << 18)
  111. #define CRT_SPARE_DIVIDE_BY_9_FROM_432 (1 << 17)
  112. #define CRT_SPARE_USB_DIVIDE_BY_9 (1 << 16)
  113. /* Definitions for usb2_stbus_obc register */
  114. #define USB_STBUS_OBC_STORE32_LOAD32 0x3
  115. /* Definitions for usb2_stbus_mess_size register */
  116. #define USB2_STBUS_MESS_SIZE_2 0x1 /* 2 packets */
  117. /* Definitions for usb2_stbus_chunk_size register */
  118. #define USB2_STBUS_CHUNK_SIZE_2 0x1 /* 2 packets */
  119. /* Definitions for usb2_strap register */
  120. #define USB2_STRAP_HFREQ_SELECT 0x1
  121. /*
  122. * USB Host Resource Definition
  123. */
  124. static struct resource ehci_resources[] = {
  125. {
  126. .parent = &asic_resource,
  127. .start = 0,
  128. .end = 0xff,
  129. .flags = IORESOURCE_MEM,
  130. },
  131. {
  132. .start = irq_usbehci,
  133. .end = irq_usbehci,
  134. .flags = IORESOURCE_IRQ,
  135. },
  136. };
  137. static u64 ehci_dmamask = 0xffffffffULL;
  138. static struct platform_device ehci_device = {
  139. .name = "powertv-ehci",
  140. .id = 0,
  141. .num_resources = 2,
  142. .resource = ehci_resources,
  143. .dev = {
  144. .dma_mask = &ehci_dmamask,
  145. .coherent_dma_mask = 0xffffffff,
  146. },
  147. };
  148. static struct resource ohci_resources[] = {
  149. {
  150. .parent = &asic_resource,
  151. .start = 0,
  152. .end = 0xff,
  153. .flags = IORESOURCE_MEM,
  154. },
  155. {
  156. .start = irq_usbohci,
  157. .end = irq_usbohci,
  158. .flags = IORESOURCE_IRQ,
  159. },
  160. };
  161. static u64 ohci_dmamask = 0xffffffffULL;
  162. static struct platform_device ohci_device = {
  163. .name = "powertv-ohci",
  164. .id = 0,
  165. .num_resources = 2,
  166. .resource = ohci_resources,
  167. .dev = {
  168. .dma_mask = &ohci_dmamask,
  169. .coherent_dma_mask = 0xffffffff,
  170. },
  171. };
  172. static unsigned usb_users;
  173. static DEFINE_SPINLOCK(usb_regs_lock);
  174. /*
  175. *
  176. * fs_update - set frequency synthesizer for USB
  177. * @pe_bits Phase tap setting
  178. * @md_bits Coarse selector bus for algorithm of phase tap
  179. * @sdiv_bits Output divider setting
  180. * @disable_div_by_3 Either QAM_FS_DISABLE_DIVIDE_BY_3 or zero
  181. * @standby Either QAM_FS_DISABLE_DIGITAL_STANDBY or zero
  182. *
  183. * QAM frequency selection code, which affects the frequency at which USB
  184. * runs. The frequency is calculated as:
  185. * 2^15 * ndiv * Fin
  186. * Fout = ------------------------------------------------------------
  187. * (sdiv * (ipe * (1 + md/32) - (ipe - 2^15)*(1 + (md + 1)/32)))
  188. * where:
  189. * Fin 54 MHz
  190. * ndiv QAM_FS_NSDIV_54MHZ ? 8 : 16
  191. * sdiv 1 << (sdiv_bits + 1)
  192. * ipe Same as pe_bits
  193. * md A five-bit, two's-complement integer (range [-16, 15]), which
  194. * is the lower 5 bits of md_bits.
  195. */
  196. static void fs_update(u32 pe_bits, int md_bits, u32 sdiv_bits,
  197. u32 disable_div_by_3, u32 standby)
  198. {
  199. u32 val;
  200. val = ((sdiv_bits << QAM_FS_SDIV_SHIFT) |
  201. ((md_bits & QAM_FS_MD_MASK) << QAM_FS_MD_SHIFT) |
  202. (pe_bits << QAM_FS_PE_SHIFT) |
  203. QAM_FS_ENABLE_OUTPUT |
  204. standby |
  205. disable_div_by_3);
  206. asic_write(val, fs432x4b4_usb_ctl);
  207. asic_write(val | QAM_FS_ENABLE_PROGRAM, fs432x4b4_usb_ctl);
  208. asic_write(val | QAM_FS_ENABLE_PROGRAM | QAM_FS_CHOOSE_FS,
  209. fs432x4b4_usb_ctl);
  210. }
  211. /*
  212. * usb_eye_configure - for optimizing the shape USB eye waveform
  213. * @set: Bits to set in the register
  214. * @clear: Bits to clear in the register; each bit with a one will
  215. * be set in the register, zero bits will not be modified
  216. */
  217. static void usb_eye_configure(u32 set, u32 clear)
  218. {
  219. u32 old;
  220. old = asic_read(crt_spare);
  221. old |= set;
  222. old &= ~clear;
  223. asic_write(old, crt_spare);
  224. }
  225. /*
  226. * platform_configure_usb - usb configuration based on platform type.
  227. */
  228. static void platform_configure_usb(void)
  229. {
  230. u32 bcm1_usb2_ctl_value;
  231. enum asic_type asic_type;
  232. unsigned long flags;
  233. spin_lock_irqsave(&usb_regs_lock, flags);
  234. usb_users++;
  235. if (usb_users != 1) {
  236. spin_unlock_irqrestore(&usb_regs_lock, flags);
  237. return;
  238. }
  239. asic_type = platform_get_asic();
  240. switch (asic_type) {
  241. case ASIC_ZEUS:
  242. fs_update(0x0000, -15, 0x02, 0, 0);
  243. bcm1_usb2_ctl_value = BCM1_USB2_CTL_EHCI_PRT_PWR_ACTIVE_HIGH |
  244. BCM1_USB2_CTL_APP_PRT_OVRCUR_IN_ACTIVE_HIGH;
  245. break;
  246. case ASIC_CRONUS:
  247. case ASIC_CRONUSLITE:
  248. usb_eye_configure(0, CRT_SPARE_USB_DIVIDE_BY_9);
  249. fs_update(0x8000, -14, 0x03, QAM_FS_DISABLE_DIVIDE_BY_3,
  250. QAM_FS_DISABLE_DIGITAL_STANDBY);
  251. bcm1_usb2_ctl_value = BCM1_USB2_CTL_EHCI_PRT_PWR_ACTIVE_HIGH |
  252. BCM1_USB2_CTL_APP_PRT_OVRCUR_IN_ACTIVE_HIGH;
  253. break;
  254. case ASIC_CALLIOPE:
  255. fs_update(0x0000, -15, 0x02, QAM_FS_DISABLE_DIVIDE_BY_3,
  256. QAM_FS_DISABLE_DIGITAL_STANDBY);
  257. switch (platform_get_family()) {
  258. case FAMILY_1500VZE:
  259. break;
  260. case FAMILY_1500VZF:
  261. usb_eye_configure(CRT_SPARE_PORT2_SHIFT_JK |
  262. CRT_SPARE_PORT1_SHIFT_JK |
  263. CRT_SPARE_PORT2_FAST_EDGE |
  264. CRT_SPARE_PORT1_FAST_EDGE, 0);
  265. break;
  266. default:
  267. usb_eye_configure(CRT_SPARE_PORT2_SHIFT_JK |
  268. CRT_SPARE_PORT1_SHIFT_JK, 0);
  269. break;
  270. }
  271. bcm1_usb2_ctl_value = BCM1_USB2_CTL_BISTOK |
  272. BCM1_USB2_CTL_EHCI_PRT_PWR_ACTIVE_HIGH |
  273. BCM1_USB2_CTL_APP_PRT_OVRCUR_IN_ACTIVE_HIGH;
  274. break;
  275. case ASIC_GAIA:
  276. fs_update(0x8000, -14, 0x03, QAM_FS_DISABLE_DIVIDE_BY_3,
  277. QAM_FS_DISABLE_DIGITAL_STANDBY);
  278. bcm1_usb2_ctl_value = BCM1_USB2_CTL_BISTOK |
  279. BCM1_USB2_CTL_EHCI_PRT_PWR_ACTIVE_HIGH |
  280. BCM1_USB2_CTL_APP_PRT_OVRCUR_IN_ACTIVE_HIGH;
  281. break;
  282. default:
  283. pr_err("Unknown ASIC type: %d\n", asic_type);
  284. bcm1_usb2_ctl_value = 0;
  285. break;
  286. }
  287. /* turn on USB power */
  288. asic_write(0, usb2_strap);
  289. /* Enable all OHCI interrupts */
  290. asic_write(bcm1_usb2_ctl_value, usb2_control);
  291. /* usb2_stbus_obc store32/load32 */
  292. asic_write(USB_STBUS_OBC_STORE32_LOAD32, usb2_stbus_obc);
  293. /* usb2_stbus_mess_size 2 packets */
  294. asic_write(USB2_STBUS_MESS_SIZE_2, usb2_stbus_mess_size);
  295. /* usb2_stbus_chunk_size 2 packets */
  296. asic_write(USB2_STBUS_CHUNK_SIZE_2, usb2_stbus_chunk_size);
  297. spin_unlock_irqrestore(&usb_regs_lock, flags);
  298. }
  299. static void platform_unconfigure_usb(void)
  300. {
  301. unsigned long flags;
  302. spin_lock_irqsave(&usb_regs_lock, flags);
  303. usb_users--;
  304. if (usb_users == 0)
  305. asic_write(USB2_STRAP_HFREQ_SELECT, usb2_strap);
  306. spin_unlock_irqrestore(&usb_regs_lock, flags);
  307. }
  308. /*
  309. * Set up the USB EHCI interface
  310. */
  311. void platform_configure_usb_ehci()
  312. {
  313. platform_configure_usb();
  314. }
  315. EXPORT_SYMBOL(platform_configure_usb_ehci);
  316. /*
  317. * Set up the USB OHCI interface
  318. */
  319. void platform_configure_usb_ohci()
  320. {
  321. platform_configure_usb();
  322. }
  323. EXPORT_SYMBOL(platform_configure_usb_ohci);
  324. /*
  325. * Shut the USB EHCI interface down
  326. */
  327. void platform_unconfigure_usb_ehci()
  328. {
  329. platform_unconfigure_usb();
  330. }
  331. EXPORT_SYMBOL(platform_unconfigure_usb_ehci);
  332. /*
  333. * Shut the USB OHCI interface down
  334. */
  335. void platform_unconfigure_usb_ohci()
  336. {
  337. platform_unconfigure_usb();
  338. }
  339. EXPORT_SYMBOL(platform_unconfigure_usb_ohci);
  340. /**
  341. * platform_devices_init - sets up USB device resourse.
  342. */
  343. int __init platform_usb_devices_init(struct platform_device **ehci_dev,
  344. struct platform_device **ohci_dev)
  345. {
  346. *ehci_dev = &ehci_device;
  347. ehci_resources[0].start = asic_reg_phys_addr(ehci_hcapbase);
  348. ehci_resources[0].end += ehci_resources[0].start;
  349. *ohci_dev = &ohci_device;
  350. ohci_resources[0].start = asic_reg_phys_addr(ohci_hc_revision);
  351. ohci_resources[0].end += ohci_resources[0].start;
  352. return 0;
  353. }