eda9485459171c22a768c9db0e3739257d028251
[cascardo/linux.git] / drivers / staging / greybus / kernel_ver.h
1 /*
2  * Greybus kernel "version" glue logic.
3  *
4  * Copyright 2014 Google Inc.
5  * Copyright 2014 Linaro Ltd.
6  *
7  * Released under the GPLv2 only.
8  *
9  * Backports of newer kernel apis to allow the code to build properly on older
10  * kernel versions.  Remove this file when merging to upstream, it should not be
11  * needed at all
12  */
13
14 #ifndef __GREYBUS_KERNEL_VER_H
15 #define __GREYBUS_KERNEL_VER_H
16
17 #include <linux/kernel.h>
18 #include <linux/version.h>
19
20 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)
21 /* Commit: 297d716 power_supply: Change ownership from driver to core */
22 #define CORE_OWNS_PSY_STRUCT
23 #endif
24
25 /*
26  * The GPIO api sucks rocks in places, like removal, so work around their
27  * explicit requirements of catching the return value for kernels older than
28  * 3.17, which they explicitly changed in the 3.17 kernel.  Consistency is
29  * overrated.
30  */
31 #include <linux/gpio.h>
32
33 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)
34 static inline void gb_gpiochip_remove(struct gpio_chip *chip)
35 {
36         gpiochip_remove(chip);
37 }
38 #else
39 static inline void gb_gpiochip_remove(struct gpio_chip *chip)
40 {
41         int ret;
42
43         ret = gpiochip_remove(chip);
44 }
45 #endif
46
47 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 15, 0)
48 #define MMC_HS400_SUPPORTED
49 #define MMC_DDR52_DEFINED
50 #endif
51
52 #ifndef MMC_CAP2_CORE_RUNTIME_PM
53 #define MMC_CAP2_CORE_RUNTIME_PM        0
54 #endif
55
56 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)
57 #define MMC_POWER_UNDEFINED_SUPPORTED
58 #endif
59
60 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
61 /*
62  * At this time the internal API for the set brightness was changed to the async
63  * version, and one sync API was added to handle cases that need immediate
64  * effect. Also, the led class flash and lock for sysfs access was introduced.
65  */
66 #define LED_HAVE_SET_SYNC
67 #define LED_HAVE_FLASH
68 #define LED_HAVE_LOCK
69 #include <linux/led-class-flash.h>
70 #endif
71
72 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0)
73 /*
74  * New change in LED api, the set_sync operation was renamed to set_blocking and
75  * the workqueue is now handle by core. So, only one set operation is need.
76  */
77 #undef LED_HAVE_SET_SYNC
78 #define LED_HAVE_SET_BLOCKING
79 #endif
80
81 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
82 /*
83  * New helper functions for registering/unregistering flash led devices as v4l2
84  * subdevices were added.
85  */
86 #define V4L2_HAVE_FLASH
87 #include <media/v4l2-flash-led-class.h>
88 #endif
89
90 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)
91 /*
92  * Power supply get by name need to drop reference after call
93  */
94 #define PSY_HAVE_PUT
95 #endif
96
97 /*
98  * General power supply properties that could be absent from various reasons,
99  * like kernel versions or vendor specific versions
100  */
101 #ifndef POWER_SUPPLY_PROP_VOLTAGE_BOOT
102         #define POWER_SUPPLY_PROP_VOLTAGE_BOOT  -1
103 #endif
104 #ifndef POWER_SUPPLY_PROP_CURRENT_BOOT
105         #define POWER_SUPPLY_PROP_CURRENT_BOOT  -1
106 #endif
107 #ifndef POWER_SUPPLY_PROP_CALIBRATE
108         #define POWER_SUPPLY_PROP_CALIBRATE     -1
109 #endif
110
111 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0)
112 #define SPI_DEV_MODALIAS "spidev"
113 #define SPI_NOR_MODALIAS "spi-nor"
114 #else
115 #define SPI_DEV_MODALIAS "spidev"
116 #define SPI_NOR_MODALIAS "m25p80"
117 #endif
118
119 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 12, 0)
120 /* Starting from this version, the spi core handles runtime pm automatically */
121 #define SPI_CORE_SUPPORT_PM
122 #endif
123
124 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
125 /*
126  * After commit b2b49ccbdd54 (PM: Kconfig: Set PM_RUNTIME if PM_SLEEP is
127  * selected) PM_RUNTIME is always set if PM is set, so files that are build
128  * conditionally if CONFIG_PM_RUNTIME is set may now be build if CONFIG_PM is
129  * set.
130  */
131
132 #ifdef CONFIG_PM
133 #define CONFIG_PM_RUNTIME
134 #endif /* CONFIG_PM */
135 #endif
136
137 #endif  /* __GREYBUS_KERNEL_VER_H */