2 * Access to GPOs on TWL6040 chip
4 * Copyright (C) 2012 Texas Instruments, Inc.
7 * Sergio Aguirre <saaguirre@ti.com>
8 * Peter Ujfalusi <peter.ujfalusi@ti.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <linux/module.h>
26 #include <linux/init.h>
27 #include <linux/kthread.h>
28 #include <linux/irq.h>
29 #include <linux/gpio.h>
30 #include <linux/platform_device.h>
33 #include <linux/mfd/twl6040.h>
35 static struct gpio_chip twl6040gpo_chip
;
37 static int twl6040gpo_get(struct gpio_chip
*chip
, unsigned offset
)
39 struct twl6040
*twl6040
= dev_get_drvdata(chip
->dev
->parent
);
42 ret
= twl6040_reg_read(twl6040
, TWL6040_REG_GPOCTL
);
46 return (ret
>> offset
) & 1;
49 static int twl6040gpo_direction_out(struct gpio_chip
*chip
, unsigned offset
,
52 /* This only drives GPOs, and can't change direction */
56 static void twl6040gpo_set(struct gpio_chip
*chip
, unsigned offset
, int value
)
58 struct twl6040
*twl6040
= dev_get_drvdata(chip
->dev
->parent
);
62 ret
= twl6040_reg_read(twl6040
, TWL6040_REG_GPOCTL
);
67 gpoctl
= ret
| (1 << offset
);
69 gpoctl
= ret
& ~(1 << offset
);
71 twl6040_reg_write(twl6040
, TWL6040_REG_GPOCTL
, gpoctl
);
74 static struct gpio_chip twl6040gpo_chip
= {
77 .get
= twl6040gpo_get
,
78 .direction_output
= twl6040gpo_direction_out
,
79 .set
= twl6040gpo_set
,
83 /*----------------------------------------------------------------------*/
85 static int gpo_twl6040_probe(struct platform_device
*pdev
)
87 struct twl6040_gpo_data
*pdata
= pdev
->dev
.platform_data
;
88 struct device
*twl6040_core_dev
= pdev
->dev
.parent
;
89 struct twl6040
*twl6040
= dev_get_drvdata(twl6040_core_dev
);
93 twl6040gpo_chip
.base
= pdata
->gpio_base
;
95 twl6040gpo_chip
.base
= -1;
97 if (twl6040_get_revid(twl6040
) < TWL6041_REV_ES2_0
)
98 twl6040gpo_chip
.ngpio
= 3; /* twl6040 have 3 GPO */
100 twl6040gpo_chip
.ngpio
= 1; /* twl6041 have 1 GPO */
102 twl6040gpo_chip
.dev
= &pdev
->dev
;
103 #ifdef CONFIG_OF_GPIO
104 twl6040gpo_chip
.of_node
= twl6040_core_dev
->of_node
;
107 ret
= gpiochip_add(&twl6040gpo_chip
);
109 dev_err(&pdev
->dev
, "could not register gpiochip, %d\n", ret
);
110 twl6040gpo_chip
.ngpio
= 0;
116 static int gpo_twl6040_remove(struct platform_device
*pdev
)
118 return gpiochip_remove(&twl6040gpo_chip
);
121 /* Note: this hardware lives inside an I2C-based multi-function device. */
122 MODULE_ALIAS("platform:twl6040-gpo");
124 static struct platform_driver gpo_twl6040_driver
= {
126 .name
= "twl6040-gpo",
127 .owner
= THIS_MODULE
,
129 .probe
= gpo_twl6040_probe
,
130 .remove
= gpo_twl6040_remove
,
133 module_platform_driver(gpo_twl6040_driver
);
135 MODULE_AUTHOR("Texas Instruments, Inc.");
136 MODULE_DESCRIPTION("GPO interface for TWL6040");
137 MODULE_LICENSE("GPL");