i2c-hid.c 31.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 * HID over I2C protocol implementation
 *
 * Copyright (c) 2012 Benjamin Tissoires <benjamin.tissoires@gmail.com>
 * Copyright (c) 2012 Ecole Nationale de l'Aviation Civile, France
 * Copyright (c) 2012 Red Hat, Inc
 *
 * This code is partly based on "USB HID support for Linux":
 *
 *  Copyright (c) 1999 Andreas Gal
 *  Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
 *  Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
 *  Copyright (c) 2007-2008 Oliver Neukum
 *  Copyright (c) 2006-2010 Jiri Kosina
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file COPYING in the main directory of this archive for
 * more details.
 */

#include <linux/module.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/input.h>
25
#include <linux/irq.h>
26 27 28
#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/pm.h>
29
#include <linux/pm_runtime.h>
30 31 32 33 34 35 36 37
#include <linux/device.h>
#include <linux/wait.h>
#include <linux/err.h>
#include <linux/string.h>
#include <linux/list.h>
#include <linux/jiffies.h>
#include <linux/kernel.h>
#include <linux/hid.h>
38
#include <linux/mutex.h>
M
Mika Westerberg 已提交
39
#include <linux/acpi.h>
40
#include <linux/of.h>
J
Jiri Kosina 已提交
41
#include <linux/regulator/consumer.h>
42

43
#include <linux/platform_data/i2c-hid.h>
44

45 46 47 48
#include "../hid-ids.h"

/* quirks to control the device */
#define I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV	BIT(0)
49
#define I2C_HID_QUIRK_NO_IRQ_AFTER_RESET	BIT(1)
50
#define I2C_HID_QUIRK_RESEND_REPORT_DESCR	BIT(2)
51

52
/* flags */
53 54 55
#define I2C_HID_STARTED		0
#define I2C_HID_RESET_PENDING	1
#define I2C_HID_READ_PENDING	2
56 57 58 59 60

#define I2C_HID_PWR_ON		0x00
#define I2C_HID_PWR_SLEEP	0x01

/* debug option */
61
static bool debug;
62 63 64
module_param(debug, bool, 0444);
MODULE_PARM_DESC(debug, "print a lot of debug information");

