Re: [PATCH/RFC v8 12/14] leds: Add driver for AAT1290 current regulator

2014-12-01 Thread Jacek Anaszewski

Hi Pavel,

Thanks for a review.

On 11/29/2014 08:05 PM, Pavel Machek wrote:

Hi!



@@ -0,0 +1,472 @@
+/*
+ * LED Flash class driver for the AAT1290
+ * 1.5A Step-Up Current Regulator for Flash LEDs
+ *
+ * Copyright (C) 2014, Samsung Electronics Co., Ltd.
+ * Author: Jacek Anaszewski 
+ *
+ * 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.
+ */
+



+#define AAT1290_MM_TO_FL_1_92  1
+#define AAT1290_MM_TO_FL_3_7   2
+#define AAT1290_MM_TO_FL_5_5   3
+#define AAT1290_MM_TO_FL_7_3   4
+#define AAT1290_MM_TO_FL_9 5
+#define AAT1290_MM_TO_FL_10_7  6
+#define AAT1290_MM_TO_FL_12_4  7
+#define AAT1290_MM_TO_FL_148
+#define AAT1290_MM_TO_FL_15_9  9
+#define AAT1290_MM_TO_FL_17_5  10
+#define AAT1290_MM_TO_FL_19_1  11
+#define AAT1290_MM_TO_FL_20_8  12
+#define AAT1290_MM_TO_FL_22_4  13
+#define AAT1290_MM_TO_FL_2414
+#define AAT1290_MM_TO_FL_25_6  15
+#define AAT1290_MM_TO_FL_OFF   16


Only one of these defines is unused.


The only cost of these macros are lines of code and I think
it is worth of having all the possible settings listed in one place.




+static struct of_device_id aat1290_led_dt_match[] = {



+   {.compatible = "skyworks,aat1290"},


spaces after { and before } ?


I see both styles in kernel, but ok, I will add spaces.

Regards,
Jacek

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH/RFC v8 12/14] leds: Add driver for AAT1290 current regulator

2014-11-29 Thread Pavel Machek
Hi!


> @@ -0,0 +1,472 @@
> +/*
> + *   LED Flash class driver for the AAT1290
> + *   1.5A Step-Up Current Regulator for Flash LEDs
> + *
> + *   Copyright (C) 2014, Samsung Electronics Co., Ltd.
> + *   Author: Jacek Anaszewski 
> + *
> + * 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.
> + */
> +

> +#define AAT1290_MM_TO_FL_1_921
> +#define AAT1290_MM_TO_FL_3_7 2
> +#define AAT1290_MM_TO_FL_5_5 3
> +#define AAT1290_MM_TO_FL_7_3 4
> +#define AAT1290_MM_TO_FL_9   5
> +#define AAT1290_MM_TO_FL_10_76
> +#define AAT1290_MM_TO_FL_12_47
> +#define AAT1290_MM_TO_FL_14  8
> +#define AAT1290_MM_TO_FL_15_99
> +#define AAT1290_MM_TO_FL_17_510
> +#define AAT1290_MM_TO_FL_19_111
> +#define AAT1290_MM_TO_FL_20_812
> +#define AAT1290_MM_TO_FL_22_413
> +#define AAT1290_MM_TO_FL_24  14
> +#define AAT1290_MM_TO_FL_25_615
> +#define AAT1290_MM_TO_FL_OFF 16

Only one of these defines is unused.

> +static struct of_device_id aat1290_led_dt_match[] = {

> + {.compatible = "skyworks,aat1290"},

spaces after { and before } ?

Otherwise looks ok, 

Signed-off-by: Pavel Machek 

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) 
http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH/RFC v8 12/14] leds: Add driver for AAT1290 current regulator

2014-11-28 Thread Jacek Anaszewski
This patch adds a driver for the 1.5A Step-Up
Current Regulator for Flash LEDs. The device is
programmed through a Skyworks proprietary AS2Cwire
serial digital interface.

Signed-off-by: Jacek Anaszewski 
Acked-by: Kyungmin Park 
Cc: Bryan Wu 
Cc: Richard Purdie 
---
 drivers/leds/Kconfig|7 +
 drivers/leds/Makefile   |1 +
 drivers/leds/leds-aat1290.c |  472 +++
 3 files changed, 480 insertions(+)
 create mode 100644 drivers/leds/leds-aat1290.c

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 2e66d55..ec4b78c 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -39,6 +39,13 @@ config LEDS_88PM860X
  This option enables support for on-chip LED drivers found on Marvell
  Semiconductor 88PM8606 PMIC.
 
+config LEDS_AAT1290
+   tristate "LED support for the AAT1290"
+   depends on LEDS_CLASS_FLASH
+   depends on OF
+   help
+This option enables support for the LEDs on the AAT1290.
+
 config LEDS_LM3530
