Lines Matching +full:sun4i +full:- +full:a10 +full:- +full:spi
9 * Based on linux spi driver. Original copyright follows:
10 * linux/drivers/spi/spi-sun4i.c
12 * Copyright (C) 2012 - 2014 Allwinner Tech
16 * Maxime Ripard <maxime.ripard@free-electrons.com>
18 * SPDX-License-Identifier: GPL-2.0+
24 #include <spi.h>
38 /* sun4i spi registers */
47 /* sun6i spi registers */
59 /* sun spi bits */
77 #define SPI_REG(priv, reg) ((priv)->base + \
78 (priv)->variant->regs[reg])
79 #define SPI_BIT(priv, bit) ((priv)->variant->bits[bit])
83 /* sun spi register set */
97 /* sun spi register bits */
144 while (len--) { in sun4i_spi_drain_fifo()
146 if (priv->rx_buf) in sun4i_spi_drain_fifo()
147 *priv->rx_buf++ = byte; in sun4i_spi_drain_fifo()
155 while (len--) { in sun4i_spi_fill_fifo()
156 byte = priv->tx_buf ? *priv->tx_buf++ : 0; in sun4i_spi_fill_fifo()
181 const void *fdt = gd->fdt_blob; in sun4i_spi_parse_pins()
189 list = fdt_getprop(fdt, dev_of_offset(dev), "pinctrl-0", &size); in sun4i_spi_parse_pins()
191 printf("WARNING: sun4i_spi: cannot find pinctrl-0 node\n"); in sun4i_spi_parse_pins()
192 return -EINVAL; in sun4i_spi_parse_pins()
197 size -= sizeof(*list); in sun4i_spi_parse_pins()
204 "drive-strength", 0); in sun4i_spi_parse_pins()
221 if (fdt_get_property(fdt, offset, "bias-disable", NULL)) in sun4i_spi_parse_pins()
223 else if (fdt_get_property(fdt, offset, "bias-pull-up", NULL)) in sun4i_spi_parse_pins()
225 else if (fdt_get_property(fdt, offset, "bias-pull-down", NULL)) in sun4i_spi_parse_pins()
265 clk_disable(&priv->clk_ahb); in sun4i_spi_set_clock()
266 clk_disable(&priv->clk_mod); in sun4i_spi_set_clock()
267 if (reset_valid(&priv->reset)) in sun4i_spi_set_clock()
268 reset_assert(&priv->reset); in sun4i_spi_set_clock()
272 ret = clk_enable(&priv->clk_ahb); in sun4i_spi_set_clock()
278 ret = clk_enable(&priv->clk_mod); in sun4i_spi_set_clock()
284 if (reset_valid(&priv->reset)) { in sun4i_spi_set_clock()
285 ret = reset_deassert(&priv->reset); in sun4i_spi_set_clock()
295 clk_disable(&priv->clk_mod); in sun4i_spi_set_clock()
297 clk_disable(&priv->clk_ahb); in sun4i_spi_set_clock()
303 struct sun4i_spi_priv *priv = dev_get_priv(dev->parent); in sun4i_spi_claim_bus()
306 ret = sun4i_spi_set_clock(dev->parent, true); in sun4i_spi_claim_bus()
313 if (priv->variant->has_soft_reset) in sun4i_spi_claim_bus()
325 struct sun4i_spi_priv *priv = dev_get_priv(dev->parent); in sun4i_spi_release_bus()
329 sun4i_spi_set_clock(dev->parent, false); in sun4i_spi_release_bus()
337 struct udevice *bus = dev->parent; in sun4i_spi_xfer()
346 priv->tx_buf = dout; in sun4i_spi_xfer()
347 priv->rx_buf = din; in sun4i_spi_xfer()
350 debug("%s: non byte-aligned SPI transfer.\n", __func__); in sun4i_spi_xfer()
351 return -ENAVAIL; in sun4i_spi_xfer()
355 sun4i_spi_set_cs(bus, slave_plat->cs, true); in sun4i_spi_xfer()
363 nbytes = min(len, (priv->variant->fifo_depth - 1)); in sun4i_spi_xfer()
369 if (priv->variant->has_burst_ctl) in sun4i_spi_xfer()
389 sun4i_spi_set_cs(bus, slave_plat->cs, false); in sun4i_spi_xfer()
396 len -= nbytes; in sun4i_spi_xfer()
400 sun4i_spi_set_cs(bus, slave_plat->cs, false); in sun4i_spi_xfer()
412 if (speed > plat->max_hz) in sun4i_spi_set_speed()
413 speed = plat->max_hz; in sun4i_spi_set_speed()
437 div--; in sun4i_spi_set_speed()
442 div = __ilog2(SUN4I_SPI_MAX_RATE) - __ilog2(speed); in sun4i_spi_set_speed()
447 priv->freq = speed; in sun4i_spi_set_speed()
467 priv->mode = mode; in sun4i_spi_set_mode()
487 ret = clk_get_by_name(bus, "ahb", &priv->clk_ahb); in sun4i_spi_probe()
493 ret = clk_get_by_name(bus, "mod", &priv->clk_mod); in sun4i_spi_probe()
499 ret = reset_get_by_index(bus, 0, &priv->reset); in sun4i_spi_probe()
500 if (ret && ret != -ENOENT) { in sun4i_spi_probe()
507 priv->variant = plat->variant; in sun4i_spi_probe()
508 priv->base = plat->base; in sun4i_spi_probe()
509 priv->freq = plat->max_hz; in sun4i_spi_probe()
519 plat->base = devfdt_get_addr(bus); in sun4i_spi_ofdata_to_platdata()
520 plat->variant = (struct sun4i_spi_variant *)dev_get_driver_data(bus); in sun4i_spi_ofdata_to_platdata()
521 plat->max_hz = fdtdec_get_int(gd->fdt_blob, node, in sun4i_spi_ofdata_to_platdata()
522 "spi-max-frequency", in sun4i_spi_ofdata_to_platdata()
525 if (plat->max_hz > SUN4I_SPI_MAX_RATE) in sun4i_spi_ofdata_to_platdata()
526 plat->max_hz = SUN4I_SPI_MAX_RATE; in sun4i_spi_ofdata_to_platdata()
611 .compatible = "allwinner,sun4i-a10-spi",
615 .compatible = "allwinner,sun6i-a31-spi",
619 .compatible = "allwinner,sun8i-h3-spi",