setup.c 10 KB

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