Skip to content

Commit b7b23e4

Browse files
author
Linus Walleij
committed
drm/panel: s6e63m0: Break out SPI transport
This panel can be accessed using both SPI and DSI. To make it possible to probe and use the device also from a DSI bus, first break out the SPI support to its own file. Since all the panel driver does is write DCS commands to the panel, we pass a DCS write function to probe() from each subdriver. We make the Kconfig entry for SPI mode default so all current users will continue to work. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Tested-by: Stephan Gerhold <stephan@gerhold.net> Cc: Paweł Chmiel <pawel.mikolaj.chmiel@gmail.com> Acked-by: Paul Cercueil <paul@crapouillou.net> Link: https://patchwork.freedesktop.org/patch/384873/
1 parent 4c8e84b commit b7b23e4

5 files changed

Lines changed: 124 additions & 70 deletions

File tree

‎drivers/gpu/drm/panel/Kconfig‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,22 @@ config DRM_PANEL_SAMSUNG_S6E63J0X03
324324
select VIDEOMODE_HELPERS
325325

326326
config DRM_PANEL_SAMSUNG_S6E63M0
327-
tristate "Samsung S6E63M0 RGB/SPI panel"
327+
tristate "Samsung S6E63M0 RGB panel"
328328
depends on OF
329-
depends on SPI
330329
depends on BACKLIGHT_CLASS_DEVICE
331330
help
332331
Say Y here if you want to enable support for Samsung S6E63M0
333-
AMOLED LCD panel.
332+
AMOLED LCD panel. This panel can be accessed using SPI or
333+
DSI.
334+
335+
config DRM_PANEL_SAMSUNG_S6E63M0_SPI
336+
tristate "Samsung S6E63M0 RGB SPI interface"
337+
depends on SPI
338+
depends on DRM_PANEL_SAMSUNG_S6E63M0
339+
default DRM_PANEL_SAMSUNG_S6E63M0
340+
help
341+
Say Y here if you want to be able to access the Samsung
342+
S6E63M0 panel using SPI.
334343

335344
config DRM_PANEL_SAMSUNG_S6E88A0_AMS452EF01
336345
tristate "Samsung AMS452EF01 panel with S6E88A0 DSI video mode controller"

‎drivers/gpu/drm/panel/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6D16D0) += panel-samsung-s6d16d0.o
3434
obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E3HA2) += panel-samsung-s6e3ha2.o
3535
obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E63J0X03) += panel-samsung-s6e63j0x03.o
3636
obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E63M0) += panel-samsung-s6e63m0.o
37+
obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E63M0_SPI) += panel-samsung-s6e63m0-spi.o
3738
obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E88A0_AMS452EF01) += panel-samsung-s6e88a0-ams452ef01.o
3839
obj-$(CONFIG_DRM_PANEL_SAMSUNG_S6E8AA0) += panel-samsung-s6e8aa0.o
3940
obj-$(CONFIG_DRM_PANEL_SEIKO_43WVF1G) += panel-seiko-43wvf1g.o
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include <linux/device.h>
4+
#include <linux/module.h>
5+
#include <linux/spi/spi.h>
6+
#include <linux/delay.h>
7+
8+
#include <drm/drm_print.h>
9+
10+
#include "panel-samsung-s6e63m0.h"
11+
12+
#define DATA_MASK 0x100
13+
14+
static int s6e63m0_spi_write_word(struct device *dev, u16 data)
15+
{
16+
struct spi_device *spi = to_spi_device(dev);
17+
struct spi_transfer xfer = {
18+
.len = 2,
19+
.tx_buf = &data,
20+
};
21+
struct spi_message msg;
22+
23+
spi_message_init(&msg);
24+
spi_message_add_tail(&xfer, &msg);
25+
26+
return spi_sync(spi, &msg);
27+
}
28+
29+
static int s6e63m0_spi_dcs_write(struct device *dev, const u8 *data, size_t len)
30+
{
31+
int ret = 0;
32+
33+
DRM_DEV_DEBUG(dev, "SPI writing dcs seq: %*ph\n", (int)len, data);
34+
ret = s6e63m0_spi_write_word(dev, *data);
35+
36+
while (!ret && --len) {
37+
++data;
38+
ret = s6e63m0_spi_write_word(dev, *data | DATA_MASK);
39+
}
40+
41+
if (ret) {
42+
DRM_DEV_ERROR(dev, "SPI error %d writing dcs seq: %*ph\n", ret,
43+
(int)len, data);
44+
}
45+
46+
usleep_range(300, 310);
47+
48+
return ret;
49+
}
50+
51+
static int s6e63m0_spi_probe(struct spi_device *spi)
52+
{
53+
struct device *dev = &spi->dev;
54+
int ret;
55+
56+
spi->bits_per_word = 9;
57+
spi->mode = SPI_MODE_3;
58+
ret = spi_setup(spi);
59+
if (ret < 0) {
60+
DRM_DEV_ERROR(dev, "spi setup failed.\n");
61+
return ret;
62+
}
63+
return s6e63m0_probe(dev, s6e63m0_spi_dcs_write);
64+
}
65+
66+
static int s6e63m0_spi_remove(struct spi_device *spi)
67+
{
68+
return s6e63m0_remove(&spi->dev);
69+
}
70+
71+
static const struct of_device_id s6e63m0_spi_of_match[] = {
72+
{ .compatible = "samsung,s6e63m0" },
73+
{ /* sentinel */ }
74+
};
75+
MODULE_DEVICE_TABLE(of, s6e63m0_spi_of_match);
76+
77+
static struct spi_driver s6e63m0_spi_driver = {
78+
.probe = s6e63m0_spi_probe,
79+
.remove = s6e63m0_spi_remove,
80+
.driver = {
81+
.name = "panel-samsung-s6e63m0",
82+
.of_match_table = s6e63m0_spi_of_match,
83+
},
84+
};
85+
module_spi_driver(s6e63m0_spi_driver);
86+
87+
MODULE_AUTHOR("Paweł Chmiel <pawel.mikolaj.chmiel@gmail.com>");
88+
MODULE_DESCRIPTION("s6e63m0 LCD SPI Driver");
89+
MODULE_LICENSE("GPL v2");

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

