Lines Matching +full:hdmi +full:- +full:cec

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Designware HDMI CEC driver
5 * Copyright (C) 2015-2017 Russell King.
16 #include <media/cec.h>
17 #include <media/cec-notifier.h>
19 #include "dw-hdmi-cec.h"
55 struct dw_hdmi *hdmi; member
71 static void dw_hdmi_write(struct dw_hdmi_cec *cec, u8 val, int offset) in dw_hdmi_write() argument
73 cec->ops->write(cec->hdmi, val, offset); in dw_hdmi_write()
76 static u8 dw_hdmi_read(struct dw_hdmi_cec *cec, int offset) in dw_hdmi_read() argument
78 return cec->ops->read(cec->hdmi, offset); in dw_hdmi_read()
83 struct dw_hdmi_cec *cec = cec_get_drvdata(adap); in dw_hdmi_cec_log_addr() local
86 cec->addresses = 0; in dw_hdmi_cec_log_addr()
88 cec->addresses |= BIT(logical_addr) | BIT(15); in dw_hdmi_cec_log_addr()
90 dw_hdmi_write(cec, cec->addresses & 255, HDMI_CEC_ADDR_L); in dw_hdmi_cec_log_addr()
91 dw_hdmi_write(cec, cec->addresses >> 8, HDMI_CEC_ADDR_H); in dw_hdmi_cec_log_addr()
99 struct dw_hdmi_cec *cec = cec_get_drvdata(adap); in dw_hdmi_cec_transmit() local
115 for (i = 0; i < msg->len; i++) in dw_hdmi_cec_transmit()
116 dw_hdmi_write(cec, msg->msg[i], HDMI_CEC_TX_DATA0 + i); in dw_hdmi_cec_transmit()
118 dw_hdmi_write(cec, msg->len, HDMI_CEC_TX_CNT); in dw_hdmi_cec_transmit()
119 dw_hdmi_write(cec, ctrl | CEC_CTRL_START, HDMI_CEC_CTRL); in dw_hdmi_cec_transmit()
127 struct dw_hdmi_cec *cec = cec_get_drvdata(adap); in dw_hdmi_cec_hardirq() local
128 unsigned int stat = dw_hdmi_read(cec, HDMI_IH_CEC_STAT0); in dw_hdmi_cec_hardirq()
134 dw_hdmi_write(cec, stat, HDMI_IH_CEC_STAT0); in dw_hdmi_cec_hardirq()
137 cec->tx_status = CEC_TX_STATUS_ERROR; in dw_hdmi_cec_hardirq()
138 cec->tx_done = true; in dw_hdmi_cec_hardirq()
141 cec->tx_status = CEC_TX_STATUS_OK; in dw_hdmi_cec_hardirq()
142 cec->tx_done = true; in dw_hdmi_cec_hardirq()
145 cec->tx_status = CEC_TX_STATUS_NACK; in dw_hdmi_cec_hardirq()
146 cec->tx_done = true; in dw_hdmi_cec_hardirq()
149 cec->tx_status = CEC_TX_STATUS_ARB_LOST; in dw_hdmi_cec_hardirq()
150 cec->tx_done = true; in dw_hdmi_cec_hardirq()
157 len = dw_hdmi_read(cec, HDMI_CEC_RX_CNT); in dw_hdmi_cec_hardirq()
158 if (len > sizeof(cec->rx_msg.msg)) in dw_hdmi_cec_hardirq()
159 len = sizeof(cec->rx_msg.msg); in dw_hdmi_cec_hardirq()
162 cec->rx_msg.msg[i] = in dw_hdmi_cec_hardirq()
163 dw_hdmi_read(cec, HDMI_CEC_RX_DATA0 + i); in dw_hdmi_cec_hardirq()
165 dw_hdmi_write(cec, 0, HDMI_CEC_LOCK); in dw_hdmi_cec_hardirq()
167 cec->rx_msg.len = len; in dw_hdmi_cec_hardirq()
169 cec->rx_done = true; in dw_hdmi_cec_hardirq()
180 struct dw_hdmi_cec *cec = cec_get_drvdata(adap); in dw_hdmi_cec_thread() local
182 if (cec->tx_done) { in dw_hdmi_cec_thread()
183 cec->tx_done = false; in dw_hdmi_cec_thread()
184 cec_transmit_attempt_done(adap, cec->tx_status); in dw_hdmi_cec_thread()
186 if (cec->rx_done) { in dw_hdmi_cec_thread()
187 cec->rx_done = false; in dw_hdmi_cec_thread()
189 cec_received_msg(adap, &cec->rx_msg); in dw_hdmi_cec_thread()
196 struct dw_hdmi_cec *cec = cec_get_drvdata(adap); in dw_hdmi_cec_enable() local
199 dw_hdmi_write(cec, ~0, HDMI_CEC_MASK); in dw_hdmi_cec_enable()
200 dw_hdmi_write(cec, ~0, HDMI_IH_MUTE_CEC_STAT0); in dw_hdmi_cec_enable()
201 dw_hdmi_write(cec, 0, HDMI_CEC_POLARITY); in dw_hdmi_cec_enable()
203 cec->ops->disable(cec->hdmi); in dw_hdmi_cec_enable()
207 dw_hdmi_write(cec, 0, HDMI_CEC_CTRL); in dw_hdmi_cec_enable()
208 dw_hdmi_write(cec, ~0, HDMI_IH_CEC_STAT0); in dw_hdmi_cec_enable()
209 dw_hdmi_write(cec, 0, HDMI_CEC_LOCK); in dw_hdmi_cec_enable()
211 dw_hdmi_cec_log_addr(cec->adap, CEC_LOG_ADDR_INVALID); in dw_hdmi_cec_enable()
213 cec->ops->enable(cec->hdmi); in dw_hdmi_cec_enable()
217 dw_hdmi_write(cec, irqs, HDMI_CEC_POLARITY); in dw_hdmi_cec_enable()
218 dw_hdmi_write(cec, ~irqs, HDMI_CEC_MASK); in dw_hdmi_cec_enable()
219 dw_hdmi_write(cec, ~irqs, HDMI_IH_MUTE_CEC_STAT0); in dw_hdmi_cec_enable()
232 struct dw_hdmi_cec *cec = data; in dw_hdmi_cec_del() local
234 cec_delete_adapter(cec->adap); in dw_hdmi_cec_del()
239 struct dw_hdmi_cec_data *data = dev_get_platdata(&pdev->dev); in dw_hdmi_cec_probe()
240 struct dw_hdmi_cec *cec; in dw_hdmi_cec_probe() local
244 return -ENXIO; in dw_hdmi_cec_probe()
247 * Our device is just a convenience - we want to link to the real in dw_hdmi_cec_probe()
249 * between the HDMI hardware and its associated CEC chardev. in dw_hdmi_cec_probe()
251 cec = devm_kzalloc(&pdev->dev, sizeof(*cec), GFP_KERNEL); in dw_hdmi_cec_probe()
252 if (!cec) in dw_hdmi_cec_probe()
253 return -ENOMEM; in dw_hdmi_cec_probe()
255 cec->irq = data->irq; in dw_hdmi_cec_probe()
256 cec->ops = data->ops; in dw_hdmi_cec_probe()
257 cec->hdmi = data->hdmi; in dw_hdmi_cec_probe()
259 platform_set_drvdata(pdev, cec); in dw_hdmi_cec_probe()
261 dw_hdmi_write(cec, 0, HDMI_CEC_TX_CNT); in dw_hdmi_cec_probe()
262 dw_hdmi_write(cec, ~0, HDMI_CEC_MASK); in dw_hdmi_cec_probe()
263 dw_hdmi_write(cec, ~0, HDMI_IH_MUTE_CEC_STAT0); in dw_hdmi_cec_probe()
264 dw_hdmi_write(cec, 0, HDMI_CEC_POLARITY); in dw_hdmi_cec_probe()
266 cec->adap = cec_allocate_adapter(&dw_hdmi_cec_ops, cec, "dw_hdmi", in dw_hdmi_cec_probe()
270 if (IS_ERR(cec->adap)) in dw_hdmi_cec_probe()
271 return PTR_ERR(cec->adap); in dw_hdmi_cec_probe()
274 cec->adap->owner = THIS_MODULE; in dw_hdmi_cec_probe()
276 ret = devm_add_action_or_reset(&pdev->dev, dw_hdmi_cec_del, cec); in dw_hdmi_cec_probe()
280 ret = devm_request_threaded_irq(&pdev->dev, cec->irq, in dw_hdmi_cec_probe()
283 "dw-hdmi-cec", cec->adap); in dw_hdmi_cec_probe()
287 cec->notify = cec_notifier_cec_adap_register(pdev->dev.parent, in dw_hdmi_cec_probe()
288 NULL, cec->adap); in dw_hdmi_cec_probe()
289 if (!cec->notify) in dw_hdmi_cec_probe()
290 return -ENOMEM; in dw_hdmi_cec_probe()
292 ret = cec_register_adapter(cec->adap, pdev->dev.parent); in dw_hdmi_cec_probe()
294 cec_notifier_cec_adap_unregister(cec->notify, cec->adap); in dw_hdmi_cec_probe()
299 * CEC documentation says we must not call cec_delete_adapter in dw_hdmi_cec_probe()
302 devm_remove_action(&pdev->dev, dw_hdmi_cec_del, cec); in dw_hdmi_cec_probe()
309 struct dw_hdmi_cec *cec = platform_get_drvdata(pdev); in dw_hdmi_cec_remove() local
311 cec_notifier_cec_adap_unregister(cec->notify, cec->adap); in dw_hdmi_cec_remove()
312 cec_unregister_adapter(cec->adap); in dw_hdmi_cec_remove()
317 struct dw_hdmi_cec *cec = dev_get_drvdata(dev); in dw_hdmi_cec_resume() local
320 dw_hdmi_write(cec, cec->addresses & 255, HDMI_CEC_ADDR_L); in dw_hdmi_cec_resume()
321 dw_hdmi_write(cec, cec->addresses >> 8, HDMI_CEC_ADDR_H); in dw_hdmi_cec_resume()
324 dw_hdmi_write(cec, cec->regs_polarity, HDMI_CEC_POLARITY); in dw_hdmi_cec_resume()
325 dw_hdmi_write(cec, cec->regs_mask, HDMI_CEC_MASK); in dw_hdmi_cec_resume()
326 dw_hdmi_write(cec, cec->regs_mute_stat0, HDMI_IH_MUTE_CEC_STAT0); in dw_hdmi_cec_resume()
333 struct dw_hdmi_cec *cec = dev_get_drvdata(dev); in dw_hdmi_cec_suspend() local
336 cec->regs_polarity = dw_hdmi_read(cec, HDMI_CEC_POLARITY); in dw_hdmi_cec_suspend()
337 cec->regs_mask = dw_hdmi_read(cec, HDMI_CEC_MASK); in dw_hdmi_cec_suspend()
338 cec->regs_mute_stat0 = dw_hdmi_read(cec, HDMI_IH_MUTE_CEC_STAT0); in dw_hdmi_cec_suspend()
351 .name = "dw-hdmi-cec",
358 MODULE_DESCRIPTION("Synopsys Designware HDMI CEC driver for i.MX");
360 MODULE_ALIAS(PLATFORM_MODULE_PREFIX "dw-hdmi-cec");