V4L2 API for flash devices and the adp1653 flash controller driver
Subsystems (2)
v2 cover V4L2 API for flash devices and the adp1653 flash controller driver
Hi,
This patchset implements RFC v4 of V4L2 API for flash devices [1], with minor modifications, and adds the adp1653 flash controller driver. There have been changes since v1 [2] of this patchset:
- Faults on the flash LED are allowed to make the LED unusable before the faults are read. This is implemented in the adp1653 driver.
- Intensities are using standard units; mA for flash / torch and uA for the indicator.
Thanks to those who have given their feedback so far in the process!
[1] http://www.spinics.net/lists/linux-media/msg32030.html
[2] http://www.spinics.net/lists/linux-media/msg32396.html
Cheers,
Signature · 2 lines
Sakari Ailus [email protected]
RFC v2 1/3 v4l: Add a class and a set of controls for flash devices.
From: Sakari Ailus <[email protected]>
Add a control class and a set of controls to support LED and Xenon flash devices. An example of such a device is the adp1653.
--- drivers/media/video/v4l2-ctrls.c | 45 ++++++++++++++++++++++++++++++++++++++ include/linux/videodev2.h | 36 ++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 0 deletions(-)
drivers/media/video/v4l2-ctrls.c +45 -0
@@ -216,6 +216,17 @@ const char * const *v4l2_ctrl_get_menu(u32 id)"75 useconds" , NULL, }; +static const char *const flash_led_mode[] = { +"Off" , +"Flash" , +"Torch" , +NULL , + }; +static const char *const flash_strobe_source[] = { +"Software" , +"External" , +NULL , + };switch (id) {case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ :
@@ -256,6 +267,10 @@ const char * const *v4l2_ctrl_get_menu(u32 id)return colorfx;case V4L2_CID_TUNE_PREEMPHASIS :return tune_preemphasis; +case V4L2_CID_FLASH_LED_MODE : +return flash_led_mode; +case V4L2_CID_FLASH_STROBE_SOURCE : +return flash_strobe_source;default :return NULL ; }
@@ -389,6 +404,21 @@ const char *v4l2_ctrl_get_name(u32 id)case V4L2_CID_TUNE_POWER_LEVEL :return "Tune Power Level" ;case V4L2_CID_TUNE_ANTENNA_CAPACITOR :return "Tune Antenna Capacitor" ; +/* Flash controls */ +case V4L2_CID_FLASH_CLASS :return "Flash controls" ; +case V4L2_CID_FLASH_LED_MODE :return "LED mode" ; +case V4L2_CID_FLASH_STROBE_SOURCE :return "Strobe source" ; +case V4L2_CID_FLASH_STROBE :return "Strobe" ; +case V4L2_CID_FLASH_STROBE_STOP :return "Stop strobe" ; +case V4L2_CID_FLASH_STROBE_STATUS :return "Strobe status" ; +case V4L2_CID_FLASH_TIMEOUT :return "Strobe timeout" ; +case V4L2_CID_FLASH_INTENSITY :return "Intensity, flash mode" ; +case V4L2_CID_FLASH_TORCH_INTENSITY :return "Intensity, torch mode" ; +case V4L2_CID_FLASH_INDICATOR_INTENSITY :return "Intensity, indicator" ; +case V4L2_CID_FLASH_FAULT :return "Faults" ; +case V4L2_CID_FLASH_CHARGE :return "Charge" ; +case V4L2_CID_FLASH_READY :return "Ready to strobe" ; +default :return NULL ; }
@@ -423,12 +453,17 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,case V4L2_CID_PILOT_TONE_ENABLED :case V4L2_CID_ILLUMINATORS_1 :case V4L2_CID_ILLUMINATORS_2 : +case V4L2_CID_FLASH_STROBE_STATUS : +case V4L2_CID_FLASH_CHARGE : +case V4L2_CID_FLASH_READY : *type =V4L2_CTRL_TYPE_BOOLEAN ; *min =0 ; *max = *step =1 ;break ;case V4L2_CID_PAN_RESET :case V4L2_CID_TILT_RESET : +case V4L2_CID_FLASH_STROBE : +case V4L2_CID_FLASH_STROBE_STOP : *type =V4L2_CTRL_TYPE_BUTTON ; *flags |=V4L2_CTRL_FLAG_WRITE_ONLY ; *min = *max = *step = *def =0 ;
@@ -452,6 +487,8 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,case V4L2_CID_EXPOSURE_AUTO :case V4L2_CID_COLORFX :case V4L2_CID_TUNE_PREEMPHASIS : +case V4L2_CID_FLASH_LED_MODE : +case V4L2_CID_FLASH_STROBE_SOURCE : *type =V4L2_CTRL_TYPE_MENU ;break ;case V4L2_CID_RDS_TX_PS_NAME :
@@ -462,6 +499,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,case V4L2_CID_CAMERA_CLASS :case V4L2_CID_MPEG_CLASS :case V4L2_CID_FM_TX_CLASS : +case V4L2_CID_FLASH_CLASS : *type =V4L2_CTRL_TYPE_CTRL_CLASS ;/* You can neither read not write these */ *flags |=V4L2_CTRL_FLAG_READ_ONLY |V4L2_CTRL_FLAG_WRITE_ONLY ;
@@ -474,6 +512,9 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,/* Max is calculated as RGB888 that is 2^24 */ *max =0xFFFFFF ;break ; +case V4L2_CID_FLASH_FAULT : + *type =V4L2_CTRL_TYPE_BITMASK ; +break ;default : *type =V4L2_CTRL_TYPE_INTEGER ;break ;
@@ -519,6 +560,10 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,case V4L2_CID_ZOOM_RELATIVE : *flags |=V4L2_CTRL_FLAG_WRITE_ONLY ;break ; +case V4L2_CID_FLASH_STROBE_STATUS : +case V4L2_CID_FLASH_READY : + *flags |=V4L2_CTRL_FLAG_READ_ONLY ; +break ; } }EXPORT_SYMBOL (v4l2_ctrl_fill);
include/linux/videodev2.h +36 -0
@@ -1022,6 +1022,7 @@ struct v4l2_ext_controls {#define V4L2_CTRL_CLASS_MPEG 0x00990000/* MPEG-compression controls */ #define V4L2_CTRL_CLASS_CAMERA 0x009a0000/* Camera class controls */ #define V4L2_CTRL_CLASS_FM_TX 0x009b0000/* FM Modulator control class */ +#define V4L2_CTRL_CLASS_FLASH 0x009c0000/* Camera flash controls */ #define V4L2_CTRL_ID_MASK (0x0fffffff)#define V4L2_CTRL_ID2CLASS (id) ((id) & 0x0fff0000UL)
@@ -1423,6 +1424,41 @@ enum v4l2_preemphasis {#define V4L2_CID_TUNE_POWER_LEVEL (V4L2_CID_FM_TX_CLASS_BASE + 113)#define V4L2_CID_TUNE_ANTENNA_CAPACITOR (V4L2_CID_FM_TX_CLASS_BASE + 114) +/* Flash and privacy (indicator) light controls */ +#define V4L2_CID_FLASH_CLASS_BASE (V4L2_CTRL_CLASS_FLASH | 0x900) +#define V4L2_CID_FLASH_CLASS (V4L2_CTRL_CLASS_FLASH | 1) + +#define V4L2_CID_FLASH_LED_MODE (V4L2_CID_FLASH_CLASS_BASE + 1) +enum v4l2_flash_led_mode { +V4L2_FLASH_LED_MODE_NONE , +V4L2_FLASH_LED_MODE_FLASH , +V4L2_FLASH_LED_MODE_TORCH , +}; + +#define V4L2_CID_FLASH_STROBE_SOURCE (V4L2_CID_FLASH_CLASS_BASE + 2) +enum v4l2_flash_strobe_source { +V4L2_FLASH_STROBE_SOURCE_SOFTWARE , +V4L2_FLASH_STROBE_SOURCE_EXTERNAL , +}; + +#define V4L2_CID_FLASH_STROBE (V4L2_CID_FLASH_CLASS_BASE + 3) +#define V4L2_CID_FLASH_STROBE_STOP (V4L2_CID_FLASH_CLASS_BASE + 4) +#define V4L2_CID_FLASH_STROBE_STATUS (V4L2_CID_FLASH_CLASS_BASE + 5) + +#define V4L2_CID_FLASH_TIMEOUT (V4L2_CID_FLASH_CLASS_BASE + 6) +#define V4L2_CID_FLASH_INTENSITY (V4L2_CID_FLASH_CLASS_BASE + 7) +#define V4L2_CID_FLASH_TORCH_INTENSITY (V4L2_CID_FLASH_CLASS_BASE + 8) +#define V4L2_CID_FLASH_INDICATOR_INTENSITY (V4L2_CID_FLASH_CLASS_BASE + 9) + +#define V4L2_CID_FLASH_FAULT (V4L2_CID_FLASH_CLASS_BASE + 10) +#define V4L2_FLASH_FAULT_OVER_VOLTAGE (1 << 0) +#define V4L2_FLASH_FAULT_TIMEOUT (1 << 1) +#define V4L2_FLASH_FAULT_OVER_TEMPERATURE (1 << 2) +#define V4L2_FLASH_FAULT_SHORT_CIRCUIT (1 << 3) + +#define V4L2_CID_FLASH_CHARGE (V4L2_CID_FLASH_CLASS_BASE + 11) +#define V4L2_CID_FLASH_READY (V4L2_CID_FLASH_CLASS_BASE + 12) +/* * T U N I N G */
Signature · 1 line
1.7.2.5
RFC v2 2/3 v4l: Add flash control documentation
In reply to Sakari AilusAdd documentation for V4L2 flash controls.
--- Documentation/DocBook/v4l/controls.xml | 221 ++++++++++++++++++++++ Documentation/DocBook/v4l/vidioc-g-ext-ctrls.xml | 7 + 2 files changed, 228 insertions(+), 0 deletions(-)
Documentation/DocBook/v4l/controls.xml +221 -0
@@ -2092,6 +2092,227 @@ manually or automatically if set to zero. Unit, range and step are driver-specif <para>For more details about RDS specification, refer to <xref linkend="en50067" /> document, from CENELEC.</para> </section> + + <section id="flash-controls"> + <title>Flash Control Reference</title> + + <para> + The V4L2 flash controls are intended to provide generic access + to flash controller devices. Flash controller devices are + typically used in digital cameras. + </para> + + <para> + The interface can support both LED and xenon flash devices. + </para> + + <table pgwide="1" frame="none" id="flash-control-id"> + <title>Flash Control IDs</title> + + <tgroup cols="4"> + <colspec colname="c1" colwidth="1*" /> + <colspec colname="c2" colwidth="6*" /> + <colspec colname="c3" colwidth="2*" /> + <colspec colname="c4" colwidth="6*" /> + <spanspec namest="c1" nameend="c2" spanname="id" /> + <spanspec namest="c2" nameend="c4" spanname="descr" /> + <thead> + <row> + <entry spanname="id" align="left">ID</entry> + <entry align="left">Type</entry> + </row><row rowsep="1"><entry spanname="descr" align="left">Description</entry> + </row> + </thead> + <tbody valign="top"> + <row><entry></entry></row> + <row> + <entry spanname="id"><constant>V4L2_CID_FLASH_CLASS</constant></entry> + <entry>class</entry> + </row> + <row> + <entry spanname="descr">The FLASH class descriptor.</entry> + </row> + <row> + <entry spanname="id"><constant>V4L2_CID_FLASH_LED_MODE</constant></entry> + <entry>menu</entry> + </row> + <row> + <entry spanname="descr">Defines the mode of the flash LED, + the high-power white LED attached to the flash + controller.</entry> + </row> + <row> + <entrytbl spanname="descr" cols="2"> + <tbody valign="top"> + <row> + <entry><constant>V4L2_FLASH_LED_MODE_NONE</constant></entry> + <entry>Off.</entry> + </row> + <row> + <entry><constant>V4L2_FLASH_LED_MODE_FLASH</constant></entry> + <entry>Flash mode.</entry> + </row> + <row> + <entry><constant>V4L2_FLASH_LED_MODE_TORCH</constant></entry> + <entry>Torch mode. See V4L2_CID_FLASH_TORCH_INTENSITY.</entry> + </row> + </tbody> + </entrytbl> + </row> + <row> + <entry spanname="id"><constant>V4L2_CID_FLASH_STROBE_SOURCE</constant></entry> + <entry>menu</entry> + </row> + <row><entry spanname="descr">Defines the mode of the + flash LED strobe.</entry> + </row> + <row> + <entrytbl spanname="descr" cols="2"> + <tbody valign="top"> + <row> + <entry><constant>V4L2_FLASH_STROBE_SOURCE_SOFTWARE</constant></entry> + <entry>The flash strobe is triggered by using + the V4L2_CID_FLASH_STROBE control.</entry> + </row> + <row> + <entry><constant>V4L2_FLASH_STROBE_SOURCE_EXTERNAL</constant></entry> + <entry>The flash strobe is triggered by an + external source. Typically this is a sensor, + which makes it possible to synchronises the + flash strobe start to exposure start.</entry> + </row> + </tbody> + </entrytbl> + </row> + <row> + <entry spanname="id"><constant>V4L2_CID_FLASH_STROBE</constant></entry> + <entry>button</entry> + </row> + <row> + <entry spanname="descr">Strobe flash. Valid when + V4L2_CID_FLASH_LED_MODE is set to + V4L2_FLASH_LED_MODE_FLASH and V4L2_CID_FLASH_STROBE_SOURCE + is set to V4L2_FLASH_STROBE_SOURCE_SOFTWARE.</entry> + </row> + <row> + <entry spanname="id"><constant>V4L2_CID_FLASH_STROBE_STOP</constant></entry> + <entry>button</entry> + </row> + <row><entry spanname="descr">Stop flash strobe immediately.</entry> + </row> + <row> + <entry spanname="id"><constant>V4L2_CID_FLASH_STROBE_STATUS</constant></entry> + <entry>boolean</entry> + </row> + <row> + <entry spanname="descr">Strobe status: whether the flash + is strobing at the moment or not. This is a read-only + control.</entry> + </row> + <row> + <entry spanname="id"><constant>V4L2_CID_FLASH_TIMEOUT</constant></entry> + <entry>integer</entry> + </row> + <row> + <entry spanname="descr">Hardware timeout for flash. The + flash strobe is stopped after this period of time has + passed from the start of the strobe.</entry> + </row> + <row> + <entry spanname="id"><constant>V4L2_CID_FLASH_INTENSITY</constant></entry> + <entry>integer</entry> + </row> + <row> + <entry spanname="descr">Intensity of the flash strobe when + the flash LED is in flash mode + (V4L2_FLASH_LED_MODE_FLASH). The unit should be milliamps + (mA) if possible.</entry> + </row> + <row> + <entry spanname="id"><constant>V4L2_CID_FLASH_TORCH_INTENSITY</constant></entry> + <entry>integer</entry> + </row> + <row> + <entry spanname="descr">Intensity of the flash LED in + torch mode (V4L2_FLASH_LED_MODE_TORCH). The unit should be + milliamps (mA) if possible.</entry> + </row> + <row> + <entry spanname="id"><constant>V4L2_CID_FLASH_INDICATOR_INTENSITY</constant></entry> + <entry>integer</entry> + </row> + <row> + <entry spanname="descr">Intensity of the indicator LED. + The indicator LED may be fully independent of the flash + LED. The unit should be microamps (uA) if possible.</entry> + </row> + <row> + <entry spanname="id"><constant>V4L2_CID_FLASH_FAULT</constant></entry> + <entry>bitmask</entry> + </row> + <row> + <entry spanname="descr">Faults related to the flash. The + faults tell about specific problems in the flash chip + itself or the LEDs attached to it. Faults related to the + flash LED may set the V4L2_CID_FLASH_LED_MODE to + V4L2_FLASH_LED_MODE_NONE, and prevent further use of the + LED before reading the faults. Exactly which faults have + such an effect is chip dependent.</entry> + + </row> + <row> + <entrytbl spanname="descr" cols="2"> + <tbody valign="top"> + <row> + <entry><constant>V4L2_FLASH_FAULT_OVER_VOLTAGE</constant></entry> + <entry>Flash controller voltage to the flash LED + has exceeded the limit specific to the flash + controller.</entry> + </row> + <row> + <entry><constant>V4L2_FLASH_FAULT_TIMEOUT</constant></entry> + <entry>The flash strobe was still on when + the timeout set by the user --- + V4L2_CID_FLASH_TIMEOUT control --- has expired. + Not all flash controllers may set this in all + such conditions.</entry> + </row> + <row> + <entry><constant>V4L2_FLASH_FAULT_OVER_TEMPERATURE</constant></entry> + <entry>The flash controller has overheated.</entry> + </row> + <row> + <entry><constant>V4L2_FLASH_FAULT_SHORT_CIRCUIT</constant></entry> + <entry>The short circuit protection of the flash + controller has been triggered.</entry> + </row> + </tbody> + </entrytbl> + </row> + <row> + <entry spanname="id"><constant>V4L2_CID_FLASH_CHARGE</constant></entry> + <entry>boolean</entry> + </row> + <row><entry spanname="descr">Enable or disable charging of the xenon + flash capacitor.</entry> + </row> + <row> + <entry spanname="id"><constant>V4L2_CID_FLASH_READY</constant></entry> + <entry>boolean</entry> + </row> + <row> + <entry spanname="descr">Is the flash ready to strobe? + Xenon flashes require their capacitors charged before + strobing. LED flashes often require a cooldown period + after strobe during which another strobe will not be + possible. This is a read-only control.</entry> + </row> + <row><entry></entry></row> + </tbody> + </tgroup> + </table> + + </section> </section> <!--
Documentation/DocBook/v4l/vidioc-g-ext-ctrls.xml +7 -0
@@ -250,6 +250,13 @@ These controls are described in <xref These controls are described in <xref linkend="fm-tx-controls" />.</entry> </row> + <row> + <entry><constant>V4L2_CTRL_CLASS_FLASH</constant></entry> + <entry>0x9c0000</entry> + <entry>The class containing flash device controls. +These controls are described in <xref + linkend="flash-controls" />.</entry> + </row> </tbody> </tgroup> </table>
Signature · 1 line
1.7.2.5
RFC v2 3/3 adp1653: Add driver for LED flash controller
In reply to Sakari AilusThis patch adds the driver for the adp1653 LED flash controller. This controller supports a high power led in flash and torch modes and an indicator light, sometimes also called privacy light.
The adp1653 is used on the Nokia N900.
--- drivers/media/video/Kconfig | 7 + drivers/media/video/Makefile | 2 + drivers/media/video/adp1653.c | 485 +++++++++++++++++++++++++++++++++++++++++ include/media/adp1653.h | 126 +++++++++++ 4 files changed, 620 insertions(+), 0 deletions(-) create mode 100644 drivers/media/video/adp1653.c create mode 100644 include/media/adp1653.h
drivers/media/video/Kconfig +7 -0
@@ -344,6 +344,13 @@ config VIDEO_TCM825X This is a driver for the Toshiba TCM825x VGA camera sensor. It is used for example in Nokia N800. +config VIDEO_ADP1653 + tristate "ADP1653 flash support" + depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER + ---help--- + This is a driver for the ADP1653 flash controller. It is used for + example in Nokia N900. + config VIDEO_SAA7110 tristate "Philips SAA7110 video decoder" depends on VIDEO_V4L2 && I2C
drivers/media/video/Makefile +2 -0
@@ -131,6 +131,8 @@ obj-$(CONFIG_VIDEO_VIA_CAMERA) += via-camera.o obj-$(CONFIG_VIDEO_OMAP3) += omap3isp/ +obj-$(CONFIG_VIDEO_ADP1653) += adp1653.o + obj-$(CONFIG_USB_ZR364XX) += zr364xx.o obj-$(CONFIG_USB_STKWEBCAM) += stkwebcam.o
drivers/media/video/adp1653.c new file +485 -0
485 lines not on this page · raw message
include/media/adp1653.h new file +126 -0
126 lines not on this page · raw message
Signature · 1 line
1.7.2.5
Re: [RFC v2 3/3] adp1653: Add driver for LED flash controller
Hi Sakari,
Quoted 5 lines · On Tuesday 17 May 2011 17:14:04 Sakari Ailus wrote:
This patch adds the driver for the adp1653 LED flash controller. This controller supports a high power led in flash and torch modes and an indicator light, sometimes also called privacy light.
The adp1653 is used on the Nokia N900.
[snip]
Quoted 5 lines
drivers/media/video/adp1653.c new file +0
-0
[snip]
Quoted 9 lines
drivers/media/video/adp1653.c new file +9
-0+static int adp1653_get_fault (struct adp1653_flash *flash) +{ +struct i2c_client *client =v4l2_get_subdevdata (&flash->subdev); +int fault; +int rval; + + fault =i2c_smbus_read_byte_data (client,ADP1653_REG_FAULT ); +if (IS_ERR_VALUE (fault)) +return fault;
drivers/media/video/adp1653.c line 67
Quoted 10 lines
drivers/media/video/adp1653.c new file +10
-0+ + flash->fault |= fault; + +if (!flash->fault) +return 0 ; + +/* Clear faults. */ + rval =i2c_smbus_write_byte_data (client,ADP1653_REG_OUT_SEL ,0 ); +if (IS_ERR_VALUE (rval)) +return rval;
Should the faults be cleared right away, instead of when the user reads the faults control ?
drivers/media/video/adp1653.c line 69
Quoted 1 line
drivers/media/video/adp1653.c new file +1
-0+ flash->led_mode->val =V4L2_FLASH_LED_MODE_NONE ;
Does the hardware switch back to "none" mode when a fault occurs ? The datasheet just states that "the ADP1653 is disabled". Does that mean temporarily disabled until the faults are cleared ? If so you should update the registers to turn the LED off.
Quoted 2 lines
drivers/media/video/adp1653.c new file +2
-0+return flash->fault; +}
[snip]
drivers/media/video/adp1653.c line 154
Quoted 7 lines
drivers/media/video/adp1653.c new file +7
-0+static int adp1653_get_ctrl (struct v4l2_ctrl *ctrl) +{ +struct adp1653_flash *flash = + container_of(ctrl->handler, struct adp1653_flash, ctrls); + +adp1653_get_fault (flash); +if (IS_ERR_VALUE (flash->fault))
Shouldn't you check the adp1653_get_fault() return value instead ?
Quoted 17 lines
drivers/media/video/adp1653.c new file +17
-0+return flash->fault; + + ctrl->cur.val =0 ; + +if (flash->fault &ADP1653_REG_FAULT_FLT_SCP ) + ctrl->cur.val |=V4L2_FLASH_FAULT_SHORT_CIRCUIT ; +if (flash->fault &ADP1653_REG_FAULT_FLT_OT ) + ctrl->cur.val |=V4L2_FLASH_FAULT_OVER_TEMPERATURE ; +if (flash->fault &ADP1653_REG_FAULT_FLT_TMR ) + ctrl->cur.val |=V4L2_FLASH_FAULT_TIMEOUT ; +if (flash->fault &ADP1653_REG_FAULT_FLT_OV ) + ctrl->cur.val |=V4L2_FLASH_FAULT_OVER_VOLTAGE ; + + flash->fault =0 ; + +return 0 ; +}
[snip]
drivers/media/video/adp1653.c line 267
Quoted 6 lines
drivers/media/video/adp1653.c new file +6
-0+static int +adp1653_registered (struct v4l2_subdev *subdev) +{ +struct adp1653_flash *flash =to_adp1653_flash (subdev); + +return adp1653_init_controls (flash);
Can't this be moved to adp1653_probe() ? You could then get rid of the registered callback.
Quoted 14 lines
drivers/media/video/adp1653.c new file +14
-0+} + +static int +adp1653_init_device (struct adp1653_flash *flash) +{ +struct i2c_client *client =v4l2_get_subdevdata (&flash->subdev); +int rval; + +/* Clear FAULT register by writing zero to OUT_SEL */ + rval =i2c_smbus_write_byte_data (client,ADP1653_REG_OUT_SEL ,0 ); +if (rval <0 ) { +dev_err (&client->dev,"failed writing fault register\n" ); +return -EIO ; + }
drivers/media/video/adp1653.c line 291
Quoted 10 lines
drivers/media/video/adp1653.c new file +10
-0+ +/* Read FAULT register */ + rval =i2c_smbus_read_byte_data (client,ADP1653_REG_FAULT ); +if (rval <0 ) { +dev_err (&client->dev,"failed reading fault register\n" ); +return -EIO ; + } + +if ((rval &0x0f ) !=0 ) { +dev_err (&client->dev,"device fault\n" );
Same comment as last time :-)
Quoted 14 lines
drivers/media/video/adp1653.c new file +14
-0+return -EIO ; + } + +mutex_lock (&flash->ctrls.lock); + rval =adp1653_update_hw (flash); +mutex_unlock (&flash->ctrls.lock); +if (rval) { +dev_err (&client->dev, +"adp1653_update_hw failed at %s\n" , __func__); +return -EIO ; + } + +return 0 ; +}
[snip]
Signature · 3 lines
Regards, Laurent Pinchart
Re: [RFC v2 3/3] adp1653: Add driver for LED flash controller
Quoted 1 line · Laurent Pinchart
Hi Sakari,
Hi Laurent,
Quoted 40 lines · On Tuesday 17 May 2011 17:14:04 Sakari Ailus wrote:
Quoted 5 lines
This patch adds the driver for the adp1653 LED flash controller. This controller supports a high power led in flash and torch modes and an indicator light, sometimes also called privacy light.
The adp1653 is used on the Nokia N900.
[snip]
Quoted 5 lines
drivers/media/video/adp1653.c new file +0
-0[snip]
Quoted 9 lines
drivers/media/video/adp1653.c new file +9
-0+static int adp1653_get_fault (struct adp1653_flash *flash) +{ +struct i2c_client *client =v4l2_get_subdevdata (&flash->subdev); +int fault; +int rval; + + fault =i2c_smbus_read_byte_data (client,ADP1653_REG_FAULT ); +if (IS_ERR_VALUE (fault)) +return fault;drivers/media/video/adp1653.c line 67
Quoted 10 lines
drivers/media/video/adp1653.c new file +10
-0+ + flash->fault |= fault; + +if (!flash->fault) +return 0 ; + +/* Clear faults. */ + rval =i2c_smbus_write_byte_data (client,ADP1653_REG_OUT_SEL ,0 ); +if (IS_ERR_VALUE (rval)) +return rval;Should the faults be cleared right away, instead of when the user reads the faults control ?
Quoted 6 lines
drivers/media/video/adp1653.c line 69
Quoted 1 line
drivers/media/video/adp1653.c new file +1
-0+ flash->led_mode->val =V4L2_FLASH_LED_MODE_NONE ;Does the hardware switch back to "none" mode when a fault occurs ? The datasheet just states that "the ADP1653 is disabled". Does that mean temporarily disabled until the faults are cleared ? If so you should update the registers to turn the LED off.
My understanding is that this is temporary until the faults are cleared. However, this is difficult to find out since the faults don't just occur that easily.
OUT_SEL register controls the current to LEDs so this turned everything off. The indicator should still remain on, I guess, since it's not affected by the faults, except possibly the over-temperature one.
Quoted 5 lines
Quoted 2 lines
drivers/media/video/adp1653.c new file +2
-0+return flash->fault; +}[snip]
Quoted 9 lines
drivers/media/video/adp1653.c line 154
Quoted 7 lines
drivers/media/video/adp1653.c new file +7
-0+static int adp1653_get_ctrl (struct v4l2_ctrl *ctrl) +{ +struct adp1653_flash *flash = + container_of(ctrl->handler, struct adp1653_flash, ctrls); + +adp1653_get_fault (flash); +if (IS_ERR_VALUE (flash->fault))Shouldn't you check the
adp1653_get_fault()return value instead ?
Yes. Good catch. I've tried to simulate this code a bit but as always, error handling tends not to be one of the best parts of the driver, especially those errors that generally do not happen. :-I
Quoted 20 lines
Quoted 17 lines
drivers/media/video/adp1653.c new file +17
-0+return flash->fault; + + ctrl->cur.val =0 ; + +if (flash->fault &ADP1653_REG_FAULT_FLT_SCP ) + ctrl->cur.val |=V4L2_FLASH_FAULT_SHORT_CIRCUIT ; +if (flash->fault &ADP1653_REG_FAULT_FLT_OT ) + ctrl->cur.val |=V4L2_FLASH_FAULT_OVER_TEMPERATURE ; +if (flash->fault &ADP1653_REG_FAULT_FLT_TMR ) + ctrl->cur.val |=V4L2_FLASH_FAULT_TIMEOUT ; +if (flash->fault &ADP1653_REG_FAULT_FLT_OV ) + ctrl->cur.val |=V4L2_FLASH_FAULT_OVER_VOLTAGE ; + + flash->fault =0 ; + +return 0 ; +}[snip]
Quoted 9 lines
drivers/media/video/adp1653.c line 267
Quoted 6 lines
drivers/media/video/adp1653.c new file +6
-0+static int +adp1653_registered (struct v4l2_subdev *subdev) +{ +struct adp1653_flash *flash =to_adp1653_flash (subdev); + +return adp1653_init_controls (flash);Can't this be moved to
adp1653_probe()? You could then get rid of the registered callback.
Good point. I'll look into this.
Quoted 18 lines
Quoted 18 lines
drivers/media/video/adp1653.c new file +18
-0+} + +static int +adp1653_init_device (struct adp1653_flash *flash) +{ +struct i2c_client *client =v4l2_get_subdevdata (&flash->subdev); +int rval; + +/* Clear FAULT register by writing zero to OUT_SEL */ + rval =i2c_smbus_write_byte_data (client,ADP1653_REG_OUT_SEL ,0 ); +if (rval <0 ) { +dev_err (&client->dev,"failed writing fault register\n" ); +return -EIO ; + } + +/* Read FAULT register */ + rval =i2c_smbus_read_byte_data (client,ADP1653_REG_FAULT ); +if (rval <0 ) {
Quoted 8 lines
drivers/media/video/adp1653.c line 291
Quoted 6 lines
drivers/media/video/adp1653.c new file +6
-0+dev_err (&client->dev,"failed reading fault register\n" ); +return -EIO ; + } + +if ((rval &0x0f ) !=0 ) { +dev_err (&client->dev,"device fault\n" );Same comment as last time :-)
Ouch. I'll try to get the fix done for the next time. :-)
Many thanks for the comments.
Regards,
Signature · 2 lines
Sakari Ailus sakari dot ailus at iki dot fi
Re: [RFC v2 3/3] adp1653: Add driver for LED flash controller
Hi Sakari,
Quoted 48 lines · On Wednesday 18 May 2011 13:29:56 Sakari Ailus wrote:
Quoted 40 lines · Laurent Pinchart
Quoted 5 lines · On Tuesday 17 May 2011 17:14:04 Sakari Ailus wrote:
This patch adds the driver for the adp1653 LED flash controller. This controller supports a high power led in flash and torch modes and an indicator light, sometimes also called privacy light.
The adp1653 is used on the Nokia N900.
[snip]
Quoted 5 lines
(quoted diff) +0
-0
b/drivers/media/video/adp1653.cnew file mode 100644 index 0000000..1679707drivers/media/video/adp1653.c new file +0
-0[snip]
Quoted 9 lines
drivers/media/video/adp1653.c new file +9
-0+static int adp1653_get_fault (struct adp1653_flash *flash) +{ +struct i2c_client *client =v4l2_get_subdevdata (&flash->subdev); +int fault; +int rval; + + fault =i2c_smbus_read_byte_data (client,ADP1653_REG_FAULT ); +if (IS_ERR_VALUE (fault)) +return fault;drivers/media/video/adp1653.c line 67
Quoted 10 lines
drivers/media/video/adp1653.c new file +10
-0+ + flash->fault |= fault; + +if (!flash->fault) +return 0 ; + +/* Clear faults. */ + rval =i2c_smbus_write_byte_data (client,ADP1653_REG_OUT_SEL ,0 ); +if (IS_ERR_VALUE (rval)) +return rval;Should the faults be cleared right away, instead of when the user reads the faults control ?
Quoted 6 lines
drivers/media/video/adp1653.c line 69
Quoted 1 line
drivers/media/video/adp1653.c new file +1
-0+ flash->led_mode->val =V4L2_FLASH_LED_MODE_NONE ;Does the hardware switch back to "none" mode when a fault occurs ? The datasheet just states that "the ADP1653 is disabled". Does that mean temporarily disabled until the faults are cleared ? If so you should update the registers to turn the LED off.
Quoted 7 lines
My understanding is that this is temporary until the faults are cleared. However, this is difficult to find out since the faults don't just occur that easily.
OUT_SELregister controls the current to LEDs so this turned everything off. The indicator should still remain on, I guess, since it's not affected by the faults, except possibly the over-temperature one.
OK, I'm fine with the code then.
Quoted 79 lines
Quoted 5 lines
Quoted 2 lines
drivers/media/video/adp1653.c new file +2
-0+return flash->fault; +}[snip]
Quoted 9 lines
drivers/media/video/adp1653.c line 154
Quoted 7 lines
drivers/media/video/adp1653.c new file +7
-0+static int adp1653_get_ctrl (struct v4l2_ctrl *ctrl) +{ +struct adp1653_flash *flash = + container_of(ctrl->handler, struct adp1653_flash, ctrls); + +adp1653_get_fault (flash); +if (IS_ERR_VALUE (flash->fault))Shouldn't you check the
adp1653_get_fault()return value instead ?Yes. Good catch. I've tried to simulate this code a bit but as always, error handling tends not to be one of the best parts of the driver, especially those errors that generally do not happen. :-I
Quoted 20 lines
Quoted 17 lines
drivers/media/video/adp1653.c new file +17
-0+return flash->fault; + + ctrl->cur.val =0 ; + +if (flash->fault &ADP1653_REG_FAULT_FLT_SCP ) + ctrl->cur.val |=V4L2_FLASH_FAULT_SHORT_CIRCUIT ; +if (flash->fault &ADP1653_REG_FAULT_FLT_OT ) + ctrl->cur.val |=V4L2_FLASH_FAULT_OVER_TEMPERATURE ; +if (flash->fault &ADP1653_REG_FAULT_FLT_TMR ) + ctrl->cur.val |=V4L2_FLASH_FAULT_TIMEOUT ; +if (flash->fault &ADP1653_REG_FAULT_FLT_OV ) + ctrl->cur.val |=V4L2_FLASH_FAULT_OVER_VOLTAGE ; + + flash->fault =0 ; + +return 0 ; +}[snip]
Quoted 9 lines
drivers/media/video/adp1653.c line 267
Quoted 6 lines
drivers/media/video/adp1653.c new file +6
-0+static int +adp1653_registered (struct v4l2_subdev *subdev) +{ +struct adp1653_flash *flash =to_adp1653_flash (subdev); + +return adp1653_init_controls (flash);Can't this be moved to
adp1653_probe()? You could then get rid of the registered callback.Good point. I'll look into this.
Quoted 18 lines
Quoted 18 lines
drivers/media/video/adp1653.c new file +18
-0+} + +static int +adp1653_init_device (struct adp1653_flash *flash) +{ +struct i2c_client *client =v4l2_get_subdevdata (&flash->subdev); +int rval; + +/* Clear FAULT register by writing zero to OUT_SEL */ + rval =i2c_smbus_write_byte_data (client,ADP1653_REG_OUT_SEL ,0 ); +if (rval <0 ) { +dev_err (&client->dev,"failed writing fault register\n" ); +return -EIO ; + } + +/* Read FAULT register */ + rval =i2c_smbus_read_byte_data (client,ADP1653_REG_FAULT ); +if (rval <0 ) {Quoted 8 lines
drivers/media/video/adp1653.c line 291
Quoted 6 lines
drivers/media/video/adp1653.c new file +6
-0+dev_err (&client->dev,"failed reading fault register\n" ); +return -EIO ; + } + +if ((rval &0x0f ) !=0 ) { +dev_err (&client->dev,"device fault\n" );Same comment as last time :-)
Ouch. I'll try to get the fix done for the next time. :-)
Signature · 3 lines
Regards, Laurent Pinchart