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