Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3129953ybv; Mon, 24 Feb 2020 18:53:35 -0800 (PST) X-Google-Smtp-Source: APXvYqxdKsqB9uqsyxNyfTUXU42PsqkfxPr2TUg0ZXN2RLvkdzofQgzVr9AS0GcSagDW0crDJ+mP X-Received: by 2002:aca:3554:: with SMTP id c81mr132976oia.0.1582599215506; Mon, 24 Feb 2020 18:53:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582599215; cv=none; d=google.com; s=arc-20160816; b=qfhZgWIWqhjQ9WJUzXEkq3wb/q/4QNXbbZOmbtGzAjvrqgdMRqHJ0oyUCR7GFRQpd1 HEXIGkp4O6nP+AOU8ma1ILxm6lnUNYl6iGoJnSJ/PgfwjMaYBsKvxHPY2/rfACQX1OKn 1Jnt5gFTZeqlblZtAK7vzzE6qcbRXVj0/wQvUh6PhEiHGgo4RSGXsTPID9H1Y9tWf4nZ 83pV/AORILdgueBsuYs+inxFm41t1ZLW7BZ+NTmwcyZ/SjF6RhMIJ1UYa71mQAsA+CDV swDsIcB+OKMqNsuvqcDxBR1/AduwaZIPI1HlgfRZxmyg3XIRxj8mAXIeI+IHkiM3if23 6tVQ== 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=l/bd6Mw5UBXhKzo1wTzbT84L4xVj8bH26ZgdQxsHA0s=; b=meMEB3vf2IAI1H2vXdVSa5fDUSctRiLmOJ0ZAp90Vm8yojnWA2TFvJaTkh06NEdq4z JQzZe+abqf9EysgeNrpB7e+UAZ6j2+GtD3nhm5R1M4RwjgfK1U8aUSAg8z1c8N7x3oEu JwYlhMeltHxusvShvFab5pVTVAdIyToP3DiBIAbURqdHo8TBZadxPyatnhfY9NVfJyPS CB6bS0+lftqMaurtvByhh7ixsE6+uiRhcv2OwKV3oGRFSxmyVemqGQSGaddaBb+4b6PX ivtlSNpNFO+WUcMdNUYwBe2eglW6Vc+MtBlx+V4PYZSUiPpzOyIAr5PIlzyr/zwPv3rF tLQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nOghHRtC; 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 x10si5577196oic.136.2020.02.24.18.53.20; Mon, 24 Feb 2020 18:53:35 -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=nOghHRtC; 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 S1728857AbgBYCxG (ORCPT + 99 others); Mon, 24 Feb 2020 21:53:06 -0500 Received: from mail-qk1-f195.google.com ([209.85.222.195]:43573 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728725AbgBYCxF (ORCPT ); Mon, 24 Feb 2020 21:53:05 -0500 Received: by mail-qk1-f195.google.com with SMTP id p7so10667900qkh.10 for ; Mon, 24 Feb 2020 18:53:05 -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=l/bd6Mw5UBXhKzo1wTzbT84L4xVj8bH26ZgdQxsHA0s=; b=nOghHRtCf7Alr2k3I+9cnFeSzq6fln62uR/3O+T0Z4lJ8N0bAWFtm8gA7x6e3lA4vn GhUDueFRrxRSDBTo47Z4dCf3z8RHpfC6NFbe2rhp/WpxRSShbcZnugkVepqyqLFpDbth mx6eXP4dwAPhFAAvp4R9RnSWP+a+1y3GR9gptFExNct0llaxfiX3ol0b94MeNdnmb4Wr LXBJPKAbzU3IJUuUiD1RnARmBwr52XpVU8uLKZOL8FqmLAAmnjxaaPj1SQFBW6ePyQez 1ZgHKTIx4aVtYP3sWuHRooirMPOo24RE2eIdaaK4fsRfIihBPkI2FizDm+H+s+wvOixo lYFw== 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=l/bd6Mw5UBXhKzo1wTzbT84L4xVj8bH26ZgdQxsHA0s=; b=V0van1PD89UC4o9IcTxOXMJmVM+eDqGI+/cwLASIo2id8AdA7cFk2FobXhLx+UiNX/ T1VvNgHnsxKj00U4DAUiiFwXGCS4hv8l6ZuR8pEh5S/QvBB7ImHcCy5OfAUM4t67YfE7 2IEMDCBmm/EAclmujzyU/4ye8rlgZDBDojNbymNL4IjKUX0efKcTuUShongNDsjahy1R ru8zHLnYYr6AtOM27Vemj59DOMfitTQjHzwESNok90R9ddbxl6vKK+eIdAke8mY6wpuh Z72UBQHTw6C+Ise2BExkK9mL/BaVeReUP5J8PzyVHOjVNm8qtsNqH8+3avzIWs9YdV63 eSLg== X-Gm-Message-State: APjAAAU1JKGzr+QOM2xPCkWqYEHrwdUAsdTIu4qdpZlKEiMuNjMf5gA3 GGRwzkledFkgnlnE8UmZkWMY+f5JvRdleKo1ToE= X-Received: by 2002:a37:8e03:: with SMTP id q3mr52989468qkd.395.1582599184955; Mon, 24 Feb 2020 18:53:04 -0800 (PST) MIME-Version: 1.0 References: <049eb16cf995d3a2dd0de01f4c0ed09965e36f92.1581906151.git.baolin.wang7@gmail.com> <20200224113926.GU3494@dell> In-Reply-To: <20200224113926.GU3494@dell> From: Baolin Wang Date: Tue, 25 Feb 2020 10:52:53 +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 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.