Loading...
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * cec-notifier.h - notify CEC drivers of physical address changes
4 *
5 * Copyright 2016 Russell King.
6 * Copyright 2016-2017 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
7 */
8
9#ifndef LINUX_CEC_NOTIFIER_H
10#define LINUX_CEC_NOTIFIER_H
11
12#include <linux/err.h>
13#include <media/cec.h>
14
15struct device;
16struct edid;
17struct cec_adapter;
18struct cec_notifier;
19
20#if IS_REACHABLE(CONFIG_CEC_CORE) && IS_ENABLED(CONFIG_CEC_NOTIFIER)
21
22/**
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.
26 * @port_name: the connector name from which the event occurs. May be NULL
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 *
30 * If a notifier for device @dev and connector @port_name already exists, then
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 */
38struct cec_notifier *
39cec_notifier_conn_register(struct device *hdmi_dev, const char *port_name,
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 */
47void 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.
53 * @port_name: the connector name from which the event occurs. May be NULL
54 * if there is always only one HDMI connector created by the HDMI device.
55 * @adap: the cec adapter that registered this notifier.
56 *
57 * If a notifier for device @dev and connector @port_name already exists, then
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 */
65struct cec_notifier *
66cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *port_name,
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.
73 * @adap: the cec adapter that registered this notifier.
74 */
75void cec_notifier_cec_adap_unregister(struct cec_notifier *n,
76 struct cec_adapter *adap);
77
78/**
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.
84 * Does nothing if @n == NULL.
85 */
86void 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.
94 * Does nothing if @n == NULL.
95 */
96void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
97 const struct edid *edid);
98
99/**
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 */
108struct device *cec_notifier_parse_hdmi_phandle(struct device *dev);
109
110#else
111
112static inline struct cec_notifier *
113cec_notifier_conn_register(struct device *hdmi_dev, const char *port_name,
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
120static inline void cec_notifier_conn_unregister(struct cec_notifier *n)
121{
122}
123
124static inline struct cec_notifier *
125cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *port_name,
126 struct cec_adapter *adap)
127{
128 /* A non-NULL pointer is expected on success */
129 return (struct cec_notifier *)0xdeadfeed;
130}
131
132static inline void cec_notifier_cec_adap_unregister(struct cec_notifier *n,
133 struct cec_adapter *adap)
134{
135}
136
137static inline void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa)
138{
139}
140
141static inline void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
142 const struct edid *edid)
143{
144}
145
146static inline struct device *cec_notifier_parse_hdmi_phandle(struct device *dev)
147{
148 return ERR_PTR(-ENODEV);
149}
150
151#endif
152
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 */
161static 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
166#endif
1/* SPDX-License-Identifier: GPL-2.0-only */
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.
7 */
8
9#ifndef LINUX_CEC_NOTIFIER_H
10#define LINUX_CEC_NOTIFIER_H
11
12#include <linux/types.h>
13#include <media/cec.h>
14
15struct device;
16struct edid;
17struct cec_adapter;
18struct cec_notifier;
19
20#if IS_REACHABLE(CONFIG_CEC_CORE) && IS_ENABLED(CONFIG_CEC_NOTIFIER)
21
22/**
23 * cec_notifier_get - find or create a new cec_notifier for the given device.
24 * @dev: device that sends the events.
25 *
26 * If a notifier for device @dev already exists, then increase the refcount
27 * and return that notifier.
28 *
29 * If it doesn't exist, then allocate a new notifier struct and return a
30 * pointer to that new struct.
31 *
32 * Return NULL if the memory could not be allocated.
33 */
34struct cec_notifier *cec_notifier_get(struct device *dev);
35
36/**
37 * cec_notifier_put - decrease refcount and delete when the refcount reaches 0.
38 * @n: notifier
39 */
40void cec_notifier_put(struct cec_notifier *n);
41
42/**
43 * cec_notifier_set_phys_addr - set a new physical address.
44 * @n: the CEC notifier
45 * @pa: the CEC physical address
46 *
47 * Set a new CEC physical address.
48 * Does nothing if @n == NULL.
49 */
50void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa);
51
52/**
53 * cec_notifier_set_phys_addr_from_edid - set parse the PA from the EDID.
54 * @n: the CEC notifier
55 * @edid: the struct edid pointer
56 *
57 * Parses the EDID to obtain the new CEC physical address and set it.
58 * Does nothing if @n == NULL.
59 */
60void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
61 const struct edid *edid);
62
63/**
64 * cec_notifier_register - register a callback with the notifier
65 * @n: the CEC notifier
66 * @adap: the CEC adapter, passed as argument to the callback function
67 * @callback: the callback function
68 */
69void cec_notifier_register(struct cec_notifier *n,
70 struct cec_adapter *adap,
71 void (*callback)(struct cec_adapter *adap, u16 pa));
72
73/**
74 * cec_notifier_unregister - unregister the callback from the notifier.
75 * @n: the CEC notifier
76 */
77void cec_notifier_unregister(struct cec_notifier *n);
78
79/**
80 * cec_register_cec_notifier - register the notifier with the cec adapter.
81 * @adap: the CEC adapter
82 * @notifier: the CEC notifier
83 */
84void cec_register_cec_notifier(struct cec_adapter *adap,
85 struct cec_notifier *notifier);
86
87#else
88static inline struct cec_notifier *cec_notifier_get(struct device *dev)
89{
90 /* A non-NULL pointer is expected on success */
91 return (struct cec_notifier *)0xdeadfeed;
92}
93
94static inline void cec_notifier_put(struct cec_notifier *n)
95{
96}
97
98static inline void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa)
99{
100}
101
102static inline void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
103 const struct edid *edid)
104{
105}
106
107static inline void cec_notifier_register(struct cec_notifier *n,
108 struct cec_adapter *adap,
109 void (*callback)(struct cec_adapter *adap, u16 pa))
110{
111}
112
113static inline void cec_notifier_unregister(struct cec_notifier *n)
114{
115}
116
117static inline void cec_register_cec_notifier(struct cec_adapter *adap,
118 struct cec_notifier *notifier)
119{
120}
121#endif
122
123/**
124 * cec_notifier_phys_addr_invalidate() - set the physical address to INVALID
125 *
126 * @n: the CEC notifier
127 *
128 * This is a simple helper function to invalidate the physical
129 * address. Does nothing if @n == NULL.
130 */
131static inline void cec_notifier_phys_addr_invalidate(struct cec_notifier *n)
132{
133 cec_notifier_set_phys_addr(n, CEC_PHYS_ADDR_INVALID);
134}
135
136#endif