hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
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
....@@ -182,6 +171,16 @@
182171 .type = EXTCON_TYPE_DISP | EXTCON_TYPE_USB,
183172 .id = EXTCON_DISP_HMD,
184173 .name = "HMD",
174
+ },
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",
185184 },
186185
187186 /* Miscellaneous external connector */
....@@ -495,21 +494,6 @@
495494 }
496495 EXPORT_SYMBOL_GPL(extcon_sync);
497496
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
-
513497 /**
514498 * extcon_get_state() - Get the state of an external connector.
515499 * @edev: the extcon device
....@@ -651,7 +635,7 @@
651635 unsigned long flags;
652636 int index, ret = 0;
653637
654
- *prop_val = (union extcon_property_value)(0);
638
+ *prop_val = (union extcon_property_value){0};
655639
656640 if (!edev)
657641 return -EINVAL;
....@@ -931,7 +915,7 @@
931915 struct notifier_block *nb)
932916 {
933917 unsigned long flags;
934
- int ret, idx = -EINVAL;
918
+ int ret, idx;
935919
936920 if (!edev || !nb)
937921 return -EINVAL;
....@@ -947,38 +931,6 @@
947931 return ret;
948932 }
949933 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);
982934
983935 /**
984936 * extcon_unregister_notifier() - Unregister a notifier block from the extcon.
....@@ -1128,19 +1080,6 @@
11281080 }
11291081 EXPORT_SYMBOL_GPL(extcon_dev_free);
11301082
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
-
11441083 /**
11451084 * extcon_dev_register() - Register an new extcon device
11461085 * @edev: the extcon device to be registered
....@@ -1191,7 +1130,6 @@
11911130 (unsigned long)atomic_inc_return(&edev_no));
11921131
11931132 if (edev->max_supported) {
1194
- char buf[10];
11951133 char *str;
11961134 struct extcon_cable *cable;
11971135
....@@ -1205,9 +1143,7 @@
12051143 for (index = 0; index < edev->max_supported; index++) {
12061144 cable = &edev->cables[index];
12071145
1208
- snprintf(buf, 10, "cable.%d", index);
1209
- str = kzalloc(strlen(buf) + 1,
1210
- GFP_KERNEL);
1146
+ str = kasprintf(GFP_KERNEL, "cable.%d", index);
12111147 if (!str) {
12121148 for (index--; index >= 0; index--) {
12131149 cable = &edev->cables[index];
....@@ -1217,7 +1153,6 @@
12171153
12181154 goto err_alloc_cables;
12191155 }
1220
- strcpy(str, buf);
12211156
12221157 cable->edev = edev;
12231158 cable->cable_index = index;
....@@ -1240,7 +1175,6 @@
12401175 }
12411176
12421177 if (edev->max_supported && edev->mutually_exclusive) {
1243
- char buf[80];
12441178 char *name;
12451179
12461180 /* Count the size of mutually_exclusive array */
....@@ -1265,9 +1199,8 @@
12651199 }
12661200
12671201 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);
1202
+ name = kasprintf(GFP_KERNEL, "0x%x",
1203
+ edev->mutually_exclusive[index]);
12711204 if (!name) {
12721205 for (index--; index >= 0; index--) {
12731206 kfree(edev->d_attrs_muex[index].attr.
....@@ -1278,7 +1211,6 @@
12781211 ret = -ENOMEM;
12791212 goto err_muex;
12801213 }
1281
- strcpy(name, buf);
12821214 sysfs_attr_init(&edev->d_attrs_muex[index].attr);
12831215 edev->d_attrs_muex[index].attr.name = name;
12841216 edev->d_attrs_muex[index].attr.mode = 0000;
....@@ -1313,26 +1245,14 @@
13131245 edev->dev.type = &edev->extcon_dev_type;
13141246 }
13151247
1316
- ret = device_register(&edev->dev);
1317
- if (ret) {
1318
- put_device(&edev->dev);
1319
- goto err_dev;
1320
- }
1321
-
13221248 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;
1249
+ if (edev->max_supported) {
1250
+ edev->nh = kcalloc(edev->max_supported, sizeof(*edev->nh),
1251
+ GFP_KERNEL);
1252
+ if (!edev->nh) {
1253
+ ret = -ENOMEM;
1254
+ goto err_alloc_nh;
1255
+ }
13361256 }
13371257
13381258 for (index = 0; index < edev->max_supported; index++)
....@@ -1343,25 +1263,22 @@
13431263 dev_set_drvdata(&edev->dev, edev);
13441264 edev->state = 0;
13451265
1266
+ ret = device_register(&edev->dev);
1267
+ if (ret) {
1268
+ put_device(&edev->dev);
1269
+ goto err_dev;
1270
+ }
1271
+
13461272 mutex_lock(&extcon_dev_list_lock);
13471273 list_add(&edev->entry, &extcon_dev_list);
13481274 mutex_unlock(&extcon_dev_list_lock);
13491275
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
-
13621276 return 0;
13631277
13641278 err_dev:
1279
+ if (edev->max_supported)
1280
+ kfree(edev->nh);
1281
+err_alloc_nh:
13651282 if (edev->max_supported)
13661283 kfree(edev->extcon_dev_type.groups);
13671284 err_alloc_groups:
....@@ -1406,11 +1323,6 @@
14061323 return;
14071324 }
14081325
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
-
14141326 device_unregister(&edev->dev);
14151327
14161328 if (edev->mutually_exclusive && edev->max_supported) {
....@@ -1427,6 +1339,7 @@
14271339 if (edev->max_supported) {
14281340 kfree(edev->extcon_dev_type.groups);
14291341 kfree(edev->cables);
1342
+ kfree(edev->nh);
14301343 }
14311344
14321345 put_device(&edev->dev);