Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3417358ybv; Tue, 25 Feb 2020 00:55:27 -0800 (PST) X-Google-Smtp-Source: APXvYqw21hC5rRl38ICQLWQehXDVrzkXL13b4LGSYR6NsmNvwoISUzYdUfZdDspIJOIfX+QMXyvS X-Received: by 2002:a05:6808:8ee:: with SMTP id d14mr2485976oic.138.1582620927167; Tue, 25 Feb 2020 00:55:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582620927; cv=none; d=google.com; s=arc-20160816; b=SrcsuxyhBHbxw8FTAVLH8/y7YWdnhkcc0pHFUQUKXJ8s5uAXodaF3WZdDiI5Qfs0K1 0QKOwkpte0c37T9Jx7D4kc/ZFVd5Z4YyCB6Og0DDn4hemndi3w/LBVN1JTBqBkWLpVd6 u87g2880oWDl1CS8LiIFyHXInv7g5xUlP7UykkfA6tTmY9Qhq1qHTl8oGh8Q7I7/9HiJ 2Ob5A9SjPGq7eorO4rU1/eFtLfvMg/MbLmf9qQKW+X7NsVEER9m3sm9RTxMo0mCkWu8g 6ZZ/7etJJFRYulOBr63utCNfS2A16wBGWJCwXGlGscipdsOMyj08iE344xXKzP1Sqk1o 1Uzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=cnofqUXRGJIN4pxgWdVN1/yaAjfW7JomRgm1+ntQ8Xw=; b=N8bFvAGt03wt8DfVfNHaIdZhYpiNTFUdY4MxckTuyAISoQL1Hj1Y4DZlBlCJDB4sit L2ufimb633b7GIB2H7Kfw4t8wVYC3qx5QLQFJAsco0FZH3xXjdyiXZeVJHm2Naiqc3ha E+WQzlJN4Z5NEJRM5dZWsVh1tErdPqhBAL8ms+5clkg+1XC2JomQ2ty/Wuq/8AotemQg pVQ9oPlYqV1/8uj4pteDyGpQIqbjTLkpw6N7Lh7E3MJwPDzHzZcccDTsvabA8GIjLR8H uX0BHpsSXlOt+NNEmCM1fF5xcw0M/V0s/pSXFHcbrSHRxjnmh4q/zdbWCEE/yG0zmC8Q TnGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EPUIycS8; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l140si6656195oib.114.2020.02.25.00.55.15; Tue, 25 Feb 2020 00:55:27 -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=@linaro.org header.s=google header.b=EPUIycS8; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729703AbgBYItn (ORCPT + 99 others); Tue, 25 Feb 2020 03:49:43 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:38315 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729253AbgBYItn (ORCPT ); Tue, 25 Feb 2020 03:49:43 -0500 Received: by mail-wr1-f66.google.com with SMTP id e8so13671579wrm.5 for ; Tue, 25 Feb 2020 00:49:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=cnofqUXRGJIN4pxgWdVN1/yaAjfW7JomRgm1+ntQ8Xw=; b=EPUIycS8dIQcn0+d2qhh474RooYVtU6/d7a/56OKgbnyb/hTHvFZli8OgwvSJLKS23 Y57gA9Fe9lX4HdDk9iGNF8BBmrLiPQNOFG72YK48jSu3HjFkVqSwb1ndBgC/kEEqo6wT 3rue1Gj59uI15SbRc5/fmRBVTWBndrCkHcWG1mY29SpYTwOlXRQAw9DOV5jwBvy6btZC abygQyIWqD12WZbsr2Z/Mk6QuvGDl9T78PoNJEAd5i2s9334EI6R+P19Q/YlzczgxSC+ mYA9Q2E2l8Mk3zIt5DdYUf6CPEzqL83yM7wdWKlw2/NkIqyWE8vRSz5xfKexTUZ9sSSF tLIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=cnofqUXRGJIN4pxgWdVN1/yaAjfW7JomRgm1+ntQ8Xw=; b=RrO3TcoGpX5l5LJu1cweao2VQN1GsQAETLHvPUWk8t7PC59gPMDEfEN72Jjxi060KF zWA9LtRgey7Cvx1tlmfPArgDYg7yIkivRQxUUWpS51TT7U+s0FlUnv6EB3mdenU6gSqW AF0pxJzg3jXinuahsckjTo0ZN3m2w0ZO8rbERrNfzq61dBy6G7blQiJgUL5ki5VjtOSy hpIKI04FSibQMmA6nk0AE9PGt48OOhe5+C8ut/iBoUYnzzwchEWcp/bBgWFxQcJTq+da KyUfM51CyuibgCpMHCaEvhu0g42LdTT1u+gTFrg4nyrhpucBAu+2aD0P0FiBXY0VN5mY DYbA== X-Gm-Message-State: APjAAAUaeUIo7/GXcE5V+cQ254HnqAFItXO5Vt7W5u81WnnxMpcTw2A9 pIl5grX/X8P7hLtFCzgHXZT9XQ== X-Received: by 2002:a5d:4d4a:: with SMTP id a10mr75744408wru.220.1582620581241; Tue, 25 Feb 2020 00:49:41 -0800 (PST) Received: from dell ([2.31.163.122]) by smtp.gmail.com with ESMTPSA id i4sm3174232wmd.23.2020.02.25.00.49.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 00:49:40 -0800 (PST) Date: Tue, 25 Feb 2020 08:50:12 +0000 From: Lee Jones To: Baolin Wang Cc: Arnd Bergmann , Chunyan Zhang , Orson Zhai , LKML Subject: Re: [RESEND PATCH] mfd: sc27xx: Add USB charger type detection support Message-ID: <20200225085012.GW3494@dell> References: <049eb16cf995d3a2dd0de01f4c0ed09965e36f92.1581906151.git.baolin.wang7@gmail.com> <20200224113926.GU3494@dell> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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. -- Lee Jones [李琼斯] Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog