]>
Commit | Line | Data |
---|---|---|
0508ad1f JK |
1 | /* |
2 | * FSI core driver | |
3 | * | |
4 | * Copyright (C) IBM Corporation 2016 | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License version 2 as | |
8 | * published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | */ | |
15 | ||
16 | #include <linux/device.h> | |
17 | #include <linux/fsi.h> | |
09aecfab | 18 | #include <linux/idr.h> |
0508ad1f JK |
19 | #include <linux/module.h> |
20 | ||
09aecfab JK |
21 | #include "fsi-master.h" |
22 | ||
23 | static DEFINE_IDA(master_ida); | |
24 | ||
25 | /* FSI master support */ | |
26 | int fsi_master_register(struct fsi_master *master) | |
27 | { | |
28 | int rc; | |
29 | ||
30 | if (!master) | |
31 | return -EINVAL; | |
32 | ||
33 | master->idx = ida_simple_get(&master_ida, 0, INT_MAX, GFP_KERNEL); | |
34 | dev_set_name(&master->dev, "fsi%d", master->idx); | |
35 | ||
36 | rc = device_register(&master->dev); | |
37 | if (rc) | |
38 | ida_simple_remove(&master_ida, master->idx); | |
39 | ||
40 | return rc; | |
41 | } | |
42 | EXPORT_SYMBOL_GPL(fsi_master_register); | |
43 | ||
44 | void fsi_master_unregister(struct fsi_master *master) | |
45 | { | |
46 | if (master->idx >= 0) { | |
47 | ida_simple_remove(&master_ida, master->idx); | |
48 | master->idx = -1; | |
49 | } | |
50 | ||
51 | device_unregister(&master->dev); | |
52 | } | |
53 | EXPORT_SYMBOL_GPL(fsi_master_unregister); | |
54 | ||
0508ad1f JK |
55 | /* FSI core & Linux bus type definitions */ |
56 | ||
dd37eed7 JK |
57 | static int fsi_bus_match(struct device *dev, struct device_driver *drv) |
58 | { | |
59 | struct fsi_device *fsi_dev = to_fsi_dev(dev); | |
60 | struct fsi_driver *fsi_drv = to_fsi_drv(drv); | |
61 | const struct fsi_device_id *id; | |
62 | ||
63 | if (!fsi_drv->id_table) | |
64 | return 0; | |
65 | ||
66 | for (id = fsi_drv->id_table; id->engine_type; id++) { | |
67 | if (id->engine_type != fsi_dev->engine_type) | |
68 | continue; | |
69 | if (id->version == FSI_VERSION_ANY || | |
70 | id->version == fsi_dev->version) | |
71 | return 1; | |
72 | } | |
73 | ||
74 | return 0; | |
75 | } | |
76 | ||
0508ad1f JK |
77 | struct bus_type fsi_bus_type = { |
78 | .name = "fsi", | |
dd37eed7 | 79 | .match = fsi_bus_match, |
0508ad1f JK |
80 | }; |
81 | EXPORT_SYMBOL_GPL(fsi_bus_type); | |
82 | ||
83 | static int fsi_init(void) | |
84 | { | |
85 | return bus_register(&fsi_bus_type); | |
86 | } | |
87 | ||
88 | static void fsi_exit(void) | |
89 | { | |
90 | bus_unregister(&fsi_bus_type); | |
91 | } | |
92 | ||
93 | module_init(fsi_init); | |
94 | module_exit(fsi_exit); |