Re: [PATCH v2] Adding the i2c-bit-platform bus

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Guys

Is there anything else that needs to be done with this on my side?

Thanks
Eran

On Thu, May 12, 2011 at 10:38 PM, Eran Duchan <pavius@xxxxxxxxx> wrote:
>
> - Platform now passes a new platform structure, i2c_bit_platform_data,
> to the driver instead of passing i2c_algo_bit_data
>
> Signed-off-by: Eran Duchan <pavius@xxxxxxxxx>
> ---
> Âdrivers/i2c/busses/Kconfig      Â|  10 +++
> Âdrivers/i2c/busses/Makefile      |  Â1 +
> Âdrivers/i2c/busses/i2c-bit-platform.c | Â120 +++++++++++++++++++++++++++++++++
> Âinclude/linux/i2c-bit-platform.h   Â|  35 ++++++++++
> Â4 files changed, 166 insertions(+), 0 deletions(-)
> Âcreate mode 100644 drivers/i2c/busses/i2c-bit-platform.c
> Âcreate mode 100644 include/linux/i2c-bit-platform.h
>
> diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
> index 3a6321c..f6c6b8c 100644
> --- a/drivers/i2c/busses/Kconfig
> +++ b/drivers/i2c/busses/Kconfig
> @@ -365,6 +365,16 @@ config I2C_GPIO
> Â Â Â Â ÂThis is a very simple bitbanging I2C driver utilizing the
> Â Â Â Â Âarch-neutral GPIO API to control the SCL and SDA lines.
>
> +config I2C_BIT_PLATFORM
> + Â Â Â tristate "I2c-bit-algo as platform device"
> + Â Â Â select I2C_ALGOBIT
> + Â Â Â help
> + Â Â Â Â An I2C bus adapter which delegates the bit-algo callback registration
> + Â Â Â Â to the platform. Useful in cases where existing adapters such as
> + Â Â Â Â i2c-gpio are too slow. Keep in mind that no resource locking of any kind
> + Â Â Â Â is performed by the adapter or algo, so any such contention must be
> + Â Â Â Â handled by the platform.
> +
> Âconfig I2C_HIGHLANDER
> Â Â Â Âtristate "Highlander FPGA SMBus interface"
> Â Â Â Âdepends on SH_HIGHLANDER
> diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
> index 84cb16a..65bced4 100644
> --- a/drivers/i2c/busses/Makefile
> +++ b/drivers/i2c/busses/Makefile
> @@ -35,6 +35,7 @@ obj-$(CONFIG_I2C_CPM) Â Â Â Â += i2c-cpm.o
> Âobj-$(CONFIG_I2C_DAVINCI) Â Â Â+= i2c-davinci.o
> Âobj-$(CONFIG_I2C_DESIGNWARE) Â += i2c-designware.o
> Âobj-$(CONFIG_I2C_GPIO) Â Â Â Â += i2c-gpio.o
> +obj-$(CONFIG_I2C_BIT_PLATFORM) += i2c-bit-platform.o
> Âobj-$(CONFIG_I2C_HIGHLANDER) Â += i2c-highlander.o
> Âobj-$(CONFIG_I2C_IBM_IIC) Â Â Â+= i2c-ibm_iic.o
> Âobj-$(CONFIG_I2C_IMX) Â Â Â Â Â+= i2c-imx.o
> diff --git a/drivers/i2c/busses/i2c-bit-platform.c b/drivers/i2c/busses/i2c-bit-platform.c
> new file mode 100644
> index 0000000..c1f4402
> --- /dev/null
> +++ b/drivers/i2c/busses/i2c-bit-platform.c
> @@ -0,0 +1,120 @@
> +/*
> + Â Âi2c-bit-algo as platform device
> + Â ÂDelegates the bit-algo callback registration to the platform
> +
> + Â ÂCopyright (C) 2011 Eran Duchan <pavius@xxxxxxxxx>
> +
> + Â Â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.
> +*/
> +
> +#include <linux/i2c.h>
> +#include <linux/i2c-algo-bit.h>
> +#include <linux/i2c-bit-platform.h>
> +#include <linux/slab.h>
> +
> +static int __devinit i2c_bit_platform_probe(struct platform_device *pdev)
> +{
> + Â Â Â struct i2c_bit_platform_data *pdata;
> + Â Â Â struct i2c_algo_bit_data *bit_data;
> + Â Â Â struct i2c_adapter *adap;
> + Â Â Â int ret;
> +
> + Â Â Â if (pdev->dev.platform_data == NULL)
> + Â Â Â Â Â Â Â ret = -ENXIO;
> +
> + Â Â Â pdata = pdev->dev.platform_data;
> +
> + Â Â Â ret = -ENOMEM;
> + Â Â Â adap = kzalloc(sizeof(struct i2c_adapter), GFP_KERNEL);
> + Â Â Â if (adap == NULL)
> + Â Â Â Â Â Â Â goto err_alloc_adap;
> + Â Â Â bit_data = kzalloc(sizeof(struct i2c_algo_bit_data), GFP_KERNEL);
> + Â Â Â if (bit_data == NULL)
> + Â Â Â Â Â Â Â goto err_alloc_bit_data;
> +
> + Â Â Â bit_data->data = pdata->data;
> + Â Â Â bit_data->setsda = pdata->setsda;
> + Â Â Â bit_data->setscl = pdata->setscl;
> + Â Â Â bit_data->getsda = pdata->getsda;
> + Â Â Â bit_data->getscl = pdata->getscl;
> + Â Â Â bit_data->udelay = pdata->udelay;
> + Â Â Â bit_data->timeout = pdata->timeout;
> +
> + Â Â Â adap->owner = THIS_MODULE;
> + Â Â Â adap->algo_data = bit_data;
> + Â Â Â adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
> + Â Â Â adap->dev.parent = &pdev->dev;
> +
> + Â Â Â snprintf(adap->name, sizeof(adap->name), "i2c-bit-platform%d",
> + Â Â Â Â Â Â Â Â Â Â Â Âpdev->id);
> + Â Â Â adap->name[sizeof(adap->name) - 1] = '\0';
> +
> + Â Â Â /*
> + Â Â Â Â* If "dev->id" is negative we consider it as zero.
> + Â Â Â Â* The reason to do so is to avoid sysfs names that only make
> + Â Â Â Â* sense when there are multiple adapters.
> + Â Â Â Â*/
> + Â Â Â adap->nr = (pdev->id != -1) ? pdev->id : 0;
> + Â Â Â ret = i2c_bit_add_numbered_bus(adap);
> + Â Â Â if (ret)
> + Â Â Â Â Â Â Â goto err_add_bus;
> +
> + Â Â Â platform_set_drvdata(pdev, adap);
> +
> + Â Â Â return 0;
> +
> +err_add_bus:
> + Â Â Â kfree(bit_data);
> +err_alloc_bit_data:
> + Â Â Â kfree(adap);
> +err_alloc_adap:
> + Â Â Â return ret;
> +}
> +
> +static int __devexit i2c_bit_platform_remove(struct platform_device *pdev)
> +{
> + Â Â Â struct i2c_adapter *adap;
> +
> + Â Â Â adap = platform_get_drvdata(pdev);
> +
> + Â Â Â i2c_del_adapter(adap);
> +
> + Â Â Â kfree(adap->algo_data);
> + Â Â Â kfree(adap);
> +
> + Â Â Â return 0;
> +}
> +
> +static struct platform_driver i2c_bit_platform_driver = {
> +    .driver     = {
> +        .name  = "i2c-bit-platform",
> + Â Â Â Â Â Â Â .owner Â= THIS_MODULE,
> + Â Â Â },
> +    .probe     Â= i2c_bit_platform_probe,
> +    .remove     = __devexit_p(i2c_bit_platform_remove),
> +};
> +
> +static int __init i2c_bit_platform_init(void)
> +{
> + Â Â Â int ret;
> +
> + Â Â Â ret = platform_driver_register(&i2c_bit_platform_driver);
> + Â Â Â if (ret)
> + Â Â Â Â Â Â Â printk(KERN_ERR "i2c-bit-platform: probe failed: %d\n", ret);
> +
> + Â Â Â return ret;
> +}
> +subsys_initcall(i2c_bit_platform_init);
> +
> +static void __exit i2c_bit_platform_exit(void)
> +{
> + Â Â Â platform_driver_unregister(&i2c_bit_platform_driver);
> +}
> +module_exit(i2c_bit_platform_exit);
> +
> +MODULE_AUTHOR("Eran Duchan <pavius@xxxxxxxxx>");
> +MODULE_DESCRIPTION("Thin platform adapter for i2c-bit-algo");
> +MODULE_LICENSE("GPL");
> diff --git a/include/linux/i2c-bit-platform.h b/include/linux/i2c-bit-platform.h
> new file mode 100644
> index 0000000..e3b601b
> --- /dev/null
> +++ b/include/linux/i2c-bit-platform.h
> @@ -0,0 +1,35 @@
> +/*
> + * i2c-bit-platform interface to platform code
> + *
> + * Copyright (C) 2011 Eran Duchan <pavius@xxxxxxxxx>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + */
> +#ifndef _LINUX_I2C_BIT_PLATFORM_H
> +#define _LINUX_I2C_BIT_PLATFORM_H
> +
> +/**
> + * struct i2c_bit_platform_data - Platform-dependent data for
> + * i2c-bit-platform
> + * @data: to be passed to callbacks, untouched
> + * @setsda: callback to set SDA line
> + * @setscl: callback to set SCL line
> + * @getsda: callback to get SDA line
> + * @getscl: callback to get SCL line
> + * @udelay: signal toggle delay. SCL frequency is (500 / udelay) kHz
> + * @timeout: clock stretching timeout in jiffies. If the slave keeps
> + * Â Â SCL low for longer than this, the transfer will time out.
> + */
> +struct i2c_bit_platform_data {
> + Â Â Â void *data;
> + Â Â Â void (*setsda) (void *data, int state);
> + Â Â Â void (*setscl) (void *data, int state);
> + Â Â Â int Â(*getsda) (void *data);
> + Â Â Â int Â(*getscl) (void *data);
> + Â Â Â int udelay;
> + Â Â Â int timeout;
> +};
> +
> +#endif /* _LINUX_I2C_BIT_PLATFORM_H */
> --
> 1.7.0.4
>
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux GPIO]     [Linux SPI]     [Linux Hardward Monitoring]     [LM Sensors]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux