Stephane Viau | 2e362e1 | 2014-11-18 12:49:48 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
| 14 | #include "mdp5_kms.h" |
| 15 | #include "mdp5_cfg.h" |
| 16 | |
| 17 | struct mdp5_cfg_handler { |
| 18 | int revision; |
| 19 | struct mdp5_cfg config; |
| 20 | }; |
| 21 | |
| 22 | /* mdp5_cfg must be exposed (used in mdp5.xml.h) */ |
| 23 | const struct mdp5_cfg_hw *mdp5_cfg = NULL; |
| 24 | |
| 25 | const struct mdp5_cfg_hw msm8x74_config = { |
| 26 | .name = "msm8x74", |
Stephane Viau | f525381 | 2015-03-09 09:11:04 -0400 | [diff] [blame] | 27 | .mdp = { |
| 28 | .count = 1, |
| 29 | .base = { 0x00100 }, |
| 30 | }, |
Stephane Viau | 2e362e1 | 2014-11-18 12:49:48 -0500 | [diff] [blame] | 31 | .smp = { |
| 32 | .mmb_count = 22, |
| 33 | .mmb_size = 4096, |
Stephane Viau | 6fa6acd | 2015-03-09 09:11:06 -0400 | [diff] [blame^] | 34 | .clients = { |
| 35 | [SSPP_VIG0] = 1, [SSPP_VIG1] = 4, [SSPP_VIG2] = 7, |
| 36 | [SSPP_DMA0] = 10, [SSPP_DMA1] = 13, |
| 37 | [SSPP_RGB0] = 16, [SSPP_RGB1] = 17, [SSPP_RGB2] = 18, |
| 38 | }, |
Stephane Viau | 2e362e1 | 2014-11-18 12:49:48 -0500 | [diff] [blame] | 39 | }, |
| 40 | .ctl = { |
| 41 | .count = 5, |
| 42 | .base = { 0x00600, 0x00700, 0x00800, 0x00900, 0x00a00 }, |
Stephane Viau | 389b09a | 2015-03-13 15:49:33 -0400 | [diff] [blame] | 43 | .flush_hw_mask = 0x0003ffff, |
Stephane Viau | 2e362e1 | 2014-11-18 12:49:48 -0500 | [diff] [blame] | 44 | }, |
| 45 | .pipe_vig = { |
| 46 | .count = 3, |
| 47 | .base = { 0x01200, 0x01600, 0x01a00 }, |
| 48 | }, |
| 49 | .pipe_rgb = { |
| 50 | .count = 3, |
| 51 | .base = { 0x01e00, 0x02200, 0x02600 }, |
| 52 | }, |
| 53 | .pipe_dma = { |
| 54 | .count = 2, |
| 55 | .base = { 0x02a00, 0x02e00 }, |
| 56 | }, |
| 57 | .lm = { |
| 58 | .count = 5, |
| 59 | .base = { 0x03200, 0x03600, 0x03a00, 0x03e00, 0x04200 }, |
| 60 | .nb_stages = 5, |
| 61 | }, |
| 62 | .dspp = { |
| 63 | .count = 3, |
| 64 | .base = { 0x04600, 0x04a00, 0x04e00 }, |
| 65 | }, |
| 66 | .ad = { |
| 67 | .count = 2, |
| 68 | .base = { 0x13100, 0x13300 }, /* NOTE: no ad in v1.0 */ |
| 69 | }, |
Hai Li | 3830590 | 2015-03-05 15:20:47 -0500 | [diff] [blame] | 70 | .pp = { |
| 71 | .count = 3, |
| 72 | .base = { 0x12d00, 0x12e00, 0x12f00 }, |
| 73 | }, |
Stephane Viau | 2e362e1 | 2014-11-18 12:49:48 -0500 | [diff] [blame] | 74 | .intf = { |
| 75 | .count = 4, |
| 76 | .base = { 0x12500, 0x12700, 0x12900, 0x12b00 }, |
| 77 | }, |
Stephane Viau | 67ac0a2 | 2015-03-13 15:49:34 -0400 | [diff] [blame] | 78 | .intfs = { |
| 79 | [0] = INTF_eDP, |
| 80 | [3] = INTF_HDMI, |
| 81 | }, |
Stephane Viau | 2e362e1 | 2014-11-18 12:49:48 -0500 | [diff] [blame] | 82 | .max_clk = 200000000, |
| 83 | }; |
| 84 | |
| 85 | const struct mdp5_cfg_hw apq8084_config = { |
| 86 | .name = "apq8084", |
Stephane Viau | f525381 | 2015-03-09 09:11:04 -0400 | [diff] [blame] | 87 | .mdp = { |
| 88 | .count = 1, |
| 89 | .base = { 0x00100 }, |
| 90 | }, |
Stephane Viau | 2e362e1 | 2014-11-18 12:49:48 -0500 | [diff] [blame] | 91 | .smp = { |
| 92 | .mmb_count = 44, |
| 93 | .mmb_size = 8192, |
Stephane Viau | 6fa6acd | 2015-03-09 09:11:06 -0400 | [diff] [blame^] | 94 | .clients = { |
| 95 | [SSPP_VIG0] = 1, [SSPP_VIG1] = 4, |
| 96 | [SSPP_VIG2] = 7, [SSPP_VIG3] = 19, |
| 97 | [SSPP_DMA0] = 10, [SSPP_DMA1] = 13, |
| 98 | [SSPP_RGB0] = 16, [SSPP_RGB1] = 17, |
| 99 | [SSPP_RGB2] = 18, [SSPP_RGB3] = 22, |
| 100 | }, |
Stephane Viau | 2e362e1 | 2014-11-18 12:49:48 -0500 | [diff] [blame] | 101 | .reserved_state[0] = GENMASK(7, 0), /* first 8 MMBs */ |
Stephane Viau | 6fa6acd | 2015-03-09 09:11:06 -0400 | [diff] [blame^] | 102 | .reserved = { |
| 103 | /* Two SMP blocks are statically tied to RGB pipes: */ |
| 104 | [16] = 2, [17] = 2, [18] = 2, [22] = 2, |
| 105 | }, |
Stephane Viau | 2e362e1 | 2014-11-18 12:49:48 -0500 | [diff] [blame] | 106 | }, |
| 107 | .ctl = { |
| 108 | .count = 5, |
| 109 | .base = { 0x00600, 0x00700, 0x00800, 0x00900, 0x00a00 }, |
Stephane Viau | 389b09a | 2015-03-13 15:49:33 -0400 | [diff] [blame] | 110 | .flush_hw_mask = 0x003fffff, |
Stephane Viau | 2e362e1 | 2014-11-18 12:49:48 -0500 | [diff] [blame] | 111 | }, |
| 112 | .pipe_vig = { |
| 113 | .count = 4, |
| 114 | .base = { 0x01200, 0x01600, 0x01a00, 0x01e00 }, |
| 115 | }, |
| 116 | .pipe_rgb = { |
| 117 | .count = 4, |
| 118 | .base = { 0x02200, 0x02600, 0x02a00, 0x02e00 }, |
| 119 | }, |
| 120 | .pipe_dma = { |
| 121 | .count = 2, |
| 122 | .base = { 0x03200, 0x03600 }, |
| 123 | }, |
| 124 | .lm = { |
| 125 | .count = 6, |
| 126 | .base = { 0x03a00, 0x03e00, 0x04200, 0x04600, 0x04a00, 0x04e00 }, |
| 127 | .nb_stages = 5, |
| 128 | }, |
| 129 | .dspp = { |
| 130 | .count = 4, |
| 131 | .base = { 0x05200, 0x05600, 0x05a00, 0x05e00 }, |
| 132 | |
| 133 | }, |
| 134 | .ad = { |
| 135 | .count = 3, |
| 136 | .base = { 0x13500, 0x13700, 0x13900 }, |
| 137 | }, |
Hai Li | 3830590 | 2015-03-05 15:20:47 -0500 | [diff] [blame] | 138 | .pp = { |
| 139 | .count = 4, |
| 140 | .base = { 0x12f00, 0x13000, 0x13100, 0x13200 }, |
| 141 | }, |
Stephane Viau | 2e362e1 | 2014-11-18 12:49:48 -0500 | [diff] [blame] | 142 | .intf = { |
| 143 | .count = 5, |
| 144 | .base = { 0x12500, 0x12700, 0x12900, 0x12b00, 0x12d00 }, |
| 145 | }, |
Stephane Viau | 67ac0a2 | 2015-03-13 15:49:34 -0400 | [diff] [blame] | 146 | .intfs = { |
| 147 | [0] = INTF_eDP, |
| 148 | [3] = INTF_HDMI, |
| 149 | }, |
Stephane Viau | 2e362e1 | 2014-11-18 12:49:48 -0500 | [diff] [blame] | 150 | .max_clk = 320000000, |
| 151 | }; |
| 152 | |
| 153 | static const struct mdp5_cfg_handler cfg_handlers[] = { |
| 154 | { .revision = 0, .config = { .hw = &msm8x74_config } }, |
| 155 | { .revision = 2, .config = { .hw = &msm8x74_config } }, |
| 156 | { .revision = 3, .config = { .hw = &apq8084_config } }, |
| 157 | }; |
| 158 | |
| 159 | |
| 160 | static struct mdp5_cfg_platform *mdp5_get_config(struct platform_device *dev); |
| 161 | |
Rob Clark | 42238da | 2014-11-18 14:28:43 -0500 | [diff] [blame] | 162 | const struct mdp5_cfg_hw *mdp5_cfg_get_hw_config(struct mdp5_cfg_handler *cfg_handler) |
Stephane Viau | 2e362e1 | 2014-11-18 12:49:48 -0500 | [diff] [blame] | 163 | { |
Stephane Viau | 2e362e1 | 2014-11-18 12:49:48 -0500 | [diff] [blame] | 164 | return cfg_handler->config.hw; |
| 165 | } |
| 166 | |
Rob Clark | 42238da | 2014-11-18 14:28:43 -0500 | [diff] [blame] | 167 | struct mdp5_cfg *mdp5_cfg_get_config(struct mdp5_cfg_handler *cfg_handler) |
Stephane Viau | 2e362e1 | 2014-11-18 12:49:48 -0500 | [diff] [blame] | 168 | { |
Stephane Viau | 2e362e1 | 2014-11-18 12:49:48 -0500 | [diff] [blame] | 169 | return &cfg_handler->config; |
| 170 | } |
| 171 | |
Rob Clark | 42238da | 2014-11-18 14:28:43 -0500 | [diff] [blame] | 172 | int mdp5_cfg_get_hw_rev(struct mdp5_cfg_handler *cfg_handler) |
Stephane Viau | 2e362e1 | 2014-11-18 12:49:48 -0500 | [diff] [blame] | 173 | { |
Stephane Viau | 2e362e1 | 2014-11-18 12:49:48 -0500 | [diff] [blame] | 174 | return cfg_handler->revision; |
| 175 | } |
| 176 | |
Rob Clark | 42238da | 2014-11-18 14:28:43 -0500 | [diff] [blame] | 177 | void mdp5_cfg_destroy(struct mdp5_cfg_handler *cfg_handler) |
Stephane Viau | 2e362e1 | 2014-11-18 12:49:48 -0500 | [diff] [blame] | 178 | { |
Stephane Viau | 2e362e1 | 2014-11-18 12:49:48 -0500 | [diff] [blame] | 179 | kfree(cfg_handler); |
| 180 | } |
| 181 | |
Rob Clark | 42238da | 2014-11-18 14:28:43 -0500 | [diff] [blame] | 182 | struct mdp5_cfg_handler *mdp5_cfg_init(struct mdp5_kms *mdp5_kms, |
Stephane Viau | 2e362e1 | 2014-11-18 12:49:48 -0500 | [diff] [blame] | 183 | uint32_t major, uint32_t minor) |
| 184 | { |
| 185 | struct drm_device *dev = mdp5_kms->dev; |
| 186 | struct platform_device *pdev = dev->platformdev; |
| 187 | struct mdp5_cfg_handler *cfg_handler; |
| 188 | struct mdp5_cfg_platform *pconfig; |
| 189 | int i, ret = 0; |
| 190 | |
| 191 | cfg_handler = kzalloc(sizeof(*cfg_handler), GFP_KERNEL); |
| 192 | if (unlikely(!cfg_handler)) { |
| 193 | ret = -ENOMEM; |
| 194 | goto fail; |
| 195 | } |
| 196 | |
| 197 | if (major != 1) { |
| 198 | dev_err(dev->dev, "unexpected MDP major version: v%d.%d\n", |
| 199 | major, minor); |
| 200 | ret = -ENXIO; |
| 201 | goto fail; |
| 202 | } |
| 203 | |
| 204 | /* only after mdp5_cfg global pointer's init can we access the hw */ |
| 205 | for (i = 0; i < ARRAY_SIZE(cfg_handlers); i++) { |
| 206 | if (cfg_handlers[i].revision != minor) |
| 207 | continue; |
| 208 | mdp5_cfg = cfg_handlers[i].config.hw; |
| 209 | |
| 210 | break; |
| 211 | } |
| 212 | if (unlikely(!mdp5_cfg)) { |
| 213 | dev_err(dev->dev, "unexpected MDP minor revision: v%d.%d\n", |
| 214 | major, minor); |
| 215 | ret = -ENXIO; |
| 216 | goto fail; |
| 217 | } |
| 218 | |
| 219 | cfg_handler->revision = minor; |
| 220 | cfg_handler->config.hw = mdp5_cfg; |
| 221 | |
| 222 | pconfig = mdp5_get_config(pdev); |
| 223 | memcpy(&cfg_handler->config.platform, pconfig, sizeof(*pconfig)); |
| 224 | |
| 225 | DBG("MDP5: %s hw config selected", mdp5_cfg->name); |
| 226 | |
| 227 | return cfg_handler; |
| 228 | |
| 229 | fail: |
| 230 | if (cfg_handler) |
| 231 | mdp5_cfg_destroy(cfg_handler); |
| 232 | |
| 233 | return NULL; |
| 234 | } |
| 235 | |
| 236 | static struct mdp5_cfg_platform *mdp5_get_config(struct platform_device *dev) |
| 237 | { |
| 238 | static struct mdp5_cfg_platform config = {}; |
| 239 | #ifdef CONFIG_OF |
| 240 | /* TODO */ |
| 241 | #endif |
| 242 | config.iommu = iommu_domain_alloc(&platform_bus_type); |
| 243 | |
| 244 | return &config; |
| 245 | } |