forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f9004dbfff8a3fbbd7e2a88c8a4327c7f2f8e5b2
kernel/drivers/extcon/extcon-max77843.c
....@@ -1,15 +1,10 @@
1
-/*
2
- * extcon-max77843.c - Maxim MAX77843 extcon driver to support
3
- * MUIC(Micro USB Interface Controller)
4
- *
5
- * Copyright (C) 2015 Samsung Electronics
6
- * Author: Jaewon Kim <jaewon02.kim@samsung.com>
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
- */
1
+// SPDX-License-Identifier: GPL-2.0+
2
+//
3
+// extcon-max77843.c - Maxim MAX77843 extcon driver to support
4
+// MUIC(Micro USB Interface Controller)
5
+//
6
+// Copyright (C) 2015 Samsung Electronics
7
+// Author: Jaewon Kim <jaewon02.kim@samsung.com>
138
149 #include <linux/extcon-provider.h>
1510 #include <linux/i2c.h>
....@@ -779,12 +774,12 @@
779774 {
780775 int ret;
781776
782
- max77843->i2c_muic = i2c_new_dummy(max77843->i2c->adapter,
777
+ max77843->i2c_muic = i2c_new_dummy_device(max77843->i2c->adapter,
783778 I2C_ADDR_MUIC);
784
- if (!max77843->i2c_muic) {
779
+ if (IS_ERR(max77843->i2c_muic)) {
785780 dev_err(&max77843->i2c->dev,
786781 "Cannot allocate I2C device for MUIC\n");
787
- return -ENOMEM;
782
+ return PTR_ERR(max77843->i2c_muic);
788783 }
789784
790785 i2c_set_clientdata(max77843->i2c_muic, max77843);
....@@ -817,6 +812,8 @@
817812 struct max77693_dev *max77843 = dev_get_drvdata(pdev->dev.parent);
818813 struct max77843_muic_info *info;
819814 unsigned int id;
815
+ int cable_type;
816
+ bool attached;
820817 int i, ret;
821818
822819 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
....@@ -848,7 +845,7 @@
848845 max77843_extcon_cable);
849846 if (IS_ERR(info->edev)) {
850847 dev_err(&pdev->dev, "Failed to allocate memory for extcon\n");
851
- ret = -ENODEV;
848
+ ret = PTR_ERR(info->edev);
852849 goto err_muic_irq;
853850 }
854851
....@@ -861,9 +858,19 @@
861858 /* Set ADC debounce time */
862859 max77843_muic_set_debounce_time(info, MAX77843_DEBOUNCE_TIME_25MS);
863860
864
- /* Set initial path for UART */
865
- max77843_muic_set_path(info, MAX77843_MUIC_CONTROL1_SW_UART, true,
866
- false);
861
+ /* Set initial path for UART when JIG is connected to get serial logs */
862
+ ret = regmap_bulk_read(max77843->regmap_muic,
863
+ MAX77843_MUIC_REG_STATUS1, info->status,
864
+ MAX77843_MUIC_STATUS_NUM);
865
+ if (ret) {
866
+ dev_err(info->dev, "Cannot read STATUS registers\n");
867
+ goto err_muic_irq;
868
+ }
869
+ cable_type = max77843_muic_get_cable_type(info, MAX77843_CABLE_GROUP_ADC,
870
+ &attached);
871
+ if (attached && cable_type == MAX77843_MUIC_ADC_FACTORY_MODE_UART_OFF)
872
+ max77843_muic_set_path(info, MAX77843_MUIC_CONTROL1_SW_UART,
873
+ true, false);
867874
868875 /* Check revision number of MUIC device */
869876 ret = regmap_read(max77843->regmap_muic, MAX77843_MUIC_REG_ID, &id);