Skip to contentSkip to conversation

rtc/tpo: Driver to support rtc and wakeup on PowerNV platform

PATCH In review Neelesh Gupta 2 participants 3 messages Oct 14, 2014 – Nov 17, 2014 2 messages not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 rtc/tpo: Driver to support rtc and wakeup on PowerNV platform

The patch implements the OPAL rtc driver that binds with the rtc driver subsystem. The driver uses the platform device infrastructure to probe the rtc device and register it to rtc class framework. The 'wakeup' is supported depending upon the property 'has-tpo' present in the OF node. It provides a way to load the generic rtc driver in in the absence of an OPAL driver.

The patch also moves the existing OPAL rtc get/set time interfaces to the new driver and exposes the necessary OPAL calls using EXPORT_SYMBOL_GPL.

Test results:
-------------
Host:
[root@tul169p1 ~]# ls -l /sys/class/rtc/
total 0
lrwxrwxrwx 1 root root 0 Oct 14 03:07 rtc0 -> ../../devices/opal-rtc/rtc/rtc0 [root@tul169p1 ~]# cat /sys/devices/opal-rtc/rtc/rtc0/time
08:10:07
[root@tul169p1 ~]# echo date '+%s' -d '+ 2 minutes' > /sys/class/rtc/rtc0/wakealarm [root@tul169p1 ~]# cat /sys/class/rtc/rtc0/wakealarm
1413274345
[root@tul169p1 ~]#

FSP:

$ smgr mfgState
standby
$ rtim timeofday

System time is valid: 2014/10/14 08:12:04.225115

$ smgr mfgState
ipling
$ 

---

Changes in v3
=============
- Rebased to the latest tree.

Changes in v2
=============
- Added Documentation/devicetree/bindings/rtc/rtc-opal.txt
- Explicitly turn off RTC_UIE mode by setting 'rtc->uie_unsupported'

 Documentation/devicetree/bindings/rtc/rtc-opal.txt |   16 +
 arch/powerpc/include/asm/opal.h                    |    7 -
 arch/powerpc/kernel/time.c                         |    1 
 arch/powerpc/platforms/powernv/opal-async.c        |    3 
 arch/powerpc/platforms/powernv/opal-rtc.c          |   65 +----
 arch/powerpc/platforms/powernv/opal-wrappers.S     |    2 
 arch/powerpc/platforms/powernv/opal.c              |    6 
 arch/powerpc/platforms/powernv/setup.c             |    2 
 drivers/rtc/Kconfig                                |   11 +
 drivers/rtc/Makefile                               |    1 
 drivers/rtc/rtc-opal.c                             |  261 ++++++++++++++++++++
 11 files changed, 325 insertions(+), 50 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/rtc/rtc-opal.txt
 create mode 100644 drivers/rtc/rtc-opal.c
