Re: [PATCH] I2C driver supporting Moorestown and Medfield platform
On Wed, Oct 27, 2010 at 12:44:03PM +0100, Alan Cox wrote: (Updated to address Ben's comments. With regard to the message segment restriction it's not something we hit on the actual platform so while I will investigate that further I don't think its a blocker to submission. At worst its a spot over-restrictive) ok, that's not so much of a problem. I'll add that to -next and then look at pusing it at the end of the week. -- Ben -- To unsubscribe from this list: send the line unsubscribe linux-i2c in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] I2C driver supporting Moorestown and Medfield platform
(Updated to address Ben's comments. With regard to the message segment restriction it's not something we hit on the actual platform so while I will investigate that further I don't think its a blocker to submission. At worst its a spot over-restrictive) From: Wen Wang wen.w.w...@intel.com Initial release of the driver. Updated and verified on hardware. Cleaned up as follows Alan Cox: Squash down the switches into tables, and use the PCI ident field. We could perhaps take this further and put the platform and port number into this. uint32t - u32 bracketing of case statements spacing and '!' usage Check the speed (which is now 0/1/2) is valid and ignore otherwise. Fix remaining problems/suggestions from Jean's review Fix items from Ben's review Arjan van de Ven: Initial power management hooks Yong Wang youg.y.w...@intel.com: Shared IRQ support Wen Wang wen.w.w...@intel.com: D3 support Fixes for OCT test runs Interrupt optimisations Hong Liu hong@intel.com The runtime PM code is working on the wrong device (i2c_adapter-dev). The correct one should be pci_dev-dev. This breaks attached i2c slave devices with runtime PM enabled. Slave device needs to runtime resume parent device before runtime resuming itself, but we always get error since we don't have pm_runtime callback for i2c_adapter-dev. Bin Yang bin.y...@intel.com: Update speed table Saadi Maalem saadi.maa...@intel.com: Clear all interrupts in the hardware init Celine Chotard celinex.chot...@intel.com: Correct ordering of clear/disable of IRQs Signed-off-by: Wen Wang wen.w.w...@intel.com Signed-off-by: Yong Wang yong.y.w...@intel.com Signed-off-by: Hong Liu hong@intel.com Signed-off-by: Bin Yang bin.y...@intel.com Signed-off-by: Arjan van de Ven ar...@linux.intel.com Signed-off-by: Alan Cox a...@linux.intel.com --- drivers/i2c/busses/Kconfig |9 drivers/i2c/busses/Makefile|1 drivers/i2c/busses/i2c-intel-mid.c | 1135 3 files changed, 1145 insertions(+), 0 deletions(-) create mode 100644 drivers/i2c/busses/i2c-intel-mid.c diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index fd455a2..a62f99e 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig @@ -396,6 +396,15 @@ config I2C_IMX This driver can also be built as a module. If so, the module will be called i2c-imx. +config I2C_INTEL_MID + tristate Intel Moorestown/Medfield Platform I2C controller + help + Say Y here if you have an Intel Moorestown/Medfield platform I2C + controller. + + This support is also available as a module. If so, the module + will be called i2c-intel-mid. + config I2C_IOP3XX tristate Intel IOPx3xx and IXP4xx on-chip I2C interface depends on ARCH_IOP32X || ARCH_IOP33X || ARCH_IXP4XX || ARCH_IOP13XX diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile index 033ad41..84cb16a 100644 --- a/drivers/i2c/busses/Makefile +++ b/drivers/i2c/busses/Makefile @@ -38,6 +38,7 @@ obj-$(CONFIG_I2C_GPIO)+= i2c-gpio.o obj-$(CONFIG_I2C_HIGHLANDER) += i2c-highlander.o obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o obj-$(CONFIG_I2C_IMX) += i2c-imx.o +obj-$(CONFIG_I2C_INTEL_MID)+= i2c-intel-mid.o obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o obj-$(CONFIG_I2C_MPC) += i2c-mpc.o diff --git a/drivers/i2c/busses/i2c-intel-mid.c b/drivers/i2c/busses/i2c-intel-mid.c new file mode 100644 index 000..80f70d3 --- /dev/null +++ b/drivers/i2c/busses/i2c-intel-mid.c @@ -0,0 +1,1135 @@ +/* + * Support for Moorestown/Medfield I2C chip + * + * Copyright (c) 2009 Intel Corporation. + * Copyright (c) 2009 Synopsys. Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, version + * 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include linux/module.h +#include linux/kernel.h +#include linux/err.h +#include linux/slab.h +#include linux/stat.h +#include linux/delay.h +#include linux/i2c.h +#include linux/init.h +#include linux/pci.h +#include linux/interrupt.h +#include linux/pm_runtime.h +#include linux/io.h + +#define DRIVER_NAMEi2c-intel-mid +#define VERSIONVersion 0.5ac2 +#define PLATFORM Moorestown/Medfield + +/* Tables use: 0
Re: [PATCH] I2C driver supporting Moorestown and Medfield platform
On Fri, 22 Oct 2010 15:05:30 +0100, Alan Cox wrote: I think this now addresses all the points raised in previous review, as well as adding runtime power management support which is needed for MID platforms. Ben, this driver has been floating around for quite some time, I think we really want to have it in kernel 2.6.37. This is for an embedded system so it would be one for you to merge, however if you can't make it on time (where on time is by the end of the week aka before Sunday October 31st, 2010) , please let me know and I will take care. At least I can build this one ;) 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
Re: [PATCH] I2C driver supporting Moorestown and Medfield platform
On Tue, Oct 26, 2010 at 10:08:00AM +0200, Jean Delvare wrote: On Fri, 22 Oct 2010 15:05:30 +0100, Alan Cox wrote: I think this now addresses all the points raised in previous review, as well as adding runtime power management support which is needed for MID platforms. Ben, this driver has been floating around for quite some time, I think we really want to have it in kernel 2.6.37. This is for an embedded system so it would be one for you to merge, however if you can't make it on time (where on time is by the end of the week aka before Sunday October 31st, 2010) , please let me know and I will take care. At least I can build this one ;) I'll be looking at this tonight. -- Ben Q: What's a light-year? A: One-third less calories than a regular year. -- 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 driver supporting Moorestown and Medfield platform
On 22/10/10 15:05, Alan Cox wrote: I think this now addresses all the points raised in previous review, as well I'll go through and have a quick look through this to see if there is anything else to look at. +/* Tables use: 0 Moorestown, 1 Medfield */ +#define NUM_PLATFORMS2 +enum platform_enum { + MOORESTOWN = 0, + MEDFIELD = 1, +}; + +struct intel_mid_i2c_private { + struct i2c_adapter adap; + /* Device for power management */ + struct device *dev; + /* Register base address */ + void __iomem *base; + /* Speed mode */ + int speed; + /* Transaction completion wait */ + struct completion complete; + /* Saved abort reason */ + int abort; + /* Working buffer */ + u8 *rx_buf; + int rx_buf_len; + /* Adapter state machine condition */ + int status; + /* Message being processed */ + struct i2c_msg *msg; + /* Which Intel MID device are we today */ + enum platform_enum platform; + /* Serialize transactions */ + struct mutex lock; +}; would have prefered this as kerneldoc. + +#define NUM_SPEEDS 3 + +#define ACTIVE 0 +#define STANDBY 1 + +#define STATUS_IDLE 0 +#define STATUS_READ_START1 +#define STATUS_READ_IN_PROGRESS 2 +#define STATUS_READ_SUCCESS 3 +#define STATUS_WRITE_START 4 +#define STATUS_WRITE_SUCCESS 5 +#define STATUS_XFER_ABORT6 +#define STATUS_STANDBY 7 would have been nicer as an enum. +/** + * intel_mid_i2c_disable - Disable I2C controller + * @adap: struct pointer to i2c_adapter + * + * Return Value: + * 0 success + * -EBUSYif device is busy + * -ETIMEDOUTif i2c cannot be disabled within the given time + * + * I2C bus state should be checked prior to disabling the hardware. If bus is + * not in idle state, an errno is returned. Write 0 to IC_ENABLE to disable + * I2C controller. + */ +static int intel_mid_i2c_disable(struct i2c_adapter *adap) +{ + struct intel_mid_i2c_private *i2c = i2c_get_adapdata(adap); + int err = 0; + int count = 0; + int ret1, ret2; + static const u16 delay[NUM_SPEEDS] = {100, 25, 3}; + + /* Set IC_ENABLE to 0 */ + writel(0, i2c-base + IC_ENABLE); + + /* Check if device is busy */ + dev_dbg(adap-dev, mrst i2c disable\n); + while ((ret1 = readl(i2c-base + IC_ENABLE_STATUS) 0x1) + || (ret2 = readl(i2c-base + IC_STATUS) 0x1)) { + udelay(delay[i2c-speed]); + writel(0, i2c-base + IC_ENABLE); + dev_dbg(adap-dev, i2c is busy, count is %d speed %d\n, + count, i2c-speed); + if (count++ 10) { + err = -ETIMEDOUT; + break; + } + } + + /* Clear all interrupts */ + readl(i2c-base + IC_CLR_INTR); + readl(i2c-base + IC_CLR_STOP_DET); + readl(i2c-base + IC_CLR_START_DET); + readl(i2c-base + IC_CLR_ACTIVITY); + readl(i2c-base + IC_CLR_TX_ABRT); + readl(i2c-base + IC_CLR_RX_OVER); + readl(i2c-base + IC_CLR_RX_UNDER); + readl(i2c-base + IC_CLR_TX_OVER); + readl(i2c-base + IC_CLR_RX_DONE); + readl(i2c-base + IC_CLR_GEN_CALL); + + /* Disable all interupts */ + writel(0x, i2c-base + IC_INTR_MASK); + + return err; +} + +/** + * intel_mid_i2c_hwinit - Initialize the I2C hardware registers + * @dev: pci device struct pointer + * + * This function will be called in intel_mid_i2c_probe() before device + * registration. + * + * Return Values: + * 0 success + * -EBUSYi2c cannot be disabled + * -ETIMEDOUTi2c cannot be disabled + * -EFAULT If APB data width is not 32-bit wide + * + * I2C should be disabled prior to other register operation. If failed, an + * errno is returned. Mask and Clear all interrpts, this should be done at + * first. Set common registers which will not be modified during normal + * transfers, including: controll register, FIFO threshold and clock freq. + * Check APB data width at last. + */ +static int intel_mid_i2c_hwinit(struct intel_mid_i2c_private *i2c) +{ + int err; + + static const u16 hcnt[NUM_PLATFORMS][NUM_SPEEDS] = { + { 0x75, 0x15, 0x07 }, + { 0x04c, 0x10, 0x06 } + }; + static const u16 lcnt[NUM_PLATFORMS][NUM_SPEEDS] = { + { 0x7C, 0x21, 0x0E }, + { 0x053, 0x19, 0x0F } + }; + + /* Disable i2c first */ + err = intel_mid_i2c_disable(i2c-adap); + if (err) + return err; + + /* + * Setup clock frequency and speed mode + * Enable restart condition, + * enable master FSM, disable slave FSM, + * use target address when initiating transfer + */ + + writel((i2c-speed + 1) 1 | SLV_DIS | RESTART | MASTER_EN, + i2c-base +
[PATCH] I2C driver supporting Moorestown and Medfield platform
I think this now addresses all the points raised in previous review, as well as adding runtime power management support which is needed for MID platforms. From: Wen Wang wen.w.w...@intel.com Initial release of the driver. Updated and verified on hardware. Cleaned up as follows Alan Cox: Squash down the switches into tables, and use the PCI ident field. We could perhaps take this further and put the platform and port number into this. uint32t - u32 bracketing of case statements spacing and '!' usage Check the speed (which is now 0/1/2) is valid and ignore otherwise. Fix remaining problems/suggestions from Jean's review Arjan van de Ven: Initial power management hooks Yong Wang youg.y.w...@intel.com: Shared IRQ support Wen Wang wen.w.w...@intel.com: D3 support Fixes for OCT test runs Interrupt optimisations Hong Liu hong@intel.com The runtime PM code is working on the wrong device (i2c_adapter-dev). The correct one should be pci_dev-dev. This breaks attached i2c slave devices with runtime PM enabled. Slave device needs to runtime resume parent device before runtime resuming itself, but we always get error since we don't have pm_runtime callback for i2c_adapter-dev. Bin Yang bin.y...@intel.com: Update speed table Saadi Maalem saadi.maa...@intel.com: Clear all interrupts in the hardware init Celine Chotard celinex.chot...@intel.com: Correct ordering of clear/disable of IRQs Signed-off-by: Wen Wang wen.w.w...@intel.com Signed-off-by: Yong Wang yong.y.w...@intel.com Signed-off-by: Hong Liu hong@intel.com Signed-off-by: Bin Yang bin.y...@intel.com Signed-off-by: Arjan van de Ven ar...@linux.intel.com Signed-off-by: Alan Cox a...@linux.intel.com --- drivers/i2c/busses/Kconfig |9 drivers/i2c/busses/Makefile|1 drivers/i2c/busses/i2c-intel-mid.c | 1132 3 files changed, 1142 insertions(+), 0 deletions(-) create mode 100644 drivers/i2c/busses/i2c-intel-mid.c diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index fd455a2..a62f99e 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig @@ -396,6 +396,15 @@ config I2C_IMX This driver can also be built as a module. If so, the module will be called i2c-imx. +config I2C_INTEL_MID + tristate Intel Moorestown/Medfield Platform I2C controller + help + Say Y here if you have an Intel Moorestown/Medfield platform I2C + controller. + + This support is also available as a module. If so, the module + will be called i2c-intel-mid. + config I2C_IOP3XX tristate Intel IOPx3xx and IXP4xx on-chip I2C interface depends on ARCH_IOP32X || ARCH_IOP33X || ARCH_IXP4XX || ARCH_IOP13XX diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile index 033ad41..84cb16a 100644 --- a/drivers/i2c/busses/Makefile +++ b/drivers/i2c/busses/Makefile @@ -38,6 +38,7 @@ obj-$(CONFIG_I2C_GPIO)+= i2c-gpio.o obj-$(CONFIG_I2C_HIGHLANDER) += i2c-highlander.o obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o obj-$(CONFIG_I2C_IMX) += i2c-imx.o +obj-$(CONFIG_I2C_INTEL_MID)+= i2c-intel-mid.o obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o obj-$(CONFIG_I2C_MPC) += i2c-mpc.o diff --git a/drivers/i2c/busses/i2c-intel-mid.c b/drivers/i2c/busses/i2c-intel-mid.c new file mode 100644 index 000..8490cd6 --- /dev/null +++ b/drivers/i2c/busses/i2c-intel-mid.c @@ -0,0 +1,1132 @@ +/* + * Support for Moorestown/Medfield I2C chip + * + * Copyright (c) 2009 Intel Corporation. + * Copyright (c) 2009 Synopsys. Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, version + * 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include linux/module.h +#include linux/kernel.h +#include linux/err.h +#include linux/slab.h +#include linux/stat.h +#include linux/delay.h +#include linux/i2c.h +#include linux/init.h +#include linux/pci.h +#include linux/interrupt.h +#include linux/pm_runtime.h +#include linux/io.h + +#define DRIVER_NAMEi2c-intel-mid +#define VERSIONVersion 0.5ac2 +#define PLATFORM Moorestown/Medfield + +/* Tables use: 0 Moorestown, 1 Medfield */ +#define NUM_PLATFORMS 2 +enum platform_enum { + MOORESTOWN = 0, + MEDFIELD = 1, +}; + +struct
[PATCH] I2C driver supporting Moorestown and Medfield platform
From: Wen Wang wen.w.w...@intel.com Initial release of the driver. Updated and verified on hardware. Cleaned up as follows and with fixes backported out of the internal tree for Meego. Alan Cox: Squash down the switches into tables, and use the PCI ident field. We could perhaps take this further and put the platform and port number into this. uint32t - u32 bracketing of case statements spacing and '!' usage Check the speed (which is now 0/1/2) is valid and ignore otherwise. Arjan van de Ven: Initial power management hooks Yong Wang youg.y.w...@intel.com: Shared IRQ support Wen Wang wen.w.w...@intel.com: D3 support Fixes for OCT test runs Interrupt optimisations Hong Liu hong@intel.com The runtime PM code is working on the wrong device (i2c_adapter-dev). The correct one should be pci_dev-dev. This breaks attached i2c slave devices with runtime PM enabled. Slave device needs to runtime resume parent device before runtime resuming itself, but we always get error since we don't have pm_runtime callback for i2c_adapter-dev. Bin Yang bin.y...@intel.com: Update speed table Saadi Maalem saadi.maa...@intel.com: Clear all interrupts in the hardware init Celine Chotard celinex.chot...@intel.com: Correct ordering of clear/disable of IRQs Signed-off-by: Wen Wang wen.w.w...@intel.com Signed-off-by: Yong Wang yong.y.w...@intel.com Signed-off-by: Hong Liu hong@intel.com Signed-off-by: Bin Yang bin.y...@intel.com Signed-off-by: Arjan van de Ven ar...@linux.intel.com Signed-off-by: Alan Cox a...@linux.intel.com --- drivers/i2c/busses/Kconfig |9 drivers/i2c/busses/Makefile|1 drivers/i2c/busses/i2c-intel-mid.c | 1132 3 files changed, 1142 insertions(+), 0 deletions(-) create mode 100644 drivers/i2c/busses/i2c-intel-mid.c diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 6539ac2..1ba849a 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig @@ -420,6 +420,15 @@ config I2C_IXP2000 This driver is deprecated and will be dropped soon. Use i2c-gpio instead. +config I2C_INTEL_MID + tristate Intel Moorestown/Medfield Platform I2C controller + help + Say Y here if you have an Intel Moorestown/Medfield platform I2C + controller. + + This support is also available as a module. If so, the module + will be called i2c-intel-mid. + config I2C_MPC tristate MPC107/824x/85xx/512x/52xx/83xx/86xx depends on PPC32 diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile index 033ad41..3742d58 100644 --- a/drivers/i2c/busses/Makefile +++ b/drivers/i2c/busses/Makefile @@ -40,6 +40,7 @@ obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o obj-$(CONFIG_I2C_IMX) += i2c-imx.o obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o +obj-$(CONFIG_I2C_INTEL_MID)+= i2c-intel-mid.o obj-$(CONFIG_I2C_MPC) += i2c-mpc.o obj-$(CONFIG_I2C_MV64XXX) += i2c-mv64xxx.o obj-$(CONFIG_I2C_NOMADIK) += i2c-nomadik.o diff --git a/drivers/i2c/busses/i2c-intel-mid.c b/drivers/i2c/busses/i2c-intel-mid.c new file mode 100644 index 000..4341bcb --- /dev/null +++ b/drivers/i2c/busses/i2c-intel-mid.c @@ -0,0 +1,1132 @@ +/* + * Support for Moorestown/Medfield I2C chip + * + * Copyright (c) 2009 Intel Corporation. + * Copyright (c) 2009 Synopsys. Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, version + * 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include linux/module.h +#include linux/moduleparam.h +#include linux/version.h +#include linux/kernel.h +#include linux/err.h +#include linux/slab.h +#include linux/stat.h +#include linux/types.h +#include linux/delay.h +#include linux/i2c.h +#include linux/init.h +#include linux/pci.h +#include linux/interrupt.h +#include linux/pm_runtime.h +#include linux/io.h + +#define DRIVER_NAMEi2c-intel-mid +#define VERSIONVersion 0.5ac2 +#define PLATFORM Moorestown/Medfield + +/* Tables use: 0 Moorestown, 1 Medfield */ +#define NUM_PLATFORMS 2 +enum platform_enum { + MOORESTOWN = 0, + MEDFIELD = 1, +}; + +struct intel_mid_i2c_private { + struct i2c_adapter adap; + /* Device for power management */ +
[PATCH] I2C driver supporting Moorestown and Medfield platform
From: Wen Wang wen.w.w...@intel.com Initial release of the driver. Updated and verified on hardware. Cleaned up as follows and with bits backported from the internal Meego tree Alan Cox: Squash down the switches into tables, and use the PCI ident field. We could perhaps take this further and put the platform and port number into this. uint32t - u32 bracketing of case statements spacing and '!' usage Check the speed (which is now 0/1/2) is valid and ignore otherwise. Arjan van de Ven: Initial power management hooks Yong Wang youg.y.w...@intel.com: Shared IRQ support Wen Wang wen.w.w...@intel.com: D3 support Fixes for OCT test runs Interrupt optimisations Hong Liu hong@intel.com The runtime PM code is working on the wrong device (i2c_adapter-dev). The correct one should be pci_dev-dev. This breaks attached i2c slave devices with runtime PM enabled. Slave device needs to runtime resume parent device before runtime resuming itself, but we always get error since we don't have pm_runtime callback for i2c_adapter-dev. Bin Yang bin.y...@intel.com: Update speed table Saadi Maalem saadi.maa...@intel.com: Clear all interrupts in the hardware init Celine Chotard celinex.chot...@intel.com: Correct ordering of clear/disable of IRQs Signed-off-by: Wen Wang wen.w.w...@intel.com Signed-off-by: Yong Wang yong.y.w...@intel.com Signed-off-by: Hong Liu hong@intel.com Signed-off-by: Bin Yang bin.y...@intel.com Signed-off-by: Arjan van de Ven ar...@linux.intel.com Signed-off-by: Alan Cox a...@linux.intel.com --- drivers/i2c/busses/Kconfig |9 drivers/i2c/busses/Makefile|1 drivers/i2c/busses/i2c-intel-mid.c | 1132 3 files changed, 1142 insertions(+), 0 deletions(-) create mode 100644 drivers/i2c/busses/i2c-intel-mid.c diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 6539ac2..1ba849a 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig @@ -420,6 +420,15 @@ config I2C_IXP2000 This driver is deprecated and will be dropped soon. Use i2c-gpio instead. +config I2C_INTEL_MID + tristate Intel Moorestown/Medfield Platform I2C controller + help + Say Y here if you have an Intel Moorestown/Medfield platform I2C + controller. + + This support is also available as a module. If so, the module + will be called i2c-intel-mid. + config I2C_MPC tristate MPC107/824x/85xx/512x/52xx/83xx/86xx depends on PPC32 diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile index 033ad41..3742d58 100644 --- a/drivers/i2c/busses/Makefile +++ b/drivers/i2c/busses/Makefile @@ -40,6 +40,7 @@ obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o obj-$(CONFIG_I2C_IMX) += i2c-imx.o obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o +obj-$(CONFIG_I2C_INTEL_MID)+= i2c-intel-mid.o obj-$(CONFIG_I2C_MPC) += i2c-mpc.o obj-$(CONFIG_I2C_MV64XXX) += i2c-mv64xxx.o obj-$(CONFIG_I2C_NOMADIK) += i2c-nomadik.o diff --git a/drivers/i2c/busses/i2c-intel-mid.c b/drivers/i2c/busses/i2c-intel-mid.c new file mode 100644 index 000..9ef60be --- /dev/null +++ b/drivers/i2c/busses/i2c-intel-mid.c @@ -0,0 +1,1132 @@ +/* + * Support for Moorestown/Medfield I2C chip + * + * Copyright (c) 2009 Intel Corporation. + * Copyright (c) 2009 Synopsys. Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, version + * 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include linux/module.h +#include linux/moduleparam.h +#include linux/version.h +#include linux/kernel.h +#include linux/err.h +#include linux/slab.h +#include linux/stat.h +#include linux/types.h +#include linux/delay.h +#include linux/i2c.h +#include linux/init.h +#include linux/pci.h +#include linux/interrupt.h +#include linux/pm_runtime.h +#include linux/io.h + +#define DRIVER_NAMEi2c-intel-mid +#define VERSIONVersion 0.5ac2 +#define PLATFORM Moorestown/Medfield + +/* Tables use: 0 Moorestown, 1 Medfield */ +#define NUM_PLATFORMS 2 +enum platform_enum { + MOORESTOWN = 0, + MEDFIELD = 1, +}; + +struct intel_mid_i2c_private { + struct i2c_adapter adap; + /* Device for power management */ +
[PATCH] I2C driver supporting Moorestown and Medfield platform
From: Wen Wang wen.w.w...@intel.com Initial release of the driver. Some clean up table removal by Alan Cox Signed-off-by: Wen Wang wen.w.w...@intel.com Signed-off-by: Alan Cox a...@linux.intel.com --- drivers/i2c/busses/Kconfig|9 drivers/i2c/busses/Makefile |1 drivers/i2c/busses/i2c-mrst.c | 902 + drivers/i2c/busses/i2c-mrst.h | 269 4 files changed, 1181 insertions(+), 0 deletions(-) create mode 100644 drivers/i2c/busses/i2c-mrst.c create mode 100644 drivers/i2c/busses/i2c-mrst.h diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 29e01f6..ea0100e 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig @@ -420,6 +420,15 @@ config I2C_IXP2000 This driver is deprecated and will be dropped soon. Use i2c-gpio instead. +config I2C_MRST + tristate Intel Moorestown/Medfield Platform I2C controller + help + Say Y here if you have an Intel Moorestown/Medfield platform I2C + controller. + + This support is also available as a module. If so, the module + will be called i2c-mrst. + config I2C_MPC tristate MPC107/824x/85xx/512x/52xx/83xx/86xx depends on PPC32 diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile index 936880b..0b9aa00 100644 --- a/drivers/i2c/busses/Makefile +++ b/drivers/i2c/busses/Makefile @@ -40,6 +40,7 @@ obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o obj-$(CONFIG_I2C_IMX) += i2c-imx.o obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o +obj-$(CONFIG_I2C_MRST) += i2c-mrst.o obj-$(CONFIG_I2C_MPC) += i2c-mpc.o obj-$(CONFIG_I2C_MV64XXX) += i2c-mv64xxx.o obj-$(CONFIG_I2C_NOMADIK) += i2c-nomadik.o diff --git a/drivers/i2c/busses/i2c-mrst.c b/drivers/i2c/busses/i2c-mrst.c new file mode 100644 index 000..5da3ca5 --- /dev/null +++ b/drivers/i2c/busses/i2c-mrst.c @@ -0,0 +1,902 @@ +/* + * Support for Moorestown/Medfield I2C chip + * + * Copyright (c) 2009 Intel Corporation. + * Copyright (c) 2009 Synopsys. Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, version + * 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include linux/module.h +#include linux/moduleparam.h +#include linux/version.h +#include linux/kernel.h +#include linux/err.h +#include linux/slab.h +#include linux/stat.h +#include linux/types.h +#include linux/delay.h +#include linux/i2c.h +#include linux/init.h +#include linux/pci.h +#include linux/gpio.h +#include linux/interrupt.h + +#include linux/io.h + +#include i2c-mrst.h + +#define DEF_BAR0 +#define VERSIONVersion 0.5 +#define PLATFORM Moorestown/Medfield + +#define mrst_i2c_read(reg) __raw_readl(reg) +#define mrst_i2c_write(reg, val) __raw_writel((val), (reg)) + +/* Use defines not enumerations so that we can do this with tables */ + +#define MOOESTOWN 0 +#defineMEDFIELD1 + +#define NUM_PLATFORMS 2 + +#define STANDARD 0 +#define FAST 1 +#define HIGH 2 + +#define NUM_SPEEDS 3 + + +static int speed_mode[6] = { + STANDARD, + STANDARD, + STANDARD, + STANDARD, + STANDARD, + STANDARD +}; +static int ctl_num; +module_param_array(speed_mode, int, ctl_num, S_IRUGO); + +/** + * mrst_i2c_disable - Disable I2C controller + * @adap: struct pointer to i2c_adapter + * + * Return Value: + * 0 success + * -EBUSY if device is busy + * -ETIMEOUT if i2c cannot be disabled within the given time + * + * I2C bus state should be checked prior to disabling the hardware. If bus is + * not in idle state, an errno is returned. Write 0 to IC_ENABLE to disable + * I2C controller. + */ +static int mrst_i2c_disable(struct i2c_adapter *adap) +{ + struct mrst_i2c_private *i2c = + (struct mrst_i2c_private *)i2c_get_adapdata(adap); + + int count = 0; + int ret1, ret2; + static const u16 delay[NUM_SPEEDS] = {100, 25, 3}; + + /* Set IC_ENABLE to 0 */ + mrst_i2c_write(i2c-base + IC_ENABLE, 0); + + /* Check if device is busy */ + dev_dbg(adap-dev, mrst i2c disable\n); + while ((ret1 = mrst_i2c_read(i2c-base + IC_ENABLE_STATUS) 0x1) + || (ret2 = mrst_i2c_read(i2c-base + IC_STATUS) 0x1)) { +
Re: [PATCH] I2C driver supporting Moorestown and Medfield platform
Hi Alan, On Mon, 19 Jul 2010 11:17:28 +0100, Alan Cox wrote: From: Wen Wang wen.w.w...@intel.com Initial release of the driver. Some clean up table removal by Alan Cox Signed-off-by: Wen Wang wen.w.w...@intel.com Signed-off-by: Alan Cox a...@linux.intel.com --- drivers/i2c/busses/Kconfig|9 drivers/i2c/busses/Makefile |1 drivers/i2c/busses/i2c-mrst.c | 902 + drivers/i2c/busses/i2c-mrst.h | 269 4 files changed, 1181 insertions(+), 0 deletions(-) create mode 100644 drivers/i2c/busses/i2c-mrst.c create mode 100644 drivers/i2c/busses/i2c-mrst.h I already reviewed this driver back in June 2009: http://marc.info/?l=linux-i2cm=124506668112908w=2 I hope that all my concerns back then have been addressed? -- 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] I2C driver supporting Moorestown and Medfield platform
From: Wen Wang wen.w.w...@intel.com Initial release of the driver. Major clean up by Alan Cox. This fixes the points raised in the initial review except that - some were no longer relevant - speed is left 0/1/2 as specifying exact frequencies uses more command line and makes it more complex for the user and for us - as we'd need to refuse anything but the tested/verified speeds anyway - the disable function doesn't do a totally time based delay - its ten times the speed udelay so its clearly bounded anyway Signed-off-by: Wen Wang wen.w.w...@intel.com Signed-off-by: Alan Cox a...@linux.intel.com --- drivers/i2c/busses/Kconfig|9 drivers/i2c/busses/Makefile |1 drivers/i2c/busses/i2c-mrst.c | 1045 + 3 files changed, 1055 insertions(+), 0 deletions(-) create mode 100644 drivers/i2c/busses/i2c-mrst.c diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 29e01f6..ea0100e 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig @@ -420,6 +420,15 @@ config I2C_IXP2000 This driver is deprecated and will be dropped soon. Use i2c-gpio instead. +config I2C_MRST + tristate Intel Moorestown/Medfield Platform I2C controller + help + Say Y here if you have an Intel Moorestown/Medfield platform I2C + controller. + + This support is also available as a module. If so, the module + will be called i2c-mrst. + config I2C_MPC tristate MPC107/824x/85xx/512x/52xx/83xx/86xx depends on PPC32 diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile index 936880b..0b9aa00 100644 --- a/drivers/i2c/busses/Makefile +++ b/drivers/i2c/busses/Makefile @@ -40,6 +40,7 @@ obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o obj-$(CONFIG_I2C_IMX) += i2c-imx.o obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o +obj-$(CONFIG_I2C_MRST) += i2c-mrst.o obj-$(CONFIG_I2C_MPC) += i2c-mpc.o obj-$(CONFIG_I2C_MV64XXX) += i2c-mv64xxx.o obj-$(CONFIG_I2C_NOMADIK) += i2c-nomadik.o diff --git a/drivers/i2c/busses/i2c-mrst.c b/drivers/i2c/busses/i2c-mrst.c new file mode 100644 index 000..862b4c2 --- /dev/null +++ b/drivers/i2c/busses/i2c-mrst.c @@ -0,0 +1,1045 @@ +/* + * Support for Moorestown/Medfield I2C chip + * + * Copyright (c) 2009 Intel Corporation. + * Copyright (c) 2009 Synopsys. Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, version + * 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include linux/module.h +#include linux/moduleparam.h +#include linux/version.h +#include linux/kernel.h +#include linux/err.h +#include linux/slab.h +#include linux/stat.h +#include linux/types.h +#include linux/delay.h +#include linux/i2c.h +#include linux/init.h +#include linux/pci.h +#include linux/interrupt.h +#include linux/io.h + +#define DRIVER_NAMEmrst_i2c +#define VERSIONVersion 0.5 +#define PLATFORM Moorestown/Medfield + +#define NUM_PLATFORMS 2 +/* Tables use: 0 Moorestown, 1 Medfield */ + +enum platform_enum { + MOORESTOWN = 0, + MEDFIELD = 1, +}; + +struct mrst_i2c_private { + struct i2c_adapter adap; + /* Register base address */ + void __iomem *base; + /* Speed mode */ + int speed; + int pm_state; + struct completion complete; + int abort; + u8 *rx_buf; + int rx_buf_len; + int status; + struct i2c_msg *msg; + enum platform_enum platform; + struct mutex lock; + spinlock_t slock; +}; + +#define ACTIVE 0 +#define STANDBY1 + +#define STATUS_IDLE0 +#define STATUS_READ_START 1 +#define STATUS_READ_IN_PROGRESS2 +#define STATUS_READ_SUCCESS3 +#define STATUS_WRITE_START 4 +#define STATUS_WRITE_SUCCESS 5 +#define STATUS_XFER_ABORT 6 + +/* Control register */ +#define IC_CON 0x00 +#define SLV_DIS(1 6)/* Disable slave mode */ +#define RESTART(1 5)/* Send a Restart condition */ +#defineADDR_10BIT (1 4)/* 10-bit addressing */ +#defineSTANDARD_MODE (1 1)/* standard mode */ +#define FAST_MODE (2 1)/* fast mode */ +#define HIGH_MODE