setup.c 9.2 KB

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