diff options
Diffstat (limited to 'drivers')
127 files changed, 5517 insertions, 2173 deletions
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index b1c723f9f58d..70f7f60929ca 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c | |||
@@ -431,7 +431,7 @@ static ssize_t acpi_battery_alarm_store(struct device *dev, | |||
431 | } | 431 | } |
432 | 432 | ||
433 | static struct device_attribute alarm_attr = { | 433 | static struct device_attribute alarm_attr = { |
434 | .attr = {.name = "alarm", .mode = 0644, .owner = THIS_MODULE}, | 434 | .attr = {.name = "alarm", .mode = 0644}, |
435 | .show = acpi_battery_alarm_show, | 435 | .show = acpi_battery_alarm_show, |
436 | .store = acpi_battery_alarm_store, | 436 | .store = acpi_battery_alarm_store, |
437 | }; | 437 | }; |
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c index 10a36512647c..7b011e7e29fe 100644 --- a/drivers/acpi/sbs.c +++ b/drivers/acpi/sbs.c | |||
@@ -463,7 +463,7 @@ static ssize_t acpi_battery_alarm_store(struct device *dev, | |||
463 | } | 463 | } |
464 | 464 | ||
465 | static struct device_attribute alarm_attr = { | 465 | static struct device_attribute alarm_attr = { |
466 | .attr = {.name = "alarm", .mode = 0644, .owner = THIS_MODULE}, | 466 | .attr = {.name = "alarm", .mode = 0644}, |
467 | .show = acpi_battery_alarm_show, | 467 | .show = acpi_battery_alarm_show, |
468 | .store = acpi_battery_alarm_store, | 468 | .store = acpi_battery_alarm_store, |
469 | }; | 469 | }; |
diff --git a/drivers/acpi/sleep/proc.c b/drivers/acpi/sleep/proc.c index bf5b04de02d1..631ee2ee2ca0 100644 --- a/drivers/acpi/sleep/proc.c +++ b/drivers/acpi/sleep/proc.c | |||
@@ -120,13 +120,13 @@ static int acpi_system_alarm_seq_show(struct seq_file *seq, void *offset) | |||
120 | spin_unlock_irqrestore(&rtc_lock, flags); | 120 | spin_unlock_irqrestore(&rtc_lock, flags); |
121 | 121 | ||
122 | if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { | 122 | if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { |
123 | BCD_TO_BIN(sec); | 123 | sec = bcd2bin(sec); |
124 | BCD_TO_BIN(min); | 124 | min = bcd2bin(min); |
125 | BCD_TO_BIN(hr); | 125 | hr = bcd2bin(hr); |
126 | BCD_TO_BIN(day); | 126 | day = bcd2bin(day); |
127 | BCD_TO_BIN(mo); | 127 | mo = bcd2bin(mo); |
128 | BCD_TO_BIN(yr); | 128 | yr = bcd2bin(yr); |
129 | BCD_TO_BIN(cent); | 129 | cent = bcd2bin(cent); |
130 | } | 130 | } |
131 | 131 | ||
132 | /* we're trusting the FADT (see above) */ | 132 | /* we're trusting the FADT (see above) */ |
@@ -204,7 +204,7 @@ static u32 cmos_bcd_read(int offset, int rtc_control) | |||
204 | { | 204 | { |
205 | u32 val = CMOS_READ(offset); | 205 | u32 val = CMOS_READ(offset); |
206 | if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) | 206 | if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) |
207 | BCD_TO_BIN(val); | 207 | val = bcd2bin(val); |
208 | return val; | 208 | return val; |
209 | } | 209 | } |
210 | 210 | ||
@@ -212,7 +212,7 @@ static u32 cmos_bcd_read(int offset, int rtc_control) | |||
212 | static void cmos_bcd_write(u32 val, int offset, int rtc_control) | 212 | static void cmos_bcd_write(u32 val, int offset, int rtc_control) |
213 | { | 213 | { |
214 | if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) | 214 | if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) |
215 | BIN_TO_BCD(val); | 215 | val = bin2bcd(val); |
216 | CMOS_WRITE(val, offset); | 216 | CMOS_WRITE(val, offset); |
217 | } | 217 | } |
218 | 218 | ||
diff --git a/drivers/acpi/system.c b/drivers/acpi/system.c index 91dec448b3ed..24e80fd927e2 100644 --- a/drivers/acpi/system.c +++ b/drivers/acpi/system.c | |||
@@ -115,7 +115,6 @@ static void acpi_table_attr_init(struct acpi_table_attr *table_attr, | |||
115 | table_attr->attr.read = acpi_table_show; | 115 | table_attr->attr.read = acpi_table_show; |
116 | table_attr->attr.attr.name = table_attr->name; | 116 | table_attr->attr.attr.name = table_attr->name; |
117 | table_attr->attr.attr.mode = 0444; | 117 | table_attr->attr.attr.mode = 0444; |
118 | table_attr->attr.attr.owner = THIS_MODULE; | ||
119 | 118 | ||
120 | return; | 119 | return; |
121 | } | 120 | } |
diff --git a/drivers/base/memory.c b/drivers/base/memory.c index af0d175c025d..5260e9e0df48 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c | |||
@@ -21,6 +21,8 @@ | |||
21 | #include <linux/memory_hotplug.h> | 21 | #include <linux/memory_hotplug.h> |
22 | #include <linux/mm.h> | 22 | #include <linux/mm.h> |
23 | #include <linux/mutex.h> | 23 | #include <linux/mutex.h> |
24 | #include <linux/stat.h> | ||
25 | |||
24 | #include <asm/atomic.h> | 26 | #include <asm/atomic.h> |
25 | #include <asm/uaccess.h> | 27 | #include <asm/uaccess.h> |
26 | 28 | ||
@@ -325,7 +327,7 @@ memory_probe_store(struct class *class, const char *buf, size_t count) | |||
325 | 327 | ||
326 | return count; | 328 | return count; |
327 | } | 329 | } |
328 | static CLASS_ATTR(probe, 0700, NULL, memory_probe_store); | 330 | static CLASS_ATTR(probe, S_IWUSR, NULL, memory_probe_store); |
329 | 331 | ||
330 | static int memory_probe_init(void) | 332 | static int memory_probe_init(void) |
331 | { | 333 | { |
diff --git a/drivers/base/node.c b/drivers/base/node.c index 5116b78c6325..f5207090885a 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <linux/nodemask.h> | 13 | #include <linux/nodemask.h> |
14 | #include <linux/cpu.h> | 14 | #include <linux/cpu.h> |
15 | #include <linux/device.h> | 15 | #include <linux/device.h> |
16 | #include <linux/swap.h> | ||
16 | 17 | ||
17 | static struct sysdev_class node_class = { | 18 | static struct sysdev_class node_class = { |
18 | .name = "node", | 19 | .name = "node", |
@@ -61,34 +62,52 @@ static ssize_t node_read_meminfo(struct sys_device * dev, | |||
61 | si_meminfo_node(&i, nid); | 62 | si_meminfo_node(&i, nid); |
62 | 63 | ||
63 | n = sprintf(buf, "\n" | 64 | n = sprintf(buf, "\n" |
64 | "Node %d MemTotal: %8lu kB\n" | 65 | "Node %d MemTotal: %8lu kB\n" |
65 | "Node %d MemFree: %8lu kB\n" | 66 | "Node %d MemFree: %8lu kB\n" |
66 | "Node %d MemUsed: %8lu kB\n" | 67 | "Node %d MemUsed: %8lu kB\n" |
67 | "Node %d Active: %8lu kB\n" | 68 | "Node %d Active: %8lu kB\n" |
68 | "Node %d Inactive: %8lu kB\n" | 69 | "Node %d Inactive: %8lu kB\n" |
70 | "Node %d Active(anon): %8lu kB\n" | ||
71 | "Node %d Inactive(anon): %8lu kB\n" | ||
72 | "Node %d Active(file): %8lu kB\n" | ||
73 | "Node %d Inactive(file): %8lu kB\n" | ||
74 | #ifdef CONFIG_UNEVICTABLE_LRU | ||
75 | "Node %d Unevictable: %8lu kB\n" | ||
76 | "Node %d Mlocked: %8lu kB\n" | ||
77 | #endif | ||
69 | #ifdef CONFIG_HIGHMEM | 78 | #ifdef CONFIG_HIGHMEM |
70 | "Node %d HighTotal: %8lu kB\n" | 79 | "Node %d HighTotal: %8lu kB\n" |
71 | "Node %d HighFree: %8lu kB\n" | 80 | "Node %d HighFree: %8lu kB\n" |
72 | "Node %d LowTotal: %8lu kB\n" | 81 | "Node %d LowTotal: %8lu kB\n" |
73 | "Node %d LowFree: %8lu kB\n" | 82 | "Node %d LowFree: %8lu kB\n" |
74 | #endif | 83 | #endif |
75 | "Node %d Dirty: %8lu kB\n" | 84 | "Node %d Dirty: %8lu kB\n" |
76 | "Node %d Writeback: %8lu kB\n" | 85 | "Node %d Writeback: %8lu kB\n" |
77 | "Node %d FilePages: %8lu kB\n" | 86 | "Node %d FilePages: %8lu kB\n" |
78 | "Node %d Mapped: %8lu kB\n" | 87 | "Node %d Mapped: %8lu kB\n" |
79 | "Node %d AnonPages: %8lu kB\n" | 88 | "Node %d AnonPages: %8lu kB\n" |
80 | "Node %d PageTables: %8lu kB\n" | 89 | "Node %d PageTables: %8lu kB\n" |
81 | "Node %d NFS_Unstable: %8lu kB\n" | 90 | "Node %d NFS_Unstable: %8lu kB\n" |
82 | "Node %d Bounce: %8lu kB\n" | 91 | "Node %d Bounce: %8lu kB\n" |
83 | "Node %d WritebackTmp: %8lu kB\n" | 92 | "Node %d WritebackTmp: %8lu kB\n" |
84 | "Node %d Slab: %8lu kB\n" | 93 | "Node %d Slab: %8lu kB\n" |
85 | "Node %d SReclaimable: %8lu kB\n" | 94 | "Node %d SReclaimable: %8lu kB\n" |
86 | "Node %d SUnreclaim: %8lu kB\n", | 95 | "Node %d SUnreclaim: %8lu kB\n", |
87 | nid, K(i.totalram), | 96 | nid, K(i.totalram), |
88 | nid, K(i.freeram), | 97 | nid, K(i.freeram), |
89 | nid, K(i.totalram - i.freeram), | 98 | nid, K(i.totalram - i.freeram), |
90 | nid, K(node_page_state(nid, NR_ACTIVE)), | 99 | nid, K(node_page_state(nid, NR_ACTIVE_ANON) + |
91 | nid, K(node_page_state(nid, NR_INACTIVE)), | 100 | node_page_state(nid, NR_ACTIVE_FILE)), |
101 | nid, K(node_page_state(nid, NR_INACTIVE_ANON) + | ||
102 | node_page_state(nid, NR_INACTIVE_FILE)), | ||
103 | nid, K(node_page_state(nid, NR_ACTIVE_ANON)), | ||
104 | nid, K(node_page_state(nid, NR_INACTIVE_ANON)), | ||
105 | nid, K(node_page_state(nid, NR_ACTIVE_FILE)), | ||
106 | nid, K(node_page_state(nid, NR_INACTIVE_FILE)), | ||
107 | #ifdef CONFIG_UNEVICTABLE_LRU | ||
108 | nid, K(node_page_state(nid, NR_UNEVICTABLE)), | ||
109 | nid, K(node_page_state(nid, NR_MLOCK)), | ||
110 | #endif | ||
92 | #ifdef CONFIG_HIGHMEM | 111 | #ifdef CONFIG_HIGHMEM |
93 | nid, K(i.totalhigh), | 112 | nid, K(i.totalhigh), |
94 | nid, K(i.freehigh), | 113 | nid, K(i.freehigh), |
@@ -173,6 +192,8 @@ int register_node(struct node *node, int num, struct node *parent) | |||
173 | sysdev_create_file(&node->sysdev, &attr_meminfo); | 192 | sysdev_create_file(&node->sysdev, &attr_meminfo); |
174 | sysdev_create_file(&node->sysdev, &attr_numastat); | 193 | sysdev_create_file(&node->sysdev, &attr_numastat); |
175 | sysdev_create_file(&node->sysdev, &attr_distance); | 194 | sysdev_create_file(&node->sysdev, &attr_distance); |
195 | |||
196 | scan_unevictable_register_node(node); | ||
176 | } | 197 | } |
177 | return error; | 198 | return error; |
178 | } | 199 | } |
@@ -192,6 +213,8 @@ void unregister_node(struct node *node) | |||
192 | sysdev_remove_file(&node->sysdev, &attr_numastat); | 213 | sysdev_remove_file(&node->sysdev, &attr_numastat); |
193 | sysdev_remove_file(&node->sysdev, &attr_distance); | 214 | sysdev_remove_file(&node->sysdev, &attr_distance); |
194 | 215 | ||
216 | scan_unevictable_unregister_node(node); | ||
217 | |||
195 | sysdev_unregister(&node->sysdev); | 218 | sysdev_unregister(&node->sysdev); |
196 | } | 219 | } |
197 | 220 | ||
diff --git a/drivers/block/aoe/aoeblk.c b/drivers/block/aoe/aoeblk.c index b82654e883a7..d876ad861237 100644 --- a/drivers/block/aoe/aoeblk.c +++ b/drivers/block/aoe/aoeblk.c | |||
@@ -90,7 +90,7 @@ static DEVICE_ATTR(state, S_IRUGO, aoedisk_show_state, NULL); | |||
90 | static DEVICE_ATTR(mac, S_IRUGO, aoedisk_show_mac, NULL); | 90 | static DEVICE_ATTR(mac, S_IRUGO, aoedisk_show_mac, NULL); |
91 | static DEVICE_ATTR(netif, S_IRUGO, aoedisk_show_netif, NULL); | 91 | static DEVICE_ATTR(netif, S_IRUGO, aoedisk_show_netif, NULL); |
92 | static struct device_attribute dev_attr_firmware_version = { | 92 | static struct device_attribute dev_attr_firmware_version = { |
93 | .attr = { .name = "firmware-version", .mode = S_IRUGO, .owner = THIS_MODULE }, | 93 | .attr = { .name = "firmware-version", .mode = S_IRUGO }, |
94 | .show = aoedisk_show_fwver, | 94 | .show = aoedisk_show_fwver, |
95 | }; | 95 | }; |
96 | 96 | ||
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 7b3351260d56..9034ca585afd 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c | |||
@@ -391,7 +391,7 @@ static ssize_t pid_show(struct device *dev, | |||
391 | } | 391 | } |
392 | 392 | ||
393 | static struct device_attribute pid_attr = { | 393 | static struct device_attribute pid_attr = { |
394 | .attr = { .name = "pid", .mode = S_IRUGO, .owner = THIS_MODULE }, | 394 | .attr = { .name = "pid", .mode = S_IRUGO}, |
395 | .show = pid_show, | 395 | .show = pid_show, |
396 | }; | 396 | }; |
397 | 397 | ||
diff --git a/drivers/char/ds1286.c b/drivers/char/ds1286.c index 5329d482b582..0a826d7be10e 100644 --- a/drivers/char/ds1286.c +++ b/drivers/char/ds1286.c | |||
@@ -210,8 +210,8 @@ static int ds1286_ioctl(struct inode *inode, struct file *file, | |||
210 | if (sec != 0) | 210 | if (sec != 0) |
211 | return -EINVAL; | 211 | return -EINVAL; |
212 | 212 | ||
213 | min = BIN2BCD(min); | 213 | min = bin2bcd(min); |
214 | min = BIN2BCD(hrs); | 214 | min = bin2bcd(hrs); |
215 | 215 | ||
216 | spin_lock(&ds1286_lock); | 216 | spin_lock(&ds1286_lock); |
217 | rtc_write(hrs, RTC_HOURS_ALARM); | 217 | rtc_write(hrs, RTC_HOURS_ALARM); |
@@ -353,7 +353,7 @@ static int ds1286_proc_output(char *buf) | |||
353 | 353 | ||
354 | ds1286_get_time(&tm); | 354 | ds1286_get_time(&tm); |
355 | hundredth = rtc_read(RTC_HUNDREDTH_SECOND); | 355 | hundredth = rtc_read(RTC_HUNDREDTH_SECOND); |
356 | BCD_TO_BIN(hundredth); | 356 | hundredth = bcd2bin(hundredth); |
357 | 357 | ||
358 | p += sprintf(p, | 358 | p += sprintf(p, |
359 | "rtc_time\t: %02d:%02d:%02d.%02d\n" | 359 | "rtc_time\t: %02d:%02d:%02d.%02d\n" |
@@ -477,12 +477,12 @@ static void ds1286_get_time(struct rtc_time *rtc_tm) | |||
477 | rtc_write(save_control, RTC_CMD); | 477 | rtc_write(save_control, RTC_CMD); |
478 | spin_unlock_irqrestore(&ds1286_lock, flags); | 478 | spin_unlock_irqrestore(&ds1286_lock, flags); |
479 | 479 | ||
480 | BCD_TO_BIN(rtc_tm->tm_sec); | 480 | rtc_tm->tm_sec = bcd2bin(rtc_tm->tm_sec); |
481 | BCD_TO_BIN(rtc_tm->tm_min); | 481 | rtc_tm->tm_min = bcd2bin(rtc_tm->tm_min); |
482 | BCD_TO_BIN(rtc_tm->tm_hour); | 482 | rtc_tm->tm_hour = bcd2bin(rtc_tm->tm_hour); |
483 | BCD_TO_BIN(rtc_tm->tm_mday); | 483 | rtc_tm->tm_mday = bcd2bin(rtc_tm->tm_mday); |
484 | BCD_TO_BIN(rtc_tm->tm_mon); | 484 | rtc_tm->tm_mon = bcd2bin(rtc_tm->tm_mon); |
485 | BCD_TO_BIN(rtc_tm->tm_year); | 485 | rtc_tm->tm_year = bcd2bin(rtc_tm->tm_year); |
486 | 486 | ||
487 | /* | 487 | /* |
488 | * Account for differences between how the RTC uses the values | 488 | * Account for differences between how the RTC uses the values |
@@ -531,12 +531,12 @@ static int ds1286_set_time(struct rtc_time *rtc_tm) | |||
531 | if (yrs >= 100) | 531 | if (yrs >= 100) |
532 | yrs -= 100; | 532 | yrs -= 100; |
533 | 533 | ||
534 | BIN_TO_BCD(sec); | 534 | sec = bin2bcd(sec); |
535 | BIN_TO_BCD(min); | 535 | min = bin2bcd(min); |
536 | BIN_TO_BCD(hrs); | 536 | hrs = bin2bcd(hrs); |
537 | BIN_TO_BCD(day); | 537 | day = bin2bcd(day); |
538 | BIN_TO_BCD(mon); | 538 | mon = bin2bcd(mon); |
539 | BIN_TO_BCD(yrs); | 539 | yrs = bin2bcd(yrs); |
540 | 540 | ||
541 | spin_lock_irqsave(&ds1286_lock, flags); | 541 | spin_lock_irqsave(&ds1286_lock, flags); |
542 | save_control = rtc_read(RTC_CMD); | 542 | save_control = rtc_read(RTC_CMD); |
@@ -572,8 +572,8 @@ static void ds1286_get_alm_time(struct rtc_time *alm_tm) | |||
572 | cmd = rtc_read(RTC_CMD); | 572 | cmd = rtc_read(RTC_CMD); |
573 | spin_unlock_irqrestore(&ds1286_lock, flags); | 573 | spin_unlock_irqrestore(&ds1286_lock, flags); |
574 | 574 | ||
575 | BCD_TO_BIN(alm_tm->tm_min); | 575 | alm_tm->tm_min = bcd2bin(alm_tm->tm_min); |
576 | BCD_TO_BIN(alm_tm->tm_hour); | 576 | alm_tm->tm_hour = bcd2bin(alm_tm->tm_hour); |
577 | alm_tm->tm_sec = 0; | 577 | alm_tm->tm_sec = 0; |
578 | } | 578 | } |
579 | 579 | ||
diff --git a/drivers/char/ds1302.c b/drivers/char/ds1302.c index c5e67a623951..170693c93c73 100644 --- a/drivers/char/ds1302.c +++ b/drivers/char/ds1302.c | |||
@@ -131,12 +131,12 @@ get_rtc_time(struct rtc_time *rtc_tm) | |||
131 | 131 | ||
132 | local_irq_restore(flags); | 132 | local_irq_restore(flags); |
133 | 133 | ||
134 | BCD_TO_BIN(rtc_tm->tm_sec); | 134 | rtc_tm->tm_sec = bcd2bin(rtc_tm->tm_sec); |
135 | BCD_TO_BIN(rtc_tm->tm_min); | 135 | rtc_tm->tm_min = bcd2bin(rtc_tm->tm_min); |
136 | BCD_TO_BIN(rtc_tm->tm_hour); | 136 | rtc_tm->tm_hour = bcd2bin(rtc_tm->tm_hour); |
137 | BCD_TO_BIN(rtc_tm->tm_mday); | 137 | rtc_tm->tm_mday = bcd2bin(rtc_tm->tm_mday); |
138 | BCD_TO_BIN(rtc_tm->tm_mon); | 138 | rtc_tm->tm_mon = bcd2bin(rtc_tm->tm_mon); |
139 | BCD_TO_BIN(rtc_tm->tm_year); | 139 | rtc_tm->tm_year = bcd2bin(rtc_tm->tm_year); |
140 | 140 | ||
141 | /* | 141 | /* |
142 | * Account for differences between how the RTC uses the values | 142 | * Account for differences between how the RTC uses the values |
@@ -211,12 +211,12 @@ static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
211 | else | 211 | else |
212 | yrs -= 1900; /* RTC (70, 71, ... 99) */ | 212 | yrs -= 1900; /* RTC (70, 71, ... 99) */ |
213 | 213 | ||
214 | BIN_TO_BCD(sec); | 214 | sec = bin2bcd(sec); |
215 | BIN_TO_BCD(min); | 215 | min = bin2bcd(min); |
216 | BIN_TO_BCD(hrs); | 216 | hrs = bin2bcd(hrs); |
217 | BIN_TO_BCD(day); | 217 | day = bin2bcd(day); |
218 | BIN_TO_BCD(mon); | 218 | mon = bin2bcd(mon); |
219 | BIN_TO_BCD(yrs); | 219 | yrs = bin2bcd(yrs); |
220 | 220 | ||
221 | lock_kernel(); | 221 | lock_kernel(); |
222 | local_irq_save(flags); | 222 | local_irq_save(flags); |
diff --git a/drivers/char/ip27-rtc.c b/drivers/char/ip27-rtc.c index ec9d0443d92c..2abd881b4cbc 100644 --- a/drivers/char/ip27-rtc.c +++ b/drivers/char/ip27-rtc.c | |||
@@ -130,12 +130,12 @@ static long rtc_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) | |||
130 | if (yrs >= 100) | 130 | if (yrs >= 100) |
131 | yrs -= 100; | 131 | yrs -= 100; |
132 | 132 | ||
133 | sec = BIN2BCD(sec); | 133 | sec = bin2bcd(sec); |
134 | min = BIN2BCD(min); | 134 | min = bin2bcd(min); |
135 | hrs = BIN2BCD(hrs); | 135 | hrs = bin2bcd(hrs); |
136 | day = BIN2BCD(day); | 136 | day = bin2bcd(day); |
137 | mon = BIN2BCD(mon); | 137 | mon = bin2bcd(mon); |
138 | yrs = BIN2BCD(yrs); | 138 | yrs = bin2bcd(yrs); |
139 | 139 | ||
140 | spin_lock_irq(&rtc_lock); | 140 | spin_lock_irq(&rtc_lock); |
141 | rtc->control |= M48T35_RTC_SET; | 141 | rtc->control |= M48T35_RTC_SET; |
@@ -311,12 +311,12 @@ static void get_rtc_time(struct rtc_time *rtc_tm) | |||
311 | rtc->control &= ~M48T35_RTC_READ; | 311 | rtc->control &= ~M48T35_RTC_READ; |
312 | spin_unlock_irq(&rtc_lock); | 312 | spin_unlock_irq(&rtc_lock); |
313 | 313 | ||
314 | rtc_tm->tm_sec = BCD2BIN(rtc_tm->tm_sec); | 314 | rtc_tm->tm_sec = bcd2bin(rtc_tm->tm_sec); |
315 | rtc_tm->tm_min = BCD2BIN(rtc_tm->tm_min); | 315 | rtc_tm->tm_min = bcd2bin(rtc_tm->tm_min); |
316 | rtc_tm->tm_hour = BCD2BIN(rtc_tm->tm_hour); | 316 | rtc_tm->tm_hour = bcd2bin(rtc_tm->tm_hour); |
317 | rtc_tm->tm_mday = BCD2BIN(rtc_tm->tm_mday); | 317 | rtc_tm->tm_mday = bcd2bin(rtc_tm->tm_mday); |
318 | rtc_tm->tm_mon = BCD2BIN(rtc_tm->tm_mon); | 318 | rtc_tm->tm_mon = bcd2bin(rtc_tm->tm_mon); |
319 | rtc_tm->tm_year = BCD2BIN(rtc_tm->tm_year); | 319 | rtc_tm->tm_year = bcd2bin(rtc_tm->tm_year); |
320 | 320 | ||
321 | /* | 321 | /* |
322 | * Account for differences between how the RTC uses the values | 322 | * Account for differences between how the RTC uses the values |
diff --git a/drivers/char/pc8736x_gpio.c b/drivers/char/pc8736x_gpio.c index b930de50407a..3f7da8cf3a80 100644 --- a/drivers/char/pc8736x_gpio.c +++ b/drivers/char/pc8736x_gpio.c | |||
@@ -41,7 +41,8 @@ static u8 pc8736x_gpio_shadow[4]; | |||
41 | #define SIO_BASE2 0x4E /* alt command-reg to check */ | 41 | #define SIO_BASE2 0x4E /* alt command-reg to check */ |
42 | 42 | ||
43 | #define SIO_SID 0x20 /* SuperI/O ID Register */ | 43 | #define SIO_SID 0x20 /* SuperI/O ID Register */ |
44 | #define SIO_SID_VALUE 0xe9 /* Expected value in SuperI/O ID Register */ | 44 | #define SIO_SID_PC87365 0xe5 /* Expected value in ID Register for PC87365 */ |
45 | #define SIO_SID_PC87366 0xe9 /* Expected value in ID Register for PC87366 */ | ||
45 | 46 | ||
46 | #define SIO_CF1 0x21 /* chip config, bit0 is chip enable */ | 47 | #define SIO_CF1 0x21 /* chip config, bit0 is chip enable */ |
47 | 48 | ||
@@ -91,13 +92,17 @@ static inline int superio_inb(int addr) | |||
91 | 92 | ||
92 | static int pc8736x_superio_present(void) | 93 | static int pc8736x_superio_present(void) |
93 | { | 94 | { |
95 | int id; | ||
96 | |||
94 | /* try the 2 possible values, read a hardware reg to verify */ | 97 | /* try the 2 possible values, read a hardware reg to verify */ |
95 | superio_cmd = SIO_BASE1; | 98 | superio_cmd = SIO_BASE1; |
96 | if (superio_inb(SIO_SID) == SIO_SID_VALUE) | 99 | id = superio_inb(SIO_SID); |
100 | if (id == SIO_SID_PC87365 || id == SIO_SID_PC87366) | ||
97 | return superio_cmd; | 101 | return superio_cmd; |
98 | 102 | ||
99 | superio_cmd = SIO_BASE2; | 103 | superio_cmd = SIO_BASE2; |
100 | if (superio_inb(SIO_SID) == SIO_SID_VALUE) | 104 | id = superio_inb(SIO_SID); |
105 | if (id == SIO_SID_PC87365 || id == SIO_SID_PC87366) | ||
101 | return superio_cmd; | 106 | return superio_cmd; |
102 | 107 | ||
103 | return 0; | 108 | return 0; |
diff --git a/drivers/char/rtc.c b/drivers/char/rtc.c index 17683de95717..32dc89720d58 100644 --- a/drivers/char/rtc.c +++ b/drivers/char/rtc.c | |||
@@ -518,17 +518,17 @@ static int rtc_do_ioctl(unsigned int cmd, unsigned long arg, int kernel) | |||
518 | if (!(CMOS_READ(RTC_CONTROL) & RTC_DM_BINARY) || | 518 | if (!(CMOS_READ(RTC_CONTROL) & RTC_DM_BINARY) || |
519 | RTC_ALWAYS_BCD) { | 519 | RTC_ALWAYS_BCD) { |
520 | if (sec < 60) | 520 | if (sec < 60) |
521 | BIN_TO_BCD(sec); | 521 | sec = bin2bcd(sec); |
522 | else | 522 | else |
523 | sec = 0xff; | 523 | sec = 0xff; |
524 | 524 | ||
525 | if (min < 60) | 525 | if (min < 60) |
526 | BIN_TO_BCD(min); | 526 | min = bin2bcd(min); |
527 | else | 527 | else |
528 | min = 0xff; | 528 | min = 0xff; |
529 | 529 | ||
530 | if (hrs < 24) | 530 | if (hrs < 24) |
531 | BIN_TO_BCD(hrs); | 531 | hrs = bin2bcd(hrs); |
532 | else | 532 | else |
533 | hrs = 0xff; | 533 | hrs = 0xff; |
534 | } | 534 | } |
@@ -614,12 +614,12 @@ static int rtc_do_ioctl(unsigned int cmd, unsigned long arg, int kernel) | |||
614 | 614 | ||
615 | if (!(CMOS_READ(RTC_CONTROL) & RTC_DM_BINARY) | 615 | if (!(CMOS_READ(RTC_CONTROL) & RTC_DM_BINARY) |
616 | || RTC_ALWAYS_BCD) { | 616 | || RTC_ALWAYS_BCD) { |
617 | BIN_TO_BCD(sec); | 617 | sec = bin2bcd(sec); |
618 | BIN_TO_BCD(min); | 618 | min = bin2bcd(min); |
619 | BIN_TO_BCD(hrs); | 619 | hrs = bin2bcd(hrs); |
620 | BIN_TO_BCD(day); | 620 | day = bin2bcd(day); |
621 | BIN_TO_BCD(mon); | 621 | mon = bin2bcd(mon); |
622 | BIN_TO_BCD(yrs); | 622 | yrs = bin2bcd(yrs); |
623 | } | 623 | } |
624 | 624 | ||
625 | save_control = CMOS_READ(RTC_CONTROL); | 625 | save_control = CMOS_READ(RTC_CONTROL); |
@@ -1099,7 +1099,7 @@ no_irq: | |||
1099 | spin_unlock_irq(&rtc_lock); | 1099 | spin_unlock_irq(&rtc_lock); |
1100 | 1100 | ||
1101 | if (!(ctrl & RTC_DM_BINARY) || RTC_ALWAYS_BCD) | 1101 | if (!(ctrl & RTC_DM_BINARY) || RTC_ALWAYS_BCD) |
1102 | BCD_TO_BIN(year); /* This should never happen... */ | 1102 | year = bcd2bin(year); /* This should never happen... */ |
1103 | 1103 | ||
1104 | if (year < 20) { | 1104 | if (year < 20) { |
1105 | epoch = 2000; | 1105 | epoch = 2000; |
@@ -1352,13 +1352,13 @@ static void rtc_get_rtc_time(struct rtc_time *rtc_tm) | |||
1352 | spin_unlock_irqrestore(&rtc_lock, flags); | 1352 | spin_unlock_irqrestore(&rtc_lock, flags); |
1353 | 1353 | ||
1354 | if (!(ctrl & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { | 1354 | if (!(ctrl & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { |
1355 | BCD_TO_BIN(rtc_tm->tm_sec); | 1355 | rtc_tm->tm_sec = bcd2bin(rtc_tm->tm_sec); |
1356 | BCD_TO_BIN(rtc_tm->tm_min); | 1356 | rtc_tm->tm_min = bcd2bin(rtc_tm->tm_min); |
1357 | BCD_TO_BIN(rtc_tm->tm_hour); | 1357 | rtc_tm->tm_hour = bcd2bin(rtc_tm->tm_hour); |
1358 | BCD_TO_BIN(rtc_tm->tm_mday); | 1358 | rtc_tm->tm_mday = bcd2bin(rtc_tm->tm_mday); |
1359 | BCD_TO_BIN(rtc_tm->tm_mon); | 1359 | rtc_tm->tm_mon = bcd2bin(rtc_tm->tm_mon); |
1360 | BCD_TO_BIN(rtc_tm->tm_year); | 1360 | rtc_tm->tm_year = bcd2bin(rtc_tm->tm_year); |
1361 | BCD_TO_BIN(rtc_tm->tm_wday); | 1361 | rtc_tm->tm_wday = bcd2bin(rtc_tm->tm_wday); |
1362 | } | 1362 | } |
1363 | 1363 | ||
1364 | #ifdef CONFIG_MACH_DECSTATION | 1364 | #ifdef CONFIG_MACH_DECSTATION |
@@ -1392,9 +1392,9 @@ static void get_rtc_alm_time(struct rtc_time *alm_tm) | |||
1392 | spin_unlock_irq(&rtc_lock); | 1392 | spin_unlock_irq(&rtc_lock); |
1393 | 1393 | ||
1394 | if (!(ctrl & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { | 1394 | if (!(ctrl & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { |
1395 | BCD_TO_BIN(alm_tm->tm_sec); | 1395 | alm_tm->tm_sec = bcd2bin(alm_tm->tm_sec); |
1396 | BCD_TO_BIN(alm_tm->tm_min); | 1396 | alm_tm->tm_min = bcd2bin(alm_tm->tm_min); |
1397 | BCD_TO_BIN(alm_tm->tm_hour); | 1397 | alm_tm->tm_hour = bcd2bin(alm_tm->tm_hour); |
1398 | } | 1398 | } |
1399 | } | 1399 | } |
1400 | 1400 | ||
diff --git a/drivers/char/sx.c b/drivers/char/sx.c index 5b8d7a1aa3e6..ba4e86281fbf 100644 --- a/drivers/char/sx.c +++ b/drivers/char/sx.c | |||
@@ -2504,7 +2504,7 @@ static void __devexit sx_remove_card(struct sx_board *board, | |||
2504 | del_timer(&board->timer); | 2504 | del_timer(&board->timer); |
2505 | if (pdev) { | 2505 | if (pdev) { |
2506 | #ifdef CONFIG_PCI | 2506 | #ifdef CONFIG_PCI |
2507 | pci_iounmap(pdev, board->base2); | 2507 | iounmap(board->base2); |
2508 | pci_release_region(pdev, IS_CF_BOARD(board) ? 3 : 2); | 2508 | pci_release_region(pdev, IS_CF_BOARD(board) ? 3 : 2); |
2509 | #endif | 2509 | #endif |
2510 | } else { | 2510 | } else { |
@@ -2677,7 +2677,7 @@ static int __devinit sx_pci_probe(struct pci_dev *pdev, | |||
2677 | } | 2677 | } |
2678 | board->hw_base = pci_resource_start(pdev, reg); | 2678 | board->hw_base = pci_resource_start(pdev, reg); |
2679 | board->base2 = | 2679 | board->base2 = |
2680 | board->base = pci_iomap(pdev, reg, WINDOW_LEN(board)); | 2680 | board->base = ioremap_nocache(board->hw_base, WINDOW_LEN(board)); |
2681 | if (!board->base) { | 2681 | if (!board->base) { |
2682 | dev_err(&pdev->dev, "ioremap failed\n"); | 2682 | dev_err(&pdev->dev, "ioremap failed\n"); |
2683 | goto err_reg; | 2683 | goto err_reg; |
@@ -2703,7 +2703,7 @@ static int __devinit sx_pci_probe(struct pci_dev *pdev, | |||
2703 | 2703 | ||
2704 | return 0; | 2704 | return 0; |
2705 | err_unmap: | 2705 | err_unmap: |
2706 | pci_iounmap(pdev, board->base2); | 2706 | iounmap(board->base2); |
2707 | err_reg: | 2707 | err_reg: |
2708 | pci_release_region(pdev, reg); | 2708 | pci_release_region(pdev, reg); |
2709 | err_flag: | 2709 | err_flag: |
diff --git a/drivers/char/sysrq.c b/drivers/char/sysrq.c index dce4cc0e6953..d0c0d64ed366 100644 --- a/drivers/char/sysrq.c +++ b/drivers/char/sysrq.c | |||
@@ -168,7 +168,7 @@ static void sysrq_handle_show_timers(int key, struct tty_struct *tty) | |||
168 | static struct sysrq_key_op sysrq_show_timers_op = { | 168 | static struct sysrq_key_op sysrq_show_timers_op = { |
169 | .handler = sysrq_handle_show_timers, | 169 | .handler = sysrq_handle_show_timers, |
170 | .help_msg = "show-all-timers(Q)", | 170 | .help_msg = "show-all-timers(Q)", |
171 | .action_msg = "Show Pending Timers", | 171 | .action_msg = "Show pending hrtimers (no others)", |
172 | }; | 172 | }; |
173 | 173 | ||
174 | static void sysrq_handle_mountro(int key, struct tty_struct *tty) | 174 | static void sysrq_handle_mountro(int key, struct tty_struct *tty) |
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c index e70d13defde4..9c47dc48c9fd 100644 --- a/drivers/char/tpm/tpm.c +++ b/drivers/char/tpm/tpm.c | |||
@@ -1157,7 +1157,7 @@ EXPORT_SYMBOL_GPL(tpm_dev_vendor_release); | |||
1157 | * Once all references to platform device are down to 0, | 1157 | * Once all references to platform device are down to 0, |
1158 | * release all allocated structures. | 1158 | * release all allocated structures. |
1159 | */ | 1159 | */ |
1160 | static void tpm_dev_release(struct device *dev) | 1160 | void tpm_dev_release(struct device *dev) |
1161 | { | 1161 | { |
1162 | struct tpm_chip *chip = dev_get_drvdata(dev); | 1162 | struct tpm_chip *chip = dev_get_drvdata(dev); |
1163 | 1163 | ||
diff --git a/drivers/edac/cell_edac.c b/drivers/edac/cell_edac.c index 0e024fe2d8c4..887072f5dc8b 100644 --- a/drivers/edac/cell_edac.c +++ b/drivers/edac/cell_edac.c | |||
@@ -142,7 +142,7 @@ static void __devinit cell_edac_init_csrows(struct mem_ctl_info *mci) | |||
142 | csrow->nr_pages = (r.end - r.start + 1) >> PAGE_SHIFT; | 142 | csrow->nr_pages = (r.end - r.start + 1) >> PAGE_SHIFT; |
143 | csrow->last_page = csrow->first_page + csrow->nr_pages - 1; | 143 | csrow->last_page = csrow->first_page + csrow->nr_pages - 1; |
144 | csrow->mtype = MEM_XDR; | 144 | csrow->mtype = MEM_XDR; |
145 | csrow->edac_mode = EDAC_FLAG_EC | EDAC_FLAG_SECDED; | 145 | csrow->edac_mode = EDAC_SECDED; |
146 | dev_dbg(mci->dev, | 146 | dev_dbg(mci->dev, |
147 | "Initialized on node %d, chanmask=0x%x," | 147 | "Initialized on node %d, chanmask=0x%x," |
148 | " first_page=0x%lx, nr_pages=0x%x\n", | 148 | " first_page=0x%lx, nr_pages=0x%x\n", |
diff --git a/drivers/firmware/iscsi_ibft.c b/drivers/firmware/iscsi_ibft.c index deb154aa47c4..4353414a0b77 100644 --- a/drivers/firmware/iscsi_ibft.c +++ b/drivers/firmware/iscsi_ibft.c | |||
@@ -732,7 +732,6 @@ static int __init ibft_create_attribute(struct ibft_kobject *kobj_data, | |||
732 | 732 | ||
733 | attr->attr.name = name; | 733 | attr->attr.name = name; |
734 | attr->attr.mode = S_IRUSR; | 734 | attr->attr.mode = S_IRUSR; |
735 | attr->attr.owner = THIS_MODULE; | ||
736 | 735 | ||
737 | attr->hdr = hdr; | 736 | attr->hdr = hdr; |
738 | attr->show = show; | 737 | attr->show = show; |
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 9112830107a5..22edc4273ef6 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c | |||
@@ -248,7 +248,7 @@ static ssize_t gpio_value_show(struct device *dev, | |||
248 | if (!test_bit(FLAG_EXPORT, &desc->flags)) | 248 | if (!test_bit(FLAG_EXPORT, &desc->flags)) |
249 | status = -EIO; | 249 | status = -EIO; |
250 | else | 250 | else |
251 | status = sprintf(buf, "%d\n", gpio_get_value_cansleep(gpio)); | 251 | status = sprintf(buf, "%d\n", !!gpio_get_value_cansleep(gpio)); |
252 | 252 | ||
253 | mutex_unlock(&sysfs_lock); | 253 | mutex_unlock(&sysfs_lock); |
254 | return status; | 254 | return status; |
@@ -1105,7 +1105,7 @@ int gpio_get_value_cansleep(unsigned gpio) | |||
1105 | 1105 | ||
1106 | might_sleep_if(extra_checks); | 1106 | might_sleep_if(extra_checks); |
1107 | chip = gpio_to_chip(gpio); | 1107 | chip = gpio_to_chip(gpio); |
1108 | return chip->get(chip, gpio - chip->base); | 1108 | return chip->get ? chip->get(chip, gpio - chip->base) : 0; |
1109 | } | 1109 | } |
1110 | EXPORT_SYMBOL_GPL(gpio_get_value_cansleep); | 1110 | EXPORT_SYMBOL_GPL(gpio_get_value_cansleep); |
1111 | 1111 | ||
diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c index b06b8e090a27..bc011da79e14 100644 --- a/drivers/hwmon/applesmc.c +++ b/drivers/hwmon/applesmc.c | |||
@@ -49,6 +49,9 @@ | |||
49 | 49 | ||
50 | #define APPLESMC_MAX_DATA_LENGTH 32 | 50 | #define APPLESMC_MAX_DATA_LENGTH 32 |
51 | 51 | ||
52 | #define APPLESMC_MIN_WAIT 0x0040 | ||
53 | #define APPLESMC_MAX_WAIT 0x8000 | ||
54 | |||
52 | #define APPLESMC_STATUS_MASK 0x0f | 55 | #define APPLESMC_STATUS_MASK 0x0f |
53 | #define APPLESMC_READ_CMD 0x10 | 56 | #define APPLESMC_READ_CMD 0x10 |
54 | #define APPLESMC_WRITE_CMD 0x11 | 57 | #define APPLESMC_WRITE_CMD 0x11 |
@@ -57,8 +60,8 @@ | |||
57 | 60 | ||
58 | #define KEY_COUNT_KEY "#KEY" /* r-o ui32 */ | 61 | #define KEY_COUNT_KEY "#KEY" /* r-o ui32 */ |
59 | 62 | ||
60 | #define LIGHT_SENSOR_LEFT_KEY "ALV0" /* r-o {alv (6 bytes) */ | 63 | #define LIGHT_SENSOR_LEFT_KEY "ALV0" /* r-o {alv (6-10 bytes) */ |
61 | #define LIGHT_SENSOR_RIGHT_KEY "ALV1" /* r-o {alv (6 bytes) */ | 64 | #define LIGHT_SENSOR_RIGHT_KEY "ALV1" /* r-o {alv (6-10 bytes) */ |
62 | #define BACKLIGHT_KEY "LKSB" /* w-o {lkb (2 bytes) */ | 65 | #define BACKLIGHT_KEY "LKSB" /* w-o {lkb (2 bytes) */ |
63 | 66 | ||
64 | #define CLAMSHELL_KEY "MSLD" /* r-o ui8 (unused) */ | 67 | #define CLAMSHELL_KEY "MSLD" /* r-o ui8 (unused) */ |
@@ -104,6 +107,15 @@ static const char* temperature_sensors_sets[][36] = { | |||
104 | /* Set 6: Macbook3 set */ | 107 | /* Set 6: Macbook3 set */ |
105 | { "TB0T", "TC0D", "TC0P", "TM0P", "TN0P", "TTF0", "TW0P", "Th0H", | 108 | { "TB0T", "TC0D", "TC0P", "TM0P", "TN0P", "TTF0", "TW0P", "Th0H", |
106 | "Th0S", "Th1H", NULL }, | 109 | "Th0S", "Th1H", NULL }, |
110 | /* Set 7: Macbook Air */ | ||
111 | { "TB0T", "TB1S", "TB1T", "TB2S", "TB2T", "TC0D", "TC0P", "TCFP", | ||
112 | "TTF0", "TW0P", "Th0H", "Tp0P", "TpFP", "Ts0P", "Ts0S", NULL }, | ||
113 | /* Set 8: Macbook Pro 4,1 (Penryn) */ | ||
114 | { "TB0T", "TC0D", "TC0P", "TG0D", "TG0H", "TTF0", "TW0P", "Th0H", | ||
115 | "Th1H", "Th2H", "Tm0P", "Ts0P", NULL }, | ||
116 | /* Set 9: Macbook Pro 3,1 (Santa Rosa) */ | ||
117 | { "TALP", "TB0T", "TC0D", "TC0P", "TG0D", "TG0H", "TTF0", "TW0P", | ||
118 | "Th0H", "Th1H", "Th2H", "Tm0P", "Ts0P", NULL }, | ||
107 | }; | 119 | }; |
108 | 120 | ||
109 | /* List of keys used to read/write fan speeds */ | 121 | /* List of keys used to read/write fan speeds */ |
@@ -163,25 +175,25 @@ static unsigned int key_at_index; | |||
163 | static struct workqueue_struct *applesmc_led_wq; | 175 | static struct workqueue_struct *applesmc_led_wq; |
164 | 176 | ||
165 | /* | 177 | /* |
166 | * __wait_status - Wait up to 2ms for the status port to get a certain value | 178 | * __wait_status - Wait up to 32ms for the status port to get a certain value |
167 | * (masked with 0x0f), returning zero if the value is obtained. Callers must | 179 | * (masked with 0x0f), returning zero if the value is obtained. Callers must |
168 | * hold applesmc_lock. | 180 | * hold applesmc_lock. |
169 | */ | 181 | */ |
170 | static int __wait_status(u8 val) | 182 | static int __wait_status(u8 val) |
171 | { | 183 | { |
172 | unsigned int i; | 184 | int us; |
173 | 185 | ||
174 | val = val & APPLESMC_STATUS_MASK; | 186 | val = val & APPLESMC_STATUS_MASK; |
175 | 187 | ||
176 | for (i = 0; i < 200; i++) { | 188 | for (us = APPLESMC_MIN_WAIT; us < APPLESMC_MAX_WAIT; us <<= 1) { |
189 | udelay(us); | ||
177 | if ((inb(APPLESMC_CMD_PORT) & APPLESMC_STATUS_MASK) == val) { | 190 | if ((inb(APPLESMC_CMD_PORT) & APPLESMC_STATUS_MASK) == val) { |
178 | if (debug) | 191 | if (debug) |
179 | printk(KERN_DEBUG | 192 | printk(KERN_DEBUG |
180 | "Waited %d us for status %x\n", | 193 | "Waited %d us for status %x\n", |
181 | i*10, val); | 194 | 2 * us - APPLESMC_MIN_WAIT, val); |
182 | return 0; | 195 | return 0; |
183 | } | 196 | } |
184 | udelay(10); | ||
185 | } | 197 | } |
186 | 198 | ||
187 | printk(KERN_WARNING "applesmc: wait status failed: %x != %x\n", | 199 | printk(KERN_WARNING "applesmc: wait status failed: %x != %x\n", |
@@ -191,6 +203,25 @@ static int __wait_status(u8 val) | |||
191 | } | 203 | } |
192 | 204 | ||
193 | /* | 205 | /* |
206 | * special treatment of command port - on newer macbooks, it seems necessary | ||
207 | * to resend the command byte before polling the status again. Callers must | ||
208 | * hold applesmc_lock. | ||
209 | */ | ||
210 | static int send_command(u8 cmd) | ||
211 | { | ||
212 | int us; | ||
213 | for (us = APPLESMC_MIN_WAIT; us < APPLESMC_MAX_WAIT; us <<= 1) { | ||
214 | outb(cmd, APPLESMC_CMD_PORT); | ||
215 | udelay(us); | ||
216 | if ((inb(APPLESMC_CMD_PORT) & APPLESMC_STATUS_MASK) == 0x0c) | ||
217 | return 0; | ||
218 | } | ||
219 | printk(KERN_WARNING "applesmc: command failed: %x -> %x\n", | ||
220 | cmd, inb(APPLESMC_CMD_PORT)); | ||
221 | return -EIO; | ||
222 | } | ||
223 | |||
224 | /* | ||
194 | * applesmc_read_key - reads len bytes from a given key, and put them in buffer. | 225 | * applesmc_read_key - reads len bytes from a given key, and put them in buffer. |
195 | * Returns zero on success or a negative error on failure. Callers must | 226 | * Returns zero on success or a negative error on failure. Callers must |
196 | * hold applesmc_lock. | 227 | * hold applesmc_lock. |
@@ -205,8 +236,7 @@ static int applesmc_read_key(const char* key, u8* buffer, u8 len) | |||
205 | return -EINVAL; | 236 | return -EINVAL; |
206 | } | 237 | } |
207 | 238 | ||
208 | outb(APPLESMC_READ_CMD, APPLESMC_CMD_PORT); | 239 | if (send_command(APPLESMC_READ_CMD)) |
209 | if (__wait_status(0x0c)) | ||
210 | return -EIO; | 240 | return -EIO; |
211 | 241 | ||
212 | for (i = 0; i < 4; i++) { | 242 | for (i = 0; i < 4; i++) { |
@@ -249,8 +279,7 @@ static int applesmc_write_key(const char* key, u8* buffer, u8 len) | |||
249 | return -EINVAL; | 279 | return -EINVAL; |
250 | } | 280 | } |
251 | 281 | ||
252 | outb(APPLESMC_WRITE_CMD, APPLESMC_CMD_PORT); | 282 | if (send_command(APPLESMC_WRITE_CMD)) |
253 | if (__wait_status(0x0c)) | ||
254 | return -EIO; | 283 | return -EIO; |
255 | 284 | ||
256 | for (i = 0; i < 4; i++) { | 285 | for (i = 0; i < 4; i++) { |
@@ -284,8 +313,7 @@ static int applesmc_get_key_at_index(int index, char* key) | |||
284 | readkey[2] = index >> 8; | 313 | readkey[2] = index >> 8; |
285 | readkey[3] = index; | 314 | readkey[3] = index; |
286 | 315 | ||
287 | outb(APPLESMC_GET_KEY_BY_INDEX_CMD, APPLESMC_CMD_PORT); | 316 | if (send_command(APPLESMC_GET_KEY_BY_INDEX_CMD)) |
288 | if (__wait_status(0x0c)) | ||
289 | return -EIO; | 317 | return -EIO; |
290 | 318 | ||
291 | for (i = 0; i < 4; i++) { | 319 | for (i = 0; i < 4; i++) { |
@@ -315,8 +343,7 @@ static int applesmc_get_key_type(char* key, char* type) | |||
315 | { | 343 | { |
316 | int i; | 344 | int i; |
317 | 345 | ||
318 | outb(APPLESMC_GET_KEY_TYPE_CMD, APPLESMC_CMD_PORT); | 346 | if (send_command(APPLESMC_GET_KEY_TYPE_CMD)) |
319 | if (__wait_status(0x0c)) | ||
320 | return -EIO; | 347 | return -EIO; |
321 | 348 | ||
322 | for (i = 0; i < 4; i++) { | 349 | for (i = 0; i < 4; i++) { |
@@ -325,7 +352,7 @@ static int applesmc_get_key_type(char* key, char* type) | |||
325 | return -EIO; | 352 | return -EIO; |
326 | } | 353 | } |
327 | 354 | ||
328 | outb(5, APPLESMC_DATA_PORT); | 355 | outb(6, APPLESMC_DATA_PORT); |
329 | 356 | ||
330 | for (i = 0; i < 6; i++) { | 357 | for (i = 0; i < 6; i++) { |
331 | if (__wait_status(0x05)) | 358 | if (__wait_status(0x05)) |
@@ -527,17 +554,27 @@ out: | |||
527 | static ssize_t applesmc_light_show(struct device *dev, | 554 | static ssize_t applesmc_light_show(struct device *dev, |
528 | struct device_attribute *attr, char *sysfsbuf) | 555 | struct device_attribute *attr, char *sysfsbuf) |
529 | { | 556 | { |
557 | static int data_length; | ||
530 | int ret; | 558 | int ret; |
531 | u8 left = 0, right = 0; | 559 | u8 left = 0, right = 0; |
532 | u8 buffer[6]; | 560 | u8 buffer[10], query[6]; |
533 | 561 | ||
534 | mutex_lock(&applesmc_lock); | 562 | mutex_lock(&applesmc_lock); |
535 | 563 | ||
536 | ret = applesmc_read_key(LIGHT_SENSOR_LEFT_KEY, buffer, 6); | 564 | if (!data_length) { |
565 | ret = applesmc_get_key_type(LIGHT_SENSOR_LEFT_KEY, query); | ||
566 | if (ret) | ||
567 | goto out; | ||
568 | data_length = clamp_val(query[0], 0, 10); | ||
569 | printk(KERN_INFO "applesmc: light sensor data length set to " | ||
570 | "%d\n", data_length); | ||
571 | } | ||
572 | |||
573 | ret = applesmc_read_key(LIGHT_SENSOR_LEFT_KEY, buffer, data_length); | ||
537 | left = buffer[2]; | 574 | left = buffer[2]; |
538 | if (ret) | 575 | if (ret) |
539 | goto out; | 576 | goto out; |
540 | ret = applesmc_read_key(LIGHT_SENSOR_RIGHT_KEY, buffer, 6); | 577 | ret = applesmc_read_key(LIGHT_SENSOR_RIGHT_KEY, buffer, data_length); |
541 | right = buffer[2]; | 578 | right = buffer[2]; |
542 | 579 | ||
543 | out: | 580 | out: |
@@ -1233,39 +1270,57 @@ static __initdata struct dmi_match_data applesmc_dmi_data[] = { | |||
1233 | { .accelerometer = 0, .light = 0, .temperature_set = 5 }, | 1270 | { .accelerometer = 0, .light = 0, .temperature_set = 5 }, |
1234 | /* MacBook3: accelerometer and temperature set 6 */ | 1271 | /* MacBook3: accelerometer and temperature set 6 */ |
1235 | { .accelerometer = 1, .light = 0, .temperature_set = 6 }, | 1272 | { .accelerometer = 1, .light = 0, .temperature_set = 6 }, |
1273 | /* MacBook Air: accelerometer, backlight and temperature set 7 */ | ||
1274 | { .accelerometer = 1, .light = 1, .temperature_set = 7 }, | ||
1275 | /* MacBook Pro 4: accelerometer, backlight and temperature set 8 */ | ||
1276 | { .accelerometer = 1, .light = 1, .temperature_set = 8 }, | ||
1277 | /* MacBook Pro 3: accelerometer, backlight and temperature set 9 */ | ||
1278 | { .accelerometer = 1, .light = 1, .temperature_set = 9 }, | ||
1236 | }; | 1279 | }; |
1237 | 1280 | ||
1238 | /* Note that DMI_MATCH(...,"MacBook") will match "MacBookPro1,1". | 1281 | /* Note that DMI_MATCH(...,"MacBook") will match "MacBookPro1,1". |
1239 | * So we need to put "Apple MacBook Pro" before "Apple MacBook". */ | 1282 | * So we need to put "Apple MacBook Pro" before "Apple MacBook". */ |
1240 | static __initdata struct dmi_system_id applesmc_whitelist[] = { | 1283 | static __initdata struct dmi_system_id applesmc_whitelist[] = { |
1284 | { applesmc_dmi_match, "Apple MacBook Air", { | ||
1285 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), | ||
1286 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBookAir") }, | ||
1287 | &applesmc_dmi_data[7]}, | ||
1288 | { applesmc_dmi_match, "Apple MacBook Pro 4", { | ||
1289 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), | ||
1290 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro4") }, | ||
1291 | &applesmc_dmi_data[8]}, | ||
1292 | { applesmc_dmi_match, "Apple MacBook Pro 3", { | ||
1293 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), | ||
1294 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro3") }, | ||
1295 | &applesmc_dmi_data[9]}, | ||
1241 | { applesmc_dmi_match, "Apple MacBook Pro", { | 1296 | { applesmc_dmi_match, "Apple MacBook Pro", { |
1242 | DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), | 1297 | DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), |
1243 | DMI_MATCH(DMI_PRODUCT_NAME,"MacBookPro") }, | 1298 | DMI_MATCH(DMI_PRODUCT_NAME,"MacBookPro") }, |
1244 | (void*)&applesmc_dmi_data[0]}, | 1299 | &applesmc_dmi_data[0]}, |
1245 | { applesmc_dmi_match, "Apple MacBook (v2)", { | 1300 | { applesmc_dmi_match, "Apple MacBook (v2)", { |
1246 | DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), | 1301 | DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), |
1247 | DMI_MATCH(DMI_PRODUCT_NAME,"MacBook2") }, | 1302 | DMI_MATCH(DMI_PRODUCT_NAME,"MacBook2") }, |
1248 | (void*)&applesmc_dmi_data[1]}, | 1303 | &applesmc_dmi_data[1]}, |
1249 | { applesmc_dmi_match, "Apple MacBook (v3)", { | 1304 | { applesmc_dmi_match, "Apple MacBook (v3)", { |
1250 | DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), | 1305 | DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), |
1251 | DMI_MATCH(DMI_PRODUCT_NAME,"MacBook3") }, | 1306 | DMI_MATCH(DMI_PRODUCT_NAME,"MacBook3") }, |
1252 | (void*)&applesmc_dmi_data[6]}, | 1307 | &applesmc_dmi_data[6]}, |
1253 | { applesmc_dmi_match, "Apple MacBook", { | 1308 | { applesmc_dmi_match, "Apple MacBook", { |
1254 | DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), | 1309 | DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), |
1255 | DMI_MATCH(DMI_PRODUCT_NAME,"MacBook") }, | 1310 | DMI_MATCH(DMI_PRODUCT_NAME,"MacBook") }, |
1256 | (void*)&applesmc_dmi_data[2]}, | 1311 | &applesmc_dmi_data[2]}, |
1257 | { applesmc_dmi_match, "Apple Macmini", { | 1312 | { applesmc_dmi_match, "Apple Macmini", { |
1258 | DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), | 1313 | DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), |
1259 | DMI_MATCH(DMI_PRODUCT_NAME,"Macmini") }, | 1314 | DMI_MATCH(DMI_PRODUCT_NAME,"Macmini") }, |
1260 | (void*)&applesmc_dmi_data[3]}, | 1315 | &applesmc_dmi_data[3]}, |
1261 | { applesmc_dmi_match, "Apple MacPro2", { | 1316 | { applesmc_dmi_match, "Apple MacPro2", { |
1262 | DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), | 1317 | DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), |
1263 | DMI_MATCH(DMI_PRODUCT_NAME,"MacPro2") }, | 1318 | DMI_MATCH(DMI_PRODUCT_NAME,"MacPro2") }, |
1264 | (void*)&applesmc_dmi_data[4]}, | 1319 | &applesmc_dmi_data[4]}, |
1265 | { applesmc_dmi_match, "Apple iMac", { | 1320 | { applesmc_dmi_match, "Apple iMac", { |
1266 | DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), | 1321 | DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), |
1267 | DMI_MATCH(DMI_PRODUCT_NAME,"iMac") }, | 1322 | DMI_MATCH(DMI_PRODUCT_NAME,"iMac") }, |
1268 | (void*)&applesmc_dmi_data[5]}, | 1323 | &applesmc_dmi_data[5]}, |
1269 | { .ident = NULL } | 1324 | { .ident = NULL } |
1270 | }; | 1325 | }; |
1271 | 1326 | ||
diff --git a/drivers/hwmon/pc87360.c b/drivers/hwmon/pc87360.c index 9b462bb13fa3..5fbfa34c110e 100644 --- a/drivers/hwmon/pc87360.c +++ b/drivers/hwmon/pc87360.c | |||
@@ -75,7 +75,8 @@ MODULE_PARM_DESC(force_id, "Override the detected device ID"); | |||
75 | #define FSCM 0x09 /* Logical device: fans */ | 75 | #define FSCM 0x09 /* Logical device: fans */ |
76 | #define VLM 0x0d /* Logical device: voltages */ | 76 | #define VLM 0x0d /* Logical device: voltages */ |
77 | #define TMS 0x0e /* Logical device: temperatures */ | 77 | #define TMS 0x0e /* Logical device: temperatures */ |
78 | static const u8 logdev[3] = { FSCM, VLM, TMS }; | 78 | #define LDNI_MAX 3 |
79 | static const u8 logdev[LDNI_MAX] = { FSCM, VLM, TMS }; | ||
79 | 80 | ||
80 | #define LD_FAN 0 | 81 | #define LD_FAN 0 |
81 | #define LD_IN 1 | 82 | #define LD_IN 1 |
@@ -489,11 +490,66 @@ static struct sensor_device_attribute in_max[] = { | |||
489 | SENSOR_ATTR(in10_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 10), | 490 | SENSOR_ATTR(in10_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 10), |
490 | }; | 491 | }; |
491 | 492 | ||
493 | /* (temp & vin) channel status register alarm bits (pdf sec.11.5.12) */ | ||
494 | #define CHAN_ALM_MIN 0x02 /* min limit crossed */ | ||
495 | #define CHAN_ALM_MAX 0x04 /* max limit exceeded */ | ||
496 | #define TEMP_ALM_CRIT 0x08 /* temp crit exceeded (temp only) */ | ||
497 | |||
498 | /* show_in_min/max_alarm() reads data from the per-channel status | ||
499 | register (sec 11.5.12), not the vin event status registers (sec | ||
500 | 11.5.2) that (legacy) show_in_alarm() resds (via data->in_alarms) */ | ||
501 | |||
502 | static ssize_t show_in_min_alarm(struct device *dev, | ||
503 | struct device_attribute *devattr, char *buf) | ||
504 | { | ||
505 | struct pc87360_data *data = pc87360_update_device(dev); | ||
506 | unsigned nr = to_sensor_dev_attr(devattr)->index; | ||
507 | |||
508 | return sprintf(buf, "%u\n", !!(data->in_status[nr] & CHAN_ALM_MIN)); | ||
509 | } | ||
510 | static ssize_t show_in_max_alarm(struct device *dev, | ||
511 | struct device_attribute *devattr, char *buf) | ||
512 | { | ||
513 | struct pc87360_data *data = pc87360_update_device(dev); | ||
514 | unsigned nr = to_sensor_dev_attr(devattr)->index; | ||
515 | |||
516 | return sprintf(buf, "%u\n", !!(data->in_status[nr] & CHAN_ALM_MAX)); | ||
517 | } | ||
518 | |||
519 | static struct sensor_device_attribute in_min_alarm[] = { | ||
520 | SENSOR_ATTR(in0_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 0), | ||
521 | SENSOR_ATTR(in1_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 1), | ||
522 | SENSOR_ATTR(in2_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 2), | ||
523 | SENSOR_ATTR(in3_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 3), | ||
524 | SENSOR_ATTR(in4_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 4), | ||
525 | SENSOR_ATTR(in5_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 5), | ||
526 | SENSOR_ATTR(in6_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 6), | ||
527 | SENSOR_ATTR(in7_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 7), | ||
528 | SENSOR_ATTR(in8_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 8), | ||
529 | SENSOR_ATTR(in9_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 9), | ||
530 | SENSOR_ATTR(in10_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 10), | ||
531 | }; | ||
532 | static struct sensor_device_attribute in_max_alarm[] = { | ||
533 | SENSOR_ATTR(in0_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 0), | ||
534 | SENSOR_ATTR(in1_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 1), | ||
535 | SENSOR_ATTR(in2_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 2), | ||
536 | SENSOR_ATTR(in3_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 3), | ||
537 | SENSOR_ATTR(in4_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 4), | ||
538 | SENSOR_ATTR(in5_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 5), | ||
539 | SENSOR_ATTR(in6_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 6), | ||
540 | SENSOR_ATTR(in7_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 7), | ||
541 | SENSOR_ATTR(in8_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 8), | ||
542 | SENSOR_ATTR(in9_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 9), | ||
543 | SENSOR_ATTR(in10_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 10), | ||
544 | }; | ||
545 | |||
492 | #define VIN_UNIT_ATTRS(X) \ | 546 | #define VIN_UNIT_ATTRS(X) \ |
493 | &in_input[X].dev_attr.attr, \ | 547 | &in_input[X].dev_attr.attr, \ |
494 | &in_status[X].dev_attr.attr, \ | 548 | &in_status[X].dev_attr.attr, \ |
495 | &in_min[X].dev_attr.attr, \ | 549 | &in_min[X].dev_attr.attr, \ |
496 | &in_max[X].dev_attr.attr | 550 | &in_max[X].dev_attr.attr, \ |
551 | &in_min_alarm[X].dev_attr.attr, \ | ||
552 | &in_max_alarm[X].dev_attr.attr | ||
497 | 553 | ||
498 | static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf) | 554 | static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf) |
499 | { | 555 | { |
@@ -658,12 +714,68 @@ static struct sensor_device_attribute therm_crit[] = { | |||
658 | show_therm_crit, set_therm_crit, 2+11), | 714 | show_therm_crit, set_therm_crit, 2+11), |
659 | }; | 715 | }; |
660 | 716 | ||
717 | /* show_therm_min/max_alarm() reads data from the per-channel voltage | ||
718 | status register (sec 11.5.12) */ | ||
719 | |||
720 | static ssize_t show_therm_min_alarm(struct device *dev, | ||
721 | struct device_attribute *devattr, char *buf) | ||
722 | { | ||
723 | struct pc87360_data *data = pc87360_update_device(dev); | ||
724 | unsigned nr = to_sensor_dev_attr(devattr)->index; | ||
725 | |||
726 | return sprintf(buf, "%u\n", !!(data->in_status[nr] & CHAN_ALM_MIN)); | ||
727 | } | ||
728 | static ssize_t show_therm_max_alarm(struct device *dev, | ||
729 | struct device_attribute *devattr, char *buf) | ||
730 | { | ||
731 | struct pc87360_data *data = pc87360_update_device(dev); | ||
732 | unsigned nr = to_sensor_dev_attr(devattr)->index; | ||
733 | |||
734 | return sprintf(buf, "%u\n", !!(data->in_status[nr] & CHAN_ALM_MAX)); | ||
735 | } | ||
736 | static ssize_t show_therm_crit_alarm(struct device *dev, | ||
737 | struct device_attribute *devattr, char *buf) | ||
738 | { | ||
739 | struct pc87360_data *data = pc87360_update_device(dev); | ||
740 | unsigned nr = to_sensor_dev_attr(devattr)->index; | ||
741 | |||
742 | return sprintf(buf, "%u\n", !!(data->in_status[nr] & TEMP_ALM_CRIT)); | ||
743 | } | ||
744 | |||
745 | static struct sensor_device_attribute therm_min_alarm[] = { | ||
746 | SENSOR_ATTR(temp4_min_alarm, S_IRUGO, | ||
747 | show_therm_min_alarm, NULL, 0+11), | ||
748 | SENSOR_ATTR(temp5_min_alarm, S_IRUGO, | ||
749 | show_therm_min_alarm, NULL, 1+11), | ||
750 | SENSOR_ATTR(temp6_min_alarm, S_IRUGO, | ||
751 | show_therm_min_alarm, NULL, 2+11), | ||
752 | }; | ||
753 | static struct sensor_device_attribute therm_max_alarm[] = { | ||
754 | SENSOR_ATTR(temp4_max_alarm, S_IRUGO, | ||
755 | show_therm_max_alarm, NULL, 0+11), | ||
756 | SENSOR_ATTR(temp5_max_alarm, S_IRUGO, | ||
757 | show_therm_max_alarm, NULL, 1+11), | ||
758 | SENSOR_ATTR(temp6_max_alarm, S_IRUGO, | ||
759 | show_therm_max_alarm, NULL, 2+11), | ||
760 | }; | ||
761 | static struct sensor_device_attribute therm_crit_alarm[] = { | ||
762 | SENSOR_ATTR(temp4_crit_alarm, S_IRUGO, | ||
763 | show_therm_crit_alarm, NULL, 0+11), | ||
764 | SENSOR_ATTR(temp5_crit_alarm, S_IRUGO, | ||
765 | show_therm_crit_alarm, NULL, 1+11), | ||
766 | SENSOR_ATTR(temp6_crit_alarm, S_IRUGO, | ||
767 | show_therm_crit_alarm, NULL, 2+11), | ||
768 | }; | ||
769 | |||
661 | #define THERM_UNIT_ATTRS(X) \ | 770 | #define THERM_UNIT_ATTRS(X) \ |
662 | &therm_input[X].dev_attr.attr, \ | 771 | &therm_input[X].dev_attr.attr, \ |
663 | &therm_status[X].dev_attr.attr, \ | 772 | &therm_status[X].dev_attr.attr, \ |
664 | &therm_min[X].dev_attr.attr, \ | 773 | &therm_min[X].dev_attr.attr, \ |
665 | &therm_max[X].dev_attr.attr, \ | 774 | &therm_max[X].dev_attr.attr, \ |
666 | &therm_crit[X].dev_attr.attr | 775 | &therm_crit[X].dev_attr.attr, \ |
776 | &therm_min_alarm[X].dev_attr.attr, \ | ||
777 | &therm_max_alarm[X].dev_attr.attr, \ | ||
778 | &therm_crit_alarm[X].dev_attr.attr | ||
667 | 779 | ||
668 | static struct attribute * pc8736x_therm_attr_array[] = { | 780 | static struct attribute * pc8736x_therm_attr_array[] = { |
669 | THERM_UNIT_ATTRS(0), | 781 | THERM_UNIT_ATTRS(0), |
@@ -790,12 +902,76 @@ static ssize_t show_temp_alarms(struct device *dev, struct device_attribute *att | |||
790 | } | 902 | } |
791 | static DEVICE_ATTR(alarms_temp, S_IRUGO, show_temp_alarms, NULL); | 903 | static DEVICE_ATTR(alarms_temp, S_IRUGO, show_temp_alarms, NULL); |
792 | 904 | ||
905 | /* show_temp_min/max_alarm() reads data from the per-channel status | ||
906 | register (sec 12.3.7), not the temp event status registers (sec | ||
907 | 12.3.2) that show_temp_alarm() reads (via data->temp_alarms) */ | ||
908 | |||
909 | static ssize_t show_temp_min_alarm(struct device *dev, | ||
910 | struct device_attribute *devattr, char *buf) | ||
911 | { | ||
912 | struct pc87360_data *data = pc87360_update_device(dev); | ||
913 | unsigned nr = to_sensor_dev_attr(devattr)->index; | ||
914 | |||
915 | return sprintf(buf, "%u\n", !!(data->temp_status[nr] & CHAN_ALM_MIN)); | ||
916 | } | ||
917 | static ssize_t show_temp_max_alarm(struct device *dev, | ||
918 | struct device_attribute *devattr, char *buf) | ||
919 | { | ||
920 | struct pc87360_data *data = pc87360_update_device(dev); | ||
921 | unsigned nr = to_sensor_dev_attr(devattr)->index; | ||
922 | |||
923 | return sprintf(buf, "%u\n", !!(data->temp_status[nr] & CHAN_ALM_MAX)); | ||
924 | } | ||
925 | static ssize_t show_temp_crit_alarm(struct device *dev, | ||
926 | struct device_attribute *devattr, char *buf) | ||
927 | { | ||
928 | struct pc87360_data *data = pc87360_update_device(dev); | ||
929 | unsigned nr = to_sensor_dev_attr(devattr)->index; | ||
930 | |||
931 | return sprintf(buf, "%u\n", !!(data->temp_status[nr] & TEMP_ALM_CRIT)); | ||
932 | } | ||
933 | |||
934 | static struct sensor_device_attribute temp_min_alarm[] = { | ||
935 | SENSOR_ATTR(temp1_min_alarm, S_IRUGO, show_temp_min_alarm, NULL, 0), | ||
936 | SENSOR_ATTR(temp2_min_alarm, S_IRUGO, show_temp_min_alarm, NULL, 1), | ||
937 | SENSOR_ATTR(temp3_min_alarm, S_IRUGO, show_temp_min_alarm, NULL, 2), | ||
938 | }; | ||
939 | static struct sensor_device_attribute temp_max_alarm[] = { | ||
940 | SENSOR_ATTR(temp1_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 0), | ||
941 | SENSOR_ATTR(temp2_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 1), | ||
942 | SENSOR_ATTR(temp3_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 2), | ||
943 | }; | ||
944 | static struct sensor_device_attribute temp_crit_alarm[] = { | ||
945 | SENSOR_ATTR(temp1_crit_alarm, S_IRUGO, show_temp_crit_alarm, NULL, 0), | ||
946 | SENSOR_ATTR(temp2_crit_alarm, S_IRUGO, show_temp_crit_alarm, NULL, 1), | ||
947 | SENSOR_ATTR(temp3_crit_alarm, S_IRUGO, show_temp_crit_alarm, NULL, 2), | ||
948 | }; | ||
949 | |||
950 | #define TEMP_FAULT 0x40 /* open diode */ | ||
951 | static ssize_t show_temp_fault(struct device *dev, | ||
952 | struct device_attribute *devattr, char *buf) | ||
953 | { | ||
954 | struct pc87360_data *data = pc87360_update_device(dev); | ||
955 | unsigned nr = to_sensor_dev_attr(devattr)->index; | ||
956 | |||
957 | return sprintf(buf, "%u\n", !!(data->temp_status[nr] & TEMP_FAULT)); | ||
958 | } | ||
959 | static struct sensor_device_attribute temp_fault[] = { | ||
960 | SENSOR_ATTR(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0), | ||
961 | SENSOR_ATTR(temp2_fault, S_IRUGO, show_temp_fault, NULL, 1), | ||
962 | SENSOR_ATTR(temp3_fault, S_IRUGO, show_temp_fault, NULL, 2), | ||
963 | }; | ||
964 | |||
793 | #define TEMP_UNIT_ATTRS(X) \ | 965 | #define TEMP_UNIT_ATTRS(X) \ |
794 | &temp_input[X].dev_attr.attr, \ | 966 | &temp_input[X].dev_attr.attr, \ |
795 | &temp_status[X].dev_attr.attr, \ | 967 | &temp_status[X].dev_attr.attr, \ |
796 | &temp_min[X].dev_attr.attr, \ | 968 | &temp_min[X].dev_attr.attr, \ |
797 | &temp_max[X].dev_attr.attr, \ | 969 | &temp_max[X].dev_attr.attr, \ |
798 | &temp_crit[X].dev_attr.attr | 970 | &temp_crit[X].dev_attr.attr, \ |
971 | &temp_min_alarm[X].dev_attr.attr, \ | ||
972 | &temp_max_alarm[X].dev_attr.attr, \ | ||
973 | &temp_crit_alarm[X].dev_attr.attr, \ | ||
974 | &temp_fault[X].dev_attr.attr | ||
799 | 975 | ||
800 | static struct attribute * pc8736x_temp_attr_array[] = { | 976 | static struct attribute * pc8736x_temp_attr_array[] = { |
801 | TEMP_UNIT_ATTRS(0), | 977 | TEMP_UNIT_ATTRS(0), |
@@ -809,8 +985,8 @@ static const struct attribute_group pc8736x_temp_group = { | |||
809 | .attrs = pc8736x_temp_attr_array, | 985 | .attrs = pc8736x_temp_attr_array, |
810 | }; | 986 | }; |
811 | 987 | ||
812 | static ssize_t show_name(struct device *dev, struct device_attribute | 988 | static ssize_t show_name(struct device *dev, |
813 | *devattr, char *buf) | 989 | struct device_attribute *devattr, char *buf) |
814 | { | 990 | { |
815 | struct pc87360_data *data = dev_get_drvdata(dev); | 991 | struct pc87360_data *data = dev_get_drvdata(dev); |
816 | return sprintf(buf, "%s\n", data->name); | 992 | return sprintf(buf, "%s\n", data->name); |
@@ -955,7 +1131,7 @@ static int __devinit pc87360_probe(struct platform_device *pdev) | |||
955 | mutex_init(&data->update_lock); | 1131 | mutex_init(&data->update_lock); |
956 | platform_set_drvdata(pdev, data); | 1132 | platform_set_drvdata(pdev, data); |
957 | 1133 | ||
958 | for (i = 0; i < 3; i++) { | 1134 | for (i = 0; i < LDNI_MAX; i++) { |
959 | if (((data->address[i] = extra_isa[i])) | 1135 | if (((data->address[i] = extra_isa[i])) |
960 | && !request_region(extra_isa[i], PC87360_EXTENT, | 1136 | && !request_region(extra_isa[i], PC87360_EXTENT, |
961 | pc87360_driver.driver.name)) { | 1137 | pc87360_driver.driver.name)) { |
@@ -1031,7 +1207,15 @@ static int __devinit pc87360_probe(struct platform_device *pdev) | |||
1031 | || (err = device_create_file(dev, | 1207 | || (err = device_create_file(dev, |
1032 | &temp_crit[i].dev_attr)) | 1208 | &temp_crit[i].dev_attr)) |
1033 | || (err = device_create_file(dev, | 1209 | || (err = device_create_file(dev, |
1034 | &temp_status[i].dev_attr))) | 1210 | &temp_status[i].dev_attr)) |
1211 | || (err = device_create_file(dev, | ||
1212 | &temp_min_alarm[i].dev_attr)) | ||
1213 | || (err = device_create_file(dev, | ||
1214 | &temp_max_alarm[i].dev_attr)) | ||
1215 | || (err = device_create_file(dev, | ||
1216 | &temp_crit_alarm[i].dev_attr)) | ||
1217 | || (err = device_create_file(dev, | ||
1218 | &temp_fault[i].dev_attr))) | ||
1035 | goto ERROR3; | 1219 | goto ERROR3; |
1036 | } | 1220 | } |
1037 | if ((err = device_create_file(dev, &dev_attr_alarms_temp))) | 1221 | if ((err = device_create_file(dev, &dev_attr_alarms_temp))) |
@@ -1131,6 +1315,16 @@ static void pc87360_write_value(struct pc87360_data *data, u8 ldi, u8 bank, | |||
1131 | mutex_unlock(&(data->lock)); | 1315 | mutex_unlock(&(data->lock)); |
1132 | } | 1316 | } |
1133 | 1317 | ||
1318 | /* (temp & vin) channel conversion status register flags (pdf sec.11.5.12) */ | ||
1319 | #define CHAN_CNVRTD 0x80 /* new data ready */ | ||
1320 | #define CHAN_ENA 0x01 /* enabled channel (temp or vin) */ | ||
1321 | #define CHAN_ALM_ENA 0x10 /* propagate to alarms-reg ?? (chk val!) */ | ||
1322 | #define CHAN_READY (CHAN_ENA|CHAN_CNVRTD) /* sample ready mask */ | ||
1323 | |||
1324 | #define TEMP_OTS_OE 0x20 /* OTS Output Enable */ | ||
1325 | #define VIN_RW1C_MASK (CHAN_READY|CHAN_ALM_MAX|CHAN_ALM_MIN) /* 0x87 */ | ||
1326 | #define TEMP_RW1C_MASK (VIN_RW1C_MASK|TEMP_ALM_CRIT|TEMP_FAULT) /* 0xCF */ | ||
1327 | |||
1134 | static void pc87360_init_device(struct platform_device *pdev, | 1328 | static void pc87360_init_device(struct platform_device *pdev, |
1135 | int use_thermistors) | 1329 | int use_thermistors) |
1136 | { | 1330 | { |
@@ -1152,11 +1346,12 @@ static void pc87360_init_device(struct platform_device *pdev, | |||
1152 | 1346 | ||
1153 | nr = data->innr < 11 ? data->innr : 11; | 1347 | nr = data->innr < 11 ? data->innr : 11; |
1154 | for (i = 0; i < nr; i++) { | 1348 | for (i = 0; i < nr; i++) { |
1349 | reg = pc87360_read_value(data, LD_IN, i, | ||
1350 | PC87365_REG_IN_STATUS); | ||
1351 | dev_dbg(&pdev->dev, "bios in%d status:0x%02x\n", i, reg); | ||
1155 | if (init >= init_in[i]) { | 1352 | if (init >= init_in[i]) { |
1156 | /* Forcibly enable voltage channel */ | 1353 | /* Forcibly enable voltage channel */ |
1157 | reg = pc87360_read_value(data, LD_IN, i, | 1354 | if (!(reg & CHAN_ENA)) { |
1158 | PC87365_REG_IN_STATUS); | ||
1159 | if (!(reg & 0x01)) { | ||
1160 | dev_dbg(&pdev->dev, "Forcibly " | 1355 | dev_dbg(&pdev->dev, "Forcibly " |
1161 | "enabling in%d\n", i); | 1356 | "enabling in%d\n", i); |
1162 | pc87360_write_value(data, LD_IN, i, | 1357 | pc87360_write_value(data, LD_IN, i, |
@@ -1168,19 +1363,24 @@ static void pc87360_init_device(struct platform_device *pdev, | |||
1168 | 1363 | ||
1169 | /* We can't blindly trust the Super-I/O space configuration bit, | 1364 | /* We can't blindly trust the Super-I/O space configuration bit, |
1170 | most BIOS won't set it properly */ | 1365 | most BIOS won't set it properly */ |
1366 | dev_dbg(&pdev->dev, "bios thermistors:%d\n", use_thermistors); | ||
1171 | for (i = 11; i < data->innr; i++) { | 1367 | for (i = 11; i < data->innr; i++) { |
1172 | reg = pc87360_read_value(data, LD_IN, i, | 1368 | reg = pc87360_read_value(data, LD_IN, i, |
1173 | PC87365_REG_TEMP_STATUS); | 1369 | PC87365_REG_TEMP_STATUS); |
1174 | use_thermistors = use_thermistors || (reg & 0x01); | 1370 | use_thermistors = use_thermistors || (reg & CHAN_ENA); |
1371 | /* thermistors are temp[4-6], measured on vin[11-14] */ | ||
1372 | dev_dbg(&pdev->dev, "bios temp%d_status:0x%02x\n", i-7, reg); | ||
1175 | } | 1373 | } |
1374 | dev_dbg(&pdev->dev, "using thermistors:%d\n", use_thermistors); | ||
1176 | 1375 | ||
1177 | i = use_thermistors ? 2 : 0; | 1376 | i = use_thermistors ? 2 : 0; |
1178 | for (; i < data->tempnr; i++) { | 1377 | for (; i < data->tempnr; i++) { |
1378 | reg = pc87360_read_value(data, LD_TEMP, i, | ||
1379 | PC87365_REG_TEMP_STATUS); | ||
1380 | dev_dbg(&pdev->dev, "bios temp%d_status:0x%02x\n", i+1, reg); | ||
1179 | if (init >= init_temp[i]) { | 1381 | if (init >= init_temp[i]) { |
1180 | /* Forcibly enable temperature channel */ | 1382 | /* Forcibly enable temperature channel */ |
1181 | reg = pc87360_read_value(data, LD_TEMP, i, | 1383 | if (!(reg & CHAN_ENA)) { |
1182 | PC87365_REG_TEMP_STATUS); | ||
1183 | if (!(reg & 0x01)) { | ||
1184 | dev_dbg(&pdev->dev, "Forcibly " | 1384 | dev_dbg(&pdev->dev, "Forcibly " |
1185 | "enabling temp%d\n", i+1); | 1385 | "enabling temp%d\n", i+1); |
1186 | pc87360_write_value(data, LD_TEMP, i, | 1386 | pc87360_write_value(data, LD_TEMP, i, |
@@ -1197,7 +1397,7 @@ static void pc87360_init_device(struct platform_device *pdev, | |||
1197 | diodes */ | 1397 | diodes */ |
1198 | reg = pc87360_read_value(data, LD_TEMP, | 1398 | reg = pc87360_read_value(data, LD_TEMP, |
1199 | (i-11)/2, PC87365_REG_TEMP_STATUS); | 1399 | (i-11)/2, PC87365_REG_TEMP_STATUS); |
1200 | if (reg & 0x01) { | 1400 | if (reg & CHAN_ENA) { |
1201 | dev_dbg(&pdev->dev, "Skipping " | 1401 | dev_dbg(&pdev->dev, "Skipping " |
1202 | "temp%d, pin already in use " | 1402 | "temp%d, pin already in use " |
1203 | "by temp%d\n", i-7, (i-11)/2); | 1403 | "by temp%d\n", i-7, (i-11)/2); |
@@ -1207,7 +1407,7 @@ static void pc87360_init_device(struct platform_device *pdev, | |||
1207 | /* Forcibly enable thermistor channel */ | 1407 | /* Forcibly enable thermistor channel */ |
1208 | reg = pc87360_read_value(data, LD_IN, i, | 1408 | reg = pc87360_read_value(data, LD_IN, i, |
1209 | PC87365_REG_IN_STATUS); | 1409 | PC87365_REG_IN_STATUS); |
1210 | if (!(reg & 0x01)) { | 1410 | if (!(reg & CHAN_ENA)) { |
1211 | dev_dbg(&pdev->dev, "Forcibly " | 1411 | dev_dbg(&pdev->dev, "Forcibly " |
1212 | "enabling temp%d\n", i-7); | 1412 | "enabling temp%d\n", i-7); |
1213 | pc87360_write_value(data, LD_IN, i, | 1413 | pc87360_write_value(data, LD_IN, i, |
@@ -1221,7 +1421,8 @@ static void pc87360_init_device(struct platform_device *pdev, | |||
1221 | if (data->innr) { | 1421 | if (data->innr) { |
1222 | reg = pc87360_read_value(data, LD_IN, NO_BANK, | 1422 | reg = pc87360_read_value(data, LD_IN, NO_BANK, |
1223 | PC87365_REG_IN_CONFIG); | 1423 | PC87365_REG_IN_CONFIG); |
1224 | if (reg & 0x01) { | 1424 | dev_dbg(&pdev->dev, "bios vin-cfg:0x%02x\n", reg); |
1425 | if (reg & CHAN_ENA) { | ||
1225 | dev_dbg(&pdev->dev, "Forcibly " | 1426 | dev_dbg(&pdev->dev, "Forcibly " |
1226 | "enabling monitoring (VLM)\n"); | 1427 | "enabling monitoring (VLM)\n"); |
1227 | pc87360_write_value(data, LD_IN, NO_BANK, | 1428 | pc87360_write_value(data, LD_IN, NO_BANK, |
@@ -1233,7 +1434,8 @@ static void pc87360_init_device(struct platform_device *pdev, | |||
1233 | if (data->tempnr) { | 1434 | if (data->tempnr) { |
1234 | reg = pc87360_read_value(data, LD_TEMP, NO_BANK, | 1435 | reg = pc87360_read_value(data, LD_TEMP, NO_BANK, |
1235 | PC87365_REG_TEMP_CONFIG); | 1436 | PC87365_REG_TEMP_CONFIG); |
1236 | if (reg & 0x01) { | 1437 | dev_dbg(&pdev->dev, "bios temp-cfg:0x%02x\n", reg); |
1438 | if (reg & CHAN_ENA) { | ||
1237 | dev_dbg(&pdev->dev, "Forcibly enabling " | 1439 | dev_dbg(&pdev->dev, "Forcibly enabling " |
1238 | "monitoring (TMS)\n"); | 1440 | "monitoring (TMS)\n"); |
1239 | pc87360_write_value(data, LD_TEMP, NO_BANK, | 1441 | pc87360_write_value(data, LD_TEMP, NO_BANK, |
@@ -1336,11 +1538,11 @@ static struct pc87360_data *pc87360_update_device(struct device *dev) | |||
1336 | pc87360_write_value(data, LD_IN, i, | 1538 | pc87360_write_value(data, LD_IN, i, |
1337 | PC87365_REG_IN_STATUS, | 1539 | PC87365_REG_IN_STATUS, |
1338 | data->in_status[i]); | 1540 | data->in_status[i]); |
1339 | if ((data->in_status[i] & 0x81) == 0x81) { | 1541 | if ((data->in_status[i] & CHAN_READY) == CHAN_READY) { |
1340 | data->in[i] = pc87360_read_value(data, LD_IN, | 1542 | data->in[i] = pc87360_read_value(data, LD_IN, |
1341 | i, PC87365_REG_IN); | 1543 | i, PC87365_REG_IN); |
1342 | } | 1544 | } |
1343 | if (data->in_status[i] & 0x01) { | 1545 | if (data->in_status[i] & CHAN_ENA) { |
1344 | data->in_min[i] = pc87360_read_value(data, | 1546 | data->in_min[i] = pc87360_read_value(data, |
1345 | LD_IN, i, | 1547 | LD_IN, i, |
1346 | PC87365_REG_IN_MIN); | 1548 | PC87365_REG_IN_MIN); |
@@ -1373,12 +1575,12 @@ static struct pc87360_data *pc87360_update_device(struct device *dev) | |||
1373 | pc87360_write_value(data, LD_TEMP, i, | 1575 | pc87360_write_value(data, LD_TEMP, i, |
1374 | PC87365_REG_TEMP_STATUS, | 1576 | PC87365_REG_TEMP_STATUS, |
1375 | data->temp_status[i]); | 1577 | data->temp_status[i]); |
1376 | if ((data->temp_status[i] & 0x81) == 0x81) { | 1578 | if ((data->temp_status[i] & CHAN_READY) == CHAN_READY) { |
1377 | data->temp[i] = pc87360_read_value(data, | 1579 | data->temp[i] = pc87360_read_value(data, |
1378 | LD_TEMP, i, | 1580 | LD_TEMP, i, |
1379 | PC87365_REG_TEMP); | 1581 | PC87365_REG_TEMP); |
1380 | } | 1582 | } |
1381 | if (data->temp_status[i] & 0x01) { | 1583 | if (data->temp_status[i] & CHAN_ENA) { |
1382 | data->temp_min[i] = pc87360_read_value(data, | 1584 | data->temp_min[i] = pc87360_read_value(data, |
1383 | LD_TEMP, i, | 1585 | LD_TEMP, i, |
1384 | PC87365_REG_TEMP_MIN); | 1586 | PC87365_REG_TEMP_MIN); |
diff --git a/drivers/i2c/chips/at24.c b/drivers/i2c/chips/at24.c index 2a4acb269569..d4775528abc6 100644 --- a/drivers/i2c/chips/at24.c +++ b/drivers/i2c/chips/at24.c | |||
@@ -460,7 +460,6 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
460 | */ | 460 | */ |
461 | at24->bin.attr.name = "eeprom"; | 461 | at24->bin.attr.name = "eeprom"; |
462 | at24->bin.attr.mode = chip.flags & AT24_FLAG_IRUGO ? S_IRUGO : S_IRUSR; | 462 | at24->bin.attr.mode = chip.flags & AT24_FLAG_IRUGO ? S_IRUGO : S_IRUSR; |
463 | at24->bin.attr.owner = THIS_MODULE; | ||
464 | at24->bin.read = at24_bin_read; | 463 | at24->bin.read = at24_bin_read; |
465 | at24->bin.size = chip.byte_len; | 464 | at24->bin.size = chip.byte_len; |
466 | 465 | ||
diff --git a/drivers/i2c/chips/ds1682.c b/drivers/i2c/chips/ds1682.c index 23be4d42cb02..f3ee4a1abb77 100644 --- a/drivers/i2c/chips/ds1682.c +++ b/drivers/i2c/chips/ds1682.c | |||
@@ -190,7 +190,6 @@ static struct bin_attribute ds1682_eeprom_attr = { | |||
190 | .attr = { | 190 | .attr = { |
191 | .name = "eeprom", | 191 | .name = "eeprom", |
192 | .mode = S_IRUGO | S_IWUSR, | 192 | .mode = S_IRUGO | S_IWUSR, |
193 | .owner = THIS_MODULE, | ||
194 | }, | 193 | }, |
195 | .size = DS1682_EEPROM_SIZE, | 194 | .size = DS1682_EEPROM_SIZE, |
196 | .read = ds1682_eeprom_read, | 195 | .read = ds1682_eeprom_read, |
diff --git a/drivers/i2c/chips/menelaus.c b/drivers/i2c/chips/menelaus.c index 176126d3a01d..4b364bae6b3e 100644 --- a/drivers/i2c/chips/menelaus.c +++ b/drivers/i2c/chips/menelaus.c | |||
@@ -832,52 +832,52 @@ static irqreturn_t menelaus_irq(int irq, void *_menelaus) | |||
832 | 832 | ||
833 | static void menelaus_to_time(char *regs, struct rtc_time *t) | 833 | static void menelaus_to_time(char *regs, struct rtc_time *t) |
834 | { | 834 | { |
835 | t->tm_sec = BCD2BIN(regs[0]); | 835 | t->tm_sec = bcd2bin(regs[0]); |
836 | t->tm_min = BCD2BIN(regs[1]); | 836 | t->tm_min = bcd2bin(regs[1]); |
837 | if (the_menelaus->rtc_control & RTC_CTRL_MODE12) { | 837 | if (the_menelaus->rtc_control & RTC_CTRL_MODE12) { |
838 | t->tm_hour = BCD2BIN(regs[2] & 0x1f) - 1; | 838 | t->tm_hour = bcd2bin(regs[2] & 0x1f) - 1; |
839 | if (regs[2] & RTC_HR_PM) | 839 | if (regs[2] & RTC_HR_PM) |
840 | t->tm_hour += 12; | 840 | t->tm_hour += 12; |
841 | } else | 841 | } else |
842 | t->tm_hour = BCD2BIN(regs[2] & 0x3f); | 842 | t->tm_hour = bcd2bin(regs[2] & 0x3f); |
843 | t->tm_mday = BCD2BIN(regs[3]); | 843 | t->tm_mday = bcd2bin(regs[3]); |
844 | t->tm_mon = BCD2BIN(regs[4]) - 1; | 844 | t->tm_mon = bcd2bin(regs[4]) - 1; |
845 | t->tm_year = BCD2BIN(regs[5]) + 100; | 845 | t->tm_year = bcd2bin(regs[5]) + 100; |
846 | } | 846 | } |
847 | 847 | ||
848 | static int time_to_menelaus(struct rtc_time *t, int regnum) | 848 | static int time_to_menelaus(struct rtc_time *t, int regnum) |
849 | { | 849 | { |
850 | int hour, status; | 850 | int hour, status; |
851 | 851 | ||
852 | status = menelaus_write_reg(regnum++, BIN2BCD(t->tm_sec)); | 852 | status = menelaus_write_reg(regnum++, bin2bcd(t->tm_sec)); |
853 | if (status < 0) | 853 | if (status < 0) |
854 | goto fail; | 854 | goto fail; |
855 | 855 | ||
856 | status = menelaus_write_reg(regnum++, BIN2BCD(t->tm_min)); | 856 | status = menelaus_write_reg(regnum++, bin2bcd(t->tm_min)); |
857 | if (status < 0) | 857 | if (status < 0) |
858 | goto fail; | 858 | goto fail; |
859 | 859 | ||
860 | if (the_menelaus->rtc_control & RTC_CTRL_MODE12) { | 860 | if (the_menelaus->rtc_control & RTC_CTRL_MODE12) { |
861 | hour = t->tm_hour + 1; | 861 | hour = t->tm_hour + 1; |
862 | if (hour > 12) | 862 | if (hour > 12) |
863 | hour = RTC_HR_PM | BIN2BCD(hour - 12); | 863 | hour = RTC_HR_PM | bin2bcd(hour - 12); |
864 | else | 864 | else |
865 | hour = BIN2BCD(hour); | 865 | hour = bin2bcd(hour); |
866 | } else | 866 | } else |
867 | hour = BIN2BCD(t->tm_hour); | 867 | hour = bin2bcd(t->tm_hour); |
868 | status = menelaus_write_reg(regnum++, hour); | 868 | status = menelaus_write_reg(regnum++, hour); |
869 | if (status < 0) | 869 | if (status < 0) |
870 | goto fail; | 870 | goto fail; |
871 | 871 | ||
872 | status = menelaus_write_reg(regnum++, BIN2BCD(t->tm_mday)); | 872 | status = menelaus_write_reg(regnum++, bin2bcd(t->tm_mday)); |
873 | if (status < 0) | 873 | if (status < 0) |
874 | goto fail; | 874 | goto fail; |
875 | 875 | ||
876 | status = menelaus_write_reg(regnum++, BIN2BCD(t->tm_mon + 1)); | 876 | status = menelaus_write_reg(regnum++, bin2bcd(t->tm_mon + 1)); |
877 | if (status < 0) | 877 | if (status < 0) |
878 | goto fail; | 878 | goto fail; |
879 | 879 | ||
880 | status = menelaus_write_reg(regnum++, BIN2BCD(t->tm_year - 100)); | 880 | status = menelaus_write_reg(regnum++, bin2bcd(t->tm_year - 100)); |
881 | if (status < 0) | 881 | if (status < 0) |
882 | goto fail; | 882 | goto fail; |
883 | 883 | ||
@@ -914,7 +914,7 @@ static int menelaus_read_time(struct device *dev, struct rtc_time *t) | |||
914 | } | 914 | } |
915 | 915 | ||
916 | menelaus_to_time(regs, t); | 916 | menelaus_to_time(regs, t); |
917 | t->tm_wday = BCD2BIN(regs[6]); | 917 | t->tm_wday = bcd2bin(regs[6]); |
918 | 918 | ||
919 | return 0; | 919 | return 0; |
920 | } | 920 | } |
@@ -927,7 +927,7 @@ static int menelaus_set_time(struct device *dev, struct rtc_time *t) | |||
927 | status = time_to_menelaus(t, MENELAUS_RTC_SEC); | 927 | status = time_to_menelaus(t, MENELAUS_RTC_SEC); |
928 | if (status < 0) | 928 | if (status < 0) |
929 | return status; | 929 | return status; |
930 | status = menelaus_write_reg(MENELAUS_RTC_WKDAY, BIN2BCD(t->tm_wday)); | 930 | status = menelaus_write_reg(MENELAUS_RTC_WKDAY, bin2bcd(t->tm_wday)); |
931 | if (status < 0) { | 931 | if (status < 0) { |
932 | dev_err(&the_menelaus->client->dev, "rtc write reg %02x " | 932 | dev_err(&the_menelaus->client->dev, "rtc write reg %02x " |
933 | "err %d\n", MENELAUS_RTC_WKDAY, status); | 933 | "err %d\n", MENELAUS_RTC_WKDAY, status); |
diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c index a78d35aecee3..f1e82a92e61e 100644 --- a/drivers/infiniband/core/cm.c +++ b/drivers/infiniband/core/cm.c | |||
@@ -122,7 +122,7 @@ struct cm_counter_attribute { | |||
122 | 122 | ||
123 | #define CM_COUNTER_ATTR(_name, _index) \ | 123 | #define CM_COUNTER_ATTR(_name, _index) \ |
124 | struct cm_counter_attribute cm_##_name##_counter_attr = { \ | 124 | struct cm_counter_attribute cm_##_name##_counter_attr = { \ |
125 | .attr = { .name = __stringify(_name), .mode = 0444, .owner = THIS_MODULE }, \ | 125 | .attr = { .name = __stringify(_name), .mode = 0444 }, \ |
126 | .index = _index \ | 126 | .index = _index \ |
127 | } | 127 | } |
128 | 128 | ||
diff --git a/drivers/media/dvb/ttpci/av7110.c b/drivers/media/dvb/ttpci/av7110.c index c7c770c28988..aa1ff524256e 100644 --- a/drivers/media/dvb/ttpci/av7110.c +++ b/drivers/media/dvb/ttpci/av7110.c | |||
@@ -36,7 +36,6 @@ | |||
36 | #include <linux/fs.h> | 36 | #include <linux/fs.h> |
37 | #include <linux/timer.h> | 37 | #include <linux/timer.h> |
38 | #include <linux/poll.h> | 38 | #include <linux/poll.h> |
39 | #include <linux/byteorder/swabb.h> | ||
40 | #include <linux/smp_lock.h> | 39 | #include <linux/smp_lock.h> |
41 | 40 | ||
42 | #include <linux/kernel.h> | 41 | #include <linux/kernel.h> |
@@ -52,6 +51,7 @@ | |||
52 | #include <linux/i2c.h> | 51 | #include <linux/i2c.h> |
53 | #include <linux/kthread.h> | 52 | #include <linux/kthread.h> |
54 | #include <asm/unaligned.h> | 53 | #include <asm/unaligned.h> |
54 | #include <asm/byteorder.h> | ||
55 | 55 | ||
56 | #include <asm/system.h> | 56 | #include <asm/system.h> |
57 | 57 | ||
diff --git a/drivers/media/video/cx18/cx18-driver.h b/drivers/media/video/cx18/cx18-driver.h index fa8be0731a3f..a4b1708fafe7 100644 --- a/drivers/media/video/cx18/cx18-driver.h +++ b/drivers/media/video/cx18/cx18-driver.h | |||
@@ -41,6 +41,7 @@ | |||
41 | #include <linux/pagemap.h> | 41 | #include <linux/pagemap.h> |
42 | #include <linux/workqueue.h> | 42 | #include <linux/workqueue.h> |
43 | #include <linux/mutex.h> | 43 | #include <linux/mutex.h> |
44 | #include <asm/byteorder.h> | ||
44 | 45 | ||
45 | #include <linux/dvb/video.h> | 46 | #include <linux/dvb/video.h> |
46 | #include <linux/dvb/audio.h> | 47 | #include <linux/dvb/audio.h> |
diff --git a/drivers/media/video/ivtv/ivtv-driver.h b/drivers/media/video/ivtv/ivtv-driver.h index bc29436e8a3c..3733b2afec5f 100644 --- a/drivers/media/video/ivtv/ivtv-driver.h +++ b/drivers/media/video/ivtv/ivtv-driver.h | |||
@@ -55,6 +55,7 @@ | |||
55 | #include <linux/mutex.h> | 55 | #include <linux/mutex.h> |
56 | #include <asm/uaccess.h> | 56 | #include <asm/uaccess.h> |
57 | #include <asm/system.h> | 57 | #include <asm/system.h> |
58 | #include <asm/byteorder.h> | ||
58 | 59 | ||
59 | #include <linux/dvb/video.h> | 60 | #include <linux/dvb/video.h> |
60 | #include <linux/dvb/audio.h> | 61 | #include <linux/dvb/audio.h> |
diff --git a/drivers/memstick/core/mspro_block.c b/drivers/memstick/core/mspro_block.c index 6e291bf8237a..5263913e0c69 100644 --- a/drivers/memstick/core/mspro_block.c +++ b/drivers/memstick/core/mspro_block.c | |||
@@ -1044,7 +1044,6 @@ static int mspro_block_read_attributes(struct memstick_dev *card) | |||
1044 | 1044 | ||
1045 | s_attr->dev_attr.attr.name = s_attr->name; | 1045 | s_attr->dev_attr.attr.name = s_attr->name; |
1046 | s_attr->dev_attr.attr.mode = S_IRUGO; | 1046 | s_attr->dev_attr.attr.mode = S_IRUGO; |
1047 | s_attr->dev_attr.attr.owner = THIS_MODULE; | ||
1048 | s_attr->dev_attr.show = mspro_block_attr_show(s_attr->id); | 1047 | s_attr->dev_attr.show = mspro_block_attr_show(s_attr->id); |
1049 | 1048 | ||
1050 | if (!rc) | 1049 | if (!rc) |
diff --git a/drivers/misc/hp-wmi.c b/drivers/misc/hp-wmi.c index 5dabfb69ee53..4b7c24c519c3 100644 --- a/drivers/misc/hp-wmi.c +++ b/drivers/misc/hp-wmi.c | |||
@@ -82,6 +82,7 @@ static struct key_entry hp_wmi_keymap[] = { | |||
82 | {KE_KEY, 0x03, KEY_BRIGHTNESSDOWN}, | 82 | {KE_KEY, 0x03, KEY_BRIGHTNESSDOWN}, |
83 | {KE_KEY, 0x20e6, KEY_PROG1}, | 83 | {KE_KEY, 0x20e6, KEY_PROG1}, |
84 | {KE_KEY, 0x2142, KEY_MEDIA}, | 84 | {KE_KEY, 0x2142, KEY_MEDIA}, |
85 | {KE_KEY, 0x213b, KEY_INFO}, | ||
85 | {KE_KEY, 0x231b, KEY_HELP}, | 86 | {KE_KEY, 0x231b, KEY_HELP}, |
86 | {KE_END, 0} | 87 | {KE_END, 0} |
87 | }; | 88 | }; |
diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig index 14f11f8b9e5f..a90d50c2c3e5 100644 --- a/drivers/mtd/Kconfig +++ b/drivers/mtd/Kconfig | |||
@@ -172,6 +172,11 @@ config MTD_CHAR | |||
172 | memory chips, and also use ioctl() to obtain information about | 172 | memory chips, and also use ioctl() to obtain information about |
173 | the device, or to erase parts of it. | 173 | the device, or to erase parts of it. |
174 | 174 | ||
175 | config HAVE_MTD_OTP | ||
176 | bool | ||
177 | help | ||
178 | Enable access to OTP regions using MTD_CHAR. | ||
179 | |||
175 | config MTD_BLKDEVS | 180 | config MTD_BLKDEVS |
176 | tristate "Common interface to block layer for MTD 'translation layers'" | 181 | tristate "Common interface to block layer for MTD 'translation layers'" |
177 | depends on BLOCK | 182 | depends on BLOCK |
diff --git a/drivers/mtd/chips/Kconfig b/drivers/mtd/chips/Kconfig index 479d32b57a1e..9408099eec48 100644 --- a/drivers/mtd/chips/Kconfig +++ b/drivers/mtd/chips/Kconfig | |||
@@ -6,6 +6,7 @@ menu "RAM/ROM/Flash chip drivers" | |||
6 | config MTD_CFI | 6 | config MTD_CFI |
7 | tristate "Detect flash chips by Common Flash Interface (CFI) probe" | 7 | tristate "Detect flash chips by Common Flash Interface (CFI) probe" |
8 | select MTD_GEN_PROBE | 8 | select MTD_GEN_PROBE |
9 | select MTD_CFI_UTIL | ||
9 | help | 10 | help |
10 | The Common Flash Interface specification was developed by Intel, | 11 | The Common Flash Interface specification was developed by Intel, |
11 | AMD and other flash manufactures that provides a universal method | 12 | AMD and other flash manufactures that provides a universal method |
@@ -154,6 +155,7 @@ config MTD_CFI_I8 | |||
154 | config MTD_OTP | 155 | config MTD_OTP |
155 | bool "Protection Registers aka one-time programmable (OTP) bits" | 156 | bool "Protection Registers aka one-time programmable (OTP) bits" |
156 | depends on MTD_CFI_ADV_OPTIONS | 157 | depends on MTD_CFI_ADV_OPTIONS |
158 | select HAVE_MTD_OTP | ||
157 | default n | 159 | default n |
158 | help | 160 | help |
159 | This enables support for reading, writing and locking so called | 161 | This enables support for reading, writing and locking so called |
@@ -187,7 +189,7 @@ config MTD_CFI_INTELEXT | |||
187 | StrataFlash and other parts. | 189 | StrataFlash and other parts. |
188 | 190 | ||
189 | config MTD_CFI_AMDSTD | 191 | config MTD_CFI_AMDSTD |
190 | tristate "Support for AMD/Fujitsu flash chips" | 192 | tristate "Support for AMD/Fujitsu/Spansion flash chips" |
191 | depends on MTD_GEN_PROBE | 193 | depends on MTD_GEN_PROBE |
192 | select MTD_CFI_UTIL | 194 | select MTD_CFI_UTIL |
193 | help | 195 | help |
diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c index 5f1b472137a0..c93a8be5d5f1 100644 --- a/drivers/mtd/chips/cfi_cmdset_0001.c +++ b/drivers/mtd/chips/cfi_cmdset_0001.c | |||
@@ -478,6 +478,28 @@ struct mtd_info *cfi_cmdset_0001(struct map_info *map, int primary) | |||
478 | else | 478 | else |
479 | cfi->chips[i].erase_time = 2000000; | 479 | cfi->chips[i].erase_time = 2000000; |
480 | 480 | ||
481 | if (cfi->cfiq->WordWriteTimeoutTyp && | ||
482 | cfi->cfiq->WordWriteTimeoutMax) | ||
483 | cfi->chips[i].word_write_time_max = | ||
484 | 1<<(cfi->cfiq->WordWriteTimeoutTyp + | ||
485 | cfi->cfiq->WordWriteTimeoutMax); | ||
486 | else | ||
487 | cfi->chips[i].word_write_time_max = 50000 * 8; | ||
488 | |||
489 | if (cfi->cfiq->BufWriteTimeoutTyp && | ||
490 | cfi->cfiq->BufWriteTimeoutMax) | ||
491 | cfi->chips[i].buffer_write_time_max = | ||
492 | 1<<(cfi->cfiq->BufWriteTimeoutTyp + | ||
493 | cfi->cfiq->BufWriteTimeoutMax); | ||
494 | |||
495 | if (cfi->cfiq->BlockEraseTimeoutTyp && | ||
496 | cfi->cfiq->BlockEraseTimeoutMax) | ||
497 | cfi->chips[i].erase_time_max = | ||
498 | 1000<<(cfi->cfiq->BlockEraseTimeoutTyp + | ||
499 | cfi->cfiq->BlockEraseTimeoutMax); | ||
500 | else | ||
501 | cfi->chips[i].erase_time_max = 2000000 * 8; | ||
502 | |||
481 | cfi->chips[i].ref_point_counter = 0; | 503 | cfi->chips[i].ref_point_counter = 0; |
482 | init_waitqueue_head(&(cfi->chips[i].wq)); | 504 | init_waitqueue_head(&(cfi->chips[i].wq)); |
483 | } | 505 | } |
@@ -703,6 +725,10 @@ static int chip_ready (struct map_info *map, struct flchip *chip, unsigned long | |||
703 | struct cfi_pri_intelext *cfip = cfi->cmdset_priv; | 725 | struct cfi_pri_intelext *cfip = cfi->cmdset_priv; |
704 | unsigned long timeo = jiffies + HZ; | 726 | unsigned long timeo = jiffies + HZ; |
705 | 727 | ||
728 | /* Prevent setting state FL_SYNCING for chip in suspended state. */ | ||
729 | if (mode == FL_SYNCING && chip->oldstate != FL_READY) | ||
730 | goto sleep; | ||
731 | |||
706 | switch (chip->state) { | 732 | switch (chip->state) { |
707 | 733 | ||
708 | case FL_STATUS: | 734 | case FL_STATUS: |
@@ -808,8 +834,9 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr | |||
808 | DECLARE_WAITQUEUE(wait, current); | 834 | DECLARE_WAITQUEUE(wait, current); |
809 | 835 | ||
810 | retry: | 836 | retry: |
811 | if (chip->priv && (mode == FL_WRITING || mode == FL_ERASING | 837 | if (chip->priv && |
812 | || mode == FL_OTP_WRITE || mode == FL_SHUTDOWN)) { | 838 | (mode == FL_WRITING || mode == FL_ERASING || mode == FL_OTP_WRITE |
839 | || mode == FL_SHUTDOWN) && chip->state != FL_SYNCING) { | ||
813 | /* | 840 | /* |
814 | * OK. We have possibility for contention on the write/erase | 841 | * OK. We have possibility for contention on the write/erase |
815 | * operations which are global to the real chip and not per | 842 | * operations which are global to the real chip and not per |
@@ -859,6 +886,14 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr | |||
859 | return ret; | 886 | return ret; |
860 | } | 887 | } |
861 | spin_lock(&shared->lock); | 888 | spin_lock(&shared->lock); |
889 | |||
890 | /* We should not own chip if it is already | ||
891 | * in FL_SYNCING state. Put contender and retry. */ | ||
892 | if (chip->state == FL_SYNCING) { | ||
893 | put_chip(map, contender, contender->start); | ||
894 | spin_unlock(contender->mutex); | ||
895 | goto retry; | ||
896 | } | ||
862 | spin_unlock(contender->mutex); | 897 | spin_unlock(contender->mutex); |
863 | } | 898 | } |
864 | 899 | ||
@@ -1012,7 +1047,7 @@ static void __xipram xip_enable(struct map_info *map, struct flchip *chip, | |||
1012 | 1047 | ||
1013 | static int __xipram xip_wait_for_operation( | 1048 | static int __xipram xip_wait_for_operation( |
1014 | struct map_info *map, struct flchip *chip, | 1049 | struct map_info *map, struct flchip *chip, |
1015 | unsigned long adr, unsigned int chip_op_time ) | 1050 | unsigned long adr, unsigned int chip_op_time_max) |
1016 | { | 1051 | { |
1017 | struct cfi_private *cfi = map->fldrv_priv; | 1052 | struct cfi_private *cfi = map->fldrv_priv; |
1018 | struct cfi_pri_intelext *cfip = cfi->cmdset_priv; | 1053 | struct cfi_pri_intelext *cfip = cfi->cmdset_priv; |
@@ -1021,7 +1056,7 @@ static int __xipram xip_wait_for_operation( | |||
1021 | flstate_t oldstate, newstate; | 1056 | flstate_t oldstate, newstate; |
1022 | 1057 | ||
1023 | start = xip_currtime(); | 1058 | start = xip_currtime(); |
1024 | usec = chip_op_time * 8; | 1059 | usec = chip_op_time_max; |
1025 | if (usec == 0) | 1060 | if (usec == 0) |
1026 | usec = 500000; | 1061 | usec = 500000; |
1027 | done = 0; | 1062 | done = 0; |
@@ -1131,8 +1166,8 @@ static int __xipram xip_wait_for_operation( | |||
1131 | #define XIP_INVAL_CACHED_RANGE(map, from, size) \ | 1166 | #define XIP_INVAL_CACHED_RANGE(map, from, size) \ |
1132 | INVALIDATE_CACHED_RANGE(map, from, size) | 1167 | INVALIDATE_CACHED_RANGE(map, from, size) |
1133 | 1168 | ||
1134 | #define INVAL_CACHE_AND_WAIT(map, chip, cmd_adr, inval_adr, inval_len, usec) \ | 1169 | #define INVAL_CACHE_AND_WAIT(map, chip, cmd_adr, inval_adr, inval_len, usec, usec_max) \ |
1135 | xip_wait_for_operation(map, chip, cmd_adr, usec) | 1170 | xip_wait_for_operation(map, chip, cmd_adr, usec_max) |
1136 | 1171 | ||
1137 | #else | 1172 | #else |
1138 | 1173 | ||
@@ -1144,7 +1179,7 @@ static int __xipram xip_wait_for_operation( | |||
1144 | static int inval_cache_and_wait_for_operation( | 1179 | static int inval_cache_and_wait_for_operation( |
1145 | struct map_info *map, struct flchip *chip, | 1180 | struct map_info *map, struct flchip *chip, |
1146 | unsigned long cmd_adr, unsigned long inval_adr, int inval_len, | 1181 | unsigned long cmd_adr, unsigned long inval_adr, int inval_len, |
1147 | unsigned int chip_op_time) | 1182 | unsigned int chip_op_time, unsigned int chip_op_time_max) |
1148 | { | 1183 | { |
1149 | struct cfi_private *cfi = map->fldrv_priv; | 1184 | struct cfi_private *cfi = map->fldrv_priv; |
1150 | map_word status, status_OK = CMD(0x80); | 1185 | map_word status, status_OK = CMD(0x80); |
@@ -1156,8 +1191,7 @@ static int inval_cache_and_wait_for_operation( | |||
1156 | INVALIDATE_CACHED_RANGE(map, inval_adr, inval_len); | 1191 | INVALIDATE_CACHED_RANGE(map, inval_adr, inval_len); |
1157 | spin_lock(chip->mutex); | 1192 | spin_lock(chip->mutex); |
1158 | 1193 | ||
1159 | /* set our timeout to 8 times the expected delay */ | 1194 | timeo = chip_op_time_max; |
1160 | timeo = chip_op_time * 8; | ||
1161 | if (!timeo) | 1195 | if (!timeo) |
1162 | timeo = 500000; | 1196 | timeo = 500000; |
1163 | reset_timeo = timeo; | 1197 | reset_timeo = timeo; |
@@ -1217,8 +1251,8 @@ static int inval_cache_and_wait_for_operation( | |||
1217 | 1251 | ||
1218 | #endif | 1252 | #endif |
1219 | 1253 | ||
1220 | #define WAIT_TIMEOUT(map, chip, adr, udelay) \ | 1254 | #define WAIT_TIMEOUT(map, chip, adr, udelay, udelay_max) \ |
1221 | INVAL_CACHE_AND_WAIT(map, chip, adr, 0, 0, udelay); | 1255 | INVAL_CACHE_AND_WAIT(map, chip, adr, 0, 0, udelay, udelay_max); |
1222 | 1256 | ||
1223 | 1257 | ||
1224 | static int do_point_onechip (struct map_info *map, struct flchip *chip, loff_t adr, size_t len) | 1258 | static int do_point_onechip (struct map_info *map, struct flchip *chip, loff_t adr, size_t len) |
@@ -1452,7 +1486,8 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip, | |||
1452 | 1486 | ||
1453 | ret = INVAL_CACHE_AND_WAIT(map, chip, adr, | 1487 | ret = INVAL_CACHE_AND_WAIT(map, chip, adr, |
1454 | adr, map_bankwidth(map), | 1488 | adr, map_bankwidth(map), |
1455 | chip->word_write_time); | 1489 | chip->word_write_time, |
1490 | chip->word_write_time_max); | ||
1456 | if (ret) { | 1491 | if (ret) { |
1457 | xip_enable(map, chip, adr); | 1492 | xip_enable(map, chip, adr); |
1458 | printk(KERN_ERR "%s: word write error (status timeout)\n", map->name); | 1493 | printk(KERN_ERR "%s: word write error (status timeout)\n", map->name); |
@@ -1623,7 +1658,7 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip, | |||
1623 | 1658 | ||
1624 | chip->state = FL_WRITING_TO_BUFFER; | 1659 | chip->state = FL_WRITING_TO_BUFFER; |
1625 | map_write(map, write_cmd, cmd_adr); | 1660 | map_write(map, write_cmd, cmd_adr); |
1626 | ret = WAIT_TIMEOUT(map, chip, cmd_adr, 0); | 1661 | ret = WAIT_TIMEOUT(map, chip, cmd_adr, 0, 0); |
1627 | if (ret) { | 1662 | if (ret) { |
1628 | /* Argh. Not ready for write to buffer */ | 1663 | /* Argh. Not ready for write to buffer */ |
1629 | map_word Xstatus = map_read(map, cmd_adr); | 1664 | map_word Xstatus = map_read(map, cmd_adr); |
@@ -1640,7 +1675,7 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip, | |||
1640 | 1675 | ||
1641 | /* Figure out the number of words to write */ | 1676 | /* Figure out the number of words to write */ |
1642 | word_gap = (-adr & (map_bankwidth(map)-1)); | 1677 | word_gap = (-adr & (map_bankwidth(map)-1)); |
1643 | words = (len - word_gap + map_bankwidth(map) - 1) / map_bankwidth(map); | 1678 | words = DIV_ROUND_UP(len - word_gap, map_bankwidth(map)); |
1644 | if (!word_gap) { | 1679 | if (!word_gap) { |
1645 | words--; | 1680 | words--; |
1646 | } else { | 1681 | } else { |
@@ -1692,7 +1727,8 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip, | |||
1692 | 1727 | ||
1693 | ret = INVAL_CACHE_AND_WAIT(map, chip, cmd_adr, | 1728 | ret = INVAL_CACHE_AND_WAIT(map, chip, cmd_adr, |
1694 | initial_adr, initial_len, | 1729 | initial_adr, initial_len, |
1695 | chip->buffer_write_time); | 1730 | chip->buffer_write_time, |
1731 | chip->buffer_write_time_max); | ||
1696 | if (ret) { | 1732 | if (ret) { |
1697 | map_write(map, CMD(0x70), cmd_adr); | 1733 | map_write(map, CMD(0x70), cmd_adr); |
1698 | chip->state = FL_STATUS; | 1734 | chip->state = FL_STATUS; |
@@ -1827,7 +1863,8 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip, | |||
1827 | 1863 | ||
1828 | ret = INVAL_CACHE_AND_WAIT(map, chip, adr, | 1864 | ret = INVAL_CACHE_AND_WAIT(map, chip, adr, |
1829 | adr, len, | 1865 | adr, len, |
1830 | chip->erase_time); | 1866 | chip->erase_time, |
1867 | chip->erase_time_max); | ||
1831 | if (ret) { | 1868 | if (ret) { |
1832 | map_write(map, CMD(0x70), adr); | 1869 | map_write(map, CMD(0x70), adr); |
1833 | chip->state = FL_STATUS; | 1870 | chip->state = FL_STATUS; |
@@ -2006,7 +2043,7 @@ static int __xipram do_xxlock_oneblock(struct map_info *map, struct flchip *chip | |||
2006 | */ | 2043 | */ |
2007 | udelay = (!extp || !(extp->FeatureSupport & (1 << 5))) ? 1000000/HZ : 0; | 2044 | udelay = (!extp || !(extp->FeatureSupport & (1 << 5))) ? 1000000/HZ : 0; |
2008 | 2045 | ||
2009 | ret = WAIT_TIMEOUT(map, chip, adr, udelay); | 2046 | ret = WAIT_TIMEOUT(map, chip, adr, udelay, udelay * 100); |
2010 | if (ret) { | 2047 | if (ret) { |
2011 | map_write(map, CMD(0x70), adr); | 2048 | map_write(map, CMD(0x70), adr); |
2012 | chip->state = FL_STATUS; | 2049 | chip->state = FL_STATUS; |
diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c index a972cc6be436..3e6f5d8609e8 100644 --- a/drivers/mtd/chips/cfi_cmdset_0002.c +++ b/drivers/mtd/chips/cfi_cmdset_0002.c | |||
@@ -13,6 +13,8 @@ | |||
13 | * XIP support hooks by Vitaly Wool (based on code for Intel flash | 13 | * XIP support hooks by Vitaly Wool (based on code for Intel flash |
14 | * by Nicolas Pitre) | 14 | * by Nicolas Pitre) |
15 | * | 15 | * |
16 | * 25/09/2008 Christopher Moore: TopBottom fixup for many Macronix with CFI V1.0 | ||
17 | * | ||
16 | * Occasionally maintained by Thayne Harbaugh tharbaugh at lnxi dot com | 18 | * Occasionally maintained by Thayne Harbaugh tharbaugh at lnxi dot com |
17 | * | 19 | * |
18 | * This code is GPL | 20 | * This code is GPL |
@@ -43,6 +45,7 @@ | |||
43 | 45 | ||
44 | #define MANUFACTURER_AMD 0x0001 | 46 | #define MANUFACTURER_AMD 0x0001 |
45 | #define MANUFACTURER_ATMEL 0x001F | 47 | #define MANUFACTURER_ATMEL 0x001F |
48 | #define MANUFACTURER_MACRONIX 0x00C2 | ||
46 | #define MANUFACTURER_SST 0x00BF | 49 | #define MANUFACTURER_SST 0x00BF |
47 | #define SST49LF004B 0x0060 | 50 | #define SST49LF004B 0x0060 |
48 | #define SST49LF040B 0x0050 | 51 | #define SST49LF040B 0x0050 |
@@ -144,12 +147,44 @@ static void fixup_amd_bootblock(struct mtd_info *mtd, void* param) | |||
144 | 147 | ||
145 | if (((major << 8) | minor) < 0x3131) { | 148 | if (((major << 8) | minor) < 0x3131) { |
146 | /* CFI version 1.0 => don't trust bootloc */ | 149 | /* CFI version 1.0 => don't trust bootloc */ |
150 | |||
151 | DEBUG(MTD_DEBUG_LEVEL1, | ||
152 | "%s: JEDEC Vendor ID is 0x%02X Device ID is 0x%02X\n", | ||
153 | map->name, cfi->mfr, cfi->id); | ||
154 | |||
155 | /* AFAICS all 29LV400 with a bottom boot block have a device ID | ||
156 | * of 0x22BA in 16-bit mode and 0xBA in 8-bit mode. | ||
157 | * These were badly detected as they have the 0x80 bit set | ||
158 | * so treat them as a special case. | ||
159 | */ | ||
160 | if (((cfi->id == 0xBA) || (cfi->id == 0x22BA)) && | ||
161 | |||
162 | /* Macronix added CFI to their 2nd generation | ||
163 | * MX29LV400C B/T but AFAICS no other 29LV400 (AMD, | ||
164 | * Fujitsu, Spansion, EON, ESI and older Macronix) | ||
165 | * has CFI. | ||
166 | * | ||
167 | * Therefore also check the manufacturer. | ||
168 | * This reduces the risk of false detection due to | ||
169 | * the 8-bit device ID. | ||
170 | */ | ||
171 | (cfi->mfr == MANUFACTURER_MACRONIX)) { | ||
172 | DEBUG(MTD_DEBUG_LEVEL1, | ||
173 | "%s: Macronix MX29LV400C with bottom boot block" | ||
174 | " detected\n", map->name); | ||
175 | extp->TopBottom = 2; /* bottom boot */ | ||
176 | } else | ||
147 | if (cfi->id & 0x80) { | 177 | if (cfi->id & 0x80) { |
148 | printk(KERN_WARNING "%s: JEDEC Device ID is 0x%02X. Assuming broken CFI table.\n", map->name, cfi->id); | 178 | printk(KERN_WARNING "%s: JEDEC Device ID is 0x%02X. Assuming broken CFI table.\n", map->name, cfi->id); |
149 | extp->TopBottom = 3; /* top boot */ | 179 | extp->TopBottom = 3; /* top boot */ |
150 | } else { | 180 | } else { |
151 | extp->TopBottom = 2; /* bottom boot */ | 181 | extp->TopBottom = 2; /* bottom boot */ |
152 | } | 182 | } |
183 | |||
184 | DEBUG(MTD_DEBUG_LEVEL1, | ||
185 | "%s: AMD CFI PRI V%c.%c has no boot block field;" | ||
186 | " deduced %s from Device ID\n", map->name, major, minor, | ||
187 | extp->TopBottom == 2 ? "bottom" : "top"); | ||
153 | } | 188 | } |
154 | } | 189 | } |
155 | #endif | 190 | #endif |
@@ -178,10 +213,18 @@ static void fixup_convert_atmel_pri(struct mtd_info *mtd, void *param) | |||
178 | if (atmel_pri.Features & 0x02) | 213 | if (atmel_pri.Features & 0x02) |
179 | extp->EraseSuspend = 2; | 214 | extp->EraseSuspend = 2; |
180 | 215 | ||
181 | if (atmel_pri.BottomBoot) | 216 | /* Some chips got it backwards... */ |
182 | extp->TopBottom = 2; | 217 | if (cfi->id == AT49BV6416) { |
183 | else | 218 | if (atmel_pri.BottomBoot) |
184 | extp->TopBottom = 3; | 219 | extp->TopBottom = 3; |
220 | else | ||
221 | extp->TopBottom = 2; | ||
222 | } else { | ||
223 | if (atmel_pri.BottomBoot) | ||
224 | extp->TopBottom = 2; | ||
225 | else | ||
226 | extp->TopBottom = 3; | ||
227 | } | ||
185 | 228 | ||
186 | /* burst write mode not supported */ | 229 | /* burst write mode not supported */ |
187 | cfi->cfiq->BufWriteTimeoutTyp = 0; | 230 | cfi->cfiq->BufWriteTimeoutTyp = 0; |
@@ -243,6 +286,7 @@ static struct cfi_fixup cfi_fixup_table[] = { | |||
243 | { CFI_MFR_ATMEL, CFI_ID_ANY, fixup_convert_atmel_pri, NULL }, | 286 | { CFI_MFR_ATMEL, CFI_ID_ANY, fixup_convert_atmel_pri, NULL }, |
244 | #ifdef AMD_BOOTLOC_BUG | 287 | #ifdef AMD_BOOTLOC_BUG |
245 | { CFI_MFR_AMD, CFI_ID_ANY, fixup_amd_bootblock, NULL }, | 288 | { CFI_MFR_AMD, CFI_ID_ANY, fixup_amd_bootblock, NULL }, |
289 | { MANUFACTURER_MACRONIX, CFI_ID_ANY, fixup_amd_bootblock, NULL }, | ||
246 | #endif | 290 | #endif |
247 | { CFI_MFR_AMD, 0x0050, fixup_use_secsi, NULL, }, | 291 | { CFI_MFR_AMD, 0x0050, fixup_use_secsi, NULL, }, |
248 | { CFI_MFR_AMD, 0x0053, fixup_use_secsi, NULL, }, | 292 | { CFI_MFR_AMD, 0x0053, fixup_use_secsi, NULL, }, |
diff --git a/drivers/mtd/chips/cfi_probe.c b/drivers/mtd/chips/cfi_probe.c index c418e92e1d92..e63e6749429a 100644 --- a/drivers/mtd/chips/cfi_probe.c +++ b/drivers/mtd/chips/cfi_probe.c | |||
@@ -44,17 +44,14 @@ do { \ | |||
44 | 44 | ||
45 | #define xip_enable(base, map, cfi) \ | 45 | #define xip_enable(base, map, cfi) \ |
46 | do { \ | 46 | do { \ |
47 | cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL); \ | 47 | cfi_qry_mode_off(base, map, cfi); \ |
48 | cfi_send_gen_cmd(0xFF, 0, base, map, cfi, cfi->device_type, NULL); \ | ||
49 | xip_allowed(base, map); \ | 48 | xip_allowed(base, map); \ |
50 | } while (0) | 49 | } while (0) |
51 | 50 | ||
52 | #define xip_disable_qry(base, map, cfi) \ | 51 | #define xip_disable_qry(base, map, cfi) \ |
53 | do { \ | 52 | do { \ |
54 | xip_disable(); \ | 53 | xip_disable(); \ |
55 | cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL); \ | 54 | cfi_qry_mode_on(base, map, cfi); \ |
56 | cfi_send_gen_cmd(0xFF, 0, base, map, cfi, cfi->device_type, NULL); \ | ||
57 | cfi_send_gen_cmd(0x98, 0x55, base, map, cfi, cfi->device_type, NULL); \ | ||
58 | } while (0) | 55 | } while (0) |
59 | 56 | ||
60 | #else | 57 | #else |
@@ -70,32 +67,6 @@ do { \ | |||
70 | in: interleave,type,mode | 67 | in: interleave,type,mode |
71 | ret: table index, <0 for error | 68 | ret: table index, <0 for error |
72 | */ | 69 | */ |
73 | static int __xipram qry_present(struct map_info *map, __u32 base, | ||
74 | struct cfi_private *cfi) | ||
75 | { | ||
76 | int osf = cfi->interleave * cfi->device_type; // scale factor | ||
77 | map_word val[3]; | ||
78 | map_word qry[3]; | ||
79 | |||
80 | qry[0] = cfi_build_cmd('Q', map, cfi); | ||
81 | qry[1] = cfi_build_cmd('R', map, cfi); | ||
82 | qry[2] = cfi_build_cmd('Y', map, cfi); | ||
83 | |||
84 | val[0] = map_read(map, base + osf*0x10); | ||
85 | val[1] = map_read(map, base + osf*0x11); | ||
86 | val[2] = map_read(map, base + osf*0x12); | ||
87 | |||
88 | if (!map_word_equal(map, qry[0], val[0])) | ||
89 | return 0; | ||
90 | |||
91 | if (!map_word_equal(map, qry[1], val[1])) | ||
92 | return 0; | ||
93 | |||
94 | if (!map_word_equal(map, qry[2], val[2])) | ||
95 | return 0; | ||
96 | |||
97 | return 1; // "QRY" found | ||
98 | } | ||
99 | 70 | ||
100 | static int __xipram cfi_probe_chip(struct map_info *map, __u32 base, | 71 | static int __xipram cfi_probe_chip(struct map_info *map, __u32 base, |
101 | unsigned long *chip_map, struct cfi_private *cfi) | 72 | unsigned long *chip_map, struct cfi_private *cfi) |
@@ -116,11 +87,7 @@ static int __xipram cfi_probe_chip(struct map_info *map, __u32 base, | |||
116 | } | 87 | } |
117 | 88 | ||
118 | xip_disable(); | 89 | xip_disable(); |
119 | cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL); | 90 | if (!cfi_qry_mode_on(base, map, cfi)) { |
120 | cfi_send_gen_cmd(0xFF, 0, base, map, cfi, cfi->device_type, NULL); | ||
121 | cfi_send_gen_cmd(0x98, 0x55, base, map, cfi, cfi->device_type, NULL); | ||
122 | |||
123 | if (!qry_present(map,base,cfi)) { | ||
124 | xip_enable(base, map, cfi); | 91 | xip_enable(base, map, cfi); |
125 | return 0; | 92 | return 0; |
126 | } | 93 | } |
@@ -141,14 +108,13 @@ static int __xipram cfi_probe_chip(struct map_info *map, __u32 base, | |||
141 | start = i << cfi->chipshift; | 108 | start = i << cfi->chipshift; |
142 | /* This chip should be in read mode if it's one | 109 | /* This chip should be in read mode if it's one |
143 | we've already touched. */ | 110 | we've already touched. */ |
144 | if (qry_present(map, start, cfi)) { | 111 | if (cfi_qry_present(map, start, cfi)) { |
145 | /* Eep. This chip also had the QRY marker. | 112 | /* Eep. This chip also had the QRY marker. |
146 | * Is it an alias for the new one? */ | 113 | * Is it an alias for the new one? */ |
147 | cfi_send_gen_cmd(0xF0, 0, start, map, cfi, cfi->device_type, NULL); | 114 | cfi_qry_mode_off(start, map, cfi); |
148 | cfi_send_gen_cmd(0xFF, 0, start, map, cfi, cfi->device_type, NULL); | ||
149 | 115 | ||
150 | /* If the QRY marker goes away, it's an alias */ | 116 | /* If the QRY marker goes away, it's an alias */ |
151 | if (!qry_present(map, start, cfi)) { | 117 | if (!cfi_qry_present(map, start, cfi)) { |
152 | xip_allowed(base, map); | 118 | xip_allowed(base, map); |
153 | printk(KERN_DEBUG "%s: Found an alias at 0x%x for the chip at 0x%lx\n", | 119 | printk(KERN_DEBUG "%s: Found an alias at 0x%x for the chip at 0x%lx\n", |
154 | map->name, base, start); | 120 | map->name, base, start); |
@@ -158,10 +124,9 @@ static int __xipram cfi_probe_chip(struct map_info *map, __u32 base, | |||
158 | * unfortunate. Stick the new chip in read mode | 124 | * unfortunate. Stick the new chip in read mode |
159 | * too and if it's the same, assume it's an alias. */ | 125 | * too and if it's the same, assume it's an alias. */ |
160 | /* FIXME: Use other modes to do a proper check */ | 126 | /* FIXME: Use other modes to do a proper check */ |
161 | cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL); | 127 | cfi_qry_mode_off(base, map, cfi); |
162 | cfi_send_gen_cmd(0xFF, 0, start, map, cfi, cfi->device_type, NULL); | ||
163 | 128 | ||
164 | if (qry_present(map, base, cfi)) { | 129 | if (cfi_qry_present(map, base, cfi)) { |
165 | xip_allowed(base, map); | 130 | xip_allowed(base, map); |
166 | printk(KERN_DEBUG "%s: Found an alias at 0x%x for the chip at 0x%lx\n", | 131 | printk(KERN_DEBUG "%s: Found an alias at 0x%x for the chip at 0x%lx\n", |
167 | map->name, base, start); | 132 | map->name, base, start); |
@@ -176,8 +141,7 @@ static int __xipram cfi_probe_chip(struct map_info *map, __u32 base, | |||
176 | cfi->numchips++; | 141 | cfi->numchips++; |
177 | 142 | ||
178 | /* Put it back into Read Mode */ | 143 | /* Put it back into Read Mode */ |
179 | cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL); | 144 | cfi_qry_mode_off(base, map, cfi); |
180 | cfi_send_gen_cmd(0xFF, 0, base, map, cfi, cfi->device_type, NULL); | ||
181 | xip_allowed(base, map); | 145 | xip_allowed(base, map); |
182 | 146 | ||
183 | printk(KERN_INFO "%s: Found %d x%d devices at 0x%x in %d-bit bank\n", | 147 | printk(KERN_INFO "%s: Found %d x%d devices at 0x%x in %d-bit bank\n", |
@@ -237,9 +201,7 @@ static int __xipram cfi_chip_setup(struct map_info *map, | |||
237 | cfi_read_query(map, base + 0xf * ofs_factor); | 201 | cfi_read_query(map, base + 0xf * ofs_factor); |
238 | 202 | ||
239 | /* Put it back into Read Mode */ | 203 | /* Put it back into Read Mode */ |
240 | cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL); | 204 | cfi_qry_mode_off(base, map, cfi); |
241 | /* ... even if it's an Intel chip */ | ||
242 | cfi_send_gen_cmd(0xFF, 0, base, map, cfi, cfi->device_type, NULL); | ||
243 | xip_allowed(base, map); | 205 | xip_allowed(base, map); |
244 | 206 | ||
245 | /* Do any necessary byteswapping */ | 207 | /* Do any necessary byteswapping */ |
diff --git a/drivers/mtd/chips/cfi_util.c b/drivers/mtd/chips/cfi_util.c index 0ee457018016..34d40e25d312 100644 --- a/drivers/mtd/chips/cfi_util.c +++ b/drivers/mtd/chips/cfi_util.c | |||
@@ -24,6 +24,66 @@ | |||
24 | #include <linux/mtd/cfi.h> | 24 | #include <linux/mtd/cfi.h> |
25 | #include <linux/mtd/compatmac.h> | 25 | #include <linux/mtd/compatmac.h> |
26 | 26 | ||
27 | int __xipram cfi_qry_present(struct map_info *map, __u32 base, | ||
28 | struct cfi_private *cfi) | ||
29 | { | ||
30 | int osf = cfi->interleave * cfi->device_type; /* scale factor */ | ||
31 | map_word val[3]; | ||
32 | map_word qry[3]; | ||
33 | |||
34 | qry[0] = cfi_build_cmd('Q', map, cfi); | ||
35 | qry[1] = cfi_build_cmd('R', map, cfi); | ||
36 | qry[2] = cfi_build_cmd('Y', map, cfi); | ||
37 | |||
38 | val[0] = map_read(map, base + osf*0x10); | ||
39 | val[1] = map_read(map, base + osf*0x11); | ||
40 | val[2] = map_read(map, base + osf*0x12); | ||
41 | |||
42 | if (!map_word_equal(map, qry[0], val[0])) | ||
43 | return 0; | ||
44 | |||
45 | if (!map_word_equal(map, qry[1], val[1])) | ||
46 | return 0; | ||
47 | |||
48 | if (!map_word_equal(map, qry[2], val[2])) | ||
49 | return 0; | ||
50 | |||
51 | return 1; /* "QRY" found */ | ||
52 | } | ||
53 | EXPORT_SYMBOL_GPL(cfi_qry_present); | ||
54 | |||
55 | int __xipram cfi_qry_mode_on(uint32_t base, struct map_info *map, | ||
56 | struct cfi_private *cfi) | ||
57 | { | ||
58 | cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL); | ||
59 | cfi_send_gen_cmd(0x98, 0x55, base, map, cfi, cfi->device_type, NULL); | ||
60 | if (cfi_qry_present(map, base, cfi)) | ||
61 | return 1; | ||
62 | /* QRY not found probably we deal with some odd CFI chips */ | ||
63 | /* Some revisions of some old Intel chips? */ | ||
64 | cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL); | ||
65 | cfi_send_gen_cmd(0xFF, 0, base, map, cfi, cfi->device_type, NULL); | ||
66 | cfi_send_gen_cmd(0x98, 0x55, base, map, cfi, cfi->device_type, NULL); | ||
67 | if (cfi_qry_present(map, base, cfi)) | ||
68 | return 1; | ||
69 | /* ST M29DW chips */ | ||
70 | cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL); | ||
71 | cfi_send_gen_cmd(0x98, 0x555, base, map, cfi, cfi->device_type, NULL); | ||
72 | if (cfi_qry_present(map, base, cfi)) | ||
73 | return 1; | ||
74 | /* QRY not found */ | ||
75 | return 0; | ||
76 | } | ||
77 | EXPORT_SYMBOL_GPL(cfi_qry_mode_on); | ||
78 | |||
79 | void __xipram cfi_qry_mode_off(uint32_t base, struct map_info *map, | ||
80 | struct cfi_private *cfi) | ||
81 | { | ||
82 | cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL); | ||
83 | cfi_send_gen_cmd(0xFF, 0, base, map, cfi, cfi->device_type, NULL); | ||
84 | } | ||
85 | EXPORT_SYMBOL_GPL(cfi_qry_mode_off); | ||
86 | |||
27 | struct cfi_extquery * | 87 | struct cfi_extquery * |
28 | __xipram cfi_read_pri(struct map_info *map, __u16 adr, __u16 size, const char* name) | 88 | __xipram cfi_read_pri(struct map_info *map, __u16 adr, __u16 size, const char* name) |
29 | { | 89 | { |
@@ -48,8 +108,7 @@ __xipram cfi_read_pri(struct map_info *map, __u16 adr, __u16 size, const char* n | |||
48 | #endif | 108 | #endif |
49 | 109 | ||
50 | /* Switch it into Query Mode */ | 110 | /* Switch it into Query Mode */ |
51 | cfi_send_gen_cmd(0x98, 0x55, base, map, cfi, cfi->device_type, NULL); | 111 | cfi_qry_mode_on(base, map, cfi); |
52 | |||
53 | /* Read in the Extended Query Table */ | 112 | /* Read in the Extended Query Table */ |
54 | for (i=0; i<size; i++) { | 113 | for (i=0; i<size; i++) { |
55 | ((unsigned char *)extp)[i] = | 114 | ((unsigned char *)extp)[i] = |
@@ -57,8 +116,7 @@ __xipram cfi_read_pri(struct map_info *map, __u16 adr, __u16 size, const char* n | |||
57 | } | 116 | } |
58 | 117 | ||
59 | /* Make sure it returns to read mode */ | 118 | /* Make sure it returns to read mode */ |
60 | cfi_send_gen_cmd(0xf0, 0, base, map, cfi, cfi->device_type, NULL); | 119 | cfi_qry_mode_off(base, map, cfi); |
61 | cfi_send_gen_cmd(0xff, 0, base, map, cfi, cfi->device_type, NULL); | ||
62 | 120 | ||
63 | #ifdef CONFIG_MTD_XIP | 121 | #ifdef CONFIG_MTD_XIP |
64 | (void) map_read(map, base); | 122 | (void) map_read(map, base); |
diff --git a/drivers/mtd/chips/gen_probe.c b/drivers/mtd/chips/gen_probe.c index f061885b2812..e2dc96441e05 100644 --- a/drivers/mtd/chips/gen_probe.c +++ b/drivers/mtd/chips/gen_probe.c | |||
@@ -111,7 +111,7 @@ static struct cfi_private *genprobe_ident_chips(struct map_info *map, struct chi | |||
111 | max_chips = 1; | 111 | max_chips = 1; |
112 | } | 112 | } |
113 | 113 | ||
114 | mapsize = sizeof(long) * ( (max_chips + BITS_PER_LONG-1) / BITS_PER_LONG ); | 114 | mapsize = sizeof(long) * DIV_ROUND_UP(max_chips, BITS_PER_LONG); |
115 | chip_map = kzalloc(mapsize, GFP_KERNEL); | 115 | chip_map = kzalloc(mapsize, GFP_KERNEL); |
116 | if (!chip_map) { | 116 | if (!chip_map) { |
117 | printk(KERN_WARNING "%s: kmalloc failed for CFI chip map\n", map->name); | 117 | printk(KERN_WARNING "%s: kmalloc failed for CFI chip map\n", map->name); |
diff --git a/drivers/mtd/cmdlinepart.c b/drivers/mtd/cmdlinepart.c index 71bc07f149b7..50a340388e74 100644 --- a/drivers/mtd/cmdlinepart.c +++ b/drivers/mtd/cmdlinepart.c | |||
@@ -7,6 +7,7 @@ | |||
7 | * | 7 | * |
8 | * mtdparts=<mtddef>[;<mtddef] | 8 | * mtdparts=<mtddef>[;<mtddef] |
9 | * <mtddef> := <mtd-id>:<partdef>[,<partdef>] | 9 | * <mtddef> := <mtd-id>:<partdef>[,<partdef>] |
10 | * where <mtd-id> is the name from the "cat /proc/mtd" command | ||
10 | * <partdef> := <size>[@offset][<name>][ro][lk] | 11 | * <partdef> := <size>[@offset][<name>][ro][lk] |
11 | * <mtd-id> := unique name used in mapping driver/device (mtd->name) | 12 | * <mtd-id> := unique name used in mapping driver/device (mtd->name) |
12 | * <size> := standard linux memsize OR "-" to denote all remaining space | 13 | * <size> := standard linux memsize OR "-" to denote all remaining space |
diff --git a/drivers/mtd/devices/Kconfig b/drivers/mtd/devices/Kconfig index 9c613f06623c..6fde0a2e3567 100644 --- a/drivers/mtd/devices/Kconfig +++ b/drivers/mtd/devices/Kconfig | |||
@@ -59,6 +59,27 @@ config MTD_DATAFLASH | |||
59 | Sometimes DataFlash chips are packaged inside MMC-format | 59 | Sometimes DataFlash chips are packaged inside MMC-format |
60 | cards; at this writing, the MMC stack won't handle those. | 60 | cards; at this writing, the MMC stack won't handle those. |
61 | 61 | ||
62 | config MTD_DATAFLASH_WRITE_VERIFY | ||
63 | bool "Verify DataFlash page writes" | ||
64 | depends on MTD_DATAFLASH | ||
65 | help | ||
66 | This adds an extra check when data is written to the flash. | ||
67 | It may help if you are verifying chip setup (timings etc) on | ||
68 | your board. There is a rare possibility that even though the | ||
69 | device thinks the write was successful, a bit could have been | ||
70 | flipped accidentally due to device wear or something else. | ||
71 | |||
72 | config MTD_DATAFLASH_OTP | ||
73 | bool "DataFlash OTP support (Security Register)" | ||
74 | depends on MTD_DATAFLASH | ||
75 | select HAVE_MTD_OTP | ||
76 | help | ||
77 | Newer DataFlash chips (revisions C and D) support 128 bytes of | ||
78 | one-time-programmable (OTP) data. The first half may be written | ||
79 | (once) with up to 64 bytes of data, such as a serial number or | ||
80 | other key product data. The second half is programmed with a | ||
81 | unique-to-each-chip bit pattern at the factory. | ||
82 | |||
62 | config MTD_M25P80 | 83 | config MTD_M25P80 |
63 | tristate "Support most SPI Flash chips (AT26DF, M25P, W25X, ...)" | 84 | tristate "Support most SPI Flash chips (AT26DF, M25P, W25X, ...)" |
64 | depends on SPI_MASTER && EXPERIMENTAL | 85 | depends on SPI_MASTER && EXPERIMENTAL |
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c index b35c3333e210..76a76751da36 100644 --- a/drivers/mtd/devices/m25p80.c +++ b/drivers/mtd/devices/m25p80.c | |||
@@ -39,6 +39,7 @@ | |||
39 | #define OPCODE_PP 0x02 /* Page program (up to 256 bytes) */ | 39 | #define OPCODE_PP 0x02 /* Page program (up to 256 bytes) */ |
40 | #define OPCODE_BE_4K 0x20 /* Erase 4KiB block */ | 40 | #define OPCODE_BE_4K 0x20 /* Erase 4KiB block */ |
41 | #define OPCODE_BE_32K 0x52 /* Erase 32KiB block */ | 41 | #define OPCODE_BE_32K 0x52 /* Erase 32KiB block */ |
42 | #define OPCODE_BE 0xc7 /* Erase whole flash block */ | ||
42 | #define OPCODE_SE 0xd8 /* Sector erase (usually 64KiB) */ | 43 | #define OPCODE_SE 0xd8 /* Sector erase (usually 64KiB) */ |
43 | #define OPCODE_RDID 0x9f /* Read JEDEC ID */ | 44 | #define OPCODE_RDID 0x9f /* Read JEDEC ID */ |
44 | 45 | ||
@@ -161,6 +162,31 @@ static int wait_till_ready(struct m25p *flash) | |||
161 | return 1; | 162 | return 1; |
162 | } | 163 | } |
163 | 164 | ||
165 | /* | ||
166 | * Erase the whole flash memory | ||
167 | * | ||
168 | * Returns 0 if successful, non-zero otherwise. | ||
169 | */ | ||
170 | static int erase_block(struct m25p *flash) | ||
171 | { | ||
172 | DEBUG(MTD_DEBUG_LEVEL3, "%s: %s %dKiB\n", | ||
173 | flash->spi->dev.bus_id, __func__, | ||
174 | flash->mtd.size / 1024); | ||
175 | |||
176 | /* Wait until finished previous write command. */ | ||
177 | if (wait_till_ready(flash)) | ||
178 | return 1; | ||
179 | |||
180 | /* Send write enable, then erase commands. */ | ||
181 | write_enable(flash); | ||
182 | |||
183 | /* Set up command buffer. */ | ||
184 | flash->command[0] = OPCODE_BE; | ||
185 | |||
186 | spi_write(flash->spi, flash->command, 1); | ||
187 | |||
188 | return 0; | ||
189 | } | ||
164 | 190 | ||
165 | /* | 191 | /* |
166 | * Erase one sector of flash memory at offset ``offset'' which is any | 192 | * Erase one sector of flash memory at offset ``offset'' which is any |
@@ -229,15 +255,21 @@ static int m25p80_erase(struct mtd_info *mtd, struct erase_info *instr) | |||
229 | */ | 255 | */ |
230 | 256 | ||
231 | /* now erase those sectors */ | 257 | /* now erase those sectors */ |
232 | while (len) { | 258 | if (len == flash->mtd.size && erase_block(flash)) { |
233 | if (erase_sector(flash, addr)) { | 259 | instr->state = MTD_ERASE_FAILED; |
234 | instr->state = MTD_ERASE_FAILED; | 260 | mutex_unlock(&flash->lock); |
235 | mutex_unlock(&flash->lock); | 261 | return -EIO; |
236 | return -EIO; | 262 | } else { |
237 | } | 263 | while (len) { |
264 | if (erase_sector(flash, addr)) { | ||
265 | instr->state = MTD_ERASE_FAILED; | ||
266 | mutex_unlock(&flash->lock); | ||
267 | return -EIO; | ||
268 | } | ||
238 | 269 | ||
239 | addr += mtd->erasesize; | 270 | addr += mtd->erasesize; |
240 | len -= mtd->erasesize; | 271 | len -= mtd->erasesize; |
272 | } | ||
241 | } | 273 | } |
242 | 274 | ||
243 | mutex_unlock(&flash->lock); | 275 | mutex_unlock(&flash->lock); |
@@ -437,6 +469,7 @@ struct flash_info { | |||
437 | * then a two byte device id. | 469 | * then a two byte device id. |
438 | */ | 470 | */ |
439 | u32 jedec_id; | 471 | u32 jedec_id; |
472 | u16 ext_id; | ||
440 | 473 | ||
441 | /* The size listed here is what works with OPCODE_SE, which isn't | 474 | /* The size listed here is what works with OPCODE_SE, which isn't |
442 | * necessarily called a "sector" by the vendor. | 475 | * necessarily called a "sector" by the vendor. |
@@ -456,72 +489,75 @@ struct flash_info { | |||
456 | static struct flash_info __devinitdata m25p_data [] = { | 489 | static struct flash_info __devinitdata m25p_data [] = { |
457 | 490 | ||
458 | /* Atmel -- some are (confusingly) marketed as "DataFlash" */ | 491 | /* Atmel -- some are (confusingly) marketed as "DataFlash" */ |
459 | { "at25fs010", 0x1f6601, 32 * 1024, 4, SECT_4K, }, | 492 | { "at25fs010", 0x1f6601, 0, 32 * 1024, 4, SECT_4K, }, |
460 | { "at25fs040", 0x1f6604, 64 * 1024, 8, SECT_4K, }, | 493 | { "at25fs040", 0x1f6604, 0, 64 * 1024, 8, SECT_4K, }, |
461 | 494 | ||
462 | { "at25df041a", 0x1f4401, 64 * 1024, 8, SECT_4K, }, | 495 | { "at25df041a", 0x1f4401, 0, 64 * 1024, 8, SECT_4K, }, |
463 | { "at25df641", 0x1f4800, 64 * 1024, 128, SECT_4K, }, | 496 | { "at25df641", 0x1f4800, 0, 64 * 1024, 128, SECT_4K, }, |
464 | 497 | ||
465 | { "at26f004", 0x1f0400, 64 * 1024, 8, SECT_4K, }, | 498 | { "at26f004", 0x1f0400, 0, 64 * 1024, 8, SECT_4K, }, |
466 | { "at26df081a", 0x1f4501, 64 * 1024, 16, SECT_4K, }, | 499 | { "at26df081a", 0x1f4501, 0, 64 * 1024, 16, SECT_4K, }, |
467 | { "at26df161a", 0x1f4601, 64 * 1024, 32, SECT_4K, }, | 500 | { "at26df161a", 0x1f4601, 0, 64 * 1024, 32, SECT_4K, }, |
468 | { "at26df321", 0x1f4701, 64 * 1024, 64, SECT_4K, }, | 501 | { "at26df321", 0x1f4701, 0, 64 * 1024, 64, SECT_4K, }, |
469 | 502 | ||
470 | /* Spansion -- single (large) sector size only, at least | 503 | /* Spansion -- single (large) sector size only, at least |
471 | * for the chips listed here (without boot sectors). | 504 | * for the chips listed here (without boot sectors). |
472 | */ | 505 | */ |
473 | { "s25sl004a", 0x010212, 64 * 1024, 8, }, | 506 | { "s25sl004a", 0x010212, 0, 64 * 1024, 8, }, |
474 | { "s25sl008a", 0x010213, 64 * 1024, 16, }, | 507 | { "s25sl008a", 0x010213, 0, 64 * 1024, 16, }, |
475 | { "s25sl016a", 0x010214, 64 * 1024, 32, }, | 508 | { "s25sl016a", 0x010214, 0, 64 * 1024, 32, }, |
476 | { "s25sl032a", 0x010215, 64 * 1024, 64, }, | 509 | { "s25sl032a", 0x010215, 0, 64 * 1024, 64, }, |
477 | { "s25sl064a", 0x010216, 64 * 1024, 128, }, | 510 | { "s25sl064a", 0x010216, 0, 64 * 1024, 128, }, |
511 | { "s25sl12800", 0x012018, 0x0300, 256 * 1024, 64, }, | ||
512 | { "s25sl12801", 0x012018, 0x0301, 64 * 1024, 256, }, | ||
478 | 513 | ||
479 | /* SST -- large erase sizes are "overlays", "sectors" are 4K */ | 514 | /* SST -- large erase sizes are "overlays", "sectors" are 4K */ |
480 | { "sst25vf040b", 0xbf258d, 64 * 1024, 8, SECT_4K, }, | 515 | { "sst25vf040b", 0xbf258d, 0, 64 * 1024, 8, SECT_4K, }, |
481 | { "sst25vf080b", 0xbf258e, 64 * 1024, 16, SECT_4K, }, | 516 | { "sst25vf080b", 0xbf258e, 0, 64 * 1024, 16, SECT_4K, }, |
482 | { "sst25vf016b", 0xbf2541, 64 * 1024, 32, SECT_4K, }, | 517 | { "sst25vf016b", 0xbf2541, 0, 64 * 1024, 32, SECT_4K, }, |
483 | { "sst25vf032b", 0xbf254a, 64 * 1024, 64, SECT_4K, }, | 518 | { "sst25vf032b", 0xbf254a, 0, 64 * 1024, 64, SECT_4K, }, |
484 | 519 | ||
485 | /* ST Microelectronics -- newer production may have feature updates */ | 520 | /* ST Microelectronics -- newer production may have feature updates */ |
486 | { "m25p05", 0x202010, 32 * 1024, 2, }, | 521 | { "m25p05", 0x202010, 0, 32 * 1024, 2, }, |
487 | { "m25p10", 0x202011, 32 * 1024, 4, }, | 522 | { "m25p10", 0x202011, 0, 32 * 1024, 4, }, |
488 | { "m25p20", 0x202012, 64 * 1024, 4, }, | 523 | { "m25p20", 0x202012, 0, 64 * 1024, 4, }, |
489 | { "m25p40", 0x202013, 64 * 1024, 8, }, | 524 | { "m25p40", 0x202013, 0, 64 * 1024, 8, }, |
490 | { "m25p80", 0, 64 * 1024, 16, }, | 525 | { "m25p80", 0, 0, 64 * 1024, 16, }, |
491 | { "m25p16", 0x202015, 64 * 1024, 32, }, | 526 | { "m25p16", 0x202015, 0, 64 * 1024, 32, }, |
492 | { "m25p32", 0x202016, 64 * 1024, 64, }, | 527 | { "m25p32", 0x202016, 0, 64 * 1024, 64, }, |
493 | { "m25p64", 0x202017, 64 * 1024, 128, }, | 528 | { "m25p64", 0x202017, 0, 64 * 1024, 128, }, |
494 | { "m25p128", 0x202018, 256 * 1024, 64, }, | 529 | { "m25p128", 0x202018, 0, 256 * 1024, 64, }, |
495 | 530 | ||
496 | { "m45pe80", 0x204014, 64 * 1024, 16, }, | 531 | { "m45pe80", 0x204014, 0, 64 * 1024, 16, }, |
497 | { "m45pe16", 0x204015, 64 * 1024, 32, }, | 532 | { "m45pe16", 0x204015, 0, 64 * 1024, 32, }, |
498 | 533 | ||
499 | { "m25pe80", 0x208014, 64 * 1024, 16, }, | 534 | { "m25pe80", 0x208014, 0, 64 * 1024, 16, }, |
500 | { "m25pe16", 0x208015, 64 * 1024, 32, SECT_4K, }, | 535 | { "m25pe16", 0x208015, 0, 64 * 1024, 32, SECT_4K, }, |
501 | 536 | ||
502 | /* Winbond -- w25x "blocks" are 64K, "sectors" are 4KiB */ | 537 | /* Winbond -- w25x "blocks" are 64K, "sectors" are 4KiB */ |
503 | { "w25x10", 0xef3011, 64 * 1024, 2, SECT_4K, }, | 538 | { "w25x10", 0xef3011, 0, 64 * 1024, 2, SECT_4K, }, |
504 | { "w25x20", 0xef3012, 64 * 1024, 4, SECT_4K, }, | 539 | { "w25x20", 0xef3012, 0, 64 * 1024, 4, SECT_4K, }, |
505 | { "w25x40", 0xef3013, 64 * 1024, 8, SECT_4K, }, | 540 | { "w25x40", 0xef3013, 0, 64 * 1024, 8, SECT_4K, }, |
506 | { "w25x80", 0xef3014, 64 * 1024, 16, SECT_4K, }, | 541 | { "w25x80", 0xef3014, 0, 64 * 1024, 16, SECT_4K, }, |
507 | { "w25x16", 0xef3015, 64 * 1024, 32, SECT_4K, }, | 542 | { "w25x16", 0xef3015, 0, 64 * 1024, 32, SECT_4K, }, |
508 | { "w25x32", 0xef3016, 64 * 1024, 64, SECT_4K, }, | 543 | { "w25x32", 0xef3016, 0, 64 * 1024, 64, SECT_4K, }, |
509 | { "w25x64", 0xef3017, 64 * 1024, 128, SECT_4K, }, | 544 | { "w25x64", 0xef3017, 0, 64 * 1024, 128, SECT_4K, }, |
510 | }; | 545 | }; |
511 | 546 | ||
512 | static struct flash_info *__devinit jedec_probe(struct spi_device *spi) | 547 | static struct flash_info *__devinit jedec_probe(struct spi_device *spi) |
513 | { | 548 | { |
514 | int tmp; | 549 | int tmp; |
515 | u8 code = OPCODE_RDID; | 550 | u8 code = OPCODE_RDID; |
516 | u8 id[3]; | 551 | u8 id[5]; |
517 | u32 jedec; | 552 | u32 jedec; |
553 | u16 ext_jedec; | ||
518 | struct flash_info *info; | 554 | struct flash_info *info; |
519 | 555 | ||
520 | /* JEDEC also defines an optional "extended device information" | 556 | /* JEDEC also defines an optional "extended device information" |
521 | * string for after vendor-specific data, after the three bytes | 557 | * string for after vendor-specific data, after the three bytes |
522 | * we use here. Supporting some chips might require using it. | 558 | * we use here. Supporting some chips might require using it. |
523 | */ | 559 | */ |
524 | tmp = spi_write_then_read(spi, &code, 1, id, 3); | 560 | tmp = spi_write_then_read(spi, &code, 1, id, 5); |
525 | if (tmp < 0) { | 561 | if (tmp < 0) { |
526 | DEBUG(MTD_DEBUG_LEVEL0, "%s: error %d reading JEDEC ID\n", | 562 | DEBUG(MTD_DEBUG_LEVEL0, "%s: error %d reading JEDEC ID\n", |
527 | spi->dev.bus_id, tmp); | 563 | spi->dev.bus_id, tmp); |
@@ -533,10 +569,14 @@ static struct flash_info *__devinit jedec_probe(struct spi_device *spi) | |||
533 | jedec = jedec << 8; | 569 | jedec = jedec << 8; |
534 | jedec |= id[2]; | 570 | jedec |= id[2]; |
535 | 571 | ||
572 | ext_jedec = id[3] << 8 | id[4]; | ||
573 | |||
536 | for (tmp = 0, info = m25p_data; | 574 | for (tmp = 0, info = m25p_data; |
537 | tmp < ARRAY_SIZE(m25p_data); | 575 | tmp < ARRAY_SIZE(m25p_data); |
538 | tmp++, info++) { | 576 | tmp++, info++) { |
539 | if (info->jedec_id == jedec) | 577 | if (info->jedec_id == jedec) |
578 | if (ext_jedec != 0 && info->ext_id != ext_jedec) | ||
579 | continue; | ||
540 | return info; | 580 | return info; |
541 | } | 581 | } |
542 | dev_err(&spi->dev, "unrecognized JEDEC id %06x\n", jedec); | 582 | dev_err(&spi->dev, "unrecognized JEDEC id %06x\n", jedec); |
diff --git a/drivers/mtd/devices/mtd_dataflash.c b/drivers/mtd/devices/mtd_dataflash.c index 8bd0dea6885f..6dd9aff8bb2d 100644 --- a/drivers/mtd/devices/mtd_dataflash.c +++ b/drivers/mtd/devices/mtd_dataflash.c | |||
@@ -30,12 +30,10 @@ | |||
30 | * doesn't (yet) use these for any kind of i/o overlap or prefetching. | 30 | * doesn't (yet) use these for any kind of i/o overlap or prefetching. |
31 | * | 31 | * |
32 | * Sometimes DataFlash is packaged in MMC-format cards, although the | 32 | * Sometimes DataFlash is packaged in MMC-format cards, although the |
33 | * MMC stack can't use SPI (yet), or distinguish between MMC and DataFlash | 33 | * MMC stack can't (yet?) distinguish between MMC and DataFlash |
34 | * protocols during enumeration. | 34 | * protocols during enumeration. |
35 | */ | 35 | */ |
36 | 36 | ||
37 | #define CONFIG_DATAFLASH_WRITE_VERIFY | ||
38 | |||
39 | /* reads can bypass the buffers */ | 37 | /* reads can bypass the buffers */ |
40 | #define OP_READ_CONTINUOUS 0xE8 | 38 | #define OP_READ_CONTINUOUS 0xE8 |
41 | #define OP_READ_PAGE 0xD2 | 39 | #define OP_READ_PAGE 0xD2 |
@@ -80,7 +78,8 @@ | |||
80 | */ | 78 | */ |
81 | #define OP_READ_ID 0x9F | 79 | #define OP_READ_ID 0x9F |
82 | #define OP_READ_SECURITY 0x77 | 80 | #define OP_READ_SECURITY 0x77 |
83 | #define OP_WRITE_SECURITY 0x9A /* OTP bits */ | 81 | #define OP_WRITE_SECURITY_REVC 0x9A |
82 | #define OP_WRITE_SECURITY 0x9B /* revision D */ | ||
84 | 83 | ||
85 | 84 | ||
86 | struct dataflash { | 85 | struct dataflash { |
@@ -402,7 +401,7 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
402 | (void) dataflash_waitready(priv->spi); | 401 | (void) dataflash_waitready(priv->spi); |
403 | 402 | ||
404 | 403 | ||
405 | #ifdef CONFIG_DATAFLASH_WRITE_VERIFY | 404 | #ifdef CONFIG_MTD_DATAFLASH_VERIFY_WRITE |
406 | 405 | ||
407 | /* (3) Compare to Buffer1 */ | 406 | /* (3) Compare to Buffer1 */ |
408 | addr = pageaddr << priv->page_offset; | 407 | addr = pageaddr << priv->page_offset; |
@@ -431,7 +430,7 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
431 | } else | 430 | } else |
432 | status = 0; | 431 | status = 0; |
433 | 432 | ||
434 | #endif /* CONFIG_DATAFLASH_WRITE_VERIFY */ | 433 | #endif /* CONFIG_MTD_DATAFLASH_VERIFY_WRITE */ |
435 | 434 | ||
436 | remaining = remaining - writelen; | 435 | remaining = remaining - writelen; |
437 | pageaddr++; | 436 | pageaddr++; |
@@ -451,16 +450,192 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
451 | 450 | ||
452 | /* ......................................................................... */ | 451 | /* ......................................................................... */ |
453 | 452 | ||
453 | #ifdef CONFIG_MTD_DATAFLASH_OTP | ||
454 | |||
455 | static int dataflash_get_otp_info(struct mtd_info *mtd, | ||
456 | struct otp_info *info, size_t len) | ||
457 | { | ||
458 | /* Report both blocks as identical: bytes 0..64, locked. | ||
459 | * Unless the user block changed from all-ones, we can't | ||
460 | * tell whether it's still writable; so we assume it isn't. | ||
461 | */ | ||
462 | info->start = 0; | ||
463 | info->length = 64; | ||
464 | info->locked = 1; | ||
465 | return sizeof(*info); | ||
466 | } | ||
467 | |||
468 | static ssize_t otp_read(struct spi_device *spi, unsigned base, | ||
469 | uint8_t *buf, loff_t off, size_t len) | ||
470 | { | ||
471 | struct spi_message m; | ||
472 | size_t l; | ||
473 | uint8_t *scratch; | ||
474 | struct spi_transfer t; | ||
475 | int status; | ||
476 | |||
477 | if (off > 64) | ||
478 | return -EINVAL; | ||
479 | |||
480 | if ((off + len) > 64) | ||
481 | len = 64 - off; | ||
482 | if (len == 0) | ||
483 | return len; | ||
484 | |||
485 | spi_message_init(&m); | ||
486 | |||
487 | l = 4 + base + off + len; | ||
488 | scratch = kzalloc(l, GFP_KERNEL); | ||
489 | if (!scratch) | ||
490 | return -ENOMEM; | ||
491 | |||
492 | /* OUT: OP_READ_SECURITY, 3 don't-care bytes, zeroes | ||
493 | * IN: ignore 4 bytes, data bytes 0..N (max 127) | ||
494 | */ | ||
495 | scratch[0] = OP_READ_SECURITY; | ||
496 | |||
497 | memset(&t, 0, sizeof t); | ||
498 | t.tx_buf = scratch; | ||
499 | t.rx_buf = scratch; | ||
500 | t.len = l; | ||
501 | spi_message_add_tail(&t, &m); | ||
502 | |||
503 | dataflash_waitready(spi); | ||
504 | |||
505 | status = spi_sync(spi, &m); | ||
506 | if (status >= 0) { | ||
507 | memcpy(buf, scratch + 4 + base + off, len); | ||
508 | status = len; | ||
509 | } | ||
510 | |||
511 | kfree(scratch); | ||
512 | return status; | ||
513 | } | ||
514 | |||
515 | static int dataflash_read_fact_otp(struct mtd_info *mtd, | ||
516 | loff_t from, size_t len, size_t *retlen, u_char *buf) | ||
517 | { | ||
518 | struct dataflash *priv = (struct dataflash *)mtd->priv; | ||
519 | int status; | ||
520 | |||
521 | /* 64 bytes, from 0..63 ... start at 64 on-chip */ | ||
522 | mutex_lock(&priv->lock); | ||
523 | status = otp_read(priv->spi, 64, buf, from, len); | ||
524 | mutex_unlock(&priv->lock); | ||
525 | |||
526 | if (status < 0) | ||
527 | return status; | ||
528 | *retlen = status; | ||
529 | return 0; | ||
530 | } | ||
531 | |||
532 | static int dataflash_read_user_otp(struct mtd_info *mtd, | ||
533 | loff_t from, size_t len, size_t *retlen, u_char *buf) | ||
534 | { | ||
535 | struct dataflash *priv = (struct dataflash *)mtd->priv; | ||
536 | int status; | ||
537 | |||
538 | /* 64 bytes, from 0..63 ... start at 0 on-chip */ | ||
539 | mutex_lock(&priv->lock); | ||
540 | status = otp_read(priv->spi, 0, buf, from, len); | ||
541 | mutex_unlock(&priv->lock); | ||
542 | |||
543 | if (status < 0) | ||
544 | return status; | ||
545 | *retlen = status; | ||
546 | return 0; | ||
547 | } | ||
548 | |||
549 | static int dataflash_write_user_otp(struct mtd_info *mtd, | ||
550 | loff_t from, size_t len, size_t *retlen, u_char *buf) | ||
551 | { | ||
552 | struct spi_message m; | ||
553 | const size_t l = 4 + 64; | ||
554 | uint8_t *scratch; | ||
555 | struct spi_transfer t; | ||
556 | struct dataflash *priv = (struct dataflash *)mtd->priv; | ||
557 | int status; | ||
558 | |||
559 | if (len > 64) | ||
560 | return -EINVAL; | ||
561 | |||
562 | /* Strictly speaking, we *could* truncate the write ... but | ||
563 | * let's not do that for the only write that's ever possible. | ||
564 | */ | ||
565 | if ((from + len) > 64) | ||
566 | return -EINVAL; | ||
567 | |||
568 | /* OUT: OP_WRITE_SECURITY, 3 zeroes, 64 data-or-zero bytes | ||
569 | * IN: ignore all | ||
570 | */ | ||
571 | scratch = kzalloc(l, GFP_KERNEL); | ||
572 | if (!scratch) | ||
573 | return -ENOMEM; | ||
574 | scratch[0] = OP_WRITE_SECURITY; | ||
575 | memcpy(scratch + 4 + from, buf, len); | ||
576 | |||
577 | spi_message_init(&m); | ||
578 | |||
579 | memset(&t, 0, sizeof t); | ||
580 | t.tx_buf = scratch; | ||
581 | t.len = l; | ||
582 | spi_message_add_tail(&t, &m); | ||
583 | |||
584 | /* Write the OTP bits, if they've not yet been written. | ||
585 | * This modifies SRAM buffer1. | ||
586 | */ | ||
587 | mutex_lock(&priv->lock); | ||
588 | dataflash_waitready(priv->spi); | ||
589 | status = spi_sync(priv->spi, &m); | ||
590 | mutex_unlock(&priv->lock); | ||
591 | |||
592 | kfree(scratch); | ||
593 | |||
594 | if (status >= 0) { | ||
595 | status = 0; | ||
596 | *retlen = len; | ||
597 | } | ||
598 | return status; | ||
599 | } | ||
600 | |||
601 | static char *otp_setup(struct mtd_info *device, char revision) | ||
602 | { | ||
603 | device->get_fact_prot_info = dataflash_get_otp_info; | ||
604 | device->read_fact_prot_reg = dataflash_read_fact_otp; | ||
605 | device->get_user_prot_info = dataflash_get_otp_info; | ||
606 | device->read_user_prot_reg = dataflash_read_user_otp; | ||
607 | |||
608 | /* rev c parts (at45db321c and at45db1281 only!) use a | ||
609 | * different write procedure; not (yet?) implemented. | ||
610 | */ | ||
611 | if (revision > 'c') | ||
612 | device->write_user_prot_reg = dataflash_write_user_otp; | ||
613 | |||
614 | return ", OTP"; | ||
615 | } | ||
616 | |||
617 | #else | ||
618 | |||
619 | static char *otp_setup(struct mtd_info *device, char revision) | ||
620 | { | ||
621 | return " (OTP)"; | ||
622 | } | ||
623 | |||
624 | #endif | ||
625 | |||
626 | /* ......................................................................... */ | ||
627 | |||
454 | /* | 628 | /* |
455 | * Register DataFlash device with MTD subsystem. | 629 | * Register DataFlash device with MTD subsystem. |
456 | */ | 630 | */ |
457 | static int __devinit | 631 | static int __devinit |
458 | add_dataflash(struct spi_device *spi, char *name, | 632 | add_dataflash_otp(struct spi_device *spi, char *name, |
459 | int nr_pages, int pagesize, int pageoffset) | 633 | int nr_pages, int pagesize, int pageoffset, char revision) |
460 | { | 634 | { |
461 | struct dataflash *priv; | 635 | struct dataflash *priv; |
462 | struct mtd_info *device; | 636 | struct mtd_info *device; |
463 | struct flash_platform_data *pdata = spi->dev.platform_data; | 637 | struct flash_platform_data *pdata = spi->dev.platform_data; |
638 | char *otp_tag = ""; | ||
464 | 639 | ||
465 | priv = kzalloc(sizeof *priv, GFP_KERNEL); | 640 | priv = kzalloc(sizeof *priv, GFP_KERNEL); |
466 | if (!priv) | 641 | if (!priv) |
@@ -489,8 +664,12 @@ add_dataflash(struct spi_device *spi, char *name, | |||
489 | device->write = dataflash_write; | 664 | device->write = dataflash_write; |
490 | device->priv = priv; | 665 | device->priv = priv; |
491 | 666 | ||
492 | dev_info(&spi->dev, "%s (%d KBytes) pagesize %d bytes\n", | 667 | if (revision >= 'c') |
493 | name, DIV_ROUND_UP(device->size, 1024), pagesize); | 668 | otp_tag = otp_setup(device, revision); |
669 | |||
670 | dev_info(&spi->dev, "%s (%d KBytes) pagesize %d bytes%s\n", | ||
671 | name, DIV_ROUND_UP(device->size, 1024), | ||
672 | pagesize, otp_tag); | ||
494 | dev_set_drvdata(&spi->dev, priv); | 673 | dev_set_drvdata(&spi->dev, priv); |
495 | 674 | ||
496 | if (mtd_has_partitions()) { | 675 | if (mtd_has_partitions()) { |
@@ -519,6 +698,14 @@ add_dataflash(struct spi_device *spi, char *name, | |||
519 | return add_mtd_device(device) == 1 ? -ENODEV : 0; | 698 | return add_mtd_device(device) == 1 ? -ENODEV : 0; |
520 | } | 699 | } |
521 | 700 | ||
701 | static inline int __devinit | ||
702 | add_dataflash(struct spi_device *spi, char *name, | ||
703 | int nr_pages, int pagesize, int pageoffset) | ||
704 | { | ||
705 | return add_dataflash_otp(spi, name, nr_pages, pagesize, | ||
706 | pageoffset, 0); | ||
707 | } | ||
708 | |||
522 | struct flash_info { | 709 | struct flash_info { |
523 | char *name; | 710 | char *name; |
524 | 711 | ||
@@ -664,13 +851,16 @@ static int __devinit dataflash_probe(struct spi_device *spi) | |||
664 | * Try to detect dataflash by JEDEC ID. | 851 | * Try to detect dataflash by JEDEC ID. |
665 | * If it succeeds we know we have either a C or D part. | 852 | * If it succeeds we know we have either a C or D part. |
666 | * D will support power of 2 pagesize option. | 853 | * D will support power of 2 pagesize option. |
854 | * Both support the security register, though with different | ||
855 | * write procedures. | ||
667 | */ | 856 | */ |
668 | info = jedec_probe(spi); | 857 | info = jedec_probe(spi); |
669 | if (IS_ERR(info)) | 858 | if (IS_ERR(info)) |
670 | return PTR_ERR(info); | 859 | return PTR_ERR(info); |
671 | if (info != NULL) | 860 | if (info != NULL) |
672 | return add_dataflash(spi, info->name, info->nr_pages, | 861 | return add_dataflash_otp(spi, info->name, info->nr_pages, |
673 | info->pagesize, info->pageoffset); | 862 | info->pagesize, info->pageoffset, |
863 | (info->flags & SUP_POW2PS) ? 'd' : 'c'); | ||
674 | 864 | ||
675 | /* | 865 | /* |
676 | * Older chips support only legacy commands, identifing | 866 | * Older chips support only legacy commands, identifing |
diff --git a/drivers/mtd/inftlcore.c b/drivers/mtd/inftlcore.c index c4f9d3378b24..50ce13887f63 100644 --- a/drivers/mtd/inftlcore.c +++ b/drivers/mtd/inftlcore.c | |||
@@ -388,6 +388,10 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned | |||
388 | if (thisEUN == targetEUN) | 388 | if (thisEUN == targetEUN) |
389 | break; | 389 | break; |
390 | 390 | ||
391 | /* Unlink the last block from the chain. */ | ||
392 | inftl->PUtable[prevEUN] = BLOCK_NIL; | ||
393 | |||
394 | /* Now try to erase it. */ | ||
391 | if (INFTL_formatblock(inftl, thisEUN) < 0) { | 395 | if (INFTL_formatblock(inftl, thisEUN) < 0) { |
392 | /* | 396 | /* |
393 | * Could not erase : mark block as reserved. | 397 | * Could not erase : mark block as reserved. |
@@ -396,7 +400,6 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned | |||
396 | } else { | 400 | } else { |
397 | /* Correctly erased : mark it as free */ | 401 | /* Correctly erased : mark it as free */ |
398 | inftl->PUtable[thisEUN] = BLOCK_FREE; | 402 | inftl->PUtable[thisEUN] = BLOCK_FREE; |
399 | inftl->PUtable[prevEUN] = BLOCK_NIL; | ||
400 | inftl->numfreeEUNs++; | 403 | inftl->numfreeEUNs++; |
401 | } | 404 | } |
402 | } | 405 | } |
diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig index df8e00bba07b..5ea169362164 100644 --- a/drivers/mtd/maps/Kconfig +++ b/drivers/mtd/maps/Kconfig | |||
@@ -332,30 +332,6 @@ config MTD_CFI_FLAGADM | |||
332 | Mapping for the Flaga digital module. If you don't have one, ignore | 332 | Mapping for the Flaga digital module. If you don't have one, ignore |
333 | this setting. | 333 | this setting. |
334 | 334 | ||
335 | config MTD_WALNUT | ||
336 | tristate "Flash device mapped on IBM 405GP Walnut" | ||
337 | depends on MTD_JEDECPROBE && WALNUT && !PPC_MERGE | ||
338 | help | ||
339 | This enables access routines for the flash chips on the IBM 405GP | ||
340 | Walnut board. If you have one of these boards and would like to | ||
341 | use the flash chips on it, say 'Y'. | ||
342 | |||
343 | config MTD_EBONY | ||
344 | tristate "Flash devices mapped on IBM 440GP Ebony" | ||
345 | depends on MTD_JEDECPROBE && EBONY && !PPC_MERGE | ||
346 | help | ||
347 | This enables access routines for the flash chips on the IBM 440GP | ||
348 | Ebony board. If you have one of these boards and would like to | ||
349 | use the flash chips on it, say 'Y'. | ||
350 | |||
351 | config MTD_OCOTEA | ||
352 | tristate "Flash devices mapped on IBM 440GX Ocotea" | ||
353 | depends on MTD_CFI && OCOTEA && !PPC_MERGE | ||
354 | help | ||
355 | This enables access routines for the flash chips on the IBM 440GX | ||
356 | Ocotea board. If you have one of these boards and would like to | ||
357 | use the flash chips on it, say 'Y'. | ||
358 | |||
359 | config MTD_REDWOOD | 335 | config MTD_REDWOOD |
360 | tristate "CFI Flash devices mapped on IBM Redwood" | 336 | tristate "CFI Flash devices mapped on IBM Redwood" |
361 | depends on MTD_CFI && ( REDWOOD_4 || REDWOOD_5 || REDWOOD_6 ) | 337 | depends on MTD_CFI && ( REDWOOD_4 || REDWOOD_5 || REDWOOD_6 ) |
@@ -458,13 +434,6 @@ config MTD_CEIVA | |||
458 | PhotoMax Digital Picture Frame. | 434 | PhotoMax Digital Picture Frame. |
459 | If you have such a device, say 'Y'. | 435 | If you have such a device, say 'Y'. |
460 | 436 | ||
461 | config MTD_NOR_TOTO | ||
462 | tristate "NOR Flash device on TOTO board" | ||
463 | depends on ARCH_OMAP && OMAP_TOTO | ||
464 | help | ||
465 | This enables access to the NOR flash on the Texas Instruments | ||
466 | TOTO board. | ||
467 | |||
468 | config MTD_H720X | 437 | config MTD_H720X |
469 | tristate "Hynix evaluation board mappings" | 438 | tristate "Hynix evaluation board mappings" |
470 | depends on MTD_CFI && ( ARCH_H7201 || ARCH_H7202 ) | 439 | depends on MTD_CFI && ( ARCH_H7201 || ARCH_H7202 ) |
@@ -522,7 +491,7 @@ config MTD_BFIN_ASYNC | |||
522 | 491 | ||
523 | config MTD_UCLINUX | 492 | config MTD_UCLINUX |
524 | tristate "Generic uClinux RAM/ROM filesystem support" | 493 | tristate "Generic uClinux RAM/ROM filesystem support" |
525 | depends on MTD_PARTITIONS && !MMU | 494 | depends on MTD_PARTITIONS && MTD_RAM && !MMU |
526 | help | 495 | help |
527 | Map driver to support image based filesystems for uClinux. | 496 | Map driver to support image based filesystems for uClinux. |
528 | 497 | ||
diff --git a/drivers/mtd/maps/Makefile b/drivers/mtd/maps/Makefile index 6cda6df973e5..6d9ba35caf11 100644 --- a/drivers/mtd/maps/Makefile +++ b/drivers/mtd/maps/Makefile | |||
@@ -50,12 +50,8 @@ obj-$(CONFIG_MTD_REDWOOD) += redwood.o | |||
50 | obj-$(CONFIG_MTD_UCLINUX) += uclinux.o | 50 | obj-$(CONFIG_MTD_UCLINUX) += uclinux.o |
51 | obj-$(CONFIG_MTD_NETtel) += nettel.o | 51 | obj-$(CONFIG_MTD_NETtel) += nettel.o |
52 | obj-$(CONFIG_MTD_SCB2_FLASH) += scb2_flash.o | 52 | obj-$(CONFIG_MTD_SCB2_FLASH) += scb2_flash.o |
53 | obj-$(CONFIG_MTD_EBONY) += ebony.o | ||
54 | obj-$(CONFIG_MTD_OCOTEA) += ocotea.o | ||
55 | obj-$(CONFIG_MTD_WALNUT) += walnut.o | ||
56 | obj-$(CONFIG_MTD_H720X) += h720x-flash.o | 53 | obj-$(CONFIG_MTD_H720X) += h720x-flash.o |
57 | obj-$(CONFIG_MTD_SBC8240) += sbc8240.o | 54 | obj-$(CONFIG_MTD_SBC8240) += sbc8240.o |
58 | obj-$(CONFIG_MTD_NOR_TOTO) += omap-toto-flash.o | ||
59 | obj-$(CONFIG_MTD_IXP4XX) += ixp4xx.o | 55 | obj-$(CONFIG_MTD_IXP4XX) += ixp4xx.o |
60 | obj-$(CONFIG_MTD_IXP2000) += ixp2000.o | 56 | obj-$(CONFIG_MTD_IXP2000) += ixp2000.o |
61 | obj-$(CONFIG_MTD_WRSBC8260) += wr_sbc82xx_flash.o | 57 | obj-$(CONFIG_MTD_WRSBC8260) += wr_sbc82xx_flash.o |
diff --git a/drivers/mtd/maps/ebony.c b/drivers/mtd/maps/ebony.c deleted file mode 100644 index d92b7c70d3ed..000000000000 --- a/drivers/mtd/maps/ebony.c +++ /dev/null | |||
@@ -1,163 +0,0 @@ | |||
1 | /* | ||
2 | * Mapping for Ebony user flash | ||
3 | * | ||
4 | * Matt Porter <mporter@kernel.crashing.org> | ||
5 | * | ||
6 | * Copyright 2002-2004 MontaVista Software Inc. | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | */ | ||
13 | |||
14 | #include <linux/module.h> | ||
15 | #include <linux/types.h> | ||
16 | #include <linux/kernel.h> | ||
17 | #include <linux/init.h> | ||
18 | #include <linux/mtd/mtd.h> | ||
19 | #include <linux/mtd/map.h> | ||
20 | #include <linux/mtd/partitions.h> | ||
21 | #include <asm/io.h> | ||
22 | #include <asm/ibm44x.h> | ||
23 | #include <platforms/4xx/ebony.h> | ||
24 | |||
25 | static struct mtd_info *flash; | ||
26 | |||
27 | static struct map_info ebony_small_map = { | ||
28 | .name = "Ebony small flash", | ||
29 | .size = EBONY_SMALL_FLASH_SIZE, | ||
30 | .bankwidth = 1, | ||
31 | }; | ||
32 | |||
33 | static struct map_info ebony_large_map = { | ||
34 | .name = "Ebony large flash", | ||
35 | .size = EBONY_LARGE_FLASH_SIZE, | ||
36 | .bankwidth = 1, | ||
37 | }; | ||
38 | |||
39 | static struct mtd_partition ebony_small_partitions[] = { | ||
40 | { | ||
41 | .name = "OpenBIOS", | ||
42 | .offset = 0x0, | ||
43 | .size = 0x80000, | ||
44 | } | ||
45 | }; | ||
46 | |||
47 | static struct mtd_partition ebony_large_partitions[] = { | ||
48 | { | ||
49 | .name = "fs", | ||
50 | .offset = 0, | ||
51 | .size = 0x380000, | ||
52 | }, | ||
53 | { | ||
54 | .name = "firmware", | ||
55 | .offset = 0x380000, | ||
56 | .size = 0x80000, | ||
57 | } | ||
58 | }; | ||
59 | |||
60 | int __init init_ebony(void) | ||
61 | { | ||
62 | u8 fpga0_reg; | ||
63 | u8 __iomem *fpga0_adr; | ||
64 | unsigned long long small_flash_base, large_flash_base; | ||
65 | |||
66 | fpga0_adr = ioremap64(EBONY_FPGA_ADDR, 16); | ||
67 | if (!fpga0_adr) | ||
68 | return -ENOMEM; | ||
69 | |||
70 | fpga0_reg = readb(fpga0_adr); | ||
71 | iounmap(fpga0_adr); | ||
72 | |||
73 | if (EBONY_BOOT_SMALL_FLASH(fpga0_reg) && | ||
74 | !EBONY_FLASH_SEL(fpga0_reg)) | ||
75 | small_flash_base = EBONY_SMALL_FLASH_HIGH2; | ||
76 | else if (EBONY_BOOT_SMALL_FLASH(fpga0_reg) && | ||
77 | EBONY_FLASH_SEL(fpga0_reg)) | ||
78 | small_flash_base = EBONY_SMALL_FLASH_HIGH1; | ||
79 | else if (!EBONY_BOOT_SMALL_FLASH(fpga0_reg) && | ||
80 | !EBONY_FLASH_SEL(fpga0_reg)) | ||
81 | small_flash_base = EBONY_SMALL_FLASH_LOW2; | ||
82 | else | ||
83 | small_flash_base = EBONY_SMALL_FLASH_LOW1; | ||
84 | |||
85 | if (EBONY_BOOT_SMALL_FLASH(fpga0_reg) && | ||
86 | !EBONY_ONBRD_FLASH_EN(fpga0_reg)) | ||
87 | large_flash_base = EBONY_LARGE_FLASH_LOW; | ||
88 | else | ||
89 | large_flash_base = EBONY_LARGE_FLASH_HIGH; | ||
90 | |||
91 | ebony_small_map.phys = small_flash_base; | ||
92 | ebony_small_map.virt = ioremap64(small_flash_base, | ||
93 | ebony_small_map.size); | ||
94 | |||
95 | if (!ebony_small_map.virt) { | ||
96 | printk("Failed to ioremap flash\n"); | ||
97 | return -EIO; | ||
98 | } | ||
99 | |||
100 | simple_map_init(&ebony_small_map); | ||
101 | |||
102 | flash = do_map_probe("jedec_probe", &ebony_small_map); | ||
103 | if (flash) { | ||
104 | flash->owner = THIS_MODULE; | ||
105 | add_mtd_partitions(flash, ebony_small_partitions, | ||
106 | ARRAY_SIZE(ebony_small_partitions)); | ||
107 | } else { | ||
108 | printk("map probe failed for flash\n"); | ||
109 | iounmap(ebony_small_map.virt); | ||
110 | return -ENXIO; | ||
111 | } | ||
112 | |||
113 | ebony_large_map.phys = large_flash_base; | ||
114 | ebony_large_map.virt = ioremap64(large_flash_base, | ||
115 | ebony_large_map.size); | ||
116 | |||
117 | if (!ebony_large_map.virt) { | ||
118 | printk("Failed to ioremap flash\n"); | ||
119 | iounmap(ebony_small_map.virt); | ||
120 | return -EIO; | ||
121 | } | ||
122 | |||
123 | simple_map_init(&ebony_large_map); | ||
124 | |||
125 | flash = do_map_probe("jedec_probe", &ebony_large_map); | ||
126 | if (flash) { | ||
127 | flash->owner = THIS_MODULE; | ||
128 | add_mtd_partitions(flash, ebony_large_partitions, | ||
129 | ARRAY_SIZE(ebony_large_partitions)); | ||
130 | } else { | ||
131 | printk("map probe failed for flash\n"); | ||
132 | iounmap(ebony_small_map.virt); | ||
133 | iounmap(ebony_large_map.virt); | ||
134 | return -ENXIO; | ||
135 | } | ||
136 | |||
137 | return 0; | ||
138 | } | ||
139 | |||
140 | static void __exit cleanup_ebony(void) | ||
141 | { | ||
142 | if (flash) { | ||
143 | del_mtd_partitions(flash); | ||
144 | map_destroy(flash); | ||
145 | } | ||
146 | |||
147 | if (ebony_small_map.virt) { | ||
148 | iounmap(ebony_small_map.virt); | ||
149 | ebony_small_map.virt = NULL; | ||
150 | } | ||
151 | |||
152 | if (ebony_large_map.virt) { | ||
153 | iounmap(ebony_large_map.virt); | ||
154 | ebony_large_map.virt = NULL; | ||
155 | } | ||
156 | } | ||
157 | |||
158 | module_init(init_ebony); | ||
159 | module_exit(cleanup_ebony); | ||
160 | |||
161 | MODULE_LICENSE("GPL"); | ||
162 | MODULE_AUTHOR("Matt Porter <mporter@kernel.crashing.org>"); | ||
163 | MODULE_DESCRIPTION("MTD map and partitions for IBM 440GP Ebony boards"); | ||
diff --git a/drivers/mtd/maps/ocotea.c b/drivers/mtd/maps/ocotea.c deleted file mode 100644 index 5522eac8c980..000000000000 --- a/drivers/mtd/maps/ocotea.c +++ /dev/null | |||
@@ -1,154 +0,0 @@ | |||
1 | /* | ||
2 | * Mapping for Ocotea user flash | ||
3 | * | ||
4 | * Matt Porter <mporter@kernel.crashing.org> | ||
5 | * | ||
6 | * Copyright 2002-2004 MontaVista Software Inc. | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | */ | ||
13 | |||
14 | #include <linux/module.h> | ||
15 | #include <linux/types.h> | ||
16 | #include <linux/kernel.h> | ||
17 | #include <linux/init.h> | ||
18 | #include <linux/mtd/mtd.h> | ||
19 | #include <linux/mtd/map.h> | ||
20 | #include <linux/mtd/partitions.h> | ||
21 | #include <asm/io.h> | ||
22 | #include <asm/ibm44x.h> | ||
23 | #include <platforms/4xx/ocotea.h> | ||
24 | |||
25 | static struct mtd_info *flash; | ||
26 | |||
27 | static struct map_info ocotea_small_map = { | ||
28 | .name = "Ocotea small flash", | ||
29 | .size = OCOTEA_SMALL_FLASH_SIZE, | ||
30 | .buswidth = 1, | ||
31 | }; | ||
32 | |||
33 | static struct map_info ocotea_large_map = { | ||
34 | .name = "Ocotea large flash", | ||
35 | .size = OCOTEA_LARGE_FLASH_SIZE, | ||
36 | .buswidth = 1, | ||
37 | }; | ||
38 | |||
39 | static struct mtd_partition ocotea_small_partitions[] = { | ||
40 | { | ||
41 | .name = "pibs", | ||
42 | .offset = 0x0, | ||
43 | .size = 0x100000, | ||
44 | } | ||
45 | }; | ||
46 | |||
47 | static struct mtd_partition ocotea_large_partitions[] = { | ||
48 | { | ||
49 | .name = "fs", | ||
50 | .offset = 0, | ||
51 | .size = 0x300000, | ||
52 | }, | ||
53 | { | ||
54 | .name = "firmware", | ||
55 | .offset = 0x300000, | ||
56 | .size = 0x100000, | ||
57 | } | ||
58 | }; | ||
59 | |||
60 | int __init init_ocotea(void) | ||
61 | { | ||
62 | u8 fpga0_reg; | ||
63 | u8 *fpga0_adr; | ||
64 | unsigned long long small_flash_base, large_flash_base; | ||
65 | |||
66 | fpga0_adr = ioremap64(OCOTEA_FPGA_ADDR, 16); | ||
67 | if (!fpga0_adr) | ||
68 | return -ENOMEM; | ||
69 | |||
70 | fpga0_reg = readb((unsigned long)fpga0_adr); | ||
71 | iounmap(fpga0_adr); | ||
72 | |||
73 | if (OCOTEA_BOOT_LARGE_FLASH(fpga0_reg)) { | ||
74 | small_flash_base = OCOTEA_SMALL_FLASH_HIGH; | ||
75 | large_flash_base = OCOTEA_LARGE_FLASH_LOW; | ||
76 | } | ||
77 | else { | ||
78 | small_flash_base = OCOTEA_SMALL_FLASH_LOW; | ||
79 | large_flash_base = OCOTEA_LARGE_FLASH_HIGH; | ||
80 | } | ||
81 | |||
82 | ocotea_small_map.phys = small_flash_base; | ||
83 | ocotea_small_map.virt = ioremap64(small_flash_base, | ||
84 | ocotea_small_map.size); | ||
85 | |||
86 | if (!ocotea_small_map.virt) { | ||
87 | printk("Failed to ioremap flash\n"); | ||
88 | return -EIO; | ||
89 | } | ||
90 | |||
91 | simple_map_init(&ocotea_small_map); | ||
92 | |||
93 | flash = do_map_probe("map_rom", &ocotea_small_map); | ||
94 | if (flash) { | ||
95 | flash->owner = THIS_MODULE; | ||
96 | add_mtd_partitions(flash, ocotea_small_partitions, | ||
97 | ARRAY_SIZE(ocotea_small_partitions)); | ||
98 | } else { | ||
99 | printk("map probe failed for flash\n"); | ||
100 | iounmap(ocotea_small_map.virt); | ||
101 | return -ENXIO; | ||
102 | } | ||
103 | |||
104 | ocotea_large_map.phys = large_flash_base; | ||
105 | ocotea_large_map.virt = ioremap64(large_flash_base, | ||
106 | ocotea_large_map.size); | ||
107 | |||
108 | if (!ocotea_large_map.virt) { | ||
109 | printk("Failed to ioremap flash\n"); | ||
110 | iounmap(ocotea_small_map.virt); | ||
111 | return -EIO; | ||
112 | } | ||
113 | |||
114 | simple_map_init(&ocotea_large_map); | ||
115 | |||
116 | flash = do_map_probe("cfi_probe", &ocotea_large_map); | ||
117 | if (flash) { | ||
118 | flash->owner = THIS_MODULE; | ||
119 | add_mtd_partitions(flash, ocotea_large_partitions, | ||
120 | ARRAY_SIZE(ocotea_large_partitions)); | ||
121 | } else { | ||
122 | printk("map probe failed for flash\n"); | ||
123 | iounmap(ocotea_small_map.virt); | ||
124 | iounmap(ocotea_large_map.virt); | ||
125 | return -ENXIO; | ||
126 | } | ||
127 | |||
128 | return 0; | ||
129 | } | ||
130 | |||
131 | static void __exit cleanup_ocotea(void) | ||
132 | { | ||
133 | if (flash) { | ||
134 | del_mtd_partitions(flash); | ||
135 | map_destroy(flash); | ||
136 | } | ||
137 | |||
138 | if (ocotea_small_map.virt) { | ||
139 | iounmap((void *)ocotea_small_map.virt); | ||
140 | ocotea_small_map.virt = 0; | ||
141 | } | ||
142 | |||
143 | if (ocotea_large_map.virt) { | ||
144 | iounmap((void *)ocotea_large_map.virt); | ||
145 | ocotea_large_map.virt = 0; | ||
146 | } | ||
147 | } | ||
148 | |||
149 | module_init(init_ocotea); | ||
150 | module_exit(cleanup_ocotea); | ||
151 | |||
152 | MODULE_LICENSE("GPL"); | ||
153 | MODULE_AUTHOR("Matt Porter <mporter@kernel.crashing.org>"); | ||
154 | MODULE_DESCRIPTION("MTD map and partitions for IBM 440GX Ocotea boards"); | ||
diff --git a/drivers/mtd/maps/omap-toto-flash.c b/drivers/mtd/maps/omap-toto-flash.c deleted file mode 100644 index 0a60ebbc2175..000000000000 --- a/drivers/mtd/maps/omap-toto-flash.c +++ /dev/null | |||
@@ -1,133 +0,0 @@ | |||
1 | /* | ||
2 | * NOR Flash memory access on TI Toto board | ||
3 | * | ||
4 | * jzhang@ti.com (C) 2003 Texas Instruments. | ||
5 | * | ||
6 | * (C) 2002 MontVista Software, Inc. | ||
7 | */ | ||
8 | |||
9 | #include <linux/module.h> | ||
10 | #include <linux/types.h> | ||
11 | #include <linux/kernel.h> | ||
12 | #include <linux/errno.h> | ||
13 | #include <linux/init.h> | ||
14 | #include <linux/slab.h> | ||
15 | |||
16 | #include <linux/mtd/mtd.h> | ||
17 | #include <linux/mtd/map.h> | ||
18 | #include <linux/mtd/partitions.h> | ||
19 | |||
20 | #include <asm/hardware.h> | ||
21 | #include <asm/io.h> | ||
22 | |||
23 | |||
24 | #ifndef CONFIG_ARCH_OMAP | ||
25 | #error This is for OMAP architecture only | ||
26 | #endif | ||
27 | |||
28 | //these lines need be moved to a hardware header file | ||
29 | #define OMAP_TOTO_FLASH_BASE 0xd8000000 | ||
30 | #define OMAP_TOTO_FLASH_SIZE 0x80000 | ||
31 | |||
32 | static struct map_info omap_toto_map_flash = { | ||
33 | .name = "OMAP Toto flash", | ||
34 | .bankwidth = 2, | ||
35 | .virt = (void __iomem *)OMAP_TOTO_FLASH_BASE, | ||
36 | }; | ||
37 | |||
38 | |||
39 | static struct mtd_partition toto_flash_partitions[] = { | ||
40 | { | ||
41 | .name = "BootLoader", | ||
42 | .size = 0x00040000, /* hopefully u-boot will stay 128k + 128*/ | ||
43 | .offset = 0, | ||
44 | .mask_flags = MTD_WRITEABLE, /* force read-only */ | ||
45 | }, { | ||
46 | .name = "ReservedSpace", | ||
47 | .size = 0x00030000, | ||
48 | .offset = MTDPART_OFS_APPEND, | ||
49 | //mask_flags: MTD_WRITEABLE, /* force read-only */ | ||
50 | }, { | ||
51 | .name = "EnvArea", /* bottom 64KiB for env vars */ | ||
52 | .size = MTDPART_SIZ_FULL, | ||
53 | .offset = MTDPART_OFS_APPEND, | ||
54 | } | ||
55 | }; | ||
56 | |||
57 | static struct mtd_partition *parsed_parts; | ||
58 | |||
59 | static struct mtd_info *flash_mtd; | ||
60 | |||
61 | static int __init init_flash (void) | ||
62 | { | ||
63 | |||
64 | struct mtd_partition *parts; | ||
65 | int nb_parts = 0; | ||
66 | int parsed_nr_parts = 0; | ||
67 | const char *part_type; | ||
68 | |||
69 | /* | ||
70 | * Static partition definition selection | ||
71 | */ | ||
72 | part_type = "static"; | ||
73 | |||
74 | parts = toto_flash_partitions; | ||
75 | nb_parts = ARRAY_SIZE(toto_flash_partitions); | ||
76 | omap_toto_map_flash.size = OMAP_TOTO_FLASH_SIZE; | ||
77 | omap_toto_map_flash.phys = virt_to_phys(OMAP_TOTO_FLASH_BASE); | ||
78 | |||
79 | simple_map_init(&omap_toto_map_flash); | ||
80 | /* | ||
81 | * Now let's probe for the actual flash. Do it here since | ||
82 | * specific machine settings might have been set above. | ||
83 | */ | ||
84 | printk(KERN_NOTICE "OMAP toto flash: probing %d-bit flash bus\n", | ||
85 | omap_toto_map_flash.bankwidth*8); | ||
86 | flash_mtd = do_map_probe("jedec_probe", &omap_toto_map_flash); | ||
87 | if (!flash_mtd) | ||
88 | return -ENXIO; | ||
89 | |||
90 | if (parsed_nr_parts > 0) { | ||
91 | parts = parsed_parts; | ||
92 | nb_parts = parsed_nr_parts; | ||
93 | } | ||
94 | |||
95 | if (nb_parts == 0) { | ||
96 | printk(KERN_NOTICE "OMAP toto flash: no partition info available," | ||
97 | "registering whole flash at once\n"); | ||
98 | if (add_mtd_device(flash_mtd)){ | ||
99 | return -ENXIO; | ||
100 | } | ||
101 | } else { | ||
102 | printk(KERN_NOTICE "Using %s partition definition\n", | ||
103 | part_type); | ||
104 | return add_mtd_partitions(flash_mtd, parts, nb_parts); | ||
105 | } | ||
106 | return 0; | ||
107 | } | ||
108 | |||
109 | int __init omap_toto_mtd_init(void) | ||
110 | { | ||
111 | int status; | ||
112 | |||
113 | if (status = init_flash()) { | ||
114 | printk(KERN_ERR "OMAP Toto Flash: unable to init map for toto flash\n"); | ||
115 | } | ||
116 | return status; | ||
117 | } | ||
118 | |||
119 | static void __exit omap_toto_mtd_cleanup(void) | ||
120 | { | ||
121 | if (flash_mtd) { | ||
122 | del_mtd_partitions(flash_mtd); | ||
123 | map_destroy(flash_mtd); | ||
124 | kfree(parsed_parts); | ||
125 | } | ||
126 | } | ||
127 | |||
128 | module_init(omap_toto_mtd_init); | ||
129 | module_exit(omap_toto_mtd_cleanup); | ||
130 | |||
131 | MODULE_AUTHOR("Jian Zhang"); | ||
132 | MODULE_DESCRIPTION("OMAP Toto board map driver"); | ||
133 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/mtd/maps/pci.c b/drivers/mtd/maps/pci.c index 5c6a25c90380..48f4cf5cb9d1 100644 --- a/drivers/mtd/maps/pci.c +++ b/drivers/mtd/maps/pci.c | |||
@@ -203,15 +203,8 @@ intel_dc21285_init(struct pci_dev *dev, struct map_pci_info *map) | |||
203 | * not enabled, should we be allocating a new resource for it | 203 | * not enabled, should we be allocating a new resource for it |
204 | * or simply enabling it? | 204 | * or simply enabling it? |
205 | */ | 205 | */ |
206 | if (!(pci_resource_flags(dev, PCI_ROM_RESOURCE) & | 206 | pci_enable_rom(dev); |
207 | IORESOURCE_ROM_ENABLE)) { | 207 | printk("%s: enabling expansion ROM\n", pci_name(dev)); |
208 | u32 val; | ||
209 | pci_resource_flags(dev, PCI_ROM_RESOURCE) |= IORESOURCE_ROM_ENABLE; | ||
210 | pci_read_config_dword(dev, PCI_ROM_ADDRESS, &val); | ||
211 | val |= PCI_ROM_ADDRESS_ENABLE; | ||
212 | pci_write_config_dword(dev, PCI_ROM_ADDRESS, val); | ||
213 | printk("%s: enabling expansion ROM\n", pci_name(dev)); | ||
214 | } | ||
215 | } | 208 | } |
216 | 209 | ||
217 | if (!len || !base) | 210 | if (!len || !base) |
@@ -232,18 +225,13 @@ intel_dc21285_init(struct pci_dev *dev, struct map_pci_info *map) | |||
232 | static void | 225 | static void |
233 | intel_dc21285_exit(struct pci_dev *dev, struct map_pci_info *map) | 226 | intel_dc21285_exit(struct pci_dev *dev, struct map_pci_info *map) |
234 | { | 227 | { |
235 | u32 val; | ||
236 | |||
237 | if (map->base) | 228 | if (map->base) |
238 | iounmap(map->base); | 229 | iounmap(map->base); |
239 | 230 | ||
240 | /* | 231 | /* |
241 | * We need to undo the PCI BAR2/PCI ROM BAR address alteration. | 232 | * We need to undo the PCI BAR2/PCI ROM BAR address alteration. |
242 | */ | 233 | */ |
243 | pci_resource_flags(dev, PCI_ROM_RESOURCE) &= ~IORESOURCE_ROM_ENABLE; | 234 | pci_disable_rom(dev); |
244 | pci_read_config_dword(dev, PCI_ROM_ADDRESS, &val); | ||
245 | val &= ~PCI_ROM_ADDRESS_ENABLE; | ||
246 | pci_write_config_dword(dev, PCI_ROM_ADDRESS, val); | ||
247 | } | 235 | } |
248 | 236 | ||
249 | static unsigned long | 237 | static unsigned long |
diff --git a/drivers/mtd/maps/physmap_of.c b/drivers/mtd/maps/physmap_of.c index 49acd4171893..5fcfec034a94 100644 --- a/drivers/mtd/maps/physmap_of.c +++ b/drivers/mtd/maps/physmap_of.c | |||
@@ -230,8 +230,7 @@ static int __devinit of_flash_probe(struct of_device *dev, | |||
230 | 230 | ||
231 | #ifdef CONFIG_MTD_OF_PARTS | 231 | #ifdef CONFIG_MTD_OF_PARTS |
232 | if (err == 0) { | 232 | if (err == 0) { |
233 | err = of_mtd_parse_partitions(&dev->dev, info->mtd, | 233 | err = of_mtd_parse_partitions(&dev->dev, dp, &info->parts); |
234 | dp, &info->parts); | ||
235 | if (err < 0) | 234 | if (err < 0) |
236 | return err; | 235 | return err; |
237 | } | 236 | } |
diff --git a/drivers/mtd/maps/walnut.c b/drivers/mtd/maps/walnut.c deleted file mode 100644 index e243476c8171..000000000000 --- a/drivers/mtd/maps/walnut.c +++ /dev/null | |||
@@ -1,122 +0,0 @@ | |||
1 | /* | ||
2 | * Mapping for Walnut flash | ||
3 | * (used ebony.c as a "framework") | ||
4 | * | ||
5 | * Heikki Lindholm <holindho@infradead.org> | ||
6 | * | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | */ | ||
13 | |||
14 | #include <linux/module.h> | ||
15 | #include <linux/types.h> | ||
16 | #include <linux/kernel.h> | ||
17 | #include <linux/init.h> | ||
18 | #include <linux/mtd/mtd.h> | ||
19 | #include <linux/mtd/map.h> | ||
20 | #include <linux/mtd/partitions.h> | ||
21 | #include <asm/io.h> | ||
22 | #include <asm/ibm4xx.h> | ||
23 | #include <platforms/4xx/walnut.h> | ||
24 | |||
25 | /* these should be in platforms/4xx/walnut.h ? */ | ||
26 | #define WALNUT_FLASH_ONBD_N(x) (x & 0x02) | ||
27 | #define WALNUT_FLASH_SRAM_SEL(x) (x & 0x01) | ||
28 | #define WALNUT_FLASH_LOW 0xFFF00000 | ||
29 | #define WALNUT_FLASH_HIGH 0xFFF80000 | ||
30 | #define WALNUT_FLASH_SIZE 0x80000 | ||
31 | |||
32 | static struct mtd_info *flash; | ||
33 | |||
34 | static struct map_info walnut_map = { | ||
35 | .name = "Walnut flash", | ||
36 | .size = WALNUT_FLASH_SIZE, | ||
37 | .bankwidth = 1, | ||
38 | }; | ||
39 | |||
40 | /* Actually, OpenBIOS is the last 128 KiB of the flash - better | ||
41 | * partitioning could be made */ | ||
42 | static struct mtd_partition walnut_partitions[] = { | ||
43 | { | ||
44 | .name = "OpenBIOS", | ||
45 | .offset = 0x0, | ||
46 | .size = WALNUT_FLASH_SIZE, | ||
47 | /*.mask_flags = MTD_WRITEABLE, */ /* force read-only */ | ||
48 | } | ||
49 | }; | ||
50 | |||
51 | int __init init_walnut(void) | ||
52 | { | ||
53 | u8 fpga_brds1; | ||
54 | void *fpga_brds1_adr; | ||
55 | void *fpga_status_adr; | ||
56 | unsigned long flash_base; | ||
57 | |||
58 | /* this should already be mapped (platform/4xx/walnut.c) */ | ||
59 | fpga_status_adr = ioremap(WALNUT_FPGA_BASE, 8); | ||
60 | if (!fpga_status_adr) | ||
61 | return -ENOMEM; | ||
62 | |||
63 | fpga_brds1_adr = fpga_status_adr+5; | ||
64 | fpga_brds1 = readb(fpga_brds1_adr); | ||
65 | /* iounmap(fpga_status_adr); */ | ||
66 | |||
67 | if (WALNUT_FLASH_ONBD_N(fpga_brds1)) { | ||
68 | printk("The on-board flash is disabled (U79 sw 5)!"); | ||
69 | iounmap(fpga_status_adr); | ||
70 | return -EIO; | ||
71 | } | ||
72 | if (WALNUT_FLASH_SRAM_SEL(fpga_brds1)) | ||
73 | flash_base = WALNUT_FLASH_LOW; | ||
74 | else | ||
75 | flash_base = WALNUT_FLASH_HIGH; | ||
76 | |||
77 | walnut_map.phys = flash_base; | ||
78 | walnut_map.virt = | ||
79 | (void __iomem *)ioremap(flash_base, walnut_map.size); | ||
80 | |||
81 | if (!walnut_map.virt) { | ||
82 | printk("Failed to ioremap flash.\n"); | ||
83 | iounmap(fpga_status_adr); | ||
84 | return -EIO; | ||
85 | } | ||
86 | |||
87 | simple_map_init(&walnut_map); | ||
88 | |||
89 | flash = do_map_probe("jedec_probe", &walnut_map); | ||
90 | if (flash) { | ||
91 | flash->owner = THIS_MODULE; | ||
92 | add_mtd_partitions(flash, walnut_partitions, | ||
93 | ARRAY_SIZE(walnut_partitions)); | ||
94 | } else { | ||
95 | printk("map probe failed for flash\n"); | ||
96 | iounmap(fpga_status_adr); | ||
97 | return -ENXIO; | ||
98 | } | ||
99 | |||
100 | iounmap(fpga_status_adr); | ||
101 | return 0; | ||
102 | } | ||
103 | |||
104 | static void __exit cleanup_walnut(void) | ||
105 | { | ||
106 | if (flash) { | ||
107 | del_mtd_partitions(flash); | ||
108 | map_destroy(flash); | ||
109 | } | ||
110 | |||
111 | if (walnut_map.virt) { | ||
112 | iounmap((void *)walnut_map.virt); | ||
113 | walnut_map.virt = 0; | ||
114 | } | ||
115 | } | ||
116 | |||
117 | module_init(init_walnut); | ||
118 | module_exit(cleanup_walnut); | ||
119 | |||
120 | MODULE_LICENSE("GPL"); | ||
121 | MODULE_AUTHOR("Heikki Lindholm <holindho@infradead.org>"); | ||
122 | MODULE_DESCRIPTION("MTD map and partitions for IBM 405GP Walnut boards"); | ||
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 1c74762dec89..963840e9b5bf 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c | |||
@@ -348,7 +348,7 @@ static void mtdchar_erase_callback (struct erase_info *instr) | |||
348 | wake_up((wait_queue_head_t *)instr->priv); | 348 | wake_up((wait_queue_head_t *)instr->priv); |
349 | } | 349 | } |
350 | 350 | ||
351 | #if defined(CONFIG_MTD_OTP) || defined(CONFIG_MTD_ONENAND_OTP) | 351 | #ifdef CONFIG_HAVE_MTD_OTP |
352 | static int otp_select_filemode(struct mtd_file_info *mfi, int mode) | 352 | static int otp_select_filemode(struct mtd_file_info *mfi, int mode) |
353 | { | 353 | { |
354 | struct mtd_info *mtd = mfi->mtd; | 354 | struct mtd_info *mtd = mfi->mtd; |
@@ -665,7 +665,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file, | |||
665 | break; | 665 | break; |
666 | } | 666 | } |
667 | 667 | ||
668 | #if defined(CONFIG_MTD_OTP) || defined(CONFIG_MTD_ONENAND_OTP) | 668 | #ifdef CONFIG_HAVE_MTD_OTP |
669 | case OTPSELECT: | 669 | case OTPSELECT: |
670 | { | 670 | { |
671 | int mode; | 671 | int mode; |
diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c index 2972a5edb73d..789842d0e6f2 100644 --- a/drivers/mtd/mtdconcat.c +++ b/drivers/mtd/mtdconcat.c | |||
@@ -444,7 +444,7 @@ static int concat_erase(struct mtd_info *mtd, struct erase_info *instr) | |||
444 | return -EINVAL; | 444 | return -EINVAL; |
445 | } | 445 | } |
446 | 446 | ||
447 | instr->fail_addr = 0xffffffff; | 447 | instr->fail_addr = MTD_FAIL_ADDR_UNKNOWN; |
448 | 448 | ||
449 | /* make a local copy of instr to avoid modifying the caller's struct */ | 449 | /* make a local copy of instr to avoid modifying the caller's struct */ |
450 | erase = kmalloc(sizeof (struct erase_info), GFP_KERNEL); | 450 | erase = kmalloc(sizeof (struct erase_info), GFP_KERNEL); |
@@ -493,7 +493,7 @@ static int concat_erase(struct mtd_info *mtd, struct erase_info *instr) | |||
493 | /* sanity check: should never happen since | 493 | /* sanity check: should never happen since |
494 | * block alignment has been checked above */ | 494 | * block alignment has been checked above */ |
495 | BUG_ON(err == -EINVAL); | 495 | BUG_ON(err == -EINVAL); |
496 | if (erase->fail_addr != 0xffffffff) | 496 | if (erase->fail_addr != MTD_FAIL_ADDR_UNKNOWN) |
497 | instr->fail_addr = erase->fail_addr + offset; | 497 | instr->fail_addr = erase->fail_addr + offset; |
498 | break; | 498 | break; |
499 | } | 499 | } |
diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c index 5a680e1e61f1..aebb3b27edbd 100644 --- a/drivers/mtd/mtdoops.c +++ b/drivers/mtd/mtdoops.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <linux/interrupt.h> | 33 | #include <linux/interrupt.h> |
34 | #include <linux/mtd/mtd.h> | 34 | #include <linux/mtd/mtd.h> |
35 | 35 | ||
36 | #define MTDOOPS_KERNMSG_MAGIC 0x5d005d00 | ||
36 | #define OOPS_PAGE_SIZE 4096 | 37 | #define OOPS_PAGE_SIZE 4096 |
37 | 38 | ||
38 | static struct mtdoops_context { | 39 | static struct mtdoops_context { |
@@ -99,7 +100,7 @@ static void mtdoops_inc_counter(struct mtdoops_context *cxt) | |||
99 | int ret; | 100 | int ret; |
100 | 101 | ||
101 | cxt->nextpage++; | 102 | cxt->nextpage++; |
102 | if (cxt->nextpage > cxt->oops_pages) | 103 | if (cxt->nextpage >= cxt->oops_pages) |
103 | cxt->nextpage = 0; | 104 | cxt->nextpage = 0; |
104 | cxt->nextcount++; | 105 | cxt->nextcount++; |
105 | if (cxt->nextcount == 0xffffffff) | 106 | if (cxt->nextcount == 0xffffffff) |
@@ -141,7 +142,7 @@ static void mtdoops_workfunc_erase(struct work_struct *work) | |||
141 | mod = (cxt->nextpage * OOPS_PAGE_SIZE) % mtd->erasesize; | 142 | mod = (cxt->nextpage * OOPS_PAGE_SIZE) % mtd->erasesize; |
142 | if (mod != 0) { | 143 | if (mod != 0) { |
143 | cxt->nextpage = cxt->nextpage + ((mtd->erasesize - mod) / OOPS_PAGE_SIZE); | 144 | cxt->nextpage = cxt->nextpage + ((mtd->erasesize - mod) / OOPS_PAGE_SIZE); |
144 | if (cxt->nextpage > cxt->oops_pages) | 145 | if (cxt->nextpage >= cxt->oops_pages) |
145 | cxt->nextpage = 0; | 146 | cxt->nextpage = 0; |
146 | } | 147 | } |
147 | 148 | ||
@@ -158,7 +159,7 @@ badblock: | |||
158 | cxt->nextpage * OOPS_PAGE_SIZE); | 159 | cxt->nextpage * OOPS_PAGE_SIZE); |
159 | i++; | 160 | i++; |
160 | cxt->nextpage = cxt->nextpage + (mtd->erasesize / OOPS_PAGE_SIZE); | 161 | cxt->nextpage = cxt->nextpage + (mtd->erasesize / OOPS_PAGE_SIZE); |
161 | if (cxt->nextpage > cxt->oops_pages) | 162 | if (cxt->nextpage >= cxt->oops_pages) |
162 | cxt->nextpage = 0; | 163 | cxt->nextpage = 0; |
163 | if (i == (cxt->oops_pages / (mtd->erasesize / OOPS_PAGE_SIZE))) { | 164 | if (i == (cxt->oops_pages / (mtd->erasesize / OOPS_PAGE_SIZE))) { |
164 | printk(KERN_ERR "mtdoops: All blocks bad!\n"); | 165 | printk(KERN_ERR "mtdoops: All blocks bad!\n"); |
@@ -224,40 +225,40 @@ static void find_next_position(struct mtdoops_context *cxt) | |||
224 | { | 225 | { |
225 | struct mtd_info *mtd = cxt->mtd; | 226 | struct mtd_info *mtd = cxt->mtd; |
226 | int ret, page, maxpos = 0; | 227 | int ret, page, maxpos = 0; |
227 | u32 count, maxcount = 0xffffffff; | 228 | u32 count[2], maxcount = 0xffffffff; |
228 | size_t retlen; | 229 | size_t retlen; |
229 | 230 | ||
230 | for (page = 0; page < cxt->oops_pages; page++) { | 231 | for (page = 0; page < cxt->oops_pages; page++) { |
231 | ret = mtd->read(mtd, page * OOPS_PAGE_SIZE, 4, &retlen, (u_char *) &count); | 232 | ret = mtd->read(mtd, page * OOPS_PAGE_SIZE, 8, &retlen, (u_char *) &count[0]); |
232 | if ((retlen != 4) || ((ret < 0) && (ret != -EUCLEAN))) { | 233 | if ((retlen != 8) || ((ret < 0) && (ret != -EUCLEAN))) { |
233 | printk(KERN_ERR "mtdoops: Read failure at %d (%td of 4 read)" | 234 | printk(KERN_ERR "mtdoops: Read failure at %d (%td of 8 read)" |
234 | ", err %d.\n", page * OOPS_PAGE_SIZE, retlen, ret); | 235 | ", err %d.\n", page * OOPS_PAGE_SIZE, retlen, ret); |
235 | continue; | 236 | continue; |
236 | } | 237 | } |
237 | 238 | ||
238 | if (count == 0xffffffff) | 239 | if (count[1] != MTDOOPS_KERNMSG_MAGIC) |
240 | continue; | ||
241 | if (count[0] == 0xffffffff) | ||
239 | continue; | 242 | continue; |
240 | if (maxcount == 0xffffffff) { | 243 | if (maxcount == 0xffffffff) { |
241 | maxcount = count; | 244 | maxcount = count[0]; |
242 | maxpos = page; | 245 | maxpos = page; |
243 | } else if ((count < 0x40000000) && (maxcount > 0xc0000000)) { | 246 | } else if ((count[0] < 0x40000000) && (maxcount > 0xc0000000)) { |
244 | maxcount = count; | 247 | maxcount = count[0]; |
245 | maxpos = page; | 248 | maxpos = page; |
246 | } else if ((count > maxcount) && (count < 0xc0000000)) { | 249 | } else if ((count[0] > maxcount) && (count[0] < 0xc0000000)) { |
247 | maxcount = count; | 250 | maxcount = count[0]; |
248 | maxpos = page; | 251 | maxpos = page; |
249 | } else if ((count > maxcount) && (count > 0xc0000000) | 252 | } else if ((count[0] > maxcount) && (count[0] > 0xc0000000) |
250 | && (maxcount > 0x80000000)) { | 253 | && (maxcount > 0x80000000)) { |
251 | maxcount = count; | 254 | maxcount = count[0]; |
252 | maxpos = page; | 255 | maxpos = page; |
253 | } | 256 | } |
254 | } | 257 | } |
255 | if (maxcount == 0xffffffff) { | 258 | if (maxcount == 0xffffffff) { |
256 | cxt->nextpage = 0; | 259 | cxt->nextpage = 0; |
257 | cxt->nextcount = 1; | 260 | cxt->nextcount = 1; |
258 | cxt->ready = 1; | 261 | schedule_work(&cxt->work_erase); |
259 | printk(KERN_DEBUG "mtdoops: Ready %d, %d (first init)\n", | ||
260 | cxt->nextpage, cxt->nextcount); | ||
261 | return; | 262 | return; |
262 | } | 263 | } |
263 | 264 | ||
@@ -358,8 +359,9 @@ mtdoops_console_write(struct console *co, const char *s, unsigned int count) | |||
358 | 359 | ||
359 | if (cxt->writecount == 0) { | 360 | if (cxt->writecount == 0) { |
360 | u32 *stamp = cxt->oops_buf; | 361 | u32 *stamp = cxt->oops_buf; |
361 | *stamp = cxt->nextcount; | 362 | *stamp++ = cxt->nextcount; |
362 | cxt->writecount = 4; | 363 | *stamp = MTDOOPS_KERNMSG_MAGIC; |
364 | cxt->writecount = 8; | ||
363 | } | 365 | } |
364 | 366 | ||
365 | if ((count + cxt->writecount) > OOPS_PAGE_SIZE) | 367 | if ((count + cxt->writecount) > OOPS_PAGE_SIZE) |
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index 9a06dc93ee0d..3728913fa5fa 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c | |||
@@ -214,7 +214,7 @@ static int part_erase(struct mtd_info *mtd, struct erase_info *instr) | |||
214 | instr->addr += part->offset; | 214 | instr->addr += part->offset; |
215 | ret = part->master->erase(part->master, instr); | 215 | ret = part->master->erase(part->master, instr); |
216 | if (ret) { | 216 | if (ret) { |
217 | if (instr->fail_addr != 0xffffffff) | 217 | if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN) |
218 | instr->fail_addr -= part->offset; | 218 | instr->fail_addr -= part->offset; |
219 | instr->addr -= part->offset; | 219 | instr->addr -= part->offset; |
220 | } | 220 | } |
@@ -226,7 +226,7 @@ void mtd_erase_callback(struct erase_info *instr) | |||
226 | if (instr->mtd->erase == part_erase) { | 226 | if (instr->mtd->erase == part_erase) { |
227 | struct mtd_part *part = PART(instr->mtd); | 227 | struct mtd_part *part = PART(instr->mtd); |
228 | 228 | ||
229 | if (instr->fail_addr != 0xffffffff) | 229 | if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN) |
230 | instr->fail_addr -= part->offset; | 230 | instr->fail_addr -= part->offset; |
231 | instr->addr -= part->offset; | 231 | instr->addr -= part->offset; |
232 | } | 232 | } |
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig index 41f361c49b32..1c2e9450d663 100644 --- a/drivers/mtd/nand/Kconfig +++ b/drivers/mtd/nand/Kconfig | |||
@@ -56,6 +56,12 @@ config MTD_NAND_H1900 | |||
56 | help | 56 | help |
57 | This enables the driver for the iPAQ h1900 flash. | 57 | This enables the driver for the iPAQ h1900 flash. |
58 | 58 | ||
59 | config MTD_NAND_GPIO | ||
60 | tristate "GPIO NAND Flash driver" | ||
61 | depends on GENERIC_GPIO && ARM | ||
62 | help | ||
63 | This enables a GPIO based NAND flash driver. | ||
64 | |||
59 | config MTD_NAND_SPIA | 65 | config MTD_NAND_SPIA |
60 | tristate "NAND Flash device on SPIA board" | 66 | tristate "NAND Flash device on SPIA board" |
61 | depends on ARCH_P720T | 67 | depends on ARCH_P720T |
@@ -68,12 +74,6 @@ config MTD_NAND_AMS_DELTA | |||
68 | help | 74 | help |
69 | Support for NAND flash on Amstrad E3 (Delta). | 75 | Support for NAND flash on Amstrad E3 (Delta). |
70 | 76 | ||
71 | config MTD_NAND_TOTO | ||
72 | tristate "NAND Flash device on TOTO board" | ||
73 | depends on ARCH_OMAP && BROKEN | ||
74 | help | ||
75 | Support for NAND flash on Texas Instruments Toto platform. | ||
76 | |||
77 | config MTD_NAND_TS7250 | 77 | config MTD_NAND_TS7250 |
78 | tristate "NAND Flash device on TS-7250 board" | 78 | tristate "NAND Flash device on TS-7250 board" |
79 | depends on MACH_TS72XX | 79 | depends on MACH_TS72XX |
@@ -163,13 +163,6 @@ config MTD_NAND_S3C2410_HWECC | |||
163 | incorrect ECC generation, and if using these, the default of | 163 | incorrect ECC generation, and if using these, the default of |
164 | software ECC is preferable. | 164 | software ECC is preferable. |
165 | 165 | ||
166 | config MTD_NAND_NDFC | ||
167 | tristate "NDFC NanD Flash Controller" | ||
168 | depends on 4xx && !PPC_MERGE | ||
169 | select MTD_NAND_ECC_SMC | ||
170 | help | ||
171 | NDFC Nand Flash Controllers are integrated in IBM/AMCC's 4xx SoCs | ||
172 | |||
173 | config MTD_NAND_S3C2410_CLKSTOP | 166 | config MTD_NAND_S3C2410_CLKSTOP |
174 | bool "S3C2410 NAND IDLE clock stop" | 167 | bool "S3C2410 NAND IDLE clock stop" |
175 | depends on MTD_NAND_S3C2410 | 168 | depends on MTD_NAND_S3C2410 |
@@ -340,6 +333,13 @@ config MTD_NAND_PXA3xx | |||
340 | This enables the driver for the NAND flash device found on | 333 | This enables the driver for the NAND flash device found on |
341 | PXA3xx processors | 334 | PXA3xx processors |
342 | 335 | ||
336 | config MTD_NAND_PXA3xx_BUILTIN | ||
337 | bool "Use builtin definitions for some NAND chips (deprecated)" | ||
338 | depends on MTD_NAND_PXA3xx | ||
339 | help | ||
340 | This enables builtin definitions for some NAND chips. This | ||
341 | is deprecated in favor of platform specific data. | ||
342 | |||
343 | config MTD_NAND_CM_X270 | 343 | config MTD_NAND_CM_X270 |
344 | tristate "Support for NAND Flash on CM-X270 modules" | 344 | tristate "Support for NAND Flash on CM-X270 modules" |
345 | depends on MTD_NAND && MACH_ARMCORE | 345 | depends on MTD_NAND && MACH_ARMCORE |
@@ -400,10 +400,24 @@ config MTD_NAND_FSL_ELBC | |||
400 | 400 | ||
401 | config MTD_NAND_FSL_UPM | 401 | config MTD_NAND_FSL_UPM |
402 | tristate "Support for NAND on Freescale UPM" | 402 | tristate "Support for NAND on Freescale UPM" |
403 | depends on MTD_NAND && OF_GPIO && (PPC_83xx || PPC_85xx) | 403 | depends on MTD_NAND && (PPC_83xx || PPC_85xx) |
404 | select FSL_LBC | 404 | select FSL_LBC |
405 | help | 405 | help |
406 | Enables support for NAND Flash chips wired onto Freescale PowerPC | 406 | Enables support for NAND Flash chips wired onto Freescale PowerPC |
407 | processor localbus with User-Programmable Machine support. | 407 | processor localbus with User-Programmable Machine support. |
408 | 408 | ||
409 | config MTD_NAND_MXC | ||
410 | tristate "MXC NAND support" | ||
411 | depends on ARCH_MX2 | ||
412 | help | ||
413 | This enables the driver for the NAND flash controller on the | ||
414 | MXC processors. | ||
415 | |||
416 | config MTD_NAND_SH_FLCTL | ||
417 | tristate "Support for NAND on Renesas SuperH FLCTL" | ||
418 | depends on MTD_NAND && SUPERH && CPU_SUBTYPE_SH7723 | ||
419 | help | ||
420 | Several Renesas SuperH CPU has FLCTL. This option enables support | ||
421 | for NAND Flash using FLCTL. This driver support SH7723. | ||
422 | |||
409 | endif # MTD_NAND | 423 | endif # MTD_NAND |
diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile index b786c5da82da..b661586afbfc 100644 --- a/drivers/mtd/nand/Makefile +++ b/drivers/mtd/nand/Makefile | |||
@@ -8,7 +8,6 @@ obj-$(CONFIG_MTD_NAND_IDS) += nand_ids.o | |||
8 | obj-$(CONFIG_MTD_NAND_CAFE) += cafe_nand.o | 8 | obj-$(CONFIG_MTD_NAND_CAFE) += cafe_nand.o |
9 | obj-$(CONFIG_MTD_NAND_SPIA) += spia.o | 9 | obj-$(CONFIG_MTD_NAND_SPIA) += spia.o |
10 | obj-$(CONFIG_MTD_NAND_AMS_DELTA) += ams-delta.o | 10 | obj-$(CONFIG_MTD_NAND_AMS_DELTA) += ams-delta.o |
11 | obj-$(CONFIG_MTD_NAND_TOTO) += toto.o | ||
12 | obj-$(CONFIG_MTD_NAND_AUTCPU12) += autcpu12.o | 11 | obj-$(CONFIG_MTD_NAND_AUTCPU12) += autcpu12.o |
13 | obj-$(CONFIG_MTD_NAND_EDB7312) += edb7312.o | 12 | obj-$(CONFIG_MTD_NAND_EDB7312) += edb7312.o |
14 | obj-$(CONFIG_MTD_NAND_AU1550) += au1550nd.o | 13 | obj-$(CONFIG_MTD_NAND_AU1550) += au1550nd.o |
@@ -24,6 +23,7 @@ obj-$(CONFIG_MTD_NAND_NANDSIM) += nandsim.o | |||
24 | obj-$(CONFIG_MTD_NAND_CS553X) += cs553x_nand.o | 23 | obj-$(CONFIG_MTD_NAND_CS553X) += cs553x_nand.o |
25 | obj-$(CONFIG_MTD_NAND_NDFC) += ndfc.o | 24 | obj-$(CONFIG_MTD_NAND_NDFC) += ndfc.o |
26 | obj-$(CONFIG_MTD_NAND_ATMEL) += atmel_nand.o | 25 | obj-$(CONFIG_MTD_NAND_ATMEL) += atmel_nand.o |
26 | obj-$(CONFIG_MTD_NAND_GPIO) += gpio.o | ||
27 | obj-$(CONFIG_MTD_NAND_CM_X270) += cmx270_nand.o | 27 | obj-$(CONFIG_MTD_NAND_CM_X270) += cmx270_nand.o |
28 | obj-$(CONFIG_MTD_NAND_BASLER_EXCITE) += excite_nandflash.o | 28 | obj-$(CONFIG_MTD_NAND_BASLER_EXCITE) += excite_nandflash.o |
29 | obj-$(CONFIG_MTD_NAND_PXA3xx) += pxa3xx_nand.o | 29 | obj-$(CONFIG_MTD_NAND_PXA3xx) += pxa3xx_nand.o |
@@ -34,5 +34,7 @@ obj-$(CONFIG_MTD_NAND_PASEMI) += pasemi_nand.o | |||
34 | obj-$(CONFIG_MTD_NAND_ORION) += orion_nand.o | 34 | obj-$(CONFIG_MTD_NAND_ORION) += orion_nand.o |
35 | obj-$(CONFIG_MTD_NAND_FSL_ELBC) += fsl_elbc_nand.o | 35 | obj-$(CONFIG_MTD_NAND_FSL_ELBC) += fsl_elbc_nand.o |
36 | obj-$(CONFIG_MTD_NAND_FSL_UPM) += fsl_upm.o | 36 | obj-$(CONFIG_MTD_NAND_FSL_UPM) += fsl_upm.o |
37 | obj-$(CONFIG_MTD_NAND_SH_FLCTL) += sh_flctl.o | ||
38 | obj-$(CONFIG_MTD_NAND_MXC) += mxc_nand.o | ||
37 | 39 | ||
38 | nand-objs := nand_base.o nand_bbt.o | 40 | nand-objs := nand_base.o nand_bbt.o |
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c index 3387e0d5076b..c98c1570a40b 100644 --- a/drivers/mtd/nand/atmel_nand.c +++ b/drivers/mtd/nand/atmel_nand.c | |||
@@ -174,48 +174,6 @@ static void atmel_write_buf16(struct mtd_info *mtd, const u8 *buf, int len) | |||
174 | } | 174 | } |
175 | 175 | ||
176 | /* | 176 | /* |
177 | * write oob for small pages | ||
178 | */ | ||
179 | static int atmel_nand_write_oob_512(struct mtd_info *mtd, | ||
180 | struct nand_chip *chip, int page) | ||
181 | { | ||
182 | int chunk = chip->ecc.bytes + chip->ecc.prepad + chip->ecc.postpad; | ||
183 | int eccsize = chip->ecc.size, length = mtd->oobsize; | ||
184 | int len, pos, status = 0; | ||
185 | const uint8_t *bufpoi = chip->oob_poi; | ||
186 | |||
187 | pos = eccsize + chunk; | ||
188 | |||
189 | chip->cmdfunc(mtd, NAND_CMD_SEQIN, pos, page); | ||
190 | len = min_t(int, length, chunk); | ||
191 | chip->write_buf(mtd, bufpoi, len); | ||
192 | bufpoi += len; | ||
193 | length -= len; | ||
194 | if (length > 0) | ||
195 | chip->write_buf(mtd, bufpoi, length); | ||
196 | |||
197 | chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1); | ||
198 | status = chip->waitfunc(mtd, chip); | ||
199 | |||
200 | return status & NAND_STATUS_FAIL ? -EIO : 0; | ||
201 | |||
202 | } | ||
203 | |||
204 | /* | ||
205 | * read oob for small pages | ||
206 | */ | ||
207 | static int atmel_nand_read_oob_512(struct mtd_info *mtd, | ||
208 | struct nand_chip *chip, int page, int sndcmd) | ||
209 | { | ||
210 | if (sndcmd) { | ||
211 | chip->cmdfunc(mtd, NAND_CMD_READOOB, 0, page); | ||
212 | sndcmd = 0; | ||
213 | } | ||
214 | chip->read_buf(mtd, chip->oob_poi, mtd->oobsize); | ||
215 | return sndcmd; | ||
216 | } | ||
217 | |||
218 | /* | ||
219 | * Calculate HW ECC | 177 | * Calculate HW ECC |
220 | * | 178 | * |
221 | * function called after a write | 179 | * function called after a write |
@@ -235,14 +193,14 @@ static int atmel_nand_calculate(struct mtd_info *mtd, | |||
235 | /* get the first 2 ECC bytes */ | 193 | /* get the first 2 ECC bytes */ |
236 | ecc_value = ecc_readl(host->ecc, PR); | 194 | ecc_value = ecc_readl(host->ecc, PR); |
237 | 195 | ||
238 | ecc_code[eccpos[0]] = ecc_value & 0xFF; | 196 | ecc_code[0] = ecc_value & 0xFF; |
239 | ecc_code[eccpos[1]] = (ecc_value >> 8) & 0xFF; | 197 | ecc_code[1] = (ecc_value >> 8) & 0xFF; |
240 | 198 | ||
241 | /* get the last 2 ECC bytes */ | 199 | /* get the last 2 ECC bytes */ |
242 | ecc_value = ecc_readl(host->ecc, NPR) & ATMEL_ECC_NPARITY; | 200 | ecc_value = ecc_readl(host->ecc, NPR) & ATMEL_ECC_NPARITY; |
243 | 201 | ||
244 | ecc_code[eccpos[2]] = ecc_value & 0xFF; | 202 | ecc_code[2] = ecc_value & 0xFF; |
245 | ecc_code[eccpos[3]] = (ecc_value >> 8) & 0xFF; | 203 | ecc_code[3] = (ecc_value >> 8) & 0xFF; |
246 | 204 | ||
247 | return 0; | 205 | return 0; |
248 | } | 206 | } |
@@ -476,14 +434,12 @@ static int __init atmel_nand_probe(struct platform_device *pdev) | |||
476 | res = -EIO; | 434 | res = -EIO; |
477 | goto err_ecc_ioremap; | 435 | goto err_ecc_ioremap; |
478 | } | 436 | } |
479 | nand_chip->ecc.mode = NAND_ECC_HW_SYNDROME; | 437 | nand_chip->ecc.mode = NAND_ECC_HW; |
480 | nand_chip->ecc.calculate = atmel_nand_calculate; | 438 | nand_chip->ecc.calculate = atmel_nand_calculate; |
481 | nand_chip->ecc.correct = atmel_nand_correct; | 439 | nand_chip->ecc.correct = atmel_nand_correct; |
482 | nand_chip->ecc.hwctl = atmel_nand_hwctl; | 440 | nand_chip->ecc.hwctl = atmel_nand_hwctl; |
483 | nand_chip->ecc.read_page = atmel_nand_read_page; | 441 | nand_chip->ecc.read_page = atmel_nand_read_page; |
484 | nand_chip->ecc.bytes = 4; | 442 | nand_chip->ecc.bytes = 4; |
485 | nand_chip->ecc.prepad = 0; | ||
486 | nand_chip->ecc.postpad = 0; | ||
487 | } | 443 | } |
488 | 444 | ||
489 | nand_chip->chip_delay = 20; /* 20us command delay time */ | 445 | nand_chip->chip_delay = 20; /* 20us command delay time */ |
@@ -514,7 +470,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev) | |||
514 | goto err_scan_ident; | 470 | goto err_scan_ident; |
515 | } | 471 | } |
516 | 472 | ||
517 | if (nand_chip->ecc.mode == NAND_ECC_HW_SYNDROME) { | 473 | if (nand_chip->ecc.mode == NAND_ECC_HW) { |
518 | /* ECC is calculated for the whole page (1 step) */ | 474 | /* ECC is calculated for the whole page (1 step) */ |
519 | nand_chip->ecc.size = mtd->writesize; | 475 | nand_chip->ecc.size = mtd->writesize; |
520 | 476 | ||
@@ -522,8 +478,6 @@ static int __init atmel_nand_probe(struct platform_device *pdev) | |||
522 | switch (mtd->writesize) { | 478 | switch (mtd->writesize) { |
523 | case 512: | 479 | case 512: |
524 | nand_chip->ecc.layout = &atmel_oobinfo_small; | 480 | nand_chip->ecc.layout = &atmel_oobinfo_small; |
525 | nand_chip->ecc.read_oob = atmel_nand_read_oob_512; | ||
526 | nand_chip->ecc.write_oob = atmel_nand_write_oob_512; | ||
527 | ecc_writel(host->ecc, MR, ATMEL_ECC_PAGESIZE_528); | 481 | ecc_writel(host->ecc, MR, ATMEL_ECC_PAGESIZE_528); |
528 | break; | 482 | break; |
529 | case 1024: | 483 | case 1024: |
diff --git a/drivers/mtd/nand/cs553x_nand.c b/drivers/mtd/nand/cs553x_nand.c index 3370a800fd36..9f1b451005ca 100644 --- a/drivers/mtd/nand/cs553x_nand.c +++ b/drivers/mtd/nand/cs553x_nand.c | |||
@@ -289,8 +289,10 @@ static int __init cs553x_init(void) | |||
289 | int i; | 289 | int i; |
290 | uint64_t val; | 290 | uint64_t val; |
291 | 291 | ||
292 | #ifdef CONFIG_MTD_PARTITIONS | ||
292 | int mtd_parts_nb = 0; | 293 | int mtd_parts_nb = 0; |
293 | struct mtd_partition *mtd_parts = NULL; | 294 | struct mtd_partition *mtd_parts = NULL; |
295 | #endif | ||
294 | 296 | ||
295 | /* If the CPU isn't a Geode GX or LX, abort */ | 297 | /* If the CPU isn't a Geode GX or LX, abort */ |
296 | if (!is_geode()) | 298 | if (!is_geode()) |
diff --git a/drivers/mtd/nand/fsl_elbc_nand.c b/drivers/mtd/nand/fsl_elbc_nand.c index 98ad3cefcaf4..4aa5bd6158da 100644 --- a/drivers/mtd/nand/fsl_elbc_nand.c +++ b/drivers/mtd/nand/fsl_elbc_nand.c | |||
@@ -918,8 +918,7 @@ static int __devinit fsl_elbc_chip_probe(struct fsl_elbc_ctrl *ctrl, | |||
918 | 918 | ||
919 | #ifdef CONFIG_MTD_OF_PARTS | 919 | #ifdef CONFIG_MTD_OF_PARTS |
920 | if (ret == 0) { | 920 | if (ret == 0) { |
921 | ret = of_mtd_parse_partitions(priv->dev, &priv->mtd, | 921 | ret = of_mtd_parse_partitions(priv->dev, node, &parts); |
922 | node, &parts); | ||
923 | if (ret < 0) | 922 | if (ret < 0) |
924 | goto err; | 923 | goto err; |
925 | } | 924 | } |
diff --git a/drivers/mtd/nand/fsl_upm.c b/drivers/mtd/nand/fsl_upm.c index 1ebfd87f00b4..024e3fffd4bb 100644 --- a/drivers/mtd/nand/fsl_upm.c +++ b/drivers/mtd/nand/fsl_upm.c | |||
@@ -13,6 +13,7 @@ | |||
13 | 13 | ||
14 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
16 | #include <linux/delay.h> | ||
16 | #include <linux/mtd/nand.h> | 17 | #include <linux/mtd/nand.h> |
17 | #include <linux/mtd/nand_ecc.h> | 18 | #include <linux/mtd/nand_ecc.h> |
18 | #include <linux/mtd/partitions.h> | 19 | #include <linux/mtd/partitions.h> |
@@ -36,8 +37,6 @@ struct fsl_upm_nand { | |||
36 | uint8_t upm_cmd_offset; | 37 | uint8_t upm_cmd_offset; |
37 | void __iomem *io_base; | 38 | void __iomem *io_base; |
38 | int rnb_gpio; | 39 | int rnb_gpio; |
39 | const uint32_t *wait_pattern; | ||
40 | const uint32_t *wait_write; | ||
41 | int chip_delay; | 40 | int chip_delay; |
42 | }; | 41 | }; |
43 | 42 | ||
@@ -61,10 +60,11 @@ static void fun_wait_rnb(struct fsl_upm_nand *fun) | |||
61 | if (fun->rnb_gpio >= 0) { | 60 | if (fun->rnb_gpio >= 0) { |
62 | while (--cnt && !fun_chip_ready(&fun->mtd)) | 61 | while (--cnt && !fun_chip_ready(&fun->mtd)) |
63 | cpu_relax(); | 62 | cpu_relax(); |
63 | if (!cnt) | ||
64 | dev_err(fun->dev, "tired waiting for RNB\n"); | ||
65 | } else { | ||
66 | ndelay(100); | ||
64 | } | 67 | } |
65 | |||
66 | if (!cnt) | ||
67 | dev_err(fun->dev, "tired waiting for RNB\n"); | ||
68 | } | 68 | } |
69 | 69 | ||
70 | static void fun_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) | 70 | static void fun_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) |
@@ -89,8 +89,7 @@ static void fun_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) | |||
89 | 89 | ||
90 | fsl_upm_run_pattern(&fun->upm, fun->io_base, cmd); | 90 | fsl_upm_run_pattern(&fun->upm, fun->io_base, cmd); |
91 | 91 | ||
92 | if (fun->wait_pattern) | 92 | fun_wait_rnb(fun); |
93 | fun_wait_rnb(fun); | ||
94 | } | 93 | } |
95 | 94 | ||
96 | static uint8_t fun_read_byte(struct mtd_info *mtd) | 95 | static uint8_t fun_read_byte(struct mtd_info *mtd) |
@@ -116,14 +115,16 @@ static void fun_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len) | |||
116 | 115 | ||
117 | for (i = 0; i < len; i++) { | 116 | for (i = 0; i < len; i++) { |
118 | out_8(fun->chip.IO_ADDR_W, buf[i]); | 117 | out_8(fun->chip.IO_ADDR_W, buf[i]); |
119 | if (fun->wait_write) | 118 | fun_wait_rnb(fun); |
120 | fun_wait_rnb(fun); | ||
121 | } | 119 | } |
122 | } | 120 | } |
123 | 121 | ||
124 | static int __devinit fun_chip_init(struct fsl_upm_nand *fun) | 122 | static int __devinit fun_chip_init(struct fsl_upm_nand *fun, |
123 | const struct device_node *upm_np, | ||
124 | const struct resource *io_res) | ||
125 | { | 125 | { |
126 | int ret; | 126 | int ret; |
127 | struct device_node *flash_np; | ||
127 | #ifdef CONFIG_MTD_PARTITIONS | 128 | #ifdef CONFIG_MTD_PARTITIONS |
128 | static const char *part_types[] = { "cmdlinepart", NULL, }; | 129 | static const char *part_types[] = { "cmdlinepart", NULL, }; |
129 | #endif | 130 | #endif |
@@ -143,18 +144,37 @@ static int __devinit fun_chip_init(struct fsl_upm_nand *fun) | |||
143 | fun->mtd.priv = &fun->chip; | 144 | fun->mtd.priv = &fun->chip; |
144 | fun->mtd.owner = THIS_MODULE; | 145 | fun->mtd.owner = THIS_MODULE; |
145 | 146 | ||
147 | flash_np = of_get_next_child(upm_np, NULL); | ||
148 | if (!flash_np) | ||
149 | return -ENODEV; | ||
150 | |||
151 | fun->mtd.name = kasprintf(GFP_KERNEL, "%x.%s", io_res->start, | ||
152 | flash_np->name); | ||
153 | if (!fun->mtd.name) { | ||
154 | ret = -ENOMEM; | ||
155 | goto err; | ||
156 | } | ||
157 | |||
146 | ret = nand_scan(&fun->mtd, 1); | 158 | ret = nand_scan(&fun->mtd, 1); |
147 | if (ret) | 159 | if (ret) |
148 | return ret; | 160 | goto err; |
149 | |||
150 | fun->mtd.name = fun->dev->bus_id; | ||
151 | 161 | ||
152 | #ifdef CONFIG_MTD_PARTITIONS | 162 | #ifdef CONFIG_MTD_PARTITIONS |
153 | ret = parse_mtd_partitions(&fun->mtd, part_types, &fun->parts, 0); | 163 | ret = parse_mtd_partitions(&fun->mtd, part_types, &fun->parts, 0); |
164 | |||
165 | #ifdef CONFIG_MTD_OF_PARTS | ||
166 | if (ret == 0) | ||
167 | ret = of_mtd_parse_partitions(fun->dev, &fun->mtd, | ||
168 | flash_np, &fun->parts); | ||
169 | #endif | ||
154 | if (ret > 0) | 170 | if (ret > 0) |
155 | return add_mtd_partitions(&fun->mtd, fun->parts, ret); | 171 | ret = add_mtd_partitions(&fun->mtd, fun->parts, ret); |
172 | else | ||
156 | #endif | 173 | #endif |
157 | return add_mtd_device(&fun->mtd); | 174 | ret = add_mtd_device(&fun->mtd); |
175 | err: | ||
176 | of_node_put(flash_np); | ||
177 | return ret; | ||
158 | } | 178 | } |
159 | 179 | ||
160 | static int __devinit fun_probe(struct of_device *ofdev, | 180 | static int __devinit fun_probe(struct of_device *ofdev, |
@@ -211,6 +231,12 @@ static int __devinit fun_probe(struct of_device *ofdev, | |||
211 | goto err2; | 231 | goto err2; |
212 | } | 232 | } |
213 | 233 | ||
234 | prop = of_get_property(ofdev->node, "chip-delay", NULL); | ||
235 | if (prop) | ||
236 | fun->chip_delay = *prop; | ||
237 | else | ||
238 | fun->chip_delay = 50; | ||
239 | |||
214 | fun->io_base = devm_ioremap_nocache(&ofdev->dev, io_res.start, | 240 | fun->io_base = devm_ioremap_nocache(&ofdev->dev, io_res.start, |
215 | io_res.end - io_res.start + 1); | 241 | io_res.end - io_res.start + 1); |
216 | if (!fun->io_base) { | 242 | if (!fun->io_base) { |
@@ -220,17 +246,8 @@ static int __devinit fun_probe(struct of_device *ofdev, | |||
220 | 246 | ||
221 | fun->dev = &ofdev->dev; | 247 | fun->dev = &ofdev->dev; |
222 | fun->last_ctrl = NAND_CLE; | 248 | fun->last_ctrl = NAND_CLE; |
223 | fun->wait_pattern = of_get_property(ofdev->node, "fsl,wait-pattern", | ||
224 | NULL); | ||
225 | fun->wait_write = of_get_property(ofdev->node, "fsl,wait-write", NULL); | ||
226 | |||
227 | prop = of_get_property(ofdev->node, "chip-delay", NULL); | ||
228 | if (prop) | ||
229 | fun->chip_delay = *prop; | ||
230 | else | ||
231 | fun->chip_delay = 50; | ||
232 | 249 | ||
233 | ret = fun_chip_init(fun); | 250 | ret = fun_chip_init(fun, ofdev->node, &io_res); |
234 | if (ret) | 251 | if (ret) |
235 | goto err2; | 252 | goto err2; |
236 | 253 | ||
@@ -251,6 +268,7 @@ static int __devexit fun_remove(struct of_device *ofdev) | |||
251 | struct fsl_upm_nand *fun = dev_get_drvdata(&ofdev->dev); | 268 | struct fsl_upm_nand *fun = dev_get_drvdata(&ofdev->dev); |
252 | 269 | ||
253 | nand_release(&fun->mtd); | 270 | nand_release(&fun->mtd); |
271 | kfree(fun->mtd.name); | ||
254 | 272 | ||
255 | if (fun->rnb_gpio >= 0) | 273 | if (fun->rnb_gpio >= 0) |
256 | gpio_free(fun->rnb_gpio); | 274 | gpio_free(fun->rnb_gpio); |
diff --git a/drivers/mtd/nand/gpio.c b/drivers/mtd/nand/gpio.c new file mode 100644 index 000000000000..8f902e75aa85 --- /dev/null +++ b/drivers/mtd/nand/gpio.c | |||
@@ -0,0 +1,375 @@ | |||
1 | /* | ||
2 | * drivers/mtd/nand/gpio.c | ||
3 | * | ||
4 | * Updated, and converted to generic GPIO based driver by Russell King. | ||
5 | * | ||
6 | * Written by Ben Dooks <ben@simtec.co.uk> | ||
7 | * Based on 2.4 version by Mark Whittaker | ||
8 | * | ||
9 | * © 2004 Simtec Electronics | ||
10 | * | ||
11 | * Device driver for NAND connected via GPIO | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify | ||
14 | * it under the terms of the GNU General Public License version 2 as | ||
15 | * published by the Free Software Foundation. | ||
16 | * | ||
17 | */ | ||
18 | |||
19 | #include <linux/kernel.h> | ||
20 | #include <linux/init.h> | ||
21 | #include <linux/slab.h> | ||
22 | #include <linux/module.h> | ||
23 | #include <linux/platform_device.h> | ||
24 | #include <linux/gpio.h> | ||
25 | #include <linux/io.h> | ||
26 | #include <linux/mtd/mtd.h> | ||
27 | #include <linux/mtd/nand.h> | ||
28 | #include <linux/mtd/partitions.h> | ||
29 | #include <linux/mtd/nand-gpio.h> | ||
30 | |||
31 | struct gpiomtd { | ||
32 | void __iomem *io_sync; | ||
33 | struct mtd_info mtd_info; | ||
34 | struct nand_chip nand_chip; | ||
35 | struct gpio_nand_platdata plat; | ||
36 | }; | ||
37 | |||
38 | #define gpio_nand_getpriv(x) container_of(x, struct gpiomtd, mtd_info) | ||
39 | |||
40 | |||
41 | #ifdef CONFIG_ARM | ||
42 | /* gpio_nand_dosync() | ||
43 | * | ||
44 | * Make sure the GPIO state changes occur in-order with writes to NAND | ||
45 | * memory region. | ||
46 | * Needed on PXA due to bus-reordering within the SoC itself (see section on | ||
47 | * I/O ordering in PXA manual (section 2.3, p35) | ||
48 | */ | ||
49 | static void gpio_nand_dosync(struct gpiomtd *gpiomtd) | ||
50 | { | ||
51 | unsigned long tmp; | ||
52 | |||
53 | if (gpiomtd->io_sync) { | ||
54 | /* | ||
55 | * Linux memory barriers don't cater for what's required here. | ||
56 | * What's required is what's here - a read from a separate | ||
57 | * region with a dependency on that read. | ||
58 | */ | ||
59 | tmp = readl(gpiomtd->io_sync); | ||
60 | asm volatile("mov %1, %0\n" : "=r" (tmp) : "r" (tmp)); | ||
61 | } | ||
62 | } | ||
63 | #else | ||
64 | static inline void gpio_nand_dosync(struct gpiomtd *gpiomtd) {} | ||
65 | #endif | ||
66 | |||
67 | static void gpio_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) | ||
68 | { | ||
69 | struct gpiomtd *gpiomtd = gpio_nand_getpriv(mtd); | ||
70 | |||
71 | gpio_nand_dosync(gpiomtd); | ||
72 | |||
73 | if (ctrl & NAND_CTRL_CHANGE) { | ||
74 | gpio_set_value(gpiomtd->plat.gpio_nce, !(ctrl & NAND_NCE)); | ||
75 | gpio_set_value(gpiomtd->plat.gpio_cle, !!(ctrl & NAND_CLE)); | ||
76 | gpio_set_value(gpiomtd->plat.gpio_ale, !!(ctrl & NAND_ALE)); | ||
77 | gpio_nand_dosync(gpiomtd); | ||
78 | } | ||
79 | if (cmd == NAND_CMD_NONE) | ||
80 | return; | ||
81 | |||
82 | writeb(cmd, gpiomtd->nand_chip.IO_ADDR_W); | ||
83 | gpio_nand_dosync(gpiomtd); | ||
84 | } | ||
85 | |||
86 | static void gpio_nand_writebuf(struct mtd_info *mtd, const u_char *buf, int len) | ||
87 | { | ||
88 | struct nand_chip *this = mtd->priv; | ||
89 | |||
90 | writesb(this->IO_ADDR_W, buf, len); | ||
91 | } | ||
92 | |||
93 | static void gpio_nand_readbuf(struct mtd_info *mtd, u_char *buf, int len) | ||
94 | { | ||
95 | struct nand_chip *this = mtd->priv; | ||
96 | |||
97 | readsb(this->IO_ADDR_R, buf, len); | ||
98 | } | ||
99 | |||
100 | static int gpio_nand_verifybuf(struct mtd_info *mtd, const u_char *buf, int len) | ||
101 | { | ||
102 | struct nand_chip *this = mtd->priv; | ||
103 | unsigned char read, *p = (unsigned char *) buf; | ||
104 | int i, err = 0; | ||
105 | |||
106 | for (i = 0; i < len; i++) { | ||
107 | read = readb(this->IO_ADDR_R); | ||
108 | if (read != p[i]) { | ||
109 | pr_debug("%s: err at %d (read %04x vs %04x)\n", | ||
110 | __func__, i, read, p[i]); | ||
111 | err = -EFAULT; | ||
112 | } | ||
113 | } | ||
114 | return err; | ||
115 | } | ||
116 | |||
117 | static void gpio_nand_writebuf16(struct mtd_info *mtd, const u_char *buf, | ||
118 | int len) | ||
119 | { | ||
120 | struct nand_chip *this = mtd->priv; | ||
121 | |||
122 | if (IS_ALIGNED((unsigned long)buf, 2)) { | ||
123 | writesw(this->IO_ADDR_W, buf, len>>1); | ||
124 | } else { | ||
125 | int i; | ||
126 | unsigned short *ptr = (unsigned short *)buf; | ||
127 | |||
128 | for (i = 0; i < len; i += 2, ptr++) | ||
129 | writew(*ptr, this->IO_ADDR_W); | ||
130 | } | ||
131 | } | ||
132 | |||
133 | static void gpio_nand_readbuf16(struct mtd_info *mtd, u_char *buf, int len) | ||
134 | { | ||
135 | struct nand_chip *this = mtd->priv; | ||
136 | |||
137 | if (IS_ALIGNED((unsigned long)buf, 2)) { | ||
138 | readsw(this->IO_ADDR_R, buf, len>>1); | ||
139 | } else { | ||
140 | int i; | ||
141 | unsigned short *ptr = (unsigned short *)buf; | ||
142 | |||
143 | for (i = 0; i < len; i += 2, ptr++) | ||
144 | *ptr = readw(this->IO_ADDR_R); | ||
145 | } | ||
146 | } | ||
147 | |||
148 | static int gpio_nand_verifybuf16(struct mtd_info *mtd, const u_char *buf, | ||
149 | int len) | ||
150 | { | ||
151 | struct nand_chip *this = mtd->priv; | ||
152 | unsigned short read, *p = (unsigned short *) buf; | ||
153 | int i, err = 0; | ||
154 | len >>= 1; | ||
155 | |||
156 | for (i = 0; i < len; i++) { | ||
157 | read = readw(this->IO_ADDR_R); | ||
158 | if (read != p[i]) { | ||
159 | pr_debug("%s: err at %d (read %04x vs %04x)\n", | ||
160 | __func__, i, read, p[i]); | ||
161 | err = -EFAULT; | ||
162 | } | ||
163 | } | ||
164 | return err; | ||
165 | } | ||
166 | |||
167 | |||
168 | static int gpio_nand_devready(struct mtd_info *mtd) | ||
169 | { | ||
170 | struct gpiomtd *gpiomtd = gpio_nand_getpriv(mtd); | ||
171 | return gpio_get_value(gpiomtd->plat.gpio_rdy); | ||
172 | } | ||
173 | |||
174 | static int __devexit gpio_nand_remove(struct platform_device *dev) | ||
175 | { | ||
176 | struct gpiomtd *gpiomtd = platform_get_drvdata(dev); | ||
177 | struct resource *res; | ||
178 | |||
179 | nand_release(&gpiomtd->mtd_info); | ||
180 | |||
181 | res = platform_get_resource(dev, IORESOURCE_MEM, 1); | ||
182 | iounmap(gpiomtd->io_sync); | ||
183 | if (res) | ||
184 | release_mem_region(res->start, res->end - res->start + 1); | ||
185 | |||
186 | res = platform_get_resource(dev, IORESOURCE_MEM, 0); | ||
187 | iounmap(gpiomtd->nand_chip.IO_ADDR_R); | ||
188 | release_mem_region(res->start, res->end - res->start + 1); | ||
189 | |||
190 | if (gpio_is_valid(gpiomtd->plat.gpio_nwp)) | ||
191 | gpio_set_value(gpiomtd->plat.gpio_nwp, 0); | ||
192 | gpio_set_value(gpiomtd->plat.gpio_nce, 1); | ||
193 | |||
194 | gpio_free(gpiomtd->plat.gpio_cle); | ||
195 | gpio_free(gpiomtd->plat.gpio_ale); | ||
196 | gpio_free(gpiomtd->plat.gpio_nce); | ||
197 | if (gpio_is_valid(gpiomtd->plat.gpio_nwp)) | ||
198 | gpio_free(gpiomtd->plat.gpio_nwp); | ||
199 | gpio_free(gpiomtd->plat.gpio_rdy); | ||
200 | |||
201 | kfree(gpiomtd); | ||
202 | |||
203 | return 0; | ||
204 | } | ||
205 | |||
206 | static void __iomem *request_and_remap(struct resource *res, size_t size, | ||
207 | const char *name, int *err) | ||
208 | { | ||
209 | void __iomem *ptr; | ||
210 | |||
211 | if (!request_mem_region(res->start, res->end - res->start + 1, name)) { | ||
212 | *err = -EBUSY; | ||
213 | return NULL; | ||
214 | } | ||
215 | |||
216 | ptr = ioremap(res->start, size); | ||
217 | if (!ptr) { | ||
218 | release_mem_region(res->start, res->end - res->start + 1); | ||
219 | *err = -ENOMEM; | ||
220 | } | ||
221 | return ptr; | ||
222 | } | ||
223 | |||
224 | static int __devinit gpio_nand_probe(struct platform_device *dev) | ||
225 | { | ||
226 | struct gpiomtd *gpiomtd; | ||
227 | struct nand_chip *this; | ||
228 | struct resource *res0, *res1; | ||
229 | int ret; | ||
230 | |||
231 | if (!dev->dev.platform_data) | ||
232 | return -EINVAL; | ||
233 | |||
234 | res0 = platform_get_resource(dev, IORESOURCE_MEM, 0); | ||
235 | if (!res0) | ||
236 | return -EINVAL; | ||
237 | |||
238 | gpiomtd = kzalloc(sizeof(*gpiomtd), GFP_KERNEL); | ||
239 | if (gpiomtd == NULL) { | ||
240 | dev_err(&dev->dev, "failed to create NAND MTD\n"); | ||
241 | return -ENOMEM; | ||
242 | } | ||
243 | |||
244 | this = &gpiomtd->nand_chip; | ||
245 | this->IO_ADDR_R = request_and_remap(res0, 2, "NAND", &ret); | ||
246 | if (!this->IO_ADDR_R) { | ||
247 | dev_err(&dev->dev, "unable to map NAND\n"); | ||
248 | goto err_map; | ||
249 | } | ||
250 | |||
251 | res1 = platform_get_resource(dev, IORESOURCE_MEM, 1); | ||
252 | if (res1) { | ||
253 | gpiomtd->io_sync = request_and_remap(res1, 4, "NAND sync", &ret); | ||
254 | if (!gpiomtd->io_sync) { | ||
255 | dev_err(&dev->dev, "unable to map sync NAND\n"); | ||
256 | goto err_sync; | ||
257 | } | ||
258 | } | ||
259 | |||
260 | memcpy(&gpiomtd->plat, dev->dev.platform_data, sizeof(gpiomtd->plat)); | ||
261 | |||
262 | ret = gpio_request(gpiomtd->plat.gpio_nce, "NAND NCE"); | ||
263 | if (ret) | ||
264 | goto err_nce; | ||
265 | gpio_direction_output(gpiomtd->plat.gpio_nce, 1); | ||
266 | if (gpio_is_valid(gpiomtd->plat.gpio_nwp)) { | ||
267 | ret = gpio_request(gpiomtd->plat.gpio_nwp, "NAND NWP"); | ||
268 | if (ret) | ||
269 | goto err_nwp; | ||
270 | gpio_direction_output(gpiomtd->plat.gpio_nwp, 1); | ||
271 | } | ||
272 | ret = gpio_request(gpiomtd->plat.gpio_ale, "NAND ALE"); | ||
273 | if (ret) | ||
274 | goto err_ale; | ||
275 | gpio_direction_output(gpiomtd->plat.gpio_ale, 0); | ||
276 | ret = gpio_request(gpiomtd->plat.gpio_cle, "NAND CLE"); | ||
277 | if (ret) | ||
278 | goto err_cle; | ||
279 | gpio_direction_output(gpiomtd->plat.gpio_cle, 0); | ||
280 | ret = gpio_request(gpiomtd->plat.gpio_rdy, "NAND RDY"); | ||
281 | if (ret) | ||
282 | goto err_rdy; | ||
283 | gpio_direction_input(gpiomtd->plat.gpio_rdy); | ||
284 | |||
285 | |||
286 | this->IO_ADDR_W = this->IO_ADDR_R; | ||
287 | this->ecc.mode = NAND_ECC_SOFT; | ||
288 | this->options = gpiomtd->plat.options; | ||
289 | this->chip_delay = gpiomtd->plat.chip_delay; | ||
290 | |||
291 | /* install our routines */ | ||
292 | this->cmd_ctrl = gpio_nand_cmd_ctrl; | ||
293 | this->dev_ready = gpio_nand_devready; | ||
294 | |||
295 | if (this->options & NAND_BUSWIDTH_16) { | ||
296 | this->read_buf = gpio_nand_readbuf16; | ||
297 | this->write_buf = gpio_nand_writebuf16; | ||
298 | this->verify_buf = gpio_nand_verifybuf16; | ||
299 | } else { | ||
300 | this->read_buf = gpio_nand_readbuf; | ||
301 | this->write_buf = gpio_nand_writebuf; | ||
302 | this->verify_buf = gpio_nand_verifybuf; | ||
303 | } | ||
304 | |||
305 | /* set the mtd private data for the nand driver */ | ||
306 | gpiomtd->mtd_info.priv = this; | ||
307 | gpiomtd->mtd_info.owner = THIS_MODULE; | ||
308 | |||
309 | if (nand_scan(&gpiomtd->mtd_info, 1)) { | ||
310 | dev_err(&dev->dev, "no nand chips found?\n"); | ||
311 | ret = -ENXIO; | ||
312 | goto err_wp; | ||
313 | } | ||
314 | |||
315 | if (gpiomtd->plat.adjust_parts) | ||
316 | gpiomtd->plat.adjust_parts(&gpiomtd->plat, | ||
317 | gpiomtd->mtd_info.size); | ||
318 | |||
319 | add_mtd_partitions(&gpiomtd->mtd_info, gpiomtd->plat.parts, | ||
320 | gpiomtd->plat.num_parts); | ||
321 | platform_set_drvdata(dev, gpiomtd); | ||
322 | |||
323 | return 0; | ||
324 | |||
325 | err_wp: | ||
326 | if (gpio_is_valid(gpiomtd->plat.gpio_nwp)) | ||
327 | gpio_set_value(gpiomtd->plat.gpio_nwp, 0); | ||
328 | gpio_free(gpiomtd->plat.gpio_rdy); | ||
329 | err_rdy: | ||
330 | gpio_free(gpiomtd->plat.gpio_cle); | ||
331 | err_cle: | ||
332 | gpio_free(gpiomtd->plat.gpio_ale); | ||
333 | err_ale: | ||
334 | if (gpio_is_valid(gpiomtd->plat.gpio_nwp)) | ||
335 | gpio_free(gpiomtd->plat.gpio_nwp); | ||
336 | err_nwp: | ||
337 | gpio_free(gpiomtd->plat.gpio_nce); | ||
338 | err_nce: | ||
339 | iounmap(gpiomtd->io_sync); | ||
340 | if (res1) | ||
341 | release_mem_region(res1->start, res1->end - res1->start + 1); | ||
342 | err_sync: | ||
343 | iounmap(gpiomtd->nand_chip.IO_ADDR_R); | ||
344 | release_mem_region(res0->start, res0->end - res0->start + 1); | ||
345 | err_map: | ||
346 | kfree(gpiomtd); | ||
347 | return ret; | ||
348 | } | ||
349 | |||
350 | static struct platform_driver gpio_nand_driver = { | ||
351 | .probe = gpio_nand_probe, | ||
352 | .remove = gpio_nand_remove, | ||
353 | .driver = { | ||
354 | .name = "gpio-nand", | ||
355 | }, | ||
356 | }; | ||
357 | |||
358 | static int __init gpio_nand_init(void) | ||
359 | { | ||
360 | printk(KERN_INFO "GPIO NAND driver, © 2004 Simtec Electronics\n"); | ||
361 | |||
362 | return platform_driver_register(&gpio_nand_driver); | ||
363 | } | ||
364 | |||
365 | static void __exit gpio_nand_exit(void) | ||
366 | { | ||
367 | platform_driver_unregister(&gpio_nand_driver); | ||
368 | } | ||
369 | |||
370 | module_init(gpio_nand_init); | ||
371 | module_exit(gpio_nand_exit); | ||
372 | |||
373 | MODULE_LICENSE("GPL"); | ||
374 | MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>"); | ||
375 | MODULE_DESCRIPTION("GPIO NAND Driver"); | ||
diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c new file mode 100644 index 000000000000..21fd4f1c4806 --- /dev/null +++ b/drivers/mtd/nand/mxc_nand.c | |||
@@ -0,0 +1,1077 @@ | |||
1 | /* | ||
2 | * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved. | ||
3 | * Copyright 2008 Sascha Hauer, kernel@pengutronix.de | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or | ||
6 | * modify it under the terms of the GNU General Public License | ||
7 | * as published by the Free Software Foundation; either version 2 | ||
8 | * of the License, or (at your option) any later version. | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
17 | * MA 02110-1301, USA. | ||
18 | */ | ||
19 | |||
20 | #include <linux/delay.h> | ||
21 | #include <linux/slab.h> | ||
22 | #include <linux/init.h> | ||
23 | #include <linux/module.h> | ||
24 | #include <linux/mtd/mtd.h> | ||
25 | #include <linux/mtd/nand.h> | ||
26 | #include <linux/mtd/partitions.h> | ||
27 | #include <linux/interrupt.h> | ||
28 | #include <linux/device.h> | ||
29 | #include <linux/platform_device.h> | ||
30 | #include <linux/clk.h> | ||
31 | #include <linux/err.h> | ||
32 | #include <linux/io.h> | ||
33 | |||
34 | #include <asm/mach/flash.h> | ||
35 | #include <mach/mxc_nand.h> | ||
36 | |||
37 | #define DRIVER_NAME "mxc_nand" | ||
38 | |||
39 | /* Addresses for NFC registers */ | ||
40 | #define NFC_BUF_SIZE 0xE00 | ||
41 | #define NFC_BUF_ADDR 0xE04 | ||
42 | #define NFC_FLASH_ADDR 0xE06 | ||
43 | #define NFC_FLASH_CMD 0xE08 | ||
44 | #define NFC_CONFIG 0xE0A | ||
45 | #define NFC_ECC_STATUS_RESULT 0xE0C | ||
46 | #define NFC_RSLTMAIN_AREA 0xE0E | ||
47 | #define NFC_RSLTSPARE_AREA 0xE10 | ||
48 | #define NFC_WRPROT 0xE12 | ||
49 | #define NFC_UNLOCKSTART_BLKADDR 0xE14 | ||
50 | #define NFC_UNLOCKEND_BLKADDR 0xE16 | ||
51 | #define NFC_NF_WRPRST 0xE18 | ||
52 | #define NFC_CONFIG1 0xE1A | ||
53 | #define NFC_CONFIG2 0xE1C | ||
54 | |||
55 | /* Addresses for NFC RAM BUFFER Main area 0 */ | ||
56 | #define MAIN_AREA0 0x000 | ||
57 | #define MAIN_AREA1 0x200 | ||
58 | #define MAIN_AREA2 0x400 | ||
59 | #define MAIN_AREA3 0x600 | ||
60 | |||
61 | /* Addresses for NFC SPARE BUFFER Spare area 0 */ | ||
62 | #define SPARE_AREA0 0x800 | ||
63 | #define SPARE_AREA1 0x810 | ||
64 | #define SPARE_AREA2 0x820 | ||
65 | #define SPARE_AREA3 0x830 | ||
66 | |||
67 | /* Set INT to 0, FCMD to 1, rest to 0 in NFC_CONFIG2 Register | ||
68 | * for Command operation */ | ||
69 | #define NFC_CMD 0x1 | ||
70 | |||
71 | /* Set INT to 0, FADD to 1, rest to 0 in NFC_CONFIG2 Register | ||
72 | * for Address operation */ | ||
73 | #define NFC_ADDR 0x2 | ||
74 | |||
75 | /* Set INT to 0, FDI to 1, rest to 0 in NFC_CONFIG2 Register | ||
76 | * for Input operation */ | ||
77 | #define NFC_INPUT 0x4 | ||
78 | |||
79 | /* Set INT to 0, FDO to 001, rest to 0 in NFC_CONFIG2 Register | ||
80 | * for Data Output operation */ | ||
81 | #define NFC_OUTPUT 0x8 | ||
82 | |||
83 | /* Set INT to 0, FD0 to 010, rest to 0 in NFC_CONFIG2 Register | ||
84 | * for Read ID operation */ | ||
85 | #define NFC_ID 0x10 | ||
86 | |||
87 | /* Set INT to 0, FDO to 100, rest to 0 in NFC_CONFIG2 Register | ||
88 | * for Read Status operation */ | ||
89 | #define NFC_STATUS 0x20 | ||
90 | |||
91 | /* Set INT to 1, rest to 0 in NFC_CONFIG2 Register for Read | ||
92 | * Status operation */ | ||
93 | #define NFC_INT 0x8000 | ||
94 | |||
95 | #define NFC_SP_EN (1 << 2) | ||
96 | #define NFC_ECC_EN (1 << 3) | ||
97 | #define NFC_INT_MSK (1 << 4) | ||
98 | #define NFC_BIG (1 << 5) | ||
99 | #define NFC_RST (1 << 6) | ||
100 | #define NFC_CE (1 << 7) | ||
101 | #define NFC_ONE_CYCLE (1 << 8) | ||
102 | |||
103 | struct mxc_nand_host { | ||
104 | struct mtd_info mtd; | ||
105 | struct nand_chip nand; | ||
106 | struct mtd_partition *parts; | ||
107 | struct device *dev; | ||
108 | |||
109 | void __iomem *regs; | ||
110 | int spare_only; | ||
111 | int status_request; | ||
112 | int pagesize_2k; | ||
113 | uint16_t col_addr; | ||
114 | struct clk *clk; | ||
115 | int clk_act; | ||
116 | int irq; | ||
117 | |||
118 | wait_queue_head_t irq_waitq; | ||
119 | }; | ||
120 | |||
121 | /* Define delays in microsec for NAND device operations */ | ||
122 | #define TROP_US_DELAY 2000 | ||
123 | /* Macros to get byte and bit positions of ECC */ | ||
124 | #define COLPOS(x) ((x) >> 3) | ||
125 | #define BITPOS(x) ((x) & 0xf) | ||
126 | |||
127 | /* Define single bit Error positions in Main & Spare area */ | ||
128 | #define MAIN_SINGLEBIT_ERROR 0x4 | ||
129 | #define SPARE_SINGLEBIT_ERROR 0x1 | ||
130 | |||
131 | /* OOB placement block for use with hardware ecc generation */ | ||
132 | static struct nand_ecclayout nand_hw_eccoob_8 = { | ||
133 | .eccbytes = 5, | ||
134 | .eccpos = {6, 7, 8, 9, 10}, | ||
135 | .oobfree = {{0, 5}, {11, 5}, } | ||
136 | }; | ||
137 | |||
138 | static struct nand_ecclayout nand_hw_eccoob_16 = { | ||
139 | .eccbytes = 5, | ||
140 | .eccpos = {6, 7, 8, 9, 10}, | ||
141 | .oobfree = {{0, 6}, {12, 4}, } | ||
142 | }; | ||
143 | |||
144 | #ifdef CONFIG_MTD_PARTITIONS | ||
145 | static const char *part_probes[] = { "RedBoot", "cmdlinepart", NULL }; | ||
146 | #endif | ||
147 | |||
148 | static irqreturn_t mxc_nfc_irq(int irq, void *dev_id) | ||
149 | { | ||
150 | struct mxc_nand_host *host = dev_id; | ||
151 | |||
152 | uint16_t tmp; | ||
153 | |||
154 | tmp = readw(host->regs + NFC_CONFIG1); | ||
155 | tmp |= NFC_INT_MSK; /* Disable interrupt */ | ||
156 | writew(tmp, host->regs + NFC_CONFIG1); | ||
157 | |||
158 | wake_up(&host->irq_waitq); | ||
159 | |||
160 | return IRQ_HANDLED; | ||
161 | } | ||
162 | |||
163 | /* This function polls the NANDFC to wait for the basic operation to | ||
164 | * complete by checking the INT bit of config2 register. | ||
165 | */ | ||
166 | static void wait_op_done(struct mxc_nand_host *host, int max_retries, | ||
167 | uint16_t param, int useirq) | ||
168 | { | ||
169 | uint32_t tmp; | ||
170 | |||
171 | if (useirq) { | ||
172 | if ((readw(host->regs + NFC_CONFIG2) & NFC_INT) == 0) { | ||
173 | |||
174 | tmp = readw(host->regs + NFC_CONFIG1); | ||
175 | tmp &= ~NFC_INT_MSK; /* Enable interrupt */ | ||
176 | writew(tmp, host->regs + NFC_CONFIG1); | ||
177 | |||
178 | wait_event(host->irq_waitq, | ||
179 | readw(host->regs + NFC_CONFIG2) & NFC_INT); | ||
180 | |||
181 | tmp = readw(host->regs + NFC_CONFIG2); | ||
182 | tmp &= ~NFC_INT; | ||
183 | writew(tmp, host->regs + NFC_CONFIG2); | ||
184 | } | ||
185 | } else { | ||
186 | while (max_retries-- > 0) { | ||
187 | if (readw(host->regs + NFC_CONFIG2) & NFC_INT) { | ||
188 | tmp = readw(host->regs + NFC_CONFIG2); | ||
189 | tmp &= ~NFC_INT; | ||
190 | writew(tmp, host->regs + NFC_CONFIG2); | ||
191 | break; | ||
192 | } | ||
193 | udelay(1); | ||
194 | } | ||
195 | if (max_retries <= 0) | ||
196 | DEBUG(MTD_DEBUG_LEVEL0, "%s(%d): INT not set\n", | ||
197 | __func__, param); | ||
198 | } | ||
199 | } | ||
200 | |||
201 | /* This function issues the specified command to the NAND device and | ||
202 | * waits for completion. */ | ||
203 | static void send_cmd(struct mxc_nand_host *host, uint16_t cmd, int useirq) | ||
204 | { | ||
205 | DEBUG(MTD_DEBUG_LEVEL3, "send_cmd(host, 0x%x, %d)\n", cmd, useirq); | ||
206 | |||
207 | writew(cmd, host->regs + NFC_FLASH_CMD); | ||
208 | writew(NFC_CMD, host->regs + NFC_CONFIG2); | ||
209 | |||
210 | /* Wait for operation to complete */ | ||
211 | wait_op_done(host, TROP_US_DELAY, cmd, useirq); | ||
212 | } | ||
213 | |||
214 | /* This function sends an address (or partial address) to the | ||
215 | * NAND device. The address is used to select the source/destination for | ||
216 | * a NAND command. */ | ||
217 | static void send_addr(struct mxc_nand_host *host, uint16_t addr, int islast) | ||
218 | { | ||
219 | DEBUG(MTD_DEBUG_LEVEL3, "send_addr(host, 0x%x %d)\n", addr, islast); | ||
220 | |||
221 | writew(addr, host->regs + NFC_FLASH_ADDR); | ||
222 | writew(NFC_ADDR, host->regs + NFC_CONFIG2); | ||
223 | |||
224 | /* Wait for operation to complete */ | ||
225 | wait_op_done(host, TROP_US_DELAY, addr, islast); | ||
226 | } | ||
227 | |||
228 | /* This function requests the NANDFC to initate the transfer | ||
229 | * of data currently in the NANDFC RAM buffer to the NAND device. */ | ||
230 | static void send_prog_page(struct mxc_nand_host *host, uint8_t buf_id, | ||
231 | int spare_only) | ||
232 | { | ||
233 | DEBUG(MTD_DEBUG_LEVEL3, "send_prog_page (%d)\n", spare_only); | ||
234 | |||
235 | /* NANDFC buffer 0 is used for page read/write */ | ||
236 | writew(buf_id, host->regs + NFC_BUF_ADDR); | ||
237 | |||
238 | /* Configure spare or page+spare access */ | ||
239 | if (!host->pagesize_2k) { | ||
240 | uint16_t config1 = readw(host->regs + NFC_CONFIG1); | ||
241 | if (spare_only) | ||
242 | config1 |= NFC_SP_EN; | ||
243 | else | ||
244 | config1 &= ~(NFC_SP_EN); | ||
245 | writew(config1, host->regs + NFC_CONFIG1); | ||
246 | } | ||
247 | |||
248 | writew(NFC_INPUT, host->regs + NFC_CONFIG2); | ||
249 | |||
250 | /* Wait for operation to complete */ | ||
251 | wait_op_done(host, TROP_US_DELAY, spare_only, true); | ||
252 | } | ||
253 | |||
254 | /* Requests NANDFC to initated the transfer of data from the | ||
255 | * NAND device into in the NANDFC ram buffer. */ | ||
256 | static void send_read_page(struct mxc_nand_host *host, uint8_t buf_id, | ||
257 | int spare_only) | ||
258 | { | ||
259 | DEBUG(MTD_DEBUG_LEVEL3, "send_read_page (%d)\n", spare_only); | ||
260 | |||
261 | /* NANDFC buffer 0 is used for page read/write */ | ||
262 | writew(buf_id, host->regs + NFC_BUF_ADDR); | ||
263 | |||
264 | /* Configure spare or page+spare access */ | ||
265 | if (!host->pagesize_2k) { | ||
266 | uint32_t config1 = readw(host->regs + NFC_CONFIG1); | ||
267 | if (spare_only) | ||
268 | config1 |= NFC_SP_EN; | ||
269 | else | ||
270 | config1 &= ~NFC_SP_EN; | ||
271 | writew(config1, host->regs + NFC_CONFIG1); | ||
272 | } | ||
273 | |||
274 | writew(NFC_OUTPUT, host->regs + NFC_CONFIG2); | ||
275 | |||
276 | /* Wait for operation to complete */ | ||
277 | wait_op_done(host, TROP_US_DELAY, spare_only, true); | ||
278 | } | ||
279 | |||
280 | /* Request the NANDFC to perform a read of the NAND device ID. */ | ||
281 | static void send_read_id(struct mxc_nand_host *host) | ||
282 | { | ||
283 | struct nand_chip *this = &host->nand; | ||
284 | uint16_t tmp; | ||
285 | |||
286 | /* NANDFC buffer 0 is used for device ID output */ | ||
287 | writew(0x0, host->regs + NFC_BUF_ADDR); | ||
288 | |||
289 | /* Read ID into main buffer */ | ||
290 | tmp = readw(host->regs + NFC_CONFIG1); | ||
291 | tmp &= ~NFC_SP_EN; | ||
292 | writew(tmp, host->regs + NFC_CONFIG1); | ||
293 | |||
294 | writew(NFC_ID, host->regs + NFC_CONFIG2); | ||
295 | |||
296 | /* Wait for operation to complete */ | ||
297 | wait_op_done(host, TROP_US_DELAY, 0, true); | ||
298 | |||
299 | if (this->options & NAND_BUSWIDTH_16) { | ||
300 | void __iomem *main_buf = host->regs + MAIN_AREA0; | ||
301 | /* compress the ID info */ | ||
302 | writeb(readb(main_buf + 2), main_buf + 1); | ||
303 | writeb(readb(main_buf + 4), main_buf + 2); | ||
304 | writeb(readb(main_buf + 6), main_buf + 3); | ||
305 | writeb(readb(main_buf + 8), main_buf + 4); | ||
306 | writeb(readb(main_buf + 10), main_buf + 5); | ||
307 | } | ||
308 | } | ||
309 | |||
310 | /* This function requests the NANDFC to perform a read of the | ||
311 | * NAND device status and returns the current status. */ | ||
312 | static uint16_t get_dev_status(struct mxc_nand_host *host) | ||
313 | { | ||
314 | void __iomem *main_buf = host->regs + MAIN_AREA1; | ||
315 | uint32_t store; | ||
316 | uint16_t ret, tmp; | ||
317 | /* Issue status request to NAND device */ | ||
318 | |||
319 | /* store the main area1 first word, later do recovery */ | ||
320 | store = readl(main_buf); | ||
321 | /* NANDFC buffer 1 is used for device status to prevent | ||
322 | * corruption of read/write buffer on status requests. */ | ||
323 | writew(1, host->regs + NFC_BUF_ADDR); | ||
324 | |||
325 | /* Read status into main buffer */ | ||
326 | tmp = readw(host->regs + NFC_CONFIG1); | ||
327 | tmp &= ~NFC_SP_EN; | ||
328 | writew(tmp, host->regs + NFC_CONFIG1); | ||
329 | |||
330 | writew(NFC_STATUS, host->regs + NFC_CONFIG2); | ||
331 | |||
332 | /* Wait for operation to complete */ | ||
333 | wait_op_done(host, TROP_US_DELAY, 0, true); | ||
334 | |||
335 | /* Status is placed in first word of main buffer */ | ||
336 | /* get status, then recovery area 1 data */ | ||
337 | ret = readw(main_buf); | ||
338 | writel(store, main_buf); | ||
339 | |||
340 | return ret; | ||
341 | } | ||
342 | |||
343 | /* This functions is used by upper layer to checks if device is ready */ | ||
344 | static int mxc_nand_dev_ready(struct mtd_info *mtd) | ||
345 | { | ||
346 | /* | ||
347 | * NFC handles R/B internally. Therefore, this function | ||
348 | * always returns status as ready. | ||
349 | */ | ||
350 | return 1; | ||
351 | } | ||
352 | |||
353 | static void mxc_nand_enable_hwecc(struct mtd_info *mtd, int mode) | ||
354 | { | ||
355 | /* | ||
356 | * If HW ECC is enabled, we turn it on during init. There is | ||
357 | * no need to enable again here. | ||
358 | */ | ||
359 | } | ||
360 | |||
361 | static int mxc_nand_correct_data(struct mtd_info *mtd, u_char *dat, | ||
362 | u_char *read_ecc, u_char *calc_ecc) | ||
363 | { | ||
364 | struct nand_chip *nand_chip = mtd->priv; | ||
365 | struct mxc_nand_host *host = nand_chip->priv; | ||
366 | |||
367 | /* | ||
368 | * 1-Bit errors are automatically corrected in HW. No need for | ||
369 | * additional correction. 2-Bit errors cannot be corrected by | ||
370 | * HW ECC, so we need to return failure | ||
371 | */ | ||
372 | uint16_t ecc_status = readw(host->regs + NFC_ECC_STATUS_RESULT); | ||
373 | |||
374 | if (((ecc_status & 0x3) == 2) || ((ecc_status >> 2) == 2)) { | ||
375 | DEBUG(MTD_DEBUG_LEVEL0, | ||
376 | "MXC_NAND: HWECC uncorrectable 2-bit ECC error\n"); | ||
377 | return -1; | ||
378 | } | ||
379 | |||
380 | return 0; | ||
381 | } | ||
382 | |||
383 | static int mxc_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, | ||
384 | u_char *ecc_code) | ||
385 | { | ||
386 | return 0; | ||
387 | } | ||
388 | |||
389 | static u_char mxc_nand_read_byte(struct mtd_info *mtd) | ||
390 | { | ||
391 | struct nand_chip *nand_chip = mtd->priv; | ||
392 | struct mxc_nand_host *host = nand_chip->priv; | ||
393 | uint8_t ret = 0; | ||
394 | uint16_t col, rd_word; | ||
395 | uint16_t __iomem *main_buf = host->regs + MAIN_AREA0; | ||
396 | uint16_t __iomem *spare_buf = host->regs + SPARE_AREA0; | ||
397 | |||
398 | /* Check for status request */ | ||
399 | if (host->status_request) | ||
400 | return get_dev_status(host) & 0xFF; | ||
401 | |||
402 | /* Get column for 16-bit access */ | ||
403 | col = host->col_addr >> 1; | ||
404 | |||
405 | /* If we are accessing the spare region */ | ||
406 | if (host->spare_only) | ||
407 | rd_word = readw(&spare_buf[col]); | ||
408 | else | ||
409 | rd_word = readw(&main_buf[col]); | ||
410 | |||
411 | /* Pick upper/lower byte of word from RAM buffer */ | ||
412 | if (host->col_addr & 0x1) | ||
413 | ret = (rd_word >> 8) & 0xFF; | ||
414 | else | ||
415 | ret = rd_word & 0xFF; | ||
416 | |||
417 | /* Update saved column address */ | ||
418 | host->col_addr++; | ||
419 | |||
420 | return ret; | ||
421 | } | ||
422 | |||
423 | static uint16_t mxc_nand_read_word(struct mtd_info *mtd) | ||
424 | { | ||
425 | struct nand_chip *nand_chip = mtd->priv; | ||
426 | struct mxc_nand_host *host = nand_chip->priv; | ||
427 | uint16_t col, rd_word, ret; | ||
428 | uint16_t __iomem *p; | ||
429 | |||
430 | DEBUG(MTD_DEBUG_LEVEL3, | ||
431 | "mxc_nand_read_word(col = %d)\n", host->col_addr); | ||
432 | |||
433 | col = host->col_addr; | ||
434 | /* Adjust saved column address */ | ||
435 | if (col < mtd->writesize && host->spare_only) | ||
436 | col += mtd->writesize; | ||
437 | |||
438 | if (col < mtd->writesize) | ||
439 | p = (host->regs + MAIN_AREA0) + (col >> 1); | ||
440 | else | ||
441 | p = (host->regs + SPARE_AREA0) + ((col - mtd->writesize) >> 1); | ||
442 | |||
443 | if (col & 1) { | ||
444 | rd_word = readw(p); | ||
445 | ret = (rd_word >> 8) & 0xff; | ||
446 | rd_word = readw(&p[1]); | ||
447 | ret |= (rd_word << 8) & 0xff00; | ||
448 | |||
449 | } else | ||
450 | ret = readw(p); | ||
451 | |||
452 | /* Update saved column address */ | ||
453 | host->col_addr = col + 2; | ||
454 | |||
455 | return ret; | ||
456 | } | ||
457 | |||
458 | /* Write data of length len to buffer buf. The data to be | ||
459 | * written on NAND Flash is first copied to RAMbuffer. After the Data Input | ||
460 | * Operation by the NFC, the data is written to NAND Flash */ | ||
461 | static void mxc_nand_write_buf(struct mtd_info *mtd, | ||
462 | const u_char *buf, int len) | ||
463 | { | ||
464 | struct nand_chip *nand_chip = mtd->priv; | ||
465 | struct mxc_nand_host *host = nand_chip->priv; | ||
466 | int n, col, i = 0; | ||
467 | |||
468 | DEBUG(MTD_DEBUG_LEVEL3, | ||
469 | "mxc_nand_write_buf(col = %d, len = %d)\n", host->col_addr, | ||
470 | len); | ||
471 | |||
472 | col = host->col_addr; | ||
473 | |||
474 | /* Adjust saved column address */ | ||
475 | if (col < mtd->writesize && host->spare_only) | ||
476 | col += mtd->writesize; | ||
477 | |||
478 | n = mtd->writesize + mtd->oobsize - col; | ||
479 | n = min(len, n); | ||
480 | |||
481 | DEBUG(MTD_DEBUG_LEVEL3, | ||
482 | "%s:%d: col = %d, n = %d\n", __func__, __LINE__, col, n); | ||
483 | |||
484 | while (n) { | ||
485 | void __iomem *p; | ||
486 | |||
487 | if (col < mtd->writesize) | ||
488 | p = host->regs + MAIN_AREA0 + (col & ~3); | ||
489 | else | ||
490 | p = host->regs + SPARE_AREA0 - | ||
491 | mtd->writesize + (col & ~3); | ||
492 | |||
493 | DEBUG(MTD_DEBUG_LEVEL3, "%s:%d: p = %p\n", __func__, | ||
494 | __LINE__, p); | ||
495 | |||
496 | if (((col | (int)&buf[i]) & 3) || n < 16) { | ||
497 | uint32_t data = 0; | ||
498 | |||
499 | if (col & 3 || n < 4) | ||
500 | data = readl(p); | ||
501 | |||
502 | switch (col & 3) { | ||
503 | case 0: | ||
504 | if (n) { | ||
505 | data = (data & 0xffffff00) | | ||
506 | (buf[i++] << 0); | ||
507 | n--; | ||
508 | col++; | ||
509 | } | ||
510 | case 1: | ||
511 | if (n) { | ||
512 | data = (data & 0xffff00ff) | | ||
513 | (buf[i++] << 8); | ||
514 | n--; | ||
515 | col++; | ||
516 | } | ||
517 | case 2: | ||
518 | if (n) { | ||
519 | data = (data & 0xff00ffff) | | ||
520 | (buf[i++] << 16); | ||
521 | n--; | ||
522 | col++; | ||
523 | } | ||
524 | case 3: | ||
525 | if (n) { | ||
526 | data = (data & 0x00ffffff) | | ||
527 | (buf[i++] << 24); | ||
528 | n--; | ||
529 | col++; | ||
530 | } | ||
531 | } | ||
532 | |||
533 | writel(data, p); | ||
534 | } else { | ||
535 | int m = mtd->writesize - col; | ||
536 | |||
537 | if (col >= mtd->writesize) | ||
538 | m += mtd->oobsize; | ||
539 | |||
540 | m = min(n, m) & ~3; | ||
541 | |||
542 | DEBUG(MTD_DEBUG_LEVEL3, | ||
543 | "%s:%d: n = %d, m = %d, i = %d, col = %d\n", | ||
544 | __func__, __LINE__, n, m, i, col); | ||
545 | |||
546 | memcpy(p, &buf[i], m); | ||
547 | col += m; | ||
548 | i += m; | ||
549 | n -= m; | ||
550 | } | ||
551 | } | ||
552 | /* Update saved column address */ | ||
553 | host->col_addr = col; | ||
554 | } | ||
555 | |||
556 | /* Read the data buffer from the NAND Flash. To read the data from NAND | ||
557 | * Flash first the data output cycle is initiated by the NFC, which copies | ||
558 | * the data to RAMbuffer. This data of length len is then copied to buffer buf. | ||
559 | */ | ||
560 | static void mxc_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len) | ||
561 | { | ||
562 | struct nand_chip *nand_chip = mtd->priv; | ||
563 | struct mxc_nand_host *host = nand_chip->priv; | ||
564 | int n, col, i = 0; | ||
565 | |||
566 | DEBUG(MTD_DEBUG_LEVEL3, | ||
567 | "mxc_nand_read_buf(col = %d, len = %d)\n", host->col_addr, len); | ||
568 | |||
569 | col = host->col_addr; | ||
570 | |||
571 | /* Adjust saved column address */ | ||
572 | if (col < mtd->writesize && host->spare_only) | ||
573 | col += mtd->writesize; | ||
574 | |||
575 | n = mtd->writesize + mtd->oobsize - col; | ||
576 | n = min(len, n); | ||
577 | |||
578 | while (n) { | ||
579 | void __iomem *p; | ||
580 | |||
581 | if (col < mtd->writesize) | ||
582 | p = host->regs + MAIN_AREA0 + (col & ~3); | ||
583 | else | ||
584 | p = host->regs + SPARE_AREA0 - | ||
585 | mtd->writesize + (col & ~3); | ||
586 | |||
587 | if (((col | (int)&buf[i]) & 3) || n < 16) { | ||
588 | uint32_t data; | ||
589 | |||
590 | data = readl(p); | ||
591 | switch (col & 3) { | ||
592 | case 0: | ||
593 | if (n) { | ||
594 | buf[i++] = (uint8_t) (data); | ||
595 | n--; | ||
596 | col++; | ||
597 | } | ||
598 | case 1: | ||
599 | if (n) { | ||
600 | buf[i++] = (uint8_t) (data >> 8); | ||
601 | n--; | ||
602 | col++; | ||
603 | } | ||
604 | case 2: | ||
605 | if (n) { | ||
606 | buf[i++] = (uint8_t) (data >> 16); | ||
607 | n--; | ||
608 | col++; | ||
609 | } | ||
610 | case 3: | ||
611 | if (n) { | ||
612 | buf[i++] = (uint8_t) (data >> 24); | ||
613 | n--; | ||
614 | col++; | ||
615 | } | ||
616 | } | ||
617 | } else { | ||
618 | int m = mtd->writesize - col; | ||
619 | |||
620 | if (col >= mtd->writesize) | ||
621 | m += mtd->oobsize; | ||
622 | |||
623 | m = min(n, m) & ~3; | ||
624 | memcpy(&buf[i], p, m); | ||
625 | col += m; | ||
626 | i += m; | ||
627 | n -= m; | ||
628 | } | ||
629 | } | ||
630 | /* Update saved column address */ | ||
631 | host->col_addr = col; | ||
632 | |||
633 | } | ||
634 | |||
635 | /* Used by the upper layer to verify the data in NAND Flash | ||
636 | * with the data in the buf. */ | ||
637 | static int mxc_nand_verify_buf(struct mtd_info *mtd, | ||
638 | const u_char *buf, int len) | ||
639 | { | ||
640 | return -EFAULT; | ||
641 | } | ||
642 | |||
643 | /* This function is used by upper layer for select and | ||
644 | * deselect of the NAND chip */ | ||
645 | static void mxc_nand_select_chip(struct mtd_info *mtd, int chip) | ||
646 | { | ||
647 | struct nand_chip *nand_chip = mtd->priv; | ||
648 | struct mxc_nand_host *host = nand_chip->priv; | ||
649 | |||
650 | #ifdef CONFIG_MTD_NAND_MXC_FORCE_CE | ||
651 | if (chip > 0) { | ||
652 | DEBUG(MTD_DEBUG_LEVEL0, | ||
653 | "ERROR: Illegal chip select (chip = %d)\n", chip); | ||
654 | return; | ||
655 | } | ||
656 | |||
657 | if (chip == -1) { | ||
658 | writew(readw(host->regs + NFC_CONFIG1) & ~NFC_CE, | ||
659 | host->regs + NFC_CONFIG1); | ||
660 | return; | ||
661 | } | ||
662 | |||
663 | writew(readw(host->regs + NFC_CONFIG1) | NFC_CE, | ||
664 | host->regs + NFC_CONFIG1); | ||
665 | #endif | ||
666 | |||
667 | switch (chip) { | ||
668 | case -1: | ||
669 | /* Disable the NFC clock */ | ||
670 | if (host->clk_act) { | ||
671 | clk_disable(host->clk); | ||
672 | host->clk_act = 0; | ||
673 | } | ||
674 | break; | ||
675 | case 0: | ||
676 | /* Enable the NFC clock */ | ||
677 | if (!host->clk_act) { | ||
678 | clk_enable(host->clk); | ||
679 | host->clk_act = 1; | ||
680 | } | ||
681 | break; | ||
682 | |||
683 | default: | ||
684 | break; | ||
685 | } | ||
686 | } | ||
687 | |||
688 | /* Used by the upper layer to write command to NAND Flash for | ||
689 | * different operations to be carried out on NAND Flash */ | ||
690 | static void mxc_nand_command(struct mtd_info *mtd, unsigned command, | ||
691 | int column, int page_addr) | ||
692 | { | ||
693 | struct nand_chip *nand_chip = mtd->priv; | ||
694 | struct mxc_nand_host *host = nand_chip->priv; | ||
695 | int useirq = true; | ||
696 | |||
697 | DEBUG(MTD_DEBUG_LEVEL3, | ||
698 | "mxc_nand_command (cmd = 0x%x, col = 0x%x, page = 0x%x)\n", | ||
699 | command, column, page_addr); | ||
700 | |||
701 | /* Reset command state information */ | ||
702 | host->status_request = false; | ||
703 | |||
704 | /* Command pre-processing step */ | ||
705 | switch (command) { | ||
706 | |||
707 | case NAND_CMD_STATUS: | ||
708 | host->col_addr = 0; | ||
709 | host->status_request = true; | ||
710 | break; | ||
711 | |||
712 | case NAND_CMD_READ0: | ||
713 | host->col_addr = column; | ||
714 | host->spare_only = false; | ||
715 | useirq = false; | ||
716 | break; | ||
717 | |||
718 | case NAND_CMD_READOOB: | ||
719 | host->col_addr = column; | ||
720 | host->spare_only = true; | ||
721 | useirq = false; | ||
722 | if (host->pagesize_2k) | ||
723 | command = NAND_CMD_READ0; /* only READ0 is valid */ | ||
724 | break; | ||
725 | |||
726 | case NAND_CMD_SEQIN: | ||
727 | if (column >= mtd->writesize) { | ||
728 | /* | ||
729 | * FIXME: before send SEQIN command for write OOB, | ||
730 | * We must read one page out. | ||
731 | * For K9F1GXX has no READ1 command to set current HW | ||
732 | * pointer to spare area, we must write the whole page | ||
733 | * including OOB together. | ||
734 | */ | ||
735 | if (host->pagesize_2k) | ||
736 | /* call ourself to read a page */ | ||
737 | mxc_nand_command(mtd, NAND_CMD_READ0, 0, | ||
738 | page_addr); | ||
739 | |||
740 | host->col_addr = column - mtd->writesize; | ||
741 | host->spare_only = true; | ||
742 | |||
743 | /* Set program pointer to spare region */ | ||
744 | if (!host->pagesize_2k) | ||
745 | send_cmd(host, NAND_CMD_READOOB, false); | ||
746 | } else { | ||
747 | host->spare_only = false; | ||
748 | host->col_addr = column; | ||
749 | |||
750 | /* Set program pointer to page start */ | ||
751 | if (!host->pagesize_2k) | ||
752 | send_cmd(host, NAND_CMD_READ0, false); | ||
753 | } | ||
754 | useirq = false; | ||
755 | break; | ||
756 | |||
757 | case NAND_CMD_PAGEPROG: | ||
758 | send_prog_page(host, 0, host->spare_only); | ||
759 | |||
760 | if (host->pagesize_2k) { | ||
761 | /* data in 4 areas datas */ | ||
762 | send_prog_page(host, 1, host->spare_only); | ||
763 | send_prog_page(host, 2, host->spare_only); | ||
764 | send_prog_page(host, 3, host->spare_only); | ||
765 | } | ||
766 | |||
767 | break; | ||
768 | |||
769 | case NAND_CMD_ERASE1: | ||
770 | useirq = false; | ||
771 | break; | ||
772 | } | ||
773 | |||
774 | /* Write out the command to the device. */ | ||
775 | send_cmd(host, command, useirq); | ||
776 | |||
777 | /* Write out column address, if necessary */ | ||
778 | if (column != -1) { | ||
779 | /* | ||
780 | * MXC NANDFC can only perform full page+spare or | ||
781 | * spare-only read/write. When the upper layers | ||
782 | * layers perform a read/write buf operation, | ||
783 | * we will used the saved column adress to index into | ||
784 | * the full page. | ||
785 | */ | ||
786 | send_addr(host, 0, page_addr == -1); | ||
787 | if (host->pagesize_2k) | ||
788 | /* another col addr cycle for 2k page */ | ||
789 | send_addr(host, 0, false); | ||
790 | } | ||
791 | |||
792 | /* Write out page address, if necessary */ | ||
793 | if (page_addr != -1) { | ||
794 | /* paddr_0 - p_addr_7 */ | ||
795 | send_addr(host, (page_addr & 0xff), false); | ||
796 | |||
797 | if (host->pagesize_2k) { | ||
798 | send_addr(host, (page_addr >> 8) & 0xFF, false); | ||
799 | if (mtd->size >= 0x40000000) | ||
800 | send_addr(host, (page_addr >> 16) & 0xff, true); | ||
801 | } else { | ||
802 | /* One more address cycle for higher density devices */ | ||
803 | if (mtd->size >= 0x4000000) { | ||
804 | /* paddr_8 - paddr_15 */ | ||
805 | send_addr(host, (page_addr >> 8) & 0xff, false); | ||
806 | send_addr(host, (page_addr >> 16) & 0xff, true); | ||
807 | } else | ||
808 | /* paddr_8 - paddr_15 */ | ||
809 | send_addr(host, (page_addr >> 8) & 0xff, true); | ||
810 | } | ||
811 | } | ||
812 | |||
813 | /* Command post-processing step */ | ||
814 | switch (command) { | ||
815 | |||
816 | case NAND_CMD_RESET: | ||
817 | break; | ||
818 | |||
819 | case NAND_CMD_READOOB: | ||
820 | case NAND_CMD_READ0: | ||
821 | if (host->pagesize_2k) { | ||
822 | /* send read confirm command */ | ||
823 | send_cmd(host, NAND_CMD_READSTART, true); | ||
824 | /* read for each AREA */ | ||
825 | send_read_page(host, 0, host->spare_only); | ||
826 | send_read_page(host, 1, host->spare_only); | ||
827 | send_read_page(host, 2, host->spare_only); | ||
828 | send_read_page(host, 3, host->spare_only); | ||
829 | } else | ||
830 | send_read_page(host, 0, host->spare_only); | ||
831 | break; | ||
832 | |||
833 | case NAND_CMD_READID: | ||
834 | send_read_id(host); | ||
835 | break; | ||
836 | |||
837 | case NAND_CMD_PAGEPROG: | ||
838 | break; | ||
839 | |||
840 | case NAND_CMD_STATUS: | ||
841 | break; | ||
842 | |||
843 | case NAND_CMD_ERASE2: | ||
844 | break; | ||
845 | } | ||
846 | } | ||
847 | |||
848 | static int __init mxcnd_probe(struct platform_device *pdev) | ||
849 | { | ||
850 | struct nand_chip *this; | ||
851 | struct mtd_info *mtd; | ||
852 | struct mxc_nand_platform_data *pdata = pdev->dev.platform_data; | ||
853 | struct mxc_nand_host *host; | ||
854 | struct resource *res; | ||
855 | uint16_t tmp; | ||
856 | int err = 0, nr_parts = 0; | ||
857 | |||
858 | /* Allocate memory for MTD device structure and private data */ | ||
859 | host = kzalloc(sizeof(struct mxc_nand_host), GFP_KERNEL); | ||
860 | if (!host) | ||
861 | return -ENOMEM; | ||
862 | |||
863 | host->dev = &pdev->dev; | ||
864 | /* structures must be linked */ | ||
865 | this = &host->nand; | ||
866 | mtd = &host->mtd; | ||
867 | mtd->priv = this; | ||
868 | mtd->owner = THIS_MODULE; | ||
869 | |||
870 | /* 50 us command delay time */ | ||
871 | this->chip_delay = 5; | ||
872 | |||
873 | this->priv = host; | ||
874 | this->dev_ready = mxc_nand_dev_ready; | ||
875 | this->cmdfunc = mxc_nand_command; | ||
876 | this->select_chip = mxc_nand_select_chip; | ||
877 | this->read_byte = mxc_nand_read_byte; | ||
878 | this->read_word = mxc_nand_read_word; | ||
879 | this->write_buf = mxc_nand_write_buf; | ||
880 | this->read_buf = mxc_nand_read_buf; | ||
881 | this->verify_buf = mxc_nand_verify_buf; | ||
882 | |||
883 | host->clk = clk_get(&pdev->dev, "nfc_clk"); | ||
884 | if (IS_ERR(host->clk)) | ||
885 | goto eclk; | ||
886 | |||
887 | clk_enable(host->clk); | ||
888 | host->clk_act = 1; | ||
889 | |||
890 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
891 | if (!res) { | ||
892 | err = -ENODEV; | ||
893 | goto eres; | ||
894 | } | ||
895 | |||
896 | host->regs = ioremap(res->start, res->end - res->start + 1); | ||
897 | if (!host->regs) { | ||
898 | err = -EIO; | ||
899 | goto eres; | ||
900 | } | ||
901 | |||
902 | tmp = readw(host->regs + NFC_CONFIG1); | ||
903 | tmp |= NFC_INT_MSK; | ||
904 | writew(tmp, host->regs + NFC_CONFIG1); | ||
905 | |||
906 | init_waitqueue_head(&host->irq_waitq); | ||
907 | |||
908 | host->irq = platform_get_irq(pdev, 0); | ||
909 | |||
910 | err = request_irq(host->irq, mxc_nfc_irq, 0, "mxc_nd", host); | ||
911 | if (err) | ||
912 | goto eirq; | ||
913 | |||
914 | if (pdata->hw_ecc) { | ||
915 | this->ecc.calculate = mxc_nand_calculate_ecc; | ||
916 | this->ecc.hwctl = mxc_nand_enable_hwecc; | ||
917 | this->ecc.correct = mxc_nand_correct_data; | ||
918 | this->ecc.mode = NAND_ECC_HW; | ||
919 | this->ecc.size = 512; | ||
920 | this->ecc.bytes = 3; | ||
921 | this->ecc.layout = &nand_hw_eccoob_8; | ||
922 | tmp = readw(host->regs + NFC_CONFIG1); | ||
923 | tmp |= NFC_ECC_EN; | ||
924 | writew(tmp, host->regs + NFC_CONFIG1); | ||
925 | } else { | ||
926 | this->ecc.size = 512; | ||
927 | this->ecc.bytes = 3; | ||
928 | this->ecc.layout = &nand_hw_eccoob_8; | ||
929 | this->ecc.mode = NAND_ECC_SOFT; | ||
930 | tmp = readw(host->regs + NFC_CONFIG1); | ||
931 | tmp &= ~NFC_ECC_EN; | ||
932 | writew(tmp, host->regs + NFC_CONFIG1); | ||
933 | } | ||
934 | |||
935 | /* Reset NAND */ | ||
936 | this->cmdfunc(mtd, NAND_CMD_RESET, -1, -1); | ||
937 | |||
938 | /* preset operation */ | ||
939 | /* Unlock the internal RAM Buffer */ | ||
940 | writew(0x2, host->regs + NFC_CONFIG); | ||
941 | |||
942 | /* Blocks to be unlocked */ | ||
943 | writew(0x0, host->regs + NFC_UNLOCKSTART_BLKADDR); | ||
944 | writew(0x4000, host->regs + NFC_UNLOCKEND_BLKADDR); | ||
945 | |||
946 | /* Unlock Block Command for given address range */ | ||
947 | writew(0x4, host->regs + NFC_WRPROT); | ||
948 | |||
949 | /* NAND bus width determines access funtions used by upper layer */ | ||
950 | if (pdata->width == 2) { | ||
951 | this->options |= NAND_BUSWIDTH_16; | ||
952 | this->ecc.layout = &nand_hw_eccoob_16; | ||
953 | } | ||
954 | |||
955 | host->pagesize_2k = 0; | ||
956 | |||
957 | /* Scan to find existence of the device */ | ||
958 | if (nand_scan(mtd, 1)) { | ||
959 | DEBUG(MTD_DEBUG_LEVEL0, | ||
960 | "MXC_ND: Unable to find any NAND device.\n"); | ||
961 | err = -ENXIO; | ||
962 | goto escan; | ||
963 | } | ||
964 | |||
965 | /* Register the partitions */ | ||
966 | #ifdef CONFIG_MTD_PARTITIONS | ||
967 | nr_parts = | ||
968 | parse_mtd_partitions(mtd, part_probes, &host->parts, 0); | ||
969 | if (nr_parts > 0) | ||
970 | add_mtd_partitions(mtd, host->parts, nr_parts); | ||
971 | else | ||
972 | #endif | ||
973 | { | ||
974 | pr_info("Registering %s as whole device\n", mtd->name); | ||
975 | add_mtd_device(mtd); | ||
976 | } | ||
977 | |||
978 | platform_set_drvdata(pdev, host); | ||
979 | |||
980 | return 0; | ||
981 | |||
982 | escan: | ||
983 | free_irq(host->irq, NULL); | ||
984 | eirq: | ||
985 | iounmap(host->regs); | ||
986 | eres: | ||
987 | clk_put(host->clk); | ||
988 | eclk: | ||
989 | kfree(host); | ||
990 | |||
991 | return err; | ||
992 | } | ||
993 | |||
994 | static int __devexit mxcnd_remove(struct platform_device *pdev) | ||
995 | { | ||
996 | struct mxc_nand_host *host = platform_get_drvdata(pdev); | ||
997 | |||
998 | clk_put(host->clk); | ||
999 | |||
1000 | platform_set_drvdata(pdev, NULL); | ||
1001 | |||
1002 | nand_release(&host->mtd); | ||
1003 | free_irq(host->irq, NULL); | ||
1004 | iounmap(host->regs); | ||
1005 | kfree(host); | ||
1006 | |||
1007 | return 0; | ||
1008 | } | ||
1009 | |||
1010 | #ifdef CONFIG_PM | ||
1011 | static int mxcnd_suspend(struct platform_device *pdev, pm_message_t state) | ||
1012 | { | ||
1013 | struct mtd_info *info = platform_get_drvdata(pdev); | ||
1014 | int ret = 0; | ||
1015 | |||
1016 | DEBUG(MTD_DEBUG_LEVEL0, "MXC_ND : NAND suspend\n"); | ||
1017 | if (info) | ||
1018 | ret = info->suspend(info); | ||
1019 | |||
1020 | /* Disable the NFC clock */ | ||
1021 | clk_disable(nfc_clk); /* FIXME */ | ||
1022 | |||
1023 | return ret; | ||
1024 | } | ||
1025 | |||
1026 | static int mxcnd_resume(struct platform_device *pdev) | ||
1027 | { | ||
1028 | struct mtd_info *info = platform_get_drvdata(pdev); | ||
1029 | int ret = 0; | ||
1030 | |||
1031 | DEBUG(MTD_DEBUG_LEVEL0, "MXC_ND : NAND resume\n"); | ||
1032 | /* Enable the NFC clock */ | ||
1033 | clk_enable(nfc_clk); /* FIXME */ | ||
1034 | |||
1035 | if (info) | ||
1036 | info->resume(info); | ||
1037 | |||
1038 | return ret; | ||
1039 | } | ||
1040 | |||
1041 | #else | ||
1042 | # define mxcnd_suspend NULL | ||
1043 | # define mxcnd_resume NULL | ||
1044 | #endif /* CONFIG_PM */ | ||
1045 | |||
1046 | static struct platform_driver mxcnd_driver = { | ||
1047 | .driver = { | ||
1048 | .name = DRIVER_NAME, | ||
1049 | }, | ||
1050 | .remove = __exit_p(mxcnd_remove), | ||
1051 | .suspend = mxcnd_suspend, | ||
1052 | .resume = mxcnd_resume, | ||
1053 | }; | ||
1054 | |||
1055 | static int __init mxc_nd_init(void) | ||
1056 | { | ||
1057 | /* Register the device driver structure. */ | ||
1058 | pr_info("MXC MTD nand Driver\n"); | ||
1059 | if (platform_driver_probe(&mxcnd_driver, mxcnd_probe) != 0) { | ||
1060 | printk(KERN_ERR "Driver register failed for mxcnd_driver\n"); | ||
1061 | return -ENODEV; | ||
1062 | } | ||
1063 | return 0; | ||
1064 | } | ||
1065 | |||
1066 | static void __exit mxc_nd_cleanup(void) | ||
1067 | { | ||
1068 | /* Unregister the device structure */ | ||
1069 | platform_driver_unregister(&mxcnd_driver); | ||
1070 | } | ||
1071 | |||
1072 | module_init(mxc_nd_init); | ||
1073 | module_exit(mxc_nd_cleanup); | ||
1074 | |||
1075 | MODULE_AUTHOR("Freescale Semiconductor, Inc."); | ||
1076 | MODULE_DESCRIPTION("MXC NAND MTD driver"); | ||
1077 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index d1129bae6c27..0a9c9cd33f96 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c | |||
@@ -801,9 +801,9 @@ static int nand_read_page_swecc(struct mtd_info *mtd, struct nand_chip *chip, | |||
801 | * nand_read_subpage - [REPLACABLE] software ecc based sub-page read function | 801 | * nand_read_subpage - [REPLACABLE] software ecc based sub-page read function |
802 | * @mtd: mtd info structure | 802 | * @mtd: mtd info structure |
803 | * @chip: nand chip info structure | 803 | * @chip: nand chip info structure |
804 | * @dataofs offset of requested data within the page | 804 | * @data_offs: offset of requested data within the page |
805 | * @readlen data length | 805 | * @readlen: data length |
806 | * @buf: buffer to store read data | 806 | * @bufpoi: buffer to store read data |
807 | */ | 807 | */ |
808 | static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip, uint32_t data_offs, uint32_t readlen, uint8_t *bufpoi) | 808 | static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip, uint32_t data_offs, uint32_t readlen, uint8_t *bufpoi) |
809 | { | 809 | { |
@@ -2042,7 +2042,7 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr, | |||
2042 | return -EINVAL; | 2042 | return -EINVAL; |
2043 | } | 2043 | } |
2044 | 2044 | ||
2045 | instr->fail_addr = 0xffffffff; | 2045 | instr->fail_addr = MTD_FAIL_ADDR_UNKNOWN; |
2046 | 2046 | ||
2047 | /* Grab the lock and see if the device is available */ | 2047 | /* Grab the lock and see if the device is available */ |
2048 | nand_get_device(chip, mtd, FL_ERASING); | 2048 | nand_get_device(chip, mtd, FL_ERASING); |
@@ -2318,6 +2318,12 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, | |||
2318 | /* Select the device */ | 2318 | /* Select the device */ |
2319 | chip->select_chip(mtd, 0); | 2319 | chip->select_chip(mtd, 0); |
2320 | 2320 | ||
2321 | /* | ||
2322 | * Reset the chip, required by some chips (e.g. Micron MT29FxGxxxxx) | ||
2323 | * after power-up | ||
2324 | */ | ||
2325 | chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1); | ||
2326 | |||
2321 | /* Send the command for reading device ID */ | 2327 | /* Send the command for reading device ID */ |
2322 | chip->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1); | 2328 | chip->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1); |
2323 | 2329 | ||
@@ -2488,6 +2494,8 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips) | |||
2488 | /* Check for a chip array */ | 2494 | /* Check for a chip array */ |
2489 | for (i = 1; i < maxchips; i++) { | 2495 | for (i = 1; i < maxchips; i++) { |
2490 | chip->select_chip(mtd, i); | 2496 | chip->select_chip(mtd, i); |
2497 | /* See comment in nand_get_flash_type for reset */ | ||
2498 | chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1); | ||
2491 | /* Send the command for reading device ID */ | 2499 | /* Send the command for reading device ID */ |
2492 | chip->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1); | 2500 | chip->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1); |
2493 | /* Read manufacturer and device IDs */ | 2501 | /* Read manufacturer and device IDs */ |
diff --git a/drivers/mtd/nand/nand_ecc.c b/drivers/mtd/nand/nand_ecc.c index 918a806a8471..868147acce2c 100644 --- a/drivers/mtd/nand/nand_ecc.c +++ b/drivers/mtd/nand/nand_ecc.c | |||
@@ -1,13 +1,18 @@ | |||
1 | /* | 1 | /* |
2 | * This file contains an ECC algorithm from Toshiba that detects and | 2 | * This file contains an ECC algorithm that detects and corrects 1 bit |
3 | * corrects 1 bit errors in a 256 byte block of data. | 3 | * errors in a 256 byte block of data. |
4 | * | 4 | * |
5 | * drivers/mtd/nand/nand_ecc.c | 5 | * drivers/mtd/nand/nand_ecc.c |
6 | * | 6 | * |
7 | * Copyright (C) 2000-2004 Steven J. Hill (sjhill@realitydiluted.com) | 7 | * Copyright © 2008 Koninklijke Philips Electronics NV. |
8 | * Toshiba America Electronics Components, Inc. | 8 | * Author: Frans Meulenbroeks |
9 | * | 9 | * |
10 | * Copyright (C) 2006 Thomas Gleixner <tglx@linutronix.de> | 10 | * Completely replaces the previous ECC implementation which was written by: |
11 | * Steven J. Hill (sjhill@realitydiluted.com) | ||
12 | * Thomas Gleixner (tglx@linutronix.de) | ||
13 | * | ||
14 | * Information on how this algorithm works and how it was developed | ||
15 | * can be found in Documentation/mtd/nand_ecc.txt | ||
11 | * | 16 | * |
12 | * This file is free software; you can redistribute it and/or modify it | 17 | * This file is free software; you can redistribute it and/or modify it |
13 | * under the terms of the GNU General Public License as published by the | 18 | * under the terms of the GNU General Public License as published by the |
@@ -23,174 +28,475 @@ | |||
23 | * with this file; if not, write to the Free Software Foundation, Inc., | 28 | * with this file; if not, write to the Free Software Foundation, Inc., |
24 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | 29 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
25 | * | 30 | * |
26 | * As a special exception, if other files instantiate templates or use | ||
27 | * macros or inline functions from these files, or you compile these | ||
28 | * files and link them with other works to produce a work based on these | ||
29 | * files, these files do not by themselves cause the resulting work to be | ||
30 | * covered by the GNU General Public License. However the source code for | ||
31 | * these files must still be made available in accordance with section (3) | ||
32 | * of the GNU General Public License. | ||
33 | * | ||
34 | * This exception does not invalidate any other reasons why a work based on | ||
35 | * this file might be covered by the GNU General Public License. | ||
36 | */ | 31 | */ |
37 | 32 | ||
33 | /* | ||
34 | * The STANDALONE macro is useful when running the code outside the kernel | ||
35 | * e.g. when running the code in a testbed or a benchmark program. | ||
36 | * When STANDALONE is used, the module related macros are commented out | ||
37 | * as well as the linux include files. | ||
38 | * Instead a private definition of mtd_info is given to satisfy the compiler | ||
39 | * (the code does not use mtd_info, so the code does not care) | ||
40 | */ | ||
41 | #ifndef STANDALONE | ||
38 | #include <linux/types.h> | 42 | #include <linux/types.h> |
39 | #include <linux/kernel.h> | 43 | #include <linux/kernel.h> |
40 | #include <linux/module.h> | 44 | #include <linux/module.h> |
45 | #include <linux/mtd/mtd.h> | ||
46 | #include <linux/mtd/nand.h> | ||
41 | #include <linux/mtd/nand_ecc.h> | 47 | #include <linux/mtd/nand_ecc.h> |
48 | #include <asm/byteorder.h> | ||
49 | #else | ||
50 | #include <stdint.h> | ||
51 | struct mtd_info; | ||
52 | #define EXPORT_SYMBOL(x) /* x */ | ||
53 | |||
54 | #define MODULE_LICENSE(x) /* x */ | ||
55 | #define MODULE_AUTHOR(x) /* x */ | ||
56 | #define MODULE_DESCRIPTION(x) /* x */ | ||
57 | |||
58 | #define printk printf | ||
59 | #define KERN_ERR "" | ||
60 | #endif | ||
61 | |||
62 | /* | ||
63 | * invparity is a 256 byte table that contains the odd parity | ||
64 | * for each byte. So if the number of bits in a byte is even, | ||
65 | * the array element is 1, and when the number of bits is odd | ||
66 | * the array eleemnt is 0. | ||
67 | */ | ||
68 | static const char invparity[256] = { | ||
69 | 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, | ||
70 | 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, | ||
71 | 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, | ||
72 | 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, | ||
73 | 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, | ||
74 | 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, | ||
75 | 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, | ||
76 | 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, | ||
77 | 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, | ||
78 | 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, | ||
79 | 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, | ||
80 | 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, | ||
81 | 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, | ||
82 | 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, | ||
83 | 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, | ||
84 | 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1 | ||
85 | }; | ||
86 | |||
87 | /* | ||
88 | * bitsperbyte contains the number of bits per byte | ||
89 | * this is only used for testing and repairing parity | ||
90 | * (a precalculated value slightly improves performance) | ||
91 | */ | ||
92 | static const char bitsperbyte[256] = { | ||
93 | 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, | ||
94 | 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, | ||
95 | 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, | ||
96 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, | ||
97 | 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, | ||
98 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, | ||
99 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, | ||
100 | 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, | ||
101 | 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, | ||
102 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, | ||
103 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, | ||
104 | 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, | ||
105 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, | ||
106 | 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, | ||
107 | 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, | ||
108 | 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8, | ||
109 | }; | ||
42 | 110 | ||
43 | /* | 111 | /* |
44 | * Pre-calculated 256-way 1 byte column parity | 112 | * addressbits is a lookup table to filter out the bits from the xor-ed |
113 | * ecc data that identify the faulty location. | ||
114 | * this is only used for repairing parity | ||
115 | * see the comments in nand_correct_data for more details | ||
45 | */ | 116 | */ |
46 | static const u_char nand_ecc_precalc_table[] = { | 117 | static const char addressbits[256] = { |
47 | 0x00, 0x55, 0x56, 0x03, 0x59, 0x0c, 0x0f, 0x5a, 0x5a, 0x0f, 0x0c, 0x59, 0x03, 0x56, 0x55, 0x00, | 118 | 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, |
48 | 0x65, 0x30, 0x33, 0x66, 0x3c, 0x69, 0x6a, 0x3f, 0x3f, 0x6a, 0x69, 0x3c, 0x66, 0x33, 0x30, 0x65, | 119 | 0x02, 0x02, 0x03, 0x03, 0x02, 0x02, 0x03, 0x03, |
49 | 0x66, 0x33, 0x30, 0x65, 0x3f, 0x6a, 0x69, 0x3c, 0x3c, 0x69, 0x6a, 0x3f, 0x65, 0x30, 0x33, 0x66, | 120 | 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, |
50 | 0x03, 0x56, 0x55, 0x00, 0x5a, 0x0f, 0x0c, 0x59, 0x59, 0x0c, 0x0f, 0x5a, 0x00, 0x55, 0x56, 0x03, | 121 | 0x02, 0x02, 0x03, 0x03, 0x02, 0x02, 0x03, 0x03, |
51 | 0x69, 0x3c, 0x3f, 0x6a, 0x30, 0x65, 0x66, 0x33, 0x33, 0x66, 0x65, 0x30, 0x6a, 0x3f, 0x3c, 0x69, | 122 | 0x04, 0x04, 0x05, 0x05, 0x04, 0x04, 0x05, 0x05, |
52 | 0x0c, 0x59, 0x5a, 0x0f, 0x55, 0x00, 0x03, 0x56, 0x56, 0x03, 0x00, 0x55, 0x0f, 0x5a, 0x59, 0x0c, | 123 | 0x06, 0x06, 0x07, 0x07, 0x06, 0x06, 0x07, 0x07, |
53 | 0x0f, 0x5a, 0x59, 0x0c, 0x56, 0x03, 0x00, 0x55, 0x55, 0x00, 0x03, 0x56, 0x0c, 0x59, 0x5a, 0x0f, | 124 | 0x04, 0x04, 0x05, 0x05, 0x04, 0x04, 0x05, 0x05, |
54 | 0x6a, 0x3f, 0x3c, 0x69, 0x33, 0x66, 0x65, 0x30, 0x30, 0x65, 0x66, 0x33, 0x69, 0x3c, 0x3f, 0x6a, | 125 | 0x06, 0x06, 0x07, 0x07, 0x06, 0x06, 0x07, 0x07, |
55 | 0x6a, 0x3f, 0x3c, 0x69, 0x33, 0x66, 0x65, 0x30, 0x30, 0x65, 0x66, 0x33, 0x69, 0x3c, 0x3f, 0x6a, | 126 | 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, |
56 | 0x0f, 0x5a, 0x59, 0x0c, 0x56, 0x03, 0x00, 0x55, 0x55, 0x00, 0x03, 0x56, 0x0c, 0x59, 0x5a, 0x0f, | 127 | 0x02, 0x02, 0x03, 0x03, 0x02, 0x02, 0x03, 0x03, |
57 | 0x0c, 0x59, 0x5a, 0x0f, 0x55, 0x00, 0x03, 0x56, 0x56, 0x03, 0x00, 0x55, 0x0f, 0x5a, 0x59, 0x0c, | 128 | 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, |
58 | 0x69, 0x3c, 0x3f, 0x6a, 0x30, 0x65, 0x66, 0x33, 0x33, 0x66, 0x65, 0x30, 0x6a, 0x3f, 0x3c, 0x69, | 129 | 0x02, 0x02, 0x03, 0x03, 0x02, 0x02, 0x03, 0x03, |
59 | 0x03, 0x56, 0x55, 0x00, 0x5a, 0x0f, 0x0c, 0x59, 0x59, 0x0c, 0x0f, 0x5a, 0x00, 0x55, 0x56, 0x03, | 130 | 0x04, 0x04, 0x05, 0x05, 0x04, 0x04, 0x05, 0x05, |
60 | 0x66, 0x33, 0x30, 0x65, 0x3f, 0x6a, 0x69, 0x3c, 0x3c, 0x69, 0x6a, 0x3f, 0x65, 0x30, 0x33, 0x66, | 131 | 0x06, 0x06, 0x07, 0x07, 0x06, 0x06, 0x07, 0x07, |
61 | 0x65, 0x30, 0x33, 0x66, 0x3c, 0x69, 0x6a, 0x3f, 0x3f, 0x6a, 0x69, 0x3c, 0x66, 0x33, 0x30, 0x65, | 132 | 0x04, 0x04, 0x05, 0x05, 0x04, 0x04, 0x05, 0x05, |
62 | 0x00, 0x55, 0x56, 0x03, 0x59, 0x0c, 0x0f, 0x5a, 0x5a, 0x0f, 0x0c, 0x59, 0x03, 0x56, 0x55, 0x00 | 133 | 0x06, 0x06, 0x07, 0x07, 0x06, 0x06, 0x07, 0x07, |
134 | 0x08, 0x08, 0x09, 0x09, 0x08, 0x08, 0x09, 0x09, | ||
135 | 0x0a, 0x0a, 0x0b, 0x0b, 0x0a, 0x0a, 0x0b, 0x0b, | ||
136 | 0x08, 0x08, 0x09, 0x09, 0x08, 0x08, 0x09, 0x09, | ||
137 | 0x0a, 0x0a, 0x0b, 0x0b, 0x0a, 0x0a, 0x0b, 0x0b, | ||
138 | 0x0c, 0x0c, 0x0d, 0x0d, 0x0c, 0x0c, 0x0d, 0x0d, | ||
139 | 0x0e, 0x0e, 0x0f, 0x0f, 0x0e, 0x0e, 0x0f, 0x0f, | ||
140 | 0x0c, 0x0c, 0x0d, 0x0d, 0x0c, 0x0c, 0x0d, 0x0d, | ||
141 | 0x0e, 0x0e, 0x0f, 0x0f, 0x0e, 0x0e, 0x0f, 0x0f, | ||
142 | 0x08, 0x08, 0x09, 0x09, 0x08, 0x08, 0x09, 0x09, | ||
143 | 0x0a, 0x0a, 0x0b, 0x0b, 0x0a, 0x0a, 0x0b, 0x0b, | ||
144 | 0x08, 0x08, 0x09, 0x09, 0x08, 0x08, 0x09, 0x09, | ||
145 | 0x0a, 0x0a, 0x0b, 0x0b, 0x0a, 0x0a, 0x0b, 0x0b, | ||
146 | 0x0c, 0x0c, 0x0d, 0x0d, 0x0c, 0x0c, 0x0d, 0x0d, | ||
147 | 0x0e, 0x0e, 0x0f, 0x0f, 0x0e, 0x0e, 0x0f, 0x0f, | ||
148 | 0x0c, 0x0c, 0x0d, 0x0d, 0x0c, 0x0c, 0x0d, 0x0d, | ||
149 | 0x0e, 0x0e, 0x0f, 0x0f, 0x0e, 0x0e, 0x0f, 0x0f | ||
63 | }; | 150 | }; |
64 | 151 | ||
65 | /** | 152 | /** |
66 | * nand_calculate_ecc - [NAND Interface] Calculate 3-byte ECC for 256-byte block | 153 | * nand_calculate_ecc - [NAND Interface] Calculate 3-byte ECC for 256/512-byte |
154 | * block | ||
67 | * @mtd: MTD block structure | 155 | * @mtd: MTD block structure |
68 | * @dat: raw data | 156 | * @buf: input buffer with raw data |
69 | * @ecc_code: buffer for ECC | 157 | * @code: output buffer with ECC |
70 | */ | 158 | */ |
71 | int nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, | 159 | int nand_calculate_ecc(struct mtd_info *mtd, const unsigned char *buf, |
72 | u_char *ecc_code) | 160 | unsigned char *code) |
73 | { | 161 | { |
74 | uint8_t idx, reg1, reg2, reg3, tmp1, tmp2; | ||
75 | int i; | 162 | int i; |
163 | const uint32_t *bp = (uint32_t *)buf; | ||
164 | /* 256 or 512 bytes/ecc */ | ||
165 | const uint32_t eccsize_mult = | ||
166 | (((struct nand_chip *)mtd->priv)->ecc.size) >> 8; | ||
167 | uint32_t cur; /* current value in buffer */ | ||
168 | /* rp0..rp15..rp17 are the various accumulated parities (per byte) */ | ||
169 | uint32_t rp0, rp1, rp2, rp3, rp4, rp5, rp6, rp7; | ||
170 | uint32_t rp8, rp9, rp10, rp11, rp12, rp13, rp14, rp15, rp16; | ||
171 | uint32_t uninitialized_var(rp17); /* to make compiler happy */ | ||
172 | uint32_t par; /* the cumulative parity for all data */ | ||
173 | uint32_t tmppar; /* the cumulative parity for this iteration; | ||
174 | for rp12, rp14 and rp16 at the end of the | ||
175 | loop */ | ||
176 | |||
177 | par = 0; | ||
178 | rp4 = 0; | ||
179 | rp6 = 0; | ||
180 | rp8 = 0; | ||
181 | rp10 = 0; | ||
182 | rp12 = 0; | ||
183 | rp14 = 0; | ||
184 | rp16 = 0; | ||
185 | |||
186 | /* | ||
187 | * The loop is unrolled a number of times; | ||
188 | * This avoids if statements to decide on which rp value to update | ||
189 | * Also we process the data by longwords. | ||
190 | * Note: passing unaligned data might give a performance penalty. | ||
191 | * It is assumed that the buffers are aligned. | ||
192 | * tmppar is the cumulative sum of this iteration. | ||
193 | * needed for calculating rp12, rp14, rp16 and par | ||
194 | * also used as a performance improvement for rp6, rp8 and rp10 | ||
195 | */ | ||
196 | for (i = 0; i < eccsize_mult << 2; i++) { | ||
197 | cur = *bp++; | ||
198 | tmppar = cur; | ||
199 | rp4 ^= cur; | ||
200 | cur = *bp++; | ||
201 | tmppar ^= cur; | ||
202 | rp6 ^= tmppar; | ||
203 | cur = *bp++; | ||
204 | tmppar ^= cur; | ||
205 | rp4 ^= cur; | ||
206 | cur = *bp++; | ||
207 | tmppar ^= cur; | ||
208 | rp8 ^= tmppar; | ||
76 | 209 | ||
77 | /* Initialize variables */ | 210 | cur = *bp++; |
78 | reg1 = reg2 = reg3 = 0; | 211 | tmppar ^= cur; |
212 | rp4 ^= cur; | ||
213 | rp6 ^= cur; | ||
214 | cur = *bp++; | ||
215 | tmppar ^= cur; | ||
216 | rp6 ^= cur; | ||
217 | cur = *bp++; | ||
218 | tmppar ^= cur; | ||
219 | rp4 ^= cur; | ||
220 | cur = *bp++; | ||
221 | tmppar ^= cur; | ||
222 | rp10 ^= tmppar; | ||
79 | 223 | ||
80 | /* Build up column parity */ | 224 | cur = *bp++; |
81 | for(i = 0; i < 256; i++) { | 225 | tmppar ^= cur; |
82 | /* Get CP0 - CP5 from table */ | 226 | rp4 ^= cur; |
83 | idx = nand_ecc_precalc_table[*dat++]; | 227 | rp6 ^= cur; |
84 | reg1 ^= (idx & 0x3f); | 228 | rp8 ^= cur; |
229 | cur = *bp++; | ||
230 | tmppar ^= cur; | ||
231 | rp6 ^= cur; | ||
232 | rp8 ^= cur; | ||
233 | cur = *bp++; | ||
234 | tmppar ^= cur; | ||
235 | rp4 ^= cur; | ||
236 | rp8 ^= cur; | ||
237 | cur = *bp++; | ||
238 | tmppar ^= cur; | ||
239 | rp8 ^= cur; | ||
85 | 240 | ||
86 | /* All bit XOR = 1 ? */ | 241 | cur = *bp++; |
87 | if (idx & 0x40) { | 242 | tmppar ^= cur; |
88 | reg3 ^= (uint8_t) i; | 243 | rp4 ^= cur; |
89 | reg2 ^= ~((uint8_t) i); | 244 | rp6 ^= cur; |
90 | } | 245 | cur = *bp++; |
246 | tmppar ^= cur; | ||
247 | rp6 ^= cur; | ||
248 | cur = *bp++; | ||
249 | tmppar ^= cur; | ||
250 | rp4 ^= cur; | ||
251 | cur = *bp++; | ||
252 | tmppar ^= cur; | ||
253 | |||
254 | par ^= tmppar; | ||
255 | if ((i & 0x1) == 0) | ||
256 | rp12 ^= tmppar; | ||
257 | if ((i & 0x2) == 0) | ||
258 | rp14 ^= tmppar; | ||
259 | if (eccsize_mult == 2 && (i & 0x4) == 0) | ||
260 | rp16 ^= tmppar; | ||
91 | } | 261 | } |
92 | 262 | ||
93 | /* Create non-inverted ECC code from line parity */ | 263 | /* |
94 | tmp1 = (reg3 & 0x80) >> 0; /* B7 -> B7 */ | 264 | * handle the fact that we use longword operations |
95 | tmp1 |= (reg2 & 0x80) >> 1; /* B7 -> B6 */ | 265 | * we'll bring rp4..rp14..rp16 back to single byte entities by |
96 | tmp1 |= (reg3 & 0x40) >> 1; /* B6 -> B5 */ | 266 | * shifting and xoring first fold the upper and lower 16 bits, |
97 | tmp1 |= (reg2 & 0x40) >> 2; /* B6 -> B4 */ | 267 | * then the upper and lower 8 bits. |
98 | tmp1 |= (reg3 & 0x20) >> 2; /* B5 -> B3 */ | 268 | */ |
99 | tmp1 |= (reg2 & 0x20) >> 3; /* B5 -> B2 */ | 269 | rp4 ^= (rp4 >> 16); |
100 | tmp1 |= (reg3 & 0x10) >> 3; /* B4 -> B1 */ | 270 | rp4 ^= (rp4 >> 8); |
101 | tmp1 |= (reg2 & 0x10) >> 4; /* B4 -> B0 */ | 271 | rp4 &= 0xff; |
102 | 272 | rp6 ^= (rp6 >> 16); | |
103 | tmp2 = (reg3 & 0x08) << 4; /* B3 -> B7 */ | 273 | rp6 ^= (rp6 >> 8); |
104 | tmp2 |= (reg2 & 0x08) << 3; /* B3 -> B6 */ | 274 | rp6 &= 0xff; |
105 | tmp2 |= (reg3 & 0x04) << 3; /* B2 -> B5 */ | 275 | rp8 ^= (rp8 >> 16); |
106 | tmp2 |= (reg2 & 0x04) << 2; /* B2 -> B4 */ | 276 | rp8 ^= (rp8 >> 8); |
107 | tmp2 |= (reg3 & 0x02) << 2; /* B1 -> B3 */ | 277 | rp8 &= 0xff; |
108 | tmp2 |= (reg2 & 0x02) << 1; /* B1 -> B2 */ | 278 | rp10 ^= (rp10 >> 16); |
109 | tmp2 |= (reg3 & 0x01) << 1; /* B0 -> B1 */ | 279 | rp10 ^= (rp10 >> 8); |
110 | tmp2 |= (reg2 & 0x01) << 0; /* B7 -> B0 */ | 280 | rp10 &= 0xff; |
111 | 281 | rp12 ^= (rp12 >> 16); | |
112 | /* Calculate final ECC code */ | 282 | rp12 ^= (rp12 >> 8); |
113 | #ifdef CONFIG_MTD_NAND_ECC_SMC | 283 | rp12 &= 0xff; |
114 | ecc_code[0] = ~tmp2; | 284 | rp14 ^= (rp14 >> 16); |
115 | ecc_code[1] = ~tmp1; | 285 | rp14 ^= (rp14 >> 8); |
286 | rp14 &= 0xff; | ||
287 | if (eccsize_mult == 2) { | ||
288 | rp16 ^= (rp16 >> 16); | ||
289 | rp16 ^= (rp16 >> 8); | ||
290 | rp16 &= 0xff; | ||
291 | } | ||
292 | |||
293 | /* | ||
294 | * we also need to calculate the row parity for rp0..rp3 | ||
295 | * This is present in par, because par is now | ||
296 | * rp3 rp3 rp2 rp2 in little endian and | ||
297 | * rp2 rp2 rp3 rp3 in big endian | ||
298 | * as well as | ||
299 | * rp1 rp0 rp1 rp0 in little endian and | ||
300 | * rp0 rp1 rp0 rp1 in big endian | ||
301 | * First calculate rp2 and rp3 | ||
302 | */ | ||
303 | #ifdef __BIG_ENDIAN | ||
304 | rp2 = (par >> 16); | ||
305 | rp2 ^= (rp2 >> 8); | ||
306 | rp2 &= 0xff; | ||
307 | rp3 = par & 0xffff; | ||
308 | rp3 ^= (rp3 >> 8); | ||
309 | rp3 &= 0xff; | ||
116 | #else | 310 | #else |
117 | ecc_code[0] = ~tmp1; | 311 | rp3 = (par >> 16); |
118 | ecc_code[1] = ~tmp2; | 312 | rp3 ^= (rp3 >> 8); |
313 | rp3 &= 0xff; | ||
314 | rp2 = par & 0xffff; | ||
315 | rp2 ^= (rp2 >> 8); | ||
316 | rp2 &= 0xff; | ||
119 | #endif | 317 | #endif |
120 | ecc_code[2] = ((~reg1) << 2) | 0x03; | ||
121 | 318 | ||
122 | return 0; | 319 | /* reduce par to 16 bits then calculate rp1 and rp0 */ |
123 | } | 320 | par ^= (par >> 16); |
124 | EXPORT_SYMBOL(nand_calculate_ecc); | 321 | #ifdef __BIG_ENDIAN |
322 | rp0 = (par >> 8) & 0xff; | ||
323 | rp1 = (par & 0xff); | ||
324 | #else | ||
325 | rp1 = (par >> 8) & 0xff; | ||
326 | rp0 = (par & 0xff); | ||
327 | #endif | ||
125 | 328 | ||
126 | static inline int countbits(uint32_t byte) | 329 | /* finally reduce par to 8 bits */ |
127 | { | 330 | par ^= (par >> 8); |
128 | int res = 0; | 331 | par &= 0xff; |
129 | 332 | ||
130 | for (;byte; byte >>= 1) | 333 | /* |
131 | res += byte & 0x01; | 334 | * and calculate rp5..rp15..rp17 |
132 | return res; | 335 | * note that par = rp4 ^ rp5 and due to the commutative property |
336 | * of the ^ operator we can say: | ||
337 | * rp5 = (par ^ rp4); | ||
338 | * The & 0xff seems superfluous, but benchmarking learned that | ||
339 | * leaving it out gives slightly worse results. No idea why, probably | ||
340 | * it has to do with the way the pipeline in pentium is organized. | ||
341 | */ | ||
342 | rp5 = (par ^ rp4) & 0xff; | ||
343 | rp7 = (par ^ rp6) & 0xff; | ||
344 | rp9 = (par ^ rp8) & 0xff; | ||
345 | rp11 = (par ^ rp10) & 0xff; | ||
346 | rp13 = (par ^ rp12) & 0xff; | ||
347 | rp15 = (par ^ rp14) & 0xff; | ||
348 | if (eccsize_mult == 2) | ||
349 | rp17 = (par ^ rp16) & 0xff; | ||
350 | |||
351 | /* | ||
352 | * Finally calculate the ecc bits. | ||
353 | * Again here it might seem that there are performance optimisations | ||
354 | * possible, but benchmarks showed that on the system this is developed | ||
355 | * the code below is the fastest | ||
356 | */ | ||
357 | #ifdef CONFIG_MTD_NAND_ECC_SMC | ||
358 | code[0] = | ||
359 | (invparity[rp7] << 7) | | ||
360 | (invparity[rp6] << 6) | | ||
361 | (invparity[rp5] << 5) | | ||
362 | (invparity[rp4] << 4) | | ||
363 | (invparity[rp3] << 3) | | ||
364 | (invparity[rp2] << 2) | | ||
365 | (invparity[rp1] << 1) | | ||
366 | (invparity[rp0]); | ||
367 | code[1] = | ||
368 | (invparity[rp15] << 7) | | ||
369 | (invparity[rp14] << 6) | | ||
370 | (invparity[rp13] << 5) | | ||
371 | (invparity[rp12] << 4) | | ||
372 | (invparity[rp11] << 3) | | ||
373 | (invparity[rp10] << 2) | | ||
374 | (invparity[rp9] << 1) | | ||
375 | (invparity[rp8]); | ||
376 | #else | ||
377 | code[1] = | ||
378 | (invparity[rp7] << 7) | | ||
379 | (invparity[rp6] << 6) | | ||
380 | (invparity[rp5] << 5) | | ||
381 | (invparity[rp4] << 4) | | ||
382 | (invparity[rp3] << 3) | | ||
383 | (invparity[rp2] << 2) | | ||
384 | (invparity[rp1] << 1) | | ||
385 | (invparity[rp0]); | ||
386 | code[0] = | ||
387 | (invparity[rp15] << 7) | | ||
388 | (invparity[rp14] << 6) | | ||
389 | (invparity[rp13] << 5) | | ||
390 | (invparity[rp12] << 4) | | ||
391 | (invparity[rp11] << 3) | | ||
392 | (invparity[rp10] << 2) | | ||
393 | (invparity[rp9] << 1) | | ||
394 | (invparity[rp8]); | ||
395 | #endif | ||
396 | if (eccsize_mult == 1) | ||
397 | code[2] = | ||
398 | (invparity[par & 0xf0] << 7) | | ||
399 | (invparity[par & 0x0f] << 6) | | ||
400 | (invparity[par & 0xcc] << 5) | | ||
401 | (invparity[par & 0x33] << 4) | | ||
402 | (invparity[par & 0xaa] << 3) | | ||
403 | (invparity[par & 0x55] << 2) | | ||
404 | 3; | ||
405 | else | ||
406 | code[2] = | ||
407 | (invparity[par & 0xf0] << 7) | | ||
408 | (invparity[par & 0x0f] << 6) | | ||
409 | (invparity[par & 0xcc] << 5) | | ||
410 | (invparity[par & 0x33] << 4) | | ||
411 | (invparity[par & 0xaa] << 3) | | ||
412 | (invparity[par & 0x55] << 2) | | ||
413 | (invparity[rp17] << 1) | | ||
414 | (invparity[rp16] << 0); | ||
415 | return 0; | ||
133 | } | 416 | } |
417 | EXPORT_SYMBOL(nand_calculate_ecc); | ||
134 | 418 | ||
135 | /** | 419 | /** |
136 | * nand_correct_data - [NAND Interface] Detect and correct bit error(s) | 420 | * nand_correct_data - [NAND Interface] Detect and correct bit error(s) |
137 | * @mtd: MTD block structure | 421 | * @mtd: MTD block structure |
138 | * @dat: raw data read from the chip | 422 | * @buf: raw data read from the chip |
139 | * @read_ecc: ECC from the chip | 423 | * @read_ecc: ECC from the chip |
140 | * @calc_ecc: the ECC calculated from raw data | 424 | * @calc_ecc: the ECC calculated from raw data |
141 | * | 425 | * |
142 | * Detect and correct a 1 bit error for 256 byte block | 426 | * Detect and correct a 1 bit error for 256/512 byte block |
143 | */ | 427 | */ |
144 | int nand_correct_data(struct mtd_info *mtd, u_char *dat, | 428 | int nand_correct_data(struct mtd_info *mtd, unsigned char *buf, |
145 | u_char *read_ecc, u_char *calc_ecc) | 429 | unsigned char *read_ecc, unsigned char *calc_ecc) |
146 | { | 430 | { |
147 | uint8_t s0, s1, s2; | 431 | unsigned char b0, b1, b2; |
432 | unsigned char byte_addr, bit_addr; | ||
433 | /* 256 or 512 bytes/ecc */ | ||
434 | const uint32_t eccsize_mult = | ||
435 | (((struct nand_chip *)mtd->priv)->ecc.size) >> 8; | ||
148 | 436 | ||
437 | /* | ||
438 | * b0 to b2 indicate which bit is faulty (if any) | ||
439 | * we might need the xor result more than once, | ||
440 | * so keep them in a local var | ||
441 | */ | ||
149 | #ifdef CONFIG_MTD_NAND_ECC_SMC | 442 | #ifdef CONFIG_MTD_NAND_ECC_SMC |
150 | s0 = calc_ecc[0] ^ read_ecc[0]; | 443 | b0 = read_ecc[0] ^ calc_ecc[0]; |
151 | s1 = calc_ecc[1] ^ read_ecc[1]; | 444 | b1 = read_ecc[1] ^ calc_ecc[1]; |
152 | s2 = calc_ecc[2] ^ read_ecc[2]; | ||
153 | #else | 445 | #else |
154 | s1 = calc_ecc[0] ^ read_ecc[0]; | 446 | b0 = read_ecc[1] ^ calc_ecc[1]; |
155 | s0 = calc_ecc[1] ^ read_ecc[1]; | 447 | b1 = read_ecc[0] ^ calc_ecc[0]; |
156 | s2 = calc_ecc[2] ^ read_ecc[2]; | ||
157 | #endif | 448 | #endif |
158 | if ((s0 | s1 | s2) == 0) | 449 | b2 = read_ecc[2] ^ calc_ecc[2]; |
159 | return 0; | ||
160 | |||
161 | /* Check for a single bit error */ | ||
162 | if( ((s0 ^ (s0 >> 1)) & 0x55) == 0x55 && | ||
163 | ((s1 ^ (s1 >> 1)) & 0x55) == 0x55 && | ||
164 | ((s2 ^ (s2 >> 1)) & 0x54) == 0x54) { | ||
165 | 450 | ||
166 | uint32_t byteoffs, bitnum; | 451 | /* check if there are any bitfaults */ |
167 | 452 | ||
168 | byteoffs = (s1 << 0) & 0x80; | 453 | /* repeated if statements are slightly more efficient than switch ... */ |
169 | byteoffs |= (s1 << 1) & 0x40; | 454 | /* ordered in order of likelihood */ |
170 | byteoffs |= (s1 << 2) & 0x20; | ||
171 | byteoffs |= (s1 << 3) & 0x10; | ||
172 | 455 | ||
173 | byteoffs |= (s0 >> 4) & 0x08; | 456 | if ((b0 | b1 | b2) == 0) |
174 | byteoffs |= (s0 >> 3) & 0x04; | 457 | return 0; /* no error */ |
175 | byteoffs |= (s0 >> 2) & 0x02; | ||
176 | byteoffs |= (s0 >> 1) & 0x01; | ||
177 | |||
178 | bitnum = (s2 >> 5) & 0x04; | ||
179 | bitnum |= (s2 >> 4) & 0x02; | ||
180 | bitnum |= (s2 >> 3) & 0x01; | ||
181 | |||
182 | dat[byteoffs] ^= (1 << bitnum); | ||
183 | 458 | ||
459 | if ((((b0 ^ (b0 >> 1)) & 0x55) == 0x55) && | ||
460 | (((b1 ^ (b1 >> 1)) & 0x55) == 0x55) && | ||
461 | ((eccsize_mult == 1 && ((b2 ^ (b2 >> 1)) & 0x54) == 0x54) || | ||
462 | (eccsize_mult == 2 && ((b2 ^ (b2 >> 1)) & 0x55) == 0x55))) { | ||
463 | /* single bit error */ | ||
464 | /* | ||
465 | * rp17/rp15/13/11/9/7/5/3/1 indicate which byte is the faulty | ||
466 | * byte, cp 5/3/1 indicate the faulty bit. | ||
467 | * A lookup table (called addressbits) is used to filter | ||
468 | * the bits from the byte they are in. | ||
469 | * A marginal optimisation is possible by having three | ||
470 | * different lookup tables. | ||
471 | * One as we have now (for b0), one for b2 | ||
472 | * (that would avoid the >> 1), and one for b1 (with all values | ||
473 | * << 4). However it was felt that introducing two more tables | ||
474 | * hardly justify the gain. | ||
475 | * | ||
476 | * The b2 shift is there to get rid of the lowest two bits. | ||
477 | * We could also do addressbits[b2] >> 1 but for the | ||
478 | * performace it does not make any difference | ||
479 | */ | ||
480 | if (eccsize_mult == 1) | ||
481 | byte_addr = (addressbits[b1] << 4) + addressbits[b0]; | ||
482 | else | ||
483 | byte_addr = (addressbits[b2 & 0x3] << 8) + | ||
484 | (addressbits[b1] << 4) + addressbits[b0]; | ||
485 | bit_addr = addressbits[b2 >> 2]; | ||
486 | /* flip the bit */ | ||
487 | buf[byte_addr] ^= (1 << bit_addr); | ||
184 | return 1; | 488 | return 1; |
185 | } | ||
186 | 489 | ||
187 | if(countbits(s0 | ((uint32_t)s1 << 8) | ((uint32_t)s2 <<16)) == 1) | 490 | } |
188 | return 1; | 491 | /* count nr of bits; use table lookup, faster than calculating it */ |
492 | if ((bitsperbyte[b0] + bitsperbyte[b1] + bitsperbyte[b2]) == 1) | ||
493 | return 1; /* error in ecc data; no action needed */ | ||
189 | 494 | ||
190 | return -EBADMSG; | 495 | printk(KERN_ERR "uncorrectable error : "); |
496 | return -1; | ||
191 | } | 497 | } |
192 | EXPORT_SYMBOL(nand_correct_data); | 498 | EXPORT_SYMBOL(nand_correct_data); |
193 | 499 | ||
194 | MODULE_LICENSE("GPL"); | 500 | MODULE_LICENSE("GPL"); |
195 | MODULE_AUTHOR("Steven J. Hill <sjhill@realitydiluted.com>"); | 501 | MODULE_AUTHOR("Frans Meulenbroeks <fransmeulenbroeks@gmail.com>"); |
196 | MODULE_DESCRIPTION("Generic NAND ECC support"); | 502 | MODULE_DESCRIPTION("Generic NAND ECC support"); |
diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c index 556e8131ecdc..ae7c57781a68 100644 --- a/drivers/mtd/nand/nandsim.c +++ b/drivers/mtd/nand/nandsim.c | |||
@@ -38,7 +38,6 @@ | |||
38 | #include <linux/delay.h> | 38 | #include <linux/delay.h> |
39 | #include <linux/list.h> | 39 | #include <linux/list.h> |
40 | #include <linux/random.h> | 40 | #include <linux/random.h> |
41 | #include <asm/div64.h> | ||
42 | 41 | ||
43 | /* Default simulator parameters values */ | 42 | /* Default simulator parameters values */ |
44 | #if !defined(CONFIG_NANDSIM_FIRST_ID_BYTE) || \ | 43 | #if !defined(CONFIG_NANDSIM_FIRST_ID_BYTE) || \ |
diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c index a64ad15b8fdd..c0fa9c9edf08 100644 --- a/drivers/mtd/nand/pxa3xx_nand.c +++ b/drivers/mtd/nand/pxa3xx_nand.c | |||
@@ -115,55 +115,11 @@ enum { | |||
115 | STATE_PIO_WRITING, | 115 | STATE_PIO_WRITING, |
116 | }; | 116 | }; |
117 | 117 | ||
118 | struct pxa3xx_nand_timing { | ||
119 | unsigned int tCH; /* Enable signal hold time */ | ||
120 | unsigned int tCS; /* Enable signal setup time */ | ||
121 | unsigned int tWH; /* ND_nWE high duration */ | ||
122 | unsigned int tWP; /* ND_nWE pulse time */ | ||
123 | unsigned int tRH; /* ND_nRE high duration */ | ||
124 | unsigned int tRP; /* ND_nRE pulse width */ | ||
125 | unsigned int tR; /* ND_nWE high to ND_nRE low for read */ | ||
126 | unsigned int tWHR; /* ND_nWE high to ND_nRE low for status read */ | ||
127 | unsigned int tAR; /* ND_ALE low to ND_nRE low delay */ | ||
128 | }; | ||
129 | |||
130 | struct pxa3xx_nand_cmdset { | ||
131 | uint16_t read1; | ||
132 | uint16_t read2; | ||
133 | uint16_t program; | ||
134 | uint16_t read_status; | ||
135 | uint16_t read_id; | ||
136 | uint16_t erase; | ||
137 | uint16_t reset; | ||
138 | uint16_t lock; | ||
139 | uint16_t unlock; | ||
140 | uint16_t lock_status; | ||
141 | }; | ||
142 | |||
143 | struct pxa3xx_nand_flash { | ||
144 | struct pxa3xx_nand_timing *timing; /* NAND Flash timing */ | ||
145 | struct pxa3xx_nand_cmdset *cmdset; | ||
146 | |||
147 | uint32_t page_per_block;/* Pages per block (PG_PER_BLK) */ | ||
148 | uint32_t page_size; /* Page size in bytes (PAGE_SZ) */ | ||
149 | uint32_t flash_width; /* Width of Flash memory (DWIDTH_M) */ | ||
150 | uint32_t dfc_width; /* Width of flash controller(DWIDTH_C) */ | ||
151 | uint32_t num_blocks; /* Number of physical blocks in Flash */ | ||
152 | uint32_t chip_id; | ||
153 | |||
154 | /* NOTE: these are automatically calculated, do not define */ | ||
155 | size_t oob_size; | ||
156 | size_t read_id_bytes; | ||
157 | |||
158 | unsigned int col_addr_cycles; | ||
159 | unsigned int row_addr_cycles; | ||
160 | }; | ||
161 | |||
162 | struct pxa3xx_nand_info { | 118 | struct pxa3xx_nand_info { |
163 | struct nand_chip nand_chip; | 119 | struct nand_chip nand_chip; |
164 | 120 | ||
165 | struct platform_device *pdev; | 121 | struct platform_device *pdev; |
166 | struct pxa3xx_nand_flash *flash_info; | 122 | const struct pxa3xx_nand_flash *flash_info; |
167 | 123 | ||
168 | struct clk *clk; | 124 | struct clk *clk; |
169 | void __iomem *mmio_base; | 125 | void __iomem *mmio_base; |
@@ -202,12 +158,20 @@ struct pxa3xx_nand_info { | |||
202 | uint32_t ndcb0; | 158 | uint32_t ndcb0; |
203 | uint32_t ndcb1; | 159 | uint32_t ndcb1; |
204 | uint32_t ndcb2; | 160 | uint32_t ndcb2; |
161 | |||
162 | /* calculated from pxa3xx_nand_flash data */ | ||
163 | size_t oob_size; | ||
164 | size_t read_id_bytes; | ||
165 | |||
166 | unsigned int col_addr_cycles; | ||
167 | unsigned int row_addr_cycles; | ||
205 | }; | 168 | }; |
206 | 169 | ||
207 | static int use_dma = 1; | 170 | static int use_dma = 1; |
208 | module_param(use_dma, bool, 0444); | 171 | module_param(use_dma, bool, 0444); |
209 | MODULE_PARM_DESC(use_dma, "enable DMA for data transfering to/from NAND HW"); | 172 | MODULE_PARM_DESC(use_dma, "enable DMA for data transfering to/from NAND HW"); |
210 | 173 | ||
174 | #ifdef CONFIG_MTD_NAND_PXA3xx_BUILTIN | ||
211 | static struct pxa3xx_nand_cmdset smallpage_cmdset = { | 175 | static struct pxa3xx_nand_cmdset smallpage_cmdset = { |
212 | .read1 = 0x0000, | 176 | .read1 = 0x0000, |
213 | .read2 = 0x0050, | 177 | .read2 = 0x0050, |
@@ -291,11 +255,35 @@ static struct pxa3xx_nand_flash micron1GbX16 = { | |||
291 | .chip_id = 0xb12c, | 255 | .chip_id = 0xb12c, |
292 | }; | 256 | }; |
293 | 257 | ||
258 | static struct pxa3xx_nand_timing stm2GbX16_timing = { | ||
259 | .tCH = 10, | ||
260 | .tCS = 35, | ||
261 | .tWH = 15, | ||
262 | .tWP = 25, | ||
263 | .tRH = 15, | ||
264 | .tRP = 25, | ||
265 | .tR = 25000, | ||
266 | .tWHR = 60, | ||
267 | .tAR = 10, | ||
268 | }; | ||
269 | |||
270 | static struct pxa3xx_nand_flash stm2GbX16 = { | ||
271 | .timing = &stm2GbX16_timing, | ||
272 | .page_per_block = 64, | ||
273 | .page_size = 2048, | ||
274 | .flash_width = 16, | ||
275 | .dfc_width = 16, | ||
276 | .num_blocks = 2048, | ||
277 | .chip_id = 0xba20, | ||
278 | }; | ||
279 | |||
294 | static struct pxa3xx_nand_flash *builtin_flash_types[] = { | 280 | static struct pxa3xx_nand_flash *builtin_flash_types[] = { |
295 | &samsung512MbX16, | 281 | &samsung512MbX16, |
296 | µn1GbX8, | 282 | µn1GbX8, |
297 | µn1GbX16, | 283 | µn1GbX16, |
284 | &stm2GbX16, | ||
298 | }; | 285 | }; |
286 | #endif /* CONFIG_MTD_NAND_PXA3xx_BUILTIN */ | ||
299 | 287 | ||
300 | #define NDTR0_tCH(c) (min((c), 7) << 19) | 288 | #define NDTR0_tCH(c) (min((c), 7) << 19) |
301 | #define NDTR0_tCS(c) (min((c), 7) << 16) | 289 | #define NDTR0_tCS(c) (min((c), 7) << 16) |
@@ -312,7 +300,7 @@ static struct pxa3xx_nand_flash *builtin_flash_types[] = { | |||
312 | #define ns2cycle(ns, clk) (int)(((ns) * (clk / 1000000) / 1000) + 1) | 300 | #define ns2cycle(ns, clk) (int)(((ns) * (clk / 1000000) / 1000) + 1) |
313 | 301 | ||
314 | static void pxa3xx_nand_set_timing(struct pxa3xx_nand_info *info, | 302 | static void pxa3xx_nand_set_timing(struct pxa3xx_nand_info *info, |
315 | struct pxa3xx_nand_timing *t) | 303 | const struct pxa3xx_nand_timing *t) |
316 | { | 304 | { |
317 | unsigned long nand_clk = clk_get_rate(info->clk); | 305 | unsigned long nand_clk = clk_get_rate(info->clk); |
318 | uint32_t ndtr0, ndtr1; | 306 | uint32_t ndtr0, ndtr1; |
@@ -354,8 +342,8 @@ static int wait_for_event(struct pxa3xx_nand_info *info, uint32_t event) | |||
354 | static int prepare_read_prog_cmd(struct pxa3xx_nand_info *info, | 342 | static int prepare_read_prog_cmd(struct pxa3xx_nand_info *info, |
355 | uint16_t cmd, int column, int page_addr) | 343 | uint16_t cmd, int column, int page_addr) |
356 | { | 344 | { |
357 | struct pxa3xx_nand_flash *f = info->flash_info; | 345 | const struct pxa3xx_nand_flash *f = info->flash_info; |
358 | struct pxa3xx_nand_cmdset *cmdset = f->cmdset; | 346 | const struct pxa3xx_nand_cmdset *cmdset = f->cmdset; |
359 | 347 | ||
360 | /* calculate data size */ | 348 | /* calculate data size */ |
361 | switch (f->page_size) { | 349 | switch (f->page_size) { |
@@ -373,14 +361,14 @@ static int prepare_read_prog_cmd(struct pxa3xx_nand_info *info, | |||
373 | info->ndcb0 = cmd | ((cmd & 0xff00) ? NDCB0_DBC : 0); | 361 | info->ndcb0 = cmd | ((cmd & 0xff00) ? NDCB0_DBC : 0); |
374 | info->ndcb1 = 0; | 362 | info->ndcb1 = 0; |
375 | info->ndcb2 = 0; | 363 | info->ndcb2 = 0; |
376 | info->ndcb0 |= NDCB0_ADDR_CYC(f->row_addr_cycles + f->col_addr_cycles); | 364 | info->ndcb0 |= NDCB0_ADDR_CYC(info->row_addr_cycles + info->col_addr_cycles); |
377 | 365 | ||
378 | if (f->col_addr_cycles == 2) { | 366 | if (info->col_addr_cycles == 2) { |
379 | /* large block, 2 cycles for column address | 367 | /* large block, 2 cycles for column address |
380 | * row address starts from 3rd cycle | 368 | * row address starts from 3rd cycle |
381 | */ | 369 | */ |
382 | info->ndcb1 |= (page_addr << 16) | (column & 0xffff); | 370 | info->ndcb1 |= (page_addr << 16) | (column & 0xffff); |
383 | if (f->row_addr_cycles == 3) | 371 | if (info->row_addr_cycles == 3) |
384 | info->ndcb2 = (page_addr >> 16) & 0xff; | 372 | info->ndcb2 = (page_addr >> 16) & 0xff; |
385 | } else | 373 | } else |
386 | /* small block, 1 cycles for column address | 374 | /* small block, 1 cycles for column address |
@@ -406,7 +394,7 @@ static int prepare_erase_cmd(struct pxa3xx_nand_info *info, | |||
406 | 394 | ||
407 | static int prepare_other_cmd(struct pxa3xx_nand_info *info, uint16_t cmd) | 395 | static int prepare_other_cmd(struct pxa3xx_nand_info *info, uint16_t cmd) |
408 | { | 396 | { |
409 | struct pxa3xx_nand_cmdset *cmdset = info->flash_info->cmdset; | 397 | const struct pxa3xx_nand_cmdset *cmdset = info->flash_info->cmdset; |
410 | 398 | ||
411 | info->ndcb0 = cmd | ((cmd & 0xff00) ? NDCB0_DBC : 0); | 399 | info->ndcb0 = cmd | ((cmd & 0xff00) ? NDCB0_DBC : 0); |
412 | info->ndcb1 = 0; | 400 | info->ndcb1 = 0; |
@@ -641,8 +629,8 @@ static void pxa3xx_nand_cmdfunc(struct mtd_info *mtd, unsigned command, | |||
641 | int column, int page_addr) | 629 | int column, int page_addr) |
642 | { | 630 | { |
643 | struct pxa3xx_nand_info *info = mtd->priv; | 631 | struct pxa3xx_nand_info *info = mtd->priv; |
644 | struct pxa3xx_nand_flash *flash_info = info->flash_info; | 632 | const struct pxa3xx_nand_flash *flash_info = info->flash_info; |
645 | struct pxa3xx_nand_cmdset *cmdset = flash_info->cmdset; | 633 | const struct pxa3xx_nand_cmdset *cmdset = flash_info->cmdset; |
646 | int ret; | 634 | int ret; |
647 | 635 | ||
648 | info->use_dma = (use_dma) ? 1 : 0; | 636 | info->use_dma = (use_dma) ? 1 : 0; |
@@ -720,7 +708,7 @@ static void pxa3xx_nand_cmdfunc(struct mtd_info *mtd, unsigned command, | |||
720 | info->use_dma = 0; /* force PIO read */ | 708 | info->use_dma = 0; /* force PIO read */ |
721 | info->buf_start = 0; | 709 | info->buf_start = 0; |
722 | info->buf_count = (command == NAND_CMD_READID) ? | 710 | info->buf_count = (command == NAND_CMD_READID) ? |
723 | flash_info->read_id_bytes : 1; | 711 | info->read_id_bytes : 1; |
724 | 712 | ||
725 | if (prepare_other_cmd(info, (command == NAND_CMD_READID) ? | 713 | if (prepare_other_cmd(info, (command == NAND_CMD_READID) ? |
726 | cmdset->read_id : cmdset->read_status)) | 714 | cmdset->read_id : cmdset->read_status)) |
@@ -861,8 +849,8 @@ static int pxa3xx_nand_ecc_correct(struct mtd_info *mtd, | |||
861 | 849 | ||
862 | static int __readid(struct pxa3xx_nand_info *info, uint32_t *id) | 850 | static int __readid(struct pxa3xx_nand_info *info, uint32_t *id) |
863 | { | 851 | { |
864 | struct pxa3xx_nand_flash *f = info->flash_info; | 852 | const struct pxa3xx_nand_flash *f = info->flash_info; |
865 | struct pxa3xx_nand_cmdset *cmdset = f->cmdset; | 853 | const struct pxa3xx_nand_cmdset *cmdset = f->cmdset; |
866 | uint32_t ndcr; | 854 | uint32_t ndcr; |
867 | uint8_t id_buff[8]; | 855 | uint8_t id_buff[8]; |
868 | 856 | ||
@@ -891,7 +879,7 @@ fail_timeout: | |||
891 | } | 879 | } |
892 | 880 | ||
893 | static int pxa3xx_nand_config_flash(struct pxa3xx_nand_info *info, | 881 | static int pxa3xx_nand_config_flash(struct pxa3xx_nand_info *info, |
894 | struct pxa3xx_nand_flash *f) | 882 | const struct pxa3xx_nand_flash *f) |
895 | { | 883 | { |
896 | struct platform_device *pdev = info->pdev; | 884 | struct platform_device *pdev = info->pdev; |
897 | struct pxa3xx_nand_platform_data *pdata = pdev->dev.platform_data; | 885 | struct pxa3xx_nand_platform_data *pdata = pdev->dev.platform_data; |
@@ -904,25 +892,25 @@ static int pxa3xx_nand_config_flash(struct pxa3xx_nand_info *info, | |||
904 | return -EINVAL; | 892 | return -EINVAL; |
905 | 893 | ||
906 | /* calculate flash information */ | 894 | /* calculate flash information */ |
907 | f->oob_size = (f->page_size == 2048) ? 64 : 16; | 895 | info->oob_size = (f->page_size == 2048) ? 64 : 16; |
908 | f->read_id_bytes = (f->page_size == 2048) ? 4 : 2; | 896 | info->read_id_bytes = (f->page_size == 2048) ? 4 : 2; |
909 | 897 | ||
910 | /* calculate addressing information */ | 898 | /* calculate addressing information */ |
911 | f->col_addr_cycles = (f->page_size == 2048) ? 2 : 1; | 899 | info->col_addr_cycles = (f->page_size == 2048) ? 2 : 1; |
912 | 900 | ||
913 | if (f->num_blocks * f->page_per_block > 65536) | 901 | if (f->num_blocks * f->page_per_block > 65536) |
914 | f->row_addr_cycles = 3; | 902 | info->row_addr_cycles = 3; |
915 | else | 903 | else |
916 | f->row_addr_cycles = 2; | 904 | info->row_addr_cycles = 2; |
917 | 905 | ||
918 | ndcr |= (pdata->enable_arbiter) ? NDCR_ND_ARB_EN : 0; | 906 | ndcr |= (pdata->enable_arbiter) ? NDCR_ND_ARB_EN : 0; |
919 | ndcr |= (f->col_addr_cycles == 2) ? NDCR_RA_START : 0; | 907 | ndcr |= (info->col_addr_cycles == 2) ? NDCR_RA_START : 0; |
920 | ndcr |= (f->page_per_block == 64) ? NDCR_PG_PER_BLK : 0; | 908 | ndcr |= (f->page_per_block == 64) ? NDCR_PG_PER_BLK : 0; |
921 | ndcr |= (f->page_size == 2048) ? NDCR_PAGE_SZ : 0; | 909 | ndcr |= (f->page_size == 2048) ? NDCR_PAGE_SZ : 0; |
922 | ndcr |= (f->flash_width == 16) ? NDCR_DWIDTH_M : 0; | 910 | ndcr |= (f->flash_width == 16) ? NDCR_DWIDTH_M : 0; |
923 | ndcr |= (f->dfc_width == 16) ? NDCR_DWIDTH_C : 0; | 911 | ndcr |= (f->dfc_width == 16) ? NDCR_DWIDTH_C : 0; |
924 | 912 | ||
925 | ndcr |= NDCR_RD_ID_CNT(f->read_id_bytes); | 913 | ndcr |= NDCR_RD_ID_CNT(info->read_id_bytes); |
926 | ndcr |= NDCR_SPARE_EN; /* enable spare by default */ | 914 | ndcr |= NDCR_SPARE_EN; /* enable spare by default */ |
927 | 915 | ||
928 | info->reg_ndcr = ndcr; | 916 | info->reg_ndcr = ndcr; |
@@ -932,12 +920,27 @@ static int pxa3xx_nand_config_flash(struct pxa3xx_nand_info *info, | |||
932 | return 0; | 920 | return 0; |
933 | } | 921 | } |
934 | 922 | ||
935 | static int pxa3xx_nand_detect_flash(struct pxa3xx_nand_info *info) | 923 | static int pxa3xx_nand_detect_flash(struct pxa3xx_nand_info *info, |
924 | const struct pxa3xx_nand_platform_data *pdata) | ||
936 | { | 925 | { |
937 | struct pxa3xx_nand_flash *f; | 926 | const struct pxa3xx_nand_flash *f; |
938 | uint32_t id; | 927 | uint32_t id = -1; |
939 | int i; | 928 | int i; |
940 | 929 | ||
930 | for (i = 0; i<pdata->num_flash; ++i) { | ||
931 | f = pdata->flash + i; | ||
932 | |||
933 | if (pxa3xx_nand_config_flash(info, f)) | ||
934 | continue; | ||
935 | |||
936 | if (__readid(info, &id)) | ||
937 | continue; | ||
938 | |||
939 | if (id == f->chip_id) | ||
940 | return 0; | ||
941 | } | ||
942 | |||
943 | #ifdef CONFIG_MTD_NAND_PXA3xx_BUILTIN | ||
941 | for (i = 0; i < ARRAY_SIZE(builtin_flash_types); i++) { | 944 | for (i = 0; i < ARRAY_SIZE(builtin_flash_types); i++) { |
942 | 945 | ||
943 | f = builtin_flash_types[i]; | 946 | f = builtin_flash_types[i]; |
@@ -951,7 +954,11 @@ static int pxa3xx_nand_detect_flash(struct pxa3xx_nand_info *info) | |||
951 | if (id == f->chip_id) | 954 | if (id == f->chip_id) |
952 | return 0; | 955 | return 0; |
953 | } | 956 | } |
957 | #endif | ||
954 | 958 | ||
959 | dev_warn(&info->pdev->dev, | ||
960 | "failed to detect configured nand flash; found %04x instead of\n", | ||
961 | id); | ||
955 | return -ENODEV; | 962 | return -ENODEV; |
956 | } | 963 | } |
957 | 964 | ||
@@ -1014,7 +1021,7 @@ static struct nand_ecclayout hw_largepage_ecclayout = { | |||
1014 | static void pxa3xx_nand_init_mtd(struct mtd_info *mtd, | 1021 | static void pxa3xx_nand_init_mtd(struct mtd_info *mtd, |
1015 | struct pxa3xx_nand_info *info) | 1022 | struct pxa3xx_nand_info *info) |
1016 | { | 1023 | { |
1017 | struct pxa3xx_nand_flash *f = info->flash_info; | 1024 | const struct pxa3xx_nand_flash *f = info->flash_info; |
1018 | struct nand_chip *this = &info->nand_chip; | 1025 | struct nand_chip *this = &info->nand_chip; |
1019 | 1026 | ||
1020 | this->options = (f->flash_width == 16) ? NAND_BUSWIDTH_16: 0; | 1027 | this->options = (f->flash_width == 16) ? NAND_BUSWIDTH_16: 0; |
@@ -1135,7 +1142,7 @@ static int pxa3xx_nand_probe(struct platform_device *pdev) | |||
1135 | goto fail_free_buf; | 1142 | goto fail_free_buf; |
1136 | } | 1143 | } |
1137 | 1144 | ||
1138 | ret = pxa3xx_nand_detect_flash(info); | 1145 | ret = pxa3xx_nand_detect_flash(info, pdata); |
1139 | if (ret) { | 1146 | if (ret) { |
1140 | dev_err(&pdev->dev, "failed to detect flash\n"); | 1147 | dev_err(&pdev->dev, "failed to detect flash\n"); |
1141 | ret = -ENODEV; | 1148 | ret = -ENODEV; |
diff --git a/drivers/mtd/nand/sh_flctl.c b/drivers/mtd/nand/sh_flctl.c new file mode 100644 index 000000000000..821acb08ff1c --- /dev/null +++ b/drivers/mtd/nand/sh_flctl.c | |||
@@ -0,0 +1,878 @@ | |||
1 | /* | ||
2 | * SuperH FLCTL nand controller | ||
3 | * | ||
4 | * Copyright © 2008 Renesas Solutions Corp. | ||
5 | * Copyright © 2008 Atom Create Engineering Co., Ltd. | ||
6 | * | ||
7 | * Based on fsl_elbc_nand.c, Copyright © 2006-2007 Freescale Semiconductor | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; version 2 of the License. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
21 | * | ||
22 | */ | ||
23 | |||
24 | #include <linux/module.h> | ||
25 | #include <linux/kernel.h> | ||
26 | #include <linux/delay.h> | ||
27 | #include <linux/io.h> | ||
28 | #include <linux/platform_device.h> | ||
29 | |||
30 | #include <linux/mtd/mtd.h> | ||
31 | #include <linux/mtd/nand.h> | ||
32 | #include <linux/mtd/partitions.h> | ||
33 | #include <linux/mtd/sh_flctl.h> | ||
34 | |||
35 | static struct nand_ecclayout flctl_4secc_oob_16 = { | ||
36 | .eccbytes = 10, | ||
37 | .eccpos = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, | ||
38 | .oobfree = { | ||
39 | {.offset = 12, | ||
40 | . length = 4} }, | ||
41 | }; | ||
42 | |||
43 | static struct nand_ecclayout flctl_4secc_oob_64 = { | ||
44 | .eccbytes = 10, | ||
45 | .eccpos = {48, 49, 50, 51, 52, 53, 54, 55, 56, 57}, | ||
46 | .oobfree = { | ||
47 | {.offset = 60, | ||
48 | . length = 4} }, | ||
49 | }; | ||
50 | |||
51 | static uint8_t scan_ff_pattern[] = { 0xff, 0xff }; | ||
52 | |||
53 | static struct nand_bbt_descr flctl_4secc_smallpage = { | ||
54 | .options = NAND_BBT_SCAN2NDPAGE, | ||
55 | .offs = 11, | ||
56 | .len = 1, | ||
57 | .pattern = scan_ff_pattern, | ||
58 | }; | ||
59 | |||
60 | static struct nand_bbt_descr flctl_4secc_largepage = { | ||
61 | .options = 0, | ||
62 | .offs = 58, | ||
63 | .len = 2, | ||
64 | .pattern = scan_ff_pattern, | ||
65 | }; | ||
66 | |||
67 | static void empty_fifo(struct sh_flctl *flctl) | ||
68 | { | ||
69 | writel(0x000c0000, FLINTDMACR(flctl)); /* FIFO Clear */ | ||
70 | writel(0x00000000, FLINTDMACR(flctl)); /* Clear Error flags */ | ||
71 | } | ||
72 | |||
73 | static void start_translation(struct sh_flctl *flctl) | ||
74 | { | ||
75 | writeb(TRSTRT, FLTRCR(flctl)); | ||
76 | } | ||
77 | |||
78 | static void wait_completion(struct sh_flctl *flctl) | ||
79 | { | ||
80 | uint32_t timeout = LOOP_TIMEOUT_MAX; | ||
81 | |||
82 | while (timeout--) { | ||
83 | if (readb(FLTRCR(flctl)) & TREND) { | ||
84 | writeb(0x0, FLTRCR(flctl)); | ||
85 | return; | ||
86 | } | ||
87 | udelay(1); | ||
88 | } | ||
89 | |||
90 | printk(KERN_ERR "wait_completion(): Timeout occured \n"); | ||
91 | writeb(0x0, FLTRCR(flctl)); | ||
92 | } | ||
93 | |||
94 | static void set_addr(struct mtd_info *mtd, int column, int page_addr) | ||
95 | { | ||
96 | struct sh_flctl *flctl = mtd_to_flctl(mtd); | ||
97 | uint32_t addr = 0; | ||
98 | |||
99 | if (column == -1) { | ||
100 | addr = page_addr; /* ERASE1 */ | ||
101 | } else if (page_addr != -1) { | ||
102 | /* SEQIN, READ0, etc.. */ | ||
103 | if (flctl->page_size) { | ||
104 | addr = column & 0x0FFF; | ||
105 | addr |= (page_addr & 0xff) << 16; | ||
106 | addr |= ((page_addr >> 8) & 0xff) << 24; | ||
107 | /* big than 128MB */ | ||
108 | if (flctl->rw_ADRCNT == ADRCNT2_E) { | ||
109 | uint32_t addr2; | ||
110 | addr2 = (page_addr >> 16) & 0xff; | ||
111 | writel(addr2, FLADR2(flctl)); | ||
112 | } | ||
113 | } else { | ||
114 | addr = column; | ||
115 | addr |= (page_addr & 0xff) << 8; | ||
116 | addr |= ((page_addr >> 8) & 0xff) << 16; | ||
117 | addr |= ((page_addr >> 16) & 0xff) << 24; | ||
118 | } | ||
119 | } | ||
120 | writel(addr, FLADR(flctl)); | ||
121 | } | ||
122 | |||
123 | static void wait_rfifo_ready(struct sh_flctl *flctl) | ||
124 | { | ||
125 | uint32_t timeout = LOOP_TIMEOUT_MAX; | ||
126 | |||
127 | while (timeout--) { | ||
128 | uint32_t val; | ||
129 | /* check FIFO */ | ||
130 | val = readl(FLDTCNTR(flctl)) >> 16; | ||
131 | if (val & 0xFF) | ||
132 | return; | ||
133 | udelay(1); | ||
134 | } | ||
135 | printk(KERN_ERR "wait_rfifo_ready(): Timeout occured \n"); | ||
136 | } | ||
137 | |||
138 | static void wait_wfifo_ready(struct sh_flctl *flctl) | ||
139 | { | ||
140 | uint32_t len, timeout = LOOP_TIMEOUT_MAX; | ||
141 | |||
142 | while (timeout--) { | ||
143 | /* check FIFO */ | ||
144 | len = (readl(FLDTCNTR(flctl)) >> 16) & 0xFF; | ||
145 | if (len >= 4) | ||
146 | return; | ||
147 | udelay(1); | ||
148 | } | ||
149 | printk(KERN_ERR "wait_wfifo_ready(): Timeout occured \n"); | ||
150 | } | ||
151 | |||
152 | static int wait_recfifo_ready(struct sh_flctl *flctl) | ||
153 | { | ||
154 | uint32_t timeout = LOOP_TIMEOUT_MAX; | ||
155 | int checked[4]; | ||
156 | void __iomem *ecc_reg[4]; | ||
157 | int i; | ||
158 | uint32_t data, size; | ||
159 | |||
160 | memset(checked, 0, sizeof(checked)); | ||
161 | |||
162 | while (timeout--) { | ||
163 | size = readl(FLDTCNTR(flctl)) >> 24; | ||
164 | if (size & 0xFF) | ||
165 | return 0; /* success */ | ||
166 | |||
167 | if (readl(FL4ECCCR(flctl)) & _4ECCFA) | ||
168 | return 1; /* can't correct */ | ||
169 | |||
170 | udelay(1); | ||
171 | if (!(readl(FL4ECCCR(flctl)) & _4ECCEND)) | ||
172 | continue; | ||
173 | |||
174 | /* start error correction */ | ||
175 | ecc_reg[0] = FL4ECCRESULT0(flctl); | ||
176 | ecc_reg[1] = FL4ECCRESULT1(flctl); | ||
177 | ecc_reg[2] = FL4ECCRESULT2(flctl); | ||
178 | ecc_reg[3] = FL4ECCRESULT3(flctl); | ||
179 | |||
180 | for (i = 0; i < 3; i++) { | ||
181 | data = readl(ecc_reg[i]); | ||
182 | if (data != INIT_FL4ECCRESULT_VAL && !checked[i]) { | ||
183 | uint8_t org; | ||
184 | int index; | ||
185 | |||
186 | index = data >> 16; | ||
187 | org = flctl->done_buff[index]; | ||
188 | flctl->done_buff[index] = org ^ (data & 0xFF); | ||
189 | checked[i] = 1; | ||
190 | } | ||
191 | } | ||
192 | |||
193 | writel(0, FL4ECCCR(flctl)); | ||
194 | } | ||
195 | |||
196 | printk(KERN_ERR "wait_recfifo_ready(): Timeout occured \n"); | ||
197 | return 1; /* timeout */ | ||
198 | } | ||
199 | |||
200 | static void wait_wecfifo_ready(struct sh_flctl *flctl) | ||
201 | { | ||
202 | uint32_t timeout = LOOP_TIMEOUT_MAX; | ||
203 | uint32_t len; | ||
204 | |||
205 | while (timeout--) { | ||
206 | /* check FLECFIFO */ | ||
207 | len = (readl(FLDTCNTR(flctl)) >> 24) & 0xFF; | ||
208 | if (len >= 4) | ||
209 | return; | ||
210 | udelay(1); | ||
211 | } | ||
212 | printk(KERN_ERR "wait_wecfifo_ready(): Timeout occured \n"); | ||
213 | } | ||
214 | |||
215 | static void read_datareg(struct sh_flctl *flctl, int offset) | ||
216 | { | ||
217 | unsigned long data; | ||
218 | unsigned long *buf = (unsigned long *)&flctl->done_buff[offset]; | ||
219 | |||
220 | wait_completion(flctl); | ||
221 | |||
222 | data = readl(FLDATAR(flctl)); | ||
223 | *buf = le32_to_cpu(data); | ||
224 | } | ||
225 | |||
226 | static void read_fiforeg(struct sh_flctl *flctl, int rlen, int offset) | ||
227 | { | ||
228 | int i, len_4align; | ||
229 | unsigned long *buf = (unsigned long *)&flctl->done_buff[offset]; | ||
230 | void *fifo_addr = (void *)FLDTFIFO(flctl); | ||
231 | |||
232 | len_4align = (rlen + 3) / 4; | ||
233 | |||
234 | for (i = 0; i < len_4align; i++) { | ||
235 | wait_rfifo_ready(flctl); | ||
236 | buf[i] = readl(fifo_addr); | ||
237 | buf[i] = be32_to_cpu(buf[i]); | ||
238 | } | ||
239 | } | ||
240 | |||
241 | static int read_ecfiforeg(struct sh_flctl *flctl, uint8_t *buff) | ||
242 | { | ||
243 | int i; | ||
244 | unsigned long *ecc_buf = (unsigned long *)buff; | ||
245 | void *fifo_addr = (void *)FLECFIFO(flctl); | ||
246 | |||
247 | for (i = 0; i < 4; i++) { | ||
248 | if (wait_recfifo_ready(flctl)) | ||
249 | return 1; | ||
250 | ecc_buf[i] = readl(fifo_addr); | ||
251 | ecc_buf[i] = be32_to_cpu(ecc_buf[i]); | ||
252 | } | ||
253 | |||
254 | return 0; | ||
255 | } | ||
256 | |||
257 | static void write_fiforeg(struct sh_flctl *flctl, int rlen, int offset) | ||
258 | { | ||
259 | int i, len_4align; | ||
260 | unsigned long *data = (unsigned long *)&flctl->done_buff[offset]; | ||
261 | void *fifo_addr = (void *)FLDTFIFO(flctl); | ||
262 | |||
263 | len_4align = (rlen + 3) / 4; | ||
264 | for (i = 0; i < len_4align; i++) { | ||
265 | wait_wfifo_ready(flctl); | ||
266 | writel(cpu_to_be32(data[i]), fifo_addr); | ||
267 | } | ||
268 | } | ||
269 | |||
270 | static void set_cmd_regs(struct mtd_info *mtd, uint32_t cmd, uint32_t flcmcdr_val) | ||
271 | { | ||
272 | struct sh_flctl *flctl = mtd_to_flctl(mtd); | ||
273 | uint32_t flcmncr_val = readl(FLCMNCR(flctl)); | ||
274 | uint32_t flcmdcr_val, addr_len_bytes = 0; | ||
275 | |||
276 | /* Set SNAND bit if page size is 2048byte */ | ||
277 | if (flctl->page_size) | ||
278 | flcmncr_val |= SNAND_E; | ||
279 | else | ||
280 | flcmncr_val &= ~SNAND_E; | ||
281 | |||
282 | /* default FLCMDCR val */ | ||
283 | flcmdcr_val = DOCMD1_E | DOADR_E; | ||
284 | |||
285 | /* Set for FLCMDCR */ | ||
286 | switch (cmd) { | ||
287 | case NAND_CMD_ERASE1: | ||
288 | addr_len_bytes = flctl->erase_ADRCNT; | ||
289 | flcmdcr_val |= DOCMD2_E; | ||
290 | break; | ||
291 | case NAND_CMD_READ0: | ||
292 | case NAND_CMD_READOOB: | ||
293 | addr_len_bytes = flctl->rw_ADRCNT; | ||
294 | flcmdcr_val |= CDSRC_E; | ||
295 | break; | ||
296 | case NAND_CMD_SEQIN: | ||
297 | /* This case is that cmd is READ0 or READ1 or READ00 */ | ||
298 | flcmdcr_val &= ~DOADR_E; /* ONLY execute 1st cmd */ | ||
299 | break; | ||
300 | case NAND_CMD_PAGEPROG: | ||
301 | addr_len_bytes = flctl->rw_ADRCNT; | ||
302 | flcmdcr_val |= DOCMD2_E | CDSRC_E | SELRW; | ||
303 | break; | ||
304 | case NAND_CMD_READID: | ||
305 | flcmncr_val &= ~SNAND_E; | ||
306 | addr_len_bytes = ADRCNT_1; | ||
307 | break; | ||
308 | case NAND_CMD_STATUS: | ||
309 | case NAND_CMD_RESET: | ||
310 | flcmncr_val &= ~SNAND_E; | ||
311 | flcmdcr_val &= ~(DOADR_E | DOSR_E); | ||
312 | break; | ||
313 | default: | ||
314 | break; | ||
315 | } | ||
316 | |||
317 | /* Set address bytes parameter */ | ||
318 | flcmdcr_val |= addr_len_bytes; | ||
319 | |||
320 | /* Now actually write */ | ||
321 | writel(flcmncr_val, FLCMNCR(flctl)); | ||
322 | writel(flcmdcr_val, FLCMDCR(flctl)); | ||
323 | writel(flcmcdr_val, FLCMCDR(flctl)); | ||
324 | } | ||
325 | |||
326 | static int flctl_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip, | ||
327 | uint8_t *buf) | ||
328 | { | ||
329 | int i, eccsize = chip->ecc.size; | ||
330 | int eccbytes = chip->ecc.bytes; | ||
331 | int eccsteps = chip->ecc.steps; | ||
332 | uint8_t *p = buf; | ||
333 | struct sh_flctl *flctl = mtd_to_flctl(mtd); | ||
334 | |||
335 | for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) | ||
336 | chip->read_buf(mtd, p, eccsize); | ||
337 | |||
338 | for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) { | ||
339 | if (flctl->hwecc_cant_correct[i]) | ||
340 | mtd->ecc_stats.failed++; | ||
341 | else | ||
342 | mtd->ecc_stats.corrected += 0; | ||
343 | } | ||
344 | |||
345 | return 0; | ||
346 | } | ||
347 | |||
348 | static void flctl_write_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip, | ||
349 | const uint8_t *buf) | ||
350 | { | ||
351 | int i, eccsize = chip->ecc.size; | ||
352 | int eccbytes = chip->ecc.bytes; | ||
353 | int eccsteps = chip->ecc.steps; | ||
354 | const uint8_t *p = buf; | ||
355 | |||
356 | for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) | ||
357 | chip->write_buf(mtd, p, eccsize); | ||
358 | } | ||
359 | |||
360 | static void execmd_read_page_sector(struct mtd_info *mtd, int page_addr) | ||
361 | { | ||
362 | struct sh_flctl *flctl = mtd_to_flctl(mtd); | ||
363 | int sector, page_sectors; | ||
364 | |||
365 | if (flctl->page_size) | ||
366 | page_sectors = 4; | ||
367 | else | ||
368 | page_sectors = 1; | ||
369 | |||
370 | writel(readl(FLCMNCR(flctl)) | ACM_SACCES_MODE | _4ECCCORRECT, | ||
371 | FLCMNCR(flctl)); | ||
372 | |||
373 | set_cmd_regs(mtd, NAND_CMD_READ0, | ||
374 | (NAND_CMD_READSTART << 8) | NAND_CMD_READ0); | ||
375 | |||
376 | for (sector = 0; sector < page_sectors; sector++) { | ||
377 | int ret; | ||
378 | |||
379 | empty_fifo(flctl); | ||
380 | writel(readl(FLCMDCR(flctl)) | 1, FLCMDCR(flctl)); | ||
381 | writel(page_addr << 2 | sector, FLADR(flctl)); | ||
382 | |||
383 | start_translation(flctl); | ||
384 | read_fiforeg(flctl, 512, 512 * sector); | ||
385 | |||
386 | ret = read_ecfiforeg(flctl, | ||
387 | &flctl->done_buff[mtd->writesize + 16 * sector]); | ||
388 | |||
389 | if (ret) | ||
390 | flctl->hwecc_cant_correct[sector] = 1; | ||
391 | |||
392 | writel(0x0, FL4ECCCR(flctl)); | ||
393 | wait_completion(flctl); | ||
394 | } | ||
395 | writel(readl(FLCMNCR(flctl)) & ~(ACM_SACCES_MODE | _4ECCCORRECT), | ||
396 | FLCMNCR(flctl)); | ||
397 | } | ||
398 | |||
399 | static void execmd_read_oob(struct mtd_info *mtd, int page_addr) | ||
400 | { | ||
401 | struct sh_flctl *flctl = mtd_to_flctl(mtd); | ||
402 | |||
403 | set_cmd_regs(mtd, NAND_CMD_READ0, | ||
404 | (NAND_CMD_READSTART << 8) | NAND_CMD_READ0); | ||
405 | |||
406 | empty_fifo(flctl); | ||
407 | if (flctl->page_size) { | ||
408 | int i; | ||
409 | /* In case that the page size is 2k */ | ||
410 | for (i = 0; i < 16 * 3; i++) | ||
411 | flctl->done_buff[i] = 0xFF; | ||
412 | |||
413 | set_addr(mtd, 3 * 528 + 512, page_addr); | ||
414 | writel(16, FLDTCNTR(flctl)); | ||
415 | |||
416 | start_translation(flctl); | ||
417 | read_fiforeg(flctl, 16, 16 * 3); | ||
418 | wait_completion(flctl); | ||
419 | } else { | ||
420 | /* In case that the page size is 512b */ | ||
421 | set_addr(mtd, 512, page_addr); | ||
422 | writel(16, FLDTCNTR(flctl)); | ||
423 | |||
424 | start_translation(flctl); | ||
425 | read_fiforeg(flctl, 16, 0); | ||
426 | wait_completion(flctl); | ||
427 | } | ||
428 | } | ||
429 | |||
430 | static void execmd_write_page_sector(struct mtd_info *mtd) | ||
431 | { | ||
432 | struct sh_flctl *flctl = mtd_to_flctl(mtd); | ||
433 | int i, page_addr = flctl->seqin_page_addr; | ||
434 | int sector, page_sectors; | ||
435 | |||
436 | if (flctl->page_size) | ||
437 | page_sectors = 4; | ||
438 | else | ||
439 | page_sectors = 1; | ||
440 | |||
441 | writel(readl(FLCMNCR(flctl)) | ACM_SACCES_MODE, FLCMNCR(flctl)); | ||
442 | |||
443 | set_cmd_regs(mtd, NAND_CMD_PAGEPROG, | ||
444 | (NAND_CMD_PAGEPROG << 8) | NAND_CMD_SEQIN); | ||
445 | |||
446 | for (sector = 0; sector < page_sectors; sector++) { | ||
447 | empty_fifo(flctl); | ||
448 | writel(readl(FLCMDCR(flctl)) | 1, FLCMDCR(flctl)); | ||
449 | writel(page_addr << 2 | sector, FLADR(flctl)); | ||
450 | |||
451 | start_translation(flctl); | ||
452 | write_fiforeg(flctl, 512, 512 * sector); | ||
453 | |||
454 | for (i = 0; i < 4; i++) { | ||
455 | wait_wecfifo_ready(flctl); /* wait for write ready */ | ||
456 | writel(0xFFFFFFFF, FLECFIFO(flctl)); | ||
457 | } | ||
458 | wait_completion(flctl); | ||
459 | } | ||
460 | |||
461 | writel(readl(FLCMNCR(flctl)) & ~ACM_SACCES_MODE, FLCMNCR(flctl)); | ||
462 | } | ||
463 | |||
464 | static void execmd_write_oob(struct mtd_info *mtd) | ||
465 | { | ||
466 | struct sh_flctl *flctl = mtd_to_flctl(mtd); | ||
467 | int page_addr = flctl->seqin_page_addr; | ||
468 | int sector, page_sectors; | ||
469 | |||
470 | if (flctl->page_size) { | ||
471 | sector = 3; | ||
472 | page_sectors = 4; | ||
473 | } else { | ||
474 | sector = 0; | ||
475 | page_sectors = 1; | ||
476 | } | ||
477 | |||
478 | set_cmd_regs(mtd, NAND_CMD_PAGEPROG, | ||
479 | (NAND_CMD_PAGEPROG << 8) | NAND_CMD_SEQIN); | ||
480 | |||
481 | for (; sector < page_sectors; sector++) { | ||
482 | empty_fifo(flctl); | ||
483 | set_addr(mtd, sector * 528 + 512, page_addr); | ||
484 | writel(16, FLDTCNTR(flctl)); /* set read size */ | ||
485 | |||
486 | start_translation(flctl); | ||
487 | write_fiforeg(flctl, 16, 16 * sector); | ||
488 | wait_completion(flctl); | ||
489 | } | ||
490 | } | ||
491 | |||
492 | static void flctl_cmdfunc(struct mtd_info *mtd, unsigned int command, | ||
493 | int column, int page_addr) | ||
494 | { | ||
495 | struct sh_flctl *flctl = mtd_to_flctl(mtd); | ||
496 | uint32_t read_cmd = 0; | ||
497 | |||
498 | flctl->read_bytes = 0; | ||
499 | if (command != NAND_CMD_PAGEPROG) | ||
500 | flctl->index = 0; | ||
501 | |||
502 | switch (command) { | ||
503 | case NAND_CMD_READ1: | ||
504 | case NAND_CMD_READ0: | ||
505 | if (flctl->hwecc) { | ||
506 | /* read page with hwecc */ | ||
507 | execmd_read_page_sector(mtd, page_addr); | ||
508 | break; | ||
509 | } | ||
510 | empty_fifo(flctl); | ||
511 | if (flctl->page_size) | ||
512 | set_cmd_regs(mtd, command, (NAND_CMD_READSTART << 8) | ||
513 | | command); | ||
514 | else | ||
515 | set_cmd_regs(mtd, command, command); | ||
516 | |||
517 | set_addr(mtd, 0, page_addr); | ||
518 | |||
519 | flctl->read_bytes = mtd->writesize + mtd->oobsize; | ||
520 | flctl->index += column; | ||
521 | goto read_normal_exit; | ||
522 | |||
523 | case NAND_CMD_READOOB: | ||
524 | if (flctl->hwecc) { | ||
525 | /* read page with hwecc */ | ||
526 | execmd_read_oob(mtd, page_addr); | ||
527 | break; | ||
528 | } | ||
529 | |||
530 | empty_fifo(flctl); | ||
531 | if (flctl->page_size) { | ||
532 | set_cmd_regs(mtd, command, (NAND_CMD_READSTART << 8) | ||
533 | | NAND_CMD_READ0); | ||
534 | set_addr(mtd, mtd->writesize, page_addr); | ||
535 | } else { | ||
536 | set_cmd_regs(mtd, command, command); | ||
537 | set_addr(mtd, 0, page_addr); | ||
538 | } | ||
539 | flctl->read_bytes = mtd->oobsize; | ||
540 | goto read_normal_exit; | ||
541 | |||
542 | case NAND_CMD_READID: | ||
543 | empty_fifo(flctl); | ||
544 | set_cmd_regs(mtd, command, command); | ||
545 | set_addr(mtd, 0, 0); | ||
546 | |||
547 | flctl->read_bytes = 4; | ||
548 | writel(flctl->read_bytes, FLDTCNTR(flctl)); /* set read size */ | ||
549 | start_translation(flctl); | ||
550 | read_datareg(flctl, 0); /* read and end */ | ||
551 | break; | ||
552 | |||
553 | case NAND_CMD_ERASE1: | ||
554 | flctl->erase1_page_addr = page_addr; | ||
555 | break; | ||
556 | |||
557 | case NAND_CMD_ERASE2: | ||
558 | set_cmd_regs(mtd, NAND_CMD_ERASE1, | ||
559 | (command << 8) | NAND_CMD_ERASE1); | ||
560 | set_addr(mtd, -1, flctl->erase1_page_addr); | ||
561 | start_translation(flctl); | ||
562 | wait_completion(flctl); | ||
563 | break; | ||
564 | |||
565 | case NAND_CMD_SEQIN: | ||
566 | if (!flctl->page_size) { | ||
567 | /* output read command */ | ||
568 | if (column >= mtd->writesize) { | ||
569 | column -= mtd->writesize; | ||
570 | read_cmd = NAND_CMD_READOOB; | ||
571 | } else if (column < 256) { | ||
572 | read_cmd = NAND_CMD_READ0; | ||
573 | } else { | ||
574 | column -= 256; | ||
575 | read_cmd = NAND_CMD_READ1; | ||
576 | } | ||
577 | } | ||
578 | flctl->seqin_column = column; | ||
579 | flctl->seqin_page_addr = page_addr; | ||
580 | flctl->seqin_read_cmd = read_cmd; | ||
581 | break; | ||
582 | |||
583 | case NAND_CMD_PAGEPROG: | ||
584 | empty_fifo(flctl); | ||
585 | if (!flctl->page_size) { | ||
586 | set_cmd_regs(mtd, NAND_CMD_SEQIN, | ||
587 | flctl->seqin_read_cmd); | ||
588 | set_addr(mtd, -1, -1); | ||
589 | writel(0, FLDTCNTR(flctl)); /* set 0 size */ | ||
590 | start_translation(flctl); | ||
591 | wait_completion(flctl); | ||
592 | } | ||
593 | if (flctl->hwecc) { | ||
594 | /* write page with hwecc */ | ||
595 | if (flctl->seqin_column == mtd->writesize) | ||
596 | execmd_write_oob(mtd); | ||
597 | else if (!flctl->seqin_column) | ||
598 | execmd_write_page_sector(mtd); | ||
599 | else | ||
600 | printk(KERN_ERR "Invalid address !?\n"); | ||
601 | break; | ||
602 | } | ||
603 | set_cmd_regs(mtd, command, (command << 8) | NAND_CMD_SEQIN); | ||
604 | set_addr(mtd, flctl->seqin_column, flctl->seqin_page_addr); | ||
605 | writel(flctl->index, FLDTCNTR(flctl)); /* set write size */ | ||
606 | start_translation(flctl); | ||
607 | write_fiforeg(flctl, flctl->index, 0); | ||
608 | wait_completion(flctl); | ||
609 | break; | ||
610 | |||
611 | case NAND_CMD_STATUS: | ||
612 | set_cmd_regs(mtd, command, command); | ||
613 | set_addr(mtd, -1, -1); | ||
614 | |||
615 | flctl->read_bytes = 1; | ||
616 | writel(flctl->read_bytes, FLDTCNTR(flctl)); /* set read size */ | ||
617 | start_translation(flctl); | ||
618 | read_datareg(flctl, 0); /* read and end */ | ||
619 | break; | ||
620 | |||
621 | case NAND_CMD_RESET: | ||
622 | set_cmd_regs(mtd, command, command); | ||
623 | set_addr(mtd, -1, -1); | ||
624 | |||
625 | writel(0, FLDTCNTR(flctl)); /* set 0 size */ | ||
626 | start_translation(flctl); | ||
627 | wait_completion(flctl); | ||
628 | break; | ||
629 | |||
630 | default: | ||
631 | break; | ||
632 | } | ||
633 | return; | ||
634 | |||
635 | read_normal_exit: | ||
636 | writel(flctl->read_bytes, FLDTCNTR(flctl)); /* set read size */ | ||
637 | start_translation(flctl); | ||
638 | read_fiforeg(flctl, flctl->read_bytes, 0); | ||
639 | wait_completion(flctl); | ||
640 | return; | ||
641 | } | ||
642 | |||
643 | static void flctl_select_chip(struct mtd_info *mtd, int chipnr) | ||
644 | { | ||
645 | struct sh_flctl *flctl = mtd_to_flctl(mtd); | ||
646 | uint32_t flcmncr_val = readl(FLCMNCR(flctl)); | ||
647 | |||
648 | switch (chipnr) { | ||
649 | case -1: | ||
650 | flcmncr_val &= ~CE0_ENABLE; | ||
651 | writel(flcmncr_val, FLCMNCR(flctl)); | ||
652 | break; | ||
653 | case 0: | ||
654 | flcmncr_val |= CE0_ENABLE; | ||
655 | writel(flcmncr_val, FLCMNCR(flctl)); | ||
656 | break; | ||
657 | default: | ||
658 | BUG(); | ||
659 | } | ||
660 | } | ||
661 | |||
662 | static void flctl_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len) | ||
663 | { | ||
664 | struct sh_flctl *flctl = mtd_to_flctl(mtd); | ||
665 | int i, index = flctl->index; | ||
666 | |||
667 | for (i = 0; i < len; i++) | ||
668 | flctl->done_buff[index + i] = buf[i]; | ||
669 | flctl->index += len; | ||
670 | } | ||
671 | |||
672 | static uint8_t flctl_read_byte(struct mtd_info *mtd) | ||
673 | { | ||
674 | struct sh_flctl *flctl = mtd_to_flctl(mtd); | ||
675 | int index = flctl->index; | ||
676 | uint8_t data; | ||
677 | |||
678 | data = flctl->done_buff[index]; | ||
679 | flctl->index++; | ||
680 | return data; | ||
681 | } | ||
682 | |||
683 | static void flctl_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) | ||
684 | { | ||
685 | int i; | ||
686 | |||
687 | for (i = 0; i < len; i++) | ||
688 | buf[i] = flctl_read_byte(mtd); | ||
689 | } | ||
690 | |||
691 | static int flctl_verify_buf(struct mtd_info *mtd, const u_char *buf, int len) | ||
692 | { | ||
693 | int i; | ||
694 | |||
695 | for (i = 0; i < len; i++) | ||
696 | if (buf[i] != flctl_read_byte(mtd)) | ||
697 | return -EFAULT; | ||
698 | return 0; | ||
699 | } | ||
700 | |||
701 | static void flctl_register_init(struct sh_flctl *flctl, unsigned long val) | ||
702 | { | ||
703 | writel(val, FLCMNCR(flctl)); | ||
704 | } | ||
705 | |||
706 | static int flctl_chip_init_tail(struct mtd_info *mtd) | ||
707 | { | ||
708 | struct sh_flctl *flctl = mtd_to_flctl(mtd); | ||
709 | struct nand_chip *chip = &flctl->chip; | ||
710 | |||
711 | if (mtd->writesize == 512) { | ||
712 | flctl->page_size = 0; | ||
713 | if (chip->chipsize > (32 << 20)) { | ||
714 | /* big than 32MB */ | ||
715 | flctl->rw_ADRCNT = ADRCNT_4; | ||
716 | flctl->erase_ADRCNT = ADRCNT_3; | ||
717 | } else if (chip->chipsize > (2 << 16)) { | ||
718 | /* big than 128KB */ | ||
719 | flctl->rw_ADRCNT = ADRCNT_3; | ||
720 | flctl->erase_ADRCNT = ADRCNT_2; | ||
721 | } else { | ||
722 | flctl->rw_ADRCNT = ADRCNT_2; | ||
723 | flctl->erase_ADRCNT = ADRCNT_1; | ||
724 | } | ||
725 | } else { | ||
726 | flctl->page_size = 1; | ||
727 | if (chip->chipsize > (128 << 20)) { | ||
728 | /* big than 128MB */ | ||
729 | flctl->rw_ADRCNT = ADRCNT2_E; | ||
730 | flctl->erase_ADRCNT = ADRCNT_3; | ||
731 | } else if (chip->chipsize > (8 << 16)) { | ||
732 | /* big than 512KB */ | ||
733 | flctl->rw_ADRCNT = ADRCNT_4; | ||
734 | flctl->erase_ADRCNT = ADRCNT_2; | ||
735 | } else { | ||
736 | flctl->rw_ADRCNT = ADRCNT_3; | ||
737 | flctl->erase_ADRCNT = ADRCNT_1; | ||
738 | } | ||
739 | } | ||
740 | |||
741 | if (flctl->hwecc) { | ||
742 | if (mtd->writesize == 512) { | ||
743 | chip->ecc.layout = &flctl_4secc_oob_16; | ||
744 | chip->badblock_pattern = &flctl_4secc_smallpage; | ||
745 | } else { | ||
746 | chip->ecc.layout = &flctl_4secc_oob_64; | ||
747 | chip->badblock_pattern = &flctl_4secc_largepage; | ||
748 | } | ||
749 | |||
750 | chip->ecc.size = 512; | ||
751 | chip->ecc.bytes = 10; | ||
752 | chip->ecc.read_page = flctl_read_page_hwecc; | ||
753 | chip->ecc.write_page = flctl_write_page_hwecc; | ||
754 | chip->ecc.mode = NAND_ECC_HW; | ||
755 | |||
756 | /* 4 symbols ECC enabled */ | ||
757 | writel(readl(FLCMNCR(flctl)) | _4ECCEN | ECCPOS2 | ECCPOS_02, | ||
758 | FLCMNCR(flctl)); | ||
759 | } else { | ||
760 | chip->ecc.mode = NAND_ECC_SOFT; | ||
761 | } | ||
762 | |||
763 | return 0; | ||
764 | } | ||
765 | |||
766 | static int __init flctl_probe(struct platform_device *pdev) | ||
767 | { | ||
768 | struct resource *res; | ||
769 | struct sh_flctl *flctl; | ||
770 | struct mtd_info *flctl_mtd; | ||
771 | struct nand_chip *nand; | ||
772 | struct sh_flctl_platform_data *pdata; | ||
773 | int ret; | ||
774 | |||
775 | pdata = pdev->dev.platform_data; | ||
776 | if (pdata == NULL) { | ||
777 | printk(KERN_ERR "sh_flctl platform_data not found.\n"); | ||
778 | return -ENODEV; | ||
779 | } | ||
780 | |||
781 | flctl = kzalloc(sizeof(struct sh_flctl), GFP_KERNEL); | ||
782 | if (!flctl) { | ||
783 | printk(KERN_ERR "Unable to allocate NAND MTD dev structure.\n"); | ||
784 | return -ENOMEM; | ||
785 | } | ||
786 | |||
787 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
788 | if (!res) { | ||
789 | printk(KERN_ERR "%s: resource not found.\n", __func__); | ||
790 | ret = -ENODEV; | ||
791 | goto err; | ||
792 | } | ||
793 | |||
794 | flctl->reg = ioremap(res->start, res->end - res->start + 1); | ||
795 | if (flctl->reg == NULL) { | ||
796 | printk(KERN_ERR "%s: ioremap error.\n", __func__); | ||
797 | ret = -ENOMEM; | ||
798 | goto err; | ||
799 | } | ||
800 | |||
801 | platform_set_drvdata(pdev, flctl); | ||
802 | flctl_mtd = &flctl->mtd; | ||
803 | nand = &flctl->chip; | ||
804 | flctl_mtd->priv = nand; | ||
805 | flctl->hwecc = pdata->has_hwecc; | ||
806 | |||
807 | flctl_register_init(flctl, pdata->flcmncr_val); | ||
808 | |||
809 | nand->options = NAND_NO_AUTOINCR; | ||
810 | |||
811 | /* Set address of hardware control function */ | ||
812 | /* 20 us command delay time */ | ||
813 | nand->chip_delay = 20; | ||
814 | |||
815 | nand->read_byte = flctl_read_byte; | ||
816 | nand->write_buf = flctl_write_buf; | ||
817 | nand->read_buf = flctl_read_buf; | ||
818 | nand->verify_buf = flctl_verify_buf; | ||
819 | nand->select_chip = flctl_select_chip; | ||
820 | nand->cmdfunc = flctl_cmdfunc; | ||
821 | |||
822 | ret = nand_scan_ident(flctl_mtd, 1); | ||
823 | if (ret) | ||
824 | goto err; | ||
825 | |||
826 | ret = flctl_chip_init_tail(flctl_mtd); | ||
827 | if (ret) | ||
828 | goto err; | ||
829 | |||
830 | ret = nand_scan_tail(flctl_mtd); | ||
831 | if (ret) | ||
832 | goto err; | ||
833 | |||
834 | add_mtd_partitions(flctl_mtd, pdata->parts, pdata->nr_parts); | ||
835 | |||
836 | return 0; | ||
837 | |||
838 | err: | ||
839 | kfree(flctl); | ||
840 | return ret; | ||
841 | } | ||
842 | |||
843 | static int __exit flctl_remove(struct platform_device *pdev) | ||
844 | { | ||
845 | struct sh_flctl *flctl = platform_get_drvdata(pdev); | ||
846 | |||
847 | nand_release(&flctl->mtd); | ||
848 | kfree(flctl); | ||
849 | |||
850 | return 0; | ||
851 | } | ||
852 | |||
853 | static struct platform_driver flctl_driver = { | ||
854 | .probe = flctl_probe, | ||
855 | .remove = flctl_remove, | ||
856 | .driver = { | ||
857 | .name = "sh_flctl", | ||
858 | .owner = THIS_MODULE, | ||
859 | }, | ||
860 | }; | ||
861 | |||
862 | static int __init flctl_nand_init(void) | ||
863 | { | ||
864 | return platform_driver_register(&flctl_driver); | ||
865 | } | ||
866 | |||
867 | static void __exit flctl_nand_cleanup(void) | ||
868 | { | ||
869 | platform_driver_unregister(&flctl_driver); | ||
870 | } | ||
871 | |||
872 | module_init(flctl_nand_init); | ||
873 | module_exit(flctl_nand_cleanup); | ||
874 | |||
875 | MODULE_LICENSE("GPL"); | ||
876 | MODULE_AUTHOR("Yoshihiro Shimoda"); | ||
877 | MODULE_DESCRIPTION("SuperH FLCTL driver"); | ||
878 | MODULE_ALIAS("platform:sh_flctl"); | ||
diff --git a/drivers/mtd/nand/toto.c b/drivers/mtd/nand/toto.c deleted file mode 100644 index bbf492e6830d..000000000000 --- a/drivers/mtd/nand/toto.c +++ /dev/null | |||
@@ -1,206 +0,0 @@ | |||
1 | /* | ||
2 | * drivers/mtd/nand/toto.c | ||
3 | * | ||
4 | * Copyright (c) 2003 Texas Instruments | ||
5 | * | ||
6 | * Derived from drivers/mtd/autcpu12.c | ||
7 | * | ||
8 | * Copyright (c) 2002 Thomas Gleixner <tgxl@linutronix.de> | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License version 2 as | ||
12 | * published by the Free Software Foundation. | ||
13 | * | ||
14 | * Overview: | ||
15 | * This is a device driver for the NAND flash device found on the | ||
16 | * TI fido board. It supports 32MiB and 64MiB cards | ||
17 | */ | ||
18 | |||
19 | #include <linux/slab.h> | ||
20 | #include <linux/init.h> | ||
21 | #include <linux/module.h> | ||
22 | #include <linux/delay.h> | ||
23 | #include <linux/mtd/mtd.h> | ||
24 | #include <linux/mtd/nand.h> | ||
25 | #include <linux/mtd/partitions.h> | ||
26 | #include <asm/io.h> | ||
27 | #include <asm/arch/hardware.h> | ||
28 | #include <asm/sizes.h> | ||
29 | #include <asm/arch/toto.h> | ||
30 | #include <asm/arch-omap1510/hardware.h> | ||
31 | #include <asm/arch/gpio.h> | ||
32 | |||
33 | #define CONFIG_NAND_WORKAROUND 1 | ||
34 | |||
35 | /* | ||
36 | * MTD structure for TOTO board | ||
37 | */ | ||
38 | static struct mtd_info *toto_mtd = NULL; | ||
39 | |||
40 | static unsigned long toto_io_base = OMAP_FLASH_1_BASE; | ||
41 | |||
42 | /* | ||
43 | * Define partitions for flash devices | ||
44 | */ | ||
45 | |||
46 | static struct mtd_partition partition_info64M[] = { | ||
47 | { .name = "toto kernel partition 1", | ||
48 | .offset = 0, | ||
49 | .size = 2 * SZ_1M }, | ||
50 | { .name = "toto file sys partition 2", | ||
51 | .offset = 2 * SZ_1M, | ||
52 | .size = 14 * SZ_1M }, | ||
53 | { .name = "toto user partition 3", | ||
54 | .offset = 16 * SZ_1M, | ||
55 | .size = 16 * SZ_1M }, | ||
56 | { .name = "toto devboard extra partition 4", | ||
57 | .offset = 32 * SZ_1M, | ||
58 | .size = 32 * SZ_1M }, | ||
59 | }; | ||
60 | |||
61 | static struct mtd_partition partition_info32M[] = { | ||
62 | { .name = "toto kernel partition 1", | ||
63 | .offset = 0, | ||
64 | .size = 2 * SZ_1M }, | ||
65 | { .name = "toto file sys partition 2", | ||
66 | .offset = 2 * SZ_1M, | ||
67 | .size = 14 * SZ_1M }, | ||
68 | { .name = "toto user partition 3", | ||
69 | .offset = 16 * SZ_1M, | ||
70 | .size = 16 * SZ_1M }, | ||
71 | }; | ||
72 | |||
73 | #define NUM_PARTITIONS32M 3 | ||
74 | #define NUM_PARTITIONS64M 4 | ||
75 | |||
76 | /* | ||
77 | * hardware specific access to control-lines | ||
78 | * | ||
79 | * ctrl: | ||
80 | * NAND_NCE: bit 0 -> bit 14 (0x4000) | ||
81 | * NAND_CLE: bit 1 -> bit 12 (0x1000) | ||
82 | * NAND_ALE: bit 2 -> bit 1 (0x0002) | ||
83 | */ | ||
84 | static void toto_hwcontrol(struct mtd_info *mtd, int cmd, | ||
85 | unsigned int ctrl) | ||
86 | { | ||
87 | struct nand_chip *chip = mtd->priv; | ||
88 | |||
89 | if (ctrl & NAND_CTRL_CHANGE) { | ||
90 | unsigned long bits; | ||
91 | |||
92 | /* hopefully enough time for tc make proceding write to clear */ | ||
93 | udelay(1); | ||
94 | |||
95 | bits = (~ctrl & NAND_NCE) << 14; | ||
96 | bits |= (ctrl & NAND_CLE) << 12; | ||
97 | bits |= (ctrl & NAND_ALE) >> 1; | ||
98 | |||
99 | #warning Wild guess as gpiosetout() is nowhere defined in the kernel source - tglx | ||
100 | gpiosetout(0x5002, bits); | ||
101 | |||
102 | #ifdef CONFIG_NAND_WORKAROUND | ||
103 | /* "some" dev boards busted, blue wired to rts2 :( */ | ||
104 | rts2setout(2, (ctrl & NAND_CLE) << 1); | ||
105 | #endif | ||
106 | /* allow time to ensure gpio state to over take memory write */ | ||
107 | udelay(1); | ||
108 | } | ||
109 | |||
110 | if (cmd != NAND_CMD_NONE) | ||
111 | writeb(cmd, chip->IO_ADDR_W); | ||
112 | } | ||
113 | |||
114 | /* | ||
115 | * Main initialization routine | ||
116 | */ | ||
117 | static int __init toto_init(void) | ||
118 | { | ||
119 | struct nand_chip *this; | ||
120 | int err = 0; | ||
121 | |||
122 | /* Allocate memory for MTD device structure and private data */ | ||
123 | toto_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL); | ||
124 | if (!toto_mtd) { | ||
125 | printk(KERN_WARNING "Unable to allocate toto NAND MTD device structure.\n"); | ||
126 | err = -ENOMEM; | ||
127 | goto out; | ||
128 | } | ||
129 | |||
130 | /* Get pointer to private data */ | ||
131 | this = (struct nand_chip *)(&toto_mtd[1]); | ||
132 | |||
133 | /* Initialize structures */ | ||
134 | memset(toto_mtd, 0, sizeof(struct mtd_info)); | ||
135 | memset(this, 0, sizeof(struct nand_chip)); | ||
136 | |||
137 | /* Link the private data with the MTD structure */ | ||
138 | toto_mtd->priv = this; | ||
139 | toto_mtd->owner = THIS_MODULE; | ||
140 | |||
141 | /* Set address of NAND IO lines */ | ||
142 | this->IO_ADDR_R = toto_io_base; | ||
143 | this->IO_ADDR_W = toto_io_base; | ||
144 | this->cmd_ctrl = toto_hwcontrol; | ||
145 | this->dev_ready = NULL; | ||
146 | /* 25 us command delay time */ | ||
147 | this->chip_delay = 30; | ||
148 | this->ecc.mode = NAND_ECC_SOFT; | ||
149 | |||
150 | /* Scan to find existance of the device */ | ||
151 | if (nand_scan(toto_mtd, 1)) { | ||
152 | err = -ENXIO; | ||
153 | goto out_mtd; | ||
154 | } | ||
155 | |||
156 | /* Register the partitions */ | ||
157 | switch (toto_mtd->size) { | ||
158 | case SZ_64M: | ||
159 | add_mtd_partitions(toto_mtd, partition_info64M, NUM_PARTITIONS64M); | ||
160 | break; | ||
161 | case SZ_32M: | ||
162 | add_mtd_partitions(toto_mtd, partition_info32M, NUM_PARTITIONS32M); | ||
163 | break; | ||
164 | default:{ | ||
165 | printk(KERN_WARNING "Unsupported Nand device\n"); | ||
166 | err = -ENXIO; | ||
167 | goto out_buf; | ||
168 | } | ||
169 | } | ||
170 | |||
171 | gpioreserve(NAND_MASK); /* claim our gpios */ | ||
172 | archflashwp(0, 0); /* open up flash for writing */ | ||
173 | |||
174 | goto out; | ||
175 | |||
176 | out_mtd: | ||
177 | kfree(toto_mtd); | ||
178 | out: | ||
179 | return err; | ||
180 | } | ||
181 | |||
182 | module_init(toto_init); | ||
183 | |||
184 | /* | ||
185 | * Clean up routine | ||
186 | */ | ||
187 | static void __exit toto_cleanup(void) | ||
188 | { | ||
189 | /* Release resources, unregister device */ | ||
190 | nand_release(toto_mtd); | ||
191 | |||
192 | /* Free the MTD device structure */ | ||
193 | kfree(toto_mtd); | ||
194 | |||
195 | /* stop flash writes */ | ||
196 | archflashwp(0, 1); | ||
197 | |||
198 | /* release gpios to system */ | ||
199 | gpiorelease(NAND_MASK); | ||
200 | } | ||
201 | |||
202 | module_exit(toto_cleanup); | ||
203 | |||
204 | MODULE_LICENSE("GPL"); | ||
205 | MODULE_AUTHOR("Richard Woodruff <r-woodruff2@ti.com>"); | ||
206 | MODULE_DESCRIPTION("Glue layer for NAND flash on toto board"); | ||
diff --git a/drivers/mtd/ofpart.c b/drivers/mtd/ofpart.c index 4f80c2fd89af..9e45b3f39c0e 100644 --- a/drivers/mtd/ofpart.c +++ b/drivers/mtd/ofpart.c | |||
@@ -20,7 +20,6 @@ | |||
20 | #include <linux/mtd/partitions.h> | 20 | #include <linux/mtd/partitions.h> |
21 | 21 | ||
22 | int __devinit of_mtd_parse_partitions(struct device *dev, | 22 | int __devinit of_mtd_parse_partitions(struct device *dev, |
23 | struct mtd_info *mtd, | ||
24 | struct device_node *node, | 23 | struct device_node *node, |
25 | struct mtd_partition **pparts) | 24 | struct mtd_partition **pparts) |
26 | { | 25 | { |
diff --git a/drivers/mtd/onenand/Kconfig b/drivers/mtd/onenand/Kconfig index cb41cbca64f7..79fa79e8f8de 100644 --- a/drivers/mtd/onenand/Kconfig +++ b/drivers/mtd/onenand/Kconfig | |||
@@ -27,8 +27,16 @@ config MTD_ONENAND_GENERIC | |||
27 | help | 27 | help |
28 | Support for OneNAND flash via platform device driver. | 28 | Support for OneNAND flash via platform device driver. |
29 | 29 | ||
30 | config MTD_ONENAND_OMAP2 | ||
31 | tristate "OneNAND on OMAP2/OMAP3 support" | ||
32 | depends on MTD_ONENAND && (ARCH_OMAP2 || ARCH_OMAP3) | ||
33 | help | ||
34 | Support for a OneNAND flash device connected to an OMAP2/OMAP3 CPU | ||
35 | via the GPMC memory controller. | ||
36 | |||
30 | config MTD_ONENAND_OTP | 37 | config MTD_ONENAND_OTP |
31 | bool "OneNAND OTP Support" | 38 | bool "OneNAND OTP Support" |
39 | select HAVE_MTD_OTP | ||
32 | help | 40 | help |
33 | One Block of the NAND Flash Array memory is reserved as | 41 | One Block of the NAND Flash Array memory is reserved as |
34 | a One-Time Programmable Block memory area. | 42 | a One-Time Programmable Block memory area. |
diff --git a/drivers/mtd/onenand/Makefile b/drivers/mtd/onenand/Makefile index 4d2eacfd7e11..64b6cc61a520 100644 --- a/drivers/mtd/onenand/Makefile +++ b/drivers/mtd/onenand/Makefile | |||
@@ -7,6 +7,7 @@ obj-$(CONFIG_MTD_ONENAND) += onenand.o | |||
7 | 7 | ||
8 | # Board specific. | 8 | # Board specific. |
9 | obj-$(CONFIG_MTD_ONENAND_GENERIC) += generic.o | 9 | obj-$(CONFIG_MTD_ONENAND_GENERIC) += generic.o |
10 | obj-$(CONFIG_MTD_ONENAND_OMAP2) += omap2.o | ||
10 | 11 | ||
11 | # Simulator | 12 | # Simulator |
12 | obj-$(CONFIG_MTD_ONENAND_SIM) += onenand_sim.o | 13 | obj-$(CONFIG_MTD_ONENAND_SIM) += onenand_sim.o |
diff --git a/drivers/mtd/onenand/omap2.c b/drivers/mtd/onenand/omap2.c new file mode 100644 index 000000000000..8387e05daae2 --- /dev/null +++ b/drivers/mtd/onenand/omap2.c | |||
@@ -0,0 +1,802 @@ | |||
1 | /* | ||
2 | * linux/drivers/mtd/onenand/omap2.c | ||
3 | * | ||
4 | * OneNAND driver for OMAP2 / OMAP3 | ||
5 | * | ||
6 | * Copyright © 2005-2006 Nokia Corporation | ||
7 | * | ||
8 | * Author: Jarkko Lavinen <jarkko.lavinen@nokia.com> and Juha Yrjölä | ||
9 | * IRQ and DMA support written by Timo Teras | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify it | ||
12 | * under the terms of the GNU General Public License version 2 as published by | ||
13 | * the Free Software Foundation. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
17 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
18 | * more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License along with | ||
21 | * this program; see the file COPYING. If not, write to the Free Software | ||
22 | * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
23 | * | ||
24 | */ | ||
25 | |||
26 | #include <linux/device.h> | ||
27 | #include <linux/module.h> | ||
28 | #include <linux/init.h> | ||
29 | #include <linux/mtd/mtd.h> | ||
30 | #include <linux/mtd/onenand.h> | ||
31 | #include <linux/mtd/partitions.h> | ||
32 | #include <linux/platform_device.h> | ||
33 | #include <linux/interrupt.h> | ||
34 | #include <linux/delay.h> | ||
35 | |||
36 | #include <asm/io.h> | ||
37 | #include <asm/mach/flash.h> | ||
38 | #include <asm/arch/gpmc.h> | ||
39 | #include <asm/arch/onenand.h> | ||
40 | #include <asm/arch/gpio.h> | ||
41 | #include <asm/arch/gpmc.h> | ||
42 | #include <asm/arch/pm.h> | ||
43 | |||
44 | #include <linux/dma-mapping.h> | ||
45 | #include <asm/dma-mapping.h> | ||
46 | #include <asm/arch/dma.h> | ||
47 | |||
48 | #include <asm/arch/board.h> | ||
49 | |||
50 | #define DRIVER_NAME "omap2-onenand" | ||
51 | |||
52 | #define ONENAND_IO_SIZE SZ_128K | ||
53 | #define ONENAND_BUFRAM_SIZE (1024 * 5) | ||
54 | |||
55 | struct omap2_onenand { | ||
56 | struct platform_device *pdev; | ||
57 | int gpmc_cs; | ||
58 | unsigned long phys_base; | ||
59 | int gpio_irq; | ||
60 | struct mtd_info mtd; | ||
61 | struct mtd_partition *parts; | ||
62 | struct onenand_chip onenand; | ||
63 | struct completion irq_done; | ||
64 | struct completion dma_done; | ||
65 | int dma_channel; | ||
66 | int freq; | ||
67 | int (*setup)(void __iomem *base, int freq); | ||
68 | }; | ||
69 | |||
70 | static void omap2_onenand_dma_cb(int lch, u16 ch_status, void *data) | ||
71 | { | ||
72 | struct omap2_onenand *c = data; | ||
73 | |||
74 | complete(&c->dma_done); | ||
75 | } | ||
76 | |||
77 | static irqreturn_t omap2_onenand_interrupt(int irq, void *dev_id) | ||
78 | { | ||
79 | struct omap2_onenand *c = dev_id; | ||
80 | |||
81 | complete(&c->irq_done); | ||
82 | |||
83 | return IRQ_HANDLED; | ||
84 | } | ||
85 | |||
86 | static inline unsigned short read_reg(struct omap2_onenand *c, int reg) | ||
87 | { | ||
88 | return readw(c->onenand.base + reg); | ||
89 | } | ||
90 | |||
91 | static inline void write_reg(struct omap2_onenand *c, unsigned short value, | ||
92 | int reg) | ||
93 | { | ||
94 | writew(value, c->onenand.base + reg); | ||
95 | } | ||
96 | |||
97 | static void wait_err(char *msg, int state, unsigned int ctrl, unsigned int intr) | ||
98 | { | ||
99 | printk(KERN_ERR "onenand_wait: %s! state %d ctrl 0x%04x intr 0x%04x\n", | ||
100 | msg, state, ctrl, intr); | ||
101 | } | ||
102 | |||
103 | static void wait_warn(char *msg, int state, unsigned int ctrl, | ||
104 | unsigned int intr) | ||
105 | { | ||
106 | printk(KERN_WARNING "onenand_wait: %s! state %d ctrl 0x%04x " | ||
107 | "intr 0x%04x\n", msg, state, ctrl, intr); | ||
108 | } | ||
109 | |||
110 | static int omap2_onenand_wait(struct mtd_info *mtd, int state) | ||
111 | { | ||
112 | struct omap2_onenand *c = container_of(mtd, struct omap2_onenand, mtd); | ||
113 | unsigned int intr = 0; | ||
114 | unsigned int ctrl; | ||
115 | unsigned long timeout; | ||
116 | u32 syscfg; | ||
117 | |||
118 | if (state == FL_RESETING) { | ||
119 | int i; | ||
120 | |||
121 | for (i = 0; i < 20; i++) { | ||
122 | udelay(1); | ||
123 | intr = read_reg(c, ONENAND_REG_INTERRUPT); | ||
124 | if (intr & ONENAND_INT_MASTER) | ||
125 | break; | ||
126 | } | ||
127 | ctrl = read_reg(c, ONENAND_REG_CTRL_STATUS); | ||
128 | if (ctrl & ONENAND_CTRL_ERROR) { | ||
129 | wait_err("controller error", state, ctrl, intr); | ||
130 | return -EIO; | ||
131 | } | ||
132 | if (!(intr & ONENAND_INT_RESET)) { | ||
133 | wait_err("timeout", state, ctrl, intr); | ||
134 | return -EIO; | ||
135 | } | ||
136 | return 0; | ||
137 | } | ||
138 | |||
139 | if (state != FL_READING) { | ||
140 | int result; | ||
141 | |||
142 | /* Turn interrupts on */ | ||
143 | syscfg = read_reg(c, ONENAND_REG_SYS_CFG1); | ||
144 | if (!(syscfg & ONENAND_SYS_CFG1_IOBE)) { | ||
145 | syscfg |= ONENAND_SYS_CFG1_IOBE; | ||
146 | write_reg(c, syscfg, ONENAND_REG_SYS_CFG1); | ||
147 | if (cpu_is_omap34xx()) | ||
148 | /* Add a delay to let GPIO settle */ | ||
149 | syscfg = read_reg(c, ONENAND_REG_SYS_CFG1); | ||
150 | } | ||
151 | |||
152 | INIT_COMPLETION(c->irq_done); | ||
153 | if (c->gpio_irq) { | ||
154 | result = omap_get_gpio_datain(c->gpio_irq); | ||
155 | if (result == -1) { | ||
156 | ctrl = read_reg(c, ONENAND_REG_CTRL_STATUS); | ||
157 | intr = read_reg(c, ONENAND_REG_INTERRUPT); | ||
158 | wait_err("gpio error", state, ctrl, intr); | ||
159 | return -EIO; | ||
160 | } | ||
161 | } else | ||
162 | result = 0; | ||
163 | if (result == 0) { | ||
164 | int retry_cnt = 0; | ||
165 | retry: | ||
166 | result = wait_for_completion_timeout(&c->irq_done, | ||
167 | msecs_to_jiffies(20)); | ||
168 | if (result == 0) { | ||
169 | /* Timeout after 20ms */ | ||
170 | ctrl = read_reg(c, ONENAND_REG_CTRL_STATUS); | ||
171 | if (ctrl & ONENAND_CTRL_ONGO) { | ||
172 | /* | ||
173 | * The operation seems to be still going | ||
174 | * so give it some more time. | ||
175 | */ | ||
176 | retry_cnt += 1; | ||
177 | if (retry_cnt < 3) | ||
178 | goto retry; | ||
179 | intr = read_reg(c, | ||
180 | ONENAND_REG_INTERRUPT); | ||
181 | wait_err("timeout", state, ctrl, intr); | ||
182 | return -EIO; | ||
183 | } | ||
184 | intr = read_reg(c, ONENAND_REG_INTERRUPT); | ||
185 | if ((intr & ONENAND_INT_MASTER) == 0) | ||
186 | wait_warn("timeout", state, ctrl, intr); | ||
187 | } | ||
188 | } | ||
189 | } else { | ||
190 | int retry_cnt = 0; | ||
191 | |||
192 | /* Turn interrupts off */ | ||
193 | syscfg = read_reg(c, ONENAND_REG_SYS_CFG1); | ||
194 | syscfg &= ~ONENAND_SYS_CFG1_IOBE; | ||
195 | write_reg(c, syscfg, ONENAND_REG_SYS_CFG1); | ||
196 | |||
197 | timeout = jiffies + msecs_to_jiffies(20); | ||
198 | while (1) { | ||
199 | if (time_before(jiffies, timeout)) { | ||
200 | intr = read_reg(c, ONENAND_REG_INTERRUPT); | ||
201 | if (intr & ONENAND_INT_MASTER) | ||
202 | break; | ||
203 | } else { | ||
204 | /* Timeout after 20ms */ | ||
205 | ctrl = read_reg(c, ONENAND_REG_CTRL_STATUS); | ||
206 | if (ctrl & ONENAND_CTRL_ONGO) { | ||
207 | /* | ||
208 | * The operation seems to be still going | ||
209 | * so give it some more time. | ||
210 | */ | ||
211 | retry_cnt += 1; | ||
212 | if (retry_cnt < 3) { | ||
213 | timeout = jiffies + | ||
214 | msecs_to_jiffies(20); | ||
215 | continue; | ||
216 | } | ||
217 | } | ||
218 | break; | ||
219 | } | ||
220 | } | ||
221 | } | ||
222 | |||
223 | intr = read_reg(c, ONENAND_REG_INTERRUPT); | ||
224 | ctrl = read_reg(c, ONENAND_REG_CTRL_STATUS); | ||
225 | |||
226 | if (intr & ONENAND_INT_READ) { | ||
227 | int ecc = read_reg(c, ONENAND_REG_ECC_STATUS); | ||
228 | |||
229 | if (ecc) { | ||
230 | unsigned int addr1, addr8; | ||
231 | |||
232 | addr1 = read_reg(c, ONENAND_REG_START_ADDRESS1); | ||
233 | addr8 = read_reg(c, ONENAND_REG_START_ADDRESS8); | ||
234 | if (ecc & ONENAND_ECC_2BIT_ALL) { | ||
235 | printk(KERN_ERR "onenand_wait: ECC error = " | ||
236 | "0x%04x, addr1 %#x, addr8 %#x\n", | ||
237 | ecc, addr1, addr8); | ||
238 | mtd->ecc_stats.failed++; | ||
239 | return -EBADMSG; | ||
240 | } else if (ecc & ONENAND_ECC_1BIT_ALL) { | ||
241 | printk(KERN_NOTICE "onenand_wait: correctable " | ||
242 | "ECC error = 0x%04x, addr1 %#x, " | ||
243 | "addr8 %#x\n", ecc, addr1, addr8); | ||
244 | mtd->ecc_stats.corrected++; | ||
245 | } | ||
246 | } | ||
247 | } else if (state == FL_READING) { | ||
248 | wait_err("timeout", state, ctrl, intr); | ||
249 | return -EIO; | ||
250 | } | ||
251 | |||
252 | if (ctrl & ONENAND_CTRL_ERROR) { | ||
253 | wait_err("controller error", state, ctrl, intr); | ||
254 | if (ctrl & ONENAND_CTRL_LOCK) | ||
255 | printk(KERN_ERR "onenand_wait: " | ||
256 | "Device is write protected!!!\n"); | ||
257 | return -EIO; | ||
258 | } | ||
259 | |||
260 | if (ctrl & 0xFE9F) | ||
261 | wait_warn("unexpected controller status", state, ctrl, intr); | ||
262 | |||
263 | return 0; | ||
264 | } | ||
265 | |||
266 | static inline int omap2_onenand_bufferram_offset(struct mtd_info *mtd, int area) | ||
267 | { | ||
268 | struct onenand_chip *this = mtd->priv; | ||
269 | |||
270 | if (ONENAND_CURRENT_BUFFERRAM(this)) { | ||
271 | if (area == ONENAND_DATARAM) | ||
272 | return mtd->writesize; | ||
273 | if (area == ONENAND_SPARERAM) | ||
274 | return mtd->oobsize; | ||
275 | } | ||
276 | |||
277 | return 0; | ||
278 | } | ||
279 | |||
280 | #if defined(CONFIG_ARCH_OMAP3) || defined(MULTI_OMAP2) | ||
281 | |||
282 | static int omap3_onenand_read_bufferram(struct mtd_info *mtd, int area, | ||
283 | unsigned char *buffer, int offset, | ||
284 | size_t count) | ||
285 | { | ||
286 | struct omap2_onenand *c = container_of(mtd, struct omap2_onenand, mtd); | ||
287 | struct onenand_chip *this = mtd->priv; | ||
288 | dma_addr_t dma_src, dma_dst; | ||
289 | int bram_offset; | ||
290 | unsigned long timeout; | ||
291 | void *buf = (void *)buffer; | ||
292 | size_t xtra; | ||
293 | volatile unsigned *done; | ||
294 | |||
295 | bram_offset = omap2_onenand_bufferram_offset(mtd, area) + area + offset; | ||
296 | if (bram_offset & 3 || (size_t)buf & 3 || count < 384) | ||
297 | goto out_copy; | ||
298 | |||
299 | if (buf >= high_memory) { | ||
300 | struct page *p1; | ||
301 | |||
302 | if (((size_t)buf & PAGE_MASK) != | ||
303 | ((size_t)(buf + count - 1) & PAGE_MASK)) | ||
304 | goto out_copy; | ||
305 | p1 = vmalloc_to_page(buf); | ||
306 | if (!p1) | ||
307 | goto out_copy; | ||
308 | buf = page_address(p1) + ((size_t)buf & ~PAGE_MASK); | ||
309 | } | ||
310 | |||
311 | xtra = count & 3; | ||
312 | if (xtra) { | ||
313 | count -= xtra; | ||
314 | memcpy(buf + count, this->base + bram_offset + count, xtra); | ||
315 | } | ||
316 | |||
317 | dma_src = c->phys_base + bram_offset; | ||
318 | dma_dst = dma_map_single(&c->pdev->dev, buf, count, DMA_FROM_DEVICE); | ||
319 | if (dma_mapping_error(&c->pdev->dev, dma_dst)) { | ||
320 | dev_err(&c->pdev->dev, | ||
321 | "Couldn't DMA map a %d byte buffer\n", | ||
322 | count); | ||
323 | goto out_copy; | ||
324 | } | ||
325 | |||
326 | omap_set_dma_transfer_params(c->dma_channel, OMAP_DMA_DATA_TYPE_S32, | ||
327 | count >> 2, 1, 0, 0, 0); | ||
328 | omap_set_dma_src_params(c->dma_channel, 0, OMAP_DMA_AMODE_POST_INC, | ||
329 | dma_src, 0, 0); | ||
330 | omap_set_dma_dest_params(c->dma_channel, 0, OMAP_DMA_AMODE_POST_INC, | ||
331 | dma_dst, 0, 0); | ||
332 | |||
333 | INIT_COMPLETION(c->dma_done); | ||
334 | omap_start_dma(c->dma_channel); | ||
335 | |||
336 | timeout = jiffies + msecs_to_jiffies(20); | ||
337 | done = &c->dma_done.done; | ||
338 | while (time_before(jiffies, timeout)) | ||
339 | if (*done) | ||
340 | break; | ||
341 | |||
342 | dma_unmap_single(&c->pdev->dev, dma_dst, count, DMA_FROM_DEVICE); | ||
343 | |||
344 | if (!*done) { | ||
345 | dev_err(&c->pdev->dev, "timeout waiting for DMA\n"); | ||
346 | goto out_copy; | ||
347 | } | ||
348 | |||
349 | return 0; | ||
350 | |||
351 | out_copy: | ||
352 | memcpy(buf, this->base + bram_offset, count); | ||
353 | return 0; | ||
354 | } | ||
355 | |||
356 | static int omap3_onenand_write_bufferram(struct mtd_info *mtd, int area, | ||
357 | const unsigned char *buffer, | ||
358 | int offset, size_t count) | ||
359 | { | ||
360 | struct omap2_onenand *c = container_of(mtd, struct omap2_onenand, mtd); | ||
361 | struct onenand_chip *this = mtd->priv; | ||
362 | dma_addr_t dma_src, dma_dst; | ||
363 | int bram_offset; | ||
364 | unsigned long timeout; | ||
365 | void *buf = (void *)buffer; | ||
366 | volatile unsigned *done; | ||
367 | |||
368 | bram_offset = omap2_onenand_bufferram_offset(mtd, area) + area + offset; | ||
369 | if (bram_offset & 3 || (size_t)buf & 3 || count < 384) | ||
370 | goto out_copy; | ||
371 | |||
372 | /* panic_write() may be in an interrupt context */ | ||
373 | if (in_interrupt()) | ||
374 | goto out_copy; | ||
375 | |||
376 | if (buf >= high_memory) { | ||
377 | struct page *p1; | ||
378 | |||
379 | if (((size_t)buf & PAGE_MASK) != | ||
380 | ((size_t)(buf + count - 1) & PAGE_MASK)) | ||
381 | goto out_copy; | ||
382 | p1 = vmalloc_to_page(buf); | ||
383 | if (!p1) | ||
384 | goto out_copy; | ||
385 | buf = page_address(p1) + ((size_t)buf & ~PAGE_MASK); | ||
386 | } | ||
387 | |||
388 | dma_src = dma_map_single(&c->pdev->dev, buf, count, DMA_TO_DEVICE); | ||
389 | dma_dst = c->phys_base + bram_offset; | ||
390 | if (dma_mapping_error(&c->pdev->dev, dma_dst)) { | ||
391 | dev_err(&c->pdev->dev, | ||
392 | "Couldn't DMA map a %d byte buffer\n", | ||
393 | count); | ||
394 | return -1; | ||
395 | } | ||
396 | |||
397 | omap_set_dma_transfer_params(c->dma_channel, OMAP_DMA_DATA_TYPE_S32, | ||
398 | count >> 2, 1, 0, 0, 0); | ||
399 | omap_set_dma_src_params(c->dma_channel, 0, OMAP_DMA_AMODE_POST_INC, | ||
400 | dma_src, 0, 0); | ||
401 | omap_set_dma_dest_params(c->dma_channel, 0, OMAP_DMA_AMODE_POST_INC, | ||
402 | dma_dst, 0, 0); | ||
403 | |||
404 | INIT_COMPLETION(c->dma_done); | ||
405 | omap_start_dma(c->dma_channel); | ||
406 | |||
407 | timeout = jiffies + msecs_to_jiffies(20); | ||
408 | done = &c->dma_done.done; | ||
409 | while (time_before(jiffies, timeout)) | ||
410 | if (*done) | ||
411 | break; | ||
412 | |||
413 | dma_unmap_single(&c->pdev->dev, dma_dst, count, DMA_TO_DEVICE); | ||
414 | |||
415 | if (!*done) { | ||
416 | dev_err(&c->pdev->dev, "timeout waiting for DMA\n"); | ||
417 | goto out_copy; | ||
418 | } | ||
419 | |||
420 | return 0; | ||
421 | |||
422 | out_copy: | ||
423 | memcpy(this->base + bram_offset, buf, count); | ||
424 | return 0; | ||
425 | } | ||
426 | |||
427 | #else | ||
428 | |||
429 | int omap3_onenand_read_bufferram(struct mtd_info *mtd, int area, | ||
430 | unsigned char *buffer, int offset, | ||
431 | size_t count); | ||
432 | |||
433 | int omap3_onenand_write_bufferram(struct mtd_info *mtd, int area, | ||
434 | const unsigned char *buffer, | ||
435 | int offset, size_t count); | ||
436 | |||
437 | #endif | ||
438 | |||
439 | #if defined(CONFIG_ARCH_OMAP2) || defined(MULTI_OMAP2) | ||
440 | |||
441 | static int omap2_onenand_read_bufferram(struct mtd_info *mtd, int area, | ||
442 | unsigned char *buffer, int offset, | ||
443 | size_t count) | ||
444 | { | ||
445 | struct omap2_onenand *c = container_of(mtd, struct omap2_onenand, mtd); | ||
446 | struct onenand_chip *this = mtd->priv; | ||
447 | dma_addr_t dma_src, dma_dst; | ||
448 | int bram_offset; | ||
449 | |||
450 | bram_offset = omap2_onenand_bufferram_offset(mtd, area) + area + offset; | ||
451 | /* DMA is not used. Revisit PM requirements before enabling it. */ | ||
452 | if (1 || (c->dma_channel < 0) || | ||
453 | ((void *) buffer >= (void *) high_memory) || (bram_offset & 3) || | ||
454 | (((unsigned int) buffer) & 3) || (count < 1024) || (count & 3)) { | ||
455 | memcpy(buffer, (__force void *)(this->base + bram_offset), | ||
456 | count); | ||
457 | return 0; | ||
458 | } | ||
459 | |||
460 | dma_src = c->phys_base + bram_offset; | ||
461 | dma_dst = dma_map_single(&c->pdev->dev, buffer, count, | ||
462 | DMA_FROM_DEVICE); | ||
463 | if (dma_mapping_error(&c->pdev->dev, dma_dst)) { | ||
464 | dev_err(&c->pdev->dev, | ||
465 | "Couldn't DMA map a %d byte buffer\n", | ||
466 | count); | ||
467 | return -1; | ||
468 | } | ||
469 | |||
470 | omap_set_dma_transfer_params(c->dma_channel, OMAP_DMA_DATA_TYPE_S32, | ||
471 | count / 4, 1, 0, 0, 0); | ||
472 | omap_set_dma_src_params(c->dma_channel, 0, OMAP_DMA_AMODE_POST_INC, | ||
473 | dma_src, 0, 0); | ||
474 | omap_set_dma_dest_params(c->dma_channel, 0, OMAP_DMA_AMODE_POST_INC, | ||
475 | dma_dst, 0, 0); | ||
476 | |||
477 | INIT_COMPLETION(c->dma_done); | ||
478 | omap_start_dma(c->dma_channel); | ||
479 | wait_for_completion(&c->dma_done); | ||
480 | |||
481 | dma_unmap_single(&c->pdev->dev, dma_dst, count, DMA_FROM_DEVICE); | ||
482 | |||
483 | return 0; | ||
484 | } | ||
485 | |||
486 | static int omap2_onenand_write_bufferram(struct mtd_info *mtd, int area, | ||
487 | const unsigned char *buffer, | ||
488 | int offset, size_t count) | ||
489 | { | ||
490 | struct omap2_onenand *c = container_of(mtd, struct omap2_onenand, mtd); | ||
491 | struct onenand_chip *this = mtd->priv; | ||
492 | dma_addr_t dma_src, dma_dst; | ||
493 | int bram_offset; | ||
494 | |||
495 | bram_offset = omap2_onenand_bufferram_offset(mtd, area) + area + offset; | ||
496 | /* DMA is not used. Revisit PM requirements before enabling it. */ | ||
497 | if (1 || (c->dma_channel < 0) || | ||
498 | ((void *) buffer >= (void *) high_memory) || (bram_offset & 3) || | ||
499 | (((unsigned int) buffer) & 3) || (count < 1024) || (count & 3)) { | ||
500 | memcpy((__force void *)(this->base + bram_offset), buffer, | ||
501 | count); | ||
502 | return 0; | ||
503 | } | ||
504 | |||
505 | dma_src = dma_map_single(&c->pdev->dev, (void *) buffer, count, | ||
506 | DMA_TO_DEVICE); | ||
507 | dma_dst = c->phys_base + bram_offset; | ||
508 | if (dma_mapping_error(&c->pdev->dev, dma_dst)) { | ||
509 | dev_err(&c->pdev->dev, | ||
510 | "Couldn't DMA map a %d byte buffer\n", | ||
511 | count); | ||
512 | return -1; | ||
513 | } | ||
514 | |||
515 | omap_set_dma_transfer_params(c->dma_channel, OMAP_DMA_DATA_TYPE_S16, | ||
516 | count / 2, 1, 0, 0, 0); | ||
517 | omap_set_dma_src_params(c->dma_channel, 0, OMAP_DMA_AMODE_POST_INC, | ||
518 | dma_src, 0, 0); | ||
519 | omap_set_dma_dest_params(c->dma_channel, 0, OMAP_DMA_AMODE_POST_INC, | ||
520 | dma_dst, 0, 0); | ||
521 | |||
522 | INIT_COMPLETION(c->dma_done); | ||
523 | omap_start_dma(c->dma_channel); | ||
524 | wait_for_completion(&c->dma_done); | ||
525 | |||
526 | dma_unmap_single(&c->pdev->dev, dma_dst, count, DMA_TO_DEVICE); | ||
527 | |||
528 | return 0; | ||
529 | } | ||
530 | |||
531 | #else | ||
532 | |||
533 | int omap2_onenand_read_bufferram(struct mtd_info *mtd, int area, | ||
534 | unsigned char *buffer, int offset, | ||
535 | size_t count); | ||
536 | |||
537 | int omap2_onenand_write_bufferram(struct mtd_info *mtd, int area, | ||
538 | const unsigned char *buffer, | ||
539 | int offset, size_t count); | ||
540 | |||
541 | #endif | ||
542 | |||
543 | static struct platform_driver omap2_onenand_driver; | ||
544 | |||
545 | static int __adjust_timing(struct device *dev, void *data) | ||
546 | { | ||
547 | int ret = 0; | ||
548 | struct omap2_onenand *c; | ||
549 | |||
550 | c = dev_get_drvdata(dev); | ||
551 | |||
552 | BUG_ON(c->setup == NULL); | ||
553 | |||
554 | /* DMA is not in use so this is all that is needed */ | ||
555 | /* Revisit for OMAP3! */ | ||
556 | ret = c->setup(c->onenand.base, c->freq); | ||
557 | |||
558 | return ret; | ||
559 | } | ||
560 | |||
561 | int omap2_onenand_rephase(void) | ||
562 | { | ||
563 | return driver_for_each_device(&omap2_onenand_driver.driver, NULL, | ||
564 | NULL, __adjust_timing); | ||
565 | } | ||
566 | |||
567 | static void __devexit omap2_onenand_shutdown(struct platform_device *pdev) | ||
568 | { | ||
569 | struct omap2_onenand *c = dev_get_drvdata(&pdev->dev); | ||
570 | |||
571 | /* With certain content in the buffer RAM, the OMAP boot ROM code | ||
572 | * can recognize the flash chip incorrectly. Zero it out before | ||
573 | * soft reset. | ||
574 | */ | ||
575 | memset((__force void *)c->onenand.base, 0, ONENAND_BUFRAM_SIZE); | ||
576 | } | ||
577 | |||
578 | static int __devinit omap2_onenand_probe(struct platform_device *pdev) | ||
579 | { | ||
580 | struct omap_onenand_platform_data *pdata; | ||
581 | struct omap2_onenand *c; | ||
582 | int r; | ||
583 | |||
584 | pdata = pdev->dev.platform_data; | ||
585 | if (pdata == NULL) { | ||
586 | dev_err(&pdev->dev, "platform data missing\n"); | ||
587 | return -ENODEV; | ||
588 | } | ||
589 | |||
590 | c = kzalloc(sizeof(struct omap2_onenand), GFP_KERNEL); | ||
591 | if (!c) | ||
592 | return -ENOMEM; | ||
593 | |||
594 | init_completion(&c->irq_done); | ||
595 | init_completion(&c->dma_done); | ||
596 | c->gpmc_cs = pdata->cs; | ||
597 | c->gpio_irq = pdata->gpio_irq; | ||
598 | c->dma_channel = pdata->dma_channel; | ||
599 | if (c->dma_channel < 0) { | ||
600 | /* if -1, don't use DMA */ | ||
601 | c->gpio_irq = 0; | ||
602 | } | ||
603 | |||
604 | r = gpmc_cs_request(c->gpmc_cs, ONENAND_IO_SIZE, &c->phys_base); | ||
605 | if (r < 0) { | ||
606 | dev_err(&pdev->dev, "Cannot request GPMC CS\n"); | ||
607 | goto err_kfree; | ||
608 | } | ||
609 | |||
610 | if (request_mem_region(c->phys_base, ONENAND_IO_SIZE, | ||
611 | pdev->dev.driver->name) == NULL) { | ||
612 | dev_err(&pdev->dev, "Cannot reserve memory region at 0x%08lx, " | ||
613 | "size: 0x%x\n", c->phys_base, ONENAND_IO_SIZE); | ||
614 | r = -EBUSY; | ||
615 | goto err_free_cs; | ||
616 | } | ||
617 | c->onenand.base = ioremap(c->phys_base, ONENAND_IO_SIZE); | ||
618 | if (c->onenand.base == NULL) { | ||
619 | r = -ENOMEM; | ||
620 | goto err_release_mem_region; | ||
621 | } | ||
622 | |||
623 | if (pdata->onenand_setup != NULL) { | ||
624 | r = pdata->onenand_setup(c->onenand.base, c->freq); | ||
625 | if (r < 0) { | ||
626 | dev_err(&pdev->dev, "Onenand platform setup failed: " | ||
627 | "%d\n", r); | ||
628 | goto err_iounmap; | ||
629 | } | ||
630 | c->setup = pdata->onenand_setup; | ||
631 | } | ||
632 | |||
633 | if (c->gpio_irq) { | ||
634 | if ((r = omap_request_gpio(c->gpio_irq)) < 0) { | ||
635 | dev_err(&pdev->dev, "Failed to request GPIO%d for " | ||
636 | "OneNAND\n", c->gpio_irq); | ||
637 | goto err_iounmap; | ||
638 | } | ||
639 | omap_set_gpio_direction(c->gpio_irq, 1); | ||
640 | |||
641 | if ((r = request_irq(OMAP_GPIO_IRQ(c->gpio_irq), | ||
642 | omap2_onenand_interrupt, IRQF_TRIGGER_RISING, | ||
643 | pdev->dev.driver->name, c)) < 0) | ||
644 | goto err_release_gpio; | ||
645 | } | ||
646 | |||
647 | if (c->dma_channel >= 0) { | ||
648 | r = omap_request_dma(0, pdev->dev.driver->name, | ||
649 | omap2_onenand_dma_cb, (void *) c, | ||
650 | &c->dma_channel); | ||
651 | if (r == 0) { | ||
652 | omap_set_dma_write_mode(c->dma_channel, | ||
653 | OMAP_DMA_WRITE_NON_POSTED); | ||
654 | omap_set_dma_src_data_pack(c->dma_channel, 1); | ||
655 | omap_set_dma_src_burst_mode(c->dma_channel, | ||
656 | OMAP_DMA_DATA_BURST_8); | ||
657 | omap_set_dma_dest_data_pack(c->dma_channel, 1); | ||
658 | omap_set_dma_dest_burst_mode(c->dma_channel, | ||
659 | OMAP_DMA_DATA_BURST_8); | ||
660 | } else { | ||
661 | dev_info(&pdev->dev, | ||
662 | "failed to allocate DMA for OneNAND, " | ||
663 | "using PIO instead\n"); | ||
664 | c->dma_channel = -1; | ||
665 | } | ||
666 | } | ||
667 | |||
668 | dev_info(&pdev->dev, "initializing on CS%d, phys base 0x%08lx, virtual " | ||
669 | "base %p\n", c->gpmc_cs, c->phys_base, | ||
670 | c->onenand.base); | ||
671 | |||
672 | c->pdev = pdev; | ||
673 | c->mtd.name = pdev->dev.bus_id; | ||
674 | c->mtd.priv = &c->onenand; | ||
675 | c->mtd.owner = THIS_MODULE; | ||
676 | |||
677 | if (c->dma_channel >= 0) { | ||
678 | struct onenand_chip *this = &c->onenand; | ||
679 | |||
680 | this->wait = omap2_onenand_wait; | ||
681 | if (cpu_is_omap34xx()) { | ||
682 | this->read_bufferram = omap3_onenand_read_bufferram; | ||
683 | this->write_bufferram = omap3_onenand_write_bufferram; | ||
684 | } else { | ||
685 | this->read_bufferram = omap2_onenand_read_bufferram; | ||
686 | this->write_bufferram = omap2_onenand_write_bufferram; | ||
687 | } | ||
688 | } | ||
689 | |||
690 | if ((r = onenand_scan(&c->mtd, 1)) < 0) | ||
691 | goto err_release_dma; | ||
692 | |||
693 | switch ((c->onenand.version_id >> 4) & 0xf) { | ||
694 | case 0: | ||
695 | c->freq = 40; | ||
696 | break; | ||
697 | case 1: | ||
698 | c->freq = 54; | ||
699 | break; | ||
700 | case 2: | ||
701 | c->freq = 66; | ||
702 | break; | ||
703 | case 3: | ||
704 | c->freq = 83; | ||
705 | break; | ||
706 | } | ||
707 | |||
708 | #ifdef CONFIG_MTD_PARTITIONS | ||
709 | if (pdata->parts != NULL) | ||
710 | r = add_mtd_partitions(&c->mtd, pdata->parts, | ||
711 | pdata->nr_parts); | ||
712 | else | ||
713 | #endif | ||
714 | r = add_mtd_device(&c->mtd); | ||
715 | if (r < 0) | ||
716 | goto err_release_onenand; | ||
717 | |||
718 | platform_set_drvdata(pdev, c); | ||
719 | |||
720 | return 0; | ||
721 | |||
722 | err_release_onenand: | ||
723 | onenand_release(&c->mtd); | ||
724 | err_release_dma: | ||
725 | if (c->dma_channel != -1) | ||
726 | omap_free_dma(c->dma_channel); | ||
727 | if (c->gpio_irq) | ||
728 | free_irq(OMAP_GPIO_IRQ(c->gpio_irq), c); | ||
729 | err_release_gpio: | ||
730 | if (c->gpio_irq) | ||
731 | omap_free_gpio(c->gpio_irq); | ||
732 | err_iounmap: | ||
733 | iounmap(c->onenand.base); | ||
734 | err_release_mem_region: | ||
735 | release_mem_region(c->phys_base, ONENAND_IO_SIZE); | ||
736 | err_free_cs: | ||
737 | gpmc_cs_free(c->gpmc_cs); | ||
738 | err_kfree: | ||
739 | kfree(c); | ||
740 | |||
741 | return r; | ||
742 | } | ||
743 | |||
744 | static int __devexit omap2_onenand_remove(struct platform_device *pdev) | ||
745 | { | ||
746 | struct omap2_onenand *c = dev_get_drvdata(&pdev->dev); | ||
747 | |||
748 | BUG_ON(c == NULL); | ||
749 | |||
750 | #ifdef CONFIG_MTD_PARTITIONS | ||
751 | if (c->parts) | ||
752 | del_mtd_partitions(&c->mtd); | ||
753 | else | ||
754 | del_mtd_device(&c->mtd); | ||
755 | #else | ||
756 | del_mtd_device(&c->mtd); | ||
757 | #endif | ||
758 | |||
759 | onenand_release(&c->mtd); | ||
760 | if (c->dma_channel != -1) | ||
761 | omap_free_dma(c->dma_channel); | ||
762 | omap2_onenand_shutdown(pdev); | ||
763 | platform_set_drvdata(pdev, NULL); | ||
764 | if (c->gpio_irq) { | ||
765 | free_irq(OMAP_GPIO_IRQ(c->gpio_irq), c); | ||
766 | omap_free_gpio(c->gpio_irq); | ||
767 | } | ||
768 | iounmap(c->onenand.base); | ||
769 | release_mem_region(c->phys_base, ONENAND_IO_SIZE); | ||
770 | kfree(c); | ||
771 | |||
772 | return 0; | ||
773 | } | ||
774 | |||
775 | static struct platform_driver omap2_onenand_driver = { | ||
776 | .probe = omap2_onenand_probe, | ||
777 | .remove = omap2_onenand_remove, | ||
778 | .shutdown = omap2_onenand_shutdown, | ||
779 | .driver = { | ||
780 | .name = DRIVER_NAME, | ||
781 | .owner = THIS_MODULE, | ||
782 | }, | ||
783 | }; | ||
784 | |||
785 | static int __init omap2_onenand_init(void) | ||
786 | { | ||
787 | printk(KERN_INFO "OneNAND driver initializing\n"); | ||
788 | return platform_driver_register(&omap2_onenand_driver); | ||
789 | } | ||
790 | |||
791 | static void __exit omap2_onenand_exit(void) | ||
792 | { | ||
793 | platform_driver_unregister(&omap2_onenand_driver); | ||
794 | } | ||
795 | |||
796 | module_init(omap2_onenand_init); | ||
797 | module_exit(omap2_onenand_exit); | ||
798 | |||
799 | MODULE_ALIAS(DRIVER_NAME); | ||
800 | MODULE_LICENSE("GPL"); | ||
801 | MODULE_AUTHOR("Jarkko Lavinen <jarkko.lavinen@nokia.com>"); | ||
802 | MODULE_DESCRIPTION("Glue layer for OneNAND flash on OMAP2 / OMAP3"); | ||
diff --git a/drivers/mtd/onenand/onenand_base.c b/drivers/mtd/onenand/onenand_base.c index 926cf3a4135d..90ed319f26e6 100644 --- a/drivers/mtd/onenand/onenand_base.c +++ b/drivers/mtd/onenand/onenand_base.c | |||
@@ -1794,7 +1794,7 @@ static int onenand_erase(struct mtd_info *mtd, struct erase_info *instr) | |||
1794 | return -EINVAL; | 1794 | return -EINVAL; |
1795 | } | 1795 | } |
1796 | 1796 | ||
1797 | instr->fail_addr = 0xffffffff; | 1797 | instr->fail_addr = MTD_FAIL_ADDR_UNKNOWN; |
1798 | 1798 | ||
1799 | /* Grab the lock and see if the device is available */ | 1799 | /* Grab the lock and see if the device is available */ |
1800 | onenand_get_device(mtd, FL_ERASING); | 1800 | onenand_get_device(mtd, FL_ERASING); |
diff --git a/drivers/mtd/ssfdc.c b/drivers/mtd/ssfdc.c index a5f3d60047d4..33a5d6ed6f18 100644 --- a/drivers/mtd/ssfdc.c +++ b/drivers/mtd/ssfdc.c | |||
@@ -321,8 +321,7 @@ static void ssfdcr_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) | |||
321 | DEBUG(MTD_DEBUG_LEVEL1, | 321 | DEBUG(MTD_DEBUG_LEVEL1, |
322 | "SSFDC_RO: cis_block=%d,erase_size=%d,map_len=%d,n_zones=%d\n", | 322 | "SSFDC_RO: cis_block=%d,erase_size=%d,map_len=%d,n_zones=%d\n", |
323 | ssfdc->cis_block, ssfdc->erase_size, ssfdc->map_len, | 323 | ssfdc->cis_block, ssfdc->erase_size, ssfdc->map_len, |
324 | (ssfdc->map_len + MAX_PHYS_BLK_PER_ZONE - 1) / | 324 | DIV_ROUND_UP(ssfdc->map_len, MAX_PHYS_BLK_PER_ZONE)); |
325 | MAX_PHYS_BLK_PER_ZONE); | ||
326 | 325 | ||
327 | /* Set geometry */ | 326 | /* Set geometry */ |
328 | ssfdc->heads = 16; | 327 | ssfdc->heads = 16; |
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c index 03c759b4eeb5..b30a0b83d7f1 100644 --- a/drivers/mtd/ubi/cdev.c +++ b/drivers/mtd/ubi/cdev.c | |||
@@ -104,12 +104,9 @@ static int vol_cdev_open(struct inode *inode, struct file *file) | |||
104 | struct ubi_volume_desc *desc; | 104 | struct ubi_volume_desc *desc; |
105 | int vol_id = iminor(inode) - 1, mode, ubi_num; | 105 | int vol_id = iminor(inode) - 1, mode, ubi_num; |
106 | 106 | ||
107 | lock_kernel(); | ||
108 | ubi_num = ubi_major2num(imajor(inode)); | 107 | ubi_num = ubi_major2num(imajor(inode)); |
109 | if (ubi_num < 0) { | 108 | if (ubi_num < 0) |
110 | unlock_kernel(); | ||
111 | return ubi_num; | 109 | return ubi_num; |
112 | } | ||
113 | 110 | ||
114 | if (file->f_mode & FMODE_WRITE) | 111 | if (file->f_mode & FMODE_WRITE) |
115 | mode = UBI_READWRITE; | 112 | mode = UBI_READWRITE; |
@@ -119,7 +116,6 @@ static int vol_cdev_open(struct inode *inode, struct file *file) | |||
119 | dbg_gen("open volume %d, mode %d", vol_id, mode); | 116 | dbg_gen("open volume %d, mode %d", vol_id, mode); |
120 | 117 | ||
121 | desc = ubi_open_volume(ubi_num, vol_id, mode); | 118 | desc = ubi_open_volume(ubi_num, vol_id, mode); |
122 | unlock_kernel(); | ||
123 | if (IS_ERR(desc)) | 119 | if (IS_ERR(desc)) |
124 | return PTR_ERR(desc); | 120 | return PTR_ERR(desc); |
125 | 121 | ||
diff --git a/drivers/mtd/ubi/scan.c b/drivers/mtd/ubi/scan.c index 967bb4406df9..4f2daa5bbecf 100644 --- a/drivers/mtd/ubi/scan.c +++ b/drivers/mtd/ubi/scan.c | |||
@@ -387,7 +387,7 @@ int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
387 | pnum, vol_id, lnum, ec, sqnum, bitflips); | 387 | pnum, vol_id, lnum, ec, sqnum, bitflips); |
388 | 388 | ||
389 | sv = add_volume(si, vol_id, pnum, vid_hdr); | 389 | sv = add_volume(si, vol_id, pnum, vid_hdr); |
390 | if (IS_ERR(sv) < 0) | 390 | if (IS_ERR(sv)) |
391 | return PTR_ERR(sv); | 391 | return PTR_ERR(sv); |
392 | 392 | ||
393 | if (si->max_sqnum < sqnum) | 393 | if (si->max_sqnum < sqnum) |
diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c index 217d0e111b2a..333c8941552f 100644 --- a/drivers/mtd/ubi/vtbl.c +++ b/drivers/mtd/ubi/vtbl.c | |||
@@ -244,8 +244,8 @@ static int vtbl_check(const struct ubi_device *ubi, | |||
244 | } | 244 | } |
245 | 245 | ||
246 | if (reserved_pebs > ubi->good_peb_count) { | 246 | if (reserved_pebs > ubi->good_peb_count) { |
247 | dbg_err("too large reserved_pebs, good PEBs %d", | 247 | dbg_err("too large reserved_pebs %d, good PEBs %d", |
248 | ubi->good_peb_count); | 248 | reserved_pebs, ubi->good_peb_count); |
249 | err = 9; | 249 | err = 9; |
250 | goto bad; | 250 | goto bad; |
251 | } | 251 | } |
diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c index fc5f2dbf5323..8b51e10b7783 100644 --- a/drivers/pci/intel-iommu.c +++ b/drivers/pci/intel-iommu.c | |||
@@ -563,7 +563,7 @@ static int __iommu_flush_context(struct intel_iommu *iommu, | |||
563 | 563 | ||
564 | spin_unlock_irqrestore(&iommu->register_lock, flag); | 564 | spin_unlock_irqrestore(&iommu->register_lock, flag); |
565 | 565 | ||
566 | /* flush context entry will implictly flush write buffer */ | 566 | /* flush context entry will implicitly flush write buffer */ |
567 | return 0; | 567 | return 0; |
568 | } | 568 | } |
569 | 569 | ||
@@ -656,7 +656,7 @@ static int __iommu_flush_iotlb(struct intel_iommu *iommu, u16 did, | |||
656 | if (DMA_TLB_IAIG(val) != DMA_TLB_IIRG(type)) | 656 | if (DMA_TLB_IAIG(val) != DMA_TLB_IIRG(type)) |
657 | pr_debug("IOMMU: tlb flush request %Lx, actual %Lx\n", | 657 | pr_debug("IOMMU: tlb flush request %Lx, actual %Lx\n", |
658 | DMA_TLB_IIRG(type), DMA_TLB_IAIG(val)); | 658 | DMA_TLB_IIRG(type), DMA_TLB_IAIG(val)); |
659 | /* flush context entry will implictly flush write buffer */ | 659 | /* flush iotlb entry will implicitly flush write buffer */ |
660 | return 0; | 660 | return 0; |
661 | } | 661 | } |
662 | 662 | ||
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index c9884bba22de..dbe9f39f4436 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c | |||
@@ -1358,11 +1358,10 @@ int pci_request_region(struct pci_dev *pdev, int bar, const char *res_name) | |||
1358 | return 0; | 1358 | return 0; |
1359 | 1359 | ||
1360 | err_out: | 1360 | err_out: |
1361 | dev_warn(&pdev->dev, "BAR %d: can't reserve %s region [%#llx-%#llx]\n", | 1361 | dev_warn(&pdev->dev, "BAR %d: can't reserve %s region %pR\n", |
1362 | bar, | 1362 | bar, |
1363 | pci_resource_flags(pdev, bar) & IORESOURCE_IO ? "I/O" : "mem", | 1363 | pci_resource_flags(pdev, bar) & IORESOURCE_IO ? "I/O" : "mem", |
1364 | (unsigned long long)pci_resource_start(pdev, bar), | 1364 | &pdev->resource[bar]); |
1365 | (unsigned long long)pci_resource_end(pdev, bar)); | ||
1366 | return -EBUSY; | 1365 | return -EBUSY; |
1367 | } | 1366 | } |
1368 | 1367 | ||
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index dd9161a054e1..d3db8b249729 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c | |||
@@ -304,9 +304,8 @@ static int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, | |||
304 | } else { | 304 | } else { |
305 | res->start = l64; | 305 | res->start = l64; |
306 | res->end = l64 + sz64; | 306 | res->end = l64 + sz64; |
307 | printk(KERN_DEBUG "PCI: %s reg %x 64bit mmio: [%llx, %llx]\n", | 307 | printk(KERN_DEBUG "PCI: %s reg %x 64bit mmio: %pR\n", |
308 | pci_name(dev), pos, (unsigned long long)res->start, | 308 | pci_name(dev), pos, res); |
309 | (unsigned long long)res->end); | ||
310 | } | 309 | } |
311 | } else { | 310 | } else { |
312 | sz = pci_size(l, sz, mask); | 311 | sz = pci_size(l, sz, mask); |
@@ -316,9 +315,10 @@ static int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, | |||
316 | 315 | ||
317 | res->start = l; | 316 | res->start = l; |
318 | res->end = l + sz; | 317 | res->end = l + sz; |
319 | printk(KERN_DEBUG "PCI: %s reg %x %s: [%llx, %llx]\n", pci_name(dev), | 318 | printk(KERN_DEBUG "PCI: %s reg %x %s: %pR\n", |
320 | pos, (res->flags & IORESOURCE_IO) ? "io port":"32bit mmio", | 319 | pci_name(dev), pos, |
321 | (unsigned long long)res->start, (unsigned long long)res->end); | 320 | (res->flags & IORESOURCE_IO) ? "io port":"32bit mmio", |
321 | res); | ||
322 | } | 322 | } |
323 | 323 | ||
324 | out: | 324 | out: |
@@ -389,9 +389,8 @@ void __devinit pci_read_bridge_bases(struct pci_bus *child) | |||
389 | res->start = base; | 389 | res->start = base; |
390 | if (!res->end) | 390 | if (!res->end) |
391 | res->end = limit + 0xfff; | 391 | res->end = limit + 0xfff; |
392 | printk(KERN_DEBUG "PCI: bridge %s io port: [%llx, %llx]\n", | 392 | printk(KERN_DEBUG "PCI: bridge %s io port: %pR\n", |
393 | pci_name(dev), (unsigned long long) res->start, | 393 | pci_name(dev), res); |
394 | (unsigned long long) res->end); | ||
395 | } | 394 | } |
396 | 395 | ||
397 | res = child->resource[1]; | 396 | res = child->resource[1]; |
@@ -403,9 +402,8 @@ void __devinit pci_read_bridge_bases(struct pci_bus *child) | |||
403 | res->flags = (mem_base_lo & PCI_MEMORY_RANGE_TYPE_MASK) | IORESOURCE_MEM; | 402 | res->flags = (mem_base_lo & PCI_MEMORY_RANGE_TYPE_MASK) | IORESOURCE_MEM; |
404 | res->start = base; | 403 | res->start = base; |
405 | res->end = limit + 0xfffff; | 404 | res->end = limit + 0xfffff; |
406 | printk(KERN_DEBUG "PCI: bridge %s 32bit mmio: [%llx, %llx]\n", | 405 | printk(KERN_DEBUG "PCI: bridge %s 32bit mmio: %pR\n", |
407 | pci_name(dev), (unsigned long long) res->start, | 406 | pci_name(dev), res); |
408 | (unsigned long long) res->end); | ||
409 | } | 407 | } |
410 | 408 | ||
411 | res = child->resource[2]; | 409 | res = child->resource[2]; |
@@ -441,9 +439,9 @@ void __devinit pci_read_bridge_bases(struct pci_bus *child) | |||
441 | res->flags = (mem_base_lo & PCI_MEMORY_RANGE_TYPE_MASK) | IORESOURCE_MEM | IORESOURCE_PREFETCH; | 439 | res->flags = (mem_base_lo & PCI_MEMORY_RANGE_TYPE_MASK) | IORESOURCE_MEM | IORESOURCE_PREFETCH; |
442 | res->start = base; | 440 | res->start = base; |
443 | res->end = limit + 0xfffff; | 441 | res->end = limit + 0xfffff; |
444 | printk(KERN_DEBUG "PCI: bridge %s %sbit mmio pref: [%llx, %llx]\n", | 442 | printk(KERN_DEBUG "PCI: bridge %s %sbit mmio pref: %pR\n", |
445 | pci_name(dev), (res->flags & PCI_PREF_RANGE_TYPE_64) ? "64" : "32", | 443 | pci_name(dev), |
446 | (unsigned long long) res->start, (unsigned long long) res->end); | 444 | (res->flags & PCI_PREF_RANGE_TYPE_64) ? "64":"32", res); |
447 | } | 445 | } |
448 | } | 446 | } |
449 | 447 | ||
diff --git a/drivers/pci/rom.c b/drivers/pci/rom.c index bd5c0e031398..1f5f6143f35c 100644 --- a/drivers/pci/rom.c +++ b/drivers/pci/rom.c | |||
@@ -21,7 +21,7 @@ | |||
21 | * between the ROM and other resources, so enabling it may disable access | 21 | * between the ROM and other resources, so enabling it may disable access |
22 | * to MMIO registers or other card memory. | 22 | * to MMIO registers or other card memory. |
23 | */ | 23 | */ |
24 | static int pci_enable_rom(struct pci_dev *pdev) | 24 | int pci_enable_rom(struct pci_dev *pdev) |
25 | { | 25 | { |
26 | struct resource *res = pdev->resource + PCI_ROM_RESOURCE; | 26 | struct resource *res = pdev->resource + PCI_ROM_RESOURCE; |
27 | struct pci_bus_region region; | 27 | struct pci_bus_region region; |
@@ -45,7 +45,7 @@ static int pci_enable_rom(struct pci_dev *pdev) | |||
45 | * Disable ROM decoding on a PCI device by turning off the last bit in the | 45 | * Disable ROM decoding on a PCI device by turning off the last bit in the |
46 | * ROM BAR. | 46 | * ROM BAR. |
47 | */ | 47 | */ |
48 | static void pci_disable_rom(struct pci_dev *pdev) | 48 | void pci_disable_rom(struct pci_dev *pdev) |
49 | { | 49 | { |
50 | u32 rom_addr; | 50 | u32 rom_addr; |
51 | pci_read_config_dword(pdev, pdev->rom_base_reg, &rom_addr); | 51 | pci_read_config_dword(pdev, pdev->rom_base_reg, &rom_addr); |
@@ -260,3 +260,5 @@ void pci_cleanup_rom(struct pci_dev *pdev) | |||
260 | 260 | ||
261 | EXPORT_SYMBOL(pci_map_rom); | 261 | EXPORT_SYMBOL(pci_map_rom); |
262 | EXPORT_SYMBOL(pci_unmap_rom); | 262 | EXPORT_SYMBOL(pci_unmap_rom); |
263 | EXPORT_SYMBOL_GPL(pci_enable_rom); | ||
264 | EXPORT_SYMBOL_GPL(pci_disable_rom); | ||
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index d5e2106760f8..471a429d7a20 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c | |||
@@ -356,10 +356,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, unsigned long | |||
356 | order = __ffs(align) - 20; | 356 | order = __ffs(align) - 20; |
357 | if (order > 11) { | 357 | if (order > 11) { |
358 | dev_warn(&dev->dev, "BAR %d bad alignment %llx: " | 358 | dev_warn(&dev->dev, "BAR %d bad alignment %llx: " |
359 | "%#016llx-%#016llx\n", i, | 359 | "%pR\n", i, (unsigned long long)align, r); |
360 | (unsigned long long)align, | ||
361 | (unsigned long long)r->start, | ||
362 | (unsigned long long)r->end); | ||
363 | r->flags = 0; | 360 | r->flags = 0; |
364 | continue; | 361 | continue; |
365 | } | 362 | } |
@@ -539,11 +536,9 @@ static void pci_bus_dump_res(struct pci_bus *bus) | |||
539 | if (!res) | 536 | if (!res) |
540 | continue; | 537 | continue; |
541 | 538 | ||
542 | printk(KERN_INFO "bus: %02x index %x %s: [%llx, %llx]\n", | 539 | printk(KERN_INFO "bus: %02x index %x %s: %pR\n", |
543 | bus->number, i, | 540 | bus->number, i, |
544 | (res->flags & IORESOURCE_IO) ? "io port" : "mmio", | 541 | (res->flags & IORESOURCE_IO) ? "io port" : "mmio", res); |
545 | (unsigned long long) res->start, | ||
546 | (unsigned long long) res->end); | ||
547 | } | 542 | } |
548 | } | 543 | } |
549 | 544 | ||
diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c index 1a5fc83c71b3..d4b5c690eaa7 100644 --- a/drivers/pci/setup-res.c +++ b/drivers/pci/setup-res.c | |||
@@ -49,10 +49,8 @@ void pci_update_resource(struct pci_dev *dev, struct resource *res, int resno) | |||
49 | 49 | ||
50 | pcibios_resource_to_bus(dev, ®ion, res); | 50 | pcibios_resource_to_bus(dev, ®ion, res); |
51 | 51 | ||
52 | dev_dbg(&dev->dev, "BAR %d: got res [%#llx-%#llx] bus [%#llx-%#llx] " | 52 | dev_dbg(&dev->dev, "BAR %d: got res %pR bus [%#llx-%#llx] " |
53 | "flags %#lx\n", resno, | 53 | "flags %#lx\n", resno, res, |
54 | (unsigned long long)res->start, | ||
55 | (unsigned long long)res->end, | ||
56 | (unsigned long long)region.start, | 54 | (unsigned long long)region.start, |
57 | (unsigned long long)region.end, | 55 | (unsigned long long)region.end, |
58 | (unsigned long)res->flags); | 56 | (unsigned long)res->flags); |
@@ -114,13 +112,11 @@ int pci_claim_resource(struct pci_dev *dev, int resource) | |||
114 | err = insert_resource(root, res); | 112 | err = insert_resource(root, res); |
115 | 113 | ||
116 | if (err) { | 114 | if (err) { |
117 | dev_err(&dev->dev, "BAR %d: %s of %s [%#llx-%#llx]\n", | 115 | dev_err(&dev->dev, "BAR %d: %s of %s %pR\n", |
118 | resource, | 116 | resource, |
119 | root ? "address space collision on" : | 117 | root ? "address space collision on" : |
120 | "no parent found for", | 118 | "no parent found for", |
121 | dtype, | 119 | dtype, res); |
122 | (unsigned long long)res->start, | ||
123 | (unsigned long long)res->end); | ||
124 | } | 120 | } |
125 | 121 | ||
126 | return err; | 122 | return err; |
@@ -139,9 +135,8 @@ int pci_assign_resource(struct pci_dev *dev, int resno) | |||
139 | align = resource_alignment(res); | 135 | align = resource_alignment(res); |
140 | if (!align) { | 136 | if (!align) { |
141 | dev_err(&dev->dev, "BAR %d: can't allocate resource (bogus " | 137 | dev_err(&dev->dev, "BAR %d: can't allocate resource (bogus " |
142 | "alignment) [%#llx-%#llx] flags %#lx\n", | 138 | "alignment) %pR flags %#lx\n", |
143 | resno, (unsigned long long)res->start, | 139 | resno, res, res->flags); |
144 | (unsigned long long)res->end, res->flags); | ||
145 | return -EINVAL; | 140 | return -EINVAL; |
146 | } | 141 | } |
147 | 142 | ||
@@ -162,11 +157,8 @@ int pci_assign_resource(struct pci_dev *dev, int resno) | |||
162 | } | 157 | } |
163 | 158 | ||
164 | if (ret) { | 159 | if (ret) { |
165 | dev_err(&dev->dev, "BAR %d: can't allocate %s resource " | 160 | dev_err(&dev->dev, "BAR %d: can't allocate %s resource %pR\n", |
166 | "[%#llx-%#llx]\n", resno, | 161 | resno, res->flags & IORESOURCE_IO ? "I/O" : "mem", res); |
167 | res->flags & IORESOURCE_IO ? "I/O" : "mem", | ||
168 | (unsigned long long)res->start, | ||
169 | (unsigned long long)res->end); | ||
170 | } else { | 162 | } else { |
171 | res->flags &= ~IORESOURCE_STARTALIGN; | 163 | res->flags &= ~IORESOURCE_STARTALIGN; |
172 | if (resno < PCI_BRIDGE_RESOURCES) | 164 | if (resno < PCI_BRIDGE_RESOURCES) |
@@ -202,11 +194,8 @@ int pci_assign_resource_fixed(struct pci_dev *dev, int resno) | |||
202 | } | 194 | } |
203 | 195 | ||
204 | if (ret) { | 196 | if (ret) { |
205 | dev_err(&dev->dev, "BAR %d: can't allocate %s resource " | 197 | dev_err(&dev->dev, "BAR %d: can't allocate %s resource %pR\n", |
206 | "[%#llx-%#llx\n]", resno, | 198 | resno, res->flags & IORESOURCE_IO ? "I/O" : "mem", res); |
207 | res->flags & IORESOURCE_IO ? "I/O" : "mem", | ||
208 | (unsigned long long)res->start, | ||
209 | (unsigned long long)res->end); | ||
210 | } else if (resno < PCI_BRIDGE_RESOURCES) { | 199 | } else if (resno < PCI_BRIDGE_RESOURCES) { |
211 | pci_update_resource(dev, res, resno); | 200 | pci_update_resource(dev, res, resno); |
212 | } | 201 | } |
@@ -237,9 +226,8 @@ void pdev_sort_resources(struct pci_dev *dev, struct resource_list *head) | |||
237 | r_align = resource_alignment(r); | 226 | r_align = resource_alignment(r); |
238 | if (!r_align) { | 227 | if (!r_align) { |
239 | dev_warn(&dev->dev, "BAR %d: bogus alignment " | 228 | dev_warn(&dev->dev, "BAR %d: bogus alignment " |
240 | "[%#llx-%#llx] flags %#lx\n", | 229 | "%pR flags %#lx\n", |
241 | i, (unsigned long long)r->start, | 230 | i, r, r->flags); |
242 | (unsigned long long)r->end, r->flags); | ||
243 | continue; | 231 | continue; |
244 | } | 232 | } |
245 | for (list = head; ; list = list->next) { | 233 | for (list = head; ; list = list->next) { |
@@ -287,9 +275,7 @@ int pci_enable_resources(struct pci_dev *dev, int mask) | |||
287 | 275 | ||
288 | if (!r->parent) { | 276 | if (!r->parent) { |
289 | dev_err(&dev->dev, "device not available because of " | 277 | dev_err(&dev->dev, "device not available because of " |
290 | "BAR %d [%#llx-%#llx] collisions\n", i, | 278 | "BAR %d %pR collisions\n", i, r); |
291 | (unsigned long long) r->start, | ||
292 | (unsigned long long) r->end); | ||
293 | return -EINVAL; | 279 | return -EINVAL; |
294 | } | 280 | } |
295 | 281 | ||
diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c index fe2aeb11939b..23ae8460f5c1 100644 --- a/drivers/power/power_supply_sysfs.c +++ b/drivers/power/power_supply_sysfs.c | |||
@@ -30,7 +30,7 @@ | |||
30 | 30 | ||
31 | #define POWER_SUPPLY_ATTR(_name) \ | 31 | #define POWER_SUPPLY_ATTR(_name) \ |
32 | { \ | 32 | { \ |
33 | .attr = { .name = #_name, .mode = 0444, .owner = THIS_MODULE }, \ | 33 | .attr = { .name = #_name, .mode = 0444 }, \ |
34 | .show = power_supply_show_property, \ | 34 | .show = power_supply_show_property, \ |
35 | .store = NULL, \ | 35 | .store = NULL, \ |
36 | } | 36 | } |
diff --git a/drivers/ps3/ps3av.c b/drivers/ps3/ps3av.c index 6f2f90ebb020..06848b254d57 100644 --- a/drivers/ps3/ps3av.c +++ b/drivers/ps3/ps3av.c | |||
@@ -915,6 +915,22 @@ int ps3av_video_mute(int mute) | |||
915 | 915 | ||
916 | EXPORT_SYMBOL_GPL(ps3av_video_mute); | 916 | EXPORT_SYMBOL_GPL(ps3av_video_mute); |
917 | 917 | ||
918 | /* mute analog output only */ | ||
919 | int ps3av_audio_mute_analog(int mute) | ||
920 | { | ||
921 | int i, res; | ||
922 | |||
923 | for (i = 0; i < ps3av->av_hw_conf.num_of_avmulti; i++) { | ||
924 | res = ps3av_cmd_av_audio_mute(1, | ||
925 | &ps3av->av_port[i + ps3av->av_hw_conf.num_of_hdmi], | ||
926 | mute); | ||
927 | if (res < 0) | ||
928 | return -1; | ||
929 | } | ||
930 | return 0; | ||
931 | } | ||
932 | EXPORT_SYMBOL_GPL(ps3av_audio_mute_analog); | ||
933 | |||
918 | int ps3av_audio_mute(int mute) | 934 | int ps3av_audio_mute(int mute) |
919 | { | 935 | { |
920 | return ps3av_set_audio_mute(mute ? PS3AV_CMD_MUTE_ON | 936 | return ps3av_set_audio_mute(mute ? PS3AV_CMD_MUTE_ON |
diff --git a/drivers/ps3/ps3av_cmd.c b/drivers/ps3/ps3av_cmd.c index 7f880c26122f..11eb50318fec 100644 --- a/drivers/ps3/ps3av_cmd.c +++ b/drivers/ps3/ps3av_cmd.c | |||
@@ -660,9 +660,10 @@ u32 ps3av_cmd_set_av_audio_param(void *p, u32 port, | |||
660 | } | 660 | } |
661 | 661 | ||
662 | /* default cs val */ | 662 | /* default cs val */ |
663 | static const u8 ps3av_mode_cs_info[] = { | 663 | u8 ps3av_mode_cs_info[] = { |
664 | 0x00, 0x09, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00 | 664 | 0x00, 0x09, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00 |
665 | }; | 665 | }; |
666 | EXPORT_SYMBOL_GPL(ps3av_mode_cs_info); | ||
666 | 667 | ||
667 | #define CS_44 0x00 | 668 | #define CS_44 0x00 |
668 | #define CS_48 0x02 | 669 | #define CS_48 0x02 |
@@ -677,7 +678,7 @@ void ps3av_cmd_set_audio_mode(struct ps3av_pkt_audio_mode *audio, u32 avport, | |||
677 | u32 ch, u32 fs, u32 word_bits, u32 format, | 678 | u32 ch, u32 fs, u32 word_bits, u32 format, |
678 | u32 source) | 679 | u32 source) |
679 | { | 680 | { |
680 | int spdif_through, spdif_bitstream; | 681 | int spdif_through; |
681 | int i; | 682 | int i; |
682 | 683 | ||
683 | if (!(ch | fs | format | word_bits | source)) { | 684 | if (!(ch | fs | format | word_bits | source)) { |
@@ -687,7 +688,6 @@ void ps3av_cmd_set_audio_mode(struct ps3av_pkt_audio_mode *audio, u32 avport, | |||
687 | format = PS3AV_CMD_AUDIO_FORMAT_PCM; | 688 | format = PS3AV_CMD_AUDIO_FORMAT_PCM; |
688 | source = PS3AV_CMD_AUDIO_SOURCE_SERIAL; | 689 | source = PS3AV_CMD_AUDIO_SOURCE_SERIAL; |
689 | } | 690 | } |
690 | spdif_through = spdif_bitstream = 0; /* XXX not supported */ | ||
691 | 691 | ||
692 | /* audio mode */ | 692 | /* audio mode */ |
693 | memset(audio, 0, sizeof(*audio)); | 693 | memset(audio, 0, sizeof(*audio)); |
@@ -777,16 +777,17 @@ void ps3av_cmd_set_audio_mode(struct ps3av_pkt_audio_mode *audio, u32 avport, | |||
777 | break; | 777 | break; |
778 | } | 778 | } |
779 | 779 | ||
780 | /* non-audio bit */ | ||
781 | spdif_through = audio->audio_cs_info[0] & 0x02; | ||
782 | |||
780 | /* pass through setting */ | 783 | /* pass through setting */ |
781 | if (spdif_through && | 784 | if (spdif_through && |
782 | (avport == PS3AV_CMD_AVPORT_SPDIF_0 || | 785 | (avport == PS3AV_CMD_AVPORT_SPDIF_0 || |
783 | avport == PS3AV_CMD_AVPORT_SPDIF_1)) { | 786 | avport == PS3AV_CMD_AVPORT_SPDIF_1 || |
787 | avport == PS3AV_CMD_AVPORT_HDMI_0 || | ||
788 | avport == PS3AV_CMD_AVPORT_HDMI_1)) { | ||
784 | audio->audio_word_bits = PS3AV_CMD_AUDIO_WORD_BITS_16; | 789 | audio->audio_word_bits = PS3AV_CMD_AUDIO_WORD_BITS_16; |
785 | audio->audio_source = PS3AV_CMD_AUDIO_SOURCE_SPDIF; | 790 | audio->audio_format = PS3AV_CMD_AUDIO_FORMAT_BITSTREAM; |
786 | if (spdif_bitstream) { | ||
787 | audio->audio_format = PS3AV_CMD_AUDIO_FORMAT_BITSTREAM; | ||
788 | audio->audio_cs_info[0] |= CS_BIT; | ||
789 | } | ||
790 | } | 791 | } |
791 | } | 792 | } |
792 | 793 | ||
diff --git a/drivers/rtc/rtc-at91rm9200.c b/drivers/rtc/rtc-at91rm9200.c index 37082616482b..b5bf93706913 100644 --- a/drivers/rtc/rtc-at91rm9200.c +++ b/drivers/rtc/rtc-at91rm9200.c | |||
@@ -53,21 +53,21 @@ static void at91_rtc_decodetime(unsigned int timereg, unsigned int calreg, | |||
53 | } while ((time != at91_sys_read(timereg)) || | 53 | } while ((time != at91_sys_read(timereg)) || |
54 | (date != at91_sys_read(calreg))); | 54 | (date != at91_sys_read(calreg))); |
55 | 55 | ||
56 | tm->tm_sec = BCD2BIN((time & AT91_RTC_SEC) >> 0); | 56 | tm->tm_sec = bcd2bin((time & AT91_RTC_SEC) >> 0); |
57 | tm->tm_min = BCD2BIN((time & AT91_RTC_MIN) >> 8); | 57 | tm->tm_min = bcd2bin((time & AT91_RTC_MIN) >> 8); |
58 | tm->tm_hour = BCD2BIN((time & AT91_RTC_HOUR) >> 16); | 58 | tm->tm_hour = bcd2bin((time & AT91_RTC_HOUR) >> 16); |
59 | 59 | ||
60 | /* | 60 | /* |
61 | * The Calendar Alarm register does not have a field for | 61 | * The Calendar Alarm register does not have a field for |
62 | * the year - so these will return an invalid value. When an | 62 | * the year - so these will return an invalid value. When an |
63 | * alarm is set, at91_alarm_year wille store the current year. | 63 | * alarm is set, at91_alarm_year wille store the current year. |
64 | */ | 64 | */ |
65 | tm->tm_year = BCD2BIN(date & AT91_RTC_CENT) * 100; /* century */ | 65 | tm->tm_year = bcd2bin(date & AT91_RTC_CENT) * 100; /* century */ |
66 | tm->tm_year += BCD2BIN((date & AT91_RTC_YEAR) >> 8); /* year */ | 66 | tm->tm_year += bcd2bin((date & AT91_RTC_YEAR) >> 8); /* year */ |
67 | 67 | ||
68 | tm->tm_wday = BCD2BIN((date & AT91_RTC_DAY) >> 21) - 1; /* day of the week [0-6], Sunday=0 */ | 68 | tm->tm_wday = bcd2bin((date & AT91_RTC_DAY) >> 21) - 1; /* day of the week [0-6], Sunday=0 */ |
69 | tm->tm_mon = BCD2BIN((date & AT91_RTC_MONTH) >> 16) - 1; | 69 | tm->tm_mon = bcd2bin((date & AT91_RTC_MONTH) >> 16) - 1; |
70 | tm->tm_mday = BCD2BIN((date & AT91_RTC_DATE) >> 24); | 70 | tm->tm_mday = bcd2bin((date & AT91_RTC_DATE) >> 24); |
71 | } | 71 | } |
72 | 72 | ||
73 | /* | 73 | /* |
@@ -106,16 +106,16 @@ static int at91_rtc_settime(struct device *dev, struct rtc_time *tm) | |||
106 | at91_sys_write(AT91_RTC_IDR, AT91_RTC_ACKUPD); | 106 | at91_sys_write(AT91_RTC_IDR, AT91_RTC_ACKUPD); |
107 | 107 | ||
108 | at91_sys_write(AT91_RTC_TIMR, | 108 | at91_sys_write(AT91_RTC_TIMR, |
109 | BIN2BCD(tm->tm_sec) << 0 | 109 | bin2bcd(tm->tm_sec) << 0 |
110 | | BIN2BCD(tm->tm_min) << 8 | 110 | | bin2bcd(tm->tm_min) << 8 |
111 | | BIN2BCD(tm->tm_hour) << 16); | 111 | | bin2bcd(tm->tm_hour) << 16); |
112 | 112 | ||
113 | at91_sys_write(AT91_RTC_CALR, | 113 | at91_sys_write(AT91_RTC_CALR, |
114 | BIN2BCD((tm->tm_year + 1900) / 100) /* century */ | 114 | bin2bcd((tm->tm_year + 1900) / 100) /* century */ |
115 | | BIN2BCD(tm->tm_year % 100) << 8 /* year */ | 115 | | bin2bcd(tm->tm_year % 100) << 8 /* year */ |
116 | | BIN2BCD(tm->tm_mon + 1) << 16 /* tm_mon starts at zero */ | 116 | | bin2bcd(tm->tm_mon + 1) << 16 /* tm_mon starts at zero */ |
117 | | BIN2BCD(tm->tm_wday + 1) << 21 /* day of the week [0-6], Sunday=0 */ | 117 | | bin2bcd(tm->tm_wday + 1) << 21 /* day of the week [0-6], Sunday=0 */ |
118 | | BIN2BCD(tm->tm_mday) << 24); | 118 | | bin2bcd(tm->tm_mday) << 24); |
119 | 119 | ||
120 | /* Restart Time/Calendar */ | 120 | /* Restart Time/Calendar */ |
121 | cr = at91_sys_read(AT91_RTC_CR); | 121 | cr = at91_sys_read(AT91_RTC_CR); |
@@ -162,13 +162,13 @@ static int at91_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
162 | 162 | ||
163 | at91_sys_write(AT91_RTC_IDR, AT91_RTC_ALARM); | 163 | at91_sys_write(AT91_RTC_IDR, AT91_RTC_ALARM); |
164 | at91_sys_write(AT91_RTC_TIMALR, | 164 | at91_sys_write(AT91_RTC_TIMALR, |
165 | BIN2BCD(tm.tm_sec) << 0 | 165 | bin2bcd(tm.tm_sec) << 0 |
166 | | BIN2BCD(tm.tm_min) << 8 | 166 | | bin2bcd(tm.tm_min) << 8 |
167 | | BIN2BCD(tm.tm_hour) << 16 | 167 | | bin2bcd(tm.tm_hour) << 16 |
168 | | AT91_RTC_HOUREN | AT91_RTC_MINEN | AT91_RTC_SECEN); | 168 | | AT91_RTC_HOUREN | AT91_RTC_MINEN | AT91_RTC_SECEN); |
169 | at91_sys_write(AT91_RTC_CALALR, | 169 | at91_sys_write(AT91_RTC_CALALR, |
170 | BIN2BCD(tm.tm_mon + 1) << 16 /* tm_mon starts at zero */ | 170 | bin2bcd(tm.tm_mon + 1) << 16 /* tm_mon starts at zero */ |
171 | | BIN2BCD(tm.tm_mday) << 24 | 171 | | bin2bcd(tm.tm_mday) << 24 |
172 | | AT91_RTC_DATEEN | AT91_RTC_MTHEN); | 172 | | AT91_RTC_DATEEN | AT91_RTC_MTHEN); |
173 | 173 | ||
174 | if (alrm->enabled) { | 174 | if (alrm->enabled) { |
diff --git a/drivers/rtc/rtc-bq4802.c b/drivers/rtc/rtc-bq4802.c index 189a018bdf34..d00a274df8fc 100644 --- a/drivers/rtc/rtc-bq4802.c +++ b/drivers/rtc/rtc-bq4802.c | |||
@@ -71,14 +71,14 @@ static int bq4802_read_time(struct device *dev, struct rtc_time *tm) | |||
71 | 71 | ||
72 | spin_unlock_irqrestore(&p->lock, flags); | 72 | spin_unlock_irqrestore(&p->lock, flags); |
73 | 73 | ||
74 | BCD_TO_BIN(tm->tm_sec); | 74 | tm->tm_sec = bcd2bin(tm->tm_sec); |
75 | BCD_TO_BIN(tm->tm_min); | 75 | tm->tm_min = bcd2bin(tm->tm_min); |
76 | BCD_TO_BIN(tm->tm_hour); | 76 | tm->tm_hour = bcd2bin(tm->tm_hour); |
77 | BCD_TO_BIN(tm->tm_mday); | 77 | tm->tm_mday = bcd2bin(tm->tm_mday); |
78 | BCD_TO_BIN(tm->tm_mon); | 78 | tm->tm_mon = bcd2bin(tm->tm_mon); |
79 | BCD_TO_BIN(tm->tm_year); | 79 | tm->tm_year = bcd2bin(tm->tm_year); |
80 | BCD_TO_BIN(tm->tm_wday); | 80 | tm->tm_wday = bcd2bin(tm->tm_wday); |
81 | BCD_TO_BIN(century); | 81 | century = bcd2bin(century); |
82 | 82 | ||
83 | tm->tm_year += (century * 100); | 83 | tm->tm_year += (century * 100); |
84 | tm->tm_year -= 1900; | 84 | tm->tm_year -= 1900; |
@@ -106,13 +106,13 @@ static int bq4802_set_time(struct device *dev, struct rtc_time *tm) | |||
106 | min = tm->tm_min; | 106 | min = tm->tm_min; |
107 | sec = tm->tm_sec; | 107 | sec = tm->tm_sec; |
108 | 108 | ||
109 | BIN_TO_BCD(sec); | 109 | sec = bin2bcd(sec); |
110 | BIN_TO_BCD(min); | 110 | min = bin2bcd(min); |
111 | BIN_TO_BCD(hrs); | 111 | hrs = bin2bcd(hrs); |
112 | BIN_TO_BCD(day); | 112 | day = bin2bcd(day); |
113 | BIN_TO_BCD(mon); | 113 | mon = bin2bcd(mon); |
114 | BIN_TO_BCD(yrs); | 114 | yrs = bin2bcd(yrs); |
115 | BIN_TO_BCD(century); | 115 | century = bin2bcd(century); |
116 | 116 | ||
117 | spin_lock_irqsave(&p->lock, flags); | 117 | spin_lock_irqsave(&p->lock, flags); |
118 | 118 | ||
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c index 963ad0b6a4e9..5549231179a2 100644 --- a/drivers/rtc/rtc-cmos.c +++ b/drivers/rtc/rtc-cmos.c | |||
@@ -143,6 +143,43 @@ static inline int hpet_unregister_irq_handler(irq_handler_t handler) | |||
143 | 143 | ||
144 | /*----------------------------------------------------------------*/ | 144 | /*----------------------------------------------------------------*/ |
145 | 145 | ||
146 | #ifdef RTC_PORT | ||
147 | |||
148 | /* Most newer x86 systems have two register banks, the first used | ||
149 | * for RTC and NVRAM and the second only for NVRAM. Caller must | ||
150 | * own rtc_lock ... and we won't worry about access during NMI. | ||
151 | */ | ||
152 | #define can_bank2 true | ||
153 | |||
154 | static inline unsigned char cmos_read_bank2(unsigned char addr) | ||
155 | { | ||
156 | outb(addr, RTC_PORT(2)); | ||
157 | return inb(RTC_PORT(3)); | ||
158 | } | ||
159 | |||
160 | static inline void cmos_write_bank2(unsigned char val, unsigned char addr) | ||
161 | { | ||
162 | outb(addr, RTC_PORT(2)); | ||
163 | outb(val, RTC_PORT(2)); | ||
164 | } | ||
165 | |||
166 | #else | ||
167 | |||
168 | #define can_bank2 false | ||
169 | |||
170 | static inline unsigned char cmos_read_bank2(unsigned char addr) | ||
171 | { | ||
172 | return 0; | ||
173 | } | ||
174 | |||
175 | static inline void cmos_write_bank2(unsigned char val, unsigned char addr) | ||
176 | { | ||
177 | } | ||
178 | |||
179 | #endif | ||
180 | |||
181 | /*----------------------------------------------------------------*/ | ||
182 | |||
146 | static int cmos_read_time(struct device *dev, struct rtc_time *t) | 183 | static int cmos_read_time(struct device *dev, struct rtc_time *t) |
147 | { | 184 | { |
148 | /* REVISIT: if the clock has a "century" register, use | 185 | /* REVISIT: if the clock has a "century" register, use |
@@ -203,26 +240,26 @@ static int cmos_read_alarm(struct device *dev, struct rtc_wkalrm *t) | |||
203 | /* REVISIT this assumes PC style usage: always BCD */ | 240 | /* REVISIT this assumes PC style usage: always BCD */ |
204 | 241 | ||
205 | if (((unsigned)t->time.tm_sec) < 0x60) | 242 | if (((unsigned)t->time.tm_sec) < 0x60) |
206 | t->time.tm_sec = BCD2BIN(t->time.tm_sec); | 243 | t->time.tm_sec = bcd2bin(t->time.tm_sec); |
207 | else | 244 | else |
208 | t->time.tm_sec = -1; | 245 | t->time.tm_sec = -1; |
209 | if (((unsigned)t->time.tm_min) < 0x60) | 246 | if (((unsigned)t->time.tm_min) < 0x60) |
210 | t->time.tm_min = BCD2BIN(t->time.tm_min); | 247 | t->time.tm_min = bcd2bin(t->time.tm_min); |
211 | else | 248 | else |
212 | t->time.tm_min = -1; | 249 | t->time.tm_min = -1; |
213 | if (((unsigned)t->time.tm_hour) < 0x24) | 250 | if (((unsigned)t->time.tm_hour) < 0x24) |
214 | t->time.tm_hour = BCD2BIN(t->time.tm_hour); | 251 | t->time.tm_hour = bcd2bin(t->time.tm_hour); |
215 | else | 252 | else |
216 | t->time.tm_hour = -1; | 253 | t->time.tm_hour = -1; |
217 | 254 | ||
218 | if (cmos->day_alrm) { | 255 | if (cmos->day_alrm) { |
219 | if (((unsigned)t->time.tm_mday) <= 0x31) | 256 | if (((unsigned)t->time.tm_mday) <= 0x31) |
220 | t->time.tm_mday = BCD2BIN(t->time.tm_mday); | 257 | t->time.tm_mday = bcd2bin(t->time.tm_mday); |
221 | else | 258 | else |
222 | t->time.tm_mday = -1; | 259 | t->time.tm_mday = -1; |
223 | if (cmos->mon_alrm) { | 260 | if (cmos->mon_alrm) { |
224 | if (((unsigned)t->time.tm_mon) <= 0x12) | 261 | if (((unsigned)t->time.tm_mon) <= 0x12) |
225 | t->time.tm_mon = BCD2BIN(t->time.tm_mon) - 1; | 262 | t->time.tm_mon = bcd2bin(t->time.tm_mon) - 1; |
226 | else | 263 | else |
227 | t->time.tm_mon = -1; | 264 | t->time.tm_mon = -1; |
228 | } | 265 | } |
@@ -294,19 +331,19 @@ static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t) | |||
294 | /* Writing 0xff means "don't care" or "match all". */ | 331 | /* Writing 0xff means "don't care" or "match all". */ |
295 | 332 | ||
296 | mon = t->time.tm_mon + 1; | 333 | mon = t->time.tm_mon + 1; |
297 | mon = (mon <= 12) ? BIN2BCD(mon) : 0xff; | 334 | mon = (mon <= 12) ? bin2bcd(mon) : 0xff; |
298 | 335 | ||
299 | mday = t->time.tm_mday; | 336 | mday = t->time.tm_mday; |
300 | mday = (mday >= 1 && mday <= 31) ? BIN2BCD(mday) : 0xff; | 337 | mday = (mday >= 1 && mday <= 31) ? bin2bcd(mday) : 0xff; |
301 | 338 | ||
302 | hrs = t->time.tm_hour; | 339 | hrs = t->time.tm_hour; |
303 | hrs = (hrs < 24) ? BIN2BCD(hrs) : 0xff; | 340 | hrs = (hrs < 24) ? bin2bcd(hrs) : 0xff; |
304 | 341 | ||
305 | min = t->time.tm_min; | 342 | min = t->time.tm_min; |
306 | min = (min < 60) ? BIN2BCD(min) : 0xff; | 343 | min = (min < 60) ? bin2bcd(min) : 0xff; |
307 | 344 | ||
308 | sec = t->time.tm_sec; | 345 | sec = t->time.tm_sec; |
309 | sec = (sec < 60) ? BIN2BCD(sec) : 0xff; | 346 | sec = (sec < 60) ? bin2bcd(sec) : 0xff; |
310 | 347 | ||
311 | spin_lock_irq(&rtc_lock); | 348 | spin_lock_irq(&rtc_lock); |
312 | 349 | ||
@@ -491,12 +528,21 @@ cmos_nvram_read(struct kobject *kobj, struct bin_attribute *attr, | |||
491 | 528 | ||
492 | if (unlikely(off >= attr->size)) | 529 | if (unlikely(off >= attr->size)) |
493 | return 0; | 530 | return 0; |
531 | if (unlikely(off < 0)) | ||
532 | return -EINVAL; | ||
494 | if ((off + count) > attr->size) | 533 | if ((off + count) > attr->size) |
495 | count = attr->size - off; | 534 | count = attr->size - off; |
496 | 535 | ||
536 | off += NVRAM_OFFSET; | ||
497 | spin_lock_irq(&rtc_lock); | 537 | spin_lock_irq(&rtc_lock); |
498 | for (retval = 0, off += NVRAM_OFFSET; count--; retval++, off++) | 538 | for (retval = 0; count; count--, off++, retval++) { |
499 | *buf++ = CMOS_READ(off); | 539 | if (off < 128) |
540 | *buf++ = CMOS_READ(off); | ||
541 | else if (can_bank2) | ||
542 | *buf++ = cmos_read_bank2(off); | ||
543 | else | ||
544 | break; | ||
545 | } | ||
500 | spin_unlock_irq(&rtc_lock); | 546 | spin_unlock_irq(&rtc_lock); |
501 | 547 | ||
502 | return retval; | 548 | return retval; |
@@ -512,6 +558,8 @@ cmos_nvram_write(struct kobject *kobj, struct bin_attribute *attr, | |||
512 | cmos = dev_get_drvdata(container_of(kobj, struct device, kobj)); | 558 | cmos = dev_get_drvdata(container_of(kobj, struct device, kobj)); |
513 | if (unlikely(off >= attr->size)) | 559 | if (unlikely(off >= attr->size)) |
514 | return -EFBIG; | 560 | return -EFBIG; |
561 | if (unlikely(off < 0)) | ||
562 | return -EINVAL; | ||
515 | if ((off + count) > attr->size) | 563 | if ((off + count) > attr->size) |
516 | count = attr->size - off; | 564 | count = attr->size - off; |
517 | 565 | ||
@@ -520,15 +568,20 @@ cmos_nvram_write(struct kobject *kobj, struct bin_attribute *attr, | |||
520 | * here. If userspace is smart enough to know what fields of | 568 | * here. If userspace is smart enough to know what fields of |
521 | * NVRAM to update, updating checksums is also part of its job. | 569 | * NVRAM to update, updating checksums is also part of its job. |
522 | */ | 570 | */ |
571 | off += NVRAM_OFFSET; | ||
523 | spin_lock_irq(&rtc_lock); | 572 | spin_lock_irq(&rtc_lock); |
524 | for (retval = 0, off += NVRAM_OFFSET; count--; retval++, off++) { | 573 | for (retval = 0; count; count--, off++, retval++) { |
525 | /* don't trash RTC registers */ | 574 | /* don't trash RTC registers */ |
526 | if (off == cmos->day_alrm | 575 | if (off == cmos->day_alrm |
527 | || off == cmos->mon_alrm | 576 | || off == cmos->mon_alrm |
528 | || off == cmos->century) | 577 | || off == cmos->century) |
529 | buf++; | 578 | buf++; |
530 | else | 579 | else if (off < 128) |
531 | CMOS_WRITE(*buf++, off); | 580 | CMOS_WRITE(*buf++, off); |
581 | else if (can_bank2) | ||
582 | cmos_write_bank2(*buf++, off); | ||
583 | else | ||
584 | break; | ||
532 | } | 585 | } |
533 | spin_unlock_irq(&rtc_lock); | 586 | spin_unlock_irq(&rtc_lock); |
534 | 587 | ||
@@ -539,7 +592,6 @@ static struct bin_attribute nvram = { | |||
539 | .attr = { | 592 | .attr = { |
540 | .name = "nvram", | 593 | .name = "nvram", |
541 | .mode = S_IRUGO | S_IWUSR, | 594 | .mode = S_IRUGO | S_IWUSR, |
542 | .owner = THIS_MODULE, | ||
543 | }, | 595 | }, |
544 | 596 | ||
545 | .read = cmos_nvram_read, | 597 | .read = cmos_nvram_read, |
@@ -631,8 +683,8 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq) | |||
631 | 683 | ||
632 | /* Heuristic to deduce NVRAM size ... do what the legacy NVRAM | 684 | /* Heuristic to deduce NVRAM size ... do what the legacy NVRAM |
633 | * driver did, but don't reject unknown configs. Old hardware | 685 | * driver did, but don't reject unknown configs. Old hardware |
634 | * won't address 128 bytes, and for now we ignore the way newer | 686 | * won't address 128 bytes. Newer chips have multiple banks, |
635 | * chips can address 256 bytes (using two more i/o ports). | 687 | * though they may not be listed in one I/O resource. |
636 | */ | 688 | */ |
637 | #if defined(CONFIG_ATARI) | 689 | #if defined(CONFIG_ATARI) |
638 | address_space = 64; | 690 | address_space = 64; |
@@ -642,6 +694,8 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq) | |||
642 | #warning Assuming 128 bytes of RTC+NVRAM address space, not 64 bytes. | 694 | #warning Assuming 128 bytes of RTC+NVRAM address space, not 64 bytes. |
643 | address_space = 128; | 695 | address_space = 128; |
644 | #endif | 696 | #endif |
697 | if (can_bank2 && ports->end > (ports->start + 1)) | ||
698 | address_space = 256; | ||
645 | 699 | ||
646 | /* For ACPI systems extension info comes from the FADT. On others, | 700 | /* For ACPI systems extension info comes from the FADT. On others, |
647 | * board specific setup provides it as appropriate. Systems where | 701 | * board specific setup provides it as appropriate. Systems where |
@@ -740,7 +794,7 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq) | |||
740 | goto cleanup2; | 794 | goto cleanup2; |
741 | } | 795 | } |
742 | 796 | ||
743 | pr_info("%s: alarms up to one %s%s%s\n", | 797 | pr_info("%s: alarms up to one %s%s, %zd bytes nvram, %s irqs\n", |
744 | cmos_rtc.rtc->dev.bus_id, | 798 | cmos_rtc.rtc->dev.bus_id, |
745 | is_valid_irq(rtc_irq) | 799 | is_valid_irq(rtc_irq) |
746 | ? (cmos_rtc.mon_alrm | 800 | ? (cmos_rtc.mon_alrm |
@@ -749,6 +803,7 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq) | |||
749 | ? "month" : "day")) | 803 | ? "month" : "day")) |
750 | : "no", | 804 | : "no", |
751 | cmos_rtc.century ? ", y3k" : "", | 805 | cmos_rtc.century ? ", y3k" : "", |
806 | nvram.size, | ||
752 | is_hpet_enabled() ? ", hpet irqs" : ""); | 807 | is_hpet_enabled() ? ", hpet irqs" : ""); |
753 | 808 | ||
754 | return 0; | 809 | return 0; |
diff --git a/drivers/rtc/rtc-ds1216.c b/drivers/rtc/rtc-ds1216.c index 0b17770b032b..9a234a4ec06d 100644 --- a/drivers/rtc/rtc-ds1216.c +++ b/drivers/rtc/rtc-ds1216.c | |||
@@ -86,19 +86,19 @@ static int ds1216_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
86 | ds1216_switch_ds_to_clock(priv->ioaddr); | 86 | ds1216_switch_ds_to_clock(priv->ioaddr); |
87 | ds1216_read(priv->ioaddr, (u8 *)®s); | 87 | ds1216_read(priv->ioaddr, (u8 *)®s); |
88 | 88 | ||
89 | tm->tm_sec = BCD2BIN(regs.sec); | 89 | tm->tm_sec = bcd2bin(regs.sec); |
90 | tm->tm_min = BCD2BIN(regs.min); | 90 | tm->tm_min = bcd2bin(regs.min); |
91 | if (regs.hour & DS1216_HOUR_1224) { | 91 | if (regs.hour & DS1216_HOUR_1224) { |
92 | /* AM/PM mode */ | 92 | /* AM/PM mode */ |
93 | tm->tm_hour = BCD2BIN(regs.hour & 0x1f); | 93 | tm->tm_hour = bcd2bin(regs.hour & 0x1f); |
94 | if (regs.hour & DS1216_HOUR_AMPM) | 94 | if (regs.hour & DS1216_HOUR_AMPM) |
95 | tm->tm_hour += 12; | 95 | tm->tm_hour += 12; |
96 | } else | 96 | } else |
97 | tm->tm_hour = BCD2BIN(regs.hour & 0x3f); | 97 | tm->tm_hour = bcd2bin(regs.hour & 0x3f); |
98 | tm->tm_wday = (regs.wday & 7) - 1; | 98 | tm->tm_wday = (regs.wday & 7) - 1; |
99 | tm->tm_mday = BCD2BIN(regs.mday & 0x3f); | 99 | tm->tm_mday = bcd2bin(regs.mday & 0x3f); |
100 | tm->tm_mon = BCD2BIN(regs.month & 0x1f); | 100 | tm->tm_mon = bcd2bin(regs.month & 0x1f); |
101 | tm->tm_year = BCD2BIN(regs.year); | 101 | tm->tm_year = bcd2bin(regs.year); |
102 | if (tm->tm_year < 70) | 102 | if (tm->tm_year < 70) |
103 | tm->tm_year += 100; | 103 | tm->tm_year += 100; |
104 | return 0; | 104 | return 0; |
@@ -114,19 +114,19 @@ static int ds1216_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
114 | ds1216_read(priv->ioaddr, (u8 *)®s); | 114 | ds1216_read(priv->ioaddr, (u8 *)®s); |
115 | 115 | ||
116 | regs.tsec = 0; /* clear 0.1 and 0.01 seconds */ | 116 | regs.tsec = 0; /* clear 0.1 and 0.01 seconds */ |
117 | regs.sec = BIN2BCD(tm->tm_sec); | 117 | regs.sec = bin2bcd(tm->tm_sec); |
118 | regs.min = BIN2BCD(tm->tm_min); | 118 | regs.min = bin2bcd(tm->tm_min); |
119 | regs.hour &= DS1216_HOUR_1224; | 119 | regs.hour &= DS1216_HOUR_1224; |
120 | if (regs.hour && tm->tm_hour > 12) { | 120 | if (regs.hour && tm->tm_hour > 12) { |
121 | regs.hour |= DS1216_HOUR_AMPM; | 121 | regs.hour |= DS1216_HOUR_AMPM; |
122 | tm->tm_hour -= 12; | 122 | tm->tm_hour -= 12; |
123 | } | 123 | } |
124 | regs.hour |= BIN2BCD(tm->tm_hour); | 124 | regs.hour |= bin2bcd(tm->tm_hour); |
125 | regs.wday &= ~7; | 125 | regs.wday &= ~7; |
126 | regs.wday |= tm->tm_wday; | 126 | regs.wday |= tm->tm_wday; |
127 | regs.mday = BIN2BCD(tm->tm_mday); | 127 | regs.mday = bin2bcd(tm->tm_mday); |
128 | regs.month = BIN2BCD(tm->tm_mon); | 128 | regs.month = bin2bcd(tm->tm_mon); |
129 | regs.year = BIN2BCD(tm->tm_year % 100); | 129 | regs.year = bin2bcd(tm->tm_year % 100); |
130 | 130 | ||
131 | ds1216_switch_ds_to_clock(priv->ioaddr); | 131 | ds1216_switch_ds_to_clock(priv->ioaddr); |
132 | ds1216_write(priv->ioaddr, (u8 *)®s); | 132 | ds1216_write(priv->ioaddr, (u8 *)®s); |
diff --git a/drivers/rtc/rtc-ds1302.c b/drivers/rtc/rtc-ds1302.c index 8f4e96bb229a..184556620778 100644 --- a/drivers/rtc/rtc-ds1302.c +++ b/drivers/rtc/rtc-ds1302.c | |||
@@ -107,13 +107,13 @@ static int ds1302_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
107 | 107 | ||
108 | spin_lock_irq(&rtc->lock); | 108 | spin_lock_irq(&rtc->lock); |
109 | 109 | ||
110 | tm->tm_sec = BCD2BIN(ds1302_readbyte(RTC_ADDR_SEC)); | 110 | tm->tm_sec = bcd2bin(ds1302_readbyte(RTC_ADDR_SEC)); |
111 | tm->tm_min = BCD2BIN(ds1302_readbyte(RTC_ADDR_MIN)); | 111 | tm->tm_min = bcd2bin(ds1302_readbyte(RTC_ADDR_MIN)); |
112 | tm->tm_hour = BCD2BIN(ds1302_readbyte(RTC_ADDR_HOUR)); | 112 | tm->tm_hour = bcd2bin(ds1302_readbyte(RTC_ADDR_HOUR)); |
113 | tm->tm_wday = BCD2BIN(ds1302_readbyte(RTC_ADDR_DAY)); | 113 | tm->tm_wday = bcd2bin(ds1302_readbyte(RTC_ADDR_DAY)); |
114 | tm->tm_mday = BCD2BIN(ds1302_readbyte(RTC_ADDR_DATE)); | 114 | tm->tm_mday = bcd2bin(ds1302_readbyte(RTC_ADDR_DATE)); |
115 | tm->tm_mon = BCD2BIN(ds1302_readbyte(RTC_ADDR_MON)) - 1; | 115 | tm->tm_mon = bcd2bin(ds1302_readbyte(RTC_ADDR_MON)) - 1; |
116 | tm->tm_year = BCD2BIN(ds1302_readbyte(RTC_ADDR_YEAR)); | 116 | tm->tm_year = bcd2bin(ds1302_readbyte(RTC_ADDR_YEAR)); |
117 | 117 | ||
118 | if (tm->tm_year < 70) | 118 | if (tm->tm_year < 70) |
119 | tm->tm_year += 100; | 119 | tm->tm_year += 100; |
@@ -141,13 +141,13 @@ static int ds1302_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
141 | /* Stop RTC */ | 141 | /* Stop RTC */ |
142 | ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) | 0x80); | 142 | ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) | 0x80); |
143 | 143 | ||
144 | ds1302_writebyte(RTC_ADDR_SEC, BIN2BCD(tm->tm_sec)); | 144 | ds1302_writebyte(RTC_ADDR_SEC, bin2bcd(tm->tm_sec)); |
145 | ds1302_writebyte(RTC_ADDR_MIN, BIN2BCD(tm->tm_min)); | 145 | ds1302_writebyte(RTC_ADDR_MIN, bin2bcd(tm->tm_min)); |
146 | ds1302_writebyte(RTC_ADDR_HOUR, BIN2BCD(tm->tm_hour)); | 146 | ds1302_writebyte(RTC_ADDR_HOUR, bin2bcd(tm->tm_hour)); |
147 | ds1302_writebyte(RTC_ADDR_DAY, BIN2BCD(tm->tm_wday)); | 147 | ds1302_writebyte(RTC_ADDR_DAY, bin2bcd(tm->tm_wday)); |
148 | ds1302_writebyte(RTC_ADDR_DATE, BIN2BCD(tm->tm_mday)); | 148 | ds1302_writebyte(RTC_ADDR_DATE, bin2bcd(tm->tm_mday)); |
149 | ds1302_writebyte(RTC_ADDR_MON, BIN2BCD(tm->tm_mon + 1)); | 149 | ds1302_writebyte(RTC_ADDR_MON, bin2bcd(tm->tm_mon + 1)); |
150 | ds1302_writebyte(RTC_ADDR_YEAR, BIN2BCD(tm->tm_year % 100)); | 150 | ds1302_writebyte(RTC_ADDR_YEAR, bin2bcd(tm->tm_year % 100)); |
151 | 151 | ||
152 | /* Start RTC */ | 152 | /* Start RTC */ |
153 | ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) & ~0x80); | 153 | ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) & ~0x80); |
diff --git a/drivers/rtc/rtc-ds1305.c b/drivers/rtc/rtc-ds1305.c index b91d02a3ace9..fc372df6534b 100644 --- a/drivers/rtc/rtc-ds1305.c +++ b/drivers/rtc/rtc-ds1305.c | |||
@@ -114,10 +114,10 @@ static unsigned bcd2hour(u8 bcd) | |||
114 | hour = 12; | 114 | hour = 12; |
115 | bcd &= ~DS1305_HR_PM; | 115 | bcd &= ~DS1305_HR_PM; |
116 | } | 116 | } |
117 | hour += BCD2BIN(bcd); | 117 | hour += bcd2bin(bcd); |
118 | return hour - 1; | 118 | return hour - 1; |
119 | } | 119 | } |
120 | return BCD2BIN(bcd); | 120 | return bcd2bin(bcd); |
121 | } | 121 | } |
122 | 122 | ||
123 | static u8 hour2bcd(bool hr12, int hour) | 123 | static u8 hour2bcd(bool hr12, int hour) |
@@ -125,11 +125,11 @@ static u8 hour2bcd(bool hr12, int hour) | |||
125 | if (hr12) { | 125 | if (hr12) { |
126 | hour++; | 126 | hour++; |
127 | if (hour <= 12) | 127 | if (hour <= 12) |
128 | return DS1305_HR_12 | BIN2BCD(hour); | 128 | return DS1305_HR_12 | bin2bcd(hour); |
129 | hour -= 12; | 129 | hour -= 12; |
130 | return DS1305_HR_12 | DS1305_HR_PM | BIN2BCD(hour); | 130 | return DS1305_HR_12 | DS1305_HR_PM | bin2bcd(hour); |
131 | } | 131 | } |
132 | return BIN2BCD(hour); | 132 | return bin2bcd(hour); |
133 | } | 133 | } |
134 | 134 | ||
135 | /*----------------------------------------------------------------------*/ | 135 | /*----------------------------------------------------------------------*/ |
@@ -206,13 +206,13 @@ static int ds1305_get_time(struct device *dev, struct rtc_time *time) | |||
206 | buf[4], buf[5], buf[6]); | 206 | buf[4], buf[5], buf[6]); |
207 | 207 | ||
208 | /* Decode the registers */ | 208 | /* Decode the registers */ |
209 | time->tm_sec = BCD2BIN(buf[DS1305_SEC]); | 209 | time->tm_sec = bcd2bin(buf[DS1305_SEC]); |
210 | time->tm_min = BCD2BIN(buf[DS1305_MIN]); | 210 | time->tm_min = bcd2bin(buf[DS1305_MIN]); |
211 | time->tm_hour = bcd2hour(buf[DS1305_HOUR]); | 211 | time->tm_hour = bcd2hour(buf[DS1305_HOUR]); |
212 | time->tm_wday = buf[DS1305_WDAY] - 1; | 212 | time->tm_wday = buf[DS1305_WDAY] - 1; |
213 | time->tm_mday = BCD2BIN(buf[DS1305_MDAY]); | 213 | time->tm_mday = bcd2bin(buf[DS1305_MDAY]); |
214 | time->tm_mon = BCD2BIN(buf[DS1305_MON]) - 1; | 214 | time->tm_mon = bcd2bin(buf[DS1305_MON]) - 1; |
215 | time->tm_year = BCD2BIN(buf[DS1305_YEAR]) + 100; | 215 | time->tm_year = bcd2bin(buf[DS1305_YEAR]) + 100; |
216 | 216 | ||
217 | dev_vdbg(dev, "%s secs=%d, mins=%d, " | 217 | dev_vdbg(dev, "%s secs=%d, mins=%d, " |
218 | "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n", | 218 | "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n", |
@@ -239,13 +239,13 @@ static int ds1305_set_time(struct device *dev, struct rtc_time *time) | |||
239 | /* Write registers starting at the first time/date address. */ | 239 | /* Write registers starting at the first time/date address. */ |
240 | *bp++ = DS1305_WRITE | DS1305_SEC; | 240 | *bp++ = DS1305_WRITE | DS1305_SEC; |
241 | 241 | ||
242 | *bp++ = BIN2BCD(time->tm_sec); | 242 | *bp++ = bin2bcd(time->tm_sec); |
243 | *bp++ = BIN2BCD(time->tm_min); | 243 | *bp++ = bin2bcd(time->tm_min); |
244 | *bp++ = hour2bcd(ds1305->hr12, time->tm_hour); | 244 | *bp++ = hour2bcd(ds1305->hr12, time->tm_hour); |
245 | *bp++ = (time->tm_wday < 7) ? (time->tm_wday + 1) : 1; | 245 | *bp++ = (time->tm_wday < 7) ? (time->tm_wday + 1) : 1; |
246 | *bp++ = BIN2BCD(time->tm_mday); | 246 | *bp++ = bin2bcd(time->tm_mday); |
247 | *bp++ = BIN2BCD(time->tm_mon + 1); | 247 | *bp++ = bin2bcd(time->tm_mon + 1); |
248 | *bp++ = BIN2BCD(time->tm_year - 100); | 248 | *bp++ = bin2bcd(time->tm_year - 100); |
249 | 249 | ||
250 | dev_dbg(dev, "%s: %02x %02x %02x, %02x %02x %02x %02x\n", | 250 | dev_dbg(dev, "%s: %02x %02x %02x, %02x %02x %02x %02x\n", |
251 | "write", buf[1], buf[2], buf[3], | 251 | "write", buf[1], buf[2], buf[3], |
@@ -329,8 +329,8 @@ static int ds1305_get_alarm(struct device *dev, struct rtc_wkalrm *alm) | |||
329 | * fill in the rest ... and also handle rollover to tomorrow when | 329 | * fill in the rest ... and also handle rollover to tomorrow when |
330 | * that's needed. | 330 | * that's needed. |
331 | */ | 331 | */ |
332 | alm->time.tm_sec = BCD2BIN(buf[DS1305_SEC]); | 332 | alm->time.tm_sec = bcd2bin(buf[DS1305_SEC]); |
333 | alm->time.tm_min = BCD2BIN(buf[DS1305_MIN]); | 333 | alm->time.tm_min = bcd2bin(buf[DS1305_MIN]); |
334 | alm->time.tm_hour = bcd2hour(buf[DS1305_HOUR]); | 334 | alm->time.tm_hour = bcd2hour(buf[DS1305_HOUR]); |
335 | alm->time.tm_mday = -1; | 335 | alm->time.tm_mday = -1; |
336 | alm->time.tm_mon = -1; | 336 | alm->time.tm_mon = -1; |
@@ -387,8 +387,8 @@ static int ds1305_set_alarm(struct device *dev, struct rtc_wkalrm *alm) | |||
387 | 387 | ||
388 | /* write alarm */ | 388 | /* write alarm */ |
389 | buf[0] = DS1305_WRITE | DS1305_ALM0(DS1305_SEC); | 389 | buf[0] = DS1305_WRITE | DS1305_ALM0(DS1305_SEC); |
390 | buf[1 + DS1305_SEC] = BIN2BCD(alm->time.tm_sec); | 390 | buf[1 + DS1305_SEC] = bin2bcd(alm->time.tm_sec); |
391 | buf[1 + DS1305_MIN] = BIN2BCD(alm->time.tm_min); | 391 | buf[1 + DS1305_MIN] = bin2bcd(alm->time.tm_min); |
392 | buf[1 + DS1305_HOUR] = hour2bcd(ds1305->hr12, alm->time.tm_hour); | 392 | buf[1 + DS1305_HOUR] = hour2bcd(ds1305->hr12, alm->time.tm_hour); |
393 | buf[1 + DS1305_WDAY] = DS1305_ALM_DISABLE; | 393 | buf[1 + DS1305_WDAY] = DS1305_ALM_DISABLE; |
394 | 394 | ||
@@ -606,7 +606,6 @@ ds1305_nvram_write(struct kobject *kobj, struct bin_attribute *attr, | |||
606 | static struct bin_attribute nvram = { | 606 | static struct bin_attribute nvram = { |
607 | .attr.name = "nvram", | 607 | .attr.name = "nvram", |
608 | .attr.mode = S_IRUGO | S_IWUSR, | 608 | .attr.mode = S_IRUGO | S_IWUSR, |
609 | .attr.owner = THIS_MODULE, | ||
610 | .read = ds1305_nvram_read, | 609 | .read = ds1305_nvram_read, |
611 | .write = ds1305_nvram_write, | 610 | .write = ds1305_nvram_write, |
612 | .size = DS1305_NVRAM_LEN, | 611 | .size = DS1305_NVRAM_LEN, |
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c index 4fcf0734a6ef..162330b9d1dc 100644 --- a/drivers/rtc/rtc-ds1307.c +++ b/drivers/rtc/rtc-ds1307.c | |||
@@ -222,17 +222,17 @@ static int ds1307_get_time(struct device *dev, struct rtc_time *t) | |||
222 | ds1307->regs[4], ds1307->regs[5], | 222 | ds1307->regs[4], ds1307->regs[5], |
223 | ds1307->regs[6]); | 223 | ds1307->regs[6]); |
224 | 224 | ||
225 | t->tm_sec = BCD2BIN(ds1307->regs[DS1307_REG_SECS] & 0x7f); | 225 | t->tm_sec = bcd2bin(ds1307->regs[DS1307_REG_SECS] & 0x7f); |
226 | t->tm_min = BCD2BIN(ds1307->regs[DS1307_REG_MIN] & 0x7f); | 226 | t->tm_min = bcd2bin(ds1307->regs[DS1307_REG_MIN] & 0x7f); |
227 | tmp = ds1307->regs[DS1307_REG_HOUR] & 0x3f; | 227 | tmp = ds1307->regs[DS1307_REG_HOUR] & 0x3f; |
228 | t->tm_hour = BCD2BIN(tmp); | 228 | t->tm_hour = bcd2bin(tmp); |
229 | t->tm_wday = BCD2BIN(ds1307->regs[DS1307_REG_WDAY] & 0x07) - 1; | 229 | t->tm_wday = bcd2bin(ds1307->regs[DS1307_REG_WDAY] & 0x07) - 1; |
230 | t->tm_mday = BCD2BIN(ds1307->regs[DS1307_REG_MDAY] & 0x3f); | 230 | t->tm_mday = bcd2bin(ds1307->regs[DS1307_REG_MDAY] & 0x3f); |
231 | tmp = ds1307->regs[DS1307_REG_MONTH] & 0x1f; | 231 | tmp = ds1307->regs[DS1307_REG_MONTH] & 0x1f; |
232 | t->tm_mon = BCD2BIN(tmp) - 1; | 232 | t->tm_mon = bcd2bin(tmp) - 1; |
233 | 233 | ||
234 | /* assume 20YY not 19YY, and ignore DS1337_BIT_CENTURY */ | 234 | /* assume 20YY not 19YY, and ignore DS1337_BIT_CENTURY */ |
235 | t->tm_year = BCD2BIN(ds1307->regs[DS1307_REG_YEAR]) + 100; | 235 | t->tm_year = bcd2bin(ds1307->regs[DS1307_REG_YEAR]) + 100; |
236 | 236 | ||
237 | dev_dbg(dev, "%s secs=%d, mins=%d, " | 237 | dev_dbg(dev, "%s secs=%d, mins=%d, " |
238 | "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n", | 238 | "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n", |
@@ -258,16 +258,16 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t) | |||
258 | t->tm_mon, t->tm_year, t->tm_wday); | 258 | t->tm_mon, t->tm_year, t->tm_wday); |
259 | 259 | ||
260 | *buf++ = 0; /* first register addr */ | 260 | *buf++ = 0; /* first register addr */ |
261 | buf[DS1307_REG_SECS] = BIN2BCD(t->tm_sec); | 261 | buf[DS1307_REG_SECS] = bin2bcd(t->tm_sec); |
262 | buf[DS1307_REG_MIN] = BIN2BCD(t->tm_min); | 262 | buf[DS1307_REG_MIN] = bin2bcd(t->tm_min); |
263 | buf[DS1307_REG_HOUR] = BIN2BCD(t->tm_hour); | 263 | buf[DS1307_REG_HOUR] = bin2bcd(t->tm_hour); |
264 | buf[DS1307_REG_WDAY] = BIN2BCD(t->tm_wday + 1); | 264 | buf[DS1307_REG_WDAY] = bin2bcd(t->tm_wday + 1); |
265 | buf[DS1307_REG_MDAY] = BIN2BCD(t->tm_mday); | 265 | buf[DS1307_REG_MDAY] = bin2bcd(t->tm_mday); |
266 | buf[DS1307_REG_MONTH] = BIN2BCD(t->tm_mon + 1); | 266 | buf[DS1307_REG_MONTH] = bin2bcd(t->tm_mon + 1); |
267 | 267 | ||
268 | /* assume 20YY not 19YY */ | 268 | /* assume 20YY not 19YY */ |
269 | tmp = t->tm_year - 100; | 269 | tmp = t->tm_year - 100; |
270 | buf[DS1307_REG_YEAR] = BIN2BCD(tmp); | 270 | buf[DS1307_REG_YEAR] = bin2bcd(tmp); |
271 | 271 | ||
272 | switch (ds1307->type) { | 272 | switch (ds1307->type) { |
273 | case ds_1337: | 273 | case ds_1337: |
@@ -551,7 +551,6 @@ static struct bin_attribute nvram = { | |||
551 | .attr = { | 551 | .attr = { |
552 | .name = "nvram", | 552 | .name = "nvram", |
553 | .mode = S_IRUGO | S_IWUSR, | 553 | .mode = S_IRUGO | S_IWUSR, |
554 | .owner = THIS_MODULE, | ||
555 | }, | 554 | }, |
556 | 555 | ||
557 | .read = ds1307_nvram_read, | 556 | .read = ds1307_nvram_read, |
@@ -709,18 +708,18 @@ read_rtc: | |||
709 | } | 708 | } |
710 | 709 | ||
711 | tmp = ds1307->regs[DS1307_REG_SECS]; | 710 | tmp = ds1307->regs[DS1307_REG_SECS]; |
712 | tmp = BCD2BIN(tmp & 0x7f); | 711 | tmp = bcd2bin(tmp & 0x7f); |
713 | if (tmp > 60) | 712 | if (tmp > 60) |
714 | goto exit_bad; | 713 | goto exit_bad; |
715 | tmp = BCD2BIN(ds1307->regs[DS1307_REG_MIN] & 0x7f); | 714 | tmp = bcd2bin(ds1307->regs[DS1307_REG_MIN] & 0x7f); |
716 | if (tmp > 60) | 715 | if (tmp > 60) |
717 | goto exit_bad; | 716 | goto exit_bad; |
718 | 717 | ||
719 | tmp = BCD2BIN(ds1307->regs[DS1307_REG_MDAY] & 0x3f); | 718 | tmp = bcd2bin(ds1307->regs[DS1307_REG_MDAY] & 0x3f); |
720 | if (tmp == 0 || tmp > 31) | 719 | if (tmp == 0 || tmp > 31) |
721 | goto exit_bad; | 720 | goto exit_bad; |
722 | 721 | ||
723 | tmp = BCD2BIN(ds1307->regs[DS1307_REG_MONTH] & 0x1f); | 722 | tmp = bcd2bin(ds1307->regs[DS1307_REG_MONTH] & 0x1f); |
724 | if (tmp == 0 || tmp > 12) | 723 | if (tmp == 0 || tmp > 12) |
725 | goto exit_bad; | 724 | goto exit_bad; |
726 | 725 | ||
@@ -739,14 +738,14 @@ read_rtc: | |||
739 | /* Be sure we're in 24 hour mode. Multi-master systems | 738 | /* Be sure we're in 24 hour mode. Multi-master systems |
740 | * take note... | 739 | * take note... |
741 | */ | 740 | */ |
742 | tmp = BCD2BIN(tmp & 0x1f); | 741 | tmp = bcd2bin(tmp & 0x1f); |
743 | if (tmp == 12) | 742 | if (tmp == 12) |
744 | tmp = 0; | 743 | tmp = 0; |
745 | if (ds1307->regs[DS1307_REG_HOUR] & DS1307_BIT_PM) | 744 | if (ds1307->regs[DS1307_REG_HOUR] & DS1307_BIT_PM) |
746 | tmp += 12; | 745 | tmp += 12; |
747 | i2c_smbus_write_byte_data(client, | 746 | i2c_smbus_write_byte_data(client, |
748 | DS1307_REG_HOUR, | 747 | DS1307_REG_HOUR, |
749 | BIN2BCD(tmp)); | 748 | bin2bcd(tmp)); |
750 | } | 749 | } |
751 | 750 | ||
752 | ds1307->rtc = rtc_device_register(client->name, &client->dev, | 751 | ds1307->rtc = rtc_device_register(client->name, &client->dev, |
diff --git a/drivers/rtc/rtc-ds1511.c b/drivers/rtc/rtc-ds1511.c index 86981d34fbb6..25caada78398 100644 --- a/drivers/rtc/rtc-ds1511.c +++ b/drivers/rtc/rtc-ds1511.c | |||
@@ -153,8 +153,8 @@ ds1511_wdog_set(unsigned long deciseconds) | |||
153 | /* | 153 | /* |
154 | * set the wdog values in the wdog registers | 154 | * set the wdog values in the wdog registers |
155 | */ | 155 | */ |
156 | rtc_write(BIN2BCD(deciseconds % 100), DS1511_WD_MSEC); | 156 | rtc_write(bin2bcd(deciseconds % 100), DS1511_WD_MSEC); |
157 | rtc_write(BIN2BCD(deciseconds / 100), DS1511_WD_SEC); | 157 | rtc_write(bin2bcd(deciseconds / 100), DS1511_WD_SEC); |
158 | /* | 158 | /* |
159 | * set wdog enable and wdog 'steering' bit to issue a reset | 159 | * set wdog enable and wdog 'steering' bit to issue a reset |
160 | */ | 160 | */ |
@@ -220,13 +220,13 @@ static int ds1511_rtc_set_time(struct device *dev, struct rtc_time *rtc_tm) | |||
220 | /* | 220 | /* |
221 | * each register is a different number of valid bits | 221 | * each register is a different number of valid bits |
222 | */ | 222 | */ |
223 | sec = BIN2BCD(sec) & 0x7f; | 223 | sec = bin2bcd(sec) & 0x7f; |
224 | min = BIN2BCD(min) & 0x7f; | 224 | min = bin2bcd(min) & 0x7f; |
225 | hrs = BIN2BCD(hrs) & 0x3f; | 225 | hrs = bin2bcd(hrs) & 0x3f; |
226 | day = BIN2BCD(day) & 0x3f; | 226 | day = bin2bcd(day) & 0x3f; |
227 | mon = BIN2BCD(mon) & 0x1f; | 227 | mon = bin2bcd(mon) & 0x1f; |
228 | yrs = BIN2BCD(yrs) & 0xff; | 228 | yrs = bin2bcd(yrs) & 0xff; |
229 | cen = BIN2BCD(cen) & 0xff; | 229 | cen = bin2bcd(cen) & 0xff; |
230 | 230 | ||
231 | spin_lock_irqsave(&ds1511_lock, flags); | 231 | spin_lock_irqsave(&ds1511_lock, flags); |
232 | rtc_disable_update(); | 232 | rtc_disable_update(); |
@@ -264,14 +264,14 @@ static int ds1511_rtc_read_time(struct device *dev, struct rtc_time *rtc_tm) | |||
264 | rtc_enable_update(); | 264 | rtc_enable_update(); |
265 | spin_unlock_irqrestore(&ds1511_lock, flags); | 265 | spin_unlock_irqrestore(&ds1511_lock, flags); |
266 | 266 | ||
267 | rtc_tm->tm_sec = BCD2BIN(rtc_tm->tm_sec); | 267 | rtc_tm->tm_sec = bcd2bin(rtc_tm->tm_sec); |
268 | rtc_tm->tm_min = BCD2BIN(rtc_tm->tm_min); | 268 | rtc_tm->tm_min = bcd2bin(rtc_tm->tm_min); |
269 | rtc_tm->tm_hour = BCD2BIN(rtc_tm->tm_hour); | 269 | rtc_tm->tm_hour = bcd2bin(rtc_tm->tm_hour); |
270 | rtc_tm->tm_mday = BCD2BIN(rtc_tm->tm_mday); | 270 | rtc_tm->tm_mday = bcd2bin(rtc_tm->tm_mday); |
271 | rtc_tm->tm_wday = BCD2BIN(rtc_tm->tm_wday); | 271 | rtc_tm->tm_wday = bcd2bin(rtc_tm->tm_wday); |
272 | rtc_tm->tm_mon = BCD2BIN(rtc_tm->tm_mon); | 272 | rtc_tm->tm_mon = bcd2bin(rtc_tm->tm_mon); |
273 | rtc_tm->tm_year = BCD2BIN(rtc_tm->tm_year); | 273 | rtc_tm->tm_year = bcd2bin(rtc_tm->tm_year); |
274 | century = BCD2BIN(century) * 100; | 274 | century = bcd2bin(century) * 100; |
275 | 275 | ||
276 | /* | 276 | /* |
277 | * Account for differences between how the RTC uses the values | 277 | * Account for differences between how the RTC uses the values |
@@ -304,16 +304,16 @@ ds1511_rtc_update_alarm(struct rtc_plat_data *pdata) | |||
304 | 304 | ||
305 | spin_lock_irqsave(&pdata->rtc->irq_lock, flags); | 305 | spin_lock_irqsave(&pdata->rtc->irq_lock, flags); |
306 | rtc_write(pdata->alrm_mday < 0 || (pdata->irqen & RTC_UF) ? | 306 | rtc_write(pdata->alrm_mday < 0 || (pdata->irqen & RTC_UF) ? |
307 | 0x80 : BIN2BCD(pdata->alrm_mday) & 0x3f, | 307 | 0x80 : bin2bcd(pdata->alrm_mday) & 0x3f, |
308 | RTC_ALARM_DATE); | 308 | RTC_ALARM_DATE); |
309 | rtc_write(pdata->alrm_hour < 0 || (pdata->irqen & RTC_UF) ? | 309 | rtc_write(pdata->alrm_hour < 0 || (pdata->irqen & RTC_UF) ? |
310 | 0x80 : BIN2BCD(pdata->alrm_hour) & 0x3f, | 310 | 0x80 : bin2bcd(pdata->alrm_hour) & 0x3f, |
311 | RTC_ALARM_HOUR); | 311 | RTC_ALARM_HOUR); |
312 | rtc_write(pdata->alrm_min < 0 || (pdata->irqen & RTC_UF) ? | 312 | rtc_write(pdata->alrm_min < 0 || (pdata->irqen & RTC_UF) ? |
313 | 0x80 : BIN2BCD(pdata->alrm_min) & 0x7f, | 313 | 0x80 : bin2bcd(pdata->alrm_min) & 0x7f, |
314 | RTC_ALARM_MIN); | 314 | RTC_ALARM_MIN); |
315 | rtc_write(pdata->alrm_sec < 0 || (pdata->irqen & RTC_UF) ? | 315 | rtc_write(pdata->alrm_sec < 0 || (pdata->irqen & RTC_UF) ? |
316 | 0x80 : BIN2BCD(pdata->alrm_sec) & 0x7f, | 316 | 0x80 : bin2bcd(pdata->alrm_sec) & 0x7f, |
317 | RTC_ALARM_SEC); | 317 | RTC_ALARM_SEC); |
318 | rtc_write(rtc_read(RTC_CMD) | (pdata->irqen ? RTC_TIE : 0), RTC_CMD); | 318 | rtc_write(rtc_read(RTC_CMD) | (pdata->irqen ? RTC_TIE : 0), RTC_CMD); |
319 | rtc_read(RTC_CMD1); /* clear interrupts */ | 319 | rtc_read(RTC_CMD1); /* clear interrupts */ |
@@ -481,7 +481,6 @@ static struct bin_attribute ds1511_nvram_attr = { | |||
481 | .attr = { | 481 | .attr = { |
482 | .name = "nvram", | 482 | .name = "nvram", |
483 | .mode = S_IRUGO | S_IWUGO, | 483 | .mode = S_IRUGO | S_IWUGO, |
484 | .owner = THIS_MODULE, | ||
485 | }, | 484 | }, |
486 | .size = DS1511_RAM_MAX, | 485 | .size = DS1511_RAM_MAX, |
487 | .read = ds1511_nvram_read, | 486 | .read = ds1511_nvram_read, |
diff --git a/drivers/rtc/rtc-ds1553.c b/drivers/rtc/rtc-ds1553.c index 4ef59285b489..b9475cd20210 100644 --- a/drivers/rtc/rtc-ds1553.c +++ b/drivers/rtc/rtc-ds1553.c | |||
@@ -78,17 +78,17 @@ static int ds1553_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
78 | void __iomem *ioaddr = pdata->ioaddr; | 78 | void __iomem *ioaddr = pdata->ioaddr; |
79 | u8 century; | 79 | u8 century; |
80 | 80 | ||
81 | century = BIN2BCD((tm->tm_year + 1900) / 100); | 81 | century = bin2bcd((tm->tm_year + 1900) / 100); |
82 | 82 | ||
83 | writeb(RTC_WRITE, pdata->ioaddr + RTC_CONTROL); | 83 | writeb(RTC_WRITE, pdata->ioaddr + RTC_CONTROL); |
84 | 84 | ||
85 | writeb(BIN2BCD(tm->tm_year % 100), ioaddr + RTC_YEAR); | 85 | writeb(bin2bcd(tm->tm_year % 100), ioaddr + RTC_YEAR); |
86 | writeb(BIN2BCD(tm->tm_mon + 1), ioaddr + RTC_MONTH); | 86 | writeb(bin2bcd(tm->tm_mon + 1), ioaddr + RTC_MONTH); |
87 | writeb(BIN2BCD(tm->tm_wday) & RTC_DAY_MASK, ioaddr + RTC_DAY); | 87 | writeb(bin2bcd(tm->tm_wday) & RTC_DAY_MASK, ioaddr + RTC_DAY); |
88 | writeb(BIN2BCD(tm->tm_mday), ioaddr + RTC_DATE); | 88 | writeb(bin2bcd(tm->tm_mday), ioaddr + RTC_DATE); |
89 | writeb(BIN2BCD(tm->tm_hour), ioaddr + RTC_HOURS); | 89 | writeb(bin2bcd(tm->tm_hour), ioaddr + RTC_HOURS); |
90 | writeb(BIN2BCD(tm->tm_min), ioaddr + RTC_MINUTES); | 90 | writeb(bin2bcd(tm->tm_min), ioaddr + RTC_MINUTES); |
91 | writeb(BIN2BCD(tm->tm_sec) & RTC_SECONDS_MASK, ioaddr + RTC_SECONDS); | 91 | writeb(bin2bcd(tm->tm_sec) & RTC_SECONDS_MASK, ioaddr + RTC_SECONDS); |
92 | 92 | ||
93 | /* RTC_CENTURY and RTC_CONTROL share same register */ | 93 | /* RTC_CENTURY and RTC_CONTROL share same register */ |
94 | writeb(RTC_WRITE | (century & RTC_CENTURY_MASK), ioaddr + RTC_CENTURY); | 94 | writeb(RTC_WRITE | (century & RTC_CENTURY_MASK), ioaddr + RTC_CENTURY); |
@@ -118,14 +118,14 @@ static int ds1553_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
118 | year = readb(ioaddr + RTC_YEAR); | 118 | year = readb(ioaddr + RTC_YEAR); |
119 | century = readb(ioaddr + RTC_CENTURY) & RTC_CENTURY_MASK; | 119 | century = readb(ioaddr + RTC_CENTURY) & RTC_CENTURY_MASK; |
120 | writeb(0, ioaddr + RTC_CONTROL); | 120 | writeb(0, ioaddr + RTC_CONTROL); |
121 | tm->tm_sec = BCD2BIN(second); | 121 | tm->tm_sec = bcd2bin(second); |
122 | tm->tm_min = BCD2BIN(minute); | 122 | tm->tm_min = bcd2bin(minute); |
123 | tm->tm_hour = BCD2BIN(hour); | 123 | tm->tm_hour = bcd2bin(hour); |
124 | tm->tm_mday = BCD2BIN(day); | 124 | tm->tm_mday = bcd2bin(day); |
125 | tm->tm_wday = BCD2BIN(week); | 125 | tm->tm_wday = bcd2bin(week); |
126 | tm->tm_mon = BCD2BIN(month) - 1; | 126 | tm->tm_mon = bcd2bin(month) - 1; |
127 | /* year is 1900 + tm->tm_year */ | 127 | /* year is 1900 + tm->tm_year */ |
128 | tm->tm_year = BCD2BIN(year) + BCD2BIN(century) * 100 - 1900; | 128 | tm->tm_year = bcd2bin(year) + bcd2bin(century) * 100 - 1900; |
129 | 129 | ||
130 | if (rtc_valid_tm(tm) < 0) { | 130 | if (rtc_valid_tm(tm) < 0) { |
131 | dev_err(dev, "retrieved date/time is not valid.\n"); | 131 | dev_err(dev, "retrieved date/time is not valid.\n"); |
@@ -141,16 +141,16 @@ static void ds1553_rtc_update_alarm(struct rtc_plat_data *pdata) | |||
141 | 141 | ||
142 | spin_lock_irqsave(&pdata->rtc->irq_lock, flags); | 142 | spin_lock_irqsave(&pdata->rtc->irq_lock, flags); |
143 | writeb(pdata->alrm_mday < 0 || (pdata->irqen & RTC_UF) ? | 143 | writeb(pdata->alrm_mday < 0 || (pdata->irqen & RTC_UF) ? |
144 | 0x80 : BIN2BCD(pdata->alrm_mday), | 144 | 0x80 : bin2bcd(pdata->alrm_mday), |
145 | ioaddr + RTC_DATE_ALARM); | 145 | ioaddr + RTC_DATE_ALARM); |
146 | writeb(pdata->alrm_hour < 0 || (pdata->irqen & RTC_UF) ? | 146 | writeb(pdata->alrm_hour < 0 || (pdata->irqen & RTC_UF) ? |
147 | 0x80 : BIN2BCD(pdata->alrm_hour), | 147 | 0x80 : bin2bcd(pdata->alrm_hour), |
148 | ioaddr + RTC_HOURS_ALARM); | 148 | ioaddr + RTC_HOURS_ALARM); |
149 | writeb(pdata->alrm_min < 0 || (pdata->irqen & RTC_UF) ? | 149 | writeb(pdata->alrm_min < 0 || (pdata->irqen & RTC_UF) ? |
150 | 0x80 : BIN2BCD(pdata->alrm_min), | 150 | 0x80 : bin2bcd(pdata->alrm_min), |
151 | ioaddr + RTC_MINUTES_ALARM); | 151 | ioaddr + RTC_MINUTES_ALARM); |
152 | writeb(pdata->alrm_sec < 0 || (pdata->irqen & RTC_UF) ? | 152 | writeb(pdata->alrm_sec < 0 || (pdata->irqen & RTC_UF) ? |
153 | 0x80 : BIN2BCD(pdata->alrm_sec), | 153 | 0x80 : bin2bcd(pdata->alrm_sec), |
154 | ioaddr + RTC_SECONDS_ALARM); | 154 | ioaddr + RTC_SECONDS_ALARM); |
155 | writeb(pdata->irqen ? RTC_INTS_AE : 0, ioaddr + RTC_INTERRUPTS); | 155 | writeb(pdata->irqen ? RTC_INTS_AE : 0, ioaddr + RTC_INTERRUPTS); |
156 | readb(ioaddr + RTC_FLAGS); /* clear interrupts */ | 156 | readb(ioaddr + RTC_FLAGS); /* clear interrupts */ |
diff --git a/drivers/rtc/rtc-ds1742.c b/drivers/rtc/rtc-ds1742.c index 24d35ede2dbf..8bc8501bffc8 100644 --- a/drivers/rtc/rtc-ds1742.c +++ b/drivers/rtc/rtc-ds1742.c | |||
@@ -66,17 +66,17 @@ static int ds1742_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
66 | void __iomem *ioaddr = pdata->ioaddr_rtc; | 66 | void __iomem *ioaddr = pdata->ioaddr_rtc; |
67 | u8 century; | 67 | u8 century; |
68 | 68 | ||
69 | century = BIN2BCD((tm->tm_year + 1900) / 100); | 69 | century = bin2bcd((tm->tm_year + 1900) / 100); |
70 | 70 | ||
71 | writeb(RTC_WRITE, ioaddr + RTC_CONTROL); | 71 | writeb(RTC_WRITE, ioaddr + RTC_CONTROL); |
72 | 72 | ||
73 | writeb(BIN2BCD(tm->tm_year % 100), ioaddr + RTC_YEAR); | 73 | writeb(bin2bcd(tm->tm_year % 100), ioaddr + RTC_YEAR); |
74 | writeb(BIN2BCD(tm->tm_mon + 1), ioaddr + RTC_MONTH); | 74 | writeb(bin2bcd(tm->tm_mon + 1), ioaddr + RTC_MONTH); |
75 | writeb(BIN2BCD(tm->tm_wday) & RTC_DAY_MASK, ioaddr + RTC_DAY); | 75 | writeb(bin2bcd(tm->tm_wday) & RTC_DAY_MASK, ioaddr + RTC_DAY); |
76 | writeb(BIN2BCD(tm->tm_mday), ioaddr + RTC_DATE); | 76 | writeb(bin2bcd(tm->tm_mday), ioaddr + RTC_DATE); |
77 | writeb(BIN2BCD(tm->tm_hour), ioaddr + RTC_HOURS); | 77 | writeb(bin2bcd(tm->tm_hour), ioaddr + RTC_HOURS); |
78 | writeb(BIN2BCD(tm->tm_min), ioaddr + RTC_MINUTES); | 78 | writeb(bin2bcd(tm->tm_min), ioaddr + RTC_MINUTES); |
79 | writeb(BIN2BCD(tm->tm_sec) & RTC_SECONDS_MASK, ioaddr + RTC_SECONDS); | 79 | writeb(bin2bcd(tm->tm_sec) & RTC_SECONDS_MASK, ioaddr + RTC_SECONDS); |
80 | 80 | ||
81 | /* RTC_CENTURY and RTC_CONTROL share same register */ | 81 | /* RTC_CENTURY and RTC_CONTROL share same register */ |
82 | writeb(RTC_WRITE | (century & RTC_CENTURY_MASK), ioaddr + RTC_CENTURY); | 82 | writeb(RTC_WRITE | (century & RTC_CENTURY_MASK), ioaddr + RTC_CENTURY); |
@@ -106,14 +106,14 @@ static int ds1742_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
106 | year = readb(ioaddr + RTC_YEAR); | 106 | year = readb(ioaddr + RTC_YEAR); |
107 | century = readb(ioaddr + RTC_CENTURY) & RTC_CENTURY_MASK; | 107 | century = readb(ioaddr + RTC_CENTURY) & RTC_CENTURY_MASK; |
108 | writeb(0, ioaddr + RTC_CONTROL); | 108 | writeb(0, ioaddr + RTC_CONTROL); |
109 | tm->tm_sec = BCD2BIN(second); | 109 | tm->tm_sec = bcd2bin(second); |
110 | tm->tm_min = BCD2BIN(minute); | 110 | tm->tm_min = bcd2bin(minute); |
111 | tm->tm_hour = BCD2BIN(hour); | 111 | tm->tm_hour = bcd2bin(hour); |
112 | tm->tm_mday = BCD2BIN(day); | 112 | tm->tm_mday = bcd2bin(day); |
113 | tm->tm_wday = BCD2BIN(week); | 113 | tm->tm_wday = bcd2bin(week); |
114 | tm->tm_mon = BCD2BIN(month) - 1; | 114 | tm->tm_mon = bcd2bin(month) - 1; |
115 | /* year is 1900 + tm->tm_year */ | 115 | /* year is 1900 + tm->tm_year */ |
116 | tm->tm_year = BCD2BIN(year) + BCD2BIN(century) * 100 - 1900; | 116 | tm->tm_year = bcd2bin(year) + bcd2bin(century) * 100 - 1900; |
117 | 117 | ||
118 | if (rtc_valid_tm(tm) < 0) { | 118 | if (rtc_valid_tm(tm) < 0) { |
119 | dev_err(dev, "retrieved date/time is not valid.\n"); | 119 | dev_err(dev, "retrieved date/time is not valid.\n"); |
diff --git a/drivers/rtc/rtc-fm3130.c b/drivers/rtc/rtc-fm3130.c index abfdfcbaa059..3a7be11cc6b9 100644 --- a/drivers/rtc/rtc-fm3130.c +++ b/drivers/rtc/rtc-fm3130.c | |||
@@ -131,17 +131,17 @@ static int fm3130_get_time(struct device *dev, struct rtc_time *t) | |||
131 | fm3130->regs[0xc], fm3130->regs[0xd], | 131 | fm3130->regs[0xc], fm3130->regs[0xd], |
132 | fm3130->regs[0xe]); | 132 | fm3130->regs[0xe]); |
133 | 133 | ||
134 | t->tm_sec = BCD2BIN(fm3130->regs[FM3130_RTC_SECONDS] & 0x7f); | 134 | t->tm_sec = bcd2bin(fm3130->regs[FM3130_RTC_SECONDS] & 0x7f); |
135 | t->tm_min = BCD2BIN(fm3130->regs[FM3130_RTC_MINUTES] & 0x7f); | 135 | t->tm_min = bcd2bin(fm3130->regs[FM3130_RTC_MINUTES] & 0x7f); |
136 | tmp = fm3130->regs[FM3130_RTC_HOURS] & 0x3f; | 136 | tmp = fm3130->regs[FM3130_RTC_HOURS] & 0x3f; |
137 | t->tm_hour = BCD2BIN(tmp); | 137 | t->tm_hour = bcd2bin(tmp); |
138 | t->tm_wday = BCD2BIN(fm3130->regs[FM3130_RTC_DAY] & 0x07) - 1; | 138 | t->tm_wday = bcd2bin(fm3130->regs[FM3130_RTC_DAY] & 0x07) - 1; |
139 | t->tm_mday = BCD2BIN(fm3130->regs[FM3130_RTC_DATE] & 0x3f); | 139 | t->tm_mday = bcd2bin(fm3130->regs[FM3130_RTC_DATE] & 0x3f); |
140 | tmp = fm3130->regs[FM3130_RTC_MONTHS] & 0x1f; | 140 | tmp = fm3130->regs[FM3130_RTC_MONTHS] & 0x1f; |
141 | t->tm_mon = BCD2BIN(tmp) - 1; | 141 | t->tm_mon = bcd2bin(tmp) - 1; |
142 | 142 | ||
143 | /* assume 20YY not 19YY, and ignore CF bit */ | 143 | /* assume 20YY not 19YY, and ignore CF bit */ |
144 | t->tm_year = BCD2BIN(fm3130->regs[FM3130_RTC_YEARS]) + 100; | 144 | t->tm_year = bcd2bin(fm3130->regs[FM3130_RTC_YEARS]) + 100; |
145 | 145 | ||
146 | dev_dbg(dev, "%s secs=%d, mins=%d, " | 146 | dev_dbg(dev, "%s secs=%d, mins=%d, " |
147 | "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n", | 147 | "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n", |
@@ -167,16 +167,16 @@ static int fm3130_set_time(struct device *dev, struct rtc_time *t) | |||
167 | t->tm_mon, t->tm_year, t->tm_wday); | 167 | t->tm_mon, t->tm_year, t->tm_wday); |
168 | 168 | ||
169 | /* first register addr */ | 169 | /* first register addr */ |
170 | buf[FM3130_RTC_SECONDS] = BIN2BCD(t->tm_sec); | 170 | buf[FM3130_RTC_SECONDS] = bin2bcd(t->tm_sec); |
171 | buf[FM3130_RTC_MINUTES] = BIN2BCD(t->tm_min); | 171 | buf[FM3130_RTC_MINUTES] = bin2bcd(t->tm_min); |
172 | buf[FM3130_RTC_HOURS] = BIN2BCD(t->tm_hour); | 172 | buf[FM3130_RTC_HOURS] = bin2bcd(t->tm_hour); |
173 | buf[FM3130_RTC_DAY] = BIN2BCD(t->tm_wday + 1); | 173 | buf[FM3130_RTC_DAY] = bin2bcd(t->tm_wday + 1); |
174 | buf[FM3130_RTC_DATE] = BIN2BCD(t->tm_mday); | 174 | buf[FM3130_RTC_DATE] = bin2bcd(t->tm_mday); |
175 | buf[FM3130_RTC_MONTHS] = BIN2BCD(t->tm_mon + 1); | 175 | buf[FM3130_RTC_MONTHS] = bin2bcd(t->tm_mon + 1); |
176 | 176 | ||
177 | /* assume 20YY not 19YY */ | 177 | /* assume 20YY not 19YY */ |
178 | tmp = t->tm_year - 100; | 178 | tmp = t->tm_year - 100; |
179 | buf[FM3130_RTC_YEARS] = BIN2BCD(tmp); | 179 | buf[FM3130_RTC_YEARS] = bin2bcd(tmp); |
180 | 180 | ||
181 | dev_dbg(dev, "%s: %02x %02x %02x %02x %02x %02x %02x" | 181 | dev_dbg(dev, "%s: %02x %02x %02x %02x %02x %02x %02x" |
182 | "%02x %02x %02x %02x %02x %02x %02x %02x\n", | 182 | "%02x %02x %02x %02x %02x %02x %02x %02x\n", |
@@ -222,11 +222,11 @@ static int fm3130_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
222 | fm3130->regs[FM3130_ALARM_MONTHS]); | 222 | fm3130->regs[FM3130_ALARM_MONTHS]); |
223 | 223 | ||
224 | 224 | ||
225 | tm->tm_sec = BCD2BIN(fm3130->regs[FM3130_ALARM_SECONDS] & 0x7F); | 225 | tm->tm_sec = bcd2bin(fm3130->regs[FM3130_ALARM_SECONDS] & 0x7F); |
226 | tm->tm_min = BCD2BIN(fm3130->regs[FM3130_ALARM_MINUTES] & 0x7F); | 226 | tm->tm_min = bcd2bin(fm3130->regs[FM3130_ALARM_MINUTES] & 0x7F); |
227 | tm->tm_hour = BCD2BIN(fm3130->regs[FM3130_ALARM_HOURS] & 0x3F); | 227 | tm->tm_hour = bcd2bin(fm3130->regs[FM3130_ALARM_HOURS] & 0x3F); |
228 | tm->tm_mday = BCD2BIN(fm3130->regs[FM3130_ALARM_DATE] & 0x3F); | 228 | tm->tm_mday = bcd2bin(fm3130->regs[FM3130_ALARM_DATE] & 0x3F); |
229 | tm->tm_mon = BCD2BIN(fm3130->regs[FM3130_ALARM_MONTHS] & 0x1F); | 229 | tm->tm_mon = bcd2bin(fm3130->regs[FM3130_ALARM_MONTHS] & 0x1F); |
230 | if (tm->tm_mon > 0) | 230 | if (tm->tm_mon > 0) |
231 | tm->tm_mon -= 1; /* RTC is 1-12, tm_mon is 0-11 */ | 231 | tm->tm_mon -= 1; /* RTC is 1-12, tm_mon is 0-11 */ |
232 | dev_dbg(dev, "%s secs=%d, mins=%d, " | 232 | dev_dbg(dev, "%s secs=%d, mins=%d, " |
@@ -252,23 +252,23 @@ static int fm3130_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
252 | 252 | ||
253 | if (tm->tm_sec != -1) | 253 | if (tm->tm_sec != -1) |
254 | fm3130->regs[FM3130_ALARM_SECONDS] = | 254 | fm3130->regs[FM3130_ALARM_SECONDS] = |
255 | BIN2BCD(tm->tm_sec) | 0x80; | 255 | bin2bcd(tm->tm_sec) | 0x80; |
256 | 256 | ||
257 | if (tm->tm_min != -1) | 257 | if (tm->tm_min != -1) |
258 | fm3130->regs[FM3130_ALARM_MINUTES] = | 258 | fm3130->regs[FM3130_ALARM_MINUTES] = |
259 | BIN2BCD(tm->tm_min) | 0x80; | 259 | bin2bcd(tm->tm_min) | 0x80; |
260 | 260 | ||
261 | if (tm->tm_hour != -1) | 261 | if (tm->tm_hour != -1) |
262 | fm3130->regs[FM3130_ALARM_HOURS] = | 262 | fm3130->regs[FM3130_ALARM_HOURS] = |
263 | BIN2BCD(tm->tm_hour) | 0x80; | 263 | bin2bcd(tm->tm_hour) | 0x80; |
264 | 264 | ||
265 | if (tm->tm_mday != -1) | 265 | if (tm->tm_mday != -1) |
266 | fm3130->regs[FM3130_ALARM_DATE] = | 266 | fm3130->regs[FM3130_ALARM_DATE] = |
267 | BIN2BCD(tm->tm_mday) | 0x80; | 267 | bin2bcd(tm->tm_mday) | 0x80; |
268 | 268 | ||
269 | if (tm->tm_mon != -1) | 269 | if (tm->tm_mon != -1) |
270 | fm3130->regs[FM3130_ALARM_MONTHS] = | 270 | fm3130->regs[FM3130_ALARM_MONTHS] = |
271 | BIN2BCD(tm->tm_mon + 1) | 0x80; | 271 | bin2bcd(tm->tm_mon + 1) | 0x80; |
272 | 272 | ||
273 | dev_dbg(dev, "alarm write %02x %02x %02x %02x %02x\n", | 273 | dev_dbg(dev, "alarm write %02x %02x %02x %02x %02x\n", |
274 | fm3130->regs[FM3130_ALARM_SECONDS], | 274 | fm3130->regs[FM3130_ALARM_SECONDS], |
@@ -414,18 +414,18 @@ static int __devinit fm3130_probe(struct i2c_client *client, | |||
414 | /* TODO */ | 414 | /* TODO */ |
415 | /* TODO need to sanity check alarm */ | 415 | /* TODO need to sanity check alarm */ |
416 | tmp = fm3130->regs[FM3130_RTC_SECONDS]; | 416 | tmp = fm3130->regs[FM3130_RTC_SECONDS]; |
417 | tmp = BCD2BIN(tmp & 0x7f); | 417 | tmp = bcd2bin(tmp & 0x7f); |
418 | if (tmp > 60) | 418 | if (tmp > 60) |
419 | goto exit_bad; | 419 | goto exit_bad; |
420 | tmp = BCD2BIN(fm3130->regs[FM3130_RTC_MINUTES] & 0x7f); | 420 | tmp = bcd2bin(fm3130->regs[FM3130_RTC_MINUTES] & 0x7f); |
421 | if (tmp > 60) | 421 | if (tmp > 60) |
422 | goto exit_bad; | 422 | goto exit_bad; |
423 | 423 | ||
424 | tmp = BCD2BIN(fm3130->regs[FM3130_RTC_DATE] & 0x3f); | 424 | tmp = bcd2bin(fm3130->regs[FM3130_RTC_DATE] & 0x3f); |
425 | if (tmp == 0 || tmp > 31) | 425 | if (tmp == 0 || tmp > 31) |
426 | goto exit_bad; | 426 | goto exit_bad; |
427 | 427 | ||
428 | tmp = BCD2BIN(fm3130->regs[FM3130_RTC_MONTHS] & 0x1f); | 428 | tmp = bcd2bin(fm3130->regs[FM3130_RTC_MONTHS] & 0x1f); |
429 | if (tmp == 0 || tmp > 12) | 429 | if (tmp == 0 || tmp > 12) |
430 | goto exit_bad; | 430 | goto exit_bad; |
431 | 431 | ||
diff --git a/drivers/rtc/rtc-isl1208.c b/drivers/rtc/rtc-isl1208.c index a81adab6e515..2cd77ab8fc66 100644 --- a/drivers/rtc/rtc-isl1208.c +++ b/drivers/rtc/rtc-isl1208.c | |||
@@ -259,26 +259,26 @@ isl1208_i2c_read_time(struct i2c_client *client, struct rtc_time *tm) | |||
259 | return sr; | 259 | return sr; |
260 | } | 260 | } |
261 | 261 | ||
262 | tm->tm_sec = BCD2BIN(regs[ISL1208_REG_SC]); | 262 | tm->tm_sec = bcd2bin(regs[ISL1208_REG_SC]); |
263 | tm->tm_min = BCD2BIN(regs[ISL1208_REG_MN]); | 263 | tm->tm_min = bcd2bin(regs[ISL1208_REG_MN]); |
264 | 264 | ||
265 | /* HR field has a more complex interpretation */ | 265 | /* HR field has a more complex interpretation */ |
266 | { | 266 | { |
267 | const u8 _hr = regs[ISL1208_REG_HR]; | 267 | const u8 _hr = regs[ISL1208_REG_HR]; |
268 | if (_hr & ISL1208_REG_HR_MIL) /* 24h format */ | 268 | if (_hr & ISL1208_REG_HR_MIL) /* 24h format */ |
269 | tm->tm_hour = BCD2BIN(_hr & 0x3f); | 269 | tm->tm_hour = bcd2bin(_hr & 0x3f); |
270 | else { | 270 | else { |
271 | /* 12h format */ | 271 | /* 12h format */ |
272 | tm->tm_hour = BCD2BIN(_hr & 0x1f); | 272 | tm->tm_hour = bcd2bin(_hr & 0x1f); |
273 | if (_hr & ISL1208_REG_HR_PM) /* PM flag set */ | 273 | if (_hr & ISL1208_REG_HR_PM) /* PM flag set */ |
274 | tm->tm_hour += 12; | 274 | tm->tm_hour += 12; |
275 | } | 275 | } |
276 | } | 276 | } |
277 | 277 | ||
278 | tm->tm_mday = BCD2BIN(regs[ISL1208_REG_DT]); | 278 | tm->tm_mday = bcd2bin(regs[ISL1208_REG_DT]); |
279 | tm->tm_mon = BCD2BIN(regs[ISL1208_REG_MO]) - 1; /* rtc starts at 1 */ | 279 | tm->tm_mon = bcd2bin(regs[ISL1208_REG_MO]) - 1; /* rtc starts at 1 */ |
280 | tm->tm_year = BCD2BIN(regs[ISL1208_REG_YR]) + 100; | 280 | tm->tm_year = bcd2bin(regs[ISL1208_REG_YR]) + 100; |
281 | tm->tm_wday = BCD2BIN(regs[ISL1208_REG_DW]); | 281 | tm->tm_wday = bcd2bin(regs[ISL1208_REG_DW]); |
282 | 282 | ||
283 | return 0; | 283 | return 0; |
284 | } | 284 | } |
@@ -305,13 +305,13 @@ isl1208_i2c_read_alarm(struct i2c_client *client, struct rtc_wkalrm *alarm) | |||
305 | } | 305 | } |
306 | 306 | ||
307 | /* MSB of each alarm register is an enable bit */ | 307 | /* MSB of each alarm register is an enable bit */ |
308 | tm->tm_sec = BCD2BIN(regs[ISL1208_REG_SCA - ISL1208_REG_SCA] & 0x7f); | 308 | tm->tm_sec = bcd2bin(regs[ISL1208_REG_SCA - ISL1208_REG_SCA] & 0x7f); |
309 | tm->tm_min = BCD2BIN(regs[ISL1208_REG_MNA - ISL1208_REG_SCA] & 0x7f); | 309 | tm->tm_min = bcd2bin(regs[ISL1208_REG_MNA - ISL1208_REG_SCA] & 0x7f); |
310 | tm->tm_hour = BCD2BIN(regs[ISL1208_REG_HRA - ISL1208_REG_SCA] & 0x3f); | 310 | tm->tm_hour = bcd2bin(regs[ISL1208_REG_HRA - ISL1208_REG_SCA] & 0x3f); |
311 | tm->tm_mday = BCD2BIN(regs[ISL1208_REG_DTA - ISL1208_REG_SCA] & 0x3f); | 311 | tm->tm_mday = bcd2bin(regs[ISL1208_REG_DTA - ISL1208_REG_SCA] & 0x3f); |
312 | tm->tm_mon = | 312 | tm->tm_mon = |
313 | BCD2BIN(regs[ISL1208_REG_MOA - ISL1208_REG_SCA] & 0x1f) - 1; | 313 | bcd2bin(regs[ISL1208_REG_MOA - ISL1208_REG_SCA] & 0x1f) - 1; |
314 | tm->tm_wday = BCD2BIN(regs[ISL1208_REG_DWA - ISL1208_REG_SCA] & 0x03); | 314 | tm->tm_wday = bcd2bin(regs[ISL1208_REG_DWA - ISL1208_REG_SCA] & 0x03); |
315 | 315 | ||
316 | return 0; | 316 | return 0; |
317 | } | 317 | } |
@@ -328,15 +328,15 @@ isl1208_i2c_set_time(struct i2c_client *client, struct rtc_time const *tm) | |||
328 | int sr; | 328 | int sr; |
329 | u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, }; | 329 | u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, }; |
330 | 330 | ||
331 | regs[ISL1208_REG_SC] = BIN2BCD(tm->tm_sec); | 331 | regs[ISL1208_REG_SC] = bin2bcd(tm->tm_sec); |
332 | regs[ISL1208_REG_MN] = BIN2BCD(tm->tm_min); | 332 | regs[ISL1208_REG_MN] = bin2bcd(tm->tm_min); |
333 | regs[ISL1208_REG_HR] = BIN2BCD(tm->tm_hour) | ISL1208_REG_HR_MIL; | 333 | regs[ISL1208_REG_HR] = bin2bcd(tm->tm_hour) | ISL1208_REG_HR_MIL; |
334 | 334 | ||
335 | regs[ISL1208_REG_DT] = BIN2BCD(tm->tm_mday); | 335 | regs[ISL1208_REG_DT] = bin2bcd(tm->tm_mday); |
336 | regs[ISL1208_REG_MO] = BIN2BCD(tm->tm_mon + 1); | 336 | regs[ISL1208_REG_MO] = bin2bcd(tm->tm_mon + 1); |
337 | regs[ISL1208_REG_YR] = BIN2BCD(tm->tm_year - 100); | 337 | regs[ISL1208_REG_YR] = bin2bcd(tm->tm_year - 100); |
338 | 338 | ||
339 | regs[ISL1208_REG_DW] = BIN2BCD(tm->tm_wday & 7); | 339 | regs[ISL1208_REG_DW] = bin2bcd(tm->tm_wday & 7); |
340 | 340 | ||
341 | sr = isl1208_i2c_get_sr(client); | 341 | sr = isl1208_i2c_get_sr(client); |
342 | if (sr < 0) { | 342 | if (sr < 0) { |
diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c index 470fb2d29545..893f7dece239 100644 --- a/drivers/rtc/rtc-m41t80.c +++ b/drivers/rtc/rtc-m41t80.c | |||
@@ -110,15 +110,15 @@ static int m41t80_get_datetime(struct i2c_client *client, | |||
110 | return -EIO; | 110 | return -EIO; |
111 | } | 111 | } |
112 | 112 | ||
113 | tm->tm_sec = BCD2BIN(buf[M41T80_REG_SEC] & 0x7f); | 113 | tm->tm_sec = bcd2bin(buf[M41T80_REG_SEC] & 0x7f); |
114 | tm->tm_min = BCD2BIN(buf[M41T80_REG_MIN] & 0x7f); | 114 | tm->tm_min = bcd2bin(buf[M41T80_REG_MIN] & 0x7f); |
115 | tm->tm_hour = BCD2BIN(buf[M41T80_REG_HOUR] & 0x3f); | 115 | tm->tm_hour = bcd2bin(buf[M41T80_REG_HOUR] & 0x3f); |
116 | tm->tm_mday = BCD2BIN(buf[M41T80_REG_DAY] & 0x3f); | 116 | tm->tm_mday = bcd2bin(buf[M41T80_REG_DAY] & 0x3f); |
117 | tm->tm_wday = buf[M41T80_REG_WDAY] & 0x07; | 117 | tm->tm_wday = buf[M41T80_REG_WDAY] & 0x07; |
118 | tm->tm_mon = BCD2BIN(buf[M41T80_REG_MON] & 0x1f) - 1; | 118 | tm->tm_mon = bcd2bin(buf[M41T80_REG_MON] & 0x1f) - 1; |
119 | 119 | ||
120 | /* assume 20YY not 19YY, and ignore the Century Bit */ | 120 | /* assume 20YY not 19YY, and ignore the Century Bit */ |
121 | tm->tm_year = BCD2BIN(buf[M41T80_REG_YEAR]) + 100; | 121 | tm->tm_year = bcd2bin(buf[M41T80_REG_YEAR]) + 100; |
122 | return 0; | 122 | return 0; |
123 | } | 123 | } |
124 | 124 | ||
@@ -161,19 +161,19 @@ static int m41t80_set_datetime(struct i2c_client *client, struct rtc_time *tm) | |||
161 | /* Merge time-data and register flags into buf[0..7] */ | 161 | /* Merge time-data and register flags into buf[0..7] */ |
162 | buf[M41T80_REG_SSEC] = 0; | 162 | buf[M41T80_REG_SSEC] = 0; |
163 | buf[M41T80_REG_SEC] = | 163 | buf[M41T80_REG_SEC] = |
164 | BIN2BCD(tm->tm_sec) | (buf[M41T80_REG_SEC] & ~0x7f); | 164 | bin2bcd(tm->tm_sec) | (buf[M41T80_REG_SEC] & ~0x7f); |
165 | buf[M41T80_REG_MIN] = | 165 | buf[M41T80_REG_MIN] = |
166 | BIN2BCD(tm->tm_min) | (buf[M41T80_REG_MIN] & ~0x7f); | 166 | bin2bcd(tm->tm_min) | (buf[M41T80_REG_MIN] & ~0x7f); |
167 | buf[M41T80_REG_HOUR] = | 167 | buf[M41T80_REG_HOUR] = |
168 | BIN2BCD(tm->tm_hour) | (buf[M41T80_REG_HOUR] & ~0x3f) ; | 168 | bin2bcd(tm->tm_hour) | (buf[M41T80_REG_HOUR] & ~0x3f) ; |
169 | buf[M41T80_REG_WDAY] = | 169 | buf[M41T80_REG_WDAY] = |
170 | (tm->tm_wday & 0x07) | (buf[M41T80_REG_WDAY] & ~0x07); | 170 | (tm->tm_wday & 0x07) | (buf[M41T80_REG_WDAY] & ~0x07); |
171 | buf[M41T80_REG_DAY] = | 171 | buf[M41T80_REG_DAY] = |
172 | BIN2BCD(tm->tm_mday) | (buf[M41T80_REG_DAY] & ~0x3f); | 172 | bin2bcd(tm->tm_mday) | (buf[M41T80_REG_DAY] & ~0x3f); |
173 | buf[M41T80_REG_MON] = | 173 | buf[M41T80_REG_MON] = |
174 | BIN2BCD(tm->tm_mon + 1) | (buf[M41T80_REG_MON] & ~0x1f); | 174 | bin2bcd(tm->tm_mon + 1) | (buf[M41T80_REG_MON] & ~0x1f); |
175 | /* assume 20YY not 19YY */ | 175 | /* assume 20YY not 19YY */ |
176 | buf[M41T80_REG_YEAR] = BIN2BCD(tm->tm_year % 100); | 176 | buf[M41T80_REG_YEAR] = bin2bcd(tm->tm_year % 100); |
177 | 177 | ||
178 | if (i2c_transfer(client->adapter, msgs, 1) != 1) { | 178 | if (i2c_transfer(client->adapter, msgs, 1) != 1) { |
179 | dev_err(&client->dev, "write error\n"); | 179 | dev_err(&client->dev, "write error\n"); |
@@ -288,15 +288,15 @@ static int m41t80_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *t) | |||
288 | 288 | ||
289 | wbuf[0] = M41T80_REG_ALARM_MON; /* offset into rtc's regs */ | 289 | wbuf[0] = M41T80_REG_ALARM_MON; /* offset into rtc's regs */ |
290 | reg[M41T80_REG_ALARM_SEC] |= t->time.tm_sec >= 0 ? | 290 | reg[M41T80_REG_ALARM_SEC] |= t->time.tm_sec >= 0 ? |
291 | BIN2BCD(t->time.tm_sec) : 0x80; | 291 | bin2bcd(t->time.tm_sec) : 0x80; |
292 | reg[M41T80_REG_ALARM_MIN] |= t->time.tm_min >= 0 ? | 292 | reg[M41T80_REG_ALARM_MIN] |= t->time.tm_min >= 0 ? |
293 | BIN2BCD(t->time.tm_min) : 0x80; | 293 | bin2bcd(t->time.tm_min) : 0x80; |
294 | reg[M41T80_REG_ALARM_HOUR] |= t->time.tm_hour >= 0 ? | 294 | reg[M41T80_REG_ALARM_HOUR] |= t->time.tm_hour >= 0 ? |
295 | BIN2BCD(t->time.tm_hour) : 0x80; | 295 | bin2bcd(t->time.tm_hour) : 0x80; |
296 | reg[M41T80_REG_ALARM_DAY] |= t->time.tm_mday >= 0 ? | 296 | reg[M41T80_REG_ALARM_DAY] |= t->time.tm_mday >= 0 ? |
297 | BIN2BCD(t->time.tm_mday) : 0x80; | 297 | bin2bcd(t->time.tm_mday) : 0x80; |
298 | if (t->time.tm_mon >= 0) | 298 | if (t->time.tm_mon >= 0) |
299 | reg[M41T80_REG_ALARM_MON] |= BIN2BCD(t->time.tm_mon + 1); | 299 | reg[M41T80_REG_ALARM_MON] |= bin2bcd(t->time.tm_mon + 1); |
300 | else | 300 | else |
301 | reg[M41T80_REG_ALARM_DAY] |= 0x40; | 301 | reg[M41T80_REG_ALARM_DAY] |= 0x40; |
302 | 302 | ||
@@ -347,15 +347,15 @@ static int m41t80_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *t) | |||
347 | t->time.tm_mday = -1; | 347 | t->time.tm_mday = -1; |
348 | t->time.tm_mon = -1; | 348 | t->time.tm_mon = -1; |
349 | if (!(reg[M41T80_REG_ALARM_SEC] & 0x80)) | 349 | if (!(reg[M41T80_REG_ALARM_SEC] & 0x80)) |
350 | t->time.tm_sec = BCD2BIN(reg[M41T80_REG_ALARM_SEC] & 0x7f); | 350 | t->time.tm_sec = bcd2bin(reg[M41T80_REG_ALARM_SEC] & 0x7f); |
351 | if (!(reg[M41T80_REG_ALARM_MIN] & 0x80)) | 351 | if (!(reg[M41T80_REG_ALARM_MIN] & 0x80)) |
352 | t->time.tm_min = BCD2BIN(reg[M41T80_REG_ALARM_MIN] & 0x7f); | 352 | t->time.tm_min = bcd2bin(reg[M41T80_REG_ALARM_MIN] & 0x7f); |
353 | if (!(reg[M41T80_REG_ALARM_HOUR] & 0x80)) | 353 | if (!(reg[M41T80_REG_ALARM_HOUR] & 0x80)) |
354 | t->time.tm_hour = BCD2BIN(reg[M41T80_REG_ALARM_HOUR] & 0x3f); | 354 | t->time.tm_hour = bcd2bin(reg[M41T80_REG_ALARM_HOUR] & 0x3f); |
355 | if (!(reg[M41T80_REG_ALARM_DAY] & 0x80)) | 355 | if (!(reg[M41T80_REG_ALARM_DAY] & 0x80)) |
356 | t->time.tm_mday = BCD2BIN(reg[M41T80_REG_ALARM_DAY] & 0x3f); | 356 | t->time.tm_mday = bcd2bin(reg[M41T80_REG_ALARM_DAY] & 0x3f); |
357 | if (!(reg[M41T80_REG_ALARM_DAY] & 0x40)) | 357 | if (!(reg[M41T80_REG_ALARM_DAY] & 0x40)) |
358 | t->time.tm_mon = BCD2BIN(reg[M41T80_REG_ALARM_MON] & 0x1f) - 1; | 358 | t->time.tm_mon = bcd2bin(reg[M41T80_REG_ALARM_MON] & 0x1f) - 1; |
359 | t->time.tm_year = -1; | 359 | t->time.tm_year = -1; |
360 | t->time.tm_wday = -1; | 360 | t->time.tm_wday = -1; |
361 | t->time.tm_yday = -1; | 361 | t->time.tm_yday = -1; |
diff --git a/drivers/rtc/rtc-m41t94.c b/drivers/rtc/rtc-m41t94.c index 9b19499c829e..c3a18c58daf6 100644 --- a/drivers/rtc/rtc-m41t94.c +++ b/drivers/rtc/rtc-m41t94.c | |||
@@ -41,17 +41,17 @@ static int m41t94_set_time(struct device *dev, struct rtc_time *tm) | |||
41 | tm->tm_mon, tm->tm_year, tm->tm_wday); | 41 | tm->tm_mon, tm->tm_year, tm->tm_wday); |
42 | 42 | ||
43 | buf[0] = 0x80 | M41T94_REG_SECONDS; /* write time + date */ | 43 | buf[0] = 0x80 | M41T94_REG_SECONDS; /* write time + date */ |
44 | buf[M41T94_REG_SECONDS] = BIN2BCD(tm->tm_sec); | 44 | buf[M41T94_REG_SECONDS] = bin2bcd(tm->tm_sec); |
45 | buf[M41T94_REG_MINUTES] = BIN2BCD(tm->tm_min); | 45 | buf[M41T94_REG_MINUTES] = bin2bcd(tm->tm_min); |
46 | buf[M41T94_REG_HOURS] = BIN2BCD(tm->tm_hour); | 46 | buf[M41T94_REG_HOURS] = bin2bcd(tm->tm_hour); |
47 | buf[M41T94_REG_WDAY] = BIN2BCD(tm->tm_wday + 1); | 47 | buf[M41T94_REG_WDAY] = bin2bcd(tm->tm_wday + 1); |
48 | buf[M41T94_REG_DAY] = BIN2BCD(tm->tm_mday); | 48 | buf[M41T94_REG_DAY] = bin2bcd(tm->tm_mday); |
49 | buf[M41T94_REG_MONTH] = BIN2BCD(tm->tm_mon + 1); | 49 | buf[M41T94_REG_MONTH] = bin2bcd(tm->tm_mon + 1); |
50 | 50 | ||
51 | buf[M41T94_REG_HOURS] |= M41T94_BIT_CEB; | 51 | buf[M41T94_REG_HOURS] |= M41T94_BIT_CEB; |
52 | if (tm->tm_year >= 100) | 52 | if (tm->tm_year >= 100) |
53 | buf[M41T94_REG_HOURS] |= M41T94_BIT_CB; | 53 | buf[M41T94_REG_HOURS] |= M41T94_BIT_CB; |
54 | buf[M41T94_REG_YEAR] = BIN2BCD(tm->tm_year % 100); | 54 | buf[M41T94_REG_YEAR] = bin2bcd(tm->tm_year % 100); |
55 | 55 | ||
56 | return spi_write(spi, buf, 8); | 56 | return spi_write(spi, buf, 8); |
57 | } | 57 | } |
@@ -82,14 +82,14 @@ static int m41t94_read_time(struct device *dev, struct rtc_time *tm) | |||
82 | spi_write(spi, buf, 2); | 82 | spi_write(spi, buf, 2); |
83 | } | 83 | } |
84 | 84 | ||
85 | tm->tm_sec = BCD2BIN(spi_w8r8(spi, M41T94_REG_SECONDS)); | 85 | tm->tm_sec = bcd2bin(spi_w8r8(spi, M41T94_REG_SECONDS)); |
86 | tm->tm_min = BCD2BIN(spi_w8r8(spi, M41T94_REG_MINUTES)); | 86 | tm->tm_min = bcd2bin(spi_w8r8(spi, M41T94_REG_MINUTES)); |
87 | hour = spi_w8r8(spi, M41T94_REG_HOURS); | 87 | hour = spi_w8r8(spi, M41T94_REG_HOURS); |
88 | tm->tm_hour = BCD2BIN(hour & 0x3f); | 88 | tm->tm_hour = bcd2bin(hour & 0x3f); |
89 | tm->tm_wday = BCD2BIN(spi_w8r8(spi, M41T94_REG_WDAY)) - 1; | 89 | tm->tm_wday = bcd2bin(spi_w8r8(spi, M41T94_REG_WDAY)) - 1; |
90 | tm->tm_mday = BCD2BIN(spi_w8r8(spi, M41T94_REG_DAY)); | 90 | tm->tm_mday = bcd2bin(spi_w8r8(spi, M41T94_REG_DAY)); |
91 | tm->tm_mon = BCD2BIN(spi_w8r8(spi, M41T94_REG_MONTH)) - 1; | 91 | tm->tm_mon = bcd2bin(spi_w8r8(spi, M41T94_REG_MONTH)) - 1; |
92 | tm->tm_year = BCD2BIN(spi_w8r8(spi, M41T94_REG_YEAR)); | 92 | tm->tm_year = bcd2bin(spi_w8r8(spi, M41T94_REG_YEAR)); |
93 | if ((hour & M41T94_BIT_CB) || !(hour & M41T94_BIT_CEB)) | 93 | if ((hour & M41T94_BIT_CB) || !(hour & M41T94_BIT_CEB)) |
94 | tm->tm_year += 100; | 94 | tm->tm_year += 100; |
95 | 95 | ||
diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c index ce4eff6a8d51..04b63dab6932 100644 --- a/drivers/rtc/rtc-m48t59.c +++ b/drivers/rtc/rtc-m48t59.c | |||
@@ -76,10 +76,10 @@ static int m48t59_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
76 | /* Issue the READ command */ | 76 | /* Issue the READ command */ |
77 | M48T59_SET_BITS(M48T59_CNTL_READ, M48T59_CNTL); | 77 | M48T59_SET_BITS(M48T59_CNTL_READ, M48T59_CNTL); |
78 | 78 | ||
79 | tm->tm_year = BCD2BIN(M48T59_READ(M48T59_YEAR)); | 79 | tm->tm_year = bcd2bin(M48T59_READ(M48T59_YEAR)); |
80 | /* tm_mon is 0-11 */ | 80 | /* tm_mon is 0-11 */ |
81 | tm->tm_mon = BCD2BIN(M48T59_READ(M48T59_MONTH)) - 1; | 81 | tm->tm_mon = bcd2bin(M48T59_READ(M48T59_MONTH)) - 1; |
82 | tm->tm_mday = BCD2BIN(M48T59_READ(M48T59_MDAY)); | 82 | tm->tm_mday = bcd2bin(M48T59_READ(M48T59_MDAY)); |
83 | 83 | ||
84 | val = M48T59_READ(M48T59_WDAY); | 84 | val = M48T59_READ(M48T59_WDAY); |
85 | if ((pdata->type == M48T59RTC_TYPE_M48T59) && | 85 | if ((pdata->type == M48T59RTC_TYPE_M48T59) && |
@@ -88,10 +88,10 @@ static int m48t59_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
88 | tm->tm_year += 100; /* one century */ | 88 | tm->tm_year += 100; /* one century */ |
89 | } | 89 | } |
90 | 90 | ||
91 | tm->tm_wday = BCD2BIN(val & 0x07); | 91 | tm->tm_wday = bcd2bin(val & 0x07); |
92 | tm->tm_hour = BCD2BIN(M48T59_READ(M48T59_HOUR) & 0x3F); | 92 | tm->tm_hour = bcd2bin(M48T59_READ(M48T59_HOUR) & 0x3F); |
93 | tm->tm_min = BCD2BIN(M48T59_READ(M48T59_MIN) & 0x7F); | 93 | tm->tm_min = bcd2bin(M48T59_READ(M48T59_MIN) & 0x7F); |
94 | tm->tm_sec = BCD2BIN(M48T59_READ(M48T59_SEC) & 0x7F); | 94 | tm->tm_sec = bcd2bin(M48T59_READ(M48T59_SEC) & 0x7F); |
95 | 95 | ||
96 | /* Clear the READ bit */ | 96 | /* Clear the READ bit */ |
97 | M48T59_CLEAR_BITS(M48T59_CNTL_READ, M48T59_CNTL); | 97 | M48T59_CLEAR_BITS(M48T59_CNTL_READ, M48T59_CNTL); |
@@ -119,17 +119,17 @@ static int m48t59_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
119 | /* Issue the WRITE command */ | 119 | /* Issue the WRITE command */ |
120 | M48T59_SET_BITS(M48T59_CNTL_WRITE, M48T59_CNTL); | 120 | M48T59_SET_BITS(M48T59_CNTL_WRITE, M48T59_CNTL); |
121 | 121 | ||
122 | M48T59_WRITE((BIN2BCD(tm->tm_sec) & 0x7F), M48T59_SEC); | 122 | M48T59_WRITE((bin2bcd(tm->tm_sec) & 0x7F), M48T59_SEC); |
123 | M48T59_WRITE((BIN2BCD(tm->tm_min) & 0x7F), M48T59_MIN); | 123 | M48T59_WRITE((bin2bcd(tm->tm_min) & 0x7F), M48T59_MIN); |
124 | M48T59_WRITE((BIN2BCD(tm->tm_hour) & 0x3F), M48T59_HOUR); | 124 | M48T59_WRITE((bin2bcd(tm->tm_hour) & 0x3F), M48T59_HOUR); |
125 | M48T59_WRITE((BIN2BCD(tm->tm_mday) & 0x3F), M48T59_MDAY); | 125 | M48T59_WRITE((bin2bcd(tm->tm_mday) & 0x3F), M48T59_MDAY); |
126 | /* tm_mon is 0-11 */ | 126 | /* tm_mon is 0-11 */ |
127 | M48T59_WRITE((BIN2BCD(tm->tm_mon + 1) & 0x1F), M48T59_MONTH); | 127 | M48T59_WRITE((bin2bcd(tm->tm_mon + 1) & 0x1F), M48T59_MONTH); |
128 | M48T59_WRITE(BIN2BCD(tm->tm_year % 100), M48T59_YEAR); | 128 | M48T59_WRITE(bin2bcd(tm->tm_year % 100), M48T59_YEAR); |
129 | 129 | ||
130 | if (pdata->type == M48T59RTC_TYPE_M48T59 && (tm->tm_year / 100)) | 130 | if (pdata->type == M48T59RTC_TYPE_M48T59 && (tm->tm_year / 100)) |
131 | val = (M48T59_WDAY_CEB | M48T59_WDAY_CB); | 131 | val = (M48T59_WDAY_CEB | M48T59_WDAY_CB); |
132 | val |= (BIN2BCD(tm->tm_wday) & 0x07); | 132 | val |= (bin2bcd(tm->tm_wday) & 0x07); |
133 | M48T59_WRITE(val, M48T59_WDAY); | 133 | M48T59_WRITE(val, M48T59_WDAY); |
134 | 134 | ||
135 | /* Clear the WRITE bit */ | 135 | /* Clear the WRITE bit */ |
@@ -158,18 +158,18 @@ static int m48t59_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
158 | /* Issue the READ command */ | 158 | /* Issue the READ command */ |
159 | M48T59_SET_BITS(M48T59_CNTL_READ, M48T59_CNTL); | 159 | M48T59_SET_BITS(M48T59_CNTL_READ, M48T59_CNTL); |
160 | 160 | ||
161 | tm->tm_year = BCD2BIN(M48T59_READ(M48T59_YEAR)); | 161 | tm->tm_year = bcd2bin(M48T59_READ(M48T59_YEAR)); |
162 | /* tm_mon is 0-11 */ | 162 | /* tm_mon is 0-11 */ |
163 | tm->tm_mon = BCD2BIN(M48T59_READ(M48T59_MONTH)) - 1; | 163 | tm->tm_mon = bcd2bin(M48T59_READ(M48T59_MONTH)) - 1; |
164 | 164 | ||
165 | val = M48T59_READ(M48T59_WDAY); | 165 | val = M48T59_READ(M48T59_WDAY); |
166 | if ((val & M48T59_WDAY_CEB) && (val & M48T59_WDAY_CB)) | 166 | if ((val & M48T59_WDAY_CEB) && (val & M48T59_WDAY_CB)) |
167 | tm->tm_year += 100; /* one century */ | 167 | tm->tm_year += 100; /* one century */ |
168 | 168 | ||
169 | tm->tm_mday = BCD2BIN(M48T59_READ(M48T59_ALARM_DATE)); | 169 | tm->tm_mday = bcd2bin(M48T59_READ(M48T59_ALARM_DATE)); |
170 | tm->tm_hour = BCD2BIN(M48T59_READ(M48T59_ALARM_HOUR)); | 170 | tm->tm_hour = bcd2bin(M48T59_READ(M48T59_ALARM_HOUR)); |
171 | tm->tm_min = BCD2BIN(M48T59_READ(M48T59_ALARM_MIN)); | 171 | tm->tm_min = bcd2bin(M48T59_READ(M48T59_ALARM_MIN)); |
172 | tm->tm_sec = BCD2BIN(M48T59_READ(M48T59_ALARM_SEC)); | 172 | tm->tm_sec = bcd2bin(M48T59_READ(M48T59_ALARM_SEC)); |
173 | 173 | ||
174 | /* Clear the READ bit */ | 174 | /* Clear the READ bit */ |
175 | M48T59_CLEAR_BITS(M48T59_CNTL_READ, M48T59_CNTL); | 175 | M48T59_CLEAR_BITS(M48T59_CNTL_READ, M48T59_CNTL); |
@@ -201,18 +201,18 @@ static int m48t59_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
201 | * 0xff means "always match" | 201 | * 0xff means "always match" |
202 | */ | 202 | */ |
203 | mday = tm->tm_mday; | 203 | mday = tm->tm_mday; |
204 | mday = (mday >= 1 && mday <= 31) ? BIN2BCD(mday) : 0xff; | 204 | mday = (mday >= 1 && mday <= 31) ? bin2bcd(mday) : 0xff; |
205 | if (mday == 0xff) | 205 | if (mday == 0xff) |
206 | mday = M48T59_READ(M48T59_MDAY); | 206 | mday = M48T59_READ(M48T59_MDAY); |
207 | 207 | ||
208 | hour = tm->tm_hour; | 208 | hour = tm->tm_hour; |
209 | hour = (hour < 24) ? BIN2BCD(hour) : 0x00; | 209 | hour = (hour < 24) ? bin2bcd(hour) : 0x00; |
210 | 210 | ||
211 | min = tm->tm_min; | 211 | min = tm->tm_min; |
212 | min = (min < 60) ? BIN2BCD(min) : 0x00; | 212 | min = (min < 60) ? bin2bcd(min) : 0x00; |
213 | 213 | ||
214 | sec = tm->tm_sec; | 214 | sec = tm->tm_sec; |
215 | sec = (sec < 60) ? BIN2BCD(sec) : 0x00; | 215 | sec = (sec < 60) ? bin2bcd(sec) : 0x00; |
216 | 216 | ||
217 | spin_lock_irqsave(&m48t59->lock, flags); | 217 | spin_lock_irqsave(&m48t59->lock, flags); |
218 | /* Issue the WRITE command */ | 218 | /* Issue the WRITE command */ |
@@ -360,7 +360,6 @@ static struct bin_attribute m48t59_nvram_attr = { | |||
360 | .attr = { | 360 | .attr = { |
361 | .name = "nvram", | 361 | .name = "nvram", |
362 | .mode = S_IRUGO | S_IWUSR, | 362 | .mode = S_IRUGO | S_IWUSR, |
363 | .owner = THIS_MODULE, | ||
364 | }, | 363 | }, |
365 | .read = m48t59_nvram_read, | 364 | .read = m48t59_nvram_read, |
366 | .write = m48t59_nvram_write, | 365 | .write = m48t59_nvram_write, |
diff --git a/drivers/rtc/rtc-m48t86.c b/drivers/rtc/rtc-m48t86.c index 3f7f99a5d96a..7c045cffa9ff 100644 --- a/drivers/rtc/rtc-m48t86.c +++ b/drivers/rtc/rtc-m48t86.c | |||
@@ -62,14 +62,14 @@ static int m48t86_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
62 | tm->tm_wday = ops->readbyte(M48T86_REG_DOW); | 62 | tm->tm_wday = ops->readbyte(M48T86_REG_DOW); |
63 | } else { | 63 | } else { |
64 | /* bcd mode */ | 64 | /* bcd mode */ |
65 | tm->tm_sec = BCD2BIN(ops->readbyte(M48T86_REG_SEC)); | 65 | tm->tm_sec = bcd2bin(ops->readbyte(M48T86_REG_SEC)); |
66 | tm->tm_min = BCD2BIN(ops->readbyte(M48T86_REG_MIN)); | 66 | tm->tm_min = bcd2bin(ops->readbyte(M48T86_REG_MIN)); |
67 | tm->tm_hour = BCD2BIN(ops->readbyte(M48T86_REG_HOUR) & 0x3F); | 67 | tm->tm_hour = bcd2bin(ops->readbyte(M48T86_REG_HOUR) & 0x3F); |
68 | tm->tm_mday = BCD2BIN(ops->readbyte(M48T86_REG_DOM)); | 68 | tm->tm_mday = bcd2bin(ops->readbyte(M48T86_REG_DOM)); |
69 | /* tm_mon is 0-11 */ | 69 | /* tm_mon is 0-11 */ |
70 | tm->tm_mon = BCD2BIN(ops->readbyte(M48T86_REG_MONTH)) - 1; | 70 | tm->tm_mon = bcd2bin(ops->readbyte(M48T86_REG_MONTH)) - 1; |
71 | tm->tm_year = BCD2BIN(ops->readbyte(M48T86_REG_YEAR)) + 100; | 71 | tm->tm_year = bcd2bin(ops->readbyte(M48T86_REG_YEAR)) + 100; |
72 | tm->tm_wday = BCD2BIN(ops->readbyte(M48T86_REG_DOW)); | 72 | tm->tm_wday = bcd2bin(ops->readbyte(M48T86_REG_DOW)); |
73 | } | 73 | } |
74 | 74 | ||
75 | /* correct the hour if the clock is in 12h mode */ | 75 | /* correct the hour if the clock is in 12h mode */ |
@@ -103,13 +103,13 @@ static int m48t86_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
103 | ops->writebyte(tm->tm_wday, M48T86_REG_DOW); | 103 | ops->writebyte(tm->tm_wday, M48T86_REG_DOW); |
104 | } else { | 104 | } else { |
105 | /* bcd mode */ | 105 | /* bcd mode */ |
106 | ops->writebyte(BIN2BCD(tm->tm_sec), M48T86_REG_SEC); | 106 | ops->writebyte(bin2bcd(tm->tm_sec), M48T86_REG_SEC); |
107 | ops->writebyte(BIN2BCD(tm->tm_min), M48T86_REG_MIN); | 107 | ops->writebyte(bin2bcd(tm->tm_min), M48T86_REG_MIN); |
108 | ops->writebyte(BIN2BCD(tm->tm_hour), M48T86_REG_HOUR); | 108 | ops->writebyte(bin2bcd(tm->tm_hour), M48T86_REG_HOUR); |
109 | ops->writebyte(BIN2BCD(tm->tm_mday), M48T86_REG_DOM); | 109 | ops->writebyte(bin2bcd(tm->tm_mday), M48T86_REG_DOM); |
110 | ops->writebyte(BIN2BCD(tm->tm_mon + 1), M48T86_REG_MONTH); | 110 | ops->writebyte(bin2bcd(tm->tm_mon + 1), M48T86_REG_MONTH); |
111 | ops->writebyte(BIN2BCD(tm->tm_year % 100), M48T86_REG_YEAR); | 111 | ops->writebyte(bin2bcd(tm->tm_year % 100), M48T86_REG_YEAR); |
112 | ops->writebyte(BIN2BCD(tm->tm_wday), M48T86_REG_DOW); | 112 | ops->writebyte(bin2bcd(tm->tm_wday), M48T86_REG_DOW); |
113 | } | 113 | } |
114 | 114 | ||
115 | /* update ended */ | 115 | /* update ended */ |
diff --git a/drivers/rtc/rtc-max6900.c b/drivers/rtc/rtc-max6900.c index 12c9cd25cad8..80782798763f 100644 --- a/drivers/rtc/rtc-max6900.c +++ b/drivers/rtc/rtc-max6900.c | |||
@@ -150,14 +150,14 @@ static int max6900_i2c_read_time(struct i2c_client *client, struct rtc_time *tm) | |||
150 | if (rc < 0) | 150 | if (rc < 0) |
151 | return rc; | 151 | return rc; |
152 | 152 | ||
153 | tm->tm_sec = BCD2BIN(regs[MAX6900_REG_SC]); | 153 | tm->tm_sec = bcd2bin(regs[MAX6900_REG_SC]); |
154 | tm->tm_min = BCD2BIN(regs[MAX6900_REG_MN]); | 154 | tm->tm_min = bcd2bin(regs[MAX6900_REG_MN]); |
155 | tm->tm_hour = BCD2BIN(regs[MAX6900_REG_HR] & 0x3f); | 155 | tm->tm_hour = bcd2bin(regs[MAX6900_REG_HR] & 0x3f); |
156 | tm->tm_mday = BCD2BIN(regs[MAX6900_REG_DT]); | 156 | tm->tm_mday = bcd2bin(regs[MAX6900_REG_DT]); |
157 | tm->tm_mon = BCD2BIN(regs[MAX6900_REG_MO]) - 1; | 157 | tm->tm_mon = bcd2bin(regs[MAX6900_REG_MO]) - 1; |
158 | tm->tm_year = BCD2BIN(regs[MAX6900_REG_YR]) + | 158 | tm->tm_year = bcd2bin(regs[MAX6900_REG_YR]) + |
159 | BCD2BIN(regs[MAX6900_REG_CENTURY]) * 100 - 1900; | 159 | bcd2bin(regs[MAX6900_REG_CENTURY]) * 100 - 1900; |
160 | tm->tm_wday = BCD2BIN(regs[MAX6900_REG_DW]); | 160 | tm->tm_wday = bcd2bin(regs[MAX6900_REG_DW]); |
161 | 161 | ||
162 | return 0; | 162 | return 0; |
163 | } | 163 | } |
@@ -184,14 +184,14 @@ max6900_i2c_set_time(struct i2c_client *client, struct rtc_time const *tm) | |||
184 | if (rc < 0) | 184 | if (rc < 0) |
185 | return rc; | 185 | return rc; |
186 | 186 | ||
187 | regs[MAX6900_REG_SC] = BIN2BCD(tm->tm_sec); | 187 | regs[MAX6900_REG_SC] = bin2bcd(tm->tm_sec); |
188 | regs[MAX6900_REG_MN] = BIN2BCD(tm->tm_min); | 188 | regs[MAX6900_REG_MN] = bin2bcd(tm->tm_min); |
189 | regs[MAX6900_REG_HR] = BIN2BCD(tm->tm_hour); | 189 | regs[MAX6900_REG_HR] = bin2bcd(tm->tm_hour); |
190 | regs[MAX6900_REG_DT] = BIN2BCD(tm->tm_mday); | 190 | regs[MAX6900_REG_DT] = bin2bcd(tm->tm_mday); |
191 | regs[MAX6900_REG_MO] = BIN2BCD(tm->tm_mon + 1); | 191 | regs[MAX6900_REG_MO] = bin2bcd(tm->tm_mon + 1); |
192 | regs[MAX6900_REG_DW] = BIN2BCD(tm->tm_wday); | 192 | regs[MAX6900_REG_DW] = bin2bcd(tm->tm_wday); |
193 | regs[MAX6900_REG_YR] = BIN2BCD(tm->tm_year % 100); | 193 | regs[MAX6900_REG_YR] = bin2bcd(tm->tm_year % 100); |
194 | regs[MAX6900_REG_CENTURY] = BIN2BCD((tm->tm_year + 1900) / 100); | 194 | regs[MAX6900_REG_CENTURY] = bin2bcd((tm->tm_year + 1900) / 100); |
195 | /* set write protect */ | 195 | /* set write protect */ |
196 | regs[MAX6900_REG_CT] = MAX6900_REG_CT_WP; | 196 | regs[MAX6900_REG_CT] = MAX6900_REG_CT_WP; |
197 | 197 | ||
diff --git a/drivers/rtc/rtc-max6902.c b/drivers/rtc/rtc-max6902.c index 78b2551fb19d..2f6507df7b49 100644 --- a/drivers/rtc/rtc-max6902.c +++ b/drivers/rtc/rtc-max6902.c | |||
@@ -124,15 +124,15 @@ static int max6902_get_datetime(struct device *dev, struct rtc_time *dt) | |||
124 | 124 | ||
125 | /* The chip sends data in this order: | 125 | /* The chip sends data in this order: |
126 | * Seconds, Minutes, Hours, Date, Month, Day, Year */ | 126 | * Seconds, Minutes, Hours, Date, Month, Day, Year */ |
127 | dt->tm_sec = BCD2BIN(chip->buf[1]); | 127 | dt->tm_sec = bcd2bin(chip->buf[1]); |
128 | dt->tm_min = BCD2BIN(chip->buf[2]); | 128 | dt->tm_min = bcd2bin(chip->buf[2]); |
129 | dt->tm_hour = BCD2BIN(chip->buf[3]); | 129 | dt->tm_hour = bcd2bin(chip->buf[3]); |
130 | dt->tm_mday = BCD2BIN(chip->buf[4]); | 130 | dt->tm_mday = bcd2bin(chip->buf[4]); |
131 | dt->tm_mon = BCD2BIN(chip->buf[5]) - 1; | 131 | dt->tm_mon = bcd2bin(chip->buf[5]) - 1; |
132 | dt->tm_wday = BCD2BIN(chip->buf[6]); | 132 | dt->tm_wday = bcd2bin(chip->buf[6]); |
133 | dt->tm_year = BCD2BIN(chip->buf[7]); | 133 | dt->tm_year = bcd2bin(chip->buf[7]); |
134 | 134 | ||
135 | century = BCD2BIN(tmp) * 100; | 135 | century = bcd2bin(tmp) * 100; |
136 | 136 | ||
137 | dt->tm_year += century; | 137 | dt->tm_year += century; |
138 | dt->tm_year -= 1900; | 138 | dt->tm_year -= 1900; |
@@ -168,15 +168,15 @@ static int max6902_set_datetime(struct device *dev, struct rtc_time *dt) | |||
168 | /* Remove write protection */ | 168 | /* Remove write protection */ |
169 | max6902_set_reg(dev, 0xF, 0); | 169 | max6902_set_reg(dev, 0xF, 0); |
170 | 170 | ||
171 | max6902_set_reg(dev, 0x01, BIN2BCD(dt->tm_sec)); | 171 | max6902_set_reg(dev, 0x01, bin2bcd(dt->tm_sec)); |
172 | max6902_set_reg(dev, 0x03, BIN2BCD(dt->tm_min)); | 172 | max6902_set_reg(dev, 0x03, bin2bcd(dt->tm_min)); |
173 | max6902_set_reg(dev, 0x05, BIN2BCD(dt->tm_hour)); | 173 | max6902_set_reg(dev, 0x05, bin2bcd(dt->tm_hour)); |
174 | 174 | ||
175 | max6902_set_reg(dev, 0x07, BIN2BCD(dt->tm_mday)); | 175 | max6902_set_reg(dev, 0x07, bin2bcd(dt->tm_mday)); |
176 | max6902_set_reg(dev, 0x09, BIN2BCD(dt->tm_mon+1)); | 176 | max6902_set_reg(dev, 0x09, bin2bcd(dt->tm_mon+1)); |
177 | max6902_set_reg(dev, 0x0B, BIN2BCD(dt->tm_wday)); | 177 | max6902_set_reg(dev, 0x0B, bin2bcd(dt->tm_wday)); |
178 | max6902_set_reg(dev, 0x0D, BIN2BCD(dt->tm_year%100)); | 178 | max6902_set_reg(dev, 0x0D, bin2bcd(dt->tm_year%100)); |
179 | max6902_set_reg(dev, 0x13, BIN2BCD(dt->tm_year/100)); | 179 | max6902_set_reg(dev, 0x13, bin2bcd(dt->tm_year/100)); |
180 | 180 | ||
181 | /* Compulab used a delay here. However, the datasheet | 181 | /* Compulab used a delay here. However, the datasheet |
182 | * does not mention a delay being required anywhere... */ | 182 | * does not mention a delay being required anywhere... */ |
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c index 8876605d4d4b..2cbeb0794f14 100644 --- a/drivers/rtc/rtc-omap.c +++ b/drivers/rtc/rtc-omap.c | |||
@@ -186,30 +186,30 @@ static int tm2bcd(struct rtc_time *tm) | |||
186 | if (rtc_valid_tm(tm) != 0) | 186 | if (rtc_valid_tm(tm) != 0) |
187 | return -EINVAL; | 187 | return -EINVAL; |
188 | 188 | ||
189 | tm->tm_sec = BIN2BCD(tm->tm_sec); | 189 | tm->tm_sec = bin2bcd(tm->tm_sec); |
190 | tm->tm_min = BIN2BCD(tm->tm_min); | 190 | tm->tm_min = bin2bcd(tm->tm_min); |
191 | tm->tm_hour = BIN2BCD(tm->tm_hour); | 191 | tm->tm_hour = bin2bcd(tm->tm_hour); |
192 | tm->tm_mday = BIN2BCD(tm->tm_mday); | 192 | tm->tm_mday = bin2bcd(tm->tm_mday); |
193 | 193 | ||
194 | tm->tm_mon = BIN2BCD(tm->tm_mon + 1); | 194 | tm->tm_mon = bin2bcd(tm->tm_mon + 1); |
195 | 195 | ||
196 | /* epoch == 1900 */ | 196 | /* epoch == 1900 */ |
197 | if (tm->tm_year < 100 || tm->tm_year > 199) | 197 | if (tm->tm_year < 100 || tm->tm_year > 199) |
198 | return -EINVAL; | 198 | return -EINVAL; |
199 | tm->tm_year = BIN2BCD(tm->tm_year - 100); | 199 | tm->tm_year = bin2bcd(tm->tm_year - 100); |
200 | 200 | ||
201 | return 0; | 201 | return 0; |
202 | } | 202 | } |
203 | 203 | ||
204 | static void bcd2tm(struct rtc_time *tm) | 204 | static void bcd2tm(struct rtc_time *tm) |
205 | { | 205 | { |
206 | tm->tm_sec = BCD2BIN(tm->tm_sec); | 206 | tm->tm_sec = bcd2bin(tm->tm_sec); |
207 | tm->tm_min = BCD2BIN(tm->tm_min); | 207 | tm->tm_min = bcd2bin(tm->tm_min); |
208 | tm->tm_hour = BCD2BIN(tm->tm_hour); | 208 | tm->tm_hour = bcd2bin(tm->tm_hour); |
209 | tm->tm_mday = BCD2BIN(tm->tm_mday); | 209 | tm->tm_mday = bcd2bin(tm->tm_mday); |
210 | tm->tm_mon = BCD2BIN(tm->tm_mon) - 1; | 210 | tm->tm_mon = bcd2bin(tm->tm_mon) - 1; |
211 | /* epoch == 1900 */ | 211 | /* epoch == 1900 */ |
212 | tm->tm_year = BCD2BIN(tm->tm_year) + 100; | 212 | tm->tm_year = bcd2bin(tm->tm_year) + 100; |
213 | } | 213 | } |
214 | 214 | ||
215 | 215 | ||
diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c index a829f20ad6d6..b725913ccbe8 100644 --- a/drivers/rtc/rtc-pcf8563.c +++ b/drivers/rtc/rtc-pcf8563.c | |||
@@ -97,13 +97,13 @@ static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm) | |||
97 | buf[8]); | 97 | buf[8]); |
98 | 98 | ||
99 | 99 | ||
100 | tm->tm_sec = BCD2BIN(buf[PCF8563_REG_SC] & 0x7F); | 100 | tm->tm_sec = bcd2bin(buf[PCF8563_REG_SC] & 0x7F); |
101 | tm->tm_min = BCD2BIN(buf[PCF8563_REG_MN] & 0x7F); | 101 | tm->tm_min = bcd2bin(buf[PCF8563_REG_MN] & 0x7F); |
102 | tm->tm_hour = BCD2BIN(buf[PCF8563_REG_HR] & 0x3F); /* rtc hr 0-23 */ | 102 | tm->tm_hour = bcd2bin(buf[PCF8563_REG_HR] & 0x3F); /* rtc hr 0-23 */ |
103 | tm->tm_mday = BCD2BIN(buf[PCF8563_REG_DM] & 0x3F); | 103 | tm->tm_mday = bcd2bin(buf[PCF8563_REG_DM] & 0x3F); |
104 | tm->tm_wday = buf[PCF8563_REG_DW] & 0x07; | 104 | tm->tm_wday = buf[PCF8563_REG_DW] & 0x07; |
105 | tm->tm_mon = BCD2BIN(buf[PCF8563_REG_MO] & 0x1F) - 1; /* rtc mn 1-12 */ | 105 | tm->tm_mon = bcd2bin(buf[PCF8563_REG_MO] & 0x1F) - 1; /* rtc mn 1-12 */ |
106 | tm->tm_year = BCD2BIN(buf[PCF8563_REG_YR]); | 106 | tm->tm_year = bcd2bin(buf[PCF8563_REG_YR]); |
107 | if (tm->tm_year < 70) | 107 | if (tm->tm_year < 70) |
108 | tm->tm_year += 100; /* assume we are in 1970...2069 */ | 108 | tm->tm_year += 100; /* assume we are in 1970...2069 */ |
109 | /* detect the polarity heuristically. see note above. */ | 109 | /* detect the polarity heuristically. see note above. */ |
@@ -138,17 +138,17 @@ static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm) | |||
138 | tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); | 138 | tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); |
139 | 139 | ||
140 | /* hours, minutes and seconds */ | 140 | /* hours, minutes and seconds */ |
141 | buf[PCF8563_REG_SC] = BIN2BCD(tm->tm_sec); | 141 | buf[PCF8563_REG_SC] = bin2bcd(tm->tm_sec); |
142 | buf[PCF8563_REG_MN] = BIN2BCD(tm->tm_min); | 142 | buf[PCF8563_REG_MN] = bin2bcd(tm->tm_min); |
143 | buf[PCF8563_REG_HR] = BIN2BCD(tm->tm_hour); | 143 | buf[PCF8563_REG_HR] = bin2bcd(tm->tm_hour); |
144 | 144 | ||
145 | buf[PCF8563_REG_DM] = BIN2BCD(tm->tm_mday); | 145 | buf[PCF8563_REG_DM] = bin2bcd(tm->tm_mday); |
146 | 146 | ||
147 | /* month, 1 - 12 */ | 147 | /* month, 1 - 12 */ |
148 | buf[PCF8563_REG_MO] = BIN2BCD(tm->tm_mon + 1); | 148 | buf[PCF8563_REG_MO] = bin2bcd(tm->tm_mon + 1); |
149 | 149 | ||
150 | /* year and century */ | 150 | /* year and century */ |
151 | buf[PCF8563_REG_YR] = BIN2BCD(tm->tm_year % 100); | 151 | buf[PCF8563_REG_YR] = bin2bcd(tm->tm_year % 100); |
152 | if (pcf8563->c_polarity ? (tm->tm_year >= 100) : (tm->tm_year < 100)) | 152 | if (pcf8563->c_polarity ? (tm->tm_year >= 100) : (tm->tm_year < 100)) |
153 | buf[PCF8563_REG_MO] |= PCF8563_MO_C; | 153 | buf[PCF8563_REG_MO] |= PCF8563_MO_C; |
154 | 154 | ||
diff --git a/drivers/rtc/rtc-pcf8583.c b/drivers/rtc/rtc-pcf8583.c index d388c662bf4b..7d33cda3f8f6 100644 --- a/drivers/rtc/rtc-pcf8583.c +++ b/drivers/rtc/rtc-pcf8583.c | |||
@@ -76,11 +76,11 @@ static int pcf8583_get_datetime(struct i2c_client *client, struct rtc_time *dt) | |||
76 | buf[4] &= 0x3f; | 76 | buf[4] &= 0x3f; |
77 | buf[5] &= 0x1f; | 77 | buf[5] &= 0x1f; |
78 | 78 | ||
79 | dt->tm_sec = BCD2BIN(buf[1]); | 79 | dt->tm_sec = bcd2bin(buf[1]); |
80 | dt->tm_min = BCD2BIN(buf[2]); | 80 | dt->tm_min = bcd2bin(buf[2]); |
81 | dt->tm_hour = BCD2BIN(buf[3]); | 81 | dt->tm_hour = bcd2bin(buf[3]); |
82 | dt->tm_mday = BCD2BIN(buf[4]); | 82 | dt->tm_mday = bcd2bin(buf[4]); |
83 | dt->tm_mon = BCD2BIN(buf[5]) - 1; | 83 | dt->tm_mon = bcd2bin(buf[5]) - 1; |
84 | } | 84 | } |
85 | 85 | ||
86 | return ret == 2 ? 0 : -EIO; | 86 | return ret == 2 ? 0 : -EIO; |
@@ -94,14 +94,14 @@ static int pcf8583_set_datetime(struct i2c_client *client, struct rtc_time *dt, | |||
94 | buf[0] = 0; | 94 | buf[0] = 0; |
95 | buf[1] = get_ctrl(client) | 0x80; | 95 | buf[1] = get_ctrl(client) | 0x80; |
96 | buf[2] = 0; | 96 | buf[2] = 0; |
97 | buf[3] = BIN2BCD(dt->tm_sec); | 97 | buf[3] = bin2bcd(dt->tm_sec); |
98 | buf[4] = BIN2BCD(dt->tm_min); | 98 | buf[4] = bin2bcd(dt->tm_min); |
99 | buf[5] = BIN2BCD(dt->tm_hour); | 99 | buf[5] = bin2bcd(dt->tm_hour); |
100 | 100 | ||
101 | if (datetoo) { | 101 | if (datetoo) { |
102 | len = 8; | 102 | len = 8; |
103 | buf[6] = BIN2BCD(dt->tm_mday) | (dt->tm_year << 6); | 103 | buf[6] = bin2bcd(dt->tm_mday) | (dt->tm_year << 6); |
104 | buf[7] = BIN2BCD(dt->tm_mon + 1) | (dt->tm_wday << 5); | 104 | buf[7] = bin2bcd(dt->tm_mon + 1) | (dt->tm_wday << 5); |
105 | } | 105 | } |
106 | 106 | ||
107 | ret = i2c_master_send(client, (char *)buf, len); | 107 | ret = i2c_master_send(client, (char *)buf, len); |
diff --git a/drivers/rtc/rtc-r9701.c b/drivers/rtc/rtc-r9701.c index 395985b339c9..42028f233bef 100644 --- a/drivers/rtc/rtc-r9701.c +++ b/drivers/rtc/rtc-r9701.c | |||
@@ -80,13 +80,13 @@ static int r9701_get_datetime(struct device *dev, struct rtc_time *dt) | |||
80 | 80 | ||
81 | memset(dt, 0, sizeof(*dt)); | 81 | memset(dt, 0, sizeof(*dt)); |
82 | 82 | ||
83 | dt->tm_sec = BCD2BIN(buf[0]); /* RSECCNT */ | 83 | dt->tm_sec = bcd2bin(buf[0]); /* RSECCNT */ |
84 | dt->tm_min = BCD2BIN(buf[1]); /* RMINCNT */ | 84 | dt->tm_min = bcd2bin(buf[1]); /* RMINCNT */ |
85 | dt->tm_hour = BCD2BIN(buf[2]); /* RHRCNT */ | 85 | dt->tm_hour = bcd2bin(buf[2]); /* RHRCNT */ |
86 | 86 | ||
87 | dt->tm_mday = BCD2BIN(buf[3]); /* RDAYCNT */ | 87 | dt->tm_mday = bcd2bin(buf[3]); /* RDAYCNT */ |
88 | dt->tm_mon = BCD2BIN(buf[4]) - 1; /* RMONCNT */ | 88 | dt->tm_mon = bcd2bin(buf[4]) - 1; /* RMONCNT */ |
89 | dt->tm_year = BCD2BIN(buf[5]) + 100; /* RYRCNT */ | 89 | dt->tm_year = bcd2bin(buf[5]) + 100; /* RYRCNT */ |
90 | 90 | ||
91 | /* the rtc device may contain illegal values on power up | 91 | /* the rtc device may contain illegal values on power up |
92 | * according to the data sheet. make sure they are valid. | 92 | * according to the data sheet. make sure they are valid. |
@@ -103,12 +103,12 @@ static int r9701_set_datetime(struct device *dev, struct rtc_time *dt) | |||
103 | if (year >= 2100 || year < 2000) | 103 | if (year >= 2100 || year < 2000) |
104 | return -EINVAL; | 104 | return -EINVAL; |
105 | 105 | ||
106 | ret = write_reg(dev, RHRCNT, BIN2BCD(dt->tm_hour)); | 106 | ret = write_reg(dev, RHRCNT, bin2bcd(dt->tm_hour)); |
107 | ret = ret ? ret : write_reg(dev, RMINCNT, BIN2BCD(dt->tm_min)); | 107 | ret = ret ? ret : write_reg(dev, RMINCNT, bin2bcd(dt->tm_min)); |
108 | ret = ret ? ret : write_reg(dev, RSECCNT, BIN2BCD(dt->tm_sec)); | 108 | ret = ret ? ret : write_reg(dev, RSECCNT, bin2bcd(dt->tm_sec)); |
109 | ret = ret ? ret : write_reg(dev, RDAYCNT, BIN2BCD(dt->tm_mday)); | 109 | ret = ret ? ret : write_reg(dev, RDAYCNT, bin2bcd(dt->tm_mday)); |
110 | ret = ret ? ret : write_reg(dev, RMONCNT, BIN2BCD(dt->tm_mon + 1)); | 110 | ret = ret ? ret : write_reg(dev, RMONCNT, bin2bcd(dt->tm_mon + 1)); |
111 | ret = ret ? ret : write_reg(dev, RYRCNT, BIN2BCD(dt->tm_year - 100)); | 111 | ret = ret ? ret : write_reg(dev, RYRCNT, bin2bcd(dt->tm_year - 100)); |
112 | ret = ret ? ret : write_reg(dev, RWKCNT, 1 << dt->tm_wday); | 112 | ret = ret ? ret : write_reg(dev, RWKCNT, 1 << dt->tm_wday); |
113 | 113 | ||
114 | return ret; | 114 | return ret; |
diff --git a/drivers/rtc/rtc-rs5c313.c b/drivers/rtc/rtc-rs5c313.c index 1c14d4497c4d..e6ea3f5ee1eb 100644 --- a/drivers/rtc/rtc-rs5c313.c +++ b/drivers/rtc/rtc-rs5c313.c | |||
@@ -235,33 +235,33 @@ static int rs5c313_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
235 | 235 | ||
236 | data = rs5c313_read_reg(RS5C313_ADDR_SEC); | 236 | data = rs5c313_read_reg(RS5C313_ADDR_SEC); |
237 | data |= (rs5c313_read_reg(RS5C313_ADDR_SEC10) << 4); | 237 | data |= (rs5c313_read_reg(RS5C313_ADDR_SEC10) << 4); |
238 | tm->tm_sec = BCD2BIN(data); | 238 | tm->tm_sec = bcd2bin(data); |
239 | 239 | ||
240 | data = rs5c313_read_reg(RS5C313_ADDR_MIN); | 240 | data = rs5c313_read_reg(RS5C313_ADDR_MIN); |
241 | data |= (rs5c313_read_reg(RS5C313_ADDR_MIN10) << 4); | 241 | data |= (rs5c313_read_reg(RS5C313_ADDR_MIN10) << 4); |
242 | tm->tm_min = BCD2BIN(data); | 242 | tm->tm_min = bcd2bin(data); |
243 | 243 | ||
244 | data = rs5c313_read_reg(RS5C313_ADDR_HOUR); | 244 | data = rs5c313_read_reg(RS5C313_ADDR_HOUR); |
245 | data |= (rs5c313_read_reg(RS5C313_ADDR_HOUR10) << 4); | 245 | data |= (rs5c313_read_reg(RS5C313_ADDR_HOUR10) << 4); |
246 | tm->tm_hour = BCD2BIN(data); | 246 | tm->tm_hour = bcd2bin(data); |
247 | 247 | ||
248 | data = rs5c313_read_reg(RS5C313_ADDR_DAY); | 248 | data = rs5c313_read_reg(RS5C313_ADDR_DAY); |
249 | data |= (rs5c313_read_reg(RS5C313_ADDR_DAY10) << 4); | 249 | data |= (rs5c313_read_reg(RS5C313_ADDR_DAY10) << 4); |
250 | tm->tm_mday = BCD2BIN(data); | 250 | tm->tm_mday = bcd2bin(data); |
251 | 251 | ||
252 | data = rs5c313_read_reg(RS5C313_ADDR_MON); | 252 | data = rs5c313_read_reg(RS5C313_ADDR_MON); |
253 | data |= (rs5c313_read_reg(RS5C313_ADDR_MON10) << 4); | 253 | data |= (rs5c313_read_reg(RS5C313_ADDR_MON10) << 4); |
254 | tm->tm_mon = BCD2BIN(data) - 1; | 254 | tm->tm_mon = bcd2bin(data) - 1; |
255 | 255 | ||
256 | data = rs5c313_read_reg(RS5C313_ADDR_YEAR); | 256 | data = rs5c313_read_reg(RS5C313_ADDR_YEAR); |
257 | data |= (rs5c313_read_reg(RS5C313_ADDR_YEAR10) << 4); | 257 | data |= (rs5c313_read_reg(RS5C313_ADDR_YEAR10) << 4); |
258 | tm->tm_year = BCD2BIN(data); | 258 | tm->tm_year = bcd2bin(data); |
259 | 259 | ||
260 | if (tm->tm_year < 70) | 260 | if (tm->tm_year < 70) |
261 | tm->tm_year += 100; | 261 | tm->tm_year += 100; |
262 | 262 | ||
263 | data = rs5c313_read_reg(RS5C313_ADDR_WEEK); | 263 | data = rs5c313_read_reg(RS5C313_ADDR_WEEK); |
264 | tm->tm_wday = BCD2BIN(data); | 264 | tm->tm_wday = bcd2bin(data); |
265 | 265 | ||
266 | RS5C313_CEDISABLE; | 266 | RS5C313_CEDISABLE; |
267 | ndelay(700); /* CE:L */ | 267 | ndelay(700); /* CE:L */ |
@@ -294,31 +294,31 @@ static int rs5c313_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
294 | } | 294 | } |
295 | } | 295 | } |
296 | 296 | ||
297 | data = BIN2BCD(tm->tm_sec); | 297 | data = bin2bcd(tm->tm_sec); |
298 | rs5c313_write_reg(RS5C313_ADDR_SEC, data); | 298 | rs5c313_write_reg(RS5C313_ADDR_SEC, data); |
299 | rs5c313_write_reg(RS5C313_ADDR_SEC10, (data >> 4)); | 299 | rs5c313_write_reg(RS5C313_ADDR_SEC10, (data >> 4)); |
300 | 300 | ||
301 | data = BIN2BCD(tm->tm_min); | 301 | data = bin2bcd(tm->tm_min); |
302 | rs5c313_write_reg(RS5C313_ADDR_MIN, data ); | 302 | rs5c313_write_reg(RS5C313_ADDR_MIN, data ); |
303 | rs5c313_write_reg(RS5C313_ADDR_MIN10, (data >> 4)); | 303 | rs5c313_write_reg(RS5C313_ADDR_MIN10, (data >> 4)); |
304 | 304 | ||
305 | data = BIN2BCD(tm->tm_hour); | 305 | data = bin2bcd(tm->tm_hour); |
306 | rs5c313_write_reg(RS5C313_ADDR_HOUR, data); | 306 | rs5c313_write_reg(RS5C313_ADDR_HOUR, data); |
307 | rs5c313_write_reg(RS5C313_ADDR_HOUR10, (data >> 4)); | 307 | rs5c313_write_reg(RS5C313_ADDR_HOUR10, (data >> 4)); |
308 | 308 | ||
309 | data = BIN2BCD(tm->tm_mday); | 309 | data = bin2bcd(tm->tm_mday); |
310 | rs5c313_write_reg(RS5C313_ADDR_DAY, data); | 310 | rs5c313_write_reg(RS5C313_ADDR_DAY, data); |
311 | rs5c313_write_reg(RS5C313_ADDR_DAY10, (data>> 4)); | 311 | rs5c313_write_reg(RS5C313_ADDR_DAY10, (data>> 4)); |
312 | 312 | ||
313 | data = BIN2BCD(tm->tm_mon + 1); | 313 | data = bin2bcd(tm->tm_mon + 1); |
314 | rs5c313_write_reg(RS5C313_ADDR_MON, data); | 314 | rs5c313_write_reg(RS5C313_ADDR_MON, data); |
315 | rs5c313_write_reg(RS5C313_ADDR_MON10, (data >> 4)); | 315 | rs5c313_write_reg(RS5C313_ADDR_MON10, (data >> 4)); |
316 | 316 | ||
317 | data = BIN2BCD(tm->tm_year % 100); | 317 | data = bin2bcd(tm->tm_year % 100); |
318 | rs5c313_write_reg(RS5C313_ADDR_YEAR, data); | 318 | rs5c313_write_reg(RS5C313_ADDR_YEAR, data); |
319 | rs5c313_write_reg(RS5C313_ADDR_YEAR10, (data >> 4)); | 319 | rs5c313_write_reg(RS5C313_ADDR_YEAR10, (data >> 4)); |
320 | 320 | ||
321 | data = BIN2BCD(tm->tm_wday); | 321 | data = bin2bcd(tm->tm_wday); |
322 | rs5c313_write_reg(RS5C313_ADDR_WEEK, data); | 322 | rs5c313_write_reg(RS5C313_ADDR_WEEK, data); |
323 | 323 | ||
324 | RS5C313_CEDISABLE; /* CE:H */ | 324 | RS5C313_CEDISABLE; /* CE:H */ |
diff --git a/drivers/rtc/rtc-rs5c348.c b/drivers/rtc/rtc-rs5c348.c index 839462659afa..dd1e2bc7a472 100644 --- a/drivers/rtc/rtc-rs5c348.c +++ b/drivers/rtc/rtc-rs5c348.c | |||
@@ -74,20 +74,20 @@ rs5c348_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
74 | txbuf[3] = 0; /* dummy */ | 74 | txbuf[3] = 0; /* dummy */ |
75 | txbuf[4] = RS5C348_CMD_MW(RS5C348_REG_SECS); /* cmd, sec, ... */ | 75 | txbuf[4] = RS5C348_CMD_MW(RS5C348_REG_SECS); /* cmd, sec, ... */ |
76 | txp = &txbuf[5]; | 76 | txp = &txbuf[5]; |
77 | txp[RS5C348_REG_SECS] = BIN2BCD(tm->tm_sec); | 77 | txp[RS5C348_REG_SECS] = bin2bcd(tm->tm_sec); |
78 | txp[RS5C348_REG_MINS] = BIN2BCD(tm->tm_min); | 78 | txp[RS5C348_REG_MINS] = bin2bcd(tm->tm_min); |
79 | if (pdata->rtc_24h) { | 79 | if (pdata->rtc_24h) { |
80 | txp[RS5C348_REG_HOURS] = BIN2BCD(tm->tm_hour); | 80 | txp[RS5C348_REG_HOURS] = bin2bcd(tm->tm_hour); |
81 | } else { | 81 | } else { |
82 | /* hour 0 is AM12, noon is PM12 */ | 82 | /* hour 0 is AM12, noon is PM12 */ |
83 | txp[RS5C348_REG_HOURS] = BIN2BCD((tm->tm_hour + 11) % 12 + 1) | | 83 | txp[RS5C348_REG_HOURS] = bin2bcd((tm->tm_hour + 11) % 12 + 1) | |
84 | (tm->tm_hour >= 12 ? RS5C348_BIT_PM : 0); | 84 | (tm->tm_hour >= 12 ? RS5C348_BIT_PM : 0); |
85 | } | 85 | } |
86 | txp[RS5C348_REG_WDAY] = BIN2BCD(tm->tm_wday); | 86 | txp[RS5C348_REG_WDAY] = bin2bcd(tm->tm_wday); |
87 | txp[RS5C348_REG_DAY] = BIN2BCD(tm->tm_mday); | 87 | txp[RS5C348_REG_DAY] = bin2bcd(tm->tm_mday); |
88 | txp[RS5C348_REG_MONTH] = BIN2BCD(tm->tm_mon + 1) | | 88 | txp[RS5C348_REG_MONTH] = bin2bcd(tm->tm_mon + 1) | |
89 | (tm->tm_year >= 100 ? RS5C348_BIT_Y2K : 0); | 89 | (tm->tm_year >= 100 ? RS5C348_BIT_Y2K : 0); |
90 | txp[RS5C348_REG_YEAR] = BIN2BCD(tm->tm_year % 100); | 90 | txp[RS5C348_REG_YEAR] = bin2bcd(tm->tm_year % 100); |
91 | /* write in one transfer to avoid data inconsistency */ | 91 | /* write in one transfer to avoid data inconsistency */ |
92 | ret = spi_write_then_read(spi, txbuf, sizeof(txbuf), NULL, 0); | 92 | ret = spi_write_then_read(spi, txbuf, sizeof(txbuf), NULL, 0); |
93 | udelay(62); /* Tcsr 62us */ | 93 | udelay(62); /* Tcsr 62us */ |
@@ -116,20 +116,20 @@ rs5c348_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
116 | if (ret < 0) | 116 | if (ret < 0) |
117 | return ret; | 117 | return ret; |
118 | 118 | ||
119 | tm->tm_sec = BCD2BIN(rxbuf[RS5C348_REG_SECS] & RS5C348_SECS_MASK); | 119 | tm->tm_sec = bcd2bin(rxbuf[RS5C348_REG_SECS] & RS5C348_SECS_MASK); |
120 | tm->tm_min = BCD2BIN(rxbuf[RS5C348_REG_MINS] & RS5C348_MINS_MASK); | 120 | tm->tm_min = bcd2bin(rxbuf[RS5C348_REG_MINS] & RS5C348_MINS_MASK); |
121 | tm->tm_hour = BCD2BIN(rxbuf[RS5C348_REG_HOURS] & RS5C348_HOURS_MASK); | 121 | tm->tm_hour = bcd2bin(rxbuf[RS5C348_REG_HOURS] & RS5C348_HOURS_MASK); |
122 | if (!pdata->rtc_24h) { | 122 | if (!pdata->rtc_24h) { |
123 | tm->tm_hour %= 12; | 123 | tm->tm_hour %= 12; |
124 | if (rxbuf[RS5C348_REG_HOURS] & RS5C348_BIT_PM) | 124 | if (rxbuf[RS5C348_REG_HOURS] & RS5C348_BIT_PM) |
125 | tm->tm_hour += 12; | 125 | tm->tm_hour += 12; |
126 | } | 126 | } |
127 | tm->tm_wday = BCD2BIN(rxbuf[RS5C348_REG_WDAY] & RS5C348_WDAY_MASK); | 127 | tm->tm_wday = bcd2bin(rxbuf[RS5C348_REG_WDAY] & RS5C348_WDAY_MASK); |
128 | tm->tm_mday = BCD2BIN(rxbuf[RS5C348_REG_DAY] & RS5C348_DAY_MASK); | 128 | tm->tm_mday = bcd2bin(rxbuf[RS5C348_REG_DAY] & RS5C348_DAY_MASK); |
129 | tm->tm_mon = | 129 | tm->tm_mon = |
130 | BCD2BIN(rxbuf[RS5C348_REG_MONTH] & RS5C348_MONTH_MASK) - 1; | 130 | bcd2bin(rxbuf[RS5C348_REG_MONTH] & RS5C348_MONTH_MASK) - 1; |
131 | /* year is 1900 + tm->tm_year */ | 131 | /* year is 1900 + tm->tm_year */ |
132 | tm->tm_year = BCD2BIN(rxbuf[RS5C348_REG_YEAR]) + | 132 | tm->tm_year = bcd2bin(rxbuf[RS5C348_REG_YEAR]) + |
133 | ((rxbuf[RS5C348_REG_MONTH] & RS5C348_BIT_Y2K) ? 100 : 0); | 133 | ((rxbuf[RS5C348_REG_MONTH] & RS5C348_BIT_Y2K) ? 100 : 0); |
134 | 134 | ||
135 | if (rtc_valid_tm(tm) < 0) { | 135 | if (rtc_valid_tm(tm) < 0) { |
diff --git a/drivers/rtc/rtc-rs5c372.c b/drivers/rtc/rtc-rs5c372.c index 8b561958fb1e..2f2c68d476da 100644 --- a/drivers/rtc/rtc-rs5c372.c +++ b/drivers/rtc/rtc-rs5c372.c | |||
@@ -148,9 +148,9 @@ static unsigned rs5c_reg2hr(struct rs5c372 *rs5c, unsigned reg) | |||
148 | unsigned hour; | 148 | unsigned hour; |
149 | 149 | ||
150 | if (rs5c->time24) | 150 | if (rs5c->time24) |
151 | return BCD2BIN(reg & 0x3f); | 151 | return bcd2bin(reg & 0x3f); |
152 | 152 | ||
153 | hour = BCD2BIN(reg & 0x1f); | 153 | hour = bcd2bin(reg & 0x1f); |
154 | if (hour == 12) | 154 | if (hour == 12) |
155 | hour = 0; | 155 | hour = 0; |
156 | if (reg & 0x20) | 156 | if (reg & 0x20) |
@@ -161,15 +161,15 @@ static unsigned rs5c_reg2hr(struct rs5c372 *rs5c, unsigned reg) | |||
161 | static unsigned rs5c_hr2reg(struct rs5c372 *rs5c, unsigned hour) | 161 | static unsigned rs5c_hr2reg(struct rs5c372 *rs5c, unsigned hour) |
162 | { | 162 | { |
163 | if (rs5c->time24) | 163 | if (rs5c->time24) |
164 | return BIN2BCD(hour); | 164 | return bin2bcd(hour); |
165 | 165 | ||
166 | if (hour > 12) | 166 | if (hour > 12) |
167 | return 0x20 | BIN2BCD(hour - 12); | 167 | return 0x20 | bin2bcd(hour - 12); |
168 | if (hour == 12) | 168 | if (hour == 12) |
169 | return 0x20 | BIN2BCD(12); | 169 | return 0x20 | bin2bcd(12); |
170 | if (hour == 0) | 170 | if (hour == 0) |
171 | return BIN2BCD(12); | 171 | return bin2bcd(12); |
172 | return BIN2BCD(hour); | 172 | return bin2bcd(hour); |
173 | } | 173 | } |
174 | 174 | ||
175 | static int rs5c372_get_datetime(struct i2c_client *client, struct rtc_time *tm) | 175 | static int rs5c372_get_datetime(struct i2c_client *client, struct rtc_time *tm) |
@@ -180,18 +180,18 @@ static int rs5c372_get_datetime(struct i2c_client *client, struct rtc_time *tm) | |||
180 | if (status < 0) | 180 | if (status < 0) |
181 | return status; | 181 | return status; |
182 | 182 | ||
183 | tm->tm_sec = BCD2BIN(rs5c->regs[RS5C372_REG_SECS] & 0x7f); | 183 | tm->tm_sec = bcd2bin(rs5c->regs[RS5C372_REG_SECS] & 0x7f); |
184 | tm->tm_min = BCD2BIN(rs5c->regs[RS5C372_REG_MINS] & 0x7f); | 184 | tm->tm_min = bcd2bin(rs5c->regs[RS5C372_REG_MINS] & 0x7f); |
185 | tm->tm_hour = rs5c_reg2hr(rs5c, rs5c->regs[RS5C372_REG_HOURS]); | 185 | tm->tm_hour = rs5c_reg2hr(rs5c, rs5c->regs[RS5C372_REG_HOURS]); |
186 | 186 | ||
187 | tm->tm_wday = BCD2BIN(rs5c->regs[RS5C372_REG_WDAY] & 0x07); | 187 | tm->tm_wday = bcd2bin(rs5c->regs[RS5C372_REG_WDAY] & 0x07); |
188 | tm->tm_mday = BCD2BIN(rs5c->regs[RS5C372_REG_DAY] & 0x3f); | 188 | tm->tm_mday = bcd2bin(rs5c->regs[RS5C372_REG_DAY] & 0x3f); |
189 | 189 | ||
190 | /* tm->tm_mon is zero-based */ | 190 | /* tm->tm_mon is zero-based */ |
191 | tm->tm_mon = BCD2BIN(rs5c->regs[RS5C372_REG_MONTH] & 0x1f) - 1; | 191 | tm->tm_mon = bcd2bin(rs5c->regs[RS5C372_REG_MONTH] & 0x1f) - 1; |
192 | 192 | ||
193 | /* year is 1900 + tm->tm_year */ | 193 | /* year is 1900 + tm->tm_year */ |
194 | tm->tm_year = BCD2BIN(rs5c->regs[RS5C372_REG_YEAR]) + 100; | 194 | tm->tm_year = bcd2bin(rs5c->regs[RS5C372_REG_YEAR]) + 100; |
195 | 195 | ||
196 | dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, " | 196 | dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, " |
197 | "mday=%d, mon=%d, year=%d, wday=%d\n", | 197 | "mday=%d, mon=%d, year=%d, wday=%d\n", |
@@ -216,13 +216,13 @@ static int rs5c372_set_datetime(struct i2c_client *client, struct rtc_time *tm) | |||
216 | tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); | 216 | tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); |
217 | 217 | ||
218 | addr = RS5C_ADDR(RS5C372_REG_SECS); | 218 | addr = RS5C_ADDR(RS5C372_REG_SECS); |
219 | buf[0] = BIN2BCD(tm->tm_sec); | 219 | buf[0] = bin2bcd(tm->tm_sec); |
220 | buf[1] = BIN2BCD(tm->tm_min); | 220 | buf[1] = bin2bcd(tm->tm_min); |
221 | buf[2] = rs5c_hr2reg(rs5c, tm->tm_hour); | 221 | buf[2] = rs5c_hr2reg(rs5c, tm->tm_hour); |
222 | buf[3] = BIN2BCD(tm->tm_wday); | 222 | buf[3] = bin2bcd(tm->tm_wday); |
223 | buf[4] = BIN2BCD(tm->tm_mday); | 223 | buf[4] = bin2bcd(tm->tm_mday); |
224 | buf[5] = BIN2BCD(tm->tm_mon + 1); | 224 | buf[5] = bin2bcd(tm->tm_mon + 1); |
225 | buf[6] = BIN2BCD(tm->tm_year - 100); | 225 | buf[6] = bin2bcd(tm->tm_year - 100); |
226 | 226 | ||
227 | if (i2c_smbus_write_i2c_block_data(client, addr, sizeof(buf), buf) < 0) { | 227 | if (i2c_smbus_write_i2c_block_data(client, addr, sizeof(buf), buf) < 0) { |
228 | dev_err(&client->dev, "%s: write error\n", __func__); | 228 | dev_err(&client->dev, "%s: write error\n", __func__); |
@@ -367,7 +367,7 @@ static int rs5c_read_alarm(struct device *dev, struct rtc_wkalrm *t) | |||
367 | 367 | ||
368 | /* report alarm time */ | 368 | /* report alarm time */ |
369 | t->time.tm_sec = 0; | 369 | t->time.tm_sec = 0; |
370 | t->time.tm_min = BCD2BIN(rs5c->regs[RS5C_REG_ALARM_A_MIN] & 0x7f); | 370 | t->time.tm_min = bcd2bin(rs5c->regs[RS5C_REG_ALARM_A_MIN] & 0x7f); |
371 | t->time.tm_hour = rs5c_reg2hr(rs5c, rs5c->regs[RS5C_REG_ALARM_A_HOURS]); | 371 | t->time.tm_hour = rs5c_reg2hr(rs5c, rs5c->regs[RS5C_REG_ALARM_A_HOURS]); |
372 | t->time.tm_mday = -1; | 372 | t->time.tm_mday = -1; |
373 | t->time.tm_mon = -1; | 373 | t->time.tm_mon = -1; |
@@ -413,7 +413,7 @@ static int rs5c_set_alarm(struct device *dev, struct rtc_wkalrm *t) | |||
413 | } | 413 | } |
414 | 414 | ||
415 | /* set alarm */ | 415 | /* set alarm */ |
416 | buf[0] = BIN2BCD(t->time.tm_min); | 416 | buf[0] = bin2bcd(t->time.tm_min); |
417 | buf[1] = rs5c_hr2reg(rs5c, t->time.tm_hour); | 417 | buf[1] = rs5c_hr2reg(rs5c, t->time.tm_hour); |
418 | buf[2] = 0x7f; /* any/all days */ | 418 | buf[2] = 0x7f; /* any/all days */ |
419 | 419 | ||
diff --git a/drivers/rtc/rtc-s35390a.c b/drivers/rtc/rtc-s35390a.c index a6fa1f2f2ca6..def4d396d0b0 100644 --- a/drivers/rtc/rtc-s35390a.c +++ b/drivers/rtc/rtc-s35390a.c | |||
@@ -104,12 +104,12 @@ static int s35390a_disable_test_mode(struct s35390a *s35390a) | |||
104 | static char s35390a_hr2reg(struct s35390a *s35390a, int hour) | 104 | static char s35390a_hr2reg(struct s35390a *s35390a, int hour) |
105 | { | 105 | { |
106 | if (s35390a->twentyfourhour) | 106 | if (s35390a->twentyfourhour) |
107 | return BIN2BCD(hour); | 107 | return bin2bcd(hour); |
108 | 108 | ||
109 | if (hour < 12) | 109 | if (hour < 12) |
110 | return BIN2BCD(hour); | 110 | return bin2bcd(hour); |
111 | 111 | ||
112 | return 0x40 | BIN2BCD(hour - 12); | 112 | return 0x40 | bin2bcd(hour - 12); |
113 | } | 113 | } |
114 | 114 | ||
115 | static int s35390a_reg2hr(struct s35390a *s35390a, char reg) | 115 | static int s35390a_reg2hr(struct s35390a *s35390a, char reg) |
@@ -117,9 +117,9 @@ static int s35390a_reg2hr(struct s35390a *s35390a, char reg) | |||
117 | unsigned hour; | 117 | unsigned hour; |
118 | 118 | ||
119 | if (s35390a->twentyfourhour) | 119 | if (s35390a->twentyfourhour) |
120 | return BCD2BIN(reg & 0x3f); | 120 | return bcd2bin(reg & 0x3f); |
121 | 121 | ||
122 | hour = BCD2BIN(reg & 0x3f); | 122 | hour = bcd2bin(reg & 0x3f); |
123 | if (reg & 0x40) | 123 | if (reg & 0x40) |
124 | hour += 12; | 124 | hour += 12; |
125 | 125 | ||
@@ -137,13 +137,13 @@ static int s35390a_set_datetime(struct i2c_client *client, struct rtc_time *tm) | |||
137 | tm->tm_min, tm->tm_hour, tm->tm_mday, tm->tm_mon, tm->tm_year, | 137 | tm->tm_min, tm->tm_hour, tm->tm_mday, tm->tm_mon, tm->tm_year, |
138 | tm->tm_wday); | 138 | tm->tm_wday); |
139 | 139 | ||
140 | buf[S35390A_BYTE_YEAR] = BIN2BCD(tm->tm_year - 100); | 140 | buf[S35390A_BYTE_YEAR] = bin2bcd(tm->tm_year - 100); |
141 | buf[S35390A_BYTE_MONTH] = BIN2BCD(tm->tm_mon + 1); | 141 | buf[S35390A_BYTE_MONTH] = bin2bcd(tm->tm_mon + 1); |
142 | buf[S35390A_BYTE_DAY] = BIN2BCD(tm->tm_mday); | 142 | buf[S35390A_BYTE_DAY] = bin2bcd(tm->tm_mday); |
143 | buf[S35390A_BYTE_WDAY] = BIN2BCD(tm->tm_wday); | 143 | buf[S35390A_BYTE_WDAY] = bin2bcd(tm->tm_wday); |
144 | buf[S35390A_BYTE_HOURS] = s35390a_hr2reg(s35390a, tm->tm_hour); | 144 | buf[S35390A_BYTE_HOURS] = s35390a_hr2reg(s35390a, tm->tm_hour); |
145 | buf[S35390A_BYTE_MINS] = BIN2BCD(tm->tm_min); | 145 | buf[S35390A_BYTE_MINS] = bin2bcd(tm->tm_min); |
146 | buf[S35390A_BYTE_SECS] = BIN2BCD(tm->tm_sec); | 146 | buf[S35390A_BYTE_SECS] = bin2bcd(tm->tm_sec); |
147 | 147 | ||
148 | /* This chip expects the bits of each byte to be in reverse order */ | 148 | /* This chip expects the bits of each byte to be in reverse order */ |
149 | for (i = 0; i < 7; ++i) | 149 | for (i = 0; i < 7; ++i) |
@@ -168,13 +168,13 @@ static int s35390a_get_datetime(struct i2c_client *client, struct rtc_time *tm) | |||
168 | for (i = 0; i < 7; ++i) | 168 | for (i = 0; i < 7; ++i) |
169 | buf[i] = bitrev8(buf[i]); | 169 | buf[i] = bitrev8(buf[i]); |
170 | 170 | ||
171 | tm->tm_sec = BCD2BIN(buf[S35390A_BYTE_SECS]); | 171 | tm->tm_sec = bcd2bin(buf[S35390A_BYTE_SECS]); |
172 | tm->tm_min = BCD2BIN(buf[S35390A_BYTE_MINS]); | 172 | tm->tm_min = bcd2bin(buf[S35390A_BYTE_MINS]); |
173 | tm->tm_hour = s35390a_reg2hr(s35390a, buf[S35390A_BYTE_HOURS]); | 173 | tm->tm_hour = s35390a_reg2hr(s35390a, buf[S35390A_BYTE_HOURS]); |
174 | tm->tm_wday = BCD2BIN(buf[S35390A_BYTE_WDAY]); | 174 | tm->tm_wday = bcd2bin(buf[S35390A_BYTE_WDAY]); |
175 | tm->tm_mday = BCD2BIN(buf[S35390A_BYTE_DAY]); | 175 | tm->tm_mday = bcd2bin(buf[S35390A_BYTE_DAY]); |
176 | tm->tm_mon = BCD2BIN(buf[S35390A_BYTE_MONTH]) - 1; | 176 | tm->tm_mon = bcd2bin(buf[S35390A_BYTE_MONTH]) - 1; |
177 | tm->tm_year = BCD2BIN(buf[S35390A_BYTE_YEAR]) + 100; | 177 | tm->tm_year = bcd2bin(buf[S35390A_BYTE_YEAR]) + 100; |
178 | 178 | ||
179 | dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, mday=%d, " | 179 | dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, mday=%d, " |
180 | "mon=%d, year=%d, wday=%d\n", __func__, tm->tm_sec, | 180 | "mon=%d, year=%d, wday=%d\n", __func__, tm->tm_sec, |
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c index e7d19b6c265a..910bc704939c 100644 --- a/drivers/rtc/rtc-s3c.c +++ b/drivers/rtc/rtc-s3c.c | |||
@@ -134,12 +134,12 @@ static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm) | |||
134 | rtc_tm->tm_year, rtc_tm->tm_mon, rtc_tm->tm_mday, | 134 | rtc_tm->tm_year, rtc_tm->tm_mon, rtc_tm->tm_mday, |
135 | rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec); | 135 | rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec); |
136 | 136 | ||
137 | BCD_TO_BIN(rtc_tm->tm_sec); | 137 | rtc_tm->tm_sec = bcd2bin(rtc_tm->tm_sec); |
138 | BCD_TO_BIN(rtc_tm->tm_min); | 138 | rtc_tm->tm_min = bcd2bin(rtc_tm->tm_min); |
139 | BCD_TO_BIN(rtc_tm->tm_hour); | 139 | rtc_tm->tm_hour = bcd2bin(rtc_tm->tm_hour); |
140 | BCD_TO_BIN(rtc_tm->tm_mday); | 140 | rtc_tm->tm_mday = bcd2bin(rtc_tm->tm_mday); |
141 | BCD_TO_BIN(rtc_tm->tm_mon); | 141 | rtc_tm->tm_mon = bcd2bin(rtc_tm->tm_mon); |
142 | BCD_TO_BIN(rtc_tm->tm_year); | 142 | rtc_tm->tm_year = bcd2bin(rtc_tm->tm_year); |
143 | 143 | ||
144 | rtc_tm->tm_year += 100; | 144 | rtc_tm->tm_year += 100; |
145 | rtc_tm->tm_mon -= 1; | 145 | rtc_tm->tm_mon -= 1; |
@@ -163,12 +163,12 @@ static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm) | |||
163 | return -EINVAL; | 163 | return -EINVAL; |
164 | } | 164 | } |
165 | 165 | ||
166 | writeb(BIN2BCD(tm->tm_sec), base + S3C2410_RTCSEC); | 166 | writeb(bin2bcd(tm->tm_sec), base + S3C2410_RTCSEC); |
167 | writeb(BIN2BCD(tm->tm_min), base + S3C2410_RTCMIN); | 167 | writeb(bin2bcd(tm->tm_min), base + S3C2410_RTCMIN); |
168 | writeb(BIN2BCD(tm->tm_hour), base + S3C2410_RTCHOUR); | 168 | writeb(bin2bcd(tm->tm_hour), base + S3C2410_RTCHOUR); |
169 | writeb(BIN2BCD(tm->tm_mday), base + S3C2410_RTCDATE); | 169 | writeb(bin2bcd(tm->tm_mday), base + S3C2410_RTCDATE); |
170 | writeb(BIN2BCD(tm->tm_mon + 1), base + S3C2410_RTCMON); | 170 | writeb(bin2bcd(tm->tm_mon + 1), base + S3C2410_RTCMON); |
171 | writeb(BIN2BCD(year), base + S3C2410_RTCYEAR); | 171 | writeb(bin2bcd(year), base + S3C2410_RTCYEAR); |
172 | 172 | ||
173 | return 0; | 173 | return 0; |
174 | } | 174 | } |
@@ -199,34 +199,34 @@ static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
199 | /* decode the alarm enable field */ | 199 | /* decode the alarm enable field */ |
200 | 200 | ||
201 | if (alm_en & S3C2410_RTCALM_SECEN) | 201 | if (alm_en & S3C2410_RTCALM_SECEN) |
202 | BCD_TO_BIN(alm_tm->tm_sec); | 202 | alm_tm->tm_sec = bcd2bin(alm_tm->tm_sec); |
203 | else | 203 | else |
204 | alm_tm->tm_sec = 0xff; | 204 | alm_tm->tm_sec = 0xff; |
205 | 205 | ||
206 | if (alm_en & S3C2410_RTCALM_MINEN) | 206 | if (alm_en & S3C2410_RTCALM_MINEN) |
207 | BCD_TO_BIN(alm_tm->tm_min); | 207 | alm_tm->tm_min = bcd2bin(alm_tm->tm_min); |
208 | else | 208 | else |
209 | alm_tm->tm_min = 0xff; | 209 | alm_tm->tm_min = 0xff; |
210 | 210 | ||
211 | if (alm_en & S3C2410_RTCALM_HOUREN) | 211 | if (alm_en & S3C2410_RTCALM_HOUREN) |
212 | BCD_TO_BIN(alm_tm->tm_hour); | 212 | alm_tm->tm_hour = bcd2bin(alm_tm->tm_hour); |
213 | else | 213 | else |
214 | alm_tm->tm_hour = 0xff; | 214 | alm_tm->tm_hour = 0xff; |
215 | 215 | ||
216 | if (alm_en & S3C2410_RTCALM_DAYEN) | 216 | if (alm_en & S3C2410_RTCALM_DAYEN) |
217 | BCD_TO_BIN(alm_tm->tm_mday); | 217 | alm_tm->tm_mday = bcd2bin(alm_tm->tm_mday); |
218 | else | 218 | else |
219 | alm_tm->tm_mday = 0xff; | 219 | alm_tm->tm_mday = 0xff; |
220 | 220 | ||
221 | if (alm_en & S3C2410_RTCALM_MONEN) { | 221 | if (alm_en & S3C2410_RTCALM_MONEN) { |
222 | BCD_TO_BIN(alm_tm->tm_mon); | 222 | alm_tm->tm_mon = bcd2bin(alm_tm->tm_mon); |
223 | alm_tm->tm_mon -= 1; | 223 | alm_tm->tm_mon -= 1; |
224 | } else { | 224 | } else { |
225 | alm_tm->tm_mon = 0xff; | 225 | alm_tm->tm_mon = 0xff; |
226 | } | 226 | } |
227 | 227 | ||
228 | if (alm_en & S3C2410_RTCALM_YEAREN) | 228 | if (alm_en & S3C2410_RTCALM_YEAREN) |
229 | BCD_TO_BIN(alm_tm->tm_year); | 229 | alm_tm->tm_year = bcd2bin(alm_tm->tm_year); |
230 | else | 230 | else |
231 | alm_tm->tm_year = 0xffff; | 231 | alm_tm->tm_year = 0xffff; |
232 | 232 | ||
@@ -250,17 +250,17 @@ static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) | |||
250 | 250 | ||
251 | if (tm->tm_sec < 60 && tm->tm_sec >= 0) { | 251 | if (tm->tm_sec < 60 && tm->tm_sec >= 0) { |
252 | alrm_en |= S3C2410_RTCALM_SECEN; | 252 | alrm_en |= S3C2410_RTCALM_SECEN; |
253 | writeb(BIN2BCD(tm->tm_sec), base + S3C2410_ALMSEC); | 253 | writeb(bin2bcd(tm->tm_sec), base + S3C2410_ALMSEC); |
254 | } | 254 | } |
255 | 255 | ||
256 | if (tm->tm_min < 60 && tm->tm_min >= 0) { | 256 | if (tm->tm_min < 60 && tm->tm_min >= 0) { |
257 | alrm_en |= S3C2410_RTCALM_MINEN; | 257 | alrm_en |= S3C2410_RTCALM_MINEN; |
258 | writeb(BIN2BCD(tm->tm_min), base + S3C2410_ALMMIN); | 258 | writeb(bin2bcd(tm->tm_min), base + S3C2410_ALMMIN); |
259 | } | 259 | } |
260 | 260 | ||
261 | if (tm->tm_hour < 24 && tm->tm_hour >= 0) { | 261 | if (tm->tm_hour < 24 && tm->tm_hour >= 0) { |
262 | alrm_en |= S3C2410_RTCALM_HOUREN; | 262 | alrm_en |= S3C2410_RTCALM_HOUREN; |
263 | writeb(BIN2BCD(tm->tm_hour), base + S3C2410_ALMHOUR); | 263 | writeb(bin2bcd(tm->tm_hour), base + S3C2410_ALMHOUR); |
264 | } | 264 | } |
265 | 265 | ||
266 | pr_debug("setting S3C2410_RTCALM to %08x\n", alrm_en); | 266 | pr_debug("setting S3C2410_RTCALM to %08x\n", alrm_en); |
diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c index 3f393c82e32c..aaf9d6a337cc 100644 --- a/drivers/rtc/rtc-sh.c +++ b/drivers/rtc/rtc-sh.c | |||
@@ -324,23 +324,23 @@ static int sh_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
324 | 324 | ||
325 | sec128 = readb(rtc->regbase + R64CNT); | 325 | sec128 = readb(rtc->regbase + R64CNT); |
326 | 326 | ||
327 | tm->tm_sec = BCD2BIN(readb(rtc->regbase + RSECCNT)); | 327 | tm->tm_sec = bcd2bin(readb(rtc->regbase + RSECCNT)); |
328 | tm->tm_min = BCD2BIN(readb(rtc->regbase + RMINCNT)); | 328 | tm->tm_min = bcd2bin(readb(rtc->regbase + RMINCNT)); |
329 | tm->tm_hour = BCD2BIN(readb(rtc->regbase + RHRCNT)); | 329 | tm->tm_hour = bcd2bin(readb(rtc->regbase + RHRCNT)); |
330 | tm->tm_wday = BCD2BIN(readb(rtc->regbase + RWKCNT)); | 330 | tm->tm_wday = bcd2bin(readb(rtc->regbase + RWKCNT)); |
331 | tm->tm_mday = BCD2BIN(readb(rtc->regbase + RDAYCNT)); | 331 | tm->tm_mday = bcd2bin(readb(rtc->regbase + RDAYCNT)); |
332 | tm->tm_mon = BCD2BIN(readb(rtc->regbase + RMONCNT)) - 1; | 332 | tm->tm_mon = bcd2bin(readb(rtc->regbase + RMONCNT)) - 1; |
333 | 333 | ||
334 | if (rtc->capabilities & RTC_CAP_4_DIGIT_YEAR) { | 334 | if (rtc->capabilities & RTC_CAP_4_DIGIT_YEAR) { |
335 | yr = readw(rtc->regbase + RYRCNT); | 335 | yr = readw(rtc->regbase + RYRCNT); |
336 | yr100 = BCD2BIN(yr >> 8); | 336 | yr100 = bcd2bin(yr >> 8); |
337 | yr &= 0xff; | 337 | yr &= 0xff; |
338 | } else { | 338 | } else { |
339 | yr = readb(rtc->regbase + RYRCNT); | 339 | yr = readb(rtc->regbase + RYRCNT); |
340 | yr100 = BCD2BIN((yr == 0x99) ? 0x19 : 0x20); | 340 | yr100 = bcd2bin((yr == 0x99) ? 0x19 : 0x20); |
341 | } | 341 | } |
342 | 342 | ||
343 | tm->tm_year = (yr100 * 100 + BCD2BIN(yr)) - 1900; | 343 | tm->tm_year = (yr100 * 100 + bcd2bin(yr)) - 1900; |
344 | 344 | ||
345 | sec2 = readb(rtc->regbase + R64CNT); | 345 | sec2 = readb(rtc->regbase + R64CNT); |
346 | cf_bit = readb(rtc->regbase + RCR1) & RCR1_CF; | 346 | cf_bit = readb(rtc->regbase + RCR1) & RCR1_CF; |
@@ -382,20 +382,20 @@ static int sh_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
382 | tmp &= ~RCR2_START; | 382 | tmp &= ~RCR2_START; |
383 | writeb(tmp, rtc->regbase + RCR2); | 383 | writeb(tmp, rtc->regbase + RCR2); |
384 | 384 | ||
385 | writeb(BIN2BCD(tm->tm_sec), rtc->regbase + RSECCNT); | 385 | writeb(bin2bcd(tm->tm_sec), rtc->regbase + RSECCNT); |
386 | writeb(BIN2BCD(tm->tm_min), rtc->regbase + RMINCNT); | 386 | writeb(bin2bcd(tm->tm_min), rtc->regbase + RMINCNT); |
387 | writeb(BIN2BCD(tm->tm_hour), rtc->regbase + RHRCNT); | 387 | writeb(bin2bcd(tm->tm_hour), rtc->regbase + RHRCNT); |
388 | writeb(BIN2BCD(tm->tm_wday), rtc->regbase + RWKCNT); | 388 | writeb(bin2bcd(tm->tm_wday), rtc->regbase + RWKCNT); |
389 | writeb(BIN2BCD(tm->tm_mday), rtc->regbase + RDAYCNT); | 389 | writeb(bin2bcd(tm->tm_mday), rtc->regbase + RDAYCNT); |
390 | writeb(BIN2BCD(tm->tm_mon + 1), rtc->regbase + RMONCNT); | 390 | writeb(bin2bcd(tm->tm_mon + 1), rtc->regbase + RMONCNT); |
391 | 391 | ||
392 | if (rtc->capabilities & RTC_CAP_4_DIGIT_YEAR) { | 392 | if (rtc->capabilities & RTC_CAP_4_DIGIT_YEAR) { |
393 | year = (BIN2BCD((tm->tm_year + 1900) / 100) << 8) | | 393 | year = (bin2bcd((tm->tm_year + 1900) / 100) << 8) | |
394 | BIN2BCD(tm->tm_year % 100); | 394 | bin2bcd(tm->tm_year % 100); |
395 | writew(year, rtc->regbase + RYRCNT); | 395 | writew(year, rtc->regbase + RYRCNT); |
396 | } else { | 396 | } else { |
397 | year = tm->tm_year % 100; | 397 | year = tm->tm_year % 100; |
398 | writeb(BIN2BCD(year), rtc->regbase + RYRCNT); | 398 | writeb(bin2bcd(year), rtc->regbase + RYRCNT); |
399 | } | 399 | } |
400 | 400 | ||
401 | /* Start RTC */ | 401 | /* Start RTC */ |
@@ -417,7 +417,7 @@ static inline int sh_rtc_read_alarm_value(struct sh_rtc *rtc, int reg_off) | |||
417 | byte = readb(rtc->regbase + reg_off); | 417 | byte = readb(rtc->regbase + reg_off); |
418 | if (byte & AR_ENB) { | 418 | if (byte & AR_ENB) { |
419 | byte &= ~AR_ENB; /* strip the enable bit */ | 419 | byte &= ~AR_ENB; /* strip the enable bit */ |
420 | value = BCD2BIN(byte); | 420 | value = bcd2bin(byte); |
421 | } | 421 | } |
422 | 422 | ||
423 | return value; | 423 | return value; |
@@ -455,7 +455,7 @@ static inline void sh_rtc_write_alarm_value(struct sh_rtc *rtc, | |||
455 | if (value < 0) | 455 | if (value < 0) |
456 | writeb(0, rtc->regbase + reg_off); | 456 | writeb(0, rtc->regbase + reg_off); |
457 | else | 457 | else |
458 | writeb(BIN2BCD(value) | AR_ENB, rtc->regbase + reg_off); | 458 | writeb(bin2bcd(value) | AR_ENB, rtc->regbase + reg_off); |
459 | } | 459 | } |
460 | 460 | ||
461 | static int sh_rtc_check_alarm(struct rtc_time *tm) | 461 | static int sh_rtc_check_alarm(struct rtc_time *tm) |
diff --git a/drivers/rtc/rtc-stk17ta8.c b/drivers/rtc/rtc-stk17ta8.c index 9a7e920315fa..f4cd46e15af9 100644 --- a/drivers/rtc/rtc-stk17ta8.c +++ b/drivers/rtc/rtc-stk17ta8.c | |||
@@ -82,14 +82,14 @@ static int stk17ta8_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
82 | flags = readb(pdata->ioaddr + RTC_FLAGS); | 82 | flags = readb(pdata->ioaddr + RTC_FLAGS); |
83 | writeb(flags | RTC_WRITE, pdata->ioaddr + RTC_FLAGS); | 83 | writeb(flags | RTC_WRITE, pdata->ioaddr + RTC_FLAGS); |
84 | 84 | ||
85 | writeb(BIN2BCD(tm->tm_year % 100), ioaddr + RTC_YEAR); | 85 | writeb(bin2bcd(tm->tm_year % 100), ioaddr + RTC_YEAR); |
86 | writeb(BIN2BCD(tm->tm_mon + 1), ioaddr + RTC_MONTH); | 86 | writeb(bin2bcd(tm->tm_mon + 1), ioaddr + RTC_MONTH); |
87 | writeb(BIN2BCD(tm->tm_wday) & RTC_DAY_MASK, ioaddr + RTC_DAY); | 87 | writeb(bin2bcd(tm->tm_wday) & RTC_DAY_MASK, ioaddr + RTC_DAY); |
88 | writeb(BIN2BCD(tm->tm_mday), ioaddr + RTC_DATE); | 88 | writeb(bin2bcd(tm->tm_mday), ioaddr + RTC_DATE); |
89 | writeb(BIN2BCD(tm->tm_hour), ioaddr + RTC_HOURS); | 89 | writeb(bin2bcd(tm->tm_hour), ioaddr + RTC_HOURS); |
90 | writeb(BIN2BCD(tm->tm_min), ioaddr + RTC_MINUTES); | 90 | writeb(bin2bcd(tm->tm_min), ioaddr + RTC_MINUTES); |
91 | writeb(BIN2BCD(tm->tm_sec) & RTC_SECONDS_MASK, ioaddr + RTC_SECONDS); | 91 | writeb(bin2bcd(tm->tm_sec) & RTC_SECONDS_MASK, ioaddr + RTC_SECONDS); |
92 | writeb(BIN2BCD((tm->tm_year + 1900) / 100), ioaddr + RTC_CENTURY); | 92 | writeb(bin2bcd((tm->tm_year + 1900) / 100), ioaddr + RTC_CENTURY); |
93 | 93 | ||
94 | writeb(flags & ~RTC_WRITE, pdata->ioaddr + RTC_FLAGS); | 94 | writeb(flags & ~RTC_WRITE, pdata->ioaddr + RTC_FLAGS); |
95 | return 0; | 95 | return 0; |
@@ -120,14 +120,14 @@ static int stk17ta8_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
120 | year = readb(ioaddr + RTC_YEAR); | 120 | year = readb(ioaddr + RTC_YEAR); |
121 | century = readb(ioaddr + RTC_CENTURY); | 121 | century = readb(ioaddr + RTC_CENTURY); |
122 | writeb(flags & ~RTC_READ, ioaddr + RTC_FLAGS); | 122 | writeb(flags & ~RTC_READ, ioaddr + RTC_FLAGS); |
123 | tm->tm_sec = BCD2BIN(second); | 123 | tm->tm_sec = bcd2bin(second); |
124 | tm->tm_min = BCD2BIN(minute); | 124 | tm->tm_min = bcd2bin(minute); |
125 | tm->tm_hour = BCD2BIN(hour); | 125 | tm->tm_hour = bcd2bin(hour); |
126 | tm->tm_mday = BCD2BIN(day); | 126 | tm->tm_mday = bcd2bin(day); |
127 | tm->tm_wday = BCD2BIN(week); | 127 | tm->tm_wday = bcd2bin(week); |
128 | tm->tm_mon = BCD2BIN(month) - 1; | 128 | tm->tm_mon = bcd2bin(month) - 1; |
129 | /* year is 1900 + tm->tm_year */ | 129 | /* year is 1900 + tm->tm_year */ |
130 | tm->tm_year = BCD2BIN(year) + BCD2BIN(century) * 100 - 1900; | 130 | tm->tm_year = bcd2bin(year) + bcd2bin(century) * 100 - 1900; |
131 | 131 | ||
132 | if (rtc_valid_tm(tm) < 0) { | 132 | if (rtc_valid_tm(tm) < 0) { |
133 | dev_err(dev, "retrieved date/time is not valid.\n"); | 133 | dev_err(dev, "retrieved date/time is not valid.\n"); |
@@ -148,16 +148,16 @@ static void stk17ta8_rtc_update_alarm(struct rtc_plat_data *pdata) | |||
148 | writeb(flags | RTC_WRITE, ioaddr + RTC_FLAGS); | 148 | writeb(flags | RTC_WRITE, ioaddr + RTC_FLAGS); |
149 | 149 | ||
150 | writeb(pdata->alrm_mday < 0 || (pdata->irqen & RTC_UF) ? | 150 | writeb(pdata->alrm_mday < 0 || (pdata->irqen & RTC_UF) ? |
151 | 0x80 : BIN2BCD(pdata->alrm_mday), | 151 | 0x80 : bin2bcd(pdata->alrm_mday), |
152 | ioaddr + RTC_DATE_ALARM); | 152 | ioaddr + RTC_DATE_ALARM); |
153 | writeb(pdata->alrm_hour < 0 || (pdata->irqen & RTC_UF) ? | 153 | writeb(pdata->alrm_hour < 0 || (pdata->irqen & RTC_UF) ? |
154 | 0x80 : BIN2BCD(pdata->alrm_hour), | 154 | 0x80 : bin2bcd(pdata->alrm_hour), |
155 | ioaddr + RTC_HOURS_ALARM); | 155 | ioaddr + RTC_HOURS_ALARM); |
156 | writeb(pdata->alrm_min < 0 || (pdata->irqen & RTC_UF) ? | 156 | writeb(pdata->alrm_min < 0 || (pdata->irqen & RTC_UF) ? |
157 | 0x80 : BIN2BCD(pdata->alrm_min), | 157 | 0x80 : bin2bcd(pdata->alrm_min), |
158 | ioaddr + RTC_MINUTES_ALARM); | 158 | ioaddr + RTC_MINUTES_ALARM); |
159 | writeb(pdata->alrm_sec < 0 || (pdata->irqen & RTC_UF) ? | 159 | writeb(pdata->alrm_sec < 0 || (pdata->irqen & RTC_UF) ? |
160 | 0x80 : BIN2BCD(pdata->alrm_sec), | 160 | 0x80 : bin2bcd(pdata->alrm_sec), |
161 | ioaddr + RTC_SECONDS_ALARM); | 161 | ioaddr + RTC_SECONDS_ALARM); |
162 | writeb(pdata->irqen ? RTC_INTS_AIE : 0, ioaddr + RTC_INTERRUPTS); | 162 | writeb(pdata->irqen ? RTC_INTS_AIE : 0, ioaddr + RTC_INTERRUPTS); |
163 | readb(ioaddr + RTC_FLAGS); /* clear interrupts */ | 163 | readb(ioaddr + RTC_FLAGS); /* clear interrupts */ |
@@ -280,7 +280,6 @@ static struct bin_attribute stk17ta8_nvram_attr = { | |||
280 | .attr = { | 280 | .attr = { |
281 | .name = "nvram", | 281 | .name = "nvram", |
282 | .mode = S_IRUGO | S_IWUSR, | 282 | .mode = S_IRUGO | S_IWUSR, |
283 | .owner = THIS_MODULE, | ||
284 | }, | 283 | }, |
285 | .size = RTC_OFFSET, | 284 | .size = RTC_OFFSET, |
286 | .read = stk17ta8_nvram_read, | 285 | .read = stk17ta8_nvram_read, |
diff --git a/drivers/rtc/rtc-v3020.c b/drivers/rtc/rtc-v3020.c index 10025d840268..14d4f036a768 100644 --- a/drivers/rtc/rtc-v3020.c +++ b/drivers/rtc/rtc-v3020.c | |||
@@ -92,19 +92,19 @@ static int v3020_read_time(struct device *dev, struct rtc_time *dt) | |||
92 | 92 | ||
93 | /* ...and then read constant values. */ | 93 | /* ...and then read constant values. */ |
94 | tmp = v3020_get_reg(chip, V3020_SECONDS); | 94 | tmp = v3020_get_reg(chip, V3020_SECONDS); |
95 | dt->tm_sec = BCD2BIN(tmp); | 95 | dt->tm_sec = bcd2bin(tmp); |
96 | tmp = v3020_get_reg(chip, V3020_MINUTES); | 96 | tmp = v3020_get_reg(chip, V3020_MINUTES); |
97 | dt->tm_min = BCD2BIN(tmp); | 97 | dt->tm_min = bcd2bin(tmp); |
98 | tmp = v3020_get_reg(chip, V3020_HOURS); | 98 | tmp = v3020_get_reg(chip, V3020_HOURS); |
99 | dt->tm_hour = BCD2BIN(tmp); | 99 | dt->tm_hour = bcd2bin(tmp); |
100 | tmp = v3020_get_reg(chip, V3020_MONTH_DAY); | 100 | tmp = v3020_get_reg(chip, V3020_MONTH_DAY); |
101 | dt->tm_mday = BCD2BIN(tmp); | 101 | dt->tm_mday = bcd2bin(tmp); |
102 | tmp = v3020_get_reg(chip, V3020_MONTH); | 102 | tmp = v3020_get_reg(chip, V3020_MONTH); |
103 | dt->tm_mon = BCD2BIN(tmp) - 1; | 103 | dt->tm_mon = bcd2bin(tmp) - 1; |
104 | tmp = v3020_get_reg(chip, V3020_WEEK_DAY); | 104 | tmp = v3020_get_reg(chip, V3020_WEEK_DAY); |
105 | dt->tm_wday = BCD2BIN(tmp); | 105 | dt->tm_wday = bcd2bin(tmp); |
106 | tmp = v3020_get_reg(chip, V3020_YEAR); | 106 | tmp = v3020_get_reg(chip, V3020_YEAR); |
107 | dt->tm_year = BCD2BIN(tmp)+100; | 107 | dt->tm_year = bcd2bin(tmp)+100; |
108 | 108 | ||
109 | #ifdef DEBUG | 109 | #ifdef DEBUG |
110 | printk("\n%s : Read RTC values\n",__func__); | 110 | printk("\n%s : Read RTC values\n",__func__); |
@@ -136,13 +136,13 @@ static int v3020_set_time(struct device *dev, struct rtc_time *dt) | |||
136 | #endif | 136 | #endif |
137 | 137 | ||
138 | /* Write all the values to ram... */ | 138 | /* Write all the values to ram... */ |
139 | v3020_set_reg(chip, V3020_SECONDS, BIN2BCD(dt->tm_sec)); | 139 | v3020_set_reg(chip, V3020_SECONDS, bin2bcd(dt->tm_sec)); |
140 | v3020_set_reg(chip, V3020_MINUTES, BIN2BCD(dt->tm_min)); | 140 | v3020_set_reg(chip, V3020_MINUTES, bin2bcd(dt->tm_min)); |
141 | v3020_set_reg(chip, V3020_HOURS, BIN2BCD(dt->tm_hour)); | 141 | v3020_set_reg(chip, V3020_HOURS, bin2bcd(dt->tm_hour)); |
142 | v3020_set_reg(chip, V3020_MONTH_DAY, BIN2BCD(dt->tm_mday)); | 142 | v3020_set_reg(chip, V3020_MONTH_DAY, bin2bcd(dt->tm_mday)); |
143 | v3020_set_reg(chip, V3020_MONTH, BIN2BCD(dt->tm_mon + 1)); | 143 | v3020_set_reg(chip, V3020_MONTH, bin2bcd(dt->tm_mon + 1)); |
144 | v3020_set_reg(chip, V3020_WEEK_DAY, BIN2BCD(dt->tm_wday)); | 144 | v3020_set_reg(chip, V3020_WEEK_DAY, bin2bcd(dt->tm_wday)); |
145 | v3020_set_reg(chip, V3020_YEAR, BIN2BCD(dt->tm_year % 100)); | 145 | v3020_set_reg(chip, V3020_YEAR, bin2bcd(dt->tm_year % 100)); |
146 | 146 | ||
147 | /* ...and set the clock. */ | 147 | /* ...and set the clock. */ |
148 | v3020_set_reg(chip, V3020_CMD_RAM2CLOCK, 0); | 148 | v3020_set_reg(chip, V3020_CMD_RAM2CLOCK, 0); |
diff --git a/drivers/rtc/rtc-x1205.c b/drivers/rtc/rtc-x1205.c index 7dcfba1bbfe1..310c10795e9a 100644 --- a/drivers/rtc/rtc-x1205.c +++ b/drivers/rtc/rtc-x1205.c | |||
@@ -118,13 +118,13 @@ static int x1205_get_datetime(struct i2c_client *client, struct rtc_time *tm, | |||
118 | for (i = 0; i <= 4; i++) | 118 | for (i = 0; i <= 4; i++) |
119 | buf[i] &= 0x7F; | 119 | buf[i] &= 0x7F; |
120 | 120 | ||
121 | tm->tm_sec = BCD2BIN(buf[CCR_SEC]); | 121 | tm->tm_sec = bcd2bin(buf[CCR_SEC]); |
122 | tm->tm_min = BCD2BIN(buf[CCR_MIN]); | 122 | tm->tm_min = bcd2bin(buf[CCR_MIN]); |
123 | tm->tm_hour = BCD2BIN(buf[CCR_HOUR] & 0x3F); /* hr is 0-23 */ | 123 | tm->tm_hour = bcd2bin(buf[CCR_HOUR] & 0x3F); /* hr is 0-23 */ |
124 | tm->tm_mday = BCD2BIN(buf[CCR_MDAY]); | 124 | tm->tm_mday = bcd2bin(buf[CCR_MDAY]); |
125 | tm->tm_mon = BCD2BIN(buf[CCR_MONTH]) - 1; /* mon is 0-11 */ | 125 | tm->tm_mon = bcd2bin(buf[CCR_MONTH]) - 1; /* mon is 0-11 */ |
126 | tm->tm_year = BCD2BIN(buf[CCR_YEAR]) | 126 | tm->tm_year = bcd2bin(buf[CCR_YEAR]) |
127 | + (BCD2BIN(buf[CCR_Y2K]) * 100) - 1900; | 127 | + (bcd2bin(buf[CCR_Y2K]) * 100) - 1900; |
128 | tm->tm_wday = buf[CCR_WDAY]; | 128 | tm->tm_wday = buf[CCR_WDAY]; |
129 | 129 | ||
130 | dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, " | 130 | dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, " |
@@ -174,11 +174,11 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm, | |||
174 | __func__, | 174 | __func__, |
175 | tm->tm_sec, tm->tm_min, tm->tm_hour); | 175 | tm->tm_sec, tm->tm_min, tm->tm_hour); |
176 | 176 | ||
177 | buf[CCR_SEC] = BIN2BCD(tm->tm_sec); | 177 | buf[CCR_SEC] = bin2bcd(tm->tm_sec); |
178 | buf[CCR_MIN] = BIN2BCD(tm->tm_min); | 178 | buf[CCR_MIN] = bin2bcd(tm->tm_min); |
179 | 179 | ||
180 | /* set hour and 24hr bit */ | 180 | /* set hour and 24hr bit */ |
181 | buf[CCR_HOUR] = BIN2BCD(tm->tm_hour) | X1205_HR_MIL; | 181 | buf[CCR_HOUR] = bin2bcd(tm->tm_hour) | X1205_HR_MIL; |
182 | 182 | ||
183 | /* should we also set the date? */ | 183 | /* should we also set the date? */ |
184 | if (datetoo) { | 184 | if (datetoo) { |
@@ -187,15 +187,15 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm, | |||
187 | __func__, | 187 | __func__, |
188 | tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); | 188 | tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); |
189 | 189 | ||
190 | buf[CCR_MDAY] = BIN2BCD(tm->tm_mday); | 190 | buf[CCR_MDAY] = bin2bcd(tm->tm_mday); |
191 | 191 | ||
192 | /* month, 1 - 12 */ | 192 | /* month, 1 - 12 */ |
193 | buf[CCR_MONTH] = BIN2BCD(tm->tm_mon + 1); | 193 | buf[CCR_MONTH] = bin2bcd(tm->tm_mon + 1); |
194 | 194 | ||
195 | /* year, since the rtc epoch*/ | 195 | /* year, since the rtc epoch*/ |
196 | buf[CCR_YEAR] = BIN2BCD(tm->tm_year % 100); | 196 | buf[CCR_YEAR] = bin2bcd(tm->tm_year % 100); |
197 | buf[CCR_WDAY] = tm->tm_wday & 0x07; | 197 | buf[CCR_WDAY] = tm->tm_wday & 0x07; |
198 | buf[CCR_Y2K] = BIN2BCD(tm->tm_year / 100); | 198 | buf[CCR_Y2K] = bin2bcd(tm->tm_year / 100); |
199 | } | 199 | } |
200 | 200 | ||
201 | /* If writing alarm registers, set compare bits on registers 0-4 */ | 201 | /* If writing alarm registers, set compare bits on registers 0-4 */ |
@@ -437,7 +437,7 @@ static int x1205_validate_client(struct i2c_client *client) | |||
437 | return -EIO; | 437 | return -EIO; |
438 | } | 438 | } |
439 | 439 | ||
440 | value = BCD2BIN(reg & probe_limits_pattern[i].mask); | 440 | value = bcd2bin(reg & probe_limits_pattern[i].mask); |
441 | 441 | ||
442 | if (value > probe_limits_pattern[i].max || | 442 | if (value > probe_limits_pattern[i].max || |
443 | value < probe_limits_pattern[i].min) { | 443 | value < probe_limits_pattern[i].min) { |
diff --git a/drivers/scsi/arcmsr/arcmsr_attr.c b/drivers/scsi/arcmsr/arcmsr_attr.c index 69f8346aa288..5877f29a6005 100644 --- a/drivers/scsi/arcmsr/arcmsr_attr.c +++ b/drivers/scsi/arcmsr/arcmsr_attr.c | |||
@@ -189,7 +189,6 @@ static struct bin_attribute arcmsr_sysfs_message_read_attr = { | |||
189 | .attr = { | 189 | .attr = { |
190 | .name = "mu_read", | 190 | .name = "mu_read", |
191 | .mode = S_IRUSR , | 191 | .mode = S_IRUSR , |
192 | .owner = THIS_MODULE, | ||
193 | }, | 192 | }, |
194 | .size = 1032, | 193 | .size = 1032, |
195 | .read = arcmsr_sysfs_iop_message_read, | 194 | .read = arcmsr_sysfs_iop_message_read, |
@@ -199,7 +198,6 @@ static struct bin_attribute arcmsr_sysfs_message_write_attr = { | |||
199 | .attr = { | 198 | .attr = { |
200 | .name = "mu_write", | 199 | .name = "mu_write", |
201 | .mode = S_IWUSR, | 200 | .mode = S_IWUSR, |
202 | .owner = THIS_MODULE, | ||
203 | }, | 201 | }, |
204 | .size = 1032, | 202 | .size = 1032, |
205 | .write = arcmsr_sysfs_iop_message_write, | 203 | .write = arcmsr_sysfs_iop_message_write, |
@@ -209,7 +207,6 @@ static struct bin_attribute arcmsr_sysfs_message_clear_attr = { | |||
209 | .attr = { | 207 | .attr = { |
210 | .name = "mu_clear", | 208 | .name = "mu_clear", |
211 | .mode = S_IWUSR, | 209 | .mode = S_IWUSR, |
212 | .owner = THIS_MODULE, | ||
213 | }, | 210 | }, |
214 | .size = 1, | 211 | .size = 1, |
215 | .write = arcmsr_sysfs_iop_message_clear, | 212 | .write = arcmsr_sysfs_iop_message_clear, |
diff --git a/drivers/scsi/sr_vendor.c b/drivers/scsi/sr_vendor.c index 4eb3da996b36..4ad3e017213f 100644 --- a/drivers/scsi/sr_vendor.c +++ b/drivers/scsi/sr_vendor.c | |||
@@ -223,9 +223,9 @@ int sr_cd_check(struct cdrom_device_info *cdi) | |||
223 | no_multi = 1; | 223 | no_multi = 1; |
224 | break; | 224 | break; |
225 | } | 225 | } |
226 | min = BCD2BIN(buffer[15]); | 226 | min = bcd2bin(buffer[15]); |
227 | sec = BCD2BIN(buffer[16]); | 227 | sec = bcd2bin(buffer[16]); |
228 | frame = BCD2BIN(buffer[17]); | 228 | frame = bcd2bin(buffer[17]); |
229 | sector = min * CD_SECS * CD_FRAMES + sec * CD_FRAMES + frame; | 229 | sector = min * CD_SECS * CD_FRAMES + sec * CD_FRAMES + frame; |
230 | break; | 230 | break; |
231 | } | 231 | } |
@@ -252,9 +252,9 @@ int sr_cd_check(struct cdrom_device_info *cdi) | |||
252 | } | 252 | } |
253 | if (rc != 0) | 253 | if (rc != 0) |
254 | break; | 254 | break; |
255 | min = BCD2BIN(buffer[1]); | 255 | min = bcd2bin(buffer[1]); |
256 | sec = BCD2BIN(buffer[2]); | 256 | sec = bcd2bin(buffer[2]); |
257 | frame = BCD2BIN(buffer[3]); | 257 | frame = bcd2bin(buffer[3]); |
258 | sector = min * CD_SECS * CD_FRAMES + sec * CD_FRAMES + frame; | 258 | sector = min * CD_SECS * CD_FRAMES + sec * CD_FRAMES + frame; |
259 | if (sector) | 259 | if (sector) |
260 | sector -= CD_MSF_OFFSET; | 260 | sector -= CD_MSF_OFFSET; |
diff --git a/drivers/serial/8250_gsc.c b/drivers/serial/8250_gsc.c index 0416ad3bc127..418b4fe9a0a1 100644 --- a/drivers/serial/8250_gsc.c +++ b/drivers/serial/8250_gsc.c | |||
@@ -111,7 +111,7 @@ static struct parisc_driver serial_driver = { | |||
111 | .probe = serial_init_chip, | 111 | .probe = serial_init_chip, |
112 | }; | 112 | }; |
113 | 113 | ||
114 | int __init probe_serial_gsc(void) | 114 | static int __init probe_serial_gsc(void) |
115 | { | 115 | { |
116 | register_parisc_driver(&lasi_driver); | 116 | register_parisc_driver(&lasi_driver); |
117 | register_parisc_driver(&serial_driver); | 117 | register_parisc_driver(&serial_driver); |
diff --git a/drivers/serial/serial_txx9.c b/drivers/serial/serial_txx9.c index 8fcb4c5b9a26..7313c2edcb83 100644 --- a/drivers/serial/serial_txx9.c +++ b/drivers/serial/serial_txx9.c | |||
@@ -1039,7 +1039,7 @@ static int __devinit serial_txx9_probe(struct platform_device *dev) | |||
1039 | ret = serial_txx9_register_port(&port); | 1039 | ret = serial_txx9_register_port(&port); |
1040 | if (ret < 0) { | 1040 | if (ret < 0) { |
1041 | dev_err(&dev->dev, "unable to register port at index %d " | 1041 | dev_err(&dev->dev, "unable to register port at index %d " |
1042 | "(IO%x MEM%llx IRQ%d): %d\n", i, | 1042 | "(IO%lx MEM%llx IRQ%d): %d\n", i, |
1043 | p->iobase, (unsigned long long)p->mapbase, | 1043 | p->iobase, (unsigned long long)p->mapbase, |
1044 | p->irq, ret); | 1044 | p->irq, ret); |
1045 | } | 1045 | } |
diff --git a/drivers/serial/sn_console.c b/drivers/serial/sn_console.c index b73e3c0056cd..d5276c012f78 100644 --- a/drivers/serial/sn_console.c +++ b/drivers/serial/sn_console.c | |||
@@ -61,7 +61,7 @@ | |||
61 | #define SN_SAL_BUFFER_SIZE (64 * (1 << 10)) | 61 | #define SN_SAL_BUFFER_SIZE (64 * (1 << 10)) |
62 | 62 | ||
63 | #define SN_SAL_UART_FIFO_DEPTH 16 | 63 | #define SN_SAL_UART_FIFO_DEPTH 16 |
64 | #define SN_SAL_UART_FIFO_SPEED_CPS 9600/10 | 64 | #define SN_SAL_UART_FIFO_SPEED_CPS (9600/10) |
65 | 65 | ||
66 | /* sn_transmit_chars() calling args */ | 66 | /* sn_transmit_chars() calling args */ |
67 | #define TRANSMIT_BUFFERED 0 | 67 | #define TRANSMIT_BUFFERED 0 |
diff --git a/drivers/staging/go7007/Kconfig b/drivers/staging/go7007/Kconfig index 57a121c338c4..593fdb767aad 100644 --- a/drivers/staging/go7007/Kconfig +++ b/drivers/staging/go7007/Kconfig | |||
@@ -1,10 +1,12 @@ | |||
1 | config VIDEO_GO7007 | 1 | config VIDEO_GO7007 |
2 | tristate "Go 7007 support" | 2 | tristate "Go 7007 support" |
3 | depends on VIDEO_DEV && PCI && I2C && INPUT | 3 | depends on VIDEO_DEV && PCI && I2C && INPUT |
4 | depends on SND | ||
4 | select VIDEOBUF_DMA_SG | 5 | select VIDEOBUF_DMA_SG |
5 | select VIDEO_IR | 6 | select VIDEO_IR |
6 | select VIDEO_TUNER | 7 | select VIDEO_TUNER |
7 | select VIDEO_TVEEPROM | 8 | select VIDEO_TVEEPROM |
9 | select SND_PCM | ||
8 | select CRC32 | 10 | select CRC32 |
9 | default N | 11 | default N |
10 | ---help--- | 12 | ---help--- |
diff --git a/drivers/staging/sxg/Kconfig b/drivers/staging/sxg/Kconfig index 1ae350806600..6e6cf0b9ef99 100644 --- a/drivers/staging/sxg/Kconfig +++ b/drivers/staging/sxg/Kconfig | |||
@@ -1,6 +1,7 @@ | |||
1 | config SXG | 1 | config SXG |
2 | tristate "Alacritech SLIC Technology Non-Accelerated 10Gbe support" | 2 | tristate "Alacritech SLIC Technology Non-Accelerated 10Gbe support" |
3 | depends on PCI && NETDEV_10000 | 3 | depends on PCI && NETDEV_10000 |
4 | depends on X86 | ||
4 | default n | 5 | default n |
5 | help | 6 | help |
6 | This driver supports the Alacritech SLIC Technology Non-Accelerated | 7 | This driver supports the Alacritech SLIC Technology Non-Accelerated |
diff --git a/drivers/telephony/phonedev.c b/drivers/telephony/phonedev.c index 4d74ba36c3a1..37caf4d69037 100644 --- a/drivers/telephony/phonedev.c +++ b/drivers/telephony/phonedev.c | |||
@@ -54,7 +54,6 @@ static int phone_open(struct inode *inode, struct file *file) | |||
54 | if (minor >= PHONE_NUM_DEVICES) | 54 | if (minor >= PHONE_NUM_DEVICES) |
55 | return -ENODEV; | 55 | return -ENODEV; |
56 | 56 | ||
57 | lock_kernel(); | ||
58 | mutex_lock(&phone_lock); | 57 | mutex_lock(&phone_lock); |
59 | p = phone_device[minor]; | 58 | p = phone_device[minor]; |
60 | if (p) | 59 | if (p) |
@@ -81,7 +80,6 @@ static int phone_open(struct inode *inode, struct file *file) | |||
81 | fops_put(old_fops); | 80 | fops_put(old_fops); |
82 | end: | 81 | end: |
83 | mutex_unlock(&phone_lock); | 82 | mutex_unlock(&phone_lock); |
84 | unlock_kernel(); | ||
85 | return err; | 83 | return err; |
86 | } | 84 | } |
87 | 85 | ||
diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c index 217c5118ae9e..cd5f20da738a 100644 --- a/drivers/video/fbmem.c +++ b/drivers/video/fbmem.c | |||
@@ -1002,101 +1002,132 @@ fb_blank(struct fb_info *info, int blank) | |||
1002 | return ret; | 1002 | return ret; |
1003 | } | 1003 | } |
1004 | 1004 | ||
1005 | static int | 1005 | static long |
1006 | fb_ioctl(struct inode *inode, struct file *file, unsigned int cmd, | 1006 | fb_ioctl(struct file *file, unsigned int cmd, |
1007 | unsigned long arg) | 1007 | unsigned long arg) |
1008 | { | 1008 | { |
1009 | struct inode *inode = file->f_path.dentry->d_inode; | ||
1009 | int fbidx = iminor(inode); | 1010 | int fbidx = iminor(inode); |
1010 | struct fb_info *info = registered_fb[fbidx]; | 1011 | struct fb_info *info; |
1011 | struct fb_ops *fb = info->fbops; | 1012 | struct fb_ops *fb; |
1012 | struct fb_var_screeninfo var; | 1013 | struct fb_var_screeninfo var; |
1013 | struct fb_fix_screeninfo fix; | 1014 | struct fb_fix_screeninfo fix; |
1014 | struct fb_con2fbmap con2fb; | 1015 | struct fb_con2fbmap con2fb; |
1015 | struct fb_cmap_user cmap; | 1016 | struct fb_cmap_user cmap; |
1016 | struct fb_event event; | 1017 | struct fb_event event; |
1017 | void __user *argp = (void __user *)arg; | 1018 | void __user *argp = (void __user *)arg; |
1018 | int i; | 1019 | long ret = 0; |
1019 | 1020 | ||
1020 | if (!fb) | 1021 | info = registered_fb[fbidx]; |
1022 | mutex_lock(&info->lock); | ||
1023 | fb = info->fbops; | ||
1024 | |||
1025 | if (!fb) { | ||
1026 | mutex_unlock(&info->lock); | ||
1021 | return -ENODEV; | 1027 | return -ENODEV; |
1028 | } | ||
1022 | switch (cmd) { | 1029 | switch (cmd) { |
1023 | case FBIOGET_VSCREENINFO: | 1030 | case FBIOGET_VSCREENINFO: |
1024 | return copy_to_user(argp, &info->var, | 1031 | ret = copy_to_user(argp, &info->var, |
1025 | sizeof(var)) ? -EFAULT : 0; | 1032 | sizeof(var)) ? -EFAULT : 0; |
1033 | break; | ||
1026 | case FBIOPUT_VSCREENINFO: | 1034 | case FBIOPUT_VSCREENINFO: |
1027 | if (copy_from_user(&var, argp, sizeof(var))) | 1035 | if (copy_from_user(&var, argp, sizeof(var))) { |
1028 | return -EFAULT; | 1036 | ret = -EFAULT; |
1037 | break; | ||
1038 | } | ||
1029 | acquire_console_sem(); | 1039 | acquire_console_sem(); |
1030 | info->flags |= FBINFO_MISC_USEREVENT; | 1040 | info->flags |= FBINFO_MISC_USEREVENT; |
1031 | i = fb_set_var(info, &var); | 1041 | ret = fb_set_var(info, &var); |
1032 | info->flags &= ~FBINFO_MISC_USEREVENT; | 1042 | info->flags &= ~FBINFO_MISC_USEREVENT; |
1033 | release_console_sem(); | 1043 | release_console_sem(); |
1034 | if (i) return i; | 1044 | if (ret == 0 && copy_to_user(argp, &var, sizeof(var))) |
1035 | if (copy_to_user(argp, &var, sizeof(var))) | 1045 | ret = -EFAULT; |
1036 | return -EFAULT; | 1046 | break; |
1037 | return 0; | ||
1038 | case FBIOGET_FSCREENINFO: | 1047 | case FBIOGET_FSCREENINFO: |
1039 | return copy_to_user(argp, &info->fix, | 1048 | ret = copy_to_user(argp, &info->fix, |
1040 | sizeof(fix)) ? -EFAULT : 0; | 1049 | sizeof(fix)) ? -EFAULT : 0; |
1050 | break; | ||
1041 | case FBIOPUTCMAP: | 1051 | case FBIOPUTCMAP: |
1042 | if (copy_from_user(&cmap, argp, sizeof(cmap))) | 1052 | if (copy_from_user(&cmap, argp, sizeof(cmap))) |
1043 | return -EFAULT; | 1053 | ret = -EFAULT; |
1044 | return (fb_set_user_cmap(&cmap, info)); | 1054 | else |
1055 | ret = fb_set_user_cmap(&cmap, info); | ||
1056 | break; | ||
1045 | case FBIOGETCMAP: | 1057 | case FBIOGETCMAP: |
1046 | if (copy_from_user(&cmap, argp, sizeof(cmap))) | 1058 | if (copy_from_user(&cmap, argp, sizeof(cmap))) |
1047 | return -EFAULT; | 1059 | ret = -EFAULT; |
1048 | return fb_cmap_to_user(&info->cmap, &cmap); | 1060 | else |
1061 | ret = fb_cmap_to_user(&info->cmap, &cmap); | ||
1062 | break; | ||
1049 | case FBIOPAN_DISPLAY: | 1063 | case FBIOPAN_DISPLAY: |
1050 | if (copy_from_user(&var, argp, sizeof(var))) | 1064 | if (copy_from_user(&var, argp, sizeof(var))) { |
1051 | return -EFAULT; | 1065 | ret = -EFAULT; |
1066 | break; | ||
1067 | } | ||
1052 | acquire_console_sem(); | 1068 | acquire_console_sem(); |
1053 | i = fb_pan_display(info, &var); | 1069 | ret = fb_pan_display(info, &var); |
1054 | release_console_sem(); | 1070 | release_console_sem(); |
1055 | if (i) | 1071 | if (ret == 0 && copy_to_user(argp, &var, sizeof(var))) |
1056 | return i; | 1072 | ret = -EFAULT; |
1057 | if (copy_to_user(argp, &var, sizeof(var))) | 1073 | break; |
1058 | return -EFAULT; | ||
1059 | return 0; | ||
1060 | case FBIO_CURSOR: | 1074 | case FBIO_CURSOR: |
1061 | return -EINVAL; | 1075 | ret = -EINVAL; |
1076 | break; | ||
1062 | case FBIOGET_CON2FBMAP: | 1077 | case FBIOGET_CON2FBMAP: |
1063 | if (copy_from_user(&con2fb, argp, sizeof(con2fb))) | 1078 | if (copy_from_user(&con2fb, argp, sizeof(con2fb))) |
1064 | return -EFAULT; | 1079 | ret = -EFAULT; |
1065 | if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES) | 1080 | else if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES) |
1066 | return -EINVAL; | 1081 | ret = -EINVAL; |
1067 | con2fb.framebuffer = -1; | 1082 | else { |
1068 | event.info = info; | 1083 | con2fb.framebuffer = -1; |
1069 | event.data = &con2fb; | 1084 | event.info = info; |
1070 | fb_notifier_call_chain(FB_EVENT_GET_CONSOLE_MAP, &event); | 1085 | event.data = &con2fb; |
1071 | return copy_to_user(argp, &con2fb, | 1086 | fb_notifier_call_chain(FB_EVENT_GET_CONSOLE_MAP, |
1087 | &event); | ||
1088 | ret = copy_to_user(argp, &con2fb, | ||
1072 | sizeof(con2fb)) ? -EFAULT : 0; | 1089 | sizeof(con2fb)) ? -EFAULT : 0; |
1090 | } | ||
1091 | break; | ||
1073 | case FBIOPUT_CON2FBMAP: | 1092 | case FBIOPUT_CON2FBMAP: |
1074 | if (copy_from_user(&con2fb, argp, sizeof(con2fb))) | 1093 | if (copy_from_user(&con2fb, argp, sizeof(con2fb))) { |
1075 | return - EFAULT; | 1094 | ret = -EFAULT; |
1076 | if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES) | 1095 | break; |
1077 | return -EINVAL; | 1096 | } |
1078 | if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX) | 1097 | if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES) { |
1079 | return -EINVAL; | 1098 | ret = -EINVAL; |
1080 | if (!registered_fb[con2fb.framebuffer]) | 1099 | break; |
1081 | request_module("fb%d", con2fb.framebuffer); | 1100 | } |
1101 | if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX) { | ||
1102 | ret = -EINVAL; | ||
1103 | break; | ||
1104 | } | ||
1082 | if (!registered_fb[con2fb.framebuffer]) | 1105 | if (!registered_fb[con2fb.framebuffer]) |
1083 | return -EINVAL; | 1106 | request_module("fb%d", con2fb.framebuffer); |
1107 | if (!registered_fb[con2fb.framebuffer]) { | ||
1108 | ret = -EINVAL; | ||
1109 | break; | ||
1110 | } | ||
1084 | event.info = info; | 1111 | event.info = info; |
1085 | event.data = &con2fb; | 1112 | event.data = &con2fb; |
1086 | return fb_notifier_call_chain(FB_EVENT_SET_CONSOLE_MAP, | 1113 | ret = fb_notifier_call_chain(FB_EVENT_SET_CONSOLE_MAP, |
1087 | &event); | 1114 | &event); |
1115 | break; | ||
1088 | case FBIOBLANK: | 1116 | case FBIOBLANK: |
1089 | acquire_console_sem(); | 1117 | acquire_console_sem(); |
1090 | info->flags |= FBINFO_MISC_USEREVENT; | 1118 | info->flags |= FBINFO_MISC_USEREVENT; |
1091 | i = fb_blank(info, arg); | 1119 | ret = fb_blank(info, arg); |
1092 | info->flags &= ~FBINFO_MISC_USEREVENT; | 1120 | info->flags &= ~FBINFO_MISC_USEREVENT; |
1093 | release_console_sem(); | 1121 | release_console_sem(); |
1094 | return i; | 1122 | break;; |
1095 | default: | 1123 | default: |
1096 | if (fb->fb_ioctl == NULL) | 1124 | if (fb->fb_ioctl == NULL) |
1097 | return -EINVAL; | 1125 | ret = -ENOTTY; |
1098 | return fb->fb_ioctl(info, cmd, arg); | 1126 | else |
1127 | ret = fb->fb_ioctl(info, cmd, arg); | ||
1099 | } | 1128 | } |
1129 | mutex_unlock(&info->lock); | ||
1130 | return ret; | ||
1100 | } | 1131 | } |
1101 | 1132 | ||
1102 | #ifdef CONFIG_COMPAT | 1133 | #ifdef CONFIG_COMPAT |
@@ -1150,7 +1181,7 @@ static int fb_getput_cmap(struct inode *inode, struct file *file, | |||
1150 | put_user(compat_ptr(data), &cmap->transp)) | 1181 | put_user(compat_ptr(data), &cmap->transp)) |
1151 | return -EFAULT; | 1182 | return -EFAULT; |
1152 | 1183 | ||
1153 | err = fb_ioctl(inode, file, cmd, (unsigned long) cmap); | 1184 | err = fb_ioctl(file, cmd, (unsigned long) cmap); |
1154 | 1185 | ||
1155 | if (!err) { | 1186 | if (!err) { |
1156 | if (copy_in_user(&cmap32->start, | 1187 | if (copy_in_user(&cmap32->start, |
@@ -1204,7 +1235,7 @@ static int fb_get_fscreeninfo(struct inode *inode, struct file *file, | |||
1204 | 1235 | ||
1205 | old_fs = get_fs(); | 1236 | old_fs = get_fs(); |
1206 | set_fs(KERNEL_DS); | 1237 | set_fs(KERNEL_DS); |
1207 | err = fb_ioctl(inode, file, cmd, (unsigned long) &fix); | 1238 | err = fb_ioctl(file, cmd, (unsigned long) &fix); |
1208 | set_fs(old_fs); | 1239 | set_fs(old_fs); |
1209 | 1240 | ||
1210 | if (!err) | 1241 | if (!err) |
@@ -1222,7 +1253,7 @@ fb_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
1222 | struct fb_ops *fb = info->fbops; | 1253 | struct fb_ops *fb = info->fbops; |
1223 | long ret = -ENOIOCTLCMD; | 1254 | long ret = -ENOIOCTLCMD; |
1224 | 1255 | ||
1225 | lock_kernel(); | 1256 | mutex_lock(&info->lock); |
1226 | switch(cmd) { | 1257 | switch(cmd) { |
1227 | case FBIOGET_VSCREENINFO: | 1258 | case FBIOGET_VSCREENINFO: |
1228 | case FBIOPUT_VSCREENINFO: | 1259 | case FBIOPUT_VSCREENINFO: |
@@ -1231,7 +1262,7 @@ fb_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
1231 | case FBIOPUT_CON2FBMAP: | 1262 | case FBIOPUT_CON2FBMAP: |
1232 | arg = (unsigned long) compat_ptr(arg); | 1263 | arg = (unsigned long) compat_ptr(arg); |
1233 | case FBIOBLANK: | 1264 | case FBIOBLANK: |
1234 | ret = fb_ioctl(inode, file, cmd, arg); | 1265 | ret = fb_ioctl(file, cmd, arg); |
1235 | break; | 1266 | break; |
1236 | 1267 | ||
1237 | case FBIOGET_FSCREENINFO: | 1268 | case FBIOGET_FSCREENINFO: |
@@ -1248,7 +1279,7 @@ fb_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
1248 | ret = fb->fb_compat_ioctl(info, cmd, arg); | 1279 | ret = fb->fb_compat_ioctl(info, cmd, arg); |
1249 | break; | 1280 | break; |
1250 | } | 1281 | } |
1251 | unlock_kernel(); | 1282 | mutex_unlock(&info->lock); |
1252 | return ret; | 1283 | return ret; |
1253 | } | 1284 | } |
1254 | #endif | 1285 | #endif |
@@ -1270,13 +1301,13 @@ fb_mmap(struct file *file, struct vm_area_struct * vma) | |||
1270 | return -ENODEV; | 1301 | return -ENODEV; |
1271 | if (fb->fb_mmap) { | 1302 | if (fb->fb_mmap) { |
1272 | int res; | 1303 | int res; |
1273 | lock_kernel(); | 1304 | mutex_lock(&info->lock); |
1274 | res = fb->fb_mmap(info, vma); | 1305 | res = fb->fb_mmap(info, vma); |
1275 | unlock_kernel(); | 1306 | mutex_unlock(&info->lock); |
1276 | return res; | 1307 | return res; |
1277 | } | 1308 | } |
1278 | 1309 | ||
1279 | lock_kernel(); | 1310 | mutex_lock(&info->lock); |
1280 | 1311 | ||
1281 | /* frame buffer memory */ | 1312 | /* frame buffer memory */ |
1282 | start = info->fix.smem_start; | 1313 | start = info->fix.smem_start; |
@@ -1285,13 +1316,13 @@ fb_mmap(struct file *file, struct vm_area_struct * vma) | |||
1285 | /* memory mapped io */ | 1316 | /* memory mapped io */ |
1286 | off -= len; | 1317 | off -= len; |
1287 | if (info->var.accel_flags) { | 1318 | if (info->var.accel_flags) { |
1288 | unlock_kernel(); | 1319 | mutex_unlock(&info->lock); |
1289 | return -EINVAL; | 1320 | return -EINVAL; |
1290 | } | 1321 | } |
1291 | start = info->fix.mmio_start; | 1322 | start = info->fix.mmio_start; |
1292 | len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.mmio_len); | 1323 | len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.mmio_len); |
1293 | } | 1324 | } |
1294 | unlock_kernel(); | 1325 | mutex_unlock(&info->lock); |
1295 | start &= PAGE_MASK; | 1326 | start &= PAGE_MASK; |
1296 | if ((vma->vm_end - vma->vm_start + off) > len) | 1327 | if ((vma->vm_end - vma->vm_start + off) > len) |
1297 | return -EINVAL; | 1328 | return -EINVAL; |
@@ -1315,13 +1346,13 @@ fb_open(struct inode *inode, struct file *file) | |||
1315 | 1346 | ||
1316 | if (fbidx >= FB_MAX) | 1347 | if (fbidx >= FB_MAX) |
1317 | return -ENODEV; | 1348 | return -ENODEV; |
1318 | lock_kernel(); | 1349 | info = registered_fb[fbidx]; |
1319 | if (!(info = registered_fb[fbidx])) | 1350 | if (!info) |
1320 | request_module("fb%d", fbidx); | 1351 | request_module("fb%d", fbidx); |
1321 | if (!(info = registered_fb[fbidx])) { | 1352 | info = registered_fb[fbidx]; |
1322 | res = -ENODEV; | 1353 | if (!info) |
1323 | goto out; | 1354 | return -ENODEV; |
1324 | } | 1355 | mutex_lock(&info->lock); |
1325 | if (!try_module_get(info->fbops->owner)) { | 1356 | if (!try_module_get(info->fbops->owner)) { |
1326 | res = -ENODEV; | 1357 | res = -ENODEV; |
1327 | goto out; | 1358 | goto out; |
@@ -1337,7 +1368,7 @@ fb_open(struct inode *inode, struct file *file) | |||
1337 | fb_deferred_io_open(info, inode, file); | 1368 | fb_deferred_io_open(info, inode, file); |
1338 | #endif | 1369 | #endif |
1339 | out: | 1370 | out: |
1340 | unlock_kernel(); | 1371 | mutex_unlock(&info->lock); |
1341 | return res; | 1372 | return res; |
1342 | } | 1373 | } |
1343 | 1374 | ||
@@ -1346,11 +1377,11 @@ fb_release(struct inode *inode, struct file *file) | |||
1346 | { | 1377 | { |
1347 | struct fb_info * const info = file->private_data; | 1378 | struct fb_info * const info = file->private_data; |
1348 | 1379 | ||
1349 | lock_kernel(); | 1380 | mutex_lock(&info->lock); |
1350 | if (info->fbops->fb_release) | 1381 | if (info->fbops->fb_release) |
1351 | info->fbops->fb_release(info,1); | 1382 | info->fbops->fb_release(info,1); |
1352 | module_put(info->fbops->owner); | 1383 | module_put(info->fbops->owner); |
1353 | unlock_kernel(); | 1384 | mutex_unlock(&info->lock); |
1354 | return 0; | 1385 | return 0; |
1355 | } | 1386 | } |
1356 | 1387 | ||
@@ -1358,7 +1389,7 @@ static const struct file_operations fb_fops = { | |||
1358 | .owner = THIS_MODULE, | 1389 | .owner = THIS_MODULE, |
1359 | .read = fb_read, | 1390 | .read = fb_read, |
1360 | .write = fb_write, | 1391 | .write = fb_write, |
1361 | .ioctl = fb_ioctl, | 1392 | .unlocked_ioctl = fb_ioctl, |
1362 | #ifdef CONFIG_COMPAT | 1393 | #ifdef CONFIG_COMPAT |
1363 | .compat_ioctl = fb_compat_ioctl, | 1394 | .compat_ioctl = fb_compat_ioctl, |
1364 | #endif | 1395 | #endif |
@@ -1429,6 +1460,7 @@ register_framebuffer(struct fb_info *fb_info) | |||
1429 | if (!registered_fb[i]) | 1460 | if (!registered_fb[i]) |
1430 | break; | 1461 | break; |
1431 | fb_info->node = i; | 1462 | fb_info->node = i; |
1463 | mutex_init(&fb_info->lock); | ||
1432 | 1464 | ||
1433 | fb_info->dev = device_create(fb_class, fb_info->device, | 1465 | fb_info->dev = device_create(fb_class, fb_info->device, |
1434 | MKDEV(FB_MAJOR, i), NULL, "fb%d", i); | 1466 | MKDEV(FB_MAJOR, i), NULL, "fb%d", i); |
diff --git a/drivers/w1/slaves/w1_ds2760.c b/drivers/w1/slaves/w1_ds2760.c index ed6b0576208c..1f09d4e4144c 100644 --- a/drivers/w1/slaves/w1_ds2760.c +++ b/drivers/w1/slaves/w1_ds2760.c | |||
@@ -80,7 +80,6 @@ static struct bin_attribute w1_ds2760_bin_attr = { | |||
80 | .attr = { | 80 | .attr = { |
81 | .name = "w1_slave", | 81 | .name = "w1_slave", |
82 | .mode = S_IRUGO, | 82 | .mode = S_IRUGO, |
83 | .owner = THIS_MODULE, | ||
84 | }, | 83 | }, |
85 | .size = DS2760_DATA_SIZE, | 84 | .size = DS2760_DATA_SIZE, |
86 | .read = w1_ds2760_read_bin, | 85 | .read = w1_ds2760_read_bin, |