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 | * |
Russell King | 4f39467 | 2020-03-28 13:03:02 +0000 | [diff] [blame] | 5 | * Copyright 2016 Russell King. |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 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 | /** |
Hans Verkuil | b48cb35 | 2019-06-20 06:10:00 -0400 | [diff] [blame] | 23 | * cec_notifier_conn_register - find or create a new cec_notifier for the given |
| 24 | * HDMI device and connector tuple. |
| 25 | * @hdmi_dev: HDMI device that sends the events. |
Hans Verkuil | 80f13a0 | 2020-03-16 10:36:47 +0100 | [diff] [blame] | 26 | * @port_name: the connector name from which the event occurs. May be NULL |
Hans Verkuil | b48cb35 | 2019-06-20 06:10:00 -0400 | [diff] [blame] | 27 | * if there is always only one HDMI connector created by the HDMI device. |
| 28 | * @conn_info: the connector info from which the event occurs (may be NULL) |
| 29 | * |
Hans Verkuil | 80f13a0 | 2020-03-16 10:36:47 +0100 | [diff] [blame] | 30 | * If a notifier for device @dev and connector @port_name already exists, then |
Hans Verkuil | b48cb35 | 2019-06-20 06:10:00 -0400 | [diff] [blame] | 31 | * increase the refcount and return that notifier. |
| 32 | * |
| 33 | * If it doesn't exist, then allocate a new notifier struct and return a |
| 34 | * pointer to that new struct. |
| 35 | * |
| 36 | * Return NULL if the memory could not be allocated. |
| 37 | */ |
| 38 | struct cec_notifier * |
Hans Verkuil | 80f13a0 | 2020-03-16 10:36:47 +0100 | [diff] [blame] | 39 | cec_notifier_conn_register(struct device *hdmi_dev, const char *port_name, |
Hans Verkuil | b48cb35 | 2019-06-20 06:10:00 -0400 | [diff] [blame] | 40 | const struct cec_connector_info *conn_info); |
| 41 | |
| 42 | /** |
| 43 | * cec_notifier_conn_unregister - decrease refcount and delete when the |
| 44 | * refcount reaches 0. |
| 45 | * @n: notifier. If NULL, then this function does nothing. |
| 46 | */ |
| 47 | void cec_notifier_conn_unregister(struct cec_notifier *n); |
| 48 | |
| 49 | /** |
| 50 | * cec_notifier_cec_adap_register - find or create a new cec_notifier for the |
| 51 | * given device. |
| 52 | * @hdmi_dev: HDMI device that sends the events. |
Hans Verkuil | 80f13a0 | 2020-03-16 10:36:47 +0100 | [diff] [blame] | 53 | * @port_name: the connector name from which the event occurs. May be NULL |
Hans Verkuil | b48cb35 | 2019-06-20 06:10:00 -0400 | [diff] [blame] | 54 | * if there is always only one HDMI connector created by the HDMI device. |
| 55 | * @adap: the cec adapter that registered this notifier. |
| 56 | * |
Hans Verkuil | 80f13a0 | 2020-03-16 10:36:47 +0100 | [diff] [blame] | 57 | * If a notifier for device @dev and connector @port_name already exists, then |
Hans Verkuil | b48cb35 | 2019-06-20 06:10:00 -0400 | [diff] [blame] | 58 | * increase the refcount and return that notifier. |
| 59 | * |
| 60 | * If it doesn't exist, then allocate a new notifier struct and return a |
| 61 | * pointer to that new struct. |
| 62 | * |
| 63 | * Return NULL if the memory could not be allocated. |
| 64 | */ |
| 65 | struct cec_notifier * |
Hans Verkuil | 80f13a0 | 2020-03-16 10:36:47 +0100 | [diff] [blame] | 66 | cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *port_name, |
Hans Verkuil | b48cb35 | 2019-06-20 06:10:00 -0400 | [diff] [blame] | 67 | struct cec_adapter *adap); |
| 68 | |
| 69 | /** |
| 70 | * cec_notifier_cec_adap_unregister - decrease refcount and delete when the |
| 71 | * refcount reaches 0. |
| 72 | * @n: notifier. If NULL, then this function does nothing. |
Hans Verkuil | 10d8f30 | 2019-10-04 13:04:24 +0200 | [diff] [blame] | 73 | * @adap: the cec adapter that registered this notifier. |
Hans Verkuil | b48cb35 | 2019-06-20 06:10:00 -0400 | [diff] [blame] | 74 | */ |
Hans Verkuil | 10d8f30 | 2019-10-04 13:04:24 +0200 | [diff] [blame] | 75 | void cec_notifier_cec_adap_unregister(struct cec_notifier *n, |
| 76 | struct cec_adapter *adap); |
Hans Verkuil | b48cb35 | 2019-06-20 06:10:00 -0400 | [diff] [blame] | 77 | |
| 78 | /** |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 79 | * cec_notifier_set_phys_addr - set a new physical address. |
| 80 | * @n: the CEC notifier |
| 81 | * @pa: the CEC physical address |
| 82 | * |
| 83 | * Set a new CEC physical address. |
Hans Verkuil | fc1ff45 | 2017-07-15 09:32:56 -0300 | [diff] [blame] | 84 | * Does nothing if @n == NULL. |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 85 | */ |
| 86 | void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa); |
| 87 | |
| 88 | /** |
| 89 | * cec_notifier_set_phys_addr_from_edid - set parse the PA from the EDID. |
| 90 | * @n: the CEC notifier |
| 91 | * @edid: the struct edid pointer |
| 92 | * |
| 93 | * 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] | 94 | * Does nothing if @n == NULL. |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 95 | */ |
| 96 | void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n, |
| 97 | const struct edid *edid); |
| 98 | |
| 99 | /** |
Hans Verkuil | fbbd403 | 2019-04-10 05:13:28 -0400 | [diff] [blame] | 100 | * cec_notifier_parse_hdmi_phandle - find the hdmi device from "hdmi-phandle" |
| 101 | * @dev: the device with the "hdmi-phandle" device tree property |
| 102 | * |
| 103 | * Returns the device pointer referenced by the "hdmi-phandle" property. |
| 104 | * Note that the refcount of the returned device is not incremented. |
| 105 | * This device pointer is only used as a key value in the notifier |
| 106 | * list, but it is never accessed by the CEC driver. |
| 107 | */ |
| 108 | struct device *cec_notifier_parse_hdmi_phandle(struct device *dev); |
| 109 | |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 110 | #else |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 111 | |
Hans Verkuil | b48cb35 | 2019-06-20 06:10:00 -0400 | [diff] [blame] | 112 | static inline struct cec_notifier * |
Hans Verkuil | 80f13a0 | 2020-03-16 10:36:47 +0100 | [diff] [blame] | 113 | cec_notifier_conn_register(struct device *hdmi_dev, const char *port_name, |
Hans Verkuil | b48cb35 | 2019-06-20 06:10:00 -0400 | [diff] [blame] | 114 | const struct cec_connector_info *conn_info) |
| 115 | { |
| 116 | /* A non-NULL pointer is expected on success */ |
| 117 | return (struct cec_notifier *)0xdeadfeed; |
| 118 | } |
| 119 | |
| 120 | static inline void cec_notifier_conn_unregister(struct cec_notifier *n) |
| 121 | { |
| 122 | } |
| 123 | |
| 124 | static inline struct cec_notifier * |
Hans Verkuil | 80f13a0 | 2020-03-16 10:36:47 +0100 | [diff] [blame] | 125 | cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *port_name, |
Hans Verkuil | b48cb35 | 2019-06-20 06:10:00 -0400 | [diff] [blame] | 126 | struct cec_adapter *adap) |
| 127 | { |
| 128 | /* A non-NULL pointer is expected on success */ |
| 129 | return (struct cec_notifier *)0xdeadfeed; |
| 130 | } |
| 131 | |
Hans Verkuil | 10d8f30 | 2019-10-04 13:04:24 +0200 | [diff] [blame] | 132 | static inline void cec_notifier_cec_adap_unregister(struct cec_notifier *n, |
| 133 | struct cec_adapter *adap) |
Hans Verkuil | b48cb35 | 2019-06-20 06:10:00 -0400 | [diff] [blame] | 134 | { |
| 135 | } |
| 136 | |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 137 | static inline void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa) |
| 138 | { |
| 139 | } |
| 140 | |
| 141 | static inline void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n, |
| 142 | const struct edid *edid) |
| 143 | { |
| 144 | } |
| 145 | |
Hans Verkuil | fbbd403 | 2019-04-10 05:13:28 -0400 | [diff] [blame] | 146 | static inline struct device *cec_notifier_parse_hdmi_phandle(struct device *dev) |
| 147 | { |
| 148 | return ERR_PTR(-ENODEV); |
| 149 | } |
| 150 | |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 151 | #endif |
| 152 | |
Hans Verkuil | fc1ff45 | 2017-07-15 09:32:56 -0300 | [diff] [blame] | 153 | /** |
| 154 | * cec_notifier_phys_addr_invalidate() - set the physical address to INVALID |
| 155 | * |
| 156 | * @n: the CEC notifier |
| 157 | * |
| 158 | * This is a simple helper function to invalidate the physical |
| 159 | * address. Does nothing if @n == NULL. |
| 160 | */ |
| 161 | static inline void cec_notifier_phys_addr_invalidate(struct cec_notifier *n) |
| 162 | { |
| 163 | cec_notifier_set_phys_addr(n, CEC_PHYS_ADDR_INVALID); |
| 164 | } |
| 165 | |
Hans Verkuil | 6917a7b | 2016-11-14 11:55:20 -0200 | [diff] [blame] | 166 | #endif |