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, 243cd951ddcSJoe Perches 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); 255cd951ddcSJoe Perches int 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 275c296d5f9SThomas Petazzoni #define FBTFT_REGISTER_DRIVER(_name, _compatible, _display) \ 276c296d5f9SThomas Petazzoni \ 277c296d5f9SThomas Petazzoni static int fbtft_driver_probe_spi(struct spi_device *spi) \ 278c296d5f9SThomas Petazzoni { \ 279c296d5f9SThomas Petazzoni return fbtft_probe_common(_display, spi, NULL); \ 280c296d5f9SThomas Petazzoni } \ 281c296d5f9SThomas Petazzoni \ 282c296d5f9SThomas Petazzoni static int fbtft_driver_remove_spi(struct spi_device *spi) \ 283c296d5f9SThomas Petazzoni { \ 284c296d5f9SThomas Petazzoni struct fb_info *info = spi_get_drvdata(spi); \ 285c296d5f9SThomas Petazzoni \ 286c296d5f9SThomas Petazzoni return fbtft_remove_common(&spi->dev, info); \ 287c296d5f9SThomas Petazzoni } \ 288c296d5f9SThomas Petazzoni \ 289c296d5f9SThomas Petazzoni static int fbtft_driver_probe_pdev(struct platform_device *pdev) \ 290c296d5f9SThomas Petazzoni { \ 291c296d5f9SThomas Petazzoni return fbtft_probe_common(_display, NULL, pdev); \ 292c296d5f9SThomas Petazzoni } \ 293c296d5f9SThomas Petazzoni \ 294c296d5f9SThomas Petazzoni static int fbtft_driver_remove_pdev(struct platform_device *pdev) \ 295c296d5f9SThomas Petazzoni { \ 296c296d5f9SThomas Petazzoni struct fb_info *info = platform_get_drvdata(pdev); \ 297c296d5f9SThomas Petazzoni \ 298c296d5f9SThomas Petazzoni return fbtft_remove_common(&pdev->dev, info); \ 299c296d5f9SThomas Petazzoni } \ 300c296d5f9SThomas Petazzoni \ 301c296d5f9SThomas Petazzoni static const struct of_device_id dt_ids[] = { \ 302c296d5f9SThomas Petazzoni { .compatible = _compatible }, \ 303c296d5f9SThomas Petazzoni {}, \ 304c296d5f9SThomas Petazzoni }; \ 305c296d5f9SThomas Petazzoni \ 306c296d5f9SThomas Petazzoni MODULE_DEVICE_TABLE(of, dt_ids); \ 307c296d5f9SThomas Petazzoni \ 308c296d5f9SThomas Petazzoni \ 309c296d5f9SThomas Petazzoni static struct spi_driver fbtft_driver_spi_driver = { \ 310c296d5f9SThomas Petazzoni .driver = { \ 311c296d5f9SThomas Petazzoni .name = _name, \ 312189f39eeSAndy Shevchenko .of_match_table = dt_ids, \ 313c296d5f9SThomas Petazzoni }, \ 314c296d5f9SThomas Petazzoni .probe = fbtft_driver_probe_spi, \ 315c296d5f9SThomas Petazzoni .remove = fbtft_driver_remove_spi, \ 316c296d5f9SThomas Petazzoni }; \ 317c296d5f9SThomas Petazzoni \ 318c296d5f9SThomas Petazzoni static struct platform_driver fbtft_driver_platform_driver = { \ 319c296d5f9SThomas Petazzoni .driver = { \ 320c296d5f9SThomas Petazzoni .name = _name, \ 321c296d5f9SThomas Petazzoni .owner = THIS_MODULE, \ 322189f39eeSAndy Shevchenko .of_match_table = dt_ids, \ 323c296d5f9SThomas Petazzoni }, \ 324c296d5f9SThomas Petazzoni .probe = fbtft_driver_probe_pdev, \ 325c296d5f9SThomas Petazzoni .remove = fbtft_driver_remove_pdev, \ 326c296d5f9SThomas Petazzoni }; \ 327c296d5f9SThomas Petazzoni \ 328c296d5f9SThomas Petazzoni static int __init fbtft_driver_module_init(void) \ 329c296d5f9SThomas Petazzoni { \ 330c296d5f9SThomas Petazzoni int ret; \ 331c296d5f9SThomas Petazzoni \ 332c296d5f9SThomas Petazzoni ret = spi_register_driver(&fbtft_driver_spi_driver); \ 333c296d5f9SThomas Petazzoni if (ret < 0) \ 334c296d5f9SThomas Petazzoni return ret; \ 335c296d5f9SThomas Petazzoni return platform_driver_register(&fbtft_driver_platform_driver); \ 336c296d5f9SThomas Petazzoni } \ 337c296d5f9SThomas Petazzoni \ 338c296d5f9SThomas Petazzoni static void __exit fbtft_driver_module_exit(void) \ 339c296d5f9SThomas Petazzoni { \ 340c296d5f9SThomas Petazzoni spi_unregister_driver(&fbtft_driver_spi_driver); \ 341c296d5f9SThomas Petazzoni platform_driver_unregister(&fbtft_driver_platform_driver); \ 342c296d5f9SThomas Petazzoni } \ 343c296d5f9SThomas Petazzoni \ 344c296d5f9SThomas Petazzoni module_init(fbtft_driver_module_init); \ 345c296d5f9SThomas Petazzoni module_exit(fbtft_driver_module_exit); 346c296d5f9SThomas Petazzoni 347c296d5f9SThomas Petazzoni /* Debug macros */ 348c296d5f9SThomas Petazzoni 349c296d5f9SThomas Petazzoni /* shorthand debug levels */ 350c296d5f9SThomas Petazzoni #define DEBUG_LEVEL_1 DEBUG_REQUEST_GPIOS 351b32d2fb2SDeepak R Varma #define DEBUG_LEVEL_2 (DEBUG_LEVEL_1 | DEBUG_DRIVER_INIT_FUNCTIONS \ 352b32d2fb2SDeepak R Varma | DEBUG_TIME_FIRST_UPDATE) 353b32d2fb2SDeepak R Varma #define DEBUG_LEVEL_3 (DEBUG_LEVEL_2 | DEBUG_RESET | DEBUG_INIT_DISPLAY \ 354b32d2fb2SDeepak R Varma | DEBUG_BLANK | DEBUG_REQUEST_GPIOS \ 355b32d2fb2SDeepak R Varma | DEBUG_FREE_GPIOS \ 356b32d2fb2SDeepak R Varma | DEBUG_VERIFY_GPIOS \ 357b32d2fb2SDeepak R Varma | DEBUG_BACKLIGHT | DEBUG_SYSFS) 358b32d2fb2SDeepak R Varma #define DEBUG_LEVEL_4 (DEBUG_LEVEL_2 | DEBUG_FB_READ | DEBUG_FB_WRITE \ 359b32d2fb2SDeepak R Varma | DEBUG_FB_FILLRECT \ 360b32d2fb2SDeepak R Varma | DEBUG_FB_COPYAREA \ 361b32d2fb2SDeepak R Varma | DEBUG_FB_IMAGEBLIT | DEBUG_FB_BLANK) 362c296d5f9SThomas Petazzoni #define DEBUG_LEVEL_5 (DEBUG_LEVEL_3 | DEBUG_UPDATE_DISPLAY) 363c296d5f9SThomas Petazzoni #define DEBUG_LEVEL_6 (DEBUG_LEVEL_4 | DEBUG_LEVEL_5) 364c296d5f9SThomas Petazzoni #define DEBUG_LEVEL_7 0xFFFFFFFF 365c296d5f9SThomas Petazzoni 36648b775caSMamta Shukla #define DEBUG_DRIVER_INIT_FUNCTIONS BIT(3) 36748b775caSMamta Shukla #define DEBUG_TIME_FIRST_UPDATE BIT(4) 36848b775caSMamta Shukla #define DEBUG_TIME_EACH_UPDATE BIT(5) 36948b775caSMamta Shukla #define DEBUG_DEFERRED_IO BIT(6) 37048b775caSMamta Shukla #define DEBUG_FBTFT_INIT_FUNCTIONS BIT(7) 371c296d5f9SThomas Petazzoni 372c296d5f9SThomas Petazzoni /* fbops */ 37348b775caSMamta Shukla #define DEBUG_FB_READ BIT(8) 37448b775caSMamta Shukla #define DEBUG_FB_WRITE BIT(9) 37548b775caSMamta Shukla #define DEBUG_FB_FILLRECT BIT(10) 37648b775caSMamta Shukla #define DEBUG_FB_COPYAREA BIT(11) 37748b775caSMamta Shukla #define DEBUG_FB_IMAGEBLIT BIT(12) 37848b775caSMamta Shukla #define DEBUG_FB_SETCOLREG BIT(13) 37948b775caSMamta Shukla #define DEBUG_FB_BLANK BIT(14) 380c296d5f9SThomas Petazzoni 38148b775caSMamta Shukla #define DEBUG_SYSFS BIT(16) 382c296d5f9SThomas Petazzoni 383c296d5f9SThomas Petazzoni /* fbtftops */ 38448b775caSMamta Shukla #define DEBUG_BACKLIGHT BIT(17) 38548b775caSMamta Shukla #define DEBUG_READ BIT(18) 38648b775caSMamta Shukla #define DEBUG_WRITE BIT(19) 38748b775caSMamta Shukla #define DEBUG_WRITE_VMEM BIT(20) 38848b775caSMamta Shukla #define DEBUG_WRITE_REGISTER BIT(21) 38948b775caSMamta Shukla #define DEBUG_SET_ADDR_WIN BIT(22) 39048b775caSMamta Shukla #define DEBUG_RESET BIT(23) 39148b775caSMamta Shukla #define DEBUG_MKDIRTY BIT(24) 39248b775caSMamta Shukla #define DEBUG_UPDATE_DISPLAY BIT(25) 39348b775caSMamta Shukla #define DEBUG_INIT_DISPLAY BIT(26) 39448b775caSMamta Shukla #define DEBUG_BLANK BIT(27) 39548b775caSMamta Shukla #define DEBUG_REQUEST_GPIOS BIT(28) 39648b775caSMamta Shukla #define DEBUG_FREE_GPIOS BIT(29) 39748b775caSMamta Shukla #define DEBUG_REQUEST_GPIOS_MATCH BIT(30) 39848b775caSMamta Shukla #define DEBUG_VERIFY_GPIOS BIT(31) 399c296d5f9SThomas Petazzoni 400c296d5f9SThomas Petazzoni #define fbtft_init_dbg(dev, format, arg...) \ 401c296d5f9SThomas Petazzoni do { \ 402c296d5f9SThomas Petazzoni if (unlikely((dev)->platform_data && \ 403c296d5f9SThomas Petazzoni (((struct fbtft_platform_data *)(dev)->platform_data)->display.debug & DEBUG_DRIVER_INIT_FUNCTIONS))) \ 404c296d5f9SThomas Petazzoni dev_info(dev, format, ##arg); \ 405c296d5f9SThomas Petazzoni } while (0) 406c296d5f9SThomas Petazzoni 407c296d5f9SThomas Petazzoni #define fbtft_par_dbg(level, par, format, arg...) \ 408c296d5f9SThomas Petazzoni do { \ 409f54df479SDeepak R Varma if (unlikely((par)->debug & (level))) \ 410f54df479SDeepak R Varma dev_info((par)->info->device, format, ##arg); \ 411c296d5f9SThomas Petazzoni } while (0) 412c296d5f9SThomas Petazzoni 413c296d5f9SThomas Petazzoni #define fbtft_par_dbg_hex(level, par, dev, type, buf, num, format, arg...) \ 414c296d5f9SThomas Petazzoni do { \ 4150b1533c6SLeonardo Brás if (unlikely((par)->debug & (level))) \ 4160b1533c6SLeonardo Brás fbtft_dbg_hex(dev, sizeof(type), buf,\ 4170b1533c6SLeonardo Brás (num) * sizeof(type), format, ##arg); \ 418c296d5f9SThomas Petazzoni } while (0) 419c296d5f9SThomas Petazzoni 420c296d5f9SThomas Petazzoni #endif /* __LINUX_FBTFT_H */ 421