Linux I2C development
 help / color / mirror / Atom feed
* Re: [PATCH v1] I2C Designware Core Supports SMBUS BLOCK
From: Mika Westerberg @ 2016-10-26  9:30 UTC (permalink / raw)
  To: Tin Huynh
  Cc: Jarkko Nikula, Andy Shevchenko, Wolfram Sang, linux-i2c,
	linux-kernel, Loc Ho, Thang Nguyen, Phong Vo, patches
In-Reply-To: <CANQ9TuAgW7ubyKq1RAiw+s=ooF4G99_MMWnG1a0bV3DxKa+UPw@mail.gmail.com>

On Wed, Oct 26, 2016 at 04:20:57PM +0700, Tin Huynh wrote:
>    We need to set stop bit if three conditions are true :  The latest
>    bytes , the latest msg_write_ids and after receiving the buffer length.
>    If we use i2c_dw_xfer_need_stop , arguments of function are complex.

OK, so you would need to pass dev and buf_len to that.

>    Can i use i2c_dw_xfer_receive_length() function  ?
>    Thank  you and best regards
>    Tin
>                       if (dev->msg_write_idx == dev->msgs_num - 1 &&
>    -                           buf_len == 1)
>    +                           buf_len == 1 && !(flags & I2C_M_RECV_LEN))
>                                    cmd |= BIT(9);

Maybe it is better if you just do it like the above then.

^ permalink raw reply

* [PATCH v3 2/2] Documentation: tpm: add the Physical TPM device tree binding documentation
From: Nayna Jain @ 2016-10-26  9:21 UTC (permalink / raw)
  To: devicetree-u79uwXL29TY76Z2rM5mHXA,
	tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: mark.rutland-5wv7dgnIgG8, robh-DgEjT+Ai2ygdnm+yROfE0A,
	pawel.moll-5wv7dgnIgG8, ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg,
	wsa-z923LK4zBo2bacvFa/9K2g,
	honclo-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA, galak-sgV2jX0FEOL9JmXXK+q4OQ,
	cclaudio-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8
In-Reply-To: <1477473705-12746-1-git-send-email-nayna-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>

Newly added support of TPM 2.0 eventlog securityfs pseudo files in tpm
device driver consumes device tree bindings representing I2C based
Physical TPM. This patch adds the documentation for corresponding device
tree bindings of I2C based Physical TPM. These bindings are similar to
vtpm device tree bindings being used on IBM Power7+ and Power8 Systems
running PowerVM.

Suggested-by: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
Signed-off-by: Nayna Jain <nayna-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
---
Changelog v3:
 - Added documentation for "label" property.

Changelog v2:

- Include review feedbacks.
  - Move the doc within bindings/security/tpm.
  - Add example for compatible property in description.
  - Delete implicit properties like status, label from description.
  - Redefine linux,sml-base description.

 .../devicetree/bindings/security/tpm/tpm-i2c.txt    | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/security/tpm/tpm-i2c.txt

diff --git a/Documentation/devicetree/bindings/security/tpm/tpm-i2c.txt b/Documentation/devicetree/bindings/security/tpm/tpm-i2c.txt
new file mode 100644
index 0000000..8cb638b
--- /dev/null
+++ b/Documentation/devicetree/bindings/security/tpm/tpm-i2c.txt
@@ -0,0 +1,21 @@
+* Device Tree Bindings for I2C based Trusted Platform Module(TPM)
+
+Required properties:
+
+- compatible     : 'manufacturer,model', eg. nuvoton,npct650
+- label          : human readable string describing the device, eg. "tpm"
+- linux,sml-base : 64-bit base address of the reserved memory allocated for
+                   the firmware event log
+- linux,sml-size : size of the memory allocated for the firmware event log
+
+Example (for OpenPower Systems with Nuvoton TPM 2.0 on I2C)
+----------------------------------------------------------
+
+tpm@57 {
+	reg = <0x57>;
+	label = "tpm";
+	compatible = "nuvoton,npct650", "nuvoton,npct601";
+	linux,sml-base = <0x7f 0xfd450000>;
+	linux,sml-size = <0x10000>;
+	status = "okay";
+};
-- 
2.5.0


------------------------------------------------------------------------------
The Command Line: Reinvented for Modern Developers
Did the resurgence of CLI tooling catch you by surprise?
Reconnect with the command line and become more productive. 
Learn the new .NET and ASP.NET CLI. Get your free copy!
http://sdm.link/telerik

^ permalink raw reply related

* [PATCH v3 1/2] Documentation: tpm: add the IBM Virtual TPM device tree binding documentation
From: Nayna Jain @ 2016-10-26  9:21 UTC (permalink / raw)
  To: devicetree-u79uwXL29TY76Z2rM5mHXA,
	tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: mark.rutland-5wv7dgnIgG8, robh-DgEjT+Ai2ygdnm+yROfE0A,
	pawel.moll-5wv7dgnIgG8, ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg,
	wsa-z923LK4zBo2bacvFa/9K2g,
	honclo-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA, galak-sgV2jX0FEOL9JmXXK+q4OQ,
	cclaudio-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8

Virtual TPM, which is being used on IBM POWER7+ and POWER8 systems running
POWERVM, is currently supported by tpm device driver but lacks the
documentation. This patch adds the missing documentation for the existing
support.

