Skip to content

Commit c2a6186

Browse files
committed
drm/panel: s6e63m0: Switch to DBI abstraction for SPI
The SPI access to s6e63m0 is using the DBI protocol, so switch to using the elaborate DBI protocol implementation in the DRM DBI helper library. Acked-by: Noralf Trønnes <[email protected]> Reviewed-by: Douglas Anderson <[email protected]> Signed-off-by: Linus Walleij <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 413f52f commit c2a6186

File tree

5 files changed

+77
-91
lines changed

5 files changed

+77
-91
lines changed

drivers/gpu/drm/panel/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ config DRM_PANEL_SAMSUNG_S6E63M0_SPI
388388
depends on SPI
389389
depends on DRM_PANEL_SAMSUNG_S6E63M0
390390
default DRM_PANEL_SAMSUNG_S6E63M0
391+
select DRM_MIPI_DBI
391392
help
392393
Say Y here if you want to be able to access the Samsung
393394
S6E63M0 panel using SPI.

drivers/gpu/drm/panel/panel-samsung-s6e63m0-dsi.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
#define MCS_GLOBAL_PARAM 0xb0
1717
#define S6E63M0_DSI_MAX_CHUNK 15 /* CMD + 15 bytes max */
1818

19-
static int s6e63m0_dsi_dcs_read(struct device *dev, const u8 cmd, u8 *data)
19+
static int s6e63m0_dsi_dcs_read(struct device *dev, void *trsp,
20+
const u8 cmd, u8 *data)
2021
{
2122
struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
2223
int ret;
@@ -32,7 +33,8 @@ static int s6e63m0_dsi_dcs_read(struct device *dev, const u8 cmd, u8 *data)
3233
return 0;
3334
}
3435

35-
static int s6e63m0_dsi_dcs_write(struct device *dev, const u8 *data, size_t len)
36+
static int s6e63m0_dsi_dcs_write(struct device *dev, void *trsp,
37+
const u8 *data, size_t len)
3638
{
3739
struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);
3840
const u8 *seqp = data;
@@ -99,8 +101,8 @@ static int s6e63m0_dsi_probe(struct mipi_dsi_device *dsi)
99101
dsi->mode_flags = MIPI_DSI_MODE_VIDEO |
100102
MIPI_DSI_MODE_VIDEO_BURST;
101103

102-
ret = s6e63m0_probe(dev, s6e63m0_dsi_dcs_read, s6e63m0_dsi_dcs_write,
103-
true);
104+
ret = s6e63m0_probe(dev, NULL, s6e63m0_dsi_dcs_read,
105+
s6e63m0_dsi_dcs_write, true);
104106
if (ret)
105107
return ret;
106108

drivers/gpu/drm/panel/panel-samsung-s6e63m0-spi.c

Lines changed: 31 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,62 +5,38 @@
55
#include <linux/spi/spi.h>
66
#include <linux/delay.h>
77

8+
#include <drm/drm_mipi_dbi.h>
89
#include <drm/drm_print.h>
910

1011
#include "panel-samsung-s6e63m0.h"
1112

12-
#define DATA_MASK 0x100
13+
static const u8 s6e63m0_dbi_read_commands[] = {
14+
MCS_READ_ID1,
15+
MCS_READ_ID2,
16+
MCS_READ_ID3,
17+
0, /* sentinel */
18+
};
1319

14-
static int s6e63m0_spi_dcs_read(struct device *dev, const u8 cmd, u8 *data)
20+
static int s6e63m0_spi_dcs_read(struct device *dev, void *trsp,
21+
const u8 cmd, u8 *data)
1522
{
16-
struct spi_device *spi = to_spi_device(dev);
17-
u16 buf[1];
18-
u16 rbuf[1];
23+
struct mipi_dbi *dbi = trsp;
1924
int ret;
2025

21-
/* SPI buffers are always in CPU order */
22-
buf[0] = (u16)cmd;
23-
ret = spi_write_then_read(spi, buf, 2, rbuf, 2);
24-
dev_dbg(dev, "READ CMD: %04x RET: %04x\n", buf[0], rbuf[0]);
25-
if (!ret)
26-
/* These high 8 bits of the 9 contains the readout */
27-
*data = (rbuf[0] & 0x1ff) >> 1;
26+
ret = mipi_dbi_command_read(dbi, cmd, data);
27+
if (ret)
28+
dev_err(dev, "error on DBI read command %02x\n", cmd);
2829

2930
return ret;
3031
}
3132

