Re: [RFC PATCH 1/5] i2c: introduce i2c-cbus driver

2012-08-29 Thread Tony Lindgren
* Aaro Koskinen  [120828 14:35]:
> Add i2c driver to enable access to devices behind CBUS on Nokia Internet
> Tablets.

Can you please do also a separate patch for the device tree binding for
getting the GPIO pins for this controller? 

Other than that thanks for doing this and:

Acked-by: Tony Lindgren 
--
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] i2c: omap: Prevent NULL pointer dereference in remove

2012-08-29 Thread Jean Delvare
On Thu, 23 Aug 2012 19:51:26 +0530, Shubhrajyoti D wrote:
> Prevent the NULL pointer access of pdev->dev in remove. The platform_device 
> is anyways
> deleted so remove  platform_set_drvdata(pdev, NULL);.

No, the platform device isn't deleted. The i2c adapters are deleted but
the underlying platform device is not.

> 
> [  654.961761] Unable to handle kernel NULL pointer dereference at virtual 
> address 0070
> [  654.970611] pgd = df254000
> [  654.973480] [0070] *pgd=9f1da831, *pte=, *ppte=
> [  654.980163] Internal error: Oops: 17 [#1] SMP ARM
> [  654.985076] Modules linked in:
> [  654.988281] CPU: 1Not tainted  (3.6.0-rc1-00031-ge547de1-dirty #339)
> [  654.995330] PC is at omap_i2c_runtime_resume+0x8/0x148
> [  655.000732] LR is at omap_i2c_runtime_resume+0x8/0x148
> 
> Signed-off-by: Shubhrajyoti D 
> ---
>  drivers/i2c/busses/i2c-omap.c |3 ---
>  1 files changed, 0 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
> index 5d19a49..84fbef6 100644
> --- a/drivers/i2c/busses/i2c-omap.c
> +++ b/drivers/i2c/busses/i2c-omap.c
> @@ -1098,7 +1098,6 @@ err_unuse_clocks:
>   iounmap(dev->base);
>   pm_runtime_disable(&pdev->dev);
>  err_free_mem:
> - platform_set_drvdata(pdev, NULL);
>   kfree(dev);
>  err_release_region:
>   release_mem_region(mem->start, resource_size(mem));

This can't be right. You're about to free the memory, so if anyone
still can access it through platform_get_drvdata(), you're in trouble
anyway. But I don't think this is the case here.

> @@ -1112,8 +,6 @@ static int __devexit omap_i2c_remove(struct 
> platform_device *pdev)
>   struct resource *mem;
>   int ret;
>  
> - platform_set_drvdata(pdev, NULL);
> -

This OTOH is a good catch. But the problem isn't with calling
platform_set_drvdata(pdev, NULL) per se. The problem is with calling it
too early. It should be called after i2c_del_adapter(), and ideally
before freeing the memory.

>   free_irq(dev->irq, dev);
>   i2c_del_adapter(&dev->adapter);
>   ret = pm_runtime_get_sync(&pdev->dev);


-- 
Jean Delvare
--
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: i2c-eg20t: regression since i2c_add_numbered_adapter change

2012-08-29 Thread Jean Delvare
Hi guys,

Sorry for joining the discussion a little late, I was on vacation.

On Thu, 23 Aug 2012 16:28:52 +0800, Feng Tang wrote:
> On Wed, 22 Aug 2012 11:17:51 +0200
> Alexander Stein  wrote:
> > Am Mittwoch, 22. August 2012, 16:04:39 schrieb Feng Tang:
> > > > Why use a fixed one? Give the driver (and maybe every i2c bus driver) a 
> > > > parameter which sets the base bus number it should use.
> > > > E.g. i2c-eg20t.base-bus-num=2 so it will register the bus numbers 
> > > > starting from 2. If this parameter is unset. It would use the first 
> > > > free one, thus simply using i2c_add_adapter.

Looks like what media and sound drivers are/were doing to assign fixed
numbers to their devices. But my understanding is that this is a legacy
thing and nobody should need to use that any longer. Adding this to all
or even some i2c bus drivers looks like the wrong example to follow. If
your system has more than one device supported by the driver, it
doesn't even reliably guarantee fixed I2C bus numbers (especially if
some can be hot-plugged.)

> > > The reason we need a fixed number is it is easier for platform code
> > > which needs to register dozens of i2c devices to different controllers
> > > with i2c_register_board_info, and they need provide a bus number for
> > > each i2c device, this _binding_ info is not detectable but have to
> > > be fixed.

Whenever you call i2c_register_board_info(), every I2C bus number
referenced in the I2C device list passed as a parameter is reserved for
static I2C bus numbers, dynamic I2C bus numbers will never overlap.

So in the quoted example, if i2c-isch is able to dynamically pick I2C
bus number 0 while i2c-eg20t want it statically, it means that either
no device was declared on bus 0 with i2c_register_board_info(), or
i2c_register_board_info() was called too late in the game.

Note that there was an assumption at the time the code was written,
that there was no need or reason to reserve a static I2C bus number if
no slave device was declared on said I2C bus. I never much liked it but
it never caused problems so far. This means that either:
* you call i2c_register_board_info() to register your slave I2C devices
  and all the affected I2C bus drivers call i2c_add_numbered_adapter();
  or
* you don't call i2c_register_board_info() and all I2C bus drivers call
  i2c_add_adapter().
You can't mix, i.e. if you don't register any slave device on a bus but
the bus driver still calls i2c_add_numbered_adapter(), it may fail.

If this is a problem now on some systems, it should be easy enough to
work around by adding a specific function to reserve an I2C bus number
for static allocation, even without declaring any slave device on it.
This function would be called at the same time
i2c_register_board_info() typically is.

> > Yes, I'm aware of that. With "Why use a fixed one?" I meant why hard-code 
> > it into the driver. I should be changeable.
> > Because this is/was not possible in general to use i2c_register_board_info, 
> > so we used an echo to /sys/bus/i2c/devices/i2c-0/new_device or 
> > /sys/bus/i2c/devices/i2c-1/new_device.

Please elaborate on "this is/was not possible in general to use
i2c_register_board_info." You are supposed to call it as part of your
platform setup, so if it is not possible for you, whatever the problem
is needs to be addressed.

> Yeah, our EG20T kernel used to use the same "echo 
> /sys/bus/i2c/devices/i2c-x/new_device"
> way, but we found out it is not convenient for:
> 1. needs extra user space script, why not make it just work in kernel after
> boot? We have several i2c devices like touchscreen/radio which we wants them
> just work without depending user space action.

It should indeed be handled all in kernel space, using
i2c_register_board_info().

> 2. The i2c bus number is not fixed, which make the user space script even
> harder, as that number depends whether we compile into kernel all the i2c
> controllers (eg20t and isch) and whether these driver are compiled as
> modules and their loading order.

You can always look-up the right I2C bus number based on its name,
assuming your driver properly names them. There is some code doing that
at:
http://www.lm-sensors.org/browser/i2c-tools/trunk/tools/i2cbusses.c#L297

Ideally this code should move to libi2c and/or i2cdetect should offer
an interface to it, so it can easily be called from custom tools and
scripts.

> Thus we come out with this fixed bus number registering.
> 
> As I said before, either your module parameter "base_bus_num" solution
> or my fixed bus number offset are ok to me. Will you cook a patch?

I think the real problem you have here is that your platform setup code
doesn't (or is not able to) allocate the bus IDs globally. It really
should. If you have an embedded system using both i2c-eg20t and
i2c-isch, the platform setup code should decide upfront who gets what
I2C bus IDs, otherwise it's impossible to declare slave devices on
these I2C buses. And these bus drivers should

Re: [PATCH 4/5] i2c-i801: Add Device IDs for Intel Lynx Point-LP PCH

2012-08-29 Thread Jean Delvare
Hi James,

Quite a long Cc list for such a trivial patch...

On Thu,  9 Aug 2012 09:43:52 -0700, james.d.rals...@intel.com wrote:
> From: James Ralston 
> 
> This patch adds the SMBus Device IDs for the Intel Lynx Point-LP PCH. The 
> Device IDs are defined in drivers/i2c/busses/i2c-i801.c

I'm curious what the "LP" stands for. Low power?

> 
> Signed-off-by: James Ralston 
> ---
>  Documentation/i2c/busses/i2c-i801 |1 +
>  drivers/i2c/busses/Kconfig|1 +
>  drivers/i2c/busses/i2c-i801.c |3 +++
>  3 files changed, 5 insertions(+), 0 deletions(-)
> 
> diff --git a/Documentation/i2c/busses/i2c-i801 
> b/Documentation/i2c/busses/i2c-i801
> index 615142d..53207df 100644
> --- a/Documentation/i2c/busses/i2c-i801
> +++ b/Documentation/i2c/busses/i2c-i801
> @@ -21,6 +21,7 @@ Supported adapters:
>* Intel DH89xxCC (PCH)
>* Intel Panther Point (PCH)
>* Intel Lynx Point (PCH)
> +  * Intel Lynx Point_LP (PCH)

You spelled it "Lynx Point-LP" (with dash not underscore) in the patch
summary. Consistency in naming would be preferred. I'll use a dash
everywhere and apply your patch.

> Datasheets: Publicly available at the Intel website
>  
>  On Intel Patsburg and later chipsets, both the normal host SMBus controller
> diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
> index 2e7530a..3500af7 100644
> --- a/drivers/i2c/busses/Kconfig
> +++ b/drivers/i2c/busses/Kconfig
> @@ -104,6 +104,7 @@ config I2C_I801
>   DH89xxCC (PCH)
>   Panther Point (PCH)
>   Lynx Point (PCH)
> + Lynx Point_LP (PCH)
>  
> This driver can also be built as a module.  If so, the module
> will be called i2c-i801.
> diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
> index 898dcf9..c467038 100644
> --- a/drivers/i2c/busses/i2c-i801.c
> +++ b/drivers/i2c/busses/i2c-i801.c
> @@ -52,6 +52,7 @@
>DH89xxCC (PCH)0x2330 32 hard yes yes yes
>Panther Point (PCH)   0x1e22 32 hard yes yes yes
>Lynx Point (PCH)  0x8c22 32 hard yes yes yes
> +  Lynx Point_LP (PCH)   0x9c22 32 hard yes yes yes
>  
>Features supported by this driver:
>Software PEC no
> @@ -155,6 +156,7 @@
>  #define PCI_DEVICE_ID_INTEL_DH89XXCC_SMBUS   0x2330
>  #define PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS  0x3b30
>  #define PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS  0x8c22
> +#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS   0x9c22
>  
>  struct i801_priv {
>   struct i2c_adapter adapter;
> @@ -771,6 +773,7 @@ static DEFINE_PCI_DEVICE_TABLE(i801_ids) = {
>   { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_DH89XXCC_SMBUS) },
>   { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 
> PCI_DEVICE_ID_INTEL_PANTHERPOINT_SMBUS) },
>   { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS) 
> },
> + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 
> PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS) },
>   { 0, }
>  };
>  


