Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp710329ybf; Wed, 26 Feb 2020 21:43:11 -0800 (PST) X-Google-Smtp-Source: APXvYqxZ00c4klQKbTrodYiyYkJOaiQMeE8GB7GV+1+WfKK5Diih+XgzgCilOKjs49Em6aTFdCtz X-Received: by 2002:aca:b284:: with SMTP id b126mr2049321oif.79.1582782191002; Wed, 26 Feb 2020 21:43:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582782190; cv=none; d=google.com; s=arc-20160816; b=fwjjBhszOAEiDQSmyBnLjYNdVIDkGqrEwKqdwFQAMjh+6cxIvCw8PvwVX1dpvK26BH KkTKvpr1d2htaSVMPIerzzmlVA7NSpRfI9ycktOmxt49Wwfqt3Ht7ctplpf11JmRvnji MV0NbxodrtXjS/6EJGrPhD/sS4jO+DH92dh9DFE98Lw9Oa8LRAEqnH8Fk4oULC6qLmAJ mMHdk30anN5WFjc34qIL/uB0aZBiQk5C2ZGwuj/KJxOXHHx3Vx11cDeC+uKRwGGBhH+L qeZrLqHXc3NzyAlOx52q3b/7QDEaUNdtP+wyMJfFf0ZrAkHFWGYNu+02bo7sC8WCxzTG 9QcA== 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=hw6QZPX2qEuN9qM/QrRO1SiFsJK0I5hW92E65JUrSnQ=; b=rHLvF6bdfqx2SlpxBBhQazv9WOr76AqT9suQUcuT1NzyraG+za7uXZ6q635mxEhHwT s0om+pDviVYkjnbRCdD6aKpYdGU/QGE9P9PWP5oAI5SWt+JokeIYUdESnIF+wElttxGl EqUvf06twk5eS4QyT/XNKaGZMzYg2idXFxerF1Eq7n+pLEAM1rKMBcT1sj+CZceOLolQ HUTLMYeVJ64GNpn04b2vO8wJUzfZItINtCDUafymkT4r773dnlB/mcBrvvxe0z8eQwCa tNQwr4Y7R8NPohlM3Z8BbUYMDDFz+jeLKNlKNEKwsk4nAffFmoUId6EpIW1QtXYJjWRB H9vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=H1XyANOT; 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 a13si921070otq.201.2020.02.26.21.42.57; Wed, 26 Feb 2020 21:43:10 -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=H1XyANOT; 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 S1725933AbgB0Flj (ORCPT + 99 others); Thu, 27 Feb 2020 00:41:39 -0500 Received: from mail-qk1-f193.google.com ([209.85.222.193]:33419 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725877AbgB0Fli (ORCPT ); Thu, 27 Feb 2020 00:41:38 -0500 Received: by mail-qk1-f193.google.com with SMTP id h4so2080502qkm.0 for ; Wed, 26 Feb 2020 21:41:38 -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=hw6QZPX2qEuN9qM/QrRO1SiFsJK0I5hW92E65JUrSnQ=; b=H1XyANOT4P+YdU62R2o0kOX5KGJssSg9lyyWUVxXWVeXXk2ltMFLHvp3BFtn0YFHdG IMq7rn+/Rex3r8CFCz8vyFIHc15sFy6r3Reb3f5ev05T5CD2XRE6FVDXPs3dylhBmaKp SHAKXEyrR4fiobTKs7vSCOMtzXxrrRfvzjgIOCYcju6V4HK51zjgp32W12aNb+Ywra2R 0sEuCjaM7LfdwQqWht+8RRSfZhmG5fa9ovKWKMLBFmHrLjCSmkZ4F/i4UOgxlxAtQH7z ArxRllUhP9QgfxgPbBBliisLaQ7bfwCIZ45k874t3DQfO4p5am0FvR67Bcu3JrmTpElK 3IyA== 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=hw6QZPX2qEuN9qM/QrRO1SiFsJK0I5hW92E65JUrSnQ=; b=ZlHidKn+dXv3c3o1ITcPEGmP89KPyCKfr3UXQEnis+Sx5EAaUhZIKyCRmBj+Re9p83 5gx6a3gQrw9jN7312yZ6Mj6WfvZEEQ7mZb5kFIm/46aEaOAAOIMaDWrK4M29ZjqfxvpH G2hpso3OKZEXmSx4LURmUs+IR8NQjAkVPuj77MvVO0yr9FjrNSC183Cq8hhljTUEXIH4 E/SqK38V42Wu4cLGt+AnzgA7RG+bNxQjWp8cS++LnnzuPsTSUJjimjk14pmhfJ6rUdx9 hWQqQ3Ci9eJc43IPbhrZNBA2J91TzZu0f/mWH1juaYOT1p5+l70jQPTpxnjuWOPJVLUd yAcQ== X-Gm-Message-State: APjAAAWleRq63NbZurKlHhSsZwRK4HVMlXpkL+yNo5FxJBHMbrjRZuTG /G+6iCHsz9GZBotsaPD9nRwMG08LMPywDREL4JXxD/ni X-Received: by 2002:a05:620a:7ee:: with SMTP id k14mr3379095qkk.170.1582782097545; Wed, 26 Feb 2020 21:41:37 -0800 (PST) MIME-Version: 1.0 References: <049eb16cf995d3a2dd0de01f4c0ed09965e36f92.1581906151.git.baolin.wang7@gmail.com> <20200224113926.GU3494@dell> <20200225085012.GW3494@dell> In-Reply-To: From: Baolin Wang Date: Thu, 27 Feb 2020 13:41:26 +0800 Message-ID: Subject: Re: [RESEND PATCH] mfd: sc27xx: Add USB charger type detection support To: Lee Jones Cc: Arnd Bergmann , Chunyan Zhang , Orson Zhai , LKML 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 Hi Lee, On Tue, Feb 25, 2020 at 5:27 PM Baolin Wang wrote: > > On Tue, Feb 25, 2020 at 4:49 PM Lee Jones wrote: > > > > On Tue, 25 Feb 2020, Baolin Wang wrote: > > > > > Hi Lee, > > > > > > On Mon, Feb 24, 2020 at 7:38 PM Lee Jones wrote: > > > > > > > > On Mon, 17 Feb 2020, Baolin Wang wrote: > > > > > > > > > The Spreadtrum SC27XX series PMICs supply the USB charger type detection > > > > > function, and related registers are located on the PMIC global registers > > > > > region, thus we implement and export this function in the MFD driver for > > > > > users to get the USB charger type. > > > > > > > > > > Signed-off-by: Baolin Wang > > > > > --- > > > > > drivers/mfd/sprd-sc27xx-spi.c | 52 +++++++++++++++++++++++++++++++++++++++ > > > > > include/linux/mfd/sc27xx-pmic.h | 7 ++++++ > > > > > 2 files changed, 59 insertions(+) > > > > > create mode 100644 include/linux/mfd/sc27xx-pmic.h > > > > > > > > [...] > > > > > > > > > +enum usb_charger_type sprd_pmic_detect_charger_type(struct device *dev) > > > > > +{ > > > > > + struct spi_device *spi = to_spi_device(dev); > > > > > + struct sprd_pmic *ddata = spi_get_drvdata(spi); > > > > > + const struct sprd_pmic_data *pdata = ddata->pdata; > > > > > + enum usb_charger_type type; > > > > > + u32 val; > > > > > + int ret; > > > > > + > > > > > + ret = regmap_read_poll_timeout(ddata->regmap, pdata->charger_det, val, > > > > > + (val & SPRD_PMIC_CHG_DET_DONE), > > > > > + SPRD_PMIC_CHG_DET_DELAY_US, > > > > > + SPRD_PMIC_CHG_DET_TIMEOUT); > > > > > + if (ret) { > > > > > + dev_err(&spi->dev, "failed to detect charger type\n"); > > > > > + return UNKNOWN_TYPE; > > > > > + } > > > > > + > > > > > + switch (val & SPRD_PMIC_CHG_TYPE_MASK) { > > > > > + case SPRD_PMIC_CDP_TYPE: > > > > > + type = CDP_TYPE; > > > > > + break; > > > > > + case SPRD_PMIC_DCP_TYPE: > > > > > + type = DCP_TYPE; > > > > > + break; > > > > > + case SPRD_PMIC_SDP_TYPE: > > > > > + type = SDP_TYPE; > > > > > + break; > > > > > + default: > > > > > + type = UNKNOWN_TYPE; > > > > > + break; > > > > > + } > > > > > + > > > > > + return type; > > > > > +} > > > > > +EXPORT_SYMBOL_GPL(sprd_pmic_detect_charger_type); > > > > > > > > Where is this called from? > > > > > > Our USB phy driver will call this API to get the charger type, which > > > is used to notify the corresponding current can be drawn to charger > > > drivers. And we will introduce users after this patch getting applied. > > > > > > > Why isn't the charger type detected in the charger driver? > > > > > > The charger type detection operation is not a part of charger, and its > > > related registers are located on the PMIC global registers area. So I > > > think the PMIC driver is the right place to implement. Moreover Arnd > > > also suggested us to implement these APIs in the PMIC driver if I > > > remember correctly. > > > > You shouldn't think of this as a PMIC driver. This is a device's > > parent were functional drivers are allocated and registered. Any > > Right. > > > useful functionality should be farmed out to the child devices which > > are to be appropriately dispersed and located into the subsystems. > > > > It looks like the charger has access to the same register map as this > > parent driver. I do not see any compelling reason to provide charger > > specific functionality in the parent driver at this point. > > Actually the charger detection is not belonging to the charger > subsystem, at least in the hardware design level. The charger > detection's theory is detetcing the USB phy D+/D- line to get the > charger type, then the hardware will save the charger type into the > PMIC global reigsters automatically for users to get. So this is not > related with the charger driver, which only supplies charging > services, and this is also not belonging to the USB phy, since the > related registers are located on the PMIC gloabl registers area. So > you still think we should not provide this funcion here? After more investigation, I found I can not move the charger detection into the charger driver. Cause the USB phy will implement the USB charger support by implementing phy->charger_detect() ops (which will call sprd_pmic_detect_charger_type() to get the charger type), which means the USB phy driver need to get a power supply object by a 'power-supply' phandle firstly, if we move the charger detection part into the charger driver. But our charger driver also need to register a USB phy notifier to be notified how much current can be drawn from the USB charger framework, which means the charger driver need to get a usb_phy object by a 'phys' phandle[1]. So this two drivers are interdependent and dead-lock. If we implement the charger type detection in the MFD, the USB phy driver can get the PMIC device by a phandle easily to get the charger type. Moreover from my previous description of the hardware design, I still think implementing the charger type detection in the MFD driver is a good way now. What do you think? Thanks. [1] https://elixir.bootlin.com/linux/v5.6-rc3/source/drivers/power/supply/sc2731_charger.c#L496