2 * Copyright (c) 2009 Wind River Systems, Inc.
3 * Tom Rix <Tom.Rix@windriver.com>
5 * This is file is based on
6 * repository git.gitorious.org/u-boot-omap3/mainline.git,
7 * branch omap3-dev-usb, file drivers/usb/gadget/twl4030_usb.c
9 * This is the unique part of its copyright :
11 * ------------------------------------------------------------------------
13 * * (C) Copyright 2009 Atin Malaviya (atin.malaviya@gmail.com)
15 * Based on: twl4030_usb.c in linux 2.6 (drivers/i2c/chips/twl4030_usb.c)
16 * Copyright (C) 2004-2007 Texas Instruments
17 * Copyright (C) 2008 Nokia Corporation
18 * Contact: Felipe Balbi <felipe.balbi@nokia.com>
20 * Author: Atin Malaviya (atin.malaviya@gmail.com)
22 * ------------------------------------------------------------------------
24 * SPDX-License-Identifier: GPL-2.0+
29 /* Defines for bits in registers */
30 #define OPMODE_MASK (3 << 3)
31 #define XCVRSELECT_MASK (3 << 0)
32 #define CARKITMODE (1 << 2)
33 #define OTG_ENAB (1 << 5)
34 #define PHYPWD (1 << 0)
35 #define CLOCKGATING_EN (1 << 2)
36 #define CLK32K_EN (1 << 1)
37 #define REQ_PHY_DPLL_CLK (1 << 0)
38 #define PHY_DPLL_CLK (1 << 0)
40 static int twl4030_usb_write(u8 address
, u8 data
)
44 ret
= twl4030_i2c_write_u8(TWL4030_CHIP_USB
, address
, data
);
46 printf("TWL4030:USB:Write[0x%x] Error %d\n", address
, ret
);
51 static int twl4030_usb_read(u8 address
)
56 ret
= twl4030_i2c_read_u8(TWL4030_CHIP_USB
, address
, &data
);
60 printf("TWL4030:USB:Read[0x%x] Error %d\n", address
, ret
);
65 static void twl4030_usb_ldo_init(void)
67 /* Enable writing to power configuration registers */
68 twl4030_i2c_write_u8(TWL4030_CHIP_PM_MASTER
,
69 TWL4030_PM_MASTER_PROTECT_KEY
, 0xC0);
70 twl4030_i2c_write_u8(TWL4030_CHIP_PM_MASTER
,
71 TWL4030_PM_MASTER_PROTECT_KEY
, 0x0C);
73 /* put VUSB3V1 LDO in active state */
74 twl4030_i2c_write_u8(TWL4030_CHIP_PM_RECEIVER
,
75 TWL4030_PM_RECEIVER_VUSB_DEDICATED2
, 0x00);
77 /* input to VUSB3V1 LDO is from VBAT, not VBUS */
78 twl4030_i2c_write_u8(TWL4030_CHIP_PM_RECEIVER
,
79 TWL4030_PM_RECEIVER_VUSB_DEDICATED1
, 0x14);
81 /* turn on 3.1V regulator */
82 twl4030_i2c_write_u8(TWL4030_CHIP_PM_RECEIVER
,
83 TWL4030_PM_RECEIVER_VUSB3V1_DEV_GRP
, 0x20);
84 twl4030_i2c_write_u8(TWL4030_CHIP_PM_RECEIVER
,
85 TWL4030_PM_RECEIVER_VUSB3V1_TYPE
, 0x00);
87 /* turn on 1.5V regulator */
88 twl4030_i2c_write_u8(TWL4030_CHIP_PM_RECEIVER
,
89 TWL4030_PM_RECEIVER_VUSB1V5_DEV_GRP
, 0x20);
90 twl4030_i2c_write_u8(TWL4030_CHIP_PM_RECEIVER
,
91 TWL4030_PM_RECEIVER_VUSB1V5_TYPE
, 0x00);
93 /* turn on 1.8V regulator */
94 twl4030_i2c_write_u8(TWL4030_CHIP_PM_RECEIVER
,
95 TWL4030_PM_RECEIVER_VUSB1V8_DEV_GRP
, 0x20);
96 twl4030_i2c_write_u8(TWL4030_CHIP_PM_RECEIVER
,
97 TWL4030_PM_RECEIVER_VUSB1V8_TYPE
, 0x00);
99 /* disable access to power configuration registers */
100 twl4030_i2c_write_u8(TWL4030_CHIP_PM_MASTER
,
101 TWL4030_PM_MASTER_PROTECT_KEY
, 0x00);
104 static void twl4030_phy_power(void)
109 pwr
= twl4030_usb_read(TWL4030_USB_PHY_PWR_CTRL
);
111 twl4030_usb_write(TWL4030_USB_PHY_PWR_CTRL
, pwr
);
113 clk
= twl4030_usb_read(TWL4030_USB_PHY_CLK_CTRL
);
114 clk
|= CLOCKGATING_EN
| CLK32K_EN
;
115 twl4030_usb_write(TWL4030_USB_PHY_CLK_CTRL
, clk
);
119 * Initiaze the ULPI interface
120 * ULPI : Universal Transceiver Macrocell Low Pin Interface
121 * An interface between the USB link controller like musb and the
122 * the PHY or transceiver that drives the actual bus.
124 int twl4030_usb_ulpi_init(void)
126 long timeout
= 1000 * 1000; /* 1 sec */;
129 /* twl4030 ldo init */
130 twl4030_usb_ldo_init();
132 /* Enable the twl4030 phy */
135 /* Enable DPLL to access PHY registers over I2C */
136 clk
= twl4030_usb_read(TWL4030_USB_PHY_CLK_CTRL
);
137 clk
|= REQ_PHY_DPLL_CLK
;
138 twl4030_usb_write(TWL4030_USB_PHY_CLK_CTRL
, clk
);
140 /* Check if the PHY DPLL is locked */
141 sts
= twl4030_usb_read(TWL4030_USB_PHY_CLK_CTRL_STS
);
142 while (!(sts
& PHY_DPLL_CLK
) && 0 < timeout
) {
144 sts
= twl4030_usb_read(TWL4030_USB_PHY_CLK_CTRL_STS
);
149 sts
= twl4030_usb_read(TWL4030_USB_PHY_CLK_CTRL_STS
);
150 if (!(sts
& PHY_DPLL_CLK
)) {
151 printf("Error:TWL4030:USB Timeout setting PHY DPLL clock\n");
156 * There are two circuit blocks attached to the PHY,
157 * Carkit and USB OTG. Disable Carkit and enable USB OTG
159 twl4030_usb_write(TWL4030_USB_IFC_CTRL_CLR
, CARKITMODE
);
160 pwr
= twl4030_usb_read(TWL4030_USB_POWER_CTRL
);
162 twl4030_usb_write(TWL4030_USB_POWER_CTRL_SET
, pwr
);
164 /* Clear the opmode bits to ensure normal encode */
165 twl4030_usb_write(TWL4030_USB_FUNC_CTRL_CLR
, OPMODE_MASK
);
167 /* Clear the xcvrselect bits to enable the high speed transeiver */
168 twl4030_usb_write(TWL4030_USB_FUNC_CTRL_CLR
, XCVRSELECT_MASK
);
170 /* Let ULPI control the DPLL clock */
171 clk
= twl4030_usb_read(TWL4030_USB_PHY_CLK_CTRL
);
172 clk
&= ~REQ_PHY_DPLL_CLK
;
173 twl4030_usb_write(TWL4030_USB_PHY_CLK_CTRL
, clk
);