Lines Matching full:pb
42 static void pwm_backlight_power_on(struct pwm_bl_data *pb) in pwm_backlight_power_on() argument
47 pwm_get_state(pb->pwm, &state); in pwm_backlight_power_on()
48 if (pb->enabled) in pwm_backlight_power_on()
51 err = regulator_enable(pb->power_supply); in pwm_backlight_power_on()
53 dev_err(pb->dev, "failed to enable power supply\n"); in pwm_backlight_power_on()
56 pwm_apply_state(pb->pwm, &state); in pwm_backlight_power_on()
58 if (pb->post_pwm_on_delay) in pwm_backlight_power_on()
59 msleep(pb->post_pwm_on_delay); in pwm_backlight_power_on()
61 if (pb->enable_gpio) in pwm_backlight_power_on()
62 gpiod_set_value_cansleep(pb->enable_gpio, 1); in pwm_backlight_power_on()
64 pb->enabled = true; in pwm_backlight_power_on()
67 static void pwm_backlight_power_off(struct pwm_bl_data *pb) in pwm_backlight_power_off() argument
71 pwm_get_state(pb->pwm, &state); in pwm_backlight_power_off()
72 if (!pb->enabled) in pwm_backlight_power_off()
75 if (pb->enable_gpio) in pwm_backlight_power_off()
76 gpiod_set_value_cansleep(pb->enable_gpio, 0); in pwm_backlight_power_off()
78 if (pb->pwm_off_delay) in pwm_backlight_power_off()
79 msleep(pb->pwm_off_delay); in pwm_backlight_power_off()
83 pwm_apply_state(pb->pwm, &state); in pwm_backlight_power_off()
85 regulator_disable(pb->power_supply); in pwm_backlight_power_off()
86 pb->enabled = false; in pwm_backlight_power_off()
89 static int compute_duty_cycle(struct pwm_bl_data *pb, int brightness) in compute_duty_cycle() argument
91 unsigned int lth = pb->lth_brightness; in compute_duty_cycle()
95 pwm_get_state(pb->pwm, &state); in compute_duty_cycle()
97 if (pb->levels) in compute_duty_cycle()
98 duty_cycle = pb->levels[brightness]; in compute_duty_cycle()
103 do_div(duty_cycle, pb->scale); in compute_duty_cycle()
110 struct pwm_bl_data *pb = bl_get_data(bl); in pwm_backlight_update_status() local
114 if (pb->notify) in pwm_backlight_update_status()
115 brightness = pb->notify(pb->dev, brightness); in pwm_backlight_update_status()
118 pwm_get_state(pb->pwm, &state); in pwm_backlight_update_status()
119 state.duty_cycle = compute_duty_cycle(pb, brightness); in pwm_backlight_update_status()
120 pwm_apply_state(pb->pwm, &state); in pwm_backlight_update_status()
121 pwm_backlight_power_on(pb); in pwm_backlight_update_status()
123 pwm_backlight_power_off(pb); in pwm_backlight_update_status()
126 if (pb->notify_after) in pwm_backlight_update_status()
127 pb->notify_after(pb->dev, brightness); in pwm_backlight_update_status()
135 struct pwm_bl_data *pb = bl_get_data(bl); in pwm_backlight_check_fb() local
137 return !pb->check_fb || pb->check_fb(pb->dev, info); in pwm_backlight_check_fb()
408 static int pwm_backlight_initial_power_state(const struct pwm_bl_data *pb) in pwm_backlight_initial_power_state() argument
410 struct device_node *node = pb->dev->of_node; in pwm_backlight_initial_power_state()
417 if (pb->enable_gpio && gpiod_get_value_cansleep(pb->enable_gpio) == 0) in pwm_backlight_initial_power_state()
420 if (!regulator_is_enabled(pb->power_supply)) in pwm_backlight_initial_power_state()
423 if (!pwm_is_enabled(pb->pwm)) in pwm_backlight_initial_power_state()
430 if (pb->enable_gpio) in pwm_backlight_initial_power_state()
431 gpiod_direction_output(pb->enable_gpio, active); in pwm_backlight_initial_power_state()
434 * Do not change pb->enabled here! pb->enabled essentially in pwm_backlight_initial_power_state()
459 struct pwm_bl_data *pb; in pwm_backlight_probe() local
480 pb = devm_kzalloc(&pdev->dev, sizeof(*pb), GFP_KERNEL); in pwm_backlight_probe()
481 if (!pb) { in pwm_backlight_probe()
486 pb->notify = data->notify; in pwm_backlight_probe()
487 pb->notify_after = data->notify_after; in pwm_backlight_probe()
488 pb->check_fb = data->check_fb; in pwm_backlight_probe()
489 pb->exit = data->exit; in pwm_backlight_probe()
490 pb->dev = &pdev->dev; in pwm_backlight_probe()
491 pb->enabled = false; in pwm_backlight_probe()
492 pb->post_pwm_on_delay = data->post_pwm_on_delay; in pwm_backlight_probe()
493 pb->pwm_off_delay = data->pwm_off_delay; in pwm_backlight_probe()
495 pb->enable_gpio = devm_gpiod_get_optional(&pdev->dev, "enable", in pwm_backlight_probe()
497 if (IS_ERR(pb->enable_gpio)) { in pwm_backlight_probe()
498 ret = PTR_ERR(pb->enable_gpio); in pwm_backlight_probe()
502 pb->power_supply = devm_regulator_get(&pdev->dev, "power"); in pwm_backlight_probe()
503 if (IS_ERR(pb->power_supply)) { in pwm_backlight_probe()
504 ret = PTR_ERR(pb->power_supply); in pwm_backlight_probe()
508 pb->pwm = devm_pwm_get(&pdev->dev, NULL); in pwm_backlight_probe()
509 if (IS_ERR(pb->pwm) && PTR_ERR(pb->pwm) != -EPROBE_DEFER && !node) { in pwm_backlight_probe()
511 pb->legacy = true; in pwm_backlight_probe()
512 pb->pwm = pwm_request(data->pwm_id, "pwm-backlight"); in pwm_backlight_probe()
515 if (IS_ERR(pb->pwm)) { in pwm_backlight_probe()
516 ret = PTR_ERR(pb->pwm); in pwm_backlight_probe()
525 pwm_init_state(pb->pwm, &state); in pwm_backlight_probe()
536 ret = pwm_apply_state(pb->pwm, &state); in pwm_backlight_probe()
546 pb->levels = data->levels; in pwm_backlight_probe()
554 if (data->levels[i] > pb->scale) in pwm_backlight_probe()
555 pb->scale = data->levels[i]; in pwm_backlight_probe()
571 pwm_get_state(pb->pwm, &state); in pwm_backlight_probe()
582 if (data->levels[i] > pb->scale) in pwm_backlight_probe()
583 pb->scale = data->levels[i]; in pwm_backlight_probe()
585 pb->levels = data->levels; in pwm_backlight_probe()
594 pb->scale = data->max_brightness; in pwm_backlight_probe()
597 pb->lth_brightness = data->lth_brightness * (div_u64(state.period, in pwm_backlight_probe()
598 pb->scale)); in pwm_backlight_probe()
602 bl = backlight_device_register(dev_name(&pdev->dev), &pdev->dev, pb, in pwm_backlight_probe()
607 if (pb->legacy) in pwm_backlight_probe()
608 pwm_free(pb->pwm); in pwm_backlight_probe()
620 bl->props.power = pwm_backlight_initial_power_state(pb); in pwm_backlight_probe()
635 struct pwm_bl_data *pb = bl_get_data(bl); in pwm_backlight_remove() local
638 pwm_backlight_power_off(pb); in pwm_backlight_remove()
640 if (pb->exit) in pwm_backlight_remove()
641 pb->exit(&pdev->dev); in pwm_backlight_remove()
642 if (pb->legacy) in pwm_backlight_remove()
643 pwm_free(pb->pwm); in pwm_backlight_remove()
651 struct pwm_bl_data *pb = bl_get_data(bl); in pwm_backlight_shutdown() local
653 pwm_backlight_power_off(pb); in pwm_backlight_shutdown()
660 struct pwm_bl_data *pb = bl_get_data(bl); in pwm_backlight_suspend() local
662 if (pb->notify) in pwm_backlight_suspend()
663 pb->notify(pb->dev, 0); in pwm_backlight_suspend()
665 pwm_backlight_power_off(pb); in pwm_backlight_suspend()
667 if (pb->notify_after) in pwm_backlight_suspend()
668 pb->notify_after(pb->dev, 0); in pwm_backlight_suspend()