Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3503261ybi; Fri, 19 Jul 2019 04:21:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqxpBq9dE+GqeFebAndUxE4rH5YRTVF7g15FxzLfPdVmtzhKDbLM41icv3MFmWqxSzHFa6AL X-Received: by 2002:a17:90a:eb04:: with SMTP id j4mr54356228pjz.103.1563535311167; Fri, 19 Jul 2019 04:21:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563535311; cv=none; d=google.com; s=arc-20160816; b=B/svbDzUhjIpjPA0DxbXY+NohBa/7Wg0pN7tXt1DLRXBcWXiM5bpSIPpBhbC+s8lqh RtxE0+KMSkdIvI/bxP81weSup9Gc3MZ1BtBemAsekMjApjCGPbNm4ergb2m8HYOZnt1D oKkNCmRM2csnEtjoOLgWwIsHHlSmQZiEmiKlczlFAzMvm7XXF3aFbZEtzHyvZnsPD8dH ItofQfcJSWgYzW1T/BDQsV1SFJGY0Auw8bMYbJAj8lypXealgJL9dU+C3fwwNNKn1YaP zkNXgclHbggIk213nWkOF/UfCqZhPUWB4Y5OipHPGoO54cFBH1UjUi32GnmaH1awKcgD DZjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=rrKMARhXT0js/owB+CF7UAVnkqQScuR7hfRSA8xnGfA=; b=U5X9LfjycR6D7kWZiIa5oUTpzMf4SMpA4XmVEkKaZUe92GWvu/vcv3rvJXWa8gvFMn 083q1AmJZnjhINOqNS7trC2LbDJ0I6J7IdsX0WiEh/UpWlt7Hhvl25woqT5B0a7ysjj3 n0tpelqDsrdvRZk83Dfo2l1C6jmDKkrnmYZ18XeDmMoN3WmFYoEKgEMAEHRvoqYdiZ1Z KHd8LBsdk4X7k/6oQ4c3L1TfEY+QOh1zilVV/QBE1V19y3DRYs7ba8ZZtp7gvvmBPgJ4 I7PQI/oz/L9to3S2415zDPWrRjDHZz9PBb7nb7HspMFJnVy5x2B5D1zYtSmincxEl5Ge I7wA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=glqCLQAg; 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=pass (p=NONE sp=NONE dis=NONE) header.from=synopsys.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x139si86690pgx.251.2019.07.19.04.21.35; Fri, 19 Jul 2019 04:21:51 -0700 (PDT) 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; dkim=pass header.i=@synopsys.com header.s=mail header.b=glqCLQAg; 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=pass (p=NONE sp=NONE dis=NONE) header.from=synopsys.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727888AbfGSLTa (ORCPT + 99 others); Fri, 19 Jul 2019 07:19:30 -0400 Received: from smtprelay-out1.synopsys.com ([198.182.61.142]:49644 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726931AbfGSLT3 (ORCPT ); Fri, 19 Jul 2019 07:19:29 -0400 Received: from mailhost.synopsys.com (mdc-mailhost2.synopsys.com [10.225.0.210]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 5F050C1211; Fri, 19 Jul 2019 11:19:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1563535168; bh=ozY6liiCOB5Amv30ZINSKCf5LrlfWFBv/ReyJjaLhQc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:In-Reply-To: References:From; b=glqCLQAgPVlRGhdUj8UaYqexWLu9qKQzme1Lq2/SGUBKkj4sktVhz2gJnvlFQyS/h bMyOgRBU8HntVIGfh6fIR9dvvJWwHRwzXyLnw2Kw+0F94HCIrSuOi6jU2odkxCrHEk QMikzNrsVlpisgHL3Ovp3OJNUWb6XizMLOa+ilaQOijJfVNSiRqJuu3Ej+o++HcpZX L6OL2gOFEFvMPJiUuVPMQ90224Ysf3ggVk/SHpq861NRx9yrHSK0DMQxsqI8uCihBA HvGUPDk2dNxUNVFCp7720mG5uSKxXADhuDxD/wdcycg+YKU8EVaFP73SxLU9moQtxu xJ/KfKyRMUxjw== Received: from de02.synopsys.com (de02.internal.synopsys.com [10.225.17.21]) by mailhost.synopsys.com (Postfix) with ESMTP id 8A899A0057; Fri, 19 Jul 2019 11:19:26 +0000 (UTC) Received: from de02dwia024.internal.synopsys.com (de02dwia024.internal.synopsys.com [10.225.19.81]) by de02.synopsys.com (Postfix) with ESMTP id 0F05C3CA31; Fri, 19 Jul 2019 13:19:26 +0200 (CEST) From: Vitor Soares To: linux-iio@vger.kernel.org, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Cc: lorenzo@kernel.org, gregkh@linuxfoundation.org, rafael@kernel.org, bbrezillon@kernel.org, Joao.Pinto@synopsys.com, Vitor Soares Subject: [PATCH v5 1/2] i3c: move i3c_device_match_id to device.c and export it Date: Fri, 19 Jul 2019 13:19:04 +0200 Message-Id: <40addcc18ac82a3156cd86e153e2b4fc1de2fe54.1563533343.git.vitor.soares@synopsys.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some I3C device drivers need to know which entry matches the i3c_device object passed to the probe function Let's move i3c_device_match_id() to device.c and export it so it can be used by drivers. Signed-off-by: Vitor Soares --- Changes in v5: Add kerneldoc Improve commit message Changes in v4: None Changes in v3: Remove i3c_get_device_id Move i3c_device_match_id from drivers/i3c/master.c to drivers/i3c/device.c Export i3c_device_match_id Changes in v2: move this function to drivers/i3c/device.c drivers/i3c/device.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/i3c/master.c | 45 --------------------------------------- include/linux/i3c/device.h | 4 ++++ 3 files changed, 57 insertions(+), 45 deletions(-) diff --git a/drivers/i3c/device.c b/drivers/i3c/device.c index 69cc040..5349059 100644 --- a/drivers/i3c/device.c +++ b/drivers/i3c/device.c @@ -201,6 +201,59 @@ struct i3c_device *dev_to_i3cdev(struct device *dev) EXPORT_SYMBOL_GPL(dev_to_i3cdev); /** + * i3c_device_match_id() - Returns the I3C device match id in @i3cdev + * @i3cdev: I3C device + * @id_table: I3C device match table + * + * Return: a pointer to I3C device id object. + */ +const struct i3c_device_id * +i3c_device_match_id(struct i3c_device *i3cdev, + const struct i3c_device_id *id_table) +{ + struct i3c_device_info devinfo; + const struct i3c_device_id *id; + + i3c_device_get_info(i3cdev, &devinfo); + + /* + * The lower 32bits of the provisional ID is just filled with a random + * value, try to match using DCR info. + */ + if (!I3C_PID_RND_LOWER_32BITS(devinfo.pid)) { + u16 manuf = I3C_PID_MANUF_ID(devinfo.pid); + u16 part = I3C_PID_PART_ID(devinfo.pid); + u16 ext_info = I3C_PID_EXTRA_INFO(devinfo.pid); + + /* First try to match by manufacturer/part ID. */ + for (id = id_table; id->match_flags != 0; id++) { + if ((id->match_flags & I3C_MATCH_MANUF_AND_PART) != + I3C_MATCH_MANUF_AND_PART) + continue; + + if (manuf != id->manuf_id || part != id->part_id) + continue; + + if ((id->match_flags & I3C_MATCH_EXTRA_INFO) && + ext_info != id->extra_info) + continue; + + return id; + } + } + + /* Fallback to DCR match. */ + for (id = id_table; id->match_flags != 0; id++) { + if ((id->match_flags & I3C_MATCH_DCR) && + id->dcr == devinfo.dcr) + return id; + } + + return NULL; +} +EXPORT_SYMBOL_GPL(i3c_device_match_id); + +/** * i3c_driver_register_with_owner() - register an I3C device driver * * @drv: driver to register diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index 5f4bd52..7667f84 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -270,51 +270,6 @@ static const struct device_type i3c_device_type = { .uevent = i3c_device_uevent, }; -static const struct i3c_device_id * -i3c_device_match_id(struct i3c_device *i3cdev, - const struct i3c_device_id *id_table) -{ - struct i3c_device_info devinfo; - const struct i3c_device_id *id; - - i3c_device_get_info(i3cdev, &devinfo); - - /* - * The lower 32bits of the provisional ID is just filled with a random - * value, try to match using DCR info. - */ - if (!I3C_PID_RND_LOWER_32BITS(devinfo.pid)) { - u16 manuf = I3C_PID_MANUF_ID(devinfo.pid); - u16 part = I3C_PID_PART_ID(devinfo.pid); - u16 ext_info = I3C_PID_EXTRA_INFO(devinfo.pid); - - /* First try to match by manufacturer/part ID. */ - for (id = id_table; id->match_flags != 0; id++) { - if ((id->match_flags & I3C_MATCH_MANUF_AND_PART) != - I3C_MATCH_MANUF_AND_PART) - continue; - - if (manuf != id->manuf_id || part != id->part_id) - continue; - - if ((id->match_flags & I3C_MATCH_EXTRA_INFO) && - ext_info != id->extra_info) - continue; - - return id; - } - } - - /* Fallback to DCR match. */ - for (id = id_table; id->match_flags != 0; id++) { - if ((id->match_flags & I3C_MATCH_DCR) && - id->dcr == devinfo.dcr) - return id; - } - - return NULL; -} - static int i3c_device_match(struct device *dev, struct device_driver *drv) { struct i3c_device *i3cdev; diff --git a/include/linux/i3c/device.h b/include/linux/i3c/device.h index 5ecb055..de102e4 100644 --- a/include/linux/i3c/device.h +++ b/include/linux/i3c/device.h @@ -188,6 +188,10 @@ static inline struct i3c_driver *drv_to_i3cdrv(struct device_driver *drv) struct device *i3cdev_to_dev(struct i3c_device *i3cdev); struct i3c_device *dev_to_i3cdev(struct device *dev); +const struct i3c_device_id * +i3c_device_match_id(struct i3c_device *i3cdev, + const struct i3c_device_id *id_table); + static inline void i3cdev_set_drvdata(struct i3c_device *i3cdev, void *data) { -- 2.7.4