28 #include <linux/module.h>
53 static struct gpio_chip twl_gpiochip;
54 static int twl4030_gpio_base;
55 static int twl4030_gpio_irq_base;
59 #define is_module() true
61 #define is_module() false
65 #define MASK_GPIO_CTRL_GPIO0CD1 BIT(0)
66 #define MASK_GPIO_CTRL_GPIO1CD2 BIT(1)
67 #define MASK_GPIO_CTRL_GPIO_ON BIT(2)
70 #define GPIO_32_MASK 0x0003ffff
76 static unsigned int gpio_usage_count;
95 #define TWL4030_LED_LEDEN 0x0
98 #define LEDEN_LEDAON BIT(0)
99 #define LEDEN_LEDBON BIT(1)
100 #define LEDEN_LEDAEXT BIT(2)
101 #define LEDEN_LEDBEXT BIT(3)
102 #define LEDEN_LEDAPWM BIT(4)
103 #define LEDEN_LEDBPWM BIT(5)
104 #define LEDEN_PWM_LENGTHA BIT(6)
105 #define LEDEN_PWM_LENGTHB BIT(7)
107 #define TWL4030_PWMx_PWMxON 0x0
108 #define TWL4030_PWMx_PWMxOFF 0x1
110 #define PWMxON_LENGTH BIT(7)
117 static inline int gpio_twl4030_read(
u8 address)
123 return (ret < 0) ? ret :
data;
128 static u8 cached_leden;
134 static void twl4030_led_set_value(
int led,
int value)
144 cached_leden &= ~mask;
146 cached_leden |=
mask;
152 static int twl4030_set_gpio_direction(
int gpio,
int is_input)
154 u8 d_bnk = gpio >> 3;
155 u8 d_msk =
BIT(gpio & 0x7);
161 ret = gpio_twl4030_read(base);
168 ret = gpio_twl4030_write(base, reg);
174 static int twl4030_set_gpio_dataout(
int gpio,
int enable)
176 u8 d_bnk = gpio >> 3;
177 u8 d_msk =
BIT(gpio & 0x7);
185 return gpio_twl4030_write(base, d_msk);
188 static int twl4030_get_gpio_datain(
int gpio)
190 u8 d_bnk = gpio >> 3;
191 u8 d_off = gpio & 0x7;
196 || !(gpio_usage_count &
BIT(gpio))))
200 ret = gpio_twl4030_read(base);
202 ret = (ret >> d_off) & 0x1;
209 static int twl_request(
struct gpio_chip *
chip,
unsigned offset)
243 cached_leden &= ~ledclr_mask;
254 if (!gpio_usage_count) {
261 pdata = chip->dev->platform_data;
263 value |= pdata->
mmc_cd & 0x03;
269 gpio_usage_count |= (0x1 <<
offset);
276 static void twl_free(
struct gpio_chip *chip,
unsigned offset)
285 gpio_usage_count &= ~
BIT(offset);
288 if (!gpio_usage_count)
294 static int twl_direction_in(
struct gpio_chip *chip,
unsigned offset)
297 ? twl4030_set_gpio_direction(offset, 1)
301 static int twl_get(
struct gpio_chip *chip,
unsigned offset)
306 status = twl4030_get_gpio_datain(offset);
311 return (status < 0) ? 0 :
status;
314 static int twl_direction_out(
struct gpio_chip *chip,
unsigned offset,
int value)
317 twl4030_set_gpio_dataout(offset, value);
318 return twl4030_set_gpio_direction(offset, 0);
325 static void twl_set(
struct gpio_chip *chip,
unsigned offset,
int value)
328 twl4030_set_gpio_dataout(offset, value);
333 static int twl_to_irq(
struct gpio_chip *chip,
unsigned offset)
336 ? (twl4030_gpio_irq_base +
offset)
340 static struct gpio_chip twl_gpiochip = {
343 .request = twl_request,
345 .direction_input = twl_direction_in,
347 .direction_output = twl_direction_out,
349 .to_irq = twl_to_irq,
363 for (gpio_bit = 1, i = 1; i < 6; i++) {
367 for (bit_mask = 0, j = 0; j < 8; j += 2, gpio_bit <<= 1) {
369 bit_mask |= 1 << (j + 1);
370 else if (downs & gpio_bit)
371 bit_mask |= 1 << (j + 0);
373 message[
i] = bit_mask;
380 static int __devinit gpio_twl4030_debounce(
u32 debounce,
u8 mmc_cd)
387 message[1] = (debounce & 0xff) | (mmc_cd & 0x03);
389 message[2] = (debounce & 0xff);
391 message[3] = (debounce & 0x03);
410 of_property_read_u32(dev->
of_node,
"ti,debounce",
412 of_property_read_u32(dev->
of_node,
"ti,mmc-cd",
414 of_property_read_u32(dev->
of_node,
"ti,pullups",
416 of_property_read_u32(dev->
of_node,
"ti,pulldowns",
419 return omap_twl_info;
430 dev_err(&pdev->
dev,
"can't dispatch IRQs from modules\n");
436 dev_err(&pdev->
dev,
"Failed to alloc irq_descs\n");
447 twl4030_gpio_irq_base = irq_base;
450 twl_gpiochip.base = -1;
452 twl_gpiochip.dev = &pdev->
dev;
455 pdata = of_gpio_twl4030(&pdev->
dev);
458 dev_err(&pdev->
dev,
"Platform data is missing\n");
470 dev_dbg(&pdev->
dev,
"pullups %.05x %.05x --> %d\n",
475 dev_dbg(&pdev->
dev,
"debounce %.03x %.01x --> %d\n",
483 twl_gpiochip.ngpio += 2;
487 dev_err(&pdev->
dev,
"could not register gpiochip, %d\n", ret);
488 twl_gpiochip.ngpio = 0;
489 gpio_twl4030_remove(pdev);
493 twl4030_gpio_base = twl_gpiochip.base;
495 if (pdata && pdata->
setup) {
501 dev_dbg(&pdev->
dev,
"setup --> %d\n", status);
518 dev_dbg(&pdev->
dev,
"teardown --> %d\n", status);
536 { .compatible =
"ti,twl4030-gpio", },
546 .name =
"twl4030_gpio",
550 .probe = gpio_twl4030_probe,
551 .remove = gpio_twl4030_remove,
554 static int __init gpio_twl4030_init(
void)
560 static void __exit gpio_twl4030_exit(
void)