Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp942056rdb; Fri, 19 Jan 2024 03:44:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IErcYoZHcQp6NejkEskERKJh6WQ2ERmPw7rK7E6htM2WtKdWj0OR0A3zPLTwBbmHyJpise2 X-Received: by 2002:a17:906:cc53:b0:a2d:e4b9:45b4 with SMTP id mm19-20020a170906cc5300b00a2de4b945b4mr1262076ejb.75.1705664671848; Fri, 19 Jan 2024 03:44:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705664671; cv=pass; d=google.com; s=arc-20160816; b=ipDR8RKX6kZ0umVMC1fWiaYLflCZ1XKyEBh6TV/BcXv70Hb354hsRxmRLYyNNCEJBP yGTF0ZldLqXS6osXtZru4u1XqGwamA19vxRj0TDADn+8wAkQzQ7WT9pz40g6jS/35Gpc 2rZH0JQoTr/sNMpZ9PpILIgHJgnVwtuKqJt6Q5Z/R/6L+atXNoHS1d/AbHuqNdOX1NGA 4b/tai5rgTSYVl2WUVFyEgHC9nkmBGcCTX0UhjQ1C6Nd1vPWMWPXlh81DepZXpZlYq+b vpMOfn4xVrpavVowX6eEp91hgKNe43WQua6mcp5DaOXHXgMvCGC/uNKzX5raP1NlQGea A3sg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=7PYEUA5mJ1YHKP7Oh2k+8QM8qEV8euCh8GWXE3TNoB4=; fh=8aStwdepYebLDDFohsWZnfYkesLRGX4cnjlDqzQpAXA=; b=dJvGHPnwhetx6I4vnIO9rU+9dEXVPJOh3h3PC+iYj+JOgkZ9p8ZW9CUoTR7lRs3j2a bM78ZymV6ZFBNm/6WwLedKQt0BsrVnWmshs3BV0WWT6ncNz014f63nC0t4jadSTc0Wbs lFqAAZtXNKVR0rPzV6Uy9yZRNadmqW8pRufIDTj+VGSRV0rEExWOja2YmSkgBeOd/6qW KzLmlgwIfjh7fekGJL3BrezQE0smmIMFqnFT8TGH4dksRQDyalkbwC32qNtOFg3gF5Wg WUcEIYpGFoq5BoL1QJnYoU765EFfjqUWceAJwKdME8oW+LsrfAqsYfvCTpTuhlkaqPao jpgw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vrUSiG8X; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-31110-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31110-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id t11-20020a170906a10b00b00a27a0bf414bsi7852747ejy.559.2024.01.19.03.44.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 03:44:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-31110-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vrUSiG8X; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-31110-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31110-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 744531F242FA for ; Fri, 19 Jan 2024 11:44:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7D1ED4F1E3; Fri, 19 Jan 2024 11:44:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="vrUSiG8X" Received: from mail-yw1-f178.google.com (mail-yw1-f178.google.com [209.85.128.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 182663C6BF for ; Fri, 19 Jan 2024 11:44:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705664659; cv=none; b=FY0OiL+3FX78ROI+02OcXuRMkJRI17hQO1ry4bECmhuwsabBBME6DwyebJfkvfjZG6g43HQS9yeULWNtThNBhyWXrCrMy+LmD8kCUU7kHbv+j9568AgYq0g+NHn3Ays13BkaxJ4glYFTRJJRq7axPNmMX2XNOy+A5czvjHVkF9A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705664659; c=relaxed/simple; bh=mF60unASc9afNmxL5MQ70oM6hhUep/SyqH/G62XJCf8=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=JAJ5iKyTaXeuVQDeYSzgPB3xIxQkWfFHMzm0ur97gu51qRyT2oWWUjXFAJVyimCBrSu6wIjeVZzoN5Xk0nsWYZVdI8+NnkTxpo8aiACUgca4nSwRC+nD1cRHenGzbFv1wqibNlVuE8d15umWuWrS4D/wFcMgKzp2k7/EBf+ya1w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=vrUSiG8X; arc=none smtp.client-ip=209.85.128.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-5efb0e180f0so7176767b3.1 for ; Fri, 19 Jan 2024 03:44:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705664657; x=1706269457; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=7PYEUA5mJ1YHKP7Oh2k+8QM8qEV8euCh8GWXE3TNoB4=; b=vrUSiG8X6y2nyb8wJ/5fl4d1HcuQ4PpMDtcN4csrE1uYZUG9NedGC4FkK1ZttBbWl7 aQoXmACmGrZibxVy+bnQyplWI+Ex0A7Y1KHZB467EjVzbow94PvPmEhyOPzkvpKH8r82 nEmRX5N+hsVXcq/I3dkfjA2wJVI8nkFR7bKRADsIXVUj1Fdxk3fRhjrAUamBej73hn4o 8moKLWNL7JRzgxuwSSDD25bKJVdvyhEOt1BZIZeun0coKD7iwhLILXfvwvbxvd9fkovY M4Bt7KROeGxJyseAm+jjAbsEaLujqjK5j8GPLKqntAVyb5XYPdlp6RpJsXFsDTz2R9y+ Wxeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705664657; x=1706269457; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7PYEUA5mJ1YHKP7Oh2k+8QM8qEV8euCh8GWXE3TNoB4=; b=pGMookh9yc3+q6YMqZPk35TFrzVWYMJj32C60PQ3eueGE4lhXm6UzWvkCyI6ityUoM CzBYMKBwB287rBVX3UiCG73C0otx+lFB2ituvaASlQSmYN5rX//ygej5UqRXcJX8OXbM y6d3pKIfYiVfKYwBLpWOvbxcYXdw+WXMIDXnlFV2pg4a01rYZOTdp2Esz9HwXm0zDFJA rr3XXZ+OkCmXwvg4F5qBJ+JH6N8kLje/wFNA4Jlj/athTFSA2iI65wuU5lX0rW0pFFLQ dzw7ypnOEIoEp4M5nlgHLszmuD9skmgkwTLUW4jdZdqYhwg1YW/qXGgMQZFC/PLPy1T8 3xvg== X-Gm-Message-State: AOJu0Ywz61SLouiLDrESjgcjuaC+vTQk1vk8Dma92YpGzlWaUvjFFC2E BbkKohvA5ld/aA+bd3HYVcU7JMZZqMgX5V6no7mo142f3/5o+g/wGtpAOl5HsVwt31ytw70rGy6 glZb+Y8j3ZXFV5xdMlz8oCRVh301y9GKIxNhz9g== X-Received: by 2002:a81:720b:0:b0:5d7:a3f:fce3 with SMTP id n11-20020a81720b000000b005d70a3ffce3mr2262644ywc.8.1705664657042; Fri, 19 Jan 2024 03:44:17 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240119104550.140061-1-angelogioacchino.delregno@collabora.com> <20240119104550.140061-3-angelogioacchino.delregno@collabora.com> In-Reply-To: <20240119104550.140061-3-angelogioacchino.delregno@collabora.com> From: Dmitry Baryshkov Date: Fri, 19 Jan 2024 13:44:06 +0200 Message-ID: Subject: Re: [PATCH 2/2] usb: typec: mux: Add ITE IT5205 Alternate Mode Passive MUX driver To: AngeloGioacchino Del Regno Cc: gregkh@linuxfoundation.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, heikki.krogerus@linux.intel.com, matthias.bgg@gmail.com, neil.armstrong@linaro.org, andersson@kernel.org, nathan@kernel.org, luca.weiss@fairphone.com, tianping.fang@mediatek.com, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, kernel@collabora.com Content-Type: text/plain; charset="UTF-8" On Fri, 19 Jan 2024 at 12:46, AngeloGioacchino Del Regno wrote: > > The ITE IT5202 is a USB Type-C Alternate Mode Passive MUX, used for > muxing the SBU lines of a Type-C port with DisplayPort altmode and > also providing an orientation switch. > > Signed-off-by: AngeloGioacchino Del Regno > --- > drivers/usb/typec/mux/Kconfig | 10 ++ > drivers/usb/typec/mux/Makefile | 1 + > drivers/usb/typec/mux/it5205.c | 292 +++++++++++++++++++++++++++++++++ > 3 files changed, 303 insertions(+) > create mode 100644 drivers/usb/typec/mux/it5205.c > > diff --git a/drivers/usb/typec/mux/Kconfig b/drivers/usb/typec/mux/Kconfig > index d2cb5e733e57..399c7b0983df 100644 > --- a/drivers/usb/typec/mux/Kconfig > +++ b/drivers/usb/typec/mux/Kconfig > @@ -36,6 +36,16 @@ config TYPEC_MUX_INTEL_PMC > control the USB role switch and also the multiplexer/demultiplexer > switches used with USB Type-C Alternate Modes. > > +config TYPEC_MUX_IT5205 > + tristate "ITE IT5205 Type-C USB Alt Mode Passive MUX driver" > + depends on I2C > + select REGMAP_I2C > + help > + Driver for the ITE IT5205 Type-C USB Alternate Mode Passive MUX > + which provides support for muxing DisplayPort and sideband signals > + on a common USB Type-C connector. > + If compiled as a module, the module will be named it5205. > + > config TYPEC_MUX_NB7VPQ904M > tristate "On Semiconductor NB7VPQ904M Type-C redriver driver" > depends on I2C > diff --git a/drivers/usb/typec/mux/Makefile b/drivers/usb/typec/mux/Makefile > index 57dc9ac6f8dc..bb96f30267af 100644 > --- a/drivers/usb/typec/mux/Makefile > +++ b/drivers/usb/typec/mux/Makefile > @@ -4,6 +4,7 @@ obj-$(CONFIG_TYPEC_MUX_FSA4480) += fsa4480.o > obj-$(CONFIG_TYPEC_MUX_GPIO_SBU) += gpio-sbu-mux.o > obj-$(CONFIG_TYPEC_MUX_PI3USB30532) += pi3usb30532.o > obj-$(CONFIG_TYPEC_MUX_INTEL_PMC) += intel_pmc_mux.o > +obj-$(CONFIG_TYPEC_MUX_IT5205) += it5205.o > obj-$(CONFIG_TYPEC_MUX_NB7VPQ904M) += nb7vpq904m.o > obj-$(CONFIG_TYPEC_MUX_PTN36502) += ptn36502.o > obj-$(CONFIG_TYPEC_MUX_WCD939X_USBSS) += wcd939x-usbss.o > diff --git a/drivers/usb/typec/mux/it5205.c b/drivers/usb/typec/mux/it5205.c > new file mode 100644 > index 000000000000..99203b8a086d > --- /dev/null > +++ b/drivers/usb/typec/mux/it5205.c > @@ -0,0 +1,292 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * ITE IT5205 Type-C USB alternate mode passive mux > + * > + * Copyright (c) 2020 MediaTek Inc. > + * Copyright (c) 2024 Collabora Ltd. > + * AngeloGioacchino Del Regno > + * > + */ > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include I'd say, it is a usual custom to sort this list. [skipped] > + > +static int it5205_mux_set(struct typec_mux_dev *mux, struct typec_mux_state *state) > +{ > + struct it5205 *it = typec_mux_get_drvdata(mux); > + u8 val; > + > + switch (state->mode) { > + case TYPEC_STATE_USB: > + val = IT5205_USB; > + break; > + case TYPEC_DP_STATE_C: > + fallthrough; > + case TYPEC_DP_STATE_E: > + val = IT5205_DP; > + break; > + case TYPEC_DP_STATE_D: > + val = IT5205_DP_USB; > + break; > + case TYPEC_STATE_SAFE: > + fallthrough; > + default: > + val = 0; > + break; > + } Please add a check for state->altmode. All states at TYPEC_STATE_MODAL and above (which includes TYPEC_DP_STATE_[CDE]) are only relevant with connection to the particular typec->altmode SVID. > + > + return regmap_update_bits(it->regmap, IT5205_REG_MUXCR, > + IT5205_DP_USB_CTRL_MASK, val); > +} > + > +static irqreturn_t it5205_irq_handler(int irq, void *data) > +{ > + struct it5205 *it = data; > + int ret; > + u32 val; > + > + ret = regmap_read(it->regmap, IT5205_REG_ISR, &val); > + if (ret) > + return IRQ_NONE; > + > + if (val & IT5205_ISR_CSBU_OVP) { > + dev_warn(&it->client->dev, "Overvoltage detected!\n"); Will it cut the voltage automatically? > + > + /* Reset CSBU */ > + regmap_update_bits(it->regmap, IT5205_REG_CSBUSR, > + IT5205_CSBUSR_SWITCH, 0); > + regmap_update_bits(it->regmap, IT5205_REG_CSBUSR, > + IT5205_CSBUSR_SWITCH, IT5205_CSBUSR_SWITCH); > + } > + > + return IRQ_HANDLED; > +} The rest LGTM -- With best wishes Dmitry