forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f9004dbfff8a3fbbd7e2a88c8a4327c7f2f8e5b2
kernel/drivers/extcon/extcon-max8997.c
....@@ -1,19 +1,9 @@
1
-/*
2
- * extcon-max8997.c - MAX8997 extcon driver to support MAX8997 MUIC
3
- *
4
- * Copyright (C) 2012 Samsung Electronics
5
- * Donggeun Kim <dg77.kim@samsung.com>
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License as published by
9
- * the Free Software Foundation; either version 2 of the License, or
10
- * (at your option) any later version.
11
- *
12
- * This program is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- * GNU General Public License for more details.
16
- */
1
+// SPDX-License-Identifier: GPL-2.0+
2
+//
3
+// extcon-max8997.c - MAX8997 extcon driver to support MAX8997 MUIC
4
+//
5
+// Copyright (C) 2012 Samsung Electronics
6
+// Donggeun Kim <dg77.kim@samsung.com>
177
188 #include <linux/kernel.h>
199 #include <linux/module.h>
....@@ -640,6 +630,8 @@
640630 struct max8997_platform_data *pdata = dev_get_platdata(max8997->dev);
641631 struct max8997_muic_info *info;
642632 int delay_jiffies;
633
+ int cable_type;
634
+ bool attached;
643635 int ret, i;
644636
645637 info = devm_kzalloc(&pdev->dev, sizeof(struct max8997_muic_info),
....@@ -682,7 +674,7 @@
682674 info->edev = devm_extcon_dev_allocate(&pdev->dev, max8997_extcon_cable);
683675 if (IS_ERR(info->edev)) {
684676 dev_err(&pdev->dev, "failed to allocate memory for extcon\n");
685
- ret = -ENOMEM;
677
+ ret = PTR_ERR(info->edev);
686678 goto err_irq;
687679 }
688680
....@@ -732,8 +724,17 @@
732724 delay_jiffies = msecs_to_jiffies(DELAY_MS_DEFAULT);
733725 }
734726
735
- /* Set initial path for UART */
736
- max8997_muic_set_path(info, info->path_uart, true);
727
+ /* Set initial path for UART when JIG is connected to get serial logs */
728
+ ret = max8997_bulk_read(info->muic, MAX8997_MUIC_REG_STATUS1,
729
+ 2, info->status);
730
+ if (ret) {
731
+ dev_err(info->dev, "failed to read MUIC register\n");
732
+ goto err_irq;
733
+ }
734
+ cable_type = max8997_muic_get_cable_type(info,
735
+ MAX8997_CABLE_GROUP_ADC, &attached);
736
+ if (attached && cable_type == MAX8997_MUIC_ADC_FACTORY_MODE_UART_OFF)
737
+ max8997_muic_set_path(info, info->path_uart, true);
737738
738739 /* Set ADC debounce time */
739740 max8997_muic_set_debounce_time(info, ADC_DEBOUNCE_TIME_25MS);