.. | .. |
---|
50 | 50 | #include <linux/of_address.h> |
---|
51 | 51 | #include <linux/of_irq.h> |
---|
52 | 52 | #include <linux/uaccess.h> |
---|
| 53 | +#include <linux/pgtable.h> |
---|
53 | 54 | #include <asm/machdep.h> |
---|
54 | 55 | #include <asm/io.h> |
---|
55 | | -#include <asm/pgtable.h> |
---|
56 | 56 | #include <asm/sections.h> |
---|
57 | 57 | #include <asm/irq.h> |
---|
58 | 58 | #ifdef CONFIG_PPC_PMAC |
---|
.. | .. |
---|
74 | 74 | |
---|
75 | 75 | /* Some compile options */ |
---|
76 | 76 | #undef DEBUG_SLEEP |
---|
77 | | - |
---|
78 | | -/* Misc minor number allocated for /dev/pmu */ |
---|
79 | | -#define PMU_MINOR 154 |
---|
80 | 77 | |
---|
81 | 78 | /* How many iterations between battery polls */ |
---|
82 | 79 | #define BATTERY_POLLING_COUNT 2 |
---|
.. | .. |
---|
212 | 209 | static int pmu_irqstats_proc_show(struct seq_file *m, void *v); |
---|
213 | 210 | static int pmu_battery_proc_show(struct seq_file *m, void *v); |
---|
214 | 211 | static void pmu_pass_intr(unsigned char *data, int len); |
---|
215 | | -static const struct file_operations pmu_options_proc_fops; |
---|
| 212 | +static const struct proc_ops pmu_options_proc_ops; |
---|
216 | 213 | |
---|
217 | 214 | #ifdef CONFIG_ADB |
---|
218 | 215 | const struct adb_driver via_pmu_driver = { |
---|
.. | .. |
---|
318 | 315 | PMU_INT_ADB | |
---|
319 | 316 | PMU_INT_TICK; |
---|
320 | 317 | |
---|
321 | | - if (vias->parent->name && ((strcmp(vias->parent->name, "ohare") == 0) |
---|
322 | | - || of_device_is_compatible(vias->parent, "ohare"))) |
---|
| 318 | + if (of_node_name_eq(vias->parent, "ohare") || |
---|
| 319 | + of_device_is_compatible(vias->parent, "ohare")) |
---|
323 | 320 | pmu_kind = PMU_OHARE_BASED; |
---|
324 | 321 | else if (of_device_is_compatible(vias->parent, "paddington")) |
---|
325 | 322 | pmu_kind = PMU_PADDINGTON_BASED; |
---|
.. | .. |
---|
573 | 570 | proc_pmu_irqstats = proc_create_single("interrupts", 0, |
---|
574 | 571 | proc_pmu_root, pmu_irqstats_proc_show); |
---|
575 | 572 | proc_pmu_options = proc_create("options", 0600, proc_pmu_root, |
---|
576 | | - &pmu_options_proc_fops); |
---|
| 573 | + &pmu_options_proc_ops); |
---|
577 | 574 | } |
---|
578 | 575 | return 0; |
---|
579 | 576 | } |
---|
.. | .. |
---|
974 | 971 | return fcount; |
---|
975 | 972 | } |
---|
976 | 973 | |
---|
977 | | -static const struct file_operations pmu_options_proc_fops = { |
---|
978 | | - .owner = THIS_MODULE, |
---|
979 | | - .open = pmu_options_proc_open, |
---|
980 | | - .read = seq_read, |
---|
981 | | - .llseek = seq_lseek, |
---|
982 | | - .release = single_release, |
---|
983 | | - .write = pmu_options_proc_write, |
---|
| 974 | +static const struct proc_ops pmu_options_proc_ops = { |
---|
| 975 | + .proc_open = pmu_options_proc_open, |
---|
| 976 | + .proc_read = seq_read, |
---|
| 977 | + .proc_lseek = seq_lseek, |
---|
| 978 | + .proc_release = single_release, |
---|
| 979 | + .proc_write = pmu_options_proc_write, |
---|
984 | 980 | }; |
---|
985 | 981 | |
---|
986 | 982 | #ifdef CONFIG_ADB |
---|
.. | .. |
---|
1464 | 1460 | pmu_pass_intr(data, len); |
---|
1465 | 1461 | /* len == 6 is probably a bad check. But how do I |
---|
1466 | 1462 | * know what PMU versions send what events here? */ |
---|
1467 | | - if (len == 6) { |
---|
| 1463 | + if (IS_ENABLED(CONFIG_ADB_PMU_EVENT) && len == 6) { |
---|
1468 | 1464 | via_pmu_event(PMU_EVT_POWER, !!(data[1]&8)); |
---|
1469 | 1465 | via_pmu_event(PMU_EVT_LID, data[1]&1); |
---|
1470 | 1466 | } |
---|
.. | .. |
---|
1735 | 1731 | pmu_request(&req, NULL, 2, PMU_POWER_CTRL, PMU_POW_IRLED | |
---|
1736 | 1732 | (on ? PMU_POW_ON : PMU_POW_OFF)); |
---|
1737 | 1733 | pmu_wait_complete(&req); |
---|
| 1734 | +} |
---|
| 1735 | + |
---|
| 1736 | +/* Offset between Unix time (1970-based) and Mac time (1904-based) */ |
---|
| 1737 | +#define RTC_OFFSET 2082844800 |
---|
| 1738 | + |
---|
| 1739 | +time64_t pmu_get_time(void) |
---|
| 1740 | +{ |
---|
| 1741 | + struct adb_request req; |
---|
| 1742 | + u32 now; |
---|
| 1743 | + |
---|
| 1744 | + if (pmu_request(&req, NULL, 1, PMU_READ_RTC) < 0) |
---|
| 1745 | + return 0; |
---|
| 1746 | + pmu_wait_complete(&req); |
---|
| 1747 | + if (req.reply_len != 4) |
---|
| 1748 | + pr_err("%s: got %d byte reply\n", __func__, req.reply_len); |
---|
| 1749 | + now = (req.reply[0] << 24) + (req.reply[1] << 16) + |
---|
| 1750 | + (req.reply[2] << 8) + req.reply[3]; |
---|
| 1751 | + return (time64_t)now - RTC_OFFSET; |
---|
| 1752 | +} |
---|
| 1753 | + |
---|
| 1754 | +int pmu_set_rtc_time(struct rtc_time *tm) |
---|
| 1755 | +{ |
---|
| 1756 | + u32 now; |
---|
| 1757 | + struct adb_request req; |
---|
| 1758 | + |
---|
| 1759 | + now = lower_32_bits(rtc_tm_to_time64(tm) + RTC_OFFSET); |
---|
| 1760 | + if (pmu_request(&req, NULL, 5, PMU_SET_RTC, |
---|
| 1761 | + now >> 24, now >> 16, now >> 8, now) < 0) |
---|
| 1762 | + return -ENXIO; |
---|
| 1763 | + pmu_wait_complete(&req); |
---|
| 1764 | + if (req.reply_len != 0) |
---|
| 1765 | + pr_err("%s: got %d byte reply\n", __func__, req.reply_len); |
---|
| 1766 | + return 0; |
---|
1738 | 1767 | } |
---|
1739 | 1768 | |
---|
1740 | 1769 | void |
---|
.. | .. |
---|
2155 | 2184 | |
---|
2156 | 2185 | if (count < 1 || !pp) |
---|
2157 | 2186 | return -EINVAL; |
---|
2158 | | - if (!access_ok(VERIFY_WRITE, buf, count)) |
---|
2159 | | - return -EFAULT; |
---|
2160 | 2187 | |
---|
2161 | 2188 | spin_lock_irqsave(&pp->lock, flags); |
---|
2162 | 2189 | add_wait_queue(&pp->wait, &wait); |
---|