aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pwm/pwm-vt8500.c
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@gmail.com>2012-06-30 20:29:28 -0400
committerThierry Reding <thierry.reding@avionic-design.de>2012-07-23 07:23:58 -0400
commit261995dd305ff991ca1cfb462862a5311739333b (patch)
tree3d1077936c0b6d6c08ab1c3f9966a7340b246bb4 /drivers/pwm/pwm-vt8500.c
parenta9970e3becbbb095296afdf0bcaa1ce2b819360f (diff)
pwm: Convert pwm-vt8500 to use devm_* APIs
Signed-off-by: Axel Lin <axel.lin@gmail.com> Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Diffstat (limited to 'drivers/pwm/pwm-vt8500.c')
-rw-r--r--drivers/pwm/pwm-vt8500.c47
1 files changed, 8 insertions, 39 deletions
diff --git a/drivers/pwm/pwm-vt8500.c b/drivers/pwm/pwm-vt8500.c
index 3db0746f7200..548021439f0c 100644
--- a/drivers/pwm/pwm-vt8500.c
+++ b/drivers/pwm/pwm-vt8500.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * arch/arm/mach-vt8500/pwm.c 2 * drivers/pwm/pwm-vt8500.c
3 * 3 *
4 * Copyright (C) 2010 Alexey Charkov <alchark@gmail.com> 4 * Copyright (C) 2010 Alexey Charkov <alchark@gmail.com>
5 * 5 *
@@ -113,7 +113,7 @@ static int __devinit pwm_probe(struct platform_device *pdev)
113 struct resource *r; 113 struct resource *r;
114 int ret; 114 int ret;
115 115
116 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 116 chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
117 if (chip == NULL) { 117 if (chip == NULL) {
118 dev_err(&pdev->dev, "failed to allocate memory\n"); 118 dev_err(&pdev->dev, "failed to allocate memory\n");
119 return -ENOMEM; 119 return -ENOMEM;
@@ -127,61 +127,30 @@ static int __devinit pwm_probe(struct platform_device *pdev)
127 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 127 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
128 if (r == NULL) { 128 if (r == NULL) {
129 dev_err(&pdev->dev, "no memory resource defined\n"); 129 dev_err(&pdev->dev, "no memory resource defined\n");
130 ret = -ENODEV; 130 return -ENODEV;
131 goto err_free;
132 } 131 }
133 132
134 r = request_mem_region(r->start, resource_size(r), pdev->name); 133 chip->base = devm_request_and_ioremap(&pdev->dev, r);
135 if (r == NULL) { 134 if (chip->base == NULL)
136 dev_err(&pdev->dev, "failed to request memory resource\n"); 135 return -EADDRNOTAVAIL;
137 ret = -EBUSY;
138 goto err_free;
139 }
140
141 chip->base = ioremap(r->start, resource_size(r));
142 if (chip->base == NULL) {
143 dev_err(&pdev->dev, "failed to ioremap() registers\n");
144 ret = -ENODEV;
145 goto err_free_mem;
146 }
147 136
148 ret = pwmchip_add(&chip->chip); 137 ret = pwmchip_add(&chip->chip);
149 if (ret < 0) 138 if (ret < 0)
150 goto err_unmap; 139 return ret;
151 140
152 platform_set_drvdata(pdev, chip); 141 platform_set_drvdata(pdev, chip);
153 return ret; 142 return ret;
154
155err_unmap:
156 iounmap(chip->base);
157err_free_mem:
158 release_mem_region(r->start, resource_size(r));
159err_free:
160 kfree(chip);
161 return ret;
162} 143}
163 144
164static int __devexit pwm_remove(struct platform_device *pdev) 145static int __devexit pwm_remove(struct platform_device *pdev)
165{ 146{
166 struct vt8500_chip *chip; 147 struct vt8500_chip *chip;
167 struct resource *r;
168 int err;
169 148
170 chip = platform_get_drvdata(pdev); 149 chip = platform_get_drvdata(pdev);
171 if (chip == NULL) 150 if (chip == NULL)
172 return -ENODEV; 151 return -ENODEV;
173 152
174 err = pwmchip_remove(&chip->chip); 153 return pwmchip_remove(&chip->chip);
175 if (err < 0)
176 return err;
177
178 iounmap(chip->base);
179
180 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
181 release_mem_region(r->start, resource_size(r));
182
183 kfree(chip);
184 return 0;
185} 154}
186 155
187static struct platform_driver pwm_driver = { 156static struct platform_driver pwm_driver = {