2 * linux/arch/sh/board/mpc1211/setup.c
4 * Copyright (C) 2002 Saito.K & Jeanne, Fujii.Y
8 #include <linux/config.h>
9 #include <linux/init.h>
10 #include <linux/irq.h>
11 #include <linux/hdreg.h>
12 #include <linux/ide.h>
13 #include <linux/interrupt.h>
16 #include <asm/machvec.h>
17 #include <asm/mpc1211/mpc1211.h>
18 #include <asm/mpc1211/pci.h>
19 #include <asm/mpc1211/m1543c.h>
22 /* ALI15X3 SMBus address offsets */
23 #define SMBHSTSTS (0 + 0x3100)
24 #define SMBHSTCNT (1 + 0x3100)
25 #define SMBHSTSTART (2 + 0x3100)
26 #define SMBHSTCMD (7 + 0x3100)
27 #define SMBHSTADD (3 + 0x3100)
28 #define SMBHSTDAT0 (4 + 0x3100)
29 #define SMBHSTDAT1 (5 + 0x3100)
30 #define SMBBLKDAT (6 + 0x3100)
33 #define MAX_TIMEOUT 500 /* times 1/100 sec */
35 /* ALI15X3 command constants */
36 #define ALI15X3_ABORT 0x04
37 #define ALI15X3_T_OUT 0x08
38 #define ALI15X3_QUICK 0x00
39 #define ALI15X3_BYTE 0x10
40 #define ALI15X3_BYTE_DATA 0x20
41 #define ALI15X3_WORD_DATA 0x30
42 #define ALI15X3_BLOCK_DATA 0x40
43 #define ALI15X3_BLOCK_CLR 0x80
45 /* ALI15X3 status register bits */
46 #define ALI15X3_STS_IDLE 0x04
47 #define ALI15X3_STS_BUSY 0x08
48 #define ALI15X3_STS_DONE 0x10
49 #define ALI15X3_STS_DEV 0x20 /* device error */
50 #define ALI15X3_STS_COLL 0x40 /* collision or no response */
51 #define ALI15X3_STS_TERM 0x80 /* terminated by abort */
52 #define ALI15X3_STS_ERR 0xE0 /* all the bad error bits */
54 const char *get_system_type(void)
56 return "Interface MPC-1211(CTP/PCI/MPC-SH02)";
59 static void __init pci_write_config(unsigned long busNo,
63 unsigned long cnfData)
66 + ((busNo & 0xff) << 16)
67 + ((devNo & 0x1f) << 11)
68 + ((fncNo & 0x07) << 8)
69 + (cnfAdd & 0xfc)), PCIPAR);
71 ctrl_outl(cnfData, PCIPDR);
75 Initialize IRQ setting
78 static unsigned char m_irq_mask = 0xfb;
79 static unsigned char s_irq_mask = 0xff;
80 volatile unsigned long irq_err_count;
82 static void disable_mpc1211_irq(unsigned int irq)
88 m_irq_mask |= (1 << irq);
89 outb(m_irq_mask,I8259_M_MR);
91 s_irq_mask |= (1 << (irq - 8));
92 outb(s_irq_mask,I8259_S_MR);
98 static void enable_mpc1211_irq(unsigned int irq)
105 m_irq_mask &= ~(1 << irq);
106 outb(m_irq_mask,I8259_M_MR);
108 s_irq_mask &= ~(1 << (irq - 8));
109 outb(s_irq_mask,I8259_S_MR);
111 restore_flags(flags);
114 static inline int mpc1211_irq_real(unsigned int irq)
121 outb(0x0b,I8259_M_CR); /* ISR register */
122 value = inb(I8259_M_CR) & irqmask;
123 outb(0x0a,I8259_M_CR); /* back ro the IPR reg */
126 irqmask = 1<<(irq - 8);
127 outb(0x0b,I8259_S_CR); /* ISR register */
128 value = inb(I8259_S_CR) & irqmask;
129 outb(0x0a,I8259_S_CR); /* back ro the IPR reg */
133 static void mask_and_ack_mpc1211(unsigned int irq)
140 if(m_irq_mask & (1<<irq)){
141 if(!mpc1211_irq_real(irq)){
143 printk("spurious 8259A interrupt: IRQ %x\n",irq);
146 m_irq_mask |= (1<<irq);
148 inb(I8259_M_MR); /* DUMMY */
149 outb(m_irq_mask,I8259_M_MR); /* disable */
150 outb(0x60+irq,I8259_M_CR); /* EOI */
153 if(s_irq_mask & (1<<(irq - 8))){
154 if(!mpc1211_irq_real(irq)){
156 printk("spurious 8259A interrupt: IRQ %x\n",irq);
159 s_irq_mask |= (1<<(irq - 8));
161 inb(I8259_S_MR); /* DUMMY */
162 outb(s_irq_mask,I8259_S_MR); /* disable */
163 outb(0x60+(irq-8),I8259_S_CR); /* EOI */
164 outb(0x60+2,I8259_M_CR);
166 restore_flags(flags);
169 static void end_mpc1211_irq(unsigned int irq)
171 enable_mpc1211_irq(irq);
174 static unsigned int startup_mpc1211_irq(unsigned int irq)
176 enable_mpc1211_irq(irq);
180 static void shutdown_mpc1211_irq(unsigned int irq)
182 disable_mpc1211_irq(irq);
185 static struct hw_interrupt_type mpc1211_irq_type = {
186 .typename = "MPC1211-IRQ",
187 .startup = startup_mpc1211_irq,
188 .shutdown = shutdown_mpc1211_irq,
189 .enable = enable_mpc1211_irq,
190 .disable = disable_mpc1211_irq,
191 .ack = mask_and_ack_mpc1211,
192 .end = end_mpc1211_irq
195 static void make_mpc1211_irq(unsigned int irq)
197 irq_desc[irq].handler = &mpc1211_irq_type;
198 irq_desc[irq].status = IRQ_DISABLED;
199 irq_desc[irq].action = 0;
200 irq_desc[irq].depth = 1;
201 disable_mpc1211_irq(irq);
204 int mpc1211_irq_demux(int irq)
209 outb(0x0c,I8259_M_CR);
210 poll = inb(I8259_M_CR);
215 outb(0x0c,I8259_S_CR);
216 poll = inb(I8259_S_CR);
217 irq = (poll & 0x07) + 8;
223 void __init init_mpc1211_IRQ(void)
227 * Super I/O (Just mimic PC):
240 pci_write_config(0,0,0,0x54, 0xb0b0002d);
241 outb(0x11, I8259_M_CR); /* mater icw1 edge trigger */
242 outb(0x11, I8259_S_CR); /* slave icw1 edge trigger */
243 outb(0x20, I8259_M_MR); /* m icw2 base vec 0x08 */
244 outb(0x28, I8259_S_MR); /* s icw2 base vec 0x70 */
245 outb(0x04, I8259_M_MR); /* m icw3 slave irq2 */
246 outb(0x02, I8259_S_MR); /* s icw3 slave id */
247 outb(0x01, I8259_M_MR); /* m icw4 non buf normal eoi*/
248 outb(0x01, I8259_S_MR); /* s icw4 non buf normal eo1*/
249 outb(0xfb, I8259_M_MR); /* disable irq0--irq7 */
250 outb(0xff, I8259_S_MR); /* disable irq8--irq15 */
252 for ( i=0; i < 16; i++) {
264 static void delay (void)
266 volatile unsigned short tmp;
267 tmp = *(volatile unsigned short *) 0xa0000000;
270 static void delay1000 (void)
274 for (i=0; i<1000; i++)
278 static int put_smb_blk(unsigned char *p, int address, int command, int no)
284 outb(0xff, SMBHSTSTS);
285 temp = inb(SMBHSTSTS);
286 for (timeout = 0; (timeout < MAX_TIMEOUT) && !(temp & ALI15X3_STS_IDLE); timeout++) {
288 temp = inb(SMBHSTSTS);
290 if (timeout >= MAX_TIMEOUT){
294 outb(((address & 0x7f) << 1), SMBHSTADD);
295 outb(0xc0, SMBHSTCNT);
296 outb(command & 0xff, SMBHSTCMD);
297 outb(no & 0x1f, SMBHSTDAT0);
299 for(i = 1; i <= no; i++) {
300 outb(*p++, SMBBLKDAT);
302 outb(0xff, SMBHSTSTART);
304 temp = inb(SMBHSTSTS);
305 for (timeout = 0; (timeout < MAX_TIMEOUT) && !(temp & (ALI15X3_STS_ERR | ALI15X3_STS_DONE)); timeout++) {
307 temp = inb(SMBHSTSTS);
309 if (timeout >= MAX_TIMEOUT) {
312 if ( temp & ALI15X3_STS_ERR ){
322 struct sh_machine_vector mv_mpc1211 __initmv = {
324 .mv_irq_demux = mpc1211_irq_demux,
325 .mv_init_irq = init_mpc1211_IRQ,
327 #ifdef CONFIG_HEARTBEAT
328 .mv_heartbeat = heartbeat_mpc1211,
334 /* arch/sh/boards/mpc1211/rtc.c */
335 void mpc1211_time_init(void);
337 int __init platform_setup(void)
339 unsigned char spd_buf[128];
341 __set_io_port_base(PA_PCI_IO);
343 pci_write_config(0,0,0,0x54, 0xb0b00000);
346 outb(ALI15X3_ABORT, SMBHSTCNT);
354 } while (put_smb_blk(spd_buf, 0x69, 0, 7) < 0);
356 board_time_init = mpc1211_time_init;