Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers/sensor/ite/tach_ite_it8xxx2: don't clear both status at once #87326

Merged
merged 2 commits into from
Mar 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 38 additions & 35 deletions drivers/sensor/ite/ite_tach_it8xxx2/tach_ite_it8xxx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ LOG_MODULE_REGISTER(tach_ite_it8xxx2, CONFIG_SENSOR_LOG_LEVEL);
* NOTE: The PWM output maximum is 324Hz in EC LPM, so if we need fan to work
* then don't let EC enter LPM.
*/
#define TACH_FREQ EC_FREQ
#define TACH_FREQ EC_FREQ

struct tach_it8xxx2_config {
/* Fan x tachometer LSB reading register */
Expand Down Expand Up @@ -110,8 +110,7 @@ static bool tach_ch_is_valid(const struct device *dev, int tach_ch)
return valid;
}

static int tach_it8xxx2_sample_fetch(const struct device *dev,
enum sensor_channel chan)
static int tach_it8xxx2_sample_fetch(const struct device *dev, enum sensor_channel chan)
{
const struct tach_it8xxx2_config *const config = dev->config;
volatile uint8_t *reg_fxtlrr = (uint8_t *)config->reg_fxtlrr;
Expand All @@ -127,8 +126,14 @@ static int tach_it8xxx2_sample_fetch(const struct device *dev,
if (tach_ch_is_valid(dev, tach_ch)) {
/* If channel data of tachometer is valid, then save it */
data->capture = ((*reg_fxtmrr) << 8) | (*reg_fxtlrr);
/* Clear tachometer data valid status */
*reg_tswctlr |= config->dvs_bit;

if (config->dvs_bit == IT8XXX2_PWM_T0DVS) {
/* Only W/C tach 0 data valid status */
*reg_tswctlr = (*reg_tswctlr & ~IT8XXX2_PWM_T1DVS);
} else {
/* Only W/C tach 1 data valid status */
*reg_tswctlr = (*reg_tswctlr & ~IT8XXX2_PWM_T0DVS);
}
} else {
/* If channel data of tachometer isn't valid, then clear it */
data->capture = 0;
Expand All @@ -137,8 +142,7 @@ static int tach_it8xxx2_sample_fetch(const struct device *dev,
return 0;
}

static int tach_it8xxx2_channel_get(const struct device *dev,
enum sensor_channel chan,
static int tach_it8xxx2_channel_get(const struct device *dev, enum sensor_channel chan,
struct sensor_value *val)
{
const struct tach_it8xxx2_config *const config = dev->config;
Expand Down Expand Up @@ -200,13 +204,17 @@ static int tach_it8xxx2_init(const struct device *dev)
if (tach_ch == IT8XXX2_TACH_CHANNEL_A) {
/* Select IT8XXX2_TACH_CHANNEL_A output to tachometer */
*reg_tswctlr &= ~(config->chsel_bit);
/* Clear tachometer data valid status */
*reg_tswctlr |= config->dvs_bit;
} else {
/* Select IT8XXX2_TACH_CHANNEL_B output to tachometer */
*reg_tswctlr |= config->chsel_bit;
/* Clear tachometer data valid status */
*reg_tswctlr |= config->dvs_bit;
}

if (config->dvs_bit == IT8XXX2_PWM_T0DVS) {
/* Only W/C tach 0 data valid status */
*reg_tswctlr = (*reg_tswctlr & ~IT8XXX2_PWM_T1DVS);
} else {
/* Only W/C tach 1 data valid status */
*reg_tswctlr = (*reg_tswctlr & ~IT8XXX2_PWM_T0DVS);
}

/* Tachometer sensor already start */
Expand All @@ -218,29 +226,24 @@ static DEVICE_API(sensor, tach_it8xxx2_driver_api) = {
.channel_get = tach_it8xxx2_channel_get,
};

#define TACH_IT8XXX2_INIT(inst) \
PINCTRL_DT_INST_DEFINE(inst); \
\
static const struct tach_it8xxx2_config tach_it8xxx2_cfg_##inst = { \
.reg_fxtlrr = DT_INST_REG_ADDR_BY_IDX(inst, 0), \
.reg_fxtmrr = DT_INST_REG_ADDR_BY_IDX(inst, 1), \
.reg_tswctlr = DT_INST_REG_ADDR_BY_IDX(inst, 2), \
.dvs_bit = DT_INST_PROP(inst, dvs_bit), \
.chsel_bit = DT_INST_PROP(inst, chsel_bit), \
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \
.channel = DT_INST_PROP(inst, channel), \
.pulses_per_round = DT_INST_PROP(inst, pulses_per_round), \
}; \
\
static struct tach_it8xxx2_data tach_it8xxx2_data_##inst; \
\
SENSOR_DEVICE_DT_INST_DEFINE(inst, \
tach_it8xxx2_init, \
NULL, \
&tach_it8xxx2_data_##inst, \
&tach_it8xxx2_cfg_##inst, \
POST_KERNEL, \
CONFIG_SENSOR_INIT_PRIORITY, \
&tach_it8xxx2_driver_api);
#define TACH_IT8XXX2_INIT(inst) \
PINCTRL_DT_INST_DEFINE(inst); \
\
static const struct tach_it8xxx2_config tach_it8xxx2_cfg_##inst = { \
.reg_fxtlrr = DT_INST_REG_ADDR_BY_IDX(inst, 0), \
.reg_fxtmrr = DT_INST_REG_ADDR_BY_IDX(inst, 1), \
.reg_tswctlr = DT_INST_REG_ADDR_BY_IDX(inst, 2), \
.dvs_bit = DT_INST_PROP(inst, dvs_bit), \
.chsel_bit = DT_INST_PROP(inst, chsel_bit), \
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \
.channel = DT_INST_PROP(inst, channel), \
.pulses_per_round = DT_INST_PROP(inst, pulses_per_round), \
}; \
\
static struct tach_it8xxx2_data tach_it8xxx2_data_##inst; \
\
SENSOR_DEVICE_DT_INST_DEFINE(inst, tach_it8xxx2_init, NULL, &tach_it8xxx2_data_##inst, \
&tach_it8xxx2_cfg_##inst, POST_KERNEL, \
CONFIG_SENSOR_INIT_PRIORITY, &tach_it8xxx2_driver_api);

DT_INST_FOREACH_STATUS_OKAY(TACH_IT8XXX2_INIT)
Loading