Linux 4.2.1
[linux/fpc-iii.git] / drivers / crypto / nx / nx-842-platform.c
blob664f13dd06ed435717363d99c9c86ef2fc7a9ee4
2 #include "nx-842.h"
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.
12 static struct nx842_driver *driver;
13 static DEFINE_SPINLOCK(driver_lock);
15 struct nx842_driver *nx842_platform_driver(void)
17 return driver;
19 EXPORT_SYMBOL_GPL(nx842_platform_driver);
21 bool nx842_platform_driver_set(struct nx842_driver *_driver)
23 bool ret = false;
25 spin_lock(&driver_lock);
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);
34 spin_unlock(&driver_lock);
35 return ret;
37 EXPORT_SYMBOL_GPL(nx842_platform_driver_set);
39 /* only call this from the platform driver exit function */
40 void nx842_platform_driver_unset(struct nx842_driver *_driver)
42 spin_lock(&driver_lock);
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");
52 spin_unlock(&driver_lock);
54 EXPORT_SYMBOL_GPL(nx842_platform_driver_unset);
56 bool nx842_platform_driver_get(void)
58 bool ret = false;
60 spin_lock(&driver_lock);
62 if (driver)
63 ret = try_module_get(driver->owner);
65 spin_unlock(&driver_lock);
67 return ret;
69 EXPORT_SYMBOL_GPL(nx842_platform_driver_get);
71 void nx842_platform_driver_put(void)
73 spin_lock(&driver_lock);
75 if (driver)
76 module_put(driver->owner);
78 spin_unlock(&driver_lock);
80 EXPORT_SYMBOL_GPL(nx842_platform_driver_put);
82 MODULE_LICENSE("GPL");
83 MODULE_AUTHOR("Dan Streetman <ddstreet@ieee.org>");
84 MODULE_DESCRIPTION("842 H/W Compression platform driver");