Re: [patch 14/32] greybus: LED driver

2016-10-07 Thread Greg KH
On Fri, Oct 07, 2016 at 03:36:56PM +0200, Pavel Machek wrote:
> On Fri 2016-09-16 16:10:14, Greg KH wrote:
> > 
> > This driver implements the Greybus LED protocol.
> 
> I guess this should be copied to LED mainainters?

It will when it comes out of the staging directory.

> Havingstandartized phone hardware to work would be great. Is it
> possible to get device using this?

Yes, Motorolla ships a phone with this hardware in it.

thanks,

greg k-h


Re: [patch 14/32] greybus: LED driver

2016-10-07 Thread Greg KH
On Fri, Oct 07, 2016 at 03:36:56PM +0200, Pavel Machek wrote:
> On Fri 2016-09-16 16:10:14, Greg KH wrote:
> > 
> > This driver implements the Greybus LED protocol.
> 
> I guess this should be copied to LED mainainters?

It will when it comes out of the staging directory.

> Havingstandartized phone hardware to work would be great. Is it
> possible to get device using this?

Yes, Motorolla ships a phone with this hardware in it.

thanks,

greg k-h


Re: [patch 14/32] greybus: LED driver

2016-10-07 Thread Pavel Machek
On Fri 2016-09-16 16:10:14, Greg KH wrote:
> 
> This driver implements the Greybus LED protocol.

I guess this should be copied to LED mainainters?

Havingstandartized phone hardware to work would be great. Is it
possible to get device using this?
Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) 
http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


signature.asc
Description: Digital signature


Re: [patch 14/32] greybus: LED driver

2016-10-07 Thread Pavel Machek
On Fri 2016-09-16 16:10:14, Greg KH wrote:
> 
> This driver implements the Greybus LED protocol.

I guess this should be copied to LED mainainters?

Havingstandartized phone hardware to work would be great. Is it
possible to get device using this?
Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) 
http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


signature.asc
Description: Digital signature


[patch 14/32] greybus: LED driver

2016-09-16 Thread Greg KH

This driver implements the Greybus LED protocol.

Signed-off-by: Greg Kroah-Hartman 
---
 drivers/greybus/light.c | 1359 
 1 file changed, 1359 insertions(+)

