setup.c 8.9 KB

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