Documentation/devicetree/bindings/rtc/rtc-opal.txt new file +16 -0
new file mode 100644
index 0000000..af87e5e
@@ -0,0 +1,16 @@
+IBM OPAL real-time clock
+------------------------
+
+Required properties:
+- comapatible: Should be "ibm,opal-rtc"
+
+Optional properties:
+- has-tpo: Decides if the wakeup is supported or not.
+
+Example:
+	rtc {
+		compatible = "ibm,opal-rtc";
+		has-tpo;
+		phandle = <0x10000029>;
+		linux,phandle = <0x10000029>;
+	};
arch/powerpc/include/asm/opal.h +5 -2
index 9124b0e..2c20561 100644
@@ -154,6 +154,8 @@ struct opal_sg_list {
 #define OPAL_HANDLE_HMI				98
 #define OPAL_REGISTER_DUMP_REGION		101
 #define OPAL_UNREGISTER_DUMP_REGION		102
+#define OPAL_WRITE_TPO				103
+#define OPAL_READ_TPO				104
 
 #ifndef __ASSEMBLY__
 
@@ -819,6 +821,9 @@ int64_t opal_rtc_read(__be32 *year_month_day,
 		      __be64 *hour_minute_second_millisecond);
 int64_t opal_rtc_write(uint32_t year_month_day,
 		       uint64_t hour_minute_second_millisecond);
+int64_t opal_tpo_read(uint64_t token, __be32 *year_mon_day, __be32 *hour_min);
+int64_t opal_tpo_write(uint64_t token, uint32_t year_mon_day,
+		       uint32_t hour_min);
 int64_t opal_cec_power_down(uint64_t request);
 int64_t opal_cec_reboot(void);
 int64_t opal_read_nvram(uint64_t buffer, uint64_t size, uint64_t offset);
@@ -992,8 +997,6 @@ extern int opal_async_wait_response(uint64_t token, struct opal_msg *msg);
 extern int opal_get_sensor_data(u32 sensor_hndl, u32 *sensor_data);
 
 struct rtc_time;
-extern int opal_set_rtc_time(struct rtc_time *tm);
-extern void opal_get_rtc_time(struct rtc_time *tm);
 extern unsigned long opal_get_boot_time(void);
 extern void opal_nvram_init(void);
 extern void opal_flash_init(void);
arch/powerpc/kernel/time.c +1 -0
index 7505599..54490c7 100644
@@ -989,6 +989,7 @@ void GregorianDay(struct rtc_time * tm)
 
 	tm->tm_wday = day % 7;
 }
+EXPORT_SYMBOL_GPL(GregorianDay);
 
 void to_tm(int tim, struct rtc_time * tm)
 {
arch/powerpc/platforms/powernv/opal-async.c +3 -0
index e462ab9..693b6cd 100644
@@ -71,6 +71,7 @@ int opal_async_get_token_interruptible(void)
 
 	return token;
 }
+EXPORT_SYMBOL_GPL(opal_async_get_token_interruptible);
 
 int __opal_async_release_token(int token)
 {
@@ -102,6 +103,7 @@ int opal_async_release_token(int token)
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(opal_async_release_token);
 
 int opal_async_wait_response(uint64_t token, struct opal_msg *msg)
 {
@@ -120,6 +122,7 @@ int opal_async_wait_response(uint64_t token, struct opal_msg *msg)
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(opal_async_wait_response);
 
 static int opal_async_comp_event(struct notifier_block *nb,
 		unsigned long msg_type, void *msg)
arch/powerpc/platforms/powernv/opal-rtc.c +19 -46

94 lines not on this page · raw message

arch/powerpc/platforms/powernv/opal-wrappers.S +2 -0
index e9e2450..7d7e7a8 100644
@@ -250,3 +250,5 @@ OPAL_CALL(opal_handle_hmi,			OPAL_HANDLE_HMI);
 OPAL_CALL(opal_register_dump_region,		OPAL_REGISTER_DUMP_REGION);
 OPAL_CALL(opal_unregister_dump_region,		OPAL_UNREGISTER_DUMP_REGION);
 OPAL_CALL(opal_pci_set_phb_cxl_mode,		OPAL_PCI_SET_PHB_CXL_MODE);
+OPAL_CALL(opal_tpo_write,			OPAL_WRITE_TPO);
+OPAL_CALL(opal_tpo_read,			OPAL_READ_TPO);
arch/powerpc/platforms/powernv/opal.c +6 -0
index b642b05..7a7365a 100644
@@ -784,3 +784,9 @@ void opal_free_sg_list(struct opal_sg_list *sg)
 			sg = NULL;
 	}
 }
