mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-28 11:18:45 +07:00
0425662fdf
Get rid of mode->vrefresh and just calculate it on demand. Saves a bit of space and avoids the cached value getting out of sync with reality. Mostly done with cocci, with the following manual fixups: - Remove the now empty loop in drm_helper_probe_single_connector_modes() - Fix __MODE() macro in ch7006_mode.c - Fix DRM_MODE_ARG() macro in drm_modes.h - Remove leftover comment from samsung_s6d16d0_mode - Drop the TODO @@ @@ struct drm_display_mode { ... - int vrefresh; ... }; @@ identifier N; expression E; @@ struct drm_display_mode N = { - .vrefresh = E }; @@ identifier N; expression E; @@ struct drm_display_mode N[...] = { ..., { - .vrefresh = E } ,... }; @@ expression E; @@ { DRM_MODE(...), - .vrefresh = E, } @@ identifier M, R; @@ int drm_mode_vrefresh(const struct drm_display_mode *M) { ... - if (M->vrefresh > 0) - R = M->vrefresh; - else if (...) { ... } ... } @@ struct drm_display_mode *p; expression E; @@ ( - p->vrefresh = E; | - p->vrefresh + drm_mode_vrefresh(p) ) @@ struct drm_display_mode s; expression E; @@ ( - s.vrefresh = E; | - s.vrefresh + drm_mode_vrefresh(&s) ) @@ expression E; @@ - drm_mode_vrefresh(E) ? drm_mode_vrefresh(E) : drm_mode_vrefresh(E) + drm_mode_vrefresh(E) @find_substruct@ identifier X; identifier S; @@ struct X { ... struct drm_display_mode S; ... }; @@ identifier find_substruct.S; expression E; identifier I; @@ { .S = { - .vrefresh = E } } @@ identifier find_substruct.S; identifier find_substruct.X; expression E; identifier I; @@ struct X I[...] = { ..., .S = { - .vrefresh = E } ,... }; v2: Drop TODO v3: Rebase v4: Rebase Cc: Andrzej Hajda <a.hajda@samsung.com> Cc: Neil Armstrong <narmstrong@baylibre.com> Cc: Laurent Pinchart <Laurent.pinchart@ideasonboard.com> Cc: Jonas Karlman <jonas@kwiboo.se> Cc: Jernej Skrabec <jernej.skrabec@siol.net> Cc: Inki Dae <inki.dae@samsung.com> Cc: Joonyoung Shim <jy0922.shim@samsung.com> Cc: Seung-Woo Kim <sw0312.kim@samsung.com> Cc: Kyungmin Park <kyungmin.park@samsung.com> Cc: Linus Walleij <linus.walleij@linaro.org> Cc: CK Hu <ck.hu@mediatek.com> Cc: Philipp Zabel <p.zabel@pengutronix.de> Cc: Ben Skeggs <bskeggs@redhat.com> Cc: Thierry Reding <thierry.reding@gmail.com> Cc: Sam Ravnborg <sam@ravnborg.org> Cc: Jerry Han <hanxu5@huaqin.corp-partner.google.com> Cc: Icenowy Zheng <icenowy@aosc.io> Cc: Jagan Teki <jagan@amarulasolutions.com> Cc: Stefan Mavrodiev <stefan@olimex.com> Cc: Robert Chiras <robert.chiras@nxp.com> Cc: "Guido Günther" <agx@sigxcpu.org> Cc: Purism Kernel Team <kernel@puri.sm> Cc: Benjamin Gaignard <benjamin.gaignard@linaro.org> Cc: Vincent Abriou <vincent.abriou@st.com> Cc: VMware Graphics <linux-graphics-maintainer@vmware.com> Cc: Thomas Hellstrom <thellstrom@vmware.com> Cc: linux-amlogic@lists.infradead.org Cc: nouveau@lists.freedesktop.org Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Emil Velikov <emil.velikov@collabora.com> Reviewed-by: Sam Ravnborg <sam@ravnborg.org> Acked-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20200428171940.19552-4-ville.syrjala@linux.intel.com
296 lines
6.4 KiB
C
296 lines
6.4 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Copyright (C) 2015 Heiko Schocher <hs@denx.de>
|
|
*
|
|
* from:
|
|
* drivers/gpu/drm/panel/panel-ld9040.c
|
|
* ld9040 AMOLED LCD drm_panel driver.
|
|
*
|
|
* Copyright (c) 2014 Samsung Electronics Co., Ltd
|
|
* Derived from drivers/video/backlight/ld9040.c
|
|
*
|
|
* Andrzej Hajda <a.hajda@samsung.com>
|
|
*/
|
|
|
|
#include <linux/delay.h>
|
|
#include <linux/gpio/consumer.h>
|
|
#include <linux/module.h>
|
|
#include <linux/regulator/consumer.h>
|
|
#include <linux/spi/spi.h>
|
|
|
|
#include <video/mipi_display.h>
|
|
#include <video/of_videomode.h>
|
|
#include <video/videomode.h>
|
|
|
|
#include <drm/drm_device.h>
|
|
#include <drm/drm_modes.h>
|
|
#include <drm/drm_panel.h>
|
|
|
|
struct lg4573 {
|
|
struct drm_panel panel;
|
|
struct spi_device *spi;
|
|
struct videomode vm;
|
|
};
|
|
|
|
static inline struct lg4573 *panel_to_lg4573(struct drm_panel *panel)
|
|
{
|
|
return container_of(panel, struct lg4573, panel);
|
|
}
|
|
|
|
static int lg4573_spi_write_u16(struct lg4573 *ctx, u16 data)
|
|
{
|
|
struct spi_transfer xfer = {
|
|
.len = 2,
|
|
};
|
|
__be16 temp = cpu_to_be16(data);
|
|
struct spi_message msg;
|
|
|
|
dev_dbg(ctx->panel.dev, "writing data: %x\n", data);
|
|
xfer.tx_buf = &temp;
|
|
spi_message_init(&msg);
|
|
spi_message_add_tail(&xfer, &msg);
|
|
|
|
return spi_sync(ctx->spi, &msg);
|
|
}
|
|
|
|
static int lg4573_spi_write_u16_array(struct lg4573 *ctx, const u16 *buffer,
|
|
unsigned int count)
|
|
{
|
|
unsigned int i;
|
|
int ret;
|
|
|
|
for (i = 0; i < count; i++) {
|
|
ret = lg4573_spi_write_u16(ctx, buffer[i]);
|
|
if (ret)
|
|
return ret;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int lg4573_spi_write_dcs(struct lg4573 *ctx, u8 dcs)
|
|
{
|
|
return lg4573_spi_write_u16(ctx, (0x70 << 8 | dcs));
|
|
}
|
|
|
|
static int lg4573_display_on(struct lg4573 *ctx)
|
|
{
|
|
int ret;
|
|
|
|
ret = lg4573_spi_write_dcs(ctx, MIPI_DCS_EXIT_SLEEP_MODE);
|
|
if (ret)
|
|
return ret;
|
|
|
|
msleep(5);
|
|
|
|
return lg4573_spi_write_dcs(ctx, MIPI_DCS_SET_DISPLAY_ON);
|
|
}
|
|
|
|
static int lg4573_display_off(struct lg4573 *ctx)
|
|
{
|
|
int ret;
|
|
|
|
ret = lg4573_spi_write_dcs(ctx, MIPI_DCS_SET_DISPLAY_OFF);
|
|
if (ret)
|
|
return ret;
|
|
|
|
msleep(120);
|
|
|
|
return lg4573_spi_write_dcs(ctx, MIPI_DCS_ENTER_SLEEP_MODE);
|
|
}
|
|
|
|
static int lg4573_display_mode_settings(struct lg4573 *ctx)
|
|
{
|
|
static const u16 display_mode_settings[] = {
|
|
0x703A, 0x7270, 0x70B1, 0x7208,
|
|
0x723B, 0x720F, 0x70B2, 0x7200,
|
|
0x72C8, 0x70B3, 0x7200, 0x70B4,
|
|
0x7200, 0x70B5, 0x7242, 0x7210,
|
|
0x7210, 0x7200, 0x7220, 0x70B6,
|
|
0x720B, 0x720F, 0x723C, 0x7213,
|
|
0x7213, 0x72E8, 0x70B7, 0x7246,
|
|
0x7206, 0x720C, 0x7200, 0x7200,
|
|
};
|
|
|
|
dev_dbg(ctx->panel.dev, "transfer display mode settings\n");
|
|
return lg4573_spi_write_u16_array(ctx, display_mode_settings,
|
|
ARRAY_SIZE(display_mode_settings));
|
|
}
|
|
|
|
static int lg4573_power_settings(struct lg4573 *ctx)
|
|
{
|
|
static const u16 power_settings[] = {
|
|
0x70C0, 0x7201, 0x7211, 0x70C3,
|
|
0x7207, 0x7203, 0x7204, 0x7204,
|
|
0x7204, 0x70C4, 0x7212, 0x7224,
|
|
0x7218, 0x7218, 0x7202, 0x7249,
|
|
0x70C5, 0x726F, 0x70C6, 0x7241,
|
|
0x7263,
|
|
};
|
|
|
|
dev_dbg(ctx->panel.dev, "transfer power settings\n");
|
|
return lg4573_spi_write_u16_array(ctx, power_settings,
|
|
ARRAY_SIZE(power_settings));
|
|
}
|
|
|
|
static int lg4573_gamma_settings(struct lg4573 *ctx)
|
|
{
|
|
static const u16 gamma_settings[] = {
|
|
0x70D0, 0x7203, 0x7207, 0x7273,
|
|
0x7235, 0x7200, 0x7201, 0x7220,
|
|
0x7200, 0x7203, 0x70D1, 0x7203,
|
|
0x7207, 0x7273, 0x7235, 0x7200,
|
|
0x7201, 0x7220, 0x7200, 0x7203,
|
|
0x70D2, 0x7203, 0x7207, 0x7273,
|
|
0x7235, 0x7200, 0x7201, 0x7220,
|
|
0x7200, 0x7203, 0x70D3, 0x7203,
|
|
0x7207, 0x7273, 0x7235, 0x7200,
|
|
0x7201, 0x7220, 0x7200, 0x7203,
|
|
0x70D4, 0x7203, 0x7207, 0x7273,
|
|
0x7235, 0x7200, 0x7201, 0x7220,
|
|
0x7200, 0x7203, 0x70D5, 0x7203,
|
|
0x7207, 0x7273, 0x7235, 0x7200,
|
|
0x7201, 0x7220, 0x7200, 0x7203,
|
|
};
|
|
|
|
dev_dbg(ctx->panel.dev, "transfer gamma settings\n");
|
|
return lg4573_spi_write_u16_array(ctx, gamma_settings,
|
|
ARRAY_SIZE(gamma_settings));
|
|
}
|
|
|
|
static int lg4573_init(struct lg4573 *ctx)
|
|
{
|
|
int ret;
|
|
|
|
dev_dbg(ctx->panel.dev, "initializing LCD\n");
|
|
|
|
ret = lg4573_display_mode_settings(ctx);
|
|
if (ret)
|
|
return ret;
|
|
|
|
ret = lg4573_power_settings(ctx);
|
|
if (ret)
|
|
return ret;
|
|
|
|
return lg4573_gamma_settings(ctx);
|
|
}
|
|
|
|
static int lg4573_power_on(struct lg4573 *ctx)
|
|
{
|
|
return lg4573_display_on(ctx);
|
|
}
|
|
|
|
static int lg4573_disable(struct drm_panel *panel)
|
|
{
|
|
struct lg4573 *ctx = panel_to_lg4573(panel);
|
|
|
|
return lg4573_display_off(ctx);
|
|
}
|
|
|
|
static int lg4573_enable(struct drm_panel *panel)
|
|
{
|
|
struct lg4573 *ctx = panel_to_lg4573(panel);
|
|
|
|
lg4573_init(ctx);
|
|
|
|
return lg4573_power_on(ctx);
|
|
}
|
|
|
|
static const struct drm_display_mode default_mode = {
|
|
.clock = 28341,
|
|
.hdisplay = 480,
|
|
.hsync_start = 480 + 10,
|
|
.hsync_end = 480 + 10 + 59,
|
|
.htotal = 480 + 10 + 59 + 10,
|
|
.vdisplay = 800,
|
|
.vsync_start = 800 + 15,
|
|
.vsync_end = 800 + 15 + 15,
|
|
.vtotal = 800 + 15 + 15 + 15,
|
|
};
|
|
|
|
static int lg4573_get_modes(struct drm_panel *panel,
|
|
struct drm_connector *connector)
|
|
{
|
|
struct drm_display_mode *mode;
|
|
|
|
mode = drm_mode_duplicate(connector->dev, &default_mode);
|
|
if (!mode) {
|
|
dev_err(panel->dev, "failed to add mode %ux%ux@%u\n",
|
|
default_mode.hdisplay, default_mode.vdisplay,
|
|
drm_mode_vrefresh(&default_mode));
|
|
return -ENOMEM;
|
|
}
|
|
|
|
drm_mode_set_name(mode);
|
|
|
|
mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
|
|
drm_mode_probed_add(connector, mode);
|
|
|
|
connector->display_info.width_mm = 61;
|
|
connector->display_info.height_mm = 103;
|
|
|
|
return 1;
|
|
}
|
|
|
|
static const struct drm_panel_funcs lg4573_drm_funcs = {
|
|
.disable = lg4573_disable,
|
|
.enable = lg4573_enable,
|
|
.get_modes = lg4573_get_modes,
|
|
};
|
|
|
|
static int lg4573_probe(struct spi_device *spi)
|
|
{
|
|
struct lg4573 *ctx;
|
|
int ret;
|
|
|
|
ctx = devm_kzalloc(&spi->dev, sizeof(*ctx), GFP_KERNEL);
|
|
if (!ctx)
|
|
return -ENOMEM;
|
|
|
|
ctx->spi = spi;
|
|
|
|
spi_set_drvdata(spi, ctx);
|
|
spi->bits_per_word = 8;
|
|
|
|
ret = spi_setup(spi);
|
|
if (ret < 0) {
|
|
dev_err(&spi->dev, "SPI setup failed: %d\n", ret);
|
|
return ret;
|
|
}
|
|
|
|
drm_panel_init(&ctx->panel, &spi->dev, &lg4573_drm_funcs,
|
|
DRM_MODE_CONNECTOR_DPI);
|
|
|
|
return drm_panel_add(&ctx->panel);
|
|
}
|
|
|
|
static int lg4573_remove(struct spi_device *spi)
|
|
{
|
|
struct lg4573 *ctx = spi_get_drvdata(spi);
|
|
|
|
lg4573_display_off(ctx);
|
|
drm_panel_remove(&ctx->panel);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct of_device_id lg4573_of_match[] = {
|
|
{ .compatible = "lg,lg4573" },
|
|
{ }
|
|
};
|
|
MODULE_DEVICE_TABLE(of, lg4573_of_match);
|
|
|
|
static struct spi_driver lg4573_driver = {
|
|
.probe = lg4573_probe,
|
|
.remove = lg4573_remove,
|
|
.driver = {
|
|
.name = "lg4573",
|
|
.of_match_table = lg4573_of_match,
|
|
},
|
|
};
|
|
module_spi_driver(lg4573_driver);
|
|
|
|
MODULE_AUTHOR("Heiko Schocher <hs@denx.de>");
|
|
MODULE_DESCRIPTION("lg4573 LCD Driver");
|
|
MODULE_LICENSE("GPL v2");
|