Commit 98823f37 authored by Geert Uytterhoeven's avatar Geert Uytterhoeven Committed by Sam Ravnborg

drm: tiny: st7735r: Prepare for adding support for more displays

Currently the st7735r driver supports only a single display panel.
Prepare for adding support for other display panels by factoring out the
display-specific parameters in struct st7735r_cfg.

For now, the following parameters can be configured:
  - Display resolution,
  - Horizontal/vertical display offsets,
  - Read-write versus read-only controllers,
  - RGB versus BGR color component ordering.

Rename jd_t18003_t01_pipe_enable() and jd_t18003_t01_pipe_funcs() to
st7735r_pipe_enable() resp. st7735r_pipe_funcs(), as they are not really
specific to the Jianda JD-T18003-T01 display anymore.
Signed-off-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: default avatarSam Ravnborg <sam@ravnborg.org>
Signed-off-by: default avatarSam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20200115124548.3951-5-geert+renesas@glider.be
parent f41a8a69
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
* DRM driver for Sitronix ST7735R panels * DRM driver for Sitronix ST7735R panels
* *
* Copyright 2017 David Lechner <david@lechnology.com> * Copyright 2017 David Lechner <david@lechnology.com>
* Copyright (C) 2019 Glider bvba
*/ */
#include <linux/backlight.h> #include <linux/backlight.h>
...@@ -10,6 +11,7 @@ ...@@ -10,6 +11,7 @@
#include <linux/dma-buf.h> #include <linux/dma-buf.h>
#include <linux/gpio/consumer.h> #include <linux/gpio/consumer.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of_device.h>
#include <linux/property.h> #include <linux/property.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#include <video/mipi_display.h> #include <video/mipi_display.h>
...@@ -37,12 +39,28 @@ ...@@ -37,12 +39,28 @@
#define ST7735R_MY BIT(7) #define ST7735R_MY BIT(7)
#define ST7735R_MX BIT(6) #define ST7735R_MX BIT(6)
#define ST7735R_MV BIT(5) #define ST7735R_MV BIT(5)
#define ST7735R_RGB BIT(3)
struct st7735r_cfg {
const struct drm_display_mode mode;
unsigned int left_offset;
unsigned int top_offset;
unsigned int write_only:1;
unsigned int rgb:1; /* RGB (vs. BGR) */
};
struct st7735r_priv {
struct mipi_dbi_dev dbidev; /* Must be first for .release() */
const struct st7735r_cfg *cfg;
};
static void jd_t18003_t01_pipe_enable(struct drm_simple_display_pipe *pipe, static void st7735r_pipe_enable(struct drm_simple_display_pipe *pipe,
struct drm_crtc_state *crtc_state, struct drm_crtc_state *crtc_state,
struct drm_plane_state *plane_state) struct drm_plane_state *plane_state)
{ {
struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(pipe->crtc.dev); struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(pipe->crtc.dev);
struct st7735r_priv *priv = container_of(dbidev, struct st7735r_priv,
dbidev);
struct mipi_dbi *dbi = &dbidev->dbi; struct mipi_dbi *dbi = &dbidev->dbi;
int ret, idx; int ret, idx;
u8 addr_mode; u8 addr_mode;
...@@ -87,6 +105,10 @@ static void jd_t18003_t01_pipe_enable(struct drm_simple_display_pipe *pipe, ...@@ -87,6 +105,10 @@ static void jd_t18003_t01_pipe_enable(struct drm_simple_display_pipe *pipe,
addr_mode = ST7735R_MY | ST7735R_MV; addr_mode = ST7735R_MY | ST7735R_MV;
break; break;
} }
if (priv->cfg->rgb)
addr_mode |= ST7735R_RGB;
mipi_dbi_command(dbi, MIPI_DCS_SET_ADDRESS_MODE, addr_mode); mipi_dbi_command(dbi, MIPI_DCS_SET_ADDRESS_MODE, addr_mode);
mipi_dbi_command(dbi, MIPI_DCS_SET_PIXEL_FORMAT, mipi_dbi_command(dbi, MIPI_DCS_SET_PIXEL_FORMAT,
MIPI_DCS_PIXEL_FMT_16BIT); MIPI_DCS_PIXEL_FMT_16BIT);
...@@ -109,15 +131,19 @@ static void jd_t18003_t01_pipe_enable(struct drm_simple_display_pipe *pipe, ...@@ -109,15 +131,19 @@ static void jd_t18003_t01_pipe_enable(struct drm_simple_display_pipe *pipe,
drm_dev_exit(idx); drm_dev_exit(idx);
} }
static const struct drm_simple_display_pipe_funcs jd_t18003_t01_pipe_funcs = { static const struct drm_simple_display_pipe_funcs st7735r_pipe_funcs = {
.enable = jd_t18003_t01_pipe_enable, .enable = st7735r_pipe_enable,
.disable = mipi_dbi_pipe_disable, .disable = mipi_dbi_pipe_disable,
.update = mipi_dbi_pipe_update, .update = mipi_dbi_pipe_update,
.prepare_fb = drm_gem_fb_simple_display_pipe_prepare_fb, .prepare_fb = drm_gem_fb_simple_display_pipe_prepare_fb,
}; };
static const struct drm_display_mode jd_t18003_t01_mode = { static const struct st7735r_cfg jd_t18003_t01_cfg = {
DRM_SIMPLE_MODE(128, 160, 28, 35), .mode = { DRM_SIMPLE_MODE(128, 160, 28, 35) },
/* Cannot read from Adafruit 1.8" display via SPI */
.write_only = true,
};
}; };
DEFINE_DRM_GEM_CMA_FOPS(st7735r_fops); DEFINE_DRM_GEM_CMA_FOPS(st7735r_fops);
...@@ -136,13 +162,13 @@ static struct drm_driver st7735r_driver = { ...@@ -136,13 +162,13 @@ static struct drm_driver st7735r_driver = {
}; };
static const struct of_device_id st7735r_of_match[] = { static const struct of_device_id st7735r_of_match[] = {
{ .compatible = "jianda,jd-t18003-t01" }, { .compatible = "jianda,jd-t18003-t01", .data = &jd_t18003_t01_cfg },
{ }, { },
}; };
MODULE_DEVICE_TABLE(of, st7735r_of_match); MODULE_DEVICE_TABLE(of, st7735r_of_match);
static const struct spi_device_id st7735r_id[] = { static const struct spi_device_id st7735r_id[] = {
{ "jd-t18003-t01", 0 }, { "jd-t18003-t01", (uintptr_t)&jd_t18003_t01_cfg },
{ }, { },
}; };
MODULE_DEVICE_TABLE(spi, st7735r_id); MODULE_DEVICE_TABLE(spi, st7735r_id);
...@@ -150,17 +176,26 @@ MODULE_DEVICE_TABLE(spi, st7735r_id); ...@@ -150,17 +176,26 @@ MODULE_DEVICE_TABLE(spi, st7735r_id);
static int st7735r_probe(struct spi_device *spi) static int st7735r_probe(struct spi_device *spi)
{ {
struct device *dev = &spi->dev; struct device *dev = &spi->dev;
const struct st7735r_cfg *cfg;
struct mipi_dbi_dev *dbidev; struct mipi_dbi_dev *dbidev;
struct st7735r_priv *priv;
struct drm_device *drm; struct drm_device *drm;
struct mipi_dbi *dbi; struct mipi_dbi *dbi;
struct gpio_desc *dc; struct gpio_desc *dc;
u32 rotation = 0; u32 rotation = 0;
int ret; int ret;
dbidev = kzalloc(sizeof(*dbidev), GFP_KERNEL); cfg = of_device_get_match_data(&spi->dev);
if (!dbidev) if (!cfg)
cfg = (void *)spi_get_device_id(spi)->driver_data;
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM; return -ENOMEM;
dbidev = &priv->dbidev;
priv->cfg = cfg;
dbi = &dbidev->dbi; dbi = &dbidev->dbi;
drm = &dbidev->drm; drm = &dbidev->drm;
ret = devm_drm_dev_init(dev, drm, &st7735r_driver); ret = devm_drm_dev_init(dev, drm, &st7735r_driver);
...@@ -193,10 +228,14 @@ static int st7735r_probe(struct spi_device *spi) ...@@ -193,10 +228,14 @@ static int st7735r_probe(struct spi_device *spi)
if (ret) if (ret)
return ret; return ret;
/* Cannot read from Adafruit 1.8" display via SPI */ if (cfg->write_only)
dbi->read_commands = NULL; dbi->read_commands = NULL;
dbidev->left_offset = cfg->left_offset;
dbidev->top_offset = cfg->top_offset;
ret = mipi_dbi_dev_init(dbidev, &jd_t18003_t01_pipe_funcs, &jd_t18003_t01_mode, rotation); ret = mipi_dbi_dev_init(dbidev, &st7735r_pipe_funcs, &cfg->mode,
rotation);
if (ret) if (ret)
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment