leds: rt4505: Add support for Richtek RT4505 flash led controller
Subsystems (2)
PATCH 1/2 leds: rt4505: Add support for Richtek RT4505 flash led controller
From: ChiYuan Huang <[email protected]>
Add support for RT4505 flash led controller. It can support up to 1.5A flash current with hardware timeout and low input voltage protection.
--- drivers/leds/Kconfig | 11 ++ drivers/leds/Makefile | 1 + drivers/leds/leds-rt4505.c | 397 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 409 insertions(+) create mode 100644 drivers/leds/leds-rt4505.c
drivers/leds/Kconfig +11 -0
@@ -717,6 +717,17 @@ config LEDS_MAX8997 This option enables support for on-chip LED drivers on MAXIM MAX8997 PMIC. +config LEDS_RT4505 + tristate "LED driver for RT4505 single channel flash led controller" + depends on I2C + depends on LEDS_CLASS_FLASH && OF + depends on V4L2_FLASH_LED_CLASS || !V4L2_FLASH_LED_CLASS + select REGMAP_I2C + help + This option enables support for the RT4505 flash led controller. + It can support up to 1.5A flash strobe current with hardware timeout + and low input voltage protection. + config LEDS_LM355x tristate "LED support for LM3554 and LM3556 chips" depends on LEDS_CLASS && I2C
drivers/leds/Makefile +1 -0
@@ -80,6 +80,7 @@ obj-$(CONFIG_LEDS_PM8058) += leds-pm8058.o obj-$(CONFIG_LEDS_POWERNV) += leds-powernv.o obj-$(CONFIG_LEDS_PWM) += leds-pwm.o obj-$(CONFIG_LEDS_REGULATOR) += leds-regulator.o +obj-$(CONFIG_LEDS_RT4505) += leds-rt4505.o obj-$(CONFIG_LEDS_S3C24XX) += leds-s3c24xx.o obj-$(CONFIG_LEDS_SC27XX_BLTC) += leds-sc27xx-bltc.o obj-$(CONFIG_LEDS_SGM3140) += leds-sgm3140.o
drivers/leds/leds-rt4505.c new file +397 -0
397 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 2/2 leds: rt4505: Add DT binding document for Richtek RT4505
From: ChiYuan Huang <[email protected]>
Add DT binding document for Richtek RT4505 flash led controller.
--- .../devicetree/bindings/leds/leds-rt4505.yaml | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-rt4505.yaml
Documentation/devicetree/bindings/leds/leds-rt4505.yaml new file +57 -0
@@ -0,0 +1,57 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/leds/leds-rt4505.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Richtek RT4505 Single Channel LED Driver + +maintainers: + - ChiYuan Huang <[email protected]> + +description: | + The RT4505 is a flash led driver that can support up to 375mA and 1.5A for + torch and flash mode, respectively. + + The data sheet can be found at: + https://www.richtek.com/assets/product_file/RT4505/DS4505-02.pdf + +properties: + compatible: + const: richtek,rt4505 + + reg: + description: I2C slave address of the controller. + maxItems: 1 + + led: + type: object + $ref: common.yaml# + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + #include <dt-bindings/leds/common.h> + + i2c0 { + #address-cells = <1>; + #size-cells = <0>; + + led-controller@63 { + compatible = "richtek,rt4505"; + reg = <0x63>; + + rt4505_flash: led { + function = LED_FUNCTION_FLASH; + color = <LED_COLOR_ID_WHITE>; + led-max-microamp = <375000>; + flash-max-microamp = <1500000>; + flash-max-timeout-us = <800000>; + }; + }; + };
Signature · 1 line
2.7.4
Hi!
Quoted 5 lines
From: ChiYuan Huang <[email protected]>
Add support for RT4505 flash led controller. It can support up to 1.5A flash current with hardware timeout and low input voltage protection.
Please use upper-case "LED" everywhere.
This should be 2nd in the series, after DT changes.
Quoted 7 lines
Signed-off-by ChiYuan Huang <[email protected]>--- drivers/leds/Kconfig | 11 ++ drivers/leds/Makefile | 1 + drivers/leds/leds-rt4505.c | 397 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 409 insertions(+) create mode 100644 drivers/leds/leds-rt4505.c
Lets put this into drivers/leds/flash/. (Yes, you'll have to create it).
drivers/leds/Kconfig config LEDS_MAX8997 · line 727
Quoted 2 lines
drivers/leds/Kconfig +2
-0+ help + This option enables support for the RT4505 flash led controller.
Information where it is used would be welcome here.
drivers/leds/Kconfig config LEDS_MAX8997 · line 729
Quoted 2 lines
drivers/leds/Kconfig +2
-0+ It can support up to 1.5A flash strobe current with hardware timeout + and low input voltage protection.
This does not / should not be here.
drivers/leds/leds-rt4505.c line 53
Quoted 3 lines
drivers/leds/leds-rt4505.c new file +3
-0+ +static int rt4505_torch_brightness_set (struct led_classdev *lcdev,enum led_brightness level) +{
80 columns, where easy.
Quoted 11 lines
drivers/leds/leds-rt4505.c new file +11
-0+ struct rt4505_priv *priv = container_of(lcdev, struct rt4505_priv, flash.led_cdev); +u32 val =0 ; +int ret; + +mutex_lock (&priv->lock); + +if (level !=LED_OFF ) { + ret =regmap_update_bits (priv->regmap,RT4505_REG_ILED ,RT4505_ITORCH_MASK , + (level -1 ) <<RT4505_ITORCH_SHIFT ); +if (ret) + goto unlock;
drivers/leds/leds-rt4505.c line 74
Quoted 10 lines
drivers/leds/leds-rt4505.c new file +10
-0+ + val =RT4505_TORCH_SET ; + } + + ret =regmap_update_bits (priv->regmap,RT4505_REG_ENABLE ,RT4505_ENABLE_MASK , val); + +unlock: +mutex_unlock (&priv->lock); +return ret; +}
Why is the locking needed? What will the /sys/class/leds interface look like on system with your flash?
drivers/leds/leds-rt4505.c line 149
Quoted 13 lines
drivers/leds/leds-rt4505.c new file +13
-0+static int rt4505_flash_strobe_get (struct led_classdev_flash *fled_cdev,bool *state) +{ + struct rt4505_priv *priv = container_of(fled_cdev, struct rt4505_priv, flash); +u32 val; +int ret; + +mutex_lock (&priv->lock); + + ret =regmap_read (priv->regmap,RT4505_REG_ENABLE , &val); +if (ret) + goto unlock; + + *state = ((val &RT4505_FLASH_GET ) ==RT4505_FLASH_GET ) ? true : false;
No need for ? ... part.
drivers/leds/leds-rt4505.c line 207
Quoted 4 lines
drivers/leds/leds-rt4505.c new file +4
-0+static bool rt4505_is_accessible_reg (struct device *dev,unsigned int reg) +{ +if (reg ==RT4505_REG_RESET || (reg >=RT4505_REG_CONFIG && reg <=RT4505_REG_FLAGS )) +return true;
Make this two stagements.
Otherwise... looks like easy simple driver, thanks.
Best regards,
Pavel
Signature · 1 line
http://www.livejournal.com/~pavelmachek
Pavel Machek <[email protected]> 於 2020年10月27日 週二 下午4:29寫道:
Quoted 5 lines
Hi!
Quoted 2 lines
From: ChiYuan Huang <[email protected]>
Quoted 7 lines
Quoted 3 lines
Add support for RT4505 flash led controller. It can support up to 1.5A flash current with hardware timeout and low input voltage protection.
Please use upper-case "LED" everywhere.
This should be 2nd in the series, after DT changes.
Sure, will ack in next series patch.
Quoted 11 lines
Quoted 8 lines
Signed-off-by ChiYuan Huang <[email protected]>--- drivers/leds/Kconfig | 11 ++ drivers/leds/Makefile | 1 + drivers/leds/leds-rt4505.c | 397 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 409 insertions(+) create mode 100644 drivers/leds/leds-rt4505.cLets put this into
drivers/leds/flash/. (Yes, you'll have to create it).
OK
Quoted 6 lines
drivers/leds/Kconfig config LEDS_MAX8997 · line 727
Quoted 4 lines
drivers/leds/Kconfig +2
-0+ help + This option enables support for the RT4505 flash led controller.Information where it is used would be welcome here.
How about to add the below line for the extra information? Usually used to company with the camera device on smartphone/tablet products
Quoted 5 lines
drivers/leds/Kconfig config LEDS_MAX8997 · line 729
Quoted 3 lines
drivers/leds/Kconfig +2
-0+ It can support up to 1.5A flash strobe current with hardware timeout + and low input voltage protection.This does not / should not be here.
OK
Quoted 5 lines
drivers/leds/leds-rt4505.c line 53
Quoted 3 lines
drivers/leds/leds-rt4505.c new file +3
-0+ +static int rt4505_torch_brightness_set (struct led_classdev *lcdev,enum led_brightness level) +{80 columns, where easy.
I'll review all source code to meet the 80 column limit.
Quoted 17 lines
Quoted 17 lines
drivers/leds/leds-rt4505.c new file +16
-0+ struct rt4505_priv *priv = container_of(lcdev, struct rt4505_priv, flash.led_cdev); +u32 val =0 ; +int ret; + +mutex_lock (&priv->lock); + +if (level !=LED_OFF ) { + ret =regmap_update_bits (priv->regmap,RT4505_REG_ILED ,RT4505_ITORCH_MASK , + (level -1 ) <<RT4505_ITORCH_SHIFT ); +if (ret) + goto unlock; + + val =RT4505_TORCH_SET ; + } + + ret =regmap_update_bits (priv->regmap,RT4505_REG_ENABLE ,RT4505_ENABLE_MASK , val);
Quoted 8 lines
drivers/leds/leds-rt4505.c line 74
Quoted 5 lines
drivers/leds/leds-rt4505.c new file +5
-0+ +unlock: +mutex_unlock (&priv->lock); +return ret; +}Why is the locking needed? What will the
/sys/class/ledsinterface look like on system with your flash?
The original thought is because there's still another way to control flash like as v4l2.
But after reviewing the source code, led sysfs node will be protected by led_cdev->led_access.
And V4L2 flash will also be protected by v4l2_fh_is_singular API. I think the whole locking in the source code code may be removed. Right?
Quoted 16 lines
Quoted 4 lines
drivers/leds/leds-rt4505.c new file +3
-0+static int rt4505_flash_strobe_get (struct led_classdev_flash *fled_cdev,bool *state) +{ + struct rt4505_priv *priv = container_of(fled_cdev, struct rt4505_priv, flash);drivers/leds/leds-rt4505.c line 149
Quoted 10 lines
drivers/leds/leds-rt4505.c new file +10
-0+u32 val; +int ret; + +mutex_lock (&priv->lock); + + ret =regmap_read (priv->regmap,RT4505_REG_ENABLE , &val); +if (ret) + goto unlock; + + *state = ((val &RT4505_FLASH_GET ) ==RT4505_FLASH_GET ) ? true : false;No need for ? ... part.
Do you mean this function is not needed? If yes, it can be removed. But if it removed, led sysfs flash_strobe show will be not supported.
Quoted 7 lines
drivers/leds/leds-rt4505.c line 207
Quoted 5 lines
drivers/leds/leds-rt4505.c new file +4
-0+static bool rt4505_is_accessible_reg (struct device *dev,unsigned int reg) +{ +if (reg ==RT4505_REG_RESET || (reg >=RT4505_REG_CONFIG && reg <=RT4505_REG_FLAGS )) +return true;Make this two stagements.
Like as the below one?? Or separate it into two if case. if (reg == RT4505_REG_RESET ||
reg >= RT4505_REG_CONFIG && reg <= RT4505_REG_FLAGS))
Quoted 7 lines
Otherwise... looks like easy simple driver, thanks.
Best regards,
Pavel
--
http://www.livejournal.com/~pavelmachek
Hi, Parvel:
Continue the last mail, I'm confused about the rule 80-characters-per-line.
I check some information about submitting changes.
https://www.phoronix.com/scan.php?page=news_item&px=Linux-Kernel-Deprecates-80-Col
Could you help to explain the current rule about this limit? still 80 characters per line? or it has been changed to 100.
ChiYuan Huang <[email protected]> 於 2020年10月27日 週二 下午5:27寫道:
Quoted 114 lines
Pavel Machek <[email protected]> 於 2020年10月27日 週二 下午4:29寫道:
Quoted 5 lines
Hi!
Quoted 2 lines
From: ChiYuan Huang <[email protected]>
Quoted 7 lines
Quoted 3 lines
Add support for RT4505 flash led controller. It can support up to 1.5A flash current with hardware timeout and low input voltage protection.
Please use upper-case "LED" everywhere.
This should be 2nd in the series, after DT changes.
Sure, will ack in next series patch.
Quoted 11 lines
Quoted 8 lines
Signed-off-by ChiYuan Huang <[email protected]>--- drivers/leds/Kconfig | 11 ++ drivers/leds/Makefile | 1 + drivers/leds/leds-rt4505.c | 397 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 409 insertions(+) create mode 100644 drivers/leds/leds-rt4505.cLets put this into
drivers/leds/flash/. (Yes, you'll have to create it).OK
Quoted 6 lines
drivers/leds/Kconfig config LEDS_MAX8997 · line 727
Quoted 4 lines
drivers/leds/Kconfig +2
-0+ help + This option enables support for the RT4505 flash led controller.Information where it is used would be welcome here.
How about to add the below line for the extra information? Usually used to company with the camera device on smartphone/tablet products
Quoted 5 lines
drivers/leds/Kconfig config LEDS_MAX8997 · line 729
Quoted 3 lines
drivers/leds/Kconfig +2
-0+ It can support up to 1.5A flash strobe current with hardware timeout + and low input voltage protection.This does not / should not be here.
OK
Quoted 5 lines
drivers/leds/leds-rt4505.c line 53
Quoted 3 lines
drivers/leds/leds-rt4505.c new file +3
-0+ +static int rt4505_torch_brightness_set (struct led_classdev *lcdev,enum led_brightness level) +{80 columns, where easy.
I'll review all source code to meet the 80 column limit.
Quoted 17 lines
Quoted 17 lines
drivers/leds/leds-rt4505.c new file +16
-0+ struct rt4505_priv *priv = container_of(lcdev, struct rt4505_priv, flash.led_cdev); +u32 val =0 ; +int ret; + +mutex_lock (&priv->lock); + +if (level !=LED_OFF ) { + ret =regmap_update_bits (priv->regmap,RT4505_REG_ILED ,RT4505_ITORCH_MASK , + (level -1 ) <<RT4505_ITORCH_SHIFT ); +if (ret) + goto unlock; + + val =RT4505_TORCH_SET ; + } + + ret =regmap_update_bits (priv->regmap,RT4505_REG_ENABLE ,RT4505_ENABLE_MASK , val);Quoted 8 lines
drivers/leds/leds-rt4505.c line 74
Quoted 5 lines
drivers/leds/leds-rt4505.c new file +5
-0+ +unlock: +mutex_unlock (&priv->lock); +return ret; +}Why is the locking needed? What will the
/sys/class/ledsinterface look like on system with your flash?The original thought is because there's still another way to control flash like as v4l2.
But after reviewing the source code, led sysfs node will be protected byled_cdev->led_access.
And V4L2 flash will also be protected byv4l2_fh_is_singularAPI. I think the whole locking in the source code code may be removed. Right?Quoted 16 lines
Quoted 4 lines
drivers/leds/leds-rt4505.c new file +3
-0+static int rt4505_flash_strobe_get (struct led_classdev_flash *fled_cdev,bool *state) +{ + struct rt4505_priv *priv = container_of(fled_cdev, struct rt4505_priv, flash);drivers/leds/leds-rt4505.c line 149
Quoted 10 lines
drivers/leds/leds-rt4505.c new file +10
-0+u32 val; +int ret; + +mutex_lock (&priv->lock); + + ret =regmap_read (priv->regmap,RT4505_REG_ENABLE , &val); +if (ret) + goto unlock; + + *state = ((val &RT4505_FLASH_GET ) ==RT4505_FLASH_GET ) ? true : false;No need for ? ... part.
Do you mean this function is not needed? If yes, it can be removed. But if it removed, led sysfs
flash_strobeshow will be not supported.Quoted 7 lines
drivers/leds/leds-rt4505.c line 207
Quoted 5 lines
drivers/leds/leds-rt4505.c new file +4
-0+static bool rt4505_is_accessible_reg (struct device *dev,unsigned int reg) +{ +if (reg ==RT4505_REG_RESET || (reg >=RT4505_REG_CONFIG && reg <=RT4505_REG_FLAGS )) +return true;Make this two stagements.
Like as the below one?? Or separate it into two if case. if (reg ==
RT4505_REG_RESET||reg >= RT4505_REG_CONFIG && reg <= RT4505_REG_FLAGS))Quoted 7 lines
Otherwise... looks like easy simple driver, thanks.
Best regards,
Pavel
--
http://www.livejournal.com/~pavelmachek
Hi!
Quoted 5 lines
Continue the last mail, I'm confused about the rule 80-characters-per-line.
I check some information about submitting changes.
https://www.phoronix.com/scan.php?page=news_item&px=Linux-Kernel-Deprecates-80-Col
Could you help to explain the current rule about this limit? still 80 characters per line? or it has been changed to 100.
Please see Documentation/process/coding-style.rst .
Pavel
Signature · 1 line
http://www.livejournal.com/~pavelmachek
Hi!
Quoted 4 lines
Quoted 3 lines
Please use upper-case "LED" everywhere.
This should be 2nd in the series, after DT changes.
Sure, will ack in next series patch.
Feel free to wait for dt ACKs before resending.
Quoted 7 lines
Quoted 4 lines
drivers/leds/Kconfig config LEDS_MAX8997 · line 727
Quoted 2 lines
drivers/leds/Kconfig +2
-0+ help + This option enables support for the RT4505 flash led controller.Information where it is used would be welcome here.
How about to add the below line for the extra information? Usually used to company with the camera device on smartphone/tablet products
Yes, that would help.
"It is commonly used in smartphones, such as Bell Packard T899" would be even better.
Quoted 10 lines
Quoted 9 lines
drivers/leds/leds-rt4505.c line 74
Quoted 6 lines
drivers/leds/leds-rt4505.c new file +6
-0+ ret =regmap_update_bits (priv->regmap,RT4505_REG_ENABLE ,RT4505_ENABLE_MASK , val); + +unlock: +mutex_unlock (&priv->lock); +return ret; +}Why is the locking needed? What will the
/sys/class/ledsinterface look like on system with your flash?
Quoted 6 lines
The original thought is because there's still another way to control flash like as v4l2.
But after reviewing the source code, led sysfs node will be protected byled_cdev->led_access.
And V4L2 flash will also be protected byv4l2_fh_is_singularAPI. I think the whole locking in the source code code may be removed. Right?
Well, maybe you need it, I did not check..
What will the /sys/class/leds interface look like on system with your flash?
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
+ *state = ((val &
RT4505_FLASH_GET) ==RT4505_FLASH_GET) ? true : false;No need for ? ... part.
Do you mean this function is not needed? If yes, it can be removed. But if it removed, led sysfs
flash_strobeshow will be not supported.
I meant "replace line with: *state = (val & RT4505_FLASH_GET) == RT4505_FLASH_GET;"
Quoted 9 lines
Quoted 6 lines
drivers/leds/leds-rt4505.c line 207
Quoted 4 lines
drivers/leds/leds-rt4505.c new file +4
-0+static bool rt4505_is_accessible_reg (struct device *dev,unsigned int reg) +{ +if (reg ==RT4505_REG_RESET || (reg >=RT4505_REG_CONFIG && reg <=RT4505_REG_FLAGS )) +return true;Make this two stagements.
Like as the below one?? Or separate it into two if case. if (reg ==
RT4505_REG_RESET||reg >= RT4505_REG_CONFIG && reg <= RT4505_REG_FLAGS))
That would be fine, too... if you use just one space before "&&" :-).
Best regards,
Pavel
Signature · 1 line
http://www.livejournal.com/~pavelmachek
Pavel Machek <[email protected]> 於 2020年10月27日 週二 下午6:15寫道:
Quoted 10 lines
Hi!
Quoted 4 lines
Quoted 3 lines
Please use upper-case "LED" everywhere.
This should be 2nd in the series, after DT changes.
Sure, will ack in next series patch.
Feel free to wait for dt ACKs before resending.
Yes, sure.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/leds/Kconfig config LEDS_MAX8997 · line 727
Quoted 2 lines
drivers/leds/Kconfig +2
-0+ help + This option enables support for the RT4505 flash led controller.Information where it is used would be welcome here.
Quoted 8 lines
Quoted 3 lines
How about to add the below line for the extra information? Usually used to company with the camera device on smartphone/tablet products
Yes, that would help.
"It is commonly used in smartphones, such as Bell Packard T899" would be even better.
Sorry, We don't focus on specific products. It's a general part flash led controller.
I'll change it like as below
"It's commonly used in smartphones and tablets to assist the builtin camera."
Quoted 22 lines
Quoted 11 lines
Quoted 10 lines
drivers/leds/leds-rt4505.c line 74
Quoted 7 lines
drivers/leds/leds-rt4505.c new file +6
-0+ ret =regmap_update_bits (priv->regmap,RT4505_REG_ENABLE ,RT4505_ENABLE_MASK , val); + +unlock: +mutex_unlock (&priv->lock); +return ret; +}Why is the locking needed? What will the
/sys/class/ledsinterface look like on system with your flash?Quoted 6 lines
The original thought is because there's still another way to control flash like as v4l2.
But after reviewing the source code, led sysfs node will be protected byled_cdev->led_access.
And V4L2 flash will also be protected byv4l2_fh_is_singularAPI. I think the whole locking in the source code code may be removed. Right?Well, maybe you need it, I did not check..
What will the
/sys/class/ledsinterface look like on system with your flash?
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
+ *state = ((val &
RT4505_FLASH_GET) ==RT4505_FLASH_GET) ? true : false;No need for ? ... part.
Do you mean this function is not needed? If yes, it can be removed. But if it removed, led sysfs
flash_strobeshow will be not supported.I meant "replace line with: *state = (val &
RT4505_FLASH_GET) ==RT4505_FLASH_GET;"
Oh, I got it. redundant judgement.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/leds/leds-rt4505.c line 207
Quoted 5 lines
drivers/leds/leds-rt4505.c new file +4
-0+static bool rt4505_is_accessible_reg (struct device *dev,unsigned int reg) +{ +if (reg ==RT4505_REG_RESET || (reg >=RT4505_REG_CONFIG && reg <=RT4505_REG_FLAGS )) +return true;Make this two stagements.
Quoted 5 lines
Quoted 3 lines
Like as the below one?? Or separate it into two if case. if (reg ==
RT4505_REG_RESET||reg >= RT4505_REG_CONFIG && reg <= RT4505_REG_FLAGS))That would be fine, too... if you use just one space before "&&" :-).
Thx.
Quoted 5 lines
Best regards,
Pavel
--
http://www.livejournal.com/~pavelmachek
ChiYuan Huang <[email protected]> 於 2020年10月27日 週二 下午6:46寫道:
Quoted 23 lines
Pavel Machek <[email protected]> 於 2020年10月27日 週二 下午6:15寫道:
Quoted 10 lines
Hi!
Quoted 4 lines
Quoted 3 lines
Please use upper-case "LED" everywhere.
This should be 2nd in the series, after DT changes.
Sure, will ack in next series patch.
Feel free to wait for dt ACKs before resending.
Yes, sure.
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines
drivers/leds/Kconfig config LEDS_MAX8997 · line 727
Quoted 2 lines
drivers/leds/Kconfig +2
-0+ help + This option enables support for the RT4505 flash led controller.Information where it is used would be welcome here.
How about to add the below line for the extra information? Usually used to company with the camera device on smartphone/tablet products
Yes, that would help.
Quoted 26 lines
Quoted 2 lines
"It is commonly used in smartphones, such as Bell Packard T899" would be even better.
Sorry, We don't focus on specific products. It's a general part flash led controller.
I'll change it like as below
"It's commonly used in smartphones and tablets to assist the builtin camera."Quoted 19 lines
Quoted 11 lines
Quoted 10 lines
drivers/leds/leds-rt4505.c line 74
Quoted 7 lines
drivers/leds/leds-rt4505.c new file +6
-0+ ret =regmap_update_bits (priv->regmap,RT4505_REG_ENABLE ,RT4505_ENABLE_MASK , val); + +unlock: +mutex_unlock (&priv->lock); +return ret; +}Why is the locking needed? What will the
/sys/class/ledsinterface look like on system with your flash?Quoted 6 lines
The original thought is because there's still another way to control flash like as v4l2.
But after reviewing the source code, led sysfs node will be protected byled_cdev->led_access.
And V4L2 flash will also be protected byv4l2_fh_is_singularAPI. I think the whole locking in the source code code may be removed. Right?Well, maybe you need it, I did not check..
I found all led class is guaranteed by led_cdev->led_access lock. And v4l2 ctrl handleris guaranteed by ctrl->handler->lock that defined in v4l2-ctrl.c.
When entering v4l2 control mode, all led sysfs will be disabled. To remove all lock operation is correct. Due to all operations are guaranteed. In next series patch, I'll remove it.
How do you think?
Quoted 29 lines
Quoted 10 lines
What will the
/sys/class/ledsinterface look like on system with your flash?Quoted 5 lines
Quoted 3 lines
Quoted 1 line
+ *state = ((val &
RT4505_FLASH_GET) ==RT4505_FLASH_GET) ? true : false;No need for ? ... part.
Do you mean this function is not needed? If yes, it can be removed. But if it removed, led sysfs
flash_strobeshow will be not supported.I meant "replace line with: *state = (val &
RT4505_FLASH_GET) ==RT4505_FLASH_GET;"Oh, I got it. redundant judgement.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/leds/leds-rt4505.c line 207
Quoted 5 lines
drivers/leds/leds-rt4505.c new file +4
-0+static bool rt4505_is_accessible_reg (struct device *dev,unsigned int reg) +{ +if (reg ==RT4505_REG_RESET || (reg >=RT4505_REG_CONFIG && reg <=RT4505_REG_FLAGS )) +return true;Make this two stagements.
Quoted 5 lines
Quoted 3 lines
Like as the below one?? Or separate it into two if case. if (reg ==
RT4505_REG_RESET||reg >= RT4505_REG_CONFIG && reg <= RT4505_REG_FLAGS))That would be fine, too... if you use just one space before "&&" :-).
Thx.
Quoted 5 lines
Best regards,
Pavel
--
http://www.livejournal.com/~pavelmachek
Hi Pavel, ChiYuan,
Quoted 19 lines · Pavel Machek
Hi!
Quoted 5 lines
From: ChiYuan Huang <[email protected]>
Add support for RT4505 flash led controller. It can support up to 1.5A flash current with hardware timeout and low input voltage protection.
Please use upper-case "LED" everywhere.
This should be 2nd in the series, after DT changes.
Quoted 7 lines
Signed-off-by ChiYuan Huang <[email protected]>--- drivers/leds/Kconfig | 11 ++ drivers/leds/Makefile | 1 + drivers/leds/leds-rt4505.c | 397 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 409 insertions(+)create mode 100644
drivers/leds/leds-rt4505.c
[...]
Quoted 21 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+static int rt4505_torch_brightness_set(struct led_classdev *lcdev, enum led_brightness level) +{80 columns, where easy.
Quoted 16 lines
drivers/leds/leds-rt4505.c new file +16
-0+ struct rt4505_priv *priv = container_of(lcdev, struct rt4505_priv, flash.led_cdev); +u32 val =0 ; +int ret; + +mutex_lock (&priv->lock); + +if (level !=LED_OFF ) { + ret =regmap_update_bits (priv->regmap,RT4505_REG_ILED ,RT4505_ITORCH_MASK , + (level -1 ) <<RT4505_ITORCH_SHIFT ); +if (ret) + goto unlock; + + val =RT4505_TORCH_SET ; + } + + ret =regmap_update_bits (priv->regmap,RT4505_REG_ENABLE ,RT4505_ENABLE_MASK , val);
Quoted 8 lines
drivers/leds/leds-rt4505.c line 74
Quoted 5 lines
drivers/leds/leds-rt4505.c new file +5
-0+ +unlock: +mutex_unlock (&priv->lock); +return ret; +}Why is the locking needed? What will the
/sys/class/ledsinterface look like on system with your flash?
The locking is needed since this can be called via led_set_brightness() from any place in the kernel, and especially from triggers.
Signature · 2 lines
Best regards, Jacek Anaszewski
Jacek Anaszewski <[email protected]> 於 2020年10月28日 週三 下午7:07寫道:
Quoted 69 lines · ChiYuan Huang
Quoted 60 lines
Hi,
Jacek Anaszewski <[email protected]> 於 2020年10月28日 週三 上午12:40寫道:
Quoted 54 lines
Hi Pavel, ChiYuan,
Quoted 19 lines · Pavel Machek
Hi!
Quoted 5 lines
From: ChiYuan Huang <[email protected]>
Add support for RT4505 flash led controller. It can support up to 1.5A flash current with hardware timeout and low input voltage protection.
Please use upper-case "LED" everywhere.
This should be 2nd in the series, after DT changes.
Quoted 7 lines
Signed-off-by ChiYuan Huang <[email protected]>--- drivers/leds/Kconfig | 11 ++ drivers/leds/Makefile | 1 + drivers/leds/leds-rt4505.c | 397 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 409 insertions(+)create mode 100644
drivers/leds/leds-rt4505.c[...]
Quoted 21 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+static int rt4505_torch_brightness_set(struct led_classdev *lcdev, enum led_brightness level) +{80 columns, where easy.
Quoted 16 lines
drivers/leds/leds-rt4505.c new file +16
-0+ struct rt4505_priv *priv = container_of(lcdev, struct rt4505_priv, flash.led_cdev); +u32 val =0 ; +int ret; + +mutex_lock (&priv->lock); + +if (level !=LED_OFF ) { + ret =regmap_update_bits (priv->regmap,RT4505_REG_ILED ,RT4505_ITORCH_MASK , + (level -1 ) <<RT4505_ITORCH_SHIFT ); +if (ret) + goto unlock; + + val =RT4505_TORCH_SET ; + } + + ret =regmap_update_bits (priv->regmap,RT4505_REG_ENABLE ,RT4505_ENABLE_MASK , val);Quoted 8 lines
drivers/leds/leds-rt4505.c line 74
Quoted 5 lines
drivers/leds/leds-rt4505.c new file +5
-0+ +unlock: +mutex_unlock (&priv->lock); +return ret; +}Why is the locking needed? What will the
/sys/class/ledsinterface look like on system with your flash?Quoted 3 lines
The locking is needed since this can be called via
led_set_brightness()from any place in the kernel, and especially from triggers. From this case, It means only led classdevQuoted 6 lines
brihtness_get/brightness_set need to be protected.
I searchled_flash_classdev, it only can be controlled via sysfs or V4l2. Like as described in last mail, flash related operation is protected by ledaccess_lockand v4l2 framework.
I'll keep the locking only in led classdev brightness_get/brightness_set API. If I misunderstand something, please help to point out.
Quoted 7 lines
Locking have to be used consistently for each access to the resource being protected with the lock. Otherwise you can end up in a situation when
rt4505_torch_brightness_setandrt4505_flash_brightness_setwill try concurrently alter hardware state. Regardless of how harmful could it be in case of this particular device it is certainly against programming rules.
Sure, any resource access must be protected.
I'll keep the locking like as the original patch.
Thx.
Quoted 3 lines
--
Best regards,
Jacek Anaszewski
Hi,
Jacek Anaszewski <[email protected]> 於 2020年10月28日 週三 上午12:40寫道:
Quoted 54 lines
Hi Pavel, ChiYuan,
Quoted 19 lines · Pavel Machek
Hi!
Quoted 5 lines
From: ChiYuan Huang <[email protected]>
Add support for RT4505 flash led controller. It can support up to 1.5A flash current with hardware timeout and low input voltage protection.
Please use upper-case "LED" everywhere.
This should be 2nd in the series, after DT changes.
Quoted 7 lines
Signed-off-by ChiYuan Huang <[email protected]>--- drivers/leds/Kconfig | 11 ++ drivers/leds/Makefile | 1 + drivers/leds/leds-rt4505.c | 397 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 409 insertions(+)create mode 100644
drivers/leds/leds-rt4505.c[...]
Quoted 21 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+static int rt4505_torch_brightness_set(struct led_classdev *lcdev, enum led_brightness level) +{80 columns, where easy.
Quoted 16 lines
drivers/leds/leds-rt4505.c new file +16
-0+ struct rt4505_priv *priv = container_of(lcdev, struct rt4505_priv, flash.led_cdev); +u32 val =0 ; +int ret; + +mutex_lock (&priv->lock); + +if (level !=LED_OFF ) { + ret =regmap_update_bits (priv->regmap,RT4505_REG_ILED ,RT4505_ITORCH_MASK , + (level -1 ) <<RT4505_ITORCH_SHIFT ); +if (ret) + goto unlock; + + val =RT4505_TORCH_SET ; + } + + ret =regmap_update_bits (priv->regmap,RT4505_REG_ENABLE ,RT4505_ENABLE_MASK , val);Quoted 8 lines
drivers/leds/leds-rt4505.c line 74
Quoted 5 lines
drivers/leds/leds-rt4505.c new file +5
-0+ +unlock: +mutex_unlock (&priv->lock); +return ret; +}Why is the locking needed? What will the
/sys/class/ledsinterface look like on system with your flash?
Quoted 2 lines
The locking is needed since this can be called via
led_set_brightness()from any place in the kernel, and especially from triggers.
From this case, It means only led classdev brihtness_get/brightness_set need to be protected.
I search led_flash_classdev, it only can be controlled via sysfs or V4l2. Like as described in last mail, flash related operation is protected by led access_lock and v4l2 framework.
I'll keep the locking only in led classdev brightness_get/brightness_set API. If I misunderstand something, please help to point out.
Thx.
Quoted 4 lines
--
Best regards,
Jacek Anaszewski
Quoted 60 lines · ChiYuan Huang
Hi,
Jacek Anaszewski <[email protected]> 於 2020年10月28日 週三 上午12:40寫道:
Quoted 54 lines
Hi Pavel, ChiYuan,
Quoted 19 lines · Pavel Machek
Hi!
Quoted 5 lines
From: ChiYuan Huang <[email protected]>
Add support for RT4505 flash led controller. It can support up to 1.5A flash current with hardware timeout and low input voltage protection.
Please use upper-case "LED" everywhere.
This should be 2nd in the series, after DT changes.
Quoted 7 lines
Signed-off-by ChiYuan Huang <[email protected]>--- drivers/leds/Kconfig | 11 ++ drivers/leds/Makefile | 1 + drivers/leds/leds-rt4505.c | 397 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 409 insertions(+)create mode 100644
drivers/leds/leds-rt4505.c[...]
Quoted 21 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+static int rt4505_torch_brightness_set(struct led_classdev *lcdev, enum led_brightness level) +{80 columns, where easy.
Quoted 16 lines
drivers/leds/leds-rt4505.c new file +16
-0+ struct rt4505_priv *priv = container_of(lcdev, struct rt4505_priv, flash.led_cdev); +u32 val =0 ; +int ret; + +mutex_lock (&priv->lock); + +if (level !=LED_OFF ) { + ret =regmap_update_bits (priv->regmap,RT4505_REG_ILED ,RT4505_ITORCH_MASK , + (level -1 ) <<RT4505_ITORCH_SHIFT ); +if (ret) + goto unlock; + + val =RT4505_TORCH_SET ; + } + + ret =regmap_update_bits (priv->regmap,RT4505_REG_ENABLE ,RT4505_ENABLE_MASK , val);Quoted 8 lines
drivers/leds/leds-rt4505.c line 74
Quoted 5 lines
drivers/leds/leds-rt4505.c new file +5
-0+ +unlock: +mutex_unlock (&priv->lock); +return ret; +}Why is the locking needed? What will the
/sys/class/ledsinterface look like on system with your flash?Quoted 3 lines
The locking is needed since this can be called via
led_set_brightness()from any place in the kernel, and especially from triggers. From this case, It means only led classdev
Quoted 6 lines
brihtness_get/brightness_set need to be protected.
I searchled_flash_classdev, it only can be controlled via sysfs or V4l2. Like as described in last mail, flash related operation is protected by ledaccess_lockand v4l2 framework.
I'll keep the locking only in led classdev brightness_get/brightness_set API. If I misunderstand something, please help to point out.
Locking have to be used consistently for each access to the resource being protected with the lock. Otherwise you can end up in a situation when rt4505_torch_brightness_set and rt4505_flash_brightness_set will try concurrently alter hardware state. Regardless of how harmful could it be in case of this particular device it is certainly against programming rules.
Signature · 2 lines
Best regards, Jacek Anaszewski
Re: [PATCH v1 2/2] leds: rt4505: Add DT binding document for Richtek RT4505
In reply to cy_huangQuoted 10 lines · cy_huang
From: ChiYuan Huang <[email protected]>
Add DT binding document for Richtek RT4505 flash led controller.
Signed-off-by ChiYuan Huang <[email protected]>--- .../devicetree/bindings/leds/leds-rt4505.yaml | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-rt4505.yaml