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

pwm: sun4i: Drop legacy callbacks

Remove the legacy callbacks .enable(), .disable(), .set_polarity() and
.config().

Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Acked-by: Chen-Yu Tsai <wens@csie.org>
Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>

authored by

Alexandre Belloni and committed by
Thierry Reding
a054c4d6 c32c5c50

-160
-160
drivers/pwm/pwm-sun4i.c
··· 305 305 return 0; 306 306 } 307 307 308 - static int sun4i_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, 309 - int duty_ns, int period_ns) 310 - { 311 - struct sun4i_pwm_chip *sun4i_pwm = to_sun4i_pwm_chip(chip); 312 - u32 prd, dty, val, clk_gate; 313 - u64 clk_rate, div = 0; 314 - unsigned int prescaler = 0; 315 - int err; 316 - 317 - clk_rate = clk_get_rate(sun4i_pwm->clk); 318 - 319 - if (sun4i_pwm->data->has_prescaler_bypass) { 320 - /* First, test without any prescaler when available */ 321 - prescaler = PWM_PRESCAL_MASK; 322 - /* 323 - * When not using any prescaler, the clock period in nanoseconds 324 - * is not an integer so round it half up instead of 325 - * truncating to get less surprising values. 326 - */ 327 - div = clk_rate * period_ns + NSEC_PER_SEC / 2; 328 - do_div(div, NSEC_PER_SEC); 329 - if (div - 1 > PWM_PRD_MASK) 330 - prescaler = 0; 331 - } 332 - 333 - if (prescaler == 0) { 334 - /* Go up from the first divider */ 335 - for (prescaler = 0; prescaler < PWM_PRESCAL_MASK; prescaler++) { 336 - if (!prescaler_table[prescaler]) 337 - continue; 338 - div = clk_rate; 339 - do_div(div, prescaler_table[prescaler]); 340 - div = div * period_ns; 341 - do_div(div, NSEC_PER_SEC); 342 - if (div - 1 <= PWM_PRD_MASK) 343 - break; 344 - } 345 - 346 - if (div - 1 > PWM_PRD_MASK) { 347 - dev_err(chip->dev, "period exceeds the maximum value\n"); 348 - return -EINVAL; 349 - } 350 - } 351 - 352 - prd = div; 353 - div *= duty_ns; 354 - do_div(div, period_ns); 355 - dty = div; 356 - 357 - err = clk_prepare_enable(sun4i_pwm->clk); 358 - if (err) { 359 - dev_err(chip->dev, "failed to enable PWM clock\n"); 360 - return err; 361 - } 362 - 363 - spin_lock(&sun4i_pwm->ctrl_lock); 364 - val = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG); 365 - 366 - if (sun4i_pwm->data->has_rdy && (val & PWM_RDY(pwm->hwpwm))) { 367 - spin_unlock(&sun4i_pwm->ctrl_lock); 368 - clk_disable_unprepare(sun4i_pwm->clk); 369 - return -EBUSY; 370 - } 371 - 372 - clk_gate = val & BIT_CH(PWM_CLK_GATING, pwm->hwpwm); 373 - if (clk_gate) { 374 - val &= ~BIT_CH(PWM_CLK_GATING, pwm->hwpwm); 375 - sun4i_pwm_writel(sun4i_pwm, val, PWM_CTRL_REG); 376 - } 377 - 378 - val = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG); 379 - val &= ~BIT_CH(PWM_PRESCAL_MASK, pwm->hwpwm); 380 - val |= BIT_CH(prescaler, pwm->hwpwm); 381 - sun4i_pwm_writel(sun4i_pwm, val, PWM_CTRL_REG); 382 - 383 - val = (dty & PWM_DTY_MASK) | PWM_PRD(prd); 384 - sun4i_pwm_writel(sun4i_pwm, val, PWM_CH_PRD(pwm->hwpwm)); 385 - 386 - if (clk_gate) { 387 - val = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG); 388 - val |= clk_gate; 389 - sun4i_pwm_writel(sun4i_pwm, val, PWM_CTRL_REG); 390 - } 391 - 392 - spin_unlock(&sun4i_pwm->ctrl_lock); 393 - clk_disable_unprepare(sun4i_pwm->clk); 394 - 395 - return 0; 396 - } 397 - 398 - static int sun4i_pwm_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm, 399 - enum pwm_polarity polarity) 400 - { 401 - struct sun4i_pwm_chip *sun4i_pwm = to_sun4i_pwm_chip(chip); 402 - u32 val; 403 - int ret; 404 - 405 - ret = clk_prepare_enable(sun4i_pwm->clk); 406 - if (ret) { 407 - dev_err(chip->dev, "failed to enable PWM clock\n"); 408 - return ret; 409 - } 410 - 411 - spin_lock(&sun4i_pwm->ctrl_lock); 412 - val = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG); 413 - 414 - if (polarity != PWM_POLARITY_NORMAL) 415 - val &= ~BIT_CH(PWM_ACT_STATE, pwm->hwpwm); 416 - else 417 - val |= BIT_CH(PWM_ACT_STATE, pwm->hwpwm); 418 - 419 - sun4i_pwm_writel(sun4i_pwm, val, PWM_CTRL_REG); 420 - 421 - spin_unlock(&sun4i_pwm->ctrl_lock); 422 - clk_disable_unprepare(sun4i_pwm->clk); 423 - 424 - return 0; 425 - } 426 - 427 - static int sun4i_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) 428 - { 429 - struct sun4i_pwm_chip *sun4i_pwm = to_sun4i_pwm_chip(chip); 430 - u32 val; 431 - int ret; 432 - 433 - ret = clk_prepare_enable(sun4i_pwm->clk); 434 - if (ret) { 435 - dev_err(chip->dev, "failed to enable PWM clock\n"); 436 - return ret; 437 - } 438 - 439 - spin_lock(&sun4i_pwm->ctrl_lock); 440 - val = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG); 441 - val |= BIT_CH(PWM_EN, pwm->hwpwm); 442 - val |= BIT_CH(PWM_CLK_GATING, pwm->hwpwm); 443 - sun4i_pwm_writel(sun4i_pwm, val, PWM_CTRL_REG); 444 - spin_unlock(&sun4i_pwm->ctrl_lock); 445 - 446 - return 0; 447 - } 448 - 449 - static void sun4i_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) 450 - { 451 - struct sun4i_pwm_chip *sun4i_pwm = to_sun4i_pwm_chip(chip); 452 - u32 val; 453 - 454 - spin_lock(&sun4i_pwm->ctrl_lock); 455 - val = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG); 456 - val &= ~BIT_CH(PWM_EN, pwm->hwpwm); 457 - val &= ~BIT_CH(PWM_CLK_GATING, pwm->hwpwm); 458 - sun4i_pwm_writel(sun4i_pwm, val, PWM_CTRL_REG); 459 - spin_unlock(&sun4i_pwm->ctrl_lock); 460 - 461 - clk_disable_unprepare(sun4i_pwm->clk); 462 - } 463 - 464 308 static const struct pwm_ops sun4i_pwm_ops = { 465 - .config = sun4i_pwm_config, 466 - .set_polarity = sun4i_pwm_set_polarity, 467 - .enable = sun4i_pwm_enable, 468 - .disable = sun4i_pwm_disable, 469 309 .apply = sun4i_pwm_apply, 470 310 .get_state = sun4i_pwm_get_state, 471 311 .owner = THIS_MODULE,