ppc83xx_setup.c 11 KB

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