linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ben Dooks <ben-i2c-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org>
To: Sebastian Andrzej Siewior
	<bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	sodaville-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org,
	tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org,
	eric.y.miao-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
	linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org,
	ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org,
	Dirk Brandewie
	<dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Subject: Re: [PATCH 3/7] i2c/pxa2xx: Add PCI support for PXA I2C controller
Date: Thu, 25 Nov 2010 23:59:33 +0000	[thread overview]
Message-ID: <20101125235933.GD15948@trinity.fluff.org> (raw)
In-Reply-To: <1290633617-15311-4-git-send-email-bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>

On Wed, Nov 24, 2010 at 10:20:13PM +0100, Sebastian Andrzej Siewior wrote:
> The Sodaville I2C controller is almost the same as found on PXA2xx. The
> difference:
> - the register are at a different spot
> - no slave support
> 
> The PCI probe code adds three platform devices which are probed then by
> the platform code.
> The X86 part also adds dummy clock defines because we don't have HW
> clock support.
> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
> Signed-off-by: Dirk Brandewie <dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> ---
>  arch/x86/include/asm/pxa_i2c.h   |   24 ++++++
>  drivers/i2c/busses/Kconfig       |    7 +-
>  drivers/i2c/busses/Makefile      |    1 +
>  drivers/i2c/busses/i2c-pxa-pci.c |  160 ++++++++++++++++++++++++++++++++++++++
>  4 files changed, 190 insertions(+), 2 deletions(-)
>  create mode 100644 arch/x86/include/asm/pxa_i2c.h
>  create mode 100644 drivers/i2c/busses/i2c-pxa-pci.c
> 
> diff --git a/arch/x86/include/asm/pxa_i2c.h b/arch/x86/include/asm/pxa_i2c.h
> new file mode 100644
> index 0000000..9f73b3de
> --- /dev/null
> +++ b/arch/x86/include/asm/pxa_i2c.h
> @@ -0,0 +1,24 @@
> +#ifndef __ASM_PXA_I2C_H__
> +#define __ASM_PXA_I2C_H__
> +
> +/*
> + * I2C registers definitions
> + */
> +#define IBMR            (0x14)
> +#define IDBR            (0x0c)
> +#define ICR             (0x00)
> +#define ISR             (0x04)
> +
> +#define _IBMR(i2c)	((i2c)->reg_base + IBMR)
> +#define _IDBR(i2c)	((i2c)->reg_base + IDBR)
> +#define _ICR(i2c)	((i2c)->reg_base + ICR)
> +#define _ISR(i2c)	((i2c)->reg_base + ISR)

couldn't these be in common code?

