1 // SPDX-License-Identifier: GPL-2.0
3 * (C) COPYRIGHT 2018 ARM Limited. All rights reserved.
4 * Author: James.Qian.Wang <james.qian.wang@arm.com>
7 #include <linux/module.h>
8 #include <linux/kernel.h>
9 #include <linux/platform_device.h>
10 #include <linux/component.h>
11 #include <drm/drm_of.h>
12 #include "komeda_dev.h"
13 #include "komeda_kms.h"
16 struct komeda_dev *mdev;
17 struct komeda_kms_dev *kms;
20 struct komeda_dev *dev_to_mdev(struct device *dev)
22 struct komeda_drv *mdrv = dev_get_drvdata(dev);
24 return mdrv ? mdrv->mdev : NULL;
27 static void komeda_unbind(struct device *dev)
29 struct komeda_drv *mdrv = dev_get_drvdata(dev);
34 komeda_kms_detach(mdrv->kms);
35 komeda_dev_destroy(mdrv->mdev);
37 dev_set_drvdata(dev, NULL);
38 devm_kfree(dev, mdrv);
41 static int komeda_bind(struct device *dev)
43 struct komeda_drv *mdrv;
46 mdrv = devm_kzalloc(dev, sizeof(*mdrv), GFP_KERNEL);
50 mdrv->mdev = komeda_dev_create(dev);
51 if (IS_ERR(mdrv->mdev)) {
52 err = PTR_ERR(mdrv->mdev);
56 mdrv->kms = komeda_kms_attach(mdrv->mdev);
57 if (IS_ERR(mdrv->kms)) {
58 err = PTR_ERR(mdrv->kms);
62 dev_set_drvdata(dev, mdrv);
67 komeda_dev_destroy(mdrv->mdev);
70 devm_kfree(dev, mdrv);
74 static const struct component_master_ops komeda_master_ops = {
76 .unbind = komeda_unbind,
79 static int compare_of(struct device *dev, void *data)
81 return dev->of_node == data;
84 static void komeda_add_slave(struct device *master,
85 struct component_match **match,
86 struct device_node *np, int port)
88 struct device_node *remote;
90 remote = of_graph_get_remote_node(np, port, 0);
92 drm_of_component_match_add(master, match, compare_of, remote);
97 static int komeda_platform_probe(struct platform_device *pdev)
99 struct device *dev = &pdev->dev;
100 struct component_match *match = NULL;
101 struct device_node *child;
106 for_each_available_child_of_node(dev->of_node, child) {
107 if (of_node_cmp(child->name, "pipeline") != 0)
111 komeda_add_slave(dev, &match, child, KOMEDA_OF_PORT_OUTPUT);
114 return component_master_add_with_match(dev, &komeda_master_ops, match);
117 static int komeda_platform_remove(struct platform_device *pdev)
119 component_master_del(&pdev->dev, &komeda_master_ops);
123 static const struct komeda_product_data komeda_products[] = {
125 .product_id = MALIDP_D71_PRODUCT_ID,
126 .identify = d71_identify,
130 static const struct of_device_id komeda_of_match[] = {
131 { .compatible = "arm,mali-d71", .data = &komeda_products[MALI_D71], },
135 MODULE_DEVICE_TABLE(of, komeda_of_match);
137 static struct platform_driver komeda_platform_driver = {
138 .probe = komeda_platform_probe,
139 .remove = komeda_platform_remove,
142 .of_match_table = komeda_of_match,
147 module_platform_driver(komeda_platform_driver);
149 MODULE_AUTHOR("James.Qian.Wang <james.qian.wang@arm.com>");
150 MODULE_DESCRIPTION("Komeda KMS driver");
151 MODULE_LICENSE("GPL v2");