*/
#include <common.h>
+#if defined(CONFIG_MGCOGE)
#include <mpc8260.h>
+#endif
#include <ioports.h>
#include <malloc.h>
#include <hush.h>
+#include <net.h>
+#include <asm/io.h>
#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
#include <libfdt.h>
#endif
+#include "../common/common.h"
#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
#include <i2c.h>
-#endif
extern int i2c_soft_read_pin (void);
unsigned long crc;
unsigned long crceeprom;
- crc = ivm_calc_crc (buf, CFG_IVM_EEPROM_PAGE_LEN - 2);
- crceeprom = (buf[CFG_IVM_EEPROM_PAGE_LEN - 1] + \
- buf[CFG_IVM_EEPROM_PAGE_LEN - 2] * 256);
+ crc = ivm_calc_crc (buf, CONFIG_SYS_IVM_EEPROM_PAGE_LEN - 2);
+ crceeprom = (buf[CONFIG_SYS_IVM_EEPROM_PAGE_LEN - 1] + \
+ buf[CONFIG_SYS_IVM_EEPROM_PAGE_LEN - 2] * 256);
if (crc != crceeprom) {
- printf ("Error CRC Block: %d EEprom: calculated: %lx EEprom: %lx\n",
- block, crc, crceeprom);
+ if (block == 0)
+ printf ("Error CRC Block: %d EEprom: calculated: \
+ %lx EEprom: %lx\n", block, crc, crceeprom);
return -1;
}
return 0;
static int ivm_analyze_block2 (unsigned char *buf, int len)
{
- unsigned char valbuf[CFG_IVM_EEPROM_PAGE_LEN];
+ unsigned char valbuf[CONFIG_SYS_IVM_EEPROM_PAGE_LEN];
unsigned long count;
/* IVM_MacAddress */
int ivm_analyze_eeprom (unsigned char *buf, int len)
{
unsigned short val;
- unsigned char valbuf[CFG_IVM_EEPROM_PAGE_LEN];
+ unsigned char valbuf[CONFIG_SYS_IVM_EEPROM_PAGE_LEN];
unsigned char *tmp;
if (ivm_check_crc (buf, 0) != 0)
return -1;
- ivm_get_value (buf, CFG_IVM_EEPROM_PAGE_LEN, "IVM_BoardId", 0, 1);
- val = ivm_get_value (buf, CFG_IVM_EEPROM_PAGE_LEN, "IVM_HWKey", 6, 1);
+ ivm_get_value (buf, CONFIG_SYS_IVM_EEPROM_PAGE_LEN, "IVM_BoardId", 0, 1);
+ val = ivm_get_value (buf, CONFIG_SYS_IVM_EEPROM_PAGE_LEN, "IVM_HWKey", 6, 1);
if (val != 0xffff) {
sprintf ((char *)valbuf, "%x", ((val /100) % 10));
ivm_set_value ("IVM_HWVariant", (char *)valbuf);
sprintf ((char *)valbuf, "%x", (val % 100));
ivm_set_value ("IVM_HWVersion", (char *)valbuf);
}
- ivm_get_value (buf, CFG_IVM_EEPROM_PAGE_LEN, "IVM_Functions", 12, 0);
+ ivm_get_value (buf, CONFIG_SYS_IVM_EEPROM_PAGE_LEN, "IVM_Functions", 12, 0);
GET_STRING("IVM_Symbol", IVM_POS_SYMBOL_ONLY, 8)
GET_STRING("IVM_DeviceName", IVM_POS_SHORT_TEXT, 64)
GET_STRING("IVM_CustomerID", IVM_POS_CUSTOMER_ID, 32)
GET_STRING("IVM_CustomerProductID", IVM_POS_CUSTOMER_PROD_ID, 32)
- if (ivm_check_crc (&buf[CFG_IVM_EEPROM_PAGE_LEN * 2], 2) != 0)
- return -2;
- ivm_analyze_block2 (&buf[CFG_IVM_EEPROM_PAGE_LEN * 2], CFG_IVM_EEPROM_PAGE_LEN);
+ if (ivm_check_crc (&buf[CONFIG_SYS_IVM_EEPROM_PAGE_LEN * 2], 2) != 0)
+ return 0;
+ ivm_analyze_block2 (&buf[CONFIG_SYS_IVM_EEPROM_PAGE_LEN * 2], CONFIG_SYS_IVM_EEPROM_PAGE_LEN);
return 0;
}
int ivm_read_eeprom (void)
{
+#if defined(CONFIG_I2C_MUX)
I2C_MUX_DEVICE *dev = NULL;
- uchar i2c_buffer[CFG_IVM_EEPROM_MAX_LEN];
+#endif
+ uchar i2c_buffer[CONFIG_SYS_IVM_EEPROM_MAX_LEN];
uchar *buf;
- unsigned dev_addr = CFG_IVM_EEPROM_ADR;
+ unsigned dev_addr = CONFIG_SYS_IVM_EEPROM_ADR;
+#if defined(CONFIG_I2C_MUX)
/* First init the Bus, select the Bus */
-#if defined(CFG_I2C_IVM_BUS)
- dev = i2c_mux_ident_muxstring ((uchar *)CFG_I2C_IVM_BUS);
+#if defined(CONFIG_SYS_I2C_IVM_BUS)
+ dev = i2c_mux_ident_muxstring ((uchar *)CONFIG_SYS_I2C_IVM_BUS);
#else
buf = (unsigned char *) getenv ("EEprom_ivm");
if (buf != NULL)
return -1;
}
i2c_set_bus_num (dev->busid);
+#endif
buf = (unsigned char *) getenv ("EEprom_ivm_addr");
if (buf != NULL)
dev_addr = simple_strtoul ((char *)buf, NULL, 16);
- if (eeprom_read (dev_addr, 0, i2c_buffer, CFG_IVM_EEPROM_MAX_LEN) != 0) {
+ if (i2c_read(dev_addr, 0, 1, i2c_buffer, CONFIG_SYS_IVM_EEPROM_MAX_LEN) != 0) {
printf ("Error reading EEprom\n");
return -2;
}
- return ivm_analyze_eeprom (i2c_buffer, CFG_IVM_EEPROM_MAX_LEN);
+ return ivm_analyze_eeprom (i2c_buffer, CONFIG_SYS_IVM_EEPROM_MAX_LEN);
}
-#if defined(CFG_I2C_INIT_BOARD)
+#if defined(CONFIG_SYS_I2C_INIT_BOARD)
#define DELAY_ABORT_SEQ 62
-#define DELAY_HALF_PERIOD (500 / (CFG_I2C_SPEED / 1000))
+#define DELAY_HALF_PERIOD (500 / (CONFIG_SYS_I2C_SPEED / 1000))
#if defined(CONFIG_MGCOGE)
#define SDA_MASK 0x00010000
#define SCL_MASK 0x00020000
static void set_pin (int state, unsigned long mask)
{
- volatile ioport_t *iop = ioport_addr ((immap_t *)CFG_IMMR, 3);
+ volatile ioport_t *iop = ioport_addr ((immap_t *)CONFIG_SYS_IMMR, 3);
if (state)
iop->pdat |= (mask);
static int get_pin (unsigned long mask)
{
- volatile ioport_t *iop = ioport_addr ((immap_t *)CFG_IMMR, 3);
+ volatile ioport_t *iop = ioport_addr ((immap_t *)CONFIG_SYS_IMMR, 3);
iop->pdir &= ~(mask);
return (0 != (iop->pdat & (mask)));
#if defined(CONFIG_HARD_I2C)
static void setports (int gpio)
{
- volatile ioport_t *iop = ioport_addr ((immap_t *)CFG_IMMR, 3);
+ volatile ioport_t *iop = ioport_addr ((immap_t *)CONFIG_SYS_IMMR, 3);
if (gpio) {
iop->ppar &= ~(SDA_MASK | SCL_MASK);
#endif
#endif
-#if defined(CONFIG_MGSUVD)
+#if defined(CONFIG_KM8XX)
static void set_sda (int state)
{
I2C_SDA(state);
static int get_sda (void)
{
- return i2c_soft_read_pin ();
+ return I2C_READ;
}
static int get_scl (void)
return ((val & SCL_BIT) == SCL_BIT);
}
-
#endif
+#if !defined(CONFIG_KMETER1)
static void writeStartSeq (void)
{
set_sda (1);
get_sda ();
return ret;
}
+#endif
/**
* i2c_init_board - reset i2c bus. When the board is powercycled during a
*/
void i2c_init_board(void)
{
-#if defined(CONFIG_HARD_I2C)
- volatile immap_t *immap = (immap_t *)CFG_IMMR ;
+#if defined(CONFIG_KMETER1)
+ struct fsl_i2c *dev;
+ dev = (struct fsl_i2c *) (CONFIG_SYS_IMMR + CONFIG_SYS_I2C_OFFSET);
+ uchar dummy;
+
+ out_8 (&dev->cr, (I2C_CR_MSTA));
+ out_8 (&dev->cr, (I2C_CR_MEN | I2C_CR_MSTA));
+ dummy = in_8(&dev->dr);
+ dummy = in_8(&dev->dr);
+ if (dummy != 0xff) {
+ dummy = in_8(&dev->dr);
+ }
+ out_8 (&dev->cr, (I2C_CR_MEN));
+ out_8 (&dev->cr, 0x00);
+ out_8 (&dev->cr, (I2C_CR_MEN));
+
+#else
+#if defined(CONFIG_HARD_I2C) && !defined(CONFIG_MACH_SUEN3)
+ volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR ;
volatile i2c8260_t *i2c = (i2c8260_t *)&immap->im_i2c;
/* disable I2C controller first, otherwhise it thinks we want to */
/* Set the PortPins back to use for I2C */
setports (0);
#endif
+#endif
+}
+#endif
+#endif
+
+#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
+int fdt_set_node_and_value (void *blob,
+ char *nodename,
+ char *regname,
+ void *var,
+ int size)
+{
+ int ret = 0;
+ int nodeoffset = 0;
+
+ nodeoffset = fdt_path_offset (blob, nodename);
+ if (nodeoffset >= 0) {
+ ret = fdt_setprop (blob, nodeoffset, regname, var,
+ size);
+ if (ret < 0)
+ printf("ft_blob_update(): cannot set %s/%s "
+ "property err:%s\n", nodename, regname,
+ fdt_strerror (ret));
+ } else {
+ printf("ft_blob_update(): cannot find %s node "
+ "err:%s\n", nodename, fdt_strerror (nodeoffset));
+ }
+ return ret;
+}
+int fdt_get_node_and_value (void *blob,
+ char *nodename,
+ char *propname,
+ void **var)
+{
+ int len;
+ int nodeoffset = 0;
+
+ nodeoffset = fdt_path_offset (blob, nodename);
+ if (nodeoffset >= 0) {
+ *var = (void *)fdt_getprop (blob, nodeoffset, propname, &len);
+ if (len == 0) {
+ /* no value */
+ printf ("%s no value\n", __FUNCTION__);
+ return -1;
+ } else if (len > 0) {
+ return len;
+ } else {
+ printf ("libfdt fdt_getprop(): %s\n",
+ fdt_strerror(len));
+ return -2;
+ }
+ } else {
+ printf("%s: cannot find %s node err:%s\n", __FUNCTION__,
+ nodename, fdt_strerror (nodeoffset));
+ return -3;
+ }
+}
+#endif
+
+#if !defined(CONFIG_MACH_SUEN3)
+int ethernet_present (void)
+{
+ return (in_8((u8 *)CONFIG_SYS_PIGGY_BASE + CONFIG_SYS_SLOT_ID_OFF) & 0x80);
}
#endif
+
+int board_eth_init (bd_t *bis)
+{
+#ifdef CONFIG_KEYMILE_HDLC_ENET
+ (void)keymile_hdlc_enet_initialize (bis);
+#endif
+ if (ethernet_present ()) {
+ return -1;
+ }
+ return 0;
+}