From mboxrd@z Thu Jan 1 00:00:00 1970 Delivery-date: Tue, 24 Aug 2021 13:23:21 +0200 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by lore.white.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1mIUWX-0006ku-KL for lore@lore.pengutronix.de; Tue, 24 Aug 2021 13:23:21 +0200 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mIUWU-0002Dg-Ua for lore@pengutronix.de; Tue, 24 Aug 2021 13:23:21 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date: Message-ID:From:References:Cc:To:Subject:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=M882C7d68e4scqQPk+z0DkEm61N5HnqoeAgBs5LkwYw=; b=Igmj/VKbW36WgYCeTxnEC4VKWr G+cY317YJoj8viUKgKQn3S/S7XhTJT8PIgQ/YeqmBAHN9E/8t6gQ5jSvS41HPua1DSxaXyenH2g0r I1DhCA1ovmbbWmWG7Spql1ylLj+Te7c3U4CI85CnOZAICZLbUWdSofPS/SSLbI4UZVEZlRLMOdK15 X7kdXKf9493wePUMBlH1q9XWzS02C2FQyo//vDN6XR8ronktGrzYZrvMCcYq7uNeXLitdJX7N6QIa S5mVAhCV9S5DcoInuoHRbGNNTLiJHFZh9UewxUcgIPROGpQQxCumhF2Cvd2GmvdOIfgqqR2gndkdp 8W7D5XMg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mIUUe-002n2h-Q2; Tue, 24 Aug 2021 11:21:24 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mIUUX-002n1H-Fn for barebox@lists.infradead.org; Tue, 24 Aug 2021 11:21:21 +0000 Received: from gallifrey.ext.pengutronix.de ([2001:67c:670:201:5054:ff:fe8d:eefb] helo=[127.0.0.1]) by metis.ext.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1mIUUV-000246-Ub; Tue, 24 Aug 2021 13:21:15 +0200 To: Marco Felsch Cc: barebox@lists.infradead.org References: <20210824104648.15938-1-m.felsch@pengutronix.de> <36ae0849-3c29-ae3e-eb52-7271cf345232@pengutronix.de> From: Ahmad Fatoum Message-ID: <94931ec0-c614-abe0-5396-85dbde991690@pengutronix.de> Date: Tue, 24 Aug 2021 13:21:15 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210824_042117_594004_46B3A58A X-CRM114-Status: GOOD ( 27.58 ) X-BeenThere: barebox@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "barebox" X-SA-Exim-Connect-IP: 2607:7c80:54:e::133 X-SA-Exim-Mail-From: barebox-bounces+lore=pengutronix.de@lists.infradead.org X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on metis.ext.pengutronix.de X-Spam-Level: X-Spam-Status: No, score=-5.6 required=4.0 tests=AWL,BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Subject: Re: [PATCH] usb: imx-us-phy: add vbus_valid ro parameter X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on metis.ext.pengutronix.de) On 24.08.21 13:13, Marco Felsch wrote: > Hi Ahmad, > > On 21-08-24 13:01, Ahmad Fatoum wrote: >> Hello Marco, >> >> On 24.08.21 12:46, Marco Felsch wrote: >>> The parameter can be used by init scripts to detect a plugged usb cable. >>> Upon a plugged usb cable the barebox behaviour can be changed which can >>> be useful e.g. during production to apply a special production >>> environment. >>> >>> Signed-off-by: Marco Felsch >>> --- >>> drivers/usb/imx/imx-usb-phy.c | 34 +++++++++++++++++++++++++++++++++- >>> 1 file changed, 33 insertions(+), 1 deletion(-) >>> >>> diff --git a/drivers/usb/imx/imx-usb-phy.c b/drivers/usb/imx/imx-usb-phy.c >>> index 32098ef248..9420c8c109 100644 >>> --- a/drivers/usb/imx/imx-usb-phy.c >>> +++ b/drivers/usb/imx/imx-usb-phy.c >>> @@ -37,9 +37,12 @@ >>> #define BM_USBPHY_CTRL_ENHOSTDISCONDETECT BIT(1) >>> >>> #define ANADIG_USB1_CHRG_DETECT_SET 0x1b4 >>> -#define ANADIG_USB2_CHRG_DETECT_SET 0x214 >>> #define ANADIG_USB1_CHRG_DETECT_EN_B BIT(20) >>> #define ANADIG_USB1_CHRG_DETECT_CHK_CHRG_B BIT(19) >>> +#define ANADIG_USB1_VBUS_DETECT_STAT 0x1c0 >>> +#define ANADIG_USB1_VBUS_DETECT_STAT_VBUS_VALID BIT(3) >>> +#define ANADIG_USB2_CHRG_DETECT_SET 0x214 >>> +#define ANADIG_USB2_VBUS_DETECT_STAT 0x220 >>> >>> struct imx_usbphy { >>> struct usb_phy usb_phy; >>> @@ -132,6 +135,27 @@ static const struct phy_ops imx_phy_ops = { >>> .to_usbphy = imx_usbphy_to_usbphy, >>> }; >>> >>> +/* Albeit the access can only happen serial use two variables */ >>> +unsigned int vbus_valid_usb1; >>> +unsigned int vbus_valid_usb2; >>> + >>> +static int imx_usbphy_get_vbus_state(struct param_d *p, void *priv) >>> +{ >>> + struct imx_usbphy *imxphy = priv; >>> + unsigned int *vbus_valid; >>> + unsigned int reg, val; >>> + >>> + reg = imxphy->port_id ? >>> + ANADIG_USB1_VBUS_DETECT_STAT : >>> + ANADIG_USB2_VBUS_DETECT_STAT; >>> + val = readl(imxphy->anatop + reg); >>> + >>> + vbus_valid = imxphy->port_id ? &vbus_valid_usb1 : &vbus_valid_usb2; >>> + *vbus_valid = !!(val & ANADIG_USB1_VBUS_DETECT_STAT_VBUS_VALID); >>> + >>> + return 0; >>> +} >>> + >>> static int imx_usbphy_probe(struct device_d *dev) >>> { >>> struct resource *iores; >>> @@ -149,11 +173,19 @@ static int imx_usbphy_probe(struct device_d *dev) >>> imxphy->port_id = ret; >>> >>> if (of_get_property(np, "fsl,anatop", NULL)) { >>> + unsigned int *vbus_valid = imxphy->port_id ? >>> + &vbus_valid_usb1 : >>> + &vbus_valid_usb2; >> >> Can you allocate this in imxphy? That way you avoid globals >> and don't hardcode the existance of only two phys into the driver. > > You're right, good point. > >>> + >>> imxphy->anatop = >>> syscon_base_lookup_by_phandle(np, "fsl,anatop"); >>> ret = PTR_ERR_OR_ZERO(imxphy->anatop); >>> if (ret) >>> goto err_free; >>> + >>> + dev_add_param_bool(dev, "vbus_valid", param_set_readonly, >>> + imx_usbphy_get_vbus_state, vbus_valid, >>> + imxphy); >> >> I assume valid == usb port is in gadget mode and host is supplying vbus? > > Your're right. > >> What happens when port is in host mode? A comment explaining this would >> be nice. > > That's a good question didn't checked this and the datasheet don't > distinguish between those modes. I will test it and add a comment. prt_imx6_check_usb_boot may also be interesting to you. The protonic boards use this to detect whether a USB drive is connected or not. Combining those could give you a usb.connected_to={gadget,host,none} (or some other better name) Cheers, Ahmad > > Regards, > Marco > >> >>> } >>> >>> iores = dev_request_mem_resource(dev, 0); >>> >> >> >> -- >> Pengutronix e.K. | | >> Steuerwalder Str. 21 | http://www.pengutronix.de/ | >> 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | >> Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | >> > -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox