Skip to content

Commit 2f2d270

Browse files
author
Russell King
committed
Merge branches 'drm-devel' and 'component-for-driver' into armada-drm
3 parents 42e62ba + 7e435aa + b509cc8 commit 2f2d270

6 files changed

Lines changed: 252 additions & 35 deletions

File tree

‎drivers/base/component.c‎

Lines changed: 157 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,23 @@
1818
#include <linux/mutex.h>
1919
#include <linux/slab.h>
2020

21+
struct component_match {
22+
size_t alloc;
23+
size_t num;
24+
struct {
25+
void *data;
26+
int (*fn)(struct device *, void *);
27+
} compare[0];
28+
};
29+
2130
struct master {
2231
struct list_head node;
2332
struct list_head components;
2433
bool bound;
2534

2635
const struct component_master_ops *ops;
2736
struct device *dev;
37+
struct component_match *match;
2838
};
2939

3040
struct component {
@@ -69,18 +79,24 @@ static void component_detach_master(struct master *master, struct component *c)
6979
c->master = NULL;
7080
}
7181

82+
/*
83+
* Add a component to a master, finding the component via the compare
84+
* function and compare data. This is safe to call for duplicate matches
85+
* and will not result in the same component being added multiple times.
86+
*/
7287
int component_master_add_child(struct master *master,
7388
int (*compare)(struct device *, void *), void *compare_data)
7489
{
7590
struct component *c;
7691
int ret = -ENXIO;
7792

7893
list_for_each_entry(c, &component_list, node) {
79-
if (c->master)
94+
if (c->master && c->master != master)
8095
continue;
8196

8297
if (compare(c->dev, compare_data)) {
83-
component_attach_master(master, c);
98+
if (!c->master)
99+
component_attach_master(master, c);
84100
ret = 0;
85101
break;
86102
}
@@ -90,6 +106,34 @@ int component_master_add_child(struct master *master,
90106
}
91107
EXPORT_SYMBOL_GPL(component_master_add_child);
92108

109+
static int find_components(struct master *master)
110+
{
111+
struct component_match *match = master->match;
112+
size_t i;
113+
int ret = 0;
114+
115+
if (!match) {
116+
/*
117+
* Search the list of components, looking for components that
118+
* belong to this master, and attach them to the master.
119+
*/
120+
return master->ops->add_components(master->dev, master);
121+
}
122+
123+
/*
124+
* Scan the array of match functions and attach
125+
* any components which are found to this master.
126+
*/
127+
for (i = 0; i < match->num; i++) {
128+
ret = component_master_add_child(master,
129+
match->compare[i].fn,
130+
match->compare[i].data);
131+
if (ret)
132+
break;
133+
}
134+
return ret;
135+
}
136+
93137
/* Detach all attached components from this master */
94138
static void master_remove_components(struct master *master)
95139
{
@@ -113,44 +157,44 @@ static void master_remove_components(struct master *master)
113157
static int try_to_bring_up_master(struct master *master,
114158
struct component *component)
115159
{
116-
int ret = 0;
160+
int ret;
117161

118-
if (!master->bound) {
119-
/*
120-
* Search the list of components, looking for components that
121-
* belong to this master, and attach them to the master.
122-
*/
123-
if (master->ops->add_components(master->dev, master)) {
124-
/* Failed to find all components */
125-
master_remove_components(master);
126-
ret = 0;
127-
goto out;
128-
}
162+
if (master->bound)
163+
return 0;
129164

130-
if (component && component->master != master) {
131-
master_remove_components(master);
132-
ret = 0;
133-
goto out;
134-
}
165+
/*
166+
* Search the list of components, looking for components that
167+
* belong to this master, and attach them to the master.
168+
*/
169+
if (find_components(master)) {
170+
/* Failed to find all components */
171+
ret = 0;
172+
goto out;
173+
}
135174

136-
if (!devres_open_group(master->dev, NULL, GFP_KERNEL)) {
137-
ret = -ENOMEM;
138-
goto out;
139-
}
175+
if (component && component->master != master) {
176+
ret = 0;
177+
goto out;
178+
}
140179

141-
/* Found all components */
142-
ret = master->ops->bind(master->dev);
143-
if (ret < 0) {
144-
devres_release_group(master->dev, NULL);
145-
dev_info(master->dev, "master bind failed: %d\n", ret);
146-
master_remove_components(master);
147-
goto out;
148-
}
180+
if (!devres_open_group(master->dev, NULL, GFP_KERNEL)) {
181+
ret = -ENOMEM;
182+
goto out;
183+
}
149184

150-
master->bound = true;
151-
ret = 1;
185+
/* Found all components */
186+
ret = master->ops->bind(master->dev);
187+
if (ret < 0) {
188+
devres_release_group(master->dev, NULL);
189+
dev_info(master->dev, "master bind failed: %d\n", ret);
190+
goto out;
152191
}
192+
193+
master->bound = true;
194+
return 1;
195+
153196
out:
197+
master_remove_components(master);
154198

155199
return ret;
156200
}
@@ -180,18 +224,89 @@ static void take_down_master(struct master *master)
180224
master_remove_components(master);
181225
}
182226

183-
int component_master_add(struct device *dev,
184-
const struct component_master_ops *ops)
227+
static size_t component_match_size(size_t num)
228+
{
229+
return offsetof(struct component_match, compare[num]);
230+
}
231+
232+
static struct component_match *component_match_realloc(struct device *dev,
233+
struct component_match *match, size_t num)
234+
{
235+
struct component_match *new;
236+
237+
if (match && match->alloc == num)
238+
return match;
239+
240+
new = devm_kmalloc(dev, component_match_size(num), GFP_KERNEL);
241+
if (!new)
242+
return ERR_PTR(-ENOMEM);
243+
244+
if (match) {
245+
memcpy(new, match, component_match_size(min(match->num, num)));
246+
devm_kfree(dev, match);
247+
} else {
248+
new->num = 0;
249+
}
250+
251+
new->alloc = num;
252+
253+
return new;
254+
}
255+
256+
/*
257+
* Add a component to be matched.
258+
*
259+
* The match array is first created or extended if necessary.
260+
*/
261+
void component_match_add(struct device *dev, struct component_match **matchptr,
262+
int (*compare)(struct device *, void *), void *compare_data)
263+
{
264+
struct component_match *match = *matchptr;
265+
266+
if (IS_ERR(match))
267+
return;
268+
269+
if (!match || match->num == match->alloc) {
270+
size_t new_size = match ? match->alloc + 16 : 15;
271+
272+
match = component_match_realloc(dev, match, new_size);
273+
274+
*matchptr = match;
275+
276+
if (IS_ERR(match))
277+
return;
278+
}
279+
280+
match->compare[match->num].fn = compare;
281+
match->compare[match->num].data = compare_data;
282+
match->num++;
283+
}
284+
EXPORT_SYMBOL(component_match_add);
285+
286+
int component_master_add_with_match(struct device *dev,
287+
const struct component_master_ops *ops,
288+
struct component_match *match)
185289
{
186290
struct master *master;
187291
int ret;
188292

293+
if (ops->add_components && match)
294+
return -EINVAL;
295+
296+
if (match) {
297+
/* Reallocate the match array for its true size */
298+
match = component_match_realloc(dev, match, match->num);
299+
if (IS_ERR(match))
300+
return PTR_ERR(match);
301+
}
302+
189303
master = kzalloc(sizeof(*master), GFP_KERNEL);
190304
if (!master)
191305
return -ENOMEM;
192306

193307
master->dev = dev;
194308
master->ops = ops;
309+
master->match = match;
195310
INIT_LIST_HEAD(&master->components);
196311

197312
/* Add to the list of available masters. */
@@ -209,6 +324,13 @@ int component_master_add(struct device *dev,
209324

210325
return ret < 0 ? ret : 0;
211326
}
327+
EXPORT_SYMBOL_GPL(component_master_add_with_match);
328+
329+
int component_master_add(struct device *dev,
330+
const struct component_master_ops *ops)
331+
{
332+
return component_master_add_with_match(dev, ops, NULL);
333+
}
212334
EXPORT_SYMBOL_GPL(component_master_add);
213335

214336
void component_master_del(struct device *dev,

‎drivers/gpu/drm/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ drm-$(CONFIG_COMPAT) += drm_ioc32.o
2020
drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o
2121
drm-$(CONFIG_PCI) += ati_pcigart.o
2222
drm-$(CONFIG_DRM_PANEL) += drm_panel.o
23+
drm-$(CONFIG_OF) += drm_of.o
2324

2425
drm-usb-y := drm_usb.o
2526

‎drivers/gpu/drm/drm_of.c‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include <linux/export.h>
2+
#include <linux/list.h>
3+
#include <linux/of_graph.h>
4+
#include <drm/drmP.h>
5+
#include <drm/drm_crtc.h>
6+
#include <drm/drm_of.h>
7+
8+
/**
9+
* drm_crtc_port_mask - find the mask of a registered CRTC by port OF node
10+
* @dev: DRM device
11+
* @port: port OF node
12+
*
13+
* Given a port OF node, return the possible mask of the corresponding
14+
* CRTC within a device's list of CRTCs. Returns zero if not found.
15+
*/
16+
static uint32_t drm_crtc_port_mask(struct drm_device *dev,
17+
struct device_node *port)
18+
{
19+
unsigned int index = 0;
20+
struct drm_crtc *tmp;
21+
22+
list_for_each_entry(tmp, &dev->mode_config.crtc_list, head) {
23+
if (tmp->port == port)
24+
return 1 << index;
25+
26+
index++;
27+
}
28+
29+
return 0;
30+
}
31+
32+
/**
33+
* drm_of_find_possible_crtcs - find the possible CRTCs for an encoder port
34+
* @dev: DRM device
35+
* @port: encoder port to scan for endpoints
36+
*
37+
* Scan all endpoints attached to a port, locate their attached CRTCs,
38+
* and generate the DRM mask of CRTCs which may be attached to this
39+
* encoder.
40+
*
41+
* See Documentation/devicetree/bindings/graph.txt for the bindings.
42+
*/
43+
uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
44+
struct device_node *port)
45+
{
46+
struct device_node *remote_port, *ep = NULL;
47+
uint32_t possible_crtcs = 0;
48+
49+
do {
50+
ep = of_graph_get_next_endpoint(port, ep);
51+
if (!ep)
52+
break;
53+
54+
remote_port = of_graph_get_remote_port(ep);
55+
if (!remote_port) {
56+
of_node_put(ep);
57+
return 0;
58+
}
59+
60+
possible_crtcs |= drm_crtc_port_mask(dev, remote_port);
61+
62+
of_node_put(remote_port);
63+
} while (1);
64+
65+
return possible_crtcs;
66+
}
67+
EXPORT_SYMBOL(drm_of_find_possible_crtcs);

‎include/drm/drm_crtc.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct drm_framebuffer;
4141
struct drm_object_properties;
4242
struct drm_file;
4343
struct drm_clip_rect;
44+
struct device_node;
4445

4546
#define DRM_MODE_OBJECT_CRTC 0xcccccccc
4647
#define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0
@@ -314,6 +315,7 @@ struct drm_crtc_funcs {
314315
*/
315316
struct drm_crtc {
316317
struct drm_device *dev;
318+
struct device_node *port;
317319
struct list_head head;
318320

319321
/**

‎include/drm/drm_of.h‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef __DRM_OF_H__
2+
#define __DRM_OF_H__
3+
4+
struct drm_device;
5+
struct device_node;
6+
7+
#ifdef CONFIG_OF
8+
extern uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
9+
struct device_node *port);
10+
#else
11+
static inline uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
12+
struct device_node *port)
13+
{
14+
return 0;
15+
}
16+
#endif
17+
18+
#endif /* __DRM_OF_H__ */

‎include/linux/component.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,11 @@ void component_master_del(struct device *,
2929
int component_master_add_child(struct master *master,
3030
int (*compare)(struct device *, void *), void *compare_data);
3131

32+
struct component_match;
33+
34+
int component_master_add_with_match(struct device *,
35+
const struct component_master_ops *, struct component_match *);
36+
void component_match_add(struct device *, struct component_match **,
37+
int (*compare)(struct device *, void *), void *compare_data);
38+
3239
#endif

0 commit comments

Comments
 (0)