core.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2016-2017 Linaro Ltd., Rob Herring <robh@kernel.org>
  4. *
  5. * Based on drivers/spmi/spmi.c:
  6. * Copyright (c) 2012-2015, The Linux Foundation. All rights reserved.
  7. */
  8. #include <linux/acpi.h>
  9. #include <linux/errno.h>
  10. #include <linux/idr.h>
  11. #include <linux/kernel.h>
  12. #include <linux/module.h>
  13. #include <linux/of.h>
  14. #include <linux/of_device.h>
  15. #include <linux/pm_domain.h>
  16. #include <linux/pm_runtime.h>
  17. #include <linux/sched.h>
  18. #include <linux/serdev.h>
  19. #include <linux/slab.h>
  20. static bool is_registered;
  21. static DEFINE_IDA(ctrl_ida);
  22. static ssize_t modalias_show(struct device *dev,
  23. struct device_attribute *attr, char *buf)
  24. {
  25. int len;
  26. len = acpi_device_modalias(dev, buf, PAGE_SIZE - 1);
  27. if (len != -ENODEV)
  28. return len;
  29. return of_device_modalias(dev, buf, PAGE_SIZE);
  30. }
  31. static DEVICE_ATTR_RO(modalias);
  32. static struct attribute *serdev_device_attrs[] = {
  33. &dev_attr_modalias.attr,
  34. NULL,
  35. };
  36. ATTRIBUTE_GROUPS(serdev_device);
  37. static int serdev_device_uevent(struct device *dev, struct kobj_uevent_env *env)
  38. {
  39. int rc;
  40. /* TODO: platform modalias */
  41. rc = acpi_device_uevent_modalias(dev, env);
  42. if (rc != -ENODEV)
  43. return rc;
  44. return of_device_uevent_modalias(dev, env);
  45. }
  46. static void serdev_device_release(struct device *dev)
  47. {
  48. struct serdev_device *serdev = to_serdev_device(dev);
  49. kfree(serdev);
  50. }
  51. static const struct device_type serdev_device_type = {
  52. .groups = serdev_device_groups,
  53. .uevent = serdev_device_uevent,
  54. .release = serdev_device_release,
  55. };
  56. static bool is_serdev_device(const struct device *dev)
  57. {
  58. return dev->type == &serdev_device_type;
  59. }
  60. static void serdev_ctrl_release(struct device *dev)
  61. {
  62. struct serdev_controller *ctrl = to_serdev_controller(dev);
  63. ida_simple_remove(&ctrl_ida, ctrl->nr);
  64. kfree(ctrl);
  65. }
  66. static const struct device_type serdev_ctrl_type = {
  67. .release = serdev_ctrl_release,
  68. };
  69. static int serdev_device_match(struct device *dev, struct device_driver *drv)
  70. {
  71. if (!is_serdev_device(dev))
  72. return 0;
  73. /* TODO: platform matching */
  74. if (acpi_driver_match_device(dev, drv))
  75. return 1;
  76. return of_driver_match_device(dev, drv);
  77. }
  78. /**
  79. * serdev_device_add() - add a device previously constructed via serdev_device_alloc()
  80. * @serdev: serdev_device to be added
  81. */
  82. int serdev_device_add(struct serdev_device *serdev)
  83. {
  84. struct serdev_controller *ctrl = serdev->ctrl;
  85. struct device *parent = serdev->dev.parent;
  86. int err;
  87. dev_set_name(&serdev->dev, "%s-%d", dev_name(parent), serdev->nr);
  88. /* Only a single slave device is currently supported. */
  89. if (ctrl->serdev) {
  90. dev_err(&serdev->dev, "controller busy\n");
  91. return -EBUSY;
  92. }
  93. ctrl->serdev = serdev;
  94. err = device_add(&serdev->dev);
  95. if (err < 0) {
  96. dev_err(&serdev->dev, "Can't add %s, status %d\n",
  97. dev_name(&serdev->dev), err);
  98. goto err_clear_serdev;
  99. }
  100. dev_dbg(&serdev->dev, "device %s registered\n", dev_name(&serdev->dev));
  101. return 0;
  102. err_clear_serdev:
  103. ctrl->serdev = NULL;
  104. return err;
  105. }
  106. EXPORT_SYMBOL_GPL(serdev_device_add);
  107. /**
  108. * serdev_device_remove(): remove an serdev device
  109. * @serdev: serdev_device to be removed
  110. */
  111. void serdev_device_remove(struct serdev_device *serdev)
  112. {
  113. struct serdev_controller *ctrl = serdev->ctrl;
  114. device_unregister(&serdev->dev);
  115. ctrl->serdev = NULL;
  116. }
  117. EXPORT_SYMBOL_GPL(serdev_device_remove);
  118. int serdev_device_open(struct serdev_device *serdev)
  119. {
  120. struct serdev_controller *ctrl = serdev->ctrl;
  121. int ret;
  122. if (!ctrl || !ctrl->ops->open)
  123. return -EINVAL;
  124. ret = ctrl->ops->open(ctrl);
  125. if (ret)
  126. return ret;
  127. ret = pm_runtime_get_sync(&ctrl->dev);
  128. if (ret < 0) {
  129. pm_runtime_put_noidle(&ctrl->dev);
  130. goto err_close;
  131. }
  132. return 0;
  133. err_close:
  134. if (ctrl->ops->close)
  135. ctrl->ops->close(ctrl);
  136. return ret;
  137. }
  138. EXPORT_SYMBOL_GPL(serdev_device_open);
  139. void serdev_device_close(struct serdev_device *serdev)
  140. {
  141. struct serdev_controller *ctrl = serdev->ctrl;
  142. if (!ctrl || !ctrl->ops->close)
  143. return;
  144. pm_runtime_put(&ctrl->dev);
  145. ctrl->ops->close(ctrl);
  146. }
  147. EXPORT_SYMBOL_GPL(serdev_device_close);
  148. static void devm_serdev_device_release(struct device *dev, void *dr)
  149. {
  150. serdev_device_close(*(struct serdev_device **)dr);
  151. }
  152. int devm_serdev_device_open(struct device *dev, struct serdev_device *serdev)
  153. {
  154. struct serdev_device **dr;
  155. int ret;
  156. dr = devres_alloc(devm_serdev_device_release, sizeof(*dr), GFP_KERNEL);
  157. if (!dr)
  158. return -ENOMEM;
  159. ret = serdev_device_open(serdev);
  160. if (ret) {
  161. devres_free(dr);
  162. return ret;
  163. }
  164. *dr = serdev;
  165. devres_add(dev, dr);
  166. return 0;
  167. }
  168. EXPORT_SYMBOL_GPL(devm_serdev_device_open);
  169. void serdev_device_write_wakeup(struct serdev_device *serdev)
  170. {
  171. complete(&serdev->write_comp);
  172. }
  173. EXPORT_SYMBOL_GPL(serdev_device_write_wakeup);
  174. /**
  175. * serdev_device_write_buf() - write data asynchronously
  176. * @serdev: serdev device
  177. * @buf: data to be written
  178. * @count: number of bytes to write
  179. *
  180. * Write data to the device asynchronously.
  181. *
  182. * Note that any accepted data has only been buffered by the controller; use
  183. * serdev_device_wait_until_sent() to make sure the controller write buffer
  184. * has actually been emptied.
  185. *
  186. * Return: The number of bytes written (less than count if not enough room in
  187. * the write buffer), or a negative errno on errors.
  188. */
  189. int serdev_device_write_buf(struct serdev_device *serdev,
  190. const unsigned char *buf, size_t count)
  191. {
  192. struct serdev_controller *ctrl = serdev->ctrl;
  193. if (!ctrl || !ctrl->ops->write_buf)
  194. return -EINVAL;
  195. return ctrl->ops->write_buf(ctrl, buf, count);
  196. }
  197. EXPORT_SYMBOL_GPL(serdev_device_write_buf);
  198. /**
  199. * serdev_device_write() - write data synchronously
  200. * @serdev: serdev device
  201. * @buf: data to be written
  202. * @count: number of bytes to write
  203. * @timeout: timeout in jiffies, or 0 to wait indefinitely
  204. *
  205. * Write data to the device synchronously by repeatedly calling
  206. * serdev_device_write() until the controller has accepted all data (unless
  207. * interrupted by a timeout or a signal).
  208. *
  209. * Note that any accepted data has only been buffered by the controller; use
  210. * serdev_device_wait_until_sent() to make sure the controller write buffer
  211. * has actually been emptied.
  212. *
  213. * Note that this function depends on serdev_device_write_wakeup() being
  214. * called in the serdev driver write_wakeup() callback.
  215. *
  216. * Return: The number of bytes written (less than count if interrupted),
  217. * -ETIMEDOUT or -ERESTARTSYS if interrupted before any bytes were written, or
  218. * a negative errno on errors.
  219. */
  220. int serdev_device_write(struct serdev_device *serdev,
  221. const unsigned char *buf, size_t count,
  222. long timeout)
  223. {
  224. struct serdev_controller *ctrl = serdev->ctrl;
  225. int written = 0;
  226. int ret;
  227. if (!ctrl || !ctrl->ops->write_buf || !serdev->ops->write_wakeup)
  228. return -EINVAL;
  229. if (timeout == 0)
  230. timeout = MAX_SCHEDULE_TIMEOUT;
  231. mutex_lock(&serdev->write_lock);
  232. do {
  233. reinit_completion(&serdev->write_comp);
  234. ret = ctrl->ops->write_buf(ctrl, buf, count);
  235. if (ret < 0)
  236. break;
  237. written += ret;
  238. buf += ret;
  239. count -= ret;
  240. if (count == 0)
  241. break;
  242. timeout = wait_for_completion_interruptible_timeout(&serdev->write_comp,
  243. timeout);
  244. } while (timeout > 0);
  245. mutex_unlock(&serdev->write_lock);
  246. if (ret < 0)
  247. return ret;
  248. if (timeout <= 0 && written == 0) {
  249. if (timeout == -ERESTARTSYS)
  250. return -ERESTARTSYS;
  251. else
  252. return -ETIMEDOUT;
  253. }
  254. return written;
  255. }
  256. EXPORT_SYMBOL_GPL(serdev_device_write);
  257. void serdev_device_write_flush(struct serdev_device *serdev)
  258. {
  259. struct serdev_controller *ctrl = serdev->ctrl;
  260. if (!ctrl || !ctrl->ops->write_flush)
  261. return;
  262. ctrl->ops->write_flush(ctrl);
  263. }
  264. EXPORT_SYMBOL_GPL(serdev_device_write_flush);
  265. int serdev_device_write_room(struct serdev_device *serdev)
  266. {
  267. struct serdev_controller *ctrl = serdev->ctrl;
  268. if (!ctrl || !ctrl->ops->write_room)
  269. return 0;
  270. return serdev->ctrl->ops->write_room(ctrl);
  271. }
  272. EXPORT_SYMBOL_GPL(serdev_device_write_room);
  273. unsigned int serdev_device_set_baudrate(struct serdev_device *serdev, unsigned int speed)
  274. {
  275. struct serdev_controller *ctrl = serdev->ctrl;
  276. if (!ctrl || !ctrl->ops->set_baudrate)
  277. return 0;
  278. return ctrl->ops->set_baudrate(ctrl, speed);
  279. }
  280. EXPORT_SYMBOL_GPL(serdev_device_set_baudrate);
  281. void serdev_device_set_flow_control(struct serdev_device *serdev, bool enable)
  282. {
  283. struct serdev_controller *ctrl = serdev->ctrl;
  284. if (!ctrl || !ctrl->ops->set_flow_control)
  285. return;
  286. ctrl->ops->set_flow_control(ctrl, enable);
  287. }
  288. EXPORT_SYMBOL_GPL(serdev_device_set_flow_control);
  289. int serdev_device_set_parity(struct serdev_device *serdev,
  290. enum serdev_parity parity)
  291. {
  292. struct serdev_controller *ctrl = serdev->ctrl;
  293. if (!ctrl || !ctrl->ops->set_parity)
  294. return -ENOTSUPP;
  295. return ctrl->ops->set_parity(ctrl, parity);
  296. }
  297. EXPORT_SYMBOL_GPL(serdev_device_set_parity);
  298. void serdev_device_wait_until_sent(struct serdev_device *serdev, long timeout)
  299. {
  300. struct serdev_controller *ctrl = serdev->ctrl;
  301. if (!ctrl || !ctrl->ops->wait_until_sent)
  302. return;
  303. ctrl->ops->wait_until_sent(ctrl, timeout);
  304. }
  305. EXPORT_SYMBOL_GPL(serdev_device_wait_until_sent);
  306. int serdev_device_get_tiocm(struct serdev_device *serdev)
  307. {
  308. struct serdev_controller *ctrl = serdev->ctrl;
  309. if (!ctrl || !ctrl->ops->get_tiocm)
  310. return -ENOTSUPP;
  311. return ctrl->ops->get_tiocm(ctrl);
  312. }
  313. EXPORT_SYMBOL_GPL(serdev_device_get_tiocm);
  314. int serdev_device_set_tiocm(struct serdev_device *serdev, int set, int clear)
  315. {
  316. struct serdev_controller *ctrl = serdev->ctrl;
  317. if (!ctrl || !ctrl->ops->set_tiocm)
  318. return -ENOTSUPP;
  319. return ctrl->ops->set_tiocm(ctrl, set, clear);
  320. }
  321. EXPORT_SYMBOL_GPL(serdev_device_set_tiocm);
  322. static int serdev_drv_probe(struct device *dev)
  323. {
  324. const struct serdev_device_driver *sdrv = to_serdev_device_driver(dev->driver);
  325. int ret;
  326. ret = dev_pm_domain_attach(dev, true);
  327. if (ret)
  328. return ret;
  329. ret = sdrv->probe(to_serdev_device(dev));
  330. if (ret)
  331. dev_pm_domain_detach(dev, true);
  332. return ret;
  333. }
  334. static int serdev_drv_remove(struct device *dev)
  335. {
  336. const struct serdev_device_driver *sdrv = to_serdev_device_driver(dev->driver);
  337. if (sdrv->remove)
  338. sdrv->remove(to_serdev_device(dev));
  339. dev_pm_domain_detach(dev, true);
  340. return 0;
  341. }
  342. static struct bus_type serdev_bus_type = {
  343. .name = "serial",
  344. .match = serdev_device_match,
  345. .probe = serdev_drv_probe,
  346. .remove = serdev_drv_remove,
  347. };
  348. /**
  349. * serdev_device_alloc() - Allocate a new serdev device
  350. * @ctrl: associated controller
  351. *
  352. * Caller is responsible for either calling serdev_device_add() to add the
  353. * newly allocated controller, or calling serdev_device_put() to discard it.
  354. */
  355. struct serdev_device *serdev_device_alloc(struct serdev_controller *ctrl)
  356. {
  357. struct serdev_device *serdev;
  358. serdev = kzalloc(sizeof(*serdev), GFP_KERNEL);
  359. if (!serdev)
  360. return NULL;
  361. serdev->ctrl = ctrl;
  362. device_initialize(&serdev->dev);
  363. serdev->dev.parent = &ctrl->dev;
  364. serdev->dev.bus = &serdev_bus_type;
  365. serdev->dev.type = &serdev_device_type;
  366. init_completion(&serdev->write_comp);
  367. mutex_init(&serdev->write_lock);
  368. return serdev;
  369. }
  370. EXPORT_SYMBOL_GPL(serdev_device_alloc);
  371. /**
  372. * serdev_controller_alloc() - Allocate a new serdev controller
  373. * @parent: parent device
  374. * @size: size of private data
  375. *
  376. * Caller is responsible for either calling serdev_controller_add() to add the
  377. * newly allocated controller, or calling serdev_controller_put() to discard it.
  378. * The allocated private data region may be accessed via
  379. * serdev_controller_get_drvdata()
  380. */
  381. struct serdev_controller *serdev_controller_alloc(struct device *parent,
  382. size_t size)
  383. {
  384. struct serdev_controller *ctrl;
  385. int id;
  386. if (WARN_ON(!parent))
  387. return NULL;
  388. ctrl = kzalloc(sizeof(*ctrl) + size, GFP_KERNEL);
  389. if (!ctrl)
  390. return NULL;
  391. id = ida_simple_get(&ctrl_ida, 0, 0, GFP_KERNEL);
  392. if (id < 0) {
  393. dev_err(parent,
  394. "unable to allocate serdev controller identifier.\n");
  395. goto err_free;
  396. }
  397. ctrl->nr = id;
  398. device_initialize(&ctrl->dev);
  399. ctrl->dev.type = &serdev_ctrl_type;
  400. ctrl->dev.bus = &serdev_bus_type;
  401. ctrl->dev.parent = parent;
  402. ctrl->dev.of_node = parent->of_node;
  403. serdev_controller_set_drvdata(ctrl, &ctrl[1]);
  404. dev_set_name(&ctrl->dev, "serial%d", id);
  405. pm_runtime_no_callbacks(&ctrl->dev);
  406. pm_suspend_ignore_children(&ctrl->dev, true);
  407. dev_dbg(&ctrl->dev, "allocated controller 0x%p id %d\n", ctrl, id);
  408. return ctrl;
  409. err_free:
  410. kfree(ctrl);
  411. return NULL;
  412. }
  413. EXPORT_SYMBOL_GPL(serdev_controller_alloc);
  414. static int of_serdev_register_devices(struct serdev_controller *ctrl)
  415. {
  416. struct device_node *node;
  417. struct serdev_device *serdev = NULL;
  418. int err;
  419. bool found = false;
  420. for_each_available_child_of_node(ctrl->dev.of_node, node) {
  421. if (!of_get_property(node, "compatible", NULL))
  422. continue;
  423. dev_dbg(&ctrl->dev, "adding child %pOF\n", node);
  424. serdev = serdev_device_alloc(ctrl);
  425. if (!serdev)
  426. continue;
  427. serdev->dev.of_node = node;
  428. err = serdev_device_add(serdev);
  429. if (err) {
  430. dev_err(&serdev->dev,
  431. "failure adding device. status %d\n", err);
  432. serdev_device_put(serdev);
  433. } else
  434. found = true;
  435. }
  436. if (!found)
  437. return -ENODEV;
  438. return 0;
  439. }
  440. #ifdef CONFIG_ACPI
  441. static acpi_status acpi_serdev_register_device(struct serdev_controller *ctrl,
  442. struct acpi_device *adev)
  443. {
  444. struct serdev_device *serdev = NULL;
  445. int err;
  446. if (acpi_bus_get_status(adev) || !adev->status.present ||
  447. acpi_device_enumerated(adev))
  448. return AE_OK;
  449. serdev = serdev_device_alloc(ctrl);
  450. if (!serdev) {
  451. dev_err(&ctrl->dev, "failed to allocate serdev device for %s\n",
  452. dev_name(&adev->dev));
  453. return AE_NO_MEMORY;
  454. }
  455. ACPI_COMPANION_SET(&serdev->dev, adev);
  456. acpi_device_set_enumerated(adev);
  457. err = serdev_device_add(serdev);
  458. if (err) {
  459. dev_err(&serdev->dev,
  460. "failure adding ACPI serdev device. status %d\n", err);
  461. serdev_device_put(serdev);
  462. }
  463. return AE_OK;
  464. }
  465. static const struct acpi_device_id serdev_acpi_devices_blacklist[] = {
  466. { "INT3511", 0 },
  467. { "INT3512", 0 },
  468. { },
  469. };
  470. static acpi_status acpi_serdev_add_device(acpi_handle handle, u32 level,
  471. void *data, void **return_value)
  472. {
  473. struct serdev_controller *ctrl = data;
  474. struct acpi_device *adev;
  475. if (acpi_bus_get_device(handle, &adev))
  476. return AE_OK;
  477. /* Skip if black listed */
  478. if (!acpi_match_device_ids(adev, serdev_acpi_devices_blacklist))
  479. return AE_OK;
  480. return acpi_serdev_register_device(ctrl, adev);
  481. }
  482. static int acpi_serdev_register_devices(struct serdev_controller *ctrl)
  483. {
  484. acpi_status status;
  485. acpi_handle handle;
  486. handle = ACPI_HANDLE(ctrl->dev.parent);
  487. if (!handle)
  488. return -ENODEV;
  489. status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1,
  490. acpi_serdev_add_device, NULL, ctrl, NULL);
  491. if (ACPI_FAILURE(status))
  492. dev_dbg(&ctrl->dev, "failed to enumerate serdev slaves\n");
  493. if (!ctrl->serdev)
  494. return -ENODEV;
  495. return 0;
  496. }
  497. #else
  498. static inline int acpi_serdev_register_devices(struct serdev_controller *ctrl)
  499. {
  500. return -ENODEV;
  501. }
  502. #endif /* CONFIG_ACPI */
  503. /**
  504. * serdev_controller_add() - Add an serdev controller
  505. * @ctrl: controller to be registered.
  506. *
  507. * Register a controller previously allocated via serdev_controller_alloc() with
  508. * the serdev core.
  509. */
  510. int serdev_controller_add(struct serdev_controller *ctrl)
  511. {
  512. int ret_of, ret_acpi, ret;
  513. /* Can't register until after driver model init */
  514. if (WARN_ON(!is_registered))
  515. return -EAGAIN;
  516. ret = device_add(&ctrl->dev);
  517. if (ret)
  518. return ret;
  519. pm_runtime_enable(&ctrl->dev);
  520. ret_of = of_serdev_register_devices(ctrl);
  521. ret_acpi = acpi_serdev_register_devices(ctrl);
  522. if (ret_of && ret_acpi) {
  523. dev_dbg(&ctrl->dev, "no devices registered: of:%d acpi:%d\n",
  524. ret_of, ret_acpi);
  525. ret = -ENODEV;
  526. goto err_rpm_disable;
  527. }
  528. dev_dbg(&ctrl->dev, "serdev%d registered: dev:%p\n",
  529. ctrl->nr, &ctrl->dev);
  530. return 0;
  531. err_rpm_disable:
  532. pm_runtime_disable(&ctrl->dev);
  533. device_del(&ctrl->dev);
  534. return ret;
  535. };
  536. EXPORT_SYMBOL_GPL(serdev_controller_add);
  537. /* Remove a device associated with a controller */
  538. static int serdev_remove_device(struct device *dev, void *data)
  539. {
  540. struct serdev_device *serdev = to_serdev_device(dev);
  541. if (dev->type == &serdev_device_type)
  542. serdev_device_remove(serdev);
  543. return 0;
  544. }
  545. /**
  546. * serdev_controller_remove(): remove an serdev controller
  547. * @ctrl: controller to remove
  548. *
  549. * Remove a serdev controller. Caller is responsible for calling
  550. * serdev_controller_put() to discard the allocated controller.
  551. */
  552. void serdev_controller_remove(struct serdev_controller *ctrl)
  553. {
  554. int dummy;
  555. if (!ctrl)
  556. return;
  557. dummy = device_for_each_child(&ctrl->dev, NULL,
  558. serdev_remove_device);
  559. pm_runtime_disable(&ctrl->dev);
  560. device_del(&ctrl->dev);
  561. }
  562. EXPORT_SYMBOL_GPL(serdev_controller_remove);
  563. /**
  564. * serdev_driver_register() - Register client driver with serdev core
  565. * @sdrv: client driver to be associated with client-device.
  566. *
  567. * This API will register the client driver with the serdev framework.
  568. * It is typically called from the driver's module-init function.
  569. */
  570. int __serdev_device_driver_register(struct serdev_device_driver *sdrv, struct module *owner)
  571. {
  572. sdrv->driver.bus = &serdev_bus_type;
  573. sdrv->driver.owner = owner;
  574. /* force drivers to async probe so I/O is possible in probe */
  575. sdrv->driver.probe_type = PROBE_PREFER_ASYNCHRONOUS;
  576. return driver_register(&sdrv->driver);
  577. }
  578. EXPORT_SYMBOL_GPL(__serdev_device_driver_register);
  579. static void __exit serdev_exit(void)
  580. {
  581. bus_unregister(&serdev_bus_type);
  582. ida_destroy(&ctrl_ida);
  583. }
  584. module_exit(serdev_exit);
  585. static int __init serdev_init(void)
  586. {
  587. int ret;
  588. ret = bus_register(&serdev_bus_type);
  589. if (ret)
  590. return ret;
  591. is_registered = true;
  592. return 0;
  593. }
  594. /* Must be before serial drivers register */
  595. postcore_initcall(serdev_init);
  596. MODULE_AUTHOR("Rob Herring <robh@kernel.org>");
  597. MODULE_LICENSE("GPL v2");
  598. MODULE_DESCRIPTION("Serial attached device bus");