[PATCH v2 08/11] dev: add dev_bus_is_spi/i2c helpers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
---
 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





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux