From patchwork Fri Jan 6 09:15:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 90127 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp9361449qgi; Fri, 6 Jan 2017 01:16:21 -0800 (PST) X-Received: by 10.84.216.91 with SMTP id f27mr5629970plj.92.1483694181090; Fri, 06 Jan 2017 01:16:21 -0800 (PST) Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id b128si78818624pgc.336.2017.01.06.01.16.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Jan 2017 01:16:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7CE2E6E99B; Fri, 6 Jan 2017 09:16:12 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x22f.google.com (mail-wm0-x22f.google.com [IPv6:2a00:1450:400c:c09::22f]) by gabe.freedesktop.org (Postfix) with ESMTPS id 56CE76E99B for ; Fri, 6 Jan 2017 09:16:07 +0000 (UTC) Received: by mail-wm0-x22f.google.com with SMTP id k184so20605465wme.1 for ; Fri, 06 Jan 2017 01:16:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Za4jfVs6Sk4Ef9yR6Y2PeujVgdfn0FbIm+cel1i6wW4=; b=DfCNStkd111UEcTvUi7Ayf+Q6ikX5cx1po7lQqEoxTmJBnNx7cB965rAvgjat3QiNZ cXb2hR16gsiSmzpB6xOyJe5F2WMPAM/fnd5qP+1Q47fx126RAHocc6A5bj9lj5D+giH0 widUzm2OTIpNwPnQBGE5iQF/zWNcKf6X/0DEs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Za4jfVs6Sk4Ef9yR6Y2PeujVgdfn0FbIm+cel1i6wW4=; b=a47EhtgzxcaloWMJuCUBrXvpShaC/ZnRx0N/s/QtcEWEXQa2SxlmWXLQatujnPWD5I Z8cCj0fIoIL4X78juGm05twsK1vSCs6aVqQfXgqC9xCsF2eiJ9efv12LejOiWv2jDzcU /LeFOPDzHi9WUzT1FrGK4J2Qhz5+Yt+G1UziMPoLH//dTwSOwdlQ3bZSs5VrAVkKSkzW Q0OfZ2s8Jn9ACkRO8N7FD1YMEMGKmIigrQEaSx/B+Ip5uvPf/oXA5/c2buxdpuOXTUfF b7xYNQJ+ZWD1Wt53QeK8s48aFavD+JUWnpIoqbEL7s88XXJM25yTdjJSmtrS4MRfjHRf 5c6A== X-Gm-Message-State: AIkVDXKOL3RUuUe8M7/tbc0dJhRTTWpyRVYqZkl0YtVFkeVGZ+Zhqz7XHJwuWedRokc9EkKN X-Received: by 10.28.195.9 with SMTP id t9mr2492771wmf.92.1483694165565; Fri, 06 Jan 2017 01:16:05 -0800 (PST) Received: from lmenx321.st.com. ([80.214.73.144]) by smtp.gmail.com with ESMTPSA id ct7sm107711861wjc.2.2017.01.06.01.16.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 06 Jan 2017 01:16:05 -0800 (PST) From: Benjamin Gaignard To: dri-devel@lists.freedesktop.org, vincent.abriou@st.com Subject: [PATCH v2 2/2] drm: sti: implement CRC capture API Date: Fri, 6 Jan 2017 10:15:04 +0100 Message-Id: <1483694104-25627-2-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1483694104-25627-1-git-send-email-benjamin.gaignard@linaro.org> References: <1483694104-25627-1-git-send-email-benjamin.gaignard@linaro.org> Cc: Daniel Vetter , Tomeu Vizoso X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Use CRC API to retrieve the 3 crc values from hardware. Signed-off-by: Benjamin Gaignard --- This patch should be applied on top of drm-misc branch where Tomeu has change crc.lock. Cc: Tomeu Vizoso Cc: Daniel Vetter --- drivers/gpu/drm/sti/sti_crtc.c | 23 ++++++++++++++++++ drivers/gpu/drm/sti/sti_mixer.c | 52 +++++++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/sti/sti_mixer.h | 4 ++++ 3 files changed, 79 insertions(+) diff --git a/drivers/gpu/drm/sti/sti_crtc.c b/drivers/gpu/drm/sti/sti_crtc.c index e992bed..caf5d61 100644 --- a/drivers/gpu/drm/sti/sti_crtc.c +++ b/drivers/gpu/drm/sti/sti_crtc.c @@ -20,6 +20,8 @@ #include "sti_vid.h" #include "sti_vtg.h" +#define CRC_SAMPLES 3 + static void sti_crtc_enable(struct drm_crtc *crtc) { struct sti_mixer *mixer = to_sti_mixer(crtc); @@ -253,6 +255,7 @@ int sti_crtc_vblank_cb(struct notifier_block *nb, unsigned long flags; struct sti_private *priv; unsigned int pipe; + u32 crcs[CRC_SAMPLES]; priv = crtc->dev->dev_private; pipe = drm_crtc_index(crtc); @@ -275,6 +278,9 @@ int sti_crtc_vblank_cb(struct notifier_block *nb, } spin_unlock_irqrestore(&crtc->dev->event_lock, flags); + if (!sti_mixer_read_crcs(mixer, &crcs[0], &crcs[1], &crcs[2])) + drm_crtc_add_crc_entry(crtc, false, 0, crcs); + if (mixer->status == STI_MIXER_DISABLING) { struct drm_plane *p; @@ -343,6 +349,22 @@ static int sti_crtc_late_register(struct drm_crtc *crtc) return 0; } +int sti_set_crc_source(struct drm_crtc *crtc, const char *source, + size_t *values_cnt) +{ + struct sti_mixer *mixer = to_sti_mixer(crtc); + + *values_cnt = CRC_SAMPLES; + + if (!source) + return sti_mixer_set_crc_status(mixer, false); + + if (source && strcmp(source, "auto") == 0) + return sti_mixer_set_crc_status(mixer, true); + + return -EINVAL; +} + static const struct drm_crtc_funcs sti_crtc_funcs = { .set_config = drm_atomic_helper_set_config, .page_flip = drm_atomic_helper_page_flip, @@ -352,6 +374,7 @@ static int sti_crtc_late_register(struct drm_crtc *crtc) .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, .late_register = sti_crtc_late_register, + .set_crc_source = sti_set_crc_source, }; bool sti_crtc_is_main(struct drm_crtc *crtc) diff --git a/drivers/gpu/drm/sti/sti_mixer.c b/drivers/gpu/drm/sti/sti_mixer.c index 4ddc58f..e245ef7 100644 --- a/drivers/gpu/drm/sti/sti_mixer.c +++ b/drivers/gpu/drm/sti/sti_mixer.c @@ -27,6 +27,13 @@ #define GAM_MIXER_ACT 0x38 #define GAM_MIXER_MBP 0x3C #define GAM_MIXER_MX0 0x80 +#define GAM_MIXER_MISR_CTL 0xA0 +#define GAM_MIXER_MISR_STA 0xA4 +#define GAM_MIXER_SIGN1 0xA8 +#define GAM_MIXER_SIGN2 0xAC +#define GAM_MIXER_SIGN3 0xB0 +#define GAM_MIXER_MISR_AVO 0xB4 +#define GAM_MIXER_MISR_AVS 0xB8 /* id for depth of CRB reg */ #define GAM_DEPTH_VID0_ID 1 @@ -47,6 +54,10 @@ #define GAM_CTL_GDP3_MASK BIT(6) #define GAM_CTL_CURSOR_MASK BIT(9) +#define GAM_MISR_EN (BIT(1) | BIT(2) | BIT(3)) +#define GAM_MISR_RST_STA BIT(0) +#define GAM_MISR_TEST_RSLT_VALID BIT(0) + const char *sti_mixer_to_str(struct sti_mixer *mixer) { switch (mixer->id) { @@ -162,6 +173,13 @@ static int mixer_dbg_show(struct seq_file *s, void *arg) DBGFS_DUMP(GAM_MIXER_MBP); DBGFS_DUMP(GAM_MIXER_MX0); mixer_dbg_mxn(s, mixer->regs + GAM_MIXER_MX0); + DBGFS_DUMP(GAM_MIXER_MISR_CTL); + DBGFS_DUMP(GAM_MIXER_MISR_STA); + DBGFS_DUMP(GAM_MIXER_SIGN1); + DBGFS_DUMP(GAM_MIXER_SIGN2); + DBGFS_DUMP(GAM_MIXER_SIGN3); + DBGFS_DUMP(GAM_MIXER_MISR_AVO); + DBGFS_DUMP(GAM_MIXER_MISR_AVS); seq_puts(s, "\n"); return 0; @@ -202,6 +220,37 @@ int sti_mixer_debugfs_init(struct sti_mixer *mixer, struct drm_minor *minor) minor->debugfs_root, minor); } +int sti_mixer_set_crc_status(struct sti_mixer *mixer, bool enable) +{ + if (enable) { + sti_mixer_reg_read(mixer, GAM_MIXER_MISR_STA); + sti_mixer_reg_read(mixer, GAM_MIXER_SIGN1); + sti_mixer_reg_read(mixer, GAM_MIXER_SIGN2); + sti_mixer_reg_read(mixer, GAM_MIXER_SIGN3); + sti_mixer_reg_write(mixer, GAM_MIXER_MISR_CTL, + GAM_MISR_EN | GAM_MISR_RST_STA); + } else { + sti_mixer_reg_write(mixer, GAM_MIXER_MISR_CTL, 0x00); + } + + return 0; +} + +int sti_mixer_read_crcs(struct sti_mixer *mixer, + u32 *sign1, u32 *sign2, u32 *sign3) +{ + u32 status = sti_mixer_reg_read(mixer, GAM_MIXER_MISR_STA); + + if (!(status & GAM_MISR_TEST_RSLT_VALID)) + return -EAGAIN; + + *sign1 = sti_mixer_reg_read(mixer, GAM_MIXER_SIGN1); + *sign2 = sti_mixer_reg_read(mixer, GAM_MIXER_SIGN2); + *sign3 = sti_mixer_reg_read(mixer, GAM_MIXER_SIGN3); + + return 0; +} + void sti_mixer_set_background_status(struct sti_mixer *mixer, bool enable) { u32 val = sti_mixer_reg_read(mixer, GAM_MIXER_CTL); @@ -301,6 +350,9 @@ int sti_mixer_active_video_area(struct sti_mixer *mixer, sti_mixer_reg_write(mixer, GAM_MIXER_AVO, ydo << 16 | xdo); sti_mixer_reg_write(mixer, GAM_MIXER_AVS, yds << 16 | xds); + sti_mixer_reg_write(mixer, GAM_MIXER_MISR_AVO, ydo << 16 | xdo); + sti_mixer_reg_write(mixer, GAM_MIXER_MISR_AVS, yds << 16 | xds); + sti_mixer_set_background_color(mixer, bkg_color); sti_mixer_set_background_area(mixer, mode); diff --git a/drivers/gpu/drm/sti/sti_mixer.h b/drivers/gpu/drm/sti/sti_mixer.h index 830a3c4..b16feb1 100644 --- a/drivers/gpu/drm/sti/sti_mixer.h +++ b/drivers/gpu/drm/sti/sti_mixer.h @@ -55,6 +55,10 @@ int sti_mixer_active_video_area(struct sti_mixer *mixer, void sti_mixer_set_background_status(struct sti_mixer *mixer, bool enable); +int sti_mixer_set_crc_status(struct sti_mixer *mixer, bool enable); +int sti_mixer_read_crcs(struct sti_mixer *mixer, + u32 *sign1, u32 *sign2, u32 *sign3); + int sti_mixer_debugfs_init(struct sti_mixer *mixer, struct drm_minor *minor); /* depth in Cross-bar control = z order */