From patchwork Wed Jan 9 14:13:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Chiras X-Patchwork-Id: 10755373 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 7807F13B5 for ; Thu, 10 Jan 2019 08:35:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 633B9290E1 for ; Thu, 10 Jan 2019 08:35:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 578CE29202; Thu, 10 Jan 2019 08:35:14 +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 BA0C2291D7 for ; Thu, 10 Jan 2019 08:35:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A59CF6F1F7; Thu, 10 Jan 2019 08:34:57 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70071.outbound.protection.outlook.com [40.107.7.71]) by gabe.freedesktop.org (Postfix) with ESMTPS id 601EA6F18D for ; Wed, 9 Jan 2019 14:13:48 +0000 (UTC) Received: from AM6PR04MB4007.eurprd04.prod.outlook.com (52.135.161.10) by AM6PR04MB5157.eurprd04.prod.outlook.com (20.177.34.161) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1495.9; Wed, 9 Jan 2019 14:13:46 +0000 Received: from AM6PR04MB4007.eurprd04.prod.outlook.com ([fe80::65e5:2a3b:b9a8:3cd9]) by AM6PR04MB4007.eurprd04.prod.outlook.com ([fe80::65e5:2a3b:b9a8:3cd9%5]) with mapi id 15.20.1516.010; Wed, 9 Jan 2019 14:13:46 +0000 From: Robert Chiras To: Daniel Vetter , Philipp Zabel , Marek Vasut Subject: [PATCH 06/10] drm/mxsfb: Add support for new pixel formats in eLCDIF Thread-Topic: [PATCH 06/10] drm/mxsfb: Add support for new pixel formats in eLCDIF Thread-Index: AQHUqCWIpokjXRlY4kiQhbXvgCRsqA== Date: Wed, 9 Jan 2019 14:13:46 +0000 Message-ID: <1547043209-8283-7-git-send-email-robert.chiras@nxp.com> References: <1547043209-8283-1-git-send-email-robert.chiras@nxp.com> In-Reply-To: <1547043209-8283-1-git-send-email-robert.chiras@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM6P193CA0015.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:3e::28) To AM6PR04MB4007.eurprd04.prod.outlook.com (2603:10a6:209:40::10) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.7.4 x-originating-ip: [95.76.156.53] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM6PR04MB5157; 6:4J6mm9DtVbJt0jfQkJ0mtgQ8p1Fm29YXbLlj3a4kVomLXmylV3F9ysoHz9wrX12T5/IqGnNxTF6kGddMbNZs2PrM2SO+Wq5Q5ZvkGzntXxPTc0vR3dXTyoTR4JP6piRaGuEQU2duyAxKbjKlGWGwpUf1SjpzrSXR8s6xmo6hSOMZ5qAkscwPZhjDDxXwiRUFmHLfWbBBsT1EZJEZJ0tLrlSHd6cOykEN6y/8u07eWftsWAQwzAOq+2ACgkaKvJHSjWbRbHwIkvJiX8aGYdjUfJwQvHfX5uwt39wJockt5XS2lTBNlpNMj1kIzBE0CF0MKfJoAT5wXQJsqqsKGecW3mIpWbLjw0L+B1fdC0ejAK3p2YmftXWM+FhKOdkHBaMtNEMAQLimWh64MGhBQtMkW04sm+JmGarFGYzB/8GEQVg4bqTRA5QtBJHjH0D2nZCKRUfqvgTy5fd6Hd9Rmk2YVQ==; 5:AoiZNGV8uYr9UazYG1diPutYYy2iwJKEa354jIyczv9QW5ZFgWmUOslh2WiVpDOtMx2J3tOQG5bin6sEtkzkFzAkSBiUWrvJDeRGJpf7uuzo5F93Q8sNXAoDWxLSHWOHNOrMSkuj81W2Mws6t9YLd219RxrsERuZSCNsvTQzU9/2oHx69kYbwy4O9306q0wnim3yZ8ejtxWrY/MP7utOFg==; 7:BHMmWhExGudH/Y5+ZJPWl3QFWXCJaVzDNpEOW7cjEJ+hvILhzKioOURAPp/3ub8gQWTg8gphGv56b8Z2ju0GgMjgHwghXuViVHYpRSfeyjsPzP1kl/HzyjEJc4tQCy1I6UWchuGu8E0Vjj9lq51FGA== x-ms-office365-filtering-correlation-id: 58631782-5d47-43c7-77b1-08d6763cab1e x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600109)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:AM6PR04MB5157; x-ms-traffictypediagnostic: AM6PR04MB5157: x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(3230021)(908002)(999002)(5005026)(6040522)(8220060)(2401047)(8121501046)(3231475)(944501520)(52105112)(3002001)(93006095)(93001095)(10201501046)(6055026)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123564045)(20161123558120)(20161123560045)(201708071742011)(7699051)(76991095); SRVR:AM6PR04MB5157; BCL:0; PCL:0; RULEID:; SRVR:AM6PR04MB5157; x-forefront-prvs: 0912297777 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(396003)(39860400002)(346002)(366004)(136003)(376002)(199004)(189003)(50226002)(99286004)(11346002)(110136005)(2616005)(256004)(316002)(86362001)(14444005)(54906003)(305945005)(7736002)(8676002)(71190400001)(6486002)(71200400001)(446003)(8936002)(105586002)(97736004)(81166006)(81156014)(36756003)(106356001)(476003)(25786009)(486006)(6436002)(186003)(3846002)(6116002)(478600001)(68736007)(53936002)(102836004)(6512007)(14454004)(5660300001)(44832011)(76176011)(52116002)(386003)(26005)(6506007)(2906002)(4326008)(66066001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM6PR04MB5157; H:AM6PR04MB4007.eurprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: vSkT2nxUC0zG4WHiwV/xHEZUzpEMzOp8/k+TbKGQg1/Pka6mpE2bkWUqwSrfmmsFxXb1mhMPR8p5JwcwV+Iz69WuUk42U1vkKTeq4IM87Mf/+Gv8bfr9+zSA+ubnOegFWFGpTB23lHGvZrNqaIU7FrzMAD7DNzlHP0AVuR1d+3L3kVbdd5hhlLRg921zLWdenRNmONs8tgCLhry0YKqFA1+YPFY6/InlgJIZKzFl9ZFZcCN/KmeN8ocD367OEtcjIajF5Pe8mYHNO1+utmj5gAzfjHUVFCUIGoid/Ps3SefQRItQy4ZS84IDYfhAeu9g spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 58631782-5d47-43c7-77b1-08d6763cab1e X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Jan 2019 14:13:45.4275 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR04MB5157 X-Mailman-Approved-At: Thu, 10 Jan 2019 08:34:06 +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: Anson Huang , David Airlie , "linux-kernel@vger.kernel.org" , Mirela Rabulea , "dri-devel@lists.freedesktop.org" , "kernel@pengutronix.de" , Fabio Estevam , Shawn Guo , dl-linux-imx Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Mirela Rabulea Add support for the following pixel formats: 16 bpp: RG16 ,BG16, XR15, XB15, AR15, AB15 Set the bus format based on input from the user and panel capabilities. Save the bus format in crtc->mode.private_flags, the DSI will use it. Use drm_get_format_name instead of locally defined fourcc_to_str. Signed-off-by: Mirela Rabulea --- drivers/gpu/drm/mxsfb/mxsfb_crtc.c | 100 ++++++++++++++++++++++++++----------- drivers/gpu/drm/mxsfb/mxsfb_drv.c | 5 ++ 2 files changed, 76 insertions(+), 29 deletions(-) diff --git a/drivers/gpu/drm/mxsfb/mxsfb_crtc.c b/drivers/gpu/drm/mxsfb/mxsfb_crtc.c index 6aa8804..b62b607 100644 --- a/drivers/gpu/drm/mxsfb/mxsfb_crtc.c +++ b/drivers/gpu/drm/mxsfb/mxsfb_crtc.c @@ -48,24 +48,6 @@ static u32 set_hsync_pulse_width(struct mxsfb_drm_private *mxsfb, u32 val) mxsfb->devdata->hs_wdth_shift; } -/* Print Four-character-code (FOURCC) */ -static char *fourcc_to_str(u32 fmt) -{ - /* Use 10 chars so we can simultaneously print two codes */ - static char code[10], *c = &code[0]; - - if (c == &code[10]) - c = &code[0]; - - *(c++) = (unsigned char)(fmt & 0xff); - *(c++) = (unsigned char)((fmt >> 8) & 0xff); - *(c++) = (unsigned char)((fmt >> 16) & 0xff); - *(c++) = (unsigned char)((fmt >> 24) & 0xff); - *(c++) = '\0'; - - return (c - 5); -} - /* Setup the MXSFB registers for decoding the pixels out of the framebuffer */ static int mxsfb_set_pixel_fmt(struct mxsfb_drm_private *mxsfb, bool update) { @@ -74,6 +56,7 @@ static int mxsfb_set_pixel_fmt(struct mxsfb_drm_private *mxsfb, bool update) const u32 format = crtc->primary->state->fb->format->format; u32 ctrl = 0, ctrl1 = 0; bool bgr_format = true; + struct drm_format_name_buf format_name_buf; if (!update) ctrl = CTRL_BYPASS_COUNT | CTRL_MASTER; @@ -92,7 +75,7 @@ static int mxsfb_set_pixel_fmt(struct mxsfb_drm_private *mxsfb, bool update) } DRM_DEV_DEBUG_DRIVER(drm->dev, "Setting up %s mode\n", - fourcc_to_str(format)); + drm_get_format_name(format, &format_name_buf)); /* Do some clean-up that we might have from a previous mode */ ctrl &= ~CTRL_SHIFT_DIR(1); @@ -103,19 +86,41 @@ static int mxsfb_set_pixel_fmt(struct mxsfb_drm_private *mxsfb, bool update) mxsfb->base + LCDC_V4_CTRL2 + REG_CLR); switch (format) { - case DRM_FORMAT_RGB565: + case DRM_FORMAT_BGR565: /* BG16 */ + if (mxsfb->devdata->ipversion < 4) + goto err; + writel(CTRL2_ODD_LINE_PATTERN(0x5) | + CTRL2_EVEN_LINE_PATTERN(0x5), + mxsfb->base + LCDC_V4_CTRL2 + REG_SET); + /* Fall through */ + case DRM_FORMAT_RGB565: /* RG16 */ ctrl |= CTRL_SET_WORD_LENGTH(0); + ctrl &= ~CTRL_DF16; ctrl1 |= CTRL1_SET_BYTE_PACKAGING(0xf); break; - case DRM_FORMAT_RGBX8888: - case DRM_FORMAT_RGBA8888: + case DRM_FORMAT_XBGR1555: /* XB15 */ + case DRM_FORMAT_ABGR1555: /* AB15 */ + if (mxsfb->devdata->ipversion < 4) + goto err; + writel(CTRL2_ODD_LINE_PATTERN(0x5) | + CTRL2_EVEN_LINE_PATTERN(0x5), + mxsfb->base + LCDC_V4_CTRL2 + REG_SET); + /* Fall through */ + case DRM_FORMAT_XRGB1555: /* XR15 */ + case DRM_FORMAT_ARGB1555: /* AR15 */ + ctrl |= CTRL_SET_WORD_LENGTH(0); + ctrl |= CTRL_DF16; + ctrl1 |= CTRL1_SET_BYTE_PACKAGING(0xf); + break; + case DRM_FORMAT_RGBX8888: /* RX24 */ + case DRM_FORMAT_RGBA8888: /* RA24 */ /* RGBX - > 0RGB */ ctrl |= CTRL_SHIFT_DIR(1); ctrl |= CTRL_SHIFT_NUM(8); bgr_format = false; /* Fall through */ - case DRM_FORMAT_XBGR8888: - case DRM_FORMAT_ABGR8888: + case DRM_FORMAT_XBGR8888: /* XB24 */ + case DRM_FORMAT_ABGR8888: /* AB24 */ if (bgr_format) { if (mxsfb->devdata->ipversion < 4) goto err; @@ -124,8 +129,8 @@ static int mxsfb_set_pixel_fmt(struct mxsfb_drm_private *mxsfb, bool update) mxsfb->base + LCDC_V4_CTRL2 + REG_SET); } /* Fall through */ - case DRM_FORMAT_XRGB8888: - case DRM_FORMAT_ARGB8888: + case DRM_FORMAT_XRGB8888: /* XR24 */ + case DRM_FORMAT_ARGB8888: /* AR24 */ ctrl |= CTRL_SET_WORD_LENGTH(3); /* Do not use packed pixels = one pixel per word instead. */ ctrl1 |= CTRL1_SET_BYTE_PACKAGING(0x7); @@ -146,19 +151,56 @@ static int mxsfb_set_pixel_fmt(struct mxsfb_drm_private *mxsfb, bool update) err: DRM_DEV_ERROR(drm->dev, "Unhandled pixel format: %s\n", - fourcc_to_str(format)); + drm_get_format_name(format, &format_name_buf)); + return -EINVAL; } +static u32 get_bus_format_from_bpp(u32 bpp) +{ + switch (bpp) { + case 16: + return MEDIA_BUS_FMT_RGB565_1X16; + case 18: + return MEDIA_BUS_FMT_RGB666_1X18; + case 24: + return MEDIA_BUS_FMT_RGB888_1X24; + default: + return MEDIA_BUS_FMT_RGB888_1X24; + } +} + static void mxsfb_set_bus_fmt(struct mxsfb_drm_private *mxsfb) { struct drm_crtc *crtc = &mxsfb->pipe.crtc; + unsigned int bits_per_pixel = crtc->primary->state->fb->format->depth; struct drm_device *drm = crtc->dev; u32 bus_format = MEDIA_BUS_FMT_RGB888_1X24; + int num_bus_formats = mxsfb->connector->display_info.num_bus_formats; + const u32 *bus_formats = mxsfb->connector->display_info.bus_formats; u32 reg = 0; + int i = 0; + + /* match the user requested bus_format to one supported by the panel */ + if (num_bus_formats) { + u32 user_bus_format = get_bus_format_from_bpp(bits_per_pixel); + + bus_format = bus_formats[0]; + for (i = 0; i < num_bus_formats; i++) { + if (user_bus_format == bus_formats[i]) { + bus_format = user_bus_format; + break; + } + } + } - if (mxsfb->connector->display_info.num_bus_formats) - bus_format = mxsfb->connector->display_info.bus_formats[0]; + /* + * CRTC will dictate the bus format via private_flags[16:1] + * and private_flags[0] will signal a bus format change + */ + crtc->mode.private_flags &= ~0x1FFFF; /* clear bus format */ + crtc->mode.private_flags |= (bus_format << 1); /* set bus format */ + crtc->mode.private_flags |= 0x1; /* bus format change indication*/ DRM_DEV_DEBUG_DRIVER(drm->dev, "Using bus_format: 0x%08X\n", bus_format); diff --git a/drivers/gpu/drm/mxsfb/mxsfb_drv.c b/drivers/gpu/drm/mxsfb/mxsfb_drv.c index aa35c43..d3fb3a8 100644 --- a/drivers/gpu/drm/mxsfb/mxsfb_drv.c +++ b/drivers/gpu/drm/mxsfb/mxsfb_drv.c @@ -65,6 +65,11 @@ static const uint32_t mxsfb_formats[] = { DRM_FORMAT_ABGR8888, DRM_FORMAT_RGBX8888, DRM_FORMAT_RGBA8888, + DRM_FORMAT_ARGB1555, + DRM_FORMAT_XRGB1555, + DRM_FORMAT_ABGR1555, + DRM_FORMAT_XBGR1555, + DRM_FORMAT_BGR565 }; static const struct mxsfb_devdata mxsfb_devdata[] = {