Suggested-by: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
Signed-off-by: Nayna Jain <nayna-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
---
Changelog v3:

- No changes done.

Changelog v2:

- New Patch.

 .../devicetree/bindings/security/tpm/ibmvtpm.txt   | 41 ++++++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/security/tpm/ibmvtpm.txt

diff --git a/Documentation/devicetree/bindings/security/tpm/ibmvtpm.txt b/Documentation/devicetree/bindings/security/tpm/ibmvtpm.txt
new file mode 100644
index 0000000..d89f999
--- /dev/null
+++ b/Documentation/devicetree/bindings/security/tpm/ibmvtpm.txt
@@ -0,0 +1,41 @@
+* Device Tree Bindings for IBM Virtual Trusted Platform Module(vtpm)
+
+Required properties:
+
+- compatible            : property name that conveys the platform architecture
+                          identifiers, as 'IBM,vtpm'
+- device_type           : specifies type of virtual device
+- interrupts            : property specifying the interrupt source number and
+                          sense code associated with this virtual I/O Adapters
+- ibm,my-drc-index      : integer index for the connector between the device
+                          and its parent - present only if Dynamic
+                          Reconfiguration(DR) Connector is enabled
+- ibm,#dma-address-cells: specifies the number of cells that are used to
+                          encode the physical address field of dma-window
+                          properties
+- ibm,#dma-size-cells   : specifies the number of cells that are used to
+                          encode the size field of dma-window properties
+- ibm,my-dma-window     : specifies DMA window associated with this virtual
+                          IOA
+- ibm,loc-code          : specifies the unique and persistent location code
+                          associated with this virtual I/O Adapters
+- linux,sml-base        : 64-bit base address of the reserved memory allocated
+                          for the firmware event log
+- linux,sml-size        : size of the memory allocated for the firmware event log
+
+Example (IBM Virtual Trusted Platform Module)
+---------------------------------------------
+
+                vtpm@30000003 {
+                        ibm,#dma-size-cells = <0x2>;
+                        compatible = "IBM,vtpm";
+                        device_type = "IBM,vtpm";
+                        ibm,my-drc-index = <0x30000003>;
+                        ibm,#dma-address-cells = <0x2>;
+                        linux,sml-base = <0xc60e 0x0>;
+                        interrupts = <0xa0003 0x0>;
+                        ibm,my-dma-window = <0x10000003 0x0 0x0 0x0 0x10000000>;
+                        ibm,loc-code = "U8286.41A.10082DV-V3-C3";
+                        reg = <0x30000003>;
+                        linux,sml-size = <0xbce10200>;
+                };
-- 
2.5.0


------------------------------------------------------------------------------
The Command Line: Reinvented for Modern Developers
Did the resurgence of CLI tooling catch you by surprise?
Reconnect with the command line and become more productive. 
Learn the new .NET and ASP.NET CLI. Get your free copy!
http://sdm.link/telerik

^ permalink raw reply related

* Re: [PATCHv6 07/11] i2c: match dt-style device names from sysfs interface
From: Lee Jones @ 2016-10-26  8:55 UTC (permalink / raw)
  To: Kieran Bingham
  Cc: Wolfram Sang, linux-i2c, linux-kernel, Javier Martinez Canillas,
	sameo
In-Reply-To: <1477413715-22894-8-git-send-email-kieran@bingham.xyz>

On Tue, 25 Oct 2016, Kieran Bingham wrote:

> A user can choose to instantiate a device on an i2c bus using the sysfs
> interface by providing a string and address to match and communicate
> with the device on the bus. Presently this string is only matched
> against the old i2c device id style strings, even in the presence of
> full device tree compatible strings with vendor prefixes.
> 
> Providing a vendor-prefixed string to the sysfs interface will not match
> against the device tree of_match_device() calls as there is no device
> tree node to parse from the sysfs interface.
> 
> Convert i2c_of_match_device_strip_vendor() such that it can match both
> vendor prefixed and stripped compatible strings on the sysfs interface.
> 
> Signed-off-by: Kieran Bingham <kieran@bingham.xyz>

Acked-by: Lee Jones <lee.jones@linaro.org>

