From: hdegoede@redhat.com (Hans de Goede)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 3/7] phy-sun4i-usb: Simplify missing dr_mode handling
Date: Mon, 15 Aug 2016 21:21:28 +0200 [thread overview]
Message-ID: <1471288892-21702-4-git-send-email-hdegoede@redhat.com> (raw)
In-Reply-To: <1471288892-21702-1-git-send-email-hdegoede@redhat.com>
If we cannot get dr_mode or no id gpio is specified simply assume
peripheral mode, as this is always safe.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
Changes in v2:
-Keep sun4i_usb_phy0_get_id_det() logic as is rather then re-ordering
the switch-case
---
drivers/phy/phy-sun4i-usb.c | 42 ++++++++++++++----------------------------
1 file changed, 14 insertions(+), 28 deletions(-)
diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
index 02cb65e..fb2d4f3 100644
--- a/drivers/phy/phy-sun4i-usb.c
+++ b/drivers/phy/phy-sun4i-usb.c
@@ -124,7 +124,6 @@ struct sun4i_usb_phy_data {
bool regulator_on;
int index;
} phys[MAX_PHYS];
- int first_phy;
/* phy0 / otg related variables */
struct extcon_dev *extcon;
bool phy0_init;
@@ -326,7 +325,10 @@ static int sun4i_usb_phy0_get_id_det(struct sun4i_usb_phy_data *data)
{
switch (data->dr_mode) {
case USB_DR_MODE_OTG:
- return gpiod_get_value_cansleep(data->id_det_gpio);
+ if (data->id_det_gpio)
+ return gpiod_get_value_cansleep(data->id_det_gpio);
+ else
+ return 1; /* Fallback to peripheral mode */
case USB_DR_MODE_HOST:
return 0;
case USB_DR_MODE_PERIPHERAL:
@@ -539,8 +541,7 @@ static struct phy *sun4i_usb_phy_xlate(struct device *dev,
{
struct sun4i_usb_phy_data *data = dev_get_drvdata(dev);
- if (args->args[0] < data->first_phy ||
- args->args[0] >= data->cfg->num_phys)
+ if (args->args[0] >= data->cfg->num_phys)
return ERR_PTR(-ENODEV);
return data->phys[args->args[0]].phy;
@@ -615,33 +616,18 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
}
data->dr_mode = of_usb_get_dr_mode_by_phy(np, 0);
- switch (data->dr_mode) {
- case USB_DR_MODE_OTG:
- /* otg without id_det makes no sense, and is not supported */
- if (!data->id_det_gpio) {
- dev_err(dev, "usb0_id_det missing or invalid\n");
- return -ENODEV;
- }
- /* fall through */
- case USB_DR_MODE_HOST:
- case USB_DR_MODE_PERIPHERAL:
- data->extcon = devm_extcon_dev_allocate(dev,
- sun4i_usb_phy0_cable);
- if (IS_ERR(data->extcon))
- return PTR_ERR(data->extcon);
- ret = devm_extcon_dev_register(dev, data->extcon);
- if (ret) {
- dev_err(dev, "failed to register extcon: %d\n", ret);
- return ret;
- }
- break;
- default:
- dev_info(dev, "dr_mode unknown, not registering usb phy0\n");
- data->first_phy = 1;
+ data->extcon = devm_extcon_dev_allocate(dev, sun4i_usb_phy0_cable);
+ if (IS_ERR(data->extcon))
+ return PTR_ERR(data->extcon);
+
+ ret = devm_extcon_dev_register(dev, data->extcon);
+ if (ret) {
+ dev_err(dev, "failed to register extcon: %d\n", ret);
+ return ret;
}
- for (i = data->first_phy; i < data->cfg->num_phys; i++) {
+ for (i = 0; i < data->cfg->num_phys; i++) {
struct sun4i_usb_phy *phy = data->phys + i;
char name[16];
--
2.7.4
next prev parent reply other threads:[~2016-08-15 19:21 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-15 19:21 [PATCH v2 0/7] musb: sunxi: Add support for run-time changing dr-mode through sysfs Hans de Goede
2016-08-15 19:21 ` [PATCH v2 1/7] phy-sun4i-usb: Use bool where appropriate Hans de Goede
2016-08-15 19:21 ` [PATCH v2 2/7] phy-sun4i-usb: Refactor forced session ending Hans de Goede
2016-08-15 19:21 ` Hans de Goede [this message]
2016-08-15 19:21 ` [PATCH v2 4/7] phy-sun4i-usb: Add support for phy_set_mode Hans de Goede
2016-08-16 13:48 ` Sergei Shtylyov
2016-08-16 20:01 ` Hans de Goede
2016-08-18 7:40 ` Felipe Balbi
2016-08-18 9:05 ` Hans de Goede
2016-08-18 10:17 ` Felipe Balbi
2016-08-19 13:27 ` Kishon Vijay Abraham I
2016-08-15 19:21 ` [PATCH v2 5/7] phy-sun4i-usb: Warn when external vbus is detected Hans de Goede
2016-08-15 19:21 ` [PATCH v2 6/7] phy-sun4i-usb: Add "allwinner, usb0-usb-a-connector" dt property Hans de Goede
2016-08-19 21:33 ` [PATCH v2 6/7] phy-sun4i-usb: Add "allwinner,usb0-usb-a-connector" " Bin Liu
2016-08-15 19:21 ` [PATCH v2 7/7] musb: sunxi: Add support for platform_set_mode Hans de Goede
2016-08-19 21:30 ` Bin Liu
2016-08-21 10:10 ` Hans de Goede
2016-08-22 14:11 ` Bin Liu
2016-08-22 15:08 ` Hans de Goede
2016-08-22 15:24 ` Bin Liu
2016-08-22 15:32 ` Hans de Goede
2016-08-22 15:38 ` Bin Liu
2016-08-22 15:55 ` Hans de Goede
2016-08-22 16:10 ` Bin Liu
2016-08-25 17:59 ` Hans de Goede
2016-08-19 21:25 ` [PATCH v2 0/7] musb: sunxi: Add support for run-time changing dr-mode through sysfs Bin Liu
2016-08-21 9:29 ` Hans de Goede
2016-08-22 14:08 ` Bin Liu
2016-08-22 14:16 ` Bin Liu
2016-08-22 15:50 ` Hans de Goede
2016-08-22 16:03 ` Bin Liu
2016-08-22 19:16 ` Rask Ingemann Lambertsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1471288892-21702-4-git-send-email-hdegoede@redhat.com \
--to=hdegoede@redhat.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).