diff mbox series

[5/9] drm/simplekms: Initialize framebuffer data from device-tree node

Message ID 20200625120011.16168-6-tzimmermann@suse.de (mailing list archive)
State New, archived
Headers show
Series drm: Support simple-framebuffer devices and firmware fbs | expand

Commit Message

Thomas Zimmermann June 25, 2020, noon UTC
A firmware framebuffer might also be specified via device-tree files. If
no device platform data is given, try the DT device node.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/gpu/drm/tiny/simplekms.c | 84 ++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)

Comments

Rob Herring (Arm) June 30, 2020, 2:36 a.m. UTC | #1
On Thu, Jun 25, 2020 at 6:00 AM Thomas Zimmermann <tzimmermann@suse.de> wrote:
>
> A firmware framebuffer might also be specified via device-tree files. If
> no device platform data is given, try the DT device node.

You are missing a DT match table for driver matching and module
loading (if a module is supported).

>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> ---
>  drivers/gpu/drm/tiny/simplekms.c | 84 ++++++++++++++++++++++++++++++++
>  1 file changed, 84 insertions(+)
>
> diff --git a/drivers/gpu/drm/tiny/simplekms.c b/drivers/gpu/drm/tiny/simplekms.c
> index ac2ebfcedd22..87636307aa4f 100644
> --- a/drivers/gpu/drm/tiny/simplekms.c
> +++ b/drivers/gpu/drm/tiny/simplekms.c
> @@ -113,6 +113,76 @@ simplefb_get_format_pd(struct drm_device *dev,
>         return simplefb_get_validated_format(dev, pd->format);
>  }
>
> +static int
> +simplefb_read_u32_of(struct drm_device *dev, struct device_node *of_node,
> +                    const char* name, u32 *value)
> +{
> +       int ret = of_property_read_u32(of_node, name, value);
> +       if (ret)
> +               drm_err(dev, "simplefb: can't parse framebuffer %s: error %d\n",
> +                       name, ret);
> +       return ret;
> +}
> +
> +static int
> +simplefb_read_string_of(struct drm_device *dev, struct device_node *of_node,
> +                       const char* name, const char **value)
> +{
> +       int ret = of_property_read_string(of_node, name, value);
> +       if (ret)
> +               drm_err(dev, "simplefb: can't parse framebuffer %s: error %d\n",
> +                       name, ret);
> +       return ret;
> +}
> +
> +static int
> +simplefb_get_width_of(struct drm_device *dev, struct device_node *of_node)
> +{
> +       int ret;
> +       u32 width;
> +
> +       ret = simplefb_read_u32_of(dev, of_node, "width", &width);
> +       if (ret)
> +               return ret;
> +       return simplefb_get_validated_int0(dev, "width", width);
> +}
> +
> +static int
> +simplefb_get_height_of(struct drm_device *dev, struct device_node *of_node)
> +{
> +       int ret;
> +       u32 height;
> +
> +       ret = simplefb_read_u32_of(dev, of_node, "height", &height);
> +       if (ret)
> +               return ret;
> +       return simplefb_get_validated_int0(dev, "height", height);
> +}
> +
> +static int
> +simplefb_get_stride_of(struct drm_device *dev, struct device_node *of_node)
> +{
> +       int ret;
> +       u32 stride;
> +
> +       ret = simplefb_read_u32_of(dev, of_node, "stride", &stride);
> +       if (ret)
> +               return ret;
> +       return simplefb_get_validated_int(dev, "stride", stride);
> +}
> +
> +static const struct drm_format_info *
> +simplefb_get_format_of(struct drm_device *dev, struct device_node *of_node)
> +{
> +       int ret;
> +       const char *format;
> +
> +       ret = simplefb_read_string_of(dev, of_node, "format", &format);
> +       if (ret)
> +               return ERR_PTR(ret);
> +       return simplefb_get_validated_format(dev, format);
> +}
> +
>  /*
>   * Simple Framebuffer device
>   */
> @@ -163,6 +233,7 @@ static int simplekms_device_init_fb(struct simplekms_device *sdev)
>         struct drm_device *dev = &sdev->dev;
>         struct platform_device *pdev = sdev->pdev;
>         const struct simplefb_platform_data *pd = dev_get_platdata(&pdev->dev);
> +       struct device_node *of_node = pdev->dev.of_node;
>
>         if (pd) {
>                 width = simplefb_get_width_pd(dev, pd);
> @@ -177,6 +248,19 @@ static int simplekms_device_init_fb(struct simplekms_device *sdev)
>                 format = simplefb_get_format_pd(dev, pd);
>                 if (IS_ERR(format))
>                         return PTR_ERR(format);
> +       } else if (of_node) {
> +               width = simplefb_get_width_of(dev, of_node);
> +               if (width < 0)
> +                       return width;
> +               height = simplefb_get_height_of(dev, of_node);
> +               if (height < 0)
> +                       return height;
> +               stride = simplefb_get_stride_of(dev, of_node);
> +               if (stride < 0)
> +                       return stride;
> +               format = simplefb_get_format_of(dev, of_node);
> +               if (IS_ERR(format))
> +                       return PTR_ERR(format);
>         } else {
>                 drm_err(dev, "no simplefb configuration found\n");
>                 return -ENODEV;
> --
> 2.27.0
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/tiny/simplekms.c b/drivers/gpu/drm/tiny/simplekms.c
index ac2ebfcedd22..87636307aa4f 100644
--- a/drivers/gpu/drm/tiny/simplekms.c
+++ b/drivers/gpu/drm/tiny/simplekms.c
@@ -113,6 +113,76 @@  simplefb_get_format_pd(struct drm_device *dev,
 	return simplefb_get_validated_format(dev, pd->format);
 }
 
+static int
+simplefb_read_u32_of(struct drm_device *dev, struct device_node *of_node,
+		     const char* name, u32 *value)
+{
+	int ret = of_property_read_u32(of_node, name, value);
+	if (ret)
+		drm_err(dev, "simplefb: can't parse framebuffer %s: error %d\n",
+			name, ret);
+	return ret;
+}
+
+static int
+simplefb_read_string_of(struct drm_device *dev, struct device_node *of_node,
+			const char* name, const char **value)
+{
+	int ret = of_property_read_string(of_node, name, value);
+	if (ret)
+		drm_err(dev, "simplefb: can't parse framebuffer %s: error %d\n",
+			name, ret);
+	return ret;
+}
+
+static int
+simplefb_get_width_of(struct drm_device *dev, struct device_node *of_node)
+{
+	int ret;
+	u32 width;
+
+	ret = simplefb_read_u32_of(dev, of_node, "width", &width);
+	if (ret)
+		return ret;
+	return simplefb_get_validated_int0(dev, "width", width);
+}
+
+static int
+simplefb_get_height_of(struct drm_device *dev, struct device_node *of_node)
+{
+	int ret;
+	u32 height;
+
+	ret = simplefb_read_u32_of(dev, of_node, "height", &height);
+	if (ret)
+		return ret;
+	return simplefb_get_validated_int0(dev, "height", height);
+}
+
+static int
+simplefb_get_stride_of(struct drm_device *dev, struct device_node *of_node)
+{
+	int ret;
+	u32 stride;
+
+	ret = simplefb_read_u32_of(dev, of_node, "stride", &stride);
+	if (ret)
+		return ret;
+	return simplefb_get_validated_int(dev, "stride", stride);
+}
+
+static const struct drm_format_info *
+simplefb_get_format_of(struct drm_device *dev, struct device_node *of_node)
+{
+	int ret;
+	const char *format;
+
+	ret = simplefb_read_string_of(dev, of_node, "format", &format);
+	if (ret)
+		return ERR_PTR(ret);
+	return simplefb_get_validated_format(dev, format);
+}
+
 /*
  * Simple Framebuffer device
  */
@@ -163,6 +233,7 @@  static int simplekms_device_init_fb(struct simplekms_device *sdev)
 	struct drm_device *dev = &sdev->dev;
 	struct platform_device *pdev = sdev->pdev;
 	const struct simplefb_platform_data *pd = dev_get_platdata(&pdev->dev);
+	struct device_node *of_node = pdev->dev.of_node;
 
 	if (pd) {
 		width = simplefb_get_width_pd(dev, pd);
@@ -177,6 +248,19 @@  static int simplekms_device_init_fb(struct simplekms_device *sdev)
 		format = simplefb_get_format_pd(dev, pd);
 		if (IS_ERR(format))
 			return PTR_ERR(format);
+	} else if (of_node) {
+		width = simplefb_get_width_of(dev, of_node);
+		if (width < 0)
+			return width;
+		height = simplefb_get_height_of(dev, of_node);
+		if (height < 0)
+			return height;
+		stride = simplefb_get_stride_of(dev, of_node);
+		if (stride < 0)
+			return stride;
+		format = simplefb_get_format_of(dev, of_node);
+		if (IS_ERR(format))
+			return PTR_ERR(format);
 	} else {
 		drm_err(dev, "no simplefb configuration found\n");
 		return -ENODEV;