static int adp5588_resume(struct i2c_client *client) { enable_irq(client->irq); return adp5588_setup(client); }
static int adp5588_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct adp5588_kpad *kpad; const struct adp5588_kpad_platform_data *pdata = dev_get_platdata(&client->dev); struct input_dev *input; unsigned int revid; int ret, i; int error; if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { dev_err(&client->dev, "SMBUS Byte Data not Supported\n"); return -EIO; } if (!pdata) { dev_err(&client->dev, "no platform data?\n"); return -EINVAL; } if (!pdata->rows || !pdata->cols || !pdata->keymap) { dev_err(&client->dev, "no rows, cols or keymap from pdata\n"); return -EINVAL; } if (pdata->keymapsize != ADP5588_KEYMAPSIZE) { dev_err(&client->dev, "invalid keymapsize\n"); return -EINVAL; } if (!pdata->gpimap && pdata->gpimapsize) { dev_err(&client->dev, "invalid gpimap from pdata\n"); return -EINVAL; } if (pdata->gpimapsize > ADP5588_GPIMAPSIZE_MAX) { dev_err(&client->dev, "invalid gpimapsize\n"); return -EINVAL; } for (i = 0; i < pdata->gpimapsize; i++) { unsigned short pin = pdata->gpimap[i].pin; if (pin < GPI_PIN_BASE || pin > GPI_PIN_END) { dev_err(&client->dev, "invalid gpi pin data\n"); return -EINVAL; } if (pin <= GPI_PIN_ROW_END) { if (pin - GPI_PIN_ROW_BASE + 1 <= pdata->rows) { dev_err(&client->dev, "invalid gpi row data\n"); return -EINVAL; } } else { if (pin - GPI_PIN_COL_BASE + 1 <= pdata->cols) { dev_err(&client->dev, "invalid gpi col data\n"); return -EINVAL; } } } if (!client->irq) { dev_err(&client->dev, "no IRQ?\n"); return -EINVAL; } kpad = kzalloc(sizeof(*kpad), GFP_KERNEL); input = input_allocate_device(); if (!kpad || !input) { error = -ENOMEM; goto err_free_mem; } kpad->client = client; kpad->input = input; INIT_DELAYED_WORK(&kpad->work, adp5588_work); ret = adp5588_read(client, DEV_ID); if (ret < 0) { error = ret; goto err_free_mem; } revid = (u8) ret & ADP5588_DEVICE_ID_MASK; if (WA_DELAYED_READOUT_REVID(revid)) kpad->delay = msecs_to_jiffies(30); input->name = client->name; input->phys = "adp5588-keys/input0"; input->dev.parent = &client->dev; input_set_drvdata(input, kpad); input->id.bustype = BUS_I2C; input->id.vendor = 0x0001; input->id.product = 0x0001; input->id.version = revid; input->keycodesize = sizeof(kpad->keycode[0]); input->keycodemax = pdata->keymapsize; input->keycode = kpad->keycode; memcpy(kpad->keycode, pdata->keymap, pdata->keymapsize * input->keycodesize); kpad->gpimap = pdata->gpimap; kpad->gpimapsize = pdata->gpimapsize; /* setup input device */ __set_bit(EV_KEY, input->evbit); if (pdata->repeat) __set_bit(EV_REP, input->evbit); for (i = 0; i < input->keycodemax; i++) if (kpad->keycode[i] <= KEY_MAX) __set_bit(kpad->keycode[i], input->keybit); __clear_bit(KEY_RESERVED, input->keybit); if (kpad->gpimapsize) __set_bit(EV_SW, input->evbit); for (i = 0; i < kpad->gpimapsize; i++) __set_bit(kpad->gpimap[i].sw_evt, input->swbit); error = input_register_device(input); if (error) { dev_err(&client->dev, "unable to register input device\n"); goto err_free_mem; } error = request_irq(client->irq, adp5588_irq, IRQF_TRIGGER_FALLING, client->dev.driver->name, kpad); if (error) { dev_err(&client->dev, "irq %d busy?\n", client->irq); goto err_unreg_dev; } error = adp5588_setup(client); if (error) goto err_free_irq; if (kpad->gpimapsize) adp5588_report_switch_state(kpad); error = adp5588_gpio_add(kpad); if (error) goto err_free_irq; device_init_wakeup(&client->dev, 1); i2c_set_clientdata(client, kpad); dev_info(&client->dev, "Rev.%d keypad, irq %d\n", revid, client->irq); return 0; err_free_irq: free_irq(client->irq, kpad); cancel_delayed_work_sync(&kpad->work); err_unreg_dev: input_unregister_device(input); input = NULL; err_free_mem: input_free_device(input); kfree(kpad); return error; }
static int __devinit adp5588_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct adp5588_kpad *kpad; struct adp5588_kpad_platform_data *pdata = client->dev.platform_data; struct input_dev *input; int ret, i; u8 revid; if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { dev_err(&client->dev, "SMBUS Byte Data not Supported\n"); return -EIO; } if (!pdata) { dev_err(&client->dev, "no platform data?\n"); return -ENODEV; } if (!pdata->rows || !pdata->cols || !pdata->keymap) { dev_err(&client->dev, ": No rows, cols or keymap from pdata\n"); return -EINVAL; } if (pdata->keymapsize != ADP5588_KEYMAPSIZE) { dev_err(&client->dev, ": Invalid keymapsize\n"); return -EINVAL; } if (!client->irq) { dev_err(&client->dev, "no IRQ?\n"); return -ENODEV; } kpad = kzalloc(sizeof(struct adp5588_kpad), GFP_KERNEL); if (!kpad) return -ENOMEM; input = input_allocate_device(); if (!input) { kfree(kpad); return -ENOMEM; } i2c_set_clientdata(client, kpad); kpad->client = client; ret = adp5588_read(client, DEV_ID); if (ret < 0) { input_free_device(input); goto out1; } revid = (u8) ret; INIT_DELAYED_WORK(&kpad->work, adp5588_work); kpad->input = input; input->name = client->name; input->phys = "adp5588-keys/inputX"; input->dev.parent = &client->dev; input_set_drvdata(input, kpad); input->id.bustype = BUS_I2C; input->id.vendor = 0x0001; input->id.product = 0x0001; input->id.version = revid; input->keycodesize = sizeof(unsigned short); input->keycodemax = pdata->keymapsize; input->keycode = kpad->keycode; memcpy(kpad->keycode, pdata->keymap, pdata->keymapsize * input->keycodesize); /* setup input device */ __set_bit(EV_KEY, input->evbit); if (pdata->repeat) __set_bit(EV_REP, input->evbit); for (i = 0; i < input->keycodemax; i++) __set_bit(kpad->keycode[i] & KEY_MAX, input->keybit); __clear_bit(KEY_RESERVED, input->keybit); ret = input_register_device(input); if (ret) { dev_err(&client->dev, ": Unable to register input device (%d)\n", ret); input_free_device(input); goto out1; } ret = request_irq(client->irq, adp5588_irq, IRQF_TRIGGER_FALLING | IRQF_DISABLED, client->dev.driver->name, kpad); if (ret) { dev_err(&client->dev, "irq %d busy?\n", client->irq); goto out2; } ret = adp5588_setup(client); if (ret) goto out3; dev_info(&client->dev, "Rev.%d keypad, irq %d\n", revid, client->irq); return ret; out3: free_irq(client->irq, kpad); out2: input_unregister_device(input); out1: i2c_set_clientdata(client, NULL); kfree(kpad); return ret; }