Abhinav Kumar | 2316fb9 | 2017-01-30 23:07:08 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved. |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
Alan Kwong | f5dd86c | 2016-08-09 18:08:17 -0400 | [diff] [blame] | 13 | #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__ |
| 14 | |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 15 | #include <linux/irqdomain.h> |
| 16 | #include <linux/irq.h> |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 17 | #include <linux/kthread.h> |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 18 | |
Alan Kwong | f5dd86c | 2016-08-09 18:08:17 -0400 | [diff] [blame] | 19 | #include "sde_irq.h" |
| 20 | #include "sde_core_irq.h" |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 21 | |
Lloyd Atkinson | e5de09d | 2017-08-21 10:15:38 -0400 | [diff] [blame] | 22 | static uint32_t g_sde_irq_status; |
| 23 | |
Harsh Sahu | 08a4a74 | 2017-09-18 11:42:39 -0700 | [diff] [blame] | 24 | void sde_irq_update(struct msm_kms *msm_kms, bool enable) |
| 25 | { |
Harsh Sahu | 08a4a74 | 2017-09-18 11:42:39 -0700 | [diff] [blame] | 26 | struct sde_kms *sde_kms = to_sde_kms(msm_kms); |
| 27 | |
| 28 | if (!msm_kms || !sde_kms) { |
| 29 | SDE_ERROR("invalid kms arguments\n"); |
| 30 | return; |
| 31 | } |
| 32 | |
Harsh Sahu | 08a4a74 | 2017-09-18 11:42:39 -0700 | [diff] [blame] | 33 | if (enable) |
Alan Kwong | 9485ecc | 2017-10-06 18:09:38 -0400 | [diff] [blame] | 34 | enable_irq(sde_kms->irq_num); |
Harsh Sahu | 08a4a74 | 2017-09-18 11:42:39 -0700 | [diff] [blame] | 35 | else |
Alan Kwong | 9485ecc | 2017-10-06 18:09:38 -0400 | [diff] [blame] | 36 | disable_irq(sde_kms->irq_num); |
Harsh Sahu | 08a4a74 | 2017-09-18 11:42:39 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 39 | irqreturn_t sde_irq(struct msm_kms *kms) |
| 40 | { |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 41 | struct sde_kms *sde_kms = to_sde_kms(kms); |
| 42 | u32 interrupts; |
| 43 | |
| 44 | sde_kms->hw_intr->ops.get_interrupt_sources(sde_kms->hw_intr, |
| 45 | &interrupts); |
| 46 | |
Lloyd Atkinson | e5de09d | 2017-08-21 10:15:38 -0400 | [diff] [blame] | 47 | /* store irq status in case of irq-storm debugging */ |
| 48 | g_sde_irq_status = interrupts; |
| 49 | |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 50 | /* |
| 51 | * Taking care of MDP interrupt |
| 52 | */ |
| 53 | if (interrupts & IRQ_SOURCE_MDP) { |
| 54 | interrupts &= ~IRQ_SOURCE_MDP; |
Alan Kwong | f5dd86c | 2016-08-09 18:08:17 -0400 | [diff] [blame] | 55 | sde_core_irq(sde_kms); |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | /* |
| 59 | * Routing all other interrupts to external drivers |
| 60 | */ |
| 61 | while (interrupts) { |
| 62 | irq_hw_number_t hwirq = fls(interrupts) - 1; |
Lloyd Atkinson | e5de09d | 2017-08-21 10:15:38 -0400 | [diff] [blame] | 63 | unsigned int mapping; |
| 64 | int rc; |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 65 | |
Lloyd Atkinson | e5de09d | 2017-08-21 10:15:38 -0400 | [diff] [blame] | 66 | mapping = irq_find_mapping(sde_kms->irq_controller.domain, |
| 67 | hwirq); |
| 68 | if (mapping == 0) { |
| 69 | SDE_EVT32(hwirq, SDE_EVTLOG_ERROR); |
| 70 | goto error; |
| 71 | } |
| 72 | |
| 73 | rc = generic_handle_irq(mapping); |
| 74 | if (rc < 0) { |
| 75 | SDE_EVT32(hwirq, mapping, rc, SDE_EVTLOG_ERROR); |
| 76 | goto error; |
| 77 | } |
| 78 | |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 79 | interrupts &= ~(1 << hwirq); |
| 80 | } |
| 81 | |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 82 | return IRQ_HANDLED; |
Lloyd Atkinson | e5de09d | 2017-08-21 10:15:38 -0400 | [diff] [blame] | 83 | |
| 84 | error: |
| 85 | /* bad situation, inform irq system, it may disable overall MDSS irq */ |
| 86 | return IRQ_NONE; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Alan Kwong | f5dd86c | 2016-08-09 18:08:17 -0400 | [diff] [blame] | 89 | void sde_irq_preinstall(struct msm_kms *kms) |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 90 | { |
Alan Kwong | f5dd86c | 2016-08-09 18:08:17 -0400 | [diff] [blame] | 91 | struct sde_kms *sde_kms = to_sde_kms(kms); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 92 | |
Alan Kwong | f5dd86c | 2016-08-09 18:08:17 -0400 | [diff] [blame] | 93 | if (!sde_kms->dev || !sde_kms->dev->dev) { |
| 94 | pr_err("invalid device handles\n"); |
| 95 | return; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 96 | } |
Alan Kwong | f5dd86c | 2016-08-09 18:08:17 -0400 | [diff] [blame] | 97 | |
| 98 | sde_core_irq_preinstall(sde_kms); |
Alan Kwong | 9485ecc | 2017-10-06 18:09:38 -0400 | [diff] [blame] | 99 | |
| 100 | sde_kms->irq_num = platform_get_irq(sde_kms->dev->platformdev, 0); |
| 101 | if (sde_kms->irq_num < 0) { |
| 102 | SDE_ERROR("invalid irq number %d\n", sde_kms->irq_num); |
| 103 | return; |
| 104 | } |
| 105 | |
| 106 | /* disable irq until power event enables it */ |
Chandan Uddaraju | 3f2cf42 | 2017-06-15 15:37:39 -0700 | [diff] [blame] | 107 | if (!sde_kms->cont_splash_en) |
| 108 | irq_set_status_flags(sde_kms->irq_num, IRQ_NOAUTOEN); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Alan Kwong | f5dd86c | 2016-08-09 18:08:17 -0400 | [diff] [blame] | 111 | int sde_irq_postinstall(struct msm_kms *kms) |
| 112 | { |
| 113 | struct sde_kms *sde_kms = to_sde_kms(kms); |
| 114 | int rc; |
| 115 | |
| 116 | if (!kms) { |
| 117 | SDE_ERROR("invalid parameters\n"); |
| 118 | return -EINVAL; |
| 119 | } |
| 120 | |
| 121 | rc = sde_core_irq_postinstall(sde_kms); |
| 122 | |
| 123 | return rc; |
| 124 | } |
| 125 | |
| 126 | void sde_irq_uninstall(struct msm_kms *kms) |
| 127 | { |
| 128 | struct sde_kms *sde_kms = to_sde_kms(kms); |
| 129 | |
| 130 | if (!kms) { |
| 131 | SDE_ERROR("invalid parameters\n"); |
| 132 | return; |
| 133 | } |
| 134 | |
| 135 | sde_core_irq_uninstall(sde_kms); |
Abhinav Kumar | 2316fb9 | 2017-01-30 23:07:08 -0800 | [diff] [blame] | 136 | sde_core_irq_domain_fini(sde_kms); |
Alan Kwong | f5dd86c | 2016-08-09 18:08:17 -0400 | [diff] [blame] | 137 | } |