--- /dev/null
+++ b/drivers/greybus/light.c
@@ -0,0 +1,1359 @@
+/*
+ * Greybus Lights protocol driver.
+ *
+ * Copyright 2015 Google Inc.
+ * Copyright 2015 Linaro Ltd.
+ *
+ * Released under the GPLv2 only.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "greybus.h"
+#include "greybus_protocols.h"
+
+#define NAMES_MAX  32
+
+struct gb_channel {
+   u8  id;
+   u32 flags;
+   u32 color;
+   char*color_name;
+   u8  fade_in;
+   u8  fade_out;
+   u32 mode;
+   char*mode_name;
+   struct attribute**attrs;
+   struct attribute_group  *attr_group;
+   const struct attribute_group**attr_groups;
+   struct led_classdev *led;
+#if IS_REACHABLE(CONFIG_LEDS_CLASS_FLASH)
+   struct led_classdev_flash   fled;
+   struct led_flash_settingintensity_uA;
+   struct led_flash_settingtimeout_us;
+#else
+   struct led_classdev cled;
+#endif
+   struct gb_light *light;
+   boolis_registered;
+   boolreleasing;
+   boolstrobe_state;
+   boolactive;
+   struct mutexlock;
+};
+
+struct gb_light {
+   u8  id;
+   char*name;
+   struct gb_lights*glights;
+   u32 flags;
+   u8  channels_count;
+   struct gb_channel   *channels;
+   boolhas_flash;
+   boolready;
+#if IS_REACHABLE(CONFIG_V4L2_FLASH_LED_CLASS)
+   struct v4l2_flash   *v4l2_flash;
+#endif
+};
+
+struct gb_lights {
+   struct gb_connection*connection;
+   u8  lights_count;
+   struct gb_light *lights;
+   struct mutexlights_lock;
+};
+
+static void gb_lights_channel_free(struct gb_channel *channel);
+
+static struct gb_connection *get_conn_from_channel(struct gb_channel *channel)
+{
+   return channel->light->glights->connection;
+}
+
+static struct gb_connection *get_conn_from_light(struct gb_light *light)
+{
+   return light->glights->connection;
+}
+
+static bool is_channel_flash(struct gb_channel *channel)
+{
+   return !!(channel->mode & (GB_CHANNEL_MODE_FLASH | GB_CHANNEL_MODE_TORCH
+  | GB_CHANNEL_MODE_INDICATOR));
+}
+
+#if IS_REACHABLE(CONFIG_LEDS_CLASS_FLASH)
+static struct gb_channel *get_channel_from_cdev(struct led_classdev *cdev)
+{
+   struct led_classdev_flash *fled_cdev = lcdev_to_flcdev(cdev);
+
+   return container_of(fled_cdev, struct gb_channel, fled);
+}
+
+static struct led_classdev *get_channel_cdev(struct gb_channel *channel)
+{
+   return >fled.led_cdev;
+}
+
+static struct gb_channel *get_channel_from_mode(struct gb_light *light,
+   u32 mode)
+{
+   struct gb_channel *channel = NULL;
+   int i;
+
+   for (i = 0; i < light->channels_count; i++) {
+   channel = >channels[i];
+   if (channel && channel->mode == mode)
+   break;
+   }
+   return channel;
+}
+
+static int __gb_lights_flash_intensity_set(struct gb_channel *channel,
+  u32 intensity)
+{
+   struct gb_connection *connection = get_conn_from_channel(channel);
+   struct gb_bundle *bundle = connection->bundle;
+   struct gb_lights_set_flash_intensity_request req;
+   int ret;
+
+   if (channel->releasing)
+   return -ESHUTDOWN;
+
+   ret = gb_pm_runtime_get_sync(bundle);
+   if (ret < 0)
+   return ret;
+
+   req.light_id = channel->light->id;
+   req.channel_id = channel->id;
+   req.intensity_uA = cpu_to_le32(intensity);
+
+   ret = gb_operation_sync(connection, GB_LIGHTS_TYPE_SET_FLASH_INTENSITY,
+   , sizeof(req), NULL, 0);
+
+   gb_pm_runtime_put_autosuspend(bundle);
+
+   return ret;
+}
+
+static int __gb_lights_flash_brightness_set(struct gb_channel *channel)
+{
+   u32 intensity;
+
+   /* If the channel is flash we need to get the attached torch channel */
+   if (channel->mode & GB_CHANNEL_MODE_FLASH)
+   channel = get_channel_from_mode(channel->light,
+   

[patch 14/32] greybus: LED driver

2016-09-16 Thread Greg KH

This driver implements the Greybus LED protocol.

Signed-off-by: Greg Kroah-Hartman 
---
 drivers/greybus/light.c | 1359 
 1 file changed, 1359 insertions(+)

--- /dev/null
+++ b/drivers/greybus/light.c
@@ -0,0 +1,1359 @@
+/*
+ * Greybus Lights protocol driver.
+ *
+ * Copyright 2015 Google Inc.
+ * Copyright 2015 Linaro Ltd.
+ *
+ * Released under the GPLv2 only.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "greybus.h"
+#include "greybus_protocols.h"
+
+#define NAMES_MAX  32
+
+struct gb_channel {
+   u8  id;
+   u32 flags;
+   u32 color;
+   char*color_name;
+   u8  fade_in;
+   u8  fade_out;
+   u32 mode;
+   char*mode_name;
+   struct attribute**attrs;
+   struct attribute_group  *attr_group;
+   const struct attribute_group**attr_groups;
+   struct led_classdev *led;
+#if IS_REACHABLE(CONFIG_LEDS_CLASS_FLASH)
+   struct led_classdev_flash   fled;
+   struct led_flash_settingintensity_uA;
+   struct led_flash_settingtimeout_us;
+#else
+   struct led_classdev cled;
+#endif
+   struct gb_light *light;
+   boolis_registered;
+   boolreleasing;
+   boolstrobe_state;
+   boolactive;
+   struct mutexlock;
+};
+
+struct gb_light {
+   u8  id;
+   char*name;
+   struct gb_lights*glights;
+   u32 flags;
+   u8  channels_count;
+   struct gb_channel   *channels;
+   boolhas_flash;
+   boolready;
+#if IS_REACHABLE(CONFIG_V4L2_FLASH_LED_CLASS)
+   struct v4l2_flash   *v4l2_flash;
+#endif
+};
+
+struct gb_lights {
+   struct gb_connection*connection;
+   u8  lights_count;
+   struct gb_light *lights;
+   struct mutexlights_lock;
+};
+
+static void gb_lights_channel_free(struct gb_channel *channel);
+
+static struct gb_connection *get_conn_from_channel(struct gb_channel *channel)
+{
+   return channel->light->glights->connection;
+}
+
+static struct gb_connection *get_conn_from_light(struct gb_light *light)
+{
+   return light->glights->connection;
+}
+
+static bool is_channel_flash(struct gb_channel *channel)
+{
+   return !!(channel->mode & (GB_CHANNEL_MODE_FLASH | GB_CHANNEL_MODE_TORCH
+  | GB_CHANNEL_MODE_INDICATOR));
+}
+
+#if IS_REACHABLE(CONFIG_LEDS_CLASS_FLASH)
+static struct gb_channel *get_channel_from_cdev(struct led_classdev *cdev)
+{
+   struct led_classdev_flash *fled_cdev = lcdev_to_flcdev(cdev);
+
+   return container_of(fled_cdev, struct gb_channel, fled);
+}
+
+static struct led_classdev *get_channel_cdev(struct gb_channel *channel)
+{
+   return >fled.led_cdev;
+}
+
+static struct gb_channel *get_channel_from_mode(struct gb_light *light,
+   u32 mode)
+{
+   struct gb_channel *channel = NULL;
+   int i;
+
+   for (i = 0; i < light->channels_count; i++) {
+   channel = >channels[i];
+   if (channel && channel->mode == mode)
+   break;
+   }
+   return channel;
+}
+
+static int __gb_lights_flash_intensity_set(struct gb_channel *channel,
+  u32 intensity)
+{
+   struct gb_connection *connection = get_conn_from_channel(channel);
+   struct gb_bundle *bundle = connection->bundle;
+   struct gb_lights_set_flash_intensity_request req;
+   int ret;
+
+   if (channel->releasing)
+   return -ESHUTDOWN;
+
+   ret = gb_pm_runtime_get_sync(bundle);
+   if (ret < 0)
+   return ret;
+
+   req.light_id = channel->light->id;
+   req.channel_id = channel->id;
+   req.intensity_uA = cpu_to_le32(intensity);
+
+   ret = gb_operation_sync(connection, GB_LIGHTS_TYPE_SET_FLASH_INTENSITY,
+   , sizeof(req), NULL, 0);
+
+   gb_pm_runtime_put_autosuspend(bundle);
+
+   return ret;
+}
+
+static int __gb_lights_flash_brightness_set(struct gb_channel *channel)
+{
+   u32 intensity;
+
+   /* If the channel is flash we need to get the attached torch channel */
+   if (channel->mode & GB_CHANNEL_MODE_FLASH)
+   channel = get_channel_from_mode(channel->light,
+   GB_CHANNEL_MODE_TORCH);
+
+   /* For not