27 #include <linux/module.h>
41 #include <linux/slab.h>
45 #define MCPC_CTRL 0x30
46 #define MCPC_CTRL_RTSOL (1 << 7)
47 #define MCPC_CTRL_EXTSWR (1 << 6)
48 #define MCPC_CTRL_EXTSWC (1 << 5)
49 #define MCPC_CTRL_VOICESW (1 << 4)
50 #define MCPC_CTRL_OUT64K (1 << 3)
51 #define MCPC_CTRL_RTSCTSSW (1 << 2)
52 #define MCPC_CTRL_HS_UART (1 << 0)
54 #define MCPC_IO_CTRL 0x33
55 #define MCPC_IO_CTRL_MICBIASEN (1 << 5)
56 #define MCPC_IO_CTRL_CTS_NPU (1 << 4)
57 #define MCPC_IO_CTRL_RXD_PU (1 << 3)
58 #define MCPC_IO_CTRL_TXDTYP (1 << 2)
59 #define MCPC_IO_CTRL_CTSTYP (1 << 1)
60 #define MCPC_IO_CTRL_RTSTYP (1 << 0)
62 #define MCPC_CTRL2 0x36
63 #define MCPC_CTRL2_MCPC_CK_EN (1 << 0)
65 #define OTHER_FUNC_CTRL 0x80
66 #define OTHER_FUNC_CTRL_BDIS_ACON_EN (1 << 4)
67 #define OTHER_FUNC_CTRL_FIVEWIRE_MODE (1 << 2)
69 #define OTHER_IFC_CTRL 0x83
70 #define OTHER_IFC_CTRL_OE_INT_EN (1 << 6)
71 #define OTHER_IFC_CTRL_CEA2011_MODE (1 << 5)
72 #define OTHER_IFC_CTRL_FSLSSERIALMODE_4PIN (1 << 4)
73 #define OTHER_IFC_CTRL_HIZ_ULPI_60MHZ_OUT (1 << 3)
74 #define OTHER_IFC_CTRL_HIZ_ULPI (1 << 2)
75 #define OTHER_IFC_CTRL_ALT_INT_REROUTE (1 << 0)
77 #define OTHER_INT_EN_RISE 0x86
78 #define OTHER_INT_EN_FALL 0x89
79 #define OTHER_INT_STS 0x8C
80 #define OTHER_INT_LATCH 0x8D
81 #define OTHER_INT_VB_SESS_VLD (1 << 7)
82 #define OTHER_INT_DM_HI (1 << 6)
83 #define OTHER_INT_DP_HI (1 << 5)
84 #define OTHER_INT_BDIS_ACON (1 << 3)
85 #define OTHER_INT_MANU (1 << 1)
86 #define OTHER_INT_ABNORMAL_STRESS (1 << 0)
88 #define ID_STATUS 0x96
89 #define ID_RES_FLOAT (1 << 4)
90 #define ID_RES_440K (1 << 3)
91 #define ID_RES_200K (1 << 2)
92 #define ID_RES_102K (1 << 1)
93 #define ID_RES_GND (1 << 0)
95 #define POWER_CTRL 0xAC
96 #define POWER_CTRL_OTG_ENAB (1 << 5)
98 #define OTHER_IFC_CTRL2 0xAF
99 #define OTHER_IFC_CTRL2_ULPI_STP_LOW (1 << 4)
100 #define OTHER_IFC_CTRL2_ULPI_TXEN_POL (1 << 3)
101 #define OTHER_IFC_CTRL2_ULPI_4PIN_2430 (1 << 2)
102 #define OTHER_IFC_CTRL2_USB_INT_OUTSEL_MASK (3 << 0)
103 #define OTHER_IFC_CTRL2_USB_INT_OUTSEL_INT1N (0 << 0)
104 #define OTHER_IFC_CTRL2_USB_INT_OUTSEL_INT2N (1 << 0)
106 #define REG_CTRL_EN 0xB2
107 #define REG_CTRL_ERROR 0xB5
108 #define ULPI_I2C_CONFLICT_INTEN (1 << 0)
110 #define OTHER_FUNC_CTRL2 0xB8
111 #define OTHER_FUNC_CTRL2_VBAT_TIMER_EN (1 << 0)
114 #define VBUS_DEBOUNCE 0xC0
115 #define ID_DEBOUNCE 0xC1
116 #define VBAT_TIMER 0xD3
117 #define PHY_PWR_CTRL 0xFD
118 #define PHY_PWR_PHYPWD (1 << 0)
119 #define PHY_CLK_CTRL 0xFE
120 #define PHY_CLK_CTRL_CLOCKGATING_EN (1 << 2)
121 #define PHY_CLK_CTRL_CLK32K_EN (1 << 1)
122 #define REQ_PHY_DPLL_CLK (1 << 0)
123 #define PHY_CLK_CTRL_STS 0xFF
124 #define PHY_DPLL_CLK (1 << 0)
127 #define STS_HW_CONDITIONS 0x0F
130 #define VUSB_DEDICATED1 0x7D
131 #define VUSB_DEDICATED2 0x7E
132 #define VUSB1V5_DEV_GRP 0x71
133 #define VUSB1V5_TYPE 0x72
134 #define VUSB1V5_REMAP 0x73
135 #define VUSB1V8_DEV_GRP 0x74
136 #define VUSB1V8_TYPE 0x75
137 #define VUSB1V8_REMAP 0x76
138 #define VUSB3V1_DEV_GRP 0x77
139 #define VUSB3V1_TYPE 0x78
140 #define VUSB3V1_REMAP 0x79
144 #define GPIO_USB_4PIN_ULPI_2430C (3 << 0)
169 #define phy_to_twl(x) container_of((x), struct twl4030_usb, phy)
173 static int twl4030_i2c_write_u8_verify(
struct twl4030_usb *twl,
182 dev_dbg(twl->
dev,
"Write%d[%d,0x%x] wrote %02x but read %02x\n",
183 1, module, address, check, data);
190 dev_dbg(twl->
dev,
"Write%d[%d,0x%x] wrote %02x but read %02x\n",
191 2, module, address, check, data);
197 #define twl4030_usb_write_verify(twl, address, data) \
198 twl4030_i2c_write_u8_verify(twl, TWL4030_MODULE_USB, (data), (address))
200 static inline int twl4030_usb_write(
struct twl4030_usb *twl,
208 "TWL4030:USB:Write[0x%x] Error %d\n", address, ret);
222 "TWL4030:readb[0x%x,0x%x] Error %d\n",
223 module, address, ret);
228 static inline int twl4030_usb_read(
struct twl4030_usb *twl,
u8 address)
238 return twl4030_usb_write(twl,
ULPI_SET(reg), bits);
244 return twl4030_usb_write(twl,
ULPI_CLR(reg), bits);
270 dev_err(twl->
dev,
"USB link status err %d\n", status);
271 else if (status & (
BIT(7) |
BIT(2))) {
272 if (status & (
BIT(7)))
284 dev_dbg(twl->
dev,
"HW_CONDITIONS 0x%02x/%d; link %d\n",
285 status, status, linkstat);
291 spin_lock_irq(&twl->
lock);
293 spin_unlock_irq(&twl->
lock);
315 dev_err(twl->
dev,
"unsupported T2 transceiver mode %d\n",
321 static void twl4030_i2c_access(
struct twl4030_usb *twl,
int on)
351 static void __twl4030_phy_power(
struct twl4030_usb *twl,
int on)
363 static void twl4030_phy_power(
struct twl4030_usb *twl,
int on)
378 __twl4030_phy_power(twl, 1);
384 __twl4030_phy_power(twl, 0);
391 static void twl4030_phy_suspend(
struct twl4030_usb *twl,
int controller_off)
396 twl4030_phy_power(twl, 0);
401 static void __twl4030_phy_resume(
struct twl4030_usb *twl)
403 twl4030_phy_power(twl, 1);
404 twl4030_i2c_access(twl, 1);
405 twl4030_usb_set_mode(twl, twl->
usb_mode);
407 twl4030_i2c_access(twl, 0);
410 static void twl4030_phy_resume(
struct twl4030_usb *twl)
414 __twl4030_phy_resume(twl);
419 static int twl4030_usb_ldo_init(
struct twl4030_usb *twl)
488 spin_unlock_irqrestore(&twl->
lock, flags);
499 status = twl4030_usb_linkstat(twl);
514 twl4030_phy_suspend(twl, 0);
516 twl4030_phy_resume(twl);
525 static void twl4030_usb_phy_init(
struct twl4030_usb *twl)
529 status = twl4030_usb_linkstat(twl);
533 __twl4030_phy_power(twl, 0);
536 __twl4030_phy_resume(twl);
550 twl4030_phy_suspend(twl, 1);
552 twl4030_phy_resume(twl);
557 static int twl4030_set_peripheral(
struct usb_otg *otg,
570 static int twl4030_set_host(
struct usb_otg *otg,
struct usb_bus *
host)
595 of_property_read_u32(np,
"usb_mode",
600 dev_err(&pdev->
dev,
"twl4030 initialized without pdata\n");
615 twl->
phy.label =
"twl4030";
617 twl->
phy.set_suspend = twl4030_set_suspend;
626 err = twl4030_usb_ldo_init(twl);
633 platform_set_drvdata(pdev, twl);
635 dev_warn(&pdev->
dev,
"could not create sysfs file\n");
650 dev_dbg(&pdev->
dev,
"can't get IRQ %d, err %d\n",
658 twl4030_usb_phy_init(twl);
660 dev_info(&pdev->
dev,
"Initialized TWL4030 USB module\n");
666 struct twl4030_usb *twl = platform_get_drvdata(pdev);
673 twl4030_usb_set_mode(twl, -1);
690 twl4030_phy_power(twl, 0);
699 static const struct of_device_id twl4030_usb_id_table[] = {
707 .probe = twl4030_usb_probe,
708 .remove =
__exit_p(twl4030_usb_remove),
710 .name =
"twl4030_usb",
716 static int __init twl4030_usb_init(
void)
722 static void __exit twl4030_usb_exit(
void)