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> |
Hans Verkuil | e3a93ad | 2016-12-13 12:15:57 -0200 | [diff] [blame] | 20 | #include <media/cec-notifier.h> |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 21 | |
Hans Verkuil | ee0c503 | 2017-08-04 06:41:51 -0400 | [diff] [blame] | 22 | #define CEC_CAP_DEFAULTS (CEC_CAP_LOG_ADDRS | CEC_CAP_TRANSMIT | \ |
| 23 | CEC_CAP_PASSTHROUGH | CEC_CAP_RC) |
| 24 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 25 | /** |
| 26 | * struct cec_devnode - cec device node |
| 27 | * @dev: cec device |
| 28 | * @cdev: cec character device |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 29 | * @minor: device node minor number |
| 30 | * @registered: the device was correctly registered |
| 31 | * @unregistered: the device was unregistered |
| 32 | * @fhs_lock: lock to control access to the filehandle list |
| 33 | * @fhs: the list of open filehandles (cec_fh) |
| 34 | * |
| 35 | * This structure represents a cec-related device node. |
| 36 | * |
| 37 | * The @parent is a physical device. It must be set by core or device drivers |
| 38 | * before registering the node. |
| 39 | */ |
| 40 | struct cec_devnode { |
| 41 | /* sysfs */ |
| 42 | struct device dev; |
| 43 | struct cdev cdev; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 44 | |
| 45 | /* device info */ |
| 46 | int minor; |
| 47 | bool registered; |
| 48 | bool unregistered; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 49 | struct list_head fhs; |
Hans Verkuil | 62148f0 | 2016-08-02 08:11:00 -0300 | [diff] [blame] | 50 | struct mutex lock; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | struct cec_adapter; |
| 54 | struct cec_data; |
Hans Verkuil | ea5c8ef | 2017-07-11 03:30:42 -0300 | [diff] [blame] | 55 | struct cec_pin; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 56 | |
| 57 | struct cec_data { |
| 58 | struct list_head list; |
| 59 | struct list_head xfer_list; |
| 60 | struct cec_adapter *adap; |
| 61 | struct cec_msg msg; |
| 62 | struct cec_fh *fh; |
| 63 | struct delayed_work work; |
| 64 | struct completion c; |
| 65 | u8 attempts; |
| 66 | bool new_initiator; |
| 67 | bool blocking; |
| 68 | bool completed; |
| 69 | }; |
| 70 | |
| 71 | struct cec_msg_entry { |
| 72 | struct list_head list; |
| 73 | struct cec_msg msg; |
| 74 | }; |
| 75 | |
Hans Verkuil | 6b2bbb0 | 2017-07-11 03:30:39 -0300 | [diff] [blame] | 76 | struct cec_event_entry { |
| 77 | struct list_head list; |
| 78 | struct cec_event ev; |
| 79 | }; |
| 80 | |
| 81 | #define CEC_NUM_CORE_EVENTS 2 |
Hans Verkuil | 4786b0d | 2018-06-28 07:43:46 -0400 | [diff] [blame] | 82 | #define CEC_NUM_EVENTS CEC_EVENT_PIN_5V_HIGH |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 83 | |
| 84 | struct cec_fh { |
| 85 | struct list_head list; |
| 86 | struct list_head xfer_list; |
| 87 | struct cec_adapter *adap; |
| 88 | u8 mode_initiator; |
| 89 | u8 mode_follower; |
| 90 | |
| 91 | /* Events */ |
| 92 | wait_queue_head_t wait; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 93 | struct mutex lock; |
Hans Verkuil | 6b2bbb0 | 2017-07-11 03:30:39 -0300 | [diff] [blame] | 94 | struct list_head events[CEC_NUM_EVENTS]; /* queued events */ |
Hans Verkuil | 6ec1cbf | 2018-03-06 16:20:00 -0500 | [diff] [blame] | 95 | u16 queued_events[CEC_NUM_EVENTS]; |
Hans Verkuil | 6b2bbb0 | 2017-07-11 03:30:39 -0300 | [diff] [blame] | 96 | unsigned int total_queued_events; |
| 97 | struct cec_event_entry core_events[CEC_NUM_CORE_EVENTS]; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 98 | struct list_head msgs; /* queued messages */ |
| 99 | unsigned int queued_msgs; |
| 100 | }; |
| 101 | |
| 102 | #define CEC_SIGNAL_FREE_TIME_RETRY 3 |
| 103 | #define CEC_SIGNAL_FREE_TIME_NEW_INITIATOR 5 |
| 104 | #define CEC_SIGNAL_FREE_TIME_NEXT_XFER 7 |
| 105 | |
| 106 | /* The nominal data bit period is 2.4 ms */ |
| 107 | #define CEC_FREE_TIME_TO_USEC(ft) ((ft) * 2400) |
| 108 | |
| 109 | struct cec_adap_ops { |
| 110 | /* Low-level callbacks */ |
| 111 | int (*adap_enable)(struct cec_adapter *adap, bool enable); |
| 112 | int (*adap_monitor_all_enable)(struct cec_adapter *adap, bool enable); |
Hans Verkuil | 48ea2e9 | 2017-11-05 07:36:36 -0500 | [diff] [blame] | 113 | int (*adap_monitor_pin_enable)(struct cec_adapter *adap, bool enable); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 114 | int (*adap_log_addr)(struct cec_adapter *adap, u8 logical_addr); |
| 115 | int (*adap_transmit)(struct cec_adapter *adap, u8 attempts, |
| 116 | u32 signal_free_time, struct cec_msg *msg); |
| 117 | void (*adap_status)(struct cec_adapter *adap, struct seq_file *file); |
Hans Verkuil | e6259b5 | 2017-07-11 03:30:36 -0300 | [diff] [blame] | 118 | void (*adap_free)(struct cec_adapter *adap); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 119 | |
Hans Verkuil | 9ca400c | 2017-10-31 09:55:09 -0400 | [diff] [blame] | 120 | /* Error injection callbacks */ |
| 121 | int (*error_inj_show)(struct cec_adapter *adap, struct seq_file *sf); |
| 122 | bool (*error_inj_parse_line)(struct cec_adapter *adap, char *line); |
| 123 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 124 | /* High-level CEC message callback */ |
| 125 | int (*received)(struct cec_adapter *adap, struct cec_msg *msg); |
| 126 | }; |
| 127 | |
| 128 | /* |
| 129 | * The minimum message length you can receive (excepting poll messages) is 2. |
| 130 | * With a transfer rate of at most 36 bytes per second this makes 18 messages |
| 131 | * per second worst case. |
| 132 | * |
Hans Verkuil | 11065f8 | 2016-07-17 11:40:05 -0300 | [diff] [blame] | 133 | * We queue at most 3 seconds worth of received messages. The CEC specification |
| 134 | * requires that messages are replied to within a second, so 3 seconds should |
| 135 | * give more than enough margin. Since most messages are actually more than 2 |
| 136 | * bytes, this is in practice a lot more than 3 seconds. |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 137 | */ |
Hans Verkuil | 11065f8 | 2016-07-17 11:40:05 -0300 | [diff] [blame] | 138 | #define CEC_MAX_MSG_RX_QUEUE_SZ (18 * 3) |
| 139 | |
| 140 | /* |
| 141 | * The transmit queue is limited to 1 second worth of messages (worst case). |
| 142 | * Messages can be transmitted by userspace and kernel space. But for both it |
| 143 | * makes no sense to have a lot of messages queued up. One second seems |
| 144 | * reasonable. |
| 145 | */ |
| 146 | #define CEC_MAX_MSG_TX_QUEUE_SZ (18 * 1) |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 147 | |
| 148 | struct cec_adapter { |
| 149 | struct module *owner; |
| 150 | char name[32]; |
| 151 | struct cec_devnode devnode; |
| 152 | struct mutex lock; |
| 153 | struct rc_dev *rc; |
| 154 | |
| 155 | struct list_head transmit_queue; |
Hans Verkuil | 11065f8 | 2016-07-17 11:40:05 -0300 | [diff] [blame] | 156 | unsigned int transmit_queue_sz; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 157 | struct list_head wait_queue; |
| 158 | struct cec_data *transmitting; |
| 159 | |
| 160 | struct task_struct *kthread_config; |
| 161 | struct completion config_completion; |
| 162 | |
| 163 | struct task_struct *kthread; |
| 164 | wait_queue_head_t kthread_waitq; |
| 165 | wait_queue_head_t waitq; |
| 166 | |
| 167 | const struct cec_adap_ops *ops; |
| 168 | void *priv; |
| 169 | u32 capabilities; |
| 170 | u8 available_log_addrs; |
| 171 | |
| 172 | u16 phys_addr; |
Hans Verkuil | f902c1e | 2017-06-07 11:46:12 -0300 | [diff] [blame] | 173 | bool needs_hpd; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 174 | bool is_configuring; |
| 175 | bool is_configured; |
Hans Verkuil | 28e11b1 | 2017-08-20 06:53:10 -0400 | [diff] [blame] | 176 | bool cec_pin_is_high; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 177 | u32 monitor_all_cnt; |
Hans Verkuil | b8d62f5 | 2017-07-11 03:30:41 -0300 | [diff] [blame] | 178 | u32 monitor_pin_cnt; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 179 | u32 follower_cnt; |
| 180 | struct cec_fh *cec_follower; |
| 181 | struct cec_fh *cec_initiator; |
| 182 | bool passthrough; |
| 183 | struct cec_log_addrs log_addrs; |
| 184 | |
Hans Verkuil | bb789e0 | 2017-07-11 03:30:34 -0300 | [diff] [blame] | 185 | u32 tx_timeouts; |
| 186 | |
Hans Verkuil | e94c328 | 2017-05-28 05:58:04 -0300 | [diff] [blame] | 187 | #ifdef CONFIG_CEC_NOTIFIER |
Hans Verkuil | e3a93ad | 2016-12-13 12:15:57 -0200 | [diff] [blame] | 188 | struct cec_notifier *notifier; |
| 189 | #endif |
Hans Verkuil | ea5c8ef | 2017-07-11 03:30:42 -0300 | [diff] [blame] | 190 | #ifdef CONFIG_CEC_PIN |
| 191 | struct cec_pin *pin; |
| 192 | #endif |
Hans Verkuil | e3a93ad | 2016-12-13 12:15:57 -0200 | [diff] [blame] | 193 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 194 | struct dentry *cec_dir; |
| 195 | struct dentry *status_file; |
Hans Verkuil | 9ca400c | 2017-10-31 09:55:09 -0400 | [diff] [blame] | 196 | struct dentry *error_inj_file; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 197 | |
| 198 | u16 phys_addrs[15]; |
| 199 | u32 sequence; |
| 200 | |
Sean Young | 518f4b2 | 2017-07-01 12:13:19 -0400 | [diff] [blame] | 201 | char device_name[32]; |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 202 | char input_phys[32]; |
| 203 | char input_drv[32]; |
| 204 | }; |
| 205 | |
Jose Abreu | 0b0b97d | 2017-03-24 13:47:52 -0300 | [diff] [blame] | 206 | static inline void *cec_get_drvdata(const struct cec_adapter *adap) |
| 207 | { |
| 208 | return adap->priv; |
| 209 | } |
| 210 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 211 | static inline bool cec_has_log_addr(const struct cec_adapter *adap, u8 log_addr) |
| 212 | { |
| 213 | return adap->log_addrs.log_addr_mask & (1 << log_addr); |
| 214 | } |
| 215 | |
| 216 | static inline bool cec_is_sink(const struct cec_adapter *adap) |
| 217 | { |
| 218 | return adap->phys_addr == 0; |
| 219 | } |
| 220 | |
Hans Verkuil | c8959a3 | 2017-11-22 04:12:39 -0500 | [diff] [blame] | 221 | /** |
| 222 | * cec_is_registered() - is the CEC adapter registered? |
| 223 | * |
| 224 | * @adap: the CEC adapter, may be NULL. |
| 225 | * |
| 226 | * Return: true if the adapter is registered, false otherwise. |
| 227 | */ |
| 228 | static inline bool cec_is_registered(const struct cec_adapter *adap) |
| 229 | { |
| 230 | return adap && adap->devnode.registered; |
| 231 | } |
| 232 | |
Hans Verkuil | ee7e9871 | 2017-04-17 07:54:37 -0300 | [diff] [blame] | 233 | #define cec_phys_addr_exp(pa) \ |
| 234 | ((pa) >> 12), ((pa) >> 8) & 0xf, ((pa) >> 4) & 0xf, (pa) & 0xf |
| 235 | |
Hans Verkuil | 23111ec | 2017-06-07 11:46:08 -0300 | [diff] [blame] | 236 | struct edid; |
| 237 | |
Hans Verkuil | f9f314f | 2017-06-08 15:37:44 -0300 | [diff] [blame] | 238 | #if IS_REACHABLE(CONFIG_CEC_CORE) |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 239 | struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops, |
Hans Verkuil | f51e808 | 2016-11-25 06:23:34 -0200 | [diff] [blame] | 240 | void *priv, const char *name, u32 caps, u8 available_las); |
| 241 | int cec_register_adapter(struct cec_adapter *adap, struct device *parent); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 242 | void cec_unregister_adapter(struct cec_adapter *adap); |
| 243 | void cec_delete_adapter(struct cec_adapter *adap); |
| 244 | |
| 245 | int cec_s_log_addrs(struct cec_adapter *adap, struct cec_log_addrs *log_addrs, |
| 246 | bool block); |
| 247 | void cec_s_phys_addr(struct cec_adapter *adap, u16 phys_addr, |
| 248 | bool block); |
Hans Verkuil | 23111ec | 2017-06-07 11:46:08 -0300 | [diff] [blame] | 249 | void cec_s_phys_addr_from_edid(struct cec_adapter *adap, |
| 250 | const struct edid *edid); |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 251 | int cec_transmit_msg(struct cec_adapter *adap, struct cec_msg *msg, |
| 252 | bool block); |
| 253 | |
| 254 | /* Called by the adapter */ |
Hans Verkuil | 0861ad1 | 2017-07-11 03:30:35 -0300 | [diff] [blame] | 255 | void cec_transmit_done_ts(struct cec_adapter *adap, u8 status, |
| 256 | u8 arb_lost_cnt, u8 nack_cnt, u8 low_drive_cnt, |
| 257 | u8 error_cnt, ktime_t ts); |
| 258 | |
| 259 | static inline void cec_transmit_done(struct cec_adapter *adap, u8 status, |
| 260 | u8 arb_lost_cnt, u8 nack_cnt, |
| 261 | u8 low_drive_cnt, u8 error_cnt) |
| 262 | { |
| 263 | cec_transmit_done_ts(adap, status, arb_lost_cnt, nack_cnt, |
| 264 | low_drive_cnt, error_cnt, ktime_get()); |
| 265 | } |
Hans Verkuil | c94cdc1 | 2017-06-07 11:46:10 -0300 | [diff] [blame] | 266 | /* |
| 267 | * Simplified version of cec_transmit_done for hardware that doesn't retry |
| 268 | * failed transmits. So this is always just one attempt in which case |
| 269 | * the status is sufficient. |
| 270 | */ |
Hans Verkuil | 0861ad1 | 2017-07-11 03:30:35 -0300 | [diff] [blame] | 271 | void cec_transmit_attempt_done_ts(struct cec_adapter *adap, |
| 272 | u8 status, ktime_t ts); |
| 273 | |
| 274 | static inline void cec_transmit_attempt_done(struct cec_adapter *adap, |
| 275 | u8 status) |
| 276 | { |
| 277 | cec_transmit_attempt_done_ts(adap, status, ktime_get()); |
| 278 | } |
| 279 | |
| 280 | void cec_received_msg_ts(struct cec_adapter *adap, |
| 281 | struct cec_msg *msg, ktime_t ts); |
| 282 | |
| 283 | static inline void cec_received_msg(struct cec_adapter *adap, |
| 284 | struct cec_msg *msg) |
| 285 | { |
| 286 | cec_received_msg_ts(adap, msg, ktime_get()); |
| 287 | } |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 288 | |
Hans Verkuil | ee7e9871 | 2017-04-17 07:54:37 -0300 | [diff] [blame] | 289 | /** |
Hans Verkuil | 9a6b2a8 | 2017-08-15 15:26:25 -0400 | [diff] [blame] | 290 | * 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] | 291 | * |
| 292 | * @adap: pointer to the cec adapter |
Hans Verkuil | 9a6b2a8 | 2017-08-15 15:26:25 -0400 | [diff] [blame] | 293 | * @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] | 294 | * @dropped_events: when true some events were dropped |
Hans Verkuil | b8d62f5 | 2017-07-11 03:30:41 -0300 | [diff] [blame] | 295 | * @ts: the timestamp for this event |
| 296 | * |
| 297 | */ |
Hans Verkuil | 6ec1cbf | 2018-03-06 16:20:00 -0500 | [diff] [blame] | 298 | void cec_queue_pin_cec_event(struct cec_adapter *adap, bool is_high, |
| 299 | bool dropped_events, ktime_t ts); |
Hans Verkuil | b8d62f5 | 2017-07-11 03:30:41 -0300 | [diff] [blame] | 300 | |
| 301 | /** |
Hans Verkuil | 333ef6b | 2017-08-15 10:07:25 -0400 | [diff] [blame] | 302 | * cec_queue_pin_hpd_event() - queue a pin event with a given timestamp. |
| 303 | * |
| 304 | * @adap: pointer to the cec adapter |
| 305 | * @is_high: when true the HPD pin is high, otherwise it is low |
| 306 | * @ts: the timestamp for this event |
| 307 | * |
| 308 | */ |
| 309 | void cec_queue_pin_hpd_event(struct cec_adapter *adap, bool is_high, ktime_t ts); |
| 310 | |
| 311 | /** |
Hans Verkuil | 4786b0d | 2018-06-28 07:43:46 -0400 | [diff] [blame] | 312 | * cec_queue_pin_5v_event() - queue a pin event with a given timestamp. |
| 313 | * |
| 314 | * @adap: pointer to the cec adapter |
| 315 | * @is_high: when true the 5V pin is high, otherwise it is low |
| 316 | * @ts: the timestamp for this event |
| 317 | * |
| 318 | */ |
| 319 | void cec_queue_pin_5v_event(struct cec_adapter *adap, bool is_high, ktime_t ts); |
| 320 | |
| 321 | /** |
Hans Verkuil | ee7e9871 | 2017-04-17 07:54:37 -0300 | [diff] [blame] | 322 | * cec_get_edid_phys_addr() - find and return the physical address |
| 323 | * |
| 324 | * @edid: pointer to the EDID data |
| 325 | * @size: size in bytes of the EDID data |
| 326 | * @offset: If not %NULL then the location of the physical address |
| 327 | * bytes in the EDID will be returned here. This is set to 0 |
| 328 | * if there is no physical address found. |
| 329 | * |
| 330 | * Return: the physical address or CEC_PHYS_ADDR_INVALID if there is none. |
| 331 | */ |
| 332 | u16 cec_get_edid_phys_addr(const u8 *edid, unsigned int size, |
| 333 | unsigned int *offset); |
| 334 | |
| 335 | /** |
| 336 | * cec_set_edid_phys_addr() - find and set the physical address |
| 337 | * |
| 338 | * @edid: pointer to the EDID data |
| 339 | * @size: size in bytes of the EDID data |
| 340 | * @phys_addr: the new physical address |
| 341 | * |
| 342 | * This function finds the location of the physical address in the EDID |
| 343 | * and fills in the given physical address and updates the checksum |
| 344 | * at the end of the EDID block. It does nothing if the EDID doesn't |
| 345 | * contain a physical address. |
| 346 | */ |
| 347 | void cec_set_edid_phys_addr(u8 *edid, unsigned int size, u16 phys_addr); |
| 348 | |
| 349 | /** |
| 350 | * cec_phys_addr_for_input() - calculate the PA for an input |
| 351 | * |
| 352 | * @phys_addr: the physical address of the parent |
| 353 | * @input: the number of the input port, must be between 1 and 15 |
| 354 | * |
| 355 | * This function calculates a new physical address based on the input |
| 356 | * port number. For example: |
| 357 | * |
| 358 | * PA = 0.0.0.0 and input = 2 becomes 2.0.0.0 |
| 359 | * |
| 360 | * PA = 3.0.0.0 and input = 1 becomes 3.1.0.0 |
| 361 | * |
| 362 | * PA = 3.2.1.0 and input = 5 becomes 3.2.1.5 |
| 363 | * |
| 364 | * PA = 3.2.1.3 and input = 5 becomes f.f.f.f since it maxed out the depth. |
| 365 | * |
| 366 | * Return: the new physical address or CEC_PHYS_ADDR_INVALID. |
| 367 | */ |
| 368 | u16 cec_phys_addr_for_input(u16 phys_addr, u8 input); |
| 369 | |
| 370 | /** |
| 371 | * cec_phys_addr_validate() - validate a physical address from an EDID |
| 372 | * |
| 373 | * @phys_addr: the physical address to validate |
| 374 | * @parent: if not %NULL, then this is filled with the parents PA. |
| 375 | * @port: if not %NULL, then this is filled with the input port. |
| 376 | * |
| 377 | * This validates a physical address as read from an EDID. If the |
| 378 | * PA is invalid (such as 1.0.1.0 since '0' is only allowed at the end), |
| 379 | * then it will return -EINVAL. |
| 380 | * |
| 381 | * The parent PA is passed into %parent and the input port is passed into |
| 382 | * %port. For example: |
| 383 | * |
| 384 | * PA = 0.0.0.0: has parent 0.0.0.0 and input port 0. |
| 385 | * |
| 386 | * PA = 1.0.0.0: has parent 0.0.0.0 and input port 1. |
| 387 | * |
| 388 | * PA = 3.2.0.0: has parent 3.0.0.0 and input port 2. |
| 389 | * |
| 390 | * PA = f.f.f.f: has parent f.f.f.f and input port 0. |
| 391 | * |
| 392 | * Return: 0 if the PA is valid, -EINVAL if not. |
| 393 | */ |
| 394 | int cec_phys_addr_validate(u16 phys_addr, u16 *parent, u16 *port); |
| 395 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 396 | #else |
| 397 | |
Hans Verkuil | f51e808 | 2016-11-25 06:23:34 -0200 | [diff] [blame] | 398 | static inline int cec_register_adapter(struct cec_adapter *adap, |
| 399 | struct device *parent) |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 400 | { |
| 401 | return 0; |
| 402 | } |
| 403 | |
| 404 | static inline void cec_unregister_adapter(struct cec_adapter *adap) |
| 405 | { |
| 406 | } |
| 407 | |
| 408 | static inline void cec_delete_adapter(struct cec_adapter *adap) |
| 409 | { |
| 410 | } |
| 411 | |
| 412 | static inline void cec_s_phys_addr(struct cec_adapter *adap, u16 phys_addr, |
| 413 | bool block) |
| 414 | { |
| 415 | } |
| 416 | |
Hans Verkuil | 23111ec | 2017-06-07 11:46:08 -0300 | [diff] [blame] | 417 | static inline void cec_s_phys_addr_from_edid(struct cec_adapter *adap, |
| 418 | const struct edid *edid) |
| 419 | { |
| 420 | } |
| 421 | |
Hans Verkuil | ee7e9871 | 2017-04-17 07:54:37 -0300 | [diff] [blame] | 422 | static inline u16 cec_get_edid_phys_addr(const u8 *edid, unsigned int size, |
| 423 | unsigned int *offset) |
| 424 | { |
| 425 | if (offset) |
| 426 | *offset = 0; |
| 427 | return CEC_PHYS_ADDR_INVALID; |
| 428 | } |
| 429 | |
| 430 | static inline void cec_set_edid_phys_addr(u8 *edid, unsigned int size, |
| 431 | u16 phys_addr) |
| 432 | { |
| 433 | } |
| 434 | |
| 435 | static inline u16 cec_phys_addr_for_input(u16 phys_addr, u8 input) |
| 436 | { |
| 437 | return CEC_PHYS_ADDR_INVALID; |
| 438 | } |
| 439 | |
| 440 | static inline int cec_phys_addr_validate(u16 phys_addr, u16 *parent, u16 *port) |
| 441 | { |
Hans Verkuil | 9267d90 | 2017-08-31 04:12:53 -0400 | [diff] [blame] | 442 | if (parent) |
| 443 | *parent = phys_addr; |
| 444 | if (port) |
| 445 | *port = 0; |
Hans Verkuil | ee7e9871 | 2017-04-17 07:54:37 -0300 | [diff] [blame] | 446 | return 0; |
| 447 | } |
| 448 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 449 | #endif |
| 450 | |
Hans Verkuil | 1353278 | 2017-06-07 11:46:09 -0300 | [diff] [blame] | 451 | /** |
| 452 | * cec_phys_addr_invalidate() - set the physical address to INVALID |
| 453 | * |
| 454 | * @adap: the CEC adapter |
| 455 | * |
| 456 | * This is a simple helper function to invalidate the physical |
| 457 | * address. |
| 458 | */ |
| 459 | static inline void cec_phys_addr_invalidate(struct cec_adapter *adap) |
| 460 | { |
| 461 | cec_s_phys_addr(adap, CEC_PHYS_ADDR_INVALID, false); |
| 462 | } |
| 463 | |
Hans Verkuil | a56960e | 2016-06-25 09:43:58 -0300 | [diff] [blame] | 464 | #endif /* _MEDIA_CEC_H */ |