> +struct clk;
> +
> +#define clk_get(dev, id)	NULL
> +#define clk_put(clk)		do { } while (0)
> +#define clk_disable(clk)	do { } while (0)
> +#define clk_enable(clk)		do { } while (0)
> +
> +#endif
> diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
> index 3a6321c..76b5f15 100644
> --- a/drivers/i2c/busses/Kconfig
> +++ b/drivers/i2c/busses/Kconfig
> @@ -525,15 +525,18 @@ config I2C_PNX
>  
>  config I2C_PXA
>  	tristate "Intel PXA2XX I2C adapter"
> -	depends on ARCH_PXA || ARCH_MMP
> +	depends on ARCH_PXA || ARCH_MMP || (X86 && PCI)
>  	help
>  	  If you have devices in the PXA I2C bus, say yes to this option.
>  	  This driver can also be built as a module.  If so, the module
>  	  will be called i2c-pxa.
>  
> +config I2C_PXA_PCI
> +	def_bool I2C_PXA && X86 && PCI
> +
>  config I2C_PXA_SLAVE
>  	bool "Intel PXA2XX I2C Slave comms support"
> -	depends on I2C_PXA
> +	depends on I2C_PXA && !X86
>  	help
>  	  Support I2C slave mode communications on the PXA I2C bus.  This
>  	  is necessary for systems where the PXA may be a target on the
> diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
> index 84cb16a..78db2e3 100644
> --- a/drivers/i2c/busses/Makefile
> +++ b/drivers/i2c/busses/Makefile
> @@ -52,6 +52,7 @@ obj-$(CONFIG_I2C_PCA_PLATFORM)	+= i2c-pca-platform.o
>  obj-$(CONFIG_I2C_PMCMSP)	+= i2c-pmcmsp.o
>  obj-$(CONFIG_I2C_PNX)		+= i2c-pnx.o
>  obj-$(CONFIG_I2C_PXA)		+= i2c-pxa.o
> +obj-$(CONFIG_I2C_PXA_PCI)	+= i2c-pxa-pci.o
>  obj-$(CONFIG_I2C_S3C2410)	+= i2c-s3c2410.o
>  obj-$(CONFIG_I2C_S6000)		+= i2c-s6000.o
>  obj-$(CONFIG_I2C_SH7760)	+= i2c-sh7760.o
> diff --git a/drivers/i2c/busses/i2c-pxa-pci.c b/drivers/i2c/busses/i2c-pxa-pci.c
> new file mode 100644
> index 0000000..9ab7a36
> --- /dev/null
> +++ b/drivers/i2c/busses/i2c-pxa-pci.c
> @@ -0,0 +1,160 @@
> +/*
> + * The CE4100's I2C device is more or less the same one as found on PXA.
> + * It does not support slave mode, the register slightly moved. This PCI
> + * device provides three bars, every contains a single I2C controller.
> + */
> +#include <linux/pci.h>
> +#include <linux/platform_device.h>
> +#include <linux/i2c/pxa-i2c.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> +
> +#define CE4100_PCI_I2C_DEVS	3
> +
> +struct ce4100_i2c_device {
> +	struct platform_device pdev;
> +	struct resource res[2];
> +	struct i2c_pxa_platform_data pdata;
> +};
> +
> +struct ce4100_devices {
> +	struct ce4100_i2c_device sd[CE4100_PCI_I2C_DEVS];
> +};
> +
> +static void plat_dev_release(struct device *dev)
> +{
> +	struct ce4100_i2c_device *sd = container_of(dev,
> +			struct ce4100_i2c_device, pdev.dev);
> +
> +	of_device_node_put(&sd->pdev.dev);
> +}
> +
> +static int add_i2c_device(struct pci_dev *dev, int bar,
> +		struct ce4100_i2c_device *sd)
> +{
> +	struct platform_device *pdev = &sd->pdev;
> +	struct i2c_pxa_platform_data *pdata = &sd->pdata;
> +
> +	pdev->name = "pxa2xx-i2c";
> +	pdev->dev.release = plat_dev_release;
> +	/*
> +	 * We assume one PCI bus here. devfn uses the lower 8 bits. To remain
> +	 * unique we encode the also bar
> +	 */
> +	pdev->id = dev->devfn << 3 | bar;
> +	pdev->dev.parent = &dev->dev;
> +#ifdef CONFIG_OF
> +	if (dev->dev.of_node) {
> +		struct device_node *child;
> +
> +		for_each_child_of_node(dev->dev.of_node, child) {
> +			const void *prop;
> +			u32 child_reg;
> +
> +			prop = of_get_property(child, "reg", NULL);
> +			if (!prop)
> +				continue;
> +			child_reg = be32_to_cpup(prop);
> +			if (child_reg == bar) {
> +				pdev->dev.of_node = child;
> +				break;
> +			}
> +		}
> +	}
> +#endif
> +	pdev->dev.platform_data = pdata;
> +	pdev->resource = sd->res;
> +
> +	sd->res[0].flags = IORESOURCE_MEM;
> +	sd->res[0].start = pci_resource_start(dev, bar);
> +	sd->res[0].end = pci_resource_end(dev, bar);
> +
> +	sd->res[1].flags = IORESOURCE_IRQ;
> +	sd->res[1].start = dev->irq;
> +	sd->res[1].end = dev->irq;
> +
> +	pdev->num_resources = 2;
> +
> +	return platform_device_register(pdev);
> +}
> +
> +static int __devinit ce4100_i2c_probe(struct pci_dev *dev,
> +		const struct pci_device_id *ent)
> +{
> +	int ret;
> +	int i;
> +	struct ce4100_devices *sds;
> +
> +	sds = kzalloc(sizeof(*sds), GFP_KERNEL);
> +	if (!sds)
> +		return -ENOMEM;
> +
> +	ret = pci_enable_device_mem(dev);
> +	if (ret)
> +		goto en_dev;
> +
> +	pci_set_drvdata(dev, sds);
> +
> +	for (i = 0; i < CE4100_PCI_I2C_DEVS; i++) {
> +		ret = add_i2c_device(dev, i, &sds->sd[i]);
> +		if (ret) {
> +			while (--i >= 0)
> +				platform_device_unregister(&sds->sd[i].pdev);
> +
> +			goto err_dev_add;
> +		}
> +	}
> +
> +	return 0;
> +
> +err_dev_add:
> +	pci_set_drvdata(dev, NULL);
> +	pci_disable_device(dev);
> +en_dev:
> +	kfree(sds);
> +	return ret;
> +}
> +
> +static void __devexit ce4100_i2c_remove(struct pci_dev *dev)
> +{
> +	struct ce4100_devices *sds;
> +	unsigned int i;
> +
> +	sds = pci_get_drvdata(dev);
> +	pci_set_drvdata(dev, NULL);
> +
> +	for (i = 0; i < CE4100_PCI_I2C_DEVS; i++)
how about using ARRAY_SIZE of sds->sd[i] ?

> +		platform_device_unregister(&sds->sd[i].pdev);
> +
> +	pci_disable_device(dev);
> +	kfree(sds);
> +}
> +
> +static struct pci_device_id ce4100_i2c_devices[] __devinitdata = {
> +	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2e68)},
> +	{ },
> +};
> +MODULE_DEVICE_TABLE(pci, ce4100_i2c_devices);
> +
> +static struct pci_driver ce4100_i2c_driver = {
> +	.name           = "ce4100_i2c",
> +	.id_table       = ce4100_i2c_devices,
> +	.probe          = ce4100_i2c_probe,
> +	.remove         = __devexit_p(ce4100_i2c_remove),
> +};
> +
> +static int __init ce4100_i2c_init(void)
> +{
> +	return pci_register_driver(&ce4100_i2c_driver);
> +}
> +module_init(ce4100_i2c_init);
> +
> +static void __exit ce4100_i2c_exit(void)
> +{
> +	pci_unregister_driver(&ce4100_i2c_driver);
> +}
> +module_exit(ce4100_i2c_exit);
> +
> +MODULE_DESCRIPTION("CE4100 PCI-I2C glue code for PXA's driver");
> +MODULE_LICENSE("GPL v2");
> +MODULE_AUTHOR("Sebastian Andrzej Siewior <bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>");
> -- 
> 1.7.3.2
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
-- 
Ben

