3 * Copyright (C) 2013, Noralf Tronnes
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <linux/module.h>
21 #include <linux/kernel.h>
22 #include <linux/init.h>
23 #include <linux/gpio.h>
24 #include <linux/spi/spi.h>
28 #define DRVNAME "fbtft_device"
32 static struct spi_device *spi_device;
33 static struct platform_device *p_device;
36 module_param(name, charp, 0);
37 MODULE_PARM_DESC(name, "Devicename (required). name=list => list all supported devices.");
39 static unsigned rotate;
40 module_param(rotate, uint, 0);
41 MODULE_PARM_DESC(rotate,
42 "Angle to rotate display counter clockwise: 0, 90, 180, 270");
44 static unsigned busnum;
45 module_param(busnum, uint, 0);
46 MODULE_PARM_DESC(busnum, "SPI bus number (default=0)");
49 module_param(cs, uint, 0);
50 MODULE_PARM_DESC(cs, "SPI chip select (default=0)");
52 static unsigned speed;
53 module_param(speed, uint, 0);
54 MODULE_PARM_DESC(speed, "SPI speed (override device default)");
57 module_param(mode, int, 0);
58 MODULE_PARM_DESC(mode, "SPI mode (override device default)");
61 module_param(gpios, charp, 0);
62 MODULE_PARM_DESC(gpios,
63 "List of gpios. Comma separated with the form: reset:23,dc:24 (when overriding the default, all gpios must be specified)");
66 module_param(fps, uint, 0);
67 MODULE_PARM_DESC(fps, "Frames per second (override driver default)");
70 module_param(gamma, charp, 0);
71 MODULE_PARM_DESC(gamma,
72 "String representation of Gamma Curve(s). Driver specific.");
75 module_param(txbuflen, int, 0);
76 MODULE_PARM_DESC(txbuflen, "txbuflen (override driver default)");
79 module_param(bgr, int, 0);
81 "BGR bit (supported by some drivers).");
83 static unsigned startbyte;
84 module_param(startbyte, uint, 0);
85 MODULE_PARM_DESC(startbyte, "Sets the Start byte used by some SPI displays.");
88 module_param(custom, bool, 0);
89 MODULE_PARM_DESC(custom, "Add a custom display device. Use speed= argument to make it a SPI device, else platform_device");
91 static unsigned width;
92 module_param(width, uint, 0);
93 MODULE_PARM_DESC(width, "Display width, used with the custom argument");
95 static unsigned height;
96 module_param(height, uint, 0);
97 MODULE_PARM_DESC(height, "Display height, used with the custom argument");
99 static unsigned buswidth = 8;
100 module_param(buswidth, uint, 0);
101 MODULE_PARM_DESC(buswidth, "Display bus width, used with the custom argument");
103 static int init[FBTFT_MAX_INIT_SEQUENCE];
105 module_param_array(init, int, &init_num, 0);
106 MODULE_PARM_DESC(init, "Init sequence, used with the custom argument");
108 static unsigned long debug;
109 module_param(debug, ulong, 0);
110 MODULE_PARM_DESC(debug,
111 "level: 0-7 (the remaining 29 bits is for advanced usage)");
113 static unsigned verbose = 3;
114 module_param(verbose, uint, 0);
115 MODULE_PARM_DESC(verbose,
116 "0 silent, >0 show gpios, >1 show devices, >2 show devices before (default=3)");
119 struct fbtft_device_display {
121 struct spi_board_info *spi;
122 struct platform_device *pdev;
125 static void fbtft_device_pdev_release(struct device *dev);
127 static int write_gpio16_wr_slow(struct fbtft_par *par, void *buf, size_t len);
128 static void adafruit18_green_tab_set_addr_win(struct fbtft_par *par,
129 int xs, int ys, int xe, int ye);
131 #define ADAFRUIT18_GAMMA \
132 "02 1c 07 12 37 32 29 2d 29 25 2B 39 00 01 03 10\n" \
133 "03 1d 07 06 2E 2C 29 2D 2E 2E 37 3F 00 00 02 10"
135 static int hy28b_init_sequence[] = {
136 -1, 0x00e7, 0x0010, -1, 0x0000, 0x0001,
137 -1, 0x0001, 0x0100, -1, 0x0002, 0x0700,
138 -1, 0x0003, 0x1030, -1, 0x0004, 0x0000,
139 -1, 0x0008, 0x0207, -1, 0x0009, 0x0000,
140 -1, 0x000a, 0x0000, -1, 0x000c, 0x0001,
141 -1, 0x000d, 0x0000, -1, 0x000f, 0x0000,
142 -1, 0x0010, 0x0000, -1, 0x0011, 0x0007,
143 -1, 0x0012, 0x0000, -1, 0x0013, 0x0000,
144 -2, 50, -1, 0x0010, 0x1590, -1, 0x0011,
145 0x0227, -2, 50, -1, 0x0012, 0x009c, -2, 50,
146 -1, 0x0013, 0x1900, -1, 0x0029, 0x0023,
147 -1, 0x002b, 0x000e, -2, 50,
148 -1, 0x0020, 0x0000, -1, 0x0021, 0x0000,
149 -2, 50, -1, 0x0050, 0x0000,
150 -1, 0x0051, 0x00ef, -1, 0x0052, 0x0000,
151 -1, 0x0053, 0x013f, -1, 0x0060, 0xa700,
152 -1, 0x0061, 0x0001, -1, 0x006a, 0x0000,
153 -1, 0x0080, 0x0000, -1, 0x0081, 0x0000,
154 -1, 0x0082, 0x0000, -1, 0x0083, 0x0000,
155 -1, 0x0084, 0x0000, -1, 0x0085, 0x0000,
156 -1, 0x0090, 0x0010, -1, 0x0092, 0x0000,
157 -1, 0x0093, 0x0003, -1, 0x0095, 0x0110,
158 -1, 0x0097, 0x0000, -1, 0x0098, 0x0000,
159 -1, 0x0007, 0x0133, -1, 0x0020, 0x0000,
160 -1, 0x0021, 0x0000, -2, 100, -3 };
162 #define HY28B_GAMMA \
163 "04 1F 4 7 7 0 7 7 6 0\n" \
164 "0F 00 1 7 4 0 0 0 6 7"
166 static int pitft_init_sequence[] = {
167 -1, 0x01, -2, 5, -1, 0x28, -1, 0xEF,
168 0x03, 0x80, 0x02, -1, 0xCF, 0x00, 0xC1, 0x30,
169 -1, 0xED, 0x64, 0x03, 0x12, 0x81,
170 -1, 0xE8, 0x85, 0x00, 0x78,
171 -1, 0xCB, 0x39, 0x2C, 0x00, 0x34, 0x02,
172 -1, 0xF7, 0x20, -1, 0xEA, 0x00, 0x00,
173 -1, 0xC0, 0x23, -1, 0xC1, 0x10, -1, 0xC5,
174 0x3e, 0x28, -1, 0xC7, 0x86, -1, 0x3A, 0x55,
175 -1, 0xB1, 0x00, 0x18, -1, 0xB6, 0x08, 0x82,
176 0x27, -1, 0xF2, 0x00, -1, 0x26, 0x01,
177 -1, 0xE0, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08,
178 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03,
179 0x0E, 0x09, 0x00, -1, 0xE1, 0x00, 0x0E, 0x14,
180 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48,
181 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F, -1,
182 0x11, -2, 100, -1, 0x29, -2, 20, -3 };
184 static int waveshare32b_init_sequence[] = {
185 -1, 0xCB, 0x39, 0x2C, 0x00, 0x34, 0x02,
186 -1, 0xCF, 0x00, 0xC1, 0x30,
187 -1, 0xE8, 0x85, 0x00, 0x78, -1, 0xEA, 0x00,
188 0x00, -1, 0xED, 0x64, 0x03, 0x12, 0x81,
189 -1, 0xF7, 0x20, -1, 0xC0, 0x23, -1, 0xC1,
190 0x10, -1, 0xC5, 0x3e, 0x28, -1, 0xC7, 0x86,
191 -1, 0x36, 0x28, -1, 0x3A, 0x55, -1, 0xB1, 0x00,
192 0x18, -1, 0xB6, 0x08, 0x82, 0x27,
193 -1, 0xF2, 0x00, -1, 0x26, 0x01,
194 -1, 0xE0, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E,
195 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00,
196 -1, 0xE1, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31,
197 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F,
198 -1, 0x11, -2, 120, -1, 0x29, -1, 0x2c, -3 };
200 /* Supported displays in alphabetical order */
201 static struct fbtft_device_display displays[] = {
203 .name = "adafruit18",
204 .spi = &(struct spi_board_info) {
205 .modalias = "fb_st7735r",
206 .max_speed_hz = 32000000,
208 .platform_data = &(struct fbtft_platform_data) {
213 .gpios = (const struct fbtft_gpio []) {
219 .gamma = ADAFRUIT18_GAMMA,
223 .name = "adafruit18_green",
224 .spi = &(struct spi_board_info) {
225 .modalias = "fb_st7735r",
226 .max_speed_hz = 4000000,
228 .platform_data = &(struct fbtft_platform_data) {
232 .fbtftops.set_addr_win =
233 adafruit18_green_tab_set_addr_win,
236 .gpios = (const struct fbtft_gpio []) {
242 .gamma = ADAFRUIT18_GAMMA,
246 .name = "adafruit22",
247 .spi = &(struct spi_board_info) {
248 .modalias = "fb_hx8340bn",
249 .max_speed_hz = 32000000,
251 .platform_data = &(struct fbtft_platform_data) {
257 .gpios = (const struct fbtft_gpio []) {
265 .name = "adafruit22a",
266 .spi = &(struct spi_board_info) {
267 .modalias = "fb_ili9340",
268 .max_speed_hz = 32000000,
270 .platform_data = &(struct fbtft_platform_data) {
276 .gpios = (const struct fbtft_gpio []) {
285 .name = "adafruit28",
286 .spi = &(struct spi_board_info) {
287 .modalias = "fb_ili9341",
288 .max_speed_hz = 32000000,
290 .platform_data = &(struct fbtft_platform_data) {
296 .gpios = (const struct fbtft_gpio []) {
305 .name = "adafruit13m",
306 .spi = &(struct spi_board_info) {
307 .modalias = "fb_ssd1306",
308 .max_speed_hz = 16000000,
310 .platform_data = &(struct fbtft_platform_data) {
314 .gpios = (const struct fbtft_gpio []) {
322 .name = "agm1264k-fl",
323 .pdev = &(struct platform_device) {
324 .name = "fb_agm1264k-fl",
327 .release = fbtft_device_pdev_release,
328 .platform_data = &(struct fbtft_platform_data) {
331 .backlight = FBTFT_ONBOARD_BACKLIGHT,
333 .gpios = (const struct fbtft_gpio []) {
341 .spi = &(struct spi_board_info) {
342 .modalias = "fb_uc1701",
343 .max_speed_hz = 8000000,
345 .platform_data = &(struct fbtft_platform_data) {
350 .gpios = (const struct fbtft_gpio []) {
358 .name = "er_tftm050_2",
359 .spi = &(struct spi_board_info) {
360 .modalias = "fb_ra8875",
361 .max_speed_hz = 5000000,
363 .platform_data = &(struct fbtft_platform_data) {
371 .gpios = (const struct fbtft_gpio []) {
379 .name = "er_tftm070_5",
380 .spi = &(struct spi_board_info) {
381 .modalias = "fb_ra8875",
382 .max_speed_hz = 5000000,
384 .platform_data = &(struct fbtft_platform_data) {
392 .gpios = (const struct fbtft_gpio []) {
401 .spi = &(struct spi_board_info) {
402 .modalias = "flexfb",
403 .max_speed_hz = 32000000,
405 .platform_data = &(struct fbtft_platform_data) {
406 .gpios = (const struct fbtft_gpio []) {
415 .pdev = &(struct platform_device) {
419 .release = fbtft_device_pdev_release,
420 .platform_data = &(struct fbtft_platform_data) {
421 .gpios = (const struct fbtft_gpio []) {
441 .name = "freetronicsoled128",
442 .spi = &(struct spi_board_info) {
443 .modalias = "fb_ssd1351",
444 .max_speed_hz = 20000000,
446 .platform_data = &(struct fbtft_platform_data) {
449 .backlight = FBTFT_ONBOARD_BACKLIGHT,
452 .gpios = (const struct fbtft_gpio []) {
461 .spi = &(struct spi_board_info) {
462 .modalias = "fb_hx8353d",
463 .max_speed_hz = 16000000,
465 .platform_data = &(struct fbtft_platform_data) {
470 .gpios = (const struct fbtft_gpio []) {
480 .spi = &(struct spi_board_info) {
481 .modalias = "fb_ili9320",
482 .max_speed_hz = 32000000,
484 .platform_data = &(struct fbtft_platform_data) {
491 .gpios = (const struct fbtft_gpio []) {
500 .spi = &(struct spi_board_info) {
501 .modalias = "fb_ili9325",
502 .max_speed_hz = 48000000,
504 .platform_data = &(struct fbtft_platform_data) {
508 .init_sequence = hy28b_init_sequence,
513 .gpios = (const struct fbtft_gpio []) {
518 .gamma = HY28B_GAMMA,
523 .spi = &(struct spi_board_info) {
524 .modalias = "fb_ili9481",
525 .max_speed_hz = 32000000,
527 .platform_data = &(struct fbtft_platform_data) {
534 .gpios = (const struct fbtft_gpio []) {
544 .pdev = &(struct platform_device) {
545 .name = "fb_s6d1121",
548 .release = fbtft_device_pdev_release,
549 .platform_data = &(struct fbtft_platform_data) {
555 .gpios = (const struct fbtft_gpio []) {
556 /* Wiring for LCD adapter kit */
558 { "dc", 0 }, /* rev 2: 2 */
559 { "wr", 1 }, /* rev 2: 3 */
563 { "db02", 21 }, /* rev 2: 27 */
576 .pdev = &(struct platform_device) {
577 .name = "fb_ili9325",
580 .release = fbtft_device_pdev_release,
581 .platform_data = &(struct fbtft_platform_data) {
587 .gpios = (const struct fbtft_gpio []) {
594 .name = "itdb28_spi",
595 .spi = &(struct spi_board_info) {
596 .modalias = "fb_ili9325",
597 .max_speed_hz = 32000000,
599 .platform_data = &(struct fbtft_platform_data) {
605 .gpios = (const struct fbtft_gpio []) {
613 .name = "mi0283qt-2",
614 .spi = &(struct spi_board_info) {
615 .modalias = "fb_hx8347d",
616 .max_speed_hz = 32000000,
618 .platform_data = &(struct fbtft_platform_data) {
625 .gpios = (const struct fbtft_gpio []) {
634 .name = "mi0283qt-9a",
635 .spi = &(struct spi_board_info) {
636 .modalias = "fb_ili9341",
637 .max_speed_hz = 32000000,
639 .platform_data = &(struct fbtft_platform_data) {
645 .gpios = (const struct fbtft_gpio []) {
653 .name = "mi0283qt-v2",
654 .spi = &(struct spi_board_info) {
655 .modalias = "fb_watterott",
656 .max_speed_hz = 4000000,
658 .platform_data = &(struct fbtft_platform_data) {
659 .gpios = (const struct fbtft_gpio []) {
667 .spi = &(struct spi_board_info) {
668 .modalias = "fb_pcd8544",
669 .max_speed_hz = 400000,
671 .platform_data = &(struct fbtft_platform_data) {
675 .gpios = (const struct fbtft_gpio []) {
684 .name = "nokia3310a",
685 .spi = &(struct spi_board_info) {
686 .modalias = "fb_tls8204",
687 .max_speed_hz = 1000000,
689 .platform_data = &(struct fbtft_platform_data) {
693 .gpios = (const struct fbtft_gpio []) {
703 .spi = &(struct spi_board_info) {
704 .modalias = "fb_ili9163",
705 .max_speed_hz = 12000000,
707 .platform_data = &(struct fbtft_platform_data) {
713 .gpios = (const struct fbtft_gpio []) {
721 .spi = &(struct spi_board_info) {
722 .modalias = "fb_ili9486",
723 .max_speed_hz = 32000000,
725 .platform_data = &(struct fbtft_platform_data) {
732 .gpios = (const struct fbtft_gpio []) {
742 .spi = &(struct spi_board_info) {
743 .modalias = "fb_ili9340",
744 .max_speed_hz = 32000000,
747 .platform_data = &(struct fbtft_platform_data) {
751 .init_sequence = pitft_init_sequence,
754 .gpios = (const struct fbtft_gpio []) {
762 .spi = &(struct spi_board_info) {
763 .modalias = "fb_ssd1351",
764 .max_speed_hz = 20000000,
766 .platform_data = &(struct fbtft_platform_data) {
771 .gpios = (const struct fbtft_gpio []) {
776 .gamma = "0 2 2 2 2 2 2 2 "
787 .name = "rpi-display",
788 .spi = &(struct spi_board_info) {
789 .modalias = "fb_ili9341",
790 .max_speed_hz = 32000000,
792 .platform_data = &(struct fbtft_platform_data) {
798 .gpios = (const struct fbtft_gpio []) {
808 .spi = &(struct spi_board_info) {
809 .modalias = "fb_s6d02a1",
810 .max_speed_hz = 32000000,
812 .platform_data = &(struct fbtft_platform_data) {
818 .gpios = (const struct fbtft_gpio []) {
827 .name = "sainsmart18",
828 .spi = &(struct spi_board_info) {
829 .modalias = "fb_st7735r",
830 .max_speed_hz = 32000000,
832 .platform_data = &(struct fbtft_platform_data) {
836 .gpios = (const struct fbtft_gpio []) {
844 .name = "sainsmart32",
845 .pdev = &(struct platform_device) {
846 .name = "fb_ssd1289",
849 .release = fbtft_device_pdev_release,
850 .platform_data = &(struct fbtft_platform_data) {
853 .txbuflen = -2, /* disable buffer */
855 .fbtftops.write = write_gpio16_wr_slow,
858 .gpios = (const struct fbtft_gpio []) {
865 .name = "sainsmart32_fast",
866 .pdev = &(struct platform_device) {
867 .name = "fb_ssd1289",
870 .release = fbtft_device_pdev_release,
871 .platform_data = &(struct fbtft_platform_data) {
874 .txbuflen = -2, /* disable buffer */
878 .gpios = (const struct fbtft_gpio []) {
885 .name = "sainsmart32_latched",
886 .pdev = &(struct platform_device) {
887 .name = "fb_ssd1289",
890 .release = fbtft_device_pdev_release,
891 .platform_data = &(struct fbtft_platform_data) {
894 .txbuflen = -2, /* disable buffer */
897 fbtft_write_gpio16_wr_latched,
900 .gpios = (const struct fbtft_gpio []) {
907 .name = "sainsmart32_spi",
908 .spi = &(struct spi_board_info) {
909 .modalias = "fb_ssd1289",
910 .max_speed_hz = 16000000,
912 .platform_data = &(struct fbtft_platform_data) {
918 .gpios = (const struct fbtft_gpio []) {
927 .spi = &(struct spi_board_info) {
928 .modalias = "spidev",
929 .max_speed_hz = 500000,
933 .platform_data = &(struct fbtft_platform_data) {
934 .gpios = (const struct fbtft_gpio []) {
941 .spi = &(struct spi_board_info) {
942 .modalias = "fb_ssd1331",
943 .max_speed_hz = 20000000,
945 .platform_data = &(struct fbtft_platform_data) {
949 .gpios = (const struct fbtft_gpio []) {
958 .spi = &(struct spi_board_info) {
959 .modalias = "fb_tinylcd",
960 .max_speed_hz = 32000000,
962 .platform_data = &(struct fbtft_platform_data) {
968 .gpios = (const struct fbtft_gpio []) {
977 .name = "tm022hdh26",
978 .spi = &(struct spi_board_info) {
979 .modalias = "fb_ili9341",
980 .max_speed_hz = 32000000,
982 .platform_data = &(struct fbtft_platform_data) {
988 .gpios = (const struct fbtft_gpio []) {
997 .name = "tontec35_9481", /* boards before 02 July 2014 */
998 .spi = &(struct spi_board_info) {
999 .modalias = "fb_ili9481",
1000 .max_speed_hz = 128000000,
1002 .platform_data = &(struct fbtft_platform_data) {
1008 .gpios = (const struct fbtft_gpio []) {
1017 .name = "tontec35_9486", /* boards after 02 July 2014 */
1018 .spi = &(struct spi_board_info) {
1019 .modalias = "fb_ili9486",
1020 .max_speed_hz = 128000000,
1022 .platform_data = &(struct fbtft_platform_data) {
1028 .gpios = (const struct fbtft_gpio []) {
1037 .name = "upd161704",
1038 .spi = &(struct spi_board_info) {
1039 .modalias = "fb_upd161704",
1040 .max_speed_hz = 32000000,
1042 .platform_data = &(struct fbtft_platform_data) {
1046 .gpios = (const struct fbtft_gpio []) {
1054 .name = "waveshare32b",
1055 .spi = &(struct spi_board_info) {
1056 .modalias = "fb_ili9340",
1057 .max_speed_hz = 48000000,
1059 .platform_data = &(struct fbtft_platform_data) {
1064 waveshare32b_init_sequence,
1067 .gpios = (const struct fbtft_gpio []) {
1075 .name = "waveshare22",
1076 .spi = &(struct spi_board_info) {
1077 .modalias = "fb_bd663474",
1078 .max_speed_hz = 32000000,
1080 .platform_data = &(struct fbtft_platform_data) {
1084 .gpios = (const struct fbtft_gpio []) {
1092 /* This should be the last item.
1093 Used with the custom argument */
1095 .spi = &(struct spi_board_info) {
1099 .platform_data = &(struct fbtft_platform_data) {
1100 .gpios = (const struct fbtft_gpio []) {
1105 .pdev = &(struct platform_device) {
1109 .release = fbtft_device_pdev_release,
1110 .platform_data = &(struct fbtft_platform_data) {
1111 .gpios = (const struct fbtft_gpio []) {
1120 static int write_gpio16_wr_slow(struct fbtft_par *par, void *buf, size_t len)
1124 #ifndef DO_NOT_OPTIMIZE_FBTFT_WRITE_GPIO
1125 static u16 prev_data;
1128 fbtft_par_dbg_hex(DEBUG_WRITE, par, par->info->device, u8, buf, len,
1129 "%s(len=%d): ", __func__, len);
1132 data = *(u16 *) buf;
1134 /* Start writing by pulling down /WR */
1135 gpio_set_value(par->gpio.wr, 0);
1138 #ifndef DO_NOT_OPTIMIZE_FBTFT_WRITE_GPIO
1139 if (data == prev_data) {
1140 gpio_set_value(par->gpio.wr, 0); /* used as delay */
1142 for (i = 0; i < 16; i++) {
1143 if ((data & 1) != (prev_data & 1))
1144 gpio_set_value(par->gpio.db[i],
1151 for (i = 0; i < 16; i++) {
1152 gpio_set_value(par->gpio.db[i], data & 1);
1158 gpio_set_value(par->gpio.wr, 1);
1160 #ifndef DO_NOT_OPTIMIZE_FBTFT_WRITE_GPIO
1161 prev_data = *(u16 *) buf;
1170 static void adafruit18_green_tab_set_addr_win(struct fbtft_par *par,
1171 int xs, int ys, int xe, int ye)
1173 fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
1174 "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
1175 write_reg(par, 0x2A, 0, xs + 2, 0, xe + 2);
1176 write_reg(par, 0x2B, 0, ys + 1, 0, ye + 1);
1177 write_reg(par, 0x2C);
1180 /* used if gpios parameter is present */
1181 static struct fbtft_gpio fbtft_device_param_gpios[MAX_GPIOS+1] = { };
1183 static void fbtft_device_pdev_release(struct device *dev)
1185 /* Needed to silence this message:
1186 Device 'xxx' does not have a release() function, it is broken and must be fixed
1190 static int spi_device_found(struct device *dev, void *data)
1192 struct spi_device *spi = container_of(dev, struct spi_device, dev);
1194 pr_info(DRVNAME": %s %s %dkHz %d bits mode=0x%02X\n",
1195 spi->modalias, dev_name(dev), spi->max_speed_hz/1000,
1196 spi->bits_per_word, spi->mode);
1201 static void pr_spi_devices(void)
1203 pr_info(DRVNAME": SPI devices registered:\n");
1204 bus_for_each_dev(&spi_bus_type, NULL, NULL, spi_device_found);
1207 static int p_device_found(struct device *dev, void *data)
1209 struct platform_device
1210 *pdev = container_of(dev, struct platform_device, dev);
1212 if (strstr(pdev->name, "fb"))
1213 pr_info(DRVNAME": %s id=%d pdata? %s\n",
1214 pdev->name, pdev->id,
1215 pdev->dev.platform_data ? "yes" : "no");
1220 static void pr_p_devices(void)
1222 pr_info(DRVNAME": 'fb' Platform devices registered:\n");
1223 bus_for_each_dev(&platform_bus_type, NULL, NULL, p_device_found);
1227 static void fbtft_device_spi_delete(struct spi_master *master, unsigned cs)
1232 snprintf(str, sizeof(str), "%s.%u", dev_name(&master->dev), cs);
1234 dev = bus_find_device_by_name(&spi_bus_type, NULL, str);
1237 pr_info(DRVNAME": Deleting %s\n", str);
1242 static int fbtft_device_spi_device_register(struct spi_board_info *spi)
1244 struct spi_master *master;
1246 master = spi_busnum_to_master(spi->bus_num);
1248 pr_err(DRVNAME ": spi_busnum_to_master(%d) returned NULL\n",
1252 /* make sure it's available */
1253 fbtft_device_spi_delete(master, spi->chip_select);
1254 spi_device = spi_new_device(master, spi);
1255 put_device(&master->dev);
1257 pr_err(DRVNAME ": spi_new_device() returned NULL\n");
1263 static int fbtft_device_spi_device_register(struct spi_board_info *spi)
1265 return spi_register_board_info(spi, 1);
1269 static int __init fbtft_device_init(void)
1271 struct spi_board_info *spi = NULL;
1272 struct fbtft_platform_data *pdata;
1273 const struct fbtft_gpio *gpio = NULL;
1274 char *p_gpio, *p_name, *p_num;
1280 pr_debug("\n\n"DRVNAME": init\n");
1284 pr_err(DRVNAME": missing module parameter: 'name'\n");
1291 if (init_num > FBTFT_MAX_INIT_SEQUENCE) {
1293 ": init parameter: exceeded max array size: %d\n",
1294 FBTFT_MAX_INIT_SEQUENCE);
1298 /* parse module parameter: gpios */
1299 while ((p_gpio = strsep(&gpios, ","))) {
1300 if (strchr(p_gpio, ':') == NULL) {
1302 ": error: missing ':' in gpios parameter: %s\n",
1307 p_name = strsep(&p_num, ":");
1308 if (p_name == NULL || p_num == NULL) {
1310 ": something bad happened parsing gpios parameter: %s\n",
1314 ret = kstrtol(p_num, 10, &val);
1317 ": could not parse number in gpios parameter: %s:%s\n",
1321 strcpy(fbtft_device_param_gpios[i].name, p_name);
1322 fbtft_device_param_gpios[i++].gpio = (int) val;
1323 if (i == MAX_GPIOS) {
1325 ": gpios parameter: exceeded max array size: %d\n",
1330 if (fbtft_device_param_gpios[0].name[0])
1331 gpio = fbtft_device_param_gpios;
1334 pr_spi_devices(); /* print list of registered SPI devices */
1337 pr_p_devices(); /* print list of 'fb' platform devices */
1339 pr_debug(DRVNAME": name='%s', busnum=%d, cs=%d\n", name, busnum, cs);
1341 if (rotate > 0 && rotate < 4) {
1342 rotate = (4 - rotate) * 90;
1343 pr_warn("argument 'rotate' should be an angle. Values 1-3 is deprecated. Setting it to %d.\n",
1346 if (rotate != 0 && rotate != 90 && rotate != 180 && rotate != 270) {
1347 pr_warn("argument 'rotate' illegal value: %d. Setting it to 0.\n",
1352 /* name=list lists all supported displays */
1353 if (strncmp(name, "list", 32) == 0) {
1354 pr_info(DRVNAME": Supported displays:\n");
1356 for (i = 0; i < ARRAY_SIZE(displays); i++)
1357 pr_info(DRVNAME": %s\n", displays[i].name);
1362 i = ARRAY_SIZE(displays) - 1;
1363 displays[i].name = name;
1365 displays[i].pdev->name = name;
1366 displays[i].spi = NULL;
1368 strncpy(displays[i].spi->modalias, name, SPI_NAME_SIZE);
1369 displays[i].pdev = NULL;
1373 for (i = 0; i < ARRAY_SIZE(displays); i++) {
1374 if (strncmp(name, displays[i].name, 32) == 0) {
1375 if (displays[i].spi) {
1376 spi = displays[i].spi;
1377 spi->chip_select = cs;
1378 spi->bus_num = busnum;
1380 spi->max_speed_hz = speed;
1383 pdata = (void *)spi->platform_data;
1384 } else if (displays[i].pdev) {
1385 p_device = displays[i].pdev;
1386 pdata = p_device->dev.platform_data;
1388 pr_err(DRVNAME": broken displays array\n");
1392 pdata->rotate = rotate;
1398 pdata->startbyte = startbyte;
1400 pdata->gamma = gamma;
1401 pdata->display.debug = debug;
1405 pdata->txbuflen = txbuflen;
1407 pdata->display.init_sequence = init;
1409 pdata->gpios = gpio;
1411 pdata->display.width = width;
1412 pdata->display.height = height;
1413 pdata->display.buswidth = buswidth;
1414 pdata->display.backlight = 1;
1417 if (displays[i].spi) {
1418 ret = fbtft_device_spi_device_register(spi);
1421 ": failed to register SPI device\n");
1425 ret = platform_device_register(p_device);
1428 ": platform_device_register() returned %d\n",
1439 pr_err(DRVNAME": display not supported: '%s'\n", name);
1443 if (verbose && pdata && pdata->gpios) {
1444 gpio = pdata->gpios;
1445 pr_info(DRVNAME": GPIOS used by '%s':\n", name);
1447 while (verbose && gpio->name[0]) {
1448 pr_info(DRVNAME": '%s' = GPIO%d\n",
1449 gpio->name, gpio->gpio);
1454 pr_info(DRVNAME": (none)\n");
1457 if (spi_device && (verbose > 1))
1459 if (p_device && (verbose > 1))
1465 static void __exit fbtft_device_exit(void)
1467 pr_debug(DRVNAME" - exit\n");
1470 device_del(&spi_device->dev);
1475 platform_device_unregister(p_device);
1479 arch_initcall(fbtft_device_init);
1480 module_exit(fbtft_device_exit);
1482 MODULE_DESCRIPTION("Add a FBTFT device.");
1483 MODULE_AUTHOR("Noralf Tronnes");
1484 MODULE_LICENSE("GPL");