aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Documentation/DocBook/tc35892.tmpl6
-rwxr-xr-xarch/arm/mach-ux500/include/mach/tc35892.h156
-rw-r--r--drivers/gpio/tc35892.c405
3 files changed, 245 insertions, 322 deletions
diff --git a/Documentation/DocBook/tc35892.tmpl b/Documentation/DocBook/tc35892.tmpl
index 6f63250ae79..b75495bb207 100644
--- a/Documentation/DocBook/tc35892.tmpl
+++ b/Documentation/DocBook/tc35892.tmpl
@@ -19,8 +19,8 @@
</authorgroup>
<copyright>
- <year>2007-2008</year>
- <holder>ST-Ericsson 2009</holder>
+ <year>2009</year>
+ <holder>ST-Ericsson</holder>
</copyright>
<legalnotice>
@@ -67,7 +67,7 @@
This chapter contains the autogenerated documentation of the structures which are
used in the TC35892 driver.
</para>
-!Iarch/arm/mach-u8500/include/mach/tc35892.h
+!Iarch/arm/mach-ux500/include/mach/tc35892.h
</chapter>
<chapter id="intfunctions">
diff --git a/arch/arm/mach-ux500/include/mach/tc35892.h b/arch/arm/mach-ux500/include/mach/tc35892.h
index ede0ea47d32..5c222eb72ee 100755
--- a/arch/arm/mach-ux500/include/mach/tc35892.h
+++ b/arch/arm/mach-ux500/include/mach/tc35892.h
@@ -15,115 +15,91 @@
#include <linux/gpio.h>
/*System registers Index*/
-
-#define MANFACTURE_Code_Index 0x80
-#define VERSION_ID_Index 0x81
-#define IOCFG_Index 0xA7
+#define MANFACTURE_Code_Index 0x80
+#define VERSION_ID_Index 0x81
+#define IOCFG_Index 0xA7
/*clock control registers*/
-
-#define CLKMODE_Index 0x88
-#define CLKCFG_Index 0x89
-#define CLKEN_Index 0x8A
+#define CLKMODE_Index 0x88
+#define CLKCFG_Index 0x89
+#define CLKEN_Index 0x8A
/*Reset Control registers*/
-
-#define RSTCTRL_Index 0x82
-#define EXTRSTN_Index 0x83
-#define RSTINTCLR_index 0x84
-
+#define RSTCTRL_Index 0x82
+#define EXTRSTN_Index 0x83
+#define RSTINTCLR_index 0x84
#define GPIO_OFFSET
/* Interrupt registers Index*/
-
-#define GPIO_IS0_Index 0xC9
-#define GPIO_IS1_Index 0xCA
-#define GPIO_IS2_Index 0xCB
-
-#define GPIO_IBE0_Index 0xCC
-#define GPIO_IBE1_Index 0xCD
-#define GPIO_IBE2_Index 0xCE
-
-#define GPIO_IEV0_Index 0xCF
-#define GPIO_IEV1_Index 0xD0
-#define GPIO_IEV2_Index 0xD1
-
-#define GPIO_IE0_Index 0xD2
-#define GPIO_IE1_Index 0xD3
-#define GPIO_IE2_Index 0xD4
-
-#define GPIO_RIS0_Index 0xD6
-#define GPIO_RIS1_Index 0xD7
-#define GPIO_RIS2_Index 0xD8
-
-#define GPIO_MIS0_Index 0xD9
-#define GPIO_MIS1_Index 0xDA
-#define GPIO_MIS2_Index 0xDB
-
-#define GPIO_IC0_Index 0xDC
-#define GPIO_IC1_Index 0xDD
-#define GPIO_IC2_Index 0xDE
-
+#define GPIO_IS0_Index 0xC9
+#define GPIO_IS1_Index 0xCA
+#define GPIO_IS2_Index 0xCB
+#define GPIO_IBE0_Index 0xCC
+#define GPIO_IBE1_Index 0xCD
+#define GPIO_IBE2_Index 0xCE
+#define GPIO_IEV0_Index 0xCF
+#define GPIO_IEV1_Index 0xD0
+#define GPIO_IEV2_Index 0xD1
+#define GPIO_IE0_Index 0xD2
+#define GPIO_IE1_Index 0xD3
+#define GPIO_IE2_Index 0xD4
+#define GPIO_RIS0_Index 0xD6
+#define GPIO_RIS1_Index 0xD7
+#define GPIO_RIS2_Index 0xD8
+#define GPIO_MIS0_Index 0xD9
+#define GPIO_MIS1_Index 0xDA
+#define GPIO_MIS2_Index 0xDB
+#define GPIO_IC0_Index 0xDC
+#define GPIO_IC1_Index 0xDD
+#define GPIO_IC2_Index 0xDE
/*GPIO's defines*/
/*GPIO data register Index*/
-#define GPIO_DATA0_Index 0xC0
-#define GPIO_MASK0_Index 0xc1
-
-#define GPIO_DATA1_Index 0xC2
-#define GPIO_MASK1_Index 0xc3
-
-#define GPIO_DATA2_Index 0xC4
-#define GPIO_MASK2_Index 0xC5
+#define GPIO_DATA0_Index 0xC0
+#define GPIO_MASK0_Index 0xc1
+#define GPIO_DATA1_Index 0xC2
+#define GPIO_MASK1_Index 0xc3
+#define GPIO_DATA2_Index 0xC4
+#define GPIO_MASK2_Index 0xC5
/* GPIO direction register Index*/
-
-#define GPIO_DIR0_Index 0xC6
-#define GPIO_DIR1_Index 0xC7
-#define GPIO_DIR2_Index 0xC8
+#define GPIO_DIR0_Index 0xC6
+#define GPIO_DIR1_Index 0xC7
+#define GPIO_DIR2_Index 0xC8
/* GPIO Sync registers*/
-
-#define GPIO_SYNC0_Index 0xE6
-#define GPIO_SYNC1_Index 0xE7
-#define GPIO_SYNC2_Index 0xE8
+#define GPIO_SYNC0_Index 0xE6
+#define GPIO_SYNC1_Index 0xE7
+#define GPIO_SYNC2_Index 0xE8
/*GPIO Wakeup registers*/
-#define GPIO_WAKE0_Index 0xE9
-#define GPIO_WAKE1_Index 0xEA
-#define GPIO_WAKE2_Index 0xEB
+#define GPIO_WAKE0_Index 0xE9
+#define GPIO_WAKE1_Index 0xEA
+#define GPIO_WAKE2_Index 0xEB
/*GPIO OpenDrain registers*/
-#define GPIO_ODM0_Index 0xE0
-#define GPIO_ODE0_Index 0xE1
-#define GPIO_ODM1_Index 0xE2
-#define GPIO_ODE1_Index 0xE3
-#define GPIO_ODM2_Index 0xE4
-#define GPIO_ODE2_Index 0xE5
+#define GPIO_ODM0_Index 0xE0
+#define GPIO_ODE0_Index 0xE1
+#define GPIO_ODM1_Index 0xE2
+#define GPIO_ODE1_Index 0xE3
+#define GPIO_ODM2_Index 0xE4
+#define GPIO_ODE2_Index 0xE5
/*PULL UP REGISTERS*/
-#define IOPC0_Index 0xAA
-#define IOPC1_Index 0xAC
-#define IOPC2_Index 0xAE
-
-
-
-#define MAX_TC35892_GPIO 24
-
-#define MAX_INT_EXP 24
-
+#define IOPC0_Index 0xAA
+#define IOPC1_Index 0xAC
+#define IOPC2_Index 0xAE
+#define MAX_TC35892_GPIO 24
+#define MAX_INT_EXP 24
#define HIGH 1
#define LOW 0
-
-#define EDGE_SENSITIVE 0
-#define LEVEl_SENSITIVE 1
-
-#define DISABLE_INTERRUPT 0
-#define ENABLE_INTERRUPT 1
-
+#define EDGE_SENSITIVE 0
+#define LEVEl_SENSITIVE 1
+#define DISABLE_INTERRUPT 0
+#define ENABLE_INTERRUPT 1
#define TC35892_FALLING_EDGE_OR_LOWLEVEL 1
#define TC35892_RISING_EDGE_OR_HIGHLEVEL 2
-#define TC35892_BOTH_EDGE 3
+#define TC35892_BOTH_EDGE 3
typedef enum {
EGPIO_PIN_0 = 268,
@@ -151,9 +127,7 @@ typedef enum {
EGPIO_PIN_22,
EGPIO_PIN_23
} egpio_pin;
-
-typedef enum
-{
+typedef enum {
TC35892_OK = 0,
TC35892_BAD_PARAMETER = -2,
TC35892_FEAT_NOT_SUPPORTED = -3,
@@ -163,7 +137,6 @@ typedef enum
TC35892_I2C_ERROR = -7,
TC35892_ERROR = -8
} t_tc35892_error;
-
/**
* struct tc35892_platform_data - tc35892 platform dependent structure
* @gpio_base: starting number of the gpio pin
@@ -175,9 +148,8 @@ struct tc35892_platform_data {
unsigned gpio_base;
int irq;
};
-
int tc35892_remove_callback(int irq);
int tc35892_set_callback(int irq, void *handler, void *data);
-t_tc35892_error tc35892_set_intr_enable (int pin_index,unsigned char intr_enable_disable);
-t_tc35892_error tc35892_set_gpio_intr_conf (int pin_index,unsigned char edge_level_sensitive, unsigned char edge_level_type);
+t_tc35892_error tc35892_set_intr_enable (int pin_index, unsigned char intr_enable_disable);
+t_tc35892_error tc35892_set_gpio_intr_conf (int pin_index, unsigned char edge_level_sensitive, unsigned char edge_level_type);
#endif
diff --git a/drivers/gpio/tc35892.c b/drivers/gpio/tc35892.c
index db77b07a0dd..633be5bf6c1 100644
--- a/drivers/gpio/tc35892.c
+++ b/drivers/gpio/tc35892.c
@@ -5,7 +5,7 @@
* Copyright (C) 2009 ST Ericsson.
*
* Author: Hanumath Prasad <hanumath.prasad@stericsson.com>
- * heavily based on stmpe2401 driver
+ *
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -25,9 +25,7 @@
#include <mach/tc35892.h>
static void tc35892_work(struct work_struct *_chip);
-
-/**
- * struct tc35892_chip - tc35892 gpio chip strcture
+/* struct tc35892_chip - tc35892 gpio chip strcture
* @gpio_chip: pointer to the gpio_chip library
* @client: pointer to the i2c_client structure
* @lock: internal sync primitive
@@ -76,7 +74,7 @@ static int tc35892_write_byte(struct tc35892_chip *chip,
* This funtion uses smbus byte read API to read a byte from the given offset.
**/
static int tc35892_read_byte(struct tc35892_chip *chip, unsigned char reg,
- unsigned char *val)
+ unsigned char *val)
{
int ret;
ret = i2c_smbus_read_byte_data(chip->client, reg);
@@ -99,10 +97,8 @@ static int tc35892_read_byte(struct tc35892_chip *chip, unsigned char reg,
static int tc35892_read(struct tc35892_chip *chip, unsigned char reg, unsigned char *buf, unsigned char nbytes)
{
int ret;
-
- ret = i2c_smbus_read_i2c_block_data(chip->client,reg,nbytes,buf);
-
- if (ret < nbytes){
+ ret = i2c_smbus_read_i2c_block_data(chip->client, reg, nbytes, buf);
+ if (ret < nbytes) {
printk(KERN_ERR "error in reading a byte, smbus byte read failed\n");
return ret;
}
@@ -117,13 +113,13 @@ static int tc35892_read(struct tc35892_chip *chip, unsigned char reg, unsigned c
* This funtion uses smbus block write API's to write n number of bytes to the tc35892
**/
static t_tc35892_error tc35892_write(struct tc35892_chip *chip,
- unsigned char *buf,unsigned char nbytes)
+ unsigned char *buf, unsigned char nbytes)
{
int ret;
/* Need to check the return value*/
- ret = i2c_smbus_write_i2c_block_data(chip->client, buf[0],nbytes-1,&buf[1]);
- if(ret < 0){
- printk("i2c smbus write block data failed\n");
+ ret = i2c_smbus_write_i2c_block_data(chip->client, buf[0], nbytes-1, &buf[1]);
+ if (ret < 0) {
+ printk(KERN_ERR"i2c smbus write block data failed\n");
return ret;
}
return 0;
@@ -162,25 +158,21 @@ static int tc35892_gpio_get_value(struct gpio_chip *gc, unsigned off)
unsigned char reg_val, offset, mask;
chip = container_of(gc, struct tc35892_chip, gpio_chip);
- if(off >= MAX_TC35892_GPIO)
+ if (off >= MAX_TC35892_GPIO)
/*number of pin exceeded*/
return TC35892_BAD_PARAMETER;
-
- if(off < 8)
- {
+ mutex_lock(&chip->lock);
+ if (off < 8) {
offset = GPIO_DATA0_Index;
mask = 1 << off;
- }
- else if(off < 16)
- {
+ } else if (off < 16) {
offset = GPIO_DATA1_Index;
mask = 1 << (off-8);
- }
- else
- {
+ } else {
offset = GPIO_DATA2_Index;
mask = 1 << (off-16);
}
+ mutex_unlock(&chip->lock);
ret = tc35892_read_byte(chip, offset, &reg_val);
if (ret < 0) {
printk(KERN_ERR "Error in tc35892_gpio_get_vaule\n");
@@ -192,7 +184,7 @@ static int tc35892_gpio_get_value(struct gpio_chip *gc, unsigned off)
* tc35892_gpio_set_value() - Set a GPIO value from the given offset
* @gc: pointer to the gpio_chip strcture
* @off: The write gpio offset
- * @val: value need to be written
+ * @val: value need to be written
*
* This funtion is called from the gpio library to set/unset a GPIO
* value. This funtion sets the GPIO DATA register to set a bit.
@@ -207,41 +199,35 @@ static void tc35892_gpio_set_value(struct gpio_chip *gc,
mutex_lock(&chip->lock);
offset = calculate_gpio_offset(off);
mask = 1 << (off % 8);
-
/*register selection depending on the pin number*/
- if((off/8) == 0){
+ if ((off/8) == 0) {
temp_buf[0] = GPIO_DATA0_Index;
- if(val == 0 ){
+ if (val == 0) {
temp_buf[1] = ~(1 << off);
temp_buf[2] = (1 << off);
- }else if(val == 1){
+ } else if (val == 1) {
temp_buf[1] = 1 << off;
temp_buf[2] = 1 << off;
}
-
- }
- else if((off/8) == 1) {
+ } else if ((off/8) == 1) {
temp_buf[0] = GPIO_DATA1_Index;
- if(val == 0 ){
+ if (val == 0) {
temp_buf[1] = ~(1 << (off-8));
temp_buf[2] = (1 << (off-8));
- }else if(val == 1){
+ } else if (val == 1) {
temp_buf[1] = 1 << (off-8);
temp_buf[2] = 1 << (off-8);
}
- }
-
- else {
+ } else {
temp_buf[0] = GPIO_DATA2_Index;
- if(val == 0 ){
+ if (val == 0) {
temp_buf[1] = ~(1 << (off-16));
temp_buf[2] = 1 << (off-16);
- }else if(val == 1){
+ } else if (val == 1) {
temp_buf[1] = 1 << (off-16);
temp_buf[2] = 1 << (off-16);
}
}
-
tc35892_write(chip, temp_buf, 3);
mutex_unlock(&chip->lock);
}
@@ -263,15 +249,18 @@ static int tc35892_gpio_direction_output(struct gpio_chip *gc,
unsigned char mask, temp;
chip = container_of(gc, struct tc35892_chip, gpio_chip);
- if(off >= MAX_TC35892_GPIO)
+ if (off >= MAX_TC35892_GPIO)
/*number of pin exceeded*/
return TC35892_BAD_PARAMETER;
offset = calculate_gpio_offset(off);
mask = 1 << (off % 8);
-
reg_val = tc35892_read_byte(chip, (GPIO_DIR0_Index + offset), &temp);
+ if (reg_val != TC35892_OK)
+ return TC35892_I2C_ERROR;
temp |= mask;
reg_val = tc35892_write_byte(chip, (GPIO_DIR0_Index + offset), temp);
+ if (reg_val != TC35892_OK)
+ return TC35892_I2C_ERROR;
return 0;
}
/**
@@ -286,19 +275,19 @@ static int tc35892_gpio_direction_input(struct gpio_chip *gc, unsigned off)
{
struct tc35892_chip *chip;
unsigned char reg_val, temp, offset, mask;
-
- if(off >= MAX_TC35892_GPIO)
+ if (off >= MAX_TC35892_GPIO)
/*number of pin exceeded*/
return TC35892_BAD_PARAMETER;
-
chip = container_of(gc, struct tc35892_chip, gpio_chip);
-
offset = calculate_gpio_offset(off);
mask = 1 << (off % 8);
reg_val = tc35892_read_byte(chip, (GPIO_DIR0_Index + offset), &temp);
+ if (reg_val != TC35892_OK)
+ return TC35892_I2C_ERROR;
temp &= ~mask;
-
- tc35892_write_byte(chip, (GPIO_DIR0_Index + offset), temp);
+ reg_val = tc35892_write_byte(chip, (GPIO_DIR0_Index + offset), temp);
+ if (reg_val != TC35892_OK)
+ return TC35892_I2C_ERROR;
return 0;
}
/**
@@ -341,143 +330,127 @@ static t_tc35892_error tc35892_bit_calc(unsigned char pin_index, unsigned char p
{
unsigned char mask;
mask = 1 << (pin_index % 8);
- if(pin_value == 0)
- {
- *reg_byte &=~ mask;
- }
- else if(pin_value == 1)
- {
- *reg_byte |= mask;
- }
- else
- {
+ if (pin_value == 0) {
+ *reg_byte &= ~mask;
+ } else if (pin_value == 1) {
+ *reg_byte |= mask;
+ } else {
return TC35892_BAD_PARAMETER;
}
return TC35892_OK;
}
/**
* tc35892_set_gpio_intr_conf()- configure tc35892 gpio interrupt configuration
- * @tc35892_id: index of the device (0-3)
* @pin_index: pin to be read (0-23)
* @edge_level_sensitive: interrupt is either edge sensitive(EDGE_SENSITIVE) or level sensitive(LEVEl_SENSITIVE)
* @edge_level_type: intr can be detected on FALLING/RISING edge or LOW/HIGH level or on BOTH EDGES
*
* This function configure tc35892 gpio intr_type for edge/level detection.
- * TC35892_FALLING_EDGE_OR_LOWLEVEL fallingedge/lowlevel detection
- * TC35892_RISING_EDGE_OR_HIGHLEVEl risingedge/highlevel detection
- * TC35892_BOTH_EDGE falling and rising edge detection
+ * TC35892_FALLING_EDGE_OR_LOWLEVEL fallingedge/lowlevel detection
+ * TC35892_RISING_EDGE_OR_HIGHLEVEl risingedge/highlevel detection
+ * TC35892_BOTH_EDGE falling and rising edge detection
* This function will set the interrupt sensitivity as edge or level sensitive. Depending on that
* it will configure the interrupt detection either on fallingedge/lowlevel or risingedge/highlevel.
**/
-t_tc35892_error tc35892_set_gpio_intr_conf (int pin_index,unsigned char edge_level_sensitive, unsigned char edge_level_type)
+t_tc35892_error tc35892_set_gpio_intr_conf (int pin_index, unsigned char edge_level_sensitive, unsigned char edge_level_type)
{
t_tc35892_error retval = TC35892_OK;
- unsigned char offset,tempbyte, off;
+ unsigned char offset, tempbyte, off;
unsigned char val_intr = 0, val_sense = 0;
unsigned char val_both_edge = 0;
pin_index = pin_index - EGPIO_PIN_0;
- if(pin_index < 0 || pin_index >= MAX_TC35892_GPIO)
+ if (pin_index < 0 || pin_index >= MAX_TC35892_GPIO)
/*number of pin exceeded*/
return TC35892_BAD_PARAMETER;
-
- switch(edge_level_sensitive)
- {
- case EDGE_SENSITIVE:
- val_sense = 0;
- break;
- case LEVEl_SENSITIVE:
- val_sense = 1;
- break;
- default :
- retval = TC35892_BAD_PARAMETER;
- break;
+ switch (edge_level_sensitive) {
+ case EDGE_SENSITIVE:
+ val_sense = 0;
+ break;
+ case LEVEl_SENSITIVE:
+ val_sense = 1;
+ break;
+ default:
+ retval = TC35892_BAD_PARAMETER;
+ break;
}
-
- switch(edge_level_type)
- {
- case TC35892_FALLING_EDGE_OR_LOWLEVEL:
- val_intr = 0;
- break;
- case TC35892_RISING_EDGE_OR_HIGHLEVEL:
- val_intr = 1;
- break;
- case TC35892_BOTH_EDGE:
- val_both_edge = 1;
- break;
- default :
- retval = TC35892_BAD_PARAMETER;
- break;
+ switch (edge_level_type) {
+ case TC35892_FALLING_EDGE_OR_LOWLEVEL:
+ val_intr = 0;
+ break;
+ case TC35892_RISING_EDGE_OR_HIGHLEVEL:
+ val_intr = 1;
+ break;
+ case TC35892_BOTH_EDGE:
+ val_both_edge = 1;
+ break;
+ default:
+ retval = TC35892_BAD_PARAMETER;
+ break;
}
-
off = calculate_gpio_offset(pin_index);
-
/*configuring the sync register to synchronize the interrupt signal*/
- if(retval == TC35892_OK)
- {
+ if (retval == TC35892_OK) {
offset = GPIO_SYNC0_Index + off;
retval = tc35892_read_byte(the_tc35892, offset, &tempbyte);
- if(retval != TC35892_OK)
- return TC35892_I2C_ERROR;
+ if (retval != TC35892_OK)
+ return TC35892_I2C_ERROR;
retval = tc35892_bit_calc(pin_index, 1, &tempbyte);
retval = tc35892_write_byte(the_tc35892, offset, tempbyte);
- if(retval != TC35892_OK)
- return TC35892_I2C_ERROR;
+ if (retval != TC35892_OK)
+ return TC35892_I2C_ERROR;
}
-
/*configuring the GPIO interrupt on both edges*/
- if(retval == TC35892_OK && val_both_edge)
- {
+ if (retval == TC35892_OK && val_both_edge) {
offset = GPIO_IBE0_Index + off;
retval = tc35892_read_byte(the_tc35892, offset, &tempbyte);
- if(retval != TC35892_OK)
- return TC35892_I2C_ERROR;
+ if (retval != TC35892_OK)
+ return TC35892_I2C_ERROR;
retval = tc35892_bit_calc(pin_index, val_both_edge, &tempbyte);
+ if (retval != TC35892_OK)
+ return TC35892_I2C_ERROR;
retval = tc35892_write_byte(the_tc35892, offset, tempbyte);
-
- tc35892_read_byte(the_tc35892, offset, &tempbyte);
-
- //printk("\n The value of the INTR CONF REISTER is = %x\n",tempbyte);
- if(retval != TC35892_OK)
- return TC35892_I2C_ERROR;
+ if (retval != TC35892_OK)
+ return TC35892_I2C_ERROR;
}
-
/*configure the GPIO on rising edge or falling edge*/
- if(retval == TC35892_OK && !val_both_edge)
- {
+ if (retval == TC35892_OK && !val_both_edge) {
offset = GPIO_IEV0_Index + off;
retval = tc35892_read_byte(the_tc35892, offset, &tempbyte);
- if(retval != TC35892_OK)
- return TC35892_I2C_ERROR;
+ if (retval != TC35892_OK)
+ return TC35892_I2C_ERROR;
retval = tc35892_bit_calc(pin_index, val_intr, &tempbyte);
+ if (retval != TC35892_OK)
+ return TC35892_I2C_ERROR;
retval = tc35892_write_byte(the_tc35892, offset, tempbyte);
- if(retval != TC35892_OK)
- return TC35892_I2C_ERROR;
+ if (retval != TC35892_OK)
+ return TC35892_I2C_ERROR;
}
-
/*configure the interrupt on edgesensitive or levelsensitive*/
- if(retval == TC35892_OK)
- {
+ if (retval == TC35892_OK) {
offset = GPIO_IS0_Index + off;
retval = tc35892_read_byte(the_tc35892, offset, &tempbyte);
- if(retval != TC35892_OK)
- return TC35892_I2C_ERROR;
+ if (retval != TC35892_OK)
+ return TC35892_I2C_ERROR;
retval = tc35892_bit_calc(pin_index, val_sense, &tempbyte);
+ if (retval != TC35892_OK)
+ return TC35892_I2C_ERROR;
retval = tc35892_write_byte(the_tc35892, offset, tempbyte);
- if(retval != TC35892_OK)
- return TC35892_I2C_ERROR;
+ if (retval != TC35892_OK)
+ return TC35892_I2C_ERROR;
}
/*clearing the interrupt*/
- if(retval == TC35892_OK)
- {
+ if (retval == TC35892_OK) {
offset = GPIO_IC0_Index + off;
retval = tc35892_read_byte(the_tc35892, offset, &tempbyte);
- if(retval != TC35892_OK)
- return TC35892_I2C_ERROR;
+ if (retval != TC35892_OK)
+ return TC35892_I2C_ERROR;
retval = tc35892_bit_calc(pin_index, 1, &tempbyte);
+ if (retval != TC35892_OK)
+ return TC35892_I2C_ERROR;
retval = tc35892_write_byte(the_tc35892, offset, tempbyte);
- if(retval != TC35892_OK)
- return TC35892_I2C_ERROR;
+ if (retval != TC35892_OK)
+ return TC35892_I2C_ERROR;
}
return retval;
}
@@ -490,65 +463,59 @@ EXPORT_SYMBOL(tc35892_set_gpio_intr_conf);
*
* This funtion will enable(ENABLE_INTERRUPT) or disable(DISABLE_INTERRUPT) the interrupt
**/
-t_tc35892_error tc35892_set_intr_enable(int pin_index,unsigned char intr_enable_disable)
+t_tc35892_error tc35892_set_intr_enable(int pin_index, unsigned char intr_enable_disable)
{
t_tc35892_error retval = TC35892_OK;
- unsigned char offset,tempbyte;
+ unsigned char offset, tempbyte;
unsigned char val_enable, off;
pin_index = pin_index - EGPIO_PIN_0;
- if(pin_index < 0 || pin_index >= MAX_TC35892_GPIO)
+ if (pin_index < 0 || pin_index >= MAX_TC35892_GPIO)
/*number of pin exceeded*/
return TC35892_BAD_PARAMETER;
- switch(intr_enable_disable)
- {
- case ENABLE_INTERRUPT:
- val_enable = 1;
- break;
- case DISABLE_INTERRUPT:
- val_enable = 0;
- break;
- default:
- retval = TC35892_BAD_PARAMETER;
- break;
-
+ switch (intr_enable_disable) {
+ case ENABLE_INTERRUPT:
+ val_enable = 1;
+ break;
+ case DISABLE_INTERRUPT:
+ val_enable = 0;
+ break;
+ default:
+ retval = TC35892_BAD_PARAMETER;
+ break;
}
-
off = calculate_gpio_offset(pin_index);
/* Enabling the interrupt */
- if(retval == TC35892_OK)
- {
+ if (retval == TC35892_OK) {
offset = GPIO_IE0_Index + off;
retval = tc35892_read_byte(the_tc35892, offset, &tempbyte);
- if(retval != TC35892_OK)
- return TC35892_I2C_ERROR;
-
- retval = tc35892_read_byte(the_tc35892, offset, &tempbyte);
+ if (retval != TC35892_OK)
+ return TC35892_I2C_ERROR;
retval = tc35892_bit_calc(pin_index, val_enable, &tempbyte);
+ if (retval != TC35892_OK)
+ return TC35892_I2C_ERROR;
retval = tc35892_write_byte(the_tc35892, offset, tempbyte);
- retval = tc35892_read_byte(the_tc35892, offset, &tempbyte);
- if(retval != TC35892_OK)
- return TC35892_I2C_ERROR;
+ if (retval != TC35892_OK)
+ return TC35892_I2C_ERROR;
}
return retval;
}
EXPORT_SYMBOL(tc35892_set_intr_enable);
-
/**
* tc35892_set_callback() - install a callback handler
* @irq: gpio number
* @handler: funtion pointer to the callback handler
- * @data: Arguement to the callback
+ * @data: Arguement to the callback
*
* This funtion install the callback handler for the client device
**/
int tc35892_set_callback(int irq, void *handler, void *data)
{
- mutex_lock(&the_tc35892->lock);
irq = irq - EGPIO_PIN_0;
- if(irq < 0 || irq >= MAX_TC35892_GPIO)
+ if (irq < 0 || irq >= MAX_TC35892_GPIO)
/*number of pin exceeded*/
return TC35892_BAD_PARAMETER;
+ mutex_lock(&the_tc35892->lock);
the_tc35892->handlers[irq] = handler;
the_tc35892->data[irq] = data;
/*if required, you can enable interrupt here
@@ -566,11 +533,11 @@ EXPORT_SYMBOL(tc35892_set_callback);
**/
int tc35892_remove_callback(int irq)
{
- mutex_lock(&the_tc35892->lock);
irq = irq - EGPIO_PIN_0;
- if(irq < 0 || irq >= MAX_TC35892_GPIO)
+ if (irq < 0 || irq >= MAX_TC35892_GPIO)
/*number of pin exceeded*/
return TC35892_BAD_PARAMETER;
+ mutex_lock(&the_tc35892->lock);
the_tc35892->handlers[irq] = NULL;
the_tc35892->data[irq] = NULL;
/*if required, you can disable interrupt here
@@ -592,7 +559,6 @@ EXPORT_SYMBOL(tc35892_remove_callback);
static irqreturn_t tc35892_intr_handler(int irq, void *_chip)
{
struct tc35892_chip *chip = _chip;
- //printk("\nInterrupt from %d\n", irq);
schedule_work(&chip->work);
return IRQ_HANDLED;
@@ -622,26 +588,24 @@ static void tc35892_work(struct work_struct *_chip)
bit = find_first_bit(&mask_intr_status, 8);
while (bit) {
handler = the_tc35892->handlers[bit + count];
- if (handler){
+ if (handler) {
handler(the_tc35892->data[bit+count]);
mask = 1 << ((bit + count) % 8);
tc35892_write_byte(chip, (GPIO_IC0_Index + i), mask);
tc35892_write_byte(chip, RSTINTCLR_index, 0x01);
return;
- //bit = find_next_bit(&mask_intr_status, 8, bit + 1);
- }
- else{
+ /*bit = find_next_bit(&mask_intr_status, 8, bit + 1);*/
+ } else {
mask = 1 << ((bit + count) % 8);
tc35892_write_byte(chip, (GPIO_IC0_Index + i), mask);
tc35892_write_byte(chip, RSTINTCLR_index, 0x01);
break;
}
- //bit = find_next_bit(&mask_intr_status, 8, bit + 1);
+ /*bit = find_next_bit(&mask_intr_status, 8, bit + 1);*/
}
count += 8;
}
}
-
/**
* tc35892_probe() - initialize the tc35892
* @client: pointer to the i2c client structure
@@ -652,12 +616,12 @@ static void tc35892_work(struct work_struct *_chip)
* and set up the i2c client information
**/
static int tc35892_probe(struct i2c_client *client,
- const struct i2c_device_id *id)
+ const struct i2c_device_id *id)
{
struct tc35892_platform_data *pdata = client->dev.platform_data;
struct tc35892_chip *chip;
unsigned char chip_id, version_id, clk_en;
- int ret,i;
+ int ret, i;
chip = kzalloc(sizeof(struct tc35892_chip), GFP_KERNEL);
if (chip == NULL)
@@ -685,63 +649,50 @@ static int tc35892_probe(struct i2c_client *client,
/*
* issue soft reset for all the modules
*/
- ret = tc35892_write_byte(chip,RSTCTRL_Index,0x0E);
- if(ret != TC35892_OK)
- {
- printk("couldn't do soft reset the tc35892 modules\n");
- return ret;
- }
- /*configure the EXTRSTN line as the hardware reset*/
-
- ret = tc35892_write_byte(chip,EXTRSTN_Index,0x1);
- if(ret != TC35892_OK)
- {
- printk("couldn't configure EXTRSTN line for hard reset \n");
- return ret;
- }
- ret = tc35892_read_byte(chip,MANFACTURE_Code_Index,&chip_id);
- if(ret != TC35892_OK)
- {
- printk("couldn't read the MANFACTURE ID of the GPIO EXPANDER \n");
- return ret;
- }
- ret = tc35892_read_byte(chip,VERSION_ID_Index,&version_id);
- if(ret != TC35892_OK)
- {
- printk("couldn't read the VERSION ID of the GPIO EXPANDER \n");
- return ret;
- }
-
- //ret = tc35892_write_byte(chip,CLKCFG_Index,0xB0);
- ret = tc35892_write_byte(chip,CLKEN_Index,0x40);
-
- if(ret != TC35892_OK)
- {
- printk("couldn't configure CLKEN register\n");
- return ret;
- }
- ret = tc35892_read(chip, CLKEN_Index, &clk_en, 1);
- if(ret != TC35892_OK)
- {
- printk("couldn't read CLKEN register\n");
- return ret;
- }
- printk(KERN_INFO
- "tc35892 gpio expander: chip id: %d, version id:%d \n", chip_id,
- version_id);
-
- ret = tc35892_write_byte( chip, RSTINTCLR_index, 0x01);
- if(ret != TC35892_OK)
- {
- printk("couldn't configure RSTINTCLR register\n");
- return ret;
- }
+ ret = tc35892_write_byte(chip, RSTCTRL_Index, 0x0E);
+ if (ret != TC35892_OK) {
+ printk(KERN_ERR"couldn't do soft reset the tc35892 modules\n");
+ return ret;
+ }
+ /*configure the EXTRSTN line as the hardware reset*/
- for(i=0; i < MAX_INT_EXP; i++)
+ ret = tc35892_write_byte(chip, EXTRSTN_Index, 0x1);
+ if (ret != TC35892_OK) {
+ printk(KERN_ERR"couldn't configure EXTRSTN line for hard reset \n");
+ return ret;
+ }
+ ret = tc35892_read_byte(chip, MANFACTURE_Code_Index, &chip_id);
+ if (ret != TC35892_OK) {
+ printk(KERN_ERR"couldn't read the MANFACTURE ID of the GPIO EXPANDER \n");
+ return ret;
+ }
+ ret = tc35892_read_byte(chip, VERSION_ID_Index, &version_id);
+ if (ret != TC35892_OK) {
+ printk(KERN_ERR"couldn't read the VERSION ID of the GPIO EXPANDER \n");
+ return ret;
+ }
+ ret = tc35892_write_byte(chip, CLKEN_Index, 0x40);
+ if (ret != TC35892_OK) {
+ printk(KERN_ERR"couldn't configure CLKEN register\n");
+ return ret;
+ }
+ ret = tc35892_read(chip, CLKEN_Index, &clk_en, 1);
+ if (ret != TC35892_OK) {
+ printk(KERN_ERR"couldn't read CLKEN register\n");
+ return ret;
+ }
+ printk(KERN_INFO
+ "tc35892 gpio expander: chip id: %d, version id:%d \n", chip_id,
+ version_id);
+ ret = tc35892_write_byte(chip, RSTINTCLR_index, 0x01);
+ if (ret != TC35892_OK) {
+ printk(KERN_ERR"couldn't configure RSTINTCLR register\n");
+ return ret;
+ }
+ for (i = 0; i < MAX_INT_EXP; i++)
the_tc35892->handlers[i] = NULL;
-
ret = request_irq(pdata->irq, tc35892_intr_handler,
- IRQF_TRIGGER_FALLING, "tc35892", chip);
+ (IRQF_TRIGGER_FALLING), "tc35892", chip);
if (ret) {
printk(KERN_ERR
"unable to request for the irq %d\n", GPIO_TO_IRQ(217));
@@ -779,9 +730,9 @@ MODULE_DEVICE_TABLE(i2c, tc35892_id);
static struct i2c_driver tc35892_driver = {
.driver = {
- .name = "tc35892",
- .owner = THIS_MODULE,
- },
+ .name = "tc35892",
+ .owner = THIS_MODULE,
+ },
.probe = tc35892_probe,
.remove = __exit_p(tc35892_remove),
.id_table = tc35892_id,