| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * GPIO Chip driver for Analog Devices |
|---|
| 3 | 4 | * ADP5588/ADP5587 I/O Expander and QWERTY Keypad Controller |
|---|
| 4 | 5 | * |
|---|
| 5 | 6 | * Copyright 2009-2010 Analog Devices Inc. |
|---|
| 6 | | - * |
|---|
| 7 | | - * Licensed under the GPL-2 or later. |
|---|
| 8 | 7 | */ |
|---|
| 9 | 8 | |
|---|
| 10 | 9 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 15 | 14 | #include <linux/gpio/driver.h> |
|---|
| 16 | 15 | #include <linux/interrupt.h> |
|---|
| 17 | 16 | #include <linux/irq.h> |
|---|
| 17 | +#include <linux/of_device.h> |
|---|
| 18 | 18 | |
|---|
| 19 | 19 | #include <linux/platform_data/adp5588.h> |
|---|
| 20 | 20 | |
|---|
| .. | .. |
|---|
| 33 | 33 | struct mutex lock; /* protect cached dir, dat_out */ |
|---|
| 34 | 34 | /* protect serialized access to the interrupt controller bus */ |
|---|
| 35 | 35 | struct mutex irq_lock; |
|---|
| 36 | | - unsigned gpio_start; |
|---|
| 37 | | - unsigned irq_base; |
|---|
| 38 | 36 | uint8_t dat_out[3]; |
|---|
| 39 | 37 | uint8_t dir[3]; |
|---|
| 40 | | - uint8_t int_lvl[3]; |
|---|
| 38 | + uint8_t int_lvl_low[3]; |
|---|
| 39 | + uint8_t int_lvl_high[3]; |
|---|
| 41 | 40 | uint8_t int_en[3]; |
|---|
| 42 | 41 | uint8_t irq_mask[3]; |
|---|
| 43 | | - uint8_t irq_stat[3]; |
|---|
| 44 | 42 | uint8_t int_input_en[3]; |
|---|
| 45 | | - uint8_t int_lvl_cached[3]; |
|---|
| 46 | 43 | }; |
|---|
| 47 | 44 | |
|---|
| 48 | 45 | static int adp5588_gpio_read(struct i2c_client *client, u8 reg) |
|---|
| .. | .. |
|---|
| 148 | 145 | } |
|---|
| 149 | 146 | |
|---|
| 150 | 147 | #ifdef CONFIG_GPIO_ADP5588_IRQ |
|---|
| 151 | | -static int adp5588_gpio_to_irq(struct gpio_chip *chip, unsigned off) |
|---|
| 152 | | -{ |
|---|
| 153 | | - struct adp5588_gpio *dev = gpiochip_get_data(chip); |
|---|
| 154 | | - |
|---|
| 155 | | - return dev->irq_base + off; |
|---|
| 156 | | -} |
|---|
| 157 | 148 | |
|---|
| 158 | 149 | static void adp5588_irq_bus_lock(struct irq_data *d) |
|---|
| 159 | 150 | { |
|---|
| 160 | | - struct adp5588_gpio *dev = irq_data_get_irq_chip_data(d); |
|---|
| 151 | + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
|---|
| 152 | + struct adp5588_gpio *dev = gpiochip_get_data(gc); |
|---|
| 161 | 153 | |
|---|
| 162 | 154 | mutex_lock(&dev->irq_lock); |
|---|
| 163 | 155 | } |
|---|
| .. | .. |
|---|
| 172 | 164 | |
|---|
| 173 | 165 | static void adp5588_irq_bus_sync_unlock(struct irq_data *d) |
|---|
| 174 | 166 | { |
|---|
| 175 | | - struct adp5588_gpio *dev = irq_data_get_irq_chip_data(d); |
|---|
| 167 | + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
|---|
| 168 | + struct adp5588_gpio *dev = gpiochip_get_data(gc); |
|---|
| 176 | 169 | int i; |
|---|
| 177 | 170 | |
|---|
| 178 | 171 | for (i = 0; i <= ADP5588_BANK(ADP5588_MAXGPIO); i++) { |
|---|
| .. | .. |
|---|
| 185 | 178 | mutex_unlock(&dev->lock); |
|---|
| 186 | 179 | } |
|---|
| 187 | 180 | |
|---|
| 188 | | - if (dev->int_lvl_cached[i] != dev->int_lvl[i]) { |
|---|
| 189 | | - dev->int_lvl_cached[i] = dev->int_lvl[i]; |
|---|
| 190 | | - adp5588_gpio_write(dev->client, GPIO_INT_LVL1 + i, |
|---|
| 191 | | - dev->int_lvl[i]); |
|---|
| 192 | | - } |
|---|
| 193 | | - |
|---|
| 194 | 181 | if (dev->int_en[i] ^ dev->irq_mask[i]) { |
|---|
| 195 | 182 | dev->int_en[i] = dev->irq_mask[i]; |
|---|
| 196 | | - adp5588_gpio_write(dev->client, GPIO_INT_EN1 + i, |
|---|
| 183 | + adp5588_gpio_write(dev->client, GPI_EM1 + i, |
|---|
| 197 | 184 | dev->int_en[i]); |
|---|
| 198 | 185 | } |
|---|
| 199 | 186 | } |
|---|
| .. | .. |
|---|
| 203 | 190 | |
|---|
| 204 | 191 | static void adp5588_irq_mask(struct irq_data *d) |
|---|
| 205 | 192 | { |
|---|
| 206 | | - struct adp5588_gpio *dev = irq_data_get_irq_chip_data(d); |
|---|
| 207 | | - unsigned gpio = d->irq - dev->irq_base; |
|---|
| 193 | + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
|---|
| 194 | + struct adp5588_gpio *dev = gpiochip_get_data(gc); |
|---|
| 208 | 195 | |
|---|
| 209 | | - dev->irq_mask[ADP5588_BANK(gpio)] &= ~ADP5588_BIT(gpio); |
|---|
| 196 | + dev->irq_mask[ADP5588_BANK(d->hwirq)] &= ~ADP5588_BIT(d->hwirq); |
|---|
| 210 | 197 | } |
|---|
| 211 | 198 | |
|---|
| 212 | 199 | static void adp5588_irq_unmask(struct irq_data *d) |
|---|
| 213 | 200 | { |
|---|
| 214 | | - struct adp5588_gpio *dev = irq_data_get_irq_chip_data(d); |
|---|
| 215 | | - unsigned gpio = d->irq - dev->irq_base; |
|---|
| 201 | + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
|---|
| 202 | + struct adp5588_gpio *dev = gpiochip_get_data(gc); |
|---|
| 216 | 203 | |
|---|
| 217 | | - dev->irq_mask[ADP5588_BANK(gpio)] |= ADP5588_BIT(gpio); |
|---|
| 204 | + dev->irq_mask[ADP5588_BANK(d->hwirq)] |= ADP5588_BIT(d->hwirq); |
|---|
| 218 | 205 | } |
|---|
| 219 | 206 | |
|---|
| 220 | 207 | static int adp5588_irq_set_type(struct irq_data *d, unsigned int type) |
|---|
| 221 | 208 | { |
|---|
| 222 | | - struct adp5588_gpio *dev = irq_data_get_irq_chip_data(d); |
|---|
| 223 | | - uint16_t gpio = d->irq - dev->irq_base; |
|---|
| 209 | + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
|---|
| 210 | + struct adp5588_gpio *dev = gpiochip_get_data(gc); |
|---|
| 211 | + uint16_t gpio = d->hwirq; |
|---|
| 224 | 212 | unsigned bank, bit; |
|---|
| 225 | | - |
|---|
| 226 | | - if ((type & IRQ_TYPE_EDGE_BOTH)) { |
|---|
| 227 | | - dev_err(&dev->client->dev, "irq %d: unsupported type %d\n", |
|---|
| 228 | | - d->irq, type); |
|---|
| 229 | | - return -EINVAL; |
|---|
| 230 | | - } |
|---|
| 231 | 213 | |
|---|
| 232 | 214 | bank = ADP5588_BANK(gpio); |
|---|
| 233 | 215 | bit = ADP5588_BIT(gpio); |
|---|
| 234 | 216 | |
|---|
| 235 | | - if (type & IRQ_TYPE_LEVEL_HIGH) |
|---|
| 236 | | - dev->int_lvl[bank] |= bit; |
|---|
| 237 | | - else if (type & IRQ_TYPE_LEVEL_LOW) |
|---|
| 238 | | - dev->int_lvl[bank] &= ~bit; |
|---|
| 239 | | - else |
|---|
| 240 | | - return -EINVAL; |
|---|
| 217 | + dev->int_lvl_low[bank] &= ~bit; |
|---|
| 218 | + dev->int_lvl_high[bank] &= ~bit; |
|---|
| 219 | + |
|---|
| 220 | + if (type & IRQ_TYPE_EDGE_BOTH || type & IRQ_TYPE_LEVEL_HIGH) |
|---|
| 221 | + dev->int_lvl_high[bank] |= bit; |
|---|
| 222 | + |
|---|
| 223 | + if (type & IRQ_TYPE_EDGE_BOTH || type & IRQ_TYPE_LEVEL_LOW) |
|---|
| 224 | + dev->int_lvl_low[bank] |= bit; |
|---|
| 241 | 225 | |
|---|
| 242 | 226 | dev->int_input_en[bank] |= bit; |
|---|
| 243 | 227 | |
|---|
| .. | .. |
|---|
| 253 | 237 | .irq_set_type = adp5588_irq_set_type, |
|---|
| 254 | 238 | }; |
|---|
| 255 | 239 | |
|---|
| 256 | | -static int adp5588_gpio_read_intstat(struct i2c_client *client, u8 *buf) |
|---|
| 257 | | -{ |
|---|
| 258 | | - int ret = i2c_smbus_read_i2c_block_data(client, GPIO_INT_STAT1, 3, buf); |
|---|
| 259 | | - |
|---|
| 260 | | - if (ret < 0) |
|---|
| 261 | | - dev_err(&client->dev, "Read INT_STAT Error\n"); |
|---|
| 262 | | - |
|---|
| 263 | | - return ret; |
|---|
| 264 | | -} |
|---|
| 265 | | - |
|---|
| 266 | 240 | static irqreturn_t adp5588_irq_handler(int irq, void *devid) |
|---|
| 267 | 241 | { |
|---|
| 268 | 242 | struct adp5588_gpio *dev = devid; |
|---|
| 269 | | - unsigned status, bank, bit, pending; |
|---|
| 270 | | - int ret; |
|---|
| 271 | | - status = adp5588_gpio_read(dev->client, INT_STAT); |
|---|
| 243 | + int status = adp5588_gpio_read(dev->client, INT_STAT); |
|---|
| 272 | 244 | |
|---|
| 273 | | - if (status & ADP5588_GPI_INT) { |
|---|
| 274 | | - ret = adp5588_gpio_read_intstat(dev->client, dev->irq_stat); |
|---|
| 275 | | - if (ret < 0) |
|---|
| 276 | | - memset(dev->irq_stat, 0, ARRAY_SIZE(dev->irq_stat)); |
|---|
| 245 | + if (status & ADP5588_KE_INT) { |
|---|
| 246 | + int ev_cnt = adp5588_gpio_read(dev->client, KEY_LCK_EC_STAT); |
|---|
| 277 | 247 | |
|---|
| 278 | | - for (bank = 0, bit = 0; bank <= ADP5588_BANK(ADP5588_MAXGPIO); |
|---|
| 279 | | - bank++, bit = 0) { |
|---|
| 280 | | - pending = dev->irq_stat[bank] & dev->irq_mask[bank]; |
|---|
| 248 | + if (ev_cnt > 0) { |
|---|
| 249 | + int i; |
|---|
| 281 | 250 | |
|---|
| 282 | | - while (pending) { |
|---|
| 283 | | - if (pending & (1 << bit)) { |
|---|
| 284 | | - handle_nested_irq(dev->irq_base + |
|---|
| 285 | | - (bank << 3) + bit); |
|---|
| 286 | | - pending &= ~(1 << bit); |
|---|
| 251 | + for (i = 0; i < (ev_cnt & ADP5588_KEC); i++) { |
|---|
| 252 | + int key = adp5588_gpio_read(dev->client, |
|---|
| 253 | + Key_EVENTA + i); |
|---|
| 254 | + /* GPIN events begin at 97, |
|---|
| 255 | + * bit 7 indicates logic level |
|---|
| 256 | + */ |
|---|
| 257 | + int gpio = (key & 0x7f) - 97; |
|---|
| 258 | + int lvl = key & (1 << 7); |
|---|
| 259 | + int bank = ADP5588_BANK(gpio); |
|---|
| 260 | + int bit = ADP5588_BIT(gpio); |
|---|
| 287 | 261 | |
|---|
| 288 | | - } |
|---|
| 289 | | - bit++; |
|---|
| 262 | + if ((lvl && dev->int_lvl_high[bank] & bit) || |
|---|
| 263 | + (!lvl && dev->int_lvl_low[bank] & bit)) |
|---|
| 264 | + handle_nested_irq(irq_find_mapping( |
|---|
| 265 | + dev->gpio_chip.irq.domain, gpio)); |
|---|
| 290 | 266 | } |
|---|
| 291 | 267 | } |
|---|
| 292 | 268 | } |
|---|
| .. | .. |
|---|
| 296 | 272 | return IRQ_HANDLED; |
|---|
| 297 | 273 | } |
|---|
| 298 | 274 | |
|---|
| 275 | + |
|---|
| 276 | +static int adp5588_irq_init_hw(struct gpio_chip *gc) |
|---|
| 277 | +{ |
|---|
| 278 | + struct adp5588_gpio *dev = gpiochip_get_data(gc); |
|---|
| 279 | + /* Enable IRQs after registering chip */ |
|---|
| 280 | + adp5588_gpio_write(dev->client, CFG, |
|---|
| 281 | + ADP5588_AUTO_INC | ADP5588_INT_CFG | ADP5588_KE_IEN); |
|---|
| 282 | + |
|---|
| 283 | + return 0; |
|---|
| 284 | +} |
|---|
| 285 | + |
|---|
| 299 | 286 | static int adp5588_irq_setup(struct adp5588_gpio *dev) |
|---|
| 300 | 287 | { |
|---|
| 301 | 288 | struct i2c_client *client = dev->client; |
|---|
| 289 | + int ret; |
|---|
| 302 | 290 | struct adp5588_gpio_platform_data *pdata = |
|---|
| 303 | 291 | dev_get_platdata(&client->dev); |
|---|
| 304 | | - unsigned gpio; |
|---|
| 305 | | - int ret; |
|---|
| 292 | + struct gpio_irq_chip *girq; |
|---|
| 306 | 293 | |
|---|
| 307 | 294 | adp5588_gpio_write(client, CFG, ADP5588_AUTO_INC); |
|---|
| 308 | 295 | adp5588_gpio_write(client, INT_STAT, -1); /* status is W1C */ |
|---|
| 309 | | - adp5588_gpio_read_intstat(client, dev->irq_stat); /* read to clear */ |
|---|
| 310 | 296 | |
|---|
| 311 | | - dev->irq_base = pdata->irq_base; |
|---|
| 312 | 297 | mutex_init(&dev->irq_lock); |
|---|
| 313 | 298 | |
|---|
| 314 | | - for (gpio = 0; gpio < dev->gpio_chip.ngpio; gpio++) { |
|---|
| 315 | | - int irq = gpio + dev->irq_base; |
|---|
| 316 | | - irq_set_chip_data(irq, dev); |
|---|
| 317 | | - irq_set_chip_and_handler(irq, &adp5588_irq_chip, |
|---|
| 318 | | - handle_level_irq); |
|---|
| 319 | | - irq_set_nested_thread(irq, 1); |
|---|
| 320 | | - irq_modify_status(irq, IRQ_NOREQUEST, IRQ_NOPROBE); |
|---|
| 321 | | - } |
|---|
| 322 | | - |
|---|
| 323 | | - ret = request_threaded_irq(client->irq, |
|---|
| 324 | | - NULL, |
|---|
| 325 | | - adp5588_irq_handler, |
|---|
| 326 | | - IRQF_TRIGGER_FALLING | IRQF_ONESHOT, |
|---|
| 327 | | - dev_name(&client->dev), dev); |
|---|
| 299 | + ret = devm_request_threaded_irq(&client->dev, client->irq, |
|---|
| 300 | + NULL, adp5588_irq_handler, IRQF_ONESHOT |
|---|
| 301 | + | IRQF_TRIGGER_FALLING | IRQF_SHARED, |
|---|
| 302 | + dev_name(&client->dev), dev); |
|---|
| 328 | 303 | if (ret) { |
|---|
| 329 | 304 | dev_err(&client->dev, "failed to request irq %d\n", |
|---|
| 330 | 305 | client->irq); |
|---|
| 331 | | - goto out; |
|---|
| 306 | + return ret; |
|---|
| 332 | 307 | } |
|---|
| 333 | 308 | |
|---|
| 334 | | - dev->gpio_chip.to_irq = adp5588_gpio_to_irq; |
|---|
| 335 | | - adp5588_gpio_write(client, CFG, |
|---|
| 336 | | - ADP5588_AUTO_INC | ADP5588_INT_CFG | ADP5588_GPI_INT); |
|---|
| 309 | + /* This will be registered in the call to devm_gpiochip_add_data() */ |
|---|
| 310 | + girq = &dev->gpio_chip.irq; |
|---|
| 311 | + girq->chip = &adp5588_irq_chip; |
|---|
| 312 | + /* This will let us handle the parent IRQ in the driver */ |
|---|
| 313 | + girq->parent_handler = NULL; |
|---|
| 314 | + girq->num_parents = 0; |
|---|
| 315 | + girq->parents = NULL; |
|---|
| 316 | + girq->first = pdata ? pdata->irq_base : 0; |
|---|
| 317 | + girq->default_type = IRQ_TYPE_NONE; |
|---|
| 318 | + girq->handler = handle_simple_irq; |
|---|
| 319 | + girq->init_hw = adp5588_irq_init_hw; |
|---|
| 320 | + girq->threaded = true; |
|---|
| 337 | 321 | |
|---|
| 338 | 322 | return 0; |
|---|
| 339 | | - |
|---|
| 340 | | -out: |
|---|
| 341 | | - dev->irq_base = 0; |
|---|
| 342 | | - return ret; |
|---|
| 343 | | -} |
|---|
| 344 | | - |
|---|
| 345 | | -static void adp5588_irq_teardown(struct adp5588_gpio *dev) |
|---|
| 346 | | -{ |
|---|
| 347 | | - if (dev->irq_base) |
|---|
| 348 | | - free_irq(dev->client->irq, dev); |
|---|
| 349 | 323 | } |
|---|
| 350 | 324 | |
|---|
| 351 | 325 | #else |
|---|
| .. | .. |
|---|
| 357 | 331 | return 0; |
|---|
| 358 | 332 | } |
|---|
| 359 | 333 | |
|---|
| 360 | | -static void adp5588_irq_teardown(struct adp5588_gpio *dev) |
|---|
| 361 | | -{ |
|---|
| 362 | | -} |
|---|
| 363 | 334 | #endif /* CONFIG_GPIO_ADP5588_IRQ */ |
|---|
| 364 | 335 | |
|---|
| 365 | | -static int adp5588_gpio_probe(struct i2c_client *client, |
|---|
| 366 | | - const struct i2c_device_id *id) |
|---|
| 336 | +static int adp5588_gpio_probe(struct i2c_client *client) |
|---|
| 367 | 337 | { |
|---|
| 368 | 338 | struct adp5588_gpio_platform_data *pdata = |
|---|
| 369 | 339 | dev_get_platdata(&client->dev); |
|---|
| 370 | 340 | struct adp5588_gpio *dev; |
|---|
| 371 | 341 | struct gpio_chip *gc; |
|---|
| 372 | 342 | int ret, i, revid; |
|---|
| 373 | | - |
|---|
| 374 | | - if (!pdata) { |
|---|
| 375 | | - dev_err(&client->dev, "missing platform data\n"); |
|---|
| 376 | | - return -ENODEV; |
|---|
| 377 | | - } |
|---|
| 343 | + unsigned int pullup_dis_mask = 0; |
|---|
| 378 | 344 | |
|---|
| 379 | 345 | if (!i2c_check_functionality(client->adapter, |
|---|
| 380 | 346 | I2C_FUNC_SMBUS_BYTE_DATA)) { |
|---|
| .. | .. |
|---|
| 394 | 360 | gc->get = adp5588_gpio_get_value; |
|---|
| 395 | 361 | gc->set = adp5588_gpio_set_value; |
|---|
| 396 | 362 | gc->can_sleep = true; |
|---|
| 363 | + gc->base = -1; |
|---|
| 364 | + gc->parent = &client->dev; |
|---|
| 397 | 365 | |
|---|
| 398 | | - gc->base = pdata->gpio_start; |
|---|
| 366 | + if (pdata) { |
|---|
| 367 | + gc->base = pdata->gpio_start; |
|---|
| 368 | + gc->names = pdata->names; |
|---|
| 369 | + pullup_dis_mask = pdata->pullup_dis_mask; |
|---|
| 370 | + } |
|---|
| 371 | + |
|---|
| 399 | 372 | gc->ngpio = ADP5588_MAXGPIO; |
|---|
| 400 | 373 | gc->label = client->name; |
|---|
| 401 | 374 | gc->owner = THIS_MODULE; |
|---|
| 402 | | - gc->names = pdata->names; |
|---|
| 403 | 375 | |
|---|
| 404 | 376 | mutex_init(&dev->lock); |
|---|
| 405 | 377 | |
|---|
| 406 | 378 | ret = adp5588_gpio_read(dev->client, DEV_ID); |
|---|
| 407 | 379 | if (ret < 0) |
|---|
| 408 | | - goto err; |
|---|
| 380 | + return ret; |
|---|
| 409 | 381 | |
|---|
| 410 | 382 | revid = ret & ADP5588_DEVICE_ID_MASK; |
|---|
| 411 | 383 | |
|---|
| .. | .. |
|---|
| 414 | 386 | dev->dir[i] = adp5588_gpio_read(client, GPIO_DIR1 + i); |
|---|
| 415 | 387 | ret |= adp5588_gpio_write(client, KP_GPIO1 + i, 0); |
|---|
| 416 | 388 | ret |= adp5588_gpio_write(client, GPIO_PULL1 + i, |
|---|
| 417 | | - (pdata->pullup_dis_mask >> (8 * i)) & 0xFF); |
|---|
| 389 | + (pullup_dis_mask >> (8 * i)) & 0xFF); |
|---|
| 418 | 390 | ret |= adp5588_gpio_write(client, GPIO_INT_EN1 + i, 0); |
|---|
| 419 | 391 | if (ret) |
|---|
| 420 | | - goto err; |
|---|
| 392 | + return ret; |
|---|
| 421 | 393 | } |
|---|
| 422 | 394 | |
|---|
| 423 | | - if (pdata->irq_base) { |
|---|
| 395 | + if (client->irq) { |
|---|
| 424 | 396 | if (WA_DELAYED_READOUT_REVID(revid)) { |
|---|
| 425 | 397 | dev_warn(&client->dev, "GPIO int not supported\n"); |
|---|
| 426 | 398 | } else { |
|---|
| 427 | 399 | ret = adp5588_irq_setup(dev); |
|---|
| 428 | 400 | if (ret) |
|---|
| 429 | | - goto err; |
|---|
| 401 | + return ret; |
|---|
| 430 | 402 | } |
|---|
| 431 | 403 | } |
|---|
| 432 | 404 | |
|---|
| 433 | 405 | ret = devm_gpiochip_add_data(&client->dev, &dev->gpio_chip, dev); |
|---|
| 434 | 406 | if (ret) |
|---|
| 435 | | - goto err_irq; |
|---|
| 407 | + return ret; |
|---|
| 436 | 408 | |
|---|
| 437 | | - dev_info(&client->dev, "IRQ Base: %d Rev.: %d\n", |
|---|
| 438 | | - pdata->irq_base, revid); |
|---|
| 439 | | - |
|---|
| 440 | | - if (pdata->setup) { |
|---|
| 409 | + if (pdata && pdata->setup) { |
|---|
| 441 | 410 | ret = pdata->setup(client, gc->base, gc->ngpio, pdata->context); |
|---|
| 442 | 411 | if (ret < 0) |
|---|
| 443 | 412 | dev_warn(&client->dev, "setup failed, %d\n", ret); |
|---|
| .. | .. |
|---|
| 446 | 415 | i2c_set_clientdata(client, dev); |
|---|
| 447 | 416 | |
|---|
| 448 | 417 | return 0; |
|---|
| 449 | | - |
|---|
| 450 | | -err_irq: |
|---|
| 451 | | - adp5588_irq_teardown(dev); |
|---|
| 452 | | -err: |
|---|
| 453 | | - return ret; |
|---|
| 454 | 418 | } |
|---|
| 455 | 419 | |
|---|
| 456 | 420 | static int adp5588_gpio_remove(struct i2c_client *client) |
|---|
| .. | .. |
|---|
| 460 | 424 | struct adp5588_gpio *dev = i2c_get_clientdata(client); |
|---|
| 461 | 425 | int ret; |
|---|
| 462 | 426 | |
|---|
| 463 | | - if (pdata->teardown) { |
|---|
| 427 | + if (pdata && pdata->teardown) { |
|---|
| 464 | 428 | ret = pdata->teardown(client, |
|---|
| 465 | 429 | dev->gpio_chip.base, dev->gpio_chip.ngpio, |
|---|
| 466 | 430 | pdata->context); |
|---|
| .. | .. |
|---|
| 470 | 434 | } |
|---|
| 471 | 435 | } |
|---|
| 472 | 436 | |
|---|
| 473 | | - if (dev->irq_base) |
|---|
| 437 | + if (dev->client->irq) |
|---|
| 474 | 438 | free_irq(dev->client->irq, dev); |
|---|
| 475 | 439 | |
|---|
| 476 | 440 | return 0; |
|---|
| .. | .. |
|---|
| 480 | 444 | {DRV_NAME, 0}, |
|---|
| 481 | 445 | {} |
|---|
| 482 | 446 | }; |
|---|
| 483 | | - |
|---|
| 484 | 447 | MODULE_DEVICE_TABLE(i2c, adp5588_gpio_id); |
|---|
| 448 | + |
|---|
| 449 | +#ifdef CONFIG_OF |
|---|
| 450 | +static const struct of_device_id adp5588_gpio_of_id[] = { |
|---|
| 451 | + { .compatible = "adi," DRV_NAME, }, |
|---|
| 452 | + {}, |
|---|
| 453 | +}; |
|---|
| 454 | +MODULE_DEVICE_TABLE(of, adp5588_gpio_of_id); |
|---|
| 455 | +#endif |
|---|
| 485 | 456 | |
|---|
| 486 | 457 | static struct i2c_driver adp5588_gpio_driver = { |
|---|
| 487 | 458 | .driver = { |
|---|
| 488 | | - .name = DRV_NAME, |
|---|
| 489 | | - }, |
|---|
| 490 | | - .probe = adp5588_gpio_probe, |
|---|
| 459 | + .name = DRV_NAME, |
|---|
| 460 | + .of_match_table = of_match_ptr(adp5588_gpio_of_id), |
|---|
| 461 | + }, |
|---|
| 462 | + .probe_new = adp5588_gpio_probe, |
|---|
| 491 | 463 | .remove = adp5588_gpio_remove, |
|---|
| 492 | 464 | .id_table = adp5588_gpio_id, |
|---|
| 493 | 465 | }; |
|---|
| 494 | 466 | |
|---|
| 495 | 467 | module_i2c_driver(adp5588_gpio_driver); |
|---|
| 496 | 468 | |
|---|
| 497 | | -MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); |
|---|
| 469 | +MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>"); |
|---|
| 498 | 470 | MODULE_DESCRIPTION("GPIO ADP5588 Driver"); |
|---|
| 499 | 471 | MODULE_LICENSE("GPL"); |
|---|