Message ID | bb8d7f33c6b9e960d542c3951101587b4ddfaef6.1667750698.git.ang.iglesiasg@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1581881wru; Sun, 6 Nov 2022 08:52:47 -0800 (PST) X-Google-Smtp-Source: AMsMyM65cytK0O+pPyyq1qLniEI5oeCrlAPccFNZFx8MOeQ168AEnLPM58FIwFNc4flHEXXvbVQM X-Received: by 2002:a05:6402:322:b0:463:ba70:42de with SMTP id q2-20020a056402032200b00463ba7042demr29912786edw.380.1667753565074; Sun, 06 Nov 2022 08:52:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667753565; cv=none; d=google.com; s=arc-20160816; b=mc1JbsCffreZDrl5DPmuf6+VCmcuyoaJHB43kkeQt+MFtqyUH2reVnZz3THq+HttQa dHNiguuhyN/mm3Ncq20K5H3pzpXHGGZC9lWfuPoVxAelbc4+ZmAPeazt2wv1rPt0MqnY 5DUBHGXg8trtkJW+nvDUppq/Vh39uivCr8MPVtE1HeLkxxEbGC3oGvTCDw36MvUZIn9S ocRjMGBP4wlJnCTESd8Xa5x9TRat327Swhiy93aBpCCY/Hqe0Qra8vJ79mE8V7KxvGVH KwKuvs8UBgizLiDv1SESL2jISUExHUSnkeHq2PJyUamyolCTcb4MhCDatwL1LPsCPsfE 6FuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mBBnZk9CGHds25bK4AquHJJWU5YRQFIcofoONm9EE0Y=; b=OTjNxrbdfEBU1gNsNC3O5rRx8S7JCabl5bo8K29OyDFSti/OtnexqJrqlqipeBOnFe an1bp6LX4tWfQDldzdJZM9CLMWCIM0Ws/7v9asSveYdYKQsZo0zIZ/WQEpalLJNyXxyG /O7iVyArsxY5a32sXB1M7nr/Ev2FYyd6pPjNpPOOw6J+db4RFE35/8M/RT9q28K9Ei2D qFmlUcSkmdsXA62AzNo4Diw/70E4cOakjtIdx3CyNsQQRJuxG7Nnhh/FHht550KxlqVr r7WEIDvAZoT1zp7g3wz44s9LCPwp+iTrb9Ug29xRhEyW1h5ecNLm3X+9VG5Y23zWe6iv 6BXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=oB2xaw02; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r18-20020a170906551200b007919c624eadsi4653414ejp.522.2022.11.06.08.52.16; Sun, 06 Nov 2022 08:52:45 -0800 (PST) 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=20210112 header.b=oB2xaw02; 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 S230143AbiKFQnF (ORCPT <rfc822;hjfbswb@gmail.com> + 99 others); Sun, 6 Nov 2022 11:43:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230109AbiKFQmx (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 6 Nov 2022 11:42:53 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DDA8B1C8; Sun, 6 Nov 2022 08:42:52 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id t25-20020a1c7719000000b003cfa34ea516so1111294wmi.1; Sun, 06 Nov 2022 08:42:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mBBnZk9CGHds25bK4AquHJJWU5YRQFIcofoONm9EE0Y=; b=oB2xaw02K/qsKo4gQmAc2N2vBGa8XdYAEaZH12L7S7024adpZByZGxjyinfmWAVnDI 1JOhtyhB3pBST1p2+VYs2bywldGyYoLXZZGKbcFQ/ZCXy1H2yDPchMxsrfjiLLXnzp+5 V8Vy0DGQ/B1Gd87KOez+DPwZ3E7vPXR7Jo5GamCrX/8YnKmzQFZ6uzJhE1Bcivv4LuD7 DCKkbIUt5zceJcZNODWaWiofOpSS4ELUOTtCw0vwxl7Dg+p2BDNgoilFbULLbxTps3W3 2AAVfzEML051Bh2ohMpGz5269PdXgFiXr5+IFpz/cqSfW8k3gH2NUp0jPycFb9YtCFa2 DZGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mBBnZk9CGHds25bK4AquHJJWU5YRQFIcofoONm9EE0Y=; b=v8PaxPP+rpNeaLo6FI6ABYzn38BGb490S0/Ohh7tj68IrzPt+jEt6XB4T+UGhGhbvl 2Nee0VfBkkhW8/EVPWx05D05Lc92LtLEnnSp/YmUSbSytSIunIcX7QD3VGc6aLM6XNgg IDZD4eZGJAZEoAC9zHp0SjfKZf9mCN4Ya+Y9WYrVmXsHyzB1Vv/R5t5wBDwOjnen88Xz 1uOStwl8Fwdt16yAiUr5jeSzLHYYdgHP8nr5DgnKHGY608MimH7egYQG451ERGHahpaJ uznPjItZFXP3srHL/gZdJSfNRYv4CyrEEONnx2bgGuU9f2+EOGXnKkoKcDz9f5Zqng5u jizg== X-Gm-Message-State: ACrzQf0Av5XuiS8qfs7dH7BDZSP2lP4j/ZFxHX+J4qHercI159h+mBmU iRMI1pTtg0/RgCGft4O6Msm0YZTwJ+U= X-Received: by 2002:a7b:c4c2:0:b0:3b4:fdc4:6df9 with SMTP id g2-20020a7bc4c2000000b003b4fdc46df9mr29783642wmk.123.1667752970427; Sun, 06 Nov 2022 08:42:50 -0800 (PST) Received: from localhost.localdomain (188.red-83-35-57.dynamicip.rima-tde.net. [83.35.57.188]) by smtp.gmail.com with ESMTPSA id fc15-20020a05600c524f00b003cf57329221sm9930077wmb.14.2022.11.06.08.42.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Nov 2022 08:42:50 -0800 (PST) From: Angel Iglesias <ang.iglesiasg@gmail.com> To: linux-iio@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Angel Iglesias <ang.iglesiasg@gmail.com>, =?utf-8?q?Nuno_S=C3=A1?= <noname.nuno@gmail.com>, Andy Shevchenko <andriy.shevchenko@linux.intel.com>, Jonathan Cameron <jic23@kernel.org>, Wolfram Sang <wsa@kernel.org>, linux-i2c@vger.kernel.org Subject: [PATCH v2 1/2] i2c: core: Introduce i2c_client_get_device_id helper function Date: Sun, 6 Nov 2022 17:42:24 +0100 Message-Id: <bb8d7f33c6b9e960d542c3951101587b4ddfaef6.1667750698.git.ang.iglesiasg@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <cover.1667750698.git.ang.iglesiasg@gmail.com> References: <cover.1667750698.git.ang.iglesiasg@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748766362176481228?= X-GMAIL-MSGID: =?utf-8?q?1748766362176481228?= |
Series |
i2c: core: Introduce i2c_client_get_device_id helper
|
|
Commit Message
Angel Iglesias
Nov. 6, 2022, 4:42 p.m. UTC
Introduces new helper function to aid in .probe_new() refactors. In order to use existing i2c_get_device_id() on the probe callback, the device match table needs to be accessible in that function, which would require bigger refactors in some drivers using the deprecated .probe callback. This issue was discussed in more detail in the IIO mailing list. Link: https://lore.kernel.org/all/20221023132302.911644-11-u.kleine-koenig@pengutronix.de/ Suggested-by: Nuno Sá <noname.nuno@gmail.com> Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Suggested-by: Jonathan Cameron <jic23@kernel.org> Signed-off-by: Angel Iglesias <ang.iglesiasg@gmail.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Comments
On Sun, 6 Nov 2022 17:42:24 +0100 Angel Iglesias <ang.iglesiasg@gmail.com> wrote: > Introduces new helper function to aid in .probe_new() refactors. In order > to use existing i2c_get_device_id() on the probe callback, the device > match table needs to be accessible in that function, which would require > bigger refactors in some drivers using the deprecated .probe callback. > > This issue was discussed in more detail in the IIO mailing list. > > Link: https://lore.kernel.org/all/20221023132302.911644-11-u.kleine-koenig@pengutronix.de/ > Suggested-by: Nuno Sá <noname.nuno@gmail.com> > Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> > Suggested-by: Jonathan Cameron <jic23@kernel.org> > Signed-off-by: Angel Iglesias <ang.iglesiasg@gmail.com> > Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Trivial comment inline - otherwise lgtm Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Thanks, > > diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c > index b4edf10e8fd0..920676e62c22 100644 > --- a/drivers/i2c/i2c-core-base.c > +++ b/drivers/i2c/i2c-core-base.c > @@ -2236,6 +2236,21 @@ int i2c_get_device_id(const struct i2c_client *client, > } > EXPORT_SYMBOL_GPL(i2c_get_device_id); > > +/** > + * i2c_client_get_device_id - get the driver match table entry of a device > + * @client: the device to query. The device must be bound to a driver or > + * the function oopses. Maybe don't state what happens otherwise if something changes to make it instead do something else unfortunate, this comment will need updating. "The device must be bound to a driver." > + * > + * Returns a pointer to the matching entry if found, NULL otherwise. > + */ > +const struct i2c_device_id *i2c_client_get_device_id(const struct i2c_client *client) > +{ > + const struct i2c_driver *drv = to_i2c_driver(client->dev.driver); > + > + return i2c_match_id(drv->id_table, client); > +} > +EXPORT_SYMBOL_GPL(i2c_client_get_device_id); > + > /* ---------------------------------------------------- > * the i2c address scanning function > * Will not work for 10-bit addresses! > diff --git a/include/linux/i2c.h b/include/linux/i2c.h > index f7c49bbdb8a1..d84e0e99f084 100644 > --- a/include/linux/i2c.h > +++ b/include/linux/i2c.h > @@ -189,6 +189,7 @@ s32 i2c_smbus_read_i2c_block_data_or_emulated(const struct i2c_client *client, > u8 *values); > int i2c_get_device_id(const struct i2c_client *client, > struct i2c_device_identity *id); > +const struct i2c_device_id *i2c_client_get_device_id(const struct i2c_client *client); > #endif /* I2C */ > > /**
On Sun, 2022-11-06 at 17:22 +0000, Jonathan Cameron wrote: > On Sun, 6 Nov 2022 17:42:24 +0100 > Angel Iglesias <ang.iglesiasg@gmail.com> wrote: > > > Introduces new helper function to aid in .probe_new() refactors. In order > > to use existing i2c_get_device_id() on the probe callback, the device > > match table needs to be accessible in that function, which would require > > bigger refactors in some drivers using the deprecated .probe callback. > > > > This issue was discussed in more detail in the IIO mailing list. > > > > Link: > > https://lore.kernel.org/all/20221023132302.911644-11-u.kleine-koenig@pengutronix.de/ > > Suggested-by: Nuno Sá <noname.nuno@gmail.com> > > Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> > > Suggested-by: Jonathan Cameron <jic23@kernel.org> > > Signed-off-by: Angel Iglesias <ang.iglesiasg@gmail.com> > > Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> > > Trivial comment inline - otherwise lgtm > Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> > > Thanks, > > > > > diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c > > index b4edf10e8fd0..920676e62c22 100644 > > --- a/drivers/i2c/i2c-core-base.c > > +++ b/drivers/i2c/i2c-core-base.c > > @@ -2236,6 +2236,21 @@ int i2c_get_device_id(const struct i2c_client > > *client, > > } > > EXPORT_SYMBOL_GPL(i2c_get_device_id); > > > > +/** > > + * i2c_client_get_device_id - get the driver match table entry of a device > > + * @client: the device to query. The device must be bound to a driver or > > + * the function oopses. > > Maybe don't state what happens otherwise if something changes to make it > instead do something else unfortunate, this comment will need updating. > "The device must be bound to a driver." Sure, sorry for the trouble. I'll wait a bit for more comments and then send v3 fixed. Thanks for your time, Angel > > > + * > > + * Returns a pointer to the matching entry if found, NULL otherwise. > > + */ > > +const struct i2c_device_id *i2c_client_get_device_id(const struct > > i2c_client *client) > > +{ > > + const struct i2c_driver *drv = to_i2c_driver(client->dev.driver); > > + > > + return i2c_match_id(drv->id_table, client); > > +} > > +EXPORT_SYMBOL_GPL(i2c_client_get_device_id); > > + > > /* ---------------------------------------------------- > > * the i2c address scanning function > > * Will not work for 10-bit addresses! > > diff --git a/include/linux/i2c.h b/include/linux/i2c.h > > index f7c49bbdb8a1..d84e0e99f084 100644 > > --- a/include/linux/i2c.h > > +++ b/include/linux/i2c.h > > @@ -189,6 +189,7 @@ s32 i2c_smbus_read_i2c_block_data_or_emulated(const > > struct i2c_client *client, > > u8 *values); > > int i2c_get_device_id(const struct i2c_client *client, > > struct i2c_device_identity *id); > > +const struct i2c_device_id *i2c_client_get_device_id(const struct > > i2c_client *client); > > #endif /* I2C */ > > > > /** >
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index b4edf10e8fd0..920676e62c22 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -2236,6 +2236,21 @@ int i2c_get_device_id(const struct i2c_client *client, } EXPORT_SYMBOL_GPL(i2c_get_device_id); +/** + * i2c_client_get_device_id - get the driver match table entry of a device + * @client: the device to query. The device must be bound to a driver or + * the function oopses. + * + * Returns a pointer to the matching entry if found, NULL otherwise. + */ +const struct i2c_device_id *i2c_client_get_device_id(const struct i2c_client *client) +{ + const struct i2c_driver *drv = to_i2c_driver(client->dev.driver); + + return i2c_match_id(drv->id_table, client); +} +EXPORT_SYMBOL_GPL(i2c_client_get_device_id); + /* ---------------------------------------------------- * the i2c address scanning function * Will not work for 10-bit addresses! diff --git a/include/linux/i2c.h b/include/linux/i2c.h index f7c49bbdb8a1..d84e0e99f084 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -189,6 +189,7 @@ s32 i2c_smbus_read_i2c_block_data_or_emulated(const struct i2c_client *client, u8 *values); int i2c_get_device_id(const struct i2c_client *client, struct i2c_device_identity *id); +const struct i2c_device_id *i2c_client_get_device_id(const struct i2c_client *client); #endif /* I2C */ /**