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>
This commit is contained in:
parent
1239e81247
commit
b04b32cd67
@ -52,28 +52,11 @@ struct usb3503 {
|
|||||||
bool secondary_ref_clk;
|
bool secondary_ref_clk;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int usb3503_reset(struct usb3503 *hub, int state)
|
|
||||||
{
|
|
||||||
if (!state && hub->connect)
|
|
||||||
gpiod_set_value_cansleep(hub->connect, 0);
|
|
||||||
|
|
||||||
if (hub->reset)
|
|
||||||
gpiod_set_value_cansleep(hub->reset, !state);
|
|
||||||
|
|
||||||
/* Wait T_HUBINIT == 4ms for hub logic to stabilize */
|
|
||||||
if (state)
|
|
||||||
usleep_range(4000, 10000);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int usb3503_connect(struct usb3503 *hub)
|
static int usb3503_connect(struct usb3503 *hub)
|
||||||
{
|
{
|
||||||
struct device *dev = hub->dev;
|
struct device *dev = hub->dev;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
usb3503_reset(hub, 1);
|
|
||||||
|
|
||||||
if (hub->regmap) {
|
if (hub->regmap) {
|
||||||
/* SP_ILOCK: set connect_n, config_n for config */
|
/* SP_ILOCK: set connect_n, config_n for config */
|
||||||
err = regmap_write(hub->regmap, USB3503_SP_ILOCK,
|
err = regmap_write(hub->regmap, USB3503_SP_ILOCK,
|
||||||
@ -126,25 +109,36 @@ static int usb3503_connect(struct usb3503 *hub)
|
|||||||
static int usb3503_switch_mode(struct usb3503 *hub, enum usb3503_mode mode)
|
static int usb3503_switch_mode(struct usb3503 *hub, enum usb3503_mode mode)
|
||||||
{
|
{
|
||||||
struct device *dev = hub->dev;
|
struct device *dev = hub->dev;
|
||||||
int err = 0;
|
int rst, conn;
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case USB3503_MODE_HUB:
|
case USB3503_MODE_HUB:
|
||||||
err = usb3503_connect(hub);
|
conn = 1;
|
||||||
|
rst = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB3503_MODE_STANDBY:
|
case USB3503_MODE_STANDBY:
|
||||||
usb3503_reset(hub, 0);
|
conn = 0;
|
||||||
|
rst = 1;
|
||||||
dev_info(dev, "switched to STANDBY mode\n");
|
dev_info(dev, "switched to STANDBY mode\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
dev_err(dev, "unknown mode is requested\n");
|
dev_err(dev, "unknown mode is requested\n");
|
||||||
err = -EINVAL;
|
return -EINVAL;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
if (!conn && hub->connect)
|
||||||
|
gpiod_set_value_cansleep(hub->connect, 0);
|
||||||
|
|
||||||
|
if (hub->reset)
|
||||||
|
gpiod_set_value_cansleep(hub->reset, rst);
|
||||||
|
|
||||||
|
if (conn) {
|
||||||
|
/* Wait T_HUBINIT == 4ms for hub logic to stabilize */
|
||||||
|
usleep_range(4000, 10000);
|
||||||
|
return usb3503_connect(hub);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct regmap_config usb3503_regmap_config = {
|
static const struct regmap_config usb3503_regmap_config = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user