Fix for Dell P57G touchpad found, need advice on patch

2015-09-11 Thread Pavel Roskin
Hi!

I'm using Dell Inspiron 13, model P57G. It has a problem with the
touchpad under Linux. Approximately half of the time, the touchpad is
not working at all - the mouse cursor is not moving. In this case,
there are error messages written to the kernel log every second:

[   53.127339] i2c_designware INT3433:00: controller timed out
[   54.219336] i2c_designware INT3433:00: controller timed out
[   55.311346] i2c_designware INT3433:00: controller timed out
[   56.403326] i2c_designware INT3433:00: controller timed out

There is a simple fix - blacklist the driver
(i2c_designware_platform). In this case, the touchpad words as a mouse
and used IRQ 12. Googling for "blackist i2c_designware_platform" shows
that I'm not the one using that approach.

I started looking at the driver in git. A patch by Romain Baeriswyl
applied on 2014-08-20 adds support for the "standard" mode with the
100kHz clock, as opposed to the 400kHz "fast" mode. Unfortunately,
that patch only affects OpenFirmware systems, and I have ACPI. As soon
as I set the clock to 100kHz, the touchpad started working every time.

One fix would be to have a module parameter to force slower clock. It
would still require users to deal with modprobe, so it's not optimal.

I noticed that dev->get_clk_rate_khz(dev) returns 10, but that
would be 10kHz = 100MHz. Not sure is somebody confused the units
or it's the correct clock.

Considering that I have no other systems to test, what would be the
best approach? Set the clock to 100kHz for INT3433? Recognize Dell
P57G system specifically? How? Preserve the original clock by reading
the DW_IC_CON register and keeping some bits?

Pavel
--
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: [RESEND PATCH v4 0/8] i2c: Relax mandatory I2C ID table passing

2015-09-11 Thread Lee Jones
On Fri, 11 Sep 2015, Kieran Bingham wrote:
> Hi Wolfram,
> 
> I have picked this patchset [0] up from Lee to rebase it, with an aim to
> get this series moving again.
> 
> This resend fixes up my SoB's as highlighted by Lee
> 
> A couple of minor issues were resolved in the rebase. As it stood, Javier
> proposed [1] to merge this series, and use a follow up series to make sure
> that all I2C drivers are using a MODLE_DEVICE_TABLE(of,...)
> 
> I have prepared a Coccinelle patch to work through the bulk of the changes
> required for the conversion, which will assist the transition process.
> 
> Once this patch set is accepted, I will commence converting the other
> drivers, and submitting with a per subsystem breakdown or simliar to
> reduce traffic.
> 
> [0] https://lkml.org/lkml/2014/8/28/283
> [1] https://lkml.org/lkml/2014/9/12/496

I appreciate that my SoB is on every patch, but this set still looks
good to me, so for extra clarification:

Acked-by: Lee Jones 

[...]

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
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 1/2] i2c-tools: add new tool 'i2ctransfer'

2015-09-11 Thread Jean Delvare
Hi Wolfram,

On Fri, 19 Jun 2015 12:40:31 +0200, Wolfram Sang wrote:
> From: Wolfram Sang 
> 
> This tool allows to construct and concat multiple I2C messages into one
> single transfer. Its aim is to test I2C master controllers, and so there
> is no SMBus fallback.

Which is fine. That wouldn't make much sense anyway as not all I2C
transactions fit into the SMBus set. For SMBus transactions we already
have i2cdump, i2cget and i2cset.

> I've been missing such a tool a number of times now, so I finally got
> around to writing it myself. As with all I2C tools, it can be dangerous,
> but it can also be very useful when developing. I am not sure if distros
> should supply it, I'll leave that to Jean's experience. For embedded
> build systems, I think this should be selectable.

I think it can be included together with the other tools. It's just as
dangerous a tool as the other ones, not more. The fact that it can't be
used on SMBus-only controllers even kind of makes it less dangerous.

> Tested with various Renesas I2C IP cores as well as Tegra and AT91.
> 
> Signed-off-by: Wolfram Sang 

Not needed for i2c-tools contributions.

> ---
>  tools/Module.mk |   8 +-
>  tools/i2ctransfer.c | 320 
> 
>
>  2 files changed, 327 insertions(+), 1 deletion(-)
>  create mode 100644 tools/i2ctransfer.c

Where is the manual page? We need one, it's mandatory for some
distributions. And "make install" currently fails because
tools/i2ctransfer.8 is missing.

While this is not kernel code, I would recommend that you run the
kernel's scripts/checkpatch.pl on tools/i2ctransfer.c. Most of the
problems reported are relevant and fixing them would improve
readability.

Overall it looks really good. I made a lot of comments below but most
of them only express my preference and you are free to ignore them if
you disagree.