32-
static int s6e63m0_spi_write_word(struct device *dev, u16 data)
33-
{
34-
struct spi_device *spi = to_spi_device(dev);
35-
36-
/* SPI buffers are always in CPU order */
37-
return spi_write(spi, &data, 2);
38-
}
39-
40-
static int s6e63m0_spi_dcs_write(struct device *dev, const u8 *data, size_t len)
33+
static int s6e63m0_spi_dcs_write(struct device *dev, void *trsp,
34+
const u8 *data, size_t len)
4135
{
42-
int ret = 0;
43-
44-
dev_dbg(dev, "SPI writing dcs seq: %*ph\n", (int)len, data);
45-
46-
/*
47-
* This sends 9 bits with the first bit (bit 8) set to 0
48-
* This indicates that this is a command. Anything after the
49-
* command is data.
50-
*/
51-
ret = s6e63m0_spi_write_word(dev, *data);
52-
53-
while (!ret && --len) {
54-
++data;
55-
/* This sends 9 bits with the first bit (bit 8) set to 1 */
56-
ret = s6e63m0_spi_write_word(dev, *data | DATA_MASK);
57-
}
58-
59-
if (ret) {
60-
dev_err(dev, "SPI error %d writing dcs seq: %*ph\n", ret,
61-
(int)len, data);
62-
}
36+
struct mipi_dbi *dbi = trsp;
37+
int ret;
6338

39+
ret = mipi_dbi_command_stackbuf(dbi, data[0], (data + 1), (len - 1));
6440
usleep_range(300, 310);
6541

6642
return ret;
@@ -69,18 +45,21 @@ static int s6e63m0_spi_dcs_write(struct device *dev, const u8 *data, size_t len)
6945
static int s6e63m0_spi_probe(struct spi_device *spi)
7046
{
7147
struct device *dev = &spi->dev;
48+
struct mipi_dbi *dbi;
7249
int ret;
7350

74-
spi->bits_per_word = 9;
75-
/* Preserve e.g. SPI_3WIRE setting */
76-
spi->mode |= SPI_MODE_3;
77-
ret = spi_setup(spi);
78-
if (ret < 0) {
79-
dev_err(dev, "spi setup failed.\n");
80-
return ret;
81-
}
82-
return s6e63m0_probe(dev, s6e63m0_spi_dcs_read, s6e63m0_spi_dcs_write,
83-
false);
51+
dbi = devm_kzalloc(dev, sizeof(*dbi), GFP_KERNEL);
52+
if (!dbi)
53+
return -ENOMEM;
54+
55+
ret = mipi_dbi_spi_init(spi, dbi, NULL);
56+
if (ret)
57+
return dev_err_probe(dev, ret, "MIPI DBI init failed\n");
58+
/* Register our custom MCS read commands */
59+
dbi->read_commands = s6e63m0_dbi_read_commands;
60+
61+
return s6e63m0_probe(dev, dbi, s6e63m0_spi_dcs_read,
62+
s6e63m0_spi_dcs_write, false);
8463
}
8564

8665
static int s6e63m0_spi_remove(struct spi_device *spi)

drivers/gpu/drm/panel/panel-samsung-s6e63m0.c

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,6 @@
2222

2323
#include "panel-samsung-s6e63m0.h"
2424

25-
/* Manufacturer Command Set */
26-
#define MCS_ELVSS_ON 0xb1
27-
#define MCS_TEMP_SWIRE 0xb2
28-
#define MCS_PENTILE_1 0xb3
29-
#define MCS_PENTILE_2 0xb4
30-
#define MCS_GAMMA_DELTA_Y_RED 0xb5
31-
#define MCS_GAMMA_DELTA_X_RED 0xb6
32-
#define MCS_GAMMA_DELTA_Y_GREEN 0xb7
33-
#define MCS_GAMMA_DELTA_X_GREEN 0xb8
34-
#define MCS_GAMMA_DELTA_Y_BLUE 0xb9
35-
#define MCS_GAMMA_DELTA_X_BLUE 0xba
36-
#define MCS_MIECTL1 0xc0
37-
#define MCS_BCMODE 0xc1
38-
#define MCS_ERROR_CHECK 0xd5
39-
#define MCS_READ_ID1 0xda
40-
#define MCS_READ_ID2 0xdb
41-
#define MCS_READ_ID3 0xdc
42-
#define MCS_LEVEL_2_KEY 0xf0
43-
#define MCS_MTP_KEY 0xf1
44-
#define MCS_DISCTL 0xf2
45-
#define MCS_SRCCTL 0xf6
46-
#define MCS_IFCTL 0xf7
47-
#define MCS_PANELCTL 0xf8
48-
#define MCS_PGAMMACTL 0xfa
49-
5025
#define S6E63M0_LCD_ID_VALUE_M2 0xA4
5126
#define S6E63M0_LCD_ID_VALUE_SM2 0xB4
5227
#define S6E63M0_LCD_ID_VALUE_SM2_1 0xB6
@@ -283,8 +258,9 @@ static u8 const s6e63m0_elvss_per_gamma[NUM_GAMMA_LEVELS] = {
283258

284259
struct s6e63m0 {
285260
struct device *dev;
286-
int (*dcs_read)(struct device *dev, const u8 cmd, u8 *val);
287-
int (*dcs_write)(struct device *dev, const u8 *data, size_t len);
261+
void *transport_data;
262+
int (*dcs_read)(struct device *dev, void *trsp, const u8 cmd, u8 *val);
263+
int (*dcs_write)(struct device *dev, void *trsp, const u8 *data, size_t len);
288264
struct drm_panel panel;
289265
struct backlight_device *bl_dev;
290266
u8 lcd_type;
@@ -340,15 +316,15 @@ static void s6e63m0_dcs_read(struct s6e63m0 *ctx, const u8 cmd, u8 *data)
340316
if (ctx->error < 0)
341317
return;
342318

343-
ctx->error = ctx->dcs_read(ctx->dev, cmd, data);
319+
ctx->error = ctx->dcs_read(ctx->dev, ctx->transport_data, cmd, data);
344320
}
345321

346322
static void s6e63m0_dcs_write(struct s6e63m0 *ctx, const u8 *data, size_t len)
347323
{
348324
if (ctx->error < 0 || len == 0)
349325
return;
350326

351-
ctx->error = ctx->dcs_write(ctx->dev, data, len);
327+
ctx->error = ctx->dcs_write(ctx->dev, ctx->transport_data, data, len);
352328
}
353329

354330
#define s6e63m0_dcs_write_seq_static(ctx, seq ...) \
@@ -713,9 +689,9 @@ static int s6e63m0_backlight_register(struct s6e63m0 *ctx, u32 max_brightness)
713689
return ret;
714690
}
715691

716-
int s6e63m0_probe(struct device *dev,
717-
int (*dcs_read)(struct device *dev, const u8 cmd, u8 *val),
718-
int (*dcs_write)(struct device *dev, const u8 *data, size_t len),
692+
int s6e63m0_probe(struct device *dev, void *trsp,
693+
int (*dcs_read)(struct device *dev, void *trsp, const u8 cmd, u8 *val),
694+
int (*dcs_write)(struct device *dev, void *trsp, const u8 *data, size_t len),
719695
bool dsi_mode)
720696
{
721697
struct s6e63m0 *ctx;
@@ -726,6 +702,7 @@ int s6e63m0_probe(struct device *dev,
726702
if (!ctx)
727703
return -ENOMEM;
728704

705+
ctx->transport_data = trsp;
729706
ctx->dsi_mode = dsi_mode;
730707
ctx->dcs_read = dcs_read;
731708
ctx->dcs_write = dcs_write;

drivers/gpu/drm/panel/panel-samsung-s6e63m0.h

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,36 @@
33
#ifndef _PANEL_SAMSUNG_S6E63M0_H
44
#define _PANEL_SAMSUNG_S6E63M0_H
55

6-
int s6e63m0_probe(struct device *dev,
7-
int (*dcs_read)(struct device *dev, const u8 cmd, u8 *val),
8-
int (*dcs_write)(struct device *dev, const u8 *data,
6+
/* Manufacturer Command Set */
7+
#define MCS_ELVSS_ON 0xb1
8+
#define MCS_TEMP_SWIRE 0xb2
9+
#define MCS_PENTILE_1 0xb3
10+
#define MCS_PENTILE_2 0xb4
11+
#define MCS_GAMMA_DELTA_Y_RED 0xb5
12+
#define MCS_GAMMA_DELTA_X_RED 0xb6
13+
#define MCS_GAMMA_DELTA_Y_GREEN 0xb7
14+
#define MCS_GAMMA_DELTA_X_GREEN 0xb8
15+
#define MCS_GAMMA_DELTA_Y_BLUE 0xb9
16+
#define MCS_GAMMA_DELTA_X_BLUE 0xba
17+
#define MCS_MIECTL1 0xc0
18+
#define MCS_BCMODE 0xc1
19+
#define MCS_ERROR_CHECK 0xd5
20+
#define MCS_READ_ID1 0xda
21+
#define MCS_READ_ID2 0xdb
22+
#define MCS_READ_ID3 0xdc
23+
#define MCS_LEVEL_2_KEY 0xf0
24+
#define MCS_MTP_KEY 0xf1
25+
#define MCS_DISCTL 0xf2
26+
#define MCS_SRCCTL 0xf6
27+
#define MCS_IFCTL 0xf7
28+
#define MCS_PANELCTL 0xf8
29+
#define MCS_PGAMMACTL 0xfa
30+
31+
int s6e63m0_probe(struct device *dev, void *trsp,
32+
int (*dcs_read)(struct device *dev, void *trsp,
33+
const u8 cmd, u8 *val),
34+
int (*dcs_write)(struct device *dev, void *trsp,
35+
const u8 *data,
936
size_t len),
1037
bool dsi_mode);
1138
int s6e63m0_remove(struct device *dev);

0 commit comments

Comments
 (0)