setup.c 11 KB

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