Re: [PATCH v3 3/9] drm/komeda: Build komeda to be a platform module

2018-12-24 Thread Liviu Dudau
On Fri, Dec 21, 2018 at 09:59:28AM +, james qian wang (Arm Technology 
China) wrote:
> Implement a simple wrapper for platform module to build komeda to module,
> Also add a very simple D71 layer code to show how to discover a product.
> Komeda driver direct bind the product ENTRY function xxx_identity to DT
> compatible name like:
> 
> d71_product = {
>   .product_id = MALIDP_D71_PRODUCT_ID,
>   .identify = d71_identify,
> },
> 
> const struct of_device_id komeda_of_match[] = {
>   { .compatible = "arm,mali-d71", .data = &d71_product, },
>   {},
> };
> 
> Then when linux found a matched DT node and call driver to probe, we can
> easily get the of data, and call into the product to do the identify:
> 
> komeda_bind()
> {
> ...
> product = of_device_get_match_data(dev);
> 
> product->identify();
> ...
> }
> 
> Changes in v3:
> - Fixed style problem found by checkpatch.pl --strict.
> 
> Signed-off-by: James (Qian) Wang 

Acked-by: Liviu Dudau 

Best regards,
Liviu

> ---
>  .../gpu/drm/arm/display/include/malidp_io.h   |  42 ++
>  drivers/gpu/drm/arm/display/komeda/Makefile   |   6 +-
>  .../gpu/drm/arm/display/komeda/d71/d71_dev.c  |  33 +
>  .../gpu/drm/arm/display/komeda/komeda_dev.h   |   3 +
>  .../gpu/drm/arm/display/komeda/komeda_drv.c   | 132 ++
>  5 files changed, 215 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/gpu/drm/arm/display/include/malidp_io.h
>  create mode 100644 drivers/gpu/drm/arm/display/komeda/d71/d71_dev.c
>  create mode 100644 drivers/gpu/drm/arm/display/komeda/komeda_drv.c
> 
> diff --git a/drivers/gpu/drm/arm/display/include/malidp_io.h 
> b/drivers/gpu/drm/arm/display/include/malidp_io.h
> new file mode 100644
> index ..4fb3caf864ce
> --- /dev/null
> +++ b/drivers/gpu/drm/arm/display/include/malidp_io.h
> @@ -0,0 +1,42 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * (C) COPYRIGHT 2018 ARM Limited. All rights reserved.
> + * Author: James.Qian.Wang 
> + *
> + */
> +#ifndef _MALIDP_IO_H_
> +#define _MALIDP_IO_H_
> +
> +#include 
> +
> +static inline u32
> +malidp_read32(u32 __iomem *base, u32 offset)
> +{
> + return readl((base + (offset >> 2)));
> +}
> +
> +static inline void
> +malidp_write32(u32 __iomem *base, u32 offset, u32 v)
> +{
> + writel(v, (base + (offset >> 2)));
> +}
> +
> +static inline void
> +malidp_write32_mask(u32 __iomem *base, u32 offset, u32 m, u32 v)
> +{
> + u32 tmp = malidp_read32(base, offset);
> +
> + tmp &= (~m);
> + malidp_write32(base, offset, v | tmp);
> +}
> +
> +static inline void
> +malidp_write_group(u32 __iomem *base, u32 offset, int num, const u32 *values)
> +{
> + int i;
> +
> + for (i = 0; i < num; i++)
> + malidp_write32(base, offset + i * 4, values[i]);
> +}
> +
> +#endif /*_MALIDP_IO_H_*/
> diff --git a/drivers/gpu/drm/arm/display/komeda/Makefile 
> b/drivers/gpu/drm/arm/display/komeda/Makefile
> index 5b44e36509b1..c03d6876ef75 100644
> --- a/drivers/gpu/drm/arm/display/komeda/Makefile
> +++ b/drivers/gpu/drm/arm/display/komeda/Makefile
> @@ -5,7 +5,11 @@ ccflags-y := \
>   -I$(src)
>  
>  komeda-y := \
> + komeda_drv.o \
>   komeda_dev.o \
> - komeda_pipeline.o \
> + komeda_pipeline.o
> +
> +komeda-y += \
> + d71/d71_dev.o
>  
>  obj-$(CONFIG_DRM_KOMEDA) += komeda.o
> diff --git a/drivers/gpu/drm/arm/display/komeda/d71/d71_dev.c 
> b/drivers/gpu/drm/arm/display/komeda/d71/d71_dev.c
> new file mode 100644
> index ..af3dabb499cd
> --- /dev/null
> +++ b/drivers/gpu/drm/arm/display/komeda/d71/d71_dev.c
> @@ -0,0 +1,33 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * (C) COPYRIGHT 2018 ARM Limited. All rights reserved.
> + * Author: James.Qian.Wang 
> + *
> + */
> +#include "malidp_io.h"
> +#include "komeda_dev.h"
> +
> +static int d71_enum_resources(struct komeda_dev *mdev)
> +{
> + /* TODO add enum resources */
> + return -1;
> +}
> +
> +static struct komeda_dev_funcs d71_chip_funcs = {
> + .enum_resources = d71_enum_resources,
> + .cleanup= NULL,
> +};
> +
> +#define GLB_ARCH_ID  0x000
> +#define GLB_CORE_ID  0x004
> +#define GLB_CORE_INFO0x008
> +
> +struct komeda_dev_funcs *
> +d71_identify(u32 __iomem *reg_base, struct komeda_chip_info *chip)
> +{
> + chip->arch_id   = malidp_read32(reg_base, GLB_ARCH_ID);
> + chip->core_id   = malidp_read32(reg_base, GLB_CORE_ID);
> + chip->core_info = malidp_read32(reg_base, GLB_CORE_INFO);
> +
> + return &d71_chip_funcs;
> +}
> diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_dev.h 
> b/drivers/gpu/drm/arm/display/komeda/komeda_dev.h
> index ad8fa160eff9..680e3e2cf100 100644
> --- a/drivers/gpu/drm/arm/display/komeda/komeda_dev.h
> +++ b/drivers/gpu/drm/arm/display/komeda/komeda_dev.h
> @@ -92,6 +92,9 @@ komeda_product_match(struct komeda_dev *mdev, u32 target)
>   return MALIDP_CORE_ID_PRODUCT_ID(mdev->chip.core_id) == target;
>  }
>  
> +struct kom

