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 */
188 * registers via SPI is not really different conceptually than using
199 static int hi3110_spi_trans(struct spi_device *spi, int len) in hi3110_spi_trans() argument
201 struct hi3110_priv *priv = spi_get_drvdata(spi); in hi3110_spi_trans()
214 ret = spi_sync(spi, &m); in hi3110_spi_trans()
217 dev_err(&spi->dev, "spi transfer failed: ret = %d\n", ret); in hi3110_spi_trans()
221 static int hi3110_cmd(struct spi_device *spi, u8 command) in hi3110_cmd() argument
223 struct hi3110_priv *priv = spi_get_drvdata(spi); in hi3110_cmd()
226 dev_dbg(&spi->dev, "hi3110_cmd: %02X\n", command); in hi3110_cmd()
228 return hi3110_spi_trans(spi, 1); in hi3110_cmd()
231 static u8 hi3110_read(struct spi_device *spi, u8 command) in hi3110_read() argument
233 struct hi3110_priv *priv = spi_get_drvdata(spi); in hi3110_read()
237 hi3110_spi_trans(spi, 2); in hi3110_read()
243 static void hi3110_write(struct spi_device *spi, u8 reg, u8 val) in hi3110_write() argument
245 struct hi3110_priv *priv = spi_get_drvdata(spi); in hi3110_write()
249 hi3110_spi_trans(spi, 2); in hi3110_write()
252 static void hi3110_hw_tx_frame(struct spi_device *spi, u8 *buf, int len) in hi3110_hw_tx_frame() argument
254 struct hi3110_priv *priv = spi_get_drvdata(spi); in hi3110_hw_tx_frame()
258 hi3110_spi_trans(spi, len + 1); in hi3110_hw_tx_frame()
261 static void hi3110_hw_tx(struct spi_device *spi, struct can_frame *frame) in hi3110_hw_tx() argument
285 hi3110_hw_tx_frame(spi, buf, HI3110_TX_EXT_BUF_LEN - in hi3110_hw_tx()
299 hi3110_hw_tx_frame(spi, buf, HI3110_TX_STD_BUF_LEN - in hi3110_hw_tx()
304 static void hi3110_hw_rx_frame(struct spi_device *spi, u8 *buf) in hi3110_hw_rx_frame() argument
306 struct hi3110_priv *priv = spi_get_drvdata(spi); in hi3110_hw_rx_frame()
309 hi3110_spi_trans(spi, HI3110_RX_BUF_LEN); in hi3110_hw_rx_frame()
313 static void hi3110_hw_rx(struct spi_device *spi) in hi3110_hw_rx() argument
315 struct hi3110_priv *priv = spi_get_drvdata(spi); in hi3110_hw_rx()
326 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()
577 struct spi_device *spi = priv->spi; in hi3110_tx_work_handler() local
587 hi3110_hw_tx(spi, frame); in hi3110_tx_work_handler()
600 struct spi_device *spi = priv->spi; in hi3110_restart_work_handler() local
605 hi3110_hw_reset(spi); in hi3110_restart_work_handler()
608 hi3110_set_normal_mode(spi); in hi3110_restart_work_handler()
612 hi3110_set_normal_mode(spi); in hi3110_restart_work_handler()
615 hi3110_hw_sleep(spi); in hi3110_restart_work_handler()
623 hi3110_hw_reset(spi); in hi3110_restart_work_handler()
626 hi3110_set_normal_mode(spi); in hi3110_restart_work_handler()
635 struct spi_device *spi = priv->spi; in hi3110_can_ist() local
645 (statf = hi3110_read(spi, HI3110_READ_STATF)))) { in hi3110_can_ist()
646 hi3110_hw_rx(spi); in hi3110_can_ist()
649 intf = hi3110_read(spi, HI3110_READ_INTF); in hi3110_can_ist()
650 eflag = hi3110_read(spi, HI3110_READ_ERR); in hi3110_can_ist()
671 txerr = hi3110_read(spi, HI3110_READ_TEC); in hi3110_can_ist()
672 rxerr = hi3110_read(spi, HI3110_READ_REC); in hi3110_can_ist()
684 hi3110_hw_sleep(spi); in hi3110_can_ist()
716 cf->data[6] = hi3110_read(spi, HI3110_READ_TEC); in hi3110_can_ist()
717 cf->data[7] = hi3110_read(spi, HI3110_READ_REC); in hi3110_can_ist()
744 struct spi_device *spi = priv->spi; in hi3110_open() local
759 ret = request_threaded_irq(spi->irq, NULL, hi3110_can_ist, in hi3110_open()
762 dev_err(&spi->dev, "failed to acquire irq %d\n", spi->irq); in hi3110_open()
775 ret = hi3110_hw_reset(spi); in hi3110_open()
783 ret = hi3110_set_normal_mode(spi); in hi3110_open()
796 free_irq(spi->irq, priv); in hi3110_open()
797 hi3110_hw_sleep(spi); in hi3110_open()
827 MODULE_DEVICE_TABLE(spi, hi3110_id_table);
829 static int hi3110_can_probe(struct spi_device *spi) in hi3110_can_probe() argument
832 &spi->dev); in hi3110_can_probe()
838 clk = devm_clk_get(&spi->dev, NULL); in hi3110_can_probe()
840 dev_err(&spi->dev, "no CAN clock source defined\n"); in hi3110_can_probe()
876 priv->model = spi_get_device_id(spi)->driver_data; in hi3110_can_probe()
880 spi_set_drvdata(spi, priv); in hi3110_can_probe()
882 /* Configure the SPI bus */ in hi3110_can_probe()
883 spi->bits_per_word = 8; in hi3110_can_probe()
884 ret = spi_setup(spi); in hi3110_can_probe()
888 priv->power = devm_regulator_get_optional(&spi->dev, "vdd"); in hi3110_can_probe()
889 priv->transceiver = devm_regulator_get_optional(&spi->dev, "xceiver"); in hi3110_can_probe()
900 priv->spi = spi; in hi3110_can_probe()
903 priv->spi_tx_buf = devm_kzalloc(&spi->dev, HI3110_RX_BUF_LEN, in hi3110_can_probe()
909 priv->spi_rx_buf = devm_kzalloc(&spi->dev, HI3110_RX_BUF_LEN, in hi3110_can_probe()
917 SET_NETDEV_DEV(net, &spi->dev); in hi3110_can_probe()
919 ret = hi3110_hw_probe(spi); in hi3110_can_probe()
922 dev_err(&spi->dev, "Cannot initialize %x. Wrong wiring?\n", in hi3110_can_probe()
926 hi3110_hw_sleep(spi); in hi3110_can_probe()
947 dev_err(&spi->dev, "Probe failed, err=%d\n", -ret); in hi3110_can_probe()
951 static int hi3110_can_remove(struct spi_device *spi) in hi3110_can_remove() argument
953 struct hi3110_priv *priv = spi_get_drvdata(spi); in hi3110_can_remove()
970 struct spi_device *spi = to_spi_device(dev); in hi3110_can_suspend() local
971 struct hi3110_priv *priv = spi_get_drvdata(spi); in hi3110_can_suspend()
975 disable_irq(spi->irq); in hi3110_can_suspend()
983 hi3110_hw_sleep(spi); in hi3110_can_suspend()
1000 struct spi_device *spi = to_spi_device(dev); in hi3110_can_resume() local
1001 struct hi3110_priv *priv = spi_get_drvdata(spi); in hi3110_can_resume()
1014 enable_irq(spi->irq); in hi3110_can_resume()