aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc
diff options
context:
space:
mode:
authorTorsten Ertbjerg Rasmussen <ertbjerg@gmail.com>2009-06-17 19:26:07 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-06-18 16:03:43 -0400
commit3a72970054e72e6d3b5cdb7364a079f8ecae62af (patch)
tree6b71b6424330a181e184e41cb46482b87ab365a2 /drivers/rtc
parent275704970c76c2453b656967586de9c35d247eae (diff)
rtc: rtc-ds1742 nvram attribute fix
The RTC driver for ds1742 / ds1743 uses a static nvram attribute. This patch replaces this static attribute with one nvram attribute for each ds174x registered. The nvram size is not the same for all types of ds174x. The nvram size is accessible as the file size of the nvram attribute in sysfs. With only a single nvram attribute, this file size will be incorrect if more than one type of ds174x is present on a system. See the comment in the removed code below. This patch have been tested with linux-2.6.28 and linux-2.6.29-rc5/6 on a custom board with one ds1743. Signed-off-by: Torsten Ertbjerg Rasmussen <ertbjerg@gmail.com> Signed-off-by: Alessandro Zummo <a.zummo@towertech.it> Cc: Atsushi Nemoto <anemo@mba.ocn.ne.jp> Cc: David Brownell <david-b@pacbell.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/rtc-ds1742.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/drivers/rtc/rtc-ds1742.c b/drivers/rtc/rtc-ds1742.c
index 8bc8501bffc8..09249459e9a4 100644
--- a/drivers/rtc/rtc-ds1742.c
+++ b/drivers/rtc/rtc-ds1742.c
@@ -57,6 +57,7 @@ struct rtc_plat_data {
57 size_t size; 57 size_t size;
58 resource_size_t baseaddr; 58 resource_size_t baseaddr;
59 unsigned long last_jiffies; 59 unsigned long last_jiffies;
60 struct bin_attribute nvram_attr;
60}; 61};
61 62
62static int ds1742_rtc_set_time(struct device *dev, struct rtc_time *tm) 63static int ds1742_rtc_set_time(struct device *dev, struct rtc_time *tm)
@@ -157,18 +158,6 @@ static ssize_t ds1742_nvram_write(struct kobject *kobj,
157 return count; 158 return count;
158} 159}
159 160
160static struct bin_attribute ds1742_nvram_attr = {
161 .attr = {
162 .name = "nvram",
163 .mode = S_IRUGO | S_IWUSR,
164 },
165 .read = ds1742_nvram_read,
166 .write = ds1742_nvram_write,
167 /* REVISIT: size in sysfs won't match actual size... if it's
168 * not a constant, each RTC should have its own attribute.
169 */
170};
171
172static int __devinit ds1742_rtc_probe(struct platform_device *pdev) 161static int __devinit ds1742_rtc_probe(struct platform_device *pdev)
173{ 162{
174 struct rtc_device *rtc; 163 struct rtc_device *rtc;
@@ -199,6 +188,12 @@ static int __devinit ds1742_rtc_probe(struct platform_device *pdev)
199 pdata->size_nvram = pdata->size - RTC_SIZE; 188 pdata->size_nvram = pdata->size - RTC_SIZE;
200 pdata->ioaddr_rtc = ioaddr + pdata->size_nvram; 189 pdata->ioaddr_rtc = ioaddr + pdata->size_nvram;
201 190
191 pdata->nvram_attr.attr.name = "nvram";
192 pdata->nvram_attr.attr.mode = S_IRUGO | S_IWUSR;
193 pdata->nvram_attr.read = ds1742_nvram_read;
194 pdata->nvram_attr.write = ds1742_nvram_write;
195 pdata->nvram_attr.size = pdata->size_nvram;
196
202 /* turn RTC on if it was not on */ 197 /* turn RTC on if it was not on */
203 ioaddr = pdata->ioaddr_rtc; 198 ioaddr = pdata->ioaddr_rtc;
204 sec = readb(ioaddr + RTC_SECONDS); 199 sec = readb(ioaddr + RTC_SECONDS);
@@ -221,11 +216,13 @@ static int __devinit ds1742_rtc_probe(struct platform_device *pdev)
221 pdata->rtc = rtc; 216 pdata->rtc = rtc;
222 pdata->last_jiffies = jiffies; 217 pdata->last_jiffies = jiffies;
223 platform_set_drvdata(pdev, pdata); 218 platform_set_drvdata(pdev, pdata);
224 ds1742_nvram_attr.size = max(ds1742_nvram_attr.size, 219
225 pdata->size_nvram); 220 ret = sysfs_create_bin_file(&pdev->dev.kobj, &pdata->nvram_attr);
226 ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1742_nvram_attr); 221 if (ret) {
227 if (ret) 222 dev_err(&pdev->dev, "creating nvram file in sysfs failed\n");
228 goto out; 223 goto out;
224 }
225
229 return 0; 226 return 0;
230 out: 227 out:
231 if (pdata->rtc) 228 if (pdata->rtc)
@@ -242,7 +239,7 @@ static int __devexit ds1742_rtc_remove(struct platform_device *pdev)
242{ 239{
243 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 240 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
244 241
245 sysfs_remove_bin_file(&pdev->dev.kobj, &ds1742_nvram_attr); 242 sysfs_remove_bin_file(&pdev->dev.kobj, &pdata->nvram_attr);
246 rtc_device_unregister(pdata->rtc); 243 rtc_device_unregister(pdata->rtc);
247 iounmap(pdata->ioaddr_nvram); 244 iounmap(pdata->ioaddr_nvram);
248 release_mem_region(pdata->baseaddr, pdata->size); 245 release_mem_region(pdata->baseaddr, pdata->size);