TX2 LCD0_BKLT_PWM can not enable output

I want enable the backlight for output pwm by LCD0_BKLT_PWM on R32.4.3.

I tracked the code:
tegra_dc_is_nvdisplay() return false in ./panel/board-panel.c.
It should return true on tx2 module.

Here is my dts fragment :

            dsi {
                    status = "okay";

                    nvidia,active-panel = <&panel_s_wuxga_8_0>;
                    panel-s-wuxga-8-0 {
                            bootloader-status = "disabled";
                            status = "okay";
                            nvidia,panel-rst-gpio = <&tegra_aon_gpio TEGRA_AON_GPIO(U, 3) 1>; //PU3
                            nvidia,panel-en-gpio = <&tegra_main_gpio TEGRA_MAIN_GPIO(P, 3) 1>; // PP3

                            nvidia,panel-bl-pwm-gpio = <&tegra_aon_gpio TEGRA_AON_GPIO(U, 0) 1>; // PU0

                            nvidia,panel-bl-en-gpio = <&tegra_aon_gpio TEGRA_AON_GPIO(U, 1) 1>;  //always

                            nvidia,en-vmm-vpp-with-i2c-config;


                    };

            };

            nvdisplay@15200000 {
                    status = "okay";
                    win-mask = <0x7>;
                    nvidia,fb-win = <0>;
                    nvidia,dc-or-node = "/host1x/dsi";
                    avdd_lcd-supply = <&dsi_power_en>;
                    avdd_dsi_csi-supply = <&spmic_sd1>;
                    dvdd_lcd-supply =<&battery_reg>;

                    outp-supply = <&battery_reg>;
                    outn-supply = <&battery_reg>;
                    vdd_lcd_bl-supply = <&battery_reg>;
                    vdd_lcd_bl_en-supply =<&battery_reg>;

            };

    backlight { 
            status = "okay";
            compatible = "pwm-backlight";

            pwms = <&tegra_pwm1 1 40161>;
            max-brightness = <255>;
            default-brightness = <255>;
            default-charge-brightness = <255>;
            bl-measured = <0x0 0x1 0x2 0x3 0x4 0x5 0x5 0x6 0x7 0x8 0x9 0xa 0xb 0xb 0xc 0xd 0xe 0xf 0xf 0x10 0x11 0x12 0x13 0x14 0x15 0x16 0x16 0x17 0x18 0x19 0x1a 0x1b 0x1c 0x1d 0x1e 0x1f 0x1f 0x20 0x21 0x22 0x23 0x24 0x25 0x25 0x26 0x27 0x28 0x29 0x29 0x2a 0x2b 0x2c 0x2d 0x2e 0x2f 0x30 0x30 0x31 0x32 0x33 0x34 0x35 0x36 0x36 0x37 0x38 0x39 0x3a 0x3a 0x3b 0x3c 0x3d 0x3e 0x3f 0x40 0x41 0x42 0x43 0x44 0x45 0x46 0x47 0x48 0x49 0x4a 0x4b 0x4b 0x4c 0x4d 0x4e 0x4f 0x50 0x51 0x52 0x53 0x54 0x55 0x56 0x57 0x58 0x59 0x5a 0x5b 0x5c 0x5d 0x5e 0x5e 0x5f 0x60 0x61 0x62 0x63 0x64 0x65 0x66 0x68 0x69 0x6a 0x6b 0x6c 0x6d 0x6e 0x6f 0x70 0x71 0x72 0x73 0x74 0x75 0x76 0x77 0x78 0x79 0x7a 0x7b 0x7d 0x7e 0x7f 0x80 0x81 0x82 0x83 0x84 0x85 0x86 0x87 0x88 0x89 0x8a 0x8b 0x8c 0x8d 0x8e 0x8f 0x90 0x92 0x93 0x94 0x95 0x96 0x97 0x98 0x99 0x9a 0x9b 0x9c 0x9d 0x9e 0x9f 0xa0 0xa1 0xa2 0xa3 0xa4 0xa5 0xa7 0xa8 0xa9 0xaa 0xab 0xac 0xad 0xae 0xaf 0xb0 0xb2 0xb3 0xb4 0xb5 0xb6 0xb7 0xb8 0xb9 0xba 0xbb 0xbc 0xbd 0xbe 0xbf 0xc0 0xc1 0xc2 0xc3 0xc4 0xc5 0xc7 0xc8 0xc9 0xca 0xcb 0xcc 0xcd 0xce 0xcf 0xd0 0xd2 0xd3 0xd4 0xd5 0xd6 0xd7 0xd8 0xd9 0xdb 0xdc 0xdd 0xde 0xdf 0xe1 0xe2 0xe3 0xe4 0xe5 0xe6 0xe7 0xe9 0xea 0xeb 0xec 0xed 0xee 0xef 0xf0 0xf1 0xf2 0xf4 0xf5 0xf6 0xf7 0xf8 0xf9 0xfa 0xfb 0xfd 0xfe 0xff>;

            power-supply = <&battery_reg>;

            /delete-node/ panel-a-edp-1080p-14-0-bl;
            /delete-node/ panel-s-wqxga-10-1-bl;
            /delete-node/ panel-s-edp-uhdtv-15-6-bl;
    };

    backlight {/*add by geng  for LCD backlight pwm*/
            panel_s_wuxga_8_0_bl: panel-s-wuxga-8-0-bl {
                    status = "okay";
                    compatible = "s,wuxga-8-0-bl";
                    pwms = <&tegra_pwm1 1 40161>;
                    max-brightness = <255>;
                    default-brightness = <255>;
                    default-charge-brightness = <255>;
                    bl-measured = < 0 1 2 3 4 5 5 6
                                    7 8 9 10 11 11 12 13
                                    14 15 15 16 17 18 19 20
                                    21 22 22 23 24 25 26 27
                                    28 29 30 31 31 32 33 34
                                    35 36 37 37 38 39 40 41
                                    41 42 43 44 45 46 47 48
                                    48 49 50 51 52 53 54 54
                                    55 56 57 58 58 59 60 61
                                    62 63 64 65 66 67 68 69
                                    70 71 72 73 74 75 75 76
                                    77 78 79 80 81 82 83 84
                                    85 86 87 88 89 90 91 92
                                    93 94 94 95 96 97 98 99
                                    100 101 102 104 105 106 107 108
                                    109 110 111 112 113 114 115 116
                                    117 118 119 120 121 122 123 125
                                    126 127 128 129 130 131 132 133
                                    134 135 136 137 138 139 140 141
                                    142 143 144 146 147 148 149 150
                                    151 152 153 154 155 156 157 158
                                    159 160 161 162 163 164 165 167
                                    168 169 170 171 172 173 174 175
                                    176 178 179 180 181 182 183 184
                                    185 186 187 188 189 190 191 192
                                    193 194 195 196 197 199 200 201
                                    202 203 204 205 206 207 208 210
                                    211 212 213 214 215 216 217 219
                                    220 221 222 223 225 226 227 228
                                    229 230 231 233 234 235 236 237
                                    238 239 240 241 242 244 245 246
                                    247 248 249 250 251 253 254 255 >;
            };
    };

