fsi-scom.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. /*
  2. * SCOM FSI Client device driver
  3. *
  4. * Copyright (C) IBM Corporation 2016
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERGCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <linux/fsi.h>
  16. #include <linux/module.h>
  17. #include <linux/cdev.h>
  18. #include <linux/delay.h>
  19. #include <linux/fs.h>
  20. #include <linux/uaccess.h>
  21. #include <linux/slab.h>
  22. #include <linux/cdev.h>
  23. #include <linux/list.h>
  24. #include <uapi/linux/fsi.h>
  25. #define FSI_ENGID_SCOM 0x5
  26. /* SCOM engine register set */
  27. #define SCOM_DATA0_REG 0x00
  28. #define SCOM_DATA1_REG 0x04
  29. #define SCOM_CMD_REG 0x08
  30. #define SCOM_FSI2PIB_RESET_REG 0x18
  31. #define SCOM_STATUS_REG 0x1C /* Read */
  32. #define SCOM_PIB_RESET_REG 0x1C /* Write */
  33. /* Command register */
  34. #define SCOM_WRITE_CMD 0x80000000
  35. #define SCOM_READ_CMD 0x00000000
  36. /* Status register bits */
  37. #define SCOM_STATUS_ERR_SUMMARY 0x80000000
  38. #define SCOM_STATUS_PROTECTION 0x01000000
  39. #define SCOM_STATUS_PARITY 0x04000000
  40. #define SCOM_STATUS_PIB_ABORT 0x00100000
  41. #define SCOM_STATUS_PIB_RESP_MASK 0x00007000
  42. #define SCOM_STATUS_PIB_RESP_SHIFT 12
  43. #define SCOM_STATUS_ANY_ERR (SCOM_STATUS_PROTECTION | \
  44. SCOM_STATUS_PARITY | \
  45. SCOM_STATUS_PIB_ABORT | \
  46. SCOM_STATUS_PIB_RESP_MASK)
  47. /* SCOM address encodings */
  48. #define XSCOM_ADDR_IND_FLAG BIT_ULL(63)
  49. #define XSCOM_ADDR_INF_FORM1 BIT_ULL(60)
  50. /* SCOM indirect stuff */
  51. #define XSCOM_ADDR_DIRECT_PART 0x7fffffffull
  52. #define XSCOM_ADDR_INDIRECT_PART 0x000fffff00000000ull
  53. #define XSCOM_DATA_IND_READ BIT_ULL(63)
  54. #define XSCOM_DATA_IND_COMPLETE BIT_ULL(31)
  55. #define XSCOM_DATA_IND_ERR_MASK 0x70000000ull
  56. #define XSCOM_DATA_IND_ERR_SHIFT 28
  57. #define XSCOM_DATA_IND_DATA 0x0000ffffull
  58. #define XSCOM_DATA_IND_FORM1_DATA 0x000fffffffffffffull
  59. #define XSCOM_ADDR_FORM1_LOW 0x000ffffffffull
  60. #define XSCOM_ADDR_FORM1_HI 0xfff00000000ull
  61. #define XSCOM_ADDR_FORM1_HI_SHIFT 20
  62. /* Retries */
  63. #define SCOM_MAX_RETRIES 100 /* Retries on busy */
  64. #define SCOM_MAX_IND_RETRIES 10 /* Retries indirect not ready */
  65. struct scom_device {
  66. struct list_head link;
  67. struct fsi_device *fsi_dev;
  68. struct device dev;
  69. struct cdev cdev;
  70. struct mutex lock;
  71. bool dead;
  72. };
  73. static int __put_scom(struct scom_device *scom_dev, uint64_t value,
  74. uint32_t addr, uint32_t *status)
  75. {
  76. __be32 data, raw_status;
  77. int rc;
  78. data = cpu_to_be32((value >> 32) & 0xffffffff);
  79. rc = fsi_device_write(scom_dev->fsi_dev, SCOM_DATA0_REG, &data,
  80. sizeof(uint32_t));
  81. if (rc)
  82. return rc;
  83. data = cpu_to_be32(value & 0xffffffff);
  84. rc = fsi_device_write(scom_dev->fsi_dev, SCOM_DATA1_REG, &data,
  85. sizeof(uint32_t));
  86. if (rc)
  87. return rc;
  88. data = cpu_to_be32(SCOM_WRITE_CMD | addr);
  89. rc = fsi_device_write(scom_dev->fsi_dev, SCOM_CMD_REG, &data,
  90. sizeof(uint32_t));
  91. if (rc)
  92. return rc;
  93. rc = fsi_device_read(scom_dev->fsi_dev, SCOM_STATUS_REG, &raw_status,
  94. sizeof(uint32_t));
  95. if (rc)
  96. return rc;
  97. *status = be32_to_cpu(raw_status);
  98. return 0;
  99. }
  100. static int __get_scom(struct scom_device *scom_dev, uint64_t *value,
  101. uint32_t addr, uint32_t *status)
  102. {
  103. __be32 data, raw_status;
  104. int rc;
  105. *value = 0ULL;
  106. data = cpu_to_be32(SCOM_READ_CMD | addr);
  107. rc = fsi_device_write(scom_dev->fsi_dev, SCOM_CMD_REG, &data,
  108. sizeof(uint32_t));
  109. if (rc)
  110. return rc;
  111. rc = fsi_device_read(scom_dev->fsi_dev, SCOM_STATUS_REG, &raw_status,
  112. sizeof(uint32_t));
  113. if (rc)
  114. return rc;
  115. /*
  116. * Read the data registers even on error, so we don't have
  117. * to interpret the status register here.
  118. */
  119. rc = fsi_device_read(scom_dev->fsi_dev, SCOM_DATA0_REG, &data,
  120. sizeof(uint32_t));
  121. if (rc)
  122. return rc;
  123. *value |= (uint64_t)be32_to_cpu(data) << 32;
  124. rc = fsi_device_read(scom_dev->fsi_dev, SCOM_DATA1_REG, &data,
  125. sizeof(uint32_t));
  126. if (rc)
  127. return rc;
  128. *value |= be32_to_cpu(data);
  129. *status = be32_to_cpu(raw_status);
  130. return rc;
  131. }
  132. static int put_indirect_scom_form0(struct scom_device *scom, uint64_t value,
  133. uint64_t addr, uint32_t *status)
  134. {
  135. uint64_t ind_data, ind_addr;
  136. int rc, retries, err = 0;
  137. if (value & ~XSCOM_DATA_IND_DATA)
  138. return -EINVAL;
  139. ind_addr = addr & XSCOM_ADDR_DIRECT_PART;
  140. ind_data = (addr & XSCOM_ADDR_INDIRECT_PART) | value;
  141. rc = __put_scom(scom, ind_data, ind_addr, status);
  142. if (rc || (*status & SCOM_STATUS_ANY_ERR))
  143. return rc;
  144. for (retries = 0; retries < SCOM_MAX_IND_RETRIES; retries++) {
  145. rc = __get_scom(scom, &ind_data, addr, status);
  146. if (rc || (*status & SCOM_STATUS_ANY_ERR))
  147. return rc;
  148. err = (ind_data & XSCOM_DATA_IND_ERR_MASK) >> XSCOM_DATA_IND_ERR_SHIFT;
  149. *status = err << SCOM_STATUS_PIB_RESP_SHIFT;
  150. if ((ind_data & XSCOM_DATA_IND_COMPLETE) || (err != SCOM_PIB_BLOCKED))
  151. return 0;
  152. msleep(1);
  153. }
  154. return rc;
  155. }
  156. static int put_indirect_scom_form1(struct scom_device *scom, uint64_t value,
  157. uint64_t addr, uint32_t *status)
  158. {
  159. uint64_t ind_data, ind_addr;
  160. if (value & ~XSCOM_DATA_IND_FORM1_DATA)
  161. return -EINVAL;
  162. ind_addr = addr & XSCOM_ADDR_FORM1_LOW;
  163. ind_data = value | (addr & XSCOM_ADDR_FORM1_HI) << XSCOM_ADDR_FORM1_HI_SHIFT;
  164. return __put_scom(scom, ind_data, ind_addr, status);
  165. }
  166. static int get_indirect_scom_form0(struct scom_device *scom, uint64_t *value,
  167. uint64_t addr, uint32_t *status)
  168. {
  169. uint64_t ind_data, ind_addr;
  170. int rc, retries, err = 0;
  171. ind_addr = addr & XSCOM_ADDR_DIRECT_PART;
  172. ind_data = (addr & XSCOM_ADDR_INDIRECT_PART) | XSCOM_DATA_IND_READ;
  173. rc = __put_scom(scom, ind_data, ind_addr, status);
  174. if (rc || (*status & SCOM_STATUS_ANY_ERR))
  175. return rc;
  176. for (retries = 0; retries < SCOM_MAX_IND_RETRIES; retries++) {
  177. rc = __get_scom(scom, &ind_data, addr, status);
  178. if (rc || (*status & SCOM_STATUS_ANY_ERR))
  179. return rc;
  180. err = (ind_data & XSCOM_DATA_IND_ERR_MASK) >> XSCOM_DATA_IND_ERR_SHIFT;
  181. *status = err << SCOM_STATUS_PIB_RESP_SHIFT;
  182. *value = ind_data & XSCOM_DATA_IND_DATA;
  183. if ((ind_data & XSCOM_DATA_IND_COMPLETE) || (err != SCOM_PIB_BLOCKED))
  184. return 0;
  185. msleep(1);
  186. }
  187. return rc;
  188. }
  189. static int raw_put_scom(struct scom_device *scom, uint64_t value,
  190. uint64_t addr, uint32_t *status)
  191. {
  192. if (addr & XSCOM_ADDR_IND_FLAG) {
  193. if (addr & XSCOM_ADDR_INF_FORM1)
  194. return put_indirect_scom_form1(scom, value, addr, status);
  195. else
  196. return put_indirect_scom_form0(scom, value, addr, status);
  197. } else
  198. return __put_scom(scom, value, addr, status);
  199. }
  200. static int raw_get_scom(struct scom_device *scom, uint64_t *value,
  201. uint64_t addr, uint32_t *status)
  202. {
  203. if (addr & XSCOM_ADDR_IND_FLAG) {
  204. if (addr & XSCOM_ADDR_INF_FORM1)
  205. return -ENXIO;
  206. return get_indirect_scom_form0(scom, value, addr, status);
  207. } else
  208. return __get_scom(scom, value, addr, status);
  209. }
  210. static int handle_fsi2pib_status(struct scom_device *scom, uint32_t status)
  211. {
  212. uint32_t dummy = -1;
  213. if (status & SCOM_STATUS_PROTECTION)
  214. return -EPERM;
  215. if (status & SCOM_STATUS_PARITY) {
  216. fsi_device_write(scom->fsi_dev, SCOM_FSI2PIB_RESET_REG, &dummy,
  217. sizeof(uint32_t));
  218. return -EIO;
  219. }
  220. /* Return -EBUSY on PIB abort to force a retry */
  221. if (status & SCOM_STATUS_PIB_ABORT)
  222. return -EBUSY;
  223. return 0;
  224. }
  225. static int handle_pib_status(struct scom_device *scom, uint8_t status)
  226. {
  227. uint32_t dummy = -1;
  228. if (status == SCOM_PIB_SUCCESS)
  229. return 0;
  230. if (status == SCOM_PIB_BLOCKED)
  231. return -EBUSY;
  232. /* Reset the bridge */
  233. fsi_device_write(scom->fsi_dev, SCOM_FSI2PIB_RESET_REG, &dummy,
  234. sizeof(uint32_t));
  235. switch(status) {
  236. case SCOM_PIB_OFFLINE:
  237. return -ENODEV;
  238. case SCOM_PIB_BAD_ADDR:
  239. return -ENXIO;
  240. case SCOM_PIB_TIMEOUT:
  241. return -ETIMEDOUT;
  242. case SCOM_PIB_PARTIAL:
  243. case SCOM_PIB_CLK_ERR:
  244. case SCOM_PIB_PARITY_ERR:
  245. default:
  246. return -EIO;
  247. }
  248. }
  249. static int put_scom(struct scom_device *scom, uint64_t value,
  250. uint64_t addr)
  251. {
  252. uint32_t status, dummy = -1;
  253. int rc, retries;
  254. for (retries = 0; retries < SCOM_MAX_RETRIES; retries++) {
  255. rc = raw_put_scom(scom, value, addr, &status);
  256. if (rc) {
  257. /* Try resetting the bridge if FSI fails */
  258. if (rc != -ENODEV && retries == 0) {
  259. fsi_device_write(scom->fsi_dev, SCOM_FSI2PIB_RESET_REG,
  260. &dummy, sizeof(uint32_t));
  261. rc = -EBUSY;
  262. } else
  263. return rc;
  264. } else
  265. rc = handle_fsi2pib_status(scom, status);
  266. if (rc && rc != -EBUSY)
  267. break;
  268. if (rc == 0) {
  269. rc = handle_pib_status(scom,
  270. (status & SCOM_STATUS_PIB_RESP_MASK)
  271. >> SCOM_STATUS_PIB_RESP_SHIFT);
  272. if (rc && rc != -EBUSY)
  273. break;
  274. }
  275. if (rc == 0)
  276. break;
  277. msleep(1);
  278. }
  279. return rc;
  280. }
  281. static int get_scom(struct scom_device *scom, uint64_t *value,
  282. uint64_t addr)
  283. {
  284. uint32_t status, dummy = -1;
  285. int rc, retries;
  286. for (retries = 0; retries < SCOM_MAX_RETRIES; retries++) {
  287. rc = raw_get_scom(scom, value, addr, &status);
  288. if (rc) {
  289. /* Try resetting the bridge if FSI fails */
  290. if (rc != -ENODEV && retries == 0) {
  291. fsi_device_write(scom->fsi_dev, SCOM_FSI2PIB_RESET_REG,
  292. &dummy, sizeof(uint32_t));
  293. rc = -EBUSY;
  294. } else
  295. return rc;
  296. } else
  297. rc = handle_fsi2pib_status(scom, status);
  298. if (rc && rc != -EBUSY)
  299. break;
  300. if (rc == 0) {
  301. rc = handle_pib_status(scom,
  302. (status & SCOM_STATUS_PIB_RESP_MASK)
  303. >> SCOM_STATUS_PIB_RESP_SHIFT);
  304. if (rc && rc != -EBUSY)
  305. break;
  306. }
  307. if (rc == 0)
  308. break;
  309. msleep(1);
  310. }
  311. return rc;
  312. }
  313. static ssize_t scom_read(struct file *filep, char __user *buf, size_t len,
  314. loff_t *offset)
  315. {
  316. struct scom_device *scom = filep->private_data;
  317. struct device *dev = &scom->fsi_dev->dev;
  318. uint64_t val;
  319. int rc;
  320. if (len != sizeof(uint64_t))
  321. return -EINVAL;
  322. mutex_lock(&scom->lock);
  323. if (scom->dead)
  324. rc = -ENODEV;
  325. else
  326. rc = get_scom(scom, &val, *offset);
  327. mutex_unlock(&scom->lock);
  328. if (rc) {
  329. dev_dbg(dev, "get_scom fail:%d\n", rc);
  330. return rc;
  331. }
  332. rc = copy_to_user(buf, &val, len);
  333. if (rc)
  334. dev_dbg(dev, "copy to user failed:%d\n", rc);
  335. return rc ? rc : len;
  336. }
  337. static ssize_t scom_write(struct file *filep, const char __user *buf,
  338. size_t len, loff_t *offset)
  339. {
  340. int rc;
  341. struct scom_device *scom = filep->private_data;
  342. struct device *dev = &scom->fsi_dev->dev;
  343. uint64_t val;
  344. if (len != sizeof(uint64_t))
  345. return -EINVAL;
  346. rc = copy_from_user(&val, buf, len);
  347. if (rc) {
  348. dev_dbg(dev, "copy from user failed:%d\n", rc);
  349. return -EINVAL;
  350. }
  351. mutex_lock(&scom->lock);
  352. if (scom->dead)
  353. rc = -ENODEV;
  354. else
  355. rc = put_scom(scom, val, *offset);
  356. mutex_unlock(&scom->lock);
  357. if (rc) {
  358. dev_dbg(dev, "put_scom failed with:%d\n", rc);
  359. return rc;
  360. }
  361. return len;
  362. }
  363. static loff_t scom_llseek(struct file *file, loff_t offset, int whence)
  364. {
  365. switch (whence) {
  366. case SEEK_CUR:
  367. break;
  368. case SEEK_SET:
  369. file->f_pos = offset;
  370. break;
  371. default:
  372. return -EINVAL;
  373. }
  374. return offset;
  375. }
  376. static void raw_convert_status(struct scom_access *acc, uint32_t status)
  377. {
  378. acc->pib_status = (status & SCOM_STATUS_PIB_RESP_MASK) >>
  379. SCOM_STATUS_PIB_RESP_SHIFT;
  380. acc->intf_errors = 0;
  381. if (status & SCOM_STATUS_PROTECTION)
  382. acc->intf_errors |= SCOM_INTF_ERR_PROTECTION;
  383. else if (status & SCOM_STATUS_PARITY)
  384. acc->intf_errors |= SCOM_INTF_ERR_PARITY;
  385. else if (status & SCOM_STATUS_PIB_ABORT)
  386. acc->intf_errors |= SCOM_INTF_ERR_ABORT;
  387. else if (status & SCOM_STATUS_ERR_SUMMARY)
  388. acc->intf_errors |= SCOM_INTF_ERR_UNKNOWN;
  389. }
  390. static int scom_raw_read(struct scom_device *scom, void __user *argp)
  391. {
  392. struct scom_access acc;
  393. uint32_t status;
  394. int rc;
  395. if (copy_from_user(&acc, argp, sizeof(struct scom_access)))
  396. return -EFAULT;
  397. rc = raw_get_scom(scom, &acc.data, acc.addr, &status);
  398. if (rc)
  399. return rc;
  400. raw_convert_status(&acc, status);
  401. if (copy_to_user(argp, &acc, sizeof(struct scom_access)))
  402. return -EFAULT;
  403. return 0;
  404. }
  405. static int scom_raw_write(struct scom_device *scom, void __user *argp)
  406. {
  407. u64 prev_data, mask, data;
  408. struct scom_access acc;
  409. uint32_t status;
  410. int rc;
  411. if (copy_from_user(&acc, argp, sizeof(struct scom_access)))
  412. return -EFAULT;
  413. if (acc.mask) {
  414. rc = raw_get_scom(scom, &prev_data, acc.addr, &status);
  415. if (rc)
  416. return rc;
  417. if (status & SCOM_STATUS_ANY_ERR)
  418. goto fail;
  419. mask = acc.mask;
  420. } else {
  421. prev_data = mask = -1ull;
  422. }
  423. data = (prev_data & ~mask) | (acc.data & mask);
  424. rc = raw_put_scom(scom, data, acc.addr, &status);
  425. if (rc)
  426. return rc;
  427. fail:
  428. raw_convert_status(&acc, status);
  429. if (copy_to_user(argp, &acc, sizeof(struct scom_access)))
  430. return -EFAULT;
  431. return 0;
  432. }
  433. static int scom_reset(struct scom_device *scom, void __user *argp)
  434. {
  435. uint32_t flags, dummy = -1;
  436. int rc = 0;
  437. if (get_user(flags, (__u32 __user *)argp))
  438. return -EFAULT;
  439. if (flags & SCOM_RESET_PIB)
  440. rc = fsi_device_write(scom->fsi_dev, SCOM_PIB_RESET_REG, &dummy,
  441. sizeof(uint32_t));
  442. if (!rc && (flags & (SCOM_RESET_PIB | SCOM_RESET_INTF)))
  443. rc = fsi_device_write(scom->fsi_dev, SCOM_FSI2PIB_RESET_REG, &dummy,
  444. sizeof(uint32_t));
  445. return rc;
  446. }
  447. static int scom_check(struct scom_device *scom, void __user *argp)
  448. {
  449. /* Still need to find out how to get "protected" */
  450. return put_user(SCOM_CHECK_SUPPORTED, (__u32 __user *)argp);
  451. }
  452. static long scom_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  453. {
  454. struct scom_device *scom = file->private_data;
  455. void __user *argp = (void __user *)arg;
  456. int rc = -ENOTTY;
  457. mutex_lock(&scom->lock);
  458. if (scom->dead) {
  459. mutex_unlock(&scom->lock);
  460. return -ENODEV;
  461. }
  462. switch(cmd) {
  463. case FSI_SCOM_CHECK:
  464. rc = scom_check(scom, argp);
  465. break;
  466. case FSI_SCOM_READ:
  467. rc = scom_raw_read(scom, argp);
  468. break;
  469. case FSI_SCOM_WRITE:
  470. rc = scom_raw_write(scom, argp);
  471. break;
  472. case FSI_SCOM_RESET:
  473. rc = scom_reset(scom, argp);
  474. break;
  475. }
  476. mutex_unlock(&scom->lock);
  477. return rc;
  478. }
  479. static int scom_open(struct inode *inode, struct file *file)
  480. {
  481. struct scom_device *scom = container_of(inode->i_cdev, struct scom_device, cdev);
  482. file->private_data = scom;
  483. return 0;
  484. }
  485. static const struct file_operations scom_fops = {
  486. .owner = THIS_MODULE,
  487. .open = scom_open,
  488. .llseek = scom_llseek,
  489. .read = scom_read,
  490. .write = scom_write,
  491. .unlocked_ioctl = scom_ioctl,
  492. };
  493. static void scom_free(struct device *dev)
  494. {
  495. struct scom_device *scom = container_of(dev, struct scom_device, dev);
  496. put_device(&scom->fsi_dev->dev);
  497. kfree(scom);
  498. }
  499. static int scom_probe(struct device *dev)
  500. {
  501. struct fsi_device *fsi_dev = to_fsi_dev(dev);
  502. struct scom_device *scom;
  503. int rc, didx;
  504. scom = kzalloc(sizeof(*scom), GFP_KERNEL);
  505. if (!scom)
  506. return -ENOMEM;
  507. dev_set_drvdata(dev, scom);
  508. mutex_init(&scom->lock);
  509. /* Grab a reference to the device (parent of our cdev), we'll drop it later */
  510. if (!get_device(dev)) {
  511. kfree(scom);
  512. return -ENODEV;
  513. }
  514. scom->fsi_dev = fsi_dev;
  515. /* Create chardev for userspace access */
  516. scom->dev.type = &fsi_cdev_type;
  517. scom->dev.parent = dev;
  518. scom->dev.release = scom_free;
  519. device_initialize(&scom->dev);
  520. /* Allocate a minor in the FSI space */
  521. rc = fsi_get_new_minor(fsi_dev, fsi_dev_scom, &scom->dev.devt, &didx);
  522. if (rc)
  523. goto err;
  524. dev_set_name(&scom->dev, "scom%d", didx);
  525. cdev_init(&scom->cdev, &scom_fops);
  526. rc = cdev_device_add(&scom->cdev, &scom->dev);
  527. if (rc) {
  528. dev_err(dev, "Error %d creating char device %s\n",
  529. rc, dev_name(&scom->dev));
  530. goto err_free_minor;
  531. }
  532. return 0;
  533. err_free_minor:
  534. fsi_free_minor(scom->dev.devt);
  535. err:
  536. put_device(&scom->dev);
  537. return rc;
  538. }
  539. static int scom_remove(struct device *dev)
  540. {
  541. struct scom_device *scom = dev_get_drvdata(dev);
  542. mutex_lock(&scom->lock);
  543. scom->dead = true;
  544. mutex_unlock(&scom->lock);
  545. cdev_device_del(&scom->cdev, &scom->dev);
  546. fsi_free_minor(scom->dev.devt);
  547. put_device(&scom->dev);
  548. return 0;
  549. }
  550. static struct fsi_device_id scom_ids[] = {
  551. {
  552. .engine_type = FSI_ENGID_SCOM,
  553. .version = FSI_VERSION_ANY,
  554. },
  555. { 0 }
  556. };
  557. static struct fsi_driver scom_drv = {
  558. .id_table = scom_ids,
  559. .drv = {
  560. .name = "scom",
  561. .bus = &fsi_bus_type,
  562. .probe = scom_probe,
  563. .remove = scom_remove,
  564. }
  565. };
  566. static int scom_init(void)
  567. {
  568. return fsi_driver_register(&scom_drv);
  569. }
  570. static void scom_exit(void)
  571. {
  572. fsi_driver_unregister(&scom_drv);
  573. }
  574. module_init(scom_init);
  575. module_exit(scom_exit);
  576. MODULE_LICENSE("GPL");