From: Robert Chiras <robert.chiras@nxp.com>
To: Daniel Vetter <daniel.vetter@ffwll.ch>,
Philipp Zabel <p.zabel@pengutronix.de>,
Marek Vasut <marex@denx.de>
Cc: Mirela Rabulea <mirela.rabulea@nxp.com>,
Stefan Agner <stefan@agner.ch>, Shawn Guo <shawnguo@kernel.org>,
Fabio Estevam <fabio.estevam@nxp.com>,
David Airlie <airlied@linux.ie>,
Anson Huang <anson.huang@nxp.com>,
"dri-devel@lists.freedesktop.org"
<dri-devel@lists.freedesktop.org>,
dl-linux-imx <linux-imx@nxp.com>,
"kernel@pengutronix.de" <kernel@pengutronix.de>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [PATCH 06/10] drm/mxsfb: Add support for new pixel formats in eLCDIF
Date: Wed, 9 Jan 2019 14:13:46 +0000 [thread overview]
Message-ID: <1547043209-8283-7-git-send-email-robert.chiras@nxp.com> (raw)
In-Reply-To: <1547043209-8283-1-git-send-email-robert.chiras@nxp.com>
From: Mirela Rabulea <mirela.rabulea@nxp.com>
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 <mirela.rabulea@nxp.com>
---
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[] = {
--
2.7.4
next prev parent reply other threads:[~2019-01-09 14:14 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-09 14:13 [PATCH 00/10] Add support for DRM bridge and additional pixel formats Robert Chiras
2019-01-09 14:13 ` [PATCH 01/10] drm/mxsfb: Update mxsfb to support a bridge Robert Chiras
2019-01-09 14:13 ` [PATCH 02/10] dt-bindings: display: Add max-res property for mxsfb Robert Chiras
2019-01-09 14:13 ` [PATCH 03/10] drm/mxsfb: Add max-res property for MXSFB Robert Chiras
2019-01-09 14:13 ` [PATCH 04/10] drm/mxsfb: Update mxsfb with additional pixel formats Robert Chiras
2019-01-14 16:38 ` Guido Günther
2019-01-09 14:13 ` [PATCH 05/10] drm/mxsfb: Fix the vblank events Robert Chiras
2019-01-09 14:13 ` Robert Chiras [this message]
2019-01-09 14:13 ` [PATCH 07/10] drm/mxsfb: Signal mode changed when bpp changed Robert Chiras
2019-01-14 16:37 ` Guido Günther
2019-01-09 14:13 ` [PATCH 08/10] drm/mxsfb: Update mxsfb to support LCD reset Robert Chiras
2019-01-10 21:19 ` Fabio Estevam
2019-01-09 14:13 ` [PATCH 09/10] drm/mxsfb: Improve the axi clock usage Robert Chiras
2019-01-09 17:09 ` Stefan Agner
2019-01-15 9:53 ` Robert Chiras
2019-01-09 14:13 ` [PATCH 10/10] drm/mxsfb: Clear OUTSTANDING_REQS bits Robert Chiras
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1547043209-8283-7-git-send-email-robert.chiras@nxp.com \
--to=robert.chiras@nxp.com \
--cc=airlied@linux.ie \
--cc=anson.huang@nxp.com \
--cc=daniel.vetter@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=fabio.estevam@nxp.com \
--cc=kernel@pengutronix.de \
--cc=linux-imx@nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=marex@denx.de \
--cc=mirela.rabulea@nxp.com \
--cc=p.zabel@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=stefan@agner.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).