setup.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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. #endif /* CONFIG_PCI */
  112. }
  113. /* SPI support */
  114. /* chip select for SPI devices */
  115. #define SEEPROM1_CS 7 /* PIO7 */
  116. #define SEEPROM2_CS 0 /* IOC */
  117. #define SEEPROM3_CS 1 /* IOC */
  118. #define SRTC_CS 2 /* IOC */
  119. static int __init rbtx4938_ethaddr_init(void)
  120. {
  121. #ifdef CONFIG_PCI
  122. unsigned char dat[17];
  123. unsigned char sum;
  124. int i;
  125. /* 0-3: "MAC\0", 4-9:eth0, 10-15:eth1, 16:sum */
  126. if (spi_eeprom_read(SEEPROM1_CS, 0, dat, sizeof(dat))) {
  127. printk(KERN_ERR "seeprom: read error.\n");
  128. return -ENODEV;
  129. } else {
  130. if (strcmp(dat, "MAC") != 0)
  131. printk(KERN_WARNING "seeprom: bad signature.\n");
  132. for (i = 0, sum = 0; i < sizeof(dat); i++)
  133. sum += dat[i];
  134. if (sum)
  135. printk(KERN_WARNING "seeprom: bad checksum.\n");
  136. }
  137. for (i = 0; i < 2; i++) {
  138. unsigned int id =
  139. TXX9_IRQ_BASE + (i ? TX4938_IR_ETH1 : TX4938_IR_ETH0);
  140. struct platform_device *pdev;
  141. if (!(__raw_readq(&tx4938_ccfgptr->pcfg) &
  142. (i ? TX4938_PCFG_ETH1_SEL : TX4938_PCFG_ETH0_SEL)))
  143. continue;
  144. pdev = platform_device_alloc("tc35815-mac", id);
  145. if (!pdev ||
  146. platform_device_add_data(pdev, &dat[4 + 6 * i], 6) ||
  147. platform_device_add(pdev))
  148. platform_device_put(pdev);
  149. }
  150. #endif /* CONFIG_PCI */
  151. return 0;
  152. }
  153. static void __init rbtx4938_spi_setup(void)
  154. {
  155. /* set SPI_SEL */
  156. txx9_set64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_SPI_SEL);
  157. }
  158. static struct resource rbtx4938_fpga_resource;
  159. static void __init rbtx4938_time_init(void)
  160. {
  161. tx4938_time_init(0);
  162. }
  163. static void __init rbtx4938_mem_setup(void)
  164. {
  165. unsigned long long pcfg;
  166. char *argptr;
  167. if (txx9_master_clock == 0)
  168. txx9_master_clock = 25000000; /* 25MHz */
  169. tx4938_setup();
  170. #ifdef CONFIG_PCI
  171. txx9_alloc_pci_controller(&txx9_primary_pcic, 0, 0, 0, 0);
  172. #else
  173. set_io_port_base(RBTX4938_ETHER_BASE);
  174. #endif
  175. tx4938_setup_serial();
  176. #ifdef CONFIG_SERIAL_TXX9_CONSOLE
  177. argptr = prom_getcmdline();
  178. if (strstr(argptr, "console=") == NULL) {
  179. strcat(argptr, " console=ttyS0,38400");
  180. }
  181. #endif
  182. #ifdef CONFIG_TOSHIBA_RBTX4938_MPLEX_PIO58_61
  183. printk("PIOSEL: disabling both ata and nand selection\n");
  184. local_irq_disable();
  185. txx9_clear64(&tx4938_ccfgptr->pcfg,
  186. TX4938_PCFG_NDF_SEL | TX4938_PCFG_ATA_SEL);
  187. #endif
  188. #ifdef CONFIG_TOSHIBA_RBTX4938_MPLEX_NAND
  189. printk("PIOSEL: enabling nand selection\n");
  190. txx9_set64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_NDF_SEL);
  191. txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_ATA_SEL);
  192. #endif
  193. #ifdef CONFIG_TOSHIBA_RBTX4938_MPLEX_ATA
  194. printk("PIOSEL: enabling ata selection\n");
  195. txx9_set64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_ATA_SEL);
  196. txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_NDF_SEL);
  197. #endif
  198. #ifdef CONFIG_IP_PNP
  199. argptr = prom_getcmdline();
  200. if (strstr(argptr, "ip=") == NULL) {
  201. strcat(argptr, " ip=any");
  202. }
  203. #endif
  204. #ifdef CONFIG_FB
  205. {
  206. conswitchp = &dummy_con;
  207. }
  208. #endif
  209. rbtx4938_spi_setup();
  210. pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg); /* updated */
  211. /* fixup piosel */
  212. if ((pcfg & (TX4938_PCFG_ATA_SEL | TX4938_PCFG_NDF_SEL)) ==
  213. TX4938_PCFG_ATA_SEL)
  214. writeb((readb(rbtx4938_piosel_addr) & 0x03) | 0x04,
  215. rbtx4938_piosel_addr);
  216. else if ((pcfg & (TX4938_PCFG_ATA_SEL | TX4938_PCFG_NDF_SEL)) ==
  217. TX4938_PCFG_NDF_SEL)
  218. writeb((readb(rbtx4938_piosel_addr) & 0x03) | 0x08,
  219. rbtx4938_piosel_addr);
  220. else
  221. writeb(readb(rbtx4938_piosel_addr) & ~(0x08 | 0x04),
  222. rbtx4938_piosel_addr);
  223. rbtx4938_fpga_resource.name = "FPGA Registers";
  224. rbtx4938_fpga_resource.start = CPHYSADDR(RBTX4938_FPGA_REG_ADDR);
  225. rbtx4938_fpga_resource.end = CPHYSADDR(RBTX4938_FPGA_REG_ADDR) + 0xffff;
  226. rbtx4938_fpga_resource.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  227. if (request_resource(&txx9_ce_res[2], &rbtx4938_fpga_resource))
  228. printk("request resource for fpga failed\n");
  229. _machine_restart = rbtx4938_machine_restart;
  230. _machine_halt = rbtx4938_machine_halt;
  231. pm_power_off = rbtx4938_machine_power_off;
  232. writeb(0xff, rbtx4938_led_addr);
  233. printk(KERN_INFO "RBTX4938 --- FPGA(Rev %02x) DIPSW:%02x,%02x\n",
  234. readb(rbtx4938_fpga_rev_addr),
  235. readb(rbtx4938_dipsw_addr), readb(rbtx4938_bdipsw_addr));
  236. }
  237. static int __init rbtx4938_ne_init(void)
  238. {
  239. struct resource res[] = {
  240. {
  241. .start = RBTX4938_RTL_8019_BASE,
  242. .end = RBTX4938_RTL_8019_BASE + 0x20 - 1,
  243. .flags = IORESOURCE_IO,
  244. }, {
  245. .start = RBTX4938_RTL_8019_IRQ,
  246. .flags = IORESOURCE_IRQ,
  247. }
  248. };
  249. struct platform_device *dev =
  250. platform_device_register_simple("ne", -1,
  251. res, ARRAY_SIZE(res));
  252. return IS_ERR(dev) ? PTR_ERR(dev) : 0;
  253. }
  254. static DEFINE_SPINLOCK(rbtx4938_spi_gpio_lock);
  255. static void rbtx4938_spi_gpio_set(struct gpio_chip *chip, unsigned int offset,
  256. int value)
  257. {
  258. u8 val;
  259. unsigned long flags;
  260. spin_lock_irqsave(&rbtx4938_spi_gpio_lock, flags);
  261. val = readb(rbtx4938_spics_addr);
  262. if (value)
  263. val |= 1 << offset;
  264. else
  265. val &= ~(1 << offset);
  266. writeb(val, rbtx4938_spics_addr);
  267. mmiowb();
  268. spin_unlock_irqrestore(&rbtx4938_spi_gpio_lock, flags);
  269. }
  270. static int rbtx4938_spi_gpio_dir_out(struct gpio_chip *chip,
  271. unsigned int offset, int value)
  272. {
  273. rbtx4938_spi_gpio_set(chip, offset, value);
  274. return 0;
  275. }
  276. static struct gpio_chip rbtx4938_spi_gpio_chip = {
  277. .set = rbtx4938_spi_gpio_set,
  278. .direction_output = rbtx4938_spi_gpio_dir_out,
  279. .label = "RBTX4938-SPICS",
  280. .base = 16,
  281. .ngpio = 3,
  282. };
  283. /* SPI support */
  284. static void __init txx9_spi_init(unsigned long base, int irq)
  285. {
  286. struct resource res[] = {
  287. {
  288. .start = base,
  289. .end = base + 0x20 - 1,
  290. .flags = IORESOURCE_MEM,
  291. }, {
  292. .start = irq,
  293. .flags = IORESOURCE_IRQ,
  294. },
  295. };
  296. platform_device_register_simple("spi_txx9", 0,
  297. res, ARRAY_SIZE(res));
  298. }
  299. static int __init rbtx4938_spi_init(void)
  300. {
  301. struct spi_board_info srtc_info = {
  302. .modalias = "rtc-rs5c348",
  303. .max_speed_hz = 1000000, /* 1.0Mbps @ Vdd 2.0V */
  304. .bus_num = 0,
  305. .chip_select = 16 + SRTC_CS,
  306. /* Mode 1 (High-Active, Shift-Then-Sample), High Avtive CS */
  307. .mode = SPI_MODE_1 | SPI_CS_HIGH,
  308. };
  309. spi_register_board_info(&srtc_info, 1);
  310. spi_eeprom_register(SEEPROM1_CS);
  311. spi_eeprom_register(16 + SEEPROM2_CS);
  312. spi_eeprom_register(16 + SEEPROM3_CS);
  313. gpio_request(16 + SRTC_CS, "rtc-rs5c348");
  314. gpio_direction_output(16 + SRTC_CS, 0);
  315. gpio_request(SEEPROM1_CS, "seeprom1");
  316. gpio_direction_output(SEEPROM1_CS, 1);
  317. gpio_request(16 + SEEPROM2_CS, "seeprom2");
  318. gpio_direction_output(16 + SEEPROM2_CS, 1);
  319. gpio_request(16 + SEEPROM3_CS, "seeprom3");
  320. gpio_direction_output(16 + SEEPROM3_CS, 1);
  321. txx9_spi_init(TX4938_SPI_REG & 0xfffffffffULL, RBTX4938_IRQ_IRC_SPI);
  322. return 0;
  323. }
  324. static void __init rbtx4938_arch_init(void)
  325. {
  326. gpiochip_add(&rbtx4938_spi_gpio_chip);
  327. rbtx4938_pci_setup();
  328. rbtx4938_spi_init();
  329. }
  330. /* Watchdog support */
  331. static int __init txx9_wdt_init(unsigned long base)
  332. {
  333. struct resource res = {
  334. .start = base,
  335. .end = base + 0x100 - 1,
  336. .flags = IORESOURCE_MEM,
  337. };
  338. struct platform_device *dev =
  339. platform_device_register_simple("txx9wdt", -1, &res, 1);
  340. return IS_ERR(dev) ? PTR_ERR(dev) : 0;
  341. }
  342. static int __init rbtx4938_wdt_init(void)
  343. {
  344. return txx9_wdt_init(TX4938_TMR_REG(2) & 0xfffffffffULL);
  345. }
  346. static void __init rbtx4938_device_init(void)
  347. {
  348. rbtx4938_ethaddr_init();
  349. rbtx4938_ne_init();
  350. rbtx4938_wdt_init();
  351. }
  352. struct txx9_board_vec rbtx4938_vec __initdata = {
  353. .system = "Toshiba RBTX4938",
  354. .prom_init = rbtx4938_prom_init,
  355. .mem_setup = rbtx4938_mem_setup,
  356. .irq_setup = rbtx4938_irq_setup,
  357. .time_init = rbtx4938_time_init,
  358. .device_init = rbtx4938_device_init,
  359. .arch_init = rbtx4938_arch_init,
  360. #ifdef CONFIG_PCI
  361. .pci_map_irq = rbtx4938_pci_map_irq,
  362. #endif
  363. };