65 66 67 68 69
#define i2c_hid_dbg(ihid, fmt, arg...)					  \
do {									  \
	if (debug)							  \
		dev_printk(KERN_DEBUG, &(ihid)->client->dev, fmt, ##arg); \
} while (0)
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

struct i2c_hid_desc {
	__le16 wHIDDescLength;
	__le16 bcdVersion;
	__le16 wReportDescLength;
	__le16 wReportDescRegister;
	__le16 wInputRegister;
	__le16 wMaxInputLength;
	__le16 wOutputRegister;
	__le16 wMaxOutputLength;
	__le16 wCommandRegister;
	__le16 wDataRegister;
	__le16 wVendorID;
	__le16 wProductID;
	__le16 wVersionID;
85
	__le32 reserved;
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
} __packed;

struct i2c_hid_cmd {
	unsigned int registerIndex;
	__u8 opcode;
	unsigned int length;
	bool wait;
};

union command {
	u8 data[0];
	struct cmd {
		__le16 reg;
		__u8 reportTypeID;
		__u8 opcode;
	} __packed c;
};

#define I2C_HID_CMD(opcode_) \
	.opcode = opcode_, .length = 4, \
	.registerIndex = offsetof(struct i2c_hid_desc, wCommandRegister)

/* fetch HID descriptor */
static const struct i2c_hid_cmd hid_descr_cmd = { .length = 2 };
/* fetch report descriptors */
static const struct i2c_hid_cmd hid_report_descr_cmd = {
		.registerIndex = offsetof(struct i2c_hid_desc,
			wReportDescRegister),
		.opcode = 0x00,
		.length = 2 };
/* commands */
static const struct i2c_hid_cmd hid_reset_cmd =		{ I2C_HID_CMD(0x01),
							  .wait = true };
static const struct i2c_hid_cmd hid_get_report_cmd =	{ I2C_HID_CMD(0x02) };
static const struct i2c_hid_cmd hid_set_report_cmd =	{ I2C_HID_CMD(0x03) };
static const struct i2c_hid_cmd hid_set_power_cmd =	{ I2C_HID_CMD(0x08) };
122
static const struct i2c_hid_cmd hid_no_cmd =		{ .length = 0 };
123 124 125 126 127 128 129 130 131 132

/*
 * These definitions are not used here, but are defined by the spec.
 * Keeping them here for documentation purposes.
 *
 * static const struct i2c_hid_cmd hid_get_idle_cmd = { I2C_HID_CMD(0x04) };
 * static const struct i2c_hid_cmd hid_set_idle_cmd = { I2C_HID_CMD(0x05) };
 * static const struct i2c_hid_cmd hid_get_protocol_cmd = { I2C_HID_CMD(0x06) };
 * static const struct i2c_hid_cmd hid_set_protocol_cmd = { I2C_HID_CMD(0x07) };
 */
133

134 135
static DEFINE_MUTEX(i2c_hid_open_mut);

136 137 138 139 140 141 142 143 144 145 146 147
/* The main device structure */
struct i2c_hid {
	struct i2c_client	*client;	/* i2c client */
	struct hid_device	*hid;	/* pointer to corresponding HID dev */
	union {
		__u8 hdesc_buffer[sizeof(struct i2c_hid_desc)];
		struct i2c_hid_desc hdesc;	/* the HID Descriptor */
	};
	__le16			wHIDDescRegister; /* location of the i2c
						   * register of the HID
						   * descriptor. */
	unsigned int		bufsize;	/* i2c buffer size */
148 149 150 151
	u8			*inbuf;		/* Input buffer */
	u8			*rawbuf;	/* Raw Input buffer */
	u8			*cmdbuf;	/* Command buffer */
	u8			*argsbuf;	/* Command arguments buffer */
152 153

	unsigned long		flags;		/* device flags */
154
	unsigned long		quirks;		/* Various quirks */
155 156

	wait_queue_head_t	wait;		/* For waiting the interrupt */
M
Mika Westerberg 已提交
157 158

	struct i2c_hid_platform_data pdata;
159 160

	bool			irq_wake_enabled;
161
	struct mutex		reset_lock;
162 163
};

164 165 166 167 168 169 170 171 172
static const struct i2c_hid_quirks {
	__u16 idVendor;
	__u16 idProduct;
	__u32 quirks;
} i2c_hid_quirks[] = {
	{ USB_VENDOR_ID_WEIDA, USB_DEVICE_ID_WEIDA_8752,
		I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV },
	{ USB_VENDOR_ID_WEIDA, USB_DEVICE_ID_WEIDA_8755,
		I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV },
173 174
	{ I2C_VENDOR_ID_HANTICK, I2C_PRODUCT_ID_HANTICK_5288,
		I2C_HID_QUIRK_NO_IRQ_AFTER_RESET },
175 176
	{ I2C_VENDOR_ID_RAYD, I2C_PRODUCT_ID_RAYD_3118,
		I2C_HID_QUIRK_RESEND_REPORT_DESCR },
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
	{ 0, 0 }
};

/*
 * i2c_hid_lookup_quirk: return any quirks associated with a I2C HID device
 * @idVendor: the 16-bit vendor ID
 * @idProduct: the 16-bit product ID
 *
 * Returns: a u32 quirks value.
 */
static u32 i2c_hid_lookup_quirk(const u16 idVendor, const u16 idProduct)
{
	u32 quirks = 0;
	int n;

	for (n = 0; i2c_hid_quirks[n].idVendor; n++)
		if (i2c_hid_quirks[n].idVendor == idVendor &&
		    (i2c_hid_quirks[n].idProduct == (__u16)HID_ANY_ID ||
		     i2c_hid_quirks[n].idProduct == idProduct))
			quirks = i2c_hid_quirks[n].quirks;

	return quirks;
}

201 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 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
static int __i2c_hid_command(struct i2c_client *client,
		const struct i2c_hid_cmd *command, u8 reportID,
		u8 reportType, u8 *args, int args_len,
		unsigned char *buf_recv, int data_len)
{
	struct i2c_hid *ihid = i2c_get_clientdata(client);
	union command *cmd = (union command *)ihid->cmdbuf;
	int ret;
	struct i2c_msg msg[2];
	int msg_num = 1;

	int length = command->length;
	bool wait = command->wait;
	unsigned int registerIndex = command->registerIndex;

	/* special case for hid_descr_cmd */
	if (command == &hid_descr_cmd) {
		cmd->c.reg = ihid->wHIDDescRegister;
	} else {
		cmd->data[0] = ihid->hdesc_buffer[registerIndex];
		cmd->data[1] = ihid->hdesc_buffer[registerIndex + 1];
	}

	if (length > 2) {
		cmd->c.opcode = command->opcode;
		cmd->c.reportTypeID = reportID | reportType << 4;
	}

	memcpy(cmd->data + length, args, args_len);
	length += args_len;

	i2c_hid_dbg(ihid, "%s: cmd=%*ph\n", __func__, length, cmd->data);

	msg[0].addr = client->addr;
	msg[0].flags = client->flags & I2C_M_TEN;
	msg[0].len = length;
	msg[0].buf = cmd->data;
	if (data_len > 0) {
		msg[1].addr = client->addr;
		msg[1].flags = client->flags & I2C_M_TEN;
		msg[1].flags |= I2C_M_RD;
		msg[1].len = data_len;
		msg[1].buf = buf_recv;
		msg_num = 2;
		set_bit(I2C_HID_READ_PENDING, &ihid->flags);
	}

	if (wait)
		set_bit(I2C_HID_RESET_PENDING, &ihid->flags);

	ret = i2c_transfer(client->adapter, msg, msg_num);

	if (data_len > 0)
		clear_bit(I2C_HID_READ_PENDING, &ihid->flags);

	if (ret != msg_num)
		return ret < 0 ? ret : -EIO;

	ret = 0;

261 262 263
	if (wait && (ihid->quirks & I2C_HID_QUIRK_NO_IRQ_AFTER_RESET)) {
		msleep(100);
	} else if (wait) {
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
		i2c_hid_dbg(ihid, "%s: waiting...\n", __func__);
		if (!wait_event_timeout(ihid->wait,
				!test_bit(I2C_HID_RESET_PENDING, &ihid->flags),
				msecs_to_jiffies(5000)))
			ret = -ENODATA;
		i2c_hid_dbg(ihid, "%s: finished.\n", __func__);
	}

	return ret;
}

static int i2c_hid_command(struct i2c_client *client,
		const struct i2c_hid_cmd *command,
		unsigned char *buf_recv, int data_len)
{
	return __i2c_hid_command(client, command, 0, 0, NULL, 0,
				buf_recv, data_len);
}

static int i2c_hid_get_report(struct i2c_client *client, u8 reportType,
		u8 reportID, unsigned char *buf_recv, int data_len)
{
	struct i2c_hid *ihid = i2c_get_clientdata(client);
	u8 args[3];
	int ret;
	int args_len = 0;
	u16 readRegister = le16_to_cpu(ihid->hdesc.wDataRegister);

	i2c_hid_dbg(ihid, "%s\n", __func__);

	if (reportID >= 0x0F) {
		args[args_len++] = reportID;
		reportID = 0x0F;
	}

	args[args_len++] = readRegister & 0xFF;
	args[args_len++] = readRegister >> 8;

	ret = __i2c_hid_command(client, &hid_get_report_cmd, reportID,
		reportType, args, args_len, buf_recv, data_len);
	if (ret) {
		dev_err(&client->dev,
			"failed to retrieve report from device.\n");
307
		return ret;
308 309 310 311 312
	}

	return 0;
}

313 314 315 316 317 318 319 320 321 322 323
/**
 * i2c_hid_set_or_send_report: forward an incoming report to the device
 * @client: the i2c_client of the device
 * @reportType: 0x03 for HID_FEATURE_REPORT ; 0x02 for HID_OUTPUT_REPORT
 * @reportID: the report ID
 * @buf: the actual data to transfer, without the report ID
 * @len: size of buf
 * @use_data: true: use SET_REPORT HID command, false: send plain OUTPUT report
 */
static int i2c_hid_set_or_send_report(struct i2c_client *client, u8 reportType,
		u8 reportID, unsigned char *buf, size_t data_len, bool use_data)
324 325 326
{
	struct i2c_hid *ihid = i2c_get_clientdata(client);
	u8 *args = ihid->argsbuf;
327
	const struct i2c_hid_cmd *hidcmd;
328 329
	int ret;
	u16 dataRegister = le16_to_cpu(ihid->hdesc.wDataRegister);
330 331
	u16 outputRegister = le16_to_cpu(ihid->hdesc.wOutputRegister);
	u16 maxOutputLength = le16_to_cpu(ihid->hdesc.wMaxOutputLength);
332 333 334 335 336 337 338 339
	u16 size;
	int args_len;
	int index = 0;

	i2c_hid_dbg(ihid, "%s\n", __func__);

	if (data_len > ihid->bufsize)
		return -EINVAL;
340

341
	size =		2			/* size */ +
342 343
			(reportID ? 1 : 0)	/* reportID */ +
			data_len		/* buf */;
344
	args_len =	(reportID >= 0x0F ? 1 : 0) /* optional third byte */ +
345 346 347
			2			/* dataRegister */ +
			size			/* args */;

348 349 350
	if (!use_data && maxOutputLength == 0)
		return -ENOSYS;

351 352 353 354 355
	if (reportID >= 0x0F) {
		args[index++] = reportID;
		reportID = 0x0F;
	}

356 357 358 359
	/*
	 * use the data register for feature reports or if the device does not
	 * support the output register
	 */
360
	if (use_data) {
361 362
		args[index++] = dataRegister & 0xFF;
		args[index++] = dataRegister >> 8;
363
		hidcmd = &hid_set_report_cmd;
364 365 366 367 368
	} else {
		args[index++] = outputRegister & 0xFF;
		args[index++] = outputRegister >> 8;
		hidcmd = &hid_no_cmd;
	}
369 370 371 372 373 374 375 376 377

	args[index++] = size & 0xFF;
	args[index++] = size >> 8;

	if (reportID)
		args[index++] = reportID;

	memcpy(&args[index], buf, data_len);

378
	ret = __i2c_hid_command(client, hidcmd, reportID,
379 380 381
		reportType, args, args_len, NULL, 0);
	if (ret) {
		dev_err(&client->dev, "failed to set a report to device.\n");
382
		return ret;
383 384 385 386 387 388 389 390 391 392 393 394
	}

	return data_len;
}

static int i2c_hid_set_power(struct i2c_client *client, int power_state)
{
	struct i2c_hid *ihid = i2c_get_clientdata(client);
	int ret;

	i2c_hid_dbg(ihid, "%s\n", __func__);

395 396 397 398 399 400 401 402 403 404 405 406 407 408
	/*
	 * Some devices require to send a command to wakeup before power on.
	 * The call will get a return value (EREMOTEIO) but device will be
	 * triggered and activated. After that, it goes like a normal device.
	 */
	if (power_state == I2C_HID_PWR_ON &&
	    ihid->quirks & I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV) {
		ret = i2c_hid_command(client, &hid_set_power_cmd, NULL, 0);

		/* Device was already activated */
		if (!ret)
			goto set_pwr_exit;
	}

409 410
	ret = __i2c_hid_command(client, &hid_set_power_cmd, power_state,
		0, NULL, 0, NULL, 0);
411

412 413 414
	if (ret)
		dev_err(&client->dev, "failed to change power setting.\n");

415
set_pwr_exit:
416 417 418 419 420 421 422 423 424 425
	return ret;
}

static int i2c_hid_hwreset(struct i2c_client *client)
{
	struct i2c_hid *ihid = i2c_get_clientdata(client);
	int ret;

	i2c_hid_dbg(ihid, "%s\n", __func__);

426 427 428 429 430 431 432
	/*
	 * This prevents sending feature reports while the device is
	 * being reset. Otherwise we may lose the reset complete
	 * interrupt.
	 */
	mutex_lock(&ihid->reset_lock);

433 434
	ret = i2c_hid_set_power(client, I2C_HID_PWR_ON);
	if (ret)
435
		goto out_unlock;
436

437 438 439 440 441 442 443 444 445
	/*
	 * The HID over I2C specification states that if a DEVICE needs time
	 * after the PWR_ON request, it should utilise CLOCK stretching.
	 * However, it has been observered that the Windows driver provides a
	 * 1ms sleep between the PWR_ON and RESET requests and that some devices
	 * rely on this.
	 */
	usleep_range(1000, 5000);

446 447 448 449 450 451 452 453
	i2c_hid_dbg(ihid, "resetting...\n");

	ret = i2c_hid_command(client, &hid_reset_cmd, NULL, 0);
	if (ret) {
		dev_err(&client->dev, "failed to reset device.\n");
		i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
	}

454 455 456
out_unlock:
	mutex_unlock(&ihid->reset_lock);
	return ret;
457 458
}

459
static void i2c_hid_get_input(struct i2c_hid *ihid)
460
{
461 462
	int ret;
	u32 ret_size;
463 464 465 466
	int size = le16_to_cpu(ihid->hdesc.wMaxInputLength);

	if (size > ihid->bufsize)
		size = ihid->bufsize;
467 468 469 470

	ret = i2c_master_recv(ihid->client, ihid->inbuf, size);
	if (ret != size) {
		if (ret < 0)
471
			return;
472 473 474

		dev_err(&ihid->client->dev, "%s: got %d data instead of %d\n",
			__func__, ret, size);
475
		return;
476 477 478 479 480 481 482 483
	}

	ret_size = ihid->inbuf[0] | ihid->inbuf[1] << 8;

	if (!ret_size) {
		/* host or device initiated RESET completed */
		if (test_and_clear_bit(I2C_HID_RESET_PENDING, &ihid->flags))
			wake_up(&ihid->wait);
484
		return;
485 486
	}

487
	if ((ret_size > size) || (ret_size <= 2)) {
488 489
		dev_err(&ihid->client->dev, "%s: incomplete report (%d/%d)\n",
			__func__, size, ret_size);
490
		return;
491 492 493 494 495 496 497 498
	}

	i2c_hid_dbg(ihid, "input: %*ph\n", ret_size, ihid->inbuf);

	if (test_bit(I2C_HID_STARTED, &ihid->flags))
		hid_input_report(ihid->hid, HID_INPUT_REPORT, ihid->inbuf + 2,
				ret_size - 2, 1);

499
	return;
500 501 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 534 535 536 537
}

static irqreturn_t i2c_hid_irq(int irq, void *dev_id)
{
	struct i2c_hid *ihid = dev_id;

	if (test_bit(I2C_HID_READ_PENDING, &ihid->flags))
		return IRQ_HANDLED;

	i2c_hid_get_input(ihid);

	return IRQ_HANDLED;
}

static int i2c_hid_get_report_length(struct hid_report *report)
{
	return ((report->size - 1) >> 3) + 1 +
		report->device->report_enum[report->type].numbered + 2;
}

/*
 * Traverse the supplied list of reports and find the longest
 */
static void i2c_hid_find_max_report(struct hid_device *hid, unsigned int type,
		unsigned int *max)
{
	struct hid_report *report;
	unsigned int size;

	/* We should not rely on wMaxInputLength, as some devices may set it to
	 * a wrong length. */
	list_for_each_entry(report, &hid->report_enum[type].report_list, list) {
		size = i2c_hid_get_report_length(report);
		if (*max < size)
			*max = size;
	}
}

538 539 540
static void i2c_hid_free_buffers(struct i2c_hid *ihid)
{
	kfree(ihid->inbuf);
541
	kfree(ihid->rawbuf);
542 543 544
	kfree(ihid->argsbuf);
	kfree(ihid->cmdbuf);
	ihid->inbuf = NULL;
545
	ihid->rawbuf = NULL;
546 547 548 549 550 551
	ihid->cmdbuf = NULL;
	ihid->argsbuf = NULL;
	ihid->bufsize = 0;
}

static int i2c_hid_alloc_buffers(struct i2c_hid *ihid, size_t report_size)
552 553 554
{
	/* the worst case is computed from the set_report command with a
	 * reportID > 15 and the maximum report length */
555 556
	int args_len = sizeof(__u8) + /* ReportID */
		       sizeof(__u8) + /* optional ReportID byte */
557 558
		       sizeof(__u16) + /* data register */
		       sizeof(__u16) + /* size of the report */
559
		       report_size; /* report */
560

561
	ihid->inbuf = kzalloc(report_size, GFP_KERNEL);
562
	ihid->rawbuf = kzalloc(report_size, GFP_KERNEL);
563 564 565
	ihid->argsbuf = kzalloc(args_len, GFP_KERNEL);
	ihid->cmdbuf = kzalloc(sizeof(union command) + args_len, GFP_KERNEL);

566
	if (!ihid->inbuf || !ihid->rawbuf || !ihid->argsbuf || !ihid->cmdbuf) {
567
		i2c_hid_free_buffers(ihid);
568 569 570
		return -ENOMEM;
	}

571
	ihid->bufsize = report_size;
572

573
	return 0;
574 575 576 577 578 579 580 581
}

static int i2c_hid_get_raw_report(struct hid_device *hid,
		unsigned char report_number, __u8 *buf, size_t count,
		unsigned char report_type)
{
	struct i2c_client *client = hid->driver_data;
	struct i2c_hid *ihid = i2c_get_clientdata(client);
582
	size_t ret_count, ask_count;
583 584 585 586 587
	int ret;

	if (report_type == HID_OUTPUT_REPORT)
		return -EINVAL;

588 589
	/* +2 bytes to include the size of the reply in the query buffer */
	ask_count = min(count + 2, (size_t)ihid->bufsize);
590 591 592

	ret = i2c_hid_get_report(client,
			report_type == HID_FEATURE_REPORT ? 0x03 : 0x01,
593
			report_number, ihid->rawbuf, ask_count);
594 595 596 597

	if (ret < 0)
		return ret;

598
	ret_count = ihid->rawbuf[0] | (ihid->rawbuf[1] << 8);
599

J
Jiri Kosina 已提交
600
	if (ret_count <= 2)
601 602 603 604 605 606
		return 0;

	ret_count = min(ret_count, ask_count);

	/* The query buffer contains the size, dropping it in the reply */
	count = min(count, ret_count - 2);
607
	memcpy(buf, ihid->rawbuf + 2, count);
608 609 610 611 612

	return count;
}

static int i2c_hid_output_raw_report(struct hid_device *hid, __u8 *buf,
613
		size_t count, unsigned char report_type, bool use_data)
614 615
{
	struct i2c_client *client = hid->driver_data;
616
	struct i2c_hid *ihid = i2c_get_clientdata(client);
617
	int report_id = buf[0];
618
	int ret;
619 620 621 622

	if (report_type == HID_INPUT_REPORT)
		return -EINVAL;

623 624
	mutex_lock(&ihid->reset_lock);

625 626 627 628 629
	if (report_id) {
		buf++;
		count--;
	}

630
	ret = i2c_hid_set_or_send_report(client,
631
				report_type == HID_FEATURE_REPORT ? 0x03 : 0x02,
632
				report_id, buf, count, use_data);
633 634 635 636

	if (report_id && ret >= 0)
		ret++; /* add report_id to the number of transfered bytes */

637 638
	mutex_unlock(&ihid->reset_lock);

639
	return ret;
640 641
}

642 643
static int i2c_hid_output_report(struct hid_device *hid, __u8 *buf,
		size_t count)
644
{
645 646 647
	return i2c_hid_output_raw_report(hid, buf, count, HID_OUTPUT_REPORT,
			false);
}
648

649 650 651 652
static int i2c_hid_raw_request(struct hid_device *hid, unsigned char reportnum,
			       __u8 *buf, size_t len, unsigned char rtype,
			       int reqtype)
{
653 654
	switch (reqtype) {
	case HID_REQ_GET_REPORT:
655
		return i2c_hid_get_raw_report(hid, reportnum, buf, len, rtype);
656
	case HID_REQ_SET_REPORT:
657 658 659 660 661
		if (buf[0] != reportnum)
			return -EINVAL;
		return i2c_hid_output_raw_report(hid, buf, len, rtype, true);
	default:
		return -EIO;
662 663 664
	}
}

665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724
static int i2c_hid_parse(struct hid_device *hid)
{
	struct i2c_client *client = hid->driver_data;
	struct i2c_hid *ihid = i2c_get_clientdata(client);
	struct i2c_hid_desc *hdesc = &ihid->hdesc;
	unsigned int rsize;
	char *rdesc;
	int ret;
	int tries = 3;

	i2c_hid_dbg(ihid, "entering %s\n", __func__);

	rsize = le16_to_cpu(hdesc->wReportDescLength);
	if (!rsize || rsize > HID_MAX_DESCRIPTOR_SIZE) {
		dbg_hid("weird size of report descriptor (%u)\n", rsize);
		return -EINVAL;
	}

	do {
		ret = i2c_hid_hwreset(client);
		if (ret)
			msleep(1000);
	} while (tries-- > 0 && ret);

	if (ret)
		return ret;

	rdesc = kzalloc(rsize, GFP_KERNEL);

	if (!rdesc) {
		dbg_hid("couldn't allocate rdesc memory\n");
		return -ENOMEM;
	}

	i2c_hid_dbg(ihid, "asking HID report descriptor\n");

	ret = i2c_hid_command(client, &hid_report_descr_cmd, rdesc, rsize);
	if (ret) {
		hid_err(hid, "reading report descriptor failed\n");
		kfree(rdesc);
		return -EIO;
	}

	i2c_hid_dbg(ihid, "Report Descriptor: %*ph\n", rsize, rdesc);

	ret = hid_parse_report(hid, rdesc, rsize);
	kfree(rdesc);
	if (ret) {
		dbg_hid("parsing report descriptor failed\n");
		return ret;
	}

	return 0;
}

static int i2c_hid_start(struct hid_device *hid)
{
	struct i2c_client *client = hid->driver_data;
	struct i2c_hid *ihid = i2c_get_clientdata(client);
	int ret;
725
	unsigned int bufsize = HID_MIN_BUFFER_SIZE;
726

727 728 729
	i2c_hid_find_max_report(hid, HID_INPUT_REPORT, &bufsize);
	i2c_hid_find_max_report(hid, HID_OUTPUT_REPORT, &bufsize);
	i2c_hid_find_max_report(hid, HID_FEATURE_REPORT, &bufsize);
730

731
	if (bufsize > ihid->bufsize) {
B
Benjamin Tissoires 已提交
732
		disable_irq(client->irq);
733 734
		i2c_hid_free_buffers(ihid);

735
		ret = i2c_hid_alloc_buffers(ihid, bufsize);
B
Benjamin Tissoires 已提交
736
		enable_irq(client->irq);
737

738
		if (ret)
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753
			return ret;
	}

	return 0;
}

static void i2c_hid_stop(struct hid_device *hid)
{
	hid->claimed = 0;
}

static int i2c_hid_open(struct hid_device *hid)
{
	struct i2c_client *client = hid->driver_data;
	struct i2c_hid *ihid = i2c_get_clientdata(client);
754
	int ret = 0;
755

756 757 758 759 760 761
	ret = pm_runtime_get_sync(&client->dev);
	if (ret < 0)
		return ret;

	set_bit(I2C_HID_STARTED, &ihid->flags);
	return 0;
762 763 764 765 766 767 768
}

static void i2c_hid_close(struct hid_device *hid)
{
	struct i2c_client *client = hid->driver_data;
	struct i2c_hid *ihid = i2c_get_clientdata(client);

769
	clear_bit(I2C_HID_STARTED, &ihid->flags);
770

771 772
	/* Save some power */
	pm_runtime_put(&client->dev);
773 774 775 776 777 778 779 780 781 782 783
}

static int i2c_hid_power(struct hid_device *hid, int lvl)
{
	struct i2c_client *client = hid->driver_data;
	struct i2c_hid *ihid = i2c_get_clientdata(client);

	i2c_hid_dbg(ihid, "%s lvl:%d\n", __func__, lvl);

	switch (lvl) {
	case PM_HINT_FULLON:
784
		pm_runtime_get_sync(&client->dev);
785 786
		break;
	case PM_HINT_NORMAL:
787
		pm_runtime_put(&client->dev);
788 789
		break;
	}
790
	return 0;
791 792
}

793
struct hid_ll_driver i2c_hid_ll_driver = {
794 795 796 797 798 799
	.parse = i2c_hid_parse,
	.start = i2c_hid_start,
	.stop = i2c_hid_stop,
	.open = i2c_hid_open,
	.close = i2c_hid_close,
	.power = i2c_hid_power,
800 801
	.output_report = i2c_hid_output_report,
	.raw_request = i2c_hid_raw_request,
802
};
803
EXPORT_SYMBOL_GPL(i2c_hid_ll_driver);
804

805
static int i2c_hid_init_irq(struct i2c_client *client)
806 807
{
	struct i2c_hid *ihid = i2c_get_clientdata(client);
808
	unsigned long irqflags = 0;
809 810
	int ret;

811
	dev_dbg(&client->dev, "Requesting IRQ: %d\n", client->irq);
812

813 814 815
	if (!irq_get_trigger_type(client->irq))
		irqflags = IRQF_TRIGGER_LOW;

816
	ret = request_threaded_irq(client->irq, NULL, i2c_hid_irq,
817
				   irqflags | IRQF_ONESHOT, client->name, ihid);
818
	if (ret < 0) {
819
		dev_warn(&client->dev,
820 821
			"Could not register for %s interrupt, irq = %d,"
			" ret = %d\n",
822
			client->name, client->irq, ret);
823 824 825 826 827 828 829

		return ret;
	}

	return 0;
}

830
static int i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid)
831 832 833 834 835 836
{
	struct i2c_client *client = ihid->client;
	struct i2c_hid_desc *hdesc = &ihid->hdesc;
	unsigned int dsize;
	int ret;

837 838 839 840
	/* i2c hid fetch using a fixed descriptor size (30 bytes) */
	i2c_hid_dbg(ihid, "Fetching the HID descriptor\n");
	ret = i2c_hid_command(client, &hid_descr_cmd, ihid->hdesc_buffer,
				sizeof(struct i2c_hid_desc));
841
	if (ret) {
842
		dev_err(&client->dev, "hid_descr_cmd failed\n");
843 844 845
		return -ENODEV;
	}

846 847 848
	/* Validate the length of HID descriptor, the 4 first bytes:
	 * bytes 0-1 -> length
	 * bytes 2-3 -> bcdVersion (has to be 1.00) */
849 850 851
	/* check bcdVersion == 1.0 */
	if (le16_to_cpu(hdesc->bcdVersion) != 0x0100) {
		dev_err(&client->dev,
852
			"unexpected HID descriptor bcdVersion (0x%04hx)\n",
853 854 855 856
			le16_to_cpu(hdesc->bcdVersion));
		return -ENODEV;
	}

857 858 859 860 861
	/* Descriptor length should be 30 bytes as per the specification */
	dsize = le16_to_cpu(hdesc->wHIDDescLength);
	if (dsize != sizeof(struct i2c_hid_desc)) {
		dev_err(&client->dev, "weird size of HID descriptor (%u)\n",
			dsize);
862 863 864 865 866 867
		return -ENODEV;
	}
	i2c_hid_dbg(ihid, "HID Descriptor: %*ph\n", dsize, ihid->hdesc_buffer);
	return 0;
}

