Lines Matching full:spi

2 /* CAN bus driver for Holt HI3110 CAN Controller with SPI Interface
35 #include <linux/spi/spi.h>
147 struct spi_device *spi; member
150 struct mutex hi3110_lock; /* SPI device lock */
189 * registers via SPI is not really different conceptually than using
200 static int hi3110_spi_trans(struct spi_device *spi, int len) in hi3110_spi_trans() argument
202 struct hi3110_priv *priv = spi_get_drvdata(spi); in hi3110_spi_trans()
215 ret = spi_sync(spi, &m); in hi3110_spi_trans()
218 dev_err(&spi->dev, "spi transfer failed: ret = %d\n", ret); in hi3110_spi_trans()
222 static int hi3110_cmd(struct spi_device *spi, u8 command) in hi3110_cmd() argument
224 struct hi3110_priv *priv = spi_get_drvdata(spi); in hi3110_cmd()
227 dev_dbg(&spi->dev, "hi3110_cmd: %02X\n", command); in hi3110_cmd()
229 return hi3110_spi_trans(spi, 1); in hi3110_cmd()
232 static u8 hi3110_read(struct spi_device *spi, u8 command) in hi3110_read() argument
234 struct hi3110_priv *priv = spi_get_drvdata(spi); in hi3110_read()
238 hi3110_spi_trans(spi, 2); in hi3110_read()
244 static void hi3110_write(struct spi_device *spi, u8 reg, u8 val) in hi3110_write() argument
246 struct hi3110_priv *priv = spi_get_drvdata(spi); in hi3110_write()
250 hi3110_spi_trans(spi, 2); in hi3110_write()
253 static void hi3110_hw_tx_frame(struct spi_device *spi, u8 *buf, int len) in hi3110_hw_tx_frame() argument
255 struct hi3110_priv *priv = spi_get_drvdata(spi); in hi3110_hw_tx_frame()
259 hi3110_spi_trans(spi, len + 1); in hi3110_hw_tx_frame()
262 static void hi3110_hw_tx(struct spi_device *spi, struct can_frame *frame) in hi3110_hw_tx() argument
286 hi3110_hw_tx_frame(spi, buf, HI3110_TX_EXT_BUF_LEN - in hi3110_hw_tx()
300 hi3110_hw_tx_frame(spi, buf, HI3110_TX_STD_BUF_LEN - in hi3110_hw_tx()
305 static void hi3110_hw_rx_frame(struct spi_device *spi, u8 *buf) in hi3110_hw_rx_frame() argument
307 struct hi3110_priv *priv = spi_get_drvdata(spi); in hi3110_hw_rx_frame()
310 hi3110_spi_trans(spi, HI3110_RX_BUF_LEN); in hi3110_hw_rx_frame()
314 static void hi3110_hw_rx(struct spi_device *spi) in hi3110_hw_rx() argument
316 struct hi3110_priv *priv = spi_get_drvdata(spi); in hi3110_hw_rx()
327 hi3110_hw_rx_frame(spi, buf); in hi3110_hw_rx()
360 static void hi3110_hw_sleep(struct spi_device *spi) in hi3110_hw_sleep() argument
362 hi3110_write(spi, HI3110_WRITE_CTRL0, HI3110_CTRL0_SLEEP_MODE); in hi3110_hw_sleep()
369 struct spi_device *spi = priv->spi; in hi3110_hard_start_xmit() local
372 dev_err(&spi->dev, "hard_xmit called while tx busy\n"); in hi3110_hard_start_xmit()
393 /* We have to delay work since SPI I/O may sleep */ in hi3110_do_set_mode()
411 struct spi_device *spi = priv->spi; in hi3110_get_berr_counter() local
414 bec->txerr = hi3110_read(spi, HI3110_READ_TEC); in hi3110_get_berr_counter()
415 bec->rxerr = hi3110_read(spi, HI3110_READ_REC); in hi3110_get_berr_counter()
421 static int hi3110_set_normal_mode(struct spi_device *spi) in hi3110_set_normal_mode() argument
423 struct hi3110_priv *priv = spi_get_drvdata(spi); in hi3110_set_normal_mode()
426 hi3110_write(spi, HI3110_WRITE_INTE, HI3110_INT_BUSERR | in hi3110_set_normal_mode()
430 hi3110_write(spi, HI3110_WRITE_CTRL1, HI3110_CTRL1_TXEN); in hi3110_set_normal_mode()
439 hi3110_write(spi, HI3110_WRITE_CTRL0, reg); in hi3110_set_normal_mode()
443 reg = hi3110_read(spi, HI3110_READ_CTRL0); in hi3110_set_normal_mode()
455 struct spi_device *spi = priv->spi; in hi3110_do_set_bittiming() local
457 hi3110_write(spi, HI3110_WRITE_BTR0, in hi3110_do_set_bittiming()
461 hi3110_write(spi, HI3110_WRITE_BTR1, in hi3110_do_set_bittiming()
469 dev_dbg(&spi->dev, "BT: 0x%02x 0x%02x\n", in hi3110_do_set_bittiming()
470 hi3110_read(spi, HI3110_READ_BTR0), in hi3110_do_set_bittiming()
471 hi3110_read(spi, HI3110_READ_BTR1)); in hi3110_do_set_bittiming()
482 static int hi3110_hw_reset(struct spi_device *spi) in hi3110_hw_reset() argument
490 ret = hi3110_cmd(spi, HI3110_MASTER_RESET); in hi3110_hw_reset()
497 reg = hi3110_read(spi, HI3110_READ_CTRL0); in hi3110_hw_reset()
504 hi3110_read(spi, HI3110_READ_ERR); in hi3110_hw_reset()
509 static int hi3110_hw_probe(struct spi_device *spi) in hi3110_hw_probe() argument
513 hi3110_hw_reset(spi); in hi3110_hw_probe()
518 statf = hi3110_read(spi, HI3110_READ_STATF); in hi3110_hw_probe()
520 dev_dbg(&spi->dev, "statf: %02X\n", statf); in hi3110_hw_probe()
542 struct spi_device *spi = priv->spi; in hi3110_stop() local
547 free_irq(spi->irq, priv); in hi3110_stop()
554 hi3110_write(spi, HI3110_WRITE_CTRL1, 0x0); in hi3110_stop()
555 hi3110_write(spi, HI3110_WRITE_INTE, 0x0); in hi3110_stop()
556 hi3110_read(spi, HI3110_READ_INTF); in hi3110_stop()
560 hi3110_hw_sleep(spi); in hi3110_stop()
575 struct spi_device *spi = priv->spi; in hi3110_tx_work_handler() local
585 hi3110_hw_tx(spi, frame); in hi3110_tx_work_handler()
598 struct spi_device *spi = priv->spi; in hi3110_restart_work_handler() local
603 hi3110_hw_reset(spi); in hi3110_restart_work_handler()
606 hi3110_set_normal_mode(spi); in hi3110_restart_work_handler()
610 hi3110_set_normal_mode(spi); in hi3110_restart_work_handler()
613 hi3110_hw_sleep(spi); in hi3110_restart_work_handler()
621 hi3110_hw_reset(spi); in hi3110_restart_work_handler()
624 hi3110_set_normal_mode(spi); in hi3110_restart_work_handler()
633 struct spi_device *spi = priv->spi; in hi3110_can_ist() local
643 (statf = hi3110_read(spi, HI3110_READ_STATF)))) { in hi3110_can_ist()
644 hi3110_hw_rx(spi); in hi3110_can_ist()
647 intf = hi3110_read(spi, HI3110_READ_INTF); in hi3110_can_ist()
648 eflag = hi3110_read(spi, HI3110_READ_ERR); in hi3110_can_ist()
669 txerr = hi3110_read(spi, HI3110_READ_TEC); in hi3110_can_ist()
670 rxerr = hi3110_read(spi, HI3110_READ_REC); in hi3110_can_ist()
680 hi3110_hw_sleep(spi); in hi3110_can_ist()
728 cf->data[6] = hi3110_read(spi, HI3110_READ_TEC); in hi3110_can_ist()
729 cf->data[7] = hi3110_read(spi, HI3110_READ_REC); in hi3110_can_ist()
752 struct spi_device *spi = priv->spi; in hi3110_open() local
767 ret = request_threaded_irq(spi->irq, NULL, hi3110_can_ist, in hi3110_open()
770 dev_err(&spi->dev, "failed to acquire irq %d\n", spi->irq); in hi3110_open()
783 ret = hi3110_hw_reset(spi); in hi3110_open()
791 ret = hi3110_set_normal_mode(spi); in hi3110_open()
803 free_irq(spi->irq, priv); in hi3110_open()
804 hi3110_hw_sleep(spi); in hi3110_open()
838 MODULE_DEVICE_TABLE(spi, hi3110_id_table);
840 static int hi3110_can_probe(struct spi_device *spi) in hi3110_can_probe() argument
842 struct device *dev = &spi->dev; in hi3110_can_probe()
850 clk = devm_clk_get_optional(&spi->dev, NULL); in hi3110_can_probe()
893 priv->model = spi_get_device_id(spi)->driver_data; in hi3110_can_probe()
897 spi_set_drvdata(spi, priv); in hi3110_can_probe()
899 /* Configure the SPI bus */ in hi3110_can_probe()
900 spi->bits_per_word = 8; in hi3110_can_probe()
901 ret = spi_setup(spi); in hi3110_can_probe()
905 priv->power = devm_regulator_get_optional(&spi->dev, "vdd"); in hi3110_can_probe()
906 priv->transceiver = devm_regulator_get_optional(&spi->dev, "xceiver"); in hi3110_can_probe()
917 priv->spi = spi; in hi3110_can_probe()
920 priv->spi_tx_buf = devm_kzalloc(&spi->dev, HI3110_RX_BUF_LEN, in hi3110_can_probe()
926 priv->spi_rx_buf = devm_kzalloc(&spi->dev, HI3110_RX_BUF_LEN, in hi3110_can_probe()
934 SET_NETDEV_DEV(net, &spi->dev); in hi3110_can_probe()
936 ret = hi3110_hw_probe(spi); in hi3110_can_probe()
941 hi3110_hw_sleep(spi); in hi3110_can_probe()
963 static void hi3110_can_remove(struct spi_device *spi) in hi3110_can_remove() argument
965 struct hi3110_priv *priv = spi_get_drvdata(spi); in hi3110_can_remove()
979 struct spi_device *spi = to_spi_device(dev); in hi3110_can_suspend() local
980 struct hi3110_priv *priv = spi_get_drvdata(spi); in hi3110_can_suspend()
984 disable_irq(spi->irq); in hi3110_can_suspend()
992 hi3110_hw_sleep(spi); in hi3110_can_suspend()
1009 struct spi_device *spi = to_spi_device(dev); in hi3110_can_resume() local
1010 struct hi3110_priv *priv = spi_get_drvdata(spi); in hi3110_can_resume()
1023 enable_irq(spi->irq); in hi3110_can_resume()