[PATCH v3 0/3] Add MAX14526 MUIC driver

MAX14526 MUIC is used by LG P880/P895 which are currently in the process of merging.
MAX14526 is a powerful extcon device which has the ability to accurately determine plugged devices. In this implementation muic can be configured to represent 3 modes: CP-USB/UART and AP-USB. Unfortunately AP-UART was disabled on P880/P895. Additionally the driver configures some stuff required by the charger.
Extcon class has empty platform struct and ops, all configuration is performed in the probe. Filling of struct and ops is welcomed.
--- Changes from v2: - created a new simple extcon uclass
Changes from v1: - used log_* instead of printf - log messages made simpler ---
Svyatoslav Ryhel (3): dm: extcom: add an uclass for extcon test: Add tests for the extcon extcon: add MAX14526 MUIC support
arch/sandbox/dts/test.dts | 4 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/extcon/Kconfig | 31 +++++++ drivers/extcon/Makefile | 7 ++ drivers/extcon/extcon-max14526.c | 151 +++++++++++++++++++++++++++++++ drivers/extcon/extcon-sandbox.c | 17 ++++ drivers/extcon/extcon-uclass.c | 16 ++++ include/dm/uclass-id.h | 1 + include/extcon.h | 19 ++++ test/dm/Makefile | 1 + test/dm/extcon.c | 21 +++++ 12 files changed, 271 insertions(+) create mode 100644 drivers/extcon/Kconfig create mode 100644 drivers/extcon/Makefile create mode 100644 drivers/extcon/extcon-max14526.c create mode 100644 drivers/extcon/extcon-sandbox.c create mode 100644 drivers/extcon/extcon-uclass.c create mode 100644 include/extcon.h create mode 100644 test/dm/extcon.c

