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 <mach/msm_iomap.h>
28 #include <mach/irqs.h>
29 #include <mach/board.h>
30 #include <mach/msm_fb.h>
33 #define FLAG_DISABLE_HIBERNATION 0x0001
34 #define FLAG_HAVE_CAPS 0x0002
35 #define FLAG_HAS_VSYNC_IRQ 0x0004
36 #define FLAG_HAVE_STATUS 0x0008
38 #define CMD_GET_CLIENT_CAP 0x0601
39 #define CMD_GET_CLIENT_STATUS 0x0602
42 unsigned char raw
[MDDI_REV_BUFFER_SIZE
];
43 struct mddi_rev_packet hdr
;
44 struct mddi_client_status status
;
45 struct mddi_client_caps caps
;
46 struct mddi_register_access reg
;
49 struct reg_read_info
{
50 struct completion done
;
62 struct msm_mddi_client_data client_data
;
64 /* buffer for rev encap packets */
67 struct mddi_llentry
*reg_write_data
;
68 dma_addr_t reg_write_addr
;
69 struct mddi_llentry
*reg_read_data
;
70 dma_addr_t reg_read_addr
;
76 wait_queue_head_t int_wait
;
78 struct mutex reg_write_lock
;
79 struct mutex reg_read_lock
;
80 struct reg_read_info
*reg_read
;
82 struct mddi_client_caps caps
;
83 struct mddi_client_status status
;
85 void (*power_client
)(struct msm_mddi_client_data
*, int);
87 /* client device published to bind us to the
88 * appropriate mddi_client driver
92 struct platform_device client_pdev
;
95 static void mddi_init_rev_encap(struct mddi_info
*mddi
);
97 #define mddi_readl(r) readl(mddi->base + (MDDI_##r))
98 #define mddi_writel(v, r) writel((v), mddi->base + (MDDI_##r))
100 void mddi_activate_link(struct msm_mddi_client_data
*cdata
)
102 struct mddi_info
*mddi
= container_of(cdata
, struct mddi_info
,
105 mddi_writel(MDDI_CMD_LINK_ACTIVE
, CMD
);
108 static void mddi_handle_link_list_done(struct mddi_info
*mddi
)
112 static void mddi_reset_rev_encap_ptr(struct mddi_info
*mddi
)
114 printk(KERN_INFO
"mddi: resetting rev ptr\n");
115 mddi
->rev_data_curr
= 0;
116 mddi_writel(mddi
->rev_addr
, REV_PTR
);
117 mddi_writel(mddi
->rev_addr
, REV_PTR
);
118 mddi_writel(MDDI_CMD_FORCE_NEW_REV_PTR
, CMD
);
121 static void mddi_handle_rev_data(struct mddi_info
*mddi
, union mddi_rev
*rev
)
124 struct reg_read_info
*ri
;
126 if ((rev
->hdr
.length
<= MDDI_REV_BUFFER_SIZE
- 2) &&
127 (rev
->hdr
.length
>= sizeof(struct mddi_rev_packet
) - 2)) {
129 switch (rev
->hdr
.type
) {
130 case TYPE_CLIENT_CAPS
:
131 memcpy(&mddi
->caps
, &rev
->caps
,
132 sizeof(struct mddi_client_caps
));
133 mddi
->flags
|= FLAG_HAVE_CAPS
;
134 wake_up(&mddi
->int_wait
);
136 case TYPE_CLIENT_STATUS
:
137 memcpy(&mddi
->status
, &rev
->status
,
138 sizeof(struct mddi_client_status
));
139 mddi
->flags
|= FLAG_HAVE_STATUS
;
140 wake_up(&mddi
->int_wait
);
142 case TYPE_REGISTER_ACCESS
:
145 printk(KERN_INFO
"rev: got reg %x = %x without "
147 rev
->reg
.register_address
,
148 rev
->reg
.register_data_list
);
151 if (ri
->reg
!= rev
->reg
.register_address
) {
152 printk(KERN_INFO
"rev: got reg %x = %x for "
153 "wrong register, expected "
155 rev
->reg
.register_address
,
156 rev
->reg
.register_data_list
, ri
->reg
);
159 mddi
->reg_read
= NULL
;
161 ri
->result
= rev
->reg
.register_data_list
;
165 printk(KERN_INFO
"rev: unknown reverse packet: "
166 "len=%04x type=%04x CURR_REV_PTR=%x\n",
167 rev
->hdr
.length
, rev
->hdr
.type
,
168 mddi_readl(CURR_REV_PTR
));
169 for (i
= 0; i
< rev
->hdr
.length
+ 2; i
++) {
171 printk(KERN_INFO
"\n");
172 printk(KERN_INFO
" %02x", rev
->raw
[i
]);
174 printk(KERN_INFO
"\n");
175 mddi_reset_rev_encap_ptr(mddi
);
178 printk(KERN_INFO
"bad rev length, %d, CURR_REV_PTR %x\n",
179 rev
->hdr
.length
, mddi_readl(CURR_REV_PTR
));
180 mddi_reset_rev_encap_ptr(mddi
);
184 static void mddi_wait_interrupt(struct mddi_info
*mddi
, uint32_t intmask
);
186 static void mddi_handle_rev_data_avail(struct mddi_info
*mddi
)
188 union mddi_rev
*rev
= mddi
->rev_data
;
189 uint32_t rev_data_count
;
190 uint32_t rev_crc_err_count
;
192 struct reg_read_info
*ri
;
196 union mddi_rev
*crev
= mddi
->rev_data
+ mddi
->rev_data_curr
;
198 /* clear the interrupt */
199 mddi_writel(MDDI_INT_REV_DATA_AVAIL
, INT
);
200 rev_data_count
= mddi_readl(REV_PKT_CNT
);
201 rev_crc_err_count
= mddi_readl(REV_CRC_ERR
);
202 if (rev_data_count
> 1)
203 printk(KERN_INFO
"rev_data_count %d\n", rev_data_count
);
205 if (rev_crc_err_count
) {
206 printk(KERN_INFO
"rev_crc_err_count %d, INT %x\n",
207 rev_crc_err_count
, mddi_readl(INT
));
210 printk(KERN_INFO
"rev: got crc error without pending "
213 mddi
->reg_read
= NULL
;
220 if (rev_data_count
== 0)
223 prev_offset
= mddi
->rev_data_curr
;
225 length
= *((uint8_t *)mddi
->rev_data
+ mddi
->rev_data_curr
);
226 mddi
->rev_data_curr
++;
227 if (mddi
->rev_data_curr
== MDDI_REV_BUFFER_SIZE
)
228 mddi
->rev_data_curr
= 0;
229 length
+= *((uint8_t *)mddi
->rev_data
+ mddi
->rev_data_curr
) << 8;
230 mddi
->rev_data_curr
+= 1 + length
;
231 if (mddi
->rev_data_curr
>= MDDI_REV_BUFFER_SIZE
)
232 mddi
->rev_data_curr
=
233 mddi
->rev_data_curr
% MDDI_REV_BUFFER_SIZE
;
235 if (length
> MDDI_REV_BUFFER_SIZE
- 2) {
236 printk(KERN_INFO
"mddi: rev data length greater than buffer"
238 mddi_reset_rev_encap_ptr(mddi
);
242 if (prev_offset
+ 2 + length
>= MDDI_REV_BUFFER_SIZE
) {
243 union mddi_rev tmprev
;
244 size_t rem
= MDDI_REV_BUFFER_SIZE
- prev_offset
;
245 memcpy(&tmprev
.raw
[0], mddi
->rev_data
+ prev_offset
, rem
);
246 memcpy(&tmprev
.raw
[rem
], mddi
->rev_data
, 2 + length
- rem
);
247 mddi_handle_rev_data(mddi
, &tmprev
);
249 mddi_handle_rev_data(mddi
, crev
);
252 if (prev_offset
< MDDI_REV_BUFFER_SIZE
/ 2 &&
253 mddi
->rev_data_curr
>= MDDI_REV_BUFFER_SIZE
/ 2) {
254 mddi_writel(mddi
->rev_addr
, REV_PTR
);
258 static irqreturn_t
mddi_isr(int irq
, void *data
)
260 struct msm_mddi_client_data
*cdata
= data
;
261 struct mddi_info
*mddi
= container_of(cdata
, struct mddi_info
,
263 uint32_t active
, status
;
265 spin_lock(&mddi
->int_lock
);
267 active
= mddi_readl(INT
);
268 status
= mddi_readl(STAT
);
270 mddi_writel(active
, INT
);
272 /* ignore any interrupts we have disabled */
273 active
&= mddi
->int_enable
;
275 mddi
->got_int
|= active
;
276 wake_up(&mddi
->int_wait
);
278 if (active
& MDDI_INT_PRI_LINK_LIST_DONE
) {
279 mddi
->int_enable
&= (~MDDI_INT_PRI_LINK_LIST_DONE
);
280 mddi_handle_link_list_done(mddi
);
282 if (active
& MDDI_INT_REV_DATA_AVAIL
)
283 mddi_handle_rev_data_avail(mddi
);
285 if (active
& ~MDDI_INT_NEED_CLEAR
)
286 mddi
->int_enable
&= ~(active
& ~MDDI_INT_NEED_CLEAR
);
288 if (active
& MDDI_INT_LINK_ACTIVE
) {
289 mddi
->int_enable
&= (~MDDI_INT_LINK_ACTIVE
);
290 mddi
->int_enable
|= MDDI_INT_IN_HIBERNATION
;
293 if (active
& MDDI_INT_IN_HIBERNATION
) {
294 mddi
->int_enable
&= (~MDDI_INT_IN_HIBERNATION
);
295 mddi
->int_enable
|= MDDI_INT_LINK_ACTIVE
;
298 mddi_writel(mddi
->int_enable
, INTEN
);
299 spin_unlock(&mddi
->int_lock
);
304 static long mddi_wait_interrupt_timeout(struct mddi_info
*mddi
,
305 uint32_t intmask
, int timeout
)
307 unsigned long irq_flags
;
309 spin_lock_irqsave(&mddi
->int_lock
, irq_flags
);
310 mddi
->got_int
&= ~intmask
;
311 mddi
->int_enable
|= intmask
;
312 mddi_writel(mddi
->int_enable
, INTEN
);
313 spin_unlock_irqrestore(&mddi
->int_lock
, irq_flags
);
314 return wait_event_timeout(mddi
->int_wait
, mddi
->got_int
& intmask
,
318 static void mddi_wait_interrupt(struct mddi_info
*mddi
, uint32_t intmask
)
320 if (mddi_wait_interrupt_timeout(mddi
, intmask
, HZ
/10) == 0)
321 printk(KERN_INFO KERN_ERR
"mddi_wait_interrupt %d, timeout "
322 "waiting for %x, INT = %x, STAT = %x gotint = %x\n",
323 current
->pid
, intmask
, mddi_readl(INT
), mddi_readl(STAT
),
327 static void mddi_init_rev_encap(struct mddi_info
*mddi
)
329 memset(mddi
->rev_data
, 0xee, MDDI_REV_BUFFER_SIZE
);
330 mddi_writel(mddi
->rev_addr
, REV_PTR
);
331 mddi_writel(MDDI_CMD_FORCE_NEW_REV_PTR
, CMD
);
332 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
335 void mddi_set_auto_hibernate(struct msm_mddi_client_data
*cdata
, int on
)
337 struct mddi_info
*mddi
= container_of(cdata
, struct mddi_info
,
339 mddi_writel(MDDI_CMD_POWERDOWN
, CMD
);
340 mddi_wait_interrupt(mddi
, MDDI_INT_IN_HIBERNATION
);
341 mddi_writel(MDDI_CMD_HIBERNATE
| !!on
, CMD
);
342 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
346 static uint16_t mddi_init_registers(struct mddi_info
*mddi
)
348 mddi_writel(0x0001, VERSION
);
349 mddi_writel(MDDI_HOST_BYTES_PER_SUBFRAME
, BPS
);
350 mddi_writel(0x0003, SPM
); /* subframes per media */
351 mddi_writel(0x0005, TA1_LEN
);
352 mddi_writel(MDDI_HOST_TA2_LEN
, TA2_LEN
);
353 mddi_writel(0x0096, DRIVE_HI
);
354 /* 0x32 normal, 0x50 for Toshiba display */
355 mddi_writel(0x0050, DRIVE_LO
);
356 mddi_writel(0x003C, DISP_WAKE
); /* wakeup counter */
357 mddi_writel(MDDI_HOST_REV_RATE_DIV
, REV_RATE_DIV
);
359 mddi_writel(MDDI_REV_BUFFER_SIZE
, REV_SIZE
);
360 mddi_writel(MDDI_MAX_REV_PKT_SIZE
, REV_ENCAP_SZ
);
362 /* disable periodic rev encap */
363 mddi_writel(MDDI_CMD_PERIODIC_REV_ENCAP
, CMD
);
364 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
366 if (mddi_readl(PAD_CTL
) == 0) {
367 /* If we are turning on band gap, need to wait 5us before
368 * turning on the rest of the PAD */
369 mddi_writel(0x08000, PAD_CTL
);
373 /* Recommendation from PAD hw team */
374 mddi_writel(0xa850f, PAD_CTL
);
377 /* Need an even number for counts */
378 mddi_writel(0x60006, DRIVER_START_CNT
);
380 mddi_set_auto_hibernate(&mddi
->client_data
, 0);
382 mddi_writel(MDDI_CMD_DISP_IGNORE
, CMD
);
383 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
385 mddi_init_rev_encap(mddi
);
386 return mddi_readl(CORE_VER
) & 0xffff;
389 static void mddi_suspend(struct msm_mddi_client_data
*cdata
)
391 struct mddi_info
*mddi
= container_of(cdata
, struct mddi_info
,
393 /* turn off the client */
394 if (mddi
->power_client
)
395 mddi
->power_client(&mddi
->client_data
, 0);
396 /* turn off the link */
397 mddi_writel(MDDI_CMD_RESET
, CMD
);
398 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
399 /* turn off the clock */
400 clk_disable(mddi
->clk
);
403 static void mddi_resume(struct msm_mddi_client_data
*cdata
)
405 struct mddi_info
*mddi
= container_of(cdata
, struct mddi_info
,
407 mddi_set_auto_hibernate(&mddi
->client_data
, 0);
408 /* turn on the client */
409 if (mddi
->power_client
)
410 mddi
->power_client(&mddi
->client_data
, 1);
411 /* turn on the clock */
412 clk_enable(mddi
->clk
);
413 /* set up the local registers */
414 mddi
->rev_data_curr
= 0;
415 mddi_init_registers(mddi
);
416 mddi_writel(mddi
->int_enable
, INTEN
);
417 mddi_writel(MDDI_CMD_LINK_ACTIVE
, CMD
);
418 mddi_writel(MDDI_CMD_SEND_RTD
, CMD
);
419 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
420 mddi_set_auto_hibernate(&mddi
->client_data
, 1);
423 static int __init
mddi_get_client_caps(struct mddi_info
*mddi
)
427 /* clear any stale interrupts */
428 mddi_writel(0xffffffff, INT
);
430 mddi
->int_enable
= MDDI_INT_LINK_ACTIVE
|
431 MDDI_INT_IN_HIBERNATION
|
432 MDDI_INT_PRI_LINK_LIST_DONE
|
433 MDDI_INT_REV_DATA_AVAIL
|
434 MDDI_INT_REV_OVERFLOW
|
435 MDDI_INT_REV_OVERWRITE
|
436 MDDI_INT_RTD_FAILURE
;
437 mddi_writel(mddi
->int_enable
, INTEN
);
439 mddi_writel(MDDI_CMD_LINK_ACTIVE
, CMD
);
440 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
442 for (j
= 0; j
< 3; j
++) {
443 /* the toshiba vga panel does not respond to get
444 * caps unless you SEND_RTD, but the first SEND_RTD
447 for (i
= 0; i
< 4; i
++) {
450 mddi_writel(MDDI_CMD_SEND_RTD
, CMD
);
451 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
452 stat
= mddi_readl(STAT
);
453 printk(KERN_INFO
"mddi cmd send rtd: int %x, stat %x, "
454 "rtd val %x\n", mddi_readl(INT
), stat
,
455 mddi_readl(RTD_VAL
));
456 if ((stat
& MDDI_STAT_RTD_MEAS_FAIL
) == 0)
461 mddi_writel(CMD_GET_CLIENT_CAP
, CMD
);
462 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
463 wait_event_timeout(mddi
->int_wait
, mddi
->flags
& FLAG_HAVE_CAPS
,
466 if (mddi
->flags
& FLAG_HAVE_CAPS
)
468 printk(KERN_INFO KERN_ERR
"mddi_init, timeout waiting for "
471 return mddi
->flags
& FLAG_HAVE_CAPS
;
474 /* link must be active when this is called */
475 int mddi_check_status(struct mddi_info
*mddi
)
477 int ret
= -1, retry
= 3;
478 mutex_lock(&mddi
->reg_read_lock
);
479 mddi_writel(MDDI_CMD_PERIODIC_REV_ENCAP
| 1, CMD
);
480 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
483 mddi
->flags
&= ~FLAG_HAVE_STATUS
;
484 mddi_writel(CMD_GET_CLIENT_STATUS
, CMD
);
485 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
486 wait_event_timeout(mddi
->int_wait
,
487 mddi
->flags
& FLAG_HAVE_STATUS
,
490 if (mddi
->flags
& FLAG_HAVE_STATUS
) {
491 if (mddi
->status
.crc_error_count
)
492 printk(KERN_INFO
"mddi status: crc_error "
494 mddi
->status
.crc_error_count
);
499 printk(KERN_INFO
"mddi status: failed to get client "
501 mddi_writel(MDDI_CMD_SEND_RTD
, CMD
);
502 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
505 mddi_writel(MDDI_CMD_PERIODIC_REV_ENCAP
| 0, CMD
);
506 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
507 mutex_unlock(&mddi
->reg_read_lock
);
512 void mddi_remote_write(struct msm_mddi_client_data
*cdata
, uint32_t val
,
515 struct mddi_info
*mddi
= container_of(cdata
, struct mddi_info
,
517 struct mddi_llentry
*ll
;
518 struct mddi_register_access
*ra
;
520 mutex_lock(&mddi
->reg_write_lock
);
522 ll
= mddi
->reg_write_data
;
526 ra
->type
= TYPE_REGISTER_ACCESS
;
528 ra
->read_write_info
= MDDI_WRITE
| 1;
531 ra
->register_address
= reg
;
532 ra
->register_data_list
= val
;
535 ll
->header_count
= 14;
537 ll
->data
= mddi
->reg_write_addr
+ offsetof(struct mddi_llentry
,
538 u
.r
.register_data_list
);
542 mddi_writel(mddi
->reg_write_addr
, PRI_PTR
);
544 mddi_wait_interrupt(mddi
, MDDI_INT_PRI_LINK_LIST_DONE
);
545 mutex_unlock(&mddi
->reg_write_lock
);
548 uint32_t mddi_remote_read(struct msm_mddi_client_data
*cdata
, uint32_t reg
)
550 struct mddi_info
*mddi
= container_of(cdata
, struct mddi_info
,
552 struct mddi_llentry
*ll
;
553 struct mddi_register_access
*ra
;
554 struct reg_read_info ri
;
557 unsigned long irq_flags
;
559 mutex_lock(&mddi
->reg_read_lock
);
561 ll
= mddi
->reg_read_data
;
565 ra
->type
= TYPE_REGISTER_ACCESS
;
567 ra
->read_write_info
= MDDI_READ
| 1;
570 ra
->register_address
= reg
;
573 ll
->header_count
= 14;
579 s
= mddi_readl(STAT
);
585 init_completion(&ri
.done
);
586 mddi
->reg_read
= &ri
;
587 mddi_writel(mddi
->reg_read_addr
, PRI_PTR
);
589 mddi_wait_interrupt(mddi
, MDDI_INT_PRI_LINK_LIST_DONE
);
591 /* Enable Periodic Reverse Encapsulation. */
592 mddi_writel(MDDI_CMD_PERIODIC_REV_ENCAP
| 1, CMD
);
593 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
594 if (wait_for_completion_timeout(&ri
.done
, HZ
/10) == 0 &&
596 printk(KERN_INFO
"mddi_remote_read(%x) timeout "
598 reg
, ri
.status
, ri
.result
, ri
.done
.done
);
599 spin_lock_irqsave(&mddi
->int_lock
, irq_flags
);
600 mddi
->reg_read
= NULL
;
601 spin_unlock_irqrestore(&mddi
->int_lock
, irq_flags
);
608 mddi_writel(MDDI_CMD_SEND_RTD
, CMD
);
609 mddi_writel(MDDI_CMD_LINK_ACTIVE
, CMD
);
610 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
611 printk(KERN_INFO
"mddi_remote_read: failed, sent "
612 "MDDI_CMD_SEND_RTD: int %x, stat %x, rtd val %x "
613 "curr_rev_ptr %x\n", mddi_readl(INT
), mddi_readl(STAT
),
614 mddi_readl(RTD_VAL
), mddi_readl(CURR_REV_PTR
));
615 } while (retry_count
-- > 0);
616 /* Disable Periodic Reverse Encapsulation. */
617 mddi_writel(MDDI_CMD_PERIODIC_REV_ENCAP
| 0, CMD
);
618 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
619 mddi
->reg_read
= NULL
;
620 mutex_unlock(&mddi
->reg_read_lock
);
624 static struct mddi_info mddi_info
[2];
626 static int __init
mddi_clk_setup(struct platform_device
*pdev
,
627 struct mddi_info
*mddi
,
628 unsigned long clk_rate
)
632 /* set up the clocks */
633 mddi
->clk
= clk_get(&pdev
->dev
, "mddi_clk");
634 if (IS_ERR(mddi
->clk
)) {
635 printk(KERN_INFO
"mddi: failed to get clock\n");
636 return PTR_ERR(mddi
->clk
);
638 ret
= clk_enable(mddi
->clk
);
641 ret
= clk_set_rate(mddi
->clk
, clk_rate
);
651 static int __init
mddi_rev_data_setup(struct mddi_info
*mddi
)
656 /* set up dma buffer */
657 dma
= dma_alloc_coherent(NULL
, 0x1000, &dma_addr
, GFP_KERNEL
);
660 mddi
->rev_data
= dma
;
661 mddi
->rev_data_curr
= 0;
662 mddi
->rev_addr
= dma_addr
;
663 mddi
->reg_write_data
= dma
+ MDDI_REV_BUFFER_SIZE
;
664 mddi
->reg_write_addr
= dma_addr
+ MDDI_REV_BUFFER_SIZE
;
665 mddi
->reg_read_data
= mddi
->reg_write_data
+ 1;
666 mddi
->reg_read_addr
= mddi
->reg_write_addr
+
667 sizeof(*mddi
->reg_write_data
);
671 static int __init
mddi_probe(struct platform_device
*pdev
)
673 struct msm_mddi_platform_data
*pdata
= pdev
->dev
.platform_data
;
674 struct mddi_info
*mddi
= &mddi_info
[pdev
->id
];
675 struct resource
*resource
;
678 resource
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
680 printk(KERN_ERR
"mddi: no associated mem resource!\n");
683 mddi
->base
= ioremap(resource
->start
, resource
->end
- resource
->start
);
685 printk(KERN_ERR
"mddi: failed to remap base!\n");
689 resource
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
691 printk(KERN_ERR
"mddi: no associated irq resource!\n");
693 goto error_get_irq_resource
;
695 mddi
->irq
= resource
->start
;
696 printk(KERN_INFO
"mddi: init() base=0x%p irq=%d\n", mddi
->base
,
698 mddi
->power_client
= pdata
->power_client
;
700 mutex_init(&mddi
->reg_write_lock
);
701 mutex_init(&mddi
->reg_read_lock
);
702 spin_lock_init(&mddi
->int_lock
);
703 init_waitqueue_head(&mddi
->int_wait
);
705 ret
= mddi_clk_setup(pdev
, mddi
, pdata
->clk_rate
);
707 printk(KERN_ERR
"mddi: failed to setup clock!\n");
708 goto error_clk_setup
;
711 ret
= mddi_rev_data_setup(mddi
);
713 printk(KERN_ERR
"mddi: failed to setup rev data!\n");
717 mddi
->int_enable
= 0;
718 mddi_writel(mddi
->int_enable
, INTEN
);
719 ret
= request_irq(mddi
->irq
, mddi_isr
, IRQF_DISABLED
, "mddi",
722 printk(KERN_ERR
"mddi: failed to request enable irq!\n");
723 goto error_request_irq
;
726 /* turn on the mddi client bridge chip */
727 if (mddi
->power_client
)
728 mddi
->power_client(&mddi
->client_data
, 1);
730 /* initialize the mddi registers */
731 mddi_set_auto_hibernate(&mddi
->client_data
, 0);
732 mddi_writel(MDDI_CMD_RESET
, CMD
);
733 mddi_wait_interrupt(mddi
, MDDI_INT_NO_CMD_PKTS_PEND
);
734 mddi
->version
= mddi_init_registers(mddi
);
735 if (mddi
->version
< 0x20) {
736 printk(KERN_ERR
"mddi: unsupported version 0x%x\n",
739 goto error_mddi_version
;
742 /* read the capabilities off the client */
743 if (!mddi_get_client_caps(mddi
)) {
744 printk(KERN_INFO
"mddi: no client found\n");
745 /* power down the panel */
746 mddi_writel(MDDI_CMD_POWERDOWN
, CMD
);
747 printk(KERN_INFO
"mddi powerdown: stat %x\n", mddi_readl(STAT
));
749 printk(KERN_INFO
"mddi powerdown: stat %x\n", mddi_readl(STAT
));
752 mddi_set_auto_hibernate(&mddi
->client_data
, 1);
754 if (mddi
->caps
.Mfr_Name
== 0 && mddi
->caps
.Product_Code
== 0)
755 pdata
->fixup(&mddi
->caps
.Mfr_Name
, &mddi
->caps
.Product_Code
);
757 mddi
->client_pdev
.id
= 0;
758 for (i
= 0; i
< pdata
->num_clients
; i
++) {
759 if (pdata
->client_platform_data
[i
].product_id
==
760 (mddi
->caps
.Mfr_Name
<< 16 | mddi
->caps
.Product_Code
)) {
761 mddi
->client_data
.private_client_data
=
762 pdata
->client_platform_data
[i
].client_data
;
763 mddi
->client_pdev
.name
=
764 pdata
->client_platform_data
[i
].name
;
765 mddi
->client_pdev
.id
=
766 pdata
->client_platform_data
[i
].id
;
767 /* XXX: possibly set clock */
772 if (i
>= pdata
->num_clients
)
773 mddi
->client_pdev
.name
= "mddi_c_dummy";
774 printk(KERN_INFO
"mddi: registering panel %s\n",
775 mddi
->client_pdev
.name
);
777 mddi
->client_data
.suspend
= mddi_suspend
;
778 mddi
->client_data
.resume
= mddi_resume
;
779 mddi
->client_data
.activate_link
= mddi_activate_link
;
780 mddi
->client_data
.remote_write
= mddi_remote_write
;
781 mddi
->client_data
.remote_read
= mddi_remote_read
;
782 mddi
->client_data
.auto_hibernate
= mddi_set_auto_hibernate
;
783 mddi
->client_data
.fb_resource
= pdata
->fb_resource
;
785 mddi
->client_data
.interface_type
= MSM_MDDI_PMDH_INTERFACE
;
786 else if (pdev
->id
== 1)
787 mddi
->client_data
.interface_type
= MSM_MDDI_EMDH_INTERFACE
;
789 printk(KERN_ERR
"mddi: can not determine interface %d!\n",
792 goto error_mddi_interface
;
795 mddi
->client_pdev
.dev
.platform_data
= &mddi
->client_data
;
796 printk(KERN_INFO
"mddi: publish: %s\n", mddi
->client_name
);
797 platform_device_register(&mddi
->client_pdev
);
800 error_mddi_interface
:
802 free_irq(mddi
->irq
, 0);
804 dma_free_coherent(NULL
, 0x1000, mddi
->rev_data
, mddi
->rev_addr
);
807 error_get_irq_resource
:
811 printk(KERN_INFO
"mddi: mddi_init() failed (%d)\n", ret
);
816 static struct platform_driver mddi_driver
= {
818 .driver
= { .name
= "msm_mddi" },
821 static int __init
_mddi_init(void)
823 return platform_driver_register(&mddi_driver
);
826 module_init(_mddi_init
);