adp5589-keys.c 29.6 KB
Newer Older
1
/*
2
 * Description:  keypad driver for ADP5589, ADP5585
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *		 I2C QWERTY Keypad and IO Expander
 * Bugs: Enter bugs at http://blackfin.uclinux.org/
 *
 * Copyright (C) 2010-2011 Analog Devices Inc.
 * Licensed under the GPL-2.
 */

#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/workqueue.h>
#include <linux/errno.h>
#include <linux/pm.h>
#include <linux/platform_device.h>
#include <linux/input.h>
#include <linux/i2c.h>
#include <linux/gpio.h>
#include <linux/slab.h>

#include <linux/input/adp5589.h>

24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
/* ADP5589/ADP5585 Common Registers */
#define ADP5589_5_ID			0x00
#define ADP5589_5_INT_STATUS		0x01
#define ADP5589_5_STATUS		0x02
#define ADP5589_5_FIFO_1		0x03
#define ADP5589_5_FIFO_2		0x04
#define ADP5589_5_FIFO_3		0x05
#define ADP5589_5_FIFO_4		0x06
#define ADP5589_5_FIFO_5		0x07
#define ADP5589_5_FIFO_6		0x08
#define ADP5589_5_FIFO_7		0x09
#define ADP5589_5_FIFO_8		0x0A
#define ADP5589_5_FIFO_9		0x0B
#define ADP5589_5_FIFO_10		0x0C
#define ADP5589_5_FIFO_11		0x0D
#define ADP5589_5_FIFO_12		0x0E
#define ADP5589_5_FIFO_13		0x0F
#define ADP5589_5_FIFO_14		0x10
#define ADP5589_5_FIFO_15		0x11
#define ADP5589_5_FIFO_16		0x12
#define ADP5589_5_GPI_INT_STAT_A	0x13
#define ADP5589_5_GPI_INT_STAT_B	0x14

/* ADP5589 Registers */
#define ADP5589_GPI_INT_STAT_C		0x15
#define ADP5589_GPI_STATUS_A		0x16
#define ADP5589_GPI_STATUS_B		0x17
#define ADP5589_GPI_STATUS_C		0x18
#define ADP5589_RPULL_CONFIG_A		0x19
#define ADP5589_RPULL_CONFIG_B		0x1A
#define ADP5589_RPULL_CONFIG_C		0x1B
#define ADP5589_RPULL_CONFIG_D		0x1C
#define ADP5589_RPULL_CONFIG_E		0x1D
#define ADP5589_GPI_INT_LEVEL_A		0x1E
#define ADP5589_GPI_INT_LEVEL_B		0x1F
#define ADP5589_GPI_INT_LEVEL_C		0x20
#define ADP5589_GPI_EVENT_EN_A		0x21
#define ADP5589_GPI_EVENT_EN_B		0x22
#define ADP5589_GPI_EVENT_EN_C		0x23
#define ADP5589_GPI_INTERRUPT_EN_A	0x24
#define ADP5589_GPI_INTERRUPT_EN_B	0x25
#define ADP5589_GPI_INTERRUPT_EN_C	0x26
#define ADP5589_DEBOUNCE_DIS_A		0x27
#define ADP5589_DEBOUNCE_DIS_B		0x28
#define ADP5589_DEBOUNCE_DIS_C		0x29
#define ADP5589_GPO_DATA_OUT_A		0x2A
#define ADP5589_GPO_DATA_OUT_B		0x2B
#define ADP5589_GPO_DATA_OUT_C		0x2C
#define ADP5589_GPO_OUT_MODE_A		0x2D
#define ADP5589_GPO_OUT_MODE_B		0x2E
#define ADP5589_GPO_OUT_MODE_C		0x2F
#define ADP5589_GPIO_DIRECTION_A	0x30
#define ADP5589_GPIO_DIRECTION_B	0x31
#define ADP5589_GPIO_DIRECTION_C	0x32
#define ADP5589_UNLOCK1			0x33
#define ADP5589_UNLOCK2			0x34
#define ADP5589_EXT_LOCK_EVENT		0x35
#define ADP5589_UNLOCK_TIMERS		0x36
#define ADP5589_LOCK_CFG		0x37
#define ADP5589_RESET1_EVENT_A		0x38
#define ADP5589_RESET1_EVENT_B		0x39
#define ADP5589_RESET1_EVENT_C		0x3A
#define ADP5589_RESET2_EVENT_A		0x3B
#define ADP5589_RESET2_EVENT_B		0x3C
#define ADP5589_RESET_CFG		0x3D
#define ADP5589_PWM_OFFT_LOW		0x3E
#define ADP5589_PWM_OFFT_HIGH		0x3F
#define ADP5589_PWM_ONT_LOW		0x40
#define ADP5589_PWM_ONT_HIGH		0x41
#define ADP5589_PWM_CFG			0x42
#define ADP5589_CLOCK_DIV_CFG		0x43
#define ADP5589_LOGIC_1_CFG		0x44
#define ADP5589_LOGIC_2_CFG		0x45
#define ADP5589_LOGIC_FF_CFG		0x46
#define ADP5589_LOGIC_INT_EVENT_EN	0x47
#define ADP5589_POLL_PTIME_CFG		0x48
#define ADP5589_PIN_CONFIG_A		0x49
#define ADP5589_PIN_CONFIG_B		0x4A
#define ADP5589_PIN_CONFIG_C		0x4B
#define ADP5589_PIN_CONFIG_D		0x4C
#define ADP5589_GENERAL_CFG		0x4D
#define ADP5589_INT_EN			0x4E

