diff options
author | Wolfgang Denk <wd@denx.de> | 2008-08-31 22:16:29 (GMT) |
---|---|---|
committer | Wolfgang Denk <wd@denx.de> | 2008-08-31 22:16:29 (GMT) |
commit | e99e9575bbeba1b7c48e046547cae065ec0071de (patch) | |
tree | c08553c4d06725bd6013a46068df0059c5b49a00 /common | |
parent | a13b2d937941f6b525abfcfad96c034f94421188 (diff) | |
parent | 08ab4e1780fa63c88dd5a5ab52f4ff4ed1ee1878 (diff) | |
download | u-boot-e99e9575bbeba1b7c48e046547cae065ec0071de.tar.xz |
Merge branch 'Makefile' of git://git.denx.de/u-boot-arm
Diffstat (limited to 'common')
-rw-r--r-- | common/Makefile | 79 | ||||
-rw-r--r-- | common/cmd_autoscript.c | 4 | ||||
-rw-r--r-- | common/cmd_console.c | 9 | ||||
-rw-r--r-- | common/cmd_terminal.c | 14 | ||||
-rw-r--r-- | common/console.c | 62 | ||||
-rw-r--r-- | common/crc16.c | 107 | ||||
-rw-r--r-- | common/devices.c | 79 | ||||
-rw-r--r-- | common/gunzip.c | 113 | ||||
-rw-r--r-- | common/lists.c | 734 | ||||
-rw-r--r-- | common/miiphybb.c | 235 | ||||
-rw-r--r-- | common/miiphyutil.c | 2 | ||||
-rw-r--r-- | common/soft_i2c.c | 423 | ||||
-rw-r--r-- | common/soft_spi.c | 193 | ||||
-rw-r--r-- | common/usb_kbd.c | 14 |
14 files changed, 121 insertions, 1947 deletions
diff --git a/common/Makefile b/common/Makefile index 944b1c0..0fe9c8b 100644 --- a/common/Makefile +++ b/common/Makefile @@ -27,16 +27,39 @@ LIB = $(obj)libcommon.a AOBJS = +# core COBJS-y += main.o -COBJS-$(CONFIG_CMD_BEDBUG) += bedbug.o COBJS-y += circbuf.o +COBJS-y += console.o +COBJS-y += command.o +COBJS-y += devices.o +COBJS-y += dlmalloc.o +COBJS-y += exports.o +COBJS-y += hush.o +COBJS-y += image.o +COBJS-y += memsize.o +COBJS-y += s_record.o +COBJS-y += serial.o +COBJS-y += xyzModem.o + +# environment +COBJS-y += environment.o +COBJS-y += env_common.o +COBJS-y += env_dataflash.o +COBJS-y += env_eeprom.o +COBJS-y += env_flash.o +COBJS-y += env_nand.o +COBJS-y += env_nvram.o +COBJS-y += env_onenand.o +COBJS-y += env_sf.o +COBJS-y += env_nowhere.o + +# command COBJS-$(CONFIG_CMD_AMBAPP) += cmd_ambapp.o -COBJS-y += cmd_autoscript.o +COBJS-$(CONFIG_AUTOSCRIPT)$(CONFIG_CMD_AUTOSCRIPT) += cmd_autoscript.o COBJS-$(CONFIG_CMD_BDI) += cmd_bdinfo.o -COBJS-$(CONFIG_CMD_BEDBUG) += cmd_bedbug.o +COBJS-$(CONFIG_CMD_BEDBUG) += bedbug.o cmd_bedbug.o COBJS-$(CONFIG_CMD_BMP) += cmd_bmp.o -COBJS-y += image.o -COBJS-y += gunzip.o COBJS-y += cmd_boot.o COBJS-$(CONFIG_CMD_BOOTLDR) += cmd_bootldr.o COBJS-y += cmd_bootm.o @@ -84,10 +107,14 @@ COBJS-$(CONFIG_CMD_JFFS2) += cmd_jffs2.o COBJS-$(CONFIG_CMD_LICENSE) += cmd_license.o COBJS-y += cmd_load.o COBJS-$(CONFIG_LOGBUFFER) += cmd_log.o +COBJS-y += cmd_mac.o COBJS-y += cmd_mem.o +COBJS-$(CONFIG_CMD_MFSL) += cmd_mfsl.o +COBJS-$(CONFIG_MII)$(CONFIG_CMD_MII) += miiphyutil.o COBJS-$(CONFIG_CMD_MII) += cmd_mii.o COBJS-$(CONFIG_CMD_MISC) += cmd_misc.o COBJS-$(CONFIG_CMD_MMC) += cmd_mmc.o +COBJS-$(CONFIG_MP) += cmd_mp.o COBJS-y += cmd_nand.o COBJS-$(CONFIG_CMD_NET) += cmd_net.o COBJS-y += cmd_nvedit.o @@ -101,58 +128,30 @@ COBJS-$(CONFIG_CMD_PORTIO) += cmd_portio.o COBJS-$(CONFIG_CMD_REGINFO) += cmd_reginfo.o COBJS-$(CONFIG_CMD_REISER) += cmd_reiser.o COBJS-$(CONFIG_CMD_SATA) += cmd_sata.o +COBJS-$(CONFIG_CMD_SF) += cmd_sf.o COBJS-$(CONFIG_CMD_SCSI) += cmd_scsi.o COBJS-$(CONFIG_CMD_SETEXPR) += cmd_setexpr.o COBJS-$(CONFIG_CMD_SPI) += cmd_spi.o COBJS-$(CONFIG_CMD_STRINGS) += cmd_strings.o COBJS-$(CONFIG_CMD_TERMINAL) += cmd_terminal.o COBJS-$(CONFIG_CMD_UNIVERSE) += cmd_universe.o -COBJS-$(CONFIG_CMD_USB) += cmd_usb.o +ifdef CONFIG_CMD_USB +COBJS-y += cmd_usb.o +COBJS-y += usb.o +COBJS-$(CONFIG_USB_STORAGE) += usb_storage.o +endif COBJS-$(CONFIG_CMD_XIMG) += cmd_ximg.o COBJS-$(CONFIG_YAFFS2) += cmd_yaffs2.o COBJS-y += cmd_vfd.o -COBJS-y += command.o -COBJS-y += console.o -COBJS-y += devices.o -COBJS-y += dlmalloc.o COBJS-$(CONFIG_CMD_DOC) += docecc.o -COBJS-y += environment.o -COBJS-y += env_common.o -COBJS-y += env_nand.o -COBJS-y += env_dataflash.o -COBJS-y += env_flash.o -COBJS-y += env_eeprom.o -COBJS-y += env_onenand.o -COBJS-y += env_sf.o -COBJS-y += env_nvram.o -COBJS-y += env_nowhere.o -COBJS-y += exports.o COBJS-y += flash.o -COBJS-y += hush.o COBJS-y += kgdb.o COBJS-$(CONFIG_LCD) += lcd.o -COBJS-y += lists.o COBJS-$(CONFIG_LYNXKDI) += lynxkdi.o -COBJS-y += memsize.o -COBJS-$(CONFIG_BITBANGMII) += miiphybb.o -COBJS-y += miiphyutil.o -COBJS-y += s_record.o -COBJS-y += serial.o -COBJS-$(CONFIG_SOFT_I2C) += soft_i2c.o -COBJS-$(CONFIG_SOFT_SPI) += soft_spi.o -ifdef CONFIG_CMD_USB -COBJS-y += usb.o -COBJS-$(CONFIG_USB_STORAGE) += usb_storage.o -endif COBJS-$(CONFIG_USB_KEYBOARD) += usb_kbd.o -COBJS-y += crc16.o -COBJS-y += xyzModem.o -COBJS-y += cmd_mac.o -COBJS-$(CONFIG_CMD_MFSL) += cmd_mfsl.o -COBJS-$(CONFIG_MP) += cmd_mp.o -COBJS-$(CONFIG_CMD_SF) += cmd_sf.o COBJS-$(CONFIG_DDR_SPD) += ddr_spd.o +COBJS-y += $(COBJS-yy) COBJS := $(COBJS-y) SRCS := $(AOBJS:.o=.S) $(COBJS:.o=.c) OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS)) diff --git a/common/cmd_autoscript.c b/common/cmd_autoscript.c index 13af93e..c2e7e66 100644 --- a/common/cmd_autoscript.c +++ b/common/cmd_autoscript.c @@ -47,8 +47,6 @@ #include <hush.h> #endif -#if defined(CONFIG_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT) - int autoscript (ulong addr, const char *fit_uname) { @@ -200,8 +198,6 @@ autoscript (ulong addr, const char *fit_uname) return rcode; } -#endif - /**************************************************/ #if defined(CONFIG_CMD_AUTOSCRIPT) int diff --git a/common/cmd_console.c b/common/cmd_console.c index 50ddb01..e2bc2a3 100644 --- a/common/cmd_console.c +++ b/common/cmd_console.c @@ -31,14 +31,17 @@ extern void _do_coninfo (void); int do_coninfo (cmd_tbl_t * cmd, int flag, int argc, char *argv[]) { - int i, l; + int l; + struct list_head *list = device_get_list(); + struct list_head *pos; + device_t *dev; /* Scan for valid output and input devices */ puts ("List of available devices:\n"); - for (i = 1; i <= ListNumItems (devlist); i++) { - device_t *dev = ListGetPtrToItem (devlist, i); + list_for_each(pos, list) { + dev = list_entry(pos, device_t, list); printf ("%-8s %08x %c%c%c ", dev->name, diff --git a/common/cmd_terminal.c b/common/cmd_terminal.c index 8871607..67a2546 100644 --- a/common/cmd_terminal.c +++ b/common/cmd_terminal.c @@ -27,12 +27,10 @@ #include <common.h> #include <command.h> #include <devices.h> - -#if defined(CONFIG_CMD_TERMINAL) +#include <serial.h> int do_terminal(cmd_tbl_t * cmd, int flag, int argc, char *argv[]) { - int i, l; int last_tilde = 0; device_t *dev = NULL; @@ -40,13 +38,7 @@ int do_terminal(cmd_tbl_t * cmd, int flag, int argc, char *argv[]) return -1; /* Scan for selected output/input device */ - for (i = 1; i <= ListNumItems (devlist); i++) { - device_t *tmp = ListGetPtrToItem (devlist, i); - if (!strcmp(tmp->name, argv[1])) { - dev = tmp; - break; - } - } + dev = device_get_by_name(argv[1]); if (!dev) return -1; @@ -98,5 +90,3 @@ U_BOOT_CMD( "terminal - start terminal emulator\n", "" ); - -#endif /* CONFIG_CMD_TERMINAL */ diff --git a/common/console.c b/common/console.c index 1b095b1..cfcaeb8 100644 --- a/common/console.c +++ b/common/console.c @@ -325,9 +325,22 @@ inline void dbg(const char *fmt, ...) /** U-Boot INIT FUNCTIONS *************************************************/ +device_t *search_device (int flags, char *name) +{ + device_t *dev; + + dev = device_get_by_name(name); + + if(dev && (dev->flags & flags)) + return dev; + + return NULL; +} + int console_assign (int file, char *devname) { - int flag, i; + int flag; + device_t *dev; /* Check for valid file */ switch (file) { @@ -344,16 +357,10 @@ int console_assign (int file, char *devname) /* Check for valid device name */ - for (i = 1; i <= ListNumItems (devlist); i++) { - device_t *dev = ListGetPtrToItem (devlist, i); - - if (strcmp (devname, dev->name) == 0) { - if (dev->flags & flag) - return console_setfile (file, dev); + dev = search_device(flag, devname); - return -1; - } - } + if(dev) + return console_setfile (file, dev); return -1; } @@ -371,27 +378,6 @@ int console_init_f (void) return (0); } -#if defined(CFG_CONSOLE_IS_IN_ENV) || defined(CONFIG_SPLASH_SCREEN) || defined(CONFIG_SILENT_CONSOLE) -/* search a device */ -device_t *search_device (int flags, char *name) -{ - int i, items; - device_t *dev = NULL; - - items = ListNumItems (devlist); - if (name == NULL) - return dev; - - for (i = 1; i <= items; i++) { - dev = ListGetPtrToItem (devlist, i); - if ((dev->flags & flags) && (strcmp (name, dev->name) == 0)) { - break; - } - } - return dev; -} -#endif /* CFG_CONSOLE_IS_IN_ENV || CONFIG_SPLASH_SCREEN */ - #ifdef CFG_CONSOLE_IS_IN_ENV /* Called after the relocation - use desired console functions */ int console_init_r (void) @@ -488,7 +474,10 @@ int console_init_r (void) int console_init_r (void) { device_t *inputdev = NULL, *outputdev = NULL; - int i, items = ListNumItems (devlist); + int i; + struct list_head *list = device_get_list(); + struct list_head *pos; + device_t *dev; #ifdef CONFIG_SPLASH_SCREEN /* suppress all output if splash screen is enabled and we have @@ -498,11 +487,8 @@ int console_init_r (void) #endif /* Scan devices looking for input and output devices */ - for (i = 1; - (i <= items) && ((inputdev == NULL) || (outputdev == NULL)); - i++ - ) { - device_t *dev = ListGetPtrToItem (devlist, i); + list_for_each(pos, list) { + dev = list_entry(pos, device_t, list); if ((dev->flags & DEV_FLAGS_INPUT) && (inputdev == NULL)) { inputdev = dev; @@ -510,6 +496,8 @@ int console_init_r (void) if ((dev->flags & DEV_FLAGS_OUTPUT) && (outputdev == NULL)) { outputdev = dev; } + if(inputdev && outputdev) + break; } /* Initializes output console first */ diff --git a/common/crc16.c b/common/crc16.c deleted file mode 100644 index 6904365..0000000 --- a/common/crc16.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - *========================================================================== - * - * crc16.c - * - * 16 bit CRC with polynomial x^16+x^12+x^5+1 - * - *========================================================================== - *####ECOSGPLCOPYRIGHTBEGIN#### - * ------------------------------------------- - * This file is part of eCos, the Embedded Configurable Operating System. - * Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. - * Copyright (C) 2002 Gary Thomas - * - * eCos is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 or (at your option) any later version. - * - * eCos is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with eCos; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - * - * As a special exception, if other files instantiate templates or use macros - * or inline functions from this file, or you compile this file and link it - * with other works to produce a work based on this file, this file does not - * by itself cause the resulting work to be covered by the GNU General Public - * License. However the source code for this file must still be made available - * in accordance with section (3) of the GNU General Public License. - * - * This exception does not invalidate any other reasons why a work based on - * this file might be covered by the GNU General Public License. - * - * Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. - * at http: *sources.redhat.com/ecos/ecos-license/ - * ------------------------------------------- - *####ECOSGPLCOPYRIGHTEND#### - *========================================================================== - *#####DESCRIPTIONBEGIN#### - * - * Author(s): gthomas - * Contributors: gthomas,asl - * Date: 2001-01-31 - * Purpose: - * Description: - * - * This code is part of eCos (tm). - * - *####DESCRIPTIONEND#### - * - *========================================================================== - */ - -#include "crc.h" - -/* Table of CRC constants - implements x^16+x^12+x^5+1 */ -static const uint16_t crc16_tab[] = { - 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, - 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, - 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, - 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, - 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, - 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, - 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, - 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, - 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, - 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, - 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, - 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, - 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, - 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, - 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, - 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, - 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, - 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, - 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, - 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, - 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, - 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, - 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, - 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, - 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, - 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, - 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, - 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, - 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, - 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, - 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, - 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0, -}; - -uint16_t -cyg_crc16(unsigned char *buf, int len) -{ - int i; - uint16_t cksum; - - cksum = 0; - for (i = 0; i < len; i++) { - cksum = crc16_tab[((cksum>>8) ^ *buf++) & 0xFF] ^ (cksum << 8); - } - return cksum; -} diff --git a/common/devices.c b/common/devices.c index 9cc963a..2977436 100644 --- a/common/devices.c +++ b/common/devices.c @@ -36,7 +36,7 @@ DECLARE_GLOBAL_DATA_PTR; -list_t devlist = 0; +static device_t devs; device_t *stdio_devices[] = { NULL, NULL, NULL }; char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" }; @@ -48,18 +48,18 @@ char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" }; #ifdef CFG_DEVICE_NULLDEV void nulldev_putc(const char c) { - /* nulldev is empty! */ + /* nulldev is empty! */ } void nulldev_puts(const char *s) { - /* nulldev is empty! */ + /* nulldev is empty! */ } int nulldev_input(void) { - /* nulldev is empty! */ - return 0; + /* nulldev is empty! */ + return 0; } #endif @@ -108,10 +108,32 @@ static void drv_system_init (void) * DEVICES ************************************************************************** */ +struct list_head* device_get_list(void) +{ + return &(devs.list); +} + +device_t* device_get_by_name(char* name) +{ + struct list_head *pos; + device_t *dev; + + if(!name) + return NULL; + + list_for_each(pos, &(devs.list)) { + dev = list_entry(pos, device_t, list); + if(strcmp(dev->name, name) == 0) + return dev; + } + + return NULL; +} + int device_register (device_t * dev) { - ListInsertItem (devlist, dev, LIST_END); + list_add(&(dev->list), &(devs.list)); return 0; } @@ -121,20 +143,15 @@ int device_register (device_t * dev) #ifdef CFG_DEVICE_DEREGISTER int device_deregister(char *devname) { - int i,l,dev_index; - device_t *dev = NULL; + int l; + struct list_head *pos; + device_t *dev; char temp_names[3][8]; - dev_index = -1; - for (i=1; i<=ListNumItems(devlist); i++) { - dev = ListGetPtrToItem (devlist, i); - if(strcmp(dev->name,devname)==0) { - dev_index=i; - break; - } - } - if(dev_index<0) /* device not found */ - return 0; + dev = device_get_by_name(devname); + + if(!dev) /* device not found */ + return -1; /* get stdio devices (ListRemoveItem changes the dev list) */ for (l=0 ; l< MAX_FILES; l++) { if (stdio_devices[l] == dev) { @@ -145,14 +162,15 @@ int device_deregister(char *devname) stdio_devices[l]->name, sizeof(stdio_devices[l]->name)); } - ListRemoveItem(devlist,NULL,dev_index); + + list_del(&(dev->list)); + /* reassign Device list */ - for (i=1; i<=ListNumItems(devlist); i++) { - dev = ListGetPtrToItem (devlist, i); + list_for_each(pos, &(devs.list)) { + dev = list_entry(pos, device_t, list); for (l=0 ; l< MAX_FILES; l++) { - if(strcmp(dev->name,temp_names[l])==0) { + if(strcmp(dev->name, temp_names[l]) == 0) stdio_devices[l] = dev; - } } } return 0; @@ -161,7 +179,7 @@ int device_deregister(char *devname) int devices_init (void) { -#ifndef CONFIG_ARM /* already relocated for current ARM implementation */ +#ifndef CONFIG_ARM /* already relocated for current ARM implementation */ ulong relocation_offset = gd->reloc_off; int i; @@ -173,12 +191,8 @@ int devices_init (void) #endif /* Initialize the list */ - devlist = ListCreate (sizeof (device_t)); + INIT_LIST_HEAD(&(devs.list)); - if (devlist == NULL) { - eputs ("Cannot initialize the list of devices!\n"); - return -1; - } #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE); #endif @@ -207,10 +221,3 @@ int devices_init (void) return (0); } - -int devices_done (void) -{ - ListDispose (devlist); - - return 0; -} diff --git a/common/gunzip.c b/common/gunzip.c deleted file mode 100644 index 74f0bf9..0000000 --- a/common/gunzip.c +++ /dev/null @@ -1,113 +0,0 @@ -/* - * (C) Copyright 2000-2006 - * Wolfgang Denk, DENX Software Engineering, wd@denx.de. - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -#include <common.h> -#include <watchdog.h> -#include <command.h> -#include <image.h> -#include <malloc.h> -#include <zlib.h> - -#define ZALLOC_ALIGNMENT 16 -#define HEAD_CRC 2 -#define EXTRA_FIELD 4 -#define ORIG_NAME 8 -#define COMMENT 0x10 -#define RESERVED 0xe0 -#define DEFLATED 8 - -int gunzip(void *, int, unsigned char *, unsigned long *); -void *zalloc(void *, unsigned, unsigned); -void zfree(void *, void *, unsigned); - -void *zalloc(void *x, unsigned items, unsigned size) -{ - void *p; - - size *= items; - size = (size + ZALLOC_ALIGNMENT - 1) & ~(ZALLOC_ALIGNMENT - 1); - - p = malloc (size); - - return (p); -} - -void zfree(void *x, void *addr, unsigned nb) -{ - free (addr); -} - -int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp) -{ - z_stream s; - int r, i, flags; - - /* skip header */ - i = 10; - flags = src[3]; - if (src[2] != DEFLATED || (flags & RESERVED) != 0) { - puts ("Error: Bad gzipped data\n"); - return (-1); - } - if ((flags & EXTRA_FIELD) != 0) - i = 12 + src[10] + (src[11] << 8); - if ((flags & ORIG_NAME) != 0) - while (src[i++] != 0) - ; - if ((flags & COMMENT) != 0) - while (src[i++] != 0) - ; - if ((flags & HEAD_CRC) != 0) - i += 2; - if (i >= *lenp) { - puts ("Error: gunzip out of data in header\n"); - return (-1); - } - - s.zalloc = zalloc; - s.zfree = zfree; -#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) - s.outcb = (cb_func)WATCHDOG_RESET; -#else - s.outcb = Z_NULL; -#endif /* CONFIG_HW_WATCHDOG */ - - r = inflateInit2(&s, -MAX_WBITS); - if (r != Z_OK) { - printf ("Error: inflateInit2() returned %d\n", r); - return (-1); - } - s.next_in = src + i; - s.avail_in = *lenp - i; - s.next_out = dst; - s.avail_out = dstlen; - r = inflate(&s, Z_FINISH); - if (r != Z_OK && r != Z_STREAM_END) { - printf ("Error: inflate() returned %d\n", r); - return (-1); - } - *lenp = s.next_out - (unsigned char *) dst; - inflateEnd(&s); - - return (0); -} diff --git a/common/lists.c b/common/lists.c deleted file mode 100644 index 0dc090a..0000000 --- a/common/lists.c +++ /dev/null @@ -1,734 +0,0 @@ -#include <common.h> -#include <malloc.h> -#include <lists.h> - -#define MAX(a,b) (((a)>(b)) ? (a) : (b)) -#define MIN(a,b) (((a)<(b)) ? (a) : (b)) -#define CAT4CHARS(a,b,c,d) ((a<<24) | (b<<16) | (c<<8) | d) - -/* increase list size by 10% every time it is full */ -#define kDefaultAllocationPercentIncrease 10 - -/* always increase list size by 4 items when it is full */ -#define kDefaultAllocationminNumItemsIncrease 4 - -/* - * how many items to expand the list by when it becomes full - * = current listSize (in items) + (hiword percent of list size) + loword - */ -#define NUMITEMSPERALLOC(list) MAX(((*list)->listSize * \ - ((*list)->percentIncrease + 100)) / 100, \ - (*list)->minNumItemsIncrease ) - -#define ITEMPTR(list,item) &(((char *)&(*list)->itemList)[(*(list))->itemSize * (item)]) - -#define LIST_SIGNATURE CAT4CHARS('L', 'I', 'S', 'T'); - -#define calloc(size,num) malloc(size*num) - -/********************************************************************/ - -Handle NewHandle (unsigned int numBytes) -{ - void *memPtr; - HandleRecord *hanPtr; - - memPtr = calloc (numBytes, 1); - hanPtr = (HandleRecord *) calloc (sizeof (HandleRecord), 1); - if (hanPtr && (memPtr || numBytes == 0)) { - hanPtr->ptr = memPtr; - hanPtr->size = numBytes; - return (Handle) hanPtr; - } else { - free (memPtr); - free (hanPtr); - return NULL; - } -} -/********************************************************************/ - -void DisposeHandle (Handle handle) -{ - if (handle) { - free (*handle); - free ((void *) handle); - } -} -/********************************************************************/ - -unsigned int GetHandleSize (Handle handle) -{ - return ((HandleRecord *) handle)->size; -} -/********************************************************************/ - -int SetHandleSize (Handle handle, unsigned int newSize) -{ - HandleRecord *hanRecPtr = (HandleRecord *) handle; - void *newPtr, *oldPtr; - unsigned int oldSize; - - - oldPtr = hanRecPtr->ptr; - oldSize = hanRecPtr->size; - - if (oldSize == newSize) - return 1; - - if (oldPtr == NULL) { - newPtr = malloc (newSize); - } else { - newPtr = realloc (oldPtr, newSize); - } - if (newPtr || (newSize == 0)) { - hanRecPtr->ptr = newPtr; - hanRecPtr->size = newSize; - if (newSize > oldSize) - memset ((char *) newPtr + oldSize, 0, newSize - oldSize); - return 1; - } else - return 0; -} - -#ifdef CFG_ALL_LIST_FUNCTIONS - -/* Used to compare list elements by their raw data contents */ -static int ListMemBlockCmp (void *a, void *b, int size) -{ - return memcmp (a, b, size); -} - -/***************************************************************************/ - -/* - * Binary search numElements of size elementSize in array for a match - * to the. item. Return the index of the element that matches - * (0 - numElements - 1). If no match is found return the -i-1 where - * i is the index (0 - numElements) where the item should be placed. - * (*theCmp)(a,b) should return <0 if a<b, 0 if a==b, >0 if a>b. - * - * This function is like the C-Library function bsearch() except that - * this function returns the index where the item should be placed if - * it is not found. - */ -int BinSearch ( void *array, int numElements, int elementSize, - void *itemPtr, CompareFunction compareFunction) -{ - int low, high, mid, cmp; - void *arrayItemPtr; - - for (low = 0, high = numElements - 1, mid = 0, cmp = -1; low <= high;) { - mid = (low + high) >> 1; - - arrayItemPtr = (void *) (((char *) array) + (mid * elementSize)); - cmp = compareFunction - ? compareFunction (itemPtr, arrayItemPtr) - : ListMemBlockCmp (itemPtr, arrayItemPtr, elementSize); - if (cmp == 0) { - return mid; - } else if (cmp < 0) { - high = mid - 1; - } else { - low = mid + 1; - } - } - if (cmp > 0) - mid++; - - return -mid - 1; -} - -#endif /* CFG_ALL_LIST_FUNCTIONS */ - -/*******************************************************************************/ - -/* - * If numNewItems == 0 then expand the list by the number of items - * indicated by its allocation policy. - * If numNewItems > 0 then expand the list by exactly the number of - * items indicated. - * If numNewItems < 0 then expand the list by the absolute value of - * numNewItems plus the number of items indicated by its allocation - * policy. - * Returns 1 for success, 0 if out of memory -*/ -static int ExpandListSpace (list_t list, int numNewItems) -{ - if (numNewItems == 0) { - numNewItems = NUMITEMSPERALLOC (list); - } else if (numNewItems < 0) { - numNewItems = (-numNewItems) + NUMITEMSPERALLOC (list); - } - - if (SetHandleSize ((Handle) list, - sizeof (ListStruct) + - ((*list)->listSize + - numNewItems) * (*list)->itemSize)) { - (*list)->listSize += numNewItems; - return 1; - } else { - return 0; - } -} - -/*******************************/ - -#ifdef CFG_ALL_LIST_FUNCTIONS - -/* - * This function reallocate the list, minus any currently unused - * portion of its allotted memory. - */ -void ListCompact (list_t list) -{ - - if (!SetHandleSize ((Handle) list, - sizeof (ListStruct) + - (*list)->numItems * (*list)->itemSize)) { - return; - } - - (*list)->listSize = (*list)->numItems; -} - -#endif /* CFG_ALL_LIST_FUNCTIONS */ - -/*******************************/ - -list_t ListCreate (int elementSize) -{ - list_t list; - - list = (list_t) (NewHandle (sizeof (ListStruct))); /* create empty list */ - if (list) { - (*list)->signature = LIST_SIGNATURE; - (*list)->numItems = 0; - (*list)->listSize = 0; - (*list)->itemSize = elementSize; - (*list)->percentIncrease = kDefaultAllocationPercentIncrease; - (*list)->minNumItemsIncrease = - kDefaultAllocationminNumItemsIncrease; - } - - return list; -} - -/*******************************/ - -void ListSetAllocationPolicy (list_t list, int minItemsPerAlloc, - int percentIncreasePerAlloc) -{ - (*list)->percentIncrease = percentIncreasePerAlloc; - (*list)->minNumItemsIncrease = minItemsPerAlloc; -} - -/*******************************/ - -void ListDispose (list_t list) -{ - DisposeHandle ((Handle) list); -} -/*******************************/ - -#ifdef CFG_ALL_LIST_FUNCTIONS - -void ListDisposePtrList (list_t list) -{ - int index; - int numItems; - - if (list) { - numItems = ListNumItems (list); - - for (index = 1; index <= numItems; index++) - free (*(void **) ListGetPtrToItem (list, index)); - - ListDispose (list); - } -} - -/*******************************/ - -/* - * keeps memory, resets the number of items to 0 - */ -void ListClear (list_t list) -{ - if (!list) - return; - (*list)->numItems = 0; -} - -/*******************************/ - -/* - * copy is only as large as necessary - */ -list_t ListCopy (list_t originalList) -{ - list_t tempList = NULL; - int numItems; - - if (!originalList) - return NULL; - - tempList = ListCreate ((*originalList)->itemSize); - if (tempList) { - numItems = ListNumItems (originalList); - - if (!SetHandleSize ((Handle) tempList, - sizeof (ListStruct) + - numItems * (*tempList)->itemSize)) { - ListDispose (tempList); - return NULL; - } - - (*tempList)->numItems = (*originalList)->numItems; - (*tempList)->listSize = (*originalList)->numItems; - (*tempList)->itemSize = (*originalList)->itemSize; - (*tempList)->percentIncrease = (*originalList)->percentIncrease; - (*tempList)->minNumItemsIncrease = - (*originalList)->minNumItemsIncrease; - - memcpy (ITEMPTR (tempList, 0), ITEMPTR (originalList, 0), - numItems * (*tempList)->itemSize); - } - - return tempList; -} - -/********************************/ - -/* - * list1 = list1 + list2 - */ -int ListAppend (list_t list1, list_t list2) -{ - int numItemsL1, numItemsL2; - - if (!list2) - return 1; - - if (!list1) - return 0; - if ((*list1)->itemSize != (*list2)->itemSize) - return 0; - - numItemsL1 = ListNumItems (list1); - numItemsL2 = ListNumItems (list2); - - if (numItemsL2 == 0) - return 1; - - if (!SetHandleSize ((Handle) list1, - sizeof (ListStruct) + (numItemsL1 + numItemsL2) * - (*list1)->itemSize)) { - return 0; - } - - (*list1)->numItems = numItemsL1 + numItemsL2; - (*list1)->listSize = numItemsL1 + numItemsL2; - - memmove (ITEMPTR (list1, numItemsL1), - ITEMPTR (list2, 0), - numItemsL2 * (*list2)->itemSize); - - return 1; -} - -#endif /* CFG_ALL_LIST_FUNCTIONS */ - -/*******************************/ - -/* - * returns 1 if the item is inserted, returns 0 if out of memory or - * bad arguments were passed. - */ -int ListInsertItem (list_t list, void *ptrToItem, int itemPosition) -{ - return ListInsertItems (list, ptrToItem, itemPosition, 1); -} - -/*******************************/ - -int ListInsertItems (list_t list, void *ptrToItems, int firstItemPosition, - int numItemsToInsert) -{ - int numItems = (*list)->numItems; - - if (firstItemPosition == numItems + 1) - firstItemPosition = LIST_END; - else if (firstItemPosition > numItems) - return 0; - - if ((*list)->numItems >= (*list)->listSize) { - if (!ExpandListSpace (list, -numItemsToInsert)) - return 0; - } - - if (firstItemPosition == LIST_START) { - if (numItems == 0) { - /* special case for empty list */ - firstItemPosition = LIST_END; - } else { - firstItemPosition = 1; - } - } - - if (firstItemPosition == LIST_END) { /* add at the end of the list */ - if (ptrToItems) - memcpy (ITEMPTR (list, numItems), ptrToItems, - (*list)->itemSize * numItemsToInsert); - else - memset (ITEMPTR (list, numItems), 0, - (*list)->itemSize * numItemsToInsert); - - (*list)->numItems += numItemsToInsert; - } else { /* move part of list up to make room for new item */ - memmove (ITEMPTR (list, firstItemPosition - 1 + numItemsToInsert), - ITEMPTR (list, firstItemPosition - 1), - (numItems + 1 - firstItemPosition) * (*list)->itemSize); - - if (ptrToItems) - memmove (ITEMPTR (list, firstItemPosition - 1), ptrToItems, - (*list)->itemSize * numItemsToInsert); - else - memset (ITEMPTR (list, firstItemPosition - 1), 0, - (*list)->itemSize * numItemsToInsert); - - (*list)->numItems += numItemsToInsert; - } - - return 1; -} - -#ifdef CFG_ALL_LIST_FUNCTIONS - -/*******************************/ - -int ListEqual (list_t list1, list_t list2) -{ - if (list1 == list2) - return 1; - - if (list1 == NULL || list2 == NULL) - return 0; - - if ((*list1)->itemSize == (*list1)->itemSize) { - if ((*list1)->numItems == (*list2)->numItems) { - return (memcmp (ITEMPTR (list1, 0), ITEMPTR (list2, 0), - (*list1)->itemSize * (*list1)->numItems) == 0); - } - } - - return 0; -} - -/*******************************/ - -/* - * The item pointed to by ptrToItem is copied over the current item - * at itemPosition - */ -void ListReplaceItem (list_t list, void *ptrToItem, int itemPosition) -{ - ListReplaceItems (list, ptrToItem, itemPosition, 1); -} - -/*******************************/ - -/* - * The item pointed to by ptrToItems is copied over the current item - * at itemPosition - */ -void ListReplaceItems ( list_t list, void *ptrToItems, - int firstItemPosition, int numItemsToReplace) -{ - - if (firstItemPosition == LIST_END) - firstItemPosition = (*list)->numItems; - else if (firstItemPosition == LIST_START) - firstItemPosition = 1; - - memmove (ITEMPTR (list, firstItemPosition - 1), ptrToItems, - (*list)->itemSize * numItemsToReplace); -} - -/*******************************/ - -void ListGetItem (list_t list, void *itemDestination, int itemPosition) -{ - ListGetItems (list, itemDestination, itemPosition, 1); -} - -#endif /* CFG_ALL_LIST_FUNCTIONS */ - -/*******************************/ - -#if defined(CFG_ALL_LIST_FUNCTIONS) || defined(CFG_DEVICE_DEREGISTER) - -void ListRemoveItem (list_t list, void *itemDestination, int itemPosition) -{ - ListRemoveItems (list, itemDestination, itemPosition, 1); -} - -/*******************************/ - -void ListRemoveItems (list_t list, void *itemsDestination, - int firstItemPosition, int numItemsToRemove) -{ - int firstItemAfterChunk, numToMove; - - if (firstItemPosition == LIST_START) - firstItemPosition = 1; - else if (firstItemPosition == LIST_END) - firstItemPosition = (*list)->numItems; - - if (itemsDestination != NULL) - memcpy (itemsDestination, ITEMPTR (list, firstItemPosition - 1), - (*list)->itemSize * numItemsToRemove); - - firstItemAfterChunk = firstItemPosition + numItemsToRemove; - numToMove = (*list)->numItems - (firstItemAfterChunk - 1); - - if (numToMove > 0) { - /* - * move part of list down to cover hole left by removed item - */ - memmove (ITEMPTR (list, firstItemPosition - 1), - ITEMPTR (list, firstItemAfterChunk - 1), - (*list)->itemSize * numToMove); - } - - (*list)->numItems -= numItemsToRemove; -} -#endif /* CFG_ALL_LIST_FUNCTIONS || CFG_DEVICE_DEREGISTER */ - -/*******************************/ - -void ListGetItems (list_t list, void *itemsDestination, - int firstItemPosition, int numItemsToGet) -{ - - if (firstItemPosition == LIST_START) - firstItemPosition = 1; - else if (firstItemPosition == LIST_END) - firstItemPosition = (*list)->numItems; - - memcpy (itemsDestination, - ITEMPTR (list, firstItemPosition - 1), - (*list)->itemSize * numItemsToGet); -} - -/*******************************/ - -/* - * Returns a pointer to the item at itemPosition. returns null if an - * errors occurred. - */ -void *ListGetPtrToItem (list_t list, int itemPosition) -{ - if (itemPosition == LIST_START) - itemPosition = 1; - else if (itemPosition == LIST_END) - itemPosition = (*list)->numItems; - - return ITEMPTR (list, itemPosition - 1); -} - -/*******************************/ - -/* - * returns a pointer the lists data (abstraction violation for - * optimization) - */ -void *ListGetDataPtr (list_t list) -{ - return &((*list)->itemList[0]); -} - -/********************************/ - -#ifdef CFG_ALL_LIST_FUNCTIONS - -int ListApplyToEach (list_t list, int ascending, - ListApplicationFunc funcToApply, - void *callbackData) -{ - int result = 0, index; - - if (!list || !funcToApply) - goto Error; - - if (ascending) { - for (index = 1; index <= ListNumItems (list); index++) { - result = funcToApply (index, - ListGetPtrToItem (list, index), - callbackData); - if (result < 0) - goto Error; - } - } else { - for (index = ListNumItems (list); - index > 0 && index <= ListNumItems (list); - index--) { - result = funcToApply (index, - ListGetPtrToItem (list, index), - callbackData); - if (result < 0) - goto Error; - } - } - -Error: - return result; -} - -#endif /* CFG_ALL_LIST_FUNCTIONS */ - -/********************************/ - -int ListGetItemSize (list_t list) -{ - return (*list)->itemSize; -} - -/********************************/ - -int ListNumItems (list_t list) -{ - return (*list)->numItems; -} - -/*******************************/ - -#ifdef CFG_ALL_LIST_FUNCTIONS - -void ListRemoveDuplicates (list_t list, CompareFunction compareFunction) -{ - int numItems, index, startIndexForFind, duplicatesIndex; - - numItems = ListNumItems (list); - - for (index = 1; index < numItems; index++) { - startIndexForFind = index + 1; - while (startIndexForFind <= numItems) { - duplicatesIndex = - ListFindItem (list, - ListGetPtrToItem (list, index), - startIndexForFind, - compareFunction); - if (duplicatesIndex > 0) { - ListRemoveItem (list, NULL, duplicatesIndex); - numItems--; - startIndexForFind = duplicatesIndex; - } else { - break; - } - } - } -} - -/*******************************/ - - -/*******************************/ - -int ListFindItem (list_t list, void *ptrToItem, int startingPosition, - CompareFunction compareFunction) -{ - int numItems, size, index, cmp; - void *listItemPtr; - - if ((numItems = (*list)->numItems) == 0) - return 0; - - size = (*list)->itemSize; - - if (startingPosition == LIST_START) - startingPosition = 1; - else if (startingPosition == LIST_END) - startingPosition = numItems; - - for (index = startingPosition; index <= numItems; index++) { - listItemPtr = ITEMPTR (list, index - 1); - cmp = compareFunction - ? compareFunction (ptrToItem, listItemPtr) - : ListMemBlockCmp (ptrToItem, listItemPtr, size); - if (cmp == 0) - return index; - } - - return 0; -} - -/*******************************/ - -int ShortCompare (void *a, void *b) -{ - if (*(short *) a < *(short *) b) - return -1; - if (*(short *) a > *(short *) b) - return 1; - return 0; -} - -/*******************************/ - -int IntCompare (void *a, void *b) -{ - if (*(int *) a < *(int *) b) - return -1; - if (*(int *) a > *(int *) b) - return 1; - return 0; -} - -/*******************************/ - -int CStringCompare (void *a, void *b) -{ - return strcmp (*(char **) a, *(char **) b); -} - -/*******************************/ - - -int ListBinSearch (list_t list, void *ptrToItem, - CompareFunction compareFunction) -{ - int index; - - index = BinSearch (ITEMPTR (list, 0), - (int) (*list)->numItems, - (int) (*list)->itemSize, ptrToItem, - compareFunction); - - if (index >= 0) - index++; /* lists start from 1 */ - else - index = 0; /* item not found */ - - return index; -} - -/**************************************************************************/ - -/* - * Reserves memory for numItems in the list. If it succeeds then - * numItems items can be inserted without possibility of an out of - * memory error (useful to simplify error recovery in complex - * functions). Returns 1 if success, 0 if out of memory. - */ -int ListPreAllocate (list_t list, int numItems) -{ - if ((*list)->listSize - (*list)->numItems < numItems) { - return ExpandListSpace (list, - numItems - ((*list)->listSize - - (*list)->numItems)); - } else { - return 1; /* enough items are already pre-allocated */ - } -} - -#endif /* CFG_ALL_LIST_FUNCTIONS */ diff --git a/common/miiphybb.c b/common/miiphybb.c deleted file mode 100644 index 6446012..0000000 --- a/common/miiphybb.c +++ /dev/null @@ -1,235 +0,0 @@ -/* - * (C) Copyright 2001 - * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com. - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -/* - * This provides a bit-banged interface to the ethernet MII management - * channel. - */ - -#include <common.h> -#include <ioports.h> -#include <ppc_asm.tmpl> - -/***************************************************************************** - * - * Utility to send the preamble, address, and register (common to read - * and write). - */ -static void miiphy_pre (char read, unsigned char addr, unsigned char reg) -{ - int j; /* counter */ -#if !(defined(CONFIG_EP8248) || defined(CONFIG_EP82XXM)) - volatile ioport_t *iop = ioport_addr ((immap_t *) CFG_IMMR, MDIO_PORT); -#endif - - /* - * Send a 32 bit preamble ('1's) with an extra '1' bit for good measure. - * The IEEE spec says this is a PHY optional requirement. The AMD - * 79C874 requires one after power up and one after a MII communications - * error. This means that we are doing more preambles than we need, - * but it is safer and will be much more robust. - */ - - MDIO_ACTIVE; - MDIO (1); - for (j = 0; j < 32; j++) { - MDC (0); - MIIDELAY; - MDC (1); - MIIDELAY; - } - - /* send the start bit (01) and the read opcode (10) or write (10) */ - MDC (0); - MDIO (0); - MIIDELAY; - MDC (1); - MIIDELAY; - MDC (0); - MDIO (1); - MIIDELAY; - MDC (1); - MIIDELAY; - MDC (0); - MDIO (read); - MIIDELAY; - MDC (1); - MIIDELAY; - MDC (0); - MDIO (!read); - MIIDELAY; - MDC (1); - MIIDELAY; - - /* send the PHY address */ - for (j = 0; j < 5; j++) { - MDC (0); - if ((addr & 0x10) == 0) { - MDIO (0); - } else { - MDIO (1); - } - MIIDELAY; - MDC (1); - MIIDELAY; - addr <<= 1; - } - - /* send the register address */ - for (j = 0; j < 5; j++) { - MDC (0); - if ((reg & 0x10) == 0) { - MDIO (0); - } else { - MDIO (1); - } - MIIDELAY; - MDC (1); - MIIDELAY; - reg <<= 1; - } -} - - -/***************************************************************************** - * - * Read a MII PHY register. - * - * Returns: - * 0 on success - */ -int bb_miiphy_read (char *devname, unsigned char addr, - unsigned char reg, unsigned short *value) -{ - short rdreg; /* register working value */ - int j; /* counter */ -#if !(defined(CONFIG_EP8248) || defined(CONFIG_EP82XXM)) - volatile ioport_t *iop = ioport_addr ((immap_t *) CFG_IMMR, MDIO_PORT); -#endif - - miiphy_pre (1, addr, reg); - - /* tri-state our MDIO I/O pin so we can read */ - MDC (0); - MDIO_TRISTATE; - MIIDELAY; - MDC (1); - MIIDELAY; - - /* check the turnaround bit: the PHY should be driving it to zero */ - if (MDIO_READ != 0) { - /* puts ("PHY didn't drive TA low\n"); */ - for (j = 0; j < 32; j++) { - MDC (0); - MIIDELAY; - MDC (1); - MIIDELAY; - } - return (-1); - } - - MDC (0); - MIIDELAY; - - /* read 16 bits of register data, MSB first */ - rdreg = 0; - for (j = 0; j < 16; j++) { - MDC (1); - MIIDELAY; - rdreg <<= 1; - rdreg |= MDIO_READ; - MDC (0); - MIIDELAY; - } - - MDC (1); - MIIDELAY; - MDC (0); - MIIDELAY; - MDC (1); - MIIDELAY; - - *value = rdreg; - -#ifdef DEBUG - printf ("miiphy_read(0x%x) @ 0x%x = 0x%04x\n", reg, addr, *value); -#endif - - return 0; -} - - -/***************************************************************************** - * - * Write a MII PHY register. - * - * Returns: - * 0 on success - */ -int bb_miiphy_write (char *devname, unsigned char addr, - unsigned char reg, unsigned short value) -{ - int j; /* counter */ -#if !(defined(CONFIG_EP8248) || defined(CONFIG_EP82XXM)) - volatile ioport_t *iop = ioport_addr ((immap_t *) CFG_IMMR, MDIO_PORT); -#endif - - miiphy_pre (0, addr, reg); - - /* send the turnaround (10) */ - MDC (0); - MDIO (1); - MIIDELAY; - MDC (1); - MIIDELAY; - MDC (0); - MDIO (0); - MIIDELAY; - MDC (1); - MIIDELAY; - - /* write 16 bits of register data, MSB first */ - for (j = 0; j < 16; j++) { - MDC (0); - if ((value & 0x00008000) == 0) { - MDIO (0); - } else { - MDIO (1); - } - MIIDELAY; - MDC (1); - MIIDELAY; - value <<= 1; - } - - /* - * Tri-state the MDIO line. - */ - MDIO_TRISTATE; - MDC (0); - MIIDELAY; - MDC (1); - MIIDELAY; - - return 0; -} diff --git a/common/miiphyutil.c b/common/miiphyutil.c index eac8275..5ef4a33 100644 --- a/common/miiphyutil.c +++ b/common/miiphyutil.c @@ -29,7 +29,6 @@ #include <common.h> #include <miiphy.h> -#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) #include <asm/types.h> #include <linux/list.h> #include <malloc.h> @@ -487,4 +486,3 @@ int miiphy_link (char *devname, unsigned char addr) } } #endif -#endif /* CONFIG_MII */ diff --git a/common/soft_i2c.c b/common/soft_i2c.c deleted file mode 100644 index 23db2ee..0000000 --- a/common/soft_i2c.c +++ /dev/null @@ -1,423 +0,0 @@ -/* - * (C) Copyright 2001, 2002 - * Wolfgang Denk, DENX Software Engineering, wd@denx.de. - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - * - * This has been changed substantially by Gerald Van Baren, Custom IDEAS, - * vanbaren@cideas.com. It was heavily influenced by LiMon, written by - * Neil Russell. - */ - -#include <common.h> -#ifdef CONFIG_MPC8260 /* only valid for MPC8260 */ -#include <ioports.h> -#endif -#ifdef CONFIG_AT91RM9200 /* need this for the at91rm9200 */ -#include <asm/io.h> -#include <asm/arch/hardware.h> -#endif -#ifdef CONFIG_IXP425 /* only valid for IXP425 */ -#include <asm/arch/ixp425.h> -#endif -#ifdef CONFIG_LPC2292 -#include <asm/arch/hardware.h> -#endif -#include <i2c.h> - -/* #define DEBUG_I2C */ - -#ifdef DEBUG_I2C -DECLARE_GLOBAL_DATA_PTR; -#endif - - -/*----------------------------------------------------------------------- - * Definitions - */ - -#define RETRIES 0 - - -#define I2C_ACK 0 /* PD_SDA level to ack a byte */ -#define I2C_NOACK 1 /* PD_SDA level to noack a byte */ - - -#ifdef DEBUG_I2C -#define PRINTD(fmt,args...) do { \ - if (gd->have_console) \ - printf (fmt ,##args); \ - } while (0) -#else -#define PRINTD(fmt,args...) -#endif - -/*----------------------------------------------------------------------- - * Local functions - */ -static void send_reset (void); -static void send_start (void); -static void send_stop (void); -static void send_ack (int); -static int write_byte (uchar byte); -static uchar read_byte (int); - - -/*----------------------------------------------------------------------- - * Send a reset sequence consisting of 9 clocks with the data signal high - * to clock any confused device back into an idle state. Also send a - * <stop> at the end of the sequence for belts & suspenders. - */ -static void send_reset(void) -{ -#ifdef CONFIG_MPC8260 - volatile ioport_t *iop = ioport_addr((immap_t *)CFG_IMMR, I2C_PORT); -#endif -#ifdef CONFIG_8xx - volatile immap_t *immr = (immap_t *)CFG_IMMR; -#endif - int j; - - I2C_SCL(1); - I2C_SDA(1); -#ifdef I2C_INIT - I2C_INIT; -#endif - I2C_TRISTATE; - for(j = 0; j < 9; j++) { - I2C_SCL(0); - I2C_DELAY; - I2C_DELAY; - I2C_SCL(1); - I2C_DELAY; - I2C_DELAY; - } - send_stop(); - I2C_TRISTATE; -} - -/*----------------------------------------------------------------------- - * START: High -> Low on SDA while SCL is High - */ -static void send_start(void) -{ -#ifdef CONFIG_MPC8260 - volatile ioport_t *iop = ioport_addr((immap_t *)CFG_IMMR, I2C_PORT); -#endif -#ifdef CONFIG_8xx - volatile immap_t *immr = (immap_t *)CFG_IMMR; -#endif - - I2C_DELAY; - I2C_SDA(1); - I2C_ACTIVE; - I2C_DELAY; - I2C_SCL(1); - I2C_DELAY; - I2C_SDA(0); - I2C_DELAY; -} - -/*----------------------------------------------------------------------- - * STOP: Low -> High on SDA while SCL is High - */ -static void send_stop(void) -{ -#ifdef CONFIG_MPC8260 - volatile ioport_t *iop = ioport_addr((immap_t *)CFG_IMMR, I2C_PORT); -#endif -#ifdef CONFIG_8xx - volatile immap_t *immr = (immap_t *)CFG_IMMR; -#endif - - I2C_SCL(0); - I2C_DELAY; - I2C_SDA(0); - I2C_ACTIVE; - I2C_DELAY; - I2C_SCL(1); - I2C_DELAY; - I2C_SDA(1); - I2C_DELAY; - I2C_TRISTATE; -} - - -/*----------------------------------------------------------------------- - * ack should be I2C_ACK or I2C_NOACK - */ -static void send_ack(int ack) -{ -#ifdef CONFIG_MPC8260 - volatile ioport_t *iop = ioport_addr((immap_t *)CFG_IMMR, I2C_PORT); -#endif -#ifdef CONFIG_8xx - volatile immap_t *immr = (immap_t *)CFG_IMMR; -#endif - - I2C_SCL(0); - I2C_DELAY; - I2C_ACTIVE; - I2C_SDA(ack); - I2C_DELAY; - I2C_SCL(1); - I2C_DELAY; - I2C_DELAY; - I2C_SCL(0); - I2C_DELAY; -} - - -/*----------------------------------------------------------------------- - * Send 8 bits and look for an acknowledgement. - */ -static int write_byte(uchar data) -{ -#ifdef CONFIG_MPC8260 - volatile ioport_t *iop = ioport_addr((immap_t *)CFG_IMMR, I2C_PORT); -#endif -#ifdef CONFIG_8xx - volatile immap_t *immr = (immap_t *)CFG_IMMR; -#endif - int j; - int nack; - - I2C_ACTIVE; - for(j = 0; j < 8; j++) { - I2C_SCL(0); - I2C_DELAY; - I2C_SDA(data & 0x80); - I2C_DELAY; - I2C_SCL(1); - I2C_DELAY; - I2C_DELAY; - - data <<= 1; - } - - /* - * Look for an <ACK>(negative logic) and return it. - */ - I2C_SCL(0); - I2C_DELAY; - I2C_SDA(1); - I2C_TRISTATE; - I2C_DELAY; - I2C_SCL(1); - I2C_DELAY; - I2C_DELAY; - nack = I2C_READ; - I2C_SCL(0); - I2C_DELAY; - I2C_ACTIVE; - - return(nack); /* not a nack is an ack */ -} - - -/*----------------------------------------------------------------------- - * if ack == I2C_ACK, ACK the byte so can continue reading, else - * send I2C_NOACK to end the read. - */ -static uchar read_byte(int ack) -{ -#ifdef CONFIG_MPC8260 - volatile ioport_t *iop = ioport_addr((immap_t *)CFG_IMMR, I2C_PORT); -#endif -#ifdef CONFIG_8xx - volatile immap_t *immr = (immap_t *)CFG_IMMR; -#endif - int data; - int j; - - /* - * Read 8 bits, MSB first. - */ - I2C_TRISTATE; - I2C_SDA(1); - data = 0; - for(j = 0; j < 8; j++) { - I2C_SCL(0); - I2C_DELAY; - I2C_SCL(1); - I2C_DELAY; - data <<= 1; - data |= I2C_READ; - I2C_DELAY; - } - send_ack(ack); - - return(data); -} - -/*=====================================================================*/ -/* Public Functions */ -/*=====================================================================*/ - -/*----------------------------------------------------------------------- - * Initialization - */ -void i2c_init (int speed, int slaveaddr) -{ - /* - * WARNING: Do NOT save speed in a static variable: if the - * I2C routines are called before RAM is initialized (to read - * the DIMM SPD, for instance), RAM won't be usable and your - * system will crash. - */ - send_reset (); -} - -/*----------------------------------------------------------------------- - * Probe to see if a chip is present. Also good for checking for the - * completion of EEPROM writes since the chip stops responding until - * the write completes (typically 10mSec). - */ -int i2c_probe(uchar addr) -{ - int rc; - - /* - * perform 1 byte write transaction with just address byte - * (fake write) - */ - send_start(); - rc = write_byte ((addr << 1) | 0); - send_stop(); - - return (rc ? 1 : 0); -} - -/*----------------------------------------------------------------------- - * Read bytes - */ -int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len) -{ - int shift; - PRINTD("i2c_read: chip %02X addr %02X alen %d buffer %p len %d\n", - chip, addr, alen, buffer, len); - -#ifdef CFG_I2C_EEPROM_ADDR_OVERFLOW - /* - * EEPROM chips that implement "address overflow" are ones - * like Catalyst 24WC04/08/16 which has 9/10/11 bits of - * address and the extra bits end up in the "chip address" - * bit slots. This makes a 24WC08 (1Kbyte) chip look like - * four 256 byte chips. - * - * Note that we consider the length of the address field to - * still be one byte because the extra address bits are - * hidden in the chip address. - */ - chip |= ((addr >> (alen * 8)) & CFG_I2C_EEPROM_ADDR_OVERFLOW); - - PRINTD("i2c_read: fix addr_overflow: chip %02X addr %02X\n", - chip, addr); -#endif - - /* - * Do the addressing portion of a write cycle to set the - * chip's address pointer. If the address length is zero, - * don't do the normal write cycle to set the address pointer, - * there is no address pointer in this chip. - */ - send_start(); - if(alen > 0) { - if(write_byte(chip << 1)) { /* write cycle */ - send_stop(); - PRINTD("i2c_read, no chip responded %02X\n", chip); - return(1); - } - shift = (alen-1) * 8; - while(alen-- > 0) { - if(write_byte(addr >> shift)) { - PRINTD("i2c_read, address not <ACK>ed\n"); - return(1); - } - shift -= 8; - } - send_stop(); /* reportedly some chips need a full stop */ - send_start(); - } - /* - * Send the chip address again, this time for a read cycle. - * Then read the data. On the last byte, we do a NACK instead - * of an ACK(len == 0) to terminate the read. - */ - write_byte((chip << 1) | 1); /* read cycle */ - while(len-- > 0) { - *buffer++ = read_byte(len == 0); - } - send_stop(); - return(0); -} - -/*----------------------------------------------------------------------- - * Write bytes - */ -int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len) -{ - int shift, failures = 0; - - PRINTD("i2c_write: chip %02X addr %02X alen %d buffer %p len %d\n", - chip, addr, alen, buffer, len); - - send_start(); - if(write_byte(chip << 1)) { /* write cycle */ - send_stop(); - PRINTD("i2c_write, no chip responded %02X\n", chip); - return(1); - } - shift = (alen-1) * 8; - while(alen-- > 0) { - if(write_byte(addr >> shift)) { - PRINTD("i2c_write, address not <ACK>ed\n"); - return(1); - } - shift -= 8; - } - - while(len-- > 0) { - if(write_byte(*buffer++)) { - failures++; - } - } - send_stop(); - return(failures); -} - -/*----------------------------------------------------------------------- - * Read a register - */ -uchar i2c_reg_read(uchar i2c_addr, uchar reg) -{ - uchar buf; - - i2c_read(i2c_addr, reg, 1, &buf, 1); - - return(buf); -} - -/*----------------------------------------------------------------------- - * Write a register - */ -void i2c_reg_write(uchar i2c_addr, uchar reg, uchar val) -{ - i2c_write(i2c_addr, reg, 1, &val, 1); -} diff --git a/common/soft_spi.c b/common/soft_spi.c deleted file mode 100644 index 25b589a..0000000 --- a/common/soft_spi.c +++ /dev/null @@ -1,193 +0,0 @@ -/* - * (C) Copyright 2002 - * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com. - * - * Influenced by code from: - * Wolfgang Denk, DENX Software Engineering, wd@denx.de. - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -#include <common.h> -#include <spi.h> - -#include <malloc.h> - -/*----------------------------------------------------------------------- - * Definitions - */ - -#ifdef DEBUG_SPI -#define PRINTD(fmt,args...) printf (fmt ,##args) -#else -#define PRINTD(fmt,args...) -#endif - -struct soft_spi_slave { - struct spi_slave slave; - unsigned int mode; -}; - -static inline struct soft_spi_slave *to_soft_spi(struct spi_slave *slave) -{ - return container_of(slave, struct soft_spi_slave, slave); -} - -/*=====================================================================*/ -/* Public Functions */ -/*=====================================================================*/ - -/*----------------------------------------------------------------------- - * Initialization - */ -void spi_init (void) -{ -#ifdef SPI_INIT - volatile immap_t *immr = (immap_t *)CFG_IMMR; - - SPI_INIT; -#endif -} - -struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, - unsigned int max_hz, unsigned int mode) -{ - struct soft_spi_slave *ss; - - if (!spi_cs_is_valid(bus, cs)) - return NULL; - - ss = malloc(sizeof(struct soft_spi_slave)); - if (!ss) - return NULL; - - ss->slave.bus = bus; - ss->slave.cs = cs; - ss->mode = mode; - - /* TODO: Use max_hz to limit the SCK rate */ - - return &ss->slave; -} - -void spi_free_slave(struct spi_slave *slave) -{ - struct soft_spi_slave *ss = to_soft_spi(slave); - - free(ss); -} - -int spi_claim_bus(struct spi_slave *slave) -{ -#ifdef CFG_IMMR - volatile immap_t *immr = (immap_t *)CFG_IMMR; -#endif - struct soft_spi_slave *ss = to_soft_spi(slave); - - /* - * Make sure the SPI clock is in idle state as defined for - * this slave. - */ - if (ss->mode & SPI_CPOL) - SPI_SCL(1); - else - SPI_SCL(0); - - return 0; -} - -void spi_release_bus(struct spi_slave *slave) -{ - /* Nothing to do */ -} - -/*----------------------------------------------------------------------- - * SPI transfer - * - * This writes "bitlen" bits out the SPI MOSI port and simultaneously clocks - * "bitlen" bits in the SPI MISO port. That's just the way SPI works. - * - * The source of the outgoing bits is the "dout" parameter and the - * destination of the input bits is the "din" parameter. Note that "dout" - * and "din" can point to the same memory location, in which case the - * input data overwrites the output data (since both are buffered by - * temporary variables, this is OK). - */ -int spi_xfer(struct spi_slave *slave, unsigned int bitlen, - const void *dout, void *din, unsigned long flags) -{ -#ifdef CFG_IMMR - volatile immap_t *immr = (immap_t *)CFG_IMMR; -#endif - struct soft_spi_slave *ss = to_soft_spi(slave); - uchar tmpdin = 0; - uchar tmpdout = 0; - const u8 *txd = dout; - u8 *rxd = din; - int cpol = ss->mode & SPI_CPOL; - int cpha = ss->mode & SPI_CPHA; - unsigned int j; - - PRINTD("spi_xfer: slave %u:%u dout %08X din %08X bitlen %u\n", - slave->bus, slave->cs, *(uint *)txd, *(uint *)rxd, bitlen); - - if (flags & SPI_XFER_BEGIN) - spi_cs_activate(slave); - - for(j = 0; j < bitlen; j++) { - /* - * Check if it is time to work on a new byte. - */ - if((j % 8) == 0) { - tmpdout = *txd++; - if(j != 0) { - *rxd++ = tmpdin; - } - tmpdin = 0; - } - - if (!cpha) - SPI_SCL(!cpol); - SPI_SDA(tmpdout & 0x80); - SPI_DELAY; - if (cpha) - SPI_SCL(!cpol); - else - SPI_SCL(cpol); - tmpdin <<= 1; - tmpdin |= SPI_READ; - tmpdout <<= 1; - SPI_DELAY; - if (cpha) - SPI_SCL(cpol); - } - /* - * If the number of bits isn't a multiple of 8, shift the last - * bits over to left-justify them. Then store the last byte - * read in. - */ - if((bitlen % 8) != 0) - tmpdin <<= 8 - (bitlen % 8); - *rxd++ = tmpdin; - - if (flags & SPI_XFER_END) - spi_cs_deactivate(slave); - - return(0); -} diff --git a/common/usb_kbd.c b/common/usb_kbd.c index 04d9730..108bd60 100644 --- a/common/usb_kbd.c +++ b/common/usb_kbd.c @@ -152,7 +152,7 @@ static int usb_kbd_probe(struct usb_device *dev, unsigned int ifnum); /* search for keyboard and register it if found */ int drv_usb_kbd_init(void) { - int error,i,index; + int error,i; device_t usb_kbd_dev,*old_dev; struct usb_device *dev; char *stdinname = getenv ("stdin"); @@ -166,13 +166,11 @@ int drv_usb_kbd_init(void) if(usb_kbd_probe(dev,0)==1) { /* Ok, we found a keyboard */ /* check, if it is already registered */ USB_KBD_PRINTF("USB KBD found set up device.\n"); - for (index=1; index<=ListNumItems(devlist); index++) { - old_dev = ListGetPtrToItem(devlist, index); - if(strcmp(old_dev->name,DEVNAME)==0) { - /* ok, already registered, just return ok */ - USB_KBD_PRINTF("USB KBD is already registered.\n"); - return 1; - } + old_dev = device_get_by_name(DEVNAME); + if(old_dev) { + /* ok, already registered, just return ok */ + USB_KBD_PRINTF("USB KBD is already registered.\n"); + return 1; } /* register the keyboard */ USB_KBD_PRINTF("USB KBD register.\n"); |