Commit 9719e19a authored by Joanna Farley's avatar Joanna Farley Committed by TrustedFirmware Code Review
Browse files

Merge changes I500ddbe9,I9c10dac9,I53bfff85,I06f7594d,I24bff8d4, ... into integration

* changes:
  nxp lx2160a-aqds: new plat based on soc lx2160a
  NXP lx2160a-rdb: new plat based on SoC lx2160a
  nxp lx2162aqds: new plat based on soc lx2160a
  nxp: errata handling at soc level for lx2160a
  nxp: make file for loading additional ddr image
  nxp: adding support of soc lx2160a
  nxp: deflt hdr files for soc & their platforms
  nxp: platform files for bl2 and bl31 setup
  nxp: warm reset support to retain ddr content
  nxp: nv storage api on platforms
  nxp: supports two mode of trusted board boot
  nxp: fip-handler for additional fip_fuse.bin
  nxp: fip-handler for additional ddr-fip.bin
  nxp: image loader for loading fip image
  nxp: svp & sip smc handling
  nxp: psci platform functions used by lib/psci
  nxp: helper function used by plat & common code
  nxp: add data handler used by bl31
  nxp: adding the driver.mk file
  nxp-tool: for creating pbl file from bl2
  nxp: adding the smmu driver
  nxp: cot using nxp internal and mbedtls
  nxp:driver for crypto h/w accelerator caam
  nxp:add driver support for sd and emmc
  nxp:add qspi driver
  nxp: add flexspi driver support
  nxp: adding gic apis for nxp soc
  nxp: gpio driver support
  nxp: added csu driver
  nxp: driver pmu for nxp soc
  nxp: ddr driver enablement for nxp layerscape soc
  nxp: i2c driver support.
  NXP: Driver for NXP Security Monitor
  NXP: SFP driver support for NXP SoC
  NXP: Interconnect API based on ARM CCN-CCI driver
  NXP: TZC API to configure ddr region
  NXP: Timer API added to enable ARM generic timer
  nxp: add dcfg driver
  nxp:add console driver for nxp platform
  tools: add mechanism to allow platform specific image UUID
  tbbr-cot: conditional definition for the macro
  tbbr-cot: fix the issue of compiling time define
  cert_create: updated tool for platform defined certs, keys & extensions
  tbbr-tools: enable override TRUSTED_KEY_CERT
