diff mbox

[27/34] media: mx2_camera: use managed functions to clean up code

Message ID 1347860103-4141-28-git-send-email-shawn.guo@linaro.org (mailing list archive)
State New, archived
Headers show

Commit Message

Shawn Guo Sept. 17, 2012, 5:34 a.m. UTC
Use managed functions to clean up the error handling code and function
mx2_camera_remove().  Along with the change, a few variables get removed
from struct mx2_camera_dev.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Cc: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Cc: linux-media@vger.kernel.org
---
 drivers/media/video/mx2_camera.c |  143 +++++++++++---------------------------
 1 file changed, 39 insertions(+), 104 deletions(-)

Comments

Guennadi Liakhovetski Sept. 17, 2012, 9:11 a.m. UTC | #1
On Mon, 17 Sep 2012, Shawn Guo wrote:

> Use managed functions to clean up the error handling code and function
> mx2_camera_remove().  Along with the change, a few variables get removed
> from struct mx2_camera_dev.
> 
> Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
> Cc: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
> Cc: linux-media@vger.kernel.org

(in case you want to push it via arm-soc)

Acked-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>

Thanks
Guennadi

> ---
>  drivers/media/video/mx2_camera.c |  143 +++++++++++---------------------------
>  1 file changed, 39 insertions(+), 104 deletions(-)
> 
> diff --git a/drivers/media/video/mx2_camera.c b/drivers/media/video/mx2_camera.c
> index 89c7e28..fe4c76c 100644
> --- a/drivers/media/video/mx2_camera.c
> +++ b/drivers/media/video/mx2_camera.c
> @@ -274,12 +274,9 @@ struct mx2_camera_dev {
>  	struct soc_camera_device *icd;
>  	struct clk		*clk_csi, *clk_emma_ahb, *clk_emma_ipg;
>  
> -	unsigned int		irq_csi, irq_emma;
>  	void __iomem		*base_csi, *base_emma;
> -	unsigned long		base_dma;
>  
>  	struct mx2_camera_platform_data *pdata;
> -	struct resource		*res_csi, *res_emma;
>  	unsigned long		platform_flags;
>  
>  	struct list_head	capture;
> @@ -1607,64 +1604,59 @@ static irqreturn_t mx27_camera_emma_irq(int irq_emma, void *data)
>  	return IRQ_HANDLED;
>  }
>  
> -static int __devinit mx27_camera_emma_init(struct mx2_camera_dev *pcdev)
> +static int __devinit mx27_camera_emma_init(struct platform_device *pdev)
>  {
> -	struct resource *res_emma = pcdev->res_emma;
> +	struct mx2_camera_dev *pcdev = platform_get_drvdata(pdev);
> +	struct resource *res_emma;
> +	int irq_emma;
>  	int err = 0;
>  
> -	if (!request_mem_region(res_emma->start, resource_size(res_emma),
> -				MX2_CAM_DRV_NAME)) {
> -		err = -EBUSY;
> +	res_emma = platform_get_resource(pdev, IORESOURCE_MEM, 1);
> +	irq_emma = platform_get_irq(pdev, 1);
> +	if (!res_emma || !irq_emma) {
> +		dev_err(pcdev->dev, "no EMMA resources\n");
>  		goto out;
>  	}
>  
> -	pcdev->base_emma = ioremap(res_emma->start, resource_size(res_emma));
> +	pcdev->base_emma = devm_request_and_ioremap(pcdev->dev, res_emma);
>  	if (!pcdev->base_emma) {
> -		err = -ENOMEM;
> -		goto exit_release;
> +		err = -EADDRNOTAVAIL;
> +		goto out;
>  	}
>  
> -	err = request_irq(pcdev->irq_emma, mx27_camera_emma_irq, 0,
> -			MX2_CAM_DRV_NAME, pcdev);
> +	err = devm_request_irq(pcdev->dev, irq_emma, mx27_camera_emma_irq, 0,
> +			       MX2_CAM_DRV_NAME, pcdev);
>  	if (err) {
>  		dev_err(pcdev->dev, "Camera EMMA interrupt register failed \n");
> -		goto exit_iounmap;
> +		goto out;
>  	}
>  
> -	pcdev->clk_emma_ipg = clk_get(pcdev->dev, "emma-ipg");
> +	pcdev->clk_emma_ipg = devm_clk_get(pcdev->dev, "emma-ipg");
>  	if (IS_ERR(pcdev->clk_emma_ipg)) {
>  		err = PTR_ERR(pcdev->clk_emma_ipg);
> -		goto exit_free_irq;
> +		goto out;
>  	}
>  
>  	clk_prepare_enable(pcdev->clk_emma_ipg);
>  
> -	pcdev->clk_emma_ahb = clk_get(pcdev->dev, "emma-ahb");
> +	pcdev->clk_emma_ahb = devm_clk_get(pcdev->dev, "emma-ahb");
>  	if (IS_ERR(pcdev->clk_emma_ahb)) {
>  		err = PTR_ERR(pcdev->clk_emma_ahb);
> -		goto exit_clk_emma_ipg_put;
> +		goto exit_clk_emma_ipg;
>  	}
>  
>  	clk_prepare_enable(pcdev->clk_emma_ahb);
>  
>  	err = mx27_camera_emma_prp_reset(pcdev);
>  	if (err)
> -		goto exit_clk_emma_ahb_put;
> +		goto exit_clk_emma_ahb;
>  
>  	return err;
>  
> -exit_clk_emma_ahb_put:
> +exit_clk_emma_ahb:
>  	clk_disable_unprepare(pcdev->clk_emma_ahb);
> -	clk_put(pcdev->clk_emma_ahb);
> -exit_clk_emma_ipg_put:
> +exit_clk_emma_ipg:
>  	clk_disable_unprepare(pcdev->clk_emma_ipg);
> -	clk_put(pcdev->clk_emma_ipg);
> -exit_free_irq:
> -	free_irq(pcdev->irq_emma, pcdev);
> -exit_iounmap:
> -	iounmap(pcdev->base_emma);
> -exit_release:
> -	release_mem_region(res_emma->start, resource_size(res_emma));
>  out:
>  	return err;
>  }
> @@ -1672,9 +1664,8 @@ out:
>  static int __devinit mx2_camera_probe(struct platform_device *pdev)
>  {
>  	struct mx2_camera_dev *pcdev;
> -	struct resource *res_csi, *res_emma;
> -	void __iomem *base_csi;
> -	int irq_csi, irq_emma;
> +	struct resource *res_csi;
> +	int irq_csi;
>  	int err = 0;
>  
>  	dev_dbg(&pdev->dev, "initialising\n");
> @@ -1687,21 +1678,20 @@ static int __devinit mx2_camera_probe(struct platform_device *pdev)
>  		goto exit;
>  	}
>  
> -	pcdev = kzalloc(sizeof(*pcdev), GFP_KERNEL);
> +	pcdev = devm_kzalloc(&pdev->dev, sizeof(*pcdev), GFP_KERNEL);
>  	if (!pcdev) {
>  		dev_err(&pdev->dev, "Could not allocate pcdev\n");
>  		err = -ENOMEM;
>  		goto exit;
>  	}
>  
> -	pcdev->clk_csi = clk_get(&pdev->dev, "ahb");
> +	pcdev->clk_csi = devm_clk_get(&pdev->dev, "ahb");
>  	if (IS_ERR(pcdev->clk_csi)) {
>  		dev_err(&pdev->dev, "Could not get csi clock\n");
>  		err = PTR_ERR(pcdev->clk_csi);
> -		goto exit_kfree;
> +		goto exit;
>  	}
>  
> -	pcdev->res_csi = res_csi;
>  	pcdev->pdata = pdev->dev.platform_data;
>  	if (pcdev->pdata) {
>  		long rate;
> @@ -1711,11 +1701,11 @@ static int __devinit mx2_camera_probe(struct platform_device *pdev)
>  		rate = clk_round_rate(pcdev->clk_csi, pcdev->pdata->clk * 2);
>  		if (rate <= 0) {
>  			err = -ENODEV;
> -			goto exit_dma_free;
> +			goto exit;
>  		}
>  		err = clk_set_rate(pcdev->clk_csi, rate);
>  		if (err < 0)
> -			goto exit_dma_free;
> +			goto exit;
>  	}
>  
>  	INIT_LIST_HEAD(&pcdev->capture);
> @@ -1723,48 +1713,28 @@ static int __devinit mx2_camera_probe(struct platform_device *pdev)
>  	INIT_LIST_HEAD(&pcdev->discard);
>  	spin_lock_init(&pcdev->lock);
>  
> -	/*
> -	 * Request the regions.
> -	 */
> -	if (!request_mem_region(res_csi->start, resource_size(res_csi),
> -				MX2_CAM_DRV_NAME)) {
> -		err = -EBUSY;
> -		goto exit_dma_free;
> +	pcdev->base_csi = devm_request_and_ioremap(&pdev->dev, res_csi);
> +	if (!pcdev->base_csi) {
> +		err = -EADDRNOTAVAIL;
> +		goto exit;
>  	}
>  
> -	base_csi = ioremap(res_csi->start, resource_size(res_csi));
> -	if (!base_csi) {
> -		err = -ENOMEM;
> -		goto exit_release;
> -	}
> -	pcdev->irq_csi = irq_csi;
> -	pcdev->base_csi = base_csi;
> -	pcdev->base_dma = res_csi->start;
>  	pcdev->dev = &pdev->dev;
> +	platform_set_drvdata(pdev, pcdev);
>  
>  	if (cpu_is_mx25()) {
> -		err = request_irq(pcdev->irq_csi, mx25_camera_irq, 0,
> -				MX2_CAM_DRV_NAME, pcdev);
> +		err = devm_request_irq(&pdev->dev, irq_csi, mx25_camera_irq, 0,
> +				       MX2_CAM_DRV_NAME, pcdev);
>  		if (err) {
>  			dev_err(pcdev->dev, "Camera interrupt register failed \n");
> -			goto exit_iounmap;
> +			goto exit;
>  		}
>  	}
>  
>  	if (cpu_is_mx27()) {
> -		/* EMMA support */
> -		res_emma = platform_get_resource(pdev, IORESOURCE_MEM, 1);
> -		irq_emma = platform_get_irq(pdev, 1);
> -
> -		if (!res_emma || !irq_emma) {
> -			dev_err(&pdev->dev, "no EMMA resources\n");
> -			goto exit_free_irq;
> -		}
> -
> -		pcdev->res_emma = res_emma;
> -		pcdev->irq_emma = irq_emma;
> -		if (mx27_camera_emma_init(pcdev))
> -			goto exit_free_irq;
> +		err = mx27_camera_emma_init(pdev);
> +		if (err)
> +			goto exit;
>  	}
>  
>  	pcdev->soc_host.drv_name	= MX2_CAM_DRV_NAME,
> @@ -1793,25 +1763,9 @@ exit_free_emma:
>  	vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx);
>  eallocctx:
>  	if (cpu_is_mx27()) {
> -		free_irq(pcdev->irq_emma, pcdev);
>  		clk_disable_unprepare(pcdev->clk_emma_ipg);
> -		clk_put(pcdev->clk_emma_ipg);
>  		clk_disable_unprepare(pcdev->clk_emma_ahb);
> -		clk_put(pcdev->clk_emma_ahb);
> -		iounmap(pcdev->base_emma);
> -		release_mem_region(pcdev->res_emma->start, resource_size(pcdev->res_emma));
>  	}
> -exit_free_irq:
> -	if (cpu_is_mx25())
> -		free_irq(pcdev->irq_csi, pcdev);
> -exit_iounmap:
> -	iounmap(base_csi);
> -exit_release:
> -	release_mem_region(res_csi->start, resource_size(res_csi));
> -exit_dma_free:
> -	clk_put(pcdev->clk_csi);
> -exit_kfree:
> -	kfree(pcdev);
>  exit:
>  	return err;
>  }
> @@ -1821,35 +1775,16 @@ static int __devexit mx2_camera_remove(struct platform_device *pdev)
>  	struct soc_camera_host *soc_host = to_soc_camera_host(&pdev->dev);
>  	struct mx2_camera_dev *pcdev = container_of(soc_host,
>  			struct mx2_camera_dev, soc_host);
> -	struct resource *res;
> -
> -	clk_put(pcdev->clk_csi);
> -	if (cpu_is_mx25())
> -		free_irq(pcdev->irq_csi, pcdev);
> -	if (cpu_is_mx27())
> -		free_irq(pcdev->irq_emma, pcdev);
>  
>  	soc_camera_host_unregister(&pcdev->soc_host);
>  
>  	vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx);
>  
> -	iounmap(pcdev->base_csi);
> -
>  	if (cpu_is_mx27()) {
>  		clk_disable_unprepare(pcdev->clk_emma_ipg);
> -		clk_put(pcdev->clk_emma_ipg);
>  		clk_disable_unprepare(pcdev->clk_emma_ahb);
> -		clk_put(pcdev->clk_emma_ahb);
> -		iounmap(pcdev->base_emma);
> -		res = pcdev->res_emma;
> -		release_mem_region(res->start, resource_size(res));
>  	}
>  
> -	res = pcdev->res_csi;
> -	release_mem_region(res->start, resource_size(res));
> -
> -	kfree(pcdev);
> -
>  	dev_info(&pdev->dev, "MX2 Camera driver unloaded\n");
>  
>  	return 0;
> -- 
> 1.7.9.5
> 

