From patchwork Sun Jul 3 15:42:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12904403 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 4E23CC433EF for ; Sun, 3 Jul 2022 15:43:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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:In-Reply-To:References: List-Owner; bh=kkOwseQYif4zjfrvTnlobWP3c4rUhfFF1WGf8aYsXjo=; b=vqaCCXwEF77PDK NQsHhVd2HbV4V249V5l3B3gn6MTT1lwWIm/bIalLuCaPxJ5YpCBeawizvwknPelVXynVnw2CMrb4c VZcLxajVgbfg4bi134A45NYbcGLYTuexKVOCGJrf6U7BEMRhXTpbRGkGof9cx68lgccMX62BUqMXV xvRlA1lqlfhTS4makKhE1LjAeQMzDaySkrS3PPJEc3alBIAqMOgiAH3xllPhnjhLq6jMJKqvhqx2L V2yhNJBVNHgC4EqlF24k3RZsWXxv6vqUIJlX1FX11+P4KykRnZgRR9ERN1JB+YJ3RtEs9RJUUYuSo 8ame6ghJdgFZoaaHAMbA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o81k4-00Gwjn-Tv; Sun, 03 Jul 2022 15:42:37 +0000 Received: from mga04.intel.com ([192.55.52.120]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o81k2-00Gwfq-6f for linux-arm-kernel@lists.infradead.org; Sun, 03 Jul 2022 15:42:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656862954; x=1688398954; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=PSyqYyC0J2kJSoqRvHgJQSUMUuLg3p+H4Cjpxh3d8gQ=; b=J3YKq/pzl3HzSnynxALdWCPuS1kMYcJPOpc46TKJm4De5Hfd+6RB4ZF9 UTw00nCNyfD+4Ey5s7XbFlTgv+Mrs14Ylhl4N5NmHtg1HLOFsTD0s3sgO 23EvtHVeInsGhepKwHNN2LdTt8qpeks92bSPVo5Q4PQhMxcDELGcHj0iW Fl4lIasfocBxwrCxOSJHCBV+4Orgu15T1yIUrtkNlGK65yUbWLMm1RtUG xeeplpYugbi7awcWiOePhz2F+2WNuqu1wKjv5/jfi94teRDYNhGu9AwMw ks7Pf6ZKHz4pT4zIC0ODBKkP5/XyRUJIIgYbT0OnrM4q1zR7urKTBYsX4 g==; X-IronPort-AV: E=McAfee;i="6400,9594,10397"; a="281719772" X-IronPort-AV: E=Sophos;i="5.92,241,1650956400"; d="scan'208";a="281719772" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jul 2022 08:42:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,241,1650956400"; d="scan'208";a="596759636" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga007.fm.intel.com with ESMTP; 03 Jul 2022 08:42:27 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id CF93111D; Sun, 3 Jul 2022 18:42:33 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , Wolfram Sang , Michael Walle , Krzysztof Kozlowski , Sam Protsenko , Lucas De Marchi , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-renesas-soc@vger.kernel.org Subject: [PATCH v2 1/2] lib/string_helpers: Add str_read_write() helper Date: Sun, 3 Jul 2022 18:42:31 +0300 Message-Id: <20220703154232.55549-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220703_084234_303194_4DCFE34C X-CRM114-Status: UNSURE ( 8.76 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Belloni , Wolfram Sang , Krzysztof Kozlowski , Till Harbaum , Alim Akhtar , Codrin Ciubotariu , Claudiu Beznea Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add str_read_write() helper to retun 'read' or 'write' string literal. Signed-off-by: Andy Shevchenko --- v2: no changes include/linux/string_helpers.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h index 4d72258d42fd..9e22cd78f3b8 100644 --- a/include/linux/string_helpers.h +++ b/include/linux/string_helpers.h @@ -126,4 +126,9 @@ static inline const char *str_enabled_disabled(bool v) return v ? "enabled" : "disabled"; } +static inline const char *str_read_write(bool v) +{ + return v ? "read" : "write"; +} + #endif From patchwork Sun Jul 3 15:42:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12904402 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id CE555C43334 for ; Sun, 3 Jul 2022 15:43:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=97HxK0Ar2fs1AdIg1oI3zeX50LtT11Tp7BgJqucGxKc=; b=qXEvvfprDdIbyT jj6Chh+FToeSYyMogdZkffYEwpyChZ5O2Sp6wjAUpl3DbuH6aVEbm8CauJC+P8WvJIy2gUeamhhRp vpxibZJLM3QoN7xki3DTXNBRr3C9vLT7q3sAUMR8l1+I3Yuc6jXrbasyMNOfn9mMYxSKQvVzECGLf YnzsO3VucNPD1WitNcJCy1xKOoyuPQaLtGCuYsRAJH2wxnhv5hiVoEIhqtDQjNPf6+qkAi/938Is6 NDI3K+K+7Tf5q5yfV1utUCl0jYnvoC3B7lb9u2MupbnlxUphTZTGWlDOrXbKNkbsOLBqO5yaRTMKt EcE6VOJybCm+2tzxgBKA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o81kD-00GwoR-Bx; Sun, 03 Jul 2022 15:42:45 +0000 Received: from mga01.intel.com ([192.55.52.88]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o81k1-00Gwfp-Q3 for linux-arm-kernel@lists.infradead.org; Sun, 03 Jul 2022 15:42:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656862953; x=1688398953; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=U0ljrAEgK39fTn6tcoy/cFQVspwN3M7R4h5Ec5TiRLE=; b=YwtytUcl3+yfwl5PGXIOiJdSsYmF5+eJfaBLr/pP1z8aPvz3uUHDuPpa BYiFdmmpUECvJbdAMLzap+JbTc6dusq0fSnOcwjNqIUrRpgxankHDD92t fJIpbbXX/6Xf4t9UduZO9DnX9rrfa4PBJj4JuQe7a7qikkON91MQeyOkZ BLFvwMDQtBmLcq8lxO86nysHbjbKpFSnboBwoY1hORDSQqxjB31Z4HiHR m7Iqd8ESUAfJhR4oLse1n08+ePwO/w7bvRIA3OHLhK212sxHPoGfwKGty f85ARSSTrWJXFeeBReMg5u9LBTNmnoojjTGGYYOFCgfw/lri05GsWCPf5 Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10397"; a="308491206" X-IronPort-AV: E=Sophos;i="5.92,241,1650956400"; d="scan'208";a="308491206" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jul 2022 08:42:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,241,1650956400"; d="scan'208";a="838573260" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga006.fm.intel.com with ESMTP; 03 Jul 2022 08:42:27 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id DB933AD; Sun, 3 Jul 2022 18:42:33 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , Wolfram Sang , Michael Walle , Krzysztof Kozlowski , Sam Protsenko , Lucas De Marchi , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-renesas-soc@vger.kernel.org Subject: [PATCH v2 2/2] i2c: Introduce i2c_str_read_write() and make use of it Date: Sun, 3 Jul 2022 18:42:32 +0300 Message-Id: <20220703154232.55549-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220703154232.55549-1-andriy.shevchenko@linux.intel.com> References: <20220703154232.55549-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220703_084233_942333_4565E0C9 X-CRM114-Status: GOOD ( 19.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Belloni , Wolfram Sang , Krzysztof Kozlowski , Till Harbaum , Alim Akhtar , Codrin Ciubotariu , Claudiu Beznea Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org str_read_write() returns a string literal "read" or "write" based on the value. It also allows to unify usage of a such in the kernel. For i2c case introduce a wrapper that takes struct i2c_msg as parameter. Signed-off-by: Andy Shevchenko --- v2: fixed typo in exynos5 (LKP) drivers/i2c/algos/i2c-algo-pca.c | 3 +-- drivers/i2c/algos/i2c-algo-pcf.c | 3 +-- drivers/i2c/busses/i2c-at91-master.c | 3 +-- drivers/i2c/busses/i2c-exynos5.c | 3 +-- drivers/i2c/busses/i2c-hix5hd2.c | 3 +-- drivers/i2c/busses/i2c-img-scb.c | 5 ++--- drivers/i2c/busses/i2c-sh_mobile.c | 3 +-- drivers/i2c/busses/i2c-tiny-usb.c | 6 ++---- drivers/i2c/busses/i2c-viperboard.c | 6 ++---- drivers/i2c/i2c-core-base.c | 3 +-- include/linux/i2c.h | 7 +++++++ 11 files changed, 20 insertions(+), 25 deletions(-) diff --git a/drivers/i2c/algos/i2c-algo-pca.c b/drivers/i2c/algos/i2c-algo-pca.c index 384af88e58ad..e5ac3eee7a99 100644 --- a/drivers/i2c/algos/i2c-algo-pca.c +++ b/drivers/i2c/algos/i2c-algo-pca.c @@ -119,8 +119,7 @@ static int pca_address(struct i2c_algo_pca_data *adap, int sta = pca_get_con(adap); int addr = i2c_8bit_addr_from_msg(msg); - DEB2("=== SLAVE ADDRESS %#04x+%c=%#04x\n", - msg->addr, msg->flags & I2C_M_RD ? 'R' : 'W', addr); + DEB2("=== SLAVE ADDRESS %#04x+%s=%#04x\n", msg->addr, i2c_str_read_write(msg), addr); pca_outw(adap, I2C_PCA_DAT, addr); diff --git a/drivers/i2c/algos/i2c-algo-pcf.c b/drivers/i2c/algos/i2c-algo-pcf.c index 7a01f2687b4c..232224bbd670 100644 --- a/drivers/i2c/algos/i2c-algo-pcf.c +++ b/drivers/i2c/algos/i2c-algo-pcf.c @@ -316,8 +316,7 @@ static int pcf_xfer(struct i2c_adapter *i2c_adap, pmsg = &msgs[i]; DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: Doing %s %d bytes to 0x%02x - %d of %d messages\n", - pmsg->flags & I2C_M_RD ? "read" : "write", - pmsg->len, pmsg->addr, i + 1, num);) + i2c_str_read_write(pmsg), pmsg->len, pmsg->addr, i + 1, num);) ret = pcf_doAddress(adap, pmsg); diff --git a/drivers/i2c/busses/i2c-at91-master.c b/drivers/i2c/busses/i2c-at91-master.c index c0c35785a0dc..3761a6cb320f 100644 --- a/drivers/i2c/busses/i2c-at91-master.c +++ b/drivers/i2c/busses/i2c-at91-master.c @@ -523,8 +523,7 @@ static int at91_do_twi_transfer(struct at91_twi_dev *dev) * writing the corresponding bit into the Control Register. */ - dev_dbg(dev->dev, "transfer: %s %zu bytes.\n", - (dev->msg->flags & I2C_M_RD) ? "read" : "write", dev->buf_len); + dev_dbg(dev->dev, "transfer: %s %zu bytes.\n", i2c_str_read_write(dev->msg), dev->buf_len); reinit_completion(&dev->cmd_complete); dev->transfer_status = 0; diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c index b812d1090c0f..4d3fe3cea688 100644 --- a/drivers/i2c/busses/i2c-exynos5.c +++ b/drivers/i2c/busses/i2c-exynos5.c @@ -744,8 +744,7 @@ static int exynos5_i2c_xfer_msg(struct exynos5_i2c *i2c, if (ret < 0) { exynos5_i2c_reset(i2c); if (ret == -ETIMEDOUT) - dev_warn(i2c->dev, "%s timeout\n", - (msgs->flags & I2C_M_RD) ? "rx" : "tx"); + dev_warn(i2c->dev, "%s timeout\n", i2c_str_read_write(msgs)); } /* Return the state as in interrupt routine */ diff --git a/drivers/i2c/busses/i2c-hix5hd2.c b/drivers/i2c/busses/i2c-hix5hd2.c index 61ae58f57047..fefa5db52138 100644 --- a/drivers/i2c/busses/i2c-hix5hd2.c +++ b/drivers/i2c/busses/i2c-hix5hd2.c @@ -332,8 +332,7 @@ static int hix5hd2_i2c_xfer_msg(struct hix5hd2_i2c_priv *priv, if (timeout == 0) { priv->state = HIX5I2C_STAT_RW_ERR; priv->err = -ETIMEDOUT; - dev_warn(priv->dev, "%s timeout=%d\n", - msgs->flags & I2C_M_RD ? "rx" : "tx", + dev_warn(priv->dev, "%s timeout=%d\n", i2c_str_read_write(msgs), priv->adap.timeout); } ret = priv->state; diff --git a/drivers/i2c/busses/i2c-img-scb.c b/drivers/i2c/busses/i2c-img-scb.c index 8e987945ed45..772443059f49 100644 --- a/drivers/i2c/busses/i2c-img-scb.c +++ b/drivers/i2c/busses/i2c-img-scb.c @@ -950,9 +950,8 @@ static irqreturn_t img_i2c_isr(int irq, void *dev_id) INT_FIFO_EMPTY | INT_FIFO_FULL))) { dev_crit(i2c->adap.dev.parent, - "fatal: clock low timeout occurred %s addr 0x%02x\n", - (i2c->msg.flags & I2C_M_RD) ? "reading" : "writing", - i2c->msg.addr); + "fatal: clock low timeout occurred when %s addr 0x%02x\n", + i2c_str_read_write(&i2c->msg), i2c->msg.addr); hret = ISR_FATAL(EIO); goto out; } diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c index 72f024a0c363..2b569403ce71 100644 --- a/drivers/i2c/busses/i2c-sh_mobile.c +++ b/drivers/i2c/busses/i2c-sh_mobile.c @@ -409,8 +409,7 @@ static irqreturn_t sh_mobile_i2c_isr(int irq, void *dev_id) pd->sr |= sr; /* remember state */ dev_dbg(pd->dev, "i2c_isr 0x%02x 0x%02x %s %d %d!\n", sr, pd->sr, - (pd->msg->flags & I2C_M_RD) ? "read" : "write", - pd->pos, pd->msg->len); + i2c_str_read_write(pd->msg), pd->pos, pd->msg->len); /* Kick off TxDMA after preface was done */ if (pd->dma_direction == DMA_TO_DEVICE && pd->pos == 0) diff --git a/drivers/i2c/busses/i2c-tiny-usb.c b/drivers/i2c/busses/i2c-tiny-usb.c index 7279ca0eaa2d..74a435d7c308 100644 --- a/drivers/i2c/busses/i2c-tiny-usb.c +++ b/drivers/i2c/busses/i2c-tiny-usb.c @@ -71,10 +71,8 @@ static int usb_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, int num) pmsg = &msgs[i]; - dev_dbg(&adapter->dev, - " %d: %s (flags %d) %d bytes to 0x%02x\n", - i, pmsg->flags & I2C_M_RD ? "read" : "write", - pmsg->flags, pmsg->len, pmsg->addr); + dev_dbg(&adapter->dev, " %d: %s (flags %d) %d bytes to 0x%02x\n", + i, i2c_str_read_write(pmsg), pmsg->flags, pmsg->len, pmsg->addr); /* and directly send the message */ if (pmsg->flags & I2C_M_RD) { diff --git a/drivers/i2c/busses/i2c-viperboard.c b/drivers/i2c/busses/i2c-viperboard.c index 8b5322c3bce0..dec12e904aca 100644 --- a/drivers/i2c/busses/i2c-viperboard.c +++ b/drivers/i2c/busses/i2c-viperboard.c @@ -278,10 +278,8 @@ static int vprbrd_i2c_xfer(struct i2c_adapter *i2c, struct i2c_msg *msgs, for (i = 0 ; i < num ; i++) { pmsg = &msgs[i]; - dev_dbg(&i2c->dev, - " %d: %s (flags %d) %d bytes to 0x%02x\n", - i, pmsg->flags & I2C_M_RD ? "read" : "write", - pmsg->flags, pmsg->len, pmsg->addr); + dev_dbg(&i2c->dev, " %d: %s (flags %d) %d bytes to 0x%02x\n", + i, i2c_str_read_write(pmsg), pmsg->flags, pmsg->len, pmsg->addr); mutex_lock(&vb->lock); /* directly send the message */ diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 94c0663a39a6..9811bb44a2e0 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -2004,8 +2004,7 @@ module_exit(i2c_exit); static int i2c_quirk_error(struct i2c_adapter *adap, struct i2c_msg *msg, char *err_msg) { dev_err_ratelimited(&adap->dev, "adapter quirk: %s (addr 0x%04x, size %u, %s)\n", - err_msg, msg->addr, msg->len, - msg->flags & I2C_M_RD ? "read" : "write"); + err_msg, msg->addr, msg->len, i2c_str_read_write(msg)); return -EOPNOTSUPP; } diff --git a/include/linux/i2c.h b/include/linux/i2c.h index fbda5ada2afc..3cfaad39cc24 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -20,7 +20,9 @@ #include #include /* for Host Notify IRQ */ #include /* for struct device_node */ +#include /* for str_read_write() */ #include /* for swab16 */ + #include extern struct bus_type i2c_bus_type; @@ -934,6 +936,11 @@ static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg) return (msg->addr << 1) | (msg->flags & I2C_M_RD ? 1 : 0); } +static inline const char *i2c_str_read_write(const struct i2c_msg *msg) +{ + return str_read_write(msg->flags & I2C_M_RD); +} + u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold); void i2c_put_dma_safe_msg_buf(u8 *buf, struct i2c_msg *msg, bool xferred);