4 * Copyright (C) 2007 Google Incorporated
5 * Copyright (C) 2007 QUALCOMM Incorporated
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/dma-mapping.h>
21 #include <linux/interrupt.h>
22 #include <linux/platform_device.h>
23 #include <linux/delay.h>
24 #include <linux/gfp.h>
25 #include <linux/spinlock.h>
26 #include <linux/clk.h>
28 #include <linux/sched.h>
29 #include <linux/platform_data/video-msm_fb.h>
32 #define FLAG_DISABLE_HIBERNATION 0x0001
33 #define FLAG_HAVE_CAPS 0x0002
34 #define FLAG_HAS_VSYNC_IRQ 0x0004
35 #define FLAG_HAVE_STATUS 0x0008
37 #define CMD_GET_CLIENT_CAP 0x0601
38 #define CMD_GET_CLIENT_STATUS 0x0602
41 unsigned char raw
[MDDI_REV_BUFFER_SIZE
];
42 struct mddi_rev_packet hdr
;
43 struct mddi_client_status status
;
44 struct mddi_client_caps caps
;
45 struct mddi_register_access reg
;
48 struct reg_read_info
{
49 struct completion done
;
61 struct msm_mddi_client_data client_data
;
63 /* buffer for rev encap packets */
66 struct mddi_llentry
*reg_write_data
;
67 dma_addr_t reg_write_addr
;
68 struct mddi_llentry
*reg_read_data
;
69 dma_addr_t reg_read_addr
;
75 wait_queue_head_t int_wait
;
77 struct mutex reg_write_lock
;
78 struct mutex reg_read_lock
;
79 struct reg_read_info
*reg_read
;
81 struct mddi_client_caps caps
;
82 struct mddi_client_status status
;
84 void (*power_client
)(struct msm_mddi_client_data
*, int);
86 /* client device published to bind us to the
87 * appropriate mddi_client driver
91 struct platform_device client_pdev
;
94 static void mddi_init_rev_encap(struct mddi_info
*mddi
);
96 #define mddi_readl(r) readl(mddi->base + (MDDI_##r))
97 #define mddi_writel(v, r) writel((v), mddi->base + (MDDI_##r))
99 void mddi_activate_link(struct msm_mddi_client_data
*cdata
)
101 struct mddi_info
*mddi
= container_of(cdata
, struct mddi_info
,
104 mddi_writel(MDDI_CMD_LINK_ACTIVE
, CMD
);
107 static void mddi_handle_link_list_done(struct mddi_info
*mddi
)
111 static void mddi_reset_rev_encap_ptr(struct mddi_info
*mddi
)
113 printk(KERN_INFO
"mddi: resetting rev ptr\n");
114 mddi
->rev_data_curr
= 0;
115 mddi_writel(mddi
->rev_addr
, REV_PTR
);
116 mddi_writel(mddi
->rev_addr
, REV_PTR
);
117 mddi_writel(MDDI_CMD_FORCE_NEW_REV_PTR
, CMD
);
120 static void mddi_handle_rev_data(struct mddi_info
*mddi
, union mddi_rev
*rev
)
123 struct reg_read_info
*ri
;
125 if ((rev
->hdr
.length
<= MDDI_REV_BUFFER_SIZE
- 2) &&
126 (rev
->hdr
.length
>= sizeof(struct mddi_rev_packet
) - 2)) {
128 switch (rev
->hdr
.type
) {
129 case TYPE_CLIENT_CAPS
:
130 memcpy(&mddi
->caps
, &rev
->caps
,
131 sizeof(struct mddi_client_caps
));
132 mddi
->flags
|= FLAG_HAVE_CAPS
;
133 wake_up(&mddi
->int_wait
);
135 case TYPE_CLIENT_STATUS
:
136 memcpy(&mddi
->status
, &rev
->status
,
137 sizeof(struct mddi_client_status
));
138 mddi
->flags
|= FLAG_HAVE_STATUS
;
139 wake_up(&mddi
->int_wait
);
141 case TYPE_REGISTER_ACCESS
:
144 printk(KERN_INFO
"rev: got reg %x = %x without "
146 rev
->reg
.register_address
,
147 rev
->reg
.register_data_list
);
150 if (ri
->reg
!= rev
->reg
.register_address
) {
151 printk(KERN_INFO
"rev: got reg %x = %x for "
152 "wrong register, expected "
154 rev
->reg
.register_address
,
155 rev
->reg
.register_data_list
, ri
->reg
);
158 mddi
->reg_read
= NULL
;
160 ri
->result
= rev
->reg
.register_data_list
;
164 printk(KERN_INFO
"rev: unknown reverse packet: "
165 "len=%04x type=%04x CURR_REV_PTR=%x\n",
166 rev
->hdr
.length
, rev
->hdr
.type
,
167 mddi_readl(CURR_REV_PTR
));
168 for (i
= 0; i
< rev
->hdr
.length
+ 2; i
++) {
170 printk(KERN_INFO
"\n");
171 printk(KERN_INFO
" %02x", rev
->raw
[i
]);
173 printk(KERN_INFO
"\n");
174 mddi_reset_rev_encap_ptr(mddi
);
177 printk(KERN_INFO
"bad rev length, %d, CURR_REV_PTR %x\n",
178 rev
->hdr
.length
, mddi_readl(CURR_REV_PTR
));
179 mddi_reset_rev_encap_ptr(mddi
);
183 static void mddi_wait_interrupt(struct mddi_info
*mddi
, uint32_t intmask
);
185 static void mddi_handle_rev_data_avail(struct mddi_info
*mddi
)
187 uint32_t rev_data_count
;
188 uint32_t rev_crc_err_count
;
189 struct reg_read_info
*ri
;
193 union mddi_rev
*crev
= mddi
->rev_data
+ mddi
->rev_data_curr
;
195 /* clear the interrupt */
196 mddi_writel(MDDI_INT_REV_DATA_AVAIL
, INT
);
197 rev_data_count
= mddi_readl(REV_PKT_CNT
);
198 rev_crc_err_count
= mddi_readl(REV_CRC_ERR
);
199 if (rev_data_count
> 1)
200 printk(KERN_INFO
"rev_data_count %d\n", rev_data_count
);
202 if (rev_crc_err_count
) {
203 printk(KERN_INFO
"rev_crc_err_count %d, INT %x\n",
204 rev_crc_err_count
, mddi_readl(INT
));
207 printk(KERN_INFO
"rev: got crc error without pending "
210 mddi
->reg_read
= NULL
;
217 if (rev_data_count
== 0)
220 prev_offset
= mddi
->rev_data_curr
;
222 length
= *((uint8_t *)mddi
->rev_data
+ mddi
->rev_data_curr
);
223 mddi
->rev_data_curr
++;
224 if (mddi
->rev_data_curr
== MDDI_REV_BUFFER_SIZE
)
225 mddi
->rev_data_curr
= 0;
226 length
+= *((uint8_t *)mddi
->rev_data
+ mddi
->rev_data_curr
) << 8;
227 mddi
->rev_data_curr
+= 1 + length
;
228 if (mddi
->rev_data_curr
>= MDDI_REV_BUFFER_SIZE
)
229 mddi
->rev_data_curr
=
230 mddi
->rev_data_curr
% MDDI_REV_BUFFER_SIZE
;
232 if (length
> MDDI_REV_BUFFER_SIZE
- 2) {
233 printk(KERN_INFO
"mddi: rev data length greater than buffer"
235 mddi_reset_rev_encap_ptr(mddi
);
239 if (prev_offset
+ 2 + length
>= MDDI_REV_BUFFER_SIZE
) {
240 union mddi_rev tmprev
;
241 size_t rem
= MDDI_REV_BUFFER_SIZE
- prev_offset
;
242 memcpy(&tmprev
.raw
[0], mddi
->rev_data
+ prev_offset
, rem
);
243 memcpy(&tmprev
.raw
[rem
], mddi
->rev_data
, 2 + length
- rem
);
244 mddi_handle_rev_data(mddi
, &tmprev
);
246 mddi_handle_rev_data(mddi
, crev
);
249 if (prev_offset
< MDDI_REV_BUFFER_SIZE
/ 2 &&
250 mddi
->rev_data_curr
>= MDDI_REV_BUFFER_SIZE
/ 2) {
251 mddi_writel(mddi
->rev_addr
, REV_PTR
);
255 static irqreturn_t
mddi_isr(int irq
, void *data
)
257 struct msm_mddi_client_data
*cdata
= data
;
258 struct mddi_info
*mddi
= container_of(cdata
, struct mddi_info
,
260 uint32_t active
, status
;
262 spin_lock(&mddi
->int_lock
);
264 active
= mddi_readl(INT
);
265 status
= mddi_readl(STAT
);
267 mddi_writel(active
, INT
);
269 /* ignore any interrupts we have disabled */
270 active
&= mddi
->int_enable
;
272 mddi
->got_int
|= active
;
273 wake_up(&mddi
->int_wait
);
275 if (active
& MDDI_INT_PRI_LINK_LIST_DONE
) {
276 mddi
->int_enable
&= (~MDDI_INT_PRI_LINK_LIST_DONE
);
277 mddi_handle_link_list_done(mddi
);
279 if (active
& MDDI_INT_REV_DATA_AVAIL
)
280 mddi_handle_rev_data_avail(mddi
);
282 if (active
& ~MDDI_INT_NEED_CLEAR
)
283 mddi
->int_enable
&= ~(active
& ~MDDI_INT_NEED_CLEAR
);
285 if (active
& MDDI_INT_LINK_ACTIVE
) {
286 mddi
->int_enable
&= (~MDDI_INT_LINK_ACTIVE
);
287 mddi
->int_enable
|= MDDI_INT_IN_HIBERNATION
;
290 if (active
& MDDI_INT_IN_HIBERNATION
) {
291 mddi
->int_enable
&= (~MDDI_INT_IN_HIBERNATION
);
292 mddi
->int_enable
|= MDDI_INT_LINK_ACTIVE
;
295 mddi_writel(mddi
->int_enable
, INTEN
);
296 spin_unlock(&mddi
->int_lock
);
301 static long mddi_wait_interrupt_timeout(struct mddi_info
*mddi
,
302 uint32_t intmask
, int timeout
)
304 unsigned long irq_flags
;
306 spin_lock_irqsave(&mddi
->int_lock
, irq_flags
);
307 mddi
->got_int
&= ~intmask
;
308 mddi
->int_enable
|= intmask
;
309 mddi_writel(mddi
->int_enable
, INTEN
);
310 spin_unlock_irqrestore(&mddi
->int_lock
, irq_flags
);
311 return wait_event_timeout(mddi
->int_wait
, mddi
->got_int
& intmask
,
315 static void mddi_wait_interrupt(struct mddi_info
*mddi
, uint32_t intmask
)
317 if (mddi_wait_interrupt_timeout(mddi
, intmask
, HZ
/10) == 0)
318 printk(KERN_INFO
"mddi_wait_interrupt %d, timeout "
319 "waiting for %x, INT = %x, STAT = %x gotint = %x\n",
320 current
->pid
, intmask
, mddi_readl(INT
), mddi_readl(STAT
),
324 static void mddi_init_rev_encap(struct mddi_info
*mddi
)
326 memset(mddi
->rev_data
, 0xee, MDDI_REV_BUFFER_SIZE
);
327 mddi_writel(mddi
->rev_addr
, REV_PTR
);
328 mddi_writel(MDDI_CMD_FORCE_NEW_REV_PTR
, CMD
);
329 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
332 void mddi_set_auto_hibernate(struct msm_mddi_client_data
*cdata
, int on
)
334 struct mddi_info
*mddi
= container_of(cdata
, struct mddi_info
,
336 mddi_writel(MDDI_CMD_POWERDOWN
, CMD
);
337 mddi_wait_interrupt(mddi
, MDDI_INT_IN_HIBERNATION
);
338 mddi_writel(MDDI_CMD_HIBERNATE
| !!on
, CMD
);
339 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
343 static uint16_t mddi_init_registers(struct mddi_info
*mddi
)
345 mddi_writel(0x0001, VERSION
);
346 mddi_writel(MDDI_HOST_BYTES_PER_SUBFRAME
, BPS
);
347 mddi_writel(0x0003, SPM
); /* subframes per media */
348 mddi_writel(0x0005, TA1_LEN
);
349 mddi_writel(MDDI_HOST_TA2_LEN
, TA2_LEN
);
350 mddi_writel(0x0096, DRIVE_HI
);
351 /* 0x32 normal, 0x50 for Toshiba display */
352 mddi_writel(0x0050, DRIVE_LO
);
353 mddi_writel(0x003C, DISP_WAKE
); /* wakeup counter */
354 mddi_writel(MDDI_HOST_REV_RATE_DIV
, REV_RATE_DIV
);
356 mddi_writel(MDDI_REV_BUFFER_SIZE
, REV_SIZE
);
357 mddi_writel(MDDI_MAX_REV_PKT_SIZE
, REV_ENCAP_SZ
);
359 /* disable periodic rev encap */
360 mddi_writel(MDDI_CMD_PERIODIC_REV_ENCAP
, CMD
);
361 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
363 if (mddi_readl(PAD_CTL
) == 0) {
364 /* If we are turning on band gap, need to wait 5us before
365 * turning on the rest of the PAD */
366 mddi_writel(0x08000, PAD_CTL
);
370 /* Recommendation from PAD hw team */
371 mddi_writel(0xa850f, PAD_CTL
);
374 /* Need an even number for counts */
375 mddi_writel(0x60006, DRIVER_START_CNT
);
377 mddi_set_auto_hibernate(&mddi
->client_data
, 0);
379 mddi_writel(MDDI_CMD_DISP_IGNORE
, CMD
);
380 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
382 mddi_init_rev_encap(mddi
);
383 return mddi_readl(CORE_VER
) & 0xffff;
386 static void mddi_suspend(struct msm_mddi_client_data
*cdata
)
388 struct mddi_info
*mddi
= container_of(cdata
, struct mddi_info
,
390 /* turn off the client */
391 if (mddi
->power_client
)
392 mddi
->power_client(&mddi
->client_data
, 0);
393 /* turn off the link */
394 mddi_writel(MDDI_CMD_RESET
, CMD
);
395 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
396 /* turn off the clock */
397 clk_disable(mddi
->clk
);
400 static void mddi_resume(struct msm_mddi_client_data
*cdata
)
402 struct mddi_info
*mddi
= container_of(cdata
, struct mddi_info
,
404 mddi_set_auto_hibernate(&mddi
->client_data
, 0);
405 /* turn on the client */
406 if (mddi
->power_client
)
407 mddi
->power_client(&mddi
->client_data
, 1);
408 /* turn on the clock */
409 clk_enable(mddi
->clk
);
410 /* set up the local registers */
411 mddi
->rev_data_curr
= 0;
412 mddi_init_registers(mddi
);
413 mddi_writel(mddi
->int_enable
, INTEN
);
414 mddi_writel(MDDI_CMD_LINK_ACTIVE
, CMD
);
415 mddi_writel(MDDI_CMD_SEND_RTD
, CMD
);
416 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
417 mddi_set_auto_hibernate(&mddi
->client_data
, 1);
420 static int mddi_get_client_caps(struct mddi_info
*mddi
)
424 /* clear any stale interrupts */
425 mddi_writel(0xffffffff, INT
);
427 mddi
->int_enable
= MDDI_INT_LINK_ACTIVE
|
428 MDDI_INT_IN_HIBERNATION
|
429 MDDI_INT_PRI_LINK_LIST_DONE
|
430 MDDI_INT_REV_DATA_AVAIL
|
431 MDDI_INT_REV_OVERFLOW
|
432 MDDI_INT_REV_OVERWRITE
|
433 MDDI_INT_RTD_FAILURE
;
434 mddi_writel(mddi
->int_enable
, INTEN
);
436 mddi_writel(MDDI_CMD_LINK_ACTIVE
, CMD
);
437 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
439 for (j
= 0; j
< 3; j
++) {
440 /* the toshiba vga panel does not respond to get
441 * caps unless you SEND_RTD, but the first SEND_RTD
444 for (i
= 0; i
< 4; i
++) {
447 mddi_writel(MDDI_CMD_SEND_RTD
, CMD
);
448 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
449 stat
= mddi_readl(STAT
);
450 printk(KERN_INFO
"mddi cmd send rtd: int %x, stat %x, "
451 "rtd val %x\n", mddi_readl(INT
), stat
,
452 mddi_readl(RTD_VAL
));
453 if ((stat
& MDDI_STAT_RTD_MEAS_FAIL
) == 0)
458 mddi_writel(CMD_GET_CLIENT_CAP
, CMD
);
459 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
460 wait_event_timeout(mddi
->int_wait
, mddi
->flags
& FLAG_HAVE_CAPS
,
463 if (mddi
->flags
& FLAG_HAVE_CAPS
)
465 printk(KERN_INFO
"mddi_init, timeout waiting for caps\n");
467 return mddi
->flags
& FLAG_HAVE_CAPS
;
470 /* link must be active when this is called */
471 int mddi_check_status(struct mddi_info
*mddi
)
473 int ret
= -1, retry
= 3;
474 mutex_lock(&mddi
->reg_read_lock
);
475 mddi_writel(MDDI_CMD_PERIODIC_REV_ENCAP
| 1, CMD
);
476 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
479 mddi
->flags
&= ~FLAG_HAVE_STATUS
;
480 mddi_writel(CMD_GET_CLIENT_STATUS
, CMD
);
481 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
482 wait_event_timeout(mddi
->int_wait
,
483 mddi
->flags
& FLAG_HAVE_STATUS
,
486 if (mddi
->flags
& FLAG_HAVE_STATUS
) {
487 if (mddi
->status
.crc_error_count
)
488 printk(KERN_INFO
"mddi status: crc_error "
490 mddi
->status
.crc_error_count
);
495 printk(KERN_INFO
"mddi status: failed to get client "
497 mddi_writel(MDDI_CMD_SEND_RTD
, CMD
);
498 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
501 mddi_writel(MDDI_CMD_PERIODIC_REV_ENCAP
| 0, CMD
);
502 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
503 mutex_unlock(&mddi
->reg_read_lock
);
508 void mddi_remote_write(struct msm_mddi_client_data
*cdata
, uint32_t val
,
511 struct mddi_info
*mddi
= container_of(cdata
, struct mddi_info
,
513 struct mddi_llentry
*ll
;
514 struct mddi_register_access
*ra
;
516 mutex_lock(&mddi
->reg_write_lock
);
518 ll
= mddi
->reg_write_data
;
522 ra
->type
= TYPE_REGISTER_ACCESS
;
524 ra
->read_write_info
= MDDI_WRITE
| 1;
527 ra
->register_address
= reg
;
528 ra
->register_data_list
= val
;
531 ll
->header_count
= 14;
533 ll
->data
= mddi
->reg_write_addr
+ offsetof(struct mddi_llentry
,
534 u
.r
.register_data_list
);
538 mddi_writel(mddi
->reg_write_addr
, PRI_PTR
);
540 mddi_wait_interrupt(mddi
, MDDI_INT_PRI_LINK_LIST_DONE
);
541 mutex_unlock(&mddi
->reg_write_lock
);
544 uint32_t mddi_remote_read(struct msm_mddi_client_data
*cdata
, uint32_t reg
)
546 struct mddi_info
*mddi
= container_of(cdata
, struct mddi_info
,
548 struct mddi_llentry
*ll
;
549 struct mddi_register_access
*ra
;
550 struct reg_read_info ri
;
553 unsigned long irq_flags
;
555 mutex_lock(&mddi
->reg_read_lock
);
557 ll
= mddi
->reg_read_data
;
561 ra
->type
= TYPE_REGISTER_ACCESS
;
563 ra
->read_write_info
= MDDI_READ
| 1;
566 ra
->register_address
= reg
;
569 ll
->header_count
= 14;
575 s
= mddi_readl(STAT
);
581 init_completion(&ri
.done
);
582 mddi
->reg_read
= &ri
;
583 mddi_writel(mddi
->reg_read_addr
, PRI_PTR
);
585 mddi_wait_interrupt(mddi
, MDDI_INT_PRI_LINK_LIST_DONE
);
587 /* Enable Periodic Reverse Encapsulation. */
588 mddi_writel(MDDI_CMD_PERIODIC_REV_ENCAP
| 1, CMD
);
589 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
590 if (wait_for_completion_timeout(&ri
.done
, HZ
/10) == 0 &&
592 printk(KERN_INFO
"mddi_remote_read(%x) timeout "
594 reg
, ri
.status
, ri
.result
, ri
.done
.done
);
595 spin_lock_irqsave(&mddi
->int_lock
, irq_flags
);
596 mddi
->reg_read
= NULL
;
597 spin_unlock_irqrestore(&mddi
->int_lock
, irq_flags
);
604 mddi_writel(MDDI_CMD_SEND_RTD
, CMD
);
605 mddi_writel(MDDI_CMD_LINK_ACTIVE
, CMD
);
606 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
607 printk(KERN_INFO
"mddi_remote_read: failed, sent "
608 "MDDI_CMD_SEND_RTD: int %x, stat %x, rtd val %x "
609 "curr_rev_ptr %x\n", mddi_readl(INT
), mddi_readl(STAT
),
610 mddi_readl(RTD_VAL
), mddi_readl(CURR_REV_PTR
));
611 } while (retry_count
-- > 0);
612 /* Disable Periodic Reverse Encapsulation. */
613 mddi_writel(MDDI_CMD_PERIODIC_REV_ENCAP
| 0, CMD
);
614 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
615 mddi
->reg_read
= NULL
;
616 mutex_unlock(&mddi
->reg_read_lock
);
620 static struct mddi_info mddi_info
[2];
622 static int mddi_clk_setup(struct platform_device
*pdev
, struct mddi_info
*mddi
,
623 unsigned long clk_rate
)
627 /* set up the clocks */
628 mddi
->clk
= clk_get(&pdev
->dev
, "mddi_clk");
629 if (IS_ERR(mddi
->clk
)) {
630 printk(KERN_INFO
"mddi: failed to get clock\n");
631 return PTR_ERR(mddi
->clk
);
633 ret
= clk_enable(mddi
->clk
);
636 ret
= clk_set_rate(mddi
->clk
, clk_rate
);
646 static int __init
mddi_rev_data_setup(struct mddi_info
*mddi
)
651 /* set up dma buffer */
652 dma
= dma_alloc_coherent(NULL
, 0x1000, &dma_addr
, GFP_KERNEL
);
655 mddi
->rev_data
= dma
;
656 mddi
->rev_data_curr
= 0;
657 mddi
->rev_addr
= dma_addr
;
658 mddi
->reg_write_data
= dma
+ MDDI_REV_BUFFER_SIZE
;
659 mddi
->reg_write_addr
= dma_addr
+ MDDI_REV_BUFFER_SIZE
;
660 mddi
->reg_read_data
= mddi
->reg_write_data
+ 1;
661 mddi
->reg_read_addr
= mddi
->reg_write_addr
+
662 sizeof(*mddi
->reg_write_data
);
666 static int mddi_probe(struct platform_device
*pdev
)
668 struct msm_mddi_platform_data
*pdata
= pdev
->dev
.platform_data
;
669 struct mddi_info
*mddi
= &mddi_info
[pdev
->id
];
670 struct resource
*resource
;
673 resource
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
675 printk(KERN_ERR
"mddi: no associated mem resource!\n");
678 mddi
->base
= ioremap(resource
->start
, resource_size(resource
));
680 printk(KERN_ERR
"mddi: failed to remap base!\n");
684 resource
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
686 printk(KERN_ERR
"mddi: no associated irq resource!\n");
688 goto error_get_irq_resource
;
690 mddi
->irq
= resource
->start
;
691 printk(KERN_INFO
"mddi: init() base=0x%p irq=%d\n", mddi
->base
,
693 mddi
->power_client
= pdata
->power_client
;
695 mutex_init(&mddi
->reg_write_lock
);
696 mutex_init(&mddi
->reg_read_lock
);
697 spin_lock_init(&mddi
->int_lock
);
698 init_waitqueue_head(&mddi
->int_wait
);
700 ret
= mddi_clk_setup(pdev
, mddi
, pdata
->clk_rate
);
702 printk(KERN_ERR
"mddi: failed to setup clock!\n");
703 goto error_clk_setup
;
706 ret
= mddi_rev_data_setup(mddi
);
708 printk(KERN_ERR
"mddi: failed to setup rev data!\n");
712 mddi
->int_enable
= 0;
713 mddi_writel(mddi
->int_enable
, INTEN
);
714 ret
= request_irq(mddi
->irq
, mddi_isr
, 0, "mddi",
717 printk(KERN_ERR
"mddi: failed to request enable irq!\n");
718 goto error_request_irq
;
721 /* turn on the mddi client bridge chip */
722 if (mddi
->power_client
)
723 mddi
->power_client(&mddi
->client_data
, 1);
725 /* initialize the mddi registers */
726 mddi_set_auto_hibernate(&mddi
->client_data
, 0);
727 mddi_writel(MDDI_CMD_RESET
, CMD
);
728 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
729 mddi
->version
= mddi_init_registers(mddi
);
730 if (mddi
->version
< 0x20) {
731 printk(KERN_ERR
"mddi: unsupported version 0x%x\n",
734 goto error_mddi_version
;
737 /* read the capabilities off the client */
738 if (!mddi_get_client_caps(mddi
)) {
739 printk(KERN_INFO
"mddi: no client found\n");
740 /* power down the panel */
741 mddi_writel(MDDI_CMD_POWERDOWN
, CMD
);
742 printk(KERN_INFO
"mddi powerdown: stat %x\n", mddi_readl(STAT
));
744 printk(KERN_INFO
"mddi powerdown: stat %x\n", mddi_readl(STAT
));
747 mddi_set_auto_hibernate(&mddi
->client_data
, 1);
749 if (mddi
->caps
.Mfr_Name
== 0 && mddi
->caps
.Product_Code
== 0)
750 pdata
->fixup(&mddi
->caps
.Mfr_Name
, &mddi
->caps
.Product_Code
);
752 mddi
->client_pdev
.id
= 0;
753 for (i
= 0; i
< pdata
->num_clients
; i
++) {
754 if (pdata
->client_platform_data
[i
].product_id
==
755 (mddi
->caps
.Mfr_Name
<< 16 | mddi
->caps
.Product_Code
)) {
756 mddi
->client_data
.private_client_data
=
757 pdata
->client_platform_data
[i
].client_data
;
758 mddi
->client_pdev
.name
=
759 pdata
->client_platform_data
[i
].name
;
760 mddi
->client_pdev
.id
=
761 pdata
->client_platform_data
[i
].id
;
762 /* XXX: possibly set clock */
767 if (i
>= pdata
->num_clients
)
768 mddi
->client_pdev
.name
= "mddi_c_dummy";
769 printk(KERN_INFO
"mddi: registering panel %s\n",
770 mddi
->client_pdev
.name
);
772 mddi
->client_data
.suspend
= mddi_suspend
;
773 mddi
->client_data
.resume
= mddi_resume
;
774 mddi
->client_data
.activate_link
= mddi_activate_link
;
775 mddi
->client_data
.remote_write
= mddi_remote_write
;
776 mddi
->client_data
.remote_read
= mddi_remote_read
;
777 mddi
->client_data
.auto_hibernate
= mddi_set_auto_hibernate
;
778 mddi
->client_data
.fb_resource
= pdata
->fb_resource
;
780 mddi
->client_data
.interface_type
= MSM_MDDI_PMDH_INTERFACE
;
781 else if (pdev
->id
== 1)
782 mddi
->client_data
.interface_type
= MSM_MDDI_EMDH_INTERFACE
;
784 printk(KERN_ERR
"mddi: can not determine interface %d!\n",
787 goto error_mddi_interface
;
790 mddi
->client_pdev
.dev
.platform_data
= &mddi
->client_data
;
791 printk(KERN_INFO
"mddi: publish: %s\n", mddi
->client_name
);
792 platform_device_register(&mddi
->client_pdev
);
795 error_mddi_interface
:
797 free_irq(mddi
->irq
, 0);
799 dma_free_coherent(NULL
, 0x1000, mddi
->rev_data
, mddi
->rev_addr
);
802 error_get_irq_resource
:
806 printk(KERN_INFO
"mddi: mddi_init() failed (%d)\n", ret
);
811 static struct platform_driver mddi_driver
= {
813 .driver
= { .name
= "msm_mddi" },
816 static int __init
_mddi_init(void)
818 return platform_driver_register(&mddi_driver
);
821 module_init(_mddi_init
);