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