Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6056287imu; Wed, 30 Jan 2019 08:05:20 -0800 (PST) X-Google-Smtp-Source: ALg8bN7ycuN9nX/CjPvKQvQ+3MgSPq6NTeIdOALP6qPdhuuHob37FFrrh8mRwylBfZHvktT04FAU X-Received: by 2002:a62:6047:: with SMTP id u68mr30558029pfb.239.1548864320279; Wed, 30 Jan 2019 08:05:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548864320; cv=none; d=google.com; s=arc-20160816; b=jgO2782XHZ49elK55CGKx6ZxBTmOVmKo3cQICdFxW27AvVe53JVZxW5yilK796L1pC Py+jPWG2sLH7OCZ9Evc84wJ/TrkrKBOtsMlx85lHF8E6rmIo7S8n7LvdQZradbqUH2gG /xw4IJSfEx4rt44VwMUeuHGQ8avgKg/QoioBetzQhlvgwdLVKeDLXsBE3JIb8S4TQs1q p3JrphiLiemqpRETq5jgs4unmTcwG2SXsnDbUZYytt5xccLFaZkHJ0OCLu/g2756N5HS fopiBBF6wkKeDSfcg6G5nC/kUuVeDPlwHCB0sBSERHfjaPpY+A5cyeoXYJnvKut0TbRT Mxwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=BtLZt3ox+ZXnOFrvNKJTxMAP0yV1H2pZ9/LaCxep3Mg=; b=cEKOTirxSoNMgZ38URNp1jN5i4e832y3SphfxL/PHbe0AVMg8daS8oT5SDTJlsMFg4 Dcz34ceOGJB2BhKIN+BDIKkukcXXZyhOkA0T7eBRB3Yo4L2rYqFHwXXzrLjvjIMA2ugF JX490jXYxnCF1VE48289XuR/1jQSz3QnpVq2ECdBPSb7wowVLboHEgwS4f1tHQ2Tz8XR QjcR8ooVvC/A1Tvac7u1V7hkzCMi334Hyyxymo+4NlxaLxX93+tTj+bOJmRXjXan/Ky9 GzOcww5MLDkT0VdDzO/UTfofU1l9oa+wiuBJKihk438zOT6ET+5KAp1Sb8ANyTOT8WVo ln3w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v13si17326pgn.355.2019.01.30.08.04.54; Wed, 30 Jan 2019 08:05:20 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731911AbfA3QDR (ORCPT + 99 others); Wed, 30 Jan 2019 11:03:17 -0500 Received: from mga02.intel.com ([134.134.136.20]:60152 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731898AbfA3QDO (ORCPT ); Wed, 30 Jan 2019 11:03:14 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Jan 2019 08:03:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,541,1539673200"; d="scan'208";a="142760912" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 30 Jan 2019 08:03:12 -0800 From: Heikki Krogerus To: Greg Kroah-Hartman Cc: Andy Shevchenko , Chen Yu , Jun Li , Hans de Goede , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/9] usb: typec: mux: Find the muxes by also matching against the device node Date: Wed, 30 Jan 2019 19:02:55 +0300 Message-Id: <20190130160259.46919-6-heikki.krogerus@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190130160259.46919-1-heikki.krogerus@linux.intel.com> References: <20190130160259.46919-1-heikki.krogerus@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When the connections are defined in firmware, struct device_connection will have the fwnode member pointing to the device node (struct fwnode_handle) of the requested device, and the endpoint will not be used at all in that case. Signed-off-by: Heikki Krogerus --- drivers/usb/typec/mux.c | 86 +++++++++++++++++++++++++++++++++++------ 1 file changed, 74 insertions(+), 12 deletions(-) diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c index 8975f58e1d60..a5947d98824d 100644 --- a/drivers/usb/typec/mux.c +++ b/drivers/usb/typec/mux.c @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include static DEFINE_MUTEX(switch_lock); @@ -23,15 +25,25 @@ static void *typec_switch_match(struct device_connection *con, int ep, { struct typec_switch *sw; - list_for_each_entry(sw, &switch_list, entry) - if (!strcmp(con->endpoint[ep], dev_name(sw->dev))) - return sw; + if (!con->fwnode) { + list_for_each_entry(sw, &switch_list, entry) + if (!strcmp(con->endpoint[ep], dev_name(sw->dev))) + return sw; + return ERR_PTR(-EPROBE_DEFER); + } /* - * We only get called if a connection was found, tell the caller to - * wait for the switch to show up. + * With OF graph the mux node must have a boolean device property named + * "orientation-switch". */ - return ERR_PTR(-EPROBE_DEFER); + if (con->id && !fwnode_property_present(con->fwnode, con->id)) + return NULL; + + list_for_each_entry(sw, &switch_list, entry) + if (dev_fwnode(sw->dev) == con->fwnode) + return sw; + + return con->id ? ERR_PTR(-EPROBE_DEFER) : NULL; } /** @@ -112,17 +124,67 @@ EXPORT_SYMBOL_GPL(typec_switch_unregister); static void *typec_mux_match(struct device_connection *con, int ep, void *data) { + const struct typec_altmode_desc *desc = data; struct typec_mux *mux; + size_t nval; + bool match; + u16 *val; + int i; - list_for_each_entry(mux, &mux_list, entry) - if (!strcmp(con->endpoint[ep], dev_name(mux->dev))) - return mux; + if (!con->fwnode) { + list_for_each_entry(mux, &mux_list, entry) + if (!strcmp(con->endpoint[ep], dev_name(mux->dev))) + return mux; + return ERR_PTR(-EPROBE_DEFER); + } /* - * We only get called if a connection was found, tell the caller to - * wait for the switch to show up. + * Check has the identifier already been "consumed". If it + * has, no need to do any extra connection identification. */ - return ERR_PTR(-EPROBE_DEFER); + match = !con->id; + if (match) + goto find_mux; + + /* Accessory Mode muxes */ + if (!desc) { + match = fwnode_property_present(con->fwnode, "accessory"); + if (match) + goto find_mux; + return NULL; + } + + /* Alternate Mode muxes */ + nval = fwnode_property_read_u16_array(con->fwnode, "svid", NULL, 0); + if (nval <= 0) + return NULL; + + val = kcalloc(nval, sizeof(*val), GFP_KERNEL); + if (!val) + return ERR_PTR(-ENOMEM); + + nval = fwnode_property_read_u16_array(con->fwnode, "svid", val, nval); + if (nval < 0) { + kfree(val); + return ERR_PTR(nval); + } + + for (i = 0; i < nval; i++) { + match = val[i] == desc->svid; + if (match) { + kfree(val); + goto find_mux; + } + } + kfree(val); + return NULL; + +find_mux: + list_for_each_entry(mux, &mux_list, entry) + if (dev_fwnode(mux->dev) == con->fwnode) + return mux; + + return match ? ERR_PTR(-EPROBE_DEFER) : NULL; } /** -- 2.20.1