22 #define pr_fmt(fmt) "%s: " fmt, __func__
24 #include <linux/module.h>
25 #include <linux/kernel.h>
28 #include <linux/stddef.h>
29 #include <linux/slab.h>
35 #include <linux/device.h>
39 #define DRIVER_NAME "pmic_gpio"
58 #define GPIO_INTCTL 0x30
61 #define GPOSW_DRV 0x01
62 #define GPOSW_DOU 0x08
63 #define GPOSW_RDRV 0x30
65 #define GPIO_UPDATE_TYPE 0x80000000
79 static void pmic_program_irqtype(
int gpio,
int type)
92 static int pmic_gpio_direction_input(
struct gpio_chip *
chip,
unsigned offset)
95 pr_err(
"only pin 0-7 support input\n");
102 static int pmic_gpio_direction_output(
struct gpio_chip *chip,
103 unsigned offset,
int value)
111 else if (offset < 16)
115 else if (offset > 15 && offset < 24)
117 value ? 1 << (offset - 16) : 0,
120 pr_err(
"invalid PMIC GPIO pin %d!\n", offset);
127 static int pmic_gpio_get(
struct gpio_chip *chip,
unsigned offset)
141 static void pmic_gpio_set(
struct gpio_chip *chip,
unsigned offset,
int value)
147 else if (offset < 16)
151 else if (offset > 15 && offset < 24)
153 value ? 1 << (offset - 16) : 0,
164 struct pmic_gpio *
pg = irq_data_get_irq_chip_data(data);
167 if (gpio >= pg->
chip.ngpio)
175 static int pmic_gpio_to_irq(
struct gpio_chip *chip,
unsigned offset)
182 static void pmic_bus_lock(
struct irq_data *data)
184 struct pmic_gpio *pg = irq_data_get_irq_chip_data(data);
189 static void pmic_bus_sync_unlock(
struct irq_data *data)
191 struct pmic_gpio *pg = irq_data_get_irq_chip_data(data);
203 static void pmic_irq_unmask(
struct irq_data *data) { }
205 static void pmic_irq_mask(
struct irq_data *data) { }
207 static struct irq_chip pmic_irqchip = {
209 .irq_mask = pmic_irq_mask,
210 .irq_unmask = pmic_irq_unmask,
211 .irq_set_type = pmic_irq_type,
212 .irq_bus_lock = pmic_bus_lock,
213 .irq_bus_sync_unlock = pmic_bus_sync_unlock,
216 static irqreturn_t pmic_irq_handler(
int irq,
void *data)
223 for (gpio = 0; gpio < 8; gpio++) {
224 if (intsts & (1 << gpio)) {
225 pr_debug(
"pmic pin %d triggered\n", gpio);
249 dev_dbg(dev,
"incorrect or missing platform data\n");
263 pr_err(
"Can not map GPIOINT\n");
268 pg->
chip.label =
"intel_pmic";
269 pg->
chip.direction_input = pmic_gpio_direction_input;
270 pg->
chip.direction_output = pmic_gpio_direction_output;
271 pg->
chip.get = pmic_gpio_get;
272 pg->
chip.set = pmic_gpio_set;
273 pg->
chip.to_irq = pmic_gpio_to_irq;
276 pg->
chip.can_sleep = 1;
284 pr_err(
"Can not add pmic gpio chip\n");
290 pr_warn(
"Interrupt request failed\n");
294 for (i = 0; i < 8; i++) {
316 .probe = platform_pmic_gpio_probe,
319 static int __init platform_pmic_gpio_init(
void)