Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp2579432rdh; Mon, 30 Oct 2023 01:06:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEeDhBXNq8rsu+bM57nWsfGx0ecyQA3V0swWyL3p2hsK690uHmNq1GY+oKXGUlZDLpipjB2 X-Received: by 2002:a05:6358:9f93:b0:168:ff1b:8f69 with SMTP id fy19-20020a0563589f9300b00168ff1b8f69mr7429398rwb.17.1698653193143; Mon, 30 Oct 2023 01:06:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698653193; cv=none; d=google.com; s=arc-20160816; b=UC71uDL0mABDvp+mE4tTDtDylFv0k8lnYFtYM0WrQ6cEsByLim9cLgvuh2kWdcJQED AK848p5MmWpxs9rR6SEW/fvQ2dcNGR8zFWk3h+jZpon7fLD/TFCtCMYnFYJQIH/ObQ+/ Id8LIQD1Dw9LQ4qt7wO/vdm53wGCDrr14BPqs2NyCyBvyvt9YQdSHM2DXgv6t4GqUWyJ DaJwKB5oZUmz5IBWW8BYnFr2QT4UHlGQu0QuhYeMw29z6JX5txmstNRl65TZz6mKyS4E el4lX0Iu2mEteQywp7OvnJatZTjcs0kxXDM031TER/XBffiRNp6TWh9UCOZ8l/IfTcEv p+1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:to:from :references:cc:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=eQeOxn3lchQjy9IwIOUUEredww/rqkL2X7LAfreMOiQ=; fh=W/bVSqeA2t3jf56PJS+FEiQF1o7Og02ZjtvDysZaTgc=; b=sZi6bm5jveeNsfFkHCyqAAxjaMh0mKHtUuqskkadAkYey0NqCh6g8datxsVJxt6xm2 3j48/+COp6BsA2jNBGaqJLo2RZefXglCpKJraFDhPZlrtNX093JKjkuRaYP/sq0H+sPY OYbXlngxtWzSOWrpynps088RJpyYNO0II3sesaKUtbIduJ3OpYwSGBJiyRQax7YMKT1/ Z0odsq8/R4SmazoQsmrrsCFctGCET0vG5ZmqCemXqTT/TM6FXuFBtaNqKnF43oL4Vjrc 3mHDLIRyTWdSY4yD6ull5NSBQhEpQN6Vtr8iHYYy728Wyn0/Is95CRYzjLa3yk9wTkA5 GkzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=bLXibatj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id 67-20020a630046000000b005b92a5ef2c3si4599333pga.439.2023.10.30.01.06.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 01:06:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=bLXibatj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id E02188075919; Mon, 30 Oct 2023 01:06:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231992AbjJ3IF5 (ORCPT + 99 others); Mon, 30 Oct 2023 04:05:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231970AbjJ3IFz (ORCPT ); Mon, 30 Oct 2023 04:05:55 -0400 Received: from smtp.smtpout.orange.fr (smtp-17.smtpout.orange.fr [80.12.242.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5527FC9 for ; Mon, 30 Oct 2023 01:05:46 -0700 (PDT) Received: from [192.168.1.18] ([86.243.2.178]) by smtp.orange.fr with ESMTPA id xNHKqXbMchjcfxNHKq5hVe; Mon, 30 Oct 2023 09:05:44 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1698653144; bh=eQeOxn3lchQjy9IwIOUUEredww/rqkL2X7LAfreMOiQ=; h=Date:Subject:Cc:References:From:To:In-Reply-To; b=bLXibatjRS5tWgqTWfDNAAz0gLqWsSbpcYGOnLBlQd5HQ3ksEwjRy8mhW75WwaxtL jU85TaDGWgz6zHlCz257bqbDg8wbK8CA2w36swL4HYhZhgm144T39xncBYt0FzCzJk 8ouf/Z7SQZrUlXhQq4USRsbi0MO6ElyMlJCBw+aup2AWpGoUB0J/J7ZBprZm0LOBJp bADnpD1Qk5JLVZdIxUX5daJVJbo7gpnMs+z1BmNZEFo0OBuGwnnClg/RYBcjSGeb60 IiQwHqeJ65+Zm5B6Aw9Bqt/VYCNxzTc6U4zDhpf5NHEPFIsKnrNrodwL108m+OtEt+ 6cJ8xGH+YgIKw== X-ME-Helo: [192.168.1.18] X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Mon, 30 Oct 2023 09:05:44 +0100 X-ME-IP: 86.243.2.178 Message-ID: <6654879e-f577-4e0c-a00a-0ee45d379b51@wanadoo.fr> Date: Mon, 30 Oct 2023 09:05:42 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 1/2] usb: dwc3: add Realtek DHC RTD SoC dwc3 glue layer driver Content-Language: fr Cc: Thinh.Nguyen@synopsys.com, conor+dt@kernel.org, devicetree@vger.kernel.org, gregkh@linuxfoundation.org, krzysztof.kozlowski+dt@linaro.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, robh+dt@kernel.org References: <20230826031028.1892-1-stanley_chang@realtek.com> From: Christophe JAILLET To: stanley_chang@realtek.com In-Reply-To: <20230826031028.1892-1-stanley_chang@realtek.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FORGED_SPF_HELO,RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,T_SPF_TEMPERROR autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 30 Oct 2023 01:06:01 -0700 (PDT) Le 26/08/2023 à 05:10, Stanley Chang a écrit : > Realtek DHC RTD SoCs integrate dwc3 IP and has some customizations to > support different generations of SoCs. > > The RTD1619b subclass SoC only supports USB 2.0 from dwc3. The driver > can set a maximum speed to support this. Add role switching function, > that can switch USB roles through other drivers, or switch USB roles > through user space through set /sys/class/usb_role/. > > Signed-off-by: Stanley Chang > Acked-by: Thinh Nguyen > --- ... > +static int dwc3_rtk_probe_dwc3_core(struct dwc3_rtk *rtk) > +{ > + struct device *dev = rtk->dev; > + struct device_node *node = dev->of_node; > + struct platform_device *dwc3_pdev; > + struct device *dwc3_dev; > + struct device_node *dwc3_node; > + enum usb_dr_mode dr_mode; > + int ret = 0; > + > + ret = dwc3_rtk_init(rtk); > + if (ret) > + return -EINVAL; > + > + ret = of_platform_populate(node, NULL, NULL, dev); > + if (ret) { > + dev_err(dev, "failed to add dwc3 core\n"); > + return ret; > + } > + > + dwc3_node = of_get_compatible_child(node, "snps,dwc3"); > + if (!dwc3_node) { > + dev_err(dev, "failed to find dwc3 core node\n"); > + ret = -ENODEV; > + goto depopulate; > + } > + > + dwc3_pdev = of_find_device_by_node(dwc3_node); > + if (!dwc3_pdev) { > + dev_err(dev, "failed to find dwc3 core platform_device\n"); > + ret = -ENODEV; > + goto err_node_put; > + } > + > + dwc3_dev = &dwc3_pdev->dev; > + rtk->dwc = platform_get_drvdata(dwc3_pdev); > + if (!rtk->dwc) { > + dev_err(dev, "failed to find dwc3 core\n"); > + ret = -ENODEV; > + goto err_pdev_put; > + } > + > + dr_mode = usb_get_dr_mode(dwc3_dev); > + if (dr_mode != rtk->dwc->dr_mode) { > + dev_info(dev, "dts set dr_mode=%d, but dwc3 set dr_mode=%d\n", > + dr_mode, rtk->dwc->dr_mode); > + dr_mode = rtk->dwc->dr_mode; > + } > + > + switch (dr_mode) { > + case USB_DR_MODE_PERIPHERAL: > + rtk->cur_role = USB_ROLE_DEVICE; > + break; > + case USB_DR_MODE_HOST: > + rtk->cur_role = USB_ROLE_HOST; > + break; > + default: > + dev_dbg(rtk->dev, "%s: dr_mode=%d\n", __func__, dr_mode); > + break; > + } > + > + if (device_property_read_bool(dwc3_dev, "usb-role-switch")) { > + ret = dwc3_rtk_setup_role_switch(rtk); > + if (ret) { > + dev_err(dev, "dwc3_rtk_setup_role_switch fail=%d\n", ret); > + goto err_pdev_put; > + } > + rtk->cur_role = dwc3_rtk_get_role(rtk); > + } > + > + switch_usb2_role(rtk, rtk->cur_role); > + > + return 0; > + > +err_pdev_put: > + platform_device_put(dwc3_pdev); > +err_node_put: > + of_node_put(dwc3_node); > +depopulate: > + of_platform_depopulate(dev); > + > + return ret; > +} > + > +static int dwc3_rtk_probe(struct platform_device *pdev) > +{ > + struct dwc3_rtk *rtk; > + struct device *dev = &pdev->dev; > + struct resource *res; > + void __iomem *regs; > + int ret = 0; > + > + rtk = devm_kzalloc(dev, sizeof(*rtk), GFP_KERNEL); > + if (!rtk) { > + ret = -ENOMEM; > + goto out; > + } > + > + platform_set_drvdata(pdev, rtk); > + > + rtk->dev = dev; > + > + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); > + if (!res) { > + dev_err(dev, "missing memory resource\n"); > + ret = -ENODEV; > + goto out; > + } > + > + regs = devm_ioremap_resource(dev, res); > + if (IS_ERR(regs)) { > + ret = PTR_ERR(regs); > + goto out; > + } > + > + rtk->regs = regs; > + rtk->regs_size = resource_size(res); > + > + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); > + if (res) { > + rtk->pm_base = devm_ioremap_resource(dev, res); > + if (IS_ERR(rtk->pm_base)) { > + ret = PTR_ERR(rtk->pm_base); > + goto out; > + } > + } > + > + ret = dwc3_rtk_probe_dwc3_core(rtk); > + > +out: > + return ret; > +} > + > +static void dwc3_rtk_remove(struct platform_device *pdev) > +{ > + struct dwc3_rtk *rtk = platform_get_drvdata(pdev); > + > + rtk->dwc = NULL; > + > + dwc3_rtk_remove_role_switch(rtk); > + Hi, Is something like platform_device_put(dwc3_pdev); of_node_put(dwc3_node); needed in the remove function? (as done in the error handling path of dwc3_rtk_probe_dwc3_core()) Or should it be added at the end of dwc3_rtk_probe_dwc3_core() if the reference are nor needed anymore when we leave the function? CJ > + of_platform_depopulate(rtk->dev); > +} > + ...