M
Mika Westerberg 已提交
868 869 870 871
#ifdef CONFIG_ACPI
static int i2c_hid_acpi_pdata(struct i2c_client *client,
		struct i2c_hid_platform_data *pdata)
{
872 873 874
	static guid_t i2c_hid_guid =
		GUID_INIT(0x3CDFF6F7, 0x4267, 0x4555,
			  0xAD, 0x05, 0xB3, 0x0A, 0x3D, 0x89, 0x38, 0xDE);
875
	union acpi_object *obj;
M
Mika Westerberg 已提交
876 877 878 879 880 881 882
	struct acpi_device *adev;
	acpi_handle handle;

	handle = ACPI_HANDLE(&client->dev);
	if (!handle || acpi_bus_get_device(handle, &adev))
		return -ENODEV;

883
	obj = acpi_evaluate_dsm_typed(handle, &i2c_hid_guid, 1, 1, NULL,
884 885
				      ACPI_TYPE_INTEGER);
	if (!obj) {
M
Mika Westerberg 已提交
886 887 888 889
		dev_err(&client->dev, "device _DSM execution failed\n");
		return -ENODEV;
	}

890 891
	pdata->hid_descriptor_address = obj->integer.value;
	ACPI_FREE(obj);
M
Mika Westerberg 已提交
892

893
	return 0;
M
Mika Westerberg 已提交
894 895
}

