xref: /linux/drivers/input/misc/hp_sdc_rtc.c (revision e80b500370e71b8cd7dd64be4080cee0a3e5068f)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * HP i8042 SDC + MSM-58321 BBRTC driver.
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  * Copyright (c) 2001 Brian S. Julin
51da177e4SLinus Torvalds  * All rights reserved.
61da177e4SLinus Torvalds  *
71da177e4SLinus Torvalds  * Redistribution and use in source and binary forms, with or without
81da177e4SLinus Torvalds  * modification, are permitted provided that the following conditions
91da177e4SLinus Torvalds  * are met:
101da177e4SLinus Torvalds  * 1. Redistributions of source code must retain the above copyright
111da177e4SLinus Torvalds  *    notice, this list of conditions, and the following disclaimer,
121da177e4SLinus Torvalds  *    without modification.
131da177e4SLinus Torvalds  * 2. The name of the author may not be used to endorse or promote products
141da177e4SLinus Torvalds  *    derived from this software without specific prior written permission.
151da177e4SLinus Torvalds  *
161da177e4SLinus Torvalds  * Alternatively, this software may be distributed under the terms of the
171da177e4SLinus Torvalds  * GNU General Public License ("GPL").
181da177e4SLinus Torvalds  *
191da177e4SLinus Torvalds  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
201da177e4SLinus Torvalds  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
211da177e4SLinus Torvalds  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
221da177e4SLinus Torvalds  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
231da177e4SLinus Torvalds  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
241da177e4SLinus Torvalds  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
251da177e4SLinus Torvalds  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
261da177e4SLinus Torvalds  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
271da177e4SLinus Torvalds  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
281da177e4SLinus Torvalds  *
291da177e4SLinus Torvalds  * References:
301da177e4SLinus Torvalds  * System Device Controller Microprocessor Firmware Theory of Operation
311da177e4SLinus Torvalds  *      for Part Number 1820-4784 Revision B.  Dwg No. A-1820-4784-2
321da177e4SLinus Torvalds  * efirtc.c by Stephane Eranian/Hewlett Packard
331da177e4SLinus Torvalds  *
341da177e4SLinus Torvalds  */
351da177e4SLinus Torvalds 
361da177e4SLinus Torvalds #include <linux/hp_sdc.h>
371da177e4SLinus Torvalds #include <linux/errno.h>
381da177e4SLinus Torvalds #include <linux/types.h>
391da177e4SLinus Torvalds #include <linux/init.h>
401da177e4SLinus Torvalds #include <linux/module.h>
411da177e4SLinus Torvalds #include <linux/time.h>
421da177e4SLinus Torvalds #include <linux/miscdevice.h>
431da177e4SLinus Torvalds #include <linux/proc_fs.h>
44c18bd9a1SDavid Howells #include <linux/seq_file.h>
451da177e4SLinus Torvalds #include <linux/poll.h>
461da177e4SLinus Torvalds #include <linux/rtc.h>
47613655faSArnd Bergmann #include <linux/mutex.h>
480f17e4c7SMatthew Wilcox #include <linux/semaphore.h>
491da177e4SLinus Torvalds 
501da177e4SLinus Torvalds MODULE_AUTHOR("Brian S. Julin <bri@calyx.com>");
511da177e4SLinus Torvalds MODULE_DESCRIPTION("HP i8042 SDC + MSM-58321 RTC Driver");
521da177e4SLinus Torvalds MODULE_LICENSE("Dual BSD/GPL");
531da177e4SLinus Torvalds 
541da177e4SLinus Torvalds #define RTC_VERSION "1.10d"
551da177e4SLinus Torvalds 
561da177e4SLinus Torvalds static unsigned long epoch = 2000;
571da177e4SLinus Torvalds 
581da177e4SLinus Torvalds static struct semaphore i8042tregs;
591da177e4SLinus Torvalds 
hp_sdc_rtc_isr(int irq,void * dev_id,uint8_t status,uint8_t data)601da177e4SLinus Torvalds static void hp_sdc_rtc_isr (int irq, void *dev_id,
611da177e4SLinus Torvalds 			    uint8_t status, uint8_t data)
621da177e4SLinus Torvalds {
631da177e4SLinus Torvalds 	return;
641da177e4SLinus Torvalds }
651da177e4SLinus Torvalds 
hp_sdc_rtc_do_read_bbrtc(struct rtc_time * rtctm)661da177e4SLinus Torvalds static int hp_sdc_rtc_do_read_bbrtc (struct rtc_time *rtctm)
671da177e4SLinus Torvalds {
681da177e4SLinus Torvalds 	struct semaphore tsem;
691da177e4SLinus Torvalds 	hp_sdc_transaction t;
701da177e4SLinus Torvalds 	uint8_t tseq[91];
711da177e4SLinus Torvalds 	int i;
721da177e4SLinus Torvalds 
731da177e4SLinus Torvalds 	i = 0;
741da177e4SLinus Torvalds 	while (i < 91) {
751da177e4SLinus Torvalds 		tseq[i++] = HP_SDC_ACT_DATAREG |
761da177e4SLinus Torvalds 			HP_SDC_ACT_POSTCMD | HP_SDC_ACT_DATAIN;
771da177e4SLinus Torvalds 		tseq[i++] = 0x01;			/* write i8042[0x70] */
781da177e4SLinus Torvalds 	  	tseq[i]   = i / 7;			/* BBRTC reg address */
791da177e4SLinus Torvalds 		i++;
801da177e4SLinus Torvalds 		tseq[i++] = HP_SDC_CMD_DO_RTCR;		/* Trigger command   */
811da177e4SLinus Torvalds 		tseq[i++] = 2;		/* expect 1 stat/dat pair back.   */
821da177e4SLinus Torvalds 		i++; i++;               /* buffer for stat/dat pair       */
831da177e4SLinus Torvalds 	}
841da177e4SLinus Torvalds 	tseq[84] |= HP_SDC_ACT_SEMAPHORE;
851da177e4SLinus Torvalds 	t.endidx =		91;
861da177e4SLinus Torvalds 	t.seq =			tseq;
871da177e4SLinus Torvalds 	t.act.semaphore =	&tsem;
8810d0ff83SThomas Gleixner 	sema_init(&tsem, 0);
891da177e4SLinus Torvalds 
901da177e4SLinus Torvalds 	if (hp_sdc_enqueue_transaction(&t)) return -1;
911da177e4SLinus Torvalds 
9215fb9683SHelge Deller 	/* Put ourselves to sleep for results. */
9315fb9683SHelge Deller 	if (WARN_ON(down_interruptible(&tsem)))
9415fb9683SHelge Deller 		return -1;
951da177e4SLinus Torvalds 
961da177e4SLinus Torvalds 	/* Check for nonpresence of BBRTC */
971da177e4SLinus Torvalds 	if (!((tseq[83] | tseq[90] | tseq[69] | tseq[76] |
981da177e4SLinus Torvalds 	       tseq[55] | tseq[62] | tseq[34] | tseq[41] |
991da177e4SLinus Torvalds 	       tseq[20] | tseq[27] | tseq[6]  | tseq[13]) & 0x0f))
1001da177e4SLinus Torvalds 		return -1;
1011da177e4SLinus Torvalds 
1021da177e4SLinus Torvalds 	memset(rtctm, 0, sizeof(struct rtc_time));
1031da177e4SLinus Torvalds 	rtctm->tm_year = (tseq[83] & 0x0f) + (tseq[90] & 0x0f) * 10;
1041da177e4SLinus Torvalds 	rtctm->tm_mon  = (tseq[69] & 0x0f) + (tseq[76] & 0x0f) * 10;
1051da177e4SLinus Torvalds 	rtctm->tm_mday = (tseq[55] & 0x0f) + (tseq[62] & 0x0f) * 10;
1061da177e4SLinus Torvalds 	rtctm->tm_wday = (tseq[48] & 0x0f);
1071da177e4SLinus Torvalds 	rtctm->tm_hour = (tseq[34] & 0x0f) + (tseq[41] & 0x0f) * 10;
1081da177e4SLinus Torvalds 	rtctm->tm_min  = (tseq[20] & 0x0f) + (tseq[27] & 0x0f) * 10;
1091da177e4SLinus Torvalds 	rtctm->tm_sec  = (tseq[6]  & 0x0f) + (tseq[13] & 0x0f) * 10;
1101da177e4SLinus Torvalds 
1111da177e4SLinus Torvalds 	return 0;
1121da177e4SLinus Torvalds }
1131da177e4SLinus Torvalds 
hp_sdc_rtc_read_bbrtc(struct rtc_time * rtctm)1141da177e4SLinus Torvalds static int hp_sdc_rtc_read_bbrtc (struct rtc_time *rtctm)
1151da177e4SLinus Torvalds {
1161da177e4SLinus Torvalds 	struct rtc_time tm, tm_last;
1171da177e4SLinus Torvalds 	int i = 0;
1181da177e4SLinus Torvalds 
1191da177e4SLinus Torvalds 	/* MSM-58321 has no read latch, so must read twice and compare. */
1201da177e4SLinus Torvalds 
1211da177e4SLinus Torvalds 	if (hp_sdc_rtc_do_read_bbrtc(&tm_last)) return -1;
1221da177e4SLinus Torvalds 	if (hp_sdc_rtc_do_read_bbrtc(&tm)) return -1;
1231da177e4SLinus Torvalds 
1241da177e4SLinus Torvalds 	while (memcmp(&tm, &tm_last, sizeof(struct rtc_time))) {
1251da177e4SLinus Torvalds 		if (i++ > 4) return -1;
1261da177e4SLinus Torvalds 		memcpy(&tm_last, &tm, sizeof(struct rtc_time));
1271da177e4SLinus Torvalds 		if (hp_sdc_rtc_do_read_bbrtc(&tm)) return -1;
1281da177e4SLinus Torvalds 	}
1291da177e4SLinus Torvalds 
1301da177e4SLinus Torvalds 	memcpy(rtctm, &tm, sizeof(struct rtc_time));
1311da177e4SLinus Torvalds 
1321da177e4SLinus Torvalds 	return 0;
1331da177e4SLinus Torvalds }
1341da177e4SLinus Torvalds 
1351da177e4SLinus Torvalds 
hp_sdc_rtc_read_i8042timer(uint8_t loadcmd,int numreg)1361da177e4SLinus Torvalds static int64_t hp_sdc_rtc_read_i8042timer (uint8_t loadcmd, int numreg)
1371da177e4SLinus Torvalds {
1381da177e4SLinus Torvalds 	hp_sdc_transaction t;
1391da177e4SLinus Torvalds 	uint8_t tseq[26] = {
1401da177e4SLinus Torvalds 		HP_SDC_ACT_PRECMD | HP_SDC_ACT_POSTCMD | HP_SDC_ACT_DATAIN,
1411da177e4SLinus Torvalds 		0,
1421da177e4SLinus Torvalds 		HP_SDC_CMD_READ_T1, 2, 0, 0,
1431da177e4SLinus Torvalds 		HP_SDC_ACT_POSTCMD | HP_SDC_ACT_DATAIN,
1441da177e4SLinus Torvalds 		HP_SDC_CMD_READ_T2, 2, 0, 0,
1451da177e4SLinus Torvalds 		HP_SDC_ACT_POSTCMD | HP_SDC_ACT_DATAIN,
1461da177e4SLinus Torvalds 		HP_SDC_CMD_READ_T3, 2, 0, 0,
1471da177e4SLinus Torvalds 		HP_SDC_ACT_POSTCMD | HP_SDC_ACT_DATAIN,
1481da177e4SLinus Torvalds 		HP_SDC_CMD_READ_T4, 2, 0, 0,
1491da177e4SLinus Torvalds 		HP_SDC_ACT_POSTCMD | HP_SDC_ACT_DATAIN,
1501da177e4SLinus Torvalds 		HP_SDC_CMD_READ_T5, 2, 0, 0
1511da177e4SLinus Torvalds 	};
1521da177e4SLinus Torvalds 
1531da177e4SLinus Torvalds 	t.endidx = numreg * 5;
1541da177e4SLinus Torvalds 
1551da177e4SLinus Torvalds 	tseq[1] = loadcmd;
1561da177e4SLinus Torvalds 	tseq[t.endidx - 4] |= HP_SDC_ACT_SEMAPHORE; /* numreg assumed > 1 */
1571da177e4SLinus Torvalds 
1581da177e4SLinus Torvalds 	t.seq =			tseq;
1591da177e4SLinus Torvalds 	t.act.semaphore =	&i8042tregs;
1601da177e4SLinus Torvalds 
16115fb9683SHelge Deller 	/* Sleep if output regs in use. */
16215fb9683SHelge Deller 	if (WARN_ON(down_interruptible(&i8042tregs)))
16315fb9683SHelge Deller 		return -1;
1641da177e4SLinus Torvalds 
165b64da05fSDan Carpenter 	if (hp_sdc_enqueue_transaction(&t)) {
166b64da05fSDan Carpenter 		up(&i8042tregs);
167b64da05fSDan Carpenter 		return -1;
168b64da05fSDan Carpenter 	}
1691da177e4SLinus Torvalds 
17015fb9683SHelge Deller 	/* Sleep until results come back. */
17115fb9683SHelge Deller 	if (WARN_ON(down_interruptible(&i8042tregs)))
17215fb9683SHelge Deller 		return -1;
17315fb9683SHelge Deller 
1741da177e4SLinus Torvalds 	up(&i8042tregs);
1751da177e4SLinus Torvalds 
1761da177e4SLinus Torvalds 	return (tseq[5] |
1771da177e4SLinus Torvalds 		((uint64_t)(tseq[10]) << 8)  | ((uint64_t)(tseq[15]) << 16) |
1781da177e4SLinus Torvalds 		((uint64_t)(tseq[20]) << 24) | ((uint64_t)(tseq[25]) << 32));
1791da177e4SLinus Torvalds }
1801da177e4SLinus Torvalds 
1811da177e4SLinus Torvalds 
1821da177e4SLinus Torvalds /* Read the i8042 real-time clock */
hp_sdc_rtc_read_rt(struct timespec64 * res)183ba564e78SWEN Pingbo static inline int hp_sdc_rtc_read_rt(struct timespec64 *res) {
1841da177e4SLinus Torvalds 	int64_t raw;
1851da177e4SLinus Torvalds 	uint32_t tenms;
1861da177e4SLinus Torvalds 	unsigned int days;
1871da177e4SLinus Torvalds 
1881da177e4SLinus Torvalds 	raw = hp_sdc_rtc_read_i8042timer(HP_SDC_CMD_LOAD_RT, 5);
1891da177e4SLinus Torvalds 	if (raw < 0) return -1;
1901da177e4SLinus Torvalds 
1911da177e4SLinus Torvalds 	tenms = (uint32_t)raw & 0xffffff;
1921da177e4SLinus Torvalds 	days  = (unsigned int)(raw >> 24) & 0xffff;
1931da177e4SLinus Torvalds 
194ba564e78SWEN Pingbo 	res->tv_nsec = (long)(tenms % 100) * 10000 * 1000;
195ba564e78SWEN Pingbo 	res->tv_sec =  (tenms / 100) + (time64_t)days * 86400;
1961da177e4SLinus Torvalds 
1971da177e4SLinus Torvalds 	return 0;
1981da177e4SLinus Torvalds }
1991da177e4SLinus Torvalds 
2001da177e4SLinus Torvalds 
2011da177e4SLinus Torvalds /* Read the i8042 fast handshake timer */
hp_sdc_rtc_read_fhs(struct timespec64 * res)202ba564e78SWEN Pingbo static inline int hp_sdc_rtc_read_fhs(struct timespec64 *res) {
2033776989dSRoel Kluin 	int64_t raw;
2041da177e4SLinus Torvalds 	unsigned int tenms;
2051da177e4SLinus Torvalds 
2061da177e4SLinus Torvalds 	raw = hp_sdc_rtc_read_i8042timer(HP_SDC_CMD_LOAD_FHS, 2);
2071da177e4SLinus Torvalds 	if (raw < 0) return -1;
2081da177e4SLinus Torvalds 
2091da177e4SLinus Torvalds 	tenms = (unsigned int)raw & 0xffff;
2101da177e4SLinus Torvalds 
211ba564e78SWEN Pingbo 	res->tv_nsec = (long)(tenms % 100) * 10000 * 1000;
212ba564e78SWEN Pingbo 	res->tv_sec  = (time64_t)(tenms / 100);
2131da177e4SLinus Torvalds 
2141da177e4SLinus Torvalds 	return 0;
2151da177e4SLinus Torvalds }
2161da177e4SLinus Torvalds 
2171da177e4SLinus Torvalds 
2181da177e4SLinus Torvalds /* Read the i8042 match timer (a.k.a. alarm) */
hp_sdc_rtc_read_mt(struct timespec64 * res)219ba564e78SWEN Pingbo static inline int hp_sdc_rtc_read_mt(struct timespec64 *res) {
2201da177e4SLinus Torvalds 	int64_t raw;
2211da177e4SLinus Torvalds 	uint32_t tenms;
2221da177e4SLinus Torvalds 
2231da177e4SLinus Torvalds 	raw = hp_sdc_rtc_read_i8042timer(HP_SDC_CMD_LOAD_MT, 3);
2241da177e4SLinus Torvalds 	if (raw < 0) return -1;
2251da177e4SLinus Torvalds 
2261da177e4SLinus Torvalds 	tenms = (uint32_t)raw & 0xffffff;
2271da177e4SLinus Torvalds 
228ba564e78SWEN Pingbo 	res->tv_nsec = (long)(tenms % 100) * 10000 * 1000;
229ba564e78SWEN Pingbo 	res->tv_sec  = (time64_t)(tenms / 100);
2301da177e4SLinus Torvalds 
2311da177e4SLinus Torvalds 	return 0;
2321da177e4SLinus Torvalds }
2331da177e4SLinus Torvalds 
2341da177e4SLinus Torvalds 
2351da177e4SLinus Torvalds /* Read the i8042 delay timer */
hp_sdc_rtc_read_dt(struct timespec64 * res)236ba564e78SWEN Pingbo static inline int hp_sdc_rtc_read_dt(struct timespec64 *res) {
2371da177e4SLinus Torvalds 	int64_t raw;
2381da177e4SLinus Torvalds 	uint32_t tenms;
2391da177e4SLinus Torvalds 
2401da177e4SLinus Torvalds 	raw = hp_sdc_rtc_read_i8042timer(HP_SDC_CMD_LOAD_DT, 3);
2411da177e4SLinus Torvalds 	if (raw < 0) return -1;
2421da177e4SLinus Torvalds 
2431da177e4SLinus Torvalds 	tenms = (uint32_t)raw & 0xffffff;
2441da177e4SLinus Torvalds 
245ba564e78SWEN Pingbo 	res->tv_nsec = (long)(tenms % 100) * 10000 * 1000;
246ba564e78SWEN Pingbo 	res->tv_sec  = (time64_t)(tenms / 100);
2471da177e4SLinus Torvalds 
2481da177e4SLinus Torvalds 	return 0;
2491da177e4SLinus Torvalds }
2501da177e4SLinus Torvalds 
2511da177e4SLinus Torvalds 
2521da177e4SLinus Torvalds /* Read the i8042 cycle timer (a.k.a. periodic) */
hp_sdc_rtc_read_ct(struct timespec64 * res)253ba564e78SWEN Pingbo static inline int hp_sdc_rtc_read_ct(struct timespec64 *res) {
2541da177e4SLinus Torvalds 	int64_t raw;
2551da177e4SLinus Torvalds 	uint32_t tenms;
2561da177e4SLinus Torvalds 
2571da177e4SLinus Torvalds 	raw = hp_sdc_rtc_read_i8042timer(HP_SDC_CMD_LOAD_CT, 3);
2581da177e4SLinus Torvalds 	if (raw < 0) return -1;
2591da177e4SLinus Torvalds 
2601da177e4SLinus Torvalds 	tenms = (uint32_t)raw & 0xffffff;
2611da177e4SLinus Torvalds 
262ba564e78SWEN Pingbo 	res->tv_nsec = (long)(tenms % 100) * 10000 * 1000;
263ba564e78SWEN Pingbo 	res->tv_sec  = (time64_t)(tenms / 100);
2641da177e4SLinus Torvalds 
2651da177e4SLinus Torvalds 	return 0;
2661da177e4SLinus Torvalds }
2671da177e4SLinus Torvalds 
hp_sdc_rtc_proc_show(struct seq_file * m,void * v)268*586dc362SRandy Dunlap static int __maybe_unused hp_sdc_rtc_proc_show(struct seq_file *m, void *v)
2691da177e4SLinus Torvalds {
2701da177e4SLinus Torvalds #define YN(bit) ("no")
2711da177e4SLinus Torvalds #define NY(bit) ("yes")
2721da177e4SLinus Torvalds         struct rtc_time tm;
273ba564e78SWEN Pingbo 	struct timespec64 tv;
2741da177e4SLinus Torvalds 
2751da177e4SLinus Torvalds 	memset(&tm, 0, sizeof(struct rtc_time));
2761da177e4SLinus Torvalds 
2771da177e4SLinus Torvalds 	if (hp_sdc_rtc_read_bbrtc(&tm)) {
278c18bd9a1SDavid Howells 		seq_puts(m, "BBRTC\t\t: READ FAILED!\n");
2791da177e4SLinus Torvalds 	} else {
280c18bd9a1SDavid Howells 		seq_printf(m,
281804cfcb9SAndy Shevchenko 			     "rtc_time\t: %ptRt\n"
282804cfcb9SAndy Shevchenko 			     "rtc_date\t: %ptRd\n"
2831da177e4SLinus Torvalds 			     "rtc_epoch\t: %04lu\n",
284804cfcb9SAndy Shevchenko 			     &tm, &tm, epoch);
2851da177e4SLinus Torvalds 	}
2861da177e4SLinus Torvalds 
2871da177e4SLinus Torvalds 	if (hp_sdc_rtc_read_rt(&tv)) {
288c18bd9a1SDavid Howells 		seq_puts(m, "i8042 rtc\t: READ FAILED!\n");
2891da177e4SLinus Torvalds 	} else {
290ba564e78SWEN Pingbo 		seq_printf(m, "i8042 rtc\t: %lld.%02ld seconds\n",
291ba564e78SWEN Pingbo 			     (s64)tv.tv_sec, (long)tv.tv_nsec/1000000L);
2921da177e4SLinus Torvalds 	}
2931da177e4SLinus Torvalds 
2941da177e4SLinus Torvalds 	if (hp_sdc_rtc_read_fhs(&tv)) {
295c18bd9a1SDavid Howells 		seq_puts(m, "handshake\t: READ FAILED!\n");
2961da177e4SLinus Torvalds 	} else {
297ba564e78SWEN Pingbo 		seq_printf(m, "handshake\t: %lld.%02ld seconds\n",
298ba564e78SWEN Pingbo 			     (s64)tv.tv_sec, (long)tv.tv_nsec/1000000L);
2991da177e4SLinus Torvalds 	}
3001da177e4SLinus Torvalds 
3011da177e4SLinus Torvalds 	if (hp_sdc_rtc_read_mt(&tv)) {
302c18bd9a1SDavid Howells 		seq_puts(m, "alarm\t\t: READ FAILED!\n");
3031da177e4SLinus Torvalds 	} else {
304ba564e78SWEN Pingbo 		seq_printf(m, "alarm\t\t: %lld.%02ld seconds\n",
305ba564e78SWEN Pingbo 			     (s64)tv.tv_sec, (long)tv.tv_nsec/1000000L);
3061da177e4SLinus Torvalds 	}
3071da177e4SLinus Torvalds 
3081da177e4SLinus Torvalds 	if (hp_sdc_rtc_read_dt(&tv)) {
309c18bd9a1SDavid Howells 		seq_puts(m, "delay\t\t: READ FAILED!\n");
3101da177e4SLinus Torvalds 	} else {
311ba564e78SWEN Pingbo 		seq_printf(m, "delay\t\t: %lld.%02ld seconds\n",
312ba564e78SWEN Pingbo 			     (s64)tv.tv_sec, (long)tv.tv_nsec/1000000L);
3131da177e4SLinus Torvalds 	}
3141da177e4SLinus Torvalds 
3151da177e4SLinus Torvalds 	if (hp_sdc_rtc_read_ct(&tv)) {
316c18bd9a1SDavid Howells 		seq_puts(m, "periodic\t: READ FAILED!\n");
3171da177e4SLinus Torvalds 	} else {
318ba564e78SWEN Pingbo 		seq_printf(m, "periodic\t: %lld.%02ld seconds\n",
319ba564e78SWEN Pingbo 			     (s64)tv.tv_sec, (long)tv.tv_nsec/1000000L);
3201da177e4SLinus Torvalds 	}
3211da177e4SLinus Torvalds 
322c18bd9a1SDavid Howells         seq_printf(m,
3231da177e4SLinus Torvalds                      "DST_enable\t: %s\n"
3241da177e4SLinus Torvalds                      "BCD\t\t: %s\n"
3251da177e4SLinus Torvalds                      "24hr\t\t: %s\n"
3261da177e4SLinus Torvalds                      "square_wave\t: %s\n"
3271da177e4SLinus Torvalds                      "alarm_IRQ\t: %s\n"
3281da177e4SLinus Torvalds                      "update_IRQ\t: %s\n"
3291da177e4SLinus Torvalds                      "periodic_IRQ\t: %s\n"
3301da177e4SLinus Torvalds 		     "periodic_freq\t: %ld\n"
3311da177e4SLinus Torvalds                      "batt_status\t: %s\n",
3321da177e4SLinus Torvalds                      YN(RTC_DST_EN),
3331da177e4SLinus Torvalds                      NY(RTC_DM_BINARY),
3341da177e4SLinus Torvalds                      YN(RTC_24H),
3351da177e4SLinus Torvalds                      YN(RTC_SQWE),
3361da177e4SLinus Torvalds                      YN(RTC_AIE),
3371da177e4SLinus Torvalds                      YN(RTC_UIE),
3381da177e4SLinus Torvalds                      YN(RTC_PIE),
3391da177e4SLinus Torvalds                      1UL,
3401da177e4SLinus Torvalds                      1 ? "okay" : "dead");
3411da177e4SLinus Torvalds 
342c18bd9a1SDavid Howells         return 0;
3431da177e4SLinus Torvalds #undef YN
3441da177e4SLinus Torvalds #undef NY
3451da177e4SLinus Torvalds }
3461da177e4SLinus Torvalds 
hp_sdc_rtc_init(void)3471da177e4SLinus Torvalds static int __init hp_sdc_rtc_init(void)
3481da177e4SLinus Torvalds {
3491da177e4SLinus Torvalds 	int ret;
3501da177e4SLinus Torvalds 
351eb98630bSGeert Uytterhoeven #ifdef __mc68000__
352eb98630bSGeert Uytterhoeven 	if (!MACH_IS_HP300)
353eb98630bSGeert Uytterhoeven 		return -ENODEV;
354eb98630bSGeert Uytterhoeven #endif
355eb98630bSGeert Uytterhoeven 
35610d0ff83SThomas Gleixner 	sema_init(&i8042tregs, 1);
3571da177e4SLinus Torvalds 
3581da177e4SLinus Torvalds 	if ((ret = hp_sdc_request_timer_irq(&hp_sdc_rtc_isr)))
3591da177e4SLinus Torvalds 		return ret;
3605d469ec0SNeil Horman 
3613f3942acSChristoph Hellwig         proc_create_single("driver/rtc", 0, NULL, hp_sdc_rtc_proc_show);
3621da177e4SLinus Torvalds 
3631da177e4SLinus Torvalds 	printk(KERN_INFO "HP i8042 SDC + MSM-58321 RTC support loaded "
3641da177e4SLinus Torvalds 			 "(RTC v " RTC_VERSION ")\n");
3651da177e4SLinus Torvalds 
3661da177e4SLinus Torvalds 	return 0;
3671da177e4SLinus Torvalds }
3681da177e4SLinus Torvalds 
hp_sdc_rtc_exit(void)3691da177e4SLinus Torvalds static void __exit hp_sdc_rtc_exit(void)
3701da177e4SLinus Torvalds {
3711da177e4SLinus Torvalds 	remove_proc_entry ("driver/rtc", NULL);
3721da177e4SLinus Torvalds 	hp_sdc_release_timer_irq(hp_sdc_rtc_isr);
3731da177e4SLinus Torvalds         printk(KERN_INFO "HP i8042 SDC + MSM-58321 RTC support unloaded\n");
3741da177e4SLinus Torvalds }
3751da177e4SLinus Torvalds 
3761da177e4SLinus Torvalds module_init(hp_sdc_rtc_init);
3771da177e4SLinus Torvalds module_exit(hp_sdc_rtc_exit);
378