pcie-designware.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. /*
  2. * Synopsys Designware PCIe host controller driver
  3. *
  4. * Copyright (C) 2013 Samsung Electronics Co., Ltd.
  5. * http://www.samsung.com
  6. *
  7. * Author: Jingoo Han <jg1.han@samsung.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/of_address.h>
  16. #include <linux/pci.h>
  17. #include <linux/pci_regs.h>
  18. #include <linux/types.h>
  19. #include "pcie-designware.h"
  20. /* Synopsis specific PCIE configuration registers */
  21. #define PCIE_PORT_LINK_CONTROL 0x710
  22. #define PORT_LINK_MODE_MASK (0x3f << 16)
  23. #define PORT_LINK_MODE_1_LANES (0x1 << 16)
  24. #define PORT_LINK_MODE_2_LANES (0x3 << 16)
  25. #define PORT_LINK_MODE_4_LANES (0x7 << 16)
  26. #define PCIE_LINK_WIDTH_SPEED_CONTROL 0x80C
  27. #define PORT_LOGIC_SPEED_CHANGE (0x1 << 17)
  28. #define PORT_LOGIC_LINK_WIDTH_MASK (0x1ff << 8)
  29. #define PORT_LOGIC_LINK_WIDTH_1_LANES (0x1 << 8)
  30. #define PORT_LOGIC_LINK_WIDTH_2_LANES (0x2 << 8)
  31. #define PORT_LOGIC_LINK_WIDTH_4_LANES (0x4 << 8)
  32. #define PCIE_MSI_ADDR_LO 0x820
  33. #define PCIE_MSI_ADDR_HI 0x824
  34. #define PCIE_MSI_INTR0_ENABLE 0x828
  35. #define PCIE_MSI_INTR0_MASK 0x82C
  36. #define PCIE_MSI_INTR0_STATUS 0x830
  37. #define PCIE_ATU_VIEWPORT 0x900
  38. #define PCIE_ATU_REGION_INBOUND (0x1 << 31)
  39. #define PCIE_ATU_REGION_OUTBOUND (0x0 << 31)
  40. #define PCIE_ATU_REGION_INDEX1 (0x1 << 0)
  41. #define PCIE_ATU_REGION_INDEX0 (0x0 << 0)
  42. #define PCIE_ATU_CR1 0x904
  43. #define PCIE_ATU_TYPE_MEM (0x0 << 0)
  44. #define PCIE_ATU_TYPE_IO (0x2 << 0)
  45. #define PCIE_ATU_TYPE_CFG0 (0x4 << 0)
  46. #define PCIE_ATU_TYPE_CFG1 (0x5 << 0)
  47. #define PCIE_ATU_CR2 0x908
  48. #define PCIE_ATU_ENABLE (0x1 << 31)
  49. #define PCIE_ATU_BAR_MODE_ENABLE (0x1 << 30)
  50. #define PCIE_ATU_LOWER_BASE 0x90C
  51. #define PCIE_ATU_UPPER_BASE 0x910
  52. #define PCIE_ATU_LIMIT 0x914
  53. #define PCIE_ATU_LOWER_TARGET 0x918
  54. #define PCIE_ATU_BUS(x) (((x) & 0xff) << 24)
  55. #define PCIE_ATU_DEV(x) (((x) & 0x1f) << 19)
  56. #define PCIE_ATU_FUNC(x) (((x) & 0x7) << 16)
  57. #define PCIE_ATU_UPPER_TARGET 0x91C
  58. static struct hw_pci dw_pci;
  59. unsigned long global_io_offset;
  60. static inline struct pcie_port *sys_to_pcie(struct pci_sys_data *sys)
  61. {
  62. return sys->private_data;
  63. }
  64. int cfg_read(void __iomem *addr, int where, int size, u32 *val)
  65. {
  66. *val = readl(addr);
  67. if (size == 1)
  68. *val = (*val >> (8 * (where & 3))) & 0xff;
  69. else if (size == 2)
  70. *val = (*val >> (8 * (where & 3))) & 0xffff;
  71. else if (size != 4)
  72. return PCIBIOS_BAD_REGISTER_NUMBER;
  73. return PCIBIOS_SUCCESSFUL;
  74. }
  75. int cfg_write(void __iomem *addr, int where, int size, u32 val)
  76. {
  77. if (size == 4)
  78. writel(val, addr);
  79. else if (size == 2)
  80. writew(val, addr + (where & 2));
  81. else if (size == 1)
  82. writeb(val, addr + (where & 3));
  83. else
  84. return PCIBIOS_BAD_REGISTER_NUMBER;
  85. return PCIBIOS_SUCCESSFUL;
  86. }
  87. static inline void dw_pcie_readl_rc(struct pcie_port *pp, u32 reg, u32 *val)
  88. {
  89. if (pp->ops->readl_rc)
  90. pp->ops->readl_rc(pp, pp->dbi_base + reg, val);
  91. else
  92. *val = readl(pp->dbi_base + reg);
  93. }
  94. static inline void dw_pcie_writel_rc(struct pcie_port *pp, u32 val, u32 reg)
  95. {
  96. if (pp->ops->writel_rc)
  97. pp->ops->writel_rc(pp, val, pp->dbi_base + reg);
  98. else
  99. writel(val, pp->dbi_base + reg);
  100. }
  101. int dw_pcie_rd_own_conf(struct pcie_port *pp, int where, int size,
  102. u32 *val)
  103. {
  104. int ret;
  105. if (pp->ops->rd_own_conf)
  106. ret = pp->ops->rd_own_conf(pp, where, size, val);
  107. else
  108. ret = cfg_read(pp->dbi_base + (where & ~0x3), where, size, val);
  109. return ret;
  110. }
  111. int dw_pcie_wr_own_conf(struct pcie_port *pp, int where, int size,
  112. u32 val)
  113. {
  114. int ret;
  115. if (pp->ops->wr_own_conf)
  116. ret = pp->ops->wr_own_conf(pp, where, size, val);
  117. else
  118. ret = cfg_write(pp->dbi_base + (where & ~0x3), where, size,
  119. val);
  120. return ret;
  121. }
  122. int dw_pcie_link_up(struct pcie_port *pp)
  123. {
  124. if (pp->ops->link_up)
  125. return pp->ops->link_up(pp);
  126. else
  127. return 0;
  128. }
  129. int __init dw_pcie_host_init(struct pcie_port *pp)
  130. {
  131. struct device_node *np = pp->dev->of_node;
  132. struct of_pci_range range;
  133. struct of_pci_range_parser parser;
  134. u32 val;
  135. if (of_pci_range_parser_init(&parser, np)) {
  136. dev_err(pp->dev, "missing ranges property\n");
  137. return -EINVAL;
  138. }
  139. /* Get the I/O and memory ranges from DT */
  140. for_each_of_pci_range(&parser, &range) {
  141. unsigned long restype = range.flags & IORESOURCE_TYPE_BITS;
  142. if (restype == IORESOURCE_IO) {
  143. of_pci_range_to_resource(&range, np, &pp->io);
  144. pp->io.name = "I/O";
  145. pp->io.start = max_t(resource_size_t,
  146. PCIBIOS_MIN_IO,
  147. range.pci_addr + global_io_offset);
  148. pp->io.end = min_t(resource_size_t,
  149. IO_SPACE_LIMIT,
  150. range.pci_addr + range.size
  151. + global_io_offset);
  152. pp->config.io_size = resource_size(&pp->io);
  153. pp->config.io_bus_addr = range.pci_addr;
  154. }
  155. if (restype == IORESOURCE_MEM) {
  156. of_pci_range_to_resource(&range, np, &pp->mem);
  157. pp->mem.name = "MEM";
  158. pp->config.mem_size = resource_size(&pp->mem);
  159. pp->config.mem_bus_addr = range.pci_addr;
  160. }
  161. if (restype == 0) {
  162. of_pci_range_to_resource(&range, np, &pp->cfg);
  163. pp->config.cfg0_size = resource_size(&pp->cfg)/2;
  164. pp->config.cfg1_size = resource_size(&pp->cfg)/2;
  165. }
  166. }
  167. if (!pp->dbi_base) {
  168. pp->dbi_base = devm_ioremap(pp->dev, pp->cfg.start,
  169. resource_size(&pp->cfg));
  170. if (!pp->dbi_base) {
  171. dev_err(pp->dev, "error with ioremap\n");
  172. return -ENOMEM;
  173. }
  174. }
  175. pp->cfg0_base = pp->cfg.start;
  176. pp->cfg1_base = pp->cfg.start + pp->config.cfg0_size;
  177. pp->io_base = pp->io.start;
  178. pp->mem_base = pp->mem.start;
  179. pp->va_cfg0_base = devm_ioremap(pp->dev, pp->cfg0_base,
  180. pp->config.cfg0_size);
  181. if (!pp->va_cfg0_base) {
  182. dev_err(pp->dev, "error with ioremap in function\n");
  183. return -ENOMEM;
  184. }
  185. pp->va_cfg1_base = devm_ioremap(pp->dev, pp->cfg1_base,
  186. pp->config.cfg1_size);
  187. if (!pp->va_cfg1_base) {
  188. dev_err(pp->dev, "error with ioremap\n");
  189. return -ENOMEM;
  190. }
  191. if (of_property_read_u32(np, "num-lanes", &pp->lanes)) {
  192. dev_err(pp->dev, "Failed to parse the number of lanes\n");
  193. return -EINVAL;
  194. }
  195. if (pp->ops->host_init)
  196. pp->ops->host_init(pp);
  197. dw_pcie_wr_own_conf(pp, PCI_BASE_ADDRESS_0, 4, 0);
  198. /* program correct class for RC */
  199. dw_pcie_wr_own_conf(pp, PCI_CLASS_DEVICE, 2, PCI_CLASS_BRIDGE_PCI);
  200. dw_pcie_rd_own_conf(pp, PCIE_LINK_WIDTH_SPEED_CONTROL, 4, &val);
  201. val |= PORT_LOGIC_SPEED_CHANGE;
  202. dw_pcie_wr_own_conf(pp, PCIE_LINK_WIDTH_SPEED_CONTROL, 4, val);
  203. dw_pci.nr_controllers = 1;
  204. dw_pci.private_data = (void **)&pp;
  205. pci_common_init(&dw_pci);
  206. pci_assign_unassigned_resources();
  207. #ifdef CONFIG_PCI_DOMAINS
  208. dw_pci.domain++;
  209. #endif
  210. return 0;
  211. }
  212. static void dw_pcie_prog_viewport_cfg0(struct pcie_port *pp, u32 busdev)
  213. {
  214. /* Program viewport 0 : OUTBOUND : CFG0 */
  215. dw_pcie_writel_rc(pp, PCIE_ATU_REGION_OUTBOUND | PCIE_ATU_REGION_INDEX0,
  216. PCIE_ATU_VIEWPORT);
  217. dw_pcie_writel_rc(pp, pp->cfg0_base, PCIE_ATU_LOWER_BASE);
  218. dw_pcie_writel_rc(pp, (pp->cfg0_base >> 32), PCIE_ATU_UPPER_BASE);
  219. dw_pcie_writel_rc(pp, pp->cfg0_base + pp->config.cfg0_size - 1,
  220. PCIE_ATU_LIMIT);
  221. dw_pcie_writel_rc(pp, busdev, PCIE_ATU_LOWER_TARGET);
  222. dw_pcie_writel_rc(pp, 0, PCIE_ATU_UPPER_TARGET);
  223. dw_pcie_writel_rc(pp, PCIE_ATU_TYPE_CFG0, PCIE_ATU_CR1);
  224. dw_pcie_writel_rc(pp, PCIE_ATU_ENABLE, PCIE_ATU_CR2);
  225. }
  226. static void dw_pcie_prog_viewport_cfg1(struct pcie_port *pp, u32 busdev)
  227. {
  228. /* Program viewport 1 : OUTBOUND : CFG1 */
  229. dw_pcie_writel_rc(pp, PCIE_ATU_REGION_OUTBOUND | PCIE_ATU_REGION_INDEX1,
  230. PCIE_ATU_VIEWPORT);
  231. dw_pcie_writel_rc(pp, PCIE_ATU_TYPE_CFG1, PCIE_ATU_CR1);
  232. dw_pcie_writel_rc(pp, PCIE_ATU_ENABLE, PCIE_ATU_CR2);
  233. dw_pcie_writel_rc(pp, pp->cfg1_base, PCIE_ATU_LOWER_BASE);
  234. dw_pcie_writel_rc(pp, (pp->cfg1_base >> 32), PCIE_ATU_UPPER_BASE);
  235. dw_pcie_writel_rc(pp, pp->cfg1_base + pp->config.cfg1_size - 1,
  236. PCIE_ATU_LIMIT);
  237. dw_pcie_writel_rc(pp, busdev, PCIE_ATU_LOWER_TARGET);
  238. dw_pcie_writel_rc(pp, 0, PCIE_ATU_UPPER_TARGET);
  239. }
  240. static void dw_pcie_prog_viewport_mem_outbound(struct pcie_port *pp)
  241. {
  242. /* Program viewport 0 : OUTBOUND : MEM */
  243. dw_pcie_writel_rc(pp, PCIE_ATU_REGION_OUTBOUND | PCIE_ATU_REGION_INDEX0,
  244. PCIE_ATU_VIEWPORT);
  245. dw_pcie_writel_rc(pp, PCIE_ATU_TYPE_MEM, PCIE_ATU_CR1);
  246. dw_pcie_writel_rc(pp, PCIE_ATU_ENABLE, PCIE_ATU_CR2);
  247. dw_pcie_writel_rc(pp, pp->mem_base, PCIE_ATU_LOWER_BASE);
  248. dw_pcie_writel_rc(pp, (pp->mem_base >> 32), PCIE_ATU_UPPER_BASE);
  249. dw_pcie_writel_rc(pp, pp->mem_base + pp->config.mem_size - 1,
  250. PCIE_ATU_LIMIT);
  251. dw_pcie_writel_rc(pp, pp->config.mem_bus_addr, PCIE_ATU_LOWER_TARGET);
  252. dw_pcie_writel_rc(pp, upper_32_bits(pp->config.mem_bus_addr),
  253. PCIE_ATU_UPPER_TARGET);
  254. }
  255. static void dw_pcie_prog_viewport_io_outbound(struct pcie_port *pp)
  256. {
  257. /* Program viewport 1 : OUTBOUND : IO */
  258. dw_pcie_writel_rc(pp, PCIE_ATU_REGION_OUTBOUND | PCIE_ATU_REGION_INDEX1,
  259. PCIE_ATU_VIEWPORT);
  260. dw_pcie_writel_rc(pp, PCIE_ATU_TYPE_IO, PCIE_ATU_CR1);
  261. dw_pcie_writel_rc(pp, PCIE_ATU_ENABLE, PCIE_ATU_CR2);
  262. dw_pcie_writel_rc(pp, pp->io_base, PCIE_ATU_LOWER_BASE);
  263. dw_pcie_writel_rc(pp, (pp->io_base >> 32), PCIE_ATU_UPPER_BASE);
  264. dw_pcie_writel_rc(pp, pp->io_base + pp->config.io_size - 1,
  265. PCIE_ATU_LIMIT);
  266. dw_pcie_writel_rc(pp, pp->config.io_bus_addr, PCIE_ATU_LOWER_TARGET);
  267. dw_pcie_writel_rc(pp, upper_32_bits(pp->config.io_bus_addr),
  268. PCIE_ATU_UPPER_TARGET);
  269. }
  270. static int dw_pcie_rd_other_conf(struct pcie_port *pp, struct pci_bus *bus,
  271. u32 devfn, int where, int size, u32 *val)
  272. {
  273. int ret = PCIBIOS_SUCCESSFUL;
  274. u32 address, busdev;
  275. busdev = PCIE_ATU_BUS(bus->number) | PCIE_ATU_DEV(PCI_SLOT(devfn)) |
  276. PCIE_ATU_FUNC(PCI_FUNC(devfn));
  277. address = where & ~0x3;
  278. if (bus->parent->number == pp->root_bus_nr) {
  279. dw_pcie_prog_viewport_cfg0(pp, busdev);
  280. ret = cfg_read(pp->va_cfg0_base + address, where, size, val);
  281. dw_pcie_prog_viewport_mem_outbound(pp);
  282. } else {
  283. dw_pcie_prog_viewport_cfg1(pp, busdev);
  284. ret = cfg_read(pp->va_cfg1_base + address, where, size, val);
  285. dw_pcie_prog_viewport_io_outbound(pp);
  286. }
  287. return ret;
  288. }
  289. static int dw_pcie_wr_other_conf(struct pcie_port *pp, struct pci_bus *bus,
  290. u32 devfn, int where, int size, u32 val)
  291. {
  292. int ret = PCIBIOS_SUCCESSFUL;
  293. u32 address, busdev;
  294. busdev = PCIE_ATU_BUS(bus->number) | PCIE_ATU_DEV(PCI_SLOT(devfn)) |
  295. PCIE_ATU_FUNC(PCI_FUNC(devfn));
  296. address = where & ~0x3;
  297. if (bus->parent->number == pp->root_bus_nr) {
  298. dw_pcie_prog_viewport_cfg0(pp, busdev);
  299. ret = cfg_write(pp->va_cfg0_base + address, where, size, val);
  300. dw_pcie_prog_viewport_mem_outbound(pp);
  301. } else {
  302. dw_pcie_prog_viewport_cfg1(pp, busdev);
  303. ret = cfg_write(pp->va_cfg1_base + address, where, size, val);
  304. dw_pcie_prog_viewport_io_outbound(pp);
  305. }
  306. return ret;
  307. }
  308. static int dw_pcie_valid_config(struct pcie_port *pp,
  309. struct pci_bus *bus, int dev)
  310. {
  311. /* If there is no link, then there is no device */
  312. if (bus->number != pp->root_bus_nr) {
  313. if (!dw_pcie_link_up(pp))
  314. return 0;
  315. }
  316. /* access only one slot on each root port */
  317. if (bus->number == pp->root_bus_nr && dev > 0)
  318. return 0;
  319. /*
  320. * do not read more than one device on the bus directly attached
  321. * to RC's (Virtual Bridge's) DS side.
  322. */
  323. if (bus->primary == pp->root_bus_nr && dev > 0)
  324. return 0;
  325. return 1;
  326. }
  327. static int dw_pcie_rd_conf(struct pci_bus *bus, u32 devfn, int where,
  328. int size, u32 *val)
  329. {
  330. struct pcie_port *pp = sys_to_pcie(bus->sysdata);
  331. unsigned long flags;
  332. int ret;
  333. if (!pp) {
  334. BUG();
  335. return -EINVAL;
  336. }
  337. if (dw_pcie_valid_config(pp, bus, PCI_SLOT(devfn)) == 0) {
  338. *val = 0xffffffff;
  339. return PCIBIOS_DEVICE_NOT_FOUND;
  340. }
  341. spin_lock_irqsave(&pp->conf_lock, flags);
  342. if (bus->number != pp->root_bus_nr)
  343. ret = dw_pcie_rd_other_conf(pp, bus, devfn,
  344. where, size, val);
  345. else
  346. ret = dw_pcie_rd_own_conf(pp, where, size, val);
  347. spin_unlock_irqrestore(&pp->conf_lock, flags);
  348. return ret;
  349. }
  350. static int dw_pcie_wr_conf(struct pci_bus *bus, u32 devfn,
  351. int where, int size, u32 val)
  352. {
  353. struct pcie_port *pp = sys_to_pcie(bus->sysdata);
  354. unsigned long flags;
  355. int ret;
  356. if (!pp) {
  357. BUG();
  358. return -EINVAL;
  359. }
  360. if (dw_pcie_valid_config(pp, bus, PCI_SLOT(devfn)) == 0)
  361. return PCIBIOS_DEVICE_NOT_FOUND;
  362. spin_lock_irqsave(&pp->conf_lock, flags);
  363. if (bus->number != pp->root_bus_nr)
  364. ret = dw_pcie_wr_other_conf(pp, bus, devfn,
  365. where, size, val);
  366. else
  367. ret = dw_pcie_wr_own_conf(pp, where, size, val);
  368. spin_unlock_irqrestore(&pp->conf_lock, flags);
  369. return ret;
  370. }
  371. static struct pci_ops dw_pcie_ops = {
  372. .read = dw_pcie_rd_conf,
  373. .write = dw_pcie_wr_conf,
  374. };
  375. int dw_pcie_setup(int nr, struct pci_sys_data *sys)
  376. {
  377. struct pcie_port *pp;
  378. pp = sys_to_pcie(sys);
  379. if (!pp)
  380. return 0;
  381. if (global_io_offset < SZ_1M && pp->config.io_size > 0) {
  382. sys->io_offset = global_io_offset - pp->config.io_bus_addr;
  383. pci_ioremap_io(sys->io_offset, pp->io.start);
  384. global_io_offset += SZ_64K;
  385. pci_add_resource_offset(&sys->resources, &pp->io,
  386. sys->io_offset);
  387. }
  388. sys->mem_offset = pp->mem.start - pp->config.mem_bus_addr;
  389. pci_add_resource_offset(&sys->resources, &pp->mem, sys->mem_offset);
  390. return 1;
  391. }
  392. struct pci_bus *dw_pcie_scan_bus(int nr, struct pci_sys_data *sys)
  393. {
  394. struct pci_bus *bus;
  395. struct pcie_port *pp = sys_to_pcie(sys);
  396. if (pp) {
  397. pp->root_bus_nr = sys->busnr;
  398. bus = pci_scan_root_bus(NULL, sys->busnr, &dw_pcie_ops,
  399. sys, &sys->resources);
  400. } else {
  401. bus = NULL;
  402. BUG();
  403. }
  404. return bus;
  405. }
  406. int dw_pcie_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  407. {
  408. struct pcie_port *pp = sys_to_pcie(dev->bus->sysdata);
  409. return pp->irq;
  410. }
  411. static struct hw_pci dw_pci = {
  412. .setup = dw_pcie_setup,
  413. .scan = dw_pcie_scan_bus,
  414. .map_irq = dw_pcie_map_irq,
  415. };
  416. void dw_pcie_setup_rc(struct pcie_port *pp)
  417. {
  418. struct pcie_port_info *config = &pp->config;
  419. u32 val;
  420. u32 membase;
  421. u32 memlimit;
  422. /* set the number of lines as 4 */
  423. dw_pcie_readl_rc(pp, PCIE_PORT_LINK_CONTROL, &val);
  424. val &= ~PORT_LINK_MODE_MASK;
  425. switch (pp->lanes) {
  426. case 1:
  427. val |= PORT_LINK_MODE_1_LANES;
  428. break;
  429. case 2:
  430. val |= PORT_LINK_MODE_2_LANES;
  431. break;
  432. case 4:
  433. val |= PORT_LINK_MODE_4_LANES;
  434. break;
  435. }
  436. dw_pcie_writel_rc(pp, val, PCIE_PORT_LINK_CONTROL);
  437. /* set link width speed control register */
  438. dw_pcie_readl_rc(pp, PCIE_LINK_WIDTH_SPEED_CONTROL, &val);
  439. val &= ~PORT_LOGIC_LINK_WIDTH_MASK;
  440. switch (pp->lanes) {
  441. case 1:
  442. val |= PORT_LOGIC_LINK_WIDTH_1_LANES;
  443. break;
  444. case 2:
  445. val |= PORT_LOGIC_LINK_WIDTH_2_LANES;
  446. break;
  447. case 4:
  448. val |= PORT_LOGIC_LINK_WIDTH_4_LANES;
  449. break;
  450. }
  451. dw_pcie_writel_rc(pp, val, PCIE_LINK_WIDTH_SPEED_CONTROL);
  452. /* setup RC BARs */
  453. dw_pcie_writel_rc(pp, 0x00000004, PCI_BASE_ADDRESS_0);
  454. dw_pcie_writel_rc(pp, 0x00000004, PCI_BASE_ADDRESS_1);
  455. /* setup interrupt pins */
  456. dw_pcie_readl_rc(pp, PCI_INTERRUPT_LINE, &val);
  457. val &= 0xffff00ff;
  458. val |= 0x00000100;
  459. dw_pcie_writel_rc(pp, val, PCI_INTERRUPT_LINE);
  460. /* setup bus numbers */
  461. dw_pcie_readl_rc(pp, PCI_PRIMARY_BUS, &val);
  462. val &= 0xff000000;
  463. val |= 0x00010100;
  464. dw_pcie_writel_rc(pp, val, PCI_PRIMARY_BUS);
  465. /* setup memory base, memory limit */
  466. membase = ((u32)pp->mem_base & 0xfff00000) >> 16;
  467. memlimit = (config->mem_size + (u32)pp->mem_base) & 0xfff00000;
  468. val = memlimit | membase;
  469. dw_pcie_writel_rc(pp, val, PCI_MEMORY_BASE);
  470. /* setup command register */
  471. dw_pcie_readl_rc(pp, PCI_COMMAND, &val);
  472. val &= 0xffff0000;
  473. val |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY |
  474. PCI_COMMAND_MASTER | PCI_COMMAND_SERR;
  475. dw_pcie_writel_rc(pp, val, PCI_COMMAND);
  476. }
  477. MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>");
  478. MODULE_DESCRIPTION("Designware PCIe host controller driver");
  479. MODULE_LICENSE("GPL v2");