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 WLAN support to device tree #3

Open hansemro opened 3 years ago

hansemro commented 3 years ago

Resources:

Based off board files, the kindle fire will share many similarities to 4430 SDP. In short, the following modifications will need to be made:

GPIO_WIFI_PMENA: 54 GPIO_WIFI_IRQ: 53

hansemro commented 3 years ago

arch/arm/boot/dts/omap4-kc1.dts

/ {
    ...
    /* regulator for wl12xx on sdio5 */
    wl12xx_vmmc: wl12xx_vmmc {
        pinctrl-names = "default";
        pinctrl-0 = <&wl12xx_gpio>;
        compatible = "regulator-fixed";
        regulator-name = "vwl1271";
        regulator-min-microvolt = <1800000>;
        regulator-max-microvolt = <1800000>;
        gpio = <&gpio2 22 GPIO_ACTIVE_HIGH>; /* gpio_54 */
        startup-delay-us = <70000>;
        enable-active-high;
    };
    ...
};
...
&omap4_pmx_core {
    ...
    uart2_pins: pinmux_uart2_pins {
        pinctrl-single,pins = <
            OMAP4_IOPAD(0x118, PIN_INPUT_PULLUP | MUX_MODE0)    /* uart2_cts.uart2_cts */
            OMAP4_IOPAD(0x11a, PIN_OUTPUT | MUX_MODE0)      /* uart2_rts.uart2_rts */
            OMAP4_IOPAD(0x11c, PIN_INPUT_PULLUP | MUX_MODE0)    /* uart2_rx.uart2_rx */
            OMAP4_IOPAD(0x11e, PIN_OUTPUT | MUX_MODE0)      /* uart2_tx.uart2_tx */
        >;
    };

    /* wl12xx GPIO output: WLAN_IRQ */
    wl12xx_gpio: pinmux_wl12xx_gpio {
        pinctrl-single,pins = <
            OMAP4_IOPAD(0x07a, PIN_OUTPUT | MUX_MODE3)      /* gpmc_ncs3.gpio_53 */
        >;
    };

    /* wl12xx GPIO inputs and WLAN_EN */
    wl12xx_pins: pinmux_wl12xx_pins {
        pinctrl-single,pins = <
            OMAP4_IOPAD(0x07c, PIN_INPUT | MUX_MODE3)       /* gpmc_nwp.gpio_54 */
            OMAP4_IOPAD(0x148, PIN_INPUT_PULLUP | MUX_MODE0)    /* sdmmc5_clk.sdmmc5_clk */
            OMAP4_IOPAD(0x14a, PIN_INPUT_PULLUP | MUX_MODE0)    /* sdmmc5_cmd.sdmmc5_cmd */
            OMAP4_IOPAD(0x14c, PIN_INPUT_PULLUP | MUX_MODE0)    /* sdmmc5_dat0.sdmmc5_dat0 */
            OMAP4_IOPAD(0x14e, PIN_INPUT_PULLUP | MUX_MODE0)    /* sdmmc5_dat1.sdmmc5_dat1 */
            OMAP4_IOPAD(0x150, PIN_INPUT_PULLUP | MUX_MODE0)    /* sdmmc5_dat2.sdmmc5_dat2 */
            OMAP4_IOPAD(0x152, PIN_INPUT_PULLUP | MUX_MODE0)    /* sdmmc5_dat3.sdmmc5_dat3 */
        >;
    };
    ...
};
...
&uart2 {
    pinctrl-names = "default";
    pinctrl-0 = <&uart2_pins>;
    status = "okay";
};

&mmc5 {
    pinctrl-names = "default";
    pinctrl-0 = <&wl12xx_pins>;
    status = "okay";
    vmmc-supply = <&wl12xx_vmmc>;
    non-removable;
    bus-width = <4>;
    cap-power-off-card;

    #address-cells = <1>;
    #size-cells = <0>;
    wlcore: wlcore@2 {
        compatible = "ti,wl1271";
        reg = <2>;
        interrupt-parent = <&gpio2>;
        interrupts = <21 IRQ_TYPE_LEVEL_HIGH>; /* gpio 53 */
        ref-clock-frequency = <38400000>;
        /*tcxo-clock-frequency = <26000000>;*/
    };
};

Issues:

5.11.0 dmesg
[    5.221221] reg-fixed-voltage wl12xx_vmmc: GPIO lookup for consumer (null)
[    5.230529] reg-fixed-voltage wl12xx_vmmc: using device tree for GPIO lookup
[    5.246887] of_get_named_gpiod_flags: can't parse 'gpios' property of node '/wl12xx_vmmc[0]'
[    5.256683] of_get_named_gpiod_flags: parsed 'gpio' property of node '/wl12xx_vmmc[0]' - status (0)
[    5.274414] vwl1271: 1800 mV, disabled
[    5.274414] reg-fixed-voltage wl12xx_vmmc: vwl1271 supplying 1800000uV
...
[   36.961303] vwl1271: disabling
mj-sakellaropoulos commented 3 years ago

