From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v2 08/11] dev: add dev_bus_is_spi/i2c helpers
Date: Wed, 11 Jan 2023 14:29:53 +0100 [thread overview]
Message-ID: <20230111132956.1153359-9-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20230111132956.1153359-1-a.fatoum@pengutronix.de>
These will simplify writing drivers that can probe via either I2C or SPI
like the SSD1307FB and upcoming KSZ I2C switch support.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/video/ssd1307fb.c | 4 ++--
include/i2c/i2c.h | 5 +++++
include/spi/spi.h | 5 +++++
3 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/drivers/video/ssd1307fb.c b/drivers/video/ssd1307fb.c
index c2b5cd9b3481..7d2769a228af 100644
--- a/drivers/video/ssd1307fb.c
+++ b/drivers/video/ssd1307fb.c
@@ -451,12 +451,12 @@ static int ssd1307fb_probe(struct device *dev)
par->device_info = (struct ssd1307fb_deviceinfo *)match->data;
- if (IS_ENABLED(CONFIG_I2C) && dev->bus == &i2c_bus) {
+ if (dev_bus_is_i2c(dev)) {
par->client = to_i2c_client(dev);
i2c_set_clientdata(par->client, par);
par->write_array = ssd1307fb_i2c_write_array;
}
- if (IS_ENABLED(CONFIG_SPI) && dev->bus == &spi_bus) {
+ if (dev_bus_is_spi(dev)) {
par->spi = to_spi_device(dev);
par->dc = of_get_named_gpio(node, "dc-gpios", 0);
if (!gpio_is_valid(par->dc)) {
diff --git a/include/i2c/i2c.h b/include/i2c/i2c.h
index 5cca73a2f86d..b1ab72850c75 100644
--- a/include/i2c/i2c.h
+++ b/include/i2c/i2c.h
@@ -330,6 +330,11 @@ extern int i2c_write_reg(struct i2c_client *client, u32 addr, const u8 *buf, u16
extern struct bus_type i2c_bus;
+static inline bool dev_bus_is_i2c(struct device *dev)
+{
+ return IS_ENABLED(CONFIG_I2C) && dev->bus == &i2c_bus;
+}
+
static inline int i2c_driver_register(struct driver *drv)
{
drv->bus = &i2c_bus;
diff --git a/include/spi/spi.h b/include/spi/spi.h
index 7591d0ff3b26..5071dd69650b 100644
--- a/include/spi/spi.h
+++ b/include/spi/spi.h
@@ -556,6 +556,11 @@ static inline ssize_t spi_w8r8(struct spi_device *spi, u8 cmd)
extern struct bus_type spi_bus;
+static inline bool dev_bus_is_spi(struct device_d *dev)
+{
+ return IS_ENABLED(CONFIG_SPI) && dev->bus == &spi_bus;
+}
+
struct spi_controller *spi_get_controller(int bus);
static inline int spi_driver_register(struct driver *drv)
--
2.30.2
next prev parent reply other threads:[~2023-01-11 13:33 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-11 13:29 [PATCH v2 00/11] net: dsa: ksz9477: use regmap to add I2C support next to SPI Ahmad Fatoum
2023-01-11 13:29 ` [PATCH v2 01/11] regmap: consolidate reg/val format into regmap_format Ahmad Fatoum
2023-01-11 13:29 ` [PATCH v2 02/11] regmap: support formatted read and write Ahmad Fatoum
2023-01-11 13:29 ` [PATCH v2 03/11] regmap: port regmap_init_spi Ahmad Fatoum
2023-01-11 13:29 ` [PATCH v2 04/11] regmap: factor out regmap cdev size calculation Ahmad Fatoum
2023-01-11 13:29 ` [PATCH v2 05/11] net: dsa: ksz9477: switch to regmap_init_spi Ahmad Fatoum
2023-01-11 13:29 ` [PATCH v2 06/11] net: dsa: ksz9477: create regmap cdev for switch registers Ahmad Fatoum
2023-01-11 13:29 ` [PATCH v2 07/11] drivers: base: regmap: introduce REGMAP_I2C Ahmad Fatoum
2023-01-11 13:29 ` Ahmad Fatoum [this message]
2023-01-11 13:29 ` [PATCH v2 09/11] net: dsa: ksz9477: refactor to prepare i2c support Ahmad Fatoum
2023-01-11 13:29 ` [PATCH v2 10/11] regmap: i2c: use formatted I/O Ahmad Fatoum
2023-01-11 13:29 ` [PATCH v2 11/11] net: ksz9477: add I2C support Ahmad Fatoum
2023-01-12 14:58 ` [PATCH v2 00/11] net: dsa: ksz9477: use regmap to add I2C support next to SPI Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230111132956.1153359-9-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox