public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Minkyu Kang <mk7.kang@samsung.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 05/16] I2C: Driver changes for FDT support
Date: Wed, 26 Dec 2012 20:54:31 +0900	[thread overview]
Message-ID: <50DAE577.2060104@samsung.com> (raw)
In-Reply-To: <1355486189-432-5-git-send-email-rajeshwari.s@samsung.com>

Dear Rajeshwari Shinde,

On 14/12/12 20:56, Rajeshwari Shinde wrote:
> Functions added to get the I2C bus number and reset I2C bus using
> FDT node.
> 
> Signed-off-by: Rajeshwari Shinde <rajeshwari.s@samsung.com>
> Acked-by: Simon Glass <sjg@chromium.org>
> Acked-by: Heiko Schocher <hs@denx.de>
> ---
> Changes in V1:
> 	-Rebased on latest u-boot-samsung
>  drivers/i2c/s3c24x0_i2c.c |   83 ++++++++++++++++++++++++++++++++++++++++++++-
>  drivers/i2c/s3c24x0_i2c.h |    8 ++++
>  include/i2c.h             |   26 ++++++++++++++
>  3 files changed, 116 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/i2c/s3c24x0_i2c.c b/drivers/i2c/s3c24x0_i2c.c
> index 9bc4c7f..94a093e 100644
> --- a/drivers/i2c/s3c24x0_i2c.c
> +++ b/drivers/i2c/s3c24x0_i2c.c
> @@ -27,9 +27,11 @@
>   */
>  
>  #include <common.h>
> +#include <fdtdec.h>
>  #ifdef CONFIG_EXYNOS5
>  #include <asm/arch/clk.h>
>  #include <asm/arch/cpu.h>
> +#include <asm/arch/pinmux.h>
>  #else
>  #include <asm/arch/s3c24x0_cpu.h>
>  #endif
> @@ -60,7 +62,14 @@
>  #define I2C_TIMEOUT 1		/* 1 second */
>  
>  
> -static unsigned int g_current_bus;	/* Stores Current I2C Bus */
> +/*
> + * For SPL boot some boards need i2c before SDRAM is initialised so force
> + * variables to live in SRAM
> + */
> +static unsigned int g_current_bus __attribute__((section(".data")));
> +static struct s3c24x0_i2c_bus i2c_bus[CONFIG_MAX_I2C_NUM]
> +			__attribute__((section(".data")));
> +static int i2c_busses __attribute__((section(".data")));
>  
>  #ifndef CONFIG_EXYNOS5
>  static int GetI2CSDA(void)
> @@ -507,4 +516,76 @@ int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len)
>  		(i2c, I2C_WRITE, chip << 1, &xaddr[4 - alen], alen, buffer,
>  		 len) != 0);
>  }
> +
> +#ifdef CONFIG_OF_CONTROL
> +void board_i2c_init(const void *blob)
> +{
> +

please remove this blank line.

> +	int node_list[CONFIG_MAX_I2C_NUM];
> +	int count, i;
> +
> +	count = fdtdec_find_aliases_for_id(blob, "i2c",
> +		COMPAT_SAMSUNG_S3C2440_I2C, node_list,
> +		CONFIG_MAX_I2C_NUM);

need blank line here.

> +	for (i = 0; i < count; i++) {
> +		struct s3c24x0_i2c_bus *bus;
> +		int node = node_list[i];

How handle if the value of count is bigger than CONFIG_MAX_I2C_NUM?

> +
> +		if (node <= 0)
> +			continue;
> +		bus = &i2c_bus[i];
> +		bus->regs = (struct s3c24x0_i2c *)
> +			fdtdec_get_addr(blob, node, "reg");
> +		bus->id = pinmux_decode_periph_id(blob, node);
> +		bus->node = node;
> +		bus->bus_num = i2c_busses++;
> +		exynos_pinmux_config(bus->id, 0);
> +	}
> +

please remove this blank line.

> +}
> +
> +static struct s3c24x0_i2c_bus *get_bus(unsigned int bus_idx)
> +{
> +	if (bus_idx < i2c_busses)
> +		return &i2c_bus[bus_idx];

need blank line here.

> +	debug("Undefined bus: %d\n", bus_idx);
> +	return NULL;
> +}
> +
> +int i2c_get_bus_num_fdt(int node)
> +{
> +	int i;
> +
> +	for (i = 0; i < i2c_busses; i++) {
> +		if (node == i2c_bus[i].node)
> +			return i;
> +	}
> +
> +	debug("%s: Can't find any matched I2C bus\n", __func__);
> +	return -1;
> +}
> +
> +int i2c_reset_port_fdt(const void *blob, int node)
> +{
> +	struct s3c24x0_i2c_bus *i2c;
> +

Please remove this blank line.

> +	int bus;
> +
> +	bus = i2c_get_bus_num_fdt(node);
> +	if (bus < 0) {
> +		debug("could not get bus for node %d\n", node);
> +		return -1;
> +	}

need blank line here.

> +	i2c = get_bus(bus);
> +	if (!i2c) {
> +		debug("get_bus() failed for node node %d\n", node);
> +		return -1;
> +	}
> +
> +	i2c_ch_init(i2c->regs, CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
> +
> +	return 0;
> +}
> +#endif
> +
>  #endif /* CONFIG_HARD_I2C */
> diff --git a/drivers/i2c/s3c24x0_i2c.h b/drivers/i2c/s3c24x0_i2c.h
> index 2dd4b06..1243bf1 100644
> --- a/drivers/i2c/s3c24x0_i2c.h
> +++ b/drivers/i2c/s3c24x0_i2c.h
> @@ -30,4 +30,12 @@ struct s3c24x0_i2c {
>  	u32	iicds;
>  	u32	iiclc;
>  };
> +
> +struct s3c24x0_i2c_bus {
> +	int node;	/* device tree node */
> +	int bus_num;	/* i2c bus number */
> +	struct s3c24x0_i2c *regs;
> +	enum periph_id id;
> +};
> +
>  #endif /* _S3C24X0_I2C_H */
> diff --git a/include/i2c.h b/include/i2c.h
> index 16f099d..c60d075 100644
> --- a/include/i2c.h
> +++ b/include/i2c.h
> @@ -262,4 +262,30 @@ extern int get_multi_scl_pin(void);
>  extern int get_multi_sda_pin(void);
>  extern int multi_i2c_init(void);
>  #endif
> +
> +/**
> + * Get FDT values for i2c bus.
> + *
> + * @param blob  Device tree blbo
> + * @return the number of I2C bus
> + */
> +void board_i2c_init(const void *blob);
> +
> +/**
> + * Find the I2C bus number by given a FDT I2C node.
> + *
> + * @param blob  Device tree blbo
> + * @param node  FDT I2C node to find
> + * @return the number of I2C bus (zero based), or -1 on error
> + */
> +int i2c_get_bus_num_fdt(int node);
> +
> +/**
> + * Reset the I2C bus represented by the given a FDT I2C node.
> + *
> + * @param blob  Device tree blbo
> + * @param node  FDT I2C node to find
> + * @return 0 if port was reset, -1 if not found
> + */
> +int i2c_reset_port_fdt(const void *blob, int node);
>  #endif	/* _I2C_H_ */
> 

--
Thanks,
Minkyu Kang.

  reply	other threads:[~2012-12-26 11:54 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-14 11:56 [U-Boot] [PATCH 01/16] EXYNOS5: FDT: Add I2C device node data Rajeshwari Shinde
2012-12-14 11:56 ` [U-Boot] [PATCH 02/16] EXYNOS5 : FDT: Add Aliases for I2C device Rajeshwari Shinde
2012-12-14 11:56 ` [U-Boot] [PATCH 03/16] FDT: Add compatible string for I2C Rajeshwari Shinde
2012-12-14 11:56 ` [U-Boot] [PATCH 04/16] EXYNOS5: FDT : Decode peripheral id Rajeshwari Shinde
2012-12-26 11:54   ` Minkyu Kang
2012-12-26 12:00     ` Rajeshwari Birje
2012-12-26 15:37       ` Simon Glass
2012-12-14 11:56 ` [U-Boot] [PATCH 05/16] I2C: Driver changes for FDT support Rajeshwari Shinde
2012-12-26 11:54   ` Minkyu Kang [this message]
2012-12-26 12:01     ` Rajeshwari Birje
2012-12-26 12:33     ` Rajeshwari Birje
2012-12-26 14:00       ` Minkyu Kang
2012-12-14 11:56 ` [U-Boot] [PATCH 06/16] SMDK5250: Initialise I2C using FDT Rajeshwari Shinde
2012-12-14 11:56 ` [U-Boot] [PATCH 07/16] EXYNOS5: FDT: Add sound device node data Rajeshwari Shinde
2012-12-14 11:56 ` [U-Boot] [PATCH 08/16] EXYNOS5: FDT: Add sound and codec device node Rajeshwari Shinde
2012-12-14 11:56 ` [U-Boot] [PATCH 09/16] EXYNOS5: FDT: Add compatible strings for sound Rajeshwari Shinde
2012-12-14 11:56 ` [U-Boot] [PATCH 10/16] Sound: Add FDT support to driver Rajeshwari Shinde
2012-12-14 11:56 ` [U-Boot] [PATCH 11/16] Sound: WM8994: Add FDT support to codec Rajeshwari Shinde
2012-12-26 11:55   ` Minkyu Kang
2012-12-26 12:02     ` Rajeshwari Birje
2012-12-14 11:56 ` [U-Boot] [PATCH 12/16] Sound: Add FDT support to CMD Rajeshwari Shinde
2012-12-14 11:56 ` [U-Boot] [PATCH 13/16] EXYNOS5: FDT: Add compatible strings for SPI Rajeshwari Shinde
2012-12-14 11:56 ` [U-Boot] [PATCH 14/16] EXYNOS5 : FDT: Add Aliases for SPI device Rajeshwari Shinde
2012-12-14 11:56 ` [U-Boot] [PATCH 15/16] EXYNOS5: FDT: Add SPI device node data Rajeshwari Shinde
2012-12-14 11:56 ` [U-Boot] [PATCH 16/16] SPI: EXYNOS: Add FDT support to driver Rajeshwari Shinde
2012-12-26 11:54   ` Minkyu Kang
2012-12-26 12:01     ` Rajeshwari Birje

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=50DAE577.2060104@samsung.com \
    --to=mk7.kang@samsung.com \
    --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