mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] base: Transform "platform_match" into "device_match" and make this function public
@ 2013-07-11 20:23 Alexander Shiyan
  2013-07-11 20:23 ` [PATCH 2/3] spi: Reuse "driver_match" for SPI bus Alexander Shiyan
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Alexander Shiyan @ 2013-07-11 20:23 UTC (permalink / raw)
  To: barebox

This change will allow reuse this function for other buses.

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 drivers/base/bus.c      | 24 ++++++++++++++++++++++++
 drivers/base/platform.c | 26 +-------------------------
 include/driver.h        |  1 +
 3 files changed, 26 insertions(+), 25 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 5251be6..4357020 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -46,3 +46,27 @@ int bus_register(struct bus_type *bus)
 
 	return 0;
 }
+
+int device_match(struct device_d *dev, struct driver_d *drv)
+{
+	if (IS_ENABLED(CONFIG_OFDEVICE) && dev->device_node &&
+	    drv->of_compatible)
+		return of_match(dev, drv);
+
+	if (!strcmp(dev->name, drv->name))
+		return 0;
+
+	if (drv->id_table) {
+		struct platform_device_id *id = drv->id_table;
+
+		while (id->name) {
+			if (!strcmp(id->name, dev->name)) {
+				dev->id_entry = id;
+				return 0;
+			}
+			id++;
+		}
+	}
+
+	return -1;
+}
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index e1a8472..34a79b2 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -21,30 +21,6 @@
 #include <errno.h>
 #include <init.h>
 
-static int platform_match(struct device_d *dev, struct driver_d *drv)
-{
-	if (IS_ENABLED(CONFIG_OFDEVICE) && dev->device_node &&
-			drv->of_compatible)
-		return of_match(dev, drv);
-
-	if (!strcmp(dev->name, drv->name))
-		return 0;
-
-	if (drv->id_table) {
-		struct platform_device_id *id = drv->id_table;
-
-		while (id->name) {
-			if (!strcmp(id->name, dev->name)) {
-				dev->id_entry = id;
-				return 0;
-			}
-			id++;
-		}
-	}
-
-	return -1;
-}
-
 static int platform_probe(struct device_d *dev)
 {
 	return dev->driver->probe(dev);
@@ -71,7 +47,7 @@ int platform_device_register(struct device_d *new_device)
 
 struct bus_type platform_bus = {
 	.name = "platform",
-	.match = platform_match,
+	.match = device_match,
 	.probe = platform_probe,
 	.remove = platform_remove,
 };
diff --git a/include/driver.h b/include/driver.h
index b18318f..d15c9dd 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -384,6 +384,7 @@ struct bus_type {
 };
 
 int bus_register(struct bus_type *bus);
+int device_match(struct device_d *dev, struct driver_d *drv);
 
 extern struct list_head bus_list;
 
-- 
1.8.1.5


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/3] spi: Reuse "driver_match" for SPI bus
  2013-07-11 20:23 [PATCH 1/3] base: Transform "platform_match" into "device_match" and make this function public Alexander Shiyan
@ 2013-07-11 20:23 ` Alexander Shiyan
  2013-07-11 20:23 ` [PATCH 3/3] i2c: Reuse "driver_match" for I2C bus Alexander Shiyan
  2013-07-15  8:08 ` [PATCH 1/3] base: Transform "platform_match" into "device_match" and make this function public Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Alexander Shiyan @ 2013-07-11 20:23 UTC (permalink / raw)
  To: barebox

This will allow to use device_ids and make code a bit smaller.

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 drivers/spi/spi.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 5d4dfd6..55bebe0 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -289,15 +289,6 @@ int spi_write_then_read(struct spi_device *spi,
 }
 EXPORT_SYMBOL(spi_write_then_read);
 