> diff --git a/tools/Module.mk b/tools/Module.mk
> index 641ac81..7192361 100644
> --- a/tools/Module.mk
> +++ b/tools/Module.mk
> @@ -18,7 +18,7 @@ else
>  TOOLS_LDFLAGS+= -Llib -li2c
>  endif
>  
> -TOOLS_TARGETS:= i2cdetect i2cdump i2cset i2cget
> +TOOLS_TARGETS:= i2cdetect i2cdump i2cset i2cget i2ctransfer
>  
>  #
>  # Programs
> @@ -36,6 +36,9 @@ $(TOOLS_DIR)/i2cset: $(TOOLS_DIR)/i2cset.o 
> $(TOOLS_DIR)/i2cbusses.o $(TOOLS_DIR)
>  $(TOOLS_DIR)/i2cget: $(TOOLS_DIR)/i2cget.o $(TOOLS_DIR)/i2cbusses.o 
> $(TOOLS_DIR)/util.o
>   $(CC) $(LDFLAGS) -o $@ $^ $(TOOLS_LDFLAGS)
>  
> +$(TOOLS_DIR)/i2ctransfer: $(TOOLS_DIR)/i2ctransfer.o 
> $(TOOLS_DIR)/i2cbusses.o $(TOOLS_DIR)/util.o
> + $(CC) $(LDFLAGS) -o $@ $^ $(TOOLS_LDFLAGS)
> +
>  #
>  # Objects
>  #
> @@ -52,6 +55,9 @@ $(TOOLS_DIR)/i2cset.o: $(TOOLS_DIR)/i2cset.c 
> $(TOOLS_DIR)/i2cbusses.h $(TOOLS_DI
>  $(TOOLS_DIR)/i2cget.o: $(TOOLS_DIR)/i2cget.c $(TOOLS_DIR)/i2cbusses.h 
> $(TOOLS_DIR)/util.h version.h $(INCLUDE_DIR)/i2c/smbus.h
>   $(CC) $(CFLAGS) $(TOOLS_CFLAGS) -c $< -o $@
>  
> +$(TOOLS_DIR)/i2ctransfer.o: $(TOOLS_DIR)/i2ctransfer.c 
> $(TOOLS_DIR)/i2cbusses.h $(TOOLS_DIR)/util.h version.h
> + $(CC) $(CFLAGS) $(TOOLS_CFLAGS) -c $< -o $@
> +
>  $(TOOLS_DIR)/i2cbusses.o: $(TOOLS_DIR)/i2cbusses.c $(TOOLS_DIR)/i2cbusses.h
>   $(CC) $(CFLAGS) $(TOOLS_CFLAGS) -c $< -o $@
>  
> diff --git a/tools/i2ctransfer.c b/tools/i2ctransfer.c
> new file mode 100644
> index 000..27f4d7a
> --- /dev/null
> +++ b/tools/i2ctransfer.c
> @@ -0,0 +1,320 @@
> +/*
> +i2ctransfer.c - A user-space program to send concatenated i2c messages
> +Copyright (C) 2015 Wolfram Sang 
> +Copyright (C) 2015 Renesas Electronics Corporation
> +
> +Based on i2cget.c:
> +Copyright (C) 2005-2012  Jean Delvare 
> +
> +which is based on i2cset.c:
> +Copyright (C) 2001-2003  Frodo Looijaard , and
> + Mark D. Studebaker 
> +Copyright (C) 2004-2005  Jean Delvare

I think you can skip this. If anyone really cares, it's already
mentioned in i2cget.c.

> +
> +This program is free software; you can redistribute it and/or modify
> +it under the terms of the GNU General Public License as published by
> +the Free Software Foundation; either version 2 of the License, or
> +(at your option) any later version.
> +
> +This program is distributed in the hope that it will be useful,
> +but WITHOUT ANY WARRANTY; without even the implied warranty of
> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +GNU General Public License for more details.
> +*/
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include "i2cbusses.h"
> +#include "util.h"
> +#include "../version.h"
> +
> +enum parse_state {
> + PARSE_GET_DESC,
> + PARSE_GET_DATA

There should be a trailing comma, in case you ever need to add a 

Re: [PATCH v4 1/8] i2c: Add pointer dereference protection to i2c_match_id()

2015-09-11 Thread Kieran Bingham
Hi Lee,

On 11 September 2015 at 10:31, Lee Jones  wrote:
> On Wed, 09 Sep 2015, Kieran Bingham wrote:
>
>> From: Lee Jones 
>>
>> Here we're providing dereference protection for i2c_match_id(), which
>> saves us having to do it each time it's called.  We're also stripping
>> out the (now) needless checks in i2c_device_match().  This patch paves
>> the way for other, similar code trimming.
>>
>> Acked-by: Grant Likely 
>> Signed-off-by: Lee Jones 
>
> SoB?


My apologies, I only added SOB to the patches I had modified ...
I didn't realise it should go on the ones I didn't touch as well.

I'll update and resend.

--
Regards

>
>> ---
>>  drivers/i2c/i2c-core.c | 12 +++-
>>  1 file changed, 7 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
>> index c83e4d1..30d8a77 100644
>> --- a/drivers/i2c/i2c-core.c
>> +++ b/drivers/i2c/i2c-core.c
>> @@ -450,6 +450,9 @@ static inline int acpi_i2c_install_space_handler(struct 
>> i2c_adapter *adapter)
>>  static const struct i2c_device_id *i2c_match_id(const struct i2c_device_id 
>> *id,
>>   const struct i2c_client 
>> *client)
>>  {
>> + if (!(id && client))
>> + return NULL;
>> +
>>   while (id->name[0]) {
>>   if (strcmp(client->name, id->name) == 0)
>>   return id;
>> @@ -463,8 +466,6 @@ static int i2c_device_match(struct device *dev, struct 
>> device_driver *drv)
>>   struct i2c_client   *client = i2c_verify_client(dev);
>>   struct i2c_driver   *driver;
>>
>> - if (!client)
>> - return 0;
>>
>>   /* Attempt an OF style match */
>>   if (of_driver_match_device(dev, drv))
>> @@ -475,9 +476,10 @@ static int i2c_device_match(struct device *dev, struct 
>> device_driver *drv)
>>   return 1;
>>
>>   driver = to_i2c_driver(drv);
>> - /* match on an id table if there is one */
>> - if (driver->id_table)
>> - return i2c_match_id(driver->id_table, client) != NULL;
>> +
>> + /* Finally an I2C match */
>> + if (i2c_match_id(driver->id_table, client))
>> + return 1;
>>
>>   return 0;
>>  }
>
> --
> Lee Jones
> Linaro STMicroelectronics Landing Team Lead
> Linaro.org │ Open source software for ARM SoCs
> Follow Linaro: Facebook | Twitter | Blog
--
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 v4 5/8] i2c: Export i2c_match_id() for direct use by device drivers

2015-09-11 Thread Lee Jones
On Wed, 09 Sep 2015, Kieran Bingham wrote:

> From: Lee Jones 
> 
> When there was no other way to match a I2C device to driver i2c_match_id()
> was exclusively used.  However, now there are other types of tables which
> are commonly supplied, matching on an i2c_device_id table is used less
> frequently.  Instead of _always_ calling i2c_match_id() from within the
> framework, we only need to do so from drivers which have no other way of
> matching.  This patch makes i2c_match_id() available to the aforementioned
> device drivers.
> 
> Acked-by: Grant Likely 
> Signed-off-by: Lee Jones 

SoB?

> ---
>  drivers/i2c/i2c-core.c | 3 ++-
>  include/linux/i2c.h| 2 ++
>  2 files changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> index 2ebc64d..0e40136 100644
> --- a/drivers/i2c/i2c-core.c
> +++ b/drivers/i2c/i2c-core.c
> @@ -447,7 +447,7 @@ static inline int acpi_i2c_install_space_handler(struct 
> i2c_adapter *adapter)
>  
>  /* - 
> */
>  
> -static const struct i2c_device_id *i2c_match_id(const struct i2c_device_id 
> *id,
> +const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,
>   const struct i2c_client *client)
>  {
>   if (!(id && client))
> @@ -460,6 +460,7 @@ static const struct i2c_device_id *i2c_match_id(const 
> struct i2c_device_id *id,
>   }
>   return NULL;
>  }
> +EXPORT_SYMBOL_GPL(i2c_match_id);
>  
>  static int i2c_device_match(struct device *dev, struct device_driver *drv)
>  {
> diff --git a/include/linux/i2c.h b/include/linux/i2c.h
> index 48bbbab..126585c 100644
> --- a/include/linux/i2c.h
> +++ b/include/linux/i2c.h
> @@ -232,6 +232,8 @@ struct i2c_client {
>  
>  extern struct i2c_client *i2c_verify_client(struct device *dev);
>  extern struct i2c_adapter *i2c_verify_adapter(struct device *dev);
> +extern const struct i2c_device_id *i2c_match_id(const struct i2c_device_id 
> *id,
> + const struct i2c_client *client);
>  
>  static inline struct i2c_client *kobj_to_i2c_client(struct kobject *kobj)
>  {

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
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 v4 7/8] mfd: 88pm860x: Move over to new I2C device .probe() call

2015-09-11 Thread Lee Jones
On Wed, 09 Sep 2015, Kieran Bingham wrote:

> From: Lee Jones 
> 
> As part of an effort to rid the mostly unused second parameter for I2C
> related .probe() functions and to conform to other existing frameworks
> we're moving over to a temporary replacement .probe() call-back.
> 
> Acked-by: Grant Likely 
> Signed-off-by: Lee Jones 

SoB?

> ---
>  drivers/mfd/88pm860x-core.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/mfd/88pm860x-core.c b/drivers/mfd/88pm860x-core.c
> index 3269a99..a499d70 100644
> --- a/drivers/mfd/88pm860x-core.c
> +++ b/drivers/mfd/88pm860x-core.c
> @@ -1130,8 +1130,7 @@ static int pm860x_dt_init(struct device_node *np,
>   return 0;
>  }
>  
> -static int pm860x_probe(struct i2c_client *client,
> -   const struct i2c_device_id *id)
> +static int pm860x_probe(struct i2c_client *client)
>  {
>   struct pm860x_platform_data *pdata = dev_get_platdata(>dev);
>   struct device_node *node = client->dev.of_node;
> @@ -1257,7 +1256,7 @@ static struct i2c_driver pm860x_driver = {
>   .pm = _pm_ops,
>   .of_match_table = pm860x_dt_ids,
>   },
> - .probe  = pm860x_probe,
> + .probe2 = pm860x_probe,
>   .remove = pm860x_remove,
>   .id_table   = pm860x_id_table,
>  };

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
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 v4 8/8] mfd: as3722: Rid driver of superfluous I2C device ID structure

2015-09-11 Thread Lee Jones
On Wed, 09 Sep 2015, Kieran Bingham wrote:

> From: Lee Jones 
> 
> Also remove unused second probe() parameter 'i2c_device_id'.
> 
> Acked-by: Grant Likely 
> Signed-off-by: Lee Jones 

SoB?

> ---
>  drivers/mfd/as3722.c | 12 ++--
>  1 file changed, 2 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/mfd/as3722.c b/drivers/mfd/as3722.c
> index 924ea90..6ac4be3 100644
> --- a/drivers/mfd/as3722.c
> +++ b/drivers/mfd/as3722.c
> @@ -354,8 +354,7 @@ static int as3722_i2c_of_probe(struct i2c_client *i2c,
>   return 0;
>  }
>  
> -static int as3722_i2c_probe(struct i2c_client *i2c,
> - const struct i2c_device_id *id)
> +static int as3722_i2c_probe(struct i2c_client *i2c)
>  {
>   struct as3722 *as3722;
>   unsigned long irq_flags;
> @@ -428,20 +427,13 @@ static const struct of_device_id as3722_of_match[] = {
>  };
>  MODULE_DEVICE_TABLE(of, as3722_of_match);
>  
> -static const struct i2c_device_id as3722_i2c_id[] = {
> - { "as3722", 0 },
> - {},
> -};
> -MODULE_DEVICE_TABLE(i2c, as3722_i2c_id);
> -
>  static struct i2c_driver as3722_i2c_driver = {
>   .driver = {
>   .name = "as3722",
>   .of_match_table = as3722_of_match,
>   },
> - .probe = as3722_i2c_probe,
> + .probe2 = as3722_i2c_probe,
>   .remove = as3722_i2c_remove,
> - .id_table = as3722_i2c_id,
>  };
>  
>  module_i2c_driver(as3722_i2c_driver);

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
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 v4 3/8] i2c: Match using traditional OF methods, then by vendor-less compatible strings

2015-09-11 Thread Lee Jones
On Wed, 09 Sep 2015, Kieran Bingham wrote:

> From: Lee Jones 
> 
> This function provides a single call for all I2C devices which need to
> match firstly using traditional OF means i.e by of_node, then if that
> fails we attempt to match using the supplied I2C client name with a
> list of supplied compatible strings with the ',' string
> removed.  The latter is required due to the unruly naming conventions
> used currently by I2C devices.
> 
> Acked-by: Grant Likely 
> Signed-off-by: Lee Jones 

SoB?

> ---
>  drivers/i2c/i2c-core.c | 16 
>  include/linux/i2c.h| 12 
>  2 files changed, 28 insertions(+)
> 
> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> index 0788c1f..94ca76e 100644
> --- a/drivers/i2c/i2c-core.c
> +++ b/drivers/i2c/i2c-core.c
> @@ -1394,6 +1394,22 @@ i2c_of_match_device_strip_vendor(const struct 
> of_device_id *matches,
>   return NULL;
>  }
>  
> +const struct of_device_id
> +*i2c_of_match_device(const struct of_device_id *matches,
> +  struct i2c_client *client)
> +{
> + const struct of_device_id *match;
> +
> + if (!(client && matches))
> + return NULL;
> +
> + match = of_match_device(matches, >dev);
> + if (match)
> + return match;
> +
> + return i2c_of_match_device_strip_vendor(matches, client);
> +}
> +EXPORT_SYMBOL_GPL(i2c_of_match_device);
>  #else
>  static void of_i2c_register_devices(struct i2c_adapter *adap) { }
>  #endif /* CONFIG_OF */
> diff --git a/include/linux/i2c.h b/include/linux/i2c.h
> index e83a738..48bbbab 100644
> --- a/include/linux/i2c.h
> +++ b/include/linux/i2c.h
> @@ -638,6 +638,10 @@ extern struct i2c_client 
> *of_find_i2c_device_by_node(struct device_node *node);
>  /* must call put_device() when done with returned i2c_adapter device */
>  extern struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node 
> *node);
>  
> +extern const struct of_device_id
> +*i2c_of_match_device(const struct of_device_id *matches,
> +  struct i2c_client *client);
> +
>  #else
>  
>  static inline struct i2c_client *of_find_i2c_device_by_node(struct 
> device_node *node)
> @@ -649,6 +653,14 @@ static inline struct i2c_adapter 
> *of_find_i2c_adapter_by_node(struct device_node
>  {
>   return NULL;
>  }
> +
> +const struct of_device_id
> +*i2c_of_match_device(const struct of_device_id *matches,
> +  struct i2c_client *client)
> +{
> + return NULL;
> +}
> +
>  #endif /* CONFIG_OF */
>  
>  #endif /* _LINUX_I2C_H */

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
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 v4 1/8] i2c: Add pointer dereference protection to i2c_match_id()

2015-09-11 Thread Lee Jones
On Wed, 09 Sep 2015, Kieran Bingham wrote:

> From: Lee Jones 
> 
> Here we're providing dereference protection for i2c_match_id(), which
> saves us having to do it each time it's called.  We're also stripping
> out the (now) needless checks in i2c_device_match().  This patch paves
> the way for other, similar code trimming.
> 
> Acked-by: Grant Likely 
> Signed-off-by: Lee Jones 

SoB?

> ---
>  drivers/i2c/i2c-core.c | 12 +++-
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> index c83e4d1..30d8a77 100644
> --- a/drivers/i2c/i2c-core.c
> +++ b/drivers/i2c/i2c-core.c
> @@ -450,6 +450,9 @@ static inline int acpi_i2c_install_space_handler(struct 
> i2c_adapter *adapter)
>  static const struct i2c_device_id *i2c_match_id(const struct i2c_device_id 
> *id,
>   const struct i2c_client *client)
>  {
> + if (!(id && client))
> + return NULL;
> +
>   while (id->name[0]) {
>   if (strcmp(client->name, id->name) == 0)
>   return id;
> @@ -463,8 +466,6 @@ static int i2c_device_match(struct device *dev, struct 
> device_driver *drv)
>   struct i2c_client   *client = i2c_verify_client(dev);
>   struct i2c_driver   *driver;
>  
> - if (!client)
> - return 0;
>  
>   /* Attempt an OF style match */
>   if (of_driver_match_device(dev, drv))
> @@ -475,9 +476,10 @@ static int i2c_device_match(struct device *dev, struct 
> device_driver *drv)
>   return 1;
>  
>   driver = to_i2c_driver(drv);
> - /* match on an id table if there is one */
> - if (driver->id_table)
> - return i2c_match_id(driver->id_table, client) != NULL;
> +
> + /* Finally an I2C match */
> + if (i2c_match_id(driver->id_table, client))
> + return 1;
>  
>   return 0;
>  }

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
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 v4 4/8] i2c: Make I2C ID tables non-mandatory for DT'ed devices

2015-09-11 Thread Lee Jones
On Wed, 09 Sep 2015, Kieran Bingham wrote:

> From: Lee Jones 
> 
> Currently the I2C framework insists on devices supplying an I2C ID
> table.  Many of the devices which do so unnecessarily adding quite a
> few wasted lines to kernel code.  This patch allows drivers a means
> to 'not' supply the aforementioned table and match on DT match tables
> instead.
> 
> Acked-by: Grant Likely 
> Signed-off-by: Lee Jones 

SoB?

> ---
>  drivers/i2c/i2c-core.c | 12 ++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> index 94ca76e..2ebc64d 100644
> --- a/drivers/i2c/i2c-core.c
> +++ b/drivers/i2c/i2c-core.c
> @@ -468,7 +468,7 @@ static int i2c_device_match(struct device *dev, struct 
> device_driver *drv)
>  
>  
>   /* Attempt an OF style match */
> - if (of_driver_match_device(dev, drv))
> + if (i2c_of_match_device(drv->of_match_table, client))
>   return 1;
>  
>   /* Then ACPI style match */
> @@ -657,7 +657,15 @@ static int i2c_device_probe(struct device *dev)
>   }
>  
>   driver = to_i2c_driver(dev->driver);
> - if (!driver->probe || !driver->id_table)
> + if (!driver->probe)
> + return -EINVAL;
> +
> + /*
> +  * An I2C ID table is not mandatory, if and only if, a suitable Device
> +  * Tree match table entry is supplied for the probing device.
> +  */
> + if (!driver->id_table &&
> + !i2c_of_match_device(dev->driver->of_match_table, client))
>   return -ENODEV;
>  
>   if (!device_can_wakeup(>dev))

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
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


[PATCH] i2c-dev: Fix I2C_SLAVE ioctl comment

2015-09-11 Thread Jean Delvare
The first part of the comment is wrong since November 2007, delete it.

The second part of the comment is related to I2C_PEC, not I2C_SLAVE, so
move it where it belongs.

Signed-off-by: Jean Delvare 
Cc: Wolfram Sang 
---
 drivers/i2c/i2c-dev.c |   17 +++--
 1 file changed, 7 insertions(+), 10 deletions(-)

--- linux-4.2.orig/drivers/i2c/i2c-dev.c2015-09-11 11:22:00.962436523 
+0200
+++ linux-4.2/drivers/i2c/i2c-dev.c 2015-09-11 11:22:22.532879192 +0200
@@ -421,16 +421,6 @@ static long i2cdev_ioctl(struct file *fi
switch (cmd) {
case I2C_SLAVE:
case I2C_SLAVE_FORCE:
-   /* NOTE:  devices set up to work with "new style" drivers
-* can't use I2C_SLAVE, even when the device node is not
-* bound to a driver.  Only I2C_SLAVE_FORCE will work.
-*
-* Setting the PEC flag here won't affect kernel drivers,
-* which will be using the i2c_client node registered with
-* the driver model core.  Likewise, when that client has
-* the PEC flag already set, the i2c-dev driver won't see
-* (or use) this setting.
-*/
if ((arg > 0x3ff) ||
(((client->flags & I2C_M_TEN) == 0) && arg > 0x7f))
return -EINVAL;
@@ -446,6 +436,13 @@ static long i2cdev_ioctl(struct file *fi
client->flags &= ~I2C_M_TEN;
return 0;
case I2C_PEC:
+   /*
+* Setting the PEC flag here won't affect kernel drivers,
+* which will be using the i2c_client node registered with
+* the driver model core.  Likewise, when that client has
+* the PEC flag already set, the i2c-dev driver won't see
+* (or use) this setting.
+*/
if (arg)
client->flags |= I2C_CLIENT_PEC;
else


-- 
Jean Delvare
SUSE L3 Support
--
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


[RESEND PATCH v4 4/8] i2c: Make I2C ID tables non-mandatory for DT'ed devices

2015-09-11 Thread Kieran Bingham
From: Lee Jones 

Currently the I2C framework insists on devices supplying an I2C ID
table.  Many of the devices which do so unnecessarily adding quite a
few wasted lines to kernel code.  This patch allows drivers a means
to 'not' supply the aforementioned table and match on DT match tables
instead.

Acked-by: Grant Likely 
Signed-off-by: Lee Jones 
Signed-off-by: Kieran Bingham 
---
 drivers/i2c/i2c-core.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 94ca76e..2ebc64d 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -468,7 +468,7 @@ static int i2c_device_match(struct device *dev, struct 
device_driver *drv)
 
 
/* Attempt an OF style match */
-   if (of_driver_match_device(dev, drv))
+   if (i2c_of_match_device(drv->of_match_table, client))
return 1;
 
/* Then ACPI style match */
@@ -657,7 +657,15 @@ static int i2c_device_probe(struct device *dev)
}
 
driver = to_i2c_driver(dev->driver);
-   if (!driver->probe || !driver->id_table)
+   if (!driver->probe)
+   return -EINVAL;
+
+   /*
+* An I2C ID table is not mandatory, if and only if, a suitable Device
+* Tree match table entry is supplied for the probing device.
+*/
+   if (!driver->id_table &&
+   !i2c_of_match_device(dev->driver->of_match_table, client))
return -ENODEV;
 
if (!device_can_wakeup(>dev))
-- 
2.1.4

--
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


[RESEND PATCH v4 3/8] i2c: Match using traditional OF methods, then by vendor-less compatible strings

2015-09-11 Thread Kieran Bingham
From: Lee Jones 

This function provides a single call for all I2C devices which need to
match firstly using traditional OF means i.e by of_node, then if that
fails we attempt to match using the supplied I2C client name with a
list of supplied compatible strings with the ',' string
removed.  The latter is required due to the unruly naming conventions
used currently by I2C devices.

Acked-by: Grant Likely 
Signed-off-by: Lee Jones 
Signed-off-by: Kieran Bingham 
---
 drivers/i2c/i2c-core.c | 16 
 include/linux/i2c.h| 12 
 2 files changed, 28 insertions(+)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 0788c1f..94ca76e 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1394,6 +1394,22 @@ i2c_of_match_device_strip_vendor(const struct 
of_device_id *matches,
return NULL;
 }
 
+const struct of_device_id
+*i2c_of_match_device(const struct of_device_id *matches,
+struct i2c_client *client)
+{
+   const struct of_device_id *match;
+
+   if (!(client && matches))
+   return NULL;
+
+   match = of_match_device(matches, >dev);
+   if (match)
+   return match;
+
+   return i2c_of_match_device_strip_vendor(matches, client);
+}
+EXPORT_SYMBOL_GPL(i2c_of_match_device);
 #else
 static void of_i2c_register_devices(struct i2c_adapter *adap) { }
 #endif /* CONFIG_OF */
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index e83a738..48bbbab 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -638,6 +638,10 @@ extern struct i2c_client 
*of_find_i2c_device_by_node(struct device_node *node);
 /* must call put_device() when done with returned i2c_adapter device */
 extern struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node 
*node);
 
+extern const struct of_device_id
+*i2c_of_match_device(const struct of_device_id *matches,
+struct i2c_client *client);
+
 #else
 
 static inline struct i2c_client *of_find_i2c_device_by_node(struct device_node 
*node)
@@ -649,6 +653,14 @@ static inline struct i2c_adapter 
*of_find_i2c_adapter_by_node(struct device_node
 {
return NULL;
 }
+
+const struct of_device_id
+*i2c_of_match_device(const struct of_device_id *matches,
+struct i2c_client *client)
+{
+   return NULL;
+}
+
 #endif /* CONFIG_OF */
 
 #endif /* _LINUX_I2C_H */
-- 
2.1.4

--
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


[RESEND PATCH v4 2/8] i2c: Add the ability to match device to compatible string without an of_node

2015-09-11 Thread Kieran Bingham
From: Lee Jones 

A great deal of I2C devices are currently matched via DT node name, and
as such the compatible naming convention of ',' has gone
somewhat awry - some nodes don't supply one, some supply an arbitrary
string and others the correct device name with an arbitrary vendor prefix.

In an effort to correct this problem we have to supply a mechanism to
match a device by compatible string AND by simple device name.  This
function strips off the ',' part of a supplied compatible string
and attempts to match without it.

The plan is to remove this function once all of the compatible strings
for each device have been brought into line.

Acked-by: Grant Likely 
Signed-off-by: Lee Jones 
[Kieran: strnicmp to strncasecmp]
Signed-off-by: Kieran Bingham 
---
 drivers/i2c/i2c-core.c | 21 +
 1 file changed, 21 insertions(+)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 30d8a77..0788c1f 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1373,6 +1373,27 @@ struct i2c_adapter *of_find_i2c_adapter_by_node(struct 
device_node *node)
return adapter;
 }
 EXPORT_SYMBOL(of_find_i2c_adapter_by_node);
+
+static const struct of_device_id*
+i2c_of_match_device_strip_vendor(const struct of_device_id *matches,
+ struct i2c_client *client)
+{
+   const char *name;
+
+   for (; matches->compatible[0]; matches++) {
+   name = strchr(matches->compatible, ',');
+   if (!name)
+   name = matches->compatible;
+   else
+   name++;
+
+   if (!strncasecmp(client->name, name, strlen(client->name)))
+   return matches;
+   }
+
+   return NULL;
+}
+
 #else
 static void of_i2c_register_devices(struct i2c_adapter *adap) { }
 #endif /* CONFIG_OF */
-- 
2.1.4

--
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


[RESEND PATCH v4 6/8] i2c: Provide a temporary .probe2() call-back type

2015-09-11 Thread Kieran Bingham
From: Lee Jones 

This will aid the seamless removal of the current probe()'s, more
commonly unused than used second parameter.  Most I2C drivers can
simply switch over to the new interface, others which have DT
support can use its own matching instead and others can call
i2c_match_id() themselves.  This brings I2C's device probe method
into line with other similar interfaces in the kernel and prevents
the requirement to pass an i2c_device_id table.

Suggested-by: Grant Likely 
Signed-off-by: Lee Jones 
[Kieran: fix rebase conflicts and adapt for dev_pm_domain_{attach,detach}]
Signed-off-by: Kieran Bingham 
---
 drivers/i2c/i2c-core.c | 22 ++
 include/linux/i2c.h|  8 +++-
 2 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 0e40136..a28b423 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -658,8 +658,6 @@ static int i2c_device_probe(struct device *dev)
}
 
driver = to_i2c_driver(dev->driver);
-   if (!driver->probe)
-   return -EINVAL;
 
/*
 * An I2C ID table is not mandatory, if and only if, a suitable Device
@@ -679,12 +677,20 @@ static int i2c_device_probe(struct device *dev)
return status;
 
status = dev_pm_domain_attach(>dev, true);
-   if (status != -EPROBE_DEFER) {
-   status = driver->probe(client, i2c_match_id(driver->id_table,
-   client));
-   if (status)
-   dev_pm_domain_detach(>dev, true);
-   }
+   if (status == -EPROBE_DEFER)
+   return status;
+
+   /* When there are no more users of probe(), rename probe2 to probe. */
+   if (driver->probe2)
+   status = driver->probe2(client);
+   else if (driver->probe)
+   status = driver->probe(client,
+   i2c_match_id(driver->id_table, client));
+   else
+   status = -EINVAL;
+
+   if (status)
+   dev_pm_domain_detach(>dev, true);
 
return status;
 }
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 787066b..bf675d5 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -127,7 +127,8 @@ extern s32 i2c_smbus_write_i2c_block_data(const struct 
i2c_client *client,
  * struct i2c_driver - represent an I2C device driver
  * @class: What kind of i2c device we instantiate (for detect)
  * @attach_adapter: Callback for bus addition (deprecated)
- * @probe: Callback for device binding
+ * @probe: Callback for device binding - soon to be deprecated
+ * @probe2: New callback for device binding
  * @remove: Callback for device unbinding
  * @shutdown: Callback for device shutdown
  * @alert: Alert callback, for example for the SMBus alert protocol
@@ -170,6 +171,11 @@ struct i2c_driver {
int (*probe)(struct i2c_client *, const struct i2c_device_id *);
int (*remove)(struct i2c_client *);
 
+   /* New driver model interface to aid the seamless removal of the
+* current probe()'s, more commonly unused than used second parameter.
+*/
+   int (*probe2)(struct i2c_client *);
+
/* driver model interfaces that don't relate to enumeration  */
void (*shutdown)(struct i2c_client *);
 
-- 
2.1.4

--
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


[RESEND PATCH v4 5/8] i2c: Export i2c_match_id() for direct use by device drivers

2015-09-11 Thread Kieran Bingham
From: Lee Jones 

When there was no other way to match a I2C device to driver i2c_match_id()
was exclusively used.  However, now there are other types of tables which
are commonly supplied, matching on an i2c_device_id table is used less
frequently.  Instead of _always_ calling i2c_match_id() from within the
framework, we only need to do so from drivers which have no other way of
matching.  This patch makes i2c_match_id() available to the aforementioned
device drivers.

Acked-by: Grant Likely 
Signed-off-by: Lee Jones 
Signed-off-by: Kieran Bingham 
---
 drivers/i2c/i2c-core.c | 3 ++-
 include/linux/i2c.h| 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 2ebc64d..0e40136 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -447,7 +447,7 @@ static inline int acpi_i2c_install_space_handler(struct 
i2c_adapter *adapter)
 
 /* - */
 
-static const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,
+const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,
const struct i2c_client *client)
 {
if (!(id && client))
@@ -460,6 +460,7 @@ static const struct i2c_device_id *i2c_match_id(const 
struct i2c_device_id *id,
}
return NULL;
 }
+EXPORT_SYMBOL_GPL(i2c_match_id);
 
 static int i2c_device_match(struct device *dev, struct device_driver *drv)
 {
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 48bbbab..787066b 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -232,6 +232,8 @@ struct i2c_client {
 
 extern struct i2c_client *i2c_verify_client(struct device *dev);
 extern struct i2c_adapter *i2c_verify_adapter(struct device *dev);
+extern const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,
+   const struct i2c_client *client);
 
 static inline struct i2c_client *kobj_to_i2c_client(struct kobject *kobj)
 {
-- 
2.1.4

--
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


[RESEND PATCH v4 8/8] mfd: as3722: Rid driver of superfluous I2C device ID structure

2015-09-11 Thread Kieran Bingham
From: Lee Jones 

Also remove unused second probe() parameter 'i2c_device_id'.

Acked-by: Grant Likely 
Signed-off-by: Lee Jones 
Signed-off-by: Kieran Bingham 
---
 drivers/mfd/as3722.c | 12 ++--
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/drivers/mfd/as3722.c b/drivers/mfd/as3722.c
index 924ea90..6ac4be3 100644
--- a/drivers/mfd/as3722.c
+++ b/drivers/mfd/as3722.c
@@ -354,8 +354,7 @@ static int as3722_i2c_of_probe(struct i2c_client *i2c,
return 0;
 }
 
-static int as3722_i2c_probe(struct i2c_client *i2c,
-   const struct i2c_device_id *id)
+static int as3722_i2c_probe(struct i2c_client *i2c)
 {
struct as3722 *as3722;
unsigned long irq_flags;
@@ -428,20 +427,13 @@ static const struct of_device_id as3722_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, as3722_of_match);
 
-static const struct i2c_device_id as3722_i2c_id[] = {
-   { "as3722", 0 },
-   {},
-};
-MODULE_DEVICE_TABLE(i2c, as3722_i2c_id);
-
 static struct i2c_driver as3722_i2c_driver = {
.driver = {
.name = "as3722",
.of_match_table = as3722_of_match,
},
-   .probe = as3722_i2c_probe,
+   .probe2 = as3722_i2c_probe,
.remove = as3722_i2c_remove,
-   .id_table = as3722_i2c_id,
 };
 
 module_i2c_driver(as3722_i2c_driver);
-- 
2.1.4

--
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


[RESEND PATCH v4 1/8] i2c: Add pointer dereference protection to i2c_match_id()

2015-09-11 Thread Kieran Bingham
From: Lee Jones 

Here we're providing dereference protection for i2c_match_id(), which
saves us having to do it each time it's called.  We're also stripping
out the (now) needless checks in i2c_device_match().  This patch paves
the way for other, similar code trimming.

Acked-by: Grant Likely 
Signed-off-by: Lee Jones 
Signed-off-by: Kieran Bingham 
---
 drivers/i2c/i2c-core.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index c83e4d1..30d8a77 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -450,6 +450,9 @@ static inline int acpi_i2c_install_space_handler(struct 
i2c_adapter *adapter)
 static const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,
const struct i2c_client *client)
 {
+   if (!(id && client))
+   return NULL;
+
while (id->name[0]) {
if (strcmp(client->name, id->name) == 0)
return id;
@@ -463,8 +466,6 @@ static int i2c_device_match(struct device *dev, struct 
device_driver *drv)
struct i2c_client   *client = i2c_verify_client(dev);
struct i2c_driver   *driver;
 
-   if (!client)
-   return 0;
 
/* Attempt an OF style match */
if (of_driver_match_device(dev, drv))
@@ -475,9 +476,10 @@ static int i2c_device_match(struct device *dev, struct 
device_driver *drv)
return 1;
 
driver = to_i2c_driver(drv);
-   /* match on an id table if there is one */
-   if (driver->id_table)
-   return i2c_match_id(driver->id_table, client) != NULL;
+
+   /* Finally an I2C match */
+   if (i2c_match_id(driver->id_table, client))
+   return 1;
 
return 0;
 }
-- 
2.1.4

--
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