Q:      What's a light-year?
A:      One-third less calories than a regular year.

  parent reply	other threads:[~2010-11-25 23:59 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-24 21:20 I2C support for Sodaville Sebastian Andrzej Siewior
     [not found] ` <1290633617-15311-1-git-send-email-bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
2010-11-24 21:20   ` [PATCH 1/7] i2c/pxa2xx: Don't touch ISAR if not in slave mode Sebastian Andrzej Siewior
     [not found]     ` <1290633617-15311-2-git-send-email-bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
2010-11-25 23:52       ` Ben Dooks
     [not found]         ` <20101125235255.GB15948-SMNkleLxa3Z6Wcw2j4pizdi2O/JbrIOy@public.gmane.org>
2010-11-26 18:28           ` [sodaville] " Sebastian Andrzej Siewior
2010-11-24 21:20   ` [PATCH 2/7] arm/pxa2xx: reorganize I2C files Sebastian Andrzej Siewior
     [not found]     ` <1290633617-15311-3-git-send-email-bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
2010-11-25 23:55       ` Ben Dooks
     [not found]         ` <20101125235520.GC15948-SMNkleLxa3Z6Wcw2j4pizdi2O/JbrIOy@public.gmane.org>
2010-11-26  0:03           ` Russell King - ARM Linux
     [not found]             ` <20101126000341.GB9310-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2010-11-26 14:11               ` Sebastian Andrzej Siewior
2010-11-24 21:20   ` [PATCH 3/7] i2c/pxa2xx: Add PCI support for PXA I2C controller Sebastian Andrzej Siewior
     [not found]     ` <1290633617-15311-4-git-send-email-bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
2010-11-25 23:59       ` Ben Dooks [this message]
     [not found]         ` <20101125235933.GD15948-SMNkleLxa3Z6Wcw2j4pizdi2O/JbrIOy@public.gmane.org>
2010-11-26 14:16           ` Sebastian Andrzej Siewior
2010-11-24 21:20   ` [PATCH 4/7] i2c/pxa2xx: add support for shared IRQ handler Sebastian Andrzej Siewior
     [not found]     ` <1290633617-15311-5-git-send-email-bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
2010-11-25  2:26       ` Haojian Zhuang
2010-11-25 10:48         ` Sebastian Andrzej Siewior
2010-11-24 21:20   ` [PATCH 5/7] i2c/pxa2xx: check timeout correctly Sebastian Andrzej Siewior
2010-11-24 21:20   ` [PATCH 6/7] i2c/pxa2xx: reset the chip if the bus is not free Sebastian Andrzej Siewior
     [not found]     ` <1290633617-15311-7-git-send-email-bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
2010-11-25  2:30       ` Haojian Zhuang
     [not found]         ` <AANLkTikvN+==eTkoh7CTQyN0mbfvPhH6Uh9NX5QW7WFx-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-11-25  2:49           ` Haojian Zhuang
     [not found]             ` <AANLkTi=8Xy3M7QGO54nt_r0_12z3+o8G5fAqQmxkTH4o-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-11-25  6:43               ` Igor Grinberg
     [not found]                 ` <4CEE05A4.6030201-UTxiZqZC01RS1MOuV/RT9w@public.gmane.org>
2010-11-25  7:04                   ` Haojian Zhuang
2010-11-25 12:24                   ` Sebastian Andrzej Siewior
     [not found]                     ` <4CEE5587.90109-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
2010-11-25 13:10                       ` Igor Grinberg
     [not found]                         ` <4CEE602D.5090501-UTxiZqZC01RS1MOuV/RT9w@public.gmane.org>
2010-11-25 13:39                           ` Sebastian Andrzej Siewior
2010-11-24 21:20   ` [PATCH 7/7] i2c/pxa2xx: pass of_node from platform driver to adapter Sebastian Andrzej Siewior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20101125235933.GD15948@trinity.fluff.org \
    --to=ben-i2c-elnmno+kys3ytjvyw6ydsg@public.gmane.org \
    --cc=ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org \
    --cc=bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org \
    --cc=dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=eric.y.miao-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org \
    --cc=sodaville-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org \
    --cc=tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).