Re: [PATCH] media: rc: mtk-cir: use of_device_get_match_data()

2018-04-16 Thread Sean Wang
On Mon, 2018-04-16 at 10:34 +0800, Ryder Lee wrote:
> The usage of of_device_get_match_data() reduce the code size a bit.
> 
> Signed-off-by: Ryder Lee <ryder@mediatek.com>
> ---
>  drivers/media/rc/mtk-cir.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/media/rc/mtk-cir.c b/drivers/media/rc/mtk-cir.c
> index e88eb64..e42efd9 100644
> --- a/drivers/media/rc/mtk-cir.c
> +++ b/drivers/media/rc/mtk-cir.c
> @@ -299,8 +299,6 @@ static int mtk_ir_probe(struct platform_device *pdev)
>  {
>   struct device *dev = >dev;
>   struct device_node *dn = dev->of_node;
> - const struct of_device_id *of_id =
> - of_match_device(mtk_ir_match, >dev);
>   struct resource *res;
>   struct mtk_ir *ir;
>   u32 val;
> @@ -312,7 +310,7 @@ static int mtk_ir_probe(struct platform_device *pdev)
>   return -ENOMEM;
>  
>   ir->dev = dev;
> - ir->data = of_id->data;
> + ir->data = of_device_get_match_data(dev);
>  
>   ir->clk = devm_clk_get(dev, "clk");
>   if (IS_ERR(ir->clk)) {


Acked-by: Sean Wang <sean.w...@mediatek.com>




Re: [PATCH v1 0/4] media: rc: add support for IR receiver on MT7622 SoC

2017-08-01 Thread Sean Wang

Hi, Mauro and Sean

Just a gentle ping on the whole patchset porting MediaTek CIR to another
platform.

Sean


On Tue, 2017-07-04 at 19:10 +0900, Andi Shyti wrote:
> Hi Sean,
> 
> > This patchset introduces Consumer IR (CIR) support for MT7622 SoC
> > implements raw mode for more compatibility with different protocols
> > as previously SoC did. Before adding support to MT7622 SoC, extra
> > code refactor is done since there're major differences in register and
> > field definition from the previous SoC.
> > 
> > Sean Wang (4):
> >   dt-bindings: media: mtk-cir: Add support for MT7622 SoC
> >   media: rc: mtk-cir: add platform data to adapt into various hardware
> >   media: rc: mtk-cir: add support for MediaTek MT7622 SoC
> >   MAINTAINERS: add entry for MediaTek CIR driver
> 
> for the whole patchset:
> 
> Reviewed-by: Andi Shyti <andi.sh...@samsung.com>
> 
> Andi




Re: [PATCH v3 2/3] Documentation: devicetree: Add document bindings for mtk-cir

2017-01-18 Thread Sean Wang
On Wed, 2017-01-18 at 16:42 -0600, Rob Herring wrote:
> On Wed, Jan 18, 2017 at 4:23 PM, Rob Herring <r...@kernel.org> wrote:
> > On Fri, Jan 13, 2017 at 03:35:38PM +0800, sean.w...@mediatek.com wrote:
> >> From: Sean Wang <sean.w...@mediatek.com>
> >>
> >> This patch adds documentation for devicetree bindings for
> >> consumer Mediatek IR controller.
> >>
> >> Signed-off-by: Sean Wang <sean.w...@mediatek.com>
> >> ---
> >>  .../devicetree/bindings/media/mtk-cir.txt  | 24 
> >> ++
> >>  1 file changed, 24 insertions(+)
> >>  create mode 100644 Documentation/devicetree/bindings/media/mtk-cir.txt
> >
> > Acked-by: Rob Herring <r...@kernel.org>
> 
> I guess I rescind my ack if this email doesn't work:
> 
> "The response from the remote server was:
> 
> 550 Relaying mail to sean.w...@mediatek.com is not allowed"


sorry for causing you inconvenience.

it should be able to work because i almost use this daily
maybe that's just a sudden problem from internal server (?) 

but if the problem still continues, please let me know and 
i will try to fix this.



--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 2/2] media: rc: add driver for IR remote receiver on MT7623 SoC

2017-01-11 Thread Sean Wang
okay, I will continue to work based on your changes unless someone else
has concerns

On Wed, 2017-01-11 at 07:45 +0900, Andi Shyti wrote:
> Hi Sean,
> 
> >include/linux/compiler.h:253:8: sparse: attribute 'no_sanitize_address': 
> > unknown attribute
> > >> drivers/media/rc/mtk-cir.c:215:41: sparse: too many arguments for 
> > >> function devm_rc_allocate_device
> >drivers/media/rc/mtk-cir.c: In function 'mtk_ir_probe':
> >drivers/media/rc/mtk-cir.c:215:11: error: too many arguments to function 
> > 'devm_rc_allocate_device'
> >  ir->rc = devm_rc_allocate_device(dev, RC_DRIVER_IR_RAW);
> >   ^~~
> >In file included from drivers/media/rc/mtk-cir.c:22:0:
> >include/media/rc-core.h:213:16: note: declared here
> > struct rc_dev *devm_rc_allocate_device(struct device *dev);
> >^~~
> > 
> > vim +/devm_rc_allocate_device +215 drivers/media/rc/mtk-cir.c
> > 
> >209  ir->base = devm_ioremap_resource(dev, res);
> >210  if (IS_ERR(ir->base)) {
> >211  dev_err(dev, "failed to map registers\n");
> >212  return PTR_ERR(ir->base);
> >213  }
> >214  
> >  > 215  ir->rc = devm_rc_allocate_device(dev, RC_DRIVER_IR_RAW);
> 
> this error comes because the patches I pointed out have not been
> applied yet. I guess you can ignore them as long as you tested
> yours on top those patches.
> 
> Andi


--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 2/2] media: rc: add driver for IR remote receiver on MT7623 SoC

