diff options
Diffstat (limited to 'drivers/crypto/nx/nx-842-platform.c')
-rw-r--r-- | drivers/crypto/nx/nx-842-platform.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/drivers/crypto/nx/nx-842-platform.c b/drivers/crypto/nx/nx-842-platform.c new file mode 100644 index 000000000000..664f13dd06ed --- /dev/null +++ b/drivers/crypto/nx/nx-842-platform.c | |||
@@ -0,0 +1,84 @@ | |||
1 | |||
2 | #include "nx-842.h" | ||
3 | |||
4 | /* this is needed, separate from the main nx-842.c driver, because that main | ||
5 | * driver loads the platform drivers during its init(), and it expects one | ||
6 | * (or none) of the platform drivers to set this pointer to its driver. | ||
7 | * That means this pointer can't be in the main nx-842 driver, because it | ||
8 | * wouldn't be accessible until after the main driver loaded, which wouldn't | ||
9 | * be possible as it's waiting for the platform driver to load. So place it | ||
10 | * here. | ||
11 | */ | ||
12 | static struct nx842_driver *driver; | ||
13 | static DEFINE_SPINLOCK(driver_lock); | ||
14 | |||
15 | struct nx842_driver *nx842_platform_driver(void) | ||
16 | { | ||
17 | return driver; | ||
18 | } | ||
19 | EXPORT_SYMBOL_GPL(nx842_platform_driver); | ||
20 | |||
21 | bool nx842_platform_driver_set(struct nx842_driver *_driver) | ||
22 | { | ||
23 | bool ret = false; | ||
24 | |||
25 | spin_lock(&driver_lock); | ||
26 | |||
27 | if (!driver) { | ||
28 | driver = _driver; | ||
29 | ret = true; | ||
30 | } else | ||
31 | WARN(1, "can't set platform driver, already set to %s\n", | ||
32 | driver->name); | ||
33 | |||
34 | spin_unlock(&driver_lock); | ||
35 | return ret; | ||
36 | } | ||
37 | EXPORT_SYMBOL_GPL(nx842_platform_driver_set); | ||
38 | |||
39 | /* only call this from the platform driver exit function */ | ||
40 | void nx842_platform_driver_unset(struct nx842_driver *_driver) | ||
41 | { | ||
42 | spin_lock(&driver_lock); | ||
43 | |||
44 | if (driver == _driver) | ||
45 | driver = NULL; | ||
46 | else if (driver) | ||
47 | WARN(1, "can't unset platform driver %s, currently set to %s\n", | ||
48 | _driver->name, driver->name); | ||
49 | else | ||
50 | WARN(1, "can't unset platform driver, already unset\n"); | ||
51 | |||
52 | spin_unlock(&driver_lock); | ||
53 | } | ||
54 | EXPORT_SYMBOL_GPL(nx842_platform_driver_unset); | ||
55 | |||
56 | bool nx842_platform_driver_get(void) | ||
57 | { | ||
58 | bool ret = false; | ||
59 | |||
60 | spin_lock(&driver_lock); | ||
61 | |||
62 | if (driver) | ||
63 | ret = try_module_get(driver->owner); | ||
64 | |||
65 | spin_unlock(&driver_lock); | ||
66 | |||
67 | return ret; | ||
68 | } | ||
69 | EXPORT_SYMBOL_GPL(nx842_platform_driver_get); | ||
70 | |||
71 | void nx842_platform_driver_put(void) | ||
72 | { | ||
73 | spin_lock(&driver_lock); | ||
74 | |||
75 | if (driver) | ||
76 | module_put(driver->owner); | ||
77 | |||
78 | spin_unlock(&driver_lock); | ||
79 | } | ||
80 | EXPORT_SYMBOL_GPL(nx842_platform_driver_put); | ||
81 | |||
82 | MODULE_LICENSE("GPL"); | ||
83 | MODULE_AUTHOR("Dan Streetman <ddstreet@ieee.org>"); | ||
84 | MODULE_DESCRIPTION("842 H/W Compression platform driver"); | ||