Lines Matching +full:spi +full:- +full:sck +full:- +full:cs +full:- +full:delay

11  * Copyright (C) 2005 David Brownell (ported to 2.6 SPI interface)
34 #include <linux/delay.h>
42 #include <linux/spi/spi.h>
43 #include <linux/spi/spi_bitbang.h>
47 #include <asm/mach-types.h>
48 #include <linux/soc/ti/omap1-io.h>
49 #include <linux/soc/ti/omap1-soc.h>
50 #include <linux/soc/ti/omap1-mux.h>
115 static inline void omap_uwire_configure_mode(u8 cs, unsigned long flags) in omap_uwire_configure_mode() argument
123 if (cs & 1) in omap_uwire_configure_mode()
127 if (cs <= 1) in omap_uwire_configure_mode()
152 return -1; in wait_uwire_csr_flag()
171 static void uwire_chipselect(struct spi_device *spi, int value) in uwire_chipselect() argument
173 struct uwire_state *ust = spi->controller_state; in uwire_chipselect()
182 if (value == BITBANG_CS_INACTIVE || old_cs != spi_get_chipselect(spi, 0)) { in uwire_chipselect()
183 /* Deselect this CS, or the previous CS */ in uwire_chipselect()
189 uwire_set_clk1_div(ust->div1_idx); in uwire_chipselect()
191 if (spi->mode & SPI_CPOL) in uwire_chipselect()
196 w = spi_get_chipselect(spi, 0) << 10; in uwire_chipselect()
202 static int uwire_txrx(struct spi_device *spi, struct spi_transfer *t) in uwire_txrx() argument
204 unsigned len = t->len; in uwire_txrx()
205 unsigned bits = t->bits_per_word; in uwire_txrx()
210 if (!t->tx_buf && !t->rx_buf) in uwire_txrx()
213 w = spi_get_chipselect(spi, 0) << 10; in uwire_txrx()
216 if (t->tx_buf) { in uwire_txrx()
217 const u8 *buf = t->tx_buf; in uwire_txrx()
224 * (msb-first) on the way out from memory. in uwire_txrx()
232 val <<= 16 - bits; in uwire_txrx()
235 pr_debug("%s: write-%d =%04x\n", in uwire_txrx()
236 dev_name(&spi->dev), bits, val); in uwire_txrx()
247 len -= bytes; in uwire_txrx()
263 } else if (t->rx_buf) { in uwire_txrx()
264 u8 *buf = t->rx_buf; in uwire_txrx()
276 len -= bytes; in uwire_txrx()
289 val &= (1 << bits) - 1; in uwire_txrx()
295 pr_debug("%s: read-%d =%04x\n", in uwire_txrx()
296 dev_name(&spi->dev), bits, val); in uwire_txrx()
303 return -EIO; in uwire_txrx()
306 static int uwire_setup_transfer(struct spi_device *spi, struct spi_transfer *t) in uwire_setup_transfer() argument
308 struct uwire_state *ust = spi->controller_state; in uwire_setup_transfer()
318 uwire = spi_controller_get_devdata(spi->controller); in uwire_setup_transfer()
324 if (spi->mode & SPI_CS_HIGH) in uwire_setup_transfer()
327 if (spi->mode & SPI_CPOL) in uwire_setup_transfer()
330 switch (spi->mode & SPI_MODE_X_MASK) { in uwire_setup_transfer()
342 rate = clk_get_rate(uwire->ck); in uwire_setup_transfer()
345 hz = t->speed_hz; in uwire_setup_transfer()
347 hz = spi->max_speed_hz; in uwire_setup_transfer()
350 pr_debug("%s: zero speed?\n", dev_name(&spi->dev)); in uwire_setup_transfer()
351 status = -EINVAL; in uwire_setup_transfer()
372 div2 = (rate / div1 + hz - 1) / hz; in uwire_setup_transfer()
378 dev_name(&spi->dev), rate / 10 / 8, hz); in uwire_setup_transfer()
379 status = -EDOM; in uwire_setup_transfer()
386 ust->div1_idx = div1_idx; in uwire_setup_transfer()
411 omap_uwire_configure_mode(spi_get_chipselect(spi, 0), flags); in uwire_setup_transfer()
412 pr_debug("%s: uwire flags %02x, armxor %lu KHz, SCK %lu KHz\n", in uwire_setup_transfer()
414 clk_get_rate(uwire->ck) / 1000, in uwire_setup_transfer()
421 static int uwire_setup(struct spi_device *spi) in uwire_setup() argument
423 struct uwire_state *ust = spi->controller_state; in uwire_setup()
430 return -ENOMEM; in uwire_setup()
431 spi->controller_state = ust; in uwire_setup()
435 status = uwire_setup_transfer(spi, NULL); in uwire_setup()
442 static void uwire_cleanup(struct spi_device *spi) in uwire_cleanup() argument
444 kfree(spi->controller_state); in uwire_cleanup()
450 clk_disable_unprepare(uwire->ck); in uwire_off()
451 spi_controller_put(uwire->bitbang.ctlr); in uwire_off()
460 host = spi_alloc_host(&pdev->dev, sizeof(*uwire)); in uwire_probe()
462 return -ENODEV; in uwire_probe()
466 uwire_base = devm_ioremap(&pdev->dev, UWIRE_BASE_PHYS, UWIRE_IO_SIZE); in uwire_probe()
468 dev_dbg(&pdev->dev, "can't ioremap UWIRE\n"); in uwire_probe()
470 return -ENOMEM; in uwire_probe()
475 uwire->ck = devm_clk_get(&pdev->dev, "fck"); in uwire_probe()
476 if (IS_ERR(uwire->ck)) { in uwire_probe()
477 status = PTR_ERR(uwire->ck); in uwire_probe()
478 dev_dbg(&pdev->dev, "no functional clock?\n"); in uwire_probe()
482 clk_prepare_enable(uwire->ck); in uwire_probe()
486 /* the spi->mode bits understood by this driver: */ in uwire_probe()
487 host->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; in uwire_probe()
488 host->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 16); in uwire_probe()
489 host->flags = SPI_CONTROLLER_HALF_DUPLEX; in uwire_probe()
491 host->bus_num = 2; /* "official" */ in uwire_probe()
492 host->num_chipselect = 4; in uwire_probe()
493 host->setup = uwire_setup; in uwire_probe()
494 host->cleanup = uwire_cleanup; in uwire_probe()
496 uwire->bitbang.ctlr = host; in uwire_probe()
497 uwire->bitbang.chipselect = uwire_chipselect; in uwire_probe()
498 uwire->bitbang.setup_transfer = uwire_setup_transfer; in uwire_probe()
499 uwire->bitbang.txrx_bufs = uwire_txrx; in uwire_probe()
501 status = spi_bitbang_start(&uwire->bitbang); in uwire_probe()
514 spi_bitbang_stop(&uwire->bitbang); in uwire_remove()