9
0
Fork 0
Commit Graph

146 Commits

Author SHA1 Message Date
Sascha Hauer 6134116686 Merge branch 'for-next/mvebu' 2017-03-13 08:16:44 +01:00
Bastian Stender 836b99c81b i2c: mv64xxx: simplify mv64xxx_i2c_wait_for_completion
Two nested while loops are not necessary here, so integrate the read,
i2c_fsm and i2c_do_action calls into mv64xxx_i2c_wait_for_completion()
and remove the obsolete interrupt remains.

Signed-off-by: Bastian Stender <bst@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2017-03-02 14:03:43 +01:00
Bastian Stender 8d38b5205c i2c: mv64xxx: add software delays
As stated in Marvell's Functional Specifications in MV-S107021-U0 Rev. A
on page 420 ff. software delays are needed. "SW delay represent a delay
of at least 2 internal clock cycles". These delays are hereby
implemented.

The original kernel driver compensates the needed software delays with
the time the interrupts take.

Signed-off-by: Bastian Stender <bst@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2017-03-02 14:03:43 +01:00
Alexander Kurz 45164aadfa i.MX: i2c: fix i2c-fsl for non-OF boards
With commit 4ed5b778a5 ("i.MX: i2c: Add Vybrid support") i2c-fsl probe
returns -EINVAL for all non-OF boards.
Since newer planforms, especially vf610 are restricted OF-only it is safe to
assume "fsl,imx21-i2c" if CONFIG_OFDEVICE is not set.

Signed-off-by: Alexander Kurz <akurz@blala.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2017-02-14 08:48:25 +01:00
Sascha Hauer 27940deb9a i2c: i.MX: Enable clock
For architectures which do not enable all clocks during initialization.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2017-01-19 15:16:15 +01:00
Sascha Hauer dcedcec375 Merge branch 'for-next/vybrid' 2017-01-12 07:13:47 +01:00
Sascha Hauer e05529dd8b Merge branch 'for-next/misc' 2017-01-11 19:00:03 +01:00
Andrey Smirnov 4ed5b778a5 i.MX: i2c: Add Vybrid support
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2017-01-11 08:07:00 +01:00
Andrey Smirnov a6cf6b3ff0 i.MX: i2c: Use read/write adapter functions
Use read/write adapter functions instead of directly calling to
readb/writeb. This is needed to prepare driver code to support Vybrid
SoC's variant of this block.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2017-01-11 08:07:00 +01:00
Andrey Smirnov 28dde40d1a i2c-mux-pca954x: Add code to control reset line
Most recent device tree binding for that mux support specifying a GPIO
connected to a reset line of that chip. Add code to handle that binding
in order to be able to use the chip on boards that leverage
aforementioned functionality.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2017-01-10 08:27:33 +01:00
Uwe Kleine-König c524f7d1bb i2c: gpio: use dynamic bus number unconditionally
While being a bit more random this helps dt setups where the id of a
platform device cannot easily be fixed anyhow.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-11-17 07:58:51 +01:00
Uwe Kleine-König 8303208e95 i2c: gpio: fix handling of return code of of_get_gpio
Instead of using gpio_is_valid just check the return code of of_get_gpio
for being < 0. This fixes -EPROBE_DEFER handling as now this error code
is handed to the caller instead of -ENODEV. If the gpio returned by
of_get_gpio is an invalid number this isn't noticed by
of_i2c_gpio_probe, but then gpio_request later fails which is good
enough.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-11-17 07:58:51 +01:00
Sascha Hauer 3bd69ad077 driver: replace dev_request_mem_region with dev_request_mem_resource
dev_request_mem_region doesn't work properly one some SoCs on which
PTR_ERR() values clash with valid return values from dev_request_mem_region.
Replace them with dev_request_mem_resource where possible.

This patch has been generated with the following semantic patch:

// <smpl>
@@
expression d;
expression n;
expression io;
identifier func;
@@
func(...) {
+struct resource *iores;
<+...
-io = dev_request_mem_region(d, n);
-if (IS_ERR(io)) {
+iores = dev_request_mem_resource(d, n);
+if (IS_ERR(iores)) {
...
-	return PTR_ERR(io);
-}
+	return PTR_ERR(iores);
+}
+io = IOMEM(iores->start);
...+>
}

