Unverified Commit ba0248b5 authored by danh-arm's avatar danh-arm Committed by GitHub
Browse files

Merge pull request #1450 from MISL-EBU-System-SW/marvell-support-v6

Marvell support for Armada 8K SoC family
parents 992a3536 23e0fe52
/*
* Copyright (C) 2018 Marvell International Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
* https://spdx.org/licenses
*/
/* GWIN unit device driver for Marvell AP810 SoC */
#include <a8k_common.h>
#include <debug.h>
#include <gwin.h>
#include <mmio.h>
#include <mvebu.h>
#include <mvebu_def.h>
#if LOG_LEVEL >= LOG_LEVEL_INFO
#define DEBUG_ADDR_MAP
#endif
/* common defines */
#define WIN_ENABLE_BIT (0x1)
#define WIN_TARGET_MASK (0xF)
#define WIN_TARGET_SHIFT (0x8)
#define WIN_TARGET(tgt) (((tgt) & WIN_TARGET_MASK) \
<< WIN_TARGET_SHIFT)
/* Bits[43:26] of the physical address are the window base,
* which is aligned to 64MB
*/
#define ADDRESS_RSHIFT (26)
#define ADDRESS_LSHIFT (10)
#define GWIN_ALIGNMENT_64M (0x4000000)
/* AP registers */
#define GWIN_CR_OFFSET(ap, win) (MVEBU_GWIN_BASE(ap) + 0x0 + \
(0x10 * (win)))
#define GWIN_ALR_OFFSET(ap, win) (MVEBU_GWIN_BASE(ap) + 0x8 + \
(0x10 * (win)))
#define GWIN_AHR_OFFSET(ap, win) (MVEBU_GWIN_BASE(ap) + 0xc + \
(0x10 * (win)))
#define CCU_GRU_CR_OFFSET(ap) (MVEBU_CCU_GRU_BASE(ap))
#define CCR_GRU_CR_GWIN_MBYPASS (1 << 1)
static void gwin_check(struct addr_map_win *win)
{
/* The base is always 64M aligned */
if (IS_NOT_ALIGN(win->base_addr, GWIN_ALIGNMENT_64M)) {
win->base_addr &= ~(GWIN_ALIGNMENT_64M - 1);
NOTICE("%s: Align the base address to 0x%llx\n",
__func__, win->base_addr);
}
/* size parameter validity check */
if (IS_NOT_ALIGN(win->win_size, GWIN_ALIGNMENT_64M)) {
win->win_size = ALIGN_UP(win->win_size, GWIN_ALIGNMENT_64M);
NOTICE("%s: Aligning window size to 0x%llx\n",
__func__, win->win_size);
}
}
static void gwin_enable_window(int ap_index, struct addr_map_win *win,
uint32_t win_num)
{
uint32_t alr, ahr;
uint64_t end_addr;
if ((win->target_id & WIN_TARGET_MASK) != win->target_id) {
ERROR("target ID = %d, is invalid\n", win->target_id);
return;
}
/* calculate 64bit end-address */
end_addr = (win->base_addr + win->win_size - 1);
alr = (uint32_t)((win->base_addr >> ADDRESS_RSHIFT) << ADDRESS_LSHIFT);
ahr = (uint32_t)((end_addr >> ADDRESS_RSHIFT) << ADDRESS_LSHIFT);
/* write start address and end address for GWIN */
mmio_write_32(GWIN_ALR_OFFSET(ap_index, win_num), alr);
mmio_write_32(GWIN_AHR_OFFSET(ap_index, win_num), ahr);
/* write the target ID and enable the window */
mmio_write_32(GWIN_CR_OFFSET(ap_index, win_num),
WIN_TARGET(win->target_id) | WIN_ENABLE_BIT);
}
static void gwin_disable_window(int ap_index, uint32_t win_num)
{
uint32_t win_reg;
win_reg = mmio_read_32(GWIN_CR_OFFSET(ap_index, win_num));
win_reg &= ~WIN_ENABLE_BIT;
mmio_write_32(GWIN_CR_OFFSET(ap_index, win_num), win_reg);
}
/* Insert/Remove temporary window for using the out-of reset default
* CPx base address to access the CP configuration space prior to
* the further base address update in accordance with address mapping
* design.
*
* NOTE: Use the same window array for insertion and removal of
* temporary windows.
*/
void gwin_temp_win_insert(int ap_index, struct addr_map_win *win, int size)
{
uint32_t win_id;
for (int i = 0; i < size; i++) {
win_id = MVEBU_GWIN_MAX_WINS - i - 1;
gwin_check(win);
gwin_enable_window(ap_index, win, win_id);
win++;
}
}
/*
* NOTE: Use the same window array for insertion and removal of
* temporary windows.
*/
void gwin_temp_win_remove(int ap_index, struct addr_map_win *win, int size)
{
uint32_t win_id;
for (int i = 0; i < size; i++) {
uint64_t base;
uint32_t target;
win_id = MVEBU_GWIN_MAX_WINS - i - 1;
target = mmio_read_32(GWIN_CR_OFFSET(ap_index, win_id));
target >>= WIN_TARGET_SHIFT;
target &= WIN_TARGET_MASK;
base = mmio_read_32(GWIN_ALR_OFFSET(ap_index, win_id));
base >>= ADDRESS_LSHIFT;
base <<= ADDRESS_RSHIFT;
if (win->target_id != target) {
ERROR("%s: Trying to remove bad window-%d!\n",
__func__, win_id);
continue;
}
gwin_disable_window(ap_index, win_id);
win++;
}
}
#ifdef DEBUG_ADDR_MAP
static void dump_gwin(int ap_index)
{
uint32_t win_num;
/* Dump all GWIN windows */
tf_printf("\tbank target start end\n");
tf_printf("\t----------------------------------------------------\n");
for (win_num = 0; win_num < MVEBU_GWIN_MAX_WINS; win_num++) {
uint32_t cr;
uint64_t alr, ahr;
cr = mmio_read_32(GWIN_CR_OFFSET(ap_index, win_num));
/* Window enabled */
if (cr & WIN_ENABLE_BIT) {
alr = mmio_read_32(GWIN_ALR_OFFSET(ap_index, win_num));
alr = (alr >> ADDRESS_LSHIFT) << ADDRESS_RSHIFT;
ahr = mmio_read_32(GWIN_AHR_OFFSET(ap_index, win_num));
ahr = (ahr >> ADDRESS_LSHIFT) << ADDRESS_RSHIFT;
tf_printf("\tgwin %d 0x%016llx 0x%016llx\n",
(cr >> 8) & 0xF, alr, ahr);
}
}
}
#endif
int init_gwin(int ap_index)
{
struct addr_map_win *win;
uint32_t win_id;
uint32_t win_count;
uint32_t win_reg;
INFO("Initializing GWIN Address decoding\n");
/* Get the array of the windows and its size */
marvell_get_gwin_memory_map(ap_index, &win, &win_count);
if (win_count <= 0) {
INFO("no windows configurations found\n");
return 0;
}
if (win_count > MVEBU_GWIN_MAX_WINS) {
ERROR("number of windows is bigger than %d\n",
MVEBU_GWIN_MAX_WINS);
return 0;
}
/* disable all windows */
for (win_id = 0; win_id < MVEBU_GWIN_MAX_WINS; win_id++)
gwin_disable_window(ap_index, win_id);
/* enable relevant windows */
for (win_id = 0; win_id < win_count; win_id++, win++) {
gwin_check(win);
gwin_enable_window(ap_index, win, win_id);
}
/* GWIN Miss feature has not verified, therefore any access towards
* remote AP should be accompanied with proper configuration to
* GWIN registers group and therefore the GWIN Miss feature
* should be set into Bypass mode, need to make sure all GWIN regions
* are defined correctly that will assure no GWIN miss occurrance
* JIRA-AURORA2-1630
*/
INFO("Update GWIN miss bypass\n");
win_reg = mmio_read_32(CCU_GRU_CR_OFFSET(ap_index));
win_reg |= CCR_GRU_CR_GWIN_MBYPASS;
mmio_write_32(CCU_GRU_CR_OFFSET(ap_index), win_reg);
#ifdef DEBUG_ADDR_MAP
dump_gwin(ap_index);
#endif
INFO("Done GWIN Address decoding Initializing\n");
return 0;
}
/*
* Copyright (C) 2018 Marvell International Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
* https://spdx.org/licenses
*/
/* This driver provides I2C support for Marvell A8K and compatible SoCs */
#include <a8k_i2c.h>
#include <debug.h>
#include <delay_timer.h>
#include <errno.h>
#include <mmio.h>
#include <mvebu_def.h>
#if LOG_LEVEL >= LOG_LEVEL_VERBOSE
#define DEBUG_I2C
#endif
#define CONFIG_SYS_TCLK 250000000
#define CONFIG_SYS_I2C_SPEED 100000
#define CONFIG_SYS_I2C_SLAVE 0x0
#define I2C_TIMEOUT_VALUE 0x500
#define I2C_MAX_RETRY_CNT 1000
#define I2C_CMD_WRITE 0x0
#define I2C_CMD_READ 0x1
#define I2C_DATA_ADDR_7BIT_OFFS 0x1
#define I2C_DATA_ADDR_7BIT_MASK (0xFF << I2C_DATA_ADDR_7BIT_OFFS)
#define I2C_CONTROL_ACK 0x00000004
#define I2C_CONTROL_IFLG 0x00000008
#define I2C_CONTROL_STOP 0x00000010
#define I2C_CONTROL_START 0x00000020
#define I2C_CONTROL_TWSIEN 0x00000040
#define I2C_CONTROL_INTEN 0x00000080
#define I2C_STATUS_START 0x08
#define I2C_STATUS_REPEATED_START 0x10
#define I2C_STATUS_ADDR_W_ACK 0x18
#define I2C_STATUS_DATA_W_ACK 0x28
#define I2C_STATUS_LOST_ARB_DATA_ADDR_TRANSFER 0x38
#define I2C_STATUS_ADDR_R_ACK 0x40
#define I2C_STATUS_DATA_R_ACK 0x50
#define I2C_STATUS_DATA_R_NAK 0x58
#define I2C_STATUS_LOST_ARB_GENERAL_CALL 0x78
#define I2C_STATUS_IDLE 0xF8
#define I2C_UNSTUCK_TRIGGER 0x1
#define I2C_UNSTUCK_ONGOING 0x2
#define I2C_UNSTUCK_ERROR 0x4
struct marvell_i2c_regs {
uint32_t slave_address;
uint32_t data;
uint32_t control;
union {
uint32_t status; /* when reading */
uint32_t baudrate; /* when writing */
} u;
uint32_t xtnd_slave_addr;
uint32_t reserved[2];
uint32_t soft_reset;
uint8_t reserved2[0xa0 - 0x20];
uint32_t unstuck;
};
static struct marvell_i2c_regs *base;
static int marvell_i2c_lost_arbitration(uint32_t *status)
{
*status = mmio_read_32((uintptr_t)&base->u.status);
if ((*status == I2C_STATUS_LOST_ARB_DATA_ADDR_TRANSFER) ||
(*status == I2C_STATUS_LOST_ARB_GENERAL_CALL))
return -EAGAIN;
return 0;
}
static void marvell_i2c_interrupt_clear(void)
{
uint32_t reg;
reg = mmio_read_32((uintptr_t)&base->control);
reg &= ~(I2C_CONTROL_IFLG);
mmio_write_32((uintptr_t)&base->control, reg);
/* Wait for 1 us for the clear to take effect */
udelay(1);
}
static int marvell_i2c_interrupt_get(void)
{
uint32_t reg;
/* get the interrupt flag bit */
reg = mmio_read_32((uintptr_t)&base->control);
reg &= I2C_CONTROL_IFLG;
return reg && I2C_CONTROL_IFLG;
}
static int marvell_i2c_wait_interrupt(void)
{
uint32_t timeout = 0;
while (!marvell_i2c_interrupt_get() && (timeout++ < I2C_TIMEOUT_VALUE))
;
if (timeout >= I2C_TIMEOUT_VALUE)
return -ETIMEDOUT;
return 0;
}
static int marvell_i2c_start_bit_set(void)
{
int is_int_flag = 0;
uint32_t status;
if (marvell_i2c_interrupt_get())
is_int_flag = 1;
/* set start bit */
mmio_write_32((uintptr_t)&base->control,
mmio_read_32((uintptr_t)&base->control) |
I2C_CONTROL_START);
/* in case that the int flag was set before i.e. repeated start bit */
if (is_int_flag) {
VERBOSE("%s: repeated start Bit\n", __func__);
marvell_i2c_interrupt_clear();
}
if (marvell_i2c_wait_interrupt()) {
ERROR("Start clear bit timeout\n");
return -ETIMEDOUT;
}
/* check that start bit went down */
if ((mmio_read_32((uintptr_t)&base->control) &
I2C_CONTROL_START) != 0) {
ERROR("Start bit didn't went down\n");
return -EPERM;
}
/* check the status */
if (marvell_i2c_lost_arbitration(&status)) {
ERROR("%s - %d: Lost arbitration, got status %x\n",
__func__, __LINE__, status);
return -EAGAIN;
}
if ((status != I2C_STATUS_START) &&
(status != I2C_STATUS_REPEATED_START)) {
ERROR("Got status %x after enable start bit.\n", status);
return -EPERM;
}
return 0;
}
static int marvell_i2c_stop_bit_set(void)
{
int timeout;
uint32_t status;
/* Generate stop bit */
mmio_write_32((uintptr_t)&base->control,
mmio_read_32((uintptr_t)&base->control) |
I2C_CONTROL_STOP);
marvell_i2c_interrupt_clear();
timeout = 0;
/* Read control register, check the control stop bit */
while ((mmio_read_32((uintptr_t)&base->control) & I2C_CONTROL_STOP) &&
(timeout++ < I2C_TIMEOUT_VALUE))
;
if (timeout >= I2C_TIMEOUT_VALUE) {
ERROR("Stop bit didn't went down\n");
return -ETIMEDOUT;
}
/* check that stop bit went down */
if ((mmio_read_32((uintptr_t)&base->control) & I2C_CONTROL_STOP) != 0) {
ERROR("Stop bit didn't went down\n");
return -EPERM;
}
/* check the status */
if (marvell_i2c_lost_arbitration(&status)) {
ERROR("%s - %d: Lost arbitration, got status %x\n",
__func__, __LINE__, status);
return -EAGAIN;
}
if (status != I2C_STATUS_IDLE) {
ERROR("Got status %x after enable stop bit.\n", status);
return -EPERM;
}
return 0;
}
static int marvell_i2c_address_set(uint8_t chain, int command)
{
uint32_t reg, status;
reg = (chain << I2C_DATA_ADDR_7BIT_OFFS) & I2C_DATA_ADDR_7BIT_MASK;
reg |= command;
mmio_write_32((uintptr_t)&base->data, reg);
udelay(1);
marvell_i2c_interrupt_clear();
if (marvell_i2c_wait_interrupt()) {
ERROR("Start clear bit timeout\n");
return -ETIMEDOUT;
}
/* check the status */
if (marvell_i2c_lost_arbitration(&status)) {
ERROR("%s - %d: Lost arbitration, got status %x\n",
__func__, __LINE__, status);
return -EAGAIN;
}
if (((status != I2C_STATUS_ADDR_R_ACK) && (command == I2C_CMD_READ)) ||
((status != I2C_STATUS_ADDR_W_ACK) && (command == I2C_CMD_WRITE))) {
/* only in debug, since in boot we try to read the SPD
* of both DRAM, and we don't want error messages in cas
* DIMM doesn't exist.
*/
INFO("%s: ERROR - status %x addr in %s mode.\n", __func__,
status, (command == I2C_CMD_WRITE) ? "Write" : "Read");
return -EPERM;
}
return 0;
}
/*
* The I2C module contains a clock divider to generate the SCL clock.
* This function calculates and sets the <N> and <M> fields in the I2C Baud
* Rate Register (t=01) to obtain given 'requested_speed'.
* The requested_speed will be equal to:
* CONFIG_SYS_TCLK / (10 * (M + 1) * (2 << N))
* Where M is the value represented by bits[6:3] and N is the value represented
* by bits[2:0] of "I2C Baud Rate Register".
* Therefore max M which can be set is 16 (2^4) and max N is 8 (2^3). So the
* lowest possible baudrate is:
* CONFIG_SYS_TCLK/(10 * (16 +1) * (2 << 8), which equals to:
* CONFIG_SYS_TCLK/87040. Assuming that CONFIG_SYS_TCLK=250MHz, the lowest
* possible frequency is ~2,872KHz.
*/
static unsigned int marvell_i2c_bus_speed_set(unsigned int requested_speed)
{
unsigned int n, m, freq, margin, min_margin = 0xffffffff;
unsigned int actual_n = 0, actual_m = 0;
int val;
/* Calculate N and M for the TWSI clock baud rate */
for (n = 0; n < 8; n++) {
for (m = 0; m < 16; m++) {
freq = CONFIG_SYS_TCLK / (10 * (m + 1) * (2 << n));
val = requested_speed - freq;
margin = (val > 0) ? val : -val;
if ((freq <= requested_speed) &&
(margin < min_margin)) {
min_margin = margin;
actual_n = n;
actual_m = m;
}
}
}
VERBOSE("%s: actual_n = %u, actual_m = %u\n",
__func__, actual_n, actual_m);
/* Set the baud rate */
mmio_write_32((uintptr_t)&base->u.baudrate, (actual_m << 3) | actual_n);
return 0;
}
#ifdef DEBUG_I2C
static int marvell_i2c_probe(uint8_t chip)
{
int ret = 0;
ret = marvell_i2c_start_bit_set();
if (ret != 0) {
marvell_i2c_stop_bit_set();
ERROR("%s - %d: %s", __func__, __LINE__,
"marvell_i2c_start_bit_set failed\n");
return -EPERM;
}
ret = marvell_i2c_address_set(chip, I2C_CMD_WRITE);
if (ret != 0) {
marvell_i2c_stop_bit_set();
ERROR("%s - %d: %s", __func__, __LINE__,
"marvell_i2c_address_set failed\n");
return -EPERM;
}
marvell_i2c_stop_bit_set();
VERBOSE("%s: successful I2C probe\n", __func__);
return ret;
}
#endif
/* regular i2c transaction */
static int marvell_i2c_data_receive(uint8_t *p_block, uint32_t block_size)
{
uint32_t reg, status, block_size_read = block_size;
/* Wait for cause interrupt */
if (marvell_i2c_wait_interrupt()) {
ERROR("Start clear bit timeout\n");
return -ETIMEDOUT;
}
while (block_size_read) {
if (block_size_read == 1) {
reg = mmio_read_32((uintptr_t)&base->control);
reg &= ~(I2C_CONTROL_ACK);
mmio_write_32((uintptr_t)&base->control, reg);
}
marvell_i2c_interrupt_clear();
if (marvell_i2c_wait_interrupt()) {
ERROR("Start clear bit timeout\n");
return -ETIMEDOUT;
}
/* check the status */
if (marvell_i2c_lost_arbitration(&status)) {
ERROR("%s - %d: Lost arbitration, got status %x\n",
__func__, __LINE__, status);
return -EAGAIN;
}
if ((status != I2C_STATUS_DATA_R_ACK) &&
(block_size_read != 1)) {
ERROR("Status %x in read transaction\n", status);
return -EPERM;
}
if ((status != I2C_STATUS_DATA_R_NAK) &&
(block_size_read == 1)) {
ERROR("Status %x in Rd Terminate\n", status);
return -EPERM;
}
/* read the data */
*p_block = (uint8_t) mmio_read_32((uintptr_t)&base->data);
VERBOSE("%s: place %d read %x\n", __func__,
block_size - block_size_read, *p_block);
p_block++;
block_size_read--;
}
return 0;
}
static int marvell_i2c_data_transmit(uint8_t *p_block, uint32_t block_size)
{
uint32_t status, block_size_write = block_size;
if (marvell_i2c_wait_interrupt()) {
ERROR("Start clear bit timeout\n");
return -ETIMEDOUT;
}
while (block_size_write) {
/* write the data */
mmio_write_32((uintptr_t)&base->data, (uint32_t) *p_block);
VERBOSE("%s: index = %d, data = %x\n", __func__,
block_size - block_size_write, *p_block);
p_block++;
block_size_write--;
marvell_i2c_interrupt_clear();
if (marvell_i2c_wait_interrupt()) {
ERROR("Start clear bit timeout\n");
return -ETIMEDOUT;
}
/* check the status */
if (marvell_i2c_lost_arbitration(&status)) {
ERROR("%s - %d: Lost arbitration, got status %x\n",
__func__, __LINE__, status);
return -EAGAIN;
}
if (status != I2C_STATUS_DATA_W_ACK) {
ERROR("Status %x in write transaction\n", status);
return -EPERM;
}
}
return 0;
}
static int marvell_i2c_target_offset_set(uint8_t chip, uint32_t addr, int alen)
{
uint8_t off_block[2];
uint32_t off_size;
if (alen == 2) { /* 2-byte addresses support */
off_block[0] = (addr >> 8) & 0xff;
off_block[1] = addr & 0xff;
off_size = 2;
} else { /* 1-byte addresses support */
off_block[0] = addr & 0xff;
off_size = 1;
}
VERBOSE("%s: off_size = %x addr1 = %x addr2 = %x\n", __func__,
off_size, off_block[0], off_block[1]);
return marvell_i2c_data_transmit(off_block, off_size);
}
static int marvell_i2c_unstuck(int ret)
{
uint32_t v;
if (ret != -ETIMEDOUT)
return ret;
VERBOSE("Trying to \"unstuck i2c\"... ");
i2c_init(base);
mmio_write_32((uintptr_t)&base->unstuck, I2C_UNSTUCK_TRIGGER);
do {
v = mmio_read_32((uintptr_t)&base->unstuck);
} while (v & I2C_UNSTUCK_ONGOING);
if (v & I2C_UNSTUCK_ERROR) {
VERBOSE("failed - soft reset i2c\n");
ret = -EPERM;
} else {
VERBOSE("ok\n");
i2c_init(base);
ret = -EAGAIN;
}
return ret;
}
/*
* API Functions
*/
void i2c_init(void *i2c_base)
{
/* For I2C speed and slave address, now we do not set them since
* we just provide the working speed and slave address in plat_def.h
* for i2c_init
*/
base = (struct marvell_i2c_regs *)i2c_base;
/* Reset the I2C logic */
mmio_write_32((uintptr_t)&base->soft_reset, 0);
udelay(200);
marvell_i2c_bus_speed_set(CONFIG_SYS_I2C_SPEED);
/* Enable the I2C and slave */
mmio_write_32((uintptr_t)&base->control,
I2C_CONTROL_TWSIEN | I2C_CONTROL_ACK);
/* set the I2C slave address */
mmio_write_32((uintptr_t)&base->xtnd_slave_addr, 0);
mmio_write_32((uintptr_t)&base->slave_address, CONFIG_SYS_I2C_SLAVE);
/* unmask I2C interrupt */
mmio_write_32((uintptr_t)&base->control,
mmio_read_32((uintptr_t)&base->control) |
I2C_CONTROL_INTEN);
udelay(10);
}
/*
* i2c_read: - Read multiple bytes from an i2c device
*
* The higher level routines take into account that this function is only
* called with len < page length of the device (see configuration file)
*
* @chip: address of the chip which is to be read
* @addr: i2c data address within the chip
* @alen: length of the i2c data address (1..2 bytes)
* @buffer: where to write the data
* @len: how much byte do we want to read
* @return: 0 in case of success
*/
int i2c_read(uint8_t chip, uint32_t addr, int alen, uint8_t *buffer, int len)
{
int ret = 0;
uint32_t counter = 0;
#ifdef DEBUG_I2C
marvell_i2c_probe(chip);
#endif
do {
if (ret != -EAGAIN && ret) {
ERROR("i2c transaction failed, after %d retries\n",
counter);
marvell_i2c_stop_bit_set();
return ret;
}
/* wait for 1 us for the interrupt clear to take effect */
if (counter > 0)
udelay(1);
counter++;
ret = marvell_i2c_start_bit_set();
if (ret) {
ret = marvell_i2c_unstuck(ret);
continue;
}
/* if EEPROM device */
if (alen != 0) {
ret = marvell_i2c_address_set(chip, I2C_CMD_WRITE);
if (ret)
continue;
ret = marvell_i2c_target_offset_set(chip, addr, alen);
if (ret)
continue;
ret = marvell_i2c_start_bit_set();
if (ret)
continue;
}
ret = marvell_i2c_address_set(chip, I2C_CMD_READ);
if (ret)
continue;
ret = marvell_i2c_data_receive(buffer, len);
if (ret)
continue;
ret = marvell_i2c_stop_bit_set();
} while ((ret == -EAGAIN) && (counter < I2C_MAX_RETRY_CNT));
if (counter == I2C_MAX_RETRY_CNT) {
ERROR("I2C transactions failed, got EAGAIN %d times\n",
I2C_MAX_RETRY_CNT);
ret = -EPERM;
}
mmio_write_32((uintptr_t)&base->control,
mmio_read_32((uintptr_t)&base->control) |
I2C_CONTROL_ACK);
udelay(1);
return ret;
}
/*
* i2c_write: - Write multiple bytes to an i2c device
*
* The higher level routines take into account that this function is only
* called with len < page length of the device (see configuration file)
*
* @chip: address of the chip which is to be written
* @addr: i2c data address within the chip
* @alen: length of the i2c data address (1..2 bytes)
* @buffer: where to find the data to be written
* @len: how much byte do we want to read
* @return: 0 in case of success
*/
int i2c_write(uint8_t chip, uint32_t addr, int alen, uint8_t *buffer, int len)
{
int ret = 0;
uint32_t counter = 0;
do {
if (ret != -EAGAIN && ret) {
ERROR("i2c transaction failed\n");
marvell_i2c_stop_bit_set();
return ret;
}
/* wait for 1 us for the interrupt clear to take effect */
if (counter > 0)
udelay(1);
counter++;
ret = marvell_i2c_start_bit_set();
if (ret) {
ret = marvell_i2c_unstuck(ret);
continue;
}
ret = marvell_i2c_address_set(chip, I2C_CMD_WRITE);
if (ret)
continue;
/* if EEPROM device */
if (alen != 0) {
ret = marvell_i2c_target_offset_set(chip, addr, alen);
if (ret)
continue;
}
ret = marvell_i2c_data_transmit(buffer, len);
if (ret)
continue;
ret = marvell_i2c_stop_bit_set();
} while ((ret == -EAGAIN) && (counter < I2C_MAX_RETRY_CNT));
if (counter == I2C_MAX_RETRY_CNT) {
ERROR("I2C transactions failed, got EAGAIN %d times\n",
I2C_MAX_RETRY_CNT);
ret = -EPERM;
}
udelay(1);
return ret;
}
/*
* Copyright (C) 2018 Marvell International Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
* https://spdx.org/licenses
*/
/* IO Window unit device driver for Marvell AP807, AP807 and AP810 SoCs */
#include <a8k_common.h>
#include <debug.h>
#include <io_win.h>
#include <mmio.h>
#include <mvebu.h>
#include <mvebu_def.h>
#if LOG_LEVEL >= LOG_LEVEL_INFO
#define DEBUG_ADDR_MAP
#endif
/* common defines */
#define WIN_ENABLE_BIT (0x1)
/* Physical address of the base of the window = {Addr[19:0],20`h0} */
#define ADDRESS_SHIFT (20 - 4)
#define ADDRESS_MASK (0xFFFFFFF0)
#define IO_WIN_ALIGNMENT_1M (0x100000)
#define IO_WIN_ALIGNMENT_64K (0x10000)
/* AP registers */
#define IO_WIN_ALR_OFFSET(ap, win) (MVEBU_IO_WIN_BASE(ap) + 0x0 + \
(0x10 * win))
#define IO_WIN_AHR_OFFSET(ap, win) (MVEBU_IO_WIN_BASE(ap) + 0x8 + \
(0x10 * win))
#define IO_WIN_CR_OFFSET(ap, win) (MVEBU_IO_WIN_BASE(ap) + 0xC + \
(0x10 * win))
/* For storage of CR, ALR, AHR abd GCR */
static uint32_t io_win_regs_save[MVEBU_IO_WIN_MAX_WINS * 3 + 1];
static void io_win_check(struct addr_map_win *win)
{
/* for IO The base is always 1M aligned */
/* check if address is aligned to 1M */
if (IS_NOT_ALIGN(win->base_addr, IO_WIN_ALIGNMENT_1M)) {
win->base_addr = ALIGN_UP(win->base_addr, IO_WIN_ALIGNMENT_1M);
NOTICE("%s: Align up the base address to 0x%llx\n",
__func__, win->base_addr);
}
/* size parameter validity check */
if (IS_NOT_ALIGN(win->win_size, IO_WIN_ALIGNMENT_1M)) {
win->win_size = ALIGN_UP(win->win_size, IO_WIN_ALIGNMENT_1M);
NOTICE("%s: Aligning size to 0x%llx\n",
__func__, win->win_size);
}
}
static void io_win_enable_window(int ap_index, struct addr_map_win *win,
uint32_t win_num)
{
uint32_t alr, ahr;
uint64_t end_addr;
if (win->target_id < 0 || win->target_id >= MVEBU_IO_WIN_MAX_WINS) {
ERROR("target ID = %d, is invalid\n", win->target_id);
return;
}
if ((win_num == 0) || (win_num > MVEBU_IO_WIN_MAX_WINS)) {
ERROR("Enabling wrong IOW window %d!\n", win_num);
return;
}
/* calculate the end-address */
end_addr = (win->base_addr + win->win_size - 1);
alr = (uint32_t)((win->base_addr >> ADDRESS_SHIFT) & ADDRESS_MASK);
alr |= WIN_ENABLE_BIT;
ahr = (uint32_t)((end_addr >> ADDRESS_SHIFT) & ADDRESS_MASK);
/* write start address and end address for IO window */
mmio_write_32(IO_WIN_ALR_OFFSET(ap_index, win_num), alr);
mmio_write_32(IO_WIN_AHR_OFFSET(ap_index, win_num), ahr);
/* write window target */
mmio_write_32(IO_WIN_CR_OFFSET(ap_index, win_num), win->target_id);
}
static void io_win_disable_window(int ap_index, uint32_t win_num)
{
uint32_t win_reg;
if ((win_num == 0) || (win_num > MVEBU_IO_WIN_MAX_WINS)) {
ERROR("Disabling wrong IOW window %d!\n", win_num);
return;
}
win_reg = mmio_read_32(IO_WIN_ALR_OFFSET(ap_index, win_num));
win_reg &= ~WIN_ENABLE_BIT;
mmio_write_32(IO_WIN_ALR_OFFSET(ap_index, win_num), win_reg);
}
/* Insert/Remove temporary window for using the out-of reset default
* CPx base address to access the CP configuration space prior to
* the further base address update in accordance with address mapping
* design.
*
* NOTE: Use the same window array for insertion and removal of
* temporary windows.
*/
void iow_temp_win_insert(int ap_index, struct addr_map_win *win, int size)
{
uint32_t win_id;
for (int i = 0; i < size; i++) {
win_id = MVEBU_IO_WIN_MAX_WINS - i - 1;
io_win_check(win);
io_win_enable_window(ap_index, win, win_id);
win++;
}
}
/*
* NOTE: Use the same window array for insertion and removal of
* temporary windows.
*/
void iow_temp_win_remove(int ap_index, struct addr_map_win *win, int size)
{
uint32_t win_id;
/* Start from the last window and do not touch Win0 */
for (int i = 0; i < size; i++) {
uint64_t base;
uint32_t target;
win_id = MVEBU_IO_WIN_MAX_WINS - i - 1;
target = mmio_read_32(IO_WIN_CR_OFFSET(ap_index, win_id));
base = mmio_read_32(IO_WIN_ALR_OFFSET(ap_index, win_id));
base &= ~WIN_ENABLE_BIT;
base <<= ADDRESS_SHIFT;
if ((win->target_id != target) || (win->base_addr != base)) {
ERROR("%s: Trying to remove bad window-%d!\n",
__func__, win_id);
continue;
}
io_win_disable_window(ap_index, win_id);
win++;
}
}
#ifdef DEBUG_ADDR_MAP
static void dump_io_win(int ap_index)
{
uint32_t trgt_id, win_id;
uint32_t alr, ahr;
uint64_t start, end;
/* Dump all IO windows */
tf_printf("\tbank target start end\n");
tf_printf("\t----------------------------------------------------\n");
for (win_id = 0; win_id < MVEBU_IO_WIN_MAX_WINS; win_id++) {
alr = mmio_read_32(IO_WIN_ALR_OFFSET(ap_index, win_id));
if (alr & WIN_ENABLE_BIT) {
alr &= ~WIN_ENABLE_BIT;
ahr = mmio_read_32(IO_WIN_AHR_OFFSET(ap_index, win_id));
trgt_id = mmio_read_32(IO_WIN_CR_OFFSET(ap_index,
win_id));
start = ((uint64_t)alr << ADDRESS_SHIFT);
end = (((uint64_t)ahr + 0x10) << ADDRESS_SHIFT);
tf_printf("\tio-win %d 0x%016llx 0x%016llx\n",
trgt_id, start, end);
}
}
tf_printf("\tio-win gcr is %x\n",
mmio_read_32(MVEBU_IO_WIN_BASE(ap_index) +
MVEBU_IO_WIN_GCR_OFFSET));
}
#endif
static void iow_save_win_range(int ap_id, int win_first, int win_last,
uint32_t *buffer)
{
int win_id, idx;
/* Save IOW */
for (idx = 0, win_id = win_first; win_id <= win_last; win_id++) {
buffer[idx++] = mmio_read_32(IO_WIN_CR_OFFSET(ap_id, win_id));
buffer[idx++] = mmio_read_32(IO_WIN_ALR_OFFSET(ap_id, win_id));
buffer[idx++] = mmio_read_32(IO_WIN_AHR_OFFSET(ap_id, win_id));
}
buffer[idx] = mmio_read_32(MVEBU_IO_WIN_BASE(ap_id) +
MVEBU_IO_WIN_GCR_OFFSET);
}
static void iow_restore_win_range(int ap_id, int win_first, int win_last,
uint32_t *buffer)
{
int win_id, idx;
/* Restore IOW */
for (idx = 0, win_id = win_first; win_id <= win_last; win_id++) {
mmio_write_32(IO_WIN_CR_OFFSET(ap_id, win_id), buffer[idx++]);
mmio_write_32(IO_WIN_ALR_OFFSET(ap_id, win_id), buffer[idx++]);
mmio_write_32(IO_WIN_AHR_OFFSET(ap_id, win_id), buffer[idx++]);
}
mmio_write_32(MVEBU_IO_WIN_BASE(ap_id) + MVEBU_IO_WIN_GCR_OFFSET,
buffer[idx++]);
}
void iow_save_win_all(int ap_id)
{
iow_save_win_range(ap_id, 0, MVEBU_IO_WIN_MAX_WINS - 1,
io_win_regs_save);
}
void iow_restore_win_all(int ap_id)
{
iow_restore_win_range(ap_id, 0, MVEBU_IO_WIN_MAX_WINS - 1,
io_win_regs_save);
}
int init_io_win(int ap_index)
{
struct addr_map_win *win;
uint32_t win_id, win_reg;
uint32_t win_count;
INFO("Initializing IO WIN Address decoding\n");
/* Get the array of the windows and its size */
marvell_get_io_win_memory_map(ap_index, &win, &win_count);
if (win_count <= 0)
INFO("no windows configurations found\n");
if (win_count > MVEBU_IO_WIN_MAX_WINS) {
INFO("number of windows is bigger than %d\n",
MVEBU_IO_WIN_MAX_WINS);
return 0;
}
/* Get the default target id to set the GCR */
win_reg = marvell_get_io_win_gcr_target(ap_index);
mmio_write_32(MVEBU_IO_WIN_BASE(ap_index) + MVEBU_IO_WIN_GCR_OFFSET,
win_reg);
/* disable all IO windows */
for (win_id = 1; win_id < MVEBU_IO_WIN_MAX_WINS; win_id++)
io_win_disable_window(ap_index, win_id);
/* enable relevant windows, starting from win_id = 1 because
* index 0 dedicated for BootROM
*/
for (win_id = 1; win_id <= win_count; win_id++, win++) {
io_win_check(win);
io_win_enable_window(ap_index, win, win_id);
}
#ifdef DEBUG_ADDR_MAP
dump_io_win(ap_index);
#endif
INFO("Done IO WIN Address decoding Initializing\n");
return 0;
}
/*
* Copyright (C) 2016 - 2018 Marvell International Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
* https://spdx.org/licenses
*/
/* IOW unit device driver for Marvell CP110 and CP115 SoCs */
#include <a8k_common.h>
#include <arch_helpers.h>
#include <debug.h>
#include <iob.h>
#include <mmio.h>
#include <mvebu.h>
#include <mvebu_def.h>
#if LOG_LEVEL >= LOG_LEVEL_INFO
#define DEBUG_ADDR_MAP
#endif
#define MVEBU_IOB_OFFSET (0x190000)
#define MVEBU_IOB_MAX_WINS 16
/* common defines */
#define WIN_ENABLE_BIT (0x1)
/* Physical address of the base of the window = {AddrLow[19:0],20`h0} */
#define ADDRESS_SHIFT (20 - 4)
#define ADDRESS_MASK (0xFFFFFFF0)
#define IOB_WIN_ALIGNMENT (0x100000)
/* IOB registers */
#define IOB_WIN_CR_OFFSET(win) (iob_base + 0x0 + (0x20 * win))
#define IOB_TARGET_ID_OFFSET (8)
#define IOB_TARGET_ID_MASK (0xF)
#define IOB_WIN_SCR_OFFSET(win) (iob_base + 0x4 + (0x20 * win))
#define IOB_WIN_ENA_CTRL_WRITE_SECURE (0x1)
#define IOB_WIN_ENA_CTRL_READ_SECURE (0x2)
#define IOB_WIN_ENA_WRITE_SECURE (0x4)
#define IOB_WIN_ENA_READ_SECURE (0x8)
#define IOB_WIN_ALR_OFFSET(win) (iob_base + 0x8 + (0x20 * win))
#define IOB_WIN_AHR_OFFSET(win) (iob_base + 0xC + (0x20 * win))
uintptr_t iob_base;
static void iob_win_check(struct addr_map_win *win, uint32_t win_num)
{
/* check if address is aligned to the size */
if (IS_NOT_ALIGN(win->base_addr, IOB_WIN_ALIGNMENT)) {
win->base_addr = ALIGN_UP(win->base_addr, IOB_WIN_ALIGNMENT);
ERROR("Window %d: base address unaligned to 0x%x\n",
win_num, IOB_WIN_ALIGNMENT);
tf_printf("Align up the base address to 0x%llx\n",
win->base_addr);
}
/* size parameter validity check */
if (IS_NOT_ALIGN(win->win_size, IOB_WIN_ALIGNMENT)) {
win->win_size = ALIGN_UP(win->win_size, IOB_WIN_ALIGNMENT);
ERROR("Window %d: window size unaligned to 0x%x\n", win_num,
IOB_WIN_ALIGNMENT);
tf_printf("Aligning size to 0x%llx\n", win->win_size);
}
}
static void iob_enable_win(struct addr_map_win *win, uint32_t win_id)
{
uint32_t iob_win_reg;
uint32_t alr, ahr;
uint64_t end_addr;
end_addr = (win->base_addr + win->win_size - 1);
alr = (uint32_t)((win->base_addr >> ADDRESS_SHIFT) & ADDRESS_MASK);
ahr = (uint32_t)((end_addr >> ADDRESS_SHIFT) & ADDRESS_MASK);
mmio_write_32(IOB_WIN_ALR_OFFSET(win_id), alr);
mmio_write_32(IOB_WIN_AHR_OFFSET(win_id), ahr);
iob_win_reg = WIN_ENABLE_BIT;
iob_win_reg |= (win->target_id & IOB_TARGET_ID_MASK)
<< IOB_TARGET_ID_OFFSET;
mmio_write_32(IOB_WIN_CR_OFFSET(win_id), iob_win_reg);
}
#ifdef DEBUG_ADDR_MAP
static void dump_iob(void)
{
uint32_t win_id, win_cr, alr, ahr;
uint8_t target_id;
uint64_t start, end;
char *iob_target_name[IOB_MAX_TID] = {
"CFG ", "MCI0 ", "PEX1 ", "PEX2 ",
"PEX0 ", "NAND ", "RUNIT", "MCI1 " };
/* Dump all IOB windows */
tf_printf("bank id target start end\n");
tf_printf("----------------------------------------------------\n");
for (win_id = 0; win_id < MVEBU_IOB_MAX_WINS; win_id++) {
win_cr = mmio_read_32(IOB_WIN_CR_OFFSET(win_id));
if (win_cr & WIN_ENABLE_BIT) {
target_id = (win_cr >> IOB_TARGET_ID_OFFSET) &
IOB_TARGET_ID_MASK;
alr = mmio_read_32(IOB_WIN_ALR_OFFSET(win_id));
start = ((uint64_t)alr << ADDRESS_SHIFT);
if (win_id != 0) {
ahr = mmio_read_32(IOB_WIN_AHR_OFFSET(win_id));
end = (((uint64_t)ahr + 0x10) << ADDRESS_SHIFT);
} else {
/* Window #0 size is hardcoded to 16MB, as it's
* reserved for CP configuration space.
*/
end = start + (16 << 20);
}
tf_printf("iob %02d %s 0x%016llx 0x%016llx\n",
win_id, iob_target_name[target_id],
start, end);
}
}
}
#endif
void iob_cfg_space_update(int ap_idx, int cp_idx, uintptr_t base,
uintptr_t new_base)
{
debug_enter();
iob_base = base + MVEBU_IOB_OFFSET;
NOTICE("Change the base address of AP%d-CP%d to %lx\n",
ap_idx, cp_idx, new_base);
mmio_write_32(IOB_WIN_ALR_OFFSET(0), new_base >> ADDRESS_SHIFT);
iob_base = new_base + MVEBU_IOB_OFFSET;
/* Make sure the address was configured by the CPU before
* any possible access to the CP.
*/
dsb();
debug_exit();
}
int init_iob(uintptr_t base)
{
struct addr_map_win *win;
uint32_t win_id, win_reg;
uint32_t win_count;
INFO("Initializing IOB Address decoding\n");
/* Get the base address of the address decoding MBUS */
iob_base = base + MVEBU_IOB_OFFSET;
/* Get the array of the windows and fill the map data */
marvell_get_iob_memory_map(&win, &win_count, base);
if (win_count <= 0) {
INFO("no windows configurations found\n");
return 0;
} else if (win_count > (MVEBU_IOB_MAX_WINS - 1)) {
ERROR("IOB mem map array > than max available windows (%d)\n",
MVEBU_IOB_MAX_WINS);
win_count = MVEBU_IOB_MAX_WINS;
}
/* disable all IOB windows, start from win_id = 1
* because can't disable internal register window
*/
for (win_id = 1; win_id < MVEBU_IOB_MAX_WINS; win_id++) {
win_reg = mmio_read_32(IOB_WIN_CR_OFFSET(win_id));
win_reg &= ~WIN_ENABLE_BIT;
mmio_write_32(IOB_WIN_CR_OFFSET(win_id), win_reg);
win_reg = ~IOB_WIN_ENA_CTRL_WRITE_SECURE;
win_reg &= ~IOB_WIN_ENA_CTRL_READ_SECURE;
win_reg &= ~IOB_WIN_ENA_WRITE_SECURE;
win_reg &= ~IOB_WIN_ENA_READ_SECURE;
mmio_write_32(IOB_WIN_SCR_OFFSET(win_id), win_reg);
}
for (win_id = 1; win_id < win_count + 1; win_id++, win++) {
iob_win_check(win, win_id);
iob_enable_win(win, win_id);
}
#ifdef DEBUG_ADDR_MAP
dump_iob();
#endif
INFO("Done IOB Address decoding Initializing\n");
return 0;
}
/*
* Copyright (C) 2018 Marvell International Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
* https://spdx.org/licenses
*/
/* MCI bus driver for Marvell ARMADA 8K and 8K+ SoCs */
#include <debug.h>
#include <delay_timer.h>
#include <mmio.h>
#include <mci.h>
#include <mvebu.h>
#include <mvebu_def.h>
#include <plat_marvell.h>
/* /HB /Units /Direct_regs /Direct regs
* /Configuration Register Write/Read Data Register
*/
#define MCI_WRITE_READ_DATA_REG(mci_index) \
MVEBU_MCI_REG_BASE_REMAP(mci_index)
/* /HB /Units /Direct_regs /Direct regs
* /Configuration Register Access Command Register
*/
#define MCI_ACCESS_CMD_REG(mci_index) \
(MVEBU_MCI_REG_BASE_REMAP(mci_index) + 0x4)
/* Access Command fields :
* bit[3:0] - Sub command: 1 => Peripheral Config Register Read,
* 0 => Peripheral Config Register Write,
* 2 => Peripheral Assign ID request,
* 3 => Circular Config Write
* bit[5] - 1 => Local (same chip access) 0 => Remote
* bit[15:8] - Destination hop ID. Put Global ID (GID) here (see scheme below).
* bit[23:22] - 0x3 IHB PHY REG address space, 0x0 IHB Controller space
* bit[21:16] - Low 6 bits of offset. Hight 2 bits are taken from bit[28:27]
* of IHB_PHY_CTRL
* (must be set before any PHY register access occurs):
* /IHB_REG /IHB_REGInterchip Hopping Bus Registers
* /IHB Version Control Register
*
* ixi_ihb_top IHB PHY
* AXI ----------------------------- -------------
* <--| axi_hb_top | ihb_pipe_top |-->| |
* -->| GID=1 | GID=0 |<--| |
* ----------------------------- -------------
*/
#define MCI_INDIRECT_CTRL_READ_CMD 0x1
#define MCI_INDIRECT_CTRL_ASSIGN_CMD 0x2
#define MCI_INDIRECT_CTRL_CIRCULAR_CMD 0x3
#define MCI_INDIRECT_CTRL_LOCAL_PKT (1 << 5)
#define MCI_INDIRECT_CTRL_CMD_DONE_OFFSET 6
#define MCI_INDIRECT_CTRL_CMD_DONE \
(1 << MCI_INDIRECT_CTRL_CMD_DONE_OFFSET)
#define MCI_INDIRECT_CTRL_DATA_READY_OFFSET 7
#define MCI_INDIRECT_CTRL_DATA_READY \
(1 << MCI_INDIRECT_CTRL_DATA_READY_OFFSET)
#define MCI_INDIRECT_CTRL_HOPID_OFFSET 8
#define MCI_INDIRECT_CTRL_HOPID(id) \
(((id) & 0xFF) << MCI_INDIRECT_CTRL_HOPID_OFFSET)
#define MCI_INDIRECT_CTRL_REG_CHIPID_OFFSET 16
#define MCI_INDIRECT_REG_CTRL_ADDR(reg_num) \
(reg_num << MCI_INDIRECT_CTRL_REG_CHIPID_OFFSET)
/* Hop ID values */
#define GID_IHB_PIPE 0
#define GID_AXI_HB 1
#define GID_IHB_EXT 2
#define MCI_DID_GLOBAL_ASSIGNMENT_REQUEST_REG 0x2
/* Target MCi Local ID (LID, which is = self DID) */
#define MCI_DID_GLOBAL_ASSIGN_REQ_MCI_LOCAL_ID(val) (((val) & 0xFF) << 16)
/* Bits [15:8]: Number of MCis on chip of target MCi */
#define MCI_DID_GLOBAL_ASSIGN_REQ_MCI_COUNT(val) (((val) & 0xFF) << 8)
/* Bits [7:0]: Number of hops on chip of target MCi */
#define MCI_DID_GLOBAL_ASSIGN_REQ_HOPS_NUM(val) (((val) & 0xFF) << 0)
/* IHB_REG domain registers */
/* /HB /Units /IHB_REG /IHB_REGInterchip Hopping Bus Registers/
* Rx Memory Configuration Register (RX_MEM_CFG)
*/
#define MCI_CTRL_RX_MEM_CFG_REG_NUM 0x0
#define MCI_CTRL_RX_TX_MEM_CFG_RQ_THRESH(val) (((val) & 0xFF) << 24)
#define MCI_CTRL_RX_TX_MEM_CFG_PQ_THRESH(val) (((val) & 0xFF) << 16)
#define MCI_CTRL_RX_TX_MEM_CFG_NQ_THRESH(val) (((val) & 0xFF) << 8)
#define MCI_CTRL_RX_TX_MEM_CFG_DELTA_THRESH(val) (((val) & 0xF) << 4)
#define MCI_CTRL_RX_TX_MEM_CFG_RTC(val) (((val) & 0x3) << 2)
#define MCI_CTRL_RX_TX_MEM_CFG_WTC(val) (((val) & 0x3) << 0)
#define MCI_CTRL_RX_MEM_CFG_REG_DEF_CP_VAL \
(MCI_CTRL_RX_TX_MEM_CFG_RQ_THRESH(0x07) | \
MCI_CTRL_RX_TX_MEM_CFG_PQ_THRESH(0x3f) | \
MCI_CTRL_RX_TX_MEM_CFG_NQ_THRESH(0x3f) | \
MCI_CTRL_RX_TX_MEM_CFG_DELTA_THRESH(0xf) | \
MCI_CTRL_RX_TX_MEM_CFG_RTC(1) | \
MCI_CTRL_RX_TX_MEM_CFG_WTC(1))
#define MCI_CTRL_RX_MEM_CFG_REG_DEF_AP_VAL \
(MCI_CTRL_RX_TX_MEM_CFG_RQ_THRESH(0x3f) | \
MCI_CTRL_RX_TX_MEM_CFG_PQ_THRESH(0x03) | \
MCI_CTRL_RX_TX_MEM_CFG_NQ_THRESH(0x3f) | \
MCI_CTRL_RX_TX_MEM_CFG_DELTA_THRESH(0xf) | \
MCI_CTRL_RX_TX_MEM_CFG_RTC(1) | \
MCI_CTRL_RX_TX_MEM_CFG_WTC(1))
/* /HB /Units /IHB_REG /IHB_REGInterchip Hopping Bus Registers/
* Tx Memory Configuration Register (TX_MEM_CFG)
*/
#define MCI_CTRL_TX_MEM_CFG_REG_NUM 0x1
/* field mapping for TX mem config register
* are the same as for RX register - see register above
*/
#define MCI_CTRL_TX_MEM_CFG_REG_DEF_VAL \
(MCI_CTRL_RX_TX_MEM_CFG_RQ_THRESH(0x20) | \
MCI_CTRL_RX_TX_MEM_CFG_PQ_THRESH(0x20) | \
MCI_CTRL_RX_TX_MEM_CFG_NQ_THRESH(0x20) | \
MCI_CTRL_RX_TX_MEM_CFG_DELTA_THRESH(2) | \
MCI_CTRL_RX_TX_MEM_CFG_RTC(1) | \
MCI_CTRL_RX_TX_MEM_CFG_WTC(1))
/* /HB /Units /IHB_REG /IHB_REGInterchip Hopping Bus Registers
* /IHB Link CRC Control
*/
/* MCi Link CRC Control Register (MCi_CRC_CTRL) */
#define MCI_LINK_CRC_CTRL_REG_NUM 0x4
/* /HB /Units /IHB_REG /IHB_REGInterchip Hopping Bus Registers
* /IHB Status Register
*/
/* MCi Status Register (MCi_STS) */
#define MCI_CTRL_STATUS_REG_NUM 0x5
#define MCI_CTRL_STATUS_REG_PHY_READY (1 << 12)
#define MCI_CTRL_STATUS_REG_LINK_PRESENT (1 << 15)
#define MCI_CTRL_STATUS_REG_PHY_CID_VIO_OFFSET 24
#define MCI_CTRL_STATUS_REG_PHY_CID_VIO_MASK \
(0xF << MCI_CTRL_STATUS_REG_PHY_CID_VIO_OFFSET)
/* Expected successful Link result, including reserved bit */
#define MCI_CTRL_PHY_READY (MCI_CTRL_STATUS_REG_PHY_READY | \
MCI_CTRL_STATUS_REG_LINK_PRESENT | \
MCI_CTRL_STATUS_REG_PHY_CID_VIO_MASK)
/* /HB /Units /IHB_REG /IHB_REGInterchip Hopping Bus Registers/
* MCi PHY Speed Settings Register (MCi_PHY_SETTING)
*/
#define MCI_CTRL_MCI_PHY_SETTINGS_REG_NUM 0x8
#define MCI_CTRL_MCI_PHY_SET_DLO_FIFO_FULL_TRESH(val) (((val) & 0xF) << 28)
#define MCI_CTRL_MCI_PHY_SET_PHY_MAX_SPEED(val) (((val) & 0xF) << 12)
#define MCI_CTRL_MCI_PHY_SET_PHYCLK_SEL(val) (((val) & 0xF) << 8)
#define MCI_CTRL_MCI_PHY_SET_REFCLK_FREQ_SEL(val) (((val) & 0xF) << 4)
#define MCI_CTRL_MCI_PHY_SET_AUTO_LINK_EN(val) (((val) & 0x1) << 1)
#define MCI_CTRL_MCI_PHY_SET_REG_DEF_VAL \
(MCI_CTRL_MCI_PHY_SET_DLO_FIFO_FULL_TRESH(0x3) | \
MCI_CTRL_MCI_PHY_SET_PHY_MAX_SPEED(0x3) | \
MCI_CTRL_MCI_PHY_SET_PHYCLK_SEL(0x2) | \
MCI_CTRL_MCI_PHY_SET_REFCLK_FREQ_SEL(0x1))
#define MCI_CTRL_MCI_PHY_SET_REG_DEF_VAL2 \
(MCI_CTRL_MCI_PHY_SET_DLO_FIFO_FULL_TRESH(0x3) | \
MCI_CTRL_MCI_PHY_SET_PHY_MAX_SPEED(0x3) | \
MCI_CTRL_MCI_PHY_SET_PHYCLK_SEL(0x5) | \
MCI_CTRL_MCI_PHY_SET_REFCLK_FREQ_SEL(0x1))
/* /HB /Units /IHB_REG /IHB_REGInterchip Hopping Bus Registers
* /IHB Mode Config
*/
#define MCI_CTRL_IHB_MODE_CFG_REG_NUM 0x25
#define MCI_CTRL_IHB_MODE_HBCLK_DIV(val) ((val) & 0xFF)
#define MCI_CTRL_IHB_MODE_CHUNK_MOD_OFFSET 8
#define MCI_CTRL_IHB_MODE_CHUNK_MOD \
(1 << MCI_CTRL_IHB_MODE_CHUNK_MOD_OFFSET)
#define MCI_CTRL_IHB_MODE_FWD_MOD_OFFSET 9
#define MCI_CTRL_IHB_MODE_FWD_MOD \
(1 << MCI_CTRL_IHB_MODE_FWD_MOD_OFFSET)
#define MCI_CTRL_IHB_MODE_SEQFF_FINE_MOD(val) (((val) & 0xF) << 12)
#define MCI_CTRL_IHB_MODE_RX_COMB_THRESH(val) (((val) & 0xFF) << 16)
#define MCI_CTRL_IHB_MODE_TX_COMB_THRESH(val) (((val) & 0xFF) << 24)
#define MCI_CTRL_IHB_MODE_CFG_REG_DEF_VAL \
(MCI_CTRL_IHB_MODE_HBCLK_DIV(6) | \
MCI_CTRL_IHB_MODE_FWD_MOD | \
MCI_CTRL_IHB_MODE_SEQFF_FINE_MOD(0xF) | \
MCI_CTRL_IHB_MODE_RX_COMB_THRESH(0x3f) | \
MCI_CTRL_IHB_MODE_TX_COMB_THRESH(0x40))
/* AXI_HB registers */
#define MCI_AXI_ACCESS_DATA_REG_NUM 0x0
#define MCI_AXI_ACCESS_PCIE_MODE 1
#define MCI_AXI_ACCESS_CACHE_CHECK_OFFSET 5
#define MCI_AXI_ACCESS_CACHE_CHECK \
(1 << MCI_AXI_ACCESS_CACHE_CHECK_OFFSET)
#define MCI_AXI_ACCESS_FORCE_POST_WR_OFFSET 6
#define MCI_AXI_ACCESS_FORCE_POST_WR \
(1 << MCI_AXI_ACCESS_FORCE_POST_WR_OFFSET)
#define MCI_AXI_ACCESS_DISABLE_CLK_GATING_OFFSET 9
#define MCI_AXI_ACCESS_DISABLE_CLK_GATING \
(1 << MCI_AXI_ACCESS_DISABLE_CLK_GATING_OFFSET)
/* /HB /Units /HB_REG /HB_REGHopping Bus Registers
* /Window 0 Address Mask Register
*/
#define MCI_HB_CTRL_WIN0_ADDRESS_MASK_REG_NUM 0x2
/* /HB /Units /HB_REG /HB_REGHopping Bus Registers
* /Window 0 Destination Register
*/
#define MCI_HB_CTRL_WIN0_DESTINATION_REG_NUM 0x3
#define MCI_HB_CTRL_WIN0_DEST_VALID_FLAG(val) (((val) & 0x1) << 16)
#define MCI_HB_CTRL_WIN0_DEST_ID(val) (((val) & 0xFF) << 0)
/* /HB /Units /HB_REG /HB_REGHopping Bus Registers /Tx Control Register */
#define MCI_HB_CTRL_TX_CTRL_REG_NUM 0xD
#define MCI_HB_CTRL_TX_CTRL_PCIE_MODE_OFFSET 24
#define MCI_HB_CTRL_TX_CTRL_PCIE_MODE \
(1 << MCI_HB_CTRL_TX_CTRL_PCIE_MODE_OFFSET)
#define MCI_HB_CTRL_TX_CTRL_PRI_TH_QOS(val) (((val) & 0xF) << 12)
#define MCI_HB_CTRL_TX_CTRL_MAX_RD_CNT(val) (((val) & 0x1F) << 6)
#define MCI_HB_CTRL_TX_CTRL_MAX_WR_CNT(val) (((val) & 0x1F) << 0)
/* /HB /Units /IHB_REG /IHB_REGInterchip Hopping Bus Registers
* /IHB Version Control Register
*/
#define MCI_PHY_CTRL_REG_NUM 0x7
#define MCI_PHY_CTRL_MCI_MINOR 0x8 /* BITS [3:0] */
#define MCI_PHY_CTRL_MCI_MAJOR_OFFSET 4
#define MCI_PHY_CTRL_MCI_MAJOR \
(1 << MCI_PHY_CTRL_MCI_MAJOR_OFFSET)
#define MCI_PHY_CTRL_MCI_SLEEP_REQ_OFFSET 11
#define MCI_PHY_CTRL_MCI_SLEEP_REQ \
(1 << MCI_PHY_CTRL_MCI_SLEEP_REQ_OFFSET)
/* Host=1 / Device=0 PHY mode */
#define MCI_PHY_CTRL_MCI_PHY_MODE_OFFSET 24
#define MCI_PHY_CTRL_MCI_PHY_MODE_HOST \
(1 << MCI_PHY_CTRL_MCI_PHY_MODE_OFFSET)
/* Register=1 / PWM=0 interface */
#define MCI_PHY_CTRL_MCI_PHY_REG_IF_MODE_OFFSET 25
#define MCI_PHY_CTRL_MCI_PHY_REG_IF_MODE \
(1 << MCI_PHY_CTRL_MCI_PHY_REG_IF_MODE_OFFSET)
/* PHY code InReset=1 */
#define MCI_PHY_CTRL_MCI_PHY_RESET_CORE_OFFSET 26
#define MCI_PHY_CTRL_MCI_PHY_RESET_CORE \
(1 << MCI_PHY_CTRL_MCI_PHY_RESET_CORE_OFFSET)
#define MCI_PHY_CTRL_PHY_ADDR_MSB_OFFSET 27
#define MCI_PHY_CTRL_PHY_ADDR_MSB(addr) \
(((addr) & 0x3) << \
MCI_PHY_CTRL_PHY_ADDR_MSB_OFFSET)
#define MCI_PHY_CTRL_PIDI_MODE_OFFSET 31
#define MCI_PHY_CTRL_PIDI_MODE \
(1 << MCI_PHY_CTRL_PIDI_MODE_OFFSET)
/* Number of times to wait for the MCI link ready after MCI configurations
* Normally takes 34-35 successive reads
*/
#define LINK_READY_TIMEOUT 100
enum mci_register_type {
MCI_REG_TYPE_PHY = 0,
MCI_REG_TYPE_CTRL,
};
enum {
MCI_CMD_WRITE,
MCI_CMD_READ
};
/* Write wrapper callback for debug:
* will print written data in case LOG_LEVEL >= 40
*/
static void mci_mmio_write_32(uintptr_t addr, uint32_t value)
{
VERBOSE("Write:\t0x%x = 0x%x\n", (uint32_t)addr, value);
mmio_write_32(addr, value);
}
/* Read wrapper callback for debug:
* will print read data in case LOG_LEVEL >= 40
*/
static uint32_t mci_mmio_read_32(uintptr_t addr)
{
uint32_t value;
value = mmio_read_32(addr);
VERBOSE("Read:\t0x%x = 0x%x\n", (uint32_t)addr, value);
return value;
}
/* MCI indirect access command completion polling:
* Each write/read command done via MCI indirect registers must be polled
* for command completions status.
*
* Returns 1 in case of error
* Returns 0 in case of command completed successfully.
*/
static int mci_poll_command_completion(int mci_index, int command_type)
{
uint32_t mci_cmd_value = 0, retry_count = 100, ret = 0;
uint32_t completion_flags = MCI_INDIRECT_CTRL_CMD_DONE;
debug_enter();
/* Read commands require validating that requested data is ready */
if (command_type == MCI_CMD_READ)
completion_flags |= MCI_INDIRECT_CTRL_DATA_READY;
do {
/* wait 1 ms before each polling */
mdelay(1);
mci_cmd_value = mci_mmio_read_32(MCI_ACCESS_CMD_REG(mci_index));
} while (((mci_cmd_value & completion_flags) != completion_flags) &&
(retry_count-- > 0));
if (retry_count == 0) {
ERROR("%s: MCI command timeout (command status = 0x%x)\n",
__func__, mci_cmd_value);
ret = 1;
}
debug_exit();
return ret;
}
int mci_read(int mci_idx, uint32_t cmd, uint32_t *value)
{
int rval;
mci_mmio_write_32(MCI_ACCESS_CMD_REG(mci_idx), cmd);
rval = mci_poll_command_completion(mci_idx, MCI_CMD_READ);
*value = mci_mmio_read_32(MCI_WRITE_READ_DATA_REG(mci_idx));
return rval;
}
int mci_write(int mci_idx, uint32_t cmd, uint32_t data)
{
mci_mmio_write_32(MCI_WRITE_READ_DATA_REG(mci_idx), data);
mci_mmio_write_32(MCI_ACCESS_CMD_REG(mci_idx), cmd);
return mci_poll_command_completion(mci_idx, MCI_CMD_WRITE);
}
/* Perform 3 configurations in one command: PCI mode,
* queues separation and cache bit
*/
static int mci_axi_set_pcie_mode(int mci_index)
{
uint32_t reg_data, ret = 1;
debug_enter();
/* This configuration makes MCI IP behave consistently with AXI protocol
* It should be configured at one side only (for example locally at AP).
* The IP takes care of performing the same configurations at MCI on
* another side (for example remotely at CP).
*/
mci_mmio_write_32(MCI_WRITE_READ_DATA_REG(mci_index),
MCI_AXI_ACCESS_PCIE_MODE |
MCI_AXI_ACCESS_CACHE_CHECK |
MCI_AXI_ACCESS_FORCE_POST_WR |
MCI_AXI_ACCESS_DISABLE_CLK_GATING);
mci_mmio_write_32(MCI_ACCESS_CMD_REG(mci_index),
MCI_INDIRECT_REG_CTRL_ADDR(
MCI_AXI_ACCESS_DATA_REG_NUM) |
MCI_INDIRECT_CTRL_HOPID(GID_AXI_HB) |
MCI_INDIRECT_CTRL_LOCAL_PKT |
MCI_INDIRECT_CTRL_CIRCULAR_CMD);
/* if Write command was successful, verify PCIe mode */
if (mci_poll_command_completion(mci_index, MCI_CMD_WRITE) == 0) {
/* Verify the PCIe mode selected */
mci_mmio_write_32(MCI_ACCESS_CMD_REG(mci_index),
MCI_INDIRECT_REG_CTRL_ADDR(
MCI_HB_CTRL_TX_CTRL_REG_NUM) |
MCI_INDIRECT_CTRL_HOPID(GID_AXI_HB) |
MCI_INDIRECT_CTRL_LOCAL_PKT |
MCI_INDIRECT_CTRL_READ_CMD);
/* if read was completed, verify PCIe mode */
if (mci_poll_command_completion(mci_index, MCI_CMD_READ) == 0) {
reg_data = mci_mmio_read_32(
MCI_WRITE_READ_DATA_REG(mci_index));
if (reg_data & MCI_HB_CTRL_TX_CTRL_PCIE_MODE)
ret = 0;
}
}
debug_exit();
return ret;
}
/* Reduce sequence FIFO timer expiration threshold */
static int mci_axi_set_fifo_thresh(int mci_index)
{
uint32_t reg_data, ret = 0;
debug_enter();
/* This configuration reduces sequence FIFO timer expiration threshold
* (to 0x7 instead of 0xA).
* In MCI 1.6 version this configuration prevents possible functional
* issues.
* In version 1.82 the configuration prevents performance degradation
*/
/* Configure local AP side */
reg_data = MCI_PHY_CTRL_PIDI_MODE |
MCI_PHY_CTRL_MCI_PHY_REG_IF_MODE |
MCI_PHY_CTRL_MCI_PHY_MODE_HOST |
MCI_PHY_CTRL_MCI_MAJOR |
MCI_PHY_CTRL_MCI_MINOR;
mci_mmio_write_32(MCI_WRITE_READ_DATA_REG(mci_index), reg_data);
mci_mmio_write_32(MCI_ACCESS_CMD_REG(mci_index),
MCI_INDIRECT_REG_CTRL_ADDR(MCI_PHY_CTRL_REG_NUM) |
MCI_INDIRECT_CTRL_LOCAL_PKT);
ret |= mci_poll_command_completion(mci_index, MCI_CMD_WRITE);
/* Reduce the threshold */
mci_mmio_write_32(MCI_WRITE_READ_DATA_REG(mci_index),
MCI_CTRL_IHB_MODE_CFG_REG_DEF_VAL);
mci_mmio_write_32(MCI_ACCESS_CMD_REG(mci_index),
MCI_INDIRECT_REG_CTRL_ADDR(
MCI_CTRL_IHB_MODE_CFG_REG_NUM) |
MCI_INDIRECT_CTRL_LOCAL_PKT);
ret |= mci_poll_command_completion(mci_index, MCI_CMD_WRITE);
/* Exit PIDI mode */
reg_data = MCI_PHY_CTRL_MCI_PHY_REG_IF_MODE |
MCI_PHY_CTRL_MCI_PHY_MODE_HOST |
MCI_PHY_CTRL_MCI_MAJOR |
MCI_PHY_CTRL_MCI_MINOR;
mci_mmio_write_32(MCI_WRITE_READ_DATA_REG(mci_index), reg_data);
mci_mmio_write_32(MCI_ACCESS_CMD_REG(mci_index),
MCI_INDIRECT_REG_CTRL_ADDR(MCI_PHY_CTRL_REG_NUM) |
MCI_INDIRECT_CTRL_LOCAL_PKT);
ret |= mci_poll_command_completion(mci_index, MCI_CMD_WRITE);
/* Configure remote CP side */
reg_data = MCI_PHY_CTRL_PIDI_MODE |
MCI_PHY_CTRL_MCI_MAJOR |
MCI_PHY_CTRL_MCI_MINOR |
MCI_PHY_CTRL_MCI_PHY_REG_IF_MODE;
mci_mmio_write_32(MCI_WRITE_READ_DATA_REG(mci_index), reg_data);
mci_mmio_write_32(MCI_ACCESS_CMD_REG(mci_index),
MCI_INDIRECT_REG_CTRL_ADDR(MCI_PHY_CTRL_REG_NUM) |
MCI_CTRL_IHB_MODE_FWD_MOD);
ret |= mci_poll_command_completion(mci_index, MCI_CMD_WRITE);
/* Reduce the threshold */
mci_mmio_write_32(MCI_WRITE_READ_DATA_REG(mci_index),
MCI_CTRL_IHB_MODE_CFG_REG_DEF_VAL);
mci_mmio_write_32(MCI_ACCESS_CMD_REG(mci_index),
MCI_INDIRECT_REG_CTRL_ADDR(
MCI_CTRL_IHB_MODE_CFG_REG_NUM) |
MCI_INDIRECT_CTRL_HOPID(GID_IHB_EXT));
ret |= mci_poll_command_completion(mci_index, MCI_CMD_WRITE);
/* Exit PIDI mode */
reg_data = MCI_PHY_CTRL_MCI_MAJOR |
MCI_PHY_CTRL_MCI_MINOR |
MCI_PHY_CTRL_MCI_PHY_REG_IF_MODE;
mci_mmio_write_32(MCI_WRITE_READ_DATA_REG(mci_index), reg_data);
mci_mmio_write_32(MCI_ACCESS_CMD_REG(mci_index),
MCI_INDIRECT_REG_CTRL_ADDR(MCI_PHY_CTRL_REG_NUM) |
MCI_CTRL_IHB_MODE_FWD_MOD);
ret |= mci_poll_command_completion(mci_index, MCI_CMD_WRITE);
debug_exit();
return ret;
}
/* Configure:
* 1. AP & CP TX thresholds and delta configurations
* 2. DLO & DLI FIFO full threshold
* 3. RX thresholds and delta configurations
* 4. CP AR and AW outstanding
* 5. AP AR and AW outstanding
*/
static int mci_axi_set_fifo_rx_tx_thresh(int mci_index)
{
uint32_t ret = 0;
debug_enter();
/* AP TX thresholds and delta configurations (IHB_reg 0x1) */
mci_mmio_write_32(MCI_WRITE_READ_DATA_REG(mci_index),
MCI_CTRL_TX_MEM_CFG_REG_DEF_VAL);
mci_mmio_write_32(MCI_ACCESS_CMD_REG(mci_index),
MCI_INDIRECT_REG_CTRL_ADDR(
MCI_CTRL_TX_MEM_CFG_REG_NUM) |
MCI_INDIRECT_CTRL_LOCAL_PKT);
ret |= mci_poll_command_completion(mci_index, MCI_CMD_WRITE);
/* CP TX thresholds and delta configurations (IHB_reg 0x1) */
mci_mmio_write_32(MCI_WRITE_READ_DATA_REG(mci_index),
MCI_CTRL_TX_MEM_CFG_REG_DEF_VAL);
mci_mmio_write_32(MCI_ACCESS_CMD_REG(mci_index),
MCI_INDIRECT_REG_CTRL_ADDR(
MCI_CTRL_TX_MEM_CFG_REG_NUM) |
MCI_INDIRECT_CTRL_HOPID(GID_IHB_EXT));
ret |= mci_poll_command_completion(mci_index, MCI_CMD_WRITE);
/* AP DLO & DLI FIFO full threshold & Auto-Link enable (IHB_reg 0x8) */
mci_mmio_write_32(MCI_WRITE_READ_DATA_REG(mci_index),
MCI_CTRL_MCI_PHY_SET_REG_DEF_VAL |
MCI_CTRL_MCI_PHY_SET_AUTO_LINK_EN(1));
mci_mmio_write_32(MCI_ACCESS_CMD_REG(mci_index),
MCI_INDIRECT_REG_CTRL_ADDR(
MCI_CTRL_MCI_PHY_SETTINGS_REG_NUM) |
MCI_INDIRECT_CTRL_LOCAL_PKT);
ret |= mci_poll_command_completion(mci_index, MCI_CMD_WRITE);
/* CP DLO & DLI FIFO full threshold (IHB_reg 0x8) */
mci_mmio_write_32(MCI_WRITE_READ_DATA_REG(mci_index),
MCI_CTRL_MCI_PHY_SET_REG_DEF_VAL);
mci_mmio_write_32(MCI_ACCESS_CMD_REG(mci_index),
MCI_INDIRECT_REG_CTRL_ADDR(
MCI_CTRL_MCI_PHY_SETTINGS_REG_NUM) |
MCI_INDIRECT_CTRL_HOPID(GID_IHB_EXT));
ret |= mci_poll_command_completion(mci_index, MCI_CMD_WRITE);
/* AP RX thresholds and delta configurations (IHB_reg 0x0) */
mci_mmio_write_32(MCI_WRITE_READ_DATA_REG(mci_index),
MCI_CTRL_RX_MEM_CFG_REG_DEF_AP_VAL);
mci_mmio_write_32(MCI_ACCESS_CMD_REG(mci_index),
MCI_INDIRECT_REG_CTRL_ADDR(
MCI_CTRL_RX_MEM_CFG_REG_NUM) |
MCI_INDIRECT_CTRL_LOCAL_PKT);
ret |= mci_poll_command_completion(mci_index, MCI_CMD_WRITE);
/* CP RX thresholds and delta configurations (IHB_reg 0x0) */
mci_mmio_write_32(MCI_WRITE_READ_DATA_REG(mci_index),
MCI_CTRL_RX_MEM_CFG_REG_DEF_CP_VAL);
mci_mmio_write_32(MCI_ACCESS_CMD_REG(mci_index),
MCI_INDIRECT_REG_CTRL_ADDR(
MCI_CTRL_RX_MEM_CFG_REG_NUM) |
MCI_INDIRECT_CTRL_HOPID(GID_IHB_EXT));
ret |= mci_poll_command_completion(mci_index, MCI_CMD_WRITE);
/* AP AR & AW maximum AXI outstanding request cfg (HB_reg 0xd) */
mci_mmio_write_32(MCI_WRITE_READ_DATA_REG(mci_index),
MCI_HB_CTRL_TX_CTRL_PRI_TH_QOS(8) |
MCI_HB_CTRL_TX_CTRL_MAX_RD_CNT(3) |
MCI_HB_CTRL_TX_CTRL_MAX_WR_CNT(3));
mci_mmio_write_32(MCI_ACCESS_CMD_REG(mci_index),
MCI_INDIRECT_REG_CTRL_ADDR(
MCI_HB_CTRL_TX_CTRL_REG_NUM) |
MCI_INDIRECT_CTRL_HOPID(GID_AXI_HB) |
MCI_INDIRECT_CTRL_LOCAL_PKT);
ret |= mci_poll_command_completion(mci_index, MCI_CMD_WRITE);
/* CP AR & AW maximum AXI outstanding request cfg (HB_reg 0xd) */
mci_mmio_write_32(MCI_WRITE_READ_DATA_REG(mci_index),
MCI_HB_CTRL_TX_CTRL_PRI_TH_QOS(8) |
MCI_HB_CTRL_TX_CTRL_MAX_RD_CNT(0xB) |
MCI_HB_CTRL_TX_CTRL_MAX_WR_CNT(0x11));
mci_mmio_write_32(MCI_ACCESS_CMD_REG(mci_index),
MCI_INDIRECT_REG_CTRL_ADDR(
MCI_HB_CTRL_TX_CTRL_REG_NUM) |
MCI_INDIRECT_CTRL_HOPID(GID_IHB_EXT) |
MCI_INDIRECT_CTRL_HOPID(GID_AXI_HB));
ret |= mci_poll_command_completion(mci_index, MCI_CMD_WRITE);
debug_exit();
return ret;
}
/* configure MCI to allow read & write transactions to arrive at the same time.
* Without the below configuration, MCI won't sent response to CPU for
* transactions which arrived simultaneously and will lead to CPU hang.
* The below will configure MCI to be able to pass transactions from/to CP/AP.
*/
static int mci_enable_simultaneous_transactions(int mci_index)
{
uint32_t ret = 0;
debug_enter();
/* ID assignment (assigning global ID offset to CP) */
mci_mmio_write_32(MCI_WRITE_READ_DATA_REG(0),
MCI_DID_GLOBAL_ASSIGN_REQ_MCI_LOCAL_ID(2) |
MCI_DID_GLOBAL_ASSIGN_REQ_MCI_COUNT(2) |
MCI_DID_GLOBAL_ASSIGN_REQ_HOPS_NUM(2));
mci_mmio_write_32(MCI_ACCESS_CMD_REG(0),
MCI_INDIRECT_REG_CTRL_ADDR(
MCI_DID_GLOBAL_ASSIGNMENT_REQUEST_REG) |
MCI_INDIRECT_CTRL_ASSIGN_CMD);
ret |= mci_poll_command_completion(mci_index, MCI_CMD_WRITE);
/* Assigning dest. ID=3 to all transactions entering from AXI at AP */
mci_mmio_write_32(MCI_WRITE_READ_DATA_REG(0),
MCI_HB_CTRL_WIN0_DEST_VALID_FLAG(1) |
MCI_HB_CTRL_WIN0_DEST_ID(3));
mci_mmio_write_32(MCI_ACCESS_CMD_REG(0),
MCI_INDIRECT_REG_CTRL_ADDR(
MCI_HB_CTRL_WIN0_DESTINATION_REG_NUM) |
MCI_INDIRECT_CTRL_HOPID(GID_AXI_HB) |
MCI_INDIRECT_CTRL_LOCAL_PKT);
ret |= mci_poll_command_completion(mci_index, MCI_CMD_WRITE);
/* Assigning dest. ID=1 to all transactions entering from AXI at CP */
mci_mmio_write_32(MCI_WRITE_READ_DATA_REG(0),
MCI_HB_CTRL_WIN0_DEST_VALID_FLAG(1) |
MCI_HB_CTRL_WIN0_DEST_ID(1));
mci_mmio_write_32(MCI_ACCESS_CMD_REG(0),
MCI_INDIRECT_REG_CTRL_ADDR(
MCI_HB_CTRL_WIN0_DESTINATION_REG_NUM) |
MCI_INDIRECT_CTRL_HOPID(GID_IHB_EXT) |
MCI_INDIRECT_CTRL_HOPID(GID_AXI_HB));
ret |= mci_poll_command_completion(mci_index, MCI_CMD_WRITE);
/* End address to all transactions entering from AXI at AP.
* This will lead to get match for any AXI address
* and receive destination ID=3
*/
mci_mmio_write_32(MCI_WRITE_READ_DATA_REG(0), 0xffffffff);
mci_mmio_write_32(MCI_ACCESS_CMD_REG(0),
MCI_INDIRECT_REG_CTRL_ADDR(
MCI_HB_CTRL_WIN0_ADDRESS_MASK_REG_NUM) |
MCI_INDIRECT_CTRL_HOPID(GID_AXI_HB) |
MCI_INDIRECT_CTRL_LOCAL_PKT);
ret |= mci_poll_command_completion(mci_index, MCI_CMD_WRITE);
/* End address to all transactions entering from AXI at CP.
* This will lead to get match for any AXI address
* and receive destination ID=1
*/
mci_mmio_write_32(MCI_WRITE_READ_DATA_REG(0), 0xffffffff);
mci_mmio_write_32(MCI_ACCESS_CMD_REG(0),
MCI_INDIRECT_REG_CTRL_ADDR(
MCI_HB_CTRL_WIN0_ADDRESS_MASK_REG_NUM) |
MCI_INDIRECT_CTRL_HOPID(GID_IHB_EXT) |
MCI_INDIRECT_CTRL_HOPID(GID_AXI_HB));
ret |= mci_poll_command_completion(mci_index, MCI_CMD_WRITE);
debug_exit();
return ret;
}
/* Check if MCI simultaneous transaction was already enabled.
* Currently bootrom does this mci configuration only when the boot source is
* SAR_MCIX4, in other cases it should be done at this stage.
* It is worth noticing that in case of booting from uart, the bootrom
* flow is different and this mci initialization is skipped even if boot
* source is SAR_MCIX4. Therefore new verification bases on appropriate mci's
* register content: if the appropriate reg contains 0x0 it means that the
* bootrom didn't perform required mci configuration.
*
* Returns:
* 0 - configuration already done
* 1 - configuration missing
*/
static _Bool mci_simulatenous_trans_missing(int mci_index)
{
uint32_t reg, ret;
/* read 'Window 0 Destination ID assignment' from HB register 0x3
* (TX_CFG_W0_DST_ID) to check whether ID assignment was already
* performed by BootROM.
*/
debug_enter();
mci_mmio_write_32(MCI_ACCESS_CMD_REG(0),
MCI_INDIRECT_REG_CTRL_ADDR(
MCI_HB_CTRL_WIN0_DESTINATION_REG_NUM) |
MCI_INDIRECT_CTRL_HOPID(GID_AXI_HB) |
MCI_INDIRECT_CTRL_LOCAL_PKT |
MCI_INDIRECT_CTRL_READ_CMD);
ret = mci_poll_command_completion(mci_index, MCI_CMD_READ);
reg = mci_mmio_read_32(MCI_WRITE_READ_DATA_REG(mci_index));
if (ret)
ERROR("Failed to verify MCI simultaneous read/write status\n");
debug_exit();
/* default ID assignment is 0, so if register doesn't contain zeros
* it means that bootrom already performed required configuration.
*/
if (reg != 0)
return 0;
return 1;
}
/* For A1 revision, configure the MCI link for performance improvement:
* - set MCI to support read/write transactions to arrive at the same time
* - Switch AXI to PCIe mode
* - Reduce sequence FIFO threshold
* - Configure RX/TX FIFO thresholds
*
* Note:
* We don't exit on error code from any sub routine, to try (best effort) to
* complete the MCI configuration.
* (If we exit - Bootloader will surely fail to boot)
*/
int mci_configure(int mci_index)
{
int rval;
debug_enter();
/* According to design guidelines the MCI simultaneous transaction
* shouldn't be enabled more then once - therefore make sure that it
* wasn't already enabled in bootrom.
*/
if (mci_simulatenous_trans_missing(mci_index)) {
VERBOSE("Enabling MCI simultaneous transaction\n");
/* set MCI to support read/write transactions
* to arrive at the same time
*/
rval = mci_enable_simultaneous_transactions(mci_index);
if (rval)
ERROR("Failed to set MCI simultaneous read/write\n");
} else
VERBOSE("Skip MCI ID assignment - already done by bootrom\n");
/* Configure MCI for more consistent behavior with AXI protocol */
rval = mci_axi_set_pcie_mode(mci_index);
if (rval)
ERROR("Failed to set MCI to AXI PCIe mode\n");
/* reduce FIFO global threshold */
rval = mci_axi_set_fifo_thresh(mci_index);
if (rval)
ERROR("Failed to set MCI FIFO global threshold\n");
/* configure RX/TX FIFO thresholds */
rval = mci_axi_set_fifo_rx_tx_thresh(mci_index);
if (rval)
ERROR("Failed to set MCI RX/TX FIFO threshold\n");
debug_exit();
return 1;
}
int mci_get_link_status(void)
{
uint32_t cmd, data;
cmd = (MCI_INDIRECT_REG_CTRL_ADDR(MCI_CTRL_STATUS_REG_NUM) |
MCI_INDIRECT_CTRL_LOCAL_PKT | MCI_INDIRECT_CTRL_READ_CMD);
if (mci_read(0, cmd, &data)) {
ERROR("Failed to read status register\n");
return -1;
}
/* Check if the link is ready */
if (data != MCI_CTRL_PHY_READY) {
ERROR("Bad link status %x\n", data);
return -1;
}
return 0;
}
void mci_turn_link_down(void)
{
uint32_t cmd, data;
int rval = 0;
debug_enter();
/* Turn off auto-link */
cmd = (MCI_INDIRECT_REG_CTRL_ADDR(MCI_CTRL_MCI_PHY_SETTINGS_REG_NUM) |
MCI_INDIRECT_CTRL_LOCAL_PKT);
data = (MCI_CTRL_MCI_PHY_SET_REG_DEF_VAL2 |
MCI_CTRL_MCI_PHY_SET_AUTO_LINK_EN(0));
rval = mci_write(0, cmd, data);
if (rval)
ERROR("Failed to turn off auto-link\n");
/* Reset AP PHY */
cmd = (MCI_INDIRECT_REG_CTRL_ADDR(MCI_PHY_CTRL_REG_NUM) |
MCI_INDIRECT_CTRL_LOCAL_PKT);
data = (MCI_PHY_CTRL_MCI_MINOR |
MCI_PHY_CTRL_MCI_MAJOR |
MCI_PHY_CTRL_MCI_PHY_MODE_HOST |
MCI_PHY_CTRL_MCI_PHY_RESET_CORE);
rval = mci_write(0, cmd, data);
if (rval)
ERROR("Failed to reset AP PHY\n");
/* Clear all status & CRC values */
cmd = (MCI_INDIRECT_REG_CTRL_ADDR(MCI_LINK_CRC_CTRL_REG_NUM) |
MCI_INDIRECT_CTRL_LOCAL_PKT);
data = 0x0;
mci_write(0, cmd, data);
cmd = (MCI_INDIRECT_REG_CTRL_ADDR(MCI_CTRL_STATUS_REG_NUM) |
MCI_INDIRECT_CTRL_LOCAL_PKT);
data = 0x0;
rval = mci_write(0, cmd, data);
if (rval)
ERROR("Failed to reset AP PHY\n");
/* Wait 5ms before un-reset the PHY */
mdelay(5);
/* Un-reset AP PHY */
cmd = (MCI_INDIRECT_REG_CTRL_ADDR(MCI_PHY_CTRL_REG_NUM) |
MCI_INDIRECT_CTRL_LOCAL_PKT);
data = (MCI_PHY_CTRL_MCI_MINOR | MCI_PHY_CTRL_MCI_MAJOR |
MCI_PHY_CTRL_MCI_PHY_MODE_HOST);
rval = mci_write(0, cmd, data);
if (rval)
ERROR("Failed to un-reset AP PHY\n");
debug_exit();
}
void mci_turn_link_on(void)
{
uint32_t cmd, data;
int rval = 0;
debug_enter();
/* Turn on auto-link */
cmd = (MCI_INDIRECT_REG_CTRL_ADDR(MCI_CTRL_MCI_PHY_SETTINGS_REG_NUM) |
MCI_INDIRECT_CTRL_LOCAL_PKT);
data = (MCI_CTRL_MCI_PHY_SET_REG_DEF_VAL2 |
MCI_CTRL_MCI_PHY_SET_AUTO_LINK_EN(1));
rval = mci_write(0, cmd, data);
if (rval)
ERROR("Failed to turn on auto-link\n");
debug_exit();
}
/* Initialize MCI for performance improvements */
int mci_initialize(int mci_index)
{
int ret;
debug_enter();
INFO("MCI%d initialization:\n", mci_index);
ret = mci_configure(mci_index);
debug_exit();
return ret;
}
/*
* Copyright (C) 2018 Marvell International Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
* https://spdx.org/licenses
*/
/* AP807 Marvell SoC driver */
#include <ap_setup.h>
#include <cache_llc.h>
#include <ccu.h>
#include <debug.h>
#include <io_win.h>
#include <mci.h>
#include <mmio.h>
#include <mvebu_def.h>
#define SMMU_sACR (MVEBU_SMMU_BASE + 0x10)
#define SMMU_sACR_PG_64K (1 << 16)
#define CCU_GSPMU_CR (MVEBU_CCU_BASE(MVEBU_AP0) \
+ 0x3F0)
#define GSPMU_CPU_CONTROL (0x1 << 0)
#define CCU_HTC_CR (MVEBU_CCU_BASE(MVEBU_AP0) \
+ 0x200)
#define CCU_SET_POC_OFFSET 5
#define DSS_CR0 (MVEBU_RFU_BASE + 0x100)
#define DVM_48BIT_VA_ENABLE (1 << 21)
/* Secure MoChi incoming access */
#define SEC_MOCHI_IN_ACC_REG (MVEBU_RFU_BASE + 0x4738)
#define SEC_MOCHI_IN_ACC_IHB0_EN (1)
#define SEC_MOCHI_IN_ACC_IHB1_EN (1 << 3)
#define SEC_MOCHI_IN_ACC_IHB2_EN (1 << 6)
#define SEC_MOCHI_IN_ACC_PIDI_EN (1 << 9)
#define SEC_IN_ACCESS_ENA_ALL_MASTERS (SEC_MOCHI_IN_ACC_IHB0_EN | \
SEC_MOCHI_IN_ACC_IHB1_EN | \
SEC_MOCHI_IN_ACC_IHB2_EN | \
SEC_MOCHI_IN_ACC_PIDI_EN)
/* SYSRST_OUTn Config definitions */
#define MVEBU_SYSRST_OUT_CONFIG_REG (MVEBU_MISC_SOC_BASE + 0x4)
#define WD_MASK_SYS_RST_OUT (1 << 2)
/* DSS PHY for DRAM */
#define DSS_SCR_REG (MVEBU_RFU_BASE + 0x208)
#define DSS_PPROT_OFFS 4
#define DSS_PPROT_MASK 0x7
#define DSS_PPROT_PRIV_SECURE_DATA 0x1
/* Used for Units of AP-807 (e.g. SDIO and etc) */
#define MVEBU_AXI_ATTR_BASE (MVEBU_REGS_BASE + 0x6F4580)
#define MVEBU_AXI_ATTR_REG(index) (MVEBU_AXI_ATTR_BASE + \
0x4 * index)
enum axi_attr {
AXI_SDIO_ATTR = 0,
AXI_DFX_ATTR,
AXI_MAX_ATTR,
};
static void ap_sec_masters_access_en(uint32_t enable)
{
uint32_t reg;
/* Open/Close incoming access for all masters.
* The access is disabled in trusted boot mode
* Could only be done in EL3
*/
reg = mmio_read_32(SEC_MOCHI_IN_ACC_REG);
if (enable)
mmio_write_32(SEC_MOCHI_IN_ACC_REG, reg |
SEC_IN_ACCESS_ENA_ALL_MASTERS);
else
mmio_write_32(SEC_MOCHI_IN_ACC_REG,
reg & ~SEC_IN_ACCESS_ENA_ALL_MASTERS);
}
static void setup_smmu(void)
{
uint32_t reg;
/* Set the SMMU page size to 64 KB */
reg = mmio_read_32(SMMU_sACR);
reg |= SMMU_sACR_PG_64K;
mmio_write_32(SMMU_sACR, reg);
}
static void init_aurora2(void)
{
uint32_t reg;
/* Enable GSPMU control by CPU */
reg = mmio_read_32(CCU_GSPMU_CR);
reg |= GSPMU_CPU_CONTROL;
mmio_write_32(CCU_GSPMU_CR, reg);
#if LLC_ENABLE
/* Enable LLC for AP807 in exclusive mode */
llc_enable(0, 1);
/* Set point of coherency to DDR.
* This is required by units which have
* SW cache coherency
*/
reg = mmio_read_32(CCU_HTC_CR);
reg |= (0x1 << CCU_SET_POC_OFFSET);
mmio_write_32(CCU_HTC_CR, reg);
#endif /* LLC_ENABLE */
}
/* MCIx indirect access register are based by default at 0xf4000000/0xf6000000
* to avoid conflict of internal registers of units connected via MCIx, which
* can be based on the same address (i.e CP1 base is also 0xf4000000),
* the following routines remaps the MCIx indirect bases to another domain
*/
static void mci_remap_indirect_access_base(void)
{
uint32_t mci;
for (mci = 0; mci < MCI_MAX_UNIT_ID; mci++)
mmio_write_32(MCIX4_REG_START_ADDRESS_REG(mci),
MVEBU_MCI_REG_BASE_REMAP(mci) >>
MCI_REMAP_OFF_SHIFT);
}
static void ap807_axi_attr_init(void)
{
uint32_t index, data;
/* Initialize AXI attributes for AP807 */
/* Go over the AXI attributes and set Ax-Cache and Ax-Domain */
for (index = 0; index < AXI_MAX_ATTR; index++) {
switch (index) {
/* DFX works with no coherent only -
* there's no option to configure the Ax-Cache and Ax-Domain
*/
case AXI_DFX_ATTR:
continue;
default:
/* Set Ax-Cache as cacheable, no allocate, modifiable,
* bufferable.
* The values are different because Read & Write
* definition is different in Ax-Cache
*/
data = mmio_read_32(MVEBU_AXI_ATTR_REG(index));
data &= ~MVEBU_AXI_ATTR_ARCACHE_MASK;
data |= (CACHE_ATTR_WRITE_ALLOC |
CACHE_ATTR_CACHEABLE |
CACHE_ATTR_BUFFERABLE) <<
MVEBU_AXI_ATTR_ARCACHE_OFFSET;
data &= ~MVEBU_AXI_ATTR_AWCACHE_MASK;
data |= (CACHE_ATTR_READ_ALLOC |
CACHE_ATTR_CACHEABLE |
CACHE_ATTR_BUFFERABLE) <<
MVEBU_AXI_ATTR_AWCACHE_OFFSET;
/* Set Ax-Domain as Outer domain */
data &= ~MVEBU_AXI_ATTR_ARDOMAIN_MASK;
data |= DOMAIN_OUTER_SHAREABLE <<
MVEBU_AXI_ATTR_ARDOMAIN_OFFSET;
data &= ~MVEBU_AXI_ATTR_AWDOMAIN_MASK;
data |= DOMAIN_OUTER_SHAREABLE <<
MVEBU_AXI_ATTR_AWDOMAIN_OFFSET;
mmio_write_32(MVEBU_AXI_ATTR_REG(index), data);
}
}
}
static void misc_soc_configurations(void)
{
uint32_t reg;
/* Enable 48-bit VA */
mmio_setbits_32(DSS_CR0, DVM_48BIT_VA_ENABLE);
/* Un-mask Watchdog reset from influencing the SYSRST_OUTn.
* Otherwise, upon WD timeout, the WD reset signal won't trigger reset
*/
reg = mmio_read_32(MVEBU_SYSRST_OUT_CONFIG_REG);
reg &= ~(WD_MASK_SYS_RST_OUT);
mmio_write_32(MVEBU_SYSRST_OUT_CONFIG_REG, reg);
}
void ap_init(void)
{
/* Setup Aurora2. */
init_aurora2();
/* configure MCI mapping */
mci_remap_indirect_access_base();
/* configure IO_WIN windows */
init_io_win(MVEBU_AP0);
/* configure CCU windows */
init_ccu(MVEBU_AP0);
/* configure the SMMU */
setup_smmu();
/* Open AP incoming access for all masters */
ap_sec_masters_access_en(1);
/* configure axi for AP */
ap807_axi_attr_init();
/* misc configuration of the SoC */
misc_soc_configurations();
}
static void ap807_dram_phy_access_config(void)
{
uint32_t reg_val;
/* Update DSS port access permission to DSS_PHY */
reg_val = mmio_read_32(DSS_SCR_REG);
reg_val &= ~(DSS_PPROT_MASK << DSS_PPROT_OFFS);
reg_val |= ((DSS_PPROT_PRIV_SECURE_DATA & DSS_PPROT_MASK) <<
DSS_PPROT_OFFS);
mmio_write_32(DSS_SCR_REG, reg_val);
}
void ap_ble_init(void)
{
/* Enable DSS port */
ap807_dram_phy_access_config();
}
int ap_get_count(void)
{
return 1;
}
/*
* Copyright (C) 2018 Marvell International Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
* https://spdx.org/licenses
*/
/* AP806 Marvell SoC driver */
#include <ap_setup.h>
#include <ccu.h>
#include <cache_llc.h>
#include <debug.h>
#include <io_win.h>
#include <mci.h>
#include <mmio.h>
#include <mvebu_def.h>
#define SMMU_sACR (MVEBU_SMMU_BASE + 0x10)
#define SMMU_sACR_PG_64K (1 << 16)
#define CCU_GSPMU_CR (MVEBU_CCU_BASE(MVEBU_AP0) + \
0x3F0)
#define GSPMU_CPU_CONTROL (0x1 << 0)
#define CCU_HTC_CR (MVEBU_CCU_BASE(MVEBU_AP0) + \
0x200)
#define CCU_SET_POC_OFFSET 5
#define CCU_RGF(win) (MVEBU_CCU_BASE(MVEBU_AP0) + \
0x90 + 4 * (win))
#define DSS_CR0 (MVEBU_RFU_BASE + 0x100)
#define DVM_48BIT_VA_ENABLE (1 << 21)
/* Secure MoChi incoming access */
#define SEC_MOCHI_IN_ACC_REG (MVEBU_RFU_BASE + 0x4738)
#define SEC_MOCHI_IN_ACC_IHB0_EN (1)
#define SEC_MOCHI_IN_ACC_IHB1_EN (1 << 3)
#define SEC_MOCHI_IN_ACC_IHB2_EN (1 << 6)
#define SEC_MOCHI_IN_ACC_PIDI_EN (1 << 9)
#define SEC_IN_ACCESS_ENA_ALL_MASTERS (SEC_MOCHI_IN_ACC_IHB0_EN | \
SEC_MOCHI_IN_ACC_IHB1_EN | \
SEC_MOCHI_IN_ACC_IHB2_EN | \
SEC_MOCHI_IN_ACC_PIDI_EN)
/* SYSRST_OUTn Config definitions */
#define MVEBU_SYSRST_OUT_CONFIG_REG (MVEBU_MISC_SOC_BASE + 0x4)
#define WD_MASK_SYS_RST_OUT (1 << 2)
/* Generic Timer System Controller */
#define MVEBU_MSS_GTCR_REG (MVEBU_REGS_BASE + 0x581000)
#define MVEBU_MSS_GTCR_ENABLE_BIT 0x1
/*
* AXI Configuration.
*/
/* Used for Units of AP-806 (e.g. SDIO and etc) */
#define MVEBU_AXI_ATTR_BASE (MVEBU_REGS_BASE + 0x6F4580)
#define MVEBU_AXI_ATTR_REG(index) (MVEBU_AXI_ATTR_BASE + \
0x4 * index)
enum axi_attr {
AXI_SDIO_ATTR = 0,
AXI_DFX_ATTR,
AXI_MAX_ATTR,
};
static void apn_sec_masters_access_en(uint32_t enable)
{
uint32_t reg;
/* Open/Close incoming access for all masters.
* The access is disabled in trusted boot mode
* Could only be done in EL3
*/
reg = mmio_read_32(SEC_MOCHI_IN_ACC_REG);
if (enable)
mmio_write_32(SEC_MOCHI_IN_ACC_REG, reg |
SEC_IN_ACCESS_ENA_ALL_MASTERS);
else
mmio_write_32(SEC_MOCHI_IN_ACC_REG, reg &
~SEC_IN_ACCESS_ENA_ALL_MASTERS);
}
static void setup_smmu(void)
{
uint32_t reg;
/* Set the SMMU page size to 64 KB */
reg = mmio_read_32(SMMU_sACR);
reg |= SMMU_sACR_PG_64K;
mmio_write_32(SMMU_sACR, reg);
}
static void apn806_errata_wa_init(void)
{
/*
* ERRATA ID: RES-3033912 - Internal Address Space Init state causes
* a hang upon accesses to [0xf070_0000, 0xf07f_ffff]
* Workaround: Boot Firmware (ATF) should configure CCU_RGF_WIN(4) to
* split [0x6e_0000, 0xff_ffff] to values [0x6e_0000, 0x6f_ffff] and
* [0x80_0000, 0xff_ffff] that cause accesses to the
* segment of [0xf070_0000, 0xf07f_ffff] to act as RAZWI.
*/
mmio_write_32(CCU_RGF(4), 0x37f9b809);
mmio_write_32(CCU_RGF(5), 0x7ffa0009);
}
static void init_aurora2(void)
{
uint32_t reg;
/* Enable GSPMU control by CPU */
reg = mmio_read_32(CCU_GSPMU_CR);
reg |= GSPMU_CPU_CONTROL;
mmio_write_32(CCU_GSPMU_CR, reg);
#if LLC_ENABLE
/* Enable LLC for AP806 in exclusive mode */
llc_enable(0, 1);
/* Set point of coherency to DDR.
* This is required by units which have
* SW cache coherency
*/
reg = mmio_read_32(CCU_HTC_CR);
reg |= (0x1 << CCU_SET_POC_OFFSET);
mmio_write_32(CCU_HTC_CR, reg);
#endif /* LLC_ENABLE */
apn806_errata_wa_init();
}
/* MCIx indirect access register are based by default at 0xf4000000/0xf6000000
* to avoid conflict of internal registers of units connected via MCIx, which
* can be based on the same address (i.e CP1 base is also 0xf4000000),
* the following routines remaps the MCIx indirect bases to another domain
*/
static void mci_remap_indirect_access_base(void)
{
uint32_t mci;
for (mci = 0; mci < MCI_MAX_UNIT_ID; mci++)
mmio_write_32(MCIX4_REG_START_ADDRESS_REG(mci),
MVEBU_MCI_REG_BASE_REMAP(mci) >>
MCI_REMAP_OFF_SHIFT);
}
static void apn806_axi_attr_init(void)
{
uint32_t index, data;
/* Initialize AXI attributes for APN806 */
/* Go over the AXI attributes and set Ax-Cache and Ax-Domain */
for (index = 0; index < AXI_MAX_ATTR; index++) {
switch (index) {
/* DFX works with no coherent only -
* there's no option to configure the Ax-Cache and Ax-Domain
*/
case AXI_DFX_ATTR:
continue;
default:
/* Set Ax-Cache as cacheable, no allocate, modifiable,
* bufferable
* The values are different because Read & Write
* definition is different in Ax-Cache
*/
data = mmio_read_32(MVEBU_AXI_ATTR_REG(index));
data &= ~MVEBU_AXI_ATTR_ARCACHE_MASK;
data |= (CACHE_ATTR_WRITE_ALLOC |
CACHE_ATTR_CACHEABLE |
CACHE_ATTR_BUFFERABLE) <<
MVEBU_AXI_ATTR_ARCACHE_OFFSET;
data &= ~MVEBU_AXI_ATTR_AWCACHE_MASK;
data |= (CACHE_ATTR_READ_ALLOC |
CACHE_ATTR_CACHEABLE |
CACHE_ATTR_BUFFERABLE) <<
MVEBU_AXI_ATTR_AWCACHE_OFFSET;
/* Set Ax-Domain as Outer domain */
data &= ~MVEBU_AXI_ATTR_ARDOMAIN_MASK;
data |= DOMAIN_OUTER_SHAREABLE <<
MVEBU_AXI_ATTR_ARDOMAIN_OFFSET;
data &= ~MVEBU_AXI_ATTR_AWDOMAIN_MASK;
data |= DOMAIN_OUTER_SHAREABLE <<
MVEBU_AXI_ATTR_AWDOMAIN_OFFSET;
mmio_write_32(MVEBU_AXI_ATTR_REG(index), data);
}
}
}
static void dss_setup(void)
{
/* Enable 48-bit VA */
mmio_setbits_32(DSS_CR0, DVM_48BIT_VA_ENABLE);
}
void misc_soc_configurations(void)
{
uint32_t reg;
/* Un-mask Watchdog reset from influencing the SYSRST_OUTn.
* Otherwise, upon WD timeout, the WD reset signal won't trigger reset
*/
reg = mmio_read_32(MVEBU_SYSRST_OUT_CONFIG_REG);
reg &= ~(WD_MASK_SYS_RST_OUT);
mmio_write_32(MVEBU_SYSRST_OUT_CONFIG_REG, reg);
}
void ap_init(void)
{
/* Setup Aurora2. */
init_aurora2();
/* configure MCI mapping */
mci_remap_indirect_access_base();
/* configure IO_WIN windows */
init_io_win(MVEBU_AP0);
/* configure CCU windows */
init_ccu(MVEBU_AP0);
/* configure DSS */
dss_setup();
/* configure the SMMU */
setup_smmu();
/* Open APN incoming access for all masters */
apn_sec_masters_access_en(1);
/* configure axi for APN*/
apn806_axi_attr_init();
/* misc configuration of the SoC */
misc_soc_configurations();
}
void ap_ble_init(void)
{
}
int ap_get_count(void)
{
return 1;
}
/*
* Copyright (C) 2018 Marvell International Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
* https://spdx.org/licenses
*/
/* CP110 Marvell SoC driver */
#include <amb_adec.h>
#include <cp110_setup.h>
#include <debug.h>
#include <delay_timer.h>
#include <iob.h>
#include <plat_marvell.h>
/*
* AXI Configuration.
*/
/* Used for Units of CP-110 (e.g. USB device, USB Host, and etc) */
#define MVEBU_AXI_ATTR_OFFSET (0x441300)
#define MVEBU_AXI_ATTR_REG(index) (MVEBU_AXI_ATTR_OFFSET + \
0x4 * index)
/* AXI Protection bits */
#define MVEBU_AXI_PROT_OFFSET (0x441200)
/* AXI Protection regs */
#define MVEBU_AXI_PROT_REG(index) ((index <= 4) ? \
(MVEBU_AXI_PROT_OFFSET + \
0x4 * index) : \
(MVEBU_AXI_PROT_OFFSET + 0x18))
#define MVEBU_AXI_PROT_REGS_NUM (6)
#define MVEBU_SOC_CFGS_OFFSET (0x441900)
#define MVEBU_SOC_CFG_REG(index) (MVEBU_SOC_CFGS_OFFSET + \
0x4 * index)
#define MVEBU_SOC_CFG_REG_NUM (0)
#define MVEBU_SOC_CFG_GLOG_SECURE_EN_MASK (0xE)
/* SATA3 MBUS to AXI regs */
#define MVEBU_BRIDGE_WIN_DIS_REG (MVEBU_SOC_CFGS_OFFSET + 0x10)
#define MVEBU_BRIDGE_WIN_DIS_OFF (0x0)
/* SATA3 MBUS to AXI regs */
#define MVEBU_SATA_M2A_AXI_PORT_CTRL_REG (0x54ff04)
/* AXI to MBUS bridge registers */
#define MVEBU_AMB_IP_OFFSET (0x13ff00)
#define MVEBU_AMB_IP_BRIDGE_WIN_REG(win) (MVEBU_AMB_IP_OFFSET + \
(win * 0x8))
#define MVEBU_AMB_IP_BRIDGE_WIN_EN_OFFSET 0
#define MVEBU_AMB_IP_BRIDGE_WIN_EN_MASK \
(0x1 << MVEBU_AMB_IP_BRIDGE_WIN_EN_OFFSET)
#define MVEBU_AMB_IP_BRIDGE_WIN_SIZE_OFFSET 16
#define MVEBU_AMB_IP_BRIDGE_WIN_SIZE_MASK \
(0xffff << MVEBU_AMB_IP_BRIDGE_WIN_SIZE_OFFSET)
#define MVEBU_SAMPLE_AT_RESET_REG (0x440600)
#define SAR_PCIE1_CLK_CFG_OFFSET 31
#define SAR_PCIE1_CLK_CFG_MASK (0x1 << SAR_PCIE1_CLK_CFG_OFFSET)
#define SAR_PCIE0_CLK_CFG_OFFSET 30
#define SAR_PCIE0_CLK_CFG_MASK (0x1 << SAR_PCIE0_CLK_CFG_OFFSET)
#define SAR_I2C_INIT_EN_OFFSET 24
#define SAR_I2C_INIT_EN_MASK (1 << SAR_I2C_INIT_EN_OFFSET)
/*******************************************************************************
* PCIE clock buffer control
******************************************************************************/
#define MVEBU_PCIE_REF_CLK_BUF_CTRL (0x4404F0)
#define PCIE1_REFCLK_BUFF_SOURCE 0x800
#define PCIE0_REFCLK_BUFF_SOURCE 0x400
/*******************************************************************************
* MSS Device Push Set Register
******************************************************************************/
#define MVEBU_CP_MSS_DPSHSR_REG (0x280040)
#define MSS_DPSHSR_REG_PCIE_CLK_SEL 0x8
/*******************************************************************************
* RTC Configuration
******************************************************************************/
#define MVEBU_RTC_BASE (0x284000)
#define MVEBU_RTC_STATUS_REG (MVEBU_RTC_BASE + 0x0)
#define MVEBU_RTC_STATUS_ALARM1_MASK 0x1
#define MVEBU_RTC_STATUS_ALARM2_MASK 0x2
#define MVEBU_RTC_IRQ_1_CONFIG_REG (MVEBU_RTC_BASE + 0x4)
#define MVEBU_RTC_IRQ_2_CONFIG_REG (MVEBU_RTC_BASE + 0x8)
#define MVEBU_RTC_TIME_REG (MVEBU_RTC_BASE + 0xC)
#define MVEBU_RTC_ALARM_1_REG (MVEBU_RTC_BASE + 0x10)
#define MVEBU_RTC_ALARM_2_REG (MVEBU_RTC_BASE + 0x14)
#define MVEBU_RTC_CCR_REG (MVEBU_RTC_BASE + 0x18)
#define MVEBU_RTC_NOMINAL_TIMING 0x2000
#define MVEBU_RTC_NOMINAL_TIMING_MASK 0x7FFF
#define MVEBU_RTC_TEST_CONFIG_REG (MVEBU_RTC_BASE + 0x1C)
#define MVEBU_RTC_BRIDGE_TIMING_CTRL0_REG (MVEBU_RTC_BASE + 0x80)
#define MVEBU_RTC_WRCLK_PERIOD_MASK 0xFFFF
#define MVEBU_RTC_WRCLK_PERIOD_DEFAULT 0x3FF
#define MVEBU_RTC_WRCLK_SETUP_OFFS 16
#define MVEBU_RTC_WRCLK_SETUP_MASK 0xFFFF0000
#define MVEBU_RTC_WRCLK_SETUP_DEFAULT 0x29
#define MVEBU_RTC_BRIDGE_TIMING_CTRL1_REG (MVEBU_RTC_BASE + 0x84)
#define MVEBU_RTC_READ_OUTPUT_DELAY_MASK 0xFFFF
#define MVEBU_RTC_READ_OUTPUT_DELAY_DEFAULT 0x1F
enum axi_attr {
AXI_ADUNIT_ATTR = 0,
AXI_COMUNIT_ATTR,
AXI_EIP197_ATTR,
AXI_USB3D_ATTR,
AXI_USB3H0_ATTR,
AXI_USB3H1_ATTR,
AXI_SATA0_ATTR,
AXI_SATA1_ATTR,
AXI_DAP_ATTR,
AXI_DFX_ATTR,
AXI_DBG_TRC_ATTR = 12,
AXI_SDIO_ATTR,
AXI_MSS_ATTR,
AXI_MAX_ATTR,
};
/* Most stream IDS are configured centrally in the CP-110 RFU
* but some are configured inside the unit registers
*/
#define RFU_STREAM_ID_BASE (0x450000)
#define USB3H_0_STREAM_ID_REG (RFU_STREAM_ID_BASE + 0xC)
#define USB3H_1_STREAM_ID_REG (RFU_STREAM_ID_BASE + 0x10)
#define SATA_0_STREAM_ID_REG (RFU_STREAM_ID_BASE + 0x14)
#define SATA_1_STREAM_ID_REG (RFU_STREAM_ID_BASE + 0x18)
#define CP_DMA_0_STREAM_ID_REG (0x6B0010)
#define CP_DMA_1_STREAM_ID_REG (0x6D0010)
/* We allocate IDs 128-255 for PCIe */
#define MAX_STREAM_ID (0x80)
uintptr_t stream_id_reg[] = {
USB3H_0_STREAM_ID_REG,
USB3H_1_STREAM_ID_REG,
CP_DMA_0_STREAM_ID_REG,
CP_DMA_1_STREAM_ID_REG,
SATA_0_STREAM_ID_REG,
SATA_1_STREAM_ID_REG,
0
};
static void cp110_errata_wa_init(uintptr_t base)
{
uint32_t data;
/* ERRATA GL-4076863:
* Reset value for global_secure_enable inputs must be changed
* from '1' to '0'.
* When asserted, only "secured" transactions can enter IHB
* configuration space.
* However, blocking AXI transactions is performed by IOB.
* Performing it also at IHB/HB complicates programming model.
*
* Enable non-secure access in SOC configuration register
*/
data = mmio_read_32(base + MVEBU_SOC_CFG_REG(MVEBU_SOC_CFG_REG_NUM));
data &= ~MVEBU_SOC_CFG_GLOG_SECURE_EN_MASK;
mmio_write_32(base + MVEBU_SOC_CFG_REG(MVEBU_SOC_CFG_REG_NUM), data);
}
static void cp110_pcie_clk_cfg(uintptr_t base)
{
uint32_t pcie0_clk, pcie1_clk, reg;
/*
* Determine the pcie0/1 clock direction (input/output) from the
* sample at reset.
*/
reg = mmio_read_32(base + MVEBU_SAMPLE_AT_RESET_REG);
pcie0_clk = (reg & SAR_PCIE0_CLK_CFG_MASK) >> SAR_PCIE0_CLK_CFG_OFFSET;
pcie1_clk = (reg & SAR_PCIE1_CLK_CFG_MASK) >> SAR_PCIE1_CLK_CFG_OFFSET;
/* CP110 revision A2 */
if (cp110_rev_id_get(base) == MVEBU_CP110_REF_ID_A2) {
/*
* PCIe Reference Clock Buffer Control register must be
* set according to the clock direction (input/output)
*/
reg = mmio_read_32(base + MVEBU_PCIE_REF_CLK_BUF_CTRL);
reg &= ~(PCIE0_REFCLK_BUFF_SOURCE | PCIE1_REFCLK_BUFF_SOURCE);
if (!pcie0_clk)
reg |= PCIE0_REFCLK_BUFF_SOURCE;
if (!pcie1_clk)
reg |= PCIE1_REFCLK_BUFF_SOURCE;
mmio_write_32(base + MVEBU_PCIE_REF_CLK_BUF_CTRL, reg);
}
/* CP110 revision A1 */
if (cp110_rev_id_get(base) == MVEBU_CP110_REF_ID_A1) {
if (!pcie0_clk || !pcie1_clk) {
/*
* if one of the pcie clocks is set to input,
* we need to set mss_push[131] field, otherwise,
* the pcie clock might not work.
*/
reg = mmio_read_32(base + MVEBU_CP_MSS_DPSHSR_REG);
reg |= MSS_DPSHSR_REG_PCIE_CLK_SEL;
mmio_write_32(base + MVEBU_CP_MSS_DPSHSR_REG, reg);
}
}
}
/* Set a unique stream id for all DMA capable devices */
static void cp110_stream_id_init(uintptr_t base, uint32_t stream_id)
{
int i = 0;
while (stream_id_reg[i]) {
if (i > MAX_STREAM_ID_PER_CP) {
NOTICE("Only first %d (maximum) Stream IDs allocated\n",
MAX_STREAM_ID_PER_CP);
return;
}
if ((stream_id_reg[i] == CP_DMA_0_STREAM_ID_REG) ||
(stream_id_reg[i] == CP_DMA_1_STREAM_ID_REG))
mmio_write_32(base + stream_id_reg[i],
stream_id << 16 | stream_id);
else
mmio_write_32(base + stream_id_reg[i], stream_id);
/* SATA port 0/1 are in the same SATA unit, and they should use
* the same STREAM ID number
*/
if (stream_id_reg[i] != SATA_0_STREAM_ID_REG)
stream_id++;
i++;
}
}
static void cp110_axi_attr_init(uintptr_t base)
{
uint32_t index, data;
/* Initialize AXI attributes for Armada-7K/8K SoC */
/* Go over the AXI attributes and set Ax-Cache and Ax-Domain */
for (index = 0; index < AXI_MAX_ATTR; index++) {
switch (index) {
/* DFX and MSS unit works with no coherent only -
* there's no option to configure the Ax-Cache and Ax-Domain
*/
case AXI_DFX_ATTR:
case AXI_MSS_ATTR:
continue;
default:
/* Set Ax-Cache as cacheable, no allocate, modifiable,
* bufferable
* The values are different because Read & Write
* definition is different in Ax-Cache
*/
data = mmio_read_32(base + MVEBU_AXI_ATTR_REG(index));
data &= ~MVEBU_AXI_ATTR_ARCACHE_MASK;
data |= (CACHE_ATTR_WRITE_ALLOC |
CACHE_ATTR_CACHEABLE |
CACHE_ATTR_BUFFERABLE) <<
MVEBU_AXI_ATTR_ARCACHE_OFFSET;
data &= ~MVEBU_AXI_ATTR_AWCACHE_MASK;
data |= (CACHE_ATTR_READ_ALLOC |
CACHE_ATTR_CACHEABLE |
CACHE_ATTR_BUFFERABLE) <<
MVEBU_AXI_ATTR_AWCACHE_OFFSET;
/* Set Ax-Domain as Outer domain */
data &= ~MVEBU_AXI_ATTR_ARDOMAIN_MASK;
data |= DOMAIN_OUTER_SHAREABLE <<
MVEBU_AXI_ATTR_ARDOMAIN_OFFSET;
data &= ~MVEBU_AXI_ATTR_AWDOMAIN_MASK;
data |= DOMAIN_OUTER_SHAREABLE <<
MVEBU_AXI_ATTR_AWDOMAIN_OFFSET;
mmio_write_32(base + MVEBU_AXI_ATTR_REG(index), data);
}
}
/* SATA IOCC supported, cache attributes
* for SATA MBUS to AXI configuration.
*/
data = mmio_read_32(base + MVEBU_SATA_M2A_AXI_PORT_CTRL_REG);
data &= ~MVEBU_SATA_M2A_AXI_AWCACHE_MASK;
data |= (CACHE_ATTR_WRITE_ALLOC |
CACHE_ATTR_CACHEABLE |
CACHE_ATTR_BUFFERABLE) <<
MVEBU_SATA_M2A_AXI_AWCACHE_OFFSET;
data &= ~MVEBU_SATA_M2A_AXI_ARCACHE_MASK;
data |= (CACHE_ATTR_READ_ALLOC |
CACHE_ATTR_CACHEABLE |
CACHE_ATTR_BUFFERABLE) <<
MVEBU_SATA_M2A_AXI_ARCACHE_OFFSET;
mmio_write_32(base + MVEBU_SATA_M2A_AXI_PORT_CTRL_REG, data);
/* Set all IO's AXI attribute to non-secure access. */
for (index = 0; index < MVEBU_AXI_PROT_REGS_NUM; index++)
mmio_write_32(base + MVEBU_AXI_PROT_REG(index),
DOMAIN_SYSTEM_SHAREABLE);
}
static void amb_bridge_init(uintptr_t base)
{
uint32_t reg;
/* Open AMB bridge Window to Access COMPHY/MDIO registers */
reg = mmio_read_32(base + MVEBU_AMB_IP_BRIDGE_WIN_REG(0));
reg &= ~(MVEBU_AMB_IP_BRIDGE_WIN_SIZE_MASK |
MVEBU_AMB_IP_BRIDGE_WIN_EN_MASK);
reg |= (0x7ff << MVEBU_AMB_IP_BRIDGE_WIN_SIZE_OFFSET) |
(0x1 << MVEBU_AMB_IP_BRIDGE_WIN_EN_OFFSET);
mmio_write_32(base + MVEBU_AMB_IP_BRIDGE_WIN_REG(0), reg);
}
static void cp110_rtc_init(uintptr_t base)
{
/* Update MBus timing parameters before accessing RTC registers */
mmio_clrsetbits_32(base + MVEBU_RTC_BRIDGE_TIMING_CTRL0_REG,
MVEBU_RTC_WRCLK_PERIOD_MASK,
MVEBU_RTC_WRCLK_PERIOD_DEFAULT);
mmio_clrsetbits_32(base + MVEBU_RTC_BRIDGE_TIMING_CTRL0_REG,
MVEBU_RTC_WRCLK_SETUP_MASK,
MVEBU_RTC_WRCLK_SETUP_DEFAULT <<
MVEBU_RTC_WRCLK_SETUP_OFFS);
mmio_clrsetbits_32(base + MVEBU_RTC_BRIDGE_TIMING_CTRL1_REG,
MVEBU_RTC_READ_OUTPUT_DELAY_MASK,
MVEBU_RTC_READ_OUTPUT_DELAY_DEFAULT);
/*
* Issue reset to the RTC if Clock Correction register
* contents did not sustain the reboot/power-on.
*/
if ((mmio_read_32(base + MVEBU_RTC_CCR_REG) &
MVEBU_RTC_NOMINAL_TIMING_MASK) != MVEBU_RTC_NOMINAL_TIMING) {
/* Reset Test register */
mmio_write_32(base + MVEBU_RTC_TEST_CONFIG_REG, 0);
mdelay(500);
/* Reset Time register */
mmio_write_32(base + MVEBU_RTC_TIME_REG, 0);
udelay(62);
/* Reset Status register */
mmio_write_32(base + MVEBU_RTC_STATUS_REG,
(MVEBU_RTC_STATUS_ALARM1_MASK |
MVEBU_RTC_STATUS_ALARM2_MASK));
udelay(62);
/* Turn off Int1 and Int2 sources & clear the Alarm count */
mmio_write_32(base + MVEBU_RTC_IRQ_1_CONFIG_REG, 0);
mmio_write_32(base + MVEBU_RTC_IRQ_2_CONFIG_REG, 0);
mmio_write_32(base + MVEBU_RTC_ALARM_1_REG, 0);
mmio_write_32(base + MVEBU_RTC_ALARM_2_REG, 0);
/* Setup nominal register access timing */
mmio_write_32(base + MVEBU_RTC_CCR_REG,
MVEBU_RTC_NOMINAL_TIMING);
/* Reset Time register */
mmio_write_32(base + MVEBU_RTC_TIME_REG, 0);
udelay(10);
/* Reset Status register */
mmio_write_32(base + MVEBU_RTC_STATUS_REG,
(MVEBU_RTC_STATUS_ALARM1_MASK |
MVEBU_RTC_STATUS_ALARM2_MASK));
udelay(50);
}
}
static void cp110_amb_adec_init(uintptr_t base)
{
/* enable AXI-MBUS by clearing "Bridge Windows Disable" */
mmio_clrbits_32(base + MVEBU_BRIDGE_WIN_DIS_REG,
(1 << MVEBU_BRIDGE_WIN_DIS_OFF));
/* configure AXI-MBUS windows for CP */
init_amb_adec(base);
}
void cp110_init(uintptr_t cp110_base, uint32_t stream_id)
{
INFO("%s: Initialize CPx - base = %lx\n", __func__, cp110_base);
/* configure IOB windows for CP0*/
init_iob(cp110_base);
/* configure AXI-MBUS windows for CP0*/
cp110_amb_adec_init(cp110_base);
/* configure axi for CP0*/
cp110_axi_attr_init(cp110_base);
/* Execute SW WA for erratas */
cp110_errata_wa_init(cp110_base);
/* Confiure pcie clock according to clock direction */
cp110_pcie_clk_cfg(cp110_base);
/* configure stream id for CP0 */
cp110_stream_id_init(cp110_base, stream_id);
/* Open AMB bridge for comphy for CP0 & CP1*/
amb_bridge_init(cp110_base);
/* Reset RTC if needed */
cp110_rtc_init(cp110_base);
}
/* Do the minimal setup required to configure the CP in BLE */
void cp110_ble_init(uintptr_t cp110_base)
{
#if PCI_EP_SUPPORT
INFO("%s: Initialize CPx - base = %lx\n", __func__, cp110_base);
amb_bridge_init(cp110_base);
/* Configure PCIe clock */
cp110_pcie_clk_cfg(cp110_base);
/* Configure PCIe endpoint */
ble_plat_pcie_ep_setup();
#endif
}
/*
* Copyright (C) 2018 Marvell International Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
* https://spdx.org/licenses
*/
/* Driver for thermal unit located in Marvell ARMADA 8K and compatible SoCs */
#include <debug.h>
#include <thermal.h>
int marvell_thermal_init(struct tsen_config *tsen_cfg)
{
if (tsen_cfg->tsen_ready == 1) {
INFO("thermal sensor is already initialized\n");
return 0;
}
if (tsen_cfg->ptr_tsen_probe == NULL) {
ERROR("initial thermal sensor configuration is missing\n");
return -1;
}
if (tsen_cfg->ptr_tsen_probe(tsen_cfg)) {
ERROR("thermal sensor initialization failed\n");
return -1;
}
VERBOSE("thermal sensor was initialized\n");
return 0;
}
int marvell_thermal_read(struct tsen_config *tsen_cfg, int *temp)
{
if (temp == NULL) {
ERROR("NULL pointer for temperature read\n");
return -1;
}
if (tsen_cfg->ptr_tsen_read == NULL ||
tsen_cfg->tsen_ready == 0) {
ERROR("thermal sensor was not initialized\n");
return -1;
}
if (tsen_cfg->ptr_tsen_read(tsen_cfg, temp)) {
ERROR("temperature read failed\n");
return -1;
}
return 0;
}
/*
* Copyright (C) 2018 Marvell International Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
* https://spdx.org/licenses
*/
/* This driver provides I2C support for Marvell A8K and compatible SoCs */
#ifndef _A8K_I2C_H_
#define _A8K_I2C_H_
#include <stdint.h>
/*
* Initialization, must be called once on start up, may be called
* repeatedly to change the speed and slave addresses.
*/
void i2c_init(void *i2c_base);
/*
* Read/Write interface:
* chip: I2C chip address, range 0..127
* addr: Memory (register) address within the chip
* alen: Number of bytes to use for addr (typically 1, 2 for larger
* memories, 0 for register type devices with only one
* register)
* buffer: Where to read/write the data
* len: How many bytes to read/write
*
* Returns: 0 on success, not 0 on failure
*/
int i2c_read(uint8_t chip,
unsigned int addr, int alen, uint8_t *buffer, int len);
int i2c_write(uint8_t chip,
unsigned int addr, int alen, uint8_t *buffer, int len);
#endif
/*
* Copyright (C) 2018 Marvell International Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
* https://spdx.org/licenses
*/
/* Address map types for Marvell address translation unit drivers */
#ifndef _ADDR_MAP_H_
#define _ADDR_MAP_H_
#include <stdint.h>
struct addr_map_win {
uint64_t base_addr;
uint64_t win_size;
uint32_t target_id;
};
#endif /* _ADDR_MAP_H_ */
/*
* Copyright (C) 2018 Marvell International Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
* https://spdx.org/licenses
*/
/* AXI to M-Bridge decoding unit driver for Marvell Armada 8K and 8K+ SoCs */
#ifndef _AMB_ADEC_H_
#define _AMB_ADEC_H_
#include <stdint.h>
enum amb_attribute_ids {
AMB_SPI0_CS0_ID = 0x1E,
AMB_SPI0_CS1_ID = 0x5E,
AMB_SPI0_CS2_ID = 0x9E,
AMB_SPI0_CS3_ID = 0xDE,
AMB_SPI1_CS0_ID = 0x1A,
AMB_SPI1_CS1_ID = 0x5A,
AMB_SPI1_CS2_ID = 0x9A,
AMB_SPI1_CS3_ID = 0xDA,
AMB_DEV_CS0_ID = 0x3E,
AMB_DEV_CS1_ID = 0x3D,
AMB_DEV_CS2_ID = 0x3B,
AMB_DEV_CS3_ID = 0x37,
AMB_BOOT_CS_ID = 0x2f,
AMB_BOOT_ROM_ID = 0x1D,
};
#define AMB_MAX_WIN_ID 7
int init_amb_adec(uintptr_t base);
#endif /* _AMB_ADEC_H_ */
/*
* Copyright (C) 2017 Marvell International Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
* https://spdx.org/licenses
*/
#ifndef _ARO_H_
#define _ARO_H_
enum hws_freq {
CPU_FREQ_2000,
CPU_FREQ_1800,
CPU_FREQ_1600,
CPU_FREQ_1400,
CPU_FREQ_1300,
CPU_FREQ_1200,
CPU_FREQ_1000,
CPU_FREQ_600,
CPU_FREQ_800,
DDR_FREQ_LAST,
DDR_FREQ_SAR
};
enum cpu_clock_freq_mode {
CPU_2000_DDR_1200_RCLK_1200 = 0x0,
CPU_2000_DDR_1050_RCLK_1050 = 0x1,
CPU_1600_DDR_800_RCLK_800 = 0x4,
CPU_1800_DDR_1200_RCLK_1200 = 0x6,
CPU_1800_DDR_1050_RCLK_1050 = 0x7,
CPU_1600_DDR_900_RCLK_900 = 0x0B,
CPU_1600_DDR_1050_RCLK_1050 = 0x0D,
CPU_1600_DDR_900_RCLK_900_2 = 0x0E,
CPU_1000_DDR_650_RCLK_650 = 0x13,
CPU_1300_DDR_800_RCLK_800 = 0x14,
CPU_1300_DDR_650_RCLK_650 = 0x17,
CPU_1200_DDR_800_RCLK_800 = 0x19,
CPU_1400_DDR_800_RCLK_800 = 0x1a,
CPU_600_DDR_800_RCLK_800 = 0x1B,
CPU_800_DDR_800_RCLK_800 = 0x1C,
CPU_1000_DDR_800_RCLK_800 = 0x1D,
CPU_DDR_RCLK_INVALID
};
int init_aro(void);
#endif /* _ARO_H_ */
/*
* Copyright (C) 2018 Marvell International Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
* https://spdx.org/licenses
*/
/* LLC driver is the Last Level Cache (L3C) driver
* for Marvell SoCs in AP806, AP807, and AP810
*/
#ifndef _CACHE_LLC_H_
#define _CACHE_LLC_H_
#define LLC_CTRL(ap) (MVEBU_LLC_BASE(ap) + 0x100)
#define LLC_SYNC(ap) (MVEBU_LLC_BASE(ap) + 0x700)
#define L2X0_INV_WAY(ap) (MVEBU_LLC_BASE(ap) + 0x77C)
#define L2X0_CLEAN_WAY(ap) (MVEBU_LLC_BASE(ap) + 0x7BC)
#define L2X0_CLEAN_INV_WAY(ap) (MVEBU_LLC_BASE(ap) + 0x7FC)
#define LLC_TC0_LOCK(ap) (MVEBU_LLC_BASE(ap) + 0x920)
#define MASTER_LLC_CTRL LLC_CTRL(MVEBU_AP0)
#define MASTER_L2X0_INV_WAY L2X0_INV_WAY(MVEBU_AP0)
#define MASTER_LLC_TC0_LOCK LLC_TC0_LOCK(MVEBU_AP0)
#define LLC_CTRL_EN 1
#define LLC_EXCLUSIVE_EN 0x100
#define LLC_WAY_MASK 0xFFFFFFFF
#ifndef __ASSEMBLY__
void llc_cache_sync(int ap_index);
void llc_flush_all(int ap_index);
void llc_clean_all(int ap_index);
void llc_inv_all(int ap_index);
void llc_disable(int ap_index);
void llc_enable(int ap_index, int excl_mode);
int llc_is_exclusive(int ap_index);
void llc_runtime_enable(int ap_index);
#endif
#endif /* _CACHE_LLC_H_ */
/*
* Copyright (C) 2018 Marvell International Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
* https://spdx.org/licenses
*/
/* CCU unit device driver for Marvell AP807, AP807 and AP810 SoCs */
#ifndef _CCU_H_
#define _CCU_H_
#ifndef __ASSEMBLY__
#include <addr_map.h>
#endif
/* CCU registers definitions */
#define CCU_WIN_CR_OFFSET(ap, win) (MVEBU_CCU_BASE(ap) + 0x0 + \
(0x10 * win))
#define CCU_TARGET_ID_OFFSET (8)
#define CCU_TARGET_ID_MASK (0x7F)
#define CCU_WIN_SCR_OFFSET(ap, win) (MVEBU_CCU_BASE(ap) + 0x4 + \
(0x10 * win))
#define CCU_WIN_ENA_WRITE_SECURE (0x1)
#define CCU_WIN_ENA_READ_SECURE (0x2)
#define CCU_WIN_ALR_OFFSET(ap, win) (MVEBU_CCU_BASE(ap) + 0x8 + \
(0x10 * win))
#define CCU_WIN_AHR_OFFSET(ap, win) (MVEBU_CCU_BASE(ap) + 0xC + \
(0x10 * win))
#define CCU_WIN_GCR_OFFSET(ap) (MVEBU_CCU_BASE(ap) + 0xD0)
#define CCU_GCR_TARGET_OFFSET (8)
#define CCU_GCR_TARGET_MASK (0xFF)
#define CCU_SRAM_WIN_CR CCU_WIN_CR_OFFSET(MVEBU_AP0, 1)
#ifndef __ASSEMBLY__
int init_ccu(int);
void ccu_win_check(struct addr_map_win *win);
void ccu_enable_win(int ap_index, struct addr_map_win *win, uint32_t win_id);
void ccu_temp_win_insert(int ap_index, struct addr_map_win *win, int size);
void ccu_temp_win_remove(int ap_index, struct addr_map_win *win, int size);
void ccu_dram_win_config(int ap_index, struct addr_map_win *win);
void ccu_dram_target_set(int ap_index, uint32_t target);
void ccu_save_win_all(int ap_id);
void ccu_restore_win_all(int ap_id);
#endif
#endif /* _CCU_H_ */
/*
* Copyright (C) 2018 Marvell International Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
* https://spdx.org/licenses
*/
/* GWIN unit device driver for Marvell AP810 SoC */
#ifndef _GWIN_H_
#define _GWIN_H_
#include <addr_map.h>
int init_gwin(int ap_index);
void gwin_temp_win_insert(int ap_index, struct addr_map_win *win, int size);
void gwin_temp_win_remove(int ap_index, struct addr_map_win *win, int size);
#endif /* _GWIN_H_ */
/*
* Copyright (C) 2018 Marvell International Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
* https://spdx.org/licenses
*/
#ifndef _I2C_H_
#define _I2C_H_
void i2c_init(void);
int i2c_read(uint8_t chip,
unsigned int addr, int alen, uint8_t *buffer, int len);
int i2c_write(uint8_t chip,
unsigned int addr, int alen, uint8_t *buffer, int len);
#endif
/*
* Copyright (C) 2018 Marvell International Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
* https://spdx.org/licenses
*/
/* IO Window unit device driver for Marvell AP807, AP807 and AP810 SoCs */
#ifndef _IO_WIN_H_
#define _IO_WIN_H_
#include <addr_map.h>
int init_io_win(int ap_index);
void iow_temp_win_insert(int ap_index, struct addr_map_win *win, int size);
void iow_temp_win_remove(int ap_index, struct addr_map_win *win, int size);
void iow_save_win_all(int ap_id);
void iow_restore_win_all(int ap_id);
#endif /* _IO_WIN_H_ */
/*
* Copyright (C) 2018 Marvell International Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
* https://spdx.org/licenses
*/
/* IOW unit device driver for Marvell CP110 and CP115 SoCs */
#ifndef _IOB_H_
#define _IOB_H_
#include <addr_map.h>
enum target_ids_iob {
INTERNAL_TID = 0x0,
MCI0_TID = 0x1,
PEX1_TID = 0x2,
PEX2_TID = 0x3,
PEX0_TID = 0x4,
NAND_TID = 0x5,
RUNIT_TID = 0x6,
MCI1_TID = 0x7,
IOB_MAX_TID
};
int init_iob(uintptr_t base);
void iob_cfg_space_update(int ap_idx, int cp_idx,
uintptr_t base, uintptr_t new_base);
#endif /* _IOB_H_ */
/*
* Copyright (C) 2018 Marvell International Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
* https://spdx.org/licenses
*/
/* MCI bus driver for Marvell ARMADA 8K and 8K+ SoCs */
#ifndef _MCI_H_
#define _MCI_H_
int mci_initialize(int mci_index);
void mci_turn_link_down(void);
void mci_turn_link_on(void);
int mci_get_link_status(void);
#endif /* _MCI_H_ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment