Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: misc: usb3503: refactor code to prepare for usb3803 addition

Refactor code to simplify adding support for USB3803 and bypass mode.

Remove static usb3503_reset() and move it to usb3503_switch_mode(),
with the addition of the bypass mode we need to drive the various
control signals to the expected configuration, not just to
assert/release the reset.

In addition to that the usb3503_connect() needs to be called only
for HUB mode.

No functional changes expected nor intended because of this change.

Signed-off-by: Emanuele Ghidoli <emanuele.ghidoli@toradex.com>
Signed-off-by: Francesco Dolcini <francesco.dolcini@toradex.com>
Link: https://lore.kernel.org/r/20230313165039.255579-3-francesco@dolcini.it
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Emanuele Ghidoli and committed by
Greg Kroah-Hartman
b04b32cd 1239e812

+19 -25
+19 -25
drivers/usb/misc/usb3503.c
··· 52 52 bool secondary_ref_clk; 53 53 }; 54 54 55 - static int usb3503_reset(struct usb3503 *hub, int state) 56 - { 57 - if (!state && hub->connect) 58 - gpiod_set_value_cansleep(hub->connect, 0); 59 - 60 - if (hub->reset) 61 - gpiod_set_value_cansleep(hub->reset, !state); 62 - 63 - /* Wait T_HUBINIT == 4ms for hub logic to stabilize */ 64 - if (state) 65 - usleep_range(4000, 10000); 66 - 67 - return 0; 68 - } 69 - 70 55 static int usb3503_connect(struct usb3503 *hub) 71 56 { 72 57 struct device *dev = hub->dev; 73 58 int err; 74 - 75 - usb3503_reset(hub, 1); 76 59 77 60 if (hub->regmap) { 78 61 /* SP_ILOCK: set connect_n, config_n for config */ ··· 109 126 static int usb3503_switch_mode(struct usb3503 *hub, enum usb3503_mode mode) 110 127 { 111 128 struct device *dev = hub->dev; 112 - int err = 0; 129 + int rst, conn; 113 130 114 131 switch (mode) { 115 132 case USB3503_MODE_HUB: 116 - err = usb3503_connect(hub); 133 + conn = 1; 134 + rst = 0; 117 135 break; 118 - 119 136 case USB3503_MODE_STANDBY: 120 - usb3503_reset(hub, 0); 137 + conn = 0; 138 + rst = 1; 121 139 dev_info(dev, "switched to STANDBY mode\n"); 122 140 break; 123 - 124 141 default: 125 142 dev_err(dev, "unknown mode is requested\n"); 126 - err = -EINVAL; 127 - break; 143 + return -EINVAL; 128 144 } 129 145 130 - return err; 146 + if (!conn && hub->connect) 147 + gpiod_set_value_cansleep(hub->connect, 0); 148 + 149 + if (hub->reset) 150 + gpiod_set_value_cansleep(hub->reset, rst); 151 + 152 + if (conn) { 153 + /* Wait T_HUBINIT == 4ms for hub logic to stabilize */ 154 + usleep_range(4000, 10000); 155 + return usb3503_connect(hub); 156 + } 157 + 158 + return 0; 131 159 } 132 160 133 161 static const struct regmap_config usb3503_regmap_config = {