blob: 664f13dd06ed435717363d99c9c86ef2fc7a9ee4 [file] [log] [blame]
Dan Streetman3e648cb2015-05-28 16:21:31 -04001
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 */
12static struct nx842_driver *driver;
13static DEFINE_SPINLOCK(driver_lock);
14
15struct nx842_driver *nx842_platform_driver(void)
16{
17 return driver;
18}
19EXPORT_SYMBOL_GPL(nx842_platform_driver);
20
21bool 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}
37EXPORT_SYMBOL_GPL(nx842_platform_driver_set);
38
39/* only call this from the platform driver exit function */
40void 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}
54EXPORT_SYMBOL_GPL(nx842_platform_driver_unset);
55
56bool 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}
69EXPORT_SYMBOL_GPL(nx842_platform_driver_get);
70
71void 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}
80EXPORT_SYMBOL_GPL(nx842_platform_driver_put);
81
82MODULE_LICENSE("GPL");
83MODULE_AUTHOR("Dan Streetman <ddstreet@ieee.org>");
84MODULE_DESCRIPTION("842 H/W Compression platform driver");