Lines Matching refs:pca

88 	struct pca9685 *pca = gpiochip_get_data(gpio);  in pca9685_pwm_gpio_request()  local
91 mutex_lock(&pca->lock); in pca9685_pwm_gpio_request()
93 pwm = &pca->chip.pwms[offset]; in pca9685_pwm_gpio_request()
96 mutex_unlock(&pca->lock); in pca9685_pwm_gpio_request()
102 mutex_unlock(&pca->lock); in pca9685_pwm_gpio_request()
103 pm_runtime_get_sync(pca->chip.dev); in pca9685_pwm_gpio_request()
107 static bool pca9685_pwm_is_gpio(struct pca9685 *pca, struct pwm_device *pwm) in pca9685_pwm_is_gpio() argument
111 mutex_lock(&pca->lock); in pca9685_pwm_is_gpio()
120 for (i = 0; i < pca->gpio.ngpio; i++) in pca9685_pwm_is_gpio()
121 if (gpiochip_is_requested(&pca->gpio, i)) { in pca9685_pwm_is_gpio()
129 mutex_unlock(&pca->lock); in pca9685_pwm_is_gpio()
135 struct pca9685 *pca = gpiochip_get_data(gpio); in pca9685_pwm_gpio_get() local
136 struct pwm_device *pwm = &pca->chip.pwms[offset]; in pca9685_pwm_gpio_get()
139 regmap_read(pca->regmap, LED_N_ON_H(pwm->hwpwm), &value); in pca9685_pwm_gpio_get()
147 struct pca9685 *pca = gpiochip_get_data(gpio); in pca9685_pwm_gpio_set() local
148 struct pwm_device *pwm = &pca->chip.pwms[offset]; in pca9685_pwm_gpio_set()
152 regmap_write(pca->regmap, LED_N_OFF_L(pwm->hwpwm), 0); in pca9685_pwm_gpio_set()
153 regmap_write(pca->regmap, LED_N_OFF_H(pwm->hwpwm), 0); in pca9685_pwm_gpio_set()
156 regmap_write(pca->regmap, LED_N_ON_H(pwm->hwpwm), on); in pca9685_pwm_gpio_set()
161 struct pca9685 *pca = gpiochip_get_data(gpio); in pca9685_pwm_gpio_free() local
165 pm_runtime_put(pca->chip.dev); in pca9685_pwm_gpio_free()
166 mutex_lock(&pca->lock); in pca9685_pwm_gpio_free()
167 pwm = &pca->chip.pwms[offset]; in pca9685_pwm_gpio_free()
168 mutex_unlock(&pca->lock); in pca9685_pwm_gpio_free()
198 static int pca9685_pwm_gpio_probe(struct pca9685 *pca) in pca9685_pwm_gpio_probe() argument
200 struct device *dev = pca->chip.dev; in pca9685_pwm_gpio_probe()
202 mutex_init(&pca->lock); in pca9685_pwm_gpio_probe()
204 pca->gpio.label = dev_name(dev); in pca9685_pwm_gpio_probe()
205 pca->gpio.parent = dev; in pca9685_pwm_gpio_probe()
206 pca->gpio.request = pca9685_pwm_gpio_request; in pca9685_pwm_gpio_probe()
207 pca->gpio.free = pca9685_pwm_gpio_free; in pca9685_pwm_gpio_probe()
208 pca->gpio.get_direction = pca9685_pwm_gpio_get_direction; in pca9685_pwm_gpio_probe()
209 pca->gpio.direction_input = pca9685_pwm_gpio_direction_input; in pca9685_pwm_gpio_probe()
210 pca->gpio.direction_output = pca9685_pwm_gpio_direction_output; in pca9685_pwm_gpio_probe()
211 pca->gpio.get = pca9685_pwm_gpio_get; in pca9685_pwm_gpio_probe()
212 pca->gpio.set = pca9685_pwm_gpio_set; in pca9685_pwm_gpio_probe()
213 pca->gpio.base = -1; in pca9685_pwm_gpio_probe()
214 pca->gpio.ngpio = PCA9685_MAXCHAN; in pca9685_pwm_gpio_probe()
215 pca->gpio.can_sleep = true; in pca9685_pwm_gpio_probe()
217 return devm_gpiochip_add_data(dev, &pca->gpio, pca); in pca9685_pwm_gpio_probe()
220 static inline bool pca9685_pwm_is_gpio(struct pca9685 *pca, in pca9685_pwm_is_gpio() argument
226 static inline int pca9685_pwm_gpio_probe(struct pca9685 *pca) in pca9685_pwm_gpio_probe() argument
232 static void pca9685_set_sleep_mode(struct pca9685 *pca, bool enable) in pca9685_set_sleep_mode() argument
234 regmap_update_bits(pca->regmap, PCA9685_MODE1, in pca9685_set_sleep_mode()
245 struct pca9685 *pca = to_pca(chip); in pca9685_pwm_config() local
250 if (period_ns != pca->period_ns) { in pca9685_pwm_config()
263 pca9685_set_sleep_mode(pca, true); in pca9685_pwm_config()
266 regmap_write(pca->regmap, PCA9685_PRESCALE, prescale); in pca9685_pwm_config()
269 pca9685_set_sleep_mode(pca, false); in pca9685_pwm_config()
271 pca->period_ns = period_ns; in pca9685_pwm_config()
279 pca->duty_ns = duty_ns; in pca9685_pwm_config()
287 regmap_write(pca->regmap, reg, LED_FULL); in pca9685_pwm_config()
299 regmap_write(pca->regmap, reg, 0x0); in pca9685_pwm_config()
306 regmap_write(pca->regmap, reg, 0x0); in pca9685_pwm_config()
314 regmap_write(pca->regmap, reg, LED_FULL); in pca9685_pwm_config()
327 regmap_write(pca->regmap, reg, (int)duty & 0xff); in pca9685_pwm_config()
334 regmap_write(pca->regmap, reg, ((int)duty >> 8) & 0xf); in pca9685_pwm_config()
342 regmap_write(pca->regmap, reg, 0); in pca9685_pwm_config()
349 struct pca9685 *pca = to_pca(chip); in pca9685_pwm_enable() local
361 regmap_write(pca->regmap, reg, 0); in pca9685_pwm_enable()
368 regmap_write(pca->regmap, reg, 0); in pca9685_pwm_enable()
379 regmap_update_bits(pca->regmap, reg, LED_FULL, 0x0); in pca9685_pwm_enable()
386 struct pca9685 *pca = to_pca(chip); in pca9685_pwm_disable() local
394 regmap_write(pca->regmap, reg, LED_FULL); in pca9685_pwm_disable()
402 regmap_write(pca->regmap, reg, 0x0); in pca9685_pwm_disable()
407 struct pca9685 *pca = to_pca(chip); in pca9685_pwm_request() local
409 if (pca9685_pwm_is_gpio(pca, pwm)) in pca9685_pwm_request()
441 struct pca9685 *pca; in pca9685_pwm_probe() local
445 pca = devm_kzalloc(&client->dev, sizeof(*pca), GFP_KERNEL); in pca9685_pwm_probe()
446 if (!pca) in pca9685_pwm_probe()
449 pca->regmap = devm_regmap_init_i2c(client, &pca9685_regmap_i2c_config); in pca9685_pwm_probe()
450 if (IS_ERR(pca->regmap)) { in pca9685_pwm_probe()
451 ret = PTR_ERR(pca->regmap); in pca9685_pwm_probe()
456 pca->duty_ns = 0; in pca9685_pwm_probe()
457 pca->period_ns = PCA9685_DEFAULT_PERIOD; in pca9685_pwm_probe()
459 i2c_set_clientdata(client, pca); in pca9685_pwm_probe()
461 regmap_read(pca->regmap, PCA9685_MODE2, &mode2); in pca9685_pwm_probe()
473 regmap_write(pca->regmap, PCA9685_MODE2, mode2); in pca9685_pwm_probe()
476 regmap_write(pca->regmap, PCA9685_ALL_LED_OFF_L, 0); in pca9685_pwm_probe()
477 regmap_write(pca->regmap, PCA9685_ALL_LED_OFF_H, 0); in pca9685_pwm_probe()
479 pca->chip.ops = &pca9685_pwm_ops; in pca9685_pwm_probe()
481 pca->chip.npwm = PCA9685_MAXCHAN + 1; in pca9685_pwm_probe()
483 pca->chip.dev = &client->dev; in pca9685_pwm_probe()
484 pca->chip.base = -1; in pca9685_pwm_probe()
486 ret = pwmchip_add(&pca->chip); in pca9685_pwm_probe()
490 ret = pca9685_pwm_gpio_probe(pca); in pca9685_pwm_probe()
492 pwmchip_remove(&pca->chip); in pca9685_pwm_probe()
509 struct pca9685 *pca = i2c_get_clientdata(client); in pca9685_pwm_remove() local
512 ret = pwmchip_remove(&pca->chip); in pca9685_pwm_remove()
523 struct pca9685 *pca = i2c_get_clientdata(client); in pca9685_pwm_runtime_suspend() local
525 pca9685_set_sleep_mode(pca, true); in pca9685_pwm_runtime_suspend()
532 struct pca9685 *pca = i2c_get_clientdata(client); in pca9685_pwm_runtime_resume() local
534 pca9685_set_sleep_mode(pca, false); in pca9685_pwm_runtime_resume()