Lines Matching refs:pulse8

173 struct pulse8 {  struct
232 static int pulse8_send_and_wait_once(struct pulse8 *pulse8, in pulse8_send_and_wait_once() argument
239 dev_info(pulse8->dev, "transmit %s: %*ph\n", in pulse8_send_and_wait_once()
241 init_completion(&pulse8->cmd_done); in pulse8_send_and_wait_once()
243 err = pulse8_send(pulse8->serio, cmd, cmd_len); in pulse8_send_and_wait_once()
247 if (!wait_for_completion_timeout(&pulse8->cmd_done, HZ)) in pulse8_send_and_wait_once()
249 if ((pulse8->data[0] & 0x3f) == MSGCODE_COMMAND_REJECTED && in pulse8_send_and_wait_once()
255 ((pulse8->data[0] & 0x3f) != response || pulse8->len < size + 1)) { in pulse8_send_and_wait_once()
256 dev_info(pulse8->dev, "transmit %s failed with %s\n", in pulse8_send_and_wait_once()
258 pulse8_msgname(pulse8->data[0])); in pulse8_send_and_wait_once()
264 static int pulse8_send_and_wait(struct pulse8 *pulse8, in pulse8_send_and_wait() argument
270 err = pulse8_send_and_wait_once(pulse8, cmd, cmd_len, response, size); in pulse8_send_and_wait()
276 err = pulse8_send_and_wait_once(pulse8, cmd_sc, 2, in pulse8_send_and_wait()
279 err = pulse8_send_and_wait_once(pulse8, cmd, cmd_len, in pulse8_send_and_wait()
286 struct pulse8 *pulse8 = container_of(work, struct pulse8, tx_work); in pulse8_tx_work_handler() local
287 struct cec_msg *msg = &pulse8->tx_msg; in pulse8_tx_work_handler()
295 mutex_lock(&pulse8->lock); in pulse8_tx_work_handler()
297 cmd[1] = pulse8->tx_signal_free_time; in pulse8_tx_work_handler()
298 err = pulse8_send_and_wait(pulse8, cmd, 2, in pulse8_tx_work_handler()
302 pulse8->tx_msg_is_bcast = cec_msg_is_broadcast(msg); in pulse8_tx_work_handler()
304 err = pulse8_send_and_wait(pulse8, cmd, 2, in pulse8_tx_work_handler()
309 err = pulse8_send_and_wait(pulse8, cmd, 2, in pulse8_tx_work_handler()
316 err = pulse8_send_and_wait(pulse8, cmd, 2, in pulse8_tx_work_handler()
321 dev_info(pulse8->dev, "%s(0x%02x) failed with error %d for msg %*ph\n", in pulse8_tx_work_handler()
325 mutex_unlock(&pulse8->lock); in pulse8_tx_work_handler()
327 cec_transmit_attempt_done(pulse8->adap, CEC_TX_STATUS_ERROR); in pulse8_tx_work_handler()
332 struct pulse8 *pulse8 = in pulse8_irq_work_handler() local
333 container_of(work, struct pulse8, irq_work); in pulse8_irq_work_handler()
337 spin_lock_irqsave(&pulse8->msg_lock, flags); in pulse8_irq_work_handler()
338 while (pulse8->rx_msg_num) { in pulse8_irq_work_handler()
339 spin_unlock_irqrestore(&pulse8->msg_lock, flags); in pulse8_irq_work_handler()
341 dev_info(pulse8->dev, "adap received %*ph\n", in pulse8_irq_work_handler()
342 pulse8->rx_msg[pulse8->rx_msg_cur_idx].len, in pulse8_irq_work_handler()
343 pulse8->rx_msg[pulse8->rx_msg_cur_idx].msg); in pulse8_irq_work_handler()
344 cec_received_msg(pulse8->adap, in pulse8_irq_work_handler()
345 &pulse8->rx_msg[pulse8->rx_msg_cur_idx]); in pulse8_irq_work_handler()
346 spin_lock_irqsave(&pulse8->msg_lock, flags); in pulse8_irq_work_handler()
347 if (pulse8->rx_msg_num) in pulse8_irq_work_handler()
348 pulse8->rx_msg_num--; in pulse8_irq_work_handler()
349 pulse8->rx_msg_cur_idx = in pulse8_irq_work_handler()
350 (pulse8->rx_msg_cur_idx + 1) % NUM_MSGS; in pulse8_irq_work_handler()
352 spin_unlock_irqrestore(&pulse8->msg_lock, flags); in pulse8_irq_work_handler()
354 mutex_lock(&pulse8->lock); in pulse8_irq_work_handler()
355 status = pulse8->tx_done_status; in pulse8_irq_work_handler()
356 pulse8->tx_done_status = 0; in pulse8_irq_work_handler()
357 mutex_unlock(&pulse8->lock); in pulse8_irq_work_handler()
359 cec_transmit_attempt_done(pulse8->adap, status); in pulse8_irq_work_handler()
365 struct pulse8 *pulse8 = serio_get_drvdata(serio); in pulse8_interrupt() local
369 if (!pulse8->started && data != MSGSTART) in pulse8_interrupt()
372 pulse8->escape = true; in pulse8_interrupt()
375 if (pulse8->escape) { in pulse8_interrupt()
377 pulse8->escape = false; in pulse8_interrupt()
379 u8 msgcode = pulse8->buf[0]; in pulse8_interrupt()
382 dev_info(pulse8->dev, "received %s: %*ph\n", in pulse8_interrupt()
384 pulse8->idx, pulse8->buf); in pulse8_interrupt()
392 pulse8->new_rx_msg_len = 1; in pulse8_interrupt()
393 pulse8->new_rx_msg[0] = pulse8->buf[1]; in pulse8_interrupt()
398 if (pulse8->new_rx_msg_len < CEC_MAX_MSG_SIZE) in pulse8_interrupt()
399 pulse8->new_rx_msg[pulse8->new_rx_msg_len++] = in pulse8_interrupt()
400 pulse8->buf[1]; in pulse8_interrupt()
404 spin_lock_irqsave(&pulse8->msg_lock, irq_flags); in pulse8_interrupt()
405 idx = (pulse8->rx_msg_cur_idx + pulse8->rx_msg_num) % in pulse8_interrupt()
407 if (pulse8->rx_msg_num == NUM_MSGS) { in pulse8_interrupt()
408 dev_warn(pulse8->dev, in pulse8_interrupt()
410 pulse8->new_rx_msg_len, in pulse8_interrupt()
411 pulse8->new_rx_msg); in pulse8_interrupt()
412 spin_unlock_irqrestore(&pulse8->msg_lock, in pulse8_interrupt()
414 pulse8->new_rx_msg_len = 0; in pulse8_interrupt()
417 pulse8->rx_msg_num++; in pulse8_interrupt()
418 memcpy(pulse8->rx_msg[idx].msg, pulse8->new_rx_msg, in pulse8_interrupt()
419 pulse8->new_rx_msg_len); in pulse8_interrupt()
420 pulse8->rx_msg[idx].len = pulse8->new_rx_msg_len; in pulse8_interrupt()
421 spin_unlock_irqrestore(&pulse8->msg_lock, irq_flags); in pulse8_interrupt()
422 schedule_work(&pulse8->irq_work); in pulse8_interrupt()
423 pulse8->new_rx_msg_len = 0; in pulse8_interrupt()
426 WARN_ON(pulse8->tx_done_status); in pulse8_interrupt()
427 pulse8->tx_done_status = CEC_TX_STATUS_OK; in pulse8_interrupt()
428 schedule_work(&pulse8->irq_work); in pulse8_interrupt()
435 if (pulse8->tx_msg_is_bcast) in pulse8_interrupt()
437 WARN_ON(pulse8->tx_done_status); in pulse8_interrupt()
438 pulse8->tx_done_status = CEC_TX_STATUS_NACK; in pulse8_interrupt()
439 schedule_work(&pulse8->irq_work); in pulse8_interrupt()
444 WARN_ON(pulse8->tx_done_status); in pulse8_interrupt()
445 pulse8->tx_done_status = CEC_TX_STATUS_ERROR; in pulse8_interrupt()
446 schedule_work(&pulse8->irq_work); in pulse8_interrupt()
452 pulse8->new_rx_msg_len = 0; in pulse8_interrupt()
457 if (pulse8->idx == 0) in pulse8_interrupt()
459 memcpy(pulse8->data, pulse8->buf, pulse8->idx); in pulse8_interrupt()
460 pulse8->len = pulse8->idx; in pulse8_interrupt()
461 complete(&pulse8->cmd_done); in pulse8_interrupt()
464 pulse8->idx = 0; in pulse8_interrupt()
465 pulse8->started = false; in pulse8_interrupt()
468 pulse8->idx = 0; in pulse8_interrupt()
469 pulse8->started = true; in pulse8_interrupt()
473 if (pulse8->idx >= DATA_SIZE) { in pulse8_interrupt()
474 dev_dbg(pulse8->dev, in pulse8_interrupt()
475 "throwing away %d bytes of garbage\n", pulse8->idx); in pulse8_interrupt()
476 pulse8->idx = 0; in pulse8_interrupt()
478 pulse8->buf[pulse8->idx++] = data; in pulse8_interrupt()
484 struct pulse8 *pulse8 = cec_get_drvdata(adap); in pulse8_cec_adap_enable() local
488 mutex_lock(&pulse8->lock); in pulse8_cec_adap_enable()
491 err = pulse8_send_and_wait(pulse8, cmd, 2, in pulse8_cec_adap_enable()
494 pulse8->rx_msg_num = 0; in pulse8_cec_adap_enable()
495 pulse8->tx_done_status = 0; in pulse8_cec_adap_enable()
497 mutex_unlock(&pulse8->lock); in pulse8_cec_adap_enable()
503 struct pulse8 *pulse8 = cec_get_drvdata(adap); in pulse8_cec_adap_log_addr() local
509 mutex_lock(&pulse8->lock); in pulse8_cec_adap_log_addr()
515 err = pulse8_send_and_wait(pulse8, cmd, 3, in pulse8_cec_adap_log_addr()
517 if ((err && mask != 0) || pulse8->restoring_config) in pulse8_cec_adap_log_addr()
522 err = pulse8_send_and_wait(pulse8, cmd, 2, in pulse8_cec_adap_log_addr()
526 pulse8->autonomous = cmd[1]; in pulse8_cec_adap_log_addr()
532 err = pulse8_send_and_wait(pulse8, cmd, 2, in pulse8_cec_adap_log_addr()
566 err = pulse8_send_and_wait(pulse8, cmd, 3, in pulse8_cec_adap_log_addr()
573 err = pulse8_send_and_wait(pulse8, cmd, 2, in pulse8_cec_adap_log_addr()
581 err = pulse8_send_and_wait(pulse8, cmd, 3, in pulse8_cec_adap_log_addr()
586 if (pulse8->vers < 10) { in pulse8_cec_adap_log_addr()
589 err = pulse8_send_and_wait(pulse8, cmd, 2, in pulse8_cec_adap_log_addr()
608 err = pulse8_send_and_wait(pulse8, cmd, 1 + osd_len, in pulse8_cec_adap_log_addr()
615 if (pulse8->restoring_config) in pulse8_cec_adap_log_addr()
616 pulse8->restoring_config = false; in pulse8_cec_adap_log_addr()
618 pulse8->config_pending = true; in pulse8_cec_adap_log_addr()
619 mutex_unlock(&pulse8->lock); in pulse8_cec_adap_log_addr()
626 struct pulse8 *pulse8 = cec_get_drvdata(adap); in pulse8_cec_adap_transmit() local
628 pulse8->tx_msg = *msg; in pulse8_cec_adap_transmit()
630 dev_info(pulse8->dev, "adap transmit %*ph\n", in pulse8_cec_adap_transmit()
632 pulse8->tx_signal_free_time = signal_free_time; in pulse8_cec_adap_transmit()
633 schedule_work(&pulse8->tx_work); in pulse8_cec_adap_transmit()
639 struct pulse8 *pulse8 = cec_get_drvdata(adap); in pulse8_cec_adap_free() local
641 cancel_delayed_work_sync(&pulse8->ping_eeprom_work); in pulse8_cec_adap_free()
642 cancel_work_sync(&pulse8->irq_work); in pulse8_cec_adap_free()
643 cancel_work_sync(&pulse8->tx_work); in pulse8_cec_adap_free()
644 kfree(pulse8); in pulse8_cec_adap_free()
656 struct pulse8 *pulse8 = serio_get_drvdata(serio); in pulse8_disconnect() local
658 cec_unregister_adapter(pulse8->adap); in pulse8_disconnect()
663 static int pulse8_setup(struct pulse8 *pulse8, struct serio *serio, in pulse8_setup() argument
666 u8 *data = pulse8->data + 1; in pulse8_setup()
671 pulse8->vers = 0; in pulse8_setup()
674 err = pulse8_send_and_wait(pulse8, cmd, 1, cmd[0], 2); in pulse8_setup()
677 pulse8->vers = (data[0] << 8) | data[1]; in pulse8_setup()
678 dev_info(pulse8->dev, "Firmware version %04x\n", pulse8->vers); in pulse8_setup()
679 if (pulse8->vers < 2) { in pulse8_setup()
685 err = pulse8_send_and_wait(pulse8, cmd, 1, cmd[0], 4); in pulse8_setup()
689 dev_info(pulse8->dev, "Firmware build date %ptT\n", &date); in pulse8_setup()
691 dev_dbg(pulse8->dev, "Persistent config:\n"); in pulse8_setup()
693 err = pulse8_send_and_wait(pulse8, cmd, 1, cmd[0], 1); in pulse8_setup()
696 pulse8->autonomous = data[0]; in pulse8_setup()
697 dev_dbg(pulse8->dev, "Autonomous mode: %s", in pulse8_setup()
700 if (pulse8->vers >= 10) { in pulse8_setup()
702 err = pulse8_send_and_wait(pulse8, cmd, 1, cmd[0], 1); in pulse8_setup()
704 dev_dbg(pulse8->dev, "Auto Power On: %s", in pulse8_setup()
709 err = pulse8_send_and_wait(pulse8, cmd, 1, cmd[0], 1); in pulse8_setup()
713 dev_dbg(pulse8->dev, "Primary device type: %d\n", data[0]); in pulse8_setup()
746 dev_info(pulse8->dev, "Unknown Primary Device Type: %d\n", in pulse8_setup()
752 err = pulse8_send_and_wait(pulse8, cmd, 1, cmd[0], 2); in pulse8_setup()
756 dev_dbg(pulse8->dev, "Logical address ACK mask: %x\n", in pulse8_setup()
762 err = pulse8_send_and_wait(pulse8, cmd, 1, cmd[0], 1); in pulse8_setup()
766 dev_dbg(pulse8->dev, "Physical address: %x.%x.%x.%x\n", in pulse8_setup()
770 if (pulse8->vers < 10) { in pulse8_setup()
772 err = pulse8_send_and_wait(pulse8, cmd, 1, cmd[0], 1); in pulse8_setup()
776 dev_dbg(pulse8->dev, "CEC version: %d\n", log_addrs->cec_version); in pulse8_setup()
780 err = pulse8_send_and_wait(pulse8, cmd, 1, cmd[0], 0); in pulse8_setup()
784 dev_dbg(pulse8->dev, "OSD name: %s\n", log_addrs->osd_name); in pulse8_setup()
789 static int pulse8_apply_persistent_config(struct pulse8 *pulse8, in pulse8_apply_persistent_config() argument
795 err = cec_s_log_addrs(pulse8->adap, log_addrs, false); in pulse8_apply_persistent_config()
799 cec_s_phys_addr(pulse8->adap, pa, false); in pulse8_apply_persistent_config()
806 struct pulse8 *pulse8 = in pulse8_ping_eeprom_work_handler() local
807 container_of(work, struct pulse8, ping_eeprom_work.work); in pulse8_ping_eeprom_work_handler()
810 mutex_lock(&pulse8->lock); in pulse8_ping_eeprom_work_handler()
812 if (pulse8_send_and_wait(pulse8, &cmd, 1, in pulse8_ping_eeprom_work_handler()
814 dev_warn(pulse8->dev, "failed to ping EEPROM\n"); in pulse8_ping_eeprom_work_handler()
818 if (pulse8->vers < 2) in pulse8_ping_eeprom_work_handler()
821 if (pulse8->config_pending && persistent_config) { in pulse8_ping_eeprom_work_handler()
822 dev_dbg(pulse8->dev, "writing pending config to EEPROM\n"); in pulse8_ping_eeprom_work_handler()
824 if (pulse8_send_and_wait(pulse8, &cmd, 1, in pulse8_ping_eeprom_work_handler()
826 dev_info(pulse8->dev, "failed to write pending config to EEPROM\n"); in pulse8_ping_eeprom_work_handler()
828 pulse8->config_pending = false; in pulse8_ping_eeprom_work_handler()
831 schedule_delayed_work(&pulse8->ping_eeprom_work, PING_PERIOD); in pulse8_ping_eeprom_work_handler()
832 mutex_unlock(&pulse8->lock); in pulse8_ping_eeprom_work_handler()
838 struct pulse8 *pulse8; in pulse8_connect() local
843 pulse8 = kzalloc(sizeof(*pulse8), GFP_KERNEL); in pulse8_connect()
845 if (!pulse8) in pulse8_connect()
848 pulse8->serio = serio; in pulse8_connect()
849 pulse8->adap = cec_allocate_adapter(&pulse8_cec_adap_ops, pulse8, in pulse8_connect()
851 err = PTR_ERR_OR_ZERO(pulse8->adap); in pulse8_connect()
853 kfree(pulse8); in pulse8_connect()
857 pulse8->dev = &serio->dev; in pulse8_connect()
858 serio_set_drvdata(serio, pulse8); in pulse8_connect()
859 INIT_WORK(&pulse8->irq_work, pulse8_irq_work_handler); in pulse8_connect()
860 INIT_WORK(&pulse8->tx_work, pulse8_tx_work_handler); in pulse8_connect()
861 INIT_DELAYED_WORK(&pulse8->ping_eeprom_work, in pulse8_connect()
863 mutex_init(&pulse8->lock); in pulse8_connect()
864 spin_lock_init(&pulse8->msg_lock); in pulse8_connect()
865 pulse8->config_pending = false; in pulse8_connect()
871 err = pulse8_setup(pulse8, serio, &log_addrs, &pa); in pulse8_connect()
875 err = cec_register_adapter(pulse8->adap, &serio->dev); in pulse8_connect()
879 pulse8->dev = &pulse8->adap->devnode.dev; in pulse8_connect()
881 if (persistent_config && pulse8->autonomous) { in pulse8_connect()
882 err = pulse8_apply_persistent_config(pulse8, &log_addrs, pa); in pulse8_connect()
885 pulse8->restoring_config = true; in pulse8_connect()
888 schedule_delayed_work(&pulse8->ping_eeprom_work, PING_PERIOD); in pulse8_connect()
893 pulse8->serio = NULL; in pulse8_connect()
897 cec_delete_adapter(pulse8->adap); in pulse8_connect()