zynq-fpga.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. /*
  2. * Copyright (c) 2011-2015 Xilinx Inc.
  3. * Copyright (c) 2015, National Instruments Corp.
  4. *
  5. * FPGA Manager Driver for Xilinx Zynq, heavily based on xdevcfg driver
  6. * in their vendor tree.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; version 2 of the License.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #include <linux/clk.h>
  18. #include <linux/completion.h>
  19. #include <linux/delay.h>
  20. #include <linux/dma-mapping.h>
  21. #include <linux/fpga/fpga-mgr.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/io.h>
  24. #include <linux/iopoll.h>
  25. #include <linux/module.h>
  26. #include <linux/mfd/syscon.h>
  27. #include <linux/of_address.h>
  28. #include <linux/of_irq.h>
  29. #include <linux/pm.h>
  30. #include <linux/regmap.h>
  31. #include <linux/string.h>
  32. #include <linux/scatterlist.h>
  33. /* Offsets into SLCR regmap */
  34. /* FPGA Software Reset Control */
  35. #define SLCR_FPGA_RST_CTRL_OFFSET 0x240
  36. /* Level Shifters Enable */
  37. #define SLCR_LVL_SHFTR_EN_OFFSET 0x900
  38. /* Constant Definitions */
  39. /* Control Register */
  40. #define CTRL_OFFSET 0x00
  41. /* Lock Register */
  42. #define LOCK_OFFSET 0x04
  43. /* Interrupt Status Register */
  44. #define INT_STS_OFFSET 0x0c
  45. /* Interrupt Mask Register */
  46. #define INT_MASK_OFFSET 0x10
  47. /* Status Register */
  48. #define STATUS_OFFSET 0x14
  49. /* DMA Source Address Register */
  50. #define DMA_SRC_ADDR_OFFSET 0x18
  51. /* DMA Destination Address Reg */
  52. #define DMA_DST_ADDR_OFFSET 0x1c
  53. /* DMA Source Transfer Length */
  54. #define DMA_SRC_LEN_OFFSET 0x20
  55. /* DMA Destination Transfer */
  56. #define DMA_DEST_LEN_OFFSET 0x24
  57. /* Unlock Register */
  58. #define UNLOCK_OFFSET 0x34
  59. /* Misc. Control Register */
  60. #define MCTRL_OFFSET 0x80
  61. /* Control Register Bit definitions */
  62. /* Signal to reset FPGA */
  63. #define CTRL_PCFG_PROG_B_MASK BIT(30)
  64. /* Enable PCAP for PR */
  65. #define CTRL_PCAP_PR_MASK BIT(27)
  66. /* Enable PCAP */
  67. #define CTRL_PCAP_MODE_MASK BIT(26)
  68. /* Miscellaneous Control Register bit definitions */
  69. /* Internal PCAP loopback */
  70. #define MCTRL_PCAP_LPBK_MASK BIT(4)
  71. /* Status register bit definitions */
  72. /* FPGA init status */
  73. #define STATUS_DMA_Q_F BIT(31)
  74. #define STATUS_DMA_Q_E BIT(30)
  75. #define STATUS_PCFG_INIT_MASK BIT(4)
  76. /* Interrupt Status/Mask Register Bit definitions */
  77. /* DMA command done */
  78. #define IXR_DMA_DONE_MASK BIT(13)
  79. /* DMA and PCAP cmd done */
  80. #define IXR_D_P_DONE_MASK BIT(12)
  81. /* FPGA programmed */
  82. #define IXR_PCFG_DONE_MASK BIT(2)
  83. #define IXR_ERROR_FLAGS_MASK 0x00F0C860
  84. #define IXR_ALL_MASK 0xF8F7F87F
  85. /* Miscellaneous constant values */
  86. /* Invalid DMA addr */
  87. #define DMA_INVALID_ADDRESS GENMASK(31, 0)
  88. /* Used to unlock the dev */
  89. #define UNLOCK_MASK 0x757bdf0d
  90. /* Timeout for polling reset bits */
  91. #define INIT_POLL_TIMEOUT 2500000
  92. /* Delay for polling reset bits */
  93. #define INIT_POLL_DELAY 20
  94. /* Signal this is the last DMA transfer, wait for the AXI and PCAP before
  95. * interrupting
  96. */
  97. #define DMA_SRC_LAST_TRANSFER 1
  98. /* Timeout for DMA completion */
  99. #define DMA_TIMEOUT_MS 5000
  100. /* Masks for controlling stuff in SLCR */
  101. /* Disable all Level shifters */
  102. #define LVL_SHFTR_DISABLE_ALL_MASK 0x0
  103. /* Enable Level shifters from PS to PL */
  104. #define LVL_SHFTR_ENABLE_PS_TO_PL 0xa
  105. /* Enable Level shifters from PL to PS */
  106. #define LVL_SHFTR_ENABLE_PL_TO_PS 0xf
  107. /* Enable global resets */
  108. #define FPGA_RST_ALL_MASK 0xf
  109. /* Disable global resets */
  110. #define FPGA_RST_NONE_MASK 0x0
  111. struct zynq_fpga_priv {
  112. int irq;
  113. struct clk *clk;
  114. void __iomem *io_base;
  115. struct regmap *slcr;
  116. spinlock_t dma_lock;
  117. unsigned int dma_elm;
  118. unsigned int dma_nelms;
  119. struct scatterlist *cur_sg;
  120. struct completion dma_done;
  121. };
  122. static inline void zynq_fpga_write(struct zynq_fpga_priv *priv, u32 offset,
  123. u32 val)
  124. {
  125. writel(val, priv->io_base + offset);
  126. }
  127. static inline u32 zynq_fpga_read(const struct zynq_fpga_priv *priv,
  128. u32 offset)
  129. {
  130. return readl(priv->io_base + offset);
  131. }
  132. #define zynq_fpga_poll_timeout(priv, addr, val, cond, sleep_us, timeout_us) \
  133. readl_poll_timeout(priv->io_base + addr, val, cond, sleep_us, \
  134. timeout_us)
  135. /* Cause the specified irq mask bits to generate IRQs */
  136. static inline void zynq_fpga_set_irq(struct zynq_fpga_priv *priv, u32 enable)
  137. {
  138. zynq_fpga_write(priv, INT_MASK_OFFSET, ~enable);
  139. }
  140. /* Must be called with dma_lock held */
  141. static void zynq_step_dma(struct zynq_fpga_priv *priv)
  142. {
  143. u32 addr;
  144. u32 len;
  145. bool first;
  146. first = priv->dma_elm == 0;
  147. while (priv->cur_sg) {
  148. /* Feed the DMA queue until it is full. */
  149. if (zynq_fpga_read(priv, STATUS_OFFSET) & STATUS_DMA_Q_F)
  150. break;
  151. addr = sg_dma_address(priv->cur_sg);
  152. len = sg_dma_len(priv->cur_sg);
  153. if (priv->dma_elm + 1 == priv->dma_nelms) {
  154. /* The last transfer waits for the PCAP to finish too,
  155. * notice this also changes the irq_mask to ignore
  156. * IXR_DMA_DONE_MASK which ensures we do not trigger
  157. * the completion too early.
  158. */
  159. addr |= DMA_SRC_LAST_TRANSFER;
  160. priv->cur_sg = NULL;
  161. } else {
  162. priv->cur_sg = sg_next(priv->cur_sg);
  163. priv->dma_elm++;
  164. }
  165. zynq_fpga_write(priv, DMA_SRC_ADDR_OFFSET, addr);
  166. zynq_fpga_write(priv, DMA_DST_ADDR_OFFSET, DMA_INVALID_ADDRESS);
  167. zynq_fpga_write(priv, DMA_SRC_LEN_OFFSET, len / 4);
  168. zynq_fpga_write(priv, DMA_DEST_LEN_OFFSET, 0);
  169. }
  170. /* Once the first transfer is queued we can turn on the ISR, future
  171. * calls to zynq_step_dma will happen from the ISR context. The
  172. * dma_lock spinlock guarentees this handover is done coherently, the
  173. * ISR enable is put at the end to avoid another CPU spinning in the
  174. * ISR on this lock.
  175. */
  176. if (first && priv->cur_sg) {
  177. zynq_fpga_set_irq(priv,
  178. IXR_DMA_DONE_MASK | IXR_ERROR_FLAGS_MASK);
  179. } else if (!priv->cur_sg) {
  180. /* The last transfer changes to DMA & PCAP mode since we do
  181. * not want to continue until everything has been flushed into
  182. * the PCAP.
  183. */
  184. zynq_fpga_set_irq(priv,
  185. IXR_D_P_DONE_MASK | IXR_ERROR_FLAGS_MASK);
  186. }
  187. }
  188. static irqreturn_t zynq_fpga_isr(int irq, void *data)
  189. {
  190. struct zynq_fpga_priv *priv = data;
  191. u32 intr_status;
  192. /* If anything other than DMA completion is reported stop and hand
  193. * control back to zynq_fpga_ops_write, something went wrong,
  194. * otherwise progress the DMA.
  195. */
  196. spin_lock(&priv->dma_lock);
  197. intr_status = zynq_fpga_read(priv, INT_STS_OFFSET);
  198. if (!(intr_status & IXR_ERROR_FLAGS_MASK) &&
  199. (intr_status & IXR_DMA_DONE_MASK) && priv->cur_sg) {
  200. zynq_fpga_write(priv, INT_STS_OFFSET, IXR_DMA_DONE_MASK);
  201. zynq_step_dma(priv);
  202. spin_unlock(&priv->dma_lock);
  203. return IRQ_HANDLED;
  204. }
  205. spin_unlock(&priv->dma_lock);
  206. zynq_fpga_set_irq(priv, 0);
  207. complete(&priv->dma_done);
  208. return IRQ_HANDLED;
  209. }
  210. /* Sanity check the proposed bitstream. It must start with the sync word in
  211. * the correct byte order, and be dword aligned. The input is a Xilinx .bin
  212. * file with every 32 bit quantity swapped.
  213. */
  214. static bool zynq_fpga_has_sync(const u8 *buf, size_t count)
  215. {
  216. for (; count >= 4; buf += 4, count -= 4)
  217. if (buf[0] == 0x66 && buf[1] == 0x55 && buf[2] == 0x99 &&
  218. buf[3] == 0xaa)
  219. return true;
  220. return false;
  221. }
  222. static int zynq_fpga_ops_write_init(struct fpga_manager *mgr,
  223. struct fpga_image_info *info,
  224. const char *buf, size_t count)
  225. {
  226. struct zynq_fpga_priv *priv;
  227. u32 ctrl, status;
  228. int err;
  229. priv = mgr->priv;
  230. err = clk_enable(priv->clk);
  231. if (err)
  232. return err;
  233. /* don't globally reset PL if we're doing partial reconfig */
  234. if (!(info->flags & FPGA_MGR_PARTIAL_RECONFIG)) {
  235. if (!zynq_fpga_has_sync(buf, count)) {
  236. dev_err(&mgr->dev,
  237. "Invalid bitstream, could not find a sync word. Bitstream must be a byte swapped .bin file\n");
  238. err = -EINVAL;
  239. goto out_err;
  240. }
  241. /* assert AXI interface resets */
  242. regmap_write(priv->slcr, SLCR_FPGA_RST_CTRL_OFFSET,
  243. FPGA_RST_ALL_MASK);
  244. /* disable all level shifters */
  245. regmap_write(priv->slcr, SLCR_LVL_SHFTR_EN_OFFSET,
  246. LVL_SHFTR_DISABLE_ALL_MASK);
  247. /* enable level shifters from PS to PL */
  248. regmap_write(priv->slcr, SLCR_LVL_SHFTR_EN_OFFSET,
  249. LVL_SHFTR_ENABLE_PS_TO_PL);
  250. /* create a rising edge on PCFG_INIT. PCFG_INIT follows
  251. * PCFG_PROG_B, so we need to poll it after setting PCFG_PROG_B
  252. * to make sure the rising edge actually happens.
  253. * Note: PCFG_PROG_B is low active, sequence as described in
  254. * UG585 v1.10 page 211
  255. */
  256. ctrl = zynq_fpga_read(priv, CTRL_OFFSET);
  257. ctrl |= CTRL_PCFG_PROG_B_MASK;
  258. zynq_fpga_write(priv, CTRL_OFFSET, ctrl);
  259. err = zynq_fpga_poll_timeout(priv, STATUS_OFFSET, status,
  260. status & STATUS_PCFG_INIT_MASK,
  261. INIT_POLL_DELAY,
  262. INIT_POLL_TIMEOUT);
  263. if (err) {
  264. dev_err(&mgr->dev, "Timeout waiting for PCFG_INIT\n");
  265. goto out_err;
  266. }
  267. ctrl = zynq_fpga_read(priv, CTRL_OFFSET);
  268. ctrl &= ~CTRL_PCFG_PROG_B_MASK;
  269. zynq_fpga_write(priv, CTRL_OFFSET, ctrl);
  270. err = zynq_fpga_poll_timeout(priv, STATUS_OFFSET, status,
  271. !(status & STATUS_PCFG_INIT_MASK),
  272. INIT_POLL_DELAY,
  273. INIT_POLL_TIMEOUT);
  274. if (err) {
  275. dev_err(&mgr->dev, "Timeout waiting for !PCFG_INIT\n");
  276. goto out_err;
  277. }
  278. ctrl = zynq_fpga_read(priv, CTRL_OFFSET);
  279. ctrl |= CTRL_PCFG_PROG_B_MASK;
  280. zynq_fpga_write(priv, CTRL_OFFSET, ctrl);
  281. err = zynq_fpga_poll_timeout(priv, STATUS_OFFSET, status,
  282. status & STATUS_PCFG_INIT_MASK,
  283. INIT_POLL_DELAY,
  284. INIT_POLL_TIMEOUT);
  285. if (err) {
  286. dev_err(&mgr->dev, "Timeout waiting for PCFG_INIT\n");
  287. goto out_err;
  288. }
  289. }
  290. /* set configuration register with following options:
  291. * - enable PCAP interface
  292. * - set throughput for maximum speed
  293. * - set CPU in user mode
  294. */
  295. ctrl = zynq_fpga_read(priv, CTRL_OFFSET);
  296. zynq_fpga_write(priv, CTRL_OFFSET,
  297. (CTRL_PCAP_PR_MASK | CTRL_PCAP_MODE_MASK | ctrl));
  298. /* We expect that the command queue is empty right now. */
  299. status = zynq_fpga_read(priv, STATUS_OFFSET);
  300. if ((status & STATUS_DMA_Q_F) ||
  301. (status & STATUS_DMA_Q_E) != STATUS_DMA_Q_E) {
  302. dev_err(&mgr->dev, "DMA command queue not right\n");
  303. err = -EBUSY;
  304. goto out_err;
  305. }
  306. /* ensure internal PCAP loopback is disabled */
  307. ctrl = zynq_fpga_read(priv, MCTRL_OFFSET);
  308. zynq_fpga_write(priv, MCTRL_OFFSET, (~MCTRL_PCAP_LPBK_MASK & ctrl));
  309. clk_disable(priv->clk);
  310. return 0;
  311. out_err:
  312. clk_disable(priv->clk);
  313. return err;
  314. }
  315. static int zynq_fpga_ops_write(struct fpga_manager *mgr, struct sg_table *sgt)
  316. {
  317. struct zynq_fpga_priv *priv;
  318. const char *why;
  319. int err;
  320. u32 intr_status;
  321. unsigned long timeout;
  322. unsigned long flags;
  323. struct scatterlist *sg;
  324. int i;
  325. priv = mgr->priv;
  326. /* The hardware can only DMA multiples of 4 bytes, and it requires the
  327. * starting addresses to be aligned to 64 bits (UG585 pg 212).
  328. */
  329. for_each_sg(sgt->sgl, sg, sgt->nents, i) {
  330. if ((sg->offset % 8) || (sg->length % 4)) {
  331. dev_err(&mgr->dev,
  332. "Invalid bitstream, chunks must be aligned\n");
  333. return -EINVAL;
  334. }
  335. }
  336. priv->dma_nelms =
  337. dma_map_sg(mgr->dev.parent, sgt->sgl, sgt->nents, DMA_TO_DEVICE);
  338. if (priv->dma_nelms == 0) {
  339. dev_err(&mgr->dev, "Unable to DMA map (TO_DEVICE)\n");
  340. return -ENOMEM;
  341. }
  342. /* enable clock */
  343. err = clk_enable(priv->clk);
  344. if (err)
  345. goto out_free;
  346. zynq_fpga_write(priv, INT_STS_OFFSET, IXR_ALL_MASK);
  347. reinit_completion(&priv->dma_done);
  348. /* zynq_step_dma will turn on interrupts */
  349. spin_lock_irqsave(&priv->dma_lock, flags);
  350. priv->dma_elm = 0;
  351. priv->cur_sg = sgt->sgl;
  352. zynq_step_dma(priv);
  353. spin_unlock_irqrestore(&priv->dma_lock, flags);
  354. timeout = wait_for_completion_timeout(&priv->dma_done,
  355. msecs_to_jiffies(DMA_TIMEOUT_MS));
  356. spin_lock_irqsave(&priv->dma_lock, flags);
  357. zynq_fpga_set_irq(priv, 0);
  358. priv->cur_sg = NULL;
  359. spin_unlock_irqrestore(&priv->dma_lock, flags);
  360. intr_status = zynq_fpga_read(priv, INT_STS_OFFSET);
  361. zynq_fpga_write(priv, INT_STS_OFFSET, IXR_ALL_MASK);
  362. /* There doesn't seem to be a way to force cancel any DMA, so if
  363. * something went wrong we are relying on the hardware to have halted
  364. * the DMA before we get here, if there was we could use
  365. * wait_for_completion_interruptible too.
  366. */
  367. if (intr_status & IXR_ERROR_FLAGS_MASK) {
  368. why = "DMA reported error";
  369. err = -EIO;
  370. goto out_report;
  371. }
  372. if (priv->cur_sg ||
  373. !((intr_status & IXR_D_P_DONE_MASK) == IXR_D_P_DONE_MASK)) {
  374. if (timeout == 0)
  375. why = "DMA timed out";
  376. else
  377. why = "DMA did not complete";
  378. err = -EIO;
  379. goto out_report;
  380. }
  381. err = 0;
  382. goto out_clk;
  383. out_report:
  384. dev_err(&mgr->dev,
  385. "%s: INT_STS:0x%x CTRL:0x%x LOCK:0x%x INT_MASK:0x%x STATUS:0x%x MCTRL:0x%x\n",
  386. why,
  387. intr_status,
  388. zynq_fpga_read(priv, CTRL_OFFSET),
  389. zynq_fpga_read(priv, LOCK_OFFSET),
  390. zynq_fpga_read(priv, INT_MASK_OFFSET),
  391. zynq_fpga_read(priv, STATUS_OFFSET),
  392. zynq_fpga_read(priv, MCTRL_OFFSET));
  393. out_clk:
  394. clk_disable(priv->clk);
  395. out_free:
  396. dma_unmap_sg(mgr->dev.parent, sgt->sgl, sgt->nents, DMA_TO_DEVICE);
  397. return err;
  398. }
  399. static int zynq_fpga_ops_write_complete(struct fpga_manager *mgr,
  400. struct fpga_image_info *info)
  401. {
  402. struct zynq_fpga_priv *priv = mgr->priv;
  403. int err;
  404. u32 intr_status;
  405. err = clk_enable(priv->clk);
  406. if (err)
  407. return err;
  408. err = zynq_fpga_poll_timeout(priv, INT_STS_OFFSET, intr_status,
  409. intr_status & IXR_PCFG_DONE_MASK,
  410. INIT_POLL_DELAY,
  411. INIT_POLL_TIMEOUT);
  412. clk_disable(priv->clk);
  413. if (err)
  414. return err;
  415. /* for the partial reconfig case we didn't touch the level shifters */
  416. if (!(info->flags & FPGA_MGR_PARTIAL_RECONFIG)) {
  417. /* enable level shifters from PL to PS */
  418. regmap_write(priv->slcr, SLCR_LVL_SHFTR_EN_OFFSET,
  419. LVL_SHFTR_ENABLE_PL_TO_PS);
  420. /* deassert AXI interface resets */
  421. regmap_write(priv->slcr, SLCR_FPGA_RST_CTRL_OFFSET,
  422. FPGA_RST_NONE_MASK);
  423. }
  424. return 0;
  425. }
  426. static enum fpga_mgr_states zynq_fpga_ops_state(struct fpga_manager *mgr)
  427. {
  428. int err;
  429. u32 intr_status;
  430. struct zynq_fpga_priv *priv;
  431. priv = mgr->priv;
  432. err = clk_enable(priv->clk);
  433. if (err)
  434. return FPGA_MGR_STATE_UNKNOWN;
  435. intr_status = zynq_fpga_read(priv, INT_STS_OFFSET);
  436. clk_disable(priv->clk);
  437. if (intr_status & IXR_PCFG_DONE_MASK)
  438. return FPGA_MGR_STATE_OPERATING;
  439. return FPGA_MGR_STATE_UNKNOWN;
  440. }
  441. static const struct fpga_manager_ops zynq_fpga_ops = {
  442. .initial_header_size = 128,
  443. .state = zynq_fpga_ops_state,
  444. .write_init = zynq_fpga_ops_write_init,
  445. .write_sg = zynq_fpga_ops_write,
  446. .write_complete = zynq_fpga_ops_write_complete,
  447. };
  448. static int zynq_fpga_probe(struct platform_device *pdev)
  449. {
  450. struct device *dev = &pdev->dev;
  451. struct zynq_fpga_priv *priv;
  452. struct resource *res;
  453. int err;
  454. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  455. if (!priv)
  456. return -ENOMEM;
  457. spin_lock_init(&priv->dma_lock);
  458. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  459. priv->io_base = devm_ioremap_resource(dev, res);
  460. if (IS_ERR(priv->io_base))
  461. return PTR_ERR(priv->io_base);
  462. priv->slcr = syscon_regmap_lookup_by_phandle(dev->of_node,
  463. "syscon");
  464. if (IS_ERR(priv->slcr)) {
  465. dev_err(dev, "unable to get zynq-slcr regmap\n");
  466. return PTR_ERR(priv->slcr);
  467. }
  468. init_completion(&priv->dma_done);
  469. priv->irq = platform_get_irq(pdev, 0);
  470. if (priv->irq < 0) {
  471. dev_err(dev, "No IRQ available\n");
  472. return priv->irq;
  473. }
  474. priv->clk = devm_clk_get(dev, "ref_clk");
  475. if (IS_ERR(priv->clk)) {
  476. dev_err(dev, "input clock not found\n");
  477. return PTR_ERR(priv->clk);
  478. }
  479. err = clk_prepare_enable(priv->clk);
  480. if (err) {
  481. dev_err(dev, "unable to enable clock\n");
  482. return err;
  483. }
  484. /* unlock the device */
  485. zynq_fpga_write(priv, UNLOCK_OFFSET, UNLOCK_MASK);
  486. zynq_fpga_set_irq(priv, 0);
  487. zynq_fpga_write(priv, INT_STS_OFFSET, IXR_ALL_MASK);
  488. err = devm_request_irq(dev, priv->irq, zynq_fpga_isr, 0, dev_name(dev),
  489. priv);
  490. if (err) {
  491. dev_err(dev, "unable to request IRQ\n");
  492. clk_disable_unprepare(priv->clk);
  493. return err;
  494. }
  495. clk_disable(priv->clk);
  496. err = fpga_mgr_register(dev, "Xilinx Zynq FPGA Manager",
  497. &zynq_fpga_ops, priv);
  498. if (err) {
  499. dev_err(dev, "unable to register FPGA manager\n");
  500. clk_unprepare(priv->clk);
  501. return err;
  502. }
  503. return 0;
  504. }
  505. static int zynq_fpga_remove(struct platform_device *pdev)
  506. {
  507. struct zynq_fpga_priv *priv;
  508. struct fpga_manager *mgr;
  509. mgr = platform_get_drvdata(pdev);
  510. priv = mgr->priv;
  511. fpga_mgr_unregister(&pdev->dev);
  512. clk_unprepare(priv->clk);
  513. return 0;
  514. }
  515. #ifdef CONFIG_OF
  516. static const struct of_device_id zynq_fpga_of_match[] = {
  517. { .compatible = "xlnx,zynq-devcfg-1.0", },
  518. {},
  519. };
  520. MODULE_DEVICE_TABLE(of, zynq_fpga_of_match);
  521. #endif
  522. static struct platform_driver zynq_fpga_driver = {
  523. .probe = zynq_fpga_probe,
  524. .remove = zynq_fpga_remove,
  525. .driver = {
  526. .name = "zynq_fpga_manager",
  527. .of_match_table = of_match_ptr(zynq_fpga_of_match),
  528. },
  529. };
  530. module_platform_driver(zynq_fpga_driver);
  531. MODULE_AUTHOR("Moritz Fischer <moritz.fischer@ettus.com>");
  532. MODULE_AUTHOR("Michal Simek <michal.simek@xilinx.com>");
  533. MODULE_DESCRIPTION("Xilinx Zynq FPGA Manager");
  534. MODULE_LICENSE("GPL v2");