ppc83xx_setup.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. /*
  2. * MPC83XX common board code
  3. *
  4. * Maintainer: Kumar Gala <galak@kernel.crashing.org>
  5. *
  6. * Copyright 2005 Freescale Semiconductor Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  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. * Added PCI support -- Tony Li <tony.li@freescale.com>
  23. */
  24. #include <linux/types.h>
  25. #include <linux/module.h>
  26. #include <linux/init.h>
  27. #include <linux/pci.h>
  28. #include <linux/serial.h>
  29. #include <linux/tty.h> /* for linux/serial_core.h */
  30. #include <linux/serial_core.h>
  31. #include <linux/serial_8250.h>
  32. #include <asm/time.h>
  33. #include <asm/mpc83xx.h>
  34. #include <asm/mmu.h>
  35. #include <asm/ppc_sys.h>
  36. #include <asm/kgdb.h>
  37. #include <asm/delay.h>
  38. #include <asm/machdep.h>
  39. #include <syslib/ppc83xx_setup.h>
  40. #if defined(CONFIG_PCI)
  41. #include <asm/delay.h>
  42. #include <syslib/ppc83xx_pci.h>
  43. #endif
  44. phys_addr_t immrbar;
  45. /* Return the amount of memory */
  46. unsigned long __init
  47. mpc83xx_find_end_of_memory(void)
  48. {
  49. bd_t *binfo;
  50. binfo = (bd_t *) __res;
  51. return binfo->bi_memsize;
  52. }
  53. long __init
  54. mpc83xx_time_init(void)
  55. {
  56. #define SPCR_OFFS 0x00000110
  57. #define SPCR_TBEN 0x00400000
  58. bd_t *binfo = (bd_t *)__res;
  59. u32 *spcr = ioremap(binfo->bi_immr_base + SPCR_OFFS, 4);
  60. *spcr |= SPCR_TBEN;
  61. iounmap(spcr);
  62. return 0;
  63. }
  64. /* The decrementer counts at the system (internal) clock freq divided by 4 */
  65. void __init
  66. mpc83xx_calibrate_decr(void)
  67. {
  68. bd_t *binfo = (bd_t *) __res;
  69. unsigned int freq, divisor;
  70. freq = binfo->bi_busfreq;
  71. divisor = 4;
  72. tb_ticks_per_jiffy = freq / HZ / divisor;
  73. tb_to_us = mulhwu_scale_factor(freq / divisor, 1000000);
  74. }
  75. #ifdef CONFIG_SERIAL_8250
  76. void __init
  77. mpc83xx_early_serial_map(void)
  78. {
  79. #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
  80. struct uart_port serial_req;
  81. #endif
  82. struct plat_serial8250_port *pdata;
  83. bd_t *binfo = (bd_t *) __res;
  84. pdata = (struct plat_serial8250_port *) ppc_sys_get_pdata(MPC83xx_DUART);
  85. /* Setup serial port access */
  86. pdata[0].uartclk = binfo->bi_busfreq;
  87. pdata[0].mapbase += binfo->bi_immr_base;
  88. pdata[0].membase = ioremap(pdata[0].mapbase, 0x100);
  89. #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
  90. memset(&serial_req, 0, sizeof (serial_req));
  91. serial_req.iotype = UPIO_MEM;
  92. serial_req.mapbase = pdata[0].mapbase;
  93. serial_req.membase = pdata[0].membase;
  94. serial_req.regshift = 0;
  95. gen550_init(0, &serial_req);
  96. #endif
  97. pdata[1].uartclk = binfo->bi_busfreq;
  98. pdata[1].mapbase += binfo->bi_immr_base;
  99. pdata[1].membase = ioremap(pdata[1].mapbase, 0x100);
  100. #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
  101. /* Assume gen550_init() doesn't modify serial_req */
  102. serial_req.mapbase = pdata[1].mapbase;
  103. serial_req.membase = pdata[1].membase;
  104. gen550_init(1, &serial_req);
  105. #endif
  106. }
  107. #endif
  108. void
  109. mpc83xx_restart(char *cmd)
  110. {
  111. volatile unsigned char __iomem *reg;
  112. unsigned char tmp;
  113. reg = ioremap(BCSR_PHYS_ADDR, BCSR_SIZE);
  114. local_irq_disable();
  115. /*
  116. * Unlock the BCSR bits so a PRST will update the contents.
  117. * Otherwise the reset asserts but doesn't clear.
  118. */
  119. tmp = in_8(reg + BCSR_MISC_REG3_OFF);
  120. tmp |= BCSR_MISC_REG3_CNFLOCK; /* low true, high false */
  121. out_8(reg + BCSR_MISC_REG3_OFF, tmp);
  122. /*
  123. * Trigger a reset via a low->high transition of the
  124. * PORESET bit.
  125. */
  126. tmp = in_8(reg + BCSR_MISC_REG2_OFF);
  127. tmp &= ~BCSR_MISC_REG2_PORESET;
  128. out_8(reg + BCSR_MISC_REG2_OFF, tmp);
  129. udelay(1);
  130. tmp |= BCSR_MISC_REG2_PORESET;
  131. out_8(reg + BCSR_MISC_REG2_OFF, tmp);
  132. for(;;);
  133. }
  134. void
  135. mpc83xx_power_off(void)
  136. {
  137. local_irq_disable();
  138. for(;;);
  139. }
  140. void
  141. mpc83xx_halt(void)
  142. {
  143. local_irq_disable();
  144. for(;;);
  145. }
  146. #if defined(CONFIG_PCI)
  147. void __init
  148. mpc83xx_setup_pci1(struct pci_controller *hose)
  149. {
  150. u16 reg16;
  151. volatile immr_pcictrl_t * pci_ctrl;
  152. volatile immr_ios_t * ios;
  153. bd_t *binfo = (bd_t *) __res;
  154. pci_ctrl = ioremap(binfo->bi_immr_base + 0x8500, sizeof(immr_pcictrl_t));
  155. ios = ioremap(binfo->bi_immr_base + 0x8400, sizeof(immr_ios_t));
  156. /*
  157. * Configure PCI Outbound Translation Windows
  158. */
  159. ios->potar0 = (MPC83xx_PCI1_LOWER_MEM >> 12) & POTAR_TA_MASK;
  160. ios->pobar0 = (MPC83xx_PCI1_LOWER_MEM >> 12) & POBAR_BA_MASK;
  161. ios->pocmr0 = POCMR_EN |
  162. (((0xffffffff - (MPC83xx_PCI1_UPPER_MEM -
  163. MPC83xx_PCI1_LOWER_MEM)) >> 12) & POCMR_CM_MASK);
  164. /* mapped to PCI1 IO space */
  165. ios->potar1 = (MPC83xx_PCI1_LOWER_IO >> 12) & POTAR_TA_MASK;
  166. ios->pobar1 = (MPC83xx_PCI1_IO_BASE >> 12) & POBAR_BA_MASK;
  167. ios->pocmr1 = POCMR_EN | POCMR_IO |
  168. (((0xffffffff - (MPC83xx_PCI1_UPPER_IO -
  169. MPC83xx_PCI1_LOWER_IO)) >> 12) & POCMR_CM_MASK);
  170. /*
  171. * Configure PCI Inbound Translation Windows
  172. */
  173. pci_ctrl->pitar1 = 0x0;
  174. pci_ctrl->pibar1 = 0x0;
  175. pci_ctrl->piebar1 = 0x0;
  176. pci_ctrl->piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP | PIWAR_WTT_SNOOP | PIWAR_IWS_2G;
  177. /*
  178. * Release PCI RST signal
  179. */
  180. pci_ctrl->gcr = 0;
  181. udelay(2000);
  182. pci_ctrl->gcr = 1;
  183. udelay(2000);
  184. reg16 = 0xff;
  185. early_read_config_word(hose, hose->first_busno, 0, PCI_COMMAND, &reg16);
  186. reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  187. early_write_config_word(hose, hose->first_busno, 0, PCI_COMMAND, reg16);
  188. /*
  189. * Clear non-reserved bits in status register.
  190. */
  191. early_write_config_word(hose, hose->first_busno, 0, PCI_STATUS, 0xffff);
  192. early_write_config_byte(hose, hose->first_busno, 0, PCI_LATENCY_TIMER, 0x80);
  193. iounmap(pci_ctrl);
  194. iounmap(ios);
  195. }
  196. void __init
  197. mpc83xx_setup_pci2(struct pci_controller *hose)
  198. {
  199. u16 reg16;
  200. volatile immr_pcictrl_t * pci_ctrl;
  201. volatile immr_ios_t * ios;
  202. bd_t *binfo = (bd_t *) __res;
  203. pci_ctrl = ioremap(binfo->bi_immr_base + 0x8600, sizeof(immr_pcictrl_t));
  204. ios = ioremap(binfo->bi_immr_base + 0x8400, sizeof(immr_ios_t));
  205. /*
  206. * Configure PCI Outbound Translation Windows
  207. */
  208. ios->potar3 = (MPC83xx_PCI2_LOWER_MEM >> 12) & POTAR_TA_MASK;
  209. ios->pobar3 = (MPC83xx_PCI2_LOWER_MEM >> 12) & POBAR_BA_MASK;
  210. ios->pocmr3 = POCMR_EN | POCMR_DST |
  211. (((0xffffffff - (MPC83xx_PCI2_UPPER_MEM -
  212. MPC83xx_PCI2_LOWER_MEM)) >> 12) & POCMR_CM_MASK);
  213. /* mapped to PCI2 IO space */
  214. ios->potar4 = (MPC83xx_PCI2_LOWER_IO >> 12) & POTAR_TA_MASK;
  215. ios->pobar4 = (MPC83xx_PCI2_IO_BASE >> 12) & POBAR_BA_MASK;
  216. ios->pocmr4 = POCMR_EN | POCMR_DST | POCMR_IO |
  217. (((0xffffffff - (MPC83xx_PCI2_UPPER_IO -
  218. MPC83xx_PCI2_LOWER_IO)) >> 12) & POCMR_CM_MASK);
  219. /*
  220. * Configure PCI Inbound Translation Windows
  221. */
  222. pci_ctrl->pitar1 = 0x0;
  223. pci_ctrl->pibar1 = 0x0;
  224. pci_ctrl->piebar1 = 0x0;
  225. pci_ctrl->piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP | PIWAR_WTT_SNOOP | PIWAR_IWS_2G;
  226. /*
  227. * Release PCI RST signal
  228. */
  229. pci_ctrl->gcr = 0;
  230. udelay(2000);
  231. pci_ctrl->gcr = 1;
  232. udelay(2000);
  233. reg16 = 0xff;
  234. early_read_config_word(hose, hose->first_busno, 0, PCI_COMMAND, &reg16);
  235. reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  236. early_write_config_word(hose, hose->first_busno, 0, PCI_COMMAND, reg16);
  237. /*
  238. * Clear non-reserved bits in status register.
  239. */
  240. early_write_config_word(hose, hose->first_busno, 0, PCI_STATUS, 0xffff);
  241. early_write_config_byte(hose, hose->first_busno, 0, PCI_LATENCY_TIMER, 0x80);
  242. iounmap(pci_ctrl);
  243. iounmap(ios);
  244. }
  245. /*
  246. * PCI buses can be enabled only if SYS board combinates with PIB
  247. * (Platform IO Board) board which provide 3 PCI slots. There is 2 PCI buses
  248. * and 3 PCI slots, so people must configure the routes between them before
  249. * enable PCI bus. This routes are under the control of PCA9555PW device which
  250. * can be accessed via I2C bus 2 and are configured by firmware. Refer to
  251. * Freescale to get more information about firmware configuration.
  252. */
  253. extern int mpc83xx_exclude_device(u_char bus, u_char devfn);
  254. extern int mpc83xx_map_irq(struct pci_dev *dev, unsigned char idsel,
  255. unsigned char pin);
  256. void __init
  257. mpc83xx_setup_hose(void)
  258. {
  259. u32 val32;
  260. volatile immr_clk_t * clk;
  261. struct pci_controller * hose1;
  262. #ifdef CONFIG_MPC83xx_PCI2
  263. struct pci_controller * hose2;
  264. #endif
  265. bd_t * binfo = (bd_t *)__res;
  266. clk = ioremap(binfo->bi_immr_base + 0xA00,
  267. sizeof(immr_clk_t));
  268. /*
  269. * Configure PCI controller and PCI_CLK_OUTPUT both in 66M mode
  270. */
  271. val32 = clk->occr;
  272. udelay(2000);
  273. clk->occr = 0xff000000;
  274. udelay(2000);
  275. iounmap(clk);
  276. hose1 = pcibios_alloc_controller();
  277. if(!hose1)
  278. return;
  279. ppc_md.pci_swizzle = common_swizzle;
  280. ppc_md.pci_map_irq = mpc83xx_map_irq;
  281. hose1->bus_offset = 0;
  282. hose1->first_busno = 0;
  283. hose1->last_busno = 0xff;
  284. setup_indirect_pci(hose1, binfo->bi_immr_base + PCI1_CFG_ADDR_OFFSET,
  285. binfo->bi_immr_base + PCI1_CFG_DATA_OFFSET);
  286. hose1->set_cfg_type = 1;
  287. mpc83xx_setup_pci1(hose1);
  288. hose1->pci_mem_offset = MPC83xx_PCI1_MEM_OFFSET;
  289. hose1->mem_space.start = MPC83xx_PCI1_LOWER_MEM;
  290. hose1->mem_space.end = MPC83xx_PCI1_UPPER_MEM;
  291. hose1->io_base_phys = MPC83xx_PCI1_IO_BASE;
  292. hose1->io_space.start = MPC83xx_PCI1_LOWER_IO;
  293. hose1->io_space.end = MPC83xx_PCI1_UPPER_IO;
  294. #ifdef CONFIG_MPC83xx_PCI2
  295. isa_io_base = (unsigned long)ioremap(MPC83xx_PCI1_IO_BASE,
  296. MPC83xx_PCI1_IO_SIZE + MPC83xx_PCI2_IO_SIZE);
  297. #else
  298. isa_io_base = (unsigned long)ioremap(MPC83xx_PCI1_IO_BASE,
  299. MPC83xx_PCI1_IO_SIZE);
  300. #endif /* CONFIG_MPC83xx_PCI2 */
  301. hose1->io_base_virt = (void *)isa_io_base;
  302. /* setup resources */
  303. pci_init_resource(&hose1->io_resource,
  304. MPC83xx_PCI1_LOWER_IO,
  305. MPC83xx_PCI1_UPPER_IO,
  306. IORESOURCE_IO, "PCI host bridge 1");
  307. pci_init_resource(&hose1->mem_resources[0],
  308. MPC83xx_PCI1_LOWER_MEM,
  309. MPC83xx_PCI1_UPPER_MEM,
  310. IORESOURCE_MEM, "PCI host bridge 1");
  311. ppc_md.pci_exclude_device = mpc83xx_exclude_device;
  312. hose1->last_busno = pciauto_bus_scan(hose1, hose1->first_busno);
  313. #ifdef CONFIG_MPC83xx_PCI2
  314. hose2 = pcibios_alloc_controller();
  315. if(!hose2)
  316. return;
  317. hose2->bus_offset = hose1->last_busno + 1;
  318. hose2->first_busno = hose1->last_busno + 1;
  319. hose2->last_busno = 0xff;
  320. setup_indirect_pci(hose2, binfo->bi_immr_base + PCI2_CFG_ADDR_OFFSET,
  321. binfo->bi_immr_base + PCI2_CFG_DATA_OFFSET);
  322. hose2->set_cfg_type = 1;
  323. mpc83xx_setup_pci2(hose2);
  324. hose2->pci_mem_offset = MPC83xx_PCI2_MEM_OFFSET;
  325. hose2->mem_space.start = MPC83xx_PCI2_LOWER_MEM;
  326. hose2->mem_space.end = MPC83xx_PCI2_UPPER_MEM;
  327. hose2->io_base_phys = MPC83xx_PCI2_IO_BASE;
  328. hose2->io_space.start = MPC83xx_PCI2_LOWER_IO;
  329. hose2->io_space.end = MPC83xx_PCI2_UPPER_IO;
  330. hose2->io_base_virt = (void *)(isa_io_base + MPC83xx_PCI1_IO_SIZE);
  331. /* setup resources */
  332. pci_init_resource(&hose2->io_resource,
  333. MPC83xx_PCI2_LOWER_IO,
  334. MPC83xx_PCI2_UPPER_IO,
  335. IORESOURCE_IO, "PCI host bridge 2");
  336. pci_init_resource(&hose2->mem_resources[0],
  337. MPC83xx_PCI2_LOWER_MEM,
  338. MPC83xx_PCI2_UPPER_MEM,
  339. IORESOURCE_MEM, "PCI host bridge 2");
  340. hose2->last_busno = pciauto_bus_scan(hose2, hose2->first_busno);
  341. #endif /* CONFIG_MPC83xx_PCI2 */
  342. }
  343. #endif /*CONFIG_PCI*/