896 897 898 899
static void i2c_hid_acpi_fix_up_power(struct device *dev)
{
	struct acpi_device *adev;

900 901
	adev = ACPI_COMPANION(dev);
	if (adev)
902 903 904
		acpi_device_fix_up_power(adev);
}

M
Mika Westerberg 已提交
905 906 907 908 909 910 911 912 913 914 915 916
static const struct acpi_device_id i2c_hid_acpi_match[] = {
	{"ACPI0C50", 0 },
	{"PNP0C50", 0 },
	{ },
};
MODULE_DEVICE_TABLE(acpi, i2c_hid_acpi_match);
#else
static inline int i2c_hid_acpi_pdata(struct i2c_client *client,
		struct i2c_hid_platform_data *pdata)
{
	return -ENODEV;
}
917 918

static inline void i2c_hid_acpi_fix_up_power(struct device *dev) {}
M
Mika Westerberg 已提交
919 920
#endif

921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956
#ifdef CONFIG_OF
static int i2c_hid_of_probe(struct i2c_client *client,
		struct i2c_hid_platform_data *pdata)
{
	struct device *dev = &client->dev;
	u32 val;
	int ret;

	ret = of_property_read_u32(dev->of_node, "hid-descr-addr", &val);
	if (ret) {
		dev_err(&client->dev, "HID register address not provided\n");
		return -ENODEV;
	}
	if (val >> 16) {
		dev_err(&client->dev, "Bad HID register address: 0x%08x\n",
			val);
		return -EINVAL;
	}
	pdata->hid_descriptor_address = val;

