1b7b23e44SLinus Walleij // SPDX-License-Identifier: GPL-2.0
2b7b23e44SLinus Walleij
3b7b23e44SLinus Walleij #include <linux/device.h>
4b7b23e44SLinus Walleij #include <linux/module.h>
5b7b23e44SLinus Walleij #include <linux/spi/spi.h>
6b7b23e44SLinus Walleij #include <linux/delay.h>
7b7b23e44SLinus Walleij
8c2a61865SLinus Walleij #include <drm/drm_mipi_dbi.h>
9b7b23e44SLinus Walleij #include <drm/drm_print.h>
10b7b23e44SLinus Walleij
11b7b23e44SLinus Walleij #include "panel-samsung-s6e63m0.h"
12b7b23e44SLinus Walleij
13c2a61865SLinus Walleij static const u8 s6e63m0_dbi_read_commands[] = {
14c2a61865SLinus Walleij MCS_READ_ID1,
15c2a61865SLinus Walleij MCS_READ_ID2,
16c2a61865SLinus Walleij MCS_READ_ID3,
17c2a61865SLinus Walleij 0, /* sentinel */
18c2a61865SLinus Walleij };
19b7b23e44SLinus Walleij
s6e63m0_spi_dcs_read(struct device * dev,void * trsp,const u8 cmd,u8 * data)20c2a61865SLinus Walleij static int s6e63m0_spi_dcs_read(struct device *dev, void *trsp,
21c2a61865SLinus Walleij const u8 cmd, u8 *data)
2291867ac7SLinus Walleij {
23c2a61865SLinus Walleij struct mipi_dbi *dbi = trsp;
241b72ea1eSLinus Walleij int ret;
2591867ac7SLinus Walleij
26c2a61865SLinus Walleij ret = mipi_dbi_command_read(dbi, cmd, data);
27c2a61865SLinus Walleij if (ret)
28c2a61865SLinus Walleij dev_err(dev, "error on DBI read command %02x\n", cmd);
291b72ea1eSLinus Walleij
301b72ea1eSLinus Walleij return ret;
3191867ac7SLinus Walleij }
3291867ac7SLinus Walleij
s6e63m0_spi_dcs_write(struct device * dev,void * trsp,const u8 * data,size_t len)33c2a61865SLinus Walleij static int s6e63m0_spi_dcs_write(struct device *dev, void *trsp,
34c2a61865SLinus Walleij const u8 *data, size_t len)
35b7b23e44SLinus Walleij {
36c2a61865SLinus Walleij struct mipi_dbi *dbi = trsp;
37c2a61865SLinus Walleij int ret;
38b7b23e44SLinus Walleij
39c2a61865SLinus Walleij ret = mipi_dbi_command_stackbuf(dbi, data[0], (data + 1), (len - 1));
40b7b23e44SLinus Walleij usleep_range(300, 310);
41b7b23e44SLinus Walleij
42b7b23e44SLinus Walleij return ret;
43b7b23e44SLinus Walleij }
44b7b23e44SLinus Walleij
s6e63m0_spi_probe(struct spi_device * spi)45b7b23e44SLinus Walleij static int s6e63m0_spi_probe(struct spi_device *spi)
46b7b23e44SLinus Walleij {
47b7b23e44SLinus Walleij struct device *dev = &spi->dev;
48c2a61865SLinus Walleij struct mipi_dbi *dbi;
49b7b23e44SLinus Walleij int ret;
50b7b23e44SLinus Walleij
51c2a61865SLinus Walleij dbi = devm_kzalloc(dev, sizeof(*dbi), GFP_KERNEL);
52c2a61865SLinus Walleij if (!dbi)
53c2a61865SLinus Walleij return -ENOMEM;
54c2a61865SLinus Walleij
55c2a61865SLinus Walleij ret = mipi_dbi_spi_init(spi, dbi, NULL);
56c2a61865SLinus Walleij if (ret)
57c2a61865SLinus Walleij return dev_err_probe(dev, ret, "MIPI DBI init failed\n");
58c2a61865SLinus Walleij /* Register our custom MCS read commands */
59c2a61865SLinus Walleij dbi->read_commands = s6e63m0_dbi_read_commands;
60c2a61865SLinus Walleij
61c2a61865SLinus Walleij return s6e63m0_probe(dev, dbi, s6e63m0_spi_dcs_read,
62c2a61865SLinus Walleij s6e63m0_spi_dcs_write, false);
63b7b23e44SLinus Walleij }
64b7b23e44SLinus Walleij
s6e63m0_spi_remove(struct spi_device * spi)65*a0386bbaSUwe Kleine-König static void s6e63m0_spi_remove(struct spi_device *spi)
66b7b23e44SLinus Walleij {
6790c45fc1SUwe Kleine-König s6e63m0_remove(&spi->dev);
68b7b23e44SLinus Walleij }
69b7b23e44SLinus Walleij
70b7b23e44SLinus Walleij static const struct of_device_id s6e63m0_spi_of_match[] = {
71b7b23e44SLinus Walleij { .compatible = "samsung,s6e63m0" },
72b7b23e44SLinus Walleij { /* sentinel */ }
73b7b23e44SLinus Walleij };
74b7b23e44SLinus Walleij MODULE_DEVICE_TABLE(of, s6e63m0_spi_of_match);
75b7b23e44SLinus Walleij
76b7b23e44SLinus Walleij static struct spi_driver s6e63m0_spi_driver = {
77b7b23e44SLinus Walleij .probe = s6e63m0_spi_probe,
78b7b23e44SLinus Walleij .remove = s6e63m0_spi_remove,
79b7b23e44SLinus Walleij .driver = {
80b7b23e44SLinus Walleij .name = "panel-samsung-s6e63m0",
81b7b23e44SLinus Walleij .of_match_table = s6e63m0_spi_of_match,
82b7b23e44SLinus Walleij },
83b7b23e44SLinus Walleij };
84b7b23e44SLinus Walleij module_spi_driver(s6e63m0_spi_driver);
85b7b23e44SLinus Walleij
86b7b23e44SLinus Walleij MODULE_AUTHOR("Paweł Chmiel <pawel.mikolaj.chmiel@gmail.com>");
87b7b23e44SLinus Walleij MODULE_DESCRIPTION("s6e63m0 LCD SPI Driver");
88b7b23e44SLinus Walleij MODULE_LICENSE("GPL v2");
89