> ---
>  drivers/i2c/i2c-core.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> index 2003334b5246..01bce56f733a 100644
> --- a/drivers/i2c/i2c-core.c
> +++ b/drivers/i2c/i2c-core.c
> @@ -1692,6 +1692,16 @@ i2c_of_match_device_strip_vendor(const struct of_device_id *matches,
>  	const char *name;
>  
>  	for (; matches->compatible[0]; matches++) {
> +		/*
> +		 * Adding devices through the i2c sysfs interface provides us
> +		 * a string to match which may be compatible with the device
> +		 * tree compatible strings, however with no actual of_node the
> +		 * of_match_device() will not match
> +		 */
> +		if (!strncasecmp(client->name, matches->compatible,
> +				strlen(matches->compatible)))
> +			return matches;
> +
>  		name = strchr(matches->compatible, ',');
>  		if (!name)
>  			name = matches->compatible;

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply

* Re: [PATCHv6 08/11] i2c: match vendorless strings on the internal string length
From: Lee Jones @ 2016-10-26  8:53 UTC (permalink / raw)
  To: Kieran Bingham
  Cc: Wolfram Sang, linux-i2c, linux-kernel, Javier Martinez Canillas,
	sameo
In-Reply-To: <1477413715-22894-9-git-send-email-kieran@bingham.xyz>

On Tue, 25 Oct 2016, Kieran Bingham wrote:

> If a user provides a shortened string to match a device to the sysfs i2c
> interface it will match on the first string that contains that string
> prefix.
> 
> for example:
>   echo a 0x68 > /sys/bus/i2c/devices/i2c-2/new_device
> 
> will match as3711, as3722, and ak8975 incorrectly.
> 
> Signed-off-by: Kieran Bingham <kieran@bingham.xyz>

Acked-by: Lee Jones <lee.jones@linaro.org>
  
> ---
>  drivers/i2c/i2c-core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> index 01bce56f733a..50c9cfdb87b7 100644
> --- a/drivers/i2c/i2c-core.c
> +++ b/drivers/i2c/i2c-core.c
> @@ -1708,7 +1708,7 @@ i2c_of_match_device_strip_vendor(const struct of_device_id *matches,
>  		else
>  			name++;
>  
> -		if (!strncasecmp(client->name, name, strlen(client->name)))
> +		if (!strncasecmp(client->name, name, strlen(name)))
>  			return matches;
>  	}
>  

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply

* Re: [PATCH v1] I2C Designware Core Supports SMBUS BLOCK
From: Mika Westerberg @ 2016-10-26  8:16 UTC (permalink / raw)
  To: Tin Huynh
  Cc: Jarkko Nikula, Andy Shevchenko, Wolfram Sang, linux-i2c,
	linux-kernel, Loc Ho, Thang Nguyen, Phong Vo, patches
In-Reply-To: <CANQ9TuB5BbR40TEndGqQ6ABDSUsCOGjEhXSvmD78jtuqGRpXvg@mail.gmail.com>

On Wed, Oct 26, 2016 at 02:26:05PM +0700, Tin Huynh wrote:
>    But can you explain more about 'but even that starts to require small
>    helper function'?

So you could add a small function i2c_dw_xfer_need_stop() that returns
true if you need to set the stop bit.

^ permalink raw reply

* Re: [Linux-parport] True Parallel Port Interface for Bit-banging?
From: Jan Kandziora @ 2016-10-26  5:20 UTC (permalink / raw)
  To: Maciej S. Szmigiero, Sebastian Frias
  Cc: Wolfram Sang, Sudip Mukherjee, linux-parport, philb, tim,
	Jean Delvare, linux-i2c
In-Reply-To: <7bd6ea08-361e-316f-be7f-d400b59aec0d@maciej.szmigiero.name>

Am 26.10.2016 um 02:04 schrieb Maciej S. Szmigiero:
>
> I have tried dosemu, dosbox and as far I remember also VirtualBox
> with an old, DOS car service app.
> Wasn't able to make it communicate until I booted true DOS.
> That machine had old-style ISA serial ports so it was possible.
>
This is because it most likely uses the K-Line protocol, which needs to
output two bytes at 5 (in words: FIVE) baud at the very beginning of
each package.

It's no possible to have such a bitrate through any standard driver.
Those old car service apps tweak the UART hardware heavily to output
that signalling. It literally needs a 8250 chip. May even fail with some
SuperIO "16550" emulations in current mainboards.

Newer cars have CAN, but these K-Line cars (up to model year 2005 I
think) can give you headaches.

Kind regards

	Jan

^ permalink raw reply

* Re: True Parallel Port Interface for Bit-banging?
From: Maciej S. Szmigiero @ 2016-10-26  0:04 UTC (permalink / raw)
  To: Sebastian Frias
  Cc: Jean Delvare, linux-parport, Wolfram Sang, linux-i2c, philb, tim
In-Reply-To: <580F72AF.9070900@laposte.net>

On 25.10.2016 16:56, Sebastian Frias wrote:
> On 10/25/2016 04:29 PM, Wolfram Sang wrote:
>>> The virtualisation idea is not good then?
>>
>> It is not that. I think good old DOSEMU could do that. Bit-Banging ports
>> can be timing critical, though, and in this department virtualization
>> solutions often fail.
>>
> 
> Thanks.
> I understand your point, but I'm guessing that the big-banging routine (or the
> protocol to be used) should be time-independent in order to run on different
> real HW PCs, right? Otherwise a 386DX and a 486DX2 could behave differently,
> right?
> 
> Or is the "timing issue" you talk about more related to unpredictable
> latencies due to the way the SW virtualisation works?
> 
> What about emulation? Do you think emulation would be more predictable?

I don't have experience with bit-banging parallel port but I do have
some with bit-banging PC serial ports (which should be very similar)
and can confirm that old DOS software can be *very* fragile with regard
to timing.
I have tried dosemu, dosbox and as far I remember also VirtualBox
with an old, DOS car service app.
Wasn't able to make it communicate until I booted true DOS.
That machine had old-style ISA serial ports so it was possible.

You also have asked previously whether laptop port would work.
On my current HP Elitebook ports of both types are wired to Super IO,
and using PC standard IO port and interrupt numbers.

I also remember that at least on ThinkPads and HP Compaqs that I had
contact with (these were laptops from 10+ years ago) both serial and
parallel ports were wired to Super IO chip (including ones available
only via port replicator).
So they were also at PC standard resources.

However, other issue is that sometimes such ports are inactive by
default (don't respond) until enabled by PnP.

This is also a problem with PCMCIA cards - they are disabled
by default.
I have Argosy 2xRS232 PCMCIA card and remember it came with
DOS driver which could enable them on I/O port close to standard
one - this was one of their major selling points.
So your ExpressCard would probably need similar software.

Maciej

^ permalink raw reply

* Re: True Parallel Port Interface for Bit-banging?
From: Wolfram Sang @ 2016-10-25 17:17 UTC (permalink / raw)
  To: Sebastian Frias
  Cc: Sudip Mukherjee, linux-parport, philb, tim, Jean Delvare,
	linux-i2c
In-Reply-To: <580F72AF.9070900@laposte.net>

[-- Attachment #1: Type: text/plain, Size: 423 bytes --]


> Or is the "timing issue" you talk about more related to unpredictable
> latencies due to the way the SW virtualisation works?

Yes, it is all about latencies and meeting deadlines. This is probably
why the application is DOS after all.

> What about emulation? Do you think emulation would be more predictable?

No difference as long as there is a multi-tasking OS in the background.
Yes, the RT patchset might help...


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply

* [PATCHv6 11/11] [TESTPATCH] rtc: convert ds1307 to interim probe_new
From: Kieran Bingham @ 2016-10-25 16:41 UTC (permalink / raw)
  To: Wolfram Sang, Lee Jones, Kieran Bingham
  Cc: linux-i2c, linux-kernel, Javier Martinez Canillas, sameo
In-Reply-To: <1477413715-22894-1-git-send-email-kieran@bingham.xyz>

Just for testing, specify a maxim,ds1307 device to identify the code path used
when instantiating the driver from userspace.

root@arm:~# echo maxim,ds1307 0x68 > /sys/bus/i2c/devices/i2c-2/new_device
[   49.807383] rtc-ds1307 2-0068: I'm a Maxim ...
[   49.814706] rtc-ds1307 2-0068: rtc core: registered maxim,ds1307 as rtc0
[   49.821813] rtc-ds1307 2-0068: 56 bytes nvram
[   49.826444] i2c i2c-2: new_device: Instantiated device maxim,ds1307 at 0x68

This patch also demonstrates how to obtain data from the id's using the
new methods.
---
 drivers/rtc/rtc-ds1307.c | 53 ++++++++++++++++++++++++++++--------------------
 1 file changed, 31 insertions(+), 22 deletions(-)

diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 8e1c5cb6ece6..f760b7cf1fdb 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -31,6 +31,7 @@
  */
 enum ds_type {
 	ds_1307,
+	maxim_1307,
 	ds_1337,
 	ds_1338,
 	ds_1339,
@@ -144,6 +145,10 @@ static struct chip_desc chips[last_ds_type] = {
 		.nvram_offset	= 8,
 		.nvram_size	= 56,
 	},
+	[maxim_1307] = {
+		.nvram_offset	= 8,
+		.nvram_size	= 56,
+	},
 	[ds_1337] = {
 		.alarm		= 1,
 	},
@@ -173,22 +178,6 @@ static struct chip_desc chips[last_ds_type] = {
 	},
 };
 
-static const struct i2c_device_id ds1307_id[] = {
-	{ "ds1307", ds_1307 },
-	{ "ds1337", ds_1337 },
-	{ "ds1338", ds_1338 },
-	{ "ds1339", ds_1339 },
-	{ "ds1388", ds_1388 },
-	{ "ds1340", ds_1340 },
-	{ "ds3231", ds_3231 },
-	{ "m41t00", m41t00 },
-	{ "mcp7940x", mcp794xx },
-	{ "mcp7941x", mcp794xx },
-	{ "pt7c4338", ds_1307 },
-	{ "rx8025", rx_8025 },
-	{ }
-};
-MODULE_DEVICE_TABLE(i2c, ds1307_id);
 
 /*----------------------------------------------------------------------*/
 
@@ -1223,13 +1212,20 @@ static void ds1307_clks_register(struct ds1307 *ds1307)
 
 #endif /* CONFIG_COMMON_CLK */
 
-static int ds1307_probe(struct i2c_client *client,
-			const struct i2c_device_id *id)
+static const struct of_device_id ds1307_dt_ids[] = {
+	{ .compatible = "dallas,ds1307", .data = (void *)ds_1307 },
+	{ .compatible = "maxim,ds1307", .data = (void *)maxim_1307 },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, ds1307_dt_ids);
+
+static int ds1307_probe(struct i2c_client *client)
 {
 	struct ds1307		*ds1307;
 	int			err = -ENODEV;
 	int			tmp, wday;
-	struct chip_desc	*chip = &chips[id->driver_data];
+	const struct of_device_id 	*idof;
+	struct chip_desc	*chip;
 	struct i2c_adapter	*adapter = to_i2c_adapter(client->dev.parent);
 	bool			want_irq = false;
 	bool			ds1307_can_wakeup_device = false;
@@ -1255,10 +1251,20 @@ static int ds1307_probe(struct i2c_client *client,
 	if (!ds1307)
 		return -ENOMEM;
 
+	/* If we've got this far, this shouldn't be able to fail - but check anyway for now */
+	idof = i2c_of_match_device(ds1307_dt_ids, client);
+	if (!idof) {
+		dev_err(&client->dev, "Probe failed to find an id entry\n");
+		return -ENODEV;
+	}
+
+	/* Now we can set our chip entry */
+	chip = &chips[(int)idof->data];
+
 	i2c_set_clientdata(client, ds1307);
 
 	ds1307->client	= client;
-	ds1307->type	= id->driver_data;
+	ds1307->type	= (int) idof->data;
 
 	if (!pdata && client->dev.of_node)
 		ds1307_trickle_of_init(client, chip);
@@ -1435,6 +1441,9 @@ read_rtc:
 	 */
 	tmp = ds1307->regs[DS1307_REG_SECS];
 	switch (ds1307->type) {
+	case maxim_1307:
+		dev_info(&client->dev, "I'm a Maxim ... \n");
+		/* fallthrough */
 	case ds_1307:
 	case m41t00:
 		/* clock halted?  turn it on, so clock can tick. */
@@ -1634,10 +1643,10 @@ static int ds1307_remove(struct i2c_client *client)
 static struct i2c_driver ds1307_driver = {
 	.driver = {
 		.name	= "rtc-ds1307",
+		.of_match_table = of_match_ptr(ds1307_dt_ids),
 	},
-	.probe		= ds1307_probe,
+	.probe_new	= ds1307_probe,
 	.remove		= ds1307_remove,
-	.id_table	= ds1307_id,
 };
 
 module_i2c_driver(ds1307_driver);
-- 
2.7.4

^ permalink raw reply related

* [PATCHv6 10/11] mfd: as3722: Rid driver of superfluous I2C device ID structure
From: Kieran Bingham @ 2016-10-25 16:41 UTC (permalink / raw)
  To: Wolfram Sang, Lee Jones, Kieran Bingham
  Cc: linux-i2c, linux-kernel, Javier Martinez Canillas, sameo
In-Reply-To: <1477413715-22894-1-git-send-email-kieran@bingham.xyz>

From: Lee Jones <lee.jones@linaro.org>

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

Acked-by: Grant Likely <grant.likely@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Kieran Bingham <kieran@bingham.xyz>

---
Changes since v4
 - Rename .probe2 to probe_new
---
 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 f87342c211bc..7d8c5e4136e2 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;
@@ -441,12 +440,6 @@ 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 const struct dev_pm_ops as3722_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(as3722_i2c_suspend, as3722_i2c_resume)
 };
@@ -457,8 +450,7 @@ static struct i2c_driver as3722_i2c_driver = {
 		.of_match_table = as3722_of_match,
 		.pm = &as3722_pm_ops,
 	},
-	.probe = as3722_i2c_probe,
-	.id_table = as3722_i2c_id,
+	.probe_new = as3722_i2c_probe,
 };
 
 module_i2c_driver(as3722_i2c_driver);
-- 
2.7.4

^ permalink raw reply related

* [PATCHv6 09/11] mfd: 88pm860x: Move over to new I2C device .probe() call
From: Kieran Bingham @ 2016-10-25 16:41 UTC (permalink / raw)
  To: Wolfram Sang, Lee Jones, Kieran Bingham
  Cc: linux-i2c, linux-kernel, Javier Martinez Canillas, sameo
In-Reply-To: <1477413715-22894-1-git-send-email-kieran@bingham.xyz>

From: Lee Jones <lee.jones@linaro.org>

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 <grant.likely@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Kieran Bingham <kieran@bingham.xyz>

---
Changes since v4
 - Rename .probe2 to probe_new
---
 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 25e1aafae60c..227b99018657 100644
--- a/drivers/mfd/88pm860x-core.c
+++ b/drivers/mfd/88pm860x-core.c
@@ -1132,8 +1132,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(&client->dev);
 	struct device_node *node = client->dev.of_node;
@@ -1259,7 +1258,7 @@ static struct i2c_driver pm860x_driver = {
 		.pm     = &pm860x_pm_ops,
 		.of_match_table	= pm860x_dt_ids,
 	},
-	.probe		= pm860x_probe,
+	.probe_new	= pm860x_probe,
 	.remove		= pm860x_remove,
 	.id_table	= pm860x_id_table,
 };
-- 
2.7.4

^ permalink raw reply related

* [PATCHv6 08/11] i2c: match vendorless strings on the internal string length
From: Kieran Bingham @ 2016-10-25 16:41 UTC (permalink / raw)
  To: Wolfram Sang, Lee Jones, Kieran Bingham
  Cc: linux-i2c, linux-kernel, Javier Martinez Canillas, sameo
In-Reply-To: <1477413715-22894-1-git-send-email-kieran@bingham.xyz>

If a user provides a shortened string to match a device to the sysfs i2c
interface it will match on the first string that contains that string
prefix.

for example:
  echo a 0x68 > /sys/bus/i2c/devices/i2c-2/new_device

will match as3711, as3722, and ak8975 incorrectly.

Signed-off-by: Kieran Bingham <kieran@bingham.xyz>
---
 drivers/i2c/i2c-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 01bce56f733a..50c9cfdb87b7 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1708,7 +1708,7 @@ i2c_of_match_device_strip_vendor(const struct of_device_id *matches,
 		else
 			name++;
 
-		if (!strncasecmp(client->name, name, strlen(client->name)))
+		if (!strncasecmp(client->name, name, strlen(name)))
 			return matches;
 	}
 
-- 
2.7.4

^ permalink raw reply related

* [PATCHv6 07/11] i2c: match dt-style device names from sysfs interface
From: Kieran Bingham @ 2016-10-25 16:41 UTC (permalink / raw)
  To: Wolfram Sang, Lee Jones, Kieran Bingham
  Cc: linux-i2c, linux-kernel, Javier Martinez Canillas, sameo
In-Reply-To: <1477413715-22894-1-git-send-email-kieran@bingham.xyz>

A user can choose to instantiate a device on an i2c bus using the sysfs
interface by providing a string and address to match and communicate
with the device on the bus. Presently this string is only matched
against the old i2c device id style strings, even in the presence of
full device tree compatible strings with vendor prefixes.

Providing a vendor-prefixed string to the sysfs interface will not match
against the device tree of_match_device() calls as there is no device
tree node to parse from the sysfs interface.

Convert i2c_of_match_device_strip_vendor() such that it can match both
vendor prefixed and stripped compatible strings on the sysfs interface.

Signed-off-by: Kieran Bingham <kieran@bingham.xyz>
---
 drivers/i2c/i2c-core.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 2003334b5246..01bce56f733a 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1692,6 +1692,16 @@ i2c_of_match_device_strip_vendor(const struct of_device_id *matches,
 	const char *name;
 
 	for (; matches->compatible[0]; matches++) {
+		/*
+		 * Adding devices through the i2c sysfs interface provides us
+		 * a string to match which may be compatible with the device
+		 * tree compatible strings, however with no actual of_node the
+		 * of_match_device() will not match
+		 */
+		if (!strncasecmp(client->name, matches->compatible,
+				strlen(matches->compatible)))
+			return matches;
+
 		name = strchr(matches->compatible, ',');
 		if (!name)
 			name = matches->compatible;
-- 
2.7.4

^ permalink raw reply related

* [PATCHv6 06/11] i2c: Provide a temporary .probe_new() call-back type
From: Kieran Bingham @ 2016-10-25 16:41 UTC (permalink / raw)
  To: Wolfram Sang, Lee Jones, Kieran Bingham
  Cc: linux-i2c, linux-kernel, Javier Martinez Canillas, sameo
In-Reply-To: <1477413715-22894-1-git-send-email-kieran@bingham.xyz>

From: Lee Jones <lee.jones@linaro.org>

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 <grant.likely@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
[Kieran: fix rebase conflicts and adapt for dev_pm_domain_{attach,detach}]
Tested-by: Kieran Bingham <kieran@bingham.xyz>
Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Tested-by: Javier Martinez Canillas <javier@osg.samsung.com>
Signed-off-by: Kieran Bingham <kieran@bingham.xyz>
---
Changes since v4 [Kieran]
 - Rename .probe2 to probe_new
 - Checkpatch warnings fixed
---
 drivers/i2c/i2c-core.c | 15 ++++++++++++---
 include/linux/i2c.h    |  8 +++++++-
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index f20c9b229570..2003334b5246 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -834,8 +834,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
@@ -877,7 +875,18 @@ static int i2c_device_probe(struct device *dev)
 	if (status == -EPROBE_DEFER)
 		goto err_clear_wakeup_irq;
 
-	status = driver->probe(client, i2c_match_id(driver->id_table, client));
+	/*
+	 * When there are no more users of probe(),
+	 * rename probe_new to probe.
+	 */
+	if (driver->probe_new)
+		status = driver->probe_new(client);
+	else if (driver->probe)
+		status = driver->probe(client,
+				       i2c_match_id(driver->id_table, client));
+	else
+		status = -EINVAL;
+
 	if (status)
 		goto err_detach_pm_domain;
 
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 39f1131a58d1..d31f37e90d11 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -135,7 +135,8 @@ enum i2c_alert_protocol {
  * 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
+ * @probe_new: 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
@@ -178,6 +179,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 (*probe_new)(struct i2c_client *);
+
 	/* driver model interfaces that don't relate to enumeration  */
 	void (*shutdown)(struct i2c_client *);
 
-- 
2.7.4

^ permalink raw reply related

* [PATCHv6 05/11] i2c: Export i2c_match_id() for direct use by device drivers
From: Kieran Bingham @ 2016-10-25 16:41 UTC (permalink / raw)
  To: Wolfram Sang, Lee Jones, Kieran Bingham
  Cc: linux-i2c, linux-kernel, Javier Martinez Canillas, sameo
In-Reply-To: <1477413715-22894-1-git-send-email-kieran@bingham.xyz>

From: Lee Jones <lee.jones@linaro.org>

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 <grant.likely@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Tested-by: Kieran Bingham <kieran@bingham.xyz>
Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Tested-by: Javier Martinez Canillas <javier@osg.samsung.com>
Signed-off-by: Kieran Bingham <kieran@bingham.xyz>
---
 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 a69b47990ae7..f20c9b229570 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -586,7 +586,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))
@@ -599,6 +599,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 2608e731e401..39f1131a58d1 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -243,6 +243,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.7.4

^ permalink raw reply related

* [PATCHv6 04/11] i2c: Make I2C ID tables non-mandatory for DT'ed devices
From: Kieran Bingham @ 2016-10-25 16:41 UTC (permalink / raw)
  To: Wolfram Sang, Lee Jones, Kieran Bingham
  Cc: linux-i2c, linux-kernel, Javier Martinez Canillas, sameo
In-Reply-To: <1477413715-22894-1-git-send-email-kieran@bingham.xyz>

From: Lee Jones <lee.jones@linaro.org>

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 <grant.likely@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Tested-by: Kieran Bingham <kieran@bingham.xyz>
Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Tested-by: Javier Martinez Canillas <javier@osg.samsung.com>
Signed-off-by: Kieran Bingham <kieran@bingham.xyz>
---
 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 d5eca0dc32be..a69b47990ae7 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -607,7 +607,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 */
@@ -833,7 +833,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 (client->flags & I2C_CLIENT_WAKE) {
-- 
2.7.4

^ permalink raw reply related

* [PATCHv6 03/11] i2c: Match using traditional OF methods, then by vendor-less compatible strings
From: Kieran Bingham @ 2016-10-25 16:41 UTC (permalink / raw)
  To: Wolfram Sang, Lee Jones, Kieran Bingham
  Cc: linux-i2c, linux-kernel, Javier Martinez Canillas, sameo
In-Reply-To: <1477413715-22894-1-git-send-email-kieran@bingham.xyz>

From: Lee Jones <lee.jones@linaro.org>

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 '<vendor>,' string
removed.  The latter is required due to the unruly naming conventions
used currently by I2C devices.

Acked-by: Grant Likely <grant.likely@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
[Kieran: Fix static inline usage on !CONFIG_OF]
Tested-by: Kieran Bingham <kieran@bingham.xyz>
Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Tested-by: Javier Martinez Canillas <javier@osg.samsung.com>
Signed-off-by: Kieran Bingham <kieran@bingham.xyz>
---
 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 a699ca541702..d5eca0dc32be 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1687,6 +1687,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, &client->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 fffdc270ca18..2608e731e401 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -748,6 +748,10 @@ extern struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node)
 /* must call i2c_put_adapter() when done with returned i2c_adapter device */
 struct i2c_adapter *of_get_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)
@@ -764,6 +768,14 @@ static inline struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node
 {
 	return NULL;
 }
+
+static inline 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.7.4

^ permalink raw reply related

* [PATCHv6 02/11] i2c: Add the ability to match device to compatible string without an of_node
From: Kieran Bingham @ 2016-10-25 16:41 UTC (permalink / raw)
  To: Wolfram Sang, Lee Jones, Kieran Bingham
  Cc: linux-i2c, linux-kernel, Javier Martinez Canillas, sameo
In-Reply-To: <1477413715-22894-1-git-send-email-kieran@bingham.xyz>

From: Lee Jones <lee.jones@linaro.org>

A great deal of I2C devices are currently matched via DT node name, and
as such the compatible naming convention of '<vendor>,<device>' 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 '<vendor>,' 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 <grant.likely@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
[Kieran: strnicmp to strncasecmp]
Tested-by: Kieran Bingham <kieran@bingham.xyz>
Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Tested-by: Javier Martinez Canillas <javier@osg.samsung.com>
Signed-off-by: Kieran Bingham <kieran@bingham.xyz>
---
 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 eec4d4d81bf8..a699ca541702 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1666,6 +1666,27 @@ struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node)
 	return adapter;
 }
 EXPORT_SYMBOL(of_get_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.7.4

^ permalink raw reply related

* [PATCHv6 01/11] i2c: Add pointer dereference protection to i2c_match_id()
From: Kieran Bingham @ 2016-10-25 16:41 UTC (permalink / raw)
  To: Wolfram Sang, Lee Jones, Kieran Bingham
  Cc: linux-i2c, linux-kernel, Javier Martinez Canillas, sameo
In-Reply-To: <1477413715-22894-1-git-send-email-kieran@bingham.xyz>

From: Lee Jones <lee.jones@linaro.org>

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 <grant.likely@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Tested-by: Kieran Bingham <kieran@bingham.xyz>
Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Tested-by: Javier Martinez Canillas <javier@osg.samsung.com>
Signed-off-by: Kieran Bingham <kieran@bingham.xyz>
---
 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 da3a02ef4a31..eec4d4d81bf8 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -589,6 +589,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;
@@ -602,8 +605,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))
@@ -614,9 +615,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.7.4