[PATCH v3 3/9] drm/komeda: Build komeda to be a platform module

2018-12-21 Thread james qian wang (Arm Technology China)
Implement a simple wrapper for platform module to build komeda to module,
Also add a very simple D71 layer code to show how to discover a product.
Komeda driver direct bind the product ENTRY function xxx_identity to DT
compatible name like:

d71_product = {
.product_id = MALIDP_D71_PRODUCT_ID,
.identify = d71_identify,
},

const struct of_device_id komeda_of_match[] = {
{ .compatible = "arm,mali-d71", .data = &d71_product, },
{},
};

Then when linux found a matched DT node and call driver to probe, we can
easily get the of data, and call into the product to do the identify:

komeda_bind()
{
...
product = of_device_get_match_data(dev);

product->identify();
...
}

Changes in v3:
- Fixed style problem found by checkpatch.pl --strict.

Signed-off-by: James (Qian) Wang 
---
 .../gpu/drm/arm/display/include/malidp_io.h   |  42 ++
 drivers/gpu/drm/arm/display/komeda/Makefile   |   6 +-
 .../gpu/drm/arm/display/komeda/d71/d71_dev.c  |  33 +
 .../gpu/drm/arm/display/komeda/komeda_dev.h   |   3 +
 .../gpu/drm/arm/display/komeda/komeda_drv.c   | 132 ++
 5 files changed, 215 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/arm/display/include/malidp_io.h
 create mode 100644 drivers/gpu/drm/arm/display/komeda/d71/d71_dev.c
 create mode 100644 drivers/gpu/drm/arm/display/komeda/komeda_drv.c

diff --git a/drivers/gpu/drm/arm/display/include/malidp_io.h 
b/drivers/gpu/drm/arm/display/include/malidp_io.h
new file mode 100644
index ..4fb3caf864ce
--- /dev/null
+++ b/drivers/gpu/drm/arm/display/include/malidp_io.h
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * (C) COPYRIGHT 2018 ARM Limited. All rights reserved.
+ * Author: James.Qian.Wang 
+ *
+ */
+#ifndef _MALIDP_IO_H_
+#define _MALIDP_IO_H_
+
+#include 
+
+static inline u32
+malidp_read32(u32 __iomem *base, u32 offset)
+{
+   return readl((base + (offset >> 2)));
+}
+
+static inline void
+malidp_write32(u32 __iomem *base, u32 offset, u32 v)
+{
+   writel(v, (base + (offset >> 2)));
+}
+
+static inline void
+malidp_write32_mask(u32 __iomem *base, u32 offset, u32 m, u32 v)
+{
+   u32 tmp = malidp_read32(base, offset);
+
+   tmp &= (~m);
+   malidp_write32(base, offset, v | tmp);
+}
+
+static inline void
+malidp_write_group(u32 __iomem *base, u32 offset, int num, const u32 *values)
+{
+   int i;
+
+   for (i = 0; i < num; i++)
+   malidp_write32(base, offset + i * 4, values[i]);
+}
+
+#endif /*_MALIDP_IO_H_*/
diff --git a/drivers/gpu/drm/arm/display/komeda/Makefile 
b/drivers/gpu/drm/arm/display/komeda/Makefile
index 5b44e36509b1..c03d6876ef75 100644
--- a/drivers/gpu/drm/arm/display/komeda/Makefile
+++ b/drivers/gpu/drm/arm/display/komeda/Makefile
@@ -5,7 +5,11 @@ ccflags-y := \
-I$(src)
 
 komeda-y := \
