cbus: tahvo: convert spinlock into mutex
Subsystems (4)
PATCH 1/27 cbus: tahvo: convert spinlock into mutex
GPIO operations can sleep, so move to a
mutex.
--- drivers/cbus/tahvo.c | 19 +++++++++---------- 1 files changed, 9 insertions(+), 10 deletions(-)
drivers/cbus/tahvo.c +9 -10
@@ -32,6 +32,7 @@#include <linux/irq.h> #include <linux/interrupt.h> #include <linux/platform_device.h> +#include <linux/mutex.h> #include "cbus.h" #include "tahvo.h"
@@ -43,7 +44,7 @@ static int tahvo_initialized;static int tahvo_is_betty;static struct tasklet_struct tahvo_tasklet; -static DEFINE_SPINLOCK (tahvo_lock); +static struct mutex tahvo_lock;static struct device *the_dev;
@@ -97,15 +98,14 @@ EXPORT_SYMBOL(tahvo_write_reg);*/ void tahvo_set_clear_reg_bits (unsigned reg,u16 set,u16 clear) { -unsigned long flags;u16 w; -spin_lock_irqsave (&tahvo_lock, flags); +mutex_lock (&tahvo_lock); w =tahvo_read_reg (reg); w &= ~clear; w |= set;tahvo_write_reg (reg, w); -spin_unlock_irqrestore (&tahvo_lock, flags); +mutex_unlock (&tahvo_lock); }/*
@@ -113,14 +113,13 @@ void tahvo_set_clear_reg_bits(unsigned reg, u16 set, u16 clear)*/ void tahvo_disable_irq (int id) { -unsigned long flags;u16 mask; -spin_lock_irqsave (&tahvo_lock, flags); +mutex_lock (&tahvo_lock); mask =tahvo_read_reg (TAHVO_REG_IMR ); mask |=1 << id;tahvo_write_reg (TAHVO_REG_IMR , mask); -spin_unlock_irqrestore (&tahvo_lock, flags); +mutex_unlock (&tahvo_lock); }EXPORT_SYMBOL (tahvo_disable_irq);
@@ -129,14 +128,13 @@ EXPORT_SYMBOL(tahvo_disable_irq);*/ void tahvo_enable_irq (int id) { -unsigned long flags;u16 mask; -spin_lock_irqsave (&tahvo_lock, flags); +mutex_lock (&tahvo_lock); mask =tahvo_read_reg (TAHVO_REG_IMR ); mask &= ~(1 << id);tahvo_write_reg (TAHVO_REG_IMR , mask); -spin_unlock_irqrestore (&tahvo_lock, flags); +mutex_unlock (&tahvo_lock); }EXPORT_SYMBOL (tahvo_enable_irq);
@@ -297,6 +295,7 @@ static int __init tahvo_probe(struct platform_device *pdev)int rev, id, ret;int irq; +mutex_init (&tahvo_lock); the_dev = &pdev->dev;/* Prepare tasklet */
Signature · 1 line
1.7.6.396.ge0613
PATCH 2/27 cbus: tahvo: move to __devinit/__devexit sections
while at that, also remove a few annoying and pretty much useless comments.
--- drivers/cbus/tahvo.c | 36 +++--------------------------------- 1 files changed, 3 insertions(+), 33 deletions(-)
drivers/cbus/tahvo.c +3 -33
@@ -108,9 +108,6 @@ void tahvo_set_clear_reg_bits(unsigned reg, u16 set, u16 clear)mutex_unlock (&tahvo_lock); } -/* -* Disable given TAHVO interrupt -*/ void tahvo_disable_irq (int id) {u16 mask;
@@ -123,9 +120,6 @@ void tahvo_disable_irq(int id) }EXPORT_SYMBOL (tahvo_disable_irq); -/* -* Enable given TAHVO interrupt -*/ void tahvo_enable_irq (int id) {u16 mask;
@@ -138,9 +132,6 @@ void tahvo_enable_irq(int id) }EXPORT_SYMBOL (tahvo_enable_irq); -/* -* Acknowledge given TAHVO interrupt -*/ void tahvo_ack_irq (int id) {tahvo_write_reg (TAHVO_REG_IDR ,1 << id);
@@ -181,18 +172,12 @@ void tahvo_set_backlight_level(int level) }EXPORT_SYMBOL (tahvo_set_backlight_level); -/* -* TAHVO interrupt handler. Only schedules the tasklet. -*/ static irqreturn_t tahvo_irq_handler (int irq,void *dev_id) {tasklet_schedule (&tahvo_tasklet);return IRQ_HANDLED ; } -/* -* Tasklet handler -*/ static void tahvo_tasklet_handler (unsigned long data) {struct tahvo_irq_handler_desc *hnd;
@@ -283,14 +268,7 @@ void tahvo_free_irq(int id) }EXPORT_SYMBOL (tahvo_free_irq); -/** -* tahvo_probe - Probe for Tahvo ASIC -* @dev: the Tahvo device -* -* Probe for the Tahvo ASIC and allocate memory -* for its device-struct if found -*/ -static int __init tahvo_probe (struct platform_device *pdev) +static int __devinit tahvo_probe (struct platform_device *pdev) {int rev, id, ret;int irq;
@@ -334,7 +312,7 @@ static int __init tahvo_probe(struct platform_device *pdev)return 0 ; } -static int __exit tahvo_remove(struct platform_device *pdev) +static int __devexit tahvo_remove(struct platform_device *pdev) {int irq;
@@ -350,25 +328,17 @@ static int __exit tahvo_remove(struct platform_device *pdev) }static struct platform_driver tahvo_driver = { - .remove =__exit_p (tahvo_remove), + .remove =__devexit_p (tahvo_remove), .driver = { .name ="tahvo" , }, }; -/** -* tahvo_init - initialise Tahvo driver -* -* Initialise the Tahvo driver and return 0 if everything worked ok -*/ static int __init tahvo_init (void ) {return platform_driver_probe (&tahvo_driver, tahvo_probe); } -/* -* Cleanup -*/ static void __exit tahvo_exit(void) {platform_driver_unregister (&tahvo_driver);
Signature · 1 line
1.7.6.396.ge0613
PATCH 3/27 cbus: tahvo: a switch looks better
In reply to Felipe Balbicleanup only, no functional changes.
--- drivers/cbus/tahvo.c | 10 +++++++--- 1 files changed, 7 insertions(+), 3 deletions(-)
drivers/cbus/tahvo.c +7 -3
@@ -284,13 +284,17 @@ static int __devinit tahvo_probe(struct platform_device *pdev) rev =tahvo_read_reg (TAHVO_REG_ASICR ); id = (rev >>8 ) &0xff ; -if (id ==0x03 ) { + +switch (id) { +case 0x03 :if ((rev &0xff ) >=0x50 ) tahvo_7bit_backlight =1 ; - }else if (id ==0x0b ) { +break ; +case 0x0b : tahvo_is_betty =1 ; tahvo_7bit_backlight =1 ; - }else { +break ; +default :dev_err (&pdev->dev,"Tahvo/Betty chip not found" );return -ENODEV ; }
Signature · 1 line
1.7.6.396.ge0613
PATCH 4/27 cbus: tahvo: don't go over 80 columns
In reply to Felipe Balbicleanup only, no functional changes.
--- drivers/cbus/tahvo.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
drivers/cbus/tahvo.c +3 -2
@@ -299,8 +299,9 @@ static int __devinit tahvo_probe(struct platform_device *pdev)return -ENODEV ; } -dev_err (&pdev->dev,"%s v%d.%d found\n" , tahvo_is_betty ?"Betty" :"Tahvo" , - (rev >>4 ) &0x0f , rev &0x0f ); +dev_err (&pdev->dev,"%s v%d.%d found\n" , + tahvo_is_betty ?"Betty" :"Tahvo" , + (rev >>4 ) &0x0f , rev &0x0f ); irq =platform_get_irq (pdev,0 );
Signature · 1 line
1.7.6.396.ge0613
PATCH 5/27 cbus: tahvo: drop the tasklet
In reply to Felipe Balbiby moving to threaded IRQ.
--- drivers/cbus/tahvo.c | 16 ++++------------ 1 files changed, 4 insertions(+), 12 deletions(-)
drivers/cbus/tahvo.c +4 -12
@@ -43,7 +43,6 @@static int tahvo_initialized;static int tahvo_is_betty; -static struct tasklet_struct tahvo_tasklet;static struct mutex tahvo_lock;static struct device *the_dev;
@@ -174,12 +173,6 @@ EXPORT_SYMBOL(tahvo_set_backlight_level);static irqreturn_t tahvo_irq_handler (int irq,void *dev_id) { -tasklet_schedule (&tahvo_tasklet); -return IRQ_HANDLED ; -} - -static void tahvo_tasklet_handler (unsigned long data) -{struct tahvo_irq_handler_desc *hnd;u16 id;u16 im;
@@ -212,6 +205,8 @@ static void tahvo_tasklet_handler(unsigned long data)*/ } } + +return IRQ_HANDLED ; }/*
@@ -276,9 +271,6 @@ static int __devinit tahvo_probe(struct platform_device *pdev)mutex_init (&tahvo_lock); the_dev = &pdev->dev; -/* Prepare tasklet */ -tasklet_init (&tahvo_tasklet, tahvo_tasklet_handler,0 ); - tahvo_initialized =1 ; rev =tahvo_read_reg (TAHVO_REG_ASICR );
@@ -308,7 +300,8 @@ static int __devinit tahvo_probe(struct platform_device *pdev)/* Mask all TAHVO interrupts */ tahvo_write_reg (TAHVO_REG_IMR ,0xffff ); - ret =request_irq (irq, tahvo_irq_handler,IRQF_TRIGGER_RISING , + ret =request_threaded_irq (irq,NULL , tahvo_irq_handler, +IRQF_TRIGGER_RISING |IRQF_ONESHOT ,"tahvo" ,0 );if (ret <0 ) {dev_err (&pdev->dev,"Unable to register IRQ handler\n" );
@@ -326,7 +319,6 @@ static int __devexit tahvo_remove(struct platform_device *pdev)/* Mask all TAHVO interrupts */ tahvo_write_reg (TAHVO_REG_IMR ,0xffff );free_irq (irq,0 ); -tasklet_kill (&tahvo_tasklet); the_dev =NULL ;return 0 ;
Signature · 1 line
1.7.6.396.ge0613
PATCH 6/27 cbus: retu: set IRQF_ONESHOT flag
In reply to Felipe Balbifor handlers which don't have top half, it's
necessary to IRQF_ONESHOT.
--- drivers/cbus/retu.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/cbus/retu.c +2 -2
@@ -469,8 +469,8 @@ static int __init retu_probe(struct platform_device *pdev)/* Mask all RETU interrupts */ __retu_write_reg (retu,RETU_REG_IMR ,0xffff ); - ret =request_threaded_irq (retu->irq,NULL , retu_irq_handler,0 , -"retu" , retu); + ret =request_threaded_irq (retu->irq,NULL , retu_irq_handler, +IRQF_ONESHOT ,"retu" , retu);if (ret <0 ) {dev_err (&pdev->dev,"Unable to register IRQ handler\n" ); goto err2;
Signature · 1 line
1.7.6.396.ge0613
PATCH 7/27 cbus: tahvo: git it a context structure
In reply to Felipe Balbijust moving things around. It's a lot easier
to handle a dynamically allocated structure
as it allows for multiple instances of the
same device.
--- drivers/cbus/tahvo.c | 128 ++++++++++++++++++++++++++++++++------------------ 1 files changed, 82 insertions(+), 46 deletions(-)
drivers/cbus/tahvo.c +82 -46
@@ -26,6 +26,7 @@#include <linux/module.h> #include <linux/init.h> +#include <linux/slab.h> #include <linux/kernel.h> #include <linux/errno.h> #include <linux/device.h>
@@ -40,12 +41,16 @@#define TAHVO_ID 0x02#define PFX "tahvo: " -static int tahvo_initialized; -static int tahvo_is_betty; +struct tahvo { +/* device lock */ +struct mutex mutex; +struct device *dev; -static struct mutex tahvo_lock; +unsigned int is_betty; +unsigned int wide_backlight; +}; -static struct device *the_dev; +static struct tahvo *the_tahvo;struct tahvo_irq_handler_desc {int (*func)(unsigned long );
@@ -57,7 +62,7 @@ static struct tahvo_irq_handler_desc tahvo_irq_handlers[MAX_TAHVO_IRQ_HANDLERS];int tahvo_get_status (void ) { -return tahvo_initialized; +return the_tahvo !=NULL ; }EXPORT_SYMBOL (tahvo_get_status);
@@ -69,8 +74,9 @@ EXPORT_SYMBOL(tahvo_get_status);*/ int tahvo_read_reg (unsigned reg) { -BUG_ON (!tahvo_initialized); -return cbus_read_reg (the_dev,TAHVO_ID , reg); +struct tahvo *tahvo = the_tahvo; + +return cbus_read_reg (tahvo->dev,TAHVO_ID , reg); }EXPORT_SYMBOL (tahvo_read_reg);
@@ -83,8 +89,9 @@ EXPORT_SYMBOL(tahvo_read_reg);*/ void tahvo_write_reg (unsigned reg,u16 val) { -BUG_ON (!tahvo_initialized); -cbus_write_reg (the_dev,TAHVO_ID , reg, val); +struct tahvo *tahvo = the_tahvo; + +cbus_write_reg (tahvo->dev,TAHVO_ID , reg, val); }EXPORT_SYMBOL (tahvo_write_reg);
@@ -97,37 +104,40 @@ EXPORT_SYMBOL(tahvo_write_reg);*/ void tahvo_set_clear_reg_bits (unsigned reg,u16 set,u16 clear) { -u16 w; +struct tahvo *tahvo = the_tahvo; +u16 w; -mutex_lock (&tahvo_lock); +mutex_lock (&tahvo->mutex); w =tahvo_read_reg (reg); w &= ~clear; w |= set;tahvo_write_reg (reg, w); -mutex_unlock (&tahvo_lock); +mutex_unlock (&tahvo->mutex); }void tahvo_disable_irq (int id) { -u16 mask; +struct tahvo *tahvo = the_tahvo; +u16 mask; -mutex_lock (&tahvo_lock); +mutex_lock (&tahvo->mutex); mask =tahvo_read_reg (TAHVO_REG_IMR ); mask |=1 << id;tahvo_write_reg (TAHVO_REG_IMR , mask); -mutex_unlock (&tahvo_lock); +mutex_unlock (&tahvo->mutex); }EXPORT_SYMBOL (tahvo_disable_irq);void tahvo_enable_irq (int id) { -u16 mask; +struct tahvo *tahvo = the_tahvo; +u16 mask; -mutex_lock (&tahvo_lock); +mutex_lock (&tahvo->mutex); mask =tahvo_read_reg (TAHVO_REG_IMR ); mask &= ~(1 << id);tahvo_write_reg (TAHVO_REG_IMR , mask); -mutex_unlock (&tahvo_lock); +mutex_unlock (&tahvo->mutex); }EXPORT_SYMBOL (tahvo_enable_irq);
@@ -137,13 +147,12 @@ void tahvo_ack_irq(int id) }EXPORT_SYMBOL (tahvo_ack_irq); -static int tahvo_7bit_backlight; -int tahvo_get_backlight_level (void ) { -int mask; +struct tahvo *tahvo = the_tahvo; +int mask; -if (tahvo_7bit_backlight) +if (tahvo->wide_backlight) mask =0x7f ;else mask =0x0f ;
@@ -153,7 +162,9 @@ EXPORT_SYMBOL(tahvo_get_backlight_level);int tahvo_get_max_backlight_level (void ) { -if (tahvo_7bit_backlight) +struct tahvo *tahvo = the_tahvo; + +if (tahvo->wide_backlight)return 0x7f ;else return 0x0f ;
@@ -162,7 +173,7 @@ EXPORT_SYMBOL(tahvo_get_max_backlight_level);void tahvo_set_backlight_level (int level) { -int max_level; +int max_level; max_level =tahvo_get_max_backlight_level ();if (level > max_level)
@@ -174,9 +185,11 @@ EXPORT_SYMBOL(tahvo_set_backlight_level);static irqreturn_t tahvo_irq_handler (int irq,void *dev_id) {struct tahvo_irq_handler_desc *hnd; -u16 id; -u16 im; -int i; + +struct tahvo *tahvo = the_tahvo; +u16 id; +u16 im; +int i;for (;;) { id =tahvo_read_reg (TAHVO_REG_IDR );
@@ -192,7 +205,7 @@ static irqreturn_t tahvo_irq_handler(int irq, void *dev_id) hnd = &tahvo_irq_handlers[i];if (hnd->func ==NULL ) {/* Spurious tahvo interrupt - just ack it */ -printk (KERN_INFO "Spurious Tahvo interrupt " +dev_err (tahvo->dev,"Spurious interrupt " "(id %d)\n" , i);tahvo_disable_irq (i);tahvo_ack_irq (i);
@@ -215,19 +228,20 @@ static irqreturn_t tahvo_irq_handler(int irq, void *dev_id)int tahvo_request_irq (int id,void *irq_handler,unsigned long arg,char *name) {struct tahvo_irq_handler_desc *hnd; +struct tahvo *tahvo = the_tahvo;if (irq_handler ==NULL || id >=MAX_TAHVO_IRQ_HANDLERS || name ==NULL ) { - printk(KERN_ERR PFX "Invalid arguments to %s\n", +dev_err (tahvo->dev,"Invalid arguments to %s\n" , __FUNCTION__);return -EINVAL ; } hnd = &tahvo_irq_handlers[id];if (hnd->func !=NULL ) { - printk(KERN_ERR PFX "IRQ %d already reserved\n", id); +dev_err (tahvo->dev,"IRQ %d already reserved\n" , id);return -EBUSY ; } - printk(KERN_INFO PFX "Registering interrupt %d for device %s\n", +dev_dbg (tahvo->dev,"Registering interrupt %d for device %s\n" , id, name); hnd->func = irq_handler; hnd->arg = arg;
@@ -246,15 +260,16 @@ EXPORT_SYMBOL(tahvo_request_irq);void tahvo_free_irq (int id) {struct tahvo_irq_handler_desc *hnd; +struct tahvo *tahvo = the_tahvo;if (id >=MAX_TAHVO_IRQ_HANDLERS ) { - printk(KERN_ERR PFX "Invalid argument to %s\n", +dev_err (tahvo->dev,"Invalid argument to %s\n" , __FUNCTION__);return ; } hnd = &tahvo_irq_handlers[id];if (hnd->func ==NULL ) { - printk(KERN_ERR PFX "IRQ %d already freed\n", id); +dev_err (tahvo->dev,"IRQ %d already freed\n" , id);return ; }
@@ -265,13 +280,24 @@ EXPORT_SYMBOL(tahvo_free_irq);static int __devinit tahvo_probe (struct platform_device *pdev) { -int rev, id, ret; -int irq; +struct tahvo *tahvo; +int rev; +int ret; +int irq; +int id; + + tahvo =kzalloc (sizeof (*tahvo),GFP_KERNEL ); +if (!tahvo) { +dev_err (&pdev->dev,"not enough memory\n" ); + ret = -ENOMEM ; + goto err0; + } -mutex_init (&tahvo_lock); - the_dev = &pdev->dev; + the_tahvo = tahvo; +platform_set_drvdata (pdev, tahvo); - tahvo_initialized =1 ; +mutex_init (&tahvo->mutex); + tahvo->dev = &pdev->dev; rev =tahvo_read_reg (TAHVO_REG_ASICR );
@@ -280,19 +306,20 @@ static int __devinit tahvo_probe(struct platform_device *pdev)switch (id) {case 0x03 :if ((rev &0xff ) >=0x50 ) - tahvo_7bit_backlight =1 ; + tahvo->wide_backlight = true;break ;case 0x0b : - tahvo_is_betty =1 ; - tahvo_7bit_backlight =1 ; + tahvo->is_betty = true; + tahvo->wide_backlight = true;break ;default :dev_err (&pdev->dev,"Tahvo/Betty chip not found" ); -return -ENODEV ; + ret = -ENODEV ; + goto err1; }dev_err (&pdev->dev,"%s v%d.%d found\n" , - tahvo_is_betty ?"Betty" :"Tahvo" , + tahvo->is_betty ?"Betty" :"Tahvo" , (rev >>4 ) &0x0f , rev &0x0f ); irq =platform_get_irq (pdev,0 );
@@ -305,21 +332,30 @@ static int __devinit tahvo_probe(struct platform_device *pdev) "tahvo", 0);if (ret <0 ) {dev_err (&pdev->dev,"Unable to register IRQ handler\n" ); -return ret; + goto err1; } +return 0 ; + +err1: +kfree (tahvo); + +err0: +return ret; } static int __devexit tahvo_remove(struct platform_device *pdev) { -int irq; +struct tahvo *tahvo =platform_get_drvdata (pdev); +int irq; irq =platform_get_irq (pdev,0 );/* Mask all TAHVO interrupts */ tahvo_write_reg (TAHVO_REG_IMR ,0xffff );free_irq (irq,0 ); - the_dev =NULL ; +kfree (tahvo); + the_tahvo =NULL ;return 0 ; }
Signature · 1 line
1.7.6.396.ge0613
PATCH 8/27 cbus: tahvo: pass tahvo to IRQ handler
In reply to Felipe Balbithat way we don't need to access the global
pointer
--- drivers/cbus/tahvo.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/cbus/tahvo.c +3 -3
@@ -182,11 +182,11 @@ void tahvo_set_backlight_level(int level) }EXPORT_SYMBOL (tahvo_set_backlight_level); -static irqreturn_t tahvo_irq_handler (int irq,void *dev_id) +static irqreturn_t tahvo_irq_handler (int irq,void *_tahvo) {struct tahvo_irq_handler_desc *hnd; -struct tahvo *tahvo = the_tahvo; +struct tahvo *tahvo = _tahvo;u16 id;u16 im;int i;
@@ -329,7 +329,7 @@ static int __devinit tahvo_probe(struct platform_device *pdev) ret =request_threaded_irq (irq,NULL , tahvo_irq_handler,IRQF_TRIGGER_RISING |IRQF_ONESHOT , -"tahvo" ,0 ); +"tahvo" , tahvo);if (ret <0 ) {dev_err (&pdev->dev,"Unable to register IRQ handler\n" ); goto err1;
Signature · 1 line
1.7.6.396.ge0613
PATCH 9/27 cbus: tahvo: introduce __tahvo_(read/write)_reg
In reply to Felipe Balbithose two functions are local to tahvo.c and
should be used to read/write Tahvo's registers.
--- drivers/cbus/tahvo.c | 56 +++++++++++++++++++++++++++++++++++-------------- 1 files changed, 40 insertions(+), 16 deletions(-)
drivers/cbus/tahvo.c +40 -16
@@ -67,6 +67,27 @@ int tahvo_get_status(void)EXPORT_SYMBOL (tahvo_get_status);/** +* __tahvo_read_reg - Reads a value from a register in Tahvo +* @tahvo: pointer to tahvo structure +* @reg: the register address to read from +*/ +static int __tahvo_read_reg (struct tahvo *tahvo,unsigned reg) +{ +return cbus_read_reg (tahvo->dev,TAHVO_ID , reg); +} + +/** +* __tahvo_write_reg - Writes a value to a register in Tahvo +* @tahvo: pointer to tahvo structure +* @reg: register address to write to +* @val: the value to be written to @reg +*/ +static void __tahvo_write_reg (struct tahvo *tahvo,unsigned reg,u16 val) +{ +cbus_write_reg (tahvo->dev,TAHVO_ID , reg, val); +} + +/** * tahvo_read_reg - Read a value from a register in Tahvo * @reg: the register to read from *
@@ -76,7 +97,7 @@ int tahvo_read_reg(unsigned reg) {struct tahvo *tahvo = the_tahvo; -return cbus_read_reg (tahvo->dev,TAHVO_ID , reg); +return __tahvo_read_reg (tahvo, reg); }EXPORT_SYMBOL (tahvo_read_reg);
@@ -91,7 +112,7 @@ void tahvo_write_reg(unsigned reg, u16 val) {struct tahvo *tahvo = the_tahvo; -cbus_write_reg (tahvo->dev,TAHVO_ID , reg, val); +__tahvo_write_reg (tahvo, reg, val); }EXPORT_SYMBOL (tahvo_write_reg);
@@ -108,10 +129,10 @@ void tahvo_set_clear_reg_bits(unsigned reg, u16 set, u16 clear)u16 w;mutex_lock (&tahvo->mutex); - w =tahvo_read_reg (reg); + w =__tahvo_read_reg (tahvo, reg); w &= ~clear; w |= set; -tahvo_write_reg (reg, w); +__tahvo_write_reg (tahvo, reg, w);mutex_unlock (&tahvo->mutex); }
@@ -121,9 +142,9 @@ void tahvo_disable_irq(int id)u16 mask;mutex_lock (&tahvo->mutex); - mask =tahvo_read_reg (TAHVO_REG_IMR ); + mask =__tahvo_read_reg (tahvo,TAHVO_REG_IMR ); mask |=1 << id; -tahvo_write_reg (TAHVO_REG_IMR , mask); +__tahvo_write_reg (tahvo,TAHVO_REG_IMR , mask);mutex_unlock (&tahvo->mutex); }EXPORT_SYMBOL (tahvo_disable_irq);
@@ -134,16 +155,18 @@ void tahvo_enable_irq(int id)u16 mask;mutex_lock (&tahvo->mutex); - mask =tahvo_read_reg (TAHVO_REG_IMR ); + mask =__tahvo_read_reg (tahvo,TAHVO_REG_IMR ); mask &= ~(1 << id); -tahvo_write_reg (TAHVO_REG_IMR , mask); +__tahvo_write_reg (tahvo,TAHVO_REG_IMR , mask);mutex_unlock (&tahvo->mutex); }EXPORT_SYMBOL (tahvo_enable_irq);void tahvo_ack_irq (int id) { -tahvo_write_reg (TAHVO_REG_IDR ,1 << id); +struct tahvo *tahvo = the_tahvo; + +__tahvo_write_reg (tahvo,TAHVO_REG_IDR ,1 << id); }EXPORT_SYMBOL (tahvo_ack_irq);
@@ -156,7 +179,7 @@ int tahvo_get_backlight_level(void) mask =0x7f ; else mask =0x0f ; -return tahvo_read_reg (TAHVO_REG_LEDPWMR ) & mask; +return __tahvo_read_reg (tahvo,TAHVO_REG_LEDPWMR ) & mask; }EXPORT_SYMBOL (tahvo_get_backlight_level);
@@ -173,12 +196,13 @@ EXPORT_SYMBOL(tahvo_get_max_backlight_level);void tahvo_set_backlight_level (int level) { +struct tahvo *tahvo = the_tahvo;int max_level; max_level =tahvo_get_max_backlight_level ();if (level > max_level) level = max_level; -tahvo_write_reg (TAHVO_REG_LEDPWMR , level); +__tahvo_write_reg (tahvo,TAHVO_REG_LEDPWMR , level); }EXPORT_SYMBOL (tahvo_set_backlight_level);
@@ -192,8 +216,8 @@ static irqreturn_t tahvo_irq_handler(int irq, void *_tahvo)int i;for (;;) { - id =tahvo_read_reg (TAHVO_REG_IDR ); - im = ~tahvo_read_reg (TAHVO_REG_IMR ); + id =__tahvo_read_reg (tahvo,TAHVO_REG_IDR ); + im = ~__tahvo_read_reg (tahvo,TAHVO_REG_IMR ); id &= im;if (!id)
@@ -299,7 +323,7 @@ static int __devinit tahvo_probe(struct platform_device *pdev)mutex_init (&tahvo->mutex); tahvo->dev = &pdev->dev; - rev =tahvo_read_reg (TAHVO_REG_ASICR ); + rev =__tahvo_read_reg (tahvo,TAHVO_REG_ASICR ); id = (rev >>8 ) &0xff ;
@@ -325,7 +349,7 @@ static int __devinit tahvo_probe(struct platform_device *pdev) irq =platform_get_irq (pdev,0 );/* Mask all TAHVO interrupts */ -tahvo_write_reg (TAHVO_REG_IMR ,0xffff ); +__tahvo_write_reg (tahvo,TAHVO_REG_IMR ,0xffff ); ret = request_threaded_irq(irq, NULL, tahvo_irq_handler, IRQF_TRIGGER_RISING | IRQF_ONESHOT,
@@ -352,7 +376,7 @@ static int __devexit tahvo_remove(struct platform_device *pdev) irq =platform_get_irq (pdev,0 );/* Mask all TAHVO interrupts */ -tahvo_write_reg (TAHVO_REG_IMR ,0xffff ); +__tahvo_write_reg (tahvo,TAHVO_REG_IMR ,0xffff );free_irq (irq,0 );kfree (tahvo); the_tahvo =NULL ;
Signature · 1 line
1.7.6.396.ge0613
PATCH 10/27 cbus: tahvo: drop some unneded defines
In reply to Felipe Balbino functional changes.
--- drivers/cbus/tahvo.c | 8 +++----- 1 files changed, 3 insertions(+), 5 deletions(-)
drivers/cbus/tahvo.c +3 -5
@@ -33,14 +33,12 @@#include <linux/irq.h> #include <linux/interrupt.h> #include <linux/platform_device.h> +#include <linux/platform_data/cbus.h> #include <linux/mutex.h> #include "cbus.h" #include "tahvo.h" -#define TAHVO_ID 0x02 -#define PFX "tahvo: " -struct tahvo {/* device lock */ struct mutex mutex;
@@ -73,7 +71,7 @@ EXPORT_SYMBOL(tahvo_get_status);*/ static int __tahvo_read_reg (struct tahvo *tahvo,unsigned reg) { -return cbus_read_reg (tahvo->dev,TAHVO_ID , reg); +return cbus_read_reg (tahvo->dev,CBUS_TAHVO_DEVICE_ID , reg); }/**
@@ -84,7 +82,7 @@ static int __tahvo_read_reg(struct tahvo *tahvo, unsigned reg)*/ static void __tahvo_write_reg (struct tahvo *tahvo,unsigned reg,u16 val) { -cbus_write_reg (tahvo->dev,TAHVO_ID , reg, val); +cbus_write_reg (tahvo->dev,CBUS_TAHVO_DEVICE_ID , reg, val); }/**
Signature · 1 line
1.7.6.396.ge0613
PATCH 11/27 cbus: retu: IRQ demux optimization
In reply to Felipe Balbiit's definitely not always that we will have all 16 interrupts fired at the same time, so in order to avoid looping so many times, we are now using ffs() which is implemented (on ARM) using the far better clz instruction.
This will save us quite some loops and could improve IRQ latency on Retu significantly (no actual measurements were made, though)
--- drivers/cbus/retu.c | 14 ++++++++------ 1 files changed, 8 insertions(+), 6 deletions(-)
drivers/cbus/retu.c +8 -6
@@ -36,6 +36,8 @@#include <linux/platform_device.h> #include <linux/platform_data/cbus.h> +#include <asm/bitops.h> +#include "cbus.h" #include "retu.h"
@@ -183,8 +185,6 @@ static irqreturn_t retu_irq_handler(int irq, void *_retu) {struct retu *retu = _retu; -int i; -u16 idr;u16 imr;
@@ -199,11 +199,13 @@ static irqreturn_t retu_irq_handler(int irq, void *_retu)return IRQ_NONE ; } -for (i = retu->irq_base; idr !=0 ; i++, idr >>=1 ) { -if (!(idr &1 )) -continue ; +while (idr) { +unsigned long pending =__ffs (idr); +unsigned int irq; -handle_nested_irq (i); + idr &= ~BIT (pending); + irq = pending + retu->irq_base; +handle_nested_irq (irq); }return IRQ_HANDLED ;
Signature · 1 line
1.7.6.396.ge0613
PATCH 12/27 cbus: tahvo: give it an irq_chip
In reply to Felipe Balbitahvo also has IRQs to demux to its children, so lets give it a struct irq_chip so that child drivers can use standard request_threaded_irq().
This is still an unused irq_chip, later patches will come to make proper use of it.
--- drivers/cbus/tahvo.c | 128 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 120 insertions(+), 8 deletions(-)
drivers/cbus/tahvo.c +120 -8
@@ -44,8 +44,17 @@ struct tahvo {struct mutex mutex;struct device *dev; -unsigned int is_betty; -unsigned int wide_backlight; +int irq_base; +int irq_end; +int irq; + +int ack; +int mask; + + unsigned int wide_backlight:1; + unsigned int mask_pending:1; + unsigned int ack_pending:1; + unsigned int is_betty:1; };static struct tahvo *the_tahvo;
@@ -300,6 +309,94 @@ void tahvo_free_irq(int id) }EXPORT_SYMBOL (tahvo_free_irq); +/* -------------------------------------------------------------------------- */ + +static void tahvo_irq_bus_lock (struct irq_data *data) +{ +struct tahvo *tahvo =irq_data_get_irq_chip_data (data); + +mutex_lock (&tahvo->mutex); +} + +static void tahvo_irq_bus_sync_unlock (struct irq_data *data) +{ +struct tahvo *tahvo =irq_data_get_irq_chip_data (data); + +if (tahvo->mask_pending) { +__tahvo_write_reg (tahvo,TAHVO_REG_IMR , tahvo->mask); + tahvo->mask_pending = false; + } + +if (tahvo->ack_pending) { +__tahvo_write_reg (tahvo,TAHVO_REG_IDR , tahvo->ack); + tahvo->ack_pending = false; + } + +mutex_unlock (&tahvo->mutex); +} + +static void tahvo_irq_mask (struct irq_data *data) +{ +struct tahvo *tahvo =irq_data_get_irq_chip_data (data); +int irq = data->irq; + + tahvo->mask |= (1 << (irq - tahvo->irq_base)); + tahvo->mask_pending = true; +} + +static void tahvo_irq_unmask (struct irq_data *data) +{ +struct tahvo *tahvo =irq_data_get_irq_chip_data (data); +int irq = data->irq; + + tahvo->mask &= ~(1 << (irq - tahvo->irq_base)); + tahvo->mask_pending = true; +} + +static void tahvo_irq_ack (struct irq_data *data) +{ +struct tahvo *tahvo =irq_data_get_irq_chip_data (data); +int irq = data->irq; + + tahvo->ack |= (1 << (irq - tahvo->irq_base)); + tahvo->ack_pending = true; +} + +static struct irq_chip tahvo_irq_chip = { + .name ="tahvo" , + .irq_bus_lock = tahvo_irq_bus_lock, + .irq_bus_sync_unlock = tahvo_irq_bus_sync_unlock, + .irq_mask = tahvo_irq_mask, + .irq_unmask = tahvo_irq_unmask, + .irq_ack = tahvo_irq_ack, +}; + +static inline void tahvo_irq_setup (int irq) +{ +#ifdef CONFIG_ARM +set_irq_flags (irq,IRQF_VALID ); +#else +set_irq_noprobe (irq); +#endif +} + +static void tahvo_irq_init (struct tahvo *tahvo) +{ +int base = tahvo->irq_base; +int end = tahvo->irq_end; +int irq; + +for (irq = base; irq < end; irq++) { +irq_set_chip_data (irq, tahvo); +irq_set_chip_and_handler (irq, &tahvo_irq_chip, + handle_simple_irq); +irq_set_nested_thread (irq,1 ); +tahvo_irq_setup (irq); + } +} + +/* -------------------------------------------------------------------------- */ +static int __devinit tahvo_probe (struct platform_device *pdev) {struct tahvo *tahvo;
@@ -315,11 +412,24 @@ static int __devinit tahvo_probe(struct platform_device *pdev) goto err0; } - the_tahvo = tahvo; + irq =platform_get_irq (pdev,0 );platform_set_drvdata (pdev, tahvo);mutex_init (&tahvo->mutex); - tahvo->dev = &pdev->dev; + + ret =irq_alloc_descs (-1 ,0 ,MAX_TAHVO_IRQ_HANDLERS ,0 ); +if (ret <0 ) { +dev_err (&pdev->dev,"failed to allocate IRQ descs\n" ); + goto err1; + } + + tahvo->irq_base = ret; + tahvo->irq_end = ret +MAX_TAHVO_IRQ_HANDLERS ; + tahvo->dev = &pdev->dev; + tahvo->irq = irq; + the_tahvo = tahvo; + +tahvo_irq_init (tahvo); rev =__tahvo_read_reg (tahvo,TAHVO_REG_ASICR );
@@ -337,15 +447,13 @@ static int __devinit tahvo_probe(struct platform_device *pdev)default :dev_err (&pdev->dev,"Tahvo/Betty chip not found" ); ret = -ENODEV ; - goto err1; + goto err2; }dev_err (&pdev->dev,"%s v%d.%d found\n" , tahvo->is_betty ?"Betty" :"Tahvo" , (rev >>4 ) &0x0f , rev &0x0f ); - irq =platform_get_irq (pdev,0 ); -/* Mask all TAHVO interrupts */ __tahvo_write_reg (tahvo,TAHVO_REG_IMR ,0xffff );
@@ -354,11 +462,14 @@ static int __devinit tahvo_probe(struct platform_device *pdev) "tahvo", tahvo);if (ret <0 ) {dev_err (&pdev->dev,"Unable to register IRQ handler\n" ); - goto err1; + goto err2; }return 0 ; +err2: +irq_free_descs (tahvo->irq_base,MAX_TAHVO_IRQ_HANDLERS ); + err1:kfree (tahvo);
@@ -376,6 +487,7 @@ static int __devexit tahvo_remove(struct platform_device *pdev)/* Mask all TAHVO interrupts */ __tahvo_write_reg (tahvo,TAHVO_REG_IMR ,0xffff );free_irq (irq,0 ); +irq_free_descs (tahvo->irq_base,MAX_TAHVO_IRQ_HANDLERS );kfree (tahvo); the_tahvo =NULL ;
Signature · 1 line
1.7.6.396.ge0613
PATCH 13/27 cbus: tahvo: start using irq_chip
In reply to Felipe Balbiin order to chieve that, we needed to allocate
our children devices (currently only one) and
fix up the irq handler.
--- arch/arm/mach-omap1/board-nokia770.c | 6 -- arch/arm/mach-omap2/board-n8x0.c | 6 -- drivers/cbus/tahvo.c | 110 ++++++++++++++++++++++++--------- 3 files changed, 80 insertions(+), 42 deletions(-)
arch/arm/mach-omap1/board-nokia770.c +0 -6
@@ -155,11 +155,6 @@ static struct platform_device tahvo_device = { }, }; -static struct platform_device tahvo_usb_device = { - .name ="tahvo-usb" , - .id =-1 , -}; -static void __init nokia770_cbus_init (void ) {int ret;
@@ -200,7 +195,6 @@ static void __init nokia770_cbus_init(void) tahvo_resource[0 ].start =gpio_to_irq (40 ); platform_device_register(&tahvo_device); - platform_device_register(&tahvo_usb_device); }#else
arch/arm/mach-omap2/board-n8x0.c +0 -6
@@ -251,11 +251,6 @@ static struct platform_device tahvo_device = { }, }; -static struct platform_device tahvo_usb_device = { - .name ="tahvo-usb" , - .id =-1 , -}; -static void __init n8x0_cbus_init (void ) {int ret;
@@ -297,7 +292,6 @@ static void __init n8x0_cbus_init(void) tahvo_resource[0 ].start =gpio_to_irq (111 ); platform_device_register(&tahvo_device); - platform_device_register(&tahvo_usb_device); }#else
drivers/cbus/tahvo.c +80 -30
131 lines not on this page · raw message
Signature · 1 line
1.7.6.396.ge0613
PATCH 14/27 cbus: tahvo: usb: fix up to use threaded irqs
In reply to Felipe Balbifix up tahvo-usb to use threaded irqs and the
new IRQ chip.
--- drivers/cbus/tahvo-usb.c | 35 +++++++++++++---------------------- 1 files changed, 13 insertions(+), 22 deletions(-)
drivers/cbus/tahvo-usb.c +13 -22
@@ -93,12 +93,13 @@ struct tahvo_usb {struct platform_device *pt_dev;struct otg_transceiver otg;int vbus_state; -struct work_struct irq_work;struct mutex serialize;#ifdef CONFIG_USB_OTG int tahvo_mode;#endif struct clk *ick; + +int irq; };static struct tahvo_usb *tahvo_usb_device;
@@ -523,23 +524,13 @@ static int tahvo_usb_set_peripheral(struct otg_transceiver *otg, struct usb_gadgreturn 0 ; } -static void tahvo_usb_irq_work (struct work_struct *work) +static irqreturn_t tahvo_usb_vbus_interrupt (int irq,void *_tu) { - struct tahvo_usb *tu = container_of(work, struct tahvo_usb, irq_work); +struct tahvo_usb *tu = _tu; -mutex_lock (&tu->serialize);check_vbus_state (tu); -mutex_unlock (&tu->serialize); -} -static void tahvo_usb_vbus_interrupt (unsigned long arg) -{ -struct tahvo_usb *tu = (struct tahvo_usb *) arg; - -tahvo_ack_irq (TAHVO_INT_VBUSON ); -/* Seems we need this to acknowledge the interrupt */ -tahvo_read_reg (TAHVO_REG_IDSR ); -schedule_work (&tu->irq_work); +return IRQ_HANDLED ; }#ifdef CONFIG_USB_OTG
@@ -602,6 +593,7 @@ static int __init tahvo_usb_probe(struct platform_device *pdev)struct tahvo_usb *tu;struct device *dev = &pdev->dev;int ret; +int irq; ret =tahvo_get_status ();if (!ret)
@@ -625,7 +617,6 @@ static int __init tahvo_usb_probe(struct platform_device *pdev)#endif #endif -INIT_WORK (&tu->irq_work, tahvo_usb_irq_work);mutex_init (&tu->serialize); tu->ick =clk_get (NULL ,"usb_l4_ick" );
@@ -640,9 +631,12 @@ static int __init tahvo_usb_probe(struct platform_device *pdev)* state changes */ tu->vbus_state =tahvo_read_reg (TAHVO_REG_IDSR ) &0x01 ; + irq =platform_get_irq (pdev,0 ); + tu->irq = irq; +/* We cannot enable interrupt until omap_udc is initialized */ - ret =tahvo_request_irq (TAHVO_INT_VBUSON , tahvo_usb_vbus_interrupt, - (unsigned long ) tu,"vbus_interrupt" ); + ret =request_threaded_irq (irq,NULL , tahvo_usb_vbus_interrupt, +IRQF_ONESHOT ,"tahvo-vbus" , tu);if (ret !=0 ) {printk (KERN_ERR "Could not register Tahvo interrupt for VBUS\n" ); goto err_release_clk;
@@ -675,13 +669,10 @@ static int __init tahvo_usb_probe(struct platform_device *pdev)dev_set_drvdata (dev, tu); -/* Act upon current vbus state once at startup. A vbus state irq may or -* may not be generated in addition to this. */ -schedule_work (&tu->irq_work);return 0 ; err_free_irq: -tahvo_free_irq (TAHVO_INT_VBUSON ); +free_irq (tu->irq, tu); err_release_clk:clk_disable (tu->ick);clk_put (tu->ick);
@@ -698,7 +689,7 @@ static int __exit tahvo_usb_remove(struct platform_device *pdev)dev_dbg (&pdev->dev,"remove\n" ); -tahvo_free_irq (TAHVO_INT_VBUSON ); +free_irq (tu->irq, tu);flush_scheduled_work ();otg_set_transceiver (0 );device_remove_file (&pdev->dev, &dev_attr_vbus_state);
Signature · 1 line
1.7.6.396.ge0613
PATCH 15/27 cbus: tahvo drop the legacy interfaces
In reply to Felipe Balbithose tahvo-specific IRQ handling routines
aren't needed anymore. Drop'em.
--- drivers/cbus/tahvo.c | 64 -------------------------------------------------- drivers/cbus/tahvo.h | 5 ---- 2 files changed, 0 insertions(+), 69 deletions(-)
drivers/cbus/tahvo.c +0 -64
@@ -59,14 +59,6 @@ struct tahvo {static struct tahvo *the_tahvo; -struct tahvo_irq_handler_desc { -int (*func)(unsigned long ); -unsigned long arg; -char name[8 ]; -}; - -static struct tahvo_irq_handler_desc tahvo_irq_handlers[MAX_TAHVO_IRQ_HANDLERS ]; -int tahvo_get_status (void ) {return the_tahvo !=NULL ;
@@ -240,62 +232,6 @@ static irqreturn_t tahvo_irq_handler(int irq, void *_tahvo)return IRQ_HANDLED ; } -/* -* Register the handler for a given TAHVO interrupt source. -*/ -int tahvo_request_irq (int id,void *irq_handler,unsigned long arg,char *name) -{ -struct tahvo_irq_handler_desc *hnd; -struct tahvo *tahvo = the_tahvo; - -if (irq_handler ==NULL || id >=MAX_TAHVO_IRQ_HANDLERS || - name ==NULL ) { -dev_err (tahvo->dev,"Invalid arguments to %s\n" , - __FUNCTION__); -return -EINVAL ; - } - hnd = &tahvo_irq_handlers[id]; -if (hnd->func !=NULL ) { -dev_err (tahvo->dev,"IRQ %d already reserved\n" , id); -return -EBUSY ; - } -dev_dbg (tahvo->dev,"Registering interrupt %d for device %s\n" , - id, name); - hnd->func = irq_handler; - hnd->arg = arg; -strlcpy (hnd->name, name,sizeof (hnd->name)); - -tahvo_ack_irq (id); -tahvo_enable_irq (id); - -return 0 ; -} -EXPORT_SYMBOL (tahvo_request_irq); - -/* -* Unregister the handler for a given TAHVO interrupt source. -*/ -void tahvo_free_irq (int id) -{ -struct tahvo_irq_handler_desc *hnd; -struct tahvo *tahvo = the_tahvo; - -if (id >=MAX_TAHVO_IRQ_HANDLERS ) { -dev_err (tahvo->dev,"Invalid argument to %s\n" , - __FUNCTION__); -return ; - } - hnd = &tahvo_irq_handlers[id]; -if (hnd->func ==NULL ) { -dev_err (tahvo->dev,"IRQ %d already freed\n" , id); -return ; - } - -tahvo_disable_irq (id); - hnd->func =NULL ; -} -EXPORT_SYMBOL (tahvo_free_irq); -/* -------------------------------------------------------------------------- */ static void tahvo_irq_bus_lock (struct irq_data *data)
drivers/cbus/tahvo.h +0 -5
@@ -54,11 +54,6 @@ int tahvo_get_status(void);int tahvo_read_reg (unsigned reg);void tahvo_write_reg (unsigned reg,u16 val);void tahvo_set_clear_reg_bits (unsigned reg,u16 set,u16 clear); -int tahvo_request_irq (int id,void *irq_handler,unsigned long arg,char *name); -void tahvo_free_irq (int id); -void tahvo_enable_irq (int id); -void tahvo_disable_irq (int id); -void tahvo_ack_irq (int id);int tahvo_get_backlight_level (void );int tahvo_get_max_backlight_level (void );void tahvo_set_backlight_level (int level);
Signature · 1 line
1.7.6.396.ge0613
PATCH 16/27 cbus: tahvo: usb: drop unused variable
In reply to Felipe Balbino functional changes.
--- drivers/cbus/tahvo-usb.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
drivers/cbus/tahvo-usb.c +0 -1
@@ -116,7 +116,6 @@ static struct platform_device *tahvo_otg_dev;static irqreturn_t omap_otg_irq (int irq,void *arg) { -struct tahvo_usb *tu = arg;u16 otg_irq; otg_irq =omap_readw (OTG_IRQ_SRC );
Signature · 1 line
1.7.6.396.ge0613
PATCH 17/27 cbus: tahvo: no need to mask interrupts on exit
In reply to Felipe Balbithe children will be unloaded first and they
will make sure to mask their own IRQ.
While at that, also move subsys_init_call()
close to tahvo_init().
--- drivers/cbus/tahvo.c | 5 +---- 1 files changed, 1 insertions(+), 4 deletions(-)
drivers/cbus/tahvo.c +1 -4
@@ -470,8 +470,6 @@ static int __devexit tahvo_remove(struct platform_device *pdev) irq =platform_get_irq (pdev,0 ); -/* Mask all TAHVO interrupts */ -__tahvo_write_reg (tahvo,TAHVO_REG_IMR ,0xffff );free_irq (irq,0 );irq_free_descs (tahvo->irq_base,MAX_TAHVO_IRQ_HANDLERS );kfree (tahvo);
@@ -491,13 +489,12 @@ static int __init tahvo_init(void) {return platform_driver_probe (&tahvo_driver, tahvo_probe); } +subsys_initcall (tahvo_init); static void __exit tahvo_exit(void) {platform_driver_unregister (&tahvo_driver); } - -subsys_initcall (tahvo_init);module_exit (tahvo_exit);MODULE_DESCRIPTION ("Tahvo ASIC control" );
Signature · 1 line
1.7.6.396.ge0613
PATCH 18/27 cbus: tahvo: drop the get_status hack
In reply to Felipe Balbithat's really not needed.
--- drivers/cbus/tahvo-usb.c | 4 ---- drivers/cbus/tahvo.c | 6 ------ drivers/cbus/tahvo.h | 1 - 3 files changed, 0 insertions(+), 11 deletions(-)
drivers/cbus/tahvo-usb.c +0 -4
@@ -594,10 +594,6 @@ static int __init tahvo_usb_probe(struct platform_device *pdev)int ret;int irq; - ret =tahvo_get_status (); -if (!ret) -return -ENODEV ; -dev_dbg (dev,"probe\n" );/* Create driver data */
drivers/cbus/tahvo.c +0 -6
@@ -59,12 +59,6 @@ struct tahvo {static struct tahvo *the_tahvo; -int tahvo_get_status (void ) -{ -return the_tahvo !=NULL ; -} -EXPORT_SYMBOL (tahvo_get_status); -/** * __tahvo_read_reg - Reads a value from a register in Tahvo * @tahvo: pointer to tahvo structure
drivers/cbus/tahvo.h +0 -1
@@ -50,7 +50,6 @@#define MAX_TAHVO_IRQ_HANDLERS 8 -int tahvo_get_status (void );int tahvo_read_reg (unsigned reg);void tahvo_write_reg (unsigned reg,u16 val);void tahvo_set_clear_reg_bits (unsigned reg,u16 set,u16 clear);
Signature · 1 line
1.7.6.396.ge0613
PATCH 19/27 cbus: tahvo: drop more unused interfaces
In reply to Felipe Balbiwe have the IRQ chip which is the standard
way of handling IRQs.
--- drivers/cbus/tahvo.c | 34 ---------------------------------- 1 files changed, 0 insertions(+), 34 deletions(-)
drivers/cbus/tahvo.c +0 -34
@@ -129,40 +129,6 @@ void tahvo_set_clear_reg_bits(unsigned reg, u16 set, u16 clear)mutex_unlock (&tahvo->mutex); } -void tahvo_disable_irq (int id) -{ -struct tahvo *tahvo = the_tahvo; -u16 mask; - -mutex_lock (&tahvo->mutex); - mask =__tahvo_read_reg (tahvo,TAHVO_REG_IMR ); - mask |=1 << id; -__tahvo_write_reg (tahvo,TAHVO_REG_IMR , mask); -mutex_unlock (&tahvo->mutex); -} -EXPORT_SYMBOL (tahvo_disable_irq); - -void tahvo_enable_irq (int id) -{ -struct tahvo *tahvo = the_tahvo; -u16 mask; - -mutex_lock (&tahvo->mutex); - mask =__tahvo_read_reg (tahvo,TAHVO_REG_IMR ); - mask &= ~(1 << id); -__tahvo_write_reg (tahvo,TAHVO_REG_IMR , mask); -mutex_unlock (&tahvo->mutex); -} -EXPORT_SYMBOL (tahvo_enable_irq); - -void tahvo_ack_irq (int id) -{ -struct tahvo *tahvo = the_tahvo; - -__tahvo_write_reg (tahvo,TAHVO_REG_IDR ,1 << id); -} -EXPORT_SYMBOL (tahvo_ack_irq); -int tahvo_get_backlight_level (void ) {struct tahvo *tahvo = the_tahvo;
Signature · 1 line
1.7.6.396.ge0613
PATCH 20/27 cbus: tahvo: pass child device pointer
In reply to Felipe Balbion read/write register operations, if we pass
the child device pointer, it becomes really easy
to access our device structure. Let's do so.
--- drivers/cbus/tahvo-usb.c | 18 ++++++++++-------- drivers/cbus/tahvo.c | 18 +++++++++++------- drivers/cbus/tahvo.h | 7 ++++--- 3 files changed, 25 insertions(+), 18 deletions(-)
drivers/cbus/tahvo-usb.c +10 -8
@@ -90,6 +90,7 @@#endif struct tahvo_usb { +struct device *dev;struct platform_device *pt_dev;struct otg_transceiver otg;int vbus_state;
@@ -240,7 +241,7 @@ static void check_vbus_state(struct tahvo_usb *tu) {int reg, prev_state; - reg =tahvo_read_reg (TAHVO_REG_IDSR ); + reg =tahvo_read_reg (tu->dev,TAHVO_REG_IDSR );if (reg &0x01 ) {u32 l;
@@ -304,7 +305,7 @@ static void tahvo_usb_become_host(struct tahvo_usb *tu)omap_writel (l,OTG_CTRL );/* Power up the transceiver in USB host mode */ -tahvo_write_reg (TAHVO_REG_USBR ,USBR_REGOUT |USBR_NSUSPEND | +tahvo_write_reg (tu->dev,TAHVO_REG_USBR ,USBR_REGOUT |USBR_NSUSPEND |USBR_MASTER_SW2 |USBR_MASTER_SW1 ); tu->otg.state =OTG_STATE_A_IDLE ;
@@ -330,7 +331,7 @@ static void tahvo_usb_become_peripheral(struct tahvo_usb *tu)omap_writel (l,OTG_CTRL );/* Power up transceiver and set it in USB perhiperal mode */ -tahvo_write_reg (TAHVO_REG_USBR ,USBR_SLAVE_CONTROL |USBR_REGOUT |USBR_NSUSPEND |USBR_SLAVE_SW ); +tahvo_write_reg (tu->dev,TAHVO_REG_USBR ,USBR_SLAVE_CONTROL |USBR_REGOUT |USBR_NSUSPEND |USBR_SLAVE_SW ); tu->otg.state =OTG_STATE_B_IDLE ;check_vbus_state (tu);
@@ -380,7 +381,7 @@ static void tahvo_usb_power_off(struct tahvo_usb *tu)omap_writel (l,OTG_SYSCON_1 );/* Power off transceiver */ -tahvo_write_reg (TAHVO_REG_USBR ,0 ); +tahvo_write_reg (tu->dev,TAHVO_REG_USBR ,0 ); tu->otg.state =OTG_STATE_UNDEFINED ; }
@@ -404,12 +405,12 @@ static int tahvo_usb_set_suspend(struct otg_transceiver *dev, int suspend)dev_dbg (&tu->pt_dev->dev,"set_suspend\n" ); - w =tahvo_read_reg (TAHVO_REG_USBR ); + w =tahvo_read_reg (tu->dev,TAHVO_REG_USBR );if (suspend) w &= ~USBR_NSUSPEND ;else w |=USBR_NSUSPEND ; -tahvo_write_reg (TAHVO_REG_USBR , w); +tahvo_write_reg (tu->dev,TAHVO_REG_USBR , w);return 0 ; }
@@ -602,7 +603,8 @@ static int __init tahvo_usb_probe(struct platform_device *pdev)return -ENOMEM ; tahvo_usb_device = tu; - tu->pt_dev = container_of(dev, struct platform_device, dev); + tu->dev = dev; + tu->pt_dev = pdev;#ifdef CONFIG_USB_OTG /* Default mode */ #ifdef CONFIG_CBUS_TAHVO_USB_HOST_BY_DEFAULT
@@ -624,7 +626,7 @@ static int __init tahvo_usb_probe(struct platform_device *pdev)/* Set initial state, so that we generate kevents only on * state changes */ - tu->vbus_state =tahvo_read_reg (TAHVO_REG_IDSR ) &0x01 ; + tu->vbus_state =tahvo_read_reg (tu->dev,TAHVO_REG_IDSR ) &0x01 ; irq =platform_get_irq (pdev,0 ); tu->irq = irq;
drivers/cbus/tahvo.c +11 -7
@@ -82,13 +82,14 @@ static void __tahvo_write_reg(struct tahvo *tahvo, unsigned reg, u16 val)/** * tahvo_read_reg - Read a value from a register in Tahvo +* @child: device pointer from the calling child * @reg: the register to read from * * This function returns the contents of the specified register */ -int tahvo_read_reg (unsigned reg) +int tahvo_read_reg (struct device *child,unsigned reg) { -struct tahvo *tahvo = the_tahvo; +struct tahvo *tahvo =dev_get_drvdata (child->parent);return __tahvo_read_reg (tahvo, reg); }
@@ -96,14 +97,15 @@ EXPORT_SYMBOL(tahvo_read_reg);/** * tahvo_write_reg - Write a value to a register in Tahvo +* @child: device pointer from the calling child * @reg: the register to write to -* @reg: the value to write to the register +* @val : the value to write to the register * * This function writes a value to the specified register */ -void tahvo_write_reg (unsigned reg,u16 val) +void tahvo_write_reg (struct device *child,unsigned reg,u16 val) { -struct tahvo *tahvo = the_tahvo; +struct tahvo *tahvo =dev_get_drvdata (child->parent);__tahvo_write_reg (tahvo, reg, val); }
@@ -111,14 +113,16 @@ EXPORT_SYMBOL(tahvo_write_reg);/** * tahvo_set_clear_reg_bits - set and clear register bits atomically +* @child: device pointer from the calling child * @reg: the register to write to * @bits: the bits to set * * This function sets and clears the specified Tahvo register bits atomically */ -void tahvo_set_clear_reg_bits (unsigned reg,u16 set,u16 clear) +void tahvo_set_clear_reg_bits (struct device *child,unsigned reg,u16 set, +u16 clear) { -struct tahvo *tahvo = the_tahvo; +struct tahvo *tahvo =dev_get_drvdata (child->parent);u16 w;mutex_lock (&tahvo->mutex);
drivers/cbus/tahvo.h +4 -3
@@ -50,9 +50,10 @@#define MAX_TAHVO_IRQ_HANDLERS 8 -int tahvo_read_reg (unsigned reg); -void tahvo_write_reg (unsigned reg,u16 val); -void tahvo_set_clear_reg_bits (unsigned reg,u16 set,u16 clear); +int tahvo_read_reg (struct device *child,unsigned reg); +void tahvo_write_reg (struct device *child,unsigned reg,u16 val); +void tahvo_set_clear_reg_bits (struct device *child,unsigned reg,u16 set, +u16 clear);int tahvo_get_backlight_level (void );int tahvo_get_max_backlight_level (void );void tahvo_set_backlight_level (int level);
Signature · 1 line
1.7.6.396.ge0613
PATCH 21/27 cbus: tahvo: drop backlight interfaces
In reply to Felipe Balbithey aren't used by anyone and they should
be, anyways, on a child LED driver not on
core Tahvo.
--- drivers/cbus/tahvo.c | 51 +------------------------------------------------- drivers/cbus/tahvo.h | 3 -- 2 files changed, 1 insertions(+), 53 deletions(-)
drivers/cbus/tahvo.c +1 -50
@@ -51,7 +51,6 @@ struct tahvo {int ack;int mask; - unsigned int wide_backlight:1; unsigned int mask_pending:1; unsigned int ack_pending:1; unsigned int is_betty:1;
@@ -133,42 +132,6 @@ void tahvo_set_clear_reg_bits(struct device *child, unsigned reg, u16 set,mutex_unlock (&tahvo->mutex); } -int tahvo_get_backlight_level (void ) -{ -struct tahvo *tahvo = the_tahvo; -int mask; - -if (tahvo->wide_backlight) - mask =0x7f ; -else - mask =0x0f ; -return __tahvo_read_reg (tahvo,TAHVO_REG_LEDPWMR ) & mask; -} -EXPORT_SYMBOL (tahvo_get_backlight_level); - -int tahvo_get_max_backlight_level (void ) -{ -struct tahvo *tahvo = the_tahvo; - -if (tahvo->wide_backlight) -return 0x7f ; -else -return 0x0f ; -} -EXPORT_SYMBOL (tahvo_get_max_backlight_level); - -void tahvo_set_backlight_level (int level) -{ -struct tahvo *tahvo = the_tahvo; -int max_level; - - max_level =tahvo_get_max_backlight_level (); -if (level > max_level) - level = max_level; -__tahvo_write_reg (tahvo,TAHVO_REG_LEDPWMR , level); -} -EXPORT_SYMBOL (tahvo_set_backlight_level); -static irqreturn_t tahvo_irq_handler (int irq,void *_tahvo) {struct tahvo *tahvo = _tahvo;
@@ -379,20 +342,8 @@ static int __devinit tahvo_probe(struct platform_device *pdev) id = (rev >>8 ) &0xff ; -switch (id) { -case 0x03 : -if ((rev &0xff ) >=0x50 ) - tahvo->wide_backlight = true; -break ; -case 0x0b : +if (id ==0x0b ) tahvo->is_betty = true; - tahvo->wide_backlight = true; -break ; -default : -dev_err (&pdev->dev,"Tahvo/Betty chip not found" ); - ret = -ENODEV ; - goto err2; - } ret =tahvo_allocate_children (&pdev->dev, tahvo->irq_base);if (ret <0 ) {
drivers/cbus/tahvo.h +0 -3
@@ -54,8 +54,5 @@ int tahvo_read_reg(struct device *child, unsigned reg);void tahvo_write_reg (struct device *child,unsigned reg,u16 val);void tahvo_set_clear_reg_bits (struct device *child,unsigned reg,u16 set,u16 clear); -int tahvo_get_backlight_level (void ); -int tahvo_get_max_backlight_level (void ); -void tahvo_set_backlight_level (int level);#endif /* __DRIVERS_CBUS_TAHVO_H */
Signature · 1 line
1.7.6.396.ge0613
PATCH 22/27 cbus: tahvo: drop static global pointer
In reply to Felipe Balbithat's not used anywhere anymore. We can
safely drop it.
--- drivers/cbus/tahvo.c | 4 ---- 1 files changed, 0 insertions(+), 4 deletions(-)
drivers/cbus/tahvo.c +0 -4
@@ -56,8 +56,6 @@ struct tahvo { unsigned int is_betty:1; }; -static struct tahvo *the_tahvo; -/** * __tahvo_read_reg - Reads a value from a register in Tahvo * @tahvo: pointer to tahvo structure
@@ -334,7 +332,6 @@ static int __devinit tahvo_probe(struct platform_device *pdev) tahvo->irq_end = ret +MAX_TAHVO_IRQ_HANDLERS ; tahvo->dev = &pdev->dev; tahvo->irq = irq; - the_tahvo = tahvo;tahvo_irq_init (tahvo);
@@ -388,7 +385,6 @@ static int __devexit tahvo_remove(struct platform_device *pdev)free_irq (irq,0 );irq_free_descs (tahvo->irq_base,MAX_TAHVO_IRQ_HANDLERS );kfree (tahvo); - the_tahvo =NULL ;return 0 ; }
Signature · 1 line
1.7.6.396.ge0613
PATCH 23/27 cbus: tahvo: prepare for children without IRQ
In reply to Felipe Balbinot all tahvo children have a dedicated IRQ
so don't add a resource for those.
--- drivers/cbus/tahvo.c | 16 +++++++++------- 1 files changed, 9 insertions(+), 7 deletions(-)
drivers/cbus/tahvo.c +9 -7
@@ -266,13 +266,15 @@ static struct device *tahvo_allocate_child(const char *name, pdev->dev.parent = parent; - generic_resources[0 ].start = irq; - - ret =platform_device_add_resources (pdev, - generic_resources,ARRAY_SIZE (generic_resources)); -if (ret <0 ) { -dev_dbg (parent,"can't add resources to %s\n" , name); - goto err1; +if (irq >0 ) { + generic_resources[0 ].start = irq; + + ret =platform_device_add_resources (pdev, generic_resources, +ARRAY_SIZE (generic_resources)); +if (ret <0 ) { +dev_dbg (parent,"can't add resources to %s\n" , name); + goto err1; + } } ret =platform_device_add (pdev);
Signature · 1 line
1.7.6.396.ge0613
PATCH 24/27 cbus: tahvo: allocate tahvo-pwm child
In reply to Felipe Balbithis will serve as a backlight driver.
--- drivers/cbus/tahvo.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
drivers/cbus/tahvo.c +4 -0
@@ -301,6 +301,10 @@ static int tahvo_allocate_children(struct device *parent, int irq_base)if (!child)return -ENOMEM ; + child =tahvo_allocate_child ("tahvo-pwm" , parent,-1 ); +if (!child) +return -ENOMEM ; +return 0 ; }
Signature · 1 line
1.7.6.396.ge0613
PATCH 25/27 cbus: fix compile issue on tahvo and retu
In reply to Felipe Balbiset_irq_noprobe has been renamed to irq_set_noprobe on commit a0cd9ca2b907d7ee26575e7b63ac92dad768a75e (genirq: Namespace cleanup) and cbus drivers were left with broken compilation. Fix it.
--- drivers/cbus/retu.c | 2 +- drivers/cbus/tahvo.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/cbus/retu.c +1 -1
@@ -279,7 +279,7 @@ static inline void retu_irq_setup(int irq)#ifdef CONFIG_ARM set_irq_flags (irq,IRQF_VALID );#else -set_irq_noprobe (irq); +irq_set_noprobe (irq);#endif }
drivers/cbus/tahvo.c +1 -1
@@ -224,7 +224,7 @@ static inline void tahvo_irq_setup(int irq)#ifdef CONFIG_ARM set_irq_flags (irq,IRQF_VALID );#else -set_irq_noprobe (irq); +irq_set_noprobe (irq);#endif }
Signature · 1 line
1.7.6.396.ge0613
PATCH 26/27 cbus: use platform_driver_register on tahvo and retu
In reply to Felipe Balbithere's no need to use platform_driver_probe() here.
--- drivers/cbus/retu.c | 9 +++++---- drivers/cbus/tahvo.c | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-)
drivers/cbus/retu.c +5 -4
@@ -427,7 +427,7 @@ static int retu_allocate_children(struct device *parent, int irq_base)* Probe for the Retu ASIC and allocate memory * for its device-struct if found */ -static int __init retu_probe (struct platform_device *pdev) +static int __devinit retu_probe (struct platform_device *pdev) {struct retu *retu;struct cbus_retu_platform_data *pdata = pdev->dev.platform_data;
@@ -507,7 +507,7 @@ err0:return ret; } -static int __exit retu_remove(struct platform_device *pdev) +static int __devexit retu_remove(struct platform_device *pdev) {struct retu *retu =platform_get_drvdata (pdev);
@@ -523,7 +523,8 @@ static int __exit retu_remove(struct platform_device *pdev) }static struct platform_driver retu_driver = { - .remove =__exit_p (retu_remove), + .probe = retu_probe, + .remove =__devexit_p (retu_remove), .driver = { .name ="retu" , },
@@ -531,7 +532,7 @@ static struct platform_driver retu_driver = {static int __init retu_init (void ) { -return platform_driver_probe (&retu_driver, retu_probe); +return platform_driver_register (&retu_driver); }subsys_initcall (retu_init);
drivers/cbus/tahvo.c +2 -1
@@ -396,6 +396,7 @@ static int __devexit tahvo_remove(struct platform_device *pdev) }static struct platform_driver tahvo_driver = { + .probe = tahvo_probe, .remove =__devexit_p (tahvo_remove), .driver = { .name ="tahvo" ,
@@ -404,7 +405,7 @@ static struct platform_driver tahvo_driver = {static int __init tahvo_init (void ) { -return platform_driver_probe (&tahvo_driver, tahvo_probe); +return platform_driver_register (&tahvo_driver); }subsys_initcall (tahvo_init);
Signature · 1 line
1.7.6.396.ge0613
PATCH 27/27 cbus: mark dependencies for ARCH_OMAP
In reply to Felipe BalbiThis is just a temporary commit. Ideally, all these drivers wouldn't depend on a particular architecture, but some of those Retu/Tahvo children are using headers under <plat>, so we must add this dependency until that's sorted out.
--- drivers/cbus/Kconfig | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/cbus/Kconfig +3 -0
@@ -24,6 +24,7 @@ if CBUS_TAHVO config CBUS_TAHVO_USB depends on USB + depends on ARCH_OMAP select USB_OTG_UTILS tristate "Support for Tahvo USB transceiver" ---help---
@@ -58,6 +59,7 @@ config CBUS_RETU_POWERBUTTON config CBUS_RETU_RTC depends on RTC_CLASS + depends on ARCH_OMAP tristate "Support for Retu pseudo-RTC" ---help--- Say Y here if you want support for the device that alleges to be an
@@ -65,6 +67,7 @@ config CBUS_RETU_RTC config CBUS_RETU_WDT depends on SYSFS && WATCHDOG + depends on ARCH_OMAP tristate "Support for Retu watchdog timer" ---help--- Say Y here if you want support for the watchdog in Retu. This will
Signature · 1 line
1.7.6.396.ge0613
Tony Lindgren
maintainerQuoted 2 lines · Felipe Balbi
GPIO operations can sleep, so move to a
mutex.
Great, seems to boot on n800 so pushing all into
cbus branch.
Tony
Quoted 6 lines · Tony Lindgren
Quoted 2 lines · Felipe Balbi
GPIO operations can sleep, so move to a
mutex.Great, seems to boot on n800 so pushing all into
cbus branch.
cool thanks. I think this is pretty much ready for mainline. At least retu. Unless you have any other plans for these little guys.
They have been missing from mainline for a loooong time though. I'm still concerned about the whole cbus bus implementation. Maybe we should the i2c framework (which already supports a few buses) and implement i2c-cbus-gpio.c ?? What do you think ?
Signature · 1 line
balbi
Tony Lindgren
maintainerQuoted 10 lines · Felipe Balbi
Quoted 6 lines · Tony Lindgren
Quoted 2 lines · Felipe Balbi
GPIO operations can sleep, so move to a
mutex.Great, seems to boot on n800 so pushing all into
cbus branch.cool thanks. I think this is pretty much ready for mainline. At least retu. Unless you have any other plans for these little guys.
Well I guess they should be in drivers/mfd, but other than that yeah these are the last pieces of non-mainline code dragging around.
Quoted 4 lines
They have been missing from mainline for a loooong time though. I'm still concerned about the whole cbus bus implementation. Maybe we should the i2c framework (which already supports a few buses) and implement
i2c-cbus-gpio.c?? What do you think ?
Heh I guess that's doable too :) Or drivers/spi maybe?
Tony
Hi,
Quoted 6 lines · Tony Lindgren
Quoted 5 lines · Felipe Balbi
Quoted 4 lines · Tony Lindgren
Quoted 2 lines · Felipe Balbi
GPIO operations can sleep, so move to a
mutex.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Great, seems to boot on n800 so pushing all into
cbus branch.cool thanks. I think this is pretty much ready for mainline. At least retu. Unless you have any other plans for these little guys.
Well I guess they should be in
drivers/mfd, but other than that yeah these are the last pieces of non-mainline code dragging around.
good, happy to be helping ;-) If Nokia were to open the specs it would've been simpler, though :-p
Quoted 6 lines
Quoted 4 lines
They have been missing from mainline for a loooong time though. I'm still concerned about the whole cbus bus implementation. Maybe we should the i2c framework (which already supports a few buses) and implement
i2c-cbus-gpio.c?? What do you think ?Heh I guess that's doable too :) Or
drivers/spimaybe?
whoever accepts it :-)
Signature · 1 line
balbi