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 v3 8/9] tegra: i2c: Enable new CONFIG_SYS_I2C framework
Date: Thu, 01 Aug 2013 06:32:11 +0200	[thread overview]
Message-ID: <51F9E4CB.9040004@denx.de> (raw)
In-Reply-To: <51F9662D.1070602@wwwdotorg.org>

Hello Stephen,

Am 31.07.2013 21:31, schrieb Stephen Warren:
> On 07/30/2013 11:46 PM, Heiko Schocher wrote:
> ...
>> Hmm.. each i2c adapter has its own init function ... why the tegra
>> driver do not use it? And do the necessary inits in it? So we
>> initialize an adapater only if we use it, which is also a rule
>> for u-boot ...
>>
>> I have no hw, but it should be possible to add to process_nodes()
>> a parameter "controller_number" and call
>> process_nodes(controller_number, ...) from the i2c drivers init
>> function ...
>
> There are two steps to initializing I2C on a Tegra system:
>
> 1) Parsing the DT to determine which/how-many I2C adapters exist in the
> SoC. This will yield information such as the register address of the I2C
> adapters, which clock/reset signal they rely on, perhaps the max bus
> clock rate, etc.
>
> This is a single global operation that needs to happen one single time
> before anything else.

Why?

> This stage initializes the i2c_controllers[] array, since that's what
> stores all the data parsed from DT.
>
> 2) Actually initializing or using the I2C HW. That could certainly be
> part of the per-I2C-controller init() function you mention.

For that purpose is the i2c_init function.

And why we could not do step 1 when we do step 2? Why doing step 1
for hw we later do not use?

saying something like this (just as an example, should be tested):

diff --git a/drivers/i2c/tegra_i2c.c b/drivers/i2c/tegra_i2c.c
index 9ac3969..7bbd3c7 100644
--- a/drivers/i2c/tegra_i2c.c
+++ b/drivers/i2c/tegra_i2c.c
@@ -378,81 +378,91 @@ static int i2c_get_config(const void *blob, int node, struct i2c_bus *i2c_bus)
   * @param is_scs       1 if this HW uses a single clock source (T114+)
   * @return 0 if ok, -1 on error
   */
