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 | /** |
| 40 | * cec_notifier_put - decrease refcount and delete when the refcount reaches 0. |
| 41 | * @n: notifier |
| 42 | */ |
| 43 | void cec_notifier_put(struct cec_notifier *n); |
| 44 | |
| 45 | /** |
| 46 | * cec_notifier_set_phys_addr - set a new physical address. |
| 47 | * @n: the CEC notifier |
| 48 | * @pa: the CEC physical address |
| 49 | * |
| 50 | * Set a new CEC physical address. |
Hans Verkuil | fc1ff45 | 2017-07-15 09:32:56 -0300 | [diff] [blame] | 51 | * Does nothing if @n == NULL. |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 52 | */ |
| 53 | void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa); |
| 54 | |
| 55 | /** |
| 56 | * cec_notifier_set_phys_addr_from_edid - set parse the PA from the EDID. |
| 57 | * @n: the CEC notifier |
| 58 | * @edid: the struct edid pointer |
| 59 | * |
| 60 | * 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] | 61 | * Does nothing if @n == NULL. |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 62 | */ |
| 63 | void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n, |
| 64 | const struct edid *edid); |
| 65 | |
| 66 | /** |
| 67 | * cec_notifier_register - register a callback with the notifier |
| 68 | * @n: the CEC notifier |
| 69 | * @adap: the CEC adapter, passed as argument to the callback function |
| 70 | * @callback: the callback function |
| 71 | */ |
| 72 | void cec_notifier_register(struct cec_notifier *n, |
| 73 | struct cec_adapter *adap, |
| 74 | void (*callback)(struct cec_adapter *adap, u16 pa)); |
| 75 | |
| 76 | /** |
| 77 | * cec_notifier_unregister - unregister the callback from the notifier. |
| 78 | * @n: the CEC notifier |
| 79 | */ |
| 80 | void cec_notifier_unregister(struct cec_notifier *n); |
| 81 | |
Hans Verkuil | 5150418 | 2017-07-13 04:07:23 -0300 | [diff] [blame] | 82 | /** |
| 83 | * cec_register_cec_notifier - register the notifier with the cec adapter. |
| 84 | * @adap: the CEC adapter |
| 85 | * @notifier: the CEC notifier |
| 86 | */ |
| 87 | void cec_register_cec_notifier(struct cec_adapter *adap, |
| 88 | struct cec_notifier *notifier); |
| 89 | |
Hans Verkuil | fbbd403 | 2019-04-10 05:13:28 -0400 | [diff] [blame^] | 90 | /** |
| 91 | * cec_notifier_parse_hdmi_phandle - find the hdmi device from "hdmi-phandle" |
| 92 | * @dev: the device with the "hdmi-phandle" device tree property |
| 93 | * |
| 94 | * Returns the device pointer referenced by the "hdmi-phandle" property. |
| 95 | * Note that the refcount of the returned device is not incremented. |
| 96 | * This device pointer is only used as a key value in the notifier |
| 97 | * list, but it is never accessed by the CEC driver. |
| 98 | */ |
| 99 | struct device *cec_notifier_parse_hdmi_phandle(struct device *dev); |
| 100 | |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 101 | #else |
Neil Armstrong | 7a78c1e | 2018-07-04 17:08:16 +0200 | [diff] [blame] | 102 | static inline struct cec_notifier *cec_notifier_get_conn(struct device *dev, |
| 103 | const char *conn) |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 104 | { |
| 105 | /* A non-NULL pointer is expected on success */ |
| 106 | return (struct cec_notifier *)0xdeadfeed; |
| 107 | } |
| 108 | |
| 109 | static inline void cec_notifier_put(struct cec_notifier *n) |
| 110 | { |
| 111 | } |
| 112 | |
| 113 | static inline void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa) |
| 114 | { |
| 115 | } |
| 116 | |
| 117 | static inline void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n, |
| 118 | const struct edid *edid) |
| 119 | { |
| 120 | } |
| 121 | |
Arnd Bergmann | 79eddc9 | 2017-05-12 16:39:21 -0300 | [diff] [blame] | 122 | static inline void cec_notifier_register(struct cec_notifier *n, |
| 123 | struct cec_adapter *adap, |
| 124 | void (*callback)(struct cec_adapter *adap, u16 pa)) |
| 125 | { |
| 126 | } |
| 127 | |
| 128 | static inline void cec_notifier_unregister(struct cec_notifier *n) |
| 129 | { |
| 130 | } |
| 131 | |
Hans Verkuil | 5150418 | 2017-07-13 04:07:23 -0300 | [diff] [blame] | 132 | static inline void cec_register_cec_notifier(struct cec_adapter *adap, |
| 133 | struct cec_notifier *notifier) |
| 134 | { |
| 135 | } |
Hans Verkuil | fbbd403 | 2019-04-10 05:13:28 -0400 | [diff] [blame^] | 136 | |
| 137 | static inline struct device *cec_notifier_parse_hdmi_phandle(struct device *dev) |
| 138 | { |
| 139 | return ERR_PTR(-ENODEV); |
| 140 | } |
| 141 | |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 142 | #endif |
| 143 | |
Hans Verkuil | fc1ff45 | 2017-07-15 09:32:56 -0300 | [diff] [blame] | 144 | /** |
Neil Armstrong | 7a78c1e | 2018-07-04 17:08:16 +0200 | [diff] [blame] | 145 | * cec_notifier_get - find or create a new cec_notifier for the given device. |
| 146 | * @dev: device that sends the events. |
| 147 | * |
| 148 | * If a notifier for device @dev already exists, then increase the refcount |
| 149 | * and return that notifier. |
| 150 | * |
| 151 | * If it doesn't exist, then allocate a new notifier struct and return a |
| 152 | * pointer to that new struct. |
| 153 | * |
| 154 | * Return NULL if the memory could not be allocated. |
| 155 | */ |
| 156 | static inline struct cec_notifier *cec_notifier_get(struct device *dev) |
| 157 | { |
| 158 | return cec_notifier_get_conn(dev, NULL); |
| 159 | } |
| 160 | |
| 161 | /** |
Hans Verkuil | fc1ff45 | 2017-07-15 09:32:56 -0300 | [diff] [blame] | 162 | * cec_notifier_phys_addr_invalidate() - set the physical address to INVALID |
| 163 | * |
| 164 | * @n: the CEC notifier |
| 165 | * |
| 166 | * This is a simple helper function to invalidate the physical |
| 167 | * address. Does nothing if @n == NULL. |
| 168 | */ |
| 169 | static inline void cec_notifier_phys_addr_invalidate(struct cec_notifier *n) |
| 170 | { |
| 171 | cec_notifier_set_phys_addr(n, CEC_PHYS_ADDR_INVALID); |
| 172 | } |
| 173 | |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 174 | #endif |