Add a new simple uclass for extcon. Currently all setup is done in the probe. Uclass struct and ops are empty for now.
Signed-off-by: Svyatoslav Ryhel clamor95@gmail.com --- drivers/Kconfig | 2 ++ drivers/Makefile | 1 + drivers/extcon/Kconfig | 15 +++++++++++++++ drivers/extcon/Makefile | 5 +++++ drivers/extcon/extcon-uclass.c | 16 ++++++++++++++++ include/dm/uclass-id.h | 1 + include/extcon.h | 19 +++++++++++++++++++ 7 files changed, 59 insertions(+) create mode 100644 drivers/extcon/Kconfig create mode 100644 drivers/extcon/Makefile create mode 100644 drivers/extcon/extcon-uclass.c create mode 100644 include/extcon.h
diff --git a/drivers/Kconfig b/drivers/Kconfig index 9101e538b0..75937fbb6d 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -36,6 +36,8 @@ source "drivers/dfu/Kconfig"
source "drivers/dma/Kconfig"
+source "drivers/extcon/Kconfig" + source "drivers/fastboot/Kconfig"
source "drivers/firmware/Kconfig" diff --git a/drivers/Makefile b/drivers/Makefile index 58be410135..ed1e71c4d6 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -9,6 +9,7 @@ obj-$(CONFIG_$(SPL_TPL_)DM) += core/ obj-$(CONFIG_$(SPL_TPL_)DMA) += dma/ obj-$(CONFIG_$(SPL_TPL_)DMA_LEGACY) += dma/ obj-$(CONFIG_$(SPL_TPL_)DFU) += dfu/ +obj-$(CONFIG_$(SPL_TPL_)EXTCON) += extcon/ obj-$(CONFIG_$(SPL_TPL_)GPIO) += gpio/ obj-$(CONFIG_$(SPL_TPL_)DRIVERS_MISC) += misc/ obj-$(CONFIG_$(SPL_TPL_)SYSRESET) += sysreset/ diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig new file mode 100644 index 0000000000..8a50250d21 --- /dev/null +++ b/drivers/extcon/Kconfig @@ -0,0 +1,15 @@ +menu "Extcon Support" + +config EXTCON + bool "External Connector Class (extcon) support" + depends on DM + help + Say Y here to enable external connector class (extcon) support. + This allows monitoring external connectors and supports external + connectors with multiple states; i.e., an extcon that may have + multiple cables attached. For example, an external connector + of a device may be used to connect an HDMI cable and a AC adaptor, + and to host USB ports. Many of 30-pin connectors including PDMI + are also good examples. + +endmenu diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile new file mode 100644 index 0000000000..2510e91c07 --- /dev/null +++ b/drivers/extcon/Makefile @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (C) 2023 Svyatoslav Ryhel clamor95@gmail.com + +obj-$(CONFIG_EXTCON) += extcon-uclass.o diff --git a/drivers/extcon/extcon-uclass.c b/drivers/extcon/extcon-uclass.c new file mode 100644 index 0000000000..9dd22b5762 --- /dev/null +++ b/drivers/extcon/extcon-uclass.c @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2023 Svyatoslav Ryhel clamor95@gmail.com + */ + +#define LOG_CATEGORY UCLASS_EXTCON + +#include <common.h> +#include <extcon.h> +#include <dm.h> + +UCLASS_DRIVER(extcon) = { + .id = UCLASS_EXTCON, + .name = "extcon", + .per_device_plat_auto = sizeof(struct extcon_uc_plat), +}; diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index 576237b954..94ab46c5ba 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -56,6 +56,7 @@ enum uclass_id { UCLASS_EFI_MEDIA, /* Devices provided by UEFI firmware */ UCLASS_ETH, /* Ethernet device */ UCLASS_ETH_PHY, /* Ethernet PHY device */ + UCLASS_EXTCON, /* External Connector Class */ UCLASS_FIRMWARE, /* Firmware */ UCLASS_FPGA, /* FPGA device */ UCLASS_FUZZING_ENGINE, /* Fuzzing engine */ diff --git a/include/extcon.h b/include/extcon.h new file mode 100644 index 0000000000..d060f5a3c1 --- /dev/null +++ b/include/extcon.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) 2023 Svyatoslav Ryhel clamor95@gmail.com + */ + +#ifndef __EXTCON_H +#define __EXTCON_H + +struct udevice; + +/** + * struct extcon_uc_plat - Platform data the uclass stores about each device + * + * To be filled + */ +struct extcon_uc_plat { +}; + +#endif

On Fri, 21 Apr 2023 at 01:05, Svyatoslav Ryhel clamor95@gmail.com wrote:
Add a new simple uclass for extcon. Currently all setup is done in the probe. Uclass struct and ops are empty for now.
Signed-off-by: Svyatoslav Ryhel clamor95@gmail.com
drivers/Kconfig | 2 ++ drivers/Makefile | 1 + drivers/extcon/Kconfig | 15 +++++++++++++++ drivers/extcon/Makefile | 5 +++++ drivers/extcon/extcon-uclass.c | 16 ++++++++++++++++ include/dm/uclass-id.h | 1 + include/extcon.h | 19 +++++++++++++++++++ 7 files changed, 59 insertions(+) create mode 100644 drivers/extcon/Kconfig create mode 100644 drivers/extcon/Makefile create mode 100644 drivers/extcon/extcon-uclass.c create mode 100644 include/extcon.h
Reviewed-by: Simon Glass sjg@chromium.org

