diff --git a/dtsi.py b/dtsi.py index e82dceb..e943e10 100644 --- a/dtsi.py +++ b/dtsi.py @@ -3,6 +3,10 @@ from panel import Panel, BacklightControl +def has_gpio_backlight(options: Options): + return 'backlight' in options.gpios + + def generate_backlight(p: Panel): if p.backlight == BacklightControl.DCS: return "" @@ -14,6 +18,7 @@ def generate_supplies(options: Options): if options.regulator: for r in options.regulator: s += f"\t\t{r}-supply = <&...>;\n" + s += f"\n" return s @@ -22,6 +27,43 @@ def generate_gpios(options: Options): for name, flags in options.gpios.items(): flags = "GPIO_ACTIVE_LOW" if flags & GpioFlag.ACTIVE_LOW else "GPIO_ACTIVE_HIGH" s += f"\t\t{name}-gpios = <&tlmm XY {flags}>;\n" + + if has_gpio_backlight(options): + s += ''' + pinctrl-0 = <&lcd_bl_en_default>; + pinctrl-names = "default"; +''' + return s + + +def generate_tlmm(options: Options): + s = "&tlmm {" + if has_gpio_backlight(options): + s += ''' + lcd_bl_en_default: lcd-bl-en-default-state { + pins = "gpioXY"; + function = "gpio"; + drive-strength = <2>; + bias-disable; + }; +''' + + s += ''' + mdss_default: mdss-default-state { + pins = "gpioXY"; + function = "gpio"; + drive-strength = <8>; + bias-disable; + }; + + mdss_sleep: mdss-sleep-state { + pins = "gpioXY"; + function = "gpio"; + drive-strength = <2>; + bias-pull-down; + }; +}; +''' return s @@ -35,6 +77,10 @@ def generate_panel_dtsi(p: Panel, options: Options) -> None: ''') f.write(f'''\ &mdss_dsi0 {{ + pinctrl-0 = <&mdss_default>; + pinctrl-1 = <&mdss_sleep>; + pinctrl-names = "default", "sleep"; + panel@0 {{ compatible = "{options.compatible}"; reg = <0>; @@ -55,6 +101,7 @@ def generate_panel_dtsi(p: Panel, options: Options) -> None: data-lanes = <{' '.join(map(str, p.lane_map.phys2log[:p.lanes]))}>; remote-endpoint = <&panel_in>; }}; + ''') if p.ldo_mode: @@ -69,3 +116,5 @@ def generate_panel_dtsi(p: Panel, options: Options) -> None: phy-type = ; }; ''') + + f.write(f'''{generate_tlmm(options)}''')