Merge master.kernel.org:/pub/scm/linux/kernel/git/lethal/sh-2.6
[pandora-kernel.git] / arch / sh / boards / landisk / setup.c
1 /*
2  * arch/sh/boards/landisk/setup.c
3  *
4  * Copyright (C) 2000 Kazumoto Kojima
5  * Copyright (C) 2002 Paul Mundt
6  *
7  * I-O DATA Device, Inc. LANDISK Support.
8  *
9  * Modified for LANDISK by
10  * Atom Create Engineering Co., Ltd. 2002.
11  *
12  * modifed by kogiidena
13  * 2005.09.16
14  *
15  * This file is subject to the terms and conditions of the GNU General Public
16  * License.  See the file "COPYING" in the main directory of this archive
17  * for more details.
18  */
19 #include <linux/init.h>
20 #include <linux/pm.h>
21 #include <linux/mm.h>
22 #include <asm/machvec.h>
23 #include <asm/rtc.h>
24 #include <asm/landisk/iodata_landisk.h>
25 #include <asm/io.h>
26
27 void landisk_time_init(void);
28 void init_landisk_IRQ(void);
29
30 int landisk_ledparam;
31 int landisk_buzzerparam;
32 int landisk_arch;
33
34 /* cycle the led's in the clasic knightrider/sun pattern */
35 static void heartbeat_landisk(void)
36 {
37         static unsigned int cnt = 0, blink = 0x00, period = 25;
38         volatile u8 *p = (volatile u8 *)PA_LED;
39         char data;
40
41         if ((landisk_ledparam & 0x080) == 0)
42                 return;
43
44         cnt += 1;
45
46         if (cnt < period)
47                 return;
48
49         cnt = 0;
50         blink++;
51
52         data = (blink & 0x01) ? (landisk_ledparam >> 16) : 0;
53         data |= (blink & 0x02) ? (landisk_ledparam >> 8) : 0;
54         data |= landisk_ledparam;
55
56         /* buzzer */
57         if (landisk_buzzerparam & 0x1) {
58                 data |= 0x80;
59         } else {
60                 data &= 0x7f;
61         }
62         *p = data;
63
64         if (((landisk_ledparam & 0x007f7f00) == 0) &&
65              (landisk_buzzerparam == 0))
66                 landisk_ledparam &= (~0x0080);
67
68         landisk_buzzerparam >>= 1;
69 }
70
71 static void landisk_power_off(void)
72 {
73         ctrl_outb(0x01, PA_SHUTDOWN);
74 }
75
76 static void check_usl5p(void)
77 {
78         volatile u8 *p = (volatile u8 *)PA_LED;
79         u8 tmp1, tmp2;
80
81         tmp1 = *p;
82         *p = 0x40;
83         tmp2 = *p;
84         *p = tmp1;
85
86         landisk_arch = (tmp2 == 0x40);
87         if (landisk_arch == 1) {
88                 /* arch == usl-5p */
89                 landisk_ledparam = 0x00000380;
90                 landisk_ledparam |= (tmp1 & 0x07c);
91         } else {
92                 /* arch == landisk */
93                 landisk_ledparam = 0x02000180;
94                 landisk_ledparam |= 0x04;
95         }
96 }
97
98 void *area5_io_base;
99 void *area6_io_base;
100
101 static int __init landisk_cf_init(void)
102 {
103         pgprot_t prot;
104         unsigned long paddrbase, psize;
105
106         /* open I/O area window */
107         paddrbase = virt_to_phys((void *)PA_AREA5_IO);
108         psize = PAGE_SIZE;
109         prot = PAGE_KERNEL_PCC(1, _PAGE_PCC_IO16);
110         area5_io_base = p3_ioremap(paddrbase, psize, prot.pgprot);
111         if (!area5_io_base) {
112                 printk("allocate_cf_area : can't open CF I/O window!\n");
113                 return -ENOMEM;
114         }
115
116         paddrbase = virt_to_phys((void *)PA_AREA6_IO);
117         psize = PAGE_SIZE;
118         prot = PAGE_KERNEL_PCC(0, _PAGE_PCC_IO16);
119         area6_io_base = p3_ioremap(paddrbase, psize, prot.pgprot);
120         if (!area6_io_base) {
121                 printk("allocate_cf_area : can't open HDD I/O window!\n");
122                 return -ENOMEM;
123         }
124
125         printk(KERN_INFO "Allocate Area5/6 success.\n");
126
127         /* XXX : do we need attribute and common-memory area also? */
128
129         return 0;
130 }
131
132 static void __init landisk_setup(char **cmdline_p)
133 {
134         device_initcall(landisk_cf_init);
135
136         landisk_buzzerparam = 0;
137         check_usl5p();
138
139         printk(KERN_INFO "I-O DATA DEVICE, INC. \"LANDISK Series\" support.\n");
140
141         board_time_init = landisk_time_init;
142         pm_power_off = landisk_power_off;
143 }
144
145 /*
146  * The Machine Vector
147  */
148 struct sh_machine_vector mv_landisk __initmv = {
149         .mv_name = "LANDISK",
150         .mv_setup = landisk_setup,
151         .mv_nr_irqs = 72,
152         .mv_inb = landisk_inb,
153         .mv_inw = landisk_inw,
154         .mv_inl = landisk_inl,
155         .mv_outb = landisk_outb,
156         .mv_outw = landisk_outw,
157         .mv_outl = landisk_outl,
158         .mv_inb_p = landisk_inb_p,
159         .mv_inw_p = landisk_inw,
160         .mv_inl_p = landisk_inl,
161         .mv_outb_p = landisk_outb_p,
162         .mv_outw_p = landisk_outw,
163         .mv_outl_p = landisk_outl,
164         .mv_insb = landisk_insb,
165         .mv_insw = landisk_insw,
166         .mv_insl = landisk_insl,
167         .mv_outsb = landisk_outsb,
168         .mv_outsw = landisk_outsw,
169         .mv_outsl = landisk_outsl,
170         .mv_ioport_map = landisk_ioport_map,
171         .mv_init_irq = init_landisk_IRQ,
172 #ifdef CONFIG_HEARTBEAT
173         .mv_heartbeat = heartbeat_landisk,
174 #endif
175 };
176 ALIAS_MV(landisk)