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

2020-07-20 Thread Chun-Kuang Hu
Hi, Eizan:

Eizan Miyamoto  於 2020年5月6日 週三 下午4: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.

For the component binding problem, MDP is similar to DRM driver [1],
and DRM is probed by mmsys driver [2] (mmsys is a device which control
display clock, display routing, mdp clock, mdp routing). Maybe you
could refer to what DRM does.

[1] 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpu/drm/mediatek/mtk_drm_drv.c?h=v5.8-rc6
[2] 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v5.8-rc6=667c769246b01c53ad0925d603d2a2531abd3ef2

Regards,
Chun-Kuang.

>
> Signed-off-by: Eizan Miyamoto 


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 
> >>> -#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",
> 

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

2020-05-07 Thread Enric Balletbo i Serra
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 
>>> -#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
>>> +   },

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_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, 

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

2020-05-06 Thread Enric Balletbo Serra
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_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)

[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,
"failed to get larb, err %d. type:%d\n",
-   err, comp->type);
+