Skip to content

Commit 7a78c1e

Browse files
superna9999Lee Jones
authored andcommitted
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: Neil Armstrong <narmstrong@baylibre.com> Reviewed-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Lee Jones <lee.jones@linaro.org>
1 parent ce397d2 commit 7a78c1e

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

drivers/media/cec/cec-notifier.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct cec_notifier {
2121
struct list_head head;
2222
struct kref kref;
2323
struct device *dev;
24+
const char *conn;
2425
struct cec_adapter *cec_adap;
2526
void (*callback)(struct cec_adapter *adap, u16 pa);
2627

@@ -30,13 +31,14 @@ struct cec_notifier {
3031
static LIST_HEAD(cec_notifiers);
3132
static DEFINE_MUTEX(cec_notifiers_lock);
3233

33-
struct cec_notifier *cec_notifier_get(struct device *dev)
34+
struct cec_notifier *cec_notifier_get_conn(struct device *dev, const char *conn)
3435
{
3536
struct cec_notifier *n;
3637

3738
mutex_lock(&cec_notifiers_lock);
3839
list_for_each_entry(n, &cec_notifiers, head) {
39-
if (n->dev == dev) {
40+
if (n->dev == dev &&
41+
(!conn || !strcmp(n->conn, conn))) {
4042
kref_get(&n->kref);
4143
mutex_unlock(&cec_notifiers_lock);
4244
return n;
@@ -46,6 +48,8 @@ struct cec_notifier *cec_notifier_get(struct device *dev)
4648
if (!n)
4749
goto unlock;
4850
n->dev = dev;
51+
if (conn)
52+
n->conn = kstrdup(conn, GFP_KERNEL);
4953
n->phys_addr = CEC_PHYS_ADDR_INVALID;
5054
mutex_init(&n->lock);
5155
kref_init(&n->kref);
@@ -54,14 +58,15 @@ struct cec_notifier *cec_notifier_get(struct device *dev)
5458
mutex_unlock(&cec_notifiers_lock);
5559
return n;
5660
}
57-
EXPORT_SYMBOL_GPL(cec_notifier_get);
61+
EXPORT_SYMBOL_GPL(cec_notifier_get_conn);
5862

5963
static void cec_notifier_release(struct kref *kref)
6064
{
6165
struct cec_notifier *n =
6266
container_of(kref, struct cec_notifier, kref);
6367

6468
list_del(&n->head);
69+
kfree(n->conn);
6570
kfree(n);
6671
}
6772

include/media/cec-notifier.h

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ struct cec_notifier;
2020
#if IS_REACHABLE(CONFIG_CEC_CORE) && IS_ENABLED(CONFIG_CEC_NOTIFIER)
2121

2222
/**
23-
* cec_notifier_get - find or create a new cec_notifier for the given device.
23+
* cec_notifier_get_conn - find or create a new cec_notifier for the given
24+
* device and connector tuple.
2425
* @dev: device that sends the events.
26+
* @conn: the connector name from which the event occurs
2527
*
2628
* If a notifier for device @dev already exists, then increase the refcount
2729
* and return that notifier.
@@ -31,7 +33,8 @@ struct cec_notifier;
3133
*
3234
* Return NULL if the memory could not be allocated.
3335
*/
34-
struct cec_notifier *cec_notifier_get(struct device *dev);
36+
struct cec_notifier *cec_notifier_get_conn(struct device *dev,
37+
const char *conn);
3538

3639
/**
3740
* 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,
8588
struct cec_notifier *notifier);
8689

8790
#else
88-
static inline struct cec_notifier *cec_notifier_get(struct device *dev)
91+
static inline struct cec_notifier *cec_notifier_get_conn(struct device *dev,
92+
const char *conn)
8993
{
9094
/* A non-NULL pointer is expected on success */
9195
return (struct cec_notifier *)0xdeadfeed;
@@ -120,6 +124,23 @@ static inline void cec_register_cec_notifier(struct cec_adapter *adap,
120124
}
121125
#endif
122126

127+
/**
128+
* cec_notifier_get - find or create a new cec_notifier for the given device.
129+
* @dev: device that sends the events.
130+
*
131+
* If a notifier for device @dev already exists, then increase the refcount
132+
* and return that notifier.
133+
*
134+
* If it doesn't exist, then allocate a new notifier struct and return a
135+
* pointer to that new struct.
136+
*
137+
* Return NULL if the memory could not be allocated.
138+
*/
139+
static inline struct cec_notifier *cec_notifier_get(struct device *dev)
140+
{
141+
return cec_notifier_get_conn(dev, NULL);
142+
}
143+
123144
/**
124145
* cec_notifier_phys_addr_invalidate() - set the physical address to INVALID
125146
*

0 commit comments

Comments
 (0)