socfpga-a10.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. /*
  2. * FPGA Manager Driver for Altera Arria10 SoCFPGA
  3. *
  4. * Copyright (C) 2015-2016 Altera Corporation
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <linux/clk.h>
  19. #include <linux/device.h>
  20. #include <linux/delay.h>
  21. #include <linux/fpga/fpga-mgr.h>
  22. #include <linux/io.h>
  23. #include <linux/module.h>
  24. #include <linux/of_address.h>
  25. #include <linux/regmap.h>
  26. #define A10_FPGAMGR_DCLKCNT_OFST 0x08
  27. #define A10_FPGAMGR_DCLKSTAT_OFST 0x0c
  28. #define A10_FPGAMGR_IMGCFG_CTL_00_OFST 0x70
  29. #define A10_FPGAMGR_IMGCFG_CTL_01_OFST 0x74
  30. #define A10_FPGAMGR_IMGCFG_CTL_02_OFST 0x78
  31. #define A10_FPGAMGR_IMGCFG_STAT_OFST 0x80
  32. #define A10_FPGAMGR_DCLKSTAT_DCLKDONE BIT(0)
  33. #define A10_FPGAMGR_IMGCFG_CTL_00_S2F_NENABLE_NCONFIG BIT(0)
  34. #define A10_FPGAMGR_IMGCFG_CTL_00_S2F_NENABLE_NSTATUS BIT(1)
  35. #define A10_FPGAMGR_IMGCFG_CTL_00_S2F_NENABLE_CONDONE BIT(2)
  36. #define A10_FPGAMGR_IMGCFG_CTL_00_S2F_NCONFIG BIT(8)
  37. #define A10_FPGAMGR_IMGCFG_CTL_00_S2F_NSTATUS_OE BIT(16)
  38. #define A10_FPGAMGR_IMGCFG_CTL_00_S2F_CONDONE_OE BIT(24)
  39. #define A10_FPGAMGR_IMGCFG_CTL_01_S2F_NENABLE_CONFIG BIT(0)
  40. #define A10_FPGAMGR_IMGCFG_CTL_01_S2F_PR_REQUEST BIT(16)
  41. #define A10_FPGAMGR_IMGCFG_CTL_01_S2F_NCE BIT(24)
  42. #define A10_FPGAMGR_IMGCFG_CTL_02_EN_CFG_CTRL BIT(0)
  43. #define A10_FPGAMGR_IMGCFG_CTL_02_CDRATIO_MASK (BIT(16) | BIT(17))
  44. #define A10_FPGAMGR_IMGCFG_CTL_02_CDRATIO_SHIFT 16
  45. #define A10_FPGAMGR_IMGCFG_CTL_02_CFGWIDTH BIT(24)
  46. #define A10_FPGAMGR_IMGCFG_CTL_02_CFGWIDTH_SHIFT 24
  47. #define A10_FPGAMGR_IMGCFG_STAT_F2S_CRC_ERROR BIT(0)
  48. #define A10_FPGAMGR_IMGCFG_STAT_F2S_EARLY_USERMODE BIT(1)
  49. #define A10_FPGAMGR_IMGCFG_STAT_F2S_USERMODE BIT(2)
  50. #define A10_FPGAMGR_IMGCFG_STAT_F2S_NSTATUS_PIN BIT(4)
  51. #define A10_FPGAMGR_IMGCFG_STAT_F2S_CONDONE_PIN BIT(6)
  52. #define A10_FPGAMGR_IMGCFG_STAT_F2S_PR_READY BIT(9)
  53. #define A10_FPGAMGR_IMGCFG_STAT_F2S_PR_DONE BIT(10)
  54. #define A10_FPGAMGR_IMGCFG_STAT_F2S_PR_ERROR BIT(11)
  55. #define A10_FPGAMGR_IMGCFG_STAT_F2S_NCONFIG_PIN BIT(12)
  56. #define A10_FPGAMGR_IMGCFG_STAT_F2S_MSEL_MASK (BIT(16) | BIT(17) | BIT(18))
  57. #define A10_FPGAMGR_IMGCFG_STAT_F2S_MSEL_SHIFT 16
  58. /* FPGA CD Ratio Value */
  59. #define CDRATIO_x1 0x0
  60. #define CDRATIO_x2 0x1
  61. #define CDRATIO_x4 0x2
  62. #define CDRATIO_x8 0x3
  63. /* Configuration width 16/32 bit */
  64. #define CFGWDTH_32 1
  65. #define CFGWDTH_16 0
  66. /*
  67. * struct a10_fpga_priv - private data for fpga manager
  68. * @regmap: regmap for register access
  69. * @fpga_data_addr: iomap for single address data register to FPGA
  70. * @clk: clock
  71. */
  72. struct a10_fpga_priv {
  73. struct regmap *regmap;
  74. void __iomem *fpga_data_addr;
  75. struct clk *clk;
  76. };
  77. static bool socfpga_a10_fpga_writeable_reg(struct device *dev, unsigned int reg)
  78. {
  79. switch (reg) {
  80. case A10_FPGAMGR_DCLKCNT_OFST:
  81. case A10_FPGAMGR_DCLKSTAT_OFST:
  82. case A10_FPGAMGR_IMGCFG_CTL_00_OFST:
  83. case A10_FPGAMGR_IMGCFG_CTL_01_OFST:
  84. case A10_FPGAMGR_IMGCFG_CTL_02_OFST:
  85. return true;
  86. }
  87. return false;
  88. }
  89. static bool socfpga_a10_fpga_readable_reg(struct device *dev, unsigned int reg)
  90. {
  91. switch (reg) {
  92. case A10_FPGAMGR_DCLKCNT_OFST:
  93. case A10_FPGAMGR_DCLKSTAT_OFST:
  94. case A10_FPGAMGR_IMGCFG_CTL_00_OFST:
  95. case A10_FPGAMGR_IMGCFG_CTL_01_OFST:
  96. case A10_FPGAMGR_IMGCFG_CTL_02_OFST:
  97. case A10_FPGAMGR_IMGCFG_STAT_OFST:
  98. return true;
  99. }
  100. return false;
  101. }
  102. static const struct regmap_config socfpga_a10_fpga_regmap_config = {
  103. .reg_bits = 32,
  104. .reg_stride = 4,
  105. .val_bits = 32,
  106. .writeable_reg = socfpga_a10_fpga_writeable_reg,
  107. .readable_reg = socfpga_a10_fpga_readable_reg,
  108. .max_register = A10_FPGAMGR_IMGCFG_STAT_OFST,
  109. .cache_type = REGCACHE_NONE,
  110. };
  111. /*
  112. * from the register map description of cdratio in imgcfg_ctrl_02:
  113. * Normal Configuration : 32bit Passive Parallel
  114. * Partial Reconfiguration : 16bit Passive Parallel
  115. */
  116. static void socfpga_a10_fpga_set_cfg_width(struct a10_fpga_priv *priv,
  117. int width)
  118. {
  119. width <<= A10_FPGAMGR_IMGCFG_CTL_02_CFGWIDTH_SHIFT;
  120. regmap_update_bits(priv->regmap, A10_FPGAMGR_IMGCFG_CTL_02_OFST,
  121. A10_FPGAMGR_IMGCFG_CTL_02_CFGWIDTH, width);
  122. }
  123. static void socfpga_a10_fpga_generate_dclks(struct a10_fpga_priv *priv,
  124. u32 count)
  125. {
  126. u32 val;
  127. /* Clear any existing DONE status. */
  128. regmap_write(priv->regmap, A10_FPGAMGR_DCLKSTAT_OFST,
  129. A10_FPGAMGR_DCLKSTAT_DCLKDONE);
  130. /* Issue the DCLK regmap. */
  131. regmap_write(priv->regmap, A10_FPGAMGR_DCLKCNT_OFST, count);
  132. /* wait till the dclkcnt done */
  133. regmap_read_poll_timeout(priv->regmap, A10_FPGAMGR_DCLKSTAT_OFST, val,
  134. val, 1, 100);
  135. /* Clear DONE status. */
  136. regmap_write(priv->regmap, A10_FPGAMGR_DCLKSTAT_OFST,
  137. A10_FPGAMGR_DCLKSTAT_DCLKDONE);
  138. }
  139. #define RBF_ENCRYPTION_MODE_OFFSET 69
  140. #define RBF_DECOMPRESS_OFFSET 229
  141. static int socfpga_a10_fpga_encrypted(u32 *buf32, size_t buf32_size)
  142. {
  143. if (buf32_size < RBF_ENCRYPTION_MODE_OFFSET + 1)
  144. return -EINVAL;
  145. /* Is the bitstream encrypted? */
  146. return ((buf32[RBF_ENCRYPTION_MODE_OFFSET] >> 2) & 3) != 0;
  147. }
  148. static int socfpga_a10_fpga_compressed(u32 *buf32, size_t buf32_size)
  149. {
  150. if (buf32_size < RBF_DECOMPRESS_OFFSET + 1)
  151. return -EINVAL;
  152. /* Is the bitstream compressed? */
  153. return !((buf32[RBF_DECOMPRESS_OFFSET] >> 1) & 1);
  154. }
  155. static unsigned int socfpga_a10_fpga_get_cd_ratio(unsigned int cfg_width,
  156. bool encrypt, bool compress)
  157. {
  158. unsigned int cd_ratio;
  159. /*
  160. * cd ratio is dependent on cfg width and whether the bitstream
  161. * is encrypted and/or compressed.
  162. *
  163. * | width | encr. | compr. | cd ratio |
  164. * | 16 | 0 | 0 | 1 |
  165. * | 16 | 0 | 1 | 4 |
  166. * | 16 | 1 | 0 | 2 |
  167. * | 16 | 1 | 1 | 4 |
  168. * | 32 | 0 | 0 | 1 |
  169. * | 32 | 0 | 1 | 8 |
  170. * | 32 | 1 | 0 | 4 |
  171. * | 32 | 1 | 1 | 8 |
  172. */
  173. if (!compress && !encrypt)
  174. return CDRATIO_x1;
  175. if (compress)
  176. cd_ratio = CDRATIO_x4;
  177. else
  178. cd_ratio = CDRATIO_x2;
  179. /* If 32 bit, double the cd ratio by incrementing the field */
  180. if (cfg_width == CFGWDTH_32)
  181. cd_ratio += 1;
  182. return cd_ratio;
  183. }
  184. static int socfpga_a10_fpga_set_cdratio(struct fpga_manager *mgr,
  185. unsigned int cfg_width,
  186. const char *buf, size_t count)
  187. {
  188. struct a10_fpga_priv *priv = mgr->priv;
  189. unsigned int cd_ratio;
  190. int encrypt, compress;
  191. encrypt = socfpga_a10_fpga_encrypted((u32 *)buf, count / 4);
  192. if (encrypt < 0)
  193. return -EINVAL;
  194. compress = socfpga_a10_fpga_compressed((u32 *)buf, count / 4);
  195. if (compress < 0)
  196. return -EINVAL;
  197. cd_ratio = socfpga_a10_fpga_get_cd_ratio(cfg_width, encrypt, compress);
  198. regmap_update_bits(priv->regmap, A10_FPGAMGR_IMGCFG_CTL_02_OFST,
  199. A10_FPGAMGR_IMGCFG_CTL_02_CDRATIO_MASK,
  200. cd_ratio << A10_FPGAMGR_IMGCFG_CTL_02_CDRATIO_SHIFT);
  201. return 0;
  202. }
  203. static u32 socfpga_a10_fpga_read_stat(struct a10_fpga_priv *priv)
  204. {
  205. u32 val;
  206. regmap_read(priv->regmap, A10_FPGAMGR_IMGCFG_STAT_OFST, &val);
  207. return val;
  208. }
  209. static int socfpga_a10_fpga_wait_for_pr_ready(struct a10_fpga_priv *priv)
  210. {
  211. u32 reg, i;
  212. for (i = 0; i < 10 ; i++) {
  213. reg = socfpga_a10_fpga_read_stat(priv);
  214. if (reg & A10_FPGAMGR_IMGCFG_STAT_F2S_PR_ERROR)
  215. return -EINVAL;
  216. if (reg & A10_FPGAMGR_IMGCFG_STAT_F2S_PR_READY)
  217. return 0;
  218. }
  219. return -ETIMEDOUT;
  220. }
  221. static int socfpga_a10_fpga_wait_for_pr_done(struct a10_fpga_priv *priv)
  222. {
  223. u32 reg, i;
  224. for (i = 0; i < 10 ; i++) {
  225. reg = socfpga_a10_fpga_read_stat(priv);
  226. if (reg & A10_FPGAMGR_IMGCFG_STAT_F2S_PR_ERROR)
  227. return -EINVAL;
  228. if (reg & A10_FPGAMGR_IMGCFG_STAT_F2S_PR_DONE)
  229. return 0;
  230. }
  231. return -ETIMEDOUT;
  232. }
  233. /* Start the FPGA programming by initialize the FPGA Manager */
  234. static int socfpga_a10_fpga_write_init(struct fpga_manager *mgr,
  235. struct fpga_image_info *info,
  236. const char *buf, size_t count)
  237. {
  238. struct a10_fpga_priv *priv = mgr->priv;
  239. unsigned int cfg_width;
  240. u32 msel, stat, mask;
  241. int ret;
  242. if (info->flags & FPGA_MGR_PARTIAL_RECONFIG)
  243. cfg_width = CFGWDTH_16;
  244. else
  245. return -EINVAL;
  246. /* Check for passive parallel (msel == 000 or 001) */
  247. msel = socfpga_a10_fpga_read_stat(priv);
  248. msel &= A10_FPGAMGR_IMGCFG_STAT_F2S_MSEL_MASK;
  249. msel >>= A10_FPGAMGR_IMGCFG_STAT_F2S_MSEL_SHIFT;
  250. if ((msel != 0) && (msel != 1)) {
  251. dev_dbg(&mgr->dev, "Fail: invalid msel=%d\n", msel);
  252. return -EINVAL;
  253. }
  254. /* Make sure no external devices are interfering */
  255. stat = socfpga_a10_fpga_read_stat(priv);
  256. mask = A10_FPGAMGR_IMGCFG_STAT_F2S_NCONFIG_PIN |
  257. A10_FPGAMGR_IMGCFG_STAT_F2S_NSTATUS_PIN;
  258. if ((stat & mask) != mask)
  259. return -EINVAL;
  260. /* Set cfg width */
  261. socfpga_a10_fpga_set_cfg_width(priv, cfg_width);
  262. /* Determine cd ratio from bitstream header and set cd ratio */
  263. ret = socfpga_a10_fpga_set_cdratio(mgr, cfg_width, buf, count);
  264. if (ret)
  265. return ret;
  266. /*
  267. * Clear s2f_nce to enable chip select. Leave pr_request
  268. * unasserted and override disabled.
  269. */
  270. regmap_write(priv->regmap, A10_FPGAMGR_IMGCFG_CTL_01_OFST,
  271. A10_FPGAMGR_IMGCFG_CTL_01_S2F_NENABLE_CONFIG);
  272. /* Set cfg_ctrl to enable s2f dclk and data */
  273. regmap_update_bits(priv->regmap, A10_FPGAMGR_IMGCFG_CTL_02_OFST,
  274. A10_FPGAMGR_IMGCFG_CTL_02_EN_CFG_CTRL,
  275. A10_FPGAMGR_IMGCFG_CTL_02_EN_CFG_CTRL);
  276. /*
  277. * Disable overrides not needed for pr.
  278. * s2f_config==1 leaves reset deasseted.
  279. */
  280. regmap_write(priv->regmap, A10_FPGAMGR_IMGCFG_CTL_00_OFST,
  281. A10_FPGAMGR_IMGCFG_CTL_00_S2F_NENABLE_NCONFIG |
  282. A10_FPGAMGR_IMGCFG_CTL_00_S2F_NENABLE_NSTATUS |
  283. A10_FPGAMGR_IMGCFG_CTL_00_S2F_NENABLE_CONDONE |
  284. A10_FPGAMGR_IMGCFG_CTL_00_S2F_NCONFIG);
  285. /* Enable override for data, dclk, nce, and pr_request to CSS */
  286. regmap_update_bits(priv->regmap, A10_FPGAMGR_IMGCFG_CTL_01_OFST,
  287. A10_FPGAMGR_IMGCFG_CTL_01_S2F_NENABLE_CONFIG, 0);
  288. /* Send some clocks to clear out any errors */
  289. socfpga_a10_fpga_generate_dclks(priv, 256);
  290. /* Assert pr_request */
  291. regmap_update_bits(priv->regmap, A10_FPGAMGR_IMGCFG_CTL_01_OFST,
  292. A10_FPGAMGR_IMGCFG_CTL_01_S2F_PR_REQUEST,
  293. A10_FPGAMGR_IMGCFG_CTL_01_S2F_PR_REQUEST);
  294. /* Provide 2048 DCLKs before starting the config data streaming. */
  295. socfpga_a10_fpga_generate_dclks(priv, 0x7ff);
  296. /* Wait for pr_ready */
  297. return socfpga_a10_fpga_wait_for_pr_ready(priv);
  298. }
  299. /*
  300. * write data to the FPGA data register
  301. */
  302. static int socfpga_a10_fpga_write(struct fpga_manager *mgr, const char *buf,
  303. size_t count)
  304. {
  305. struct a10_fpga_priv *priv = mgr->priv;
  306. u32 *buffer_32 = (u32 *)buf;
  307. size_t i = 0;
  308. if (count <= 0)
  309. return -EINVAL;
  310. /* Write out the complete 32-bit chunks */
  311. while (count >= sizeof(u32)) {
  312. writel(buffer_32[i++], priv->fpga_data_addr);
  313. count -= sizeof(u32);
  314. }
  315. /* Write out remaining non 32-bit chunks */
  316. switch (count) {
  317. case 3:
  318. writel(buffer_32[i++] & 0x00ffffff, priv->fpga_data_addr);
  319. break;
  320. case 2:
  321. writel(buffer_32[i++] & 0x0000ffff, priv->fpga_data_addr);
  322. break;
  323. case 1:
  324. writel(buffer_32[i++] & 0x000000ff, priv->fpga_data_addr);
  325. break;
  326. case 0:
  327. break;
  328. default:
  329. /* This will never happen */
  330. return -EFAULT;
  331. }
  332. return 0;
  333. }
  334. static int socfpga_a10_fpga_write_complete(struct fpga_manager *mgr,
  335. struct fpga_image_info *info)
  336. {
  337. struct a10_fpga_priv *priv = mgr->priv;
  338. u32 reg;
  339. int ret;
  340. /* Wait for pr_done */
  341. ret = socfpga_a10_fpga_wait_for_pr_done(priv);
  342. /* Clear pr_request */
  343. regmap_update_bits(priv->regmap, A10_FPGAMGR_IMGCFG_CTL_01_OFST,
  344. A10_FPGAMGR_IMGCFG_CTL_01_S2F_PR_REQUEST, 0);
  345. /* Send some clocks to clear out any errors */
  346. socfpga_a10_fpga_generate_dclks(priv, 256);
  347. /* Disable s2f dclk and data */
  348. regmap_update_bits(priv->regmap, A10_FPGAMGR_IMGCFG_CTL_02_OFST,
  349. A10_FPGAMGR_IMGCFG_CTL_02_EN_CFG_CTRL, 0);
  350. /* Deassert chip select */
  351. regmap_update_bits(priv->regmap, A10_FPGAMGR_IMGCFG_CTL_01_OFST,
  352. A10_FPGAMGR_IMGCFG_CTL_01_S2F_NCE,
  353. A10_FPGAMGR_IMGCFG_CTL_01_S2F_NCE);
  354. /* Disable data, dclk, nce, and pr_request override to CSS */
  355. regmap_update_bits(priv->regmap, A10_FPGAMGR_IMGCFG_CTL_01_OFST,
  356. A10_FPGAMGR_IMGCFG_CTL_01_S2F_NENABLE_CONFIG,
  357. A10_FPGAMGR_IMGCFG_CTL_01_S2F_NENABLE_CONFIG);
  358. /* Return any errors regarding pr_done or pr_error */
  359. if (ret)
  360. return ret;
  361. /* Final check */
  362. reg = socfpga_a10_fpga_read_stat(priv);
  363. if (((reg & A10_FPGAMGR_IMGCFG_STAT_F2S_USERMODE) == 0) ||
  364. ((reg & A10_FPGAMGR_IMGCFG_STAT_F2S_CONDONE_PIN) == 0) ||
  365. ((reg & A10_FPGAMGR_IMGCFG_STAT_F2S_NSTATUS_PIN) == 0)) {
  366. dev_dbg(&mgr->dev,
  367. "Timeout in final check. Status=%08xf\n", reg);
  368. return -ETIMEDOUT;
  369. }
  370. return 0;
  371. }
  372. static enum fpga_mgr_states socfpga_a10_fpga_state(struct fpga_manager *mgr)
  373. {
  374. struct a10_fpga_priv *priv = mgr->priv;
  375. u32 reg = socfpga_a10_fpga_read_stat(priv);
  376. if (reg & A10_FPGAMGR_IMGCFG_STAT_F2S_USERMODE)
  377. return FPGA_MGR_STATE_OPERATING;
  378. if (reg & A10_FPGAMGR_IMGCFG_STAT_F2S_PR_READY)
  379. return FPGA_MGR_STATE_WRITE;
  380. if (reg & A10_FPGAMGR_IMGCFG_STAT_F2S_CRC_ERROR)
  381. return FPGA_MGR_STATE_WRITE_COMPLETE_ERR;
  382. if ((reg & A10_FPGAMGR_IMGCFG_STAT_F2S_NSTATUS_PIN) == 0)
  383. return FPGA_MGR_STATE_RESET;
  384. return FPGA_MGR_STATE_UNKNOWN;
  385. }
  386. static const struct fpga_manager_ops socfpga_a10_fpga_mgr_ops = {
  387. .initial_header_size = (RBF_DECOMPRESS_OFFSET + 1) * 4,
  388. .state = socfpga_a10_fpga_state,
  389. .write_init = socfpga_a10_fpga_write_init,
  390. .write = socfpga_a10_fpga_write,
  391. .write_complete = socfpga_a10_fpga_write_complete,
  392. };
  393. static int socfpga_a10_fpga_probe(struct platform_device *pdev)
  394. {
  395. struct device *dev = &pdev->dev;
  396. struct a10_fpga_priv *priv;
  397. void __iomem *reg_base;
  398. struct resource *res;
  399. int ret;
  400. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  401. if (!priv)
  402. return -ENOMEM;
  403. /* First mmio base is for register access */
  404. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  405. reg_base = devm_ioremap_resource(dev, res);
  406. if (IS_ERR(reg_base))
  407. return PTR_ERR(reg_base);
  408. /* Second mmio base is for writing FPGA image data */
  409. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  410. priv->fpga_data_addr = devm_ioremap_resource(dev, res);
  411. if (IS_ERR(priv->fpga_data_addr))
  412. return PTR_ERR(priv->fpga_data_addr);
  413. /* regmap for register access */
  414. priv->regmap = devm_regmap_init_mmio(dev, reg_base,
  415. &socfpga_a10_fpga_regmap_config);
  416. if (IS_ERR(priv->regmap))
  417. return -ENODEV;
  418. priv->clk = devm_clk_get(dev, NULL);
  419. if (IS_ERR(priv->clk)) {
  420. dev_err(dev, "no clock specified\n");
  421. return PTR_ERR(priv->clk);
  422. }
  423. ret = clk_prepare_enable(priv->clk);
  424. if (ret) {
  425. dev_err(dev, "could not enable clock\n");
  426. return -EBUSY;
  427. }
  428. return fpga_mgr_register(dev, "SoCFPGA Arria10 FPGA Manager",
  429. &socfpga_a10_fpga_mgr_ops, priv);
  430. }
  431. static int socfpga_a10_fpga_remove(struct platform_device *pdev)
  432. {
  433. struct fpga_manager *mgr = platform_get_drvdata(pdev);
  434. struct a10_fpga_priv *priv = mgr->priv;
  435. fpga_mgr_unregister(&pdev->dev);
  436. clk_disable_unprepare(priv->clk);
  437. return 0;
  438. }
  439. static const struct of_device_id socfpga_a10_fpga_of_match[] = {
  440. { .compatible = "altr,socfpga-a10-fpga-mgr", },
  441. {},
  442. };
  443. MODULE_DEVICE_TABLE(of, socfpga_a10_fpga_of_match);
  444. static struct platform_driver socfpga_a10_fpga_driver = {
  445. .probe = socfpga_a10_fpga_probe,
  446. .remove = socfpga_a10_fpga_remove,
  447. .driver = {
  448. .name = "socfpga_a10_fpga_manager",
  449. .of_match_table = socfpga_a10_fpga_of_match,
  450. },
  451. };
  452. module_platform_driver(socfpga_a10_fpga_driver);
  453. MODULE_AUTHOR("Alan Tull <atull@opensource.altera.com>");
  454. MODULE_DESCRIPTION("SoCFPGA Arria10 FPGA Manager");
  455. MODULE_LICENSE("GPL v2");