@@ -64,7 +64,7 @@ def generate_struct(p: Panel, options: Options) -> str:
6464
6565 if options .regulator :
6666 if len (options .regulator ) > 1 :
67- variables .append (f'struct regulator_bulk_data supplies[ { len ( options . regulator ) } ] ' )
67+ variables .append (f'struct regulator_bulk_data * supplies' )
6868 else :
6969 variables .append ('struct regulator *supply' )
7070 variables += [f'struct gpio_desc *{ name } _gpio' for name in options .gpios .keys ()]
@@ -78,6 +78,18 @@ def generate_struct(p: Panel, options: Options) -> str:
7878 return s
7979
8080
81+ def generate_regulator_bulk (p : Panel , options : Options ) -> str :
82+ if not options .regulator or len (options .regulator ) == 1 :
83+ return ''
84+
85+ s = '\n \n '
86+ s += f'static const struct regulator_bulk_data { p .short_id } _supplies[] = {{'
87+ for r in options .regulator :
88+ s += f'\n \t {{ .supply = "{ r } " }},'
89+ s += '\n };'
90+ return s
91+
92+
8193# msleep(< 20) will possibly sleep up to 20ms
8294# In this case, usleep_range should be used
8395def msleep (m : int ) -> str :
@@ -153,7 +165,7 @@ def generate_cleanup(p: Panel, options: Options, indent: int = 1) -> str:
153165 cleanup .append ('gpiod_set_value_cansleep(ctx->reset_gpio, 1);' )
154166 if options .regulator :
155167 if len (options .regulator ) > 1 :
156- cleanup .append ('regulator_bulk_disable(ARRAY_SIZE(ctx->supplies ), ctx->supplies);' )
168+ cleanup .append (f 'regulator_bulk_disable(ARRAY_SIZE({ p . short_id } _supplies ), ctx->supplies);' )
157169 else :
158170 cleanup .append ('regulator_disable(ctx->supply);' )
159171
@@ -183,12 +195,12 @@ def generate_prepare(p: Panel, options: Options) -> str:
183195
184196 if options .regulator :
185197 if len (options .regulator ) > 1 :
186- s += '''
187- ret = regulator_bulk_enable(ARRAY_SIZE(ctx->supplies ), ctx->supplies);
188- if (ret < 0) {
198+ s += f '''
199+ ret = regulator_bulk_enable(ARRAY_SIZE({ p . short_id } _supplies ), ctx->supplies);
200+ if (ret < 0) {{
189201 dev_err(dev, "Failed to enable regulators: %d\\ n", ret);
190202 return ret;
191- }
203+ }}
192204'''
193205 else :
194206 s += '''
@@ -364,14 +376,13 @@ def generate_probe(p: Panel, options: Options) -> str:
364376
365377 if options .regulator :
366378 if len (options .regulator ) > 1 :
367- i = 0
368- for i , r in enumerate (options .regulator ):
369- s += f'\n \t ctx->supplies[{ i } ].supply = "{ r } ";'
370379 s += f'''
371- ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(ctx->supplies),
372- ctx->supplies);
380+ ret = devm_regulator_bulk_get_const(dev,
381+ ARRAY_SIZE({ p .short_id } _supplies),
382+ { p .short_id } _supplies,
383+ &ctx->supplies);
373384 if (ret < 0)
374- return dev_err_probe(dev, ret, "Failed to get regulators \\ n") ;
385+ return ret;
375386'''
376387 else :
377388 s += f'''
@@ -523,7 +534,7 @@ def generate_driver(p: Panel, options: Options) -> None:
523534// Copyright (c) 2013, The Linux Foundation. All rights reserved. (FIXME)
524535{ generate_includes (p , options )}
525536
526- { generate_struct (p , options )}
537+ { generate_struct (p , options )} { generate_regulator_bulk ( p , options ) }
527538
528539{ wrap .simple ([f'static inline' , f'struct { p .short_id } *to_{ p .short_id } (struct drm_panel *panel)' ])}
529540{{
0 commit comments