aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sh/boards/mach-sh03
diff options
context:
space:
mode:
Diffstat (limited to 'arch/sh/boards/mach-sh03')
-rw-r--r--arch/sh/boards/mach-sh03/Makefile5
-rw-r--r--arch/sh/boards/mach-sh03/rtc.c132
-rw-r--r--arch/sh/boards/mach-sh03/setup.c75
3 files changed, 212 insertions, 0 deletions
diff --git a/arch/sh/boards/mach-sh03/Makefile b/arch/sh/boards/mach-sh03/Makefile
new file mode 100644
index 000000000000..400306a796ec
--- /dev/null
+++ b/arch/sh/boards/mach-sh03/Makefile
@@ -0,0 +1,5 @@
1#
2# Makefile for the Interface (CTP/PCI-SH03) specific parts of the kernel
3#
4
5obj-y := setup.o rtc.o
diff --git a/arch/sh/boards/mach-sh03/rtc.c b/arch/sh/boards/mach-sh03/rtc.c
new file mode 100644
index 000000000000..0a9266bb51c5
--- /dev/null
+++ b/arch/sh/boards/mach-sh03/rtc.c
@@ -0,0 +1,132 @@
1/*
2 * linux/arch/sh/boards/sh03/rtc.c -- CTP/PCI-SH03 on-chip RTC support
3 *
4 * Copyright (C) 2004 Saito.K & Jeanne(ksaito@interface.co.jp)
5 *
6 */
7
8#include <linux/init.h>
9#include <linux/kernel.h>
10#include <linux/sched.h>
11#include <linux/time.h>
12#include <linux/bcd.h>
13#include <linux/rtc.h>
14#include <linux/spinlock.h>
15#include <asm/io.h>
16#include <asm/rtc.h>
17
18#define RTC_BASE 0xb0000000
19#define RTC_SEC1 (RTC_BASE + 0)
20#define RTC_SEC10 (RTC_BASE + 1)
21#define RTC_MIN1 (RTC_BASE + 2)
22#define RTC_MIN10 (RTC_BASE + 3)
23#define RTC_HOU1 (RTC_BASE + 4)
24#define RTC_HOU10 (RTC_BASE + 5)
25#define RTC_WEE1 (RTC_BASE + 6)
26#define RTC_DAY1 (RTC_BASE + 7)
27#define RTC_DAY10 (RTC_BASE + 8)
28#define RTC_MON1 (RTC_BASE + 9)
29#define RTC_MON10 (RTC_BASE + 10)
30#define RTC_YEA1 (RTC_BASE + 11)
31#define RTC_YEA10 (RTC_BASE + 12)
32#define RTC_YEA100 (RTC_BASE + 13)
33#define RTC_YEA1000 (RTC_BASE + 14)
34#define RTC_CTL (RTC_BASE + 15)
35#define RTC_BUSY 1
36#define RTC_STOP 2
37
38extern spinlock_t rtc_lock;
39
40unsigned long get_cmos_time(void)
41{
42 unsigned int year, mon, day, hour, min, sec;
43
44 spin_lock(&rtc_lock);
45 again:
46 do {
47 sec = (ctrl_inb(RTC_SEC1) & 0xf) + (ctrl_inb(RTC_SEC10) & 0x7) * 10;
48 min = (ctrl_inb(RTC_MIN1) & 0xf) + (ctrl_inb(RTC_MIN10) & 0xf) * 10;
49 hour = (ctrl_inb(RTC_HOU1) & 0xf) + (ctrl_inb(RTC_HOU10) & 0xf) * 10;
50 day = (ctrl_inb(RTC_DAY1) & 0xf) + (ctrl_inb(RTC_DAY10) & 0xf) * 10;
51 mon = (ctrl_inb(RTC_MON1) & 0xf) + (ctrl_inb(RTC_MON10) & 0xf) * 10;
52 year = (ctrl_inb(RTC_YEA1) & 0xf) + (ctrl_inb(RTC_YEA10) & 0xf) * 10
53 + (ctrl_inb(RTC_YEA100 ) & 0xf) * 100
54 + (ctrl_inb(RTC_YEA1000) & 0xf) * 1000;
55 } while (sec != (ctrl_inb(RTC_SEC1) & 0xf) + (ctrl_inb(RTC_SEC10) & 0x7) * 10);
56 if (year == 0 || mon < 1 || mon > 12 || day > 31 || day < 1 ||
57 hour > 23 || min > 59 || sec > 59) {
58 printk(KERN_ERR
59 "SH-03 RTC: invalid value, resetting to 1 Jan 2000\n");
60 printk("year=%d, mon=%d, day=%d, hour=%d, min=%d, sec=%d\n",
61 year, mon, day, hour, min, sec);
62
63 ctrl_outb(0, RTC_SEC1); ctrl_outb(0, RTC_SEC10);
64 ctrl_outb(0, RTC_MIN1); ctrl_outb(0, RTC_MIN10);
65 ctrl_outb(0, RTC_HOU1); ctrl_outb(0, RTC_HOU10);
66 ctrl_outb(6, RTC_WEE1);
67 ctrl_outb(1, RTC_DAY1); ctrl_outb(0, RTC_DAY10);
68 ctrl_outb(1, RTC_MON1); ctrl_outb(0, RTC_MON10);
69 ctrl_outb(0, RTC_YEA1); ctrl_outb(0, RTC_YEA10);
70 ctrl_outb(0, RTC_YEA100);
71 ctrl_outb(2, RTC_YEA1000);
72 ctrl_outb(0, RTC_CTL);
73 goto again;
74 }
75
76 spin_unlock(&rtc_lock);
77 return mktime(year, mon, day, hour, min, sec);
78}
79
80void sh03_rtc_gettimeofday(struct timespec *tv)
81{
82
83 tv->tv_sec = get_cmos_time();
84 tv->tv_nsec = 0;
85}
86
87static int set_rtc_mmss(unsigned long nowtime)
88{
89 int retval = 0;
90 int real_seconds, real_minutes, cmos_minutes;
91 int i;
92
93 /* gets recalled with irq locally disabled */
94 spin_lock(&rtc_lock);
95 for (i = 0 ; i < 1000000 ; i++) /* may take up to 1 second... */
96 if (!(ctrl_inb(RTC_CTL) & RTC_BUSY))
97 break;
98 cmos_minutes = (ctrl_inb(RTC_MIN1) & 0xf) + (ctrl_inb(RTC_MIN10) & 0xf) * 10;
99 real_seconds = nowtime % 60;
100 real_minutes = nowtime / 60;
101 if (((abs(real_minutes - cmos_minutes) + 15)/30) & 1)
102 real_minutes += 30; /* correct for half hour time zone */
103 real_minutes %= 60;
104
105 if (abs(real_minutes - cmos_minutes) < 30) {
106 ctrl_outb(real_seconds % 10, RTC_SEC1);
107 ctrl_outb(real_seconds / 10, RTC_SEC10);
108 ctrl_outb(real_minutes % 10, RTC_MIN1);
109 ctrl_outb(real_minutes / 10, RTC_MIN10);
110 } else {
111 printk(KERN_WARNING
112 "set_rtc_mmss: can't update from %d to %d\n",
113 cmos_minutes, real_minutes);
114 retval = -1;
115 }
116 spin_unlock(&rtc_lock);
117
118 return retval;
119}
120
121int sh03_rtc_settimeofday(const time_t secs)
122{
123 unsigned long nowtime = secs;
124
125 return set_rtc_mmss(nowtime);
126}
127
128void sh03_time_init(void)
129{
130 rtc_sh_get_time = sh03_rtc_gettimeofday;
131 rtc_sh_set_time = sh03_rtc_settimeofday;
132}
diff --git a/arch/sh/boards/mach-sh03/setup.c b/arch/sh/boards/mach-sh03/setup.c
new file mode 100644
index 000000000000..cd9cff1ed349
--- /dev/null
+++ b/arch/sh/boards/mach-sh03/setup.c
@@ -0,0 +1,75 @@
1/*
2 * linux/arch/sh/boards/sh03/setup.c
3 *
4 * Copyright (C) 2004 Interface Co.,Ltd. Saito.K
5 *
6 */
7
8#include <linux/init.h>
9#include <linux/irq.h>
10#include <linux/pci.h>
11#include <linux/platform_device.h>
12#include <asm/io.h>
13#include <asm/rtc.h>
14#include <mach/io.h>
15#include <mach/sh03.h>
16#include <asm/addrspace.h>
17
18static void __init init_sh03_IRQ(void)
19{
20 plat_irq_setup_pins(IRQ_MODE_IRQ);
21}
22
23extern void *cf_io_base;
24
25static void __iomem *sh03_ioport_map(unsigned long port, unsigned int size)
26{
27 if (PXSEG(port))
28 return (void __iomem *)port;
29 /* CompactFlash (IDE) */
30 if (((port >= 0x1f0) && (port <= 0x1f7)) || (port == 0x3f6))
31 return (void __iomem *)((unsigned long)cf_io_base + port);
32
33 return (void __iomem *)(port + PCI_IO_BASE);
34}
35
36/* arch/sh/boards/sh03/rtc.c */
37void sh03_time_init(void);
38
39static void __init sh03_setup(char **cmdline_p)
40{
41 board_time_init = sh03_time_init;
42}
43
44static struct resource heartbeat_resources[] = {
45 [0] = {
46 .start = 0xa0800000,
47 .end = 0xa0800000,
48 .flags = IORESOURCE_MEM,
49 },
50};
51
52static struct platform_device heartbeat_device = {
53 .name = "heartbeat",
54 .id = -1,
55 .num_resources = ARRAY_SIZE(heartbeat_resources),
56 .resource = heartbeat_resources,
57};
58
59static struct platform_device *sh03_devices[] __initdata = {
60 &heartbeat_device,
61};
62
63static int __init sh03_devices_setup(void)
64{
65 return platform_add_devices(sh03_devices, ARRAY_SIZE(sh03_devices));
66}
67__initcall(sh03_devices_setup);
68
69static struct sh_machine_vector mv_sh03 __initmv = {
70 .mv_name = "Interface (CTP/PCI-SH03)",
71 .mv_setup = sh03_setup,
72 .mv_nr_irqs = 48,
73 .mv_ioport_map = sh03_ioport_map,
74 .mv_init_irq = init_sh03_IRQ,
75};