	return 0;
}

static const struct of_device_id i2c_hid_of_match[] = {
	{ .compatible = "hid-over-i2c" },
	{},
};
MODULE_DEVICE_TABLE(of, i2c_hid_of_match);
#else
static inline int i2c_hid_of_probe(struct i2c_client *client,
		struct i2c_hid_platform_data *pdata)
{
	return -ENODEV;
}
#endif

957 958 959 960 961 962 963 964 965 966
static void i2c_hid_fwnode_probe(struct i2c_client *client,
				 struct i2c_hid_platform_data *pdata)
{
	u32 val;

	if (!device_property_read_u32(&client->dev, "post-power-on-delay-ms",
				      &val))
		pdata->post_power_delay_ms = val;
}

967 968
static int i2c_hid_probe(struct i2c_client *client,
			 const struct i2c_device_id *dev_id)
969 970 971 972 973 974 975 976 977
{
	int ret;
	struct i2c_hid *ihid;
	struct hid_device *hid;
	__u16 hidRegister;
	struct i2c_hid_platform_data *platform_data = client->dev.platform_data;

	dbg_hid("HID probe called for i2c 0x%02x\n", client->addr);

978 979 980 981 982 983
	if (!client->irq) {
		dev_err(&client->dev,
			"HID over i2c has not been provided an Int IRQ\n");
		return -EINVAL;
	}

984 985 986 987 988 989 990
	if (client->irq < 0) {
		if (client->irq != -EPROBE_DEFER)
			dev_err(&client->dev,
				"HID over i2c doesn't have a valid IRQ\n");
		return client->irq;
	}

991 992 993 994
	ihid = kzalloc(sizeof(struct i2c_hid), GFP_KERNEL);
	if (!ihid)
		return -ENOMEM;

995 996 997 998 999
	if (client->dev.of_node) {
		ret = i2c_hid_of_probe(client, &ihid->pdata);
		if (ret)
			goto err;
	} else if (!platform_data) {
M
Mika Westerberg 已提交
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
		ret = i2c_hid_acpi_pdata(client, &ihid->pdata);
		if (ret) {
			dev_err(&client->dev,
				"HID register address not provided\n");
			goto err;
		}
	} else {
		ihid->pdata = *platform_data;
	}

1010 1011 1012
	/* Parse platform agnostic common properties from ACPI / device tree */
	i2c_hid_fwnode_probe(client, &ihid->pdata);

1013 1014 1015 1016 1017 1018
	ihid->pdata.supply = devm_regulator_get(&client->dev, "vdd");
	if (IS_ERR(ihid->pdata.supply)) {
		ret = PTR_ERR(ihid->pdata.supply);
		if (ret != -EPROBE_DEFER)
			dev_err(&client->dev, "Failed to get regulator: %d\n",
				ret);
1019
		goto err;
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
	}

	ret = regulator_enable(ihid->pdata.supply);
	if (ret < 0) {
		dev_err(&client->dev, "Failed to enable regulator: %d\n",
			ret);
		goto err;
	}
	if (ihid->pdata.post_power_delay_ms)
		msleep(ihid->pdata.post_power_delay_ms);

1031 1032 1033 1034
	i2c_set_clientdata(client, ihid);

	ihid->client = client;

M
Mika Westerberg 已提交
1035
	hidRegister = ihid->pdata.hid_descriptor_address;
1036 1037 1038
	ihid->wHIDDescRegister = cpu_to_le16(hidRegister);

	init_waitqueue_head(&ihid->wait);
1039
	mutex_init(&ihid->reset_lock);
1040 1041 1042 1043

	/* we need to allocate the command buffer without knowing the maximum
	 * size of the reports. Let's use HID_MIN_BUFFER_SIZE, then we do the
	 * real computation later. */
1044 1045
	ret = i2c_hid_alloc_buffers(ihid, HID_MIN_BUFFER_SIZE);
	if (ret < 0)
1046
		goto err_regulator;
1047

1048 1049
	i2c_hid_acpi_fix_up_power(&client->dev);

1050 1051 1052
	pm_runtime_get_noresume(&client->dev);
	pm_runtime_set_active(&client->dev);
	pm_runtime_enable(&client->dev);
1053
	device_enable_async_suspend(&client->dev);
1054

1055 1056
	ret = i2c_hid_fetch_hid_descriptor(ihid);
	if (ret < 0)
1057
		goto err_pm;
1058 1059 1060

	ret = i2c_hid_init_irq(client);
	if (ret < 0)
1061
		goto err_pm;
1062 1063 1064 1065

	hid = hid_allocate_device();
	if (IS_ERR(hid)) {
		ret = PTR_ERR(hid);
1066
		goto err_irq;
1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078
	}

	ihid->hid = hid;

	hid->driver_data = client;
	hid->ll_driver = &i2c_hid_ll_driver;
	hid->dev.parent = &client->dev;
	hid->bus = BUS_I2C;
	hid->version = le16_to_cpu(ihid->hdesc.bcdVersion);
	hid->vendor = le16_to_cpu(ihid->hdesc.wVendorID);
	hid->product = le16_to_cpu(ihid->hdesc.wProductID);

1079
	snprintf(hid->name, sizeof(hid->name), "%s %04hX:%04hX",
1080
		 client->name, hid->vendor, hid->product);
1081
	strlcpy(hid->phys, dev_name(&client->dev), sizeof(hid->phys));
1082

1083 1084
	ihid->quirks = i2c_hid_lookup_quirk(hid->vendor, hid->product);

1085 1086 1087 1088 1089 1090 1091
	ret = hid_add_device(hid);
	if (ret) {
		if (ret != -ENODEV)
			hid_err(client, "can't add hid device: %d\n", ret);
		goto err_mem_free;
	}

1092
	pm_runtime_put(&client->dev);
1093 1094 1095 1096 1097
	return 0;

err_mem_free:
	hid_destroy_device(hid);

1098
err_irq:
1099
	free_irq(client->irq, ihid);
1100

1101 1102 1103 1104
err_pm:
	pm_runtime_put_noidle(&client->dev);
	pm_runtime_disable(&client->dev);

1105 1106 1107
err_regulator:
	regulator_disable(ihid->pdata.supply);

1108
err:
1109
	i2c_hid_free_buffers(ihid);
1110 1111 1112 1113
	kfree(ihid);
	return ret;
}

