2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2014-10-03 10:21:06 +00:00
|
|
|
/*
|
2016-08-25 08:02:31 +00:00
|
|
|
* Copyright (C) 2012-2015 Panasonic Corporation
|
|
|
|
* Copyright (C) 2015-2016 Socionext Inc.
|
|
|
|
* Author: Masahiro Yamada <yamada.masahiro@socionext.com>
|
2014-10-03 10:21:06 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2015-09-21 15:27:31 +00:00
|
|
|
#include <linux/ctype.h>
|
2015-05-29 08:30:00 +00:00
|
|
|
#include <linux/io.h>
|
2016-01-08 16:51:13 +00:00
|
|
|
|
|
|
|
#include "micro-support-card.h"
|
2014-10-03 10:21:06 +00:00
|
|
|
|
2015-09-21 15:27:32 +00:00
|
|
|
#define MICRO_SUPPORT_CARD_BASE 0x43f00000
|
|
|
|
#define SMC911X_BASE ((MICRO_SUPPORT_CARD_BASE) + 0x00000)
|
|
|
|
#define LED_BASE ((MICRO_SUPPORT_CARD_BASE) + 0x90000)
|
|
|
|
#define NS16550A_BASE ((MICRO_SUPPORT_CARD_BASE) + 0xb0000)
|
|
|
|
#define MICRO_SUPPORT_CARD_RESET ((MICRO_SUPPORT_CARD_BASE) + 0xd0034)
|
|
|
|
#define MICRO_SUPPORT_CARD_REVISION ((MICRO_SUPPORT_CARD_BASE) + 0xd00E0)
|
|
|
|
|
2014-10-03 10:21:06 +00:00
|
|
|
/*
|
|
|
|
* 0: reset deassert, 1: reset
|
|
|
|
*
|
|
|
|
* bit[0]: LAN, I2C, LED
|
|
|
|
* bit[1]: UART
|
|
|
|
*/
|
2017-01-15 05:59:06 +00:00
|
|
|
static void support_card_reset_deassert(void)
|
2014-10-03 10:21:06 +00:00
|
|
|
{
|
ARM: uniphier: add work-around to support Micro Support Card v3.6.10
Due to some hardware guy's awful work, this version is not compatible
with v3.6: the logic of BIT(0) of the reset logic is inverted! (and
v3.6.10 is horribly wrong in multiple ways), but this is what we have
to solve now.
The v3.6 expects 0x0000 set to the register for reset de-assertion,
while v3.6 does 0x0001.
This commit (ab)uses another bug of v3.6.10 to work around the issue.
The UniPhier System Bus is a 16-bit bus, which this support card is
connected to. A 32-bit write to the bus (writel() function call) is
divided into two 16-bit write transactions, with LSB the first. What
is amazing for v3.6.10 is that access to address 4N + 2 goes to 4N
(Jesus Christ!).
For clarification, things are like this:
writel(0x00010000, MICRO_SUPPORT_CARD_RESET);
is done with two bus transactions as follows
[1] write 0x0000 to address MICRO_SUPPORT_CARD
[2] write 0x0001 to address MICRO_SUPPORT_CARD + 2
For v3.6, [1] is written to the register and [2] is correctly ignored
because there is nothing at the address MICRO_SUPPORT_CARD + 2. This
is what we expect.
For v3.6.10, [1] is written to the reset register and then [2] is
over-written to the same register due to the bus access bug.
For the latter, it produces a glitch signal to the BIT[0], so the
device state is lost due to the reset pulse. This solution only
works for the start-up code.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2016-03-18 07:41:46 +00:00
|
|
|
writel(0x00010000, MICRO_SUPPORT_CARD_RESET);
|
2014-10-03 10:21:06 +00:00
|
|
|
}
|
|
|
|
|
2017-01-15 05:59:06 +00:00
|
|
|
static void support_card_reset(void)
|
2014-10-03 10:21:06 +00:00
|
|
|
{
|
ARM: uniphier: add work-around to support Micro Support Card v3.6.10
Due to some hardware guy's awful work, this version is not compatible
with v3.6: the logic of BIT(0) of the reset logic is inverted! (and
v3.6.10 is horribly wrong in multiple ways), but this is what we have
to solve now.
The v3.6 expects 0x0000 set to the register for reset de-assertion,
while v3.6 does 0x0001.
This commit (ab)uses another bug of v3.6.10 to work around the issue.
The UniPhier System Bus is a 16-bit bus, which this support card is
connected to. A 32-bit write to the bus (writel() function call) is
divided into two 16-bit write transactions, with LSB the first. What
is amazing for v3.6.10 is that access to address 4N + 2 goes to 4N
(Jesus Christ!).
For clarification, things are like this:
writel(0x00010000, MICRO_SUPPORT_CARD_RESET);
is done with two bus transactions as follows
[1] write 0x0000 to address MICRO_SUPPORT_CARD
[2] write 0x0001 to address MICRO_SUPPORT_CARD + 2
For v3.6, [1] is written to the register and [2] is correctly ignored
because there is nothing at the address MICRO_SUPPORT_CARD + 2. This
is what we expect.
For v3.6.10, [1] is written to the reset register and then [2] is
over-written to the same register due to the bus access bug.
For the latter, it produces a glitch signal to the BIT[0], so the
device state is lost due to the reset pulse. This solution only
works for the start-up code.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2016-03-18 07:41:46 +00:00
|
|
|
writel(0x00020003, MICRO_SUPPORT_CARD_RESET);
|
2014-10-03 10:21:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int support_card_show_revision(void)
|
|
|
|
{
|
|
|
|
u32 revision;
|
|
|
|
|
2015-09-11 11:17:45 +00:00
|
|
|
revision = readl(MICRO_SUPPORT_CARD_REVISION);
|
2016-08-25 08:02:31 +00:00
|
|
|
revision &= 0xff;
|
|
|
|
|
|
|
|
/* revision 3.6.x card changed the revision format */
|
2017-02-20 08:32:19 +00:00
|
|
|
printf("SC: Micro Support Card (CPLD version %s%d.%d)\n",
|
|
|
|
revision >> 4 == 6 ? "3." : "",
|
2016-08-25 08:02:31 +00:00
|
|
|
revision >> 4, revision & 0xf);
|
|
|
|
|
2014-10-03 10:21:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void support_card_init(void)
|
|
|
|
{
|
2017-01-15 05:59:06 +00:00
|
|
|
support_card_reset();
|
2014-10-03 10:21:06 +00:00
|
|
|
/*
|
|
|
|
* After power on, we need to keep the LAN controller in reset state
|
|
|
|
* for a while. (200 usec)
|
|
|
|
*/
|
2016-10-08 04:25:29 +00:00
|
|
|
udelay(200);
|
2014-10-03 10:21:06 +00:00
|
|
|
support_card_reset_deassert();
|
2017-02-20 08:32:19 +00:00
|
|
|
|
|
|
|
support_card_show_revision();
|
2014-10-03 10:21:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(CONFIG_SMC911X)
|
|
|
|
#include <netdev.h>
|
|
|
|
|
|
|
|
int board_eth_init(bd_t *bis)
|
|
|
|
{
|
2015-09-21 15:27:32 +00:00
|
|
|
return smc911x_initialize(0, SMC911X_BASE);
|
2014-10-03 10:21:06 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-02-11 13:43:54 +00:00
|
|
|
#if defined(CONFIG_MTD_NOR_FLASH)
|
2014-10-03 10:21:06 +00:00
|
|
|
|
|
|
|
#include <mtd/cfi_flash.h>
|
|
|
|
|
2014-12-05 15:03:26 +00:00
|
|
|
struct memory_bank {
|
|
|
|
phys_addr_t base;
|
|
|
|
unsigned long size;
|
|
|
|
};
|
2014-10-03 10:21:06 +00:00
|
|
|
|
2014-12-05 15:03:26 +00:00
|
|
|
static int mem_is_flash(const struct memory_bank *mem)
|
2014-10-03 10:21:06 +00:00
|
|
|
{
|
|
|
|
const int loop = 128;
|
|
|
|
u32 *scratch_addr;
|
|
|
|
u32 saved_value;
|
|
|
|
int ret = 1;
|
|
|
|
int i;
|
|
|
|
|
2014-12-05 15:03:26 +00:00
|
|
|
/* just in case, use the tail of the memory bank */
|
|
|
|
scratch_addr = map_physmem(mem->base + mem->size - sizeof(u32) * loop,
|
|
|
|
sizeof(u32) * loop, MAP_NOCACHE);
|
2014-10-03 10:21:06 +00:00
|
|
|
|
|
|
|
for (i = 0; i < loop; i++, scratch_addr++) {
|
|
|
|
saved_value = readl(scratch_addr);
|
|
|
|
writel(~saved_value, scratch_addr);
|
|
|
|
if (readl(scratch_addr) != saved_value) {
|
|
|
|
/* We assume no memory or SRAM here. */
|
|
|
|
writel(saved_value, scratch_addr);
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unmap_physmem(scratch_addr, MAP_NOCACHE);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-09-11 11:17:45 +00:00
|
|
|
/* {address, size} */
|
|
|
|
static const struct memory_bank memory_banks[] = {
|
2015-09-11 11:17:47 +00:00
|
|
|
{0x42000000, 0x01f00000},
|
2014-12-05 15:03:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct memory_bank
|
|
|
|
*flash_banks_list[CONFIG_SYS_MAX_FLASH_BANKS_DETECT];
|
|
|
|
|
|
|
|
phys_addr_t cfi_flash_bank_addr(int i)
|
2014-10-03 10:21:06 +00:00
|
|
|
{
|
2014-12-05 15:03:26 +00:00
|
|
|
return flash_banks_list[i]->base;
|
|
|
|
}
|
2014-10-03 10:21:06 +00:00
|
|
|
|
2014-12-05 15:03:26 +00:00
|
|
|
unsigned long cfi_flash_bank_size(int i)
|
|
|
|
{
|
|
|
|
return flash_banks_list[i]->size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void detect_num_flash_banks(void)
|
|
|
|
{
|
|
|
|
const struct memory_bank *memory_bank, *end;
|
|
|
|
|
|
|
|
cfi_flash_num_flash_banks = 0;
|
|
|
|
|
2015-09-11 11:17:45 +00:00
|
|
|
memory_bank = memory_banks;
|
|
|
|
end = memory_bank + ARRAY_SIZE(memory_banks);
|
2014-12-05 15:03:26 +00:00
|
|
|
|
|
|
|
for (; memory_bank < end; memory_bank++) {
|
|
|
|
if (cfi_flash_num_flash_banks >=
|
|
|
|
CONFIG_SYS_MAX_FLASH_BANKS_DETECT)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (mem_is_flash(memory_bank)) {
|
|
|
|
flash_banks_list[cfi_flash_num_flash_banks] =
|
|
|
|
memory_bank;
|
|
|
|
|
|
|
|
debug("flash bank found: base = 0x%lx, size = 0x%lx\n",
|
2016-02-26 09:59:45 +00:00
|
|
|
(unsigned long)memory_bank->base,
|
|
|
|
(unsigned long)memory_bank->size);
|
2014-12-05 15:03:26 +00:00
|
|
|
cfi_flash_num_flash_banks++;
|
2014-10-03 10:21:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-05 15:03:26 +00:00
|
|
|
debug("number of flash banks: %d\n", cfi_flash_num_flash_banks);
|
|
|
|
}
|
2017-02-11 13:43:54 +00:00
|
|
|
#else /* CONFIG_MTD_NOR_FLASH */
|
2017-01-15 05:59:06 +00:00
|
|
|
static void detect_num_flash_banks(void)
|
2014-12-05 15:03:26 +00:00
|
|
|
{
|
|
|
|
};
|
2017-02-11 13:43:54 +00:00
|
|
|
#endif /* CONFIG_MTD_NOR_FLASH */
|
2014-12-05 15:03:26 +00:00
|
|
|
|
|
|
|
void support_card_late_init(void)
|
|
|
|
{
|
|
|
|
detect_num_flash_banks();
|
2014-10-03 10:21:06 +00:00
|
|
|
}
|
2015-09-21 15:27:31 +00:00
|
|
|
|
|
|
|
static const u8 ledval_num[] = {
|
|
|
|
0x7e, /* 0 */
|
|
|
|
0x0c, /* 1 */
|
|
|
|
0xb6, /* 2 */
|
|
|
|
0x9e, /* 3 */
|
|
|
|
0xcc, /* 4 */
|
|
|
|
0xda, /* 5 */
|
|
|
|
0xfa, /* 6 */
|
|
|
|
0x4e, /* 7 */
|
|
|
|
0xfe, /* 8 */
|
|
|
|
0xde, /* 9 */
|
|
|
|
};
|
|
|
|
|
|
|
|
static const u8 ledval_alpha[] = {
|
|
|
|
0xee, /* A */
|
|
|
|
0xf8, /* B */
|
|
|
|
0x72, /* C */
|
|
|
|
0xbc, /* D */
|
|
|
|
0xf2, /* E */
|
|
|
|
0xe2, /* F */
|
|
|
|
0x7a, /* G */
|
|
|
|
0xe8, /* H */
|
|
|
|
0x08, /* I */
|
|
|
|
0x3c, /* J */
|
|
|
|
0xea, /* K */
|
|
|
|
0x70, /* L */
|
|
|
|
0x6e, /* M */
|
|
|
|
0xa8, /* N */
|
|
|
|
0xb8, /* O */
|
|
|
|
0xe6, /* P */
|
|
|
|
0xce, /* Q */
|
|
|
|
0xa0, /* R */
|
|
|
|
0xc8, /* S */
|
|
|
|
0x8c, /* T */
|
|
|
|
0x7c, /* U */
|
|
|
|
0x54, /* V */
|
|
|
|
0xfc, /* W */
|
|
|
|
0xec, /* X */
|
|
|
|
0xdc, /* Y */
|
|
|
|
0xa4, /* Z */
|
|
|
|
};
|
|
|
|
|
|
|
|
static u8 char2ledval(char c)
|
|
|
|
{
|
|
|
|
if (isdigit(c))
|
|
|
|
return ledval_num[c - '0'];
|
|
|
|
else if (isalpha(c))
|
|
|
|
return ledval_alpha[toupper(c) - 'A'];
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void led_puts(const char *s)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u32 val = 0;
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
val <<= 8;
|
|
|
|
val |= char2ledval(*s);
|
|
|
|
if (*s != '\0')
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
|
2015-09-21 15:27:32 +00:00
|
|
|
writel(~val, LED_BASE);
|
2015-09-21 15:27:31 +00:00
|
|
|
}
|