Changes between Version 47 and Version 48 of expansion/gw16146


Ignore:
Timestamp:
02/14/2024 06:01:51 PM (9 months ago)
Author:
Tim Harvey
Comment:

updated module loading details based on latest driver changes

Legend:

Unmodified
Added
Removed
Modified
  • expansion/gw16146

    v47 v48  
    203203== Software
    204204Software support consists of the following items: (This a summary. Details are below)
    205  - Linux kernel driver for FT232H as a USB to SPI bridge
    206  - Linux kernel driver for the NRC7292 SPI Radio chip
    207   - Gateworks NRC7292 Driver: [https://github.com/Gateworks/nrc7292]
     205 - [https://github.com/Gateworks/ftdi-usb-spi Linux kernel driver for FT232H as a USB to SPI bridge on the GW16146]
     206 - [https://github.com/Gateworks/nrc7292 Linux kernel driver for the NRC7292 SPI Radio chip]
    208207 - Firmware files required for NRC7292 driver in /lib/firmware: nrc7292_cspi.bin and nrc7292_bd.dat
    209208 - Userspace cli_app application to performing miscellaneous configuration via Netlink to the NRC7292 driver
     
    214213 - Ventana Ubuntu Focal (20.04) pre-built images
    215214
    216 Gateworks NRC7292 Driver:
    217 [https://github.com/Gateworks/nrc7292]
    218 
    219 *** Note as of May 2023, the 5.15 kernel is required and 6.1 kernel support has not been added ***
    220 
    221215[=#spi_ft232h]
    222216=== FT232H USB to SPI bridge
    223 The FT232H features an multi-protocol engine that can be used for UART, JTAG, SPI among perhaps other things.
    224 
    225 Gateworks has programmed the USB VID:PID to 0x2beb:0x0146 which binds to the out-of-tree Linux kernel [https://github.com/Gateworks/ftdi-usb-spi spi-ft232h driver].
    226 
    227 When a GW16146 is found on the USB bus a SPI master host controller will be registered with the Linux kernel which you can see in /sys/class/spi_master. Note that various SoC's used for Gateworks boards also have built-in SPI controllers so you will need to look at the directory in /sys/class/spi_master to see what drivers each spi controller is bound to to find the right one.
    228 
    229 Examples:
    230  * show spi master controllers
    231 {{{#!bash
    232 ls /sys/class/spi_master/
    233 # spi1  spi3
    234 }}}
    235  * show drivers providing each master:
    236 {{{#!bash
    237 ls -l /sys/class/spi_master/
    238 #total 0
    239 #lrwxrwxrwx 1 root root 0 Aug 27 17:59 spi1 -> ../../devices/platform/soc@0/soc@0:bus@30800000/30830000.spi/spi_master/spi1
    240 #lrwxrwxrwx 1 root root 0 Aug 27 17:59 spi3 -> ../../devices/platform/soc@0/soc@0:bus@32c00000/32e50000.usb/ci_hdrc.1/usb2/2-1/2-1.3/2-1.3:1.0/spi-ft232h.0/spi_master/spi3
    241 
    242 for i in $(ls /sys/class/spi_master/); do echo $i:$(basename $(readlink /sys/class/spi_master/$i/device)); done
    243 # spi1:30830000.spi
    244 # spi3:spi-ft232h.0
    245 }}}
    246  * find spi master bound to spi-ft232h:
    247 {{{#!bash
    248 for i in $(ls /sys/class/spi_master/); do if [ "$(basename $(readlink /sys/class/spi_master/$i/device))" == "spi-ft232h.0" ]; then echo $i; fi; done
    249 # spi3
    250 }}}
    251  * assign the bus number of the first spi-ft232h bus to a var:
    252 {{{#!bash
    253 BUSNO=$(for i in $(ls /sys/class/spi_master/); do if [ "$(basename $(readlink /sys/class/spi_master/$i/device))" == "spi-ft232h.0" ]; then echo $i | sed 's/[^0-9]*//g'; fi; done)
    254 echo $BUSNO
    255 #3
    256 }}}
    257 
    258 Note that the SPI bus frequency can range from 450KHz to 30Mhz in 30MHz/n divisions where n is 1 to 65535 thus 30, 15, 10, 7.5, 6, 3.75MHz and so on. Invalid values will round up to the next highest freq. The frequency will be requested from the nrc.ko driver via the hifspeed kernel param (see below)
     217The FT232H features an multi-protocol engine that can be used for UART, JTAG, SPI, I2C among perhaps other things. The FT232H's MPSSE is great for generating signals to communicate using the SPI protocol. The MPSSE can take care of generating a clock signal from about 450hz to 30Mhz, and read & write bytes of data at that frequency.
     218
     219Gateworks has programmed the USB VID:PID on the GW16146 to 0x2beb:0x0146 which binds to the out-of-tree Linux kernel [https://github.com/Gateworks/ftdi-usb-spi spi-ft232h driver].
     220
     221When a GW16146 is found on the USB bus a SPI master host controller will be registered with the Linux kernel (which you can see in /sys/class/spi_master) as well as registers a nrc80211 SPI device which binds to the nrc7292 driver. Note that earlier versions of this driver required you to manually determine the SPI bus and manually probe the nrc driver with arguments pointing to the bus. Please make sure you are using the latest version of these drivers (available on the Gateworks pre-built Ubuntu based OS images) to avoid this (or refer to earlier documentation).
    259222
    260223Building:
     
    269232The Silex SX-NEWAH module on the GW16146 has a Newracom NRC7292 which is supported by [https://github.com/newracom/nrc7292_sw_pkg Newracom's open-source driver].
    270233
    271 However, the Newracom driver assumes a SoC GPIO is used for SPI IRQ and in the case of the GW16146 this does not exist. Therefore a SPI polling feature was added to the driver therefore '''Gateworks has its own [https://github.com/Gateworks/nrc7292 nrc7292] driver.'''
    272 
    273 '''View the [https://github.com/Gateworks/nrc7292 Gateworks Driver]'''
     234The [https://github.com/Gateworks/nrc7292 Gateworks nrc7292 driver] has some modifications to the Newracom NRC7292 driver:
     235 * add support for v6.2+
     236 * nrc-init: default to spi polling
     237 * nrc-hif-cspi: remove spam from spi_check_ready
     238 * nrc-mac80211: display wlan device registered
     239 * nrc: add display of driver version and chip identified
     240 * nrc: remove prints for non-errors
    274241
    275242nrc7292 driver history:
     
    278245 - v1.3 (April 2021) - Gateworks original driver
    279246
    280 nrc7292 driver notes:
    281  - the name the driver registers the wlan device with changes with the version of the driver being used. This name is used when determining which wlan device in your system is the nrc7292 device. The older v1.3 driver used the name of 'nrc80211' and the newer drivers use the 'spi<busno>.0' notation which depends on the SPI bus master
    282  - Linux 6.2 removed support for the spi_busnum_to_master() function which is currently what is used by the Gateworks nrc driver to find the spi master via kernel parameter. The [https://github.com/torvalds/linux/commit/bdc7ca008e1f5539e891187032cb2cbbc3decb5e kernel patch that removed this function] needs to be reverted in the kernel for this driver to work.
    283 
    284 There is a large set of kernel params (which you can see via 'modinfo nrc.ko')  but for our purposes the following are needed:
     247There is a large set of kernel params (which you can see via 'modinfo nrc.ko') but for our purposes the following are needed:
    285248 * fw_name - firmware file from /lib/firmware
    286249 * bd_name - Board data file from /lib/firmware
    287  * hifspeed - port speed in MHz (recommend 30000000 for 30MHz; available frequencies are 450KHz to 30Mhz in 30MHz/n divisions where n is 1 to 65535 thus 30, 15, 10, 7.5, 6, 3.75MHz and so on. Invalid values will round up to the next highest freq)
    288  * spi_bus_num - SPI bus number (find this dynamically from /sys/class/spi_master)
    289  * spi_cs_num - SPI chip select (must be 0 for FTDI USB_SPI bridge)
    290250 * spi_polling_interval - SPI polling interval in ms (recommend 5ms)
    291251
    292 The following steps have been condensed into a downloadable [http://trac.gateworks.com/attachment/wiki/expansion/gw16146/GW16146.sh script].
    293 
    294 You must determine the SPI bus at runtime which can be done via:
    295 {{{#!bash
    296 BUSNO=$(for i in $(ls /sys/class/spi_master/); do if [ "$(basename $(readlink /sys/class/spi_master/$i/device))" == "spi-ft232h.0" ]; then echo $i | sed 's/[^0-9]*//g'; fi; done)
    297 echo $BUSNO
    298 }}}
    299 
    300 Now the module can be loaded as such:
    301 {{{#!bash
    302 modprobe nrc fw_name=nrc7292_cspi.bin bd_name=nrc7292_bd.dat spi_bus_num=$BUSNO spi_polling_interval=5 hifspeed=30000000
    303 }}}
    304 
    305 After several seconds due to the timing of firmware loading you should see a new wlan device under /sys/class/net. To find the correct wlan interface that is bound to the NRC7292 driver:
    306 {{{#!bash
    307 LINK=nrc80211 # for older v1.3 of the nrc7292 driver
    308 LINK=spi$BUSNO.0 # for newer v1.5 of the nrc7292 driver
    309 WLAN="$(for i in $(ls -d /sys/class/net/wlan* 2>/dev/null); do if [ "$(basename $(readlink $i/device))" == "$LINK" ]; then basename $i; fi; done)"
     252Example module loading:
     253{{{#!bash
     254modprobe fw_name=nrc7292_cspi.bin bd_name=nrc7292_bd.dat spi_polling_interval=5
     255}}}
     256
     257When using an OS like Ubuntu you create a file in /etc/modprobe.d/ to use these automatically when the module is loaded:
     258{{{#!bash
     259cat << EOF > /etc/modprobe.d/nrc.conf
     260options nrc fw_name=nrc7292_cspi.bin bd_name=nrc7292_bd.dat spi_polling_interval=5
     261EOF
     262}}}
     263 
     264To find the correct wlan interface that is bound to the NRC7292 driver you can look at the devices in /sys/class/net to see which ones have a SPI based device-driver:
     265{{{#!bash
     266WLAN="$(for i in $(ls -d /sys/class/net/wlan* 2>/dev/null); do if [ -d $i/device/driver/spi* ]; then basename $i; fi; done)"
    310267echo $WLAN
    311268# wlan0
     
    450407# Bus 001 Device 003: ID 2beb:0146 
    451408}}}
    452  b. Obtain the SPI bus number created by the spi-ft232h driver which has bound to the GW16046 via VID/PID (Note that we save this in the BUSNO env variable which will be used below)
    453 {{{#!bash
    454 BUSNO="$(for i in $(ls /sys/class/spi_master/); do if [ "$(basename $(readlink /sys/class/spi_master/$i/device))" == "spi-ft232h.0" ]; then echo $i | sed 's/[^0-9]*//g'; fi; done)"
    455 echo $BUSNO
    456 # 3
    457 }}}
    458  c. Load the NRC7292 driver providing the SPI bus number from above (we use the BUSNO env var here):
    459 {{{#!bash
    460 modprobe nrc fw_name=nrc7292_cspi.bin bd_name=nrc7292_bd.dat spi_bus_num=$BUSNO # spi_polling_interval=5 hifspeed=30000000
     409 b. Load the NRC7292 driver providing the fw_name bd_name and spi_polling_interval parameters:
     410{{{#!bash
     411modprobe nrc fw_name=nrc7292_cspi.bin bd_name=nrc7292_bd.dat spi_polling_interval=5
    461412}}}
    462413  - after several seconds you should see a new wlan device under /sys/class/net
    463  d. obtain the wlan device that is bound to the driver (note it takes several seconds after loading the driver module for the device to get registered due to firmware loading and timing) (Note that we save this in the WLAN env variable which will be used below)
    464 {{{#!bash
    465 LINK=nrc80211 # for older v1.3 of the nrc7292 driver
    466 LINK=spi$BUSNO.0 # for newer v1.5 of the nrc7292 driver
    467 WLAN="$(for i in $(ls -d /sys/class/net/wlan* 2>/dev/null); do if [ "$(basename $(readlink $i/device))" == "$LINK" ]; then basename $i; fi; done)"
     414 c. find the correct wlan interface that is bound to the NRC7292 driver by looking for a devices in /sys/class/net with a SPI based device-driver:
     415{{{#!bash
     416WLAN="$(for i in $(ls -d /sys/class/net/wlan* 2>/dev/null); do if [ -d $i/device/driver/spi* ]; then basename $i; fi; done)"
    468417echo $WLAN
    469418# wlan0
    470419}}}
    471  e. set the country code (required for newer versions of the driver)
     420 d. set the country code (required for newer versions of the driver)
    472421{{{#!bash
    473422iw reg set US
    474423}}}
    475  f. bring up the interface (required for configuration below)
     424 e. bring up the interface (required for configuration below)
    476425{{{#!bash
    477426ifconfig $WLAN up