提交 aa8ccef6 编写于 作者: W William Breathitt Gray 提交者: Lipeng Sang

counter: microchip-tcb-capture: Handle Signal1 read and Synapse

stable inclusion
from stable-v5.10.153
commit 0bcd1ab3e8b3e897141e6e757a3ca00040bd49b8
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I64YCA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=0bcd1ab3e8b3e897141e6e757a3ca00040bd49b8

--------------------------------

commit d917a62a upstream.

The signal_read(), action_read(), and action_write() callbacks have been
assuming Signal0 is requested without checking. This results in requests
for Signal1 returning data for Signal0. This patch fixes these
oversights by properly checking for the Signal's id in the respective
callbacks and handling accordingly based on the particular Signal
requested. The trig_inverted member of the mchp_tc_data is removed as
superfluous.

Fixes: 106b1041 ("counter: Add microchip TCB capture counter")
Cc: stable@vger.kernel.org
Reviewed-by: NKamel Bouhara <kamel.bouhara@bootlin.com>
Link: https://lore.kernel.org/r/20221018121014.7368-1-william.gray@linaro.org/Signed-off-by: NWilliam Breathitt Gray <william.gray@linaro.org>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NLipeng Sang <sanglipeng1@jd.com>
上级 691034e6
...@@ -29,7 +29,6 @@ struct mchp_tc_data { ...@@ -29,7 +29,6 @@ struct mchp_tc_data {
int qdec_mode; int qdec_mode;
int num_channels; int num_channels;
int channel[2]; int channel[2];
bool trig_inverted;
}; };
enum mchp_tc_count_function { enum mchp_tc_count_function {
...@@ -163,7 +162,7 @@ static int mchp_tc_count_signal_read(struct counter_device *counter, ...@@ -163,7 +162,7 @@ static int mchp_tc_count_signal_read(struct counter_device *counter,
regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], SR), &sr); regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], SR), &sr);
if (priv->trig_inverted) if (signal->id == 1)
sigstatus = (sr & ATMEL_TC_MTIOB); sigstatus = (sr & ATMEL_TC_MTIOB);
else else
sigstatus = (sr & ATMEL_TC_MTIOA); sigstatus = (sr & ATMEL_TC_MTIOA);
...@@ -181,6 +180,17 @@ static int mchp_tc_count_action_get(struct counter_device *counter, ...@@ -181,6 +180,17 @@ static int mchp_tc_count_action_get(struct counter_device *counter,
struct mchp_tc_data *const priv = counter->priv; struct mchp_tc_data *const priv = counter->priv;
u32 cmr; u32 cmr;
if (priv->qdec_mode) {
*action = COUNTER_SYNAPSE_ACTION_BOTH_EDGES;
return 0;
}
/* Only TIOA signal is evaluated in non-QDEC mode */
if (synapse->signal->id != 0) {
*action = COUNTER_SYNAPSE_ACTION_NONE;
return 0;
}
regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CMR), &cmr); regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CMR), &cmr);
switch (cmr & ATMEL_TC_ETRGEDG) { switch (cmr & ATMEL_TC_ETRGEDG) {
...@@ -209,8 +219,8 @@ static int mchp_tc_count_action_set(struct counter_device *counter, ...@@ -209,8 +219,8 @@ static int mchp_tc_count_action_set(struct counter_device *counter,
struct mchp_tc_data *const priv = counter->priv; struct mchp_tc_data *const priv = counter->priv;
u32 edge = ATMEL_TC_ETRGEDG_NONE; u32 edge = ATMEL_TC_ETRGEDG_NONE;
/* QDEC mode is rising edge only */ /* QDEC mode is rising edge only; only TIOA handled in non-QDEC mode */
if (priv->qdec_mode) if (priv->qdec_mode || synapse->signal->id != 0)
return -EINVAL; return -EINVAL;
switch (action) { switch (action) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册