Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2093906rbb; Tue, 27 Feb 2024 10:20:35 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWCkJAr51uqzO1h0SWg+y2cmCSbYyKJzAW0Al9vIQtmuyzXupw5vOlRAg8I0qq/4Zn18lOBnXxHJtmfQkC3TDQ8OubrJ7OTnLzyGuRsCg== X-Google-Smtp-Source: AGHT+IHqefFyBdlNsBrfL9egdXSHc1QWsfyGTcdKPJHKPa3YR4I6aFeSZ72sBLxTI2/Z5MrCs+hF X-Received: by 2002:a05:6a00:181d:b0:6e4:8c89:3bf9 with SMTP id y29-20020a056a00181d00b006e48c893bf9mr11589100pfa.3.1709058035167; Tue, 27 Feb 2024 10:20:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709058035; cv=pass; d=google.com; s=arc-20160816; b=oKO5Frr3fgOSFk6aQk8wdmWpn56opTsGEbGPHZs2FM2EwOCcjic+c9FLTBb2vcnQMd gaXQjXe65kGMmzlz4Yg1PXNQptQS5ipqWLT4nIje93p1351IVgiQT8HDTzbld/XYv8UQ ddP0Mb0Cjnk4Dz32ao7Iz6mujt0X8mNnN2iy6ohKpOlFtt/rL2MsUSsFuY6lbg/f2oo4 FabKZu0sUHDckeWzx14FERu5xsKzAeL9mZkNtNnlBtr6kiFEiV4JOMZfxxT6SCEwt9zT 5I/7q0qd9F1Acb5dw2BLjU8JnGqhUHLukpeewPc3dtxOut95XJXXTmuCrL+6XJKP1tk+ lhlA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=oK3u5VA04nVMBTkalarhGWM8df4YU9kjhwAaKc3RoBs=; fh=ozwKRq0p8tj2zy4oAJzh3eawPsCHg5fP2FoTNn7f1y4=; b=WeG7TsjBsg2oAsGEOy9DSWKriwOUERLI0OR8b/dv3aoncnMhgmwzq0PxAvU6LdBZOY RKfa+7woWzxK/ykFPRqnrEITmDp3DuHRaTIN7fnZVJACrFU/9pU8im69b6Hek59IpNq9 x1QOcc/rIY2gMSXE9/g1KeSye8i2Woxn0ZnRSKwoVqOtJ6T5sOGzczhABJVHfTxE5beH zmOoBupNqTHMObJ/VfQxa6qXfVOspNX6UCBUh2dg8CdT8isSbzXRK8NdzG4yUcwGiUOt 2Clu7RkjAx4QRVyWJ3CmbFh3eHaHlLXBl0IZLCnHfGlEYV+/RE7Gqi+bh+BZOYBWBQ0V CanQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=eD9ZphYg; arc=pass (i=1 spf=pass spfdomain=foss.st.com dkim=pass dkdomain=foss.st.com dmarc=pass fromdomain=foss.st.com); spf=pass (google.com: domain of linux-kernel+bounces-83755-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83755-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id u15-20020aa7848f000000b006e4ec0dfe3bsi5849218pfn.43.2024.02.27.10.20.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 10:20:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83755-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=eD9ZphYg; arc=pass (i=1 spf=pass spfdomain=foss.st.com dkim=pass dkdomain=foss.st.com dmarc=pass fromdomain=foss.st.com); spf=pass (google.com: domain of linux-kernel+bounces-83755-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83755-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id D2268B25EAB for ; Tue, 27 Feb 2024 17:42:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2892C14CAC4; Tue, 27 Feb 2024 17:40:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="eD9ZphYg" Received: from mx08-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) (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 97ACD14C582; Tue, 27 Feb 2024 17:40:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.207.212.93 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709055617; cv=none; b=GVAIcmJVmLgtRTPLGPn3LmhnMpw0aFUFcI0ptUgibRHQ58jcW8G5Fp1NjJJvC7O6dlZ/btS5XbqdfYfNxLqoQU6Lvn0hOonY1QxcQtDrrpklJ1vDMixI0wDgk8UbBZ7TexVpuZNUDQO2/CkDldjJI9z/PDIEVmPfFx3hQ+RkMns= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709055617; c=relaxed/simple; bh=+CcntBR+ctzeanI9LzOMfiPrNC9s3Xf4oSTtOMYaew0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TZWhiOxPcNxMtFdj6XfzD4xLO2b0h0yluh/EcITjpvrBKxtJEAhR1jp8qdip6h92iAWF/1jIvolj9DPHgp/4AVWhMphzrOAdp+r8jD9W7tPvS336AZsFi2qnpIjmldk3SFt7f0vFCheBE+TvmBnAkDFuB0yGwbpRBYjdBeZPCtU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b=eD9ZphYg; arc=none smtp.client-ip=91.207.212.93 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Received: from pps.filterd (m0369457.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41RBi70e025166; Tue, 27 Feb 2024 18:40:04 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= selector1; bh=oK3u5VA04nVMBTkalarhGWM8df4YU9kjhwAaKc3RoBs=; b=eD 9ZphYgfJ9gBTwl6j6MwI0mcx9Bwa8VTiBCbjxphWa9jJN3C7YTCKWYWJ0P8aChdP sXw3y8qS+0z8E8RemiFi/aBHQX2jbDRKAVsRGX11+7jsxco8I4lYultM/TK7HLjx 2rLP995uKHmxbFJZ2E3BDvHfFej5aysaHaQtQbcN4F96g3Zmsvbw0sSuk5jJnC/U in0/Ew0ZP8ZHo9BYlFDKJIkMlfgzzDJjwY3EzZeJ9ewYZso09iXysMkYi+P6Ykmb EKcXmiBqiLND0IYcvYNIKDtFn90wQ1DadTnI/JRW2fznZy3DayIgk9bnlYWLGFV8 QLyknZK5xwCDW8fTwCVA== Received: from beta.dmz-ap.st.com (beta.dmz-ap.st.com [138.198.100.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3whf4bscdb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Feb 2024 18:40:04 +0100 (CET) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id E35AB4002D; Tue, 27 Feb 2024 18:39:59 +0100 (CET) Received: from Webmail-eu.st.com (shfdag1node2.st.com [10.75.129.70]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 29A682AD133; Tue, 27 Feb 2024 18:39:33 +0100 (CET) Received: from localhost (10.252.26.109) by SHFDAG1NODE2.st.com (10.75.129.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 27 Feb 2024 18:39:30 +0100 From: Fabrice Gasnier To: CC: , , , , , , Subject: [PATCH v4 09/11] counter: stm32-timer-cnt: probe number of channels from registers Date: Tue, 27 Feb 2024 18:38:01 +0100 Message-ID: <20240227173803.53906-10-fabrice.gasnier@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240227173803.53906-1-fabrice.gasnier@foss.st.com> References: <20240227173803.53906-1-fabrice.gasnier@foss.st.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 Content-Type: text/plain X-ClientProxiedBy: SHFCAS1NODE2.st.com (10.75.129.73) To SHFDAG1NODE2.st.com (10.75.129.70) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-27_05,2024-02-27_01,2023-05-22_02 Probe the number of capture compare channels, by writing CCER register bits and read them back. Take care to restore the register original value. This is a precursor patch to support capture channels. Signed-off-by: Fabrice Gasnier --- Changes in v4: - directly use dev struct in stm32_timer_cnt_detect_channels routine. Changes in v3: - New patch split from: "counter: stm32-timer-cnt: populate capture channels and check encoder" --- drivers/counter/stm32-timer-cnt.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/counter/stm32-timer-cnt.c b/drivers/counter/stm32-timer-cnt.c index 66039d1b3642..710437d3b33f 100644 --- a/drivers/counter/stm32-timer-cnt.c +++ b/drivers/counter/stm32-timer-cnt.c @@ -42,6 +42,7 @@ struct stm32_timer_cnt { bool enabled; struct stm32_timer_regs bak; bool has_encoder; + unsigned int nchannels; }; static const enum counter_function stm32_count_functions[] = { @@ -416,6 +417,20 @@ static struct counter_count stm32_counts = { .num_ext = ARRAY_SIZE(stm32_count_ext) }; +static void stm32_timer_cnt_detect_channels(struct device *dev, + struct stm32_timer_cnt *priv) +{ + u32 ccer, ccer_backup; + + regmap_read(priv->regmap, TIM_CCER, &ccer_backup); + regmap_set_bits(priv->regmap, TIM_CCER, TIM_CCER_CCXE); + regmap_read(priv->regmap, TIM_CCER, &ccer); + regmap_write(priv->regmap, TIM_CCER, ccer_backup); + priv->nchannels = hweight32(ccer & TIM_CCER_CCXE); + + dev_dbg(dev, "has %d cc channels\n", priv->nchannels); +} + /* encoder supported on TIM1 TIM2 TIM3 TIM4 TIM5 TIM8 */ #define STM32_TIM_ENCODER_SUPPORTED (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(7)) @@ -484,6 +499,8 @@ static int stm32_timer_cnt_probe(struct platform_device *pdev) if (ret) return ret; + stm32_timer_cnt_detect_channels(dev, priv); + counter->name = dev_name(dev); counter->parent = dev; counter->ops = &stm32_timer_cnt_ops; -- 2.25.1