From patchwork Wed Feb 19 00:20:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitor Soares X-Patchwork-Id: 11390125 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E4A3E17EF for ; Wed, 19 Feb 2020 00:20:59 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 C236E2465A for ; Wed, 19 Feb 2020 00:20:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="IHnDzdoQ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="D7yEFYsK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C236E2465A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=synopsys.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-i3c-bounces+linux-i3c=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=UqkPPwTAc4jrQDM0KJhyNTsH4SkvmWUG/XR/N/WE2Ig=; b=IHnDzdoQtPISTJoC5ZhfZ7qGzX /4jou/bf0mzHagp4HxEp8S2zTvfTvbmdOXJ5RkcYyx1xo7ACRgpmr68Ry1EtE2Oyhwtx794r1iUBL 3nEJY8oBzXqsexqhBUXRvRI76wLTovbJyhNGEh8XXBZa7whguT92DMOFCbEnQTxJYKvKevkm0WLPq 1IWppaQPVqxxOOKjiFtwTRV8Bw5aTyQfRCezwSXZcnK+WaRe3N1pNeK7L7pWK8e6EyvGCzPpnfzTV vm4bglJe6djO6WPbGRl+lCPvtzXjpN4OlHVJFM3T+arr4jpMYPN7BfYfDc7EC7NCQgCo0y5ptyo0J BvIijTwA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j4D6p-0007bE-17; Wed, 19 Feb 2020 00:20:59 +0000 Received: from us03-smtprelay2.synopsys.com ([149.117.87.133] helo=smtprelay-out1.synopsys.com) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1j4D6l-0007Xd-4i for linux-i3c@lists.infradead.org; Wed, 19 Feb 2020 00:20:57 +0000 Received: from mailhost.synopsys.com (mdc-mailhost1.synopsys.com [10.225.0.209]) (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 1ED66C009F; Wed, 19 Feb 2020 00:20:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1582071650; bh=EWznO/7FCN3HQvpSq9KAAmnQZlA5wLD6bU4uUlvRy1Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:In-Reply-To: References:From; b=D7yEFYsKiCNN/fVOHeWcjILm9RSnalwliFqbs+26c49s6SbQgmtuEzmRAD5AnmmD9 buKLT/6BPv+SlLAjyi85dhWbg5e4/0Q0Ze6TsCIgo8fsdc1UJw5n7MVCI3cwP1W8W4 fj+JkBlc68RbAfa121TfFBVwlTA9Mo2BsH8V7zb/nubkzCznltDxrH7tAJjwLUY7s4 Q/du/CZifju4EeOpDAmOI1rHyJ3Zfp4RNR0hLlhJ/0VCE79NCbaRD8LmE5A24EtJmT aSGf/i8yKBYsL825kgawfp6LTlh9bNsExdmo/CISQZPDJE0FMxm9YU850sn6ER+ojI pWAdZSMDBOhfw== Received: from de02.synopsys.com (germany.internal.synopsys.com [10.225.17.21]) by mailhost.synopsys.com (Postfix) with ESMTP id 1C355A0077; Wed, 19 Feb 2020 00:20:47 +0000 (UTC) Received: from de02dwia024.internal.synopsys.com (de02dwia024.internal.synopsys.com [10.225.19.81]) by de02.synopsys.com (Postfix) with ESMTP id 03ECB3D244; Wed, 19 Feb 2020 01:20:47 +0100 (CET) From: Vitor Soares To: linux-kernel@vger.kernel.org, linux-i3c@lists.infradead.org Subject: [PATCH v3 1/5] i3c: master: export i3c_masterdev_type Date: Wed, 19 Feb 2020 01:20:39 +0100 Message-Id: <7c742fba6c488b29f6fb15a5b910e799d50c5051.1582069402.git.vitor.soares@synopsys.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200218_162055_226460_34C6A650 X-CRM114-Status: GOOD ( 11.82 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux I3C List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jose.Abreu@synopsys.com, corbet@lwn.net, Joao.Pinto@synopsys.com, arnd@arndb.de, wsa@the-dreams.de, gregkh@linuxfoundation.org, bbrezillon@kernel.org, Vitor Soares , broonie@kernel.org MIME-Version: 1.0 Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=patchwork.kernel.org@lists.infradead.org Exporte i3c_masterdev_type so i3cdev module can verify if an i3c device is a master. Signed-off-by: Vitor Soares --- drivers/i3c/internals.h | 1 + drivers/i3c/master.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/i3c/internals.h b/drivers/i3c/internals.h index 86b7b44..bc062e8 100644 --- a/drivers/i3c/internals.h +++ b/drivers/i3c/internals.h @@ -11,6 +11,7 @@ #include extern struct bus_type i3c_bus_type; +extern const struct device_type i3c_masterdev_type; void i3c_bus_normaluse_lock(struct i3c_bus *bus); void i3c_bus_normaluse_unlock(struct i3c_bus *bus); diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index 7f8f896..8a0ba34 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -523,9 +523,10 @@ static void i3c_masterdev_release(struct device *dev) of_node_put(dev->of_node); } -static const struct device_type i3c_masterdev_type = { +const struct device_type i3c_masterdev_type = { .groups = i3c_masterdev_groups, }; +EXPORT_SYMBOL_GPL(i3c_masterdev_type); static int i3c_bus_set_mode(struct i3c_bus *i3cbus, enum i3c_bus_mode mode, unsigned long max_i2c_scl_rate) From patchwork Wed Feb 19 00:20:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitor Soares X-Patchwork-Id: 11390127 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 012C713A4 for ; Wed, 19 Feb 2020 00:21:00 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 D0EEA24677 for ; Wed, 19 Feb 2020 00:20:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="WtwbCxJl"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="K3W9i1XB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D0EEA24677 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=synopsys.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-i3c-bounces+linux-i3c=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=PWsgaLpaotA750bRfU+93AB7mCgCNIHJc6vl2qr9S90=; b=WtwbCxJlNVHW1YvMlW/cxxS1G5 si15218n9OFmJnoOX0iK7iBznaXuLASY3pPuIt+lXwzLFCMets/H595E/yiacbs/uy+V///n3glB5 6cwELMVXywWN7AO6+w3LL/h57yrhGYj/+l5hDbSmCeypiIhVN5y+AfTyxHk/9XW3cTBbyhtCjr405 9VqtJmvGTOaPGzpTs/DZTe6mHlRmDylDzXBuK6FQQtJcS8cnZ8C5QyNhARKPiZHCsOVwmYWXtDJFP k7O89yvneOGwnD8WoQjCxMa6NcokfjfLDhgtFlqolYgMfjBO9xYmlbEQx6XcRMREvxsPLNA40mGQs IYdhtVNg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j4D6p-0007bP-4A; Wed, 19 Feb 2020 00:20:59 +0000 Received: from us03-smtprelay2.synopsys.com ([149.117.87.133] helo=smtprelay-out1.synopsys.com) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1j4D6l-0007Xf-4V for linux-i3c@lists.infradead.org; Wed, 19 Feb 2020 00:20:57 +0000 Received: from mailhost.synopsys.com (mdc-mailhost1.synopsys.com [10.225.0.209]) (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 27B98C00A1; Wed, 19 Feb 2020 00:20:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1582071650; bh=5BSmiW9SFB6AJj8MBxrfazTpkHfyo3zqP3n71iT8md0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:In-Reply-To: References:From; b=K3W9i1XB1w1pVvZU5vgWa2mbXpM1XNjph3+TAupOSd3ZJl69q6UtHUQf4XmEOruDo U4eRU58xBZS0xGrfW8MOmerKnXTbu0oQB2XJas7ACSWB3k/nxQl7XBzncTFTsbG25Q p2ZVtvner1olIMelw3RLkM0D0Zx9XsJNq7O3YLONLJJHAeFFUSszOFsa8JDAdcok9q UTzDne+t5fQaDJZN04c+ZNGTcWPYjcRklHcZcBjMKgh1PvGubVsml3GT18+1ACb3DA gfzIpaViRoMRq05B1psGAWTEPT2/K10tPlroex90nFmUyANCu1usfWYHz6kUXKITZR RVDnDWunA6iXA== Received: from de02.synopsys.com (germany.internal.synopsys.com [10.225.17.21]) by mailhost.synopsys.com (Postfix) with ESMTP id 2778BA005E; Wed, 19 Feb 2020 00:20:47 +0000 (UTC) Received: from de02dwia024.internal.synopsys.com (de02dwia024.internal.synopsys.com [10.225.19.81]) by de02.synopsys.com (Postfix) with ESMTP id 156EC3D248; Wed, 19 Feb 2020 01:20:47 +0100 (CET) From: Vitor Soares To: linux-kernel@vger.kernel.org, linux-i3c@lists.infradead.org Subject: [PATCH v3 2/5] i3c: master: export i3c_bus_type symbol Date: Wed, 19 Feb 2020 01:20:40 +0100 Message-Id: <449db711a8174934e078f90b21c31b683d11da8c.1582069402.git.vitor.soares@synopsys.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200218_162055_212649_F7672E2F X-CRM114-Status: UNSURE ( 9.29 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux I3C List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jose.Abreu@synopsys.com, corbet@lwn.net, Joao.Pinto@synopsys.com, arnd@arndb.de, wsa@the-dreams.de, gregkh@linuxfoundation.org, bbrezillon@kernel.org, Vitor Soares , broonie@kernel.org MIME-Version: 1.0 Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=patchwork.kernel.org@lists.infradead.org Export i3c_bus_type symbol so i3cdev can register a notifier chain for i3c bus. Signed-off-by: Vitor Soares --- drivers/i3c/master.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index 8a0ba34..21c4372 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -321,6 +321,7 @@ struct bus_type i3c_bus_type = { .probe = i3c_device_probe, .remove = i3c_device_remove, }; +EXPORT_SYMBOL_GPL(i3c_bus_type); static enum i3c_addr_slot_status i3c_bus_get_addr_slot_status(struct i3c_bus *bus, u16 addr) From patchwork Wed Feb 19 00:20:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitor Soares X-Patchwork-Id: 11390123 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D2836159A for ; Wed, 19 Feb 2020 00:20:59 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 B09BE24672 for ; Wed, 19 Feb 2020 00:20:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="GPbKKUba"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="Q34BR4Yf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B09BE24672 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=synopsys.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-i3c-bounces+linux-i3c=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=DR+sySk8h6OAu7lpDZYheyklKMqkeX+tQj/1mYL0Dz4=; b=GPbKKUbafG/lOYjhpP8AupSjjR AVp34ToxJox4SXRmm4Car5gXBUqabZ2hIB/TMSssIzFjXUVWz0GodOkFpeOwlMJgLLopyq3G2JLRO DemrRj8yEeeg0Kzd9hUz54BJxbcKO/lxQe+BAF1VW0hQABViGzIIrXWq4SqaZAmtoXnh2wdcsTl6A WCRHHVrmpVD9sfqVr6oureyLl3FMPDmUTF6b8Md66tf/g8y5FGqkjqFLKXrqQiz+aXeaTz+PC/fZ5 KEuV6dCM8qDyWngv8MhPSTO8c8Gzn68ddapzsihSOKew0gL0G5P7rUMiPoPCsTAtJNvPWRRKjBHjT Y34dMn/Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j4D6o-0007b6-UZ; Wed, 19 Feb 2020 00:20:58 +0000 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1j4D6l-0007Xc-4x for linux-i3c@lists.infradead.org; Wed, 19 Feb 2020 00:20:57 +0000 Received: from mailhost.synopsys.com (mdc-mailhost1.synopsys.com [10.225.0.209]) (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 2B208C00A4; Wed, 19 Feb 2020 00:20:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1582071650; bh=49HIPV7UVjMJfo0JxqqaYUaFztMT5Pl+eqcCydvEj0Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:In-Reply-To: References:From; b=Q34BR4YfOfzg0GjdllVRD1JoImwYzmv9qLtGWrY11hQKY0Bawam1oWDCCh6cBRZj4 uIAB1d5Vef/vBRUVnxI1HaS0shoT2T7flSzqvgIWpirFGpSY+SQOp7aiBHA+qMGwL6 rWwZMhSeygkAzFKx+d/F/O0rQ4xG3nnXPDfNGiJmm0mxy1a0cvvJFjGQyWGAXeih/I uVe1CkIjvV8bR9JfO6dt7SmN3O5Lh1g5UseuGvmHadHi9qRmIqBfZKTZVhlnkXaWCt 3sd5gEmYltG0aCy01DrPT1tk2UudkzAFDumGpU5L228peOZk0Lx4DQDQl4ZfazlR4C nqgVbdd2vm/gg== Received: from de02.synopsys.com (de02.internal.synopsys.com [10.225.17.21]) by mailhost.synopsys.com (Postfix) with ESMTP id 3A98BA0079; Wed, 19 Feb 2020 00:20:47 +0000 (UTC) Received: from de02dwia024.internal.synopsys.com (de02dwia024.internal.synopsys.com [10.225.19.81]) by de02.synopsys.com (Postfix) with ESMTP id 26A223D24C; Wed, 19 Feb 2020 01:20:47 +0100 (CET) From: Vitor Soares To: linux-kernel@vger.kernel.org, linux-i3c@lists.infradead.org Subject: [PATCH v3 3/5] i3c: master: add i3c_for_each_dev helper Date: Wed, 19 Feb 2020 01:20:41 +0100 Message-Id: <868e5b37fd817b65e6953ed7279f5063e5fc06c5.1582069402.git.vitor.soares@synopsys.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200218_162055_246621_69675FBF X-CRM114-Status: GOOD ( 10.31 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux I3C List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jose.Abreu@synopsys.com, corbet@lwn.net, Joao.Pinto@synopsys.com, arnd@arndb.de, wsa@the-dreams.de, gregkh@linuxfoundation.org, bbrezillon@kernel.org, Vitor Soares , broonie@kernel.org MIME-Version: 1.0 Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=patchwork.kernel.org@lists.infradead.org Introduce i3c_for_each_dev(), an i3c device iterator for use by i3cdev. Signed-off-by: Vitor Soares Signed-off-by: Vitor Soares --- drivers/i3c/internals.h | 1 + drivers/i3c/master.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/drivers/i3c/internals.h b/drivers/i3c/internals.h index bc062e8..a6deedf 100644 --- a/drivers/i3c/internals.h +++ b/drivers/i3c/internals.h @@ -24,4 +24,5 @@ int i3c_dev_enable_ibi_locked(struct i3c_dev_desc *dev); int i3c_dev_request_ibi_locked(struct i3c_dev_desc *dev, const struct i3c_ibi_setup *req); void i3c_dev_free_ibi_locked(struct i3c_dev_desc *dev); +int i3c_for_each_dev(void *data, int (*fn)(struct device *, void *)); #endif /* I3C_INTERNAL_H */ diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index 21c4372..8e22da2 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -2640,6 +2640,18 @@ void i3c_dev_free_ibi_locked(struct i3c_dev_desc *dev) dev->ibi = NULL; } +int i3c_for_each_dev(void *data, int (*fn)(struct device *, void *)) +{ + int res; + + mutex_lock(&i3c_core_lock); + res = bus_for_each_dev(&i3c_bus_type, NULL, data, fn); + mutex_unlock(&i3c_core_lock); + + return res; +} +EXPORT_SYMBOL_GPL(i3c_for_each_dev); + static int __init i3c_init(void) { return bus_register(&i3c_bus_type); From patchwork Wed Feb 19 00:20:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitor Soares X-Patchwork-Id: 11390131 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4661A17F0 for ; Wed, 19 Feb 2020 00:21:00 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 224742465A for ; Wed, 19 Feb 2020 00:21:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="HGjNqlUe"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="H7FNTi3b" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 224742465A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=synopsys.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-i3c-bounces+linux-i3c=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=iEiVlvSb8MUnJHvPAOg1f5y0MJDa3J3EAtBGFewdO/A=; b=HGjNqlUeRSQTy2hI1YfqJMx9Qx gvsvJNIuIR14LqXpVmWfmVRSgH5JXoB+yTTFzLY2nZ/y7lORI4AHl3KVgOcoBkwjfU5jG76LyLPEQ wL2ovDeS7YFbIa0qdxDwlCQbgznRlphbNO3Jd5yzUmxUVPILtukjgkfGlBz3AGQi8rhIKIA3gFroE DQmBeFtYF2+7WxES4U9LGYfERNe5nJSO6r4L97490/2HLLmFfkns6db34oqgv1VFsuoilgQg1zBDX vm1XNScwxLVGHVZk+KJiBK//bAwcMhK8XheJUtqyezOPVFPV6h3E4eb+VgYGCf0lp8sRmHa1C2ona Vn8INsmg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j4D6p-0007bs-CG; Wed, 19 Feb 2020 00:20:59 +0000 Received: from us03-smtprelay2.synopsys.com ([149.117.87.133] helo=smtprelay-out1.synopsys.com) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1j4D6k-0007Xh-Fi for linux-i3c@lists.infradead.org; Wed, 19 Feb 2020 00:20:57 +0000 Received: from mailhost.synopsys.com (mdc-mailhost1.synopsys.com [10.225.0.209]) (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 1E5BDC009E; Wed, 19 Feb 2020 00:20:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1582071650; bh=q0mOux0YTylyNFWh/bIJlHYc47b9ESSYqZ+vR2TUk7A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:In-Reply-To: References:From; b=H7FNTi3brnMFzcl2CZgjZvXX+zexB5jsUvVlaPs0dtKiSGVc93kt8L/TGAy7+wdhP YUZr/d/DWQuDwgBj4L8F/YVI51/Frh4m3qk9N9MgVXL7851V361NucwJqQbr9wp+ie +jCFMTp0ImLlCIiJHcqPQM1jlXJrw8bbPaSA8t750XvO1vPhRQ9DIOixktTyNgDwyr lIcg8kAhXUbXtSK29WJl4Rpd5iIsuD1V6RlDcyNC6zHmrn8YU8YEMAvZ0ImHzfRDK4 n/xLQEUXhNGIUskXM5HyxfxTD6/JMyRN0Cx59N0zpdiF6UKs/Pe+RukkO/UYnzJgPW 5JWMWdJ37VDRQ== Received: from de02.synopsys.com (de02.internal.synopsys.com [10.225.17.21]) by mailhost.synopsys.com (Postfix) with ESMTP id 5232DA007C; Wed, 19 Feb 2020 00:20:47 +0000 (UTC) Received: from de02dwia024.internal.synopsys.com (de02dwia024.internal.synopsys.com [10.225.19.81]) by de02.synopsys.com (Postfix) with ESMTP id 37D773D250; Wed, 19 Feb 2020 01:20:47 +0100 (CET) From: Vitor Soares To: linux-kernel@vger.kernel.org, linux-i3c@lists.infradead.org Subject: [PATCH v3 4/5] i3c: add i3cdev module to expose i3c dev in /dev Date: Wed, 19 Feb 2020 01:20:42 +0100 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200218_162054_596094_4D082F70 X-CRM114-Status: GOOD ( 26.12 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux I3C List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jose.Abreu@synopsys.com, corbet@lwn.net, Joao.Pinto@synopsys.com, arnd@arndb.de, wsa@the-dreams.de, gregkh@linuxfoundation.org, bbrezillon@kernel.org, Vitor Soares , broonie@kernel.org MIME-Version: 1.0 Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=patchwork.kernel.org@lists.infradead.org This patch adds user mode support to I3C SDR transfers. The module is based on i2c-dev.c with the follow features: - expose on /dev the i3c devices dynamically based on if they have a device driver bound. - Dynamically allocate the char device Major number. Signed-off-by: Vitor Soares --- Changes in v3: Use the xfer_lock to prevent device detach during ioctl call Expose i3cdev under /dev/bus/i3c/ folder like usb does Change NOTIFY_BOUND to NOTIFY_BIND, this allows the device detach occur before driver->probe Avoid use of IS_ERR_OR_NULL Use u64_to_user_ptr instead of (void __user *)(uintptr_t) cast Allocate k_xfer and data_ptrs at once to eliminate duble allocation check Pass i3cdev to dev->driver_data Make all minors available Changes in v2: Use IDR api for minor numbering Modify ioctl struct Fix SPDX license drivers/i3c/Kconfig | 15 ++ drivers/i3c/Makefile | 1 + drivers/i3c/i3cdev.c | 429 ++++++++++++++++++++++++++++++++++++++++ include/uapi/linux/i3c/i3cdev.h | 38 ++++ 4 files changed, 483 insertions(+) create mode 100644 drivers/i3c/i3cdev.c create mode 100644 include/uapi/linux/i3c/i3cdev.h diff --git a/drivers/i3c/Kconfig b/drivers/i3c/Kconfig index 30a4415..0164276 100644 --- a/drivers/i3c/Kconfig +++ b/drivers/i3c/Kconfig @@ -20,5 +20,20 @@ menuconfig I3C will be called i3c. if I3C + +config I3CDEV + tristate "I3C device interface" + depends on I3C + help + Say Y here to use i3c-* device files, usually found in the /dev + directory on your system. They make it possible to have user-space + programs use the I3C devices. + + This support is also available as a module. If so, the module + will be called i3cdev. + + Note that this application programming interface is EXPERIMENTAL + and hence SUBJECT TO CHANGE WITHOUT NOTICE while it stabilizes. + source "drivers/i3c/master/Kconfig" endif # I3C diff --git a/drivers/i3c/Makefile b/drivers/i3c/Makefile index 11982ef..606d422 100644 --- a/drivers/i3c/Makefile +++ b/drivers/i3c/Makefile @@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 i3c-y := device.o master.o obj-$(CONFIG_I3C) += i3c.o +obj-$(CONFIG_I3CDEV) += i3cdev.o obj-$(CONFIG_I3C) += master/ diff --git a/drivers/i3c/i3cdev.c b/drivers/i3c/i3cdev.c new file mode 100644 index 0000000..1a6bd35 --- /dev/null +++ b/drivers/i3c/i3cdev.c @@ -0,0 +1,429 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2020 Synopsys, Inc. and/or its affiliates. + * + * Author: Vitor Soares + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "internals.h" + +struct i3cdev_data { + struct i3c_device *i3c; + struct device *dev; + struct mutex xfer_lock; /* prevent detach while transferring */ + struct cdev cdev; + int id; +}; + +static DEFINE_IDA(i3cdev_ida); +static dev_t i3cdev_number; +#define I3C_MINORS (MINORMASK + 1) + +static struct i3cdev_data *get_free_i3cdev(struct i3c_device *i3c) +{ + struct i3cdev_data *i3cdev; + int id; + + id = ida_simple_get(&i3cdev_ida, 0, I3C_MINORS, GFP_KERNEL); + if (id < 0) { + pr_err("i3cdev: no minor number available!\n"); + return ERR_PTR(id); + } + + i3cdev = kzalloc(sizeof(*i3cdev), GFP_KERNEL); + if (!i3cdev) { + ida_simple_remove(&i3cdev_ida, id); + return ERR_PTR(-ENOMEM); + } + + i3cdev->i3c = i3c; + i3cdev->id = id; + i3cdev_set_drvdata(i3c, i3cdev); + + return i3cdev; +} + +static void put_i3cdev(struct i3cdev_data *i3cdev) +{ + i3cdev_set_drvdata(i3cdev->i3c, NULL); + kfree(i3cdev); +} + +static ssize_t +i3cdev_read(struct file *file, char __user *buf, size_t count, loff_t *f_pos) +{ + struct i3cdev_data *i3cdev = file->private_data; + struct i3c_device *i3c = i3cdev->i3c; + struct i3c_priv_xfer xfers = { + .rnw = true, + .len = count, + }; + int ret = -EACCES; + char *tmp; + + mutex_lock(&i3cdev->xfer_lock); + if (i3c->dev.driver) + goto err_out; + + tmp = kzalloc(count, GFP_KERNEL); + if (!tmp) + return -ENOMEM; + + xfers.data.in = tmp; + + dev_dbg(&i3c->dev, "Reading %zu bytes.\n", count); + + ret = i3c_device_do_priv_xfers(i3c, &xfers, 1); + if (!ret) + ret = copy_to_user(buf, tmp, xfers.len) ? -EFAULT : xfers.len; + + kfree(tmp); + +err_out: + mutex_unlock(&i3cdev->xfer_lock); + return ret; +} + +static ssize_t +i3cdev_write(struct file *file, const char __user *buf, size_t count, + loff_t *f_pos) +{ + struct i3cdev_data *i3cdev = file->private_data; + struct i3c_device *i3c = i3cdev->i3c; + struct i3c_priv_xfer xfers = { + .rnw = false, + .len = count, + }; + int ret = -EACCES; + char *tmp; + + mutex_lock(&i3cdev->xfer_lock); + if (i3c->dev.driver) + goto err_out; + + tmp = memdup_user(buf, count); + if (IS_ERR(tmp)) + return PTR_ERR(tmp); + + xfers.data.out = tmp; + + dev_dbg(&i3c->dev, "Writing %zu bytes.\n", count); + + ret = i3c_device_do_priv_xfers(i3c, &xfers, 1); + kfree(tmp); + +err_out: + mutex_unlock(&i3cdev->xfer_lock); + return (!ret) ? count : ret; +} + +static int +i3cdev_do_priv_xfer(struct i3c_device *dev, struct i3c_ioc_priv_xfer *xfers, + unsigned int nxfers) +{ + struct i3c_priv_xfer *k_xfers; + u8 **data_ptrs; + int i, ret = 0; + + /* Since we have nxfers we may allocate k_xfer + *data_ptrs together */ + k_xfers = kcalloc(nxfers, sizeof(*k_xfers) + sizeof(*data_ptrs), + GFP_KERNEL); + if (!k_xfers) + return -ENOMEM; + + /* set data_ptrs to be after nxfers * i3c_priv_xfer */ + data_ptrs = (void *)k_xfers + (nxfers * sizeof(*k_xfers)); + + for (i = 0; i < nxfers; i++) { + data_ptrs[i] = memdup_user((const u8 __user *) + (uintptr_t)xfers[i].data, + xfers[i].len); + if (IS_ERR(data_ptrs[i])) { + ret = PTR_ERR(data_ptrs[i]); + break; + } + + k_xfers[i].len = xfers[i].len; + if (xfers[i].rnw) { + k_xfers[i].rnw = true; + k_xfers[i].data.in = data_ptrs[i]; + } else { + k_xfers[i].rnw = false; + k_xfers[i].data.out = data_ptrs[i]; + } + } + + if (ret < 0) { + i--; + goto err_free_mem; + } + + ret = i3c_device_do_priv_xfers(dev, k_xfers, nxfers); + if (ret) + goto err_free_mem; + + for (i = 0; i < nxfers; i++) { + if (xfers[i].rnw) { + if (copy_to_user(u64_to_user_ptr(xfers[i].data), + data_ptrs[i], xfers[i].len)) + ret = -EFAULT; + } + } + +err_free_mem: + for (; i >= 0; i--) + kfree(data_ptrs[i]); + kfree(k_xfers); + return ret; +} + +static struct i3c_ioc_priv_xfer * +i3cdev_get_ioc_priv_xfer(unsigned int cmd, struct i3c_ioc_priv_xfer *u_xfers, + unsigned int *nxfers) +{ + u32 tmp = _IOC_SIZE(cmd); + + if ((tmp % sizeof(struct i3c_ioc_priv_xfer)) != 0) + return ERR_PTR(-EINVAL); + + *nxfers = tmp / sizeof(struct i3c_ioc_priv_xfer); + if (*nxfers == 0) + return ERR_PTR(-EINVAL); + + return memdup_user(u_xfers, tmp); +} + +static int +i3cdev_ioc_priv_xfer(struct i3c_device *i3c, unsigned int cmd, + struct i3c_ioc_priv_xfer *u_xfers) +{ + struct i3c_ioc_priv_xfer *k_xfers; + unsigned int nxfers; + int ret; + + k_xfers = i3cdev_get_ioc_priv_xfer(cmd, u_xfers, &nxfers); + if (IS_ERR(k_xfers)) + return PTR_ERR(k_xfers); + + ret = i3cdev_do_priv_xfer(i3c, k_xfers, nxfers); + + kfree(k_xfers); + + return ret; +} + +static long +i3cdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) +{ + struct i3cdev_data *i3cdev = file->private_data; + struct i3c_device *i3c = i3cdev->i3c; + int ret = -EACCES; + + dev_dbg(&i3c->dev, "ioctl, cmd=0x%02x, arg=0x%02lx\n", cmd, arg); + + if (_IOC_TYPE(cmd) != I3C_DEV_IOC_MAGIC) + return -ENOTTY; + + /* Use the xfer_lock to prevent device detach during ioctl call */ + mutex_lock(&i3cdev->xfer_lock); + if (i3c->dev.driver) + goto err_no_dev; + + /* Check command number and direction */ + if (_IOC_NR(cmd) == _IOC_NR(I3C_IOC_PRIV_XFER(0)) && + _IOC_DIR(cmd) == (_IOC_READ | _IOC_WRITE)) + ret = i3cdev_ioc_priv_xfer(i3c, cmd, + (struct i3c_ioc_priv_xfer __user *)arg); + +err_no_dev: + mutex_unlock(&i3cdev->xfer_lock); + return ret; +} + +static int i3cdev_open(struct inode *inode, struct file *file) +{ + struct i3cdev_data *i3cdev = container_of(inode->i_cdev, + struct i3cdev_data, + cdev); + file->private_data = i3cdev; + + return 0; +} + +static int i3cdev_release(struct inode *inode, struct file *file) +{ + file->private_data = NULL; + + return 0; +} + +static const struct file_operations i3cdev_fops = { + .owner = THIS_MODULE, + .read = i3cdev_read, + .write = i3cdev_write, + .unlocked_ioctl = i3cdev_ioctl, + .compat_ioctl = compat_ptr_ioctl, + .open = i3cdev_open, + .release = i3cdev_release, +}; + +/* ------------------------------------------------------------------------- */ + +static struct class *i3cdev_class; + +static int i3cdev_attach(struct device *dev, void *dummy) +{ + struct i3cdev_data *i3cdev; + struct i3c_device *i3c; + int res; + + if (dev->type == &i3c_masterdev_type || dev->driver) + return 0; + + i3c = dev_to_i3cdev(dev); + + /* Get a device */ + i3cdev = get_free_i3cdev(i3c); + if (IS_ERR(i3cdev)) + return PTR_ERR(i3cdev); + + mutex_init(&i3cdev->xfer_lock); + cdev_init(&i3cdev->cdev, &i3cdev_fops); + i3cdev->cdev.owner = THIS_MODULE; + res = cdev_add(&i3cdev->cdev, + MKDEV(MAJOR(i3cdev_number), i3cdev->id), 1); + if (res) + goto error_cdev; + + /* register this i3c device with the driver core */ + i3cdev->dev = device_create(i3cdev_class, &i3c->dev, + MKDEV(MAJOR(i3cdev_number), i3cdev->id), + NULL, "bus!i3c!%s", dev_name(&i3c->dev)); + if (IS_ERR(i3cdev->dev)) { + res = PTR_ERR(i3cdev->dev); + goto error; + } + pr_debug("i3cdev: I3C device [%s] registered as minor %d\n", + dev_name(&i3c->dev), i3cdev->id); + return 0; + +error: + cdev_del(&i3cdev->cdev); +error_cdev: + put_i3cdev(i3cdev); + return res; +} + +static int i3cdev_detach(struct device *dev, void *dummy) +{ + struct i3cdev_data *i3cdev; + struct i3c_device *i3c; + + if (dev->type == &i3c_masterdev_type) + return 0; + + i3c = dev_to_i3cdev(dev); + + i3cdev = i3cdev_get_drvdata(i3c); + if (!i3cdev) + return 0; + + /* Prevent transfers while cdev removal */ + mutex_lock(&i3cdev->xfer_lock); + cdev_del(&i3cdev->cdev); + device_destroy(i3cdev_class, MKDEV(MAJOR(i3cdev_number), i3cdev->id)); + mutex_unlock(&i3cdev->xfer_lock); + + ida_simple_remove(&i3cdev_ida, i3cdev->id); + put_i3cdev(i3cdev); + + pr_debug("i3cdev: device [%s] unregistered\n", dev_name(&i3c->dev)); + + return 0; +} + +static int i3cdev_notifier_call(struct notifier_block *nb, + unsigned long action, + void *data) +{ + struct device *dev = data; + + switch (action) { + case BUS_NOTIFY_ADD_DEVICE: + case BUS_NOTIFY_UNBOUND_DRIVER: + return i3cdev_attach(dev, NULL); + case BUS_NOTIFY_DEL_DEVICE: + case BUS_NOTIFY_BIND_DRIVER: + return i3cdev_detach(dev, NULL); + } + + return 0; +} + +static struct notifier_block i3cdev_notifier = { + .notifier_call = i3cdev_notifier_call, +}; + +static int __init i3cdev_init(void) +{ + int res; + + /* Dynamically request unused major number */ + res = alloc_chrdev_region(&i3cdev_number, 0, I3C_MINORS, "i3c"); + if (res) + goto out; + + /* Create a classe to populate sysfs entries*/ + i3cdev_class = class_create(THIS_MODULE, "i3cdev"); + if (IS_ERR(i3cdev_class)) { + res = PTR_ERR(i3cdev_class); + goto out_unreg_chrdev; + } + + /* Keep track of busses which have devices to add or remove later */ + res = bus_register_notifier(&i3c_bus_type, &i3cdev_notifier); + if (res) + goto out_unreg_class; + + /* Bind to already existing device without driver right away */ + i3c_for_each_dev(NULL, i3cdev_attach); + + return 0; + +out_unreg_class: + class_destroy(i3cdev_class); +out_unreg_chrdev: + unregister_chrdev_region(i3cdev_number, I3C_MINORS); +out: + pr_err("%s: Driver Initialisation failed\n", __FILE__); + return res; +} + +static void __exit i3cdev_exit(void) +{ + bus_unregister_notifier(&i3c_bus_type, &i3cdev_notifier); + i3c_for_each_dev(NULL, i3cdev_detach); + class_destroy(i3cdev_class); + unregister_chrdev_region(i3cdev_number, I3C_MINORS); +} + +MODULE_AUTHOR("Vitor Soares "); +MODULE_DESCRIPTION("I3C /dev entries driver"); +MODULE_LICENSE("GPL"); + +module_init(i3cdev_init); +module_exit(i3cdev_exit); diff --git a/include/uapi/linux/i3c/i3cdev.h b/include/uapi/linux/i3c/i3cdev.h new file mode 100644 index 0000000..656a686 --- /dev/null +++ b/include/uapi/linux/i3c/i3cdev.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * Copyright (c) 2020 Synopsys, Inc. and/or its affiliates. + * + * Author: Vitor Soares + */ + +#ifndef _UAPI_I3C_DEV_H_ +#define _UAPI_I3C_DEV_H_ + +#include +#include + +/* IOCTL commands */ +#define I3C_DEV_IOC_MAGIC 0x07 + +/** + * struct i3c_ioc_priv_xfer - I3C SDR ioctl private transfer + * @data: Holds pointer to userspace buffer with transmit data. + * @len: Length of data buffer buffers, in bytes. + * @rnw: encodes the transfer direction. true for a read, false for a write + */ +struct i3c_ioc_priv_xfer { + __u64 data; + __u16 len; + __u8 rnw; + __u8 pad[5]; +}; + +#define I3C_PRIV_XFER_SIZE(N) \ + ((((sizeof(struct i3c_ioc_priv_xfer)) * (N)) < (1 << _IOC_SIZEBITS)) \ + ? ((sizeof(struct i3c_ioc_priv_xfer)) * (N)) : 0) + +#define I3C_IOC_PRIV_XFER(N) \ + _IOC(_IOC_READ|_IOC_WRITE, I3C_DEV_IOC_MAGIC, 30, I3C_PRIV_XFER_SIZE(N)) + +#endif From patchwork Wed Feb 19 00:20:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitor Soares X-Patchwork-Id: 11390121 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 10F5C159A for ; Wed, 19 Feb 2020 00:20:58 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 E04BD2465A for ; Wed, 19 Feb 2020 00:20:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="thUMOaWx"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="f/+P0S8V" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E04BD2465A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=synopsys.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-i3c-bounces+linux-i3c=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=xmYg+z514CwJySpnluO3kqCQeJ4G3MaD/SYjG4SHSkI=; b=thUMOaWxBHJl/C/NKVcmDhzH3F u3A9O8dXqyGpimIP8TZnr9EvtGc1LafJ0b/xmwuzE9FHcxXOCe3VoxL6dNin7GwsY7IXHTeyIfcG9 uvOGJNOqLe5T7+sb2bhbm8RRMA/xdHO/dBJnXNSZcHJvOtesqLhJ01ENyv9NT3+f5XIDKGAy/6b+1 9khDgZ5Z1rCVDDcrszKFwd3LONjV+I00jvTcUS25JVrasD/syyUoT+SHIBDs+Oh3J70Cn0Pg7U/Ys hGdYMdGHe3OVU1lgswDqv2XFjsTG0KPOQJMIeawFOa35ivGNgcJ+Dg84aqXWAf17T63YPZNbIpoN9 czOx5Ttg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j4D6m-0007aE-Ro; Wed, 19 Feb 2020 00:20:56 +0000 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1j4D6k-0007Xg-Fv for linux-i3c@lists.infradead.org; Wed, 19 Feb 2020 00:20:55 +0000 Received: from mailhost.synopsys.com (mdc-mailhost1.synopsys.com [10.225.0.209]) (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 23916C00A0; Wed, 19 Feb 2020 00:20:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1582071650; bh=wRaHT6OlsAkBw+1g6iSX8HH400srvvpxsxuJTkRgCvg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:In-Reply-To: References:From; b=f/+P0S8VgEGpfYNSAGkhdi19uDzy08MkSLKyxwHR5cSMOUixTc9U1Jc15m92Jyaeb CBDUV+rzIdoNjxPH9zaX90K64a3vqKn2b6nMWa02Y4FUxUl6oC92XHTysFCFfkHs7K uvkoP+Dw86Hn8AEINxMQk4aerrujUXyJVgAD3kPLWl7QyXiT9xHWeBH4J1dS//jZSr QxvwuywjPYhG7sKbgIETQTv/VPB6SimRr3BSlseH4NBxFg8+Oeds/Y+rOIupCkjHlN e92W7kYmJXfutNVgq5yxedN6BIiJnx0eG48Fp/ZVRfDGSqmcD5IcFX+fMmyaF5No3O 2Y+XkrXl3cmhA== Received: from de02.synopsys.com (de02.internal.synopsys.com [10.225.17.21]) by mailhost.synopsys.com (Postfix) with ESMTP id 9EA83A007D; Wed, 19 Feb 2020 00:20:47 +0000 (UTC) Received: from de02dwia024.internal.synopsys.com (de02dwia024.internal.synopsys.com [10.225.19.81]) by de02.synopsys.com (Postfix) with ESMTP id 4FFBC3D255; Wed, 19 Feb 2020 01:20:47 +0100 (CET) From: Vitor Soares To: linux-kernel@vger.kernel.org, linux-i3c@lists.infradead.org Subject: [PATCH v3 5/5] add i3cdev documentation Date: Wed, 19 Feb 2020 01:20:43 +0100 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200218_162054_592874_C1333C00 X-CRM114-Status: GOOD ( 18.60 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux I3C List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jose.Abreu@synopsys.com, corbet@lwn.net, Joao.Pinto@synopsys.com, arnd@arndb.de, wsa@the-dreams.de, gregkh@linuxfoundation.org, bbrezillon@kernel.org, Vitor Soares , broonie@kernel.org MIME-Version: 1.0 Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=patchwork.kernel.org@lists.infradead.org This patch add documentation for the userspace API of i3cdev module. Signed-off-by: Vitor Soares --- Documentation/userspace-api/i3c/i3cdev.rst | 116 +++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 Documentation/userspace-api/i3c/i3cdev.rst diff --git a/Documentation/userspace-api/i3c/i3cdev.rst b/Documentation/userspace-api/i3c/i3cdev.rst new file mode 100644 index 0000000..ada269f --- /dev/null +++ b/Documentation/userspace-api/i3c/i3cdev.rst @@ -0,0 +1,116 @@ +==================== +I3C Device Interface +==================== + +I3C devices have the flexibility of being accessed from userspace, as well +through the conventional use of kernel drivers. Userspace access, although +limited to private SDR I3C transfers, provides the advantage of simplifying +the implementation of straightforward communication protocols, applicable to +scenarios where transfers are dedicated such for sensor bring-up scenarios +(prototyping environments) or for microcontroller slave communication +implementation. + +The major device number is dynamically attributed and it's all reserved for +the i3c devices. By default, the i3cdev module only exposes the i3c devices +without device driver bind and aren't of master type in sort of character +device file under /dev/bus/i3c/ folder. They are identified through its +- same way they can be found in /sys/bus/i3c/devices/. +:: + +# ls -l /dev/bus/i3c/ +total 0 +crw------- 1 root root 248, 0 Jan 1 00:22 0-6072303904d2 +crw------- 1 root root 248, 1 Jan 1 00:22 0-b7405ba00929 + +The simplest way to use this interface is to not have an I3C device bound to +a kernel driver, this can be achieved by not have the kernel driver loaded or +using the Sysfs to unbind the kernel driver from the device. + +BASIC CHARACTER DEVICE API +=============================== +For now, the API has only support private SDR read and write transfers. +Those transaction can be achieved by the following: + +``read(file, buffer, sizeof(buffer))`` + The standard read() operation will work as a simple transaction of private + SDR read data followed a stop. + Return the number of bytes read on success, and a negative error otherwise. + +``write(file, buffer, sizeof(buffer))`` + The standard write() operation will work as a simple transaction of private + SDR write data followed a stop. + Return the number of bytes written on success, and a negative error otherwise. + +``ioctl(file, I3C_IOC_PRIV_XFER(nxfers), struct i3c_ioc_priv_xfer *xfers)`` + It combines read/write transactions without a stop in between. + Return 0 on success, and a negative error otherwise. + +NOTES: + - According to the MIPI I3C Protocol is the I3C slave that terminates the read + transaction otherwise Master can abort early on ninth (T) data bit of each + SDR data word. + + - Normal open() and close() operations on /dev/bus/i3c/- + files work as you would expect. + + - As documented in cdev_del() if a device was already open during + i3cdev_detach, the read(), write() and ioctl() fops will still be callable + yet they will return -EACCES. + +C EXAMPLE +========= +Working with I3C devices is much like working with files. You will need to open +a file descriptor, do some I/O operations with it, and then close it. + +The following header files should be included in an I3C program:: + +#include +#include +#include +#include +#include + +To work with an I3C device, the application must open the driver, made +available at the device node:: + + int file; + + file = open("/dev/bus/i3c/0-6072303904d2", O_RDWR); + if (file < 0) + exit(1); + +Now the file is opened, we can perform the operations available:: + + /* Write function */ + uint_t8 buf[] = {0x00, 0xde, 0xad, 0xbe, 0xef} + if (write(file, buf, 5) != 5) { + /* ERROR HANDLING: I3C transaction failed */ + } + + /* Read function */ + ret = read(file, buf, 5); + If (ret < 0) { + /* ERROR HANDLING: I3C transaction failed */ + } else { + /* Iterate over buf[] to get the read data */ + } + + /* IOCTL function */ + struct i3c_ioc_priv_xfer xfers[2]; + + uint8_t tx_buf[] = {0x00, 0xde, 0xad, 0xbe, 0xef}; + uint8_t rx_buf[10]; + + xfers[0].data = (uintptr_t)tx_buf; + xfers[0].len = 5; + xfers[0].rnw = 0; + xfers[1].data = (uintptr_t)rx_buf; + xfers[1].len = 10; + xfers[1].rnw = 1; + + if (ioctl(file, I3C_IOC_PRIV_XFER(2), xfers) < 0) + /* ERROR HANDLING: I3C transaction failed */ + +The device can be closed when the open file descriptor is no longer required:: + + close(file); \ No newline at end of file