/* ADP5585 Registers */
#define ADP5585_GPI_STATUS_A		0x15
#define ADP5585_GPI_STATUS_B		0x16
#define ADP5585_RPULL_CONFIG_A		0x17
#define ADP5585_RPULL_CONFIG_B		0x18
#define ADP5585_RPULL_CONFIG_C		0x19
#define ADP5585_RPULL_CONFIG_D		0x1A
#define ADP5585_GPI_INT_LEVEL_A		0x1B
#define ADP5585_GPI_INT_LEVEL_B		0x1C
#define ADP5585_GPI_EVENT_EN_A		0x1D
#define ADP5585_GPI_EVENT_EN_B		0x1E
#define ADP5585_GPI_INTERRUPT_EN_A	0x1F
#define ADP5585_GPI_INTERRUPT_EN_B	0x20
#define ADP5585_DEBOUNCE_DIS_A		0x21
#define ADP5585_DEBOUNCE_DIS_B		0x22
#define ADP5585_GPO_DATA_OUT_A		0x23
#define ADP5585_GPO_DATA_OUT_B		0x24
#define ADP5585_GPO_OUT_MODE_A		0x25
#define ADP5585_GPO_OUT_MODE_B		0x26
#define ADP5585_GPIO_DIRECTION_A	0x27
#define ADP5585_GPIO_DIRECTION_B	0x28
#define ADP5585_RESET1_EVENT_A		0x29
#define ADP5585_RESET1_EVENT_B		0x2A
#define ADP5585_RESET1_EVENT_C		0x2B
#define ADP5585_RESET2_EVENT_A		0x2C
#define ADP5585_RESET2_EVENT_B		0x2D
#define ADP5585_RESET_CFG		0x2E
#define ADP5585_PWM_OFFT_LOW		0x2F
#define ADP5585_PWM_OFFT_HIGH		0x30
#define ADP5585_PWM_ONT_LOW		0x31
#define ADP5585_PWM_ONT_HIGH		0x32
#define ADP5585_PWM_CFG			0x33
#define ADP5585_LOGIC_CFG		0x34
#define ADP5585_LOGIC_FF_CFG		0x35
#define ADP5585_LOGIC_INT_EVENT_EN	0x36
#define ADP5585_POLL_PTIME_CFG		0x37
#define ADP5585_PIN_CONFIG_A		0x38
#define ADP5585_PIN_CONFIG_B		0x39
#define ADP5585_PIN_CONFIG_D		0x3A
#define ADP5585_GENERAL_CFG		0x3B
#define ADP5585_INT_EN			0x3C

/* ID Register */
#define ADP5589_5_DEVICE_ID_MASK	0xF
#define ADP5589_5_MAN_ID_MASK		0xF
#define ADP5589_5_MAN_ID_SHIFT		4
#define ADP5589_5_MAN_ID		0x02

155 156 157
/* GENERAL_CFG Register */
#define OSC_EN		(1 << 7)
#define CORE_CLK(x)	(((x) & 0x3) << 5)
158 159
#define LCK_TRK_LOGIC	(1 << 4)	/* ADP5589 only */
#define LCK_TRK_GPI	(1 << 3)	/* ADP5589 only */
160 161 162 163
#define INT_CFG		(1 << 1)
#define RST_CFG		(1 << 0)

/* INT_EN Register */
164
#define LOGIC2_IEN	(1 << 5)	/* ADP5589 only */
165
#define LOGIC1_IEN	(1 << 4)
166
#define LOCK_IEN	(1 << 3)	/* ADP5589 only */
167 168 169 170 171
#define OVRFLOW_IEN	(1 << 2)
#define GPI_IEN		(1 << 1)
#define EVENT_IEN	(1 << 0)

/* Interrupt Status Register */
172
#define LOGIC2_INT	(1 << 5)	/* ADP5589 only */
173
#define LOGIC1_INT	(1 << 4)
174
#define LOCK_INT	(1 << 3)	/* ADP5589 only */
175 176 177 178 179
#define OVRFLOW_INT	(1 << 2)
#define GPI_INT		(1 << 1)
#define EVENT_INT	(1 << 0)

/* STATUS Register */
180
#define LOGIC2_STAT	(1 << 7)	/* ADP5589 only */
181
#define LOGIC1_STAT	(1 << 6)
182
#define LOCK_STAT	(1 << 5)	/* ADP5589 only */
183 184 185 186 187 188 189 190 191 192
#define KEC		0xF

/* PIN_CONFIG_D Register */
#define C4_EXTEND_CFG	(1 << 6)	/* RESET2 */
#define R4_EXTEND_CFG	(1 << 5)	/* RESET1 */

/* LOCK_CFG */
#define LOCK_EN		(1 << 0)

#define PTIME_MASK	0x3
193
#define LTIME_MASK	0x3		/* ADP5589 only */
194 195 196 197 198 199

/* Key Event Register xy */
#define KEY_EV_PRESSED		(1 << 7)
#define KEY_EV_MASK		(0x7F)

#define KEYP_MAX_EVENT		16
200 201
#define ADP5589_MAXGPIO		19
#define ADP5585_MAXGPIO		11 /* 10 on the ADP5585-01, 11 on ADP5585-02 */
202

203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
enum {
	ADP5589,
	ADP5585_01,
	ADP5585_02
};

struct adp_constants {
	u8 maxgpio;
	u8 keymapsize;
	u8 gpi_pin_row_base;
	u8 gpi_pin_row_end;
	u8 gpi_pin_col_base;
	u8 gpi_pin_base;
	u8 gpi_pin_end;
	u8 gpimapsize_max;
	u8 max_row_num;
	u8 max_col_num;
	u8 row_mask;
	u8 col_mask;
	u8 col_shift;
	u8 c4_extend_cfg;
	u8 (*bank) (u8 offset);
	u8 (*bit) (u8 offset);
	u8 (*reg) (u8 reg);
};
228 229 230 231

