1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * cec-notifier.h - notify CEC drivers of physical address changes
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.
9 #ifndef LINUX_CEC_NOTIFIER_H
10 #define LINUX_CEC_NOTIFIER_H
12 #include <linux/types.h>
13 #include <media/cec.h>
20 #if IS_REACHABLE(CONFIG_CEC_CORE) && IS_ENABLED(CONFIG_CEC_NOTIFIER)
23 * cec_notifier_get - find or create a new cec_notifier for the given device.
24 * @dev: device that sends the events.
26 * If a notifier for device @dev already exists, then increase the refcount
27 * and return that notifier.
29 * If it doesn't exist, then allocate a new notifier struct and return a
30 * pointer to that new struct.
32 * Return NULL if the memory could not be allocated.
34 struct cec_notifier *cec_notifier_get(struct device *dev);
37 * cec_notifier_put - decrease refcount and delete when the refcount reaches 0.
40 void cec_notifier_put(struct cec_notifier *n);
43 * cec_notifier_set_phys_addr - set a new physical address.
44 * @n: the CEC notifier
45 * @pa: the CEC physical address
47 * Set a new CEC physical address.
48 * Does nothing if @n == NULL.
50 void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa);
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
57 * Parses the EDID to obtain the new CEC physical address and set it.
58 * Does nothing if @n == NULL.
60 void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
61 const struct edid *edid);
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
69 void cec_notifier_register(struct cec_notifier *n,
70 struct cec_adapter *adap,
71 void (*callback)(struct cec_adapter *adap, u16 pa));
74 * cec_notifier_unregister - unregister the callback from the notifier.
75 * @n: the CEC notifier
77 void cec_notifier_unregister(struct cec_notifier *n);
80 * cec_register_cec_notifier - register the notifier with the cec adapter.
81 * @adap: the CEC adapter
82 * @notifier: the CEC notifier
84 void cec_register_cec_notifier(struct cec_adapter *adap,
85 struct cec_notifier *notifier);
88 static inline struct cec_notifier *cec_notifier_get(struct device *dev)
90 /* A non-NULL pointer is expected on success */
91 return (struct cec_notifier *)0xdeadfeed;
94 static inline void cec_notifier_put(struct cec_notifier *n)
98 static inline void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa)
102 static inline void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
103 const struct edid *edid)
107 static inline void cec_notifier_register(struct cec_notifier *n,
108 struct cec_adapter *adap,
109 void (*callback)(struct cec_adapter *adap, u16 pa))
113 static inline void cec_notifier_unregister(struct cec_notifier *n)
117 static inline void cec_register_cec_notifier(struct cec_adapter *adap,
118 struct cec_notifier *notifier)
124 * cec_notifier_phys_addr_invalidate() - set the physical address to INVALID
126 * @n: the CEC notifier
128 * This is a simple helper function to invalidate the physical
129 * address. Does nothing if @n == NULL.
131 static inline void cec_notifier_phys_addr_invalidate(struct cec_notifier *n)
133 cec_notifier_set_phys_addr(n, CEC_PHYS_ADDR_INVALID);