Lines Matching refs:tp

99 	struct vsc_tp *tp = data;  in vsc_tp_isr()  local
101 atomic_inc(&tp->assert_cnt); in vsc_tp_isr()
103 wake_up(&tp->xfer_wait); in vsc_tp_isr()
110 struct vsc_tp *tp = data; in vsc_tp_thread_isr() local
112 if (tp->event_notify) in vsc_tp_thread_isr()
113 tp->event_notify(tp->event_notify_context); in vsc_tp_thread_isr()
119 static int vsc_tp_wakeup_request(struct vsc_tp *tp) in vsc_tp_wakeup_request() argument
123 gpiod_set_value_cansleep(tp->wakeupfw, 0); in vsc_tp_wakeup_request()
125 ret = wait_event_timeout(tp->xfer_wait, in vsc_tp_wakeup_request()
126 atomic_read(&tp->assert_cnt), in vsc_tp_wakeup_request()
134 tp->wakeuphost); in vsc_tp_wakeup_request()
137 static void vsc_tp_wakeup_release(struct vsc_tp *tp) in vsc_tp_wakeup_release() argument
139 atomic_dec_if_positive(&tp->assert_cnt); in vsc_tp_wakeup_release()
141 gpiod_set_value_cansleep(tp->wakeupfw, 1); in vsc_tp_wakeup_release()
144 static int vsc_tp_dev_xfer(struct vsc_tp *tp, void *obuf, void *ibuf, size_t len) in vsc_tp_dev_xfer() argument
155 return spi_sync_locked(tp->spi, &msg); in vsc_tp_dev_xfer()
158 static int vsc_tp_xfer_helper(struct vsc_tp *tp, struct vsc_tp_packet *pkt, in vsc_tp_xfer_helper() argument
163 u8 *src, *crc_src, *rx_buf = tp->rx_buf; in vsc_tp_xfer_helper()
171 ret = vsc_tp_dev_xfer(tp, pkt, rx_buf, next_xfer_len); in vsc_tp_xfer_helper()
246 if (~recv_crc != crc || le32_to_cpu(ack.seq) != tp->seq) { in vsc_tp_xfer_helper()
247 dev_err(&tp->spi->dev, "recv crc or seq error\n"); in vsc_tp_xfer_helper()
253 dev_err(&tp->spi->dev, "recv cmd ack error\n"); in vsc_tp_xfer_helper()
271 int vsc_tp_xfer(struct vsc_tp *tp, u8 cmd, const void *obuf, size_t olen, in vsc_tp_xfer() argument
274 struct vsc_tp_packet *pkt = tp->tx_buf; in vsc_tp_xfer()
281 guard(mutex)(&tp->mutex); in vsc_tp_xfer()
286 pkt->seq = cpu_to_le32(++tp->seq); in vsc_tp_xfer()
292 ret = vsc_tp_wakeup_request(tp); in vsc_tp_xfer()
294 dev_err(&tp->spi->dev, "wakeup firmware failed ret: %d\n", ret); in vsc_tp_xfer()
296 ret = vsc_tp_xfer_helper(tp, pkt, ibuf, ilen); in vsc_tp_xfer()
298 vsc_tp_wakeup_release(tp); in vsc_tp_xfer()
312 int vsc_tp_rom_xfer(struct vsc_tp *tp, const void *obuf, void *ibuf, size_t len) in vsc_tp_rom_xfer() argument
320 guard(mutex)(&tp->mutex); in vsc_tp_rom_xfer()
323 cpu_to_be32_array(tp->tx_buf, obuf, words); in vsc_tp_rom_xfer()
328 tp->wakeuphost); in vsc_tp_rom_xfer()
330 dev_err(&tp->spi->dev, "wait rom failed ret: %d\n", ret); in vsc_tp_rom_xfer()
334 ret = vsc_tp_dev_xfer(tp, tp->tx_buf, ibuf ? tp->rx_buf : NULL, len); in vsc_tp_rom_xfer()
339 be32_to_cpu_array(ibuf, tp->rx_buf, words); in vsc_tp_rom_xfer()
348 void vsc_tp_reset(struct vsc_tp *tp) in vsc_tp_reset() argument
350 disable_irq(tp->spi->irq); in vsc_tp_reset()
353 gpiod_set_value_cansleep(tp->resetfw, 0); in vsc_tp_reset()
355 gpiod_set_value_cansleep(tp->resetfw, 1); in vsc_tp_reset()
364 gpiod_set_value_cansleep(tp->wakeupfw, 1); in vsc_tp_reset()
366 atomic_set(&tp->assert_cnt, 0); in vsc_tp_reset()
368 enable_irq(tp->spi->irq); in vsc_tp_reset()
377 bool vsc_tp_need_read(struct vsc_tp *tp) in vsc_tp_need_read() argument
379 if (!atomic_read(&tp->assert_cnt)) in vsc_tp_need_read()
381 if (!gpiod_get_value_cansleep(tp->wakeuphost)) in vsc_tp_need_read()
383 if (!gpiod_get_value_cansleep(tp->wakeupfw)) in vsc_tp_need_read()
397 int vsc_tp_register_event_cb(struct vsc_tp *tp, vsc_tp_event_cb_t event_cb, in vsc_tp_register_event_cb() argument
400 tp->event_notify = event_cb; in vsc_tp_register_event_cb()
401 tp->event_notify_context = context; in vsc_tp_register_event_cb()
411 int vsc_tp_request_irq(struct vsc_tp *tp) in vsc_tp_request_irq() argument
413 struct spi_device *spi = tp->spi; in vsc_tp_request_irq()
420 dev_name(dev), tp); in vsc_tp_request_irq()
432 void vsc_tp_free_irq(struct vsc_tp *tp) in vsc_tp_free_irq() argument
434 free_irq(tp->spi->irq, tp); in vsc_tp_free_irq()
442 void vsc_tp_intr_synchronize(struct vsc_tp *tp) in vsc_tp_intr_synchronize() argument
444 synchronize_irq(tp->spi->irq); in vsc_tp_intr_synchronize()
452 void vsc_tp_intr_enable(struct vsc_tp *tp) in vsc_tp_intr_enable() argument
454 enable_irq(tp->spi->irq); in vsc_tp_intr_enable()
462 void vsc_tp_intr_disable(struct vsc_tp *tp) in vsc_tp_intr_disable() argument
464 disable_irq(tp->spi->irq); in vsc_tp_intr_disable()
479 struct vsc_tp *tp; in vsc_tp_probe() local
482 .data = &tp, in vsc_tp_probe()
483 .size_data = sizeof(tp), in vsc_tp_probe()
491 tp = devm_kzalloc(dev, sizeof(*tp), GFP_KERNEL); in vsc_tp_probe()
492 if (!tp) in vsc_tp_probe()
495 tp->tx_buf = devm_kzalloc(dev, VSC_TP_MAX_XFER_SIZE, GFP_KERNEL); in vsc_tp_probe()
496 if (!tp->tx_buf) in vsc_tp_probe()
499 tp->rx_buf = devm_kzalloc(dev, VSC_TP_MAX_XFER_SIZE, GFP_KERNEL); in vsc_tp_probe()
500 if (!tp->rx_buf) in vsc_tp_probe()
507 tp->wakeuphost = devm_gpiod_get(dev, "wakeuphost", GPIOD_IN); in vsc_tp_probe()
508 if (IS_ERR(tp->wakeuphost)) in vsc_tp_probe()
509 return PTR_ERR(tp->wakeuphost); in vsc_tp_probe()
511 tp->resetfw = devm_gpiod_get(dev, "resetfw", GPIOD_OUT_HIGH); in vsc_tp_probe()
512 if (IS_ERR(tp->resetfw)) in vsc_tp_probe()
513 return PTR_ERR(tp->resetfw); in vsc_tp_probe()
515 tp->wakeupfw = devm_gpiod_get(dev, "wakeupfw", GPIOD_OUT_HIGH); in vsc_tp_probe()
516 if (IS_ERR(tp->wakeupfw)) in vsc_tp_probe()
517 return PTR_ERR(tp->wakeupfw); in vsc_tp_probe()
519 atomic_set(&tp->assert_cnt, 0); in vsc_tp_probe()
520 init_waitqueue_head(&tp->xfer_wait); in vsc_tp_probe()
521 tp->spi = spi; in vsc_tp_probe()
526 dev_name(dev), tp); in vsc_tp_probe()
530 mutex_init(&tp->mutex); in vsc_tp_probe()
547 tp->pdev = pdev; in vsc_tp_probe()
548 spi_set_drvdata(spi, tp); in vsc_tp_probe()
553 mutex_destroy(&tp->mutex); in vsc_tp_probe()
555 free_irq(spi->irq, tp); in vsc_tp_probe()
562 struct vsc_tp *tp = spi_get_drvdata(spi); in vsc_tp_remove() local
564 platform_device_unregister(tp->pdev); in vsc_tp_remove()
566 mutex_destroy(&tp->mutex); in vsc_tp_remove()
568 free_irq(spi->irq, tp); in vsc_tp_remove()
573 struct vsc_tp *tp = spi_get_drvdata(spi); in vsc_tp_shutdown() local
575 platform_device_unregister(tp->pdev); in vsc_tp_shutdown()
577 mutex_destroy(&tp->mutex); in vsc_tp_shutdown()
579 vsc_tp_reset(tp); in vsc_tp_shutdown()
581 free_irq(spi->irq, tp); in vsc_tp_shutdown()