uboot/board/trizepsiv/eeprom.c
<<
>>
Prefs
   1/*
   2 * (C) Copyright 2007
   3 * Stefano Babic, DENX Software Engineering, sbabic@denx.de.
   4 *
   5 * SPDX-License-Identifier:     GPL-2.0+
   6 */
   7
   8#include <common.h>
   9#include <command.h>
  10#include <dm9000.h>
  11
  12static int do_read_dm9000_eeprom ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) {
  13        unsigned int i;
  14        u8 data[2];
  15
  16        for (i=0; i < 0x40; i++) {
  17                if (!(i % 0x10))
  18                        printf("\n%08x:", i);
  19                dm9000_read_srom_word(i, data);
  20                printf(" %02x%02x", data[1], data[0]);
  21        }
  22        printf ("\n");
  23        return (0);
  24}
  25
  26static int do_write_dm9000_eeprom ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) {
  27        int offset,value;
  28
  29        if (argc < 4)
  30                return cmd_usage(cmdtp);
  31
  32        offset=simple_strtoul(argv[2],NULL,16);
  33        value=simple_strtoul(argv[3],NULL,16);
  34        if (offset > 0x40) {
  35                printf("Wrong offset : 0x%x\n",offset);
  36                return cmd_usage(cmdtp);
  37        }
  38        dm9000_write_srom_word(offset, value);
  39        return (0);
  40}
  41
  42int do_dm9000_eeprom ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) {
  43        if (argc < 2)
  44                return cmd_usage(cmdtp);
  45
  46        if (strcmp (argv[1],"read") == 0)
  47                return (do_read_dm9000_eeprom(cmdtp,flag,argc,argv));
  48        else if (strcmp (argv[1],"write") == 0)
  49                return (do_write_dm9000_eeprom(cmdtp,flag,argc,argv));
  50        else
  51                return cmd_usage(cmdtp);
  52}
  53
  54U_BOOT_CMD(
  55        dm9000ee,4,1,do_dm9000_eeprom,
  56        "Read/Write eeprom connected to Ethernet Controller",
  57        "\ndm9000ee write <word offset> <value> \n"
  58        "\tdm9000ee read \n"
  59        "\tword:\t\t00-02 : MAC Address\n"
  60        "\t\t\t03-07 : DM9000 Configuration\n"
  61        "\t\t\t08-63 : User data"
  62);
  63