[PATCH v4 1/7] ARM: OMAP4/5: Centralize early clock initialization

Early clock initialization is currently done in two stages for OMAP4/5
SoCs. The first stage is the initialization of console clocks and
then we initialize basic clocks for functionality necessary for SoC
initialization and basic board functionality.

By splitting up prcm_init and centralizing this clock initialization,
we setup the code for follow on patches that can do board specific
initialization such as board detection which will depend on these
basic clocks.

As part of this change, since the early clock initialization
is centralized, we no longer need to expose the console clock
initialization.

NOTE: we change the sequence slightly by initializing console clocks
timer after the io settings are complete, but this is not expected
to have any functioanlity impact since we setup the basic IO drive
strength initialization as part of do_io_settings.

Signed-off-by: Steve Kipisz <s-kipisz2@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Lokesh Vutla <lokeshvutla@ti.com>

Centralize gpi2c_init into omap_common from the sys_proto header so
that the information can be reused across SoCs.

Signed-off-by: Steve Kipisz <s-kipisz2@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Lokesh Vutla <lokeshvutla@ti.com>

Several TI EVMs have EEPROM that can contain board description information
such as revision, DDR definition, serial number, etc. In just about all
cases, these EEPROM are on the I2C bus and provides us the opportunity
to centralize the generic operations involved.

The on-board EEPROM on the BeagleBone Black, BeagleBone, AM335x EVM,
AM43x GP EVM, AM57xx-evm, BeagleBoard-X15 share the same format.
However, DRA-7* EVMs, OMAP4SDP use a modified format.

We hence introduce logic which is generic between these platforms
without enforcing any specific format. This allows the boards to use the
relevant format for operations that they might choose.

This module will compile for all TI SoC based boards when I2C is enabled,
even non-TI boards that do not have the EEPROM. If the functions are not
used, they will not be linked in.

It is important to note that this logic is fundamental to the board
configuration process such as DDR configuration which is needed in
SPL, hence cannot be part of the standard u-boot driver model (which
is available later in the process). Hence, to aid efficiency, the
eeprom contents are copied over to SRAM scratchpad memory area at the
first invocation to retrieve data.

The follow on patches introduce the use of this library for AM335x,
AM437x, and AM57xx.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Signed-off-by: Steve Kipisz <s-kipisz2@ti.com>

Use the generic EEPROM detection logic instead of duplicating the AM
eeprom logic.

Signed-off-by: Nishanth Menon <nm@ti.com>
Signed-off-by: Steven Kipisz <s-kipisz2@ti.com>

Now that we have a generic TI eeprom logic which can be reused accross
platforms, reuse the same.

Signed-off-by: Nishanth Menon <nm@ti.com>
Signed-off-by: Steven Kipisz <s-kipisz2@ti.com>

Many TI EVMs have capability to store relevant board information
such as DDR description in EEPROM. Further many pad configuration
variations can occur as part of revision changes in the platform.
In-order to support these at runtime, we for a board detection hook
which is available for override from board files that may desire to do
so.

NOTE: All TI EVMs are capable of detecting board information based on
early clocks that are configured. However, in case of additional needs
this can be achieved within the override logic from within the board
file.

Signed-off-by: Steve Kipisz <s-kipisz2@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

