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_mipi_dbi.h>
9 #include <drm/drm_print.h>
10
11 #include "panel-samsung-s6e63m0.h"
12
13 static const u8 s6e63m0_dbi_read_commands[] = {
14 MCS_READ_ID1,
15 MCS_READ_ID2,
16 MCS_READ_ID3,
17 0, /* sentinel */
18 };
19
s6e63m0_spi_dcs_read(struct device * dev,void * trsp,const u8 cmd,u8 * data)20 static int s6e63m0_spi_dcs_read(struct device *dev, void *trsp,
21 const u8 cmd, u8 *data)
22 {
23 struct mipi_dbi *dbi = trsp;
24 int ret;
25
26 ret = mipi_dbi_command_read(dbi, cmd, data);
27 if (ret)
28 dev_err(dev, "error on DBI read command %02x\n", cmd);
29
30 return ret;
31 }
32
s6e63m0_spi_dcs_write(struct device * dev,void * trsp,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)
35 {
36 struct mipi_dbi *dbi = trsp;
37 int ret;
38
39 ret = mipi_dbi_command_stackbuf(dbi, data[0], (data + 1), (len - 1));
40 usleep_range(300, 310);
41
42 return ret;
43 }
44
s6e63m0_spi_probe(struct spi_device * spi)45 static int s6e63m0_spi_probe(struct spi_device *spi)
46 {
47 struct device *dev = &spi->dev;
48 struct mipi_dbi *dbi;
49 int ret;
50
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);
63 }
64
s6e63m0_spi_remove(struct spi_device * spi)65 static void s6e63m0_spi_remove(struct spi_device *spi)
66 {
67 s6e63m0_remove(&spi->dev);
68 }
69
70 static const struct of_device_id s6e63m0_spi_of_match[] = {
71 { .compatible = "samsung,s6e63m0" },
72 { /* sentinel */ }
73 };
74 MODULE_DEVICE_TABLE(of, s6e63m0_spi_of_match);
75
76 static struct spi_driver s6e63m0_spi_driver = {
77 .probe = s6e63m0_spi_probe,
78 .remove = s6e63m0_spi_remove,
79 .driver = {
80 .name = "panel-samsung-s6e63m0",
81 .of_match_table = s6e63m0_spi_of_match,
82 },
83 };
84 module_spi_driver(s6e63m0_spi_driver);
85
86 MODULE_AUTHOR("Paweł Chmiel <pawel.mikolaj.chmiel@gmail.com>");
87 MODULE_DESCRIPTION("s6e63m0 LCD SPI Driver");
88 MODULE_LICENSE("GPL v2");
89