Lines Matching +full:spi +full:- +full:cpol
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * SPI master driver for ICP DAS LP-8841 RTC
11 * Copyright (C) 2003 - 2007 Paul Mundt
19 #include <linux/spi/spi.h>
30 * REVISIT If there is support for SPI_3WIRE and SPI_LSB_FIRST in SPI
31 * GPIO driver, this SPI driver can be replaced by a simple GPIO driver
44 data->state |= SPI_LP8841_RTC_CLK; in setsck()
46 data->state &= ~SPI_LP8841_RTC_CLK; in setsck()
47 writeb(data->state, data->iomem); in setsck()
54 data->state |= SPI_LP8841_RTC_MOSI; in setmosi()
56 data->state &= ~SPI_LP8841_RTC_MOSI; in setmosi()
57 writeb(data->state, data->iomem); in setmosi()
63 return ioread8(data->iomem) & SPI_LP8841_RTC_MISO; in getmiso()
68 unsigned usecs, unsigned cpol, unsigned flags, in bitbang_txrx_be_cpha0_lsb() argument
71 /* if (cpol == 0) this is SPI_MODE_0; else this is SPI_MODE_2 */ in bitbang_txrx_be_cpha0_lsb()
73 u32 shift = 32 - bits; in bitbang_txrx_be_cpha0_lsb()
75 for (; likely(bits); bits--) { in bitbang_txrx_be_cpha0_lsb()
88 setsck(data, !cpol); in bitbang_txrx_be_cpha0_lsb()
91 setsck(data, cpol); in bitbang_txrx_be_cpha0_lsb()
100 struct spi_device *spi, in spi_lp8841_rtc_transfer_one() argument
104 unsigned count = t->len; in spi_lp8841_rtc_transfer_one()
105 const u8 *tx = t->tx_buf; in spi_lp8841_rtc_transfer_one()
106 u8 *rx = t->rx_buf; in spi_lp8841_rtc_transfer_one()
111 data->state &= ~SPI_LP8841_RTC_nWE; in spi_lp8841_rtc_transfer_one()
112 writeb(data->state, data->iomem); in spi_lp8841_rtc_transfer_one()
117 count--; in spi_lp8841_rtc_transfer_one()
120 data->state |= SPI_LP8841_RTC_nWE; in spi_lp8841_rtc_transfer_one()
121 writeb(data->state, data->iomem); in spi_lp8841_rtc_transfer_one()
126 count--; in spi_lp8841_rtc_transfer_one()
129 ret = -EINVAL; in spi_lp8841_rtc_transfer_one()
138 spi_lp8841_rtc_set_cs(struct spi_device *spi, bool enable) in spi_lp8841_rtc_set_cs() argument
140 struct spi_lp8841_rtc *data = spi_master_get_devdata(spi->master); in spi_lp8841_rtc_set_cs()
142 data->state = 0; in spi_lp8841_rtc_set_cs()
143 writeb(data->state, data->iomem); in spi_lp8841_rtc_set_cs()
146 data->state |= SPI_LP8841_RTC_CE; in spi_lp8841_rtc_set_cs()
147 writeb(data->state, data->iomem); in spi_lp8841_rtc_set_cs()
153 spi_lp8841_rtc_setup(struct spi_device *spi) in spi_lp8841_rtc_setup() argument
155 if ((spi->mode & SPI_CS_HIGH) == 0) { in spi_lp8841_rtc_setup()
156 dev_err(&spi->dev, "unsupported active low chip select\n"); in spi_lp8841_rtc_setup()
157 return -EINVAL; in spi_lp8841_rtc_setup()
160 if ((spi->mode & SPI_LSB_FIRST) == 0) { in spi_lp8841_rtc_setup()
161 dev_err(&spi->dev, "unsupported MSB first mode\n"); in spi_lp8841_rtc_setup()
162 return -EINVAL; in spi_lp8841_rtc_setup()
165 if ((spi->mode & SPI_3WIRE) == 0) { in spi_lp8841_rtc_setup()
166 dev_err(&spi->dev, "unsupported wiring. 3 wires required\n"); in spi_lp8841_rtc_setup()
167 return -EINVAL; in spi_lp8841_rtc_setup()
175 { .compatible = "icpdas,lp8841-spi-rtc" },
189 master = spi_alloc_master(&pdev->dev, sizeof(*data)); in spi_lp8841_rtc_probe()
191 return -ENOMEM; in spi_lp8841_rtc_probe()
194 master->flags = SPI_MASTER_HALF_DUPLEX; in spi_lp8841_rtc_probe()
195 master->mode_bits = SPI_CS_HIGH | SPI_3WIRE | SPI_LSB_FIRST; in spi_lp8841_rtc_probe()
197 master->bus_num = pdev->id; in spi_lp8841_rtc_probe()
198 master->num_chipselect = 1; in spi_lp8841_rtc_probe()
199 master->setup = spi_lp8841_rtc_setup; in spi_lp8841_rtc_probe()
200 master->set_cs = spi_lp8841_rtc_set_cs; in spi_lp8841_rtc_probe()
201 master->transfer_one = spi_lp8841_rtc_transfer_one; in spi_lp8841_rtc_probe()
202 master->bits_per_word_mask = SPI_BPW_MASK(8); in spi_lp8841_rtc_probe()
204 master->dev.of_node = pdev->dev.of_node; in spi_lp8841_rtc_probe()
209 data->iomem = devm_platform_ioremap_resource(pdev, 0); in spi_lp8841_rtc_probe()
210 ret = PTR_ERR_OR_ZERO(data->iomem); in spi_lp8841_rtc_probe()
212 dev_err(&pdev->dev, "failed to get IO address\n"); in spi_lp8841_rtc_probe()
216 /* register with the SPI framework */ in spi_lp8841_rtc_probe()
217 ret = devm_spi_register_master(&pdev->dev, master); in spi_lp8841_rtc_probe()
219 dev_err(&pdev->dev, "cannot register spi master\n"); in spi_lp8841_rtc_probe()
243 MODULE_DESCRIPTION("SPI master driver for ICP DAS LP-8841 RTC");