tca6416-keypad.c (b74b953b998bcc2db91b694446f3a2619ec32de6) | tca6416-keypad.c (b8a3d6bcbc85d7636d9f2adede8479ce2999c232) |
---|---|
1/* 2 * Driver for keys on TCA6416 I2C IO expander 3 * 4 * Copyright (C) 2010 Texas Instruments 5 * 6 * Author : Sriramakrishnan.A.G. <srk@ti.com> 7 * 8 * This program is free software; you can redistribute it and/or modify --- 15 unchanged lines hidden (view full) --- 24 25#define TCA6416_INPUT 0 26#define TCA6416_OUTPUT 1 27#define TCA6416_INVERT 2 28#define TCA6416_DIRECTION 3 29 30static const struct i2c_device_id tca6416_id[] = { 31 { "tca6416-keys", 16, }, | 1/* 2 * Driver for keys on TCA6416 I2C IO expander 3 * 4 * Copyright (C) 2010 Texas Instruments 5 * 6 * Author : Sriramakrishnan.A.G. <srk@ti.com> 7 * 8 * This program is free software; you can redistribute it and/or modify --- 15 unchanged lines hidden (view full) --- 24 25#define TCA6416_INPUT 0 26#define TCA6416_OUTPUT 1 27#define TCA6416_INVERT 2 28#define TCA6416_DIRECTION 3 29 30static const struct i2c_device_id tca6416_id[] = { 31 { "tca6416-keys", 16, }, |
32 { "tca6408-keys", 8, }, |
|
32 { } 33}; 34MODULE_DEVICE_TABLE(i2c, tca6416_id); 35 36struct tca6416_drv_data { 37 struct input_dev *input; 38 struct tca6416_button data[0]; 39}; 40 41struct tca6416_keypad_chip { 42 uint16_t reg_output; 43 uint16_t reg_direction; 44 uint16_t reg_input; 45 46 struct i2c_client *client; 47 struct input_dev *input; 48 struct delayed_work dwork; | 33 { } 34}; 35MODULE_DEVICE_TABLE(i2c, tca6416_id); 36 37struct tca6416_drv_data { 38 struct input_dev *input; 39 struct tca6416_button data[0]; 40}; 41 42struct tca6416_keypad_chip { 43 uint16_t reg_output; 44 uint16_t reg_direction; 45 uint16_t reg_input; 46 47 struct i2c_client *client; 48 struct input_dev *input; 49 struct delayed_work dwork; |
49 u16 pinmask; | 50 int io_size; |
50 int irqnum; | 51 int irqnum; |
52 u16 pinmask; |
|
51 bool use_polling; 52 struct tca6416_button buttons[0]; 53}; 54 55static int tca6416_write_reg(struct tca6416_keypad_chip *chip, int reg, u16 val) 56{ 57 int error; 58 | 53 bool use_polling; 54 struct tca6416_button buttons[0]; 55}; 56 57static int tca6416_write_reg(struct tca6416_keypad_chip *chip, int reg, u16 val) 58{ 59 int error; 60 |
59 error = i2c_smbus_write_word_data(chip->client, reg << 1, val); | 61 error = chip->io_size > 8 ? 62 i2c_smbus_write_word_data(chip->client, reg << 1, val) : 63 i2c_smbus_write_byte_data(chip->client, reg, val); |
60 if (error < 0) { 61 dev_err(&chip->client->dev, 62 "%s failed, reg: %d, val: %d, error: %d\n", 63 __func__, reg, val, error); 64 return error; 65 } 66 67 return 0; 68} 69 70static int tca6416_read_reg(struct tca6416_keypad_chip *chip, int reg, u16 *val) 71{ 72 int retval; 73 | 64 if (error < 0) { 65 dev_err(&chip->client->dev, 66 "%s failed, reg: %d, val: %d, error: %d\n", 67 __func__, reg, val, error); 68 return error; 69 } 70 71 return 0; 72} 73 74static int tca6416_read_reg(struct tca6416_keypad_chip *chip, int reg, u16 *val) 75{ 76 int retval; 77 |
74 retval = i2c_smbus_read_word_data(chip->client, reg << 1); | 78 retval = chip->io_size > 8 ? 79 i2c_smbus_read_word_data(chip->client, reg << 1) : 80 i2c_smbus_read_byte_data(chip->client, reg); |
75 if (retval < 0) { 76 dev_err(&chip->client->dev, "%s failed, reg: %d, error: %d\n", 77 __func__, reg, retval); 78 return retval; 79 } 80 81 *val = (u16)retval; 82 return 0; --- 136 unchanged lines hidden (view full) --- 219 input = input_allocate_device(); 220 if (!chip || !input) { 221 error = -ENOMEM; 222 goto fail1; 223 } 224 225 chip->client = client; 226 chip->input = input; | 81 if (retval < 0) { 82 dev_err(&chip->client->dev, "%s failed, reg: %d, error: %d\n", 83 __func__, reg, retval); 84 return retval; 85 } 86 87 *val = (u16)retval; 88 return 0; --- 136 unchanged lines hidden (view full) --- 225 input = input_allocate_device(); 226 if (!chip || !input) { 227 error = -ENOMEM; 228 goto fail1; 229 } 230 231 chip->client = client; 232 chip->input = input; |
233 chip->io_size = id->driver_data; |
|
227 chip->pinmask = pdata->pinmask; 228 chip->use_polling = pdata->use_polling; 229 230 INIT_DELAYED_WORK(&chip->dwork, tca6416_keys_work_func); 231 232 input->phys = "tca6416-keys/input0"; 233 input->name = client->name; 234 input->dev.parent = &client->dev; --- 113 unchanged lines hidden --- | 234 chip->pinmask = pdata->pinmask; 235 chip->use_polling = pdata->use_polling; 236 237 INIT_DELAYED_WORK(&chip->dwork, tca6416_keys_work_func); 238 239 input->phys = "tca6416-keys/input0"; 240 input->name = client->name; 241 input->dev.parent = &client->dev; --- 113 unchanged lines hidden --- |