-- 
Jean Delvare
--
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] i2c multiplexer driver for Proliant microserver N36L

2012-08-29 Thread Jean Delvare
Eddi, Thomas,

On Wed, 14 Mar 2012 09:28:54 +0100, Eddi De Pieri wrote:
> Hi Thomas,
> 
> > With the updated patch and the modified sensors-detect I have been
> > able to probe all ports and have not encountered the power issue
> > again. If no further issues are identified I will seperate the patch
> > into stages and submit for review.
> 
> I confirm that your patch works well on my proliant n36l and solve the
> power issue.
> 
> Thank you for rewrote my patch.

Recent mainline changes to the i2c-piix4 driver make the patch no
longer apply, so I can't push it upstream. Can either of you please
rebase the patch on top of Linus' latest kernel and resubmit?

Thanks,
-- 
Jean Delvare
--
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 v11 2/4] Replace clk_lookup.con_id with clk_lookup.dev_id entries for twi clk

2012-08-29 Thread Nikolaus Voss
The old driver used con_id clock entries. Convert to use dev_id
for clock lookup via standard method.

Signed-off-by: Nikolaus Voss 
---
 arch/arm/mach-at91/at91rm9200.c  |1 +
 arch/arm/mach-at91/at91sam9260.c |1 +
 arch/arm/mach-at91/at91sam9261.c |1 +
 arch/arm/mach-at91/at91sam9263.c |1 +
 arch/arm/mach-at91/at91sam9g45.c |2 ++
 arch/arm/mach-at91/at91sam9rl.c  |2 ++
 arch/arm/mach-at91/at91sam9x5.c  |3 +++
 7 files changed, 11 insertions(+)