---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Javier Martin Sept. 17, 2012, 1:36 p.m. UTC | #2
Hi,

On 17 September 2012 11:11, Guennadi Liakhovetski <g.liakhovetski@gmx.de> wrote:
> On Mon, 17 Sep 2012, Shawn Guo wrote:
>
>> Use managed functions to clean up the error handling code and function
>> mx2_camera_remove().  Along with the change, a few variables get removed
>> from struct mx2_camera_dev.
>>
>> Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
>> Cc: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
>> Cc: linux-media@vger.kernel.org
>
> (in case you want to push it via arm-soc)
>
> Acked-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>

This patch breaks the driver:

soc-camera-pdrv soc-camera-pdrv.0: Probing soc-camera-pdrv.0
Unable to handle kernel paging request at virtual address 656d6162
pgd = c0004000
[656d6162] *pgd=00000000
Internal error: Oops: 80000005 [#1] PREEMPT ARM
Modules linked in:
CPU: 0    Not tainted  (3.6.0-rc5-01222-g3413fb1 #12)
PC is at 0x656d6162
LR is at soc_camera_host_register+0x230/0x81c
pc : [<656d6162>]    lr : [<c01ff6a0>]    psr: 40000033
sp : c3025e48  ip : 00000000  fp : 00000000
r10: c03f236c  r9 : 00000000  r8 : 00000001
r7 : 00000000  r6 : c317d414  r5 : c30431a0  r4 : c317d600
r3 : 656d6163  r2 : c3025e18  r1 : 000c0000  r0 : c317d600
Flags: nZcv  IRQs on  FIQs on  Mode SVC_32  ISA Thumb  Segment kernel
Control: 0005317f  Table: a0004000  DAC: 00000017
Process swapper (pid: 1, stack limit = 0xc3024270)
Stack: (0xc3025e48 to 0xc3026000)
5e40:                   c3006460 00000000 c3192960 00000043 c317d638 c005d624
5e60: 00000043 c317d410 c317d478 c317d414 c02012f0 c317d410 00000000 00000043
5e80: c31a9800 c31a9820 00000000 c022ca74 c300ab20 00000000 c306e4a8 c306e4a0
5ea0: c30000c0 40000013 000080d0 c317d410 c317d410 c306e4a8 c306e4a0 00000001
5ec0: 00000000 c03f236c 00000000 c02c8d50 00000000 c03535ee c317d410 c02c8a44
5ee0: c306e4a8 c306e4a8 c03fc478 c03fc478 00000050 c03e0774 c03dc684 c0189d30
5f00: c306e4a8 c0188c3c c306e4a8 c306e4dc c03fc478 00000000 00000050 c0188db8
5f20: c03fc478 c3025f30 c0188d58 c0187610 c300760c c3079ad0 c03fc478 c03fc478
5f40: c318e680 c03f6458 00000000 c0187d24 c03535ee c03535ee c3025f58 c03fc478
5f60: 00000001 c04049c0 00000000 c01892c8 c03fc464 00000001 c04049c0 00000000
5f80: 00000050 c018a05c c03dc67c c03d4e84 c04049c0 c00087c8 00000006 00000006
5fa0: c03eeca0 c03dc67c 00000007 c03dc67c 00000007 c04049c0 c03c41a4 00000050
5fc0: c03e0774 c03c42f4 00000006 00000006 c03c41a4 00000000 00000000 c03c4214
5fe0: c0014900 00000013 00000000 00000000 00000000 c0014900 ffffffff ffffffff
[<c01ff6a0>] (soc_camera_host_register+0x230/0x81c) from [<c02c8d50>]
(mx2_camera_probe+0x30c/0x3ac)
[<c02c8d50>] (mx2_camera_probe+0x30c/0x3ac) from [<c0189d30>]
(platform_drv_probe+0x14/0x18)
[<c0189d30>] (platform_drv_probe+0x14/0x18) from [<c0188c3c>]
(driver_probe_device+0xb0/0x1cc)
[<c0188c3c>] (driver_probe_device+0xb0/0x1cc) from [<c0188db8>]
(__driver_attach+0x60/0x84)
[<c0188db8>] (__driver_attach+0x60/0x84) from [<c0187610>]
(bus_for_each_dev+0x48/0x84)
[<c0187610>] (bus_for_each_dev+0x48/0x84) from [<c0187d24>]
(bus_add_driver+0x9c/0x20c)
[<c0187d24>] (bus_add_driver+0x9c/0x20c) from [<c01892c8>]
(driver_register+0xa0/0x138)
[<c01892c8>] (driver_register+0xa0/0x138) from [<c018a05c>]
(platform_driver_probe+0x18/0x98)
[<c018a05c>] (platform_driver_probe+0x18/0x98) from [<c00087c8>]
(do_one_initcall+0x94/0x16c)
[<c00087c8>] (do_one_initcall+0x94/0x16c) from [<c03c42f4>]
(kernel_init+0xe0/0x1ac)
[<c03c42f4>] (kernel_init+0xe0/0x1ac) from [<c0014900>]
(kernel_thread_exit+0x0/0x8)
Code: bad PC value
---[ end trace 7f259a1ce2e10b1a ]---
Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
Shawn Guo Sept. 18, 2012, 7:43 a.m. UTC | #3
On Mon, Sep 17, 2012 at 03:36:07PM +0200, javier Martin wrote:
> This patch breaks the driver:
> 
Javier,

Can you please apply the following change to see if it fixes the
problem?

Shawn

@@ -1783,6 +1783,8 @@ static int __devinit mx2_camera_probe(struct platform_device *pdev)
                        goto exit;
        }

+       platform_set_drvdata(pdev, NULL);
+
        pcdev->soc_host.drv_name        = MX2_CAM_DRV_NAME,
        pcdev->soc_host.ops             = &mx2_soc_camera_host_ops,
        pcdev->soc_host.priv            = pcdev;

> soc-camera-pdrv soc-camera-pdrv.0: Probing soc-camera-pdrv.0
> Unable to handle kernel paging request at virtual address 656d6162
> pgd = c0004000
> [656d6162] *pgd=00000000
> Internal error: Oops: 80000005 [#1] PREEMPT ARM
> Modules linked in:
> CPU: 0    Not tainted  (3.6.0-rc5-01222-g3413fb1 #12)
> PC is at 0x656d6162
> LR is at soc_camera_host_register+0x230/0x81c
> pc : [<656d6162>]    lr : [<c01ff6a0>]    psr: 40000033
> sp : c3025e48  ip : 00000000  fp : 00000000
> r10: c03f236c  r9 : 00000000  r8 : 00000001
> r7 : 00000000  r6 : c317d414  r5 : c30431a0  r4 : c317d600
> r3 : 656d6163  r2 : c3025e18  r1 : 000c0000  r0 : c317d600
> Flags: nZcv  IRQs on  FIQs on  Mode SVC_32  ISA Thumb  Segment kernel
> Control: 0005317f  Table: a0004000  DAC: 00000017
> Process swapper (pid: 1, stack limit = 0xc3024270)
> Stack: (0xc3025e48 to 0xc3026000)
> 5e40:                   c3006460 00000000 c3192960 00000043 c317d638 c005d624
> 5e60: 00000043 c317d410 c317d478 c317d414 c02012f0 c317d410 00000000 00000043
> 5e80: c31a9800 c31a9820 00000000 c022ca74 c300ab20 00000000 c306e4a8 c306e4a0
> 5ea0: c30000c0 40000013 000080d0 c317d410 c317d410 c306e4a8 c306e4a0 00000001
> 5ec0: 00000000 c03f236c 00000000 c02c8d50 00000000 c03535ee c317d410 c02c8a44
> 5ee0: c306e4a8 c306e4a8 c03fc478 c03fc478 00000050 c03e0774 c03dc684 c0189d30
> 5f00: c306e4a8 c0188c3c c306e4a8 c306e4dc c03fc478 00000000 00000050 c0188db8
> 5f20: c03fc478 c3025f30 c0188d58 c0187610 c300760c c3079ad0 c03fc478 c03fc478
> 5f40: c318e680 c03f6458 00000000 c0187d24 c03535ee c03535ee c3025f58 c03fc478
> 5f60: 00000001 c04049c0 00000000 c01892c8 c03fc464 00000001 c04049c0 00000000
> 5f80: 00000050 c018a05c c03dc67c c03d4e84 c04049c0 c00087c8 00000006 00000006
> 5fa0: c03eeca0 c03dc67c 00000007 c03dc67c 00000007 c04049c0 c03c41a4 00000050
> 5fc0: c03e0774 c03c42f4 00000006 00000006 c03c41a4 00000000 00000000 c03c4214
> 5fe0: c0014900 00000013 00000000 00000000 00000000 c0014900 ffffffff ffffffff
> [<c01ff6a0>] (soc_camera_host_register+0x230/0x81c) from [<c02c8d50>]
> (mx2_camera_probe+0x30c/0x3ac)
> [<c02c8d50>] (mx2_camera_probe+0x30c/0x3ac) from [<c0189d30>]
> (platform_drv_probe+0x14/0x18)
> [<c0189d30>] (platform_drv_probe+0x14/0x18) from [<c0188c3c>]
> (driver_probe_device+0xb0/0x1cc)
> [<c0188c3c>] (driver_probe_device+0xb0/0x1cc) from [<c0188db8>]
> (__driver_attach+0x60/0x84)
> [<c0188db8>] (__driver_attach+0x60/0x84) from [<c0187610>]
> (bus_for_each_dev+0x48/0x84)
> [<c0187610>] (bus_for_each_dev+0x48/0x84) from [<c0187d24>]
> (bus_add_driver+0x9c/0x20c)
> [<c0187d24>] (bus_add_driver+0x9c/0x20c) from [<c01892c8>]
> (driver_register+0xa0/0x138)
> [<c01892c8>] (driver_register+0xa0/0x138) from [<c018a05c>]
> (platform_driver_probe+0x18/0x98)
> [<c018a05c>] (platform_driver_probe+0x18/0x98) from [<c00087c8>]
> (do_one_initcall+0x94/0x16c)
> [<c00087c8>] (do_one_initcall+0x94/0x16c) from [<c03c42f4>]
> (kernel_init+0xe0/0x1ac)
> [<c03c42f4>] (kernel_init+0xe0/0x1ac) from [<c0014900>]
> (kernel_thread_exit+0x0/0x8)
> Code: bad PC value
> ---[ end trace 7f259a1ce2e10b1a ]---
> Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Javier Martin Sept. 18, 2012, 8:34 a.m. UTC | #4
Hi Shawn,

On 18 September 2012 09:43, Shawn Guo <shawn.guo@linaro.org> wrote:
> On Mon, Sep 17, 2012 at 03:36:07PM +0200, javier Martin wrote:
>> This patch breaks the driver:
>>
> Javier,
>
> Can you please apply the following change to see if it fixes the
> problem?
>
> Shawn
>
> @@ -1783,6 +1783,8 @@ static int __devinit mx2_camera_probe(struct platform_device *pdev)
>                         goto exit;
>         }
>
> +       platform_set_drvdata(pdev, NULL);
> +
>         pcdev->soc_host.drv_name        = MX2_CAM_DRV_NAME,
>         pcdev->soc_host.ops             = &mx2_soc_camera_host_ops,
>         pcdev->soc_host.priv            = pcdev;

Yes. That fixes the problem.

With this fix:

Tested-by: Javier Martin <javier.martin@vista-silicon.com>

Regards.
diff mbox

Patch

diff --git a/drivers/media/video/mx2_camera.c b/drivers/media/video/mx2_camera.c
index 89c7e28..fe4c76c 100644
--- a/drivers/media/video/mx2_camera.c
+++ b/drivers/media/video/mx2_camera.c
@@ -274,12 +274,9 @@  struct mx2_camera_dev {
 	struct soc_camera_device *icd;
 	struct clk		*clk_csi, *clk_emma_ahb, *clk_emma_ipg;
 
-	unsigned int		irq_csi, irq_emma;
 	void __iomem		*base_csi, *base_emma;
-	unsigned long		base_dma;
 
 	struct mx2_camera_platform_data *pdata;
-	struct resource		*res_csi, *res_emma;
 	unsigned long		platform_flags;
 
 	struct list_head	capture;
@@ -1607,64 +1604,59 @@  static irqreturn_t mx27_camera_emma_irq(int irq_emma, void *data)
 	return IRQ_HANDLED;
 }
 
-static int __devinit mx27_camera_emma_init(struct mx2_camera_dev *pcdev)
+static int __devinit mx27_camera_emma_init(struct platform_device *pdev)
 {
-	struct resource *res_emma = pcdev->res_emma;
+	struct mx2_camera_dev *pcdev = platform_get_drvdata(pdev);
+	struct resource *res_emma;
+	int irq_emma;
 	int err = 0;
 
-	if (!request_mem_region(res_emma->start, resource_size(res_emma),
-				MX2_CAM_DRV_NAME)) {
-		err = -EBUSY;
+	res_emma = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+	irq_emma = platform_get_irq(pdev, 1);
+	if (!res_emma || !irq_emma) {
+		dev_err(pcdev->dev, "no EMMA resources\n");
 		goto out;
 	}
 
-	pcdev->base_emma = ioremap(res_emma->start, resource_size(res_emma));
+	pcdev->base_emma = devm_request_and_ioremap(pcdev->dev, res_emma);
 	if (!pcdev->base_emma) {
-		err = -ENOMEM;
-		goto exit_release;
+		err = -EADDRNOTAVAIL;
+		goto out;
 	}
 
-	err = request_irq(pcdev->irq_emma, mx27_camera_emma_irq, 0,
-			MX2_CAM_DRV_NAME, pcdev);
+	err = devm_request_irq(pcdev->dev, irq_emma, mx27_camera_emma_irq, 0,
+			       MX2_CAM_DRV_NAME, pcdev);
 	if (err) {
 		dev_err(pcdev->dev, "Camera EMMA interrupt register failed \n");
-		goto exit_iounmap;
+		goto out;
 	}
 
-	pcdev->clk_emma_ipg = clk_get(pcdev->dev, "emma-ipg");
+	pcdev->clk_emma_ipg = devm_clk_get(pcdev->dev, "emma-ipg");
 	if (IS_ERR(pcdev->clk_emma_ipg)) {
 		err = PTR_ERR(pcdev->clk_emma_ipg);
-		goto exit_free_irq;
+		goto out;
 	}
 
 	clk_prepare_enable(pcdev->clk_emma_ipg);
 
-	pcdev->clk_emma_ahb = clk_get(pcdev->dev, "emma-ahb");
+	pcdev->clk_emma_ahb = devm_clk_get(pcdev->dev, "emma-ahb");
 	if (IS_ERR(pcdev->clk_emma_ahb)) {
 		err = PTR_ERR(pcdev->clk_emma_ahb);
-		goto exit_clk_emma_ipg_put;
+		goto exit_clk_emma_ipg;
 	}
 
 	clk_prepare_enable(pcdev->clk_emma_ahb);
 
 	err = mx27_camera_emma_prp_reset(pcdev);
 	if (err)
-		goto exit_clk_emma_ahb_put;
+		goto exit_clk_emma_ahb;
 
 	return err;
 
-exit_clk_emma_ahb_put:
+exit_clk_emma_ahb:
 	clk_disable_unprepare(pcdev->clk_emma_ahb);
-	clk_put(pcdev->clk_emma_ahb);
-exit_clk_emma_ipg_put:
+exit_clk_emma_ipg:
 	clk_disable_unprepare(pcdev->clk_emma_ipg);
-	clk_put(pcdev->clk_emma_ipg);
-exit_free_irq:
-	free_irq(pcdev->irq_emma, pcdev);
-exit_iounmap:
-	iounmap(pcdev->base_emma);
-exit_release:
-	release_mem_region(res_emma->start, resource_size(res_emma));
 out:
 	return err;
 }
@@ -1672,9 +1664,8 @@  out:
 static int __devinit mx2_camera_probe(struct platform_device *pdev)
 {
 	struct mx2_camera_dev *pcdev;
-	struct resource *res_csi, *res_emma;
-	void __iomem *base_csi;
-	int irq_csi, irq_emma;
+	struct resource *res_csi;
+	int irq_csi;
 	int err = 0;
 
 	dev_dbg(&pdev->dev, "initialising\n");
@@ -1687,21 +1678,20 @@  static int __devinit mx2_camera_probe(struct platform_device *pdev)
 		goto exit;
 	}
 
-	pcdev = kzalloc(sizeof(*pcdev), GFP_KERNEL);
+	pcdev = devm_kzalloc(&pdev->dev, sizeof(*pcdev), GFP_KERNEL);
 	if (!pcdev) {
 		dev_err(&pdev->dev, "Could not allocate pcdev\n");
 		err = -ENOMEM;
 		goto exit;
 	}
 
-	pcdev->clk_csi = clk_get(&pdev->dev, "ahb");
+	pcdev->clk_csi = devm_clk_get(&pdev->dev, "ahb");
 	if (IS_ERR(pcdev->clk_csi)) {
 		dev_err(&pdev->dev, "Could not get csi clock\n");
 		err = PTR_ERR(pcdev->clk_csi);
-		goto exit_kfree;
+		goto exit;
 	}
 
-	pcdev->res_csi = res_csi;
 	pcdev->pdata = pdev->dev.platform_data;
 	if (pcdev->pdata) {
 		long rate;
@@ -1711,11 +1701,11 @@  static int __devinit mx2_camera_probe(struct platform_device *pdev)
 		rate = clk_round_rate(pcdev->clk_csi, pcdev->pdata->clk * 2);
 		if (rate <= 0) {
 			err = -ENODEV;
-			goto exit_dma_free;
+			goto exit;
 		}
 		err = clk_set_rate(pcdev->clk_csi, rate);
 		if (err < 0)
-			goto exit_dma_free;
+			goto exit;
 	}
 
 	INIT_LIST_HEAD(&pcdev->capture);
@@ -1723,48 +1713,28 @@  static int __devinit mx2_camera_probe(struct platform_device *pdev)
 	INIT_LIST_HEAD(&pcdev->discard);
 	spin_lock_init(&pcdev->lock);
 
-	/*
-	 * Request the regions.
-	 */
-	if (!request_mem_region(res_csi->start, resource_size(res_csi),
-				MX2_CAM_DRV_NAME)) {
-		err = -EBUSY;
-		goto exit_dma_free;
+	pcdev->base_csi = devm_request_and_ioremap(&pdev->dev, res_csi);
+	if (!pcdev->base_csi) {
+		err = -EADDRNOTAVAIL;
+		goto exit;
 	}
 
-	base_csi = ioremap(res_csi->start, resource_size(res_csi));
-	if (!base_csi) {
-		err = -ENOMEM;
-		goto exit_release;
-	}
-	pcdev->irq_csi = irq_csi;
-	pcdev->base_csi = base_csi;
-	pcdev->base_dma = res_csi->start;
 	pcdev->dev = &pdev->dev;
+	platform_set_drvdata(pdev, pcdev);
 
 	if (cpu_is_mx25()) {
-		err = request_irq(pcdev->irq_csi, mx25_camera_irq, 0,
-				MX2_CAM_DRV_NAME, pcdev);
+		err = devm_request_irq(&pdev->dev, irq_csi, mx25_camera_irq, 0,
+				       MX2_CAM_DRV_NAME, pcdev);
 		if (err) {
 			dev_err(pcdev->dev, "Camera interrupt register failed \n");
-			goto exit_iounmap;
+			goto exit;
 		}
 	}
 
 	if (cpu_is_mx27()) {
-		/* EMMA support */
-		res_emma = platform_get_resource(pdev, IORESOURCE_MEM, 1);
-		irq_emma = platform_get_irq(pdev, 1);
-
-		if (!res_emma || !irq_emma) {
-			dev_err(&pdev->dev, "no EMMA resources\n");
-			goto exit_free_irq;
-		}
-
-		pcdev->res_emma = res_emma;
-		pcdev->irq_emma = irq_emma;
-		if (mx27_camera_emma_init(pcdev))
-			goto exit_free_irq;
+		err = mx27_camera_emma_init(pdev);
+		if (err)
+			goto exit;
 	}
 
 	pcdev->soc_host.drv_name	= MX2_CAM_DRV_NAME,
@@ -1793,25 +1763,9 @@  exit_free_emma:
 	vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx);
 eallocctx:
 	if (cpu_is_mx27()) {
-		free_irq(pcdev->irq_emma, pcdev);
 		clk_disable_unprepare(pcdev->clk_emma_ipg);
-		clk_put(pcdev->clk_emma_ipg);
 		clk_disable_unprepare(pcdev->clk_emma_ahb);
-		clk_put(pcdev->clk_emma_ahb);
-		iounmap(pcdev->base_emma);
-		release_mem_region(pcdev->res_emma->start, resource_size(pcdev->res_emma));
 	}
-exit_free_irq:
-	if (cpu_is_mx25())
-		free_irq(pcdev->irq_csi, pcdev);
-exit_iounmap:
-	iounmap(base_csi);
-exit_release:
-	release_mem_region(res_csi->start, resource_size(res_csi));
-exit_dma_free:
-	clk_put(pcdev->clk_csi);
-exit_kfree:
-	kfree(pcdev);
 exit:
 	return err;
 }
@@ -1821,35 +1775,16 @@  static int __devexit mx2_camera_remove(struct platform_device *pdev)
 	struct soc_camera_host *soc_host = to_soc_camera_host(&pdev->dev);
 	struct mx2_camera_dev *pcdev = container_of(soc_host,
 			struct mx2_camera_dev, soc_host);
-	struct resource *res;
-
-	clk_put(pcdev->clk_csi);
-	if (cpu_is_mx25())
-		free_irq(pcdev->irq_csi, pcdev);
-	if (cpu_is_mx27())
-		free_irq(pcdev->irq_emma, pcdev);
 
 	soc_camera_host_unregister(&pcdev->soc_host);
 
 	vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx);
 
-	iounmap(pcdev->base_csi);
-
 	if (cpu_is_mx27()) {
 		clk_disable_unprepare(pcdev->clk_emma_ipg);
-		clk_put(pcdev->clk_emma_ipg);
 		clk_disable_unprepare(pcdev->clk_emma_ahb);
-		clk_put(pcdev->clk_emma_ahb);
-		iounmap(pcdev->base_emma);
-		res = pcdev->res_emma;
-		release_mem_region(res->start, resource_size(res));
 	}
 
-	res = pcdev->res_csi;
-	release_mem_region(res->start, resource_size(res));
-
-	kfree(pcdev);
-
 	dev_info(&pdev->dev, "MX2 Camera driver unloaded\n");
 
 	return 0;