1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0 2*4882a593Smuzhiyun 3*4882a593SmuzhiyunCEC Kernel Support 4*4882a593Smuzhiyun================== 5*4882a593Smuzhiyun 6*4882a593SmuzhiyunThe CEC framework provides a unified kernel interface for use with HDMI CEC 7*4882a593Smuzhiyunhardware. It is designed to handle a multiple types of hardware (receivers, 8*4882a593Smuzhiyuntransmitters, USB dongles). The framework also gives the option to decide 9*4882a593Smuzhiyunwhat to do in the kernel driver and what should be handled by userspace 10*4882a593Smuzhiyunapplications. In addition it integrates the remote control passthrough 11*4882a593Smuzhiyunfeature into the kernel's remote control framework. 12*4882a593Smuzhiyun 13*4882a593Smuzhiyun 14*4882a593SmuzhiyunThe CEC Protocol 15*4882a593Smuzhiyun---------------- 16*4882a593Smuzhiyun 17*4882a593SmuzhiyunThe CEC protocol enables consumer electronic devices to communicate with each 18*4882a593Smuzhiyunother through the HDMI connection. The protocol uses logical addresses in the 19*4882a593Smuzhiyuncommunication. The logical address is strictly connected with the functionality 20*4882a593Smuzhiyunprovided by the device. The TV acting as the communication hub is always 21*4882a593Smuzhiyunassigned address 0. The physical address is determined by the physical 22*4882a593Smuzhiyunconnection between devices. 23*4882a593Smuzhiyun 24*4882a593SmuzhiyunThe CEC framework described here is up to date with the CEC 2.0 specification. 25*4882a593SmuzhiyunIt is documented in the HDMI 1.4 specification with the new 2.0 bits documented 26*4882a593Smuzhiyunin the HDMI 2.0 specification. But for most of the features the freely available 27*4882a593SmuzhiyunHDMI 1.3a specification is sufficient: 28*4882a593Smuzhiyun 29*4882a593Smuzhiyunhttp://www.microprocessor.org/HDMISpecification13a.pdf 30*4882a593Smuzhiyun 31*4882a593Smuzhiyun 32*4882a593SmuzhiyunCEC Adapter Interface 33*4882a593Smuzhiyun--------------------- 34*4882a593Smuzhiyun 35*4882a593SmuzhiyunThe struct cec_adapter represents the CEC adapter hardware. It is created by 36*4882a593Smuzhiyuncalling cec_allocate_adapter() and deleted by calling cec_delete_adapter(): 37*4882a593Smuzhiyun 38*4882a593Smuzhiyun.. c:function:: 39*4882a593Smuzhiyun struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops, \ 40*4882a593Smuzhiyun void *priv, const char *name, \ 41*4882a593Smuzhiyun u32 caps, u8 available_las); 42*4882a593Smuzhiyun 43*4882a593Smuzhiyun.. c:function:: 44*4882a593Smuzhiyun void cec_delete_adapter(struct cec_adapter *adap); 45*4882a593Smuzhiyun 46*4882a593SmuzhiyunTo create an adapter you need to pass the following information: 47*4882a593Smuzhiyun 48*4882a593Smuzhiyunops: 49*4882a593Smuzhiyun adapter operations which are called by the CEC framework and that you 50*4882a593Smuzhiyun have to implement. 51*4882a593Smuzhiyun 52*4882a593Smuzhiyunpriv: 53*4882a593Smuzhiyun will be stored in adap->priv and can be used by the adapter ops. 54*4882a593Smuzhiyun Use cec_get_drvdata(adap) to get the priv pointer. 55*4882a593Smuzhiyun 56*4882a593Smuzhiyunname: 57*4882a593Smuzhiyun the name of the CEC adapter. Note: this name will be copied. 58*4882a593Smuzhiyun 59*4882a593Smuzhiyuncaps: 60*4882a593Smuzhiyun capabilities of the CEC adapter. These capabilities determine the 61*4882a593Smuzhiyun capabilities of the hardware and which parts are to be handled 62*4882a593Smuzhiyun by userspace and which parts are handled by kernelspace. The 63*4882a593Smuzhiyun capabilities are returned by CEC_ADAP_G_CAPS. 64*4882a593Smuzhiyun 65*4882a593Smuzhiyunavailable_las: 66*4882a593Smuzhiyun the number of simultaneous logical addresses that this 67*4882a593Smuzhiyun adapter can handle. Must be 1 <= available_las <= CEC_MAX_LOG_ADDRS. 68*4882a593Smuzhiyun 69*4882a593SmuzhiyunTo obtain the priv pointer use this helper function: 70*4882a593Smuzhiyun 71*4882a593Smuzhiyun.. c:function:: 72*4882a593Smuzhiyun void *cec_get_drvdata(const struct cec_adapter *adap); 73*4882a593Smuzhiyun 74*4882a593SmuzhiyunTo register the /dev/cecX device node and the remote control device (if 75*4882a593SmuzhiyunCEC_CAP_RC is set) you call: 76*4882a593Smuzhiyun 77*4882a593Smuzhiyun.. c:function:: 78*4882a593Smuzhiyun int cec_register_adapter(struct cec_adapter *adap, \ 79*4882a593Smuzhiyun struct device *parent); 80*4882a593Smuzhiyun 81*4882a593Smuzhiyunwhere parent is the parent device. 82*4882a593Smuzhiyun 83*4882a593SmuzhiyunTo unregister the devices call: 84*4882a593Smuzhiyun 85*4882a593Smuzhiyun.. c:function:: 86*4882a593Smuzhiyun void cec_unregister_adapter(struct cec_adapter *adap); 87*4882a593Smuzhiyun 88*4882a593SmuzhiyunNote: if cec_register_adapter() fails, then call cec_delete_adapter() to 89*4882a593Smuzhiyunclean up. But if cec_register_adapter() succeeded, then only call 90*4882a593Smuzhiyuncec_unregister_adapter() to clean up, never cec_delete_adapter(). The 91*4882a593Smuzhiyununregister function will delete the adapter automatically once the last user 92*4882a593Smuzhiyunof that /dev/cecX device has closed its file handle. 93*4882a593Smuzhiyun 94*4882a593Smuzhiyun 95*4882a593SmuzhiyunImplementing the Low-Level CEC Adapter 96*4882a593Smuzhiyun-------------------------------------- 97*4882a593Smuzhiyun 98*4882a593SmuzhiyunThe following low-level adapter operations have to be implemented in 99*4882a593Smuzhiyunyour driver: 100*4882a593Smuzhiyun 101*4882a593Smuzhiyun.. c:struct:: cec_adap_ops 102*4882a593Smuzhiyun 103*4882a593Smuzhiyun.. code-block:: none 104*4882a593Smuzhiyun 105*4882a593Smuzhiyun struct cec_adap_ops 106*4882a593Smuzhiyun { 107*4882a593Smuzhiyun /* Low-level callbacks */ 108*4882a593Smuzhiyun int (*adap_enable)(struct cec_adapter *adap, bool enable); 109*4882a593Smuzhiyun int (*adap_monitor_all_enable)(struct cec_adapter *adap, bool enable); 110*4882a593Smuzhiyun int (*adap_monitor_pin_enable)(struct cec_adapter *adap, bool enable); 111*4882a593Smuzhiyun int (*adap_log_addr)(struct cec_adapter *adap, u8 logical_addr); 112*4882a593Smuzhiyun int (*adap_transmit)(struct cec_adapter *adap, u8 attempts, 113*4882a593Smuzhiyun u32 signal_free_time, struct cec_msg *msg); 114*4882a593Smuzhiyun void (*adap_status)(struct cec_adapter *adap, struct seq_file *file); 115*4882a593Smuzhiyun void (*adap_free)(struct cec_adapter *adap); 116*4882a593Smuzhiyun 117*4882a593Smuzhiyun /* Error injection callbacks */ 118*4882a593Smuzhiyun ... 119*4882a593Smuzhiyun 120*4882a593Smuzhiyun /* High-level callbacks */ 121*4882a593Smuzhiyun ... 122*4882a593Smuzhiyun }; 123*4882a593Smuzhiyun 124*4882a593SmuzhiyunThe seven low-level ops deal with various aspects of controlling the CEC adapter 125*4882a593Smuzhiyunhardware: 126*4882a593Smuzhiyun 127*4882a593Smuzhiyun 128*4882a593SmuzhiyunTo enable/disable the hardware:: 129*4882a593Smuzhiyun 130*4882a593Smuzhiyun int (*adap_enable)(struct cec_adapter *adap, bool enable); 131*4882a593Smuzhiyun 132*4882a593SmuzhiyunThis callback enables or disables the CEC hardware. Enabling the CEC hardware 133*4882a593Smuzhiyunmeans powering it up in a state where no logical addresses are claimed. This 134*4882a593Smuzhiyunop assumes that the physical address (adap->phys_addr) is valid when enable is 135*4882a593Smuzhiyuntrue and will not change while the CEC adapter remains enabled. The initial 136*4882a593Smuzhiyunstate of the CEC adapter after calling cec_allocate_adapter() is disabled. 137*4882a593Smuzhiyun 138*4882a593SmuzhiyunNote that adap_enable must return 0 if enable is false. 139*4882a593Smuzhiyun 140*4882a593Smuzhiyun 141*4882a593SmuzhiyunTo enable/disable the 'monitor all' mode:: 142*4882a593Smuzhiyun 143*4882a593Smuzhiyun int (*adap_monitor_all_enable)(struct cec_adapter *adap, bool enable); 144*4882a593Smuzhiyun 145*4882a593SmuzhiyunIf enabled, then the adapter should be put in a mode to also monitor messages 146*4882a593Smuzhiyunthat not for us. Not all hardware supports this and this function is only 147*4882a593Smuzhiyuncalled if the CEC_CAP_MONITOR_ALL capability is set. This callback is optional 148*4882a593Smuzhiyun(some hardware may always be in 'monitor all' mode). 149*4882a593Smuzhiyun 150*4882a593SmuzhiyunNote that adap_monitor_all_enable must return 0 if enable is false. 151*4882a593Smuzhiyun 152*4882a593Smuzhiyun 153*4882a593SmuzhiyunTo enable/disable the 'monitor pin' mode:: 154*4882a593Smuzhiyun 155*4882a593Smuzhiyun int (*adap_monitor_pin_enable)(struct cec_adapter *adap, bool enable); 156*4882a593Smuzhiyun 157*4882a593SmuzhiyunIf enabled, then the adapter should be put in a mode to also monitor CEC pin 158*4882a593Smuzhiyunchanges. Not all hardware supports this and this function is only called if 159*4882a593Smuzhiyunthe CEC_CAP_MONITOR_PIN capability is set. This callback is optional 160*4882a593Smuzhiyun(some hardware may always be in 'monitor pin' mode). 161*4882a593Smuzhiyun 162*4882a593SmuzhiyunNote that adap_monitor_pin_enable must return 0 if enable is false. 163*4882a593Smuzhiyun 164*4882a593Smuzhiyun 165*4882a593SmuzhiyunTo program a new logical address:: 166*4882a593Smuzhiyun 167*4882a593Smuzhiyun int (*adap_log_addr)(struct cec_adapter *adap, u8 logical_addr); 168*4882a593Smuzhiyun 169*4882a593SmuzhiyunIf logical_addr == CEC_LOG_ADDR_INVALID then all programmed logical addresses 170*4882a593Smuzhiyunare to be erased. Otherwise the given logical address should be programmed. 171*4882a593SmuzhiyunIf the maximum number of available logical addresses is exceeded, then it 172*4882a593Smuzhiyunshould return -ENXIO. Once a logical address is programmed the CEC hardware 173*4882a593Smuzhiyuncan receive directed messages to that address. 174*4882a593Smuzhiyun 175*4882a593SmuzhiyunNote that adap_log_addr must return 0 if logical_addr is CEC_LOG_ADDR_INVALID. 176*4882a593Smuzhiyun 177*4882a593Smuzhiyun 178*4882a593SmuzhiyunTo transmit a new message:: 179*4882a593Smuzhiyun 180*4882a593Smuzhiyun int (*adap_transmit)(struct cec_adapter *adap, u8 attempts, 181*4882a593Smuzhiyun u32 signal_free_time, struct cec_msg *msg); 182*4882a593Smuzhiyun 183*4882a593SmuzhiyunThis transmits a new message. The attempts argument is the suggested number of 184*4882a593Smuzhiyunattempts for the transmit. 185*4882a593Smuzhiyun 186*4882a593SmuzhiyunThe signal_free_time is the number of data bit periods that the adapter should 187*4882a593Smuzhiyunwait when the line is free before attempting to send a message. This value 188*4882a593Smuzhiyundepends on whether this transmit is a retry, a message from a new initiator or 189*4882a593Smuzhiyuna new message for the same initiator. Most hardware will handle this 190*4882a593Smuzhiyunautomatically, but in some cases this information is needed. 191*4882a593Smuzhiyun 192*4882a593SmuzhiyunThe CEC_FREE_TIME_TO_USEC macro can be used to convert signal_free_time to 193*4882a593Smuzhiyunmicroseconds (one data bit period is 2.4 ms). 194*4882a593Smuzhiyun 195*4882a593Smuzhiyun 196*4882a593SmuzhiyunTo log the current CEC hardware status:: 197*4882a593Smuzhiyun 198*4882a593Smuzhiyun void (*adap_status)(struct cec_adapter *adap, struct seq_file *file); 199*4882a593Smuzhiyun 200*4882a593SmuzhiyunThis optional callback can be used to show the status of the CEC hardware. 201*4882a593SmuzhiyunThe status is available through debugfs: cat /sys/kernel/debug/cec/cecX/status 202*4882a593Smuzhiyun 203*4882a593SmuzhiyunTo free any resources when the adapter is deleted:: 204*4882a593Smuzhiyun 205*4882a593Smuzhiyun void (*adap_free)(struct cec_adapter *adap); 206*4882a593Smuzhiyun 207*4882a593SmuzhiyunThis optional callback can be used to free any resources that might have been 208*4882a593Smuzhiyunallocated by the driver. It's called from cec_delete_adapter. 209*4882a593Smuzhiyun 210*4882a593Smuzhiyun 211*4882a593SmuzhiyunYour adapter driver will also have to react to events (typically interrupt 212*4882a593Smuzhiyundriven) by calling into the framework in the following situations: 213*4882a593Smuzhiyun 214*4882a593SmuzhiyunWhen a transmit finished (successfully or otherwise):: 215*4882a593Smuzhiyun 216*4882a593Smuzhiyun void cec_transmit_done(struct cec_adapter *adap, u8 status, 217*4882a593Smuzhiyun u8 arb_lost_cnt, u8 nack_cnt, u8 low_drive_cnt, 218*4882a593Smuzhiyun u8 error_cnt); 219*4882a593Smuzhiyun 220*4882a593Smuzhiyunor:: 221*4882a593Smuzhiyun 222*4882a593Smuzhiyun void cec_transmit_attempt_done(struct cec_adapter *adap, u8 status); 223*4882a593Smuzhiyun 224*4882a593SmuzhiyunThe status can be one of: 225*4882a593Smuzhiyun 226*4882a593SmuzhiyunCEC_TX_STATUS_OK: 227*4882a593Smuzhiyun the transmit was successful. 228*4882a593Smuzhiyun 229*4882a593SmuzhiyunCEC_TX_STATUS_ARB_LOST: 230*4882a593Smuzhiyun arbitration was lost: another CEC initiator 231*4882a593Smuzhiyun took control of the CEC line and you lost the arbitration. 232*4882a593Smuzhiyun 233*4882a593SmuzhiyunCEC_TX_STATUS_NACK: 234*4882a593Smuzhiyun the message was nacked (for a directed message) or 235*4882a593Smuzhiyun acked (for a broadcast message). A retransmission is needed. 236*4882a593Smuzhiyun 237*4882a593SmuzhiyunCEC_TX_STATUS_LOW_DRIVE: 238*4882a593Smuzhiyun low drive was detected on the CEC bus. This indicates that 239*4882a593Smuzhiyun a follower detected an error on the bus and requested a 240*4882a593Smuzhiyun retransmission. 241*4882a593Smuzhiyun 242*4882a593SmuzhiyunCEC_TX_STATUS_ERROR: 243*4882a593Smuzhiyun some unspecified error occurred: this can be one of ARB_LOST 244*4882a593Smuzhiyun or LOW_DRIVE if the hardware cannot differentiate or something 245*4882a593Smuzhiyun else entirely. Some hardware only supports OK and FAIL as the 246*4882a593Smuzhiyun result of a transmit, i.e. there is no way to differentiate 247*4882a593Smuzhiyun between the different possible errors. In that case map FAIL 248*4882a593Smuzhiyun to CEC_TX_STATUS_NACK and not to CEC_TX_STATUS_ERROR. 249*4882a593Smuzhiyun 250*4882a593SmuzhiyunCEC_TX_STATUS_MAX_RETRIES: 251*4882a593Smuzhiyun could not transmit the message after trying multiple times. 252*4882a593Smuzhiyun Should only be set by the driver if it has hardware support for 253*4882a593Smuzhiyun retrying messages. If set, then the framework assumes that it 254*4882a593Smuzhiyun doesn't have to make another attempt to transmit the message 255*4882a593Smuzhiyun since the hardware did that already. 256*4882a593Smuzhiyun 257*4882a593SmuzhiyunThe hardware must be able to differentiate between OK, NACK and 'something 258*4882a593Smuzhiyunelse'. 259*4882a593Smuzhiyun 260*4882a593SmuzhiyunThe \*_cnt arguments are the number of error conditions that were seen. 261*4882a593SmuzhiyunThis may be 0 if no information is available. Drivers that do not support 262*4882a593Smuzhiyunhardware retry can just set the counter corresponding to the transmit error 263*4882a593Smuzhiyunto 1, if the hardware does support retry then either set these counters to 264*4882a593Smuzhiyun0 if the hardware provides no feedback of which errors occurred and how many 265*4882a593Smuzhiyuntimes, or fill in the correct values as reported by the hardware. 266*4882a593Smuzhiyun 267*4882a593SmuzhiyunBe aware that calling these functions can immediately start a new transmit 268*4882a593Smuzhiyunif there is one pending in the queue. So make sure that the hardware is in 269*4882a593Smuzhiyuna state where new transmits can be started *before* calling these functions. 270*4882a593Smuzhiyun 271*4882a593SmuzhiyunThe cec_transmit_attempt_done() function is a helper for cases where the 272*4882a593Smuzhiyunhardware never retries, so the transmit is always for just a single 273*4882a593Smuzhiyunattempt. It will call cec_transmit_done() in turn, filling in 1 for the 274*4882a593Smuzhiyuncount argument corresponding to the status. Or all 0 if the status was OK. 275*4882a593Smuzhiyun 276*4882a593SmuzhiyunWhen a CEC message was received: 277*4882a593Smuzhiyun 278*4882a593Smuzhiyun.. c:function:: 279*4882a593Smuzhiyun void cec_received_msg(struct cec_adapter *adap, struct cec_msg *msg); 280*4882a593Smuzhiyun 281*4882a593SmuzhiyunSpeaks for itself. 282*4882a593Smuzhiyun 283*4882a593SmuzhiyunImplementing the interrupt handler 284*4882a593Smuzhiyun---------------------------------- 285*4882a593Smuzhiyun 286*4882a593SmuzhiyunTypically the CEC hardware provides interrupts that signal when a transmit 287*4882a593Smuzhiyunfinished and whether it was successful or not, and it provides and interrupt 288*4882a593Smuzhiyunwhen a CEC message was received. 289*4882a593Smuzhiyun 290*4882a593SmuzhiyunThe CEC driver should always process the transmit interrupts first before 291*4882a593Smuzhiyunhandling the receive interrupt. The framework expects to see the cec_transmit_done 292*4882a593Smuzhiyuncall before the cec_received_msg call, otherwise it can get confused if the 293*4882a593Smuzhiyunreceived message was in reply to the transmitted message. 294*4882a593Smuzhiyun 295*4882a593SmuzhiyunOptional: Implementing Error Injection Support 296*4882a593Smuzhiyun---------------------------------------------- 297*4882a593Smuzhiyun 298*4882a593SmuzhiyunIf the CEC adapter supports Error Injection functionality, then that can 299*4882a593Smuzhiyunbe exposed through the Error Injection callbacks: 300*4882a593Smuzhiyun 301*4882a593Smuzhiyun.. code-block:: none 302*4882a593Smuzhiyun 303*4882a593Smuzhiyun struct cec_adap_ops { 304*4882a593Smuzhiyun /* Low-level callbacks */ 305*4882a593Smuzhiyun ... 306*4882a593Smuzhiyun 307*4882a593Smuzhiyun /* Error injection callbacks */ 308*4882a593Smuzhiyun int (*error_inj_show)(struct cec_adapter *adap, struct seq_file *sf); 309*4882a593Smuzhiyun bool (*error_inj_parse_line)(struct cec_adapter *adap, char *line); 310*4882a593Smuzhiyun 311*4882a593Smuzhiyun /* High-level CEC message callback */ 312*4882a593Smuzhiyun ... 313*4882a593Smuzhiyun }; 314*4882a593Smuzhiyun 315*4882a593SmuzhiyunIf both callbacks are set, then an ``error-inj`` file will appear in debugfs. 316*4882a593SmuzhiyunThe basic syntax is as follows: 317*4882a593Smuzhiyun 318*4882a593SmuzhiyunLeading spaces/tabs are ignored. If the next character is a ``#`` or the end of the 319*4882a593Smuzhiyunline was reached, then the whole line is ignored. Otherwise a command is expected. 320*4882a593Smuzhiyun 321*4882a593SmuzhiyunThis basic parsing is done in the CEC Framework. It is up to the driver to decide 322*4882a593Smuzhiyunwhat commands to implement. The only requirement is that the command ``clear`` without 323*4882a593Smuzhiyunany arguments must be implemented and that it will remove all current error injection 324*4882a593Smuzhiyuncommands. 325*4882a593Smuzhiyun 326*4882a593SmuzhiyunThis ensures that you can always do ``echo clear >error-inj`` to clear any error 327*4882a593Smuzhiyuninjections without having to know the details of the driver-specific commands. 328*4882a593Smuzhiyun 329*4882a593SmuzhiyunNote that the output of ``error-inj`` shall be valid as input to ``error-inj``. 330*4882a593SmuzhiyunSo this must work: 331*4882a593Smuzhiyun 332*4882a593Smuzhiyun.. code-block:: none 333*4882a593Smuzhiyun 334*4882a593Smuzhiyun $ cat error-inj >einj.txt 335*4882a593Smuzhiyun $ cat einj.txt >error-inj 336*4882a593Smuzhiyun 337*4882a593SmuzhiyunThe first callback is called when this file is read and it should show the 338*4882a593Smuzhiyunthe current error injection state:: 339*4882a593Smuzhiyun 340*4882a593Smuzhiyun int (*error_inj_show)(struct cec_adapter *adap, struct seq_file *sf); 341*4882a593Smuzhiyun 342*4882a593SmuzhiyunIt is recommended that it starts with a comment block with basic usage 343*4882a593Smuzhiyuninformation. It returns 0 for success and an error otherwise. 344*4882a593Smuzhiyun 345*4882a593SmuzhiyunThe second callback will parse commands written to the ``error-inj`` file:: 346*4882a593Smuzhiyun 347*4882a593Smuzhiyun bool (*error_inj_parse_line)(struct cec_adapter *adap, char *line); 348*4882a593Smuzhiyun 349*4882a593SmuzhiyunThe ``line`` argument points to the start of the command. Any leading 350*4882a593Smuzhiyunspaces or tabs have already been skipped. It is a single line only (so there 351*4882a593Smuzhiyunare no embedded newlines) and it is 0-terminated. The callback is free to 352*4882a593Smuzhiyunmodify the contents of the buffer. It is only called for lines containing a 353*4882a593Smuzhiyuncommand, so this callback is never called for empty lines or comment lines. 354*4882a593Smuzhiyun 355*4882a593SmuzhiyunReturn true if the command was valid or false if there were syntax errors. 356*4882a593Smuzhiyun 357*4882a593SmuzhiyunImplementing the High-Level CEC Adapter 358*4882a593Smuzhiyun--------------------------------------- 359*4882a593Smuzhiyun 360*4882a593SmuzhiyunThe low-level operations drive the hardware, the high-level operations are 361*4882a593SmuzhiyunCEC protocol driven. The following high-level callbacks are available: 362*4882a593Smuzhiyun 363*4882a593Smuzhiyun.. code-block:: none 364*4882a593Smuzhiyun 365*4882a593Smuzhiyun struct cec_adap_ops { 366*4882a593Smuzhiyun /* Low-level callbacks */ 367*4882a593Smuzhiyun ... 368*4882a593Smuzhiyun 369*4882a593Smuzhiyun /* Error injection callbacks */ 370*4882a593Smuzhiyun ... 371*4882a593Smuzhiyun 372*4882a593Smuzhiyun /* High-level CEC message callback */ 373*4882a593Smuzhiyun int (*received)(struct cec_adapter *adap, struct cec_msg *msg); 374*4882a593Smuzhiyun }; 375*4882a593Smuzhiyun 376*4882a593SmuzhiyunThe received() callback allows the driver to optionally handle a newly 377*4882a593Smuzhiyunreceived CEC message:: 378*4882a593Smuzhiyun 379*4882a593Smuzhiyun int (*received)(struct cec_adapter *adap, struct cec_msg *msg); 380*4882a593Smuzhiyun 381*4882a593SmuzhiyunIf the driver wants to process a CEC message, then it can implement this 382*4882a593Smuzhiyuncallback. If it doesn't want to handle this message, then it should return 383*4882a593Smuzhiyun-ENOMSG, otherwise the CEC framework assumes it processed this message and 384*4882a593Smuzhiyunit will not do anything with it. 385*4882a593Smuzhiyun 386*4882a593Smuzhiyun 387*4882a593SmuzhiyunCEC framework functions 388*4882a593Smuzhiyun----------------------- 389*4882a593Smuzhiyun 390*4882a593SmuzhiyunCEC Adapter drivers can call the following CEC framework functions: 391*4882a593Smuzhiyun 392*4882a593Smuzhiyun.. c:function:: 393*4882a593Smuzhiyun int cec_transmit_msg(struct cec_adapter *adap, struct cec_msg *msg, \ 394*4882a593Smuzhiyun bool block); 395*4882a593Smuzhiyun 396*4882a593SmuzhiyunTransmit a CEC message. If block is true, then wait until the message has been 397*4882a593Smuzhiyuntransmitted, otherwise just queue it and return. 398*4882a593Smuzhiyun 399*4882a593Smuzhiyun.. c:function:: 400*4882a593Smuzhiyun void cec_s_phys_addr(struct cec_adapter *adap, u16 phys_addr, bool block); 401*4882a593Smuzhiyun 402*4882a593SmuzhiyunChange the physical address. This function will set adap->phys_addr and 403*4882a593Smuzhiyunsend an event if it has changed. If cec_s_log_addrs() has been called and 404*4882a593Smuzhiyunthe physical address has become valid, then the CEC framework will start 405*4882a593Smuzhiyunclaiming the logical addresses. If block is true, then this function won't 406*4882a593Smuzhiyunreturn until this process has finished. 407*4882a593Smuzhiyun 408*4882a593SmuzhiyunWhen the physical address is set to a valid value the CEC adapter will 409*4882a593Smuzhiyunbe enabled (see the adap_enable op). When it is set to CEC_PHYS_ADDR_INVALID, 410*4882a593Smuzhiyunthen the CEC adapter will be disabled. If you change a valid physical address 411*4882a593Smuzhiyunto another valid physical address, then this function will first set the 412*4882a593Smuzhiyunaddress to CEC_PHYS_ADDR_INVALID before enabling the new physical address. 413*4882a593Smuzhiyun 414*4882a593Smuzhiyun.. c:function:: 415*4882a593Smuzhiyun void cec_s_phys_addr_from_edid(struct cec_adapter *adap, \ 416*4882a593Smuzhiyun const struct edid *edid); 417*4882a593Smuzhiyun 418*4882a593SmuzhiyunA helper function that extracts the physical address from the edid struct 419*4882a593Smuzhiyunand calls cec_s_phys_addr() with that address, or CEC_PHYS_ADDR_INVALID 420*4882a593Smuzhiyunif the EDID did not contain a physical address or edid was a NULL pointer. 421*4882a593Smuzhiyun 422*4882a593Smuzhiyun.. c:function:: 423*4882a593Smuzhiyun int cec_s_log_addrs(struct cec_adapter *adap, \ 424*4882a593Smuzhiyun struct cec_log_addrs *log_addrs, bool block); 425*4882a593Smuzhiyun 426*4882a593SmuzhiyunClaim the CEC logical addresses. Should never be called if CEC_CAP_LOG_ADDRS 427*4882a593Smuzhiyunis set. If block is true, then wait until the logical addresses have been 428*4882a593Smuzhiyunclaimed, otherwise just queue it and return. To unconfigure all logical 429*4882a593Smuzhiyunaddresses call this function with log_addrs set to NULL or with 430*4882a593Smuzhiyunlog_addrs->num_log_addrs set to 0. The block argument is ignored when 431*4882a593Smuzhiyununconfiguring. This function will just return if the physical address is 432*4882a593Smuzhiyuninvalid. Once the physical address becomes valid, then the framework will 433*4882a593Smuzhiyunattempt to claim these logical addresses. 434*4882a593Smuzhiyun 435*4882a593SmuzhiyunCEC Pin framework 436*4882a593Smuzhiyun----------------- 437*4882a593Smuzhiyun 438*4882a593SmuzhiyunMost CEC hardware operates on full CEC messages where the software provides 439*4882a593Smuzhiyunthe message and the hardware handles the low-level CEC protocol. But some 440*4882a593Smuzhiyunhardware only drives the CEC pin and software has to handle the low-level 441*4882a593SmuzhiyunCEC protocol. The CEC pin framework was created to handle such devices. 442*4882a593Smuzhiyun 443*4882a593SmuzhiyunNote that due to the close-to-realtime requirements it can never be guaranteed 444*4882a593Smuzhiyunto work 100%. This framework uses highres timers internally, but if a 445*4882a593Smuzhiyuntimer goes off too late by more than 300 microseconds wrong results can 446*4882a593Smuzhiyunoccur. In reality it appears to be fairly reliable. 447*4882a593Smuzhiyun 448*4882a593SmuzhiyunOne advantage of this low-level implementation is that it can be used as 449*4882a593Smuzhiyuna cheap CEC analyser, especially if interrupts can be used to detect 450*4882a593SmuzhiyunCEC pin transitions from low to high or vice versa. 451*4882a593Smuzhiyun 452*4882a593Smuzhiyun.. kernel-doc:: include/media/cec-pin.h 453*4882a593Smuzhiyun 454*4882a593SmuzhiyunCEC Notifier framework 455*4882a593Smuzhiyun---------------------- 456*4882a593Smuzhiyun 457*4882a593SmuzhiyunMost drm HDMI implementations have an integrated CEC implementation and no 458*4882a593Smuzhiyunnotifier support is needed. But some have independent CEC implementations 459*4882a593Smuzhiyunthat have their own driver. This could be an IP block for an SoC or a 460*4882a593Smuzhiyuncompletely separate chip that deals with the CEC pin. For those cases a 461*4882a593Smuzhiyundrm driver can install a notifier and use the notifier to inform the 462*4882a593SmuzhiyunCEC driver about changes in the physical address. 463*4882a593Smuzhiyun 464*4882a593Smuzhiyun.. kernel-doc:: include/media/cec-notifier.h 465