Current AM57xx evm supports both BeagleBoard-X15
(http://beagleboard.org/x15) and AM57xx EVM
(http://www.ti.com/tool/tmdxevm5728).

The AM572x EValuation Module(EVM) provides an affordable platform to
quickly start evaluation of Sitara. ARM Cortex-A15 AM57x Processors
(AM5728, AM5726, AM5718, AM5716) and accelerate development for HMI,
machine vision, networking, medical imaging and many other industrial
applications. This EVM is based on the same BeagleBoard-X15 Chassis
and adds mPCIe, mSATA, LCD, touchscreen, Camera, push button and TI's
wlink8 offering.

Since the EEPROM contents are compatible between the BeagleBoard-X15 and
the AM57xx-evm, we add support for the detection logic to enable
support for various user programmable scripting capability.

NOTE: U-boot configuration is currently a superset of AM57xx evm and
BeagleBoard-X15 and no additional configuration tweaking is needed.

This change also sets up the stage for future support of TI AM57xx EVMs
to the same base bootloader build.

Signed-off-by: Steve Kipisz <s-kipisz2@ti.com>

From: Nishanth Menon <nm@ti.com>

Use the generic EEPROM detection logic instead of duplicating the AM
eeprom logic.

Signed-off-by: Nishanth Menon <nm@ti.com>
Signed-off-by: Steven Kipisz <s-kipisz2@ti.com>

Reviewed-by: Lokesh Vutla <lokeshvutla@ti.com>

Thanks and regards,
Lokesh

From: Nishanth Menon <nm@ti.com>

Now that we have a generic TI eeprom logic which can be reused accross
platforms, reuse the same.

Signed-off-by: Nishanth Menon <nm@ti.com>
Signed-off-by: Steven Kipisz <s-kipisz2@ti.com>

Reviewed-by: Lokesh Vutla <lokeshvutla@ti.com>

Thanks and regards,
Lokesh

Many TI EVMs have capability to store relevant board information
such as DDR description in EEPROM. Further many pad configuration
variations can occur as part of revision changes in the platform.
In-order to support these at runtime, we for a board detection hook
which is available for override from board files that may desire to do
so.

NOTE: All TI EVMs are capable of detecting board information based on
early clocks that are configured. However, in case of additional needs
this can be achieved within the override logic from within the board
file.

Reviewed-by: Lokesh Vutla <lokeshvutla@ti.com>

Thanks and regards,
Lokesh

Acked-by: Igor Grinberg <grinberg@compulab.co.il>

Acked-by: Igor Grinberg <grinberg@compulab.co.il>

Reviewed-by: Tom Rini <trini@konsulko.com>

Reviewed-by: Tom Rini <trini@konsulko.com>

Reviewed-by: Tom Rini <trini@konsulko.com>

Reviewed-by: Tom Rini <trini@konsulko.com>

[...]

diff --git a/board/ti/common/board_detect.c b/board/ti/common/board_detect.c
new file mode 100644
index 000000000000..3d2b1bb1465e
--- /dev/null
+++ b/board/ti/common/board_detect.c

[...]

+int __maybe_unused ti_i2c_eeprom_am_get_print(int bus_addr, int dev_addr,
+ struct ti_am_eeprom_printable *p)
+{
+ struct ti_am_eeprom *ep;
+ int rc;
+
+ /* Incase of invalid eeprom contents */
+ p->name[0] = 0x00;
+ p->version[0] = 0x00;
+ p->serial[0] = 0x00;
+
+ rc = ti_i2c_eeprom_am_get(bus_addr, dev_addr, &ep);
+ if (rc)
+ return rc;
+
+ /*
+ * Alas! we have to null terminate and cleanup the strings!
+ */
+ strlcpy(p->name, ep->name, TI_EEPROM_HDR_NAME_LEN);
+ ti_eeprom_string_cleanup(p->name);
+ strlcpy(p->version, ep->version, TI_EEPROM_HDR_NAME_LEN);

s/TI_EEPROM_HDR_NAME_LEN/TI_EEPROM_HDR_REV_LEN ?

+ ti_eeprom_string_cleanup(p->version);
+ strlcpy(p->serial, ep->serial, TI_EEPROM_HDR_NAME_LEN);

s/TI_EEPROM_HDR_NAME_LEN/TI_EEPROM_HDR_SERIAL_LEN?

+ ti_eeprom_string_cleanup(p->serial);
+ return 0;
+}
+
+bool __maybe_unused board_am_is(char *name_tag)
+{
+ struct ti_am_eeprom *ep = TI_AM_EEPROM_DATA;
+
+ if (ep->header != TI_EEPROM_HEADER_MAGIC)
+ return false;
+ return !strncmp(ep->name, name_tag, TI_EEPROM_HDR_NAME_LEN);
+}
+
+bool __maybe_unused board_am_rev_is(char *rev_tag, int cmp_len)
+{
+ struct ti_am_eeprom *ep = TI_AM_EEPROM_DATA;
+ int l;
+
+ if (ep->header != TI_EEPROM_HEADER_MAGIC)
+ return false;
+
+ l = cmp_len > TI_EEPROM_HDR_REV_LEN ? TI_EEPROM_HDR_NAME_LEN : cmp_len;

s/TI_EEPROM_HDR_NAME_LEN/TI_EEPROM_HDR_REV_LEN/ ?

+ return !strncmp(ep->version, rev_tag, l);
+}
+

[...]

[...]

+#define TI_EEPROM_HDR_NAME_LEN 8
+#define TI_EEPROM_HDR_REV_LEN 12
+#define TI_EEPROM_HDR_SERIAL_LEN 4

^^ minor typo here as well. Serial should be 12 and REV is 4.

[...]

[...]

diff --git a/board/ti/am57xx/board.c b/board/ti/am57xx/board.c
index 042f9ab1965a..15da8e66fee5 100644
--- a/board/ti/am57xx/board.c
+++ b/board/ti/am57xx/board.c

  [...]

+static void setup_board_eeprom_env(void)
+{
+ char *name = "beagle_x15";
+ int rc;
+ struct ti_am_eeprom_printable p;
+
+ rc = ti_i2c_eeprom_am_get_print(CONFIG_EEPROM_BUS_ADDRESS,
+ CONFIG_EEPROM_CHIP_ADDRESS, &p);
+ if (rc) {
+ printf("Invalid EEPROM data(@0x%p). Default to X15\n",
+ TI_AM_EEPROM_DATA);
+ goto invalid_eeprom;
+ }
+
+ if (board_is_am572x_evm())
+ name = "am57xx_evm";

I suggest adding:
  else if (board_is_x15())
    name = "beagle_x15";
If we dont do that, we end up with the "Unidentified board claim"
print even if we have a valid eeprom.

Also, at this point, we can reasonably detect and update our prints (to
prevent folks from being confused :))

How about squashing the following to this patch?
diff --git a/board/ti/am57xx/board.c b/board/ti/am57xx/board.c
index 4ae484140608..30d358885fe0 100644
--- a/board/ti/am57xx/board.c
+++ b/board/ti/am57xx/board.c
@@ -46,7 +46,7 @@ DECLARE_GLOBAL_DATA_PTR;
#define GPIO_DDR_VTT_EN 203

const struct omap_sysinfo sysinfo = {
- "Board: BeagleBoard x15\n"
+ "Board: UNKNOWN(BeagleBoard X15?)\n"
};

static const struct dmm_lisa_map_regs beagle_x15_lisa_regs = {
@@ -262,6 +262,27 @@ void do_board_detect(void)

#else /* CONFIG_SPL_BUILD */

+void do_board_detect(void)
+{
+ struct ti_am_eeprom *ep;
+ char *bname = NULL;
+ int rc;