/* We can provide 15-700 mA out to the LED */ #define RT8515_MIN_IOUT_MA 15 #define RT8515_MAX_IOUT_MA 700 /* The maximum intensity is 1-16 for flash and 1-100 for torch */ #define RT8515_FLASH_MAX 16 #define RT8515_TORCH_MAX 100
staticvoid rt8515_gpio_brightness_commit(struct gpio_desc *gpiod, int brightness)
{ int i;
/* *TogglingaGPIOlinewithasmalldelayincreasesthe *brightnessonestepatatime.
*/ for (i = 0; i < brightness; i++) {
gpiod_set_value(gpiod, 0);
udelay(1);
gpiod_set_value(gpiod, 1);
udelay(1);
}
}
/* This is setting the torch light level */ staticint rt8515_led_brightness_set(struct led_classdev *led, enum led_brightness brightness)
{ struct led_classdev_flash *fled = lcdev_to_flcdev(led); struct rt8515 *rt = to_rt8515(fled);
mutex_lock(&rt->lock);
if (brightness == LED_OFF) { /* Off */
rt8515_gpio_led_off(rt);
} elseif (brightness < RT8515_TORCH_MAX) { /* Step it up to movie mode brightness using the flash pin */
rt8515_gpio_brightness_commit(rt->enable_torch, brightness);
} else { /* Max torch brightness requested */
gpiod_set_value(rt->enable_torch, 1);
}
if (state) { /* Enable LED flash mode and set brightness */
rt8515_gpio_brightness_commit(rt->enable_flash, brightness); /* Set timeout */
mod_timer(&rt->powerdown_timer,
jiffies + usecs_to_jiffies(timeout->val));
} else {
timer_delete_sync(&rt->powerdown_timer); /* Turn the LED off */
rt8515_gpio_led_off(rt);
}
fled->led_cdev.brightness = LED_OFF; /* After this the torch LED will be disabled */
staticint rt8515_led_flash_timeout_set(struct led_classdev_flash *fled,
u32 timeout)
{ /* The timeout is stored in the led-class-flash core */ return0;
}
staticvoid rt8515_determine_max_intensity(struct rt8515 *rt, struct fwnode_handle *led, constchar *resistance, constchar *max_ua_prop, int hw_max, int *max_intensity_setting)
{
u32 res = 0; /* Can't be 0 so 0 is undefined */
u32 ua;
u32 max_ma; int max_intensity; int ret;
fwnode_property_read_u32(rt->dev->fwnode, resistance, &res);
ret = fwnode_property_read_u32(led, max_ua_prop, &ua);
/* Missing info in DT, OK go with hardware maxima */ if (ret || res == 0) {
dev_err(rt->dev, "either %s or %s missing from DT, using HW max\n",
resistance, max_ua_prop);
max_ma = RT8515_MAX_IOUT_MA;
max_intensity = hw_max; goto out_assign_max;
}
rt = devm_kzalloc(dev, sizeof(*rt), GFP_KERNEL); if (!rt) return -ENOMEM;
rt->dev = dev;
fled = &rt->fled;
led = &fled->led_cdev;
/* ENF - Enable Flash line */
rt->enable_flash = devm_gpiod_get(dev, "enf", GPIOD_OUT_LOW); if (IS_ERR(rt->enable_flash)) return dev_err_probe(dev, PTR_ERR(rt->enable_flash), "cannot get ENF (enable flash) GPIO\n");
/* ENT - Enable Torch line */
rt->enable_torch = devm_gpiod_get(dev, "ent", GPIOD_OUT_LOW); if (IS_ERR(rt->enable_torch)) return dev_err_probe(dev, PTR_ERR(rt->enable_torch), "cannot get ENT (enable torch) GPIO\n");
child = fwnode_get_next_available_child_node(dev->fwnode, NULL); if (!child) {
dev_err(dev, "No fwnode child node found for connected LED.\n"); return -EINVAL;
}
init_data.fwnode = child;
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.