Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp9229676imu; Wed, 5 Dec 2018 00:58:24 -0800 (PST) X-Google-Smtp-Source: AFSGD/XAocbjARfyvjW2Xl3Re3sPLg9CG1A8cxtJ55Pl+3gUCg1qf2pdHffa+BVpPlfhtu28OWsV X-Received: by 2002:a17:902:b118:: with SMTP id q24mr23639238plr.209.1544000304862; Wed, 05 Dec 2018 00:58:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544000304; cv=none; d=google.com; s=arc-20160816; b=Exl19p48Mkqp0qBX4Vt5GrQBTfL622+4YTOMPPc50yHfYwWTK2sSk78TYEbua1u21s 8J8Iry3ByA/BAzb8tppMWv/BMGFEIpVfKYhG5LRjFr45p3Bn8HLXOIJ2qOnFireZEvO7 ciaNwn/p9pZIBbXGaYSPrHmfSNFgMl3bCGOnoCgJVfmMklGF/6Iic+FXCqSheUqNTeFn htoxqC7dio4oA1rURoBerAoa0bbxtYE+LXB3Qp84QeKBgYEM5eHO8Br7v6hqSmQftjCd 8yAVmGyzVas7i6/LASkZbVT6/MgMQVw2kHpRNiUhyTyGpxuewP8gLkmY4fJ/A0MbfaEW vcxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=zERybKQJd2x47hfhSLTf44xTTD9wdxtlCkhng0jSipg=; b=P2OjvnJcEEfxMTaPlqWU+TNl5fbFgYL/6ZRVvHnmWG8bbhDTLJ1bZZT3TdtqhvF5RE uitwoxTIHxphOhzQmWM4hK0Qp9VYiP1Redw+03/MTi7MEWWccQ9g5IAzDBFypfWkCBPw l29xa8BKlCrEdfBf1DScAdQ2Q+DoyYo82hon6lWaadYLA1JhfpRfgiYzHI6uWxtl4e5U eCSENgqlatborM+S6ZfTpXRJGXD7V8kcNtLW1XETurWrS58bbT0vhAZeL5Yd3o1N1839 pnWjCqxLCNuQgY7bG3GZgx8MVHHHTX+JZyVpi+MqYtUaV4tyJOvTxXCsul5HBr9NL8hN KU1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kU4oxF7A; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t20si21400656plj.94.2018.12.05.00.58.09; Wed, 05 Dec 2018 00:58:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kU4oxF7A; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727349AbeLEI5Z (ORCPT + 99 others); Wed, 5 Dec 2018 03:57:25 -0500 Received: from mail-io1-f66.google.com ([209.85.166.66]:36057 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726102AbeLEI5Z (ORCPT ); Wed, 5 Dec 2018 03:57:25 -0500 Received: by mail-io1-f66.google.com with SMTP id m19so16053809ioh.3; Wed, 05 Dec 2018 00:57:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zERybKQJd2x47hfhSLTf44xTTD9wdxtlCkhng0jSipg=; b=kU4oxF7Au11Hb3CwmCYodQDJp54822xanGFsv3ZDtfifvmi9ZYr5KzJGJe1RMWAzGU I54ZBK7tEKkPbYbI5v471BxJwJN8WsmwB4iLN+hSrdZqb5xZ0l42o0WYgd4iWTNjwUK8 5nHXTiU0uVzmTWKiryfQO5No942WnSCM8TerHwOyg17JQo/82Bw7yPxy8+5JFpd1iZTM spVSZBPnsAKgfm1BY2u3fROL2Gw6EAeFOr7FObSo3/6JAZ0HYrlu2tfvaOmzNSzsvF6F fkm6sbjKnvgpheNI2s/R7PdqIwHqxzAXVe1pe+xXxhp3/y9QL5YddfaA6C8IBJk+fT9+ 200Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zERybKQJd2x47hfhSLTf44xTTD9wdxtlCkhng0jSipg=; b=t+Jrd/q/DpD7ivZzF21kz7l4JWixpP2g79/xT8zfkwB9DxNaQqwmEXimkGMp5czfpd hm8ukwMQJQzeDjjVNhZ/C9xu99i+vKl+kgx785KxPc+BPNZj3Jo5YbfEovx3T4tnIELV AFotIhmDDtQNVBUZX/nJ3SGb3aR93xZOKRIcAMWQO6Ulsv3RRjwUcpXMFgnNYKtwchL2 RZaiDLhOGpzfXeGemWmSKpRvexPPe9ZP92JeWsm4EgasUXPQtezcMYt+CHy//hUu3Hvp KrJkd+lAQbuBoYmE7hYN90MJMj4SqIFA0xIAnzL7OxnHDmquoks850qskFidNvV1fBJ6 khPQ== X-Gm-Message-State: AA+aEWZRPGb1LPq5gSNdZyjCDn+aaO2aOS8h9oKyKvJXgTuszgem63Wh cnJ8xetwadXbRwLqAodLdPHLfWWQMqVg9x9Wi/4= X-Received: by 2002:a6b:8b0a:: with SMTP id n10mr19425414iod.2.1544000243348; Wed, 05 Dec 2018 00:57:23 -0800 (PST) MIME-Version: 1.0 References: <1542535751-16079-1-git-send-email-pawell@cadence.com> <1542535751-16079-5-git-send-email-pawell@cadence.com> <5BF7E5E8.3090406@ti.com> <5C065AEE.4010205@ti.com> In-Reply-To: <5C065AEE.4010205@ti.com> From: Peter Chen Date: Wed, 5 Dec 2018 16:57:12 +0800 Message-ID: Subject: Re: [RFC PATCH v2 04/15] usb:cdns3: Driver initialization code. To: rogerq@ti.com Cc: pawell@cadence.com, devicetree@vger.kernel.org, Greg Kroah-Hartman , linux-usb@vger.kernel.org, lkml , adouglas@cadence.com, jbergsagel@ti.com, nsekhar@ti.com, nm@ti.com, sureshp@cadence.com, peter.chen@nxp.com, pjez@cadence.com, kurahul@cadence.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > > > > On 04/12/18 10:50, Peter Chen wrote: > >>> + * Cadence USBSS DRD Driver. > >>> + * > >>> + * Copyright (C) 2018 Cadence. > >>> + * > >>> + * Author: Peter Chen > >>> + * Pawel Laszczak > >>> + */ > >>> + > >>> +#include > >>> +#include > >>> +#include > >>> +#include > >>> +#include > >>> +#include > >>> + > >>> +#include "gadget.h" > >>> +#include "core.h" > >>> + > >>> +static inline struct cdns3_role_driver *cdns3_get_current_role_driver(struct cdns3 *cdns) > >>> +{ > >>> + WARN_ON(cdns->role >= CDNS3_ROLE_END || !cdns->roles[cdns->role]); > >>> + return cdns->roles[cdns->role]; > >>> +} > >>> + > >>> +static inline int cdns3_role_start(struct cdns3 *cdns, enum cdns3_roles role) > >>> +{ > >>> + int ret; > >>> + > >>> + if (role >= CDNS3_ROLE_END) > >> > >> WARN_ON()? > >> > >>> + return 0; > >>> + > >>> + if (!cdns->roles[role]) > >>> + return -ENXIO; > >>> + > >>> + mutex_lock(&cdns->mutex); > >>> + cdns->role = role; > >>> + ret = cdns->roles[role]->start(cdns); > >>> + mutex_unlock(&cdns->mutex); > >>> + return ret; > >>> +} > >>> + > >>> +static inline void cdns3_role_stop(struct cdns3 *cdns) > >>> +{ > >>> + enum cdns3_roles role = cdns->role; > >>> + > >>> + if (role == CDNS3_ROLE_END) > >> > >> WARN_ON(role >= CNDS3_ROLE_END) ? > >> > >>> + return; > >>> + > >>> + mutex_lock(&cdns->mutex); > >>> + cdns->roles[role]->stop(cdns); > >>> + cdns->role = CDNS3_ROLE_END; > >> > >> Why change the role here? You are just stopping the role not changing it. > >> I think cdns->role should remain unchanged, so we can call cdns3_role_start() > >> if required without error. > >> > > > > The current version of this IP has some issues to detect vbus status correctly, > > we have to force vbus status accordingly, so we need a status to indicate > > vbus disconnection, and add some code to let controller know vbus > > removal, in that case, the controller's state machine can be correct. > > So, we increase one role 'CDNS3_ROLE_END' to for this purpose. > > > > CDNS3_ROLE_GADGET: gadget mode and VBUS on > > CDNS3_ROLE_HOST: host mode and VBUS on > > CDNS3_ROLE_END: VBUS off, eg either host or device cable on the port. > > > > So, we may start role from CDNS3_ROLE_END at probe when nothing is connected, > > and need to set role as CDNS3_ROLE_END at ->stop for further handling at > > role switch routine. > > OK. but still this (changing to ROLE_END) must be moved to the role switch routine > and the explanation you just mentioned must be added there. > If we use host part as separate driver, something may need to change. The ROLE_END may need to add at role switch routine as your said. > > > >>> + mutex_unlock(&cdns->mutex); > >>> +} > >>> + > >>> +static enum cdns3_roles cdns3_get_role(struct cdns3 *cdns) > >>> +{ > >>> + if (cdns->roles[CDNS3_ROLE_HOST] && cdns->roles[CDNS3_ROLE_GADGET]) { > >>> + //TODO: implements selecting device/host mode > >>> + return CDNS3_ROLE_HOST; > >>> + } > >>> + return cdns->roles[CDNS3_ROLE_HOST] > >>> + ? CDNS3_ROLE_HOST > >>> + : CDNS3_ROLE_GADGET; > >> > >> Why not just > >> return cdns->role; > >> > >> I'm wondering if we really need this function. > > > > cdns->role gets from cdns3_get_role, and this API tells role at the runtime. > > If both roles are supported, the role is decided by external > > conditions, eg, vbus/id > > or external connector. If only single role is supported, only one role structure > > is allocated, cdns->roles[CDNS3_ROLE_HOST] or cdns->roles[CDNS3_ROLE_GADGET] > > > > How about adding this description in function documentation. > Sure, but may need to redesign it due to host part as a standalone driver. > >> > >> Then you can move cdns3_role_start() as well to core_init_role(). > >> > > > > Usually, we request irq after hardware initialization has finished, if not, > > there may unexpected interrupt. > > Doesn't kernel warn if interrupt happens and there is no handler? > To avoid that I was suggesting to request_irq first. > The interrupt will not happen (related bit at GIC is masked) until we call request_irq. And we don't want to handle interrupts until hardware initialization, don't we? Peter