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 | ||
faf0b116 JK |
25 | struct fsi_slave { |
26 | struct device dev; | |
27 | struct fsi_master *master; | |
28 | int id; | |
29 | int link; | |
30 | uint32_t size; /* size of slave address space */ | |
31 | }; | |
32 | ||
33 | #define to_fsi_slave(d) container_of(d, struct fsi_slave, dev) | |
34 | ||
09aecfab JK |
35 | /* FSI master support */ |
36 | int fsi_master_register(struct fsi_master *master) | |
37 | { | |
38 | int rc; | |
39 | ||
40 | if (!master) | |
41 | return -EINVAL; | |
42 | ||
43 | master->idx = ida_simple_get(&master_ida, 0, INT_MAX, GFP_KERNEL); | |
44 | dev_set_name(&master->dev, "fsi%d", master->idx); | |
45 | ||
46 | rc = device_register(&master->dev); | |
47 | if (rc) | |
48 | ida_simple_remove(&master_ida, master->idx); | |
49 | ||
50 | return rc; | |
51 | } | |
52 | EXPORT_SYMBOL_GPL(fsi_master_register); | |
53 | ||
54 | void fsi_master_unregister(struct fsi_master *master) | |
55 | { | |
56 | if (master->idx >= 0) { | |
57 | ida_simple_remove(&master_ida, master->idx); | |
58 | master->idx = -1; | |
59 | } | |
60 | ||
61 | device_unregister(&master->dev); | |
62 | } | |
63 | EXPORT_SYMBOL_GPL(fsi_master_unregister); | |
64 | ||
0508ad1f JK |
65 | /* FSI core & Linux bus type definitions */ |
66 | ||
dd37eed7 JK |
67 | static int fsi_bus_match(struct device *dev, struct device_driver *drv) |
68 | { | |
69 | struct fsi_device *fsi_dev = to_fsi_dev(dev); | |
70 | struct fsi_driver *fsi_drv = to_fsi_drv(drv); | |
71 | const struct fsi_device_id *id; | |
72 | ||
73 | if (!fsi_drv->id_table) | |
74 | return 0; | |
75 | ||
76 | for (id = fsi_drv->id_table; id->engine_type; id++) { | |
77 | if (id->engine_type != fsi_dev->engine_type) | |
78 | continue; | |
79 | if (id->version == FSI_VERSION_ANY || | |
80 | id->version == fsi_dev->version) | |
81 | return 1; | |
82 | } | |
83 | ||
84 | return 0; | |
85 | } | |
86 | ||
0508ad1f JK |
87 | struct bus_type fsi_bus_type = { |
88 | .name = "fsi", | |
dd37eed7 | 89 | .match = fsi_bus_match, |
0508ad1f JK |
90 | }; |
91 | EXPORT_SYMBOL_GPL(fsi_bus_type); | |
92 | ||
93 | static int fsi_init(void) | |
94 | { | |
95 | return bus_register(&fsi_bus_type); | |
96 | } | |
97 | ||
98 | static void fsi_exit(void) | |
99 | { | |
100 | bus_unregister(&fsi_bus_type); | |
101 | } | |
102 | ||
103 | module_init(fsi_init); | |
104 | module_exit(fsi_exit); |