18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * cec-notifier.h - notify CEC drivers of physical address changes
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright 2016 Russell King.
68c2ecf20Sopenharmony_ci * Copyright 2016-2017 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#ifndef LINUX_CEC_NOTIFIER_H
108c2ecf20Sopenharmony_ci#define LINUX_CEC_NOTIFIER_H
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/err.h>
138c2ecf20Sopenharmony_ci#include <media/cec.h>
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_cistruct device;
168c2ecf20Sopenharmony_cistruct edid;
178c2ecf20Sopenharmony_cistruct cec_adapter;
188c2ecf20Sopenharmony_cistruct cec_notifier;
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#if IS_REACHABLE(CONFIG_CEC_CORE) && IS_ENABLED(CONFIG_CEC_NOTIFIER)
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci/**
238c2ecf20Sopenharmony_ci * cec_notifier_conn_register - find or create a new cec_notifier for the given
248c2ecf20Sopenharmony_ci * HDMI device and connector tuple.
258c2ecf20Sopenharmony_ci * @hdmi_dev: HDMI device that sends the events.
268c2ecf20Sopenharmony_ci * @port_name: the connector name from which the event occurs. May be NULL
278c2ecf20Sopenharmony_ci * if there is always only one HDMI connector created by the HDMI device.
288c2ecf20Sopenharmony_ci * @conn_info: the connector info from which the event occurs (may be NULL)
298c2ecf20Sopenharmony_ci *
308c2ecf20Sopenharmony_ci * If a notifier for device @dev and connector @port_name already exists, then
318c2ecf20Sopenharmony_ci * increase the refcount and return that notifier.
328c2ecf20Sopenharmony_ci *
338c2ecf20Sopenharmony_ci * If it doesn't exist, then allocate a new notifier struct and return a
348c2ecf20Sopenharmony_ci * pointer to that new struct.
358c2ecf20Sopenharmony_ci *
368c2ecf20Sopenharmony_ci * Return NULL if the memory could not be allocated.
378c2ecf20Sopenharmony_ci */
388c2ecf20Sopenharmony_cistruct cec_notifier *
398c2ecf20Sopenharmony_cicec_notifier_conn_register(struct device *hdmi_dev, const char *port_name,
408c2ecf20Sopenharmony_ci			   const struct cec_connector_info *conn_info);
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci/**
438c2ecf20Sopenharmony_ci * cec_notifier_conn_unregister - decrease refcount and delete when the
448c2ecf20Sopenharmony_ci * refcount reaches 0.
458c2ecf20Sopenharmony_ci * @n: notifier. If NULL, then this function does nothing.
468c2ecf20Sopenharmony_ci */
478c2ecf20Sopenharmony_civoid cec_notifier_conn_unregister(struct cec_notifier *n);
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci/**
508c2ecf20Sopenharmony_ci * cec_notifier_cec_adap_register - find or create a new cec_notifier for the
518c2ecf20Sopenharmony_ci * given device.
528c2ecf20Sopenharmony_ci * @hdmi_dev: HDMI device that sends the events.
538c2ecf20Sopenharmony_ci * @port_name: the connector name from which the event occurs. May be NULL
548c2ecf20Sopenharmony_ci * if there is always only one HDMI connector created by the HDMI device.
558c2ecf20Sopenharmony_ci * @adap: the cec adapter that registered this notifier.
568c2ecf20Sopenharmony_ci *
578c2ecf20Sopenharmony_ci * If a notifier for device @dev and connector @port_name already exists, then
588c2ecf20Sopenharmony_ci * increase the refcount and return that notifier.
598c2ecf20Sopenharmony_ci *
608c2ecf20Sopenharmony_ci * If it doesn't exist, then allocate a new notifier struct and return a
618c2ecf20Sopenharmony_ci * pointer to that new struct.
628c2ecf20Sopenharmony_ci *
638c2ecf20Sopenharmony_ci * Return NULL if the memory could not be allocated.
648c2ecf20Sopenharmony_ci */
658c2ecf20Sopenharmony_cistruct cec_notifier *
668c2ecf20Sopenharmony_cicec_notifier_cec_adap_register(struct device *hdmi_dev, const char *port_name,
678c2ecf20Sopenharmony_ci			       struct cec_adapter *adap);
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci/**
708c2ecf20Sopenharmony_ci * cec_notifier_cec_adap_unregister - decrease refcount and delete when the
718c2ecf20Sopenharmony_ci * refcount reaches 0.
728c2ecf20Sopenharmony_ci * @n: notifier. If NULL, then this function does nothing.
738c2ecf20Sopenharmony_ci * @adap: the cec adapter that registered this notifier.
748c2ecf20Sopenharmony_ci */
758c2ecf20Sopenharmony_civoid cec_notifier_cec_adap_unregister(struct cec_notifier *n,
768c2ecf20Sopenharmony_ci				      struct cec_adapter *adap);
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci/**
798c2ecf20Sopenharmony_ci * cec_notifier_set_phys_addr - set a new physical address.
808c2ecf20Sopenharmony_ci * @n: the CEC notifier
818c2ecf20Sopenharmony_ci * @pa: the CEC physical address
828c2ecf20Sopenharmony_ci *
838c2ecf20Sopenharmony_ci * Set a new CEC physical address.
848c2ecf20Sopenharmony_ci * Does nothing if @n == NULL.
858c2ecf20Sopenharmony_ci */
868c2ecf20Sopenharmony_civoid cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa);
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci/**
898c2ecf20Sopenharmony_ci * cec_notifier_set_phys_addr_from_edid - set parse the PA from the EDID.
908c2ecf20Sopenharmony_ci * @n: the CEC notifier
918c2ecf20Sopenharmony_ci * @edid: the struct edid pointer
928c2ecf20Sopenharmony_ci *
938c2ecf20Sopenharmony_ci * Parses the EDID to obtain the new CEC physical address and set it.
948c2ecf20Sopenharmony_ci * Does nothing if @n == NULL.
958c2ecf20Sopenharmony_ci */
968c2ecf20Sopenharmony_civoid cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
978c2ecf20Sopenharmony_ci					  const struct edid *edid);
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci/**
1008c2ecf20Sopenharmony_ci * cec_notifier_parse_hdmi_phandle - find the hdmi device from "hdmi-phandle"
1018c2ecf20Sopenharmony_ci * @dev: the device with the "hdmi-phandle" device tree property
1028c2ecf20Sopenharmony_ci *
1038c2ecf20Sopenharmony_ci * Returns the device pointer referenced by the "hdmi-phandle" property.
1048c2ecf20Sopenharmony_ci * Note that the refcount of the returned device is not incremented.
1058c2ecf20Sopenharmony_ci * This device pointer is only used as a key value in the notifier
1068c2ecf20Sopenharmony_ci * list, but it is never accessed by the CEC driver.
1078c2ecf20Sopenharmony_ci */
1088c2ecf20Sopenharmony_cistruct device *cec_notifier_parse_hdmi_phandle(struct device *dev);
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci#else
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_cistatic inline struct cec_notifier *
1138c2ecf20Sopenharmony_cicec_notifier_conn_register(struct device *hdmi_dev, const char *port_name,
1148c2ecf20Sopenharmony_ci			   const struct cec_connector_info *conn_info)
1158c2ecf20Sopenharmony_ci{
1168c2ecf20Sopenharmony_ci	/* A non-NULL pointer is expected on success */
1178c2ecf20Sopenharmony_ci	return (struct cec_notifier *)0xdeadfeed;
1188c2ecf20Sopenharmony_ci}
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_cistatic inline void cec_notifier_conn_unregister(struct cec_notifier *n)
1218c2ecf20Sopenharmony_ci{
1228c2ecf20Sopenharmony_ci}
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_cistatic inline struct cec_notifier *
1258c2ecf20Sopenharmony_cicec_notifier_cec_adap_register(struct device *hdmi_dev, const char *port_name,
1268c2ecf20Sopenharmony_ci			       struct cec_adapter *adap)
1278c2ecf20Sopenharmony_ci{
1288c2ecf20Sopenharmony_ci	/* A non-NULL pointer is expected on success */
1298c2ecf20Sopenharmony_ci	return (struct cec_notifier *)0xdeadfeed;
1308c2ecf20Sopenharmony_ci}
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_cistatic inline void cec_notifier_cec_adap_unregister(struct cec_notifier *n,
1338c2ecf20Sopenharmony_ci						    struct cec_adapter *adap)
1348c2ecf20Sopenharmony_ci{
1358c2ecf20Sopenharmony_ci}
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_cistatic inline void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa)
1388c2ecf20Sopenharmony_ci{
1398c2ecf20Sopenharmony_ci}
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_cistatic inline void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
1428c2ecf20Sopenharmony_ci							const struct edid *edid)
1438c2ecf20Sopenharmony_ci{
1448c2ecf20Sopenharmony_ci}
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_cistatic inline struct device *cec_notifier_parse_hdmi_phandle(struct device *dev)
1478c2ecf20Sopenharmony_ci{
1488c2ecf20Sopenharmony_ci	return ERR_PTR(-ENODEV);
1498c2ecf20Sopenharmony_ci}
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci#endif
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci/**
1548c2ecf20Sopenharmony_ci * cec_notifier_phys_addr_invalidate() - set the physical address to INVALID
1558c2ecf20Sopenharmony_ci *
1568c2ecf20Sopenharmony_ci * @n: the CEC notifier
1578c2ecf20Sopenharmony_ci *
1588c2ecf20Sopenharmony_ci * This is a simple helper function to invalidate the physical
1598c2ecf20Sopenharmony_ci * address. Does nothing if @n == NULL.
1608c2ecf20Sopenharmony_ci */
1618c2ecf20Sopenharmony_cistatic inline void cec_notifier_phys_addr_invalidate(struct cec_notifier *n)
1628c2ecf20Sopenharmony_ci{
1638c2ecf20Sopenharmony_ci	cec_notifier_set_phys_addr(n, CEC_PHYS_ADDR_INVALID);
1648c2ecf20Sopenharmony_ci}
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci#endif
167