^ permalink raw reply related

* [PATCHv6 00/11] i2c: Relax mandatory I2C ID table passing
From: Kieran Bingham @ 2016-10-25 16:41 UTC (permalink / raw)
  To: Wolfram Sang, Lee Jones, Kieran Bingham
  Cc: linux-i2c, linux-kernel, Javier Martinez Canillas, sameo

Version 6 of this patchset adds two new patches on top of the existing
submission to resolve the (final?) pending question from the previous
discussions during v5 [0]. Javier's tags are also collected here.

In particular, the remaining issue was that a user could provide a full
vendor prefixed string to the sysfs interface to instantiate an i2c
device. In version 5 of this submission this would not have matched
against a device driver as highlighted by the test patch provided by
Wolfram.

As such, in this series I have extended i2c_of_match_device_strip_vendor
so that it will also perform a search against a full compatible string
for the matching process. This was not done by the core OF framework as
the sysfs interface does not create an of_node to match against. If so
desired, this function could now be renamed to i2c_of_match_device_sysfs

Patch 11/11 of this series brings back Wolframs test case (correctly this
time) and also serves as a demonstration as to how to map the ID's when
matched against an of-style node. Note that this patch is *not* signed
off and not suitable for integration.

[0] [PATCHv5 0/8] 2c: Relax mandatory I2C ID table passing
    https://lkml.org/lkml/2016/5/4/534

