Lines Matching +full:pwm +full:- +full:period

1 // SPDX-License-Identifier: GPL-2.0
6 * - The hardware supports fixed period & configures only 2-wire mode.
7 * - Supports normal polarity. Does not support changing polarity.
8 * - When PWM is disabled, output of PWM will become 0(inactive). It doesn't
9 * keep track of running period.
10 * - When duty cycle is changed, PWM output may be a mix of previous setting
11 * and new setting for the first period. From second period, the output is
13 * - It is a dedicated PWM fan controller. There are no other consumers for
14 * this PWM controller.
21 #include <linux/pwm.h>
36 #define LGM_PWM_MAX_RPM (BIT(16) - 1)
38 #define LGM_PWM_MAX_DUTY_CYCLE (BIT(8) - 1)
47 u32 period; member
58 struct regmap *regmap = pc->regmap; in lgm_pwm_enable()
64 static int lgm_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, in lgm_pwm_apply() argument
71 /* The hardware only supports normal polarity and fixed period. */ in lgm_pwm_apply()
72 if (state->polarity != PWM_POLARITY_NORMAL || state->period < pc->period) in lgm_pwm_apply()
73 return -EINVAL; in lgm_pwm_apply()
75 if (!state->enabled) in lgm_pwm_apply()
78 duty_cycle = min_t(u64, state->duty_cycle, pc->period); in lgm_pwm_apply()
79 val = duty_cycle * LGM_PWM_MAX_DUTY_CYCLE / pc->period; in lgm_pwm_apply()
81 ret = regmap_update_bits(pc->regmap, LGM_PWM_FAN_CON0, LGM_PWM_FAN_DC_MSK, in lgm_pwm_apply()
89 static int lgm_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, in lgm_pwm_get_state() argument
95 state->enabled = regmap_test_bits(pc->regmap, LGM_PWM_FAN_CON0, in lgm_pwm_get_state()
97 state->polarity = PWM_POLARITY_NORMAL; in lgm_pwm_get_state()
98 state->period = pc->period; /* fixed period */ in lgm_pwm_get_state()
100 regmap_read(pc->regmap, LGM_PWM_FAN_CON0, &val); in lgm_pwm_get_state()
102 state->duty_cycle = DIV_ROUND_UP(duty * pc->period, LGM_PWM_MAX_DUTY_CYCLE); in lgm_pwm_get_state()
115 struct regmap *regmap = pc->regmap; in lgm_pwm_init()
119 pc->period = LGM_PWM_PERIOD_2WIRE_NS; in lgm_pwm_init()
170 struct device *dev = &pdev->dev; in lgm_pwm_probe()
179 return -ENOMEM; in lgm_pwm_probe()
185 pc->regmap = devm_regmap_init_mmio(dev, io_base, &lgm_pwm_regmap_config); in lgm_pwm_probe()
186 if (IS_ERR(pc->regmap)) in lgm_pwm_probe()
187 return dev_err_probe(dev, PTR_ERR(pc->regmap), in lgm_pwm_probe()
207 pc->chip.dev = dev; in lgm_pwm_probe()
208 pc->chip.ops = &lgm_pwm_ops; in lgm_pwm_probe()
209 pc->chip.npwm = 1; in lgm_pwm_probe()
213 ret = devm_pwmchip_add(dev, &pc->chip); in lgm_pwm_probe()
215 return dev_err_probe(dev, ret, "failed to add PWM chip\n"); in lgm_pwm_probe()
221 { .compatible = "intel,lgm-pwm" },
228 .name = "intel-pwm",