start process of re-porting st7789 driver. currently working for 240x240 display with overlay. need to redo dirty function

This commit is contained in:
lady ada 2020-07-27 15:14:11 -04:00
parent 55539a84a1
commit fc8dcd7ffb
3 changed files with 273 additions and 221 deletions

View file

@ -292,8 +292,8 @@ EOF
[ -d /lib/modules/$(uname -r)/build ] || { warning "Kernel was updated, please reboot now and re-run script!" && exit 1; } [ -d /lib/modules/$(uname -r)/build ] || { warning "Kernel was updated, please reboot now and re-run script!" && exit 1; }
cd st7789_module cd st7789_module
make -C /lib/modules/$(uname -r)/build M=$(pwd) modules || { warning "Apt failed to compile ST7789V driver!" && exit 1; } make -C /lib/modules/$(uname -r)/build M=$(pwd) modules || { warning "Apt failed to compile ST7789V driver!" && exit 1; }
mv /lib/modules/$(uname -r)/kernel/drivers/gpu/drm/tinydrm/mi0283qt.ko /lib/modules/$(uname -r)/kernel/drivers/gpu/drm/tinydrm/mi0283qt.BACK mv /lib/modules/$(uname -r)/kernel/drivers/gpu/drm/tiny/mi0283qt.ko /lib/modules/$(uname -r)/kernel/drivers/gpu/drm/tiny/mi0283qt.BACK
mv st7789v_ada.ko /lib/modules/$(uname -r)/kernel/drivers/gpu/drm/tinydrm/mi0283qt.ko mv st7789v_ada.ko /lib/modules/$(uname -r)/kernel/drivers/gpu/drm/tiny/mi0283qt.ko
overlay="dtoverlay=drm-minipitft114,rotation=${pitftrot}" overlay="dtoverlay=drm-minipitft114,rotation=${pitftrot}"
fi fi

View file

@ -0,0 +1,78 @@
/*
* Device Tree overlay for Adafruit Mini PiTFT 1.3" and 1.5" 240x240 Display
*
*/
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";
fragment@0 {
target = <&spi0>;
__overlay__ {
status = "okay";
spidev@0{
status = "disabled";
};
};
};
fragment@1 {
target = <&gpio>;
__overlay__ {
pitft_pins: pitft_pins {
brcm,pins = <25>; /* dc pin */
brcm,function = <1>; /* out */
brcm,pull = <0>; /* no pull */
};
};
};
fragment@2 {
target = <&spi0>;
__overlay__ {
/* needed to avoid dtc warning */
#address-cells = <1>;
#size-cells = <0>;
pitft: pitft@0{
compatible = "multi-inno,mi0283qt";
reg = <0>;
pinctrl-names = "default";
pinctrl-0 = <&pitft_pins>;
spi-max-frequency = <32000000>;
rotation = <0>;
width = <240>;
height = <240>;
col_offset = <0>;
row_offset = <80>;
dc-gpios = <&gpio 25 0>;
backlight = <&backlight>;
};
};
};
fragment@3 {
target-path = "/soc";
__overlay__ {
backlight: backlight {
compatible = "gpio-backlight";
gpios = <&gpio 22 0>;
};
};
};
__overrides__ {
speed = <&pitft>,"spi-max-frequency:0";
rotation = <&pitft>,"rotation:0";
width = <&pitft>,"width:0";
height = <&pitft>,"height:0";
col_offset = <&pitft>,"col_offset:0";
row_offset = <&pitft>,"row_offset:0";
};
};

View file

