setup.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. /*
  2. * This program is free software; you can redistribute it and/or modify it
  3. * under the terms of the GNU General Public License as published by the
  4. * Free Software Foundation; either version 2 of the License, or (at your
  5. * option) any later version.
  6. *
  7. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  8. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  9. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  10. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  11. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  12. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  13. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  14. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  15. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  16. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 675 Mass Ave, Cambridge, MA 02139, USA.
  21. *
  22. * Copyright 2001 MontaVista Software Inc.
  23. * Author: MontaVista Software, Inc.
  24. * ahennessy@mvista.com
  25. *
  26. * Copyright (C) 2000-2001 Toshiba Corporation
  27. * Copyright (C) 2007 Ralf Baechle (ralf@linux-mips.org)
  28. */
  29. #include <linux/clockchips.h>
  30. #include <linux/init.h>
  31. #include <linux/kernel.h>
  32. #include <linux/kdev_t.h>
  33. #include <linux/types.h>
  34. #include <linux/sched.h>
  35. #include <linux/pci.h>
  36. #include <linux/ide.h>
  37. #include <linux/irq.h>
  38. #include <linux/ioport.h>
  39. #include <linux/param.h> /* for HZ */
  40. #include <linux/delay.h>
  41. #include <linux/pm.h>
  42. #include <linux/platform_device.h>
  43. #ifdef CONFIG_SERIAL_TXX9
  44. #include <linux/tty.h>
  45. #include <linux/serial.h>
  46. #include <linux/serial_core.h>
  47. #endif
  48. #include <asm/addrspace.h>
  49. #include <asm/time.h>
  50. #include <asm/reboot.h>
  51. #include <asm/jmr3927/jmr3927.h>
  52. #include <asm/mipsregs.h>
  53. extern void puts(const char *cp);
  54. /* Tick Timer divider */
  55. #define JMR3927_TIMER_CCD 0 /* 1/2 */
  56. #define JMR3927_TIMER_CLK (JMR3927_IMCLK / (2 << JMR3927_TIMER_CCD))
  57. /* don't enable - see errata */
  58. static int jmr3927_ccfg_toeon;
  59. static inline void do_reset(void)
  60. {
  61. #if 1 /* Resetting PCI bus */
  62. jmr3927_ioc_reg_out(0, JMR3927_IOC_RESET_ADDR);
  63. jmr3927_ioc_reg_out(JMR3927_IOC_RESET_PCI, JMR3927_IOC_RESET_ADDR);
  64. (void)jmr3927_ioc_reg_in(JMR3927_IOC_RESET_ADDR); /* flush WB */
  65. mdelay(1);
  66. jmr3927_ioc_reg_out(0, JMR3927_IOC_RESET_ADDR);
  67. #endif
  68. jmr3927_ioc_reg_out(JMR3927_IOC_RESET_CPU, JMR3927_IOC_RESET_ADDR);
  69. }
  70. static void jmr3927_machine_restart(char *command)
  71. {
  72. local_irq_disable();
  73. puts("Rebooting...");
  74. do_reset();
  75. }
  76. static void jmr3927_machine_halt(void)
  77. {
  78. puts("JMR-TX3927 halted.\n");
  79. while (1);
  80. }
  81. static void jmr3927_machine_power_off(void)
  82. {
  83. puts("JMR-TX3927 halted. Please turn off the power.\n");
  84. while (1);
  85. }
  86. static cycle_t jmr3927_hpt_read(void)
  87. {
  88. /* We assume this function is called xtime_lock held. */
  89. return jiffies * (JMR3927_TIMER_CLK / HZ) + jmr3927_tmrptr->trr;
  90. }
  91. static void jmr3927_set_mode(enum clock_event_mode mode,
  92. struct clock_event_device *evt)
  93. {
  94. /* Nothing to do here */
  95. }
  96. struct clock_event_device jmr3927_clock_event_device = {
  97. .name = "MIPS",
  98. .features = CLOCK_EVT_FEAT_PERIODIC,
  99. .shift = 32,
  100. .rating = 300,
  101. .cpumask = CPU_MASK_CPU0,
  102. .irq = JMR3927_IRQ_TICK,
  103. .set_mode = jmr3927_set_mode,
  104. };
  105. static irqreturn_t jmr3927_timer_interrupt(int irq, void *dev_id)
  106. {
  107. struct clock_event_device *cd = &jmr3927_clock_event_device;
  108. jmr3927_tmrptr->tisr = 0; /* ack interrupt */
  109. cd->event_handler(cd);
  110. return IRQ_HANDLED;
  111. }
  112. static struct irqaction jmr3927_timer_irqaction = {
  113. .handler = jmr3927_timer_interrupt,
  114. .flags = IRQF_DISABLED | IRQF_PERCPU,
  115. .name = "jmr3927-timer",
  116. };
  117. void __init plat_time_init(void)
  118. {
  119. struct clock_event_device *cd;
  120. clocksource_mips.read = jmr3927_hpt_read;
  121. mips_hpt_frequency = JMR3927_TIMER_CLK;
  122. jmr3927_tmrptr->cpra = JMR3927_TIMER_CLK / HZ;
  123. jmr3927_tmrptr->itmr = TXx927_TMTITMR_TIIE | TXx927_TMTITMR_TZCE;
  124. jmr3927_tmrptr->ccdr = JMR3927_TIMER_CCD;
  125. jmr3927_tmrptr->tcr =
  126. TXx927_TMTCR_TCE | TXx927_TMTCR_CCDE | TXx927_TMTCR_TMODE_ITVL;
  127. cd = &jmr3927_clock_event_device;
  128. /* Calculate the min / max delta */
  129. cd->mult = div_sc((unsigned long) JMR3927_IMCLK, NSEC_PER_SEC, 32);
  130. cd->max_delta_ns = clockevent_delta2ns(0x7fffffff, cd);
  131. cd->min_delta_ns = clockevent_delta2ns(0x300, cd);
  132. clockevents_register_device(cd);
  133. setup_irq(JMR3927_IRQ_TICK, &jmr3927_timer_irqaction);
  134. }
  135. #define DO_WRITE_THROUGH
  136. #define DO_ENABLE_CACHE
  137. extern char * __init prom_getcmdline(void);
  138. static void jmr3927_board_init(void);
  139. extern struct resource pci_io_resource;
  140. extern struct resource pci_mem_resource;
  141. void __init plat_mem_setup(void)
  142. {
  143. char *argptr;
  144. set_io_port_base(JMR3927_PORT_BASE + JMR3927_PCIIO);
  145. _machine_restart = jmr3927_machine_restart;
  146. _machine_halt = jmr3927_machine_halt;
  147. pm_power_off = jmr3927_machine_power_off;
  148. /*
  149. * IO/MEM resources.
  150. */
  151. ioport_resource.start = pci_io_resource.start;
  152. ioport_resource.end = pci_io_resource.end;
  153. iomem_resource.start = 0;
  154. iomem_resource.end = 0xffffffff;
  155. /* Reboot on panic */
  156. panic_timeout = 180;
  157. /* cache setup */
  158. {
  159. unsigned int conf;
  160. #ifdef DO_ENABLE_CACHE
  161. int mips_ic_disable = 0, mips_dc_disable = 0;
  162. #else
  163. int mips_ic_disable = 1, mips_dc_disable = 1;
  164. #endif
  165. #ifdef DO_WRITE_THROUGH
  166. int mips_config_cwfon = 0;
  167. int mips_config_wbon = 0;
  168. #else
  169. int mips_config_cwfon = 1;
  170. int mips_config_wbon = 1;
  171. #endif
  172. conf = read_c0_conf();
  173. conf &= ~(TX39_CONF_ICE | TX39_CONF_DCE | TX39_CONF_WBON | TX39_CONF_CWFON);
  174. conf |= mips_ic_disable ? 0 : TX39_CONF_ICE;
  175. conf |= mips_dc_disable ? 0 : TX39_CONF_DCE;
  176. conf |= mips_config_wbon ? TX39_CONF_WBON : 0;
  177. conf |= mips_config_cwfon ? TX39_CONF_CWFON : 0;
  178. write_c0_conf(conf);
  179. write_c0_cache(0);
  180. }
  181. /* initialize board */
  182. jmr3927_board_init();
  183. argptr = prom_getcmdline();
  184. if ((argptr = strstr(argptr, "toeon")) != NULL)
  185. jmr3927_ccfg_toeon = 1;
  186. argptr = prom_getcmdline();
  187. if ((argptr = strstr(argptr, "ip=")) == NULL) {
  188. argptr = prom_getcmdline();
  189. strcat(argptr, " ip=bootp");
  190. }
  191. #ifdef CONFIG_SERIAL_TXX9
  192. {
  193. extern int early_serial_txx9_setup(struct uart_port *port);
  194. int i;
  195. struct uart_port req;
  196. for(i = 0; i < 2; i++) {
  197. memset(&req, 0, sizeof(req));
  198. req.line = i;
  199. req.iotype = UPIO_MEM;
  200. req.membase = (unsigned char __iomem *)TX3927_SIO_REG(i);
  201. req.mapbase = TX3927_SIO_REG(i);
  202. req.irq = i == 0 ?
  203. JMR3927_IRQ_IRC_SIO0 : JMR3927_IRQ_IRC_SIO1;
  204. if (i == 0)
  205. req.flags |= UPF_BUGGY_UART /*HAVE_CTS_LINE*/;
  206. req.uartclk = JMR3927_IMCLK;
  207. early_serial_txx9_setup(&req);
  208. }
  209. }
  210. #ifdef CONFIG_SERIAL_TXX9_CONSOLE
  211. argptr = prom_getcmdline();
  212. if ((argptr = strstr(argptr, "console=")) == NULL) {
  213. argptr = prom_getcmdline();
  214. strcat(argptr, " console=ttyS1,115200");
  215. }
  216. #endif
  217. #endif
  218. }
  219. static void tx3927_setup(void);
  220. static void __init jmr3927_board_init(void)
  221. {
  222. tx3927_setup();
  223. /* SIO0 DTR on */
  224. jmr3927_ioc_reg_out(0, JMR3927_IOC_DTR_ADDR);
  225. jmr3927_led_set(0);
  226. printk("JMR-TX3927 (Rev %d) --- IOC(Rev %d) DIPSW:%d,%d,%d,%d\n",
  227. jmr3927_ioc_reg_in(JMR3927_IOC_BREV_ADDR) & JMR3927_REV_MASK,
  228. jmr3927_ioc_reg_in(JMR3927_IOC_REV_ADDR) & JMR3927_REV_MASK,
  229. jmr3927_dipsw1(), jmr3927_dipsw2(),
  230. jmr3927_dipsw3(), jmr3927_dipsw4());
  231. }
  232. static void __init tx3927_setup(void)
  233. {
  234. int i;
  235. #ifdef CONFIG_PCI
  236. unsigned long mips_pci_io_base = JMR3927_PCIIO;
  237. unsigned long mips_pci_io_size = JMR3927_PCIIO_SIZE;
  238. unsigned long mips_pci_mem_base = JMR3927_PCIMEM;
  239. unsigned long mips_pci_mem_size = JMR3927_PCIMEM_SIZE;
  240. /* for legacy I/O, PCI I/O PCI Bus address must be 0 */
  241. unsigned long mips_pci_io_pciaddr = 0;
  242. #endif
  243. /* SDRAMC are configured by PROM */
  244. /* ROMC */
  245. tx3927_romcptr->cr[1] = JMR3927_ROMCE1 | 0x00030048;
  246. tx3927_romcptr->cr[2] = JMR3927_ROMCE2 | 0x000064c8;
  247. tx3927_romcptr->cr[3] = JMR3927_ROMCE3 | 0x0003f698;
  248. tx3927_romcptr->cr[5] = JMR3927_ROMCE5 | 0x0000f218;
  249. /* CCFG */
  250. /* enable Timeout BusError */
  251. if (jmr3927_ccfg_toeon)
  252. tx3927_ccfgptr->ccfg |= TX3927_CCFG_TOE;
  253. /* clear BusErrorOnWrite flag */
  254. tx3927_ccfgptr->ccfg &= ~TX3927_CCFG_BEOW;
  255. /* Disable PCI snoop */
  256. tx3927_ccfgptr->ccfg &= ~TX3927_CCFG_PSNP;
  257. #ifdef DO_WRITE_THROUGH
  258. /* Enable PCI SNOOP - with write through only */
  259. tx3927_ccfgptr->ccfg |= TX3927_CCFG_PSNP;
  260. #endif
  261. /* Pin selection */
  262. tx3927_ccfgptr->pcfg &= ~TX3927_PCFG_SELALL;
  263. tx3927_ccfgptr->pcfg |=
  264. TX3927_PCFG_SELSIOC(0) | TX3927_PCFG_SELSIO_ALL |
  265. (TX3927_PCFG_SELDMA_ALL & ~TX3927_PCFG_SELDMA(1));
  266. printk("TX3927 -- CRIR:%08lx CCFG:%08lx PCFG:%08lx\n",
  267. tx3927_ccfgptr->crir,
  268. tx3927_ccfgptr->ccfg, tx3927_ccfgptr->pcfg);
  269. /* TMR */
  270. /* disable all timers */
  271. for (i = 0; i < TX3927_NR_TMR; i++) {
  272. tx3927_tmrptr(i)->tcr = TXx927_TMTCR_CRE;
  273. tx3927_tmrptr(i)->tisr = 0;
  274. tx3927_tmrptr(i)->cpra = 0xffffffff;
  275. tx3927_tmrptr(i)->itmr = 0;
  276. tx3927_tmrptr(i)->ccdr = 0;
  277. tx3927_tmrptr(i)->pgmr = 0;
  278. }
  279. /* DMA */
  280. tx3927_dmaptr->mcr = 0;
  281. for (i = 0; i < ARRAY_SIZE(tx3927_dmaptr->ch); i++) {
  282. /* reset channel */
  283. tx3927_dmaptr->ch[i].ccr = TX3927_DMA_CCR_CHRST;
  284. tx3927_dmaptr->ch[i].ccr = 0;
  285. }
  286. /* enable DMA */
  287. #ifdef __BIG_ENDIAN
  288. tx3927_dmaptr->mcr = TX3927_DMA_MCR_MSTEN;
  289. #else
  290. tx3927_dmaptr->mcr = TX3927_DMA_MCR_MSTEN | TX3927_DMA_MCR_LE;
  291. #endif
  292. #ifdef CONFIG_PCI
  293. /* PCIC */
  294. printk("TX3927 PCIC -- DID:%04x VID:%04x RID:%02x Arbiter:",
  295. tx3927_pcicptr->did, tx3927_pcicptr->vid,
  296. tx3927_pcicptr->rid);
  297. if (!(tx3927_ccfgptr->ccfg & TX3927_CCFG_PCIXARB)) {
  298. printk("External\n");
  299. /* XXX */
  300. } else {
  301. printk("Internal\n");
  302. /* Reset PCI Bus */
  303. jmr3927_ioc_reg_out(0, JMR3927_IOC_RESET_ADDR);
  304. udelay(100);
  305. jmr3927_ioc_reg_out(JMR3927_IOC_RESET_PCI,
  306. JMR3927_IOC_RESET_ADDR);
  307. udelay(100);
  308. jmr3927_ioc_reg_out(0, JMR3927_IOC_RESET_ADDR);
  309. /* Disable External PCI Config. Access */
  310. tx3927_pcicptr->lbc = TX3927_PCIC_LBC_EPCAD;
  311. #ifdef __BIG_ENDIAN
  312. tx3927_pcicptr->lbc |= TX3927_PCIC_LBC_IBSE |
  313. TX3927_PCIC_LBC_TIBSE |
  314. TX3927_PCIC_LBC_TMFBSE | TX3927_PCIC_LBC_MSDSE;
  315. #endif
  316. /* LB->PCI mappings */
  317. tx3927_pcicptr->iomas = ~(mips_pci_io_size - 1);
  318. tx3927_pcicptr->ilbioma = mips_pci_io_base;
  319. tx3927_pcicptr->ipbioma = mips_pci_io_pciaddr;
  320. tx3927_pcicptr->mmas = ~(mips_pci_mem_size - 1);
  321. tx3927_pcicptr->ilbmma = mips_pci_mem_base;
  322. tx3927_pcicptr->ipbmma = mips_pci_mem_base;
  323. /* PCI->LB mappings */
  324. tx3927_pcicptr->iobas = 0xffffffff;
  325. tx3927_pcicptr->ioba = 0;
  326. tx3927_pcicptr->tlbioma = 0;
  327. tx3927_pcicptr->mbas = ~(mips_pci_mem_size - 1);
  328. tx3927_pcicptr->mba = 0;
  329. tx3927_pcicptr->tlbmma = 0;
  330. /* Enable Direct mapping Address Space Decoder */
  331. tx3927_pcicptr->lbc |= TX3927_PCIC_LBC_ILMDE | TX3927_PCIC_LBC_ILIDE;
  332. /* Clear All Local Bus Status */
  333. tx3927_pcicptr->lbstat = TX3927_PCIC_LBIM_ALL;
  334. /* Enable All Local Bus Interrupts */
  335. tx3927_pcicptr->lbim = TX3927_PCIC_LBIM_ALL;
  336. /* Clear All PCI Status Error */
  337. tx3927_pcicptr->pcistat = TX3927_PCIC_PCISTATIM_ALL;
  338. /* Enable All PCI Status Error Interrupts */
  339. tx3927_pcicptr->pcistatim = TX3927_PCIC_PCISTATIM_ALL;
  340. /* PCIC Int => IRC IRQ10 */
  341. tx3927_pcicptr->il = TX3927_IR_PCI;
  342. /* Target Control (per errata) */
  343. tx3927_pcicptr->tc = TX3927_PCIC_TC_OF8E | TX3927_PCIC_TC_IF8E;
  344. /* Enable Bus Arbiter */
  345. tx3927_pcicptr->pbapmc = TX3927_PCIC_PBAPMC_PBAEN;
  346. tx3927_pcicptr->pcicmd = PCI_COMMAND_MASTER |
  347. PCI_COMMAND_MEMORY |
  348. PCI_COMMAND_IO |
  349. PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
  350. }
  351. #endif /* CONFIG_PCI */
  352. /* PIO */
  353. /* PIO[15:12] connected to LEDs */
  354. tx3927_pioptr->dir = 0x0000f000;
  355. tx3927_pioptr->maskcpu = 0;
  356. tx3927_pioptr->maskext = 0;
  357. {
  358. unsigned int conf;
  359. conf = read_c0_conf();
  360. if (!(conf & TX39_CONF_ICE))
  361. printk("TX3927 I-Cache disabled.\n");
  362. if (!(conf & TX39_CONF_DCE))
  363. printk("TX3927 D-Cache disabled.\n");
  364. else if (!(conf & TX39_CONF_WBON))
  365. printk("TX3927 D-Cache WriteThrough.\n");
  366. else if (!(conf & TX39_CONF_CWFON))
  367. printk("TX3927 D-Cache WriteBack.\n");
  368. else
  369. printk("TX3927 D-Cache WriteBack (CWF) .\n");
  370. }
  371. }
  372. /* This trick makes rtc-ds1742 driver usable as is. */
  373. unsigned long __swizzle_addr_b(unsigned long port)
  374. {
  375. if ((port & 0xffff0000) != JMR3927_IOC_NVRAMB_ADDR)
  376. return port;
  377. port = (port & 0xffff0000) | (port & 0x7fff << 1);
  378. #ifdef __BIG_ENDIAN
  379. return port;
  380. #else
  381. return port | 1;
  382. #endif
  383. }
  384. EXPORT_SYMBOL(__swizzle_addr_b);
  385. static int __init jmr3927_rtc_init(void)
  386. {
  387. static struct resource __initdata res = {
  388. .start = JMR3927_IOC_NVRAMB_ADDR - IO_BASE,
  389. .end = JMR3927_IOC_NVRAMB_ADDR - IO_BASE + 0x800 - 1,
  390. .flags = IORESOURCE_MEM,
  391. };
  392. struct platform_device *dev;
  393. dev = platform_device_register_simple("rtc-ds1742", -1, &res, 1);
  394. return IS_ERR(dev) ? PTR_ERR(dev) : 0;
  395. }
  396. device_initcall(jmr3927_rtc_init);