ppc83xx_setup.c 11 KB

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