-static int spi_match(struct device_d *dev, struct driver_d *drv)
-{
-	if (IS_ENABLED(CONFIG_OFDEVICE) && dev->device_node &&
-			drv->of_compatible)
-		return of_match(dev, drv);
-
-	return strcmp(dev->name, drv->name) ? -1 : 0;
-}
-
 static int spi_probe(struct device_d *dev)
 {
 	return dev->driver->probe(dev);
@@ -310,7 +301,7 @@ static void spi_remove(struct device_d *dev)
 
 struct bus_type spi_bus = {
 	.name = "spi",
-	.match = spi_match,
+	.match = device_match,
 	.probe = spi_probe,
 	.remove = spi_remove,
 };
-- 
1.8.1.5


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 3/3] i2c: Reuse "driver_match" for I2C bus
  2013-07-11 20:23 [PATCH 1/3] base: Transform "platform_match" into "device_match" and make this function public Alexander Shiyan
  2013-07-11 20:23 ` [PATCH 2/3] spi: Reuse "driver_match" for SPI bus Alexander Shiyan
@ 2013-07-11 20:23 ` Alexander Shiyan
  2013-07-15  8:08 ` [PATCH 1/3] base: Transform "platform_match" into "device_match" and make this function public Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Alexander Shiyan @ 2013-07-11 20:23 UTC (permalink / raw)
  To: barebox

This will allow to use device_ids and make code a bit smaller.

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 drivers/i2c/i2c.c | 22 +---------------------
 1 file changed, 1 insertion(+), 21 deletions(-)

diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index 3e09547..ccc4844 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -454,26 +454,6 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adapter)
 }
 EXPORT_SYMBOL(i2c_add_numbered_adapter);
 
-static int i2c_match(struct device_d *dev, struct driver_d *drv)
-{
-	if (!strcmp(dev->name, drv->name))
-		return 0;
-
-	if (drv->id_table) {
-		struct platform_device_id *id = drv->id_table;
-
-		while (id->name) {
-			if (!strcmp(id->name, dev->name)) {
-				dev->id_entry = id;
-				return 0;
-			}
-			id++;
-		}
-	}
-
-	return -1;
-}
-
 static int i2c_probe(struct device_d *dev)
 {
 	return dev->driver->probe(dev);
@@ -486,7 +466,7 @@ static void i2c_remove(struct device_d *dev)
 
 struct bus_type i2c_bus = {
 	.name = "i2c",
-	.match = i2c_match,
+	.match = device_match,
 	.probe = i2c_probe,
 	.remove = i2c_remove,
 };
-- 
1.8.1.5


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/3] base: Transform "platform_match" into "device_match" and make this function public
  2013-07-11 20:23 [PATCH 1/3] base: Transform "platform_match" into "device_match" and make this function public Alexander Shiyan
  2013-07-11 20:23 ` [PATCH 2/3] spi: Reuse "driver_match" for SPI bus Alexander Shiyan
  2013-07-11 20:23 ` [PATCH 3/3] i2c: Reuse "driver_match" for I2C bus Alexander Shiyan
@ 2013-07-15  8:08 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2013-07-15  8:08 UTC (permalink / raw)
  To: Alexander Shiyan; +Cc: barebox

On Fri, Jul 12, 2013 at 12:23:28AM +0400, Alexander Shiyan wrote:
> This change will allow reuse this function for other buses.
> 
> Signed-off-by: Alexander Shiyan <shc_work@mail.ru>

Applied, thanks

Sascha

> ---
>  drivers/base/bus.c      | 24 ++++++++++++++++++++++++
>  drivers/base/platform.c | 26 +-------------------------
>  include/driver.h        |  1 +
>  3 files changed, 26 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/base/bus.c b/drivers/base/bus.c
> index 5251be6..4357020 100644
> --- a/drivers/base/bus.c
> +++ b/drivers/base/bus.c
> @@ -46,3 +46,27 @@ int bus_register(struct bus_type *bus)
>  
>  	return 0;
>  }
> +
> +int device_match(struct device_d *dev, struct driver_d *drv)
> +{
> +	if (IS_ENABLED(CONFIG_OFDEVICE) && dev->device_node &&
> +	    drv->of_compatible)
> +		return of_match(dev, drv);
> +
> +	if (!strcmp(dev->name, drv->name))
> +		return 0;
> +
> +	if (drv->id_table) {
> +		struct platform_device_id *id = drv->id_table;
> +
> +		while (id->name) {
> +			if (!strcmp(id->name, dev->name)) {
> +				dev->id_entry = id;
> +				return 0;
> +			}
> +			id++;
> +		}
> +	}
> +
> +	return -1;
> +}
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index e1a8472..34a79b2 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -21,30 +21,6 @@
>  #include <errno.h>
>  #include <init.h>
>  
> -static int platform_match(struct device_d *dev, struct driver_d *drv)
> -{
> -	if (IS_ENABLED(CONFIG_OFDEVICE) && dev->device_node &&
> -			drv->of_compatible)
> -		return of_match(dev, drv);
> -
> -	if (!strcmp(dev->name, drv->name))
> -		return 0;
> -
> -	if (drv->id_table) {
> -		struct platform_device_id *id = drv->id_table;
> -
> -		while (id->name) {
> -			if (!strcmp(id->name, dev->name)) {
> -				dev->id_entry = id;
> -				return 0;
> -			}
> -			id++;
> -		}
> -	}
> -
> -	return -1;
> -}
> -
>  static int platform_probe(struct device_d *dev)
>  {
>  	return dev->driver->probe(dev);
> @@ -71,7 +47,7 @@ int platform_device_register(struct device_d *new_device)
>  
>  struct bus_type platform_bus = {
>  	.name = "platform",
> -	.match = platform_match,
> +	.match = device_match,
>  	.probe = platform_probe,
>  	.remove = platform_remove,
>  };
> diff --git a/include/driver.h b/include/driver.h
> index b18318f..d15c9dd 100644
> --- a/include/driver.h
> +++ b/include/driver.h
> @@ -384,6 +384,7 @@ struct bus_type {
>  };
>  
>  int bus_register(struct bus_type *bus);
> +int device_match(struct device_d *dev, struct driver_d *drv);
>  
>  extern struct list_head bus_list;
>  
> -- 
> 1.8.1.5
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-07-15  8:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-11 20:23 [PATCH 1/3] base: Transform "platform_match" into "device_match" and make this function public Alexander Shiyan
2013-07-11 20:23 ` [PATCH 2/3] spi: Reuse "driver_match" for SPI bus Alexander Shiyan
2013-07-11 20:23 ` [PATCH 3/3] i2c: Reuse "driver_match" for I2C bus Alexander Shiyan
2013-07-15  8:08 ` [PATCH 1/3] base: Transform "platform_match" into "device_match" and make this function public Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox