linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Hans de Goede <hdegoede@redhat.com>
Cc: Darren Hart <dvhart@infradead.org>,
	Andy Shevchenko <andy@infradead.org>,
	MyungJoo Ham <myungjoo.ham@samsung.com>,
	Chanwoo Choi <cw00.choi@samsung.com>,
	Mathias Nyman <mathias.nyman@intel.com>,
	Heikki Krogerus <heikki.krogerus@linux.intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Platform Driver <platform-driver-x86@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	USB <linux-usb@vger.kernel.org>
Subject: Re: [PATCH 09/12] usb: roles: Add Intel XHCI USB role switch driver
Date: Fri, 16 Feb 2018 15:47:04 +0200	[thread overview]
Message-ID: <CAHp75VfnqbSecz4y-ThLRPVjTe6jrBPgwEnGEuxb6AunvNDvvg@mail.gmail.com> (raw)
In-Reply-To: <20180216104751.8371-10-hdegoede@redhat.com>

On Fri, Feb 16, 2018 at 12:47 PM, Hans de Goede <hdegoede@redhat.com> wrote:
> Various Intel SoCs (Cherry Trail, Broxton and others) have an internal USB
> role switch for swiching the OTG USB data lines between the xHCI host
> controller and the dwc3 gadget controller.
>
> Note on some Cherry Trail systems there is ACPI/AML code listening to
> edge interrupts on the id-pin (through an _AIE ACPI method) and switching
> the role between ROLE_HOST and ROLE_NONE based on the id-pin. Note it does
> not set the role to ROLE_DEVICE, because device-mode is usually not used
> under Windows.
>
> The presence of AML code which modifies the cfg0 reg (on some systems)
> means that we our read/write/modify of cfg0 may race with the AML code
> doing the same to avoid this we take the global ACPI lock while doing
> the read/write/modify.

> +/* register definition */
> +#define DUAL_ROLE_CFG0                 0x68
> +#define SW_VBUS_VALID                  (1 << 24)
> +#define SW_IDPIN_EN                    (1 << 21)
> +#define SW_IDPIN                       (1 << 20)
> +
> +#define DUAL_ROLE_CFG1                 0x6c
> +#define HOST_MODE                      (1 << 29)

Does it make sense to use BIT() macro above?


> +struct intel_xhci_acpi_match {
> +       const char *hid;
> +       int hrv;
> +};

Consider to unify with struct acpi_ac_bl.

> +static const struct intel_xhci_acpi_match allow_userspace_ctrl_ids[] = {
> +       { "INT33F4",  3 }, /* X-Powers AXP288 PMIC */
> +};
> +
> +static int intel_xhci_usb_set_role(struct device *dev, enum usb_role role)
> +{
> +       struct intel_xhci_usb_data *data = dev_get_drvdata(dev);
> +       unsigned long timeout;
> +       acpi_status status;

> +       u32 glk = -1U;

I prefer to see consistency and moreover less confusing set, like

~0U

> +       u32 val;
> +
> +       /*
> +        * On many CHT devices ACPI event (_AEI) handlers read / modify /
> +        * write the cfg0 register, just like we do. Take the ACPI lock
> +        * to avoid us racing with the AML code.
> +        */
> +       status = acpi_acquire_global_lock(ACPI_WAIT_FOREVER, &glk);

FOREVER?!
Wouldn't be slightly long under certain circumstances?

> +       if (ACPI_FAILURE(status) && status != AE_NOT_CONFIGURED) {
> +               dev_err(dev, "Error could not acquire lock\n");
> +               return -EIO;
> +       }

> +       acpi_release_global_lock(glk);

> +       /* Polling on CFG1 register to confirm mode switch.*/
> +       do {
> +               val = readl(data->base + DUAL_ROLE_CFG1);

> +               if (!!(val & HOST_MODE) == (role == USB_ROLE_HOST))

I would prefer ^ instead of first ==, but it's up to you.

> +                       return 0;
> +
> +               /* Interval for polling is set to about 5 - 10 ms */
> +               usleep_range(5000, 10000);
> +       } while (time_before(jiffies, timeout));
> +
> +       dev_warn(dev, "Timeout waiting for role-switch\n");
> +       return -ETIMEDOUT;
> +}

> +static int intel_xhci_usb_probe(struct platform_device *pdev)
> +{
> +       struct device *dev = &pdev->dev;
> +       struct intel_xhci_usb_data *data;
> +       struct resource *res;
> +       resource_size_t size;
> +       int i, ret;
> +
> +       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);

> +       size = (res->end + 1) - res->start;

resource_size()

> +       data->base = devm_ioremap_nocache(dev, res->start, size);

So, what's wrong with devm_ioremap_resource() ?
...which also prints an error message.

> +       if (IS_ERR(data->base)) {
> +               ret = PTR_ERR(data->base);

> +               dev_err(dev, "Error iomaping registers: %d\n", ret);

At least printing return code is useless. Driver core does this.

> +               return ret;
> +       }
> +

