mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] Extend device_platform_driver macro
@ 2013-03-08  9:05 Alexander Shiyan
  2013-03-09 15:12 ` Sascha Hauer
  0 siblings, 1 reply; 6+ messages in thread
From: Alexander Shiyan @ 2013-03-08  9:05 UTC (permalink / raw)
  To: barebox

This patch extends device_platform_driver macro, so now we allow
use it with various init levels and subsystems.

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 include/driver.h | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/include/driver.h b/include/driver.h
index 46c56c0..b891f80 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -395,16 +395,19 @@ extern struct bus_type platform_bus;
 
 int platform_driver_register(struct driver_d *drv);
 
-/* device_platform_driver() - Helper macro for drivers that don't do
+/* register_driver_macro() - Helper macro for drivers that don't do
  * anything special in module registration. This eliminates a lot of
  * boilerplate. Each module may only use this macro once.
  */
-#define device_platform_driver(drv)			\
-	static int __init drv ## _register(void)	\
-	{						\
-		return platform_driver_register(&drv);	\
-	}						\
-	device_initcall(drv ## _register)
+#define register_driver_macro(level,subsystem,drv)		\
+	static int __init drv##_register(void)			\
+	{							\
+		return subsystem##_driver_register(&drv);	\
+	}							\
+	level##_initcall(drv##_register)
+
+#define device_platform_driver(drv)	\
+	register_driver_macro(device,platform,drv)
 
 int platform_device_register(struct device_d *new_device);
 
-- 
1.7.12.4


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

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

* Re: [PATCH] Extend device_platform_driver macro
  2013-03-08  9:05 [PATCH] Extend device_platform_driver macro Alexander Shiyan
@ 2013-03-09 15:12 ` Sascha Hauer
  2013-03-09 15:19   ` Re[2]: " Alexander Shiyan
  2013-03-09 18:36   ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 2 replies; 6+ messages in thread
From: Sascha Hauer @ 2013-03-09 15:12 UTC (permalink / raw)
  To: Alexander Shiyan; +Cc: barebox

Hi Alexander,

On Fri, Mar 08, 2013 at 01:05:14PM +0400, Alexander Shiyan wrote:
> This patch extends device_platform_driver macro, so now we allow
> use it with various init levels and subsystems.
> 
> Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
> ---
>  include/driver.h | 17 ++++++++++-------
>  1 file changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/include/driver.h b/include/driver.h
> index 46c56c0..b891f80 100644
> --- a/include/driver.h
> +++ b/include/driver.h
> @@ -395,16 +395,19 @@ extern struct bus_type platform_bus;
>  
>  int platform_driver_register(struct driver_d *drv);
>  
> -/* device_platform_driver() - Helper macro for drivers that don't do
> +/* register_driver_macro() - Helper macro for drivers that don't do
>   * anything special in module registration. This eliminates a lot of
>   * boilerplate. Each module may only use this macro once.
>   */
> -#define device_platform_driver(drv)			\
> -	static int __init drv ## _register(void)	\
> -	{						\
> -		return platform_driver_register(&drv);	\
> -	}						\
> -	device_initcall(drv ## _register)
> +#define register_driver_macro(level,subsystem,drv)		\
> +	static int __init drv##_register(void)			\
> +	{							\
> +		return subsystem##_driver_register(&drv);	\
> +	}							\
> +	level##_initcall(drv##_register)

So the usage would look like:

register_driver_macro(device, i2c, &mc_driver)

?

I'm not sure if I like this. I'm a bit concerned about being able
to grep for for example i2c_register_driver. This would become

wcgrep register_driver_macro | grep i2c

or similar.

What do others think about it?

Sascha

-- 
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] 6+ messages in thread

* Re[2]: [PATCH] Extend device_platform_driver macro
  2013-03-09 15:12 ` Sascha Hauer
