Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4616759rdh; Wed, 29 Nov 2023 06:27:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IHVfChbAHpgRfkziBXWA/gvfeIUX+fRAJ3SMiMMNzQl7oZfMykyif+b2Zw6DHTVoebvHqqh X-Received: by 2002:a17:90a:3fc7:b0:280:37a0:69d4 with SMTP id u7-20020a17090a3fc700b0028037a069d4mr31342768pjm.19.1701268029285; Wed, 29 Nov 2023 06:27:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701268029; cv=none; d=google.com; s=arc-20160816; b=uRulq5o4uQ7WYwQrv4nyP53geLjVSnxn5e9XDJpajMltrjwCYgXl1p7kiWBZXbQ0cG 7zelaE9xCHMR8lMteZRb7GAhEPzDGqbRqJCBibCcUMef8Z6kITYsD2JOX7Hogj9q7SIN AAnNSl1lrdAvrmWjInPSxCF2rSYpPqEJBbxC9dRdWyvWvvSg4yymj/vPAZS5+GFKTm2P Q9fkP02caNkQaQIsOKE59fty9i7G+uQW29/nrKTK6gnqkmH2HcreHD2lHOWHDTf9uZMy bg0h+45Hjv+hk4+4NPPtXH0Zvs+VftguDwThv1vZew9Q9Q0L6JwI9gT0jEirv2Mdbco9 UnTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=iswt40EPhHTffeXaRt+qCVXb20wNcwxnE8y5ags+KXs=; fh=/YCznLxpJrNNHRDw3EUhJ2kNvhE3EVzmzeZ7uormgTs=; b=SQSU8slnYpl2N7Wwss3zCEIqwyoV5nWK/K7CTqJlWyPofurY/XCxlgmqP6HROY8W6Y aG/PBsiPZ3RMbf4nY60aE6sYWZzzOEGdyfYcIfRxEMN3CDHG73D4m4wZH1U5ZJ01+w64 QgEQOFxjkixpLi5BZ4qCe6x1O1VLrHoDjS1JyJ9Z9NBnP0K8nGXzrJrvPTxfhUBYqfK6 5eps06jlfNEHHYg0Cb/sqbfmsIOk1I8Vk6jzCUrIPKRqpy39Uqo/MMHakwwDkO2OdabE rCPc3nGfnALNMWNPbsng+kXyVRsNrVy7zxP41dmubG8icEEks0F3ekqkjwVRqu830t4b jblw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ecoJrFJg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id on7-20020a17090b1d0700b00285b940b290si1485193pjb.190.2023.11.29.06.27.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 06:27:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ecoJrFJg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 9A46F804196D; Wed, 29 Nov 2023 06:27:06 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234305AbjK2O0s (ORCPT + 99 others); Wed, 29 Nov 2023 09:26:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230146AbjK2O0m (ORCPT ); Wed, 29 Nov 2023 09:26:42 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FAA8AF; Wed, 29 Nov 2023 06:26:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701268008; x=1732804008; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=6vU5nIcIA/G5AH3PqLyM/mmU21yIpCzIkpJ6WCyjOrE=; b=ecoJrFJgckEphCpTfLaGYTEdVvOIG1UhBo58f+6XVtFFYOGMyeyWvxBN Hv+3ACHxkvBsvGKq+a/vqwe8U/Lwh0Cc1F6w3SOg+uEGj9o6bsiQx9ap/ lt2jG8ijfEbqOCOjI3IsvQkM71XeBm/Llq532VxtIZsDMWbkkODfPFjKv zNewLunw1d2F9YAfEqFodhmazgF3cnfEPeGyFkE6mg4aXbCgKFKmYdosI WL6s+ijb6540iX236ITZe8hamjU2KXAdYuNr/GtmrZ/4zvojvq/dT/+st g/Fm0dCJ1OhY8IVYCUy2nKREkf84ll4GHzfowTNIKBKkpQDqH7DzvtA62 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10909"; a="373353386" X-IronPort-AV: E=Sophos;i="6.04,235,1695711600"; d="scan'208";a="373353386" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Nov 2023 06:26:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10909"; a="772696789" X-IronPort-AV: E=Sophos;i="6.04,235,1695711600"; d="scan'208";a="772696789" Received: from kuha.fi.intel.com ([10.237.72.185]) by fmsmga007.fm.intel.com with SMTP; 29 Nov 2023 06:26:44 -0800 Received: by kuha.fi.intel.com (sSMTP sendmail emulation); Wed, 29 Nov 2023 16:26:43 +0200 Date: Wed, 29 Nov 2023 16:26:43 +0200 From: Heikki Krogerus To: Alexandru Ardelean Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, gregkh@linuxfoundation.org, rogerq@kernel.org, christophe.jaillet@wanadoo.fr, a-govindraju@ti.com, trix@redhat.com, abdelalkuor@geotab.com Subject: Re: [PATCH] USB: typec: tps6598x: use device 'type' field to identify devices Message-ID: References: <20231123210021.463122-1-alex@shruggie.ro> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231123210021.463122-1-alex@shruggie.ro> X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 29 Nov 2023 06:27:06 -0800 (PST) Hi, Sorry to keep you waiting. On Thu, Nov 23, 2023 at 11:00:21PM +0200, Alexandru Ardelean wrote: > Using the {of_}device_is_compatible function(s) is not too expensive. > But since the driver already needs to match for the 'struct tipd_data' > device parameters (via device_get_match_data()), we can add a simple 'type' > field. > > This adds a minor optimization in certain operations, where we the check > for TPS25750 (or Apple CD321X) is a bit faster. > > Signed-off-by: Alexandru Ardelean > --- > drivers/usb/typec/tipd/core.c | 34 ++++++++++++++++++++++------------ > 1 file changed, 22 insertions(+), 12 deletions(-) > > diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c > index fbd23de5c5cb..69d3e11bb30c 100644 > --- a/drivers/usb/typec/tipd/core.c > +++ b/drivers/usb/typec/tipd/core.c > @@ -105,7 +105,14 @@ static const char *const modes[] = { > > struct tps6598x; > > +enum tipd_type { > + TIPD_TYPE_TI_TPS6598X, > + TIPD_TYPE_APPLE_CD321X, > + TIPD_TYPE_TI_TPS25750X, > +}; > + > struct tipd_data { > + enum tipd_type type; > irq_handler_t irq_handler; > int (*register_port)(struct tps6598x *tps, struct fwnode_handle *node); > void (*trace_power_status)(u16 status); Why not just match against the structures themselves? if (tps->data == &tps25750_data) ... > @@ -1195,7 +1202,6 @@ tps25750_register_port(struct tps6598x *tps, struct fwnode_handle *fwnode) > > static int tps6598x_probe(struct i2c_client *client) > { > - struct device_node *np = client->dev.of_node; > struct tps6598x *tps; > struct fwnode_handle *fwnode; > u32 status; > @@ -1211,11 +1217,19 @@ static int tps6598x_probe(struct i2c_client *client) > mutex_init(&tps->lock); > tps->dev = &client->dev; > > + if (dev_fwnode(tps->dev)) > + tps->data = device_get_match_data(tps->dev); > + else > + tps->data = i2c_get_match_data(client); > + > + if (!tps->data) > + return -EINVAL; > + > tps->regmap = devm_regmap_init_i2c(client, &tps6598x_regmap_config); > if (IS_ERR(tps->regmap)) > return PTR_ERR(tps->regmap); > > - is_tps25750 = device_is_compatible(tps->dev, "ti,tps25750"); > + is_tps25750 = (tps->data->type == TIPD_TYPE_TI_TPS25750X); > if (!is_tps25750) { > ret = tps6598x_read32(tps, TPS_REG_VID, &vid); > if (ret < 0 || !vid) > @@ -1229,7 +1243,7 @@ static int tps6598x_probe(struct i2c_client *client) > if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) > tps->i2c_protocol = true; > > - if (np && of_device_is_compatible(np, "apple,cd321x")) { > + if (tps->data->type == TIPD_TYPE_APPLE_CD321X) { > /* Switch CD321X chips to the correct system power state */ > ret = cd321x_switch_power_state(tps, TPS_SYSTEM_POWER_STATE_S0); > if (ret) > @@ -1247,13 +1261,6 @@ static int tps6598x_probe(struct i2c_client *client) > TPS_REG_INT_PLUG_EVENT; > } > > - if (dev_fwnode(tps->dev)) > - tps->data = device_get_match_data(tps->dev); > - else > - tps->data = i2c_get_match_data(client); > - if (!tps->data) > - return -EINVAL; > - > /* Make sure the controller has application firmware running */ > ret = tps6598x_check_mode(tps); > if (ret < 0) > @@ -1366,7 +1373,7 @@ static void tps6598x_remove(struct i2c_client *client) > usb_role_switch_put(tps->role_sw); > > /* Reset PD controller to remove any applied patch */ > - if (device_is_compatible(tps->dev, "ti,tps25750")) > + if (tps->data->type == TIPD_TYPE_TI_TPS25750X) > tps6598x_exec_cmd_tmo(tps, "GAID", 0, NULL, 0, NULL, 2000, 0); > } > > @@ -1396,7 +1403,7 @@ static int __maybe_unused tps6598x_resume(struct device *dev) > if (ret < 0) > return ret; > > - if (device_is_compatible(tps->dev, "ti,tps25750") && ret == TPS_MODE_PTCH) { > + if (tps->data->type == TIPD_TYPE_TI_TPS25750X && ret == TPS_MODE_PTCH) { > ret = tps25750_init(tps); > if (ret) > return ret; > @@ -1419,6 +1426,7 @@ static const struct dev_pm_ops tps6598x_pm_ops = { > }; > > static const struct tipd_data cd321x_data = { > + .type = TIPD_TYPE_APPLE_CD321X, > .irq_handler = cd321x_interrupt, > .register_port = tps6598x_register_port, > .trace_power_status = trace_tps6598x_power_status, > @@ -1426,6 +1434,7 @@ static const struct tipd_data cd321x_data = { > }; > > static const struct tipd_data tps6598x_data = { > + .type = TIPD_TYPE_TI_TPS6598X, > .irq_handler = tps6598x_interrupt, > .register_port = tps6598x_register_port, > .trace_power_status = trace_tps6598x_power_status, > @@ -1433,6 +1442,7 @@ static const struct tipd_data tps6598x_data = { > }; > > static const struct tipd_data tps25750_data = { > + .type = TIPD_TYPE_TI_TPS25750X, > .irq_handler = tps25750_interrupt, > .register_port = tps25750_register_port, > .trace_power_status = trace_tps25750_power_status, > -- > 2.42.1 thanks, -- heikki