blob: 155677e0d948f642313899c35804621b18fc49ac [file] [log] [blame]
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +05301/*
Rajeshwari Shinde7590d3c2012-05-21 16:38:03 +05302 * SAMSUNG EXYNOS USB HOST EHCI Controller
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +05303 *
4 * Copyright (C) 2012 Samsung Electronics Co.Ltd
5 * Vivek Gautam <gautam.vivek@samsung.com>
6 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +05308 */
9
10#include <common.h>
Rajeshwari Shindee18bf1f2013-01-07 23:35:03 +000011#include <fdtdec.h>
12#include <libfdt.h>
13#include <malloc.h>
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +053014#include <usb.h>
15#include <asm/arch/cpu.h>
Rajeshwari Shinde7590d3c2012-05-21 16:38:03 +053016#include <asm/arch/ehci.h>
Rajeshwari Shinde71045da2012-05-14 05:52:02 +000017#include <asm/arch/system.h>
Rajeshwari Shindec48ac112012-05-14 05:52:03 +000018#include <asm/arch/power.h>
Rajeshwari Shindee18bf1f2013-01-07 23:35:03 +000019#include <asm-generic/errno.h>
20#include <linux/compat.h>
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +053021#include "ehci.h"
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +053022
Rajeshwari Shindee18bf1f2013-01-07 23:35:03 +000023/* Declare global data pointer */
24DECLARE_GLOBAL_DATA_PTR;
25
26/**
27 * Contains pointers to register base addresses
28 * for the usb controller.
29 */
30struct exynos_ehci {
31 struct exynos_usb_phy *usb;
Vivek Gautam24a47752013-03-06 14:18:32 +053032 struct ehci_hccr *hcd;
Rajeshwari Shindee18bf1f2013-01-07 23:35:03 +000033};
34
Vivek Gautam24a47752013-03-06 14:18:32 +053035static struct exynos_ehci exynos;
36
Vivek Gautamc74b0112013-03-06 14:18:33 +053037#ifdef CONFIG_OF_CONTROL
Rajeshwari Shindee18bf1f2013-01-07 23:35:03 +000038static int exynos_usb_parse_dt(const void *blob, struct exynos_ehci *exynos)
39{
Vivek Gautam24a47752013-03-06 14:18:32 +053040 fdt_addr_t addr;
Rajeshwari Shindee18bf1f2013-01-07 23:35:03 +000041 unsigned int node;
42 int depth;
43
44 node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS_EHCI);
45 if (node <= 0) {
46 debug("EHCI: Can't get device node for ehci\n");
47 return -ENODEV;
48 }
49
50 /*
51 * Get the base address for EHCI controller from the device node
52 */
Vivek Gautam24a47752013-03-06 14:18:32 +053053 addr = fdtdec_get_addr(blob, node, "reg");
54 if (addr == FDT_ADDR_T_NONE) {
Rajeshwari Shindee18bf1f2013-01-07 23:35:03 +000055 debug("Can't get the EHCI register address\n");
56 return -ENXIO;
57 }
58
Vivek Gautam24a47752013-03-06 14:18:32 +053059 exynos->hcd = (struct ehci_hccr *)addr;
60
Rajeshwari Shindee18bf1f2013-01-07 23:35:03 +000061 depth = 0;
62 node = fdtdec_next_compatible_subnode(blob, node,
63 COMPAT_SAMSUNG_EXYNOS_USB_PHY, &depth);
64 if (node <= 0) {
65 debug("EHCI: Can't get device node for usb-phy controller\n");
66 return -ENODEV;
67 }
68
69 /*
70 * Get the base address for usbphy from the device node
71 */
72 exynos->usb = (struct exynos_usb_phy *)fdtdec_get_addr(blob, node,
73 "reg");
74 if (exynos->usb == NULL) {
75 debug("Can't get the usbphy register address\n");
76 return -ENXIO;
77 }
78
79 return 0;
80}
Vivek Gautamc74b0112013-03-06 14:18:33 +053081#endif
Rajeshwari Shindee18bf1f2013-01-07 23:35:03 +000082
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +053083/* Setup the EHCI host controller. */
Rajeshwari Shinde7590d3c2012-05-21 16:38:03 +053084static void setup_usb_phy(struct exynos_usb_phy *usb)
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +053085{
Rajeshwari Shinde71045da2012-05-14 05:52:02 +000086 set_usbhost_mode(USB20_PHY_CFG_HOST_LINK_EN);
87
Rajeshwari Shindec48ac112012-05-14 05:52:03 +000088 set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_EN);
89
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +053090 clrbits_le32(&usb->usbphyctrl0,
91 HOST_CTRL0_FSEL_MASK |
92 HOST_CTRL0_COMMONON_N |
93 /* HOST Phy setting */
94 HOST_CTRL0_PHYSWRST |
95 HOST_CTRL0_PHYSWRSTALL |
96 HOST_CTRL0_SIDDQ |
97 HOST_CTRL0_FORCESUSPEND |
98 HOST_CTRL0_FORCESLEEP);
99
100 setbits_le32(&usb->usbphyctrl0,
101 /* Setting up the ref freq */
102 (CLK_24MHZ << 16) |
103 /* HOST Phy setting */
104 HOST_CTRL0_LINKSWRST |
105 HOST_CTRL0_UTMISWRST);
106 udelay(10);
107 clrbits_le32(&usb->usbphyctrl0,
108 HOST_CTRL0_LINKSWRST |
109 HOST_CTRL0_UTMISWRST);
110 udelay(20);
111
112 /* EHCI Ctrl setting */
113 setbits_le32(&usb->ehcictrl,
114 EHCICTRL_ENAINCRXALIGN |
115 EHCICTRL_ENAINCR4 |
116 EHCICTRL_ENAINCR8 |
117 EHCICTRL_ENAINCR16);
118}
119
120/* Reset the EHCI host controller. */
Rajeshwari Shinde7590d3c2012-05-21 16:38:03 +0530121static void reset_usb_phy(struct exynos_usb_phy *usb)
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +0530122{
123 /* HOST_PHY reset */
124 setbits_le32(&usb->usbphyctrl0,
125 HOST_CTRL0_PHYSWRST |
126 HOST_CTRL0_PHYSWRSTALL |
127 HOST_CTRL0_SIDDQ |
128 HOST_CTRL0_FORCESUSPEND |
129 HOST_CTRL0_FORCESLEEP);
Rajeshwari Shindec48ac112012-05-14 05:52:03 +0000130
131 set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_DISABLE);
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +0530132}
133
134/*
135 * EHCI-initialization
136 * Create the appropriate control structures to manage
137 * a new EHCI host controller.
138 */
Lucas Stach676ae062012-09-26 00:14:35 +0200139int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +0530140{
Vivek Gautam24a47752013-03-06 14:18:32 +0530141 struct exynos_ehci *ctx = &exynos;
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +0530142
Vivek Gautamc74b0112013-03-06 14:18:33 +0530143#ifdef CONFIG_OF_CONTROL
Vivek Gautam24a47752013-03-06 14:18:32 +0530144 if (exynos_usb_parse_dt(gd->fdt_blob, ctx)) {
145 debug("Unable to parse device tree for ehci-exynos\n");
146 return -ENODEV;
Rajeshwari Shindee18bf1f2013-01-07 23:35:03 +0000147 }
Vivek Gautamc74b0112013-03-06 14:18:33 +0530148#else
149 ctx->usb = (struct exynos_usb_phy *)samsung_get_base_usb_phy();
150 ctx->hcd = (struct ehci_hccr *)samsung_get_base_usb_ehci();
151#endif
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +0530152
Vivek Gautam24a47752013-03-06 14:18:32 +0530153 setup_usb_phy(ctx->usb);
Rajeshwari Shindee18bf1f2013-01-07 23:35:03 +0000154
Vivek Gautam24a47752013-03-06 14:18:32 +0530155 *hccr = ctx->hcd;
Lucas Stach676ae062012-09-26 00:14:35 +0200156 *hcor = (struct ehci_hcor *)((uint32_t) *hccr
157 + HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +0530158
159 debug("Exynos5-ehci: init hccr %x and hcor %x hc_length %d\n",
Lucas Stach676ae062012-09-26 00:14:35 +0200160 (uint32_t)*hccr, (uint32_t)*hcor,
161 (uint32_t)HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +0530162
163 return 0;
164}
165
166/*
167 * Destroy the appropriate control structures corresponding
168 * the EHCI host controller.
169 */
Lucas Stach676ae062012-09-26 00:14:35 +0200170int ehci_hcd_stop(int index)
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +0530171{
Vivek Gautam24a47752013-03-06 14:18:32 +0530172 struct exynos_ehci *ctx = &exynos;
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +0530173
Vivek Gautam24a47752013-03-06 14:18:32 +0530174 reset_usb_phy(ctx->usb);
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +0530175
176 return 0;
177}