1114
static int i2c_hid_remove(struct i2c_client *client)
1115 1116 1117 1118
{
	struct i2c_hid *ihid = i2c_get_clientdata(client);
	struct hid_device *hid;

1119 1120 1121 1122 1123
	pm_runtime_get_sync(&client->dev);
	pm_runtime_disable(&client->dev);
	pm_runtime_set_suspended(&client->dev);
	pm_runtime_put_noidle(&client->dev);

1124 1125 1126
	hid = ihid->hid;
	hid_destroy_device(hid);

1127
	free_irq(client->irq, ihid);
1128

1129 1130 1131
	if (ihid->bufsize)
		i2c_hid_free_buffers(ihid);

1132 1133
	regulator_disable(ihid->pdata.supply);

1134 1135 1136 1137 1138
	kfree(ihid);

	return 0;
}

1139 1140 1141 1142 1143 1144 1145 1146
static void i2c_hid_shutdown(struct i2c_client *client)
{
	struct i2c_hid *ihid = i2c_get_clientdata(client);

	i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
	free_irq(client->irq, ihid);
}

1147 1148 1149 1150
#ifdef CONFIG_PM_SLEEP
static int i2c_hid_suspend(struct device *dev)
{
	struct i2c_client *client = to_i2c_client(dev);
1151 1152
	struct i2c_hid *ihid = i2c_get_clientdata(client);
	struct hid_device *hid = ihid->hid;
1153
	int ret;
1154
	int wake_status;
1155

1156 1157 1158 1159 1160 1161 1162 1163 1164
	if (hid->driver && hid->driver->suspend) {
		/*
		 * Wake up the device so that IO issues in
		 * HID driver's suspend code can succeed.
		 */
		ret = pm_runtime_resume(dev);
		if (ret < 0)
			return ret;

1165
		ret = hid->driver->suspend(hid, PMSG_SUSPEND);
1166 1167 1168 1169 1170 1171 1172 1173
		if (ret < 0)
			return ret;
	}

	if (!pm_runtime_suspended(dev)) {
		/* Save some power */
		i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);

1174
		disable_irq(client->irq);
1175
	}
