Hans Verkuil | ab15d24 | 2018-02-07 09:05:46 -0500 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 2 | /* |
| 3 | * cec - HDMI Consumer Electronics Control support header |
| 4 | * |
| 5 | * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved. |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef _MEDIA_CEC_H |
| 9 | #define _MEDIA_CEC_H |
| 10 | |
| 11 | #include <linux/poll.h> |
| 12 | #include <linux/fs.h> |
| 13 | #include <linux/debugfs.h> |
| 14 | #include <linux/device.h> |
| 15 | #include <linux/cdev.h> |
| 16 | #include <linux/kthread.h> |
| 17 | #include <linux/timer.h> |
| 18 | #include <linux/cec-funcs.h> |
| 19 | #include <media/rc-core.h> |
Dariusz Marcinkiewicz | 32a847f | 2019-06-20 05:17:18 -0400 | [diff] [blame] | 20 | |
| 21 | /* CEC_ADAP_G_CONNECTOR_INFO is available */ |
| 22 | #define CEC_CAP_CONNECTOR_INFO (1 << 8) |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 23 | |
Hans Verkuil | ee0c503 | 2017-08-04 06:41:51 -0400 | [diff] [blame] | 24 | #define CEC_CAP_DEFAULTS (CEC_CAP_LOG_ADDRS | CEC_CAP_TRANSMIT | \ |
| 25 | CEC_CAP_PASSTHROUGH | CEC_CAP_RC) |
| 26 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 27 | /** |
| 28 | * struct cec_devnode - cec device node |
| 29 | * @dev: cec device |
| 30 | * @cdev: cec character device |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 31 | * @minor: device node minor number |
| 32 | * @registered: the device was correctly registered |
| 33 | * @unregistered: the device was unregistered |
| 34 | * @fhs_lock: lock to control access to the filehandle list |
| 35 | * @fhs: the list of open filehandles (cec_fh) |
| 36 | * |
| 37 | * This structure represents a cec-related device node. |
| 38 | * |
| 39 | * The @parent is a physical device. It must be set by core or device drivers |
| 40 | * before registering the node. |
| 41 | */ |
| 42 | struct cec_devnode { |
| 43 | /* sysfs */ |
| 44 | struct device dev; |
| 45 | struct cdev cdev; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 46 | |
| 47 | /* device info */ |
| 48 | int minor; |
| 49 | bool registered; |
| 50 | bool unregistered; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 51 | struct list_head fhs; |
Hans Verkuil | 62148f0 | 2016-08-02 08:11:00 -0300 | [diff] [blame] | 52 | struct mutex lock; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | struct cec_adapter; |
| 56 | struct cec_data; |
Hans Verkuil | ea5c8ef | 2017-07-11 03:30:42 -0300 | [diff] [blame] | 57 | struct cec_pin; |
Dariusz Marcinkiewicz | 32a847f | 2019-06-20 05:17:18 -0400 | [diff] [blame] | 58 | struct cec_notifier; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 59 | |
| 60 | struct cec_data { |
| 61 | struct list_head list; |
| 62 | struct list_head xfer_list; |
| 63 | struct cec_adapter *adap; |
| 64 | struct cec_msg msg; |
| 65 | struct cec_fh *fh; |
| 66 | struct delayed_work work; |
| 67 | struct completion c; |
| 68 | u8 attempts; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 69 | bool blocking; |
| 70 | bool completed; |
| 71 | }; |
| 72 | |
| 73 | struct cec_msg_entry { |
| 74 | struct list_head list; |
| 75 | struct cec_msg msg; |
| 76 | }; |
| 77 | |
Hans Verkuil | 6b2bbb0 | 2017-07-11 03:30:39 -0300 | [diff] [blame] | 78 | struct cec_event_entry { |
| 79 | struct list_head list; |
| 80 | struct cec_event ev; |
| 81 | }; |
| 82 | |
| 83 | #define CEC_NUM_CORE_EVENTS 2 |
Hans Verkuil | 4786b0d | 2018-06-28 07:43:46 -0400 | [diff] [blame] | 84 | #define CEC_NUM_EVENTS CEC_EVENT_PIN_5V_HIGH |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 85 | |
| 86 | struct cec_fh { |
| 87 | struct list_head list; |
| 88 | struct list_head xfer_list; |
| 89 | struct cec_adapter *adap; |
| 90 | u8 mode_initiator; |
| 91 | u8 mode_follower; |
| 92 | |
| 93 | /* Events */ |
| 94 | wait_queue_head_t wait; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 95 | struct mutex lock; |
Hans Verkuil | 6b2bbb0 | 2017-07-11 03:30:39 -0300 | [diff] [blame] | 96 | struct list_head events[CEC_NUM_EVENTS]; /* queued events */ |
Hans Verkuil | 6ec1cbf | 2018-03-06 16:20:00 -0500 | [diff] [blame] | 97 | u16 queued_events[CEC_NUM_EVENTS]; |
Hans Verkuil | 6b2bbb0 | 2017-07-11 03:30:39 -0300 | [diff] [blame] | 98 | unsigned int total_queued_events; |
| 99 | struct cec_event_entry core_events[CEC_NUM_CORE_EVENTS]; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 100 | struct list_head msgs; /* queued messages */ |
| 101 | unsigned int queued_msgs; |
| 102 | }; |
| 103 | |
| 104 | #define CEC_SIGNAL_FREE_TIME_RETRY 3 |
| 105 | #define CEC_SIGNAL_FREE_TIME_NEW_INITIATOR 5 |
| 106 | #define CEC_SIGNAL_FREE_TIME_NEXT_XFER 7 |
| 107 | |
| 108 | /* The nominal data bit period is 2.4 ms */ |
| 109 | #define CEC_FREE_TIME_TO_USEC(ft) ((ft) * 2400) |
| 110 | |
| 111 | struct cec_adap_ops { |
| 112 | /* Low-level callbacks */ |
| 113 | int (*adap_enable)(struct cec_adapter *adap, bool enable); |
| 114 | int (*adap_monitor_all_enable)(struct cec_adapter *adap, bool enable); |
Hans Verkuil | 48ea2e9 | 2017-11-05 07:36:36 -0500 | [diff] [blame] | 115 | int (*adap_monitor_pin_enable)(struct cec_adapter *adap, bool enable); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 116 | int (*adap_log_addr)(struct cec_adapter *adap, u8 logical_addr); |
| 117 | int (*adap_transmit)(struct cec_adapter *adap, u8 attempts, |
| 118 | u32 signal_free_time, struct cec_msg *msg); |
| 119 | void (*adap_status)(struct cec_adapter *adap, struct seq_file *file); |
Hans Verkuil | e6259b5 | 2017-07-11 03:30:36 -0300 | [diff] [blame] | 120 | void (*adap_free)(struct cec_adapter *adap); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 121 | |
Hans Verkuil | 9ca400c | 2017-10-31 09:55:09 -0400 | [diff] [blame] | 122 | /* Error injection callbacks */ |
| 123 | int (*error_inj_show)(struct cec_adapter *adap, struct seq_file *sf); |
| 124 | bool (*error_inj_parse_line)(struct cec_adapter *adap, char *line); |
| 125 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 126 | /* High-level CEC message callback */ |
| 127 | int (*received)(struct cec_adapter *adap, struct cec_msg *msg); |
| 128 | }; |
| 129 | |
| 130 | /* |
| 131 | * The minimum message length you can receive (excepting poll messages) is 2. |
| 132 | * With a transfer rate of at most 36 bytes per second this makes 18 messages |
| 133 | * per second worst case. |
| 134 | * |
Hans Verkuil | 11065f8 | 2016-07-17 11:40:05 -0300 | [diff] [blame] | 135 | * We queue at most 3 seconds worth of received messages. The CEC specification |
| 136 | * requires that messages are replied to within a second, so 3 seconds should |
| 137 | * give more than enough margin. Since most messages are actually more than 2 |
| 138 | * bytes, this is in practice a lot more than 3 seconds. |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 139 | */ |
Hans Verkuil | 11065f8 | 2016-07-17 11:40:05 -0300 | [diff] [blame] | 140 | #define CEC_MAX_MSG_RX_QUEUE_SZ (18 * 3) |
| 141 | |
| 142 | /* |
| 143 | * The transmit queue is limited to 1 second worth of messages (worst case). |
| 144 | * Messages can be transmitted by userspace and kernel space. But for both it |
| 145 | * makes no sense to have a lot of messages queued up. One second seems |
| 146 | * reasonable. |
| 147 | */ |
| 148 | #define CEC_MAX_MSG_TX_QUEUE_SZ (18 * 1) |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 149 | |
Dariusz Marcinkiewicz | 32a847f | 2019-06-20 05:17:18 -0400 | [diff] [blame] | 150 | /** |
| 151 | * struct cec_drm_connector_info - tells which drm connector is |
| 152 | * associated with the CEC adapter. |
| 153 | * @card_no: drm card number |
| 154 | * @connector_id: drm connector ID |
| 155 | */ |
| 156 | struct cec_drm_connector_info { |
| 157 | __u32 card_no; |
| 158 | __u32 connector_id; |
| 159 | }; |
| 160 | |
| 161 | #define CEC_CONNECTOR_TYPE_NO_CONNECTOR 0 |
| 162 | #define CEC_CONNECTOR_TYPE_DRM 1 |
| 163 | |
| 164 | /** |
| 165 | * struct cec_connector_info - tells if and which connector is |
| 166 | * associated with the CEC adapter. |
| 167 | * @type: connector type (if any) |
| 168 | * @drm: drm connector info |
| 169 | */ |
| 170 | struct cec_connector_info { |
| 171 | __u32 type; |
| 172 | union { |
| 173 | struct cec_drm_connector_info drm; |
| 174 | __u32 raw[16]; |
| 175 | }; |
| 176 | }; |
| 177 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 178 | struct cec_adapter { |
| 179 | struct module *owner; |
| 180 | char name[32]; |
| 181 | struct cec_devnode devnode; |
| 182 | struct mutex lock; |
| 183 | struct rc_dev *rc; |
| 184 | |
| 185 | struct list_head transmit_queue; |
Hans Verkuil | 11065f8 | 2016-07-17 11:40:05 -0300 | [diff] [blame] | 186 | unsigned int transmit_queue_sz; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 187 | struct list_head wait_queue; |
| 188 | struct cec_data *transmitting; |
Hans Verkuil | 32804fc | 2018-10-19 03:55:34 -0400 | [diff] [blame] | 189 | bool transmit_in_progress; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 190 | |
| 191 | struct task_struct *kthread_config; |
| 192 | struct completion config_completion; |
| 193 | |
| 194 | struct task_struct *kthread; |
| 195 | wait_queue_head_t kthread_waitq; |
| 196 | wait_queue_head_t waitq; |
| 197 | |
| 198 | const struct cec_adap_ops *ops; |
| 199 | void *priv; |
| 200 | u32 capabilities; |
| 201 | u8 available_log_addrs; |
| 202 | |
| 203 | u16 phys_addr; |
Hans Verkuil | f902c1e | 2017-06-07 11:46:12 -0300 | [diff] [blame] | 204 | bool needs_hpd; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 205 | bool is_configuring; |
| 206 | bool is_configured; |
Hans Verkuil | 28e11b1 | 2017-08-20 06:53:10 -0400 | [diff] [blame] | 207 | bool cec_pin_is_high; |
Hans Verkuil | 7d867a1 | 2018-10-05 08:00:21 -0400 | [diff] [blame] | 208 | u8 last_initiator; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 209 | u32 monitor_all_cnt; |
Hans Verkuil | b8d62f5 | 2017-07-11 03:30:41 -0300 | [diff] [blame] | 210 | u32 monitor_pin_cnt; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 211 | u32 follower_cnt; |
| 212 | struct cec_fh *cec_follower; |
| 213 | struct cec_fh *cec_initiator; |
| 214 | bool passthrough; |
| 215 | struct cec_log_addrs log_addrs; |
Dariusz Marcinkiewicz | 32a847f | 2019-06-20 05:17:18 -0400 | [diff] [blame] | 216 | struct cec_connector_info conn_info; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 217 | |
Hans Verkuil | bb789e0 | 2017-07-11 03:30:34 -0300 | [diff] [blame] | 218 | u32 tx_timeouts; |
| 219 | |
Hans Verkuil | e94c328 | 2017-05-28 05:58:04 -0300 | [diff] [blame] | 220 | #ifdef CONFIG_CEC_NOTIFIER |
Hans Verkuil | e3a93ad | 2016-12-13 12:15:57 -0200 | [diff] [blame] | 221 | struct cec_notifier *notifier; |
| 222 | #endif |
Hans Verkuil | ea5c8ef | 2017-07-11 03:30:42 -0300 | [diff] [blame] | 223 | #ifdef CONFIG_CEC_PIN |
| 224 | struct cec_pin *pin; |
| 225 | #endif |
Hans Verkuil | e3a93ad | 2016-12-13 12:15:57 -0200 | [diff] [blame] | 226 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 227 | struct dentry *cec_dir; |
| 228 | struct dentry *status_file; |
Hans Verkuil | 9ca400c | 2017-10-31 09:55:09 -0400 | [diff] [blame] | 229 | struct dentry *error_inj_file; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 230 | |
| 231 | u16 phys_addrs[15]; |
| 232 | u32 sequence; |
| 233 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 234 | char input_phys[32]; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 235 | }; |
| 236 | |
Jose Abreu | 0b0b97d | 2017-03-24 13:47:52 -0300 | [diff] [blame] | 237 | static inline void *cec_get_drvdata(const struct cec_adapter *adap) |
| 238 | { |
| 239 | return adap->priv; |
| 240 | } |
| 241 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 242 | static inline bool cec_has_log_addr(const struct cec_adapter *adap, u8 log_addr) |
| 243 | { |
| 244 | return adap->log_addrs.log_addr_mask & (1 << log_addr); |
| 245 | } |
| 246 | |
| 247 | static inline bool cec_is_sink(const struct cec_adapter *adap) |
| 248 | { |
| 249 | return adap->phys_addr == 0; |
| 250 | } |
| 251 | |
Hans Verkuil | c8959a3 | 2017-11-22 04:12:39 -0500 | [diff] [blame] | 252 | /** |
| 253 | * cec_is_registered() - is the CEC adapter registered? |
| 254 | * |
| 255 | * @adap: the CEC adapter, may be NULL. |
| 256 | * |
| 257 | * Return: true if the adapter is registered, false otherwise. |
| 258 | */ |
| 259 | static inline bool cec_is_registered(const struct cec_adapter *adap) |
| 260 | { |
| 261 | return adap && adap->devnode.registered; |
| 262 | } |
| 263 | |
Hans Verkuil | ee7e9871 | 2017-04-17 07:54:37 -0300 | [diff] [blame] | 264 | #define cec_phys_addr_exp(pa) \ |
| 265 | ((pa) >> 12), ((pa) >> 8) & 0xf, ((pa) >> 4) & 0xf, (pa) & 0xf |
| 266 | |
Hans Verkuil | 23111ec | 2017-06-07 11:46:08 -0300 | [diff] [blame] | 267 | struct edid; |
Dariusz Marcinkiewicz | 32a847f | 2019-06-20 05:17:18 -0400 | [diff] [blame] | 268 | struct drm_connector; |
Hans Verkuil | 23111ec | 2017-06-07 11:46:08 -0300 | [diff] [blame] | 269 | |
Hans Verkuil | f9f314f | 2017-06-08 15:37:44 -0300 | [diff] [blame] | 270 | #if IS_REACHABLE(CONFIG_CEC_CORE) |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 271 | struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops, |
Hans Verkuil | f51e808 | 2016-11-25 06:23:34 -0200 | [diff] [blame] | 272 | void *priv, const char *name, u32 caps, u8 available_las); |
| 273 | int cec_register_adapter(struct cec_adapter *adap, struct device *parent); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 274 | void cec_unregister_adapter(struct cec_adapter *adap); |
| 275 | void cec_delete_adapter(struct cec_adapter *adap); |
| 276 | |
| 277 | int cec_s_log_addrs(struct cec_adapter *adap, struct cec_log_addrs *log_addrs, |
| 278 | bool block); |
| 279 | void cec_s_phys_addr(struct cec_adapter *adap, u16 phys_addr, |
| 280 | bool block); |
Hans Verkuil | 23111ec | 2017-06-07 11:46:08 -0300 | [diff] [blame] | 281 | void cec_s_phys_addr_from_edid(struct cec_adapter *adap, |
| 282 | const struct edid *edid); |
Dariusz Marcinkiewicz | 32a847f | 2019-06-20 05:17:18 -0400 | [diff] [blame] | 283 | void cec_s_conn_info(struct cec_adapter *adap, |
| 284 | const struct cec_connector_info *conn_info); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 285 | int cec_transmit_msg(struct cec_adapter *adap, struct cec_msg *msg, |
| 286 | bool block); |
| 287 | |
| 288 | /* Called by the adapter */ |
Hans Verkuil | 0861ad1 | 2017-07-11 03:30:35 -0300 | [diff] [blame] | 289 | void cec_transmit_done_ts(struct cec_adapter *adap, u8 status, |
| 290 | u8 arb_lost_cnt, u8 nack_cnt, u8 low_drive_cnt, |
| 291 | u8 error_cnt, ktime_t ts); |
| 292 | |
| 293 | static inline void cec_transmit_done(struct cec_adapter *adap, u8 status, |
| 294 | u8 arb_lost_cnt, u8 nack_cnt, |
| 295 | u8 low_drive_cnt, u8 error_cnt) |
| 296 | { |
| 297 | cec_transmit_done_ts(adap, status, arb_lost_cnt, nack_cnt, |
| 298 | low_drive_cnt, error_cnt, ktime_get()); |
| 299 | } |
Hans Verkuil | c94cdc1 | 2017-06-07 11:46:10 -0300 | [diff] [blame] | 300 | /* |
| 301 | * Simplified version of cec_transmit_done for hardware that doesn't retry |
| 302 | * failed transmits. So this is always just one attempt in which case |
| 303 | * the status is sufficient. |
| 304 | */ |
Hans Verkuil | 0861ad1 | 2017-07-11 03:30:35 -0300 | [diff] [blame] | 305 | void cec_transmit_attempt_done_ts(struct cec_adapter *adap, |
| 306 | u8 status, ktime_t ts); |
| 307 | |
| 308 | static inline void cec_transmit_attempt_done(struct cec_adapter *adap, |
| 309 | u8 status) |
| 310 | { |
| 311 | cec_transmit_attempt_done_ts(adap, status, ktime_get()); |
| 312 | } |
| 313 | |
| 314 | void cec_received_msg_ts(struct cec_adapter *adap, |
| 315 | struct cec_msg *msg, ktime_t ts); |
| 316 | |
| 317 | static inline void cec_received_msg(struct cec_adapter *adap, |
| 318 | struct cec_msg *msg) |
| 319 | { |
| 320 | cec_received_msg_ts(adap, msg, ktime_get()); |
| 321 | } |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 322 | |
Hans Verkuil | ee7e9871 | 2017-04-17 07:54:37 -0300 | [diff] [blame] | 323 | /** |
Hans Verkuil | 9a6b2a8 | 2017-08-15 15:26:25 -0400 | [diff] [blame] | 324 | * cec_queue_pin_cec_event() - queue a CEC pin event with a given timestamp. |
Hans Verkuil | b8d62f5 | 2017-07-11 03:30:41 -0300 | [diff] [blame] | 325 | * |
| 326 | * @adap: pointer to the cec adapter |
Hans Verkuil | 9a6b2a8 | 2017-08-15 15:26:25 -0400 | [diff] [blame] | 327 | * @is_high: when true the CEC pin is high, otherwise it is low |
Hans Verkuil | 6ec1cbf | 2018-03-06 16:20:00 -0500 | [diff] [blame] | 328 | * @dropped_events: when true some events were dropped |
Hans Verkuil | b8d62f5 | 2017-07-11 03:30:41 -0300 | [diff] [blame] | 329 | * @ts: the timestamp for this event |
| 330 | * |
| 331 | */ |
Hans Verkuil | 6ec1cbf | 2018-03-06 16:20:00 -0500 | [diff] [blame] | 332 | void cec_queue_pin_cec_event(struct cec_adapter *adap, bool is_high, |
| 333 | bool dropped_events, ktime_t ts); |
Hans Verkuil | b8d62f5 | 2017-07-11 03:30:41 -0300 | [diff] [blame] | 334 | |
| 335 | /** |
Hans Verkuil | 333ef6b | 2017-08-15 10:07:25 -0400 | [diff] [blame] | 336 | * cec_queue_pin_hpd_event() - queue a pin event with a given timestamp. |
| 337 | * |
| 338 | * @adap: pointer to the cec adapter |
| 339 | * @is_high: when true the HPD pin is high, otherwise it is low |
| 340 | * @ts: the timestamp for this event |
| 341 | * |
| 342 | */ |
| 343 | void cec_queue_pin_hpd_event(struct cec_adapter *adap, bool is_high, ktime_t ts); |
| 344 | |
| 345 | /** |
Hans Verkuil | 4786b0d | 2018-06-28 07:43:46 -0400 | [diff] [blame] | 346 | * cec_queue_pin_5v_event() - queue a pin event with a given timestamp. |
| 347 | * |
| 348 | * @adap: pointer to the cec adapter |
| 349 | * @is_high: when true the 5V pin is high, otherwise it is low |
| 350 | * @ts: the timestamp for this event |
| 351 | * |
| 352 | */ |
| 353 | void cec_queue_pin_5v_event(struct cec_adapter *adap, bool is_high, ktime_t ts); |
| 354 | |
| 355 | /** |
Hans Verkuil | ee7e9871 | 2017-04-17 07:54:37 -0300 | [diff] [blame] | 356 | * cec_get_edid_phys_addr() - find and return the physical address |
| 357 | * |
| 358 | * @edid: pointer to the EDID data |
| 359 | * @size: size in bytes of the EDID data |
| 360 | * @offset: If not %NULL then the location of the physical address |
| 361 | * bytes in the EDID will be returned here. This is set to 0 |
| 362 | * if there is no physical address found. |
| 363 | * |
| 364 | * Return: the physical address or CEC_PHYS_ADDR_INVALID if there is none. |
| 365 | */ |
| 366 | u16 cec_get_edid_phys_addr(const u8 *edid, unsigned int size, |
| 367 | unsigned int *offset); |
| 368 | |
Dariusz Marcinkiewicz | 32a847f | 2019-06-20 05:17:18 -0400 | [diff] [blame] | 369 | void cec_fill_conn_info_from_drm(struct cec_connector_info *conn_info, |
| 370 | const struct drm_connector *connector); |
| 371 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 372 | #else |
| 373 | |
Hans Verkuil | f51e808 | 2016-11-25 06:23:34 -0200 | [diff] [blame] | 374 | static inline int cec_register_adapter(struct cec_adapter *adap, |
| 375 | struct device *parent) |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 376 | { |
| 377 | return 0; |
| 378 | } |
| 379 | |
| 380 | static inline void cec_unregister_adapter(struct cec_adapter *adap) |
| 381 | { |
| 382 | } |
| 383 | |
| 384 | static inline void cec_delete_adapter(struct cec_adapter *adap) |
| 385 | { |
| 386 | } |
| 387 | |
| 388 | static inline void cec_s_phys_addr(struct cec_adapter *adap, u16 phys_addr, |
| 389 | bool block) |
| 390 | { |
| 391 | } |
| 392 | |
Hans Verkuil | 23111ec | 2017-06-07 11:46:08 -0300 | [diff] [blame] | 393 | static inline void cec_s_phys_addr_from_edid(struct cec_adapter *adap, |
| 394 | const struct edid *edid) |
| 395 | { |
| 396 | } |
| 397 | |
Hans Verkuil | ee7e9871 | 2017-04-17 07:54:37 -0300 | [diff] [blame] | 398 | static inline u16 cec_get_edid_phys_addr(const u8 *edid, unsigned int size, |
| 399 | unsigned int *offset) |
| 400 | { |
| 401 | if (offset) |
| 402 | *offset = 0; |
| 403 | return CEC_PHYS_ADDR_INVALID; |
| 404 | } |
| 405 | |
Dariusz Marcinkiewicz | 32a847f | 2019-06-20 05:17:18 -0400 | [diff] [blame] | 406 | static inline void cec_s_conn_info(struct cec_adapter *adap, |
| 407 | const struct cec_connector_info *conn_info) |
| 408 | { |
| 409 | } |
| 410 | |
| 411 | static inline void |
| 412 | cec_fill_conn_info_from_drm(struct cec_connector_info *conn_info, |
| 413 | const struct drm_connector *connector) |
| 414 | { |
| 415 | memset(conn_info, 0, sizeof(*conn_info)); |
| 416 | } |
| 417 | |
| 418 | #endif |
| 419 | |
| 420 | #if IS_REACHABLE(CONFIG_CEC_CORE) && IS_ENABLED(CONFIG_CEC_NOTIFIER) |
| 421 | |
| 422 | /** |
| 423 | * cec_notifier_register - register a callback with the notifier |
| 424 | * @n: the CEC notifier |
| 425 | * @adap: the CEC adapter, passed as argument to the callback function |
| 426 | * @callback: the callback function |
| 427 | */ |
| 428 | void cec_notifier_register(struct cec_notifier *n, |
| 429 | struct cec_adapter *adap, |
| 430 | void (*callback)(struct cec_adapter *adap, u16 pa)); |
| 431 | |
| 432 | /** |
| 433 | * cec_notifier_unregister - unregister the callback from the notifier. |
| 434 | * @n: the CEC notifier |
| 435 | */ |
| 436 | void cec_notifier_unregister(struct cec_notifier *n); |
| 437 | |
| 438 | /** |
| 439 | * cec_register_cec_notifier - register the notifier with the cec adapter. |
| 440 | * @adap: the CEC adapter |
| 441 | * @notifier: the CEC notifier |
| 442 | */ |
| 443 | void cec_register_cec_notifier(struct cec_adapter *adap, |
| 444 | struct cec_notifier *notifier); |
| 445 | |
| 446 | #else |
| 447 | |
| 448 | static inline void |
| 449 | cec_notifier_register(struct cec_notifier *n, |
| 450 | struct cec_adapter *adap, |
| 451 | void (*callback)(struct cec_adapter *adap, u16 pa)) |
| 452 | { |
| 453 | } |
| 454 | |
| 455 | static inline void cec_notifier_unregister(struct cec_notifier *n) |
| 456 | { |
| 457 | } |
| 458 | |
| 459 | static inline void cec_register_cec_notifier(struct cec_adapter *adap, |
| 460 | struct cec_notifier *notifier) |
| 461 | { |
| 462 | } |
| 463 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 464 | #endif |
| 465 | |
Hans Verkuil | 1353278 | 2017-06-07 11:46:09 -0300 | [diff] [blame] | 466 | /** |
| 467 | * cec_phys_addr_invalidate() - set the physical address to INVALID |
| 468 | * |
| 469 | * @adap: the CEC adapter |
| 470 | * |
| 471 | * This is a simple helper function to invalidate the physical |
| 472 | * address. |
| 473 | */ |
| 474 | static inline void cec_phys_addr_invalidate(struct cec_adapter *adap) |
| 475 | { |
| 476 | cec_s_phys_addr(adap, CEC_PHYS_ADDR_INVALID, false); |
| 477 | } |
| 478 | |
Hans Verkuil | b915bf57 | 2018-09-13 03:25:59 -0400 | [diff] [blame] | 479 | /** |
| 480 | * cec_get_edid_spa_location() - find location of the Source Physical Address |
| 481 | * |
| 482 | * @edid: the EDID |
| 483 | * @size: the size of the EDID |
| 484 | * |
| 485 | * This EDID is expected to be a CEA-861 compliant, which means that there are |
| 486 | * at least two blocks and one or more of the extensions blocks are CEA-861 |
| 487 | * blocks. |
| 488 | * |
| 489 | * The returned location is guaranteed to be <= size-2. |
| 490 | * |
| 491 | * This is an inline function since it is used by both CEC and V4L2. |
| 492 | * Ideally this would go in a module shared by both, but it is overkill to do |
| 493 | * that for just a single function. |
| 494 | */ |
| 495 | static inline unsigned int cec_get_edid_spa_location(const u8 *edid, |
| 496 | unsigned int size) |
| 497 | { |
| 498 | unsigned int blocks = size / 128; |
| 499 | unsigned int block; |
| 500 | u8 d; |
| 501 | |
| 502 | /* Sanity check: at least 2 blocks and a multiple of the block size */ |
| 503 | if (blocks < 2 || size % 128) |
| 504 | return 0; |
| 505 | |
| 506 | /* |
| 507 | * If there are fewer extension blocks than the size, then update |
| 508 | * 'blocks'. It is allowed to have more extension blocks than the size, |
| 509 | * since some hardware can only read e.g. 256 bytes of the EDID, even |
| 510 | * though more blocks are present. The first CEA-861 extension block |
| 511 | * should normally be in block 1 anyway. |
| 512 | */ |
| 513 | if (edid[0x7e] + 1 < blocks) |
| 514 | blocks = edid[0x7e] + 1; |
| 515 | |
| 516 | for (block = 1; block < blocks; block++) { |
| 517 | unsigned int offset = block * 128; |
| 518 | |
| 519 | /* Skip any non-CEA-861 extension blocks */ |
| 520 | if (edid[offset] != 0x02 || edid[offset + 1] != 0x03) |
| 521 | continue; |
| 522 | |
| 523 | /* search Vendor Specific Data Block (tag 3) */ |
| 524 | d = edid[offset + 2] & 0x7f; |
| 525 | /* Check if there are Data Blocks */ |
| 526 | if (d <= 4) |
| 527 | continue; |
| 528 | if (d > 4) { |
| 529 | unsigned int i = offset + 4; |
| 530 | unsigned int end = offset + d; |
| 531 | |
| 532 | /* Note: 'end' is always < 'size' */ |
| 533 | do { |
| 534 | u8 tag = edid[i] >> 5; |
| 535 | u8 len = edid[i] & 0x1f; |
| 536 | |
| 537 | if (tag == 3 && len >= 5 && i + len <= end && |
| 538 | edid[i + 1] == 0x03 && |
| 539 | edid[i + 2] == 0x0c && |
| 540 | edid[i + 3] == 0x00) |
| 541 | return i + 4; |
| 542 | i += len + 1; |
| 543 | } while (i < end); |
| 544 | } |
| 545 | } |
| 546 | return 0; |
| 547 | } |
| 548 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 549 | #endif /* _MEDIA_CEC_H */ |