hansemro / kc1-linux

Documentation of mainline Linux on First Generation Kindle Fire
GNU General Public License v2.0
4 stars 0 forks source link

Add backlight support to device tree #11

Closed hansemro closed 2 years ago

hansemro commented 3 years ago

References:

Notes:

Status:

hansemro commented 3 years ago

Backlight does not seem to be driven by twl-pwm nor twl-pwmled, but rather by an external IC (O2Micro)

hansemro commented 3 years ago

do_setbacklight routine notes: https://github.com/Hashcode/u-boot/blob/p-ti-u-boot-2014.01/board/ti/omap4_kc1/kc1_backlight.c

From OMAP4430 Reference Manual (pg 4423): GPTIMER10 Base Address: 0x48086000 GPTIMER Size: 4KB CM_L4PER_GPTIMER10_CLKCTRL: 0x4A009428

Used GPTIMER10 Registers: (used to configure PWM)

GPIO 119, 120 (handled by GPIO3): ?

CONTROL_CORE_PAD0_ABE_DMIC_CLK1_PAD1_ABE_DMIC_DIN1: 0x4a100110

GPIO3.GPIO_OE (Output Enable): 0x48059134

GPIO3.DATA_OUT: 0x4805913C

Parameter backlight is 8 bits to set 256 PWM steps.

Experimental result by setting memory mapped pins from U-Boot console:

U-Boot# mw.l 0x48086024 0x01863; mw.l 0x48086038 0xffffff00
U-Boot# mw.l 0x48086024 0x01863; mw.l 0x48086038 0xffffff30
U-Boot# mw.l 0x48086024 0x01863; mw.l 0x48086038 0xfffffffe
U-Boot# mw.l 0x48086024 0x018e3; mw.l 0x48086038 0xffffff00
hansemro commented 3 years ago

Backlight brightness turns out to be pretty straightforward.

amazon-otter:~# uname -a
Linux amazon-otter 3.4.48+ #24 SMP PREEMPT Tue Mar 2 01:53:11 PST 2021 armv7l GNU/Linux
## Install pydevmem https://pypi.org/project/devmem/
amazon-otter:~# pip3 install devmem
...
amazon-otter:~# pydevmem -r 0x48086024 
0x48086024:   00001863 
amazon-otter:~# pydevmem -r 0x48086038
0x48086038:   ffffff68
amazon-otter:~# pydevmem -w 0x48086038 0xffffff00
## display is dimmer, but not off
hansemro commented 3 years ago

The same method will not work with mainline and current device tree.

amazon-otter:~# uname -a
Linux amazon-otter 5.11.0+ #33 SMP Wed Apr 21 21:20:33 PDT 2021 armv7l GNU/Linux
amazon-otter:~# pydevmem -r 0x48086024 
Bus error
amazon-otter:~# pydevmem -r 0x48086038
Bus error
amazon-otter:~# pydevmem -r 0x4a100110
0x4a100110:   001b001b 
amazon-otter:~# pydevmem -r 0x48059134
Bus error
amazon-otter:~# pydevmem -r 0x4805913C
Bus error
hansemro commented 3 years ago
5.11.0 kernel /proc/iomem
amazon-otter:~# uname -a
Linux amazon-otter 5.11.0+ #33 SMP Wed Apr 21 21:20:33 PDT 2021 armv7l GNU/Linux
amazon-otter:~# cat /proc/iomem
40130000-4013007f : 40130000.wdt wdt@0
40138000-4013807f : 40138000.timer timer@0
4013a000-4013a07f : 4013a000.timer timer@0
4013c000-4013c07f : 4013c000.timer timer@0
4013e000-4013e07f : 4013e000.timer timer@0
40304000-4030dfff : 40304000.sram sram@40304000
44000000-44000fff : 44000000.ocp ocp
44800000-44801fff : 44000000.ocp ocp
45000000-45000fff : 44000000.ocp ocp
48020000-480200ff : 48020000.serial serial@0
48032000-4803207f : 48032000.timer timer@0
48034000-4803407f : 48034000.timer timer@0
48036000-4803607f : 48036000.timer timer@0
4803e000-4803e07f : 4803e000.timer timer@0
48055000-480551ff : 48055000.gpio gpio@0
48057000-480571ff : 48057000.gpio gpio@0
48059000-480591ff : 48059000.gpio gpio@0
4805b000-4805b1ff : 4805b000.gpio gpio@0
4805d000-4805d1ff : 4805d000.gpio gpio@0
48060000-480600ff : 48060000.i2c i2c@0
4806a000-4806a0ff : 4806a000.serial serial@0
4806c000-4806c0ff : 4806c000.serial serial@0
4806e000-4806e0ff : 4806e000.serial serial@0
48070000-480700ff : 48070000.i2c i2c@0
48072000-480720ff : 48072000.i2c i2c@0
48086000-4808607f : 48086000.timer timer@0
48088000-4808807f : 48088000.timer timer@0
48098000-480981ff : 48098000.spi spi@0
4809a000-4809a1ff : 4809a000.spi spi@0
480b4000-480b43ff : 480b4000.mmc mmc@0
480b8000-480b81ff : 480b8000.spi spi@0
480ba000-480ba1ff : 480ba000.spi spi@0
480d5000-480d53ff : 480d5000.mmc mmc@0
48350000-483500ff : 48350000.i2c i2c@0
4a002260-4a002263 : 4a002260.bandgap bandgap@4a002260
4a002300-4a002303 : 4a002300.control-phy power
4a00232c-4a00232f : 4a002260.bandgap bandgap@4a002260
4a00233c-4a00233f : 4a00233c.control-phy otghs_control
4a056000-4a056fff : 4a056000.dma-controller dma-controller@0
4a062000-4a062fff : 4a062000.usbhstll usbhstll@0
4a064000-4a0647ff : 4a064000.usbhshost usbhshost@0
4a064800-4a064bff : 4a064800.ohci ohci@800
4a064c00-4a064fff : 4a064c00.ehci ehci@c00
4a066000-4a0660ff : 4a066000.mmu mmu@0
4a0ab000-4a0ab7fe : usb_otg_hs@0
  4a0ab000-4a0ab7fe : musb-hdrc.0.auto usb_otg_hs@0