Kieran Bingham (3):
  i2c: match dt-style device names from sysfs interface
  i2c: match vendorless strings on the internal string length
  [TESTPATCH] rtc: convert ds1307 to interim probe_new

Lee Jones (8):
  i2c: Add pointer dereference protection to i2c_match_id()
  i2c: Add the ability to match device to compatible string without an
    of_node
  i2c: Match using traditional OF methods, then by vendor-less
    compatible strings
  i2c: Make I2C ID tables non-mandatory for DT'ed devices
  i2c: Export i2c_match_id() for direct use by device drivers
  i2c: Provide a temporary .probe_new() call-back type
  mfd: 88pm860x: Move over to new I2C device .probe() call
  mfd: as3722: Rid driver of superfluous I2C device ID structure

 drivers/i2c/i2c-core.c      | 85 ++++++++++++++++++++++++++++++++++++++++-----
 drivers/mfd/88pm860x-core.c |  5 ++-
 drivers/mfd/as3722.c        | 12 ++-----
 drivers/rtc/rtc-ds1307.c    | 53 ++++++++++++++++------------
 include/linux/i2c.h         | 22 +++++++++++-
 5 files changed, 132 insertions(+), 45 deletions(-)

-- 
2.7.4

^ permalink raw reply

* Re: True Parallel Port Interface for Bit-banging?
From: Sebastian Frias @ 2016-10-25 16:12 UTC (permalink / raw)
  To: Jean Delvare; +Cc: Sudip Mukherjee, linux-parport, philb, tim, linux-i2c
