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) |
| 217 | The 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 | |
| 219 | Gateworks 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 | |
| 221 | 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) 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). |
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]''' |
| 234 | The [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 |
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)" |
| 252 | Example module loading: |
| 253 | {{{#!bash |
| 254 | modprobe fw_name=nrc7292_cspi.bin bd_name=nrc7292_bd.dat spi_polling_interval=5 |
| 255 | }}} |
| 256 | |
| 257 | When using an OS like Ubuntu you create a file in /etc/modprobe.d/ to use these automatically when the module is loaded: |
| 258 | {{{#!bash |
| 259 | cat << EOF > /etc/modprobe.d/nrc.conf |
| 260 | options nrc fw_name=nrc7292_cspi.bin bd_name=nrc7292_bd.dat spi_polling_interval=5 |
| 261 | EOF |
| 262 | }}} |
| 263 | |
| 264 | To 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 |
| 266 | WLAN="$(for i in $(ls -d /sys/class/net/wlan* 2>/dev/null); do if [ -d $i/device/driver/spi* ]; then basename $i; fi; done)" |