Skip to content

Commit

Permalink
MFD: ucb1x00-core: use mutexes instead of semaphores
Browse files Browse the repository at this point in the history
Convert the ucb1x00 driver to use mutexes rather than the depreciated
semaphores for exclusive access to the ADC.

Acked-by: Jochen Friedrich <jochen@scram.de>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
  • Loading branch information
Russell King committed Feb 18, 2012
1 parent ddb1e04 commit cae1547
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
15 changes: 7 additions & 8 deletions drivers/mfd/ucb1x00-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <linux/mutex.h>
#include <linux/mfd/ucb1x00.h>
#include <linux/gpio.h>
#include <linux/semaphore.h>

static DEFINE_MUTEX(ucb1x00_mutex);
static LIST_HEAD(ucb1x00_drivers);
Expand Down Expand Up @@ -99,7 +98,7 @@ void ucb1x00_io_write(struct ucb1x00 *ucb, unsigned int set, unsigned int clear)
* ucb1x00_enable must have been called to enable the comms
* before using this function.
*
* This function does not take any semaphores or spinlocks.
* This function does not take any mutexes or spinlocks.
*/
unsigned int ucb1x00_io_read(struct ucb1x00 *ucb)
{
Expand Down Expand Up @@ -183,7 +182,7 @@ static int ucb1x00_gpio_direction_output(struct gpio_chip *chip, unsigned offset
* Any code wishing to use the ADC converter must call this
* function prior to using it.
*
* This function takes the ADC semaphore to prevent two or more
* This function takes the ADC mutex to prevent two or more
* concurrent uses, and therefore may sleep. As a result, it
* can only be called from process context, not interrupt
* context.
Expand All @@ -193,7 +192,7 @@ static int ucb1x00_gpio_direction_output(struct gpio_chip *chip, unsigned offset
*/
void ucb1x00_adc_enable(struct ucb1x00 *ucb)
{
down(&ucb->adc_sem);
mutex_lock(&ucb->adc_mutex);

ucb->adc_cr |= UCB_ADC_ENA;

Expand All @@ -215,7 +214,7 @@ void ucb1x00_adc_enable(struct ucb1x00 *ucb)
* complete (2 frames max without sync).
*
* If called for a synchronised ADC conversion, it may sleep
* with the ADC semaphore held.
* with the ADC mutex held.
*/
unsigned int ucb1x00_adc_read(struct ucb1x00 *ucb, int adc_channel, int sync)
{
Expand Down Expand Up @@ -243,15 +242,15 @@ unsigned int ucb1x00_adc_read(struct ucb1x00 *ucb, int adc_channel, int sync)
* ucb1x00_adc_disable - disable the ADC converter
* @ucb: UCB1x00 structure describing chip
*
* Disable the ADC converter and release the ADC semaphore.
* Disable the ADC converter and release the ADC mutex.
*/
void ucb1x00_adc_disable(struct ucb1x00 *ucb)
{
ucb->adc_cr &= ~UCB_ADC_ENA;
ucb1x00_reg_write(ucb, UCB_ADC_CR, ucb->adc_cr);
ucb1x00_disable(ucb);

up(&ucb->adc_sem);
mutex_unlock(&ucb->adc_mutex);
}

/*
Expand Down Expand Up @@ -560,7 +559,7 @@ static int ucb1x00_probe(struct mcp *mcp)

spin_lock_init(&ucb->lock);
spin_lock_init(&ucb->io_lock);
sema_init(&ucb->adc_sem, 1);
mutex_init(&ucb->adc_mutex);

ucb->id = id;
ucb->mcp = mcp;
Expand Down
4 changes: 2 additions & 2 deletions include/linux/mfd/ucb1x00.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <linux/mfd/mcp.h>
#include <linux/gpio.h>
#include <linux/semaphore.h>
#include <linux/mutex.h>

#define UCB_IO_DATA 0x00
#define UCB_IO_DIR 0x01
Expand Down Expand Up @@ -124,7 +124,7 @@ struct ucb1x00 {
spinlock_t lock;
struct mcp *mcp;
unsigned int irq;
struct semaphore adc_sem;
struct mutex adc_mutex;
spinlock_t io_lock;
u16 id;
u16 io_dir;
Expand Down

0 comments on commit cae1547

Please sign in to comment.