blob: a9691c7603a7b161a3421d94f12668b349aefaf9 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +00002/*
3 * (C) Copyright 2012 SAMSUNG Electronics
4 * Padmavathi Venna <padma.v@samsung.com>
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +00005 */
6
7#include <common.h>
Simon Glassca7eafe2014-10-13 23:42:01 -06008#include <dm.h>
9#include <errno.h>
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +000010#include <malloc.h>
11#include <spi.h>
Rajeshwari Shinde64ef8a32012-12-26 20:03:23 +000012#include <fdtdec.h>
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +000013#include <asm/arch/clk.h>
14#include <asm/arch/clock.h>
15#include <asm/arch/cpu.h>
16#include <asm/arch/gpio.h>
17#include <asm/arch/pinmux.h>
Thomas Abraham74f84862015-08-03 17:58:00 +053018#include <asm/arch/spi.h>
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +000019#include <asm/io.h>
20
Rajeshwari Shinde64ef8a32012-12-26 20:03:23 +000021DECLARE_GLOBAL_DATA_PTR;
22
Simon Glassca7eafe2014-10-13 23:42:01 -060023struct exynos_spi_platdata {
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +000024 enum periph_id periph_id;
25 s32 frequency; /* Default clock frequency, -1 for none */
26 struct exynos_spi *regs;
Rajeshwari Shindeab46adb2013-10-08 16:20:04 +053027 uint deactivate_delay_us; /* Delay to wait after deactivate */
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +000028};
29
Simon Glassca7eafe2014-10-13 23:42:01 -060030struct exynos_spi_priv {
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +000031 struct exynos_spi *regs;
32 unsigned int freq; /* Default frequency */
33 unsigned int mode;
34 enum periph_id periph_id; /* Peripheral ID for this device */
35 unsigned int fifo_size;
Rajeshwari Shinde813637c2013-05-28 20:10:38 +000036 int skip_preamble;
Rajeshwari Shindeab46adb2013-10-08 16:20:04 +053037 ulong last_transaction_us; /* Time of last transaction end */
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +000038};
39
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +000040/**
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +000041 * Flush spi tx, rx fifos and reset the SPI controller
42 *
Simon Glassca7eafe2014-10-13 23:42:01 -060043 * @param regs Pointer to SPI registers
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +000044 */
Simon Glassca7eafe2014-10-13 23:42:01 -060045static void spi_flush_fifo(struct exynos_spi *regs)
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +000046{
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +000047 clrsetbits_le32(&regs->ch_cfg, SPI_CH_HS_EN, SPI_CH_RST);
48 clrbits_le32(&regs->ch_cfg, SPI_CH_RST);
49 setbits_le32(&regs->ch_cfg, SPI_TX_CH_ON | SPI_RX_CH_ON);
50}
51
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +000052static void spi_get_fifo_levels(struct exynos_spi *regs,
53 int *rx_lvl, int *tx_lvl)
54{
55 uint32_t spi_sts = readl(&regs->spi_sts);
56
57 *rx_lvl = (spi_sts >> SPI_RX_LVL_OFFSET) & SPI_FIFO_LVL_MASK;
58 *tx_lvl = (spi_sts >> SPI_TX_LVL_OFFSET) & SPI_FIFO_LVL_MASK;
59}
60
61/**
62 * If there's something to transfer, do a software reset and set a
63 * transaction size.
64 *
65 * @param regs SPI peripheral registers
66 * @param count Number of bytes to transfer
Rajeshwari Shindeffc74612013-10-08 16:20:06 +053067 * @param step Number of bytes to transfer in each packet (1 or 4)
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +000068 */
Rajeshwari Shindeffc74612013-10-08 16:20:06 +053069static void spi_request_bytes(struct exynos_spi *regs, int count, int step)
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +000070{
Simon Glassca7eafe2014-10-13 23:42:01 -060071 debug("%s: regs=%p, count=%d, step=%d\n", __func__, regs, count, step);
72
Rajeshwari Shindeffc74612013-10-08 16:20:06 +053073 /* For word address we need to swap bytes */
74 if (step == 4) {
75 setbits_le32(&regs->mode_cfg,
76 SPI_MODE_CH_WIDTH_WORD | SPI_MODE_BUS_WIDTH_WORD);
77 count /= 4;
78 setbits_le32(&regs->swap_cfg, SPI_TX_SWAP_EN | SPI_RX_SWAP_EN |
79 SPI_TX_BYTE_SWAP | SPI_RX_BYTE_SWAP |
80 SPI_TX_HWORD_SWAP | SPI_RX_HWORD_SWAP);
81 } else {
82 /* Select byte access and clear the swap configuration */
83 clrbits_le32(&regs->mode_cfg,
84 SPI_MODE_CH_WIDTH_WORD | SPI_MODE_BUS_WIDTH_WORD);
85 writel(0, &regs->swap_cfg);
86 }
87
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +000088 assert(count && count < (1 << 16));
89 setbits_le32(&regs->ch_cfg, SPI_CH_RST);
90 clrbits_le32(&regs->ch_cfg, SPI_CH_RST);
Rajeshwari Shindeffc74612013-10-08 16:20:06 +053091
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +000092 writel(count | SPI_PACKET_CNT_EN, &regs->pkt_cnt);
93}
94
Simon Glassca7eafe2014-10-13 23:42:01 -060095static int spi_rx_tx(struct exynos_spi_priv *priv, int todo,
Rajeshwari Shinde813637c2013-05-28 20:10:38 +000096 void **dinp, void const **doutp, unsigned long flags)
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +000097{
Simon Glassca7eafe2014-10-13 23:42:01 -060098 struct exynos_spi *regs = priv->regs;
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +000099 uchar *rxp = *dinp;
100 const uchar *txp = *doutp;
101 int rx_lvl, tx_lvl;
102 uint out_bytes, in_bytes;
Rajeshwari Shinde813637c2013-05-28 20:10:38 +0000103 int toread;
104 unsigned start = get_timer(0);
105 int stopping;
Rajeshwari Shindeffc74612013-10-08 16:20:06 +0530106 int step;
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +0000107
108 out_bytes = in_bytes = todo;
109
Simon Glassca7eafe2014-10-13 23:42:01 -0600110 stopping = priv->skip_preamble && (flags & SPI_XFER_END) &&
111 !(priv->mode & SPI_SLAVE);
Rajeshwari Shinde813637c2013-05-28 20:10:38 +0000112
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +0000113 /*
Rajeshwari Shindeffc74612013-10-08 16:20:06 +0530114 * Try to transfer words if we can. This helps read performance at
115 * SPI clock speeds above about 20MHz.
116 */
117 step = 1;
118 if (!((todo | (uintptr_t)rxp | (uintptr_t)txp) & 3) &&
Simon Glassca7eafe2014-10-13 23:42:01 -0600119 !priv->skip_preamble)
Rajeshwari Shindeffc74612013-10-08 16:20:06 +0530120 step = 4;
121
122 /*
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +0000123 * If there's something to send, do a software reset and set a
124 * transaction size.
125 */
Rajeshwari Shindeffc74612013-10-08 16:20:06 +0530126 spi_request_bytes(regs, todo, step);
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +0000127
128 /*
129 * Bytes are transmitted/received in pairs. Wait to receive all the
130 * data because then transmission will be done as well.
131 */
Rajeshwari Shinde813637c2013-05-28 20:10:38 +0000132 toread = in_bytes;
133
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +0000134 while (in_bytes) {
135 int temp;
136
137 /* Keep the fifos full/empty. */
138 spi_get_fifo_levels(regs, &rx_lvl, &tx_lvl);
Rajeshwari Shindeffc74612013-10-08 16:20:06 +0530139
140 /*
141 * Don't completely fill the txfifo, since we don't want our
142 * rxfifo to overflow, and it may already contain data.
143 */
Simon Glassca7eafe2014-10-13 23:42:01 -0600144 while (tx_lvl < priv->fifo_size/2 && out_bytes) {
Rajeshwari Shindeffc74612013-10-08 16:20:06 +0530145 if (!txp)
146 temp = -1;
147 else if (step == 4)
148 temp = *(uint32_t *)txp;
149 else
150 temp = *txp;
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +0000151 writel(temp, &regs->tx_data);
Rajeshwari Shindeffc74612013-10-08 16:20:06 +0530152 out_bytes -= step;
153 if (txp)
154 txp += step;
155 tx_lvl += step;
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +0000156 }
Rajeshwari Shindeffc74612013-10-08 16:20:06 +0530157 if (rx_lvl >= step) {
158 while (rx_lvl >= step) {
Rajeshwari Shinde0c0faef2013-10-08 16:20:05 +0530159 temp = readl(&regs->rx_data);
Simon Glassca7eafe2014-10-13 23:42:01 -0600160 if (priv->skip_preamble) {
Rajeshwari Shinde0c0faef2013-10-08 16:20:05 +0530161 if (temp == SPI_PREAMBLE_END_BYTE) {
Simon Glassca7eafe2014-10-13 23:42:01 -0600162 priv->skip_preamble = 0;
Rajeshwari Shinde0c0faef2013-10-08 16:20:05 +0530163 stopping = 0;
164 }
165 } else {
Rajeshwari Shindeffc74612013-10-08 16:20:06 +0530166 if (rxp || stopping) {
Akshay Saraswat8613bed2014-06-18 17:52:41 +0530167 if (step == 4)
168 *(uint32_t *)rxp = temp;
169 else
170 *rxp = temp;
Rajeshwari Shindeffc74612013-10-08 16:20:06 +0530171 rxp += step;
172 }
173 in_bytes -= step;
Rajeshwari Shinde813637c2013-05-28 20:10:38 +0000174 }
Rajeshwari Shindeffc74612013-10-08 16:20:06 +0530175 toread -= step;
176 rx_lvl -= step;
177 }
Rajeshwari Shinde813637c2013-05-28 20:10:38 +0000178 } else if (!toread) {
179 /*
180 * We have run out of input data, but haven't read
181 * enough bytes after the preamble yet. Read some more,
182 * and make sure that we transmit dummy bytes too, to
183 * keep things going.
184 */
185 assert(!out_bytes);
186 out_bytes = in_bytes;
187 toread = in_bytes;
188 txp = NULL;
Rajeshwari Shindeffc74612013-10-08 16:20:06 +0530189 spi_request_bytes(regs, toread, step);
Rajeshwari Shinde813637c2013-05-28 20:10:38 +0000190 }
Simon Glassca7eafe2014-10-13 23:42:01 -0600191 if (priv->skip_preamble && get_timer(start) > 100) {
Simon Glass905ed0b2015-07-02 18:16:11 -0600192 debug("SPI timeout: in_bytes=%d, out_bytes=%d, ",
193 in_bytes, out_bytes);
194 return -ETIMEDOUT;
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +0000195 }
196 }
Rajeshwari Shinde813637c2013-05-28 20:10:38 +0000197
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +0000198 *dinp = rxp;
199 *doutp = txp;
Rajeshwari Shinde813637c2013-05-28 20:10:38 +0000200
201 return 0;
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +0000202}
203
204/**
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +0000205 * Activate the CS by driving it LOW
206 *
207 * @param slave Pointer to spi_slave to which controller has to
208 * communicate with
209 */
Simon Glassca7eafe2014-10-13 23:42:01 -0600210static void spi_cs_activate(struct udevice *dev)
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +0000211{
Simon Glassca7eafe2014-10-13 23:42:01 -0600212 struct udevice *bus = dev->parent;
213 struct exynos_spi_platdata *pdata = dev_get_platdata(bus);
214 struct exynos_spi_priv *priv = dev_get_priv(bus);
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +0000215
Rajeshwari Shindeab46adb2013-10-08 16:20:04 +0530216 /* If it's too soon to do another transaction, wait */
Simon Glassca7eafe2014-10-13 23:42:01 -0600217 if (pdata->deactivate_delay_us &&
218 priv->last_transaction_us) {
Rajeshwari Shindeab46adb2013-10-08 16:20:04 +0530219 ulong delay_us; /* The delay completed so far */
Simon Glassca7eafe2014-10-13 23:42:01 -0600220 delay_us = timer_get_us() - priv->last_transaction_us;
221 if (delay_us < pdata->deactivate_delay_us)
222 udelay(pdata->deactivate_delay_us - delay_us);
Rajeshwari Shindeab46adb2013-10-08 16:20:04 +0530223 }
224
Simon Glassca7eafe2014-10-13 23:42:01 -0600225 clrbits_le32(&priv->regs->cs_reg, SPI_SLAVE_SIG_INACT);
226 debug("Activate CS, bus '%s'\n", bus->name);
227 priv->skip_preamble = priv->mode & SPI_PREAMBLE;
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +0000228}
229
230/**
231 * Deactivate the CS by driving it HIGH
232 *
233 * @param slave Pointer to spi_slave to which controller has to
234 * communicate with
235 */
Simon Glassca7eafe2014-10-13 23:42:01 -0600236static void spi_cs_deactivate(struct udevice *dev)
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +0000237{
Simon Glassca7eafe2014-10-13 23:42:01 -0600238 struct udevice *bus = dev->parent;
239 struct exynos_spi_platdata *pdata = dev_get_platdata(bus);
240 struct exynos_spi_priv *priv = dev_get_priv(bus);
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +0000241
Simon Glassca7eafe2014-10-13 23:42:01 -0600242 setbits_le32(&priv->regs->cs_reg, SPI_SLAVE_SIG_INACT);
Simon Glassa193ed02014-07-07 10:16:38 -0600243
244 /* Remember time of this transaction so we can honour the bus delay */
Simon Glassca7eafe2014-10-13 23:42:01 -0600245 if (pdata->deactivate_delay_us)
246 priv->last_transaction_us = timer_get_us();
Simon Glassa193ed02014-07-07 10:16:38 -0600247
Simon Glassca7eafe2014-10-13 23:42:01 -0600248 debug("Deactivate CS, bus '%s'\n", bus->name);
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +0000249}
250
Simon Glassca7eafe2014-10-13 23:42:01 -0600251static int exynos_spi_ofdata_to_platdata(struct udevice *bus)
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +0000252{
Simon Glassca7eafe2014-10-13 23:42:01 -0600253 struct exynos_spi_platdata *plat = bus->platdata;
254 const void *blob = gd->fdt_blob;
Simon Glassdd79d6e2017-01-17 16:52:55 -0700255 int node = dev_of_offset(bus);
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +0000256
Simon Glassba1dea42017-05-17 17:18:05 -0600257 plat->regs = (struct exynos_spi *)devfdt_get_addr(bus);
Simon Glassca7eafe2014-10-13 23:42:01 -0600258 plat->periph_id = pinmux_decode_periph_id(blob, node);
Rajeshwari Shinde64ef8a32012-12-26 20:03:23 +0000259
Simon Glassca7eafe2014-10-13 23:42:01 -0600260 if (plat->periph_id == PERIPH_ID_NONE) {
Rajeshwari Shinde64ef8a32012-12-26 20:03:23 +0000261 debug("%s: Invalid peripheral ID %d\n", __func__,
Simon Glassca7eafe2014-10-13 23:42:01 -0600262 plat->periph_id);
Rajeshwari Shinde64ef8a32012-12-26 20:03:23 +0000263 return -FDT_ERR_NOTFOUND;
264 }
265
266 /* Use 500KHz as a suitable default */
Simon Glassca7eafe2014-10-13 23:42:01 -0600267 plat->frequency = fdtdec_get_int(blob, node, "spi-max-frequency",
Rajeshwari Shinde64ef8a32012-12-26 20:03:23 +0000268 500000);
Simon Glassca7eafe2014-10-13 23:42:01 -0600269 plat->deactivate_delay_us = fdtdec_get_int(blob, node,
Rajeshwari Shindeab46adb2013-10-08 16:20:04 +0530270 "spi-deactivate-delay", 0);
Simon Glassca7eafe2014-10-13 23:42:01 -0600271 debug("%s: regs=%p, periph_id=%d, max-frequency=%d, deactivate_delay=%d\n",
272 __func__, plat->regs, plat->periph_id, plat->frequency,
273 plat->deactivate_delay_us);
Rajeshwari Shinde64ef8a32012-12-26 20:03:23 +0000274
275 return 0;
276}
277
Simon Glassca7eafe2014-10-13 23:42:01 -0600278static int exynos_spi_probe(struct udevice *bus)
Rajeshwari Shinde64ef8a32012-12-26 20:03:23 +0000279{
Simon Glassca7eafe2014-10-13 23:42:01 -0600280 struct exynos_spi_platdata *plat = dev_get_platdata(bus);
281 struct exynos_spi_priv *priv = dev_get_priv(bus);
Rajeshwari Shinde64ef8a32012-12-26 20:03:23 +0000282
Simon Glassca7eafe2014-10-13 23:42:01 -0600283 priv->regs = plat->regs;
284 if (plat->periph_id == PERIPH_ID_SPI1 ||
285 plat->periph_id == PERIPH_ID_SPI2)
286 priv->fifo_size = 64;
287 else
288 priv->fifo_size = 256;
Rajeshwari Shinde64ef8a32012-12-26 20:03:23 +0000289
Simon Glassca7eafe2014-10-13 23:42:01 -0600290 priv->skip_preamble = 0;
291 priv->last_transaction_us = timer_get_us();
292 priv->freq = plat->frequency;
293 priv->periph_id = plat->periph_id;
Rajeshwari Shinde64ef8a32012-12-26 20:03:23 +0000294
Simon Glassca7eafe2014-10-13 23:42:01 -0600295 return 0;
296}
Rajeshwari Shinde64ef8a32012-12-26 20:03:23 +0000297
Simon Glass5c74fba2015-04-19 09:05:40 -0600298static int exynos_spi_claim_bus(struct udevice *dev)
Simon Glassca7eafe2014-10-13 23:42:01 -0600299{
Simon Glass5c74fba2015-04-19 09:05:40 -0600300 struct udevice *bus = dev->parent;
Simon Glassca7eafe2014-10-13 23:42:01 -0600301 struct exynos_spi_priv *priv = dev_get_priv(bus);
302
303 exynos_pinmux_config(priv->periph_id, PINMUX_FLAG_NONE);
304 spi_flush_fifo(priv->regs);
305
306 writel(SPI_FB_DELAY_180, &priv->regs->fb_clk);
Rajeshwari Shinde64ef8a32012-12-26 20:03:23 +0000307
308 return 0;
309}
310
Simon Glass5c74fba2015-04-19 09:05:40 -0600311static int exynos_spi_release_bus(struct udevice *dev)
Hung-ying Tyan00391232013-05-15 18:27:30 +0800312{
Simon Glass5c74fba2015-04-19 09:05:40 -0600313 struct udevice *bus = dev->parent;
Simon Glassca7eafe2014-10-13 23:42:01 -0600314 struct exynos_spi_priv *priv = dev_get_priv(bus);
Hung-ying Tyan00391232013-05-15 18:27:30 +0800315
Simon Glassca7eafe2014-10-13 23:42:01 -0600316 spi_flush_fifo(priv->regs);
317
318 return 0;
319}
320
321static int exynos_spi_xfer(struct udevice *dev, unsigned int bitlen,
322 const void *dout, void *din, unsigned long flags)
323{
324 struct udevice *bus = dev->parent;
325 struct exynos_spi_priv *priv = dev_get_priv(bus);
326 int upto, todo;
327 int bytelen;
328 int ret = 0;
329
330 /* spi core configured to do 8 bit transfers */
331 if (bitlen % 8) {
332 debug("Non byte aligned SPI transfer.\n");
333 return -1;
Hung-ying Tyan00391232013-05-15 18:27:30 +0800334 }
335
Simon Glassca7eafe2014-10-13 23:42:01 -0600336 /* Start the transaction, if necessary. */
337 if ((flags & SPI_XFER_BEGIN))
338 spi_cs_activate(dev);
339
340 /*
341 * Exynos SPI limits each transfer to 65535 transfers. To keep
342 * things simple, allow a maximum of 65532 bytes. We could allow
343 * more in word mode, but the performance difference is small.
344 */
345 bytelen = bitlen / 8;
346 for (upto = 0; !ret && upto < bytelen; upto += todo) {
347 todo = min(bytelen - upto, (1 << 16) - 4);
348 ret = spi_rx_tx(priv, todo, &din, &dout, flags);
349 if (ret)
350 break;
351 }
352
353 /* Stop the transaction, if necessary. */
354 if ((flags & SPI_XFER_END) && !(priv->mode & SPI_SLAVE)) {
355 spi_cs_deactivate(dev);
356 if (priv->skip_preamble) {
357 assert(!priv->skip_preamble);
358 debug("Failed to complete premable transaction\n");
359 ret = -1;
360 }
361 }
362
363 return ret;
364}
365
366static int exynos_spi_set_speed(struct udevice *bus, uint speed)
367{
368 struct exynos_spi_platdata *plat = bus->platdata;
369 struct exynos_spi_priv *priv = dev_get_priv(bus);
370 int ret;
371
372 if (speed > plat->frequency)
373 speed = plat->frequency;
374 ret = set_spi_clk(priv->periph_id, speed);
375 if (ret)
376 return ret;
377 priv->freq = speed;
378 debug("%s: regs=%p, speed=%d\n", __func__, priv->regs, priv->freq);
379
380 return 0;
Hung-ying Tyan00391232013-05-15 18:27:30 +0800381}
382
Simon Glassca7eafe2014-10-13 23:42:01 -0600383static int exynos_spi_set_mode(struct udevice *bus, uint mode)
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +0000384{
Simon Glassca7eafe2014-10-13 23:42:01 -0600385 struct exynos_spi_priv *priv = dev_get_priv(bus);
386 uint32_t reg;
Rajeshwari Shinde64ef8a32012-12-26 20:03:23 +0000387
Simon Glassca7eafe2014-10-13 23:42:01 -0600388 reg = readl(&priv->regs->ch_cfg);
389 reg &= ~(SPI_CH_CPHA_B | SPI_CH_CPOL_L);
Rajeshwari Shinde64ef8a32012-12-26 20:03:23 +0000390
Simon Glassca7eafe2014-10-13 23:42:01 -0600391 if (mode & SPI_CPHA)
392 reg |= SPI_CH_CPHA_B;
Rajeshwari Shinde64ef8a32012-12-26 20:03:23 +0000393
Simon Glassca7eafe2014-10-13 23:42:01 -0600394 if (mode & SPI_CPOL)
395 reg |= SPI_CH_CPOL_L;
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +0000396
Simon Glassca7eafe2014-10-13 23:42:01 -0600397 writel(reg, &priv->regs->ch_cfg);
398 priv->mode = mode;
399 debug("%s: regs=%p, mode=%d\n", __func__, priv->regs, priv->mode);
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +0000400
Simon Glassca7eafe2014-10-13 23:42:01 -0600401 return 0;
Rajeshwari Shindeba3b8932012-11-02 01:15:36 +0000402}
Simon Glassca7eafe2014-10-13 23:42:01 -0600403
404static const struct dm_spi_ops exynos_spi_ops = {
405 .claim_bus = exynos_spi_claim_bus,
406 .release_bus = exynos_spi_release_bus,
407 .xfer = exynos_spi_xfer,
408 .set_speed = exynos_spi_set_speed,
409 .set_mode = exynos_spi_set_mode,
410 /*
411 * cs_info is not needed, since we require all chip selects to be
412 * in the device tree explicitly
413 */
414};
415
416static const struct udevice_id exynos_spi_ids[] = {
417 { .compatible = "samsung,exynos-spi" },
418 { }
419};
420
421U_BOOT_DRIVER(exynos_spi) = {
422 .name = "exynos_spi",
423 .id = UCLASS_SPI,
424 .of_match = exynos_spi_ids,
425 .ops = &exynos_spi_ops,
426 .ofdata_to_platdata = exynos_spi_ofdata_to_platdata,
427 .platdata_auto_alloc_size = sizeof(struct exynos_spi_platdata),
428 .priv_auto_alloc_size = sizeof(struct exynos_spi_priv),
Simon Glassca7eafe2014-10-13 23:42:01 -0600429 .probe = exynos_spi_probe,
430};