+
+EXPORT_SYMBOL_GPL(opal_poll_events);
+EXPORT_SYMBOL_GPL(opal_rtc_read);
+EXPORT_SYMBOL_GPL(opal_rtc_write);
+EXPORT_SYMBOL_GPL(opal_tpo_read);
+EXPORT_SYMBOL_GPL(opal_tpo_write);
arch/powerpc/platforms/powernv/setup.c +0 -2
index 3f9546d..9759338 100644
@@ -265,8 +265,6 @@ static unsigned long pnv_memory_block_size(void)
 static void __init pnv_setup_machdep_opal(void)
 {
 	ppc_md.get_boot_time = opal_get_boot_time;
-	ppc_md.get_rtc_time = opal_get_rtc_time;
-	ppc_md.set_rtc_time = opal_set_rtc_time;
 	ppc_md.restart = pnv_restart;
 	ppc_md.power_off = pnv_power_off;
 	ppc_md.halt = pnv_halt;
drivers/rtc/Kconfig +11 -0
index 8cd0bee..0e38cec 100644
@@ -979,6 +979,17 @@ config RTC_DRV_NUC900
 	  If you say yes here you get support for the RTC subsystem of the
 	  NUC910/NUC920 used in embedded systems.
 
+config RTC_DRV_OPAL
+	tristate "IBM OPAL RTC driver"
+	depends on PPC_POWERNV
+	default y
+	help
+	  If you say yes here you get support for the PowerNV platform RTC
+	  driver based on OPAL interfaces.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called rtc-opal.
+
 comment "on-CPU RTC drivers"
 
 config RTC_DRV_DAVINCI
drivers/rtc/Makefile +1 -0
index b188323..c8ef3e1 100644
@@ -92,6 +92,7 @@ obj-$(CONFIG_RTC_DRV_MSM6242)	+= rtc-msm6242.o
 obj-$(CONFIG_RTC_DRV_MPC5121)	+= rtc-mpc5121.o
 obj-$(CONFIG_RTC_DRV_MV)	+= rtc-mv.o
 obj-$(CONFIG_RTC_DRV_NUC900)	+= rtc-nuc900.o
+obj-$(CONFIG_RTC_DRV_OPAL)	+= rtc-opal.o
 obj-$(CONFIG_RTC_DRV_OMAP)	+= rtc-omap.o
 obj-$(CONFIG_RTC_DRV_PALMAS)	+= rtc-palmas.o
 obj-$(CONFIG_RTC_DRV_PCAP)	+= rtc-pcap.o
drivers/rtc/rtc-opal.c new file +261 -0

261 lines not on this page · raw message

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev

A message that is not in the archive (sent off-list or not yet received): 20141014083447.7505.89771.stgit-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]

#2 lore raw
Quoted 9 lines · Neelesh Gupta

The patch implements the OPAL rtc driver that binds with the rtc driver subsystem. The driver uses the platform device infrastructure to probe the rtc device and register it to rtc class framework. The 'wakeup' is supported depending upon the property 'has-tpo' present in the OF node. It provides a way to load the generic rtc driver in in the absence of an OPAL driver.

The patch also moves the existing OPAL rtc get/set time interfaces to the new driver and exposes the necessary OPAL calls using EXPORT_SYMBOL_GPL.

Hi Alessandro,

Awaiting Ack from your side, so that we can take this through the powerpc tree.

Regards,
Neelesh

Quoted 49 lines

Test results:
-------------
Host:
[root@tul169p1 ~]# ls -l /sys/class/rtc/
total 0
lrwxrwxrwx 1 root root 0 Oct 14 03:07 rtc0 -> ../../devices/opal-rtc/rtc/rtc0 [root@tul169p1 ~]# cat /sys/devices/opal-rtc/rtc/rtc0/time
08:10:07
[root@tul169p1 ~]# echo date '+%s' -d '+ 2 minutes' > /sys/class/rtc/rtc0/wakealarm [root@tul169p1 ~]# cat /sys/class/rtc/rtc0/wakealarm
1413274345
[root@tul169p1 ~]#

FSP:

$ smgr mfgState
standby
$ rtim timeofday

System time is valid: 2014/10/14 08:12:04.225115

$ smgr mfgState
ipling
$

---

Changes in v3
=============
- Rebased to the latest tree.