2017-01-11 Thread Sean Wang
t; > +   ir->rc->input_id.vendor = 0x0001;
> > > > +   ir->rc->input_id.product = 0x0001;
> > > > +   ir->rc->input_id.version = 0x0001;
> > > > +   map_name = of_get_property(dn, "linux,rc-map-name", NULL);
> > > > +   ir->rc->map_name = map_name ?: RC_MAP_EMPTY;
> > > > +   ir->rc->dev.parent = dev;
> > > > +   ir->rc->driver_name = MTK_IR_DEV;
> > > > +   ir->rc->allowed_protocols = RC_BIT_ALL;
> > > > +   ir->rc->rx_resolution = MTK_IR_SAMPLE;
> > > > +   ir->rc->timeout = MTK_MAX_SAMPLES * (MTK_IR_SAMPLE + 1);
> > > > +
> > > > +   ret = devm_rc_register_device(dev, ir->rc);
> > > 
> > > Here you do devm_rc_register_device()
> > 
> > does it have problem ?
> 
> Sorry, no. I just wanted to highlight wrt a comment below.
> > 
> > 
> > > > +   if (ret) {
> > > > +   dev_err(dev, "failed to register rc device\n");
> > > > +   return ret;
> > > > +   }
> > > > +
> > > > +   platform_set_drvdata(pdev, ir);
> > > > +
> > > > +   ir->irq = platform_get_irq(pdev, 0);
> > > > +   if (ir->irq < 0) {
> > > > +   dev_err(dev, "no irq resource\n");
> > > > +   return -ENODEV;
> > > > +   }
> > > > +
> > > > +   /* Enable interrupt after proper hardware
> > > > +* setup and IRQ handler registration
> > > > +*/
> > > > +   if (clk_prepare_enable(ir->clk)) {
> > > > +   dev_err(dev, "try to enable ir_clk failed\n");
> > > > +   ret = -EINVAL;
> > > > +   goto exit_clkdisable_clk;
> > > > +   }
> > > > +
> > > > +   mtk_irq_disable(ir, MTK_IRINT_EN);
> > > > +
> > > > +   ret = devm_request_irq(dev, ir->irq, mtk_ir_irq, 0, MTK_IR_DEV, 
> > > > ir);
> > > > +   if (ret) {
> > > > +   dev_err(dev, "failed request irq\n");
> > > > +   goto exit_clkdisable_clk;
> > > > +   }
> > > > +
> > > > +   /* Enable IR and PWM */
> > > > +   val = mtk_r32(ir, MTK_CONFIG_HIGH_REG);
> > > > +   val |= MTK_PWM_EN | MTK_IR_EN;
> > > > +   mtk_w32(ir, val, MTK_CONFIG_HIGH_REG);
> > > > +
> > > > +   /* Setting sample period */
> > > > +   mtk_w32_mask(ir, MTK_CHK_PERIOD, MTK_CHK_PERIOD_MASK,
> > > > +MTK_CONFIG_LOW_REG);
> > > > +
> > > > +   mtk_irq_enable(ir, MTK_IRINT_EN);
> > > > +
> > > > +   dev_info(dev, "Initialized MT7623 IR driver, sample period = 
> > > > %luus\n",
> > > > +DIV_ROUND_CLOSEST(MTK_IR_SAMPLE, 1000));
> > > > +
> > > > +   return 0;
> > > > +
> > > > +exit_clkdisable_clk:
> > > > +   clk_disable_unprepare(ir->clk);
> > > > +
> > > > +   return ret;
> > > > +}
> > > > +
> > > > +static int mtk_ir_remove(struct platform_device *pdev)
> > > > +{
> > > > +   struct mtk_ir *ir = platform_get_drvdata(pdev);
> > > > +
> > > > +   /* Avoid contention between remove handler and
> > > > +* IRQ handler so that disabling IR interrupt and
> > > > +* waiting for pending IRQ handler to complete
> > > > +*/
> > > > +   mtk_irq_disable(ir, MTK_IRINT_EN);
> > > > +   synchronize_irq(ir->irq);
> > > > +
> > > > +   clk_disable_unprepare(ir->clk);
> > > > +
> > > > +   rc_unregister_device(ir->rc);
> > > 
> > > Yet here you explicitly call rc_unregister_device(). Since it was 
> > > registered
> > > with the devm call, this call is not needed and will lead to double frees 
> > > etc
> > 
> > bug :( .  I will fix it ..
> > 
> > > > +
> > > > +   return 0;
> > > > +}
> > > > +
> > > > +static const struct of_device_id mtk_ir_match[] = {
> > > > +   { .compatible = "mediatek,mt7623-cir" },
> > > > +   {},
> > > > +};
> > > > +MODULE_DEVICE_TABLE(of, mtk_ir_match);
> > > > +
> > > > +static struct platform_driver mtk_ir_driver = {
> > > > +   .probe  = mtk_ir_probe,
> > > > +   .remove = mtk_ir_remove,
> > > > +   .driver = {
> > > > +   .name = MTK_IR_DEV,
> > > > +   .of_match_table = mtk_ir_match,
> > > > +   },
> > > > +};
> > > > +
> > > > +module_platform_driver(mtk_ir_driver);
> > > > +
> > > > +MODULE_DESCRIPTION("Mediatek IR Receiver Controller Driver");
> > > > +MODULE_AUTHOR("Sean Wang <sean.w...@mediatek.com>");
> > > > +MODULE_LICENSE("GPL");
> > > > -- 
> > > > 2.7.4
> > > > 
> > 
> > 
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-media" in
> > the body of a message to majord...@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html


--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 2/2] media: rc: add driver for IR remote receiver on MT7623 SoC

