setup.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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. char *argptr;
  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_SERIAL_TXX9_CONSOLE
  151. argptr = prom_getcmdline();
  152. if (!strstr(argptr, "console="))
  153. strcat(argptr, " console=ttyS0,38400");
  154. #endif
  155. #ifdef CONFIG_TOSHIBA_RBTX4938_MPLEX_PIO58_61
  156. pr_info("PIOSEL: disabling both ATA and NAND selection\n");
  157. txx9_clear64(&tx4938_ccfgptr->pcfg,
  158. TX4938_PCFG_NDF_SEL | TX4938_PCFG_ATA_SEL);
  159. #endif
  160. #ifdef CONFIG_TOSHIBA_RBTX4938_MPLEX_NAND
  161. pr_info("PIOSEL: enabling NAND selection\n");
  162. txx9_set64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_NDF_SEL);
  163. txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_ATA_SEL);
  164. #endif
  165. #ifdef CONFIG_TOSHIBA_RBTX4938_MPLEX_ATA
  166. pr_info("PIOSEL: enabling ATA selection\n");
  167. txx9_set64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_ATA_SEL);
  168. txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_NDF_SEL);
  169. #endif
  170. #ifdef CONFIG_TOSHIBA_RBTX4938_MPLEX_KEEP
  171. pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg);
  172. pr_info("PIOSEL: NAND %s, ATA %s\n",
  173. (pcfg & TX4938_PCFG_NDF_SEL) ? "enabled" : "disabled",
  174. (pcfg & TX4938_PCFG_ATA_SEL) ? "enabled" : "disabled");
  175. #endif
  176. rbtx4938_spi_setup();
  177. pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg); /* updated */
  178. /* fixup piosel */
  179. if ((pcfg & (TX4938_PCFG_ATA_SEL | TX4938_PCFG_NDF_SEL)) ==
  180. TX4938_PCFG_ATA_SEL)
  181. writeb((readb(rbtx4938_piosel_addr) & 0x03) | 0x04,
  182. rbtx4938_piosel_addr);
  183. else if ((pcfg & (TX4938_PCFG_ATA_SEL | TX4938_PCFG_NDF_SEL)) ==
  184. TX4938_PCFG_NDF_SEL)
  185. writeb((readb(rbtx4938_piosel_addr) & 0x03) | 0x08,
  186. rbtx4938_piosel_addr);
  187. else
  188. writeb(readb(rbtx4938_piosel_addr) & ~(0x08 | 0x04),
  189. rbtx4938_piosel_addr);
  190. rbtx4938_fpga_resource.name = "FPGA Registers";
  191. rbtx4938_fpga_resource.start = CPHYSADDR(RBTX4938_FPGA_REG_ADDR);
  192. rbtx4938_fpga_resource.end = CPHYSADDR(RBTX4938_FPGA_REG_ADDR) + 0xffff;
  193. rbtx4938_fpga_resource.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  194. if (request_resource(&txx9_ce_res[2], &rbtx4938_fpga_resource))
  195. printk(KERN_ERR "request resource for fpga failed\n");
  196. _machine_restart = rbtx4938_machine_restart;
  197. writeb(0xff, rbtx4938_led_addr);
  198. printk(KERN_INFO "RBTX4938 --- FPGA(Rev %02x) DIPSW:%02x,%02x\n",
  199. readb(rbtx4938_fpga_rev_addr),
  200. readb(rbtx4938_dipsw_addr), readb(rbtx4938_bdipsw_addr));
  201. }
  202. static void __init rbtx4938_ne_init(void)
  203. {
  204. struct resource res[] = {
  205. {
  206. .start = RBTX4938_RTL_8019_BASE,
  207. .end = RBTX4938_RTL_8019_BASE + 0x20 - 1,
  208. .flags = IORESOURCE_IO,
  209. }, {
  210. .start = RBTX4938_RTL_8019_IRQ,
  211. .flags = IORESOURCE_IRQ,
  212. }
  213. };
  214. platform_device_register_simple("ne", -1, res, ARRAY_SIZE(res));
  215. }
  216. static DEFINE_SPINLOCK(rbtx4938_spi_gpio_lock);
  217. static void rbtx4938_spi_gpio_set(struct gpio_chip *chip, unsigned int offset,
  218. int value)
  219. {
  220. u8 val;
  221. unsigned long flags;
  222. spin_lock_irqsave(&rbtx4938_spi_gpio_lock, flags);
  223. val = readb(rbtx4938_spics_addr);
  224. if (value)
  225. val |= 1 << offset;
  226. else
  227. val &= ~(1 << offset);
  228. writeb(val, rbtx4938_spics_addr);
  229. mmiowb();
  230. spin_unlock_irqrestore(&rbtx4938_spi_gpio_lock, flags);
  231. }
  232. static int rbtx4938_spi_gpio_dir_out(struct gpio_chip *chip,
  233. unsigned int offset, int value)
  234. {
  235. rbtx4938_spi_gpio_set(chip, offset, value);
  236. return 0;
  237. }
  238. static struct gpio_chip rbtx4938_spi_gpio_chip = {
  239. .set = rbtx4938_spi_gpio_set,
  240. .direction_output = rbtx4938_spi_gpio_dir_out,
  241. .label = "RBTX4938-SPICS",
  242. .base = 16,
  243. .ngpio = 3,
  244. };
  245. static int __init rbtx4938_spi_init(void)
  246. {
  247. struct spi_board_info srtc_info = {
  248. .modalias = "rtc-rs5c348",
  249. .max_speed_hz = 1000000, /* 1.0Mbps @ Vdd 2.0V */
  250. .bus_num = 0,
  251. .chip_select = 16 + SRTC_CS,
  252. /* Mode 1 (High-Active, Shift-Then-Sample), High Avtive CS */
  253. .mode = SPI_MODE_1 | SPI_CS_HIGH,
  254. };
  255. spi_register_board_info(&srtc_info, 1);
  256. spi_eeprom_register(SPI_BUSNO, SEEPROM1_CS, 128);
  257. spi_eeprom_register(SPI_BUSNO, 16 + SEEPROM2_CS, 128);
  258. spi_eeprom_register(SPI_BUSNO, 16 + SEEPROM3_CS, 128);
  259. gpio_request(16 + SRTC_CS, "rtc-rs5c348");
  260. gpio_direction_output(16 + SRTC_CS, 0);
  261. gpio_request(SEEPROM1_CS, "seeprom1");
  262. gpio_direction_output(SEEPROM1_CS, 1);
  263. gpio_request(16 + SEEPROM2_CS, "seeprom2");
  264. gpio_direction_output(16 + SEEPROM2_CS, 1);
  265. gpio_request(16 + SEEPROM3_CS, "seeprom3");
  266. gpio_direction_output(16 + SEEPROM3_CS, 1);
  267. tx4938_spi_init(SPI_BUSNO);
  268. return 0;
  269. }
  270. static void __init rbtx4938_mtd_init(void)
  271. {
  272. struct physmap_flash_data pdata = {
  273. .width = 4,
  274. };
  275. switch (readb(rbtx4938_bdipsw_addr) & 7) {
  276. case 0:
  277. /* Boot */
  278. txx9_physmap_flash_init(0, 0x1fc00000, 0x400000, &pdata);
  279. /* System */
  280. txx9_physmap_flash_init(1, 0x1e000000, 0x1000000, &pdata);
  281. break;
  282. case 1:
  283. /* System */
  284. txx9_physmap_flash_init(0, 0x1f000000, 0x1000000, &pdata);
  285. /* Boot */
  286. txx9_physmap_flash_init(1, 0x1ec00000, 0x400000, &pdata);
  287. break;
  288. case 2:
  289. /* Ext */
  290. txx9_physmap_flash_init(0, 0x1f000000, 0x1000000, &pdata);
  291. /* System */
  292. txx9_physmap_flash_init(1, 0x1e000000, 0x1000000, &pdata);
  293. /* Boot */
  294. txx9_physmap_flash_init(2, 0x1dc00000, 0x400000, &pdata);
  295. break;
  296. case 3:
  297. /* Boot */
  298. txx9_physmap_flash_init(1, 0x1bc00000, 0x400000, &pdata);
  299. /* System */
  300. txx9_physmap_flash_init(2, 0x1a000000, 0x1000000, &pdata);
  301. break;
  302. }
  303. }
  304. static void __init rbtx4938_arch_init(void)
  305. {
  306. gpiochip_add(&rbtx4938_spi_gpio_chip);
  307. rbtx4938_pci_setup();
  308. rbtx4938_spi_init();
  309. }
  310. static void __init rbtx4938_device_init(void)
  311. {
  312. rbtx4938_ethaddr_init();
  313. rbtx4938_ne_init();
  314. tx4938_wdt_init();
  315. rbtx4938_mtd_init();
  316. txx9_iocled_init(RBTX4938_LED_ADDR - IO_BASE, -1, 8, 1, "green", NULL);
  317. }
  318. struct txx9_board_vec rbtx4938_vec __initdata = {
  319. .system = "Toshiba RBTX4938",
  320. .prom_init = rbtx4938_prom_init,
  321. .mem_setup = rbtx4938_mem_setup,
  322. .irq_setup = rbtx4938_irq_setup,
  323. .time_init = rbtx4938_time_init,
  324. .device_init = rbtx4938_device_init,
  325. .arch_init = rbtx4938_arch_init,
  326. #ifdef CONFIG_PCI
  327. .pci_map_irq = rbtx4938_pci_map_irq,
  328. #endif
  329. };