Hans Verkuil | ab15d24 | 2018-02-07 09:05:46 -0500 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 2 | /* |
| 3 | * cec-notifier.h - notify CEC drivers of physical address changes |
| 4 | * |
| 5 | * Copyright 2016 Russell King <rmk+kernel@arm.linux.org.uk> |
| 6 | * Copyright 2016-2017 Cisco Systems, Inc. and/or its affiliates. All rights reserved. |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef LINUX_CEC_NOTIFIER_H |
| 10 | #define LINUX_CEC_NOTIFIER_H |
| 11 | |
Hans Verkuil | fbbd403 | 2019-04-10 05:13:28 -0400 | [diff] [blame] | 12 | #include <linux/err.h> |
Hans Verkuil | ee7e9871 | 2017-04-17 07:54:37 -0300 | [diff] [blame] | 13 | #include <media/cec.h> |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 14 | |
| 15 | struct device; |
| 16 | struct edid; |
| 17 | struct cec_adapter; |
| 18 | struct cec_notifier; |
| 19 | |
Hans Verkuil | e94c328 | 2017-05-28 05:58:04 -0300 | [diff] [blame] | 20 | #if IS_REACHABLE(CONFIG_CEC_CORE) && IS_ENABLED(CONFIG_CEC_NOTIFIER) |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 21 | |
| 22 | /** |
Neil Armstrong | 7a78c1e | 2018-07-04 17:08:16 +0200 | [diff] [blame] | 23 | * cec_notifier_get_conn - find or create a new cec_notifier for the given |
| 24 | * device and connector tuple. |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 25 | * @dev: device that sends the events. |
Neil Armstrong | 7a78c1e | 2018-07-04 17:08:16 +0200 | [diff] [blame] | 26 | * @conn: the connector name from which the event occurs |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 27 | * |
| 28 | * If a notifier for device @dev already exists, then increase the refcount |
| 29 | * and return that notifier. |
| 30 | * |
| 31 | * If it doesn't exist, then allocate a new notifier struct and return a |
| 32 | * pointer to that new struct. |
| 33 | * |
| 34 | * Return NULL if the memory could not be allocated. |
| 35 | */ |
Neil Armstrong | 7a78c1e | 2018-07-04 17:08:16 +0200 | [diff] [blame] | 36 | struct cec_notifier *cec_notifier_get_conn(struct device *dev, |
| 37 | const char *conn); |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 38 | |
| 39 | /** |
Hans Verkuil | b48cb35 | 2019-06-20 06:10:00 -0400 | [diff] [blame] | 40 | * cec_notifier_conn_register - find or create a new cec_notifier for the given |
| 41 | * HDMI device and connector tuple. |
| 42 | * @hdmi_dev: HDMI device that sends the events. |
| 43 | * @conn_name: the connector name from which the event occurs. May be NULL |
| 44 | * if there is always only one HDMI connector created by the HDMI device. |
| 45 | * @conn_info: the connector info from which the event occurs (may be NULL) |
| 46 | * |
| 47 | * If a notifier for device @dev and connector @conn_name already exists, then |
| 48 | * increase the refcount and return that notifier. |
| 49 | * |
| 50 | * If it doesn't exist, then allocate a new notifier struct and return a |
| 51 | * pointer to that new struct. |
| 52 | * |
| 53 | * Return NULL if the memory could not be allocated. |
| 54 | */ |
| 55 | struct cec_notifier * |
| 56 | cec_notifier_conn_register(struct device *hdmi_dev, const char *conn_name, |
| 57 | const struct cec_connector_info *conn_info); |
| 58 | |
| 59 | /** |
| 60 | * cec_notifier_conn_unregister - decrease refcount and delete when the |
| 61 | * refcount reaches 0. |
| 62 | * @n: notifier. If NULL, then this function does nothing. |
| 63 | */ |
| 64 | void cec_notifier_conn_unregister(struct cec_notifier *n); |
| 65 | |
| 66 | /** |
| 67 | * cec_notifier_cec_adap_register - find or create a new cec_notifier for the |
| 68 | * given device. |
| 69 | * @hdmi_dev: HDMI device that sends the events. |
| 70 | * @conn_name: the connector name from which the event occurs. May be NULL |
| 71 | * if there is always only one HDMI connector created by the HDMI device. |
| 72 | * @adap: the cec adapter that registered this notifier. |
| 73 | * |
| 74 | * If a notifier for device @dev and connector @conn_name already exists, then |
| 75 | * increase the refcount and return that notifier. |
| 76 | * |
| 77 | * If it doesn't exist, then allocate a new notifier struct and return a |
| 78 | * pointer to that new struct. |
| 79 | * |
| 80 | * Return NULL if the memory could not be allocated. |
| 81 | */ |
| 82 | struct cec_notifier * |
| 83 | cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *conn_name, |
| 84 | struct cec_adapter *adap); |
| 85 | |
| 86 | /** |
| 87 | * cec_notifier_cec_adap_unregister - decrease refcount and delete when the |
| 88 | * refcount reaches 0. |
| 89 | * @n: notifier. If NULL, then this function does nothing. |
Hans Verkuil | 10d8f30 | 2019-10-04 13:04:24 +0200 | [diff] [blame] | 90 | * @adap: the cec adapter that registered this notifier. |
Hans Verkuil | b48cb35 | 2019-06-20 06:10:00 -0400 | [diff] [blame] | 91 | */ |
Hans Verkuil | 10d8f30 | 2019-10-04 13:04:24 +0200 | [diff] [blame] | 92 | void cec_notifier_cec_adap_unregister(struct cec_notifier *n, |
| 93 | struct cec_adapter *adap); |
Hans Verkuil | b48cb35 | 2019-06-20 06:10:00 -0400 | [diff] [blame] | 94 | |
| 95 | /** |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 96 | * cec_notifier_set_phys_addr - set a new physical address. |
| 97 | * @n: the CEC notifier |
| 98 | * @pa: the CEC physical address |
| 99 | * |
| 100 | * Set a new CEC physical address. |
Hans Verkuil | fc1ff45 | 2017-07-15 09:32:56 -0300 | [diff] [blame] | 101 | * Does nothing if @n == NULL. |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 102 | */ |
| 103 | void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa); |
| 104 | |
| 105 | /** |
| 106 | * cec_notifier_set_phys_addr_from_edid - set parse the PA from the EDID. |
| 107 | * @n: the CEC notifier |
| 108 | * @edid: the struct edid pointer |
| 109 | * |
| 110 | * Parses the EDID to obtain the new CEC physical address and set it. |
Hans Verkuil | fc1ff45 | 2017-07-15 09:32:56 -0300 | [diff] [blame] | 111 | * Does nothing if @n == NULL. |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 112 | */ |
| 113 | void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n, |
| 114 | const struct edid *edid); |
| 115 | |
| 116 | /** |
Hans Verkuil | fbbd403 | 2019-04-10 05:13:28 -0400 | [diff] [blame] | 117 | * cec_notifier_parse_hdmi_phandle - find the hdmi device from "hdmi-phandle" |
| 118 | * @dev: the device with the "hdmi-phandle" device tree property |
| 119 | * |
| 120 | * Returns the device pointer referenced by the "hdmi-phandle" property. |
| 121 | * Note that the refcount of the returned device is not incremented. |
| 122 | * This device pointer is only used as a key value in the notifier |
| 123 | * list, but it is never accessed by the CEC driver. |
| 124 | */ |
| 125 | struct device *cec_notifier_parse_hdmi_phandle(struct device *dev); |
| 126 | |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 127 | #else |
Neil Armstrong | 7a78c1e | 2018-07-04 17:08:16 +0200 | [diff] [blame] | 128 | static inline struct cec_notifier *cec_notifier_get_conn(struct device *dev, |
| 129 | const char *conn) |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 130 | { |
| 131 | /* A non-NULL pointer is expected on success */ |
| 132 | return (struct cec_notifier *)0xdeadfeed; |
| 133 | } |
| 134 | |
Hans Verkuil | b48cb35 | 2019-06-20 06:10:00 -0400 | [diff] [blame] | 135 | static inline struct cec_notifier * |
| 136 | cec_notifier_conn_register(struct device *hdmi_dev, const char *conn_name, |
| 137 | const struct cec_connector_info *conn_info) |
| 138 | { |
| 139 | /* A non-NULL pointer is expected on success */ |
| 140 | return (struct cec_notifier *)0xdeadfeed; |
| 141 | } |
| 142 | |
| 143 | static inline void cec_notifier_conn_unregister(struct cec_notifier *n) |
| 144 | { |
| 145 | } |
| 146 | |
| 147 | static inline struct cec_notifier * |
| 148 | cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *conn_name, |
| 149 | struct cec_adapter *adap) |
| 150 | { |
| 151 | /* A non-NULL pointer is expected on success */ |
| 152 | return (struct cec_notifier *)0xdeadfeed; |
| 153 | } |
| 154 | |
Hans Verkuil | 10d8f30 | 2019-10-04 13:04:24 +0200 | [diff] [blame] | 155 | static inline void cec_notifier_cec_adap_unregister(struct cec_notifier *n, |
| 156 | struct cec_adapter *adap) |
Hans Verkuil | b48cb35 | 2019-06-20 06:10:00 -0400 | [diff] [blame] | 157 | { |
| 158 | } |
| 159 | |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 160 | static inline void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa) |
| 161 | { |
| 162 | } |
| 163 | |
| 164 | static inline void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n, |
| 165 | const struct edid *edid) |
| 166 | { |
| 167 | } |
| 168 | |
Hans Verkuil | fbbd403 | 2019-04-10 05:13:28 -0400 | [diff] [blame] | 169 | static inline struct device *cec_notifier_parse_hdmi_phandle(struct device *dev) |
| 170 | { |
| 171 | return ERR_PTR(-ENODEV); |
| 172 | } |
| 173 | |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 174 | #endif |
| 175 | |
Hans Verkuil | fc1ff45 | 2017-07-15 09:32:56 -0300 | [diff] [blame] | 176 | /** |
| 177 | * cec_notifier_phys_addr_invalidate() - set the physical address to INVALID |
| 178 | * |
| 179 | * @n: the CEC notifier |
| 180 | * |
| 181 | * This is a simple helper function to invalidate the physical |
| 182 | * address. Does nothing if @n == NULL. |
| 183 | */ |
| 184 | static inline void cec_notifier_phys_addr_invalidate(struct cec_notifier *n) |
| 185 | { |
| 186 | cec_notifier_set_phys_addr(n, CEC_PHYS_ADDR_INVALID); |
| 187 | } |
| 188 | |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 189 | #endif |