@ 2013-03-09 15:19   ` Alexander Shiyan
  2013-03-09 20:46     ` Uwe Kleine-König
  2013-03-09 18:36   ` Jean-Christophe PLAGNIOL-VILLARD
  1 sibling, 1 reply; 6+ messages in thread
From: Alexander Shiyan @ 2013-03-09 15:19 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

> Hi Alexander,
> 
> On Fri, Mar 08, 2013 at 01:05:14PM +0400, Alexander Shiyan wrote:
> > This patch extends device_platform_driver macro, so now we allow
> > use it with various init levels and subsystems.
> > 
> > Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
> > ---
> >  include/driver.h | 17 ++++++++++-------
> >  1 file changed, 10 insertions(+), 7 deletions(-)
> > 
> > diff --git a/include/driver.h b/include/driver.h
> > index 46c56c0..b891f80 100644
> > --- a/include/driver.h
> > +++ b/include/driver.h
> > @@ -395,16 +395,19 @@ extern struct bus_type platform_bus;
> >  
> >  int platform_driver_register(struct driver_d *drv);
> >  
> > -/* device_platform_driver() - Helper macro for drivers that don't do
> > +/* register_driver_macro() - Helper macro for drivers that don't do
> >   * anything special in module registration. This eliminates a lot of
> >   * boilerplate. Each module may only use this macro once.
> >   */
> > -#define device_platform_driver(drv)			\
> > -	static int __init drv ## _register(void)	\
> > -	{						\
> > -		return platform_driver_register(&drv);	\
> > -	}						\
> > -	device_initcall(drv ## _register)
> > +#define register_driver_macro(level,subsystem,drv)		\
> > +	static int __init drv##_register(void)			\
> > +	{							\
> > +		return subsystem##_driver_register(&drv);	\
> > +	}							\
> > +	level##_initcall(drv##_register)
> 
> So the usage would look like:
> 
> register_driver_macro(device, i2c, &mc_driver)
> 
> ?
> 
> I'm not sure if I like this. I'm a bit concerned about being able
> to grep for for example i2c_register_driver. This would become
> 
> wcgrep register_driver_macro | grep i2c
> 
> or similar.

You are skip 2 important lines:
#define device_platform_driver(drv) \
 register_driver_macro(device,platform,drv)

For i2c we can define new macro like this:
#define device_i2c_driver(drv) \
 register_driver_macro(device,i2c,drv)

then use device_i2c_driver(&foo) in the driver.

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

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

* Re: [PATCH] Extend device_platform_driver macro
  2013-03-09 15:12 ` Sascha Hauer
  2013-03-09 15:19   ` Re[2]: " Alexander Shiyan
@ 2013-03-09 18:36   ` Jean-Christophe PLAGNIOL-VILLARD
  1 sibling, 0 replies; 6+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-03-09 18:36 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox


On Mar 9, 2013, at 11:12 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:

