Lines Matching refs:pca

94 static bool pca9685_prescaler_can_change(struct pca9685 *pca, int channel)  in pca9685_prescaler_can_change()  argument
97 if (bitmap_empty(pca->pwms_enabled, PCA9685_MAXCHAN + 1)) in pca9685_prescaler_can_change()
100 if (bitmap_weight(pca->pwms_enabled, PCA9685_MAXCHAN + 1) > 1) in pca9685_prescaler_can_change()
106 return test_bit(channel, pca->pwms_enabled); in pca9685_prescaler_can_change()
111 struct pca9685 *pca = to_pca(chip); in pca9685_read_reg() local
115 err = regmap_read(pca->regmap, reg, val); in pca9685_read_reg()
124 struct pca9685 *pca = to_pca(chip); in pca9685_write_reg() local
128 err = regmap_write(pca->regmap, reg, val); in pca9685_write_reg()
212 static bool pca9685_pwm_test_and_set_inuse(struct pca9685 *pca, int pwm_idx) in pca9685_pwm_test_and_set_inuse() argument
216 mutex_lock(&pca->lock); in pca9685_pwm_test_and_set_inuse()
222 if (!bitmap_empty(pca->pwms_inuse, PCA9685_MAXCHAN)) { in pca9685_pwm_test_and_set_inuse()
231 if (test_bit(PCA9685_MAXCHAN, pca->pwms_inuse)) { in pca9685_pwm_test_and_set_inuse()
236 is_inuse = test_and_set_bit(pwm_idx, pca->pwms_inuse); in pca9685_pwm_test_and_set_inuse()
238 mutex_unlock(&pca->lock); in pca9685_pwm_test_and_set_inuse()
242 static void pca9685_pwm_clear_inuse(struct pca9685 *pca, int pwm_idx) in pca9685_pwm_clear_inuse() argument
244 mutex_lock(&pca->lock); in pca9685_pwm_clear_inuse()
245 clear_bit(pwm_idx, pca->pwms_inuse); in pca9685_pwm_clear_inuse()
246 mutex_unlock(&pca->lock); in pca9685_pwm_clear_inuse()
252 struct pca9685 *pca = to_pca(chip); in pca9685_pwm_gpio_request() local
254 if (pca9685_pwm_test_and_set_inuse(pca, offset)) in pca9685_pwm_gpio_request()
278 struct pca9685 *pca = to_pca(chip); in pca9685_pwm_gpio_free() local
282 pca9685_pwm_clear_inuse(pca, offset); in pca9685_pwm_gpio_free()
314 struct pca9685 *pca = to_pca(chip); in pca9685_pwm_gpio_probe() local
317 pca->gpio.label = dev_name(dev); in pca9685_pwm_gpio_probe()
318 pca->gpio.parent = dev; in pca9685_pwm_gpio_probe()
319 pca->gpio.request = pca9685_pwm_gpio_request; in pca9685_pwm_gpio_probe()
320 pca->gpio.free = pca9685_pwm_gpio_free; in pca9685_pwm_gpio_probe()
321 pca->gpio.get_direction = pca9685_pwm_gpio_get_direction; in pca9685_pwm_gpio_probe()
322 pca->gpio.direction_input = pca9685_pwm_gpio_direction_input; in pca9685_pwm_gpio_probe()
323 pca->gpio.direction_output = pca9685_pwm_gpio_direction_output; in pca9685_pwm_gpio_probe()
324 pca->gpio.get = pca9685_pwm_gpio_get; in pca9685_pwm_gpio_probe()
325 pca->gpio.set = pca9685_pwm_gpio_set; in pca9685_pwm_gpio_probe()
326 pca->gpio.base = -1; in pca9685_pwm_gpio_probe()
327 pca->gpio.ngpio = PCA9685_MAXCHAN; in pca9685_pwm_gpio_probe()
328 pca->gpio.can_sleep = true; in pca9685_pwm_gpio_probe()
330 return devm_gpiochip_add_data(dev, &pca->gpio, chip); in pca9685_pwm_gpio_probe()
333 static inline bool pca9685_pwm_test_and_set_inuse(struct pca9685 *pca, in pca9685_pwm_test_and_set_inuse() argument
340 pca9685_pwm_clear_inuse(struct pca9685 *pca, int pwm_idx) in pca9685_pwm_clear_inuse() argument
353 struct pca9685 *pca = to_pca(chip); in pca9685_set_sleep_mode() local
354 int err = regmap_update_bits(pca->regmap, PCA9685_MODE1, in pca9685_set_sleep_mode()
371 struct pca9685 *pca = to_pca(chip); in __pca9685_pwm_apply() local
392 if (!pca9685_prescaler_can_change(pca, pwm->hwpwm)) { in __pca9685_pwm_apply()
423 struct pca9685 *pca = to_pca(chip); in pca9685_pwm_apply() local
426 mutex_lock(&pca->lock); in pca9685_pwm_apply()
430 set_bit(pwm->hwpwm, pca->pwms_enabled); in pca9685_pwm_apply()
432 clear_bit(pwm->hwpwm, pca->pwms_enabled); in pca9685_pwm_apply()
434 mutex_unlock(&pca->lock); in pca9685_pwm_apply()
477 struct pca9685 *pca = to_pca(chip); in pca9685_pwm_request() local
479 if (pca9685_pwm_test_and_set_inuse(pca, pwm->hwpwm)) in pca9685_pwm_request()
484 mutex_lock(&pca->lock); in pca9685_pwm_request()
485 set_bit(pwm->hwpwm, pca->pwms_enabled); in pca9685_pwm_request()
486 mutex_unlock(&pca->lock); in pca9685_pwm_request()
496 struct pca9685 *pca = to_pca(chip); in pca9685_pwm_free() local
498 mutex_lock(&pca->lock); in pca9685_pwm_free()
500 clear_bit(pwm->hwpwm, pca->pwms_enabled); in pca9685_pwm_free()
501 mutex_unlock(&pca->lock); in pca9685_pwm_free()
504 pca9685_pwm_clear_inuse(pca, pwm->hwpwm); in pca9685_pwm_free()
524 struct pca9685 *pca; in pca9685_pwm_probe() local
529 chip = devm_pwmchip_alloc(&client->dev, PCA9685_MAXCHAN + 1, sizeof(*pca)); in pca9685_pwm_probe()
532 pca = to_pca(chip); in pca9685_pwm_probe()
534 pca->regmap = devm_regmap_init_i2c(client, &pca9685_regmap_i2c_config); in pca9685_pwm_probe()
535 if (IS_ERR(pca->regmap)) { in pca9685_pwm_probe()
536 ret = PTR_ERR(pca->regmap); in pca9685_pwm_probe()
544 mutex_init(&pca->lock); in pca9685_pwm_probe()