From f70575805708cabdedea7498aaa3f710fde4d920 Mon Sep 17 00:00:00 2001 From: hc <hc@nodka.com> Date: Wed, 31 Jan 2024 03:29:01 +0000 Subject: [PATCH] add lvds1024*800 --- kernel/drivers/leds/leds-as3645a.c | 142 +++++++++++++++++++++-------------------------- 1 files changed, 64 insertions(+), 78 deletions(-) diff --git a/kernel/drivers/leds/leds-as3645a.c b/kernel/drivers/leds/leds-as3645a.c index 8219443..80411d4 100644 --- a/kernel/drivers/leds/leds-as3645a.c +++ b/kernel/drivers/leds/leds-as3645a.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0-only /* * drivers/leds/leds-as3645a.c - AS3645A and LM3555 flash controllers driver * @@ -7,15 +8,6 @@ * Based on drivers/media/i2c/as3645a.c. * * Contact: Sakari Ailus <sakari.ailus@iki.fi> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * version 2 as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. */ #include <linux/delay.h> @@ -25,7 +17,7 @@ #include <linux/leds.h> #include <linux/module.h> #include <linux/mutex.h> -#include <linux/of.h> +#include <linux/property.h> #include <linux/slab.h> #include <media/v4l2-flash-led-class.h> @@ -132,11 +124,6 @@ u32 peak; }; -struct as3645a_names { - char flash[32]; - char indicator[32]; -}; - struct as3645a { struct i2c_client *client; @@ -148,8 +135,8 @@ struct v4l2_flash *vf; struct v4l2_flash *vfind; - struct device_node *flash_node; - struct device_node *indicator_node; + struct fwnode_handle *flash_node; + struct fwnode_handle *indicator_node; struct as3645a_config cfg; @@ -492,25 +479,25 @@ } static int as3645a_parse_node(struct as3645a *flash, - struct as3645a_names *names, - struct device_node *node) + struct fwnode_handle *fwnode) { struct as3645a_config *cfg = &flash->cfg; - struct device_node *child; - const char *name; + struct fwnode_handle *child; int rval; - for_each_child_of_node(node, child) { + fwnode_for_each_child_node(fwnode, child) { u32 id = 0; - of_property_read_u32(child, "reg", &id); + fwnode_property_read_u32(child, "reg", &id); switch (id) { case AS_LED_FLASH: - flash->flash_node = of_node_get(child); + flash->flash_node = child; + fwnode_handle_get(child); break; case AS_LED_INDICATOR: - flash->indicator_node = of_node_get(child); + flash->indicator_node = child; + fwnode_handle_get(child); break; default: dev_warn(&flash->client->dev, @@ -524,42 +511,35 @@ return -ENODEV; } - rval = of_property_read_string(flash->flash_node, "label", &name); - if (!rval) - strlcpy(names->flash, name, sizeof(names->flash)); - else - snprintf(names->flash, sizeof(names->flash), - "%s:flash", node->name); - - rval = of_property_read_u32(flash->flash_node, "flash-timeout-us", - &cfg->flash_timeout_us); + rval = fwnode_property_read_u32(flash->flash_node, "flash-timeout-us", + &cfg->flash_timeout_us); if (rval < 0) { dev_err(&flash->client->dev, "can't read flash-timeout-us property for flash\n"); goto out_err; } - rval = of_property_read_u32(flash->flash_node, "flash-max-microamp", - &cfg->flash_max_ua); + rval = fwnode_property_read_u32(flash->flash_node, "flash-max-microamp", + &cfg->flash_max_ua); if (rval < 0) { dev_err(&flash->client->dev, "can't read flash-max-microamp property for flash\n"); goto out_err; } - rval = of_property_read_u32(flash->flash_node, "led-max-microamp", - &cfg->assist_max_ua); + rval = fwnode_property_read_u32(flash->flash_node, "led-max-microamp", + &cfg->assist_max_ua); if (rval < 0) { dev_err(&flash->client->dev, "can't read led-max-microamp property for flash\n"); goto out_err; } - of_property_read_u32(flash->flash_node, "voltage-reference", - &cfg->voltage_reference); + fwnode_property_read_u32(flash->flash_node, "voltage-reference", + &cfg->voltage_reference); - of_property_read_u32(flash->flash_node, "ams,input-max-microamp", - &cfg->peak); + fwnode_property_read_u32(flash->flash_node, "ams,input-max-microamp", + &cfg->peak); cfg->peak = AS_PEAK_mA_TO_REG(cfg->peak); if (!flash->indicator_node) { @@ -569,15 +549,10 @@ goto out_err; } - rval = of_property_read_string(flash->indicator_node, "label", &name); - if (!rval) - strlcpy(names->indicator, name, sizeof(names->indicator)); - else - snprintf(names->indicator, sizeof(names->indicator), - "%s:indicator", node->name); - rval = of_property_read_u32(flash->indicator_node, "led-max-microamp", - &cfg->indicator_max_ua); + rval = fwnode_property_read_u32(flash->indicator_node, + "led-max-microamp", + &cfg->indicator_max_ua); if (rval < 0) { dev_err(&flash->client->dev, "can't read led-max-microamp property for indicator\n"); @@ -587,27 +562,31 @@ return 0; out_err: - of_node_put(flash->flash_node); - of_node_put(flash->indicator_node); + fwnode_handle_put(flash->flash_node); + fwnode_handle_put(flash->indicator_node); return rval; } -static int as3645a_led_class_setup(struct as3645a *flash, - struct as3645a_names *names) +static int as3645a_led_class_setup(struct as3645a *flash) { struct led_classdev *fled_cdev = &flash->fled.led_cdev; struct led_classdev *iled_cdev = &flash->iled_cdev; + struct led_init_data init_data = {}; struct led_flash_setting *cfg; int rval; - iled_cdev->name = names->indicator; iled_cdev->brightness_set_blocking = as3645a_set_indicator_brightness; iled_cdev->max_brightness = flash->cfg.indicator_max_ua / AS_INDICATOR_INTENSITY_STEP; iled_cdev->flags = LED_CORE_SUSPENDRESUME; - rval = led_classdev_register(&flash->client->dev, iled_cdev); + init_data.fwnode = flash->indicator_node; + init_data.devicename = AS_NAME; + init_data.default_label = "indicator"; + + rval = led_classdev_register_ext(&flash->client->dev, iled_cdev, + &init_data); if (rval < 0) return rval; @@ -625,7 +604,6 @@ flash->fled.ops = &as3645a_led_flash_ops; - fled_cdev->name = names->flash; fled_cdev->brightness_set_blocking = as3645a_set_assist_brightness; /* Value 0 is off in LED class. */ fled_cdev->max_brightness = @@ -633,14 +611,22 @@ flash->cfg.assist_max_ua) + 1; fled_cdev->flags = LED_DEV_CAP_FLASH | LED_CORE_SUSPENDRESUME; - rval = led_classdev_flash_register(&flash->client->dev, &flash->fled); - if (rval) { - led_classdev_unregister(iled_cdev); - dev_err(&flash->client->dev, - "led_classdev_flash_register() failed, error %d\n", - rval); - } + init_data.fwnode = flash->flash_node; + init_data.devicename = AS_NAME; + init_data.default_label = "flash"; + rval = led_classdev_flash_register_ext(&flash->client->dev, + &flash->fled, &init_data); + if (rval) + goto out_err; + + return rval; + +out_err: + led_classdev_unregister(iled_cdev); + dev_err(&flash->client->dev, + "led_classdev_flash_register() failed, error %d\n", + rval); return rval; } @@ -665,18 +651,19 @@ }, }; - strlcpy(cfg.dev_name, led->name, sizeof(cfg.dev_name)); - strlcpy(cfgind.dev_name, flash->iled_cdev.name, sizeof(cfg.dev_name)); + strlcpy(cfg.dev_name, led->dev->kobj.name, sizeof(cfg.dev_name)); + strlcpy(cfgind.dev_name, flash->iled_cdev.dev->kobj.name, + sizeof(cfgind.dev_name)); flash->vf = v4l2_flash_init( - &flash->client->dev, of_fwnode_handle(flash->flash_node), - &flash->fled, NULL, &cfg); + &flash->client->dev, flash->flash_node, &flash->fled, NULL, + &cfg); if (IS_ERR(flash->vf)) return PTR_ERR(flash->vf); flash->vfind = v4l2_flash_indicator_init( - &flash->client->dev, of_fwnode_handle(flash->indicator_node), - &flash->iled_cdev, &cfgind); + &flash->client->dev, flash->indicator_node, &flash->iled_cdev, + &cfgind); if (IS_ERR(flash->vfind)) { v4l2_flash_release(flash->vf); return PTR_ERR(flash->vfind); @@ -687,11 +674,10 @@ static int as3645a_probe(struct i2c_client *client) { - struct as3645a_names names; struct as3645a *flash; int rval; - if (client->dev.of_node == NULL) + if (!dev_fwnode(&client->dev)) return -ENODEV; flash = devm_kzalloc(&client->dev, sizeof(*flash), GFP_KERNEL); @@ -700,7 +686,7 @@ flash->client = client; - rval = as3645a_parse_node(flash, &names, client->dev.of_node); + rval = as3645a_parse_node(flash, dev_fwnode(&client->dev)); if (rval < 0) return rval; @@ -715,7 +701,7 @@ if (rval) goto out_mutex_destroy; - rval = as3645a_led_class_setup(flash, &names); + rval = as3645a_led_class_setup(flash); if (rval) goto out_mutex_destroy; @@ -732,8 +718,8 @@ mutex_destroy(&flash->mutex); out_put_nodes: - of_node_put(flash->flash_node); - of_node_put(flash->indicator_node); + fwnode_handle_put(flash->flash_node); + fwnode_handle_put(flash->indicator_node); return rval; } @@ -752,8 +738,8 @@ mutex_destroy(&flash->mutex); - of_node_put(flash->flash_node); - of_node_put(flash->indicator_node); + fwnode_handle_put(flash->flash_node); + fwnode_handle_put(flash->indicator_node); return 0; } -- Gitblit v1.6.2