From patchwork Fri Apr 20 08:06:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heikki Krogerus X-Patchwork-Id: 10352055 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 329856023A for ; Fri, 20 Apr 2018 08:06:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 25D8228684 for ; Fri, 20 Apr 2018 08:06:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A5A3286A3; Fri, 20 Apr 2018 08:06:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E59328684 for ; Fri, 20 Apr 2018 08:06:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754475AbeDTIGR (ORCPT ); Fri, 20 Apr 2018 04:06:17 -0400 Received: from mga05.intel.com ([192.55.52.43]:23325 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754395AbeDTIGQ (ORCPT ); Fri, 20 Apr 2018 04:06:16 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Apr 2018 01:06:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,300,1520924400"; d="scan'208";a="48481375" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 20 Apr 2018 01:06:14 -0700 From: Heikki Krogerus To: Hans de Goede Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org Subject: [PATCH] usb: roles: intel_xhci: Don't use PMIC for port type identification Date: Fri, 20 Apr 2018 11:06:13 +0300 Message-Id: <20180420080613.38371-1-heikki.krogerus@linux.intel.com> X-Mailer: git-send-email 2.17.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This will add an array of known USB Type-C Port devices that will be used as a blacklist for enabling userspace-control, and remove the PMIC ACPI HID which was used for the same purpose. It turns out that on some CHT based platforms the X-Powers PMIC is handled in firmware. The ACPI HID for it is therefore not usable for determining the port type. The driver now searches for known USB Type-C port devices instead. Signed-off-by: Heikki Krogerus --- Hi Hans, So it seems that we can't rely on the PMIC. This is my proposal for a fix. I'm in practice just using blacklist instead of whitelist for identifying the port type. Let me know if it's OK to you. Thanks, --- .../usb/roles/intel-xhci-usb-role-switch.c | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/drivers/usb/roles/intel-xhci-usb-role-switch.c b/drivers/usb/roles/intel-xhci-usb-role-switch.c index de72eedb762e..1696d1f25769 100644 --- a/drivers/usb/roles/intel-xhci-usb-role-switch.c +++ b/drivers/usb/roles/intel-xhci-usb-role-switch.c @@ -38,19 +38,26 @@ struct intel_xhci_usb_data { void __iomem *base; }; -struct intel_xhci_acpi_match { - const char *hid; - int hrv; +static const struct acpi_device_id typec_port_devices[] = { + { "PNP0CA0", 0 }, /* UCSI */ + { "INT33FE", 0 }, /* CHT USB Type-C PHY */ + { }, }; -/* - * ACPI IDs for PMICs which do not support separate data and power role - * detection (USB ACA detection for micro USB OTG), we allow userspace to - * change the role manually on these. - */ -static const struct intel_xhci_acpi_match allow_userspace_ctrl_ids[] = { - { "INT33F4", 3 }, /* X-Powers AXP288 PMIC */ -}; +static acpi_status intel_xhci_userspace_ctrl(acpi_handle handle, u32 level, + void *ctx, void **ret) +{ + struct acpi_device *adev; + + if (acpi_bus_get_device(handle, &adev)) + return AE_OK; + + /* Don't allow userspace-control with Type-C ports */ + if (!acpi_match_device_ids(adev, typec_port_devices)) + return AE_ACCESS; + + return AE_OK; +} static int intel_xhci_usb_set_role(struct device *dev, enum usb_role role) { @@ -137,7 +144,7 @@ static int intel_xhci_usb_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct intel_xhci_usb_data *data; struct resource *res; - int i; + acpi_status status; data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); if (!data) @@ -148,10 +155,11 @@ static int intel_xhci_usb_probe(struct platform_device *pdev) if (!data->base) return -ENOMEM; - for (i = 0; i < ARRAY_SIZE(allow_userspace_ctrl_ids); i++) - if (acpi_dev_present(allow_userspace_ctrl_ids[i].hid, "1", - allow_userspace_ctrl_ids[i].hrv)) - sw_desc.allow_userspace_control = true; + status = acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, + ACPI_UINT32_MAX, intel_xhci_userspace_ctrl, + NULL, NULL, NULL); + if (ACPI_SUCCESS(status)) + sw_desc.allow_userspace_control = true; platform_set_drvdata(pdev, data);