From patchwork Mon May 25 15:13:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacek Anaszewski X-Patchwork-Id: 6475561 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 49D6EC0020 for ; Mon, 25 May 2015 15:14:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C43AD2012E for ; Mon, 25 May 2015 15:14:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 16A32203DA for ; Mon, 25 May 2015 15:14:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751882AbbEYPO2 (ORCPT ); Mon, 25 May 2015 11:14:28 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:19389 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751793AbbEYPO0 (ORCPT ); Mon, 25 May 2015 11:14:26 -0400 Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NOW00EF4VO0PB00@mailout3.samsung.com>; Tue, 26 May 2015 00:14:24 +0900 (KST) X-AuditID: cbfee61b-f79416d0000014c0-d0-55633c50cba4 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 66.E7.05312.05C33655; Tue, 26 May 2015 00:14:24 +0900 (KST) Received: from AMDC2362.DIGITAL.local ([106.120.53.23]) by mmp1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0NOW004EQVNH5790@mmp1.samsung.com>; Tue, 26 May 2015 00:14:24 +0900 (KST) From: Jacek Anaszewski To: linux-leds@vger.kernel.org, linux-media@vger.kernel.org Cc: devicetree@vger.kernel.org, kyungmin.park@samsung.com, pavel@ucw.cz, cooloney@gmail.com, rpurdie@rpsys.net, sakari.ailus@iki.fi, s.nawrocki@samsung.com, Jacek Anaszewski Subject: [PATCH v9 3/8] leds: max77693: add support for V4L2 Flash sub-device Date: Mon, 25 May 2015 17:13:58 +0200 Message-id: <1432566843-6391-4-git-send-email-j.anaszewski@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1432566843-6391-1-git-send-email-j.anaszewski@samsung.com> References: <1432566843-6391-1-git-send-email-j.anaszewski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrCLMWRmVeSWpSXmKPExsVy+t9jAd0Am+RQgxUXhSyO7pzIZDH/yDlW i96rzxktzja9YbfY+mYdo0XPhq2sFndPHWWz2L3rKavF4TftrBZn9q9kc+Dy2DnrLrvH4a8L WTz2zP/B6tG3ZRWjx4rV39k9Pm+SC2CL4rJJSc3JLEst0rdL4Mq4OCuuoNuu4mjnD6YGxqfG XYycHBICJhJzN39hgbDFJC7cW8/WxcjFISSwiFHi++fn7CAJIYGfjBK7TwmB2GwChhI/X7xm ArFFBKwlZh2aDtbMLHCGUWLaVFsQW1jAV2L3kSNANRwcLAKqElv+CoOEeQXcJQ6tWsYKEpYQ UJCYM8kGJMwp4CHRcPArC8Qmd4lLhyYyTmDkXcDIsIpRNLUguaA4KT3XSK84Mbe4NC9dLzk/ dxMjOOyeSe9gXNVgcYhRgINRiYc3IiMpVIg1say4MvcQowQHs5IIb6JJcqgQb0piZVVqUX58 UWlOavEhRmkOFiVx3pP5PqFCAumJJanZqakFqUUwWSYOTqkGRtu7H9zcP/StDxKZ+TnvbN6M RbWH9Hlz2mVYb6pI9JcuZugV09XYmLyyICgnYzJX/DGmG8dijvazCHovKF6aunH9Nu7dVeEL vdkWbty3+P3qVd8/35zPs61Puu90w+OVe1ZPUdWaZu5s8PzGaqfya/tld7z7ubPu81aVG4G/ 76T5z1a0DL3wvF6JpTgj0VCLuag4EQCRK6z/NwIAAA== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add support for V4L2 Flash sub-device to the max77693 LED Flash class driver. The support allows for V4L2 Flash sub-device to take the control of the LED Flash class device. Signed-off-by: Jacek Anaszewski Acked-by: Kyungmin Park Cc: Bryan Wu Cc: Richard Purdie Cc: Sakari Ailus Acked-by: Sakari Ailus --- drivers/leds/leds-max77693.c | 129 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 123 insertions(+), 6 deletions(-) diff --git a/drivers/leds/leds-max77693.c b/drivers/leds/leds-max77693.c index eecaa92..b8b0eec 100644 --- a/drivers/leds/leds-max77693.c +++ b/drivers/leds/leds-max77693.c @@ -20,6 +20,7 @@ #include #include #include +#include #define MODE_OFF 0 #define MODE_FLASH(a) (1 << (a)) @@ -62,6 +63,8 @@ struct max77693_sub_led { struct led_classdev_flash fled_cdev; /* assures led-triggers compatibility */ struct work_struct work_brightness_set; + /* V4L2 Flash device */ + struct v4l2_flash *v4l2_flash; /* brightness cache */ unsigned int torch_brightness; @@ -627,7 +630,8 @@ static int max77693_led_flash_timeout_set( } static int max77693_led_parse_dt(struct max77693_led_device *led, - struct max77693_led_config_data *cfg) + struct max77693_led_config_data *cfg, + struct device_node **sub_nodes) { struct device *dev = &led->pdev->dev; struct max77693_sub_led *sub_leds = led->sub_leds; @@ -674,6 +678,13 @@ static int max77693_led_parse_dt(struct max77693_led_device *led, return -EINVAL; } + if (sub_nodes[fled_id]) { + dev_err(dev, + "Conflicting \"led-sources\" DT properties\n"); + return -EINVAL; + } + + sub_nodes[fled_id] = child_node; sub_leds[fled_id].fled_id = fled_id; cfg->label[fled_id] = @@ -786,11 +797,12 @@ static void max77693_led_validate_configuration(struct max77693_led_device *led, } static int max77693_led_get_configuration(struct max77693_led_device *led, - struct max77693_led_config_data *cfg) + struct max77693_led_config_data *cfg, + struct device_node **sub_nodes) { int ret; - ret = max77693_led_parse_dt(led, cfg); + ret = max77693_led_parse_dt(led, cfg, sub_nodes); if (ret < 0) return ret; @@ -838,6 +850,71 @@ static void max77693_init_flash_settings(struct max77693_sub_led *sub_led, setting->val = setting->max; } +#if IS_ENABLED(CONFIG_V4L2_FLASH_LED_CLASS) + +static int max77693_led_external_strobe_set( + struct v4l2_flash *v4l2_flash, + bool enable) +{ + struct max77693_sub_led *sub_led = + flcdev_to_sub_led(v4l2_flash->fled_cdev); + struct max77693_led_device *led = sub_led_to_led(sub_led); + int fled_id = sub_led->fled_id; + int ret; + + mutex_lock(&led->lock); + + if (enable) + ret = max77693_add_mode(led, MODE_FLASH_EXTERNAL(fled_id)); + else + ret = max77693_clear_mode(led, MODE_FLASH_EXTERNAL(fled_id)); + + mutex_unlock(&led->lock); + + return ret; +} + +static void max77693_init_v4l2_flash_config(struct max77693_sub_led *sub_led, + struct max77693_led_config_data *led_cfg, + struct v4l2_flash_config *v4l2_sd_cfg) +{ + struct max77693_led_device *led = sub_led_to_led(sub_led); + struct device *dev = &led->pdev->dev; + struct max77693_dev *iodev = dev_get_drvdata(dev->parent); + struct i2c_client *i2c = iodev->i2c; + struct led_flash_setting *s; + + snprintf(v4l2_sd_cfg->dev_name, sizeof(v4l2_sd_cfg->dev_name), + "%s %d-%04x", sub_led->fled_cdev.led_cdev.name, + i2c_adapter_id(i2c->adapter), i2c->addr); + + s = &v4l2_sd_cfg->torch_intensity; + s->min = TORCH_IOUT_MIN; + s->max = sub_led->fled_cdev.led_cdev.max_brightness * TORCH_IOUT_STEP; + s->step = TORCH_IOUT_STEP; + s->val = s->max; + + /* Init flash faults config */ + v4l2_sd_cfg->flash_faults = LED_FAULT_OVER_VOLTAGE | + LED_FAULT_SHORT_CIRCUIT | + LED_FAULT_OVER_CURRENT; + + v4l2_sd_cfg->has_external_strobe = true; +} + +static const struct v4l2_flash_ops v4l2_flash_ops = { + .external_strobe_set = max77693_led_external_strobe_set, +}; +#else +static inline void max77693_init_v4l2_flash_config( + struct max77693_sub_led *sub_led, + struct max77693_led_config_data *led_cfg, + struct v4l2_flash_config *v4l2_sd_cfg) +{ +} +static const struct v4l2_flash_ops v4l2_flash_ops; +#endif + static void max77693_init_fled_cdev(struct max77693_sub_led *sub_led, struct max77693_led_config_data *led_cfg) { @@ -870,12 +947,45 @@ static void max77693_init_fled_cdev(struct max77693_sub_led *sub_led, sub_led->flash_timeout = fled_cdev->timeout.val; } +static int max77693_register_led(struct max77693_sub_led *sub_led, + struct max77693_led_config_data *led_cfg, + struct device_node *sub_node) +{ + struct max77693_led_device *led = sub_led_to_led(sub_led); + struct led_classdev_flash *fled_cdev = &sub_led->fled_cdev; + struct device *dev = &led->pdev->dev; + struct v4l2_flash_config v4l2_sd_cfg = {}; + int ret; + + /* Register in the LED subsystem */ + ret = led_classdev_flash_register(dev, fled_cdev); + if (ret < 0) + return ret; + + max77693_init_v4l2_flash_config(sub_led, led_cfg, &v4l2_sd_cfg); + + /* Register in the V4L2 subsystem. */ + sub_led->v4l2_flash = v4l2_flash_init(dev, sub_node, fled_cdev, NULL, + &v4l2_flash_ops, &v4l2_sd_cfg); + if (IS_ERR(sub_led->v4l2_flash)) { + ret = PTR_ERR(sub_led->v4l2_flash); + goto err_v4l2_flash_init; + } + + return 0; + +err_v4l2_flash_init: + led_classdev_flash_unregister(fled_cdev); + return ret; +} + static int max77693_led_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct max77693_dev *iodev = dev_get_drvdata(dev->parent); struct max77693_led_device *led; struct max77693_sub_led *sub_leds; + struct device_node *sub_nodes[2] = {}; struct max77693_led_config_data led_cfg = {}; int init_fled_cdev[2], i, ret; @@ -889,7 +999,7 @@ static int max77693_led_probe(struct platform_device *pdev) sub_leds = led->sub_leds; platform_set_drvdata(pdev, led); - ret = max77693_led_get_configuration(led, &led_cfg); + ret = max77693_led_get_configuration(led, &led_cfg, sub_nodes); if (ret < 0) return ret; @@ -911,8 +1021,12 @@ static int max77693_led_probe(struct platform_device *pdev) /* Initialize LED Flash class device */ max77693_init_fled_cdev(&sub_leds[i], &led_cfg); - /* Register LED Flash class device */ - ret = led_classdev_flash_register(dev, &sub_leds[i].fled_cdev); + /* + * Register LED Flash class device and corresponding + * V4L2 Flash device. + */ + ret = max77693_register_led(&sub_leds[i], &led_cfg, + sub_nodes[i]); if (ret < 0) { /* * At this moment FLED1 might have been already @@ -931,6 +1045,7 @@ err_register_led2: /* It is possible than only FLED2 was to be registered */ if (!init_fled_cdev[FLED1]) goto err_register_led1; + v4l2_flash_release(sub_leds[FLED1].v4l2_flash); led_classdev_flash_unregister(&sub_leds[FLED1].fled_cdev); err_register_led1: mutex_destroy(&led->lock); @@ -944,11 +1059,13 @@ static int max77693_led_remove(struct platform_device *pdev) struct max77693_sub_led *sub_leds = led->sub_leds; if (led->iout_joint || max77693_fled_used(led, FLED1)) { + v4l2_flash_release(sub_leds[FLED1].v4l2_flash); led_classdev_flash_unregister(&sub_leds[FLED1].fled_cdev); cancel_work_sync(&sub_leds[FLED1].work_brightness_set); } if (!led->iout_joint && max77693_fled_used(led, FLED2)) { + v4l2_flash_release(sub_leds[FLED2].v4l2_flash); led_classdev_flash_unregister(&sub_leds[FLED2].fled_cdev); cancel_work_sync(&sub_leds[FLED2].work_brightness_set); }