1 // SPDX-License-Identifier: GPL-2.0+
4 * Copyright (C) 2013, Noralf Tronnes
7 #define pr_fmt(fmt) "fbtft_device: " fmt
8 #include <linux/module.h>
9 #include <linux/kernel.h>
10 #include <linux/init.h>
11 #include <linux/gpio.h>
12 #include <linux/spi/spi.h>
13 #include <video/mipi_display.h>
19 static struct spi_device *spi_device;
20 static struct platform_device *p_device;
23 module_param(name, charp, 0000);
24 MODULE_PARM_DESC(name,
25 "Devicename (required). name=list => list all supported devices.");
27 static unsigned int rotate;
28 module_param(rotate, uint, 0000);
29 MODULE_PARM_DESC(rotate,
30 "Angle to rotate display counter clockwise: 0, 90, 180, 270");
32 static unsigned int busnum;
33 module_param(busnum, uint, 0000);
34 MODULE_PARM_DESC(busnum, "SPI bus number (default=0)");
36 static unsigned int cs;
37 module_param(cs, uint, 0000);
38 MODULE_PARM_DESC(cs, "SPI chip select (default=0)");
40 static unsigned int speed;
41 module_param(speed, uint, 0000);
42 MODULE_PARM_DESC(speed, "SPI speed (override device default)");
45 module_param(mode, int, 0000);
46 MODULE_PARM_DESC(mode, "SPI mode (override device default)");
49 module_param(gpios, charp, 0000);
50 MODULE_PARM_DESC(gpios,
51 "List of gpios. Comma separated with the form: reset:23,dc:24 (when overriding the default, all gpios must be specified)");
53 static unsigned int fps;
54 module_param(fps, uint, 0000);
55 MODULE_PARM_DESC(fps, "Frames per second (override driver default)");
58 module_param(gamma, charp, 0000);
59 MODULE_PARM_DESC(gamma,
60 "String representation of Gamma Curve(s). Driver specific.");
63 module_param(txbuflen, int, 0000);
64 MODULE_PARM_DESC(txbuflen, "txbuflen (override driver default)");
67 module_param(bgr, int, 0000);
69 "BGR bit (supported by some drivers).");
71 static unsigned int startbyte;
72 module_param(startbyte, uint, 0000);
73 MODULE_PARM_DESC(startbyte, "Sets the Start byte used by some SPI displays.");
76 module_param(custom, bool, 0000);
77 MODULE_PARM_DESC(custom, "Add a custom display device. Use speed= argument to make it a SPI device, else platform_device");
79 static unsigned int width;
80 module_param(width, uint, 0000);
81 MODULE_PARM_DESC(width, "Display width, used with the custom argument");
83 static unsigned int height;
84 module_param(height, uint, 0000);
85 MODULE_PARM_DESC(height, "Display height, used with the custom argument");
87 static unsigned int buswidth = 8;
88 module_param(buswidth, uint, 0000);
89 MODULE_PARM_DESC(buswidth, "Display bus width, used with the custom argument");
91 static s16 init[FBTFT_MAX_INIT_SEQUENCE];
93 module_param_array(init, short, &init_num, 0000);
94 MODULE_PARM_DESC(init, "Init sequence, used with the custom argument");
96 static unsigned long debug;
97 module_param(debug, ulong, 0000);
98 MODULE_PARM_DESC(debug,
99 "level: 0-7 (the remaining 29 bits is for advanced usage)");
101 static unsigned int verbose = 3;
102 module_param(verbose, uint, 0000);
103 MODULE_PARM_DESC(verbose,
104 "0 silent, >0 show gpios, >1 show devices, >2 show devices before (default=3)");
106 struct fbtft_device_display {
108 struct spi_board_info *spi;
109 struct platform_device *pdev;
112 static void fbtft_device_pdev_release(struct device *dev);
114 static int write_gpio16_wr_slow(struct fbtft_par *par, void *buf, size_t len);
115 static void adafruit18_green_tab_set_addr_win(struct fbtft_par *par,
116 int xs, int ys, int xe, int ye);
118 #define ADAFRUIT18_GAMMA \
119 "02 1c 07 12 37 32 29 2d 29 25 2B 39 00 01 03 10\n" \
120 "03 1d 07 06 2E 2C 29 2D 2E 2E 37 3F 00 00 02 10"
122 #define CBERRY28_GAMMA \
123 "D0 00 14 15 13 2C 42 43 4E 09 16 14 18 21\n" \
124 "D0 00 14 15 13 0B 43 55 53 0C 17 14 23 20"
126 static const s16 cberry28_init_sequence[] = {
127 /* turn off sleep mode */
128 -1, MIPI_DCS_EXIT_SLEEP_MODE,
131 /* set pixel format to RGB-565 */
132 -1, MIPI_DCS_SET_PIXEL_FORMAT, MIPI_DCS_PIXEL_FMT_16BIT,
134 -1, 0xB2, 0x0C, 0x0C, 0x00, 0x33, 0x33,
143 * VDV and VRH register values come from command write
146 -1, 0xC2, 0x01, 0xFF,
149 * VAP = 4.7V + (VCOM + VCOM offset + 0.5 * VDV)
150 * VAN = -4.7V + (VCOM + VCOM offset + 0.5 * VDV)
160 /* VCOM offset = 0V */
168 -1, 0xD0, 0xA4, 0xA1,
170 -1, MIPI_DCS_SET_DISPLAY_ON,
175 static const s16 hy28b_init_sequence[] = {
176 -1, 0x00e7, 0x0010, -1, 0x0000, 0x0001,
177 -1, 0x0001, 0x0100, -1, 0x0002, 0x0700,
178 -1, 0x0003, 0x1030, -1, 0x0004, 0x0000,
179 -1, 0x0008, 0x0207, -1, 0x0009, 0x0000,
180 -1, 0x000a, 0x0000, -1, 0x000c, 0x0001,
181 -1, 0x000d, 0x0000, -1, 0x000f, 0x0000,
182 -1, 0x0010, 0x0000, -1, 0x0011, 0x0007,
183 -1, 0x0012, 0x0000, -1, 0x0013, 0x0000,
184 -2, 50, -1, 0x0010, 0x1590, -1, 0x0011,
185 0x0227, -2, 50, -1, 0x0012, 0x009c, -2, 50,
186 -1, 0x0013, 0x1900, -1, 0x0029, 0x0023,
187 -1, 0x002b, 0x000e, -2, 50,
188 -1, 0x0020, 0x0000, -1, 0x0021, 0x0000,
189 -2, 50, -1, 0x0050, 0x0000,
190 -1, 0x0051, 0x00ef, -1, 0x0052, 0x0000,
191 -1, 0x0053, 0x013f, -1, 0x0060, 0xa700,
192 -1, 0x0061, 0x0001, -1, 0x006a, 0x0000,
193 -1, 0x0080, 0x0000, -1, 0x0081, 0x0000,
194 -1, 0x0082, 0x0000, -1, 0x0083, 0x0000,
195 -1, 0x0084, 0x0000, -1, 0x0085, 0x0000,
196 -1, 0x0090, 0x0010, -1, 0x0092, 0x0000,
197 -1, 0x0093, 0x0003, -1, 0x0095, 0x0110,
198 -1, 0x0097, 0x0000, -1, 0x0098, 0x0000,
199 -1, 0x0007, 0x0133, -1, 0x0020, 0x0000,
200 -1, 0x0021, 0x0000, -2, 100, -3 };
202 #define HY28B_GAMMA \
203 "04 1F 4 7 7 0 7 7 6 0\n" \
204 "0F 00 1 7 4 0 0 0 6 7"
206 static const s16 pitft_init_sequence[] = {
207 -1, MIPI_DCS_SOFT_RESET,
209 -1, MIPI_DCS_SET_DISPLAY_OFF,
210 -1, 0xEF, 0x03, 0x80, 0x02,
211 -1, 0xCF, 0x00, 0xC1, 0x30,
212 -1, 0xED, 0x64, 0x03, 0x12, 0x81,
213 -1, 0xE8, 0x85, 0x00, 0x78,
214 -1, 0xCB, 0x39, 0x2C, 0x00, 0x34, 0x02,
216 -1, 0xEA, 0x00, 0x00,
219 -1, 0xC5, 0x3E, 0x28,
221 -1, MIPI_DCS_SET_PIXEL_FORMAT, 0x55,
222 -1, 0xB1, 0x00, 0x18,
223 -1, 0xB6, 0x08, 0x82, 0x27,
225 -1, MIPI_DCS_SET_GAMMA_CURVE, 0x01,
226 -1, 0xE0, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E,
227 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00,
228 -1, 0xE1, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31,
229 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F,
230 -1, MIPI_DCS_EXIT_SLEEP_MODE,
232 -1, MIPI_DCS_SET_DISPLAY_ON,
237 static const s16 waveshare32b_init_sequence[] = {
238 -1, 0xCB, 0x39, 0x2C, 0x00, 0x34, 0x02,
239 -1, 0xCF, 0x00, 0xC1, 0x30,
240 -1, 0xE8, 0x85, 0x00, 0x78,
241 -1, 0xEA, 0x00, 0x00,
242 -1, 0xED, 0x64, 0x03, 0x12, 0x81,
246 -1, 0xC5, 0x3E, 0x28,
248 -1, MIPI_DCS_SET_ADDRESS_MODE, 0x28,
249 -1, MIPI_DCS_SET_PIXEL_FORMAT, 0x55,
250 -1, 0xB1, 0x00, 0x18,
251 -1, 0xB6, 0x08, 0x82, 0x27,
253 -1, MIPI_DCS_SET_GAMMA_CURVE, 0x01,
254 -1, 0xE0, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E,
255 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00,
256 -1, 0xE1, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31,
257 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F,
258 -1, MIPI_DCS_EXIT_SLEEP_MODE,
260 -1, MIPI_DCS_SET_DISPLAY_ON,
261 -1, MIPI_DCS_WRITE_MEMORY_START,
265 #define PIOLED_GAMMA "0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 " \
266 "2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 " \
267 "3 3 3 4 4 4 4 4 4 4 4 4 4 4 4"
269 /* Supported displays in alphabetical order */
270 static struct fbtft_device_display displays[] = {
272 .name = "adafruit18",
273 .spi = &(struct spi_board_info) {
274 .modalias = "fb_st7735r",
275 .max_speed_hz = 32000000,
277 .platform_data = &(struct fbtft_platform_data) {
282 .gpios = (const struct fbtft_gpio []) {
288 .gamma = ADAFRUIT18_GAMMA,
292 .name = "adafruit18_green",
293 .spi = &(struct spi_board_info) {
294 .modalias = "fb_st7735r",
295 .max_speed_hz = 4000000,
297 .platform_data = &(struct fbtft_platform_data) {
301 .fbtftops.set_addr_win =
302 adafruit18_green_tab_set_addr_win,
305 .gpios = (const struct fbtft_gpio []) {
311 .gamma = ADAFRUIT18_GAMMA,
315 .name = "adafruit22",
316 .spi = &(struct spi_board_info) {
317 .modalias = "fb_hx8340bn",
318 .max_speed_hz = 32000000,
320 .platform_data = &(struct fbtft_platform_data) {
326 .gpios = (const struct fbtft_gpio []) {
334 .name = "adafruit22a",
335 .spi = &(struct spi_board_info) {
336 .modalias = "fb_ili9340",
337 .max_speed_hz = 32000000,
339 .platform_data = &(struct fbtft_platform_data) {
345 .gpios = (const struct fbtft_gpio []) {
354 .name = "adafruit28",
355 .spi = &(struct spi_board_info) {
356 .modalias = "fb_ili9341",
357 .max_speed_hz = 32000000,
359 .platform_data = &(struct fbtft_platform_data) {
365 .gpios = (const struct fbtft_gpio []) {
374 .name = "adafruit13m",
375 .spi = &(struct spi_board_info) {
376 .modalias = "fb_ssd1306",
377 .max_speed_hz = 16000000,
379 .platform_data = &(struct fbtft_platform_data) {
383 .gpios = (const struct fbtft_gpio []) {
391 .name = "admatec_c-berry28",
392 .spi = &(struct spi_board_info) {
393 .modalias = "fb_st7789v",
394 .max_speed_hz = 48000000,
396 .platform_data = &(struct fbtft_platform_data) {
400 .init_sequence = cberry28_init_sequence,
402 .gpios = (const struct fbtft_gpio []) {
408 .gamma = CBERRY28_GAMMA,
412 .name = "agm1264k-fl",
413 .pdev = &(struct platform_device) {
414 .name = "fb_agm1264k-fl",
417 .release = fbtft_device_pdev_release,
418 .platform_data = &(struct fbtft_platform_data) {
421 .backlight = FBTFT_ONBOARD_BACKLIGHT,
423 .gpios = (const struct fbtft_gpio []) {
431 .spi = &(struct spi_board_info) {
432 .modalias = "fb_uc1701",
433 .max_speed_hz = 8000000,
435 .platform_data = &(struct fbtft_platform_data) {
440 .gpios = (const struct fbtft_gpio []) {
448 .name = "er_tftm050_2",
449 .spi = &(struct spi_board_info) {
450 .modalias = "fb_ra8875",
451 .max_speed_hz = 5000000,
453 .platform_data = &(struct fbtft_platform_data) {
461 .gpios = (const struct fbtft_gpio []) {
469 .name = "er_tftm070_5",
470 .spi = &(struct spi_board_info) {
471 .modalias = "fb_ra8875",
472 .max_speed_hz = 5000000,
474 .platform_data = &(struct fbtft_platform_data) {
482 .gpios = (const struct fbtft_gpio []) {
491 .spi = &(struct spi_board_info) {
492 .modalias = "fb_uc1611",
493 .max_speed_hz = 32000000,
495 .platform_data = &(struct fbtft_platform_data) {
499 .gpios = (const struct fbtft_gpio []) {
506 .name = "ew24ha0_9bit",
507 .spi = &(struct spi_board_info) {
508 .modalias = "fb_uc1611",
509 .max_speed_hz = 32000000,
511 .platform_data = &(struct fbtft_platform_data) {
515 .gpios = (const struct fbtft_gpio []) {
522 .spi = &(struct spi_board_info) {
523 .modalias = "flexfb",
524 .max_speed_hz = 32000000,
526 .platform_data = &(struct fbtft_platform_data) {
527 .gpios = (const struct fbtft_gpio []) {
536 .pdev = &(struct platform_device) {
540 .release = fbtft_device_pdev_release,
541 .platform_data = &(struct fbtft_platform_data) {
542 .gpios = (const struct fbtft_gpio []) {
562 .name = "freetronicsoled128",
563 .spi = &(struct spi_board_info) {
564 .modalias = "fb_ssd1351",
565 .max_speed_hz = 20000000,
567 .platform_data = &(struct fbtft_platform_data) {
570 .backlight = FBTFT_ONBOARD_BACKLIGHT,
573 .gpios = (const struct fbtft_gpio []) {
582 .spi = &(struct spi_board_info) {
583 .modalias = "fb_hx8353d",
584 .max_speed_hz = 16000000,
586 .platform_data = &(struct fbtft_platform_data) {
591 .gpios = (const struct fbtft_gpio []) {
601 .spi = &(struct spi_board_info) {
602 .modalias = "fb_ili9320",
603 .max_speed_hz = 32000000,
605 .platform_data = &(struct fbtft_platform_data) {
612 .gpios = (const struct fbtft_gpio []) {
621 .spi = &(struct spi_board_info) {
622 .modalias = "fb_ili9325",
623 .max_speed_hz = 48000000,
625 .platform_data = &(struct fbtft_platform_data) {
629 .init_sequence = hy28b_init_sequence,
634 .gpios = (const struct fbtft_gpio []) {
639 .gamma = HY28B_GAMMA,
644 .spi = &(struct spi_board_info) {
645 .modalias = "fb_ili9481",
646 .max_speed_hz = 32000000,
648 .platform_data = &(struct fbtft_platform_data) {
655 .gpios = (const struct fbtft_gpio []) {
665 .pdev = &(struct platform_device) {
666 .name = "fb_s6d1121",
669 .release = fbtft_device_pdev_release,
670 .platform_data = &(struct fbtft_platform_data) {
676 .gpios = (const struct fbtft_gpio []) {
677 /* Wiring for LCD adapter kit */
679 { "dc", 0 }, /* rev 2: 2 */
680 { "wr", 1 }, /* rev 2: 3 */
684 { "db02", 21 }, /* rev 2: 27 */
697 .pdev = &(struct platform_device) {
698 .name = "fb_ili9325",
701 .release = fbtft_device_pdev_release,
702 .platform_data = &(struct fbtft_platform_data) {
708 .gpios = (const struct fbtft_gpio []) {
715 .name = "itdb28_spi",
716 .spi = &(struct spi_board_info) {
717 .modalias = "fb_ili9325",
718 .max_speed_hz = 32000000,
720 .platform_data = &(struct fbtft_platform_data) {
726 .gpios = (const struct fbtft_gpio []) {
734 .name = "mi0283qt-2",
735 .spi = &(struct spi_board_info) {
736 .modalias = "fb_hx8347d",
737 .max_speed_hz = 32000000,
739 .platform_data = &(struct fbtft_platform_data) {
746 .gpios = (const struct fbtft_gpio []) {
755 .name = "mi0283qt-9a",
756 .spi = &(struct spi_board_info) {
757 .modalias = "fb_ili9341",
758 .max_speed_hz = 32000000,
760 .platform_data = &(struct fbtft_platform_data) {
766 .gpios = (const struct fbtft_gpio []) {
774 .name = "mi0283qt-v2",
775 .spi = &(struct spi_board_info) {
776 .modalias = "fb_watterott",
777 .max_speed_hz = 4000000,
779 .platform_data = &(struct fbtft_platform_data) {
780 .gpios = (const struct fbtft_gpio []) {
788 .spi = &(struct spi_board_info) {
789 .modalias = "fb_pcd8544",
790 .max_speed_hz = 400000,
792 .platform_data = &(struct fbtft_platform_data) {
796 .gpios = (const struct fbtft_gpio []) {
805 .name = "nokia3310a",
806 .spi = &(struct spi_board_info) {
807 .modalias = "fb_tls8204",
808 .max_speed_hz = 1000000,
810 .platform_data = &(struct fbtft_platform_data) {
814 .gpios = (const struct fbtft_gpio []) {
824 .spi = &(struct spi_board_info) {
825 .modalias = "fb_ili9163",
826 .max_speed_hz = 12000000,
828 .platform_data = &(struct fbtft_platform_data) {
834 .gpios = (const struct fbtft_gpio []) {
841 .spi = &(struct spi_board_info) {
842 .modalias = "fb_ili9486",
843 .max_speed_hz = 32000000,
845 .platform_data = &(struct fbtft_platform_data) {
852 .gpios = (const struct fbtft_gpio []) {
862 .spi = &(struct spi_board_info) {
863 .modalias = "fb_ili9340",
864 .max_speed_hz = 32000000,
867 .platform_data = &(struct fbtft_platform_data) {
871 .init_sequence = pitft_init_sequence,
874 .gpios = (const struct fbtft_gpio []) {
882 .spi = &(struct spi_board_info) {
883 .modalias = "fb_ssd1351",
884 .max_speed_hz = 20000000,
886 .platform_data = &(struct fbtft_platform_data) {
891 .gpios = (const struct fbtft_gpio []) {
896 .gamma = PIOLED_GAMMA
900 .name = "rpi-display",
901 .spi = &(struct spi_board_info) {
902 .modalias = "fb_ili9341",
903 .max_speed_hz = 32000000,
905 .platform_data = &(struct fbtft_platform_data) {
911 .gpios = (const struct fbtft_gpio []) {
921 .spi = &(struct spi_board_info) {
922 .modalias = "fb_s6d02a1",
923 .max_speed_hz = 32000000,
925 .platform_data = &(struct fbtft_platform_data) {
931 .gpios = (const struct fbtft_gpio []) {
940 .name = "sainsmart18",
941 .spi = &(struct spi_board_info) {
942 .modalias = "fb_st7735r",
943 .max_speed_hz = 32000000,
945 .platform_data = &(struct fbtft_platform_data) {
949 .gpios = (const struct fbtft_gpio []) {
957 .name = "sainsmart32",
958 .pdev = &(struct platform_device) {
959 .name = "fb_ssd1289",
962 .release = fbtft_device_pdev_release,
963 .platform_data = &(struct fbtft_platform_data) {
966 .txbuflen = -2, /* disable buffer */
968 .fbtftops.write = write_gpio16_wr_slow,
971 .gpios = (const struct fbtft_gpio []) {
978 .name = "sainsmart32_fast",
979 .pdev = &(struct platform_device) {
980 .name = "fb_ssd1289",
983 .release = fbtft_device_pdev_release,
984 .platform_data = &(struct fbtft_platform_data) {
987 .txbuflen = -2, /* disable buffer */
991 .gpios = (const struct fbtft_gpio []) {
998 .name = "sainsmart32_latched",
999 .pdev = &(struct platform_device) {
1000 .name = "fb_ssd1289",
1003 .release = fbtft_device_pdev_release,
1004 .platform_data = &(struct fbtft_platform_data) {
1007 .txbuflen = -2, /* disable buffer */
1010 fbtft_write_gpio16_wr_latched,
1013 .gpios = (const struct fbtft_gpio []) {
1020 .name = "sainsmart32_spi",
1021 .spi = &(struct spi_board_info) {
1022 .modalias = "fb_ssd1289",
1023 .max_speed_hz = 16000000,
1025 .platform_data = &(struct fbtft_platform_data) {
1031 .gpios = (const struct fbtft_gpio []) {
1040 .spi = &(struct spi_board_info) {
1041 .modalias = "spidev",
1042 .max_speed_hz = 500000,
1046 .platform_data = &(struct fbtft_platform_data) {
1047 .gpios = (const struct fbtft_gpio []) {
1054 .spi = &(struct spi_board_info) {
1055 .modalias = "fb_ssd1331",
1056 .max_speed_hz = 20000000,
1058 .platform_data = &(struct fbtft_platform_data) {
1062 .gpios = (const struct fbtft_gpio []) {
1070 .name = "tinylcd35",
1071 .spi = &(struct spi_board_info) {
1072 .modalias = "fb_tinylcd",
1073 .max_speed_hz = 32000000,
1075 .platform_data = &(struct fbtft_platform_data) {
1081 .gpios = (const struct fbtft_gpio []) {
1090 .name = "tm022hdh26",
1091 .spi = &(struct spi_board_info) {
1092 .modalias = "fb_ili9341",
1093 .max_speed_hz = 32000000,
1095 .platform_data = &(struct fbtft_platform_data) {
1101 .gpios = (const struct fbtft_gpio []) {
1110 .name = "tontec35_9481", /* boards before 02 July 2014 */
1111 .spi = &(struct spi_board_info) {
1112 .modalias = "fb_ili9481",
1113 .max_speed_hz = 128000000,
1115 .platform_data = &(struct fbtft_platform_data) {
1121 .gpios = (const struct fbtft_gpio []) {
1130 .name = "tontec35_9486", /* boards after 02 July 2014 */
1131 .spi = &(struct spi_board_info) {
1132 .modalias = "fb_ili9486",
1133 .max_speed_hz = 128000000,
1135 .platform_data = &(struct fbtft_platform_data) {
1141 .gpios = (const struct fbtft_gpio []) {
1150 .name = "upd161704",
1151 .spi = &(struct spi_board_info) {
1152 .modalias = "fb_upd161704",
1153 .max_speed_hz = 32000000,
1155 .platform_data = &(struct fbtft_platform_data) {
1159 .gpios = (const struct fbtft_gpio []) {
1167 .name = "waveshare32b",
1168 .spi = &(struct spi_board_info) {
1169 .modalias = "fb_ili9340",
1170 .max_speed_hz = 48000000,
1172 .platform_data = &(struct fbtft_platform_data) {
1177 waveshare32b_init_sequence,
1180 .gpios = (const struct fbtft_gpio []) {
1188 .name = "waveshare22",
1189 .spi = &(struct spi_board_info) {
1190 .modalias = "fb_bd663474",
1191 .max_speed_hz = 32000000,
1193 .platform_data = &(struct fbtft_platform_data) {
1197 .gpios = (const struct fbtft_gpio []) {
1205 /* This should be the last item.
1206 * Used with the custom argument
1209 .spi = &(struct spi_board_info) {
1213 .platform_data = &(struct fbtft_platform_data) {
1214 .gpios = (const struct fbtft_gpio []) {
1219 .pdev = &(struct platform_device) {
1223 .release = fbtft_device_pdev_release,
1224 .platform_data = &(struct fbtft_platform_data) {
1225 .gpios = (const struct fbtft_gpio []) {
1234 static int write_gpio16_wr_slow(struct fbtft_par *par, void *buf, size_t len)
1238 #ifndef DO_NOT_OPTIMIZE_FBTFT_WRITE_GPIO
1239 static u16 prev_data;
1242 fbtft_par_dbg_hex(DEBUG_WRITE, par, par->info->device, u8, buf, len,
1243 "%s(len=%d): ", __func__, len);
1248 /* Start writing by pulling down /WR */
1249 gpio_set_value(par->gpio.wr, 0);
1252 #ifndef DO_NOT_OPTIMIZE_FBTFT_WRITE_GPIO
1253 if (data == prev_data) {
1254 gpio_set_value(par->gpio.wr, 0); /* used as delay */
1256 for (i = 0; i < 16; i++) {
1257 if ((data & 1) != (prev_data & 1))
1258 gpio_set_value(par->gpio.db[i],
1265 for (i = 0; i < 16; i++) {
1266 gpio_set_value(par->gpio.db[i], data & 1);
1272 gpio_set_value(par->gpio.wr, 1);
1274 #ifndef DO_NOT_OPTIMIZE_FBTFT_WRITE_GPIO
1275 prev_data = *(u16 *)buf;
1284 static void adafruit18_green_tab_set_addr_win(struct fbtft_par *par,
1285 int xs, int ys, int xe, int ye)
1287 write_reg(par, 0x2A, 0, xs + 2, 0, xe + 2);
1288 write_reg(par, 0x2B, 0, ys + 1, 0, ye + 1);
1289 write_reg(par, 0x2C);
1292 /* used if gpios parameter is present */
1293 static struct fbtft_gpio fbtft_device_param_gpios[MAX_GPIOS + 1] = { };
1295 static void fbtft_device_pdev_release(struct device *dev)
1297 /* Needed to silence this message:
1298 * Device 'xxx' does not have a release() function,
1299 * it is broken and must be fixed
1303 static int spi_device_found(struct device *dev, void *data)
1305 struct spi_device *spi = to_spi_device(dev);
1307 dev_info(dev, "%s %s %dkHz %d bits mode=0x%02X\n", spi->modalias,
1308 dev_name(dev), spi->max_speed_hz / 1000, spi->bits_per_word,
1314 static void pr_spi_devices(void)
1316 pr_debug("SPI devices registered:\n");
1317 bus_for_each_dev(&spi_bus_type, NULL, NULL, spi_device_found);
1320 static int p_device_found(struct device *dev, void *data)
1322 struct platform_device
1323 *pdev = to_platform_device(dev);
1325 if (strstr(pdev->name, "fb"))
1326 dev_info(dev, "%s id=%d pdata? %s\n", pdev->name, pdev->id,
1327 pdev->dev.platform_data ? "yes" : "no");
1332 static void pr_p_devices(void)
1334 pr_debug("'fb' Platform devices registered:\n");
1335 bus_for_each_dev(&platform_bus_type, NULL, NULL, p_device_found);
1339 static void fbtft_device_spi_delete(struct spi_master *master, unsigned int cs)
1344 snprintf(str, sizeof(str), "%s.%u", dev_name(&master->dev), cs);
1346 dev = bus_find_device_by_name(&spi_bus_type, NULL, str);
1349 dev_info(dev, "Deleting %s\n", str);
1354 static int fbtft_device_spi_device_register(struct spi_board_info *spi)
1356 struct spi_master *master;
1358 master = spi_busnum_to_master(spi->bus_num);
1360 pr_err("spi_busnum_to_master(%d) returned NULL\n",
1364 /* make sure it's available */
1365 fbtft_device_spi_delete(master, spi->chip_select);
1366 spi_device = spi_new_device(master, spi);
1367 put_device(&master->dev);
1369 dev_err(&master->dev, "spi_new_device() returned NULL\n");
1375 static int fbtft_device_spi_device_register(struct spi_board_info *spi)
1377 return spi_register_board_info(spi, 1);
1381 static int __init fbtft_device_init(void)
1383 struct spi_board_info *spi = NULL;
1384 struct fbtft_platform_data *pdata;
1385 const struct fbtft_gpio *gpio = NULL;
1386 char *p_gpio, *p_name, *p_num;
1394 pr_err("missing module parameter: 'name'\n");
1401 if (init_num > FBTFT_MAX_INIT_SEQUENCE) {
1402 pr_err("init parameter: exceeded max array size: %d\n",
1403 FBTFT_MAX_INIT_SEQUENCE);
1407 /* parse module parameter: gpios */
1408 while ((p_gpio = strsep(&gpios, ","))) {
1409 if (!strchr(p_gpio, ':')) {
1410 pr_err("error: missing ':' in gpios parameter: %s\n",
1415 p_name = strsep(&p_num, ":");
1416 if (!p_name || !p_num) {
1417 pr_err("something bad happened parsing gpios parameter: %s\n",
1421 ret = kstrtol(p_num, 10, &val);
1423 pr_err("could not parse number in gpios parameter: %s:%s\n",
1427 strncpy(fbtft_device_param_gpios[i].name, p_name,
1428 FBTFT_GPIO_NAME_SIZE - 1);
1429 fbtft_device_param_gpios[i++].gpio = (int)val;
1430 if (i == MAX_GPIOS) {
1431 pr_err("gpios parameter: exceeded max array size: %d\n",
1436 if (fbtft_device_param_gpios[0].name[0])
1437 gpio = fbtft_device_param_gpios;
1440 pr_spi_devices(); /* print list of registered SPI devices */
1441 pr_p_devices(); /* print list of 'fb' platform devices */
1444 pr_debug("name='%s', busnum=%d, cs=%d\n", name, busnum, cs);
1446 if (rotate > 0 && rotate < 4) {
1447 rotate = (4 - rotate) * 90;
1448 pr_warn("argument 'rotate' should be an angle. Values 1-3 is deprecated. Setting it to %d.\n",
1451 if (rotate != 0 && rotate != 90 && rotate != 180 && rotate != 270) {
1452 pr_warn("argument 'rotate' illegal value: %d. Setting it to 0.\n",
1457 /* name=list lists all supported displays */
1458 if (strncmp(name, "list", FBTFT_GPIO_NAME_SIZE) == 0) {
1459 pr_info("Supported displays:\n");
1461 for (i = 0; i < ARRAY_SIZE(displays); i++)
1462 pr_info("%s\n", displays[i].name);
1467 i = ARRAY_SIZE(displays) - 1;
1468 displays[i].name = name;
1470 displays[i].pdev->name = name;
1471 displays[i].spi = NULL;
1475 len = strlcpy(displays[i].spi->modalias, name,
1477 if (len >= SPI_NAME_SIZE)
1478 pr_warn("modalias (name) truncated to: %s\n",
1479 displays[i].spi->modalias);
1480 displays[i].pdev = NULL;
1484 for (i = 0; i < ARRAY_SIZE(displays); i++) {
1485 if (strncmp(name, displays[i].name, SPI_NAME_SIZE) == 0) {
1486 if (displays[i].spi) {
1487 spi = displays[i].spi;
1488 spi->chip_select = cs;
1489 spi->bus_num = busnum;
1491 spi->max_speed_hz = speed;
1494 pdata = (void *)spi->platform_data;
1495 } else if (displays[i].pdev) {
1496 p_device = displays[i].pdev;
1497 pdata = p_device->dev.platform_data;
1499 pr_err("broken displays array\n");
1503 pdata->rotate = rotate;
1509 pdata->startbyte = startbyte;
1511 pdata->gamma = gamma;
1512 pdata->display.debug = debug;
1516 pdata->txbuflen = txbuflen;
1518 pdata->display.init_sequence = init;
1520 pdata->gpios = gpio;
1522 pdata->display.width = width;
1523 pdata->display.height = height;
1524 pdata->display.buswidth = buswidth;
1525 pdata->display.backlight = 1;
1528 if (displays[i].spi) {
1529 ret = fbtft_device_spi_device_register(spi);
1531 pr_err("failed to register SPI device\n");
1535 ret = platform_device_register(p_device);
1537 pr_err("platform_device_register() returned %d\n",
1548 pr_err("display not supported: '%s'\n", name);
1552 if (verbose && pdata && pdata->gpios) {
1553 gpio = pdata->gpios;
1554 pr_info("GPIOS used by '%s':\n", name);
1556 while (verbose && gpio->name[0]) {
1557 pr_info("'%s' = GPIO%d\n", gpio->name, gpio->gpio);
1562 pr_info("(none)\n");
1565 if (spi_device && (verbose > 1))
1567 if (p_device && (verbose > 1))
1573 static void __exit fbtft_device_exit(void)
1576 device_del(&spi_device->dev);
1581 platform_device_unregister(p_device);
1584 arch_initcall(fbtft_device_init);
1585 module_exit(fbtft_device_exit);
1587 MODULE_DESCRIPTION("Add a FBTFT device.");
1588 MODULE_AUTHOR("Noralf Tronnes");
1589 MODULE_LICENSE("GPL");