1 // SPDX-License-Identifier: GPL-2.0
3 #include <linux/device.h>
4 #include <linux/module.h>
5 #include <linux/spi/spi.h>
6 #include <linux/delay.h>
8 #include <drm/drm_print.h>
10 #include "panel-samsung-s6e63m0.h"
12 #define DATA_MASK 0x100
14 static int s6e63m0_spi_dcs_read(struct device
*dev
, const u8 cmd
, u8
*data
)
16 struct spi_device
*spi
= to_spi_device(dev
);
21 /* SPI buffers are always in CPU order */
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]);
26 /* These high 8 bits of the 9 contains the readout */
27 *data
= (rbuf
[0] & 0x1ff) >> 1;
32 static int s6e63m0_spi_write_word(struct device
*dev
, u16 data
)
34 struct spi_device
*spi
= to_spi_device(dev
);
36 /* SPI buffers are always in CPU order */
37 return spi_write(spi
, &data
, 2);
40 static int s6e63m0_spi_dcs_write(struct device
*dev
, const u8
*data
, size_t len
)
44 dev_dbg(dev
, "SPI writing dcs seq: %*ph\n", (int)len
, data
);
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
51 ret
= s6e63m0_spi_write_word(dev
, *data
);
53 while (!ret
&& --len
) {
55 /* This sends 9 bits with the first bit (bit 8) set to 1 */
56 ret
= s6e63m0_spi_write_word(dev
, *data
| DATA_MASK
);
60 dev_err(dev
, "SPI error %d writing dcs seq: %*ph\n", ret
,
64 usleep_range(300, 310);
69 static int s6e63m0_spi_probe(struct spi_device
*spi
)
71 struct device
*dev
= &spi
->dev
;
74 spi
->bits_per_word
= 9;
75 /* Preserve e.g. SPI_3WIRE setting */
76 spi
->mode
|= SPI_MODE_3
;
79 dev_err(dev
, "spi setup failed.\n");
82 return s6e63m0_probe(dev
, s6e63m0_spi_dcs_read
, s6e63m0_spi_dcs_write
,
86 static int s6e63m0_spi_remove(struct spi_device
*spi
)
88 return s6e63m0_remove(&spi
->dev
);
91 static const struct of_device_id s6e63m0_spi_of_match
[] = {
92 { .compatible
= "samsung,s6e63m0" },
95 MODULE_DEVICE_TABLE(of
, s6e63m0_spi_of_match
);
97 static struct spi_driver s6e63m0_spi_driver
= {
98 .probe
= s6e63m0_spi_probe
,
99 .remove
= s6e63m0_spi_remove
,
101 .name
= "panel-samsung-s6e63m0",
102 .of_match_table
= s6e63m0_spi_of_match
,
105 module_spi_driver(s6e63m0_spi_driver
);
107 MODULE_AUTHOR("Paweł Chmiel <pawel.mikolaj.chmiel@gmail.com>");
108 MODULE_DESCRIPTION("s6e63m0 LCD SPI Driver");
109 MODULE_LICENSE("GPL v2");