Forced wl12xx_vmmc to always on

installed firmware via apk add linux-firmware-ti-connectivity

modprobe -a wlcore wl12xx wlcore_sdio Modules are loaded, regulatory.db loaded (I think) all with no errors.

But no /dev/wlan , nothing in sysfs either - no wlan device is created, no driver probe in dmesg, no firmware load attempt - nothing

hansemro commented 3 years ago

But no /dev/wlan , nothing in sysfs either - no wlan device is created

Something is wrong with the device tree. wl127x driver does not get loaded automatically

mj-sakellaropoulos commented 3 years ago

compatible string is right for sure

the rest seems pretty standard too

mj-sakellaropoulos commented 3 years ago

refclock is wrong , should be 38.4 MHz

hansemro commented 3 years ago

Yeah, you're right.

mj-sakellaropoulos commented 3 years ago

Actually, per https://github.com/torvalds/linux/blob/e4adffb8daf476a01e7b4a55f586dc8c26e81392/Documentation/devicetree/bindings/net/wireless/ti%2Cwlcore.txt#L26-L27

Since the clock is _XTAL , does the mean eXTernAL ? Then perhaps there are more nodes required for the clock setup

hansemro commented 3 years ago

xtal usually means crystal oscillator for clock

mj-sakellaropoulos commented 3 years ago

Enabled very verbose dmesg - I haven't seen anything interesting

hansemro commented 3 years ago

Related issue with what I encountered with 3.4.48 kernel: https://bugzilla.kernel.org/show_bug.cgi?id=119331 https://forum.digikey.com/t/pandaboard-a4-wifi-module-not-found/2951/5

It mentions TWL6030 driver not supporting 32kHz clock may cause issues.

hansemro commented 3 years ago

So the patch in the digikey post actually makes the wlcore/wl12xx modules load.

[   13.349822] wlcore: WARNING Detected unconfigured mac address in nvs, derive from fuse instead.
[   13.359558] wlcore: WARNING Your device performance is not optimized.
[   13.366455] wlcore: WARNING Please use the calibrator tool to configure your device.
[   13.374694] wlcore: WARNING Fuse mac address is zero. using random mac
[   13.381713] wlcore: WARNING NIC part of the MAC address wraps around!
[   13.402008] wlcore: loaded
[   17.395355] wlcore: firmware booted (Rev 6.3.10.0.142)

wlan0 also starts up! It needs to be calibrated, but I think we are getting closer.

https://web.archive.org/web/20160311003302/http://processors.wiki.ti.com/index.php/WL12xx_NLCP_Calibration_Process

hansemro commented 3 years ago

Building calibrator (on kindle):

apk add patch
wget http://www.infradead.org/~tgr/libnl/files/libnl-2.0.tar.gz
cd libnl-2.0
./configure
make
make install
cd ..
git clone https://github.com/TI-OpenLink/ti-utils
cd ti-utils
wget https://git.buildroot.net/buildroot/plain/package/ti-utils/0001-plt.h-fix-build-with-gcc-10.patch
patch -p1 < 0001-plt*.patch
make
hansemro commented 3 years ago

I guess calibration is not really required despite the warnings. I am able to connect to a network with nmtui and browse the web with w3m.

amazon-otter:~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: usb0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 3e:fa:88:ad:78:50 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.1/8 brd 10.255.255.255 scope global usb0
       valid_lft forever preferred_lft forever
    inet6 fe80::3cfa:88ff:fead:7850/64 scope link tentative 
       valid_lft forever preferred_lft forever
3: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN qlen 1000
    link/sit 0.0.0.0 brd 0.0.0.0
4: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 08:00:28:8b:f8:3d brd ff:ff:ff:ff:ff:ff
    inet 192.168.137.43/24 brd 192.168.137.255 scope global dynamic noprefixroute wlan0
       valid_lft 604395sec preferred_lft 604395sec
    inet6 fe80::6e22:b802:8519:7636/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
hansemro commented 3 years ago

image

hansemro commented 3 years ago

Added a patch to enable clk32kg required for wlan: 0742b657c4c5813cef63804dc2877549a05e5580

mj-sakellaropoulos commented 3 years ago

Applied patch on 5.11 , still no dice. Made sure to update DTB also. Any other steps/commands needed?

hansemro commented 3 years ago

Can you try this? v5.11_wlan.tar.gz

I did not take too many steps aside from installing ti firmware like you did above: apk add linux-firmware-ti-connectivity

I also realize that some of the network-related kernel config options I have selected are not necessary.

mj-sakellaropoulos commented 3 years ago

I must have mucked something up, testing now

