hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/extcon/extcon.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * drivers/extcon/extcon.c - External Connector (extcon) framework.
34 *
....@@ -11,15 +12,6 @@
1112 * based on android/drivers/switch/switch_class.c
1213 * Copyright (C) 2008 Google, Inc.
1314 * Author: Mike Lockwood <lockwood@android.com>
14
- *
15
- * This software is licensed under the terms of the GNU General Public
16
- * License version 2, as published by the Free Software Foundation, and
17
- * may be copied, distributed, and modified under those terms.
18
- *
19
- * This program is distributed in the hope that it will be useful,
20
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
- * GNU General Public License for more details.
2315 */
2416
2517 #include <linux/module.h>
....@@ -33,9 +25,6 @@
3325 #include <linux/sysfs.h>
3426
3527 #include "extcon.h"
36
-#ifdef CONFIG_ARCH_ROCKCHIP
37
-#include "../base/base.h"
38
-#endif
3928
4029 #define SUPPORTED_CABLE_MAX 32
4130
....@@ -183,6 +172,16 @@
183172 .id = EXTCON_DISP_HMD,
184173 .name = "HMD",
185174 },
175
+ [EXTCON_DISP_CVBS] = {
176
+ .type = EXTCON_TYPE_DISP,
177
+ .id = EXTCON_DISP_CVBS,
178
+ .name = "CVBS",
179
+ },
180
+ [EXTCON_DISP_EDP] = {
181
+ .type = EXTCON_TYPE_DISP,
182
+ .id = EXTCON_DISP_EDP,
183
+ .name = "EDP",
184
+ },
186185
187186 /* Miscellaneous external connector */
188187 [EXTCON_DOCK] = {
....@@ -212,6 +211,14 @@
212211 * @attr_name: "name" sysfs entry
213212 * @attr_state: "state" sysfs entry
214213 * @attrs: the array pointing to attr_name and attr_state for attr_g
214
+ * @usb_propval: the array of USB connector properties
215
+ * @chg_propval: the array of charger connector properties
216
+ * @jack_propval: the array of jack connector properties
217
+ * @disp_propval: the array of display connector properties
218
+ * @usb_bits: the bit array of the USB connector property capabilities
219
+ * @chg_bits: the bit array of the charger connector property capabilities
220
+ * @jack_bits: the bit array of the jack connector property capabilities
221
+ * @disp_bits: the bit array of the display connector property capabilities
215222 */
216223 struct extcon_cable {
217224 struct extcon_dev *edev;
....@@ -495,21 +502,6 @@
495502 }
496503 EXPORT_SYMBOL_GPL(extcon_sync);
497504
498
-int extcon_blocking_sync(struct extcon_dev *edev, unsigned int id, bool val)
499
-{
500
- int index;
501
-
502
- if (!edev)
503
- return -EINVAL;
504
-
505
- index = find_cable_index_by_id(edev, id);
506
- if (index < 0)
507
- return index;
508
-
509
- return blocking_notifier_call_chain(&edev->bnh[index], val, edev);
510
-}
511
-EXPORT_SYMBOL(extcon_blocking_sync);
512
-
513505 /**
514506 * extcon_get_state() - Get the state of an external connector.
515507 * @edev: the extcon device
....@@ -651,7 +643,7 @@
651643 unsigned long flags;
652644 int index, ret = 0;
653645
654
- *prop_val = (union extcon_property_value)(0);
646
+ *prop_val = (union extcon_property_value){0};
655647
656648 if (!edev)
657649 return -EINVAL;
....@@ -931,7 +923,7 @@
931923 struct notifier_block *nb)
932924 {
933925 unsigned long flags;
934
- int ret, idx = -EINVAL;
926
+ int ret, idx;
935927
936928 if (!edev || !nb)
937929 return -EINVAL;
....@@ -947,38 +939,6 @@
947939 return ret;
948940 }
949941 EXPORT_SYMBOL_GPL(extcon_register_notifier);
950
-
951
-int extcon_register_blocking_notifier(struct extcon_dev *edev, unsigned int id,
952
- struct notifier_block *nb)
953
-{
954
- int idx = -EINVAL;
955
-
956
- if (!edev || !nb)
957
- return -EINVAL;
958
-
959
- idx = find_cable_index_by_id(edev, id);
960
- if (idx < 0)
961
- return idx;
962
-
963
- return blocking_notifier_chain_register(&edev->bnh[idx], nb);
964
-}
965
-EXPORT_SYMBOL(extcon_register_blocking_notifier);
966
-
967
-int extcon_unregister_blocking_notifier(struct extcon_dev *edev,
968
- unsigned int id, struct notifier_block *nb)
969
-{
970
- int idx;
971
-
972
- if (!edev || !nb)
973
- return -EINVAL;
974
-
975
- idx = find_cable_index_by_id(edev, id);
976
- if (idx < 0)
977
- return idx;
978
-
979
- return blocking_notifier_chain_unregister(&edev->bnh[idx], nb);
980
-}
981
-EXPORT_SYMBOL(extcon_unregister_blocking_notifier);
982942
983943 /**
984944 * extcon_unregister_notifier() - Unregister a notifier block from the extcon.
....@@ -1128,19 +1088,6 @@
11281088 }
11291089 EXPORT_SYMBOL_GPL(extcon_dev_free);
11301090
1131
-#ifdef CONFIG_ARCH_ROCKCHIP
1132
-static const char *extcon_get_link_name(struct extcon_dev *edev)
1133
-{
1134
- const char *dot = strchr(edev->name, '.');
1135
- const char *name = dot + 1;
1136
-
1137
- if (!dot || !name || !(*name))
1138
- name = edev->name;
1139
-
1140
- return name;
1141
-}
1142
-#endif
1143
-
11441091 /**
11451092 * extcon_dev_register() - Register an new extcon device
11461093 * @edev: the extcon device to be registered
....@@ -1191,7 +1138,6 @@
11911138 (unsigned long)atomic_inc_return(&edev_no));
11921139
11931140 if (edev->max_supported) {
1194
- char buf[10];
11951141 char *str;
11961142 struct extcon_cable *cable;
11971143
....@@ -1205,9 +1151,7 @@
12051151 for (index = 0; index < edev->max_supported; index++) {
12061152 cable = &edev->cables[index];
12071153
1208
- snprintf(buf, 10, "cable.%d", index);
1209
- str = kzalloc(strlen(buf) + 1,
1210
- GFP_KERNEL);
1154
+ str = kasprintf(GFP_KERNEL, "cable.%d", index);
12111155 if (!str) {
12121156 for (index--; index >= 0; index--) {
12131157 cable = &edev->cables[index];
....@@ -1217,7 +1161,6 @@
12171161
12181162 goto err_alloc_cables;
12191163 }
1220
- strcpy(str, buf);
12211164
12221165 cable->edev = edev;
12231166 cable->cable_index = index;
....@@ -1240,7 +1183,6 @@
12401183 }
12411184
12421185 if (edev->max_supported && edev->mutually_exclusive) {
1243
- char buf[80];
12441186 char *name;
12451187
12461188 /* Count the size of mutually_exclusive array */
....@@ -1265,9 +1207,8 @@
12651207 }
12661208
12671209 for (index = 0; edev->mutually_exclusive[index]; index++) {
1268
- sprintf(buf, "0x%x", edev->mutually_exclusive[index]);
1269
- name = kzalloc(strlen(buf) + 1,
1270
- GFP_KERNEL);
1210
+ name = kasprintf(GFP_KERNEL, "0x%x",
1211
+ edev->mutually_exclusive[index]);
12711212 if (!name) {
12721213 for (index--; index >= 0; index--) {
12731214 kfree(edev->d_attrs_muex[index].attr.
....@@ -1278,7 +1219,6 @@
12781219 ret = -ENOMEM;
12791220 goto err_muex;
12801221 }
1281
- strcpy(name, buf);
12821222 sysfs_attr_init(&edev->d_attrs_muex[index].attr);
12831223 edev->d_attrs_muex[index].attr.name = name;
12841224 edev->d_attrs_muex[index].attr.mode = 0000;
....@@ -1313,26 +1253,14 @@
13131253 edev->dev.type = &edev->extcon_dev_type;
13141254 }
13151255
1316
- ret = device_register(&edev->dev);
1317
- if (ret) {
1318
- put_device(&edev->dev);
1319
- goto err_dev;
1320
- }
1321
-
13221256 spin_lock_init(&edev->lock);
1323
- edev->nh = devm_kcalloc(&edev->dev, edev->max_supported,
1324
- sizeof(*edev->nh), GFP_KERNEL);
1325
- if (!edev->nh) {
1326
- ret = -ENOMEM;
1327
- device_unregister(&edev->dev);
1328
- goto err_dev;
1329
- }
1330
-
1331
- edev->bnh = devm_kzalloc(&edev->dev,
1332
- sizeof(*edev->bnh) * edev->max_supported, GFP_KERNEL);
1333
- if (!edev->bnh) {
1334
- ret = -ENOMEM;
1335
- goto err_dev;
1257
+ if (edev->max_supported) {
1258
+ edev->nh = kcalloc(edev->max_supported, sizeof(*edev->nh),
1259
+ GFP_KERNEL);
1260
+ if (!edev->nh) {
1261
+ ret = -ENOMEM;
1262
+ goto err_alloc_nh;
1263
+ }
13361264 }
13371265
13381266 for (index = 0; index < edev->max_supported; index++)
....@@ -1343,25 +1271,22 @@
13431271 dev_set_drvdata(&edev->dev, edev);
13441272 edev->state = 0;
13451273
1274
+ ret = device_register(&edev->dev);
1275
+ if (ret) {
1276
+ put_device(&edev->dev);
1277
+ goto err_dev;
1278
+ }
1279
+
13461280 mutex_lock(&extcon_dev_list_lock);
13471281 list_add(&edev->entry, &extcon_dev_list);
13481282 mutex_unlock(&extcon_dev_list_lock);
13491283
1350
-#ifdef CONFIG_ARCH_ROCKCHIP
1351
- {
1352
- const char *name = extcon_get_link_name(edev);
1353
-
1354
- ret = sysfs_create_link_nowarn(&edev->dev.class->p->subsys.kobj,
1355
- &edev->dev.kobj, name);
1356
- if (ret)
1357
- dev_err(&edev->dev,
1358
- "failed to create extcon %s link\n", name);
1359
- }
1360
-#endif
1361
-
13621284 return 0;
13631285
13641286 err_dev:
1287
+ if (edev->max_supported)
1288
+ kfree(edev->nh);
1289
+err_alloc_nh:
13651290 if (edev->max_supported)
13661291 kfree(edev->extcon_dev_type.groups);
13671292 err_alloc_groups:
....@@ -1406,11 +1331,6 @@
14061331 return;
14071332 }
14081333
1409
-#ifdef CONFIG_ARCH_ROCKCHIP
1410
- sysfs_delete_link(&edev->dev.class->p->subsys.kobj,
1411
- &edev->dev.kobj, extcon_get_link_name(edev));
1412
-#endif
1413
-
14141334 device_unregister(&edev->dev);
14151335
14161336 if (edev->mutually_exclusive && edev->max_supported) {
....@@ -1427,6 +1347,7 @@
14271347 if (edev->max_supported) {
14281348 kfree(edev->extcon_dev_type.groups);
14291349 kfree(edev->cables);
1350
+ kfree(edev->nh);
14301351 }
14311352
14321353 put_device(&edev->dev);