struct adp5589_kpad {
	struct i2c_client *client;
	struct input_dev *input;
232
	const struct adp_constants *var;
233 234 235 236
	unsigned short keycode[ADP5589_KEYMAPSIZE];
	const struct adp5589_gpi_map *gpimap;
	unsigned short gpimapsize;
	unsigned extend_cfg;
237 238
	bool is_adp5585;
	bool adp5585_support_row5;
239
#ifdef CONFIG_GPIOLIB
240
	unsigned char gpiomap[ADP5589_MAXGPIO];
241 242 243 244 245 246 247 248
	bool export_gpio;
	struct gpio_chip gc;
	struct mutex gpio_lock;	/* Protect cached dir, dat_out */
	u8 dat_out[3];
	u8 dir[3];
#endif
};

249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
/*
 *  ADP5589 / ADP5585 derivative / variant handling
 */


/* ADP5589 */

static unsigned char adp5589_bank(unsigned char offset)
{
	return offset >> 3;
}

static unsigned char adp5589_bit(unsigned char offset)
{
	return 1u << (offset & 0x7);
}

static unsigned char adp5589_reg(unsigned char reg)
{
	return reg;
}

static const struct adp_constants const_adp5589 = {
	.maxgpio		= ADP5589_MAXGPIO,
	.keymapsize		= ADP5589_KEYMAPSIZE,
	.gpi_pin_row_base	= ADP5589_GPI_PIN_ROW_BASE,
	.gpi_pin_row_end	= ADP5589_GPI_PIN_ROW_END,
	.gpi_pin_col_base	= ADP5589_GPI_PIN_COL_BASE,
	.gpi_pin_base		= ADP5589_GPI_PIN_BASE,
	.gpi_pin_end		= ADP5589_GPI_PIN_END,
	.gpimapsize_max		= ADP5589_GPIMAPSIZE_MAX,
	.c4_extend_cfg		= 12,
	.max_row_num		= ADP5589_MAX_ROW_NUM,
	.max_col_num		= ADP5589_MAX_COL_NUM,
	.row_mask		= ADP5589_ROW_MASK,
	.col_mask		= ADP5589_COL_MASK,
	.col_shift		= ADP5589_COL_SHIFT,
	.bank			= adp5589_bank,
	.bit			= adp5589_bit,
	.reg			= adp5589_reg,
};

/* ADP5585 */

static unsigned char adp5585_bank(unsigned char offset)
{
	return offset > ADP5585_MAX_ROW_NUM;
}

static unsigned char adp5585_bit(unsigned char offset)
{
	return (offset > ADP5585_MAX_ROW_NUM) ?
		1u << (offset - ADP5585_COL_SHIFT) : 1u << offset;
}

static const unsigned char adp5585_reg_lut[] = {
	[ADP5589_GPI_STATUS_A]		= ADP5585_GPI_STATUS_A,
	[ADP5589_GPI_STATUS_B]		= ADP5585_GPI_STATUS_B,
	[ADP5589_RPULL_CONFIG_A]	= ADP5585_RPULL_CONFIG_A,
	[ADP5589_RPULL_CONFIG_B]	= ADP5585_RPULL_CONFIG_B,
	[ADP5589_RPULL_CONFIG_C]	= ADP5585_RPULL_CONFIG_C,
	[ADP5589_RPULL_CONFIG_D]	= ADP5585_RPULL_CONFIG_D,
	[ADP5589_GPI_INT_LEVEL_A]	= ADP5585_GPI_INT_LEVEL_A,
	[ADP5589_GPI_INT_LEVEL_B]	= ADP5585_GPI_INT_LEVEL_B,
	[ADP5589_GPI_EVENT_EN_A]	= ADP5585_GPI_EVENT_EN_A,
	[ADP5589_GPI_EVENT_EN_B]	= ADP5585_GPI_EVENT_EN_B,
	[ADP5589_GPI_INTERRUPT_EN_A]	= ADP5585_GPI_INTERRUPT_EN_A,
	[ADP5589_GPI_INTERRUPT_EN_B]	= ADP5585_GPI_INTERRUPT_EN_B,
	[ADP5589_DEBOUNCE_DIS_A]	= ADP5585_DEBOUNCE_DIS_A,
	[ADP5589_DEBOUNCE_DIS_B]	= ADP5585_DEBOUNCE_DIS_B,
	[ADP5589_GPO_DATA_OUT_A]	= ADP5585_GPO_DATA_OUT_A,
	[ADP5589_GPO_DATA_OUT_B]	= ADP5585_GPO_DATA_OUT_B,
	[ADP5589_GPO_OUT_MODE_A]	= ADP5585_GPO_OUT_MODE_A,
	[ADP5589_GPO_OUT_MODE_B]	= ADP5585_GPO_OUT_MODE_B,
	[ADP5589_GPIO_DIRECTION_A]	= ADP5585_GPIO_DIRECTION_A,
	[ADP5589_GPIO_DIRECTION_B]	= ADP5585_GPIO_DIRECTION_B,
	[ADP5589_RESET1_EVENT_A]	= ADP5585_RESET1_EVENT_A,
	[ADP5589_RESET1_EVENT_B]	= ADP5585_RESET1_EVENT_B,
	[ADP5589_RESET1_EVENT_C]	= ADP5585_RESET1_EVENT_C,
	[ADP5589_RESET2_EVENT_A]	= ADP5585_RESET2_EVENT_A,
	[ADP5589_RESET2_EVENT_B]	= ADP5585_RESET2_EVENT_B,
	[ADP5589_RESET_CFG]		= ADP5585_RESET_CFG,
	[ADP5589_PWM_OFFT_LOW]		= ADP5585_PWM_OFFT_LOW,
	[ADP5589_PWM_OFFT_HIGH]		= ADP5585_PWM_OFFT_HIGH,
	[ADP5589_PWM_ONT_LOW]		= ADP5585_PWM_ONT_LOW,
	[ADP5589_PWM_ONT_HIGH]		= ADP5585_PWM_ONT_HIGH,
	[ADP5589_PWM_CFG]		= ADP5585_PWM_CFG,
	[ADP5589_LOGIC_1_CFG]		= ADP5585_LOGIC_CFG,
	[ADP5589_LOGIC_FF_CFG]		= ADP5585_LOGIC_FF_CFG,
	[ADP5589_LOGIC_INT_EVENT_EN]	= ADP5585_LOGIC_INT_EVENT_EN,
	[ADP5589_POLL_PTIME_CFG]	= ADP5585_POLL_PTIME_CFG,
	[ADP5589_PIN_CONFIG_A]		= ADP5585_PIN_CONFIG_A,
	[ADP5589_PIN_CONFIG_B]		= ADP5585_PIN_CONFIG_B,
	[ADP5589_PIN_CONFIG_D]		= ADP5585_PIN_CONFIG_D,
	[ADP5589_GENERAL_CFG]		= ADP5585_GENERAL_CFG,
	[ADP5589_INT_EN]		= ADP5585_INT_EN,
};

