mvebu: backport mainline patches from kernel 3.12
[openwrt.git] / target / linux / mvebu / patches-3.10 / 0106-mtd-nand-pxa3xx-Move-buffer-release-code-to-its-own-.patch
1 From 49ff5bd7d4d51a8eb05796f130e9a1a96d18f522 Mon Sep 17 00:00:00 2001
2 From: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
3 Date: Wed, 17 Apr 2013 13:38:14 -0300
4 Subject: [PATCH 106/203] mtd: nand: pxa3xx: Move buffer release code to its
5  own function
6
7 Create a function to release the buffer and the dma channel, thus undoing
8 what pxa3xx_nand_init_buff() did. This commit makes the code more readable
9 and will allow to handle non-DMA capable platforms easier.
10
11 Signed-off-by: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
12 Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
13 Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
14 ---
15  drivers/mtd/nand/pxa3xx_nand.c | 26 ++++++++++++++------------
16  1 file changed, 14 insertions(+), 12 deletions(-)
17
18 --- a/drivers/mtd/nand/pxa3xx_nand.c
19 +++ b/drivers/mtd/nand/pxa3xx_nand.c
20 @@ -912,6 +912,18 @@ static int pxa3xx_nand_init_buff(struct
21         return 0;
22  }
23  
24 +static void pxa3xx_nand_free_buff(struct pxa3xx_nand_info *info)
25 +{
26 +       struct platform_device *pdev = info->pdev;
27 +       if (use_dma) {
28 +               pxa_free_dma(info->data_dma_ch);
29 +               dma_free_coherent(&pdev->dev, MAX_BUFF_SIZE,
30 +                                 info->data_buff, info->data_buff_phys);
31 +       } else {
32 +               kfree(info->data_buff);
33 +       }
34 +}
35 +
36  static int pxa3xx_nand_sensing(struct pxa3xx_nand_info *info)
37  {
38         struct mtd_info *mtd;
39 @@ -1137,12 +1149,7 @@ static int alloc_nand_resource(struct pl
40  
41  fail_free_buf:
42         free_irq(irq, info);
43 -       if (use_dma) {
44 -               pxa_free_dma(info->data_dma_ch);
45 -               dma_free_coherent(&pdev->dev, MAX_BUFF_SIZE,
46 -                       info->data_buff, info->data_buff_phys);
47 -       } else
48 -               kfree(info->data_buff);
49 +       pxa3xx_nand_free_buff(info);
50  fail_disable_clk:
51         clk_disable_unprepare(info->clk);
52         return ret;
53 @@ -1163,12 +1170,7 @@ static int pxa3xx_nand_remove(struct pla
54         irq = platform_get_irq(pdev, 0);
55         if (irq >= 0)
56                 free_irq(irq, info);
57 -       if (use_dma) {
58 -               pxa_free_dma(info->data_dma_ch);
59 -               dma_free_writecombine(&pdev->dev, MAX_BUFF_SIZE,
60 -                               info->data_buff, info->data_buff_phys);
61 -       } else
62 -               kfree(info->data_buff);
63 +       pxa3xx_nand_free_buff(info);
64  
65         clk_disable_unprepare(info->clk);
66