renames + good math

This commit is contained in:
lady ada 2020-07-27 23:58:57 -04:00
parent 72002bc814
commit cd981e348b

View file

@ -1,8 +1,14 @@
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
/* /*
* DRM driver for Multi-Inno MI0283QT panels * DRM driver for ST7789V panels with flexible config
* *
* 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>
@ -42,7 +48,7 @@ static short x_offset = 0;
static short y_offset = 0; static short y_offset = 0;
static void mi0283qt_fb_dirty(struct drm_framebuffer *fb, struct drm_rect *rect) static void st7789vada_fb_dirty(struct drm_framebuffer *fb, struct drm_rect *rect)
{ {
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 mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(fb->dev); struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(fb->dev);
@ -100,7 +106,7 @@ err_msg:
static void mi0283qt_pipe_update(struct drm_simple_display_pipe *pipe, static void st7789vada_pipe_update(struct drm_simple_display_pipe *pipe,
struct drm_plane_state *old_state) struct drm_plane_state *old_state)
{ {
struct drm_plane_state *state = pipe->plane.state; struct drm_plane_state *state = pipe->plane.state;
@ -108,7 +114,7 @@ static void mi0283qt_pipe_update(struct drm_simple_display_pipe *pipe,
struct drm_rect rect; struct drm_rect rect;
if (drm_atomic_helper_damage_merged(old_state, state, &rect)) if (drm_atomic_helper_damage_merged(old_state, state, &rect))
mi0283qt_fb_dirty(state->fb, &rect); st7789vada_fb_dirty(state->fb, &rect);
if (crtc->state->event) { if (crtc->state->event) {
spin_lock_irq(&crtc->dev->event_lock); spin_lock_irq(&crtc->dev->event_lock);
@ -119,48 +125,48 @@ static void mi0283qt_pipe_update(struct drm_simple_display_pipe *pipe,
} }
static struct drm_display_mode mi0283qt_mode = { static struct drm_display_mode st7789vada_mode = {
DRM_SIMPLE_MODE(240, 320, 58, 43), DRM_SIMPLE_MODE(240, 320, 58, 43),
}; };
DEFINE_DRM_GEM_CMA_FOPS(mi0283qt_fops); DEFINE_DRM_GEM_CMA_FOPS(st7789vada_fops);
static struct drm_driver mi0283qt_driver = { static struct drm_driver st7789vada_driver = {
.driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC, .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC,
.fops = &mi0283qt_fops, .fops = &st7789vada_fops,
.release = mipi_dbi_release, .release = mipi_dbi_release,
DRM_GEM_CMA_VMAP_DRIVER_OPS, DRM_GEM_CMA_VMAP_DRIVER_OPS,
.debugfs_init = mipi_dbi_debugfs_init, .debugfs_init = mipi_dbi_debugfs_init,
.name = "mi0283qt", .name = "st7789vada",
.desc = "Multi-Inno MI0283QT", .desc = "ST7789V Adafruit",
.date = "20160614", .date = "20200727",
.major = 1, .major = 1,
.minor = 0, .minor = 0,
}; };
static const struct of_device_id mi0283qt_of_match[] = { static const struct of_device_id st7789vada_of_match[] = {
{ .compatible = "multi-inno,mi0283qt" }, { .compatible = "multi-inno,mi0283qt" },
{}, {},
}; };
MODULE_DEVICE_TABLE(of, mi0283qt_of_match); MODULE_DEVICE_TABLE(of, st7789vada_of_match);
static const struct spi_device_id mi0283qt_id[] = { static const struct spi_device_id st7789vada_id[] = {
{ "mi0283qt", 0 }, { "st7789vada", 0 },
{ }, { },
}; };
MODULE_DEVICE_TABLE(spi, mi0283qt_id); MODULE_DEVICE_TABLE(spi, st7789vada_id);
static void mi0283qt_enable(struct drm_simple_display_pipe *pipe, static void st7789vada_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 mipi_dbi *dbi = &dbidev->dbi; struct mipi_dbi *dbi = &dbidev->dbi;
u8 addr_mode; u8 addr_mode;
u16 width = mi0283qt_mode.htotal; u16 width = st7789vada_mode.htotal;
u16 height = mi0283qt_mode.vtotal; u16 height = st7789vada_mode.vtotal;
int ret, idx; int ret, idx;
printk(KERN_INFO "w/h %d %d\n", width, height); printk(KERN_INFO "w/h %d %d\n", width, height);
@ -216,14 +222,14 @@ out_enable:
break; break;
case 180: case 180:
addr_mode = ST77XX_MADCTL_MX | ST77XX_MADCTL_MY; addr_mode = ST77XX_MADCTL_MX | ST77XX_MADCTL_MY;
x_offset = (240 - width) + col_offset+col_hack_fix_offset; x_offset = (240 - width) - col_offset + col_hack_fix_offset;
// hack tweak to account for extra pixel width to make even // hack tweak to account for extra pixel width to make even
y_offset = (320 - height) + row_offset; y_offset = (320 - height) - row_offset;
break; break;
case 270: case 270:
addr_mode = ST77XX_MADCTL_MV | ST77XX_MADCTL_MY; addr_mode = ST77XX_MADCTL_MV | ST77XX_MADCTL_MY;
x_offset = (320 - height) + row_offset; x_offset = (320 - height) - row_offset;
y_offset = (240 - width) + col_offset; y_offset = (240 - width) - col_offset;
break; break;
} }
printk(KERN_INFO "Rotation offsets %d %d\n", x_offset, y_offset); printk(KERN_INFO "Rotation offsets %d %d\n", x_offset, y_offset);
@ -239,16 +245,16 @@ out_exit:
static const struct drm_simple_display_pipe_funcs mi0283qt_pipe_funcs = { static const struct drm_simple_display_pipe_funcs st7789vada_pipe_funcs = {
.enable = mi0283qt_enable, .enable = st7789vada_enable,
.disable = mipi_dbi_pipe_disable, .disable = mipi_dbi_pipe_disable,
.update = mi0283qt_pipe_update, .update = st7789vada_pipe_update,
.prepare_fb = drm_gem_fb_simple_display_pipe_prepare_fb, .prepare_fb = drm_gem_fb_simple_display_pipe_prepare_fb,
}; };
static int mi0283qt_probe(struct spi_device *spi) static int st7789vada_probe(struct spi_device *spi)
{ {
struct device *dev = &spi->dev; struct device *dev = &spi->dev;
struct mipi_dbi_dev *dbidev; struct mipi_dbi_dev *dbidev;
@ -268,7 +274,7 @@ static int mi0283qt_probe(struct spi_device *spi)
dbi = &dbidev->dbi; dbi = &dbidev->dbi;
drm = &dbidev->drm; drm = &dbidev->drm;
ret = devm_drm_dev_init(dev, drm, &mi0283qt_driver); ret = devm_drm_dev_init(dev, drm, &st7789vada_driver);
if (ret) { if (ret) {
kfree(dbidev); kfree(dbidev);
return ret; return ret;
@ -302,7 +308,7 @@ static int mi0283qt_probe(struct spi_device *spi)
device_property_read_u32(dev, "width", &width); device_property_read_u32(dev, "width", &width);
if (width % 2) { if (width % 2) {
width +=1; // odd width will cause a kernel panic width +=1; // odd width will cause a kernel panic
col_hack_fix_offset = 1; col_hack_fix_offset = 3;
} else { } else {
col_hack_fix_offset = 0; col_hack_fix_offset = 0;
} }
@ -316,10 +322,10 @@ static int mi0283qt_probe(struct spi_device *spi)
height = 320; // default to full framebuff; height = 320; // default to full framebuff;
} }
mi0283qt_mode.hdisplay = mi0283qt_mode.hsync_start = st7789vada_mode.hdisplay = st7789vada_mode.hsync_start =
mi0283qt_mode.hsync_end = mi0283qt_mode.htotal = width; st7789vada_mode.hsync_end = st7789vada_mode.htotal = width;
mi0283qt_mode.vdisplay = mi0283qt_mode.vsync_start = st7789vada_mode.vdisplay = st7789vada_mode.vsync_start =
mi0283qt_mode.vsync_end = mi0283qt_mode.vtotal = height; 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);
@ -336,7 +342,7 @@ static int mi0283qt_probe(struct spi_device *spi)
/* Cannot read from this controller via SPI */ /* Cannot read from this controller via SPI */
dbi->read_commands = NULL; dbi->read_commands = NULL;
ret = mipi_dbi_dev_init(dbidev, &mi0283qt_pipe_funcs, &mi0283qt_mode, rotation); ret = mipi_dbi_dev_init(dbidev, &st7789vada_pipe_funcs, &st7789vada_mode, rotation);
if (ret) if (ret)
return ret; return ret;
@ -353,7 +359,7 @@ static int mi0283qt_probe(struct spi_device *spi)
return 0; return 0;
} }
static int mi0283qt_remove(struct spi_device *spi) static int st7789vada_remove(struct spi_device *spi)
{ {
struct drm_device *drm = spi_get_drvdata(spi); struct drm_device *drm = spi_get_drvdata(spi);
@ -363,40 +369,40 @@ static int mi0283qt_remove(struct spi_device *spi)
return 0; return 0;
} }
static void mi0283qt_shutdown(struct spi_device *spi) static void st7789vada_shutdown(struct spi_device *spi)
{ {
drm_atomic_helper_shutdown(spi_get_drvdata(spi)); drm_atomic_helper_shutdown(spi_get_drvdata(spi));
} }
static int __maybe_unused mi0283qt_pm_suspend(struct device *dev) static int __maybe_unused st7789vada_pm_suspend(struct device *dev)
{ {
return drm_mode_config_helper_suspend(dev_get_drvdata(dev)); return drm_mode_config_helper_suspend(dev_get_drvdata(dev));
} }
static int __maybe_unused mi0283qt_pm_resume(struct device *dev) static int __maybe_unused st7789vada_pm_resume(struct device *dev)
{ {
drm_mode_config_helper_resume(dev_get_drvdata(dev)); drm_mode_config_helper_resume(dev_get_drvdata(dev));
return 0; return 0;
} }
static const struct dev_pm_ops mi0283qt_pm_ops = { static const struct dev_pm_ops st7789vada_pm_ops = {
SET_SYSTEM_SLEEP_PM_OPS(mi0283qt_pm_suspend, mi0283qt_pm_resume) SET_SYSTEM_SLEEP_PM_OPS(st7789vada_pm_suspend, st7789vada_pm_resume)
}; };
static struct spi_driver mi0283qt_spi_driver = { static struct spi_driver st7789vada_spi_driver = {
.driver = { .driver = {
.name = "mi0283qt", .name = "st7789vada",
.owner = THIS_MODULE, .owner = THIS_MODULE,
.of_match_table = mi0283qt_of_match, .of_match_table = st7789vada_of_match,
.pm = &mi0283qt_pm_ops, .pm = &st7789vada_pm_ops,
}, },
.id_table = mi0283qt_id, .id_table = st7789vada_id,
.probe = mi0283qt_probe, .probe = st7789vada_probe,
.remove = mi0283qt_remove, .remove = st7789vada_remove,
.shutdown = mi0283qt_shutdown, .shutdown = st7789vada_shutdown,
}; };
module_spi_driver(mi0283qt_spi_driver); module_spi_driver(st7789vada_spi_driver);
MODULE_DESCRIPTION("Sitronix ST7789V Flexible DRM driver"); MODULE_DESCRIPTION("Sitronix ST7789V Flexible DRM driver");
MODULE_AUTHOR("Noralf Trønnes + Limor Fried"); MODULE_AUTHOR("Noralf Trønnes + Limor Fried");