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/spinlock.h>
25 #include <linux/clk.h>
27 #include <linux/sched.h>
28 #include <mach/msm_iomap.h>
29 #include <mach/irqs.h>
30 #include <mach/board.h>
31 #include <mach/msm_fb.h>
34 #define FLAG_DISABLE_HIBERNATION 0x0001
35 #define FLAG_HAVE_CAPS 0x0002
36 #define FLAG_HAS_VSYNC_IRQ 0x0004
37 #define FLAG_HAVE_STATUS 0x0008
39 #define CMD_GET_CLIENT_CAP 0x0601
40 #define CMD_GET_CLIENT_STATUS 0x0602
43 unsigned char raw
[MDDI_REV_BUFFER_SIZE
];
44 struct mddi_rev_packet hdr
;
45 struct mddi_client_status status
;
46 struct mddi_client_caps caps
;
47 struct mddi_register_access reg
;
50 struct reg_read_info
{
51 struct completion done
;
63 struct msm_mddi_client_data client_data
;
65 /* buffer for rev encap packets */
68 struct mddi_llentry
*reg_write_data
;
69 dma_addr_t reg_write_addr
;
70 struct mddi_llentry
*reg_read_data
;
71 dma_addr_t reg_read_addr
;
77 wait_queue_head_t int_wait
;
79 struct mutex reg_write_lock
;
80 struct mutex reg_read_lock
;
81 struct reg_read_info
*reg_read
;
83 struct mddi_client_caps caps
;
84 struct mddi_client_status status
;
86 void (*power_client
)(struct msm_mddi_client_data
*, int);
88 /* client device published to bind us to the
89 * appropriate mddi_client driver
93 struct platform_device client_pdev
;
96 static void mddi_init_rev_encap(struct mddi_info
*mddi
);
98 #define mddi_readl(r) readl(mddi->base + (MDDI_##r))
99 #define mddi_writel(v, r) writel((v), mddi->base + (MDDI_##r))
101 void mddi_activate_link(struct msm_mddi_client_data
*cdata
)
103 struct mddi_info
*mddi
= container_of(cdata
, struct mddi_info
,
106 mddi_writel(MDDI_CMD_LINK_ACTIVE
, CMD
);
109 static void mddi_handle_link_list_done(struct mddi_info
*mddi
)
113 static void mddi_reset_rev_encap_ptr(struct mddi_info
*mddi
)
115 printk(KERN_INFO
"mddi: resetting rev ptr\n");
116 mddi
->rev_data_curr
= 0;
117 mddi_writel(mddi
->rev_addr
, REV_PTR
);
118 mddi_writel(mddi
->rev_addr
, REV_PTR
);
119 mddi_writel(MDDI_CMD_FORCE_NEW_REV_PTR
, CMD
);
122 static void mddi_handle_rev_data(struct mddi_info
*mddi
, union mddi_rev
*rev
)
125 struct reg_read_info
*ri
;
127 if ((rev
->hdr
.length
<= MDDI_REV_BUFFER_SIZE
- 2) &&
128 (rev
->hdr
.length
>= sizeof(struct mddi_rev_packet
) - 2)) {
130 switch (rev
->hdr
.type
) {
131 case TYPE_CLIENT_CAPS
:
132 memcpy(&mddi
->caps
, &rev
->caps
,
133 sizeof(struct mddi_client_caps
));
134 mddi
->flags
|= FLAG_HAVE_CAPS
;
135 wake_up(&mddi
->int_wait
);
137 case TYPE_CLIENT_STATUS
:
138 memcpy(&mddi
->status
, &rev
->status
,
139 sizeof(struct mddi_client_status
));
140 mddi
->flags
|= FLAG_HAVE_STATUS
;
141 wake_up(&mddi
->int_wait
);
143 case TYPE_REGISTER_ACCESS
:
146 printk(KERN_INFO
"rev: got reg %x = %x without "
148 rev
->reg
.register_address
,
149 rev
->reg
.register_data_list
);
152 if (ri
->reg
!= rev
->reg
.register_address
) {
153 printk(KERN_INFO
"rev: got reg %x = %x for "
154 "wrong register, expected "
156 rev
->reg
.register_address
,
157 rev
->reg
.register_data_list
, ri
->reg
);
160 mddi
->reg_read
= NULL
;
162 ri
->result
= rev
->reg
.register_data_list
;
166 printk(KERN_INFO
"rev: unknown reverse packet: "
167 "len=%04x type=%04x CURR_REV_PTR=%x\n",
168 rev
->hdr
.length
, rev
->hdr
.type
,
169 mddi_readl(CURR_REV_PTR
));
170 for (i
= 0; i
< rev
->hdr
.length
+ 2; i
++) {
172 printk(KERN_INFO
"\n");
173 printk(KERN_INFO
" %02x", rev
->raw
[i
]);
175 printk(KERN_INFO
"\n");
176 mddi_reset_rev_encap_ptr(mddi
);
179 printk(KERN_INFO
"bad rev length, %d, CURR_REV_PTR %x\n",
180 rev
->hdr
.length
, mddi_readl(CURR_REV_PTR
));
181 mddi_reset_rev_encap_ptr(mddi
);
185 static void mddi_wait_interrupt(struct mddi_info
*mddi
, uint32_t intmask
);
187 static void mddi_handle_rev_data_avail(struct mddi_info
*mddi
)
189 union mddi_rev
*rev
= mddi
->rev_data
;
190 uint32_t rev_data_count
;
191 uint32_t rev_crc_err_count
;
193 struct reg_read_info
*ri
;
197 union mddi_rev
*crev
= mddi
->rev_data
+ mddi
->rev_data_curr
;
199 /* clear the interrupt */
200 mddi_writel(MDDI_INT_REV_DATA_AVAIL
, INT
);
201 rev_data_count
= mddi_readl(REV_PKT_CNT
);
202 rev_crc_err_count
= mddi_readl(REV_CRC_ERR
);
203 if (rev_data_count
> 1)
204 printk(KERN_INFO
"rev_data_count %d\n", rev_data_count
);
206 if (rev_crc_err_count
) {
207 printk(KERN_INFO
"rev_crc_err_count %d, INT %x\n",
208 rev_crc_err_count
, mddi_readl(INT
));
211 printk(KERN_INFO
"rev: got crc error without pending "
214 mddi
->reg_read
= NULL
;
221 if (rev_data_count
== 0)
224 prev_offset
= mddi
->rev_data_curr
;
226 length
= *((uint8_t *)mddi
->rev_data
+ mddi
->rev_data_curr
);
227 mddi
->rev_data_curr
++;
228 if (mddi
->rev_data_curr
== MDDI_REV_BUFFER_SIZE
)
229 mddi
->rev_data_curr
= 0;
230 length
+= *((uint8_t *)mddi
->rev_data
+ mddi
->rev_data_curr
) << 8;
231 mddi
->rev_data_curr
+= 1 + length
;
232 if (mddi
->rev_data_curr
>= MDDI_REV_BUFFER_SIZE
)
233 mddi
->rev_data_curr
=
234 mddi
->rev_data_curr
% MDDI_REV_BUFFER_SIZE
;
236 if (length
> MDDI_REV_BUFFER_SIZE
- 2) {
237 printk(KERN_INFO
"mddi: rev data length greater than buffer"
239 mddi_reset_rev_encap_ptr(mddi
);
243 if (prev_offset
+ 2 + length
>= MDDI_REV_BUFFER_SIZE
) {
244 union mddi_rev tmprev
;
245 size_t rem
= MDDI_REV_BUFFER_SIZE
- prev_offset
;
246 memcpy(&tmprev
.raw
[0], mddi
->rev_data
+ prev_offset
, rem
);
247 memcpy(&tmprev
.raw
[rem
], mddi
->rev_data
, 2 + length
- rem
);
248 mddi_handle_rev_data(mddi
, &tmprev
);
250 mddi_handle_rev_data(mddi
, crev
);
253 if (prev_offset
< MDDI_REV_BUFFER_SIZE
/ 2 &&
254 mddi
->rev_data_curr
>= MDDI_REV_BUFFER_SIZE
/ 2) {
255 mddi_writel(mddi
->rev_addr
, REV_PTR
);
259 static irqreturn_t
mddi_isr(int irq
, void *data
)
261 struct msm_mddi_client_data
*cdata
= data
;
262 struct mddi_info
*mddi
= container_of(cdata
, struct mddi_info
,
264 uint32_t active
, status
;
266 spin_lock(&mddi
->int_lock
);
268 active
= mddi_readl(INT
);
269 status
= mddi_readl(STAT
);
271 mddi_writel(active
, INT
);
273 /* ignore any interrupts we have disabled */
274 active
&= mddi
->int_enable
;
276 mddi
->got_int
|= active
;
277 wake_up(&mddi
->int_wait
);
279 if (active
& MDDI_INT_PRI_LINK_LIST_DONE
) {
280 mddi
->int_enable
&= (~MDDI_INT_PRI_LINK_LIST_DONE
);
281 mddi_handle_link_list_done(mddi
);
283 if (active
& MDDI_INT_REV_DATA_AVAIL
)
284 mddi_handle_rev_data_avail(mddi
);
286 if (active
& ~MDDI_INT_NEED_CLEAR
)
287 mddi
->int_enable
&= ~(active
& ~MDDI_INT_NEED_CLEAR
);
289 if (active
& MDDI_INT_LINK_ACTIVE
) {
290 mddi
->int_enable
&= (~MDDI_INT_LINK_ACTIVE
);
291 mddi
->int_enable
|= MDDI_INT_IN_HIBERNATION
;
294 if (active
& MDDI_INT_IN_HIBERNATION
) {
295 mddi
->int_enable
&= (~MDDI_INT_IN_HIBERNATION
);
296 mddi
->int_enable
|= MDDI_INT_LINK_ACTIVE
;
299 mddi_writel(mddi
->int_enable
, INTEN
);
300 spin_unlock(&mddi
->int_lock
);
305 static long mddi_wait_interrupt_timeout(struct mddi_info
*mddi
,
306 uint32_t intmask
, int timeout
)
308 unsigned long irq_flags
;
310 spin_lock_irqsave(&mddi
->int_lock
, irq_flags
);
311 mddi
->got_int
&= ~intmask
;
312 mddi
->int_enable
|= intmask
;
313 mddi_writel(mddi
->int_enable
, INTEN
);
314 spin_unlock_irqrestore(&mddi
->int_lock
, irq_flags
);
315 return wait_event_timeout(mddi
->int_wait
, mddi
->got_int
& intmask
,
319 static void mddi_wait_interrupt(struct mddi_info
*mddi
, uint32_t intmask
)
321 if (mddi_wait_interrupt_timeout(mddi
, intmask
, HZ
/10) == 0)
322 printk(KERN_INFO KERN_ERR
"mddi_wait_interrupt %d, timeout "
323 "waiting for %x, INT = %x, STAT = %x gotint = %x\n",
324 current
->pid
, intmask
, mddi_readl(INT
), mddi_readl(STAT
),
328 static void mddi_init_rev_encap(struct mddi_info
*mddi
)
330 memset(mddi
->rev_data
, 0xee, MDDI_REV_BUFFER_SIZE
);
331 mddi_writel(mddi
->rev_addr
, REV_PTR
);
332 mddi_writel(MDDI_CMD_FORCE_NEW_REV_PTR
, CMD
);
333 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
336 void mddi_set_auto_hibernate(struct msm_mddi_client_data
*cdata
, int on
)
338 struct mddi_info
*mddi
= container_of(cdata
, struct mddi_info
,
340 mddi_writel(MDDI_CMD_POWERDOWN
, CMD
);
341 mddi_wait_interrupt(mddi
, MDDI_INT_IN_HIBERNATION
);
342 mddi_writel(MDDI_CMD_HIBERNATE
| !!on
, CMD
);
343 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
347 static uint16_t mddi_init_registers(struct mddi_info
*mddi
)
349 mddi_writel(0x0001, VERSION
);
350 mddi_writel(MDDI_HOST_BYTES_PER_SUBFRAME
, BPS
);
351 mddi_writel(0x0003, SPM
); /* subframes per media */
352 mddi_writel(0x0005, TA1_LEN
);
353 mddi_writel(MDDI_HOST_TA2_LEN
, TA2_LEN
);
354 mddi_writel(0x0096, DRIVE_HI
);
355 /* 0x32 normal, 0x50 for Toshiba display */
356 mddi_writel(0x0050, DRIVE_LO
);
357 mddi_writel(0x003C, DISP_WAKE
); /* wakeup counter */
358 mddi_writel(MDDI_HOST_REV_RATE_DIV
, REV_RATE_DIV
);
360 mddi_writel(MDDI_REV_BUFFER_SIZE
, REV_SIZE
);
361 mddi_writel(MDDI_MAX_REV_PKT_SIZE
, REV_ENCAP_SZ
);
363 /* disable periodic rev encap */
364 mddi_writel(MDDI_CMD_PERIODIC_REV_ENCAP
, CMD
);
365 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
367 if (mddi_readl(PAD_CTL
) == 0) {
368 /* If we are turning on band gap, need to wait 5us before
369 * turning on the rest of the PAD */
370 mddi_writel(0x08000, PAD_CTL
);
374 /* Recommendation from PAD hw team */
375 mddi_writel(0xa850f, PAD_CTL
);
378 /* Need an even number for counts */
379 mddi_writel(0x60006, DRIVER_START_CNT
);
381 mddi_set_auto_hibernate(&mddi
->client_data
, 0);
383 mddi_writel(MDDI_CMD_DISP_IGNORE
, CMD
);
384 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
386 mddi_init_rev_encap(mddi
);
387 return mddi_readl(CORE_VER
) & 0xffff;
390 static void mddi_suspend(struct msm_mddi_client_data
*cdata
)
392 struct mddi_info
*mddi
= container_of(cdata
, struct mddi_info
,
394 /* turn off the client */
395 if (mddi
->power_client
)
396 mddi
->power_client(&mddi
->client_data
, 0);
397 /* turn off the link */
398 mddi_writel(MDDI_CMD_RESET
, CMD
);
399 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
400 /* turn off the clock */
401 clk_disable(mddi
->clk
);
404 static void mddi_resume(struct msm_mddi_client_data
*cdata
)
406 struct mddi_info
*mddi
= container_of(cdata
, struct mddi_info
,
408 mddi_set_auto_hibernate(&mddi
->client_data
, 0);
409 /* turn on the client */
410 if (mddi
->power_client
)
411 mddi
->power_client(&mddi
->client_data
, 1);
412 /* turn on the clock */
413 clk_enable(mddi
->clk
);
414 /* set up the local registers */
415 mddi
->rev_data_curr
= 0;
416 mddi_init_registers(mddi
);
417 mddi_writel(mddi
->int_enable
, INTEN
);
418 mddi_writel(MDDI_CMD_LINK_ACTIVE
, CMD
);
419 mddi_writel(MDDI_CMD_SEND_RTD
, CMD
);
420 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
421 mddi_set_auto_hibernate(&mddi
->client_data
, 1);
424 static int __init
mddi_get_client_caps(struct mddi_info
*mddi
)
428 /* clear any stale interrupts */
429 mddi_writel(0xffffffff, INT
);
431 mddi
->int_enable
= MDDI_INT_LINK_ACTIVE
|
432 MDDI_INT_IN_HIBERNATION
|
433 MDDI_INT_PRI_LINK_LIST_DONE
|
434 MDDI_INT_REV_DATA_AVAIL
|
435 MDDI_INT_REV_OVERFLOW
|
436 MDDI_INT_REV_OVERWRITE
|
437 MDDI_INT_RTD_FAILURE
;
438 mddi_writel(mddi
->int_enable
, INTEN
);
440 mddi_writel(MDDI_CMD_LINK_ACTIVE
, CMD
);
441 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
443 for (j
= 0; j
< 3; j
++) {
444 /* the toshiba vga panel does not respond to get
445 * caps unless you SEND_RTD, but the first SEND_RTD
448 for (i
= 0; i
< 4; i
++) {
451 mddi_writel(MDDI_CMD_SEND_RTD
, CMD
);
452 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
453 stat
= mddi_readl(STAT
);
454 printk(KERN_INFO
"mddi cmd send rtd: int %x, stat %x, "
455 "rtd val %x\n", mddi_readl(INT
), stat
,
456 mddi_readl(RTD_VAL
));
457 if ((stat
& MDDI_STAT_RTD_MEAS_FAIL
) == 0)
462 mddi_writel(CMD_GET_CLIENT_CAP
, CMD
);
463 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
464 wait_event_timeout(mddi
->int_wait
, mddi
->flags
& FLAG_HAVE_CAPS
,
467 if (mddi
->flags
& FLAG_HAVE_CAPS
)
469 printk(KERN_INFO KERN_ERR
"mddi_init, timeout waiting for "
472 return mddi
->flags
& FLAG_HAVE_CAPS
;
475 /* link must be active when this is called */
476 int mddi_check_status(struct mddi_info
*mddi
)
478 int ret
= -1, retry
= 3;
479 mutex_lock(&mddi
->reg_read_lock
);
480 mddi_writel(MDDI_CMD_PERIODIC_REV_ENCAP
| 1, CMD
);
481 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
484 mddi
->flags
&= ~FLAG_HAVE_STATUS
;
485 mddi_writel(CMD_GET_CLIENT_STATUS
, CMD
);
486 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
487 wait_event_timeout(mddi
->int_wait
,
488 mddi
->flags
& FLAG_HAVE_STATUS
,
491 if (mddi
->flags
& FLAG_HAVE_STATUS
) {
492 if (mddi
->status
.crc_error_count
)
493 printk(KERN_INFO
"mddi status: crc_error "
495 mddi
->status
.crc_error_count
);
500 printk(KERN_INFO
"mddi status: failed to get client "
502 mddi_writel(MDDI_CMD_SEND_RTD
, CMD
);
503 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
506 mddi_writel(MDDI_CMD_PERIODIC_REV_ENCAP
| 0, CMD
);
507 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
508 mutex_unlock(&mddi
->reg_read_lock
);
513 void mddi_remote_write(struct msm_mddi_client_data
*cdata
, uint32_t val
,
516 struct mddi_info
*mddi
= container_of(cdata
, struct mddi_info
,
518 struct mddi_llentry
*ll
;
519 struct mddi_register_access
*ra
;
521 mutex_lock(&mddi
->reg_write_lock
);
523 ll
= mddi
->reg_write_data
;
527 ra
->type
= TYPE_REGISTER_ACCESS
;
529 ra
->read_write_info
= MDDI_WRITE
| 1;
532 ra
->register_address
= reg
;
533 ra
->register_data_list
= val
;
536 ll
->header_count
= 14;
538 ll
->data
= mddi
->reg_write_addr
+ offsetof(struct mddi_llentry
,
539 u
.r
.register_data_list
);
543 mddi_writel(mddi
->reg_write_addr
, PRI_PTR
);
545 mddi_wait_interrupt(mddi
, MDDI_INT_PRI_LINK_LIST_DONE
);
546 mutex_unlock(&mddi
->reg_write_lock
);
549 uint32_t mddi_remote_read(struct msm_mddi_client_data
*cdata
, uint32_t reg
)
551 struct mddi_info
*mddi
= container_of(cdata
, struct mddi_info
,
553 struct mddi_llentry
*ll
;
554 struct mddi_register_access
*ra
;
555 struct reg_read_info ri
;
558 unsigned long irq_flags
;
560 mutex_lock(&mddi
->reg_read_lock
);
562 ll
= mddi
->reg_read_data
;
566 ra
->type
= TYPE_REGISTER_ACCESS
;
568 ra
->read_write_info
= MDDI_READ
| 1;
571 ra
->register_address
= reg
;
574 ll
->header_count
= 14;
580 s
= mddi_readl(STAT
);
586 init_completion(&ri
.done
);
587 mddi
->reg_read
= &ri
;
588 mddi_writel(mddi
->reg_read_addr
, PRI_PTR
);
590 mddi_wait_interrupt(mddi
, MDDI_INT_PRI_LINK_LIST_DONE
);
592 /* Enable Periodic Reverse Encapsulation. */
593 mddi_writel(MDDI_CMD_PERIODIC_REV_ENCAP
| 1, CMD
);
594 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
595 if (wait_for_completion_timeout(&ri
.done
, HZ
/10) == 0 &&
597 printk(KERN_INFO
"mddi_remote_read(%x) timeout "
599 reg
, ri
.status
, ri
.result
, ri
.done
.done
);
600 spin_lock_irqsave(&mddi
->int_lock
, irq_flags
);
601 mddi
->reg_read
= NULL
;
602 spin_unlock_irqrestore(&mddi
->int_lock
, irq_flags
);
609 mddi_writel(MDDI_CMD_SEND_RTD
, CMD
);
610 mddi_writel(MDDI_CMD_LINK_ACTIVE
, CMD
);
611 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
612 printk(KERN_INFO
"mddi_remote_read: failed, sent "
613 "MDDI_CMD_SEND_RTD: int %x, stat %x, rtd val %x "
614 "curr_rev_ptr %x\n", mddi_readl(INT
), mddi_readl(STAT
),
615 mddi_readl(RTD_VAL
), mddi_readl(CURR_REV_PTR
));
616 } while (retry_count
-- > 0);
617 /* Disable Periodic Reverse Encapsulation. */
618 mddi_writel(MDDI_CMD_PERIODIC_REV_ENCAP
| 0, CMD
);
619 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
620 mddi
->reg_read
= NULL
;
621 mutex_unlock(&mddi
->reg_read_lock
);
625 static struct mddi_info mddi_info
[2];
627 static int __init
mddi_clk_setup(struct platform_device
*pdev
,
628 struct mddi_info
*mddi
,
629 unsigned long clk_rate
)
633 /* set up the clocks */
634 mddi
->clk
= clk_get(&pdev
->dev
, "mddi_clk");
635 if (IS_ERR(mddi
->clk
)) {
636 printk(KERN_INFO
"mddi: failed to get clock\n");
637 return PTR_ERR(mddi
->clk
);
639 ret
= clk_enable(mddi
->clk
);
642 ret
= clk_set_rate(mddi
->clk
, clk_rate
);
652 static int __init
mddi_rev_data_setup(struct mddi_info
*mddi
)
657 /* set up dma buffer */
658 dma
= dma_alloc_coherent(NULL
, 0x1000, &dma_addr
, GFP_KERNEL
);
661 mddi
->rev_data
= dma
;
662 mddi
->rev_data_curr
= 0;
663 mddi
->rev_addr
= dma_addr
;
664 mddi
->reg_write_data
= dma
+ MDDI_REV_BUFFER_SIZE
;
665 mddi
->reg_write_addr
= dma_addr
+ MDDI_REV_BUFFER_SIZE
;
666 mddi
->reg_read_data
= mddi
->reg_write_data
+ 1;
667 mddi
->reg_read_addr
= mddi
->reg_write_addr
+
668 sizeof(*mddi
->reg_write_data
);
672 static int __init
mddi_probe(struct platform_device
*pdev
)
674 struct msm_mddi_platform_data
*pdata
= pdev
->dev
.platform_data
;
675 struct mddi_info
*mddi
= &mddi_info
[pdev
->id
];
676 struct resource
*resource
;
679 resource
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
681 printk(KERN_ERR
"mddi: no associated mem resource!\n");
684 mddi
->base
= ioremap(resource
->start
, resource
->end
- resource
->start
);
686 printk(KERN_ERR
"mddi: failed to remap base!\n");
690 resource
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
692 printk(KERN_ERR
"mddi: no associated irq resource!\n");
694 goto error_get_irq_resource
;
696 mddi
->irq
= resource
->start
;
697 printk(KERN_INFO
"mddi: init() base=0x%p irq=%d\n", mddi
->base
,
699 mddi
->power_client
= pdata
->power_client
;
701 mutex_init(&mddi
->reg_write_lock
);
702 mutex_init(&mddi
->reg_read_lock
);
703 spin_lock_init(&mddi
->int_lock
);
704 init_waitqueue_head(&mddi
->int_wait
);
706 ret
= mddi_clk_setup(pdev
, mddi
, pdata
->clk_rate
);
708 printk(KERN_ERR
"mddi: failed to setup clock!\n");
709 goto error_clk_setup
;
712 ret
= mddi_rev_data_setup(mddi
);
714 printk(KERN_ERR
"mddi: failed to setup rev data!\n");
718 mddi
->int_enable
= 0;
719 mddi_writel(mddi
->int_enable
, INTEN
);
720 ret
= request_irq(mddi
->irq
, mddi_isr
, IRQF_DISABLED
, "mddi",
723 printk(KERN_ERR
"mddi: failed to request enable irq!\n");
724 goto error_request_irq
;
727 /* turn on the mddi client bridge chip */
728 if (mddi
->power_client
)
729 mddi
->power_client(&mddi
->client_data
, 1);
731 /* initialize the mddi registers */
732 mddi_set_auto_hibernate(&mddi
->client_data
, 0);
733 mddi_writel(MDDI_CMD_RESET
, CMD
);
734 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
735 mddi
->version
= mddi_init_registers(mddi
);
736 if (mddi
->version
< 0x20) {
737 printk(KERN_ERR
"mddi: unsupported version 0x%x\n",
740 goto error_mddi_version
;
743 /* read the capabilities off the client */
744 if (!mddi_get_client_caps(mddi
)) {
745 printk(KERN_INFO
"mddi: no client found\n");
746 /* power down the panel */
747 mddi_writel(MDDI_CMD_POWERDOWN
, CMD
);
748 printk(KERN_INFO
"mddi powerdown: stat %x\n", mddi_readl(STAT
));
750 printk(KERN_INFO
"mddi powerdown: stat %x\n", mddi_readl(STAT
));
753 mddi_set_auto_hibernate(&mddi
->client_data
, 1);
755 if (mddi
->caps
.Mfr_Name
== 0 && mddi
->caps
.Product_Code
== 0)
756 pdata
->fixup(&mddi
->caps
.Mfr_Name
, &mddi
->caps
.Product_Code
);
758 mddi
->client_pdev
.id
= 0;
759 for (i
= 0; i
< pdata
->num_clients
; i
++) {
760 if (pdata
->client_platform_data
[i
].product_id
==
761 (mddi
->caps
.Mfr_Name
<< 16 | mddi
->caps
.Product_Code
)) {
762 mddi
->client_data
.private_client_data
=
763 pdata
->client_platform_data
[i
].client_data
;
764 mddi
->client_pdev
.name
=
765 pdata
->client_platform_data
[i
].name
;
766 mddi
->client_pdev
.id
=
767 pdata
->client_platform_data
[i
].id
;
768 /* XXX: possibly set clock */
773 if (i
>= pdata
->num_clients
)
774 mddi
->client_pdev
.name
= "mddi_c_dummy";
775 printk(KERN_INFO
"mddi: registering panel %s\n",
776 mddi
->client_pdev
.name
);
778 mddi
->client_data
.suspend
= mddi_suspend
;
779 mddi
->client_data
.resume
= mddi_resume
;
780 mddi
->client_data
.activate_link
= mddi_activate_link
;
781 mddi
->client_data
.remote_write
= mddi_remote_write
;
782 mddi
->client_data
.remote_read
= mddi_remote_read
;
783 mddi
->client_data
.auto_hibernate
= mddi_set_auto_hibernate
;
784 mddi
->client_data
.fb_resource
= pdata
->fb_resource
;
786 mddi
->client_data
.interface_type
= MSM_MDDI_PMDH_INTERFACE
;
787 else if (pdev
->id
== 1)
788 mddi
->client_data
.interface_type
= MSM_MDDI_EMDH_INTERFACE
;
790 printk(KERN_ERR
"mddi: can not determine interface %d!\n",
793 goto error_mddi_interface
;
796 mddi
->client_pdev
.dev
.platform_data
= &mddi
->client_data
;
797 printk(KERN_INFO
"mddi: publish: %s\n", mddi
->client_name
);
798 platform_device_register(&mddi
->client_pdev
);
801 error_mddi_interface
:
803 free_irq(mddi
->irq
, 0);
805 dma_free_coherent(NULL
, 0x1000, mddi
->rev_data
, mddi
->rev_addr
);
808 error_get_irq_resource
:
812 printk(KERN_INFO
"mddi: mddi_init() failed (%d)\n", ret
);
817 static struct platform_driver mddi_driver
= {
819 .driver
= { .name
= "msm_mddi" },
822 static int __init
_mddi_init(void)
824 return platform_driver_register(&mddi_driver
);
827 module_init(_mddi_init
);