// SPDX-License-Identifier: GPL-2.0
/*
* S6E63M0 AMOLED LCD drm_panel driver.
*
* Copyright (C) 2019 Paweł Chmiel <pawel.mikolaj.chmiel@gmail.com>
* Derived from drivers/gpu/drm/panel-samsung-ld9040.c
*
* Andrzej Hajda <a.hajda@samsung.com>
*/
#include <drm/drm_modes.h>
#include <drm/drm_panel.h>
#include <linux/backlight.h>
#include <linux/delay.h>
#include <linux/export.h>
#include <linux/gpio/consumer.h>
#include <linux/module.h>
#include <linux/property.h>
#include <linux/regulator/consumer.h>
#include <linux/media-bus-format.h>
#include <video/mipi_display.h>
#include "panel-samsung-s6e63m0.h"
#define S6E63M0_LCD_ID_VALUE_M2 0 xA4
#define S6E63M0_LCD_ID_VALUE_SM2 0 xB4
#define S6E63M0_LCD_ID_VALUE_SM2_1 0 xB6
#define NUM_GAMMA_LEVELS 28
#define GAMMA_TABLE_COUNT 23
#define MAX_BRIGHTNESS (NUM_GAMMA_LEVELS - 1 )
/* array of gamma tables for gamma value 2.2 */
static u8 const s6e63m0_gamma_22[NUM_GAMMA_LEVELS][GAMMA_TABLE_COUNT] = {
/* 30 cd */
{ MCS_PGAMMACTL, 0 x02,
0 x18, 0 x08, 0 x24, 0 xA1, 0 x51, 0 x7B, 0 xCE,
0 xCB, 0 xC2, 0 xC7, 0 xCB, 0 xBC, 0 xDA, 0 xDD,
0 xD3, 0 x00, 0 x53, 0 x00, 0 x52, 0 x00, 0 x6F, },
/* 40 cd */
{ MCS_PGAMMACTL, 0 x02,
0 x18, 0 x08, 0 x24, 0 x97, 0 x58, 0 x71, 0 xCC,
0 xCB, 0 xC0, 0 xC5, 0 xC9, 0 xBA, 0 xD9, 0 xDC,
0 xD1, 0 x00, 0 x5B, 0 x00, 0 x5A, 0 x00, 0 x7A, },
/* 50 cd */
{ MCS_PGAMMACTL, 0 x02,
0 x18, 0 x08, 0 x24, 0 x96, 0 x58, 0 x72, 0 xCB,
0 xCA, 0 xBF, 0 xC6, 0 xC9, 0 xBA, 0 xD6, 0 xD9,
0 xCD, 0 x00, 0 x61, 0 x00, 0 x61, 0 x00, 0 x83, },
/* 60 cd */
{ MCS_PGAMMACTL, 0 x02,
0 x18, 0 x08, 0 x24, 0 x91, 0 x5E, 0 x6E, 0 xC9,
0 xC9, 0 xBD, 0 xC4, 0 xC9, 0 xB8, 0 xD3, 0 xD7,
0 xCA, 0 x00, 0 x69, 0 x00, 0 x67, 0 x00, 0 x8D, },
/* 70 cd */
{ MCS_PGAMMACTL, 0 x02,
0 x18, 0 x08, 0 x24, 0 x8E, 0 x62, 0 x6B, 0 xC7,
0 xC9, 0 xBB, 0 xC3, 0 xC7, 0 xB7, 0 xD3, 0 xD7,
0 xCA, 0 x00, 0 x6E, 0 x00, 0 x6C, 0 x00, 0 x94, },
/* 80 cd */
{ MCS_PGAMMACTL, 0 x02,
0 x18, 0 x08, 0 x24, 0 x89, 0 x68, 0 x65, 0 xC9,
0 xC9, 0 xBC, 0 xC1, 0 xC5, 0 xB6, 0 xD2, 0 xD5,
0 xC9, 0 x00, 0 x73, 0 x00, 0 x72, 0 x00, 0 x9A, },
/* 90 cd */
{ MCS_PGAMMACTL, 0 x02,
0 x18, 0 x08, 0 x24, 0 x89, 0 x69, 0 x64, 0 xC7,
0 xC8, 0 xBB, 0 xC0, 0 xC5, 0 xB4, 0 xD2, 0 xD5,
0 xC9, 0 x00, 0 x77, 0 x00, 0 x76, 0 x00, 0 xA0, },
/* 100 cd */
{ MCS_PGAMMACTL, 0 x02,
0 x18, 0 x08, 0 x24, 0 x86, 0 x69, 0 x60, 0 xC6,
0 xC8, 0 xBA, 0 xBF, 0 xC4, 0 xB4, 0 xD0, 0 xD4,
0 xC6, 0 x00, 0 x7C, 0 x00, 0 x7A, 0 x00, 0 xA7, },
/* 110 cd */
{ MCS_PGAMMACTL, 0 x02,
0 x18, 0 x08, 0 x24, 0 x86, 0 x6A, 0 x60, 0 xC5,
0 xC7, 0 xBA, 0 xBD, 0 xC3, 0 xB2, 0 xD0, 0 xD4,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0 xC7,
0 xBB, 0 x00, 0 xB6, 0 x00, 0 xB6, 0 x00, 0 xFA, },
/* 300 cd */
{ MCS_PGAMMACTL, 0 x02,
0 x18, 0 x08, 0 x24, 0 x70, 0 x6E, 0 x4E, 0 xBC,
0 xC0, 0 xAF, 0 xB3, 0 xB8, 0 xA5, 0 xC5, 0 xC7,
0 xBB, 0 x00, 0 xB9, 0 x00, 0 xB8, 0 x00, 0 xFC, },
};
#define NUM_ACL_LEVELS 7
#define ACL_TABLE_COUNT 28
static u8 const s6e63m0_acl[NUM_ACL_LEVELS][ACL_TABLE_COUNT] = {
/* NULL ACL */
{ MCS_BCMODE,
0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00,
0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00,
0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00,
0 x00, 0 x00, 0 x00 },
/* 40P ACL */
{ MCS_BCMODE,
0 x4D, 0 x96, 0 x1D, 0 x00, 0 x00, 0 x01, 0 xDF, 0 x00,
0 x00, 0 x03, 0 x1F, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00,
0 x01, 0 x06, 0 x0C, 0 x11, 0 x16, 0 x1C, 0 x21, 0 x26,
0 x2B, 0 x31, 0 x36 },
/* 43P ACL */
{ MCS_BCMODE,
0 x4D, 0 x96, 0 x1D, 0 x00, 0 x00, 0 x01, 0 xDF, 0 x00,
0 x00, 0 x03, 0 x1F, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00,
0 x01, 0 x07, 0 x0C, 0 x12, 0 x18, 0 x1E, 0 x23, 0 x29,
0 x2F, 0 x34, 0 x3A },
/* 45P ACL */
{ MCS_BCMODE,
0 x4D, 0 x96, 0 x1D, 0 x00, 0 x00, 0 x01, 0 xDF, 0 x00,
0 x00, 0 x03, 0 x1F, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00,
0 x01, 0 x07, 0 x0D, 0 x13, 0 x19, 0 x1F, 0 x25, 0 x2B,
0 x31, 0 x37, 0 x3D },
/* 47P ACL */
{ MCS_BCMODE,
0 x4D, 0 x96, 0 x1D, 0 x00, 0 x00, 0 x01, 0 xDF, 0 x00,
0 x00, 0 x03, 0 x1F, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00,
0 x01, 0 x07, 0 x0E, 0 x14, 0 x1B, 0 x21, 0 x27, 0 x2E,
0 x34, 0 x3B, 0 x41 },
/* 48P ACL */
{ MCS_BCMODE,
0 x4D, 0 x96, 0 x1D, 0 x00, 0 x00, 0 x01, 0 xDF, 0 x00,
0 x00, 0 x03, 0 x1F, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00,
0 x01, 0 x08, 0 x0E, 0 x15, 0 x1B, 0 x22, 0 x29, 0 x2F,
0 x36, 0 x3C, 0 x43 },
/* 50P ACL */
{ MCS_BCMODE,
0 x4D, 0 x96, 0 x1D, 0 x00, 0 x00, 0 x01, 0 xDF, 0 x00,
0 x00, 0 x03, 0 x1F, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00,
0 x01, 0 x08, 0 x0F, 0 x16, 0 x1D, 0 x24, 0 x2A, 0 x31,
0 x38, 0 x3F, 0 x46 },
};
/* This tells us which ACL level goes with which gamma */
static u8 const s6e63m0_acl_per_gamma[NUM_GAMMA_LEVELS] = {
/* 30 - 60 cd: ACL off/NULL */
0 , 0 , 0 , 0 ,
/* 70 - 250 cd: 40P ACL */
1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
/* 260 - 300 cd: 50P ACL */
6 , 6 , 6 , 6 , 6 ,
};
/* The ELVSS backlight regulator has 5 levels */
#define S6E63M0_ELVSS_LEVELS 5
static u8 const s6e63m0_elvss_offsets[S6E63M0_ELVSS_LEVELS] = {
0 x00, /* not set */
0 x0D, /* 30 cd - 100 cd */
0 x09, /* 110 cd - 160 cd */
0 x07, /* 170 cd - 200 cd */
0 x00, /* 210 cd - 300 cd */
};
/* This tells us which ELVSS level goes with which gamma */
static u8 const s6e63m0_elvss_per_gamma[NUM_GAMMA_LEVELS] = {
/* 30 - 100 cd */
1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
/* 110 - 160 cd */
2 , 2 , 2 , 2 , 2 , 2 ,
/* 170 - 200 cd */
3 , 3 , 3 , 3 ,
/* 210 - 300 cd */
4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 ,
};
struct s6e63m0 {
struct device *dev;
void *transport_data;
int (*dcs_read)(struct device *dev, void *trsp, const u8 cmd, u8 *val);
int (*dcs_write)(struct device *dev, void *trsp, const u8 *data, size_t len);
struct drm_panel panel;
struct backlight_device *bl_dev;
u8 lcd_type;
u8 elvss_pulse;
bool dsi_mode;
struct regulator_bulk_data supplies[2 ];
struct gpio_desc *reset_gpio;
/*
* This field is tested by functions directly accessing bus before
* transfer, transfer is skipped if it is set. In case of transfer
* failure or unexpected response the field is set to error value.
* Such construct allows to eliminate many checks in higher level
* functions.
*/
int error;
};
static const struct drm_display_mode default_mode = {
.clock = 25628 ,
.hdisplay = 480 ,
.hsync_start = 480 + 16 ,
.hsync_end = 480 + 16 + 2 ,
.htotal = 480 + 16 + 2 + 16 ,
.vdisplay = 800 ,
.vsync_start = 800 + 28 ,
.vsync_end = 800 + 28 + 2 ,
.vtotal = 800 + 28 + 2 + 1 ,
.width_mm = 53 ,
.height_mm = 89 ,
.flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
};
static inline struct s6e63m0 *panel_to_s6e63m0(struct drm_panel *panel)
{
return container_of(panel, struct s6e63m0, panel);
}
static int s6e63m0_clear_error(struct s6e63m0 *ctx)
{
int ret = ctx->error;
ctx->error = 0 ;
return ret;
}
static void s6e63m0_dcs_read(struct s6e63m0 *ctx, const u8 cmd, u8 *data)
{
if (ctx->error < 0 )
return ;
ctx->error = ctx->dcs_read(ctx->dev, ctx->transport_data, cmd, data);
}
static void s6e63m0_dcs_write(struct s6e63m0 *ctx, const u8 *data, size_t len)
{
if (ctx->error < 0 || len == 0 )
return ;
ctx->error = ctx->dcs_write(ctx->dev, ctx->transport_data, data, len);
}
#define s6e63m0_dcs_write_seq_static(ctx, seq ...) \
({ \
static const u8 d[] = { seq }; \
s6e63m0_dcs_write(ctx, d, ARRAY_SIZE(d)); \
})
static int s6e63m0_check_lcd_type(struct s6e63m0 *ctx)
{
u8 id1, id2, id3;
int ret;
s6e63m0_dcs_read(ctx, MCS_READ_ID1, &id1);
s6e63m0_dcs_read(ctx, MCS_READ_ID2, &id2);
s6e63m0_dcs_read(ctx, MCS_READ_ID3, &id3);
ret = s6e63m0_clear_error(ctx);
if (ret) {
dev_err(ctx->dev, "error checking LCD type (%d)\n" , ret);
ctx->lcd_type = 0 x00;
return ret;
}
dev_info(ctx->dev, "MTP ID: %02x %02x %02x\n" , id1, id2, id3);
/*
* We attempt to detect what panel is mounted on the controller.
* The third ID byte represents the desired ELVSS pulse for
* some displays.
*/
switch (id2) {
case S6E63M0_LCD_ID_VALUE_M2:
dev_info(ctx->dev, "detected LCD panel AMS397GE MIPI M2\n" );
ctx->elvss_pulse = id3;
break ;
case S6E63M0_LCD_ID_VALUE_SM2:
case S6E63M0_LCD_ID_VALUE_SM2_1:
dev_info(ctx->dev, "detected LCD panel AMS397GE MIPI SM2\n" );
ctx->elvss_pulse = id3;
break ;
default :
dev_info(ctx->dev, "unknown LCD panel type %02x\n" , id2);
/* Default ELVSS pulse level */
ctx->elvss_pulse = 0 x16;
break ;
}
ctx->lcd_type = id2;
return 0 ;
}
static void s6e63m0_init(struct s6e63m0 *ctx)
{
/*
* We do not know why there is a difference in the DSI mode.
* (No datasheet.)
*
* In the vendor driver this sequence is called
* "SEQ_PANEL_CONDITION_SET" or "DCS_CMD_SEQ_PANEL_COND_SET".
*/
if (ctx->dsi_mode)
s6e63m0_dcs_write_seq_static(ctx, MCS_PANELCTL,
0 x01, 0 x2c, 0 x2c, 0 x07, 0 x07, 0 x5f, 0 xb3,
0 x6d, 0 x97, 0 x1d, 0 x3a, 0 x0f, 0 x00, 0 x00);
else
s6e63m0_dcs_write_seq_static(ctx, MCS_PANELCTL,
0 x01, 0 x27, 0 x27, 0 x07, 0 x07, 0 x54, 0 x9f,
0 x63, 0 x8f, 0 x1a, 0 x33, 0 x0d, 0 x00, 0 x00);
s6e63m0_dcs_write_seq_static(ctx, MCS_DISCTL,
0 x02, 0 x03, 0 x1c, 0 x10, 0 x10);
s6e63m0_dcs_write_seq_static(ctx, MCS_IFCTL,
0 x03, 0 x00, 0 x00);
s6e63m0_dcs_write_seq_static(ctx, MCS_PGAMMACTL,
0 x00, 0 x18, 0 x08, 0 x24, 0 x64, 0 x56, 0 x33,
0 xb6, 0 xba, 0 xa8, 0 xac, 0 xb1, 0 x9d, 0 xc1,
0 xc1, 0 xb7, 0 x00, 0 x9c, 0 x00, 0 x9f, 0 x00,
0 xd6);
s6e63m0_dcs_write_seq_static(ctx, MCS_PGAMMACTL,
0 x01);
s6e63m0_dcs_write_seq_static(ctx, MCS_SRCCTL,
0 x00, 0 x8e, 0 x07);
s6e63m0_dcs_write_seq_static(ctx, MCS_PENTILE_1, 0 x6c);
s6e63m0_dcs_write_seq_static(ctx, MCS_GAMMA_DELTA_Y_RED,
0 x2c, 0 x12, 0 x0c, 0 x0a, 0 x10, 0 x0e, 0 x17,
0 x13, 0 x1f, 0 x1a, 0 x2a, 0 x24, 0 x1f, 0 x1b,
0 x1a, 0 x17, 0 x2b, 0 x26, 0 x22, 0 x20, 0 x3a,
0 x34, 0 x30, 0 x2c, 0 x29, 0 x26, 0 x25, 0 x23,
0 x21, 0 x20, 0 x1e, 0 x1e);
s6e63m0_dcs_write_seq_static(ctx, MCS_GAMMA_DELTA_X_RED,
0 x00, 0 x00, 0 x11, 0 x22, 0 x33, 0 x44, 0 x44,
0 x44, 0 x55, 0 x55, 0 x66, 0 x66, 0 x66, 0 x66,
0 x66, 0 x66);
s6e63m0_dcs_write_seq_static(ctx, MCS_GAMMA_DELTA_Y_GREEN,
0 x2c, 0 x12, 0 x0c, 0 x0a, 0 x10, 0 x0e, 0 x17,
0 x13, 0 x1f, 0 x1a, 0 x2a, 0 x24, 0 x1f, 0 x1b,
0 x1a, 0 x17, 0 x2b, 0 x26, 0 x22, 0 x20, 0 x3a,
0 x34, 0 x30, 0 x2c, 0 x29, 0 x26, 0 x25, 0 x23,
0 x21, 0 x20, 0 x1e, 0 x1e);
s6e63m0_dcs_write_seq_static(ctx, MCS_GAMMA_DELTA_X_GREEN,
0 x00, 0 x00, 0 x11, 0 x22, 0 x33, 0 x44, 0 x44,
0 x44, 0 x55, 0 x55, 0 x66, 0 x66, 0 x66, 0 x66,
0 x66, 0 x66);
s6e63m0_dcs_write_seq_static(ctx, MCS_GAMMA_DELTA_Y_BLUE,
0 x2c, 0 x12, 0 x0c, 0 x0a, 0 x10, 0 x0e, 0 x17,
0 x13, 0 x1f, 0 x1a, 0 x2a, 0 x24, 0 x1f, 0 x1b,
0 x1a, 0 x17, 0 x2b, 0 x26, 0 x22, 0 x20, 0 x3a,
0 x34, 0 x30, 0 x2c, 0 x29, 0 x26, 0 x25, 0 x23,
0 x21, 0 x20, 0 x1e, 0 x1e);
s6e63m0_dcs_write_seq_static(ctx, MCS_GAMMA_DELTA_X_BLUE,
0 x00, 0 x00, 0 x11, 0 x22, 0 x33, 0 x44, 0 x44,
0 x44, 0 x55, 0 x55, 0 x66, 0 x66, 0 x66, 0 x66,
0 x66, 0 x66);
s6e63m0_dcs_write_seq_static(ctx, MCS_BCMODE,
0 x4d, 0 x96, 0 x1d, 0 x00, 0 x00, 0 x01, 0 xdf,
0 x00, 0 x00, 0 x03, 0 x1f, 0 x00, 0 x00, 0 x00,
0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x03, 0 x06,
0 x09, 0 x0d, 0 x0f, 0 x12, 0 x15, 0 x18);
s6e63m0_dcs_write_seq_static(ctx, MCS_TEMP_SWIRE,
0 x10, 0 x10, 0 x0b, 0 x05);
s6e63m0_dcs_write_seq_static(ctx, MCS_MIECTL1,
0 x01);
s6e63m0_dcs_write_seq_static(ctx, MCS_ELVSS_ON,
0 x0b);
}
static int s6e63m0_power_on(struct s6e63m0 *ctx)
{
int ret;
ret = regulator_bulk_enable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
if (ret < 0 )
return ret;
msleep(25 );
/* Be sure to send a reset pulse */
gpiod_set_value(ctx->reset_gpio, 1 );
msleep(5 );
gpiod_set_value(ctx->reset_gpio, 0 );
msleep(120 );
return 0 ;
}
static int s6e63m0_power_off(struct s6e63m0 *ctx)
{
int ret;
gpiod_set_value(ctx->reset_gpio, 1 );
msleep(120 );
ret = regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
if (ret < 0 )
return ret;
return 0 ;
}
static int s6e63m0_disable(struct drm_panel *panel)
{
struct s6e63m0 *ctx = panel_to_s6e63m0(panel);
backlight_disable(ctx->bl_dev);
s6e63m0_dcs_write_seq_static(ctx, MIPI_DCS_SET_DISPLAY_OFF);
msleep(10 );
s6e63m0_dcs_write_seq_static(ctx, MIPI_DCS_ENTER_SLEEP_MODE);
msleep(120 );
return 0 ;
}
static int s6e63m0_unprepare(struct drm_panel *panel)
{
struct s6e63m0 *ctx = panel_to_s6e63m0(panel);
int ret;
s6e63m0_clear_error(ctx);
ret = s6e63m0_power_off(ctx);
if (ret < 0 )
return ret;
return 0 ;
}
static int s6e63m0_prepare(struct drm_panel *panel)
{
struct s6e63m0 *ctx = panel_to_s6e63m0(panel);
int ret;
ret = s6e63m0_power_on(ctx);
if (ret < 0 )
return ret;
/* Magic to unlock level 2 control of the display */
s6e63m0_dcs_write_seq_static(ctx, MCS_LEVEL_2_KEY, 0 x5a, 0 x5a);
/* Magic to unlock MTP reading */
s6e63m0_dcs_write_seq_static(ctx, MCS_MTP_KEY, 0 x5a, 0 x5a);
ret = s6e63m0_check_lcd_type(ctx);
if (ret < 0 )
return ret;
s6e63m0_init(ctx);
ret = s6e63m0_clear_error(ctx);
if (ret < 0 )
s6e63m0_unprepare(panel);
return ret;
}
static int s6e63m0_enable(struct drm_panel *panel)
{
struct s6e63m0 *ctx = panel_to_s6e63m0(panel);
s6e63m0_dcs_write_seq_static(ctx, MIPI_DCS_EXIT_SLEEP_MODE);
msleep(120 );
s6e63m0_dcs_write_seq_static(ctx, MIPI_DCS_SET_DISPLAY_ON);
msleep(10 );
s6e63m0_dcs_write_seq_static(ctx, MCS_ERROR_CHECK,
0 xE7, 0 x14, 0 x60, 0 x17, 0 x0A, 0 x49, 0 xC3,
0 x8F, 0 x19, 0 x64, 0 x91, 0 x84, 0 x76, 0 x20,
0 x0F, 0 x00);
backlight_enable(ctx->bl_dev);
return 0 ;
}
static int s6e63m0_get_modes(struct drm_panel *panel,
struct drm_connector *connector)
{
struct drm_display_mode *mode;
static const u32 bus_format = MEDIA_BUS_FMT_RGB888_1X24;
mode = drm_mode_duplicate(connector->dev, &default_mode);
if (!mode) {
dev_err(panel->dev, "failed to add mode %ux%u@%u\n" ,
default_mode.hdisplay, default_mode.vdisplay,
drm_mode_vrefresh(&default_mode));
return -ENOMEM;
}
connector->display_info.width_mm = mode->width_mm;
connector->display_info.height_mm = mode->height_mm;
drm_display_info_set_bus_formats(&connector->display_info,
&bus_format, 1 );
connector->display_info.bus_flags = DRM_BUS_FLAG_DE_LOW |
DRM_BUS_FLAG_PIXDATA_DRIVE_NEGEDGE;
drm_mode_set_name(mode);
mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
drm_mode_probed_add(connector, mode);
return 1 ;
}
static const struct drm_panel_funcs s6e63m0_drm_funcs = {
.disable = s6e63m0_disable,
.unprepare = s6e63m0_unprepare,
.prepare = s6e63m0_prepare,
.enable = s6e63m0_enable,
.get_modes = s6e63m0_get_modes,
};
static int s6e63m0_set_brightness(struct backlight_device *bd)
{
struct s6e63m0 *ctx = bl_get_data(bd);
int brightness = bd->props.brightness;
u8 elvss_val;
u8 elvss_cmd_set[5 ];
int i;
/* Adjust ELVSS to candela level */
i = s6e63m0_elvss_per_gamma[brightness];
elvss_val = ctx->elvss_pulse + s6e63m0_elvss_offsets[i];
if (elvss_val > 0 x1f)
elvss_val = 0 x1f;
elvss_cmd_set[0 ] = MCS_TEMP_SWIRE;
elvss_cmd_set[1 ] = elvss_val;
elvss_cmd_set[2 ] = elvss_val;
elvss_cmd_set[3 ] = elvss_val;
elvss_cmd_set[4 ] = elvss_val;
s6e63m0_dcs_write(ctx, elvss_cmd_set, 5 );
/* Update the ACL per gamma value */
i = s6e63m0_acl_per_gamma[brightness];
s6e63m0_dcs_write(ctx, s6e63m0_acl[i],
ARRAY_SIZE(s6e63m0_acl[i]));
/* Update gamma table */
s6e63m0_dcs_write(ctx, s6e63m0_gamma_22[brightness],
ARRAY_SIZE(s6e63m0_gamma_22[brightness]));
s6e63m0_dcs_write_seq_static(ctx, MCS_PGAMMACTL, 0 x03);
return s6e63m0_clear_error(ctx);
}
static const struct backlight_ops s6e63m0_backlight_ops = {
.update_status = s6e63m0_set_brightness,
};
static int s6e63m0_backlight_register(struct s6e63m0 *ctx, u32 max_brightness)
{
struct backlight_properties props = {
.type = BACKLIGHT_RAW,
.brightness = max_brightness,
.max_brightness = max_brightness,
};
struct device *dev = ctx->dev;
int ret = 0 ;
ctx->bl_dev = devm_backlight_device_register(dev, "panel" , dev, ctx,
&s6e63m0_backlight_ops,
&props);
if (IS_ERR(ctx->bl_dev)) {
ret = PTR_ERR(ctx->bl_dev);
dev_err(dev, "error registering backlight device (%d)\n" , ret);
}
return ret;
}
int s6e63m0_probe(struct device *dev, void *trsp,
int (*dcs_read)(struct device *dev, void *trsp, const u8 cmd, u8 *val),
int (*dcs_write)(struct device *dev, void *trsp, const u8 *data, size_t len),
bool dsi_mode)
{
struct s6e63m0 *ctx;
u32 max_brightness;
int ret;
ctx = devm_kzalloc(dev, sizeof (struct s6e63m0), GFP_KERNEL);
if (!ctx)
return -ENOMEM;
ctx->transport_data = trsp;
ctx->dsi_mode = dsi_mode;
ctx->dcs_read = dcs_read;
ctx->dcs_write = dcs_write;
dev_set_drvdata(dev, ctx);
ctx->dev = dev;
ret = device_property_read_u32(dev, "max-brightness" , &max_brightness);
if (ret)
max_brightness = MAX_BRIGHTNESS;
if (max_brightness > MAX_BRIGHTNESS) {
dev_err(dev, "illegal max brightness specified\n" );
max_brightness = MAX_BRIGHTNESS;
}
ctx->supplies[0 ].supply = "vdd3" ;
ctx->supplies[1 ].supply = "vci" ;
ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(ctx->supplies),
ctx->supplies);
if (ret < 0 ) {
dev_err(dev, "failed to get regulators: %d\n" , ret);
return ret;
}
ctx->reset_gpio = devm_gpiod_get(dev, "reset" , GPIOD_OUT_HIGH);
if (IS_ERR(ctx->reset_gpio)) {
dev_err(dev, "cannot get reset-gpios %ld\n" , PTR_ERR(ctx->reset_gpio));
return PTR_ERR(ctx->reset_gpio);
}
drm_panel_init(&ctx->panel, dev, &s6e63m0_drm_funcs,
dsi_mode ? DRM_MODE_CONNECTOR_DSI :
DRM_MODE_CONNECTOR_DPI);
ret = s6e63m0_backlight_register(ctx, max_brightness);
if (ret < 0 )
return ret;
drm_panel_add(&ctx->panel);
return 0 ;
}
EXPORT_SYMBOL_GPL(s6e63m0_probe);
void s6e63m0_remove(struct device *dev)
{
struct s6e63m0 *ctx = dev_get_drvdata(dev);
drm_panel_remove(&ctx->panel);
}
EXPORT_SYMBOL_GPL(s6e63m0_remove);
MODULE_AUTHOR("Paweł Chmiel <pawel.mikolaj.chmiel@gmail.com>" );
MODULE_DESCRIPTION("s6e63m0 LCD Driver" );
MODULE_LICENSE("GPL v2" );
Messung V0.5 in Prozent C=94 H=92 G=92