mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
To: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
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
Subject: Re: [PATCH 2/2] usb: typec: mux: Add ITE IT5205 Alternate Mode Passive MUX driver
Date: Fri, 19 Jan 2024 13:55:17 +0100	[thread overview]
Message-ID: <8834d309-19f2-466f-aed4-ab0f9e2df02d@collabora.com> (raw)
In-Reply-To: <CAA8EJprroFtKvCeZtP_FySr5d6v4dogYQKFQvzPJLpwWBuMrKw@mail.gmail.com>

Il 19/01/24 12:44, Dmitry Baryshkov ha scritto:
> On Fri, 19 Jan 2024 at 12:46, AngeloGioacchino Del Regno
> <angelogioacchino.delregno@collabora.com> 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 <angelogioacchino.delregno@collabora.com>
>> ---
>>   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 <angelogioacchino.delregno@collabora.com>
>> + *
>> + */
>> +#include <linux/i2c.h>
>> +#include <linux/kernel.h>
>> +#include <linux/delay.h>
>> +#include <linux/module.h>
>> +#include <linux/platform_device.h>
>> +#include <linux/mutex.h>
>> +#include <linux/of_platform.h>
>> +#include <linux/regmap.h>
>> +#include <linux/usb/typec.h>
>> +#include <linux/usb/typec_mux.h>
>> +#include <linux/usb/typec_dp.h>
>> +#include <linux/regulator/consumer.h>
>> +#include <linux/gpio/consumer.h>
>> +#include <linux/gpio.h>
>> +#include <linux/usb/tcpm.h>
> 
> I'd say, it is a usual custom to sort this list.
> 

Oh, whoops. Totally forgot to do that, sorry - thanks for pointing that out!
Done for v2.

> [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.
> 

Done for v2.

>> +
>> +       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?
> 

As far as I understand, yes.
Unfortunately, there's no datasheet.

>> +
>> +               /* 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
> 
> 




      reply	other threads:[~2024-01-19 12:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-19 10:45 [PATCH 0/2] Add ITE IT5205 Passive MUX AngeloGioacchino Del Regno
2024-01-19 10:45 ` [PATCH 1/2] dt-bindings: usb: Introduce ITE IT5205 Alt. Mode " AngeloGioacchino Del Regno
2024-01-19 10:45 ` [PATCH 2/2] usb: typec: mux: Add ITE IT5205 Alternate Mode Passive MUX driver AngeloGioacchino Del Regno
2024-01-19 11:44   ` Dmitry Baryshkov
2024-01-19 12:55     ` AngeloGioacchino Del Regno [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8834d309-19f2-466f-aed4-ab0f9e2df02d@collabora.com \
    --to=angelogioacchino.delregno@collabora.com \
    --cc=andersson@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.baryshkov@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=kernel@collabora.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=luca.weiss@fairphone.com \
    --cc=matthias.bgg@gmail.com \
    --cc=nathan@kernel.org \
    --cc=neil.armstrong@linaro.org \
    --cc=robh+dt@kernel.org \
    --cc=tianping.fang@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®