> Hi Alexander,
> 
> On Fri, Mar 08, 2013 at 01:05:14PM +0400, Alexander Shiyan wrote:
>> This patch extends device_platform_driver macro, so now we allow
>> use it with various init levels and subsystems.
>> 
>> Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
>> ---
>> include/driver.h | 17 ++++++++++-------
>> 1 file changed, 10 insertions(+), 7 deletions(-)
>> 
>> diff --git a/include/driver.h b/include/driver.h
>> index 46c56c0..b891f80 100644
>> --- a/include/driver.h
>> +++ b/include/driver.h
>> @@ -395,16 +395,19 @@ extern struct bus_type platform_bus;
>> 
>> int platform_driver_register(struct driver_d *drv);
>> 
>> -/* device_platform_driver() - Helper macro for drivers that don't do
>> +/* register_driver_macro() - Helper macro for drivers that don't do
>>  * anything special in module registration. This eliminates a lot of
>>  * boilerplate. Each module may only use this macro once.
>>  */
>> -#define device_platform_driver(drv)			\
>> -	static int __init drv ## _register(void)	\
>> -	{						\
>> -		return platform_driver_register(&drv);	\
>> -	}						\
>> -	device_initcall(drv ## _register)
>> +#define register_driver_macro(level,subsystem,drv)		\
>> +	static int __init drv##_register(void)			\
>> +	{							\
>> +		return subsystem##_driver_register(&drv);	\
>> +	}							\
>> +	level##_initcall(drv##_register)
> 
> So the usage would look like:
> 
> register_driver_macro(device, i2c, &mc_driver)
> 
> ?
> 
> I'm not sure if I like this. I'm a bit concerned about being able
> to grep for for example i2c_register_driver. This would become
> 
> wcgrep register_driver_macro | grep i2c
> 
> or similar.
> 
> What do others think about it?
same I don't like it

Best Regards,
J.
> 
> Sascha
> 
> -- 
> 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


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

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

* Re: [PATCH] Extend device_platform_driver macro
  2013-03-09 15:19   ` Re[2]: " Alexander Shiyan
@ 2013-03-09 20:46     ` Uwe Kleine-König
  2013-03-09 21:10       ` Re[2]: " Alexander Shiyan
  0 siblings, 1 reply; 6+ messages in thread
From: Uwe Kleine-König @ 2013-03-09 20:46 UTC (permalink / raw)
  To: Alexander Shiyan; +Cc: barebox

Hi,

On Sat, Mar 09, 2013 at 07:19:31PM +0400, Alexander Shiyan wrote:
> > On Fri, Mar 08, 2013 at 01:05:14PM +0400, Alexander Shiyan wrote:
> > > This patch extends device_platform_driver macro, so now we allow
> > > use it with various init levels and subsystems.
> > > 
> > > Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
> > > ---
> > >  include/driver.h | 17 ++++++++++-------
> > >  1 file changed, 10 insertions(+), 7 deletions(-)
> > > 
> > > diff --git a/include/driver.h b/include/driver.h
> > > index 46c56c0..b891f80 100644
> > > --- a/include/driver.h
> > > +++ b/include/driver.h
> > > @@ -395,16 +395,19 @@ extern struct bus_type platform_bus;
> > >  
> > >  int platform_driver_register(struct driver_d *drv);
> > >  
> > > -/* device_platform_driver() - Helper macro for drivers that don't do
> > > +/* register_driver_macro() - Helper macro for drivers that don't do
> > >   * anything special in module registration. This eliminates a lot of
> > >   * boilerplate. Each module may only use this macro once.
> > >   */
> > > -#define device_platform_driver(drv)			\
> > > -	static int __init drv ## _register(void)	\
> > > -	{						\
> > > -		return platform_driver_register(&drv);	\
> > > -	}						\
> > > -	device_initcall(drv ## _register)
> > > +#define register_driver_macro(level,subsystem,drv)		\
> > > +	static int __init drv##_register(void)			\
> > > +	{							\
> > > +		return subsystem##_driver_register(&drv);	\
> > > +	}							\
> > > +	level##_initcall(drv##_register)
> > 
> > So the usage would look like:
> > 
> > register_driver_macro(device, i2c, &mc_driver)
> > 
> > ?
> > 
> > I'm not sure if I like this. I'm a bit concerned about being able
> > to grep for for example i2c_register_driver. This would become
> > 
> > wcgrep register_driver_macro | grep i2c
> > 
> > or similar.
> 
> You are skip 2 important lines:
> #define device_platform_driver(drv) \
>  register_driver_macro(device,platform,drv)
> 
> For i2c we can define new macro like this:
> #define device_i2c_driver(drv) \
>  register_driver_macro(device,i2c,drv)
> 
> then use device_i2c_driver(&foo) in the driver.
I like the idea. Alexander, what is your motivation? Maybe offer a patch
series that first contains this patch and then in a later patch
introduces a nice usage.

Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

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

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

* Re[2]: [PATCH] Extend device_platform_driver macro
  2013-03-09 20:46     ` Uwe Kleine-König
@ 2013-03-09 21:10       ` Alexander Shiyan
  0 siblings, 0 replies; 6+ messages in thread
From: Alexander Shiyan @ 2013-03-09 21:10 UTC (permalink / raw)
  To: Uwe Kleine-K�nig; +Cc: barebox

> Hi,
> 
> On Sat, Mar 09, 2013 at 07:19:31PM +0400, Alexander Shiyan wrote:
> > > On Fri, Mar 08, 2013 at 01:05:14PM +0400, Alexander Shiyan wrote:
> > > > This patch extends device_platform_driver macro, so now we allow
> > > > use it with various init levels and subsystems.
> > > > 
> > > > Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
> > > > ---
> > > >  include/driver.h | 17 ++++++++++-------
> > > >  1 file changed, 10 insertions(+), 7 deletions(-)
> > > > 
> > > > diff --git a/include/driver.h b/include/driver.h
> > > > index 46c56c0..b891f80 100644
> > > > --- a/include/driver.h
> > > > +++ b/include/driver.h
> > > > @@ -395,16 +395,19 @@ extern struct bus_type platform_bus;
> > > >  
> > > >  int platform_driver_register(struct driver_d *drv);
> > > >  
> > > > -/* device_platform_driver() - Helper macro for drivers that don't do
> > > > +/* register_driver_macro() - Helper macro for drivers that don't do
> > > >   * anything special in module registration. This eliminates a lot of
> > > >   * boilerplate. Each module may only use this macro once.
> > > >   */
> > > > -#define device_platform_driver(drv)			\
> > > > -	static int __init drv ## _register(void)	\
> > > > -	{						\
> > > > -		return platform_driver_register(&drv);	\
> > > > -	}						\
> > > > -	device_initcall(drv ## _register)
> > > > +#define register_driver_macro(level,subsystem,drv)		\
> > > > +	static int __init drv##_register(void)			\
> > > > +	{							\
> > > > +		return subsystem##_driver_register(&drv);	\
> > > > +	}							\
> > > > +	level##_initcall(drv##_register)
> > > 
> > > So the usage would look like:
> > > 
> > > register_driver_macro(device, i2c, &mc_driver)
> > > 
> > > ?
> > > 
> > > I'm not sure if I like this. I'm a bit concerned about being able
> > > to grep for for example i2c_register_driver. This would become
> > > 
> > > wcgrep register_driver_macro | grep i2c
> > > 
> > > or similar.
> > 
> > You are skip 2 important lines:
> > #define device_platform_driver(drv) \
> >  register_driver_macro(device,platform,drv)
> > 
> > For i2c we can define new macro like this:
> > #define device_i2c_driver(drv) \
> >  register_driver_macro(device,i2c,drv)
> > 
> > then use device_i2c_driver(&foo) in the driver.
> I like the idea. Alexander, what is your motivation? Maybe offer a patch
> series that first contains this patch and then in a later patch
> introduces a nice usage.

The first use of this idea was already here:
http://git.pengutronix.de/?p=barebox.git;a=commit;h=6a256321b839534cb3da4b8ffc06c126871a78e3

But you're right, I'll prepare another patch to show the use of the extended version.

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

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

end of thread, other threads:[~2013-03-09 21:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-08  9:05 [PATCH] Extend device_platform_driver macro Alexander Shiyan
2013-03-09 15:12 ` Sascha Hauer
2013-03-09 15:19   ` Re[2]: " Alexander Shiyan
2013-03-09 20:46     ` Uwe Kleine-König
2013-03-09 21:10       ` Re[2]: " Alexander Shiyan
2013-03-09 18:36   ` Jean-Christophe PLAGNIOL-VILLARD

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