From mboxrd@z Thu Jan 1 00:00:00 1970 From: Felipe Balbi Date: Thu, 02 Mar 2017 21:10:32 +0200 Subject: [U-Boot] [PATCH 01/31] ti: common: board_detect: Allow settings board detection variables manually In-Reply-To: <20170302190435.23212-2-fcooper@ti.com> References: <20170302190435.23212-1-fcooper@ti.com> <20170302190435.23212-2-fcooper@ti.com> Message-ID: <87tw7bsdef.fsf@linux.intel.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hi, Franklin S Cooper Jr writes: > From: Nishanth Menon > > In some situations the EEPROM used for board detection may not be > programmed or simply programmed incorrectly. Therefore, it may be > necessary to "simulate" reading the contents of the EEPROM to set > appropriate variables used in the board detection code. > > This may also be helpful in certain boot modes where doing i2c reads > may be costly and the config supports running only a specific board. > > Signed-off-by: Nishanth Menon > Signed-off-by: Tero Kristo > Signed-off-by: Keerthy > Signed-off-by: Franklin S Cooper Jr. > --- > board/ti/common/board_detect.c | 24 ++++++++++++++++++++++++ > board/ti/common/board_detect.h | 17 +++++++++++++++++ > 2 files changed, 41 insertions(+) > > diff --git a/board/ti/common/board_detect.c b/board/ti/common/board_detect.c > index a5dba94..5aaf884 100644 > --- a/board/ti/common/board_detect.c > +++ b/board/ti/common/board_detect.c > @@ -116,6 +116,30 @@ static int __maybe_unused ti_i2c_eeprom_get(int bus_addr, int dev_addr, > return 0; > } > > +int __maybe_unused ti_i2c_eeprom_am_set(const char *name, const char *rev) > +{ > + struct ti_common_eeprom *ep; > + > + if (!name || !rev) > + return -1; > + > + ep = TI_EEPROM_DATA; > + if (ep->header == TI_EEPROM_HEADER_MAGIC) > + goto already_set; > + > + /* Set to 0 all fields */ > + memset(ep, 0, sizeof(*ep)); > + strncpy(ep->name, name, TI_EEPROM_HDR_NAME_LEN); > + strncpy(ep->version, rev, TI_EEPROM_HDR_REV_LEN); > + /* Some dummy serial number to identify the platform */ > + strncpy(ep->serial, "0000", TI_EEPROM_HDR_SERIAL_LEN); > + /* Mark it with a valid header */ > + ep->header = TI_EEPROM_HEADER_MAGIC; > + > +already_set: > + return 0; > +} > + > int __maybe_unused ti_i2c_eeprom_am_get(int bus_addr, int dev_addr) > { > int rc; > diff --git a/board/ti/common/board_detect.h b/board/ti/common/board_detect.h > index 343fcb4..eeeacd3 100644 > --- a/board/ti/common/board_detect.h > +++ b/board/ti/common/board_detect.h > @@ -193,4 +193,21 @@ u64 board_ti_get_emif2_size(void); > */ > void set_board_info_env(char *name); > > +/** > + * ti_i2c_eeprom_am_set() - Setup the eeprom data with predefined values > + * @name: Name of the board > + * @rev: Revision of the board > + * > + * In some cases such as in RTC-only mode, we are able to skip reading eeprom > + * and wasting i2c based initialization time by using predefined flags for > + * detecting what platform we are booting on. For those platforms, provide > + * a handy function to pre-program information. there's a micro-optimization for some cases here. You can try to read i2c only on first time and save the result to environment. Something like: if (!getenv("serial#")) { read_serial_from_eeprom(&serial); setenv("serial#", serial); saveenv(); } Of course, this assumes i2c is available and eeprom is properly programmed. For bogus eeprom data, well, can't do much. -- balbi