hsi_core.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * HSI core.
  4. *
  5. * Copyright (C) 2010 Nokia Corporation. All rights reserved.
  6. *
  7. * Contact: Carlos Chinea <carlos.chinea@nokia.com>
  8. */
  9. #include <linux/hsi/hsi.h>
  10. #include <linux/compiler.h>
  11. #include <linux/list.h>
  12. #include <linux/kobject.h>
  13. #include <linux/slab.h>
  14. #include <linux/string.h>
  15. #include <linux/notifier.h>
  16. #include <linux/of.h>
  17. #include <linux/of_device.h>
  18. #include "hsi_core.h"
  19. static ssize_t modalias_show(struct device *dev,
  20. struct device_attribute *a __maybe_unused, char *buf)
  21. {
  22. return sprintf(buf, "hsi:%s\n", dev_name(dev));
  23. }
  24. static DEVICE_ATTR_RO(modalias);
  25. static struct attribute *hsi_bus_dev_attrs[] = {
  26. &dev_attr_modalias.attr,
  27. NULL,
  28. };
  29. ATTRIBUTE_GROUPS(hsi_bus_dev);
  30. static int hsi_bus_uevent(const struct device *dev, struct kobj_uevent_env *env)
  31. {
  32. add_uevent_var(env, "MODALIAS=hsi:%s", dev_name(dev));
  33. return 0;
  34. }
  35. static int hsi_bus_match(struct device *dev, const struct device_driver *driver)
  36. {
  37. if (of_driver_match_device(dev, driver))
  38. return true;
  39. if (strcmp(dev_name(dev), driver->name) == 0)
  40. return true;
  41. return false;
  42. }
  43. static const struct bus_type hsi_bus_type = {
  44. .name = "hsi",
  45. .dev_groups = hsi_bus_dev_groups,
  46. .match = hsi_bus_match,
  47. .uevent = hsi_bus_uevent,
  48. };
  49. static void hsi_client_release(struct device *dev)
  50. {
  51. struct hsi_client *cl = to_hsi_client(dev);
  52. kfree(cl->tx_cfg.channels);
  53. kfree(cl->rx_cfg.channels);
  54. kfree(cl);
  55. }
  56. struct hsi_client *hsi_new_client(struct hsi_port *port,
  57. struct hsi_board_info *info)
  58. {
  59. struct hsi_client *cl;
  60. size_t size;
  61. cl = kzalloc(sizeof(*cl), GFP_KERNEL);
  62. if (!cl)
  63. goto err;
  64. cl->tx_cfg = info->tx_cfg;
  65. if (cl->tx_cfg.channels) {
  66. size = cl->tx_cfg.num_channels * sizeof(*cl->tx_cfg.channels);
  67. cl->tx_cfg.channels = kmemdup(info->tx_cfg.channels, size,
  68. GFP_KERNEL);
  69. if (!cl->tx_cfg.channels)
  70. goto err_tx;
  71. }
  72. cl->rx_cfg = info->rx_cfg;
  73. if (cl->rx_cfg.channels) {
  74. size = cl->rx_cfg.num_channels * sizeof(*cl->rx_cfg.channels);
  75. cl->rx_cfg.channels = kmemdup(info->rx_cfg.channels, size,
  76. GFP_KERNEL);
  77. if (!cl->rx_cfg.channels)
  78. goto err_rx;
  79. }
  80. cl->device.bus = &hsi_bus_type;
  81. cl->device.parent = &port->device;
  82. cl->device.release = hsi_client_release;
  83. dev_set_name(&cl->device, "%s", info->name);
  84. cl->device.platform_data = info->platform_data;
  85. if (info->archdata)
  86. cl->device.archdata = *info->archdata;
  87. if (device_register(&cl->device) < 0) {
  88. pr_err("hsi: failed to register client: %s\n", info->name);
  89. put_device(&cl->device);
  90. goto err;
  91. }
  92. return cl;
  93. err_rx:
  94. kfree(cl->tx_cfg.channels);
  95. err_tx:
  96. kfree(cl);
  97. err:
  98. return NULL;
  99. }
  100. EXPORT_SYMBOL_GPL(hsi_new_client);
  101. static void hsi_scan_board_info(struct hsi_controller *hsi)
  102. {
  103. struct hsi_cl_info *cl_info;
  104. struct hsi_port *p;
  105. list_for_each_entry(cl_info, &hsi_board_list, list)
  106. if (cl_info->info.hsi_id == hsi->id) {
  107. p = hsi_find_port_num(hsi, cl_info->info.port);
  108. if (!p)
  109. continue;
  110. hsi_new_client(p, &cl_info->info);
  111. }
  112. }
  113. #ifdef CONFIG_OF
  114. static struct hsi_board_info hsi_char_dev_info = {
  115. .name = "hsi_char",
  116. };
  117. static int hsi_of_property_parse_mode(struct device_node *client, char *name,
  118. unsigned int *result)
  119. {
  120. const char *mode;
  121. int err;
  122. err = of_property_read_string(client, name, &mode);
  123. if (err < 0)
  124. return err;
  125. if (strcmp(mode, "stream") == 0)
  126. *result = HSI_MODE_STREAM;
  127. else if (strcmp(mode, "frame") == 0)
  128. *result = HSI_MODE_FRAME;
  129. else
  130. return -EINVAL;
  131. return 0;
  132. }
  133. static int hsi_of_property_parse_flow(struct device_node *client, char *name,
  134. unsigned int *result)
  135. {
  136. const char *flow;
  137. int err;
  138. err = of_property_read_string(client, name, &flow);
  139. if (err < 0)
  140. return err;
  141. if (strcmp(flow, "synchronized") == 0)
  142. *result = HSI_FLOW_SYNC;
  143. else if (strcmp(flow, "pipeline") == 0)
  144. *result = HSI_FLOW_PIPE;
  145. else
  146. return -EINVAL;
  147. return 0;
  148. }
  149. static int hsi_of_property_parse_arb_mode(struct device_node *client,
  150. char *name, unsigned int *result)
  151. {
  152. const char *arb_mode;
  153. int err;
  154. err = of_property_read_string(client, name, &arb_mode);
  155. if (err < 0)
  156. return err;
  157. if (strcmp(arb_mode, "round-robin") == 0)
  158. *result = HSI_ARB_RR;
  159. else if (strcmp(arb_mode, "priority") == 0)
  160. *result = HSI_ARB_PRIO;
  161. else
  162. return -EINVAL;
  163. return 0;
  164. }
  165. static void hsi_add_client_from_dt(struct hsi_port *port,
  166. struct device_node *client)
  167. {
  168. struct hsi_client *cl;
  169. struct hsi_channel channel;
  170. struct property *prop;
  171. char name[32];
  172. int length, cells, err, i, max_chan, mode;
  173. cl = kzalloc(sizeof(*cl), GFP_KERNEL);
  174. if (!cl)
  175. return;
  176. err = of_alias_from_compatible(client, name, sizeof(name));
  177. if (err)
  178. goto err;
  179. err = hsi_of_property_parse_mode(client, "hsi-mode", &mode);
  180. if (err) {
  181. err = hsi_of_property_parse_mode(client, "hsi-rx-mode",
  182. &cl->rx_cfg.mode);
  183. if (err)
  184. goto err;
  185. err = hsi_of_property_parse_mode(client, "hsi-tx-mode",
  186. &cl->tx_cfg.mode);
  187. if (err)
  188. goto err;
  189. } else {
  190. cl->rx_cfg.mode = mode;
  191. cl->tx_cfg.mode = mode;
  192. }
  193. err = of_property_read_u32(client, "hsi-speed-kbps",
  194. &cl->tx_cfg.speed);
  195. if (err)
  196. goto err;
  197. cl->rx_cfg.speed = cl->tx_cfg.speed;
  198. err = hsi_of_property_parse_flow(client, "hsi-flow",
  199. &cl->rx_cfg.flow);
  200. if (err)
  201. goto err;
  202. err = hsi_of_property_parse_arb_mode(client, "hsi-arb-mode",
  203. &cl->rx_cfg.arb_mode);
  204. if (err)
  205. goto err;
  206. prop = of_find_property(client, "hsi-channel-ids", &length);
  207. if (!prop) {
  208. err = -EINVAL;
  209. goto err;
  210. }
  211. cells = length / sizeof(u32);
  212. cl->rx_cfg.num_channels = cells;
  213. cl->tx_cfg.num_channels = cells;
  214. cl->rx_cfg.channels = kcalloc(cells, sizeof(channel), GFP_KERNEL);
  215. if (!cl->rx_cfg.channels) {
  216. err = -ENOMEM;
  217. goto err;
  218. }
  219. cl->tx_cfg.channels = kcalloc(cells, sizeof(channel), GFP_KERNEL);
  220. if (!cl->tx_cfg.channels) {
  221. err = -ENOMEM;
  222. goto err2;
  223. }
  224. max_chan = 0;
  225. for (i = 0; i < cells; i++) {
  226. err = of_property_read_u32_index(client, "hsi-channel-ids", i,
  227. &channel.id);
  228. if (err)
  229. goto err3;
  230. err = of_property_read_string_index(client, "hsi-channel-names",
  231. i, &channel.name);
  232. if (err)
  233. channel.name = NULL;
  234. if (channel.id > max_chan)
  235. max_chan = channel.id;
  236. cl->rx_cfg.channels[i] = channel;
  237. cl->tx_cfg.channels[i] = channel;
  238. }
  239. cl->rx_cfg.num_hw_channels = max_chan + 1;
  240. cl->tx_cfg.num_hw_channels = max_chan + 1;
  241. cl->device.bus = &hsi_bus_type;
  242. cl->device.parent = &port->device;
  243. cl->device.release = hsi_client_release;
  244. cl->device.of_node = client;
  245. dev_set_name(&cl->device, "%s", name);
  246. if (device_register(&cl->device) < 0) {
  247. pr_err("hsi: failed to register client: %s\n", name);
  248. put_device(&cl->device);
  249. }
  250. return;
  251. err3:
  252. kfree(cl->tx_cfg.channels);
  253. err2:
  254. kfree(cl->rx_cfg.channels);
  255. err:
  256. kfree(cl);
  257. pr_err("hsi client: missing or incorrect of property: err=%d\n", err);
  258. }
  259. void hsi_add_clients_from_dt(struct hsi_port *port, struct device_node *clients)
  260. {
  261. struct device_node *child;
  262. /* register hsi-char device */
  263. hsi_new_client(port, &hsi_char_dev_info);
  264. for_each_available_child_of_node(clients, child)
  265. hsi_add_client_from_dt(port, child);
  266. }
  267. EXPORT_SYMBOL_GPL(hsi_add_clients_from_dt);
  268. #endif
  269. int hsi_remove_client(struct device *dev, void *data __maybe_unused)
  270. {
  271. device_unregister(dev);
  272. return 0;
  273. }
  274. EXPORT_SYMBOL_GPL(hsi_remove_client);
  275. static int hsi_remove_port(struct device *dev, void *data __maybe_unused)
  276. {
  277. device_for_each_child(dev, NULL, hsi_remove_client);
  278. device_unregister(dev);
  279. return 0;
  280. }
  281. static void hsi_controller_release(struct device *dev)
  282. {
  283. struct hsi_controller *hsi = to_hsi_controller(dev);
  284. kfree(hsi->port);
  285. kfree(hsi);
  286. }
  287. static void hsi_port_release(struct device *dev)
  288. {
  289. kfree(to_hsi_port(dev));
  290. }
  291. /**
  292. * hsi_port_unregister_clients - Unregister an HSI port
  293. * @port: The HSI port to unregister
  294. */
  295. void hsi_port_unregister_clients(struct hsi_port *port)
  296. {
  297. device_for_each_child(&port->device, NULL, hsi_remove_client);
  298. }
  299. EXPORT_SYMBOL_GPL(hsi_port_unregister_clients);
  300. /**
  301. * hsi_unregister_controller - Unregister an HSI controller
  302. * @hsi: The HSI controller to register
  303. */
  304. void hsi_unregister_controller(struct hsi_controller *hsi)
  305. {
  306. device_for_each_child(&hsi->device, NULL, hsi_remove_port);
  307. device_unregister(&hsi->device);
  308. }
  309. EXPORT_SYMBOL_GPL(hsi_unregister_controller);
  310. /**
  311. * hsi_register_controller - Register an HSI controller and its ports
  312. * @hsi: The HSI controller to register
  313. *
  314. * Returns -errno on failure, 0 on success.
  315. */
  316. int hsi_register_controller(struct hsi_controller *hsi)
  317. {
  318. unsigned int i;
  319. int err;
  320. err = device_add(&hsi->device);
  321. if (err < 0)
  322. return err;
  323. for (i = 0; i < hsi->num_ports; i++) {
  324. hsi->port[i]->device.parent = &hsi->device;
  325. err = device_add(&hsi->port[i]->device);
  326. if (err < 0)
  327. goto out;
  328. }
  329. /* Populate HSI bus with HSI clients */
  330. hsi_scan_board_info(hsi);
  331. return 0;
  332. out:
  333. while (i-- > 0)
  334. device_del(&hsi->port[i]->device);
  335. device_del(&hsi->device);
  336. return err;
  337. }
  338. EXPORT_SYMBOL_GPL(hsi_register_controller);
  339. /**
  340. * hsi_register_client_driver - Register an HSI client to the HSI bus
  341. * @drv: HSI client driver to register
  342. *
  343. * Returns -errno on failure, 0 on success.
  344. */
  345. int hsi_register_client_driver(struct hsi_client_driver *drv)
  346. {
  347. drv->driver.bus = &hsi_bus_type;
  348. return driver_register(&drv->driver);
  349. }
  350. EXPORT_SYMBOL_GPL(hsi_register_client_driver);
  351. static inline int hsi_dummy_msg(struct hsi_msg *msg __maybe_unused)
  352. {
  353. return 0;
  354. }
  355. static inline int hsi_dummy_cl(struct hsi_client *cl __maybe_unused)
  356. {
  357. return 0;
  358. }
  359. /**
  360. * hsi_put_controller - Free an HSI controller
  361. *
  362. * @hsi: Pointer to the HSI controller to freed
  363. *
  364. * HSI controller drivers should only use this function if they need
  365. * to free their allocated hsi_controller structures before a successful
  366. * call to hsi_register_controller. Other use is not allowed.
  367. */
  368. void hsi_put_controller(struct hsi_controller *hsi)
  369. {
  370. unsigned int i;
  371. if (!hsi)
  372. return;
  373. for (i = 0; i < hsi->num_ports; i++)
  374. if (hsi->port && hsi->port[i])
  375. put_device(&hsi->port[i]->device);
  376. put_device(&hsi->device);
  377. }
  378. EXPORT_SYMBOL_GPL(hsi_put_controller);
  379. /**
  380. * hsi_alloc_controller - Allocate an HSI controller and its ports
  381. * @n_ports: Number of ports on the HSI controller
  382. * @flags: Kernel allocation flags
  383. *
  384. * Return NULL on failure or a pointer to an hsi_controller on success.
  385. */
  386. struct hsi_controller *hsi_alloc_controller(unsigned int n_ports, gfp_t flags)
  387. {
  388. struct hsi_controller *hsi;
  389. struct hsi_port **port;
  390. unsigned int i;
  391. if (!n_ports)
  392. return NULL;
  393. hsi = kzalloc(sizeof(*hsi), flags);
  394. if (!hsi)
  395. return NULL;
  396. port = kcalloc(n_ports, sizeof(*port), flags);
  397. if (!port) {
  398. kfree(hsi);
  399. return NULL;
  400. }
  401. hsi->num_ports = n_ports;
  402. hsi->port = port;
  403. hsi->device.release = hsi_controller_release;
  404. device_initialize(&hsi->device);
  405. for (i = 0; i < n_ports; i++) {
  406. port[i] = kzalloc(sizeof(**port), flags);
  407. if (port[i] == NULL)
  408. goto out;
  409. port[i]->num = i;
  410. port[i]->async = hsi_dummy_msg;
  411. port[i]->setup = hsi_dummy_cl;
  412. port[i]->flush = hsi_dummy_cl;
  413. port[i]->start_tx = hsi_dummy_cl;
  414. port[i]->stop_tx = hsi_dummy_cl;
  415. port[i]->release = hsi_dummy_cl;
  416. mutex_init(&port[i]->lock);
  417. BLOCKING_INIT_NOTIFIER_HEAD(&port[i]->n_head);
  418. dev_set_name(&port[i]->device, "port%d", i);
  419. hsi->port[i]->device.release = hsi_port_release;
  420. device_initialize(&hsi->port[i]->device);
  421. }
  422. return hsi;
  423. out:
  424. hsi_put_controller(hsi);
  425. return NULL;
  426. }
  427. EXPORT_SYMBOL_GPL(hsi_alloc_controller);
  428. /**
  429. * hsi_free_msg - Free an HSI message
  430. * @msg: Pointer to the HSI message
  431. *
  432. * Client is responsible to free the buffers pointed by the scatterlists.
  433. */
  434. void hsi_free_msg(struct hsi_msg *msg)
  435. {
  436. if (!msg)
  437. return;
  438. sg_free_table(&msg->sgt);
  439. kfree(msg);
  440. }
  441. EXPORT_SYMBOL_GPL(hsi_free_msg);
  442. /**
  443. * hsi_alloc_msg - Allocate an HSI message
  444. * @nents: Number of memory entries
  445. * @flags: Kernel allocation flags
  446. *
  447. * nents can be 0. This mainly makes sense for read transfer.
  448. * In that case, HSI drivers will call the complete callback when
  449. * there is data to be read without consuming it.
  450. *
  451. * Return NULL on failure or a pointer to an hsi_msg on success.
  452. */
  453. struct hsi_msg *hsi_alloc_msg(unsigned int nents, gfp_t flags)
  454. {
  455. struct hsi_msg *msg;
  456. int err;
  457. msg = kzalloc(sizeof(*msg), flags);
  458. if (!msg)
  459. return NULL;
  460. if (!nents)
  461. return msg;
  462. err = sg_alloc_table(&msg->sgt, nents, flags);
  463. if (unlikely(err)) {
  464. kfree(msg);
  465. msg = NULL;
  466. }
  467. return msg;
  468. }
  469. EXPORT_SYMBOL_GPL(hsi_alloc_msg);
  470. /**
  471. * hsi_async - Submit an HSI transfer to the controller
  472. * @cl: HSI client sending the transfer
  473. * @msg: The HSI transfer passed to controller
  474. *
  475. * The HSI message must have the channel, ttype, complete and destructor
  476. * fields set beforehand. If nents > 0 then the client has to initialize
  477. * also the scatterlists to point to the buffers to write to or read from.
  478. *
  479. * HSI controllers relay on pre-allocated buffers from their clients and they
  480. * do not allocate buffers on their own.
  481. *
  482. * Once the HSI message transfer finishes, the HSI controller calls the
  483. * complete callback with the status and actual_len fields of the HSI message
  484. * updated. The complete callback can be called before returning from
  485. * hsi_async.
  486. *
  487. * Returns -errno on failure or 0 on success
  488. */
  489. int hsi_async(struct hsi_client *cl, struct hsi_msg *msg)
  490. {
  491. struct hsi_port *port = hsi_get_port(cl);
  492. if (!hsi_port_claimed(cl))
  493. return -EACCES;
  494. WARN_ON_ONCE(!msg->destructor || !msg->complete);
  495. msg->cl = cl;
  496. return port->async(msg);
  497. }
  498. EXPORT_SYMBOL_GPL(hsi_async);
  499. /**
  500. * hsi_claim_port - Claim the HSI client's port
  501. * @cl: HSI client that wants to claim its port
  502. * @share: Flag to indicate if the client wants to share the port or not.
  503. *
  504. * Returns -errno on failure, 0 on success.
  505. */
  506. int hsi_claim_port(struct hsi_client *cl, unsigned int share)
  507. {
  508. struct hsi_port *port = hsi_get_port(cl);
  509. int err = 0;
  510. mutex_lock(&port->lock);
  511. if ((port->claimed) && (!port->shared || !share)) {
  512. err = -EBUSY;
  513. goto out;
  514. }
  515. if (!try_module_get(to_hsi_controller(port->device.parent)->owner)) {
  516. err = -ENODEV;
  517. goto out;
  518. }
  519. port->claimed++;
  520. port->shared = !!share;
  521. cl->pclaimed = 1;
  522. out:
  523. mutex_unlock(&port->lock);
  524. return err;
  525. }
  526. EXPORT_SYMBOL_GPL(hsi_claim_port);
  527. /**
  528. * hsi_release_port - Release the HSI client's port
  529. * @cl: HSI client which previously claimed its port
  530. */
  531. void hsi_release_port(struct hsi_client *cl)
  532. {
  533. struct hsi_port *port = hsi_get_port(cl);
  534. mutex_lock(&port->lock);
  535. /* Allow HW driver to do some cleanup */
  536. port->release(cl);
  537. if (cl->pclaimed)
  538. port->claimed--;
  539. BUG_ON(port->claimed < 0);
  540. cl->pclaimed = 0;
  541. if (!port->claimed)
  542. port->shared = 0;
  543. module_put(to_hsi_controller(port->device.parent)->owner);
  544. mutex_unlock(&port->lock);
  545. }
  546. EXPORT_SYMBOL_GPL(hsi_release_port);
  547. static int hsi_event_notifier_call(struct notifier_block *nb,
  548. unsigned long event, void *data __maybe_unused)
  549. {
  550. struct hsi_client *cl = container_of(nb, struct hsi_client, nb);
  551. (*cl->ehandler)(cl, event);
  552. return 0;
  553. }
  554. /**
  555. * hsi_register_port_event - Register a client to receive port events
  556. * @cl: HSI client that wants to receive port events
  557. * @handler: Event handler callback
  558. *
  559. * Clients should register a callback to be able to receive
  560. * events from the ports. Registration should happen after
  561. * claiming the port.
  562. * The handler can be called in interrupt context.
  563. *
  564. * Returns -errno on error, or 0 on success.
  565. */
  566. int hsi_register_port_event(struct hsi_client *cl,
  567. void (*handler)(struct hsi_client *, unsigned long))
  568. {
  569. struct hsi_port *port = hsi_get_port(cl);
  570. if (!handler || cl->ehandler)
  571. return -EINVAL;
  572. if (!hsi_port_claimed(cl))
  573. return -EACCES;
  574. cl->ehandler = handler;
  575. cl->nb.notifier_call = hsi_event_notifier_call;
  576. return blocking_notifier_chain_register(&port->n_head, &cl->nb);
  577. }
  578. EXPORT_SYMBOL_GPL(hsi_register_port_event);
  579. /**
  580. * hsi_unregister_port_event - Stop receiving port events for a client
  581. * @cl: HSI client that wants to stop receiving port events
  582. *
  583. * Clients should call this function before releasing their associated
  584. * port.
  585. *
  586. * Returns -errno on error, or 0 on success.
  587. */
  588. int hsi_unregister_port_event(struct hsi_client *cl)
  589. {
  590. struct hsi_port *port = hsi_get_port(cl);
  591. int err;
  592. WARN_ON(!hsi_port_claimed(cl));
  593. err = blocking_notifier_chain_unregister(&port->n_head, &cl->nb);
  594. if (!err)
  595. cl->ehandler = NULL;
  596. return err;
  597. }
  598. EXPORT_SYMBOL_GPL(hsi_unregister_port_event);
  599. /**
  600. * hsi_event - Notifies clients about port events
  601. * @port: Port where the event occurred
  602. * @event: The event type
  603. *
  604. * Clients should not be concerned about wake line behavior. However, due
  605. * to a race condition in HSI HW protocol, clients need to be notified
  606. * about wake line changes, so they can implement a workaround for it.
  607. *
  608. * Events:
  609. * HSI_EVENT_START_RX - Incoming wake line high
  610. * HSI_EVENT_STOP_RX - Incoming wake line down
  611. *
  612. * Returns -errno on error, or 0 on success.
  613. */
  614. int hsi_event(struct hsi_port *port, unsigned long event)
  615. {
  616. return blocking_notifier_call_chain(&port->n_head, event, NULL);
  617. }
  618. EXPORT_SYMBOL_GPL(hsi_event);
  619. /**
  620. * hsi_get_channel_id_by_name - acquire channel id by channel name
  621. * @cl: HSI client, which uses the channel
  622. * @name: name the channel is known under
  623. *
  624. * Clients can call this function to get the hsi channel ids similar to
  625. * requesting IRQs or GPIOs by name. This function assumes the same
  626. * channel configuration is used for RX and TX.
  627. *
  628. * Returns -errno on error or channel id on success.
  629. */
  630. int hsi_get_channel_id_by_name(struct hsi_client *cl, char *name)
  631. {
  632. int i;
  633. if (!cl->rx_cfg.channels)
  634. return -ENOENT;
  635. for (i = 0; i < cl->rx_cfg.num_channels; i++)
  636. if (!strcmp(cl->rx_cfg.channels[i].name, name))
  637. return cl->rx_cfg.channels[i].id;
  638. return -ENXIO;
  639. }
  640. EXPORT_SYMBOL_GPL(hsi_get_channel_id_by_name);
  641. static int __init hsi_init(void)
  642. {
  643. return bus_register(&hsi_bus_type);
  644. }
  645. postcore_initcall(hsi_init);
  646. static void __exit hsi_exit(void)
  647. {
  648. bus_unregister(&hsi_bus_type);
  649. }
  650. module_exit(hsi_exit);
  651. MODULE_AUTHOR("Carlos Chinea <carlos.chinea@nokia.com>");
  652. MODULE_DESCRIPTION("High-speed Synchronous Serial Interface (HSI) framework");
  653. MODULE_LICENSE("GPL v2");