hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/macintosh/via-pmu.c
....@@ -50,9 +50,9 @@
5050 #include <linux/of_address.h>
5151 #include <linux/of_irq.h>
5252 #include <linux/uaccess.h>
53
+#include <linux/pgtable.h>
5354 #include <asm/machdep.h>
5455 #include <asm/io.h>
55
-#include <asm/pgtable.h>
5656 #include <asm/sections.h>
5757 #include <asm/irq.h>
5858 #ifdef CONFIG_PPC_PMAC
....@@ -74,9 +74,6 @@
7474
7575 /* Some compile options */
7676 #undef DEBUG_SLEEP
77
-
78
-/* Misc minor number allocated for /dev/pmu */
79
-#define PMU_MINOR 154
8077
8178 /* How many iterations between battery polls */
8279 #define BATTERY_POLLING_COUNT 2
....@@ -212,7 +209,7 @@
212209 static int pmu_irqstats_proc_show(struct seq_file *m, void *v);
213210 static int pmu_battery_proc_show(struct seq_file *m, void *v);
214211 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;
216213
217214 #ifdef CONFIG_ADB
218215 const struct adb_driver via_pmu_driver = {
....@@ -318,8 +315,8 @@
318315 PMU_INT_ADB |
319316 PMU_INT_TICK;
320317
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"))
323320 pmu_kind = PMU_OHARE_BASED;
324321 else if (of_device_is_compatible(vias->parent, "paddington"))
325322 pmu_kind = PMU_PADDINGTON_BASED;
....@@ -573,7 +570,7 @@
573570 proc_pmu_irqstats = proc_create_single("interrupts", 0,
574571 proc_pmu_root, pmu_irqstats_proc_show);
575572 proc_pmu_options = proc_create("options", 0600, proc_pmu_root,
576
- &pmu_options_proc_fops);
573
+ &pmu_options_proc_ops);
577574 }
578575 return 0;
579576 }
....@@ -974,13 +971,12 @@
974971 return fcount;
975972 }
976973
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,
984980 };
985981
986982 #ifdef CONFIG_ADB
....@@ -1464,7 +1460,7 @@
14641460 pmu_pass_intr(data, len);
14651461 /* len == 6 is probably a bad check. But how do I
14661462 * know what PMU versions send what events here? */
1467
- if (len == 6) {
1463
+ if (IS_ENABLED(CONFIG_ADB_PMU_EVENT) && len == 6) {
14681464 via_pmu_event(PMU_EVT_POWER, !!(data[1]&8));
14691465 via_pmu_event(PMU_EVT_LID, data[1]&1);
14701466 }
....@@ -1735,6 +1731,39 @@
17351731 pmu_request(&req, NULL, 2, PMU_POWER_CTRL, PMU_POW_IRLED |
17361732 (on ? PMU_POW_ON : PMU_POW_OFF));
17371733 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;
17381767 }
17391768
17401769 void
....@@ -2155,8 +2184,6 @@
21552184
21562185 if (count < 1 || !pp)
21572186 return -EINVAL;
2158
- if (!access_ok(VERIFY_WRITE, buf, count))
2159
- return -EFAULT;
21602187
21612188 spin_lock_irqsave(&pp->lock, flags);
21622189 add_wait_queue(&pp->wait, &wait);