-static int process_nodes(const void *blob, int node_list[], int count,
+static int process_nodes(const void *blob, int node_list[],
+                        struct i2c_adapter *adap, int count,
                          int is_dvc, int is_scs)
  {
         struct i2c_bus *i2c_bus;
-       int i;
-
-       /* build the i2c_controllers[] for each controller */
-       for (i = 0; i < count; i++) {
-               int node = node_list[i];
+       int node = node_list[i];

-               if (node <= 0)
-                       continue;
+       bus = &i2c_controllers[adap->hwadapnr];
+       i2c_bus->id = adap->hwadapnr;

-               i2c_bus = &i2c_controllers[i];
-               i2c_bus->id = i;
+       if (node <= 0)
+               continue;

-               if (i2c_get_config(blob, node, i2c_bus)) {
-                       printf("i2c_init_board: failed to decode bus %d\n", i);
-                       return -1;
-               }
+       if (i2c_get_config(blob, node, i2c_bus)) {
+               printf("i2c_init_board: failed to decode bus %d\n", i);
+               return -1;
+       }

-               i2c_bus->is_scs = is_scs;
+       i2c_bus->is_scs = is_scs;

-               i2c_bus->is_dvc = is_dvc;
-               if (is_dvc) {
-                       i2c_bus->control =
-                               &((struct dvc_ctlr *)i2c_bus->regs)->control;
-               } else {
-                       i2c_bus->control = &i2c_bus->regs->control;
-               }
-               debug("%s: controller bus %d at %p, periph_id %d, speed %d: ",
-                     is_dvc ? "dvc" : "i2c", i, i2c_bus->regs,
-                     i2c_bus->periph_id, i2c_bus->speed);
-               i2c_init_controller(i2c_bus);
-               debug("ok\n");
-               i2c_bus->inited = 1;
-
-               /* Mark position as used */
-               node_list[i] = -1;
+       i2c_bus->is_dvc = is_dvc;
+       if (is_dvc) {
+               i2c_bus->control =
+                       &((struct dvc_ctlr *)i2c_bus->regs)->control;
+       } else {
+               i2c_bus->control = &i2c_bus->regs->control;
         }
+       debug("%s: controller bus %d at %p, periph_id %d, speed %d: ",
+             is_dvc ? "dvc" : "i2c", i, i2c_bus->regs,
+             i2c_bus->periph_id, i2c_bus->speed);
+       i2c_init_controller(i2c_bus);
+       debug("ok\n");
+       i2c_bus->inited = 1;
+
+       /* Mark position as used */
+       node_list[i] = -1;

         return 0;
  }

  /* Sadly there is no error return from this function */
-void i2c_init_board(void)
+static int tegra_i2c_init_board(struct i2c_adapter *adap)
  {
+       struct i2c_bus *i2c_bus;
         int node_list[TEGRA_I2C_NUM_CONTROLLERS];
         const void *blob = gd->fdt_blob;
         int count;

+       bus = tegra_i2c_get_bus(adap);
+        if (bus)
+                return 0;
+
         /* First check for newer (T114+) I2C ports */
         count = fdtdec_find_aliases_for_id(blob, "i2c",
                         COMPAT_NVIDIA_TEGRA114_I2C, node_list,
                         TEGRA_I2C_NUM_CONTROLLERS);
-       if (process_nodes(blob, node_list, count, 0, 1))
-               return;
+       if (process_nodes(blob, node_list, adap, count, 0, 1))
+               return -1;

         /* Now get the older (T20/T30) normal I2C ports */
         count = fdtdec_find_aliases_for_id(blob, "i2c",
                         COMPAT_NVIDIA_TEGRA20_I2C, node_list,
                         TEGRA_I2C_NUM_CONTROLLERS);
-       if (process_nodes(blob, node_list, count, 0, 0))
-               return;
+       if (process_nodes(blob, node_list, adap, count, 0, 0))
+               return -1;

         /* Now look for dvc ports */
         count = fdtdec_add_aliases_for_id(blob, "i2c",
                         COMPAT_NVIDIA_TEGRA20_DVC, node_list,
                         TEGRA_I2C_NUM_CONTROLLERS);
-       if (process_nodes(blob, node_list, count, 1, 0))
-               return;
+       if (process_nodes(blob, node_list, adap, count, 1, 0))
+               return -1;
+
+       return 0;
  }

  static void tegra_i2c_init(struct i2c_adapter *adap, int speed, int slaveaddr)
  {
+       int ret;
+
+       ret = tegra_i2c_init_board(adap);
+       if (ret) {
+               printf("Could not decode bus: %d\n", adap->hwadapnr);
+               return;
+       }
         /* This will override the speed selected in the fdt for that port */
         debug("i2c_init(speed=%u, slaveaddr=0x%x)\n", speed, slaveaddr);
         i2c_set_bus_speed(speed);

Which will call process_nodes() from the i2c_init function, which only
is called, when i2c bus get used ...

> Now, I think the big disconnect here is that historically, the U-Boot
> binary has hard-coded all the details that step (1) above parses out of
> DT, so that step (1) did not need to exist.
>
> However, Simon has been pushing Tegra towards not hard-coding any of
> this information, but instead having a single binary that can work on
> arbitrary Tegra boards and even across different Tegra SoCs which have a
> different number of I2C controllers at different register addresses.
> This is quite fundamentally different to how U-Boot has worked in the
> past, and evidently has some problems fitting into the typical U-Boot
> initialization sequence.

Yes ... but again, if we parse the DT in the moment we need to init
a hw, it would fit again (at least for the dt case). But we have a
problem, if we need to write (like the i2c_controllers[] array) before
relocation. So I2C and DT usage is not possible before relocation.
(And not only i2c in conjunction with dt I think)

bye,
Heiko
-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

  reply	other threads:[~2013-08-01  4:32 UTC|newest]

Thread overview: 104+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-04 12:01 [U-Boot] [PATCH v3 0/9] Bring in new I2C framework Heiko Schocher
2013-05-04 12:01 ` [U-Boot] [PATCH v3 1/9] i2c: add i2c_core and prepare for new multibus support Heiko Schocher
2013-05-04 12:01 ` [U-Boot] [PATCH v3 2/9] i2c: common changes for multibus/multiadapter support Heiko Schocher
2013-05-06 16:39   ` Daniel Schwierzeck
2013-05-07 13:05     ` Heiko Schocher
2013-05-11 21:17   ` Simon Glass
2013-05-13  4:47     ` Heiko Schocher
2013-05-11 21:33   ` Simon Glass
2013-05-13  5:41     ` Heiko Schocher
2013-05-04 12:01 ` [U-Boot] [PATCH v3 3/9] i2c, soft-i2c: switch to new " Heiko Schocher
2013-05-04 12:01 ` [U-Boot] [PATCH v3 4/9] i2c, fsl_i2c: " Heiko Schocher
2013-05-04 12:01 ` [U-Boot] [PATCH v3 5/9] i2c, multibus: get rid of CONFIG_I2C_MUX Heiko Schocher
2013-05-06 12:23   ` Holger Brunck
2013-05-06 13:57     ` Heiko Schocher
2013-05-04 12:01 ` [U-Boot] [PATCH v3 6/9] i2c, multibus, keymile: get rid of EEprom_ivm envvariable Heiko Schocher
2013-05-06 12:24   ` Holger Brunck
2013-05-06 13:58     ` Heiko Schocher
2013-05-04 12:01 ` [U-Boot] [PATCH v3 7/9] tegra: i2c: Add function to know about current bus Heiko Schocher
2013-05-04 12:01 ` [U-Boot] [PATCH v3 8/9] tegra: i2c: Enable new CONFIG_SYS_I2C framework Heiko Schocher
2013-05-06 19:08   ` Stephen Warren
2013-05-07  8:01     ` [U-Boot] [PATCH v3 8/9] tegra: i2c: Enable new CONFIG_SYS_I2Cframework Marc Dietrich
2013-05-07 14:55       ` Stephen Warren
2013-05-07 16:17         ` Simon Glass
2013-05-08  4:11         ` Heiko Schocher
2013-05-07 13:07     ` [U-Boot] [PATCH v3 8/9] tegra: i2c: Enable new CONFIG_SYS_I2C framework Heiko Schocher
     [not found]     ` <5FBF8E85CA34454794F0F7ECBA79798F37ACAFEF3F@HQMAIL04.nvidia.com>
2013-05-07 13:12       ` Heiko Schocher
2013-07-29 16:12   ` Stephen Warren
2013-07-30  4:28     ` Heiko Schocher
2013-07-30  4:34       ` Simon Glass
2013-07-30 18:56       ` Stephen Warren
2013-07-31  4:29         ` Heiko Schocher
2013-07-30 19:22       ` Stephen Warren
2013-07-30 20:00         ` Stephen Warren
2013-07-30 21:21           ` Simon Glass
2013-07-30 21:32             ` Stephen Warren
2013-07-30 21:46               ` Simon Glass
2013-07-30 21:51                 ` Stephen Warren
2013-07-30 22:05                   ` Simon Glass
2013-07-31  5:46                     ` Heiko Schocher
2013-07-31 19:31                       ` Stephen Warren
2013-08-01  4:32                         ` Heiko Schocher [this message]
2013-08-01  5:39                           ` Stephen Warren
2013-08-01  6:02                             ` Heiko Schocher
2013-08-01  6:53                               ` Albert ARIBAUD
2013-08-01  8:38                                 ` Heiko Schocher
2013-08-01 14:22                                   ` Simon Glass
2013-08-01 15:06                                     ` Heiko Schocher
2013-08-01 20:16                                     ` Albert ARIBAUD
2013-08-02 19:32                                       ` Simon Glass
2013-08-01 20:14                                   ` Albert ARIBAUD
2013-08-01 20:34                                 ` Stephen Warren
2013-08-01 20:32                               ` Stephen Warren
2013-08-02  4:40                                 ` Heiko Schocher
2013-08-02 19:35                                   ` Simon Glass
2013-08-02 21:43                                   ` Stephen Warren
2013-08-03  3:55                                     ` Heiko Schocher
2013-08-05 15:40                                       ` Simon Glass
2013-08-05 17:28                                         ` Stephen Warren
2013-08-05 20:12                                           ` Simon Glass
2013-08-05 20:15                                             ` Stephen Warren
2013-08-05 17:59                                       ` Stephen Warren
2013-07-30 22:09                   ` Albert ARIBAUD
2013-07-30 22:11                     ` Simon Glass
2013-07-31  5:18                     ` Wolfgang Denk
2013-07-31  5:55                       ` Heiko Schocher
2013-07-31  7:06                       ` Albert ARIBAUD
2013-07-31  7:36                         ` Heiko Schocher
2013-07-31  8:16                           ` Albert ARIBAUD
2013-07-31  8:31                             ` Heiko Schocher
2013-07-31  9:38                               ` Albert ARIBAUD
2013-07-31 12:30                                 ` Simon Glass
2013-07-31 13:03                                   ` Heiko Schocher
2013-07-31 19:41                               ` Stephen Warren
2013-08-01  4:32                                 ` Heiko Schocher
2013-07-31 19:39                         ` Wolfgang Denk
2013-07-31  5:52                     ` Heiko Schocher
2013-07-31  5:03           ` Heiko Schocher
2013-08-05 19:21           ` Stephen Warren
2013-08-05 20:08             ` Tom Rini
2013-08-05 21:06               ` Stephen Warren
2013-08-05 23:18               ` Stephen Warren
2013-07-30 21:19         ` Simon Glass
2013-07-30 21:21           ` Stephen Warren
2013-07-30 21:45             ` Simon Glass
2013-07-31  5:01         ` Heiko Schocher
2013-05-04 12:01 ` [U-Boot] [PATCH v3 9/9] i2c, ppc4xx_i2c: switch to new multibus/multiadapter support Heiko Schocher
2013-05-06  6:52   ` Stefan Roese
2013-05-06  8:57 ` [U-Boot] [PATCH v3 0/9] Bring in new I2C framework Dirk Eibach
2013-05-06 14:11   ` Heiko Schocher
2013-05-17 13:17 ` Piotr Wilczek
2013-05-18 17:41   ` Simon Glass
2013-05-20  6:13     ` Piotr Wilczek
2013-06-19 22:07       ` Simon Glass
2013-06-20  3:38         ` Heiko Schocher
2013-06-20  5:50           ` Minkyu Kang
2013-06-20  6:41             ` Piotr Wilczek
2013-06-20  7:14               ` Heiko Schocher
2013-06-20  8:34                 ` Piotr Wilczek
2013-06-20  9:19                   ` Heiko Schocher
2013-06-20  5:52           ` Piotr Wilczek
2013-06-20  6:52           ` Dirk Eibach
2013-06-20  7:59             ` Heiko Schocher
2013-06-20  8:20               ` Dirk Eibach
2013-06-20  9:11                 ` Heiko Schocher

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=51F9E4CB.9040004@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