+   komeda_drv.o \
komeda_dev.o \
-   komeda_pipeline.o \
+   komeda_pipeline.o
+
+komeda-y += \
+   d71/d71_dev.o
 
 obj-$(CONFIG_DRM_KOMEDA) += komeda.o
diff --git a/drivers/gpu/drm/arm/display/komeda/d71/d71_dev.c 
b/drivers/gpu/drm/arm/display/komeda/d71/d71_dev.c
new file mode 100644
index ..af3dabb499cd
--- /dev/null
+++ b/drivers/gpu/drm/arm/display/komeda/d71/d71_dev.c
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * (C) COPYRIGHT 2018 ARM Limited. All rights reserved.
+ * Author: James.Qian.Wang 
+ *
+ */
+#include "malidp_io.h"
+#include "komeda_dev.h"
+
+static int d71_enum_resources(struct komeda_dev *mdev)
+{
+   /* TODO add enum resources */
+   return -1;
+}
+
+static struct komeda_dev_funcs d71_chip_funcs = {
+   .enum_resources = d71_enum_resources,
+   .cleanup= NULL,
+};
+
+#define GLB_ARCH_ID0x000
+#define GLB_CORE_ID0x004
+#define GLB_CORE_INFO  0x008
+
+struct komeda_dev_funcs *
+d71_identify(u32 __iomem *reg_base, struct komeda_chip_info *chip)
+{
+   chip->arch_id   = malidp_read32(reg_base, GLB_ARCH_ID);
+   chip->core_id   = malidp_read32(reg_base, GLB_CORE_ID);
+   chip->core_info = malidp_read32(reg_base, GLB_CORE_INFO);
+
+   return &d71_chip_funcs;
+}
diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_dev.h 
b/drivers/gpu/drm/arm/display/komeda/komeda_dev.h
index ad8fa160eff9..680e3e2cf100 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_dev.h
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_dev.h
@@ -92,6 +92,9 @@ komeda_product_match(struct komeda_dev *mdev, u32 target)
return MALIDP_CORE_ID_PRODUCT_ID(mdev->chip.core_id) == target;
 }
 
+struct komeda_dev_funcs *
+d71_identify(u32 __iomem *reg, struct komeda_chip_info *chip);
+
 struct komeda_dev *komeda_dev_create(struct device *dev);
 void komeda_dev_destroy(struct komeda_dev *mdev);
 
diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_drv.c 
b/drivers/gpu/drm/arm/display/komeda/komeda_drv.c
new file mode 100644
index ..326ae264481f
--- /dev/null
+++ b/drivers/gpu/drm/arm/d

[PATCH v3 3/9] drm/komeda: Build komeda to be a platform module

2018-12-21 Thread james qian wang (Arm Technology China)
Implement a simple wrapper for platform module to build komeda to module,
Also add a very simple D71 layer code to show how to discover a product.
Komeda driver direct bind the product ENTRY function xxx_identity to DT
compatible name like:

d71_product = {
.product_id = MALIDP_D71_PRODUCT_ID,
.identify = d71_identify,
},

const struct of_device_id komeda_of_match[] = {
{ .compatible = "arm,mali-d71", .data = &d71_product, },
{},
};

Then when linux found a matched DT node and call driver to probe, we can
easily get the of data, and call into the product to do the identify:

komeda_bind()
{
...
product = of_device_get_match_data(dev);

product->identify();
...
}

Changes in v3:
- Fixed style problem found by checkpatch.pl --strict.

Signed-off-by: James (Qian) Wang 
---
 .../gpu/drm/arm/display/include/malidp_io.h   |  42 ++
 drivers/gpu/drm/arm/display/komeda/Makefile   |   6 +-
 .../gpu/drm/arm/display/komeda/d71/d71_dev.c  |  33 +
 .../gpu/drm/arm/display/komeda/komeda_dev.h   |   3 +
 .../gpu/drm/arm/display/komeda/komeda_drv.c   | 132 ++
 5 files changed, 215 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/arm/display/include/malidp_io.h
 create mode 100644 drivers/gpu/drm/arm/display/komeda/d71/d71_dev.c
 create mode 100644 drivers/gpu/drm/arm/display/komeda/komeda_drv.c