In-Reply-To: <1477401755.4275.18.camel@chaos.suse>

On 10/25/2016 03:22 PM, Jean Delvare wrote:
> On mar., 2016-10-25 at 13:21 +0200, Sebastian Frias wrote:
>> Alternatively, does anybody knows if the Parallel Port available thru Laptop
>> docking stations (Dell, HP, Thinkpad, etc.) are True Parallel Ports (ISA
>> compatible)?
> 
> Some laptops such as the ThinkPad T42 had parallel ports, without the
> need of a docking station. I know because my dad still has one. But well
> these are 2004 machines, may be hard to find these days.
> 

Actually, according to this:

https://www-user.tu-chemnitz.de/~heha/basteln/PC/USB2LPT/index.en.htm

PCMCIA cards could work, is anybody able to confirm?

^ permalink raw reply

* Re: True Parallel Port Interface for Bit-banging?
From: Sebastian Frias @ 2016-10-25 14:56 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: Sudip Mukherjee, linux-parport, philb, tim, Jean Delvare,
	linux-i2c
In-Reply-To: <20161025142935.GA2875@katana>

On 10/25/2016 04:29 PM, Wolfram Sang wrote:
>> The virtualisation idea is not good then?
> 
> It is not that. I think good old DOSEMU could do that. Bit-Banging ports
> can be timing critical, though, and in this department virtualization
> solutions often fail.
> 

