/* Board specific functions for those embedded 8xx boards that do
* not have boot monitor support for board information.
*
* 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.
*/
#include <linux/types.h>
#include <linux/config.h>
#include <linux/string.h>
#include <asm/reg.h>
#ifdef CONFIG_8xx
#include <asm/mpc8xx.h>
#endif
#ifdef CONFIG_8260
#include <asm/mpc8260.h>
#include <asm/immap_cpm2.h>
#endif
#ifdef CONFIG_40x
#include <asm/io.h>
#endif
extern unsigned long timebase_period_ns;
/* For those boards that don't provide one.
*/
#if !defined(CONFIG_MBX)
static bd_t bdinfo;
#endif
/* IIC functions.
* These are just the basic master read/write operations so we can
* examine serial EEPROM.
*/
extern void iic_read(uint devaddr, u_char *buf, uint offset, uint count);
/* Supply a default Ethernet address for those eval boards that don't
* ship with one. This is an address from the MBX board I have, so
* it is unlikely you will find it on your network.
*/
static ushort def_enet_addr[] = { 0x0800, 0x3e26, 0x1559 };
#if defined(CONFIG_MBX)
/* The MBX hands us a pretty much ready to go board descriptor. This
* is where the idea started in the first place.
*/
void
embed_config(bd_t **bdp)
{
u_char *mp;
u_char eebuf[128];
int i = 8;
bd_t *bd;
bd = *bdp;
/* Read the first 128 bytes of the EEPROM. There is more,
* but this is all we need.
*/
iic_read(0xa4, eebuf, 0, 128);
/* All we are looking for is the Ethernet MAC address. The
* first 8 bytes are 'MOTOROLA', so check for part of that.
* Next, the VPD describes a MAC 'packet' as being of type 08
* and size 06. So we look for that and the MAC must follow.
* If there are more than one, we still only care about the first.
* If it's there, assume we have a valid MAC address. If not,
* grab our default one.
*/
if ((*(uint *)eebuf) == 0x4d4f544f) {
while (i < 127 && !(eebuf[i] == 0x08 && eebuf[i + 1] == 0x06))
i += eebuf[i + 1] + 2; /* skip this packet */
if (i == 127) /* Couldn't find. */
mp = (u_char *)def_enet_addr;
else
mp = &eebuf[i + 2];
}
else
mp = (u_char *)def_enet_addr;
for (i=0; i<6; i++)
bd->bi_enetaddr[i] = *mp++;
/* The boot rom passes these to us in MHz. Linux now expects
* them to be in Hz.
*/
bd->bi_intfreq *= 1000000;
bd->bi_busfreq *= 1000000;
/* Stuff a baud rate here as well.
*/
bd->bi_baudrate = 9600;
}
#endif /* CONFIG_MBX */
#if defined(CONFIG_RPXLITE) || defined(CONFIG_RPXCLASSIC) || \
defined(CONFIG_RPX8260) || defined(CONFIG_EP405)
/* Helper functions for Embedded Planet boards.
*/
/* Because I didn't find anything that would do this.......
*/
u_char
aschex_to_byte(u_char *cp)
{
u_char byte, c;
c = *cp++;
if ((c >= 'A') && (c <= 'F')) {
c -= 'A';
c += 10;
} else if ((c >= 'a') && (c <= 'f')) {
c -= 'a';
c += 10;
} else
c -= '0';
byte = c * 16;
c = *cp;
if ((c >= 'A') && (c <= 'F')) {
c -= 'A';
c += 10;
} else if ((c >= 'a') && (c <= 'f')) {
c -= 'a';
c += 10;
} else
c -= '0';
byte += c;
return(byte);
}
static void
rpx_eth(bd_t *bd, u_char *cp)
{
int i;
for (i=0; i<6; i++) {
bd->bi_enetaddr[i] = aschex_to_byte(cp);
cp += 2;
}
}
#ifdef CONFIG_RPX8260
static uint
rpx_baseten(u_char *cp)
{
uint retval;
retval = 0;
while (*cp != '\n') {
retval *= 10;
retval += (*cp) - '0';
cp++;
}
return(retval);
}
#endif
#if defined(CONFIG_RPXLITE) || defined(CONFIG_RPXCLASSIC)
static void
rpx_brate(bd_t *bd, u_char *cp)
{
uint rate;
rate = 0;
while (*cp != '\n') {
rate *= 10;
rate += (*cp) - '0';
cp++;
}
bd->bi_baudrate = rate * 100;
}
static void
rpx_cpuspeed(bd_t *bd, u_char *cp)
{
uint num, den;
num = den = 0;
while (*cp != '\n') {
num *= 10;
num += (