1176

1177
	if (device_may_wakeup(&client->dev)) {
1178
		wake_status = enable_irq_wake(client->irq);
1179 1180 1181 1182 1183
		if (!wake_status)
			ihid->irq_wake_enabled = true;
		else
			hid_warn(hid, "Failed to enable irq wake: %d\n",
				wake_status);
1184 1185 1186 1187
	} else {
		ret = regulator_disable(ihid->pdata.supply);
		if (ret < 0)
			hid_warn(hid, "Failed to disable supply: %d\n", ret);
1188
	}
1189

1190
	return 0;
1191 1192 1193 1194 1195 1196
}

static int i2c_hid_resume(struct device *dev)
{
	int ret;
	struct i2c_client *client = to_i2c_client(dev);
1197 1198
	struct i2c_hid *ihid = i2c_get_clientdata(client);
	struct hid_device *hid = ihid->hid;
1199
	int wake_status;
1200

1201 1202 1203 1204 1205 1206 1207
	if (!device_may_wakeup(&client->dev)) {
		ret = regulator_enable(ihid->pdata.supply);
		if (ret < 0)
			hid_warn(hid, "Failed to enable supply: %d\n", ret);
		if (ihid->pdata.post_power_delay_ms)
			msleep(ihid->pdata.post_power_delay_ms);
	} else if (ihid->irq_wake_enabled) {
1208
		wake_status = disable_irq_wake(client->irq);
1209 1210 1211 1212 1213 1214
		if (!wake_status)
			ihid->irq_wake_enabled = false;
		else
			hid_warn(hid, "Failed to disable irq wake: %d\n",
				wake_status);
	}
1215

1216 1217 1218 1219 1220
	/* We'll resume to full power */
	pm_runtime_disable(dev);
	pm_runtime_set_active(dev);
	pm_runtime_enable(dev);

1221
	enable_irq(client->irq);
1222 1223 1224 1225
	ret = i2c_hid_hwreset(client);
	if (ret)
		return ret;

1226 1227 1228 1229 1230 1231
	/* RAYDIUM device (2386:3118) need to re-send report descr cmd
	 * after resume, after this it will be back normal.
	 * otherwise it issues too many incomplete reports.
	 */
	if (ihid->quirks & I2C_HID_QUIRK_RESEND_REPORT_DESCR) {
		ret = i2c_hid_command(client, &hid_report_descr_cmd, NULL, 0);
1232
		if (ret)
1233 1234 1235
			return ret;
	}

1236 1237 1238 1239 1240
	if (hid->driver && hid->driver->reset_resume) {
		ret = hid->driver->reset_resume(hid);
		return ret;
	}

1241 1242 1243 1244
	return 0;
}
#endif