parents b59444ea f359a382
/*
* Copyright 2021 NXP
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#ifndef PLAT_GICV2_H
#define PLAT_GICV2_H
#include <drivers/arm/gicv2.h>
/* register offsets */
#define GICD_CTLR_OFFSET 0x0
#define GICD_CPENDSGIR3_OFFSET 0xF1C
#define GICD_SPENDSGIR3_OFFSET 0xF2C
#define GICD_SGIR_OFFSET 0xF00
#define GICD_IGROUPR0_OFFSET 0x080
#define GICD_TYPER_OFFSET 0x0004
#define GICD_ISENABLER0_OFFSET 0x0100
#define GICD_ICENABLER0_OFFSET 0x0180
#define GICD_IPRIORITYR3_OFFSET 0x040C
#define GICD_ISENABLERn_OFFSET 0x0100
#define GICD_ISACTIVER0_OFFSET 0x300
#define GICC_CTLR_OFFSET 0x0
#define GICC_PMR_OFFSET 0x0004
#define GICC_IAR_OFFSET 0x000C
#define GICC_DIR_OFFSET 0x1000
#define GICC_EOIR_OFFSET 0x0010
/* bitfield masks */
#define GICC_CTLR_EN_GRP0 0x1
#define GICC_CTLR_EN_GRP1 0x2
#define GICC_CTLR_EOImodeS_MASK 0x200
#define GICC_CTLR_DIS_BYPASS 0x60
#define GICC_CTLR_CBPR_MASK 0x10
#define GICC_CTLR_FIQ_EN_MASK 0x8
#define GICC_CTLR_ACKCTL_MASK 0x4
#define GICC_PMR_FILTER 0xFF
#define GICD_CTLR_EN_GRP0 0x1
#define GICD_CTLR_EN_GRP1 0x2
#define GICD_IGROUP0_SGI15 0x8000
#define GICD_ISENABLE0_SGI15 0x8000
#define GICD_ICENABLE0_SGI15 0x8000
#define GICD_ISACTIVER0_SGI15 0x8000
#define GICD_CPENDSGIR_CLR_MASK 0xFF000000
#define GICD_IPRIORITY_SGI15_MASK 0xFF000000
#define GICD_SPENDSGIR3_SGI15_MASK 0xFF000000
#define GICD_SPENDSGIR3_SGI15_OFFSET 0x18
#ifndef __ASSEMBLER__
/* GIC common API's */
void plat_ls_gic_driver_init(const uintptr_t nxp_gicd_addr,
const uintptr_t nxp_gicc_addr,
uint8_t plat_core_count,
interrupt_prop_t *ls_interrupt_props,
uint8_t ls_interrupt_prop_count,
uint32_t *target_mask_array);
void plat_ls_gic_init(void);
void plat_ls_gic_cpuif_enable(void);
void plat_ls_gic_cpuif_disable(void);
void plat_ls_gic_redistif_on(void);
void plat_ls_gic_redistif_off(void);
void plat_gic_pcpu_init(void);
/* GIC utility functions */
void get_gic_offset(uint32_t *gicc_base, uint32_t *gicd_base);
#endif
#endif /* PLAT_GICV2_H */
/*
* Copyright 2021 NXP
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#ifndef PLAT_GICV3_H
#define PLAT_GICV3_H
#include <drivers/arm/gicv3.h>
/* offset between redistributors */
#define GIC_RD_OFFSET 0x00020000
/* offset between SGI's */
#define GIC_SGI_OFFSET 0x00020000
/* offset from rd base to sgi base */
#define GIC_RD_2_SGI_OFFSET 0x00010000
/* register offsets */
#define GICD_CTLR_OFFSET 0x0
#define GICD_CLR_SPI_SR 0x58
#define GICD_IGROUPR_2 0x88
#define GICD_ISENABLER_2 0x108
#define GICD_ICENABLER_2 0x188
#define GICD_ICPENDR_2 0x288
#define GICD_ICACTIVER_2 0x388
#define GICD_IPRIORITYR_22 0x458
#define GICD_ICFGR_5 0xC14
#define GICD_IGRPMODR_2 0xD08
#define GICD_IROUTER60_OFFSET 0x61e0
#define GICD_IROUTER76_OFFSET 0x6260
#define GICD_IROUTER89_OFFSET 0x62C8
#define GICD_IROUTER112_OFFSET 0x6380
#define GICD_IROUTER113_OFFSET 0x6388
#define GICR_ICENABLER0_OFFSET 0x180
#define GICR_CTLR_OFFSET 0x0
#define GICR_IGROUPR0_OFFSET 0x80
#define GICR_IGRPMODR0_OFFSET 0xD00
#define GICR_IPRIORITYR3_OFFSET 0x40C
#define GICR_ICPENDR0_OFFSET 0x280
#define GICR_ISENABLER0_OFFSET 0x100
#define GICR_TYPER_OFFSET 0x8
#define GICR_WAKER_OFFSET 0x14
#define GICR_ICACTIVER0_OFFSET 0x380
#define GICR_ICFGR0_OFFSET 0xC00
/* bitfield masks */
#define GICD_CTLR_EN_GRP_MASK 0x7
#define GICD_CTLR_EN_GRP_1NS 0x2
#define GICD_CTLR_EN_GRP_1S 0x4
#define GICD_CTLR_EN_GRP_0 0x1
#define GICD_CTLR_ARE_S_MASK 0x10
#define GICD_CTLR_RWP 0x80000000
#define GICR_ICENABLER0_SGI15 0x00008000
#define GICR_CTLR_RWP 0x8
#define GICR_CTLR_DPG0_MASK 0x2000000
#define GICR_IGROUPR0_SGI15 0x00008000
#define GICR_IGRPMODR0_SGI15 0x00008000
#define GICR_ISENABLER0_SGI15 0x00008000
#define GICR_IPRIORITYR3_SGI15_MASK 0xFF000000
#define GICR_ICPENDR0_SGI15 0x8000
#define GIC_SPI_89_MASK 0x02000000
#define GIC_SPI89_PRIORITY_MASK 0xFF00
#define GIC_IRM_SPI89 0x80000000
#define GICD_IROUTER_VALUE 0x100
#define GICR_WAKER_SLEEP_BIT 0x2
#define GICR_WAKER_ASLEEP (1 << 2 | 1 << 1)
#define ICC_SRE_EL3_SRE 0x1
#define ICC_IGRPEN0_EL1_EN 0x1
#define ICC_CTLR_EL3_CBPR_EL1S 0x1
#define ICC_CTLR_EL3_RM 0x20
#define ICC_CTLR_EL3_EOIMODE_EL3 0x4
#define ICC_CTLR_EL3_PMHE 0x40
#define ICC_PMR_EL1_P_FILTER 0xFF
#define ICC_IAR0_EL1_SGI15 0xF
#define ICC_SGI0R_EL1_INTID 0x0F000000
#define ICC_IAR0_INTID_SPI_89 0x59
#define ICC_IGRPEN1_EL1 S3_0_C12_C12_7
#define ICC_PMR_EL1 S3_0_C4_C6_0
#define ICC_SRE_EL3 S3_6_C12_C12_5
#define ICC_CTLR_EL3 S3_6_C12_C12_4
#define ICC_SRE_EL2 S3_4_C12_C9_5
#define ICC_CTLR_EL1 S3_0_C12_C12_4
#ifndef __ASSEMBLER__
/* GIC common API's */
typedef unsigned int (*my_core_pos_fn)(void);
void plat_ls_gic_driver_init(const uintptr_t nxp_gicd_addr,
const uintptr_t nxp_gicr_addr,
uint8_t plat_core_count,
interrupt_prop_t *ls_interrupt_props,
uint8_t ls_interrupt_prop_count,
uintptr_t *target_mask_array,
mpidr_hash_fn mpidr_to_core_pos);
//void plat_ls_gic_driver_init(void);
void plat_ls_gic_init(void);
void plat_ls_gic_cpuif_enable(void);
void plat_ls_gic_cpuif_disable(void);
void plat_ls_gic_redistif_on(void);
void plat_ls_gic_redistif_off(void);
void plat_gic_pcpu_init(void);
#endif
#endif /* PLAT_GICV3_H */
/*
* Copyright 2021 NXP
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#include <gicv2.h>
#include <plat_gic.h>
/*
* NXP common helper to initialize the GICv3 only driver.
*/
void plat_ls_gic_driver_init(uintptr_t nxp_gicd_addr,
uintptr_t nxp_gicc_addr,
uint8_t plat_core_count,
interrupt_prop_t *ls_interrupt_props,
uint8_t ls_interrupt_prop_count,
uint32_t *target_mask_array)
{
static struct gicv2_driver_data ls_gic_data;
ls_gic_data.gicd_base = nxp_gicd_addr;
ls_gic_data.gicc_base = nxp_gicc_addr;
ls_gic_data.target_masks = target_mask_array;
ls_gic_data.target_masks_num = plat_core_count;
ls_gic_data.interrupt_props = ls_interrupt_props;
ls_gic_data.interrupt_props_num = ls_interrupt_prop_count;
gicv2_driver_init(&ls_gic_data);
}
void plat_ls_gic_init(void)
{
gicv2_distif_init();
gicv2_pcpu_distif_init();
gicv2_cpuif_enable();
}
/******************************************************************************
* ARM common helper to enable the GICv2 CPU interface
*****************************************************************************/
void plat_ls_gic_cpuif_enable(void)
{
gicv2_cpuif_enable();
}
/******************************************************************************
* ARM common helper to disable the GICv2 CPU interface
*****************************************************************************/
void plat_ls_gic_cpuif_disable(void)
{
gicv2_cpuif_disable();
}
/******************************************************************************
* NXP common helper to initialize GICv2 per cpu
*****************************************************************************/
void plat_gic_pcpu_init(void)
{
gicv2_pcpu_distif_init();
gicv2_cpuif_enable();
}
/******************************************************************************
* Stubs for Redistributor power management. Although GICv2 doesn't have
* Redistributor interface, these are provided for the sake of uniform GIC API
*****************************************************************************/
void plat_ls_gic_redistif_on(void)
{
}
void plat_ls_gic_redistif_off(void)
{
}
/*
* Copyright 2021 NXP
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#include <drivers/arm/gicv3.h>
#include <plat_gic.h>
#include <plat/common/platform.h>
/*
* NXP common helper to initialize the GICv3 only driver.
*/
void plat_ls_gic_driver_init(uintptr_t nxp_gicd_addr,
uintptr_t nxp_gicr_addr,
uint8_t plat_core_count,
interrupt_prop_t *ls_interrupt_props,
uint8_t ls_interrupt_prop_count,
uintptr_t *target_mask_array,
mpidr_hash_fn mpidr_to_core_pos)
{
static struct gicv3_driver_data ls_gic_data;
ls_gic_data.gicd_base = nxp_gicd_addr;
ls_gic_data.gicr_base = nxp_gicr_addr;
ls_gic_data.interrupt_props = ls_interrupt_props;
ls_gic_data.interrupt_props_num = ls_interrupt_prop_count;
ls_gic_data.rdistif_num = plat_core_count;
ls_gic_data.rdistif_base_addrs = target_mask_array;
ls_gic_data.mpidr_to_core_pos = mpidr_to_core_pos;
gicv3_driver_init(&ls_gic_data);
}
void plat_ls_gic_init(void)
{
gicv3_distif_init();
gicv3_rdistif_init(plat_my_core_pos());
gicv3_cpuif_enable(plat_my_core_pos());
}
/*
* NXP common helper to enable the GICv3 CPU interface
*/
void plat_ls_gic_cpuif_enable(void)
{
gicv3_cpuif_enable(plat_my_core_pos());
}
/*
* NXP common helper to disable the GICv3 CPU interface
*/
void plat_ls_gic_cpuif_disable(void)
{
gicv3_cpuif_disable(plat_my_core_pos());
}
/*
* NXP common helper to initialize the per cpu distributor interface in GICv3
*/
void plat_gic_pcpu_init(void)
{
gicv3_rdistif_init(plat_my_core_pos());
gicv3_cpuif_enable(plat_my_core_pos());
}
/*
* Stubs for Redistributor power management. Although GICv3 doesn't have
* Redistributor interface, these are provided for the sake of uniform GIC API
*/
void plat_ls_gic_redistif_on(void)
{
}
void plat_ls_gic_redistif_off(void)
{
}
#
# Copyright 2021 NXP
#
# SPDX-License-Identifier: BSD-3-Clause
#
#-----------------------------------------------------------------------------
ifeq (${GPIO_ADDED},)
GPIO_ADDED := 1
GPIO_DRIVERS_PATH := drivers/nxp/gpio
PLAT_INCLUDES += -I$(GPIO_DRIVERS_PATH)
GPIO_SOURCES := $(GPIO_DRIVERS_PATH)/nxp_gpio.c
ifeq (${BL_COMM_GPIO_NEEDED},yes)
BL_COMMON_SOURCES += ${GPIO_SOURCES}
else
ifeq (${BL2_GPIO_NEEDED},yes)
BL2_SOURCES += ${GPIO_SOURCES}
endif
ifeq (${BL31_GPIO_NEEDED},yes)
BL31_SOURCES += ${GPIO_SOURCES}
endif
endif
endif
#------------------------------------------------
/*
* Copyright 2021 NXP
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#include <common/debug.h>
#include <lib/mmio.h>
#include <nxp_gpio.h>
static gpio_init_info_t *gpio_init_info;
void gpio_init(gpio_init_info_t *gpio_init_data)
{
gpio_init_info = gpio_init_data;
}
/* This function set GPIO pin for raising POVDD. */
int set_gpio_bit(uint32_t *gpio_base_addr,
uint32_t bit_num)
{
uint32_t val = 0U;
uint32_t *gpdir = NULL;
uint32_t *gpdat = NULL;
if (gpio_init_info == NULL) {
ERROR("GPIO is not initialized.\n");
return GPIO_FAILURE;
}
gpdir = gpio_base_addr + GPDIR_REG_OFFSET;
gpdat = gpio_base_addr + (GPDAT_REG_OFFSET >> 2);
/*
* Set the corresponding bit in direction register
* to configure the GPIO as output.
*/
val = gpio_read32(gpdir);
val = val | bit_num;
gpio_write32(gpdir, val);
/* Set the corresponding bit in GPIO data register */
val = gpio_read32(gpdat);
val = val | bit_num;
gpio_write32(gpdat, val);
val = gpio_read32(gpdat);
if ((val & bit_num) == 0U) {
return GPIO_FAILURE;
}
return GPIO_SUCCESS;
}
/* This function reset GPIO pin set for raising POVDD. */
int clr_gpio_bit(uint32_t *gpio_base_addr, uint32_t bit_num)
{
uint32_t val = 0U;
uint32_t *gpdir = NULL;
uint32_t *gpdat = NULL;
if (gpio_init_info == NULL) {
ERROR("GPIO is not initialized.\n");
return GPIO_FAILURE;
}
gpdir = gpio_base_addr + GPDIR_REG_OFFSET;
gpdat = gpio_base_addr + GPDAT_REG_OFFSET;
/*
* Reset the corresponding bit in direction and data register
* to configure the GPIO as input.
*/
val = gpio_read32(gpdat);
val = val & ~(bit_num);
gpio_write32(gpdat, val);
val = gpio_read32(gpdat);
val = gpio_read32(gpdir);
val = val & ~(bit_num);
gpio_write32(gpdir, val);
val = gpio_read32(gpdat);
if ((val & bit_num) != 0U) {
return GPIO_FAILURE;
}
return GPIO_SUCCESS;
}
uint32_t *select_gpio_n_bitnum(uint32_t povdd_gpio, uint32_t *bit_num)
{
uint32_t *ret_gpio;
uint32_t povdd_gpio_val = 0U;
uint32_t gpio_num = 0U;
if (gpio_init_info == NULL) {
ERROR("GPIO is not initialized.\n");
}
/*
* Subtract 1 from fuse_hdr povdd_gpio value as
* for 0x1 value, bit 0 is to be set
* for 0x20 value i.e 32, bit 31 i.e. 0x1f is to be set.
* 0x1f - 0x00 : GPIO_1
* 0x3f - 0x20 : GPIO_2
* 0x5f - 0x40 : GPIO_3
* 0x7f - 0x60 : GPIO_4
*/
povdd_gpio_val = (povdd_gpio - 1U) & GPIO_SEL_MASK;
/* Right shift by 5 to divide by 32 */
gpio_num = povdd_gpio_val >> GPIO_ID_BASE_ADDR_SHIFT;
*bit_num = 1U << (GPIO_BITS_PER_BASE_REG
- (povdd_gpio_val & GPIO_BIT_MASK)
- 1U);
switch (gpio_num) {
case GPIO_0:
ret_gpio = (uint32_t *) gpio_init_info->gpio1_base_addr;
break;
case GPIO_1:
ret_gpio = (uint32_t *) gpio_init_info->gpio2_base_addr;
break;
case GPIO_2:
ret_gpio = (uint32_t *) gpio_init_info->gpio3_base_addr;
break;
case GPIO_3:
ret_gpio = (uint32_t *) gpio_init_info->gpio4_base_addr;
break;
default:
ret_gpio = NULL;
}
if (ret_gpio == NULL) {
INFO("GPIO_NUM = %d doesn't exist.\n", gpio_num);
}
return ret_gpio;
}
/*
* Copyright 2021 NXP
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#ifndef PLAT_GPIO_H
#define PLAT_GPIO_H
#include <endian.h>
#include <lib/mmio.h>
/* GPIO Register offset */
#define GPIO_SEL_MASK 0x7F
#define GPIO_BIT_MASK 0x1F
#define GPDIR_REG_OFFSET 0x0
#define GPDAT_REG_OFFSET 0x8
#define GPIO_ID_BASE_ADDR_SHIFT 5U
#define GPIO_BITS_PER_BASE_REG 32U
#define GPIO_0 0
#define GPIO_1 1
#define GPIO_2 2
#define GPIO_3 3
#define GPIO_SUCCESS 0x0
#define GPIO_FAILURE 0x1
#ifdef NXP_GPIO_BE
#define gpio_read32(a) bswap32(mmio_read_32((uintptr_t)(a)))
#define gpio_write32(a, v) mmio_write_32((uintptr_t)(a), bswap32(v))
#elif defined(NXP_GPIO_LE)
#define gpio_read32(a) mmio_read_32((uintptr_t)(a))
#define gpio_write32(a, v) mmio_write_32((uintptr_t)(a), (v))
#else
#error Please define GPIO register endianness
#endif
typedef struct {
uintptr_t gpio1_base_addr;
uintptr_t gpio2_base_addr;
uintptr_t gpio3_base_addr;
uintptr_t gpio4_base_addr;
} gpio_init_info_t;
void gpio_init(gpio_init_info_t *gpio_init_data);
uint32_t *select_gpio_n_bitnum(uint32_t povdd_gpio, uint32_t *bit_num);
int clr_gpio_bit(uint32_t *gpio_base_addr, uint32_t bit_num);
int set_gpio_bit(uint32_t *gpio_base_addr, uint32_t bit_num);
#endif /* PLAT_GPIO_H */
/*
* Copyright 2016-2020 NXP
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <common/debug.h>
#include <drivers/delay_timer.h>
#include "i2c.h"
#include <nxp_timer.h>
static uintptr_t g_nxp_i2c_addr;
void i2c_init(uintptr_t nxp_i2c_addr)
{
struct ls_i2c *ccsr_i2c = (void *)nxp_i2c_addr;
g_nxp_i2c_addr = nxp_i2c_addr;
/* Presume workaround for erratum a009203 applied */
i2c_out(&ccsr_i2c->cr, I2C_CR_DIS);
i2c_out(&ccsr_i2c->fd, I2C_FD_CONSERV);
i2c_out(&ccsr_i2c->sr, I2C_SR_RST);
i2c_out(&ccsr_i2c->cr, I2C_CR_EN);
}
static int wait_for_state(struct ls_i2c *ccsr_i2c,
unsigned char state, unsigned char mask)
{
unsigned char sr;
uint64_t start_time = get_timer_val(0);
uint64_t timer;
do {
sr = i2c_in(&ccsr_i2c->sr);
if (sr & I2C_SR_AL) {
i2c_out(&ccsr_i2c->sr, sr);
WARN("I2C arbitration lost\n");
return -EIO;
}
if ((sr & mask) == state) {
return (int)sr;
}
timer = get_timer_val(start_time);
if (timer > I2C_TIMEOUT)
break;
mdelay(1);
} while (1);
WARN("I2C: Timeout waiting for state 0x%x, sr = 0x%x\n", state, sr);
return -ETIMEDOUT;
}
static int tx_byte(struct ls_i2c *ccsr_i2c, unsigned char c)
{
int ret;
i2c_out(&ccsr_i2c->sr, I2C_SR_IF);
i2c_out(&ccsr_i2c->dr, c);
ret = wait_for_state(ccsr_i2c, I2C_SR_IF, I2C_SR_IF);
if (ret < 0) {
WARN("%s: state error\n", __func__);
return ret;
}
if (ret & I2C_SR_RX_NAK) {
WARN("%s: nodev\n", __func__);
return -ENODEV;
}
return 0;
}
static int gen_stop(struct ls_i2c *ccsr_i2c)
{
unsigned char cr;
int ret;
cr = i2c_in(&ccsr_i2c->cr);
cr &= ~(I2C_CR_MA | I2C_CR_TX);
i2c_out(&ccsr_i2c->cr, cr);
ret = wait_for_state(ccsr_i2c, I2C_SR_IDLE, I2C_SR_BB);
if (ret < 0) {
WARN("I2C: Generating stop failed.\n");
}
return ret;
}
static int i2c_write_addr(struct ls_i2c *ccsr_i2c, unsigned char chip,
int addr, int alen)
{
int ret;
unsigned char cr;
if (alen != 1) {
WARN("I2C: Unsupported address len [%d]\n", alen);
return -EIO;
}
if (i2c_in(&ccsr_i2c->ad) == (chip << 1)) {
WARN("I2C: slave address same as self\n");
return -ENODEV;
}
i2c_out(&ccsr_i2c->sr, I2C_SR_IF);
ret = wait_for_state(ccsr_i2c, I2C_SR_IDLE, I2C_SR_BB);
if (ret < 0) {
return ret;
}
cr = i2c_in(&ccsr_i2c->cr);
cr |= I2C_CR_MA;
i2c_out(&ccsr_i2c->cr, cr);
ret = wait_for_state(ccsr_i2c, I2C_SR_BB, I2C_SR_BB);
if (ret < 0) {
return ret;
}
VERBOSE("Before writing chip %d\n", chip);
cr |= I2C_CR_TX | I2C_CR_TX_NAK;
i2c_out(&ccsr_i2c->cr, cr);
ret = tx_byte(ccsr_i2c, chip << 1);
if (ret < 0) {
gen_stop(ccsr_i2c);
return ret;
}
VERBOSE("Before writing addr\n");
while (alen--) {
ret = tx_byte(ccsr_i2c, (addr >> (alen << 3)) & 0xff);
if (ret < 0) {
gen_stop(ccsr_i2c);
return ret;
}
}
return 0;
}
static int read_data(struct ls_i2c *ccsr_i2c, unsigned char chip,
unsigned char *buf, int len)
{
int i;
int ret;
unsigned char cr;
cr = i2c_in(&ccsr_i2c->cr);
cr &= ~(I2C_CR_TX | I2C_CR_TX_NAK);
if (len == 1) {
cr |= I2C_CR_TX_NAK;
}
i2c_out(&ccsr_i2c->cr, cr);
i2c_out(&ccsr_i2c->sr, I2C_SR_IF);
i2c_in(&ccsr_i2c->dr); /* dummy read */
for (i = 0; i < len; i++) {
ret = wait_for_state(ccsr_i2c, I2C_SR_IF, I2C_SR_IF);
if (ret < 0) {
gen_stop(ccsr_i2c);
return ret;
}
if (i == (len - 1)) {
gen_stop(ccsr_i2c);
} else if (i == (len - 2)) {
/* Updating the command to send
* No ACK.
*/
cr = i2c_in(&ccsr_i2c->cr);
cr |= I2C_CR_TX_NAK;
i2c_out(&ccsr_i2c->cr, cr);
}
i2c_out(&ccsr_i2c->sr, I2C_SR_IF);
buf[i] = i2c_in(&ccsr_i2c->dr);
}
return 0;
}
static int write_data(struct ls_i2c *ccsr_i2c, unsigned char chip,
const unsigned char *buf, int len)
{
int i;
int ret;
for (i = 0; i < len; i++) {
ret = tx_byte(ccsr_i2c, buf[i]);
if (ret < 0) {
break;
}
}
ret = gen_stop(ccsr_i2c);
return ret;
}
int i2c_read(unsigned char chip, int addr, int alen,
unsigned char *buf, int len)
{
int ret;
unsigned char cr;
struct ls_i2c *ccsr_i2c = (void *)g_nxp_i2c_addr;
ret = i2c_write_addr(ccsr_i2c, chip, addr, alen);
if (ret < 0) {
gen_stop(ccsr_i2c);
return ret;
}
cr = i2c_in(&ccsr_i2c->cr);
cr |= I2C_CR_RSTA;
i2c_out(&ccsr_i2c->cr, cr);
ret = tx_byte(ccsr_i2c, (chip << 1) | 1);
if (ret < 0) {
gen_stop(ccsr_i2c);
return ret;
}
return read_data(ccsr_i2c, chip, buf, len);
}
int i2c_write(unsigned char chip, int addr, int alen,
const unsigned char *buf, int len)
{
int ret;
struct ls_i2c *ccsr_i2c = (void *)g_nxp_i2c_addr;
ret = i2c_write_addr(ccsr_i2c, chip, addr, alen);
if (ret < 0) {
return ret;
}
return write_data(ccsr_i2c, chip, buf, len);
}
int i2c_probe_chip(unsigned char chip)
{
int ret;
struct ls_i2c *ccsr_i2c = (void *)g_nxp_i2c_addr;
ret = i2c_write_addr(ccsr_i2c, chip, 0, 0);
if (ret < 0) {
WARN("write addr failed\n");
return ret;
}
ret = gen_stop(ccsr_i2c);
if (ret < 0) {
WARN("I2C: Probe not complete.\n");
}
return ret;
}
/*
* Copyright 2016-2020 NXP
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#ifndef I2C_H
#define I2C_H
#include <lib/mmio.h>
#define I2C_TIMEOUT 1000 /* ms */
#define I2C_FD_CONSERV 0x7e
#define I2C_CR_DIS (1 << 7)
#define I2C_CR_EN (0 << 7)
#define I2C_CR_MA (1 << 5)
#define I2C_CR_TX (1 << 4)
#define I2C_CR_TX_NAK (1 << 3)
#define I2C_CR_RSTA (1 << 2)
#define I2C_SR_BB (1 << 5)
#define I2C_SR_IDLE (0 << 5)
#define I2C_SR_AL (1 << 4)
#define I2C_SR_IF (1 << 1)
#define I2C_SR_RX_NAK (1 << 0)
#define I2C_SR_RST (I2C_SR_AL | I2C_SR_IF)
#define I2C_GLITCH_EN 0x8
#define i2c_in(a) mmio_read_8((uintptr_t)(a))
#define i2c_out(a, v) mmio_write_8((uintptr_t)(a), (v))
struct ls_i2c {
unsigned char ad; /* I2c Bus Address Register */
unsigned char fd; /* I2c Bus Frequency Dividor Register */
unsigned char cr; /* I2c Bus Control Register */
unsigned char sr; /* I2c Bus Status Register */
unsigned char dr; /* I2C Bus Data I/O Register */
unsigned char ic; /* I2C Bus Interrupt Config Register */
unsigned char dbg; /* I2C Bus Debug Register */
};
void i2c_init(uintptr_t nxp_i2c_addr);
int i2c_read(unsigned char chip, int addr, int alen,
unsigned char *buf, int len);
int i2c_write(unsigned char chip, int addr, int alen,
const unsigned char *buf, int len);
int i2c_probe_chip(unsigned char chip);
#endif /* I2C_H */
#
# Copyright 2020 NXP
#
# SPDX-License-Identifier: BSD-3-Clause
#
ifeq (${ADD_I2C},)
ADD_I2C := 1
I2C_DRIVERS_PATH := ${PLAT_DRIVERS_PATH}/i2c
I2C_SOURCES += $(I2C_DRIVERS_PATH)/i2c.c
PLAT_INCLUDES += -I$(I2C_DRIVERS_PATH)
ifeq (${BL_COMM_I2C_NEEDED},yes)
BL_COMMON_SOURCES += ${I2C_SOURCES}
else
ifeq (${BL2_I2C_NEEDED},yes)
BL2_SOURCES += ${I2C_SOURCES}
endif
ifeq (${BL31_I2C_NEEDED},yes)
BL31_SOURCES += ${I2C_SOURCES}
endif
endif
endif
# Copyright 2020 NXP
#
# SPDX-License-Identifier: BSD-3-Clause
#
#
#------------------------------------------------------------------------------
#
# Select the Interconnect files
#
# -----------------------------------------------------------------------------
ifeq (${ADD_INTERCONNECT},)
ADD_INTERCONNECT := 1
PLAT_INCLUDES += -I${PLAT_DRIVERS_PATH}/interconnect
ifeq (, $(filter $(INTERCONNECT), CCI400 CCN502 CCN504 CCN508))
$(error -> Interconnect type not set!)
else
$(eval $(call add_define_val,INTERCONNECT,${INTERCONNECT}))
ifeq ($(INTERCONNECT), $(filter $(INTERCONNECT), CCN502 CCN504 CCN508))
INTERCONNECT_SOURCES := drivers/arm/ccn/ccn.c \
${PLAT_DRIVERS_PATH}/interconnect/ls_ccn.c
else
ifeq ($(INTERCONNECT), CCI400)
INTERCONNECT_SOURCES := drivers/arm/cci/cci.c \
${PLAT_DRIVERS_PATH}/interconnect/ls_cci.c
endif
endif
endif
ifeq (${BL_COMM_INTERCONNECT_NEEDED},yes)
BL_COMMON_SOURCES += ${INTERCONNECT_SOURCES}
else
ifeq (${BL2_INTERCONNECT_NEEDED},yes)
BL2_SOURCES += ${INTERCONNECT_SOURCES}
endif
ifeq (${BL31_INTERCONNECT_NEEDED},yes)
BL31_SOURCES += ${INTERCONNECT_SOURCES}
endif
endif
endif
# -----------------------------------------------------------------------------
/*
* Copyright 2020 NXP
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#include <arch.h>
#include <cci.h>
#include <plat_arm.h>
/******************************************************************************
* The following functions are defined as weak to allow a platform to override
* the way ARM CCI driver is initialised and used.
*****************************************************************************/
#pragma weak plat_arm_interconnect_enter_coherency
#pragma weak plat_arm_interconnect_exit_coherency
/******************************************************************************
* Helper function to place current master into coherency
*****************************************************************************/
void plat_ls_interconnect_enter_coherency(unsigned int num_clusters)
{
cci_enable_snoop_dvm_reqs(MPIDR_AFFLVL1_VAL(read_mpidr_el1()));
for (uint32_t index = 1U; index < num_clusters; index++) {
cci_enable_snoop_dvm_reqs(index);
}
}
/******************************************************************************
* Helper function to remove current master from coherency
*****************************************************************************/
void plat_ls_interconnect_exit_coherency(void)
{
cci_disable_snoop_dvm_reqs(MPIDR_AFFLVL1_VAL(read_mpidr_el1()));
}
/*
* Copyright 2020 NXP
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#include <arch.h>
#include <ccn.h>
#include <plat_arm.h>
/******************************************************************************
* Helper function to place current master into coherency
*****************************************************************************/
void plat_ls_interconnect_enter_coherency(unsigned int num_clusters)
{
ccn_enter_snoop_dvm_domain(1ULL << MPIDR_AFFLVL1_VAL(read_mpidr_el1()));
for (uint32_t index = 1U; index < num_clusters; index++) {
ccn_enter_snoop_dvm_domain(1ULL << index);
}
}
/******************************************************************************
* Helper function to remove current master from coherency
*****************************************************************************/
void plat_ls_interconnect_exit_coherency(void)
{
ccn_exit_snoop_dvm_domain(1ULL << MPIDR_AFFLVL1_VAL(read_mpidr_el1()));
}
/*
* Copyright 2020 NXP
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#ifndef LS_INTERCONNECT_H
#define LS_INTERCONNECT_H
#if (INTERCONNECT == CCI400)
#define CCI_TERMINATE_BARRIER_TX 0x8
#endif
/* Interconnect CCI/CCN functions */
void plat_ls_interconnect_enter_coherency(unsigned int num_clusters);
void plat_ls_interconnect_exit_coherency(void);
#endif
/*
* Copyright 2021 NXP
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#include <arch.h>
#include <arch_helpers.h>
#include <common/debug.h>
#include <dcfg.h>
#include <lib/mmio.h>
#include <pmu.h>
void enable_timer_base_to_cluster(uintptr_t nxp_pmu_addr)
{
uint32_t *cltbenr = NULL;
uint32_t cltbenr_val = 0U;
cltbenr = (uint32_t *)(nxp_pmu_addr
+ CLUST_TIMER_BASE_ENBL_OFFSET);
cltbenr_val = mmio_read_32((uintptr_t)cltbenr);
cltbenr_val = cltbenr_val
| (1 << MPIDR_AFFLVL1_VAL(read_mpidr_el1()));
mmio_write_32((uintptr_t)cltbenr, cltbenr_val);
VERBOSE("Enable cluster time base\n");
}
/*
* Enable core timebase. In certain Layerscape SoCs, the clock for each core's
* has an enable bit in the PMU Physical Core Time Base Enable
* Register (PCTBENR), which allows the watchdog to operate.
*/
void enable_core_tb(uintptr_t nxp_pmu_addr)
{
uint32_t *pctbenr = (uint32_t *) (nxp_pmu_addr +
CORE_TIMEBASE_ENBL_OFFSET);
mmio_write_32((uintptr_t)pctbenr, 0xff);
}
/*
* Copyright 2021 NXP
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#ifndef PMU_H
#define PMU_H
/* PMU Registers' OFFSET */
#define PMU_PCPW20SR_OFFSET 0x830
#define PMU_CLL2FLUSHSETR_OFFSET 0x1110
#define PMU_CLSL2FLUSHCLRR_OFFSET 0x1114
#define PMU_CLL2FLUSHSR_OFFSET 0x1118
#define PMU_POWMGTCSR_VAL (1 << 20)
/* PMU Registers */
#define CORE_TIMEBASE_ENBL_OFFSET 0x8A0
#define CLUST_TIMER_BASE_ENBL_OFFSET 0x18A0
#define PMU_IDLE_CLUSTER_MASK 0x2
#define PMU_FLUSH_CLUSTER_MASK 0x2
#define PMU_IDLE_CORE_MASK 0xfe
/* pmu register offsets and bitmaps */
#define PMU_POWMGTDCR0_OFFSET 0xC20
#define PMU_POWMGTCSR_OFFSET 0x4000
#define PMU_CLAINACTSETR_OFFSET 0x1100
#define PMU_CLAINACTCLRR_OFFSET 0x1104
#define PMU_CLSINACTSETR_OFFSET 0x1108
#define PMU_CLSINACTCLRR_OFFSET 0x110C
#define PMU_CLL2FLUSHSETR_OFFSET 0x1110
#define PMU_CLL2FLUSHCLRR_OFFSET 0x1114
#define PMU_IPPDEXPCR0_OFFSET 0x4040
#define PMU_IPPDEXPCR1_OFFSET 0x4044
#define PMU_IPPDEXPCR2_OFFSET 0x4048
#define PMU_IPPDEXPCR3_OFFSET 0x404C
#define PMU_IPPDEXPCR4_OFFSET 0x4050
#define PMU_IPPDEXPCR5_OFFSET 0x4054
#define PMU_IPPDEXPCR6_OFFSET 0x4058
#define PMU_IPSTPCR0_OFFSET 0x4120
#define PMU_IPSTPCR1_OFFSET 0x4124
#define PMU_IPSTPCR2_OFFSET 0x4128
#define PMU_IPSTPCR3_OFFSET 0x412C
#define PMU_IPSTPCR4_OFFSET 0x4130
#define PMU_IPSTPCR5_OFFSET 0x4134
#define PMU_IPSTPCR6_OFFSET 0x4138
#define PMU_IPSTPACKSR0_OFFSET 0x4140
#define PMU_IPSTPACKSR1_OFFSET 0x4144
#define PMU_IPSTPACKSR2_OFFSET 0x4148
#define PMU_IPSTPACKSR3_OFFSET 0x414C
#define PMU_IPSTPACKSR4_OFFSET 0x4150
#define PMU_IPSTPACKSR5_OFFSET 0x4154
#define PMU_IPSTPACKSR6_OFFSET 0x4158
#define CLAINACT_DISABLE_ACP 0xFF
#define CLSINACT_DISABLE_SKY 0xFF
#define POWMGTDCR_STP_OV_EN 0x1
#define POWMGTCSR_LPM20_REQ 0x00100000
/* Used by PMU */
#define DEVDISR1_MASK 0x024F3504
#define DEVDISR2_MASK 0x0003FFFF
#define DEVDISR3_MASK 0x0000303F
#define DEVDISR4_MASK 0x0000FFFF
#define DEVDISR5_MASK 0x00F07603
#define DEVDISR6_MASK 0x00000001
#ifndef __ASSEMBLER__
void enable_timer_base_to_cluster(uintptr_t nxp_pmu_addr);
void enable_core_tb(uintptr_t nxp_pmu_addr);
#endif /* __ASSEMBLER__ */
#endif
#
# Copyright 2021 NXP
#
# SPDX-License-Identifier: BSD-3-Clause
#
#-----------------------------------------------------------------------------
ifeq (${PMU_ADDED},)
PMU_ADDED := 1
PMU_DRIVERS_PATH := ${PLAT_DRIVERS_PATH}/pmu
PLAT_INCLUDES += -I$(PMU_DRIVERS_PATH)
PMU_SOURCES += $(PMU_DRIVERS_PATH)/pmu.c
ifeq (${BL_COMM_PMU_NEEDED},yes)
BL_COMMON_SOURCES += ${PMU_SOURCES}
else
ifeq (${BL2_PMU_NEEDED},yes)
BL2_SOURCES += ${PMU_SOURCES}
endif
ifeq (${BL31_PMU_NEEDED},yes)
BL31_SOURCES += ${PMU_SOURCES}
endif
endif
endif
#------------------------------------------------
/*
* Copyright 2021 NXP
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#include <assert.h>
#include <common/debug.h>
#include <lib/mmio.h>
#include <lib/xlat_tables/xlat_tables_v2.h>
#include <qspi.h>
int qspi_io_setup(uintptr_t nxp_qspi_flash_addr,
size_t nxp_qspi_flash_size,
uintptr_t fip_offset)
{
uint32_t qspi_mcr_val = qspi_in32(CHS_QSPI_MCR);
/* Enable and change endianness of QSPI IP */
qspi_out32(CHS_QSPI_MCR, (qspi_mcr_val | CHS_QSPI_64LE));
/* Adding QSPI Memory Map in XLAT Table */
mmap_add_region(nxp_qspi_flash_addr, nxp_qspi_flash_addr,
nxp_qspi_flash_size, MT_MEMORY | MT_RW);
return 0;
}
/*
* Copyright 2021 NXP
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#ifndef QSPI_H
#define QSPI_H
#include <endian.h>
#include <lib/mmio.h>
#define CHS_QSPI_MCR 0x01550000
#define CHS_QSPI_64LE 0xC
#ifdef NXP_QSPI_BE
#define qspi_in32(a) bswap32(mmio_read_32((uintptr_t)(a)))
#define qspi_out32(a, v) mmio_write_32((uintptr_t)(a), bswap32(v))
#elif defined(NXP_QSPI_LE)
#define qspi_in32(a) mmio_read_32((uintptr_t)(a))
#define qspi_out32(a, v) mmio_write_32((uintptr_t)(a), (v))
#else
#error Please define CCSR QSPI register endianness
#endif
int qspi_io_setup(uintptr_t nxp_qspi_flash_addr,
size_t nxp_qspi_flash_size,
uintptr_t fip_offset);
#endif /* __QSPI_H__ */
#
# Copyright 2020 NXP
#
# SPDX-License-Identifier: BSD-3-Clause
#
ifeq (${QSPI_ADDED},)
QSPI_ADDED := 1
QSPI_DRIVERS_PATH := ${PLAT_DRIVERS_PATH}/qspi
QSPI_SOURCES := $(QSPI_DRIVERS_PATH)/qspi.c
PLAT_INCLUDES += -I$(QSPI_DRIVERS_PATH)
ifeq (${BL_COMM_QSPI_NEEDED},yes)
BL_COMMON_SOURCES += ${QSPI_SOURCES}
else
ifeq (${BL2_QSPI_NEEDED},yes)
BL2_SOURCES += ${QSPI_SOURCES}
endif
ifeq (${BL31_QSPI_NEEDED},yes)
BL31_SOURCES += ${QSPI_SOURCES}
endif
endif
endif
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