Lines Matching defs:mddi
97 static void mddi_init_rev_encap(struct mddi_info *mddi);
99 #define mddi_readl(r) readl(mddi->base + (MDDI_##r))
100 #define mddi_writel(v, r) writel((v), mddi->base + (MDDI_##r))
104 struct mddi_info *mddi = container_of(cdata, struct mddi_info,
110 static void mddi_handle_link_list_done(struct mddi_info *mddi)
114 static void mddi_reset_rev_encap_ptr(struct mddi_info *mddi)
116 printk(KERN_INFO "mddi: resetting rev ptr\n");
117 mddi->rev_data_curr = 0;
118 mddi_writel(mddi->rev_addr, REV_PTR);
119 mddi_writel(mddi->rev_addr, REV_PTR);
123 static void mddi_handle_rev_data(struct mddi_info *mddi, union mddi_rev *rev)
133 memcpy(&mddi->caps, &rev->caps,
135 mddi->flags |= FLAG_HAVE_CAPS;
136 wake_up(&mddi->int_wait);
139 memcpy(&mddi->status, &rev->status,
141 mddi->flags |= FLAG_HAVE_STATUS;
142 wake_up(&mddi->int_wait);
145 ri = mddi->reg_read;
161 mddi->reg_read = NULL;
177 mddi_reset_rev_encap_ptr(mddi);
182 mddi_reset_rev_encap_ptr(mddi);
186 static void mddi_wait_interrupt(struct mddi_info *mddi, uint32_t intmask);
188 static void mddi_handle_rev_data_avail(struct mddi_info *mddi)
196 union mddi_rev *crev = mddi->rev_data + mddi->rev_data_curr;
208 ri = mddi->reg_read;
213 mddi->reg_read = NULL;
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;
236 printk(KERN_INFO "mddi: rev data length greater than buffer"
238 mddi_reset_rev_encap_ptr(mddi);
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);
253 mddi->rev_data_curr >= MDDI_REV_BUFFER_SIZE / 2) {
254 mddi_writel(mddi->rev_addr, REV_PTR);
261 struct mddi_info *mddi = container_of(cdata, struct mddi_info,
265 spin_lock(&mddi->int_lock);
273 active &= mddi->int_enable;
275 mddi->got_int |= active;
276 wake_up(&mddi->int_wait);
279 mddi->int_enable &= (~MDDI_INT_PRI_LINK_LIST_DONE);
280 mddi_handle_link_list_done(mddi);
283 mddi_handle_rev_data_avail(mddi);
286 mddi->int_enable &= ~(active & ~MDDI_INT_NEED_CLEAR);
289 mddi->int_enable &= (~MDDI_INT_LINK_ACTIVE);
290 mddi->int_enable |= 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,
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)
324 mddi->got_int);
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);
332 mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND);
337 struct mddi_info *mddi = container_of(cdata, struct mddi_info,
340 mddi_wait_interrupt(mddi, MDDI_INT_IN_HIBERNATION);
342 mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND);
346 static uint16_t mddi_init_registers(struct mddi_info *mddi)
364 mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND);
380 mddi_set_auto_hibernate(&mddi->client_data, 0);
383 mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND);
385 mddi_init_rev_encap(mddi);
391 struct mddi_info *mddi = container_of(cdata, struct mddi_info,
394 if (mddi->power_client)
395 mddi->power_client(&mddi->client_data, 0);
398 mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND);
400 clk_disable(mddi->clk);
405 struct mddi_info *mddi = container_of(cdata, struct mddi_info,
407 mddi_set_auto_hibernate(&mddi->client_data, 0);
409 if (mddi->power_client)
410 mddi->power_client(&mddi->client_data, 1);
412 clk_enable(mddi->clk);
414 mddi->rev_data_curr = 0;
415 mddi_init_registers(mddi);
416 mddi_writel(mddi->int_enable, INTEN);
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)
430 mddi->int_enable = MDDI_INT_LINK_ACTIVE |
437 mddi_writel(mddi->int_enable, INTEN);
440 mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND);
451 mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND);
453 printk(KERN_INFO "mddi cmd send rtd: int %x, stat %x, "
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)
471 return mddi->flags & FLAG_HAVE_CAPS;
475 int mddi_check_status(struct mddi_info *mddi)
478 mutex_lock(&mddi->reg_read_lock);
480 mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND);
483 mddi->flags &= ~FLAG_HAVE_STATUS;
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 "
502 mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND);
506 mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND);
507 mutex_unlock(&mddi->reg_read_lock);
515 struct mddi_info *mddi = container_of(cdata, struct mddi_info,
520 mutex_lock(&mddi->reg_write_lock);
522 ll = mddi->reg_write_data;
537 ll->data = mddi->reg_write_addr + offsetof(struct mddi_llentry,
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);
550 struct mddi_info *mddi = container_of(cdata, struct mddi_info,
559 mutex_lock(&mddi->reg_read_lock);
561 ll = mddi->reg_read_data;
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);
593 mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND);
599 spin_lock_irqsave(&mddi->int_lock, irq_flags);
600 mddi->reg_read = NULL;
601 spin_unlock_irqrestore(&mddi->int_lock, irq_flags);
610 mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND);
618 mddi_wait_interrupt(mddi, MDDI_INT_NO_CMD_PKTS_PEND);
619 mddi->reg_read = NULL;
620 mutex_unlock(&mddi->reg_read_lock);
627 struct mddi_info *mddi,
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);
647 clk_put(mddi->clk);
651 static int __init mddi_rev_data_setup(struct mddi_info *mddi)
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);
674 struct mddi_info *mddi = &mddi_info[pdev->id];
680 printk(KERN_ERR "mddi: no associated mem resource!\n");
683 mddi->base = ioremap(resource->start, resource->end - resource->start);
684 if (!mddi->base) {
685 printk(KERN_ERR "mddi: failed to remap base!\n");
691 printk(KERN_ERR "mddi: no associated irq resource!\n");
695 mddi->irq = resource->start;
696 printk(KERN_INFO "mddi: init() base=0x%p irq=%d\n", mddi->base,
697 mddi->irq);
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");
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",
720 &mddi->client_data);
722 printk(KERN_ERR "mddi: failed to request enable irq!\n");
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);
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",
737 mddi->version);
743 if (!mddi_get_client_caps(mddi)) {
744 printk(KERN_INFO "mddi: no client found\n");
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;
760 (mddi->caps.Mfr_Name << 16 | mddi->caps.Product_Code)) {
761 mddi->client_data.private_client_data =
763 mddi->client_pdev.name =
765 mddi->client_pdev.id =
772 mddi->client_pdev.name = "mddi_c_dummy";
773 printk(KERN_INFO "mddi: registering panel %s\n",
774 mddi->client_pdev.name);
776 mddi->client_data.suspend = mddi_suspend;
777 mddi->client_data.resume = mddi_resume;
778 mddi->client_data.activate_link = mddi_activate_link;
779 mddi->client_data.remote_write = mddi_remote_write;
780 mddi->client_data.remote_read = mddi_remote_read;
781 mddi->client_data.auto_hibernate = mddi_set_auto_hibernate;
782 mddi->client_data.fb_resource = pdata->fb_resource;
784 mddi->client_data.interface_type = MSM_MDDI_PMDH_INTERFACE;
786 mddi->client_data.interface_type = MSM_MDDI_EMDH_INTERFACE;
788 printk(KERN_ERR "mddi: can not determine interface %d!\n",
794 mddi->client_pdev.dev.platform_data = &mddi->client_data;
795 printk(KERN_INFO "mddi: publish: %s\n", mddi->client_name);
796 platform_device_register(&mddi->client_pdev);
801 free_irq(mddi->irq, 0);
803 dma_free_coherent(NULL, 0x1000, mddi->rev_data, mddi->rev_addr);
807 iounmap(mddi->base);
810 printk(KERN_INFO "mddi: mddi_init() failed (%d)\n", ret);