mj-sakellaropoulos commented 3 years ago

When loading modules, I get unknown symbol error: (This is using your boot.img and modules)

/ # modprobe -a wlcore wl12xx wlcore_sdio wlcore_spi
modprobe: ERROR: could not insert 'wlcore': Unknown symbol in module, or unknown parameter (see dmesg)
modprobe: ERROR: could not insert 'wl12xx': Unknown symbol in module, or unknown parameter (see dmesg)
modprobe: ERROR: could not insert 'wlcore_sdio': Unknown symbol in module, or unknown parameter (see dmesg)
modprobe: ERROR: could not insert 'wlcore_spi': Unknown symbol in module, or unknown parameter (see dmesg)
hansemro commented 3 years ago

When loading modules, I get unknown symbol error:

Did you push the modules to /lib/modules/5.11.0+/ ? The modules should load automatically.

Maybe I did something wrong? I will check.

mj-sakellaropoulos commented 3 years ago

I think I did, unless it didn't work.

Triple checked it now, should be your modules in /lib.

My usual process is to create a tar file that has /lib/modules/5.11.0+ , then I untar it at the root directory

mj-sakellaropoulos commented 3 years ago

More detail in dmesg:

[  451.573944] cfg80211: Unknown symbol __stack_chk_guard (err -2)
[  451.711059] cfg80211: Unknown symbol __stack_chk_guard (err -2)
[  451.794769] wlcore_sdio: Unknown symbol __stack_chk_guard (err -2)
[  451.882629] wlcore_spi: Unknown symbol __stack_chk_guard (err -2)
[  869.729583] cfg80211: Unknown symbol __stack_chk_guard (err -2)
[  869.839538] cfg80211: Unknown symbol __stack_chk_guard (err -2)
[  869.923675] wlcore_sdio: Unknown symbol __stack_chk_guard (err -2)
[  870.001617] wlcore_spi: Unknown symbol __stack_chk_guard (err -2)
hansemro commented 3 years ago

I packaged the modules improperly. My bad.

mj-sakellaropoulos commented 3 years ago

What went wrong?

hansemro commented 3 years ago

I packaged with symbolic links rather than the actual files. So I am now using zip again.

v5.11_modules.zip v5.11_wlan2.tar.gz

Notes:

mj-sakellaropoulos commented 3 years ago

I packaged with symbolic links rather than the actual files

ah

mj-sakellaropoulos commented 3 years ago

Working 100%

Very cool !!!!!!!!!!!!!!!!

mj-sakellaropoulos commented 3 years ago

Just tried my devicetree with your kernel and it stopped working, looks like I had something wrong with my DTS.

hansemro commented 3 years ago

Just tried my devicetree with your kernel and it stopped working, looks like I had something wrong with my DTS.

Does the wlan regulator have regulator-always-on; property?

mj-sakellaropoulos commented 3 years ago

Yeah that property is there

it's probably due to some other changes I made while debugging

hansemro commented 3 years ago

Made some corrections to wlan dtsi in 82b2084ef42700db07b2af6fd40465c9faa8de03. @mj-sakellaropoulos Can you confirm that this works for you as well?

Fixes the following issue:

[   23.835388] wlcore: WARNING Detected unconfigured mac address in nvs, derive from fuse instead.
[   23.835723] wlcore: WARNING Your device performance is not optimized.
[   23.835784] wlcore: WARNING Please use the calibrator tool to configure your device.
[   23.835815] wlcore: WARNING Fuse mac address is zero. using random mac
[   23.835968] wlcore: WARNING NIC part of the MAC address wraps around!
[   23.853546] wlcore: loaded
[   24.716827] EXT4-fs (mmcblk0p12): re-mounted. Opts: (null). Quota mode: none.
[   28.097595] wlcore: firmware booted (Rev 6.3.10.0.142)
[   28.147521] wlcore: down
[   33.246154] wlcore: ERROR timeout waiting for the hardware to complete initialization
[   35.054229] VDAC: disabling
[   35.055816] VANA: disabling
[   37.380126] wlcore: ERROR timeout waiting for the hardware to complete initialization
[   41.491729] wlcore: ERROR timeout waiting for the hardware to complete initialization
[   41.491973] wlcore: ERROR firmware boot failed despite 3 retries

Steps to reproduce:

  1. Build https://gitlab.com/h_ro/pmaports/-/commit/e6aa84d30315c86dad5afc76e9c625fc2133393c with networkmanager
  2. Use stock partition layout and install boot to cache partition and root to media partition
  3. Start network manager: sudo rc-service networkmanager start
  4. check dmesg and nmtui and see that wlcore goes and stays down, and fails to load firmware

Changes:

After these changes, pmOS build can now powerdown and powerup wlan without issue.

mj-sakellaropoulos commented 3 years ago

Sure, I can test it Wednesday

(uni stuff until then)