linux/drivers/video/omap2/dss/core.c
<<
>>
Prefs
   1/*
   2 * linux/drivers/video/omap2/dss/core.c
   3 *
   4 * Copyright (C) 2009 Nokia Corporation
   5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
   6 *
   7 * Some code and ideas taken from drivers/video/omap/ driver
   8 * by Imre Deak.
   9 *
  10 * This program is free software; you can redistribute it and/or modify it
  11 * under the terms of the GNU General Public License version 2 as published by
  12 * the Free Software Foundation.
  13 *
  14 * This program is distributed in the hope that it will be useful, but WITHOUT
  15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  17 * more details.
  18 *
  19 * You should have received a copy of the GNU General Public License along with
  20 * this program.  If not, see <http://www.gnu.org/licenses/>.
  21 */
  22
  23#define DSS_SUBSYS_NAME "CORE"
  24
  25#include <linux/kernel.h>
  26#include <linux/module.h>
  27#include <linux/clk.h>
  28#include <linux/err.h>
  29#include <linux/platform_device.h>
  30#include <linux/seq_file.h>
  31#include <linux/debugfs.h>
  32#include <linux/io.h>
  33#include <linux/device.h>
  34#include <linux/regulator/consumer.h>
  35#include <linux/suspend.h>
  36#include <linux/slab.h>
  37
  38#include <video/omapdss.h>
  39
  40#include "dss.h"
  41#include "dss_features.h"
  42
  43static struct {
  44        struct platform_device *pdev;
  45
  46        struct regulator *vdds_dsi_reg;
  47        struct regulator *vdds_sdi_reg;
  48
  49        const char *default_display_name;
  50} core;
  51
  52static char *def_disp_name;
  53module_param_named(def_disp, def_disp_name, charp, 0);
  54MODULE_PARM_DESC(def_disp, "default display name");
  55
  56static bool dss_initialized;
  57
  58const char *omapdss_get_default_display_name(void)
  59{
  60        return core.default_display_name;
  61}
  62EXPORT_SYMBOL(omapdss_get_default_display_name);
  63
  64enum omapdss_version omapdss_get_version(void)
  65{
  66        struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
  67        return pdata->version;
  68}
  69EXPORT_SYMBOL(omapdss_get_version);
  70
  71bool omapdss_is_initialized(void)
  72{
  73        return dss_initialized;
  74}
  75EXPORT_SYMBOL(omapdss_is_initialized);
  76
  77struct platform_device *dss_get_core_pdev(void)
  78{
  79        return core.pdev;
  80}
  81
  82/* REGULATORS */
  83
  84struct regulator *dss_get_vdds_dsi(void)
  85{
  86        struct regulator *reg;
  87
  88        if (core.vdds_dsi_reg != NULL)
  89                return core.vdds_dsi_reg;
  90
  91        reg = devm_regulator_get(&core.pdev->dev, "vdds_dsi");
  92        if (!IS_ERR(reg))
  93                core.vdds_dsi_reg = reg;
  94
  95        return reg;
  96}
  97
  98struct regulator *dss_get_vdds_sdi(void)
  99{
 100        struct regulator *reg;
 101
 102        if (core.vdds_sdi_reg != NULL)
 103                return core.vdds_sdi_reg;
 104
 105        reg = devm_regulator_get(&core.pdev->dev, "vdds_sdi");
 106        if (!IS_ERR(reg))
 107                core.vdds_sdi_reg = reg;
 108
 109        return reg;
 110}
 111
 112int dss_dsi_enable_pads(int dsi_id, unsigned lane_mask)
 113{
 114        struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
 115
 116        if (!board_data->dsi_enable_pads)
 117                return -ENOENT;
 118
 119        return board_data->dsi_enable_pads(dsi_id, lane_mask);
 120}
 121
 122void dss_dsi_disable_pads(int dsi_id, unsigned lane_mask)
 123{
 124        struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
 125
 126        if (!board_data->dsi_disable_pads)
 127                return;
 128
 129        return board_data->dsi_disable_pads(dsi_id, lane_mask);
 130}
 131
 132int dss_set_min_bus_tput(struct device *dev, unsigned long tput)
 133{
 134        struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
 135
 136        if (pdata->set_min_bus_tput)
 137                return pdata->set_min_bus_tput(dev, tput);
 138        else
 139                return 0;
 140}
 141
 142#if defined(CONFIG_OMAP2_DSS_DEBUGFS)
 143static int dss_debug_show(struct seq_file *s, void *unused)
 144{
 145        void (*func)(struct seq_file *) = s->private;
 146        func(s);
 147        return 0;
 148}
 149
 150static int dss_debug_open(struct inode *inode, struct file *file)
 151{
 152        return single_open(file, dss_debug_show, inode->i_private);
 153}
 154
 155static const struct file_operations dss_debug_fops = {
 156        .open           = dss_debug_open,
 157        .read           = seq_read,
 158        .llseek         = seq_lseek,
 159        .release        = single_release,
 160};
 161
 162static struct dentry *dss_debugfs_dir;
 163
 164static int dss_initialize_debugfs(void)
 165{
 166        dss_debugfs_dir = debugfs_create_dir("omapdss", NULL);
 167        if (IS_ERR(dss_debugfs_dir)) {
 168                int err = PTR_ERR(dss_debugfs_dir);
 169                dss_debugfs_dir = NULL;
 170                return err;
 171        }
 172
 173        debugfs_create_file("clk", S_IRUGO, dss_debugfs_dir,
 174                        &dss_debug_dump_clocks, &dss_debug_fops);
 175
 176        return 0;
 177}
 178
 179static void dss_uninitialize_debugfs(void)
 180{
 181        if (dss_debugfs_dir)
 182                debugfs_remove_recursive(dss_debugfs_dir);
 183}
 184
 185int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
 186{
 187        struct dentry *d;
 188
 189        d = debugfs_create_file(name, S_IRUGO, dss_debugfs_dir,
 190                        write, &dss_debug_fops);
 191
 192        return PTR_RET(d);
 193}
 194#else /* CONFIG_OMAP2_DSS_DEBUGFS */
 195static inline int dss_initialize_debugfs(void)
 196{
 197        return 0;
 198}
 199static inline void dss_uninitialize_debugfs(void)
 200{
 201}
 202int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
 203{
 204        return 0;
 205}
 206#endif /* CONFIG_OMAP2_DSS_DEBUGFS */
 207
 208/* PLATFORM DEVICE */
 209static int omap_dss_pm_notif(struct notifier_block *b, unsigned long v, void *d)
 210{
 211        DSSDBG("pm notif %lu\n", v);
 212
 213        switch (v) {
 214        case PM_SUSPEND_PREPARE:
 215                DSSDBG("suspending displays\n");
 216                return dss_suspend_all_devices();
 217
 218        case PM_POST_SUSPEND:
 219                DSSDBG("resuming displays\n");
 220                return dss_resume_all_devices();
 221
 222        default:
 223                return 0;
 224        }
 225}
 226
 227static struct notifier_block omap_dss_pm_notif_block = {
 228        .notifier_call = omap_dss_pm_notif,
 229};
 230
 231static int __init omap_dss_probe(struct platform_device *pdev)
 232{
 233        struct omap_dss_board_info *pdata = pdev->dev.platform_data;
 234        int r;
 235
 236        core.pdev = pdev;
 237
 238        dss_features_init(omapdss_get_version());
 239
 240        r = dss_initialize_debugfs();
 241        if (r)
 242                goto err_debugfs;
 243
 244        if (def_disp_name)
 245                core.default_display_name = def_disp_name;
 246        else if (pdata->default_display_name)
 247                core.default_display_name = pdata->default_display_name;
 248        else if (pdata->default_device)
 249                core.default_display_name = pdata->default_device->name;
 250
 251        register_pm_notifier(&omap_dss_pm_notif_block);
 252
 253        return 0;
 254
 255err_debugfs:
 256
 257        return r;
 258}
 259
 260static int omap_dss_remove(struct platform_device *pdev)
 261{
 262        unregister_pm_notifier(&omap_dss_pm_notif_block);
 263
 264        dss_uninitialize_debugfs();
 265
 266        return 0;
 267}
 268
 269static void omap_dss_shutdown(struct platform_device *pdev)
 270{
 271        DSSDBG("shutdown\n");
 272        dss_disable_all_devices();
 273}
 274
 275static struct platform_driver omap_dss_driver = {
 276        .remove         = omap_dss_remove,
 277        .shutdown       = omap_dss_shutdown,
 278        .driver         = {
 279                .name   = "omapdss",
 280                .owner  = THIS_MODULE,
 281        },
 282};
 283
 284/* BUS */
 285static int dss_bus_match(struct device *dev, struct device_driver *driver)
 286{
 287        struct omap_dss_device *dssdev = to_dss_device(dev);
 288
 289        DSSDBG("bus_match. dev %s/%s, drv %s\n",
 290                        dev_name(dev), dssdev->driver_name, driver->name);
 291
 292        return strcmp(dssdev->driver_name, driver->name) == 0;
 293}
 294
 295static struct bus_type dss_bus_type = {
 296        .name = "omapdss",
 297        .match = dss_bus_match,
 298};
 299
 300static void dss_bus_release(struct device *dev)
 301{
 302        DSSDBG("bus_release\n");
 303}
 304
 305static struct device dss_bus = {
 306        .release = dss_bus_release,
 307};
 308
 309struct bus_type *dss_get_bus(void)
 310{
 311        return &dss_bus_type;
 312}
 313
 314/* DRIVER */
 315static int dss_driver_probe(struct device *dev)
 316{
 317        int r;
 318        struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
 319        struct omap_dss_device *dssdev = to_dss_device(dev);
 320
 321        DSSDBG("driver_probe: dev %s/%s, drv %s\n",
 322                                dev_name(dev), dssdev->driver_name,
 323                                dssdrv->driver.name);
 324
 325        r = dssdrv->probe(dssdev);
 326
 327        if (r) {
 328                DSSERR("driver probe failed: %d\n", r);
 329                return r;
 330        }
 331
 332        DSSDBG("probe done for device %s\n", dev_name(dev));
 333
 334        dssdev->driver = dssdrv;
 335
 336        return 0;
 337}
 338
 339static int dss_driver_remove(struct device *dev)
 340{
 341        struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
 342        struct omap_dss_device *dssdev = to_dss_device(dev);
 343
 344        DSSDBG("driver_remove: dev %s/%s\n", dev_name(dev),
 345                        dssdev->driver_name);
 346
 347        dssdrv->remove(dssdev);
 348
 349        dssdev->driver = NULL;
 350
 351        return 0;
 352}
 353
 354static int omapdss_default_connect(struct omap_dss_device *dssdev)
 355{
 356        struct omap_dss_device *out;
 357        struct omap_overlay_manager *mgr;
 358        int r;
 359
 360        out = dssdev->output;
 361
 362        if (out == NULL)
 363                return -ENODEV;
 364
 365        mgr = omap_dss_get_overlay_manager(out->dispc_channel);
 366        if (!mgr)
 367                return -ENODEV;
 368
 369        r = dss_mgr_connect(mgr, out);
 370        if (r)
 371                return r;
 372
 373        return 0;
 374}
 375
 376static void omapdss_default_disconnect(struct omap_dss_device *dssdev)
 377{
 378        struct omap_dss_device *out;
 379        struct omap_overlay_manager *mgr;
 380
 381        out = dssdev->output;
 382
 383        if (out == NULL)
 384                return;
 385
 386        mgr = out->manager;
 387
 388        if (mgr == NULL)
 389                return;
 390
 391        dss_mgr_disconnect(mgr, out);
 392}
 393
 394int omap_dss_register_driver(struct omap_dss_driver *dssdriver)
 395{
 396        dssdriver->driver.bus = &dss_bus_type;
 397        dssdriver->driver.probe = dss_driver_probe;
 398        dssdriver->driver.remove = dss_driver_remove;
 399
 400        if (dssdriver->get_resolution == NULL)
 401                dssdriver->get_resolution = omapdss_default_get_resolution;
 402        if (dssdriver->get_recommended_bpp == NULL)
 403                dssdriver->get_recommended_bpp =
 404                        omapdss_default_get_recommended_bpp;
 405        if (dssdriver->get_timings == NULL)
 406                dssdriver->get_timings = omapdss_default_get_timings;
 407        if (dssdriver->connect == NULL)
 408                dssdriver->connect = omapdss_default_connect;
 409        if (dssdriver->disconnect == NULL)
 410                dssdriver->disconnect = omapdss_default_disconnect;
 411
 412        return driver_register(&dssdriver->driver);
 413}
 414EXPORT_SYMBOL(omap_dss_register_driver);
 415
 416void omap_dss_unregister_driver(struct omap_dss_driver *dssdriver)
 417{
 418        driver_unregister(&dssdriver->driver);
 419}
 420EXPORT_SYMBOL(omap_dss_unregister_driver);
 421
 422/* DEVICE */
 423
 424static void omap_dss_dev_release(struct device *dev)
 425{
 426        struct omap_dss_device *dssdev = to_dss_device(dev);
 427        kfree(dssdev);
 428}
 429
 430static int disp_num_counter;
 431
 432struct omap_dss_device *dss_alloc_and_init_device(struct device *parent)
 433{
 434        struct omap_dss_device *dssdev;
 435
 436        dssdev = kzalloc(sizeof(*dssdev), GFP_KERNEL);
 437        if (!dssdev)
 438                return NULL;
 439
 440        dssdev->old_dev.bus = &dss_bus_type;
 441        dssdev->old_dev.parent = parent;
 442        dssdev->old_dev.release = omap_dss_dev_release;
 443        dev_set_name(&dssdev->old_dev, "display%d", disp_num_counter++);
 444
 445        device_initialize(&dssdev->old_dev);
 446
 447        return dssdev;
 448}
 449
 450int dss_add_device(struct omap_dss_device *dssdev)
 451{
 452        dssdev->dev = &dssdev->old_dev;
 453
 454        omapdss_register_display(dssdev);
 455        return device_add(&dssdev->old_dev);
 456}
 457
 458void dss_put_device(struct omap_dss_device *dssdev)
 459{
 460        put_device(&dssdev->old_dev);
 461}
 462
 463void dss_unregister_device(struct omap_dss_device *dssdev)
 464{
 465        device_unregister(&dssdev->old_dev);
 466        omapdss_unregister_display(dssdev);
 467}
 468
 469static int dss_unregister_dss_dev(struct device *dev, void *data)
 470{
 471        struct omap_dss_device *dssdev = to_dss_device(dev);
 472        dss_unregister_device(dssdev);
 473        return 0;
 474}
 475
 476void dss_unregister_child_devices(struct device *parent)
 477{
 478        device_for_each_child(parent, NULL, dss_unregister_dss_dev);
 479}
 480
 481void dss_copy_device_pdata(struct omap_dss_device *dst,
 482                const struct omap_dss_device *src)
 483{
 484        u8 *d = (u8 *)dst;
 485        u8 *s = (u8 *)src;
 486        size_t dsize = sizeof(struct device);
 487
 488        memcpy(d + dsize, s + dsize, sizeof(struct omap_dss_device) - dsize);
 489}
 490
 491/* BUS */
 492static int __init omap_dss_bus_register(void)
 493{
 494        int r;
 495
 496        r = bus_register(&dss_bus_type);
 497        if (r) {
 498                DSSERR("bus register failed\n");
 499                return r;
 500        }
 501
 502        dev_set_name(&dss_bus, "omapdss");
 503        r = device_register(&dss_bus);
 504        if (r) {
 505                DSSERR("bus driver register failed\n");
 506                bus_unregister(&dss_bus_type);
 507                return r;
 508        }
 509
 510        return 0;
 511}
 512
 513/* INIT */
 514static int (*dss_output_drv_reg_funcs[])(void) __initdata = {
 515#ifdef CONFIG_OMAP2_DSS_DSI
 516        dsi_init_platform_driver,
 517#endif
 518#ifdef CONFIG_OMAP2_DSS_DPI
 519        dpi_init_platform_driver,
 520#endif
 521#ifdef CONFIG_OMAP2_DSS_SDI
 522        sdi_init_platform_driver,
 523#endif
 524#ifdef CONFIG_OMAP2_DSS_RFBI
 525        rfbi_init_platform_driver,
 526#endif
 527#ifdef CONFIG_OMAP2_DSS_VENC
 528        venc_init_platform_driver,
 529#endif
 530#ifdef CONFIG_OMAP4_DSS_HDMI
 531        hdmi_init_platform_driver,
 532#endif
 533};
 534
 535static void (*dss_output_drv_unreg_funcs[])(void) __exitdata = {
 536#ifdef CONFIG_OMAP2_DSS_DSI
 537        dsi_uninit_platform_driver,
 538#endif
 539#ifdef CONFIG_OMAP2_DSS_DPI
 540        dpi_uninit_platform_driver,
 541#endif
 542#ifdef CONFIG_OMAP2_DSS_SDI
 543        sdi_uninit_platform_driver,
 544#endif
 545#ifdef CONFIG_OMAP2_DSS_RFBI
 546        rfbi_uninit_platform_driver,
 547#endif
 548#ifdef CONFIG_OMAP2_DSS_VENC
 549        venc_uninit_platform_driver,
 550#endif
 551#ifdef CONFIG_OMAP4_DSS_HDMI
 552        hdmi_uninit_platform_driver,
 553#endif
 554};
 555
 556static bool dss_output_drv_loaded[ARRAY_SIZE(dss_output_drv_reg_funcs)];
 557
 558static int __init omap_dss_register_drivers(void)
 559{
 560        int r;
 561        int i;
 562
 563        r = platform_driver_probe(&omap_dss_driver, omap_dss_probe);
 564        if (r)
 565                return r;
 566
 567        r = dss_init_platform_driver();
 568        if (r) {
 569                DSSERR("Failed to initialize DSS platform driver\n");
 570                goto err_dss;
 571        }
 572
 573        r = dispc_init_platform_driver();
 574        if (r) {
 575                DSSERR("Failed to initialize dispc platform driver\n");
 576                goto err_dispc;
 577        }
 578
 579        /*
 580         * It's ok if the output-driver register fails. It happens, for example,
 581         * when there is no output-device (e.g. SDI for OMAP4).
 582         */
 583        for (i = 0; i < ARRAY_SIZE(dss_output_drv_reg_funcs); ++i) {
 584                r = dss_output_drv_reg_funcs[i]();
 585                if (r == 0)
 586                        dss_output_drv_loaded[i] = true;
 587        }
 588
 589        return 0;
 590
 591err_dispc:
 592        dss_uninit_platform_driver();
 593err_dss:
 594        platform_driver_unregister(&omap_dss_driver);
 595
 596        return r;
 597}
 598
 599static void __exit omap_dss_unregister_drivers(void)
 600{
 601        int i;
 602
 603        for (i = 0; i < ARRAY_SIZE(dss_output_drv_unreg_funcs); ++i) {
 604                if (dss_output_drv_loaded[i])
 605                        dss_output_drv_unreg_funcs[i]();
 606        }
 607
 608        dispc_uninit_platform_driver();
 609        dss_uninit_platform_driver();
 610
 611        platform_driver_unregister(&omap_dss_driver);
 612}
 613
 614#ifdef CONFIG_OMAP2_DSS_MODULE
 615static void omap_dss_bus_unregister(void)
 616{
 617        device_unregister(&dss_bus);
 618
 619        bus_unregister(&dss_bus_type);
 620}
 621
 622static int __init omap_dss_init(void)
 623{
 624        int r;
 625
 626        r = omap_dss_bus_register();
 627        if (r)
 628                return r;
 629
 630        r = omap_dss_register_drivers();
 631        if (r) {
 632                omap_dss_bus_unregister();
 633                return r;
 634        }
 635
 636        dss_initialized = true;
 637
 638        return 0;
 639}
 640
 641static void __exit omap_dss_exit(void)
 642{
 643        omap_dss_unregister_drivers();
 644
 645        omap_dss_bus_unregister();
 646}
 647
 648module_init(omap_dss_init);
 649module_exit(omap_dss_exit);
 650#else
 651static int __init omap_dss_init(void)
 652{
 653        return omap_dss_bus_register();
 654}
 655
 656static int __init omap_dss_init2(void)
 657{
 658        int r;
 659
 660        r = omap_dss_register_drivers();
 661        if (r)
 662                return r;
 663
 664        dss_initialized = true;
 665
 666        return 0;
 667}
 668
 669core_initcall(omap_dss_init);
 670device_initcall(omap_dss_init2);
 671#endif
 672
 673MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
 674MODULE_DESCRIPTION("OMAP2/3 Display Subsystem");
 675MODULE_LICENSE("GPL v2");
 676
 677