Skip to content

Commit 8a105aa

Browse files
committed
Merge branch 'drm-armada-devel' of git://ftp.arm.linux.org.uk/~rmk/linux-arm into drm-next
Merge armada changes, I've confirmed the componenet changes are same as in Greg's tree. * 'drm-armada-devel' of git://ftp.arm.linux.org.uk/~rmk/linux-arm: drm/armada: register crtc with port drm/armada: permit CRTCs to be registered as separate devices dt-bindings: add Marvell Dove LCD controller documentation drm/armada: update Armada 510 (Dove) to use "ext_ref_clk1" as the clock drm/armada: convert to componentized support drm: add of_graph endpoint helper to find possible CRTCs component: fix bug with legacy API drm/armada: make variant a CRTC thing drm/armada: move variant initialisation to CRTC init drm/armada: use number of CRTCs registered drm/armada: move IRQ handling into CRTC component: add support for component match array component: ignore multiple additions of the same component component: fix missed cleanup in case of devres failure
2 parents 7296c84 + 9611cb9 commit 8a105aa

12 files changed

Lines changed: 642 additions & 154 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Device Tree bindings for Armada DRM CRTC driver
2+
3+
Required properties:
4+
- compatible: value should be "marvell,dove-lcd".
5+
- reg: base address and size of the LCD controller
6+
- interrupts: single interrupt number for the LCD controller
7+
- port: video output port with endpoints, as described by graph.txt
8+
9+
Optional properties:
10+
11+
- clocks: as described by clock-bindings.txt
12+
- clock-names: as described by clock-bindings.txt
13+
"axiclk" - axi bus clock for pixel clock
14+
"plldivider" - pll divider clock for pixel clock
15+
"ext_ref_clk0" - external clock 0 for pixel clock
16+
"ext_ref_clk1" - external clock 1 for pixel clock
17+
18+
Note: all clocks are optional but at least one must be specified.
19+
Further clocks may be added in the future according to requirements of
20+
different SoCs.
21+
22+
Example:
23+
24+
lcd0: lcd-controller@820000 {
25+
compatible = "marvell,dove-lcd";
26+
reg = <0x820000 0x1000>;
27+
interrupts = <47>;
28+
clocks = <&si5351 0>;
29+
clock-names = "ext_ref_clk_1";
30+
};

‎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/armada/armada_510.c‎

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,19 @@
1515
#include "armada_drm.h"
1616
#include "armada_hw.h"
1717

18-
static int armada510_init(struct armada_private *priv, struct device *dev)
18+
static int armada510_crtc_init(struct armada_crtc *dcrtc, struct device *dev)
1919
{
20-
priv->extclk[0] = devm_clk_get(dev, "ext_ref_clk_1");
20+
struct clk *clk;
2121

22-
if (IS_ERR(priv->extclk[0]) && PTR_ERR(priv->extclk[0]) == -ENOENT)
23-
priv->extclk[0] = ERR_PTR(-EPROBE_DEFER);
22+
clk = devm_clk_get(dev, "ext_ref_clk1");
23+
if (IS_ERR(clk))
24+
return PTR_ERR(clk) == -ENOENT ? -EPROBE_DEFER : PTR_ERR(clk);
2425

25-
return PTR_RET(priv->extclk[0]);
26-
}
26+
dcrtc->extclk[0] = clk;
2727

28-
static int armada510_crtc_init(struct armada_crtc *dcrtc)
29-
{
3028
/* Lower the watermark so to eliminate jitter at higher bandwidths */
3129
armada_updatel(0x20, (1 << 11) | 0xff, dcrtc->base + LCD_CFG_RDREG4F);
30+
3231
return 0;
3332
}
3433

@@ -45,8 +44,7 @@ static int armada510_crtc_init(struct armada_crtc *dcrtc)
4544
static int armada510_crtc_compute_clock(struct armada_crtc *dcrtc,
4645
const struct drm_display_mode *mode, uint32_t *sclk)
4746
{
48-
struct armada_private *priv = dcrtc->crtc.dev->dev_private;
49-
struct clk *clk = priv->extclk[0];
47+
struct clk *clk = dcrtc->extclk[0];
5048
int ret;
5149

5250
if (dcrtc->num == 1)
@@ -81,7 +79,6 @@ static int armada510_crtc_compute_clock(struct armada_crtc *dcrtc,
8179
const struct armada_variant armada510_ops = {
8280
.has_spu_adv_reg = true,
8381
.spu_adv_reg = ADV_HWC32ENABLE | ADV_HWC32ARGB | ADV_HWC32BLEND,
84-
.init = armada510_init,
85-
.crtc_init = armada510_crtc_init,
86-
.crtc_compute_clock = armada510_crtc_compute_clock,
82+
.init = armada510_crtc_init,
83+
.compute_clock = armada510_crtc_compute_clock,
8784
};

0 commit comments

Comments
 (0)