• Home
  • Raw
  • Download

Lines Matching +full:min +full:- +full:output +full:- +full:impedance

1 // SPDX-License-Identifier: GPL-2.0
7 * Copyright (C) 2014-2017 Glider bvba
14 #include <linux/dma-mapping.h>
87 #define SIMDR1_SYNCAC_SHIFT 25 /* Sync Polarity (1 = Active-low) */
91 #define SIMDR1_FLD_MASK GENMASK(3, 2) /* Frame Sync Signal Interval (0-3) */
100 #define SIMDR2_BITLEN1(i) (((i) - 1) << 24) /* Data Size (8-32 bits) */
101 #define SIMDR2_WDLEN1(i) (((i) - 1) << 16) /* Word Count (1-64/256 (SH, A1))) */
102 #define SIMDR2_GRPMASK1 BIT(0) /* Group Output Mask 1 (SH, A1) */
105 #define SISCR_BRPS_MASK GENMASK(12, 8) /* Prescaler Setting (1-32) */
106 #define SISCR_BRPS(i) (((i) - 1) << 8)
124 #define SICTR_TXDIZ_MASK GENMASK(23, 22) /* Pin Output When TX is Disabled */
127 #define SICTR_TXDIZ_HIZ (2 << 22) /* High-impedance */
128 #define SICTR_TSCKE BIT(15) /* Transmit Serial Clock Output Enable */
129 #define SICTR_TFSE BIT(14) /* Transmit Frame Sync Signal Output Enable */
197 return ioread16(p->mapbase + reg_offs); in sh_msiof_read()
199 return ioread32(p->mapbase + reg_offs); in sh_msiof_read()
209 iowrite16(value, p->mapbase + reg_offs); in sh_msiof_write()
212 iowrite32(value, p->mapbase + reg_offs); in sh_msiof_write()
228 return readl_poll_timeout_atomic(p->mapbase + SICTR, data, in sh_msiof_modify_ctr_wait()
238 complete(&p->done); in sh_msiof_spi_irq()
252 readl_poll_timeout_atomic(p->mapbase + SICTR, data, !(data & mask), 1, in sh_msiof_spi_reset_regs()
266 unsigned int div_pow = p->min_div_pow; in sh_msiof_spi_set_clk_regs()
289 dev_err(&p->pdev->dev, in sh_msiof_spi_set_clk_regs()
297 if (!(p->ctlr->flags & SPI_CONTROLLER_MUST_TX)) in sh_msiof_spi_set_clk_regs()
304 * DTDL/SYNCDL bit : p->info->dtdl or p->info->syncdl in sh_msiof_get_delay_bit()
322 if (!p->info) in sh_msiof_spi_get_dtdl_and_syncdl()
326 if (p->info->dtdl > 200 || p->info->syncdl > 300) { in sh_msiof_spi_get_dtdl_and_syncdl()
327 dev_warn(&p->pdev->dev, "DTDL or SYNCDL is too large\n"); in sh_msiof_spi_get_dtdl_and_syncdl()
332 if ((p->info->dtdl + p->info->syncdl) % 100) { in sh_msiof_spi_get_dtdl_and_syncdl()
333 dev_warn(&p->pdev->dev, "the sum of DTDL/SYNCDL is not good\n"); in sh_msiof_spi_get_dtdl_and_syncdl()
337 val = sh_msiof_get_delay_bit(p->info->dtdl) << SIMDR1_DTDL_SHIFT; in sh_msiof_spi_get_dtdl_and_syncdl()
338 val |= sh_msiof_get_delay_bit(p->info->syncdl) << SIMDR1_SYNCDL_SHIFT; in sh_msiof_spi_get_dtdl_and_syncdl()
361 if (spi_controller_is_slave(p->ctlr)) { in sh_msiof_spi_set_pin_regs()
368 if (p->ctlr->flags & SPI_CONTROLLER_MUST_TX) { in sh_msiof_spi_set_pin_regs()
392 if (tx_buf || (p->ctlr->flags & SPI_CONTROLLER_MUST_TX)) in sh_msiof_spi_set_mode_regs()
550 spi_controller_get_devdata(spi->controller); in sh_msiof_spi_setup()
553 if (spi->cs_gpiod || spi_controller_is_slave(p->ctlr)) in sh_msiof_spi_setup()
556 if (p->native_cs_inited && in sh_msiof_spi_setup()
557 (p->native_cs_high == !!(spi->mode & SPI_CS_HIGH))) in sh_msiof_spi_setup()
563 if (spi->mode & SPI_CS_HIGH) in sh_msiof_spi_setup()
567 pm_runtime_get_sync(&p->pdev->dev); in sh_msiof_spi_setup()
572 pm_runtime_put(&p->pdev->dev); in sh_msiof_spi_setup()
573 p->native_cs_high = spi->mode & SPI_CS_HIGH; in sh_msiof_spi_setup()
574 p->native_cs_inited = true; in sh_msiof_spi_setup()
582 const struct spi_device *spi = msg->spi; in sh_msiof_prepare_message()
586 if (spi->cs_gpiod) { in sh_msiof_prepare_message()
587 ss = ctlr->unused_native_cs; in sh_msiof_prepare_message()
588 cs_high = p->native_cs_high; in sh_msiof_prepare_message()
590 ss = spi->chip_select; in sh_msiof_prepare_message()
591 cs_high = !!(spi->mode & SPI_CS_HIGH); in sh_msiof_prepare_message()
593 sh_msiof_spi_set_pin_regs(p, ss, !!(spi->mode & SPI_CPOL), in sh_msiof_prepare_message()
594 !!(spi->mode & SPI_CPHA), in sh_msiof_prepare_message()
595 !!(spi->mode & SPI_3WIRE), in sh_msiof_prepare_message()
596 !!(spi->mode & SPI_LSB_FIRST), cs_high); in sh_msiof_prepare_message()
602 bool slave = spi_controller_is_slave(p->ctlr); in sh_msiof_spi_start()
622 bool slave = spi_controller_is_slave(p->ctlr); in sh_msiof_spi_stop()
642 p->slave_aborted = true; in sh_msiof_slave_abort()
643 complete(&p->done); in sh_msiof_slave_abort()
644 complete(&p->done_txdma); in sh_msiof_slave_abort()
651 if (spi_controller_is_slave(p->ctlr)) { in sh_msiof_wait_for_completion()
653 p->slave_aborted) { in sh_msiof_wait_for_completion()
654 dev_dbg(&p->pdev->dev, "interrupted\n"); in sh_msiof_wait_for_completion()
655 return -EINTR; in sh_msiof_wait_for_completion()
659 dev_err(&p->pdev->dev, "timeout\n"); in sh_msiof_wait_for_completion()
660 return -ETIMEDOUT; in sh_msiof_wait_for_completion()
680 words = min_t(int, words, p->tx_fifo_size); in sh_msiof_spi_txrx_once()
682 words = min_t(int, words, p->rx_fifo_size); in sh_msiof_spi_txrx_once()
685 fifo_shift = 32 - bits; in sh_msiof_spi_txrx_once()
698 reinit_completion(&p->done); in sh_msiof_spi_txrx_once()
699 p->slave_aborted = false; in sh_msiof_spi_txrx_once()
703 dev_err(&p->pdev->dev, "failed to start hardware\n"); in sh_msiof_spi_txrx_once()
708 ret = sh_msiof_wait_for_completion(p, &p->done); in sh_msiof_spi_txrx_once()
721 dev_err(&p->pdev->dev, "failed to shut down hardware\n"); in sh_msiof_spi_txrx_once()
751 desc_rx = dmaengine_prep_slave_single(p->ctlr->dma_rx, in sh_msiof_dma_once()
752 p->rx_dma_addr, len, DMA_DEV_TO_MEM, in sh_msiof_dma_once()
755 return -EAGAIN; in sh_msiof_dma_once()
757 desc_rx->callback = sh_msiof_dma_complete; in sh_msiof_dma_once()
758 desc_rx->callback_param = &p->done; in sh_msiof_dma_once()
766 dma_sync_single_for_device(p->ctlr->dma_tx->device->dev, in sh_msiof_dma_once()
767 p->tx_dma_addr, len, DMA_TO_DEVICE); in sh_msiof_dma_once()
768 desc_tx = dmaengine_prep_slave_single(p->ctlr->dma_tx, in sh_msiof_dma_once()
769 p->tx_dma_addr, len, DMA_MEM_TO_DEV, in sh_msiof_dma_once()
772 ret = -EAGAIN; in sh_msiof_dma_once()
776 desc_tx->callback = sh_msiof_dma_complete; in sh_msiof_dma_once()
777 desc_tx->callback_param = &p->done_txdma; in sh_msiof_dma_once()
788 /* setup msiof transfer mode registers (32-bit words) */ in sh_msiof_dma_once()
793 reinit_completion(&p->done); in sh_msiof_dma_once()
795 reinit_completion(&p->done_txdma); in sh_msiof_dma_once()
796 p->slave_aborted = false; in sh_msiof_dma_once()
800 dma_async_issue_pending(p->ctlr->dma_rx); in sh_msiof_dma_once()
802 dma_async_issue_pending(p->ctlr->dma_tx); in sh_msiof_dma_once()
806 dev_err(&p->pdev->dev, "failed to start hardware\n"); in sh_msiof_dma_once()
812 ret = sh_msiof_wait_for_completion(p, &p->done_txdma); in sh_msiof_dma_once()
819 ret = sh_msiof_wait_for_completion(p, &p->done); in sh_msiof_dma_once()
827 ret = sh_msiof_wait_for_completion(p, &p->done); in sh_msiof_dma_once()
837 dev_err(&p->pdev->dev, "failed to shut down hardware\n"); in sh_msiof_dma_once()
842 dma_sync_single_for_cpu(p->ctlr->dma_rx->device->dev, in sh_msiof_dma_once()
843 p->rx_dma_addr, len, DMA_FROM_DEVICE); in sh_msiof_dma_once()
852 dmaengine_terminate_all(p->ctlr->dma_tx); in sh_msiof_dma_once()
855 dmaengine_terminate_all(p->ctlr->dma_rx); in sh_msiof_dma_once()
864 while (words--) { in copy_bswap32()
869 while (words--) { in copy_bswap32()
874 while (words--) in copy_bswap32()
883 while (words--) { in copy_wswap32()
888 while (words--) { in copy_wswap32()
893 while (words--) in copy_wswap32()
911 const void *tx_buf = t->tx_buf; in sh_msiof_transfer_one()
912 void *rx_buf = t->rx_buf; in sh_msiof_transfer_one()
913 unsigned int len = t->len; in sh_msiof_transfer_one()
914 unsigned int bits = t->bits_per_word; in sh_msiof_transfer_one()
925 if (!spi_controller_is_slave(p->ctlr)) in sh_msiof_transfer_one()
926 sh_msiof_spi_set_clk_regs(p, clk_get_rate(p->clk), t->speed_hz); in sh_msiof_transfer_one()
928 while (ctlr->dma_tx && len > 15) { in sh_msiof_transfer_one()
930 * DMA supports 32-bit words only, hence pack 8-bit and 16-bit in sh_msiof_transfer_one()
936 l = min(round_down(len, 4), p->tx_fifo_size * 4); in sh_msiof_transfer_one()
938 l = min(round_down(len, 4), p->rx_fifo_size * 4); in sh_msiof_transfer_one()
949 copy32(p->tx_dma_page, tx_buf, l / 4); in sh_msiof_transfer_one()
952 if (ret == -EAGAIN) { in sh_msiof_transfer_one()
953 dev_warn_once(&p->pdev->dev, in sh_msiof_transfer_one()
961 copy32(rx_buf, p->rx_dma_page, l / 4); in sh_msiof_transfer_one()
967 len -= l; in sh_msiof_transfer_one()
1032 words -= n; in sh_msiof_transfer_one()
1036 bits = t->bits_per_word; in sh_msiof_transfer_one()
1073 { .compatible = "renesas,sh-mobile-msiof", .data = &sh_data },
1074 { .compatible = "renesas,msiof-r8a7743", .data = &rcar_gen2_data },
1075 { .compatible = "renesas,msiof-r8a7745", .data = &rcar_gen2_data },
1076 { .compatible = "renesas,msiof-r8a7790", .data = &rcar_gen2_data },
1077 { .compatible = "renesas,msiof-r8a7791", .data = &rcar_gen2_data },
1078 { .compatible = "renesas,msiof-r8a7792", .data = &rcar_gen2_data },
1079 { .compatible = "renesas,msiof-r8a7793", .data = &rcar_gen2_data },
1080 { .compatible = "renesas,msiof-r8a7794", .data = &rcar_gen2_data },
1081 { .compatible = "renesas,rcar-gen2-msiof", .data = &rcar_gen2_data },
1082 { .compatible = "renesas,msiof-r8a7796", .data = &rcar_gen3_data },
1083 { .compatible = "renesas,rcar-gen3-msiof", .data = &rcar_gen3_data },
1084 { .compatible = "renesas,sh-msiof", .data = &sh_data }, /* Deprecated */
1093 struct device_node *np = dev->of_node; in sh_msiof_spi_parse_dt()
1100 info->mode = of_property_read_bool(np, "spi-slave") ? MSIOF_SPI_SLAVE in sh_msiof_spi_parse_dt()
1104 if (info->mode == MSIOF_SPI_MASTER) in sh_msiof_spi_parse_dt()
1105 of_property_read_u32(np, "num-cs", &num_cs); in sh_msiof_spi_parse_dt()
1106 of_property_read_u32(np, "renesas,tx-fifo-size", in sh_msiof_spi_parse_dt()
1107 &info->tx_fifo_override); in sh_msiof_spi_parse_dt()
1108 of_property_read_u32(np, "renesas,rx-fifo-size", in sh_msiof_spi_parse_dt()
1109 &info->rx_fifo_override); in sh_msiof_spi_parse_dt()
1110 of_property_read_u32(np, "renesas,dtdl", &info->dtdl); in sh_msiof_spi_parse_dt()
1111 of_property_read_u32(np, "renesas,syncdl", &info->syncdl); in sh_msiof_spi_parse_dt()
1113 info->num_chipselect = num_cs; in sh_msiof_spi_parse_dt()
1165 struct platform_device *pdev = p->pdev; in sh_msiof_request_dma()
1166 struct device *dev = &pdev->dev; in sh_msiof_request_dma()
1167 const struct sh_msiof_spi_info *info = p->info; in sh_msiof_request_dma()
1173 if (dev->of_node) { in sh_msiof_request_dma()
1177 } else if (info && info->dma_tx_id && info->dma_rx_id) { in sh_msiof_request_dma()
1178 dma_tx_id = info->dma_tx_id; in sh_msiof_request_dma()
1179 dma_rx_id = info->dma_rx_id; in sh_msiof_request_dma()
1190 ctlr = p->ctlr; in sh_msiof_request_dma()
1191 ctlr->dma_tx = sh_msiof_request_dma_chan(dev, DMA_MEM_TO_DEV, in sh_msiof_request_dma()
1192 dma_tx_id, res->start + SITFDR); in sh_msiof_request_dma()
1193 if (!ctlr->dma_tx) in sh_msiof_request_dma()
1194 return -ENODEV; in sh_msiof_request_dma()
1196 ctlr->dma_rx = sh_msiof_request_dma_chan(dev, DMA_DEV_TO_MEM, in sh_msiof_request_dma()
1197 dma_rx_id, res->start + SIRFDR); in sh_msiof_request_dma()
1198 if (!ctlr->dma_rx) in sh_msiof_request_dma()
1201 p->tx_dma_page = (void *)__get_free_page(GFP_KERNEL | GFP_DMA); in sh_msiof_request_dma()
1202 if (!p->tx_dma_page) in sh_msiof_request_dma()
1205 p->rx_dma_page = (void *)__get_free_page(GFP_KERNEL | GFP_DMA); in sh_msiof_request_dma()
1206 if (!p->rx_dma_page) in sh_msiof_request_dma()
1209 tx_dev = ctlr->dma_tx->device->dev; in sh_msiof_request_dma()
1210 p->tx_dma_addr = dma_map_single(tx_dev, p->tx_dma_page, PAGE_SIZE, in sh_msiof_request_dma()
1212 if (dma_mapping_error(tx_dev, p->tx_dma_addr)) in sh_msiof_request_dma()
1215 rx_dev = ctlr->dma_rx->device->dev; in sh_msiof_request_dma()
1216 p->rx_dma_addr = dma_map_single(rx_dev, p->rx_dma_page, PAGE_SIZE, in sh_msiof_request_dma()
1218 if (dma_mapping_error(rx_dev, p->rx_dma_addr)) in sh_msiof_request_dma()
1225 dma_unmap_single(tx_dev, p->tx_dma_addr, PAGE_SIZE, DMA_TO_DEVICE); in sh_msiof_request_dma()
1227 free_page((unsigned long)p->rx_dma_page); in sh_msiof_request_dma()
1229 free_page((unsigned long)p->tx_dma_page); in sh_msiof_request_dma()
1231 dma_release_channel(ctlr->dma_rx); in sh_msiof_request_dma()
1233 dma_release_channel(ctlr->dma_tx); in sh_msiof_request_dma()
1234 ctlr->dma_tx = NULL; in sh_msiof_request_dma()
1235 return -ENODEV; in sh_msiof_request_dma()
1240 struct spi_controller *ctlr = p->ctlr; in sh_msiof_release_dma()
1242 if (!ctlr->dma_tx) in sh_msiof_release_dma()
1245 dma_unmap_single(ctlr->dma_rx->device->dev, p->rx_dma_addr, PAGE_SIZE, in sh_msiof_release_dma()
1247 dma_unmap_single(ctlr->dma_tx->device->dev, p->tx_dma_addr, PAGE_SIZE, in sh_msiof_release_dma()
1249 free_page((unsigned long)p->rx_dma_page); in sh_msiof_release_dma()
1250 free_page((unsigned long)p->tx_dma_page); in sh_msiof_release_dma()
1251 dma_release_channel(ctlr->dma_rx); in sh_msiof_release_dma()
1252 dma_release_channel(ctlr->dma_tx); in sh_msiof_release_dma()
1264 chipdata = of_device_get_match_data(&pdev->dev); in sh_msiof_spi_probe()
1266 info = sh_msiof_spi_parse_dt(&pdev->dev); in sh_msiof_spi_probe()
1268 chipdata = (const void *)pdev->id_entry->driver_data; in sh_msiof_spi_probe()
1269 info = dev_get_platdata(&pdev->dev); in sh_msiof_spi_probe()
1273 dev_err(&pdev->dev, "failed to obtain device info\n"); in sh_msiof_spi_probe()
1274 return -ENXIO; in sh_msiof_spi_probe()
1277 if (info->mode == MSIOF_SPI_SLAVE) in sh_msiof_spi_probe()
1278 ctlr = spi_alloc_slave(&pdev->dev, in sh_msiof_spi_probe()
1281 ctlr = spi_alloc_master(&pdev->dev, in sh_msiof_spi_probe()
1284 return -ENOMEM; in sh_msiof_spi_probe()
1289 p->ctlr = ctlr; in sh_msiof_spi_probe()
1290 p->info = info; in sh_msiof_spi_probe()
1291 p->min_div_pow = chipdata->min_div_pow; in sh_msiof_spi_probe()
1293 init_completion(&p->done); in sh_msiof_spi_probe()
1294 init_completion(&p->done_txdma); in sh_msiof_spi_probe()
1296 p->clk = devm_clk_get(&pdev->dev, NULL); in sh_msiof_spi_probe()
1297 if (IS_ERR(p->clk)) { in sh_msiof_spi_probe()
1298 dev_err(&pdev->dev, "cannot get clock\n"); in sh_msiof_spi_probe()
1299 ret = PTR_ERR(p->clk); in sh_msiof_spi_probe()
1309 p->mapbase = devm_platform_ioremap_resource(pdev, 0); in sh_msiof_spi_probe()
1310 if (IS_ERR(p->mapbase)) { in sh_msiof_spi_probe()
1311 ret = PTR_ERR(p->mapbase); in sh_msiof_spi_probe()
1315 ret = devm_request_irq(&pdev->dev, i, sh_msiof_spi_irq, 0, in sh_msiof_spi_probe()
1316 dev_name(&pdev->dev), p); in sh_msiof_spi_probe()
1318 dev_err(&pdev->dev, "unable to request irq\n"); in sh_msiof_spi_probe()
1322 p->pdev = pdev; in sh_msiof_spi_probe()
1323 pm_runtime_enable(&pdev->dev); in sh_msiof_spi_probe()
1326 p->tx_fifo_size = chipdata->tx_fifo_size; in sh_msiof_spi_probe()
1327 p->rx_fifo_size = chipdata->rx_fifo_size; in sh_msiof_spi_probe()
1328 if (p->info->tx_fifo_override) in sh_msiof_spi_probe()
1329 p->tx_fifo_size = p->info->tx_fifo_override; in sh_msiof_spi_probe()
1330 if (p->info->rx_fifo_override) in sh_msiof_spi_probe()
1331 p->rx_fifo_size = p->info->rx_fifo_override; in sh_msiof_spi_probe()
1334 ctlr->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; in sh_msiof_spi_probe()
1335 ctlr->mode_bits |= SPI_LSB_FIRST | SPI_3WIRE; in sh_msiof_spi_probe()
1336 ctlr->flags = chipdata->ctlr_flags; in sh_msiof_spi_probe()
1337 ctlr->bus_num = pdev->id; in sh_msiof_spi_probe()
1338 ctlr->num_chipselect = p->info->num_chipselect; in sh_msiof_spi_probe()
1339 ctlr->dev.of_node = pdev->dev.of_node; in sh_msiof_spi_probe()
1340 ctlr->setup = sh_msiof_spi_setup; in sh_msiof_spi_probe()
1341 ctlr->prepare_message = sh_msiof_prepare_message; in sh_msiof_spi_probe()
1342 ctlr->slave_abort = sh_msiof_slave_abort; in sh_msiof_spi_probe()
1343 ctlr->bits_per_word_mask = chipdata->bits_per_word_mask; in sh_msiof_spi_probe()
1344 ctlr->auto_runtime_pm = true; in sh_msiof_spi_probe()
1345 ctlr->transfer_one = sh_msiof_transfer_one; in sh_msiof_spi_probe()
1346 ctlr->use_gpio_descriptors = true; in sh_msiof_spi_probe()
1347 ctlr->max_native_cs = MAX_SS; in sh_msiof_spi_probe()
1351 dev_warn(&pdev->dev, "DMA not available, using PIO\n"); in sh_msiof_spi_probe()
1353 ret = devm_spi_register_controller(&pdev->dev, ctlr); in sh_msiof_spi_probe()
1355 dev_err(&pdev->dev, "devm_spi_register_controller error.\n"); in sh_msiof_spi_probe()
1363 pm_runtime_disable(&pdev->dev); in sh_msiof_spi_probe()
1374 pm_runtime_disable(&pdev->dev); in sh_msiof_spi_remove()
1389 return spi_controller_suspend(p->ctlr); in sh_msiof_spi_suspend()
1396 return spi_controller_resume(p->ctlr); in sh_msiof_spi_resume()