]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/mips/txx9/rbtx4938/setup.c
fc9034db526e8eb58495ec842b789e3d1d00aa2b
[linux-2.6-omap-h63xx.git] / arch / mips / txx9 / rbtx4938 / setup.c
1 /*
2  * Setup pointers to hardware-dependent routines.
3  * Copyright (C) 2000-2001 Toshiba Corporation
4  *
5  * 2003-2005 (c) MontaVista Software, Inc. This file is licensed under the
6  * terms of the GNU General Public License version 2. This program is
7  * licensed "as is" without any warranty of any kind, whether express
8  * or implied.
9  *
10  * Support for TX4938 in 2.6 - Manish Lachwani (mlachwani@mvista.com)
11  */
12 #include <linux/init.h>
13 #include <linux/types.h>
14 #include <linux/ioport.h>
15 #include <linux/delay.h>
16 #include <linux/interrupt.h>
17 #include <linux/console.h>
18 #include <linux/pm.h>
19 #include <linux/platform_device.h>
20 #include <linux/gpio.h>
21
22 #include <asm/reboot.h>
23 #include <asm/io.h>
24 #include <asm/txx9/generic.h>
25 #include <asm/txx9/pci.h>
26 #include <asm/txx9/rbtx4938.h>
27 #include <linux/spi/spi.h>
28 #include <asm/txx9/spi.h>
29 #include <asm/txx9pio.h>
30
31 static void rbtx4938_machine_halt(void)
32 {
33         printk(KERN_NOTICE "System Halted\n");
34         local_irq_disable();
35
36         while (1)
37                 __asm__(".set\tmips3\n\t"
38                         "wait\n\t"
39                         ".set\tmips0");
40 }
41
42 static void rbtx4938_machine_power_off(void)
43 {
44         rbtx4938_machine_halt();
45         /* no return */
46 }
47
48 static void rbtx4938_machine_restart(char *command)
49 {
50         local_irq_disable();
51
52         printk("Rebooting...");
53         writeb(1, rbtx4938_softresetlock_addr);
54         writeb(1, rbtx4938_sfvol_addr);
55         writeb(1, rbtx4938_softreset_addr);
56         while(1)
57                 ;
58 }
59
60 static void __init rbtx4938_pci_setup(void)
61 {
62 #ifdef CONFIG_PCI
63         int extarb = !(__raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCIARB);
64         struct pci_controller *c = &txx9_primary_pcic;
65
66         register_pci_controller(c);
67
68         if (__raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCI66)
69                 txx9_pci_option =
70                         (txx9_pci_option & ~TXX9_PCI_OPT_CLK_MASK) |
71                         TXX9_PCI_OPT_CLK_66; /* already configured */
72
73         /* Reset PCI Bus */
74         writeb(0, rbtx4938_pcireset_addr);
75         /* Reset PCIC */
76         txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
77         if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) ==
78             TXX9_PCI_OPT_CLK_66)
79                 tx4938_pciclk66_setup();
80         mdelay(10);
81         /* clear PCIC reset */
82         txx9_clear64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
83         writeb(1, rbtx4938_pcireset_addr);
84         iob();
85
86         tx4938_report_pciclk();
87         tx4927_pcic_setup(tx4938_pcicptr, c, extarb);
88         if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) ==
89             TXX9_PCI_OPT_CLK_AUTO &&
90             txx9_pci66_check(c, 0, 0)) {
91                 /* Reset PCI Bus */
92                 writeb(0, rbtx4938_pcireset_addr);
93                 /* Reset PCIC */
94                 txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
95                 tx4938_pciclk66_setup();
96                 mdelay(10);
97                 /* clear PCIC reset */
98                 txx9_clear64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
99                 writeb(1, rbtx4938_pcireset_addr);
100                 iob();
101                 /* Reinitialize PCIC */
102                 tx4938_report_pciclk();
103                 tx4927_pcic_setup(tx4938_pcicptr, c, extarb);
104         }
105
106         if (__raw_readq(&tx4938_ccfgptr->pcfg) &
107             (TX4938_PCFG_ETH0_SEL|TX4938_PCFG_ETH1_SEL)) {
108                 /* Reset PCIC1 */
109                 txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIC1RST);
110                 /* PCI1DMD==0 => PCI1CLK==GBUSCLK/2 => PCI66 */
111                 if (!(__raw_readq(&tx4938_ccfgptr->ccfg)
112                       & TX4938_CCFG_PCI1DMD))
113                         tx4938_ccfg_set(TX4938_CCFG_PCI1_66);
114                 mdelay(10);
115                 /* clear PCIC1 reset */
116                 txx9_clear64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIC1RST);
117                 tx4938_report_pci1clk();
118
119                 /* mem:64K(max), io:64K(max) (enough for ETH0,ETH1) */
120                 c = txx9_alloc_pci_controller(NULL, 0, 0x10000, 0, 0x10000);
121                 register_pci_controller(c);
122                 tx4927_pcic_setup(tx4938_pcic1ptr, c, 0);
123         }
124 #endif /* CONFIG_PCI */
125 }
126
127 /* SPI support */
128
129 /* chip select for SPI devices */
130 #define SEEPROM1_CS     7       /* PIO7 */
131 #define SEEPROM2_CS     0       /* IOC */
132 #define SEEPROM3_CS     1       /* IOC */
133 #define SRTC_CS 2       /* IOC */
134
135 static int __init rbtx4938_ethaddr_init(void)
136 {
137 #ifdef CONFIG_PCI
138         unsigned char dat[17];
139         unsigned char sum;
140         int i;
141
142         /* 0-3: "MAC\0", 4-9:eth0, 10-15:eth1, 16:sum */
143         if (spi_eeprom_read(SEEPROM1_CS, 0, dat, sizeof(dat))) {
144                 printk(KERN_ERR "seeprom: read error.\n");
145                 return -ENODEV;
146         } else {
147                 if (strcmp(dat, "MAC") != 0)
148                         printk(KERN_WARNING "seeprom: bad signature.\n");
149                 for (i = 0, sum = 0; i < sizeof(dat); i++)
150                         sum += dat[i];
151                 if (sum)
152                         printk(KERN_WARNING "seeprom: bad checksum.\n");
153         }
154         for (i = 0; i < 2; i++) {
155                 unsigned int id =
156                         TXX9_IRQ_BASE + (i ? TX4938_IR_ETH1 : TX4938_IR_ETH0);
157                 struct platform_device *pdev;
158                 if (!(__raw_readq(&tx4938_ccfgptr->pcfg) &
159                       (i ? TX4938_PCFG_ETH1_SEL : TX4938_PCFG_ETH0_SEL)))
160                         continue;
161                 pdev = platform_device_alloc("tc35815-mac", id);
162                 if (!pdev ||
163                     platform_device_add_data(pdev, &dat[4 + 6 * i], 6) ||
164                     platform_device_add(pdev))
165                         platform_device_put(pdev);
166         }
167 #endif /* CONFIG_PCI */
168         return 0;
169 }
170
171 static void __init rbtx4938_spi_setup(void)
172 {
173         /* set SPI_SEL */
174         txx9_set64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_SPI_SEL);
175 }
176
177 static struct resource rbtx4938_fpga_resource;
178
179 static void __init rbtx4938_time_init(void)
180 {
181         tx4938_time_init(0);
182 }
183
184 static void __init rbtx4938_mem_setup(void)
185 {
186         unsigned long long pcfg;
187         char *argptr;
188
189         if (txx9_master_clock == 0)
190                 txx9_master_clock = 25000000; /* 25MHz */
191
192         tx4938_setup();
193
194 #ifdef CONFIG_PCI
195         txx9_alloc_pci_controller(&txx9_primary_pcic, 0, 0, 0, 0);
196         txx9_board_pcibios_setup = tx4927_pcibios_setup;
197 #else
198         set_io_port_base(RBTX4938_ETHER_BASE);
199 #endif
200
201         tx4938_setup_serial();
202 #ifdef CONFIG_SERIAL_TXX9_CONSOLE
203         argptr = prom_getcmdline();
204         if (strstr(argptr, "console=") == NULL) {
205                 strcat(argptr, " console=ttyS0,38400");
206         }
207 #endif
208
209 #ifdef CONFIG_TOSHIBA_RBTX4938_MPLEX_PIO58_61
210         printk("PIOSEL: disabling both ata and nand selection\n");
211         local_irq_disable();
212         txx9_clear64(&tx4938_ccfgptr->pcfg,
213                      TX4938_PCFG_NDF_SEL | TX4938_PCFG_ATA_SEL);
214 #endif
215
216 #ifdef CONFIG_TOSHIBA_RBTX4938_MPLEX_NAND
217         printk("PIOSEL: enabling nand selection\n");
218         txx9_set64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_NDF_SEL);
219         txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_ATA_SEL);
220 #endif
221
222 #ifdef CONFIG_TOSHIBA_RBTX4938_MPLEX_ATA
223         printk("PIOSEL: enabling ata selection\n");
224         txx9_set64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_ATA_SEL);
225         txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_NDF_SEL);
226 #endif
227
228 #ifdef CONFIG_IP_PNP
229         argptr = prom_getcmdline();
230         if (strstr(argptr, "ip=") == NULL) {
231                 strcat(argptr, " ip=any");
232         }
233 #endif
234
235
236 #ifdef CONFIG_FB
237         {
238                 conswitchp = &dummy_con;
239         }
240 #endif
241
242         rbtx4938_spi_setup();
243         pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg);    /* updated */
244         /* fixup piosel */
245         if ((pcfg & (TX4938_PCFG_ATA_SEL | TX4938_PCFG_NDF_SEL)) ==
246             TX4938_PCFG_ATA_SEL)
247                 writeb((readb(rbtx4938_piosel_addr) & 0x03) | 0x04,
248                        rbtx4938_piosel_addr);
249         else if ((pcfg & (TX4938_PCFG_ATA_SEL | TX4938_PCFG_NDF_SEL)) ==
250                  TX4938_PCFG_NDF_SEL)
251                 writeb((readb(rbtx4938_piosel_addr) & 0x03) | 0x08,
252                        rbtx4938_piosel_addr);
253         else
254                 writeb(readb(rbtx4938_piosel_addr) & ~(0x08 | 0x04),
255                        rbtx4938_piosel_addr);
256
257         rbtx4938_fpga_resource.name = "FPGA Registers";
258         rbtx4938_fpga_resource.start = CPHYSADDR(RBTX4938_FPGA_REG_ADDR);
259         rbtx4938_fpga_resource.end = CPHYSADDR(RBTX4938_FPGA_REG_ADDR) + 0xffff;
260         rbtx4938_fpga_resource.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
261         if (request_resource(&txx9_ce_res[2], &rbtx4938_fpga_resource))
262                 printk("request resource for fpga failed\n");
263
264         _machine_restart = rbtx4938_machine_restart;
265         _machine_halt = rbtx4938_machine_halt;
266         pm_power_off = rbtx4938_machine_power_off;
267
268         writeb(0xff, rbtx4938_led_addr);
269         printk(KERN_INFO "RBTX4938 --- FPGA(Rev %02x) DIPSW:%02x,%02x\n",
270                readb(rbtx4938_fpga_rev_addr),
271                readb(rbtx4938_dipsw_addr), readb(rbtx4938_bdipsw_addr));
272 }
273
274 static int __init rbtx4938_ne_init(void)
275 {
276         struct resource res[] = {
277                 {
278                         .start  = RBTX4938_RTL_8019_BASE,
279                         .end    = RBTX4938_RTL_8019_BASE + 0x20 - 1,
280                         .flags  = IORESOURCE_IO,
281                 }, {
282                         .start  = RBTX4938_RTL_8019_IRQ,
283                         .flags  = IORESOURCE_IRQ,
284                 }
285         };
286         struct platform_device *dev =
287                 platform_device_register_simple("ne", -1,
288                                                 res, ARRAY_SIZE(res));
289         return IS_ERR(dev) ? PTR_ERR(dev) : 0;
290 }
291
292 static DEFINE_SPINLOCK(rbtx4938_spi_gpio_lock);
293
294 static void rbtx4938_spi_gpio_set(struct gpio_chip *chip, unsigned int offset,
295                                   int value)
296 {
297         u8 val;
298         unsigned long flags;
299         spin_lock_irqsave(&rbtx4938_spi_gpio_lock, flags);
300         val = readb(rbtx4938_spics_addr);
301         if (value)
302                 val |= 1 << offset;
303         else
304                 val &= ~(1 << offset);
305         writeb(val, rbtx4938_spics_addr);
306         mmiowb();
307         spin_unlock_irqrestore(&rbtx4938_spi_gpio_lock, flags);
308 }
309
310 static int rbtx4938_spi_gpio_dir_out(struct gpio_chip *chip,
311                                      unsigned int offset, int value)
312 {
313         rbtx4938_spi_gpio_set(chip, offset, value);
314         return 0;
315 }
316
317 static struct gpio_chip rbtx4938_spi_gpio_chip = {
318         .set = rbtx4938_spi_gpio_set,
319         .direction_output = rbtx4938_spi_gpio_dir_out,
320         .label = "RBTX4938-SPICS",
321         .base = 16,
322         .ngpio = 3,
323 };
324
325 /* SPI support */
326
327 static void __init txx9_spi_init(unsigned long base, int irq)
328 {
329         struct resource res[] = {
330                 {
331                         .start  = base,
332                         .end    = base + 0x20 - 1,
333                         .flags  = IORESOURCE_MEM,
334                 }, {
335                         .start  = irq,
336                         .flags  = IORESOURCE_IRQ,
337                 },
338         };
339         platform_device_register_simple("spi_txx9", 0,
340                                         res, ARRAY_SIZE(res));
341 }
342
343 static int __init rbtx4938_spi_init(void)
344 {
345         struct spi_board_info srtc_info = {
346                 .modalias = "rtc-rs5c348",
347                 .max_speed_hz = 1000000, /* 1.0Mbps @ Vdd 2.0V */
348                 .bus_num = 0,
349                 .chip_select = 16 + SRTC_CS,
350                 /* Mode 1 (High-Active, Shift-Then-Sample), High Avtive CS  */
351                 .mode = SPI_MODE_1 | SPI_CS_HIGH,
352         };
353         spi_register_board_info(&srtc_info, 1);
354         spi_eeprom_register(SEEPROM1_CS);
355         spi_eeprom_register(16 + SEEPROM2_CS);
356         spi_eeprom_register(16 + SEEPROM3_CS);
357         gpio_request(16 + SRTC_CS, "rtc-rs5c348");
358         gpio_direction_output(16 + SRTC_CS, 0);
359         gpio_request(SEEPROM1_CS, "seeprom1");
360         gpio_direction_output(SEEPROM1_CS, 1);
361         gpio_request(16 + SEEPROM2_CS, "seeprom2");
362         gpio_direction_output(16 + SEEPROM2_CS, 1);
363         gpio_request(16 + SEEPROM3_CS, "seeprom3");
364         gpio_direction_output(16 + SEEPROM3_CS, 1);
365         txx9_spi_init(TX4938_SPI_REG & 0xfffffffffULL, RBTX4938_IRQ_IRC_SPI);
366         return 0;
367 }
368
369 static void __init rbtx4938_arch_init(void)
370 {
371         gpiochip_add(&rbtx4938_spi_gpio_chip);
372         rbtx4938_pci_setup();
373         rbtx4938_spi_init();
374 }
375
376 /* Watchdog support */
377
378 static int __init txx9_wdt_init(unsigned long base)
379 {
380         struct resource res = {
381                 .start  = base,
382                 .end    = base + 0x100 - 1,
383                 .flags  = IORESOURCE_MEM,
384         };
385         struct platform_device *dev =
386                 platform_device_register_simple("txx9wdt", -1, &res, 1);
387         return IS_ERR(dev) ? PTR_ERR(dev) : 0;
388 }
389
390 static int __init rbtx4938_wdt_init(void)
391 {
392         return txx9_wdt_init(TX4938_TMR_REG(2) & 0xfffffffffULL);
393 }
394
395 static void __init rbtx4938_device_init(void)
396 {
397         rbtx4938_ethaddr_init();
398         rbtx4938_ne_init();
399         rbtx4938_wdt_init();
400 }
401
402 struct txx9_board_vec rbtx4938_vec __initdata = {
403         .system = "Toshiba RBTX4938",
404         .prom_init = rbtx4938_prom_init,
405         .mem_setup = rbtx4938_mem_setup,
406         .irq_setup = rbtx4938_irq_setup,
407         .time_init = rbtx4938_time_init,
408         .device_init = rbtx4938_device_init,
409         .arch_init = rbtx4938_arch_init,
410 #ifdef CONFIG_PCI
411         .pci_map_irq = rbtx4938_pci_map_irq,
412 #endif
413 };