Lines Matching +full:on +full:- +full:chip

1 // SPDX-License-Identifier: GPL-2.0-only
6 * Copyright 2024 Ideas on Board Oy
9 * - The .apply() operation executes atomically, but may not wait for the
11 * - Disabling the PWM drives the output pin to a low level immediately.
12 * - The hardware can only generate normal polarity output.
35 static int pwm_adp5585_request(struct pwm_chip *chip, struct pwm_device *pwm) in pwm_adp5585_request() argument
37 struct regmap *regmap = pwmchip_get_drvdata(chip); in pwm_adp5585_request()
45 static void pwm_adp5585_free(struct pwm_chip *chip, struct pwm_device *pwm) in pwm_adp5585_free() argument
47 struct regmap *regmap = pwmchip_get_drvdata(chip); in pwm_adp5585_free()
54 static int pwm_adp5585_apply(struct pwm_chip *chip, in pwm_adp5585_apply() argument
58 struct regmap *regmap = pwmchip_get_drvdata(chip); in pwm_adp5585_apply()
60 u32 on, off; in pwm_adp5585_apply() local
64 if (!state->enabled) { in pwm_adp5585_apply()
70 if (state->polarity != PWM_POLARITY_NORMAL) in pwm_adp5585_apply()
71 return -EINVAL; in pwm_adp5585_apply()
73 if (state->period < ADP5585_PWM_MIN_PERIOD_NS) in pwm_adp5585_apply()
74 return -EINVAL; in pwm_adp5585_apply()
76 period = min(state->period, ADP5585_PWM_MAX_PERIOD_NS); in pwm_adp5585_apply()
77 duty_cycle = min(state->duty_cycle, period); in pwm_adp5585_apply()
80 * Compute the on and off time. As the internal oscillator frequency is in pwm_adp5585_apply()
83 on = div_u64(duty_cycle, NSEC_PER_SEC / ADP5585_PWM_OSC_FREQ_HZ); in pwm_adp5585_apply()
84 off = div_u64(period, NSEC_PER_SEC / ADP5585_PWM_OSC_FREQ_HZ) - on; in pwm_adp5585_apply()
91 val = cpu_to_le16(on); in pwm_adp5585_apply()
110 static int pwm_adp5585_get_state(struct pwm_chip *chip, in pwm_adp5585_get_state() argument
114 struct regmap *regmap = pwmchip_get_drvdata(chip); in pwm_adp5585_get_state()
115 unsigned int on, off; in pwm_adp5585_get_state() local
128 on = le16_to_cpu(on_off); in pwm_adp5585_get_state()
130 state->duty_cycle = on * (NSEC_PER_SEC / ADP5585_PWM_OSC_FREQ_HZ); in pwm_adp5585_get_state()
131 state->period = (on + off) * (NSEC_PER_SEC / ADP5585_PWM_OSC_FREQ_HZ); in pwm_adp5585_get_state()
133 state->polarity = PWM_POLARITY_NORMAL; in pwm_adp5585_get_state()
136 state->enabled = !!(val & ADP5585_PWM_EN); in pwm_adp5585_get_state()
150 struct device *dev = &pdev->dev; in adp5585_pwm_probe()
151 struct adp5585_dev *adp5585 = dev_get_drvdata(dev->parent); in adp5585_pwm_probe()
152 struct pwm_chip *chip; in adp5585_pwm_probe() local
155 chip = devm_pwmchip_alloc(dev, ADP5585_PWM_CHAN_NUM, 0); in adp5585_pwm_probe()
156 if (IS_ERR(chip)) in adp5585_pwm_probe()
157 return PTR_ERR(chip); in adp5585_pwm_probe()
159 device_set_of_node_from_dev(dev, dev->parent); in adp5585_pwm_probe()
161 pwmchip_set_drvdata(chip, adp5585->regmap); in adp5585_pwm_probe()
162 chip->ops = &adp5585_pwm_ops; in adp5585_pwm_probe()
164 ret = devm_pwmchip_add(dev, chip); in adp5585_pwm_probe()
166 return dev_err_probe(dev, ret, "failed to add PWM chip\n"); in adp5585_pwm_probe()
172 { "adp5585-pwm" },
179 .name = "adp5585-pwm",