// SPDX-License-Identifier: GPL-2.0-only /* * LED Flash class driver for the AAT1290 * 1.5A Step-Up Current Regulator for Flash LEDs * * Copyright (C) 2015, Samsung Electronics Co., Ltd. * Author: Jacek Anaszewski <j.anaszewski@samsung.com>
*/
struct aat1290_led_config_data { /* maximum LED current in movie mode */
u32 max_mm_current; /* maximum LED current in flash mode */
u32 max_flash_current; /* maximum flash timeout */
u32 max_flash_tm; /* external strobe capability */ bool has_external_strobe; /* max LED brightness level */ enum led_brightness max_brightness;
};
struct aat1290_led { /* platform device data */ struct platform_device *pdev; /* secures access to the device */ struct mutex lock;
/* corresponding LED Flash class device */ struct led_classdev_flash fled_cdev; /* V4L2 Flash device */ struct v4l2_flash *v4l2_flash;
/* FLEN pin */ struct gpio_desc *gpio_fl_en; /* EN|SET pin */ struct gpio_desc *gpio_en_set; /* movie mode current scale */ int *mm_current_scale; /* device mode */ bool movie_mode;
};
/* write data */ for (i = 0; i < value; ++i) {
udelay(AAT1290_EN_SET_TICK_TIME_US);
gpiod_direction_output(led->gpio_en_set, 0);
udelay(AAT1290_EN_SET_TICK_TIME_US);
gpiod_direction_output(led->gpio_en_set, 1);
}
/* * To reenter movie mode after a flash event the part must be cycled * off and back on to reset the movie mode and reprogrammed via the * AS2Cwire. Therefore the brightness and movie_mode properties needs * to be updated here to reflect the actual state.
*/
led_cdev->brightness = 0;
led->movie_mode = false;
mutex_unlock(&led->lock);
return 0;
}
staticint aat1290_led_flash_timeout_set(struct led_classdev_flash *fled_cdev,
u32 timeout)
{ /* * Don't do anything - flash timeout is cached in the led-class-flash * core and will be applied in the strobe_set op, as writing the * safety timer register spuriously turns the torch mode on.
*/
led->gpio_fl_en = devm_gpiod_get(dev, "flen", GPIOD_ASIS); if (IS_ERR(led->gpio_fl_en)) {
ret = PTR_ERR(led->gpio_fl_en);
dev_err(dev, "Unable to claim gpio \"flen\".\n"); return ret;
}
led->gpio_en_set = devm_gpiod_get(dev, "enset", GPIOD_ASIS); if (IS_ERR(led->gpio_en_set)) {
ret = PTR_ERR(led->gpio_en_set);
dev_err(dev, "Unable to claim gpio \"enset\".\n"); return ret;
}
#if IS_ENABLED(CONFIG_V4L2_FLASH_LED_CLASS)
pinctrl = devm_pinctrl_get_select_default(&led->pdev->dev); if (IS_ERR(pinctrl)) {
cfg->has_external_strobe = false;
dev_info(dev, "No support for external strobe detected.\n");
} else {
cfg->has_external_strobe = true;
} #endif
struct device_node *child_node __free(device_node) =
of_get_next_available_child(dev_of_node(dev), NULL); if (!child_node) {
dev_err(dev, "No DT child node found for connected LED.\n"); return -EINVAL;
}
ret = of_property_read_u32(child_node, "led-max-microamp",
&cfg->max_mm_current); /* * led-max-microamp will default to 1/20 of flash-max-microamp * in case it is missing.
*/ if (ret < 0)
dev_warn(dev, "led-max-microamp DT property missing\n");
ret = of_property_read_u32(child_node, "flash-max-microamp",
&cfg->max_flash_current); if (ret < 0) {
dev_err(dev, "flash-max-microamp DT property missing\n"); return ret;
}
ret = of_property_read_u32(child_node, "flash-max-timeout-us",
&cfg->max_flash_tm); if (ret < 0) {
dev_err(dev, "flash-max-timeout-us DT property missing\n"); return ret;
}
*sub_node = child_node;
return 0;
}
staticvoid aat1290_led_validate_mm_current(struct aat1290_led *led, struct aat1290_led_config_data *cfg)
{ int i, b = 0, e = AAT1290_MM_CURRENT_SCALE_SIZE;
while (e - b > 1) {
i = b + (e - b) / 2; if (cfg->max_mm_current < led->mm_current_scale[i])
e = i; else
b = i;
}
cfg->max_mm_current = led->mm_current_scale[b];
cfg->max_brightness = b + 1;
}
ret = aat1290_led_parse_dt(led, cfg, sub_node); if (ret < 0) return ret; /* * Init non-linear movie mode current scale basing * on the max flash current from led configuration.
*/
ret = init_mm_current_scale(led, cfg); if (ret < 0) return ret;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.