2017-01-10 Thread Sean Wang
meout = MTK_MAX_SAMPLES * (MTK_IR_SAMPLE + 1);
> > +
> > +   ret = devm_rc_register_device(dev, ir->rc);
> 
> Here you do devm_rc_register_device()

does it have problem ?


> > +   if (ret) {
> > +   dev_err(dev, "failed to register rc device\n");
> > +   return ret;
> > +   }
> > +
> > +   platform_set_drvdata(pdev, ir);
> > +
> > +   ir->irq = platform_get_irq(pdev, 0);
> > +   if (ir->irq < 0) {
> > +   dev_err(dev, "no irq resource\n");
> > +   return -ENODEV;
> > +   }
> > +
> > +   /* Enable interrupt after proper hardware
> > +* setup and IRQ handler registration
> > +*/
> > +   if (clk_prepare_enable(ir->clk)) {
> > +   dev_err(dev, "try to enable ir_clk failed\n");
> > +   ret = -EINVAL;
> > +   goto exit_clkdisable_clk;
> > +   }
> > +
> > +   mtk_irq_disable(ir, MTK_IRINT_EN);
> > +
> > +   ret = devm_request_irq(dev, ir->irq, mtk_ir_irq, 0, MTK_IR_DEV, ir);
> > +   if (ret) {
> > +   dev_err(dev, "failed request irq\n");
> > +   goto exit_clkdisable_clk;
> > +   }
> > +
> > +   /* Enable IR and PWM */
> > +   val = mtk_r32(ir, MTK_CONFIG_HIGH_REG);
> > +   val |= MTK_PWM_EN | MTK_IR_EN;
> > +   mtk_w32(ir, val, MTK_CONFIG_HIGH_REG);
> > +
> > +   /* Setting sample period */
> > +   mtk_w32_mask(ir, MTK_CHK_PERIOD, MTK_CHK_PERIOD_MASK,
> > +MTK_CONFIG_LOW_REG);
> > +
> > +   mtk_irq_enable(ir, MTK_IRINT_EN);
> > +
> > +   dev_info(dev, "Initialized MT7623 IR driver, sample period = %luus\n",
> > +DIV_ROUND_CLOSEST(MTK_IR_SAMPLE, 1000));
> > +
> > +   return 0;
> > +
> > +exit_clkdisable_clk:
> > +   clk_disable_unprepare(ir->clk);
> > +
> > +   return ret;
> > +}
> > +
> > +static int mtk_ir_remove(struct platform_device *pdev)
> > +{
> > +   struct mtk_ir *ir = platform_get_drvdata(pdev);
> > +
> > +   /* Avoid contention between remove handler and
> > +* IRQ handler so that disabling IR interrupt and
> > +* waiting for pending IRQ handler to complete
> > +*/
> > +   mtk_irq_disable(ir, MTK_IRINT_EN);
> > +   synchronize_irq(ir->irq);
> > +
> > +   clk_disable_unprepare(ir->clk);
> > +
> > +   rc_unregister_device(ir->rc);
> 
> Yet here you explicitly call rc_unregister_device(). Since it was registered
> with the devm call, this call is not needed and will lead to double frees etc

bug :( .  I will fix it ..

> > +
> > +   return 0;
> > +}
> > +
> > +static const struct of_device_id mtk_ir_match[] = {
> > +   { .compatible = "mediatek,mt7623-cir" },
> > +   {},
> > +};
> > +MODULE_DEVICE_TABLE(of, mtk_ir_match);
> > +
> > +static struct platform_driver mtk_ir_driver = {
> > +   .probe  = mtk_ir_probe,
> > +   .remove = mtk_ir_remove,
> > +   .driver = {
> > +   .name = MTK_IR_DEV,
> > +   .of_match_table = mtk_ir_match,
> > +   },
> > +};
> > +
> > +module_platform_driver(mtk_ir_driver);
> > +
> > +MODULE_DESCRIPTION("Mediatek IR Receiver Controller Driver");
> > +MODULE_AUTHOR("Sean Wang <sean.w...@mediatek.com>");
> > +MODULE_LICENSE("GPL");
> > -- 
> > 2.7.4
> > 


--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/2] Documentation: devicetree: Add document bindings for mtk-cir

