Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 16b1d26e authored by Neelesh Gupta's avatar Neelesh Gupta Committed by Michael Ellerman
Browse files

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
$

CC: devicetree@vger.kernel.org
CC: tglx@linutronix.de
CC: rtc-linux@googlegroups.com
CC: a.zummo@towertech.it
Signed-off-by: default avatarNeelesh Gupta <neelegup@linux.vnet.ibm.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent 59994fb0
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
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>;
	};
+5 −2
Original line number Diff line number Diff line
@@ -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
#define OPAL_IPMI_SEND				107
#define OPAL_IPMI_RECV				108

@@ -832,6 +834,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);
@@ -1009,8 +1014,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);
+1 −0
Original line number Diff line number Diff line
@@ -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)
{
+3 −0
Original line number Diff line number Diff line
@@ -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)
+19 −46
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
#include <linux/bcd.h>
#include <linux/rtc.h>
#include <linux/delay.h>
#include <linux/platform_device.h>
#include <linux/of_platform.h>

#include <asm/opal.h>
#include <asm/firmware.h>
@@ -43,7 +45,7 @@ unsigned long __init opal_get_boot_time(void)
	long rc = OPAL_BUSY;

	if (!opal_check_token(OPAL_RTC_READ))
		goto out;
		return 0;

	while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
		rc = opal_rtc_read(&__y_m_d, &__h_m_s_ms);
@@ -53,62 +55,33 @@ unsigned long __init opal_get_boot_time(void)
			mdelay(10);
	}
	if (rc != OPAL_SUCCESS)
		goto out;
		return 0;

	y_m_d = be32_to_cpu(__y_m_d);
	h_m_s_ms = be64_to_cpu(__h_m_s_ms);
	opal_to_tm(y_m_d, h_m_s_ms, &tm);
	return mktime(tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
		      tm.tm_hour, tm.tm_min, tm.tm_sec);
out:
	ppc_md.get_rtc_time = NULL;
	ppc_md.set_rtc_time = NULL;
	return 0;
}

void opal_get_rtc_time(struct rtc_time *tm)
static __init int opal_time_init(void)
{
	long rc = OPAL_BUSY;
	u32 y_m_d;
	u64 h_m_s_ms;
	__be32 __y_m_d;
	__be64 __h_m_s_ms;
	struct platform_device *pdev;
	struct device_node *rtc;

	while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
		rc = opal_rtc_read(&__y_m_d, &__h_m_s_ms);
		if (rc == OPAL_BUSY_EVENT)
			opal_poll_events(NULL);
	rtc = of_find_node_by_path("/ibm,opal/rtc");
	if (rtc) {
		pdev = of_platform_device_create(rtc, "opal-rtc", NULL);
		of_node_put(rtc);
	} else {
		if (opal_check_token(OPAL_RTC_READ) ||
		    opal_check_token(OPAL_READ_TPO))
			pdev = platform_device_register_simple("opal-rtc", -1,
							       NULL, 0);
		else
			mdelay(10);
	}
	if (rc != OPAL_SUCCESS)
		return;
	y_m_d = be32_to_cpu(__y_m_d);
	h_m_s_ms = be64_to_cpu(__h_m_s_ms);
	opal_to_tm(y_m_d, h_m_s_ms, tm);
			return -ENODEV;
	}

int opal_set_rtc_time(struct rtc_time *tm)
{
	long rc = OPAL_BUSY;
	u32 y_m_d = 0;
	u64 h_m_s_ms = 0;

	y_m_d |= ((u32)bin2bcd((tm->tm_year + 1900) / 100)) << 24;
	y_m_d |= ((u32)bin2bcd((tm->tm_year + 1900) % 100)) << 16;
	y_m_d |= ((u32)bin2bcd((tm->tm_mon + 1))) << 8;
	y_m_d |= ((u32)bin2bcd(tm->tm_mday));

	h_m_s_ms |= ((u64)bin2bcd(tm->tm_hour)) << 56;
	h_m_s_ms |= ((u64)bin2bcd(tm->tm_min)) << 48;
	h_m_s_ms |= ((u64)bin2bcd(tm->tm_sec)) << 40;

	while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
		rc = opal_rtc_write(y_m_d, h_m_s_ms);
		if (rc == OPAL_BUSY_EVENT)
			opal_poll_events(NULL);
		else
			mdelay(10);
	}
	return rc == OPAL_SUCCESS ? 0 : -EIO;
	return PTR_ERR_OR_ZERO(pdev);
}
machine_subsys_initcall(powernv, opal_time_init);
Loading