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 | edc4330 | 2015-12-30 17:40:24 +0200 | [diff] [blame] | 23 | #include <drm/drm_atomic.h> |
| 24 | #include <drm/drm_atomic_helper.h> |
Masahiro Yamada | bb2af9b | 2017-04-24 13:50:32 +0900 | [diff] [blame] | 25 | #include <drm/drm_fb_helper.h> |
Noralf Trønnes | 6025a15 | 2017-08-13 15:32:02 +0200 | [diff] [blame] | 26 | #include <drm/drm_gem_framebuffer_helper.h> |
Daniel Vetter | fcd70cd | 2019-01-17 22:03:34 +0100 | [diff] [blame] | 27 | #include <drm/drm_probe_helper.h> |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 28 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 29 | #include "tilcdc_drv.h" |
| 30 | #include "tilcdc_regs.h" |
| 31 | #include "tilcdc_tfp410.h" |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 32 | #include "tilcdc_panel.h" |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 33 | #include "tilcdc_external.h" |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 34 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 35 | static LIST_HEAD(module_list); |
| 36 | |
Jyri Sarha | bcc5a6f | 2016-08-11 19:09:43 +0300 | [diff] [blame] | 37 | static const u32 tilcdc_rev1_formats[] = { DRM_FORMAT_RGB565 }; |
| 38 | |
| 39 | static const u32 tilcdc_straight_formats[] = { DRM_FORMAT_RGB565, |
| 40 | DRM_FORMAT_BGR888, |
| 41 | DRM_FORMAT_XBGR8888 }; |
| 42 | |
| 43 | static const u32 tilcdc_crossed_formats[] = { DRM_FORMAT_BGR565, |
| 44 | DRM_FORMAT_RGB888, |
| 45 | DRM_FORMAT_XRGB8888 }; |
| 46 | |
| 47 | static const u32 tilcdc_legacy_formats[] = { DRM_FORMAT_RGB565, |
| 48 | DRM_FORMAT_RGB888, |
| 49 | DRM_FORMAT_XRGB8888 }; |
| 50 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 51 | void tilcdc_module_init(struct tilcdc_module *mod, const char *name, |
| 52 | const struct tilcdc_module_ops *funcs) |
| 53 | { |
| 54 | mod->name = name; |
| 55 | mod->funcs = funcs; |
| 56 | INIT_LIST_HEAD(&mod->list); |
| 57 | list_add(&mod->list, &module_list); |
| 58 | } |
| 59 | |
| 60 | void tilcdc_module_cleanup(struct tilcdc_module *mod) |
| 61 | { |
| 62 | list_del(&mod->list); |
| 63 | } |
| 64 | |
| 65 | static struct of_device_id tilcdc_of_match[]; |
| 66 | |
| 67 | static struct drm_framebuffer *tilcdc_fb_create(struct drm_device *dev, |
Ville Syrjälä | 1eb83451 | 2015-11-11 19:11:29 +0200 | [diff] [blame] | 68 | 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] | 69 | { |
Noralf Trønnes | 6025a15 | 2017-08-13 15:32:02 +0200 | [diff] [blame] | 70 | return drm_gem_fb_create(dev, file_priv, mode_cmd); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 71 | } |
| 72 | |
Wei Yongjun | 3045767 | 2016-09-10 12:32:57 +0000 | [diff] [blame] | 73 | static int tilcdc_atomic_check(struct drm_device *dev, |
| 74 | struct drm_atomic_state *state) |
Jyri Sarha | edc4330 | 2015-12-30 17:40:24 +0200 | [diff] [blame] | 75 | { |
| 76 | int ret; |
| 77 | |
| 78 | ret = drm_atomic_helper_check_modeset(dev, state); |
| 79 | if (ret) |
| 80 | return ret; |
| 81 | |
| 82 | ret = drm_atomic_helper_check_planes(dev, state); |
| 83 | if (ret) |
| 84 | return ret; |
| 85 | |
| 86 | /* |
| 87 | * tilcdc ->atomic_check can update ->mode_changed if pixel format |
| 88 | * changes, hence will we check modeset changes again. |
| 89 | */ |
| 90 | ret = drm_atomic_helper_check_modeset(dev, state); |
| 91 | if (ret) |
| 92 | return ret; |
| 93 | |
| 94 | return ret; |
| 95 | } |
| 96 | |
| 97 | static int tilcdc_commit(struct drm_device *dev, |
| 98 | struct drm_atomic_state *state, |
| 99 | bool async) |
| 100 | { |
| 101 | int ret; |
| 102 | |
| 103 | ret = drm_atomic_helper_prepare_planes(dev, state); |
| 104 | if (ret) |
| 105 | return ret; |
| 106 | |
Maarten Lankhorst | fad9e43 | 2017-07-11 16:33:11 +0200 | [diff] [blame] | 107 | ret = drm_atomic_helper_swap_state(state, true); |
| 108 | if (ret) { |
| 109 | drm_atomic_helper_cleanup_planes(dev, state); |
| 110 | return ret; |
| 111 | } |
Jyri Sarha | edc4330 | 2015-12-30 17:40:24 +0200 | [diff] [blame] | 112 | |
| 113 | /* |
| 114 | * Everything below can be run asynchronously without the need to grab |
| 115 | * any modeset locks at all under one condition: It must be guaranteed |
| 116 | * that the asynchronous work has either been cancelled (if the driver |
| 117 | * supports it, which at least requires that the framebuffers get |
| 118 | * cleaned up with drm_atomic_helper_cleanup_planes()) or completed |
| 119 | * before the new state gets committed on the software side with |
| 120 | * drm_atomic_helper_swap_state(). |
| 121 | * |
| 122 | * This scheme allows new atomic state updates to be prepared and |
| 123 | * checked in parallel to the asynchronous completion of the previous |
| 124 | * update. Which is important since compositors need to figure out the |
| 125 | * composition of the next frame right after having submitted the |
| 126 | * current layout. |
| 127 | */ |
| 128 | |
| 129 | drm_atomic_helper_commit_modeset_disables(dev, state); |
| 130 | |
Liu Ying | 2b58e98 | 2016-08-29 17:12:03 +0800 | [diff] [blame] | 131 | drm_atomic_helper_commit_planes(dev, state, 0); |
Jyri Sarha | edc4330 | 2015-12-30 17:40:24 +0200 | [diff] [blame] | 132 | |
| 133 | drm_atomic_helper_commit_modeset_enables(dev, state); |
| 134 | |
| 135 | drm_atomic_helper_wait_for_vblanks(dev, state); |
| 136 | |
| 137 | drm_atomic_helper_cleanup_planes(dev, state); |
| 138 | |
Jyri Sarha | edc4330 | 2015-12-30 17:40:24 +0200 | [diff] [blame] | 139 | return 0; |
| 140 | } |
| 141 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 142 | static const struct drm_mode_config_funcs mode_config_funcs = { |
| 143 | .fb_create = tilcdc_fb_create, |
Jyri Sarha | edc4330 | 2015-12-30 17:40:24 +0200 | [diff] [blame] | 144 | .atomic_check = tilcdc_atomic_check, |
| 145 | .atomic_commit = tilcdc_commit, |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 146 | }; |
| 147 | |
Jyri Sarha | 9963d36 | 2016-11-15 22:56:46 +0200 | [diff] [blame] | 148 | static void modeset_init(struct drm_device *dev) |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 149 | { |
| 150 | struct tilcdc_drm_private *priv = dev->dev_private; |
| 151 | struct tilcdc_module *mod; |
| 152 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 153 | list_for_each_entry(mod, &module_list, list) { |
| 154 | DBG("loading module: %s", mod->name); |
| 155 | mod->funcs->modeset_init(mod, dev); |
| 156 | } |
| 157 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 158 | dev->mode_config.min_width = 0; |
| 159 | dev->mode_config.min_height = 0; |
| 160 | dev->mode_config.max_width = tilcdc_crtc_max_width(priv->crtc); |
| 161 | dev->mode_config.max_height = 2048; |
| 162 | dev->mode_config.funcs = &mode_config_funcs; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | #ifdef CONFIG_CPU_FREQ |
| 166 | static int cpufreq_transition(struct notifier_block *nb, |
| 167 | unsigned long val, void *data) |
| 168 | { |
| 169 | struct tilcdc_drm_private *priv = container_of(nb, |
| 170 | struct tilcdc_drm_private, freq_transition); |
Jyri Sarha | a6b7eba | 2016-09-05 20:39:32 +0300 | [diff] [blame] | 171 | |
Jyri Sarha | 642e516 | 2016-09-06 16:19:54 +0300 | [diff] [blame] | 172 | if (val == CPUFREQ_POSTCHANGE) |
| 173 | tilcdc_crtc_update_clk(priv->crtc); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | #endif |
| 178 | |
| 179 | /* |
| 180 | * DRM operations: |
| 181 | */ |
| 182 | |
Jyri Sarha | 923310b | 2016-10-17 17:53:33 +0300 | [diff] [blame] | 183 | static void tilcdc_fini(struct drm_device *dev) |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 184 | { |
| 185 | struct tilcdc_drm_private *priv = dev->dev_private; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 186 | |
Jyri Sarha | 432973f | 2018-12-12 19:26:32 +0200 | [diff] [blame] | 187 | #ifdef CONFIG_CPU_FREQ |
| 188 | if (priv->freq_transition.notifier_call) |
| 189 | cpufreq_unregister_notifier(&priv->freq_transition, |
| 190 | CPUFREQ_TRANSITION_NOTIFIER); |
| 191 | #endif |
| 192 | |
Jyri Sarha | 9e79e06 | 2016-10-18 23:23:27 +0300 | [diff] [blame] | 193 | if (priv->crtc) |
Jyri Sarha | 2d53a18 | 2016-10-25 12:27:31 +0300 | [diff] [blame] | 194 | tilcdc_crtc_shutdown(priv->crtc); |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 195 | |
Jyri Sarha | 9e79e06 | 2016-10-18 23:23:27 +0300 | [diff] [blame] | 196 | if (priv->is_registered) |
| 197 | drm_dev_unregister(dev); |
Jyri Sarha | 923310b | 2016-10-17 17:53:33 +0300 | [diff] [blame] | 198 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 199 | drm_kms_helper_poll_fini(dev); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 200 | drm_irq_uninstall(dev); |
Jyri Sarha | 923310b | 2016-10-17 17:53:33 +0300 | [diff] [blame] | 201 | drm_mode_config_cleanup(dev); |
Jyri Sarha | ec9eab0 | 2016-10-31 17:34:22 +0200 | [diff] [blame] | 202 | tilcdc_remove_external_device(dev); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 203 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 204 | if (priv->clk) |
| 205 | clk_put(priv->clk); |
| 206 | |
| 207 | if (priv->mmio) |
| 208 | iounmap(priv->mmio); |
| 209 | |
Jyri Sarha | 9e79e06 | 2016-10-18 23:23:27 +0300 | [diff] [blame] | 210 | if (priv->wq) { |
| 211 | flush_workqueue(priv->wq); |
| 212 | destroy_workqueue(priv->wq); |
| 213 | } |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 214 | |
| 215 | dev->dev_private = NULL; |
| 216 | |
| 217 | pm_runtime_disable(dev->dev); |
| 218 | |
Aishwarya Pant | ce7b700 | 2017-09-26 14:00:19 +0530 | [diff] [blame] | 219 | drm_dev_put(dev); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 220 | } |
| 221 | |
Jyri Sarha | 923310b | 2016-10-17 17:53:33 +0300 | [diff] [blame] | 222 | static int tilcdc_init(struct drm_driver *ddrv, struct device *dev) |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 223 | { |
Jyri Sarha | 923310b | 2016-10-17 17:53:33 +0300 | [diff] [blame] | 224 | struct drm_device *ddev; |
| 225 | struct platform_device *pdev = to_platform_device(dev); |
| 226 | struct device_node *node = dev->of_node; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 227 | struct tilcdc_drm_private *priv; |
| 228 | struct resource *res; |
Benoit Parrot | dc28aa0 | 2013-06-18 17:18:31 -0500 | [diff] [blame] | 229 | u32 bpp = 0; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 230 | int ret; |
| 231 | |
Jyri Sarha | 923310b | 2016-10-17 17:53:33 +0300 | [diff] [blame] | 232 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
Markus Elfring | 3366ba3 | 2018-02-06 21:51:15 +0100 | [diff] [blame] | 233 | if (!priv) |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 234 | return -ENOMEM; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 235 | |
Jyri Sarha | 923310b | 2016-10-17 17:53:33 +0300 | [diff] [blame] | 236 | ddev = drm_dev_alloc(ddrv, dev); |
| 237 | if (IS_ERR(ddev)) |
| 238 | return PTR_ERR(ddev); |
| 239 | |
Jyri Sarha | 923310b | 2016-10-17 17:53:33 +0300 | [diff] [blame] | 240 | ddev->dev_private = priv; |
Jyri Sarha | 9e79e06 | 2016-10-18 23:23:27 +0300 | [diff] [blame] | 241 | platform_set_drvdata(pdev, ddev); |
| 242 | drm_mode_config_init(ddev); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 243 | |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 244 | priv->is_componentized = |
Jyri Sarha | 923310b | 2016-10-17 17:53:33 +0300 | [diff] [blame] | 245 | tilcdc_get_external_components(dev, NULL) > 0; |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 246 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 247 | priv->wq = alloc_ordered_workqueue("tilcdc", 0); |
Ezequiel Garcia | b478e336b | 2014-09-02 09:51:15 -0300 | [diff] [blame] | 248 | if (!priv->wq) { |
| 249 | ret = -ENOMEM; |
Jyri Sarha | 9e79e06 | 2016-10-18 23:23:27 +0300 | [diff] [blame] | 250 | goto init_failed; |
Ezequiel Garcia | b478e336b | 2014-09-02 09:51:15 -0300 | [diff] [blame] | 251 | } |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 252 | |
| 253 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 254 | if (!res) { |
Jyri Sarha | 923310b | 2016-10-17 17:53:33 +0300 | [diff] [blame] | 255 | dev_err(dev, "failed to get memory resource\n"); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 256 | ret = -EINVAL; |
Jyri Sarha | 9e79e06 | 2016-10-18 23:23:27 +0300 | [diff] [blame] | 257 | goto init_failed; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | priv->mmio = ioremap_nocache(res->start, resource_size(res)); |
| 261 | if (!priv->mmio) { |
Jyri Sarha | 923310b | 2016-10-17 17:53:33 +0300 | [diff] [blame] | 262 | dev_err(dev, "failed to ioremap\n"); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 263 | ret = -ENOMEM; |
Jyri Sarha | 9e79e06 | 2016-10-18 23:23:27 +0300 | [diff] [blame] | 264 | goto init_failed; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 265 | } |
| 266 | |
Jyri Sarha | 923310b | 2016-10-17 17:53:33 +0300 | [diff] [blame] | 267 | priv->clk = clk_get(dev, "fck"); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 268 | if (IS_ERR(priv->clk)) { |
Jyri Sarha | 923310b | 2016-10-17 17:53:33 +0300 | [diff] [blame] | 269 | dev_err(dev, "failed to get functional clock\n"); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 270 | ret = -ENODEV; |
Jyri Sarha | 9e79e06 | 2016-10-18 23:23:27 +0300 | [diff] [blame] | 271 | goto init_failed; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 272 | } |
| 273 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 274 | if (of_property_read_u32(node, "max-bandwidth", &priv->max_bandwidth)) |
Darren Etheridge | 4e56434 | 2013-06-21 13:52:23 -0500 | [diff] [blame] | 275 | priv->max_bandwidth = TILCDC_DEFAULT_MAX_BANDWIDTH; |
| 276 | |
| 277 | DBG("Maximum Bandwidth Value %d", priv->max_bandwidth); |
| 278 | |
Bartosz Golaszewski | 0186fcc | 2016-11-28 12:37:23 +0100 | [diff] [blame] | 279 | if (of_property_read_u32(node, "max-width", &priv->max_width)) |
Darren Etheridge | 4e56434 | 2013-06-21 13:52:23 -0500 | [diff] [blame] | 280 | priv->max_width = TILCDC_DEFAULT_MAX_WIDTH; |
| 281 | |
| 282 | DBG("Maximum Horizontal Pixel Width Value %dpixels", priv->max_width); |
| 283 | |
Bartosz Golaszewski | 0186fcc | 2016-11-28 12:37:23 +0100 | [diff] [blame] | 284 | if (of_property_read_u32(node, "max-pixelclock", |
Darren Etheridge | 4e56434 | 2013-06-21 13:52:23 -0500 | [diff] [blame] | 285 | &priv->max_pixelclock)) |
| 286 | priv->max_pixelclock = TILCDC_DEFAULT_MAX_PIXELCLOCK; |
| 287 | |
| 288 | DBG("Maximum Pixel Clock Value %dKHz", priv->max_pixelclock); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 289 | |
Jyri Sarha | 923310b | 2016-10-17 17:53:33 +0300 | [diff] [blame] | 290 | pm_runtime_enable(dev); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 291 | |
| 292 | /* Determine LCD IP Version */ |
Jyri Sarha | 923310b | 2016-10-17 17:53:33 +0300 | [diff] [blame] | 293 | pm_runtime_get_sync(dev); |
| 294 | switch (tilcdc_read(ddev, LCDC_PID_REG)) { |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 295 | case 0x4c100102: |
| 296 | priv->rev = 1; |
| 297 | break; |
| 298 | case 0x4f200800: |
| 299 | case 0x4f201000: |
| 300 | priv->rev = 2; |
| 301 | break; |
| 302 | default: |
Jyri Sarha | 923310b | 2016-10-17 17:53:33 +0300 | [diff] [blame] | 303 | dev_warn(dev, "Unknown PID Reg value 0x%08x, " |
| 304 | "defaulting to LCD revision 1\n", |
| 305 | tilcdc_read(ddev, LCDC_PID_REG)); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 306 | priv->rev = 1; |
| 307 | break; |
| 308 | } |
| 309 | |
Jyri Sarha | 923310b | 2016-10-17 17:53:33 +0300 | [diff] [blame] | 310 | pm_runtime_put_sync(dev); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 311 | |
Jyri Sarha | bcc5a6f | 2016-08-11 19:09:43 +0300 | [diff] [blame] | 312 | if (priv->rev == 1) { |
| 313 | DBG("Revision 1 LCDC supports only RGB565 format"); |
| 314 | priv->pixelformats = tilcdc_rev1_formats; |
| 315 | priv->num_pixelformats = ARRAY_SIZE(tilcdc_rev1_formats); |
Jyri Sarha | c566538 | 2016-08-13 21:08:20 +0300 | [diff] [blame] | 316 | bpp = 16; |
Jyri Sarha | bcc5a6f | 2016-08-11 19:09:43 +0300 | [diff] [blame] | 317 | } else { |
| 318 | const char *str = "\0"; |
| 319 | |
| 320 | of_property_read_string(node, "blue-and-red-wiring", &str); |
| 321 | if (0 == strcmp(str, "crossed")) { |
| 322 | DBG("Configured for crossed blue and red wires"); |
| 323 | priv->pixelformats = tilcdc_crossed_formats; |
| 324 | priv->num_pixelformats = |
| 325 | ARRAY_SIZE(tilcdc_crossed_formats); |
Jyri Sarha | c566538 | 2016-08-13 21:08:20 +0300 | [diff] [blame] | 326 | bpp = 32; /* Choose bpp with RGB support for fbdef */ |
Jyri Sarha | bcc5a6f | 2016-08-11 19:09:43 +0300 | [diff] [blame] | 327 | } else if (0 == strcmp(str, "straight")) { |
| 328 | DBG("Configured for straight blue and red wires"); |
| 329 | priv->pixelformats = tilcdc_straight_formats; |
| 330 | priv->num_pixelformats = |
| 331 | ARRAY_SIZE(tilcdc_straight_formats); |
Jyri Sarha | c566538 | 2016-08-13 21:08:20 +0300 | [diff] [blame] | 332 | bpp = 16; /* Choose bpp with RGB support for fbdef */ |
Jyri Sarha | bcc5a6f | 2016-08-11 19:09:43 +0300 | [diff] [blame] | 333 | } else { |
| 334 | DBG("Blue and red wiring '%s' unknown, use legacy mode", |
| 335 | str); |
| 336 | priv->pixelformats = tilcdc_legacy_formats; |
| 337 | priv->num_pixelformats = |
| 338 | ARRAY_SIZE(tilcdc_legacy_formats); |
Jyri Sarha | c566538 | 2016-08-13 21:08:20 +0300 | [diff] [blame] | 339 | bpp = 16; /* This is just a guess */ |
Jyri Sarha | bcc5a6f | 2016-08-11 19:09:43 +0300 | [diff] [blame] | 340 | } |
| 341 | } |
| 342 | |
Jyri Sarha | 9963d36 | 2016-11-15 22:56:46 +0200 | [diff] [blame] | 343 | ret = tilcdc_crtc_create(ddev); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 344 | if (ret < 0) { |
Jyri Sarha | 9963d36 | 2016-11-15 22:56:46 +0200 | [diff] [blame] | 345 | dev_err(dev, "failed to create crtc\n"); |
Jyri Sarha | 9e79e06 | 2016-10-18 23:23:27 +0300 | [diff] [blame] | 346 | goto init_failed; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 347 | } |
Jyri Sarha | 9963d36 | 2016-11-15 22:56:46 +0200 | [diff] [blame] | 348 | modeset_init(ddev); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 349 | |
Jyri Sarha | 432973f | 2018-12-12 19:26:32 +0200 | [diff] [blame] | 350 | #ifdef CONFIG_CPU_FREQ |
| 351 | priv->freq_transition.notifier_call = cpufreq_transition; |
| 352 | ret = cpufreq_register_notifier(&priv->freq_transition, |
| 353 | CPUFREQ_TRANSITION_NOTIFIER); |
| 354 | if (ret) { |
| 355 | dev_err(dev, "failed to register cpufreq notifier\n"); |
| 356 | priv->freq_transition.notifier_call = NULL; |
| 357 | goto init_failed; |
| 358 | } |
| 359 | #endif |
| 360 | |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 361 | if (priv->is_componentized) { |
Jyri Sarha | 923310b | 2016-10-17 17:53:33 +0300 | [diff] [blame] | 362 | ret = component_bind_all(dev, ddev); |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 363 | if (ret < 0) |
Jyri Sarha | 9e79e06 | 2016-10-18 23:23:27 +0300 | [diff] [blame] | 364 | goto init_failed; |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 365 | |
Jyri Sarha | ec9eab0 | 2016-10-31 17:34:22 +0200 | [diff] [blame] | 366 | ret = tilcdc_add_component_encoder(ddev); |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 367 | if (ret < 0) |
Jyri Sarha | 9e79e06 | 2016-10-18 23:23:27 +0300 | [diff] [blame] | 368 | goto init_failed; |
Jyri Sarha | ec9eab0 | 2016-10-31 17:34:22 +0200 | [diff] [blame] | 369 | } else { |
| 370 | ret = tilcdc_attach_external_device(ddev); |
| 371 | if (ret) |
| 372 | goto init_failed; |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 373 | } |
| 374 | |
Jyri Sarha | ec9eab0 | 2016-10-31 17:34:22 +0200 | [diff] [blame] | 375 | if (!priv->external_connector && |
| 376 | ((priv->num_encoders == 0) || (priv->num_connectors == 0))) { |
Jyri Sarha | 923310b | 2016-10-17 17:53:33 +0300 | [diff] [blame] | 377 | dev_err(dev, "no encoders/connectors found\n"); |
Sjoerd Simons | a132b5a | 2018-03-30 15:15:53 +0200 | [diff] [blame] | 378 | ret = -EPROBE_DEFER; |
Jyri Sarha | 9e79e06 | 2016-10-18 23:23:27 +0300 | [diff] [blame] | 379 | goto init_failed; |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 380 | } |
| 381 | |
Jyri Sarha | 923310b | 2016-10-17 17:53:33 +0300 | [diff] [blame] | 382 | ret = drm_vblank_init(ddev, 1); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 383 | if (ret < 0) { |
Jyri Sarha | 923310b | 2016-10-17 17:53:33 +0300 | [diff] [blame] | 384 | dev_err(dev, "failed to initialize vblank\n"); |
Jyri Sarha | 9e79e06 | 2016-10-18 23:23:27 +0300 | [diff] [blame] | 385 | goto init_failed; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 386 | } |
| 387 | |
Jyri Sarha | 923310b | 2016-10-17 17:53:33 +0300 | [diff] [blame] | 388 | ret = drm_irq_install(ddev, platform_get_irq(pdev, 0)); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 389 | if (ret < 0) { |
Jyri Sarha | 923310b | 2016-10-17 17:53:33 +0300 | [diff] [blame] | 390 | dev_err(dev, "failed to install IRQ handler\n"); |
Jyri Sarha | 9e79e06 | 2016-10-18 23:23:27 +0300 | [diff] [blame] | 391 | goto init_failed; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 392 | } |
| 393 | |
Jyri Sarha | 923310b | 2016-10-17 17:53:33 +0300 | [diff] [blame] | 394 | drm_mode_config_reset(ddev); |
Jyri Sarha | 522a76f | 2015-12-29 17:27:32 +0200 | [diff] [blame] | 395 | |
Jyri Sarha | 923310b | 2016-10-17 17:53:33 +0300 | [diff] [blame] | 396 | drm_kms_helper_poll_init(ddev); |
| 397 | |
| 398 | ret = drm_dev_register(ddev, 0); |
| 399 | if (ret) |
Jyri Sarha | 9e79e06 | 2016-10-18 23:23:27 +0300 | [diff] [blame] | 400 | goto init_failed; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 401 | |
Noralf Trønnes | 45cf875 | 2018-10-25 22:13:39 +0200 | [diff] [blame] | 402 | drm_fbdev_generic_setup(ddev, bpp); |
| 403 | |
Jyri Sarha | 9e79e06 | 2016-10-18 23:23:27 +0300 | [diff] [blame] | 404 | priv->is_registered = true; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 405 | return 0; |
| 406 | |
Jyri Sarha | 9e79e06 | 2016-10-18 23:23:27 +0300 | [diff] [blame] | 407 | init_failed: |
| 408 | tilcdc_fini(ddev); |
Jyri Sarha | d0ec32c | 2016-02-23 12:44:27 +0200 | [diff] [blame] | 409 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 410 | return ret; |
| 411 | } |
| 412 | |
Daniel Vetter | e9f0d76 | 2013-12-11 11:34:42 +0100 | [diff] [blame] | 413 | static irqreturn_t tilcdc_irq(int irq, void *arg) |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 414 | { |
| 415 | struct drm_device *dev = arg; |
| 416 | struct tilcdc_drm_private *priv = dev->dev_private; |
| 417 | return tilcdc_crtc_irq(priv->crtc); |
| 418 | } |
| 419 | |
Jyri Sarha | 514d1a1 | 2016-06-16 11:28:23 +0300 | [diff] [blame] | 420 | #if defined(CONFIG_DEBUG_FS) |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 421 | static const struct { |
| 422 | const char *name; |
| 423 | uint8_t rev; |
| 424 | uint8_t save; |
| 425 | uint32_t reg; |
Sachin Kamat | 3250145 | 2013-03-02 15:53:08 +0530 | [diff] [blame] | 426 | } registers[] = { |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 427 | #define REG(rev, save, reg) { #reg, rev, save, reg } |
| 428 | /* exists in revision 1: */ |
| 429 | REG(1, false, LCDC_PID_REG), |
| 430 | REG(1, true, LCDC_CTRL_REG), |
| 431 | REG(1, false, LCDC_STAT_REG), |
| 432 | REG(1, true, LCDC_RASTER_CTRL_REG), |
| 433 | REG(1, true, LCDC_RASTER_TIMING_0_REG), |
| 434 | REG(1, true, LCDC_RASTER_TIMING_1_REG), |
| 435 | REG(1, true, LCDC_RASTER_TIMING_2_REG), |
| 436 | REG(1, true, LCDC_DMA_CTRL_REG), |
| 437 | REG(1, true, LCDC_DMA_FB_BASE_ADDR_0_REG), |
| 438 | REG(1, true, LCDC_DMA_FB_CEILING_ADDR_0_REG), |
| 439 | REG(1, true, LCDC_DMA_FB_BASE_ADDR_1_REG), |
| 440 | REG(1, true, LCDC_DMA_FB_CEILING_ADDR_1_REG), |
| 441 | /* new in revision 2: */ |
| 442 | REG(2, false, LCDC_RAW_STAT_REG), |
| 443 | REG(2, false, LCDC_MASKED_STAT_REG), |
Jyri Sarha | f3a9994 | 2016-01-08 12:17:50 +0200 | [diff] [blame] | 444 | REG(2, true, LCDC_INT_ENABLE_SET_REG), |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 445 | REG(2, false, LCDC_INT_ENABLE_CLR_REG), |
| 446 | REG(2, false, LCDC_END_OF_INT_IND_REG), |
| 447 | REG(2, true, LCDC_CLK_ENABLE_REG), |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 448 | #undef REG |
| 449 | }; |
Jyri Sarha | 29ddd6e | 2015-07-02 16:26:12 +0300 | [diff] [blame] | 450 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 451 | #endif |
| 452 | |
| 453 | #ifdef CONFIG_DEBUG_FS |
| 454 | static int tilcdc_regs_show(struct seq_file *m, void *arg) |
| 455 | { |
| 456 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 457 | struct drm_device *dev = node->minor->dev; |
| 458 | struct tilcdc_drm_private *priv = dev->dev_private; |
| 459 | unsigned i; |
| 460 | |
| 461 | pm_runtime_get_sync(dev->dev); |
| 462 | |
| 463 | seq_printf(m, "revision: %d\n", priv->rev); |
| 464 | |
| 465 | for (i = 0; i < ARRAY_SIZE(registers); i++) |
| 466 | if (priv->rev >= registers[i].rev) |
| 467 | seq_printf(m, "%s:\t %08x\n", registers[i].name, |
| 468 | tilcdc_read(dev, registers[i].reg)); |
| 469 | |
| 470 | pm_runtime_put_sync(dev->dev); |
| 471 | |
| 472 | return 0; |
| 473 | } |
| 474 | |
| 475 | static int tilcdc_mm_show(struct seq_file *m, void *arg) |
| 476 | { |
| 477 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 478 | struct drm_device *dev = node->minor->dev; |
Daniel Vetter | b5c3714 | 2016-12-29 12:09:24 +0100 | [diff] [blame] | 479 | struct drm_printer p = drm_seq_file_printer(m); |
| 480 | drm_mm_print(&dev->vma_offset_manager->vm_addr_space_mm, &p); |
| 481 | return 0; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | static struct drm_info_list tilcdc_debugfs_list[] = { |
| 485 | { "regs", tilcdc_regs_show, 0 }, |
| 486 | { "mm", tilcdc_mm_show, 0 }, |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 487 | }; |
| 488 | |
| 489 | static int tilcdc_debugfs_init(struct drm_minor *minor) |
| 490 | { |
| 491 | struct drm_device *dev = minor->dev; |
| 492 | struct tilcdc_module *mod; |
| 493 | int ret; |
| 494 | |
| 495 | ret = drm_debugfs_create_files(tilcdc_debugfs_list, |
| 496 | ARRAY_SIZE(tilcdc_debugfs_list), |
| 497 | minor->debugfs_root, minor); |
| 498 | |
| 499 | list_for_each_entry(mod, &module_list, list) |
| 500 | if (mod->funcs->debugfs_init) |
| 501 | mod->funcs->debugfs_init(mod, minor); |
| 502 | |
| 503 | if (ret) { |
| 504 | dev_err(dev->dev, "could not install tilcdc_debugfs_list\n"); |
| 505 | return ret; |
| 506 | } |
| 507 | |
| 508 | return ret; |
| 509 | } |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 510 | #endif |
| 511 | |
Daniel Vetter | d55f7e5 | 2017-03-08 15:12:56 +0100 | [diff] [blame] | 512 | DEFINE_DRM_GEM_CMA_FOPS(fops); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 513 | |
| 514 | static struct drm_driver tilcdc_driver = { |
Daniel Vetter | 5b38e74 | 2019-01-29 11:42:46 +0100 | [diff] [blame] | 515 | .driver_features = (DRIVER_GEM | DRIVER_MODESET | |
Jyri Sarha | 305198d | 2016-04-07 15:05:16 +0300 | [diff] [blame] | 516 | DRIVER_PRIME | DRIVER_ATOMIC), |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 517 | .irq_handler = tilcdc_irq, |
Daniel Vetter | aa0438c | 2016-05-30 19:53:05 +0200 | [diff] [blame] | 518 | .gem_free_object_unlocked = drm_gem_cma_free_object, |
Noralf Trønnes | fbf65b7 | 2017-11-07 20:13:46 +0100 | [diff] [blame] | 519 | .gem_print_info = drm_gem_cma_print_info, |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 520 | .gem_vm_ops = &drm_gem_cma_vm_ops, |
| 521 | .dumb_create = drm_gem_cma_dumb_create, |
Jyri Sarha | 9c15390 | 2015-06-23 14:31:17 +0300 | [diff] [blame] | 522 | |
| 523 | .prime_handle_to_fd = drm_gem_prime_handle_to_fd, |
| 524 | .prime_fd_to_handle = drm_gem_prime_fd_to_handle, |
| 525 | .gem_prime_import = drm_gem_prime_import, |
| 526 | .gem_prime_export = drm_gem_prime_export, |
| 527 | .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table, |
| 528 | .gem_prime_import_sg_table = drm_gem_cma_prime_import_sg_table, |
| 529 | .gem_prime_vmap = drm_gem_cma_prime_vmap, |
| 530 | .gem_prime_vunmap = drm_gem_cma_prime_vunmap, |
| 531 | .gem_prime_mmap = drm_gem_cma_prime_mmap, |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 532 | #ifdef CONFIG_DEBUG_FS |
| 533 | .debugfs_init = tilcdc_debugfs_init, |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 534 | #endif |
| 535 | .fops = &fops, |
| 536 | .name = "tilcdc", |
| 537 | .desc = "TI LCD Controller DRM", |
| 538 | .date = "20121205", |
| 539 | .major = 1, |
| 540 | .minor = 0, |
| 541 | }; |
| 542 | |
| 543 | /* |
| 544 | * Power management: |
| 545 | */ |
| 546 | |
| 547 | #ifdef CONFIG_PM_SLEEP |
| 548 | static int tilcdc_pm_suspend(struct device *dev) |
| 549 | { |
| 550 | struct drm_device *ddev = dev_get_drvdata(dev); |
Souptick Joarder | 4fdce78 | 2018-08-08 21:46:41 +0530 | [diff] [blame] | 551 | int ret = 0; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 552 | |
Souptick Joarder | 4fdce78 | 2018-08-08 21:46:41 +0530 | [diff] [blame] | 553 | ret = drm_mode_config_helper_suspend(ddev); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 554 | |
Darren Etheridge | 85fd27f | 2014-09-19 01:42:57 +0000 | [diff] [blame] | 555 | /* Select sleep pin state */ |
| 556 | pinctrl_pm_select_sleep_state(dev); |
| 557 | |
Souptick Joarder | 4fdce78 | 2018-08-08 21:46:41 +0530 | [diff] [blame] | 558 | return ret; |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | static int tilcdc_pm_resume(struct device *dev) |
| 562 | { |
| 563 | struct drm_device *ddev = dev_get_drvdata(dev); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 564 | |
Dave Gerlach | 416a07f | 2014-07-29 06:27:58 +0000 | [diff] [blame] | 565 | /* Select default pin state */ |
| 566 | pinctrl_pm_select_default_state(dev); |
Souptick Joarder | 4fdce78 | 2018-08-08 21:46:41 +0530 | [diff] [blame] | 567 | return drm_mode_config_helper_resume(ddev); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 568 | } |
| 569 | #endif |
| 570 | |
| 571 | static const struct dev_pm_ops tilcdc_pm_ops = { |
| 572 | SET_SYSTEM_SLEEP_PM_OPS(tilcdc_pm_suspend, tilcdc_pm_resume) |
| 573 | }; |
| 574 | |
| 575 | /* |
| 576 | * Platform driver: |
| 577 | */ |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 578 | static int tilcdc_bind(struct device *dev) |
| 579 | { |
Jyri Sarha | 923310b | 2016-10-17 17:53:33 +0300 | [diff] [blame] | 580 | return tilcdc_init(&tilcdc_driver, dev); |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | static void tilcdc_unbind(struct device *dev) |
| 584 | { |
Jyri Sarha | 20a98ac | 2016-06-23 11:07:16 +0300 | [diff] [blame] | 585 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 586 | |
| 587 | /* Check if a subcomponent has already triggered the unloading. */ |
| 588 | if (!ddev->dev_private) |
| 589 | return; |
| 590 | |
Jyri Sarha | 923310b | 2016-10-17 17:53:33 +0300 | [diff] [blame] | 591 | tilcdc_fini(dev_get_drvdata(dev)); |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | static const struct component_master_ops tilcdc_comp_ops = { |
| 595 | .bind = tilcdc_bind, |
| 596 | .unbind = tilcdc_unbind, |
| 597 | }; |
| 598 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 599 | static int tilcdc_pdev_probe(struct platform_device *pdev) |
| 600 | { |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 601 | struct component_match *match = NULL; |
| 602 | int ret; |
| 603 | |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 604 | /* bail out early if no DT data: */ |
| 605 | if (!pdev->dev.of_node) { |
| 606 | dev_err(&pdev->dev, "device-tree data is missing\n"); |
| 607 | return -ENXIO; |
| 608 | } |
| 609 | |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 610 | ret = tilcdc_get_external_components(&pdev->dev, &match); |
| 611 | if (ret < 0) |
| 612 | return ret; |
| 613 | else if (ret == 0) |
Jyri Sarha | 923310b | 2016-10-17 17:53:33 +0300 | [diff] [blame] | 614 | return tilcdc_init(&tilcdc_driver, &pdev->dev); |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 615 | else |
| 616 | return component_master_add_with_match(&pdev->dev, |
| 617 | &tilcdc_comp_ops, |
| 618 | match); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | static int tilcdc_pdev_remove(struct platform_device *pdev) |
| 622 | { |
Jyri Sarha | 20a98ac | 2016-06-23 11:07:16 +0300 | [diff] [blame] | 623 | int ret; |
Jyri Sarha | 103cd8b | 2015-02-10 14:13:23 +0200 | [diff] [blame] | 624 | |
Jyri Sarha | 20a98ac | 2016-06-23 11:07:16 +0300 | [diff] [blame] | 625 | ret = tilcdc_get_external_components(&pdev->dev, NULL); |
| 626 | if (ret < 0) |
| 627 | return ret; |
| 628 | else if (ret == 0) |
Jyri Sarha | 923310b | 2016-10-17 17:53:33 +0300 | [diff] [blame] | 629 | tilcdc_fini(platform_get_drvdata(pdev)); |
Jyri Sarha | 20a98ac | 2016-06-23 11:07:16 +0300 | [diff] [blame] | 630 | else |
| 631 | component_master_del(&pdev->dev, &tilcdc_comp_ops); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 632 | |
| 633 | return 0; |
| 634 | } |
| 635 | |
| 636 | static struct of_device_id tilcdc_of_match[] = { |
| 637 | { .compatible = "ti,am33xx-tilcdc", }, |
Bartosz Golaszewski | 507b72b | 2016-10-03 17:45:19 +0200 | [diff] [blame] | 638 | { .compatible = "ti,da850-tilcdc", }, |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 639 | { }, |
| 640 | }; |
| 641 | MODULE_DEVICE_TABLE(of, tilcdc_of_match); |
| 642 | |
| 643 | static struct platform_driver tilcdc_platform_driver = { |
| 644 | .probe = tilcdc_pdev_probe, |
| 645 | .remove = tilcdc_pdev_remove, |
| 646 | .driver = { |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 647 | .name = "tilcdc", |
| 648 | .pm = &tilcdc_pm_ops, |
| 649 | .of_match_table = tilcdc_of_match, |
| 650 | }, |
| 651 | }; |
| 652 | |
| 653 | static int __init tilcdc_drm_init(void) |
| 654 | { |
| 655 | DBG("init"); |
| 656 | tilcdc_tfp410_init(); |
Rob Clark | 0d4bbaf | 2012-12-18 17:34:16 -0600 | [diff] [blame] | 657 | tilcdc_panel_init(); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 658 | return platform_driver_register(&tilcdc_platform_driver); |
| 659 | } |
| 660 | |
| 661 | static void __exit tilcdc_drm_fini(void) |
| 662 | { |
| 663 | DBG("fini"); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 664 | platform_driver_unregister(&tilcdc_platform_driver); |
Guido Martínez | eb565a2 | 2014-06-17 11:17:08 -0300 | [diff] [blame] | 665 | tilcdc_panel_fini(); |
Guido Martínez | eb565a2 | 2014-06-17 11:17:08 -0300 | [diff] [blame] | 666 | tilcdc_tfp410_fini(); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 667 | } |
| 668 | |
Guido Martínez | 2023d84 | 2014-06-17 11:17:11 -0300 | [diff] [blame] | 669 | module_init(tilcdc_drm_init); |
Rob Clark | 16ea975 | 2013-01-08 15:04:28 -0600 | [diff] [blame] | 670 | module_exit(tilcdc_drm_fini); |
| 671 | |
| 672 | MODULE_AUTHOR("Rob Clark <robdclark@gmail.com"); |
| 673 | MODULE_DESCRIPTION("TI LCD Controller DRM Driver"); |
| 674 | MODULE_LICENSE("GPL"); |