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
....@@ -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 */
....@@ -217,6 +211,14 @@
217211 * @attr_name: "name" sysfs entry
218212 * @attr_state: "state" sysfs entry
219213 * @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
220222 */
221223 struct extcon_cable {
222224 struct extcon_dev *edev;
....@@ -500,21 +502,6 @@
500502 }
501503 EXPORT_SYMBOL_GPL(extcon_sync);
502504
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
-
518505 /**
519506 * extcon_get_state() - Get the state of an external connector.
520507 * @edev: the extcon device
....@@ -656,7 +643,7 @@
656643 unsigned long flags;
657644 int index, ret = 0;
658645
659
- *prop_val = (union extcon_property_value)(0);
646
+ *prop_val = (union extcon_property_value){0};
660647
661648 if (!edev)
662649 return -EINVAL;
....@@ -936,7 +923,7 @@
936923 struct notifier_block *nb)
937924 {
938925 unsigned long flags;
939
- int ret, idx = -EINVAL;
926
+ int ret, idx;
940927
941928 if (!edev || !nb)
942929 return -EINVAL;
....@@ -952,38 +939,6 @@
952939 return ret;
953940 }
954941 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);
987942
988943 /**
989944 * extcon_unregister_notifier() - Unregister a notifier block from the extcon.
....@@ -1133,19 +1088,6 @@
11331088 }
11341089 EXPORT_SYMBOL_GPL(extcon_dev_free);
11351090
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
-
11491091 /**
11501092 * extcon_dev_register() - Register an new extcon device
11511093 * @edev: the extcon device to be registered
....@@ -1196,7 +1138,6 @@
11961138 (unsigned long)atomic_inc_return(&edev_no));
11971139
11981140 if (edev->max_supported) {
1199
- char buf[10];
12001141 char *str;
12011142 struct extcon_cable *cable;
12021143
....@@ -1210,9 +1151,7 @@
12101151 for (index = 0; index < edev->max_supported; index++) {
12111152 cable = &edev->cables[index];
12121153
1213
- snprintf(buf, 10, "cable.%d", index);
1214
- str = kzalloc(strlen(buf) + 1,
1215
- GFP_KERNEL);
1154
+ str = kasprintf(GFP_KERNEL, "cable.%d", index);
12161155 if (!str) {
12171156 for (index--; index >= 0; index--) {
12181157 cable = &edev->cables[index];
....@@ -1222,7 +1161,6 @@
12221161
12231162 goto err_alloc_cables;
12241163 }
1225
- strcpy(str, buf);
12261164
12271165 cable->edev = edev;
12281166 cable->cable_index = index;
....@@ -1245,7 +1183,6 @@
12451183 }
12461184
12471185 if (edev->max_supported && edev->mutually_exclusive) {
1248
- char buf[80];
12491186 char *name;
12501187
12511188 /* Count the size of mutually_exclusive array */
....@@ -1270,9 +1207,8 @@
12701207 }
12711208
12721209 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);
1210
+ name = kasprintf(GFP_KERNEL, "0x%x",
1211
+ edev->mutually_exclusive[index]);
12761212 if (!name) {
12771213 for (index--; index >= 0; index--) {
12781214 kfree(edev->d_attrs_muex[index].attr.
....@@ -1283,7 +1219,6 @@
12831219 ret = -ENOMEM;
12841220 goto err_muex;
12851221 }
1286
- strcpy(name, buf);
12871222 sysfs_attr_init(&edev->d_attrs_muex[index].attr);
12881223 edev->d_attrs_muex[index].attr.name = name;
12891224 edev->d_attrs_muex[index].attr.mode = 0000;
....@@ -1318,26 +1253,14 @@
13181253 edev->dev.type = &edev->extcon_dev_type;
13191254 }
13201255
1321
- ret = device_register(&edev->dev);
1322
- if (ret) {
1323
- put_device(&edev->dev);
1324
- goto err_dev;
1325
- }
1326
-
13271256 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;
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
+ }
13411264 }
13421265
13431266 for (index = 0; index < edev->max_supported; index++)
....@@ -1348,25 +1271,22 @@
13481271 dev_set_drvdata(&edev->dev, edev);
13491272 edev->state = 0;
13501273
1274
+ ret = device_register(&edev->dev);
1275
+ if (ret) {
1276
+ put_device(&edev->dev);
1277
+ goto err_dev;
1278
+ }
1279
+
13511280 mutex_lock(&extcon_dev_list_lock);
13521281 list_add(&edev->entry, &extcon_dev_list);
13531282 mutex_unlock(&extcon_dev_list_lock);
13541283
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
-
13671284 return 0;
13681285
13691286 err_dev:
1287
+ if (edev->max_supported)
1288
+ kfree(edev->nh);
1289
+err_alloc_nh:
13701290 if (edev->max_supported)
13711291 kfree(edev->extcon_dev_type.groups);
13721292 err_alloc_groups:
....@@ -1411,11 +1331,6 @@
14111331 return;
14121332 }
14131333
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
-
14191334 device_unregister(&edev->dev);
14201335
14211336 if (edev->mutually_exclusive && edev->max_supported) {
....@@ -1432,6 +1347,7 @@
14321347 if (edev->max_supported) {
14331348 kfree(edev->extcon_dev_type.groups);
14341349 kfree(edev->cables);
1350
+ kfree(edev->nh);
14351351 }
14361352
14371353 put_device(&edev->dev);