forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 072de836f53be56a70cecf70b43ae43b7ce17376
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
....@@ -158,11 +147,6 @@
158147 .id = EXTCON_DISP_HDMI,
159148 .name = "HDMI",
160149 },
161
- [EXTCON_DISP_HDMI_AUDIO] = {
162
- .type = EXTCON_TYPE_DISP,
163
- .id = EXTCON_DISP_HDMI_AUDIO,
164
- .name = "HDMI-AUDIO",
165
- },
166150 [EXTCON_DISP_MHL] = {
167151 .type = EXTCON_TYPE_DISP,
168152 .id = EXTCON_DISP_MHL,
....@@ -187,6 +171,16 @@
187171 .type = EXTCON_TYPE_DISP | EXTCON_TYPE_USB,
188172 .id = EXTCON_DISP_HMD,
189173 .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",
190184 },
191185
192186 /* Miscellaneous external connector */
....@@ -500,21 +494,6 @@
500494 }
501495 EXPORT_SYMBOL_GPL(extcon_sync);
502496
503
-int extcon_blocking_sync(struct extcon_dev *edev, unsigned int id, bool val)
504
-{
505
- int index;
506
-
507
- if (!edev)
508
- return -EINVAL;
509
-
510
- index = find_cable_index_by_id(edev, id);
511
- if (index < 0)
512
- return index;
513
-
514
- return blocking_notifier_call_chain(&edev->bnh[index], val, edev);
515
-}
516
-EXPORT_SYMBOL(extcon_blocking_sync);
517
-
518497 /**
519498 * extcon_get_state() - Get the state of an external connector.
520499 * @edev: the extcon device
....@@ -656,7 +635,7 @@
656635 unsigned long flags;
657636 int index, ret = 0;
658637
659
- *prop_val = (union extcon_property_value)(0);
638
+ *prop_val = (union extcon_property_value){0};
660639
661640 if (!edev)
662641 return -EINVAL;
....@@ -936,7 +915,7 @@
936915 struct notifier_block *nb)
937916 {
938917 unsigned long flags;
939
- int ret, idx = -EINVAL;
918
+ int ret, idx;
940919
941920 if (!edev || !nb)
942921 return -EINVAL;
....@@ -952,38 +931,6 @@
952931 return ret;
953932 }
954933 EXPORT_SYMBOL_GPL(extcon_register_notifier);
955
-
956
-int extcon_register_blocking_notifier(struct extcon_dev *edev, unsigned int id,
957
- struct notifier_block *nb)
958
-{
959
- int idx = -EINVAL;
960
-
961
- if (!edev || !nb)
962
- return -EINVAL;
963
-
964
- idx = find_cable_index_by_id(edev, id);
965
- if (idx < 0)
966
- return idx;
967
-
968
- return blocking_notifier_chain_register(&edev->bnh[idx], nb);
969
-}
970
-EXPORT_SYMBOL(extcon_register_blocking_notifier);
971
-
972
-int extcon_unregister_blocking_notifier(struct extcon_dev *edev,
973
- unsigned int id, struct notifier_block *nb)
974
-{
975
- int idx;
976
-
977
- if (!edev || !nb)
978
- return -EINVAL;
979
-
980
- idx = find_cable_index_by_id(edev, id);
981
- if (idx < 0)
982
- return idx;
983
-
984
- return blocking_notifier_chain_unregister(&edev->bnh[idx], nb);
985
-}
986
-EXPORT_SYMBOL(extcon_unregister_blocking_notifier);
987934
988935 /**
989936 * extcon_unregister_notifier() - Unregister a notifier block from the extcon.
....@@ -1133,19 +1080,6 @@
11331080 }
11341081 EXPORT_SYMBOL_GPL(extcon_dev_free);
11351082
1136
-#ifdef CONFIG_ARCH_ROCKCHIP
1137
-static const char *extcon_get_link_name(struct extcon_dev *edev)
1138
-{
1139
- const char *dot = strchr(edev->name, '.');
1140
- const char *name = dot + 1;
1141
-
1142
- if (!dot || !name || !(*name))
1143
- name = edev->name;
1144
-
1145
- return name;
1146
-}
1147
-#endif
1148
-
11491083 /**
11501084 * extcon_dev_register() - Register an new extcon device
11511085 * @edev: the extcon device to be registered
....@@ -1196,7 +1130,6 @@
11961130 (unsigned long)atomic_inc_return(&edev_no));
11971131
11981132 if (edev->max_supported) {
1199
- char buf[10];
12001133 char *str;
12011134 struct extcon_cable *cable;
12021135
....@@ -1210,9 +1143,7 @@
12101143 for (index = 0; index < edev->max_supported; index++) {
12111144 cable = &edev->cables[index];
12121145
1213
- snprintf(buf, 10, "cable.%d", index);
1214
- str = kzalloc(strlen(buf) + 1,
1215
- GFP_KERNEL);
1146
+ str = kasprintf(GFP_KERNEL, "cable.%d", index);
12161147 if (!str) {
12171148 for (index--; index >= 0; index--) {
12181149 cable = &edev->cables[index];
....@@ -1222,7 +1153,6 @@
12221153
12231154 goto err_alloc_cables;
12241155 }
1225
- strcpy(str, buf);
12261156
12271157 cable->edev = edev;
12281158 cable->cable_index = index;
....@@ -1245,7 +1175,6 @@
12451175 }
12461176
12471177 if (edev->max_supported && edev->mutually_exclusive) {
1248
- char buf[80];
12491178 char *name;
12501179
12511180 /* Count the size of mutually_exclusive array */
....@@ -1270,9 +1199,8 @@
12701199 }
12711200
12721201 for (index = 0; edev->mutually_exclusive[index]; index++) {
1273
- sprintf(buf, "0x%x", edev->mutually_exclusive[index]);
1274
- name = kzalloc(strlen(buf) + 1,
1275
- GFP_KERNEL);
1202
+ name = kasprintf(GFP_KERNEL, "0x%x",
1203
+ edev->mutually_exclusive[index]);
12761204 if (!name) {
12771205 for (index--; index >= 0; index--) {
12781206 kfree(edev->d_attrs_muex[index].attr.
....@@ -1283,7 +1211,6 @@
12831211 ret = -ENOMEM;
12841212 goto err_muex;
12851213 }
1286
- strcpy(name, buf);
12871214 sysfs_attr_init(&edev->d_attrs_muex[index].attr);
12881215 edev->d_attrs_muex[index].attr.name = name;
12891216 edev->d_attrs_muex[index].attr.mode = 0000;
....@@ -1318,26 +1245,14 @@
13181245 edev->dev.type = &edev->extcon_dev_type;
13191246 }
13201247
1321
- ret = device_register(&edev->dev);
1322
- if (ret) {
1323
- put_device(&edev->dev);
1324
- goto err_dev;
1325
- }
1326
-
13271248 spin_lock_init(&edev->lock);
1328
- edev->nh = devm_kcalloc(&edev->dev, edev->max_supported,
1329
- sizeof(*edev->nh), GFP_KERNEL);
1330
- if (!edev->nh) {
1331
- ret = -ENOMEM;
1332
- device_unregister(&edev->dev);
1333
- goto err_dev;
1334
- }
1335
-
1336
- edev->bnh = devm_kzalloc(&edev->dev,
1337
- sizeof(*edev->bnh) * edev->max_supported, GFP_KERNEL);
1338
- if (!edev->bnh) {
1339
- ret = -ENOMEM;
1340
- 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
+ }
13411256 }
13421257
13431258 for (index = 0; index < edev->max_supported; index++)
....@@ -1348,25 +1263,22 @@
13481263 dev_set_drvdata(&edev->dev, edev);
13491264 edev->state = 0;
13501265
1266
+ ret = device_register(&edev->dev);
1267
+ if (ret) {
1268
+ put_device(&edev->dev);
1269
+ goto err_dev;
1270
+ }
1271
+
13511272 mutex_lock(&extcon_dev_list_lock);
13521273 list_add(&edev->entry, &extcon_dev_list);
13531274 mutex_unlock(&extcon_dev_list_lock);
13541275
1355
-#ifdef CONFIG_ARCH_ROCKCHIP
1356
- {
1357
- const char *name = extcon_get_link_name(edev);
1358
-
1359
- ret = sysfs_create_link_nowarn(&edev->dev.class->p->subsys.kobj,
1360
- &edev->dev.kobj, name);
1361
- if (ret)
1362
- dev_err(&edev->dev,
1363
- "failed to create extcon %s link\n", name);
1364
- }
1365
-#endif
1366
-
13671276 return 0;
13681277
13691278 err_dev:
1279
+ if (edev->max_supported)
1280
+ kfree(edev->nh);
1281
+err_alloc_nh:
13701282 if (edev->max_supported)
13711283 kfree(edev->extcon_dev_type.groups);
13721284 err_alloc_groups:
....@@ -1411,11 +1323,6 @@
14111323 return;
14121324 }
14131325
1414
-#ifdef CONFIG_ARCH_ROCKCHIP
1415
- sysfs_delete_link(&edev->dev.class->p->subsys.kobj,
1416
- &edev->dev.kobj, extcon_get_link_name(edev));
1417
-#endif
1418
-
14191326 device_unregister(&edev->dev);
14201327
14211328 if (edev->mutually_exclusive && edev->max_supported) {
....@@ -1432,6 +1339,7 @@
14321339 if (edev->max_supported) {
14331340 kfree(edev->extcon_dev_type.groups);
14341341 kfree(edev->cables);
1342
+ kfree(edev->nh);
14351343 }
14361344
14371345 put_device(&edev->dev);