Thanks.
I understand your point, but I'm guessing that the big-banging routine (or the
protocol to be used) should be time-independent in order to run on different
real HW PCs, right? Otherwise a 386DX and a 486DX2 could behave differently,
right?

Or is the "timing issue" you talk about more related to unpredictable
latencies due to the way the SW virtualisation works?

What about emulation? Do you think emulation would be more predictable?

^ permalink raw reply

* Re: True Parallel Port Interface for Bit-banging?
From: Wolfram Sang @ 2016-10-25 14:29 UTC (permalink / raw)
  To: Sebastian Frias
  Cc: Sudip Mukherjee, linux-parport, philb, tim, Jean Delvare,
	linux-i2c
In-Reply-To: <580F6A1D.4000409@laposte.net>

[-- Attachment #1: Type: text/plain, Size: 390 bytes --]


> Would the ExpressCard Parallel Port appear always at the same address?
> While this could work, it wouldn't be generic. I would have to do the operation
> for N apps.

I see.

> The virtualisation idea is not good then?

It is not that. I think good old DOSEMU could do that. Bit-Banging ports
can be timing critical, though, and in this department virtualization
solutions often fail.


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply

* Re: True Parallel Port Interface for Bit-banging?
From: Sebastian Frias @ 2016-10-25 14:20 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: Jean Delvare, linux-parport, linux-i2c, philb, tim
In-Reply-To: <20161025120951.GL1597@katana>

On 10/25/2016 02:09 PM, Wolfram Sang wrote:
> 
>> Would that make sense and/or be feasible? Are there better/easier solutions?
> 
> Binary patching the DOS application? Port accesses should be easy to
> find.

Would the ExpressCard Parallel Port appear always at the same address?
While this could work, it wouldn't be generic. I would have to do the operation
for N apps.

> 
> Getting a laptop with parallel port via auction site?

:-)
I would like to avoid having to buy another laptop.

The virtualisation idea is not good then?

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox