Lines Matching refs:pb
43 static void pwm_backlight_power_on(struct pwm_bl_data *pb) in pwm_backlight_power_on() argument
48 pwm_get_state(pb->pwm, &state); in pwm_backlight_power_on()
49 if (pb->enabled) in pwm_backlight_power_on()
52 err = regulator_enable(pb->power_supply); in pwm_backlight_power_on()
54 dev_err(pb->dev, "failed to enable power supply\n"); in pwm_backlight_power_on()
57 pwm_apply_state(pb->pwm, &state); in pwm_backlight_power_on()
59 if (pb->post_pwm_on_delay) in pwm_backlight_power_on()
60 msleep(pb->post_pwm_on_delay); in pwm_backlight_power_on()
62 if (pb->enable_gpio) in pwm_backlight_power_on()
63 gpiod_set_value_cansleep(pb->enable_gpio, 1); in pwm_backlight_power_on()
65 pb->enabled = true; in pwm_backlight_power_on()
68 static void pwm_backlight_power_off(struct pwm_bl_data *pb) in pwm_backlight_power_off() argument
72 pwm_get_state(pb->pwm, &state); in pwm_backlight_power_off()
73 if (!pb->enabled) in pwm_backlight_power_off()
76 if (pb->enable_gpio) in pwm_backlight_power_off()
77 gpiod_set_value_cansleep(pb->enable_gpio, 0); in pwm_backlight_power_off()
79 if (pb->pwm_off_delay) in pwm_backlight_power_off()
80 msleep(pb->pwm_off_delay); in pwm_backlight_power_off()
84 pwm_apply_state(pb->pwm, &state); in pwm_backlight_power_off()
86 regulator_disable(pb->power_supply); in pwm_backlight_power_off()
87 pb->enabled = false; in pwm_backlight_power_off()
90 static int compute_duty_cycle(struct pwm_bl_data *pb, int brightness) in compute_duty_cycle() argument
92 unsigned int lth = pb->lth_brightness; in compute_duty_cycle()
96 pwm_get_state(pb->pwm, &state); in compute_duty_cycle()
98 if (pb->levels) in compute_duty_cycle()
99 duty_cycle = pb->levels[brightness]; in compute_duty_cycle()
104 do_div(duty_cycle, pb->scale); in compute_duty_cycle()
111 struct pwm_bl_data *pb = bl_get_data(bl); in pwm_backlight_update_status() local
120 if (pb->notify) in pwm_backlight_update_status()
121 brightness = pb->notify(pb->dev, brightness); in pwm_backlight_update_status()
124 pwm_get_state(pb->pwm, &state); in pwm_backlight_update_status()
125 state.duty_cycle = compute_duty_cycle(pb, brightness); in pwm_backlight_update_status()
126 pwm_apply_state(pb->pwm, &state); in pwm_backlight_update_status()
127 pwm_backlight_power_on(pb); in pwm_backlight_update_status()
129 pwm_backlight_power_off(pb); in pwm_backlight_update_status()
131 if (pb->notify_after) in pwm_backlight_update_status()
132 pb->notify_after(pb->dev, brightness); in pwm_backlight_update_status()
140 struct pwm_bl_data *pb = bl_get_data(bl); in pwm_backlight_check_fb() local
142 return !pb->check_fb || pb->check_fb(pb->dev, info); in pwm_backlight_check_fb()
415 static int pwm_backlight_initial_power_state(const struct pwm_bl_data *pb) in pwm_backlight_initial_power_state() argument
417 struct device_node *node = pb->dev->of_node; in pwm_backlight_initial_power_state()
431 if (pb->enable_gpio && gpiod_get_value_cansleep(pb->enable_gpio) == 0) in pwm_backlight_initial_power_state()
435 if (!regulator_is_enabled(pb->power_supply)) in pwm_backlight_initial_power_state()
439 if (!pwm_is_enabled(pb->pwm)) in pwm_backlight_initial_power_state()
452 struct pwm_bl_data *pb; in pwm_backlight_probe() local
473 pb = devm_kzalloc(&pdev->dev, sizeof(*pb), GFP_KERNEL); in pwm_backlight_probe()
474 if (!pb) { in pwm_backlight_probe()
479 pb->notify = data->notify; in pwm_backlight_probe()
480 pb->notify_after = data->notify_after; in pwm_backlight_probe()
481 pb->check_fb = data->check_fb; in pwm_backlight_probe()
482 pb->exit = data->exit; in pwm_backlight_probe()
483 pb->dev = &pdev->dev; in pwm_backlight_probe()
484 pb->enabled = false; in pwm_backlight_probe()
485 pb->post_pwm_on_delay = data->post_pwm_on_delay; in pwm_backlight_probe()
486 pb->pwm_off_delay = data->pwm_off_delay; in pwm_backlight_probe()
488 pb->enable_gpio = devm_gpiod_get_optional(&pdev->dev, "enable", in pwm_backlight_probe()
490 if (IS_ERR(pb->enable_gpio)) { in pwm_backlight_probe()
491 ret = PTR_ERR(pb->enable_gpio); in pwm_backlight_probe()
499 if (!pb->enable_gpio && gpio_is_valid(data->enable_gpio)) { in pwm_backlight_probe()
508 pb->enable_gpio = gpio_to_desc(data->enable_gpio); in pwm_backlight_probe()
519 if (pb->enable_gpio && in pwm_backlight_probe()
520 gpiod_get_direction(pb->enable_gpio) != 0) in pwm_backlight_probe()
521 gpiod_direction_output(pb->enable_gpio, 1); in pwm_backlight_probe()
523 pb->power_supply = devm_regulator_get(&pdev->dev, "power"); in pwm_backlight_probe()
524 if (IS_ERR(pb->power_supply)) { in pwm_backlight_probe()
525 ret = PTR_ERR(pb->power_supply); in pwm_backlight_probe()
529 pb->pwm = devm_pwm_get(&pdev->dev, NULL); in pwm_backlight_probe()
530 if (IS_ERR(pb->pwm) && PTR_ERR(pb->pwm) != -EPROBE_DEFER && !node) { in pwm_backlight_probe()
532 pb->legacy = true; in pwm_backlight_probe()
533 pb->pwm = pwm_request(data->pwm_id, "pwm-backlight"); in pwm_backlight_probe()
536 if (IS_ERR(pb->pwm)) { in pwm_backlight_probe()
537 ret = PTR_ERR(pb->pwm); in pwm_backlight_probe()
546 pwm_init_state(pb->pwm, &state); in pwm_backlight_probe()
557 ret = pwm_apply_state(pb->pwm, &state); in pwm_backlight_probe()
573 if (data->levels[i] > pb->scale) in pwm_backlight_probe()
574 pb->scale = data->levels[i]; in pwm_backlight_probe()
576 pb->levels = data->levels; in pwm_backlight_probe()
593 pwm_get_state(pb->pwm, &state); in pwm_backlight_probe()
604 if (data->levels[i] > pb->scale) in pwm_backlight_probe()
605 pb->scale = data->levels[i]; in pwm_backlight_probe()
607 pb->levels = data->levels; in pwm_backlight_probe()
616 pb->scale = data->max_brightness; in pwm_backlight_probe()
619 pb->lth_brightness = data->lth_brightness * (div_u64(state.period, in pwm_backlight_probe()
620 pb->scale)); in pwm_backlight_probe()
624 bl = backlight_device_register(dev_name(&pdev->dev), &pdev->dev, pb, in pwm_backlight_probe()
629 if (pb->legacy) in pwm_backlight_probe()
630 pwm_free(pb->pwm); in pwm_backlight_probe()
642 bl->props.power = pwm_backlight_initial_power_state(pb); in pwm_backlight_probe()
657 struct pwm_bl_data *pb = bl_get_data(bl); in pwm_backlight_remove() local
660 pwm_backlight_power_off(pb); in pwm_backlight_remove()
662 if (pb->exit) in pwm_backlight_remove()
663 pb->exit(&pdev->dev); in pwm_backlight_remove()
664 if (pb->legacy) in pwm_backlight_remove()
665 pwm_free(pb->pwm); in pwm_backlight_remove()
673 struct pwm_bl_data *pb = bl_get_data(bl); in pwm_backlight_shutdown() local
675 pwm_backlight_power_off(pb); in pwm_backlight_shutdown()
682 struct pwm_bl_data *pb = bl_get_data(bl); in pwm_backlight_suspend() local
684 if (pb->notify) in pwm_backlight_suspend()
685 pb->notify(pb->dev, 0); in pwm_backlight_suspend()
687 pwm_backlight_power_off(pb); in pwm_backlight_suspend()
689 if (pb->notify_after) in pwm_backlight_suspend()
690 pb->notify_after(pb->dev, 0); in pwm_backlight_suspend()