2017-01-09 Thread Sean Wang
Hi Rob,

thanks for your effort for reviewing. I added comments inline.

On Mon, 2017-01-09 at 12:32 -0600, Rob Herring wrote:
> On Fri, Jan 06, 2017 at 12:06:23AM +0800, sean.w...@mediatek.com wrote:
> > From: Sean Wang <sean.w...@mediatek.com>
> > 
> > This patch adds documentation for devicetree bindings for
> > Mediatek IR controller.
> > 
> > Signed-off-by: Sean Wang <sean.w...@mediatek.com>
> > ---
> >  .../devicetree/bindings/media/mtk-cir.txt  | 23 
> > ++
> >  1 file changed, 23 insertions(+)
> >  create mode 100644 
> > linux-4.8.rc1_p0/Documentation/devicetree/bindings/media/mtk-cir.txt
> > 
> > diff --git a/Documentation/devicetree/bindings/media/mtk-cir.txt 
> > b/Documentation/devicetree/bindings/media/mtk-cir.txt
> > new file mode 100644
> > index 000..bbedd71
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/media/mtk-cir.txt
> > @@ -0,0 +1,23 @@
> > +Device-Tree bindings for Mediatek IR controller found in Mediatek SoC 
> > family
> > +
> > +Required properties:
> > +- compatible   : "mediatek,mt7623-ir"
> > +- clocks   : list of clock specifiers, corresponding to
> > + entries in clock-names property;
> > +- clock-names  : should contain "clk" entries;
> > +- interrupts   : should contain IR IRQ number;
> > +- reg  : should contain IO map address for IR.
> > +
> > +Optional properties:
> > +- linux,rc-map-name : Remote control map name.
> 
> Would 'label' be appropriate here instead? If not, this needs to be 
> documented in a common location and explained better.
> 
I checked with how the way applied in other IR drivers is and found that
most IR driver also use the same label to identify the scan/key table
they prefer to use such as gpio-ir-recv, ir-hix5hd2, meson-ir and
sunxi-cir or use hard coding inside the driver. So I thought it should
be appropriate here currently.