> +       data->role_sw = usb_role_switch_register(dev, &sw_desc);
> +       if (IS_ERR(data->role_sw)) {
> +               ret = PTR_ERR(data->role_sw);

> +               dev_err(dev, "Error registering role-switch: %d\n", ret);

Ditto.

> +               return ret;
> +       }
> +
> +       return 0;
> +}

> +static const struct platform_device_id intel_xhci_usb_table[] = {
> +       { .name = DRV_NAME },

> +       {},

No comma, please.

> +};

-- 
With Best Regards,
Andy Shevchenko

  parent reply	other threads:[~2018-02-16 13:47 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-16 10:47 [PATCH 00/12] USB Type-C device-connection, mux and switch support Hans de Goede
2018-02-16 10:47 ` [PATCH 01/12] drivers: base: Unified device connection lookup Hans de Goede
2018-02-16 11:00   ` Andy Shevchenko
2018-02-16 11:21     ` Hans de Goede
2018-02-16 11:28       ` Heikki Krogerus
2018-02-16 10:47 ` [PATCH 02/12] usb: typec: Start using ERR_PTR Hans de Goede
2018-02-16 11:07   ` Andy Shevchenko
2018-02-16 11:21     ` Hans de Goede
2018-02-16 10:47 ` [PATCH 03/12] usb: typec: API for controlling USB Type-C Multiplexers Hans de Goede
2018-02-16 14:00   ` Andy Shevchenko
2018-02-25 12:13     ` Hans de Goede
2018-02-16 10:47 ` [PATCH 04/12] usb: common: Small class for USB role switches Hans de Goede
2018-02-16 14:07   ` Andy Shevchenko
2018-02-16 14:22     ` Heikki Krogerus
2018-02-19  9:32       ` Hans de Goede
2018-02-25 12:16     ` Hans de Goede
2018-02-16 18:33   ` Randy Dunlap
2018-02-25 12:16     ` Hans de Goede
2018-02-16 10:47 ` [PATCH 05/12] usb: typec: tcpm: Set USB role switch to device mode when configured as such Hans de Goede
2018-02-16 13:19   ` Heikki Krogerus
2018-02-16 10:47 ` [PATCH 06/12] usb: typec: tcpm: Use new Type-C switch/mux and usb-role-switch functions Hans de Goede
2018-02-16 13:20   ` Heikki Krogerus
2018-02-16 10:47 ` [PATCH 07/12] xhci: Add option to get next extended capability in list by passing id = 0 Hans de Goede
2018-02-16 13:21   ` Heikki Krogerus
2018-02-16 10:47 ` [PATCH 08/12] xhci: Add Intel extended cap / otg phy mux handling Hans de Goede
2018-02-16 13:32   ` Heikki Krogerus
2018-02-16 13:53   ` Andy Shevchenko
2018-02-25 13:01     ` Hans de Goede
2018-02-16 10:47 ` [PATCH 09/12] usb: roles: Add Intel XHCI USB role switch driver Hans de Goede
2018-02-16 13:38   ` Heikki Krogerus
2018-02-25 12:11     ` Hans de Goede
2018-02-16 13:47   ` Andy Shevchenko [this message]
2018-02-25 13:29     ` Hans de Goede
2018-02-16 10:47 ` [PATCH 10/12] usb: typec: driver for Pericom PI3USB30532 Type-C cross switch Hans de Goede
2018-02-16 13:33   ` Andy Shevchenko
2018-02-16 13:43   ` Heikki Krogerus
2018-02-16 10:47 ` [PATCH 11/12] platform/x86: intel_cht_int33fe: Add device connections for the Type-C port Hans de Goede
2018-02-16 13:10   ` Andy Shevchenko
2018-02-16 13:43   ` Heikki Krogerus
2018-02-16 10:47 ` [PATCH 12/12] extcon: axp288: Set USB role where necessary Hans de Goede
2018-02-16 13:19   ` Andy Shevchenko
2018-02-25 13:49     ` Hans de Goede
2018-02-16 13:45   ` Heikki Krogerus
2018-02-16 13:36 ` [PATCH 00/12] USB Type-C device-connection, mux and switch support Andy Shevchenko
  -- strict thread matches above, loose matches on Subject: below --
2018-02-16 10:43 [PATCH 0/12] " Hans de Goede
2018-02-16 10:43 ` [PATCH 09/12] usb: roles: Add Intel XHCI USB role switch driver Hans de Goede

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=CAHp75VfnqbSecz4y-ThLRPVjTe6jrBPgwEnGEuxb6AunvNDvvg@mail.gmail.com \
    --to=andy.shevchenko@gmail.com \
    --cc=andy@infradead.org \
    --cc=cw00.choi@samsung.com \
    --cc=dvhart@infradead.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hdegoede@redhat.com \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    --cc=myungjoo.ham@samsung.com \
    --cc=platform-driver-x86@vger.kernel.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).