Re: [PATCH v1] Support Elan Touchscreen eKTF product.

2012-10-22 Thread Jian-Jhong Ding
Dmitry Torokhov dmitry.torok...@gmail.com writes:
 On Mon, Oct 22, 2012 at 11:47:42AM +0800, Jian-Jhong Ding wrote:
 With Benjamin's i2c-hid implimentation, is it possible to make
 hid-multitouch not depend on USBHID and reuse it to drive this device?

 Exactly. Before looking any further - is this the same part that Tom Lin
 posted a driver for earlier this summer?

No.  Tom's driver was only for trackpads, this is probably for some
touch panel.  The controller ICs may have some similarities, but the
firmware is developed independently, though both somewhat conform to the
HID over I2C protocol.

Thanks,
-JJ
 Thanks.

 -- 
 Dmitry
--
To unsubscribe from this list: send the line unsubscribe linux-i2c in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2] i2c-hid: introduce HID over i2c specification implementation

2012-10-18 Thread Jian-Jhong Ding
Hi Benjamin,

Some suggestions to make the error messages more human, and a little
question on the return value of i2c_hid_fetch_hid_descriptor.  Please see below:

Benjamin Tissoires benjamin.tissoi...@gmail.com writes:
 diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c
 new file mode 100644
 index 000..8b6c31a
 --- /dev/null
 +++ b/drivers/hid/i2c-hid/i2c-hid.c
 @@ -0,0 +1,990 @@
 +/*
 + * HID over I2C protocol implementation
 + *
 + * Copyright (c) 2012 Benjamin Tissoires benjamin.tissoi...@gmail.com
 + * Copyright (c) 2012 Ecole Nationale de l'Aviation Civile, France
 + *
 + * This code is partly based on USB HID support for Linux:
 + *
 + *  Copyright (c) 1999 Andreas Gal
 + *  Copyright (c) 2000-2005 Vojtech Pavlik vojt...@suse.cz
 + *  Copyright (c) 2005 Michael Haboustak mi...@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
 +#include linux/delay.h
 +#include linux/slab.h
 +#include linux/pm.h
 +#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/bug.h
 +#include linux/hid.h
 +
 +#include linux/i2c/i2c-hid.h
 +
 +/* flags */
 +#define I2C_HID_STARTED  (1  0)
 +#define I2C_HID_RESET_PENDING(1  1)
 +#define I2C_HID_READ_PENDING (1  2)
 +
 +#define I2C_HID_PWR_ON   0x00
 +#define I2C_HID_PWR_SLEEP0x01
 +
 +/* debug option */
 +static bool debug = false;
 +module_param(debug, bool, 0444);
 +MODULE_PARM_DESC(debug, print a lot of debug information);
 +
 +#define i2c_hid_dbg(ihid, fmt, arg...)   \
 + if (debug)  \
 + dev_printk(KERN_DEBUG, (ihid)-client-dev, fmt, ##arg)
 +
 +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;
 +} __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_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) };
 +static const struct i2c_hid_cmd hid_set_power_cmd =  { I2C_HID_CMD(0x08) };
 +/* read/write data register */
 +static const struct i2c_hid_cmd hid_data_cmd = {
 + .registerIndex = offsetof(struct i2c_hid_desc, wDataRegister),
 + .opcode = 0x00,
 + .length = 2 };
 +/* write output reports */
 +static const struct i2c_hid_cmd hid_out_cmd = {
 + .registerIndex = offsetof(struct i2c_hid_desc,
 + wOutputRegister),
 + .opcode = 0x00,
 + .length = 2 };
 +
 +/* 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
 +   

Re: [PATCH v2] i2c-hid: introduce HID over i2c specification implementation

2012-10-18 Thread Jian-Jhong Ding
Benjamin Tissoires benjamin.tissoi...@gmail.com writes:
 Hi JJ,

 On Thu, Oct 18, 2012 at 11:07 AM, Jian-Jhong Ding jj_d...@emc.com.tw wrote:
 Hi Benjamin,

 Some suggestions to make the error messages more human, and a little
 question on the return value of i2c_hid_fetch_hid_descriptor.  Please see 
 below:

 I fully agree with the more human error messages.

 However, for i2c_hid_fetch_hid_descriptor return values, I'm affraid I
 can't use -EINVAL.

 Jean Delvare (one of the i2c maintainers) told in his review of the v1:
 
 These should all be -ENODEV in this function
 [i2c_hid_fetch_hid_descriptor]: the device isn't what you
 expected. EINVAL is for invalid argument.
 

I must have missed that mail.  Thank you for pointing this out.

-JJ

 So ENODEV is the right return value.

 Anyway, thanks for the review.

 Cheers,
 Benjamin
--
To unsubscribe from this list: send the line unsubscribe linux-i2c in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v1] i2c-hid: introduce HID over i2c specification implementation

2012-10-02 Thread Jian-Jhong Ding
Hi Benjamin,

I have one little question about __i2chid_command(), please see below.

benjamin.tissoires benjamin.tissoi...@gmail.com writes:
 From: Benjamin Tissoires benjamin.tissoi...@enac.fr

 Microsoft published the protocol specification of HID over i2c:
 http://msdn.microsoft.com/en-us/library/windows/hardware/hh852380.aspx

 This patch introduces an implementation of this protocol.

 This implementation does not includes the ACPI part of the specification.
 This will come when ACPI 5.0 devices will be available.

 Once the ACPI part will be done, OEM will not have to declare HID over I2C
 devices in their platform specific driver.

 Signed-off-by: Benjamin Tissoires benjamin.tissoi...@enac.fr
 ---

 Hi,

 this is finally my first implementation of HID over I2C.

 This has been tested on an Elan Microelectronics HID over I2C device, with
 a Samsung Exynos 4412 board.

 Any comments are welcome.

 Cheers,
 Benjamin

  drivers/i2c/Kconfig |8 +
  drivers/i2c/Makefile|1 +
  drivers/i2c/i2c-hid.c   | 1027 
 +++
  include/linux/i2c/i2c-hid.h |   35 ++
  4 files changed, 1071 insertions(+)
  create mode 100644 drivers/i2c/i2c-hid.c
  create mode 100644 include/linux/i2c/i2c-hid.h

 diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
 index 5a3bb3d..5adf65a 100644
 --- a/drivers/i2c/Kconfig
 +++ b/drivers/i2c/Kconfig
 @@ -47,6 +47,14 @@ config I2C_CHARDEV
 This support is also available as a module.  If so, the module 
 will be called i2c-dev.
  
 +config I2C_HID
 + tristate HID over I2C bus
 + help
 +   Say Y here to use the HID over i2c protocol implementation.
 +
 +   This support is also available as a module.  If so, the module
 +   will be called i2c-hid.
 +
  config I2C_MUX
   tristate I2C bus multiplexing support
   help
 diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
 index beee6b2..8f38116 100644
 --- a/drivers/i2c/Makefile
 +++ b/drivers/i2c/Makefile
 @@ -6,6 +6,7 @@ obj-$(CONFIG_I2C_BOARDINFO)   += i2c-boardinfo.o
  obj-$(CONFIG_I2C)+= i2c-core.o
  obj-$(CONFIG_I2C_SMBUS)  += i2c-smbus.o
  obj-$(CONFIG_I2C_CHARDEV)+= i2c-dev.o
 +obj-$(CONFIG_I2C_HID)+= i2c-hid.o
  obj-$(CONFIG_I2C_MUX)+= i2c-mux.o
  obj-y+= algos/ busses/ muxes/
  
 diff --git a/drivers/i2c/i2c-hid.c b/drivers/i2c/i2c-hid.c
 new file mode 100644
 index 000..eb17d8c
 --- /dev/null
 +++ b/drivers/i2c/i2c-hid.c
 @@ -0,0 +1,1027 @@
 +/*
 + * HID over I2C protocol implementation
 + *
 + * Copyright (c) 2012 Benjamin Tissoires benjamin.tissoi...@gmail.com
 + * Copyright (c) 2012 Ecole Nationale de l'Aviation Civile, France
 + *
 + * This code is partly based on USB HID support for Linux:
 + *
 + *  Copyright (c) 1999 Andreas Gal
 + *  Copyright (c) 2000-2005 Vojtech Pavlik vojt...@suse.cz
 + *  Copyright (c) 2005 Michael Haboustak mi...@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/irq.h
 +#include linux/gpio.h
 +#include linux/interrupt.h
 +#include linux/input.h
 +#include linux/delay.h
 +#include linux/slab.h
 +#include linux/pm.h
 +
 +#include linux/i2c/i2c-hid.h
 +
 +#include linux/hid.h
 +#include linux/hiddev.h
 +#include linux/hidraw.h
 +
 +#define DRIVER_NAME  i2chid
 +#define DRIVER_DESC  HID over I2C core driver
 +
 +#define I2C_HID_COMMAND_TRIES3
 +
 +/* flags */
 +#define I2C_HID_STARTED  (1  0)
 +#define I2C_HID_OUT_RUNNING  (1  1)
 +#define I2C_HID_IN_RUNNING   (1  2)
 +#define I2C_HID_RESET_PENDING(1  3)
 +#define I2C_HID_SUSPENDED(1  4)
 +
 +#define I2C_HID_PWR_ON   0x00
 +#define I2C_HID_PWR_SLEEP0x01
 +
 +/* debug option */
 +static bool debug = false;
 +module_param(debug, bool, 0444);
 +MODULE_PARM_DESC(debug, print a lot of debug informations);
 +
 +struct i2chid_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;
 +} __packed;
 +
 +struct i2chid_cmd {
 + enum {
 + /* fecth HID descriptor */
 + HID_DESCR_CMD,
 +
 + /* fetch report descriptors */
 + HID_REPORT_DESCR_CMD,
 +
 + /* commands */
 + HID_RESET_CMD,
 + HID_GET_REPORT_CMD,
 + HID_SET_REPORT_CMD,
 +