> > +
> > +Example:
> > +
> > +cir: cir@0x10013000 {
> 
> Drop the '0x'.
> 

okay, I will.

> > +   compatible = "mediatek,mt7623-ir";
> > +   reg = <0 0x10013000 0 0x1000>;
> > +   interrupts = ;
> > +   clocks = < CLK_INFRA_IRRX>;
> > +   clock-names = "clk";
> > +   linux,rc-map-name = "rc-rc6-mce";
> > +};
> > -- 
> > 1.9.1
> > 


--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] media: rc: add driver for IR remote receiver on MT7623 SoC

2017-01-08 Thread Sean Wang
On Sun, 2017-01-08 at 21:16 +, Sean Young wrote:
> Hi Sean,
> 
> On Fri, Jan 06, 2017 at 03:31:25PM +0800, Sean Wang wrote:
> > On Thu, 2017-01-05 at 17:12 +, Sean Young wrote:
> > > On Fri, Jan 06, 2017 at 12:06:24AM +0800, sean.w...@mediatek.com wrote:
> > > > +   /* Handle pulse and space until end of message */
> > > > +   for (i = 0 ; i < MTK_CHKDATA_SZ ; i++) {
> > > > +   val = mtk_r32(ir, MTK_CHKDATA_REG(i));
> > > > +   dev_dbg(ir->dev, "@reg%d=0x%08x\n", i, val);
> > > > +
> > > > +   for (j = 0 ; j < 4 ; j++) {
> > > > +   wid = (val & (0xff << j * 8)) >> j * 8;
> > > > +   rawir.pulse = !rawir.pulse;
> > > > +   rawir.duration = wid * (MTK_IR_SAMPLE + 1);
> > > > +   ir_raw_event_store_with_filter(ir->rc, );
> > > > +
> > > > +   if (MTK_IR_END(wid))
> > > > +   goto end_msg;
> > > > +   }
> > > > +   }
> > > 
> > > If I read this correctly, there is a maximum of 17 * 4 = 68 edges per
> > > IR message. The rc6 mce key 0 (scancode 0x800f0400) is 69 edges, so that
> > > won't work.
> > > 
> > Uh, this is related to hardware limitation. Maximum number hardware
> > holds indeed is only 68 edges as you said :( 
> > 
> > For the case, I will try change the logic into that the whole message 
> > is dropped if no end of message is seen within 68 counts to avoid
> > wasting CPU for decoding. 
> 
> I'm not sure it is worthwhile dropping the IR in that case. The processing
> is minimal and it might be possible that we have just enough IR to decode
> a scancode even if the trailing end of message is missing. Note that
> the call to ir_raw_event_set_idle() will generate an timeout IR event, so
> there will always be an end of message marker.


1)
I agree with you :) The original logic I made already as you pointed out
is sent incomplete IR message to let ir-raw try to decode as possible.

2)
I had another question. I found multiple and same IR messages being
received when using SONY remote controller. Should driver needs to
report each message or only one of these to the upper layer ?


> All I wanted to do was point out a limitation in case there is a
> workaround; if there is not then we might as well make do with the IR
> we do have.

I also will leave some words about limitation we had in the comments.

> Thanks
> Sean


--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] media: rc: add driver for IR remote receiver on MT7623 SoC

2017-01-05 Thread Sean Wang
Hi Andi,

Thank for your reminder. I will refine the code based on your work.
to have elegant code and easy error handling.

Sean

On Fri, 2017-01-06 at 12:43 +0900, Andi Shyti wrote:
> Hi Sean,
> 
> > +   ir->rc = rc_allocate_device();
> 
> Yes, you should use devm_rc_allocate_device(...)
> 
> Besides, standing to this patch which is not in yet:
> 
> https://lkml.org/lkml/2016/12/18/39
> 
> rc_allocate_device should provide the driver type during
> allocation, so it should be:
> 
>   ir->rc = rc_allocate_device(RC_DRIVER_IR_RAW);
> 
> and this line can be removed:
> 
> > +   ir->rc->driver_type = RC_DRIVER_IR_RAW;
> 
> I don't know when Mauro will take the patch above.
> 
> Andi


--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] media: rc: add driver for IR remote receiver on MT7623 SoC

2017-01-05 Thread Sean Wang
Hi Sean,

Thanks for your effort for code reviewing. I add comments inline. 

