1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
/* Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
#include <linux/gpio.h>
#include <linux/qpnp/pin.h>
#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/leds.h>
#include <linux/regulator/consumer.h>
#include <linux/dma-mapping.h>
#include <linux/uaccess.h>
#include <linux/msm-sps.h>
#include "mdss.h"
#include "mdss_panel.h"
#include "mdss_qpic.h"
#include "mdss_qpic_panel.h"
static u32 panel_is_on;
static u32 panel_refresh_rate;
static int (*qpic_panel_on)(struct qpic_panel_io_desc *qpic_panel_io);
static void (*qpic_panel_off)(struct qpic_panel_io_desc *qpic_panel_io);
static int mdss_qpic_pinctrl_init(struct platform_device *pdev,
struct qpic_panel_io_desc *qpic_panel_io);
u32 qpic_panel_get_framerate(void)
{
return panel_refresh_rate;
}
/* write a frame of pixels to a MIPI screen */
u32 qpic_send_frame(u32 x_start,
u32 y_start,
u32 x_end,
u32 y_end,
u32 *data,
u32 total_bytes)
{
u8 param[4];
u32 status;
u32 start_0_7;
u32 end_0_7;
u32 start_8_15;
u32 end_8_15;
/* convert to 16 bit representation */
x_start = x_start & 0xffff;
y_start = y_start & 0xffff;
x_end = x_end & 0xffff;
y_end = y_end & 0xffff;
/* set column/page */
start_0_7 = x_start & 0xff;
end_0_7 = x_end & 0xff;
start_8_15 = (x_start >> 8) & 0xff;
end_8_15 = (x_end >> 8) & 0xff;
param[0] = start_8_15;
param[1] = start_0_7;
param[2] = end_8_15;
param[3] = end_0_7;
status = qpic_send_pkt(OP_SET_COLUMN_ADDRESS, param, 4);
if (status) {
pr_err("Failed to set column address");
return status;
}
start_0_7 = y_start & 0xff;
end_0_7 = y_end & 0xff;
start_8_15 = (y_start >> 8) & 0xff;
end_8_15 = (y_end >> 8) & 0xff;
param[0] = start_8_15;
param[1] = start_0_7;
param[2] = end_8_15;
param[3] = end_0_7;
status = qpic_send_pkt(OP_SET_PAGE_ADDRESS, param, 4);
if (status) {
pr_err("Failed to set page address");
return status;
}
status = qpic_send_pkt(OP_WRITE_MEMORY_START, (u8 *)data, total_bytes);
if (status) {
pr_err("Failed to start memory write");
return status;
}
return 0;
}
static int mdss_qpic_pinctrl_init(struct platform_device *pdev,
struct qpic_panel_io_desc *qpic_panel_io)
{
qpic_panel_io->pin_res.pinctrl = devm_pinctrl_get(&pdev->dev);
if (IS_ERR_OR_NULL(qpic_panel_io->pin_res.pinctrl)) {
pr_err("%s: failed to get pinctrl\n", __func__);
return PTR_ERR(qpic_panel_io->pin_res.pinctrl);
}
qpic_panel_io->pin_res.gpio_state_active
= pinctrl_lookup_state(qpic_panel_io->pin_res.pinctrl,
MDSS_PINCTRL_STATE_DEFAULT);
if (IS_ERR_OR_NULL(qpic_panel_io->pin_res.gpio_state_active))
pr_warn("%s: cannot get default pinstate\n", __func__);
qpic_panel_io->pin_res.gpio_state_suspend
= pinctrl_lookup_state(qpic_panel_io->pin_res.pinctrl,
MDSS_PINCTRL_STATE_SLEEP);
if (IS_ERR_OR_NULL(qpic_panel_io->pin_res.gpio_state_suspend))
pr_warn("%s: cannot get sleep pinstate\n", __func__);
return 0;
}
int mdss_qpic_panel_on(struct mdss_panel_data *pdata,
struct qpic_panel_io_desc *panel_io)
{
int rc = 0;
if (panel_is_on)
return 0;
mdss_qpic_init();
if (qpic_panel_on)
rc = qpic_panel_on(panel_io);
if (rc)
return rc;
panel_is_on = true;
return 0;
}
int mdss_qpic_panel_off(struct mdss_panel_data *pdata,
struct qpic_panel_io_desc *panel_io)
{
if (qpic_panel_off)
qpic_panel_off(panel_io);
panel_is_on = false;
return 0;
}
int mdss_qpic_panel_io_init(struct platform_device *pdev,
struct qpic_panel_io_desc *qpic_panel_io)
{
int rc = 0;
struct device_node *np = pdev->dev.of_node;
int rst_gpio, cs_gpio, te_gpio, ad8_gpio, bl_gpio;
struct regulator *vdd_vreg;
struct regulator *avdd_vreg;
rc = mdss_qpic_pinctrl_init(pdev, qpic_panel_io);
if (rc)
pr_warn("%s: failed to get pin resources\n", __func__);
rst_gpio = of_get_named_gpio(np, "qcom,rst-gpio", 0);
cs_gpio = of_get_named_gpio(np, "qcom,cs-gpio", 0);
ad8_gpio = of_get_named_gpio(np, "qcom,ad8-gpio", 0);
te_gpio = of_get_named_gpio(np, "qcom,te-gpio", 0);
bl_gpio = of_get_named_gpio(np, "qcom,bl-gpio", 0);
if (!gpio_is_valid(rst_gpio))
pr_warn("%s: reset gpio not specified\n" , __func__);
else
qpic_panel_io->rst_gpio = rst_gpio;
if (!gpio_is_valid(cs_gpio))
pr_warn("%s: cs gpio not specified\n", __func__);
else
qpic_panel_io->cs_gpio = cs_gpio;
if (!gpio_is_valid(ad8_gpio))
pr_warn("%s: ad8 gpio not specified\n", __func__);
else
qpic_panel_io->ad8_gpio = ad8_gpio;
if (!gpio_is_valid(te_gpio))
pr_warn("%s: te gpio not specified\n", __func__);
else
qpic_panel_io->te_gpio = te_gpio;
if (!gpio_is_valid(bl_gpio))
pr_warn("%s: te gpio not specified\n", __func__);
else
qpic_panel_io->bl_gpio = bl_gpio;
vdd_vreg = devm_regulator_get(&pdev->dev, "vdd");
if (IS_ERR(vdd_vreg))
pr_err("%s could not get vdd,", __func__);
else
qpic_panel_io->vdd_vreg = vdd_vreg;
avdd_vreg = devm_regulator_get(&pdev->dev, "avdd");
if (IS_ERR(avdd_vreg))
pr_err("%s could not get avdd,", __func__);
else
qpic_panel_io->avdd_vreg = avdd_vreg;
return 0;
}
static int mdss_panel_parse_dt(struct platform_device *pdev,
struct mdss_panel_data *panel_data)
{
struct device_node *np = pdev->dev.of_node;
u32 res[6], tmp;
int rc;
rc = of_property_read_u32_array(np, "qcom,mdss-pan-res", res, 2);
if (rc) {
pr_err("%s:%d, panel resolution not specified\n",
__func__, __LINE__);
return -EINVAL;
}
pr_debug("panel res %d %d\n", res[0], res[1]);
panel_data->panel_info.xres = (!rc ? res[0] : 320);
panel_data->panel_info.yres = (!rc ? res[1] : 480);
rc = of_property_read_u32(np, "qcom,mdss-pan-bpp", &tmp);
if (rc) {
pr_err("%s:%d, panel bpp not specified\n",
__func__, __LINE__);
return -EINVAL;
}
pr_debug("panel bpp %d\n", tmp);
panel_data->panel_info.bpp = (!rc ? tmp : 18);
of_property_read_u32(np, "qcom,refresh_rate", &panel_refresh_rate);
panel_data->panel_info.type = EBI2_PANEL;
panel_data->panel_info.pdest = DISPLAY_1;
return rc;
}
static int mdss_qpic_panel_probe(struct platform_device *pdev)
{
int rc = 0;
static struct mdss_panel_data vendor_pdata;
static const char *panel_name;
pr_debug("%s:%d, debug info id=%d", __func__, __LINE__, pdev->id);
if (!pdev->dev.of_node)
return -ENODEV;
panel_name = of_get_property(pdev->dev.of_node, "label", NULL);
if (!panel_name)
pr_info("%s:%d, panel name not specified\n",
__func__, __LINE__);
else
pr_info("%s: Panel Name = %s\n", __func__, panel_name);
rc = mdss_panel_parse_dt(pdev, &vendor_pdata);
if (rc)
return rc;
/* select panel according to label */
if (panel_name && !strcmp(panel_name, "ili qvga lcdc panel")) {
qpic_panel_on = ili9341_on;
qpic_panel_off = ili9341_off;
} else {
/* select default panel driver */
pr_info("%s: select default panel driver\n", __func__);
qpic_panel_on = ili9341_on;
qpic_panel_off = ili9341_off;
}
rc = qpic_register_panel(&vendor_pdata);
if (rc)
return rc;
return 0;
}
static const struct of_device_id mdss_qpic_panel_match[] = {
{.compatible = "qcom,mdss-qpic-panel"},
{}
};
static struct platform_driver this_driver = {
.probe = mdss_qpic_panel_probe,
.driver = {
.name = "qpic_panel",
.of_match_table = mdss_qpic_panel_match,
},
};
static int __init mdss_qpic_panel_init(void)
{
return platform_driver_register(&this_driver);
}
MODULE_DEVICE_TABLE(of, mdss_qpic_panel_match);
module_init(mdss_qpic_panel_init);
|