forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f9004dbfff8a3fbbd7e2a88c8a4327c7f2f8e5b2
kernel/drivers/extcon/extcon-max14577.c
....@@ -1,20 +1,10 @@
1
-/*
2
- * extcon-max14577.c - MAX14577/77836 extcon driver to support MUIC
3
- *
4
- * Copyright (C) 2013,2014 Samsung Electronics
5
- * Chanwoo Choi <cw00.choi@samsung.com>
6
- * Krzysztof Kozlowski <krzk@kernel.org>
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- * GNU General Public License for more details.
17
- */
1
+// SPDX-License-Identifier: GPL-2.0+
2
+//
3
+// extcon-max14577.c - MAX14577/77836 extcon driver to support MUIC
4
+//
5
+// Copyright (C) 2013,2014 Samsung Electronics
6
+// Chanwoo Choi <cw00.choi@samsung.com>
7
+// Krzysztof Kozlowski <krzk@kernel.org>
188
199 #include <linux/kernel.h>
2010 #include <linux/module.h>
....@@ -667,6 +657,8 @@
667657 struct max14577 *max14577 = dev_get_drvdata(pdev->dev.parent);
668658 struct max14577_muic_info *info;
669659 int delay_jiffies;
660
+ int cable_type;
661
+ bool attached;
670662 int ret;
671663 int i;
672664 u8 id;
....@@ -721,7 +713,7 @@
721713 max14577_extcon_cable);
722714 if (IS_ERR(info->edev)) {
723715 dev_err(&pdev->dev, "failed to allocate memory for extcon\n");
724
- return -ENOMEM;
716
+ return PTR_ERR(info->edev);
725717 }
726718
727719 ret = devm_extcon_dev_register(&pdev->dev, info->edev);
....@@ -735,8 +727,17 @@
735727 info->path_uart = CTRL1_SW_UART;
736728 delay_jiffies = msecs_to_jiffies(DELAY_MS_DEFAULT);
737729
738
- /* Set initial path for UART */
739
- max14577_muic_set_path(info, info->path_uart, true);
730
+ /* Set initial path for UART when JIG is connected to get serial logs */
731
+ ret = max14577_bulk_read(info->max14577->regmap,
732
+ MAX14577_MUIC_REG_STATUS1, info->status, 2);
733
+ if (ret) {
734
+ dev_err(info->dev, "Cannot read STATUS registers\n");
735
+ return ret;
736
+ }
737
+ cable_type = max14577_muic_get_cable_type(info, MAX14577_CABLE_GROUP_ADC,
738
+ &attached);
739
+ if (attached && cable_type == MAX14577_MUIC_ADC_FACTORY_MODE_UART_OFF)
740
+ max14577_muic_set_path(info, info->path_uart, true);
740741
741742 /* Check revision number of MUIC device*/
742743 ret = max14577_read_reg(info->max14577->regmap,
....@@ -781,9 +782,19 @@
781782 };
782783 MODULE_DEVICE_TABLE(platform, max14577_muic_id);
783784
785
+static const struct of_device_id of_max14577_muic_dt_match[] = {
786
+ { .compatible = "maxim,max14577-muic",
787
+ .data = (void *)MAXIM_DEVICE_TYPE_MAX14577, },
788
+ { .compatible = "maxim,max77836-muic",
789
+ .data = (void *)MAXIM_DEVICE_TYPE_MAX77836, },
790
+ { },
791
+};
792
+MODULE_DEVICE_TABLE(of, of_max14577_muic_dt_match);
793
+
784794 static struct platform_driver max14577_muic_driver = {
785795 .driver = {
786796 .name = "max14577-muic",
797
+ .of_match_table = of_max14577_muic_dt_match,
787798 },
788799 .probe = max14577_muic_probe,
789800 .remove = max14577_muic_remove,