Lines Matching +full:cec +full:- +full:irq
1 // SPDX-License-Identifier: GPL-2.0+
3 * CEC driver for ChromeOS Embedded Controller
15 #include <linux/cec.h>
20 #include <media/cec.h>
21 #include <media/cec-notifier.h>
23 #define DRV_NAME "cros-ec-cec"
26 * struct cros_ec_cec_port - Driver data for a single EC CEC port
29 * @adap: CEC adapter
30 * @notify: CEC notifier pointer
43 * struct cros_ec_cec - Driver data for EC CEC
48 * @num_ports: Number of CEC ports
65 port->rx_msg.len = len; in cros_ec_cec_received_message()
66 memcpy(port->rx_msg.msg, msg, len); in cros_ec_cec_received_message()
68 cec_received_msg(port->adap, &port->rx_msg); in cros_ec_cec_received_message()
73 struct cros_ec_device *cros_ec = cros_ec_cec->cros_ec; in handle_cec_message()
74 uint8_t *cec_message = cros_ec->event_data.data.cec_message; in handle_cec_message()
75 unsigned int len = cros_ec->event_size; in handle_cec_message()
78 * There are two ways of receiving CEC messages: in handle_cec_message()
84 * Check that the EC only has one CEC port, and then we can assume the in handle_cec_message()
87 if (cros_ec_cec->num_ports != 1) { in handle_cec_message()
88 dev_err(cros_ec->dev, in handle_cec_message()
90 cros_ec_cec->num_ports); in handle_cec_message()
93 port = cros_ec_cec->ports[0]; in handle_cec_message()
100 struct cros_ec_device *cros_ec = port->cros_ec_cec->cros_ec; in cros_ec_cec_read_message()
102 .port = port->port_num, in cros_ec_cec_read_message()
110 dev_err(cros_ec->dev, in cros_ec_cec_read_message()
111 "error reading CEC message on EC: %d\n", ret); in cros_ec_cec_read_message()
120 struct cros_ec_device *cros_ec = cros_ec_cec->cros_ec; in handle_cec_event()
121 uint32_t cec_events = cros_ec->event_data.data.cec_events; in handle_cec_event()
126 if (port_num >= cros_ec_cec->num_ports) { in handle_cec_event()
127 dev_err(cros_ec->dev, in handle_cec_event()
128 "received CEC event for invalid port %d\n", port_num); in handle_cec_event()
131 port = cros_ec_cec->ports[port_num]; in handle_cec_event()
134 cec_transmit_attempt_done(port->adap, CEC_TX_STATUS_OK); in handle_cec_event()
138 cec_transmit_attempt_done(port->adap, in handle_cec_event()
154 cros_ec = cros_ec_cec->cros_ec; in cros_ec_cec_event()
156 if (cros_ec->event_data.event_type == EC_MKBP_EVENT_CEC_EVENT) { in cros_ec_cec_event()
161 if (cros_ec->event_data.event_type == EC_MKBP_EVENT_CEC_MESSAGE) { in cros_ec_cec_event()
171 struct cros_ec_cec_port *port = adap->priv; in cros_ec_cec_set_log_addr()
172 struct cros_ec_cec *cros_ec_cec = port->cros_ec_cec; in cros_ec_cec_set_log_addr()
173 struct cros_ec_device *cros_ec = cros_ec_cec->cros_ec; in cros_ec_cec_set_log_addr()
176 .port = port->port_num, in cros_ec_cec_set_log_addr()
184 dev_err(cros_ec->dev, in cros_ec_cec_set_log_addr()
185 "error setting CEC logical address on EC: %d\n", ret); in cros_ec_cec_set_log_addr()
195 struct cros_ec_cec_port *port = adap->priv; in cros_ec_cec_transmit()
196 struct cros_ec_cec *cros_ec_cec = port->cros_ec_cec; in cros_ec_cec_transmit()
197 struct cros_ec_device *cros_ec = cros_ec_cec->cros_ec; in cros_ec_cec_transmit()
202 if (cros_ec_cec->write_cmd_version == 0) { in cros_ec_cec_transmit()
203 memcpy(params.msg, cec_msg->msg, cec_msg->len); in cros_ec_cec_transmit()
205 cec_msg->len, NULL, 0); in cros_ec_cec_transmit()
207 params_v1.port = port->port_num; in cros_ec_cec_transmit()
208 params_v1.msg_len = cec_msg->len; in cros_ec_cec_transmit()
209 memcpy(params_v1.msg, cec_msg->msg, cec_msg->len); in cros_ec_cec_transmit()
210 ret = cros_ec_cmd(cros_ec, cros_ec_cec->write_cmd_version, in cros_ec_cec_transmit()
216 dev_err(cros_ec->dev, in cros_ec_cec_transmit()
217 "error writing CEC msg on EC: %d\n", ret); in cros_ec_cec_transmit()
226 struct cros_ec_cec_port *port = adap->priv; in cros_ec_cec_adap_enable()
227 struct cros_ec_cec *cros_ec_cec = port->cros_ec_cec; in cros_ec_cec_adap_enable()
228 struct cros_ec_device *cros_ec = cros_ec_cec->cros_ec; in cros_ec_cec_adap_enable()
231 .port = port->port_num, in cros_ec_cec_adap_enable()
239 dev_err(cros_ec->dev, in cros_ec_cec_adap_enable()
240 "error %sabling CEC on EC: %d\n", in cros_ec_cec_adap_enable()
258 struct cros_ec_cec *cros_ec_cec = dev_get_drvdata(&pdev->dev); in cros_ec_cec_suspend()
261 enable_irq_wake(cros_ec_cec->cros_ec->irq); in cros_ec_cec_suspend()
269 struct cros_ec_cec *cros_ec_cec = dev_get_drvdata(&pdev->dev); in cros_ec_cec_resume()
272 disable_irq_wake(cros_ec_cec->cros_ec->irq); in cros_ec_cec_resume()
285 * corresponding to each CEC port. The order of connectors must match the order
342 if (dmi_match(DMI_SYS_VENDOR, m->sys_vendor) && in cros_ec_cec_find_hdmi_dev()
343 dmi_match(DMI_PRODUCT_NAME, m->product_name)) { in cros_ec_cec_find_hdmi_dev()
348 m->devname); in cros_ec_cec_find_hdmi_dev()
350 return ERR_PTR(-EPROBE_DEFER); in cros_ec_cec_find_hdmi_dev()
352 *conns = m->conns; in cros_ec_cec_find_hdmi_dev()
358 dev_warn(dev, "CEC notifier not configured for this hardware\n"); in cros_ec_cec_find_hdmi_dev()
360 return ERR_PTR(-ENODEV); in cros_ec_cec_find_hdmi_dev()
368 return ERR_PTR(-ENODEV); in cros_ec_cec_find_hdmi_dev()
378 ret = cros_ec_cmd(cros_ec_cec->cros_ec, 0, EC_CMD_CEC_PORT_COUNT, NULL, in cros_ec_cec_get_num_ports()
385 cros_ec_cec->num_ports = 1; in cros_ec_cec_get_num_ports()
390 dev_err(cros_ec_cec->cros_ec->dev, in cros_ec_cec_get_num_ports()
391 "EC reports 0 CEC ports\n"); in cros_ec_cec_get_num_ports()
392 return -ENODEV; in cros_ec_cec_get_num_ports()
396 dev_err(cros_ec_cec->cros_ec->dev, in cros_ec_cec_get_num_ports()
398 return -EINVAL; in cros_ec_cec_get_num_ports()
401 cros_ec_cec->num_ports = response.port_count; in cros_ec_cec_get_num_ports()
407 struct cros_ec_device *cros_ec = cros_ec_cec->cros_ec; in cros_ec_cec_get_write_cmd_version()
417 dev_err(cros_ec->dev, in cros_ec_cec_get_write_cmd_version()
418 "error getting CEC write command version: %d\n", ret); in cros_ec_cec_get_write_cmd_version()
423 cros_ec_cec->write_cmd_version = 1; in cros_ec_cec_get_write_cmd_version()
425 if (cros_ec_cec->num_ports != 1) { in cros_ec_cec_get_write_cmd_version()
426 dev_err(cros_ec->dev, in cros_ec_cec_get_write_cmd_version()
428 cros_ec_cec->num_ports); in cros_ec_cec_get_write_cmd_version()
429 return -EINVAL; in cros_ec_cec_get_write_cmd_version()
431 cros_ec_cec->write_cmd_version = 0; in cros_ec_cec_get_write_cmd_version()
447 return -ENOMEM; in cros_ec_cec_init_port()
449 port->cros_ec_cec = cros_ec_cec; in cros_ec_cec_init_port()
450 port->port_num = port_num; in cros_ec_cec_init_port()
452 port->adap = cec_allocate_adapter(&cros_ec_cec_ops, port, DRV_NAME, in cros_ec_cec_init_port()
455 if (IS_ERR(port->adap)) in cros_ec_cec_init_port()
456 return PTR_ERR(port->adap); in cros_ec_cec_init_port()
460 ret = -ENODEV; in cros_ec_cec_init_port()
464 port->notify = cec_notifier_cec_adap_register(hdmi_dev, conns[port_num], in cros_ec_cec_init_port()
465 port->adap); in cros_ec_cec_init_port()
466 if (!port->notify) { in cros_ec_cec_init_port()
467 ret = -ENOMEM; in cros_ec_cec_init_port()
471 ret = cec_register_adapter(port->adap, dev); in cros_ec_cec_init_port()
475 cros_ec_cec->ports[port_num] = port; in cros_ec_cec_init_port()
480 cec_notifier_cec_adap_unregister(port->notify, port->adap); in cros_ec_cec_init_port()
482 cec_delete_adapter(port->adap); in cros_ec_cec_init_port()
488 struct cros_ec_dev *ec_dev = dev_get_drvdata(pdev->dev.parent); in cros_ec_cec_probe()
489 struct cros_ec_device *cros_ec = ec_dev->ec_dev; in cros_ec_cec_probe()
496 hdmi_dev = cros_ec_cec_find_hdmi_dev(&pdev->dev, &conns); in cros_ec_cec_probe()
500 cros_ec_cec = devm_kzalloc(&pdev->dev, sizeof(*cros_ec_cec), in cros_ec_cec_probe()
503 return -ENOMEM; in cros_ec_cec_probe()
506 cros_ec_cec->cros_ec = cros_ec; in cros_ec_cec_probe()
508 device_init_wakeup(&pdev->dev, 1); in cros_ec_cec_probe()
518 for (int i = 0; i < cros_ec_cec->num_ports; i++) { in cros_ec_cec_probe()
519 ret = cros_ec_cec_init_port(&pdev->dev, cros_ec_cec, i, in cros_ec_cec_probe()
525 /* Get CEC events from the EC. */ in cros_ec_cec_probe()
526 cros_ec_cec->notifier.notifier_call = cros_ec_cec_event; in cros_ec_cec_probe()
527 ret = blocking_notifier_chain_register(&cros_ec->event_notifier, in cros_ec_cec_probe()
528 &cros_ec_cec->notifier); in cros_ec_cec_probe()
530 dev_err(&pdev->dev, "failed to register notifier\n"); in cros_ec_cec_probe()
540 * so any non-NULL ports must have been registered. in cros_ec_cec_probe()
542 for (int i = 0; i < cros_ec_cec->num_ports; i++) { in cros_ec_cec_probe()
543 port = cros_ec_cec->ports[i]; in cros_ec_cec_probe()
546 cec_notifier_cec_adap_unregister(port->notify, port->adap); in cros_ec_cec_probe()
547 cec_unregister_adapter(port->adap); in cros_ec_cec_probe()
555 struct device *dev = &pdev->dev; in cros_ec_cec_remove()
565 &cros_ec_cec->cros_ec->event_notifier, in cros_ec_cec_remove()
566 &cros_ec_cec->notifier); in cros_ec_cec_remove()
570 for (int i = 0; i < cros_ec_cec->num_ports; i++) { in cros_ec_cec_remove()
571 port = cros_ec_cec->ports[i]; in cros_ec_cec_remove()
572 cec_notifier_cec_adap_unregister(port->notify, port->adap); in cros_ec_cec_remove()
573 cec_unregister_adapter(port->adap); in cros_ec_cec_remove()
595 MODULE_DESCRIPTION("CEC driver for ChromeOS ECs");