fsl_rio.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. /*
  2. * Freescale MPC85xx/MPC86xx RapidIO support
  3. *
  4. * Copyright 2009 Sysgo AG
  5. * Thomas Moll <thomas.moll@sysgo.com>
  6. * - fixed maintenance access routines, check for aligned access
  7. *
  8. * Copyright 2009 Integrated Device Technology, Inc.
  9. * Alex Bounine <alexandre.bounine@idt.com>
  10. * - Added Port-Write message handling
  11. * - Added Machine Check exception handling
  12. *
  13. * Copyright (C) 2007, 2008, 2010, 2011 Freescale Semiconductor, Inc.
  14. * Zhang Wei <wei.zhang@freescale.com>
  15. *
  16. * Copyright 2005 MontaVista Software, Inc.
  17. * Matt Porter <mporter@kernel.crashing.org>
  18. *
  19. * This program is free software; you can redistribute it and/or modify it
  20. * under the terms of the GNU General Public License as published by the
  21. * Free Software Foundation; either version 2 of the License, or (at your
  22. * option) any later version.
  23. */
  24. #include <linux/init.h>
  25. #include <linux/module.h>
  26. #include <linux/types.h>
  27. #include <linux/dma-mapping.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/device.h>
  30. #include <linux/of_platform.h>
  31. #include <linux/delay.h>
  32. #include <linux/slab.h>
  33. #include <linux/io.h>
  34. #include <linux/uaccess.h>
  35. #include <asm/machdep.h>
  36. #include "fsl_rio.h"
  37. #undef DEBUG_PW /* Port-Write debugging */
  38. #define RIO_PORT1_EDCSR 0x0640
  39. #define RIO_PORT2_EDCSR 0x0680
  40. #define RIO_PORT1_IECSR 0x10130
  41. #define RIO_PORT2_IECSR 0x101B0
  42. #define RIO_GCCSR 0x13c
  43. #define RIO_ESCSR 0x158
  44. #define ESCSR_CLEAR 0x07120204
  45. #define RIO_PORT2_ESCSR 0x178
  46. #define RIO_CCSR 0x15c
  47. #define RIO_LTLEDCSR_IER 0x80000000
  48. #define RIO_LTLEDCSR_PRT 0x01000000
  49. #define IECSR_CLEAR 0x80000000
  50. #define RIO_ISR_AACR 0x10120
  51. #define RIO_ISR_AACR_AA 0x1 /* Accept All ID */
  52. #define __fsl_read_rio_config(x, addr, err, op) \
  53. __asm__ __volatile__( \
  54. "1: "op" %1,0(%2)\n" \
  55. " eieio\n" \
  56. "2:\n" \
  57. ".section .fixup,\"ax\"\n" \
  58. "3: li %1,-1\n" \
  59. " li %0,%3\n" \
  60. " b 2b\n" \
  61. ".section __ex_table,\"a\"\n" \
  62. PPC_LONG_ALIGN "\n" \
  63. PPC_LONG "1b,3b\n" \
  64. ".text" \
  65. : "=r" (err), "=r" (x) \
  66. : "b" (addr), "i" (-EFAULT), "0" (err))
  67. void __iomem *rio_regs_win;
  68. void __iomem *rmu_regs_win;
  69. resource_size_t rio_law_start;
  70. struct fsl_rio_dbell *dbell;
  71. struct fsl_rio_pw *pw;
  72. #ifdef CONFIG_E500
  73. int fsl_rio_mcheck_exception(struct pt_regs *regs)
  74. {
  75. const struct exception_table_entry *entry;
  76. unsigned long reason;
  77. if (!rio_regs_win)
  78. return 0;
  79. reason = in_be32((u32 *)(rio_regs_win + RIO_LTLEDCSR));
  80. if (reason & (RIO_LTLEDCSR_IER | RIO_LTLEDCSR_PRT)) {
  81. /* Check if we are prepared to handle this fault */
  82. entry = search_exception_tables(regs->nip);
  83. if (entry) {
  84. pr_debug("RIO: %s - MC Exception handled\n",
  85. __func__);
  86. out_be32((u32 *)(rio_regs_win + RIO_LTLEDCSR),
  87. 0);
  88. regs->msr |= MSR_RI;
  89. regs->nip = entry->fixup;
  90. return 1;
  91. }
  92. }
  93. return 0;
  94. }
  95. EXPORT_SYMBOL_GPL(fsl_rio_mcheck_exception);
  96. #endif
  97. /**
  98. * fsl_local_config_read - Generate a MPC85xx local config space read
  99. * @mport: RapidIO master port info
  100. * @index: ID of RapdiIO interface
  101. * @offset: Offset into configuration space
  102. * @len: Length (in bytes) of the maintenance transaction
  103. * @data: Value to be read into
  104. *
  105. * Generates a MPC85xx local configuration space read. Returns %0 on
  106. * success or %-EINVAL on failure.
  107. */
  108. static int fsl_local_config_read(struct rio_mport *mport,
  109. int index, u32 offset, int len, u32 *data)
  110. {
  111. struct rio_priv *priv = mport->priv;
  112. pr_debug("fsl_local_config_read: index %d offset %8.8x\n", index,
  113. offset);
  114. *data = in_be32(priv->regs_win + offset);
  115. return 0;
  116. }
  117. /**
  118. * fsl_local_config_write - Generate a MPC85xx local config space write
  119. * @mport: RapidIO master port info
  120. * @index: ID of RapdiIO interface
  121. * @offset: Offset into configuration space
  122. * @len: Length (in bytes) of the maintenance transaction
  123. * @data: Value to be written
  124. *
  125. * Generates a MPC85xx local configuration space write. Returns %0 on
  126. * success or %-EINVAL on failure.
  127. */
  128. static int fsl_local_config_write(struct rio_mport *mport,
  129. int index, u32 offset, int len, u32 data)
  130. {
  131. struct rio_priv *priv = mport->priv;
  132. pr_debug
  133. ("fsl_local_config_write: index %d offset %8.8x data %8.8x\n",
  134. index, offset, data);
  135. out_be32(priv->regs_win + offset, data);
  136. return 0;
  137. }
  138. /**
  139. * fsl_rio_config_read - Generate a MPC85xx read maintenance transaction
  140. * @mport: RapidIO master port info
  141. * @index: ID of RapdiIO interface
  142. * @destid: Destination ID of transaction
  143. * @hopcount: Number of hops to target device
  144. * @offset: Offset into configuration space
  145. * @len: Length (in bytes) of the maintenance transaction
  146. * @val: Location to be read into
  147. *
  148. * Generates a MPC85xx read maintenance transaction. Returns %0 on
  149. * success or %-EINVAL on failure.
  150. */
  151. static int
  152. fsl_rio_config_read(struct rio_mport *mport, int index, u16 destid,
  153. u8 hopcount, u32 offset, int len, u32 *val)
  154. {
  155. struct rio_priv *priv = mport->priv;
  156. u8 *data;
  157. u32 rval, err = 0;
  158. pr_debug
  159. ("fsl_rio_config_read:"
  160. " index %d destid %d hopcount %d offset %8.8x len %d\n",
  161. index, destid, hopcount, offset, len);
  162. /* 16MB maintenance window possible */
  163. /* allow only aligned access to maintenance registers */
  164. if (offset > (0x1000000 - len) || !IS_ALIGNED(offset, len))
  165. return -EINVAL;
  166. out_be32(&priv->maint_atmu_regs->rowtar,
  167. (destid << 22) | (hopcount << 12) | (offset >> 12));
  168. out_be32(&priv->maint_atmu_regs->rowtear, (destid >> 10));
  169. data = (u8 *) priv->maint_win + (offset & (RIO_MAINT_WIN_SIZE - 1));
  170. switch (len) {
  171. case 1:
  172. __fsl_read_rio_config(rval, data, err, "lbz");
  173. break;
  174. case 2:
  175. __fsl_read_rio_config(rval, data, err, "lhz");
  176. break;
  177. case 4:
  178. __fsl_read_rio_config(rval, data, err, "lwz");
  179. break;
  180. default:
  181. return -EINVAL;
  182. }
  183. if (err) {
  184. pr_debug("RIO: cfg_read error %d for %x:%x:%x\n",
  185. err, destid, hopcount, offset);
  186. }
  187. *val = rval;
  188. return err;
  189. }
  190. /**
  191. * fsl_rio_config_write - Generate a MPC85xx write maintenance transaction
  192. * @mport: RapidIO master port info
  193. * @index: ID of RapdiIO interface
  194. * @destid: Destination ID of transaction
  195. * @hopcount: Number of hops to target device
  196. * @offset: Offset into configuration space
  197. * @len: Length (in bytes) of the maintenance transaction
  198. * @val: Value to be written
  199. *
  200. * Generates an MPC85xx write maintenance transaction. Returns %0 on
  201. * success or %-EINVAL on failure.
  202. */
  203. static int
  204. fsl_rio_config_write(struct rio_mport *mport, int index, u16 destid,
  205. u8 hopcount, u32 offset, int len, u32 val)
  206. {
  207. struct rio_priv *priv = mport->priv;
  208. u8 *data;
  209. pr_debug
  210. ("fsl_rio_config_write:"
  211. " index %d destid %d hopcount %d offset %8.8x len %d val %8.8x\n",
  212. index, destid, hopcount, offset, len, val);
  213. /* 16MB maintenance windows possible */
  214. /* allow only aligned access to maintenance registers */
  215. if (offset > (0x1000000 - len) || !IS_ALIGNED(offset, len))
  216. return -EINVAL;
  217. out_be32(&priv->maint_atmu_regs->rowtar,
  218. (destid << 22) | (hopcount << 12) | (offset >> 12));
  219. out_be32(&priv->maint_atmu_regs->rowtear, (destid >> 10));
  220. data = (u8 *) priv->maint_win + (offset & (RIO_MAINT_WIN_SIZE - 1));
  221. switch (len) {
  222. case 1:
  223. out_8((u8 *) data, val);
  224. break;
  225. case 2:
  226. out_be16((u16 *) data, val);
  227. break;
  228. case 4:
  229. out_be32((u32 *) data, val);
  230. break;
  231. default:
  232. return -EINVAL;
  233. }
  234. return 0;
  235. }
  236. void fsl_rio_port_error_handler(int offset)
  237. {
  238. /*XXX: Error recovery is not implemented, we just clear errors */
  239. out_be32((u32 *)(rio_regs_win + RIO_LTLEDCSR), 0);
  240. if (offset == 0) {
  241. out_be32((u32 *)(rio_regs_win + RIO_PORT1_EDCSR), 0);
  242. out_be32((u32 *)(rio_regs_win + RIO_PORT1_IECSR), IECSR_CLEAR);
  243. out_be32((u32 *)(rio_regs_win + RIO_ESCSR), ESCSR_CLEAR);
  244. } else {
  245. out_be32((u32 *)(rio_regs_win + RIO_PORT2_EDCSR), 0);
  246. out_be32((u32 *)(rio_regs_win + RIO_PORT2_IECSR), IECSR_CLEAR);
  247. out_be32((u32 *)(rio_regs_win + RIO_PORT2_ESCSR), ESCSR_CLEAR);
  248. }
  249. }
  250. static inline void fsl_rio_info(struct device *dev, u32 ccsr)
  251. {
  252. const char *str;
  253. if (ccsr & 1) {
  254. /* Serial phy */
  255. switch (ccsr >> 30) {
  256. case 0:
  257. str = "1";
  258. break;
  259. case 1:
  260. str = "4";
  261. break;
  262. default:
  263. str = "Unknown";
  264. break;
  265. }
  266. dev_info(dev, "Hardware port width: %s\n", str);
  267. switch ((ccsr >> 27) & 7) {
  268. case 0:
  269. str = "Single-lane 0";
  270. break;
  271. case 1:
  272. str = "Single-lane 2";
  273. break;
  274. case 2:
  275. str = "Four-lane";
  276. break;
  277. default:
  278. str = "Unknown";
  279. break;
  280. }
  281. dev_info(dev, "Training connection status: %s\n", str);
  282. } else {
  283. /* Parallel phy */
  284. if (!(ccsr & 0x80000000))
  285. dev_info(dev, "Output port operating in 8-bit mode\n");
  286. if (!(ccsr & 0x08000000))
  287. dev_info(dev, "Input port operating in 8-bit mode\n");
  288. }
  289. }
  290. /**
  291. * fsl_rio_setup - Setup Freescale PowerPC RapidIO interface
  292. * @dev: platform_device pointer
  293. *
  294. * Initializes MPC85xx RapidIO hardware interface, configures
  295. * master port with system-specific info, and registers the
  296. * master port with the RapidIO subsystem.
  297. */
  298. int fsl_rio_setup(struct platform_device *dev)
  299. {
  300. struct rio_ops *ops;
  301. struct rio_mport *port;
  302. struct rio_priv *priv;
  303. int rc = 0;
  304. const u32 *dt_range, *cell, *port_index;
  305. u32 active_ports = 0;
  306. struct resource regs, rmu_regs;
  307. struct device_node *np, *rmu_node;
  308. int rlen;
  309. u32 ccsr;
  310. u64 range_start, range_size;
  311. int paw, aw, sw;
  312. u32 i;
  313. static int tmp;
  314. struct device_node *rmu_np[MAX_MSG_UNIT_NUM] = {NULL};
  315. if (!dev->dev.of_node) {
  316. dev_err(&dev->dev, "Device OF-Node is NULL");
  317. return -ENODEV;
  318. }
  319. rc = of_address_to_resource(dev->dev.of_node, 0, &regs);
  320. if (rc) {
  321. dev_err(&dev->dev, "Can't get %s property 'reg'\n",
  322. dev->dev.of_node->full_name);
  323. return -EFAULT;
  324. }
  325. dev_info(&dev->dev, "Of-device full name %s\n",
  326. dev->dev.of_node->full_name);
  327. dev_info(&dev->dev, "Regs: %pR\n", &regs);
  328. rio_regs_win = ioremap(regs.start, resource_size(&regs));
  329. if (!rio_regs_win) {
  330. dev_err(&dev->dev, "Unable to map rio register window\n");
  331. rc = -ENOMEM;
  332. goto err_rio_regs;
  333. }
  334. ops = kzalloc(sizeof(struct rio_ops), GFP_KERNEL);
  335. if (!ops) {
  336. rc = -ENOMEM;
  337. goto err_ops;
  338. }
  339. ops->lcread = fsl_local_config_read;
  340. ops->lcwrite = fsl_local_config_write;
  341. ops->cread = fsl_rio_config_read;
  342. ops->cwrite = fsl_rio_config_write;
  343. ops->dsend = fsl_rio_doorbell_send;
  344. ops->pwenable = fsl_rio_pw_enable;
  345. ops->open_outb_mbox = fsl_open_outb_mbox;
  346. ops->open_inb_mbox = fsl_open_inb_mbox;
  347. ops->close_outb_mbox = fsl_close_outb_mbox;
  348. ops->close_inb_mbox = fsl_close_inb_mbox;
  349. ops->add_outb_message = fsl_add_outb_message;
  350. ops->add_inb_buffer = fsl_add_inb_buffer;
  351. ops->get_inb_message = fsl_get_inb_message;
  352. rmu_node = of_parse_phandle(dev->dev.of_node, "fsl,srio-rmu-handle", 0);
  353. if (!rmu_node)
  354. goto err_rmu;
  355. rc = of_address_to_resource(rmu_node, 0, &rmu_regs);
  356. if (rc) {
  357. dev_err(&dev->dev, "Can't get %s property 'reg'\n",
  358. rmu_node->full_name);
  359. goto err_rmu;
  360. }
  361. rmu_regs_win = ioremap(rmu_regs.start, resource_size(&rmu_regs));
  362. if (!rmu_regs_win) {
  363. dev_err(&dev->dev, "Unable to map rmu register window\n");
  364. rc = -ENOMEM;
  365. goto err_rmu;
  366. }
  367. for_each_compatible_node(np, NULL, "fsl,srio-msg-unit") {
  368. rmu_np[tmp] = np;
  369. tmp++;
  370. }
  371. /*set up doobell node*/
  372. np = of_find_compatible_node(NULL, NULL, "fsl,srio-dbell-unit");
  373. if (!np) {
  374. rc = -ENODEV;
  375. goto err_dbell;
  376. }
  377. dbell = kzalloc(sizeof(struct fsl_rio_dbell), GFP_KERNEL);
  378. if (!(dbell)) {
  379. dev_err(&dev->dev, "Can't alloc memory for 'fsl_rio_dbell'\n");
  380. rc = -ENOMEM;
  381. goto err_dbell;
  382. }
  383. dbell->dev = &dev->dev;
  384. dbell->bellirq = irq_of_parse_and_map(np, 1);
  385. dev_info(&dev->dev, "bellirq: %d\n", dbell->bellirq);
  386. aw = of_n_addr_cells(np);
  387. dt_range = of_get_property(np, "reg", &rlen);
  388. if (!dt_range) {
  389. pr_err("%s: unable to find 'reg' property\n",
  390. np->full_name);
  391. rc = -ENOMEM;
  392. goto err_pw;
  393. }
  394. range_start = of_read_number(dt_range, aw);
  395. dbell->dbell_regs = (struct rio_dbell_regs *)(rmu_regs_win +
  396. (u32)range_start);
  397. /*set up port write node*/
  398. np = of_find_compatible_node(NULL, NULL, "fsl,srio-port-write-unit");
  399. if (!np) {
  400. rc = -ENODEV;
  401. goto err_pw;
  402. }
  403. pw = kzalloc(sizeof(struct fsl_rio_pw), GFP_KERNEL);
  404. if (!(pw)) {
  405. dev_err(&dev->dev, "Can't alloc memory for 'fsl_rio_pw'\n");
  406. rc = -ENOMEM;
  407. goto err_pw;
  408. }
  409. pw->dev = &dev->dev;
  410. pw->pwirq = irq_of_parse_and_map(np, 0);
  411. dev_info(&dev->dev, "pwirq: %d\n", pw->pwirq);
  412. aw = of_n_addr_cells(np);
  413. dt_range = of_get_property(np, "reg", &rlen);
  414. if (!dt_range) {
  415. pr_err("%s: unable to find 'reg' property\n",
  416. np->full_name);
  417. rc = -ENOMEM;
  418. goto err;
  419. }
  420. range_start = of_read_number(dt_range, aw);
  421. pw->pw_regs = (struct rio_pw_regs *)(rmu_regs_win + (u32)range_start);
  422. /*set up ports node*/
  423. for_each_child_of_node(dev->dev.of_node, np) {
  424. port_index = of_get_property(np, "cell-index", NULL);
  425. if (!port_index) {
  426. dev_err(&dev->dev, "Can't get %s property 'cell-index'\n",
  427. np->full_name);
  428. continue;
  429. }
  430. dt_range = of_get_property(np, "ranges", &rlen);
  431. if (!dt_range) {
  432. dev_err(&dev->dev, "Can't get %s property 'ranges'\n",
  433. np->full_name);
  434. continue;
  435. }
  436. /* Get node address wide */
  437. cell = of_get_property(np, "#address-cells", NULL);
  438. if (cell)
  439. aw = *cell;
  440. else
  441. aw = of_n_addr_cells(np);
  442. /* Get node size wide */
  443. cell = of_get_property(np, "#size-cells", NULL);
  444. if (cell)
  445. sw = *cell;
  446. else
  447. sw = of_n_size_cells(np);
  448. /* Get parent address wide wide */
  449. paw = of_n_addr_cells(np);
  450. range_start = of_read_number(dt_range + aw, paw);
  451. range_size = of_read_number(dt_range + aw + paw, sw);
  452. dev_info(&dev->dev, "%s: LAW start 0x%016llx, size 0x%016llx.\n",
  453. np->full_name, range_start, range_size);
  454. port = kzalloc(sizeof(struct rio_mport), GFP_KERNEL);
  455. if (!port)
  456. continue;
  457. i = *port_index - 1;
  458. port->index = (unsigned char)i;
  459. priv = kzalloc(sizeof(struct rio_priv), GFP_KERNEL);
  460. if (!priv) {
  461. dev_err(&dev->dev, "Can't alloc memory for 'priv'\n");
  462. kfree(port);
  463. continue;
  464. }
  465. INIT_LIST_HEAD(&port->dbells);
  466. port->iores.start = range_start;
  467. port->iores.end = port->iores.start + range_size - 1;
  468. port->iores.flags = IORESOURCE_MEM;
  469. port->iores.name = "rio_io_win";
  470. if (request_resource(&iomem_resource, &port->iores) < 0) {
  471. dev_err(&dev->dev, "RIO: Error requesting master port region"
  472. " 0x%016llx-0x%016llx\n",
  473. (u64)port->iores.start, (u64)port->iores.end);
  474. kfree(priv);
  475. kfree(port);
  476. continue;
  477. }
  478. sprintf(port->name, "RIO mport %d", i);
  479. priv->dev = &dev->dev;
  480. port->ops = ops;
  481. port->priv = priv;
  482. port->phys_efptr = 0x100;
  483. priv->regs_win = rio_regs_win;
  484. /* Probe the master port phy type */
  485. ccsr = in_be32(priv->regs_win + RIO_CCSR + i*0x20);
  486. port->phy_type = (ccsr & 1) ? RIO_PHY_SERIAL : RIO_PHY_PARALLEL;
  487. if (port->phy_type == RIO_PHY_PARALLEL) {
  488. dev_err(&dev->dev, "RIO: Parallel PHY type, unsupported port type!\n");
  489. release_resource(&port->iores);
  490. kfree(priv);
  491. kfree(port);
  492. continue;
  493. }
  494. dev_info(&dev->dev, "RapidIO PHY type: Serial\n");
  495. /* Checking the port training status */
  496. if (in_be32((priv->regs_win + RIO_ESCSR + i*0x20)) & 1) {
  497. dev_err(&dev->dev, "Port %d is not ready. "
  498. "Try to restart connection...\n", i);
  499. /* Disable ports */
  500. out_be32(priv->regs_win
  501. + RIO_CCSR + i*0x20, 0);
  502. /* Set 1x lane */
  503. setbits32(priv->regs_win
  504. + RIO_CCSR + i*0x20, 0x02000000);
  505. /* Enable ports */
  506. setbits32(priv->regs_win
  507. + RIO_CCSR + i*0x20, 0x00600000);
  508. msleep(100);
  509. if (in_be32((priv->regs_win
  510. + RIO_ESCSR + i*0x20)) & 1) {
  511. dev_err(&dev->dev,
  512. "Port %d restart failed.\n", i);
  513. release_resource(&port->iores);
  514. kfree(priv);
  515. kfree(port);
  516. continue;
  517. }
  518. dev_info(&dev->dev, "Port %d restart success!\n", i);
  519. }
  520. fsl_rio_info(&dev->dev, ccsr);
  521. port->sys_size = (in_be32((priv->regs_win + RIO_PEF_CAR))
  522. & RIO_PEF_CTLS) >> 4;
  523. dev_info(&dev->dev, "RapidIO Common Transport System size: %d\n",
  524. port->sys_size ? 65536 : 256);
  525. if (rio_register_mport(port)) {
  526. release_resource(&port->iores);
  527. kfree(priv);
  528. kfree(port);
  529. continue;
  530. }
  531. if (port->host_deviceid >= 0)
  532. out_be32(priv->regs_win + RIO_GCCSR, RIO_PORT_GEN_HOST |
  533. RIO_PORT_GEN_MASTER | RIO_PORT_GEN_DISCOVERED);
  534. else
  535. out_be32(priv->regs_win + RIO_GCCSR,
  536. RIO_PORT_GEN_MASTER);
  537. priv->atmu_regs = (struct rio_atmu_regs *)(priv->regs_win
  538. + ((i == 0) ? RIO_ATMU_REGS_PORT1_OFFSET :
  539. RIO_ATMU_REGS_PORT2_OFFSET));
  540. priv->maint_atmu_regs = priv->atmu_regs + 1;
  541. /* Set to receive any dist ID for serial RapidIO controller. */
  542. if (port->phy_type == RIO_PHY_SERIAL)
  543. out_be32((priv->regs_win
  544. + RIO_ISR_AACR + i*0x80), RIO_ISR_AACR_AA);
  545. /* Configure maintenance transaction window */
  546. out_be32(&priv->maint_atmu_regs->rowbar,
  547. port->iores.start >> 12);
  548. out_be32(&priv->maint_atmu_regs->rowar,
  549. 0x80077000 | (ilog2(RIO_MAINT_WIN_SIZE) - 1));
  550. priv->maint_win = ioremap(port->iores.start,
  551. RIO_MAINT_WIN_SIZE);
  552. rio_law_start = range_start;
  553. fsl_rio_setup_rmu(port, rmu_np[i]);
  554. dbell->mport[i] = port;
  555. active_ports++;
  556. }
  557. if (!active_ports) {
  558. rc = -ENOLINK;
  559. goto err;
  560. }
  561. fsl_rio_doorbell_init(dbell);
  562. fsl_rio_port_write_init(pw);
  563. return 0;
  564. err:
  565. kfree(pw);
  566. err_pw:
  567. kfree(dbell);
  568. err_dbell:
  569. iounmap(rmu_regs_win);
  570. err_rmu:
  571. kfree(ops);
  572. err_ops:
  573. iounmap(rio_regs_win);
  574. err_rio_regs:
  575. return rc;
  576. }
  577. /* The probe function for RapidIO peer-to-peer network.
  578. */
  579. static int __devinit fsl_of_rio_rpn_probe(struct platform_device *dev)
  580. {
  581. printk(KERN_INFO "Setting up RapidIO peer-to-peer network %s\n",
  582. dev->dev.of_node->full_name);
  583. return fsl_rio_setup(dev);
  584. };
  585. static const struct of_device_id fsl_of_rio_rpn_ids[] = {
  586. {
  587. .compatible = "fsl,srio",
  588. },
  589. {},
  590. };
  591. static struct platform_driver fsl_of_rio_rpn_driver = {
  592. .driver = {
  593. .name = "fsl-of-rio",
  594. .owner = THIS_MODULE,
  595. .of_match_table = fsl_of_rio_rpn_ids,
  596. },
  597. .probe = fsl_of_rio_rpn_probe,
  598. };
  599. static __init int fsl_of_rio_rpn_init(void)
  600. {
  601. return platform_driver_register(&fsl_of_rio_rpn_driver);
  602. }
  603. subsys_initcall(fsl_of_rio_rpn_init);