static int adp5520_keys_probe(struct platform_device *pdev) { struct adp5520_keys_platform_data *pdata = dev_get_platdata(&pdev->dev); struct input_dev *input; struct adp5520_keys *dev; int ret, i; unsigned char en_mask, ctl_mask = 0; if (pdev->id != ID_ADP5520) { dev_err(&pdev->dev, "only ADP5520 supports Keypad\n"); return -EINVAL; } if (!pdata) { dev_err(&pdev->dev, "missing platform data\n"); return -EINVAL; } if (!(pdata->rows_en_mask && pdata->cols_en_mask)) return -EINVAL; dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); if (!dev) { dev_err(&pdev->dev, "failed to alloc memory\n"); return -ENOMEM; } input = devm_input_allocate_device(&pdev->dev); if (!input) return -ENOMEM; dev->master = pdev->dev.parent; dev->input = input; input->name = pdev->name; input->phys = "adp5520-keys/input0"; input->dev.parent = &pdev->dev; input_set_drvdata(input, dev); input->id.bustype = BUS_I2C; input->id.vendor = 0x0001; input->id.product = 0x5520; input->id.version = 0x0001; input->keycodesize = sizeof(dev->keycode[0]); input->keycodemax = pdata->keymapsize; input->keycode = dev->keycode; memcpy(dev->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(dev->keycode[i], input->keybit); __clear_bit(KEY_RESERVED, input->keybit); ret = input_register_device(input); if (ret) { dev_err(&pdev->dev, "unable to register input device\n"); return ret; } en_mask = pdata->rows_en_mask | pdata->cols_en_mask; ret = adp5520_set_bits(dev->master, ADP5520_GPIO_CFG_1, en_mask); if (en_mask & ADP5520_COL_C3) ctl_mask |= ADP5520_C3_MODE; if (en_mask & ADP5520_ROW_R3) ctl_mask |= ADP5520_R3_MODE; if (ctl_mask) ret |= adp5520_set_bits(dev->master, ADP5520_LED_CONTROL, ctl_mask); ret |= adp5520_set_bits(dev->master, ADP5520_GPIO_PULLUP, pdata->rows_en_mask); if (ret) { dev_err(&pdev->dev, "failed to write\n"); return -EIO; } dev->notifier.notifier_call = adp5520_keys_notifier; ret = adp5520_register_notifier(dev->master, &dev->notifier, ADP5520_KP_IEN | ADP5520_KR_IEN); if (ret) { dev_err(&pdev->dev, "failed to register notifier\n"); return ret; } platform_set_drvdata(pdev, dev); return 0; }
static int __devinit adp5520_keys_probe(struct platform_device *pdev) { struct adp5520_keys_platfrom_data *pdata = pdev->dev.platform_data; struct input_dev *input; struct adp5520_keys *dev; int ret, i; unsigned char en_mask, ctl_mask = 0; if (pdev->id != ID_ADP5520) { dev_err(&pdev->dev, "only ADP5520 supports Keypad\n"); return -EFAULT; } if (pdata == NULL) { dev_err(&pdev->dev, "missing platform data\n"); return -ENODEV; } if (!(pdata->rows_en_mask && pdata->cols_en_mask)) return -ENODEV; dev = kzalloc(sizeof(*dev), GFP_KERNEL); if (dev == NULL) { dev_err(&pdev->dev, "failed to alloc memory\n"); return -ENOMEM; } input = input_allocate_device(); if (!input) { ret = -ENOMEM; goto err; } dev->master = pdev->dev.parent; dev->input = input; input->name = pdev->name; input->phys = "adp5520-keys/input0"; input->dev.parent = &pdev->dev; input_set_drvdata(input, dev); input->id.bustype = BUS_I2C; input->id.vendor = 0x0001; input->id.product = 0x5520; input->id.version = 0x0001; input->keycodesize = sizeof(unsigned short); input->keycodemax = pdata->keymapsize; input->keycode = dev->keycode; memcpy(dev->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(dev->keycode[i] & KEY_MAX, input->keybit); __clear_bit(KEY_RESERVED, input->keybit); ret = input_register_device(input); if (ret) { dev_err(&pdev->dev, ": Unable to register input device (%d)\n", ret); input_free_device(input); goto err; } en_mask = pdata->rows_en_mask | pdata->cols_en_mask; ret = adp5520_set_bits(dev->master, GPIO_CFG_1, en_mask); if (en_mask & COL_C3) ctl_mask |= C3_MODE; if (en_mask & ROW_R3) ctl_mask |= R3_MODE; if (ctl_mask) ret |= adp5520_set_bits(dev->master, LED_CONTROL, ctl_mask); ret |= adp5520_set_bits(dev->master, GPIO_PULLUP, pdata->rows_en_mask); if (ret) { dev_err(&pdev->dev, "failed to write\n"); goto err1; } dev->notifier.notifier_call = adp5520_keys_notifier; ret = adp5520_register_notifier(dev->master, &dev->notifier, KP_IEN | KR_IEN); if (ret) { dev_err(&pdev->dev, "failed to register notifier\n"); goto err1; } platform_set_drvdata(pdev, dev); return 0; err1: input_unregister_device(input); err: kfree(dev); return ret; }