Changes in v2
=============
- Added Documentation/devicetree/bindings/rtc/rtc-opal.txt
- Explicitly turn off RTC_UIE mode by setting 'rtc->uie_unsupported'

  Documentation/devicetree/bindings/rtc/rtc-opal.txt |   16 +
  arch/powerpc/include/asm/opal.h                    |    7 -
  arch/powerpc/kernel/time.c                         |    1
  arch/powerpc/platforms/powernv/opal-async.c        |    3
  arch/powerpc/platforms/powernv/opal-rtc.c          |   65 +----
  arch/powerpc/platforms/powernv/opal-wrappers.S     |    2
  arch/powerpc/platforms/powernv/opal.c              |    6
  arch/powerpc/platforms/powernv/setup.c             |    2
  drivers/rtc/Kconfig                                |   11 +
  drivers/rtc/Makefile                               |    1
  drivers/rtc/rtc-opal.c                             |  261 ++++++++++++++++++++
  11 files changed, 325 insertions(+), 50 deletions(-)
Quoted 3 lines

create mode 100644 Documentation/devicetree/bindings/rtc/rtc-opal.txt create mode 100644 drivers/rtc/rtc-opal.c

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 54476F4B.8050108-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org

#4 lore raw
Quoted 9 lines · Neelesh Gupta
Quoted 7 lines · Neelesh Gupta

The patch implements the OPAL rtc driver that binds with the rtc driver subsystem. The driver uses the platform device infrastructure to probe the rtc device and register it to rtc class framework. The 'wakeup' is supported depending upon the property 'has-tpo' present in the OF node. It provides a way to load the generic rtc driver in in the absence of an OPAL driver.

Quoted 6 lines
Quoted 2 lines

The patch also moves the existing OPAL rtc get/set time interfaces to the new driver and exposes the necessary OPAL calls using EXPORT_SYMBOL_GPL.

Hi Alessandro,

Awaiting Ack from your side, so that we can take this through the powerpc tree.

Hi Alessandro,

Please acknowledge..

- Neelesh

Quoted 58 lines

Regards,
Neelesh

Quoted 50 lines

Test results:
-------------
Host:
[root@tul169p1 ~]# ls -l /sys/class/rtc/
total 0
lrwxrwxrwx 1 root root 0 Oct 14 03:07 rtc0 -> ../../devices/opal-rtc/rtc/rtc0 [root@tul169p1 ~]# cat /sys/devices/opal-rtc/rtc/rtc0/time
08:10:07
[root@tul169p1 ~]# echo date '+%s' -d '+ 2 minutes' > /sys/class/rtc/rtc0/wakealarm [root@tul169p1 ~]# cat /sys/class/rtc/rtc0/wakealarm
1413274345
[root@tul169p1 ~]#

FSP:

$ smgr mfgState
standby
$ rtim timeofday

System time is valid: 2014/10/14 08:12:04.225115

$ smgr mfgState
ipling
$

---

Changes in v3
=============
- Rebased to the latest tree.

Changes in v2
=============
- Added Documentation/devicetree/bindings/rtc/rtc-opal.txt
- Explicitly turn off RTC_UIE mode by setting 'rtc->uie_unsupported'

  Documentation/devicetree/bindings/rtc/rtc-opal.txt |   16 +
  arch/powerpc/include/asm/opal.h                    |    7 -
  arch/powerpc/kernel/time.c                         |    1
  arch/powerpc/platforms/powernv/opal-async.c        |    3
  arch/powerpc/platforms/powernv/opal-rtc.c          |   65 +----
  arch/powerpc/platforms/powernv/opal-wrappers.S     |    2
  arch/powerpc/platforms/powernv/opal.c              |    6
  arch/powerpc/platforms/powernv/setup.c             |    2
  drivers/rtc/Kconfig                                |   11 +
  drivers/rtc/Makefile                               |    1
  drivers/rtc/rtc-opal.c                             |  261 
++++++++++++++++++++
  11 files changed, 325 insertions(+), 50 deletions(-)
Quoted 3 lines

create mode 100644 Documentation/devicetree/bindings/rtc/rtc-opal.txt create mode 100644 drivers/rtc/rtc-opal.c

Quoted 4 lines

_______________________________________________
Linuxppc-dev mailing list Linuxppc-dev-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html