FIX: [uboot] change findings from rs regarding shield
SVN commit 24938@trunk
This commit is contained in:
parent
1e663e39f5
commit
f702243ee9
|
|
@ -22,7 +22,7 @@
|
|||
#include <i2c.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#include "bdparser.h" /* tlv parser */
|
||||
#include "bdparser.h" /* tlv parser */
|
||||
|
||||
#define MAX_PARTITION_ENTRIES 4
|
||||
|
||||
|
|
@ -36,7 +36,7 @@ void bd_register_context_list(const BD_Context *list, size_t count) {
|
|||
|
||||
int bd_get_context(BD_Context *bdctx, uint32_t i2caddress, uint32_t offset)
|
||||
{
|
||||
bd_bool_t rc;
|
||||
bd_bool_t rc;
|
||||
uint8_t bdHeader[8];
|
||||
void* pBdData = NULL;
|
||||
/* Read header bytes from beginning of EEPROM */
|
||||
|
|
@ -242,12 +242,12 @@ int bd_get_devicetree(char* devicetreename, size_t len)
|
|||
|
||||
int bd_get_shield(int shieldnr)
|
||||
{
|
||||
bd_uint16_t shield = 0;
|
||||
bd_uint16_t shield = 0;
|
||||
|
||||
if (!_get_uint16(PD_Shield, shieldnr, &shield) ) {
|
||||
debug("%s() no shield populated\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
return shield;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@
|
|||
DECLARE_GLOBAL_DATA_PTR;
|
||||
|
||||
/* GPIO that controls power to DDR on EVM-SK */
|
||||
#define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio))
|
||||
#define GPIO_DDR_VTT_EN GPIO_TO_PIN(0, 7)
|
||||
#define ICE_GPIO_DDR_VTT_EN GPIO_TO_PIN(0, 18)
|
||||
#define GPIO_PR1_MII_CTRL GPIO_TO_PIN(3, 4)
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ static int _bd_init(void)
|
|||
}
|
||||
|
||||
bd_register_context_list(bdctx, ARRAY_SIZE(bdctx));
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -104,7 +104,7 @@ static int _bd_init(void)
|
|||
*/
|
||||
static inline int __maybe_unused read_eeprom(void)
|
||||
{
|
||||
return _bd_init();
|
||||
return _bd_init();
|
||||
}
|
||||
|
||||
struct serial_device *default_serial_console(void)
|
||||
|
|
@ -520,89 +520,96 @@ static void check_fct(void)
|
|||
|
||||
static void set_fdtshieldcmd(const char *fdt_cmd)
|
||||
{
|
||||
setenv("fdtshieldcmd", fdt_cmd);
|
||||
setenv("fdtshieldcmd", fdt_cmd);
|
||||
}
|
||||
|
||||
struct shield_command {
|
||||
int shield_id;
|
||||
const char *default_shieldcmd;
|
||||
const char *fdtshieldcmd;
|
||||
int shield_id;
|
||||
const char *name;
|
||||
const char *default_shieldcmd;
|
||||
const char *fdtshieldcmd;
|
||||
};
|
||||
|
||||
#define SHIELD_COM_IO 0
|
||||
#define SHIELD_DUALCAN 1
|
||||
|
||||
static struct shield_command known_shield_commands[] = {
|
||||
{
|
||||
SHIELD_COM_IO,
|
||||
"shield comio mode rs232",
|
||||
"fdt get value serial0 /aliases serial0;" \
|
||||
"fdt set $serial0 status okay"
|
||||
},
|
||||
{
|
||||
SHIELD_DUALCAN,
|
||||
"shield dualcan termination off off",
|
||||
"fdt get value can0 /aliases d_can0;" \
|
||||
"fdt get value can1 /aliases d_can1;" \
|
||||
"fdt set $can0 status okay;" \
|
||||
"fdt set $can1 status okay;" \
|
||||
},
|
||||
{
|
||||
SHIELD_COM_IO,
|
||||
"comio",
|
||||
"shield comio mode rs232",
|
||||
"fdt get value serial0 /aliases serial0;" \
|
||||
"fdt set $serial0 status okay"
|
||||
},
|
||||
{
|
||||
SHIELD_DUALCAN,
|
||||
"dualcan",
|
||||
"shield dualcan termination off off",
|
||||
"fdt get value can0 /aliases d_can0;" \
|
||||
"fdt get value can1 /aliases d_can1;" \
|
||||
"fdt set $can0 status okay;" \
|
||||
"fdt set $can1 status okay;" \
|
||||
},
|
||||
};
|
||||
|
||||
static const struct shield_command* get_shield_command(int shield_id)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(known_shield_commands); i++) {
|
||||
if (known_shield_commands[i].shield_id == shield_id) {
|
||||
return &known_shield_commands[i];
|
||||
}
|
||||
}
|
||||
for (i = 0; i < ARRAY_SIZE(known_shield_commands); i++) {
|
||||
if (known_shield_commands[i].shield_id == shield_id) {
|
||||
return &known_shield_commands[i];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void shield_config(void)
|
||||
{
|
||||
#define MAX_SHIELD_CMD_LEN 128
|
||||
char shieldcmd_linux[MAX_SHIELD_CMD_LEN];
|
||||
const char *shieldcmd;
|
||||
const struct shield_command *cmd;
|
||||
int len;
|
||||
char shieldcmd_linux[MAX_SHIELD_CMD_LEN];
|
||||
const char *shieldcmd;
|
||||
const struct shield_command *cmd;
|
||||
int len;
|
||||
|
||||
int shield_id = bd_get_shield(0);
|
||||
if (shield_id < 0) {
|
||||
printf("No shield found in bd\n");
|
||||
return;
|
||||
}
|
||||
int shield_id = bd_get_shield(0);
|
||||
if (shield_id < 0) {
|
||||
debug("No shield found in bd\n");
|
||||
return;
|
||||
}
|
||||
|
||||
cmd = get_shield_command(shield_id);
|
||||
if (cmd == NULL) {
|
||||
printf ("Unknown shield id %d\n", shield_id);
|
||||
return;
|
||||
}
|
||||
cmd = get_shield_command(shield_id);
|
||||
if (cmd == NULL) {
|
||||
printf ("Unknown shield id %d\n", shield_id);
|
||||
return;
|
||||
}
|
||||
|
||||
shieldcmd = cmd->default_shieldcmd;
|
||||
printf("Shield found: %s\n", cmd->name);
|
||||
|
||||
/* If a shield configuration set by linux take it without bd check, we asume that Linux knows
|
||||
* what to do. */
|
||||
len = read_file("/root/boot/shieldcmd", shieldcmd_linux, MAX_SHIELD_CMD_LEN);
|
||||
if (len > 0) {
|
||||
puts("Shield command found in file, using it\n");
|
||||
shieldcmd = shieldcmd_linux;
|
||||
}
|
||||
shieldcmd = cmd->default_shieldcmd;
|
||||
|
||||
setenv("shieldcmd", shieldcmd);
|
||||
/* If a shield configuration set by linux take it without bd check, we asume that Linux knows
|
||||
* what to do. */
|
||||
len = read_file("/root/boot/shieldcmd", shieldcmd_linux, MAX_SHIELD_CMD_LEN);
|
||||
if (len > 0) {
|
||||
debug("Shield command found in file, using it\n");
|
||||
shieldcmd = shieldcmd_linux;
|
||||
}
|
||||
|
||||
set_fdtshieldcmd(cmd->fdtshieldcmd);
|
||||
printf("Shield command: %s\n", shieldcmd);
|
||||
|
||||
setenv("shieldcmd", shieldcmd);
|
||||
|
||||
set_fdtshieldcmd(cmd->fdtshieldcmd);
|
||||
}
|
||||
|
||||
static void shield_init(void)
|
||||
{
|
||||
can_shield_init();
|
||||
comio_shield_init();
|
||||
can_shield_init();
|
||||
comio_shield_init();
|
||||
|
||||
shield_config();
|
||||
shield_config();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -642,7 +649,7 @@ int board_late_init(void)
|
|||
enable_wlan_clock();
|
||||
|
||||
#if !defined(CONFIG_SPL_BUILD)
|
||||
shield_init();
|
||||
shield_init();
|
||||
|
||||
check_fct();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#define DEBUG
|
||||
#undef DEBUG
|
||||
|
||||
#include <common.h>
|
||||
#include <asm/gpio.h>
|
||||
|
|
@ -34,32 +34,31 @@ int shield_gpio_request_as_input(unsigned int gpio, const char *label)
|
|||
|
||||
void shield_register(struct shield_t *shield)
|
||||
{
|
||||
if (shield_count >= MAX_SHIELDS) {
|
||||
printf("Max shield count reached (%d), please increment MAX_SHIELDS\n", MAX_SHIELDS);
|
||||
return;
|
||||
}
|
||||
shields[shield_count++] = shield;
|
||||
if (shield_count >= MAX_SHIELDS) {
|
||||
printf("Max shield count reached (%d), please increment MAX_SHIELDS\n", MAX_SHIELDS);
|
||||
return;
|
||||
}
|
||||
shields[shield_count++] = shield;
|
||||
}
|
||||
|
||||
int shield_set_mode(const char* shield_type, int argc, char * const argv[])
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < shield_count; i++) {
|
||||
if (strcmp(shield_type, shields[i]->name) == 0) {
|
||||
return shields[i]->setmode(argv, argc);
|
||||
}
|
||||
}
|
||||
printf("Shield %s is unknown\n", shield_type);
|
||||
return -1;
|
||||
for (i = 0; i < shield_count; i++) {
|
||||
if (strcmp(shield_type, shields[i]->name) == 0) {
|
||||
return shields[i]->setmode(argv, argc);
|
||||
}
|
||||
}
|
||||
printf("Shield %s is unknown\n", shield_type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int do_shieldmode(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||
{
|
||||
if (argc < 3) {
|
||||
puts("Invalid command (see help)\n");
|
||||
if (argc < 3) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return shield_set_mode(argv[1], argc - 2, &argv[2]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#define DEBUG
|
||||
#undef DEBUG
|
||||
|
||||
#include <common.h>
|
||||
#include <asm/gpio.h>
|
||||
|
|
@ -37,7 +37,7 @@ static int request_gpios(void)
|
|||
{
|
||||
int ret;
|
||||
|
||||
debug("Shiled configure gpios\n");
|
||||
debug("Shield configure gpios\n");
|
||||
ret = shield_gpio_request_as_input(NETBIRD_GPIO_RST_SHIELD_N, "shield-rst");
|
||||
if ((ret < 0))
|
||||
return -1;
|
||||
|
|
@ -57,12 +57,12 @@ static int request_gpios(void)
|
|||
|
||||
static int configure_shieldmode(int mode)
|
||||
{
|
||||
int ret;
|
||||
int ret;
|
||||
|
||||
if (mode < 0 || mode > 3) {
|
||||
printf("Invalid shield mode %d\n", mode);
|
||||
return -1;
|
||||
}
|
||||
if (mode < 0 || mode > 3) {
|
||||
debug("Invalid shield mode %d\n", mode);
|
||||
return -1;
|
||||
}
|
||||
|
||||
debug("Shield type dualcan\n");
|
||||
debug ("Set shield mode to %d\n", mode);
|
||||
|
|
@ -144,8 +144,8 @@ static int get_termination(const char* termination)
|
|||
return 0;
|
||||
}
|
||||
|
||||
printf ("Invalid termination mode %s (falling back to off)", termination);
|
||||
return 0;
|
||||
debug ("Invalid termination mode %s (falling back to off)", termination);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int get_mode_from_args(char * const argv[], int argc)
|
||||
|
|
@ -157,12 +157,15 @@ static int get_mode_from_args(char * const argv[], int argc)
|
|||
assert(argc == (CAN_PORTS + 1));
|
||||
|
||||
if (strcmp ("termination", argv[0])) {
|
||||
puts("The only option for dualcan is terminations\n");
|
||||
debug("The only option for dualcan is terminations\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < CAN_PORTS; i ++) {
|
||||
terminations[i] = get_termination(argv[i + 1]);
|
||||
if (terminations[i] < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Termination is inverse */
|
||||
|
|
@ -172,12 +175,11 @@ static int get_mode_from_args(char * const argv[], int argc)
|
|||
static int set_shieldmode(char * const argv[], int argc)
|
||||
{
|
||||
if (argc != 3) {
|
||||
puts("Too few arguments for dualcan\n");
|
||||
debug("Too few arguments for dualcan\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
configure_shieldmode(get_mode_from_args(argv, argc));
|
||||
return 0;
|
||||
return configure_shieldmode(get_mode_from_args(argv, argc));
|
||||
}
|
||||
|
||||
struct shield_t can_shield = {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* #define DEBUG */
|
||||
#undef DEBUG
|
||||
|
||||
#include <common.h>
|
||||
#include <asm/gpio.h>
|
||||
|
|
@ -55,12 +55,12 @@ static int request_gpios(void)
|
|||
|
||||
static int configure_shieldmode(int mode)
|
||||
{
|
||||
int ret;
|
||||
int ret;
|
||||
|
||||
if (mode < 0 || mode > 3) {
|
||||
printf("Invalid shield mode %d\n", mode);
|
||||
return -1;
|
||||
}
|
||||
if (mode < 0 || mode > 3) {
|
||||
debug ("Invalid shield mode %d\n", mode);
|
||||
return -1;
|
||||
}
|
||||
|
||||
debug("Shield type comio\n");
|
||||
debug ("Set shield mode to %d\n", mode);
|
||||
|
|
@ -138,7 +138,6 @@ static int configure_shieldmode(int mode)
|
|||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
static int get_rs232(const char *mode)
|
||||
|
|
@ -160,8 +159,8 @@ static int get_termination(const char* termination)
|
|||
return 0;
|
||||
}
|
||||
|
||||
printf ("Invalid termination mode %s (falling back to off)", termination);
|
||||
return 0;
|
||||
debug ("Invalid termination mode %s (falling back to off)", termination);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int get_mode_from_args(char * const argv[], int argc)
|
||||
|
|
@ -169,10 +168,10 @@ static int get_mode_from_args(char * const argv[], int argc)
|
|||
int termination = 0;
|
||||
int rs232 = 0;
|
||||
|
||||
assert(argc >= 2);
|
||||
assert(argc >= 2);
|
||||
|
||||
if (strcmp ("mode", argv[0])) {
|
||||
puts("Invalid arguments (see help)\n");
|
||||
debug("Invalid arguments (see help)\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -180,10 +179,14 @@ static int get_mode_from_args(char * const argv[], int argc)
|
|||
|
||||
if (argc > 2) {
|
||||
if (rs232 || strcmp("termination", argv[2])) {
|
||||
puts("Invalid arguments, do not configure termination\n");
|
||||
debug("Invalid arguments, do not configure termination\n");
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
termination = get_termination(argv[3]);
|
||||
if (termination < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -194,13 +197,12 @@ static int get_mode_from_args(char * const argv[], int argc)
|
|||
int set_shieldmode(char * const argv[], int argc)
|
||||
{
|
||||
if (argc < 2) {
|
||||
puts("Too few arguments for comio\n");
|
||||
debug("Too few arguments for comio\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
configure_shieldmode(get_mode_from_args(argv, argc));
|
||||
|
||||
return 0;
|
||||
/* -1 will make configure_shieldmode to faile and is okay therefore */
|
||||
return configure_shieldmode(get_mode_from_args(argv, argc));
|
||||
}
|
||||
|
||||
struct shield_t comio_shield = {
|
||||
|
|
|
|||
Loading…
Reference in New Issue