tristate "LCD Backlight driver for LM3530"
depends on LEDS_CLASS
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 57ca62b..b802251 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -7,6 +7,7 @@ obj-$(CONFIG_LEDS_TRIGGERS) += led-triggers.o
 
 # LED Platform Drivers
 obj-$(CONFIG_LEDS_88PM860X)+= leds-88pm860x.o
+obj-$(CONFIG_LEDS_AAT1290) += leds-aat1290.o
 obj-$(CONFIG_LEDS_BD2802)  += leds-bd2802.o
 obj-$(CONFIG_LEDS_LOCOMO)  += leds-locomo.o
 obj-$(CONFIG_LEDS_LM3530)  += leds-lm3530.o
diff --git a/drivers/leds/leds-aat1290.c b/drivers/leds/leds-aat1290.c
new file mode 100644
index 000..2f8bd99
--- /dev/null
+++ b/drivers/leds/leds-aat1290.c
@@ -0,0 +1,472 @@
+/*
+ * LED Flash class driver for the AAT1290
+ * 1.5A Step-Up Current Regulator for Flash LEDs
+ *
+ * Copyright (C) 2014, Samsung Electronics Co., Ltd.
+ * Author: Jacek Anaszewski 
+ *
+ * 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define AAT1290_MOVIE_MODE_CURRENT_ADDR17
+#define AAT1290_FLASH_SAFETY_TIMER_ADDR18
+#define AAT1290_MOVIE_MODE_CONFIG_ADDR 19
+#define AAT1290_MM_CURRENT_RATIO_ADDR  20
+#define AAT1290_LATCH_TIME_US  500
+#define AAT1290_EN_SET_TICK_TIME_US1
+#define AAT1290_MOVIE_MODE_OFF 1
+#define AAT1290_MOVIE_MODE_ON  3
+#define AAT1290_MAX_MM_CURR_PERCENT_0  16
+#define AAT1290_MAX_MM_CURR_PERCENT_100 1
+#define AAT1290_FLASH_TM_NUM_LEVELS16
+
+#define AAT1290_MM_TO_FL_1_92  1
+#define AAT1290_MM_TO_FL_3_7   2
+#define AAT1290_MM_TO_FL_5_5   3
+#define AAT1290_MM_TO_FL_7_3   4
+#define AAT1290_MM_TO_FL_9 5
+#define AAT1290_MM_TO_FL_10_7  6
+#define AAT1290_MM_TO_FL_12_4  7
+#define AAT1290_MM_TO_FL_148
+#define AAT1290_MM_TO_FL_15_9  9
+#define AAT1290_MM_TO_FL_17_5  10
+#define AAT1290_MM_TO_FL_19_1  11
+#define AAT1290_MM_TO_FL_20_8  12
+#define AAT1290_MM_TO_FL_22_4  13
+#define AAT1290_MM_TO_FL_2414
+#define AAT1290_MM_TO_FL_25_6  15
+#define AAT1290_MM_TO_FL_OFF   16
+
+struct aat1290_led_settings {
+   struct led_flash_setting torch_brightness;
+   struct led_flash_setting flash_brightness;
+   struct led_flash_setting flash_timeout;
+};
+
+struct aat1290_led {
+   struct platform_device *pdev;
+   struct mutex lock;
+
+   struct led_classdev_flash ldev;
+   struct v4l2_flash *v4l2_flash;
+
+   int flen_gpio;
+   int en_set_gpio;
+
+   u32 max_flash_tm;
+   bool movie_mode;
+
+   char *label;
+   unsigned int torch_brightness;
+   unsigned int flash_timeout;
+   struct work_struct work_brightness_set;
+};
+
+static struct aat1290_led *ldev_to_led(struct led_classdev_flash *ldev)
+{
+   return container_of(ldev, struct aat1290_led, ldev);
+}
+
+static void aat1290_as2cwire_write(struct aat1290_led *led, int addr, int 
value)
+{
+   int i;
+
+   gpio_set_value(led->flen_gpio, 0);
+   gpio_set_value(led->en_set_gpio, 0);
+
+   udelay(10);
+
+   /* write address */
+   for (i = 0; i < addr; ++i) {
+   udelay(AAT1290_EN_SET_TICK_TIME_US);
+   gpio_set_value(led->en_set_gpio, 0);
+   udelay(AAT1290_EN_SET_TICK_TIME_US);
+   gpio_set_value(led->en_set_gpio, 1);
+   }
+
+   udelay(AAT1290_LATCH_TIME_US);
+
+   /* write data */
+   for (i = 0; i < value; ++i) {
+   udelay(AAT1290_EN_SET_TICK_TIME_US);
+   gpio_set_value(led->en_set_gpio, 0);
+   udelay(AAT1290_EN_SET_TICK_TIME_US);
+   gpio_set_value(led->en_set_gpio, 1);
+