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/consumer.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)");
48 static unsigned int fps;
49 module_param(fps, uint, 0000);
50 MODULE_PARM_DESC(fps, "Frames per second (override driver default)");
53 module_param(gamma, charp, 0000);
54 MODULE_PARM_DESC(gamma,
55 "String representation of Gamma Curve(s). Driver specific.");
58 module_param(txbuflen, int, 0000);
59 MODULE_PARM_DESC(txbuflen, "txbuflen (override driver default)");
62 module_param(bgr, int, 0000);
64 "BGR bit (supported by some drivers).");
66 static unsigned int startbyte;
67 module_param(startbyte, uint, 0000);
68 MODULE_PARM_DESC(startbyte, "Sets the Start byte used by some SPI displays.");
71 module_param(custom, bool, 0000);
72 MODULE_PARM_DESC(custom, "Add a custom display device. Use speed= argument to make it a SPI device, else platform_device");
74 static unsigned int width;
75 module_param(width, uint, 0000);
76 MODULE_PARM_DESC(width, "Display width, used with the custom argument");
78 static unsigned int height;
79 module_param(height, uint, 0000);
80 MODULE_PARM_DESC(height, "Display height, used with the custom argument");
82 static unsigned int buswidth = 8;
83 module_param(buswidth, uint, 0000);
84 MODULE_PARM_DESC(buswidth, "Display bus width, used with the custom argument");
86 static s16 init[FBTFT_MAX_INIT_SEQUENCE];
88 module_param_array(init, short, &init_num, 0000);
89 MODULE_PARM_DESC(init, "Init sequence, used with the custom argument");
91 static unsigned long debug;
92 module_param(debug, ulong, 0000);
93 MODULE_PARM_DESC(debug,
94 "level: 0-7 (the remaining 29 bits is for advanced usage)");
96 static unsigned int verbose = 3;
97 module_param(verbose, uint, 0000);
98 MODULE_PARM_DESC(verbose,
99 "0 silent, >1 show devices, >2 show devices before (default=3)");
101 struct fbtft_device_display {
103 struct spi_board_info *spi;
104 struct platform_device *pdev;
107 static void fbtft_device_pdev_release(struct device *dev);
109 static int write_gpio16_wr_slow(struct fbtft_par *par, void *buf, size_t len);
110 static void adafruit18_green_tab_set_addr_win(struct fbtft_par *par,
111 int xs, int ys, int xe, int ye);
113 #define ADAFRUIT18_GAMMA \
114 "02 1c 07 12 37 32 29 2d 29 25 2B 39 00 01 03 10\n" \
115 "03 1d 07 06 2E 2C 29 2D 2E 2E 37 3F 00 00 02 10"
117 #define CBERRY28_GAMMA \
118 "D0 00 14 15 13 2C 42 43 4E 09 16 14 18 21\n" \
119 "D0 00 14 15 13 0B 43 55 53 0C 17 14 23 20"
121 static const s16 cberry28_init_sequence[] = {
122 /* turn off sleep mode */
123 -1, MIPI_DCS_EXIT_SLEEP_MODE,
126 /* set pixel format to RGB-565 */
127 -1, MIPI_DCS_SET_PIXEL_FORMAT, MIPI_DCS_PIXEL_FMT_16BIT,
129 -1, 0xB2, 0x0C, 0x0C, 0x00, 0x33, 0x33,
138 * VDV and VRH register values come from command write
141 -1, 0xC2, 0x01, 0xFF,
144 * VAP = 4.7V + (VCOM + VCOM offset + 0.5 * VDV)
145 * VAN = -4.7V + (VCOM + VCOM offset + 0.5 * VDV)
155 /* VCOM offset = 0V */
163 -1, 0xD0, 0xA4, 0xA1,
165 -1, MIPI_DCS_SET_DISPLAY_ON,
170 static const s16 hy28b_init_sequence[] = {
171 -1, 0x00e7, 0x0010, -1, 0x0000, 0x0001,
172 -1, 0x0001, 0x0100, -1, 0x0002, 0x0700,
173 -1, 0x0003, 0x1030, -1, 0x0004, 0x0000,
174 -1, 0x0008, 0x0207, -1, 0x0009, 0x0000,
175 -1, 0x000a, 0x0000, -1, 0x000c, 0x0001,
176 -1, 0x000d, 0x0000, -1, 0x000f, 0x0000,
177 -1, 0x0010, 0x0000, -1, 0x0011, 0x0007,
178 -1, 0x0012, 0x0000, -1, 0x0013, 0x0000,
179 -2, 50, -1, 0x0010, 0x1590, -1, 0x0011,
180 0x0227, -2, 50, -1, 0x0012, 0x009c, -2, 50,
181 -1, 0x0013, 0x1900, -1, 0x0029, 0x0023,
182 -1, 0x002b, 0x000e, -2, 50,
183 -1, 0x0020, 0x0000, -1, 0x0021, 0x0000,
184 -2, 50, -1, 0x0050, 0x0000,
185 -1, 0x0051, 0x00ef, -1, 0x0052, 0x0000,
186 -1, 0x0053, 0x013f, -1, 0x0060, 0xa700,
187 -1, 0x0061, 0x0001, -1, 0x006a, 0x0000,
188 -1, 0x0080, 0x0000, -1, 0x0081, 0x0000,
189 -1, 0x0082, 0x0000, -1, 0x0083, 0x0000,
190 -1, 0x0084, 0x0000, -1, 0x0085, 0x0000,
191 -1, 0x0090, 0x0010, -1, 0x0092, 0x0000,
192 -1, 0x0093, 0x0003, -1, 0x0095, 0x0110,
193 -1, 0x0097, 0x0000, -1, 0x0098, 0x0000,
194 -1, 0x0007, 0x0133, -1, 0x0020, 0x0000,
195 -1, 0x0021, 0x0000, -2, 100, -3 };
197 #define HY28B_GAMMA \
198 "04 1F 4 7 7 0 7 7 6 0\n" \
199 "0F 00 1 7 4 0 0 0 6 7"
201 static const s16 pitft_init_sequence[] = {
202 -1, MIPI_DCS_SOFT_RESET,
204 -1, MIPI_DCS_SET_DISPLAY_OFF,
205 -1, 0xEF, 0x03, 0x80, 0x02,
206 -1, 0xCF, 0x00, 0xC1, 0x30,
207 -1, 0xED, 0x64, 0x03, 0x12, 0x81,
208 -1, 0xE8, 0x85, 0x00, 0x78,
209 -1, 0xCB, 0x39, 0x2C, 0x00, 0x34, 0x02,
211 -1, 0xEA, 0x00, 0x00,
214 -1, 0xC5, 0x3E, 0x28,
216 -1, MIPI_DCS_SET_PIXEL_FORMAT, 0x55,
217 -1, 0xB1, 0x00, 0x18,
218 -1, 0xB6, 0x08, 0x82, 0x27,
220 -1, MIPI_DCS_SET_GAMMA_CURVE, 0x01,
221 -1, 0xE0, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E,
222 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00,
223 -1, 0xE1, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31,
224 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F,
225 -1, MIPI_DCS_EXIT_SLEEP_MODE,
227 -1, MIPI_DCS_SET_DISPLAY_ON,
232 static const s16 waveshare32b_init_sequence[] = {
233 -1, 0xCB, 0x39, 0x2C, 0x00, 0x34, 0x02,
234 -1, 0xCF, 0x00, 0xC1, 0x30,
235 -1, 0xE8, 0x85, 0x00, 0x78,
236 -1, 0xEA, 0x00, 0x00,
237 -1, 0xED, 0x64, 0x03, 0x12, 0x81,
241 -1, 0xC5, 0x3E, 0x28,
243 -1, MIPI_DCS_SET_ADDRESS_MODE, 0x28,
244 -1, MIPI_DCS_SET_PIXEL_FORMAT, 0x55,
245 -1, 0xB1, 0x00, 0x18,
246 -1, 0xB6, 0x08, 0x82, 0x27,
248 -1, MIPI_DCS_SET_GAMMA_CURVE, 0x01,
249 -1, 0xE0, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E,
250 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00,
251 -1, 0xE1, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31,
252 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F,
253 -1, MIPI_DCS_EXIT_SLEEP_MODE,
255 -1, MIPI_DCS_SET_DISPLAY_ON,
256 -1, MIPI_DCS_WRITE_MEMORY_START,
260 #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 " \
261 "2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 " \
262 "3 3 3 4 4 4 4 4 4 4 4 4 4 4 4"
264 /* Supported displays in alphabetical order */
265 static struct fbtft_device_display displays[] = {
267 .name = "adafruit18",
268 .spi = &(struct spi_board_info) {
269 .modalias = "fb_st7735r",
270 .max_speed_hz = 32000000,
272 .platform_data = &(struct fbtft_platform_data) {
277 .gamma = ADAFRUIT18_GAMMA,
281 .name = "adafruit18_green",
282 .spi = &(struct spi_board_info) {
283 .modalias = "fb_st7735r",
284 .max_speed_hz = 4000000,
286 .platform_data = &(struct fbtft_platform_data) {
290 .fbtftops.set_addr_win =
291 adafruit18_green_tab_set_addr_win,
294 .gamma = ADAFRUIT18_GAMMA,
298 .name = "adafruit22",
299 .spi = &(struct spi_board_info) {
300 .modalias = "fb_hx8340bn",
301 .max_speed_hz = 32000000,
303 .platform_data = &(struct fbtft_platform_data) {
312 .name = "adafruit22a",
313 .spi = &(struct spi_board_info) {
314 .modalias = "fb_ili9340",
315 .max_speed_hz = 32000000,
317 .platform_data = &(struct fbtft_platform_data) {
326 .name = "adafruit28",
327 .spi = &(struct spi_board_info) {
328 .modalias = "fb_ili9341",
329 .max_speed_hz = 32000000,
331 .platform_data = &(struct fbtft_platform_data) {
340 .name = "adafruit13m",
341 .spi = &(struct spi_board_info) {
342 .modalias = "fb_ssd1306",
343 .max_speed_hz = 16000000,
345 .platform_data = &(struct fbtft_platform_data) {
352 .name = "admatec_c-berry28",
353 .spi = &(struct spi_board_info) {
354 .modalias = "fb_st7789v",
355 .max_speed_hz = 48000000,
357 .platform_data = &(struct fbtft_platform_data) {
361 .init_sequence = cberry28_init_sequence,
363 .gamma = CBERRY28_GAMMA,
367 .name = "agm1264k-fl",
368 .pdev = &(struct platform_device) {
369 .name = "fb_agm1264k-fl",
372 .release = fbtft_device_pdev_release,
373 .platform_data = &(struct fbtft_platform_data) {
376 .backlight = FBTFT_ONBOARD_BACKLIGHT,
383 .spi = &(struct spi_board_info) {
384 .modalias = "fb_uc1701",
385 .max_speed_hz = 8000000,
387 .platform_data = &(struct fbtft_platform_data) {
395 .name = "er_tftm050_2",
396 .spi = &(struct spi_board_info) {
397 .modalias = "fb_ra8875",
398 .max_speed_hz = 5000000,
400 .platform_data = &(struct fbtft_platform_data) {
411 .name = "er_tftm070_5",
412 .spi = &(struct spi_board_info) {
413 .modalias = "fb_ra8875",
414 .max_speed_hz = 5000000,
416 .platform_data = &(struct fbtft_platform_data) {
428 .spi = &(struct spi_board_info) {
429 .modalias = "fb_uc1611",
430 .max_speed_hz = 32000000,
432 .platform_data = &(struct fbtft_platform_data) {
439 .name = "ew24ha0_9bit",
440 .spi = &(struct spi_board_info) {
441 .modalias = "fb_uc1611",
442 .max_speed_hz = 32000000,
444 .platform_data = &(struct fbtft_platform_data) {
452 .spi = &(struct spi_board_info) {
453 .modalias = "flexfb",
454 .max_speed_hz = 32000000,
459 .pdev = &(struct platform_device) {
463 .release = fbtft_device_pdev_release,
467 .name = "freetronicsoled128",
468 .spi = &(struct spi_board_info) {
469 .modalias = "fb_ssd1351",
470 .max_speed_hz = 20000000,
472 .platform_data = &(struct fbtft_platform_data) {
475 .backlight = FBTFT_ONBOARD_BACKLIGHT,
482 .spi = &(struct spi_board_info) {
483 .modalias = "fb_hx8353d",
484 .max_speed_hz = 16000000,
486 .platform_data = &(struct fbtft_platform_data) {
495 .spi = &(struct spi_board_info) {
496 .modalias = "fb_ili9320",
497 .max_speed_hz = 32000000,
499 .platform_data = &(struct fbtft_platform_data) {
510 .spi = &(struct spi_board_info) {
511 .modalias = "fb_ili9325",
512 .max_speed_hz = 48000000,
514 .platform_data = &(struct fbtft_platform_data) {
518 .init_sequence = hy28b_init_sequence,
523 .gamma = HY28B_GAMMA,
528 .spi = &(struct spi_board_info) {
529 .modalias = "fb_ili9481",
530 .max_speed_hz = 32000000,
532 .platform_data = &(struct fbtft_platform_data) {
543 .pdev = &(struct platform_device) {
544 .name = "fb_s6d1121",
547 .release = fbtft_device_pdev_release,
548 .platform_data = &(struct fbtft_platform_data) {
559 .pdev = &(struct platform_device) {
560 .name = "fb_ili9325",
563 .release = fbtft_device_pdev_release,
564 .platform_data = &(struct fbtft_platform_data) {
574 .name = "itdb28_spi",
575 .spi = &(struct spi_board_info) {
576 .modalias = "fb_ili9325",
577 .max_speed_hz = 32000000,
579 .platform_data = &(struct fbtft_platform_data) {
588 .name = "mi0283qt-2",
589 .spi = &(struct spi_board_info) {
590 .modalias = "fb_hx8347d",
591 .max_speed_hz = 32000000,
593 .platform_data = &(struct fbtft_platform_data) {
603 .name = "mi0283qt-9a",
604 .spi = &(struct spi_board_info) {
605 .modalias = "fb_ili9341",
606 .max_speed_hz = 32000000,
608 .platform_data = &(struct fbtft_platform_data) {
617 .name = "mi0283qt-v2",
618 .spi = &(struct spi_board_info) {
619 .modalias = "fb_watterott",
620 .max_speed_hz = 4000000,
622 .platform_data = &(struct fbtft_platform_data) {
627 .spi = &(struct spi_board_info) {
628 .modalias = "fb_pcd8544",
629 .max_speed_hz = 400000,
631 .platform_data = &(struct fbtft_platform_data) {
638 .name = "nokia3310a",
639 .spi = &(struct spi_board_info) {
640 .modalias = "fb_tls8204",
641 .max_speed_hz = 1000000,
643 .platform_data = &(struct fbtft_platform_data) {
651 .spi = &(struct spi_board_info) {
652 .modalias = "fb_ili9163",
653 .max_speed_hz = 12000000,
655 .platform_data = &(struct fbtft_platform_data) {
665 .spi = &(struct spi_board_info) {
666 .modalias = "fb_ili9486",
667 .max_speed_hz = 32000000,
669 .platform_data = &(struct fbtft_platform_data) {
680 .spi = &(struct spi_board_info) {
681 .modalias = "fb_ili9340",
682 .max_speed_hz = 32000000,
685 .platform_data = &(struct fbtft_platform_data) {
689 .init_sequence = pitft_init_sequence,
696 .spi = &(struct spi_board_info) {
697 .modalias = "fb_ssd1351",
698 .max_speed_hz = 20000000,
700 .platform_data = &(struct fbtft_platform_data) {
705 .gamma = PIOLED_GAMMA
709 .name = "rpi-display",
710 .spi = &(struct spi_board_info) {
711 .modalias = "fb_ili9341",
712 .max_speed_hz = 32000000,
714 .platform_data = &(struct fbtft_platform_data) {
724 .spi = &(struct spi_board_info) {
725 .modalias = "fb_s6d02a1",
726 .max_speed_hz = 32000000,
728 .platform_data = &(struct fbtft_platform_data) {
737 .name = "sainsmart18",
738 .spi = &(struct spi_board_info) {
739 .modalias = "fb_st7735r",
740 .max_speed_hz = 32000000,
742 .platform_data = &(struct fbtft_platform_data) {
749 .name = "sainsmart32",
750 .pdev = &(struct platform_device) {
751 .name = "fb_ssd1289",
754 .release = fbtft_device_pdev_release,
755 .platform_data = &(struct fbtft_platform_data) {
758 .txbuflen = -2, /* disable buffer */
760 .fbtftops.write = write_gpio16_wr_slow,
767 .name = "sainsmart32_fast",
768 .pdev = &(struct platform_device) {
769 .name = "fb_ssd1289",
772 .release = fbtft_device_pdev_release,
773 .platform_data = &(struct fbtft_platform_data) {
776 .txbuflen = -2, /* disable buffer */
784 .name = "sainsmart32_latched",
785 .pdev = &(struct platform_device) {
786 .name = "fb_ssd1289",
789 .release = fbtft_device_pdev_release,
790 .platform_data = &(struct fbtft_platform_data) {
793 .txbuflen = -2, /* disable buffer */
796 fbtft_write_gpio16_wr_latched,
803 .name = "sainsmart32_spi",
804 .spi = &(struct spi_board_info) {
805 .modalias = "fb_ssd1289",
806 .max_speed_hz = 16000000,
808 .platform_data = &(struct fbtft_platform_data) {
818 .spi = &(struct spi_board_info) {
819 .modalias = "spidev",
820 .max_speed_hz = 500000,
824 .platform_data = &(struct fbtft_platform_data) {
829 .spi = &(struct spi_board_info) {
830 .modalias = "fb_ssd1331",
831 .max_speed_hz = 20000000,
833 .platform_data = &(struct fbtft_platform_data) {
841 .spi = &(struct spi_board_info) {
842 .modalias = "fb_tinylcd",
843 .max_speed_hz = 32000000,
845 .platform_data = &(struct fbtft_platform_data) {
854 .name = "tm022hdh26",
855 .spi = &(struct spi_board_info) {
856 .modalias = "fb_ili9341",
857 .max_speed_hz = 32000000,
859 .platform_data = &(struct fbtft_platform_data) {
868 .name = "tontec35_9481", /* boards before 02 July 2014 */
869 .spi = &(struct spi_board_info) {
870 .modalias = "fb_ili9481",
871 .max_speed_hz = 128000000,
873 .platform_data = &(struct fbtft_platform_data) {
882 .name = "tontec35_9486", /* boards after 02 July 2014 */
883 .spi = &(struct spi_board_info) {
884 .modalias = "fb_ili9486",
885 .max_speed_hz = 128000000,
887 .platform_data = &(struct fbtft_platform_data) {
897 .spi = &(struct spi_board_info) {
898 .modalias = "fb_upd161704",
899 .max_speed_hz = 32000000,
901 .platform_data = &(struct fbtft_platform_data) {
908 .name = "waveshare32b",
909 .spi = &(struct spi_board_info) {
910 .modalias = "fb_ili9340",
911 .max_speed_hz = 48000000,
913 .platform_data = &(struct fbtft_platform_data) {
918 waveshare32b_init_sequence,
924 .name = "waveshare22",
925 .spi = &(struct spi_board_info) {
926 .modalias = "fb_bd663474",
927 .max_speed_hz = 32000000,
929 .platform_data = &(struct fbtft_platform_data) {
936 /* This should be the last item.
937 * Used with the custom argument
940 .spi = &(struct spi_board_info) {
944 .platform_data = &(struct fbtft_platform_data) {
947 .pdev = &(struct platform_device) {
951 .release = fbtft_device_pdev_release,
952 .platform_data = &(struct fbtft_platform_data) {
959 static int write_gpio16_wr_slow(struct fbtft_par *par, void *buf, size_t len)
963 #ifndef DO_NOT_OPTIMIZE_FBTFT_WRITE_GPIO
964 static u16 prev_data;
967 fbtft_par_dbg_hex(DEBUG_WRITE, par, par->info->device, u8, buf, len,
968 "%s(len=%zu): ", __func__, len);
973 /* Start writing by pulling down /WR */
974 gpiod_set_value(par->gpio.wr, 0);
977 #ifndef DO_NOT_OPTIMIZE_FBTFT_WRITE_GPIO
978 if (data == prev_data) {
979 gpiod_set_value(par->gpio.wr, 0); /* used as delay */
981 for (i = 0; i < 16; i++) {
982 if ((data & 1) != (prev_data & 1))
983 gpiod_set_value(par->gpio.db[i],
990 for (i = 0; i < 16; i++) {
991 gpiod_set_value(par->gpio.db[i], data & 1);
997 gpiod_set_value(par->gpio.wr, 1);
999 #ifndef DO_NOT_OPTIMIZE_FBTFT_WRITE_GPIO
1000 prev_data = *(u16 *)buf;
1009 static void adafruit18_green_tab_set_addr_win(struct fbtft_par *par,
1010 int xs, int ys, int xe, int ye)
1012 write_reg(par, 0x2A, 0, xs + 2, 0, xe + 2);
1013 write_reg(par, 0x2B, 0, ys + 1, 0, ye + 1);
1014 write_reg(par, 0x2C);
1017 static void fbtft_device_pdev_release(struct device *dev)
1019 /* Needed to silence this message:
1020 * Device 'xxx' does not have a release() function,
1021 * it is broken and must be fixed
1025 static int spi_device_found(struct device *dev, void *data)
1027 struct spi_device *spi = to_spi_device(dev);
1029 dev_info(dev, "%s %s %dkHz %d bits mode=0x%02X\n", spi->modalias,
1030 dev_name(dev), spi->max_speed_hz / 1000, spi->bits_per_word,
1036 static void pr_spi_devices(void)
1038 pr_debug("SPI devices registered:\n");
1039 bus_for_each_dev(&spi_bus_type, NULL, NULL, spi_device_found);
1042 static int p_device_found(struct device *dev, void *data)
1044 struct platform_device
1045 *pdev = to_platform_device(dev);
1047 if (strstr(pdev->name, "fb"))
1048 dev_info(dev, "%s id=%d pdata? %s\n", pdev->name, pdev->id,
1049 pdev->dev.platform_data ? "yes" : "no");
1054 static void pr_p_devices(void)
1056 pr_debug("'fb' Platform devices registered:\n");
1057 bus_for_each_dev(&platform_bus_type, NULL, NULL, p_device_found);
1061 static void fbtft_device_spi_delete(struct spi_master *master, unsigned int cs)
1066 snprintf(str, sizeof(str), "%s.%u", dev_name(&master->dev), cs);
1068 dev = bus_find_device_by_name(&spi_bus_type, NULL, str);
1071 dev_info(dev, "Deleting %s\n", str);
1076 static int fbtft_device_spi_device_register(struct spi_board_info *spi)
1078 struct spi_master *master;
1080 master = spi_busnum_to_master(spi->bus_num);
1082 pr_err("spi_busnum_to_master(%d) returned NULL\n",
1086 /* make sure it's available */
1087 fbtft_device_spi_delete(master, spi->chip_select);
1088 spi_device = spi_new_device(master, spi);
1089 put_device(&master->dev);
1091 dev_err(&master->dev, "spi_new_device() returned NULL\n");
1097 static int fbtft_device_spi_device_register(struct spi_board_info *spi)
1099 return spi_register_board_info(spi, 1);
1103 static int __init fbtft_device_init(void)
1105 struct spi_board_info *spi = NULL;
1106 struct fbtft_platform_data *pdata;
1113 pr_err("missing module parameter: 'name'\n");
1120 if (init_num > FBTFT_MAX_INIT_SEQUENCE) {
1121 pr_err("init parameter: exceeded max array size: %d\n",
1122 FBTFT_MAX_INIT_SEQUENCE);
1127 pr_spi_devices(); /* print list of registered SPI devices */
1128 pr_p_devices(); /* print list of 'fb' platform devices */
1131 pr_debug("name='%s', busnum=%d, cs=%d\n", name, busnum, cs);
1133 if (rotate > 0 && rotate < 4) {
1134 rotate = (4 - rotate) * 90;
1135 pr_warn("argument 'rotate' should be an angle. Values 1-3 is deprecated. Setting it to %d.\n",
1138 if (rotate != 0 && rotate != 90 && rotate != 180 && rotate != 270) {
1139 pr_warn("argument 'rotate' illegal value: %d. Setting it to 0.\n",
1144 /* name=list lists all supported displays */
1145 if (strcmp(name, "list") == 0) {
1146 pr_info("Supported displays:\n");
1148 for (i = 0; i < ARRAY_SIZE(displays); i++)
1149 pr_info("%s\n", displays[i].name);
1154 i = ARRAY_SIZE(displays) - 1;
1155 displays[i].name = name;
1157 displays[i].pdev->name = name;
1158 displays[i].spi = NULL;
1162 len = strlcpy(displays[i].spi->modalias, name,
1164 if (len >= SPI_NAME_SIZE)
1165 pr_warn("modalias (name) truncated to: %s\n",
1166 displays[i].spi->modalias);
1167 displays[i].pdev = NULL;
1171 for (i = 0; i < ARRAY_SIZE(displays); i++) {
1172 if (strncmp(name, displays[i].name, SPI_NAME_SIZE) == 0) {
1173 if (displays[i].spi) {
1174 spi = displays[i].spi;
1175 spi->chip_select = cs;
1176 spi->bus_num = busnum;
1178 spi->max_speed_hz = speed;
1181 pdata = (void *)spi->platform_data;
1182 } else if (displays[i].pdev) {
1183 p_device = displays[i].pdev;
1184 pdata = p_device->dev.platform_data;
1186 pr_err("broken displays array\n");
1190 pdata->rotate = rotate;
1196 pdata->startbyte = startbyte;
1198 pdata->gamma = gamma;
1199 pdata->display.debug = debug;
1203 pdata->txbuflen = txbuflen;
1205 pdata->display.init_sequence = init;
1207 pdata->display.width = width;
1208 pdata->display.height = height;
1209 pdata->display.buswidth = buswidth;
1210 pdata->display.backlight = 1;
1213 if (displays[i].spi) {
1214 ret = fbtft_device_spi_device_register(spi);
1216 pr_err("failed to register SPI device\n");
1220 ret = platform_device_register(p_device);
1222 pr_err("platform_device_register() returned %d\n",
1233 pr_err("display not supported: '%s'\n", name);
1237 if (spi_device && (verbose > 1))
1239 if (p_device && (verbose > 1))
1245 static void __exit fbtft_device_exit(void)
1248 device_del(&spi_device->dev);
1253 platform_device_unregister(p_device);
1256 arch_initcall(fbtft_device_init);
1257 module_exit(fbtft_device_exit);
1259 MODULE_DESCRIPTION("Add a FBTFT device.");
1260 MODULE_AUTHOR("Noralf Tronnes");
1261 MODULE_LICENSE("GPL");