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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
|
/* Copyright (c) 2013-2016, 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/kernel.h>
#include <linux/sched.h>
#include <linux/time.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/spinlock.h>
#include <linux/hrtimer.h>
#include <linux/clk.h>
#include <linux/io.h>
#include <linux/debugfs.h>
#include <linux/delay.h>
#include <linux/mutex.h>
#include <linux/regulator/consumer.h>
#include <linux/semaphore.h>
#include <linux/uaccess.h>
#include <linux/bootmem.h>
#include <linux/dma-mapping.h>
#include <linux/clk/msm-clk.h>
#include <linux/msm-sps.h>
#include <linux/msm-bus.h>
#include "mdss_fb.h"
#include "mdss_qpic.h"
#include "mdss_qpic_panel.h"
static int mdss_qpic_probe(struct platform_device *pdev);
static int mdss_qpic_remove(struct platform_device *pdev);
static void qpic_interrupt_en(u32 en);
struct qpic_data_type *qpic_res;
/* for debugging */
static u32 use_bam = true;
static u32 use_irq = true;
static u32 use_vsync;
static const struct of_device_id mdss_qpic_dt_match[] = {
{ .compatible = "qcom,mdss_qpic",},
{}
};
MODULE_DEVICE_TABLE(of, mdss_qpic_dt_match);
static struct platform_driver mdss_qpic_driver = {
.probe = mdss_qpic_probe,
.remove = mdss_qpic_remove,
.shutdown = NULL,
.driver = {
/*
* Simulate mdp hw
*/
.name = "mdp",
.of_match_table = mdss_qpic_dt_match,
},
};
int qpic_on(struct msm_fb_data_type *mfd)
{
int ret;
if (qpic_res->qpic_a_clk)
clk_prepare_enable(qpic_res->qpic_a_clk);
ret = mdss_qpic_panel_on(qpic_res->panel_data, &qpic_res->panel_io);
qpic_res->qpic_is_on = true;
return ret;
}
int qpic_off(struct msm_fb_data_type *mfd)
{
int ret;
ret = mdss_qpic_panel_off(qpic_res->panel_data, &qpic_res->panel_io);
if (use_irq)
qpic_interrupt_en(false);
if (qpic_res->qpic_a_clk)
clk_disable_unprepare(qpic_res->qpic_a_clk);
qpic_res->qpic_is_on = false;
return ret;
}
static int msm_qpic_bus_set_vote(u32 vote)
{
int ret;
if (!qpic_res->bus_handle)
return 0;
ret = msm_bus_scale_client_update_request(qpic_res->bus_handle,
vote);
if (ret)
pr_err("msm_bus_scale_client_update_request() failed, bus_handle=0x%x, vote=%d, err=%d\n",
qpic_res->bus_handle, vote, ret);
return ret;
}
static void mdss_qpic_pan_display(struct msm_fb_data_type *mfd)
{
struct fb_info *fbi;
u32 offset, fb_offset, size;
int bpp;
if (!mfd) {
pr_err("%s: mfd is NULL!", __func__);
return;
}
if (!qpic_res->qpic_is_on) {
pr_err("%s: Failed since panel is not ON\n", __func__);
return;
}
fbi = mfd->fbi;
bpp = fbi->var.bits_per_pixel / 8;
offset = fbi->var.xoffset * bpp +
fbi->var.yoffset * fbi->fix.line_length;
if (offset > fbi->fix.smem_len) {
pr_err("invalid fb offset=%u total length=%u\n",
offset, fbi->fix.smem_len);
return;
}
if (use_bam)
fb_offset = (u32)fbi->fix.smem_start + offset;
else
fb_offset = (u32)mfd->fbi->screen_base + offset;
msm_qpic_bus_set_vote(1);
mdss_qpic_panel_on(qpic_res->panel_data, &qpic_res->panel_io);
size = fbi->var.xres * fbi->var.yres * bpp;
qpic_send_frame(0, 0, fbi->var.xres - 1, fbi->var.yres - 1,
(u32 *)fb_offset, size);
msm_qpic_bus_set_vote(0);
}
int mdss_qpic_alloc_fb_mem(struct msm_fb_data_type *mfd)
{
size_t size;
u32 yres = mfd->fbi->var.yres_virtual;
size = PAGE_ALIGN(mfd->fbi->fix.line_length * yres);
if (!qpic_res->res_init)
return -EINVAL;
if (mfd->index != 0) {
mfd->fbi->fix.smem_start = 0;
mfd->fbi->screen_base = NULL;
mfd->fbi->fix.smem_len = 0;
mfd->iova = 0;
return 0;
}
if (!qpic_res->fb_virt) {
qpic_res->fb_virt = (void *)dmam_alloc_coherent(
&qpic_res->pdev->dev,
size,
&qpic_res->fb_phys,
GFP_KERNEL);
pr_debug("%s size=%d vir_addr=%x phys_addr=%x",
__func__, size, (int)qpic_res->fb_virt,
(int)qpic_res->fb_phys);
if (!qpic_res->fb_virt) {
pr_err("%s fb allocation failed", __func__);
return -ENOMEM;
}
}
if (!qpic_res->cmd_buf_virt) {
qpic_res->cmd_buf_virt = dma_alloc_writecombine(
NULL, QPIC_MAX_CMD_BUF_SIZE,
&qpic_res->cmd_buf_phys, GFP_KERNEL);
pr_debug("%s cmd_buf virt=%x phys=%x", __func__,
(int)qpic_res->cmd_buf_virt,
qpic_res->cmd_buf_phys);
if (!qpic_res->cmd_buf_virt) {
pr_err("%s cmd buf allocation failed", __func__);
return -ENOMEM;
}
}
mfd->fbi->fix.smem_start = qpic_res->fb_phys;
mfd->fbi->screen_base = qpic_res->fb_virt;
mfd->fbi->fix.smem_len = size;
mfd->iova = 0;
return 0;
}
u32 mdss_qpic_fb_stride(u32 fb_index, u32 xres, int bpp)
{
return xres * bpp;
}
int mdss_qpic_overlay_init(struct msm_fb_data_type *mfd)
{
struct msm_mdp_interface *qpic_interface = &mfd->mdp;
qpic_interface->on_fnc = qpic_on;
qpic_interface->off_fnc = qpic_off;
qpic_interface->do_histogram = NULL;
qpic_interface->cursor_update = NULL;
qpic_interface->dma_fnc = mdss_qpic_pan_display;
qpic_interface->ioctl_handler = NULL;
qpic_interface->kickoff_fnc = NULL;
return 0;
}
int qpic_register_panel(struct mdss_panel_data *pdata)
{
struct platform_device *mdss_fb_dev = NULL;
int rc;
if (!qpic_res)
return -ENODEV;
mdss_fb_dev = platform_device_alloc("mdss_fb", pdata->panel_info.pdest);
if (!mdss_fb_dev) {
pr_err("unable to allocate mdss_fb device\n");
return -ENOMEM;
}
mdss_fb_dev->dev.platform_data = pdata;
rc = platform_device_add(mdss_fb_dev);
if (rc) {
platform_device_put(mdss_fb_dev);
pr_err("unable to probe mdss_fb device (%d)\n", rc);
return rc;
}
qpic_res->panel_data = pdata;
return rc;
}
int qpic_init_sps(struct platform_device *pdev,
struct qpic_sps_endpt *end_point)
{
int rc = 0;
struct sps_pipe *pipe_handle;
struct sps_connect *sps_config = &end_point->config;
struct sps_register_event *sps_event = &end_point->bam_event;
struct sps_bam_props bam = {0};
unsigned long bam_handle = 0;
if (qpic_res->sps_init)
return 0;
bam.phys_addr = qpic_res->qpic_phys + 0x4000;
bam.virt_addr = qpic_res->qpic_base + 0x4000;
bam.irq = qpic_res->irq - 4;
bam.manage = SPS_BAM_MGR_DEVICE_REMOTE | SPS_BAM_MGR_MULTI_EE;
rc = sps_phy2h(bam.phys_addr, &bam_handle);
if (rc)
rc = sps_register_bam_device(&bam, &bam_handle);
if (rc) {
pr_err("%s bam_handle is NULL", __func__);
rc = -ENOMEM;
goto out;
}
pipe_handle = sps_alloc_endpoint();
if (!pipe_handle) {
pr_err("sps_alloc_endpoint() failed\n");
rc = -ENOMEM;
goto out;
}
rc = sps_get_config(pipe_handle, sps_config);
if (rc) {
pr_err("sps_get_config() failed %d\n", rc);
goto free_endpoint;
}
/* WRITE CASE: source - system memory; destination - BAM */
sps_config->source = SPS_DEV_HANDLE_MEM;
sps_config->destination = bam_handle;
sps_config->mode = SPS_MODE_DEST;
sps_config->dest_pipe_index = 6;
sps_config->options = SPS_O_AUTO_ENABLE | SPS_O_EOT;
sps_config->lock_group = 0;
/*
* Descriptor FIFO is a cyclic FIFO. If 64 descriptors
* are allowed to be submitted before we get any ack for any of them,
* the descriptor FIFO size should be: (SPS_MAX_DESC_NUM + 1) *
* sizeof(struct sps_iovec).
*/
sps_config->desc.size = (64) *
sizeof(struct sps_iovec);
sps_config->desc.base = dmam_alloc_coherent(&pdev->dev,
sps_config->desc.size,
&sps_config->desc.phys_base,
GFP_KERNEL);
if (!sps_config->desc.base) {
pr_err("dmam_alloc_coherent() failed for size %x\n",
sps_config->desc.size);
rc = -ENOMEM;
goto free_endpoint;
}
memset(sps_config->desc.base, 0x00, sps_config->desc.size);
rc = sps_connect(pipe_handle, sps_config);
if (rc) {
pr_err("sps_connect() failed %d\n", rc);
goto free_endpoint;
}
init_completion(&end_point->completion);
sps_event->mode = SPS_TRIGGER_WAIT;
sps_event->options = SPS_O_EOT;
sps_event->xfer_done = &end_point->completion;
sps_event->user = (void *)qpic_res;
rc = sps_register_event(pipe_handle, sps_event);
if (rc) {
pr_err("sps_register_event() failed %d\n", rc);
goto sps_disconnect;
}
end_point->handle = pipe_handle;
qpic_res->sps_init = true;
goto out;
sps_disconnect:
sps_disconnect(pipe_handle);
free_endpoint:
sps_free_endpoint(pipe_handle);
out:
return rc;
}
void mdss_qpic_reset(void)
{
u32 time_end;
QPIC_OUTP(QPIC_REG_QPIC_LCDC_RESET, 1 << 0);
/* wait 100 us after reset as suggested by hw */
usleep_range(100, 100);
time_end = (u32)ktime_to_ms(ktime_get()) +
QPIC_MAX_VSYNC_WAIT_TIME;
while (((QPIC_INP(QPIC_REG_QPIC_LCDC_STTS) & (1 << 8)) == 0)) {
if ((u32)ktime_to_ms(ktime_get()) > time_end) {
pr_err("%s reset not finished", __func__);
break;
}
/* yield 100 us for next polling by experiment*/
usleep_range(100, 100);
}
}
static void qpic_interrupt_en(u32 en)
{
QPIC_OUTP(QPIC_REG_QPIC_LCDC_IRQ_CLR, 0xff);
if (en) {
if (!qpic_res->irq_ena) {
init_completion(&qpic_res->fifo_eof_comp);
qpic_res->irq_ena = true;
enable_irq(qpic_res->irq);
}
} else {
QPIC_OUTP(QPIC_REG_QPIC_LCDC_IRQ_EN, 0);
disable_irq(qpic_res->irq);
qpic_res->irq_ena = false;
}
}
static irqreturn_t qpic_irq_handler(int irq, void *ptr)
{
u32 data;
data = QPIC_INP(QPIC_REG_QPIC_LCDC_IRQ_STTS);
QPIC_OUTP(QPIC_REG_QPIC_LCDC_IRQ_CLR, 0xff);
QPIC_OUTP(QPIC_REG_QPIC_LCDC_IRQ_EN, 0);
if (data & ((1 << 2) | (1 << 4)))
complete(&qpic_res->fifo_eof_comp);
return IRQ_HANDLED;
}
static int qpic_send_pkt_bam(u32 cmd, u32 len, u8 *param)
{
int ret = 0;
u32 phys_addr, cfg2, block_len , flags;
if ((cmd != OP_WRITE_MEMORY_START) &&
(cmd != OP_WRITE_MEMORY_CONTINUE)) {
memcpy((u8 *)qpic_res->cmd_buf_virt, param, len);
phys_addr = qpic_res->cmd_buf_phys;
} else {
phys_addr = (u32)param;
}
cfg2 = QPIC_INP(QPIC_REG_QPIC_LCDC_CFG2);
cfg2 &= ~0xFF;
cfg2 |= cmd;
QPIC_OUTP(QPIC_REG_QPIC_LCDC_CFG2, cfg2);
block_len = 0x7FF0;
while (len > 0) {
if (len <= 0x7FF0) {
flags = SPS_IOVEC_FLAG_EOT;
block_len = len;
} else {
flags = 0;
}
ret = sps_transfer_one(qpic_res->qpic_endpt.handle,
phys_addr, block_len, NULL, flags);
if (ret)
pr_err("failed to submit command %x ret %d\n",
cmd, ret);
phys_addr += block_len;
len -= block_len;
}
ret = wait_for_completion_timeout(
&qpic_res->qpic_endpt.completion,
msecs_to_jiffies(100 * 4));
if (ret <= 0)
pr_err("%s timeout %x", __func__, ret);
else
ret = 0;
return ret;
}
void qpic_dump_reg(void)
{
pr_info("%s\n", __func__);
pr_info("QPIC_REG_QPIC_LCDC_CTRL = %x\n",
QPIC_INP(QPIC_REG_QPIC_LCDC_CTRL));
pr_info("QPIC_REG_QPIC_LCDC_CMD_DATA_CYCLE_CNT = %x\n",
QPIC_INP(QPIC_REG_QPIC_LCDC_CMD_DATA_CYCLE_CNT));
pr_info("QPIC_REG_QPIC_LCDC_CFG0 = %x\n",
QPIC_INP(QPIC_REG_QPIC_LCDC_CFG0));
pr_info("QPIC_REG_QPIC_LCDC_CFG1 = %x\n",
QPIC_INP(QPIC_REG_QPIC_LCDC_CFG1));
pr_info("QPIC_REG_QPIC_LCDC_CFG2 = %x\n",
QPIC_INP(QPIC_REG_QPIC_LCDC_CFG2));
pr_info("QPIC_REG_QPIC_LCDC_IRQ_EN = %x\n",
QPIC_INP(QPIC_REG_QPIC_LCDC_IRQ_EN));
pr_info("QPIC_REG_QPIC_LCDC_IRQ_STTS = %x\n",
QPIC_INP(QPIC_REG_QPIC_LCDC_IRQ_STTS));
pr_info("QPIC_REG_QPIC_LCDC_STTS = %x\n",
QPIC_INP(QPIC_REG_QPIC_LCDC_STTS));
pr_info("QPIC_REG_QPIC_LCDC_FIFO_SOF = %x\n",
QPIC_INP(QPIC_REG_QPIC_LCDC_FIFO_SOF));
}
static int qpic_wait_for_fifo(void)
{
u32 data, time_end;
int ret = 0;
if (use_irq) {
data = QPIC_INP(QPIC_REG_QPIC_LCDC_STTS);
data &= 0x3F;
if (data == 0)
return ret;
reinit_completion(&qpic_res->fifo_eof_comp);
QPIC_OUTP(QPIC_REG_QPIC_LCDC_IRQ_EN, (1 << 4));
ret = wait_for_completion_timeout(&qpic_res->fifo_eof_comp,
msecs_to_jiffies(QPIC_MAX_VSYNC_WAIT_TIME));
if (ret > 0) {
ret = 0;
} else {
pr_err("%s timeout %x\n", __func__, ret);
ret = -ETIMEDOUT;
}
QPIC_OUTP(QPIC_REG_QPIC_LCDC_IRQ_EN, 0);
} else {
time_end = (u32)ktime_to_ms(ktime_get()) +
QPIC_MAX_VSYNC_WAIT_TIME;
while (1) {
data = QPIC_INP(QPIC_REG_QPIC_LCDC_STTS);
data &= 0x3F;
if (data == 0)
break;
/* yield 10 us for next polling by experiment*/
usleep_range(10, 10);
if (ktime_to_ms(ktime_get()) > time_end) {
pr_err("%s time out", __func__);
ret = -EBUSY;
break;
}
}
}
return ret;
}
static int qpic_wait_for_eof(void)
{
u32 data, time_end;
int ret = 0;
if (use_irq) {
data = QPIC_INP(QPIC_REG_QPIC_LCDC_IRQ_STTS);
if (data & (1 << 2))
return ret;
reinit_completion(&qpic_res->fifo_eof_comp);
QPIC_OUTP(QPIC_REG_QPIC_LCDC_IRQ_EN, (1 << 2));
ret = wait_for_completion_timeout(&qpic_res->fifo_eof_comp,
msecs_to_jiffies(QPIC_MAX_VSYNC_WAIT_TIME));
if (ret > 0) {
ret = 0;
} else {
pr_err("%s timeout %x\n", __func__, ret);
ret = -ETIMEDOUT;
}
QPIC_OUTP(QPIC_REG_QPIC_LCDC_IRQ_EN, 0);
} else {
time_end = (u32)ktime_to_ms(ktime_get()) +
QPIC_MAX_VSYNC_WAIT_TIME;
while (1) {
data = QPIC_INP(QPIC_REG_QPIC_LCDC_IRQ_STTS);
if (data & (1 << 2))
break;
/* yield 10 us for next polling by experiment*/
usleep_range(10, 10);
if (ktime_to_ms(ktime_get()) > time_end) {
pr_err("%s wait for eof time out\n", __func__);
qpic_dump_reg();
ret = -EBUSY;
break;
}
}
}
return ret;
}
static int qpic_send_pkt_sw(u32 cmd, u32 len, u8 *param)
{
u32 bytes_left, space, data, cfg2;
int i, ret = 0;
if (len <= 4) {
len = (len + 3) / 4; /* len in dwords */
data = 0;
if (param) {
for (i = 0; i < len; i++)
data |= (u32)param[i] << (8 * i);
}
QPIC_OUTP(QPIC_REG_QPIC_LCDC_CMD_DATA_CYCLE_CNT, len);
QPIC_OUTP(QPIC_REG_LCD_DEVICE_CMD0 + (4 * cmd), data);
return 0;
}
if ((len & 0x1) != 0) {
pr_debug("%s: number of bytes needs be even", __func__);
len = (len + 1) & (~0x1);
}
QPIC_OUTP(QPIC_REG_QPIC_LCDC_IRQ_CLR, 0xff);
QPIC_OUTP(QPIC_REG_QPIC_LCDC_CMD_DATA_CYCLE_CNT, 0);
cfg2 = QPIC_INP(QPIC_REG_QPIC_LCDC_CFG2);
if ((cmd != OP_WRITE_MEMORY_START) &&
(cmd != OP_WRITE_MEMORY_CONTINUE))
cfg2 |= (1 << 24); /* transparent mode */
else
cfg2 &= ~(1 << 24);
cfg2 &= ~0xFF;
cfg2 |= cmd;
QPIC_OUTP(QPIC_REG_QPIC_LCDC_CFG2, cfg2);
QPIC_OUTP(QPIC_REG_QPIC_LCDC_FIFO_SOF, 0x0);
bytes_left = len;
while (bytes_left > 0) {
ret = qpic_wait_for_fifo();
if (ret)
goto exit_send_cmd_sw;
space = 16;
while ((space > 0) && (bytes_left > 0)) {
/* write to fifo */
if (bytes_left >= 4) {
QPIC_OUTP(QPIC_REG_QPIC_LCDC_FIFO_DATA_PORT0,
*(u32 *)param);
param += 4;
bytes_left -= 4;
space--;
} else if (bytes_left == 2) {
QPIC_OUTPW(QPIC_REG_QPIC_LCDC_FIFO_DATA_PORT0,
*(u16 *)param);
bytes_left -= 2;
}
}
}
/* finished */
QPIC_OUTP(QPIC_REG_QPIC_LCDC_FIFO_EOF, 0x0);
ret = qpic_wait_for_eof();
exit_send_cmd_sw:
cfg2 &= ~(1 << 24);
QPIC_OUTP(QPIC_REG_QPIC_LCDC_CFG2, cfg2);
return ret;
}
int qpic_send_pkt(u32 cmd, u8 *param, u32 len)
{
if (!use_bam || ((cmd != OP_WRITE_MEMORY_CONTINUE) &&
(cmd != OP_WRITE_MEMORY_START)))
return qpic_send_pkt_sw(cmd, len, param);
else
return qpic_send_pkt_bam(cmd, len, param);
}
int mdss_qpic_init(void)
{
int ret = 0;
u32 data;
mdss_qpic_reset();
pr_info("%s version=%x", __func__, QPIC_INP(QPIC_REG_LCDC_VERSION));
data = QPIC_INP(QPIC_REG_QPIC_LCDC_CTRL);
/* clear vsync wait , bam mode = 0*/
data &= ~(3 << 0);
data &= ~(0x1f << 3);
data |= (1 << 3); /* threshold */
data |= (1 << 8); /* lcd_en */
data &= ~(0x1f << 9);
data |= (1 << 9); /* threshold */
QPIC_OUTP(QPIC_REG_QPIC_LCDC_CTRL, data);
if (use_irq && (!qpic_res->irq_requested)) {
ret = devm_request_irq(&qpic_res->pdev->dev,
qpic_res->irq, qpic_irq_handler,
0x0, "QPIC", qpic_res);
if (ret) {
pr_err("qpic request_irq() failed!\n");
use_irq = false;
} else {
disable_irq(qpic_res->irq);
}
qpic_res->irq_requested = true;
}
qpic_interrupt_en(use_irq);
QPIC_OUTP(QPIC_REG_QPIC_LCDC_CFG0, 0x02108501);
data = QPIC_INP(QPIC_REG_QPIC_LCDC_CFG2);
data &= ~(0xFFF);
data |= 0x200; /* XRGB */
data |= 0x2C;
QPIC_OUTP(QPIC_REG_QPIC_LCDC_CFG2, data);
if (use_bam) {
qpic_init_sps(qpic_res->pdev , &qpic_res->qpic_endpt);
data = QPIC_INP(QPIC_REG_QPIC_LCDC_CTRL);
data |= (1 << 1);
QPIC_OUTP(QPIC_REG_QPIC_LCDC_CTRL, data);
}
/* TE enable */
if (use_vsync) {
data = QPIC_INP(QPIC_REG_QPIC_LCDC_CTRL);
data |= (1 << 0);
QPIC_OUTP(QPIC_REG_QPIC_LCDC_CTRL, data);
}
return ret;
}
u32 qpic_read_data(u32 cmd_index, u32 size)
{
u32 data = 0;
if (size <= 4) {
QPIC_OUTP(QPIC_REG_QPIC_LCDC_CMD_DATA_CYCLE_CNT, size);
data = QPIC_INP(QPIC_REG_LCD_DEVICE_CMD0 + (cmd_index * 4));
}
return data;
}
static int msm_qpic_bus_register(struct platform_device *pdev)
{
int ret = 0;
struct msm_bus_scale_pdata *use_cases;
use_cases = msm_bus_cl_get_pdata(pdev);
if (!use_cases) {
pr_err("msm_bus_cl_get_pdata failed\n");
return -EINVAL;
}
qpic_res->bus_handle =
msm_bus_scale_register_client(use_cases);
if (!qpic_res->bus_handle) {
ret = -EINVAL;
pr_err("msm_bus_scale_register_client failed\n");
}
return ret;
}
static int mdss_qpic_probe(struct platform_device *pdev)
{
struct resource *res;
int rc = 0;
static struct msm_mdp_interface qpic_interface = {
.init_fnc = mdss_qpic_overlay_init,
.fb_mem_alloc_fnc = mdss_qpic_alloc_fb_mem,
.fb_stride = mdss_qpic_fb_stride,
};
if (!pdev->dev.of_node) {
pr_err("qpic driver only supports device tree probe\n");
return -ENOTSUPP;
}
if (!qpic_res)
qpic_res = devm_kzalloc(&pdev->dev,
sizeof(*qpic_res), GFP_KERNEL);
if (!qpic_res)
return -ENOMEM;
if (qpic_res->res_init) {
pr_err("qpic already initialized\n");
return -EINVAL;
}
pdev->id = 0;
qpic_res->pdev = pdev;
platform_set_drvdata(pdev, qpic_res);
res = platform_get_resource_byname(pdev,
IORESOURCE_MEM, "qpic_base");
if (!res) {
pr_err("unable to get QPIC reg base address\n");
rc = -ENOMEM;
goto probe_done;
}
qpic_res->qpic_reg_size = resource_size(res);
qpic_res->qpic_base = devm_ioremap(&pdev->dev, res->start,
qpic_res->qpic_reg_size);
if (unlikely(!qpic_res->qpic_base)) {
pr_err("unable to map MDSS QPIC base\n");
rc = -ENOMEM;
goto probe_done;
}
qpic_res->qpic_phys = res->start;
pr_info("MDSS QPIC HW Base phy_Address=0x%x virt=0x%x\n",
(int) res->start,
(int) qpic_res->qpic_base);
res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
if (!res) {
pr_err("unable to get QPIC irq\n");
rc = -ENOMEM;
goto probe_done;
}
qpic_res->qpic_a_clk = clk_get(&pdev->dev, "core_a_clk");
if (IS_ERR(qpic_res->qpic_a_clk))
pr_err("%s: Can't find core_a_clk", __func__);
qpic_res->irq = res->start;
qpic_res->res_init = true;
mdss_qpic_panel_io_init(pdev, &qpic_res->panel_io);
rc = mdss_fb_register_mdp_instance(&qpic_interface);
if (rc)
pr_err("unable to register QPIC instance\n");
msm_qpic_bus_register(pdev);
probe_done:
return rc;
}
static int mdss_qpic_remove(struct platform_device *pdev)
{
if (qpic_res->bus_handle)
msm_bus_scale_unregister_client(qpic_res->bus_handle);
qpic_res->bus_handle = 0;
return 0;
}
static int __init mdss_qpic_driver_init(void)
{
int ret;
ret = platform_driver_register(&mdss_qpic_driver);
if (ret)
pr_err("mdss_qpic_register_driver() failed!\n");
return ret;
}
module_init(mdss_qpic_driver_init);
|