Lines changed: 12 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
#include <linux/gpio/consumer.h>
1717
#include <linux/module.h>
1818
#include <linux/regulator/consumer.h>
19-
#include <linux/spi/spi.h>
2019

2120
#include <video/mipi_display.h>
2221

22+
#include "panel-samsung-s6e63m0.h"
23+
2324
/* Manufacturer Command Set */
2425
#define MCS_ELVSS_ON 0xb1
2526
#define MCS_MIECTL1 0xc0
@@ -33,8 +34,6 @@
3334
#define NUM_GAMMA_LEVELS 11
3435
#define GAMMA_TABLE_COUNT 23
3536

36-
#define DATA_MASK 0x100
37-
3837
#define MAX_BRIGHTNESS (NUM_GAMMA_LEVELS - 1)
3938

4039
/* array of gamma tables for gamma value 2.2 */
@@ -87,6 +86,7 @@ static u8 const s6e63m0_gamma_22[NUM_GAMMA_LEVELS][GAMMA_TABLE_COUNT] = {
8786

8887
struct s6e63m0 {
8988
struct device *dev;
89+
int (*dcs_write)(struct device *dev, const u8 *data, size_t len);
9090
struct drm_panel panel;
9191
struct backlight_device *bl_dev;
9292

@@ -134,42 +134,12 @@ static int s6e63m0_clear_error(struct s6e63m0 *ctx)
134134
return ret;
135135
}
136136

137-
static int s6e63m0_spi_write_word(struct s6e63m0 *ctx, u16 data)
138-
{
139-
struct spi_device *spi = to_spi_device(ctx->dev);
140-
struct spi_transfer xfer = {
141-
.len = 2,
142-
.tx_buf = &data,
143-
};
144-
struct spi_message msg;
145-
146-
spi_message_init(&msg);
147-
spi_message_add_tail(&xfer, &msg);
148-
149-
return spi_sync(spi, &msg);
150-
}
151-
152137
static void s6e63m0_dcs_write(struct s6e63m0 *ctx, const u8 *data, size_t len)
153138
{
154-
int ret = 0;
155-
156139
if (ctx->error < 0 || len == 0)
157140
return;
158141

159-
dev_dbg(ctx->dev, "writing dcs seq: %*ph\n", (int)len, data);
160-
ret = s6e63m0_spi_write_word(ctx, *data);
161-
162-
while (!ret && --len) {
163-
++data;
164-
ret = s6e63m0_spi_write_word(ctx, *data | DATA_MASK);
165-
}
166-
167-
if (ret) {
168-
dev_err(ctx->dev, "error %d writing dcs seq: %*ph\n", ret, (int)len, data);
169-
ctx->error = ret;
170-
}
171-
172-
usleep_range(300, 310);
142+
ctx->error = ctx->dcs_write(ctx->dev, data, len);
173143
}
174144

175145
#define s6e63m0_dcs_write_seq_static(ctx, seq ...) \
@@ -429,17 +399,18 @@ static int s6e63m0_backlight_register(struct s6e63m0 *ctx)
429399
return ret;
430400
}
431401

