uboot/arch/powerpc/cpu/ppc4xx/cmd_chip_config.c
<<
>>
Prefs
   1/*
   2 * (C) Copyright 2008-2009
   3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
   4 *
   5 * (C) Copyright 2009
   6 * Dirk Eibach,  Guntermann & Drunck GmbH, eibach@gdsys.de
   7 *
   8 * See file CREDITS for list of people who contributed to this
   9 * project.
  10 *
  11 * This program is free software; you can redistribute it and/or
  12 * modify it under the terms of the GNU General Public License as
  13 * published by the Free Software Foundation; either version 2 of
  14 * the License, or (at your option) any later version.
  15 *
  16 * This program is distributed in the hope that it will be useful,
  17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19 * GNU General Public License for more details.
  20 *
  21 * You should have received a copy of the GNU General Public License
  22 * along with this program; if not, write to the Free Software
  23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24 * MA 02111-1307 USA
  25 *
  26 */
  27
  28#include <common.h>
  29#include <command.h>
  30#include <i2c.h>
  31#include <asm/ppc4xx_config.h>
  32#include <asm/io.h>
  33
  34static void print_configs(int cur_config_nr)
  35{
  36        int i;
  37
  38        for (i = 0; i < ppc4xx_config_count; i++) {
  39                printf("%-16s - %s", ppc4xx_config_val[i].label,
  40                       ppc4xx_config_val[i].description);
  41                if (i == cur_config_nr)
  42                        printf(" ***");
  43                printf("\n");
  44        }
  45
  46}
  47
  48static int do_chip_config(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  49{
  50        int i;
  51        int ret;
  52        int cur_config_nr = -1;
  53        u8 cur_config[CONFIG_4xx_CONFIG_BLOCKSIZE];
  54
  55        /*
  56         * First switch to correct I2C bus. This is I2C bus 0
  57         * for all currently available 4xx derivats.
  58         */
  59        I2C_SET_BUS(0);
  60
  61#ifdef CONFIG_CMD_EEPROM
  62        ret = eeprom_read(CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR,
  63                          CONFIG_4xx_CONFIG_I2C_EEPROM_OFFSET,
  64                          cur_config, CONFIG_4xx_CONFIG_BLOCKSIZE);
  65#else
  66        ret = i2c_read(CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR,
  67                       CONFIG_4xx_CONFIG_I2C_EEPROM_OFFSET,
  68                       1, cur_config, CONFIG_4xx_CONFIG_BLOCKSIZE);
  69#endif
  70        if (ret) {
  71                printf("Error reading EEPROM at addr 0x%x\n",
  72                       CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR);
  73                return -1;
  74        }
  75
  76        /*
  77         * Search the current configuration
  78         */
  79        for (i = 0; i < ppc4xx_config_count; i++) {
  80                if (memcmp(cur_config, ppc4xx_config_val[i].val,
  81                           CONFIG_4xx_CONFIG_BLOCKSIZE) == 0)
  82                        cur_config_nr = i;
  83        }
  84
  85        if (cur_config_nr == -1) {
  86                printf("Warning: The I2C bootstrap values don't match any"
  87                       " of the available options!\n");
  88                printf("I2C bootstrap EEPROM values are (I2C address 0x%02x):\n",
  89                        CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR);
  90                for (i = 0; i < CONFIG_4xx_CONFIG_BLOCKSIZE; i++) {
  91                        printf("%02x ", cur_config[i]);
  92                }
  93                printf("\n");
  94        }
  95
  96        if (argc < 2) {
  97                printf("Available configurations (I2C address 0x%02x):\n",
  98                       CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR);
  99                print_configs(cur_config_nr);
 100                return 0;
 101        }
 102
 103        for (i = 0; i < ppc4xx_config_count; i++) {
 104                /*
 105                 * Search for configuration name/label
 106                 */
 107                if (strcmp(argv[1], ppc4xx_config_val[i].label) == 0) {
 108                        printf("Using configuration:\n%-16s - %s\n",
 109                               ppc4xx_config_val[i].label,
 110                               ppc4xx_config_val[i].description);
 111
 112#ifdef CONFIG_CMD_EEPROM
 113                        ret = eeprom_write(CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR,
 114                                           CONFIG_4xx_CONFIG_I2C_EEPROM_OFFSET,
 115                                           ppc4xx_config_val[i].val,
 116                                           CONFIG_4xx_CONFIG_BLOCKSIZE);
 117#else
 118                        ret = i2c_write(CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR,
 119                                        CONFIG_4xx_CONFIG_I2C_EEPROM_OFFSET,
 120                                        1, ppc4xx_config_val[i].val,
 121                                        CONFIG_4xx_CONFIG_BLOCKSIZE);
 122#endif
 123                        udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
 124                        if (ret) {
 125                                printf("Error updating EEPROM at addr 0x%x\n",
 126                                       CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR);
 127                                return -1;
 128                        }
 129
 130                        printf("done (dump via 'i2c md %x 0.1 %x')\n",
 131                               CONFIG_4xx_CONFIG_I2C_EEPROM_ADDR,
 132                               CONFIG_4xx_CONFIG_BLOCKSIZE);
 133                        printf("Reset the board for the changes to"
 134                               " take effect\n");
 135                        return 0;
 136                }
 137        }
 138
 139        printf("Configuration %s not found!\n", argv[1]);
 140        print_configs(cur_config_nr);
 141        return -1;
 142}
 143
 144U_BOOT_CMD(
 145        chip_config,    2,      0,      do_chip_config,
 146        "program the I2C bootstrap EEPROM",
 147        "[config-label]"
 148);
 149