ppc83xx_setup.c 11 KB

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