Lines Matching +full:- +full:spi

1 // SPDX-License-Identifier: GPL-2.0-only
2 /* CAN bus driver for Holt HI3110 CAN Controller with SPI Interface
12 * - Sascha Hauer, Marc Kleine-Budde, Pengutronix
13 * - Simon Kallweit, intefo AG
35 #include <linux/spi/spi.h>
147 struct spi_device *spi; member
150 struct mutex hi3110_lock; /* SPI device lock */
178 if (priv->tx_skb || priv->tx_len) in hi3110_clean()
179 net->stats.tx_errors++; in hi3110_clean()
180 dev_kfree_skb(priv->tx_skb); in hi3110_clean()
181 if (priv->tx_len) in hi3110_clean()
182 can_free_echo_skb(priv->net, 0); in hi3110_clean()
183 priv->tx_skb = NULL; in hi3110_clean()
184 priv->tx_len = 0; in hi3110_clean()
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()
203 .tx_buf = priv->spi_tx_buf, in hi3110_spi_trans()
204 .rx_buf = priv->spi_rx_buf, 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 u8 hi3110_cmd(struct spi_device *spi, u8 command) in hi3110_cmd() argument
223 struct hi3110_priv *priv = spi_get_drvdata(spi); in hi3110_cmd()
225 priv->spi_tx_buf[0] = command; 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()
236 priv->spi_tx_buf[0] = command; in hi3110_read()
237 hi3110_spi_trans(spi, 2); in hi3110_read()
238 val = priv->spi_rx_buf[1]; 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()
247 priv->spi_tx_buf[0] = reg; in hi3110_write()
248 priv->spi_tx_buf[1] = val; 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()
256 priv->spi_tx_buf[0] = HI3110_WRITE_FIFO; in hi3110_hw_tx_frame()
257 memcpy(priv->spi_tx_buf + 1, buf, len); 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
267 if (frame->can_id & CAN_EFF_FLAG) { in hi3110_hw_tx()
269 buf[HI3110_FIFO_ID_OFF] = (frame->can_id & CAN_EFF_MASK) >> 21; in hi3110_hw_tx()
271 (((frame->can_id & CAN_EFF_MASK) >> 13) & 0xe0) | in hi3110_hw_tx()
273 (((frame->can_id & CAN_EFF_MASK) >> 15) & 0x07); in hi3110_hw_tx()
275 (frame->can_id & CAN_EFF_MASK) >> 7; in hi3110_hw_tx()
277 ((frame->can_id & CAN_EFF_MASK) << 1) | in hi3110_hw_tx()
278 ((frame->can_id & CAN_RTR_FLAG) ? 1 : 0); in hi3110_hw_tx()
280 buf[HI3110_FIFO_EXT_DLC_OFF] = frame->can_dlc; in hi3110_hw_tx()
283 frame->data, frame->can_dlc); in hi3110_hw_tx()
285 hi3110_hw_tx_frame(spi, buf, HI3110_TX_EXT_BUF_LEN - in hi3110_hw_tx()
286 (HI3110_CAN_MAX_DATA_LEN - frame->can_dlc)); in hi3110_hw_tx()
289 buf[HI3110_FIFO_ID_OFF] = (frame->can_id & CAN_SFF_MASK) >> 3; in hi3110_hw_tx()
291 ((frame->can_id & CAN_SFF_MASK) << 5) | in hi3110_hw_tx()
292 ((frame->can_id & CAN_RTR_FLAG) ? (1 << 4) : 0); in hi3110_hw_tx()
294 buf[HI3110_FIFO_STD_DLC_OFF] = frame->can_dlc; in hi3110_hw_tx()
297 frame->data, frame->can_dlc); in hi3110_hw_tx()
299 hi3110_hw_tx_frame(spi, buf, HI3110_TX_STD_BUF_LEN - in hi3110_hw_tx()
300 (HI3110_CAN_MAX_DATA_LEN - frame->can_dlc)); 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()
308 priv->spi_tx_buf[0] = HI3110_READ_FIFO_WOTIME; in hi3110_hw_rx_frame()
309 hi3110_spi_trans(spi, HI3110_RX_BUF_LEN); in hi3110_hw_rx_frame()
310 memcpy(buf, priv->spi_rx_buf + 1, HI3110_RX_BUF_LEN - 1); 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()
318 u8 buf[HI3110_RX_BUF_LEN - 1]; in hi3110_hw_rx()
320 skb = alloc_can_skb(priv->net, &frame); in hi3110_hw_rx()
322 priv->net->stats.rx_dropped++; in hi3110_hw_rx()
326 hi3110_hw_rx_frame(spi, buf); in hi3110_hw_rx()
328 /* IDE is recessive (1), indicating extended 29-bit frame */ in hi3110_hw_rx()
329 frame->can_id = CAN_EFF_FLAG; in hi3110_hw_rx()
330 frame->can_id |= in hi3110_hw_rx()
337 /* IDE is dominant (0), frame indicating standard 11-bit */ in hi3110_hw_rx()
338 frame->can_id = in hi3110_hw_rx()
344 frame->can_dlc = get_can_dlc(buf[HI3110_FIFO_WOTIME_DLC_OFF] & 0x0F); in hi3110_hw_rx()
347 frame->can_id |= CAN_RTR_FLAG; in hi3110_hw_rx()
349 memcpy(frame->data, buf + HI3110_FIFO_WOTIME_DAT_OFF, in hi3110_hw_rx()
350 frame->can_dlc); in hi3110_hw_rx()
352 priv->net->stats.rx_packets++; in hi3110_hw_rx()
353 priv->net->stats.rx_bytes += frame->can_dlc; in hi3110_hw_rx()
355 can_led_event(priv->net, CAN_LED_EVENT_RX); 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
371 if (priv->tx_skb || priv->tx_len) { in hi3110_hard_start_xmit()
372 dev_err(&spi->dev, "hard_xmit called while tx busy\n"); in hi3110_hard_start_xmit()
380 priv->tx_skb = skb; in hi3110_hard_start_xmit()
381 queue_work(priv->wq, &priv->tx_work); in hi3110_hard_start_xmit()
393 /* We have to delay work since SPI I/O may sleep */ in hi3110_do_set_mode()
394 priv->can.state = CAN_STATE_ERROR_ACTIVE; in hi3110_do_set_mode()
395 priv->restart_tx = 1; in hi3110_do_set_mode()
396 if (priv->can.restart_ms == 0) in hi3110_do_set_mode()
397 priv->after_suspend = HI3110_AFTER_SUSPEND_RESTART; in hi3110_do_set_mode()
398 queue_work(priv->wq, &priv->restart_work); in hi3110_do_set_mode()
401 return -EOPNOTSUPP; in hi3110_do_set_mode()
411 struct spi_device *spi = priv->spi; in hi3110_get_berr_counter() local
413 mutex_lock(&priv->hi3110_lock); in hi3110_get_berr_counter()
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()
416 mutex_unlock(&priv->hi3110_lock); 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()
432 if (priv->can.ctrlmode & CAN_CTRLMODE_LOOPBACK) in hi3110_set_normal_mode()
434 else if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) 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()
445 return -EBUSY; in hi3110_set_normal_mode()
447 priv->can.state = CAN_STATE_ERROR_ACTIVE; in hi3110_set_normal_mode()
454 struct can_bittiming *bt = &priv->can.bittiming; in hi3110_do_set_bittiming()
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()
458 ((bt->sjw - 1) << HI3110_BTR0_SJW_SHIFT) | in hi3110_do_set_bittiming()
459 ((bt->brp - 1) << HI3110_BTR0_BRP_SHIFT)); in hi3110_do_set_bittiming()
461 hi3110_write(spi, HI3110_WRITE_BTR1, in hi3110_do_set_bittiming()
462 (priv->can.ctrlmode & in hi3110_do_set_bittiming()
465 ((bt->phase_seg1 + bt->prop_seg - 1) in hi3110_do_set_bittiming()
467 ((bt->phase_seg2 - 1) << HI3110_BTR1_TSEG2_SHIFT)); 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()
499 return -ENODEV; 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()
523 return -ENODEV; in hi3110_hw_probe()
542 struct spi_device *spi = priv->spi; in hi3110_stop() local
546 priv->force_quit = 1; in hi3110_stop()
547 free_irq(spi->irq, priv); in hi3110_stop()
548 destroy_workqueue(priv->wq); in hi3110_stop()
549 priv->wq = NULL; in hi3110_stop()
551 mutex_lock(&priv->hi3110_lock); 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()
562 hi3110_power_enable(priv->transceiver, 0); in hi3110_stop()
564 priv->can.state = CAN_STATE_STOPPED; in hi3110_stop()
566 mutex_unlock(&priv->hi3110_lock); in hi3110_stop()
577 struct spi_device *spi = priv->spi; in hi3110_tx_work_handler() local
578 struct net_device *net = priv->net; in hi3110_tx_work_handler()
581 mutex_lock(&priv->hi3110_lock); in hi3110_tx_work_handler()
582 if (priv->tx_skb) { in hi3110_tx_work_handler()
583 if (priv->can.state == CAN_STATE_BUS_OFF) { in hi3110_tx_work_handler()
586 frame = (struct can_frame *)priv->tx_skb->data; in hi3110_tx_work_handler()
587 hi3110_hw_tx(spi, frame); in hi3110_tx_work_handler()
588 priv->tx_len = 1 + frame->can_dlc; in hi3110_tx_work_handler()
589 can_put_echo_skb(priv->tx_skb, net, 0); in hi3110_tx_work_handler()
590 priv->tx_skb = NULL; in hi3110_tx_work_handler()
593 mutex_unlock(&priv->hi3110_lock); in hi3110_tx_work_handler()
600 struct spi_device *spi = priv->spi; in hi3110_restart_work_handler() local
601 struct net_device *net = priv->net; in hi3110_restart_work_handler()
603 mutex_lock(&priv->hi3110_lock); in hi3110_restart_work_handler()
604 if (priv->after_suspend) { in hi3110_restart_work_handler()
605 hi3110_hw_reset(spi); in hi3110_restart_work_handler()
607 if (priv->after_suspend & HI3110_AFTER_SUSPEND_RESTART) { in hi3110_restart_work_handler()
608 hi3110_set_normal_mode(spi); in hi3110_restart_work_handler()
609 } else if (priv->after_suspend & HI3110_AFTER_SUSPEND_UP) { 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()
617 priv->after_suspend = 0; in hi3110_restart_work_handler()
618 priv->force_quit = 0; in hi3110_restart_work_handler()
621 if (priv->restart_tx) { in hi3110_restart_work_handler()
622 priv->restart_tx = 0; 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()
629 mutex_unlock(&priv->hi3110_lock); in hi3110_restart_work_handler()
635 struct spi_device *spi = priv->spi; in hi3110_can_ist() local
636 struct net_device *net = priv->net; in hi3110_can_ist()
638 mutex_lock(&priv->hi3110_lock); in hi3110_can_ist()
640 while (!priv->force_quit) { in hi3110_can_ist()
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()
661 if (new_state != priv->can.state) { 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()
673 cf->data[6] = txerr; in hi3110_can_ist()
674 cf->data[7] = rxerr; in hi3110_can_ist()
682 if (priv->can.restart_ms == 0) { in hi3110_can_ist()
683 priv->force_quit = 1; in hi3110_can_ist()
684 hi3110_hw_sleep(spi); in hi3110_can_ist()
692 (priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING)) { in hi3110_can_ist()
702 cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR; in hi3110_can_ist()
703 priv->can.can_stats.bus_error++; in hi3110_can_ist()
704 priv->net->stats.rx_errors++; in hi3110_can_ist()
706 cf->data[2] |= CAN_ERR_PROT_BIT; in hi3110_can_ist()
708 cf->data[2] |= CAN_ERR_PROT_FORM; in hi3110_can_ist()
710 cf->data[2] |= CAN_ERR_PROT_STUFF; in hi3110_can_ist()
712 cf->data[3] |= CAN_ERR_PROT_LOC_CRC_SEQ; in hi3110_can_ist()
714 cf->data[3] |= CAN_ERR_PROT_LOC_ACK; 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()
718 netdev_dbg(priv->net, "Bus Error\n"); in hi3110_can_ist()
723 if (priv->tx_len && statf & HI3110_STAT_TXMTY) { in hi3110_can_ist()
724 net->stats.tx_packets++; in hi3110_can_ist()
725 net->stats.tx_bytes += priv->tx_len - 1; in hi3110_can_ist()
727 if (priv->tx_len) { in hi3110_can_ist()
729 priv->tx_len = 0; in hi3110_can_ist()
737 mutex_unlock(&priv->hi3110_lock); in hi3110_can_ist()
744 struct spi_device *spi = priv->spi; in hi3110_open() local
752 mutex_lock(&priv->hi3110_lock); in hi3110_open()
753 hi3110_power_enable(priv->transceiver, 1); in hi3110_open()
755 priv->force_quit = 0; in hi3110_open()
756 priv->tx_skb = NULL; in hi3110_open()
757 priv->tx_len = 0; in hi3110_open()
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()
766 priv->wq = alloc_workqueue("hi3110_wq", WQ_FREEZABLE | WQ_MEM_RECLAIM, in hi3110_open()
768 if (!priv->wq) { in hi3110_open()
769 ret = -ENOMEM; in hi3110_open()
772 INIT_WORK(&priv->tx_work, hi3110_tx_work_handler); in hi3110_open()
773 INIT_WORK(&priv->restart_work, hi3110_restart_work_handler); in hi3110_open()
775 ret = hi3110_hw_reset(spi); in hi3110_open()
783 ret = hi3110_set_normal_mode(spi); in hi3110_open()
789 mutex_unlock(&priv->hi3110_lock); in hi3110_open()
794 destroy_workqueue(priv->wq); in hi3110_open()
796 free_irq(spi->irq, priv); in hi3110_open()
797 hi3110_hw_sleep(spi); in hi3110_open()
799 hi3110_power_enable(priv->transceiver, 0); in hi3110_open()
801 mutex_unlock(&priv->hi3110_lock); 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()
847 return -ERANGE; in hi3110_can_probe()
852 return -ENOMEM; in hi3110_can_probe()
860 net->netdev_ops = &hi3110_netdev_ops; in hi3110_can_probe()
861 net->flags |= IFF_ECHO; in hi3110_can_probe()
864 priv->can.bittiming_const = &hi3110_bittiming_const; in hi3110_can_probe()
865 priv->can.do_set_mode = hi3110_do_set_mode; in hi3110_can_probe()
866 priv->can.do_get_berr_counter = hi3110_get_berr_counter; in hi3110_can_probe()
867 priv->can.clock.freq = freq / 2; in hi3110_can_probe()
868 priv->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES | in hi3110_can_probe()
874 priv->model = (enum hi3110_model)of_id->data; in hi3110_can_probe()
876 priv->model = spi_get_device_id(spi)->driver_data; in hi3110_can_probe()
877 priv->net = net; in hi3110_can_probe()
878 priv->clk = clk; 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()
890 if ((PTR_ERR(priv->power) == -EPROBE_DEFER) || in hi3110_can_probe()
891 (PTR_ERR(priv->transceiver) == -EPROBE_DEFER)) { in hi3110_can_probe()
892 ret = -EPROBE_DEFER; in hi3110_can_probe()
896 ret = hi3110_power_enable(priv->power, 1); in hi3110_can_probe()
900 priv->spi = spi; in hi3110_can_probe()
901 mutex_init(&priv->hi3110_lock); in hi3110_can_probe()
903 priv->spi_tx_buf = devm_kzalloc(&spi->dev, HI3110_RX_BUF_LEN, in hi3110_can_probe()
905 if (!priv->spi_tx_buf) { in hi3110_can_probe()
906 ret = -ENOMEM; in hi3110_can_probe()
909 priv->spi_rx_buf = devm_kzalloc(&spi->dev, HI3110_RX_BUF_LEN, in hi3110_can_probe()
912 if (!priv->spi_rx_buf) { in hi3110_can_probe()
913 ret = -ENOMEM; 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()
921 if (ret == -ENODEV) in hi3110_can_probe()
922 dev_err(&spi->dev, "Cannot initialize %x. Wrong wiring?\n", in hi3110_can_probe()
923 priv->model); in hi3110_can_probe()
926 hi3110_hw_sleep(spi); in hi3110_can_probe()
933 netdev_info(net, "%x successfully initialized.\n", priv->model); in hi3110_can_probe()
938 hi3110_power_enable(priv->power, 0); 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()
954 struct net_device *net = priv->net; in hi3110_can_remove()
958 hi3110_power_enable(priv->power, 0); in hi3110_can_remove()
960 if (!IS_ERR(priv->clk)) in hi3110_can_remove()
961 clk_disable_unprepare(priv->clk); 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()
972 struct net_device *net = priv->net; in hi3110_can_suspend()
974 priv->force_quit = 1; in hi3110_can_suspend()
975 disable_irq(spi->irq); in hi3110_can_suspend()
983 hi3110_hw_sleep(spi); in hi3110_can_suspend()
984 hi3110_power_enable(priv->transceiver, 0); in hi3110_can_suspend()
985 priv->after_suspend = HI3110_AFTER_SUSPEND_UP; in hi3110_can_suspend()
987 priv->after_suspend = HI3110_AFTER_SUSPEND_DOWN; in hi3110_can_suspend()
990 if (!IS_ERR_OR_NULL(priv->power)) { in hi3110_can_suspend()
991 regulator_disable(priv->power); in hi3110_can_suspend()
992 priv->after_suspend |= HI3110_AFTER_SUSPEND_POWER; 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()
1003 if (priv->after_suspend & HI3110_AFTER_SUSPEND_POWER) in hi3110_can_resume()
1004 hi3110_power_enable(priv->power, 1); in hi3110_can_resume()
1006 if (priv->after_suspend & HI3110_AFTER_SUSPEND_UP) { in hi3110_can_resume()
1007 hi3110_power_enable(priv->transceiver, 1); in hi3110_can_resume()
1008 queue_work(priv->wq, &priv->restart_work); in hi3110_can_resume()
1010 priv->after_suspend = 0; in hi3110_can_resume()
1013 priv->force_quit = 0; in hi3110_can_resume()
1014 enable_irq(spi->irq); in hi3110_can_resume()
1035 MODULE_DESCRIPTION("Holt HI-3110 CAN driver");