I finally resolved the issue.
The problems were missing entries in the device tree files (error code -19
-- Thanks to @Stefan's answer) and missing support for the SPI controller in the clock driver (error code -2
) from the SoC.
My working modifications:
SPI driver (drivers/spi/rk_spi.c):
static const struct udevice_id rockchip_spi_ids[] = {
{ .compatible = "rockchip,rk3066-spi" },
{ .compatible = "rockchip,rk3288-spi" },
{ .compatible = "rockchip,rk3328-spi" },
{ .compatible = "rockchip,rk3368-spi",
.data = (ulong)&rk3399_spi_params },
{ .compatible = "rockchip,rk3399-spi",
.data = (ulong)&rk3399_spi_params },
{ }
};
Here I have simple added the device ID string (rockchip,rk3328-spi) for the specified device. Not sure if rk3399_spi_params
is also needed. But works without it.
Clock driver (drivers/clk/rockchip/clk_rk3328.c):
I have added these new functions...
static ulong rk3328_spi_get_clk(struct rk3328_cru *cru)
{
u32 div, val;
val = readl(&cru->clksel_con[24]);
div = (val & CLK_SPI_DIV_CON_MASK) >> CLK_SPI_DIV_CON_SHIFT;
return DIV_TO_RATE(OSC_HZ, div);
}
static ulong rk3328_spi_set_clk(struct rk3328_cru *cru, uint hz)
{
u32 src_clk_div;
src_clk_div = GPLL_HZ / hz;
assert(src_clk_div < 128);
rk_clrsetreg(&cru->clksel_con[24],
CLK_PWM_PLL_SEL_MASK | CLK_PWM_DIV_CON_MASK,
CLK_PWM_PLL_SEL_GPLL << CLK_PWM_PLL_SEL_SHIFT |
(src_clk_div - 1) << CLK_PWM_DIV_CON_SHIFT);
return rk3328_spi_get_clk(cru);
}
...and added the functions calls to the functions rk3328_clk_get_rate()
and rk3328_clk_set_rate()
in the switch statements:
static ulong rk3328_clk_get_rate(struct clk *clk)
{
struct rk3328_clk_priv *priv = dev_get_priv(clk->dev);
ulong rate = 0;
switch (clk->id) {
case 0 ... 29:
return 0;
case HCLK_SDMMC:
case HCLK_EMMC:
case SCLK_SDMMC:
case SCLK_EMMC:
rate = rk3328_mmc_get_clk(priv->cru, clk->id);
break;
case SCLK_I2C0:
case SCLK_I2C1:
case SCLK_I2C2:
case SCLK_I2C3:
rate = rk3328_i2c_get_clk(priv->cru, clk->id);
break;
case SCLK_PWM:
rate = rk3328_pwm_get_clk(priv->cru);
break;
case SCLK_SARADC:
rate = rk3328_saradc_get_clk(priv->cru);
break;
case SCLK_SPI:
rate = rk3328_spi_get_clk(priv->cru);
break;
default:
return -ENOENT;
}
return rate;
}
static ulong rk3328_clk_set_rate(struct clk *clk, ulong rate)
{
struct rk3328_clk_priv *priv = dev_get_priv(clk->dev);
ulong ret = 0;
switch (clk->id) {
case 0 ... 29:
return 0;
case HCLK_SDMMC:
case HCLK_EMMC:
case SCLK_SDMMC:
case SCLK_EMMC:
ret = rk3328_mmc_set_clk(priv->cru, clk->id, rate);
break;
case SCLK_I2C0:
case SCLK_I2C1:
case SCLK_I2C2:
case SCLK_I2C3:
ret = rk3328_i2c_set_clk(priv->cru, clk->id, rate);
break;
case SCLK_MAC2IO:
ret = rk3328_gmac2io_set_clk(priv->cru, rate);
break;
case SCLK_PWM:
ret = rk3328_pwm_set_clk(priv->cru, rate);
break;
case SCLK_SARADC:
ret = rk3328_saradc_set_clk(priv->cru, rate);
break;
case SCLK_SPI:
ret = rk3328_spi_set_clk(priv->cru, rate);
break;
case DCLK_LCDC:
case SCLK_PDM:
case SCLK_RTC32K:
case SCLK_UART0:
case SCLK_UART1:
case SCLK_UART2:
case SCLK_SDIO:
case SCLK_TSP:
case SCLK_WIFI:
case ACLK_BUS_PRE:
case HCLK_BUS_PRE:
case PCLK_BUS_PRE:
case ACLK_PERI_PRE:
case HCLK_PERI:
case PCLK_PERI:
case ACLK_VIO_PRE:
case HCLK_VIO_PRE:
case ACLK_RGA_PRE:
case SCLK_RGA:
case ACLK_VOP_PRE:
case ACLK_RKVDEC_PRE:
case ACLK_RKVENC:
case ACLK_VPU_PRE:
case SCLK_VDEC_CABAC:
case SCLK_VDEC_CORE:
case SCLK_VENC_CORE:
case SCLK_VENC_DSP:
case SCLK_EFUSE:
case PCLK_DDR:
case ACLK_GMAC:
case PCLK_GMAC:
case SCLK_USB3OTG_SUSPEND:
return 0;
default:
return -ENOENT;
}
return ret;
}
Device-Trees:
arch/arm/dts/rk3328-u-boot.dtsi:
I have added the correct alias...
/ {
aliases {
mmc0 = &emmc;
mmc1 = &sdmmc;
spi0 = &spi0;
};
...and the SPI controller itself.
&spi0 {
u-boot,dm-pre-reloc;
};
arch/arm/dts/rk3328-rock64-u-boot.dtsi:
For the SPI flash I added these...
&spi0 {
spi_flash: spiflash@0 {
u-boot,dm-pre-reloc;
};
};
Board configuration (configs/rock64-rk3328_defconfig):
Added these configuration switches...
CONFIG_ROCKCHIP_SPI=y
CONFIG_SPI_FLASH_GIGADEVICE=y
The result:
=> sf probe
SF: Detected gd25q128 with page size 256 Bytes, erase size 4 KiB, total 16 MiB
=>
The SPI flash will be correctly detected.
Not sure if I should release a patch in the U-Boot list for this.