[PATCH v1] platform/chrome: cros_ec_debugfs: conditionally create uptime node

2020-07-07 Thread Eizan Miyamoto
Before creating an 'uptime' node in debugfs, this change adds a check to
see if a EC_CMD_GET_UPTIME_INFO command can be successfully run.

If the uptime node is created, userspace programs may periodically poll
it (e.g., timberslide), causing commands to be sent to the EC each time.
If the EC doesn't support EC_CMD_GET_UPTIME_INFO, an error will be
emitted in the EC console, producing noise.

Signed-off-by: Eizan Miyamoto 
---

 drivers/platform/chrome/cros_ec_debugfs.c | 35 +--
 1 file changed, 26 insertions(+), 9 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec_debugfs.c 
b/drivers/platform/chrome/cros_ec_debugfs.c
index ecfada00e6c51..8708fe12f8ca8 100644
--- a/drivers/platform/chrome/cros_ec_debugfs.c
+++ b/drivers/platform/chrome/cros_ec_debugfs.c
@@ -242,17 +242,14 @@ static ssize_t cros_ec_pdinfo_read(struct file *file,
   read_buf, p - read_buf);
 }
 
-static ssize_t cros_ec_uptime_read(struct file *file, char __user *user_buf,
-  size_t count, loff_t *ppos)
+static int cros_ec_get_uptime(struct cros_ec_device *ec_dev,
+ uint32_t *uptime)
 {
-   struct cros_ec_debugfs *debug_info = file->private_data;
-   struct cros_ec_device *ec_dev = debug_info->ec->ec_dev;
struct {
struct cros_ec_command cmd;
struct ec_response_uptime_info resp;
} __packed msg = {};
struct ec_response_uptime_info *resp;
-   char read_buf[32];
int ret;
 
resp = (struct ec_response_uptime_info *)
@@ -264,8 +261,24 @@ static ssize_t cros_ec_uptime_read(struct file *file, char 
__user *user_buf,
if (ret < 0)
return ret;
 
-   ret = scnprintf(read_buf, sizeof(read_buf), "%u\n",
-   resp->time_since_ec_boot_ms);
+   *uptime = resp->time_since_ec_boot_ms;
+   return 0;
+}
+
+static ssize_t cros_ec_uptime_read(struct file *file, char __user *user_buf,
+  size_t count, loff_t *ppos)
+{
+   struct cros_ec_debugfs *debug_info = file->private_data;
+   struct cros_ec_device *ec_dev = debug_info->ec->ec_dev;
+   char read_buf[32];
+   int ret;
+   uint32_t uptime;
+
+   ret = cros_ec_get_uptime(ec_dev, );
+   if (ret < 0)
+   return ret;
+
+   ret = scnprintf(read_buf, sizeof(read_buf), "%u\n", uptime);
 
return simple_read_from_buffer(user_buf, count, ppos, read_buf, ret);
 }
@@ -425,6 +438,7 @@ static int cros_ec_debugfs_probe(struct platform_device *pd)
const char *name = ec_platform->ec_name;
struct cros_ec_debugfs *debug_info;
int ret;
+   uint32_t uptime;
 
debug_info = devm_kzalloc(ec->dev, sizeof(*debug_info), GFP_KERNEL);
if (!debug_info)
@@ -444,8 +458,11 @@ static int cros_ec_debugfs_probe(struct platform_device 
*pd)
debugfs_create_file("pdinfo", 0444, debug_info->dir, debug_info,
_ec_pdinfo_fops);
 
-   debugfs_create_file("uptime", 0444, debug_info->dir, debug_info,
-   _ec_uptime_fops);
+   if (cros_ec_get_uptime(debug_info->ec->ec_dev, ) >= 0)
+   debugfs_create_file("uptime", 0444, debug_info->dir, debug_info,
+   _ec_uptime_fops);
+   else
+   dev_dbg(ec->dev, "EC does not provide uptime");
 
debugfs_create_x32("last_resume_result", 0444, debug_info->dir,
   >ec_dev->last_resume_result);
-- 
2.27.0.383.g050319c2ae-goog



Re: [PATCH v2 2/2] [media] mtk-mdp: use pm_runtime in MDP component driver

2020-05-20 Thread Eizan Miyamoto
On Thu, May 7, 2020 at 3:07 AM Enric Balletbo Serra  wrote:
>
> Hi Eizan,
>
> Thank you for the patch.
>
> Missatge de Eizan Miyamoto  del dia dc., 6 de maig
> 2020 a les 10:42:
> >
> > Without this change, the MDP components are not fully integrated into
> > the runtime power management subsystem, and the MDP driver does not
> > work.
> >
> > For each of the component device drivers to be able to call
> > pm_runtime_get/put_sync() a pointer to the component's device struct
> > had to be added to struct mtk_mdp_comp, set by mtk_mdp_comp_init().
> >
> > Note that the dev argument to mtk_mdp_comp_clock_on/off() has been
> > removed. Those functions used to be called from the "master" mdp driver
> > in mtk_mdp_core.c, but the component's device pointer no longer
> > corresponds to the mdp master device pointer, which is not the right
> > device to pass to pm_runtime_put/get_sync() which we had to add to get
> > the driver to work properly.
> >
> > Signed-off-by: Eizan Miyamoto 
> > ---
> >
> > Changes in v2:
>
> Ah, I guess this change log corresponds to the first patch.
>
> > - remove empty mtk_mdp_comp_init
> > - update documentation for enum mtk_mdp_comp_type
> > - remove comma after last element of mtk_mdp_comp_driver_dt_match
> >
> >  drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 22 ++-
> >  drivers/media/platform/mtk-mdp/mtk_mdp_comp.h |  6 +++--
> >  drivers/media/platform/mtk-mdp/mtk_mdp_core.c |  6 ++---
> >  3 files changed, 23 insertions(+), 11 deletions(-)
> >
> > diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c 
> > b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
> > index 5b4d482df778..228c58f92c8c 100644
> > --- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
> > +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
> > @@ -15,6 +15,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >
> >  #include "mtk_mdp_comp.h"
> >  #include "mtk_mdp_core.h"
> > @@ -53,7 +54,7 @@ static const struct of_device_id 
> > mtk_mdp_comp_driver_dt_match[] = {
> >  };
> >  MODULE_DEVICE_TABLE(of, mtk_mdp_comp_driver_dt_match);
> >
> > -void mtk_mdp_comp_clock_on(struct device *dev, struct mtk_mdp_comp *comp)
> > +void mtk_mdp_comp_clock_on(struct mtk_mdp_comp *comp)
> >  {
> > int i, err;
> >
> > @@ -62,25 +63,31 @@ void mtk_mdp_comp_clock_on(struct device *dev, struct 
> > mtk_mdp_comp *comp)
> > if (err) {
> > enum mtk_mdp_comp_type comp_type =
> > (enum mtk_mdp_comp_type)
> > -   of_device_get_match_data(dev);
> > -   dev_err(dev,
> > +   of_device_get_match_data(comp->dev);
> > +   dev_err(comp->dev,
> > "failed to get larb, err %d. type:%d\n",
> > err, comp_type);
> > }
> > }
> >
> > +   err = pm_runtime_get_sync(comp->dev);
> > +   if (err < 0)
> > +   dev_err(comp->dev,
> > +   "failed to runtime get, err %d.\n",
> > +   err);
>
> Should you really ignore this error? If that's the case I'd just call
> pm_runtime_get_sync() without adding the logic to just print an error
> message.

This is mostly consistent with style elsewhere, e.g., in mtk_mdp_m2m.c
mtk_mdp_m2m_start_streaming and mtk_mdp_m2m_stop_streaming.

>
> > +
> > for (i = 0; i < ARRAY_SIZE(comp->clk); i++) {
> > if (IS_ERR(comp->clk[i]))
> > continue;
> > err = clk_prepare_enable(comp->clk[i]);
> > if (err)
> > -   dev_err(dev,
> > +   dev_err(comp->dev,
> > "failed to enable clock, err %d. i:%d\n",
> > err, i);
>
> Although ignoring errors seems to be a common pattern in this file and
> I know you did not introduce this.

Maybe the issue is that since no action is taken, logging at the 'error' log
level is not the right thing? IOW, should it be changed to an informational
message instead? Nevertheless, I think we should defer these changes to a
follow-up patch instead.

>
> > }
> >  }
> >
> > -void mtk_mdp_comp_clock_off(struct 

Re: [PATCH v2 1/2] [media] mtk-mdp: add driver to probe mdp components

2020-05-14 Thread Eizan Miyamoto
On Thu, May 7, 2020 at 11:44 PM Enric Balletbo i Serra
 wrote:
>
> Hi Eizan,
>
> On 7/5/20 13:11, Eizan Miyamoto wrote:
> > On Thu, May 7, 2020 at 2:54 AM Enric Balletbo Serra  
> > wrote:
> >>
> >> Hi Eizan,
> >>
> >> Thank you for the patch.
> >>
> >> Missatge de Eizan Miyamoto  del dia dc., 6 de maig
> >> 2020 a les 10:41:
> >>>
> >>> Broadly, this patch (1) adds a driver for various MTK MDP components to
> >>> go alongside the main MTK MDP driver, and (2) hooks them all together
> >>> using the component framework.
> >>>
> >>> (1) Up until now, the MTK MDP driver controls 8 devices in the device
> >>> tree on its own. When running tests for the hardware video decoder, we
> >>> found that the iommus and LARBs were not being properly configured. To
> >>> configure them, a driver for each be added to mtk_mdp_comp so that
> >>> mtk_iommu_add_device() can (eventually) be called from dma_configure()
> >>> inside really_probe().
> >>>
> >>> (2) The integration into the component framework allows us to defer the
> >>> registration with the v4l2 subsystem until all the MDP-related devices
> >>> have been probed, so that the relevant device node does not become
> >>> available until initialization of all the components is complete.
> >>>
> >>> Some notes about how the component framework has been integrated:
> >>>
> >>> - The driver for the rdma0 component serves double duty as the "master"
> >>>   (aggregate) driver as well as a component driver. This is a non-ideal
> >>>   compromise until a better solution is developed. This device is
> >>>   differentiated from the rest by checking for a "mediatek,vpu" property
> >>>   in the device node.
> >>>
> >>> - The list of mdp components remains hard-coded as mtk_mdp_comp_dt_ids[]
> >>>   in mtk_mdp_core.c, and as mtk_mdp_comp_driver_dt_match[] in
> >>>   mtk_mdp_comp.c. This unfortunate duplication of information is
> >>>   addressed in a following patch in this series.
> >>>
> >>> - The component driver calls component_add() for each device that is
> >>>   probed.
> >>>
> >>> - In mtk_mdp_probe (the "master" device), we scan the device tree for
> >>>   any matching nodes against mtk_mdp_comp_dt_ids, and add component
> >>>   matches for them. The match criteria is a matching device node
> >>>   pointer.
> >>>
> >>> - When the set of components devices that have been probed corresponds
> >>>   with the list that is generated by the "master", the callback to
> >>>   mtk_mdp_master_bind() is made, which then calls the component bind
> >>>   functions.
> >>>
> >>> - Inside mtk_mdp_master_bind(), once all the component bind functions
> >>>   have been called, we can then register our device to the v4l2
> >>>   subsystem.
> >>>
> >>> - The call to pm_runtime_enable() in the master device is called after
> >>>   all the components have been registered by their bind() functions
> >>>   called by mtk_mtp_master_bind(). As a result, the list of components
> >>>   will not change while power management callbacks mtk_mdp_suspend()/
> >>>   resume() are accessing the list of components.
> >>>
> >>> Signed-off-by: Eizan Miyamoto 
> >>> ---
> >>>
> >>> Changes in v2: None
> >>>
> >>
> >> Not really true :-)
> >>
> >>>  drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 150 +--
> >>>  drivers/media/platform/mtk-mdp/mtk_mdp_comp.h |  26 +--
> >>>  drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 176 +-
> >>>  drivers/media/platform/mtk-mdp/mtk_mdp_core.h |   1 +
> >>>  4 files changed, 263 insertions(+), 90 deletions(-)
> >>>
> >>> diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c 
> >>> b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
> >>> index 362fff924aef..5b4d482df778 100644
> >>> --- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
> >>> +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
> >>> @@ -5,14 +5,53 @@
> >>>   */
> >>>
> >>>  #include 
> >>> +#include 
> >>>  #include 
> >>> -#incl

Re: [PATCH v2 1/2] [media] mtk-mdp: add driver to probe mdp components

2020-05-07 Thread Eizan Miyamoto
On Thu, May 7, 2020 at 2:54 AM Enric Balletbo Serra  wrote:
>
> Hi Eizan,
>
> Thank you for the patch.
>
> Missatge de Eizan Miyamoto  del dia dc., 6 de maig
> 2020 a les 10:41:
> >
> > Broadly, this patch (1) adds a driver for various MTK MDP components to
> > go alongside the main MTK MDP driver, and (2) hooks them all together
> > using the component framework.
> >
> > (1) Up until now, the MTK MDP driver controls 8 devices in the device
> > tree on its own. When running tests for the hardware video decoder, we
> > found that the iommus and LARBs were not being properly configured. To
> > configure them, a driver for each be added to mtk_mdp_comp so that
> > mtk_iommu_add_device() can (eventually) be called from dma_configure()
> > inside really_probe().
> >
> > (2) The integration into the component framework allows us to defer the
> > registration with the v4l2 subsystem until all the MDP-related devices
> > have been probed, so that the relevant device node does not become
> > available until initialization of all the components is complete.
> >
> > Some notes about how the component framework has been integrated:
> >
> > - The driver for the rdma0 component serves double duty as the "master"
> >   (aggregate) driver as well as a component driver. This is a non-ideal
> >   compromise until a better solution is developed. This device is
> >   differentiated from the rest by checking for a "mediatek,vpu" property
> >   in the device node.
> >
> > - The list of mdp components remains hard-coded as mtk_mdp_comp_dt_ids[]
> >   in mtk_mdp_core.c, and as mtk_mdp_comp_driver_dt_match[] in
> >   mtk_mdp_comp.c. This unfortunate duplication of information is
> >   addressed in a following patch in this series.
> >
> > - The component driver calls component_add() for each device that is
> >   probed.
> >
> > - In mtk_mdp_probe (the "master" device), we scan the device tree for
> >   any matching nodes against mtk_mdp_comp_dt_ids, and add component
> >   matches for them. The match criteria is a matching device node
> >   pointer.
> >
> > - When the set of components devices that have been probed corresponds
> >   with the list that is generated by the "master", the callback to
> >   mtk_mdp_master_bind() is made, which then calls the component bind
> >   functions.
> >
> > - Inside mtk_mdp_master_bind(), once all the component bind functions
> >   have been called, we can then register our device to the v4l2
> >   subsystem.
> >
> > - The call to pm_runtime_enable() in the master device is called after
> >   all the components have been registered by their bind() functions
> >   called by mtk_mtp_master_bind(). As a result, the list of components
> >   will not change while power management callbacks mtk_mdp_suspend()/
> >   resume() are accessing the list of components.
> >
> > Signed-off-by: Eizan Miyamoto 
> > ---
> >
> > Changes in v2: None
> >
>
> Not really true :-)
>
> >  drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 150 +--
> >  drivers/media/platform/mtk-mdp/mtk_mdp_comp.h |  26 +--
> >  drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 176 +-
> >  drivers/media/platform/mtk-mdp/mtk_mdp_core.h |   1 +
> >  4 files changed, 263 insertions(+), 90 deletions(-)
> >
> > diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c 
> > b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
> > index 362fff924aef..5b4d482df778 100644
> > --- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
> > +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
> > @@ -5,14 +5,53 @@
> >   */
> >
> >  #include 
> > +#include 
> >  #include 
> > -#include 
> > +#include 
> >  #include 
> > +#include 
> > +#include 
> > +#include 
> >  #include 
> >  #include 
> > +#include 
> >
> >  #include "mtk_mdp_comp.h"
> > -
> > +#include "mtk_mdp_core.h"
> > +
> > +/**
> > + * enum mtk_mdp_comp_type - the MDP component
> > + * @MTK_MDP_RDMA:  Read DMA
> > + * @MTK_MDP_RSZ:   Reszer
> > + * @MTK_MDP_WDMA:  Write DMA
> > + * @MTK_MDP_WROT:  Write DMA with rotation
> > + * @MTK_MDP_COMP_TYPE_MAX: Placeholder for num elems in this enum
> > + */
> > +enum mtk_mdp_comp_type {
> > +   MTK_MDP_RDMA,
> > +   MTK_MDP_RSZ,
> > +   MTK_MDP_WDMA,
> > +   MTK_

[PATCH v3 4/5] [media] mtk-mdp: convert mtk_mdp_dev.comp array to list

2020-05-07 Thread Eizan Miyamoto
The functions mtk_mdp_register/unregister_component have been created to
add / remove items from the list of components.

This will eventually enable us to specify a list of components in the
device tree instead of hardcoding them into this driver.

The list is modified by a single thread at driver probe time, and will
not be traversed by another thread until the call to pm_runtime_enable
at the end of probing.

Signed-off-by: Eizan Miyamoto 
Reviewed-by: Enric Balletbo I Serra 
---

Changes in v3: None
Changes in v2: None

 drivers/media/platform/mtk-mdp/mtk_mdp_comp.c |  1 +
 drivers/media/platform/mtk-mdp/mtk_mdp_comp.h |  2 +
 drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 46 +--
 drivers/media/platform/mtk-mdp/mtk_mdp_core.h | 10 +++-
 4 files changed, 43 insertions(+), 16 deletions(-)

diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c 
b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
index c76cd61fb178..da2bdad7a8d1 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
@@ -103,6 +103,7 @@ int mtk_mdp_comp_init(struct device *dev, struct 
device_node *node,
return -EINVAL;
}
 
+   INIT_LIST_HEAD(>node);
comp->dev_node = of_node_get(node);
comp->id = comp_id;
comp->type = mtk_mdp_matches[comp_id].type;
diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h 
b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
index 3b83bd6e0d8b..1f745891c6c3 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
@@ -36,6 +36,7 @@ enum mtk_mdp_comp_id {
 
 /**
  * struct mtk_mdp_comp - the MDP's function component data
+ * @node:  list node to track sibing MDP components
  * @dev_node:  component device node
  * @clk:   clocks required for component
  * @larb_dev:  SMI device required for component
@@ -43,6 +44,7 @@ enum mtk_mdp_comp_id {
  * @id:component ID
  */
 struct mtk_mdp_comp {
+   struct list_headnode;
struct device_node  *dev_node;
struct clk  *clk[2];
struct device   *larb_dev;
diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c 
b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
index 17d155219ba2..40b9fda8b03b 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
@@ -55,19 +55,19 @@ MODULE_DEVICE_TABLE(of, mtk_mdp_of_ids);
 static void mtk_mdp_clock_on(struct mtk_mdp_dev *mdp)
 {
struct device *dev = >pdev->dev;
-   int i;
+   struct mtk_mdp_comp *comp_node;
 
-   for (i = 0; i < ARRAY_SIZE(mdp->comp); i++)
-   mtk_mdp_comp_clock_on(dev, mdp->comp[i]);
+   list_for_each_entry(comp_node, >comp_list, node)
+   mtk_mdp_comp_clock_on(dev, comp_node);
 }
 
 static void mtk_mdp_clock_off(struct mtk_mdp_dev *mdp)
 {
struct device *dev = >pdev->dev;
-   int i;
+   struct mtk_mdp_comp *comp_node;
 
-   for (i = 0; i < ARRAY_SIZE(mdp->comp); i++)
-   mtk_mdp_comp_clock_off(dev, mdp->comp[i]);
+   list_for_each_entry(comp_node, >comp_list, node)
+   mtk_mdp_comp_clock_off(dev, comp_node);
 }
 
 static void mtk_mdp_wdt_worker(struct work_struct *work)
@@ -91,12 +91,25 @@ static void mtk_mdp_reset_handler(void *priv)
queue_work(mdp->wdt_wq, >wdt_work);
 }
 
+void mtk_mdp_register_component(struct mtk_mdp_dev *mdp,
+   struct mtk_mdp_comp *comp)
+{
+   list_add(>comp_list, >node);
+}
+
+void mtk_mdp_unregister_component(struct mtk_mdp_dev *mdp,
+ struct mtk_mdp_comp *comp)
+{
+   list_del(>node);
+}
+
 static int mtk_mdp_probe(struct platform_device *pdev)
 {
struct mtk_mdp_dev *mdp;
struct device *dev = >dev;
struct device_node *node, *parent;
-   int i, ret = 0;
+   struct mtk_mdp_comp *comp, *comp_temp;
+   int ret = 0;
 
mdp = devm_kzalloc(dev, sizeof(*mdp), GFP_KERNEL);
if (!mdp)
@@ -104,6 +117,7 @@ static int mtk_mdp_probe(struct platform_device *pdev)
 
mdp->id = pdev->id;
mdp->pdev = pdev;
+   INIT_LIST_HEAD(>comp_list);
INIT_LIST_HEAD(>ctx_list);
 
mutex_init(>lock);
@@ -124,7 +138,6 @@ static int mtk_mdp_probe(struct platform_device *pdev)
const struct of_device_id *of_id;
enum mtk_mdp_comp_type comp_type;
int comp_id;
-   struct mtk_mdp_comp *comp;
 
of_id = of_match_node(mtk_mdp_comp_dt_ids, node);
if (!of_id)
@@ -150,13 +163,14 @@ static int mtk_mdp_probe(struct platform_device *pdev)
of_node_put(node);
goto err_comp;
}
-   mdp->comp[comp_id] = comp;
 
   

[PATCH v3 5/5] [media] mtk-mdp: Remove mtk_mdp_comp.id and supporting functionality

2020-05-07 Thread Eizan Miyamoto
Since components are registered in a list, the numeric component id that
specified a location in an array is not necessary.

Signed-off-by: Eizan Miyamoto 
---

Changes in v3:
- Removed extra Signed-off-by: tag from commit messages.
- Removed extra line break in mtk_mdp_core.c
- Update cover letter with dependent commit

Changes in v2:
- rebase onto linux-next/master to pick up
  757570f11fa4b0ce5472a6583de6f06e996a8527

 drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 60 +++
 drivers/media/platform/mtk-mdp/mtk_mdp_comp.h | 19 +-
 drivers/media/platform/mtk-mdp/mtk_mdp_core.c |  9 +--
 3 files changed, 10 insertions(+), 78 deletions(-)

diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c 
b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
index da2bdad7a8d1..362fff924aef 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
@@ -14,46 +14,6 @@
 #include "mtk_mdp_comp.h"
 
 
-static const char * const mtk_mdp_comp_stem[MTK_MDP_COMP_TYPE_MAX] = {
-   "mdp-rdma",
-   "mdp-rsz",
-   "mdp-wdma",
-   "mdp-wrot",
-};
-
-struct mtk_mdp_comp_match {
-   enum mtk_mdp_comp_type type;
-   int alias_id;
-};
-
-static const struct mtk_mdp_comp_match mtk_mdp_matches[MTK_MDP_COMP_ID_MAX] = {
-   { MTK_MDP_RDMA, 0 },
-   { MTK_MDP_RDMA, 1 },
-   { MTK_MDP_RSZ,  0 },
-   { MTK_MDP_RSZ,  1 },
-   { MTK_MDP_RSZ,  2 },
-   { MTK_MDP_WDMA, 0 },
-   { MTK_MDP_WROT, 0 },
-   { MTK_MDP_WROT, 1 },
-};
-
-int mtk_mdp_comp_get_id(struct device *dev, struct device_node *node,
-   enum mtk_mdp_comp_type comp_type)
-{
-   int id = of_alias_get_id(node, mtk_mdp_comp_stem[comp_type]);
-   int i;
-
-   for (i = 0; i < ARRAY_SIZE(mtk_mdp_matches); i++) {
-   if (comp_type == mtk_mdp_matches[i].type &&
-   id == mtk_mdp_matches[i].alias_id)
-   return i;
-   }
-
-   dev_err(dev, "Failed to get id. type: %d, id: %d\n", comp_type, id);
-
-   return -EINVAL;
-}
-
 void mtk_mdp_comp_clock_on(struct device *dev, struct mtk_mdp_comp *comp)
 {
int i, err;
@@ -62,8 +22,8 @@ void mtk_mdp_comp_clock_on(struct device *dev, struct 
mtk_mdp_comp *comp)
err = mtk_smi_larb_get(comp->larb_dev);
if (err)
dev_err(dev,
-   "failed to get larb, err %d. type:%d id:%d\n",
-   err, comp->type, comp->id);
+   "failed to get larb, err %d. type:%d\n",
+   err, comp->type);
}
 
for (i = 0; i < ARRAY_SIZE(comp->clk); i++) {
@@ -72,8 +32,8 @@ void mtk_mdp_comp_clock_on(struct device *dev, struct 
mtk_mdp_comp *comp)
err = clk_prepare_enable(comp->clk[i]);
if (err)
dev_err(dev,
-   "failed to enable clock, err %d. type:%d id:%d i:%d\n",
-   err, comp->type, comp->id, i);
+   "failed to enable clock, err %d. type:%d i:%d\n",
+   err, comp->type, i);
}
 }
 