Provide tests to the simple extcon device.
Signed-off-by: Svyatoslav Ryhel clamor95@gmail.com --- arch/sandbox/dts/test.dts | 4 ++++ drivers/extcon/Kconfig | 7 +++++++ drivers/extcon/Makefile | 1 + drivers/extcon/extcon-sandbox.c | 17 +++++++++++++++++ test/dm/Makefile | 1 + test/dm/extcon.c | 21 +++++++++++++++++++++ 6 files changed, 51 insertions(+) create mode 100644 drivers/extcon/extcon-sandbox.c create mode 100644 test/dm/extcon.c
diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 7c1ee71cb7..731b48459d 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -1802,6 +1802,10 @@ compatible = "u-boot,fwu-mdata-gpt"; fwu-mdata-store = <&mmc0>; }; + + extcon { + compatible = "sandbox,extcon"; + }; };
#include "sandbox_pmic.dtsi" diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig index 8a50250d21..6fd3d2b97b 100644 --- a/drivers/extcon/Kconfig +++ b/drivers/extcon/Kconfig @@ -12,4 +12,11 @@ config EXTCON and to host USB ports. Many of 30-pin connectors including PDMI are also good examples.
+config EXTCON_SANDBOX + bool "Sandbox extcon" + depends on EXTCON + help + Enable extcon support for sandbox. This is an emulation of a real + extcon. Currectly all configuration is done in the probe. + endmenu diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile index 2510e91c07..c4223d97d1 100644 --- a/drivers/extcon/Makefile +++ b/drivers/extcon/Makefile @@ -3,3 +3,4 @@ # Copyright (C) 2023 Svyatoslav Ryhel clamor95@gmail.com
obj-$(CONFIG_EXTCON) += extcon-uclass.o +obj-$(CONFIG_EXTCON_SANDBOX) += extcon-sandbox.o diff --git a/drivers/extcon/extcon-sandbox.c b/drivers/extcon/extcon-sandbox.c new file mode 100644 index 0000000000..ab6a6c1cfd --- /dev/null +++ b/drivers/extcon/extcon-sandbox.c @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2022 Svyatoslav Ryhel clamor95@gmail.com + */ + +#include <dm.h> + +static const struct udevice_id sandbox_extcon_ids[] = { + { .compatible = "sandbox,extcon" }, + { /* sentinel */ } +}; + +U_BOOT_DRIVER(extcon_sandbox) = { + .name = "extcon_sandbox", + .id = UCLASS_EXTCON, + .of_match = sandbox_extcon_ids, +}; diff --git a/test/dm/Makefile b/test/dm/Makefile index e15bdbf04b..5ada659974 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -44,6 +44,7 @@ obj-$(CONFIG_DM_DSA) += dsa.o obj-$(CONFIG_ECDSA_VERIFY) += ecdsa.o obj-$(CONFIG_EFI_MEDIA_SANDBOX) += efi_media.o obj-$(CONFIG_DM_ETH) += eth.o +obj-$(CONFIG_EXTCON) += extcon.o ifneq ($(CONFIG_EFI_PARTITION),) obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fastboot.o endif diff --git a/test/dm/extcon.c b/test/dm/extcon.c new file mode 100644 index 0000000000..6a4e22bfdc --- /dev/null +++ b/test/dm/extcon.c @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2023 Svyatoslav Ryhel clamor95@gmail.com + */ + +#include <dm.h> +#include <dm/test.h> +#include <extcon.h> +#include <test/test.h> +#include <test/ut.h> + +static int dm_test_extcon(struct unit_test_state *uts) +{ + struct udevice *dev; + + ut_assertok(uclass_get_device_by_name(UCLASS_EXTCON, "extcon", &dev)); + + return 0; +} + +DM_TEST(dm_test_extcon, UT_TESTF_SCAN_FDT);

On Fri, 21 Apr 2023 at 01:05, Svyatoslav Ryhel clamor95@gmail.com wrote:
Provide tests to the simple extcon device.
Signed-off-by: Svyatoslav Ryhel clamor95@gmail.com
arch/sandbox/dts/test.dts | 4 ++++ drivers/extcon/Kconfig | 7 +++++++ drivers/extcon/Makefile | 1 + drivers/extcon/extcon-sandbox.c | 17 +++++++++++++++++ test/dm/Makefile | 1 + test/dm/extcon.c | 21 +++++++++++++++++++++ 6 files changed, 51 insertions(+) create mode 100644 drivers/extcon/extcon-sandbox.c create mode 100644 test/dm/extcon.c
Reviewed-by: Simon Glass sjg@chromium.org

