|
@@ -12,6 +12,7 @@
|
|
#include <common.h>
|
|
#include <common.h>
|
|
#include <clk.h>
|
|
#include <clk.h>
|
|
#include <dm.h>
|
|
#include <dm.h>
|
|
|
|
+#include <dt-structs.h>
|
|
#include <errno.h>
|
|
#include <errno.h>
|
|
#include <spi.h>
|
|
#include <spi.h>
|
|
#include <linux/errno.h>
|
|
#include <linux/errno.h>
|
|
@@ -27,6 +28,9 @@ DECLARE_GLOBAL_DATA_PTR;
|
|
#define DEBUG_RK_SPI 0
|
|
#define DEBUG_RK_SPI 0
|
|
|
|
|
|
struct rockchip_spi_platdata {
|
|
struct rockchip_spi_platdata {
|
|
|
|
+#if CONFIG_IS_ENABLED(OF_PLATDATA)
|
|
|
|
+ struct dtd_rockchip_rk3288_spi of_plat;
|
|
|
|
+#endif
|
|
s32 frequency; /* Default clock frequency, -1 for none */
|
|
s32 frequency; /* Default clock frequency, -1 for none */
|
|
fdt_addr_t base;
|
|
fdt_addr_t base;
|
|
uint deactivate_delay_us; /* Delay to wait after deactivate */
|
|
uint deactivate_delay_us; /* Delay to wait after deactivate */
|
|
@@ -127,9 +131,29 @@ static void spi_cs_deactivate(struct udevice *dev, uint cs)
|
|
priv->last_transaction_us = timer_get_us();
|
|
priv->last_transaction_us = timer_get_us();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+#if CONFIG_IS_ENABLED(OF_PLATDATA)
|
|
|
|
+static int conv_of_platdata(struct udevice *dev)
|
|
|
|
+{
|
|
|
|
+ struct rockchip_spi_platdata *plat = dev->platdata;
|
|
|
|
+ struct dtd_rockchip_rk3288_spi *dtplat = &plat->of_plat;
|
|
|
|
+ struct rockchip_spi_priv *priv = dev_get_priv(dev);
|
|
|
|
+ int ret;
|
|
|
|
+
|
|
|
|
+ plat->base = dtplat->reg[0];
|
|
|
|
+ plat->frequency = 20000000;
|
|
|
|
+ ret = clk_get_by_index_platdata(dev, 0, dtplat->clocks, &priv->clk);
|
|
|
|
+ if (ret < 0)
|
|
|
|
+ return ret;
|
|
|
|
+ dev->req_seq = 0;
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+#endif
|
|
|
|
+
|
|
static int rockchip_spi_ofdata_to_platdata(struct udevice *bus)
|
|
static int rockchip_spi_ofdata_to_platdata(struct udevice *bus)
|
|
{
|
|
{
|
|
- struct rockchip_spi_platdata *plat = bus->platdata;
|
|
|
|
|
|
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
|
|
|
|
+ struct rockchip_spi_platdata *plat = dev_get_platdata(bus);
|
|
struct rockchip_spi_priv *priv = dev_get_priv(bus);
|
|
struct rockchip_spi_priv *priv = dev_get_priv(bus);
|
|
const void *blob = gd->fdt_blob;
|
|
const void *blob = gd->fdt_blob;
|
|
int node = bus->of_offset;
|
|
int node = bus->of_offset;
|
|
@@ -153,6 +177,7 @@ static int rockchip_spi_ofdata_to_platdata(struct udevice *bus)
|
|
debug("%s: base=%x, max-frequency=%d, deactivate_delay=%d\n",
|
|
debug("%s: base=%x, max-frequency=%d, deactivate_delay=%d\n",
|
|
__func__, (uint)plat->base, plat->frequency,
|
|
__func__, (uint)plat->base, plat->frequency,
|
|
plat->deactivate_delay_us);
|
|
plat->deactivate_delay_us);
|
|
|
|
+#endif
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
@@ -164,6 +189,11 @@ static int rockchip_spi_probe(struct udevice *bus)
|
|
int ret;
|
|
int ret;
|
|
|
|
|
|
debug("%s: probe\n", __func__);
|
|
debug("%s: probe\n", __func__);
|
|
|
|
+#if CONFIG_IS_ENABLED(OF_PLATDATA)
|
|
|
|
+ ret = conv_of_platdata(bus);
|
|
|
|
+ if (ret)
|
|
|
|
+ return ret;
|
|
|
|
+#endif
|
|
priv->regs = (struct rockchip_spi *)plat->base;
|
|
priv->regs = (struct rockchip_spi *)plat->base;
|
|
|
|
|
|
priv->last_transaction_us = timer_get_us();
|
|
priv->last_transaction_us = timer_get_us();
|
|
@@ -369,7 +399,11 @@ static const struct udevice_id rockchip_spi_ids[] = {
|
|
};
|
|
};
|
|
|
|
|
|
U_BOOT_DRIVER(rockchip_spi) = {
|
|
U_BOOT_DRIVER(rockchip_spi) = {
|
|
|
|
+#if CONFIG_IS_ENABLED(OF_PLATDATA)
|
|
|
|
+ .name = "rockchip_rk3288_spi",
|
|
|
|
+#else
|
|
.name = "rockchip_spi",
|
|
.name = "rockchip_spi",
|
|
|
|
+#endif
|
|
.id = UCLASS_SPI,
|
|
.id = UCLASS_SPI,
|
|
.of_match = rockchip_spi_ids,
|
|
.of_match = rockchip_spi_ids,
|
|
.ops = &rockchip_spi_ops,
|
|
.ops = &rockchip_spi_ops,
|