1245
#ifdef CONFIG_PM
1246 1247 1248 1249 1250
static int i2c_hid_runtime_suspend(struct device *dev)
{
	struct i2c_client *client = to_i2c_client(dev);

	i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
1251
	disable_irq(client->irq);
1252 1253 1254 1255 1256 1257 1258
	return 0;
}

static int i2c_hid_runtime_resume(struct device *dev)
{
	struct i2c_client *client = to_i2c_client(dev);

1259
	enable_irq(client->irq);
1260 1261 1262 1263 1264 1265 1266 1267 1268 1269
	i2c_hid_set_power(client, I2C_HID_PWR_ON);
	return 0;
}
#endif

static const struct dev_pm_ops i2c_hid_pm = {
	SET_SYSTEM_SLEEP_PM_OPS(i2c_hid_suspend, i2c_hid_resume)
	SET_RUNTIME_PM_OPS(i2c_hid_runtime_suspend, i2c_hid_runtime_resume,
			   NULL)
};
1270 1271

static const struct i2c_device_id i2c_hid_id_table[] = {
B
Benjamin Tissoires 已提交
1272
	{ "hid", 0 },
1273
	{ "hid-over-i2c", 0 },
1274 1275 1276 1277 1278 1279 1280 1281 1282
	{ },
};
MODULE_DEVICE_TABLE(i2c, i2c_hid_id_table);


static struct i2c_driver i2c_hid_driver = {
	.driver = {
		.name	= "i2c_hid",
		.pm	= &i2c_hid_pm,
M
Mika Westerberg 已提交
1283
		.acpi_match_table = ACPI_PTR(i2c_hid_acpi_match),
1284
		.of_match_table = of_match_ptr(i2c_hid_of_match),
1285 1286 1287
	},

	.probe		= i2c_hid_probe,
1288
	.remove		= i2c_hid_remove,
1289
	.shutdown	= i2c_hid_shutdown,
1290 1291 1292 1293 1294 1295 1296 1297
	.id_table	= i2c_hid_id_table,
};

module_i2c_driver(i2c_hid_driver);

MODULE_DESCRIPTION("HID over I2C core driver");
MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
MODULE_LICENSE("GPL");