setup.c 10 KB

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