fsi-scom.c 16 KB

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