]> git.karo-electronics.de Git - karo-tx-linux.git/blob - include/drm/tinydrm/mipi-dbi.h
Merge tag 'for-linus-4.12b-rc5-tag' of git://git.kernel.org/pub/scm/linux/kernel...
[karo-tx-linux.git] / include / drm / tinydrm / mipi-dbi.h
1 /*
2  * MIPI Display Bus Interface (DBI) LCD controller support
3  *
4  * Copyright 2016 Noralf Trønnes
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  */
11
12 #ifndef __LINUX_MIPI_DBI_H
13 #define __LINUX_MIPI_DBI_H
14
15 #include <drm/tinydrm/tinydrm.h>
16
17 struct spi_device;
18 struct gpio_desc;
19 struct regulator;
20
21 /**
22  * struct mipi_dbi - MIPI DBI controller
23  * @tinydrm: tinydrm base
24  * @spi: SPI device
25  * @enabled: Pipeline is enabled
26  * @cmdlock: Command lock
27  * @command: Bus specific callback executing commands.
28  * @read_commands: Array of read commands terminated by a zero entry.
29  *                 Reading is disabled if this is NULL.
30  * @dc: Optional D/C gpio.
31  * @tx_buf: Buffer used for transfer (copy clip rect area)
32  * @tx_buf9: Buffer used for Option 1 9-bit conversion
33  * @tx_buf9_len: Size of tx_buf9.
34  * @swap_bytes: Swap bytes in buffer before transfer
35  * @reset: Optional reset gpio
36  * @rotation: initial rotation in degrees Counter Clock Wise
37  * @backlight: backlight device (optional)
38  * @regulator: power regulator (optional)
39  */
40 struct mipi_dbi {
41         struct tinydrm_device tinydrm;
42         struct spi_device *spi;
43         bool enabled;
44         struct mutex cmdlock;
45         int (*command)(struct mipi_dbi *mipi, u8 cmd, u8 *param, size_t num);
46         const u8 *read_commands;
47         struct gpio_desc *dc;
48         u16 *tx_buf;
49         void *tx_buf9;
50         size_t tx_buf9_len;
51         bool swap_bytes;
52         struct gpio_desc *reset;
53         unsigned int rotation;
54         struct backlight_device *backlight;
55         struct regulator *regulator;
56 };
57
58 static inline struct mipi_dbi *
59 mipi_dbi_from_tinydrm(struct tinydrm_device *tdev)
60 {
61         return container_of(tdev, struct mipi_dbi, tinydrm);
62 }
63
64 int mipi_dbi_spi_init(struct spi_device *spi, struct mipi_dbi *mipi,
65                       struct gpio_desc *dc,
66                       const struct drm_simple_display_pipe_funcs *pipe_funcs,
67                       struct drm_driver *driver,
68                       const struct drm_display_mode *mode,
69                       unsigned int rotation);
70 int mipi_dbi_init(struct device *dev, struct mipi_dbi *mipi,
71                   const struct drm_simple_display_pipe_funcs *pipe_funcs,
72                   struct drm_driver *driver,
73                   const struct drm_display_mode *mode, unsigned int rotation);
74 void mipi_dbi_pipe_enable(struct drm_simple_display_pipe *pipe,
75                           struct drm_crtc_state *crtc_state);
76 void mipi_dbi_pipe_disable(struct drm_simple_display_pipe *pipe);
77 void mipi_dbi_hw_reset(struct mipi_dbi *mipi);
78 bool mipi_dbi_display_is_on(struct mipi_dbi *mipi);
79
80 int mipi_dbi_command_read(struct mipi_dbi *mipi, u8 cmd, u8 *val);
81 int mipi_dbi_command_buf(struct mipi_dbi *mipi, u8 cmd, u8 *data, size_t len);
82
83 /**
84  * mipi_dbi_command - MIPI DCS command with optional parameter(s)
85  * @mipi: MIPI structure
86  * @cmd: Command
87  * @seq...: Optional parameter(s)
88  *
89  * Send MIPI DCS command to the controller. Use mipi_dbi_command_read() for
90  * get/read.
91  *
92  * Returns:
93  * Zero on success, negative error code on failure.
94  */
95 #define mipi_dbi_command(mipi, cmd, seq...) \
96 ({ \
97         u8 d[] = { seq }; \
98         mipi_dbi_command_buf(mipi, cmd, d, ARRAY_SIZE(d)); \
99 })
100
101 #ifdef CONFIG_DEBUG_FS
102 int mipi_dbi_debugfs_init(struct drm_minor *minor);
103 #else
104 #define mipi_dbi_debugfs_init           NULL
105 #endif
106
107 #endif /* __LINUX_MIPI_DBI_H */