diff options
author | Baruch Siach <baruch@tkos.co.il> | 2013-12-30 13:30:44 -0500 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2013-12-31 07:30:18 -0500 |
commit | 04f421e7b0b10de3fae543dac4d324b449a1db6b (patch) | |
tree | cdbb475e66a2ac6bc755d83f04eeabaf43569cbb /drivers/spi/spi-dw-mmio.c | |
parent | 0a47d3c40428fb8174ea36ede35267ddc7042f34 (diff) |
spi: dw: use managed resources
Migrate mmio code and core driver to managed resources to reduce boilerplate
error handling code. Also, handle clk_enable() failure while at it, and drop
unused dw_spi iolen field.
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'drivers/spi/spi-dw-mmio.c')
-rw-r--r-- | drivers/spi/spi-dw-mmio.c | 70 |
1 files changed, 20 insertions, 50 deletions
diff --git a/drivers/spi/spi-dw-mmio.c b/drivers/spi/spi-dw-mmio.c index 168c620947f4..569adf877b16 100644 --- a/drivers/spi/spi-dw-mmio.c +++ b/drivers/spi/spi-dw-mmio.c | |||
@@ -30,14 +30,13 @@ static int dw_spi_mmio_probe(struct platform_device *pdev) | |||
30 | { | 30 | { |
31 | struct dw_spi_mmio *dwsmmio; | 31 | struct dw_spi_mmio *dwsmmio; |
32 | struct dw_spi *dws; | 32 | struct dw_spi *dws; |
33 | struct resource *mem, *ioarea; | 33 | struct resource *mem; |
34 | int ret; | 34 | int ret; |
35 | 35 | ||
36 | dwsmmio = kzalloc(sizeof(struct dw_spi_mmio), GFP_KERNEL); | 36 | dwsmmio = devm_kzalloc(&pdev->dev, sizeof(struct dw_spi_mmio), |
37 | if (!dwsmmio) { | 37 | GFP_KERNEL); |
38 | ret = -ENOMEM; | 38 | if (!dwsmmio) |
39 | goto err_end; | 39 | return -ENOMEM; |
40 | } | ||
41 | 40 | ||
42 | dws = &dwsmmio->dws; | 41 | dws = &dwsmmio->dws; |
43 | 42 | ||
@@ -45,80 +44,51 @@ static int dw_spi_mmio_probe(struct platform_device *pdev) | |||
45 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 44 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
46 | if (!mem) { | 45 | if (!mem) { |
47 | dev_err(&pdev->dev, "no mem resource?\n"); | 46 | dev_err(&pdev->dev, "no mem resource?\n"); |
48 | ret = -EINVAL; | 47 | return -EINVAL; |
49 | goto err_kfree; | ||
50 | } | 48 | } |
51 | 49 | ||
52 | ioarea = request_mem_region(mem->start, resource_size(mem), | 50 | dws->regs = devm_ioremap_resource(&pdev->dev, mem); |
53 | pdev->name); | 51 | if (IS_ERR(dws->regs)) { |
54 | if (!ioarea) { | 52 | dev_err(&pdev->dev, "SPI region map failed\n"); |
55 | dev_err(&pdev->dev, "SPI region already claimed\n"); | 53 | return PTR_ERR(dws->regs); |
56 | ret = -EBUSY; | ||
57 | goto err_kfree; | ||
58 | } | ||
59 | |||
60 | dws->regs = ioremap_nocache(mem->start, resource_size(mem)); | ||
61 | if (!dws->regs) { | ||
62 | dev_err(&pdev->dev, "SPI region already mapped\n"); | ||
63 | ret = -ENOMEM; | ||
64 | goto err_release_reg; | ||
65 | } | 54 | } |
66 | 55 | ||
67 | dws->irq = platform_get_irq(pdev, 0); | 56 | dws->irq = platform_get_irq(pdev, 0); |
68 | if (dws->irq < 0) { | 57 | if (dws->irq < 0) { |
69 | dev_err(&pdev->dev, "no irq resource?\n"); | 58 | dev_err(&pdev->dev, "no irq resource?\n"); |
70 | ret = dws->irq; /* -ENXIO */ | 59 | return dws->irq; /* -ENXIO */ |
71 | goto err_unmap; | ||
72 | } | 60 | } |
73 | 61 | ||
74 | dwsmmio->clk = clk_get(&pdev->dev, NULL); | 62 | dwsmmio->clk = devm_clk_get(&pdev->dev, NULL); |
75 | if (IS_ERR(dwsmmio->clk)) { | 63 | if (IS_ERR(dwsmmio->clk)) |
76 | ret = PTR_ERR(dwsmmio->clk); | 64 | return PTR_ERR(dwsmmio->clk); |
77 | goto err_unmap; | 65 | ret = clk_enable(dwsmmio->clk); |
78 | } | 66 | if (ret) |
79 | clk_enable(dwsmmio->clk); | 67 | return ret; |
80 | 68 | ||
81 | dws->parent_dev = &pdev->dev; | ||
82 | dws->bus_num = 0; | 69 | dws->bus_num = 0; |
83 | dws->num_cs = 4; | 70 | dws->num_cs = 4; |
84 | dws->max_freq = clk_get_rate(dwsmmio->clk); | 71 | dws->max_freq = clk_get_rate(dwsmmio->clk); |
85 | 72 | ||
86 | ret = dw_spi_add_host(dws); | 73 | ret = dw_spi_add_host(&pdev->dev, dws); |
87 | if (ret) | 74 | if (ret) |
88 | goto err_clk; | 75 | goto out; |
89 | 76 | ||
90 | platform_set_drvdata(pdev, dwsmmio); | 77 | platform_set_drvdata(pdev, dwsmmio); |
91 | return 0; | 78 | return 0; |
92 | 79 | ||
93 | err_clk: | 80 | out: |
94 | clk_disable(dwsmmio->clk); | 81 | clk_disable(dwsmmio->clk); |
95 | clk_put(dwsmmio->clk); | ||
96 | dwsmmio->clk = NULL; | ||
97 | err_unmap: | ||
98 | iounmap(dws->regs); | ||
99 | err_release_reg: | ||
100 | release_mem_region(mem->start, resource_size(mem)); | ||
101 | err_kfree: | ||
102 | kfree(dwsmmio); | ||
103 | err_end: | ||
104 | return ret; | 82 | return ret; |
105 | } | 83 | } |
106 | 84 | ||
107 | static int dw_spi_mmio_remove(struct platform_device *pdev) | 85 | static int dw_spi_mmio_remove(struct platform_device *pdev) |
108 | { | 86 | { |
109 | struct dw_spi_mmio *dwsmmio = platform_get_drvdata(pdev); | 87 | struct dw_spi_mmio *dwsmmio = platform_get_drvdata(pdev); |
110 | struct resource *mem; | ||
111 | 88 | ||
112 | clk_disable(dwsmmio->clk); | 89 | clk_disable(dwsmmio->clk); |
113 | clk_put(dwsmmio->clk); | ||
114 | dwsmmio->clk = NULL; | ||
115 | |||
116 | dw_spi_remove_host(&dwsmmio->dws); | 90 | dw_spi_remove_host(&dwsmmio->dws); |
117 | iounmap(dwsmmio->dws.regs); | ||
118 | kfree(dwsmmio); | ||
119 | 91 | ||
120 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
121 | release_mem_region(mem->start, resource_size(mem)); | ||
122 | return 0; | 92 | return 0; |
123 | } | 93 | } |
124 | 94 | ||