From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16FF5C433ED for ; Thu, 20 May 2021 12:33:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E537560FDB for ; Thu, 20 May 2021 12:33:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235550AbhETMfM (ORCPT ); Thu, 20 May 2021 08:35:12 -0400 Received: from mga14.intel.com ([192.55.52.115]:40582 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236467AbhETMe6 (ORCPT ); Thu, 20 May 2021 08:34:58 -0400 IronPort-SDR: xNyF7BnA0sfzqeRborUJpS50Ukj3lR6AilMBTTQU+wzwC1b65BFmBDmXV7iCtdJJeuQX4PTj+Z zHDFLjGZWq5w== X-IronPort-AV: E=McAfee;i="6200,9189,9989"; a="200915678" X-IronPort-AV: E=Sophos;i="5.82,313,1613462400"; d="scan'208";a="200915678" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 May 2021 05:33:36 -0700 IronPort-SDR: YPSVAAhCNqWnrl03Khe1at6noFmJbazD2tO2C08UqTvwyl8miudcz6Eae7wNh9YY+h1msFXqt3 MeBj/VRPwjPA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,313,1613462400"; d="scan'208";a="543512173" Received: from kuha.fi.intel.com ([10.237.72.162]) by fmsmga001.fm.intel.com with SMTP; 20 May 2021 05:33:32 -0700 Received: by kuha.fi.intel.com (sSMTP sendmail emulation); Thu, 20 May 2021 15:33:32 +0300 Date: Thu, 20 May 2021 15:33:32 +0300 From: Heikki Krogerus To: Li Jun Cc: robh+dt@kernel.org, shawnguo@kernel.org, gregkh@linuxfoundation.org, linux@roeck-us.net, linux-usb@vger.kernel.org, linux-imx@nxp.com, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH 3/4] usb: typec: add typec orientation switch support via mux controller Message-ID: References: <1621408490-23811-1-git-send-email-jun.li@nxp.com> <1621408490-23811-4-git-send-email-jun.li@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1621408490-23811-4-git-send-email-jun.li@nxp.com> Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org On Wed, May 19, 2021 at 03:14:49PM +0800, Li Jun wrote: > Some dedicated mux block can use existing mux controller as a > mux provider, typec port as a consumer to select channel for > orientation switch, this can be an alternate way to current > typec_switch interface. > > Signed-off-by: Li Jun > --- > drivers/usb/typec/class.c | 26 +++++++++++++++++++++++++- > drivers/usb/typec/class.h | 2 ++ > drivers/usb/typec/mux.c | 34 ++++++++++++++++++++++++++++++++++ > include/linux/usb/typec_mux.h | 4 ++++ > 4 files changed, 65 insertions(+), 1 deletion(-) > > diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c > index a29bf2c32233..1bb0275e6204 100644 > --- a/drivers/usb/typec/class.c > +++ b/drivers/usb/typec/class.c > @@ -1601,6 +1601,7 @@ static void typec_release(struct device *dev) > ida_simple_remove(&typec_index_ida, port->id); > ida_destroy(&port->mode_ids); > typec_switch_put(port->sw); > + typec_mux_control_switch_put(port->mux_control_switch); > typec_mux_put(port->mux); > kfree(port->cap); > kfree(port); > @@ -1816,6 +1817,13 @@ int typec_set_orientation(struct typec_port *port, > if (ret) > return ret; > > + if (!port->sw) { > + ret = typec_mux_control_switch_set(port->mux_control_switch, > + port->mux_control_switch_states[orientation]); > + if (ret) > + return ret; > + } > + > port->orientation = orientation; > sysfs_notify(&port->dev.kobj, NULL, "orientation"); > kobject_uevent(&port->dev.kobj, KOBJ_CHANGE); > @@ -1991,7 +1999,7 @@ struct typec_port *typec_register_port(struct device *parent, > const struct typec_capability *cap) > { > struct typec_port *port; > - int ret; > + int ret = 0; > int id; > > port = kzalloc(sizeof(*port), GFP_KERNEL); > @@ -2068,6 +2076,22 @@ struct typec_port *typec_register_port(struct device *parent, > return ERR_PTR(ret); > } > > + if (!port->sw) { > + /* Try to get typec switch via general mux controller */ > + port->mux_control_switch = typec_mux_control_switch_get(&port->dev); > + if (IS_ERR(port->mux_control_switch)) > + ret = PTR_ERR(port->mux_control_switch); > + else if (port->mux_control_switch) > + ret = device_property_read_u32_array(&port->dev, > + "mux-control-switch-states", > + port->mux_control_switch_states, > + 3); > + if (ret) { > + put_device(&port->dev); > + return ERR_PTR(ret); > + } > + } Why not just do that inside fwnode_typec_switch_get() and handle the whole thing in drivers/usb/typec/mux.c (or in its own file if you prefer)? You'll just need to register a "wrapper" Type-C switch object for the OF mux controller, but that should not be a problem. That way you don't need to export any new functions, touch this file or anything else. thanks, -- heikki From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D60DEC433B4 for ; Thu, 20 May 2021 12:35:32 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5F10361184 for ; Thu, 20 May 2021 12:35:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5F10361184 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Jmo9SblkDfuBd9/RWywBwcwZDhCJqw254H6DAvrjgzI=; b=M7md25t9RttdQepGfPDDo8rGI0 iZtU2po1tBzaNOl1f11+wk9hB75z4epGkIKOvReRz6QqdSc3MJaJivDfIUvSt+iLFYKT6CiykPHWQ D4VA4RtMrmXxcbPKtUIJmMZwtiwDBNBAGUFAu1Hv5jn+dN1zjdJoV5xUb4uUw81oEy/eFJfaq79Cz mJB2WK7JE6Yjxnmprw+k5wkAoawaptTPOdGswe8fVm8YNPxtx3Dyjuzz1t6yNcRyGDEQRg4xvcR8n pEMO3Y+OSlLPGu/m9PuRCxhP6rHo11d4E6vvgQZEQxBnTSlJV+P/o1NFWH+9Mpe0byEMi//NPJd0n XnnJbTMw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ljhs4-000pWl-Qf; Thu, 20 May 2021 12:33:49 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ljhrx-000pUo-AC for linux-arm-kernel@desiato.infradead.org; Thu, 20 May 2021 12:33:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=SQ+sFWG2VtxNo5pMo2ygnOZTL0wIhPh6BpuWUKp5TvU=; b=IRPkh7K+WRRwZR83XMNwPps3kJ gF1J2nSkz8XGCEzwwY7AIQc7dDji/hYBJHCTGQoxMlQ/iW+UVBIs9NmJIGeCHlFESGnW4husNOnA1 eAJLna+OS05GIaUshJuA9yqHGBg+4xRj67KS9tJ5QZs0LwPVgfeDJphBSqQhi9xgMo0J4bW2JWvoY h14DuXT5sS9u3rnCcPZFn7VlBItLq4gXltIHXiwdJ39PkoWOKIkMK1Mz8/YXfAQtQqZDWxkjaZ945 5ksIa86dRprsRzxYzEU8zjP3SE6DiZnt931PNcMfRQV8ySY/VUnMhO3KwVv0B/u8T2dHU9l0cSvPE f+gFryPw==; Received: from mga17.intel.com ([192.55.52.151]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1ljhru-00GJzh-Gu for linux-arm-kernel@lists.infradead.org; Thu, 20 May 2021 12:33:39 +0000 IronPort-SDR: 5q+NqDRE9VRm2jM9aFR9sL6u64IPrzcbwk2GcKaPtJOTBqRTFCYyQFfZQAAw9iYAZyre1vl0z0 q/uZxS6wYiag== X-IronPort-AV: E=McAfee;i="6200,9189,9989"; a="181495283" X-IronPort-AV: E=Sophos;i="5.82,313,1613462400"; d="scan'208";a="181495283" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 May 2021 05:33:36 -0700 IronPort-SDR: YPSVAAhCNqWnrl03Khe1at6noFmJbazD2tO2C08UqTvwyl8miudcz6Eae7wNh9YY+h1msFXqt3 MeBj/VRPwjPA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,313,1613462400"; d="scan'208";a="543512173" Received: from kuha.fi.intel.com ([10.237.72.162]) by fmsmga001.fm.intel.com with SMTP; 20 May 2021 05:33:32 -0700 Received: by kuha.fi.intel.com (sSMTP sendmail emulation); Thu, 20 May 2021 15:33:32 +0300 Date: Thu, 20 May 2021 15:33:32 +0300 From: Heikki Krogerus To: Li Jun Cc: robh+dt@kernel.org, shawnguo@kernel.org, gregkh@linuxfoundation.org, linux@roeck-us.net, linux-usb@vger.kernel.org, linux-imx@nxp.com, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH 3/4] usb: typec: add typec orientation switch support via mux controller Message-ID: References: <1621408490-23811-1-git-send-email-jun.li@nxp.com> <1621408490-23811-4-git-send-email-jun.li@nxp.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1621408490-23811-4-git-send-email-jun.li@nxp.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210520_053338_595970_FD65AFF2 X-CRM114-Status: GOOD ( 24.06 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, May 19, 2021 at 03:14:49PM +0800, Li Jun wrote: > Some dedicated mux block can use existing mux controller as a > mux provider, typec port as a consumer to select channel for > orientation switch, this can be an alternate way to current > typec_switch interface. > > Signed-off-by: Li Jun > --- > drivers/usb/typec/class.c | 26 +++++++++++++++++++++++++- > drivers/usb/typec/class.h | 2 ++ > drivers/usb/typec/mux.c | 34 ++++++++++++++++++++++++++++++++++ > include/linux/usb/typec_mux.h | 4 ++++ > 4 files changed, 65 insertions(+), 1 deletion(-) > > diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c > index a29bf2c32233..1bb0275e6204 100644 > --- a/drivers/usb/typec/class.c > +++ b/drivers/usb/typec/class.c > @@ -1601,6 +1601,7 @@ static void typec_release(struct device *dev) > ida_simple_remove(&typec_index_ida, port->id); > ida_destroy(&port->mode_ids); > typec_switch_put(port->sw); > + typec_mux_control_switch_put(port->mux_control_switch); > typec_mux_put(port->mux); > kfree(port->cap); > kfree(port); > @@ -1816,6 +1817,13 @@ int typec_set_orientation(struct typec_port *port, > if (ret) > return ret; > > + if (!port->sw) { > + ret = typec_mux_control_switch_set(port->mux_control_switch, > + port->mux_control_switch_states[orientation]); > + if (ret) > + return ret; > + } > + > port->orientation = orientation; > sysfs_notify(&port->dev.kobj, NULL, "orientation"); > kobject_uevent(&port->dev.kobj, KOBJ_CHANGE); > @@ -1991,7 +1999,7 @@ struct typec_port *typec_register_port(struct device *parent, > const struct typec_capability *cap) > { > struct typec_port *port; > - int ret; > + int ret = 0; > int id; > > port = kzalloc(sizeof(*port), GFP_KERNEL); > @@ -2068,6 +2076,22 @@ struct typec_port *typec_register_port(struct device *parent, > return ERR_PTR(ret); > } > > + if (!port->sw) { > + /* Try to get typec switch via general mux controller */ > + port->mux_control_switch = typec_mux_control_switch_get(&port->dev); > + if (IS_ERR(port->mux_control_switch)) > + ret = PTR_ERR(port->mux_control_switch); > + else if (port->mux_control_switch) > + ret = device_property_read_u32_array(&port->dev, > + "mux-control-switch-states", > + port->mux_control_switch_states, > + 3); > + if (ret) { > + put_device(&port->dev); > + return ERR_PTR(ret); > + } > + } Why not just do that inside fwnode_typec_switch_get() and handle the whole thing in drivers/usb/typec/mux.c (or in its own file if you prefer)? You'll just need to register a "wrapper" Type-C switch object for the OF mux controller, but that should not be a problem. That way you don't need to export any new functions, touch this file or anything else. thanks, -- heikki _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel