Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Take linux kernel driver drivers/gpio/gpio-pca953x.c for reference. |
| 4 | * |
| 5 | * Copyright (C) 2016 Peng Fan <van.freenix@gmail.com> |
| 6 | * |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | /* |
| 10 | * Note: |
| 11 | * The driver's compatible table is borrowed from Linux Kernel, |
| 12 | * but now max supported gpio pins is 24 and only PCA953X_TYPE |
| 13 | * is supported. PCA957X_TYPE is not supported now. |
| 14 | * Also the Polarity Inversion feature is not supported now. |
| 15 | * |
| 16 | * TODO: |
| 17 | * 1. Support PCA957X_TYPE |
Vignesh Raghavendra | dd6638a | 2020-01-27 23:19:00 +0530 | [diff] [blame] | 18 | * 2. Support Polarity Inversion |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include <common.h> |
| 22 | #include <errno.h> |
| 23 | #include <dm.h> |
| 24 | #include <fdtdec.h> |
| 25 | #include <i2c.h> |
| 26 | #include <malloc.h> |
| 27 | #include <asm/gpio.h> |
| 28 | #include <asm/io.h> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 29 | #include <dm/device_compat.h> |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 30 | #include <dt-bindings/gpio/gpio.h> |
Simon Glass | cd93d62 | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 31 | #include <linux/bitops.h> |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 32 | |
| 33 | #define PCA953X_INPUT 0 |
| 34 | #define PCA953X_OUTPUT 1 |
| 35 | #define PCA953X_INVERT 2 |
| 36 | #define PCA953X_DIRECTION 3 |
| 37 | |
Luca Ellero | c170fe0 | 2022-03-22 15:38:36 +0100 | [diff] [blame] | 38 | #define PCA957X_INPUT 0 |
| 39 | #define PCA957X_OUTPUT 5 |
| 40 | #define PCA957X_INVERT 1 |
| 41 | #define PCA957X_DIRECTION 4 |
| 42 | |
| 43 | |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 44 | #define PCA_GPIO_MASK 0x00FF |
| 45 | #define PCA_INT 0x0100 |
| 46 | #define PCA953X_TYPE 0x1000 |
| 47 | #define PCA957X_TYPE 0x2000 |
| 48 | #define PCA_TYPE_MASK 0xF000 |
| 49 | #define PCA_CHIP_TYPE(x) ((x) & PCA_TYPE_MASK) |
| 50 | |
| 51 | enum { |
| 52 | PCA953X_DIRECTION_IN, |
| 53 | PCA953X_DIRECTION_OUT, |
| 54 | }; |
| 55 | |
mario.six@gdsys.cc | 71db327 | 2016-04-25 15:25:37 +0200 | [diff] [blame] | 56 | #define MAX_BANK 5 |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 57 | #define BANK_SZ 8 |
| 58 | |
Luca Ellero | c170fe0 | 2022-03-22 15:38:36 +0100 | [diff] [blame] | 59 | struct pca95xx_reg { |
| 60 | int input; |
| 61 | int output; |
| 62 | int invert; |
| 63 | int direction; |
| 64 | }; |
| 65 | |
| 66 | static const struct pca95xx_reg pca953x_regs = { |
| 67 | .direction = PCA953X_DIRECTION, |
| 68 | .output = PCA953X_OUTPUT, |
| 69 | .input = PCA953X_INPUT, |
| 70 | .invert = PCA953X_INVERT, |
| 71 | }; |
| 72 | |
| 73 | static const struct pca95xx_reg pca957x_regs = { |
| 74 | .direction = PCA957X_DIRECTION, |
| 75 | .output = PCA957X_OUTPUT, |
| 76 | .input = PCA957X_INPUT, |
| 77 | .invert = PCA957X_INVERT, |
| 78 | }; |
| 79 | |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 80 | /* |
Luca Ellero | c170fe0 | 2022-03-22 15:38:36 +0100 | [diff] [blame] | 81 | * struct pca953x_info - Data for pca953x/pca957x |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 82 | * |
| 83 | * @dev: udevice structure for the device |
| 84 | * @addr: i2c slave address |
| 85 | * @invert: Polarity inversion or not |
| 86 | * @gpio_count: the number of gpio pins that the device supports |
| 87 | * @chip_type: indicate the chip type,PCA953X or PCA957X |
| 88 | * @bank_count: the number of banks that the device supports |
| 89 | * @reg_output: array to hold the value of output registers |
| 90 | * @reg_direction: array to hold the value of direction registers |
Luca Ellero | c170fe0 | 2022-03-22 15:38:36 +0100 | [diff] [blame] | 91 | * @regs: struct to hold the registers addresses |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 92 | */ |
| 93 | struct pca953x_info { |
| 94 | struct udevice *dev; |
| 95 | int addr; |
| 96 | int invert; |
| 97 | int gpio_count; |
| 98 | int chip_type; |
| 99 | int bank_count; |
| 100 | u8 reg_output[MAX_BANK]; |
| 101 | u8 reg_direction[MAX_BANK]; |
Luca Ellero | c170fe0 | 2022-03-22 15:38:36 +0100 | [diff] [blame] | 102 | const struct pca95xx_reg *regs; |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | static int pca953x_write_single(struct udevice *dev, int reg, u8 val, |
| 106 | int offset) |
| 107 | { |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 108 | struct pca953x_info *info = dev_get_plat(dev); |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 109 | int bank_shift = fls((info->gpio_count - 1) / BANK_SZ); |
| 110 | int off = offset / BANK_SZ; |
| 111 | int ret = 0; |
| 112 | |
| 113 | ret = dm_i2c_write(dev, (reg << bank_shift) + off, &val, 1); |
| 114 | if (ret) { |
| 115 | dev_err(dev, "%s error\n", __func__); |
| 116 | return ret; |
| 117 | } |
| 118 | |
| 119 | return 0; |
| 120 | } |
| 121 | |
| 122 | static int pca953x_read_single(struct udevice *dev, int reg, u8 *val, |
| 123 | int offset) |
| 124 | { |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 125 | struct pca953x_info *info = dev_get_plat(dev); |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 126 | int bank_shift = fls((info->gpio_count - 1) / BANK_SZ); |
| 127 | int off = offset / BANK_SZ; |
| 128 | int ret; |
| 129 | u8 byte; |
| 130 | |
| 131 | ret = dm_i2c_read(dev, (reg << bank_shift) + off, &byte, 1); |
| 132 | if (ret) { |
| 133 | dev_err(dev, "%s error\n", __func__); |
| 134 | return ret; |
| 135 | } |
| 136 | |
| 137 | *val = byte; |
| 138 | |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | static int pca953x_read_regs(struct udevice *dev, int reg, u8 *val) |
| 143 | { |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 144 | struct pca953x_info *info = dev_get_plat(dev); |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 145 | int ret = 0; |
| 146 | |
| 147 | if (info->gpio_count <= 8) { |
| 148 | ret = dm_i2c_read(dev, reg, val, 1); |
| 149 | } else if (info->gpio_count <= 16) { |
| 150 | ret = dm_i2c_read(dev, reg << 1, val, info->bank_count); |
Vignesh Raghavendra | dd6638a | 2020-01-27 23:19:00 +0530 | [diff] [blame] | 151 | } else if (info->gpio_count <= 24) { |
| 152 | /* Auto increment */ |
| 153 | ret = dm_i2c_read(dev, (reg << 2) | 0x80, val, |
| 154 | info->bank_count); |
mario.six@gdsys.cc | 71db327 | 2016-04-25 15:25:37 +0200 | [diff] [blame] | 155 | } else if (info->gpio_count == 40) { |
| 156 | /* Auto increment */ |
Mario Six | fb01e07 | 2018-01-15 11:07:44 +0100 | [diff] [blame] | 157 | ret = dm_i2c_read(dev, (reg << 3) | 0x80, val, |
| 158 | info->bank_count); |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 159 | } else { |
| 160 | dev_err(dev, "Unsupported now\n"); |
| 161 | return -EINVAL; |
| 162 | } |
| 163 | |
| 164 | return ret; |
| 165 | } |
| 166 | |
Ye Li | 3764b2b | 2018-10-18 16:16:46 +0200 | [diff] [blame] | 167 | static int pca953x_write_regs(struct udevice *dev, int reg, u8 *val) |
| 168 | { |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 169 | struct pca953x_info *info = dev_get_plat(dev); |
Ye Li | 3764b2b | 2018-10-18 16:16:46 +0200 | [diff] [blame] | 170 | int ret = 0; |
| 171 | |
| 172 | if (info->gpio_count <= 8) { |
| 173 | ret = dm_i2c_write(dev, reg, val, 1); |
| 174 | } else if (info->gpio_count <= 16) { |
| 175 | ret = dm_i2c_write(dev, reg << 1, val, info->bank_count); |
Vignesh Raghavendra | dd6638a | 2020-01-27 23:19:00 +0530 | [diff] [blame] | 176 | } else if (info->gpio_count <= 24) { |
| 177 | /* Auto increment */ |
| 178 | ret = dm_i2c_write(dev, (reg << 2) | 0x80, val, |
| 179 | info->bank_count); |
Ye Li | 3764b2b | 2018-10-18 16:16:46 +0200 | [diff] [blame] | 180 | } else if (info->gpio_count == 40) { |
| 181 | /* Auto increment */ |
| 182 | ret = dm_i2c_write(dev, (reg << 3) | 0x80, val, info->bank_count); |
| 183 | } else { |
| 184 | return -EINVAL; |
| 185 | } |
| 186 | |
| 187 | return ret; |
| 188 | } |
| 189 | |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 190 | static int pca953x_is_output(struct udevice *dev, int offset) |
| 191 | { |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 192 | struct pca953x_info *info = dev_get_plat(dev); |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 193 | |
| 194 | int bank = offset / BANK_SZ; |
| 195 | int off = offset % BANK_SZ; |
| 196 | |
| 197 | /*0: output; 1: input */ |
| 198 | return !(info->reg_direction[bank] & (1 << off)); |
| 199 | } |
| 200 | |
Mario Six | fb01e07 | 2018-01-15 11:07:44 +0100 | [diff] [blame] | 201 | static int pca953x_get_value(struct udevice *dev, uint offset) |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 202 | { |
Luca Ellero | c170fe0 | 2022-03-22 15:38:36 +0100 | [diff] [blame] | 203 | struct pca953x_info *info = dev_get_plat(dev); |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 204 | int ret; |
| 205 | u8 val = 0; |
| 206 | |
mario.six@gdsys.cc | fc76b69 | 2016-05-23 09:54:56 +0200 | [diff] [blame] | 207 | int off = offset % BANK_SZ; |
| 208 | |
Luca Ellero | c170fe0 | 2022-03-22 15:38:36 +0100 | [diff] [blame] | 209 | ret = pca953x_read_single(dev, info->regs->input, &val, offset); |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 210 | if (ret) |
| 211 | return ret; |
| 212 | |
mario.six@gdsys.cc | fc76b69 | 2016-05-23 09:54:56 +0200 | [diff] [blame] | 213 | return (val >> off) & 0x1; |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 214 | } |
| 215 | |
Mario Six | fb01e07 | 2018-01-15 11:07:44 +0100 | [diff] [blame] | 216 | static int pca953x_set_value(struct udevice *dev, uint offset, int value) |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 217 | { |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 218 | struct pca953x_info *info = dev_get_plat(dev); |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 219 | int bank = offset / BANK_SZ; |
| 220 | int off = offset % BANK_SZ; |
| 221 | u8 val; |
| 222 | int ret; |
| 223 | |
| 224 | if (value) |
| 225 | val = info->reg_output[bank] | (1 << off); |
| 226 | else |
| 227 | val = info->reg_output[bank] & ~(1 << off); |
| 228 | |
Luca Ellero | c170fe0 | 2022-03-22 15:38:36 +0100 | [diff] [blame] | 229 | ret = pca953x_write_single(dev, info->regs->output, val, offset); |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 230 | if (ret) |
| 231 | return ret; |
| 232 | |
| 233 | info->reg_output[bank] = val; |
| 234 | |
| 235 | return 0; |
| 236 | } |
| 237 | |
Mario Six | fb01e07 | 2018-01-15 11:07:44 +0100 | [diff] [blame] | 238 | static int pca953x_set_direction(struct udevice *dev, uint offset, int dir) |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 239 | { |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 240 | struct pca953x_info *info = dev_get_plat(dev); |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 241 | int bank = offset / BANK_SZ; |
| 242 | int off = offset % BANK_SZ; |
| 243 | u8 val; |
| 244 | int ret; |
| 245 | |
| 246 | if (dir == PCA953X_DIRECTION_IN) |
| 247 | val = info->reg_direction[bank] | (1 << off); |
| 248 | else |
| 249 | val = info->reg_direction[bank] & ~(1 << off); |
| 250 | |
Luca Ellero | c170fe0 | 2022-03-22 15:38:36 +0100 | [diff] [blame] | 251 | ret = pca953x_write_single(dev, info->regs->direction, val, offset); |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 252 | if (ret) |
| 253 | return ret; |
| 254 | |
| 255 | info->reg_direction[bank] = val; |
| 256 | |
| 257 | return 0; |
| 258 | } |
| 259 | |
Mario Six | fb01e07 | 2018-01-15 11:07:44 +0100 | [diff] [blame] | 260 | static int pca953x_direction_input(struct udevice *dev, uint offset) |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 261 | { |
| 262 | return pca953x_set_direction(dev, offset, PCA953X_DIRECTION_IN); |
| 263 | } |
| 264 | |
Mario Six | fb01e07 | 2018-01-15 11:07:44 +0100 | [diff] [blame] | 265 | static int pca953x_direction_output(struct udevice *dev, uint offset, int value) |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 266 | { |
| 267 | /* Configure output value. */ |
| 268 | pca953x_set_value(dev, offset, value); |
| 269 | |
| 270 | /* Configure direction as output. */ |
| 271 | pca953x_set_direction(dev, offset, PCA953X_DIRECTION_OUT); |
| 272 | |
| 273 | return 0; |
| 274 | } |
| 275 | |
Mario Six | fb01e07 | 2018-01-15 11:07:44 +0100 | [diff] [blame] | 276 | static int pca953x_get_function(struct udevice *dev, uint offset) |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 277 | { |
| 278 | if (pca953x_is_output(dev, offset)) |
| 279 | return GPIOF_OUTPUT; |
| 280 | else |
| 281 | return GPIOF_INPUT; |
| 282 | } |
| 283 | |
| 284 | static int pca953x_xlate(struct udevice *dev, struct gpio_desc *desc, |
Simon Glass | 3a57123 | 2017-05-18 20:09:18 -0600 | [diff] [blame] | 285 | struct ofnode_phandle_args *args) |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 286 | { |
| 287 | desc->offset = args->args[0]; |
Anatolij Gustschin | 745915a | 2018-10-18 16:15:39 +0200 | [diff] [blame] | 288 | desc->flags = args->args[1] & GPIO_ACTIVE_LOW ? GPIOD_ACTIVE_LOW : 0; |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 289 | |
| 290 | return 0; |
| 291 | } |
| 292 | |
| 293 | static const struct dm_gpio_ops pca953x_ops = { |
| 294 | .direction_input = pca953x_direction_input, |
| 295 | .direction_output = pca953x_direction_output, |
| 296 | .get_value = pca953x_get_value, |
| 297 | .set_value = pca953x_set_value, |
| 298 | .get_function = pca953x_get_function, |
| 299 | .xlate = pca953x_xlate, |
| 300 | }; |
| 301 | |
| 302 | static int pca953x_probe(struct udevice *dev) |
| 303 | { |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 304 | struct pca953x_info *info = dev_get_plat(dev); |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 305 | struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); |
Mario Six | 1e5f898 | 2018-03-01 14:45:04 +0100 | [diff] [blame] | 306 | char name[32], label[8], *str; |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 307 | int addr; |
| 308 | ulong driver_data; |
| 309 | int ret; |
Mario Six | 1e5f898 | 2018-03-01 14:45:04 +0100 | [diff] [blame] | 310 | int size; |
| 311 | const u8 *tmp; |
Ye Li | 3764b2b | 2018-10-18 16:16:46 +0200 | [diff] [blame] | 312 | u8 val[MAX_BANK]; |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 313 | |
Mario Six | f62ca2cd | 2018-01-15 11:07:45 +0100 | [diff] [blame] | 314 | addr = dev_read_addr(dev); |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 315 | if (addr == 0) |
| 316 | return -ENODEV; |
| 317 | |
| 318 | info->addr = addr; |
| 319 | |
| 320 | driver_data = dev_get_driver_data(dev); |
| 321 | |
| 322 | info->gpio_count = driver_data & PCA_GPIO_MASK; |
| 323 | if (info->gpio_count > MAX_BANK * BANK_SZ) { |
| 324 | dev_err(dev, "Max support %d pins now\n", MAX_BANK * BANK_SZ); |
| 325 | return -EINVAL; |
| 326 | } |
| 327 | |
| 328 | info->chip_type = PCA_CHIP_TYPE(driver_data); |
Luca Ellero | c170fe0 | 2022-03-22 15:38:36 +0100 | [diff] [blame] | 329 | if (info->chip_type == PCA953X_TYPE) |
| 330 | info->regs = &pca953x_regs; |
| 331 | else |
| 332 | info->regs = &pca957x_regs; |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 333 | |
| 334 | info->bank_count = DIV_ROUND_UP(info->gpio_count, BANK_SZ); |
| 335 | |
Luca Ellero | c170fe0 | 2022-03-22 15:38:36 +0100 | [diff] [blame] | 336 | ret = pca953x_read_regs(dev, info->regs->output, info->reg_output); |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 337 | if (ret) { |
| 338 | dev_err(dev, "Error reading output register\n"); |
| 339 | return ret; |
| 340 | } |
| 341 | |
| 342 | ret = pca953x_read_regs(dev, PCA953X_DIRECTION, info->reg_direction); |
| 343 | if (ret) { |
| 344 | dev_err(dev, "Error reading direction register\n"); |
| 345 | return ret; |
| 346 | } |
| 347 | |
Mario Six | 1e5f898 | 2018-03-01 14:45:04 +0100 | [diff] [blame] | 348 | tmp = dev_read_prop(dev, "label", &size); |
| 349 | |
| 350 | if (tmp) { |
| 351 | memcpy(label, tmp, sizeof(label) - 1); |
| 352 | label[sizeof(label) - 1] = '\0'; |
| 353 | snprintf(name, sizeof(name), "%s@%x_", label, info->addr); |
| 354 | } else { |
| 355 | snprintf(name, sizeof(name), "gpio@%x_", info->addr); |
| 356 | } |
| 357 | |
Ye Li | 3764b2b | 2018-10-18 16:16:46 +0200 | [diff] [blame] | 358 | /* Clear the polarity registers to no invert */ |
| 359 | memset(val, 0, MAX_BANK); |
Luca Ellero | c170fe0 | 2022-03-22 15:38:36 +0100 | [diff] [blame] | 360 | ret = pca953x_write_regs(dev, info->regs->invert, val); |
Ye Li | 3764b2b | 2018-10-18 16:16:46 +0200 | [diff] [blame] | 361 | if (ret < 0) { |
| 362 | dev_err(dev, "Error writing invert register\n"); |
| 363 | return ret; |
| 364 | } |
| 365 | |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 366 | str = strdup(name); |
| 367 | if (!str) |
| 368 | return -ENOMEM; |
| 369 | uc_priv->bank_name = str; |
| 370 | uc_priv->gpio_count = info->gpio_count; |
| 371 | |
| 372 | dev_dbg(dev, "%s is ready\n", str); |
| 373 | |
| 374 | return 0; |
| 375 | } |
| 376 | |
| 377 | #define OF_953X(__nrgpio, __int) (ulong)(__nrgpio | PCA953X_TYPE | __int) |
| 378 | #define OF_957X(__nrgpio, __int) (ulong)(__nrgpio | PCA957X_TYPE | __int) |
| 379 | |
| 380 | static const struct udevice_id pca953x_ids[] = { |
| 381 | { .compatible = "nxp,pca9505", .data = OF_953X(40, PCA_INT), }, |
| 382 | { .compatible = "nxp,pca9534", .data = OF_953X(8, PCA_INT), }, |
| 383 | { .compatible = "nxp,pca9535", .data = OF_953X(16, PCA_INT), }, |
| 384 | { .compatible = "nxp,pca9536", .data = OF_953X(4, 0), }, |
| 385 | { .compatible = "nxp,pca9537", .data = OF_953X(4, PCA_INT), }, |
| 386 | { .compatible = "nxp,pca9538", .data = OF_953X(8, PCA_INT), }, |
| 387 | { .compatible = "nxp,pca9539", .data = OF_953X(16, PCA_INT), }, |
| 388 | { .compatible = "nxp,pca9554", .data = OF_953X(8, PCA_INT), }, |
| 389 | { .compatible = "nxp,pca9555", .data = OF_953X(16, PCA_INT), }, |
| 390 | { .compatible = "nxp,pca9556", .data = OF_953X(8, 0), }, |
| 391 | { .compatible = "nxp,pca9557", .data = OF_953X(8, 0), }, |
| 392 | { .compatible = "nxp,pca9574", .data = OF_957X(8, PCA_INT), }, |
| 393 | { .compatible = "nxp,pca9575", .data = OF_957X(16, PCA_INT), }, |
| 394 | { .compatible = "nxp,pca9698", .data = OF_953X(40, 0), }, |
| 395 | |
| 396 | { .compatible = "maxim,max7310", .data = OF_953X(8, 0), }, |
| 397 | { .compatible = "maxim,max7312", .data = OF_953X(16, PCA_INT), }, |
| 398 | { .compatible = "maxim,max7313", .data = OF_953X(16, PCA_INT), }, |
| 399 | { .compatible = "maxim,max7315", .data = OF_953X(8, PCA_INT), }, |
| 400 | |
| 401 | { .compatible = "ti,pca6107", .data = OF_953X(8, PCA_INT), }, |
| 402 | { .compatible = "ti,tca6408", .data = OF_953X(8, PCA_INT), }, |
| 403 | { .compatible = "ti,tca6416", .data = OF_953X(16, PCA_INT), }, |
| 404 | { .compatible = "ti,tca6424", .data = OF_953X(24, PCA_INT), }, |
Marek Vasut | 4a09831 | 2019-05-25 22:52:20 +0200 | [diff] [blame] | 405 | { .compatible = "ti,tca9539", .data = OF_953X(16, PCA_INT), }, |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 406 | |
| 407 | { .compatible = "onsemi,pca9654", .data = OF_953X(8, PCA_INT), }, |
| 408 | |
| 409 | { .compatible = "exar,xra1202", .data = OF_953X(8, 0), }, |
| 410 | { } |
| 411 | }; |
| 412 | |
| 413 | U_BOOT_DRIVER(pca953x) = { |
| 414 | .name = "pca953x", |
| 415 | .id = UCLASS_GPIO, |
| 416 | .ops = &pca953x_ops, |
| 417 | .probe = pca953x_probe, |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 418 | .plat_auto = sizeof(struct pca953x_info), |
Peng Fan | 0377343 | 2016-04-14 21:45:06 +0800 | [diff] [blame] | 419 | .of_match = pca953x_ids, |
| 420 | }; |