Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

pwm: pca9685: Drop GPIO support

The functionality will be restored after the driver is converted to the
waveform API as the pwm core optionally provides a gpio chip for all
pwm chips that support the waveform API.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Link: https://lore.kernel.org/r/d975376fce9640c90ddc868e3722adeb83fff279.1753784092.git.u.kleine-koenig@baylibre.com
Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>

authored by

Uwe Kleine-König and committed by
Uwe Kleine-König
42f18ae3 3d4c4217

-156
-156
drivers/pwm/pwm-pca9685.c
··· 26 26 * that is enabled is allowed to change the prescale register. 27 27 * PWM channels requested afterwards must use a period that results in the same 28 28 * prescale setting as the one set by the first requested channel. 29 - * GPIOs do not count as enabled PWMs as they are not using the prescaler. 30 29 */ 31 30 32 31 #define PCA9685_MODE1 0x00 ··· 79 80 struct regmap *regmap; 80 81 struct mutex lock; 81 82 DECLARE_BITMAP(pwms_enabled, PCA9685_MAXCHAN + 1); 82 - #if IS_ENABLED(CONFIG_GPIOLIB) 83 - struct gpio_chip gpio; 84 - DECLARE_BITMAP(pwms_inuse, PCA9685_MAXCHAN + 1); 85 - #endif 86 83 }; 87 84 88 85 static inline struct pca9685 *to_pca(struct pwm_chip *chip) ··· 212 217 return (off - on) & (PCA9685_COUNTER_RANGE - 1); 213 218 } 214 219 215 - #if IS_ENABLED(CONFIG_GPIOLIB) 216 - static bool pca9685_pwm_test_and_set_inuse(struct pca9685 *pca, int pwm_idx) 217 - { 218 - bool is_inuse; 219 - 220 - mutex_lock(&pca->lock); 221 - if (pwm_idx >= PCA9685_MAXCHAN) { 222 - /* 223 - * "All LEDs" channel: 224 - * pretend already in use if any of the PWMs are requested 225 - */ 226 - if (!bitmap_empty(pca->pwms_inuse, PCA9685_MAXCHAN)) { 227 - is_inuse = true; 228 - goto out; 229 - } 230 - } else { 231 - /* 232 - * Regular channel: 233 - * pretend already in use if the "all LEDs" channel is requested 234 - */ 235 - if (test_bit(PCA9685_MAXCHAN, pca->pwms_inuse)) { 236 - is_inuse = true; 237 - goto out; 238 - } 239 - } 240 - is_inuse = test_and_set_bit(pwm_idx, pca->pwms_inuse); 241 - out: 242 - mutex_unlock(&pca->lock); 243 - return is_inuse; 244 - } 245 - 246 - static void pca9685_pwm_clear_inuse(struct pca9685 *pca, int pwm_idx) 247 - { 248 - mutex_lock(&pca->lock); 249 - clear_bit(pwm_idx, pca->pwms_inuse); 250 - mutex_unlock(&pca->lock); 251 - } 252 - 253 - static int pca9685_pwm_gpio_request(struct gpio_chip *gpio, unsigned int offset) 254 - { 255 - struct pwm_chip *chip = gpiochip_get_data(gpio); 256 - struct pca9685 *pca = to_pca(chip); 257 - 258 - if (pca9685_pwm_test_and_set_inuse(pca, offset)) 259 - return -EBUSY; 260 - pm_runtime_get_sync(pwmchip_parent(chip)); 261 - return 0; 262 - } 263 - 264 - static int pca9685_pwm_gpio_get(struct gpio_chip *gpio, unsigned int offset) 265 - { 266 - struct pwm_chip *chip = gpiochip_get_data(gpio); 267 - 268 - return pca9685_pwm_get_duty(chip, offset) != 0; 269 - } 270 - 271 - static int pca9685_pwm_gpio_set(struct gpio_chip *gpio, unsigned int offset, 272 - int value) 273 - { 274 - struct pwm_chip *chip = gpiochip_get_data(gpio); 275 - 276 - pca9685_pwm_set_duty(chip, offset, value ? PCA9685_COUNTER_RANGE : 0); 277 - 278 - return 0; 279 - } 280 - 281 - static void pca9685_pwm_gpio_free(struct gpio_chip *gpio, unsigned int offset) 282 - { 283 - struct pwm_chip *chip = gpiochip_get_data(gpio); 284 - struct pca9685 *pca = to_pca(chip); 285 - 286 - pca9685_pwm_set_duty(chip, offset, 0); 287 - pm_runtime_put(pwmchip_parent(chip)); 288 - pca9685_pwm_clear_inuse(pca, offset); 289 - } 290 - 291 - static int pca9685_pwm_gpio_get_direction(struct gpio_chip *chip, 292 - unsigned int offset) 293 - { 294 - /* Always out */ 295 - return GPIO_LINE_DIRECTION_OUT; 296 - } 297 - 298 - static int pca9685_pwm_gpio_direction_input(struct gpio_chip *gpio, 299 - unsigned int offset) 300 - { 301 - return -EINVAL; 302 - } 303 - 304 - static int pca9685_pwm_gpio_direction_output(struct gpio_chip *gpio, 305 - unsigned int offset, int value) 306 - { 307 - pca9685_pwm_gpio_set(gpio, offset, value); 308 - 309 - return 0; 310 - } 311 - 312 - /* 313 - * The PCA9685 has a bit for turning the PWM output full off or on. Some 314 - * boards like Intel Galileo actually uses these as normal GPIOs so we 315 - * expose a GPIO chip here which can exclusively take over the underlying 316 - * PWM channel. 317 - */ 318 - static int pca9685_pwm_gpio_probe(struct pwm_chip *chip) 319 - { 320 - struct pca9685 *pca = to_pca(chip); 321 - struct device *dev = pwmchip_parent(chip); 322 - 323 - pca->gpio.label = dev_name(dev); 324 - pca->gpio.parent = dev; 325 - pca->gpio.request = pca9685_pwm_gpio_request; 326 - pca->gpio.free = pca9685_pwm_gpio_free; 327 - pca->gpio.get_direction = pca9685_pwm_gpio_get_direction; 328 - pca->gpio.direction_input = pca9685_pwm_gpio_direction_input; 329 - pca->gpio.direction_output = pca9685_pwm_gpio_direction_output; 330 - pca->gpio.get = pca9685_pwm_gpio_get; 331 - pca->gpio.set = pca9685_pwm_gpio_set; 332 - pca->gpio.base = -1; 333 - pca->gpio.ngpio = PCA9685_MAXCHAN; 334 - pca->gpio.can_sleep = true; 335 - 336 - return devm_gpiochip_add_data(dev, &pca->gpio, chip); 337 - } 338 - #else 339 - static inline bool pca9685_pwm_test_and_set_inuse(struct pca9685 *pca, 340 - int pwm_idx) 341 - { 342 - return false; 343 - } 344 - 345 - static inline void 346 - pca9685_pwm_clear_inuse(struct pca9685 *pca, int pwm_idx) 347 - { 348 - } 349 - 350 - static inline int pca9685_pwm_gpio_probe(struct pwm_chip *chip) 351 - { 352 - return 0; 353 - } 354 - #endif 355 - 356 220 static void pca9685_set_sleep_mode(struct pwm_chip *chip, bool enable) 357 221 { 358 222 struct device *dev = pwmchip_parent(chip); ··· 341 487 { 342 488 struct pca9685 *pca = to_pca(chip); 343 489 344 - if (pca9685_pwm_test_and_set_inuse(pca, pwm->hwpwm)) 345 - return -EBUSY; 346 - 347 490 if (pwm->hwpwm < PCA9685_MAXCHAN) { 348 491 /* PWMs - except the "all LEDs" channel - default to enabled */ 349 492 mutex_lock(&pca->lock); ··· 362 511 mutex_unlock(&pca->lock); 363 512 364 513 pm_runtime_put(pwmchip_parent(chip)); 365 - pca9685_pwm_clear_inuse(pca, pwm->hwpwm); 366 514 } 367 515 368 516 static const struct pwm_ops pca9685_pwm_ops = { ··· 464 614 ret = pwmchip_add(chip); 465 615 if (ret < 0) 466 616 return ret; 467 - 468 - ret = pca9685_pwm_gpio_probe(chip); 469 - if (ret < 0) { 470 - pwmchip_remove(chip); 471 - return ret; 472 - } 473 617 474 618 pm_runtime_enable(&client->dev); 475 619