Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * (C) COPYRIGHT 2018 ARM Limited. All rights reserved.
0004  * Author: James.Qian.Wang <james.qian.wang@arm.com>
0005  *
0006  */
0007 #include <linux/module.h>
0008 #include <linux/kernel.h>
0009 #include <linux/platform_device.h>
0010 #include <linux/component.h>
0011 #include <linux/pm_runtime.h>
0012 #include <drm/drm_module.h>
0013 #include <drm/drm_of.h>
0014 #include "komeda_dev.h"
0015 #include "komeda_kms.h"
0016 
0017 struct komeda_drv {
0018     struct komeda_dev *mdev;
0019     struct komeda_kms_dev *kms;
0020 };
0021 
0022 struct komeda_dev *dev_to_mdev(struct device *dev)
0023 {
0024     struct komeda_drv *mdrv = dev_get_drvdata(dev);
0025 
0026     return mdrv ? mdrv->mdev : NULL;
0027 }
0028 
0029 static void komeda_unbind(struct device *dev)
0030 {
0031     struct komeda_drv *mdrv = dev_get_drvdata(dev);
0032 
0033     if (!mdrv)
0034         return;
0035 
0036     komeda_kms_detach(mdrv->kms);
0037 
0038     if (pm_runtime_enabled(dev))
0039         pm_runtime_disable(dev);
0040     else
0041         komeda_dev_suspend(mdrv->mdev);
0042 
0043     komeda_dev_destroy(mdrv->mdev);
0044 
0045     dev_set_drvdata(dev, NULL);
0046     devm_kfree(dev, mdrv);
0047 }
0048 
0049 static int komeda_bind(struct device *dev)
0050 {
0051     struct komeda_drv *mdrv;
0052     int err;
0053 
0054     mdrv = devm_kzalloc(dev, sizeof(*mdrv), GFP_KERNEL);
0055     if (!mdrv)
0056         return -ENOMEM;
0057 
0058     mdrv->mdev = komeda_dev_create(dev);
0059     if (IS_ERR(mdrv->mdev)) {
0060         err = PTR_ERR(mdrv->mdev);
0061         goto free_mdrv;
0062     }
0063 
0064     pm_runtime_enable(dev);
0065     if (!pm_runtime_enabled(dev))
0066         komeda_dev_resume(mdrv->mdev);
0067 
0068     mdrv->kms = komeda_kms_attach(mdrv->mdev);
0069     if (IS_ERR(mdrv->kms)) {
0070         err = PTR_ERR(mdrv->kms);
0071         goto destroy_mdev;
0072     }
0073 
0074     dev_set_drvdata(dev, mdrv);
0075 
0076     return 0;
0077 
0078 destroy_mdev:
0079     if (pm_runtime_enabled(dev))
0080         pm_runtime_disable(dev);
0081     else
0082         komeda_dev_suspend(mdrv->mdev);
0083 
0084     komeda_dev_destroy(mdrv->mdev);
0085 
0086 free_mdrv:
0087     devm_kfree(dev, mdrv);
0088     return err;
0089 }
0090 
0091 static const struct component_master_ops komeda_master_ops = {
0092     .bind   = komeda_bind,
0093     .unbind = komeda_unbind,
0094 };
0095 
0096 static void komeda_add_slave(struct device *master,
0097                  struct component_match **match,
0098                  struct device_node *np,
0099                  u32 port, u32 endpoint)
0100 {
0101     struct device_node *remote;
0102 
0103     remote = of_graph_get_remote_node(np, port, endpoint);
0104     if (remote) {
0105         drm_of_component_match_add(master, match, component_compare_of, remote);
0106         of_node_put(remote);
0107     }
0108 }
0109 
0110 static int komeda_platform_probe(struct platform_device *pdev)
0111 {
0112     struct device *dev = &pdev->dev;
0113     struct component_match *match = NULL;
0114     struct device_node *child;
0115 
0116     if (!dev->of_node)
0117         return -ENODEV;
0118 
0119     for_each_available_child_of_node(dev->of_node, child) {
0120         if (of_node_cmp(child->name, "pipeline") != 0)
0121             continue;
0122 
0123         /* add connector */
0124         komeda_add_slave(dev, &match, child, KOMEDA_OF_PORT_OUTPUT, 0);
0125         komeda_add_slave(dev, &match, child, KOMEDA_OF_PORT_OUTPUT, 1);
0126     }
0127 
0128     return component_master_add_with_match(dev, &komeda_master_ops, match);
0129 }
0130 
0131 static int komeda_platform_remove(struct platform_device *pdev)
0132 {
0133     component_master_del(&pdev->dev, &komeda_master_ops);
0134     return 0;
0135 }
0136 
0137 static const struct of_device_id komeda_of_match[] = {
0138     { .compatible = "arm,mali-d71", .data = d71_identify, },
0139     { .compatible = "arm,mali-d32", .data = d71_identify, },
0140     {},
0141 };
0142 
0143 MODULE_DEVICE_TABLE(of, komeda_of_match);
0144 
0145 static int __maybe_unused komeda_rt_pm_suspend(struct device *dev)
0146 {
0147     struct komeda_drv *mdrv = dev_get_drvdata(dev);
0148 
0149     return komeda_dev_suspend(mdrv->mdev);
0150 }
0151 
0152 static int __maybe_unused komeda_rt_pm_resume(struct device *dev)
0153 {
0154     struct komeda_drv *mdrv = dev_get_drvdata(dev);
0155 
0156     return komeda_dev_resume(mdrv->mdev);
0157 }
0158 
0159 static int __maybe_unused komeda_pm_suspend(struct device *dev)
0160 {
0161     struct komeda_drv *mdrv = dev_get_drvdata(dev);
0162     int res;
0163 
0164     res = drm_mode_config_helper_suspend(&mdrv->kms->base);
0165 
0166     if (!pm_runtime_status_suspended(dev))
0167         komeda_dev_suspend(mdrv->mdev);
0168 
0169     return res;
0170 }
0171 
0172 static int __maybe_unused komeda_pm_resume(struct device *dev)
0173 {
0174     struct komeda_drv *mdrv = dev_get_drvdata(dev);
0175 
0176     if (!pm_runtime_status_suspended(dev))
0177         komeda_dev_resume(mdrv->mdev);
0178 
0179     return drm_mode_config_helper_resume(&mdrv->kms->base);
0180 }
0181 
0182 static const struct dev_pm_ops komeda_pm_ops = {
0183     SET_SYSTEM_SLEEP_PM_OPS(komeda_pm_suspend, komeda_pm_resume)
0184     SET_RUNTIME_PM_OPS(komeda_rt_pm_suspend, komeda_rt_pm_resume, NULL)
0185 };
0186 
0187 static struct platform_driver komeda_platform_driver = {
0188     .probe  = komeda_platform_probe,
0189     .remove = komeda_platform_remove,
0190     .driver = {
0191         .name = "komeda",
0192         .of_match_table = komeda_of_match,
0193         .pm = &komeda_pm_ops,
0194     },
0195 };
0196 
0197 drm_module_platform_driver(komeda_platform_driver);
0198 
0199 MODULE_AUTHOR("James.Qian.Wang <james.qian.wang@arm.com>");
0200 MODULE_DESCRIPTION("Komeda KMS driver");
0201 MODULE_LICENSE("GPL v2");