hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/rtc/rtc-ds1685.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * An rtc driver for the Dallas/Maxim DS1685/DS1687 and related real-time
34 * chips.
....@@ -10,10 +11,6 @@
1011 * DS17x85/DS17x87 3V/5V Real-Time Clocks, 19-5222, Rev 4/10.
1112 * DS1689/DS1693 3V/5V Serialized Real-Time Clocks, Rev 112105.
1213 * Application Note 90, Using the Multiplex Bus RTC Extended Features.
13
- *
14
- * This program is free software; you can redistribute it and/or modify
15
- * it under the terms of the GNU General Public License version 2 as
16
- * published by the Free Software Foundation.
1714 */
1815
1916 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -34,7 +31,10 @@
3431
3532
3633 /* ----------------------------------------------------------------------- */
37
-/* Standard read/write functions if platform does not provide overrides */
34
+/*
35
+ * Standard read/write
36
+ * all registers are mapped in CPU address space
37
+ */
3838
3939 /**
4040 * ds1685_read - read a value from an rtc register.
....@@ -62,6 +62,35 @@
6262 }
6363 /* ----------------------------------------------------------------------- */
6464
65
+/*
66
+ * Indirect read/write functions
67
+ * access happens via address and data register mapped in CPU address space
68
+ */
69
+
70
+/**
71
+ * ds1685_indirect_read - read a value from an rtc register.
72
+ * @rtc: pointer to the ds1685 rtc structure.
73
+ * @reg: the register address to read.
74
+ */
75
+static u8
76
+ds1685_indirect_read(struct ds1685_priv *rtc, int reg)
77
+{
78
+ writeb(reg, rtc->regs);
79
+ return readb(rtc->data);
80
+}
81
+
82
+/**
83
+ * ds1685_indirect_write - write a value to an rtc register.
84
+ * @rtc: pointer to the ds1685 rtc structure.
85
+ * @reg: the register address to write.
86
+ * @value: value to write to the register.
87
+ */
88
+static void
89
+ds1685_indirect_write(struct ds1685_priv *rtc, int reg, u8 value)
90
+{
91
+ writeb(reg, rtc->regs);
92
+ writeb(value, rtc->data);
93
+}
6594
6695 /* ----------------------------------------------------------------------- */
6796 /* Inlined functions */
....@@ -164,12 +193,12 @@
164193 rtc->write(rtc, RTC_CTRL_B,
165194 (rtc->read(rtc, RTC_CTRL_B) | RTC_CTRL_B_SET));
166195
196
+ /* Switch to Bank 1 */
197
+ ds1685_rtc_switch_to_bank1(rtc);
198
+
167199 /* Read Ext Ctrl 4A and check the INCR bit to avoid a lockout. */
168200 while (rtc->read(rtc, RTC_EXT_CTRL_4A) & RTC_CTRL_4A_INCR)
169201 cpu_relax();
170
-
171
- /* Switch to Bank 1 */
172
- ds1685_rtc_switch_to_bank1(rtc);
173202 }
174203
175204 /**
....@@ -184,47 +213,11 @@
184213 ds1685_rtc_end_data_access(struct ds1685_priv *rtc)
185214 {
186215 /* Switch back to Bank 0 */
187
- ds1685_rtc_switch_to_bank1(rtc);
216
+ ds1685_rtc_switch_to_bank0(rtc);
188217
189218 /* Clear the SET bit in Ctrl B */
190219 rtc->write(rtc, RTC_CTRL_B,
191220 (rtc->read(rtc, RTC_CTRL_B) & ~(RTC_CTRL_B_SET)));
192
-}
193
-
194
-/**
195
- * ds1685_rtc_begin_ctrl_access - prepare the rtc for ctrl access.
196
- * @rtc: pointer to the ds1685 rtc structure.
197
- * @flags: irq flags variable for spin_lock_irqsave.
198
- *
199
- * This takes several steps to prepare the rtc for access to read just the
200
- * control registers:
201
- * - Sets a spinlock on the rtc IRQ.
202
- * - Switches the rtc to bank 1. This allows access to the two extended
203
- * control registers.
204
- *
205
- * Only use this where you are certain another lock will not be held.
206
- */
207
-static inline void
208
-ds1685_rtc_begin_ctrl_access(struct ds1685_priv *rtc, unsigned long *flags)
209
-{
210
- spin_lock_irqsave(&rtc->lock, *flags);
211
- ds1685_rtc_switch_to_bank1(rtc);
212
-}
213
-
214
-/**
215
- * ds1685_rtc_end_ctrl_access - end ctrl access on the rtc.
216
- * @rtc: pointer to the ds1685 rtc structure.
217
- * @flags: irq flags variable for spin_unlock_irqrestore.
218
- *
219
- * This ends what was started by ds1685_rtc_begin_ctrl_access:
220
- * - Switches the rtc back to bank 0.
221
- * - Unsets the spinlock on the rtc IRQ.
222
- */
223
-static inline void
224
-ds1685_rtc_end_ctrl_access(struct ds1685_priv *rtc, unsigned long flags)
225
-{
226
- ds1685_rtc_switch_to_bank0(rtc);
227
- spin_unlock_irqrestore(&rtc->lock, flags);
228221 }
229222
230223 /**
....@@ -268,7 +261,7 @@
268261 ds1685_rtc_read_time(struct device *dev, struct rtc_time *tm)
269262 {
270263 struct ds1685_priv *rtc = dev_get_drvdata(dev);
271
- u8 ctrlb, century;
264
+ u8 century;
272265 u8 seconds, minutes, hours, wday, mday, month, years;
273266
274267 /* Fetch the time info from the RTC registers. */
....@@ -281,7 +274,6 @@
281274 month = rtc->read(rtc, RTC_MONTH);
282275 years = rtc->read(rtc, RTC_YEAR);
283276 century = rtc->read(rtc, RTC_CENTURY);
284
- ctrlb = rtc->read(rtc, RTC_CTRL_B);
285277 ds1685_rtc_end_data_access(rtc);
286278
287279 /* bcd2bin if needed, perform fixups, and store to rtc_time. */
....@@ -546,10 +538,6 @@
546538 ds1685_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
547539 {
548540 struct ds1685_priv *rtc = dev_get_drvdata(dev);
549
- unsigned long flags = 0;
550
-
551
- /* Enable/disable the Alarm IRQ-Enable flag. */
552
- spin_lock_irqsave(&rtc->lock, flags);
553541
554542 /* Flip the requisite interrupt-enable bit. */
555543 if (enabled)
....@@ -561,7 +549,6 @@
561549
562550 /* Read Control C to clear all the flag bits. */
563551 rtc->read(rtc, RTC_CTRL_C);
564
- spin_unlock_irqrestore(&rtc->lock, flags);
565552
566553 return 0;
567554 }
....@@ -569,97 +556,17 @@
569556
570557
571558 /* ----------------------------------------------------------------------- */
572
-/* IRQ handler & workqueue. */
559
+/* IRQ handler */
573560
574561 /**
575
- * ds1685_rtc_irq_handler - IRQ handler.
576
- * @irq: IRQ number.
577
- * @dev_id: platform device pointer.
578
- */
579
-static irqreturn_t
580
-ds1685_rtc_irq_handler(int irq, void *dev_id)
581
-{
582
- struct platform_device *pdev = dev_id;
583
- struct ds1685_priv *rtc = platform_get_drvdata(pdev);
584
- u8 ctrlb, ctrlc;
585
- unsigned long events = 0;
586
- u8 num_irqs = 0;
587
-
588
- /* Abort early if the device isn't ready yet (i.e., DEBUG_SHIRQ). */
589
- if (unlikely(!rtc))
590
- return IRQ_HANDLED;
591
-
592
- /* Ctrlb holds the interrupt-enable bits and ctrlc the flag bits. */
593
- spin_lock(&rtc->lock);
594
- ctrlb = rtc->read(rtc, RTC_CTRL_B);
595
- ctrlc = rtc->read(rtc, RTC_CTRL_C);
596
-
597
- /* Is the IRQF bit set? */
598
- if (likely(ctrlc & RTC_CTRL_C_IRQF)) {
599
- /*
600
- * We need to determine if it was one of the standard
601
- * events: PF, AF, or UF. If so, we handle them and
602
- * update the RTC core.
603
- */
604
- if (likely(ctrlc & RTC_CTRL_B_PAU_MASK)) {
605
- events = RTC_IRQF;
606
-
607
- /* Check for a periodic interrupt. */
608
- if ((ctrlb & RTC_CTRL_B_PIE) &&
609
- (ctrlc & RTC_CTRL_C_PF)) {
610
- events |= RTC_PF;
611
- num_irqs++;
612
- }
613
-
614
- /* Check for an alarm interrupt. */
615
- if ((ctrlb & RTC_CTRL_B_AIE) &&
616
- (ctrlc & RTC_CTRL_C_AF)) {
617
- events |= RTC_AF;
618
- num_irqs++;
619
- }
620
-
621
- /* Check for an update interrupt. */
622
- if ((ctrlb & RTC_CTRL_B_UIE) &&
623
- (ctrlc & RTC_CTRL_C_UF)) {
624
- events |= RTC_UF;
625
- num_irqs++;
626
- }
627
-
628
- rtc_update_irq(rtc->dev, num_irqs, events);
629
- } else {
630
- /*
631
- * One of the "extended" interrupts was received that
632
- * is not recognized by the RTC core. These need to
633
- * be handled in task context as they can call other
634
- * functions and the time spent in irq context needs
635
- * to be minimized. Schedule them into a workqueue
636
- * and inform the RTC core that the IRQs were handled.
637
- */
638
- spin_unlock(&rtc->lock);
639
- schedule_work(&rtc->work);
640
- rtc_update_irq(rtc->dev, 0, 0);
641
- return IRQ_HANDLED;
642
- }
643
- }
644
- spin_unlock(&rtc->lock);
645
-
646
- return events ? IRQ_HANDLED : IRQ_NONE;
647
-}
648
-
649
-/**
650
- * ds1685_rtc_work_queue - work queue handler.
651
- * @work: work_struct containing data to work on in task context.
562
+ * ds1685_rtc_extended_irq - take care of extended interrupts
563
+ * @rtc: pointer to the ds1685 rtc structure.
564
+ * @pdev: platform device pointer.
652565 */
653566 static void
654
-ds1685_rtc_work_queue(struct work_struct *work)
567
+ds1685_rtc_extended_irq(struct ds1685_priv *rtc, struct platform_device *pdev)
655568 {
656
- struct ds1685_priv *rtc = container_of(work,
657
- struct ds1685_priv, work);
658
- struct platform_device *pdev = to_platform_device(&rtc->dev->dev);
659
- struct mutex *rtc_mutex = &rtc->dev->ops_lock;
660569 u8 ctrl4a, ctrl4b;
661
-
662
- mutex_lock(rtc_mutex);
663570
664571 ds1685_rtc_switch_to_bank1(rtc);
665572 ctrl4a = rtc->read(rtc, RTC_EXT_CTRL_4A);
....@@ -739,8 +646,76 @@
739646 "RAM-Clear IRQ just occurred!\n");
740647 }
741648 ds1685_rtc_switch_to_bank0(rtc);
649
+}
742650
651
+/**
652
+ * ds1685_rtc_irq_handler - IRQ handler.
653
+ * @irq: IRQ number.
654
+ * @dev_id: platform device pointer.
655
+ */
656
+static irqreturn_t
657
+ds1685_rtc_irq_handler(int irq, void *dev_id)
658
+{
659
+ struct platform_device *pdev = dev_id;
660
+ struct ds1685_priv *rtc = platform_get_drvdata(pdev);
661
+ struct mutex *rtc_mutex;
662
+ u8 ctrlb, ctrlc;
663
+ unsigned long events = 0;
664
+ u8 num_irqs = 0;
665
+
666
+ /* Abort early if the device isn't ready yet (i.e., DEBUG_SHIRQ). */
667
+ if (unlikely(!rtc))
668
+ return IRQ_HANDLED;
669
+
670
+ rtc_mutex = &rtc->dev->ops_lock;
671
+ mutex_lock(rtc_mutex);
672
+
673
+ /* Ctrlb holds the interrupt-enable bits and ctrlc the flag bits. */
674
+ ctrlb = rtc->read(rtc, RTC_CTRL_B);
675
+ ctrlc = rtc->read(rtc, RTC_CTRL_C);
676
+
677
+ /* Is the IRQF bit set? */
678
+ if (likely(ctrlc & RTC_CTRL_C_IRQF)) {
679
+ /*
680
+ * We need to determine if it was one of the standard
681
+ * events: PF, AF, or UF. If so, we handle them and
682
+ * update the RTC core.
683
+ */
684
+ if (likely(ctrlc & RTC_CTRL_B_PAU_MASK)) {
685
+ events = RTC_IRQF;
686
+
687
+ /* Check for a periodic interrupt. */
688
+ if ((ctrlb & RTC_CTRL_B_PIE) &&
689
+ (ctrlc & RTC_CTRL_C_PF)) {
690
+ events |= RTC_PF;
691
+ num_irqs++;
692
+ }
693
+
694
+ /* Check for an alarm interrupt. */
695
+ if ((ctrlb & RTC_CTRL_B_AIE) &&
696
+ (ctrlc & RTC_CTRL_C_AF)) {
697
+ events |= RTC_AF;
698
+ num_irqs++;
699
+ }
700
+
701
+ /* Check for an update interrupt. */
702
+ if ((ctrlb & RTC_CTRL_B_UIE) &&
703
+ (ctrlc & RTC_CTRL_C_UF)) {
704
+ events |= RTC_UF;
705
+ num_irqs++;
706
+ }
707
+ } else {
708
+ /*
709
+ * One of the "extended" interrupts was received that
710
+ * is not recognized by the RTC core.
711
+ */
712
+ ds1685_rtc_extended_irq(rtc, pdev);
713
+ }
714
+ }
715
+ rtc_update_irq(rtc->dev, num_irqs, events);
743716 mutex_unlock(rtc_mutex);
717
+
718
+ return events ? IRQ_HANDLED : IRQ_NONE;
744719 }
745720 /* ----------------------------------------------------------------------- */
746721
....@@ -770,33 +745,6 @@
770745 "512Hz", "256Hz", "128Hz", "64Hz", "32Hz", "16Hz", "8Hz", "4Hz", "2Hz"
771746 };
772747
773
-#ifdef CONFIG_RTC_DS1685_PROC_REGS
774
-/**
775
- * ds1685_rtc_print_regs - helper function to print register values.
776
- * @hex: hex byte to convert into binary bits.
777
- * @dest: destination char array.
778
- *
779
- * This is basically a hex->binary function, just with extra spacing between
780
- * the digits. It only works on 1-byte values (8 bits).
781
- */
782
-static char*
783
-ds1685_rtc_print_regs(u8 hex, char *dest)
784
-{
785
- u32 i, j;
786
- char *tmp = dest;
787
-
788
- for (i = 0; i < NUM_BITS; i++) {
789
- *tmp++ = ((hex & 0x80) != 0 ? '1' : '0');
790
- for (j = 0; j < NUM_SPACES; j++)
791
- *tmp++ = ' ';
792
- hex <<= 1;
793
- }
794
- *tmp++ = '\0';
795
-
796
- return dest;
797
-}
798
-#endif
799
-
800748 /**
801749 * ds1685_rtc_proc - procfs access function.
802750 * @dev: pointer to device structure.
....@@ -805,20 +753,15 @@
805753 static int
806754 ds1685_rtc_proc(struct device *dev, struct seq_file *seq)
807755 {
808
- struct platform_device *pdev = to_platform_device(dev);
809
- struct ds1685_priv *rtc = platform_get_drvdata(pdev);
810
- u8 ctrla, ctrlb, ctrlc, ctrld, ctrl4a, ctrl4b, ssn[8];
756
+ struct ds1685_priv *rtc = dev_get_drvdata(dev);
757
+ u8 ctrla, ctrlb, ctrld, ctrl4a, ctrl4b, ssn[8];
811758 char *model;
812
-#ifdef CONFIG_RTC_DS1685_PROC_REGS
813
- char bits[NUM_REGS][(NUM_BITS * NUM_SPACES) + NUM_BITS + 1];
814
-#endif
815759
816760 /* Read all the relevant data from the control registers. */
817761 ds1685_rtc_switch_to_bank1(rtc);
818762 ds1685_rtc_get_ssn(rtc, ssn);
819763 ctrla = rtc->read(rtc, RTC_CTRL_A);
820764 ctrlb = rtc->read(rtc, RTC_CTRL_B);
821
- ctrlc = rtc->read(rtc, RTC_CTRL_C);
822765 ctrld = rtc->read(rtc, RTC_CTRL_D);
823766 ctrl4a = rtc->read(rtc, RTC_EXT_CTRL_4A);
824767 ctrl4b = rtc->read(rtc, RTC_EXT_CTRL_4B);
....@@ -859,28 +802,7 @@
859802 "Periodic IRQ\t: %s\n"
860803 "Periodic Rate\t: %s\n"
861804 "SQW Freq\t: %s\n"
862
-#ifdef CONFIG_RTC_DS1685_PROC_REGS
863
- "Serial #\t: %8phC\n"
864
- "Register Status\t:\n"
865
- " Ctrl A\t: UIP DV2 DV1 DV0 RS3 RS2 RS1 RS0\n"
866
- "\t\t: %s\n"
867
- " Ctrl B\t: SET PIE AIE UIE SQWE DM 2412 DSE\n"
868
- "\t\t: %s\n"
869
- " Ctrl C\t: IRQF PF AF UF --- --- --- ---\n"
870
- "\t\t: %s\n"
871
- " Ctrl D\t: VRT --- --- --- --- --- --- ---\n"
872
- "\t\t: %s\n"
873
-#if !defined(CONFIG_RTC_DRV_DS1685) && !defined(CONFIG_RTC_DRV_DS1689)
874
- " Ctrl 4A\t: VRT2 INCR BME --- PAB RF WF KF\n"
875
-#else
876
- " Ctrl 4A\t: VRT2 INCR --- --- PAB RF WF KF\n"
877
-#endif
878
- "\t\t: %s\n"
879
- " Ctrl 4B\t: ABE E32k CS RCE PRS RIE WIE KSE\n"
880
- "\t\t: %s\n",
881
-#else
882805 "Serial #\t: %8phC\n",
883
-#endif
884806 model,
885807 ((ctrla & RTC_CTRL_A_DV1) ? "enabled" : "disabled"),
886808 ((ctrlb & RTC_CTRL_B_2412) ? "24-hour" : "12-hour"),
....@@ -894,17 +816,7 @@
894816 ds1685_rtc_pirq_rate[(ctrla & RTC_CTRL_A_RS_MASK)] : "none"),
895817 (!((ctrl4b & RTC_CTRL_4B_E32K)) ?
896818 ds1685_rtc_sqw_freq[(ctrla & RTC_CTRL_A_RS_MASK)] : "32768Hz"),
897
-#ifdef CONFIG_RTC_DS1685_PROC_REGS
898
- ssn,
899
- ds1685_rtc_print_regs(ctrla, bits[0]),
900
- ds1685_rtc_print_regs(ctrlb, bits[1]),
901
- ds1685_rtc_print_regs(ctrlc, bits[2]),
902
- ds1685_rtc_print_regs(ctrld, bits[3]),
903
- ds1685_rtc_print_regs(ctrl4a, bits[4]),
904
- ds1685_rtc_print_regs(ctrl4b, bits[5]));
905
-#else
906819 ssn);
907
-#endif
908820 return 0;
909821 }
910822 #else
....@@ -927,32 +839,19 @@
927839 };
928840 /* ----------------------------------------------------------------------- */
929841
930
-
931
-/* ----------------------------------------------------------------------- */
932
-/* SysFS interface */
933
-
934
-#ifdef CONFIG_SYSFS
935
-/**
936
- * ds1685_rtc_sysfs_nvram_read - reads rtc nvram via sysfs.
937
- * @file: pointer to file structure.
938
- * @kobj: pointer to kobject structure.
939
- * @bin_attr: pointer to bin_attribute structure.
940
- * @buf: pointer to char array to hold the output.
941
- * @pos: current file position pointer.
942
- * @size: size of the data to read.
943
- */
944
-static ssize_t
945
-ds1685_rtc_sysfs_nvram_read(struct file *filp, struct kobject *kobj,
946
- struct bin_attribute *bin_attr, char *buf,
947
- loff_t pos, size_t size)
842
+static int ds1685_nvram_read(void *priv, unsigned int pos, void *val,
843
+ size_t size)
948844 {
949
- struct platform_device *pdev =
950
- to_platform_device(container_of(kobj, struct device, kobj));
951
- struct ds1685_priv *rtc = platform_get_drvdata(pdev);
845
+ struct ds1685_priv *rtc = priv;
846
+ struct mutex *rtc_mutex = &rtc->dev->ops_lock;
952847 ssize_t count;
953
- unsigned long flags = 0;
848
+ u8 *buf = val;
849
+ int err;
954850
955
- spin_lock_irqsave(&rtc->lock, flags);
851
+ err = mutex_lock_interruptible(rtc_mutex);
852
+ if (err)
853
+ return err;
854
+
956855 ds1685_rtc_switch_to_bank0(rtc);
957856
958857 /* Read NVRAM in time and bank0 registers. */
....@@ -1002,37 +901,24 @@
1002901 ds1685_rtc_switch_to_bank0(rtc);
1003902 }
1004903 #endif /* !CONFIG_RTC_DRV_DS1689 */
1005
- spin_unlock_irqrestore(&rtc->lock, flags);
904
+ mutex_unlock(rtc_mutex);
1006905
1007
- /*
1008
- * XXX: Bug? this appears to cause the function to get executed
1009
- * several times in succession. But it's the only way to actually get
1010
- * data written out to a file.
1011
- */
1012
- return count;
906
+ return 0;
1013907 }
1014908
1015
-/**
1016
- * ds1685_rtc_sysfs_nvram_write - writes rtc nvram via sysfs.
1017
- * @file: pointer to file structure.
1018
- * @kobj: pointer to kobject structure.
1019
- * @bin_attr: pointer to bin_attribute structure.
1020
- * @buf: pointer to char array to hold the input.
1021
- * @pos: current file position pointer.
1022
- * @size: size of the data to write.
1023
- */
1024
-static ssize_t
1025
-ds1685_rtc_sysfs_nvram_write(struct file *filp, struct kobject *kobj,
1026
- struct bin_attribute *bin_attr, char *buf,
1027
- loff_t pos, size_t size)
909
+static int ds1685_nvram_write(void *priv, unsigned int pos, void *val,
910
+ size_t size)
1028911 {
1029
- struct platform_device *pdev =
1030
- to_platform_device(container_of(kobj, struct device, kobj));
1031
- struct ds1685_priv *rtc = platform_get_drvdata(pdev);
912
+ struct ds1685_priv *rtc = priv;
913
+ struct mutex *rtc_mutex = &rtc->dev->ops_lock;
1032914 ssize_t count;
1033
- unsigned long flags = 0;
915
+ u8 *buf = val;
916
+ int err;
1034917
1035
- spin_lock_irqsave(&rtc->lock, flags);
918
+ err = mutex_lock_interruptible(rtc_mutex);
919
+ if (err)
920
+ return err;
921
+
1036922 ds1685_rtc_switch_to_bank0(rtc);
1037923
1038924 /* Write NVRAM in time and bank0 registers. */
....@@ -1082,28 +968,13 @@
1082968 ds1685_rtc_switch_to_bank0(rtc);
1083969 }
1084970 #endif /* !CONFIG_RTC_DRV_DS1689 */
1085
- spin_unlock_irqrestore(&rtc->lock, flags);
971
+ mutex_unlock(rtc_mutex);
1086972
1087
- return count;
973
+ return 0;
1088974 }
1089975
1090
-/**
1091
- * struct ds1685_rtc_sysfs_nvram_attr - sysfs attributes for rtc nvram.
1092
- * @attr: nvram attributes.
1093
- * @read: nvram read function.
1094
- * @write: nvram write function.
1095
- * @size: nvram total size (bank0 + extended).
1096
- */
1097
-static struct bin_attribute
1098
-ds1685_rtc_sysfs_nvram_attr = {
1099
- .attr = {
1100
- .name = "nvram",
1101
- .mode = S_IRUGO | S_IWUSR,
1102
- },
1103
- .read = ds1685_rtc_sysfs_nvram_read,
1104
- .write = ds1685_rtc_sysfs_nvram_write,
1105
- .size = NVRAM_TOTAL_SZ
1106
-};
976
+/* ----------------------------------------------------------------------- */
977
+/* SysFS interface */
1107978
1108979 /**
1109980 * ds1685_rtc_sysfs_battery_show - sysfs file for main battery status.
....@@ -1115,7 +986,7 @@
1115986 ds1685_rtc_sysfs_battery_show(struct device *dev,
1116987 struct device_attribute *attr, char *buf)
1117988 {
1118
- struct ds1685_priv *rtc = dev_get_drvdata(dev);
989
+ struct ds1685_priv *rtc = dev_get_drvdata(dev->parent);
1119990 u8 ctrld;
1120991
1121992 ctrld = rtc->read(rtc, RTC_CTRL_D);
....@@ -1135,7 +1006,7 @@
11351006 ds1685_rtc_sysfs_auxbatt_show(struct device *dev,
11361007 struct device_attribute *attr, char *buf)
11371008 {
1138
- struct ds1685_priv *rtc = dev_get_drvdata(dev);
1009
+ struct ds1685_priv *rtc = dev_get_drvdata(dev->parent);
11391010 u8 ctrl4a;
11401011
11411012 ds1685_rtc_switch_to_bank1(rtc);
....@@ -1157,7 +1028,7 @@
11571028 ds1685_rtc_sysfs_serial_show(struct device *dev,
11581029 struct device_attribute *attr, char *buf)
11591030 {
1160
- struct ds1685_priv *rtc = dev_get_drvdata(dev);
1031
+ struct ds1685_priv *rtc = dev_get_drvdata(dev->parent);
11611032 u8 ssn[8];
11621033
11631034 ds1685_rtc_switch_to_bank1(rtc);
....@@ -1168,7 +1039,7 @@
11681039 }
11691040 static DEVICE_ATTR(serial, S_IRUGO, ds1685_rtc_sysfs_serial_show, NULL);
11701041
1171
-/**
1042
+/*
11721043 * struct ds1685_rtc_sysfs_misc_attrs - list for misc RTC features.
11731044 */
11741045 static struct attribute*
....@@ -1179,7 +1050,7 @@
11791050 NULL,
11801051 };
11811052
1182
-/**
1053
+/*
11831054 * struct ds1685_rtc_sysfs_misc_grp - attr group for misc RTC features.
11841055 */
11851056 static const struct attribute_group
....@@ -1187,43 +1058,6 @@
11871058 .name = "misc",
11881059 .attrs = ds1685_rtc_sysfs_misc_attrs,
11891060 };
1190
-
1191
-/**
1192
- * ds1685_rtc_sysfs_register - register sysfs files.
1193
- * @dev: pointer to device structure.
1194
- */
1195
-static int
1196
-ds1685_rtc_sysfs_register(struct device *dev)
1197
-{
1198
- int ret = 0;
1199
-
1200
- sysfs_bin_attr_init(&ds1685_rtc_sysfs_nvram_attr);
1201
- ret = sysfs_create_bin_file(&dev->kobj, &ds1685_rtc_sysfs_nvram_attr);
1202
- if (ret)
1203
- return ret;
1204
-
1205
- ret = sysfs_create_group(&dev->kobj, &ds1685_rtc_sysfs_misc_grp);
1206
- if (ret)
1207
- return ret;
1208
-
1209
- return 0;
1210
-}
1211
-
1212
-/**
1213
- * ds1685_rtc_sysfs_unregister - unregister sysfs files.
1214
- * @dev: pointer to device structure.
1215
- */
1216
-static int
1217
-ds1685_rtc_sysfs_unregister(struct device *dev)
1218
-{
1219
- sysfs_remove_bin_file(&dev->kobj, &ds1685_rtc_sysfs_nvram_attr);
1220
- sysfs_remove_group(&dev->kobj, &ds1685_rtc_sysfs_misc_grp);
1221
-
1222
- return 0;
1223
-}
1224
-#endif /* CONFIG_SYSFS */
1225
-
1226
-
12271061
12281062 /* ----------------------------------------------------------------------- */
12291063 /* Driver Probe/Removal */
....@@ -1236,12 +1070,17 @@
12361070 ds1685_rtc_probe(struct platform_device *pdev)
12371071 {
12381072 struct rtc_device *rtc_dev;
1239
- struct resource *res;
12401073 struct ds1685_priv *rtc;
12411074 struct ds1685_rtc_platform_data *pdata;
12421075 u8 ctrla, ctrlb, hours;
12431076 unsigned char am_pm;
12441077 int ret = 0;
1078
+ struct nvmem_config nvmem_cfg = {
1079
+ .name = "ds1685_nvram",
1080
+ .size = NVRAM_TOTAL_SZ,
1081
+ .reg_read = ds1685_nvram_read,
1082
+ .reg_write = ds1685_nvram_write,
1083
+ };
12451084
12461085 /* Get the platform data. */
12471086 pdata = (struct ds1685_rtc_platform_data *) pdev->dev.platform_data;
....@@ -1253,59 +1092,35 @@
12531092 if (!rtc)
12541093 return -ENOMEM;
12551094
1256
- /*
1257
- * Allocate/setup any IORESOURCE_MEM resources, if required. Not all
1258
- * platforms put the RTC in an easy-access place. Like the SGI Octane,
1259
- * which attaches the RTC to a "ByteBus", hooked to a SuperIO chip
1260
- * that sits behind the IOC3 PCI metadevice.
1261
- */
1262
- if (pdata->alloc_io_resources) {
1263
- /* Get the platform resources. */
1264
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1265
- if (!res)
1266
- return -ENXIO;
1267
- rtc->size = resource_size(res);
1268
-
1269
- /* Request a memory region. */
1270
- /* XXX: mmio-only for now. */
1271
- if (!devm_request_mem_region(&pdev->dev, res->start, rtc->size,
1272
- pdev->name))
1273
- return -EBUSY;
1274
-
1275
- /*
1276
- * Set the base address for the rtc, and ioremap its
1277
- * registers.
1278
- */
1279
- rtc->baseaddr = res->start;
1280
- rtc->regs = devm_ioremap(&pdev->dev, res->start, rtc->size);
1281
- if (!rtc->regs)
1282
- return -ENOMEM;
1095
+ /* Setup resources and access functions */
1096
+ switch (pdata->access_type) {
1097
+ case ds1685_reg_direct:
1098
+ rtc->regs = devm_platform_ioremap_resource(pdev, 0);
1099
+ if (IS_ERR(rtc->regs))
1100
+ return PTR_ERR(rtc->regs);
1101
+ rtc->read = ds1685_read;
1102
+ rtc->write = ds1685_write;
1103
+ break;
1104
+ case ds1685_reg_indirect:
1105
+ rtc->regs = devm_platform_ioremap_resource(pdev, 0);
1106
+ if (IS_ERR(rtc->regs))
1107
+ return PTR_ERR(rtc->regs);
1108
+ rtc->data = devm_platform_ioremap_resource(pdev, 1);
1109
+ if (IS_ERR(rtc->data))
1110
+ return PTR_ERR(rtc->data);
1111
+ rtc->read = ds1685_indirect_read;
1112
+ rtc->write = ds1685_indirect_write;
1113
+ break;
12831114 }
1284
- rtc->alloc_io_resources = pdata->alloc_io_resources;
1115
+
1116
+ if (!rtc->read || !rtc->write)
1117
+ return -ENXIO;
12851118
12861119 /* Get the register step size. */
12871120 if (pdata->regstep > 0)
12881121 rtc->regstep = pdata->regstep;
12891122 else
12901123 rtc->regstep = 1;
1291
-
1292
- /* Platform read function, else default if mmio setup */
1293
- if (pdata->plat_read)
1294
- rtc->read = pdata->plat_read;
1295
- else
1296
- if (pdata->alloc_io_resources)
1297
- rtc->read = ds1685_read;
1298
- else
1299
- return -ENXIO;
1300
-
1301
- /* Platform write function, else default if mmio setup */
1302
- if (pdata->plat_write)
1303
- rtc->write = pdata->plat_write;
1304
- else
1305
- if (pdata->alloc_io_resources)
1306
- rtc->write = ds1685_write;
1307
- else
1308
- return -ENXIO;
13091124
13101125 /* Platform pre-shutdown function, if defined. */
13111126 if (pdata->plat_prepare_poweroff)
....@@ -1319,9 +1134,7 @@
13191134 if (pdata->plat_post_ram_clear)
13201135 rtc->post_ram_clear = pdata->plat_post_ram_clear;
13211136
1322
- /* Init the spinlock, workqueue, & set the driver data. */
1323
- spin_lock_init(&rtc->lock);
1324
- INIT_WORK(&rtc->work, ds1685_rtc_work_queue);
1137
+ /* set the driver data. */
13251138 platform_set_drvdata(pdev, rtc);
13261139
13271140 /* Turn the oscillator on if is not already on (DV1 = 1). */
....@@ -1463,7 +1276,6 @@
14631276 /* See if the platform doesn't support UIE. */
14641277 if (pdata->uie_unsupported)
14651278 rtc_dev->uie_unsupported = 1;
1466
- rtc->uie_unsupported = pdata->uie_unsupported;
14671279
14681280 rtc->dev = rtc_dev;
14691281
....@@ -1477,33 +1289,38 @@
14771289 */
14781290 if (!pdata->no_irq) {
14791291 ret = platform_get_irq(pdev, 0);
1480
- if (ret > 0) {
1481
- rtc->irq_num = ret;
1482
-
1483
- /* Request an IRQ. */
1484
- ret = devm_request_irq(&pdev->dev, rtc->irq_num,
1485
- ds1685_rtc_irq_handler,
1486
- IRQF_SHARED, pdev->name, pdev);
1487
-
1488
- /* Check to see if something came back. */
1489
- if (unlikely(ret)) {
1490
- dev_warn(&pdev->dev,
1491
- "RTC interrupt not available\n");
1492
- rtc->irq_num = 0;
1493
- }
1494
- } else
1292
+ if (ret <= 0)
14951293 return ret;
1294
+
1295
+ rtc->irq_num = ret;
1296
+
1297
+ /* Request an IRQ. */
1298
+ ret = devm_request_threaded_irq(&pdev->dev, rtc->irq_num,
1299
+ NULL, ds1685_rtc_irq_handler,
1300
+ IRQF_SHARED | IRQF_ONESHOT,
1301
+ pdev->name, pdev);
1302
+
1303
+ /* Check to see if something came back. */
1304
+ if (unlikely(ret)) {
1305
+ dev_warn(&pdev->dev,
1306
+ "RTC interrupt not available\n");
1307
+ rtc->irq_num = 0;
1308
+ }
14961309 }
14971310 rtc->no_irq = pdata->no_irq;
14981311
14991312 /* Setup complete. */
15001313 ds1685_rtc_switch_to_bank0(rtc);
15011314
1502
-#ifdef CONFIG_SYSFS
1503
- ret = ds1685_rtc_sysfs_register(&pdev->dev);
1315
+ ret = rtc_add_group(rtc_dev, &ds1685_rtc_sysfs_misc_grp);
15041316 if (ret)
15051317 return ret;
1506
-#endif
1318
+
1319
+ rtc_dev->nvram_old_abi = true;
1320
+ nvmem_cfg.priv = rtc;
1321
+ ret = rtc_nvmem_register(rtc_dev, &nvmem_cfg);
1322
+ if (ret)
1323
+ return ret;
15071324
15081325 return rtc_register_device(rtc_dev);
15091326 }
....@@ -1516,10 +1333,6 @@
15161333 ds1685_rtc_remove(struct platform_device *pdev)
15171334 {
15181335 struct ds1685_priv *rtc = platform_get_drvdata(pdev);
1519
-
1520
-#ifdef CONFIG_SYSFS
1521
- ds1685_rtc_sysfs_unregister(&pdev->dev);
1522
-#endif
15231336
15241337 /* Read Ctrl B and clear PIE/AIE/UIE. */
15251338 rtc->write(rtc, RTC_CTRL_B,
....@@ -1539,12 +1352,10 @@
15391352 (rtc->read(rtc, RTC_EXT_CTRL_4A) &
15401353 ~(RTC_CTRL_4A_RWK_MASK)));
15411354
1542
- cancel_work_sync(&rtc->work);
1543
-
15441355 return 0;
15451356 }
15461357
1547
-/**
1358
+/*
15481359 * ds1685_rtc_driver - rtc driver properties.
15491360 */
15501361 static struct platform_driver ds1685_rtc_driver = {
....@@ -1630,7 +1441,7 @@
16301441 unreachable();
16311442 }
16321443 }
1633
-EXPORT_SYMBOL(ds1685_rtc_poweroff);
1444
+EXPORT_SYMBOL_GPL(ds1685_rtc_poweroff);
16341445 /* ----------------------------------------------------------------------- */
16351446
16361447