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 static void komeda_unbind(struct device *dev)
22 struct komeda_drv *mdrv = dev_get_drvdata(dev);
27 komeda_kms_detach(mdrv->kms);
28 komeda_dev_destroy(mdrv->mdev);
30 dev_set_drvdata(dev, NULL);
31 devm_kfree(dev, mdrv);
34 static int komeda_bind(struct device *dev)
36 struct komeda_drv *mdrv;
39 mdrv = devm_kzalloc(dev, sizeof(*mdrv), GFP_KERNEL);
43 mdrv->mdev = komeda_dev_create(dev);
44 if (IS_ERR(mdrv->mdev)) {
45 err = PTR_ERR(mdrv->mdev);
49 mdrv->kms = komeda_kms_attach(mdrv->mdev);
50 if (IS_ERR(mdrv->kms)) {
51 err = PTR_ERR(mdrv->kms);
55 dev_set_drvdata(dev, mdrv);
60 komeda_dev_destroy(mdrv->mdev);
63 devm_kfree(dev, mdrv);
67 static const struct component_master_ops komeda_master_ops = {
69 .unbind = komeda_unbind,
72 static int compare_of(struct device *dev, void *data)
74 return dev->of_node == data;
77 static void komeda_add_slave(struct device *master,
78 struct component_match **match,
79 struct device_node *np, int port)
81 struct device_node *remote;
83 remote = of_graph_get_remote_node(np, port, 0);
85 drm_of_component_match_add(master, match, compare_of, remote);
90 static int komeda_platform_probe(struct platform_device *pdev)
92 struct device *dev = &pdev->dev;
93 struct component_match *match = NULL;
94 struct device_node *child;
99 for_each_available_child_of_node(dev->of_node, child) {
100 if (of_node_cmp(child->name, "pipeline") != 0)
104 komeda_add_slave(dev, &match, child, KOMEDA_OF_PORT_OUTPUT);
107 return component_master_add_with_match(dev, &komeda_master_ops, match);
110 static int komeda_platform_remove(struct platform_device *pdev)
112 component_master_del(&pdev->dev, &komeda_master_ops);
116 static const struct komeda_product_data komeda_products[] = {
118 .product_id = MALIDP_D71_PRODUCT_ID,
119 .identify = d71_identify,
123 const struct of_device_id komeda_of_match[] = {
124 { .compatible = "arm,mali-d71", .data = &komeda_products[MALI_D71], },
128 MODULE_DEVICE_TABLE(of, komeda_of_match);
130 static struct platform_driver komeda_platform_driver = {
131 .probe = komeda_platform_probe,
132 .remove = komeda_platform_remove,
135 .of_match_table = komeda_of_match,
140 module_platform_driver(komeda_platform_driver);
142 MODULE_AUTHOR("James.Qian.Wang <james.qian.wang@arm.com>");
143 MODULE_DESCRIPTION("Komeda KMS driver");
144 MODULE_LICENSE("GPL v2");