diff --git a/arch/arm/mach-at91/at91rm9200.c b/arch/arm/mach-at91/at91rm9200.c
index 2691768..cf354a3 100644
--- a/arch/arm/mach-at91/at91rm9200.c
+++ b/arch/arm/mach-at91/at91rm9200.c
@@ -186,6 +186,7 @@ static struct clk_lookup periph_clocks_lookups[] = {
CLKDEV_CON_DEV_ID("pclk", "ssc.0", &ssc0_clk),
CLKDEV_CON_DEV_ID("pclk", "ssc.1", &ssc1_clk),
CLKDEV_CON_DEV_ID("pclk", "ssc.2", &ssc2_clk),
+   CLKDEV_CON_DEV_ID(NULL, "at91_i2c", &twi_clk),
/* fake hclk clock */
CLKDEV_CON_DEV_ID("hclk", "at91_ohci", &ohci_clk),
CLKDEV_CON_ID("pioA", &pioA_clk),
diff --git a/arch/arm/mach-at91/at91sam9260.c b/arch/arm/mach-at91/at91sam9260.c
index 2b1e438..2e56321 100644
--- a/arch/arm/mach-at91/at91sam9260.c
+++ b/arch/arm/mach-at91/at91sam9260.c
@@ -210,6 +210,7 @@ static struct clk_lookup periph_clocks_lookups[] = {
CLKDEV_CON_DEV_ID("t1_clk", "atmel_tcb.1", &tc4_clk),
CLKDEV_CON_DEV_ID("t2_clk", "atmel_tcb.1", &tc5_clk),
CLKDEV_CON_DEV_ID("pclk", "ssc.0", &ssc_clk),
+   CLKDEV_CON_DEV_ID(NULL, "at91_i2c", &twi_clk),
/* more usart lookup table for DT entries */
CLKDEV_CON_DEV_ID("usart", "f200.serial", &mck),
CLKDEV_CON_DEV_ID("usart", "fffb.serial", &usart0_clk),
diff --git a/arch/arm/mach-at91/at91sam9261.c b/arch/arm/mach-at91/at91sam9261.c
index c77d503..f21196d 100644
--- a/arch/arm/mach-at91/at91sam9261.c
+++ b/arch/arm/mach-at91/at91sam9261.c
@@ -177,6 +177,7 @@ static struct clk_lookup periph_clocks_lookups[] = {
CLKDEV_CON_DEV_ID("pclk", "ssc.1", &ssc1_clk),
CLKDEV_CON_DEV_ID("pclk", "ssc.2", &ssc2_clk),
CLKDEV_CON_DEV_ID("hclk", "at91_ohci", &hck0),
+   CLKDEV_CON_DEV_ID(NULL, "at91_i2c", &twi_clk),
CLKDEV_CON_ID("pioA", &pioA_clk),
CLKDEV_CON_ID("pioB", &pioB_clk),
CLKDEV_CON_ID("pioC", &pioC_clk),
diff --git a/arch/arm/mach-at91/at91sam9263.c b/arch/arm/mach-at91/at91sam9263.c
index ed91c7e..71305fa 100644
--- a/arch/arm/mach-at91/at91sam9263.c
+++ b/arch/arm/mach-at91/at91sam9263.c
@@ -192,6 +192,7 @@ static struct clk_lookup periph_clocks_lookups[] = {
CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.0", &spi0_clk),
CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.1", &spi1_clk),
CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.0", &tcb_clk),
+   CLKDEV_CON_DEV_ID(NULL, "at91_i2c", &twi_clk),
/* fake hclk clock */
CLKDEV_CON_DEV_ID("hclk", "at91_ohci", &ohci_clk),
CLKDEV_CON_ID("pioA", &pioA_clk),
diff --git a/arch/arm/mach-at91/at91sam9g45.c b/arch/arm/mach-at91/at91sam9g45.c
index 4792682..2944fc7 100644
--- a/arch/arm/mach-at91/at91sam9g45.c
+++ b/arch/arm/mach-at91/at91sam9g45.c
@@ -228,6 +228,8 @@ static struct clk_lookup periph_clocks_lookups[] = {
CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.1", &spi1_clk),
CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.0", &tcb0_clk),
CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.1", &tcb0_clk),
+   CLKDEV_CON_DEV_ID(NULL, "at91_i2c.0", &twi0_clk),
+   CLKDEV_CON_DEV_ID(NULL, "at91_i2c.1", &twi1_clk),
CLKDEV_CON_DEV_ID("pclk", "ssc.0", &ssc0_clk),
CLKDEV_CON_DEV_ID("pclk", "ssc.1", &ssc1_clk),
CLKDEV_CON_DEV_ID(NULL, "atmel-trng", &trng_clk),
diff --git a/arch/arm/mach-at91/at91sam9rl.c b/arch/arm/mach-at91/at91sam9rl.c
index e420085..8a97218 100644
--- a/arch/arm/mach-at91/at91sam9rl.c
+++ b/arch/arm/mach-at91/at91sam9rl.c
@@ -185,6 +185,8 @@ static struct clk_lookup periph_clocks_lookups[] = {
CLKDEV_CON_DEV_ID("t2_clk", "atmel_tcb.0", &tc2_clk),
CLKDEV_CON_DEV_ID("pclk", "ssc.0", &ssc0_clk),
CLKDEV_CON_DEV_ID("pclk", "ssc.1", &ssc1_clk),
+   CLKDEV_CON_DEV_ID(NULL, "at91_i2c.0", &twi0_clk),
+   CLKDEV_CON_DEV_ID(NULL, "at91_i2c.1", &twi1_clk),
CLKDEV_CON_ID("pioA", &pioA_clk),
CLKDEV_CON_ID("pioB", &pioB_clk),
CLKDEV_CON_ID("pioC", &pioC_clk),
diff --git a/arch/arm/mach-at91/at91sam9x5.c b/arch/arm/mach-at91/at91sam9x5.c
index 1b144b4..def85e5 100644
--- a/arch/arm/mach-at91/at91sam9x5.c
+++ b/arch/arm/mach-at91/at91sam9x5.c
@@ -231,6 +231,9 @@ static struct clk_lookup periph_clocks_lookups[] = {
CLKDEV_CON_DEV_ID("t0_clk", "f800c000.timer", &tcb0_clk),
CLKDEV_CON_DEV_ID("dma_clk", "ec00.dma-controller", &dma0_clk),
CLKDEV_CON_DEV_ID("dma_clk", "ee00.dma-controller", &dma1_clk),
+   CLKDEV_CON_DEV_ID(NULL, "at91_i2c.0", &twi0_clk),
+   CLKDEV_CON_DEV_ID(NULL, "at91_i2c.1", &

[PATCH v11 1/4] drivers/i2c/busses/i2c-at91.c: remove old polling driver

2012-08-29 Thread Nikolaus Voss
Signed-off-by: Nikolaus Voss 
---
 arch/arm/mach-at91/include/mach/at91_twi.h |   68 --
 drivers/i2c/busses/Makefile|1 -
 drivers/i2c/busses/i2c-at91.c  |  314 
 3 files changed, 383 deletions(-)
 delete mode 100644 arch/arm/mach-at91/include/mach/at91_twi.h
 delete mode 100644 drivers/i2c/busses/i2c-at91.c

diff --git a/arch/arm/mach-at91/include/mach/at91_twi.h 
b/arch/arm/mach-at91/include/mach/at91_twi.h
deleted file mode 100644
index bb2880f..000
--- a/arch/arm/mach-at91/include/mach/at91_twi.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * arch/arm/mach-at91/include/mach/at91_twi.h
- *
- * Copyright (C) 2005 Ivan Kokshaysky
- * Copyright (C) SAN People
- *
- * Two-wire Interface (TWI) registers.
- * Based on AT91RM9200 datasheet revision E.
- *
- * 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.
- */
-
-#ifndef AT91_TWI_H
-#define AT91_TWI_H
-
-#defineAT91_TWI_CR 0x00/* Control Register */
-#defineAT91_TWI_START  (1 <<  0)   /* Send a Start 
Condition */
-#defineAT91_TWI_STOP   (1 <<  1)   /* Send a Stop 
Condition */
-#defineAT91_TWI_MSEN   (1 <<  2)   /* Master 
Transfer Enable */
-#defineAT91_TWI_MSDIS  (1 <<  3)   /* Master 
Transfer Disable */
-#defineAT91_TWI_SVEN   (1 <<  4)   /* Slave 
Transfer Enable [SAM9260 only] */
-#defineAT91_TWI_SVDIS  (1 <<  5)   /* Slave 
Transfer Disable [SAM9260 only] */
-#defineAT91_TWI_SWRST  (1 <<  7)   /* Software 
Reset */
-
-#defineAT91_TWI_MMR0x04/* Master Mode Register 
*/
-#defineAT91_TWI_IADRSZ (3<<  8)/* Internal 
Device Address Size */
-#defineAT91_TWI_IADRSZ_NO  (0 << 8)
-#defineAT91_TWI_IADRSZ_1   (1 << 8)
-#defineAT91_TWI_IADRSZ_2   (2 << 8)
-#defineAT91_TWI_IADRSZ_3   (3 << 8)
-#defineAT91_TWI_MREAD  (1<< 12)/* Master Read 
Direction */
-#defineAT91_TWI_DADR   (0x7f << 16)/* Device 
Address */
-
-#defineAT91_TWI_SMR0x08/* Slave Mode Register 
[SAM9260 only] */
-#defineAT91_TWI_SADR   (0x7f << 16)/* Slave 
Address */
-
-#defineAT91_TWI_IADR   0x0c/* Internal Address 
Register */
-
-#defineAT91_TWI_CWGR   0x10/* Clock Waveform 
Generator Register */
-#defineAT91_TWI_CLDIV  (0xff <<  0)/* Clock Low 
Divisor */
-#defineAT91_TWI_CHDIV  (0xff <<  8)/* Clock High 
Divisor */
-#defineAT91_TWI_CKDIV  (7<< 16)/* Clock 
Divider */
-
-#defineAT91_TWI_SR 0x20/* Status Register */
-#defineAT91_TWI_TXCOMP (1 <<  0)   /* Transmission 
Complete */
-#defineAT91_TWI_RXRDY  (1 <<  1)   /* Receive 
Holding Register Ready */
-#defineAT91_TWI_TXRDY  (1 <<  2)   /* Transmit 
Holding Register Ready */
-#defineAT91_TWI_SVREAD (1 <<  3)   /* Slave Read 
[SAM9260 only] */
-#defineAT91_TWI_SVACC  (1 <<  4)   /* Slave Access 
[SAM9260 only] */
-#defineAT91_TWI_GACC   (1 <<  5)   /* General Call 
Access [SAM9260 only] */
-#defineAT91_TWI_OVRE   (1 <<  6)   /* Overrun 
Error [AT91RM9200 only] */
-#defineAT91_TWI_UNRE   (1 <<  7)   /* Underrun 
Error [AT91RM9200 only] */
-#defineAT91_TWI_NACK   (1 <<  8)   /* Not 
Acknowledged */
-#defineAT91_TWI_ARBLST (1 <<  9)   /* Arbitration 
Lost [SAM9260 only] */
-#defineAT91_TWI_SCLWS  (1 << 10)   /* Clock Wait 
State [SAM9260 only] */
-#defineAT91_TWI_EOSACC (1 << 11)   /* End of Slave 
Address [SAM9260 only] */
-
-#defineAT91_TWI_IER0x24/* Interrupt Enable 
Register */
-#defineAT91_TWI_IDR0x28/* Interrupt Disable 
Register */
-#defineAT91_TWI_IMR0x2c/* Interrupt Mask 
Register */
-#defineAT91_TWI_RHR0x30/* Receive Holding 
Register */
-#defineAT91_TWI_THR0x34/* Transmit Holding 
Register */
-
-#endif
-
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
ind

[PATCH v11 3/4] drivers/i2c/busses/i2c-at91.c: add new driver

2012-08-29 Thread Nikolaus Voss
This driver has the following properties compared to the old driver:
1. Support for multiple interfaces.
2. Interrupt driven I/O as opposed to polling/busy waiting.
3. Support for _one_ repeated start (Sr) condition, which is enough
   for most real-world applications including all SMBus transfer types.
   (The hardware does not support issuing arbitrary Sr conditions on the
bus.)

testing: SoC: at91sam9g45
 - BQ20Z80 battery SMBus client.
 - on a 2.6.38 kernel with several i2c clients (temp-sensor,
   audio-codec, touchscreen-controller, w1-bridge, io-expanders)

Signed-off-by: Nikolaus Voss 
Reviewed-by: Felipe Balbi 
Tested-by: Hubert Feurstein 

v12: - corrected wrong id_entry on sam9261 twi gpio pdev
v11: - fix for flags persistency suggested by Carsten Behling
 - calc_twi_clock fix for sam9261 by Ludovic Desroches
v10: - applied fix for RXRDY overrun bug submitted by Hubert Feurstein
 - applied fix for calculating twi_clk
v9: - merge i2c-at91.c patches to single patch
- rewrite cwgr reg after timeout
v8: - remove local include
- remove cpu_is_rm9200() and put twi hw bug info in platform_device
- use readl/writel_relaxed instead of __raw_readl/writel
v7: i)  fix bug if internal address > 1 byte
ii) send stop when len == 1 (both reported by Carsten Behling)
v6: support for I2C_SMBUS_BLOCK_DATA transfers.
Better use of clk_(un)prepare().
More sensible transfer timeout.
v5: Another round of review comments from Ryan Mallon, Felipe Balbi
and Russell King: convert twi clk to use .dev_id, cleanups
v4: Integrated more review comments from Ryan Mallon and Felipe Balbi:
Moved register include file to local include, code cleanups
v3: Integrated review comments from Ryan Mallon and Felipe Balbi
v2: Fixed whitespace issue
---
 arch/arm/mach-at91/at91rm9200_devices.c  |9 +
 arch/arm/mach-at91/at91sam9261_devices.c |9 +
 drivers/i2c/busses/Kconfig   |   11 +-
 drivers/i2c/busses/Makefile  |1 +
 drivers/i2c/busses/i2c-at91.c|  493 ++
 5 files changed, 516 insertions(+), 7 deletions(-)
 create mode 100644 drivers/i2c/busses/i2c-at91.c

diff --git a/arch/arm/mach-at91/at91rm9200_devices.c 
b/arch/arm/mach-at91/at91rm9200_devices.c
index e6b7d05..2977a2d 100644
--- a/arch/arm/mach-at91/at91rm9200_devices.c
+++ b/arch/arm/mach-at91/at91rm9200_devices.c
@@ -494,9 +494,18 @@ static struct resource twi_resources[] = {
},
 };
 
+static const struct platform_device_id twi_ip_type = {
+   /*
+* driver_data is 1 for RM9200 compatible ip, see enum twi_ip_id in
+* drivers/i2c/busses/i2c-at91.c
+*/
+   .driver_data= 1,
+};
+
 static struct platform_device at91rm9200_twi_device = {
.name   = "at91_i2c",
.id = -1,
+   .id_entry   = &twi_ip_type,
.resource   = twi_resources,
.num_resources  = ARRAY_SIZE(twi_resources),
 };
diff --git a/arch/arm/mach-at91/at91sam9261_devices.c 
b/arch/arm/mach-at91/at91sam9261_devices.c
index 9295e90..aeb2eed 100644
--- a/arch/arm/mach-at91/at91sam9261_devices.c
+++ b/arch/arm/mach-at91/at91sam9261_devices.c
@@ -316,9 +316,18 @@ static struct resource twi_resources[] = {
},
 };
 
+static const struct platform_device_id twi_ip_type = {
+   /*
+* driver_data is 2 for SAM9261 compatible ip, see enum twi_ip_id in
+* drivers/i2c/busses/i2c-at91.c
+*/
+   .driver_data= 2,
+};
+
 static struct platform_device at91sam9261_twi_device = {
.name   = "at91_i2c",
.id = -1,
+   .id_entry   = &twi_ip_type,
.resource   = twi_resources,
.num_resources  = ARRAY_SIZE(twi_resources),
 };
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 7244c8b..6b74287 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -286,18 +286,15 @@ comment "I2C system bus drivers (mostly embedded / 
system-on-chip)"
 
 config I2C_AT91
tristate "Atmel AT91 I2C Two-Wire interface (TWI)"
-   depends on ARCH_AT91 && EXPERIMENTAL && BROKEN
+   depends on ARCH_AT91 && EXPERIMENTAL
help
  This supports the use of the I2C interface on Atmel AT91
  processors.
 
- This driver is BROKEN because the controller which it uses
- will easily trigger RX overrun and TX underrun errors.  Using
- low I2C clock rates may partially work around those issues
- on some systems.  Another serious problem is that there is no
- documented way to issue repeated START conditions, as needed
+ A serious problem is that there is no documented way to issue
+ repeated START conditions for more than two messages, as needed
  to support combined I2C messages.  Use the i2c-gpio driver
- unless your system can cope with those limitations.
+ unless your system can c

[PATCH v11 4/4] G45 TWI: remove open drain setting for twi function gpios

2012-08-29 Thread Nikolaus Voss
The G45 datasheets explicitly states that setting the open drain property
on peripheral function gpios is not allowed. (How about other A91 chips?)

Signed-off-by: Nikolaus Voss 
---
 arch/arm/mach-at91/at91sam9g45_devices.c |6 --
 1 file changed, 6 deletions(-)

diff --git a/arch/arm/mach-at91/at91sam9g45_devices.c 
b/arch/arm/mach-at91/at91sam9g45_devices.c
index eec5eb6..2134663 100644
--- a/arch/arm/mach-at91/at91sam9g45_devices.c
+++ b/arch/arm/mach-at91/at91sam9g45_devices.c
@@ -686,18 +686,12 @@ void __init at91_add_device_i2c(short i2c_id, struct 
i2c_board_info *devices, in
/* pins used for TWI interface */
if (i2c_id == 0) {
at91_set_A_periph(AT91_PIN_PA20, 0);/* TWD */
-   at91_set_multi_drive(AT91_PIN_PA20, 1);
-
at91_set_A_periph(AT91_PIN_PA21, 0);/* TWCK */
-   at91_set_multi_drive(AT91_PIN_PA21, 1);
 
platform_device_register(&at91sam9g45_twi0_device);
} else {
at91_set_A_periph(AT91_PIN_PB10, 0);/* TWD */
-   at91_set_multi_drive(AT91_PIN_PB10, 1);
-
at91_set_A_periph(AT91_PIN_PB11, 0);/* TWCK */
-   at91_set_multi_drive(AT91_PIN_PB11, 1);
 
platform_device_register(&at91sam9g45_twi1_device);
}
-- 
1.7.9.5

--
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 v11 0/4] AT91: replace old i2c-at91.c TWI driver

2012-08-29 Thread Nikolaus Voss
The old driver has two main deficencies:
i)  No repeated start (Sr) condiction is possible, this makes it unusable
e.g. for most SMBus transfers.
ii) I/O was done with polling/busy waiting what caused over-/underruns
even at light system loads and clock speeds.

The new driver overcomes these deficencies and in addition allows for
more than one TWI interface.

A remaining limitation is the fact, that only one repeated start is
possible (two concatenated messages). This limitation is imposed by
the hardware. However, this should not be a problem as all common
i2c-client communication does not rely on more than one repeated start.

Changes since v11:
- corrected wrong id_entry on sam9261 twi gpio pdev

Nikolaus Voss (4):
  drivers/i2c/busses/i2c-at91.c: remove old polling driver
  Replace clk_lookup.con_id with clk_lookup.dev_id entries for twi clk
  drivers/i2c/busses/i2c-at91.c: add new driver
  G45 TWI: remove open drain setting for twi function gpios

 arch/arm/mach-at91/at91rm9200.c|1 +
 arch/arm/mach-at91/at91rm9200_devices.c|9 +
 arch/arm/mach-at91/at91sam9260.c   |1 +
 arch/arm/mach-at91/at91sam9261.c   |1 +
 arch/arm/mach-at91/at91sam9261_devices.c   |9 +
 arch/arm/mach-at91/at91sam9263.c   |1 +
 arch/arm/mach-at91/at91sam9g45.c   |2 +
 arch/arm/mach-at91/at91sam9g45_devices.c   |6 -
 arch/arm/mach-at91/at91sam9rl.c|2 +
 arch/arm/mach-at91/at91sam9x5.c|3 +
 arch/arm/mach-at91/include/mach/at91_twi.h |   68 
 drivers/i2c/busses/Kconfig |   11 +-
 drivers/i2c/busses/i2c-at91.c  |  591 ++--
 13 files changed, 418 insertions(+), 287 deletions(-)
 delete mode 100644 arch/arm/mach-at91/include/mach/at91_twi.h

-- 
1.7.9.5

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