public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Heiko Schocher <hs@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 2/8] drivers: i2c: davinci_i2c: Update davinci i2c driver to driver model
Date: Fri, 28 Apr 2017 05:55:38 +0200	[thread overview]
Message-ID: <5902BD3A.3080403@denx.de> (raw)
In-Reply-To: <20170420152549.28031-3-fcooper@ti.com>

Hello Franklin,

Am 20.04.2017 um 17:25 schrieb Franklin S Cooper Jr:
> Convert davinci i2c driver to driver model.
>
> Signed-off-by: Franklin S Cooper Jr <fcooper@ti.com>
> ---
>   drivers/i2c/davinci_i2c.c | 92 +++++++++++++++++++++++++++++++++++++++++++++--
>   1 file changed, 90 insertions(+), 2 deletions(-)

Reviewed-by: Heiko Schocher <hs@denx.de>

Applied to u-boot-i2c/next

bye,
Heiko
>
> diff --git a/drivers/i2c/davinci_i2c.c b/drivers/i2c/davinci_i2c.c
> index a6bce26..4471193 100644
> --- a/drivers/i2c/davinci_i2c.c
> +++ b/drivers/i2c/davinci_i2c.c
> @@ -14,11 +14,21 @@
>
>   #include <common.h>
>   #include <i2c.h>
> +#include <dm.h>
>   #include <asm/arch/hardware.h>
>   #include <asm/arch/i2c_defs.h>
>   #include <asm/io.h>
>   #include "davinci_i2c.h"
>
> +#ifdef CONFIG_DM_I2C
> +/* Information about i2c controller */
> +struct i2c_bus {
> +	int			id;
> +	uint			speed;
> +	struct i2c_regs		*regs;
> +};
> +#endif
> +
>   #define CHECK_NACK() \
>   	do {\
>   		if (tmp & (I2C_TIMEOUT | I2C_STAT_NACK)) {\
> @@ -27,8 +37,6 @@
>   		} \
>   	} while (0)
>
> -static struct i2c_regs *davinci_get_base(struct i2c_adapter *adap);
> -
>   static int _wait_for_bus(struct i2c_regs *i2c_base)
>   {
>   	int	stat, timeout;
> @@ -331,6 +339,7 @@ static int _davinci_i2c_probe_chip(struct i2c_regs *i2c_base, uint8_t chip)
>   	return rc;
>   }
>
> +#ifndef CONFIG_DM_I2C
>   static struct i2c_regs *davinci_get_base(struct i2c_adapter *adap)
>   {
>   	switch (adap->hwadapnr) {
> @@ -420,3 +429,82 @@ U_BOOT_I2C_ADAP_COMPLETE(davinci_2, davinci_i2c_init, davinci_i2c_probe_chip,
>   			 CONFIG_SYS_DAVINCI_I2C_SLAVE2,
>   			 2)
>   #endif
> +
> +#else /* CONFIG_DM_I2C */
> +
> +static int davinci_i2c_xfer(struct udevice *bus, struct i2c_msg *msg,
> +			  int nmsgs)
> +{
> +	struct i2c_bus *i2c_bus = dev_get_priv(bus);
> +	int ret;
> +
> +	debug("i2c_xfer: %d messages\n", nmsgs);
> +	for (; nmsgs > 0; nmsgs--, msg++) {
> +		debug("i2c_xfer: chip=0x%x, len=0x%x\n", msg->addr, msg->len);
> +		if (msg->flags & I2C_M_RD) {
> +			ret = _davinci_i2c_read(i2c_bus->regs, msg->addr,
> +				0, 0, msg->buf, msg->len);
> +		} else {
> +			ret = _davinci_i2c_write(i2c_bus->regs, msg->addr,
> +				0, 0, msg->buf, msg->len);
> +		}
> +		if (ret) {
> +			debug("i2c_write: error sending\n");
> +			return -EREMOTEIO;
> +		}
> +	}
> +
> +	return ret;
> +}
> +
> +static int davinci_i2c_set_speed(struct udevice *dev, uint speed)
> +{
> +	struct i2c_bus *i2c_bus = dev_get_priv(dev);
> +
> +	i2c_bus->speed = speed;
> +	return _davinci_i2c_setspeed(i2c_bus->regs, speed);
> +}
> +
> +static int davinci_i2c_probe(struct udevice *dev)
> +{
> +	struct i2c_bus *i2c_bus = dev_get_priv(dev);
> +
> +	i2c_bus->id = dev->seq;
> +	i2c_bus->regs = (struct i2c_regs *)dev_get_addr(dev);
> +
> +	i2c_bus->speed = 100000;
> +	 _davinci_i2c_init(i2c_bus->regs, i2c_bus->speed, 0);
> +
> +	return 0;
> +}
> +
> +static int davinci_i2c_probe_chip(struct udevice *bus, uint chip_addr,
> +				  uint chip_flags)
> +{
> +	struct i2c_bus *i2c_bus = dev_get_priv(bus);
> +
> +	return _davinci_i2c_probe_chip(i2c_bus->regs, chip_addr);
> +}
> +
> +static const struct dm_i2c_ops davinci_i2c_ops = {
> +	.xfer		= davinci_i2c_xfer,
> +	.probe_chip	= davinci_i2c_probe_chip,
> +	.set_bus_speed	= davinci_i2c_set_speed,
> +};
> +
> +static const struct udevice_id davinci_i2c_ids[] = {
> +	{ .compatible = "ti,davinci-i2c"},
> +	{ .compatible = "ti,keystone-i2c"},
> +	{ }
> +};
> +
> +U_BOOT_DRIVER(i2c_davinci) = {
> +	.name	= "i2c_davinci",
> +	.id	= UCLASS_I2C,
> +	.of_match = davinci_i2c_ids,
> +	.probe	= davinci_i2c_probe,
> +	.priv_auto_alloc_size = sizeof(struct i2c_bus),
> +	.ops	= &davinci_i2c_ops,
> +};
> +
> +#endif /* CONFIG_DM_I2C */
>

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

  parent reply	other threads:[~2017-04-28  3:55 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-20 15:25 [U-Boot] [PATCH v2 0/8] drivers: i2c: davinci_i2c: Convert driver to DM Franklin S Cooper Jr
2017-04-20 15:25 ` [U-Boot] [PATCH v2 1/8] i2c: davinci: Split functions into two parts for future DM support Franklin S Cooper Jr
2017-04-26 19:16   ` Tom Rini
2017-04-28  3:54   ` Heiko Schocher
2017-04-20 15:25 ` [U-Boot] [PATCH v2 2/8] drivers: i2c: davinci_i2c: Update davinci i2c driver to driver model Franklin S Cooper Jr
2017-04-26 19:16   ` Tom Rini
2017-04-28  3:55   ` Heiko Schocher [this message]
2017-04-20 15:25 ` [U-Boot] [PATCH v2 3/8] ti: common: board_detect: Introduce function to set the address length Franklin S Cooper Jr
2017-04-26 19:16   ` Tom Rini
2017-04-28  3:58   ` Heiko Schocher
2017-04-20 15:25 ` [U-Boot] [PATCH v2 4/8] ti: common: board_detect: Set alen to expected value before i2c read Franklin S Cooper Jr
2017-04-28  4:00   ` Heiko Schocher
2017-04-20 15:25 ` [U-Boot] [PATCH v2 5/8] ARM: dts: k2g: Add I2C nodes to 66AK2Gx Franklin S Cooper Jr
2017-04-28  4:01   ` Heiko Schocher
2017-04-20 15:25 ` [U-Boot] [PATCH v2 6/8] ARM: dts: keystone2: add I2C aliases for davinci I2C nodes Franklin S Cooper Jr
2017-04-26 19:16   ` Tom Rini
2017-04-28  4:03   ` Heiko Schocher
2017-04-20 15:25 ` [U-Boot] [PATCH v2 7/8] ARM: dts: keystone-k2g-evm: Enable I2C0 and I2C1 Franklin S Cooper Jr
2017-04-26 19:16   ` Tom Rini
2017-04-28  4:05   ` Heiko Schocher
2017-04-20 15:25 ` [U-Boot] [PATCH v2 8/8] ARM: keystone: Enable DM_I2C by default Franklin S Cooper Jr
2017-04-26 19:16   ` Tom Rini
2017-04-28  4:07   ` Heiko Schocher
2017-04-21  4:08 ` [U-Boot] [PATCH v2 0/8] drivers: i2c: davinci_i2c: Convert driver to DM Vignesh R
2017-04-21  9:13   ` Vignesh R
2017-06-08  5:13 ` Lokesh Vutla

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=5902BD3A.3080403@denx.de \
    --to=hs@denx.de \
    --cc=u-boot@lists.denx.de \
    /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