static unsigned char adp5585_reg(unsigned char reg)
{
	return adp5585_reg_lut[reg];
}

static const struct adp_constants const_adp5585 = {
	.maxgpio		= ADP5585_MAXGPIO,
	.keymapsize		= ADP5585_KEYMAPSIZE,
	.gpi_pin_row_base	= ADP5585_GPI_PIN_ROW_BASE,
	.gpi_pin_row_end	= ADP5585_GPI_PIN_ROW_END,
	.gpi_pin_col_base	= ADP5585_GPI_PIN_COL_BASE,
	.gpi_pin_base		= ADP5585_GPI_PIN_BASE,
	.gpi_pin_end		= ADP5585_GPI_PIN_END,
	.gpimapsize_max		= ADP5585_GPIMAPSIZE_MAX,
	.c4_extend_cfg		= 10,
	.max_row_num		= ADP5585_MAX_ROW_NUM,
	.max_col_num		= ADP5585_MAX_COL_NUM,
	.row_mask		= ADP5585_ROW_MASK,
	.col_mask		= ADP5585_COL_MASK,
	.col_shift		= ADP5585_COL_SHIFT,
	.bank			= adp5585_bank,
	.bit			= adp5585_bit,
	.reg			= adp5585_reg,
};

372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
static int adp5589_read(struct i2c_client *client, u8 reg)
{
	int ret = i2c_smbus_read_byte_data(client, reg);

	if (ret < 0)
		dev_err(&client->dev, "Read Error\n");

	return ret;
}

static int adp5589_write(struct i2c_client *client, u8 reg, u8 val)
{
	return i2c_smbus_write_byte_data(client, reg, val);
}

#ifdef CONFIG_GPIOLIB
static int adp5589_gpio_get_value(struct gpio_chip *chip, unsigned off)
{
	struct adp5589_kpad *kpad = container_of(chip, struct adp5589_kpad, gc);
391 392
	unsigned int bank = kpad->var->bank(kpad->gpiomap[off]);
	unsigned int bit = kpad->var->bit(kpad->gpiomap[off]);
393

394 395 396
	return !!(adp5589_read(kpad->client,
			       kpad->var->reg(ADP5589_GPI_STATUS_A) + bank) &
			       bit);
397 398 399 400 401 402
}

static void adp5589_gpio_set_value(struct gpio_chip *chip,
				   unsigned off, int val)
{
	struct adp5589_kpad *kpad = container_of(chip, struct adp5589_kpad, gc);
403 404
	unsigned int bank = kpad->var->bank(kpad->gpiomap[off]);
	unsigned int bit = kpad->var->bit(kpad->gpiomap[off]);
405 406 407 408 409 410 411 412

	mutex_lock(&kpad->gpio_lock);

	if (val)
		kpad->dat_out[bank] |= bit;
	else
		kpad->dat_out[bank] &= ~bit;

413 414
	adp5589_write(kpad->client, kpad->var->reg(ADP5589_GPO_DATA_OUT_A) +
		      bank, kpad->dat_out[bank]);
415 416 417 418 419 420 421

	mutex_unlock(&kpad->gpio_lock);
}

static int adp5589_gpio_direction_input(struct gpio_chip *chip, unsigned off)
{
	struct adp5589_kpad *kpad = container_of(chip, struct adp5589_kpad, gc);
422 423
	unsigned int bank = kpad->var->bank(kpad->gpiomap[off]);
	unsigned int bit = kpad->var->bit(kpad->gpiomap[off]);
424 425 426 427 428
	int ret;

	mutex_lock(&kpad->gpio_lock);

	kpad->dir[bank] &= ~bit;
429 430
	ret = adp5589_write(kpad->client,
			    kpad->var->reg(ADP5589_GPIO_DIRECTION_A) + bank,
431 432 433 434 435 436 437 438 439 440 441
			    kpad->dir[bank]);

	mutex_unlock(&kpad->gpio_lock);

	return ret;
}

static int adp5589_gpio_direction_output(struct gpio_chip *chip,
					 unsigned off, int val)
{
	struct adp5589_kpad *kpad = container_of(chip, struct adp5589_kpad, gc);
442 443
	unsigned int bank = kpad->var->bank(kpad->gpiomap[off]);
	unsigned int bit = kpad->var->bit(kpad->gpiomap[off]);
444 445 446 447 448 449 450 451 452 453 454
	int ret;

	mutex_lock(&kpad->gpio_lock);

	kpad->dir[bank] |= bit;

	if (val)
		kpad->dat_out[bank] |= bit;
	else
		kpad->dat_out[bank] &= ~bit;

455 456 457 458
	ret = adp5589_write(kpad->client, kpad->var->reg(ADP5589_GPO_DATA_OUT_A)
			    + bank, kpad->dat_out[bank]);
	ret |= adp5589_write(kpad->client,
			     kpad->var->reg(ADP5589_GPIO_DIRECTION_A) + bank,
459 460 461 462 463 464 465
			     kpad->dir[bank]);

	mutex_unlock(&kpad->gpio_lock);

	return ret;
}

B
Bill Pemberton 已提交
466
static int adp5589_build_gpiomap(struct adp5589_kpad *kpad,
467 468
				const struct adp5589_kpad_platform_data *pdata)
{
469
	bool pin_used[ADP5589_MAXGPIO];
470 471 472 473 474
	int n_unused = 0;
	int i;

	memset(pin_used, false, sizeof(pin_used));

475
	for (i = 0; i < kpad->var->maxgpio; i++)
476 477 478 479
		if (pdata->keypad_en_mask & (1 << i))
			pin_used[i] = true;

	for (i = 0; i < kpad->gpimapsize; i++)
480
		pin_used[kpad->gpimap[i].pin - kpad->var->gpi_pin_base] = true;
481 482 483 484 485

	if (kpad->extend_cfg & R4_EXTEND_CFG)
		pin_used[4] = true;

	if (kpad->extend_cfg & C4_EXTEND_CFG)
486 487 488 489
		pin_used[kpad->var->c4_extend_cfg] = true;

	if (!kpad->adp5585_support_row5)
		pin_used[5] = true;
490

491
	for (i = 0; i < kpad->var->maxgpio; i++)
492 493 494 495 496 497
		if (!pin_used[i])
			kpad->gpiomap[n_unused++] = i;

	return n_unused;
}

B
Bill Pemberton 已提交
498
static int adp5589_gpio_add(struct adp5589_kpad *kpad)
499 500
{
	struct device *dev = &kpad->client->dev;
J
Jingoo Han 已提交
501
	const struct adp5589_kpad_platform_data *pdata = dev_get_platdata(dev);
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
	const struct adp5589_gpio_platform_data *gpio_data = pdata->gpio_data;
	int i, error;

	if (!gpio_data)
		return 0;

	kpad->gc.ngpio = adp5589_build_gpiomap(kpad, pdata);
	if (kpad->gc.ngpio == 0) {
		dev_info(dev, "No unused gpios left to export\n");
		return 0;
	}

	kpad->export_gpio = true;

	kpad->gc.direction_input = adp5589_gpio_direction_input;
	kpad->gc.direction_output = adp5589_gpio_direction_output;
	kpad->gc.get = adp5589_gpio_get_value;
	kpad->gc.set = adp5589_gpio_set_value;
	kpad->gc.can_sleep = 1;

	kpad->gc.base = gpio_data->gpio_start;
	kpad->gc.label = kpad->client->name;
	kpad->gc.owner = THIS_MODULE;

	mutex_init(&kpad->gpio_lock);

	error = gpiochip_add(&kpad->gc);
	if (error) {
		dev_err(dev, "gpiochip_add failed, err: %d\n", error);
		return error;
	}

534 535 536 537 538
	for (i = 0; i <= kpad->var->bank(kpad->var->maxgpio); i++) {
		kpad->dat_out[i] = adp5589_read(kpad->client, kpad->var->reg(
						ADP5589_GPO_DATA_OUT_A) + i);
		kpad->dir[i] = adp5589_read(kpad->client, kpad->var->reg(
					    ADP5589_GPIO_DIRECTION_A) + i);
539 540 541 542 543 544 545 546 547 548 549 550 551
	}

	if (gpio_data->setup) {
		error = gpio_data->setup(kpad->client,
					 kpad->gc.base, kpad->gc.ngpio,
					 gpio_data->context);
		if (error)
			dev_warn(dev, "setup failed, %d\n", error);
	}

	return 0;
}

B
Bill Pemberton 已提交
552
static void adp5589_gpio_remove(struct adp5589_kpad *kpad)
553 554
{
	struct device *dev = &kpad->client->dev;
J
Jingoo Han 已提交
555
	const struct adp5589_kpad_platform_data *pdata = dev_get_platdata(dev);
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
	const struct adp5589_gpio_platform_data *gpio_data = pdata->gpio_data;
	int error;

	if (!kpad->export_gpio)
		return;

	if (gpio_data->teardown) {
		error = gpio_data->teardown(kpad->client,
					    kpad->gc.base, kpad->gc.ngpio,
					    gpio_data->context);
		if (error)
			dev_warn(dev, "teardown failed %d\n", error);
	}

	error = gpiochip_remove(&kpad->gc);
	if (error)
		dev_warn(dev, "gpiochip_remove failed %d\n", error);
}
#else
static inline int adp5589_gpio_add(struct adp5589_kpad *kpad)
{
	return 0;
}

static inline void adp5589_gpio_remove(struct adp5589_kpad *kpad)
{
}
#endif

static void adp5589_report_switches(struct adp5589_kpad *kpad,
				    int key, int key_val)
{
	int i;

	for (i = 0; i < kpad->gpimapsize; i++) {
		if (key_val == kpad->gpimap[i].pin) {
			input_report_switch(kpad->input,
					    kpad->gpimap[i].sw_evt,
					    key & KEY_EV_PRESSED);
			break;
		}
	}
}

static void adp5589_report_events(struct adp5589_kpad *kpad, int ev_cnt)
{
	int i;

	for (i = 0; i < ev_cnt; i++) {
605
		int key = adp5589_read(kpad->client, ADP5589_5_FIFO_1 + i);
606 607
		int key_val = key & KEY_EV_MASK;

608 609
		if (key_val >= kpad->var->gpi_pin_base &&
		    key_val <= kpad->var->gpi_pin_end) {
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
			adp5589_report_switches(kpad, key, key_val);
		} else {
			input_report_key(kpad->input,
					 kpad->keycode[key_val - 1],
					 key & KEY_EV_PRESSED);
		}
	}
}