@@ -92,21 +52,15 @@ void mtk_mdp_comp_clock_off(struct device *dev, struct 
mtk_mdp_comp *comp)
 }
 
 int mtk_mdp_comp_init(struct device *dev, struct device_node *node,
- struct mtk_mdp_comp *comp, enum mtk_mdp_comp_id comp_id)
+ struct mtk_mdp_comp *comp,
+ enum mtk_mdp_comp_type comp_type)
 {
struct device_node *larb_node;
struct platform_device *larb_pdev;
int i;
 
-   if (comp_id < 0 || comp_id >= MTK_MDP_COMP_ID_MAX) {
-   dev_err(dev, "Invalid comp_id %d\n", comp_id);
-   return -EINVAL;
-   }
-
-   INIT_LIST_HEAD(>node);
comp->dev_node = of_node_get(node);
-   comp->id = comp_id;
-   comp->type = mtk_mdp_matches[comp_id].type;
+   comp->type = comp_type;
 
for (i = 0; i < ARRAY_SIZE(comp->clk); i++) {
comp->clk[i] = of_clk_get(node, i);
diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h 
b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
index 1f745891c6c3..1bf0242cce46 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
@@ -22,18 +22,6 @@ enum mtk_mdp_comp_type {
MTK_MDP_COMP_TYPE_MAX,
 };
 
-enum mtk_mdp_comp_id {
-   MTK_MDP_COMP_RDMA0,
-   MTK_MDP_COMP_RDMA1,
-   MTK_MDP_COMP_RSZ0,
-   MTK_MDP_COMP_RSZ1,
-   MTK_MDP_COMP_RSZ2,
-   MTK_MDP_COMP_WDMA,
-   MTK_MDP_COMP_WROT0,
-   MTK_MDP_COMP_WROT1,
-   MTK_MDP_COMP_ID_MAX,
-};
-
 /**
  * struct mtk_mdp_comp - the MDP's function component dat

[PATCH v3 3/5] [media] mtk-mdp: handle vpu_wdt_reg_handler() errors during probe

2020-05-07 Thread Eizan Miyamoto
This is a cleanup to better handle errors during MDP probe.

Signed-off-by: Eizan Miyamoto 
Reviewed-by: Enric Balletbo i Serra 
---

Changes in v3: None
Changes in v2:
- remove unnecessary error handling labels in favor of err_m2m_register

 drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c 
b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
index 9b24b8d46eb7..17d155219ba2 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
@@ -188,8 +188,12 @@ static int mtk_mdp_probe(struct platform_device *pdev)
}
 
mdp->vpu_dev = vpu_get_plat_device(pdev);
-   vpu_wdt_reg_handler(mdp->vpu_dev, mtk_mdp_reset_handler, mdp,
-   VPU_RST_MDP);
+   ret = vpu_wdt_reg_handler(mdp->vpu_dev, mtk_mdp_reset_handler, mdp,
+ VPU_RST_MDP);
+   if (ret) {
+   dev_err(>dev, "Failed to register reset handler\n");
+   goto err_m2m_register;
+   }
 
platform_set_drvdata(pdev, mdp);
 
-- 
2.26.2.526.g744177e7f7-goog



[PATCH v3 2/5] [media] mtk-mdp: handle vb2_dma_contig_set_max_seg_size errors during probe

2020-05-07 Thread Eizan Miyamoto
This is a cleanup to better handle errors during MDP probe.

Signed-off-by: Eizan Miyamoto 
Reviewed-by: Enric Balletbo i Serra 
---

Changes in v3: None
Changes in v2:
- remove unnecessary error handling labels in favor of err_m2m_register

 drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c 
b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
index aeaed2cf4458..9b24b8d46eb7 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
@@ -193,7 +193,11 @@ static int mtk_mdp_probe(struct platform_device *pdev)
 
platform_set_drvdata(pdev, mdp);
 
-   vb2_dma_contig_set_max_seg_size(>dev, DMA_BIT_MASK(32));
+   ret = vb2_dma_contig_set_max_seg_size(>dev, DMA_BIT_MASK(32));
+   if (ret) {
+   dev_err(>dev, "Failed to set vb2 dma mag seg size\n");
+   goto err_m2m_register;
+   }
 
pm_runtime_enable(dev);
dev_dbg(dev, "mdp-%d registered successfully\n", mdp->id);
-- 
2.26.2.526.g744177e7f7-goog



[PATCH v3 1/5] [media] mtk-mdp: remove mtk_mdp_comp.regs from mtk_mdp_comp.h

2020-05-07 Thread Eizan Miyamoto
These fields are not used and can be removed.

Signed-off-by: Eizan Miyamoto 
Reviewed-by: Enric Balletbo I Serra 
---

Changes in v3: None
Changes in v2: None

 drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 1 -
 drivers/media/platform/mtk-mdp/mtk_mdp_comp.h | 2 --
 2 files changed, 3 deletions(-)

diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c 
b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
index 58abfbdfb82d..c76cd61fb178 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
@@ -106,7 +106,6 @@ int mtk_mdp_comp_init(struct device *dev, struct 
device_node *node,
comp->dev_node = of_node_get(node);
comp->id = comp_id;
comp->type = mtk_mdp_matches[comp_id].type;
-   comp->regs = of_iomap(node, 0);
 
for (i = 0; i < ARRAY_SIZE(comp->clk); i++) {
comp->clk[i] = of_clk_get(node, i);
diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h 
b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
index 998a4b953025..3b83bd6e0d8b 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
@@ -38,7 +38,6 @@ enum mtk_mdp_comp_id {
  * struct mtk_mdp_comp - the MDP's function component data
  * @dev_node:  component device node
  * @clk:   clocks required for component
- * @regs:  Mapped address of component registers.
  * @larb_dev:  SMI device required for component
  * @type:  component type
  * @id:component ID
@@ -46,7 +45,6 @@ enum mtk_mdp_comp_id {
 struct mtk_mdp_comp {
struct device_node  *dev_node;
struct clk  *clk[2];
-   void __iomem*regs;
struct device   *larb_dev;
enum mtk_mdp_comp_type  type;
enum mtk_mdp_comp_idid;
-- 
2.26.2.526.g744177e7f7-goog



[PATCH v3 0/5] MTK MDP driver cleanups to prep for futher work

2020-05-07 Thread Eizan Miyamoto


It most notably converts an array of MDP components to a list instead,
but also removes some unused fields.

This series of patches does some cleanup in preparation for futher work
so that hardware video decode works on 4.19 and later kernels. We are
planning on adding a dummy driver for the relevant MDP components that
will be bound together using the component framework, which will enable
calls to set up IOMMUs and LARBs, and make calls into pm_runtime.

Note: these changes depend on 757570f11fa4b0ce5472a6583de6f06e996a8527
to apply cleanly.

Changes in v3:
- Removed extra Signed-off-by: tag from commit messages.
- Removed extra line break in mtk_mdp_core.c
- Update cover letter with dependent commit

Changes in v2:
- remove unnecessary error handling labels in favor of err_m2m_register
- remove unnecessary error handling labels in favor of err_m2m_register
- rebase onto linux-next/master to pick up
  757570f11fa4b0ce5472a6583de6f06e996a8527

Eizan Miyamoto (5):
  [media] mtk-mdp: remove mtk_mdp_comp.regs from mtk_mdp_comp.h
  [media] mtk-mdp: handle vb2_dma_contig_set_max_seg_size errors during
probe
  [media] mtk-mdp: handle vpu_wdt_reg_handler() errors during probe
  [media] mtk-mdp: convert mtk_mdp_dev.comp array to list
  [media] mtk-mdp: Remove mtk_mdp_comp.id and supporting functionality

 drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 60 ++--
 drivers/media/platform/mtk-mdp/mtk_mdp_comp.h | 23 ++-
 drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 69 ---
 drivers/media/platform/mtk-mdp/mtk_mdp_core.h | 10 ++-
 4 files changed, 63 insertions(+), 99 deletions(-)

-- 
2.26.2.526.g744177e7f7-goog



[PATCH v2 2/2] [media] mtk-mdp: use pm_runtime in MDP component driver

2020-05-06 Thread Eizan Miyamoto
Without this change, the MDP components are not fully integrated into
the runtime power management subsystem, and the MDP driver does not
work.

For each of the component device drivers to be able to call
pm_runtime_get/put_sync() a pointer to the component's device struct
had to be added to struct mtk_mdp_comp, set by mtk_mdp_comp_init().

Note that the dev argument to mtk_mdp_comp_clock_on/off() has been
removed. Those functions used to be called from the "master" mdp driver
in mtk_mdp_core.c, but the component's device pointer no longer
corresponds to the mdp master device pointer, which is not the right
device to pass to pm_runtime_put/get_sync() which we had to add to get
the driver to work properly.

Signed-off-by: Eizan Miyamoto 
---

Changes in v2:
- remove empty mtk_mdp_comp_init
- update documentation for enum mtk_mdp_comp_type
- remove comma after last element of mtk_mdp_comp_driver_dt_match

 drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 22 ++-
 drivers/media/platform/mtk-mdp/mtk_mdp_comp.h |  6 +++--
 drivers/media/platform/mtk-mdp/mtk_mdp_core.c |  6 ++---
 3 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c 
b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
index 5b4d482df778..228c58f92c8c 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "mtk_mdp_comp.h"
 #include "mtk_mdp_core.h"
@@ -53,7 +54,7 @@ static const struct of_device_id 
mtk_mdp_comp_driver_dt_match[] = {
 };
 MODULE_DEVICE_TABLE(of, mtk_mdp_comp_driver_dt_match);
 
-void mtk_mdp_comp_clock_on(struct device *dev, struct mtk_mdp_comp *comp)
+void mtk_mdp_comp_clock_on(struct mtk_mdp_comp *comp)
 {
int i, err;
 
@@ -62,25 +63,31 @@ void mtk_mdp_comp_clock_on(struct device *dev, struct 
mtk_mdp_comp *comp)
if (err) {
enum mtk_mdp_comp_type comp_type =
(enum mtk_mdp_comp_type)
-   of_device_get_match_data(dev);
-   dev_err(dev,
+   of_device_get_match_data(comp->dev);
+   dev_err(comp->dev,
"failed to get larb, err %d. type:%d\n",
err, comp_type);
}
}
 
+   err = pm_runtime_get_sync(comp->dev);
+   if (err < 0)
+   dev_err(comp->dev,
+   "failed to runtime get, err %d.\n",
+   err);
+
for (i = 0; i < ARRAY_SIZE(comp->clk); i++) {
if (IS_ERR(comp->clk[i]))
continue;
err = clk_prepare_enable(comp->clk[i]);
if (err)
-   dev_err(dev,
+   dev_err(comp->dev,
"failed to enable clock, err %d. i:%d\n",
err, i);
}
 }
 
-void mtk_mdp_comp_clock_off(struct device *dev, struct mtk_mdp_comp *comp)
+void mtk_mdp_comp_clock_off(struct mtk_mdp_comp *comp)
 {
int i;
 
@@ -92,6 +99,8 @@ void mtk_mdp_comp_clock_off(struct device *dev, struct 
mtk_mdp_comp *comp)
 
if (comp->larb_dev)
mtk_smi_larb_put(comp->larb_dev);
+
+   pm_runtime_put_sync(comp->dev);
 }
 
 static int mtk_mdp_comp_bind(struct device *dev, struct device *master,
@@ -101,6 +110,7 @@ static int mtk_mdp_comp_bind(struct device *dev, struct 
device *master,
struct mtk_mdp_dev *mdp = data;
 
mtk_mdp_register_component(mdp, comp);
+   pm_runtime_enable(dev);
 
return 0;
 }
@@ -111,6 +121,7 @@ static void mtk_mdp_comp_unbind(struct device *dev, struct 
device *master,
struct mtk_mdp_dev *mdp = data;
struct mtk_mdp_comp *comp = dev_get_drvdata(dev);
 
+   pm_runtime_disable(dev);
mtk_mdp_unregister_component(mdp, comp);
 }
 
@@ -129,6 +140,7 @@ int mtk_mdp_comp_init(struct mtk_mdp_comp *comp, struct 
device *dev)
 (enum mtk_mdp_comp_type)of_device_get_match_data(dev);
 
INIT_LIST_HEAD(>node);
+   comp->dev = dev;
 
for (i = 0; i < ARRAY_SIZE(comp->clk); i++) {
comp->clk[i] = of_clk_get(node, i);
diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h 
b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
index b5a18fe567aa..de158d3712f6 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
@@ -12,17 +12,19 @@
  * @node:  list node to track sibing MDP components
  * @clk:   clocks required for component
  * @larb_dev:  SMI device required for component
+ * @dev:   component's device
  */
 struct mtk_mdp_comp {
struct list_headnode;
  

[PATCH v2 0/2] Refactor MDP driver and add dummy component driver

2020-05-06 Thread Eizan Miyamoto


This series depends on all changes in the series:
https://patchwork.kernel.org/patch/11530275/

We are adding a dummy MDP component driver so that all the components
are properly configured with IOMMUs and LARBs. This is required for
us to get hardware video decode working in 4.19, and possibly newer
kernels.

Changes in v2:
- remove empty mtk_mdp_comp_init
- update documentation for enum mtk_mdp_comp_type
- remove comma after last element of mtk_mdp_comp_driver_dt_match

Eizan Miyamoto (2):
  [media] mtk-mdp: add driver to probe mdp components
  [media] mtk-mdp: use pm_runtime in MDP component driver

 drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 172 ++---
 drivers/media/platform/mtk-mdp/mtk_mdp_comp.h |  32 +--
 drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 182 --
 drivers/media/platform/mtk-mdp/mtk_mdp_core.h |   1 +
 4 files changed, 286 insertions(+), 101 deletions(-)

-- 
2.26.2.526.g744177e7f7-goog



[PATCH v2 1/2] [media] mtk-mdp: add driver to probe mdp components

2020-05-06 Thread Eizan Miyamoto
Broadly, this patch (1) adds a driver for various MTK MDP components to
go alongside the main MTK MDP driver, and (2) hooks them all together
using the component framework.

(1) Up until now, the MTK MDP driver controls 8 devices in the device
tree on its own. When running tests for the hardware video decoder, we
found that the iommus and LARBs were not being properly configured. To
configure them, a driver for each be added to mtk_mdp_comp so that
mtk_iommu_add_device() can (eventually) be called from dma_configure()
inside really_probe().

(2) The integration into the component framework allows us to defer the
registration with the v4l2 subsystem until all the MDP-related devices
have been probed, so that the relevant device node does not become
available until initialization of all the components is complete.

Some notes about how the component framework has been integrated:

- The driver for the rdma0 component serves double duty as the "master"
  (aggregate) driver as well as a component driver. This is a non-ideal
  compromise until a better solution is developed. This device is
  differentiated from the rest by checking for a "mediatek,vpu" property
  in the device node.

- The list of mdp components remains hard-coded as mtk_mdp_comp_dt_ids[]
  in mtk_mdp_core.c, and as mtk_mdp_comp_driver_dt_match[] in
  mtk_mdp_comp.c. This unfortunate duplication of information is
  addressed in a following patch in this series.

- The component driver calls component_add() for each device that is
  probed.

- In mtk_mdp_probe (the "master" device), we scan the device tree for
  any matching nodes against mtk_mdp_comp_dt_ids, and add component
  matches for them. The match criteria is a matching device node
  pointer.

- When the set of components devices that have been probed corresponds
  with the list that is generated by the "master", the callback to
  mtk_mdp_master_bind() is made, which then calls the component bind
  functions.

- Inside mtk_mdp_master_bind(), once all the component bind functions
  have been called, we can then register our device to the v4l2
  subsystem.

- The call to pm_runtime_enable() in the master device is called after
  all the components have been registered by their bind() functions
  called by mtk_mtp_master_bind(). As a result, the list of components
  will not change while power management callbacks mtk_mdp_suspend()/
  resume() are accessing the list of components.

Signed-off-by: Eizan Miyamoto 
---

Changes in v2: None

 drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 150 +--
 drivers/media/platform/mtk-mdp/mtk_mdp_comp.h |  26 +--
 drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 176 +-
 drivers/media/platform/mtk-mdp/mtk_mdp_core.h |   1 +
 4 files changed, 263 insertions(+), 90 deletions(-)

diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c 
b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
index 362fff924aef..5b4d482df778 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
@@ -5,14 +5,53 @@
  */
 
 #include 
+#include 
 #include 
-#include 
+#include 
 #include 
+#include 
+#include 
+#include 
 #include 
 #include 
+#include 
 
 #include "mtk_mdp_comp.h"
-
+#include "mtk_mdp_core.h"
+
+/**
+ * enum mtk_mdp_comp_type - the MDP component
+ * @MTK_MDP_RDMA:  Read DMA
+ * @MTK_MDP_RSZ:   Reszer
+ * @MTK_MDP_WDMA:  Write DMA
+ * @MTK_MDP_WROT:  Write DMA with rotation
+ * @MTK_MDP_COMP_TYPE_MAX: Placeholder for num elems in this enum
+ */
+enum mtk_mdp_comp_type {
+   MTK_MDP_RDMA,
+   MTK_MDP_RSZ,
+   MTK_MDP_WDMA,
+   MTK_MDP_WROT,
+   MTK_MDP_COMP_TYPE_MAX,
+};
+
+static const struct of_device_id mtk_mdp_comp_driver_dt_match[] = {
+   {
+   .compatible = "mediatek,mt8173-mdp-rdma",
+   .data = (void *)MTK_MDP_RDMA
+   }, {
+   .compatible = "mediatek,mt8173-mdp-rsz",
+   .data = (void *)MTK_MDP_RSZ
+   }, {
+   .compatible = "mediatek,mt8173-mdp-wdma",
+   .data = (void *)MTK_MDP_WDMA
+   }, {
+   .compatible = "mediatek,mt8173-mdp-wrot",
+   .data = (void *)MTK_MDP_WROT
+   },
+   { }
+};
+MODULE_DEVICE_TABLE(of, mtk_mdp_comp_driver_dt_match);
 
 void mtk_mdp_comp_clock_on(struct device *dev, struct mtk_mdp_comp *comp)
 {
@@ -20,10 +59,14 @@ void mtk_mdp_comp_clock_on(struct device *dev, struct 
mtk_mdp_comp *comp)
 
if (comp->larb_dev) {
err = mtk_smi_larb_get(comp->larb_dev);
-   if (err)
+   if (err) {
+   enum mtk_mdp_comp_type comp_type =
+   (enum mtk_mdp_comp_type)
+   of_device_get_match_data(dev);
dev_err(dev,
  

[PATCH v2 5/5] [media] mtk-mdp: Remove mtk_mdp_comp.id and supporting functionality

2020-05-05 Thread Eizan Miyamoto
Since components are registered in a list, the numeric component id that
specified a location in an array is not necessary.

Signed-off-by: ei...@chromium.org
Signed-off-by: Eizan Miyamoto 
---

Changes in v1:
- rebase onto linux-next/master to pick up
  757570f11fa4b0ce5472a6583de6f06e996a8527

 drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 60 +++
 drivers/media/platform/mtk-mdp/mtk_mdp_comp.h | 19 +-
 drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 10 +---
 3 files changed, 11 insertions(+), 78 deletions(-)

diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c 
b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
index da2bdad7a8d1..362fff924aef 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
@@ -14,46 +14,6 @@
 #include "mtk_mdp_comp.h"
 
 
-static const char * const mtk_mdp_comp_stem[MTK_MDP_COMP_TYPE_MAX] = {
-   "mdp-rdma",
-   "mdp-rsz",
-   "mdp-wdma",
-   "mdp-wrot",
-};
-
-struct mtk_mdp_comp_match {
-   enum mtk_mdp_comp_type type;
-   int alias_id;
-};
-
-static const struct mtk_mdp_comp_match mtk_mdp_matches[MTK_MDP_COMP_ID_MAX] = {
-   { MTK_MDP_RDMA, 0 },
-   { MTK_MDP_RDMA, 1 },
-   { MTK_MDP_RSZ,  0 },
-   { MTK_MDP_RSZ,  1 },
-   { MTK_MDP_RSZ,  2 },
-   { MTK_MDP_WDMA, 0 },
-   { MTK_MDP_WROT, 0 },
-   { MTK_MDP_WROT, 1 },
-};
-
-int mtk_mdp_comp_get_id(struct device *dev, struct device_node *node,
-   enum mtk_mdp_comp_type comp_type)
-{
-   int id = of_alias_get_id(node, mtk_mdp_comp_stem[comp_type]);
-   int i;
-
-   for (i = 0; i < ARRAY_SIZE(mtk_mdp_matches); i++) {
-   if (comp_type == mtk_mdp_matches[i].type &&
-   id == mtk_mdp_matches[i].alias_id)
-   return i;
-   }
-
-   dev_err(dev, "Failed to get id. type: %d, id: %d\n", comp_type, id);
-
-   return -EINVAL;
-}
-
 void mtk_mdp_comp_clock_on(struct device *dev, struct mtk_mdp_comp *comp)
 {
int i, err;
@@ -62,8 +22,8 @@ void mtk_mdp_comp_clock_on(struct device *dev, struct 
mtk_mdp_comp *comp)
err = mtk_smi_larb_get(comp->larb_dev);
if (err)
dev_err(dev,
-   "failed to get larb, err %d. type:%d id:%d\n",
-   err, comp->type, comp->id);
+   "failed to get larb, err %d. type:%d\n",
+   err, comp->type);
}
 
for (i = 0; i < ARRAY_SIZE(comp->clk); i++) {
@@ -72,8 +32,8 @@ void mtk_mdp_comp_clock_on(struct device *dev, struct 
mtk_mdp_comp *comp)
err = clk_prepare_enable(comp->clk[i]);
if (err)
dev_err(dev,
-   "failed to enable clock, err %d. type:%d id:%d i:%d\n",
-   err, comp->type, comp->id, i);
+   "failed to enable clock, err %d. type:%d i:%d\n",
+   err, comp->type, i);
}
 }
 
@@ -92,21 +52,15 @@ void mtk_mdp_comp_clock_off(struct device *dev, struct 
mtk_mdp_comp *comp)
 }
 
 int mtk_mdp_comp_init(struct device *dev, struct device_node *node,
- struct mtk_mdp_comp *comp, enum mtk_mdp_comp_id comp_id)
+ struct mtk_mdp_comp *comp,
+ enum mtk_mdp_comp_type comp_type)
 {
struct device_node *larb_node;
struct platform_device *larb_pdev;
int i;
 
-   if (comp_id < 0 || comp_id >= MTK_MDP_COMP_ID_MAX) {
-   dev_err(dev, "Invalid comp_id %d\n", comp_id);
-   return -EINVAL;
-   }
-
-   INIT_LIST_HEAD(>node);
comp->dev_node = of_node_get(node);
-   comp->id = comp_id;
-   comp->type = mtk_mdp_matches[comp_id].type;
+   comp->type = comp_type;
 
for (i = 0; i < ARRAY_SIZE(comp->clk); i++) {
comp->clk[i] = of_clk_get(node, i);
diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h 
b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
index 1f745891c6c3..1bf0242cce46 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
@@ -22,18 +22,6 @@ enum mtk_mdp_comp_type {
MTK_MDP_COMP_TYPE_MAX,
 };
 
-enum mtk_mdp_comp_id {
-   MTK_MDP_COMP_RDMA0,
-   MTK_MDP_COMP_RDMA1,
-   MTK_MDP_COMP_RSZ0,
-   MTK_MDP_COMP_RSZ1,
-   MTK_MDP_COMP_RSZ2,
-   MTK_MDP_COMP_WDMA,
-   MTK_MDP_COMP_WROT0,
-   MTK_MDP_COMP_WROT1,
-   MTK_MDP_COMP_ID_MAX,
-};
-
 /**
  * struct mtk_mdp_comp - the MDP's function component data
  * @node:  list node to track sibing MDP components
@@ -41,7 +29,6 @@ enum mtk_mdp_comp_id {
  * @clk:   clocks re

[PATCH v2 4/5] [media] mtk-mdp: convert mtk_mdp_dev.comp array to list

2020-05-05 Thread Eizan Miyamoto
The functions mtk_mdp_register/unregister_component have been created to
add / remove items from the list of components.

This will eventually enable us to specify a list of components in the
device tree instead of hardcoding them into this driver.

The list is modified by a single thread at driver probe time, and will
not be traversed by another thread until the call to pm_runtime_enable
at the end of probing.

Signed-off-by: ei...@chromium.org
Reviewed-by: Enric Balletbo I Serra 
Signed-off-by: Eizan Miyamoto 
---

Changes in v1: None

 drivers/media/platform/mtk-mdp/mtk_mdp_comp.c |  1 +
 drivers/media/platform/mtk-mdp/mtk_mdp_comp.h |  2 +
 drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 46 +--
 drivers/media/platform/mtk-mdp/mtk_mdp_core.h | 10 +++-
 4 files changed, 43 insertions(+), 16 deletions(-)

diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c 
b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
index c76cd61fb178..da2bdad7a8d1 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
@@ -103,6 +103,7 @@ int mtk_mdp_comp_init(struct device *dev, struct 
device_node *node,
return -EINVAL;
}
 
+   INIT_LIST_HEAD(>node);
comp->dev_node = of_node_get(node);
comp->id = comp_id;
comp->type = mtk_mdp_matches[comp_id].type;
diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h 
b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
index 3b83bd6e0d8b..1f745891c6c3 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
@@ -36,6 +36,7 @@ enum mtk_mdp_comp_id {
 
 /**
  * struct mtk_mdp_comp - the MDP's function component data
+ * @node:  list node to track sibing MDP components
  * @dev_node:  component device node
  * @clk:   clocks required for component
  * @larb_dev:  SMI device required for component
@@ -43,6 +44,7 @@ enum mtk_mdp_comp_id {
  * @id:component ID
  */
 struct mtk_mdp_comp {
+   struct list_headnode;
struct device_node  *dev_node;
struct clk  *clk[2];
struct device   *larb_dev;
diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c 
b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
index 17d155219ba2..40b9fda8b03b 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
@@ -55,19 +55,19 @@ MODULE_DEVICE_TABLE(of, mtk_mdp_of_ids);
 static void mtk_mdp_clock_on(struct mtk_mdp_dev *mdp)
 {
struct device *dev = >pdev->dev;
-   int i;
+   struct mtk_mdp_comp *comp_node;
 
-   for (i = 0; i < ARRAY_SIZE(mdp->comp); i++)
-   mtk_mdp_comp_clock_on(dev, mdp->comp[i]);
+   list_for_each_entry(comp_node, >comp_list, node)
+   mtk_mdp_comp_clock_on(dev, comp_node);
 }
 
 static void mtk_mdp_clock_off(struct mtk_mdp_dev *mdp)
 {
struct device *dev = >pdev->dev;
-   int i;
+   struct mtk_mdp_comp *comp_node;
 
-   for (i = 0; i < ARRAY_SIZE(mdp->comp); i++)
-   mtk_mdp_comp_clock_off(dev, mdp->comp[i]);
+   list_for_each_entry(comp_node, >comp_list, node)
+   mtk_mdp_comp_clock_off(dev, comp_node);
 }
 
 static void mtk_mdp_wdt_worker(struct work_struct *work)
@@ -91,12 +91,25 @@ static void mtk_mdp_reset_handler(void *priv)
queue_work(mdp->wdt_wq, >wdt_work);
 }
 
+void mtk_mdp_register_component(struct mtk_mdp_dev *mdp,
+   struct mtk_mdp_comp *comp)
+{
+   list_add(>comp_list, >node);
+}
+
+void mtk_mdp_unregister_component(struct mtk_mdp_dev *mdp,
+ struct mtk_mdp_comp *comp)
+{
+   list_del(>node);
+}
+
 static int mtk_mdp_probe(struct platform_device *pdev)
 {
struct mtk_mdp_dev *mdp;
struct device *dev = >dev;
struct device_node *node, *parent;
-   int i, ret = 0;
+   struct mtk_mdp_comp *comp, *comp_temp;
+   int ret = 0;
 
mdp = devm_kzalloc(dev, sizeof(*mdp), GFP_KERNEL);
if (!mdp)
@@ -104,6 +117,7 @@ static int mtk_mdp_probe(struct platform_device *pdev)
 
mdp->id = pdev->id;
mdp->pdev = pdev;
+   INIT_LIST_HEAD(>comp_list);
INIT_LIST_HEAD(>ctx_list);
 
mutex_init(>lock);
@@ -124,7 +138,6 @@ static int mtk_mdp_probe(struct platform_device *pdev)
const struct of_device_id *of_id;
enum mtk_mdp_comp_type comp_type;
int comp_id;
-   struct mtk_mdp_comp *comp;
 
of_id = of_match_node(mtk_mdp_comp_dt_ids, node);
if (!of_id)
@@ -150,13 +163,14 @@ static int mtk_mdp_probe(struct platform_device *pdev)
of_node_put(node);
goto err_comp;
}
-   mdp->comp[comp_id] = comp;
 
   

[PATCH v2 1/5] [media] mtk-mdp: remove mtk_mdp_comp.regs from mtk_mdp_comp.h

2020-05-05 Thread Eizan Miyamoto
These fields are not used and can be removed.

Signed-off-by: ei...@chromium.org
Reviewed-by: Enric Balletbo I Serra 
Signed-off-by: Eizan Miyamoto 
---

Changes in v1: None

 drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 1 -
 drivers/media/platform/mtk-mdp/mtk_mdp_comp.h | 2 --
 2 files changed, 3 deletions(-)

diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c 
b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
index 58abfbdfb82d..c76cd61fb178 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
@@ -106,7 +106,6 @@ int mtk_mdp_comp_init(struct device *dev, struct 
device_node *node,
comp->dev_node = of_node_get(node);
comp->id = comp_id;
comp->type = mtk_mdp_matches[comp_id].type;
-   comp->regs = of_iomap(node, 0);
 
for (i = 0; i < ARRAY_SIZE(comp->clk); i++) {
comp->clk[i] = of_clk_get(node, i);
diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h 
b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
index 998a4b953025..3b83bd6e0d8b 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
@@ -38,7 +38,6 @@ enum mtk_mdp_comp_id {
  * struct mtk_mdp_comp - the MDP's function component data
  * @dev_node:  component device node
  * @clk:   clocks required for component
- * @regs:  Mapped address of component registers.
  * @larb_dev:  SMI device required for component
  * @type:  component type
  * @id:component ID
@@ -46,7 +45,6 @@ enum mtk_mdp_comp_id {
 struct mtk_mdp_comp {
struct device_node  *dev_node;
struct clk  *clk[2];
-   void __iomem*regs;
struct device   *larb_dev;
enum mtk_mdp_comp_type  type;
enum mtk_mdp_comp_idid;
-- 
2.26.2.526.g744177e7f7-goog



[PATCH v2 0/5] MTK MDP driver cleanups to prep for futher work

2020-05-05 Thread Eizan Miyamoto


It most notably converts an array of MDP components to a list instead,
but also removes some unused fields.

This series of patches does some cleanup in preparation for futher work
so that hardware video decode works on 4.19 and later kernels. We are
planning on adding a dummy driver for the relevant MDP components that
will be bound together using the component framework, which will enable
calls to set up IOMMUs and LARBs, and make calls into pm_runtime.

Changes in v2:
- remove unnecessary error handling labels in favor of err_m2m_register
- rebase onto linux-next/master to pick up
  757570f11fa4b0ce5472a6583de6f06e996a8527

Eizan Miyamoto (5):
  [media] mtk-mdp: remove mtk_mdp_comp.regs from mtk_mdp_comp.h
  [media] mtk-mdp: handle vb2_dma_contig_set_max_seg_size errors during
probe
  [media] mtk-mdp: handle vpu_wdt_reg_handler() errors during probe
  [media] mtk-mdp: convert mtk_mdp_dev.comp array to list
  [media] mtk-mdp: Remove mtk_mdp_comp.id and supporting functionality

 drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 60 ++--
 drivers/media/platform/mtk-mdp/mtk_mdp_comp.h | 23 ++
 drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 70 ---
 drivers/media/platform/mtk-mdp/mtk_mdp_core.h | 10 ++-
 4 files changed, 64 insertions(+), 99 deletions(-)

-- 
2.26.2.526.g744177e7f7-goog



[PATCH v2 3/5] [media] mtk-mdp: handle vpu_wdt_reg_handler() errors during probe

2020-05-05 Thread Eizan Miyamoto
This is a cleanup to better handle errors during MDP probe.

Signed-off-by: ei...@chromium.org
Signed-off-by: Eizan Miyamoto 
---

Changes in v1:
- remove unnecessary error handling labels in favor of err_m2m_register

 drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c 
b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
index 9b24b8d46eb7..17d155219ba2 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
@@ -188,8 +188,12 @@ static int mtk_mdp_probe(struct platform_device *pdev)
}
 
mdp->vpu_dev = vpu_get_plat_device(pdev);
-   vpu_wdt_reg_handler(mdp->vpu_dev, mtk_mdp_reset_handler, mdp,
-   VPU_RST_MDP);
+   ret = vpu_wdt_reg_handler(mdp->vpu_dev, mtk_mdp_reset_handler, mdp,
+ VPU_RST_MDP);
+   if (ret) {
+   dev_err(>dev, "Failed to register reset handler\n");
+   goto err_m2m_register;
+   }
 
platform_set_drvdata(pdev, mdp);
 
-- 
2.26.2.526.g744177e7f7-goog



[PATCH v2 2/5] [media] mtk-mdp: handle vb2_dma_contig_set_max_seg_size errors during probe

2020-05-05 Thread Eizan Miyamoto
This is a cleanup to better handle errors during MDP probe.

Signed-off-by: ei...@chromium.org
Signed-off-by: Eizan Miyamoto 
---

Changes in v1:
- remove unnecessary error handling labels in favor of err_m2m_register

 drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c 
b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
index aeaed2cf4458..9b24b8d46eb7 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
@@ -193,7 +193,11 @@ static int mtk_mdp_probe(struct platform_device *pdev)
 
platform_set_drvdata(pdev, mdp);
 
-   vb2_dma_contig_set_max_seg_size(>dev, DMA_BIT_MASK(32));
+   ret = vb2_dma_contig_set_max_seg_size(>dev, DMA_BIT_MASK(32));
+   if (ret) {
+   dev_err(>dev, "Failed to set vb2 dma mag seg size\n");
+   goto err_m2m_register;
+   }
 
pm_runtime_enable(dev);
dev_dbg(dev, "mdp-%d registered successfully\n", mdp->id);
-- 
2.26.2.526.g744177e7f7-goog



[PATCH v2] [media] mtk-mdp: Remove states for format checks

2020-05-05 Thread Eizan Miyamoto
From: Francois Buergisser 

The mtk-mdp driver uses states to check if the formats have been set
on the capture and output when turning the streaming on, setting
controls or setting the selection rectangles.
Those states are reset when 0 buffers are requested like when checking
capabilities.
This patch removes all format checks and set one by default as queues in
V4L2 are expected to always have a format set.

https://linuxtv.org/downloads/v4l-dvb-apis/uapi/v4l/vidioc-streamon.html
https://linuxtv.org/downloads/v4l-dvb-apis/uapi/v4l/vidioc-g-ctrl.html
https://linuxtv.org/downloads/v4l-dvb-apis/uapi/v4l/vidioc-g-selection.html

Signed-off-by: Francois Buergisser 
Signed-off-by: Eizan Miyamoto 
Reviewed-by: Enric Balletbo I Serra 
---

 drivers/media/platform/mtk-mdp/mtk_mdp_core.h |  2 -
 drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c  | 90 +++
 2 files changed, 34 insertions(+), 58 deletions(-)

diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_core.h 
b/drivers/media/platform/mtk-mdp/mtk_mdp_core.h
index bafcccd71f31..dd130cc218c9 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_core.h
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_core.h
@@ -28,8 +28,6 @@
 #define MTK_MDP_FMT_FLAG_CAPTURE   BIT(1)
 
 #define MTK_MDP_VPU_INIT   BIT(0)
-#define MTK_MDP_SRC_FMTBIT(1)
-#define MTK_MDP_DST_FMTBIT(2)
 #define MTK_MDP_CTX_ERROR  BIT(5)
 
 /**
diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c 
b/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
index 821f2cf325f0..bb9caaf513bc 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
@@ -369,13 +369,6 @@ void mtk_mdp_ctx_state_lock_set(struct mtk_mdp_ctx *ctx, 
u32 state)
mutex_unlock(>slock);
 }
 
-static void mtk_mdp_ctx_state_lock_clear(struct mtk_mdp_ctx *ctx, u32 state)
-{
-   mutex_lock(>slock);
-   ctx->state &= ~state;
-   mutex_unlock(>slock);
-}
-
 static bool mtk_mdp_ctx_state_is_set(struct mtk_mdp_ctx *ctx, u32 mask)
 {
bool ret;
@@ -726,11 +719,6 @@ static int mtk_mdp_m2m_s_fmt_mplane(struct file *file, 
void *fh,
ctx->quant = pix_mp->quantization;
}
 
-   if (V4L2_TYPE_IS_OUTPUT(f->type))
-   mtk_mdp_ctx_state_lock_set(ctx, MTK_MDP_SRC_FMT);
-   else
-   mtk_mdp_ctx_state_lock_set(ctx, MTK_MDP_DST_FMT);
-
mtk_mdp_dbg(2, "[%d] type:%d, frame:%dx%d", ctx->id, f->type,
frame->width, frame->height);
 
@@ -742,13 +730,6 @@ static int mtk_mdp_m2m_reqbufs(struct file *file, void *fh,
 {
struct mtk_mdp_ctx *ctx = fh_to_ctx(fh);
 
-   if (reqbufs->count == 0) {
-   if (reqbufs->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
-   mtk_mdp_ctx_state_lock_clear(ctx, MTK_MDP_SRC_FMT);
-   else
-   mtk_mdp_ctx_state_lock_clear(ctx, MTK_MDP_DST_FMT);
-   }
-
return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, reqbufs);
 }
 
@@ -758,14 +739,6 @@ static int mtk_mdp_m2m_streamon(struct file *file, void 
*fh,
struct mtk_mdp_ctx *ctx = fh_to_ctx(fh);
int ret;
 
-   /* The source and target color format need to be set */
-   if (V4L2_TYPE_IS_OUTPUT(type)) {
-   if (!mtk_mdp_ctx_state_is_set(ctx, MTK_MDP_SRC_FMT))
-   return -EINVAL;
-   } else if (!mtk_mdp_ctx_state_is_set(ctx, MTK_MDP_DST_FMT)) {
-   return -EINVAL;
-   }
-
if (!mtk_mdp_ctx_state_is_set(ctx, MTK_MDP_VPU_INIT)) {
ret = mtk_mdp_vpu_init(>vpu);
if (ret < 0) {
@@ -899,24 +872,21 @@ static int mtk_mdp_m2m_s_selection(struct file *file, 
void *fh,
frame = >d_frame;
 
/* Check to see if scaling ratio is within supported range */
-   if (mtk_mdp_ctx_state_is_set(ctx, MTK_MDP_DST_FMT | MTK_MDP_SRC_FMT)) {
-   if (V4L2_TYPE_IS_OUTPUT(s->type)) {
-   ret = mtk_mdp_check_scaler_ratio(variant, new_r.width,
-   new_r.height, ctx->d_frame.crop.width,
-   ctx->d_frame.crop.height,
-   ctx->ctrls.rotate->val);
-   } else {
-   ret = mtk_mdp_check_scaler_ratio(variant,
-   ctx->s_frame.crop.width,
-   ctx->s_frame.crop.height, new_r.width,
-   new_r.height, ctx->ctrls.rotate->val);
-   }
+   if (V4L2_TYPE_IS_OUTPUT(s->type))
+   ret = mtk_mdp_check_scaler_ratio(variant, new_r.width,
+   new_r.height, ctx->d_frame.crop.width,
+   ctx->d_frame.crop.height,
+   ctx->ctrls.rotate->val);
+   else
+   ret = mtk_m

[PATCH v1 2/2] [media] mtk-mdp: use pm_runtime in MDP component driver

2020-05-05 Thread Eizan Miyamoto
Without this change, the MDP components are not fully integrated into
the runtime power management subsystem, and the MDP driver does not
work.

For each of the component device drivers to be able to call
pm_runtime_get/put_sync() a pointer to the component's device struct
had to be added to struct mtk_mdp_comp, set by mtk_mdp_comp_init().

Note that the dev argument to mtk_mdp_comp_clock_on/off() has been
removed. Those functions used to be called from the "master" mdp driver
in mtk_mdp_core.c, but the component's device pointer no longer
corresponds to the mdp master device pointer, which is not the right
device to pass to pm_runtime_put/get_sync() which we had to add to get
the driver to work properly.

Signed-off-by: ei...@chromium.org
Signed-off-by: Eizan Miyamoto 
---

 drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 22 ++-
 drivers/media/platform/mtk-mdp/mtk_mdp_comp.h |  6 +++--
 drivers/media/platform/mtk-mdp/mtk_mdp_core.c |  6 ++---
 3 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c 
b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
index 4c77a582c79a..6716baaf8788 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "mtk_mdp_comp.h"
 #include "mtk_mdp_core.h"
@@ -52,7 +53,7 @@ static const struct of_device_id 
mtk_mdp_comp_driver_dt_match[] = {
 };
 MODULE_DEVICE_TABLE(of, mtk_mdp_comp_driver_dt_match);
 
-void mtk_mdp_comp_clock_on(struct device *dev, struct mtk_mdp_comp *comp)
+void mtk_mdp_comp_clock_on(struct mtk_mdp_comp *comp)
 {
int i, err;
 
@@ -61,25 +62,31 @@ void mtk_mdp_comp_clock_on(struct device *dev, struct 
mtk_mdp_comp *comp)
if (err) {
enum mtk_mdp_comp_type comp_type =
(enum mtk_mdp_comp_type)
-   of_device_get_match_data(dev);
-   dev_err(dev,
+   of_device_get_match_data(comp->dev);
+   dev_err(comp->dev,
"failed to get larb, err %d. type:%d\n",
err, comp_type);
}
}
 
+   err = pm_runtime_get_sync(comp->dev);
+   if (err < 0)
+   dev_err(comp->dev,
+   "failed to runtime get, err %d.\n",
+   err);
+
for (i = 0; i < ARRAY_SIZE(comp->clk); i++) {
if (IS_ERR(comp->clk[i]))
continue;
err = clk_prepare_enable(comp->clk[i]);
if (err)
-   dev_err(dev,
+   dev_err(comp->dev,
"failed to enable clock, err %d. i:%d\n",
err, i);
}
 }
 
-void mtk_mdp_comp_clock_off(struct device *dev, struct mtk_mdp_comp *comp)
+void mtk_mdp_comp_clock_off(struct mtk_mdp_comp *comp)
 {
int i;
 
@@ -91,6 +98,8 @@ void mtk_mdp_comp_clock_off(struct device *dev, struct 
mtk_mdp_comp *comp)
 
if (comp->larb_dev)
mtk_smi_larb_put(comp->larb_dev);
+
+   pm_runtime_put_sync(comp->dev);
 }
 
 static int mtk_mdp_comp_bind(struct device *dev, struct device *master,
@@ -100,6 +109,7 @@ static int mtk_mdp_comp_bind(struct device *dev, struct 
device *master,
struct mtk_mdp_dev *mdp = data;
 
mtk_mdp_register_component(mdp, comp);
+   pm_runtime_enable(dev);
 
return 0;
 }
@@ -110,6 +120,7 @@ static void mtk_mdp_comp_unbind(struct device *dev, struct 
device *master,
struct mtk_mdp_dev *mdp = data;
struct mtk_mdp_comp *comp = dev_get_drvdata(dev);
 
+   pm_runtime_disable(dev);
mtk_mdp_unregister_component(mdp, comp);
 }
 
@@ -128,6 +139,7 @@ int mtk_mdp_comp_init(struct mtk_mdp_comp *comp, struct 
device *dev)
 (enum mtk_mdp_comp_type)of_device_get_match_data(dev);
 
INIT_LIST_HEAD(>node);
+   comp->dev = dev;
 
for (i = 0; i < ARRAY_SIZE(comp->clk); i++) {
comp->clk[i] = of_clk_get(node, i);
diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h 
b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
index edc2ece717b5..91407150ac9e 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
@@ -12,18 +12,20 @@
  * @node:  list node to track sibing MDP components
  * @clk:   clocks required for component
  * @larb_dev:  SMI device required for component
+ * @dev:   component's device
  */
 struct mtk_mdp_comp {
struct list_headnode;
struct clk  *clk[2];
struct device   *larb_dev;
+   struct device   *dev;
 };
 
 int mtk_mdp_comp_

[PATCH v1 1/2] [media] mtk-mdp: add driver to probe mdp components

2020-05-05 Thread Eizan Miyamoto
Broadly, this patch (1) adds a driver for various MTK MDP components to
go alongside the main MTK MDP driver, and (2) hooks them all together
using the component framework.

(1) Up until now, the MTK MDP driver controls 8 devices in the device
tree on its own. When running tests for the hardware video decoder, we
found that the iommus and LARBs were not being properly configured. To
configure them, a driver for each be added to mtk_mdp_comp so that
mtk_iommu_add_device() can (eventually) be called from dma_configure()
inside really_probe().

(2) The integration into the component framework allows us to defer the
registration with the v4l2 subsystem until all the MDP-related devices
have been probed, so that the relevant device node does not become
available until initialization of all the components is complete.

Some notes about how the component framework has been integrated:

- The driver for the rdma0 component serves double duty as the "master"
  (aggregate) driver as well as a component driver. This is a non-ideal
  compromise until a better solution is developed. This device is
  differentiated from the rest by checking for a "mediatek,vpu" property
  in the device node.

- The list of mdp components remains hard-coded as mtk_mdp_comp_dt_ids[]
  in mtk_mdp_core.c, and as mtk_mdp_comp_driver_dt_match[] in
  mtk_mdp_comp.c. This unfortunate duplication of information is
  addressed in a following patch in this series.

- The component driver calls component_add() for each device that is
  probed.

- In mtk_mdp_probe (the "master" device), we scan the device tree for
  any matching nodes against mtk_mdp_comp_dt_ids, and add component
  matches for them. The match criteria is a matching device node
  pointer.

- When the set of components devices that have been probed corresponds
  with the list that is generated by the "master", the callback to
  mtk_mdp_master_bind() is made, which then calls the component bind
  functions.

- Inside mtk_mdp_master_bind(), once all the component bind functions
  have been called, we can then register our device to the v4l2
  subsystem.

- The call to pm_runtime_enable() in the master device is called after
  all the components have been registered by their bind() functions
  called by mtk_mtp_master_bind(). As a result, the list of components
  will not change while power management callbacks mtk_mdp_suspend()/
  resume() are accessing the list of components.

Signed-off-by: ei...@chromium.org
Signed-off-by: Eizan Miyamoto 
---

 drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 164 +++--
 drivers/media/platform/mtk-mdp/mtk_mdp_comp.h |  27 +--
 drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 171 +-
 drivers/media/platform/mtk-mdp/mtk_mdp_core.h |   1 +
 4 files changed, 274 insertions(+), 89 deletions(-)

diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c 
b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
index 362fff924aef..4c77a582c79a 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
@@ -5,14 +5,52 @@
  */
 
 #include 
+#include 
 #include 
-#include 
+#include 
 #include 
+#include 
+#include 
+#include 
 #include 
 #include 
+#include 
 
 #include "mtk_mdp_comp.h"
-
+#include "mtk_mdp_core.h"
+
+/**
+ * enum mtk_mdp_comp_type - the MDP component
+ * @MTK_MDP_RDMA:  Read DMA
+ * @MTK_MDP_RSZ:   Riszer
+ * @MTK_MDP_WDMA:  Write DMA
+ * @MTK_MDP_WROT:  Write DMA with rotation
+ */
+enum mtk_mdp_comp_type {
+   MTK_MDP_RDMA,
+   MTK_MDP_RSZ,
+   MTK_MDP_WDMA,
+   MTK_MDP_WROT,
+   MTK_MDP_COMP_TYPE_MAX,
+};
+
+static const struct of_device_id mtk_mdp_comp_driver_dt_match[] = {
+   {
+   .compatible = "mediatek,mt8173-mdp-rdma",
+   .data = (void *)MTK_MDP_RDMA
+   }, {
+   .compatible = "mediatek,mt8173-mdp-rsz",
+   .data = (void *)MTK_MDP_RSZ
+   }, {
+   .compatible = "mediatek,mt8173-mdp-wdma",
+   .data = (void *)MTK_MDP_WDMA
+   }, {
+   .compatible = "mediatek,mt8173-mdp-wrot",
+   .data = (void *)MTK_MDP_WROT
+   },
+   { },
+};
+MODULE_DEVICE_TABLE(of, mtk_mdp_comp_driver_dt_match);
 
 void mtk_mdp_comp_clock_on(struct device *dev, struct mtk_mdp_comp *comp)
 {
@@ -20,10 +58,14 @@ void mtk_mdp_comp_clock_on(struct device *dev, struct 
mtk_mdp_comp *comp)
 
if (comp->larb_dev) {
err = mtk_smi_larb_get(comp->larb_dev);
-   if (err)
+   if (err) {
+   enum mtk_mdp_comp_type comp_type =
+   (enum mtk_mdp_comp_type)
+   of_device_get_match_data(dev);
dev_err(dev,
"failed to get larb, err %

[PATCH v1 0/2] Refactor MDP driver and add dummy component driver

2020-05-05 Thread Eizan Miyamoto


This series depends on changes in
https://patchwork.kernel.org/patch/11528171/

We are adding a dummy MDP component driver so that all the components
are properly configured with IOMMUs and LARBs. This is required for
us to get hardware video decode working in 4.19, and possibly newer
kernels.


Eizan Miyamoto (2):
  [media] mtk-mdp: add driver to probe mdp components
  [media] mtk-mdp: use pm_runtime in MDP component driver

 drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 186 +++---
 drivers/media/platform/mtk-mdp/mtk_mdp_comp.h |  33 +---
 drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 177 -
 drivers/media/platform/mtk-mdp/mtk_mdp_core.h |   1 +
 4 files changed, 297 insertions(+), 100 deletions(-)

-- 
2.26.2.526.g744177e7f7-goog



[PATCH v1 3/5] [media] mtk-mdp: handle vpu_wdt_reg_handler() errors during probe

2020-05-04 Thread Eizan Miyamoto
This is a cleanup to better handle errors during MDP probe.

Signed-off-by: ei...@chromium.org
Signed-off-by: Eizan Miyamoto 
---

 drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c 
b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
index c20ac7681c6f..f974242663dc 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
@@ -188,8 +188,12 @@ static int mtk_mdp_probe(struct platform_device *pdev)
}
 
mdp->vpu_dev = vpu_get_plat_device(pdev);
-   vpu_wdt_reg_handler(mdp->vpu_dev, mtk_mdp_reset_handler, mdp,
-   VPU_RST_MDP);
+   ret = vpu_wdt_reg_handler(mdp->vpu_dev, mtk_mdp_reset_handler, mdp,
+ VPU_RST_MDP);
+   if (ret) {
+   dev_err(>dev, "Failed to register reset handler\n");
+   goto err_wdt_reg;
+   }
 
platform_set_drvdata(pdev, mdp);
 
@@ -206,6 +210,8 @@ static int mtk_mdp_probe(struct platform_device *pdev)
 
 err_set_max_seg_size:
 
+err_wdt_reg:
+
 err_m2m_register:
v4l2_device_unregister(>v4l2_dev);
 
-- 
2.26.2.526.g744177e7f7-goog



[PATCH v1 5/5] [media] mtk-mdp: Remove mtk_mdp_comp.id and supporting functionality

2020-05-04 Thread Eizan Miyamoto
Since components are registered in a list, the numeric component id that
specified a location in an array is not necessary.

Signed-off-by: ei...@chromium.org
Signed-off-by: Eizan Miyamoto 
---

 drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 60 +++
 drivers/media/platform/mtk-mdp/mtk_mdp_comp.h | 19 +-
 drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 10 +---
 3 files changed, 11 insertions(+), 78 deletions(-)

diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c 
b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
index d4afed1363d5..362fff924aef 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
@@ -14,46 +14,6 @@
 #include "mtk_mdp_comp.h"
 
 
-static const char * const mtk_mdp_comp_stem[MTK_MDP_COMP_TYPE_MAX] = {
-   "mdp_rdma",
-   "mdp_rsz",
-   "mdp_wdma",
-   "mdp_wrot",
-};
-
-struct mtk_mdp_comp_match {
-   enum mtk_mdp_comp_type type;
-   int alias_id;
-};
-
-static const struct mtk_mdp_comp_match mtk_mdp_matches[MTK_MDP_COMP_ID_MAX] = {
-   { MTK_MDP_RDMA, 0 },
-   { MTK_MDP_RDMA, 1 },
-   { MTK_MDP_RSZ,  0 },
-   { MTK_MDP_RSZ,  1 },
-   { MTK_MDP_RSZ,  2 },
-   { MTK_MDP_WDMA, 0 },
-   { MTK_MDP_WROT, 0 },
-   { MTK_MDP_WROT, 1 },
-};
-
-int mtk_mdp_comp_get_id(struct device *dev, struct device_node *node,
-   enum mtk_mdp_comp_type comp_type)
-{
-   int id = of_alias_get_id(node, mtk_mdp_comp_stem[comp_type]);
-   int i;
-
-   for (i = 0; i < ARRAY_SIZE(mtk_mdp_matches); i++) {
-   if (comp_type == mtk_mdp_matches[i].type &&
-   id == mtk_mdp_matches[i].alias_id)
-   return i;
-   }
-
-   dev_err(dev, "Failed to get id. type: %d, id: %d\n", comp_type, id);
-
-   return -EINVAL;
-}
-
 void mtk_mdp_comp_clock_on(struct device *dev, struct mtk_mdp_comp *comp)
 {
int i, err;
@@ -62,8 +22,8 @@ void mtk_mdp_comp_clock_on(struct device *dev, struct 
mtk_mdp_comp *comp)
err = mtk_smi_larb_get(comp->larb_dev);
if (err)
dev_err(dev,
-   "failed to get larb, err %d. type:%d id:%d\n",
-   err, comp->type, comp->id);
+   "failed to get larb, err %d. type:%d\n",
+   err, comp->type);
}
 
for (i = 0; i < ARRAY_SIZE(comp->clk); i++) {
@@ -72,8 +32,8 @@ void mtk_mdp_comp_clock_on(struct device *dev, struct 
mtk_mdp_comp *comp)
err = clk_prepare_enable(comp->clk[i]);
if (err)
dev_err(dev,
-   "failed to enable clock, err %d. type:%d id:%d i:%d\n",
-   err, comp->type, comp->id, i);
+   "failed to enable clock, err %d. type:%d i:%d\n",
+   err, comp->type, i);
}
 }
 
@@ -92,21 +52,15 @@ void mtk_mdp_comp_clock_off(struct device *dev, struct 
mtk_mdp_comp *comp)
 }
 
 int mtk_mdp_comp_init(struct device *dev, struct device_node *node,
- struct mtk_mdp_comp *comp, enum mtk_mdp_comp_id comp_id)
+ struct mtk_mdp_comp *comp,
+ enum mtk_mdp_comp_type comp_type)
 {
struct device_node *larb_node;
struct platform_device *larb_pdev;
int i;
 
-   if (comp_id < 0 || comp_id >= MTK_MDP_COMP_ID_MAX) {
-   dev_err(dev, "Invalid comp_id %d\n", comp_id);
-   return -EINVAL;
-   }
-
-   INIT_LIST_HEAD(>node);
comp->dev_node = of_node_get(node);
-   comp->id = comp_id;
-   comp->type = mtk_mdp_matches[comp_id].type;
+   comp->type = comp_type;
 
for (i = 0; i < ARRAY_SIZE(comp->clk); i++) {
comp->clk[i] = of_clk_get(node, i);
diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h 
b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
index 1f745891c6c3..1bf0242cce46 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
@@ -22,18 +22,6 @@ enum mtk_mdp_comp_type {
MTK_MDP_COMP_TYPE_MAX,
 };
 
-enum mtk_mdp_comp_id {
-   MTK_MDP_COMP_RDMA0,
-   MTK_MDP_COMP_RDMA1,
-   MTK_MDP_COMP_RSZ0,
-   MTK_MDP_COMP_RSZ1,
-   MTK_MDP_COMP_RSZ2,
-   MTK_MDP_COMP_WDMA,
-   MTK_MDP_COMP_WROT0,
-   MTK_MDP_COMP_WROT1,
-   MTK_MDP_COMP_ID_MAX,
-};
-
 /**
  * struct mtk_mdp_comp - the MDP's function component data
  * @node:  list node to track sibing MDP components
@@ -41,7 +29,6 @@ enum mtk_mdp_comp_id {
  * @clk:   clocks required for component
  * @larb_dev:  SMI device required for component
  * @type:  component type
- 

[PATCH v1 4/5] [media] mtk-mdp: convert mtk_mdp_dev.comp array to list

2020-05-04 Thread Eizan Miyamoto
The functions mtk_mdp_register/unregister_component have been created to
add / remove items from the list of components.

This will eventually enable us to specify a list of components in the
device tree instead of hardcoding them into this driver.

The list is modified by a single thread at driver probe time, and will
not be traversed by another thread until the call to pm_runtime_enable
at the end of probing.

Signed-off-by: ei...@chromium.org
Signed-off-by: Eizan Miyamoto 
---

 drivers/media/platform/mtk-mdp/mtk_mdp_comp.c |  1 +
 drivers/media/platform/mtk-mdp/mtk_mdp_comp.h |  2 +
 drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 46 +--
 drivers/media/platform/mtk-mdp/mtk_mdp_core.h | 10 +++-
 4 files changed, 43 insertions(+), 16 deletions(-)

diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c 
b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
index facc6104b91f..d4afed1363d5 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
@@ -103,6 +103,7 @@ int mtk_mdp_comp_init(struct device *dev, struct 
device_node *node,
return -EINVAL;
}
 
+   INIT_LIST_HEAD(>node);
comp->dev_node = of_node_get(node);
comp->id = comp_id;
comp->type = mtk_mdp_matches[comp_id].type;
diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h 
b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
index 3b83bd6e0d8b..1f745891c6c3 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
@@ -36,6 +36,7 @@ enum mtk_mdp_comp_id {
 
 /**
  * struct mtk_mdp_comp - the MDP's function component data
+ * @node:  list node to track sibing MDP components
  * @dev_node:  component device node
  * @clk:   clocks required for component
  * @larb_dev:  SMI device required for component
@@ -43,6 +44,7 @@ enum mtk_mdp_comp_id {
  * @id:component ID
  */
 struct mtk_mdp_comp {
+   struct list_headnode;
struct device_node  *dev_node;
struct clk  *clk[2];
struct device   *larb_dev;
diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c 
b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
index f974242663dc..e6e702d9cb69 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
@@ -55,19 +55,19 @@ MODULE_DEVICE_TABLE(of, mtk_mdp_of_ids);
 static void mtk_mdp_clock_on(struct mtk_mdp_dev *mdp)
 {
struct device *dev = >pdev->dev;
-   int i;
+   struct mtk_mdp_comp *comp_node;
 
-   for (i = 0; i < ARRAY_SIZE(mdp->comp); i++)
-   mtk_mdp_comp_clock_on(dev, mdp->comp[i]);
+   list_for_each_entry(comp_node, >comp_list, node)
+   mtk_mdp_comp_clock_on(dev, comp_node);
 }
 
 static void mtk_mdp_clock_off(struct mtk_mdp_dev *mdp)
 {
struct device *dev = >pdev->dev;
-   int i;
+   struct mtk_mdp_comp *comp_node;
 
-   for (i = 0; i < ARRAY_SIZE(mdp->comp); i++)
-   mtk_mdp_comp_clock_off(dev, mdp->comp[i]);
+   list_for_each_entry(comp_node, >comp_list, node)
+   mtk_mdp_comp_clock_off(dev, comp_node);
 }
 
 static void mtk_mdp_wdt_worker(struct work_struct *work)
@@ -91,12 +91,25 @@ static void mtk_mdp_reset_handler(void *priv)
queue_work(mdp->wdt_wq, >wdt_work);
 }
 
+void mtk_mdp_register_component(struct mtk_mdp_dev *mdp,
+   struct mtk_mdp_comp *comp)
+{
+   list_add(>comp_list, >node);
+}
+
+void mtk_mdp_unregister_component(struct mtk_mdp_dev *mdp,
+ struct mtk_mdp_comp *comp)
+{
+   list_del(>node);
+}
+
 static int mtk_mdp_probe(struct platform_device *pdev)
 {
struct mtk_mdp_dev *mdp;
struct device *dev = >dev;
struct device_node *node, *parent;
-   int i, ret = 0;
+   struct mtk_mdp_comp *comp, *comp_temp;
+   int ret = 0;
 
mdp = devm_kzalloc(dev, sizeof(*mdp), GFP_KERNEL);
if (!mdp)
@@ -104,6 +117,7 @@ static int mtk_mdp_probe(struct platform_device *pdev)
 
mdp->id = pdev->id;
mdp->pdev = pdev;
+   INIT_LIST_HEAD(>comp_list);
INIT_LIST_HEAD(>ctx_list);
 
mutex_init(>lock);
@@ -124,7 +138,6 @@ static int mtk_mdp_probe(struct platform_device *pdev)
const struct of_device_id *of_id;
enum mtk_mdp_comp_type comp_type;
int comp_id;
-   struct mtk_mdp_comp *comp;
 
of_id = of_match_node(mtk_mdp_comp_dt_ids, node);
if (!of_id)
@@ -150,13 +163,14 @@ static int mtk_mdp_probe(struct platform_device *pdev)
of_node_put(node);
goto err_comp;
}
-   mdp->comp[comp_id] = comp;
 
ret = mtk_mdp_comp_init(dev, no

[PATCH v1 0/5] MTK MDP driver cleanups to prep for futher work

2020-05-04 Thread Eizan Miyamoto
From: Eizan Miyamoto 


It most notably converts an array of MDP components to a list instead,
but also removes some unused fields.

This series of patches does some cleanup in preparation for futher work
so that hardware video decode works on 4.19 and later kernels. We are
planning on adding a dummy driver for the relevant MDP components that
will be bound together using the component framework, which will enable
calls to set up IOMMUs and LARBs, and make calls into pm_runtime.


Eizan Miyamoto (5):
  [media] mtk-mdp: remove mtk_mdp_comp.regs from mtk_mdp_comp.h
  [media] mtk-mdp: handle vb2_dma_contig_set_max_seg_size errors during
probe
  [media] mtk-mdp: handle vpu_wdt_reg_handler() errors during probe
  [media] mtk-mdp: convert mtk_mdp_dev.comp array to list
  [media] mtk-mdp: Remove mtk_mdp_comp.id and supporting functionality

 drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 60 ++-
 drivers/media/platform/mtk-mdp/mtk_mdp_comp.h | 23 +-
 drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 74 ---
 drivers/media/platform/mtk-mdp/mtk_mdp_core.h | 10 ++-
 4 files changed, 68 insertions(+), 99 deletions(-)

-- 
2.26.2.526.g744177e7f7-goog



[PATCH v1 2/5] [media] mtk-mdp: handle vb2_dma_contig_set_max_seg_size errors during probe

2020-05-04 Thread Eizan Miyamoto
This is a cleanup to better handle errors during MDP probe.

Signed-off-by: ei...@chromium.org
Signed-off-by: Eizan Miyamoto 
---

 drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c 
b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
index aeaed2cf4458..c20ac7681c6f 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
@@ -193,13 +193,19 @@ static int mtk_mdp_probe(struct platform_device *pdev)
 
platform_set_drvdata(pdev, mdp);
 
-   vb2_dma_contig_set_max_seg_size(>dev, DMA_BIT_MASK(32));
+   ret = vb2_dma_contig_set_max_seg_size(>dev, DMA_BIT_MASK(32));
+   if (ret) {
+   dev_err(>dev, "Failed to set vb2 dma mag seg size\n");
+   goto err_set_max_seg_size;
+   }
 
pm_runtime_enable(dev);
dev_dbg(dev, "mdp-%d registered successfully\n", mdp->id);
 
return 0;
 
+err_set_max_seg_size:
+
 err_m2m_register:
v4l2_device_unregister(>v4l2_dev);
 
-- 
2.26.2.526.g744177e7f7-goog



[PATCH v1 1/5] [media] mtk-mdp: remove mtk_mdp_comp.regs from mtk_mdp_comp.h

2020-05-04 Thread Eizan Miyamoto
These fields are not used and can be removed.

Signed-off-by: ei...@chromium.org
Signed-off-by: Eizan Miyamoto 
---

 drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 1 -
 drivers/media/platform/mtk-mdp/mtk_mdp_comp.h | 2 --
 2 files changed, 3 deletions(-)

diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c 
b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
index 14991685adb7..facc6104b91f 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
@@ -106,7 +106,6 @@ int mtk_mdp_comp_init(struct device *dev, struct 
device_node *node,
comp->dev_node = of_node_get(node);
comp->id = comp_id;
comp->type = mtk_mdp_matches[comp_id].type;
-   comp->regs = of_iomap(node, 0);
 
for (i = 0; i < ARRAY_SIZE(comp->clk); i++) {
comp->clk[i] = of_clk_get(node, i);
diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h 
b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
index 998a4b953025..3b83bd6e0d8b 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
@@ -38,7 +38,6 @@ enum mtk_mdp_comp_id {
  * struct mtk_mdp_comp - the MDP's function component data
  * @dev_node:  component device node
  * @clk:   clocks required for component
- * @regs:  Mapped address of component registers.
  * @larb_dev:  SMI device required for component
  * @type:  component type
  * @id:component ID
@@ -46,7 +45,6 @@ enum mtk_mdp_comp_id {
 struct mtk_mdp_comp {
struct device_node  *dev_node;
struct clk  *clk[2];
-   void __iomem*regs;
struct device   *larb_dev;
enum mtk_mdp_comp_type  type;
enum mtk_mdp_comp_idid;
-- 
2.26.2.526.g744177e7f7-goog



[PATCH v1] [media] mtk-mdp: Remove states for format checks

2020-05-04 Thread Eizan Miyamoto
From: Francois Buergisser 

The mtk-mdp driver uses states to check if the formats have been set
on the capture and output when turning the streaming on, setting
controls or setting the selection rectangles.
Those states are reset when 0 buffers are requested like when checking
capabilities.
This patch removes all format checks and set one by default as queues in
V4L2 are expected to always have a format set.

https://linuxtv.org/downloads/v4l-dvb-apis/uapi/v4l/vidioc-streamon.html
https://linuxtv.org/downloads/v4l-dvb-apis/uapi/v4l/vidioc-g-ctrl.html
https://linuxtv.org/downloads/v4l-dvb-apis/uapi/v4l/vidioc-g-selection.html

Signed-off-by: Francois Buergisser 
Reviewed-by: Tomasz Figa 
(cherry picked from commit 1887bb3924d030352df179347c8962248cdb903e)
Signed-off-by: Eizan Miyamoto 
---

 drivers/media/platform/mtk-mdp/mtk_mdp_core.h |  2 -
 drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c  | 90 +++
 2 files changed, 34 insertions(+), 58 deletions(-)

diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_core.h 
b/drivers/media/platform/mtk-mdp/mtk_mdp_core.h
index bafcccd71f31..dd130cc218c9 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_core.h
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_core.h
@@ -28,8 +28,6 @@
 #define MTK_MDP_FMT_FLAG_CAPTURE   BIT(1)
 
 #define MTK_MDP_VPU_INIT   BIT(0)
-#define MTK_MDP_SRC_FMTBIT(1)
-#define MTK_MDP_DST_FMTBIT(2)
 #define MTK_MDP_CTX_ERROR  BIT(5)
 
 /**
diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c 
b/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
index 821f2cf325f0..bb9caaf513bc 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
@@ -369,13 +369,6 @@ void mtk_mdp_ctx_state_lock_set(struct mtk_mdp_ctx *ctx, 
u32 state)
mutex_unlock(>slock);
 }
 
-static void mtk_mdp_ctx_state_lock_clear(struct mtk_mdp_ctx *ctx, u32 state)
-{
-   mutex_lock(>slock);
-   ctx->state &= ~state;
-   mutex_unlock(>slock);
-}
-
 static bool mtk_mdp_ctx_state_is_set(struct mtk_mdp_ctx *ctx, u32 mask)
 {
bool ret;
@@ -726,11 +719,6 @@ static int mtk_mdp_m2m_s_fmt_mplane(struct file *file, 
void *fh,
ctx->quant = pix_mp->quantization;
}
 
-   if (V4L2_TYPE_IS_OUTPUT(f->type))
-   mtk_mdp_ctx_state_lock_set(ctx, MTK_MDP_SRC_FMT);
-   else
-   mtk_mdp_ctx_state_lock_set(ctx, MTK_MDP_DST_FMT);
-
mtk_mdp_dbg(2, "[%d] type:%d, frame:%dx%d", ctx->id, f->type,
frame->width, frame->height);
 
@@ -742,13 +730,6 @@ static int mtk_mdp_m2m_reqbufs(struct file *file, void *fh,
 {
struct mtk_mdp_ctx *ctx = fh_to_ctx(fh);
 
-   if (reqbufs->count == 0) {
-   if (reqbufs->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
-   mtk_mdp_ctx_state_lock_clear(ctx, MTK_MDP_SRC_FMT);
-   else
-   mtk_mdp_ctx_state_lock_clear(ctx, MTK_MDP_DST_FMT);
-   }
-
return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, reqbufs);
 }
 
@@ -758,14 +739,6 @@ static int mtk_mdp_m2m_streamon(struct file *file, void 
*fh,
struct mtk_mdp_ctx *ctx = fh_to_ctx(fh);
int ret;
 
-   /* The source and target color format need to be set */
-   if (V4L2_TYPE_IS_OUTPUT(type)) {
-   if (!mtk_mdp_ctx_state_is_set(ctx, MTK_MDP_SRC_FMT))
-   return -EINVAL;
-   } else if (!mtk_mdp_ctx_state_is_set(ctx, MTK_MDP_DST_FMT)) {
-   return -EINVAL;
-   }
-
if (!mtk_mdp_ctx_state_is_set(ctx, MTK_MDP_VPU_INIT)) {
ret = mtk_mdp_vpu_init(>vpu);
if (ret < 0) {
@@ -899,24 +872,21 @@ static int mtk_mdp_m2m_s_selection(struct file *file, 
void *fh,
frame = >d_frame;
 
/* Check to see if scaling ratio is within supported range */
-   if (mtk_mdp_ctx_state_is_set(ctx, MTK_MDP_DST_FMT | MTK_MDP_SRC_FMT)) {
-   if (V4L2_TYPE_IS_OUTPUT(s->type)) {
-   ret = mtk_mdp_check_scaler_ratio(variant, new_r.width,
-   new_r.height, ctx->d_frame.crop.width,
-   ctx->d_frame.crop.height,
-   ctx->ctrls.rotate->val);
-   } else {
-   ret = mtk_mdp_check_scaler_ratio(variant,
-   ctx->s_frame.crop.width,
-   ctx->s_frame.crop.height, new_r.width,
-   new_r.height, ctx->ctrls.rotate->val);
-   }
+   if (V4L2_TYPE_IS_OUTPUT(s->type))
+   ret = mtk_mdp_check_scaler_ratio(variant, new_r.width,
+   new_r.height, ctx->d_frame.crop.width,
+   ctx->d_frame.crop.height,
+   ctx->ctrls.rotate-&