Loading...
Note: File does not exist in v3.1.
1/*
2 * DRM driver for Multi-Inno MI0283QT panels
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#include <linux/backlight.h>
13#include <linux/delay.h>
14#include <linux/gpio/consumer.h>
15#include <linux/module.h>
16#include <linux/property.h>
17#include <linux/regulator/consumer.h>
18#include <linux/spi/spi.h>
19
20#include <drm/drm_fb_helper.h>
21#include <drm/drm_modeset_helper.h>
22#include <drm/tinydrm/mipi-dbi.h>
23#include <drm/tinydrm/tinydrm-helpers.h>
24#include <video/mipi_display.h>
25
26#define ILI9341_FRMCTR1 0xb1
27#define ILI9341_DISCTRL 0xb6
28#define ILI9341_ETMOD 0xb7
29
30#define ILI9341_PWCTRL1 0xc0
31#define ILI9341_PWCTRL2 0xc1
32#define ILI9341_VMCTRL1 0xc5
33#define ILI9341_VMCTRL2 0xc7
34#define ILI9341_PWCTRLA 0xcb
35#define ILI9341_PWCTRLB 0xcf
36
37#define ILI9341_PGAMCTRL 0xe0
38#define ILI9341_NGAMCTRL 0xe1
39#define ILI9341_DTCTRLA 0xe8
40#define ILI9341_DTCTRLB 0xea
41#define ILI9341_PWRSEQ 0xed
42
43#define ILI9341_EN3GAM 0xf2
44#define ILI9341_PUMPCTRL 0xf7
45
46#define ILI9341_MADCTL_BGR BIT(3)
47#define ILI9341_MADCTL_MV BIT(5)
48#define ILI9341_MADCTL_MX BIT(6)
49#define ILI9341_MADCTL_MY BIT(7)
50
51static void mi0283qt_enable(struct drm_simple_display_pipe *pipe,
52 struct drm_crtc_state *crtc_state)
53{
54 struct tinydrm_device *tdev = pipe_to_tinydrm(pipe);
55 struct mipi_dbi *mipi = mipi_dbi_from_tinydrm(tdev);
56 u8 addr_mode;
57 int ret;
58
59 DRM_DEBUG_KMS("\n");
60
61 ret = mipi_dbi_poweron_conditional_reset(mipi);
62 if (ret < 0)
63 return;
64 if (ret == 1)
65 goto out_enable;
66
67 mipi_dbi_command(mipi, MIPI_DCS_SET_DISPLAY_OFF);
68
69 mipi_dbi_command(mipi, ILI9341_PWCTRLB, 0x00, 0x83, 0x30);
70 mipi_dbi_command(mipi, ILI9341_PWRSEQ, 0x64, 0x03, 0x12, 0x81);
71 mipi_dbi_command(mipi, ILI9341_DTCTRLA, 0x85, 0x01, 0x79);
72 mipi_dbi_command(mipi, ILI9341_PWCTRLA, 0x39, 0x2c, 0x00, 0x34, 0x02);
73 mipi_dbi_command(mipi, ILI9341_PUMPCTRL, 0x20);
74 mipi_dbi_command(mipi, ILI9341_DTCTRLB, 0x00, 0x00);
75
76 /* Power Control */
77 mipi_dbi_command(mipi, ILI9341_PWCTRL1, 0x26);
78 mipi_dbi_command(mipi, ILI9341_PWCTRL2, 0x11);
79 /* VCOM */
80 mipi_dbi_command(mipi, ILI9341_VMCTRL1, 0x35, 0x3e);
81 mipi_dbi_command(mipi, ILI9341_VMCTRL2, 0xbe);
82
83 /* Memory Access Control */
84 mipi_dbi_command(mipi, MIPI_DCS_SET_PIXEL_FORMAT, MIPI_DCS_PIXEL_FMT_16BIT);
85
86 switch (mipi->rotation) {
87 default:
88 addr_mode = ILI9341_MADCTL_MV | ILI9341_MADCTL_MY |
89 ILI9341_MADCTL_MX;
90 break;
91 case 90:
92 addr_mode = ILI9341_MADCTL_MY;
93 break;
94 case 180:
95 addr_mode = ILI9341_MADCTL_MV;
96 break;
97 case 270:
98 addr_mode = ILI9341_MADCTL_MX;
99 break;
100 }
101 addr_mode |= ILI9341_MADCTL_BGR;
102 mipi_dbi_command(mipi, MIPI_DCS_SET_ADDRESS_MODE, addr_mode);
103
104 /* Frame Rate */
105 mipi_dbi_command(mipi, ILI9341_FRMCTR1, 0x00, 0x1b);
106
107 /* Gamma */
108 mipi_dbi_command(mipi, ILI9341_EN3GAM, 0x08);
109 mipi_dbi_command(mipi, MIPI_DCS_SET_GAMMA_CURVE, 0x01);
110 mipi_dbi_command(mipi, ILI9341_PGAMCTRL,
111 0x1f, 0x1a, 0x18, 0x0a, 0x0f, 0x06, 0x45, 0x87,
112 0x32, 0x0a, 0x07, 0x02, 0x07, 0x05, 0x00);
113 mipi_dbi_command(mipi, ILI9341_NGAMCTRL,
114 0x00, 0x25, 0x27, 0x05, 0x10, 0x09, 0x3a, 0x78,
115 0x4d, 0x05, 0x18, 0x0d, 0x38, 0x3a, 0x1f);
116
117 /* DDRAM */
118 mipi_dbi_command(mipi, ILI9341_ETMOD, 0x07);
119
120 /* Display */
121 mipi_dbi_command(mipi, ILI9341_DISCTRL, 0x0a, 0x82, 0x27, 0x00);
122 mipi_dbi_command(mipi, MIPI_DCS_EXIT_SLEEP_MODE);
123 msleep(100);
124
125 mipi_dbi_command(mipi, MIPI_DCS_SET_DISPLAY_ON);
126 msleep(100);
127
128out_enable:
129 mipi_dbi_enable_flush(mipi);
130}
131
132static const struct drm_simple_display_pipe_funcs mi0283qt_pipe_funcs = {
133 .enable = mi0283qt_enable,
134 .disable = mipi_dbi_pipe_disable,
135 .update = tinydrm_display_pipe_update,
136 .prepare_fb = tinydrm_display_pipe_prepare_fb,
137};
138
139static const struct drm_display_mode mi0283qt_mode = {
140 TINYDRM_MODE(320, 240, 58, 43),
141};
142
143DEFINE_DRM_GEM_CMA_FOPS(mi0283qt_fops);
144
145static struct drm_driver mi0283qt_driver = {
146 .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME |
147 DRIVER_ATOMIC,
148 .fops = &mi0283qt_fops,
149 TINYDRM_GEM_DRIVER_OPS,
150 .lastclose = drm_fb_helper_lastclose,
151 .debugfs_init = mipi_dbi_debugfs_init,
152 .name = "mi0283qt",
153 .desc = "Multi-Inno MI0283QT",
154 .date = "20160614",
155 .major = 1,
156 .minor = 0,
157};
158
159static const struct of_device_id mi0283qt_of_match[] = {
160 { .compatible = "multi-inno,mi0283qt" },
161 {},
162};
163MODULE_DEVICE_TABLE(of, mi0283qt_of_match);
164
165static const struct spi_device_id mi0283qt_id[] = {
166 { "mi0283qt", 0 },
167 { },
168};
169MODULE_DEVICE_TABLE(spi, mi0283qt_id);
170
171static int mi0283qt_probe(struct spi_device *spi)
172{
173 struct device *dev = &spi->dev;
174 struct mipi_dbi *mipi;
175 struct gpio_desc *dc;
176 u32 rotation = 0;
177 int ret;
178
179 mipi = devm_kzalloc(dev, sizeof(*mipi), GFP_KERNEL);
180 if (!mipi)
181 return -ENOMEM;
182
183 mipi->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
184 if (IS_ERR(mipi->reset)) {
185 DRM_DEV_ERROR(dev, "Failed to get gpio 'reset'\n");
186 return PTR_ERR(mipi->reset);
187 }
188
189 dc = devm_gpiod_get_optional(dev, "dc", GPIOD_OUT_LOW);
190 if (IS_ERR(dc)) {
191 DRM_DEV_ERROR(dev, "Failed to get gpio 'dc'\n");
192 return PTR_ERR(dc);
193 }
194
195 mipi->regulator = devm_regulator_get(dev, "power");
196 if (IS_ERR(mipi->regulator))
197 return PTR_ERR(mipi->regulator);
198
199 mipi->backlight = devm_of_find_backlight(dev);
200 if (IS_ERR(mipi->backlight))
201 return PTR_ERR(mipi->backlight);
202
203 device_property_read_u32(dev, "rotation", &rotation);
204
205 ret = mipi_dbi_spi_init(spi, mipi, dc);
206 if (ret)
207 return ret;
208
209 ret = mipi_dbi_init(&spi->dev, mipi, &mi0283qt_pipe_funcs,
210 &mi0283qt_driver, &mi0283qt_mode, rotation);
211 if (ret)
212 return ret;
213
214 spi_set_drvdata(spi, mipi);
215
216 return devm_tinydrm_register(&mipi->tinydrm);
217}
218
219static void mi0283qt_shutdown(struct spi_device *spi)
220{
221 struct mipi_dbi *mipi = spi_get_drvdata(spi);
222
223 tinydrm_shutdown(&mipi->tinydrm);
224}
225
226static int __maybe_unused mi0283qt_pm_suspend(struct device *dev)
227{
228 struct mipi_dbi *mipi = dev_get_drvdata(dev);
229
230 return drm_mode_config_helper_suspend(mipi->tinydrm.drm);
231}
232
233static int __maybe_unused mi0283qt_pm_resume(struct device *dev)
234{
235 struct mipi_dbi *mipi = dev_get_drvdata(dev);
236
237 drm_mode_config_helper_resume(mipi->tinydrm.drm);
238
239 return 0;
240}
241
242static const struct dev_pm_ops mi0283qt_pm_ops = {
243 SET_SYSTEM_SLEEP_PM_OPS(mi0283qt_pm_suspend, mi0283qt_pm_resume)
244};
245
246static struct spi_driver mi0283qt_spi_driver = {
247 .driver = {
248 .name = "mi0283qt",
249 .owner = THIS_MODULE,
250 .of_match_table = mi0283qt_of_match,
251 .pm = &mi0283qt_pm_ops,
252 },
253 .id_table = mi0283qt_id,
254 .probe = mi0283qt_probe,
255 .shutdown = mi0283qt_shutdown,
256};
257module_spi_driver(mi0283qt_spi_driver);
258
259MODULE_DESCRIPTION("Multi-Inno MI0283QT DRM driver");
260MODULE_AUTHOR("Noralf Trønnes");
261MODULE_LICENSE("GPL");