Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2397897ybl; Mon, 20 Jan 2020 02:07:39 -0800 (PST) X-Google-Smtp-Source: APXvYqyqpD5bpvdTxjc+4yU9NdkO7s2cf1WhK2mn8w4uT4MA+cQjxE/FIOfD4DKoY522LojkzI/6 X-Received: by 2002:a9d:402:: with SMTP id 2mr14094298otc.357.1579514859350; Mon, 20 Jan 2020 02:07:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579514859; cv=none; d=google.com; s=arc-20160816; b=w7cSxxcU4vjQ0OHiVI5x0jqUrrkegoh4qaREdQ0NyYsGUVlbNh4W8csXIpwIiYWkRx fGDlQWzjemfACVHm0y4zXrr+AySy5rHLgUQw1QSR5vUR8yihVG35XTeOVWwzqpBUL8uO G/xn9Mvg5R60rbeHgRfal938Uv2JusXdD1zGibD/gUq7flCInn3Y5XBjD4VCqP5oUJ9M OMSwVB4KqEIkmIBDb8edPBZhYvxQ/4Fo4Wjsqg4KZKs5AraIbgp3ieKdN1tA7eSN2UZ/ Kc+ledZQgvxSlLNO4kewp9kpycEgkNLrMNuc7SS3adyxcjoO6TvThHJcLZm1UKLaBf7e FwEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=Hi+7gFsTmZyrz3ap1i/enKvUy7a27c6rw8lfHWInIaw=; b=LrxdWTfo/AGQRrTHir8srVgyTN3SIJx1w6C1O4PaDyEHB773HfoFzBETDjDlyBDYCS 9qUIX2w+PlPSw+tCJhPd2YeYOVyA9EFJ1GGnHqU6vS8kKcILP6k4tWgDb/rYjN2loequ d8I5o1wn9ls/IBKj585qCAsPl9hz7DkFA6LxsUWAfIdMiJN/maRNs/4Cp/qH0uBoh7gP vWp606Al4II6LSTB7wqPm4bqIOdZn4SC1nLNBhyoSVQwrLhLP3oLBA2R2wKFZGISDKVN kKHri3HuH4QDbZGiQ31d7fpbDbj+gYEa1ZR/C4VcSaVeH+uHrqEK9LIO91Nutmxp+I8c auuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CBxjDSVL; 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 h7si17970312otm.165.2020.01.20.02.07.26; Mon, 20 Jan 2020 02:07:39 -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=CBxjDSVL; 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 S1726626AbgATKGd (ORCPT + 99 others); Mon, 20 Jan 2020 05:06:33 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:33509 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726039AbgATKGc (ORCPT ); Mon, 20 Jan 2020 05:06:32 -0500 Received: by mail-pf1-f196.google.com with SMTP id z16so15623875pfk.0 for ; Mon, 20 Jan 2020 02:06:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Hi+7gFsTmZyrz3ap1i/enKvUy7a27c6rw8lfHWInIaw=; b=CBxjDSVLdXpaCInCNxpsY4coBMv8cUmgC3beuQz8Z6aXskVII7LKTYBMC6e/iCZ5ds nvgjO+skFYauWJ4o+NAOaNyxRsj1oiGv2fII8lD0N15EktuuGrOmKi9geTWHWx8Yh3LN GGFFKS38cPq/oc6hf1hC5mPwQngc+ou1rbL0Fjw4qRMyJBA9fyq8t2Sh8PwkdTLmw386 lkQ4oZyDGrmUknvDt9LD98DRqLiLEczbHkNSCGGqalVVZTZhK1Xj1coIVvMMneFrXV8b MPzRZg9wIEQehV6YobjNLoJZoKf0M8IX+Dz9BI6aJXD+V4QzytP1bREYwDplc2nwDXDn VKag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Hi+7gFsTmZyrz3ap1i/enKvUy7a27c6rw8lfHWInIaw=; b=RJ30acGBb182KJG6YYa6kMzXKeY+MTfG6qn6e7kld1bZQSxwitvInDXx9JxYdNE0ZF T+m2zs5HJLkW0RP2VjQ3+2fo3LDAvFx3e7UouIbdckPyTlEbYpqYYmLH7a2x3XznwnAj Xm3oSNDtqd9OL55bj9GUXgfKHALiKJXn0FTMnaAMruPAoriazN+HKD2t3wpwa8lYf/GM 69fbKDodwIWfdoyt0+XL8rdXy84DFiZQJBmBi4Zailzsio8b8P2qZ4fbCsY5+UUFmV2b qE/us3saqtRaA2D8DQxuiGi9wkYmECg2sQZ/ijE9TxgQbubyH2uWZ4f0EXTV++ToEUVd ymhA== X-Gm-Message-State: APjAAAUJWuHVp2pgLroMD4dj9zJx4KZpQzHO1mCIjjkrJq/eXMFfuXmz kA+4H+qGqv3GfYVtC8/lGKs= X-Received: by 2002:aa7:949a:: with SMTP id z26mr16152092pfk.98.1579514792120; Mon, 20 Jan 2020 02:06:32 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id v143sm39206358pfc.71.2020.01.20.02.06.29 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 20 Jan 2020 02:06:31 -0800 (PST) From: Baolin Wang To: lee.jones@linaro.org Cc: arnd@arndb.de, zhang.lyra@gmail.com, orsonzhai@gmail.com, baolin.wang7@gmail.com, linux-kernel@vger.kernel.org Subject: [PATCH] mfd: sc27xx: Add USB charger type detection support Date: Mon, 20 Jan 2020 18:05:55 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 diff --git a/drivers/mfd/sprd-sc27xx-spi.c b/drivers/mfd/sprd-sc27xx-spi.c index c0529a1..ebdf2f1 100644 --- a/drivers/mfd/sprd-sc27xx-spi.c +++ b/drivers/mfd/sprd-sc27xx-spi.c @@ -10,6 +10,7 @@ #include #include #include +#include #define SPRD_PMIC_INT_MASK_STATUS 0x0 #define SPRD_PMIC_INT_RAW_STATUS 0x4 @@ -17,6 +18,16 @@ #define SPRD_SC2731_IRQ_BASE 0x140 #define SPRD_SC2731_IRQ_NUMS 16 +#define SPRD_SC2731_CHG_DET 0xedc + +/* PMIC charger detection definition */ +#define SPRD_PMIC_CHG_DET_DELAY_US 200000 +#define SPRD_PMIC_CHG_DET_TIMEOUT 2000000 +#define SPRD_PMIC_CHG_DET_DONE BIT(11) +#define SPRD_PMIC_SDP_TYPE BIT(7) +#define SPRD_PMIC_DCP_TYPE BIT(6) +#define SPRD_PMIC_CDP_TYPE BIT(5) +#define SPRD_PMIC_CHG_TYPE_MASK GENMASK(7, 5) struct sprd_pmic { struct regmap *regmap; @@ -24,12 +35,14 @@ struct sprd_pmic { struct regmap_irq *irqs; struct regmap_irq_chip irq_chip; struct regmap_irq_chip_data *irq_data; + const struct sprd_pmic_data *pdata; int irq; }; struct sprd_pmic_data { u32 irq_base; u32 num_irqs; + u32 charger_det; }; /* @@ -40,8 +53,46 @@ struct sprd_pmic_data { static const struct sprd_pmic_data sc2731_data = { .irq_base = SPRD_SC2731_IRQ_BASE, .num_irqs = SPRD_SC2731_IRQ_NUMS, + .charger_det = SPRD_SC2731_CHG_DET, }; +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); + static const struct mfd_cell sprd_pmic_devs[] = { { .name = "sc27xx-wdt", @@ -181,6 +232,7 @@ static int sprd_pmic_probe(struct spi_device *spi) spi_set_drvdata(spi, ddata); ddata->dev = &spi->dev; ddata->irq = spi->irq; + ddata->pdata = pdata; ddata->irq_chip.name = dev_name(&spi->dev); ddata->irq_chip.status_base = diff --git a/include/linux/mfd/sc27xx-pmic.h b/include/linux/mfd/sc27xx-pmic.h new file mode 100644 index 0000000..57e45c0 --- /dev/null +++ b/include/linux/mfd/sc27xx-pmic.h @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LINUX_MFD_SC27XX_PMIC_H +#define __LINUX_MFD_SC27XX_PMIC_H + +extern enum usb_charger_type sprd_pmic_detect_charger_type(struct device *dev); + +#endif /* __LINUX_MFD_SC27XX_PMIC_H */ -- 1.7.9.5