Skip to content

Commit db70ebd

Browse files
committed
drm: apple: Add CRTC CRC support
The DCP firmware has CRC support. While this is not yet reverse engineering report always 0 to at least be able to run tests from igt-gpu-tools with "--skip-crc-compare". Signed-off-by: Janne Grunau <j@jannau.net>
1 parent c6a3f63 commit db70ebd

5 files changed

Lines changed: 76 additions & 0 deletions

File tree

drivers/gpu/drm/apple/apple_drv.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,70 @@ static void apple_crtc_cleanup(struct drm_crtc *crtc)
260260
kfree(to_apple_crtc(crtc));
261261
}
262262

263+
static int apple_crtc_parse_crc_source(const char *source, bool *enabled)
264+
{
265+
int ret = 0;
266+
267+
if (!source) {
268+
*enabled = false;
269+
} else if (strcmp(source, "auto") == 0) {
270+
*enabled = true;
271+
} else {
272+
*enabled = false;
273+
ret = -EINVAL;
274+
}
275+
276+
return ret;
277+
}
278+
279+
static int apple_crtc_set_crc_source(struct drm_crtc *crtc, const char *source)
280+
{
281+
bool enabled = false;
282+
283+
int ret = apple_crtc_parse_crc_source(source, &enabled);
284+
285+
if (!ret)
286+
dcp_set_crc(crtc, enabled);
287+
288+
return ret;
289+
}
290+
291+
static int apple_crtc_verify_crc_source(struct drm_crtc *crtc,
292+
const char *source,
293+
size_t *values_cnt)
294+
{
295+
bool enabled;
296+
297+
if (apple_crtc_parse_crc_source(source, &enabled) < 0) {
298+
pr_warn("dcp: Invalid CRC source name %s\n", source);
299+
return -EINVAL;
300+
}
301+
302+
*values_cnt = 1;
303+
304+
return 0;
305+
}
306+
307+
static const char * const apple_crtc_crc_sources[] = {"auto"};
308+
309+
static const char *const * apple_crtc_get_crc_sources(struct drm_crtc *crtc,
310+
size_t *count)
311+
{
312+
*count = ARRAY_SIZE(apple_crtc_crc_sources);
313+
return apple_crtc_crc_sources;
314+
}
315+
263316
static const struct drm_crtc_funcs apple_crtc_funcs = {
264317
.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
265318
.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
266319
.destroy = apple_crtc_cleanup,
267320
.page_flip = drm_atomic_helper_page_flip,
268321
.reset = drm_atomic_helper_crtc_reset,
269322
.set_config = drm_atomic_helper_set_config,
323+
.set_crc_source = apple_crtc_set_crc_source,
324+
.verify_crc_source = apple_crtc_verify_crc_source,
325+
.get_crc_sources = apple_crtc_get_crc_sources,
326+
270327
};
271328

272329
static const struct drm_mode_config_funcs apple_mode_config_funcs = {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ struct apple_dcp {
198198
/* clear all surfaces on init */
199199
bool surfaces_cleared;
200200

201+
/* enable CRC calculation */
202+
bool crc_enabled;
203+
201204
/* Modes valid for the connected display */
202205
struct dcp_display_mode *modes;
203206
unsigned int nr_modes;

drivers/gpu/drm/apple/dcp.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,17 @@ bool dcp_has_panel(struct apple_dcp *dcp)
191191
return dcp->panel.width_mm > 0;
192192
}
193193

194+
int dcp_set_crc(struct drm_crtc *crtc, bool enabled)
195+
{
196+
struct apple_crtc *ac = to_apple_crtc(crtc);
197+
struct apple_dcp *dcp = platform_get_drvdata(ac->dcp);
198+
199+
dcp->crc_enabled = enabled;
200+
201+
return 0;
202+
}
203+
EXPORT_SYMBOL_GPL(dcp_set_crc);
204+
194205
/*
195206
* Helper to send a DRM vblank event. We do not know how call swap_submit_dcp
196207
* without surfaces. To avoid timeouts in drm_atomic_helper_wait_for_vblanks

drivers/gpu/drm/apple/dcp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct apple_encoder {
3131

3232
void dcp_poweroff(struct platform_device *pdev);
3333
void dcp_poweron(struct platform_device *pdev);
34+
int dcp_set_crc(struct drm_crtc *crtc, bool enabled);
3435
int dcp_crtc_atomic_check(struct drm_crtc *crtc, struct drm_atomic_state *state);
3536
int dcp_get_connector_type(struct platform_device *pdev);
3637
void dcp_link(struct platform_device *pdev, struct apple_crtc *apple,

drivers/gpu/drm/apple/iomfb_template.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ static void dcpep_cb_swap_complete(struct apple_dcp *dcp,
125125
dcp->last_swap_id = resp->swap_id;
126126

127127
dcp_drm_crtc_page_flip(dcp, now);
128+
if (dcp->crc_enabled) {
129+
u32 crc32 = 0;
130+
drm_crtc_add_crc_entry(&dcp->crtc->base, true, resp->swap_id, &crc32);
131+
}
128132
}
129133

130134
/* special */

0 commit comments

Comments
 (0)