Commit 7a78c1e1 authored by Neil Armstrong's avatar Neil Armstrong Committed by Lee Jones

media: cec-notifier: Get notifier by device and connector name

In non device-tree world, we can need to get the notifier by the driver
name directly and eventually defer probe if not yet created.

This patch adds a variant of the get function by using the device name
instead and will not create a notifier if not yet created.

But the i915 driver exposes at least 2 HDMI connectors, this patch also
adds the possibility to add a connector name tied to the notifier device
to form a tuple and associate different CEC controllers for each HDMI
connectors.
Signed-off-by: default avatarNeil Armstrong <narmstrong@baylibre.com>
Reviewed-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
parent ce397d21
...@@ -21,6 +21,7 @@ struct cec_notifier { ...@@ -21,6 +21,7 @@ struct cec_notifier {
struct list_head head; struct list_head head;
struct kref kref; struct kref kref;
struct device *dev; struct device *dev;
const char *conn;
struct cec_adapter *cec_adap; struct cec_adapter *cec_adap;
void (*callback)(struct cec_adapter *adap, u16 pa); void (*callback)(struct cec_adapter *adap, u16 pa);
...@@ -30,13 +31,14 @@ struct cec_notifier { ...@@ -30,13 +31,14 @@ struct cec_notifier {
static LIST_HEAD(cec_notifiers); static LIST_HEAD(cec_notifiers);
static DEFINE_MUTEX(cec_notifiers_lock); static DEFINE_MUTEX(cec_notifiers_lock);
struct cec_notifier *cec_notifier_get(struct device *dev) struct cec_notifier *cec_notifier_get_conn(struct device *dev, const char *conn)
{ {
struct cec_notifier *n; struct cec_notifier *n;
mutex_lock(&cec_notifiers_lock); mutex_lock(&cec_notifiers_lock);
list_for_each_entry(n, &cec_notifiers, head) { list_for_each_entry(n, &cec_notifiers, head) {
if (n->dev == dev) { if (n->dev == dev &&
(!conn || !strcmp(n->conn, conn))) {
kref_get(&n->kref); kref_get(&n->kref);
mutex_unlock(&cec_notifiers_lock); mutex_unlock(&cec_notifiers_lock);
return n; return n;
...@@ -46,6 +48,8 @@ struct cec_notifier *cec_notifier_get(struct device *dev) ...@@ -46,6 +48,8 @@ struct cec_notifier *cec_notifier_get(struct device *dev)
if (!n) if (!n)
goto unlock; goto unlock;
n->dev = dev; n->dev = dev;
if (conn)
n->conn = kstrdup(conn, GFP_KERNEL);
n->phys_addr = CEC_PHYS_ADDR_INVALID; n->phys_addr = CEC_PHYS_ADDR_INVALID;
mutex_init(&n->lock); mutex_init(&n->lock);
kref_init(&n->kref); kref_init(&n->kref);
...@@ -54,7 +58,7 @@ struct cec_notifier *cec_notifier_get(struct device *dev) ...@@ -54,7 +58,7 @@ struct cec_notifier *cec_notifier_get(struct device *dev)
mutex_unlock(&cec_notifiers_lock); mutex_unlock(&cec_notifiers_lock);
return n; return n;
} }
EXPORT_SYMBOL_GPL(cec_notifier_get); EXPORT_SYMBOL_GPL(cec_notifier_get_conn);
static void cec_notifier_release(struct kref *kref) static void cec_notifier_release(struct kref *kref)
{ {
...@@ -62,6 +66,7 @@ static void cec_notifier_release(struct kref *kref) ...@@ -62,6 +66,7 @@ static void cec_notifier_release(struct kref *kref)
container_of(kref, struct cec_notifier, kref); container_of(kref, struct cec_notifier, kref);
list_del(&n->head); list_del(&n->head);
kfree(n->conn);
kfree(n); kfree(n);
} }
......
...@@ -20,8 +20,10 @@ struct cec_notifier; ...@@ -20,8 +20,10 @@ struct cec_notifier;
#if IS_REACHABLE(CONFIG_CEC_CORE) && IS_ENABLED(CONFIG_CEC_NOTIFIER) #if IS_REACHABLE(CONFIG_CEC_CORE) && IS_ENABLED(CONFIG_CEC_NOTIFIER)
/** /**
* cec_notifier_get - find or create a new cec_notifier for the given device. * cec_notifier_get_conn - find or create a new cec_notifier for the given
* device and connector tuple.
* @dev: device that sends the events. * @dev: device that sends the events.
* @conn: the connector name from which the event occurs
* *
* If a notifier for device @dev already exists, then increase the refcount * If a notifier for device @dev already exists, then increase the refcount
* and return that notifier. * and return that notifier.
...@@ -31,7 +33,8 @@ struct cec_notifier; ...@@ -31,7 +33,8 @@ struct cec_notifier;
* *
* Return NULL if the memory could not be allocated. * Return NULL if the memory could not be allocated.
*/ */
struct cec_notifier *cec_notifier_get(struct device *dev); struct cec_notifier *cec_notifier_get_conn(struct device *dev,
const char *conn);
/** /**
* cec_notifier_put - decrease refcount and delete when the refcount reaches 0. * cec_notifier_put - decrease refcount and delete when the refcount reaches 0.
...@@ -85,7 +88,8 @@ void cec_register_cec_notifier(struct cec_adapter *adap, ...@@ -85,7 +88,8 @@ void cec_register_cec_notifier(struct cec_adapter *adap,
struct cec_notifier *notifier); struct cec_notifier *notifier);
#else #else
static inline struct cec_notifier *cec_notifier_get(struct device *dev) static inline struct cec_notifier *cec_notifier_get_conn(struct device *dev,
const char *conn)
{ {
/* A non-NULL pointer is expected on success */ /* A non-NULL pointer is expected on success */
return (struct cec_notifier *)0xdeadfeed; return (struct cec_notifier *)0xdeadfeed;
...@@ -120,6 +124,23 @@ static inline void cec_register_cec_notifier(struct cec_adapter *adap, ...@@ -120,6 +124,23 @@ static inline void cec_register_cec_notifier(struct cec_adapter *adap,
} }
#endif #endif
/**
* cec_notifier_get - find or create a new cec_notifier for the given device.
* @dev: device that sends the events.
*
* If a notifier for device @dev already exists, then increase the refcount
* and return that notifier.
*
* If it doesn't exist, then allocate a new notifier struct and return a
* pointer to that new struct.
*
* Return NULL if the memory could not be allocated.
*/
static inline struct cec_notifier *cec_notifier_get(struct device *dev)
{
return cec_notifier_get_conn(dev, NULL);
}
/** /**
* cec_notifier_phys_addr_invalidate() - set the physical address to INVALID * cec_notifier_phys_addr_invalidate() - set the physical address to INVALID
* *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment