Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3461906ybv; Tue, 25 Feb 2020 01:45:05 -0800 (PST) X-Google-Smtp-Source: APXvYqy/XNv8tFnTrPTEE1UFyXLlH7MbaaBHZ1R57m5mRmqpewn8OWfZPFnz31A8licKQuJsqljy X-Received: by 2002:aca:1206:: with SMTP id 6mr2873430ois.176.1582623905292; Tue, 25 Feb 2020 01:45:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582623905; cv=none; d=google.com; s=arc-20160816; b=wL9RYs/dvOZcH7XCkxtlAEFYC5QDGHWC/m4uIUTIyTPpKPtYc++BSgrlvD3qa0N1BA 5yRNJQFmseh2hgnRVXwnsk7Y5H4mAfs0oO4/QOc/OLc0NGufSXDPJcn0d+K164/siHvv 7m6MfQkenNA/T8eobPBtb3H3vEzJF1r4kFV6O65eqIm4has0RMzjfIq5aheRcsRs2Avv amdkbF3iu1wqQfeXIVQJWT4YPLihiB4OqSG7/ljBmXBxVSeunnxmWk87PX5SiQt6Fk8a xmqF1aLr4KoIuz2ji4FmGH8ir1aKKX4zS2WMT15K0SLSzF3X7Hdl6NxX8SE2v75PASOQ xTbA== 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=QRG2PghZrwb3dGb8lOhFhJFv2KKsjZVPjqM/nt46UBo=; b=z9/Ey4ZyLF9KKizAAPbhCyrFGaPMIRU6kAyCE13xonRtbseqW2+jU/4V8wsCiNQjJa lOPRVLbebj1zJ4MrN3MsaAs2Zb6xN8DWlqditOzp/6iBmEiLQeEFccyNDzbjPgg2lxmy DXYfCPDU69O+hwK7ZcTDcP9DN3f9808MxPl77uy8IypJ1GDqwkp7bRE0DfrPPAxi2qW/ JffzKWVH37OTtLRy4Aeqshuitbkrt+LqAVL/0GRqSFGkiZ0U4it1Ih48qa73lM7/H1Pj s7n18Qtv3nzZvMm/IP/nK0jGzv/9hdZgh1B5/PT/L0X3LmRUhEj+0QJXLfD1RpC/Tn8x vLaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=eEiHhc8z; 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 u8si7982687otq.262.2020.02.25.01.44.53; Tue, 25 Feb 2020 01:45:05 -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=eEiHhc8z; 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 S1729048AbgBYJ17 (ORCPT + 99 others); Tue, 25 Feb 2020 04:27:59 -0500 Received: from mail-qk1-f194.google.com ([209.85.222.194]:36288 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727068AbgBYJ17 (ORCPT ); Tue, 25 Feb 2020 04:27:59 -0500 Received: by mail-qk1-f194.google.com with SMTP id f3so8406308qkh.3 for ; Tue, 25 Feb 2020 01:27:58 -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=QRG2PghZrwb3dGb8lOhFhJFv2KKsjZVPjqM/nt46UBo=; b=eEiHhc8zl+0ReOz3L4SnCrVCAPsNFhLZNgOYYCTUF3H7R2nOREFcrhlYgNK4hJ7tSi gbMRkfLUI124Jp8oQMe27+w40fGnhGRXhHNtfKU/a433Sn86jV9ALpncejsMDSBobdZA 4hqMEBQzIMpA8DWiyTWkgVAqnhQ8FqBig8SoIEjM/wBQLff70IhnvYh3zyOE/G2Zhapu hjyjkH7zuoTYYLFvcW2dpYp+Z3vT2QdbNVGbldwPQoaIKFaYqh/OqW+n3WKWTMf5Rtib O9ncXNkBZ461X68Y+VHRK+/Jz2auGi6c3coI83bOBpXOrUWopsyAdnS4shOIY1/JXQt8 Q11w== 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=QRG2PghZrwb3dGb8lOhFhJFv2KKsjZVPjqM/nt46UBo=; b=Fg6hDqdwSQvyF0Ee0FTBPoXD2NGBbtxCmVhTCw92o34Xp38BOpcrK6nSo2tx6Jdk5v bxZvlRscOC+wjIKu/boKFWUzuD9rOtx4uHZgLT50N0mSH1rP+RkhKeZXIAHMq0Nvv4Pm Fmx7g0yB91KAHkPthAjJFfeu46wFpB0FG5KD+Bhihpqq4ob8vdL09lTuA8sZzxh4dA6U kQi39Z+RNAv7dHdxFw8g39wqkqyGTn8PH3tuCroNf5M4T+CanPh+8IiJtYiC8A0CvX8x 2beRPI7roWW6W/SS/f3SOazHXWUIzHfI5sLQk5JXkh96XV5dHszAiTQxsqcXidA5F36Z wSoQ== X-Gm-Message-State: APjAAAVgqThKZsEV4CYvc57x7e4+zLZlpcyEUlUxHVQLKGfdcSBuTsD7 rGPYawDsVwpm6iaRfbIBvdwpjhgaeUSHbru1g0I= X-Received: by 2002:a05:620a:1353:: with SMTP id c19mr31005517qkl.114.1582622877710; Tue, 25 Feb 2020 01:27:57 -0800 (PST) MIME-Version: 1.0 References: <049eb16cf995d3a2dd0de01f4c0ed09965e36f92.1581906151.git.baolin.wang7@gmail.com> <20200224113926.GU3494@dell> <20200225085012.GW3494@dell> In-Reply-To: <20200225085012.GW3494@dell> From: Baolin Wang Date: Tue, 25 Feb 2020 17:27:45 +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 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?