MAX14526 is a powerful extcon chip which allows detection of various plugs like usb, mhl, uart, headset etc. This version of driver implements support of AP-usb and CP-usb/uart paths.
Tested-by: Andreas Westman Dorcsak hedmoo@yahoo.com # LG P880 T30 Tested-by: Svyatoslav Ryhel clamor95@gmail.com # LG P895 T30 Signed-off-by: Svyatoslav Ryhel clamor95@gmail.com --- drivers/extcon/Kconfig | 9 ++ drivers/extcon/Makefile | 1 + drivers/extcon/extcon-max14526.c | 151 +++++++++++++++++++++++++++++++ 3 files changed, 161 insertions(+) create mode 100644 drivers/extcon/extcon-max14526.c
diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig index 6fd3d2b97b..fbb73354aa 100644 --- a/drivers/extcon/Kconfig +++ b/drivers/extcon/Kconfig @@ -19,4 +19,13 @@ config EXTCON_SANDBOX Enable extcon support for sandbox. This is an emulation of a real extcon. Currectly all configuration is done in the probe.
+config EXTCON_MAX14526 + bool "Maxim MAX14526 EXTCON Support" + depends on DM_I2C + depends on EXTCON + help + If you say yes here you get support for the MUIC device of + Maxim MAX14526. The MAX14526 MUIC is a USB port accessory + detector and switch. + endmenu diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile index c4223d97d1..3309f2aac2 100644 --- a/drivers/extcon/Makefile +++ b/drivers/extcon/Makefile @@ -4,3 +4,4 @@
obj-$(CONFIG_EXTCON) += extcon-uclass.o obj-$(CONFIG_EXTCON_SANDBOX) += extcon-sandbox.o +obj-$(CONFIG_EXTCON_MAX14526) += extcon-max14526.o diff --git a/drivers/extcon/extcon-max14526.c b/drivers/extcon/extcon-max14526.c new file mode 100644 index 0000000000..a33b5ef919 --- /dev/null +++ b/drivers/extcon/extcon-max14526.c @@ -0,0 +1,151 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2022 Svyatoslav Ryhel clamor95@gmail.com + */ + +#include <common.h> +#include <dm.h> +#include <i2c.h> +#include <linux/delay.h> +#include <linux/err.h> +#include <log.h> +#include <extcon.h> +#include <asm/gpio.h> + +#define CONTROL_1 0x01 +#define SW_CONTROL 0x03 + +#define ID_200 0x10 +#define ADC_EN 0x02 +#define CP_EN 0x01 + +#define DP_USB 0x00 +#define DP_UART 0x08 +#define DP_AUDIO 0x10 +#define DP_OPEN 0x38 + +#define DM_USB 0x00 +#define DM_UART 0x01 +#define DM_AUDIO 0x02 +#define DM_OPEN 0x07 + +#define AP_USB BIT(0) +#define CP_USB BIT(1) +#define CP_UART BIT(2) + +struct max14526_priv { + struct gpio_desc usif_gpio; + struct gpio_desc dp2t_gpio; + struct gpio_desc ifx_usb_vbus_gpio; +}; + +static void max14526_set_mode(struct udevice *dev, int mode) +{ + struct max14526_priv *priv = dev_get_priv(dev); + int ret; + + if ((mode & AP_USB) || (mode & CP_USB)) { + /* Connect CP UART signals to AP */ + ret = dm_gpio_set_value(&priv->usif_gpio, 0); + if (ret) + log_debug("cp-uart > ap failed (%d)\n", ret); + } + + if (mode & CP_UART) { + /* Connect CP UART signals to DP2T */ + ret = dm_gpio_set_value(&priv->usif_gpio, 1); + if (ret) + log_debug("cp-uart > dp2t failed (%d)\n", ret); + } + + if (mode & CP_USB) { + /* Connect CP USB to MUIC UART */ + ret = dm_gpio_set_value(&priv->ifx_usb_vbus_gpio, 1); + if (ret) + log_debug("usb-vbus-gpio enable failed (%d)\n", ret); + + ret = dm_gpio_set_value(&priv->dp2t_gpio, 1); + if (ret) + log_debug("cp-usb > muic-uart failed (%d)\n", ret); + } + + if ((mode & AP_USB) || (mode & CP_UART)) { + /* Connect CP UART to MUIC UART */ + ret = dm_gpio_set_value(&priv->dp2t_gpio, 0); + if (ret) + log_debug("cp-uart > muic-uart failed (%d)\n", ret); + } + + if (mode & AP_USB) { + /* Enables USB Path */ + ret = dm_i2c_reg_write(dev, SW_CONTROL, DP_USB | DM_USB); + if (ret) + log_debug("USB path set failed: %d\n", ret); + } + + if ((mode & CP_USB) || (mode & CP_UART)) { + /* Enables UART Path */ + ret = dm_i2c_reg_write(dev, SW_CONTROL, DP_UART | DM_UART); + if (ret) + log_debug("UART path set failed: %d\n", ret); + } + + /* Enables 200K, Charger Pump, and ADC */ + ret = dm_i2c_reg_write(dev, CONTROL_1, ID_200 | ADC_EN | CP_EN); + if (ret) + log_debug("200K, Charger Pump, and ADC set failed: %d\n", ret); +} + +static int max14526_probe(struct udevice *dev) +{ + struct max14526_priv *priv = dev_get_priv(dev); + int ret, mode = 0; + + ret = gpio_request_by_name(dev, "usif-gpios", 0, + &priv->usif_gpio, GPIOD_IS_OUT); + if (ret) { + log_err("could not decode usif-gpios (%d)\n", ret); + return ret; + } + + ret = gpio_request_by_name(dev, "dp2t-gpios", 0, + &priv->dp2t_gpio, GPIOD_IS_OUT); + if (ret) { + log_err("could not decode dp2t-gpios (%d)\n", ret); + return ret; + } + + if (dev_read_bool(dev, "maxim,ap-usb")) + mode |= AP_USB; + + if (dev_read_bool(dev, "maxim,cp-usb")) { + mode |= CP_USB; + + ret = gpio_request_by_name(dev, "usb-vbus-gpios", 0, + &priv->ifx_usb_vbus_gpio, GPIOD_IS_OUT); + if (ret) { + log_err("could not decode usb-vbus-gpios (%d)\n", ret); + return ret; + } + } + + if (dev_read_bool(dev, "maxim,cp-uart")) + mode |= CP_UART; + + max14526_set_mode(dev, mode); + + return 0; +} + +static const struct udevice_id max14526_ids[] = { + { .compatible = "maxim,max14526-muic" }, + { } +}; + +U_BOOT_DRIVER(extcon_max14526) = { + .name = "extcon_max14526", + .id = UCLASS_EXTCON, + .of_match = max14526_ids, + .probe = max14526_probe, + .priv_auto = sizeof(struct max14526_priv), +};

On Fri, 21 Apr 2023 at 01:05, Svyatoslav Ryhel clamor95@gmail.com wrote:
MAX14526 is a powerful extcon chip which allows detection of various plugs like usb, mhl, uart, headset etc. This version of driver implements support of AP-usb and CP-usb/uart paths.
Tested-by: Andreas Westman Dorcsak hedmoo@yahoo.com # LG P880 T30 Tested-by: Svyatoslav Ryhel clamor95@gmail.com # LG P895 T30 Signed-off-by: Svyatoslav Ryhel clamor95@gmail.com
drivers/extcon/Kconfig | 9 ++ drivers/extcon/Makefile | 1 + drivers/extcon/extcon-max14526.c | 151 +++++++++++++++++++++++++++++++ 3 files changed, 161 insertions(+) create mode 100644 drivers/extcon/extcon-max14526.c
Reviewed-by: Simon Glass sjg@chromium.org
participants (2)
-
Simon Glass
-
Svyatoslav Ryhel