Skip to content

Commit 043e429

Browse files
jannaumarcan
authored andcommitted
gpu: drm: apple: Wait for iomfb initialization
Avoids "[drm] Cannot find any crtc or sizes" during fbdev initialization if a display is connected. Signed-off-by: Janne Grunau <j@jannau.net>
1 parent d49abbd commit 043e429

File tree

5 files changed

+51
-3
lines changed

5 files changed

+51
-3
lines changed

drivers/gpu/drm/apple/apple_drv.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <linux/component.h>
1111
#include <linux/dma-mapping.h>
12+
#include <linux/jiffies.h>
1213
#include <linux/module.h>
1314
#include <linux/of_address.h>
1415
#include <linux/of_device.h>
@@ -401,7 +402,8 @@ static int apple_drm_init_dcp(struct device *dev)
401402
struct apple_drm_private *apple = dev_get_drvdata(dev);
402403
struct platform_device *dcp[MAX_COPROCESSORS];
403404
struct device_node *np;
404-
int ret, num_dcp = 0;
405+
u64 timeout;
406+
int i, ret, num_dcp = 0;
405407

406408
for_each_matching_node(np, apple_dcp_id_tbl) {
407409
if (!of_device_is_available(np)) {
@@ -429,6 +431,21 @@ static int apple_drm_init_dcp(struct device *dev)
429431
if (num_dcp < 1)
430432
return -ENODEV;
431433

434+
timeout = get_jiffies_64() + msecs_to_jiffies(500);
435+
436+
for (i = 0; i < num_dcp; ++i) {
437+
u64 jiffies = get_jiffies_64();
438+
u64 wait = time_after_eq64(jiffies, timeout) ?
439+
0 :
440+
timeout - jiffies;
441+
ret = dcp_wait_ready(dcp[i], wait);
442+
/* There is nothing we can do if a dcp/dcpext does not boot
443+
* (successfully). Ignoring it should not do any harm now.
444+
* Needs to reevaluated whenn adding dcpext support.
445+
*/
446+
if (ret)
447+
dev_warn(dev, "DCP[%d] not ready: %d\n", i, ret);
448+
}
432449

433450
return 0;
434451
}

drivers/gpu/drm/apple/dcp-internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ struct apple_dcp {
134134
bool valid_mode;
135135
struct dcp_set_digital_out_mode_req mode;
136136

137+
/* completion for active turning true */
138+
struct completion start_done;
139+
137140
/* Is the DCP booted? */
138141
bool active;
139142

drivers/gpu/drm/apple/dcp.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ static void dcp_rtk_crashed(void *cookie)
117117
dcp->connector->connected = 0;
118118
schedule_work(&dcp->connector->hotplug_wq);
119119
}
120+
complete(&dcp->start_done);
120121
}
121122

122123
static int dcp_rtk_shmem_setup(void *cookie, struct apple_rtkit_shmem *bfr)
@@ -248,6 +249,8 @@ int dcp_start(struct platform_device *pdev)
248249
struct apple_dcp *dcp = platform_get_drvdata(pdev);
249250
int ret;
250251

252+
init_completion(&dcp->start_done);
253+
251254
/* start RTKit endpoints */
252255
ret = iomfb_start_rtkit(dcp);
253256
if (ret)
@@ -257,6 +260,29 @@ int dcp_start(struct platform_device *pdev)
257260
}
258261
EXPORT_SYMBOL(dcp_start);
259262

263+
int dcp_wait_ready(struct platform_device *pdev, u64 timeout)
264+
{
265+
struct apple_dcp *dcp = platform_get_drvdata(pdev);
266+
int ret;
267+
268+
if (dcp->crashed)
269+
return -ENODEV;
270+
if (dcp->active)
271+
return 0;
272+
if (timeout <= 0)
273+
return -ETIMEDOUT;
274+
275+
ret = wait_for_completion_timeout(&dcp->start_done, timeout);
276+
if (ret < 0)
277+
return ret;
278+
279+
if (dcp->crashed)
280+
return -ENODEV;
281+
282+
return dcp->active ? 0 : -ETIMEDOUT;
283+
}
284+
EXPORT_SYMBOL(dcp_wait_ready);
285+
260286
static void dcp_work_register_backlight(struct work_struct *work)
261287
{
262288
int ret;

drivers/gpu/drm/apple/dcp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ int dcp_get_connector_type(struct platform_device *pdev);
4949
void dcp_link(struct platform_device *pdev, struct apple_crtc *apple,
5050
struct apple_connector *connector);
5151
int dcp_start(struct platform_device *pdev);
52+
int dcp_wait_ready(struct platform_device *pdev, u64 timeout);
5253
void dcp_flush(struct drm_crtc *crtc, struct drm_atomic_state *state);
5354
bool dcp_is_initialized(struct platform_device *pdev);
5455
void apple_crtc_vblank(struct apple_crtc *apple);

drivers/gpu/drm/apple/iomfb.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,13 +1810,14 @@ static void res_is_main_display(struct apple_dcp *dcp, void *out, void *cookie)
18101810

18111811
dcp->main_display = result != 0;
18121812

1813-
dcp->active = true;
1814-
18151813
connector = dcp->connector;
18161814
if (connector) {
18171815
connector->connected = dcp->nr_modes > 0;
18181816
schedule_work(&connector->hotplug_wq);
18191817
}
1818+
1819+
dcp->active = true;
1820+
complete(&dcp->start_done);
18201821
}
18211822

18221823
static void init_3(struct apple_dcp *dcp, void *out, void *cookie)

0 commit comments

Comments
 (0)