From patchwork Tue Dec 18 15:37:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lubomir Rintel X-Patchwork-Id: 10736883 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 50A541399 for ; Wed, 19 Dec 2018 08:41:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 42E742AE76 for ; Wed, 19 Dec 2018 08:41:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 417CA2AEAF; Wed, 19 Dec 2018 08:41:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BA6252AE90 for ; Wed, 19 Dec 2018 08:41:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 213856EE36; Wed, 19 Dec 2018 08:40:59 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from shell.v3.sk (shell.v3.sk [90.176.6.54]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6B3916EC46 for ; Tue, 18 Dec 2018 15:38:27 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id 2F301CA1C7; Tue, 18 Dec 2018 16:38:26 +0100 (CET) Received: from shell.v3.sk ([127.0.0.1]) by localhost (zimbra.v3.sk [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id ZmZOKPGbuzQF; Tue, 18 Dec 2018 16:38:10 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id AD0E5CA2D4; Tue, 18 Dec 2018 16:37:53 +0100 (CET) X-Virus-Scanned: amavisd-new at zimbra.v3.sk Received: from shell.v3.sk ([127.0.0.1]) by localhost (zimbra.v3.sk [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id mCOlqcZOPCQM; Tue, 18 Dec 2018 16:37:51 +0100 (CET) Received: from belphegor.brq.redhat.com (nat-pool-brq-t.redhat.com [213.175.37.10]) by zimbra.v3.sk (Postfix) with ESMTPSA id F02A6CA2E2; Tue, 18 Dec 2018 16:37:47 +0100 (CET) From: Lubomir Rintel To: dri-devel@lists.freedesktop.org Subject: [RFC 15/16] drm/armada: add mmp2 support Date: Tue, 18 Dec 2018 16:37:41 +0100 Message-Id: <20181218153742.1313125-16-lkundrak@v3.sk> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181218153742.1313125-1-lkundrak@v3.sk> References: <20181218153742.1313125-1-lkundrak@v3.sk> MIME-Version: 1.0 X-Mailman-Approved-At: Wed, 19 Dec 2018 08:40:40 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lubomir Rintel , Russell King , James Cameron Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This pretty much boils down to setting the LCD_CFG_SCLK_DIV register, and is tailored to the OLPC XO-1.75. I have no idea what are the meanings of most bits there, so I'm just making sure it ends up being 0x40001102. This means that the selection of the source clock is hardwired. Apparently the bit 30 selects the AXI bus clock as base clock for the pixel clock. It is not known to me what other options are there. Signed-off-by: Lubomir Rintel --- Notes; perhaps James or someone else with a datasheet could help me with this. I'm somewhat confused about the clock selection. The firmware contains this line: h# 00000700 value pmua-disp-clk-sel \ PLL1 / 7 -> 113.86 MHz However, the Linux clock driver seems to consider the value of 7 to configure the divisor to 8, so the resulting clock would end up being 100 MHz. Also, the clk-of-mmp2 driver suggests PLL1 outputs 800 MHz, dividing that by 7 would end up being 114.29 MHz, not 113.86 MHz. If the same logic was used here as Armada 510 driver uses, we'll end up with the divisor of 1 in LCD_CFG_SCLK_DIV and disp0_div divisor of 16. Would that be good also? (Do perhaps any of the bits in LCD_CFG_SCLK_DIV allow for a fractional divisor, allowing us to get the clock we need more precisely?) The pxa168fb driver as used on the stock OLPC software just avoids touching the register, preserving the value set from the firmware. --- drivers/gpu/drm/armada/Makefile | 1 + drivers/gpu/drm/armada/armada_610.c | 50 ++++++++++++++++++++++++++++ drivers/gpu/drm/armada/armada_crtc.c | 4 +++ drivers/gpu/drm/armada/armada_drm.h | 1 + drivers/gpu/drm/armada/armada_drv.c | 1 + drivers/gpu/drm/armada/armada_rmem.c | 4 ++- 6 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/armada/armada_610.c diff --git a/drivers/gpu/drm/armada/Makefile b/drivers/gpu/drm/armada/Makefile index d34843e121c7..ac299fe35173 100644 --- a/drivers/gpu/drm/armada/Makefile +++ b/drivers/gpu/drm/armada/Makefile @@ -2,6 +2,7 @@ armada-y := armada_crtc.o armada_drv.o armada_fb.o armada_fbdev.o \ armada_gem.o armada_overlay.o armada_plane.o armada_trace.o armada-y += armada_510.o +armada-y += armada_610.o armada-$(CONFIG_DEBUG_FS) += armada_debugfs.o obj-$(CONFIG_DRM_ARMADA) := armada.o diff --git a/drivers/gpu/drm/armada/armada_610.c b/drivers/gpu/drm/armada/armada_610.c new file mode 100644 index 000000000000..e86b9fed9d2f --- /dev/null +++ b/drivers/gpu/drm/armada/armada_610.c @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2012 Russell King + * Copyright (C) 2018 Lubomir Rintel + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * Armada MMP2 variant support + */ +#include +#include +#include +#include "armada_crtc.h" +#include "armada_drm.h" + +/* + * This gets called with sclk = NULL to test whether the mode is + * supportable, and again with sclk != NULL to set the clocks up for + * that. The former can return an error, but the latter is expected + * not to. + */ +static int armada610_crtc_compute_clock(struct armada_crtc *dcrtc, + const struct drm_display_mode *mode, uint32_t *sclk) +{ + struct clk *clk = dcrtc->axiclk; + uint32_t rate, ref, div; + + if (!clk) + return -EINVAL; + + rate = mode->clock * 1000; + ref = clk_get_rate(clk); + div = DIV_ROUND_UP(ref, rate); + + if (div < 2) + return -EINVAL; + + if (sclk) { + *sclk = 0x00001100; /* No idea */ + *sclk |= (0x1 << 30); /* SCLK_SOURCE_SELECT = AXI bus clk */ + *sclk |= div; + } + + return 0; +} + +const struct armada_variant armada610_ops = { + .compute_clock = armada610_crtc_compute_clock, +}; diff --git a/drivers/gpu/drm/armada/armada_crtc.c b/drivers/gpu/drm/armada/armada_crtc.c index 973c377975a1..9d450669faea 100644 --- a/drivers/gpu/drm/armada/armada_crtc.c +++ b/drivers/gpu/drm/armada/armada_crtc.c @@ -915,6 +915,10 @@ static const struct of_device_id armada_lcd_of_match[] = { .compatible = "marvell,dove-lcd", .data = &armada510_ops, }, + { + .compatible = "marvell,mmp2-lcd", + .data = &armada610_ops, + }, {} }; MODULE_DEVICE_TABLE(of, armada_lcd_of_match); diff --git a/drivers/gpu/drm/armada/armada_drm.h b/drivers/gpu/drm/armada/armada_drm.h index f09083ff15d3..7cbcf33d0304 100644 --- a/drivers/gpu/drm/armada/armada_drm.h +++ b/drivers/gpu/drm/armada/armada_drm.h @@ -52,6 +52,7 @@ struct armada_variant { /* Variant ops */ extern const struct armada_variant armada510_ops; +extern const struct armada_variant armada610_ops; struct armada_private { struct drm_device drm; diff --git a/drivers/gpu/drm/armada/armada_drv.c b/drivers/gpu/drm/armada/armada_drv.c index deef34153c56..fed590e0916f 100644 --- a/drivers/gpu/drm/armada/armada_drv.c +++ b/drivers/gpu/drm/armada/armada_drv.c @@ -302,6 +302,7 @@ MODULE_DEVICE_TABLE(platform, armada_drm_platform_ids); static const struct of_device_id armada_drm_dt_ids[] = { { .compatible = "marvell,dove-display-subsystem", }, + { .compatible = "marvell,mmp2-display-subsystem", }, { /* sentinel */ }, }; MODULE_DEVICE_TABLE(of, armada_drm_dt_ids); diff --git a/drivers/gpu/drm/armada/armada_rmem.c b/drivers/gpu/drm/armada/armada_rmem.c index 36bb20e426b6..45f8b2eff822 100644 --- a/drivers/gpu/drm/armada/armada_rmem.c +++ b/drivers/gpu/drm/armada/armada_rmem.c @@ -45,5 +45,7 @@ static int __init armada_rmem_init(struct reserved_mem *rmem) return 0; } -RESERVEDMEM_OF_DECLARE(armada_rmem, "marvell,dove-framebuffer", +RESERVEDMEM_OF_DECLARE(armada_dove_rmem, "marvell,dove-framebuffer", + armada_rmem_init); +RESERVEDMEM_OF_DECLARE(armada_mmp2_rmem, "marvell,mmp2-framebuffer", armada_rmem_init);