1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/ 4 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com> 5 */ 6 7 #include <drm/drm_print.h> 8 9 #include "tidss_crtc.h" 10 #include "tidss_dispc.h" 11 #include "tidss_drv.h" 12 #include "tidss_irq.h" 13 #include "tidss_plane.h" 14 15 /* call with wait_lock and dispc runtime held */ 16 static void tidss_irq_update(struct tidss_device *tidss) 17 { 18 assert_spin_locked(&tidss->wait_lock); 19 20 dispc_set_irqenable(tidss->dispc, tidss->irq_mask); 21 } 22 23 void tidss_irq_enable_vblank(struct drm_crtc *crtc) 24 { 25 struct drm_device *ddev = crtc->dev; 26 struct tidss_device *tidss = to_tidss(ddev); 27 struct tidss_crtc *tcrtc = to_tidss_crtc(crtc); 28 u32 hw_videoport = tcrtc->hw_videoport; 29 unsigned long flags; 30 31 spin_lock_irqsave(&tidss->wait_lock, flags); 32 tidss->irq_mask |= DSS_IRQ_VP_VSYNC_EVEN(hw_videoport) | 33 DSS_IRQ_VP_VSYNC_ODD(hw_videoport); 34 tidss_irq_update(tidss); 35 spin_unlock_irqrestore(&tidss->wait_lock, flags); 36 } 37 38 void tidss_irq_disable_vblank(struct drm_crtc *crtc) 39 { 40 struct drm_device *ddev = crtc->dev; 41 struct tidss_device *tidss = to_tidss(ddev); 42 struct tidss_crtc *tcrtc = to_tidss_crtc(crtc); 43 u32 hw_videoport = tcrtc->hw_videoport; 44 unsigned long flags; 45 46 spin_lock_irqsave(&tidss->wait_lock, flags); 47 tidss->irq_mask &= ~(DSS_IRQ_VP_VSYNC_EVEN(hw_videoport) | 48 DSS_IRQ_VP_VSYNC_ODD(hw_videoport)); 49 tidss_irq_update(tidss); 50 spin_unlock_irqrestore(&tidss->wait_lock, flags); 51 } 52 53 irqreturn_t tidss_irq_handler(int irq, void *arg) 54 { 55 struct drm_device *ddev = (struct drm_device *)arg; 56 struct tidss_device *tidss = to_tidss(ddev); 57 unsigned int id; 58 dispc_irq_t irqstatus; 59 60 if (WARN_ON(!ddev->irq_enabled)) 61 return IRQ_NONE; 62 63 irqstatus = dispc_read_and_clear_irqstatus(tidss->dispc); 64 65 for (id = 0; id < tidss->num_crtcs; id++) { 66 struct drm_crtc *crtc = tidss->crtcs[id]; 67 struct tidss_crtc *tcrtc = to_tidss_crtc(crtc); 68 u32 hw_videoport = tcrtc->hw_videoport; 69 70 if (irqstatus & (DSS_IRQ_VP_VSYNC_EVEN(hw_videoport) | 71 DSS_IRQ_VP_VSYNC_ODD(hw_videoport))) 72 tidss_crtc_vblank_irq(crtc); 73 74 if (irqstatus & (DSS_IRQ_VP_FRAME_DONE(hw_videoport))) 75 tidss_crtc_framedone_irq(crtc); 76 77 if (irqstatus & DSS_IRQ_VP_SYNC_LOST(hw_videoport)) 78 tidss_crtc_error_irq(crtc, irqstatus); 79 } 80 81 if (irqstatus & DSS_IRQ_DEVICE_OCP_ERR) 82 dev_err_ratelimited(tidss->dev, "OCP error\n"); 83 84 return IRQ_HANDLED; 85 } 86 87 void tidss_irq_resume(struct tidss_device *tidss) 88 { 89 unsigned long flags; 90 91 spin_lock_irqsave(&tidss->wait_lock, flags); 92 tidss_irq_update(tidss); 93 spin_unlock_irqrestore(&tidss->wait_lock, flags); 94 } 95 96 void tidss_irq_preinstall(struct drm_device *ddev) 97 { 98 struct tidss_device *tidss = to_tidss(ddev); 99 100 spin_lock_init(&tidss->wait_lock); 101 102 tidss_runtime_get(tidss); 103 104 dispc_set_irqenable(tidss->dispc, 0); 105 dispc_read_and_clear_irqstatus(tidss->dispc); 106 107 tidss_runtime_put(tidss); 108 } 109 110 int tidss_irq_postinstall(struct drm_device *ddev) 111 { 112 struct tidss_device *tidss = to_tidss(ddev); 113 unsigned long flags; 114 unsigned int i; 115 116 tidss_runtime_get(tidss); 117 118 spin_lock_irqsave(&tidss->wait_lock, flags); 119 120 tidss->irq_mask = DSS_IRQ_DEVICE_OCP_ERR; 121 122 for (i = 0; i < tidss->num_crtcs; ++i) { 123 struct tidss_crtc *tcrtc = to_tidss_crtc(tidss->crtcs[i]); 124 125 tidss->irq_mask |= DSS_IRQ_VP_SYNC_LOST(tcrtc->hw_videoport); 126 127 tidss->irq_mask |= DSS_IRQ_VP_FRAME_DONE(tcrtc->hw_videoport); 128 } 129 130 tidss_irq_update(tidss); 131 132 spin_unlock_irqrestore(&tidss->wait_lock, flags); 133 134 tidss_runtime_put(tidss); 135 136 return 0; 137 } 138 139 void tidss_irq_uninstall(struct drm_device *ddev) 140 { 141 struct tidss_device *tidss = to_tidss(ddev); 142 143 tidss_runtime_get(tidss); 144 dispc_set_irqenable(tidss->dispc, 0); 145 tidss_runtime_put(tidss); 146 } 147