diff --git a/drivers/gpu/drm/arm/display/include/malidp_io.h 
b/drivers/gpu/drm/arm/display/include/malidp_io.h
new file mode 100644
index ..4fb3caf864ce
--- /dev/null
+++ b/drivers/gpu/drm/arm/display/include/malidp_io.h
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * (C) COPYRIGHT 2018 ARM Limited. All rights reserved.
+ * Author: James.Qian.Wang 
+ *
+ */
+#ifndef _MALIDP_IO_H_
+#define _MALIDP_IO_H_
+
+#include 
+
+static inline u32
+malidp_read32(u32 __iomem *base, u32 offset)
+{
+   return readl((base + (offset >> 2)));
+}
+
+static inline void
+malidp_write32(u32 __iomem *base, u32 offset, u32 v)
+{
+   writel(v, (base + (offset >> 2)));
+}
+
+static inline void
+malidp_write32_mask(u32 __iomem *base, u32 offset, u32 m, u32 v)
+{
+   u32 tmp = malidp_read32(base, offset);
+
+   tmp &= (~m);
+   malidp_write32(base, offset, v | tmp);
+}
+
+static inline void
+malidp_write_group(u32 __iomem *base, u32 offset, int num, const u32 *values)
+{
+   int i;
+
+   for (i = 0; i < num; i++)
+   malidp_write32(base, offset + i * 4, values[i]);
+}
+
+#endif /*_MALIDP_IO_H_*/
diff --git a/drivers/gpu/drm/arm/display/komeda/Makefile 
b/drivers/gpu/drm/arm/display/komeda/Makefile
index 5b44e36509b1..c03d6876ef75 100644
--- a/drivers/gpu/drm/arm/display/komeda/Makefile
+++ b/drivers/gpu/drm/arm/display/komeda/Makefile
@@ -5,7 +5,11 @@ ccflags-y := \
-I$(src)
 
 komeda-y := \
+   komeda_drv.o \
komeda_dev.o \
-   komeda_pipeline.o \
+   komeda_pipeline.o
+
+komeda-y += \
+   d71/d71_dev.o
 
 obj-$(CONFIG_DRM_KOMEDA) += komeda.o
diff --git a/drivers/gpu/drm/arm/display/komeda/d71/d71_dev.c 
b/drivers/gpu/drm/arm/display/komeda/d71/d71_dev.c
new file mode 100644
index ..af3dabb499cd
--- /dev/null
+++ b/drivers/gpu/drm/arm/display/komeda/d71/d71_dev.c
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * (C) COPYRIGHT 2018 ARM Limited. All rights reserved.
+ * Author: James.Qian.Wang 
+ *
+ */
+#include "malidp_io.h"
+#include "komeda_dev.h"
+
+static int d71_enum_resources(struct komeda_dev *mdev)
+{
+   /* TODO add enum resources */
+   return -1;
+}
+
+static struct komeda_dev_funcs d71_chip_funcs = {
+   .enum_resources = d71_enum_resources,
+   .cleanup= NULL,
+};
+
+#define GLB_ARCH_ID0x000
+#define GLB_CORE_ID0x004
+#define GLB_CORE_INFO  0x008
+
+struct komeda_dev_funcs *
+d71_identify(u32 __iomem *reg_base, struct komeda_chip_info *chip)
+{
+   chip->arch_id   = malidp_read32(reg_base, GLB_ARCH_ID);
+   chip->core_id   = malidp_read32(reg_base, GLB_CORE_ID);
+   chip->core_info = malidp_read32(reg_base, GLB_CORE_INFO);
+
+   return &d71_chip_funcs;
+}
diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_dev.h 
b/drivers/gpu/drm/arm/display/komeda/komeda_dev.h
index ad8fa160eff9..680e3e2cf100 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_dev.h
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_dev.h
@@ -92,6 +92,9 @@ komeda_product_match(struct komeda_dev *mdev, u32 target)
return MALIDP_CORE_ID_PRODUCT_ID(mdev->chip.core_id) == target;
 }
 
+struct komeda_dev_funcs *
+d71_identify(u32 __iomem *reg, struct komeda_chip_info *chip);
+
 struct komeda_dev *komeda_dev_create(struct device *dev);
 void komeda_dev_destroy(struct komeda_dev *mdev);
 
diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_drv.c 
b/drivers/gpu/drm/arm/display/komeda/komeda_drv.c
new file mode 100644
index ..a2657b3d09d7
--- /dev/null
+++ b/drivers/gpu/drm/arm/d