xref: /openbmc/linux/drivers/staging/fbtft/fbtft.h (revision 0e8cf2be)
1783de57cSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0+ */
278c00cccSGreg Kroah-Hartman /* Copyright (C) 2013 Noralf Tronnes */
3c296d5f9SThomas Petazzoni 
4c296d5f9SThomas Petazzoni #ifndef __LINUX_FBTFT_H
5c296d5f9SThomas Petazzoni #define __LINUX_FBTFT_H
6c296d5f9SThomas Petazzoni 
7c296d5f9SThomas Petazzoni #include <linux/fb.h>
8c296d5f9SThomas Petazzoni #include <linux/spinlock.h>
9c296d5f9SThomas Petazzoni #include <linux/spi/spi.h>
10c296d5f9SThomas Petazzoni #include <linux/platform_device.h>
11c296d5f9SThomas Petazzoni 
12c296d5f9SThomas Petazzoni #define FBTFT_ONBOARD_BACKLIGHT 2
13c296d5f9SThomas Petazzoni 
14c296d5f9SThomas Petazzoni #define FBTFT_GPIO_NO_MATCH		0xFFFF
15c296d5f9SThomas Petazzoni #define FBTFT_GPIO_NAME_SIZE	32
16c296d5f9SThomas Petazzoni #define FBTFT_MAX_INIT_SEQUENCE      512
17c296d5f9SThomas Petazzoni #define FBTFT_GAMMA_MAX_VALUES_TOTAL 128
18c296d5f9SThomas Petazzoni 
19c296d5f9SThomas Petazzoni #define FBTFT_OF_INIT_CMD	BIT(24)
20c296d5f9SThomas Petazzoni #define FBTFT_OF_INIT_DELAY	BIT(25)
21c296d5f9SThomas Petazzoni 
22c296d5f9SThomas Petazzoni /**
23c296d5f9SThomas Petazzoni  * struct fbtft_gpio - Structure that holds one pinname to gpio mapping
24c296d5f9SThomas Petazzoni  * @name: pinname (reset, dc, etc.)
25c296d5f9SThomas Petazzoni  * @gpio: GPIO number
26c296d5f9SThomas Petazzoni  *
27c296d5f9SThomas Petazzoni  */
28c296d5f9SThomas Petazzoni struct fbtft_gpio {
29c296d5f9SThomas Petazzoni 	char name[FBTFT_GPIO_NAME_SIZE];
30c440eee1SNishad Kamdar 	struct gpio_desc *gpio;
31c296d5f9SThomas Petazzoni };
32c296d5f9SThomas Petazzoni 
33c296d5f9SThomas Petazzoni struct fbtft_par;
34c296d5f9SThomas Petazzoni 
35c296d5f9SThomas Petazzoni /**
36c296d5f9SThomas Petazzoni  * struct fbtft_ops - FBTFT operations structure
37c296d5f9SThomas Petazzoni  * @write: Writes to interface bus
38c296d5f9SThomas Petazzoni  * @read: Reads from interface bus
39c296d5f9SThomas Petazzoni  * @write_vmem: Writes video memory to display
40c296d5f9SThomas Petazzoni  * @write_reg: Writes to controller register
41c296d5f9SThomas Petazzoni  * @set_addr_win: Set the GRAM update window
42c296d5f9SThomas Petazzoni  * @reset: Reset the LCD controller
43c296d5f9SThomas Petazzoni  * @mkdirty: Marks display lines for update
44c296d5f9SThomas Petazzoni  * @update_display: Updates the display
45c296d5f9SThomas Petazzoni  * @init_display: Initializes the display
46c296d5f9SThomas Petazzoni  * @blank: Blank the display (optional)
47c296d5f9SThomas Petazzoni  * @request_gpios_match: Do pinname to gpio matching
48c296d5f9SThomas Petazzoni  * @request_gpios: Request gpios from the kernel
49c296d5f9SThomas Petazzoni  * @free_gpios: Free previously requested gpios
50c296d5f9SThomas Petazzoni  * @verify_gpios: Verify that necessary gpios is present (optional)
51c296d5f9SThomas Petazzoni  * @register_backlight: Used to register backlight device (optional)
52c296d5f9SThomas Petazzoni  * @unregister_backlight: Unregister backlight device (optional)
53c296d5f9SThomas Petazzoni  * @set_var: Configure LCD with values from variables like @rotate and @bgr
54c296d5f9SThomas Petazzoni  *           (optional)
55c296d5f9SThomas Petazzoni  * @set_gamma: Set Gamma curve (optional)
56c296d5f9SThomas Petazzoni  *
57c296d5f9SThomas Petazzoni  * Most of these operations have default functions assigned to them in
58c296d5f9SThomas Petazzoni  *     fbtft_framebuffer_alloc()
59c296d5f9SThomas Petazzoni  */
60c296d5f9SThomas Petazzoni struct fbtft_ops {
61c296d5f9SThomas Petazzoni 	int (*write)(struct fbtft_par *par, void *buf, size_t len);
62c296d5f9SThomas Petazzoni 	int (*read)(struct fbtft_par *par, void *buf, size_t len);
63c296d5f9SThomas Petazzoni 	int (*write_vmem)(struct fbtft_par *par, size_t offset, size_t len);
64c296d5f9SThomas Petazzoni 	void (*write_register)(struct fbtft_par *par, int len, ...);
65c296d5f9SThomas Petazzoni 
66c296d5f9SThomas Petazzoni 	void (*set_addr_win)(struct fbtft_par *par,
67c296d5f9SThomas Petazzoni 			     int xs, int ys, int xe, int ye);
68c296d5f9SThomas Petazzoni 	void (*reset)(struct fbtft_par *par);
69c296d5f9SThomas Petazzoni 	void (*mkdirty)(struct fb_info *info, int from, int to);
70c296d5f9SThomas Petazzoni 	void (*update_display)(struct fbtft_par *par,
711c41494aSMing Yang 			       unsigned int start_line, unsigned int end_line);
72c296d5f9SThomas Petazzoni 	int (*init_display)(struct fbtft_par *par);
73c296d5f9SThomas Petazzoni 	int (*blank)(struct fbtft_par *par, bool on);
74c296d5f9SThomas Petazzoni 
75c296d5f9SThomas Petazzoni 	unsigned long (*request_gpios_match)(struct fbtft_par *par,
76c296d5f9SThomas Petazzoni 					     const struct fbtft_gpio *gpio);
77c296d5f9SThomas Petazzoni 	int (*request_gpios)(struct fbtft_par *par);
78c296d5f9SThomas Petazzoni 	int (*verify_gpios)(struct fbtft_par *par);
79c296d5f9SThomas Petazzoni 
80c296d5f9SThomas Petazzoni 	void (*register_backlight)(struct fbtft_par *par);
81c296d5f9SThomas Petazzoni 	void (*unregister_backlight)(struct fbtft_par *par);
82c296d5f9SThomas Petazzoni 
83c296d5f9SThomas Petazzoni 	int (*set_var)(struct fbtft_par *par);
8422eb36b8SArnd Bergmann 	int (*set_gamma)(struct fbtft_par *par, u32 *curves);
85c296d5f9SThomas Petazzoni };
86c296d5f9SThomas Petazzoni 
87c296d5f9SThomas Petazzoni /**
88c296d5f9SThomas Petazzoni  * struct fbtft_display - Describes the display properties
89c296d5f9SThomas Petazzoni  * @width: Width of display in pixels
90c296d5f9SThomas Petazzoni  * @height: Height of display in pixels
91c296d5f9SThomas Petazzoni  * @regwidth: LCD Controller Register width in bits
92c296d5f9SThomas Petazzoni  * @buswidth: Display interface bus width in bits
93c296d5f9SThomas Petazzoni  * @backlight: Backlight type.
94c296d5f9SThomas Petazzoni  * @fbtftops: FBTFT operations provided by driver or device (platform_data)
95c296d5f9SThomas Petazzoni  * @bpp: Bits per pixel
96c296d5f9SThomas Petazzoni  * @fps: Frames per second
97c296d5f9SThomas Petazzoni  * @txbuflen: Size of transmit buffer
98c296d5f9SThomas Petazzoni  * @init_sequence: Pointer to LCD initialization array
99c296d5f9SThomas Petazzoni  * @gamma: String representation of Gamma curve(s)
100c296d5f9SThomas Petazzoni  * @gamma_num: Number of Gamma curves
101c296d5f9SThomas Petazzoni  * @gamma_len: Number of values per Gamma curve
102c296d5f9SThomas Petazzoni  * @debug: Initial debug value
103c296d5f9SThomas Petazzoni  *
104c296d5f9SThomas Petazzoni  * This structure is not stored by FBTFT except for init_sequence.
105c296d5f9SThomas Petazzoni  */
106c296d5f9SThomas Petazzoni struct fbtft_display {
1071c41494aSMing Yang 	unsigned int width;
1081c41494aSMing Yang 	unsigned int height;
1091c41494aSMing Yang 	unsigned int regwidth;
1101c41494aSMing Yang 	unsigned int buswidth;
1111c41494aSMing Yang 	unsigned int backlight;
112c296d5f9SThomas Petazzoni 	struct fbtft_ops fbtftops;
1131c41494aSMing Yang 	unsigned int bpp;
1141c41494aSMing Yang 	unsigned int fps;
115c296d5f9SThomas Petazzoni 	int txbuflen;
1160a859b31SJoe Perches 	const s16 *init_sequence;
117c296d5f9SThomas Petazzoni 	char *gamma;
118c296d5f9SThomas Petazzoni 	int gamma_num;
119c296d5f9SThomas Petazzoni 	int gamma_len;
120c296d5f9SThomas Petazzoni 	unsigned long debug;
121c296d5f9SThomas Petazzoni };
122c296d5f9SThomas Petazzoni 
123c296d5f9SThomas Petazzoni /**
124c296d5f9SThomas Petazzoni  * struct fbtft_platform_data - Passes display specific data to the driver
125c296d5f9SThomas Petazzoni  * @display: Display properties
12692def781SMasanari Iida  * @gpios: Pointer to an array of pinname to gpio mappings
127c296d5f9SThomas Petazzoni  * @rotate: Display rotation angle
128c296d5f9SThomas Petazzoni  * @bgr: LCD Controller BGR bit
129c296d5f9SThomas Petazzoni  * @fps: Frames per second (this will go away, use @fps in @fbtft_display)
130c296d5f9SThomas Petazzoni  * @txbuflen: Size of transmit buffer
131c296d5f9SThomas Petazzoni  * @startbyte: When set, enables use of Startbyte in transfers
132c296d5f9SThomas Petazzoni  * @gamma: String representation of Gamma curve(s)
133c296d5f9SThomas Petazzoni  * @extra: A way to pass extra info
134c296d5f9SThomas Petazzoni  */
135c296d5f9SThomas Petazzoni struct fbtft_platform_data {
136c296d5f9SThomas Petazzoni 	struct fbtft_display display;
1371c41494aSMing Yang 	unsigned int rotate;
138c296d5f9SThomas Petazzoni 	bool bgr;
1391c41494aSMing Yang 	unsigned int fps;
140c296d5f9SThomas Petazzoni 	int txbuflen;
141c296d5f9SThomas Petazzoni 	u8 startbyte;
142c296d5f9SThomas Petazzoni 	char *gamma;
143c296d5f9SThomas Petazzoni 	void *extra;
144c296d5f9SThomas Petazzoni };
145c296d5f9SThomas Petazzoni 
146c296d5f9SThomas Petazzoni /**
147c296d5f9SThomas Petazzoni  * struct fbtft_par - Main FBTFT data structure
148c296d5f9SThomas Petazzoni  *
149c296d5f9SThomas Petazzoni  * This structure holds all relevant data to operate the display
150c296d5f9SThomas Petazzoni  *
151c296d5f9SThomas Petazzoni  * See sourcefile for documentation since nested structs is not
152c296d5f9SThomas Petazzoni  * supported by kernel-doc.
153c296d5f9SThomas Petazzoni  *
154c296d5f9SThomas Petazzoni  */
155c296d5f9SThomas Petazzoni /* @spi: Set if it is a SPI device
156c296d5f9SThomas Petazzoni  * @pdev: Set if it is a platform device
157c296d5f9SThomas Petazzoni  * @info: Pointer to framebuffer fb_info structure
158c296d5f9SThomas Petazzoni  * @pdata: Pointer to platform data
159c296d5f9SThomas Petazzoni  * @ssbuf: Not used
160c296d5f9SThomas Petazzoni  * @pseudo_palette: Used by fb_set_colreg()
161c296d5f9SThomas Petazzoni  * @txbuf.buf: Transmit buffer
162c296d5f9SThomas Petazzoni  * @txbuf.len: Transmit buffer length
163c296d5f9SThomas Petazzoni  * @buf: Small buffer used when writing init data over SPI
164c296d5f9SThomas Petazzoni  * @startbyte: Used by some controllers when in SPI mode.
165c296d5f9SThomas Petazzoni  *             Format: 6 bit Device id + RS bit + RW bit
166c296d5f9SThomas Petazzoni  * @fbtftops: FBTFT operations provided by driver or device (platform_data)
167c296d5f9SThomas Petazzoni  * @dirty_lock: Protects dirty_lines_start and dirty_lines_end
168c296d5f9SThomas Petazzoni  * @dirty_lines_start: Where to begin updating display
169c296d5f9SThomas Petazzoni  * @dirty_lines_end: Where to end updating display
170c296d5f9SThomas Petazzoni  * @gpio.reset: GPIO used to reset display
171c296d5f9SThomas Petazzoni  * @gpio.dc: Data/Command signal, also known as RS
172c296d5f9SThomas Petazzoni  * @gpio.rd: Read latching signal
173c296d5f9SThomas Petazzoni  * @gpio.wr: Write latching signal
174c296d5f9SThomas Petazzoni  * @gpio.latch: Bus latch signal, eg. 16->8 bit bus latch
175c296d5f9SThomas Petazzoni  * @gpio.cs: LCD Chip Select with parallel interface bus
176c296d5f9SThomas Petazzoni  * @gpio.db[16]: Parallel databus
177c296d5f9SThomas Petazzoni  * @gpio.led[16]: Led control signals
17892def781SMasanari Iida  * @gpio.aux[16]: Auxiliary signals, not used by core
179c296d5f9SThomas Petazzoni  * @init_sequence: Pointer to LCD initialization array
180c296d5f9SThomas Petazzoni  * @gamma.lock: Mutex for Gamma curve locking
181c296d5f9SThomas Petazzoni  * @gamma.curves: Pointer to Gamma curve array
182c296d5f9SThomas Petazzoni  * @gamma.num_values: Number of values per Gamma curve
183c296d5f9SThomas Petazzoni  * @gamma.num_curves: Number of Gamma curves
184c296d5f9SThomas Petazzoni  * @debug: Pointer to debug value
185c296d5f9SThomas Petazzoni  * @current_debug:
186c296d5f9SThomas Petazzoni  * @first_update_done: Used to only time the first display update
187c296d5f9SThomas Petazzoni  * @update_time: Used to calculate 'fps' in debug output
188c296d5f9SThomas Petazzoni  * @bgr: BGR mode/\n
189c296d5f9SThomas Petazzoni  * @extra: Extra info needed by driver
190c296d5f9SThomas Petazzoni  */
191c296d5f9SThomas Petazzoni struct fbtft_par {
192c296d5f9SThomas Petazzoni 	struct spi_device *spi;
193c296d5f9SThomas Petazzoni 	struct platform_device *pdev;
194c296d5f9SThomas Petazzoni 	struct fb_info *info;
195c296d5f9SThomas Petazzoni 	struct fbtft_platform_data *pdata;
196c296d5f9SThomas Petazzoni 	u16 *ssbuf;
197c296d5f9SThomas Petazzoni 	u32 pseudo_palette[16];
198c296d5f9SThomas Petazzoni 	struct {
199c296d5f9SThomas Petazzoni 		void *buf;
200c296d5f9SThomas Petazzoni 		size_t len;
201c296d5f9SThomas Petazzoni 	} txbuf;
202c296d5f9SThomas Petazzoni 	u8 *buf;
203c296d5f9SThomas Petazzoni 	u8 startbyte;
204c296d5f9SThomas Petazzoni 	struct fbtft_ops fbtftops;
205c296d5f9SThomas Petazzoni 	spinlock_t dirty_lock;
2061c41494aSMing Yang 	unsigned int dirty_lines_start;
2071c41494aSMing Yang 	unsigned int dirty_lines_end;
208c296d5f9SThomas Petazzoni 	struct {
209c440eee1SNishad Kamdar 		struct gpio_desc *reset;
210c440eee1SNishad Kamdar 		struct gpio_desc *dc;
211c440eee1SNishad Kamdar 		struct gpio_desc *rd;
212c440eee1SNishad Kamdar 		struct gpio_desc *wr;
213c440eee1SNishad Kamdar 		struct gpio_desc *latch;
214c440eee1SNishad Kamdar 		struct gpio_desc *cs;
215c440eee1SNishad Kamdar 		struct gpio_desc *db[16];
216c440eee1SNishad Kamdar 		struct gpio_desc *led[16];
217c440eee1SNishad Kamdar 		struct gpio_desc *aux[16];
218c296d5f9SThomas Petazzoni 	} gpio;
2190a859b31SJoe Perches 	const s16 *init_sequence;
220c296d5f9SThomas Petazzoni 	struct {
221c296d5f9SThomas Petazzoni 		struct mutex lock;
22222eb36b8SArnd Bergmann 		u32 *curves;
223c296d5f9SThomas Petazzoni 		int num_values;
224c296d5f9SThomas Petazzoni 		int num_curves;
225c296d5f9SThomas Petazzoni 	} gamma;
226c296d5f9SThomas Petazzoni 	unsigned long debug;
227c296d5f9SThomas Petazzoni 	bool first_update_done;
228367e8560SKsenija Stanojevic 	ktime_t update_time;
229c296d5f9SThomas Petazzoni 	bool bgr;
230c296d5f9SThomas Petazzoni 	void *extra;
2319adfe5c8SDaniel Vetter 	bool polarity;
232c296d5f9SThomas Petazzoni };
233c296d5f9SThomas Petazzoni 
234c296d5f9SThomas Petazzoni #define NUMARGS(...)  (sizeof((int[]){__VA_ARGS__}) / sizeof(int))
235c296d5f9SThomas Petazzoni 
236c296d5f9SThomas Petazzoni #define write_reg(par, ...)                                            \
2370b1533c6SLeonardo Brás 	((par)->fbtftops.write_register(par, NUMARGS(__VA_ARGS__), __VA_ARGS__))
238c296d5f9SThomas Petazzoni 
239c296d5f9SThomas Petazzoni /* fbtft-core.c */
24060da7020SHeiner Kallweit int fbtft_write_buf_dc(struct fbtft_par *par, void *buf, size_t len, int dc);
24127a0eb8fSJeremy Sowden __printf(5, 6)
242cd951ddcSJoe Perches void fbtft_dbg_hex(const struct device *dev, int groupsize,
243*0e8cf2beSAndy Shevchenko 		   const void *buf, size_t len, const char *fmt, ...);
244ad6d8812SNoralf Trønnes struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display,
245ad6d8812SNoralf Trønnes 					struct device *dev,
246ad6d8812SNoralf Trønnes 					struct fbtft_platform_data *pdata);
247cd951ddcSJoe Perches void fbtft_framebuffer_release(struct fb_info *info);
248cd951ddcSJoe Perches int fbtft_register_framebuffer(struct fb_info *fb_info);
249cd951ddcSJoe Perches int fbtft_unregister_framebuffer(struct fb_info *fb_info);
250cd951ddcSJoe Perches void fbtft_register_backlight(struct fbtft_par *par);
251cd951ddcSJoe Perches void fbtft_unregister_backlight(struct fbtft_par *par);
252cd951ddcSJoe Perches int fbtft_init_display(struct fbtft_par *par);
253cd951ddcSJoe Perches int fbtft_probe_common(struct fbtft_display *display, struct spi_device *sdev,
254cd951ddcSJoe Perches 		       struct platform_device *pdev);
255cb08d3d2SUwe Kleine-König void fbtft_remove_common(struct device *dev, struct fb_info *info);
256c296d5f9SThomas Petazzoni 
257c296d5f9SThomas Petazzoni /* fbtft-io.c */
258cd951ddcSJoe Perches int fbtft_write_spi(struct fbtft_par *par, void *buf, size_t len);
259cd951ddcSJoe Perches int fbtft_write_spi_emulate_9(struct fbtft_par *par, void *buf, size_t len);
260cd951ddcSJoe Perches int fbtft_read_spi(struct fbtft_par *par, void *buf, size_t len);
261cd951ddcSJoe Perches int fbtft_write_gpio8_wr(struct fbtft_par *par, void *buf, size_t len);
262cd951ddcSJoe Perches int fbtft_write_gpio16_wr(struct fbtft_par *par, void *buf, size_t len);
263cd951ddcSJoe Perches int fbtft_write_gpio16_wr_latched(struct fbtft_par *par, void *buf, size_t len);
264c296d5f9SThomas Petazzoni 
265c296d5f9SThomas Petazzoni /* fbtft-bus.c */
266cd951ddcSJoe Perches int fbtft_write_vmem8_bus8(struct fbtft_par *par, size_t offset, size_t len);
267cd951ddcSJoe Perches int fbtft_write_vmem16_bus16(struct fbtft_par *par, size_t offset, size_t len);
268cd951ddcSJoe Perches int fbtft_write_vmem16_bus8(struct fbtft_par *par, size_t offset, size_t len);
269cd951ddcSJoe Perches int fbtft_write_vmem16_bus9(struct fbtft_par *par, size_t offset, size_t len);
270cd951ddcSJoe Perches void fbtft_write_reg8_bus8(struct fbtft_par *par, int len, ...);
271cd951ddcSJoe Perches void fbtft_write_reg8_bus9(struct fbtft_par *par, int len, ...);
272cd951ddcSJoe Perches void fbtft_write_reg16_bus8(struct fbtft_par *par, int len, ...);
273cd951ddcSJoe Perches void fbtft_write_reg16_bus16(struct fbtft_par *par, int len, ...);
274c296d5f9SThomas Petazzoni 
27539ddef56SUwe Kleine-König #define FBTFT_DT_TABLE(_compatible)						\
27639ddef56SUwe Kleine-König static const struct of_device_id dt_ids[] = {					\
27739ddef56SUwe Kleine-König 	{ .compatible = _compatible },						\
27839ddef56SUwe Kleine-König 	{},									\
27939ddef56SUwe Kleine-König };										\
28039ddef56SUwe Kleine-König MODULE_DEVICE_TABLE(of, dt_ids);
28139ddef56SUwe Kleine-König 
28239ddef56SUwe Kleine-König #define FBTFT_SPI_DRIVER(_name, _compatible, _display, _spi_ids)		\
283c296d5f9SThomas Petazzoni 										\
284c296d5f9SThomas Petazzoni static int fbtft_driver_probe_spi(struct spi_device *spi)			\
285c296d5f9SThomas Petazzoni {										\
286c296d5f9SThomas Petazzoni 	return fbtft_probe_common(_display, spi, NULL);				\
287c296d5f9SThomas Petazzoni }										\
288c296d5f9SThomas Petazzoni 										\
289c296d5f9SThomas Petazzoni static void fbtft_driver_remove_spi(struct spi_device *spi)			\
290c296d5f9SThomas Petazzoni {										\
291c296d5f9SThomas Petazzoni 	struct fb_info *info = spi_get_drvdata(spi);				\
292c296d5f9SThomas Petazzoni 										\
293cb08d3d2SUwe Kleine-König 	fbtft_remove_common(&spi->dev, info);					\
294cb08d3d2SUwe Kleine-König }										\
295c296d5f9SThomas Petazzoni 										\
296c296d5f9SThomas Petazzoni static struct spi_driver fbtft_driver_spi_driver = {				\
29739ddef56SUwe Kleine-König 	.driver = {								\
29839ddef56SUwe Kleine-König 		.name = _name,							\
29939ddef56SUwe Kleine-König 		.of_match_table = dt_ids,					\
30039ddef56SUwe Kleine-König 	},									\
30139ddef56SUwe Kleine-König 	.id_table = _spi_ids,							\
30239ddef56SUwe Kleine-König 	.probe = fbtft_driver_probe_spi,					\
30339ddef56SUwe Kleine-König 	.remove = fbtft_driver_remove_spi,					\
30439ddef56SUwe Kleine-König };
30539ddef56SUwe Kleine-König 
30639ddef56SUwe Kleine-König #define FBTFT_REGISTER_DRIVER(_name, _compatible, _display)                \
30739ddef56SUwe Kleine-König 									   \
30839ddef56SUwe Kleine-König static int fbtft_driver_probe_pdev(struct platform_device *pdev)           \
309c296d5f9SThomas Petazzoni {                                                                          \
310c296d5f9SThomas Petazzoni 	return fbtft_probe_common(_display, NULL, pdev);                   \
311c296d5f9SThomas Petazzoni }                                                                          \
312c296d5f9SThomas Petazzoni 									   \
313c296d5f9SThomas Petazzoni static int fbtft_driver_remove_pdev(struct platform_device *pdev)          \
314c296d5f9SThomas Petazzoni {                                                                          \
315c296d5f9SThomas Petazzoni 	struct fb_info *info = platform_get_drvdata(pdev);                 \
316c296d5f9SThomas Petazzoni 									   \
317c296d5f9SThomas Petazzoni 	fbtft_remove_common(&pdev->dev, info);                             \
318cb08d3d2SUwe Kleine-König 	return 0;                                                          \
319cb08d3d2SUwe Kleine-König }                                                                          \
320c296d5f9SThomas Petazzoni 									   \
321c296d5f9SThomas Petazzoni FBTFT_DT_TABLE(_compatible)						   \
32239ddef56SUwe Kleine-König 									   \
323c296d5f9SThomas Petazzoni FBTFT_SPI_DRIVER(_name, _compatible, _display, NULL)			   \
32439ddef56SUwe Kleine-König 									   \
325c296d5f9SThomas Petazzoni static struct platform_driver fbtft_driver_platform_driver = {             \
326c296d5f9SThomas Petazzoni 	.driver = {                                                        \
327c296d5f9SThomas Petazzoni 		.name   = _name,                                           \
328c296d5f9SThomas Petazzoni 		.owner  = THIS_MODULE,                                     \
329c296d5f9SThomas Petazzoni 		.of_match_table = dt_ids,                                  \
330189f39eeSAndy Shevchenko 	},                                                                 \
331c296d5f9SThomas Petazzoni 	.probe  = fbtft_driver_probe_pdev,                                 \
332c296d5f9SThomas Petazzoni 	.remove = fbtft_driver_remove_pdev,                                \
333c296d5f9SThomas Petazzoni };                                                                         \
334c296d5f9SThomas Petazzoni 									   \
335c296d5f9SThomas Petazzoni static int __init fbtft_driver_module_init(void)                           \
336c296d5f9SThomas Petazzoni {                                                                          \
337c296d5f9SThomas Petazzoni 	int ret;                                                           \
338c296d5f9SThomas Petazzoni 									   \
339c296d5f9SThomas Petazzoni 	ret = spi_register_driver(&fbtft_driver_spi_driver);               \
340c296d5f9SThomas Petazzoni 	if (ret < 0)                                                       \
341c296d5f9SThomas Petazzoni 		return ret;                                                \
342c296d5f9SThomas Petazzoni 	ret = platform_driver_register(&fbtft_driver_platform_driver);     \
343426aca16SUwe Kleine-König 	if (ret < 0)                                                       \
344426aca16SUwe Kleine-König 		spi_unregister_driver(&fbtft_driver_spi_driver);           \
345426aca16SUwe Kleine-König 	return ret;                                                        \
346426aca16SUwe Kleine-König }                                                                          \
347c296d5f9SThomas Petazzoni 									   \
348c296d5f9SThomas Petazzoni static void __exit fbtft_driver_module_exit(void)                          \
349c296d5f9SThomas Petazzoni {                                                                          \
350c296d5f9SThomas Petazzoni 	spi_unregister_driver(&fbtft_driver_spi_driver);                   \
351c296d5f9SThomas Petazzoni 	platform_driver_unregister(&fbtft_driver_platform_driver);         \
352c296d5f9SThomas Petazzoni }                                                                          \
353c296d5f9SThomas Petazzoni 									   \
354c296d5f9SThomas Petazzoni module_init(fbtft_driver_module_init);                                     \
355c296d5f9SThomas Petazzoni module_exit(fbtft_driver_module_exit);
356c296d5f9SThomas Petazzoni 
357c296d5f9SThomas Petazzoni #define FBTFT_REGISTER_SPI_DRIVER(_name, _comp_vend, _comp_dev, _display)	\
35815e66fc7SHeiner Kallweit 										\
35915e66fc7SHeiner Kallweit FBTFT_DT_TABLE(_comp_vend "," _comp_dev)					\
36039ddef56SUwe Kleine-König 										\
36115e66fc7SHeiner Kallweit static const struct spi_device_id spi_ids[] = {					\
36215e66fc7SHeiner Kallweit 	{ .name = _comp_dev },							\
36315e66fc7SHeiner Kallweit 	{},									\
36415e66fc7SHeiner Kallweit };										\
36515e66fc7SHeiner Kallweit MODULE_DEVICE_TABLE(spi, spi_ids);						\
36615e66fc7SHeiner Kallweit 										\
36715e66fc7SHeiner Kallweit FBTFT_SPI_DRIVER(_name, _comp_vend "," _comp_dev, _display, spi_ids)		\
36839ddef56SUwe Kleine-König 										\
36915e66fc7SHeiner Kallweit module_spi_driver(fbtft_driver_spi_driver);
37015e66fc7SHeiner Kallweit 
37115e66fc7SHeiner Kallweit /* Debug macros */
372c296d5f9SThomas Petazzoni 
373c296d5f9SThomas Petazzoni /* shorthand debug levels */
374c296d5f9SThomas Petazzoni #define DEBUG_LEVEL_1	DEBUG_REQUEST_GPIOS
375c296d5f9SThomas Petazzoni #define DEBUG_LEVEL_2	(DEBUG_LEVEL_1 | DEBUG_DRIVER_INIT_FUNCTIONS        \
376b32d2fb2SDeepak R Varma 				       | DEBUG_TIME_FIRST_UPDATE)
377b32d2fb2SDeepak R Varma #define DEBUG_LEVEL_3	(DEBUG_LEVEL_2 | DEBUG_RESET | DEBUG_INIT_DISPLAY   \
378b32d2fb2SDeepak R Varma 				       | DEBUG_BLANK | DEBUG_REQUEST_GPIOS  \
379b32d2fb2SDeepak R Varma 				       | DEBUG_FREE_GPIOS                   \
380b32d2fb2SDeepak R Varma 				       | DEBUG_VERIFY_GPIOS                 \
381b32d2fb2SDeepak R Varma 				       | DEBUG_BACKLIGHT | DEBUG_SYSFS)
382b32d2fb2SDeepak R Varma #define DEBUG_LEVEL_4	(DEBUG_LEVEL_2 | DEBUG_FB_READ | DEBUG_FB_WRITE     \
383b32d2fb2SDeepak R Varma 				       | DEBUG_FB_FILLRECT                  \
384b32d2fb2SDeepak R Varma 				       | DEBUG_FB_COPYAREA                  \
385b32d2fb2SDeepak R Varma 				       | DEBUG_FB_IMAGEBLIT | DEBUG_FB_BLANK)
386b32d2fb2SDeepak R Varma #define DEBUG_LEVEL_5	(DEBUG_LEVEL_3 | DEBUG_UPDATE_DISPLAY)
387c296d5f9SThomas Petazzoni #define DEBUG_LEVEL_6	(DEBUG_LEVEL_4 | DEBUG_LEVEL_5)
388c296d5f9SThomas Petazzoni #define DEBUG_LEVEL_7	0xFFFFFFFF
389c296d5f9SThomas Petazzoni 
390c296d5f9SThomas Petazzoni #define DEBUG_DRIVER_INIT_FUNCTIONS BIT(3)
39148b775caSMamta Shukla #define DEBUG_TIME_FIRST_UPDATE     BIT(4)
39248b775caSMamta Shukla #define DEBUG_TIME_EACH_UPDATE      BIT(5)
39348b775caSMamta Shukla #define DEBUG_DEFERRED_IO           BIT(6)
39448b775caSMamta Shukla #define DEBUG_FBTFT_INIT_FUNCTIONS  BIT(7)
39548b775caSMamta Shukla 
396c296d5f9SThomas Petazzoni /* fbops */
397c296d5f9SThomas Petazzoni #define DEBUG_FB_READ               BIT(8)
39848b775caSMamta Shukla #define DEBUG_FB_WRITE              BIT(9)
39948b775caSMamta Shukla #define DEBUG_FB_FILLRECT           BIT(10)
40048b775caSMamta Shukla #define DEBUG_FB_COPYAREA           BIT(11)
40148b775caSMamta Shukla #define DEBUG_FB_IMAGEBLIT          BIT(12)
40248b775caSMamta Shukla #define DEBUG_FB_SETCOLREG          BIT(13)
40348b775caSMamta Shukla #define DEBUG_FB_BLANK              BIT(14)
40448b775caSMamta Shukla 
405c296d5f9SThomas Petazzoni #define DEBUG_SYSFS                 BIT(16)
40648b775caSMamta Shukla 
407c296d5f9SThomas Petazzoni /* fbtftops */
408c296d5f9SThomas Petazzoni #define DEBUG_BACKLIGHT             BIT(17)
40948b775caSMamta Shukla #define DEBUG_READ                  BIT(18)
41048b775caSMamta Shukla #define DEBUG_WRITE                 BIT(19)
41148b775caSMamta Shukla #define DEBUG_WRITE_VMEM            BIT(20)
41248b775caSMamta Shukla #define DEBUG_WRITE_REGISTER        BIT(21)
41348b775caSMamta Shukla #define DEBUG_SET_ADDR_WIN          BIT(22)
41448b775caSMamta Shukla #define DEBUG_RESET                 BIT(23)
41548b775caSMamta Shukla #define DEBUG_MKDIRTY               BIT(24)
41648b775caSMamta Shukla #define DEBUG_UPDATE_DISPLAY        BIT(25)
41748b775caSMamta Shukla #define DEBUG_INIT_DISPLAY          BIT(26)
41848b775caSMamta Shukla #define DEBUG_BLANK                 BIT(27)
41948b775caSMamta Shukla #define DEBUG_REQUEST_GPIOS         BIT(28)
42048b775caSMamta Shukla #define DEBUG_FREE_GPIOS            BIT(29)
42148b775caSMamta Shukla #define DEBUG_REQUEST_GPIOS_MATCH   BIT(30)
42248b775caSMamta Shukla #define DEBUG_VERIFY_GPIOS          BIT(31)
42348b775caSMamta Shukla 
424c296d5f9SThomas Petazzoni #define fbtft_init_dbg(dev, format, arg...)                  \
425c296d5f9SThomas Petazzoni do {                                                         \
426c296d5f9SThomas Petazzoni 	if (unlikely((dev)->platform_data &&                 \
427c296d5f9SThomas Petazzoni 	    (((struct fbtft_platform_data *)(dev)->platform_data)->display.debug & DEBUG_DRIVER_INIT_FUNCTIONS))) \
428c296d5f9SThomas Petazzoni 		dev_info(dev, format, ##arg);                \
429c296d5f9SThomas Petazzoni } while (0)
430c296d5f9SThomas Petazzoni 
431c296d5f9SThomas Petazzoni #define fbtft_par_dbg(level, par, format, arg...)            \
432c296d5f9SThomas Petazzoni do {                                                         \
433c296d5f9SThomas Petazzoni 	if (unlikely((par)->debug & (level)))                    \
434f54df479SDeepak R Varma 		dev_info((par)->info->device, format, ##arg);  \
435f54df479SDeepak R Varma } while (0)
436c296d5f9SThomas Petazzoni 
437c296d5f9SThomas Petazzoni #define fbtft_par_dbg_hex(level, par, dev, type, buf, num, format, arg...) \
438c296d5f9SThomas Petazzoni do {                                                                       \
439c296d5f9SThomas Petazzoni 	if (unlikely((par)->debug & (level)))                                  \
4400b1533c6SLeonardo Brás 		fbtft_dbg_hex(dev, sizeof(type), buf,\
4410b1533c6SLeonardo Brás 			      (num) * sizeof(type), format, ##arg); \
4420b1533c6SLeonardo Brás } while (0)
443c296d5f9SThomas Petazzoni 
444c296d5f9SThomas Petazzoni #endif /* __LINUX_FBTFT_H */
445c296d5f9SThomas Petazzoni