Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Generic ULPI USB transceiver support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2009 Daniel Mack <daniel@caiaq.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Based on sources from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *   Sascha Hauer <s.hauer@pengutronix.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *   Freescale Semiconductors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/usb/otg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/usb/ulpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) struct ulpi_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	unsigned int	id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	char		*name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define ULPI_ID(vendor, product) (((vendor) << 16) | (product))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define ULPI_INFO(_id, _name)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	{				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 		.id	= (_id),	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		.name	= (_name),	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) /* ULPI hardcoded IDs, used for probing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) static struct ulpi_info ulpi_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	ULPI_INFO(ULPI_ID(0x04cc, 0x1504), "NXP ISP1504"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	ULPI_INFO(ULPI_ID(0x0424, 0x0006), "SMSC USB331x"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	ULPI_INFO(ULPI_ID(0x0424, 0x0007), "SMSC USB3320"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	ULPI_INFO(ULPI_ID(0x0424, 0x0009), "SMSC USB334x"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	ULPI_INFO(ULPI_ID(0x0451, 0x1507), "TI TUSB1210"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) static int ulpi_set_otg_flags(struct usb_phy *phy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	unsigned int flags = ULPI_OTG_CTRL_DP_PULLDOWN |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 			     ULPI_OTG_CTRL_DM_PULLDOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	if (phy->flags & ULPI_OTG_ID_PULLUP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		flags |= ULPI_OTG_CTRL_ID_PULLUP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	 * ULPI Specification rev.1.1 default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	 * for Dp/DmPulldown is enabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	if (phy->flags & ULPI_OTG_DP_PULLDOWN_DIS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		flags &= ~ULPI_OTG_CTRL_DP_PULLDOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	if (phy->flags & ULPI_OTG_DM_PULLDOWN_DIS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		flags &= ~ULPI_OTG_CTRL_DM_PULLDOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	if (phy->flags & ULPI_OTG_EXTVBUSIND)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		flags |= ULPI_OTG_CTRL_EXTVBUSIND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	return usb_phy_io_write(phy, flags, ULPI_OTG_CTRL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) static int ulpi_set_fc_flags(struct usb_phy *phy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	unsigned int flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	 * ULPI Specification rev.1.1 default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	 * for XcvrSelect is Full Speed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	if (phy->flags & ULPI_FC_HS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		flags |= ULPI_FUNC_CTRL_HIGH_SPEED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	else if (phy->flags & ULPI_FC_LS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		flags |= ULPI_FUNC_CTRL_LOW_SPEED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	else if (phy->flags & ULPI_FC_FS4LS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		flags |= ULPI_FUNC_CTRL_FS4LS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		flags |= ULPI_FUNC_CTRL_FULL_SPEED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	if (phy->flags & ULPI_FC_TERMSEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		flags |= ULPI_FUNC_CTRL_TERMSELECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	 * ULPI Specification rev.1.1 default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	 * for OpMode is Normal Operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (phy->flags & ULPI_FC_OP_NODRV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		flags |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	else if (phy->flags & ULPI_FC_OP_DIS_NRZI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		flags |= ULPI_FUNC_CTRL_OPMODE_DISABLE_NRZI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	else if (phy->flags & ULPI_FC_OP_NSYNC_NEOP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		flags |= ULPI_FUNC_CTRL_OPMODE_NOSYNC_NOEOP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		flags |= ULPI_FUNC_CTRL_OPMODE_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	 * ULPI Specification rev.1.1 default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	 * for SuspendM is Powered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	flags |= ULPI_FUNC_CTRL_SUSPENDM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	return usb_phy_io_write(phy, flags, ULPI_FUNC_CTRL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static int ulpi_set_ic_flags(struct usb_phy *phy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	unsigned int flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	if (phy->flags & ULPI_IC_AUTORESUME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		flags |= ULPI_IFC_CTRL_AUTORESUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (phy->flags & ULPI_IC_EXTVBUS_INDINV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		flags |= ULPI_IFC_CTRL_EXTERNAL_VBUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	if (phy->flags & ULPI_IC_IND_PASSTHRU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		flags |= ULPI_IFC_CTRL_PASSTHRU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	if (phy->flags & ULPI_IC_PROTECT_DIS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		flags |= ULPI_IFC_CTRL_PROTECT_IFC_DISABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	return usb_phy_io_write(phy, flags, ULPI_IFC_CTRL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static int ulpi_set_flags(struct usb_phy *phy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	ret = ulpi_set_otg_flags(phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	ret = ulpi_set_ic_flags(phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	return ulpi_set_fc_flags(phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static int ulpi_check_integrity(struct usb_phy *phy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	unsigned int val = 0x55;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	for (i = 0; i < 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		ret = usb_phy_io_write(phy, val, ULPI_SCRATCH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		ret = usb_phy_io_read(phy, ULPI_SCRATCH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		if (ret != val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			pr_err("ULPI integrity check: failed!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		val = val << 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	pr_info("ULPI integrity check: passed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) static int ulpi_init(struct usb_phy *phy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	int i, vid, pid, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	u32 ulpi_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	for (i = 0; i < 4; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		ret = usb_phy_io_read(phy, ULPI_PRODUCT_ID_HIGH - i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		ulpi_id = (ulpi_id << 8) | ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	vid = ulpi_id & 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	pid = ulpi_id >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	pr_info("ULPI transceiver vendor/product ID 0x%04x/0x%04x\n", vid, pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	for (i = 0; i < ARRAY_SIZE(ulpi_ids); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		if (ulpi_ids[i].id == ULPI_ID(vid, pid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 			pr_info("Found %s ULPI transceiver.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 				ulpi_ids[i].name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	ret = ulpi_check_integrity(phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	return ulpi_set_flags(phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) static int ulpi_set_host(struct usb_otg *otg, struct usb_bus *host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	struct usb_phy *phy = otg->usb_phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	unsigned int flags = usb_phy_io_read(phy, ULPI_IFC_CTRL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	if (!host) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		otg->host = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	otg->host = host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	flags &= ~(ULPI_IFC_CTRL_6_PIN_SERIAL_MODE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		   ULPI_IFC_CTRL_3_PIN_SERIAL_MODE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		   ULPI_IFC_CTRL_CARKITMODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	if (phy->flags & ULPI_IC_6PIN_SERIAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		flags |= ULPI_IFC_CTRL_6_PIN_SERIAL_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	else if (phy->flags & ULPI_IC_3PIN_SERIAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		flags |= ULPI_IFC_CTRL_3_PIN_SERIAL_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	else if (phy->flags & ULPI_IC_CARKIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		flags |= ULPI_IFC_CTRL_CARKITMODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	return usb_phy_io_write(phy, flags, ULPI_IFC_CTRL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) static int ulpi_set_vbus(struct usb_otg *otg, bool on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	struct usb_phy *phy = otg->usb_phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	unsigned int flags = usb_phy_io_read(phy, ULPI_OTG_CTRL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	flags &= ~(ULPI_OTG_CTRL_DRVVBUS | ULPI_OTG_CTRL_DRVVBUS_EXT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	if (on) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		if (phy->flags & ULPI_OTG_DRVVBUS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			flags |= ULPI_OTG_CTRL_DRVVBUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		if (phy->flags & ULPI_OTG_DRVVBUS_EXT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			flags |= ULPI_OTG_CTRL_DRVVBUS_EXT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	return usb_phy_io_write(phy, flags, ULPI_OTG_CTRL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) static void otg_ulpi_init(struct usb_phy *phy, struct usb_otg *otg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 			  struct usb_phy_io_ops *ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 			  unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	phy->label	= "ULPI";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	phy->flags	= flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	phy->io_ops	= ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	phy->otg	= otg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	phy->init	= ulpi_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	otg->usb_phy	= phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	otg->set_host	= ulpi_set_host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	otg->set_vbus	= ulpi_set_vbus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) struct usb_phy *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) otg_ulpi_create(struct usb_phy_io_ops *ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	struct usb_phy *phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	struct usb_otg *otg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	phy = kzalloc(sizeof(*phy), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	if (!phy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	otg = kzalloc(sizeof(*otg), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	if (!otg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		kfree(phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	otg_ulpi_init(phy, otg, ops, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	return phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) EXPORT_SYMBOL_GPL(otg_ulpi_create);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) struct usb_phy *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) devm_otg_ulpi_create(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		     struct usb_phy_io_ops *ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		     unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	struct usb_phy *phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	struct usb_otg *otg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	if (!phy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	otg = devm_kzalloc(dev, sizeof(*otg), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	if (!otg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		devm_kfree(dev, phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	otg_ulpi_init(phy, otg, ops, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	return phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) EXPORT_SYMBOL_GPL(devm_otg_ulpi_create);