Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * cec-notifier.h - notify CEC drivers of physical address changes
0004  *
0005  * Copyright 2016 Russell King.
0006  * Copyright 2016-2017 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
0007  */
0008 
0009 #ifndef LINUX_CEC_NOTIFIER_H
0010 #define LINUX_CEC_NOTIFIER_H
0011 
0012 #include <linux/err.h>
0013 #include <media/cec.h>
0014 
0015 struct device;
0016 struct edid;
0017 struct cec_adapter;
0018 struct cec_notifier;
0019 
0020 #if IS_REACHABLE(CONFIG_CEC_CORE) && IS_ENABLED(CONFIG_CEC_NOTIFIER)
0021 
0022 /**
0023  * cec_notifier_conn_register - find or create a new cec_notifier for the given
0024  * HDMI device and connector tuple.
0025  * @hdmi_dev: HDMI device that sends the events.
0026  * @port_name: the connector name from which the event occurs. May be NULL
0027  * if there is always only one HDMI connector created by the HDMI device.
0028  * @conn_info: the connector info from which the event occurs (may be NULL)
0029  *
0030  * If a notifier for device @dev and connector @port_name already exists, then
0031  * increase the refcount and return that notifier.
0032  *
0033  * If it doesn't exist, then allocate a new notifier struct and return a
0034  * pointer to that new struct.
0035  *
0036  * Return NULL if the memory could not be allocated.
0037  */
0038 struct cec_notifier *
0039 cec_notifier_conn_register(struct device *hdmi_dev, const char *port_name,
0040                const struct cec_connector_info *conn_info);
0041 
0042 /**
0043  * cec_notifier_conn_unregister - decrease refcount and delete when the
0044  * refcount reaches 0.
0045  * @n: notifier. If NULL, then this function does nothing.
0046  */
0047 void cec_notifier_conn_unregister(struct cec_notifier *n);
0048 
0049 /**
0050  * cec_notifier_cec_adap_register - find or create a new cec_notifier for the
0051  * given device.
0052  * @hdmi_dev: HDMI device that sends the events.
0053  * @port_name: the connector name from which the event occurs. May be NULL
0054  * if there is always only one HDMI connector created by the HDMI device.
0055  * @adap: the cec adapter that registered this notifier.
0056  *
0057  * If a notifier for device @dev and connector @port_name already exists, then
0058  * increase the refcount and return that notifier.
0059  *
0060  * If it doesn't exist, then allocate a new notifier struct and return a
0061  * pointer to that new struct.
0062  *
0063  * Return NULL if the memory could not be allocated.
0064  */
0065 struct cec_notifier *
0066 cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *port_name,
0067                    struct cec_adapter *adap);
0068 
0069 /**
0070  * cec_notifier_cec_adap_unregister - decrease refcount and delete when the
0071  * refcount reaches 0.
0072  * @n: notifier. If NULL, then this function does nothing.
0073  * @adap: the cec adapter that registered this notifier.
0074  */
0075 void cec_notifier_cec_adap_unregister(struct cec_notifier *n,
0076                       struct cec_adapter *adap);
0077 
0078 /**
0079  * cec_notifier_set_phys_addr - set a new physical address.
0080  * @n: the CEC notifier
0081  * @pa: the CEC physical address
0082  *
0083  * Set a new CEC physical address.
0084  * Does nothing if @n == NULL.
0085  */
0086 void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa);
0087 
0088 /**
0089  * cec_notifier_set_phys_addr_from_edid - set parse the PA from the EDID.
0090  * @n: the CEC notifier
0091  * @edid: the struct edid pointer
0092  *
0093  * Parses the EDID to obtain the new CEC physical address and set it.
0094  * Does nothing if @n == NULL.
0095  */
0096 void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
0097                       const struct edid *edid);
0098 
0099 /**
0100  * cec_notifier_parse_hdmi_phandle - find the hdmi device from "hdmi-phandle"
0101  * @dev: the device with the "hdmi-phandle" device tree property
0102  *
0103  * Returns the device pointer referenced by the "hdmi-phandle" property.
0104  * Note that the refcount of the returned device is not incremented.
0105  * This device pointer is only used as a key value in the notifier
0106  * list, but it is never accessed by the CEC driver.
0107  */
0108 struct device *cec_notifier_parse_hdmi_phandle(struct device *dev);
0109 
0110 #else
0111 
0112 static inline struct cec_notifier *
0113 cec_notifier_conn_register(struct device *hdmi_dev, const char *port_name,
0114                const struct cec_connector_info *conn_info)
0115 {
0116     /* A non-NULL pointer is expected on success */
0117     return (struct cec_notifier *)0xdeadfeed;
0118 }
0119 
0120 static inline void cec_notifier_conn_unregister(struct cec_notifier *n)
0121 {
0122 }
0123 
0124 static inline struct cec_notifier *
0125 cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *port_name,
0126                    struct cec_adapter *adap)
0127 {
0128     /* A non-NULL pointer is expected on success */
0129     return (struct cec_notifier *)0xdeadfeed;
0130 }
0131 
0132 static inline void cec_notifier_cec_adap_unregister(struct cec_notifier *n,
0133                             struct cec_adapter *adap)
0134 {
0135 }
0136 
0137 static inline void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa)
0138 {
0139 }
0140 
0141 static inline void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
0142                             const struct edid *edid)
0143 {
0144 }
0145 
0146 static inline struct device *cec_notifier_parse_hdmi_phandle(struct device *dev)
0147 {
0148     return ERR_PTR(-ENODEV);
0149 }
0150 
0151 #endif
0152 
0153 /**
0154  * cec_notifier_phys_addr_invalidate() - set the physical address to INVALID
0155  *
0156  * @n: the CEC notifier
0157  *
0158  * This is a simple helper function to invalidate the physical
0159  * address. Does nothing if @n == NULL.
0160  */
0161 static inline void cec_notifier_phys_addr_invalidate(struct cec_notifier *n)
0162 {
0163     cec_notifier_set_phys_addr(n, CEC_PHYS_ADDR_INVALID);
0164 }
0165 
0166 #endif