Lines Matching refs:dln2

102 static int dln2_spi_enable(struct dln2_spi *dln2, bool enable)  in dln2_spi_enable()  argument
111 tx.port = dln2->port; in dln2_spi_enable()
121 return dln2_transfer_tx(dln2->pdev, cmd, &tx, len); in dln2_spi_enable()
132 static int dln2_spi_cs_set(struct dln2_spi *dln2, u8 cs_mask) in dln2_spi_cs_set() argument
139 tx.port = dln2->port; in dln2_spi_cs_set()
148 return dln2_transfer_tx(dln2->pdev, DLN2_SPI_SET_SS, &tx, sizeof(tx)); in dln2_spi_cs_set()
154 static int dln2_spi_cs_set_one(struct dln2_spi *dln2, u8 cs) in dln2_spi_cs_set_one() argument
156 return dln2_spi_cs_set(dln2, BIT(cs)); in dln2_spi_cs_set_one()
162 static int dln2_spi_cs_enable(struct dln2_spi *dln2, u8 cs_mask, bool enable) in dln2_spi_cs_enable() argument
170 tx.port = dln2->port; in dln2_spi_cs_enable()
174 return dln2_transfer_tx(dln2->pdev, cmd, &tx, sizeof(tx)); in dln2_spi_cs_enable()
177 static int dln2_spi_cs_enable_all(struct dln2_spi *dln2, bool enable) in dln2_spi_cs_enable_all() argument
179 u8 cs_mask = GENMASK(dln2->host->num_chipselect - 1, 0); in dln2_spi_cs_enable_all()
181 return dln2_spi_cs_enable(dln2, cs_mask, enable); in dln2_spi_cs_enable_all()
184 static int dln2_spi_get_cs_num(struct dln2_spi *dln2, u16 *cs_num) in dln2_spi_get_cs_num() argument
195 tx.port = dln2->port; in dln2_spi_get_cs_num()
196 ret = dln2_transfer(dln2->pdev, DLN2_SPI_GET_SS_COUNT, &tx, sizeof(tx), in dln2_spi_get_cs_num()
205 dev_dbg(&dln2->pdev->dev, "cs_num = %d\n", *cs_num); in dln2_spi_get_cs_num()
210 static int dln2_spi_get_speed(struct dln2_spi *dln2, u16 cmd, u32 *freq) in dln2_spi_get_speed() argument
221 tx.port = dln2->port; in dln2_spi_get_speed()
223 ret = dln2_transfer(dln2->pdev, cmd, &tx, sizeof(tx), &rx, &rx_len); in dln2_spi_get_speed()
237 static int dln2_spi_get_speed_range(struct dln2_spi *dln2, u32 *fmin, u32 *fmax) in dln2_spi_get_speed_range() argument
241 ret = dln2_spi_get_speed(dln2, DLN2_SPI_GET_MIN_FREQUENCY, fmin); in dln2_spi_get_speed_range()
245 ret = dln2_spi_get_speed(dln2, DLN2_SPI_GET_MAX_FREQUENCY, fmax); in dln2_spi_get_speed_range()
249 dev_dbg(&dln2->pdev->dev, "freq_min = %d, freq_max = %d\n", in dln2_spi_get_speed_range()
259 static int dln2_spi_set_speed(struct dln2_spi *dln2, u32 speed) in dln2_spi_set_speed() argument
271 tx.port = dln2->port; in dln2_spi_set_speed()
274 ret = dln2_transfer(dln2->pdev, DLN2_SPI_SET_FREQUENCY, &tx, sizeof(tx), in dln2_spi_set_speed()
287 static int dln2_spi_set_mode(struct dln2_spi *dln2, u8 mode) in dln2_spi_set_mode() argument
294 tx.port = dln2->port; in dln2_spi_set_mode()
297 return dln2_transfer_tx(dln2->pdev, DLN2_SPI_SET_MODE, &tx, sizeof(tx)); in dln2_spi_set_mode()
303 static int dln2_spi_set_bpw(struct dln2_spi *dln2, u8 bpw) in dln2_spi_set_bpw() argument
310 tx.port = dln2->port; in dln2_spi_set_bpw()
313 return dln2_transfer_tx(dln2->pdev, DLN2_SPI_SET_FRAME_SIZE, in dln2_spi_set_bpw()
317 static int dln2_spi_get_supported_frame_sizes(struct dln2_spi *dln2, in dln2_spi_get_supported_frame_sizes() argument
327 } *rx = dln2->buf; in dln2_spi_get_supported_frame_sizes()
331 tx.port = dln2->port; in dln2_spi_get_supported_frame_sizes()
333 ret = dln2_transfer(dln2->pdev, DLN2_SPI_GET_SUPPORTED_FRAME_SIZES, in dln2_spi_get_supported_frame_sizes()
346 dev_dbg(&dln2->pdev->dev, "bpw_mask = 0x%X\n", *bpw_mask); in dln2_spi_get_supported_frame_sizes()
419 static int dln2_spi_write_one(struct dln2_spi *dln2, const u8 *data, in dln2_spi_write_one() argument
427 } __packed *tx = dln2->buf; in dln2_spi_write_one()
435 tx->port = dln2->port; in dln2_spi_write_one()
439 dln2_spi_copy_to_buf(tx->buf, data, data_len, dln2->bpw); in dln2_spi_write_one()
442 return dln2_transfer_tx(dln2->pdev, DLN2_SPI_WRITE, tx, tx_len); in dln2_spi_write_one()
448 static int dln2_spi_read_one(struct dln2_spi *dln2, u8 *data, in dln2_spi_read_one() argument
460 } __packed *rx = dln2->buf; in dln2_spi_read_one()
468 tx.port = dln2->port; in dln2_spi_read_one()
472 ret = dln2_transfer(dln2->pdev, DLN2_SPI_READ, &tx, sizeof(tx), in dln2_spi_read_one()
481 dln2_spi_copy_from_buf(data, rx->buf, data_len, dln2->bpw); in dln2_spi_read_one()
489 static int dln2_spi_read_write_one(struct dln2_spi *dln2, const u8 *tx_data, in dln2_spi_read_write_one() argument
516 tx = dln2->buf; in dln2_spi_read_write_one()
517 rx = dln2->buf; in dln2_spi_read_write_one()
519 tx->port = dln2->port; in dln2_spi_read_write_one()
523 dln2_spi_copy_to_buf(tx->buf, tx_data, data_len, dln2->bpw); in dln2_spi_read_write_one()
528 ret = dln2_transfer(dln2->pdev, DLN2_SPI_READ_WRITE, tx, tx_len, in dln2_spi_read_write_one()
537 dln2_spi_copy_from_buf(rx_data, rx->buf, data_len, dln2->bpw); in dln2_spi_read_write_one()
546 static int dln2_spi_rdwr(struct dln2_spi *dln2, const u8 *tx_data, in dln2_spi_rdwr() argument
567 ret = dln2_spi_read_write_one(dln2, in dln2_spi_rdwr()
572 ret = dln2_spi_write_one(dln2, in dln2_spi_rdwr()
576 ret = dln2_spi_read_one(dln2, in dln2_spi_rdwr()
596 struct dln2_spi *dln2 = spi_controller_get_devdata(host); in dln2_spi_prepare_message() local
599 if (dln2->cs != spi_get_chipselect(spi, 0)) { in dln2_spi_prepare_message()
600 ret = dln2_spi_cs_set_one(dln2, spi_get_chipselect(spi, 0)); in dln2_spi_prepare_message()
604 dln2->cs = spi_get_chipselect(spi, 0); in dln2_spi_prepare_message()
610 static int dln2_spi_transfer_setup(struct dln2_spi *dln2, u32 speed, in dln2_spi_transfer_setup() argument
616 bus_setup_change = dln2->speed != speed || dln2->mode != mode || in dln2_spi_transfer_setup()
617 dln2->bpw != bpw; in dln2_spi_transfer_setup()
622 ret = dln2_spi_enable(dln2, false); in dln2_spi_transfer_setup()
626 if (dln2->speed != speed) { in dln2_spi_transfer_setup()
627 ret = dln2_spi_set_speed(dln2, speed); in dln2_spi_transfer_setup()
631 dln2->speed = speed; in dln2_spi_transfer_setup()
634 if (dln2->mode != mode) { in dln2_spi_transfer_setup()
635 ret = dln2_spi_set_mode(dln2, mode & 0x3); in dln2_spi_transfer_setup()
639 dln2->mode = mode; in dln2_spi_transfer_setup()
642 if (dln2->bpw != bpw) { in dln2_spi_transfer_setup()
643 ret = dln2_spi_set_bpw(dln2, bpw); in dln2_spi_transfer_setup()
647 dln2->bpw = bpw; in dln2_spi_transfer_setup()
650 return dln2_spi_enable(dln2, true); in dln2_spi_transfer_setup()
657 struct dln2_spi *dln2 = spi_controller_get_devdata(host); in dln2_spi_transfer_one() local
661 status = dln2_spi_transfer_setup(dln2, xfer->speed_hz, in dln2_spi_transfer_one()
665 dev_err(&dln2->pdev->dev, "Cannot setup transfer\n"); in dln2_spi_transfer_one()
672 status = dln2_spi_rdwr(dln2, xfer->tx_buf, xfer->rx_buf, in dln2_spi_transfer_one()
675 dev_err(&dln2->pdev->dev, "write/read failed!\n"); in dln2_spi_transfer_one()
683 struct dln2_spi *dln2; in dln2_spi_probe() local
688 host = spi_alloc_host(&pdev->dev, sizeof(*dln2)); in dln2_spi_probe()
696 dln2 = spi_controller_get_devdata(host); in dln2_spi_probe()
698 dln2->buf = devm_kmalloc(&pdev->dev, DLN2_SPI_BUF_SIZE, GFP_KERNEL); in dln2_spi_probe()
699 if (!dln2->buf) { in dln2_spi_probe()
704 dln2->host = host; in dln2_spi_probe()
705 dln2->pdev = pdev; in dln2_spi_probe()
706 dln2->port = pdata->port; in dln2_spi_probe()
708 dln2->cs = 0xff; in dln2_spi_probe()
709 dln2->mode = 0xff; in dln2_spi_probe()
712 ret = dln2_spi_enable(dln2, false); in dln2_spi_probe()
718 ret = dln2_spi_get_cs_num(dln2, &host->num_chipselect); in dln2_spi_probe()
724 ret = dln2_spi_get_speed_range(dln2, in dln2_spi_probe()
732 ret = dln2_spi_get_supported_frame_sizes(dln2, in dln2_spi_probe()
739 ret = dln2_spi_cs_enable_all(dln2, true); in dln2_spi_probe()
752 ret = dln2_spi_enable(dln2, true); in dln2_spi_probe()
776 if (dln2_spi_enable(dln2, false) < 0) in dln2_spi_probe()
787 struct dln2_spi *dln2 = spi_controller_get_devdata(host); in dln2_spi_remove() local
791 if (dln2_spi_enable(dln2, false) < 0) in dln2_spi_remove()
800 struct dln2_spi *dln2 = spi_controller_get_devdata(host); in dln2_spi_suspend() local
807 ret = dln2_spi_enable(dln2, false); in dln2_spi_suspend()
816 dln2->cs = 0xff; in dln2_spi_suspend()
817 dln2->speed = 0; in dln2_spi_suspend()
818 dln2->bpw = 0; in dln2_spi_suspend()
819 dln2->mode = 0xff; in dln2_spi_suspend()
828 struct dln2_spi *dln2 = spi_controller_get_devdata(host); in dln2_spi_resume() local
831 ret = dln2_spi_cs_enable_all(dln2, true); in dln2_spi_resume()
835 ret = dln2_spi_enable(dln2, true); in dln2_spi_resume()
848 struct dln2_spi *dln2 = spi_controller_get_devdata(host); in dln2_spi_runtime_suspend() local
850 return dln2_spi_enable(dln2, false); in dln2_spi_runtime_suspend()
856 struct dln2_spi *dln2 = spi_controller_get_devdata(host); in dln2_spi_runtime_resume() local
858 return dln2_spi_enable(dln2, true); in dln2_spi_runtime_resume()