log fragment :

[ 0.924802]
====tegra_available_pwm_bl_ops_register()=====
[ 0.924981] tegra-pcie 10003000.pcie-controller: probing port 0, using 2 lanes
[ 0.925043] pwm-backlight backlight: unable to request PWM
[ 0.925096] pwm-backlight: probe of backlight failed with error -22
[ 0.925305] tegra_camera_platform tegra-camera-platform: tegra_camera_probe:camera_platform_driver probe
[ 0.925415] misc tegra_camera_ctrl: tegra_camera_isomgr_register isp_iso_bw=1875000, vi_iso_bw=750000, max_bw=1875000
[ 0.927938] tsec 15500000.tsec: initialized
[ 0.928986] tsec 15100000.tsecb: initialized
[ 0.931402] nvdec 15480000.nvdec: initialized
[ 0.935756] falcon 15340000.vic: initialized
[ 0.937036] falcon 154c0000.nvenc: initialized
[ 0.938242] falcon 15380000.nvjpg: initialized
[ 0.940008] iommu_context_dev 13e10000.host1x:ctx0: initialized (streamid=56)
[ 0.941299] iommu_context_dev 13e10000.host1x:ctx1: initialized (streamid=57)
[ 0.942612] iommu_context_dev 13e10000.host1x:ctx2: initialized (streamid=58)
[ 0.943932] iommu_context_dev 13e10000.host1x:ctx3: initialized (streamid=59)
[ 0.945279] iommu_context_dev 13e10000.host1x:ctx4: initialized (streamid=60)
[ 0.946679] iommu_context_dev 13e10000.host1x:ctx5: initialized (streamid=61)
[ 0.947977] iommu_context_dev 13e10000.host1x:ctx6: initialized (streamid=62)
[ 0.949280] iommu_context_dev 13e10000.host1x:ctx7: initialized (streamid=63)
[ 0.952061] tegradccommon 15200000.dc_common: host1x channel mapped
[ 0.952069] tegradccommon 15200000.dc_common: dc_common syncpt # 1 allocated
[ 0.952096] tegradccommon 15200000.dc_common: dma mapping done
[ 0.952431] tegra_cec 3960000.tegra_cec: dt=1 start=0x03960000 end=0x03960FFF irq=392
[ 0.952594] tegradc 15200000.nvdisplay: disp0 connected to head0->/host1x/dsi
[ 0.952716] tegradc 15200000.nvdisplay: No hpd-gpio in DT
[ 0.952850] tegradc 15200000.nvdisplay: DT parsed successfully
[ 0.952867] tegradc 15200000.nvdisplay: Display dc.ffffff800b3e0000 registered with id=0
[ 0.953130] tegra_cec 3960000.tegra_cec: Unpowergate DISP: 0.
[ 0.953950] tegra_cec 3960000.tegra_cec: Enable clock result: 0.
[ 0.953964] tegra_cec 3960000.tegra_cec: tegra_cec_init started
[ 0.954121] tegra_cec 3960000.tegra_cec: cec_add_sysfs ret=0
[ 0.954125] tegra_cec 3960000.tegra_cec: probed
[ 0.957439] tegra_nvdisp_bandwidth_register_max_config: max config iso bw = 16727000 KB/s
[ 0.957443] tegra_nvdisp_bandwidth_register_max_config: max config EMC floor = 665600000 Hz
[ 0.957446] tegra_nvdisp_bandwidth_register_max_config: max config hubclk = 357620000 Hz
[ 0.957615] tegradc 15200000.nvdisplay: vblank syncpt # 8 for dc 0
[ 0.957621] tegradc 15200000.nvdisplay: vpulse3 syncpt # 9 for dc 0
[ 0.965999] tegra-pcie 10003000.pcie-controller: PCI host bridge to bus 0000:00

I remember that issue is due to the pwm-backlight driver is getting called earlier than the nvdisplay driver.

Which means tegra_dc_hw_init is not getting called yet. The “tegra_dc_is_nvdisplay” will only return true if the tegra_dc_hw_init is done and you are TX2 board.

Thus, you can workaround it by remove the check inside board-panel.c.

I changed the board-panel.c

void tegra_pwm_bl_ops_register(struct device *dev)
{
bool ret = 0;

    if (tegra_dc_is_nvdisplay())
            return;

return; //2021-07-22

    ret = tegra_available_pwm_bl_ops_register(dev);
    if (!ret)
            tegra_pwm_bl_ops_reg_based_on_disp_board_id(dev);

}

But, log output

[ 0.916690] pwm-backlight backlight: unable to request PWM
[ 0.916743] pwm-backlight: probe of backlight failed with error -22

ls /sys/class/backlight/
no file be created in ./backlight/

Your issue is totally same as this guy.

Please check.

https://forums.developer.nvidia.com/t/tt2-4g-r32-3-1-lcd0-bklt-pwm/163852/81