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