blob: 139e93be13b003906c9766478089a8564d780389 [file] [log] [blame]
Hans Verkuilab15d242018-02-07 09:05:46 -05001/* SPDX-License-Identifier: GPL-2.0-only */
Hans Verkuil6917a7b2016-11-14 11:55:20 -02002/*
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 Verkuil6917a7b2016-11-14 11:55:20 -02007 */
8
9#ifndef LINUX_CEC_NOTIFIER_H
10#define LINUX_CEC_NOTIFIER_H
11
Hans Verkuilfbbd4032019-04-10 05:13:28 -040012#include <linux/err.h>
Hans Verkuilee7e98712017-04-17 07:54:37 -030013#include <media/cec.h>
Hans Verkuil6917a7b2016-11-14 11:55:20 -020014
15struct device;
16struct edid;
17struct cec_adapter;
18struct cec_notifier;
19
Hans Verkuile94c3282017-05-28 05:58:04 -030020#if IS_REACHABLE(CONFIG_CEC_CORE) && IS_ENABLED(CONFIG_CEC_NOTIFIER)
Hans Verkuil6917a7b2016-11-14 11:55:20 -020021
22/**
Neil Armstrong7a78c1e2018-07-04 17:08:16 +020023 * cec_notifier_get_conn - find or create a new cec_notifier for the given
24 * device and connector tuple.
Hans Verkuil6917a7b2016-11-14 11:55:20 -020025 * @dev: device that sends the events.
Neil Armstrong7a78c1e2018-07-04 17:08:16 +020026 * @conn: the connector name from which the event occurs
Hans Verkuil6917a7b2016-11-14 11:55:20 -020027 *
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 Armstrong7a78c1e2018-07-04 17:08:16 +020036struct cec_notifier *cec_notifier_get_conn(struct device *dev,
37 const char *conn);
Hans Verkuil6917a7b2016-11-14 11:55:20 -020038
39/**
Hans Verkuilb48cb352019-06-20 06:10:00 -040040 * 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 */
55struct cec_notifier *
56cec_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 */
64void 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 */
82struct cec_notifier *
83cec_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 Verkuil10d8f302019-10-04 13:04:24 +020090 * @adap: the cec adapter that registered this notifier.
Hans Verkuilb48cb352019-06-20 06:10:00 -040091 */
Hans Verkuil10d8f302019-10-04 13:04:24 +020092void cec_notifier_cec_adap_unregister(struct cec_notifier *n,
93 struct cec_adapter *adap);
Hans Verkuilb48cb352019-06-20 06:10:00 -040094
95/**
Hans Verkuil6917a7b2016-11-14 11:55:20 -020096 * 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 Verkuilfc1ff452017-07-15 09:32:56 -0300101 * Does nothing if @n == NULL.
Hans Verkuil6917a7b2016-11-14 11:55:20 -0200102 */
103void 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 Verkuilfc1ff452017-07-15 09:32:56 -0300111 * Does nothing if @n == NULL.
Hans Verkuil6917a7b2016-11-14 11:55:20 -0200112 */
113void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
114 const struct edid *edid);
115
116/**
Hans Verkuilfbbd4032019-04-10 05:13:28 -0400117 * 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 */
125struct device *cec_notifier_parse_hdmi_phandle(struct device *dev);
126
Hans Verkuil6917a7b2016-11-14 11:55:20 -0200127#else
Neil Armstrong7a78c1e2018-07-04 17:08:16 +0200128static inline struct cec_notifier *cec_notifier_get_conn(struct device *dev,
129 const char *conn)
Hans Verkuil6917a7b2016-11-14 11:55:20 -0200130{
131 /* A non-NULL pointer is expected on success */
132 return (struct cec_notifier *)0xdeadfeed;
133}
134
Hans Verkuilb48cb352019-06-20 06:10:00 -0400135static inline struct cec_notifier *
136cec_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
143static inline void cec_notifier_conn_unregister(struct cec_notifier *n)
144{
145}
146
147static inline struct cec_notifier *
148cec_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 Verkuil10d8f302019-10-04 13:04:24 +0200155static inline void cec_notifier_cec_adap_unregister(struct cec_notifier *n,
156 struct cec_adapter *adap)
Hans Verkuilb48cb352019-06-20 06:10:00 -0400157{
158}
159
Hans Verkuil6917a7b2016-11-14 11:55:20 -0200160static inline void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa)
161{
162}
163
164static inline void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
165 const struct edid *edid)
166{
167}
168
Hans Verkuilfbbd4032019-04-10 05:13:28 -0400169static inline struct device *cec_notifier_parse_hdmi_phandle(struct device *dev)
170{
171 return ERR_PTR(-ENODEV);
172}
173
Hans Verkuil6917a7b2016-11-14 11:55:20 -0200174#endif
175
Hans Verkuilfc1ff452017-07-15 09:32:56 -0300176/**
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 */
184static 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 Verkuil6917a7b2016-11-14 11:55:20 -0200189#endif