@@
expression d;
expression n;
expression io;
identifier func;
@@
func(...) {
+struct resource *iores;
<+...
-io = dev_request_mem_region(d, n);
-if (IS_ERR(io)) {
+iores = dev_request_mem_resource(d, n);
+if (IS_ERR(iores))
-	return PTR_ERR(io);
-}
+	return PTR_ERR(iores);
+io = IOMEM(iores->start);
...+>
}

@@
expression d;
expression n;
expression io;
identifier func;
@@
func(...) {
+struct resource *iores;
<+...
-io = dev_request_mem_region(d, n);
-if (IS_ERR(io)) {
-	ret = PTR_ERR(io);
+iores = dev_request_mem_resource(d, n);
+if (IS_ERR(iores)) {
+	ret = PTR_ERR(iores);
...
}
+io = IOMEM(iores->start);
...+>
}

@@
expression d;
expression n;
expression io;
identifier func;
@@
func(...) {
+struct resource *iores;
<+...
-io = dev_request_mem_region(d, n);
+iores = dev_request_mem_resource(d, n);
+if (IS_ERR(iores))
+	return PTR_ERR(iores);
+io = IOMEM(iores->start);
...+>
}

@@
identifier func;
@@
func(...) {
<+...
struct resource *iores;
-struct resource *iores;
...+>
}
// </smpl>

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-03-07 08:57:56 +01:00
Sascha Hauer 8ee5479a28 driver: Fix return check of dev_request_mem_region
dev_request_mem_region returns an ERR_PTR, fix places which check for a
NULL pointer instead. This patch has been generated with this semantic
patch, written by me and improved by Andrey Smirnov:

// <smpl>
@@
expression e;
expression e1;
@@
e = dev_request_mem_region(...);
...
-if (!e)
-	return e1;
+if (IS_ERR(e))
+	return PTR_ERR(e);

@ rule1 @
expression e;
@@
e = dev_request_mem_region(...);

@@
expression rule1.e;
identifier ret, label;
constant errno;
@@
if (!e) {
	...
(
-	ret = -errno;
+	ret = PTR_ERR(e);
	...
	goto label;
|
-	return -errno;
+	return PTR_ERR(e);
)
}

@depends on rule1@
expression rule1.e;
@@
-	if (e == NULL)
+	if (IS_ERR(e))
{
...
}
// </smpl>

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
2016-02-23 08:14:16 +01:00
Trent Piepho b097f7b910 i2c: core: Add client I2C address to devinfo
Useful bit of information.  Example:
barebox:/ devinfo dummy0
Bus: i2c
  Address: 0x52

Signed-off-by: Trent Piepho <tpiepho@kymetacorp.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-11-20 08:43:42 +01:00
Antony Pavlov 4aa3a0347c i2c: add pca954x bus multiplexer driver
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-11-19 08:58:26 +01:00
Antony Pavlov c3859ce93c i2c: import multiplexed I2C bus core support from linux kernel
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-11-19 08:58:26 +01:00
Sascha Hauer 901b13e243 i2c: Create for_each_i2c_adapter()
This can be used by the i2c_probe command to iterate over i2c adapters.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-11-19 08:58:25 +01:00
Andrey Smirnov 9e6f482cd8 i2c-imx: Use xzalloc instead of kzalloc
Driver's private data structure is allocated with kzalloc without any
code to check for kzalloc's possible failure. Fix that by replaceing
kzalloc with xzalloc.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-11-19 08:58:25 +01:00
Andrey Smirnov 0534926f41 i2c: Add support for DesignWare controllers
Add a driver for DesignWare I2C controller IP block found on several
SoCs including Altera SoC products

Tested using Terrasic SoCKit board and GPIO expander board with I2C
EEPROM on it

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-11-19 08:58:25 +01:00
Sascha Hauer e79fa9b5f0 i2c: fsl: Add bus recovery support
Useful for recovering busses. This needs additional device tree properties
describing the sda/scl gpios. The corresponding linux patch with the binding
description is currently under review.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-09-17 10:05:07 +02:00
Sascha Hauer 69dccb494a Merge branch 'for-next/misc' 2015-09-01 09:43:54 +02:00
Jan Luebbe ffcabbe125 i2c: gpio: add bus recovery support
Signed-off-by: Jan Luebbe <jluebbe@debian.org>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-08-20 07:47:15 +02:00
Jan Luebbe 4f32ba9fcb i2c: algo-bit: check if the bus is busy
If we have a timeout while waiting, try to recover.

Signed-off-by: Jan Luebbe <jluebbe@debian.org>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-08-20 07:47:15 +02:00
Jan Luebbe abcbcfca3a i2c: algo-bit: fix debug code
Replace jiffies from kernel code with get_time_ns. The flags variable
used in the readbytes debug output does not exist.

Signed-off-by: Jan Luebbe <jluebbe@debian.org>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-08-20 07:47:14 +02:00
Jan Luebbe fab3dc2bfb i2c-omap: add bus recovery support
This is based on commit 9dcb0e7b999db6c420c70fd32497a979a044fcdf from
the kernel with some additional fixes.

Signed-off-by: Jan Luebbe <jluebbe@debian.org>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-08-20 07:47:14 +02:00
Jan Luebbe 58fc376abf i2c-omap: clear ARDY twice
This implements the fix from the kernel commit
4cdbf7d346e7461c3b93a26707c852e2c9db3753.

Signed-off-by: Jan Luebbe <jluebbe@debian.org>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-08-20 07:47:14 +02:00
Jan Luebbe e1944fb6b2 i2c: add bus recovery infrastructure
This is based on the code introduced to the kernel in
5f9296ba21b3c395e53dd84e7ff9578f97f24295.

Signed-off-by: Jan Luebbe <jluebbe@debian.org>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-08-20 07:47:14 +02:00
Andrey Smirnov 1f6d1c0082 i2c-imx: Fix memory leak in i2c_fsl_probe()
All points of failure in the code of i2c_fsl_probe() happen after the
allocation of i2c_fsl, so all of them have to perform necessary
cleanup setups in case of failure.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-08-19 16:23:54 +02:00
Sascha Hauer 0dea9c7cf9 Merge branch 'for-next/ppc' 2015-08-06 12:33:16 +02:00
Juergen Borleis 90c52fe07a PPC/MPC5200: re-use the IMX I2C master driver for MPC5200
This IP core is shared between many FSL SoCs. The MPC5200 provides this
core as well.

Signed-off-by: Juergen Borleis <jbe@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-08-03 08:52:43 +02:00
Jan Luebbe 5d3cd266d2 i2c: only register enabled child nodes
Signed-off-by: Jan Luebbe <jluebbe@debian.org>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-07-09 10:19:41 +02:00
Sascha Hauer 7a429bfb3b Merge branch 'for-next/misc' 2015-06-09 09:26:44 +02:00
Robert Schwebel 92b7939211 i2c: omap: fix i2c bus number output
When probing from devicetree, the output for several i2c host
controllers prints out a bus number of -1:

i2c-omap 44e0b000.i2c: bus -1 rev0.11 at 400 kHz
i2c-omap 4802a000.i2c: bus -1 rev0.11 at 400 kHz
i2c-omap 4819c000.i2c: bus -1 rev0.11 at 400 kHz

The call to i2c_add_numbered_adapter() in probe finds out the next free
bus number, so we move the output to a location where the number is
already determined.

Signed-off-by: Robert Schwebel <r.schwebel@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-06-03 09:56:07 +02:00
Sascha Hauer 3dc08c3056 i2c: Use correct format specifier
'count' is of type u16, not size_t.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-05-15 07:01:42 +02:00
Sascha Hauer 4de5f732c0 Merge branch 'for-next/of-device-id' 2015-05-06 21:36:13 +02:00
Antony Pavlov 377d261708 of: use 'const void *' for struct of_device_id.data
Since 2011 barebox' of_device_id struct uses unsigned long type for data field:

    struct of_device_id {
            char *compatible;
            unsigned long data;
    };

Almost always struct of_device_id.data field are used as pointer
and need 'unsigned long' casting.

E.g. see 'git grep -A 4 of_device_id drivers/' output:

    drivers/ata/sata-imx.c:static __maybe_unused struct of_device_id imx_sata_dt_ids[] = {
    drivers/ata/sata-imx.c- {
    drivers/ata/sata-imx.c-         .compatible = "fsl,imx6q-ahci",
    drivers/ata/sata-imx.c-         .data = (unsigned long)&data_imx6,
    drivers/ata/sata-imx.c- }, {

Here is of_device_id struct in linux kernel v4.0:

    struct of_device_id {
            char name[32];
            char type[32];
            char compatible[128];
            const void *data;
    };

Changing of_device_id.data type to 'const void *data' will increase
barebox' linux kernel compatibility and decrease number of 'unsigned
long' casts.

Part of the patch was done using the 'coccinelle' tool with the
following semantic patch:

    @rule1@
    identifier dev;
    identifier type;
    identifier func;
    @@
    func(...) {
    <...
    - dev_get_drvdata(dev, (unsigned long *)&type)
    + dev_get_drvdata(dev, (const void **)&type)
    ...>
    }
    @rule2@
    identifier dev;
    identifier type;
    identifier func;
    identifier data;
    @@
    func(...) {
    <...
    - dev_get_drvdata(dev, (unsigned long *)&type->data)
    + dev_get_drvdata(dev, (const void **)&type->data)
    ...>
    }

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-04-30 08:12:57 +02:00
Antony Pavlov f993f94ae7 i2c: mv64xxx: continue probe when clock-frequency is missing
Based on this linux kernel commit:

    commit 0ce4bc1dbdd911ae1763e2d4ff36bd1b214a59f7
    Author: Chen-Yu Tsai <wens@csie.org>
    Date:   Mon Sep 1 22:28:13 2014 +0800

        i2c: mv64xxx: continue probe when clock-frequency is missing

        The "clock-frequency" DT property is listed as optional, However,
        the current code stores the return value of of_property_read_u32 in
        the return code of mv64xxx_of_config, but then forgets to clear it
        after setting the default value of "clock-frequency". It is then
        passed out to the main probe function, resulting in a probe failure
        when "clock-frequency" is missing.

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-04-17 07:31:35 +02:00
Sascha Hauer e0899dfa3b driver: Call remove function only when available
The bus implementations currently call the drivers remove
hook unconditionally, but this hook is seldomly populated. Only call
it when it's actually populated.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-03-17 07:24:50 +01:00
Jan Weitzel c5151cae17 i2c: omap: fix fclk_rate for ti,omap4-i2c
The compatible "ti,omap4-i2c" don't help to get fclk_rate. So set it acording to
cpu compatible: "ti,am33xx" and "ti,omap4"

Signed-off-by: Jan Weitzel <j.weitzel@phytec.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-01-06 14:46:51 +01:00
Sascha Hauer 7b4cc54579 Merge branch 'for-next/tegra' 2014-11-05 15:47:39 +01:00
Lucas Stach dfa6b3e46c i2c: at91: fix invalid length check
Signed-off-by: Lucas Stach <dev@lynxeye.de>
Acked-by: Bo Shen <voice.shen@atmel.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-10-21 13:08:02 +02:00
Lucas Stach 4e4d40c1ae i2c: tegra: move to fs initcall
i2c is needed to enable voltage rails that are later
needed by other drivers.

Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-10-08 08:39:01 +02:00
Sascha Hauer fa93e4fb60 Merge branch 'for-next/resource-err-ptr' 2014-10-02 08:54:42 +02:00
Sascha Hauer 61bf20dcc6 Merge branch 'for-next/at91' 2014-10-02 08:54:41 +02:00
Teresa Gámez 0abb68b107 i2c: omap: fix dts property "clock-frequency" usage
Looking at the linux kernel the clock-frequency property of
the device tree is used to set the bus speed and not the
fclk_rate. Adapted this to be compliant with linux kernel.

Signed-off-by: Teresa Gámez <t.gamez@phytec.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-10-02 07:50:16 +02:00
Bo Shen 791ff495fb I2C: at91: fix the method for interrupt
As the i2c-at91 driver won't work in the interrupt mode,
so need to poll the interrupts.

Signed-off-by: Bo Shen <voice.shen@atmel.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-09-25 08:10:56 +02:00
Raphaël Poggi a0ca2c13f6 i2c: at91: add support of device tree
Signed-off-by: Raphaël Poggi <poggi.raph@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-09-25 08:10:56 +02:00
Raphaël Poggi ccc282fb1b i2c: at91: add at91sam9x5 config
Signed-off-by: Raphaël Poggi <poggi.raph@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-09-25 08:10:56 +02:00
Raphaël Poggi d78e8051f3 i2c: at91: fix coding style issue
Signed-off-by: Raphaël Poggi <poggi.raph@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-09-25 08:10:56 +02:00