MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 1 | /* |
Chanwoo Choi | b9ec23c | 2015-04-24 14:48:52 +0900 | [diff] [blame] | 2 | * drivers/extcon/extcon.c - External Connector (extcon) framework. |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 3 | * |
| 4 | * External connector (extcon) class driver |
| 5 | * |
Chanwoo Choi | 2a9de9c | 2015-04-24 19:16:05 +0900 | [diff] [blame] | 6 | * Copyright (C) 2015 Samsung Electronics |
| 7 | * Author: Chanwoo Choi <cw00.choi@samsung.com> |
| 8 | * |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 9 | * Copyright (C) 2012 Samsung Electronics |
| 10 | * Author: Donggeun Kim <dg77.kim@samsung.com> |
| 11 | * Author: MyungJoo Ham <myungjoo.ham@samsung.com> |
| 12 | * |
| 13 | * based on android/drivers/switch/switch_class.c |
| 14 | * Copyright (C) 2008 Google, Inc. |
| 15 | * Author: Mike Lockwood <lockwood@android.com> |
| 16 | * |
| 17 | * This software is licensed under the terms of the GNU General Public |
| 18 | * License version 2, as published by the Free Software Foundation, and |
| 19 | * may be copied, distributed, and modified under those terms. |
| 20 | * |
| 21 | * This program is distributed in the hope that it will be useful, |
| 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | * GNU General Public License for more details. |
Chanwoo Choi | b9ec23c | 2015-04-24 14:48:52 +0900 | [diff] [blame] | 25 | */ |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 26 | |
| 27 | #include <linux/module.h> |
| 28 | #include <linux/types.h> |
| 29 | #include <linux/init.h> |
| 30 | #include <linux/device.h> |
| 31 | #include <linux/fs.h> |
| 32 | #include <linux/err.h> |
| 33 | #include <linux/extcon.h> |
Tomasz Figa | f841afb1 | 2014-10-16 15:11:44 +0200 | [diff] [blame] | 34 | #include <linux/of.h> |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 35 | #include <linux/slab.h> |
Mark Brown | 9baf322 | 2012-08-16 20:03:21 +0100 | [diff] [blame] | 36 | #include <linux/sysfs.h> |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 37 | |
Chanwoo Choi | 2a9de9c | 2015-04-24 19:16:05 +0900 | [diff] [blame] | 38 | #define SUPPORTED_CABLE_MAX 32 |
| 39 | #define CABLE_NAME_MAX 30 |
| 40 | |
| 41 | static const char *extcon_name[] = { |
Chanwoo Choi | 11eecf9 | 2015-10-03 14:15:13 +0900 | [diff] [blame] | 42 | [EXTCON_NONE] = "NONE", |
Chanwoo Choi | 73b6ecd | 2015-06-12 11:10:06 +0900 | [diff] [blame] | 43 | |
Chanwoo Choi | 8e9bc36 | 2015-05-19 19:58:49 +0900 | [diff] [blame] | 44 | /* USB external connector */ |
Chanwoo Choi | 11eecf9 | 2015-10-03 14:15:13 +0900 | [diff] [blame] | 45 | [EXTCON_USB] = "USB", |
| 46 | [EXTCON_USB_HOST] = "USB-HOST", |
Chanwoo Choi | 8e9bc36 | 2015-05-19 19:58:49 +0900 | [diff] [blame] | 47 | |
Chanwoo Choi | 11eecf9 | 2015-10-03 14:15:13 +0900 | [diff] [blame] | 48 | /* Charging external connector */ |
| 49 | [EXTCON_CHG_USB_SDP] = "SDP", |
| 50 | [EXTCON_CHG_USB_DCP] = "DCP", |
| 51 | [EXTCON_CHG_USB_CDP] = "CDP", |
| 52 | [EXTCON_CHG_USB_ACA] = "ACA", |
| 53 | [EXTCON_CHG_USB_FAST] = "FAST-CHARGER", |
| 54 | [EXTCON_CHG_USB_SLOW] = "SLOW-CHARGER", |
Chanwoo Choi | 8e9bc36 | 2015-05-19 19:58:49 +0900 | [diff] [blame] | 55 | |
Chanwoo Choi | 11eecf9 | 2015-10-03 14:15:13 +0900 | [diff] [blame] | 56 | /* Jack external connector */ |
| 57 | [EXTCON_JACK_MICROPHONE] = "MICROPHONE", |
| 58 | [EXTCON_JACK_HEADPHONE] = "HEADPHONE", |
| 59 | [EXTCON_JACK_LINE_IN] = "LINE-IN", |
| 60 | [EXTCON_JACK_LINE_OUT] = "LINE-OUT", |
| 61 | [EXTCON_JACK_VIDEO_IN] = "VIDEO-IN", |
| 62 | [EXTCON_JACK_VIDEO_OUT] = "VIDEO-OUT", |
| 63 | [EXTCON_JACK_SPDIF_IN] = "SPDIF-IN", |
| 64 | [EXTCON_JACK_SPDIF_OUT] = "SPDIF-OUT", |
Chanwoo Choi | 8e9bc36 | 2015-05-19 19:58:49 +0900 | [diff] [blame] | 65 | |
Chanwoo Choi | 11eecf9 | 2015-10-03 14:15:13 +0900 | [diff] [blame] | 66 | /* Display external connector */ |
| 67 | [EXTCON_DISP_HDMI] = "HDMI", |
| 68 | [EXTCON_DISP_MHL] = "MHL", |
| 69 | [EXTCON_DISP_DVI] = "DVI", |
| 70 | [EXTCON_DISP_VGA] = "VGA", |
Chanwoo Choi | 8e9bc36 | 2015-05-19 19:58:49 +0900 | [diff] [blame] | 71 | |
Chanwoo Choi | 11eecf9 | 2015-10-03 14:15:13 +0900 | [diff] [blame] | 72 | /* Miscellaneous external connector */ |
| 73 | [EXTCON_DOCK] = "DOCK", |
| 74 | [EXTCON_JIG] = "JIG", |
| 75 | [EXTCON_MECHANICAL] = "MECHANICAL", |
Chanwoo Choi | 8e9bc36 | 2015-05-19 19:58:49 +0900 | [diff] [blame] | 76 | |
Chanwoo Choi | 2a9de9c | 2015-04-24 19:16:05 +0900 | [diff] [blame] | 77 | NULL, |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 78 | }; |
| 79 | |
Mark Brown | be3a07f | 2012-06-05 16:14:38 +0100 | [diff] [blame] | 80 | static struct class *extcon_class; |
MyungJoo Ham | 449a2bf | 2012-04-23 20:19:57 +0900 | [diff] [blame] | 81 | #if defined(CONFIG_ANDROID) |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 82 | static struct class_compat *switch_class; |
MyungJoo Ham | 449a2bf | 2012-04-23 20:19:57 +0900 | [diff] [blame] | 83 | #endif /* CONFIG_ANDROID */ |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 84 | |
Donggeun Kim | 74c5d09 | 2012-04-20 14:16:24 +0900 | [diff] [blame] | 85 | static LIST_HEAD(extcon_dev_list); |
| 86 | static DEFINE_MUTEX(extcon_dev_list_lock); |
| 87 | |
MyungJoo Ham | bde68e6 | 2012-04-20 14:16:26 +0900 | [diff] [blame] | 88 | /** |
| 89 | * check_mutually_exclusive - Check if new_state violates mutually_exclusive |
Chanwoo Choi | a75e1c7 | 2013-08-31 13:16:49 +0900 | [diff] [blame] | 90 | * condition. |
MyungJoo Ham | bde68e6 | 2012-04-20 14:16:26 +0900 | [diff] [blame] | 91 | * @edev: the extcon device |
| 92 | * @new_state: new cable attach status for @edev |
| 93 | * |
| 94 | * Returns 0 if nothing violates. Returns the index + 1 for the first |
| 95 | * violated condition. |
| 96 | */ |
| 97 | static int check_mutually_exclusive(struct extcon_dev *edev, u32 new_state) |
| 98 | { |
| 99 | int i = 0; |
| 100 | |
| 101 | if (!edev->mutually_exclusive) |
| 102 | return 0; |
| 103 | |
| 104 | for (i = 0; edev->mutually_exclusive[i]; i++) { |
anish kumar | 28c0ada | 2012-08-30 00:35:10 +0530 | [diff] [blame] | 105 | int weight; |
MyungJoo Ham | bde68e6 | 2012-04-20 14:16:26 +0900 | [diff] [blame] | 106 | u32 correspondants = new_state & edev->mutually_exclusive[i]; |
MyungJoo Ham | bde68e6 | 2012-04-20 14:16:26 +0900 | [diff] [blame] | 107 | |
anish kumar | 28c0ada | 2012-08-30 00:35:10 +0530 | [diff] [blame] | 108 | /* calculate the total number of bits set */ |
| 109 | weight = hweight32(correspondants); |
| 110 | if (weight > 1) |
| 111 | return i + 1; |
MyungJoo Ham | bde68e6 | 2012-04-20 14:16:26 +0900 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | return 0; |
| 115 | } |
| 116 | |
Chanwoo Choi | 73b6ecd | 2015-06-12 11:10:06 +0900 | [diff] [blame] | 117 | static int find_cable_index_by_id(struct extcon_dev *edev, const unsigned int id) |
Chanwoo Choi | 2a9de9c | 2015-04-24 19:16:05 +0900 | [diff] [blame] | 118 | { |
| 119 | int i; |
| 120 | |
| 121 | /* Find the the index of extcon cable in edev->supported_cable */ |
| 122 | for (i = 0; i < edev->max_supported; i++) { |
| 123 | if (edev->supported_cable[i] == id) |
| 124 | return i; |
| 125 | } |
| 126 | |
| 127 | return -EINVAL; |
| 128 | } |
| 129 | |
Chanwoo Choi | 046050f | 2015-05-19 20:01:12 +0900 | [diff] [blame] | 130 | static bool is_extcon_changed(u32 prev, u32 new, int idx, bool *attached) |
| 131 | { |
| 132 | if (((prev >> idx) & 0x1) != ((new >> idx) & 0x1)) { |
Hans de Goede | f4513b0 | 2015-08-24 00:35:36 +0200 | [diff] [blame] | 133 | *attached = ((new >> idx) & 0x1) ? true : false; |
Chanwoo Choi | 046050f | 2015-05-19 20:01:12 +0900 | [diff] [blame] | 134 | return true; |
| 135 | } |
| 136 | |
| 137 | return false; |
| 138 | } |
| 139 | |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 140 | static ssize_t state_show(struct device *dev, struct device_attribute *attr, |
| 141 | char *buf) |
| 142 | { |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 143 | int i, count = 0; |
Jingoo Han | cb8bb3a | 2013-09-09 14:33:32 +0900 | [diff] [blame] | 144 | struct extcon_dev *edev = dev_get_drvdata(dev); |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 145 | |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 146 | if (edev->max_supported == 0) |
| 147 | return sprintf(buf, "%u\n", edev->state); |
| 148 | |
Chanwoo Choi | 2a9de9c | 2015-04-24 19:16:05 +0900 | [diff] [blame] | 149 | for (i = 0; i < edev->max_supported; i++) { |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 150 | count += sprintf(buf + count, "%s=%d\n", |
Chanwoo Choi | 2a9de9c | 2015-04-24 19:16:05 +0900 | [diff] [blame] | 151 | extcon_name[edev->supported_cable[i]], |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 152 | !!(edev->state & (1 << i))); |
| 153 | } |
| 154 | |
| 155 | return count; |
| 156 | } |
| 157 | |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 158 | static ssize_t state_store(struct device *dev, struct device_attribute *attr, |
| 159 | const char *buf, size_t count) |
| 160 | { |
| 161 | u32 state; |
| 162 | ssize_t ret = 0; |
Jingoo Han | cb8bb3a | 2013-09-09 14:33:32 +0900 | [diff] [blame] | 163 | struct extcon_dev *edev = dev_get_drvdata(dev); |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 164 | |
| 165 | ret = sscanf(buf, "0x%x", &state); |
| 166 | if (ret == 0) |
| 167 | ret = -EINVAL; |
| 168 | else |
MyungJoo Ham | bde68e6 | 2012-04-20 14:16:26 +0900 | [diff] [blame] | 169 | ret = extcon_set_state(edev, state); |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 170 | |
| 171 | if (ret < 0) |
| 172 | return ret; |
| 173 | |
| 174 | return count; |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 175 | } |
Greg Kroah-Hartman | af01da0 | 2013-07-24 15:05:10 -0700 | [diff] [blame] | 176 | static DEVICE_ATTR_RW(state); |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 177 | |
| 178 | static ssize_t name_show(struct device *dev, struct device_attribute *attr, |
| 179 | char *buf) |
| 180 | { |
Jingoo Han | cb8bb3a | 2013-09-09 14:33:32 +0900 | [diff] [blame] | 181 | struct extcon_dev *edev = dev_get_drvdata(dev); |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 182 | |
Chanwoo Choi | 71c3ffa | 2015-04-15 15:02:01 +0900 | [diff] [blame] | 183 | return sprintf(buf, "%s\n", edev->name); |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 184 | } |
Greg Kroah-Hartman | af01da0 | 2013-07-24 15:05:10 -0700 | [diff] [blame] | 185 | static DEVICE_ATTR_RO(name); |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 186 | |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 187 | static ssize_t cable_name_show(struct device *dev, |
| 188 | struct device_attribute *attr, char *buf) |
| 189 | { |
| 190 | struct extcon_cable *cable = container_of(attr, struct extcon_cable, |
| 191 | attr_name); |
Chanwoo Choi | 2a9de9c | 2015-04-24 19:16:05 +0900 | [diff] [blame] | 192 | int i = cable->cable_index; |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 193 | |
| 194 | return sprintf(buf, "%s\n", |
Chanwoo Choi | 2a9de9c | 2015-04-24 19:16:05 +0900 | [diff] [blame] | 195 | extcon_name[cable->edev->supported_cable[i]]); |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | static ssize_t cable_state_show(struct device *dev, |
| 199 | struct device_attribute *attr, char *buf) |
| 200 | { |
| 201 | struct extcon_cable *cable = container_of(attr, struct extcon_cable, |
| 202 | attr_state); |
| 203 | |
Roger Quadros | be052cc | 2015-07-07 16:06:15 +0300 | [diff] [blame] | 204 | int i = cable->cable_index; |
| 205 | |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 206 | return sprintf(buf, "%d\n", |
| 207 | extcon_get_cable_state_(cable->edev, |
Roger Quadros | be052cc | 2015-07-07 16:06:15 +0300 | [diff] [blame] | 208 | cable->edev->supported_cable[i])); |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 209 | } |
| 210 | |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 211 | /** |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 212 | * extcon_update_state() - Update the cable attach states of the extcon device |
Chanwoo Choi | a75e1c7 | 2013-08-31 13:16:49 +0900 | [diff] [blame] | 213 | * only for the masked bits. |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 214 | * @edev: the extcon device |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 215 | * @mask: the bit mask to designate updated bits. |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 216 | * @state: new cable attach status for @edev |
| 217 | * |
| 218 | * Changing the state sends uevent with environment variable containing |
| 219 | * the name of extcon device (envp[0]) and the state output (envp[1]). |
| 220 | * Tizen uses this format for extcon device to get events from ports. |
| 221 | * Android uses this format as well. |
Donggeun Kim | 74c5d09 | 2012-04-20 14:16:24 +0900 | [diff] [blame] | 222 | * |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 223 | * Note that the notifier provides which bits are changed in the state |
| 224 | * variable with the val parameter (second) to the callback. |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 225 | */ |
MyungJoo Ham | bde68e6 | 2012-04-20 14:16:26 +0900 | [diff] [blame] | 226 | int extcon_update_state(struct extcon_dev *edev, u32 mask, u32 state) |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 227 | { |
| 228 | char name_buf[120]; |
| 229 | char state_buf[120]; |
| 230 | char *prop_buf; |
| 231 | char *envp[3]; |
| 232 | int env_offset = 0; |
| 233 | int length; |
Chanwoo Choi | 046050f | 2015-05-19 20:01:12 +0900 | [diff] [blame] | 234 | int index; |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 235 | unsigned long flags; |
Chanwoo Choi | 046050f | 2015-05-19 20:01:12 +0900 | [diff] [blame] | 236 | bool attached; |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 237 | |
Chanwoo Choi | 7eae43a | 2015-06-21 23:48:36 +0900 | [diff] [blame] | 238 | if (!edev) |
| 239 | return -EINVAL; |
| 240 | |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 241 | spin_lock_irqsave(&edev->lock, flags); |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 242 | |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 243 | if (edev->state != ((edev->state & ~mask) | (state & mask))) { |
Roger Quadros | f7a8981 | 2015-07-06 17:46:58 +0300 | [diff] [blame] | 244 | u32 old_state; |
| 245 | |
MyungJoo Ham | bde68e6 | 2012-04-20 14:16:26 +0900 | [diff] [blame] | 246 | if (check_mutually_exclusive(edev, (edev->state & ~mask) | |
| 247 | (state & mask))) { |
| 248 | spin_unlock_irqrestore(&edev->lock, flags); |
| 249 | return -EPERM; |
| 250 | } |
| 251 | |
Roger Quadros | f7a8981 | 2015-07-06 17:46:58 +0300 | [diff] [blame] | 252 | old_state = edev->state; |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 253 | edev->state &= ~mask; |
| 254 | edev->state |= state & mask; |
| 255 | |
Roger Quadros | f7a8981 | 2015-07-06 17:46:58 +0300 | [diff] [blame] | 256 | for (index = 0; index < edev->max_supported; index++) { |
| 257 | if (is_extcon_changed(old_state, edev->state, index, |
| 258 | &attached)) |
| 259 | raw_notifier_call_chain(&edev->nh[index], |
| 260 | attached, edev); |
| 261 | } |
| 262 | |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 263 | /* This could be in interrupt handler */ |
| 264 | prop_buf = (char *)get_zeroed_page(GFP_ATOMIC); |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 265 | if (prop_buf) { |
Chanwoo Choi | dae6165 | 2013-09-27 09:19:40 +0900 | [diff] [blame] | 266 | length = name_show(&edev->dev, NULL, prop_buf); |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 267 | if (length > 0) { |
| 268 | if (prop_buf[length - 1] == '\n') |
| 269 | prop_buf[length - 1] = 0; |
| 270 | snprintf(name_buf, sizeof(name_buf), |
| 271 | "NAME=%s", prop_buf); |
| 272 | envp[env_offset++] = name_buf; |
| 273 | } |
Chanwoo Choi | dae6165 | 2013-09-27 09:19:40 +0900 | [diff] [blame] | 274 | length = state_show(&edev->dev, NULL, prop_buf); |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 275 | if (length > 0) { |
| 276 | if (prop_buf[length - 1] == '\n') |
| 277 | prop_buf[length - 1] = 0; |
| 278 | snprintf(state_buf, sizeof(state_buf), |
| 279 | "STATE=%s", prop_buf); |
| 280 | envp[env_offset++] = state_buf; |
| 281 | } |
| 282 | envp[env_offset] = NULL; |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 283 | /* Unlock early before uevent */ |
| 284 | spin_unlock_irqrestore(&edev->lock, flags); |
| 285 | |
Chanwoo Choi | dae6165 | 2013-09-27 09:19:40 +0900 | [diff] [blame] | 286 | kobject_uevent_env(&edev->dev.kobj, KOBJ_CHANGE, envp); |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 287 | free_page((unsigned long)prop_buf); |
| 288 | } else { |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 289 | /* Unlock early before uevent */ |
| 290 | spin_unlock_irqrestore(&edev->lock, flags); |
| 291 | |
Chanwoo Choi | dae6165 | 2013-09-27 09:19:40 +0900 | [diff] [blame] | 292 | dev_err(&edev->dev, "out of memory in extcon_set_state\n"); |
| 293 | kobject_uevent(&edev->dev.kobj, KOBJ_CHANGE); |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 294 | } |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 295 | } else { |
| 296 | /* No changes */ |
| 297 | spin_unlock_irqrestore(&edev->lock, flags); |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 298 | } |
MyungJoo Ham | bde68e6 | 2012-04-20 14:16:26 +0900 | [diff] [blame] | 299 | |
| 300 | return 0; |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 301 | } |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 302 | EXPORT_SYMBOL_GPL(extcon_update_state); |
| 303 | |
| 304 | /** |
| 305 | * extcon_set_state() - Set the cable attach states of the extcon device. |
| 306 | * @edev: the extcon device |
| 307 | * @state: new cable attach status for @edev |
| 308 | * |
| 309 | * Note that notifier provides which bits are changed in the state |
| 310 | * variable with the val parameter (second) to the callback. |
| 311 | */ |
MyungJoo Ham | bde68e6 | 2012-04-20 14:16:26 +0900 | [diff] [blame] | 312 | int extcon_set_state(struct extcon_dev *edev, u32 state) |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 313 | { |
Chanwoo Choi | 7eae43a | 2015-06-21 23:48:36 +0900 | [diff] [blame] | 314 | if (!edev) |
| 315 | return -EINVAL; |
| 316 | |
MyungJoo Ham | bde68e6 | 2012-04-20 14:16:26 +0900 | [diff] [blame] | 317 | return extcon_update_state(edev, 0xffffffff, state); |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 318 | } |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 319 | EXPORT_SYMBOL_GPL(extcon_set_state); |
| 320 | |
Donggeun Kim | 74c5d09 | 2012-04-20 14:16:24 +0900 | [diff] [blame] | 321 | /** |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 322 | * extcon_get_cable_state_() - Get the status of a specific cable. |
| 323 | * @edev: the extcon device that has the cable. |
Chanwoo Choi | 2a9de9c | 2015-04-24 19:16:05 +0900 | [diff] [blame] | 324 | * @id: the unique id of each external connector in extcon enumeration. |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 325 | */ |
Chanwoo Choi | 73b6ecd | 2015-06-12 11:10:06 +0900 | [diff] [blame] | 326 | int extcon_get_cable_state_(struct extcon_dev *edev, const unsigned int id) |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 327 | { |
Chanwoo Choi | 2a9de9c | 2015-04-24 19:16:05 +0900 | [diff] [blame] | 328 | int index; |
| 329 | |
Chanwoo Choi | 7eae43a | 2015-06-21 23:48:36 +0900 | [diff] [blame] | 330 | if (!edev) |
| 331 | return -EINVAL; |
| 332 | |
Chanwoo Choi | 2a9de9c | 2015-04-24 19:16:05 +0900 | [diff] [blame] | 333 | index = find_cable_index_by_id(edev, id); |
| 334 | if (index < 0) |
| 335 | return index; |
| 336 | |
| 337 | if (edev->max_supported && edev->max_supported <= index) |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 338 | return -EINVAL; |
| 339 | |
| 340 | return !!(edev->state & (1 << index)); |
| 341 | } |
| 342 | EXPORT_SYMBOL_GPL(extcon_get_cable_state_); |
| 343 | |
| 344 | /** |
Axel Lin | 909f9ec | 2012-10-04 09:53:45 +0900 | [diff] [blame] | 345 | * extcon_set_cable_state_() - Set the status of a specific cable. |
Chanwoo Choi | a75e1c7 | 2013-08-31 13:16:49 +0900 | [diff] [blame] | 346 | * @edev: the extcon device that has the cable. |
Chanwoo Choi | 2a9de9c | 2015-04-24 19:16:05 +0900 | [diff] [blame] | 347 | * @id: the unique id of each external connector |
| 348 | * in extcon enumeration. |
| 349 | * @state: the new cable status. The default semantics is |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 350 | * true: attached / false: detached. |
| 351 | */ |
Chanwoo Choi | 73b6ecd | 2015-06-12 11:10:06 +0900 | [diff] [blame] | 352 | int extcon_set_cable_state_(struct extcon_dev *edev, unsigned int id, |
Chanwoo Choi | 2a9de9c | 2015-04-24 19:16:05 +0900 | [diff] [blame] | 353 | bool cable_state) |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 354 | { |
| 355 | u32 state; |
Chanwoo Choi | 2a9de9c | 2015-04-24 19:16:05 +0900 | [diff] [blame] | 356 | int index; |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 357 | |
Chanwoo Choi | 7eae43a | 2015-06-21 23:48:36 +0900 | [diff] [blame] | 358 | if (!edev) |
| 359 | return -EINVAL; |
| 360 | |
Chanwoo Choi | 2a9de9c | 2015-04-24 19:16:05 +0900 | [diff] [blame] | 361 | index = find_cable_index_by_id(edev, id); |
| 362 | if (index < 0) |
| 363 | return index; |
| 364 | |
| 365 | if (edev->max_supported && edev->max_supported <= index) |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 366 | return -EINVAL; |
| 367 | |
| 368 | state = cable_state ? (1 << index) : 0; |
MyungJoo Ham | bde68e6 | 2012-04-20 14:16:26 +0900 | [diff] [blame] | 369 | return extcon_update_state(edev, 1 << index, state); |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 370 | } |
| 371 | EXPORT_SYMBOL_GPL(extcon_set_cable_state_); |
| 372 | |
| 373 | /** |
Donggeun Kim | 74c5d09 | 2012-04-20 14:16:24 +0900 | [diff] [blame] | 374 | * extcon_get_extcon_dev() - Get the extcon device instance from the name |
| 375 | * @extcon_name: The extcon name provided with extcon_dev_register() |
| 376 | */ |
| 377 | struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name) |
| 378 | { |
| 379 | struct extcon_dev *sd; |
| 380 | |
Chanwoo Choi | 7eae43a | 2015-06-21 23:48:36 +0900 | [diff] [blame] | 381 | if (!extcon_name) |
| 382 | return ERR_PTR(-EINVAL); |
| 383 | |
Donggeun Kim | 74c5d09 | 2012-04-20 14:16:24 +0900 | [diff] [blame] | 384 | mutex_lock(&extcon_dev_list_lock); |
| 385 | list_for_each_entry(sd, &extcon_dev_list, entry) { |
| 386 | if (!strcmp(sd->name, extcon_name)) |
| 387 | goto out; |
| 388 | } |
| 389 | sd = NULL; |
| 390 | out: |
| 391 | mutex_unlock(&extcon_dev_list_lock); |
| 392 | return sd; |
| 393 | } |
| 394 | EXPORT_SYMBOL_GPL(extcon_get_extcon_dev); |
| 395 | |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 396 | /** |
Peter Meerwald | c338bb0 | 2012-08-23 09:11:54 +0900 | [diff] [blame] | 397 | * extcon_register_notifier() - Register a notifiee to get notified by |
Chanwoo Choi | a75e1c7 | 2013-08-31 13:16:49 +0900 | [diff] [blame] | 398 | * any attach status changes from the extcon. |
Chanwoo Choi | 046050f | 2015-05-19 20:01:12 +0900 | [diff] [blame] | 399 | * @edev: the extcon device that has the external connecotr. |
| 400 | * @id: the unique id of each external connector in extcon enumeration. |
Donggeun Kim | 74c5d09 | 2012-04-20 14:16:24 +0900 | [diff] [blame] | 401 | * @nb: a notifier block to be registered. |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 402 | * |
| 403 | * Note that the second parameter given to the callback of nb (val) is |
| 404 | * "old_state", not the current state. The current state can be retrieved |
| 405 | * by looking at the third pameter (edev pointer)'s state value. |
Donggeun Kim | 74c5d09 | 2012-04-20 14:16:24 +0900 | [diff] [blame] | 406 | */ |
Chanwoo Choi | 73b6ecd | 2015-06-12 11:10:06 +0900 | [diff] [blame] | 407 | int extcon_register_notifier(struct extcon_dev *edev, unsigned int id, |
Chanwoo Choi | 046050f | 2015-05-19 20:01:12 +0900 | [diff] [blame] | 408 | struct notifier_block *nb) |
Donggeun Kim | 74c5d09 | 2012-04-20 14:16:24 +0900 | [diff] [blame] | 409 | { |
Hans de Goede | 66bee35 | 2015-03-21 17:26:24 +0100 | [diff] [blame] | 410 | unsigned long flags; |
Chanwoo Choi | 046050f | 2015-05-19 20:01:12 +0900 | [diff] [blame] | 411 | int ret, idx; |
| 412 | |
Chanwoo Choi | 830ae44 | 2016-05-31 17:32:30 +0900 | [diff] [blame] | 413 | if (!nb) |
Chanwoo Choi | 7eae43a | 2015-06-21 23:48:36 +0900 | [diff] [blame] | 414 | return -EINVAL; |
| 415 | |
Chanwoo Choi | 830ae44 | 2016-05-31 17:32:30 +0900 | [diff] [blame] | 416 | if (edev) { |
| 417 | idx = find_cable_index_by_id(edev, id); |
Stephen Boyd | a05f44c | 2016-06-23 19:34:30 +0900 | [diff] [blame^] | 418 | if (idx < 0) |
| 419 | return idx; |
Hans de Goede | 66bee35 | 2015-03-21 17:26:24 +0100 | [diff] [blame] | 420 | |
Chanwoo Choi | 830ae44 | 2016-05-31 17:32:30 +0900 | [diff] [blame] | 421 | spin_lock_irqsave(&edev->lock, flags); |
| 422 | ret = raw_notifier_chain_register(&edev->nh[idx], nb); |
| 423 | spin_unlock_irqrestore(&edev->lock, flags); |
| 424 | } else { |
| 425 | struct extcon_dev *extd; |
| 426 | |
| 427 | mutex_lock(&extcon_dev_list_lock); |
| 428 | list_for_each_entry(extd, &extcon_dev_list, entry) { |
| 429 | idx = find_cable_index_by_id(extd, id); |
| 430 | if (idx >= 0) |
| 431 | break; |
| 432 | } |
| 433 | mutex_unlock(&extcon_dev_list_lock); |
| 434 | |
| 435 | if (idx >= 0) { |
| 436 | edev = extd; |
| 437 | return extcon_register_notifier(extd, id, nb); |
| 438 | } else { |
| 439 | ret = -ENODEV; |
| 440 | } |
| 441 | } |
Hans de Goede | 66bee35 | 2015-03-21 17:26:24 +0100 | [diff] [blame] | 442 | |
| 443 | return ret; |
Donggeun Kim | 74c5d09 | 2012-04-20 14:16:24 +0900 | [diff] [blame] | 444 | } |
| 445 | EXPORT_SYMBOL_GPL(extcon_register_notifier); |
| 446 | |
| 447 | /** |
Peter Meerwald | c338bb0 | 2012-08-23 09:11:54 +0900 | [diff] [blame] | 448 | * extcon_unregister_notifier() - Unregister a notifiee from the extcon device. |
Chanwoo Choi | 046050f | 2015-05-19 20:01:12 +0900 | [diff] [blame] | 449 | * @edev: the extcon device that has the external connecotr. |
| 450 | * @id: the unique id of each external connector in extcon enumeration. |
| 451 | * @nb: a notifier block to be registered. |
Donggeun Kim | 74c5d09 | 2012-04-20 14:16:24 +0900 | [diff] [blame] | 452 | */ |
Chanwoo Choi | 73b6ecd | 2015-06-12 11:10:06 +0900 | [diff] [blame] | 453 | int extcon_unregister_notifier(struct extcon_dev *edev, unsigned int id, |
Chanwoo Choi | 046050f | 2015-05-19 20:01:12 +0900 | [diff] [blame] | 454 | struct notifier_block *nb) |
Donggeun Kim | 74c5d09 | 2012-04-20 14:16:24 +0900 | [diff] [blame] | 455 | { |
Hans de Goede | 66bee35 | 2015-03-21 17:26:24 +0100 | [diff] [blame] | 456 | unsigned long flags; |
Chanwoo Choi | 046050f | 2015-05-19 20:01:12 +0900 | [diff] [blame] | 457 | int ret, idx; |
| 458 | |
Chanwoo Choi | 7eae43a | 2015-06-21 23:48:36 +0900 | [diff] [blame] | 459 | if (!edev || !nb) |
| 460 | return -EINVAL; |
| 461 | |
Chanwoo Choi | 046050f | 2015-05-19 20:01:12 +0900 | [diff] [blame] | 462 | idx = find_cable_index_by_id(edev, id); |
Stephen Boyd | a05f44c | 2016-06-23 19:34:30 +0900 | [diff] [blame^] | 463 | if (idx < 0) |
| 464 | return idx; |
Hans de Goede | 66bee35 | 2015-03-21 17:26:24 +0100 | [diff] [blame] | 465 | |
| 466 | spin_lock_irqsave(&edev->lock, flags); |
Chanwoo Choi | 046050f | 2015-05-19 20:01:12 +0900 | [diff] [blame] | 467 | ret = raw_notifier_chain_unregister(&edev->nh[idx], nb); |
Hans de Goede | 66bee35 | 2015-03-21 17:26:24 +0100 | [diff] [blame] | 468 | spin_unlock_irqrestore(&edev->lock, flags); |
| 469 | |
| 470 | return ret; |
Donggeun Kim | 74c5d09 | 2012-04-20 14:16:24 +0900 | [diff] [blame] | 471 | } |
| 472 | EXPORT_SYMBOL_GPL(extcon_unregister_notifier); |
| 473 | |
Greg Kroah-Hartman | af01da0 | 2013-07-24 15:05:10 -0700 | [diff] [blame] | 474 | static struct attribute *extcon_attrs[] = { |
| 475 | &dev_attr_state.attr, |
| 476 | &dev_attr_name.attr, |
| 477 | NULL, |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 478 | }; |
Greg Kroah-Hartman | af01da0 | 2013-07-24 15:05:10 -0700 | [diff] [blame] | 479 | ATTRIBUTE_GROUPS(extcon); |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 480 | |
| 481 | static int create_extcon_class(void) |
| 482 | { |
| 483 | if (!extcon_class) { |
| 484 | extcon_class = class_create(THIS_MODULE, "extcon"); |
| 485 | if (IS_ERR(extcon_class)) |
| 486 | return PTR_ERR(extcon_class); |
Greg Kroah-Hartman | af01da0 | 2013-07-24 15:05:10 -0700 | [diff] [blame] | 487 | extcon_class->dev_groups = extcon_groups; |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 488 | |
MyungJoo Ham | 449a2bf | 2012-04-23 20:19:57 +0900 | [diff] [blame] | 489 | #if defined(CONFIG_ANDROID) |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 490 | switch_class = class_compat_register("switch"); |
| 491 | if (WARN(!switch_class, "cannot allocate")) |
| 492 | return -ENOMEM; |
MyungJoo Ham | 449a2bf | 2012-04-23 20:19:57 +0900 | [diff] [blame] | 493 | #endif /* CONFIG_ANDROID */ |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | return 0; |
| 497 | } |
| 498 | |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 499 | static void extcon_dev_release(struct device *dev) |
| 500 | { |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 501 | } |
| 502 | |
MyungJoo Ham | bde68e6 | 2012-04-20 14:16:26 +0900 | [diff] [blame] | 503 | static const char *muex_name = "mutually_exclusive"; |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 504 | static void dummy_sysfs_dev_release(struct device *dev) |
| 505 | { |
| 506 | } |
| 507 | |
Chanwoo Choi | a9af652 | 2014-04-24 19:46:49 +0900 | [diff] [blame] | 508 | /* |
| 509 | * extcon_dev_allocate() - Allocate the memory of extcon device. |
Chanwoo Choi | 2a9de9c | 2015-04-24 19:16:05 +0900 | [diff] [blame] | 510 | * @supported_cable: Array of supported extcon ending with EXTCON_NONE. |
Chanwoo Choi | a9af652 | 2014-04-24 19:46:49 +0900 | [diff] [blame] | 511 | * If supported_cable is NULL, cable name related APIs |
| 512 | * are disabled. |
| 513 | * |
| 514 | * This function allocates the memory for extcon device without allocating |
| 515 | * memory in each extcon provider driver and initialize default setting for |
| 516 | * extcon device. |
| 517 | * |
| 518 | * Return the pointer of extcon device if success or ERR_PTR(err) if fail |
| 519 | */ |
Chanwoo Choi | 73b6ecd | 2015-06-12 11:10:06 +0900 | [diff] [blame] | 520 | struct extcon_dev *extcon_dev_allocate(const unsigned int *supported_cable) |
Chanwoo Choi | a9af652 | 2014-04-24 19:46:49 +0900 | [diff] [blame] | 521 | { |
| 522 | struct extcon_dev *edev; |
| 523 | |
Chanwoo Choi | 7eae43a | 2015-06-21 23:48:36 +0900 | [diff] [blame] | 524 | if (!supported_cable) |
| 525 | return ERR_PTR(-EINVAL); |
| 526 | |
Chanwoo Choi | a9af652 | 2014-04-24 19:46:49 +0900 | [diff] [blame] | 527 | edev = kzalloc(sizeof(*edev), GFP_KERNEL); |
| 528 | if (!edev) |
| 529 | return ERR_PTR(-ENOMEM); |
| 530 | |
| 531 | edev->max_supported = 0; |
| 532 | edev->supported_cable = supported_cable; |
| 533 | |
| 534 | return edev; |
| 535 | } |
| 536 | |
| 537 | /* |
| 538 | * extcon_dev_free() - Free the memory of extcon device. |
| 539 | * @edev: the extcon device to free |
| 540 | */ |
| 541 | void extcon_dev_free(struct extcon_dev *edev) |
| 542 | { |
| 543 | kfree(edev); |
| 544 | } |
| 545 | EXPORT_SYMBOL_GPL(extcon_dev_free); |
| 546 | |
Chanwoo Choi | 739ba1b | 2014-04-24 20:12:15 +0900 | [diff] [blame] | 547 | static int devm_extcon_dev_match(struct device *dev, void *res, void *data) |
| 548 | { |
| 549 | struct extcon_dev **r = res; |
| 550 | |
| 551 | if (WARN_ON(!r || !*r)) |
| 552 | return 0; |
| 553 | |
| 554 | return *r == data; |
| 555 | } |
| 556 | |
| 557 | static void devm_extcon_dev_release(struct device *dev, void *res) |
| 558 | { |
| 559 | extcon_dev_free(*(struct extcon_dev **)res); |
| 560 | } |
| 561 | |
| 562 | /** |
| 563 | * devm_extcon_dev_allocate - Allocate managed extcon device |
| 564 | * @dev: device owning the extcon device being created |
Chanwoo Choi | 2a9de9c | 2015-04-24 19:16:05 +0900 | [diff] [blame] | 565 | * @supported_cable: Array of supported extcon ending with EXTCON_NONE. |
Chanwoo Choi | 739ba1b | 2014-04-24 20:12:15 +0900 | [diff] [blame] | 566 | * If supported_cable is NULL, cable name related APIs |
| 567 | * are disabled. |
| 568 | * |
| 569 | * This function manages automatically the memory of extcon device using device |
| 570 | * resource management and simplify the control of freeing the memory of extcon |
| 571 | * device. |
| 572 | * |
| 573 | * Returns the pointer memory of allocated extcon_dev if success |
| 574 | * or ERR_PTR(err) if fail |
| 575 | */ |
| 576 | struct extcon_dev *devm_extcon_dev_allocate(struct device *dev, |
Chanwoo Choi | 73b6ecd | 2015-06-12 11:10:06 +0900 | [diff] [blame] | 577 | const unsigned int *supported_cable) |
Chanwoo Choi | 739ba1b | 2014-04-24 20:12:15 +0900 | [diff] [blame] | 578 | { |
| 579 | struct extcon_dev **ptr, *edev; |
| 580 | |
| 581 | ptr = devres_alloc(devm_extcon_dev_release, sizeof(*ptr), GFP_KERNEL); |
| 582 | if (!ptr) |
| 583 | return ERR_PTR(-ENOMEM); |
| 584 | |
| 585 | edev = extcon_dev_allocate(supported_cable); |
| 586 | if (IS_ERR(edev)) { |
| 587 | devres_free(ptr); |
| 588 | return edev; |
| 589 | } |
| 590 | |
Chanwoo Choi | ac65a62 | 2014-05-30 10:13:15 +0900 | [diff] [blame] | 591 | edev->dev.parent = dev; |
| 592 | |
Chanwoo Choi | 739ba1b | 2014-04-24 20:12:15 +0900 | [diff] [blame] | 593 | *ptr = edev; |
| 594 | devres_add(dev, ptr); |
| 595 | |
| 596 | return edev; |
| 597 | } |
| 598 | EXPORT_SYMBOL_GPL(devm_extcon_dev_allocate); |
| 599 | |
| 600 | void devm_extcon_dev_free(struct device *dev, struct extcon_dev *edev) |
| 601 | { |
| 602 | WARN_ON(devres_release(dev, devm_extcon_dev_release, |
| 603 | devm_extcon_dev_match, edev)); |
| 604 | } |
| 605 | EXPORT_SYMBOL_GPL(devm_extcon_dev_free); |
| 606 | |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 607 | /** |
| 608 | * extcon_dev_register() - Register a new extcon device |
| 609 | * @edev : the new extcon device (should be allocated before calling) |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 610 | * |
| 611 | * Among the members of edev struct, please set the "user initializing data" |
| 612 | * in any case and set the "optional callbacks" if required. However, please |
| 613 | * do not set the values of "internal data", which are initialized by |
| 614 | * this function. |
| 615 | */ |
Chanwoo Choi | 42d7d75 | 2013-09-27 09:20:26 +0900 | [diff] [blame] | 616 | int extcon_dev_register(struct extcon_dev *edev) |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 617 | { |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 618 | int ret, index = 0; |
Chanwoo Choi | 71c3ffa | 2015-04-15 15:02:01 +0900 | [diff] [blame] | 619 | static atomic_t edev_no = ATOMIC_INIT(-1); |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 620 | |
| 621 | if (!extcon_class) { |
| 622 | ret = create_extcon_class(); |
| 623 | if (ret < 0) |
| 624 | return ret; |
| 625 | } |
| 626 | |
Chanwoo Choi | 7eae43a | 2015-06-21 23:48:36 +0900 | [diff] [blame] | 627 | if (!edev || !edev->supported_cable) |
Chanwoo Choi | 2a9de9c | 2015-04-24 19:16:05 +0900 | [diff] [blame] | 628 | return -EINVAL; |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 629 | |
Chanwoo Choi | 2a9de9c | 2015-04-24 19:16:05 +0900 | [diff] [blame] | 630 | for (; edev->supported_cable[index] != EXTCON_NONE; index++); |
| 631 | |
| 632 | edev->max_supported = index; |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 633 | if (index > SUPPORTED_CABLE_MAX) { |
Chanwoo Choi | 2a9de9c | 2015-04-24 19:16:05 +0900 | [diff] [blame] | 634 | dev_err(&edev->dev, |
| 635 | "exceed the maximum number of supported cables\n"); |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 636 | return -EINVAL; |
| 637 | } |
| 638 | |
Chanwoo Choi | dae6165 | 2013-09-27 09:19:40 +0900 | [diff] [blame] | 639 | edev->dev.class = extcon_class; |
| 640 | edev->dev.release = extcon_dev_release; |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 641 | |
Chanwoo Choi | 71c3ffa | 2015-04-15 15:02:01 +0900 | [diff] [blame] | 642 | edev->name = dev_name(edev->dev.parent); |
Chanwoo Choi | 42d7d75 | 2013-09-27 09:20:26 +0900 | [diff] [blame] | 643 | if (IS_ERR_OR_NULL(edev->name)) { |
| 644 | dev_err(&edev->dev, |
| 645 | "extcon device name is null\n"); |
| 646 | return -EINVAL; |
| 647 | } |
Chanwoo Choi | 71c3ffa | 2015-04-15 15:02:01 +0900 | [diff] [blame] | 648 | dev_set_name(&edev->dev, "extcon%lu", |
| 649 | (unsigned long)atomic_inc_return(&edev_no)); |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 650 | |
| 651 | if (edev->max_supported) { |
| 652 | char buf[10]; |
| 653 | char *str; |
| 654 | struct extcon_cable *cable; |
| 655 | |
| 656 | edev->cables = kzalloc(sizeof(struct extcon_cable) * |
| 657 | edev->max_supported, GFP_KERNEL); |
| 658 | if (!edev->cables) { |
| 659 | ret = -ENOMEM; |
| 660 | goto err_sysfs_alloc; |
| 661 | } |
| 662 | for (index = 0; index < edev->max_supported; index++) { |
| 663 | cable = &edev->cables[index]; |
| 664 | |
| 665 | snprintf(buf, 10, "cable.%d", index); |
| 666 | str = kzalloc(sizeof(char) * (strlen(buf) + 1), |
| 667 | GFP_KERNEL); |
| 668 | if (!str) { |
| 669 | for (index--; index >= 0; index--) { |
| 670 | cable = &edev->cables[index]; |
| 671 | kfree(cable->attr_g.name); |
| 672 | } |
| 673 | ret = -ENOMEM; |
| 674 | |
| 675 | goto err_alloc_cables; |
| 676 | } |
| 677 | strcpy(str, buf); |
| 678 | |
| 679 | cable->edev = edev; |
| 680 | cable->cable_index = index; |
| 681 | cable->attrs[0] = &cable->attr_name.attr; |
| 682 | cable->attrs[1] = &cable->attr_state.attr; |
| 683 | cable->attrs[2] = NULL; |
| 684 | cable->attr_g.name = str; |
| 685 | cable->attr_g.attrs = cable->attrs; |
| 686 | |
Mark Brown | 9baf322 | 2012-08-16 20:03:21 +0100 | [diff] [blame] | 687 | sysfs_attr_init(&cable->attr_name.attr); |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 688 | cable->attr_name.attr.name = "name"; |
| 689 | cable->attr_name.attr.mode = 0444; |
| 690 | cable->attr_name.show = cable_name_show; |
| 691 | |
Mark Brown | 9baf322 | 2012-08-16 20:03:21 +0100 | [diff] [blame] | 692 | sysfs_attr_init(&cable->attr_state.attr); |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 693 | cable->attr_state.attr.name = "state"; |
Chanwoo Choi | ea9dd9d | 2013-05-22 19:31:59 +0900 | [diff] [blame] | 694 | cable->attr_state.attr.mode = 0444; |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 695 | cable->attr_state.show = cable_state_show; |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 696 | } |
| 697 | } |
| 698 | |
MyungJoo Ham | bde68e6 | 2012-04-20 14:16:26 +0900 | [diff] [blame] | 699 | if (edev->max_supported && edev->mutually_exclusive) { |
| 700 | char buf[80]; |
| 701 | char *name; |
| 702 | |
| 703 | /* Count the size of mutually_exclusive array */ |
| 704 | for (index = 0; edev->mutually_exclusive[index]; index++) |
| 705 | ; |
| 706 | |
| 707 | edev->attrs_muex = kzalloc(sizeof(struct attribute *) * |
| 708 | (index + 1), GFP_KERNEL); |
| 709 | if (!edev->attrs_muex) { |
| 710 | ret = -ENOMEM; |
| 711 | goto err_muex; |
| 712 | } |
| 713 | |
| 714 | edev->d_attrs_muex = kzalloc(sizeof(struct device_attribute) * |
| 715 | index, GFP_KERNEL); |
| 716 | if (!edev->d_attrs_muex) { |
| 717 | ret = -ENOMEM; |
| 718 | kfree(edev->attrs_muex); |
| 719 | goto err_muex; |
| 720 | } |
| 721 | |
| 722 | for (index = 0; edev->mutually_exclusive[index]; index++) { |
| 723 | sprintf(buf, "0x%x", edev->mutually_exclusive[index]); |
| 724 | name = kzalloc(sizeof(char) * (strlen(buf) + 1), |
| 725 | GFP_KERNEL); |
| 726 | if (!name) { |
| 727 | for (index--; index >= 0; index--) { |
| 728 | kfree(edev->d_attrs_muex[index].attr. |
| 729 | name); |
| 730 | } |
| 731 | kfree(edev->d_attrs_muex); |
| 732 | kfree(edev->attrs_muex); |
| 733 | ret = -ENOMEM; |
| 734 | goto err_muex; |
| 735 | } |
| 736 | strcpy(name, buf); |
Mark Brown | 9baf322 | 2012-08-16 20:03:21 +0100 | [diff] [blame] | 737 | sysfs_attr_init(&edev->d_attrs_muex[index].attr); |
MyungJoo Ham | bde68e6 | 2012-04-20 14:16:26 +0900 | [diff] [blame] | 738 | edev->d_attrs_muex[index].attr.name = name; |
| 739 | edev->d_attrs_muex[index].attr.mode = 0000; |
| 740 | edev->attrs_muex[index] = &edev->d_attrs_muex[index] |
| 741 | .attr; |
| 742 | } |
| 743 | edev->attr_g_muex.name = muex_name; |
| 744 | edev->attr_g_muex.attrs = edev->attrs_muex; |
| 745 | |
| 746 | } |
| 747 | |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 748 | if (edev->max_supported) { |
| 749 | edev->extcon_dev_type.groups = |
| 750 | kzalloc(sizeof(struct attribute_group *) * |
MyungJoo Ham | bde68e6 | 2012-04-20 14:16:26 +0900 | [diff] [blame] | 751 | (edev->max_supported + 2), GFP_KERNEL); |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 752 | if (!edev->extcon_dev_type.groups) { |
| 753 | ret = -ENOMEM; |
| 754 | goto err_alloc_groups; |
| 755 | } |
| 756 | |
Chanwoo Choi | dae6165 | 2013-09-27 09:19:40 +0900 | [diff] [blame] | 757 | edev->extcon_dev_type.name = dev_name(&edev->dev); |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 758 | edev->extcon_dev_type.release = dummy_sysfs_dev_release; |
| 759 | |
| 760 | for (index = 0; index < edev->max_supported; index++) |
| 761 | edev->extcon_dev_type.groups[index] = |
| 762 | &edev->cables[index].attr_g; |
MyungJoo Ham | bde68e6 | 2012-04-20 14:16:26 +0900 | [diff] [blame] | 763 | if (edev->mutually_exclusive) |
| 764 | edev->extcon_dev_type.groups[index] = |
| 765 | &edev->attr_g_muex; |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 766 | |
Chanwoo Choi | dae6165 | 2013-09-27 09:19:40 +0900 | [diff] [blame] | 767 | edev->dev.type = &edev->extcon_dev_type; |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 768 | } |
| 769 | |
Chanwoo Choi | dae6165 | 2013-09-27 09:19:40 +0900 | [diff] [blame] | 770 | ret = device_register(&edev->dev); |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 771 | if (ret) { |
Chanwoo Choi | dae6165 | 2013-09-27 09:19:40 +0900 | [diff] [blame] | 772 | put_device(&edev->dev); |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 773 | goto err_dev; |
| 774 | } |
MyungJoo Ham | 449a2bf | 2012-04-23 20:19:57 +0900 | [diff] [blame] | 775 | #if defined(CONFIG_ANDROID) |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 776 | if (switch_class) |
Chanwoo Choi | dae6165 | 2013-09-27 09:19:40 +0900 | [diff] [blame] | 777 | ret = class_compat_create_link(switch_class, &edev->dev, NULL); |
MyungJoo Ham | 449a2bf | 2012-04-23 20:19:57 +0900 | [diff] [blame] | 778 | #endif /* CONFIG_ANDROID */ |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 779 | |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 780 | spin_lock_init(&edev->lock); |
| 781 | |
Chanwoo Choi | 046050f | 2015-05-19 20:01:12 +0900 | [diff] [blame] | 782 | edev->nh = devm_kzalloc(&edev->dev, |
| 783 | sizeof(*edev->nh) * edev->max_supported, GFP_KERNEL); |
| 784 | if (!edev->nh) { |
| 785 | ret = -ENOMEM; |
| 786 | goto err_dev; |
| 787 | } |
| 788 | |
| 789 | for (index = 0; index < edev->max_supported; index++) |
| 790 | RAW_INIT_NOTIFIER_HEAD(&edev->nh[index]); |
Donggeun Kim | 74c5d09 | 2012-04-20 14:16:24 +0900 | [diff] [blame] | 791 | |
Chanwoo Choi | dae6165 | 2013-09-27 09:19:40 +0900 | [diff] [blame] | 792 | dev_set_drvdata(&edev->dev, edev); |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 793 | edev->state = 0; |
Donggeun Kim | 74c5d09 | 2012-04-20 14:16:24 +0900 | [diff] [blame] | 794 | |
| 795 | mutex_lock(&extcon_dev_list_lock); |
| 796 | list_add(&edev->entry, &extcon_dev_list); |
| 797 | mutex_unlock(&extcon_dev_list_lock); |
| 798 | |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 799 | return 0; |
| 800 | |
| 801 | err_dev: |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 802 | if (edev->max_supported) |
| 803 | kfree(edev->extcon_dev_type.groups); |
| 804 | err_alloc_groups: |
MyungJoo Ham | bde68e6 | 2012-04-20 14:16:26 +0900 | [diff] [blame] | 805 | if (edev->max_supported && edev->mutually_exclusive) { |
| 806 | for (index = 0; edev->mutually_exclusive[index]; index++) |
| 807 | kfree(edev->d_attrs_muex[index].attr.name); |
| 808 | kfree(edev->d_attrs_muex); |
| 809 | kfree(edev->attrs_muex); |
| 810 | } |
| 811 | err_muex: |
MyungJoo Ham | 806d9dd | 2012-04-20 14:16:25 +0900 | [diff] [blame] | 812 | for (index = 0; index < edev->max_supported; index++) |
| 813 | kfree(edev->cables[index].attr_g.name); |
| 814 | err_alloc_cables: |
| 815 | if (edev->max_supported) |
| 816 | kfree(edev->cables); |
| 817 | err_sysfs_alloc: |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 818 | return ret; |
| 819 | } |
| 820 | EXPORT_SYMBOL_GPL(extcon_dev_register); |
| 821 | |
| 822 | /** |
| 823 | * extcon_dev_unregister() - Unregister the extcon device. |
Peter Meerwald | c338bb0 | 2012-08-23 09:11:54 +0900 | [diff] [blame] | 824 | * @edev: the extcon device instance to be unregistered. |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 825 | * |
| 826 | * Note that this does not call kfree(edev) because edev was not allocated |
| 827 | * by this class. |
| 828 | */ |
| 829 | void extcon_dev_unregister(struct extcon_dev *edev) |
| 830 | { |
anish kumar | 57e7cd3 | 2012-10-22 09:43:33 +0900 | [diff] [blame] | 831 | int index; |
| 832 | |
Chanwoo Choi | 7eae43a | 2015-06-21 23:48:36 +0900 | [diff] [blame] | 833 | if (!edev) |
| 834 | return; |
| 835 | |
anish kumar | 57e7cd3 | 2012-10-22 09:43:33 +0900 | [diff] [blame] | 836 | mutex_lock(&extcon_dev_list_lock); |
| 837 | list_del(&edev->entry); |
| 838 | mutex_unlock(&extcon_dev_list_lock); |
| 839 | |
Chanwoo Choi | dae6165 | 2013-09-27 09:19:40 +0900 | [diff] [blame] | 840 | if (IS_ERR_OR_NULL(get_device(&edev->dev))) { |
| 841 | dev_err(&edev->dev, "Failed to unregister extcon_dev (%s)\n", |
| 842 | dev_name(&edev->dev)); |
anish kumar | 57e7cd3 | 2012-10-22 09:43:33 +0900 | [diff] [blame] | 843 | return; |
| 844 | } |
| 845 | |
Wang, Xiaoming | 7585ca0 | 2013-11-01 18:48:14 -0400 | [diff] [blame] | 846 | device_unregister(&edev->dev); |
| 847 | |
anish kumar | 57e7cd3 | 2012-10-22 09:43:33 +0900 | [diff] [blame] | 848 | if (edev->mutually_exclusive && edev->max_supported) { |
| 849 | for (index = 0; edev->mutually_exclusive[index]; |
| 850 | index++) |
| 851 | kfree(edev->d_attrs_muex[index].attr.name); |
| 852 | kfree(edev->d_attrs_muex); |
| 853 | kfree(edev->attrs_muex); |
| 854 | } |
| 855 | |
| 856 | for (index = 0; index < edev->max_supported; index++) |
| 857 | kfree(edev->cables[index].attr_g.name); |
| 858 | |
| 859 | if (edev->max_supported) { |
| 860 | kfree(edev->extcon_dev_type.groups); |
| 861 | kfree(edev->cables); |
| 862 | } |
| 863 | |
| 864 | #if defined(CONFIG_ANDROID) |
| 865 | if (switch_class) |
Chanwoo Choi | dae6165 | 2013-09-27 09:19:40 +0900 | [diff] [blame] | 866 | class_compat_remove_link(switch_class, &edev->dev, NULL); |
anish kumar | 57e7cd3 | 2012-10-22 09:43:33 +0900 | [diff] [blame] | 867 | #endif |
Chanwoo Choi | dae6165 | 2013-09-27 09:19:40 +0900 | [diff] [blame] | 868 | put_device(&edev->dev); |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 869 | } |
| 870 | EXPORT_SYMBOL_GPL(extcon_dev_unregister); |
| 871 | |
Sangjung Woo | 1111244 | 2014-04-21 19:10:08 +0900 | [diff] [blame] | 872 | static void devm_extcon_dev_unreg(struct device *dev, void *res) |
| 873 | { |
| 874 | extcon_dev_unregister(*(struct extcon_dev **)res); |
| 875 | } |
| 876 | |
Sangjung Woo | 1111244 | 2014-04-21 19:10:08 +0900 | [diff] [blame] | 877 | /** |
| 878 | * devm_extcon_dev_register() - Resource-managed extcon_dev_register() |
| 879 | * @dev: device to allocate extcon device |
| 880 | * @edev: the new extcon device to register |
| 881 | * |
| 882 | * Managed extcon_dev_register() function. If extcon device is attached with |
| 883 | * this function, that extcon device is automatically unregistered on driver |
| 884 | * detach. Internally this function calls extcon_dev_register() function. |
| 885 | * To get more information, refer that function. |
| 886 | * |
| 887 | * If extcon device is registered with this function and the device needs to be |
| 888 | * unregistered separately, devm_extcon_dev_unregister() should be used. |
| 889 | * |
| 890 | * Returns 0 if success or negaive error number if failure. |
| 891 | */ |
| 892 | int devm_extcon_dev_register(struct device *dev, struct extcon_dev *edev) |
| 893 | { |
| 894 | struct extcon_dev **ptr; |
| 895 | int ret; |
| 896 | |
| 897 | ptr = devres_alloc(devm_extcon_dev_unreg, sizeof(*ptr), GFP_KERNEL); |
| 898 | if (!ptr) |
| 899 | return -ENOMEM; |
| 900 | |
| 901 | ret = extcon_dev_register(edev); |
| 902 | if (ret) { |
| 903 | devres_free(ptr); |
| 904 | return ret; |
| 905 | } |
| 906 | |
| 907 | *ptr = edev; |
| 908 | devres_add(dev, ptr); |
| 909 | |
| 910 | return 0; |
| 911 | } |
| 912 | EXPORT_SYMBOL_GPL(devm_extcon_dev_register); |
| 913 | |
| 914 | /** |
| 915 | * devm_extcon_dev_unregister() - Resource-managed extcon_dev_unregister() |
| 916 | * @dev: device the extcon belongs to |
| 917 | * @edev: the extcon device to unregister |
| 918 | * |
| 919 | * Unregister extcon device that is registered with devm_extcon_dev_register() |
| 920 | * function. |
| 921 | */ |
| 922 | void devm_extcon_dev_unregister(struct device *dev, struct extcon_dev *edev) |
| 923 | { |
| 924 | WARN_ON(devres_release(dev, devm_extcon_dev_unreg, |
| 925 | devm_extcon_dev_match, edev)); |
| 926 | } |
| 927 | EXPORT_SYMBOL_GPL(devm_extcon_dev_unregister); |
| 928 | |
Chanwoo Choi | 1ad94ff | 2014-03-18 19:55:46 +0900 | [diff] [blame] | 929 | #ifdef CONFIG_OF |
| 930 | /* |
| 931 | * extcon_get_edev_by_phandle - Get the extcon device from devicetree |
| 932 | * @dev - instance to the given device |
| 933 | * @index - index into list of extcon_dev |
| 934 | * |
| 935 | * return the instance of extcon device |
| 936 | */ |
| 937 | struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index) |
| 938 | { |
| 939 | struct device_node *node; |
| 940 | struct extcon_dev *edev; |
| 941 | |
Chanwoo Choi | 7eae43a | 2015-06-21 23:48:36 +0900 | [diff] [blame] | 942 | if (!dev) |
| 943 | return ERR_PTR(-EINVAL); |
| 944 | |
Chanwoo Choi | 1ad94ff | 2014-03-18 19:55:46 +0900 | [diff] [blame] | 945 | if (!dev->of_node) { |
| 946 | dev_err(dev, "device does not have a device node entry\n"); |
| 947 | return ERR_PTR(-EINVAL); |
| 948 | } |
| 949 | |
| 950 | node = of_parse_phandle(dev->of_node, "extcon", index); |
| 951 | if (!node) { |
| 952 | dev_err(dev, "failed to get phandle in %s node\n", |
| 953 | dev->of_node->full_name); |
| 954 | return ERR_PTR(-ENODEV); |
| 955 | } |
| 956 | |
Tomasz Figa | f841afb1 | 2014-10-16 15:11:44 +0200 | [diff] [blame] | 957 | mutex_lock(&extcon_dev_list_lock); |
| 958 | list_for_each_entry(edev, &extcon_dev_list, entry) { |
| 959 | if (edev->dev.parent && edev->dev.parent->of_node == node) { |
| 960 | mutex_unlock(&extcon_dev_list_lock); |
| 961 | return edev; |
| 962 | } |
Chanwoo Choi | 1ad94ff | 2014-03-18 19:55:46 +0900 | [diff] [blame] | 963 | } |
Tomasz Figa | f841afb1 | 2014-10-16 15:11:44 +0200 | [diff] [blame] | 964 | mutex_unlock(&extcon_dev_list_lock); |
Chanwoo Choi | 1ad94ff | 2014-03-18 19:55:46 +0900 | [diff] [blame] | 965 | |
Tomasz Figa | f841afb1 | 2014-10-16 15:11:44 +0200 | [diff] [blame] | 966 | return ERR_PTR(-EPROBE_DEFER); |
Chanwoo Choi | 1ad94ff | 2014-03-18 19:55:46 +0900 | [diff] [blame] | 967 | } |
| 968 | #else |
| 969 | struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index) |
| 970 | { |
| 971 | return ERR_PTR(-ENOSYS); |
| 972 | } |
| 973 | #endif /* CONFIG_OF */ |
| 974 | EXPORT_SYMBOL_GPL(extcon_get_edev_by_phandle); |
| 975 | |
Chanwoo Choi | 707d755 | 2015-04-15 13:57:51 +0900 | [diff] [blame] | 976 | /** |
| 977 | * extcon_get_edev_name() - Get the name of the extcon device. |
| 978 | * @edev: the extcon device |
| 979 | */ |
| 980 | const char *extcon_get_edev_name(struct extcon_dev *edev) |
| 981 | { |
| 982 | return !edev ? NULL : edev->name; |
| 983 | } |
| 984 | |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 985 | static int __init extcon_class_init(void) |
| 986 | { |
| 987 | return create_extcon_class(); |
| 988 | } |
| 989 | module_init(extcon_class_init); |
| 990 | |
| 991 | static void __exit extcon_class_exit(void) |
| 992 | { |
Peter Huewe | 0dc77b6 | 2012-09-24 15:32:31 +0900 | [diff] [blame] | 993 | #if defined(CONFIG_ANDROID) |
| 994 | class_compat_unregister(switch_class); |
| 995 | #endif |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 996 | class_destroy(extcon_class); |
| 997 | } |
| 998 | module_exit(extcon_class_exit); |
| 999 | |
Chanwoo Choi | 2a9de9c | 2015-04-24 19:16:05 +0900 | [diff] [blame] | 1000 | MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>"); |
MyungJoo Ham | de55d87 | 2012-04-20 14:16:22 +0900 | [diff] [blame] | 1001 | MODULE_AUTHOR("Mike Lockwood <lockwood@android.com>"); |
| 1002 | MODULE_AUTHOR("Donggeun Kim <dg77.kim@samsung.com>"); |
| 1003 | MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>"); |
| 1004 | MODULE_DESCRIPTION("External connector (extcon) class driver"); |
| 1005 | MODULE_LICENSE("GPL"); |