Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3050968imm; Tue, 4 Sep 2018 14:37:16 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZnBRSdsgDrl4Kp3Mtgx4L2grwA+uqqvrd7YO0cRm6iXiVVd+q949HmoHCHsPkeA5Xrcp4L X-Received: by 2002:a62:1219:: with SMTP id a25-v6mr36848555pfj.104.1536097036169; Tue, 04 Sep 2018 14:37:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536097036; cv=none; d=google.com; s=arc-20160816; b=hprVdNRyJgszMcURi3HXfKRGRmrsKJJFziIafTQB1EcmOhzEelcCdeMUG6gF6qjNPA WkJoGwtvDla21biby0zKaQdshXN9QFIjF+CnBJxUcST2NVMI6xOMsw72jzT+IVTa4ZTx mRFDSWGNC9ApLM1zw/nfw/3nebfY3ulk4pdVOc2CQW8TCKTNuWqYb8eehmkK0UpTqQs6 sQDa2RzJHaA1Ep6S8UQN+H6c3Nw1V4/E9uxOysMDVrhtppWIJI5rKo/eOtwBOUPcg7qK tcRozVSlaJBBr+JeUMdP7rn76qyc5zBue6XYXneUA8R8pomW/I87ACUCRT+0jNAwHq99 V0Tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=hjiM4T8yvpXzEl/iEWOCBClsAHGBb7m7psmJZ30l+/0=; b=ErXceC7cc9mp2bvQYU+f0Fg3xtY3JOb8N8/U+Jb4MMlI2oGhM3wSxMk9OeU9YqwcMp 0WXujP21pg4a5fWP7GB2arHy2skb0jrxJtpPV21Spo6gJQuarWIYhWA8Uk8TFuIjq7xM igj6w8OlfHLuKORyrfjU4+N3TmERxDJEBpOSslg6r9UvzIb0Ajk0OT5UajYgYbO5pU+P byI/caF/fVlB3qdBtv05Q7/mSpgzLiZgiH5/pLNOxsWzlND6F82wPOZ7TNca7XW0G1kM 2K40XV707D/JA4nv5wjZEuvQAeOLJA+jkpbj3qfHWbW1ubc1vidFUXFdSP5fgjTOb9Zf G6Nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=Q1qRsWLR; dkim=pass header.i=@codeaurora.org header.s=default header.b=IepCiIK0; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w17-v6si21835743plp.335.2018.09.04.14.37.01; Tue, 04 Sep 2018 14:37:16 -0700 (PDT) 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=@codeaurora.org header.s=default header.b=Q1qRsWLR; dkim=pass header.i=@codeaurora.org header.s=default header.b=IepCiIK0; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727454AbeIECCq (ORCPT + 99 others); Tue, 4 Sep 2018 22:02:46 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:35342 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725825AbeIECCo (ORCPT ); Tue, 4 Sep 2018 22:02:44 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 50AAF60807; Tue, 4 Sep 2018 21:35:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1536096945; bh=4dPCBcMXsbB3ajLGWI6jYg0Uexal99YXOxfb+rgVeeQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q1qRsWLReM1Iut37bLbUX4drNof4j8lnBBgcop5gQj2Jg4grLkPzSq+MKrLTK6CZc De+rP/Lgxr+rlpL//+JQDF0EiVBAZU3KBPY3rNaRKV8BGUgth4R/bPzlrL/GEwd88O 9UcXFDnieX8dc1Rg71IZrS3pyj5cXc/uqw5tNmdY= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from pheragu-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: pheragu@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id CD80660708; Tue, 4 Sep 2018 21:35:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1536096944; bh=4dPCBcMXsbB3ajLGWI6jYg0Uexal99YXOxfb+rgVeeQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IepCiIK0GFq5ZESYEqbe0Qva0kdXMG+0dKu4ONVCOYCdko3Ix57hzYZxBEqZH9jxP +fCGjTvZgVMXA+B1S/4jI081o4HwnV/a7m2CMxGLm24p5RwTsQqsGSbK/ZikTGU7A/ lFCeZiLCH0fYOPK6v3/6W9fLlvhjpZatpgy2S8Vk= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org CD80660708 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=pheragu@codeaurora.org From: Prakruthi Deepak Heragu To: linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org Cc: linux-kernel@vger.kernel.org, ckadabi@codeaurora.org, tsoni@codeaurora.org, rnayak@codeaurora.org, bryanh@codeaurora.org, psodagud@codeaurora.org, Prakruthi Deepak Heragu , Satya Durga Srinivasu Prabhala Subject: [PATCH v2 2/2] Embedded USB Debugger (EUD) driver Date: Tue, 4 Sep 2018 14:34:13 -0700 Message-Id: <1536096853-30473-3-git-send-email-pheragu@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1536096853-30473-1-git-send-email-pheragu@codeaurora.org> References: <1536096853-30473-1-git-send-email-pheragu@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for control peripheral of EUD (Embedded USB Debugger) to listen to events such as USB attach/detach, charger enable/disable, pet EUD to indicate software is functional. Signed-off-by: Satya Durga Srinivasu Prabhala Signed-off-by: Prakruthi Deepak Heragu --- drivers/soc/qcom/Kconfig | 12 ++ drivers/soc/qcom/Makefile | 1 + drivers/soc/qcom/eud.c | 338 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 351 insertions(+) create mode 100644 drivers/soc/qcom/eud.c diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig index 5856e79..12669ec 100644 --- a/drivers/soc/qcom/Kconfig +++ b/drivers/soc/qcom/Kconfig @@ -136,4 +136,16 @@ config QCOM_APR application processor and QDSP6. APR is used by audio driver to configure QDSP6 ASM, ADM and AFE modules. + +config QCOM_EUD + tristate "QTI Embedded USB Debugger (EUD)" + depends on ARCH_QCOM + help + The Embedded USB Debugger (EUD) driver is a driver for the + control peripheral which waits on events like USB attach/detach + and charger enable/disable. The control peripheral further helps + support the USB-based debug and trace capabilities. + This module enables support for Qualcomm Technologies, Inc. + Embedded USB Debugger (EUD). + If unsure, say N. endmenu diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile index 19dcf95..dd4701b 100644 --- a/drivers/soc/qcom/Makefile +++ b/drivers/soc/qcom/Makefile @@ -15,3 +15,4 @@ obj-$(CONFIG_QCOM_SMP2P) += smp2p.o obj-$(CONFIG_QCOM_SMSM) += smsm.o obj-$(CONFIG_QCOM_WCNSS_CTRL) += wcnss_ctrl.o obj-$(CONFIG_QCOM_APR) += apr.o +obj-$(CONFIG_QCOM_EUD) += eud.o diff --git a/drivers/soc/qcom/eud.c b/drivers/soc/qcom/eud.c new file mode 100644 index 0000000..16a0e7b --- /dev/null +++ b/drivers/soc/qcom/eud.c @@ -0,0 +1,338 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define EUD_ENABLE_CMD 1 +#define EUD_DISABLE_CMD 0 + +#define EUD_REG_INT1_EN_MASK 0x0024 +#define EUD_REG_INT_STATUS_1 0x0044 +#define EUD_REG_CTL_OUT_1 0x0074 +#define EUD_REG_VBUS_INT_CLR 0x0080 +#define EUD_REG_CHGR_INT_CLR 0x0084 +#define EUD_REG_CSR_EUD_EN 0x1014 +#define EUD_REG_SW_ATTACH_DET 0x1018 + +#define EUD_INT_VBUS BIT(2) +#define EUD_INT_CHGR BIT(3) +#define EUD_INT_SAFE_MODE BIT(4) + +struct eud_chip { + struct device *dev; + int eud_irq; + unsigned int extcon_id; + unsigned int int_status; + bool usb_attach; + bool chgr_enable; + void __iomem *eud_reg_base; + struct extcon_dev *extcon; + struct work_struct eud_work; +}; + +static const unsigned int eud_extcon_cable[] = { + EXTCON_USB, + EXTCON_CHG_USB_SDP, + EXTCON_NONE, +}; + +/* + * On the kernel command line specify eud.enable=1 to enable EUD. + * EUD is disabled by default. + */ +static int enable; +static bool eud_ready; +static struct eud_chip *eud_private; + +static void enable_eud(struct eud_chip *priv) +{ + struct power_supply *usb_psy = NULL; + union power_supply_propval pval = {0}; + union power_supply_propval tval = {0}; + int ret; + + usb_psy = power_supply_get_by_name("usb"); + if (!usb_psy) + return; + + ret = power_supply_get_property(usb_psy, + POWER_SUPPLY_PROP_PRESENT, &pval); + if (ret) + return; + + ret = power_supply_get_property(usb_psy, + POWER_SUPPLY_PROP_REAL_TYPE, &tval); + if (ret) + return; + + if (pval.intval && (tval.intval == POWER_SUPPLY_TYPE_USB || + tval.intval == POWER_SUPPLY_TYPE_USB_CDP)) { + /* write into CSR to enable EUD */ + writel_relaxed(BIT(0), priv->eud_reg_base + EUD_REG_CSR_EUD_EN); + /* Enable vbus, chgr & safe mode warning interrupts */ + writel_relaxed(EUD_INT_VBUS | EUD_INT_CHGR | EUD_INT_SAFE_MODE, + priv->eud_reg_base + EUD_REG_INT1_EN_MASK); + + /* Ensure Register Writes Complete */ + wmb(); + + /* + * Set the default cable state to usb connect and charger + * enable + */ + ret = extcon_set_state_sync(priv->extcon, EXTCON_USB, true); + if (ret) + return; + ret = extcon_set_state_sync(priv->extcon, + EXTCON_CHG_USB_SDP, true); + if (ret) + return; + } else { + return; + } + +} + +static void disable_eud(struct eud_chip *priv) +{ + /* write into CSR to disable EUD */ + writel_relaxed(0, priv->eud_reg_base + EUD_REG_CSR_EUD_EN); +} + +static int param_eud_set(const char *val, const struct kernel_param *kp) +{ + int enable = 0; + + if (sscanf(val, "%du", &enable) != 1) + return -EINVAL; + + if (enable != EUD_ENABLE_CMD && enable != EUD_DISABLE_CMD) + return -EINVAL; + + *((uint *)kp->arg) = enable; + if (!eud_ready) + return 0; + + if (enable == EUD_ENABLE_CMD) + enable_eud(eud_private); + else if (enable == EUD_DISABLE_CMD) + disable_eud(eud_private); + + return 0; +} + +static const struct kernel_param_ops eud_param_ops = { + .set = param_eud_set, + .get = param_get_int, +}; + +module_param_cb(enable, &eud_param_ops, &enable, 0644); + +static void eud_event_notifier(struct work_struct *eud_work) +{ + struct eud_chip *chip = container_of(eud_work, struct eud_chip, + eud_work); + int ret; + + if (chip->int_status == EUD_INT_VBUS) { + ret = extcon_set_state_sync(chip->extcon, chip->extcon_id, + chip->usb_attach); + if (ret) + return; + } else if (chip->int_status == EUD_INT_CHGR) { + ret = extcon_set_state_sync(chip->extcon, chip->extcon_id, + chip->chgr_enable); + if (ret) + return; + } +} + +static void usb_attach_detach(struct eud_chip *chip) +{ + u32 reg; + + chip->extcon_id = EXTCON_USB; + /* read ctl_out_1[4] to find USB attach or detach event */ + reg = readl_relaxed(chip->eud_reg_base + EUD_REG_CTL_OUT_1); + if (reg & BIT(4)) + chip->usb_attach = true; + else + chip->usb_attach = false; + + schedule_work(&chip->eud_work); + + /* set and clear vbus_int_clr[0] to clear interrupt */ + writel_relaxed(BIT(0), chip->eud_reg_base + EUD_REG_VBUS_INT_CLR); + /* Ensure Register Writes Complete */ + wmb(); + writel_relaxed(0, chip->eud_reg_base + EUD_REG_VBUS_INT_CLR); +} + +static void chgr_enable_disable(struct eud_chip *chip) +{ + u32 reg; + + chip->extcon_id = EXTCON_CHG_USB_SDP; + /* read ctl_out_1[6] to find charger enable or disable event */ + reg = readl_relaxed(chip->eud_reg_base + EUD_REG_CTL_OUT_1); + if (reg & BIT(6)) + chip->chgr_enable = true; + else + chip->chgr_enable = false; + + schedule_work(&chip->eud_work); + + /* set and clear chgr_int_clr[0] to clear interrupt */ + writel_relaxed(BIT(0), chip->eud_reg_base + EUD_REG_CHGR_INT_CLR); + /* Ensure Register Writes Complete */ + wmb(); + writel_relaxed(0, chip->eud_reg_base + EUD_REG_CHGR_INT_CLR); +} + +static void pet_eud(struct eud_chip *chip) +{ + u32 reg; + + /* read sw_attach_det[0] to find attach/detach event */ + reg = readl_relaxed(chip->eud_reg_base + EUD_REG_SW_ATTACH_DET); + if (reg & BIT(0)) { + /* Detach & Attach pet for EUD */ + writel_relaxed(0, chip->eud_reg_base + EUD_REG_SW_ATTACH_DET); + /* Ensure Register Writes Complete */ + wmb(); + /* Delay to make sure detach pet is done before attach pet */ + udelay(100); + writel_relaxed(BIT(0), chip->eud_reg_base + + EUD_REG_SW_ATTACH_DET); + /* Ensure Register Writes Complete */ + wmb(); + } else { + /* Attach pet for EUD */ + writel_relaxed(BIT(0), chip->eud_reg_base + + EUD_REG_SW_ATTACH_DET); + /* Ensure Register Writes Complete */ + wmb(); + } +} + +static irqreturn_t handle_eud_irq(int irq, void *data) +{ + struct eud_chip *chip = data; + u32 reg; + + /* read status register and find out which interrupt triggered */ + reg = readl_relaxed(chip->eud_reg_base + EUD_REG_INT_STATUS_1); + if (reg & EUD_INT_VBUS) { + chip->int_status = EUD_INT_VBUS; + usb_attach_detach(chip); + } else if (reg & EUD_INT_CHGR) { + chip->int_status = EUD_INT_CHGR; + chgr_enable_disable(chip); + } else if (reg & EUD_INT_SAFE_MODE) { + pet_eud(chip); + } else { + return IRQ_NONE; + } + + return IRQ_HANDLED; +} + +static int msm_eud_probe(struct platform_device *pdev) +{ + struct eud_chip *chip; + struct resource *res; + int ret; + + chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); + if (!chip) { + ret = -ENOMEM; + return ret; + } + + platform_set_drvdata(pdev, chip); + + chip->extcon = devm_extcon_dev_allocate(&pdev->dev, eud_extcon_cable); + if (IS_ERR(chip->extcon)) + return PTR_ERR(chip->extcon); + + ret = devm_extcon_dev_register(&pdev->dev, chip->extcon); + if (ret) + return ret; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) { + ret = -ENOMEM; + return ret; + } + + chip->eud_reg_base = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(chip->eud_reg_base)) + return PTR_ERR(chip->eud_reg_base); + + chip->eud_irq = platform_get_irq(pdev, 0); + + ret = devm_request_irq(&pdev->dev, chip->eud_irq, handle_eud_irq, + IRQF_TRIGGER_HIGH, NULL, chip); + if (ret) + return ret; + + device_init_wakeup(&pdev->dev, true); + enable_irq_wake(chip->eud_irq); + + INIT_WORK(&chip->eud_work, eud_event_notifier); + + eud_private = chip; + eud_ready = true; + + /* Enable EUD */ + if (enable) + enable_eud(eud_private); + + return 0; +} + +static int msm_eud_remove(struct platform_device *pdev) +{ + struct eud_chip *chip = platform_get_drvdata(pdev); + + if (enable) + disable_eud(eud_private); + device_init_wakeup(&pdev->dev, false); + disable_irq_wake(chip->eud_irq); + platform_set_drvdata(pdev, NULL); + + return 0; +} + +static const struct of_device_id msm_eud_dt_match[] = { + {.compatible = "qcom,msm-eud"}, + {}, +}; +MODULE_DEVICE_TABLE(of, msm_eud_dt_match); + +static struct platform_driver msm_eud_driver = { + .probe = msm_eud_probe, + .remove = msm_eud_remove, + .driver = { + .name = "msm-eud", + .of_match_table = msm_eud_dt_match, + }, +}; +module_platform_driver(msm_eud_driver); + +MODULE_DESCRIPTION("QTI EUD driver"); +MODULE_LICENSE("GPL v2"); -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project