usb: misc: nb7vpq904m: default gpio operation for orientaion

There is possible crash when phy driver which control the same pin,
1. redriver driver read gpio state and start release state,
2. phy driver start request another state,
3. redriver driver finish release state, clear module owner,
4. phy driver string compare of module owner which is NULL to crash,
prepare to fix it by provide orientaion for USB module.

Change-Id: I177691abd702bac4f388fbbc0c375e19008f5adb
Signed-off-by: Linyu Yuan <linyyuan@codeaurora.org>
This commit is contained in:
Linyu Yuan 2020-12-09 15:00:39 +08:00 • committed by Gerrit - the friendly Code Review server
commit eba0b1fc29

View file

@ -85,7 +85,6 @@ struct ssusb_redriver {
struct i2c_client *client;
int orientation_gpio;
bool orientation_gpio_enable;
enum plug_orientation typec_orientation;
enum operation_mode op_mode;
@ -403,40 +402,15 @@ err:
static int ssusb_redriver_read_orientation(struct ssusb_redriver *redriver)
{
struct device *dev = redriver->dev;
struct pinctrl *orientation_pinctrl;
struct pinctrl_state *gpio_state;
int ret;
if (!redriver->orientation_gpio_enable)
if (!gpio_is_valid(redriver->orientation_gpio))
return -EINVAL;
orientation_pinctrl = pinctrl_get(dev);
if (IS_ERR_OR_NULL(orientation_pinctrl)) {
dev_err(dev, "Failed to get pinctrl\n");
return -EINVAL;
}
gpio_state = pinctrl_lookup_state(orientation_pinctrl, "enable_gpio");
if (IS_ERR_OR_NULL(gpio_state)) {
dev_err(dev, "Failed to get gpio state\n");
ret = -ENODEV;
goto put_pinctrl;
}
ret = pinctrl_select_state(orientation_pinctrl, gpio_state);
if (ret) {
dev_err(redriver->dev, "fail to enable gpio state\n");
ret = -EINVAL;
goto put_pinctrl;
}
/* wait for some time ??? */
ret = gpio_get_value(redriver->orientation_gpio);
if (ret < 0) {
dev_err(redriver->dev, "fail to read gpio value\n");
ret = -EINVAL;
goto put_pinctrl;
return -EINVAL;
}
if (ret == 0)
@ -444,12 +418,7 @@ static int ssusb_redriver_read_orientation(struct ssusb_redriver *redriver)
else
redriver->typec_orientation = ORIENTATION_CC2;
ret = 0;
put_pinctrl:
pinctrl_put(orientation_pinctrl);
return ret;
return 0;
}
static int ssusb_redriver_ucsi_notifier(struct notifier_block *nb,
@ -669,9 +638,8 @@ static void ssusb_redriver_orientation_gpio_init(
struct device *dev = redriver->dev;
int rc;
redriver->orientation_gpio =
of_get_named_gpio(dev->of_node, "orientation_gpio", 0);
if (redriver->orientation_gpio < 0) {
redriver->orientation_gpio = of_get_gpio(dev->of_node, 0);
if (!gpio_is_valid(redriver->orientation_gpio)) {
dev_err(dev, "Failed to get gpio\n");
return;
}
@ -679,10 +647,9 @@ static void ssusb_redriver_orientation_gpio_init(
rc = devm_gpio_request(dev, redriver->orientation_gpio, "redriver");
if (rc < 0) {
dev_err(dev, "Failed to request gpio\n");
redriver->orientation_gpio = -EINVAL;
return;
}
redriver->orientation_gpio_enable = true;
}
static const struct regmap_config redriver_regmap = {