Lines Matching +full:rs +full:-

1 // SPDX-License-Identifier: GPL-2.0+
5 * Derived from the Linux driver version drivers/spi/spi-mt7621.c
7 * Copyright (C) 2011-2013 Gabor Juhos <juhosg@openwrt.org>
8 * Copyright (C) 2014-2015 Felix Fietkau <nbd@nbd.name>
48 static void mt7621_spi_reset(struct mt7621_spi *rs, int duplex) in mt7621_spi_reset() argument
50 setbits_le32(rs->base + MT7621_SPI_MASTER, in mt7621_spi_reset()
54 static void mt7621_spi_set_cs(struct mt7621_spi *rs, int cs, int enable) in mt7621_spi_set_cs() argument
58 debug("%s: cs#%d -> %s\n", __func__, cs, enable ? "enable" : "disable"); in mt7621_spi_set_cs()
61 iowrite32(val, rs->base + MT7621_SPI_POLAR); in mt7621_spi_set_cs()
66 struct mt7621_spi *rs = dev_get_priv(bus); in mt7621_spi_set_mode() local
70 reg = ioread32(rs->base + MT7621_SPI_MASTER); in mt7621_spi_set_mode()
90 iowrite32(reg, rs->base + MT7621_SPI_MASTER); in mt7621_spi_set_mode()
97 struct mt7621_spi *rs = dev_get_priv(bus); in mt7621_spi_set_speed() local
102 rate = DIV_ROUND_UP(rs->sys_freq, speed); in mt7621_spi_set_speed()
106 return -EINVAL; in mt7621_spi_set_speed()
111 reg = ioread32(rs->base + MT7621_SPI_MASTER); in mt7621_spi_set_speed()
113 reg |= (rate - 2) << MASTER_RS_CLK_SEL_SHIFT; in mt7621_spi_set_speed()
114 iowrite32(reg, rs->base + MT7621_SPI_MASTER); in mt7621_spi_set_speed()
119 static inline int mt7621_spi_wait_till_ready(struct mt7621_spi *rs) in mt7621_spi_wait_till_ready() argument
123 ret = wait_for_bit_le32(rs->base + MT7621_SPI_TRANS, in mt7621_spi_wait_till_ready()
134 struct udevice *bus = dev->parent; in mt7621_spi_xfer()
135 struct mt7621_spi *rs = dev_get_priv(bus); in mt7621_spi_xfer() local
150 * This driver only supports half-duplex, so complain and bail out in mt7621_spi_xfer()
151 * upon full-duplex messages in mt7621_spi_xfer()
154 printf("Only half-duplex SPI transfer supported\n"); in mt7621_spi_xfer()
155 return -EIO; in mt7621_spi_xfer()
159 debug("TX-DATA: "); in mt7621_spi_xfer()
165 mt7621_spi_wait_till_ready(rs); in mt7621_spi_xfer()
172 mt7621_spi_set_cs(rs, spi_chip_select(dev), 1); in mt7621_spi_xfer()
183 if (rs->tx_len > 4) in mt7621_spi_xfer()
184 chunk_size -= rs->tx_len; in mt7621_spi_xfer()
190 if ((chunk_size + rs->tx_len) > SPI_MSG_SIZE_OVERALL) { in mt7621_spi_xfer()
192 chunk_size + rs->tx_len); in mt7621_spi_xfer()
193 return -EMSGSIZE; in mt7621_spi_xfer()
201 for (i = 0; i < chunk_size; i++, rs->tx_len++) { in mt7621_spi_xfer()
202 rs->data[rs->tx_len / 4] |= in mt7621_spi_xfer()
203 tx_buf[i] << (8 * (rs->tx_len & 3)); in mt7621_spi_xfer()
209 if (rs->tx_len) { in mt7621_spi_xfer()
210 rs->data[0] = swab32(rs->data[0]); in mt7621_spi_xfer()
211 if (rs->tx_len < 4) in mt7621_spi_xfer()
212 rs->data[0] >>= (4 - rs->tx_len) * 8; in mt7621_spi_xfer()
214 for (i = 0; i < rs->tx_len; i += 4) { in mt7621_spi_xfer()
215 iowrite32(rs->data[i / 4], rs->base + in mt7621_spi_xfer()
221 val = (min_t(int, rs->tx_len, 4) * 8) << 24; in mt7621_spi_xfer()
222 if (rs->tx_len > 4) in mt7621_spi_xfer()
223 val |= (rs->tx_len - 4) * 8; in mt7621_spi_xfer()
225 iowrite32(val, rs->base + MT7621_SPI_MOREBUF); in mt7621_spi_xfer()
228 setbits_le32(rs->base + MT7621_SPI_TRANS, in mt7621_spi_xfer()
232 mt7621_spi_wait_till_ready(rs); in mt7621_spi_xfer()
235 rs->tx_len = 0; in mt7621_spi_xfer()
236 memset(rs->data, 0, sizeof(rs->data)); in mt7621_spi_xfer()
240 data[i / 4] = ioread32(rs->base + MT7621_SPI_DATA0 + i); in mt7621_spi_xfer()
243 debug("RX-DATA: "); in mt7621_spi_xfer()
255 total_size -= chunk_size; in mt7621_spi_xfer()
258 /* Wait until xfer is finished on bus and de-assert CS */ in mt7621_spi_xfer()
259 mt7621_spi_wait_till_ready(rs); in mt7621_spi_xfer()
261 mt7621_spi_set_cs(rs, spi_chip_select(dev), 0); in mt7621_spi_xfer()
268 struct mt7621_spi *rs = dev_get_priv(dev); in mt7621_spi_probe() local
270 rs->base = dev_remap_addr(dev); in mt7621_spi_probe()
271 if (!rs->base) in mt7621_spi_probe()
272 return -EINVAL; in mt7621_spi_probe()
279 rs->sys_freq = dev_read_u32_default(dev, "clock-frequency", 0); in mt7621_spi_probe()
280 if (!rs->sys_freq) { in mt7621_spi_probe()
281 printf("Please provide clock-frequency!\n"); in mt7621_spi_probe()
282 return -EINVAL; in mt7621_spi_probe()
285 mt7621_spi_reset(rs, 0); in mt7621_spi_probe()
301 { .compatible = "ralink,mt7621-spi" },