static irqreturn_t adp5589_irq(int irq, void *handle)
{
	struct adp5589_kpad *kpad = handle;
	struct i2c_client *client = kpad->client;
	int status, ev_cnt;

625
	status = adp5589_read(client, ADP5589_5_INT_STATUS);
626 627 628 629 630

	if (status & OVRFLOW_INT)	/* Unlikely and should never happen */
		dev_err(&client->dev, "Event Overflow Error\n");

	if (status & EVENT_INT) {
631
		ev_cnt = adp5589_read(client, ADP5589_5_STATUS) & KEC;
632 633 634 635 636 637
		if (ev_cnt) {
			adp5589_report_events(kpad, ev_cnt);
			input_sync(kpad->input);
		}
	}

638
	adp5589_write(client, ADP5589_5_INT_STATUS, status); /* Status is W1C */
639 640 641 642

	return IRQ_HANDLED;
}

B
Bill Pemberton 已提交
643
static int adp5589_get_evcode(struct adp5589_kpad *kpad, unsigned short key)
644 645 646
{
	int i;

647
	for (i = 0; i < kpad->var->keymapsize; i++)
648 649 650 651 652 653 654 655
		if (key == kpad->keycode[i])
			return (i + 1) | KEY_EV_PRESSED;

	dev_err(&kpad->client->dev, "RESET/UNLOCK key not in keycode map\n");

	return -EINVAL;
}

B
Bill Pemberton 已提交
656
static int adp5589_setup(struct adp5589_kpad *kpad)
657 658 659
{
	struct i2c_client *client = kpad->client;
	const struct adp5589_kpad_platform_data *pdata =
J
Jingoo Han 已提交
660
		dev_get_platdata(&client->dev);
661
	u8 (*reg) (u8) = kpad->var->reg;
662 663
	unsigned char evt_mode1 = 0, evt_mode2 = 0, evt_mode3 = 0;
	unsigned char pull_mask = 0;
664 665 666 667 668 669 670
	int i, ret;

	ret = adp5589_write(client, reg(ADP5589_PIN_CONFIG_A),
			    pdata->keypad_en_mask & kpad->var->row_mask);
	ret |= adp5589_write(client, reg(ADP5589_PIN_CONFIG_B),
			     (pdata->keypad_en_mask >> kpad->var->col_shift) &
			     kpad->var->col_mask);
671

672 673 674
	if (!kpad->is_adp5585)
		ret |= adp5589_write(client, ADP5589_PIN_CONFIG_C,
				     (pdata->keypad_en_mask >> 16) & 0xFF);
675

676
	if (!kpad->is_adp5585 && pdata->en_keylock) {
677 678 679 680 681 682 683 684 685 686
		ret |= adp5589_write(client, ADP5589_UNLOCK1,
				     pdata->unlock_key1);
		ret |= adp5589_write(client, ADP5589_UNLOCK2,
				     pdata->unlock_key2);
		ret |= adp5589_write(client, ADP5589_UNLOCK_TIMERS,
				     pdata->unlock_timer & LTIME_MASK);
		ret |= adp5589_write(client, ADP5589_LOCK_CFG, LOCK_EN);
	}

	for (i = 0; i < KEYP_MAX_EVENT; i++)
687
		ret |= adp5589_read(client, ADP5589_5_FIFO_1 + i);
688 689 690 691

	for (i = 0; i < pdata->gpimapsize; i++) {
		unsigned short pin = pdata->gpimap[i].pin;

692 693
		if (pin <= kpad->var->gpi_pin_row_end) {
			evt_mode1 |= (1 << (pin - kpad->var->gpi_pin_row_base));
694 695
		} else {
			evt_mode2 |=
696 697 698 699
			    ((1 << (pin - kpad->var->gpi_pin_col_base)) & 0xFF);
			if (!kpad->is_adp5585)
				evt_mode3 |= ((1 << (pin -
					kpad->var->gpi_pin_col_base)) >> 8);
700 701 702 703
		}
	}

	if (pdata->gpimapsize) {
704 705 706 707 708 709 710 711
		ret |= adp5589_write(client, reg(ADP5589_GPI_EVENT_EN_A),
				     evt_mode1);
		ret |= adp5589_write(client, reg(ADP5589_GPI_EVENT_EN_B),
				     evt_mode2);
		if (!kpad->is_adp5585)
			ret |= adp5589_write(client,
					     reg(ADP5589_GPI_EVENT_EN_C),
					     evt_mode3);
712 713 714
	}

	if (pdata->pull_dis_mask & pdata->pullup_en_100k &
715
		pdata->pullup_en_300k & pdata->pulldown_en_300k)
716 717
		dev_warn(&client->dev, "Conflicting pull resistor config\n");

718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736
	for (i = 0; i <= kpad->var->max_row_num; i++) {
		unsigned val = 0, bit = (1 << i);
		if (pdata->pullup_en_300k & bit)
			val = 0;
		else if (pdata->pulldown_en_300k & bit)
			val = 1;
		else if (pdata->pullup_en_100k & bit)
			val = 2;
		else if (pdata->pull_dis_mask & bit)
			val = 3;

		pull_mask |= val << (2 * (i & 0x3));

		if (i == 3 || i == kpad->var->max_row_num) {
			ret |= adp5589_write(client, reg(ADP5585_RPULL_CONFIG_A)
					     + (i >> 2), pull_mask);
			pull_mask = 0;
		}
	}
737

738 739 740
	for (i = 0; i <= kpad->var->max_col_num; i++) {
		unsigned val = 0, bit = 1 << (i + kpad->var->col_shift);
		if (pdata->pullup_en_300k & bit)
741
			val = 0;
742
		else if (pdata->pulldown_en_300k & bit)
743
			val = 1;
744
		else if (pdata->pullup_en_100k & bit)
745
			val = 2;
746
		else if (pdata->pull_dis_mask & bit)
747 748 749 750
			val = 3;

		pull_mask |= val << (2 * (i & 0x3));

751
		if (i == 3 || i == kpad->var->max_col_num) {
752
			ret |= adp5589_write(client,
753 754
					     reg(ADP5585_RPULL_CONFIG_C) +
					     (i >> 2), pull_mask);
755 756 757 758 759
			pull_mask = 0;
		}
	}

	if (pdata->reset1_key_1 && pdata->reset1_key_2 && pdata->reset1_key_3) {
760
		ret |= adp5589_write(client, reg(ADP5589_RESET1_EVENT_A),
761 762
				     adp5589_get_evcode(kpad,
							pdata->reset1_key_1));
763
		ret |= adp5589_write(client, reg(ADP5589_RESET1_EVENT_B),
764 765
				     adp5589_get_evcode(kpad,
							pdata->reset1_key_2));
766
		ret |= adp5589_write(client, reg(ADP5589_RESET1_EVENT_C),
767 768 769 770 771 772
				     adp5589_get_evcode(kpad,
							pdata->reset1_key_3));
		kpad->extend_cfg |= R4_EXTEND_CFG;
	}

	if (pdata->reset2_key_1 && pdata->reset2_key_2) {
773
		ret |= adp5589_write(client, reg(ADP5589_RESET2_EVENT_A),
774 775
				     adp5589_get_evcode(kpad,
							pdata->reset2_key_1));
776
		ret |= adp5589_write(client, reg(ADP5589_RESET2_EVENT_B),
777 778 779 780 781 782
				     adp5589_get_evcode(kpad,
							pdata->reset2_key_2));
		kpad->extend_cfg |= C4_EXTEND_CFG;
	}

	if (kpad->extend_cfg) {
783
		ret |= adp5589_write(client, reg(ADP5589_RESET_CFG),
784
				     pdata->reset_cfg);
785
		ret |= adp5589_write(client, reg(ADP5589_PIN_CONFIG_D),
786 787 788
				     kpad->extend_cfg);
	}

789 790
	ret |= adp5589_write(client, reg(ADP5589_DEBOUNCE_DIS_A),
			    pdata->debounce_dis_mask & kpad->var->row_mask);
791

792 793 794 795 796 797 798 799 800
	ret |= adp5589_write(client, reg(ADP5589_DEBOUNCE_DIS_B),
			     (pdata->debounce_dis_mask >> kpad->var->col_shift)
			     & kpad->var->col_mask);

	if (!kpad->is_adp5585)
		ret |= adp5589_write(client, reg(ADP5589_DEBOUNCE_DIS_C),
				     (pdata->debounce_dis_mask >> 16) & 0xFF);

	ret |= adp5589_write(client, reg(ADP5589_POLL_PTIME_CFG),
801
			     pdata->scan_cycle_time & PTIME_MASK);
802 803 804 805
	ret |= adp5589_write(client, ADP5589_5_INT_STATUS,
			     (kpad->is_adp5585 ? 0 : LOGIC2_INT) |
			     LOGIC1_INT | OVRFLOW_INT |
			     (kpad->is_adp5585 ? 0 : LOCK_INT) |
806 807
			     GPI_INT | EVENT_INT);	/* Status is W1C */

808
	ret |= adp5589_write(client, reg(ADP5589_GENERAL_CFG),
809
			     INT_CFG | OSC_EN | CORE_CLK(3));
810
	ret |= adp5589_write(client, reg(ADP5589_INT_EN),
811 812 813 814 815 816 817 818 819 820
			     OVRFLOW_IEN | GPI_IEN | EVENT_IEN);

	if (ret < 0) {
		dev_err(&client->dev, "Write Error\n");
		return ret;
	}

	return 0;
}