@ -1,13 +1,8 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/* /*
* DRM driver for ST7789V panels with flexible config * DRM driver for Multi-Inno MI0283QT panels
* *
* Copyright 2019 Limor Fried
* Copyright 2016 Noralf Trønnes * Copyright 2016 Noralf Trønnes
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/ */
#include <linux/backlight.h> #include <linux/backlight.h>
@ -18,13 +13,43 @@
#include <linux/regulator/consumer.h> #include <linux/regulator/consumer.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#include <drm/drm_atomic_helper.h>
#include <drm/drm_damage_helper.h>
#include <drm/drm_drv.h>
#include <drm/drm_fb_cma_helper.h>
#include <drm/drm_fb_helper.h> #include <drm/drm_fb_helper.h>
#include <drm/drm_modeset_helper.h> #include <drm/drm_fourcc.h>
#include <drm/drm_gem_cma_helper.h>
#include <drm/drm_gem_framebuffer_helper.h> #include <drm/drm_gem_framebuffer_helper.h>
#include <drm/tinydrm/mipi-dbi.h> #include <drm/drm_mipi_dbi.h>
#include <drm/tinydrm/tinydrm-helpers.h> #include <drm/drm_modeset_helper.h>
#include <video/mipi_display.h> #include <video/mipi_display.h>
#define ILI9341_FRMCTR1 0xb1
#define ILI9341_DISCTRL 0xb6
#define ILI9341_ETMOD 0xb7
#define ILI9341_PWCTRL1 0xc0
#define ILI9341_PWCTRL2 0xc1
#define ILI9341_VMCTRL1 0xc5
#define ILI9341_VMCTRL2 0xc7
#define ILI9341_PWCTRLA 0xcb
#define ILI9341_PWCTRLB 0xcf
#define ILI9341_PGAMCTRL 0xe0
#define ILI9341_NGAMCTRL 0xe1
#define ILI9341_DTCTRLA 0xe8
#define ILI9341_DTCTRLB 0xea
#define ILI9341_PWRSEQ 0xed
#define ILI9341_EN3GAM 0xf2
#define ILI9341_PUMPCTRL 0xf7
#define ILI9341_MADCTL_BGR BIT(3)
#define ILI9341_MADCTL_MV BIT(5)
#define ILI9341_MADCTL_MX BIT(6)
#define ILI9341_MADCTL_MY BIT(7)
#define ST77XX_MADCTL_MY 0x80 #define ST77XX_MADCTL_MY 0x80
#define ST77XX_MADCTL_MX 0x40 #define ST77XX_MADCTL_MX 0x40
#define ST77XX_MADCTL_MV 0x20 #define ST77XX_MADCTL_MV 0x20
@ -32,54 +57,58 @@
#define ST77XX_MADCTL_BGR 0x08 #define ST77XX_MADCTL_BGR 0x08
#define ST77XX_MADCTL_RGB 0x00 #define ST77XX_MADCTL_RGB 0x00
static u32 col_offset = 0; static u32 col_offset = 0;
static u32 row_offset = 0; static u32 row_offset = 0;
static u8 col_hack_fix_offset = 0; static u8 col_hack_fix_offset = 0;
static short x_offset = 0; static short x_offset = 0;
static short y_offset = 0; static short y_offset = 0;
static void st7789vada_enable(struct drm_simple_display_pipe *pipe, static void mi0283qt_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 tinydrm_device *tdev = pipe_to_tinydrm(pipe); struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(pipe->crtc.dev);
struct mipi_dbi *mipi = mipi_dbi_from_tinydrm(tdev); struct mipi_dbi *dbi = &dbidev->dbi;
u8 addr_mode; u8 addr_mode;
int ret; int ret, idx;
if (!drm_dev_enter(pipe->crtc.dev, &idx))
return;
DRM_DEBUG_KMS("\n"); DRM_DEBUG_KMS("\n");
ret = mipi_dbi_poweron_conditional_reset(mipi); ret = mipi_dbi_poweron_conditional_reset(dbidev);
if (ret < 0) if (ret < 0)
return; goto out_exit;
if (ret == 1) if (ret == 1)
goto out_enable; goto out_enable;
mipi_dbi_command(mipi, MIPI_DCS_SET_DISPLAY_OFF); mipi_dbi_command(dbi, MIPI_DCS_SET_DISPLAY_OFF);
mipi_dbi_command(mipi, MIPI_DCS_SOFT_RESET); mipi_dbi_command(dbi, MIPI_DCS_SOFT_RESET);
msleep(150); msleep(150);
mipi_dbi_command(mipi, MIPI_DCS_EXIT_SLEEP_MODE); mipi_dbi_command(dbi, MIPI_DCS_EXIT_SLEEP_MODE);
msleep(10); msleep(10);
mipi_dbi_command(mipi, MIPI_DCS_SET_PIXEL_FORMAT, 0x55); // 16 bit color mipi_dbi_command(dbi, MIPI_DCS_SET_PIXEL_FORMAT, 0x55); // 16 bit color
msleep(10); msleep(10);
mipi_dbi_command(mipi, MIPI_DCS_SET_ADDRESS_MODE, 0); mipi_dbi_command(dbi, MIPI_DCS_SET_ADDRESS_MODE, 0);
mipi_dbi_command(mipi, MIPI_DCS_SET_COLUMN_ADDRESS, 0, 0, 0, 240); mipi_dbi_command(dbi, MIPI_DCS_SET_COLUMN_ADDRESS, 0, 0, 0, 240);
mipi_dbi_command(mipi, MIPI_DCS_SET_PAGE_ADDRESS, 0, 0, 320>>8, 320&0xFF); mipi_dbi_command(dbi, MIPI_DCS_SET_PAGE_ADDRESS, 0, 0, 320>>8, 320&0xFF);
mipi_dbi_command(mipi, MIPI_DCS_ENTER_INVERT_MODE); // odd hack, displays are inverted mipi_dbi_command(dbi, MIPI_DCS_ENTER_INVERT_MODE); // odd hack, displays are inverted
mipi_dbi_command(mipi, MIPI_DCS_ENTER_NORMAL_MODE); mipi_dbi_command(dbi, MIPI_DCS_ENTER_NORMAL_MODE);
msleep(10); msleep(10);
mipi_dbi_command(mipi, MIPI_DCS_SET_DISPLAY_ON); mipi_dbi_command(dbi, MIPI_DCS_SET_DISPLAY_ON);
msleep(10); msleep(10);
out_enable: out_enable:
/* The PiTFT (ili9340) has a hardware reset circuit that /* The PiTFT has a hardware reset circuit that
* resets only on power-on and not on each reboot through * resets only on power-on and not on each reboot through
* a gpio like the rpi-display does. * a gpio like the rpi-display does.
* As a result, we need to always apply the rotation value * As a result, we need to always apply the rotation value
* regardless of the display "on/off" state. * regardless of the display "on/off" state.
*/ */
switch (mipi->rotation) { switch (dbidev->rotation) {
default: default:
addr_mode = 0; addr_mode = 0;
x_offset = col_offset; x_offset = col_offset;
@ -102,202 +131,144 @@ out_enable:
y_offset = col_offset; y_offset = col_offset;
break; break;
} }
mipi_dbi_command(mipi, MIPI_DCS_SET_ADDRESS_MODE, addr_mode); mipi_dbi_command(dbi, MIPI_DCS_SET_ADDRESS_MODE, addr_mode);
mipi_dbi_command(mipi, MIPI_DCS_SET_DISPLAY_ON); mipi_dbi_command(dbi, MIPI_DCS_SET_DISPLAY_ON);
mipi_dbi_enable_flush(mipi, crtc_state, plane_state); mipi_dbi_enable_flush(dbidev, crtc_state, plane_state);
out_exit:
backlight_enable(mipi->backlight); drm_dev_exit(idx);
} }
static const struct drm_simple_display_pipe_funcs st7789vada_pipe_funcs = { static const struct drm_simple_display_pipe_funcs mi0283qt_pipe_funcs = {
.enable = st7789vada_enable, .enable = mi0283qt_enable,
.disable = mipi_dbi_pipe_disable, .disable = mipi_dbi_pipe_disable,
.update = tinydrm_display_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 struct drm_display_mode st7789vada_mode = { static const struct drm_display_mode mi0283qt_mode = {
TINYDRM_MODE(240, 320, 25, 15), // width, height, mm_w, mm_h DRM_SIMPLE_MODE(240, 320, 58, 43),
}; };
DEFINE_DRM_GEM_CMA_FOPS(st7789vada_fops); DEFINE_DRM_GEM_CMA_FOPS(mi0283qt_fops);
static struct drm_driver st7789vada_driver = { static struct drm_driver mi0283qt_driver = {
.driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME | .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC,
DRIVER_ATOMIC, .fops = &mi0283qt_fops,
.fops = &st7789vada_fops, .release = mipi_dbi_release,
TINYDRM_GEM_DRIVER_OPS, DRM_GEM_CMA_VMAP_DRIVER_OPS,
.debugfs_init = mipi_dbi_debugfs_init, .debugfs_init = mipi_dbi_debugfs_init,
.name = "st7789vada", .name = "mi0283qt",
.desc = "ST7789V Adafruit", .desc = "Multi-Inno MI0283QT",
.date = "20190914", .date = "20160614",
.major = 1, .major = 1,
.minor = 0, .minor = 0,
}; };
static const struct of_device_id st7789vada_of_match[] = { static const struct of_device_id mi0283qt_of_match[] = {
{ .compatible = "multi-inno,mi0283qt" }, { .compatible = "multi-inno,mi0283qt" },
{}, {},
}; };
MODULE_DEVICE_TABLE(of, st7789vada_of_match); MODULE_DEVICE_TABLE(of, mi0283qt_of_match);
static const struct spi_device_id st7789vada_id[] = { static const struct spi_device_id mi0283qt_id[] = {
{ "st7789vada", 0 }, { "mi0283qt", 0 },
{ }, { },
}; };
MODULE_DEVICE_TABLE(spi, st7789vada_id); MODULE_DEVICE_TABLE(spi, mi0283qt_id);
static const struct drm_framebuffer_funcs st7789vada_fb_funcs = { static void st7789vada_fb_dirty(struct drm_framebuffer *fb, struct drm_rect *rect)
.destroy = drm_gem_fb_destroy,
.create_handle = drm_gem_fb_create_handle,
.dirty = tinydrm_fb_dirty,
};
static const uint32_t st7789vada_formats[] = {
DRM_FORMAT_RGB565,
DRM_FORMAT_XRGB8888,
};
static int st7789vada_fb_dirty(struct drm_framebuffer *fb,
struct drm_file *file_priv,
unsigned int flags, unsigned int color,
struct drm_clip_rect *clips,
unsigned int num_clips)
{ {
struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0); struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
struct tinydrm_device *tdev = fb->dev->dev_private; struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(fb->dev);
struct mipi_dbi *mipi = mipi_dbi_from_tinydrm(tdev); unsigned int height = rect->y2 - rect->y1;
bool swap = mipi->swap_bytes; unsigned int width = rect->x2 - rect->x1;
struct drm_clip_rect clip; struct mipi_dbi *dbi = &dbidev->dbi;
int ret = 0; bool swap = dbi->swap_bytes;
u16 x_start, y_start;
u16 x1, x2, y1, y2;
int idx, ret = 0;
bool full; bool full;
void *tr; void *tr;
u16 x1, x2, y1, y2;
if (!mipi->enabled) if (!dbidev->enabled)
return 0; return;
full = tinydrm_merge_clips(&clip, clips, num_clips, flags, if (!drm_dev_enter(fb->dev, &idx))
fb->width, fb->height); return;
DRM_DEBUG("Flushing [FB:%d] x1=%u, x2=%u, y1=%u, y2=%u\n", fb->base.id, full = width == fb->width && height == fb->height;
clip.x1, clip.x2, clip.y1, clip.y2);
if (!mipi->dc || !full || swap || DRM_DEBUG_KMS("Flushing [FB:%d] " DRM_RECT_FMT "\n", fb->base.id, DRM_RECT_ARG(rect));
if (!dbi->dc || !full || swap ||
fb->format->format == DRM_FORMAT_XRGB8888) { fb->format->format == DRM_FORMAT_XRGB8888) {
tr = mipi->tx_buf; tr = dbidev->tx_buf;
ret = mipi_dbi_buf_copy(mipi->tx_buf, fb, &clip, swap); ret = mipi_dbi_buf_copy(dbidev->tx_buf, fb, rect, swap);
if (ret) if (ret)
return ret; goto err_msg;
} else { } else {
tr = cma_obj->vaddr; tr = cma_obj->vaddr;
} }
x1 = clip.x1 + x_offset; x1 = rect->x1 + x_offset;
x2 = clip.x2 - 1 + x_offset; x2 = rect->x2 - 1 + x_offset;
y1 = clip.y1 + y_offset; y1 = rect->y1 + y_offset;
y2 = clip.y2 - 1 + y_offset; y2 = rect->y2 - 1 + y_offset;
//printk(KERN_INFO "setaddrwin %d %d %d %d\n", x1, y1, x2, y2); printk(KERN_INFO "setaddrwin %d %d %d %d\n", x1, y1, x2, y2);
mipi_dbi_command(mipi, MIPI_DCS_SET_COLUMN_ADDRESS, mipi_dbi_command(dbi, MIPI_DCS_SET_COLUMN_ADDRESS,
(x1 >> 8) & 0xFF, x1 & 0xFF, (x1 >> 8) & 0xFF, x1 & 0xFF,
(x2 >> 8) & 0xFF, x2 & 0xFF); (x2 >> 8) & 0xFF, x2 & 0xFF);
mipi_dbi_command(mipi, MIPI_DCS_SET_PAGE_ADDRESS, mipi_dbi_command(dbi, MIPI_DCS_SET_PAGE_ADDRESS,
(y1 >> 8) & 0xFF, y1 & 0xFF, (y1 >> 8) & 0xFF, y1 & 0xFF,
(y2 >> 8) & 0xFF, y2 & 0xFF); (y2 >> 8) & 0xFF, y2 & 0xFF);
ret = mipi_dbi_command_buf(mipi, MIPI_DCS_WRITE_MEMORY_START, tr, ret = mipi_dbi_command_buf(dbi, MIPI_DCS_WRITE_MEMORY_START, tr,
(clip.x2 - clip.x1) * (clip.y2 - clip.y1) * 2); width*height * 2);
err_msg:
if (ret)
dev_err_once(fb->dev->dev, "Failed to update display %d\n", ret);
return ret; drm_dev_exit(idx);
} }
/**
* st7789vada - MIPI DBI initialization
* @dev: Parent device
* @mipi: &mipi_dbi structure to initialize
* @pipe_funcs: Display pipe functions
* @driver: DRM driver
* @mode: Display mode
* @rotation: Initial rotation in degrees Counter Clock Wise
*
* This function initializes a &mipi_dbi structure and it's underlying
* @tinydrm_device. It also sets up the display pipeline.
*
* Supported formats: Native RGB565 and emulated XRGB8888.
*
* Objects created by this function will be automatically freed on driver
* detach (devres).
*
* Returns:
* Zero on success, negative error code on failure.
*/
int st7789vada_init(struct device *dev, struct mipi_dbi *mipi,
const struct drm_simple_display_pipe_funcs *pipe_funcs,
struct drm_driver *driver,
const struct drm_display_mode *mode, unsigned int rotation)
{
size_t bufsize = mode->vdisplay * mode->hdisplay * sizeof(u16);
struct tinydrm_device *tdev = &mipi->tinydrm;
int ret;
if (!mipi->command) static int mi0283qt_probe(struct spi_device *spi)
return -EINVAL;
mutex_init(&mipi->cmdlock);
mipi->tx_buf = devm_kmalloc(dev, bufsize, GFP_KERNEL);
if (!mipi->tx_buf)
return -ENOMEM;
ret = devm_tinydrm_init(dev, tdev, &st7789vada_fb_funcs, driver);
if (ret)
return ret;
tdev->fb_dirty = st7789vada_fb_dirty;
/* TODO: Maybe add DRM_MODE_CONNECTOR_SPI */
ret = tinydrm_display_pipe_init(tdev, pipe_funcs,
DRM_MODE_CONNECTOR_VIRTUAL,
st7789vada_formats,
ARRAY_SIZE(st7789vada_formats), mode,
rotation);
if (ret)
return ret;
tdev->drm->mode_config.preferred_depth = 16;
mipi->rotation = rotation;
drm_mode_config_reset(tdev->drm);
DRM_DEBUG_KMS("preferred_depth=%u, rotation = %u\n",
tdev->drm->mode_config.preferred_depth, rotation);
return 0;
}
static int st7789vada_probe(struct spi_device *spi)
{ {
struct device *dev = &spi->dev; struct device *dev = &spi->dev;
struct mipi_dbi *mipi; struct mipi_dbi_dev *dbidev;
struct drm_device *drm;
struct mipi_dbi *dbi;
struct gpio_desc *dc; struct gpio_desc *dc;
u32 rotation = 0; u32 rotation = 0;
u32 width = 240; u32 width = 240;
u32 height = 320; u32 height = 320;
int ret; int ret;
mipi = devm_kzalloc(dev, sizeof(*mipi), GFP_KERNEL); dbidev = kzalloc(sizeof(*dbidev), GFP_KERNEL);
if (!mipi) if (!dbidev)
return -ENOMEM; return -ENOMEM;
mipi->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); printk(KERN_INFO "ST7789 fake driver\n");
if (IS_ERR(mipi->reset)) {
dbi = &dbidev->dbi;
drm = &dbidev->drm;
ret = devm_drm_dev_init(dev, drm, &mi0283qt_driver);
if (ret) {
kfree(dbidev);
return ret;
}
drm_mode_config_init(drm);
dbi->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
if (IS_ERR(dbi->reset)) {
DRM_DEV_ERROR(dev, "Failed to get gpio 'reset'\n"); DRM_DEV_ERROR(dev, "Failed to get gpio 'reset'\n");
return PTR_ERR(mipi->reset); return PTR_ERR(dbi->reset);
} }
dc = devm_gpiod_get_optional(dev, "dc", GPIOD_OUT_LOW); dc = devm_gpiod_get_optional(dev, "dc", GPIOD_OUT_LOW);
@ -306,16 +277,19 @@ static int st7789vada_probe(struct spi_device *spi)
return PTR_ERR(dc); return PTR_ERR(dc);
} }
mipi->regulator = devm_regulator_get(dev, "power"); dbidev->regulator = devm_regulator_get(dev, "power");
if (IS_ERR(mipi->regulator)) if (IS_ERR(dbidev->regulator))
return PTR_ERR(mipi->regulator); return PTR_ERR(dbidev->regulator);
mipi->backlight = devm_of_find_backlight(dev); dbidev->backlight = devm_of_find_backlight(dev);
if (IS_ERR(mipi->backlight)) if (IS_ERR(dbidev->backlight))
return PTR_ERR(mipi->backlight); return PTR_ERR(dbidev->backlight);
device_property_read_u32(dev, "rotation", &rotation); device_property_read_u32(dev, "rotation", &rotation);
//printk(KERN_INFO "Rotation %d\n", rotation);
ret = mipi_dbi_spi_init(spi, dbi, dc);
if (ret)
return ret;
device_property_read_u32(dev, "width", &width); device_property_read_u32(dev, "width", &width);
if (width % 2) { if (width % 2) {
@ -324,84 +298,84 @@ static int st7789vada_probe(struct spi_device *spi)
} else { } else {
col_hack_fix_offset = 0; col_hack_fix_offset = 0;
} }
//printk(KERN_INFO "Width %d\n", width); printk(KERN_INFO "Width %d\n", width);
if ((width == 0) || (width > 240)) { if ((width == 0) || (width > 240)) {
width = 240; // default to full framebuff; width = 240; // default to full framebuff;
} }
device_property_read_u32(dev, "height", &height); device_property_read_u32(dev, "height", &height);
//printk(KERN_INFO "Height %d\n", height); printk(KERN_INFO "Height %d\n", height);
if ((height == 0) || (height > 320)) { if ((height == 0) || (height > 320)) {
height = 320; // default to full framebuff; height = 320; // default to full framebuff;
} }
st7789vada_mode.hdisplay = st7789vada_mode.hsync_start =
st7789vada_mode.hsync_end = st7789vada_mode.htotal = width;
st7789vada_mode.vdisplay = st7789vada_mode.vsync_start =
st7789vada_mode.vsync_end = st7789vada_mode.vtotal = height;
device_property_read_u32(dev, "col_offset", &col_offset); device_property_read_u32(dev, "col_offset", &col_offset);
//printk(KERN_INFO "Column offset %d\n", col_offset); printk(KERN_INFO "Column offset %d\n", col_offset);
device_property_read_u32(dev, "row_offset", &row_offset); device_property_read_u32(dev, "row_offset", &row_offset);
//printk(KERN_INFO "Row offset %d\n", row_offset); printk(KERN_INFO "Row offset %d\n", row_offset);
ret = mipi_dbi_spi_init(spi, mipi, dc); ret = mipi_dbi_dev_init(dbidev, &mi0283qt_pipe_funcs, &mi0283qt_mode, rotation);
if (ret) if (ret)
return ret; return ret;
/* Cannot read from this controller via SPI */ drm_mode_config_reset(drm);
mipi->read_commands = NULL;
ret = st7789vada_init(&spi->dev, mipi, &st7789vada_pipe_funcs, ret = drm_dev_register(drm, 0);
&st7789vada_driver, &st7789vada_mode, rotation);
if (ret) if (ret)
return ret; return ret;
spi_set_drvdata(spi, mipi); spi_set_drvdata(spi, drm);
return devm_tinydrm_register(&mipi->tinydrm); drm_fbdev_generic_setup(drm, 0);
}
static void st7789vada_shutdown(struct spi_device *spi)
{
struct mipi_dbi *mipi = spi_get_drvdata(spi);
tinydrm_shutdown(&mipi->tinydrm);
}
static int __maybe_unused st7789vada_pm_suspend(struct device *dev)
{
struct mipi_dbi *mipi = dev_get_drvdata(dev);
return drm_mode_config_helper_suspend(mipi->tinydrm.drm);
}
static int __maybe_unused st7789vada_pm_resume(struct device *dev)
{
struct mipi_dbi *mipi = dev_get_drvdata(dev);
drm_mode_config_helper_resume(mipi->tinydrm.drm);
return 0; return 0;
} }
static const struct dev_pm_ops st7789vada_pm_ops = { static int mi0283qt_remove(struct spi_device *spi)
SET_SYSTEM_SLEEP_PM_OPS(st7789vada_pm_suspend, st7789vada_pm_resume) {
struct drm_device *drm = spi_get_drvdata(spi);
drm_dev_unplug(drm);
drm_atomic_helper_shutdown(drm);
return 0;
}
static void mi0283qt_shutdown(struct spi_device *spi)
{
drm_atomic_helper_shutdown(spi_get_drvdata(spi));
}
static int __maybe_unused mi0283qt_pm_suspend(struct device *dev)
{
return drm_mode_config_helper_suspend(dev_get_drvdata(dev));
}
static int __maybe_unused mi0283qt_pm_resume(struct device *dev)
{
drm_mode_config_helper_resume(dev_get_drvdata(dev));
return 0;
}
static const struct dev_pm_ops mi0283qt_pm_ops = {
SET_SYSTEM_SLEEP_PM_OPS(mi0283qt_pm_suspend, mi0283qt_pm_resume)
}; };
static struct spi_driver st7789vada_spi_driver = { static struct spi_driver mi0283qt_spi_driver = {
.driver = { .driver = {
.name = "st7789vada", .name = "mi0283qt",
.owner = THIS_MODULE, .owner = THIS_MODULE,
.of_match_table = st7789vada_of_match, .of_match_table = mi0283qt_of_match,
.pm = &st7789vada_pm_ops, .pm = &mi0283qt_pm_ops,
}, },
.id_table = st7789vada_id, .id_table = mi0283qt_id,
.probe = st7789vada_probe, .probe = mi0283qt_probe,
.shutdown = st7789vada_shutdown, .remove = mi0283qt_remove,
.shutdown = mi0283qt_shutdown,
}; };
module_spi_driver(st7789vada_spi_driver); module_spi_driver(mi0283qt_spi_driver);
MODULE_DESCRIPTION("Sitronix ST7789V Flexible DRM driver"); MODULE_DESCRIPTION("Sitronix ST7789V Flexible DRM driver");
MODULE_AUTHOR("Limor Fried"); MODULE_AUTHOR("Noralf Trønnes + Limor Fried");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");