/*
- * NDS SPI controller driver.
+ * Andestech ATCSPI200 SPI controller driver.
*
* Copyright 2017 Andes Technology, Inc.
* Author: Rick Chen (rick@andestech.com)
#define SPI1_BASE 0xf0f00000
#define NSPI_MAX_CS_NUM 1
-struct ae3xx_spi_regs {
+struct atcspi200_spi_regs {
u32 rev;
u32 reserve1[3];
u32 format; /* 0x10 */
#ifndef CONFIG_DM_SPI
struct spi_slave slave;
#endif
- volatile struct ae3xx_spi_regs *regs;
+ volatile struct atcspi200_spi_regs *regs;
int to;
unsigned int freq;
ulong clock;
unsigned int max_transfer_length;
};
-static int __ae3xx_spi_set_speed(struct nds_spi_slave *ns)
+static int __atcspi200_spi_set_speed(struct nds_spi_slave *ns)
{
u32 tm;
u8 div;
}
-static int __ae3xx_spi_claim_bus(struct nds_spi_slave *ns)
+static int __atcspi200_spi_claim_bus(struct nds_spi_slave *ns)
{
unsigned int format=0;
ns->regs->ctrl |= (TXFRST|RXFRST|SPIRST);
ns->cmd_len = 0;
format = ns->mode|DATA_LENGTH(8);
ns->regs->format = format;
- __ae3xx_spi_set_speed(ns);
+ __atcspi200_spi_set_speed(ns);
return 0;
}
-static int __ae3xx_spi_release_bus(struct nds_spi_slave *ns)
+static int __atcspi200_spi_release_bus(struct nds_spi_slave *ns)
{
/* do nothing */
return 0;
}
-static int __ae3xx_spi_start(struct nds_spi_slave *ns)
+static int __atcspi200_spi_start(struct nds_spi_slave *ns)
{
int i,olen=0;
int tc = ns->regs->tctrl;
return 0;
}
-static int __ae3xx_spi_stop(struct nds_spi_slave *ns)
+static int __atcspi200_spi_stop(struct nds_spi_slave *ns)
{
ns->regs->timing = ns->mtiming;
while ((ns->regs->status & SPIBSY)&&(ns->to--))
}
-static int __ae3xx_spi_xfer(struct nds_spi_slave *ns,
+static int __atcspi200_spi_xfer(struct nds_spi_slave *ns,
unsigned int bitlen, const void *data_out, void *data_in,
unsigned long flags)
{
memcpy(cmd_buf, data_out, cmd_len);
data_out = 0;
data_len = 0;
- __ae3xx_spi_start(ns);
+ __atcspi200_spi_start(ns);
break;
}
debug("spi_xfer: data_out %08X(%p) data_in %08X(%p) data_len %u\n",
num_bytes = (tran_len) % CHUNK_SIZE;
if(num_bytes == 0)
num_bytes = CHUNK_SIZE;
- __ae3xx_spi_start(ns);
+ __atcspi200_spi_start(ns);
while (num_blks) {
event = in_le32(&ns->regs->status);
ns->cmd_buf[3] += ((tran_len)&0xff);
ns->data_len = data_len;
}
- ret = __ae3xx_spi_stop(ns);
+ ret = __atcspi200_spi_stop(ns);
}
- ret = __ae3xx_spi_stop(ns);
+ ret = __atcspi200_spi_stop(ns);
return ret;
}
switch (bus) {
case SPI0_BUS:
- ns->regs = (struct ae3xx_spi_regs *)SPI0_BASE;
+ ns->regs = (struct atcspi200_spi_regs *)SPI0_BASE;
break;
case SPI1_BUS:
- ns->regs = (struct ae3xx_spi_regs *)SPI1_BASE;
+ ns->regs = (struct atcspi200_spi_regs *)SPI1_BASE;
break;
default:
int spi_claim_bus(struct spi_slave *slave)
{
struct nds_spi_slave *ns = to_nds_spi_slave(slave);
- return __ae3xx_spi_claim_bus(ns);
+ return __atcspi200_spi_claim_bus(ns);
}
void spi_release_bus(struct spi_slave *slave)
{
struct nds_spi_slave *ns = to_nds_spi_slave(slave);
- __ae3xx_spi_release_bus(ns);
+ __atcspi200_spi_release_bus(ns);
}
int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *data_out,
void *data_in, unsigned long flags)
{
struct nds_spi_slave *ns = to_nds_spi_slave(slave);
- return __ae3xx_spi_xfer(ns, bitlen, data_out, data_in, flags);
+ return __atcspi200_spi_xfer(ns, bitlen, data_out, data_in, flags);
}
int spi_cs_is_valid(unsigned int bus, unsigned int cs)
void spi_cs_activate(struct spi_slave *slave)
{
struct nds_spi_slave *ns = to_nds_spi_slave(slave);
- __ae3xx_spi_start(ns);
+ __atcspi200_spi_start(ns);
}
void spi_cs_deactivate(struct spi_slave *slave)
{
struct nds_spi_slave *ns = to_nds_spi_slave(slave);
- __ae3xx_spi_stop(ns);
+ __atcspi200_spi_stop(ns);
}
#else
-static int ae3xx_spi_set_speed(struct udevice *bus, uint max_hz)
+static int atcspi200_spi_set_speed(struct udevice *bus, uint max_hz)
{
struct nds_spi_slave *ns = dev_get_priv(bus);
debug("%s speed %u\n", __func__, max_hz);
ns->freq = max_hz;
- __ae3xx_spi_set_speed(ns);
+ __atcspi200_spi_set_speed(ns);
return 0;
}
-static int ae3xx_spi_set_mode(struct udevice *bus, uint mode)
+static int atcspi200_spi_set_mode(struct udevice *bus, uint mode)
{
struct nds_spi_slave *ns = dev_get_priv(bus);
return 0;
}
-static int ae3xx_spi_claim_bus(struct udevice *dev)
+static int atcspi200_spi_claim_bus(struct udevice *dev)
{
struct dm_spi_slave_platdata *slave_plat =
dev_get_parent_platdata(dev);
return -EINVAL;
}
- return __ae3xx_spi_claim_bus(ns);
+ return __atcspi200_spi_claim_bus(ns);
}
-static int ae3xx_spi_release_bus(struct udevice *dev)
+static int atcspi200_spi_release_bus(struct udevice *dev)
{
struct nds_spi_slave *ns = dev_get_priv(dev->parent);
- return __ae3xx_spi_release_bus(ns);
+ return __atcspi200_spi_release_bus(ns);
}
-static int ae3xx_spi_xfer(struct udevice *dev, unsigned int bitlen,
+static int atcspi200_spi_xfer(struct udevice *dev, unsigned int bitlen,
const void *dout, void *din,
unsigned long flags)
{
struct udevice *bus = dev->parent;
struct nds_spi_slave *ns = dev_get_priv(bus);
- return __ae3xx_spi_xfer(ns, bitlen, dout, din, flags);
+ return __atcspi200_spi_xfer(ns, bitlen, dout, din, flags);
}
-static int ae3xx_spi_get_clk(struct udevice *bus)
+static int atcspi200_spi_get_clk(struct udevice *bus)
{
struct nds_spi_slave *ns = dev_get_priv(bus);
struct clk clk;
return 0;
}
-static int ae3xx_spi_probe(struct udevice *bus)
+static int atcspi200_spi_probe(struct udevice *bus)
{
struct nds_spi_slave *ns = dev_get_priv(bus);
ns->to = SPI_TIMEOUT;
ns->max_transfer_length = MAX_TRANSFER_LEN;
ns->mtiming = ns->regs->timing;
- ae3xx_spi_get_clk(bus);
+ atcspi200_spi_get_clk(bus);
return 0;
}
-static int ae3xx_ofdata_to_platadata(struct udevice *bus)
+static int atcspi200_ofdata_to_platadata(struct udevice *bus)
{
struct nds_spi_slave *ns = dev_get_priv(bus);
const void *blob = gd->fdt_blob;
int node = dev_of_offset(bus);
ns->regs = map_physmem(devfdt_get_addr(bus),
- sizeof(struct ae3xx_spi_regs),
+ sizeof(struct atcspi200_spi_regs),
MAP_NOCACHE);
if (!ns->regs) {
printf("%s: could not map device address\n", __func__);
return 0;
}
-static const struct dm_spi_ops ae3xx_spi_ops = {
- .claim_bus = ae3xx_spi_claim_bus,
- .release_bus = ae3xx_spi_release_bus,
- .xfer = ae3xx_spi_xfer,
- .set_speed = ae3xx_spi_set_speed,
- .set_mode = ae3xx_spi_set_mode,
+static const struct dm_spi_ops atcspi200_spi_ops = {
+ .claim_bus = atcspi200_spi_claim_bus,
+ .release_bus = atcspi200_spi_release_bus,
+ .xfer = atcspi200_spi_xfer,
+ .set_speed = atcspi200_spi_set_speed,
+ .set_mode = atcspi200_spi_set_mode,
};
-static const struct udevice_id ae3xx_spi_ids[] = {
+static const struct udevice_id atcspi200_spi_ids[] = {
{ .compatible = "andestech,atcspi200" },
{ }
};
-U_BOOT_DRIVER(ae3xx_spi) = {
- .name = "ae3xx_spi",
+U_BOOT_DRIVER(atcspi200_spi) = {
+ .name = "atcspi200_spi",
.id = UCLASS_SPI,
- .of_match = ae3xx_spi_ids,
- .ops = &ae3xx_spi_ops,
- .ofdata_to_platdata = ae3xx_ofdata_to_platadata,
+ .of_match = atcspi200_spi_ids,
+ .ops = &atcspi200_spi_ops,
+ .ofdata_to_platdata = atcspi200_ofdata_to_platadata,
.priv_auto_alloc_size = sizeof(struct nds_spi_slave),
- .probe = ae3xx_spi_probe,
+ .probe = atcspi200_spi_probe,
};
#endif