B
Bill Pemberton 已提交
821
static void adp5589_report_switch_state(struct adp5589_kpad *kpad)
822 823 824
{
	int gpi_stat_tmp, pin_loc;
	int i;
825 826 827 828 829 830
	int gpi_stat1 = adp5589_read(kpad->client,
				     kpad->var->reg(ADP5589_GPI_STATUS_A));
	int gpi_stat2 = adp5589_read(kpad->client,
				     kpad->var->reg(ADP5589_GPI_STATUS_B));
	int gpi_stat3 = !kpad->is_adp5585 ?
			adp5589_read(kpad->client, ADP5589_GPI_STATUS_C) : 0;
831 832 833 834

	for (i = 0; i < kpad->gpimapsize; i++) {
		unsigned short pin = kpad->gpimap[i].pin;

835
		if (pin <= kpad->var->gpi_pin_row_end) {
836
			gpi_stat_tmp = gpi_stat1;
837 838
			pin_loc = pin - kpad->var->gpi_pin_row_base;
		} else if ((pin - kpad->var->gpi_pin_col_base) < 8) {
839
			gpi_stat_tmp = gpi_stat2;
840
			pin_loc = pin - kpad->var->gpi_pin_col_base;
841 842
		} else {
			gpi_stat_tmp = gpi_stat3;
843
			pin_loc = pin - kpad->var->gpi_pin_col_base - 8;
844 845 846 847
		}

		if (gpi_stat_tmp < 0) {
			dev_err(&kpad->client->dev,
848 849
				"Can't read GPIO_DAT_STAT switch %d, default to OFF\n",
				pin);
850 851 852 853 854 855 856 857 858 859 860
			gpi_stat_tmp = 0;
		}

		input_report_switch(kpad->input,
				    kpad->gpimap[i].sw_evt,
				    !(gpi_stat_tmp & (1 << pin_loc)));
	}

	input_sync(kpad->input);
}

B
Bill Pemberton 已提交
861 862
static int adp5589_probe(struct i2c_client *client,
			 const struct i2c_device_id *id)
863 864
{
	struct adp5589_kpad *kpad;
865
	const struct adp5589_kpad_platform_data *pdata =
J
Jingoo Han 已提交
866
		dev_get_platdata(&client->dev);
867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882
	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;
	}