4a0ad000-4a0ad01e : 4a0ad000.ocp2scp ocp2scp@0
4a0ad080-4a0ad0d7 : 4a0ad080.usb2phy usb2phy@80
4a0f4000-4a0f41ff : 4a0f4000.mailbox mailbox@0
4a0f6000-4a0f6fff : 4a0f6000.spinlock spinlock@0
4a100040-4a1001d5 : pinctrl-single
4a306300-4a3063ff : 4a306300.prm prm@300
4a306400-4a3064ff : 4a306400.prm prm@400
4a306500-4a3065ff : 4a306500.prm prm@500
4a306600-4a3066ff : 4a306600.prm prm@600
4a306700-4a3067ff : 4a306700.prm prm@700
4a306f00-4a306fff : 4a306f00.prm prm@f00
4a307000-4a3070ff : 4a307000.prm prm@1000
4a307100-4a30713f : 4a307100.prm prm@1100
4a307200-4a3072ff : 4a307200.prm prm@1200
4a307300-4a3073ff : 4a307300.prm prm@1300
4a307400-4a3074ff : 4a307400.prm prm@1400
4a307600-4a3076ff : 4a307600.prm prm@1600
4a307700-4a3077ff : 4a307700.prm prm@1700
4a307900-4a3079ff : 4a307900.prm prm@1900
4a307b00-4a307b3f : 4a307b00.prm prm@1b00
4a307bd0-4a307bd7 : 4a307bd0.regulator-abb-mpu base-address
4a310000-4a3101ff : 4a310000.gpio gpio@0
4a314000-4a31407f : 4a314000.wdt wdt@0
4a31e040-4a31e077 : pinctrl-single
50000000-50000fff : 50000000.gpmc gpmc@50000000
55082000-550820ff : 55082000.mmu mmu@0
58000000-5800007f : 58000000.dss dss@0
58001000-58001fff : 58001000.dispc dispc@0
58005000-580051ff : 58005000.encoder proto
58005200-5800523f : 58005000.encoder phy
58005300-5800531f : 58005000.encoder pll
80000000-9fdfffff : System RAM
  80008000-811fffff : Kernel code
  81300000-81a6aea3 : Kernel data
hansemro commented 3 years ago

This has bad GPIO pin configurations:

arch/arm/boot/dts/omap4-kc1.dts: backlight on/off only

/ {
    ...
    bl: backlight {
        pinctrl-names = "default";
        pinctrl-0 = <&backlight_pins>;
        compatible = "pwm-backlight";
        brightness-levels = <0 4 8 16 32 64 128 255>;
        num-interpolated-steps = <256>;
        default-brightness-level = <4>;
        enable-gpio = <
            &gpio2 15 GPIO_ACTIVE_HIGH /* gpio_47 3V3_EN */
            >;
        power-supply = <&lcd2_power>;
        pwms = <&pwm10 0 75000 0>; /* 75 KHz */
    };

    pwm10: dmtimer-pwm@10 {
        pinctrl-names = "default";
        pinctrl-0 = <&timer10_pins>;
        gpio = <&gpio2 30 GPIO_ACTIVE_HIGH>; /* gpio_94 */
        compatible = "ti,omap-dmtimer-pwm";
        ti,timers = <&timer10>;
        ti,prescaler = <0>; /* prescale = 1 */
        ti,clock-source = <1>; /* 32 KHz source */
        #pwm-cells = <3>;
    };
    ...
};
...
&omap4_pmx_core {
    ...
    backlight_pins: pinmux_backlight_pins {
        pinctrl-single,pins = <
            OMAP4_IOPAD(0x06e, PIN_OUTPUT | MUX_MODE3) /* gpio_47 3V3 rail enable */
        >;
    };

    timer10_pins: pinmux_timer10_pins {
        pinctrl-single,pins = <
            OMAP4_IOPAD(0x0d6, PIN_OUTPUT | MUX_MODE1) /* dmtimer10_pwm_evt.gpio_94*/
        >;
    };
    ...
};
hansemro commented 3 years ago
hansemro commented 2 years ago

Managed to get proper backlight control with the following changes:

Change GPTimer10 clock source to high-frequency System Clock instead of 32kHz source:

Before:

ti,clock-source = <1>; /* 32 KHz source */

After:

ti,clock-source = <0>; /* high frequency sysclk */

Correctly convert frequency to period (in ns) for 2nd cell

Before:

pwms = <&pwm10 0 75000 0>; /* 75 KHz */

After:

pwms = <&pwm10 0 13333 0>; /* 75 KHz */
hansemro commented 2 years ago

Fixed in https://github.com/hansemro/kc1-linux/commit/a726042ca731e3e087450a53e9fb6b1f60a2aa52.

Note: Apply this patch after applying 0001-Update-device-tree-for-omap4-kc1.patch.