Message ID | 20250407095119.588920-4-mitltlatltl@gmail.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | backlight: ktz8866: improve it and support slave | expand |
On Mon, Apr 07, 2025 at 05:51:18PM +0800, Pengyu Luo wrote: > I polled all registers when the module was loading, found that > current sinks have already been configured. Bootloader would set > when booting. So checking it before setting the all channels. Can you rephrase this so the problem and solution are more clearly expressed. Perhaps template Ingo suggests here would be good: https://www.spinics.net/lists/kernel/msg1633438.html > Signed-off-by: Pengyu Luo <mitltlatltl@gmail.com> > --- > drivers/video/backlight/ktz8866.c | 23 +++++++++++++++++++---- > 1 file changed, 19 insertions(+), 4 deletions(-) > > diff --git a/drivers/video/backlight/ktz8866.c b/drivers/video/backlight/ktz8866.c > index 017ad80dd..b67ca136d 100644 > --- a/drivers/video/backlight/ktz8866.c > +++ b/drivers/video/backlight/ktz8866.c > @@ -46,6 +46,8 @@ > #define LCD_BIAS_EN 0x9F > #define PWM_HYST 0x5 > > +#define CURRENT_SINKS_MASK GENMASK(5, 0) > + Call this BL_EN_CURRENT_SINKS_MASK and keep it next to the register it applies to. > struct ktz8866_slave { > struct i2c_client *client; > struct regmap *regmap; > @@ -112,11 +120,18 @@ static void ktz8866_init(struct ktz8866 *ktz) > { > unsigned int val = 0; > > - if (!of_property_read_u32(ktz->client->dev.of_node, "current-num-sinks", &val)) > + if (!of_property_read_u32(ktz->client->dev.of_node, "current-num-sinks", &val)) { > ktz8866_write(ktz, BL_EN, BIT(val) - 1); > - else > - /* Enable all 6 current sinks if the number of current sinks isn't specified. */ > - ktz8866_write(ktz, BL_EN, BIT(6) - 1); > + } else { > + /* > + * Enable all 6 current sinks if the number of current > + * sinks isn't specified and the bootloader didn't set > + * the value. > + */ > + ktz8866_read(ktz, BL_EN, &val); > + if (!(val && CURRENT_SINKS_MASK)) This is the wrong form of AND. > + ktz8866_write(ktz, BL_EN, CURRENT_SINKS_MASK); > + } Daniel.
Hi Pengyu, kernel test robot noticed the following build errors: [auto build test ERROR on lee-backlight/for-backlight-next] [also build test ERROR on lee-leds/for-leds-next lee-backlight/for-backlight-fixes linus/master v6.15-rc1 next-20250407] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Pengyu-Luo/dt-bindings-backlight-kinetic-ktz8866-add-ktz8866-slave-compatible/20250407-175635 base: https://git.kernel.org/pub/scm/linux/kernel/git/lee/backlight.git for-backlight-next patch link: https://lore.kernel.org/r/20250407095119.588920-4-mitltlatltl%40gmail.com patch subject: [PATCH 3/4] backlight: ktz8866: improve current sinks setting config: riscv-randconfig-002-20250408 (https://download.01.org/0day-ci/archive/20250408/202504081109.E7PjHxpa-lkp@intel.com/config) compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project 92c93f5286b9ff33f27ff694d2dc33da1c07afdd) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250408/202504081109.E7PjHxpa-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202504081109.E7PjHxpa-lkp@intel.com/ All error/warnings (new ones prefixed by >>): >> drivers/video/backlight/ktz8866.c:73:32: error: incompatible pointer types passing 'unsigned int **' to parameter of type 'unsigned int *'; remove & [-Werror,-Wincompatible-pointer-types] 73 | regmap_read(ktz->regmap, reg, &val); | ^~~~ include/linux/regmap.h:1297:69: note: passing argument to parameter 'val' here 1297 | int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val); | ^ >> drivers/video/backlight/ktz8866.c:132:13: warning: use of logical '&&' with constant operand [-Wconstant-logical-operand] 132 | if (!(val && CURRENT_SINKS_MASK)) | ^ ~~~~~~~~~~~~~~~~~~ drivers/video/backlight/ktz8866.c:132:13: note: use '&' for a bitwise operation 132 | if (!(val && CURRENT_SINKS_MASK)) | ^~ | & drivers/video/backlight/ktz8866.c:132:13: note: remove constant to silence this warning 132 | if (!(val && CURRENT_SINKS_MASK)) | ^~~~~~~~~~~~~~~~~~~~~ 1 warning and 1 error generated. vim +73 drivers/video/backlight/ktz8866.c 69 70 static inline void ktz8866_read(struct ktz8866 *ktz, unsigned int reg, 71 unsigned int *val) 72 { > 73 regmap_read(ktz->regmap, reg, &val); 74 } 75 76 static void ktz8866_write(struct ktz8866 *ktz, unsigned int reg, 77 unsigned int val) 78 { 79 regmap_write(ktz->regmap, reg, val); 80 81 if (ktz->slave) 82 regmap_write(ktz->slave->regmap, reg, val); 83 } 84 85 static void ktz8866_update_bits(struct ktz8866 *ktz, unsigned int reg, 86 unsigned int mask, unsigned int val) 87 { 88 regmap_update_bits(ktz->regmap, reg, mask, val); 89 90 if (ktz->slave) 91 regmap_update_bits(ktz->slave->regmap, reg, mask, val); 92 } 93 94 static int ktz8866_backlight_update_status(struct backlight_device *backlight_dev) 95 { 96 struct ktz8866 *ktz = bl_get_data(backlight_dev); 97 unsigned int brightness = backlight_get_brightness(backlight_dev); 98 99 if (!ktz->led_on && brightness > 0) { 100 ktz8866_update_bits(ktz, BL_EN, BL_EN_BIT, BL_EN_BIT); 101 ktz->led_on = true; 102 } else if (brightness == 0) { 103 ktz8866_update_bits(ktz, BL_EN, BL_EN_BIT, 0); 104 ktz->led_on = false; 105 } 106 107 /* Set brightness */ 108 ktz8866_write(ktz, BL_BRT_LSB, brightness & 0x7); 109 ktz8866_write(ktz, BL_BRT_MSB, (brightness >> 3) & 0xFF); 110 111 return 0; 112 } 113 114 static const struct backlight_ops ktz8866_backlight_ops = { 115 .options = BL_CORE_SUSPENDRESUME, 116 .update_status = ktz8866_backlight_update_status, 117 }; 118 119 static void ktz8866_init(struct ktz8866 *ktz) 120 { 121 unsigned int val = 0; 122 123 if (!of_property_read_u32(ktz->client->dev.of_node, "current-num-sinks", &val)) { 124 ktz8866_write(ktz, BL_EN, BIT(val) - 1); 125 } else { 126 /* 127 * Enable all 6 current sinks if the number of current 128 * sinks isn't specified and the bootloader didn't set 129 * the value. 130 */ 131 ktz8866_read(ktz, BL_EN, &val); > 132 if (!(val && CURRENT_SINKS_MASK)) 133 ktz8866_write(ktz, BL_EN, CURRENT_SINKS_MASK); 134 } 135 136 if (!of_property_read_u32(ktz->client->dev.of_node, "kinetic,current-ramp-delay-ms", &val)) { 137 if (val <= 128) 138 ktz8866_write(ktz, BL_CFG2, BIT(7) | (ilog2(val) << 3) | PWM_HYST); 139 else 140 ktz8866_write(ktz, BL_CFG2, BIT(7) | ((5 + val / 64) << 3) | PWM_HYST); 141 } 142 143 if (!of_property_read_u32(ktz->client->dev.of_node, "kinetic,led-enable-ramp-delay-ms", &val)) { 144 if (val == 0) 145 ktz8866_write(ktz, BL_DIMMING, 0); 146 else { 147 unsigned int ramp_off_time = ilog2(val) + 1; 148 unsigned int ramp_on_time = ramp_off_time << 4; 149 ktz8866_write(ktz, BL_DIMMING, ramp_on_time | ramp_off_time); 150 } 151 } 152 153 if (of_property_read_bool(ktz->client->dev.of_node, "kinetic,enable-lcd-bias")) 154 ktz8866_write(ktz, LCD_BIAS_CFG1, LCD_BIAS_EN); 155 } 156
Hi Pengyu, kernel test robot noticed the following build errors: [auto build test ERROR on lee-backlight/for-backlight-next] [also build test ERROR on lee-leds/for-leds-next lee-backlight/for-backlight-fixes linus/master v6.15-rc1 next-20250407] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Pengyu-Luo/dt-bindings-backlight-kinetic-ktz8866-add-ktz8866-slave-compatible/20250407-175635 base: https://git.kernel.org/pub/scm/linux/kernel/git/lee/backlight.git for-backlight-next patch link: https://lore.kernel.org/r/20250407095119.588920-4-mitltlatltl%40gmail.com patch subject: [PATCH 3/4] backlight: ktz8866: improve current sinks setting config: sparc64-randconfig-002-20250408 (https://download.01.org/0day-ci/archive/20250408/202504081106.mAYfJsQj-lkp@intel.com/config) compiler: sparc64-linux-gcc (GCC) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250408/202504081106.mAYfJsQj-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202504081106.mAYfJsQj-lkp@intel.com/ All errors (new ones prefixed by >>): drivers/video/backlight/ktz8866.c: In function 'ktz8866_read': >> drivers/video/backlight/ktz8866.c:73:39: error: passing argument 3 of 'regmap_read' from incompatible pointer type [-Wincompatible-pointer-types] 73 | regmap_read(ktz->regmap, reg, &val); | ^~~~ | | | unsigned int ** In file included from drivers/video/backlight/ktz8866.c:17: include/linux/regmap.h:1297:69: note: expected 'unsigned int *' but argument is of type 'unsigned int **' 1297 | int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val); | ~~~~~~~~~~~~~~^~~ vim +/regmap_read +73 drivers/video/backlight/ktz8866.c 69 70 static inline void ktz8866_read(struct ktz8866 *ktz, unsigned int reg, 71 unsigned int *val) 72 { > 73 regmap_read(ktz->regmap, reg, &val); 74 } 75
diff --git a/drivers/video/backlight/ktz8866.c b/drivers/video/backlight/ktz8866.c index 017ad80dd..b67ca136d 100644 --- a/drivers/video/backlight/ktz8866.c +++ b/drivers/video/backlight/ktz8866.c @@ -46,6 +46,8 @@ #define LCD_BIAS_EN 0x9F #define PWM_HYST 0x5 +#define CURRENT_SINKS_MASK GENMASK(5, 0) + struct ktz8866_slave { struct i2c_client *client; struct regmap *regmap; @@ -65,6 +67,12 @@ static const struct regmap_config ktz8866_regmap_config = { .max_register = REG_MAX, }; +static inline void ktz8866_read(struct ktz8866 *ktz, unsigned int reg, + unsigned int *val) +{ + regmap_read(ktz->regmap, reg, &val); +} + static void ktz8866_write(struct ktz8866 *ktz, unsigned int reg, unsigned int val) { @@ -112,11 +120,18 @@ static void ktz8866_init(struct ktz8866 *ktz) { unsigned int val = 0; - if (!of_property_read_u32(ktz->client->dev.of_node, "current-num-sinks", &val)) + if (!of_property_read_u32(ktz->client->dev.of_node, "current-num-sinks", &val)) { ktz8866_write(ktz, BL_EN, BIT(val) - 1); - else - /* Enable all 6 current sinks if the number of current sinks isn't specified. */ - ktz8866_write(ktz, BL_EN, BIT(6) - 1); + } else { + /* + * Enable all 6 current sinks if the number of current + * sinks isn't specified and the bootloader didn't set + * the value. + */ + ktz8866_read(ktz, BL_EN, &val); + if (!(val && CURRENT_SINKS_MASK)) + ktz8866_write(ktz, BL_EN, CURRENT_SINKS_MASK); + } if (!of_property_read_u32(ktz->client->dev.of_node, "kinetic,current-ramp-delay-ms", &val)) { if (val <= 128)
I polled all registers when the module was loading, found that current sinks have already been configured. Bootloader would set when booting. So checking it before setting the all channels. Signed-off-by: Pengyu Luo <mitltlatltl@gmail.com> --- drivers/video/backlight/ktz8866.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)