diff mbox series

[1/3] drm/loongson: Add helpers for creating subdevice

Message ID 20240513001243.1739336-2-sui.jingfeng@linux.dev (mailing list archive)
State New, archived
Headers show
Series drm/loongson: Introduce component framework support | expand

Commit Message

Sui Jingfeng May 13, 2024, 12:12 a.m. UTC
In some display subsystems, the functionality of a PCI(e) device may too
complex for a single driver to be managed by a monolithic driver. A split
of the functionality into child devices can helps to achieve better
modularity, eaiser for understand and maintain.

Add the loongson_create_platform_device() function to pove the way for the
mentioned goals. Pure software method, no hardware operations involved.

Signed-off-by: Sui Jingfeng <sui.jingfeng@linux.dev>
---
 drivers/gpu/drm/loongson/loongson_device.c | 42 ++++++++++++++++++++++
 drivers/gpu/drm/loongson/lsdc_drv.h        |  6 ++++
 2 files changed, 48 insertions(+)

Comments

Markus Elfring May 15, 2024, 8:30 p.m. UTC | #1
> In some display subsystems, the functionality of a PCI(e) device may too> of the functionality into child devices can helps to achieve better
> modularity, eaiser for understand and maintain.
>
> Add the loongson_create_platform_device() function to pove the way …

Please avoid typos in such a change description.

Regards,
Markus
Sui Jingfeng May 16, 2024, 2:29 a.m. UTC | #2
Hi,

On 5/16/24 04:30, Markus Elfring wrote:
>> In some display subsystems, the functionality of a PCI(e) device may too
> …
>> of the functionality into child devices can helps to achieve better
>> modularity, eaiser for understand and maintain.
>>
>> Add the loongson_create_platform_device() function to pove the way …
> 
> Please avoid typos in such a change description.


I was too hurry, sorry, my bad.
Will be fixed at the next version.


> Regards,
> Markus
diff mbox series

Patch

diff --git a/drivers/gpu/drm/loongson/loongson_device.c b/drivers/gpu/drm/loongson/loongson_device.c
index 9986c8a2a255..b268549d643e 100644
--- a/drivers/gpu/drm/loongson/loongson_device.c
+++ b/drivers/gpu/drm/loongson/loongson_device.c
@@ -4,6 +4,7 @@ 
  */
 
 #include <linux/pci.h>
+#include <linux/platform_device.h>
 
 #include "lsdc_drv.h"
 
@@ -100,3 +101,44 @@  lsdc_device_probe(struct pci_dev *pdev, enum loongson_chip_id chip_id)
 {
 	return __chip_id_desc_table[chip_id];
 }
+
+int loongson_create_platform_device(struct device *parent,
+				    const char *name, int id,
+				    struct resource *pres,
+				    void *data,
+				    struct platform_device **ppdev)
+{
+	struct platform_device *pdev;
+	int ret;
+
+	pdev = platform_device_alloc(name, id);
+	if (!pdev)
+		return -ENOMEM;
+
+	pdev->dev.parent = parent;
+
+	if (pres) {
+		ret = platform_device_add_resources(pdev, pres, 1);
+		if (ret) {
+			platform_device_put(pdev);
+			return ret;
+		}
+	}
+
+	if (data) {
+		void *pdata = kmalloc(sizeof(void *), GFP_KERNEL);
+
+		*(void **)pdata = data;
+		pdev->dev.platform_data = pdata;
+	}
+
+	ret = platform_device_add(pdev);
+	if (ret) {
+		platform_device_put(pdev);
+		return ret;
+	}
+
+	*ppdev = pdev;
+
+	return 0;
+}
diff --git a/drivers/gpu/drm/loongson/lsdc_drv.h b/drivers/gpu/drm/loongson/lsdc_drv.h
index fbf2d760ef27..a2c6b496a69f 100644
--- a/drivers/gpu/drm/loongson/lsdc_drv.h
+++ b/drivers/gpu/drm/loongson/lsdc_drv.h
@@ -47,6 +47,12 @@  enum loongson_chip_id {
 const struct lsdc_desc *
 lsdc_device_probe(struct pci_dev *pdev, enum loongson_chip_id chip);
 
+int loongson_create_platform_device(struct device *parent,
+				    const char *name, int id,
+				    struct resource *pres,
+				    void *data,
+				    struct platform_device **ppdev);
+
 struct lsdc_kms_funcs;
 
 /* DC specific */