From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9068E380FCE for ; Thu, 30 Jul 2026 08:07:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785398872; cv=none; b=MFa4U7nc6W64CQvmAOYJvkzRZuVXWNgMmrJBGrfMoWllaE4yV2uuo5OVv3Z5zCWL7pmX/CKPG/sPKY0ixaiPWeuabSihOp5CSDBPWtv2YOh0QaCZNFHCwWThL2w1O3YkhItahgd6jJjRXfs2nKMzmO4/nJi2KToGe6U6iCp2L5o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785398872; c=relaxed/simple; bh=XkZC+VCD78aC1HgIFYNHSIbXV+TujpcNG0JPLu9ihkM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Lp6tDTmCN5iGD6EbKV4m9zQsF0+M+hASH773jtDxiIGe5ut+Fd2AdgfYgW2bGNiHzE202s9yItLNvxLZmYVIXe50wEtXP8nvKImF7XP3P/KWEYSW+4qQD66iYZNv539vwxsCclKr/2F5G44TID0oVzIviN0JAaIhRNRGluYmESw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=OtQ7ECk/; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=SfBzWyQO; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="OtQ7ECk/"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="SfBzWyQO" Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 66U82ijQ1385493 for ; Thu, 30 Jul 2026 08:07:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=z7mwDzt4pyi csJbF/PR33YEwBkAHXFs91MmvUgurCW4=; b=OtQ7ECk/SETUBacw0cGjUCSYA97 Kx40hAmwPyjXXUIxTEaU53QsKLUC3HzDGKAeefqWvLBhv5mLkS3GgE9nYELwOUSV CgzsDAN4qx/AhTgCo6vV5+j+5BMiDOhPIFpFJs+SXopQ5lEyr/2pyMJiEat2ZbYD lLSR1pilstZu6ZNWCWFTCmJ83J7fZOwiquagG2aNc2U+pij4Bg6729y1ch9lUs38 xTjir5P9X840EEDkQEwn2jaDIh++xJvkWVaWHHtNzKzI9ZcIkY/nwP65/JyEKSOr yFuQxBMaUJmIFDYV+Q19+0hZ3GdEFy6Vbg7g6fUpdtpdd8Sf1ltsvAxsugA== Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4fr2rp00tm-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 30 Jul 2026 08:07:44 +0000 (GMT) Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-2cfa4e4684bso48805445ad.2 for ; Thu, 30 Jul 2026 01:07:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1785398863; x=1786003663; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=z7mwDzt4pyicsJbF/PR33YEwBkAHXFs91MmvUgurCW4=; b=SfBzWyQORhTuKl3YHZMa8eMsI7yWg180zkSk8A77TjVGIeL5iQbiDKvlJy532ejHTP A/fDbZji+DSzXDEcfV7XelnKjTqYPwLNTWvFi1gtj3O6PT0zL3CSa4SZL9tukRvT2TfS l45rFK9tMEuFr82qfx2TZN20zj41eEntF+83BqckGilc7hCqL3TwEBP46T6gQFhbvM8W QIXrC0WdMp+AFgaYdMMaRQIpWNKg2gGPitRdYHECjr4CaA9UfTcWaX1WXWHvGxIJImrd pyh0da4Q08RZlvQ5H5n5VDm4V9Ap6V2C8/tclGAbfXUR22HuZOVfdoF+SBvVFzEO1c6J aZQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785398863; x=1786003663; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=z7mwDzt4pyicsJbF/PR33YEwBkAHXFs91MmvUgurCW4=; b=FjEKNZ00GPcyl/+Ag7Z5JpMGJeaGDP2NvLiWFuH/9JEQxcQw47VGyZhm7V4+Yb/JWK i598ZOgkuIe8WIc6URz8/sPL9pQ16rrMoxbEHWSRjjzRXUlTq+X72ujOZrZSRQAzLQx/ bxBYuQopay8nA53FUhKCtF3o9o0TVZJOgRK5Lcg9GHyPqCfPYR80UurLGcBDaDzrB1zT SjrLnFD4G5x9Xv83B88cYr99WwcUA2oiyIZAy7wERAs87M7eSyrpj8AdTP+47lDeD3rz b0LIIUlBPecWjz85FK3t8UdMXyEflHDUqRv7L1L0wcAMrD8yv4Pj+dnoJ62+6/OMuNrX Cnhg== X-Forwarded-Encrypted: i=1; AHgh+RrSpSql8XLby7VxyQbaJHRtekmEYC+BjK/90u4RBspALwgND6K4Sqb6sFRuNIqt54ZOsPFTXyyjb8nibkw=@vger.kernel.org X-Gm-Message-State: AOJu0Yx4j2UnrgsVeJdInKsGFZN+eCRYhr9r36IYrEHmt16SxQDEn/7Y jCNyh90MyvGDoXVHGoYOXpTdPcE08tzZSsJhcmj68gOAmhwy+VIhLeIm09Y3g1lP/w01oHWjfXJ vW5LbYLARSjDx+3TohdPMPgvRXZt5+CUkP1cOiaZ/iIrOy8HUI0OMIFEVmfSN7Adkz2o= X-Gm-Gg: AR+sD12m/N1N80w2l/VhL6CrfPcY9yUT+iPxW7YfzUE1z3JNHCbOa0kzBDt2Jk+YaRz WWRmtutD1jMq+eu3dOnfz1i0vVteMIYYBnwLTBTbq6IHzzitA4PTUhdUN6dexPXCbMHQ/bEc6KI t5ZCqTsYPXklJYq0VfEfl5LbyDyT3O2Uev6UoJwTRnWpZjAAVWsL6ofkcOLluvEZTIoh7KZcncQ 6gXUxFSmeF3Wm+TIOQ+mBJVMaibfZm2spzKanErrYpBDsri0OwHmMwJd4f4x93p3JgT1ADoxeKJ 0He8kDh+ejwJIR6Vw9hYfwpEJPCCm8D39sIYanI/dEaHX9NQPj7xg3sZvXACS4qLg2NF2VbRNDd 47TbA37Ihi+CLsC2YUddhnhyQOMtZs0wMuIqNO0hDE5NWanrYWVQVpoc= X-Received: by 2002:a17:90b:3c11:b0:38e:488f:7068 with SMTP id 98e67ed59e1d1-38f9bd74415mr1582721a91.2.1785398862831; Thu, 30 Jul 2026 01:07:42 -0700 (PDT) X-Received: by 2002:a17:90b:3c11:b0:38e:488f:7068 with SMTP id 98e67ed59e1d1-38f9bd74415mr1582687a91.2.1785398862390; Thu, 30 Jul 2026 01:07:42 -0700 (PDT) Received: from hu-songchai-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-38f9bab61desm619516a91.13.2026.07.30.01.07.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jul 2026 01:07:41 -0700 (PDT) From: Songwei Chai To: andersson@kernel.org, alexander.shishkin@linux.intel.com, mike.leach@linaro.org, konrad.dybcio@oss.qualcomm.com, suzuki.poulose@arm.com, james.clark@arm.com, krzk+dt@kernel.org, conor+dt@kernel.org Cc: Songwei Chai , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, coresight@lists.linaro.org, devicetree@vger.kernel.org, gregkh@linuxfoundation.org, Jie Gan Subject: [PATCH v16 2/7] qcom-tgu: Add TGU driver Date: Thu, 30 Jul 2026 01:06:59 -0700 Message-Id: <20260730080704.2903540-3-songwei.chai@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260730080704.2903540-1-songwei.chai@oss.qualcomm.com> References: <20260730080704.2903540-1-songwei.chai@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Spam-Info: AW1haW4tMjYwNzMwMDA1NyBTYWx0ZWRfXy6schm0WK/Ql NZ+coyGZ+1Ix/9Cce6DlpLLoBOzbsp4lJFCurW2VRTkzE+LuZwlodXHOzLvOg10SXr0UFTi14pW jfpvHFdWLGqMAMm5sz/gwhpAlyEWA9I= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzMwMDA1NyBTYWx0ZWRfX/+CCn6Lfv9XF 6C8ddwz2dm+irdfDG3RSNPOX87XYFcAEG8oVJGgtr1CLaqmtTmSx3zTn0UfoZDNzYKMCg6EN8gD nyDEmmkQbPo3BmZeG2h+SaVkoP/NnFS2PSAkbKQJExfts0CF2hNE280FP6iWhHj2hOthg/8bm3M SFAGTOFJCM3MBtQ1ep2iFw+HUoY/GYKfvZGoiXtNpupXyDlOYuYCT0Cj7J0qn278TCgqlCcR6CS DO3ZdeGVw4Fvw23hzOOEm5HqewOjnumRWCwxFKipy1uKmZvRxkPENJyEs8IM38AWyNBp7sSy6Bk lo4w1io5DoCI++cYUV0EX0IgnLofbKEg6bfE8C6T53cbGy75chOQaQi2MxBXAL/nnPp6BOPLI3H mskx0+XICaHwB9H2G2ZHPVeDGUiyFgkvyk2sFVhrU5WkxHlcsFsJ072/87WK6ohXOitrWV1lPS5 WXuV4rUw7Wf0JBgAyHQ== X-Proofpoint-GUID: jvAZeij8CUlxT9OAbSojp6dEBLvISXKL X-Proofpoint-ORIG-GUID: jvAZeij8CUlxT9OAbSojp6dEBLvISXKL X-Authority-Analysis: v=2.4 cv=OcOoyBTY c=1 sm=1 tr=0 ts=6a6b0650 cx=c_pps a=cmESyDAEBpBGqyK7t0alAg==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=RAioF0-LDSMA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=eoimf2acIAo5FJnRuUoq:22 a=EUspDBNiAAAA:8 a=7CQSdrXTAAAA:8 a=VwQbUJbxAAAA:8 a=ihhBPCL7kiVGXwQKODUA:9 a=1OuFwYUASf3TG4hYMiVC:22 a=a-qgeE7W1pNrGK8U0ZQC:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-07-30_02,2026-07-29_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 adultscore=0 phishscore=0 malwarescore=0 suspectscore=0 spamscore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607300057 Add driver to support device TGU (Trigger Generation Unit). TGU is a Data Engine which can be utilized to sense a plurality of signals and create a trigger into the CTI or generate interrupts to processors. Add probe/enable/disable functions for tgu. Signed-off-by: Songwei Chai Acked-by: Konrad Dybcio Reviewed-by: Jie Gan --- .../ABI/testing/sysfs-bus-amba-devices-tgu | 9 + MAINTAINERS | 11 + drivers/Makefile | 1 + drivers/hwtracing/Kconfig | 2 + drivers/hwtracing/qcom/Kconfig | 20 ++ drivers/hwtracing/qcom/Makefile | 3 + drivers/hwtracing/qcom/tgu.c | 192 ++++++++++++++++++ drivers/hwtracing/qcom/tgu.h | 51 +++++ 8 files changed, 289 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-amba-devices-tgu create mode 100644 drivers/hwtracing/qcom/Kconfig create mode 100644 drivers/hwtracing/qcom/Makefile create mode 100644 drivers/hwtracing/qcom/tgu.c create mode 100644 drivers/hwtracing/qcom/tgu.h diff --git a/Documentation/ABI/testing/sysfs-bus-amba-devices-tgu b/Documentation/ABI/testing/sysfs-bus-amba-devices-tgu new file mode 100644 index 000000000000..36ab64f1e301 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-bus-amba-devices-tgu @@ -0,0 +1,9 @@ +What: /sys/bus/amba/devices//enable_tgu +Date: August 2026 +KernelVersion: 7.2 +Contact: Jinlong Mao , Songwei Chai +Description: + (RW) Set/Get the enable/disable status of TGU + Accepts only one of the 2 values - 0 or 1. + 0 : disable TGU. + 1 : enable TGU. diff --git a/MAINTAINERS b/MAINTAINERS index ce5c5185c773..4789321cca6d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -22360,6 +22360,17 @@ S: Maintained F: Documentation/tee/qtee.rst F: drivers/tee/qcomtee/ +QUALCOMM HARDWARETRACING DRIVER +M: Songwei Chai +M: Jie Gan +M: Suzuki K Poulose +L: linux-arm-msm@vger.kernel.org +S: Maintained +T: git git://git.kernel.org/pub/scm/linux/kernel/git/coresight/linux.git +F: Documentation/ABI/testing/sysfs-bus-amba-devices-tgu +F: Documentation/devicetree/bindings/arm/qcom,tgu.yaml +F: drivers/hwtracing/qcom/ + QUALCOMM TRUST ZONE MEMORY ALLOCATOR M: Bartosz Golaszewski L: linux-arm-msm@vger.kernel.org diff --git a/drivers/Makefile b/drivers/Makefile index 0841ea851847..6a2cbe5b340f 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -176,6 +176,7 @@ obj-$(CONFIG_RAS) += ras/ obj-$(CONFIG_USB4) += thunderbolt/ obj-$(CONFIG_CORESIGHT) += hwtracing/coresight/ obj-y += hwtracing/intel_th/ +obj-y += hwtracing/qcom/ obj-$(CONFIG_STM) += hwtracing/stm/ obj-$(CONFIG_HISI_PTT) += hwtracing/ptt/ obj-y += android/ diff --git a/drivers/hwtracing/Kconfig b/drivers/hwtracing/Kconfig index 911ee977103c..8a640218eed8 100644 --- a/drivers/hwtracing/Kconfig +++ b/drivers/hwtracing/Kconfig @@ -7,4 +7,6 @@ source "drivers/hwtracing/intel_th/Kconfig" source "drivers/hwtracing/ptt/Kconfig" +source "drivers/hwtracing/qcom/Kconfig" + endmenu diff --git a/drivers/hwtracing/qcom/Kconfig b/drivers/hwtracing/qcom/Kconfig new file mode 100644 index 000000000000..5c94c75ffa39 --- /dev/null +++ b/drivers/hwtracing/qcom/Kconfig @@ -0,0 +1,20 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# QCOM specific hwtracing drivers +# +menu "Qualcomm specific hwtracing drivers" + +config QCOM_TGU + tristate "QCOM Trigger Generation Unit driver" + depends on ARCH_QCOM || COMPILE_TEST + depends on ARM_AMBA + help + This driver provides support for Trigger Generation Unit that is + used to detect patterns or sequences on a given set of signals. + TGU is used to monitor a particular bus within a given region to + detect illegal transaction sequences or slave responses. It is also + used to monitor a data stream to detect protocol violations and to + provide a trigger point for centering data around a specific event + within the trace data buffer. + +endmenu diff --git a/drivers/hwtracing/qcom/Makefile b/drivers/hwtracing/qcom/Makefile new file mode 100644 index 000000000000..5a0a868c1ea0 --- /dev/null +++ b/drivers/hwtracing/qcom/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_QCOM_TGU) += tgu.o diff --git a/drivers/hwtracing/qcom/tgu.c b/drivers/hwtracing/qcom/tgu.c new file mode 100644 index 000000000000..9c7dd4a09f02 --- /dev/null +++ b/drivers/hwtracing/qcom/tgu.c @@ -0,0 +1,192 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "tgu.h" + +static void tgu_write_all_hw_regs(struct tgu_drvdata *drvdata) +{ + TGU_UNLOCK(drvdata->base); + /* Enable TGU to program the triggers */ + writel(1, drvdata->base + TGU_CONTROL); + TGU_LOCK(drvdata->base); +} + +static void tgu_enable(struct tgu_drvdata *drvdata) +{ + tgu_write_all_hw_regs(drvdata); + drvdata->enabled = true; +} + +static void tgu_disable(struct tgu_drvdata *drvdata) +{ + TGU_UNLOCK(drvdata->base); + writel(0, drvdata->base + TGU_CONTROL); + TGU_LOCK(drvdata->base); + + drvdata->enabled = false; +} + +static ssize_t enable_tgu_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct tgu_drvdata *drvdata = dev_get_drvdata(dev); + bool enabled; + + scoped_guard(mutex, &drvdata->lock) + enabled = drvdata->enabled; + + return sysfs_emit(buf, "%d\n", enabled); +} + +/* enable_tgu_store - Enable or disable the Trigger Generation Unit (TGU). */ +static ssize_t enable_tgu_store(struct device *dev, + struct device_attribute *attr, + const char *buf, + size_t size) +{ + struct tgu_drvdata *drvdata = dev_get_drvdata(dev); + unsigned long val; + int ret; + + ret = kstrtoul(buf, 0, &val); + if (ret || val > 1) + return -EINVAL; + + /* + * Hold the mutex across the whole check-and-act sequence: the check of + * drvdata->enabled, the PM runtime reference counting and the state + * update must be atomic, otherwise concurrent writers could each + * imbalance the PM runtime usage counter. + */ + guard(mutex)(&drvdata->lock); + + if (val) { + if (drvdata->enabled) + return -EBUSY; + + ret = pm_runtime_resume_and_get(dev); + if (ret) + return ret; + + tgu_enable(drvdata); + } else { + if (!drvdata->enabled) + return -EINVAL; + + tgu_disable(drvdata); + pm_runtime_put(dev); + } + + return size; +} +static DEVICE_ATTR_RW(enable_tgu); + +static struct attribute *tgu_common_attrs[] = { + &dev_attr_enable_tgu.attr, + NULL, +}; + +static const struct attribute_group tgu_common_grp = { + .attrs = tgu_common_attrs, +}; + +static const struct attribute_group *tgu_attr_groups[] = { + &tgu_common_grp, + NULL, +}; + +static int tgu_probe(struct amba_device *adev, const struct amba_id *id) +{ + struct device *dev = &adev->dev; + struct tgu_drvdata *drvdata; + int ret; + + drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + if (!drvdata) + return -ENOMEM; + + drvdata->dev = &adev->dev; + dev_set_drvdata(dev, drvdata); + + drvdata->base = devm_ioremap_resource(dev, &adev->res); + if (IS_ERR(drvdata->base)) + return PTR_ERR(drvdata->base); + + ret = devm_mutex_init(dev, &drvdata->lock); + if (ret) + return ret; + + drvdata->enabled = false; + + ret = sysfs_create_groups(&dev->kobj, tgu_attr_groups); + if (ret) { + dev_err(dev, "failed to create sysfs groups: %d\n", ret); + return ret; + } + + pm_runtime_put(&adev->dev); + + return 0; +} + +static void tgu_remove(struct amba_device *adev) +{ + struct device *dev = &adev->dev; + struct tgu_drvdata *drvdata = dev_get_drvdata(dev); + + sysfs_remove_groups(&dev->kobj, tgu_attr_groups); + + /* + * If the device is still enabled through sysfs, disable the hardware + * and drop the PM runtime reference taken in enable_tgu_store() so the + * usage counter stays balanced. Use the synchronous put: the driver core + * disables runtime PM right after ->remove() returns, and the barrier in + * pm_runtime_disable() would cancel a still-queued async idle/suspend, + * leaving the runtime-PM state inconsistent. + */ + scoped_guard(mutex, &drvdata->lock) { + if (drvdata->enabled) { + tgu_disable(drvdata); + pm_runtime_put_sync(dev); + } + } +} + +static const struct amba_id tgu_ids[] = { + { + .id = 0x000f0e00, + .mask = 0x000fffff, + }, + { 0, 0, NULL }, +}; + +MODULE_DEVICE_TABLE(amba, tgu_ids); + +static struct amba_driver tgu_driver = { + .drv = { + .name = "qcom-tgu", + .suppress_bind_attrs = true, + }, + .probe = tgu_probe, + .remove = tgu_remove, + .id_table = tgu_ids, +}; + +module_amba_driver(tgu_driver); + +MODULE_AUTHOR("Songwei Chai "); +MODULE_AUTHOR("Jinlong Mao "); +MODULE_DESCRIPTION("Qualcomm Trigger Generation Unit driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/hwtracing/qcom/tgu.h b/drivers/hwtracing/qcom/tgu.h new file mode 100644 index 000000000000..ebba49402a20 --- /dev/null +++ b/drivers/hwtracing/qcom/tgu.h @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + */ + +#ifndef _QCOM_TGU_H +#define _QCOM_TGU_H + +/* Register addresses */ +#define TGU_CONTROL 0x0000 +#define TGU_LAR 0xfb0 +#define TGU_UNLOCK_OFFSET 0xc5acce55 + +static inline void TGU_LOCK(void __iomem *addr) +{ + do { + /* Wait for things to settle */ + mb(); + writel_relaxed(0x0, addr + TGU_LAR); + } while (0); +} + +static inline void TGU_UNLOCK(void __iomem *addr) +{ + do { + writel_relaxed(TGU_UNLOCK_OFFSET, addr + TGU_LAR); + /* Make sure everyone has seen this */ + mb(); + } while (0); +} + +/** + * struct tgu_drvdata - Data structure for a TGU (Trigger Generation Unit) + * @base: Memory-mapped base address of the TGU device + * @dev: Pointer to the associated device structure + * @lock: Mutex serialising enable/disable and the associated PM runtime + * reference counting against concurrent sysfs access + * @enabled: Flag indicating whether the TGU device is enabled + * + * This structure defines the data associated with a TGU device, + * including its base address, device pointer, the lock serialising + * enable/disable, and the enable status. + */ +struct tgu_drvdata { + void __iomem *base; + struct device *dev; + struct mutex lock; + bool enabled; +}; + +#endif -- 2.34.1