Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752499AbdIHPqX (ORCPT ); Fri, 8 Sep 2017 11:46:23 -0400 Received: from mail-ve1eur01on0115.outbound.protection.outlook.com ([104.47.1.115]:31920 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750934AbdIHPqS (ORCPT ); Fri, 8 Sep 2017 11:46:18 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=peda@axentia.se; From: Peter Rosin To: Hans de Goede Cc: Peter Rosin , MyungJoo Ham , Chanwoo Choi , Guenter Roeck , Heikki Krogerus , Darren Hart , Andy Shevchenko , Mathias Nyman , linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org, devel@driverdev.osuosl.org, Kuppuswamy Sathyanarayanan , Sathyanarayanan Kuppuswamy Natarajan , Greg Kroah-Hartman , linux-usb@vger.kernel.org Subject: Re: [PATCH v2 05/11] mux: Add Intel Cherrytrail USB mux driver Date: Fri, 8 Sep 2017 17:45:12 +0200 Message-Id: <20170908154514.4463-1-peda@axentia.se> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170905164221.11266-6-hdegoede@redhat.com> References: <20170905164221.11266-6-hdegoede@redhat.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [81.224.168.30] X-ClientProxiedBy: HE1PR0301CA0017.eurprd03.prod.outlook.com (2603:10a6:3:76::27) To VI1PR0202MB2557.eurprd02.prod.outlook.com (2603:10a6:801:6::8) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6cf504af-4659-4d7a-5360-08d4f6d0bc7c X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(2017082002075)(300000503095)(300135400095)(201703131423075)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:VI1PR0202MB2557; X-Microsoft-Exchange-Diagnostics: 1;VI1PR0202MB2557;3:3mzPTFJO2cImAP/fw4kw4dssS2U4WAdGWVD1U87rvyGx94ks1zXTyVCcfuv0vfzC/ju3mE+VZYGsYPpjBZA1VI6koHsVFGqHVyBJHIgH9v+p9btXuMKaTeaYmyImVfbT4fkCtDTE5dFQf8hBawpgi61gFFcvmb4xR2dwkww8oiigZHhd/uwoB2emv105gO8F+avjDvnDuEQlvTCBNnDtgplTuT0Hc8c2twgWqIvGpOj4H4xeqVMQlEhz6+BtXci+;25:VfOqEYQZjLoeo/NxiY66WD1bpUgUVphJ3RuWvRnnWqIerHaqG7iReHdiuOLoMQ+z+jDvcJEpf814/cXEQL3aiyoEZ8+37VpQjsF3yPhOL7nRBxlzJX7juhCTGaDeOCwR0xnT99eywluNCU4QKrMdrXCnrPwqnsEXnf8aFGvzMoa08jCmfcJnprQFvp8jTW+OVGUw0bQxbDisXgbj/fDTtLr7fLBXitjidMQ/h+ta+HTDhbPbM3WHWMZwzPnCVA1ZDc6MZyZXtUDxBn61Mx3v/pwoio05HRp2bO27xx+QIfrBw/CpoFylKpT15xm0KKqRS8VkEgwkGPYCElQbiDJfTQ==;31:a4dwfeo7tG1+CC2G47RtTN7kGg9YDmg6AcZZhwEkrBLxPhIOdGtvNQv3jpr0mIv8E1ICaxleKdLS9GhdOOX7Al6RGqCztLdegOeD+0/n8S0bf3IQZ8bQdXo984s+ISx3JuANV6a9RKadcNUGoJvdBL0cETtNjZVSB8+Hw4lt6xu5O7rVzcFO/c03ZTSuOZGIwTGm8xbtC1ylJIweT/1C7vTWxLteoE+st2pr81AfASc= X-MS-TrafficTypeDiagnostic: VI1PR0202MB2557: X-Exchange-Antispam-Report-Test: UriScan:(211171220733660)(11668515415152); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(93006095)(93001095)(3002001)(10201501046)(100000703101)(100105400095)(6041248)(20161123558100)(20161123560025)(20161123555025)(2016111802025)(20161123564025)(201703131423075)(201703061421075)(20161123562025)(6042181)(6043046)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:VI1PR0202MB2557;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:VI1PR0202MB2557; X-Microsoft-Exchange-Diagnostics: 1;VI1PR0202MB2557;4:56ItQ/XLnxOOK+TZNc6woOXRhlXDJsr1TDM9iSnksgr4ecUKTR6CpXdBkvlDVWWWrxhlhLk187g7bULTmtTOvDjLUJd1GcLk5zrAOSHVcG03pq1lWZ+Exbv4Lf4FipOdegcnUw7SoEs+8BwxRexKFlLteQ6//mktkBy77gNGjhTybYIABfSY2KgVKMIikZr/T08veU4IZMl9NHXlLlpibZO/d4Hk5mgdONksShtyDnEBo161gFAeglAl6ehCu3wkvnHnHGVcqptyONRSt+xERaNBkg3tQEjqdkkHb3TJolEpzWjhoCQG13+r2woYsimuJSh6zX3mC1OYRJaFggyGGw== X-Forefront-PRVS: 04244E0DC5 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(7370300001)(6009001)(24454002)(377424004)(199003)(189002)(53546010)(6116002)(68736007)(86362001)(189998001)(3846002)(2906002)(6916009)(2950100002)(50986999)(1076002)(110136004)(76176999)(6246003)(4326008)(53936002)(36756003)(54906002)(7350300001)(97736004)(6512007)(5003940100001)(81156014)(81166006)(8676002)(7736002)(66066001)(6506006)(305945005)(229853002)(50226002)(508600001)(50466002)(7416002)(101416001)(74482002)(105586002)(47776003)(48376002)(42186005)(5660300001)(33646002)(106356001)(25786009)(6486002)(2004002)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:VI1PR0202MB2557;H:orc.pedanet;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;VI1PR0202MB2557;23:2zH3pVPPI9UlrFQLGtQdALJG5Pe0YrXa+r9hnq1?= =?us-ascii?Q?V512e13tPHLQCaom+KM80JN8e95YVW3xL8HrhxHldJDFGJ9sJsJVJgTfoadh?= =?us-ascii?Q?/AQW/8n329hf3ppvhNZPLxJdeTUvdGbhVQlud+N1U8DWjSDlmc3URHsmke8H?= =?us-ascii?Q?oKBrBUzdDtc4ibjqbCDmAj6UBvYaw64ecHuygqpOXG1QUlT8Qx6y/6o4xNgb?= =?us-ascii?Q?9kawxTcbRjtIwqOw1PlCjRgz9GMqyuZnZl++bNYbkDehaUkyCkTD0xJLM3jr?= =?us-ascii?Q?/wD0ykr+FjTvB+oNTJOUtsSZGar1OHlQPIOHilIpX7ljkO1tPvD24u0OwuUs?= =?us-ascii?Q?eWuVhmU4NEysL498imqB6aks4E8V5w6Mf/LYZS5PByvZMWaRrgNUiIQPFWry?= =?us-ascii?Q?2PXcWUkAYpgX1WfSWZ/uyGtlDJqPxgJOM/AWvArIYDuMLfP966tLJXRyKDkn?= =?us-ascii?Q?6vOo7ABED0yfDLutZWwIAeVPcop2aI4nmbgafQyFLnkydZxAekXUVXW8T32s?= =?us-ascii?Q?U3lFXy9WwNK61byMhn3UiNK95q4IjZZtskUGmjwVpIIMHWcQuXLQ3ualbvKx?= =?us-ascii?Q?DvD7EU7fj2CsHZX2y1aBgk9wUmtVV8LvOpv0Z+u3GW3TuKVdvmVx7Z6naTa/?= =?us-ascii?Q?lEupGaqF3yAASLkqhYFNZH6V4aVG1IzOUPRVQwfmIINK4+NJLCxV52IPdx96?= =?us-ascii?Q?7jbPHmdA7T8/S7T//N+uPyhiG4qjhtM0qgekBUMkrGY8ARkNO9nhbIwqzKXM?= =?us-ascii?Q?mHrXN1uZJalyj5+09FFuhcIVsfq5H3fOc0F4XuoLrsmQJfv6bfIq2swJ7BNs?= =?us-ascii?Q?a5B7wBqpjUh9sbtu5KRxCn6jyKrjyPi1Vk9jTO3uFAQsQDqnm30+D4Ba4izD?= =?us-ascii?Q?s4JwVSi9FX8B2gJIlq+gs5KFrptHJzW1FFTYIaDdfJle64ZTys3b6JTUwSCp?= =?us-ascii?Q?GHZAMHNzScAi1pU+U7ciRFYTGoaf6YRNFuKfSoqZXv4GUYsG5htalZaRGfsW?= =?us-ascii?Q?TbD++LcrtHSg9ZedH/1vlTD6iiYa8ULuMdnJR773O2qRUst73Rp602BAe/g6?= =?us-ascii?Q?NCxcMm2nV8X3Qb9uVkUZf9EXWQNuuF2DHlssPQEbWYVA0p+myyUytyurC7uP?= =?us-ascii?Q?Rp2uaTr8Lt4V84TV8ocqaZGUy3HyRCdkVld92VemtCS188B7DCGb9Zq2gxg6?= =?us-ascii?Q?C2snV1RGe7OFYBiAnOpaS51LbDfj7kBmA3JEm17MHmiDfbwt4UdO0l9sfP32?= =?us-ascii?Q?eTjPpfH7OqZmgfiqK5rXqv/Bfyv35Kfp7ALO0V7k5L3mFeigP5QRFXcshxmF?= =?us-ascii?Q?jTQ=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;VI1PR0202MB2557;6:ouzAs519hg3lfKbiBFSh8yTRndeWcGT/p5mIcs/smsiq5LD8RBTrGVpv1dvvxUTDt+caQyJkNzd3FpKpMW+1baYm0OM2K+rY1hP26PIfhcJDDWf8sIncjy6tH7GRyg0kJqfgTNnFV0O+bP5Z/TXfo+vG/MQF3MmelYLeX8dj1LzgQFby70K0Ef8E5QL/cCm7oP1KE+LzLxUeVtPPZ6KoAboQyjmsfsn5MlB+q5UPe+3wnfAVmFJdAj5uXzHRsJezYD3HQixs/LPZpjUmmCmly84G51H4G8E5gtD3RJuiEdniLud4AV/tPE+oyYAuZJ40qWWtPSJKCkD5JKcezUYZ/g==;5:hnYTdU9JbY6USqYSie4SI0iqOuL+x+RV1evu+GF4rgLt36ldXV4/Ue1as7oRK1fRzBbNTYf8Qk+iAdI8/pl7ccuuWguqLgXz2kybNnm6aXzN2p3mZvlE40rZHzHQ1JAbgUsUCGL/zMAwdkF2dGPNXw==;24:v8ON94xdAlcc8ioaTw0stDvR4l6hUC3rlQZMWDlHb5HDKBqE4EO4sP+kyeA5pl53Ug58FyoPkWEOUq6KRZopF/tPFIpz+WRXVt3mXOlV+AI=;7:i4eCv3U4adNW1cIagMSd5M2NS2Y4qurvpGlUsAE7eQLF1EwLEVii9gCKjWblk6YA4YCMenm8JT7k8wlbh3McO6ANv7ulhta7LLTF/inG+8Kdf7BhofTQsdXvI/Xs4h5hIVPt9Mi9b+2eS6gCGVmLe1LURS0W/ugdlPHuR67mxZYkWMkTsXo2u1MkPtzdxQX7t/lDTFyOq3UfMIBPpP4okPsSQQ+G+ACi1dH4f8OGxgQ= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Sep 2017 15:46:12.3695 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0202MB2557 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 13480 Lines: 429 On 2017-09-05 18:42, Hans de Goede wrote: > Intel Cherrytrail SoCs have an internal USB mux for muxing the otg-port > USB data lines between the xHCI host controller and the dwc3 gadget > controller. On some Cherrytrail systems this mux is controlled through > AML code reacting on a GPIO IRQ connected to the USB OTG id pin (through > an _AIE ACPI method) so things just work. > > But on other Cherrytrail systems we need to control the mux ourselves > this driver exports the mux through the mux subsys, so that other drivers > can control it if necessary. > > This driver also updates the vbus-valid reporting to the dwc3 gadget > controller, as this uses the same registers as the mux. This is needed > for gadget/device mode to work properly (even on systems which control > the mux from their AML code). > > Note this depends on the xhci driver registering a platform device > named "intel_cht_usb_mux", which has an IOMEM resource 0 which points > to the Intel Vendor Defined XHCI extended capabilities region. > > Signed-off-by: Hans de Goede > --- > Changes in v2: > -Complete rewrite as a stand-alone platform-driver rather then as a phy > driver, since this is just a mux, not a phy > > Changes in v3: > -Make this a mux subsys driver instead of listening to USB_HOST extcon > cable events and responding to those > > Changes in v4 (of patch, v2 of new mux based series): > -Rename C-file to use - in name > -Add MAINTAINERS entry > -Various code-style fixes > --- > MAINTAINERS | 5 + > drivers/mux/Kconfig | 11 ++ > drivers/mux/Makefile | 10 +- > drivers/mux/intel-cht-usb-mux.c | 257 ++++++++++++++++++++++++++++++++++++++++ > 4 files changed, 279 insertions(+), 4 deletions(-) > create mode 100644 drivers/mux/intel-cht-usb-mux.c > > diff --git a/MAINTAINERS b/MAINTAINERS > index 14a2fd905217..dfaed958db85 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -8991,6 +8991,11 @@ F: include/linux/dt-bindings/mux/ > F: include/linux/mux/ > F: drivers/mux/ > > +MULTIPLEXER SUBSYSTEM INTEL CHT USB MUX DRIVER > +M: Hans de Goede > +S: Maintained > +F: drivers/mix/intel-cht-usb-mux.c s/mix/mux/ (also in patch 06/11) > + > MULTISOUND SOUND DRIVER > M: Andrew Veliath > S: Maintained > diff --git a/drivers/mux/Kconfig b/drivers/mux/Kconfig > index 19e4e904c9bf..947cfd7af02a 100644 > --- a/drivers/mux/Kconfig > +++ b/drivers/mux/Kconfig > @@ -34,6 +34,17 @@ config MUX_GPIO > To compile the driver as a module, choose M here: the module will > be called mux-gpio. > > +config MUX_INTEL_CHT_USB_MUX > + tristate "Intel Cherrytrail USB Multiplexer" > + depends on ACPI && X86 && EXTCON > + help > + This driver adds support for the internal USB mux for muxing the OTG > + USB data lines between the xHCI host controller and the dwc3 gadget > + controller found on Intel Cherrytrail SoCs. > + > + To compile the driver as a module, choose M here: the module will > + be called mux-intel_cht_usb_mux. s/_/-/g > + > config MUX_MMIO > tristate "MMIO register bitfield-controlled Multiplexer" > depends on (OF && MFD_SYSCON) || COMPILE_TEST > diff --git a/drivers/mux/Makefile b/drivers/mux/Makefile > index 0e1e59760e3f..6cf41be2754f 100644 > --- a/drivers/mux/Makefile > +++ b/drivers/mux/Makefile > @@ -5,9 +5,11 @@ > mux-core-objs := core.o > mux-adg792a-objs := adg792a.o > mux-gpio-objs := gpio.o > +mux-intel-cht-usb-mux-objs := intel-cht-usb-mux.o > mux-mmio-objs := mmio.o > > -obj-$(CONFIG_MULTIPLEXER) += mux-core.o > -obj-$(CONFIG_MUX_ADG792A) += mux-adg792a.o > -obj-$(CONFIG_MUX_GPIO) += mux-gpio.o > -obj-$(CONFIG_MUX_MMIO) += mux-mmio.o > +obj-$(CONFIG_MULTIPLEXER) += mux-core.o > +obj-$(CONFIG_MUX_ADG792A) += mux-adg792a.o > +obj-$(CONFIG_MUX_GPIO) += mux-gpio.o > +obj-$(CONFIG_MUX_INTEL_CHT_USB_MUX) += mux-intel-cht-usb-mux.o > +obj-$(CONFIG_MUX_MMIO) += mux-mmio.o > diff --git a/drivers/mux/intel-cht-usb-mux.c b/drivers/mux/intel-cht-usb-mux.c > new file mode 100644 > index 000000000000..9cd1a1f5027f > --- /dev/null > +++ b/drivers/mux/intel-cht-usb-mux.c > @@ -0,0 +1,257 @@ > +/* > + * Intel Cherrytrail USB OTG MUX driver > + * > + * Copyright (c) 2016 Hans de Goede 2017? > + * > + * Loosely based on android x86 kernel code which is: > + * > + * Copyright (C) 2014 Intel Corp. > + * > + * Author: Wu, Hao > + * > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License version 2 as > + * published by the Free Software Foundation, or (at your option) > + * any later version. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +/* 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) > + > +#define DUAL_ROLE_CFG1_POLL_TIMEOUT 1000 > + > +#define DRV_NAME "intel_cht_usb_mux" > + > +struct intel_cht_usb_data { > + struct mutex cfg0_lock; > + void __iomem *base; > + struct extcon_dev *vbus_extcon; > + struct notifier_block vbus_nb; > + struct work_struct vbus_work; > +}; > + > +struct intel_cht_extcon_info { > + const char *hid; > + int hrv; > + const char *extcon; > +}; > + > +static const struct intel_cht_extcon_info vbus_providers[] = { > + { .hid = "INT33F4", .hrv = -1, .extcon = "axp288_extcon" }, > + { .hid = "INT34D3", .hrv = 3, .extcon = "cht_wcove_pwrsrc" }, > +}; > + > +static const unsigned int vbus_cable_ids[] = { > + EXTCON_CHG_USB_SDP, EXTCON_CHG_USB_CDP, EXTCON_CHG_USB_DCP, > + EXTCON_CHG_USB_ACA, EXTCON_CHG_USB_FAST, > +}; > + > +static int intel_cht_usb_set_mux(struct mux_control *mux, int state) > +{ > + struct intel_cht_usb_data *data = mux_chip_priv(mux->chip); > + unsigned long timeout; > + bool host_mode; > + u32 val; > + > + mutex_lock(&data->cfg0_lock); > + > + /* Set idpin value as requested */ > + val = readl(data->base + DUAL_ROLE_CFG0); > + if (state == MUX_USB_DEVICE) { > + val |= SW_IDPIN; > + host_mode = false; > + } else { > + val &= ~SW_IDPIN; > + host_mode = true; > + } > + val |= SW_IDPIN_EN; > + writel(val, data->base + DUAL_ROLE_CFG0); > + > + mutex_unlock(&data->cfg0_lock); > + > + /* In most case it takes about 600ms to finish mode switching */ > + timeout = jiffies + msecs_to_jiffies(DUAL_ROLE_CFG1_POLL_TIMEOUT); > + > + /* Polling on CFG1 register to confirm mode switch.*/ > + while (1) { > + val = readl(data->base + DUAL_ROLE_CFG1); > + if (!!(val & HOST_MODE) == host_mode) > + break; > + > + /* Interval for polling is set to about 5 - 10 ms */ > + usleep_range(5000, 10000); > + > + if (time_after(jiffies, timeout)) { > + dev_warn(&mux->chip->dev, > + "Timeout waiting for mux to switch\n"); > + break; > + } > + } > + > + return 0; > +} I think what Andy was after was something like this (untested): do { val = readl(data->base + DUAL_ROLE_CFG1); if (!!(val & HOST_MODE) == host_mode) return 0; /* Interval for polling is set to about 5 - 10 ms */ usleep_range(5000, 10000); } while (time_before(jiffies, timeout)); dev_warn(&mux->chip->dev, "Timeout waiting for mux to switch\n"); return -ETIMEDOUT; } Note that I changed the return value to fail on timeout. I don't know why you didn't pass on the failure before? > + > +static void intel_cht_usb_set_vbus_valid(struct intel_cht_usb_data *data, > + bool valid) > +{ > + u32 val; > + > + mutex_lock(&data->cfg0_lock); > + > + val = readl(data->base + DUAL_ROLE_CFG0); > + if (valid) > + val |= SW_VBUS_VALID; > + else > + val &= ~SW_VBUS_VALID; > + > + val |= SW_IDPIN_EN; > + writel(val, data->base + DUAL_ROLE_CFG0); > + > + mutex_unlock(&data->cfg0_lock); > +} > + > +static void intel_cht_usb_vbus_work(struct work_struct *work) > +{ > + struct intel_cht_usb_data *data = > + container_of(work, struct intel_cht_usb_data, vbus_work); > + bool vbus_present = false; > + int i; > + > + for (i = 0; i < ARRAY_SIZE(vbus_cable_ids); i++) { > + if (extcon_get_state(data->vbus_extcon, vbus_cable_ids[i]) > 0) { > + vbus_present = true; > + break; > + } > + } > + > + intel_cht_usb_set_vbus_valid(data, vbus_present); > +} > + > +static int intel_cht_usb_vbus_extcon_evt(struct notifier_block *nb, > + unsigned long event, void *param) > +{ > + struct intel_cht_usb_data *data = > + container_of(nb, struct intel_cht_usb_data, vbus_nb); > + > + schedule_work(&data->vbus_work); > + > + return NOTIFY_OK; > +} > + > +static const struct mux_control_ops intel_cht_usb_ops = { > + .set = intel_cht_usb_set_mux, > +}; > + > +static int intel_cht_usb_probe(struct platform_device *pdev) > +{ > + struct device *dev = &pdev->dev; > + struct intel_cht_usb_data *data; > + struct mux_chip *mux_chip; > + struct resource *res; > + resource_size_t size; > + int i, ret; > + > + mux_chip = devm_mux_chip_alloc(dev, 1, sizeof(*data)); > + if (IS_ERR(mux_chip)) > + return PTR_ERR(mux_chip); > + > + mux_chip->ops = &intel_cht_usb_ops; > + mux_chip->mux[0].idle_state = MUX_USB_DEVICE; > + /* Keep initial state as is, for e.g. booting from an USB disk */ > + mux_chip->mux[0].cached_state = MUX_USB_DEVICE; This I don't like. The cached_state is owned by the core. But I get that the initial idle state is special and might also be special for other muxes. So, I think some sanctioned and explicit way to special case the initial idle state is the way to go. Honestly, I can't think of more than two sane modes to initialize a mux though. Either you initialize it to whatever the idle state is (like what is happening today), or you keep it in it's current state. So, I'm thinking something like this in the driver should be sufficient: mux_chip->mux[0].init_as_is = true; I'll reply with a suggested patch implementing that... [time passes] When I tried to describe that commit, I realized that I had a very hard time coming up with something sensible. The problem I had was that if it is crucial that the mux is left alone, then registering a mux controller for it may not be the wisest thing to do. Because mux consumers are then provided with a way to trample on whatever depends on the mux to be in its specific pre-registration position. The correct thing to do is to wait with the mux controller registration until it is ok to set it to its idle state. But maybe that kind of thinking is just utopia? Another way would be lock the mux controller in a specific state during registration it. But if there are competing mux consumers it gets hairy to decide which consumer should be responsible for unselecting it. Seems like a non-starter to me... (I obviously have the above comment also for patch 06/11) Cheers, Peter > + mux_chip->mux[0].states = MUX_USB_STATES; > + data = mux_chip_priv(mux_chip); > + mutex_init(&data->cfg0_lock); > + > + /* > + * Besides controlling the mux we also need to control the vbus_valid > + * flag for device/gadget mode to work properly. To do this we monitor > + * the extcon interface exported by the PMIC drivers for the PMICs used > + * with the Cherry Trail SoC. > + * > + * We try to get the extcon_dev before registering the mux as this > + * may lead to us exiting with -EPROBE_DEFER. > + */ > + for (i = 0 ; i < ARRAY_SIZE(vbus_providers); i++) { > + if (!acpi_dev_present(vbus_providers[i].hid, NULL, > + vbus_providers[i].hrv)) > + continue; > + > + data->vbus_extcon = extcon_get_extcon_dev( > + vbus_providers[i].extcon); > + if (data->vbus_extcon == NULL) > + return -EPROBE_DEFER; > + > + dev_info(dev, "using extcon '%s' for vbus-valid\n", > + vbus_providers[i].extcon); > + break; > + } > + > + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); > + size = (res->end + 1) - res->start; > + data->base = devm_ioremap_nocache(dev, res->start, size); > + if (IS_ERR(data->base)) { > + ret = PTR_ERR(data->base); > + dev_err(dev, "can't iomap registers: %d\n", ret); > + return ret; > + } > + > + ret = devm_mux_chip_register(dev, mux_chip); > + if (ret < 0) > + return ret; > + > + if (data->vbus_extcon) { > + INIT_WORK(&data->vbus_work, intel_cht_usb_vbus_work); > + data->vbus_nb.notifier_call = intel_cht_usb_vbus_extcon_evt; > + ret = devm_extcon_register_notifier_all(dev, data->vbus_extcon, > + &data->vbus_nb); > + if (ret) { > + dev_err(dev, "can't register vbus extcon notifier: %d\n", > + ret); > + return ret; > + } > + > + /* Sync initial mode */ > + schedule_work(&data->vbus_work); > + } > + > + return 0; > +} > + > +static const struct platform_device_id intel_cht_usb_table[] = { > + { .name = DRV_NAME }, > + {}, > +}; > +MODULE_DEVICE_TABLE(platform, intel_cht_usb_table); > + > +static struct platform_driver intel_cht_usb_driver = { > + .driver = { > + .name = DRV_NAME, > + }, > + .id_table = intel_cht_usb_table, > + .probe = intel_cht_usb_probe, > +}; > + > +module_platform_driver(intel_cht_usb_driver); > + > +MODULE_AUTHOR("Hans de Goede "); > +MODULE_DESCRIPTION("Intel Cherrytrail USB mux driver"); > +MODULE_LICENSE("GPL"); >