eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 1 | /* |
Aaron Sierra | 1e19169 | 2014-02-07 16:35:48 -0600 | [diff] [blame] | 2 | * PCA953x 4/8/16/24/40 bit I/O ports |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2005 Ben Gardner <bgardner@wabtec.com> |
| 5 | * Copyright (C) 2007 Marvell International Ltd. |
| 6 | * |
| 7 | * Derived from drivers/i2c/chips/pca9539.c |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; version 2 of the License. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/init.h> |
H Hartley Sweeten | d120c17 | 2009-09-22 16:46:37 -0700 | [diff] [blame] | 16 | #include <linux/gpio.h> |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 17 | #include <linux/interrupt.h> |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 18 | #include <linux/i2c.h> |
Vivien Didelot | 5877457 | 2013-08-29 15:24:14 -0400 | [diff] [blame] | 19 | #include <linux/platform_data/pca953x.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 20 | #include <linux/slab.h> |
Nate Case | 1965d30 | 2009-06-17 16:26:17 -0700 | [diff] [blame] | 21 | #ifdef CONFIG_OF_GPIO |
| 22 | #include <linux/of_platform.h> |
Nate Case | 1965d30 | 2009-06-17 16:26:17 -0700 | [diff] [blame] | 23 | #endif |
Andy Shevchenko | f32517b | 2015-10-01 14:20:28 +0300 | [diff] [blame] | 24 | #include <linux/acpi.h> |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 25 | |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 26 | #define PCA953X_INPUT 0 |
| 27 | #define PCA953X_OUTPUT 1 |
| 28 | #define PCA953X_INVERT 2 |
| 29 | #define PCA953X_DIRECTION 3 |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 30 | |
Andreas Schallenberg | ae79c19 | 2012-05-09 09:46:17 +0200 | [diff] [blame] | 31 | #define REG_ADDR_AI 0x80 |
| 32 | |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 33 | #define PCA957X_IN 0 |
| 34 | #define PCA957X_INVRT 1 |
| 35 | #define PCA957X_BKEN 2 |
| 36 | #define PCA957X_PUPD 3 |
| 37 | #define PCA957X_CFG 4 |
| 38 | #define PCA957X_OUT 5 |
| 39 | #define PCA957X_MSK 6 |
| 40 | #define PCA957X_INTS 7 |
| 41 | |
| 42 | #define PCA_GPIO_MASK 0x00FF |
| 43 | #define PCA_INT 0x0100 |
| 44 | #define PCA953X_TYPE 0x1000 |
| 45 | #define PCA957X_TYPE 0x2000 |
Andy Shevchenko | c666414 | 2015-10-01 14:20:27 +0300 | [diff] [blame] | 46 | #define PCA_TYPE_MASK 0xF000 |
| 47 | |
| 48 | #define PCA_CHIP_TYPE(x) ((x) & PCA_TYPE_MASK) |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 49 | |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 50 | static const struct i2c_device_id pca953x_id[] = { |
Gregory CLEMENT | 89f5df0 | 2013-01-22 22:10:24 +0100 | [diff] [blame] | 51 | { "pca9505", 40 | PCA953X_TYPE | PCA_INT, }, |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 52 | { "pca9534", 8 | PCA953X_TYPE | PCA_INT, }, |
| 53 | { "pca9535", 16 | PCA953X_TYPE | PCA_INT, }, |
| 54 | { "pca9536", 4 | PCA953X_TYPE, }, |
| 55 | { "pca9537", 4 | PCA953X_TYPE | PCA_INT, }, |
| 56 | { "pca9538", 8 | PCA953X_TYPE | PCA_INT, }, |
| 57 | { "pca9539", 16 | PCA953X_TYPE | PCA_INT, }, |
| 58 | { "pca9554", 8 | PCA953X_TYPE | PCA_INT, }, |
| 59 | { "pca9555", 16 | PCA953X_TYPE | PCA_INT, }, |
| 60 | { "pca9556", 8 | PCA953X_TYPE, }, |
| 61 | { "pca9557", 8 | PCA953X_TYPE, }, |
| 62 | { "pca9574", 8 | PCA957X_TYPE | PCA_INT, }, |
| 63 | { "pca9575", 16 | PCA957X_TYPE | PCA_INT, }, |
Aaron Sierra | eb32b5a | 2014-02-13 13:59:23 +0100 | [diff] [blame] | 64 | { "pca9698", 40 | PCA953X_TYPE, }, |
David Brownell | ab5dc372 | 2009-01-06 14:42:27 -0800 | [diff] [blame] | 65 | |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 66 | { "max7310", 8 | PCA953X_TYPE, }, |
| 67 | { "max7312", 16 | PCA953X_TYPE | PCA_INT, }, |
| 68 | { "max7313", 16 | PCA953X_TYPE | PCA_INT, }, |
| 69 | { "max7315", 8 | PCA953X_TYPE | PCA_INT, }, |
| 70 | { "pca6107", 8 | PCA953X_TYPE | PCA_INT, }, |
| 71 | { "tca6408", 8 | PCA953X_TYPE | PCA_INT, }, |
| 72 | { "tca6416", 16 | PCA953X_TYPE | PCA_INT, }, |
Andreas Schallenberg | ae79c19 | 2012-05-09 09:46:17 +0200 | [diff] [blame] | 73 | { "tca6424", 24 | PCA953X_TYPE | PCA_INT, }, |
Thierry Reding | 2db8aba | 2015-09-29 12:55:44 +0200 | [diff] [blame] | 74 | { "tca9539", 16 | PCA953X_TYPE | PCA_INT, }, |
Aaron Sierra | e73760a | 2014-02-07 16:36:21 -0600 | [diff] [blame] | 75 | { "xra1202", 8 | PCA953X_TYPE }, |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 76 | { } |
Guennadi Liakhovetski | f5e8ff4 | 2008-02-06 01:39:04 -0800 | [diff] [blame] | 77 | }; |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 78 | MODULE_DEVICE_TABLE(i2c, pca953x_id); |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 79 | |
Andy Shevchenko | f32517b | 2015-10-01 14:20:28 +0300 | [diff] [blame] | 80 | static const struct acpi_device_id pca953x_acpi_ids[] = { |
| 81 | { "INT3491", 16 | PCA953X_TYPE | PCA_INT, }, |
| 82 | { } |
| 83 | }; |
| 84 | MODULE_DEVICE_TABLE(acpi, pca953x_acpi_ids); |
| 85 | |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 86 | #define MAX_BANK 5 |
| 87 | #define BANK_SZ 8 |
| 88 | |
| 89 | #define NBANK(chip) (chip->gpio_chip.ngpio / BANK_SZ) |
| 90 | |
Guennadi Liakhovetski | f3dc363 | 2008-02-06 01:39:03 -0800 | [diff] [blame] | 91 | struct pca953x_chip { |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 92 | unsigned gpio_start; |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 93 | u8 reg_output[MAX_BANK]; |
| 94 | u8 reg_direction[MAX_BANK]; |
Roland Stigge | 6e20fb1 | 2011-02-10 15:01:23 -0800 | [diff] [blame] | 95 | struct mutex i2c_lock; |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 96 | |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 97 | #ifdef CONFIG_GPIO_PCA953X_IRQ |
| 98 | struct mutex irq_lock; |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 99 | u8 irq_mask[MAX_BANK]; |
| 100 | u8 irq_stat[MAX_BANK]; |
| 101 | u8 irq_trig_raise[MAX_BANK]; |
| 102 | u8 irq_trig_fall[MAX_BANK]; |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 103 | #endif |
| 104 | |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 105 | struct i2c_client *client; |
| 106 | struct gpio_chip gpio_chip; |
Uwe Kleine-König | 6215499 | 2010-05-26 14:42:17 -0700 | [diff] [blame] | 107 | const char *const *names; |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 108 | int chip_type; |
Andy Shevchenko | c666414 | 2015-10-01 14:20:27 +0300 | [diff] [blame] | 109 | unsigned long driver_data; |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 110 | }; |
| 111 | |
Linus Walleij | 7bcbce5 | 2014-05-09 13:27:57 +0200 | [diff] [blame] | 112 | static inline struct pca953x_chip *to_pca(struct gpio_chip *gc) |
| 113 | { |
| 114 | return container_of(gc, struct pca953x_chip, gpio_chip); |
| 115 | } |
| 116 | |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 117 | static int pca953x_read_single(struct pca953x_chip *chip, int reg, u32 *val, |
| 118 | int off) |
| 119 | { |
| 120 | int ret; |
| 121 | int bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ); |
| 122 | int offset = off / BANK_SZ; |
| 123 | |
| 124 | ret = i2c_smbus_read_byte_data(chip->client, |
| 125 | (reg << bank_shift) + offset); |
| 126 | *val = ret; |
| 127 | |
| 128 | if (ret < 0) { |
| 129 | dev_err(&chip->client->dev, "failed reading register\n"); |
| 130 | return ret; |
| 131 | } |
| 132 | |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | static int pca953x_write_single(struct pca953x_chip *chip, int reg, u32 val, |
| 137 | int off) |
| 138 | { |
| 139 | int ret = 0; |
| 140 | int bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ); |
| 141 | int offset = off / BANK_SZ; |
| 142 | |
| 143 | ret = i2c_smbus_write_byte_data(chip->client, |
| 144 | (reg << bank_shift) + offset, val); |
| 145 | |
| 146 | if (ret < 0) { |
| 147 | dev_err(&chip->client->dev, "failed writing register\n"); |
| 148 | return ret; |
| 149 | } |
| 150 | |
| 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | static int pca953x_write_regs(struct pca953x_chip *chip, int reg, u8 *val) |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 155 | { |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 156 | int ret = 0; |
Guennadi Liakhovetski | f5e8ff4 | 2008-02-06 01:39:04 -0800 | [diff] [blame] | 157 | |
| 158 | if (chip->gpio_chip.ngpio <= 8) |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 159 | ret = i2c_smbus_write_byte_data(chip->client, reg, *val); |
| 160 | else if (chip->gpio_chip.ngpio >= 24) { |
| 161 | int bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ); |
Andreas Schallenberg | 96b7064 | 2012-05-21 09:52:43 +0200 | [diff] [blame] | 162 | ret = i2c_smbus_write_i2c_block_data(chip->client, |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 163 | (reg << bank_shift) | REG_ADDR_AI, |
| 164 | NBANK(chip), val); |
Laurent Navet | 50e4443 | 2013-03-20 13:15:58 +0100 | [diff] [blame] | 165 | } else { |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 166 | switch (chip->chip_type) { |
| 167 | case PCA953X_TYPE: |
| 168 | ret = i2c_smbus_write_word_data(chip->client, |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 169 | reg << 1, (u16) *val); |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 170 | break; |
| 171 | case PCA957X_TYPE: |
| 172 | ret = i2c_smbus_write_byte_data(chip->client, reg << 1, |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 173 | val[0]); |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 174 | if (ret < 0) |
| 175 | break; |
| 176 | ret = i2c_smbus_write_byte_data(chip->client, |
| 177 | (reg << 1) + 1, |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 178 | val[1]); |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 179 | break; |
| 180 | } |
| 181 | } |
Guennadi Liakhovetski | f5e8ff4 | 2008-02-06 01:39:04 -0800 | [diff] [blame] | 182 | |
| 183 | if (ret < 0) { |
| 184 | dev_err(&chip->client->dev, "failed writing register\n"); |
David Brownell | ab5dc372 | 2009-01-06 14:42:27 -0800 | [diff] [blame] | 185 | return ret; |
Guennadi Liakhovetski | f5e8ff4 | 2008-02-06 01:39:04 -0800 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | return 0; |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 189 | } |
| 190 | |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 191 | static int pca953x_read_regs(struct pca953x_chip *chip, int reg, u8 *val) |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 192 | { |
| 193 | int ret; |
| 194 | |
Andreas Schallenberg | 96b7064 | 2012-05-21 09:52:43 +0200 | [diff] [blame] | 195 | if (chip->gpio_chip.ngpio <= 8) { |
Guennadi Liakhovetski | f5e8ff4 | 2008-02-06 01:39:04 -0800 | [diff] [blame] | 196 | ret = i2c_smbus_read_byte_data(chip->client, reg); |
Andreas Schallenberg | 96b7064 | 2012-05-21 09:52:43 +0200 | [diff] [blame] | 197 | *val = ret; |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 198 | } else if (chip->gpio_chip.ngpio >= 24) { |
| 199 | int bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ); |
| 200 | |
Andreas Schallenberg | 96b7064 | 2012-05-21 09:52:43 +0200 | [diff] [blame] | 201 | ret = i2c_smbus_read_i2c_block_data(chip->client, |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 202 | (reg << bank_shift) | REG_ADDR_AI, |
| 203 | NBANK(chip), val); |
Andreas Schallenberg | 96b7064 | 2012-05-21 09:52:43 +0200 | [diff] [blame] | 204 | } else { |
Guennadi Liakhovetski | f5e8ff4 | 2008-02-06 01:39:04 -0800 | [diff] [blame] | 205 | ret = i2c_smbus_read_word_data(chip->client, reg << 1); |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 206 | val[0] = (u16)ret & 0xFF; |
| 207 | val[1] = (u16)ret >> 8; |
Andreas Schallenberg | 96b7064 | 2012-05-21 09:52:43 +0200 | [diff] [blame] | 208 | } |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 209 | if (ret < 0) { |
| 210 | dev_err(&chip->client->dev, "failed reading register\n"); |
David Brownell | ab5dc372 | 2009-01-06 14:42:27 -0800 | [diff] [blame] | 211 | return ret; |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 212 | } |
| 213 | |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 214 | return 0; |
| 215 | } |
| 216 | |
Guennadi Liakhovetski | f3dc363 | 2008-02-06 01:39:03 -0800 | [diff] [blame] | 217 | static int pca953x_gpio_direction_input(struct gpio_chip *gc, unsigned off) |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 218 | { |
Linus Walleij | 7bcbce5 | 2014-05-09 13:27:57 +0200 | [diff] [blame] | 219 | struct pca953x_chip *chip = to_pca(gc); |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 220 | u8 reg_val; |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 221 | int ret, offset = 0; |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 222 | |
Roland Stigge | 6e20fb1 | 2011-02-10 15:01:23 -0800 | [diff] [blame] | 223 | mutex_lock(&chip->i2c_lock); |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 224 | reg_val = chip->reg_direction[off / BANK_SZ] | (1u << (off % BANK_SZ)); |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 225 | |
| 226 | switch (chip->chip_type) { |
| 227 | case PCA953X_TYPE: |
| 228 | offset = PCA953X_DIRECTION; |
| 229 | break; |
| 230 | case PCA957X_TYPE: |
| 231 | offset = PCA957X_CFG; |
| 232 | break; |
| 233 | } |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 234 | ret = pca953x_write_single(chip, offset, reg_val, off); |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 235 | if (ret) |
Roland Stigge | 6e20fb1 | 2011-02-10 15:01:23 -0800 | [diff] [blame] | 236 | goto exit; |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 237 | |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 238 | chip->reg_direction[off / BANK_SZ] = reg_val; |
Roland Stigge | 6e20fb1 | 2011-02-10 15:01:23 -0800 | [diff] [blame] | 239 | ret = 0; |
| 240 | exit: |
| 241 | mutex_unlock(&chip->i2c_lock); |
| 242 | return ret; |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 243 | } |
| 244 | |
Guennadi Liakhovetski | f3dc363 | 2008-02-06 01:39:03 -0800 | [diff] [blame] | 245 | static int pca953x_gpio_direction_output(struct gpio_chip *gc, |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 246 | unsigned off, int val) |
| 247 | { |
Linus Walleij | 7bcbce5 | 2014-05-09 13:27:57 +0200 | [diff] [blame] | 248 | struct pca953x_chip *chip = to_pca(gc); |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 249 | u8 reg_val; |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 250 | int ret, offset = 0; |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 251 | |
Roland Stigge | 6e20fb1 | 2011-02-10 15:01:23 -0800 | [diff] [blame] | 252 | mutex_lock(&chip->i2c_lock); |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 253 | /* set output level */ |
| 254 | if (val) |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 255 | reg_val = chip->reg_output[off / BANK_SZ] |
| 256 | | (1u << (off % BANK_SZ)); |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 257 | else |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 258 | reg_val = chip->reg_output[off / BANK_SZ] |
| 259 | & ~(1u << (off % BANK_SZ)); |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 260 | |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 261 | switch (chip->chip_type) { |
| 262 | case PCA953X_TYPE: |
| 263 | offset = PCA953X_OUTPUT; |
| 264 | break; |
| 265 | case PCA957X_TYPE: |
| 266 | offset = PCA957X_OUT; |
| 267 | break; |
| 268 | } |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 269 | ret = pca953x_write_single(chip, offset, reg_val, off); |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 270 | if (ret) |
Roland Stigge | 6e20fb1 | 2011-02-10 15:01:23 -0800 | [diff] [blame] | 271 | goto exit; |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 272 | |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 273 | chip->reg_output[off / BANK_SZ] = reg_val; |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 274 | |
| 275 | /* then direction */ |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 276 | reg_val = chip->reg_direction[off / BANK_SZ] & ~(1u << (off % BANK_SZ)); |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 277 | switch (chip->chip_type) { |
| 278 | case PCA953X_TYPE: |
| 279 | offset = PCA953X_DIRECTION; |
| 280 | break; |
| 281 | case PCA957X_TYPE: |
| 282 | offset = PCA957X_CFG; |
| 283 | break; |
| 284 | } |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 285 | ret = pca953x_write_single(chip, offset, reg_val, off); |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 286 | if (ret) |
Roland Stigge | 6e20fb1 | 2011-02-10 15:01:23 -0800 | [diff] [blame] | 287 | goto exit; |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 288 | |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 289 | chip->reg_direction[off / BANK_SZ] = reg_val; |
Roland Stigge | 6e20fb1 | 2011-02-10 15:01:23 -0800 | [diff] [blame] | 290 | ret = 0; |
| 291 | exit: |
| 292 | mutex_unlock(&chip->i2c_lock); |
| 293 | return ret; |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 294 | } |
| 295 | |
Guennadi Liakhovetski | f3dc363 | 2008-02-06 01:39:03 -0800 | [diff] [blame] | 296 | static int pca953x_gpio_get_value(struct gpio_chip *gc, unsigned off) |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 297 | { |
Linus Walleij | 7bcbce5 | 2014-05-09 13:27:57 +0200 | [diff] [blame] | 298 | struct pca953x_chip *chip = to_pca(gc); |
Andreas Schallenberg | ae79c19 | 2012-05-09 09:46:17 +0200 | [diff] [blame] | 299 | u32 reg_val; |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 300 | int ret, offset = 0; |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 301 | |
Roland Stigge | 6e20fb1 | 2011-02-10 15:01:23 -0800 | [diff] [blame] | 302 | mutex_lock(&chip->i2c_lock); |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 303 | switch (chip->chip_type) { |
| 304 | case PCA953X_TYPE: |
| 305 | offset = PCA953X_INPUT; |
| 306 | break; |
| 307 | case PCA957X_TYPE: |
| 308 | offset = PCA957X_IN; |
| 309 | break; |
| 310 | } |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 311 | ret = pca953x_read_single(chip, offset, ®_val, off); |
Roland Stigge | 6e20fb1 | 2011-02-10 15:01:23 -0800 | [diff] [blame] | 312 | mutex_unlock(&chip->i2c_lock); |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 313 | if (ret < 0) { |
| 314 | /* NOTE: diagnostic already emitted; that's all we should |
| 315 | * do unless gpio_*_value_cansleep() calls become different |
| 316 | * from their nonsleeping siblings (and report faults). |
| 317 | */ |
| 318 | return 0; |
| 319 | } |
| 320 | |
Andrew Ruder | 40a625d | 2013-08-07 16:52:40 -0500 | [diff] [blame] | 321 | return (reg_val & (1u << (off % BANK_SZ))) ? 1 : 0; |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 322 | } |
| 323 | |
Guennadi Liakhovetski | f3dc363 | 2008-02-06 01:39:03 -0800 | [diff] [blame] | 324 | static void pca953x_gpio_set_value(struct gpio_chip *gc, unsigned off, int val) |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 325 | { |
Linus Walleij | 7bcbce5 | 2014-05-09 13:27:57 +0200 | [diff] [blame] | 326 | struct pca953x_chip *chip = to_pca(gc); |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 327 | u8 reg_val; |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 328 | int ret, offset = 0; |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 329 | |
Roland Stigge | 6e20fb1 | 2011-02-10 15:01:23 -0800 | [diff] [blame] | 330 | mutex_lock(&chip->i2c_lock); |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 331 | if (val) |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 332 | reg_val = chip->reg_output[off / BANK_SZ] |
| 333 | | (1u << (off % BANK_SZ)); |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 334 | else |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 335 | reg_val = chip->reg_output[off / BANK_SZ] |
| 336 | & ~(1u << (off % BANK_SZ)); |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 337 | |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 338 | switch (chip->chip_type) { |
| 339 | case PCA953X_TYPE: |
| 340 | offset = PCA953X_OUTPUT; |
| 341 | break; |
| 342 | case PCA957X_TYPE: |
| 343 | offset = PCA957X_OUT; |
| 344 | break; |
| 345 | } |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 346 | ret = pca953x_write_single(chip, offset, reg_val, off); |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 347 | if (ret) |
Roland Stigge | 6e20fb1 | 2011-02-10 15:01:23 -0800 | [diff] [blame] | 348 | goto exit; |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 349 | |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 350 | chip->reg_output[off / BANK_SZ] = reg_val; |
Roland Stigge | 6e20fb1 | 2011-02-10 15:01:23 -0800 | [diff] [blame] | 351 | exit: |
| 352 | mutex_unlock(&chip->i2c_lock); |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 353 | } |
| 354 | |
Guennadi Liakhovetski | f5e8ff4 | 2008-02-06 01:39:04 -0800 | [diff] [blame] | 355 | static void pca953x_setup_gpio(struct pca953x_chip *chip, int gpios) |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 356 | { |
| 357 | struct gpio_chip *gc; |
| 358 | |
| 359 | gc = &chip->gpio_chip; |
| 360 | |
Guennadi Liakhovetski | f3dc363 | 2008-02-06 01:39:03 -0800 | [diff] [blame] | 361 | gc->direction_input = pca953x_gpio_direction_input; |
| 362 | gc->direction_output = pca953x_gpio_direction_output; |
| 363 | gc->get = pca953x_gpio_get_value; |
| 364 | gc->set = pca953x_gpio_set_value; |
Linus Walleij | 9fb1f39 | 2013-12-04 14:42:46 +0100 | [diff] [blame] | 365 | gc->can_sleep = true; |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 366 | |
| 367 | gc->base = chip->gpio_start; |
Guennadi Liakhovetski | f5e8ff4 | 2008-02-06 01:39:04 -0800 | [diff] [blame] | 368 | gc->ngpio = gpios; |
| 369 | gc->label = chip->client->name; |
David Brownell | d8f388d8 | 2008-07-25 01:46:07 -0700 | [diff] [blame] | 370 | gc->dev = &chip->client->dev; |
Guennadi Liakhovetski | d72cbed | 2008-04-28 02:14:45 -0700 | [diff] [blame] | 371 | gc->owner = THIS_MODULE; |
Daniel Silverstone | 77906a54 | 2009-06-17 16:26:15 -0700 | [diff] [blame] | 372 | gc->names = chip->names; |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 373 | } |
| 374 | |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 375 | #ifdef CONFIG_GPIO_PCA953X_IRQ |
Lennert Buytenhek | 6f5cfc0 | 2011-01-12 17:00:15 -0800 | [diff] [blame] | 376 | static void pca953x_irq_mask(struct irq_data *d) |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 377 | { |
Linus Walleij | 7bcbce5 | 2014-05-09 13:27:57 +0200 | [diff] [blame] | 378 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
| 379 | struct pca953x_chip *chip = to_pca(gc); |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 380 | |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 381 | chip->irq_mask[d->hwirq / BANK_SZ] &= ~(1 << (d->hwirq % BANK_SZ)); |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 382 | } |
| 383 | |
Lennert Buytenhek | 6f5cfc0 | 2011-01-12 17:00:15 -0800 | [diff] [blame] | 384 | static void pca953x_irq_unmask(struct irq_data *d) |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 385 | { |
Linus Walleij | 7bcbce5 | 2014-05-09 13:27:57 +0200 | [diff] [blame] | 386 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
| 387 | struct pca953x_chip *chip = to_pca(gc); |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 388 | |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 389 | chip->irq_mask[d->hwirq / BANK_SZ] |= 1 << (d->hwirq % BANK_SZ); |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 390 | } |
| 391 | |
Lennert Buytenhek | 6f5cfc0 | 2011-01-12 17:00:15 -0800 | [diff] [blame] | 392 | static void pca953x_irq_bus_lock(struct irq_data *d) |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 393 | { |
Linus Walleij | 7bcbce5 | 2014-05-09 13:27:57 +0200 | [diff] [blame] | 394 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
| 395 | struct pca953x_chip *chip = to_pca(gc); |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 396 | |
| 397 | mutex_lock(&chip->irq_lock); |
| 398 | } |
| 399 | |
Lennert Buytenhek | 6f5cfc0 | 2011-01-12 17:00:15 -0800 | [diff] [blame] | 400 | static void pca953x_irq_bus_sync_unlock(struct irq_data *d) |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 401 | { |
Linus Walleij | 7bcbce5 | 2014-05-09 13:27:57 +0200 | [diff] [blame] | 402 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
| 403 | struct pca953x_chip *chip = to_pca(gc); |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 404 | u8 new_irqs; |
| 405 | int level, i; |
Marc Zyngier | a2cb9ae | 2010-04-27 13:13:07 -0700 | [diff] [blame] | 406 | |
| 407 | /* Look for any newly setup interrupt */ |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 408 | for (i = 0; i < NBANK(chip); i++) { |
| 409 | new_irqs = chip->irq_trig_fall[i] | chip->irq_trig_raise[i]; |
| 410 | new_irqs &= ~chip->reg_direction[i]; |
Marc Zyngier | a2cb9ae | 2010-04-27 13:13:07 -0700 | [diff] [blame] | 411 | |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 412 | while (new_irqs) { |
| 413 | level = __ffs(new_irqs); |
| 414 | pca953x_gpio_direction_input(&chip->gpio_chip, |
| 415 | level + (BANK_SZ * i)); |
| 416 | new_irqs &= ~(1 << level); |
| 417 | } |
Marc Zyngier | a2cb9ae | 2010-04-27 13:13:07 -0700 | [diff] [blame] | 418 | } |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 419 | |
| 420 | mutex_unlock(&chip->irq_lock); |
| 421 | } |
| 422 | |
Lennert Buytenhek | 6f5cfc0 | 2011-01-12 17:00:15 -0800 | [diff] [blame] | 423 | static int pca953x_irq_set_type(struct irq_data *d, unsigned int type) |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 424 | { |
Linus Walleij | 7bcbce5 | 2014-05-09 13:27:57 +0200 | [diff] [blame] | 425 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
| 426 | struct pca953x_chip *chip = to_pca(gc); |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 427 | int bank_nb = d->hwirq / BANK_SZ; |
| 428 | u8 mask = 1 << (d->hwirq % BANK_SZ); |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 429 | |
| 430 | if (!(type & IRQ_TYPE_EDGE_BOTH)) { |
| 431 | dev_err(&chip->client->dev, "irq %d: unsupported type %d\n", |
Lennert Buytenhek | 6f5cfc0 | 2011-01-12 17:00:15 -0800 | [diff] [blame] | 432 | d->irq, type); |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 433 | return -EINVAL; |
| 434 | } |
| 435 | |
| 436 | if (type & IRQ_TYPE_EDGE_FALLING) |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 437 | chip->irq_trig_fall[bank_nb] |= mask; |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 438 | else |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 439 | chip->irq_trig_fall[bank_nb] &= ~mask; |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 440 | |
| 441 | if (type & IRQ_TYPE_EDGE_RISING) |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 442 | chip->irq_trig_raise[bank_nb] |= mask; |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 443 | else |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 444 | chip->irq_trig_raise[bank_nb] &= ~mask; |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 445 | |
Marc Zyngier | a2cb9ae | 2010-04-27 13:13:07 -0700 | [diff] [blame] | 446 | return 0; |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | static struct irq_chip pca953x_irq_chip = { |
| 450 | .name = "pca953x", |
Lennert Buytenhek | 6f5cfc0 | 2011-01-12 17:00:15 -0800 | [diff] [blame] | 451 | .irq_mask = pca953x_irq_mask, |
| 452 | .irq_unmask = pca953x_irq_unmask, |
| 453 | .irq_bus_lock = pca953x_irq_bus_lock, |
| 454 | .irq_bus_sync_unlock = pca953x_irq_bus_sync_unlock, |
| 455 | .irq_set_type = pca953x_irq_set_type, |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 456 | }; |
| 457 | |
Joshua Scott | b6ac128 | 2015-05-22 12:35:12 +1200 | [diff] [blame] | 458 | static bool pca953x_irq_pending(struct pca953x_chip *chip, u8 *pending) |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 459 | { |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 460 | u8 cur_stat[MAX_BANK]; |
| 461 | u8 old_stat[MAX_BANK]; |
Joshua Scott | b6ac128 | 2015-05-22 12:35:12 +1200 | [diff] [blame] | 462 | bool pending_seen = false; |
| 463 | bool trigger_seen = false; |
| 464 | u8 trigger[MAX_BANK]; |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 465 | int ret, i, offset = 0; |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 466 | |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 467 | switch (chip->chip_type) { |
| 468 | case PCA953X_TYPE: |
| 469 | offset = PCA953X_INPUT; |
| 470 | break; |
| 471 | case PCA957X_TYPE: |
| 472 | offset = PCA957X_IN; |
| 473 | break; |
| 474 | } |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 475 | ret = pca953x_read_regs(chip, offset, cur_stat); |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 476 | if (ret) |
Joshua Scott | b6ac128 | 2015-05-22 12:35:12 +1200 | [diff] [blame] | 477 | return false; |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 478 | |
| 479 | /* Remove output pins from the equation */ |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 480 | for (i = 0; i < NBANK(chip); i++) |
| 481 | cur_stat[i] &= chip->reg_direction[i]; |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 482 | |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 483 | memcpy(old_stat, chip->irq_stat, NBANK(chip)); |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 484 | |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 485 | for (i = 0; i < NBANK(chip); i++) { |
| 486 | trigger[i] = (cur_stat[i] ^ old_stat[i]) & chip->irq_mask[i]; |
Joshua Scott | b6ac128 | 2015-05-22 12:35:12 +1200 | [diff] [blame] | 487 | if (trigger[i]) |
| 488 | trigger_seen = true; |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 489 | } |
| 490 | |
Joshua Scott | b6ac128 | 2015-05-22 12:35:12 +1200 | [diff] [blame] | 491 | if (!trigger_seen) |
| 492 | return false; |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 493 | |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 494 | memcpy(chip->irq_stat, cur_stat, NBANK(chip)); |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 495 | |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 496 | for (i = 0; i < NBANK(chip); i++) { |
| 497 | pending[i] = (old_stat[i] & chip->irq_trig_fall[i]) | |
| 498 | (cur_stat[i] & chip->irq_trig_raise[i]); |
| 499 | pending[i] &= trigger[i]; |
Joshua Scott | b6ac128 | 2015-05-22 12:35:12 +1200 | [diff] [blame] | 500 | if (pending[i]) |
| 501 | pending_seen = true; |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 502 | } |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 503 | |
Joshua Scott | b6ac128 | 2015-05-22 12:35:12 +1200 | [diff] [blame] | 504 | return pending_seen; |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | static irqreturn_t pca953x_irq_handler(int irq, void *devid) |
| 508 | { |
| 509 | struct pca953x_chip *chip = devid; |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 510 | u8 pending[MAX_BANK]; |
| 511 | u8 level; |
Toby Smith | 3275d07 | 2014-04-30 18:01:40 +1000 | [diff] [blame] | 512 | unsigned nhandled = 0; |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 513 | int i; |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 514 | |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 515 | if (!pca953x_irq_pending(chip, pending)) |
Toby Smith | 3275d07 | 2014-04-30 18:01:40 +1000 | [diff] [blame] | 516 | return IRQ_NONE; |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 517 | |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 518 | for (i = 0; i < NBANK(chip); i++) { |
| 519 | while (pending[i]) { |
| 520 | level = __ffs(pending[i]); |
Linus Walleij | 7bcbce5 | 2014-05-09 13:27:57 +0200 | [diff] [blame] | 521 | handle_nested_irq(irq_find_mapping(chip->gpio_chip.irqdomain, |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 522 | level + (BANK_SZ * i))); |
| 523 | pending[i] &= ~(1 << level); |
Toby Smith | 3275d07 | 2014-04-30 18:01:40 +1000 | [diff] [blame] | 524 | nhandled++; |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 525 | } |
| 526 | } |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 527 | |
Toby Smith | 3275d07 | 2014-04-30 18:01:40 +1000 | [diff] [blame] | 528 | return (nhandled > 0) ? IRQ_HANDLED : IRQ_NONE; |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | static int pca953x_irq_setup(struct pca953x_chip *chip, |
David Jander | c6dcf59 | 2011-06-14 11:00:55 +0200 | [diff] [blame] | 532 | int irq_base) |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 533 | { |
| 534 | struct i2c_client *client = chip->client; |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 535 | int ret, i, offset = 0; |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 536 | |
Markus Pargmann | 4bb9334 | 2014-07-29 09:24:43 +0200 | [diff] [blame] | 537 | if (client->irq && irq_base != -1 |
Andy Shevchenko | c666414 | 2015-10-01 14:20:27 +0300 | [diff] [blame] | 538 | && (chip->driver_data & PCA_INT)) { |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 539 | |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 540 | switch (chip->chip_type) { |
| 541 | case PCA953X_TYPE: |
| 542 | offset = PCA953X_INPUT; |
| 543 | break; |
| 544 | case PCA957X_TYPE: |
| 545 | offset = PCA957X_IN; |
| 546 | break; |
| 547 | } |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 548 | ret = pca953x_read_regs(chip, offset, chip->irq_stat); |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 549 | if (ret) |
Linus Walleij | b42748c | 2013-01-25 17:59:28 +0100 | [diff] [blame] | 550 | return ret; |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 551 | |
| 552 | /* |
| 553 | * There is no way to know which GPIO line generated the |
| 554 | * interrupt. We have to rely on the previous read for |
| 555 | * this purpose. |
| 556 | */ |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 557 | for (i = 0; i < NBANK(chip); i++) |
| 558 | chip->irq_stat[i] &= chip->reg_direction[i]; |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 559 | mutex_init(&chip->irq_lock); |
| 560 | |
Linus Walleij | b42748c | 2013-01-25 17:59:28 +0100 | [diff] [blame] | 561 | ret = devm_request_threaded_irq(&client->dev, |
| 562 | client->irq, |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 563 | NULL, |
| 564 | pca953x_irq_handler, |
Toby Smith | 9132913 | 2014-04-30 18:01:41 +1000 | [diff] [blame] | 565 | IRQF_TRIGGER_LOW | IRQF_ONESHOT | |
| 566 | IRQF_SHARED, |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 567 | dev_name(&client->dev), chip); |
| 568 | if (ret) { |
| 569 | dev_err(&client->dev, "failed to request irq %d\n", |
| 570 | client->irq); |
Gregory CLEMENT | 0e8f2fd | 2013-01-25 17:59:27 +0100 | [diff] [blame] | 571 | return ret; |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 572 | } |
| 573 | |
Linus Walleij | 7bcbce5 | 2014-05-09 13:27:57 +0200 | [diff] [blame] | 574 | ret = gpiochip_irqchip_add(&chip->gpio_chip, |
| 575 | &pca953x_irq_chip, |
| 576 | irq_base, |
| 577 | handle_simple_irq, |
| 578 | IRQ_TYPE_NONE); |
| 579 | if (ret) { |
| 580 | dev_err(&client->dev, |
| 581 | "could not connect irqchip to gpiochip\n"); |
| 582 | return ret; |
| 583 | } |
Grygorii Strashko | fdd5040 | 2015-07-07 17:34:49 +0300 | [diff] [blame] | 584 | |
| 585 | gpiochip_set_chained_irqchip(&chip->gpio_chip, |
| 586 | &pca953x_irq_chip, |
| 587 | client->irq, NULL); |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | return 0; |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 591 | } |
| 592 | |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 593 | #else /* CONFIG_GPIO_PCA953X_IRQ */ |
| 594 | static int pca953x_irq_setup(struct pca953x_chip *chip, |
David Jander | c6dcf59 | 2011-06-14 11:00:55 +0200 | [diff] [blame] | 595 | int irq_base) |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 596 | { |
| 597 | struct i2c_client *client = chip->client; |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 598 | |
Andy Shevchenko | c666414 | 2015-10-01 14:20:27 +0300 | [diff] [blame] | 599 | if (irq_base != -1 && (chip->driver_data & PCA_INT)) |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 600 | dev_warn(&client->dev, "interrupt support not compiled in\n"); |
| 601 | |
| 602 | return 0; |
| 603 | } |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 604 | #endif |
| 605 | |
Bill Pemberton | 3836309 | 2012-11-19 13:22:34 -0500 | [diff] [blame] | 606 | static int device_pca953x_init(struct pca953x_chip *chip, u32 invert) |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 607 | { |
| 608 | int ret; |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 609 | u8 val[MAX_BANK]; |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 610 | |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 611 | ret = pca953x_read_regs(chip, PCA953X_OUTPUT, chip->reg_output); |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 612 | if (ret) |
| 613 | goto out; |
| 614 | |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 615 | ret = pca953x_read_regs(chip, PCA953X_DIRECTION, |
| 616 | chip->reg_direction); |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 617 | if (ret) |
| 618 | goto out; |
| 619 | |
| 620 | /* set platform specific polarity inversion */ |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 621 | if (invert) |
| 622 | memset(val, 0xFF, NBANK(chip)); |
| 623 | else |
| 624 | memset(val, 0, NBANK(chip)); |
| 625 | |
| 626 | ret = pca953x_write_regs(chip, PCA953X_INVERT, val); |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 627 | out: |
| 628 | return ret; |
| 629 | } |
| 630 | |
Bill Pemberton | 3836309 | 2012-11-19 13:22:34 -0500 | [diff] [blame] | 631 | static int device_pca957x_init(struct pca953x_chip *chip, u32 invert) |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 632 | { |
| 633 | int ret; |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 634 | u8 val[MAX_BANK]; |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 635 | |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 636 | ret = pca953x_read_regs(chip, PCA957X_OUT, chip->reg_output); |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 637 | if (ret) |
| 638 | goto out; |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 639 | ret = pca953x_read_regs(chip, PCA957X_CFG, chip->reg_direction); |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 640 | if (ret) |
| 641 | goto out; |
| 642 | |
| 643 | /* set platform specific polarity inversion */ |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 644 | if (invert) |
| 645 | memset(val, 0xFF, NBANK(chip)); |
| 646 | else |
| 647 | memset(val, 0, NBANK(chip)); |
Nicholas Krause | c75a377 | 2015-08-26 17:52:19 -0400 | [diff] [blame] | 648 | ret = pca953x_write_regs(chip, PCA957X_INVRT, val); |
| 649 | if (ret) |
| 650 | goto out; |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 651 | |
Colin Cronin | 20a8a96 | 2015-05-18 11:41:43 -0700 | [diff] [blame] | 652 | /* To enable register 6, 7 to control pull up and pull down */ |
Gregory CLEMENT | f5f0b7a | 2013-01-22 22:10:23 +0100 | [diff] [blame] | 653 | memset(val, 0x02, NBANK(chip)); |
Nicholas Krause | c75a377 | 2015-08-26 17:52:19 -0400 | [diff] [blame] | 654 | ret = pca953x_write_regs(chip, PCA957X_BKEN, val); |
| 655 | if (ret) |
| 656 | goto out; |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 657 | |
| 658 | return 0; |
| 659 | out: |
| 660 | return ret; |
| 661 | } |
| 662 | |
Bill Pemberton | 3836309 | 2012-11-19 13:22:34 -0500 | [diff] [blame] | 663 | static int pca953x_probe(struct i2c_client *client, |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 664 | const struct i2c_device_id *id) |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 665 | { |
Guennadi Liakhovetski | f3dc363 | 2008-02-06 01:39:03 -0800 | [diff] [blame] | 666 | struct pca953x_platform_data *pdata; |
| 667 | struct pca953x_chip *chip; |
Chandrabhanu Mahapatra | 6a7b36a | 2012-07-10 19:05:37 +0530 | [diff] [blame] | 668 | int irq_base = 0; |
Wolfram Sang | 7ea2aa2 | 2011-10-14 15:32:00 +0200 | [diff] [blame] | 669 | int ret; |
Chandrabhanu Mahapatra | 6a7b36a | 2012-07-10 19:05:37 +0530 | [diff] [blame] | 670 | u32 invert = 0; |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 671 | |
Linus Walleij | b42748c | 2013-01-25 17:59:28 +0100 | [diff] [blame] | 672 | chip = devm_kzalloc(&client->dev, |
| 673 | sizeof(struct pca953x_chip), GFP_KERNEL); |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 674 | if (chip == NULL) |
| 675 | return -ENOMEM; |
| 676 | |
Jingoo Han | e56aee1 | 2013-07-30 17:08:05 +0900 | [diff] [blame] | 677 | pdata = dev_get_platdata(&client->dev); |
David Jander | c6dcf59 | 2011-06-14 11:00:55 +0200 | [diff] [blame] | 678 | if (pdata) { |
| 679 | irq_base = pdata->irq_base; |
| 680 | chip->gpio_start = pdata->gpio_base; |
| 681 | invert = pdata->invert; |
| 682 | chip->names = pdata->names; |
| 683 | } else { |
Markus Pargmann | 4bb9334 | 2014-07-29 09:24:43 +0200 | [diff] [blame] | 684 | chip->gpio_start = -1; |
| 685 | irq_base = 0; |
Nate Case | 1965d30 | 2009-06-17 16:26:17 -0700 | [diff] [blame] | 686 | } |
| 687 | |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 688 | chip->client = client; |
| 689 | |
Andy Shevchenko | f32517b | 2015-10-01 14:20:28 +0300 | [diff] [blame] | 690 | if (id) { |
| 691 | chip->driver_data = id->driver_data; |
| 692 | } else { |
| 693 | const struct acpi_device_id *id; |
| 694 | |
| 695 | id = acpi_match_device(pca953x_acpi_ids, &client->dev); |
| 696 | if (!id) |
| 697 | return -ENODEV; |
| 698 | |
| 699 | chip->driver_data = id->driver_data; |
| 700 | } |
| 701 | |
Andy Shevchenko | c666414 | 2015-10-01 14:20:27 +0300 | [diff] [blame] | 702 | chip->chip_type = PCA_CHIP_TYPE(chip->driver_data); |
Daniel Silverstone | 77906a54 | 2009-06-17 16:26:15 -0700 | [diff] [blame] | 703 | |
Roland Stigge | 6e20fb1 | 2011-02-10 15:01:23 -0800 | [diff] [blame] | 704 | mutex_init(&chip->i2c_lock); |
| 705 | |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 706 | /* initialize cached registers from their original values. |
| 707 | * we can't share this chip with another i2c master. |
| 708 | */ |
Andy Shevchenko | c666414 | 2015-10-01 14:20:27 +0300 | [diff] [blame] | 709 | pca953x_setup_gpio(chip, chip->driver_data & PCA_GPIO_MASK); |
Guennadi Liakhovetski | f5e8ff4 | 2008-02-06 01:39:04 -0800 | [diff] [blame] | 710 | |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 711 | if (chip->chip_type == PCA953X_TYPE) |
Wolfram Sang | 7ea2aa2 | 2011-10-14 15:32:00 +0200 | [diff] [blame] | 712 | ret = device_pca953x_init(chip, invert); |
Haojian Zhuang | 33226ff | 2011-04-18 22:12:46 +0800 | [diff] [blame] | 713 | else |
Wolfram Sang | 7ea2aa2 | 2011-10-14 15:32:00 +0200 | [diff] [blame] | 714 | ret = device_pca957x_init(chip, invert); |
| 715 | if (ret) |
Linus Walleij | b42748c | 2013-01-25 17:59:28 +0100 | [diff] [blame] | 716 | return ret; |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 717 | |
Linus Walleij | 7bcbce5 | 2014-05-09 13:27:57 +0200 | [diff] [blame] | 718 | ret = gpiochip_add(&chip->gpio_chip); |
Marc Zyngier | 89ea8bb | 2010-03-05 13:44:36 -0800 | [diff] [blame] | 719 | if (ret) |
Linus Walleij | b42748c | 2013-01-25 17:59:28 +0100 | [diff] [blame] | 720 | return ret; |
Guennadi Liakhovetski | f5e8ff4 | 2008-02-06 01:39:04 -0800 | [diff] [blame] | 721 | |
Andy Shevchenko | c666414 | 2015-10-01 14:20:27 +0300 | [diff] [blame] | 722 | ret = pca953x_irq_setup(chip, irq_base); |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 723 | if (ret) |
Linus Walleij | b42748c | 2013-01-25 17:59:28 +0100 | [diff] [blame] | 724 | return ret; |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 725 | |
David Jander | c6dcf59 | 2011-06-14 11:00:55 +0200 | [diff] [blame] | 726 | if (pdata && pdata->setup) { |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 727 | ret = pdata->setup(client, chip->gpio_chip.base, |
| 728 | chip->gpio_chip.ngpio, pdata->context); |
| 729 | if (ret < 0) |
| 730 | dev_warn(&client->dev, "setup failed, %d\n", ret); |
| 731 | } |
| 732 | |
| 733 | i2c_set_clientdata(client, chip); |
| 734 | return 0; |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 735 | } |
| 736 | |
Guennadi Liakhovetski | f3dc363 | 2008-02-06 01:39:03 -0800 | [diff] [blame] | 737 | static int pca953x_remove(struct i2c_client *client) |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 738 | { |
Jingoo Han | e56aee1 | 2013-07-30 17:08:05 +0900 | [diff] [blame] | 739 | struct pca953x_platform_data *pdata = dev_get_platdata(&client->dev); |
Guennadi Liakhovetski | f3dc363 | 2008-02-06 01:39:03 -0800 | [diff] [blame] | 740 | struct pca953x_chip *chip = i2c_get_clientdata(client); |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 741 | int ret = 0; |
| 742 | |
David Jander | c6dcf59 | 2011-06-14 11:00:55 +0200 | [diff] [blame] | 743 | if (pdata && pdata->teardown) { |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 744 | ret = pdata->teardown(client, chip->gpio_chip.base, |
| 745 | chip->gpio_chip.ngpio, pdata->context); |
| 746 | if (ret < 0) { |
| 747 | dev_err(&client->dev, "%s failed, %d\n", |
| 748 | "teardown", ret); |
| 749 | return ret; |
| 750 | } |
| 751 | } |
| 752 | |
abdoulaye berthe | 9f5132a | 2014-07-12 22:30:12 +0200 | [diff] [blame] | 753 | gpiochip_remove(&chip->gpio_chip); |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 754 | |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 755 | return 0; |
| 756 | } |
| 757 | |
Maxime Ripard | ed32620 | 2012-11-08 18:01:52 +0100 | [diff] [blame] | 758 | static const struct of_device_id pca953x_dt_ids[] = { |
Gregory CLEMENT | 89f5df0 | 2013-01-22 22:10:24 +0100 | [diff] [blame] | 759 | { .compatible = "nxp,pca9505", }, |
Maxime Ripard | ed32620 | 2012-11-08 18:01:52 +0100 | [diff] [blame] | 760 | { .compatible = "nxp,pca9534", }, |
| 761 | { .compatible = "nxp,pca9535", }, |
| 762 | { .compatible = "nxp,pca9536", }, |
| 763 | { .compatible = "nxp,pca9537", }, |
| 764 | { .compatible = "nxp,pca9538", }, |
| 765 | { .compatible = "nxp,pca9539", }, |
| 766 | { .compatible = "nxp,pca9554", }, |
| 767 | { .compatible = "nxp,pca9555", }, |
| 768 | { .compatible = "nxp,pca9556", }, |
| 769 | { .compatible = "nxp,pca9557", }, |
| 770 | { .compatible = "nxp,pca9574", }, |
| 771 | { .compatible = "nxp,pca9575", }, |
Aaron Sierra | eb32b5a | 2014-02-13 13:59:23 +0100 | [diff] [blame] | 772 | { .compatible = "nxp,pca9698", }, |
Maxime Ripard | ed32620 | 2012-11-08 18:01:52 +0100 | [diff] [blame] | 773 | |
| 774 | { .compatible = "maxim,max7310", }, |
| 775 | { .compatible = "maxim,max7312", }, |
| 776 | { .compatible = "maxim,max7313", }, |
| 777 | { .compatible = "maxim,max7315", }, |
| 778 | |
| 779 | { .compatible = "ti,pca6107", }, |
| 780 | { .compatible = "ti,tca6408", }, |
| 781 | { .compatible = "ti,tca6416", }, |
| 782 | { .compatible = "ti,tca6424", }, |
Aaron Sierra | e73760a | 2014-02-07 16:36:21 -0600 | [diff] [blame] | 783 | |
| 784 | { .compatible = "exar,xra1202", }, |
Maxime Ripard | ed32620 | 2012-11-08 18:01:52 +0100 | [diff] [blame] | 785 | { } |
| 786 | }; |
| 787 | |
| 788 | MODULE_DEVICE_TABLE(of, pca953x_dt_ids); |
| 789 | |
Guennadi Liakhovetski | f3dc363 | 2008-02-06 01:39:03 -0800 | [diff] [blame] | 790 | static struct i2c_driver pca953x_driver = { |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 791 | .driver = { |
Guennadi Liakhovetski | f3dc363 | 2008-02-06 01:39:03 -0800 | [diff] [blame] | 792 | .name = "pca953x", |
Maxime Ripard | ed32620 | 2012-11-08 18:01:52 +0100 | [diff] [blame] | 793 | .of_match_table = pca953x_dt_ids, |
Andy Shevchenko | f32517b | 2015-10-01 14:20:28 +0300 | [diff] [blame] | 794 | .acpi_match_table = ACPI_PTR(pca953x_acpi_ids), |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 795 | }, |
Guennadi Liakhovetski | f3dc363 | 2008-02-06 01:39:03 -0800 | [diff] [blame] | 796 | .probe = pca953x_probe, |
| 797 | .remove = pca953x_remove, |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 798 | .id_table = pca953x_id, |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 799 | }; |
| 800 | |
Guennadi Liakhovetski | f3dc363 | 2008-02-06 01:39:03 -0800 | [diff] [blame] | 801 | static int __init pca953x_init(void) |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 802 | { |
Guennadi Liakhovetski | f3dc363 | 2008-02-06 01:39:03 -0800 | [diff] [blame] | 803 | return i2c_add_driver(&pca953x_driver); |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 804 | } |
David Brownell | 2f8d119 | 2008-10-15 22:03:13 -0700 | [diff] [blame] | 805 | /* register after i2c postcore initcall and before |
| 806 | * subsys initcalls that may rely on these GPIOs |
| 807 | */ |
| 808 | subsys_initcall(pca953x_init); |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 809 | |
Guennadi Liakhovetski | f3dc363 | 2008-02-06 01:39:03 -0800 | [diff] [blame] | 810 | static void __exit pca953x_exit(void) |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 811 | { |
Guennadi Liakhovetski | f3dc363 | 2008-02-06 01:39:03 -0800 | [diff] [blame] | 812 | i2c_del_driver(&pca953x_driver); |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 813 | } |
Guennadi Liakhovetski | f3dc363 | 2008-02-06 01:39:03 -0800 | [diff] [blame] | 814 | module_exit(pca953x_exit); |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 815 | |
| 816 | MODULE_AUTHOR("eric miao <eric.miao@marvell.com>"); |
Guennadi Liakhovetski | f3dc363 | 2008-02-06 01:39:03 -0800 | [diff] [blame] | 817 | MODULE_DESCRIPTION("GPIO expander driver for PCA953x"); |
eric miao | 9e60fdc | 2008-02-04 22:28:26 -0800 | [diff] [blame] | 818 | MODULE_LICENSE("GPL"); |