Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * linux/drivers/video/omap2/dss/core.c
0004  *
0005  * Copyright (C) 2009 Nokia Corporation
0006  * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
0007  *
0008  * Some code and ideas taken from drivers/video/omap/ driver
0009  * by Imre Deak.
0010  */
0011 
0012 #define DSS_SUBSYS_NAME "CORE"
0013 
0014 #include <linux/kernel.h>
0015 #include <linux/module.h>
0016 #include <linux/clk.h>
0017 #include <linux/err.h>
0018 #include <linux/platform_device.h>
0019 #include <linux/seq_file.h>
0020 #include <linux/debugfs.h>
0021 #include <linux/io.h>
0022 #include <linux/device.h>
0023 #include <linux/regulator/consumer.h>
0024 #include <linux/suspend.h>
0025 #include <linux/slab.h>
0026 
0027 #include <video/omapfb_dss.h>
0028 
0029 #include "dss.h"
0030 #include "dss_features.h"
0031 
0032 static struct {
0033     struct platform_device *pdev;
0034 
0035     const char *default_display_name;
0036 } core;
0037 
0038 static char *def_disp_name;
0039 module_param_named(def_disp, def_disp_name, charp, 0);
0040 MODULE_PARM_DESC(def_disp, "default display name");
0041 
0042 const char *omapdss_get_default_display_name(void)
0043 {
0044     return core.default_display_name;
0045 }
0046 EXPORT_SYMBOL(omapdss_get_default_display_name);
0047 
0048 enum omapdss_version omapdss_get_version(void)
0049 {
0050     struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
0051     return pdata->version;
0052 }
0053 EXPORT_SYMBOL(omapdss_get_version);
0054 
0055 struct platform_device *dss_get_core_pdev(void)
0056 {
0057     return core.pdev;
0058 }
0059 
0060 int dss_dsi_enable_pads(int dsi_id, unsigned lane_mask)
0061 {
0062     struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
0063 
0064     if (!board_data->dsi_enable_pads)
0065         return -ENOENT;
0066 
0067     return board_data->dsi_enable_pads(dsi_id, lane_mask);
0068 }
0069 
0070 void dss_dsi_disable_pads(int dsi_id, unsigned lane_mask)
0071 {
0072     struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
0073 
0074     if (!board_data->dsi_disable_pads)
0075         return;
0076 
0077     return board_data->dsi_disable_pads(dsi_id, lane_mask);
0078 }
0079 
0080 int dss_set_min_bus_tput(struct device *dev, unsigned long tput)
0081 {
0082     struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
0083 
0084     if (pdata->set_min_bus_tput)
0085         return pdata->set_min_bus_tput(dev, tput);
0086     else
0087         return 0;
0088 }
0089 
0090 #if defined(CONFIG_FB_OMAP2_DSS_DEBUGFS)
0091 static int dss_show(struct seq_file *s, void *unused)
0092 {
0093     void (*func)(struct seq_file *) = s->private;
0094     func(s);
0095     return 0;
0096 }
0097 
0098 DEFINE_SHOW_ATTRIBUTE(dss);
0099 
0100 static struct dentry *dss_debugfs_dir;
0101 
0102 static void dss_initialize_debugfs(void)
0103 {
0104     dss_debugfs_dir = debugfs_create_dir("omapdss", NULL);
0105 
0106     debugfs_create_file("clk", S_IRUGO, dss_debugfs_dir,
0107             &dss_debug_dump_clocks, &dss_fops);
0108 }
0109 
0110 static void dss_uninitialize_debugfs(void)
0111 {
0112     debugfs_remove_recursive(dss_debugfs_dir);
0113 }
0114 
0115 void dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
0116 {
0117     debugfs_create_file(name, S_IRUGO, dss_debugfs_dir, write, &dss_fops);
0118 }
0119 #else /* CONFIG_FB_OMAP2_DSS_DEBUGFS */
0120 static inline void dss_initialize_debugfs(void)
0121 {
0122 }
0123 static inline void dss_uninitialize_debugfs(void)
0124 {
0125 }
0126 void dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
0127 {
0128 }
0129 #endif /* CONFIG_FB_OMAP2_DSS_DEBUGFS */
0130 
0131 /* PLATFORM DEVICE */
0132 static int omap_dss_pm_notif(struct notifier_block *b, unsigned long v, void *d)
0133 {
0134     DSSDBG("pm notif %lu\n", v);
0135 
0136     switch (v) {
0137     case PM_SUSPEND_PREPARE:
0138     case PM_HIBERNATION_PREPARE:
0139     case PM_RESTORE_PREPARE:
0140         DSSDBG("suspending displays\n");
0141         return dss_suspend_all_devices();
0142 
0143     case PM_POST_SUSPEND:
0144     case PM_POST_HIBERNATION:
0145     case PM_POST_RESTORE:
0146         DSSDBG("resuming displays\n");
0147         return dss_resume_all_devices();
0148 
0149     default:
0150         return 0;
0151     }
0152 }
0153 
0154 static struct notifier_block omap_dss_pm_notif_block = {
0155     .notifier_call = omap_dss_pm_notif,
0156 };
0157 
0158 static int __init omap_dss_probe(struct platform_device *pdev)
0159 {
0160     core.pdev = pdev;
0161 
0162     dss_features_init(omapdss_get_version());
0163 
0164     dss_initialize_debugfs();
0165 
0166     if (def_disp_name)
0167         core.default_display_name = def_disp_name;
0168 
0169     register_pm_notifier(&omap_dss_pm_notif_block);
0170 
0171     return 0;
0172 }
0173 
0174 static int omap_dss_remove(struct platform_device *pdev)
0175 {
0176     unregister_pm_notifier(&omap_dss_pm_notif_block);
0177 
0178     dss_uninitialize_debugfs();
0179 
0180     return 0;
0181 }
0182 
0183 static void omap_dss_shutdown(struct platform_device *pdev)
0184 {
0185     DSSDBG("shutdown\n");
0186     dss_disable_all_devices();
0187 }
0188 
0189 static struct platform_driver omap_dss_driver = {
0190     .remove         = omap_dss_remove,
0191     .shutdown   = omap_dss_shutdown,
0192     .driver         = {
0193         .name   = "omapdss",
0194     },
0195 };
0196 
0197 /* INIT */
0198 static int (*dss_output_drv_reg_funcs[])(void) __initdata = {
0199     dss_init_platform_driver,
0200     dispc_init_platform_driver,
0201 #ifdef CONFIG_FB_OMAP2_DSS_DSI
0202     dsi_init_platform_driver,
0203 #endif
0204 #ifdef CONFIG_FB_OMAP2_DSS_DPI
0205     dpi_init_platform_driver,
0206 #endif
0207 #ifdef CONFIG_FB_OMAP2_DSS_SDI
0208     sdi_init_platform_driver,
0209 #endif
0210 #ifdef CONFIG_FB_OMAP2_DSS_VENC
0211     venc_init_platform_driver,
0212 #endif
0213 #ifdef CONFIG_FB_OMAP4_DSS_HDMI
0214     hdmi4_init_platform_driver,
0215 #endif
0216 #ifdef CONFIG_FB_OMAP5_DSS_HDMI
0217     hdmi5_init_platform_driver,
0218 #endif
0219 };
0220 
0221 static void (*dss_output_drv_unreg_funcs[])(void) = {
0222 #ifdef CONFIG_FB_OMAP5_DSS_HDMI
0223     hdmi5_uninit_platform_driver,
0224 #endif
0225 #ifdef CONFIG_FB_OMAP4_DSS_HDMI
0226     hdmi4_uninit_platform_driver,
0227 #endif
0228 #ifdef CONFIG_FB_OMAP2_DSS_VENC
0229     venc_uninit_platform_driver,
0230 #endif
0231 #ifdef CONFIG_FB_OMAP2_DSS_SDI
0232     sdi_uninit_platform_driver,
0233 #endif
0234 #ifdef CONFIG_FB_OMAP2_DSS_DPI
0235     dpi_uninit_platform_driver,
0236 #endif
0237 #ifdef CONFIG_FB_OMAP2_DSS_DSI
0238     dsi_uninit_platform_driver,
0239 #endif
0240     dispc_uninit_platform_driver,
0241     dss_uninit_platform_driver,
0242 };
0243 
0244 static int __init omap_dss_init(void)
0245 {
0246     int r;
0247     int i;
0248 
0249     r = platform_driver_probe(&omap_dss_driver, omap_dss_probe);
0250     if (r)
0251         return r;
0252 
0253     for (i = 0; i < ARRAY_SIZE(dss_output_drv_reg_funcs); ++i) {
0254         r = dss_output_drv_reg_funcs[i]();
0255         if (r)
0256             goto err_reg;
0257     }
0258 
0259     return 0;
0260 
0261 err_reg:
0262     for (i = ARRAY_SIZE(dss_output_drv_reg_funcs) - i;
0263             i < ARRAY_SIZE(dss_output_drv_reg_funcs);
0264             ++i)
0265         dss_output_drv_unreg_funcs[i]();
0266 
0267     platform_driver_unregister(&omap_dss_driver);
0268 
0269     return r;
0270 }
0271 
0272 static void __exit omap_dss_exit(void)
0273 {
0274     int i;
0275 
0276     for (i = 0; i < ARRAY_SIZE(dss_output_drv_unreg_funcs); ++i)
0277         dss_output_drv_unreg_funcs[i]();
0278 
0279     platform_driver_unregister(&omap_dss_driver);
0280 }
0281 
0282 module_init(omap_dss_init);
0283 module_exit(omap_dss_exit);
0284 
0285 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
0286 MODULE_DESCRIPTION("OMAP2/3 Display Subsystem");
0287 MODULE_LICENSE("GPL v2");
0288