Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Texas Instruments |
| 3 | * Author: Rob Clark <robdclark@gmail.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 as published by |
| 7 | * the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | |
| 18 | /* LCDC DRM driver, based on da8xx-fb */ |
| 19 | |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 20 | #include <linux/component.h> |
Dave Gerlach | 416a07f | 2014-07-29 06:27:58 +0000 | [diff] [blame] | 21 | #include <linux/pinctrl/consumer.h> |
| 22 | #include <linux/suspend.h> |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 23 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 24 | #include "tilcdc_drv.h" |
| 25 | #include "tilcdc_regs.h" |
| 26 | #include "tilcdc_tfp410.h" |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 27 | #include "tilcdc_panel.h" |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 28 | #include "tilcdc_external.h" |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 29 | |
| 30 | #include "drm_fb_helper.h" |
| 31 | |
| 32 | static LIST_HEAD(module_list); |
| 33 | |
| 34 | void tilcdc_module_init(struct tilcdc_module *mod, const char *name, |
| 35 | const struct tilcdc_module_ops *funcs) |
| 36 | { |
| 37 | mod->name = name; |
| 38 | mod->funcs = funcs; |
| 39 | INIT_LIST_HEAD(&mod->list); |
| 40 | list_add(&mod->list, &module_list); |
| 41 | } |
| 42 | |
| 43 | void tilcdc_module_cleanup(struct tilcdc_module *mod) |
| 44 | { |
| 45 | list_del(&mod->list); |
| 46 | } |
| 47 | |
| 48 | static struct of_device_id tilcdc_of_match[]; |
| 49 | |
| 50 | static struct drm_framebuffer *tilcdc_fb_create(struct drm_device *dev, |
Ville Syrjälä | 1eb8345 | 2015-11-11 19:11:29 +0200 | [diff] [blame] | 51 | struct drm_file *file_priv, const struct drm_mode_fb_cmd2 *mode_cmd) |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 52 | { |
| 53 | return drm_fb_cma_create(dev, file_priv, mode_cmd); |
| 54 | } |
| 55 | |
| 56 | static void tilcdc_fb_output_poll_changed(struct drm_device *dev) |
| 57 | { |
| 58 | struct tilcdc_drm_private *priv = dev->dev_private; |
Markus Elfring | c0844817 | 2014-11-19 17:05:20 +0100 | [diff] [blame] | 59 | drm_fbdev_cma_hotplug_event(priv->fbdev); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | static const struct drm_mode_config_funcs mode_config_funcs = { |
| 63 | .fb_create = tilcdc_fb_create, |
| 64 | .output_poll_changed = tilcdc_fb_output_poll_changed, |
| 65 | }; |
| 66 | |
| 67 | static int modeset_init(struct drm_device *dev) |
| 68 | { |
| 69 | struct tilcdc_drm_private *priv = dev->dev_private; |
| 70 | struct tilcdc_module *mod; |
| 71 | |
| 72 | drm_mode_config_init(dev); |
| 73 | |
| 74 | priv->crtc = tilcdc_crtc_create(dev); |
| 75 | |
| 76 | list_for_each_entry(mod, &module_list, list) { |
| 77 | DBG("loading module: %s", mod->name); |
| 78 | mod->funcs->modeset_init(mod, dev); |
| 79 | } |
| 80 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 81 | dev->mode_config.min_width = 0; |
| 82 | dev->mode_config.min_height = 0; |
| 83 | dev->mode_config.max_width = tilcdc_crtc_max_width(priv->crtc); |
| 84 | dev->mode_config.max_height = 2048; |
| 85 | dev->mode_config.funcs = &mode_config_funcs; |
| 86 | |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | #ifdef CONFIG_CPU_FREQ |
| 91 | static int cpufreq_transition(struct notifier_block *nb, |
| 92 | unsigned long val, void *data) |
| 93 | { |
| 94 | struct tilcdc_drm_private *priv = container_of(nb, |
| 95 | struct tilcdc_drm_private, freq_transition); |
| 96 | if (val == CPUFREQ_POSTCHANGE) { |
| 97 | if (priv->lcd_fck_rate != clk_get_rate(priv->clk)) { |
| 98 | priv->lcd_fck_rate = clk_get_rate(priv->clk); |
| 99 | tilcdc_crtc_update_clk(priv->crtc); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | #endif |
| 106 | |
| 107 | /* |
| 108 | * DRM operations: |
| 109 | */ |
| 110 | |
| 111 | static int tilcdc_unload(struct drm_device *dev) |
| 112 | { |
| 113 | struct tilcdc_drm_private *priv = dev->dev_private; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 114 | |
Tomi Valkeinen | 1aea1e7 | 2015-10-19 14:15:26 +0300 | [diff] [blame] | 115 | tilcdc_crtc_dpms(priv->crtc, DRM_MODE_DPMS_OFF); |
| 116 | |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 117 | tilcdc_remove_external_encoders(dev); |
| 118 | |
Guido Martínez | 3a49012 | 2014-06-17 11:17:07 -0300 | [diff] [blame] | 119 | drm_fbdev_cma_fini(priv->fbdev); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 120 | drm_kms_helper_poll_fini(dev); |
| 121 | drm_mode_config_cleanup(dev); |
| 122 | drm_vblank_cleanup(dev); |
| 123 | |
| 124 | pm_runtime_get_sync(dev->dev); |
| 125 | drm_irq_uninstall(dev); |
| 126 | pm_runtime_put_sync(dev->dev); |
| 127 | |
| 128 | #ifdef CONFIG_CPU_FREQ |
| 129 | cpufreq_unregister_notifier(&priv->freq_transition, |
| 130 | CPUFREQ_TRANSITION_NOTIFIER); |
| 131 | #endif |
| 132 | |
| 133 | if (priv->clk) |
| 134 | clk_put(priv->clk); |
| 135 | |
| 136 | if (priv->mmio) |
| 137 | iounmap(priv->mmio); |
| 138 | |
| 139 | flush_workqueue(priv->wq); |
| 140 | destroy_workqueue(priv->wq); |
| 141 | |
| 142 | dev->dev_private = NULL; |
| 143 | |
| 144 | pm_runtime_disable(dev->dev); |
| 145 | |
Jyri Sarha | 29ddd6e | 2015-07-02 16:26:12 +0300 | [diff] [blame] | 146 | kfree(priv->saved_register); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 147 | kfree(priv); |
| 148 | |
| 149 | return 0; |
| 150 | } |
| 151 | |
Jyri Sarha | 29ddd6e | 2015-07-02 16:26:12 +0300 | [diff] [blame] | 152 | static size_t tilcdc_num_regs(void); |
| 153 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 154 | static int tilcdc_load(struct drm_device *dev, unsigned long flags) |
| 155 | { |
| 156 | struct platform_device *pdev = dev->platformdev; |
| 157 | struct device_node *node = pdev->dev.of_node; |
| 158 | struct tilcdc_drm_private *priv; |
Benoit Parrot | dc28aa0 | 2013-06-18 17:18:31 -0500 | [diff] [blame] | 159 | struct tilcdc_module *mod; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 160 | struct resource *res; |
Benoit Parrot | dc28aa0 | 2013-06-18 17:18:31 -0500 | [diff] [blame] | 161 | u32 bpp = 0; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 162 | int ret; |
| 163 | |
| 164 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
Jyri Sarha | 29ddd6e | 2015-07-02 16:26:12 +0300 | [diff] [blame] | 165 | if (priv) |
| 166 | priv->saved_register = kcalloc(tilcdc_num_regs(), |
| 167 | sizeof(*priv->saved_register), |
| 168 | GFP_KERNEL); |
| 169 | if (!priv || !priv->saved_register) { |
| 170 | kfree(priv); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 171 | dev_err(dev->dev, "failed to allocate private data\n"); |
| 172 | return -ENOMEM; |
| 173 | } |
| 174 | |
| 175 | dev->dev_private = priv; |
| 176 | |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 177 | priv->is_componentized = |
| 178 | tilcdc_get_external_components(dev->dev, NULL) > 0; |
| 179 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 180 | priv->wq = alloc_ordered_workqueue("tilcdc", 0); |
Ezequiel Garcia | b478e336b | 2014-09-02 09:51:15 -0300 | [diff] [blame] | 181 | if (!priv->wq) { |
| 182 | ret = -ENOMEM; |
| 183 | goto fail_free_priv; |
| 184 | } |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 185 | |
| 186 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 187 | if (!res) { |
| 188 | dev_err(dev->dev, "failed to get memory resource\n"); |
| 189 | ret = -EINVAL; |
Ezequiel Garcia | b478e336b | 2014-09-02 09:51:15 -0300 | [diff] [blame] | 190 | goto fail_free_wq; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | priv->mmio = ioremap_nocache(res->start, resource_size(res)); |
| 194 | if (!priv->mmio) { |
| 195 | dev_err(dev->dev, "failed to ioremap\n"); |
| 196 | ret = -ENOMEM; |
Ezequiel Garcia | b478e336b | 2014-09-02 09:51:15 -0300 | [diff] [blame] | 197 | goto fail_free_wq; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | priv->clk = clk_get(dev->dev, "fck"); |
| 201 | if (IS_ERR(priv->clk)) { |
| 202 | dev_err(dev->dev, "failed to get functional clock\n"); |
| 203 | ret = -ENODEV; |
Ezequiel Garcia | b478e336b | 2014-09-02 09:51:15 -0300 | [diff] [blame] | 204 | goto fail_iounmap; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 205 | } |
| 206 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 207 | #ifdef CONFIG_CPU_FREQ |
| 208 | priv->lcd_fck_rate = clk_get_rate(priv->clk); |
| 209 | priv->freq_transition.notifier_call = cpufreq_transition; |
| 210 | ret = cpufreq_register_notifier(&priv->freq_transition, |
| 211 | CPUFREQ_TRANSITION_NOTIFIER); |
| 212 | if (ret) { |
| 213 | dev_err(dev->dev, "failed to register cpufreq notifier\n"); |
Darren Etheridge | 3d19306 | 2014-01-15 15:52:36 -0600 | [diff] [blame] | 214 | goto fail_put_clk; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 215 | } |
| 216 | #endif |
| 217 | |
| 218 | if (of_property_read_u32(node, "max-bandwidth", &priv->max_bandwidth)) |
Darren Etheridge | 4e56434 | 2013-06-21 13:52:23 -0500 | [diff] [blame] | 219 | priv->max_bandwidth = TILCDC_DEFAULT_MAX_BANDWIDTH; |
| 220 | |
| 221 | DBG("Maximum Bandwidth Value %d", priv->max_bandwidth); |
| 222 | |
| 223 | if (of_property_read_u32(node, "ti,max-width", &priv->max_width)) |
| 224 | priv->max_width = TILCDC_DEFAULT_MAX_WIDTH; |
| 225 | |
| 226 | DBG("Maximum Horizontal Pixel Width Value %dpixels", priv->max_width); |
| 227 | |
| 228 | if (of_property_read_u32(node, "ti,max-pixelclock", |
| 229 | &priv->max_pixelclock)) |
| 230 | priv->max_pixelclock = TILCDC_DEFAULT_MAX_PIXELCLOCK; |
| 231 | |
| 232 | DBG("Maximum Pixel Clock Value %dKHz", priv->max_pixelclock); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 233 | |
| 234 | pm_runtime_enable(dev->dev); |
| 235 | |
| 236 | /* Determine LCD IP Version */ |
| 237 | pm_runtime_get_sync(dev->dev); |
| 238 | switch (tilcdc_read(dev, LCDC_PID_REG)) { |
| 239 | case 0x4c100102: |
| 240 | priv->rev = 1; |
| 241 | break; |
| 242 | case 0x4f200800: |
| 243 | case 0x4f201000: |
| 244 | priv->rev = 2; |
| 245 | break; |
| 246 | default: |
| 247 | dev_warn(dev->dev, "Unknown PID Reg value 0x%08x, " |
| 248 | "defaulting to LCD revision 1\n", |
| 249 | tilcdc_read(dev, LCDC_PID_REG)); |
| 250 | priv->rev = 1; |
| 251 | break; |
| 252 | } |
| 253 | |
| 254 | pm_runtime_put_sync(dev->dev); |
| 255 | |
| 256 | ret = modeset_init(dev); |
| 257 | if (ret < 0) { |
| 258 | dev_err(dev->dev, "failed to initialize mode setting\n"); |
Ezequiel Garcia | b478e336b | 2014-09-02 09:51:15 -0300 | [diff] [blame] | 259 | goto fail_cpufreq_unregister; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 260 | } |
| 261 | |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 262 | platform_set_drvdata(pdev, dev); |
| 263 | |
| 264 | if (priv->is_componentized) { |
| 265 | ret = component_bind_all(dev->dev, dev); |
| 266 | if (ret < 0) |
| 267 | goto fail_mode_config_cleanup; |
| 268 | |
| 269 | ret = tilcdc_add_external_encoders(dev, &bpp); |
| 270 | if (ret < 0) |
| 271 | goto fail_component_cleanup; |
| 272 | } |
| 273 | |
| 274 | if ((priv->num_encoders == 0) || (priv->num_connectors == 0)) { |
| 275 | dev_err(dev->dev, "no encoders/connectors found\n"); |
| 276 | ret = -ENXIO; |
| 277 | goto fail_external_cleanup; |
| 278 | } |
| 279 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 280 | ret = drm_vblank_init(dev, 1); |
| 281 | if (ret < 0) { |
| 282 | dev_err(dev->dev, "failed to initialize vblank\n"); |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 283 | goto fail_external_cleanup; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | pm_runtime_get_sync(dev->dev); |
Daniel Vetter | bb0f1b5 | 2013-11-03 21:09:27 +0100 | [diff] [blame] | 287 | ret = drm_irq_install(dev, platform_get_irq(dev->platformdev, 0)); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 288 | pm_runtime_put_sync(dev->dev); |
| 289 | if (ret < 0) { |
| 290 | dev_err(dev->dev, "failed to install IRQ handler\n"); |
Ezequiel Garcia | b478e336b | 2014-09-02 09:51:15 -0300 | [diff] [blame] | 291 | goto fail_vblank_cleanup; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 292 | } |
| 293 | |
Benoit Parrot | dc28aa0 | 2013-06-18 17:18:31 -0500 | [diff] [blame] | 294 | list_for_each_entry(mod, &module_list, list) { |
| 295 | DBG("%s: preferred_bpp: %d", mod->name, mod->preferred_bpp); |
| 296 | bpp = mod->preferred_bpp; |
| 297 | if (bpp > 0) |
| 298 | break; |
| 299 | } |
| 300 | |
Maxime Ripard | 4314e19 | 2016-01-14 16:24:56 +0100 | [diff] [blame] | 301 | drm_helper_disable_unused_functions(dev); |
Benoit Parrot | dc28aa0 | 2013-06-18 17:18:31 -0500 | [diff] [blame] | 302 | priv->fbdev = drm_fbdev_cma_init(dev, bpp, |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 303 | dev->mode_config.num_crtc, |
| 304 | dev->mode_config.num_connector); |
Ezequiel Garcia | b478e336b | 2014-09-02 09:51:15 -0300 | [diff] [blame] | 305 | if (IS_ERR(priv->fbdev)) { |
| 306 | ret = PTR_ERR(priv->fbdev); |
| 307 | goto fail_irq_uninstall; |
| 308 | } |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 309 | |
| 310 | drm_kms_helper_poll_init(dev); |
| 311 | |
| 312 | return 0; |
| 313 | |
Ezequiel Garcia | b478e336b | 2014-09-02 09:51:15 -0300 | [diff] [blame] | 314 | fail_irq_uninstall: |
| 315 | pm_runtime_get_sync(dev->dev); |
| 316 | drm_irq_uninstall(dev); |
| 317 | pm_runtime_put_sync(dev->dev); |
| 318 | |
| 319 | fail_vblank_cleanup: |
| 320 | drm_vblank_cleanup(dev); |
| 321 | |
| 322 | fail_mode_config_cleanup: |
| 323 | drm_mode_config_cleanup(dev); |
| 324 | |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 325 | fail_component_cleanup: |
| 326 | if (priv->is_componentized) |
| 327 | component_unbind_all(dev->dev, dev); |
| 328 | |
| 329 | fail_external_cleanup: |
| 330 | tilcdc_remove_external_encoders(dev); |
| 331 | |
Ezequiel Garcia | b478e336b | 2014-09-02 09:51:15 -0300 | [diff] [blame] | 332 | fail_cpufreq_unregister: |
| 333 | pm_runtime_disable(dev->dev); |
| 334 | #ifdef CONFIG_CPU_FREQ |
| 335 | cpufreq_unregister_notifier(&priv->freq_transition, |
| 336 | CPUFREQ_TRANSITION_NOTIFIER); |
Ezequiel Garcia | b478e336b | 2014-09-02 09:51:15 -0300 | [diff] [blame] | 337 | |
| 338 | fail_put_clk: |
Grygorii Strashko | 7974dff | 2015-02-25 18:19:43 +0200 | [diff] [blame] | 339 | #endif |
Ezequiel Garcia | b478e336b | 2014-09-02 09:51:15 -0300 | [diff] [blame] | 340 | clk_put(priv->clk); |
| 341 | |
| 342 | fail_iounmap: |
| 343 | iounmap(priv->mmio); |
| 344 | |
| 345 | fail_free_wq: |
| 346 | flush_workqueue(priv->wq); |
| 347 | destroy_workqueue(priv->wq); |
| 348 | |
| 349 | fail_free_priv: |
| 350 | dev->dev_private = NULL; |
Jyri Sarha | 29ddd6e | 2015-07-02 16:26:12 +0300 | [diff] [blame] | 351 | kfree(priv->saved_register); |
Ezequiel Garcia | b478e336b | 2014-09-02 09:51:15 -0300 | [diff] [blame] | 352 | kfree(priv); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 353 | return ret; |
| 354 | } |
| 355 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 356 | static void tilcdc_lastclose(struct drm_device *dev) |
| 357 | { |
| 358 | struct tilcdc_drm_private *priv = dev->dev_private; |
| 359 | drm_fbdev_cma_restore_mode(priv->fbdev); |
| 360 | } |
| 361 | |
Daniel Vetter | e9f0d76 | 2013-12-11 11:34:42 +0100 | [diff] [blame] | 362 | static irqreturn_t tilcdc_irq(int irq, void *arg) |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 363 | { |
| 364 | struct drm_device *dev = arg; |
| 365 | struct tilcdc_drm_private *priv = dev->dev_private; |
| 366 | return tilcdc_crtc_irq(priv->crtc); |
| 367 | } |
| 368 | |
| 369 | static void tilcdc_irq_preinstall(struct drm_device *dev) |
| 370 | { |
| 371 | tilcdc_clear_irqstatus(dev, 0xffffffff); |
| 372 | } |
| 373 | |
| 374 | static int tilcdc_irq_postinstall(struct drm_device *dev) |
| 375 | { |
| 376 | struct tilcdc_drm_private *priv = dev->dev_private; |
| 377 | |
| 378 | /* enable FIFO underflow irq: */ |
Jyri Sarha | 947df7e3 | 2015-12-09 12:16:11 +0200 | [diff] [blame] | 379 | if (priv->rev == 1) { |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 380 | tilcdc_set(dev, LCDC_RASTER_CTRL_REG, LCDC_V1_UNDERFLOW_INT_ENA); |
Jyri Sarha | 947df7e3 | 2015-12-09 12:16:11 +0200 | [diff] [blame] | 381 | } else { |
| 382 | tilcdc_write(dev, LCDC_INT_ENABLE_SET_REG, |
Darren Etheridge | b62222f | 2014-09-25 00:59:31 +0000 | [diff] [blame] | 383 | LCDC_V2_UNDERFLOW_INT_ENA | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 384 | LCDC_V2_END_OF_FRAME0_INT_ENA | |
Darren Etheridge | b62222f | 2014-09-25 00:59:31 +0000 | [diff] [blame] | 385 | LCDC_FRAME_DONE); |
Jyri Sarha | 947df7e3 | 2015-12-09 12:16:11 +0200 | [diff] [blame] | 386 | } |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 387 | |
| 388 | return 0; |
| 389 | } |
| 390 | |
| 391 | static void tilcdc_irq_uninstall(struct drm_device *dev) |
| 392 | { |
| 393 | struct tilcdc_drm_private *priv = dev->dev_private; |
| 394 | |
| 395 | /* disable irqs that we might have enabled: */ |
| 396 | if (priv->rev == 1) { |
| 397 | tilcdc_clear(dev, LCDC_RASTER_CTRL_REG, |
| 398 | LCDC_V1_UNDERFLOW_INT_ENA | LCDC_V1_PL_INT_ENA); |
| 399 | tilcdc_clear(dev, LCDC_DMA_CTRL_REG, LCDC_V1_END_OF_FRAME_INT_ENA); |
| 400 | } else { |
Jyri Sarha | 947df7e3 | 2015-12-09 12:16:11 +0200 | [diff] [blame] | 401 | tilcdc_write(dev, LCDC_INT_ENABLE_CLR_REG, |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 402 | LCDC_V2_UNDERFLOW_INT_ENA | LCDC_V2_PL_INT_ENA | |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 403 | LCDC_V2_END_OF_FRAME0_INT_ENA | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 404 | LCDC_FRAME_DONE); |
| 405 | } |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 406 | } |
| 407 | |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 408 | static int tilcdc_enable_vblank(struct drm_device *dev, unsigned int pipe) |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 409 | { |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 410 | return 0; |
| 411 | } |
| 412 | |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 413 | static void tilcdc_disable_vblank(struct drm_device *dev, unsigned int pipe) |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 414 | { |
Tomi Valkeinen | 2b2080d | 2015-10-20 09:37:27 +0300 | [diff] [blame] | 415 | return; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | #if defined(CONFIG_DEBUG_FS) || defined(CONFIG_PM_SLEEP) |
| 419 | static const struct { |
| 420 | const char *name; |
| 421 | uint8_t rev; |
| 422 | uint8_t save; |
| 423 | uint32_t reg; |
Sachin Kamat | 3250145 | 2013-03-02 15:53:08 +0530 | [diff] [blame] | 424 | } registers[] = { |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 425 | #define REG(rev, save, reg) { #reg, rev, save, reg } |
| 426 | /* exists in revision 1: */ |
| 427 | REG(1, false, LCDC_PID_REG), |
| 428 | REG(1, true, LCDC_CTRL_REG), |
| 429 | REG(1, false, LCDC_STAT_REG), |
| 430 | REG(1, true, LCDC_RASTER_CTRL_REG), |
| 431 | REG(1, true, LCDC_RASTER_TIMING_0_REG), |
| 432 | REG(1, true, LCDC_RASTER_TIMING_1_REG), |
| 433 | REG(1, true, LCDC_RASTER_TIMING_2_REG), |
| 434 | REG(1, true, LCDC_DMA_CTRL_REG), |
| 435 | REG(1, true, LCDC_DMA_FB_BASE_ADDR_0_REG), |
| 436 | REG(1, true, LCDC_DMA_FB_CEILING_ADDR_0_REG), |
| 437 | REG(1, true, LCDC_DMA_FB_BASE_ADDR_1_REG), |
| 438 | REG(1, true, LCDC_DMA_FB_CEILING_ADDR_1_REG), |
| 439 | /* new in revision 2: */ |
| 440 | REG(2, false, LCDC_RAW_STAT_REG), |
| 441 | REG(2, false, LCDC_MASKED_STAT_REG), |
Jyri Sarha | f3a9994 | 2016-01-08 12:17:50 +0200 | [diff] [blame^] | 442 | REG(2, true, LCDC_INT_ENABLE_SET_REG), |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 443 | REG(2, false, LCDC_INT_ENABLE_CLR_REG), |
| 444 | REG(2, false, LCDC_END_OF_INT_IND_REG), |
| 445 | REG(2, true, LCDC_CLK_ENABLE_REG), |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 446 | #undef REG |
| 447 | }; |
Jyri Sarha | 29ddd6e | 2015-07-02 16:26:12 +0300 | [diff] [blame] | 448 | |
| 449 | static size_t tilcdc_num_regs(void) |
| 450 | { |
| 451 | return ARRAY_SIZE(registers); |
| 452 | } |
| 453 | #else |
| 454 | static size_t tilcdc_num_regs(void) |
| 455 | { |
| 456 | return 0; |
| 457 | } |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 458 | #endif |
| 459 | |
| 460 | #ifdef CONFIG_DEBUG_FS |
| 461 | static int tilcdc_regs_show(struct seq_file *m, void *arg) |
| 462 | { |
| 463 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 464 | struct drm_device *dev = node->minor->dev; |
| 465 | struct tilcdc_drm_private *priv = dev->dev_private; |
| 466 | unsigned i; |
| 467 | |
| 468 | pm_runtime_get_sync(dev->dev); |
| 469 | |
| 470 | seq_printf(m, "revision: %d\n", priv->rev); |
| 471 | |
| 472 | for (i = 0; i < ARRAY_SIZE(registers); i++) |
| 473 | if (priv->rev >= registers[i].rev) |
| 474 | seq_printf(m, "%s:\t %08x\n", registers[i].name, |
| 475 | tilcdc_read(dev, registers[i].reg)); |
| 476 | |
| 477 | pm_runtime_put_sync(dev->dev); |
| 478 | |
| 479 | return 0; |
| 480 | } |
| 481 | |
| 482 | static int tilcdc_mm_show(struct seq_file *m, void *arg) |
| 483 | { |
| 484 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 485 | struct drm_device *dev = node->minor->dev; |
Daniel Vetter | b04a590 | 2013-12-11 14:24:46 +0100 | [diff] [blame] | 486 | return drm_mm_dump_table(m, &dev->vma_offset_manager->vm_addr_space_mm); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | static struct drm_info_list tilcdc_debugfs_list[] = { |
| 490 | { "regs", tilcdc_regs_show, 0 }, |
| 491 | { "mm", tilcdc_mm_show, 0 }, |
| 492 | { "fb", drm_fb_cma_debugfs_show, 0 }, |
| 493 | }; |
| 494 | |
| 495 | static int tilcdc_debugfs_init(struct drm_minor *minor) |
| 496 | { |
| 497 | struct drm_device *dev = minor->dev; |
| 498 | struct tilcdc_module *mod; |
| 499 | int ret; |
| 500 | |
| 501 | ret = drm_debugfs_create_files(tilcdc_debugfs_list, |
| 502 | ARRAY_SIZE(tilcdc_debugfs_list), |
| 503 | minor->debugfs_root, minor); |
| 504 | |
| 505 | list_for_each_entry(mod, &module_list, list) |
| 506 | if (mod->funcs->debugfs_init) |
| 507 | mod->funcs->debugfs_init(mod, minor); |
| 508 | |
| 509 | if (ret) { |
| 510 | dev_err(dev->dev, "could not install tilcdc_debugfs_list\n"); |
| 511 | return ret; |
| 512 | } |
| 513 | |
| 514 | return ret; |
| 515 | } |
| 516 | |
| 517 | static void tilcdc_debugfs_cleanup(struct drm_minor *minor) |
| 518 | { |
| 519 | struct tilcdc_module *mod; |
| 520 | drm_debugfs_remove_files(tilcdc_debugfs_list, |
| 521 | ARRAY_SIZE(tilcdc_debugfs_list), minor); |
| 522 | |
| 523 | list_for_each_entry(mod, &module_list, list) |
| 524 | if (mod->funcs->debugfs_cleanup) |
| 525 | mod->funcs->debugfs_cleanup(mod, minor); |
| 526 | } |
| 527 | #endif |
| 528 | |
| 529 | static const struct file_operations fops = { |
| 530 | .owner = THIS_MODULE, |
| 531 | .open = drm_open, |
| 532 | .release = drm_release, |
| 533 | .unlocked_ioctl = drm_ioctl, |
| 534 | #ifdef CONFIG_COMPAT |
| 535 | .compat_ioctl = drm_compat_ioctl, |
| 536 | #endif |
| 537 | .poll = drm_poll, |
| 538 | .read = drm_read, |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 539 | .llseek = no_llseek, |
| 540 | .mmap = drm_gem_cma_mmap, |
| 541 | }; |
| 542 | |
| 543 | static struct drm_driver tilcdc_driver = { |
Jyri Sarha | 9c15390 | 2015-06-23 14:31:17 +0300 | [diff] [blame] | 544 | .driver_features = (DRIVER_HAVE_IRQ | DRIVER_GEM | DRIVER_MODESET | |
| 545 | DRIVER_PRIME), |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 546 | .load = tilcdc_load, |
| 547 | .unload = tilcdc_unload, |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 548 | .lastclose = tilcdc_lastclose, |
David Herrmann | 915b4d1 | 2014-08-29 12:12:43 +0200 | [diff] [blame] | 549 | .set_busid = drm_platform_set_busid, |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 550 | .irq_handler = tilcdc_irq, |
| 551 | .irq_preinstall = tilcdc_irq_preinstall, |
| 552 | .irq_postinstall = tilcdc_irq_postinstall, |
| 553 | .irq_uninstall = tilcdc_irq_uninstall, |
Ville Syrjälä | b44f840 | 2015-09-30 16:46:48 +0300 | [diff] [blame] | 554 | .get_vblank_counter = drm_vblank_no_hw_counter, |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 555 | .enable_vblank = tilcdc_enable_vblank, |
| 556 | .disable_vblank = tilcdc_disable_vblank, |
| 557 | .gem_free_object = drm_gem_cma_free_object, |
| 558 | .gem_vm_ops = &drm_gem_cma_vm_ops, |
| 559 | .dumb_create = drm_gem_cma_dumb_create, |
| 560 | .dumb_map_offset = drm_gem_cma_dumb_map_offset, |
Daniel Vetter | 43387b3 | 2013-07-16 09:12:04 +0200 | [diff] [blame] | 561 | .dumb_destroy = drm_gem_dumb_destroy, |
Jyri Sarha | 9c15390 | 2015-06-23 14:31:17 +0300 | [diff] [blame] | 562 | |
| 563 | .prime_handle_to_fd = drm_gem_prime_handle_to_fd, |
| 564 | .prime_fd_to_handle = drm_gem_prime_fd_to_handle, |
| 565 | .gem_prime_import = drm_gem_prime_import, |
| 566 | .gem_prime_export = drm_gem_prime_export, |
| 567 | .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table, |
| 568 | .gem_prime_import_sg_table = drm_gem_cma_prime_import_sg_table, |
| 569 | .gem_prime_vmap = drm_gem_cma_prime_vmap, |
| 570 | .gem_prime_vunmap = drm_gem_cma_prime_vunmap, |
| 571 | .gem_prime_mmap = drm_gem_cma_prime_mmap, |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 572 | #ifdef CONFIG_DEBUG_FS |
| 573 | .debugfs_init = tilcdc_debugfs_init, |
| 574 | .debugfs_cleanup = tilcdc_debugfs_cleanup, |
| 575 | #endif |
| 576 | .fops = &fops, |
| 577 | .name = "tilcdc", |
| 578 | .desc = "TI LCD Controller DRM", |
| 579 | .date = "20121205", |
| 580 | .major = 1, |
| 581 | .minor = 0, |
| 582 | }; |
| 583 | |
| 584 | /* |
| 585 | * Power management: |
| 586 | */ |
| 587 | |
| 588 | #ifdef CONFIG_PM_SLEEP |
| 589 | static int tilcdc_pm_suspend(struct device *dev) |
| 590 | { |
| 591 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 592 | struct tilcdc_drm_private *priv = ddev->dev_private; |
| 593 | unsigned i, n = 0; |
| 594 | |
| 595 | drm_kms_helper_poll_disable(ddev); |
| 596 | |
Darren Etheridge | 85fd27f | 2014-09-19 01:42:57 +0000 | [diff] [blame] | 597 | /* Select sleep pin state */ |
| 598 | pinctrl_pm_select_sleep_state(dev); |
| 599 | |
| 600 | if (pm_runtime_suspended(dev)) { |
| 601 | priv->ctx_valid = false; |
| 602 | return 0; |
| 603 | } |
| 604 | |
Darren Etheridge | 614b3cfe | 2014-09-25 00:59:32 +0000 | [diff] [blame] | 605 | /* Disable the LCDC controller, to avoid locking up the PRCM */ |
| 606 | tilcdc_crtc_dpms(priv->crtc, DRM_MODE_DPMS_OFF); |
| 607 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 608 | /* Save register state: */ |
| 609 | for (i = 0; i < ARRAY_SIZE(registers); i++) |
| 610 | if (registers[i].save && (priv->rev >= registers[i].rev)) |
| 611 | priv->saved_register[n++] = tilcdc_read(ddev, registers[i].reg); |
| 612 | |
Darren Etheridge | 85fd27f | 2014-09-19 01:42:57 +0000 | [diff] [blame] | 613 | priv->ctx_valid = true; |
Dave Gerlach | 416a07f | 2014-07-29 06:27:58 +0000 | [diff] [blame] | 614 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 615 | return 0; |
| 616 | } |
| 617 | |
| 618 | static int tilcdc_pm_resume(struct device *dev) |
| 619 | { |
| 620 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 621 | struct tilcdc_drm_private *priv = ddev->dev_private; |
| 622 | unsigned i, n = 0; |
| 623 | |
Dave Gerlach | 416a07f | 2014-07-29 06:27:58 +0000 | [diff] [blame] | 624 | /* Select default pin state */ |
| 625 | pinctrl_pm_select_default_state(dev); |
| 626 | |
Darren Etheridge | 85fd27f | 2014-09-19 01:42:57 +0000 | [diff] [blame] | 627 | if (priv->ctx_valid == true) { |
| 628 | /* Restore register state: */ |
| 629 | for (i = 0; i < ARRAY_SIZE(registers); i++) |
| 630 | if (registers[i].save && |
| 631 | (priv->rev >= registers[i].rev)) |
| 632 | tilcdc_write(ddev, registers[i].reg, |
| 633 | priv->saved_register[n++]); |
| 634 | } |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 635 | |
| 636 | drm_kms_helper_poll_enable(ddev); |
| 637 | |
| 638 | return 0; |
| 639 | } |
| 640 | #endif |
| 641 | |
| 642 | static const struct dev_pm_ops tilcdc_pm_ops = { |
| 643 | SET_SYSTEM_SLEEP_PM_OPS(tilcdc_pm_suspend, tilcdc_pm_resume) |
| 644 | }; |
| 645 | |
| 646 | /* |
| 647 | * Platform driver: |
| 648 | */ |
| 649 | |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 650 | static int tilcdc_bind(struct device *dev) |
| 651 | { |
| 652 | return drm_platform_init(&tilcdc_driver, to_platform_device(dev)); |
| 653 | } |
| 654 | |
| 655 | static void tilcdc_unbind(struct device *dev) |
| 656 | { |
| 657 | drm_put_dev(dev_get_drvdata(dev)); |
| 658 | } |
| 659 | |
| 660 | static const struct component_master_ops tilcdc_comp_ops = { |
| 661 | .bind = tilcdc_bind, |
| 662 | .unbind = tilcdc_unbind, |
| 663 | }; |
| 664 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 665 | static int tilcdc_pdev_probe(struct platform_device *pdev) |
| 666 | { |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 667 | struct component_match *match = NULL; |
| 668 | int ret; |
| 669 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 670 | /* bail out early if no DT data: */ |
| 671 | if (!pdev->dev.of_node) { |
| 672 | dev_err(&pdev->dev, "device-tree data is missing\n"); |
| 673 | return -ENXIO; |
| 674 | } |
| 675 | |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 676 | ret = tilcdc_get_external_components(&pdev->dev, &match); |
| 677 | if (ret < 0) |
| 678 | return ret; |
| 679 | else if (ret == 0) |
| 680 | return drm_platform_init(&tilcdc_driver, pdev); |
| 681 | else |
| 682 | return component_master_add_with_match(&pdev->dev, |
| 683 | &tilcdc_comp_ops, |
| 684 | match); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | static int tilcdc_pdev_remove(struct platform_device *pdev) |
| 688 | { |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 689 | struct drm_device *ddev = dev_get_drvdata(&pdev->dev); |
| 690 | struct tilcdc_drm_private *priv = ddev->dev_private; |
| 691 | |
| 692 | /* Check if a subcomponent has already triggered the unloading. */ |
| 693 | if (!priv) |
| 694 | return 0; |
| 695 | |
| 696 | if (priv->is_componentized) |
| 697 | component_master_del(&pdev->dev, &tilcdc_comp_ops); |
| 698 | else |
| 699 | drm_put_dev(platform_get_drvdata(pdev)); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 700 | |
| 701 | return 0; |
| 702 | } |
| 703 | |
| 704 | static struct of_device_id tilcdc_of_match[] = { |
| 705 | { .compatible = "ti,am33xx-tilcdc", }, |
| 706 | { }, |
| 707 | }; |
| 708 | MODULE_DEVICE_TABLE(of, tilcdc_of_match); |
| 709 | |
| 710 | static struct platform_driver tilcdc_platform_driver = { |
| 711 | .probe = tilcdc_pdev_probe, |
| 712 | .remove = tilcdc_pdev_remove, |
| 713 | .driver = { |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 714 | .name = "tilcdc", |
| 715 | .pm = &tilcdc_pm_ops, |
| 716 | .of_match_table = tilcdc_of_match, |
| 717 | }, |
| 718 | }; |
| 719 | |
| 720 | static int __init tilcdc_drm_init(void) |
| 721 | { |
| 722 | DBG("init"); |
| 723 | tilcdc_tfp410_init(); |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 724 | tilcdc_panel_init(); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 725 | return platform_driver_register(&tilcdc_platform_driver); |
| 726 | } |
| 727 | |
| 728 | static void __exit tilcdc_drm_fini(void) |
| 729 | { |
| 730 | DBG("fini"); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 731 | platform_driver_unregister(&tilcdc_platform_driver); |
Guido Martínez | eb565a2 | 2014-06-17 11:17:08 -0300 | [diff] [blame] | 732 | tilcdc_panel_fini(); |
Guido Martínez | eb565a2 | 2014-06-17 11:17:08 -0300 | [diff] [blame] | 733 | tilcdc_tfp410_fini(); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 734 | } |
| 735 | |
Guido Martínez | 2023d84 | 2014-06-17 11:17:11 -0300 | [diff] [blame] | 736 | module_init(tilcdc_drm_init); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 737 | module_exit(tilcdc_drm_fini); |
| 738 | |
| 739 | MODULE_AUTHOR("Rob Clark <robdclark@gmail.com"); |
| 740 | MODULE_DESCRIPTION("TI LCD Controller DRM Driver"); |
| 741 | MODULE_LICENSE("GPL"); |