On Thu, 2017-01-05 at 17:12 +, Sean Young wrote:
> Hi Sean,
> 
> Some review comments.
> 
> On Fri, Jan 06, 2017 at 12:06:24AM +0800, sean.w...@mediatek.com wrote:
> > From: Sean Wang <sean.w...@mediatek.com>
> > 
> > This patch adds driver for IR controller on
> > Mediatek MT7623 SoC. Currently testing successfully
> > on NEC and SONY remote controller only but it should
> > work on others (lirc, rc-5 and rc-6).
> > 
> > Signed-off-by: Sean Wang <sean.w...@mediatek.com>
> > ---
> >  drivers/media/rc/Kconfig   |  10 ++
> >  drivers/media/rc/Makefile  |   1 +
> >  drivers/media/rc/mtk-cir.c | 319 
> > +
> >  3 files changed, 330 insertions(+)
> >  create mode 100644 linux-4.8.rc1_p0/drivers/media/rc/mtk-cir.c
> > 
> > diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
> > index 370e16e..626c500 100644
> > --- a/drivers/media/rc/Kconfig
> > +++ b/drivers/media/rc/Kconfig
> > @@ -389,4 +389,14 @@ config IR_SUNXI
> >To compile this driver as a module, choose M here: the module will
> >be called sunxi-ir.
> >  
> > +config IR_MTK
> > +   tristate "Mediatek IR remote control"
> > +   depends on RC_CORE
> > +   depends on ARCH_MEDIATEK || COMPILE_TEST
> > +   ---help---
> > +  Say Y if you want to use Mediatek internal IR Controller
> > +
> > +  To compile this driver as a module, choose M here: the module will
> > +  be called mtk-cir.
> > +
> >  endif #RC_DEVICES
> > diff --git a/drivers/media/rc/Makefile b/drivers/media/rc/Makefile
> > index 379a5c0..505908d 100644
> > --- a/drivers/media/rc/Makefile
> > +++ b/drivers/media/rc/Makefile
> > @@ -37,3 +37,4 @@ obj-$(CONFIG_IR_TTUSBIR) += ttusbir.o
> >  obj-$(CONFIG_RC_ST) += st_rc.o
> >  obj-$(CONFIG_IR_SUNXI) += sunxi-cir.o
> >  obj-$(CONFIG_IR_IMG) += img-ir/
> > +obj-$(CONFIG_IR_MTK) += mtk-cir.o
> > diff --git a/drivers/media/rc/mtk-cir.c b/drivers/media/rc/mtk-cir.c
> > new file mode 100644
> > index 000..4fa4cab
> > --- /dev/null
> > +++ b/drivers/media/rc/mtk-cir.c
> > @@ -0,0 +1,319 @@
> > +/*
> > + * Driver for Mediatek MT7623 IR Receiver Controller
> > + *
> > + * Copyright (C) 2017 Sean Wang <sean.w...@mediatek.com>
> > + *
> > + * This program is free software; you can redistribute it and/or
> > + * modify it under the terms of the GNU General Public License as
> > + * published by the Free Software Foundation; either version 2 of
> > + * the License, or (at your option) any later version.
> > + *
> > + * This program is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > + * GNU General Public License for more details.
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#define MTK_IR_DEV "mtk-ir"
> 
> KBUILD_MODNAME could be used instead. Currently the module is called
> mtk-cir but the rc device will have driver name mtk-ir.


okay. i will use this instead of this insistent coding.

> > +
> > +/* Register to enable PWM and IR */
> > +#define MTK_CONFIG_HIGH_REG   0x0c
> > +/* Enable IR pulse width detection */
> > +#define MTK_PWM_EN   BIT(13)
> > +/* Enable IR hardware function */
> > +#define MTK_IR_ENBIT(0)
> > +
> > +/* Register to setting sample period */
> > +#define MTK_CONFIG_LOW_REG0x10
> > +/* Field to set sample period */
> > +#define CHK_PERIOD   0xC00
> > +#define MTK_CHK_PERIOD(((CHK_PERIOD) << 8) & (GENMASK(20, 8)))
> > +#define MTK_CHK_PERIOD_MASK  (GENMASK(20, 8))
> > +
> > +/* Register to clear state of state machine */
> > +#define MTK_IRCLR_REG 0x20
> > +/* Bit to restart IR receiving */
> > +#define MTK_IRCLRBIT(0)
> > +
> > +/* Register containing pulse width data */
> > +#define MTK_CHKDATA_REG(i)(0x88 + 4 * i)
> > +
> > +/* Register to enable IR interrupt */
> > +#define MTK_IRINT_EN_REG  0xcc
> > +/* Bit to enable interrupt */
> > +#define MTK_IRINT_EN BIT(0)
> > +
> > +/* Register to ack IR interrupt */
> > +#define MTK_IRINT_CLR_