883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901
	kpad = kzalloc(sizeof(*kpad), GFP_KERNEL);
	if (!kpad)
		return -ENOMEM;

	switch (id->driver_data) {
	case ADP5585_02:
		kpad->adp5585_support_row5 = true;
	case ADP5585_01:
		kpad->is_adp5585 = true;
		kpad->var = &const_adp5585;
		break;
	case ADP5589:
		kpad->var = &const_adp5589;
		break;
	}

	if (!((pdata->keypad_en_mask & kpad->var->row_mask) &&
			(pdata->keypad_en_mask >> kpad->var->col_shift)) ||
			!pdata->keymap) {
902
		dev_err(&client->dev, "no rows, cols or keymap from pdata\n");
903 904
		error = -EINVAL;
		goto err_free_mem;
905 906
	}

907
	if (pdata->keymapsize != kpad->var->keymapsize) {
908
		dev_err(&client->dev, "invalid keymapsize\n");
909 910
		error = -EINVAL;
		goto err_free_mem;
911 912 913 914
	}

	if (!pdata->gpimap && pdata->gpimapsize) {
		dev_err(&client->dev, "invalid gpimap from pdata\n");
915 916
		error = -EINVAL;
		goto err_free_mem;
917 918
	}

919
	if (pdata->gpimapsize > kpad->var->gpimapsize_max) {
920
		dev_err(&client->dev, "invalid gpimapsize\n");
921 922
		error = -EINVAL;
		goto err_free_mem;
923 924 925 926 927
	}

	for (i = 0; i < pdata->gpimapsize; i++) {
		unsigned short pin = pdata->gpimap[i].pin;

928 929
		if (pin < kpad->var->gpi_pin_base ||
				pin > kpad->var->gpi_pin_end) {
930
			dev_err(&client->dev, "invalid gpi pin data\n");
931 932
			error = -EINVAL;
			goto err_free_mem;
933 934
		}

935
		if ((1 << (pin - kpad->var->gpi_pin_row_base)) &
936 937
				pdata->keypad_en_mask) {
			dev_err(&client->dev, "invalid gpi row/col data\n");
938 939
			error = -EINVAL;
			goto err_free_mem;
940 941 942 943 944
		}
	}

	if (!client->irq) {
		dev_err(&client->dev, "no IRQ?\n");
945 946
		error = -EINVAL;
		goto err_free_mem;
947 948 949
	}

	input = input_allocate_device();
950
	if (!input) {
951 952 953 954 955 956 957
		error = -ENOMEM;
		goto err_free_mem;
	}

	kpad->client = client;
	kpad->input = input;

958
	ret = adp5589_read(client, ADP5589_5_ID);
959 960
	if (ret < 0) {
		error = ret;
961
		goto err_free_input;
962 963
	}

964
	revid = (u8) ret & ADP5589_5_DEVICE_ID_MASK;
965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993

	input->name = client->name;
	input->phys = "adp5589-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++)
994 995
		if (kpad->keycode[i] <= KEY_MAX)
			__set_bit(kpad->keycode[i], input->keybit);
996 997 998 999 1000 1001 1002 1003 1004 1005
	__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");
1006
		goto err_free_input;
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038
	}

	error = request_threaded_irq(client->irq, NULL, adp5589_irq,
				     IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
				     client->dev.driver->name, kpad);
	if (error) {
		dev_err(&client->dev, "irq %d busy?\n", client->irq);
		goto err_unreg_dev;
	}

	error = adp5589_setup(kpad);
	if (error)
		goto err_free_irq;

	if (kpad->gpimapsize)
		adp5589_report_switch_state(kpad);

	error = adp5589_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);
err_unreg_dev:
	input_unregister_device(input);
	input = NULL;
1039
err_free_input:
1040
	input_free_device(input);
1041
err_free_mem:
1042 1043 1044 1045 1046
	kfree(kpad);

	return error;
}

B
Bill Pemberton 已提交
1047
static int adp5589_remove(struct i2c_client *client)
1048 1049 1050
{
	struct adp5589_kpad *kpad = i2c_get_clientdata(client);

1051
	adp5589_write(client, kpad->var->reg(ADP5589_GENERAL_CFG), 0);
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
	free_irq(client->irq, kpad);
	input_unregister_device(kpad->input);
	adp5589_gpio_remove(kpad);
	kfree(kpad);

	return 0;
}

#ifdef CONFIG_PM_SLEEP
static int adp5589_suspend(struct device *dev)
{
	struct adp5589_kpad *kpad = dev_get_drvdata(dev);
	struct i2c_client *client = kpad->client;

	disable_irq(client->irq);

	if (device_may_wakeup(&client->dev))
		enable_irq_wake(client->irq);

	return 0;
}

static int adp5589_resume(struct device *dev)
{
	struct adp5589_kpad *kpad = dev_get_drvdata(dev);
	struct i2c_client *client = kpad->client;

	if (device_may_wakeup(&client->dev))
		disable_irq_wake(client->irq);

	enable_irq(client->irq);

	return 0;
}
#endif

static SIMPLE_DEV_PM_OPS(adp5589_dev_pm_ops, adp5589_suspend, adp5589_resume);

static const struct i2c_device_id adp5589_id[] = {
1091 1092 1093
	{"adp5589-keys", ADP5589},
	{"adp5585-keys", ADP5585_01},
	{"adp5585-02-keys", ADP5585_02}, /* Adds ROW5 to ADP5585 */
1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105
	{}
};

MODULE_DEVICE_TABLE(i2c, adp5589_id);

static struct i2c_driver adp5589_driver = {
	.driver = {
		.name = KBUILD_MODNAME,
		.owner = THIS_MODULE,
		.pm = &adp5589_dev_pm_ops,
	},
	.probe = adp5589_probe,
B
Bill Pemberton 已提交
1106
	.remove = adp5589_remove,
1107 1108 1109
	.id_table = adp5589_id,
};

1110
module_i2c_driver(adp5589_driver);
1111 1112 1113

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
1114
MODULE_DESCRIPTION("ADP5589/ADP5585 Keypad driver");