Lines Matching +full:mmp2 +full:- +full:ssp
1 // SPDX-License-Identifier: GPL-2.0-or-later
31 #include "spi-pxa2xx.h"
34 MODULE_DESCRIPTION("PXA2xx SSP SPI Controller");
36 MODULE_ALIAS("platform:pxa2xx-spi");
41 * For testing SSCR1 changes that require SSP restart, basically
78 /* LPSS offset from drv_data->ioaddr */
80 /* Register offsets from drv_data->lpss_base or -1 */
104 .reg_capabilities = -1,
114 .reg_capabilities = -1,
124 .reg_capabilities = -1,
134 .reg_general = -1,
137 .reg_capabilities = -1,
144 .reg_general = -1,
157 .reg_general = -1,
173 return &lpss_platforms[drv_data->ssp_type - LPSS_LPT_SSP]; in lpss_get_config()
178 switch (drv_data->ssp_type) { in is_lpss_ssp()
193 return drv_data->ssp_type == QUARK_X1000_SSP; in is_quark_x1000_ssp()
198 return drv_data->ssp_type == MMP2_SSP; in is_mmp2_ssp()
203 return drv_data->ssp_type == MRFLD_SSP; in is_mrfld_ssp()
214 switch (drv_data->ssp_type) { in pxa2xx_spi_get_ssrc1_change_mask()
227 switch (drv_data->ssp_type) { in pxa2xx_spi_get_rx_default_thre()
241 switch (drv_data->ssp_type) { in pxa2xx_spi_txfifo_full()
261 switch (drv_data->ssp_type) { in pxa2xx_spi_clear_rx_thre()
278 switch (drv_data->ssp_type) { in pxa2xx_spi_set_rx_thre()
294 switch (drv_data->ssp_type) { in pxa2xx_configure_sscr0()
302 | SSCR0_DataSize(bits > 16 ? bits - 16 : bits) in pxa2xx_configure_sscr0()
308 * Read and write LPSS SSP private registers. Caller must first check that
313 WARN_ON(!drv_data->lpss_base); in __lpss_ssp_read_priv()
314 return readl(drv_data->lpss_base + offset); in __lpss_ssp_read_priv()
320 WARN_ON(!drv_data->lpss_base); in __lpss_ssp_write_priv()
321 writel(value, drv_data->lpss_base + offset); in __lpss_ssp_write_priv()
325 * lpss_ssp_setup - perform LPSS SSP specific setup
328 * Perform LPSS SSP specific setup. This function must be called first if
329 * one is going to use LPSS SSP private registers.
337 drv_data->lpss_base = drv_data->ssp->mmio_base + config->offset; in lpss_ssp_setup()
340 value = __lpss_ssp_read_priv(drv_data, config->reg_cs_ctrl); in lpss_ssp_setup()
343 __lpss_ssp_write_priv(drv_data, config->reg_cs_ctrl, value); in lpss_ssp_setup()
346 if (drv_data->controller_info->enable_dma) { in lpss_ssp_setup()
347 __lpss_ssp_write_priv(drv_data, config->reg_ssp, 1); in lpss_ssp_setup()
349 if (config->reg_general >= 0) { in lpss_ssp_setup()
351 config->reg_general); in lpss_ssp_setup()
354 config->reg_general, value); in lpss_ssp_setup()
363 spi_controller_get_devdata(spi->controller); in lpss_ssp_select_cs()
366 if (!config->cs_sel_mask) in lpss_ssp_select_cs()
369 value = __lpss_ssp_read_priv(drv_data, config->reg_cs_ctrl); in lpss_ssp_select_cs()
372 cs <<= config->cs_sel_shift; in lpss_ssp_select_cs()
373 if (cs != (value & config->cs_sel_mask)) { in lpss_ssp_select_cs()
381 value &= ~config->cs_sel_mask; in lpss_ssp_select_cs()
384 config->reg_cs_ctrl, value); in lpss_ssp_select_cs()
386 (drv_data->controller->max_speed_hz / 2)); in lpss_ssp_select_cs()
393 spi_controller_get_devdata(spi->controller); in lpss_ssp_cs_control()
402 value = __lpss_ssp_read_priv(drv_data, config->reg_cs_ctrl); in lpss_ssp_cs_control()
407 __lpss_ssp_write_priv(drv_data, config->reg_cs_ctrl, value); in lpss_ssp_cs_control()
408 if (config->cs_clk_stays_gated) { in lpss_ssp_cs_control()
429 spi_controller_get_devdata(spi->controller); in cs_assert()
431 if (drv_data->ssp_type == CE4100_SSP) { in cs_assert()
443 spi_controller_get_devdata(spi->controller); in cs_deassert()
446 if (drv_data->ssp_type == CE4100_SSP) in cs_deassert()
449 /* Wait until SSP becomes idle before deasserting the CS */ in cs_deassert()
474 } while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_BSY) && --limit); in pxa2xx_spi_flush()
486 pxa_ssp_disable(drv_data->ssp); in pxa2xx_spi_off()
491 u8 n_bytes = drv_data->n_bytes; in null_writer()
494 || (drv_data->tx == drv_data->tx_end)) in null_writer()
498 drv_data->tx += n_bytes; in null_writer()
505 u8 n_bytes = drv_data->n_bytes; in null_reader()
507 while (read_SSSR_bits(drv_data, SSSR_RNE) && drv_data->rx < drv_data->rx_end) { in null_reader()
509 drv_data->rx += n_bytes; in null_reader()
512 return drv_data->rx == drv_data->rx_end; in null_reader()
518 || (drv_data->tx == drv_data->tx_end)) in u8_writer()
521 pxa2xx_spi_write(drv_data, SSDR, *(u8 *)(drv_data->tx)); in u8_writer()
522 ++drv_data->tx; in u8_writer()
529 while (read_SSSR_bits(drv_data, SSSR_RNE) && drv_data->rx < drv_data->rx_end) { in u8_reader()
530 *(u8 *)(drv_data->rx) = pxa2xx_spi_read(drv_data, SSDR); in u8_reader()
531 ++drv_data->rx; in u8_reader()
534 return drv_data->rx == drv_data->rx_end; in u8_reader()
540 || (drv_data->tx == drv_data->tx_end)) in u16_writer()
543 pxa2xx_spi_write(drv_data, SSDR, *(u16 *)(drv_data->tx)); in u16_writer()
544 drv_data->tx += 2; in u16_writer()
551 while (read_SSSR_bits(drv_data, SSSR_RNE) && drv_data->rx < drv_data->rx_end) { in u16_reader()
552 *(u16 *)(drv_data->rx) = pxa2xx_spi_read(drv_data, SSDR); in u16_reader()
553 drv_data->rx += 2; in u16_reader()
556 return drv_data->rx == drv_data->rx_end; in u16_reader()
562 || (drv_data->tx == drv_data->tx_end)) in u32_writer()
565 pxa2xx_spi_write(drv_data, SSDR, *(u32 *)(drv_data->tx)); in u32_writer()
566 drv_data->tx += 4; in u32_writer()
573 while (read_SSSR_bits(drv_data, SSSR_RNE) && drv_data->rx < drv_data->rx_end) { in u32_reader()
574 *(u32 *)(drv_data->rx) = pxa2xx_spi_read(drv_data, SSDR); in u32_reader()
575 drv_data->rx += 4; in u32_reader()
578 return drv_data->rx == drv_data->rx_end; in u32_reader()
583 u32 mask = drv_data->int_cr1 | drv_data->dma_cr1, threshold; in reset_sccr1()
586 if (drv_data->controller->cur_msg) { in reset_sccr1()
587 chip = spi_get_ctldata(drv_data->controller->cur_msg->spi); in reset_sccr1()
588 threshold = chip->threshold; in reset_sccr1()
593 switch (drv_data->ssp_type) { in reset_sccr1()
611 write_SSSR_CS(drv_data, drv_data->clear_sr); in int_stop_and_reset()
625 dev_err(drv_data->ssp->dev, "%s\n", msg); in int_error_stop()
627 drv_data->controller->cur_msg->status = err; in int_error_stop()
628 spi_finalize_current_transfer(drv_data->controller); in int_error_stop()
635 spi_finalize_current_transfer(drv_data->controller); in int_transfer_complete()
642 irq_status = read_SSSR_bits(drv_data, drv_data->mask_sr); in interrupt_transfer()
647 int_error_stop(drv_data, "interrupt_transfer: FIFO overrun", -EIO); in interrupt_transfer()
652 int_error_stop(drv_data, "interrupt_transfer: FIFO underrun", -EIO); in interrupt_transfer()
658 if (drv_data->read(drv_data)) { in interrupt_transfer()
666 if (drv_data->read(drv_data)) { in interrupt_transfer()
670 } while (drv_data->write(drv_data)); in interrupt_transfer()
672 if (drv_data->read(drv_data)) { in interrupt_transfer()
677 if (drv_data->tx == drv_data->tx_end) { in interrupt_transfer()
693 bytes_left = drv_data->rx_end - drv_data->rx; in interrupt_transfer()
694 switch (drv_data->n_bytes) { in interrupt_transfer()
721 dev_err(drv_data->ssp->dev, "bad message state in interrupt handler\n"); in handle_bad_msg()
728 u32 mask = drv_data->mask_sr; in ssp_int()
737 if (pm_runtime_suspended(drv_data->ssp->dev)) in ssp_int()
763 pxa2xx_spi_write(drv_data, SSCR1, sccr1_reg & ~drv_data->int_cr1); in ssp_int()
766 if (!drv_data->controller->cur_msg) { in ssp_int()
772 return drv_data->transfer_handler(drv_data); in ssp_int()
831 scale = fls_long(q1 - 1); in quark_x1000_get_clk_div()
833 q1 >>= scale - 9; in quark_x1000_get_clk_div()
834 mul >>= scale - 9; in quark_x1000_get_clk_div()
847 r1 = abs(fref1 / (1 << (24 - fls_long(mul))) / q1 - rate); in quark_x1000_get_clk_div()
852 r2 = abs(fref2 / q2 - rate); in quark_x1000_get_clk_div()
882 r1 = abs(fssp - rate); in quark_x1000_get_clk_div()
893 return q - 1; in quark_x1000_get_clk_div()
898 unsigned long ssp_clk = drv_data->controller->max_speed_hz; in ssp_get_clk_div()
899 const struct ssp_device *ssp = drv_data->ssp; in ssp_get_clk_div() local
905 * that the SSP transmission rate can be greater than the device rate. in ssp_get_clk_div()
907 if (ssp->type == PXA25x_SSP || ssp->type == CE4100_SSP) in ssp_get_clk_div()
908 return (DIV_ROUND_UP(ssp_clk, 2 * rate) - 1) & 0xff; in ssp_get_clk_div()
910 return (DIV_ROUND_UP(ssp_clk, rate) - 1) & 0xfff; in ssp_get_clk_div()
917 spi_get_ctldata(drv_data->controller->cur_msg->spi); in pxa2xx_ssp_get_clk_div()
920 switch (drv_data->ssp_type) { in pxa2xx_ssp_get_clk_div()
922 clk_div = quark_x1000_get_clk_div(rate, &chip->dds_rate); in pxa2xx_ssp_get_clk_div()
937 return chip->enable_dma && in pxa2xx_spi_can_dma()
938 xfer->len <= MAX_DMA_LEN && in pxa2xx_spi_can_dma()
939 xfer->len >= chip->dma_burst_size; in pxa2xx_spi_can_dma()
947 struct spi_message *message = controller->cur_msg; in pxa2xx_spi_transfer_one()
949 u32 dma_thresh = chip->dma_threshold; in pxa2xx_spi_transfer_one()
950 u32 dma_burst = chip->dma_burst_size; in pxa2xx_spi_transfer_one()
961 if (transfer->len > MAX_DMA_LEN && chip->enable_dma) { in pxa2xx_spi_transfer_one()
963 /* Reject already-mapped transfers; PIO won't always work */ in pxa2xx_spi_transfer_one()
964 if (message->is_dma_mapped in pxa2xx_spi_transfer_one()
965 || transfer->rx_dma || transfer->tx_dma) { in pxa2xx_spi_transfer_one()
966 dev_err(&spi->dev, in pxa2xx_spi_transfer_one()
968 transfer->len, MAX_DMA_LEN); in pxa2xx_spi_transfer_one()
969 return -EINVAL; in pxa2xx_spi_transfer_one()
973 dev_warn_ratelimited(&spi->dev, in pxa2xx_spi_transfer_one()
975 transfer->len, MAX_DMA_LEN); in pxa2xx_spi_transfer_one()
980 dev_err(&spi->dev, "Flush failed\n"); in pxa2xx_spi_transfer_one()
981 return -EIO; in pxa2xx_spi_transfer_one()
983 drv_data->tx = (void *)transfer->tx_buf; in pxa2xx_spi_transfer_one()
984 drv_data->tx_end = drv_data->tx + transfer->len; in pxa2xx_spi_transfer_one()
985 drv_data->rx = transfer->rx_buf; in pxa2xx_spi_transfer_one()
986 drv_data->rx_end = drv_data->rx + transfer->len; in pxa2xx_spi_transfer_one()
989 bits = transfer->bits_per_word; in pxa2xx_spi_transfer_one()
990 speed = transfer->speed_hz; in pxa2xx_spi_transfer_one()
995 drv_data->n_bytes = 1; in pxa2xx_spi_transfer_one()
996 drv_data->read = drv_data->rx ? u8_reader : null_reader; in pxa2xx_spi_transfer_one()
997 drv_data->write = drv_data->tx ? u8_writer : null_writer; in pxa2xx_spi_transfer_one()
999 drv_data->n_bytes = 2; in pxa2xx_spi_transfer_one()
1000 drv_data->read = drv_data->rx ? u16_reader : null_reader; in pxa2xx_spi_transfer_one()
1001 drv_data->write = drv_data->tx ? u16_writer : null_writer; in pxa2xx_spi_transfer_one()
1003 drv_data->n_bytes = 4; in pxa2xx_spi_transfer_one()
1004 drv_data->read = drv_data->rx ? u32_reader : null_reader; in pxa2xx_spi_transfer_one()
1005 drv_data->write = drv_data->tx ? u32_writer : null_writer; in pxa2xx_spi_transfer_one()
1011 if (chip->enable_dma) { in pxa2xx_spi_transfer_one()
1016 dev_warn_ratelimited(&spi->dev, in pxa2xx_spi_transfer_one()
1020 dma_mapped = controller->can_dma && in pxa2xx_spi_transfer_one()
1021 controller->can_dma(controller, spi, transfer) && in pxa2xx_spi_transfer_one()
1022 controller->cur_msg_mapped; in pxa2xx_spi_transfer_one()
1026 drv_data->transfer_handler = pxa2xx_spi_dma_transfer; in pxa2xx_spi_transfer_one()
1033 cr1 = chip->cr1 | dma_thresh | drv_data->dma_cr1; in pxa2xx_spi_transfer_one()
1034 pxa2xx_spi_write(drv_data, SSSR, drv_data->clear_sr); in pxa2xx_spi_transfer_one()
1039 drv_data->transfer_handler = interrupt_transfer; in pxa2xx_spi_transfer_one()
1042 cr1 = chip->cr1 | chip->threshold | drv_data->int_cr1; in pxa2xx_spi_transfer_one()
1043 write_SSSR_CS(drv_data, drv_data->clear_sr); in pxa2xx_spi_transfer_one()
1049 dev_dbg(&spi->dev, "%u Hz actual, %s\n", in pxa2xx_spi_transfer_one()
1050 controller->max_speed_hz in pxa2xx_spi_transfer_one()
1054 dev_dbg(&spi->dev, "%u Hz actual, %s\n", in pxa2xx_spi_transfer_one()
1055 controller->max_speed_hz / 2 in pxa2xx_spi_transfer_one()
1060 pxa2xx_spi_update(drv_data, SSIRF, GENMASK(7, 0), chip->lpss_rx_threshold); in pxa2xx_spi_transfer_one()
1061 pxa2xx_spi_update(drv_data, SSITF, GENMASK(15, 0), chip->lpss_tx_threshold); in pxa2xx_spi_transfer_one()
1068 thresh |= SFIFOTT_RxThresh(chip->lpss_rx_threshold); in pxa2xx_spi_transfer_one()
1069 thresh |= SFIFOTT_TxThresh(chip->lpss_tx_threshold); in pxa2xx_spi_transfer_one()
1075 pxa2xx_spi_update(drv_data, DDS_RATE, GENMASK(23, 0), chip->dds_rate); in pxa2xx_spi_transfer_one()
1077 /* Stop the SSP */ in pxa2xx_spi_transfer_one()
1079 pxa_ssp_disable(drv_data->ssp); in pxa2xx_spi_transfer_one()
1082 pxa2xx_spi_write(drv_data, SSTO, chip->timeout); in pxa2xx_spi_transfer_one()
1090 /* Restart the SSP */ in pxa2xx_spi_transfer_one()
1091 pxa_ssp_enable(drv_data->ssp); in pxa2xx_spi_transfer_one()
1097 /* On MMP2, flipping SSE doesn't to empty Tx FIFO. */ in pxa2xx_spi_transfer_one()
1098 dev_warn(&spi->dev, "%u bytes of garbage in Tx FIFO!\n", tx_level); in pxa2xx_spi_transfer_one()
1099 if (tx_level > transfer->len) in pxa2xx_spi_transfer_one()
1100 tx_level = transfer->len; in pxa2xx_spi_transfer_one()
1101 drv_data->tx += tx_level; in pxa2xx_spi_transfer_one()
1106 while (drv_data->write(drv_data)) in pxa2xx_spi_transfer_one()
1108 if (drv_data->gpiod_ready) { in pxa2xx_spi_transfer_one()
1109 gpiod_set_value(drv_data->gpiod_ready, 1); in pxa2xx_spi_transfer_one()
1111 gpiod_set_value(drv_data->gpiod_ready, 0); in pxa2xx_spi_transfer_one()
1128 int_error_stop(drv_data, "transfer aborted", -EINTR); in pxa2xx_spi_target_abort()
1140 /* Disable the SSP */ in pxa2xx_spi_handle_err()
1150 if (atomic_read(&drv_data->dma_running)) in pxa2xx_spi_handle_err()
1158 /* Disable the SSP now */ in pxa2xx_spi_unprepare_transfer()
1170 spi_controller_get_devdata(spi->controller); in setup()
1173 switch (drv_data->ssp_type) { in setup()
1196 tx_thres = config->tx_threshold_lo; in setup()
1197 tx_hi_thres = config->tx_threshold_hi; in setup()
1198 rx_thres = config->rx_threshold; in setup()
1202 if (spi_controller_is_target(drv_data->controller)) { in setup()
1217 return -ENOMEM; in setup()
1219 if (drv_data->ssp_type == CE4100_SSP) { in setup()
1221 dev_err(&spi->dev, in setup()
1224 return -EINVAL; in setup()
1227 chip->enable_dma = drv_data->controller_info->enable_dma; in setup()
1228 chip->timeout = TIMOUT_DFLT; in setup()
1235 chip_info = spi->controller_data; in setup()
1239 if (chip_info->timeout) in setup()
1240 chip->timeout = chip_info->timeout; in setup()
1241 if (chip_info->tx_threshold) in setup()
1242 tx_thres = chip_info->tx_threshold; in setup()
1243 if (chip_info->tx_hi_threshold) in setup()
1244 tx_hi_thres = chip_info->tx_hi_threshold; in setup()
1245 if (chip_info->rx_threshold) in setup()
1246 rx_thres = chip_info->rx_threshold; in setup()
1247 chip->dma_threshold = 0; in setup()
1250 chip->cr1 = 0; in setup()
1251 if (spi_controller_is_target(drv_data->controller)) { in setup()
1252 chip->cr1 |= SSCR1_SCFR; in setup()
1253 chip->cr1 |= SSCR1_SCLKDIR; in setup()
1254 chip->cr1 |= SSCR1_SFRMDIR; in setup()
1255 chip->cr1 |= SSCR1_SPH; in setup()
1259 chip->lpss_rx_threshold = SSIRF_RxThresh(rx_thres); in setup()
1260 chip->lpss_tx_threshold = SSITF_TxLoThresh(tx_thres) | in setup()
1265 chip->lpss_rx_threshold = rx_thres; in setup()
1266 chip->lpss_tx_threshold = tx_thres; in setup()
1271 * chip_info goes away after setting chip->enable_dma, the burst and in setup()
1274 if (chip->enable_dma) { in setup()
1277 spi->bits_per_word, in setup()
1278 &chip->dma_burst_size, in setup()
1279 &chip->dma_threshold)) { in setup()
1280 dev_warn(&spi->dev, in setup()
1283 dev_dbg(&spi->dev, in setup()
1285 chip->dma_burst_size); in setup()
1288 switch (drv_data->ssp_type) { in setup()
1290 chip->threshold = (QUARK_X1000_SSCR1_RxTresh(rx_thres) in setup()
1296 chip->threshold = (CE4100_SSCR1_RxTresh(rx_thres) & CE4100_SSCR1_RFT) | in setup()
1300 chip->threshold = (SSCR1_RxTresh(rx_thres) & SSCR1_RFT) | in setup()
1305 chip->cr1 &= ~(SSCR1_SPO | SSCR1_SPH); in setup()
1306 chip->cr1 |= ((spi->mode & SPI_CPHA) ? SSCR1_SPH : 0) | in setup()
1307 ((spi->mode & SPI_CPOL) ? SSCR1_SPO : 0); in setup()
1309 if (spi->mode & SPI_LOOP) in setup()
1310 chip->cr1 |= SSCR1_LBM; in setup()
1326 return param == chan->device->dev; in pxa2xx_spi_idma_filter()
1333 struct device *dev = &pdev->dev; in pxa2xx_spi_init_pdata()
1334 struct device *parent = dev->parent; in pxa2xx_spi_init_pdata()
1335 struct ssp_device *ssp; in pxa2xx_spi_init_pdata() local
1351 status = device_property_read_u32(dev, "intel,spi-pxa2xx-type", &value); in pxa2xx_spi_init_pdata()
1358 /* Validate the SSP type correctness */ in pxa2xx_spi_init_pdata()
1360 return ERR_PTR(-EINVAL); in pxa2xx_spi_init_pdata()
1364 return ERR_PTR(-ENOMEM); in pxa2xx_spi_init_pdata()
1366 ssp = &pdata->ssp; in pxa2xx_spi_init_pdata()
1368 ssp->mmio_base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in pxa2xx_spi_init_pdata()
1369 if (IS_ERR(ssp->mmio_base)) in pxa2xx_spi_init_pdata()
1370 return ERR_CAST(ssp->mmio_base); in pxa2xx_spi_init_pdata()
1372 ssp->phys_base = res->start; in pxa2xx_spi_init_pdata()
1374 /* Platforms with iDMA 64-bit */ in pxa2xx_spi_init_pdata()
1376 pdata->tx_param = parent; in pxa2xx_spi_init_pdata()
1377 pdata->rx_param = parent; in pxa2xx_spi_init_pdata()
1378 pdata->dma_filter = pxa2xx_spi_idma_filter; in pxa2xx_spi_init_pdata()
1381 ssp->clk = devm_clk_get(dev, NULL); in pxa2xx_spi_init_pdata()
1382 if (IS_ERR(ssp->clk)) in pxa2xx_spi_init_pdata()
1383 return ERR_CAST(ssp->clk); in pxa2xx_spi_init_pdata()
1385 ssp->irq = platform_get_irq(pdev, 0); in pxa2xx_spi_init_pdata()
1386 if (ssp->irq < 0) in pxa2xx_spi_init_pdata()
1387 return ERR_PTR(ssp->irq); in pxa2xx_spi_init_pdata()
1389 ssp->type = type; in pxa2xx_spi_init_pdata()
1390 ssp->dev = dev; in pxa2xx_spi_init_pdata()
1394 ssp->port_id = -1; in pxa2xx_spi_init_pdata()
1396 ssp->port_id = uid; in pxa2xx_spi_init_pdata()
1398 pdata->is_target = device_property_read_bool(dev, "spi-slave"); in pxa2xx_spi_init_pdata()
1399 pdata->num_chipselect = 1; in pxa2xx_spi_init_pdata()
1400 pdata->enable_dma = true; in pxa2xx_spi_init_pdata()
1401 pdata->dma_burst_size = 1; in pxa2xx_spi_init_pdata()
1411 if (has_acpi_companion(drv_data->ssp->dev)) { in pxa2xx_spi_fw_translate_cs()
1412 switch (drv_data->ssp_type) { in pxa2xx_spi_fw_translate_cs()
1420 return cs - 1; in pxa2xx_spi_fw_translate_cs()
1437 struct device *dev = &pdev->dev; in pxa2xx_spi_probe()
1441 struct ssp_device *ssp; in pxa2xx_spi_probe() local
1450 dev_err(&pdev->dev, "missing platform data\n"); in pxa2xx_spi_probe()
1455 ssp = pxa_ssp_request(pdev->id, pdev->name); in pxa2xx_spi_probe()
1456 if (!ssp) in pxa2xx_spi_probe()
1457 ssp = &platform_info->ssp; in pxa2xx_spi_probe()
1459 if (!ssp->mmio_base) { in pxa2xx_spi_probe()
1460 dev_err(&pdev->dev, "failed to get SSP\n"); in pxa2xx_spi_probe()
1461 return -ENODEV; in pxa2xx_spi_probe()
1464 if (platform_info->is_target) in pxa2xx_spi_probe()
1470 dev_err(&pdev->dev, "cannot alloc spi_controller\n"); in pxa2xx_spi_probe()
1471 status = -ENOMEM; in pxa2xx_spi_probe()
1475 drv_data->controller = controller; in pxa2xx_spi_probe()
1476 drv_data->controller_info = platform_info; in pxa2xx_spi_probe()
1477 drv_data->ssp = ssp; in pxa2xx_spi_probe()
1479 device_set_node(&controller->dev, dev_fwnode(dev)); in pxa2xx_spi_probe()
1481 /* The spi->mode bits understood by this driver: */ in pxa2xx_spi_probe()
1482 controller->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP; in pxa2xx_spi_probe()
1484 controller->bus_num = ssp->port_id; in pxa2xx_spi_probe()
1485 controller->dma_alignment = DMA_ALIGNMENT; in pxa2xx_spi_probe()
1486 controller->cleanup = cleanup; in pxa2xx_spi_probe()
1487 controller->setup = setup; in pxa2xx_spi_probe()
1488 controller->set_cs = pxa2xx_spi_set_cs; in pxa2xx_spi_probe()
1489 controller->transfer_one = pxa2xx_spi_transfer_one; in pxa2xx_spi_probe()
1490 controller->target_abort = pxa2xx_spi_target_abort; in pxa2xx_spi_probe()
1491 controller->handle_err = pxa2xx_spi_handle_err; in pxa2xx_spi_probe()
1492 controller->unprepare_transfer_hardware = pxa2xx_spi_unprepare_transfer; in pxa2xx_spi_probe()
1493 controller->fw_translate_cs = pxa2xx_spi_fw_translate_cs; in pxa2xx_spi_probe()
1494 controller->auto_runtime_pm = true; in pxa2xx_spi_probe()
1495 controller->flags = SPI_CONTROLLER_MUST_RX | SPI_CONTROLLER_MUST_TX; in pxa2xx_spi_probe()
1497 drv_data->ssp_type = ssp->type; in pxa2xx_spi_probe()
1500 switch (drv_data->ssp_type) { in pxa2xx_spi_probe()
1502 controller->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32); in pxa2xx_spi_probe()
1505 controller->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16); in pxa2xx_spi_probe()
1509 drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE; in pxa2xx_spi_probe()
1510 drv_data->dma_cr1 = 0; in pxa2xx_spi_probe()
1511 drv_data->clear_sr = SSSR_ROR; in pxa2xx_spi_probe()
1512 drv_data->mask_sr = SSSR_RFS | SSSR_TFS | SSSR_ROR; in pxa2xx_spi_probe()
1514 controller->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32); in pxa2xx_spi_probe()
1515 drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE | SSCR1_TINTE; in pxa2xx_spi_probe()
1516 drv_data->dma_cr1 = DEFAULT_DMA_CR1; in pxa2xx_spi_probe()
1517 drv_data->clear_sr = SSSR_ROR | SSSR_TINT; in pxa2xx_spi_probe()
1518 drv_data->mask_sr = SSSR_TINT | SSSR_RFS | SSSR_TFS in pxa2xx_spi_probe()
1522 status = request_irq(ssp->irq, ssp_int, IRQF_SHARED, dev_name(dev), in pxa2xx_spi_probe()
1525 dev_err(&pdev->dev, "cannot get IRQ %d\n", ssp->irq); in pxa2xx_spi_probe()
1530 if (platform_info->enable_dma) { in pxa2xx_spi_probe()
1534 platform_info->enable_dma = false; in pxa2xx_spi_probe()
1536 controller->can_dma = pxa2xx_spi_can_dma; in pxa2xx_spi_probe()
1537 controller->max_dma_len = MAX_DMA_LEN; in pxa2xx_spi_probe()
1538 controller->max_transfer_size = in pxa2xx_spi_probe()
1544 status = clk_prepare_enable(ssp->clk); in pxa2xx_spi_probe()
1548 controller->max_speed_hz = clk_get_rate(ssp->clk); in pxa2xx_spi_probe()
1554 controller->min_speed_hz = in pxa2xx_spi_probe()
1555 DIV_ROUND_UP(controller->max_speed_hz, 4096); in pxa2xx_spi_probe()
1557 controller->min_speed_hz = in pxa2xx_spi_probe()
1558 DIV_ROUND_UP(controller->max_speed_hz, 512); in pxa2xx_spi_probe()
1560 pxa_ssp_disable(ssp); in pxa2xx_spi_probe()
1562 /* Load default SSP configuration */ in pxa2xx_spi_probe()
1563 switch (drv_data->ssp_type) { in pxa2xx_spi_probe()
1610 if (config->reg_capabilities >= 0) { in pxa2xx_spi_probe()
1612 config->reg_capabilities); in pxa2xx_spi_probe()
1615 platform_info->num_chipselect = ffz(tmp); in pxa2xx_spi_probe()
1616 } else if (config->cs_num) { in pxa2xx_spi_probe()
1617 platform_info->num_chipselect = config->cs_num; in pxa2xx_spi_probe()
1620 controller->num_chipselect = platform_info->num_chipselect; in pxa2xx_spi_probe()
1621 controller->use_gpio_descriptors = true; in pxa2xx_spi_probe()
1623 if (platform_info->is_target) { in pxa2xx_spi_probe()
1624 drv_data->gpiod_ready = devm_gpiod_get_optional(dev, in pxa2xx_spi_probe()
1626 if (IS_ERR(drv_data->gpiod_ready)) { in pxa2xx_spi_probe()
1627 status = PTR_ERR(drv_data->gpiod_ready); in pxa2xx_spi_probe()
1632 pm_runtime_set_autosuspend_delay(&pdev->dev, 50); in pxa2xx_spi_probe()
1633 pm_runtime_use_autosuspend(&pdev->dev); in pxa2xx_spi_probe()
1634 pm_runtime_set_active(&pdev->dev); in pxa2xx_spi_probe()
1635 pm_runtime_enable(&pdev->dev); in pxa2xx_spi_probe()
1641 dev_err(&pdev->dev, "problem registering SPI controller\n"); in pxa2xx_spi_probe()
1648 pm_runtime_disable(&pdev->dev); in pxa2xx_spi_probe()
1651 clk_disable_unprepare(ssp->clk); in pxa2xx_spi_probe()
1655 free_irq(ssp->irq, drv_data); in pxa2xx_spi_probe()
1658 pxa_ssp_free(ssp); in pxa2xx_spi_probe()
1665 struct ssp_device *ssp = drv_data->ssp; in pxa2xx_spi_remove() local
1667 pm_runtime_get_sync(&pdev->dev); in pxa2xx_spi_remove()
1669 spi_unregister_controller(drv_data->controller); in pxa2xx_spi_remove()
1671 /* Disable the SSP at the peripheral and SOC level */ in pxa2xx_spi_remove()
1672 pxa_ssp_disable(ssp); in pxa2xx_spi_remove()
1673 clk_disable_unprepare(ssp->clk); in pxa2xx_spi_remove()
1676 if (drv_data->controller_info->enable_dma) in pxa2xx_spi_remove()
1679 pm_runtime_put_noidle(&pdev->dev); in pxa2xx_spi_remove()
1680 pm_runtime_disable(&pdev->dev); in pxa2xx_spi_remove()
1683 free_irq(ssp->irq, drv_data); in pxa2xx_spi_remove()
1685 /* Release SSP */ in pxa2xx_spi_remove()
1686 pxa_ssp_free(ssp); in pxa2xx_spi_remove()
1692 struct ssp_device *ssp = drv_data->ssp; in pxa2xx_spi_suspend() local
1695 status = spi_controller_suspend(drv_data->controller); in pxa2xx_spi_suspend()
1699 pxa_ssp_disable(ssp); in pxa2xx_spi_suspend()
1702 clk_disable_unprepare(ssp->clk); in pxa2xx_spi_suspend()
1710 struct ssp_device *ssp = drv_data->ssp; in pxa2xx_spi_resume() local
1713 /* Enable the SSP clock */ in pxa2xx_spi_resume()
1715 status = clk_prepare_enable(ssp->clk); in pxa2xx_spi_resume()
1721 return spi_controller_resume(drv_data->controller); in pxa2xx_spi_resume()
1728 clk_disable_unprepare(drv_data->ssp->clk); in pxa2xx_spi_runtime_suspend()
1736 return clk_prepare_enable(drv_data->ssp->clk); in pxa2xx_spi_runtime_resume()
1758 { .compatible = "marvell,mmp2-ssp", .data = (void *)MMP2_SSP },
1765 .name = "pxa2xx-spi",