18 #include <linux/module.h>
19 #include <linux/kernel.h>
28 #include <linux/sched.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
42 struct mddi_rev_packet
hdr;
44 struct mddi_client_caps
caps;
45 struct mddi_register_access
reg;
81 struct mddi_client_caps
caps;
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))
107 static void mddi_handle_link_list_done(
struct mddi_info *mddi)
111 static void mddi_reset_rev_encap_ptr(
struct mddi_info *mddi)
126 (rev->
hdr.length >=
sizeof(
struct mddi_rev_packet) - 2)) {
128 switch (rev->
hdr.type) {
131 sizeof(
struct mddi_client_caps));
137 sizeof(
struct mddi_client_status));
146 rev->
reg.register_address,
147 rev->
reg.register_data_list);
150 if (ri->
reg != rev->
reg.register_address) {
152 "wrong register, expected "
154 rev->
reg.register_address,
155 rev->
reg.register_data_list, ri->
reg);
160 ri->
result = rev->
reg.register_data_list;
165 "len=%04x type=%04x CURR_REV_PTR=%x\n",
166 rev->
hdr.length, rev->
hdr.type,
168 for (i = 0; i < rev->
hdr.length + 2; i++) {
174 mddi_reset_rev_encap_ptr(mddi);
179 mddi_reset_rev_encap_ptr(mddi);
185 static void mddi_handle_rev_data_avail(
struct mddi_info *mddi)
199 if (rev_data_count > 1)
202 if (rev_crc_err_count) {
217 if (rev_data_count == 0)
235 mddi_reset_rev_encap_ptr(mddi);
244 mddi_handle_rev_data(mddi, &tmprev);
246 mddi_handle_rev_data(mddi, crev);
276 mddi->
int_enable &= (~MDDI_INT_PRI_LINK_LIST_DONE);
277 mddi_handle_link_list_done(mddi);
280 mddi_handle_rev_data_avail(mddi);
291 mddi->
int_enable &= (~MDDI_INT_IN_HIBERNATION);
301 static long mddi_wait_interrupt_timeout(
struct mddi_info *mddi,
304 unsigned long irq_flags;
310 spin_unlock_irqrestore(&mddi->
int_lock, irq_flags);
317 if (mddi_wait_interrupt_timeout(mddi, intmask,
HZ/10) == 0)
319 "waiting for %x, INT = %x, STAT = %x gotint = %x\n",
324 static void mddi_init_rev_encap(
struct mddi_info *mddi)
382 mddi_init_rev_encap(mddi);
412 mddi_init_registers(mddi);
429 MDDI_INT_PRI_LINK_LIST_DONE |
430 MDDI_INT_REV_DATA_AVAIL |
439 for (j = 0; j < 3; j++) {
444 for (i = 0; i < 4; i++) {
487 if (mddi->
status.crc_error_count)
490 mddi->
status.crc_error_count);
513 struct mddi_llentry *ll;
514 struct mddi_register_access *
ra;
527 ra->register_address =
reg;
528 ra->register_data_list =
val;
531 ll->header_count = 14;
534 u.r.register_data_list);
540 mddi_wait_interrupt(mddi, MDDI_INT_PRI_LINK_LIST_DONE);
548 struct mddi_llentry *ll;
549 struct mddi_register_access *
ra;
553 unsigned long irq_flags;
566 ra->register_address =
reg;
569 ll->header_count = 14;
581 init_completion(&ri.
done);
585 mddi_wait_interrupt(mddi, MDDI_INT_PRI_LINK_LIST_DONE);
597 spin_unlock_irqrestore(&mddi->
int_lock, irq_flags);
608 "MDDI_CMD_SEND_RTD: int %x, stat %x, rtd val %x "
611 }
while (retry_count-- > 0);
624 unsigned long clk_rate)
630 if (IS_ERR(mddi->
clk)) {
632 return PTR_ERR(mddi->
clk);
689 goto error_get_irq_resource;
701 ret = mddi_clk_setup(pdev, mddi, pdata->
clk_rate);
704 goto error_clk_setup;
707 ret = mddi_rev_data_setup(mddi);
719 goto error_request_irq;
730 mddi->
version = mddi_init_registers(mddi);
735 goto error_mddi_version;
739 if (!mddi_get_client_caps(mddi)) {
750 if (mddi->
caps.Mfr_Name == 0 && mddi->
caps.Product_Code == 0)
751 pdata->
fixup(&mddi->
caps.Mfr_Name, &mddi->
caps.Product_Code);
756 (mddi->
caps.Mfr_Name << 16 | mddi->
caps.Product_Code)) {
782 else if (pdev->
id == 1)
788 goto error_mddi_interface;
796 error_mddi_interface:
803 error_get_irq_resource:
814 .driver = { .name =
"msm_mddi" },
817 static int __init _mddi_init(
void)