2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2012-11-02 01:15:36 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2012 SAMSUNG Electronics
|
|
|
|
* Padmavathi Venna <padma.v@samsung.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2014-10-14 05:42:01 +00:00
|
|
|
#include <dm.h>
|
|
|
|
#include <errno.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2012-11-02 01:15:36 +00:00
|
|
|
#include <malloc.h>
|
|
|
|
#include <spi.h>
|
2012-12-26 20:03:23 +00:00
|
|
|
#include <fdtdec.h>
|
2019-11-14 19:57:30 +00:00
|
|
|
#include <time.h>
|
2012-11-02 01:15:36 +00:00
|
|
|
#include <asm/arch/clk.h>
|
|
|
|
#include <asm/arch/clock.h>
|
|
|
|
#include <asm/arch/cpu.h>
|
|
|
|
#include <asm/arch/gpio.h>
|
|
|
|
#include <asm/arch/pinmux.h>
|
2015-08-03 12:28:00 +00:00
|
|
|
#include <asm/arch/spi.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2012-11-02 01:15:36 +00:00
|
|
|
#include <asm/io.h>
|
2020-05-10 17:40:11 +00:00
|
|
|
#include <linux/delay.h>
|
2012-11-02 01:15:36 +00:00
|
|
|
|
2012-12-26 20:03:23 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2020-12-03 23:55:23 +00:00
|
|
|
struct exynos_spi_plat {
|
2012-11-02 01:15:36 +00:00
|
|
|
enum periph_id periph_id;
|
|
|
|
s32 frequency; /* Default clock frequency, -1 for none */
|
|
|
|
struct exynos_spi *regs;
|
2013-10-08 10:50:04 +00:00
|
|
|
uint deactivate_delay_us; /* Delay to wait after deactivate */
|
2012-11-02 01:15:36 +00:00
|
|
|
};
|
|
|
|
|
2014-10-14 05:42:01 +00:00
|
|
|
struct exynos_spi_priv {
|
2012-11-02 01:15:36 +00:00
|
|
|
struct exynos_spi *regs;
|
|
|
|
unsigned int freq; /* Default frequency */
|
|
|
|
unsigned int mode;
|
|
|
|
enum periph_id periph_id; /* Peripheral ID for this device */
|
|
|
|
unsigned int fifo_size;
|
2013-05-28 20:10:38 +00:00
|
|
|
int skip_preamble;
|
2013-10-08 10:50:04 +00:00
|
|
|
ulong last_transaction_us; /* Time of last transaction end */
|
2012-11-02 01:15:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Flush spi tx, rx fifos and reset the SPI controller
|
|
|
|
*
|
2014-10-14 05:42:01 +00:00
|
|
|
* @param regs Pointer to SPI registers
|
2012-11-02 01:15:36 +00:00
|
|
|
*/
|
2014-10-14 05:42:01 +00:00
|
|
|
static void spi_flush_fifo(struct exynos_spi *regs)
|
2012-11-02 01:15:36 +00:00
|
|
|
{
|
|
|
|
clrsetbits_le32(®s->ch_cfg, SPI_CH_HS_EN, SPI_CH_RST);
|
|
|
|
clrbits_le32(®s->ch_cfg, SPI_CH_RST);
|
|
|
|
setbits_le32(®s->ch_cfg, SPI_TX_CH_ON | SPI_RX_CH_ON);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void spi_get_fifo_levels(struct exynos_spi *regs,
|
|
|
|
int *rx_lvl, int *tx_lvl)
|
|
|
|
{
|
|
|
|
uint32_t spi_sts = readl(®s->spi_sts);
|
|
|
|
|
|
|
|
*rx_lvl = (spi_sts >> SPI_RX_LVL_OFFSET) & SPI_FIFO_LVL_MASK;
|
|
|
|
*tx_lvl = (spi_sts >> SPI_TX_LVL_OFFSET) & SPI_FIFO_LVL_MASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If there's something to transfer, do a software reset and set a
|
|
|
|
* transaction size.
|
|
|
|
*
|
|
|
|
* @param regs SPI peripheral registers
|
|
|
|
* @param count Number of bytes to transfer
|
2013-10-08 10:50:06 +00:00
|
|
|
* @param step Number of bytes to transfer in each packet (1 or 4)
|
2012-11-02 01:15:36 +00:00
|
|
|
*/
|
2013-10-08 10:50:06 +00:00
|
|
|
static void spi_request_bytes(struct exynos_spi *regs, int count, int step)
|
2012-11-02 01:15:36 +00:00
|
|
|
{
|
2014-10-14 05:42:01 +00:00
|
|
|
debug("%s: regs=%p, count=%d, step=%d\n", __func__, regs, count, step);
|
|
|
|
|
2013-10-08 10:50:06 +00:00
|
|
|
/* For word address we need to swap bytes */
|
|
|
|
if (step == 4) {
|
|
|
|
setbits_le32(®s->mode_cfg,
|
|
|
|
SPI_MODE_CH_WIDTH_WORD | SPI_MODE_BUS_WIDTH_WORD);
|
|
|
|
count /= 4;
|
|
|
|
setbits_le32(®s->swap_cfg, SPI_TX_SWAP_EN | SPI_RX_SWAP_EN |
|
|
|
|
SPI_TX_BYTE_SWAP | SPI_RX_BYTE_SWAP |
|
|
|
|
SPI_TX_HWORD_SWAP | SPI_RX_HWORD_SWAP);
|
|
|
|
} else {
|
|
|
|
/* Select byte access and clear the swap configuration */
|
|
|
|
clrbits_le32(®s->mode_cfg,
|
|
|
|
SPI_MODE_CH_WIDTH_WORD | SPI_MODE_BUS_WIDTH_WORD);
|
|
|
|
writel(0, ®s->swap_cfg);
|
|
|
|
}
|
|
|
|
|
2012-11-02 01:15:36 +00:00
|
|
|
assert(count && count < (1 << 16));
|
|
|
|
setbits_le32(®s->ch_cfg, SPI_CH_RST);
|
|
|
|
clrbits_le32(®s->ch_cfg, SPI_CH_RST);
|
2013-10-08 10:50:06 +00:00
|
|
|
|
2012-11-02 01:15:36 +00:00
|
|
|
writel(count | SPI_PACKET_CNT_EN, ®s->pkt_cnt);
|
|
|
|
}
|
|
|
|
|
2014-10-14 05:42:01 +00:00
|
|
|
static int spi_rx_tx(struct exynos_spi_priv *priv, int todo,
|
2013-05-28 20:10:38 +00:00
|
|
|
void **dinp, void const **doutp, unsigned long flags)
|
2012-11-02 01:15:36 +00:00
|
|
|
{
|
2014-10-14 05:42:01 +00:00
|
|
|
struct exynos_spi *regs = priv->regs;
|
2012-11-02 01:15:36 +00:00
|
|
|
uchar *rxp = *dinp;
|
|
|
|
const uchar *txp = *doutp;
|
|
|
|
int rx_lvl, tx_lvl;
|
|
|
|
uint out_bytes, in_bytes;
|
2013-05-28 20:10:38 +00:00
|
|
|
int toread;
|
|
|
|
unsigned start = get_timer(0);
|
|
|
|
int stopping;
|
2013-10-08 10:50:06 +00:00
|
|
|
int step;
|
2012-11-02 01:15:36 +00:00
|
|
|
|
|
|
|
out_bytes = in_bytes = todo;
|
|
|
|
|
2014-10-14 05:42:01 +00:00
|
|
|
stopping = priv->skip_preamble && (flags & SPI_XFER_END) &&
|
|
|
|
!(priv->mode & SPI_SLAVE);
|
2013-05-28 20:10:38 +00:00
|
|
|
|
2013-10-08 10:50:06 +00:00
|
|
|
/*
|
|
|
|
* Try to transfer words if we can. This helps read performance at
|
|
|
|
* SPI clock speeds above about 20MHz.
|
|
|
|
*/
|
|
|
|
step = 1;
|
|
|
|
if (!((todo | (uintptr_t)rxp | (uintptr_t)txp) & 3) &&
|
2014-10-14 05:42:01 +00:00
|
|
|
!priv->skip_preamble)
|
2013-10-08 10:50:06 +00:00
|
|
|
step = 4;
|
|
|
|
|
2012-11-02 01:15:36 +00:00
|
|
|
/*
|
|
|
|
* If there's something to send, do a software reset and set a
|
|
|
|
* transaction size.
|
|
|
|
*/
|
2013-10-08 10:50:06 +00:00
|
|
|
spi_request_bytes(regs, todo, step);
|
2012-11-02 01:15:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Bytes are transmitted/received in pairs. Wait to receive all the
|
|
|
|
* data because then transmission will be done as well.
|
|
|
|
*/
|
2013-05-28 20:10:38 +00:00
|
|
|
toread = in_bytes;
|
|
|
|
|
2012-11-02 01:15:36 +00:00
|
|
|
while (in_bytes) {
|
|
|
|
int temp;
|
|
|
|
|
|
|
|
/* Keep the fifos full/empty. */
|
|
|
|
spi_get_fifo_levels(regs, &rx_lvl, &tx_lvl);
|
2013-10-08 10:50:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't completely fill the txfifo, since we don't want our
|
|
|
|
* rxfifo to overflow, and it may already contain data.
|
|
|
|
*/
|
2014-10-14 05:42:01 +00:00
|
|
|
while (tx_lvl < priv->fifo_size/2 && out_bytes) {
|
2013-10-08 10:50:06 +00:00
|
|
|
if (!txp)
|
|
|
|
temp = -1;
|
|
|
|
else if (step == 4)
|
|
|
|
temp = *(uint32_t *)txp;
|
|
|
|
else
|
|
|
|
temp = *txp;
|
2012-11-02 01:15:36 +00:00
|
|
|
writel(temp, ®s->tx_data);
|
2013-10-08 10:50:06 +00:00
|
|
|
out_bytes -= step;
|
|
|
|
if (txp)
|
|
|
|
txp += step;
|
|
|
|
tx_lvl += step;
|
2012-11-02 01:15:36 +00:00
|
|
|
}
|
2013-10-08 10:50:06 +00:00
|
|
|
if (rx_lvl >= step) {
|
|
|
|
while (rx_lvl >= step) {
|
2013-10-08 10:50:05 +00:00
|
|
|
temp = readl(®s->rx_data);
|
2014-10-14 05:42:01 +00:00
|
|
|
if (priv->skip_preamble) {
|
2013-10-08 10:50:05 +00:00
|
|
|
if (temp == SPI_PREAMBLE_END_BYTE) {
|
2014-10-14 05:42:01 +00:00
|
|
|
priv->skip_preamble = 0;
|
2013-10-08 10:50:05 +00:00
|
|
|
stopping = 0;
|
|
|
|
}
|
|
|
|
} else {
|
2013-10-08 10:50:06 +00:00
|
|
|
if (rxp || stopping) {
|
2014-06-18 12:22:41 +00:00
|
|
|
if (step == 4)
|
|
|
|
*(uint32_t *)rxp = temp;
|
|
|
|
else
|
|
|
|
*rxp = temp;
|
2013-10-08 10:50:06 +00:00
|
|
|
rxp += step;
|
|
|
|
}
|
|
|
|
in_bytes -= step;
|
2013-05-28 20:10:38 +00:00
|
|
|
}
|
2013-10-08 10:50:06 +00:00
|
|
|
toread -= step;
|
|
|
|
rx_lvl -= step;
|
|
|
|
}
|
2013-05-28 20:10:38 +00:00
|
|
|
} else if (!toread) {
|
|
|
|
/*
|
|
|
|
* We have run out of input data, but haven't read
|
|
|
|
* enough bytes after the preamble yet. Read some more,
|
|
|
|
* and make sure that we transmit dummy bytes too, to
|
|
|
|
* keep things going.
|
|
|
|
*/
|
|
|
|
assert(!out_bytes);
|
|
|
|
out_bytes = in_bytes;
|
|
|
|
toread = in_bytes;
|
|
|
|
txp = NULL;
|
2013-10-08 10:50:06 +00:00
|
|
|
spi_request_bytes(regs, toread, step);
|
2013-05-28 20:10:38 +00:00
|
|
|
}
|
2014-10-14 05:42:01 +00:00
|
|
|
if (priv->skip_preamble && get_timer(start) > 100) {
|
2015-07-03 00:16:11 +00:00
|
|
|
debug("SPI timeout: in_bytes=%d, out_bytes=%d, ",
|
|
|
|
in_bytes, out_bytes);
|
|
|
|
return -ETIMEDOUT;
|
2012-11-02 01:15:36 +00:00
|
|
|
}
|
|
|
|
}
|
2013-05-28 20:10:38 +00:00
|
|
|
|
2012-11-02 01:15:36 +00:00
|
|
|
*dinp = rxp;
|
|
|
|
*doutp = txp;
|
2013-05-28 20:10:38 +00:00
|
|
|
|
|
|
|
return 0;
|
2012-11-02 01:15:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Activate the CS by driving it LOW
|
|
|
|
*
|
|
|
|
* @param slave Pointer to spi_slave to which controller has to
|
|
|
|
* communicate with
|
|
|
|
*/
|
2014-10-14 05:42:01 +00:00
|
|
|
static void spi_cs_activate(struct udevice *dev)
|
2012-11-02 01:15:36 +00:00
|
|
|
{
|
2014-10-14 05:42:01 +00:00
|
|
|
struct udevice *bus = dev->parent;
|
2020-12-03 23:55:23 +00:00
|
|
|
struct exynos_spi_plat *pdata = dev_get_plat(bus);
|
2014-10-14 05:42:01 +00:00
|
|
|
struct exynos_spi_priv *priv = dev_get_priv(bus);
|
2012-11-02 01:15:36 +00:00
|
|
|
|
2013-10-08 10:50:04 +00:00
|
|
|
/* If it's too soon to do another transaction, wait */
|
2014-10-14 05:42:01 +00:00
|
|
|
if (pdata->deactivate_delay_us &&
|
|
|
|
priv->last_transaction_us) {
|
2013-10-08 10:50:04 +00:00
|
|
|
ulong delay_us; /* The delay completed so far */
|
2014-10-14 05:42:01 +00:00
|
|
|
delay_us = timer_get_us() - priv->last_transaction_us;
|
|
|
|
if (delay_us < pdata->deactivate_delay_us)
|
|
|
|
udelay(pdata->deactivate_delay_us - delay_us);
|
2013-10-08 10:50:04 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 05:42:01 +00:00
|
|
|
clrbits_le32(&priv->regs->cs_reg, SPI_SLAVE_SIG_INACT);
|
|
|
|
debug("Activate CS, bus '%s'\n", bus->name);
|
|
|
|
priv->skip_preamble = priv->mode & SPI_PREAMBLE;
|
2012-11-02 01:15:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deactivate the CS by driving it HIGH
|
|
|
|
*
|
|
|
|
* @param slave Pointer to spi_slave to which controller has to
|
|
|
|
* communicate with
|
|
|
|
*/
|
2014-10-14 05:42:01 +00:00
|
|
|
static void spi_cs_deactivate(struct udevice *dev)
|
2012-11-02 01:15:36 +00:00
|
|
|
{
|
2014-10-14 05:42:01 +00:00
|
|
|
struct udevice *bus = dev->parent;
|
2020-12-03 23:55:23 +00:00
|
|
|
struct exynos_spi_plat *pdata = dev_get_plat(bus);
|
2014-10-14 05:42:01 +00:00
|
|
|
struct exynos_spi_priv *priv = dev_get_priv(bus);
|
2012-11-02 01:15:36 +00:00
|
|
|
|
2014-10-14 05:42:01 +00:00
|
|
|
setbits_le32(&priv->regs->cs_reg, SPI_SLAVE_SIG_INACT);
|
2014-07-07 16:16:38 +00:00
|
|
|
|
|
|
|
/* Remember time of this transaction so we can honour the bus delay */
|
2014-10-14 05:42:01 +00:00
|
|
|
if (pdata->deactivate_delay_us)
|
|
|
|
priv->last_transaction_us = timer_get_us();
|
2014-07-07 16:16:38 +00:00
|
|
|
|
2014-10-14 05:42:01 +00:00
|
|
|
debug("Deactivate CS, bus '%s'\n", bus->name);
|
2012-11-02 01:15:36 +00:00
|
|
|
}
|
|
|
|
|
2020-12-03 23:55:21 +00:00
|
|
|
static int exynos_spi_of_to_plat(struct udevice *bus)
|
2012-11-02 01:15:36 +00:00
|
|
|
{
|
2020-12-23 02:30:28 +00:00
|
|
|
struct exynos_spi_plat *plat = dev_get_plat(bus);
|
2014-10-14 05:42:01 +00:00
|
|
|
const void *blob = gd->fdt_blob;
|
2017-01-17 23:52:55 +00:00
|
|
|
int node = dev_of_offset(bus);
|
2012-11-02 01:15:36 +00:00
|
|
|
|
2020-07-17 05:36:46 +00:00
|
|
|
plat->regs = dev_read_addr_ptr(bus);
|
2014-10-14 05:42:01 +00:00
|
|
|
plat->periph_id = pinmux_decode_periph_id(blob, node);
|
2012-12-26 20:03:23 +00:00
|
|
|
|
2014-10-14 05:42:01 +00:00
|
|
|
if (plat->periph_id == PERIPH_ID_NONE) {
|
2012-12-26 20:03:23 +00:00
|
|
|
debug("%s: Invalid peripheral ID %d\n", __func__,
|
2014-10-14 05:42:01 +00:00
|
|
|
plat->periph_id);
|
2012-12-26 20:03:23 +00:00
|
|
|
return -FDT_ERR_NOTFOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Use 500KHz as a suitable default */
|
2014-10-14 05:42:01 +00:00
|
|
|
plat->frequency = fdtdec_get_int(blob, node, "spi-max-frequency",
|
2012-12-26 20:03:23 +00:00
|
|
|
500000);
|
2014-10-14 05:42:01 +00:00
|
|
|
plat->deactivate_delay_us = fdtdec_get_int(blob, node,
|
2013-10-08 10:50:04 +00:00
|
|
|
"spi-deactivate-delay", 0);
|
2014-10-14 05:42:01 +00:00
|
|
|
debug("%s: regs=%p, periph_id=%d, max-frequency=%d, deactivate_delay=%d\n",
|
|
|
|
__func__, plat->regs, plat->periph_id, plat->frequency,
|
|
|
|
plat->deactivate_delay_us);
|
2012-12-26 20:03:23 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-14 05:42:01 +00:00
|
|
|
static int exynos_spi_probe(struct udevice *bus)
|
2012-12-26 20:03:23 +00:00
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct exynos_spi_plat *plat = dev_get_plat(bus);
|
2014-10-14 05:42:01 +00:00
|
|
|
struct exynos_spi_priv *priv = dev_get_priv(bus);
|
2012-12-26 20:03:23 +00:00
|
|
|
|
2014-10-14 05:42:01 +00:00
|
|
|
priv->regs = plat->regs;
|
|
|
|
if (plat->periph_id == PERIPH_ID_SPI1 ||
|
|
|
|
plat->periph_id == PERIPH_ID_SPI2)
|
|
|
|
priv->fifo_size = 64;
|
|
|
|
else
|
|
|
|
priv->fifo_size = 256;
|
2012-12-26 20:03:23 +00:00
|
|
|
|
2014-10-14 05:42:01 +00:00
|
|
|
priv->skip_preamble = 0;
|
|
|
|
priv->last_transaction_us = timer_get_us();
|
|
|
|
priv->freq = plat->frequency;
|
|
|
|
priv->periph_id = plat->periph_id;
|
2012-12-26 20:03:23 +00:00
|
|
|
|
2014-10-14 05:42:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2012-12-26 20:03:23 +00:00
|
|
|
|
2015-04-19 15:05:40 +00:00
|
|
|
static int exynos_spi_claim_bus(struct udevice *dev)
|
2014-10-14 05:42:01 +00:00
|
|
|
{
|
2015-04-19 15:05:40 +00:00
|
|
|
struct udevice *bus = dev->parent;
|
2014-10-14 05:42:01 +00:00
|
|
|
struct exynos_spi_priv *priv = dev_get_priv(bus);
|
|
|
|
|
|
|
|
exynos_pinmux_config(priv->periph_id, PINMUX_FLAG_NONE);
|
|
|
|
spi_flush_fifo(priv->regs);
|
|
|
|
|
|
|
|
writel(SPI_FB_DELAY_180, &priv->regs->fb_clk);
|
2012-12-26 20:03:23 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-19 15:05:40 +00:00
|
|
|
static int exynos_spi_release_bus(struct udevice *dev)
|
2013-05-15 10:27:30 +00:00
|
|
|
{
|
2015-04-19 15:05:40 +00:00
|
|
|
struct udevice *bus = dev->parent;
|
2014-10-14 05:42:01 +00:00
|
|
|
struct exynos_spi_priv *priv = dev_get_priv(bus);
|
|
|
|
|
|
|
|
spi_flush_fifo(priv->regs);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int exynos_spi_xfer(struct udevice *dev, unsigned int bitlen,
|
|
|
|
const void *dout, void *din, unsigned long flags)
|
|
|
|
{
|
|
|
|
struct udevice *bus = dev->parent;
|
|
|
|
struct exynos_spi_priv *priv = dev_get_priv(bus);
|
|
|
|
int upto, todo;
|
|
|
|
int bytelen;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
/* spi core configured to do 8 bit transfers */
|
|
|
|
if (bitlen % 8) {
|
|
|
|
debug("Non byte aligned SPI transfer.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Start the transaction, if necessary. */
|
|
|
|
if ((flags & SPI_XFER_BEGIN))
|
|
|
|
spi_cs_activate(dev);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Exynos SPI limits each transfer to 65535 transfers. To keep
|
|
|
|
* things simple, allow a maximum of 65532 bytes. We could allow
|
|
|
|
* more in word mode, but the performance difference is small.
|
|
|
|
*/
|
|
|
|
bytelen = bitlen / 8;
|
|
|
|
for (upto = 0; !ret && upto < bytelen; upto += todo) {
|
|
|
|
todo = min(bytelen - upto, (1 << 16) - 4);
|
|
|
|
ret = spi_rx_tx(priv, todo, &din, &dout, flags);
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
}
|
2013-05-15 10:27:30 +00:00
|
|
|
|
2014-10-14 05:42:01 +00:00
|
|
|
/* Stop the transaction, if necessary. */
|
|
|
|
if ((flags & SPI_XFER_END) && !(priv->mode & SPI_SLAVE)) {
|
|
|
|
spi_cs_deactivate(dev);
|
|
|
|
if (priv->skip_preamble) {
|
|
|
|
assert(!priv->skip_preamble);
|
|
|
|
debug("Failed to complete premable transaction\n");
|
|
|
|
ret = -1;
|
|
|
|
}
|
2013-05-15 10:27:30 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 05:42:01 +00:00
|
|
|
return ret;
|
2013-05-15 10:27:30 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 05:42:01 +00:00
|
|
|
static int exynos_spi_set_speed(struct udevice *bus, uint speed)
|
2012-11-02 01:15:36 +00:00
|
|
|
{
|
2020-12-23 02:30:28 +00:00
|
|
|
struct exynos_spi_plat *plat = dev_get_plat(bus);
|
2014-10-14 05:42:01 +00:00
|
|
|
struct exynos_spi_priv *priv = dev_get_priv(bus);
|
|
|
|
int ret;
|
2012-12-26 20:03:23 +00:00
|
|
|
|
2014-10-14 05:42:01 +00:00
|
|
|
if (speed > plat->frequency)
|
|
|
|
speed = plat->frequency;
|
|
|
|
ret = set_spi_clk(priv->periph_id, speed);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
priv->freq = speed;
|
|
|
|
debug("%s: regs=%p, speed=%d\n", __func__, priv->regs, priv->freq);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2012-12-26 20:03:23 +00:00
|
|
|
|
2014-10-14 05:42:01 +00:00
|
|
|
static int exynos_spi_set_mode(struct udevice *bus, uint mode)
|
|
|
|
{
|
|
|
|
struct exynos_spi_priv *priv = dev_get_priv(bus);
|
|
|
|
uint32_t reg;
|
2012-12-26 20:03:23 +00:00
|
|
|
|
2014-10-14 05:42:01 +00:00
|
|
|
reg = readl(&priv->regs->ch_cfg);
|
|
|
|
reg &= ~(SPI_CH_CPHA_B | SPI_CH_CPOL_L);
|
2012-11-02 01:15:36 +00:00
|
|
|
|
2014-10-14 05:42:01 +00:00
|
|
|
if (mode & SPI_CPHA)
|
|
|
|
reg |= SPI_CH_CPHA_B;
|
2012-11-02 01:15:36 +00:00
|
|
|
|
2014-10-14 05:42:01 +00:00
|
|
|
if (mode & SPI_CPOL)
|
|
|
|
reg |= SPI_CH_CPOL_L;
|
|
|
|
|
|
|
|
writel(reg, &priv->regs->ch_cfg);
|
|
|
|
priv->mode = mode;
|
|
|
|
debug("%s: regs=%p, mode=%d\n", __func__, priv->regs, priv->mode);
|
|
|
|
|
|
|
|
return 0;
|
2012-11-02 01:15:36 +00:00
|
|
|
}
|
2014-10-14 05:42:01 +00:00
|
|
|
|
|
|
|
static const struct dm_spi_ops exynos_spi_ops = {
|
|
|
|
.claim_bus = exynos_spi_claim_bus,
|
|
|
|
.release_bus = exynos_spi_release_bus,
|
|
|
|
.xfer = exynos_spi_xfer,
|
|
|
|
.set_speed = exynos_spi_set_speed,
|
|
|
|
.set_mode = exynos_spi_set_mode,
|
|
|
|
/*
|
|
|
|
* cs_info is not needed, since we require all chip selects to be
|
|
|
|
* in the device tree explicitly
|
|
|
|
*/
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id exynos_spi_ids[] = {
|
|
|
|
{ .compatible = "samsung,exynos-spi" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(exynos_spi) = {
|
|
|
|
.name = "exynos_spi",
|
|
|
|
.id = UCLASS_SPI,
|
|
|
|
.of_match = exynos_spi_ids,
|
|
|
|
.ops = &exynos_spi_ops,
|
2020-12-03 23:55:21 +00:00
|
|
|
.of_to_plat = exynos_spi_of_to_plat,
|
2020-12-03 23:55:23 +00:00
|
|
|
.plat_auto = sizeof(struct exynos_spi_plat),
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct exynos_spi_priv),
|
2014-10-14 05:42:01 +00:00
|
|
|
.probe = exynos_spi_probe,
|
|
|
|
};
|