diff options
-rw-r--r-- | drivers/rtc/rtc-ds1216.c | 44 |
1 files changed, 9 insertions, 35 deletions
diff --git a/drivers/rtc/rtc-ds1216.c b/drivers/rtc/rtc-ds1216.c index 45cd8c9f5a39..c7702b7269f7 100644 --- a/drivers/rtc/rtc-ds1216.c +++ b/drivers/rtc/rtc-ds1216.c | |||
@@ -30,8 +30,6 @@ struct ds1216_regs { | |||
30 | struct ds1216_priv { | 30 | struct ds1216_priv { |
31 | struct rtc_device *rtc; | 31 | struct rtc_device *rtc; |
32 | void __iomem *ioaddr; | 32 | void __iomem *ioaddr; |
33 | size_t size; | ||
34 | unsigned long baseaddr; | ||
35 | }; | 33 | }; |
36 | 34 | ||
37 | static const u8 magic[] = { | 35 | static const u8 magic[] = { |
@@ -144,57 +142,33 @@ static int __init ds1216_rtc_probe(struct platform_device *pdev) | |||
144 | { | 142 | { |
145 | struct resource *res; | 143 | struct resource *res; |
146 | struct ds1216_priv *priv; | 144 | struct ds1216_priv *priv; |
147 | int ret = 0; | ||
148 | u8 dummy[8]; | 145 | u8 dummy[8]; |
149 | 146 | ||
150 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 147 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
151 | if (!res) | 148 | if (!res) |
152 | return -ENODEV; | 149 | return -ENODEV; |
153 | priv = kzalloc(sizeof *priv, GFP_KERNEL); | 150 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); |
154 | if (!priv) | 151 | if (!priv) |
155 | return -ENOMEM; | 152 | return -ENOMEM; |
156 | 153 | ||
157 | platform_set_drvdata(pdev, priv); | 154 | platform_set_drvdata(pdev, priv); |
158 | 155 | ||
159 | priv->size = resource_size(res); | 156 | priv->ioaddr = devm_ioremap_resource(&pdev->dev, res); |
160 | if (!request_mem_region(res->start, priv->size, pdev->name)) { | 157 | if (IS_ERR(priv->ioaddr)) |
161 | ret = -EBUSY; | 158 | return PTR_ERR(priv->ioaddr); |
162 | goto out; | 159 | |
163 | } | 160 | priv->rtc = devm_rtc_device_register(&pdev->dev, "ds1216", |
164 | priv->baseaddr = res->start; | 161 | &ds1216_rtc_ops, THIS_MODULE); |
165 | priv->ioaddr = ioremap(priv->baseaddr, priv->size); | 162 | if (IS_ERR(priv->rtc)) |
166 | if (!priv->ioaddr) { | 163 | return PTR_ERR(priv->rtc); |
167 | ret = -ENOMEM; | ||
168 | goto out; | ||
169 | } | ||
170 | priv->rtc = rtc_device_register("ds1216", &pdev->dev, | ||
171 | &ds1216_rtc_ops, THIS_MODULE); | ||
172 | if (IS_ERR(priv->rtc)) { | ||
173 | ret = PTR_ERR(priv->rtc); | ||
174 | goto out; | ||
175 | } | ||
176 | 164 | ||
177 | /* dummy read to get clock into a known state */ | 165 | /* dummy read to get clock into a known state */ |
178 | ds1216_read(priv->ioaddr, dummy); | 166 | ds1216_read(priv->ioaddr, dummy); |
179 | return 0; | 167 | return 0; |
180 | |||
181 | out: | ||
182 | if (priv->ioaddr) | ||
183 | iounmap(priv->ioaddr); | ||
184 | if (priv->baseaddr) | ||
185 | release_mem_region(priv->baseaddr, priv->size); | ||
186 | kfree(priv); | ||
187 | return ret; | ||
188 | } | 168 | } |
189 | 169 | ||
190 | static int __exit ds1216_rtc_remove(struct platform_device *pdev) | 170 | static int __exit ds1216_rtc_remove(struct platform_device *pdev) |
191 | { | 171 | { |
192 | struct ds1216_priv *priv = platform_get_drvdata(pdev); | ||
193 | |||
194 | rtc_device_unregister(priv->rtc); | ||
195 | iounmap(priv->ioaddr); | ||
196 | release_mem_region(priv->baseaddr, priv->size); | ||
197 | kfree(priv); | ||
198 | return 0; | 172 | return 0; |
199 | } | 173 | } |
200 | 174 | ||