diff options
Diffstat (limited to 'drivers/rtc')
-rw-r--r-- | drivers/rtc/rtc-ep93xx.c | 71 |
1 files changed, 28 insertions, 43 deletions
diff --git a/drivers/rtc/rtc-ep93xx.c b/drivers/rtc/rtc-ep93xx.c index 9da02d108b73..91bde976bc0f 100644 --- a/drivers/rtc/rtc-ep93xx.c +++ b/drivers/rtc/rtc-ep93xx.c | |||
@@ -115,6 +115,15 @@ static ssize_t ep93xx_rtc_show_comp_delete(struct device *dev, | |||
115 | } | 115 | } |
116 | static DEVICE_ATTR(comp_delete, S_IRUGO, ep93xx_rtc_show_comp_delete, NULL); | 116 | static DEVICE_ATTR(comp_delete, S_IRUGO, ep93xx_rtc_show_comp_delete, NULL); |
117 | 117 | ||
118 | static struct attribute *ep93xx_rtc_attrs[] = { | ||
119 | &dev_attr_comp_preload.attr, | ||
120 | &dev_attr_comp_delete.attr, | ||
121 | NULL | ||
122 | }; | ||
123 | |||
124 | static const struct attribute_group ep93xx_rtc_sysfs_files = { | ||
125 | .attrs = ep93xx_rtc_attrs, | ||
126 | }; | ||
118 | 127 | ||
119 | static int __init ep93xx_rtc_probe(struct platform_device *pdev) | 128 | static int __init ep93xx_rtc_probe(struct platform_device *pdev) |
120 | { | 129 | { |
@@ -123,27 +132,22 @@ static int __init ep93xx_rtc_probe(struct platform_device *pdev) | |||
123 | struct rtc_device *rtc; | 132 | struct rtc_device *rtc; |
124 | int err; | 133 | int err; |
125 | 134 | ||
126 | ep93xx_rtc = kzalloc(sizeof(struct ep93xx_rtc), GFP_KERNEL); | 135 | ep93xx_rtc = devm_kzalloc(&pdev->dev, sizeof(*ep93xx_rtc), GFP_KERNEL); |
127 | if (ep93xx_rtc == NULL) | 136 | if (!ep93xx_rtc) |
128 | return -ENOMEM; | 137 | return -ENOMEM; |
129 | 138 | ||
130 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 139 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
131 | if (res == NULL) { | 140 | if (!res) |
132 | err = -ENXIO; | 141 | return -ENXIO; |
133 | goto fail_free; | ||
134 | } | ||
135 | 142 | ||
136 | res = request_mem_region(res->start, resource_size(res), pdev->name); | 143 | if (!devm_request_mem_region(&pdev->dev, res->start, |
137 | if (res == NULL) { | 144 | resource_size(res), pdev->name)) |
138 | err = -EBUSY; | 145 | return -EBUSY; |
139 | goto fail_free; | ||
140 | } | ||
141 | 146 | ||
142 | ep93xx_rtc->mmio_base = ioremap(res->start, resource_size(res)); | 147 | ep93xx_rtc->mmio_base = devm_ioremap(&pdev->dev, res->start, |
143 | if (ep93xx_rtc->mmio_base == NULL) { | 148 | resource_size(res)); |
144 | err = -ENXIO; | 149 | if (!ep93xx_rtc->mmio_base) |
145 | goto fail; | 150 | return -ENXIO; |
146 | } | ||
147 | 151 | ||
148 | pdev->dev.platform_data = ep93xx_rtc; | 152 | pdev->dev.platform_data = ep93xx_rtc; |
149 | 153 | ||
@@ -151,53 +155,34 @@ static int __init ep93xx_rtc_probe(struct platform_device *pdev) | |||
151 | &pdev->dev, &ep93xx_rtc_ops, THIS_MODULE); | 155 | &pdev->dev, &ep93xx_rtc_ops, THIS_MODULE); |
152 | if (IS_ERR(rtc)) { | 156 | if (IS_ERR(rtc)) { |
153 | err = PTR_ERR(rtc); | 157 | err = PTR_ERR(rtc); |
154 | goto fail; | 158 | goto exit; |
155 | } | 159 | } |
156 | 160 | ||
157 | platform_set_drvdata(pdev, rtc); | 161 | platform_set_drvdata(pdev, rtc); |
158 | 162 | ||
159 | err = device_create_file(&pdev->dev, &dev_attr_comp_preload); | 163 | err = sysfs_create_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files); |
160 | if (err) | 164 | if (err) |
161 | goto fail; | 165 | goto fail; |
162 | err = device_create_file(&pdev->dev, &dev_attr_comp_delete); | ||
163 | if (err) { | ||
164 | device_remove_file(&pdev->dev, &dev_attr_comp_preload); | ||
165 | goto fail; | ||
166 | } | ||
167 | 166 | ||
168 | return 0; | 167 | return 0; |
169 | 168 | ||
170 | fail: | 169 | fail: |
171 | if (ep93xx_rtc->mmio_base) { | 170 | platform_set_drvdata(pdev, NULL); |
172 | iounmap(ep93xx_rtc->mmio_base); | 171 | rtc_device_unregister(rtc); |
173 | pdev->dev.platform_data = NULL; | 172 | exit: |
174 | } | 173 | pdev->dev.platform_data = NULL; |
175 | release_mem_region(res->start, resource_size(res)); | ||
176 | fail_free: | ||
177 | kfree(ep93xx_rtc); | ||
178 | return err; | 174 | return err; |
179 | } | 175 | } |
180 | 176 | ||
181 | static int __exit ep93xx_rtc_remove(struct platform_device *pdev) | 177 | static int __exit ep93xx_rtc_remove(struct platform_device *pdev) |
182 | { | 178 | { |
183 | struct rtc_device *rtc = platform_get_drvdata(pdev); | 179 | struct rtc_device *rtc = platform_get_drvdata(pdev); |
184 | struct ep93xx_rtc *ep93xx_rtc = pdev->dev.platform_data; | ||
185 | struct resource *res; | ||
186 | |||
187 | /* cleanup sysfs */ | ||
188 | device_remove_file(&pdev->dev, &dev_attr_comp_delete); | ||
189 | device_remove_file(&pdev->dev, &dev_attr_comp_preload); | ||
190 | 180 | ||
181 | sysfs_remove_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files); | ||
182 | platform_set_drvdata(pdev, NULL); | ||
191 | rtc_device_unregister(rtc); | 183 | rtc_device_unregister(rtc); |
192 | |||
193 | iounmap(ep93xx_rtc->mmio_base); | ||
194 | pdev->dev.platform_data = NULL; | 184 | pdev->dev.platform_data = NULL; |
195 | 185 | ||
196 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
197 | release_mem_region(res->start, resource_size(res)); | ||
198 | |||
199 | platform_set_drvdata(pdev, NULL); | ||
200 | |||
201 | return 0; | 186 | return 0; |
202 | } | 187 | } |
203 | 188 | ||