MLK-19227-5: hdp: Add mutex for register access function
authorSandor Yu <Sandor.yu@nxp.com>
Tue, 28 Aug 2018 07:40:03 +0000 (15:40 +0800)
committerLeonard Crestez <leonard.crestez@nxp.com>
Wed, 17 Apr 2019 23:51:34 +0000 (02:51 +0300)
Both CEC and HPD thread will access HDP register read/write
function, add mutex to support mulit-thread access.

Signed-off-by: Sandor Yu <Sandor.yu@nxp.com>
(cherry picked from commit 7e62bd0ad4b5d3187a3d1c0f2258c1d4e3ba66a6)

drivers/gpu/drm/imx/hdp/imx-hdp.c
drivers/mxc/hdp/util.h

index ca35db4..def6934 100644 (file)
@@ -13,6 +13,7 @@
  */
 #include <linux/clk.h>
 #include <linux/kthread.h>
+#include <linux/mutex.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/component.h>
@@ -945,57 +946,80 @@ static const struct drm_encoder_funcs imx_hdp_imx_encoder_funcs = {
 static int imx8mq_hdp_read(struct hdp_mem *mem, unsigned int addr, unsigned int *value)
 {
        unsigned int temp;
-       void *tmp_addr = mem->regs_base + addr;
+       void *tmp_addr;
+
+       mutex_lock(&mem->mutex);
+       tmp_addr = mem->regs_base + addr;
        temp = __raw_readl((volatile unsigned int *)tmp_addr);
        *value = temp;
+       mutex_unlock(&mem->mutex);
        return 0;
 }
 
 static int imx8mq_hdp_write(struct hdp_mem *mem, unsigned int addr, unsigned int value)
 {
-       void *tmp_addr = mem->regs_base + addr;
+       void *tmp_addr;
 
+       mutex_lock(&mem->mutex);
+       tmp_addr = mem->regs_base + addr;
        __raw_writel(value, (volatile unsigned int *)tmp_addr);
+       mutex_unlock(&mem->mutex);
        return 0;
 }
 
 static int imx8mq_hdp_sread(struct hdp_mem *mem, unsigned int addr, unsigned int *value)
 {
        unsigned int temp;
-       void *tmp_addr = mem->ss_base + addr;
+       void *tmp_addr;
+
+       mutex_lock(&mem->mutex);
+       tmp_addr = mem->ss_base + addr;
        temp = __raw_readl((volatile unsigned int *)tmp_addr);
        *value = temp;
+       mutex_unlock(&mem->mutex);
        return 0;
 }
 
 static int imx8mq_hdp_swrite(struct hdp_mem *mem, unsigned int addr, unsigned int value)
 {
-       void *tmp_addr = mem->ss_base + addr;
+       void *tmp_addr;
+
+       mutex_lock(&mem->mutex);
+       tmp_addr = mem->ss_base + addr;
        __raw_writel(value, (volatile unsigned int *)tmp_addr);
+       mutex_unlock(&mem->mutex);
        return 0;
 }
 
 static int imx8qm_hdp_read(struct hdp_mem *mem, unsigned int addr, unsigned int *value)
 {
        unsigned int temp;
-       void *tmp_addr = (addr & 0xfff) + mem->regs_base;
-       void *off_addr = 0x8 + mem->ss_base;;
+       void *tmp_addr;
+       void *off_addr;
 
+       mutex_lock(&mem->mutex);
+       tmp_addr = (addr & 0xfff) + mem->regs_base;
+       off_addr = 0x8 + mem->ss_base;;
        __raw_writel(addr >> 12, off_addr);
        temp = __raw_readl((volatile unsigned int *)tmp_addr);
 
        *value = temp;
+       mutex_unlock(&mem->mutex);
        return 0;
 }
 
 static int imx8qm_hdp_write(struct hdp_mem *mem, unsigned int addr, unsigned int value)
 {
-       void *tmp_addr = (addr & 0xfff) + mem->regs_base;
-       void *off_addr = 0x8 + mem->ss_base;;
+       void *tmp_addr;
+       void *off_addr;
 
+       mutex_lock(&mem->mutex);
+       tmp_addr = (addr & 0xfff) + mem->regs_base;
+       off_addr = 0x8 + mem->ss_base;
        __raw_writel(addr >> 12, off_addr);
 
        __raw_writel(value, (volatile unsigned int *) tmp_addr);
+       mutex_unlock(&mem->mutex);
 
        return 0;
 }
@@ -1003,23 +1027,31 @@ static int imx8qm_hdp_write(struct hdp_mem *mem, unsigned int addr, unsigned int
 static int imx8qm_hdp_sread(struct hdp_mem *mem, unsigned int addr, unsigned int *value)
 {
        unsigned int temp;
-       void *tmp_addr = (addr & 0xfff) + mem->regs_base;
-       void *off_addr = 0xc + mem->ss_base;;
+       void *tmp_addr;
+       void *off_addr;
 
+       mutex_lock(&mem->mutex);
+       tmp_addr = (addr & 0xfff) + mem->regs_base;
+       off_addr = 0xc + mem->ss_base;
        __raw_writel(addr >> 12, off_addr);
 
        temp = __raw_readl((volatile unsigned int *)tmp_addr);
        *value = temp;
+       mutex_unlock(&mem->mutex);
        return 0;
 }
 
 static int imx8qm_hdp_swrite(struct hdp_mem *mem, unsigned int addr, unsigned int value)
 {
-       void *tmp_addr = (addr & 0xfff) + mem->regs_base;
-       void *off_addr = 0xc + mem->ss_base;
+       void *tmp_addr;
+       void *off_addr;
 
+       mutex_lock(&mem->mutex);
+       tmp_addr = (addr & 0xfff) + mem->regs_base;
+       off_addr = 0xc + mem->ss_base;
        __raw_writel(addr >> 12, off_addr);
        __raw_writel(value, (volatile unsigned int *)tmp_addr);
+       mutex_unlock(&mem->mutex);
 
        return 0;
 }
@@ -1218,6 +1250,8 @@ static int imx_hdp_imx_bind(struct device *dev, struct device *master,
        if (hdp->irq[HPD_IRQ_OUT] < 0)
                dev_info(&pdev->dev, "No plug_out irq number\n");
 
+
+       mutex_init(&hdp->mem.mutex);
        /* register map */
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        hdp->mem.regs_base = devm_ioremap_resource(dev, res);
index 5cf3c81..a034752 100644 (file)
@@ -182,6 +182,7 @@ struct hdp_mem {
        void __iomem *regs_base; /* Controller regs base */
        void __iomem *ss_base; /* HDP Subsystem regs base */
        void __iomem *rst_base; /* HDP Subsystem reset base */
+       struct mutex mutex;
 };
 
 struct hdp_rw_func {