fsl_rio.c 18 KB

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