432-
static int s6e63m0_probe(struct spi_device *spi)
402+
int s6e63m0_probe(struct device *dev,
403+
int (*dcs_write)(struct device *dev, const u8 *data, size_t len))
433404
{
434-
struct device *dev = &spi->dev;
435405
struct s6e63m0 *ctx;
436406
int ret;
437407

438408
ctx = devm_kzalloc(dev, sizeof(struct s6e63m0), GFP_KERNEL);
439409
if (!ctx)
440410
return -ENOMEM;
441411

442-
spi_set_drvdata(spi, ctx);
412+
ctx->dcs_write = dcs_write;
413+
dev_set_drvdata(dev, ctx);
443414

444415
ctx->dev = dev;
445416
ctx->enabled = false;
@@ -460,14 +431,6 @@ static int s6e63m0_probe(struct spi_device *spi)
460431
return PTR_ERR(ctx->reset_gpio);
461432
}
462433

463-
spi->bits_per_word = 9;
464-
spi->mode = SPI_MODE_3;
465-
ret = spi_setup(spi);
466-
if (ret < 0) {
467-
dev_err(dev, "spi setup failed.\n");
468-
return ret;
469-
}
470-
471434
drm_panel_init(&ctx->panel, dev, &s6e63m0_drm_funcs,
472435
DRM_MODE_CONNECTOR_DPI);
473436

@@ -479,32 +442,14 @@ static int s6e63m0_probe(struct spi_device *spi)
479442

480443
return 0;
481444
}
445+
EXPORT_SYMBOL_GPL(s6e63m0_probe);
482446

483-
static int s6e63m0_remove(struct spi_device *spi)
447+
int s6e63m0_remove(struct device *dev)
484448
{
485-
struct s6e63m0 *ctx = spi_get_drvdata(spi);
449+
struct s6e63m0 *ctx = dev_get_drvdata(dev);
486450

487451
drm_panel_remove(&ctx->panel);
488452

489453
return 0;
490454
}
491-
492-
static const struct of_device_id s6e63m0_of_match[] = {
493-
{ .compatible = "samsung,s6e63m0" },
494-
{ /* sentinel */ }
495-
};
496-
MODULE_DEVICE_TABLE(of, s6e63m0_of_match);
497-
498-
static struct spi_driver s6e63m0_driver = {
499-
.probe = s6e63m0_probe,
500-
.remove = s6e63m0_remove,
501-
.driver = {
502-
.name = "panel-samsung-s6e63m0",
503-
.of_match_table = s6e63m0_of_match,
504-
},
505-
};
506-
module_spi_driver(s6e63m0_driver);
507-
508-
MODULE_AUTHOR("Paweł Chmiel <pawel.mikolaj.chmiel@gmail.com>");
509-
MODULE_DESCRIPTION("s6e63m0 LCD Driver");
510-
MODULE_LICENSE("GPL v2");
455+
EXPORT_SYMBOL_GPL(s6e63m0_remove);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
#ifndef _PANEL_SAMSUNG_S6E63M0_H
4+
#define _PANEL_SAMSUNG_S6E63M0_H
5+
6+
int s6e63m0_probe(struct device *dev,
7+
int (*dcs_write)(struct device *dev, const u8 *data, size_t len));
8+
int s6e63m0_remove(struct device *dev);
9+
10+
#endif /* _PANEL_SAMSUNG_S6E63M0_H */

0 commit comments

Comments
 (0)