Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp483534rwo; Fri, 21 Jul 2023 15:29:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlFlcA2PQA5P1e60zvQZWZt0M5vBstIgvqDZTkr2SfGV9ZxFj12wX0tthPmi9mhiIjEHEztU X-Received: by 2002:a17:906:10db:b0:993:e860:f20 with SMTP id v27-20020a17090610db00b00993e8600f20mr3045455ejv.19.1689978579419; Fri, 21 Jul 2023 15:29:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689978579; cv=none; d=google.com; s=arc-20160816; b=GA33fqEyo77mVtKiIKMOHRUI0QJlUK42ZF+1SHnZbI6bgl99b2PutigdTSrWfTVoM3 FjoDhI9+sc+j4kgMciRd6Mehg1Bozi6jLS3t4uAOkiYuA2yJVcgQo/8BpVrr92fL6vm3 L55gXAWtqwiOP9mydLpe6KoapwMhJBKBIkRfAs/MlKr0EY76ARzPqOxVD9IC039IYZWC HQteWaQLOhWIe0j+ajAQ5rCcORCud/e5Bny3nkuUoipvdFgC22Wjpv2p2aUaBI/XyuQB EGn3pb4IslwSdAGhqfl0uOwrPb0UeoCDTxOHVwI2EAtfUW9eSUN7dOuYqknLynx3niXF pqRw== 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=pXQ5hDMKSWJDU9uqg2X9Wkd9h1kRn35yH0M0crdOhaU=; fh=Zw31+JlNdrVVyVd0pXtmYndEao3rOlN5JvrGUpe/GPo=; b=0nC0d4BGjCCjtKMqZhigtCIS7TNEl6LnzPqnu75Iw/s87cxuwYQCqOVyg3ew/ydYQn fQapCn3MIZPliHfWb7p91w+d48MfrdjVzmlrEdfOjGx1KICuatKbXeqXlI0hR0Bvj2lY 6pdhheGcNCJaTBqbwsbO3ZjUAEl10aXKEOvLG4bt2lS8eGI33fmT6L8kHJWsjEbW/MLE 6dI9CUT4C34B71tTgeKFSCbS50Y6+B2Qvkleb1AoL4KkOjVYFTuafLbht3YG3t4kuZjB RUZ00zyHaR5G25JhiDb6PFYNh+4mFr1jbGpSiiNnsgOBbOqttoqfEbStgCkSZZjj0Q3j BgSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=g34ViM1C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ss20-20020a170907039400b00992d262ff61si2628840ejb.989.2023.07.21.15.29.15; Fri, 21 Jul 2023 15:29:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=g34ViM1C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229981AbjGUWKK (ORCPT + 99 others); Fri, 21 Jul 2023 18:10:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229945AbjGUWKH (ORCPT ); Fri, 21 Jul 2023 18:10:07 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3046E30CD; Fri, 21 Jul 2023 15:10:06 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1b89b75dc1cso23701265ad.1; Fri, 21 Jul 2023 15:10:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689977405; x=1690582205; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=pXQ5hDMKSWJDU9uqg2X9Wkd9h1kRn35yH0M0crdOhaU=; b=g34ViM1CXFJPjCYZoKRcJrdpHZi+9UkPqbaSslBQDt30H1ol90S1y7sP+EI+VkhEqe 18DiNo4SpRI8WiSidQCHSqPnJIGNnOwbTmq6Ob3KL+rkcAD11d2wegnYOly2amk5Vvto 7SlRhZzsmUlufw2r8InjywH+CylaNw7F2Hp1SNTR0cQagcF58DrzIZh6MCkLYmDtIRBm UztzuAOetSgbSLvMmVudfly+FkMNw9V5Y+70EnEjaeRi1lEVXmDFhc5OqUU08xkMcW6t OqGAEnZiI3WqJnS6ieUSPdyOVFJqIZMrY414wlsr8GEhx96NTIoXZUcU4I34Dbh3/ZA+ WxSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689977405; x=1690582205; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=pXQ5hDMKSWJDU9uqg2X9Wkd9h1kRn35yH0M0crdOhaU=; b=kJ0IE52EV9ugsh5WPUVZKloypA3e3GaR/nJepzBFMcC6O3yqALw3xcR7tO7GE4a6Yz gKryTiTQj0X+XAO6AHCZrrh7p7fs2ERJtr3NtJnD9O0FvYme8IreGYAyCO9soW9xNvkM 8lopZUJolViQ71azVdH2yIDXBd043uH4xE6IidePZ1nAlYxtc2bTq+KvsVnRFZrpeLga J8FB15A3npzI/Kn0HbzBAdF2jgmQaEupJ3sgFSS6MIdkB/q7LCKeP7mk+WwPUzy3IuXu cx4Ws38Sr4gWLhouUO0T25dlbgflP/OYCVFaI4TFFRADFPjObilEA2IVx/pyWJmW6JjT l9Cg== X-Gm-Message-State: ABy/qLZlXOzBEZD05z8kkQZmM9sW9KkwshTjfZP0F3h7kqXBpvYpZYIm 6NOShRElIm+4Y7WnkxE9Lc3ydNpiFEM= X-Received: by 2002:a17:902:f690:b0:1b8:8682:62fb with SMTP id l16-20020a170902f69000b001b8868262fbmr5966360plg.4.1689977405457; Fri, 21 Jul 2023 15:10:05 -0700 (PDT) Received: from google.com ([2620:15c:9d:2:fd88:dbb:fc42:8207]) by smtp.gmail.com with ESMTPSA id e15-20020a17090301cf00b001b9de67285dsm3996910plh.156.2023.07.21.15.10.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jul 2023 15:10:05 -0700 (PDT) Date: Fri, 21 Jul 2023 15:10:02 -0700 From: Dmitry Torokhov To: Biju Das Cc: Mark Brown , Mike Looijmans , Andreas Helbech Kleist , Geert Uytterhoeven , Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= , "linux-input@vger.kernel.org" , Prabhakar Mahadev Lad , "linux-renesas-soc@vger.kernel.org" , Wolfram Sang , Andy Shevchenko , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v2 1/2] Input: exc3000 - Simplify probe() Message-ID: References: <20230717131756.240645-1-biju.das.jz@bp.renesas.com> <20230717131756.240645-2-biju.das.jz@bp.renesas.com> <66228ad3-c087-418c-925f-b9fd4a60fb16@sirena.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,FSL_HELO_FAKE, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 19, 2023 at 06:43:47AM +0000, Biju Das wrote: > Hi Dmitry Torokhov, > > Thanks for the feedback. > > > Subject: Re: [PATCH v2 1/2] Input: exc3000 - Simplify probe() > > > > On Mon, Jul 17, 2023 at 06:45:27PM +0000, Biju Das wrote: > > > Hi Dmitry, > > > > > > > Subject: Re: [PATCH v2 1/2] Input: exc3000 - Simplify probe() > > > > > > > > On Mon, Jul 17, 2023 at 07:15:50PM +0100, Mark Brown wrote: > > > > > On Mon, Jul 17, 2023 at 04:35:02PM +0000, Biju Das wrote: > > > > > > > > > > > The .device_get_match_data callbacks are missing for I2C and SPI > > > > > > bus > > > > subsystems. > > > > > > Can you please throw some lights on this? > > > > > > > > > > It's the first time I've ever heard of that callback, I don't know > > > > > why whoever added it wouldn't have done those buses in particular > > > > > or if it just didn't happen. Try adding it and if it works send > > the patches? > > > > > > > > I think there is a disconnect. Right now device_get_match_data > > > > callbacks are part of fwnode_operations. I was proposing to add > > > > another optional device_get_match_data callback to 'struct bus_type' > > > > to allow individual buses control how match data is handled, before > > > > (or after) jumping into the fwnode-backed device_get_match_data > > callbacks. > > > > > > That is what implemented here [1] and [2] right? > > [1] https://elixir.bootlin.com/linux/v6.5-rc2/source/drivers/spi/spi.c#L364 > > [2] https://elixir.bootlin.com/linux/v6.5-rc2/source/drivers/i2c/i2c-core-base.c#L117 > > > > > > > > > > First it check for fwnode-backed device_get_match_data callbacks and > > > Fallback is bus-type based match. > > > > > > Looks like you are proposing to unify [1] and [2] and you want the > > > logic to be other way around. ie, first bus-type match, then > > > fwnode-backed callbacks? > > > > > > > I do not have a strong preference for the ordering, i.e. I think it is > > perfectly fine to do the generic fwnode-based lookup and if there is no > > match have bus method called as a fallback, > > That involves a bit of work. > > const void *device_get_match_data(const struct device *dev); > > const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id, > const struct i2c_client *client); > > const struct spi_device_id *spi_get_device_id(const struct spi_device *sdev); > > Basically, the bus-client driver(such as exc3000) needs to pass struct device > and device_get_match_data after generic fwnode-based lookup, > needs to find the bus type based on struct device and call a new generic > void* bus_get_match_data(void*) callback, so that each bus interface > can do a match. Yes, something like this (which does not seem that involved to me...): diff --git a/drivers/base/property.c b/drivers/base/property.c index 8c40abed7852..cc0bf7bb6f3a 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -1277,7 +1277,13 @@ EXPORT_SYMBOL(fwnode_graph_parse_endpoint); const void *device_get_match_data(const struct device *dev) { - return fwnode_call_ptr_op(dev_fwnode(dev), device_get_match_data, dev); + const void *data; + + data = fwnode_call_ptr_op(dev_fwnode(dev), device_get_match_data, dev); + if (!data && dev->bus && dev->bus->get_match_data) + data = dev->bus->get_match_data(dev); + + return data; } EXPORT_SYMBOL_GPL(device_get_match_data); diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 60746652fd52..5fe47bc491a6 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -114,6 +114,26 @@ const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id, } EXPORT_SYMBOL_GPL(i2c_match_id); +static const void *i2c_device_get_match_data(const struct device *dev) +{ + const struct i2c_client *client = to_i2c_client(dev); + const struct i2c_driver *driver; + const struct i2c_device_id *match; + + if (!dev->driver) + return NULL; + + driver = to_i2c_driver(dev->driver); + if (!driver) + return NULL; + + match = i2c_match_id(driver->id_table, client); + if (!match) + return NULL; + + return (const void *)match->driver_data; +} + const void *i2c_get_match_data(const struct i2c_client *client) { struct i2c_driver *driver = to_i2c_driver(client->dev.driver); @@ -695,6 +715,7 @@ struct bus_type i2c_bus_type = { .probe = i2c_device_probe, .remove = i2c_device_remove, .shutdown = i2c_device_shutdown, + .get_match_data = i2c_device_get_match_data, }; EXPORT_SYMBOL_GPL(i2c_bus_type); diff --git a/include/linux/device/bus.h b/include/linux/device/bus.h index ae10c4322754..3f2cba28a1af 100644 --- a/include/linux/device/bus.h +++ b/include/linux/device/bus.h @@ -102,6 +102,8 @@ struct bus_type { int (*dma_configure)(struct device *dev); void (*dma_cleanup)(struct device *dev); + const void *(*get_match_data)(const struct device *dev); + const struct dev_pm_ops *pm; const struct iommu_ops *iommu_ops; Thanks. -- Dmitry