aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-10-29 13:38:10 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-10-29 13:38:10 -0400
commit738b04fba18d35cd352b7b15afefb8a7b798648e (patch)
tree07fabb1a920af5c92bd35e10f9821cf56c8de3e4
parentfe675d4d3c6b96710d481346821839b4a817c672 (diff)
parent4ab7e05dd070600833680bd318d6d962f010caa2 (diff)
Merge tag 'staging-4.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging
Pull staging/IIO driver updates from Greg KH: "Here is the big staging and IIO driver pull request for 4.20-rc1. There are lots of things here, we ended up adding more lines than removing, thanks to a large influx of Comedi National Instrument device support. Someday soon we need to get comedi out of staging... Other than the comedi drivers, the "big" things here are: - new iio drivers - delete dgnc driver (no one used it and no one had the hardware anymore) - vbox driver updates and fixes - erofs fixes - tons and tons of tiny checkpatch fixes for almost all staging drivers All of these have been in linux-next, with the last few happening a bit "late" due to them getting stuck on my laptop during travel to the Mantainers summit" * tag 'staging-4.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging: (690 commits) staging: gasket: Fix sparse "incorrect type in assignment" warnings. staging: gasket: remove debug logs for callback invocation staging: gasket: remove debug logs in page table mapping calls staging: rtl8188eu: core: Use sizeof(*p) instead of sizeof(struct P) for memory allocation staging: ks7010: Remove extra blank line staging: gasket: Remove extra blank line staging: media: davinci_vpfe: Fix spelling mistake in enum staging: speakup: Add a pair of braces staging: wlan-ng: Replace long int with long staging: MAINTAINERS: remove obsolete IPX staging directory staging: MAINTAINERS: remove NCP filesystem entry staging: rtl8188eu: cleanup comparsions to false staging: gasket: Update device virtual address comment staging: gasket: sysfs: fix attribute release comment staging: gasket: apex: fix sysfs_show staging: gasket: page_table: simplify gasket_components_to_dev_address staging: gasket: page_table: fix comment in components_to_dev_address staging: gasket: page table: fixup error path allocating coherent mem staging: gasket: page_table: rearrange gasket_page_table_entry staging: gasket: page_table: remove unnecessary PTE status set to free ...
-rw-r--r--Documentation/ABI/testing/sysfs-bus-iio2
-rw-r--r--Documentation/devicetree/bindings/iio/accel/adxl372.txt33
-rw-r--r--Documentation/devicetree/bindings/iio/adc/mcp3911.txt30
-rw-r--r--Documentation/devicetree/bindings/iio/adc/qcom,spmi-vadc.txt81
-rw-r--r--Documentation/devicetree/bindings/iio/adc/sprd,sc27xx-adc.txt4
-rw-r--r--Documentation/devicetree/bindings/iio/dac/ad5758.txt5
-rw-r--r--Documentation/devicetree/bindings/iio/dac/ltc1660.txt21
-rw-r--r--Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt1
-rw-r--r--Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt1
-rw-r--r--Documentation/devicetree/bindings/iio/light/bh1750.txt18
-rw-r--r--Documentation/devicetree/bindings/iio/light/tsl2772.txt42
-rw-r--r--Documentation/devicetree/bindings/iio/proximity/vl53l0x.txt12
-rw-r--r--Documentation/devicetree/bindings/trivial-devices.txt10
-rw-r--r--Documentation/filesystems/pohmelfs/design_notes.txt72
-rw-r--r--Documentation/filesystems/pohmelfs/info.txt99
-rw-r--r--Documentation/filesystems/pohmelfs/network_protocol.txt227
-rw-r--r--MAINTAINERS52
-rw-r--r--drivers/iio/accel/Kconfig27
-rw-r--r--drivers/iio/accel/Makefile3
-rw-r--r--drivers/iio/accel/adxl345_i2c.c5
-rw-r--r--drivers/iio/accel/adxl372.c975
-rw-r--r--drivers/iio/accel/adxl372.h17
-rw-r--r--drivers/iio/accel/adxl372_i2c.c61
-rw-r--r--drivers/iio/accel/adxl372_spi.c52
-rw-r--r--drivers/iio/adc/Kconfig30
-rw-r--r--drivers/iio/adc/Makefile2
-rw-r--r--drivers/iio/adc/ad7298.c2
-rw-r--r--drivers/iio/adc/ad7476.c2
-rw-r--r--drivers/iio/adc/ad7793.c2
-rw-r--r--drivers/iio/adc/ad7887.c2
-rw-r--r--drivers/iio/adc/ad7923.c2
-rw-r--r--drivers/iio/adc/ad799x.c2
-rw-r--r--drivers/iio/adc/at91_adc.c6
-rw-r--r--drivers/iio/adc/envelope-detector.c5
-rw-r--r--drivers/iio/adc/fsl-imx25-gcq.c6
-rw-r--r--drivers/iio/adc/max9611.c2
-rw-r--r--drivers/iio/adc/mcp3911.c363
-rw-r--r--drivers/iio/adc/meson_saradc.c70
-rw-r--r--drivers/iio/adc/qcom-pm8xxx-xoadc.c4
-rw-r--r--drivers/iio/adc/qcom-spmi-adc5.c793
-rw-r--r--drivers/iio/adc/qcom-vadc-common.c189
-rw-r--r--drivers/iio/adc/qcom-vadc-common.h54
-rw-r--r--drivers/iio/adc/rcar-gyroadc.c12
-rw-r--r--drivers/iio/adc/sc27xx_adc.c154
-rw-r--r--drivers/iio/adc/ti-ads7950.c53
-rw-r--r--drivers/iio/amplifiers/ad8366.c2
-rw-r--r--drivers/iio/chemical/bme680.h19
-rw-r--r--drivers/iio/chemical/bme680_core.c154
-rw-r--r--drivers/iio/dac/Kconfig10
-rw-r--r--drivers/iio/dac/Makefile1
-rw-r--r--drivers/iio/dac/ad5064.c53
-rw-r--r--drivers/iio/dac/ad5446.c2
-rw-r--r--drivers/iio/dac/ad5504.c2
-rw-r--r--drivers/iio/dac/ad5686.c2
-rw-r--r--drivers/iio/dac/ad5758.c26
-rw-r--r--drivers/iio/dac/ad5791.c2
-rw-r--r--drivers/iio/dac/dpot-dac.c5
-rw-r--r--drivers/iio/dac/ltc1660.c250
-rw-r--r--drivers/iio/dac/max517.c11
-rw-r--r--drivers/iio/dac/max5821.c11
-rw-r--r--drivers/iio/dac/mcp4725.c12
-rw-r--r--drivers/iio/dac/mcp4922.c11
-rw-r--r--drivers/iio/dac/ti-dac5571.c1
-rw-r--r--drivers/iio/frequency/ad9523.c2
-rw-r--r--drivers/iio/frequency/adf4350.c2
-rw-r--r--drivers/iio/health/max30102.c6
-rw-r--r--drivers/iio/imu/inv_mpu6050/inv_mpu_core.c62
-rw-r--r--drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h2
-rw-r--r--drivers/iio/imu/st_lsm6dsx/Kconfig2
-rw-r--r--drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h18
-rw-r--r--drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c166
-rw-r--r--drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c51
-rw-r--r--drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c5
-rw-r--r--drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c5
-rw-r--r--drivers/iio/light/bh1750.c25
-rw-r--r--drivers/iio/light/max44000.c1
-rw-r--r--drivers/iio/light/tsl2772.c194
-rw-r--r--drivers/iio/magnetometer/hmc5843.h2
-rw-r--r--drivers/iio/multiplexer/iio-mux.c5
-rw-r--r--drivers/iio/potentiometer/max5481.c7
-rw-r--r--drivers/iio/potentiometer/mcp4018.c9
-rw-r--r--drivers/iio/potentiometer/mcp4531.c14
-rw-r--r--drivers/iio/pressure/ms5611.h5
-rw-r--r--drivers/iio/pressure/ms5611_core.c5
-rw-r--r--drivers/iio/pressure/ms5611_i2c.c7
-rw-r--r--drivers/iio/pressure/ms5611_spi.c7
-rw-r--r--drivers/iio/proximity/Kconfig11
-rw-r--r--drivers/iio/proximity/Makefile2
-rw-r--r--drivers/iio/proximity/isl29501.c12
-rw-r--r--drivers/iio/proximity/vl53l0x-i2c.c164
-rw-r--r--drivers/iio/trigger/iio-trig-sysfs.c2
-rw-r--r--drivers/staging/Kconfig2
-rw-r--r--drivers/staging/Makefile1
-rw-r--r--drivers/staging/android/ion/ion.h5
-rw-r--r--drivers/staging/android/ion/ion_system_heap.c24
-rw-r--r--drivers/staging/axis-fifo/axis-fifo.c24
-rw-r--r--drivers/staging/clocking-wizard/clk-xlnx-clock-wizard.c20
-rw-r--r--drivers/staging/comedi/Kconfig4
-rw-r--r--drivers/staging/comedi/comedi.h174
-rw-r--r--drivers/staging/comedi/comedi_fops.c73
-rw-r--r--drivers/staging/comedi/comedidev.h14
-rw-r--r--drivers/staging/comedi/drivers.c19
-rw-r--r--drivers/staging/comedi/drivers/Makefile28
-rw-r--r--drivers/staging/comedi/drivers/comedi_test.c44
-rw-r--r--drivers/staging/comedi/drivers/ni_660x.c363
-rw-r--r--drivers/staging/comedi/drivers/ni_mio_common.c944
-rw-r--r--drivers/staging/comedi/drivers/ni_pcidio.c13
-rw-r--r--drivers/staging/comedi/drivers/ni_pcimio.c21
-rw-r--r--drivers/staging/comedi/drivers/ni_routes.c523
-rw-r--r--drivers/staging/comedi/drivers/ni_routes.h329
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/README240
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/ni_device_routes.c51
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/ni_device_routes.h32
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/ni_device_routes/all.h54
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6070e.c639
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6220.c1418
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6221.c1602
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6229.c1602
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6251.c1652
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6254.c1464
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6259.c1652
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6534.c290
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6602.c3378
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6713.c400
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6723.c400
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6733.c428
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxi-6030e.c608
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxi-6224.c1432
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxi-6225.c1613
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxi-6251.c1655
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxi-6733.c428
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxie-6251.c1656
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxie-6535.c575
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxie-6738.c3083
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/ni_route_values.c42
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/ni_route_values.h98
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/ni_route_values/all.h37
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/ni_route_values/ni_660x.c650
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/ni_route_values/ni_eseries.c602
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/ni_route_values/ni_mseries.c1752
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/tools/.gitignore7
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/tools/Makefile79
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/tools/convert_c_to_py.c159
-rwxr-xr-xdrivers/staging/comedi/drivers/ni_routing/tools/convert_csv_to_c.py503
-rwxr-xr-xdrivers/staging/comedi/drivers/ni_routing/tools/convert_py_to_csv.py67
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/tools/csv_collection.py40
-rwxr-xr-xdrivers/staging/comedi/drivers/ni_routing/tools/make_blank_csv.py32
-rw-r--r--drivers/staging/comedi/drivers/ni_routing/tools/ni_names.py56
-rw-r--r--drivers/staging/comedi/drivers/ni_stc.h79
-rw-r--r--drivers/staging/comedi/drivers/ni_tio.c461
-rw-r--r--drivers/staging/comedi/drivers/ni_tio.h42
-rw-r--r--drivers/staging/comedi/drivers/ni_tio_internal.h2
-rw-r--r--drivers/staging/comedi/drivers/ni_tiocmd.c66
-rw-r--r--drivers/staging/comedi/drivers/tests/Makefile7
-rw-r--r--drivers/staging/comedi/drivers/tests/example_test.c72
-rw-r--r--drivers/staging/comedi/drivers/tests/ni_routes_test.c613
-rw-r--r--drivers/staging/comedi/drivers/tests/unittest.h63
-rw-r--r--drivers/staging/dgnc/Kconfig6
-rw-r--r--drivers/staging/dgnc/Makefile4
-rw-r--r--drivers/staging/dgnc/TODO6
-rw-r--r--drivers/staging/dgnc/dgnc_cls.c1135
-rw-r--r--drivers/staging/dgnc/dgnc_cls.h67
-rw-r--r--drivers/staging/dgnc/dgnc_driver.c404
-rw-r--r--drivers/staging/dgnc/dgnc_driver.h345
-rw-r--r--drivers/staging/dgnc/dgnc_tty.c2372
-rw-r--r--drivers/staging/dgnc/dgnc_tty.h24
-rw-r--r--drivers/staging/dgnc/digi.h128
-rw-r--r--drivers/staging/emxx_udc/emxx_udc.c43
-rw-r--r--drivers/staging/erofs/Kconfig9
-rw-r--r--drivers/staging/erofs/data.c105
-rw-r--r--drivers/staging/erofs/dir.c15
-rw-r--r--drivers/staging/erofs/erofs_fs.h11
-rw-r--r--drivers/staging/erofs/include/trace/events/erofs.h20
-rw-r--r--drivers/staging/erofs/inode.c50
-rw-r--r--drivers/staging/erofs/internal.h111
-rw-r--r--drivers/staging/erofs/namei.c28
-rw-r--r--drivers/staging/erofs/super.c96
-rw-r--r--drivers/staging/erofs/unzip_vle.c447
-rw-r--r--drivers/staging/erofs/unzip_vle.h12
-rw-r--r--drivers/staging/erofs/unzip_vle_lz4.c69
-rw-r--r--drivers/staging/erofs/utils.c2
-rw-r--r--drivers/staging/erofs/xattr.c196
-rw-r--r--drivers/staging/fbtft/fbtft.h58
-rw-r--r--drivers/staging/fsl-dpaa2/ethsw/ethsw.c6
-rw-r--r--drivers/staging/gasket/Kconfig5
-rw-r--r--drivers/staging/gasket/apex_driver.c6
-rw-r--r--drivers/staging/gasket/gasket_core.c145
-rw-r--r--drivers/staging/gasket/gasket_core.h21
-rw-r--r--drivers/staging/gasket/gasket_interrupt.c110
-rw-r--r--drivers/staging/gasket/gasket_interrupt.h24
-rw-r--r--drivers/staging/gasket/gasket_page_table.c162
-rw-r--r--drivers/staging/gasket/gasket_sysfs.h4
-rw-r--r--drivers/staging/greybus/audio_codec.c1
-rw-r--r--drivers/staging/greybus/loopback.c8
-rw-r--r--drivers/staging/greybus/tools/README.loopback2
-rw-r--r--drivers/staging/greybus/tools/loopback_test.c2
-rw-r--r--drivers/staging/iio/adc/Kconfig2
-rw-r--r--drivers/staging/iio/adc/ad7192.c2
-rw-r--r--drivers/staging/iio/adc/ad7280a.c2
-rw-r--r--drivers/staging/iio/adc/ad7606.c42
-rw-r--r--drivers/staging/iio/adc/ad7606.h31
-rw-r--r--drivers/staging/iio/adc/ad7606_par.c5
-rw-r--r--drivers/staging/iio/adc/ad7606_spi.c3
-rw-r--r--drivers/staging/iio/adc/ad7780.c2
-rw-r--r--drivers/staging/iio/cdc/ad7746.c2
-rw-r--r--drivers/staging/iio/frequency/ad9832.c2
-rw-r--r--drivers/staging/iio/frequency/ad9834.c2
-rw-r--r--drivers/staging/iio/impedance-analyzer/ad5933.c2
-rw-r--r--drivers/staging/ks7010/ks_hostif.c5
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_ipipe.c6
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_resizer.c2
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_resizer.h2
-rw-r--r--drivers/staging/media/imx/imx-media-dev.c15
-rw-r--r--drivers/staging/media/imx/imx-media-of.c4
-rw-r--r--drivers/staging/most/cdev/cdev.c12
-rw-r--r--drivers/staging/most/core.c49
-rw-r--r--drivers/staging/most/net/net.c2
-rw-r--r--drivers/staging/most/usb/usb.c55
-rw-r--r--drivers/staging/most/video/video.c4
-rw-r--r--drivers/staging/mt7621-dma/ralink-gdma.c1
-rw-r--r--drivers/staging/mt7621-eth/gsw_mt7621.c1
-rw-r--r--drivers/staging/mt7621-eth/mdio.c4
-rw-r--r--drivers/staging/mt7621-eth/mtk_eth_soc.c1
-rw-r--r--drivers/staging/mt7621-mmc/dbg.c104
-rw-r--r--drivers/staging/mt7621-mmc/dbg.h100
-rw-r--r--drivers/staging/mt7621-mmc/sd.c708
-rw-r--r--drivers/staging/mt7621-pci/pci-mt7621.c76
-rw-r--r--drivers/staging/octeon-usb/octeon-hcd.c58
-rw-r--r--drivers/staging/olpc_dcon/Kconfig1
-rw-r--r--drivers/staging/olpc_dcon/olpc_dcon.c5
-rw-r--r--drivers/staging/olpc_dcon/olpc_dcon_xo_1.c5
-rw-r--r--drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c5
-rw-r--r--drivers/staging/pi433/rf69.c3
-rw-r--r--drivers/staging/rtl8188eu/Makefile2
-rw-r--r--drivers/staging/rtl8188eu/TODO2
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_ap.c25
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_cmd.c57
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_debug.c25
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_efuse.c80
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_ieee80211.c24
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_ioctl_set.c142
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_led.c242
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_mlme.c69
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_mlme_ext.c60
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_pwrctrl.c9
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_recv.c43
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_security.c13
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_wlan_util.c73
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_xmit.c187
-rw-r--r--drivers/staging/rtl8188eu/hal/bb_cfg.c8
-rw-r--r--drivers/staging/rtl8188eu/hal/fw.c6
-rw-r--r--drivers/staging/rtl8188eu/hal/hal8188e_rate_adaptive.c18
-rw-r--r--drivers/staging/rtl8188eu/hal/hal_com.c11
-rw-r--r--drivers/staging/rtl8188eu/hal/odm.c21
-rw-r--r--drivers/staging/rtl8188eu/hal/odm_hwconfig.c (renamed from drivers/staging/rtl8188eu/hal/odm_HWConfig.c)100
-rw-r--r--drivers/staging/rtl8188eu/hal/odm_rtl8188e.c67
-rw-r--r--drivers/staging/rtl8188eu/hal/phy.c27
-rw-r--r--drivers/staging/rtl8188eu/hal/pwrseq.c5
-rw-r--r--drivers/staging/rtl8188eu/hal/rf_cfg.c2
-rw-r--r--drivers/staging/rtl8188eu/hal/rtl8188e_hal_init.c101
-rw-r--r--drivers/staging/rtl8188eu/hal/usb_halinit.c26
-rw-r--r--drivers/staging/rtl8188eu/include/drv_types.h7
-rw-r--r--drivers/staging/rtl8188eu/include/hal_com.h12
-rw-r--r--drivers/staging/rtl8188eu/include/odm_hwconfig.h (renamed from drivers/staging/rtl8188eu/include/odm_HWConfig.h)0
-rw-r--r--drivers/staging/rtl8188eu/include/odm_precomp.h4
-rw-r--r--drivers/staging/rtl8188eu/include/odm_reg.h106
-rw-r--r--drivers/staging/rtl8188eu/include/osdep_service.h2
-rw-r--r--drivers/staging/rtl8188eu/include/phy.h1
-rw-r--r--drivers/staging/rtl8188eu/include/rtw_mlme.h3
-rw-r--r--drivers/staging/rtl8188eu/include/rtw_mlme_ext.h18
-rw-r--r--drivers/staging/rtl8188eu/include/rtw_qos.h18
-rw-r--r--drivers/staging/rtl8188eu/include/wifi.h8
-rw-r--r--drivers/staging/rtl8188eu/os_dep/ioctl_linux.c25
-rw-r--r--drivers/staging/rtl8188eu/os_dep/mlme_linux.c2
-rw-r--r--drivers/staging/rtl8188eu/os_dep/os_intfs.c2
-rw-r--r--drivers/staging/rtl8188eu/os_dep/osdep_service.c14
-rw-r--r--drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c4
-rw-r--r--drivers/staging/rtl8188eu/os_dep/xmit_linux.c47
-rw-r--r--drivers/staging/rtl8192e/rtllib_softmac.c16
-rw-r--r--drivers/staging/rtl8192u/ieee80211/dot11d.c108
-rw-r--r--drivers/staging/rtl8192u/ieee80211/dot11d.h77
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211.h18
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_module.c35
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c12
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c14
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c4
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c6
-rw-r--r--drivers/staging/rtl8192u/ieee80211/rtl819x_BA.h84
-rw-r--r--drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c184
-rw-r--r--drivers/staging/rtl8192u/ieee80211/rtl819x_HT.h161
-rw-r--r--drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c138
-rw-r--r--drivers/staging/rtl8192u/ieee80211/rtl819x_TS.h6
-rw-r--r--drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c16
-rw-r--r--drivers/staging/rtl8192u/r8180_93cx6.h19
-rw-r--r--drivers/staging/rtl8192u/r8190_rtl8256.c33
-rw-r--r--drivers/staging/rtl8192u/r8190_rtl8256.h11
-rw-r--r--drivers/staging/rtl8192u/r8192U.h46
-rw-r--r--drivers/staging/rtl8192u/r8192U_core.c105
-rw-r--r--drivers/staging/rtl8192u/r8192U_hw.h204
-rw-r--r--drivers/staging/rtl8192u/r819xU_firmware.c4
-rw-r--r--drivers/staging/rtl8192u/r819xU_firmware.h11
-rw-r--r--drivers/staging/rtl8192u/r819xU_phy.c31
-rw-r--r--drivers/staging/rtl8192u/r819xU_phy.h6
-rw-r--r--drivers/staging/rtl8712/basic_types.h10
-rw-r--r--drivers/staging/rtl8712/drv_types.h10
-rw-r--r--drivers/staging/rtl8712/ethernet.h10
-rw-r--r--drivers/staging/rtl8712/hal_init.c10
-rw-r--r--drivers/staging/rtl8712/ieee80211.c10
-rw-r--r--drivers/staging/rtl8712/ieee80211.h13
-rw-r--r--drivers/staging/rtl8712/mlme_linux.c14
-rw-r--r--drivers/staging/rtl8712/mlme_osdep.h14
-rw-r--r--drivers/staging/rtl8712/mp_custom_oid.h14
-rw-r--r--drivers/staging/rtl8712/os_intfs.c10
-rw-r--r--drivers/staging/rtl8712/osdep_intf.h14
-rw-r--r--drivers/staging/rtl8712/osdep_service.h14
-rw-r--r--drivers/staging/rtl8712/recv_linux.c14
-rw-r--r--drivers/staging/rtl8712/recv_osdep.h14
-rw-r--r--drivers/staging/rtl8712/rtl8712_bitdef.h15
-rw-r--r--drivers/staging/rtl8712/rtl8712_cmd.c14
-rw-r--r--drivers/staging/rtl8712/rtl8712_cmd.h14
-rw-r--r--drivers/staging/rtl8712/rtl8712_cmdctrl_bitdef.h15
-rw-r--r--drivers/staging/rtl8712/rtl8712_cmdctrl_regdef.h15
-rw-r--r--drivers/staging/rtl8712/rtl8712_debugctrl_bitdef.h15
-rw-r--r--drivers/staging/rtl8712/rtl8712_debugctrl_regdef.h15
-rw-r--r--drivers/staging/rtl8712/rtl8712_edcasetting_bitdef.h14
-rw-r--r--drivers/staging/rtl8712/rtl8712_edcasetting_regdef.h15
-rw-r--r--drivers/staging/rtl8712/rtl8712_efuse.c14
-rw-r--r--drivers/staging/rtl8712/rtl8712_event.h14
-rw-r--r--drivers/staging/rtl8712/rtl8712_fifoctrl_bitdef.h15
-rw-r--r--drivers/staging/rtl8712/rtl8712_fifoctrl_regdef.h15
-rw-r--r--drivers/staging/rtl8712/rtl8712_gp_bitdef.h14
-rw-r--r--drivers/staging/rtl8712/rtl8712_gp_regdef.h14
-rw-r--r--drivers/staging/rtl8712/rtl8712_hal.h14
-rw-r--r--drivers/staging/rtl8712/rtl8712_interrupt_bitdef.h15
-rw-r--r--drivers/staging/rtl8712/rtl8712_io.c14
-rw-r--r--drivers/staging/rtl8712/rtl8712_led.c14
-rw-r--r--drivers/staging/rtl8712/rtl8712_macsetting_bitdef.h15
-rw-r--r--drivers/staging/rtl8712/rtl8712_macsetting_regdef.h15
-rw-r--r--drivers/staging/rtl8712/rtl8712_powersave_bitdef.h15
-rw-r--r--drivers/staging/rtl8712/rtl8712_powersave_regdef.h15
-rw-r--r--drivers/staging/rtl8712/rtl8712_ratectrl_bitdef.h15
-rw-r--r--drivers/staging/rtl8712/rtl8712_ratectrl_regdef.h14
-rw-r--r--drivers/staging/rtl8712/rtl8712_recv.c14
-rw-r--r--drivers/staging/rtl8712/rtl8712_recv.h14
-rw-r--r--drivers/staging/rtl8712/rtl8712_regdef.h14
-rw-r--r--drivers/staging/rtl8712/rtl8712_security_bitdef.h15
-rw-r--r--drivers/staging/rtl8712/rtl8712_spec.h14
-rw-r--r--drivers/staging/rtl8712/rtl8712_syscfg_bitdef.h14
-rw-r--r--drivers/staging/rtl8712/rtl8712_syscfg_regdef.h14
-rw-r--r--drivers/staging/rtl8712/rtl8712_timectrl_bitdef.h15
-rw-r--r--drivers/staging/rtl8712/rtl8712_timectrl_regdef.h15
-rw-r--r--drivers/staging/rtl8712/rtl8712_wmac_bitdef.h14
-rw-r--r--drivers/staging/rtl8712/rtl8712_wmac_regdef.h14
-rw-r--r--drivers/staging/rtl8712/rtl8712_xmit.c14
-rw-r--r--drivers/staging/rtl8712/rtl8712_xmit.h14
-rw-r--r--drivers/staging/rtl8712/rtl871x_cmd.c14
-rw-r--r--drivers/staging/rtl8712/rtl871x_cmd.h14
-rw-r--r--drivers/staging/rtl8712/rtl871x_debug.h14
-rw-r--r--drivers/staging/rtl8712/rtl871x_eeprom.c14
-rw-r--r--drivers/staging/rtl8712/rtl871x_eeprom.h15
-rw-r--r--drivers/staging/rtl8712/rtl871x_event.h14
-rw-r--r--drivers/staging/rtl8712/rtl871x_ht.h14
-rw-r--r--drivers/staging/rtl8712/rtl871x_io.c20
-rw-r--r--drivers/staging/rtl8712/rtl871x_io.h14
-rw-r--r--drivers/staging/rtl8712/rtl871x_ioctl_linux.c21
-rw-r--r--drivers/staging/rtl8712/rtl871x_ioctl_rtl.c14
-rw-r--r--drivers/staging/rtl8712/rtl871x_ioctl_rtl.h14
-rw-r--r--drivers/staging/rtl8712/rtl871x_ioctl_set.c14
-rw-r--r--drivers/staging/rtl8712/rtl871x_ioctl_set.h14
-rw-r--r--drivers/staging/rtl8712/rtl871x_led.h14
-rw-r--r--drivers/staging/rtl8712/rtl871x_mlme.c14
-rw-r--r--drivers/staging/rtl8712/rtl871x_mlme.h14
-rw-r--r--drivers/staging/rtl8712/rtl871x_mp.c14
-rw-r--r--drivers/staging/rtl8712/rtl871x_mp.h14
-rw-r--r--drivers/staging/rtl8712/rtl871x_mp_ioctl.c14
-rw-r--r--drivers/staging/rtl8712/rtl871x_mp_ioctl.h14
-rw-r--r--drivers/staging/rtl8712/rtl871x_pwrctrl.c14
-rw-r--r--drivers/staging/rtl8712/rtl871x_pwrctrl.h14
-rw-r--r--drivers/staging/rtl8712/rtl871x_recv.c14
-rw-r--r--drivers/staging/rtl8712/rtl871x_rf.h14
-rw-r--r--drivers/staging/rtl8712/rtl871x_security.c14
-rw-r--r--drivers/staging/rtl8712/rtl871x_security.h14
-rw-r--r--drivers/staging/rtl8712/rtl871x_sta_mgt.c14
-rw-r--r--drivers/staging/rtl8712/rtl871x_wlan_sme.h14
-rw-r--r--drivers/staging/rtl8712/rtl871x_xmit.c16
-rw-r--r--drivers/staging/rtl8712/rtl871x_xmit.h14
-rw-r--r--drivers/staging/rtl8712/sta_info.h14
-rw-r--r--drivers/staging/rtl8712/usb_halinit.c14
-rw-r--r--drivers/staging/rtl8712/usb_intf.c14
-rw-r--r--drivers/staging/rtl8712/usb_ops.c14
-rw-r--r--drivers/staging/rtl8712/usb_ops.h14
-rw-r--r--drivers/staging/rtl8712/usb_ops_linux.c14
-rw-r--r--drivers/staging/rtl8712/usb_osintf.h14
-rw-r--r--drivers/staging/rtl8712/wifi.h14
-rw-r--r--drivers/staging/rtl8712/wlan_bssdef.h14
-rw-r--r--drivers/staging/rtl8712/xmit_linux.c14
-rw-r--r--drivers/staging/rtl8712/xmit_osdep.h14
-rw-r--r--drivers/staging/rtl8723bs/core/rtw_ap.c24
-rw-r--r--drivers/staging/rtl8723bs/core/rtw_debug.c2
-rw-r--r--drivers/staging/rtl8723bs/core/rtw_mlme.c2
-rw-r--r--drivers/staging/rtl8723bs/core/rtw_mlme_ext.c11
-rw-r--r--drivers/staging/rtl8723bs/core/rtw_pwrctrl.c4
-rw-r--r--drivers/staging/rtl8723bs/core/rtw_security.c5
-rw-r--r--drivers/staging/rtl8723bs/hal/hal_com_phycfg.c11
-rw-r--r--drivers/staging/rtl8723bs/hal/odm_DIG.c4
-rw-r--r--drivers/staging/rtl8723bs/hal/odm_EdcaTurboCheck.c2
-rw-r--r--drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c2
-rw-r--r--drivers/staging/rtl8723bs/include/drv_types.h2
-rw-r--r--drivers/staging/rtl8723bs/os_dep/ioctl_linux.c30
-rw-r--r--drivers/staging/rtl8723bs/os_dep/sdio_intf.c2
-rw-r--r--drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.c10
-rw-r--r--drivers/staging/rtlwifi/efuse.c3
-rw-r--r--drivers/staging/rtlwifi/halmac/rtl_halmac.c4
-rw-r--r--drivers/staging/rtlwifi/phydm/phydm_adc_sampling.c2
-rw-r--r--drivers/staging/rtlwifi/phydm/phydm_dig.c4
-rw-r--r--drivers/staging/rtlwifi/regd.c2
-rw-r--r--drivers/staging/rtlwifi/wifi.h4
-rw-r--r--drivers/staging/rts5208/ms.c619
-rw-r--r--drivers/staging/rts5208/rtsx_card.c92
-rw-r--r--drivers/staging/rts5208/rtsx_card.h3
-rw-r--r--drivers/staging/rts5208/rtsx_chip.c396
-rw-r--r--drivers/staging/rts5208/rtsx_scsi.c108
-rw-r--r--drivers/staging/rts5208/sd.c649
-rw-r--r--drivers/staging/rts5208/spi.c141
-rw-r--r--drivers/staging/rts5208/xd.c210
-rw-r--r--drivers/staging/sm750fb/ddk750_mode.c2
-rw-r--r--drivers/staging/sm750fb/ddk750_sii164.c8
-rw-r--r--drivers/staging/sm750fb/sm750.c10
-rw-r--r--drivers/staging/speakup/spk_ttyio.c4
-rw-r--r--drivers/staging/vboxvideo/TODO1
-rw-r--r--drivers/staging/vboxvideo/vbox_drv.c165
-rw-r--r--drivers/staging/vboxvideo/vbox_drv.h86
-rw-r--r--drivers/staging/vboxvideo/vbox_fb.c152
-rw-r--r--drivers/staging/vboxvideo/vbox_irq.c8
-rw-r--r--drivers/staging/vboxvideo/vbox_main.c185
-rw-r--r--drivers/staging/vboxvideo/vbox_mode.c922
-rw-r--r--drivers/staging/vboxvideo/vbox_ttm.c78
-rw-r--r--drivers/staging/vc04_services/bcm2835-audio/bcm2835-ctl.c235
-rw-r--r--drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c338
-rw-r--r--drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c883
-rw-r--r--drivers/staging/vc04_services/bcm2835-audio/bcm2835.c222
-rw-r--r--drivers/staging/vc04_services/bcm2835-audio/bcm2835.h86
-rw-r--r--drivers/staging/vc04_services/bcm2835-camera/TODO6
-rw-r--r--drivers/staging/vc04_services/bcm2835-camera/controls.c2
-rw-r--r--drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c10
-rw-r--r--drivers/staging/vc04_services/interface/vchi/connections/connection.h324
-rw-r--r--drivers/staging/vc04_services/interface/vchi/message_drivers/message.h196
-rw-r--r--drivers/staging/vc04_services/interface/vchi/vchi.h227
-rw-r--r--drivers/staging/vc04_services/interface/vchi/vchi_cfg.h2
-rw-r--r--drivers/staging/vc04_services/interface/vchi/vchi_cfg_internal.h71
-rw-r--r--drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c4
-rw-r--r--drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c35
-rw-r--r--drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h5
-rw-r--r--drivers/staging/vc04_services/interface/vchiq_arm/vchiq_genversion88
-rw-r--r--drivers/staging/vc04_services/interface/vchiq_arm/vchiq_shim.c38
-rw-r--r--drivers/staging/vt6655/rxtx.c29
-rw-r--r--drivers/staging/wilc1000/Kconfig8
-rw-r--r--drivers/staging/wilc1000/Makefile5
-rw-r--r--drivers/staging/wilc1000/coreconfigurator.c4
-rw-r--r--drivers/staging/wilc1000/host_interface.c277
-rw-r--r--drivers/staging/wilc1000/host_interface.h19
-rw-r--r--drivers/staging/wilc1000/linux_mon.c3
-rw-r--r--drivers/staging/wilc1000/linux_wlan.c129
-rw-r--r--drivers/staging/wilc1000/wilc_debugfs.c115
-rw-r--r--drivers/staging/wilc1000/wilc_sdio.c56
-rw-r--r--drivers/staging/wilc1000/wilc_spi.c57
-rw-r--r--drivers/staging/wilc1000/wilc_wfi_cfgoperations.c281
-rw-r--r--drivers/staging/wilc1000/wilc_wfi_cfgoperations.h4
-rw-r--r--drivers/staging/wilc1000/wilc_wfi_netdevice.h55
-rw-r--r--drivers/staging/wilc1000/wilc_wlan.c208
-rw-r--r--drivers/staging/wilc1000/wilc_wlan.h8
-rw-r--r--drivers/staging/wilc1000/wilc_wlan_cfg.c294
-rw-r--r--drivers/staging/wilc1000/wilc_wlan_cfg.h26
-rw-r--r--drivers/staging/wilc1000/wilc_wlan_if.h4
-rw-r--r--drivers/staging/wlan-ng/cfg80211.c49
-rw-r--r--drivers/staging/wlan-ng/hfa384x_usb.c46
-rw-r--r--drivers/staging/wlan-ng/p80211conv.c2
-rw-r--r--drivers/staging/wlan-ng/p80211metadef.h121
-rw-r--r--drivers/staging/wlan-ng/p80211metastruct.h3
-rw-r--r--drivers/staging/wlan-ng/p80211netdev.c12
-rw-r--r--drivers/staging/wlan-ng/p80211req.c36
-rw-r--r--drivers/staging/wlan-ng/prism2fw.c37
-rw-r--r--drivers/staging/wlan-ng/prism2mib.c76
-rw-r--r--drivers/staging/wlan-ng/prism2sta.c86
-rw-r--r--include/dt-bindings/iio/qcom,spmi-vadc.h125
485 files changed, 44060 insertions, 16309 deletions
diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
index a5b4f223641d..8127a08e366d 100644
--- a/Documentation/ABI/testing/sysfs-bus-iio
+++ b/Documentation/ABI/testing/sysfs-bus-iio
@@ -199,7 +199,7 @@ Description:
199 199
200What: /sys/bus/iio/devices/iio:deviceX/in_positionrelative_x_raw 200What: /sys/bus/iio/devices/iio:deviceX/in_positionrelative_x_raw
201What: /sys/bus/iio/devices/iio:deviceX/in_positionrelative_y_raw 201What: /sys/bus/iio/devices/iio:deviceX/in_positionrelative_y_raw
202KernelVersion: 4.18 202KernelVersion: 4.19
203Contact: linux-iio@vger.kernel.org 203Contact: linux-iio@vger.kernel.org
204Description: 204Description:
205 Relative position in direction x or y on a pad (may be 205 Relative position in direction x or y on a pad (may be
diff --git a/Documentation/devicetree/bindings/iio/accel/adxl372.txt b/Documentation/devicetree/bindings/iio/accel/adxl372.txt
new file mode 100644
index 000000000000..a289964756a7
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/accel/adxl372.txt
@@ -0,0 +1,33 @@
1Analog Devices ADXL372 3-Axis, +/-(200g) Digital Accelerometer
2
3http://www.analog.com/media/en/technical-documentation/data-sheets/adxl372.pdf
4
5Required properties:
6 - compatible : should be "adi,adxl372"
7 - reg: the I2C address or SPI chip select number for the device
8
9Required properties for SPI bus usage:
10 - spi-max-frequency: Max SPI frequency to use
11
12Optional properties:
13 - interrupts: interrupt mapping for IRQ as documented in
14 Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
15
16Example for a I2C device node:
17
18 accelerometer@53 {
19 compatible = "adi,adxl372";
20 reg = <0x53>;
21 interrupt-parent = <&gpio>;
22 interrupts = <25 IRQ_TYPE_EDGE_FALLING>;
23 };
24
25Example for a SPI device node:
26
27 accelerometer@0 {
28 compatible = "adi,adxl372";
29 reg = <0>;
30 spi-max-frequency = <1000000>;
31 interrupt-parent = <&gpio>;
32 interrupts = <25 IRQ_TYPE_EDGE_FALLING>;
33 };
diff --git a/Documentation/devicetree/bindings/iio/adc/mcp3911.txt b/Documentation/devicetree/bindings/iio/adc/mcp3911.txt
new file mode 100644
index 000000000000..3071f48fb30b
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/mcp3911.txt
@@ -0,0 +1,30 @@
1* Microchip MCP3911 Dual channel analog front end (ADC)
2
3Required properties:
4 - compatible: Should be "microchip,mcp3911"
5 - reg: SPI chip select number for the device
6
7Recommended properties:
8 - spi-max-frequency: Definition as per
9 Documentation/devicetree/bindings/spi/spi-bus.txt.
10 Max frequency for this chip is 20MHz.
11
12Optional properties:
13 - clocks: Phandle and clock identifier for sampling clock
14 - interrupt-parent: Phandle to the parent interrupt controller
15 - interrupts: IRQ line for the ADC
16 - microchip,device-addr: Device address when multiple MCP3911 chips are present on the
17 same SPI bus. Valid values are 0-3. Defaults to 0.
18 - vref-supply: Phandle to the external reference voltage supply.
19
20Example:
21adc@0 {
22 compatible = "microchip,mcp3911";
23 reg = <0>;
24 interrupt-parent = <&gpio5>;
25 interrupts = <15 IRQ_TYPE_EDGE_RISING>;
26 spi-max-frequency = <20000000>;
27 microchip,device-addr = <0>;
28 vref-supply = <&vref_reg>;
29 clocks = <&xtal>;
30};
diff --git a/Documentation/devicetree/bindings/iio/adc/qcom,spmi-vadc.txt b/Documentation/devicetree/bindings/iio/adc/qcom,spmi-vadc.txt
index 0fb46137f936..b3c86f4ac7cd 100644
--- a/Documentation/devicetree/bindings/iio/adc/qcom,spmi-vadc.txt
+++ b/Documentation/devicetree/bindings/iio/adc/qcom,spmi-vadc.txt
@@ -1,7 +1,9 @@
1Qualcomm's SPMI PMIC voltage ADC 1Qualcomm's SPMI PMIC ADC
2 2
3SPMI PMIC voltage ADC (VADC) provides interface to clients to read 3- SPMI PMIC voltage ADC (VADC) provides interface to clients to read
4voltage. The VADC is a 15-bit sigma-delta ADC. 4 voltage. The VADC is a 15-bit sigma-delta ADC.
5- SPMI PMIC5 voltage ADC (ADC) provides interface to clients to read
6 voltage. The VADC is a 16-bit sigma-delta ADC.
5 7
6VADC node: 8VADC node:
7 9
@@ -9,11 +11,13 @@ VADC node:
9 Usage: required 11 Usage: required
10 Value type: <string> 12 Value type: <string>
11 Definition: Should contain "qcom,spmi-vadc". 13 Definition: Should contain "qcom,spmi-vadc".
14 Should contain "qcom,spmi-adc5" for PMIC5 ADC driver.
15 Should contain "qcom,spmi-adc-rev2" for PMIC rev2 ADC driver.
12 16
13- reg: 17- reg:
14 Usage: required 18 Usage: required
15 Value type: <prop-encoded-array> 19 Value type: <prop-encoded-array>
16 Definition: VADC base address and length in the SPMI PMIC register map. 20 Definition: VADC base address in the SPMI PMIC register map.
17 21
18- #address-cells: 22- #address-cells:
19 Usage: required 23 Usage: required
@@ -45,13 +49,26 @@ Channel node properties:
45 Definition: ADC channel number. 49 Definition: ADC channel number.
46 See include/dt-bindings/iio/qcom,spmi-vadc.h 50 See include/dt-bindings/iio/qcom,spmi-vadc.h
47 51
52- label:
53 Usage: required for "qcom,spmi-adc5" and "qcom,spmi-adc-rev2"
54 Value type: <empty>
55 Definition: ADC input of the platform as seen in the schematics.
56 For thermistor inputs connected to generic AMUX or GPIO inputs
57 these can vary across platform for the same pins. Hence select
58 the platform schematics name for this channel.
59
48- qcom,decimation: 60- qcom,decimation:
49 Usage: optional 61 Usage: optional
50 Value type: <u32> 62 Value type: <u32>
51 Definition: This parameter is used to decrease ADC sampling rate. 63 Definition: This parameter is used to decrease ADC sampling rate.
52 Quicker measurements can be made by reducing decimation ratio. 64 Quicker measurements can be made by reducing decimation ratio.
53 Valid values are 512, 1024, 2048, 4096. 65 - For compatible property "qcom,spmi-vadc", valid values are
54 If property is not found, default value of 512 will be used. 66 512, 1024, 2048, 4096. If property is not found, default value
67 of 512 will be used.
68 - For compatible property "qcom,spmi-adc5", valid values are 250, 420
69 and 840. If property is not found, default value of 840 is used.
70 - For compatible property "qcom,spmi-adc-rev2", valid values are 256,
71 512 and 1024. If property is not present, default value is 1024.
55 72
56- qcom,pre-scaling: 73- qcom,pre-scaling:
57 Usage: optional 74 Usage: optional
@@ -66,21 +83,38 @@ Channel node properties:
66- qcom,ratiometric: 83- qcom,ratiometric:
67 Usage: optional 84 Usage: optional
68 Value type: <empty> 85 Value type: <empty>
69 Definition: Channel calibration type. If this property is specified 86 Definition: Channel calibration type.
70 VADC will use the VDD reference (1.8V) and GND for channel 87 - For compatible property "qcom,spmi-vadc", if this property is
71 calibration. If property is not found, channel will be 88 specified VADC will use the VDD reference (1.8V) and GND for
72 calibrated with 0.625V and 1.25V reference channels, also 89 channel calibration. If property is not found, channel will be
73 known as absolute calibration. 90 calibrated with 0.625V and 1.25V reference channels, also
91 known as absolute calibration.
92 - For compatible property "qcom,spmi-adc5" and "qcom,spmi-adc-rev2",
93 if this property is specified VADC will use the VDD reference
94 (1.875V) and GND for channel calibration. If property is not found,
95 channel will be calibrated with 0V and 1.25V reference channels,
96 also known as absolute calibration.
74 97
75- qcom,hw-settle-time: 98- qcom,hw-settle-time:
76 Usage: optional 99 Usage: optional
77 Value type: <u32> 100 Value type: <u32>
78 Definition: Time between AMUX getting configured and the ADC starting 101 Definition: Time between AMUX getting configured and the ADC starting
79 conversion. Delay = 100us * (value) for value < 11, and 102 conversion. The 'hw_settle_time' is an index used from valid values
80 2ms * (value - 10) otherwise. 103 and programmed in hardware to achieve the hardware settling delay.
81 Valid values are: 0, 100, 200, 300, 400, 500, 600, 700, 800, 104 - For compatible property "qcom,spmi-vadc" and "qcom,spmi-adc-rev2",
82 900 us and 1, 2, 4, 6, 8, 10 ms 105 Delay = 100us * (hw_settle_time) for hw_settle_time < 11,
83 If property is not found, channel will use 0us. 106 and 2ms * (hw_settle_time - 10) otherwise.
107 Valid values are: 0, 100, 200, 300, 400, 500, 600, 700, 800,
108 900 us and 1, 2, 4, 6, 8, 10 ms.
109 If property is not found, channel will use 0us.
110 - For compatible property "qcom,spmi-adc5", delay = 15us for
111 value 0, 100us * (value) for values < 11,
112 and 2ms * (value - 10) otherwise.
113 Valid values are: 15, 100, 200, 300, 400, 500, 600, 700, 800,
114 900 us and 1, 2, 4, 6, 8, 10 ms
115 Certain controller digital versions have valid values of
116 15, 100, 200, 300, 400, 500, 600, 700, 1, 2, 4, 8, 16, 32, 64, 128 ms
117 If property is not found, channel will use 15us.
84 118
85- qcom,avg-samples: 119- qcom,avg-samples:
86 Usage: optional 120 Usage: optional
@@ -89,13 +123,18 @@ Channel node properties:
89 Averaging provides the option to obtain a single measurement 123 Averaging provides the option to obtain a single measurement
90 from the ADC that is an average of multiple samples. The value 124 from the ADC that is an average of multiple samples. The value
91 selected is 2^(value). 125 selected is 2^(value).
92 Valid values are: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 126 - For compatible property "qcom,spmi-vadc", valid values
93 If property is not found, 1 sample will be used. 127 are: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512
128 If property is not found, 1 sample will be used.
129 - For compatible property "qcom,spmi-adc5" and "qcom,spmi-adc-rev2",
130 valid values are: 1, 2, 4, 8, 16
131 If property is not found, 1 sample will be used.
94 132
95NOTE: 133NOTE:
96 134
97Following channels, also known as reference point channels, are used for 135For compatible property "qcom,spmi-vadc" following channels, also known as
98result calibration and their channel configuration nodes should be defined: 136reference point channels, are used for result calibration and their channel
137configuration nodes should be defined:
99VADC_REF_625MV and/or VADC_SPARE1(based on PMIC version) VADC_REF_1250MV, 138VADC_REF_625MV and/or VADC_SPARE1(based on PMIC version) VADC_REF_1250MV,
100VADC_GND_REF and VADC_VDD_VADC. 139VADC_GND_REF and VADC_VDD_VADC.
101 140
@@ -104,7 +143,7 @@ Example:
104 /* VADC node */ 143 /* VADC node */
105 pmic_vadc: vadc@3100 { 144 pmic_vadc: vadc@3100 {
106 compatible = "qcom,spmi-vadc"; 145 compatible = "qcom,spmi-vadc";
107 reg = <0x3100 0x100>; 146 reg = <0x3100>;
108 interrupts = <0x0 0x31 0x0 IRQ_TYPE_EDGE_RISING>; 147 interrupts = <0x0 0x31 0x0 IRQ_TYPE_EDGE_RISING>;
109 #address-cells = <1>; 148 #address-cells = <1>;
110 #size-cells = <0>; 149 #size-cells = <0>;
diff --git a/Documentation/devicetree/bindings/iio/adc/sprd,sc27xx-adc.txt b/Documentation/devicetree/bindings/iio/adc/sprd,sc27xx-adc.txt
index 8aad960de50b..b4daa15dcf15 100644
--- a/Documentation/devicetree/bindings/iio/adc/sprd,sc27xx-adc.txt
+++ b/Documentation/devicetree/bindings/iio/adc/sprd,sc27xx-adc.txt
@@ -12,6 +12,8 @@ Required properties:
12- interrupts: The interrupt number for the ADC device. 12- interrupts: The interrupt number for the ADC device.
13- #io-channel-cells: Number of cells in an IIO specifier. 13- #io-channel-cells: Number of cells in an IIO specifier.
14- hwlocks: Reference to a phandle of a hwlock provider node. 14- hwlocks: Reference to a phandle of a hwlock provider node.
15- nvmem-cells: A phandle to the calibration cells provided by eFuse device.
16- nvmem-cell-names: Should be "big_scale_calib", "small_scale_calib".
15 17
16Example: 18Example:
17 19
@@ -32,5 +34,7 @@ Example:
32 interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; 34 interrupts = <0 IRQ_TYPE_LEVEL_HIGH>;
33 #io-channel-cells = <1>; 35 #io-channel-cells = <1>;
34 hwlocks = <&hwlock 4>; 36 hwlocks = <&hwlock 4>;
37 nvmem-cells = <&adc_big_scale>, <&adc_small_scale>;
38 nvmem-cell-names = "big_scale_calib", "small_scale_calib";
35 }; 39 };
36 }; 40 };
diff --git a/Documentation/devicetree/bindings/iio/dac/ad5758.txt b/Documentation/devicetree/bindings/iio/dac/ad5758.txt
index bba01a5cab1b..2f607f41f9d3 100644
--- a/Documentation/devicetree/bindings/iio/dac/ad5758.txt
+++ b/Documentation/devicetree/bindings/iio/dac/ad5758.txt
@@ -50,6 +50,9 @@ Required properties:
50 50
51Optional properties: 51Optional properties:
52 52
53 - reset-gpios : GPIO spec for the RESET pin. If specified, it will be
54 asserted during driver probe.
55
53 - adi,dc-dc-ilim-microamp: The dc-to-dc converter current limit 56 - adi,dc-dc-ilim-microamp: The dc-to-dc converter current limit
54 The following values are currently supported [uA]: 57 The following values are currently supported [uA]:
55 * 150000 58 * 150000
@@ -71,6 +74,8 @@ AD5758 Example:
71 spi-max-frequency = <1000000>; 74 spi-max-frequency = <1000000>;
72 spi-cpha; 75 spi-cpha;
73 76
77 reset-gpios = <&gpio 22 0>;
78
74 adi,dc-dc-mode = <2>; 79 adi,dc-dc-mode = <2>;
75 adi,range-microvolt = <0 10000000>; 80 adi,range-microvolt = <0 10000000>;
76 adi,dc-dc-ilim-microamp = <200000>; 81 adi,dc-dc-ilim-microamp = <200000>;
diff --git a/Documentation/devicetree/bindings/iio/dac/ltc1660.txt b/Documentation/devicetree/bindings/iio/dac/ltc1660.txt
new file mode 100644
index 000000000000..c5b5f22d6c64
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/dac/ltc1660.txt
@@ -0,0 +1,21 @@
1* Linear Technology Micropower octal 8-Bit and 10-Bit DACs
2
3Required properties:
4 - compatible: Must be one of the following:
5 "lltc,ltc1660"
6 "lltc,ltc1665"
7 - reg: SPI chip select number for the device
8 - vref-supply: Phandle to the voltage reference supply
9
10Recommended properties:
11 - spi-max-frequency: Definition as per
12 Documentation/devicetree/bindings/spi/spi-bus.txt.
13 Max frequency for this chip is 5 MHz.
14
15Example:
16dac@0 {
17 compatible = "lltc,ltc1660";
18 reg = <0>;
19 spi-max-frequency = <5000000>;
20 vref-supply = <&vref_reg>;
21};
diff --git a/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt b/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt
index b2f27da847b8..6ab9a9d196b0 100644
--- a/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt
+++ b/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt
@@ -20,6 +20,7 @@ Required properties:
20 bindings. 20 bindings.
21 21
22Optional properties: 22Optional properties:
23 - vddio-supply: regulator phandle for VDDIO supply
23 - mount-matrix: an optional 3x3 mounting rotation matrix 24 - mount-matrix: an optional 3x3 mounting rotation matrix
24 - i2c-gate node. These devices also support an auxiliary i2c bus. This is 25 - i2c-gate node. These devices also support an auxiliary i2c bus. This is
25 simple enough to be described using the i2c-gate binding. See 26 simple enough to be described using the i2c-gate binding. See
diff --git a/Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt b/Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt
index ea2d6e0ae4c5..879322ad50fd 100644
--- a/Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt
+++ b/Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt
@@ -7,6 +7,7 @@ Required properties:
7 "st,lsm6dsl" 7 "st,lsm6dsl"
8 "st,lsm6dsm" 8 "st,lsm6dsm"
9 "st,ism330dlc" 9 "st,ism330dlc"
10 "st,lsm6dso"
10- reg: i2c address of the sensor / spi cs line 11- reg: i2c address of the sensor / spi cs line
11 12
12Optional properties: 13Optional properties:
diff --git a/Documentation/devicetree/bindings/iio/light/bh1750.txt b/Documentation/devicetree/bindings/iio/light/bh1750.txt
new file mode 100644
index 000000000000..1e7685797d7a
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/light/bh1750.txt
@@ -0,0 +1,18 @@
1ROHM BH1750 - ALS, Ambient light sensor
2
3Required properties:
4
5- compatible: Must be one of:
6 "rohm,bh1710"
7 "rohm,bh1715"
8 "rohm,bh1721"
9 "rohm,bh1750"
10 "rohm,bh1751"
11- reg: the I2C address of the sensor
12
13Example:
14
15light-sensor@23 {
16 compatible = "rohm,bh1750";
17 reg = <0x23>;
18};
diff --git a/Documentation/devicetree/bindings/iio/light/tsl2772.txt b/Documentation/devicetree/bindings/iio/light/tsl2772.txt
new file mode 100644
index 000000000000..1c5e6f17a1df
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/light/tsl2772.txt
@@ -0,0 +1,42 @@
1* AMS/TAOS ALS and proximity sensor
2
3Required properties:
4
5 - compatible: Should be one of
6 "amstaos,tsl2571"
7 "amstaos,tsl2671"
8 "amstaos,tmd2671"
9 "amstaos,tsl2771"
10 "amstaos,tmd2771"
11 "amstaos,tsl2572"
12 "amstaos,tsl2672"
13 "amstaos,tmd2672"
14 "amstaos,tsl2772"
15 "amstaos,tmd2772"
16 "avago,apds9930"
17 - reg: the I2C address of the device
18
19Optional properties:
20
21 - amstaos,proximity-diodes - proximity diodes to enable. <0>, <1>, or <0 1>
22 are the only valid values.
23 - led-max-microamp - current for the proximity LED. Must be 100000, 50000,
24 25000, or 13000.
25 - vdd-supply: phandle to the regulator that provides power to the sensor.
26 - vddio-supply: phandle to the regulator that provides power to the bus.
27 - interrupts: the sole interrupt generated by the device
28
29 Refer to interrupt-controller/interrupts.txt for generic interrupt client
30 node bindings.
31
32Example:
33
34tsl2772@39 {
35 compatible = "amstaos,tsl2772";
36 reg = <0x39>;
37 interrupts-extended = <&msmgpio 61 IRQ_TYPE_EDGE_FALLING>;
38 vdd-supply = <&pm8941_l17>;
39 vddio-supply = <&pm8941_lvs1>;
40 amstaos,proximity-diodes = <0>;
41 led-max-microamp = <100000>;
42};
diff --git a/Documentation/devicetree/bindings/iio/proximity/vl53l0x.txt b/Documentation/devicetree/bindings/iio/proximity/vl53l0x.txt
new file mode 100644
index 000000000000..aac5f621f8dc
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/proximity/vl53l0x.txt
@@ -0,0 +1,12 @@
1ST VL53L0X ToF ranging sensor
2
3Required properties:
4 - compatible: must be "st,vl53l0x"
5 - reg: i2c address where to find the device
6
7Example:
8
9vl53l0x@29 {
10 compatible = "st,vl53l0x";
11 reg = <0x29>;
12};
diff --git a/Documentation/devicetree/bindings/trivial-devices.txt b/Documentation/devicetree/bindings/trivial-devices.txt
index 69c934aec13b..6ab001fa1ed4 100644
--- a/Documentation/devicetree/bindings/trivial-devices.txt
+++ b/Documentation/devicetree/bindings/trivial-devices.txt
@@ -21,16 +21,6 @@ adi,adt7490 +/-1C TDM Extended Temp Range I.C
21adi,adxl345 Three-Axis Digital Accelerometer 21adi,adxl345 Three-Axis Digital Accelerometer
22adi,adxl346 Three-Axis Digital Accelerometer (backward-compatibility value "adi,adxl345" must be listed too) 22adi,adxl346 Three-Axis Digital Accelerometer (backward-compatibility value "adi,adxl345" must be listed too)
23ams,iaq-core AMS iAQ-Core VOC Sensor 23ams,iaq-core AMS iAQ-Core VOC Sensor
24amstaos,tsl2571 AMS/TAOS ALS and proximity sensor
25amstaos,tsl2671 AMS/TAOS ALS and proximity sensor
26amstaos,tmd2671 AMS/TAOS ALS and proximity sensor
27amstaos,tsl2771 AMS/TAOS ALS and proximity sensor
28amstaos,tmd2771 AMS/TAOS ALS and proximity sensor
29amstaos,tsl2572 AMS/TAOS ALS and proximity sensor
30amstaos,tsl2672 AMS/TAOS ALS and proximity sensor
31amstaos,tmd2672 AMS/TAOS ALS and proximity sensor
32amstaos,tsl2772 AMS/TAOS ALS and proximity sensor
33amstaos,tmd2772 AMS/TAOS ALS and proximity sensor
34at,24c08 i2c serial eeprom (24cxx) 24at,24c08 i2c serial eeprom (24cxx)
35atmel,at97sc3204t i2c trusted platform module (TPM) 25atmel,at97sc3204t i2c trusted platform module (TPM)
36capella,cm32181 CM32181: Ambient Light Sensor 26capella,cm32181 CM32181: Ambient Light Sensor
diff --git a/Documentation/filesystems/pohmelfs/design_notes.txt b/Documentation/filesystems/pohmelfs/design_notes.txt
deleted file mode 100644
index 106d17fbb05f..000000000000
--- a/Documentation/filesystems/pohmelfs/design_notes.txt
+++ /dev/null
@@ -1,72 +0,0 @@
1POHMELFS: Parallel Optimized Host Message Exchange Layered File System.
2
3 Evgeniy Polyakov <zbr@ioremap.net>
4
5Homepage: http://www.ioremap.net/projects/pohmelfs
6
7POHMELFS first began as a network filesystem with coherent local data and
8metadata caches but is now evolving into a parallel distributed filesystem.
9
10Main features of this FS include:
11 * Locally coherent cache for data and metadata with (potentially) byte-range locks.
12 Since all Linux filesystems lock the whole inode during writing, algorithm
13 is very simple and does not use byte-ranges, although they are sent in
14 locking messages.
15 * Completely async processing of all events except creation of hard and symbolic
16 links, and rename events.
17 Object creation and data reading and writing are processed asynchronously.
18 * Flexible object architecture optimized for network processing.
19 Ability to create long paths to objects and remove arbitrarily huge
20 directories with a single network command.
21 (like removing the whole kernel tree via a single network command).
22 * Very high performance.
23 * Fast and scalable multithreaded userspace server. Being in userspace it works
24 with any underlying filesystem and still is much faster than async in-kernel NFS one.
25 * Client is able to switch between different servers (if one goes down, client
26 automatically reconnects to second and so on).
27 * Transactions support. Full failover for all operations.
28 Resending transactions to different servers on timeout or error.
29 * Read request (data read, directory listing, lookup requests) balancing between multiple servers.
30 * Write requests are replicated to multiple servers and completed only when all of them are acked.
31 * Ability to add and/or remove servers from the working set at run-time.
32 * Strong authentication and possible data encryption in network channel.
33 * Extended attributes support.
34
35POHMELFS is based on transactions, which are potentially long-standing objects that live
36in the client's memory. Each transaction contains all the information needed to process a given
37command (or set of commands, which is frequently used during data writing: single transactions
38can contain creation and data writing commands). Transactions are committed by all the servers
39to which they are sent and, in case of failures, are eventually resent or dropped with an error.
40For example, reading will return an error if no servers are available.
41
42POHMELFS uses a asynchronous approach to data processing. Courtesy of transactions, it is
43possible to detach replies from requests and, if the command requires data to be received, the
44caller sleeps waiting for it. Thus, it is possible to issue multiple read commands to different
45servers and async threads will pick up replies in parallel, find appropriate transactions in the
46system and put the data where it belongs (like the page or inode cache).
47
48The main feature of POHMELFS is writeback data and the metadata cache.
49Only a few non-performance critical operations use the write-through cache and
50are synchronous: hard and symbolic link creation, and object rename. Creation,
51removal of objects and data writing are asynchronous and are sent to
52the server during system writeback. Only one writer at a time is allowed for any
53given inode, which is guarded by an appropriate locking protocol.
54Because of this feature, POHMELFS is extremely fast at metadata intensive
55workloads and can fully utilize the bandwidth to the servers when doing bulk
56data transfers.
57
58POHMELFS clients operate with a working set of servers and are capable of balancing read-only
59operations (like lookups or directory listings) between them according to IO priorities.
60Administrators can add or remove servers from the set at run-time via special commands (described
61in Documentation/filesystems/pohmelfs/info.txt file). Writes are replicated to all servers, which
62are connected with write permission turned on. IO priority and permissions can be changed in
63run-time.
64
65POHMELFS is capable of full data channel encryption and/or strong crypto hashing.
66One can select any kernel supported cipher, encryption mode, hash type and operation mode
67(hmac or digest). It is also possible to use both or neither (default). Crypto configuration
68is checked during mount time and, if the server does not support it, appropriate capabilities
69will be disabled or mount will fail (if 'crypto_fail_unsupported' mount option is specified).
70Crypto performance heavily depends on the number of crypto threads, which asynchronously perform
71crypto operations and send the resulting data to server or submit it up the stack. This number
72can be controlled via a mount option.
diff --git a/Documentation/filesystems/pohmelfs/info.txt b/Documentation/filesystems/pohmelfs/info.txt
deleted file mode 100644
index db2e41393626..000000000000
--- a/Documentation/filesystems/pohmelfs/info.txt
+++ /dev/null
@@ -1,99 +0,0 @@
1POHMELFS usage information.
2
3Mount options.
4All but index, number of crypto threads and maximum IO size can changed via remount.
5
6idx=%u
7 Each mountpoint is associated with a special index via this option.
8 Administrator can add or remove servers from the given index, so all mounts,
9 which were attached to it, are updated.
10 Default it is 0.
11
12trans_scan_timeout=%u
13 This timeout, expressed in milliseconds, specifies time to scan transaction
14 trees looking for stale requests, which have to be resent, or if number of
15 retries exceed specified limit, dropped with error.
16 Default is 5 seconds.
17
18drop_scan_timeout=%u
19 Internal timeout, expressed in milliseconds, which specifies how frequently
20 inodes marked to be dropped are freed. It also specifies how frequently
21 the system checks that servers have to be added or removed from current working set.
22 Default is 1 second.
23
24wait_on_page_timeout=%u
25 Number of milliseconds to wait for reply from remote server for data reading command.
26 If this timeout is exceeded, reading returns an error.
27 Default is 5 seconds.
28
29trans_retries=%u
30 This is the number of times that a transaction will be resent to a server that did
31 not answer for the last @trans_scan_timeout milliseconds.
32 When the number of resends exceeds this limit, the transaction is completed with error.
33 Default is 5 resends.
34
35crypto_thread_num=%u
36 Number of crypto processing threads. Threads are used both for RX and TX traffic.
37 Default is 2, or no threads if crypto operations are not supported.
38
39trans_max_pages=%u
40 Maximum number of pages in a single transaction. This parameter also controls
41 the number of pages, allocated for crypto processing (each crypto thread has
42 pool of pages, the number of which is equal to 'trans_max_pages'.
43 Default is 100 pages.
44
45crypto_fail_unsupported
46 If specified, mount will fail if the server does not support requested crypto operations.
47 By default mount will disable non-matching crypto operations.
48
49mcache_timeout=%u
50 Maximum number of milliseconds to wait for the mcache objects to be processed.
51 Mcache includes locks (given lock should be granted by server), attributes (they should be
52 fully received in the given timeframe).
53 Default is 5 seconds.
54
55Usage examples.
56
57Add server server1.net:1025 into the working set with index $idx
58with appropriate hash algorithm and key file and cipher algorithm, mode and key file:
59$cfg A add -a server1.net -p 1025 -i $idx -K $hash_key -k $cipher_key
60
61Mount filesystem with given index $idx to /mnt mountpoint.
62Client will connect to all servers specified in the working set via previous command:
63mount -t pohmel -o idx=$idx q /mnt
64
65Change permissions to read-only (-I 1 option, '-I 2' - write-only, 3 - rw):
66$cfg A modify -a server1.net -p 1025 -i $idx -I 1
67
68Change IO priority to 123 (node with the highest priority gets read requests).
69$cfg A modify -a server1.net -p 1025 -i $idx -P 123
70
71One can check currect status of all connections in the mountstats file:
72# cat /proc/$PID/mountstats
73...
74device none mounted on /mnt with fstype pohmel
75idx addr(:port) socket_type protocol active priority permissions
760 server1.net:1026 1 6 1 250 1
770 server2.net:1025 1 6 1 123 3
78
79Server installation.
80
81Creating a server, which listens at port 1025 and 0.0.0.0 address.
82Working root directory (note, that server chroots there, so you have to have appropriate permissions)
83is set to /mnt, server will negotiate hash/cipher with client, in case client requested it, there
84are appropriate key files.
85Number of working threads is set to 10.
86
87# ./fserver -a 0.0.0.0 -p 1025 -r /mnt -w 10 -K hash_key -k cipher_key
88
89 -A 6 - listen on ipv6 address. Default: Disabled.
90 -r root - path to root directory. Default: /tmp.
91 -a addr - listen address. Default: 0.0.0.0.
92 -p port - listen port. Default: 1025.
93 -w workers - number of workers per connected client. Default: 1.
94 -K file - hash key size. Default: none.
95 -k file - cipher key size. Default: none.
96 -h - this help.
97
98Number of worker threads specifies how many workers will be created for each client.
99Bulk single-client transafers usually are better handled with smaller number (like 1-3).
diff --git a/Documentation/filesystems/pohmelfs/network_protocol.txt b/Documentation/filesystems/pohmelfs/network_protocol.txt
deleted file mode 100644
index c680b4b5353d..000000000000
--- a/Documentation/filesystems/pohmelfs/network_protocol.txt
+++ /dev/null
@@ -1,227 +0,0 @@
1POHMELFS network protocol.
2
3Basic structure used in network communication is following command:
4
5struct netfs_cmd
6{
7 __u16 cmd; /* Command number */
8 __u16 csize; /* Attached crypto information size */
9 __u16 cpad; /* Attached padding size */
10 __u16 ext; /* External flags */
11 __u32 size; /* Size of the attached data */
12 __u32 trans; /* Transaction id */
13 __u64 id; /* Object ID to operate on. Used for feedback.*/
14 __u64 start; /* Start of the object. */
15 __u64 iv; /* IV sequence */
16 __u8 data[0];
17};
18
19Commands can be embedded into transaction command (which in turn has own command),
20so one can extend protocol as needed without breaking backward compatibility as long
21as old commands are supported. All string lengths include tail 0 byte.
22
23All commands are transferred over the network in big-endian. CPU endianness is used at the end peers.
24
25@cmd - command number, which specifies command to be processed. Following
26 commands are used currently:
27
28 NETFS_READDIR = 1, /* Read directory for given inode number */
29 NETFS_READ_PAGE, /* Read data page from the server */
30 NETFS_WRITE_PAGE, /* Write data page to the server */
31 NETFS_CREATE, /* Create directory entry */
32 NETFS_REMOVE, /* Remove directory entry */
33 NETFS_LOOKUP, /* Lookup single object */
34 NETFS_LINK, /* Create a link */
35 NETFS_TRANS, /* Transaction */
36 NETFS_OPEN, /* Open intent */
37 NETFS_INODE_INFO, /* Metadata cache coherency synchronization message */
38 NETFS_PAGE_CACHE, /* Page cache invalidation message */
39 NETFS_READ_PAGES, /* Read multiple contiguous pages in one go */
40 NETFS_RENAME, /* Rename object */
41 NETFS_CAPABILITIES, /* Capabilities of the client, for example supported crypto */
42 NETFS_LOCK, /* Distributed lock message */
43 NETFS_XATTR_SET, /* Set extended attribute */
44 NETFS_XATTR_GET, /* Get extended attribute */
45
46@ext - external flags. Used by different commands to specify some extra arguments
47 like partial size of the embedded objects or creation flags.
48
49@size - size of the attached data. For NETFS_READ_PAGE and NETFS_READ_PAGES no data is attached,
50 but size of the requested data is incorporated here. It does not include size of the command
51 header (struct netfs_cmd) itself.
52
53@id - id of the object this command operates on. Each command can use it for own purpose.
54
55@start - start of the object this command operates on. Each command can use it for own purpose.
56
57@csize, @cpad - size and padding size of the (attached if needed) crypto information.
58
59Command specifications.
60
61@NETFS_READDIR
62This command is used to sync content of the remote dir to the client.
63
64@ext - length of the path to object.
65@size - the same.
66@id - local inode number of the directory to read.
67@start - zero.
68
69
70@NETFS_READ_PAGE
71This command is used to read data from remote server.
72Data size does not exceed local page cache size.
73
74@id - inode number.
75@start - first byte offset.
76@size - number of bytes to read plus length of the path to object.
77@ext - object path length.
78
79
80@NETFS_CREATE
81Used to create object.
82It does not require that all directories on top of the object were
83already created, it will create them automatically. Each object has
84associated @netfs_path_entry data structure, which contains creation
85mode (permissions and type) and length of the name as long as name itself.
86
87@start - 0
88@size - size of the all data structures needed to create a path
89@id - local inode number
90@ext - 0
91
92
93@NETFS_REMOVE
94Used to remove object.
95
96@ext - length of the path to object.
97@size - the same.
98@id - local inode number.
99@start - zero.
100
101
102@NETFS_LOOKUP
103Lookup information about object on server.
104
105@ext - length of the path to object.
106@size - the same.
107@id - local inode number of the directory to look object in.
108@start - local inode number of the object to look at.
109
110
111@NETFS_LINK
112Create hard of symlink.
113Command is sent as "object_path|target_path".
114
115@size - size of the above string.
116@id - parent local inode number.
117@start - 1 for symlink, 0 for hardlink.
118@ext - size of the "object_path" above.
119
120
121@NETFS_TRANS
122Transaction header.
123
124@size - incorporates all embedded command sizes including theirs header sizes.
125@start - transaction generation number - unique id used to find transaction.
126@ext - transaction flags. Unused at the moment.
127@id - 0.
128
129
130@NETFS_OPEN
131Open intent for given transaction.
132
133@id - local inode number.
134@start - 0.
135@size - path length to the object.
136@ext - open flags (O_RDWR and so on).
137
138
139@NETFS_INODE_INFO
140Metadata update command.
141It is sent to servers when attributes of the object are changed and received
142when data or metadata were updated. It operates with the following structure:
143
144struct netfs_inode_info
145{
146 unsigned int mode;
147 unsigned int nlink;
148 unsigned int uid;
149 unsigned int gid;
150 unsigned int blocksize;
151 unsigned int padding;
152 __u64 ino;
153 __u64 blocks;
154 __u64 rdev;
155 __u64 size;
156 __u64 version;
157};
158
159It effectively mirrors stat(2) returned data.
160
161
162@ext - path length to the object.
163@size - the same plus size of the netfs_inode_info structure.
164@id - local inode number.
165@start - 0.
166
167
168@NETFS_PAGE_CACHE
169Command is only received by clients. It contains information about
170page to be marked as not up-to-date.
171
172@id - client's inode number.
173@start - last byte of the page to be invalidated. If it is not equal to
174 current inode size, it will be vmtruncated().
175@size - 0
176@ext - 0
177
178
179@NETFS_READ_PAGES
180Used to read multiple contiguous pages in one go.
181
182@start - first byte of the contiguous region to read.
183@size - contains of two fields: lower 8 bits are used to represent page cache shift
184 used by client, another 3 bytes are used to get number of pages.
185@id - local inode number.
186@ext - path length to the object.
187
188
189@NETFS_RENAME
190Used to rename object.
191Attached data is formed into following string: "old_path|new_path".
192
193@id - local inode number.
194@start - parent inode number.
195@size - length of the above string.
196@ext - length of the old path part.
197
198
199@NETFS_CAPABILITIES
200Used to exchange crypto capabilities with server.
201If crypto capabilities are not supported by server, then client will disable it
202or fail (if 'crypto_fail_unsupported' mount options was specified).
203
204@id - superblock index. Used to specify crypto information for group of servers.
205@size - size of the attached capabilities structure.
206@start - 0.
207@size - 0.
208@scsize - 0.
209
210@NETFS_LOCK
211Used to send lock request/release messages. Although it sends byte range request
212and is capable of flushing pages based on that, it is not used, since all Linux
213filesystems lock the whole inode.
214
215@id - lock generation number.
216@start - start of the locked range.
217@size - size of the locked range.
218@ext - lock type: read/write. Not used actually. 15'th bit is used to determine,
219 if it is lock request (1) or release (0).
220
221@NETFS_XATTR_SET
222@NETFS_XATTR_GET
223Used to set/get extended attributes for given inode.
224@id - attribute generation number or xattr setting type
225@start - size of the attribute (request or attached)
226@size - name length, path len and data size for given attribute
227@ext - path length for given object
diff --git a/MAINTAINERS b/MAINTAINERS
index 11b7d81f883a..c6c9cc1019ad 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -549,6 +549,15 @@ W: http://ez.analog.com/community/linux-device-drivers
549S: Supported 549S: Supported
550F: drivers/input/misc/adxl34x.c 550F: drivers/input/misc/adxl34x.c
551 551
552ADXL372 THREE-AXIS DIGITAL ACCELEROMETER DRIVER
553M: Stefan Popa <stefan.popa@analog.com>
554W: http://ez.analog.com/community/linux-device-drivers
555S: Supported
556F: drivers/iio/accel/adxl372.c
557F: drivers/iio/accel/adxl372_spi.c
558F: drivers/iio/accel/adxl372_i2c.c
559F: Documentation/devicetree/bindings/iio/accel/adxl372.txt
560
552AF9013 MEDIA DRIVER 561AF9013 MEDIA DRIVER
553M: Antti Palosaari <crope@iki.fi> 562M: Antti Palosaari <crope@iki.fi>
554L: linux-media@vger.kernel.org 563L: linux-media@vger.kernel.org
@@ -4388,13 +4397,6 @@ L: linux-gpio@vger.kernel.org
4388S: Maintained 4397S: Maintained
4389F: drivers/gpio/gpio-gpio-mm.c 4398F: drivers/gpio/gpio-gpio-mm.c
4390 4399
4391DIGI NEO AND CLASSIC PCI PRODUCTS
4392M: Lidza Louina <lidza.louina@gmail.com>
4393M: Mark Hounschell <markh@compro.net>
4394L: driverdev-devel@linuxdriverproject.org
4395S: Maintained
4396F: drivers/staging/dgnc/
4397
4398DIOLAN U2C-12 I2C DRIVER 4400DIOLAN U2C-12 I2C DRIVER
4399M: Guenter Roeck <linux@roeck-us.net> 4401M: Guenter Roeck <linux@roeck-us.net>
4400L: linux-i2c@vger.kernel.org 4402L: linux-i2c@vger.kernel.org
@@ -5675,10 +5677,9 @@ F: Documentation/fault-injection/
5675F: lib/fault-inject.c 5677F: lib/fault-inject.c
5676 5678
5677FBTFT Framebuffer drivers 5679FBTFT Framebuffer drivers
5678M: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> 5680S: Orphan
5679L: dri-devel@lists.freedesktop.org 5681L: dri-devel@lists.freedesktop.org
5680L: linux-fbdev@vger.kernel.org 5682L: linux-fbdev@vger.kernel.org
5681S: Maintained
5682F: drivers/staging/fbtft/ 5683F: drivers/staging/fbtft/
5683 5684
5684FC0011 TUNER DRIVER 5685FC0011 TUNER DRIVER
@@ -7737,7 +7738,6 @@ IPX NETWORK LAYER
7737L: netdev@vger.kernel.org 7738L: netdev@vger.kernel.org
7738S: Obsolete 7739S: Obsolete
7739F: include/uapi/linux/ipx.h 7740F: include/uapi/linux/ipx.h
7740F: drivers/staging/ipx/
7741 7741
7742IRQ DOMAINS (IRQ NUMBER MAPPING LIBRARY) 7742IRQ DOMAINS (IRQ NUMBER MAPPING LIBRARY)
7743M: Marc Zyngier <marc.zyngier@arm.com> 7743M: Marc Zyngier <marc.zyngier@arm.com>
@@ -8716,6 +8716,13 @@ L: linux-scsi@vger.kernel.org
8716S: Maintained 8716S: Maintained
8717F: drivers/scsi/sym53c8xx_2/ 8717F: drivers/scsi/sym53c8xx_2/
8718 8718
8719LTC1660 DAC DRIVER
8720M: Marcus Folkesson <marcus.folkesson@gmail.com>
8721L: linux-iio@vger.kernel.org
8722S: Maintained
8723F: Documentation/devicetree/bindings/iio/dac/ltc1660.txt
8724F: drivers/iio/dac/ltc1660.c
8725
8719LTC4261 HARDWARE MONITOR DRIVER 8726LTC4261 HARDWARE MONITOR DRIVER
8720M: Guenter Roeck <linux@roeck-us.net> 8727M: Guenter Roeck <linux@roeck-us.net>
8721L: linux-hwmon@vger.kernel.org 8728L: linux-hwmon@vger.kernel.org
@@ -9670,6 +9677,14 @@ L: netdev@vger.kernel.org
9670S: Maintained 9677S: Maintained
9671F: drivers/net/ethernet/microchip/lan743x_* 9678F: drivers/net/ethernet/microchip/lan743x_*
9672 9679
9680MICROCHIP / ATMEL MCP3911 ADC DRIVER
9681M: Marcus Folkesson <marcus.folkesson@gmail.com>
9682M: Kent Gustavsson <kent@minoris.se>
9683L: linux-iio@vger.kernel.org
9684S: Supported
9685F: drivers/iio/adc/mcp3911.c
9686F: Documentation/devicetree/bindings/iio/adc/mcp3911.txt
9687
9673MICROCHIP USB251XB DRIVER 9688MICROCHIP USB251XB DRIVER
9674M: Richard Leitner <richard.leitner@skidata.com> 9689M: Richard Leitner <richard.leitner@skidata.com>
9675L: linux-usb@vger.kernel.org 9690L: linux-usb@vger.kernel.org
@@ -10060,11 +10075,6 @@ NATSEMI ETHERNET DRIVER (DP8381x)
10060S: Orphan 10075S: Orphan
10061F: drivers/net/ethernet/natsemi/natsemi.c 10076F: drivers/net/ethernet/natsemi/natsemi.c
10062 10077
10063NCP FILESYSTEM
10064M: Petr Vandrovec <petr@vandrovec.name>
10065S: Obsolete
10066F: drivers/staging/ncpfs/
10067
10068NCR 5380 SCSI DRIVERS 10078NCR 5380 SCSI DRIVERS
10069M: Finn Thain <fthain@telegraphics.com.au> 10079M: Finn Thain <fthain@telegraphics.com.au>
10070M: Michael Schmitz <schmitzmic@gmail.com> 10080M: Michael Schmitz <schmitzmic@gmail.com>
@@ -13911,6 +13921,13 @@ L: linux-i2c@vger.kernel.org
13911S: Maintained 13921S: Maintained
13912F: drivers/i2c/busses/i2c-stm32* 13922F: drivers/i2c/busses/i2c-stm32*
13913 13923
13924ST VL53L0X ToF RANGER(I2C) IIO DRIVER
13925M: Song Qiang <songqiang1304521@gmail.com>
13926L: linux-iio@vger.kernel.org
13927S: Maintained
13928F: drivers/iio/proximity/vl53l0x-i2c.c
13929F: Documentation/devicetree/bindings/iio/proximity/vl53l0x.txt
13930
13914STABLE BRANCH 13931STABLE BRANCH
13915M: Greg Kroah-Hartman <gregkh@linuxfoundation.org> 13932M: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
13916L: stable@vger.kernel.org 13933L: stable@vger.kernel.org
@@ -13930,11 +13947,6 @@ L: linux-erofs@lists.ozlabs.org
13930S: Maintained 13947S: Maintained
13931F: drivers/staging/erofs/ 13948F: drivers/staging/erofs/
13932 13949
13933STAGING - FLARION FT1000 DRIVERS
13934M: Marek Belisko <marek.belisko@gmail.com>
13935S: Odd Fixes
13936F: drivers/staging/ft1000/
13937
13938STAGING - INDUSTRIAL IO 13950STAGING - INDUSTRIAL IO
13939M: Jonathan Cameron <jic23@kernel.org> 13951M: Jonathan Cameron <jic23@kernel.org>
13940L: linux-iio@vger.kernel.org 13952L: linux-iio@vger.kernel.org
diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig
index 829dc96c9dd6..7993a67bd351 100644
--- a/drivers/iio/accel/Kconfig
+++ b/drivers/iio/accel/Kconfig
@@ -60,6 +60,33 @@ config ADXL345_SPI
60 will be called adxl345_spi and you will also get adxl345_core 60 will be called adxl345_spi and you will also get adxl345_core
61 for the core module. 61 for the core module.
62 62
63config ADXL372
64 tristate
65 select IIO_BUFFER
66 select IIO_TRIGGERED_BUFFER
67
68config ADXL372_SPI
69 tristate "Analog Devices ADXL372 3-Axis Accelerometer SPI Driver"
70 depends on SPI
71 select ADXL372
72 select REGMAP_SPI
73 help
74 Say yes here to add support for the Analog Devices ADXL372 triaxial
75 acceleration sensor.
76 To compile this driver as a module, choose M here: the
77 module will be called adxl372_spi.
78
79config ADXL372_I2C
80 tristate "Analog Devices ADXL372 3-Axis Accelerometer I2C Driver"
81 depends on I2C
82 select ADXL372
83 select REGMAP_I2C
84 help
85 Say yes here to add support for the Analog Devices ADXL372 triaxial
86 acceleration sensor.
87 To compile this driver as a module, choose M here: the
88 module will be called adxl372_i2c.
89
63config BMA180 90config BMA180
64 tristate "Bosch BMA180/BMA250 3-Axis Accelerometer Driver" 91 tristate "Bosch BMA180/BMA250 3-Axis Accelerometer Driver"
65 depends on I2C 92 depends on I2C
diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile
index 636d4d1b2990..56bd0215e0d4 100644
--- a/drivers/iio/accel/Makefile
+++ b/drivers/iio/accel/Makefile
@@ -9,6 +9,9 @@ obj-$(CONFIG_ADIS16209) += adis16209.o
9obj-$(CONFIG_ADXL345) += adxl345_core.o 9obj-$(CONFIG_ADXL345) += adxl345_core.o
10obj-$(CONFIG_ADXL345_I2C) += adxl345_i2c.o 10obj-$(CONFIG_ADXL345_I2C) += adxl345_i2c.o
11obj-$(CONFIG_ADXL345_SPI) += adxl345_spi.o 11obj-$(CONFIG_ADXL345_SPI) += adxl345_spi.o
12obj-$(CONFIG_ADXL372) += adxl372.o
13obj-$(CONFIG_ADXL372_I2C) += adxl372_i2c.o
14obj-$(CONFIG_ADXL372_SPI) += adxl372_spi.o
12obj-$(CONFIG_BMA180) += bma180.o 15obj-$(CONFIG_BMA180) += bma180.o
13obj-$(CONFIG_BMA220) += bma220_spi.o 16obj-$(CONFIG_BMA220) += bma220_spi.o
14obj-$(CONFIG_BMC150_ACCEL) += bmc150-accel-core.o 17obj-$(CONFIG_BMC150_ACCEL) += bmc150-accel-core.o
diff --git a/drivers/iio/accel/adxl345_i2c.c b/drivers/iio/accel/adxl345_i2c.c
index 785c89de91e7..f22f71315a0c 100644
--- a/drivers/iio/accel/adxl345_i2c.c
+++ b/drivers/iio/accel/adxl345_i2c.c
@@ -27,6 +27,9 @@ static int adxl345_i2c_probe(struct i2c_client *client,
27{ 27{
28 struct regmap *regmap; 28 struct regmap *regmap;
29 29
30 if (!id)
31 return -ENODEV;
32
30 regmap = devm_regmap_init_i2c(client, &adxl345_i2c_regmap_config); 33 regmap = devm_regmap_init_i2c(client, &adxl345_i2c_regmap_config);
31 if (IS_ERR(regmap)) { 34 if (IS_ERR(regmap)) {
32 dev_err(&client->dev, "Error initializing i2c regmap: %ld\n", 35 dev_err(&client->dev, "Error initializing i2c regmap: %ld\n",
@@ -35,7 +38,7 @@ static int adxl345_i2c_probe(struct i2c_client *client,
35 } 38 }
36 39
37 return adxl345_core_probe(&client->dev, regmap, id->driver_data, 40 return adxl345_core_probe(&client->dev, regmap, id->driver_data,
38 id ? id->name : NULL); 41 id->name);
39} 42}
40 43
41static int adxl345_i2c_remove(struct i2c_client *client) 44static int adxl345_i2c_remove(struct i2c_client *client)
diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c
new file mode 100644
index 000000000000..3b84cb243a87
--- /dev/null
+++ b/drivers/iio/accel/adxl372.c
@@ -0,0 +1,975 @@
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * ADXL372 3-Axis Digital Accelerometer core driver
4 *
5 * Copyright 2018 Analog Devices Inc.
6 */
7
8#include <linux/bitops.h>
9#include <linux/interrupt.h>
10#include <linux/irq.h>
11#include <linux/module.h>
12#include <linux/regmap.h>
13#include <linux/spi/spi.h>
14
15#include <linux/iio/iio.h>
16#include <linux/iio/sysfs.h>
17#include <linux/iio/buffer.h>
18#include <linux/iio/events.h>
19#include <linux/iio/trigger.h>
20#include <linux/iio/trigger_consumer.h>
21#include <linux/iio/triggered_buffer.h>
22
23#include "adxl372.h"
24
25/* ADXL372 registers definition */
26#define ADXL372_DEVID 0x00
27#define ADXL372_DEVID_MST 0x01
28#define ADXL372_PARTID 0x02
29#define ADXL372_STATUS_1 0x04
30#define ADXL372_STATUS_2 0x05
31#define ADXL372_FIFO_ENTRIES_2 0x06
32#define ADXL372_FIFO_ENTRIES_1 0x07
33#define ADXL372_X_DATA_H 0x08
34#define ADXL372_X_DATA_L 0x09
35#define ADXL372_Y_DATA_H 0x0A
36#define ADXL372_Y_DATA_L 0x0B
37#define ADXL372_Z_DATA_H 0x0C
38#define ADXL372_Z_DATA_L 0x0D
39#define ADXL372_X_MAXPEAK_H 0x15
40#define ADXL372_X_MAXPEAK_L 0x16
41#define ADXL372_Y_MAXPEAK_H 0x17
42#define ADXL372_Y_MAXPEAK_L 0x18
43#define ADXL372_Z_MAXPEAK_H 0x19
44#define ADXL372_Z_MAXPEAK_L 0x1A
45#define ADXL372_OFFSET_X 0x20
46#define ADXL372_OFFSET_Y 0x21
47#define ADXL372_OFFSET_Z 0x22
48#define ADXL372_X_THRESH_ACT_H 0x23
49#define ADXL372_X_THRESH_ACT_L 0x24
50#define ADXL372_Y_THRESH_ACT_H 0x25
51#define ADXL372_Y_THRESH_ACT_L 0x26
52#define ADXL372_Z_THRESH_ACT_H 0x27
53#define ADXL372_Z_THRESH_ACT_L 0x28
54#define ADXL372_TIME_ACT 0x29
55#define ADXL372_X_THRESH_INACT_H 0x2A
56#define ADXL372_X_THRESH_INACT_L 0x2B
57#define ADXL372_Y_THRESH_INACT_H 0x2C
58#define ADXL372_Y_THRESH_INACT_L 0x2D
59#define ADXL372_Z_THRESH_INACT_H 0x2E
60#define ADXL372_Z_THRESH_INACT_L 0x2F
61#define ADXL372_TIME_INACT_H 0x30
62#define ADXL372_TIME_INACT_L 0x31
63#define ADXL372_X_THRESH_ACT2_H 0x32
64#define ADXL372_X_THRESH_ACT2_L 0x33
65#define ADXL372_Y_THRESH_ACT2_H 0x34
66#define ADXL372_Y_THRESH_ACT2_L 0x35
67#define ADXL372_Z_THRESH_ACT2_H 0x36
68#define ADXL372_Z_THRESH_ACT2_L 0x37
69#define ADXL372_HPF 0x38
70#define ADXL372_FIFO_SAMPLES 0x39
71#define ADXL372_FIFO_CTL 0x3A
72#define ADXL372_INT1_MAP 0x3B
73#define ADXL372_INT2_MAP 0x3C
74#define ADXL372_TIMING 0x3D
75#define ADXL372_MEASURE 0x3E
76#define ADXL372_POWER_CTL 0x3F
77#define ADXL372_SELF_TEST 0x40
78#define ADXL372_RESET 0x41
79#define ADXL372_FIFO_DATA 0x42
80
81#define ADXL372_DEVID_VAL 0xAD
82#define ADXL372_PARTID_VAL 0xFA
83#define ADXL372_RESET_CODE 0x52
84
85/* ADXL372_POWER_CTL */
86#define ADXL372_POWER_CTL_MODE_MSK GENMASK_ULL(1, 0)
87#define ADXL372_POWER_CTL_MODE(x) (((x) & 0x3) << 0)
88
89/* ADXL372_MEASURE */
90#define ADXL372_MEASURE_LINKLOOP_MSK GENMASK_ULL(5, 4)
91#define ADXL372_MEASURE_LINKLOOP_MODE(x) (((x) & 0x3) << 4)
92#define ADXL372_MEASURE_BANDWIDTH_MSK GENMASK_ULL(2, 0)
93#define ADXL372_MEASURE_BANDWIDTH_MODE(x) (((x) & 0x7) << 0)
94
95/* ADXL372_TIMING */
96#define ADXL372_TIMING_ODR_MSK GENMASK_ULL(7, 5)
97#define ADXL372_TIMING_ODR_MODE(x) (((x) & 0x7) << 5)
98
99/* ADXL372_FIFO_CTL */
100#define ADXL372_FIFO_CTL_FORMAT_MSK GENMASK(5, 3)
101#define ADXL372_FIFO_CTL_FORMAT_MODE(x) (((x) & 0x7) << 3)
102#define ADXL372_FIFO_CTL_MODE_MSK GENMASK(2, 1)
103#define ADXL372_FIFO_CTL_MODE_MODE(x) (((x) & 0x3) << 1)
104#define ADXL372_FIFO_CTL_SAMPLES_MSK BIT(1)
105#define ADXL372_FIFO_CTL_SAMPLES_MODE(x) (((x) > 0xFF) ? 1 : 0)
106
107/* ADXL372_STATUS_1 */
108#define ADXL372_STATUS_1_DATA_RDY(x) (((x) >> 0) & 0x1)
109#define ADXL372_STATUS_1_FIFO_RDY(x) (((x) >> 1) & 0x1)
110#define ADXL372_STATUS_1_FIFO_FULL(x) (((x) >> 2) & 0x1)
111#define ADXL372_STATUS_1_FIFO_OVR(x) (((x) >> 3) & 0x1)
112#define ADXL372_STATUS_1_USR_NVM_BUSY(x) (((x) >> 5) & 0x1)
113#define ADXL372_STATUS_1_AWAKE(x) (((x) >> 6) & 0x1)
114#define ADXL372_STATUS_1_ERR_USR_REGS(x) (((x) >> 7) & 0x1)
115
116/* ADXL372_INT1_MAP */
117#define ADXL372_INT1_MAP_DATA_RDY_MSK BIT(0)
118#define ADXL372_INT1_MAP_DATA_RDY_MODE(x) (((x) & 0x1) << 0)
119#define ADXL372_INT1_MAP_FIFO_RDY_MSK BIT(1)
120#define ADXL372_INT1_MAP_FIFO_RDY_MODE(x) (((x) & 0x1) << 1)
121#define ADXL372_INT1_MAP_FIFO_FULL_MSK BIT(2)
122#define ADXL372_INT1_MAP_FIFO_FULL_MODE(x) (((x) & 0x1) << 2)
123#define ADXL372_INT1_MAP_FIFO_OVR_MSK BIT(3)
124#define ADXL372_INT1_MAP_FIFO_OVR_MODE(x) (((x) & 0x1) << 3)
125#define ADXL372_INT1_MAP_INACT_MSK BIT(4)
126#define ADXL372_INT1_MAP_INACT_MODE(x) (((x) & 0x1) << 4)
127#define ADXL372_INT1_MAP_ACT_MSK BIT(5)
128#define ADXL372_INT1_MAP_ACT_MODE(x) (((x) & 0x1) << 5)
129#define ADXL372_INT1_MAP_AWAKE_MSK BIT(6)
130#define ADXL372_INT1_MAP_AWAKE_MODE(x) (((x) & 0x1) << 6)
131#define ADXL372_INT1_MAP_LOW_MSK BIT(7)
132#define ADXL372_INT1_MAP_LOW_MODE(x) (((x) & 0x1) << 7)
133
134/* The ADXL372 includes a deep, 512 sample FIFO buffer */
135#define ADXL372_FIFO_SIZE 512
136
137/*
138 * At +/- 200g with 12-bit resolution, scale is computed as:
139 * (200 + 200) * 9.81 / (2^12 - 1) = 0.958241
140 */
141#define ADXL372_USCALE 958241
142
143enum adxl372_op_mode {
144 ADXL372_STANDBY,
145 ADXL372_WAKE_UP,
146 ADXL372_INSTANT_ON,
147 ADXL372_FULL_BW_MEASUREMENT,
148};
149
150enum adxl372_act_proc_mode {
151 ADXL372_DEFAULT,
152 ADXL372_LINKED,
153 ADXL372_LOOPED,
154};
155
156enum adxl372_th_activity {
157 ADXL372_ACTIVITY,
158 ADXL372_ACTIVITY2,
159 ADXL372_INACTIVITY,
160};
161
162enum adxl372_odr {
163 ADXL372_ODR_400HZ,
164 ADXL372_ODR_800HZ,
165 ADXL372_ODR_1600HZ,
166 ADXL372_ODR_3200HZ,
167 ADXL372_ODR_6400HZ,
168};
169
170enum adxl372_bandwidth {
171 ADXL372_BW_200HZ,
172 ADXL372_BW_400HZ,
173 ADXL372_BW_800HZ,
174 ADXL372_BW_1600HZ,
175 ADXL372_BW_3200HZ,
176};
177
178static const unsigned int adxl372_th_reg_high_addr[3] = {
179 [ADXL372_ACTIVITY] = ADXL372_X_THRESH_ACT_H,
180 [ADXL372_ACTIVITY2] = ADXL372_X_THRESH_ACT2_H,
181 [ADXL372_INACTIVITY] = ADXL372_X_THRESH_INACT_H,
182};
183
184enum adxl372_fifo_format {
185 ADXL372_XYZ_FIFO,
186 ADXL372_X_FIFO,
187 ADXL372_Y_FIFO,
188 ADXL372_XY_FIFO,
189 ADXL372_Z_FIFO,
190 ADXL372_XZ_FIFO,
191 ADXL372_YZ_FIFO,
192 ADXL372_XYZ_PEAK_FIFO,
193};
194
195enum adxl372_fifo_mode {
196 ADXL372_FIFO_BYPASSED,
197 ADXL372_FIFO_STREAMED,
198 ADXL372_FIFO_TRIGGERED,
199 ADXL372_FIFO_OLD_SAVED
200};
201
202static const int adxl372_samp_freq_tbl[5] = {
203 400, 800, 1600, 3200, 6400,
204};
205
206static const int adxl372_bw_freq_tbl[5] = {
207 200, 400, 800, 1600, 3200,
208};
209
210struct adxl372_axis_lookup {
211 unsigned int bits;
212 enum adxl372_fifo_format fifo_format;
213};
214
215static const struct adxl372_axis_lookup adxl372_axis_lookup_table[] = {
216 { BIT(0), ADXL372_X_FIFO },
217 { BIT(1), ADXL372_Y_FIFO },
218 { BIT(2), ADXL372_Z_FIFO },
219 { BIT(0) | BIT(1), ADXL372_XY_FIFO },
220 { BIT(0) | BIT(2), ADXL372_XZ_FIFO },
221 { BIT(1) | BIT(2), ADXL372_YZ_FIFO },
222 { BIT(0) | BIT(1) | BIT(2), ADXL372_XYZ_FIFO },
223};
224
225#define ADXL372_ACCEL_CHANNEL(index, reg, axis) { \
226 .type = IIO_ACCEL, \
227 .address = reg, \
228 .modified = 1, \
229 .channel2 = IIO_MOD_##axis, \
230 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
231 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
232 BIT(IIO_CHAN_INFO_SAMP_FREQ) | \
233 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \
234 .scan_index = index, \
235 .scan_type = { \
236 .sign = 's', \
237 .realbits = 12, \
238 .storagebits = 16, \
239 .shift = 4, \
240 }, \
241}
242
243static const struct iio_chan_spec adxl372_channels[] = {
244 ADXL372_ACCEL_CHANNEL(0, ADXL372_X_DATA_H, X),
245 ADXL372_ACCEL_CHANNEL(1, ADXL372_Y_DATA_H, Y),
246 ADXL372_ACCEL_CHANNEL(2, ADXL372_Z_DATA_H, Z),
247};
248
249struct adxl372_state {
250 int irq;
251 struct device *dev;
252 struct regmap *regmap;
253 struct iio_trigger *dready_trig;
254 enum adxl372_fifo_mode fifo_mode;
255 enum adxl372_fifo_format fifo_format;
256 enum adxl372_op_mode op_mode;
257 enum adxl372_act_proc_mode act_proc_mode;
258 enum adxl372_odr odr;
259 enum adxl372_bandwidth bw;
260 u32 act_time_ms;
261 u32 inact_time_ms;
262 u8 fifo_set_size;
263 u8 int1_bitmask;
264 u8 int2_bitmask;
265 u16 watermark;
266 __be16 fifo_buf[ADXL372_FIFO_SIZE];
267};
268
269static const unsigned long adxl372_channel_masks[] = {
270 BIT(0), BIT(1), BIT(2),
271 BIT(0) | BIT(1),
272 BIT(0) | BIT(2),
273 BIT(1) | BIT(2),
274 BIT(0) | BIT(1) | BIT(2),
275 0
276};
277
278static int adxl372_read_axis(struct adxl372_state *st, u8 addr)
279{
280 __be16 regval;
281 int ret;
282
283 ret = regmap_bulk_read(st->regmap, addr, &regval, sizeof(regval));
284 if (ret < 0)
285 return ret;
286
287 return be16_to_cpu(regval);
288}
289
290static int adxl372_set_op_mode(struct adxl372_state *st,
291 enum adxl372_op_mode op_mode)
292{
293 int ret;
294
295 ret = regmap_update_bits(st->regmap, ADXL372_POWER_CTL,
296 ADXL372_POWER_CTL_MODE_MSK,
297 ADXL372_POWER_CTL_MODE(op_mode));
298 if (ret < 0)
299 return ret;
300
301 st->op_mode = op_mode;
302
303 return ret;
304}
305
306static int adxl372_set_odr(struct adxl372_state *st,
307 enum adxl372_odr odr)
308{
309 int ret;
310
311 ret = regmap_update_bits(st->regmap, ADXL372_TIMING,
312 ADXL372_TIMING_ODR_MSK,
313 ADXL372_TIMING_ODR_MODE(odr));
314 if (ret < 0)
315 return ret;
316
317 st->odr = odr;
318
319 return ret;
320}
321
322static int adxl372_find_closest_match(const int *array,
323 unsigned int size, int val)
324{
325 int i;
326
327 for (i = 0; i < size; i++) {
328 if (val <= array[i])
329 return i;
330 }
331
332 return size - 1;
333}
334
335static int adxl372_set_bandwidth(struct adxl372_state *st,
336 enum adxl372_bandwidth bw)
337{
338 int ret;
339
340 ret = regmap_update_bits(st->regmap, ADXL372_MEASURE,
341 ADXL372_MEASURE_BANDWIDTH_MSK,
342 ADXL372_MEASURE_BANDWIDTH_MODE(bw));
343 if (ret < 0)
344 return ret;
345
346 st->bw = bw;
347
348 return ret;
349}
350
351static int adxl372_set_act_proc_mode(struct adxl372_state *st,
352 enum adxl372_act_proc_mode mode)
353{
354 int ret;
355
356 ret = regmap_update_bits(st->regmap,
357 ADXL372_MEASURE,
358 ADXL372_MEASURE_LINKLOOP_MSK,
359 ADXL372_MEASURE_LINKLOOP_MODE(mode));
360 if (ret < 0)
361 return ret;
362
363 st->act_proc_mode = mode;
364
365 return ret;
366}
367
368static int adxl372_set_activity_threshold(struct adxl372_state *st,
369 enum adxl372_th_activity act,
370 bool ref_en, bool enable,
371 unsigned int threshold)
372{
373 unsigned char buf[6];
374 unsigned char th_reg_high_val, th_reg_low_val, th_reg_high_addr;
375
376 /* scale factor is 100 mg/code */
377 th_reg_high_val = (threshold / 100) >> 3;
378 th_reg_low_val = ((threshold / 100) << 5) | (ref_en << 1) | enable;
379 th_reg_high_addr = adxl372_th_reg_high_addr[act];
380
381 buf[0] = th_reg_high_val;
382 buf[1] = th_reg_low_val;
383 buf[2] = th_reg_high_val;
384 buf[3] = th_reg_low_val;
385 buf[4] = th_reg_high_val;
386 buf[5] = th_reg_low_val;
387
388 return regmap_bulk_write(st->regmap, th_reg_high_addr,
389 buf, ARRAY_SIZE(buf));
390}
391
392static int adxl372_set_activity_time_ms(struct adxl372_state *st,
393 unsigned int act_time_ms)
394{
395 unsigned int reg_val, scale_factor;
396 int ret;
397
398 /*
399 * 3.3 ms per code is the scale factor of the TIME_ACT register for
400 * ODR = 6400 Hz. It is 6.6 ms per code for ODR = 3200 Hz and below.
401 */
402 if (st->odr == ADXL372_ODR_6400HZ)
403 scale_factor = 3300;
404 else
405 scale_factor = 6600;
406
407 reg_val = DIV_ROUND_CLOSEST(act_time_ms * 1000, scale_factor);
408
409 /* TIME_ACT register is 8 bits wide */
410 if (reg_val > 0xFF)
411 reg_val = 0xFF;
412
413 ret = regmap_write(st->regmap, ADXL372_TIME_ACT, reg_val);
414 if (ret < 0)
415 return ret;
416
417 st->act_time_ms = act_time_ms;
418
419 return ret;
420}
421
422static int adxl372_set_inactivity_time_ms(struct adxl372_state *st,
423 unsigned int inact_time_ms)
424{
425 unsigned int reg_val_h, reg_val_l, res, scale_factor;
426 int ret;
427
428 /*
429 * 13 ms per code is the scale factor of the TIME_INACT register for
430 * ODR = 6400 Hz. It is 26 ms per code for ODR = 3200 Hz and below.
431 */
432 if (st->odr == ADXL372_ODR_6400HZ)
433 scale_factor = 13;
434 else
435 scale_factor = 26;
436
437 res = DIV_ROUND_CLOSEST(inact_time_ms, scale_factor);
438 reg_val_h = (res >> 8) & 0xFF;
439 reg_val_l = res & 0xFF;
440
441 ret = regmap_write(st->regmap, ADXL372_TIME_INACT_H, reg_val_h);
442 if (ret < 0)
443 return ret;
444
445 ret = regmap_write(st->regmap, ADXL372_TIME_INACT_L, reg_val_l);
446 if (ret < 0)
447 return ret;
448
449 st->inact_time_ms = inact_time_ms;
450
451 return ret;
452}
453
454static int adxl372_set_interrupts(struct adxl372_state *st,
455 unsigned char int1_bitmask,
456 unsigned char int2_bitmask)
457{
458 int ret;
459
460 ret = regmap_write(st->regmap, ADXL372_INT1_MAP, int1_bitmask);
461 if (ret < 0)
462 return ret;
463
464 return regmap_write(st->regmap, ADXL372_INT2_MAP, int2_bitmask);
465}
466
467static int adxl372_configure_fifo(struct adxl372_state *st)
468{
469 unsigned int fifo_samples, fifo_ctl;
470 int ret;
471
472 /* FIFO must be configured while in standby mode */
473 ret = adxl372_set_op_mode(st, ADXL372_STANDBY);
474 if (ret < 0)
475 return ret;
476
477 fifo_samples = st->watermark & 0xFF;
478 fifo_ctl = ADXL372_FIFO_CTL_FORMAT_MODE(st->fifo_format) |
479 ADXL372_FIFO_CTL_MODE_MODE(st->fifo_mode) |
480 ADXL372_FIFO_CTL_SAMPLES_MODE(st->watermark);
481
482 ret = regmap_write(st->regmap, ADXL372_FIFO_SAMPLES, fifo_samples);
483 if (ret < 0)
484 return ret;
485
486 ret = regmap_write(st->regmap, ADXL372_FIFO_CTL, fifo_ctl);
487 if (ret < 0)
488 return ret;
489
490 return adxl372_set_op_mode(st, ADXL372_FULL_BW_MEASUREMENT);
491}
492
493static int adxl372_get_status(struct adxl372_state *st,
494 u8 *status1, u8 *status2,
495 u16 *fifo_entries)
496{
497 __be32 buf;
498 u32 val;
499 int ret;
500
501 /* STATUS1, STATUS2, FIFO_ENTRIES2 and FIFO_ENTRIES are adjacent regs */
502 ret = regmap_bulk_read(st->regmap, ADXL372_STATUS_1,
503 &buf, sizeof(buf));
504 if (ret < 0)
505 return ret;
506
507 val = be32_to_cpu(buf);
508
509 *status1 = (val >> 24) & 0x0F;
510 *status2 = (val >> 16) & 0x0F;
511 /*
512 * FIFO_ENTRIES contains the least significant byte, and FIFO_ENTRIES2
513 * contains the two most significant bits
514 */
515 *fifo_entries = val & 0x3FF;
516
517 return ret;
518}
519
520static irqreturn_t adxl372_trigger_handler(int irq, void *p)
521{
522 struct iio_poll_func *pf = p;
523 struct iio_dev *indio_dev = pf->indio_dev;
524 struct adxl372_state *st = iio_priv(indio_dev);
525 u8 status1, status2;
526 u16 fifo_entries;
527 int i, ret;
528
529 ret = adxl372_get_status(st, &status1, &status2, &fifo_entries);
530 if (ret < 0)
531 goto err;
532
533 if (st->fifo_mode != ADXL372_FIFO_BYPASSED &&
534 ADXL372_STATUS_1_FIFO_FULL(status1)) {
535 /*
536 * When reading data from multiple axes from the FIFO,
537 * to ensure that data is not overwritten and stored out
538 * of order at least one sample set must be left in the
539 * FIFO after every read.
540 */
541 fifo_entries -= st->fifo_set_size;
542
543 /* Read data from the FIFO */
544 ret = regmap_noinc_read(st->regmap, ADXL372_FIFO_DATA,
545 st->fifo_buf,
546 fifo_entries * sizeof(u16));
547 if (ret < 0)
548 goto err;
549
550 /* Each sample is 2 bytes */
551 for (i = 0; i < fifo_entries * sizeof(u16);
552 i += st->fifo_set_size * sizeof(u16))
553 iio_push_to_buffers(indio_dev, &st->fifo_buf[i]);
554 }
555err:
556 iio_trigger_notify_done(indio_dev->trig);
557 return IRQ_HANDLED;
558}
559
560static int adxl372_setup(struct adxl372_state *st)
561{
562 unsigned int regval;
563 int ret;
564
565 ret = regmap_read(st->regmap, ADXL372_DEVID, &regval);
566 if (ret < 0)
567 return ret;
568
569 if (regval != ADXL372_DEVID_VAL) {
570 dev_err(st->dev, "Invalid chip id %x\n", regval);
571 return -ENODEV;
572 }
573
574 ret = adxl372_set_op_mode(st, ADXL372_STANDBY);
575 if (ret < 0)
576 return ret;
577
578 /* Set threshold for activity detection to 1g */
579 ret = adxl372_set_activity_threshold(st, ADXL372_ACTIVITY,
580 true, true, 1000);
581 if (ret < 0)
582 return ret;
583
584 /* Set threshold for inactivity detection to 100mg */
585 ret = adxl372_set_activity_threshold(st, ADXL372_INACTIVITY,
586 true, true, 100);
587 if (ret < 0)
588 return ret;
589
590 /* Set activity processing in Looped mode */
591 ret = adxl372_set_act_proc_mode(st, ADXL372_LOOPED);
592 if (ret < 0)
593 return ret;
594
595 ret = adxl372_set_odr(st, ADXL372_ODR_6400HZ);
596 if (ret < 0)
597 return ret;
598
599 ret = adxl372_set_bandwidth(st, ADXL372_BW_3200HZ);
600 if (ret < 0)
601 return ret;
602
603 /* Set activity timer to 1ms */
604 ret = adxl372_set_activity_time_ms(st, 1);
605 if (ret < 0)
606 return ret;
607
608 /* Set inactivity timer to 10s */
609 ret = adxl372_set_inactivity_time_ms(st, 10000);
610 if (ret < 0)
611 return ret;
612
613 /* Set the mode of operation to full bandwidth measurement mode */
614 return adxl372_set_op_mode(st, ADXL372_FULL_BW_MEASUREMENT);
615}
616
617static int adxl372_reg_access(struct iio_dev *indio_dev,
618 unsigned int reg,
619 unsigned int writeval,
620 unsigned int *readval)
621{
622 struct adxl372_state *st = iio_priv(indio_dev);
623
624 if (readval)
625 return regmap_read(st->regmap, reg, readval);
626 else
627 return regmap_write(st->regmap, reg, writeval);
628}
629
630static int adxl372_read_raw(struct iio_dev *indio_dev,
631 struct iio_chan_spec const *chan,
632 int *val, int *val2, long info)
633{
634 struct adxl372_state *st = iio_priv(indio_dev);
635 int ret;
636
637 switch (info) {
638 case IIO_CHAN_INFO_RAW:
639 ret = iio_device_claim_direct_mode(indio_dev);
640 if (ret)
641 return ret;
642
643 ret = adxl372_read_axis(st, chan->address);
644 iio_device_release_direct_mode(indio_dev);
645 if (ret < 0)
646 return ret;
647
648 *val = sign_extend32(ret >> chan->scan_type.shift,
649 chan->scan_type.realbits - 1);
650 return IIO_VAL_INT;
651 case IIO_CHAN_INFO_SCALE:
652 *val = 0;
653 *val2 = ADXL372_USCALE;
654 return IIO_VAL_INT_PLUS_MICRO;
655 case IIO_CHAN_INFO_SAMP_FREQ:
656 *val = adxl372_samp_freq_tbl[st->odr];
657 return IIO_VAL_INT;
658 case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
659 *val = adxl372_bw_freq_tbl[st->bw];
660 return IIO_VAL_INT;
661 }
662
663 return -EINVAL;
664}
665
666static int adxl372_write_raw(struct iio_dev *indio_dev,
667 struct iio_chan_spec const *chan,
668 int val, int val2, long info)
669{
670 struct adxl372_state *st = iio_priv(indio_dev);
671 int odr_index, bw_index, ret;
672
673 switch (info) {
674 case IIO_CHAN_INFO_SAMP_FREQ:
675 odr_index = adxl372_find_closest_match(adxl372_samp_freq_tbl,
676 ARRAY_SIZE(adxl372_samp_freq_tbl),
677 val);
678 ret = adxl372_set_odr(st, odr_index);
679 if (ret < 0)
680 return ret;
681 /*
682 * The timer period depends on the ODR selected.
683 * At 3200 Hz and below, it is 6.6 ms; at 6400 Hz, it is 3.3 ms
684 */
685 ret = adxl372_set_activity_time_ms(st, st->act_time_ms);
686 if (ret < 0)
687 return ret;
688 /*
689 * The timer period depends on the ODR selected.
690 * At 3200 Hz and below, it is 26 ms; at 6400 Hz, it is 13 ms
691 */
692 ret = adxl372_set_inactivity_time_ms(st, st->inact_time_ms);
693 if (ret < 0)
694 return ret;
695 /*
696 * The maximum bandwidth is constrained to at most half of
697 * the ODR to ensure that the Nyquist criteria is not violated
698 */
699 if (st->bw > odr_index)
700 ret = adxl372_set_bandwidth(st, odr_index);
701
702 return ret;
703 case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
704 bw_index = adxl372_find_closest_match(adxl372_bw_freq_tbl,
705 ARRAY_SIZE(adxl372_bw_freq_tbl),
706 val);
707 return adxl372_set_bandwidth(st, bw_index);
708 default:
709 return -EINVAL;
710 }
711}
712
713static ssize_t adxl372_show_filter_freq_avail(struct device *dev,
714 struct device_attribute *attr,
715 char *buf)
716{
717 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
718 struct adxl372_state *st = iio_priv(indio_dev);
719 int i;
720 size_t len = 0;
721
722 for (i = 0; i <= st->odr; i++)
723 len += scnprintf(buf + len, PAGE_SIZE - len,
724 "%d ", adxl372_bw_freq_tbl[i]);
725
726 buf[len - 1] = '\n';
727
728 return len;
729}
730
731static ssize_t adxl372_get_fifo_enabled(struct device *dev,
732 struct device_attribute *attr,
733 char *buf)
734{
735 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
736 struct adxl372_state *st = iio_priv(indio_dev);
737
738 return sprintf(buf, "%d\n", st->fifo_mode);
739}
740
741static ssize_t adxl372_get_fifo_watermark(struct device *dev,
742 struct device_attribute *attr,
743 char *buf)
744{
745 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
746 struct adxl372_state *st = iio_priv(indio_dev);
747
748 return sprintf(buf, "%d\n", st->watermark);
749}
750
751static IIO_CONST_ATTR(hwfifo_watermark_min, "1");
752static IIO_CONST_ATTR(hwfifo_watermark_max,
753 __stringify(ADXL372_FIFO_SIZE));
754static IIO_DEVICE_ATTR(hwfifo_watermark, 0444,
755 adxl372_get_fifo_watermark, NULL, 0);
756static IIO_DEVICE_ATTR(hwfifo_enabled, 0444,
757 adxl372_get_fifo_enabled, NULL, 0);
758
759static const struct attribute *adxl372_fifo_attributes[] = {
760 &iio_const_attr_hwfifo_watermark_min.dev_attr.attr,
761 &iio_const_attr_hwfifo_watermark_max.dev_attr.attr,
762 &iio_dev_attr_hwfifo_watermark.dev_attr.attr,
763 &iio_dev_attr_hwfifo_enabled.dev_attr.attr,
764 NULL,
765};
766
767static int adxl372_set_watermark(struct iio_dev *indio_dev, unsigned int val)
768{
769 struct adxl372_state *st = iio_priv(indio_dev);
770
771 if (val > ADXL372_FIFO_SIZE)
772 val = ADXL372_FIFO_SIZE;
773
774 st->watermark = val;
775
776 return 0;
777}
778
779static int adxl372_buffer_postenable(struct iio_dev *indio_dev)
780{
781 struct adxl372_state *st = iio_priv(indio_dev);
782 unsigned int mask;
783 int i, ret;
784
785 ret = adxl372_set_interrupts(st, ADXL372_INT1_MAP_FIFO_FULL_MSK, 0);
786 if (ret < 0)
787 return ret;
788
789 mask = *indio_dev->active_scan_mask;
790
791 for (i = 0; i < ARRAY_SIZE(adxl372_axis_lookup_table); i++) {
792 if (mask == adxl372_axis_lookup_table[i].bits)
793 break;
794 }
795
796 if (i == ARRAY_SIZE(adxl372_axis_lookup_table))
797 return -EINVAL;
798
799 st->fifo_format = adxl372_axis_lookup_table[i].fifo_format;
800 st->fifo_set_size = bitmap_weight(indio_dev->active_scan_mask,
801 indio_dev->masklength);
802 /*
803 * The 512 FIFO samples can be allotted in several ways, such as:
804 * 170 sample sets of concurrent 3-axis data
805 * 256 sample sets of concurrent 2-axis data (user selectable)
806 * 512 sample sets of single-axis data
807 */
808 if ((st->watermark * st->fifo_set_size) > ADXL372_FIFO_SIZE)
809 st->watermark = (ADXL372_FIFO_SIZE / st->fifo_set_size);
810
811 st->fifo_mode = ADXL372_FIFO_STREAMED;
812
813 ret = adxl372_configure_fifo(st);
814 if (ret < 0) {
815 st->fifo_mode = ADXL372_FIFO_BYPASSED;
816 adxl372_set_interrupts(st, 0, 0);
817 return ret;
818 }
819
820 return iio_triggered_buffer_postenable(indio_dev);
821}
822
823static int adxl372_buffer_predisable(struct iio_dev *indio_dev)
824{
825 struct adxl372_state *st = iio_priv(indio_dev);
826 int ret;
827
828 ret = iio_triggered_buffer_predisable(indio_dev);
829 if (ret < 0)
830 return ret;
831
832 adxl372_set_interrupts(st, 0, 0);
833 st->fifo_mode = ADXL372_FIFO_BYPASSED;
834 adxl372_configure_fifo(st);
835
836 return 0;
837}
838
839static const struct iio_buffer_setup_ops adxl372_buffer_ops = {
840 .postenable = adxl372_buffer_postenable,
841 .predisable = adxl372_buffer_predisable,
842};
843
844static int adxl372_dready_trig_set_state(struct iio_trigger *trig,
845 bool state)
846{
847 struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
848 struct adxl372_state *st = iio_priv(indio_dev);
849 unsigned long int mask = 0;
850
851 if (state)
852 mask = ADXL372_INT1_MAP_FIFO_FULL_MSK;
853
854 return adxl372_set_interrupts(st, mask, 0);
855}
856
857static int adxl372_validate_trigger(struct iio_dev *indio_dev,
858 struct iio_trigger *trig)
859{
860 struct adxl372_state *st = iio_priv(indio_dev);
861
862 if (st->dready_trig != trig)
863 return -EINVAL;
864
865 return 0;
866}
867
868static const struct iio_trigger_ops adxl372_trigger_ops = {
869 .validate_device = &iio_trigger_validate_own_device,
870 .set_trigger_state = adxl372_dready_trig_set_state,
871};
872
873static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("400 800 1600 3200 6400");
874static IIO_DEVICE_ATTR(in_accel_filter_low_pass_3db_frequency_available,
875 0444, adxl372_show_filter_freq_avail, NULL, 0);
876
877static struct attribute *adxl372_attributes[] = {
878 &iio_const_attr_sampling_frequency_available.dev_attr.attr,
879 &iio_dev_attr_in_accel_filter_low_pass_3db_frequency_available.dev_attr.attr,
880 NULL,
881};
882
883static const struct attribute_group adxl372_attrs_group = {
884 .attrs = adxl372_attributes,
885};
886
887static const struct iio_info adxl372_info = {
888 .validate_trigger = &adxl372_validate_trigger,
889 .attrs = &adxl372_attrs_group,
890 .read_raw = adxl372_read_raw,
891 .write_raw = adxl372_write_raw,
892 .debugfs_reg_access = &adxl372_reg_access,
893 .hwfifo_set_watermark = adxl372_set_watermark,
894};
895
896bool adxl372_readable_noinc_reg(struct device *dev, unsigned int reg)
897{
898 return (reg == ADXL372_FIFO_DATA);
899}
900EXPORT_SYMBOL_GPL(adxl372_readable_noinc_reg);
901
902int adxl372_probe(struct device *dev, struct regmap *regmap,
903 int irq, const char *name)
904{
905 struct iio_dev *indio_dev;
906 struct adxl372_state *st;
907 int ret;
908
909 indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
910 if (!indio_dev)
911 return -ENOMEM;
912
913 st = iio_priv(indio_dev);
914 dev_set_drvdata(dev, indio_dev);
915
916 st->dev = dev;
917 st->regmap = regmap;
918 st->irq = irq;
919
920 indio_dev->channels = adxl372_channels;
921 indio_dev->num_channels = ARRAY_SIZE(adxl372_channels);
922 indio_dev->available_scan_masks = adxl372_channel_masks;
923 indio_dev->dev.parent = dev;
924 indio_dev->name = name;
925 indio_dev->info = &adxl372_info;
926 indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE;
927
928 ret = adxl372_setup(st);
929 if (ret < 0) {
930 dev_err(dev, "ADXL372 setup failed\n");
931 return ret;
932 }
933
934 ret = devm_iio_triggered_buffer_setup(dev,
935 indio_dev, NULL,
936 adxl372_trigger_handler,
937 &adxl372_buffer_ops);
938 if (ret < 0)
939 return ret;
940
941 iio_buffer_set_attrs(indio_dev->buffer, adxl372_fifo_attributes);
942
943 if (st->irq) {
944 st->dready_trig = devm_iio_trigger_alloc(dev,
945 "%s-dev%d",
946 indio_dev->name,
947 indio_dev->id);
948 if (st->dready_trig == NULL)
949 return -ENOMEM;
950
951 st->dready_trig->ops = &adxl372_trigger_ops;
952 st->dready_trig->dev.parent = dev;
953 iio_trigger_set_drvdata(st->dready_trig, indio_dev);
954 ret = devm_iio_trigger_register(dev, st->dready_trig);
955 if (ret < 0)
956 return ret;
957
958 indio_dev->trig = iio_trigger_get(st->dready_trig);
959
960 ret = devm_request_threaded_irq(dev, st->irq,
961 iio_trigger_generic_data_rdy_poll,
962 NULL,
963 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
964 indio_dev->name, st->dready_trig);
965 if (ret < 0)
966 return ret;
967 }
968
969 return devm_iio_device_register(dev, indio_dev);
970}
971EXPORT_SYMBOL_GPL(adxl372_probe);
972
973MODULE_AUTHOR("Stefan Popa <stefan.popa@analog.com>");
974MODULE_DESCRIPTION("Analog Devices ADXL372 3-axis accelerometer driver");
975MODULE_LICENSE("GPL");
diff --git a/drivers/iio/accel/adxl372.h b/drivers/iio/accel/adxl372.h
new file mode 100644
index 000000000000..80a0aa9714fc
--- /dev/null
+++ b/drivers/iio/accel/adxl372.h
@@ -0,0 +1,17 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * ADXL372 3-Axis Digital Accelerometer
4 *
5 * Copyright 2018 Analog Devices Inc.
6 */
7
8#ifndef _ADXL372_H_
9#define _ADXL372_H_
10
11#define ADXL372_REVID 0x03
12
13int adxl372_probe(struct device *dev, struct regmap *regmap,
14 int irq, const char *name);
15bool adxl372_readable_noinc_reg(struct device *dev, unsigned int reg);
16
17#endif /* _ADXL372_H_ */
diff --git a/drivers/iio/accel/adxl372_i2c.c b/drivers/iio/accel/adxl372_i2c.c
new file mode 100644
index 000000000000..e1affe480c77
--- /dev/null
+++ b/drivers/iio/accel/adxl372_i2c.c
@@ -0,0 +1,61 @@
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * ADXL372 3-Axis Digital Accelerometer I2C driver
4 *
5 * Copyright 2018 Analog Devices Inc.
6 */
7
8#include <linux/i2c.h>
9#include <linux/module.h>
10#include <linux/regmap.h>
11
12#include "adxl372.h"
13
14static const struct regmap_config adxl372_regmap_config = {
15 .reg_bits = 8,
16 .val_bits = 8,
17 .readable_noinc_reg = adxl372_readable_noinc_reg,
18};
19
20static int adxl372_i2c_probe(struct i2c_client *client,
21 const struct i2c_device_id *id)
22{
23 struct regmap *regmap;
24 unsigned int regval;
25 int ret;
26
27 regmap = devm_regmap_init_i2c(client, &adxl372_regmap_config);
28 if (IS_ERR(regmap))
29 return PTR_ERR(regmap);
30
31 ret = regmap_read(regmap, ADXL372_REVID, &regval);
32 if (ret < 0)
33 return ret;
34
35 /* Starting with the 3rd revision an I2C chip bug was fixed */
36 if (regval < 3)
37 dev_warn(&client->dev,
38 "I2C might not work properly with other devices on the bus");
39
40 return adxl372_probe(&client->dev, regmap, client->irq, id->name);
41}
42
43static const struct i2c_device_id adxl372_i2c_id[] = {
44 { "adxl372", 0 },
45 {}
46};
47MODULE_DEVICE_TABLE(i2c, adxl372_i2c_id);
48
49static struct i2c_driver adxl372_i2c_driver = {
50 .driver = {
51 .name = "adxl372_i2c",
52 },
53 .probe = adxl372_i2c_probe,
54 .id_table = adxl372_i2c_id,
55};
56
57module_i2c_driver(adxl372_i2c_driver);
58
59MODULE_AUTHOR("Stefan Popa <stefan.popa@analog.com>");
60MODULE_DESCRIPTION("Analog Devices ADXL372 3-axis accelerometer I2C driver");
61MODULE_LICENSE("GPL");
diff --git a/drivers/iio/accel/adxl372_spi.c b/drivers/iio/accel/adxl372_spi.c
new file mode 100644
index 000000000000..e14e655ef165
--- /dev/null
+++ b/drivers/iio/accel/adxl372_spi.c
@@ -0,0 +1,52 @@
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * ADXL372 3-Axis Digital Accelerometer SPI driver
4 *
5 * Copyright 2018 Analog Devices Inc.
6 */
7
8#include <linux/module.h>
9#include <linux/regmap.h>
10#include <linux/spi/spi.h>
11
12#include "adxl372.h"
13
14static const struct regmap_config adxl372_spi_regmap_config = {
15 .reg_bits = 7,
16 .pad_bits = 1,
17 .val_bits = 8,
18 .read_flag_mask = BIT(0),
19 .readable_noinc_reg = adxl372_readable_noinc_reg,
20};
21
22static int adxl372_spi_probe(struct spi_device *spi)
23{
24 const struct spi_device_id *id = spi_get_device_id(spi);
25 struct regmap *regmap;
26
27 regmap = devm_regmap_init_spi(spi, &adxl372_spi_regmap_config);
28 if (IS_ERR(regmap))
29 return PTR_ERR(regmap);
30
31 return adxl372_probe(&spi->dev, regmap, spi->irq, id->name);
32}
33
34static const struct spi_device_id adxl372_spi_id[] = {
35 { "adxl372", 0 },
36 {}
37};
38MODULE_DEVICE_TABLE(spi, adxl372_spi_id);
39
40static struct spi_driver adxl372_spi_driver = {
41 .driver = {
42 .name = "adxl372_spi",
43 },
44 .probe = adxl372_spi_probe,
45 .id_table = adxl372_spi_id,
46};
47
48module_spi_driver(adxl372_spi_driver);
49
50MODULE_AUTHOR("Stefan Popa <stefan.popa@analog.com>");
51MODULE_DESCRIPTION("Analog Devices ADXL372 3-axis accelerometer SPI driver");
52MODULE_LICENSE("GPL");
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 4a754921fb6f..a52fea8749a9 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -501,6 +501,16 @@ config MCP3422
501 This driver can also be built as a module. If so, the module will be 501 This driver can also be built as a module. If so, the module will be
502 called mcp3422. 502 called mcp3422.
503 503
504config MCP3911
505 tristate "Microchip Technology MCP3911 driver"
506 depends on SPI
507 help
508 Say yes here to build support for Microchip Technology's MCP3911
509 analog to digital converter.
510
511 This driver can also be built as a module. If so, the module will be
512 called mcp3911.
513
504config MEDIATEK_MT6577_AUXADC 514config MEDIATEK_MT6577_AUXADC
505 tristate "MediaTek AUXADC driver" 515 tristate "MediaTek AUXADC driver"
506 depends on ARCH_MEDIATEK || COMPILE_TEST 516 depends on ARCH_MEDIATEK || COMPILE_TEST
@@ -596,6 +606,26 @@ config QCOM_SPMI_VADC
596 To compile this driver as a module, choose M here: the module will 606 To compile this driver as a module, choose M here: the module will
597 be called qcom-spmi-vadc. 607 be called qcom-spmi-vadc.
598 608
609config QCOM_SPMI_ADC5
610 tristate "Qualcomm Technologies Inc. SPMI PMIC5 ADC"
611 depends on SPMI
612 select REGMAP_SPMI
613 select QCOM_VADC_COMMON
614 help
615 This is the IIO Voltage PMIC5 ADC driver for Qualcomm Technologies Inc.
616
617 The driver supports multiple channels read. The ADC is a 16-bit
618 sigma-delta ADC. The hardware supports calibrated results for
619 conversion requests and clients include reading voltage phone
620 power, on board system thermistors connected to the PMIC ADC,
621 PMIC die temperature, charger temperature, battery current, USB voltage
622 input, voltage signals connected to supported PMIC GPIO inputs. The
623 hardware supports internal pull-up for thermistors and can choose between
624 a 100k, 30k and 400k pull up using the ADC channels.
625
626 To compile this driver as a module, choose M here: the module will
627 be called qcom-spmi-adc5.
628
599config RCAR_GYRO_ADC 629config RCAR_GYRO_ADC
600 tristate "Renesas R-Car GyroADC driver" 630 tristate "Renesas R-Car GyroADC driver"
601 depends on ARCH_RCAR_GEN2 || COMPILE_TEST 631 depends on ARCH_RCAR_GEN2 || COMPILE_TEST
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index 03db7b578f9c..a6e6a0b659e2 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -47,12 +47,14 @@ obj-$(CONFIG_MAX1363) += max1363.o
47obj-$(CONFIG_MAX9611) += max9611.o 47obj-$(CONFIG_MAX9611) += max9611.o
48obj-$(CONFIG_MCP320X) += mcp320x.o 48obj-$(CONFIG_MCP320X) += mcp320x.o
49obj-$(CONFIG_MCP3422) += mcp3422.o 49obj-$(CONFIG_MCP3422) += mcp3422.o
50obj-$(CONFIG_MCP3911) += mcp3911.o
50obj-$(CONFIG_MEDIATEK_MT6577_AUXADC) += mt6577_auxadc.o 51obj-$(CONFIG_MEDIATEK_MT6577_AUXADC) += mt6577_auxadc.o
51obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o 52obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o
52obj-$(CONFIG_MESON_SARADC) += meson_saradc.o 53obj-$(CONFIG_MESON_SARADC) += meson_saradc.o
53obj-$(CONFIG_MXS_LRADC_ADC) += mxs-lradc-adc.o 54obj-$(CONFIG_MXS_LRADC_ADC) += mxs-lradc-adc.o
54obj-$(CONFIG_NAU7802) += nau7802.o 55obj-$(CONFIG_NAU7802) += nau7802.o
55obj-$(CONFIG_PALMAS_GPADC) += palmas_gpadc.o 56obj-$(CONFIG_PALMAS_GPADC) += palmas_gpadc.o
57obj-$(CONFIG_QCOM_SPMI_ADC5) += qcom-spmi-adc5.o
56obj-$(CONFIG_QCOM_SPMI_IADC) += qcom-spmi-iadc.o 58obj-$(CONFIG_QCOM_SPMI_IADC) += qcom-spmi-iadc.o
57obj-$(CONFIG_QCOM_VADC_COMMON) += qcom-vadc-common.o 59obj-$(CONFIG_QCOM_VADC_COMMON) += qcom-vadc-common.o
58obj-$(CONFIG_QCOM_SPMI_VADC) += qcom-spmi-vadc.o 60obj-$(CONFIG_QCOM_SPMI_VADC) += qcom-spmi-vadc.o
diff --git a/drivers/iio/adc/ad7298.c b/drivers/iio/adc/ad7298.c
index 2b20c6c8ec7f..e0220825fde0 100644
--- a/drivers/iio/adc/ad7298.c
+++ b/drivers/iio/adc/ad7298.c
@@ -385,6 +385,6 @@ static struct spi_driver ad7298_driver = {
385}; 385};
386module_spi_driver(ad7298_driver); 386module_spi_driver(ad7298_driver);
387 387
388MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 388MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
389MODULE_DESCRIPTION("Analog Devices AD7298 ADC"); 389MODULE_DESCRIPTION("Analog Devices AD7298 ADC");
390MODULE_LICENSE("GPL v2"); 390MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/adc/ad7476.c b/drivers/iio/adc/ad7476.c
index fbaae47746a8..0549686b9ef8 100644
--- a/drivers/iio/adc/ad7476.c
+++ b/drivers/iio/adc/ad7476.c
@@ -328,6 +328,6 @@ static struct spi_driver ad7476_driver = {
328}; 328};
329module_spi_driver(ad7476_driver); 329module_spi_driver(ad7476_driver);
330 330
331MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 331MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
332MODULE_DESCRIPTION("Analog Devices AD7476 and similar 1-channel ADCs"); 332MODULE_DESCRIPTION("Analog Devices AD7476 and similar 1-channel ADCs");
333MODULE_LICENSE("GPL v2"); 333MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/adc/ad7793.c b/drivers/iio/adc/ad7793.c
index d4bbe5b53318..4ac3ae62f56f 100644
--- a/drivers/iio/adc/ad7793.c
+++ b/drivers/iio/adc/ad7793.c
@@ -822,6 +822,6 @@ static struct spi_driver ad7793_driver = {
822}; 822};
823module_spi_driver(ad7793_driver); 823module_spi_driver(ad7793_driver);
824 824
825MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 825MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
826MODULE_DESCRIPTION("Analog Devices AD7793 and similar ADCs"); 826MODULE_DESCRIPTION("Analog Devices AD7793 and similar ADCs");
827MODULE_LICENSE("GPL v2"); 827MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/adc/ad7887.c b/drivers/iio/adc/ad7887.c
index 205c0f1761aa..9d4c2467d362 100644
--- a/drivers/iio/adc/ad7887.c
+++ b/drivers/iio/adc/ad7887.c
@@ -362,6 +362,6 @@ static struct spi_driver ad7887_driver = {
362}; 362};
363module_spi_driver(ad7887_driver); 363module_spi_driver(ad7887_driver);
364 364
365MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 365MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
366MODULE_DESCRIPTION("Analog Devices AD7887 ADC"); 366MODULE_DESCRIPTION("Analog Devices AD7887 ADC");
367MODULE_LICENSE("GPL v2"); 367MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/adc/ad7923.c b/drivers/iio/adc/ad7923.c
index ffb7e089969c..d62dbb62be45 100644
--- a/drivers/iio/adc/ad7923.c
+++ b/drivers/iio/adc/ad7923.c
@@ -363,7 +363,7 @@ static struct spi_driver ad7923_driver = {
363}; 363};
364module_spi_driver(ad7923_driver); 364module_spi_driver(ad7923_driver);
365 365
366MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 366MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
367MODULE_AUTHOR("Patrick Vasseur <patrick.vasseur@c-s.fr>"); 367MODULE_AUTHOR("Patrick Vasseur <patrick.vasseur@c-s.fr>");
368MODULE_DESCRIPTION("Analog Devices AD7904/AD7914/AD7923/AD7924 ADC"); 368MODULE_DESCRIPTION("Analog Devices AD7904/AD7914/AD7923/AD7924 ADC");
369MODULE_LICENSE("GPL v2"); 369MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
index e1da67d5ee22..7a5b5d00a87d 100644
--- a/drivers/iio/adc/ad799x.c
+++ b/drivers/iio/adc/ad799x.c
@@ -892,6 +892,6 @@ static struct i2c_driver ad799x_driver = {
892}; 892};
893module_i2c_driver(ad799x_driver); 893module_i2c_driver(ad799x_driver);
894 894
895MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 895MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
896MODULE_DESCRIPTION("Analog Devices AD799x ADC"); 896MODULE_DESCRIPTION("Analog Devices AD799x ADC");
897MODULE_LICENSE("GPL v2"); 897MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
index 44b516863c9d..75d2f73582a3 100644
--- a/drivers/iio/adc/at91_adc.c
+++ b/drivers/iio/adc/at91_adc.c
@@ -248,12 +248,14 @@ static irqreturn_t at91_adc_trigger_handler(int irq, void *p)
248 struct iio_poll_func *pf = p; 248 struct iio_poll_func *pf = p;
249 struct iio_dev *idev = pf->indio_dev; 249 struct iio_dev *idev = pf->indio_dev;
250 struct at91_adc_state *st = iio_priv(idev); 250 struct at91_adc_state *st = iio_priv(idev);
251 struct iio_chan_spec const *chan;
251 int i, j = 0; 252 int i, j = 0;
252 253
253 for (i = 0; i < idev->masklength; i++) { 254 for (i = 0; i < idev->masklength; i++) {
254 if (!test_bit(i, idev->active_scan_mask)) 255 if (!test_bit(i, idev->active_scan_mask))
255 continue; 256 continue;
256 st->buffer[j] = at91_adc_readl(st, AT91_ADC_CHAN(st, i)); 257 chan = idev->channels + i;
258 st->buffer[j] = at91_adc_readl(st, AT91_ADC_CHAN(st, chan->channel));
257 j++; 259 j++;
258 } 260 }
259 261
@@ -279,6 +281,8 @@ static void handle_adc_eoc_trigger(int irq, struct iio_dev *idev)
279 iio_trigger_poll(idev->trig); 281 iio_trigger_poll(idev->trig);
280 } else { 282 } else {
281 st->last_value = at91_adc_readl(st, AT91_ADC_CHAN(st, st->chnb)); 283 st->last_value = at91_adc_readl(st, AT91_ADC_CHAN(st, st->chnb));
284 /* Needed to ACK the DRDY interruption */
285 at91_adc_readl(st, AT91_ADC_LCDR);
282 st->done = true; 286 st->done = true;
283 wake_up_interruptible(&st->wq_data_avail); 287 wake_up_interruptible(&st->wq_data_avail);
284 } 288 }
diff --git a/drivers/iio/adc/envelope-detector.c b/drivers/iio/adc/envelope-detector.c
index 4ebda8ab54fe..2f2b563c1162 100644
--- a/drivers/iio/adc/envelope-detector.c
+++ b/drivers/iio/adc/envelope-detector.c
@@ -1,13 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Driver for an envelope detector using a DAC and a comparator 3 * Driver for an envelope detector using a DAC and a comparator
3 * 4 *
4 * Copyright (C) 2016 Axentia Technologies AB 5 * Copyright (C) 2016 Axentia Technologies AB
5 * 6 *
6 * Author: Peter Rosin <peda@axentia.se> 7 * Author: Peter Rosin <peda@axentia.se>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */ 8 */
12 9
13/* 10/*
diff --git a/drivers/iio/adc/fsl-imx25-gcq.c b/drivers/iio/adc/fsl-imx25-gcq.c
index ea264fa9e567..929c617db364 100644
--- a/drivers/iio/adc/fsl-imx25-gcq.c
+++ b/drivers/iio/adc/fsl-imx25-gcq.c
@@ -209,12 +209,14 @@ static int mx25_gcq_setup_cfgs(struct platform_device *pdev,
209 ret = of_property_read_u32(child, "reg", &reg); 209 ret = of_property_read_u32(child, "reg", &reg);
210 if (ret) { 210 if (ret) {
211 dev_err(dev, "Failed to get reg property\n"); 211 dev_err(dev, "Failed to get reg property\n");
212 of_node_put(child);
212 return ret; 213 return ret;
213 } 214 }
214 215
215 if (reg >= MX25_NUM_CFGS) { 216 if (reg >= MX25_NUM_CFGS) {
216 dev_err(dev, 217 dev_err(dev,
217 "reg value is greater than the number of available configuration registers\n"); 218 "reg value is greater than the number of available configuration registers\n");
219 of_node_put(child);
218 return -EINVAL; 220 return -EINVAL;
219 } 221 }
220 222
@@ -228,6 +230,7 @@ static int mx25_gcq_setup_cfgs(struct platform_device *pdev,
228 if (IS_ERR(priv->vref[refp])) { 230 if (IS_ERR(priv->vref[refp])) {
229 dev_err(dev, "Error, trying to use external voltage reference without a vref-%s regulator.", 231 dev_err(dev, "Error, trying to use external voltage reference without a vref-%s regulator.",
230 mx25_gcq_refp_names[refp]); 232 mx25_gcq_refp_names[refp]);
233 of_node_put(child);
231 return PTR_ERR(priv->vref[refp]); 234 return PTR_ERR(priv->vref[refp]);
232 } 235 }
233 priv->channel_vref_mv[reg] = 236 priv->channel_vref_mv[reg] =
@@ -240,6 +243,7 @@ static int mx25_gcq_setup_cfgs(struct platform_device *pdev,
240 break; 243 break;
241 default: 244 default:
242 dev_err(dev, "Invalid positive reference %d\n", refp); 245 dev_err(dev, "Invalid positive reference %d\n", refp);
246 of_node_put(child);
243 return -EINVAL; 247 return -EINVAL;
244 } 248 }
245 249
@@ -254,10 +258,12 @@ static int mx25_gcq_setup_cfgs(struct platform_device *pdev,
254 258
255 if ((refp & MX25_ADCQ_CFG_REFP_MASK) != refp) { 259 if ((refp & MX25_ADCQ_CFG_REFP_MASK) != refp) {
256 dev_err(dev, "Invalid fsl,adc-refp property value\n"); 260 dev_err(dev, "Invalid fsl,adc-refp property value\n");
261 of_node_put(child);
257 return -EINVAL; 262 return -EINVAL;
258 } 263 }
259 if ((refn & MX25_ADCQ_CFG_REFN_MASK) != refn) { 264 if ((refn & MX25_ADCQ_CFG_REFN_MASK) != refn) {
260 dev_err(dev, "Invalid fsl,adc-refn property value\n"); 265 dev_err(dev, "Invalid fsl,adc-refn property value\n");
266 of_node_put(child);
261 return -EINVAL; 267 return -EINVAL;
262 } 268 }
263 269
diff --git a/drivers/iio/adc/max9611.c b/drivers/iio/adc/max9611.c
index 0538ff8c4ac1..643a4e66eb80 100644
--- a/drivers/iio/adc/max9611.c
+++ b/drivers/iio/adc/max9611.c
@@ -289,7 +289,7 @@ static int max9611_read_csa_voltage(struct max9611_dev *max9611,
289 return ret; 289 return ret;
290 290
291 if (*adc_raw > 0) { 291 if (*adc_raw > 0) {
292 *csa_gain = gain_selectors[i]; 292 *csa_gain = (enum max9611_csa_gain)gain_selectors[i];
293 return 0; 293 return 0;
294 } 294 }
295 } 295 }
diff --git a/drivers/iio/adc/mcp3911.c b/drivers/iio/adc/mcp3911.c
new file mode 100644
index 000000000000..dd52f08ec82e
--- /dev/null
+++ b/drivers/iio/adc/mcp3911.c
@@ -0,0 +1,363 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Driver for Microchip MCP3911, Two-channel Analog Front End
4 *
5 * Copyright (C) 2018 Marcus Folkesson <marcus.folkesson@gmail.com>
6 * Copyright (C) 2018 Kent Gustavsson <kent@minoris.se>
7 */
8#include <linux/clk.h>
9#include <linux/delay.h>
10#include <linux/err.h>
11#include <linux/iio/iio.h>
12#include <linux/module.h>
13#include <linux/regulator/consumer.h>
14#include <linux/spi/spi.h>
15
16#define MCP3911_REG_CHANNEL0 0x00
17#define MCP3911_REG_CHANNEL1 0x03
18#define MCP3911_REG_MOD 0x06
19#define MCP3911_REG_PHASE 0x07
20#define MCP3911_REG_GAIN 0x09
21
22#define MCP3911_REG_STATUSCOM 0x0a
23#define MCP3911_STATUSCOM_CH1_24WIDTH BIT(4)
24#define MCP3911_STATUSCOM_CH0_24WIDTH BIT(3)
25#define MCP3911_STATUSCOM_EN_OFFCAL BIT(2)
26#define MCP3911_STATUSCOM_EN_GAINCAL BIT(1)
27
28#define MCP3911_REG_CONFIG 0x0c
29#define MCP3911_CONFIG_CLKEXT BIT(1)
30#define MCP3911_CONFIG_VREFEXT BIT(2)
31
32#define MCP3911_REG_OFFCAL_CH0 0x0e
33#define MCP3911_REG_GAINCAL_CH0 0x11
34#define MCP3911_REG_OFFCAL_CH1 0x14
35#define MCP3911_REG_GAINCAL_CH1 0x17
36#define MCP3911_REG_VREFCAL 0x1a
37
38#define MCP3911_CHANNEL(x) (MCP3911_REG_CHANNEL0 + x * 3)
39#define MCP3911_OFFCAL(x) (MCP3911_REG_OFFCAL_CH0 + x * 6)
40
41/* Internal voltage reference in uV */
42#define MCP3911_INT_VREF_UV 1200000
43
44#define MCP3911_REG_READ(reg, id) ((((reg) << 1) | ((id) << 5) | (1 << 0)) & 0xff)
45#define MCP3911_REG_WRITE(reg, id) ((((reg) << 1) | ((id) << 5) | (0 << 0)) & 0xff)
46
47#define MCP3911_NUM_CHANNELS 2
48
49struct mcp3911 {
50 struct spi_device *spi;
51 struct mutex lock;
52 struct regulator *vref;
53 struct clk *clki;
54 u32 dev_addr;
55};
56
57static int mcp3911_read(struct mcp3911 *adc, u8 reg, u32 *val, u8 len)
58{
59 int ret;
60
61 reg = MCP3911_REG_READ(reg, adc->dev_addr);
62 ret = spi_write_then_read(adc->spi, &reg, 1, val, len);
63 if (ret < 0)
64 return ret;
65
66 be32_to_cpus(val);
67 *val >>= ((4 - len) * 8);
68 dev_dbg(&adc->spi->dev, "reading 0x%x from register 0x%x\n", *val,
69 reg >> 1);
70 return ret;
71}
72
73static int mcp3911_write(struct mcp3911 *adc, u8 reg, u32 val, u8 len)
74{
75 dev_dbg(&adc->spi->dev, "writing 0x%x to register 0x%x\n", val, reg);
76
77 val <<= (3 - len) * 8;
78 cpu_to_be32s(&val);
79 val |= MCP3911_REG_WRITE(reg, adc->dev_addr);
80
81 return spi_write(adc->spi, &val, len + 1);
82}
83
84static int mcp3911_update(struct mcp3911 *adc, u8 reg, u32 mask,
85 u32 val, u8 len)
86{
87 u32 tmp;
88 int ret;
89
90 ret = mcp3911_read(adc, reg, &tmp, len);
91 if (ret)
92 return ret;
93
94 val &= mask;
95 val |= tmp & ~mask;
96 return mcp3911_write(adc, reg, val, len);
97}
98
99static int mcp3911_read_raw(struct iio_dev *indio_dev,
100 struct iio_chan_spec const *channel, int *val,
101 int *val2, long mask)
102{
103 struct mcp3911 *adc = iio_priv(indio_dev);
104 int ret = -EINVAL;
105
106 mutex_lock(&adc->lock);
107 switch (mask) {
108 case IIO_CHAN_INFO_RAW:
109 ret = mcp3911_read(adc,
110 MCP3911_CHANNEL(channel->channel), val, 3);
111 if (ret)
112 goto out;
113
114 ret = IIO_VAL_INT;
115 break;
116
117 case IIO_CHAN_INFO_OFFSET:
118 ret = mcp3911_read(adc,
119 MCP3911_OFFCAL(channel->channel), val, 3);
120 if (ret)
121 goto out;
122
123 ret = IIO_VAL_INT;
124 break;
125
126 case IIO_CHAN_INFO_SCALE:
127 if (adc->vref) {
128 ret = regulator_get_voltage(adc->vref);
129 if (ret < 0) {
130 dev_err(indio_dev->dev.parent,
131 "failed to get vref voltage: %d\n",
132 ret);
133 goto out;
134 }
135
136 *val = ret / 1000;
137 } else {
138 *val = MCP3911_INT_VREF_UV;
139 }
140
141 *val2 = 24;
142 ret = IIO_VAL_FRACTIONAL_LOG2;
143 break;
144 }
145
146out:
147 mutex_unlock(&adc->lock);
148 return ret;
149}
150
151static int mcp3911_write_raw(struct iio_dev *indio_dev,
152 struct iio_chan_spec const *channel, int val,
153 int val2, long mask)
154{
155 struct mcp3911 *adc = iio_priv(indio_dev);
156 int ret = -EINVAL;
157
158 mutex_lock(&adc->lock);
159 switch (mask) {
160 case IIO_CHAN_INFO_OFFSET:
161 if (val2 != 0) {
162 ret = -EINVAL;
163 goto out;
164 }
165
166 /* Write offset */
167 ret = mcp3911_write(adc, MCP3911_OFFCAL(channel->channel), val,
168 3);
169 if (ret)
170 goto out;
171
172 /* Enable offset*/
173 ret = mcp3911_update(adc, MCP3911_REG_STATUSCOM,
174 MCP3911_STATUSCOM_EN_OFFCAL,
175 MCP3911_STATUSCOM_EN_OFFCAL, 2);
176 break;
177 }
178
179out:
180 mutex_unlock(&adc->lock);
181 return ret;
182}
183
184#define MCP3911_CHAN(idx) { \
185 .type = IIO_VOLTAGE, \
186 .indexed = 1, \
187 .channel = idx, \
188 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
189 BIT(IIO_CHAN_INFO_OFFSET) | \
190 BIT(IIO_CHAN_INFO_SCALE), \
191}
192
193static const struct iio_chan_spec mcp3911_channels[] = {
194 MCP3911_CHAN(0),
195 MCP3911_CHAN(1),
196};
197
198static const struct iio_info mcp3911_info = {
199 .read_raw = mcp3911_read_raw,
200 .write_raw = mcp3911_write_raw,
201};
202
203static int mcp3911_config(struct mcp3911 *adc, struct device_node *of_node)
204{
205 u32 configreg;
206 int ret;
207
208 of_property_read_u32(of_node, "device-addr", &adc->dev_addr);
209 if (adc->dev_addr > 3) {
210 dev_err(&adc->spi->dev,
211 "invalid device address (%i). Must be in range 0-3.\n",
212 adc->dev_addr);
213 return -EINVAL;
214 }
215 dev_dbg(&adc->spi->dev, "use device address %i\n", adc->dev_addr);
216
217 ret = mcp3911_read(adc, MCP3911_REG_CONFIG, &configreg, 2);
218 if (ret)
219 return ret;
220
221 if (adc->vref) {
222 dev_dbg(&adc->spi->dev, "use external voltage reference\n");
223 configreg |= MCP3911_CONFIG_VREFEXT;
224 } else {
225 dev_dbg(&adc->spi->dev,
226 "use internal voltage reference (1.2V)\n");
227 configreg &= ~MCP3911_CONFIG_VREFEXT;
228 }
229
230 if (adc->clki) {
231 dev_dbg(&adc->spi->dev, "use external clock as clocksource\n");
232 configreg |= MCP3911_CONFIG_CLKEXT;
233 } else {
234 dev_dbg(&adc->spi->dev,
235 "use crystal oscillator as clocksource\n");
236 configreg &= ~MCP3911_CONFIG_CLKEXT;
237 }
238
239 return mcp3911_write(adc, MCP3911_REG_CONFIG, configreg, 2);
240}
241
242static int mcp3911_probe(struct spi_device *spi)
243{
244 struct iio_dev *indio_dev;
245 struct mcp3911 *adc;
246 int ret;
247
248 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc));
249 if (!indio_dev)
250 return -ENOMEM;
251
252 adc = iio_priv(indio_dev);
253 adc->spi = spi;
254
255 adc->vref = devm_regulator_get_optional(&adc->spi->dev, "vref");
256 if (IS_ERR(adc->vref)) {
257 if (PTR_ERR(adc->vref) == -ENODEV) {
258 adc->vref = NULL;
259 } else {
260 dev_err(&adc->spi->dev,
261 "failed to get regulator (%ld)\n",
262 PTR_ERR(adc->vref));
263 return PTR_ERR(adc->vref);
264 }
265
266 } else {
267 ret = regulator_enable(adc->vref);
268 if (ret)
269 return ret;
270 }
271
272 adc->clki = devm_clk_get(&adc->spi->dev, NULL);
273 if (IS_ERR(adc->clki)) {
274 if (PTR_ERR(adc->clki) == -ENOENT) {
275 adc->clki = NULL;
276 } else {
277 dev_err(&adc->spi->dev,
278 "failed to get adc clk (%ld)\n",
279 PTR_ERR(adc->clki));
280 ret = PTR_ERR(adc->clki);
281 goto reg_disable;
282 }
283 } else {
284 ret = clk_prepare_enable(adc->clki);
285 if (ret < 0) {
286 dev_err(&adc->spi->dev,
287 "Failed to enable clki: %d\n", ret);
288 goto reg_disable;
289 }
290 }
291
292 ret = mcp3911_config(adc, spi->dev.of_node);
293 if (ret)
294 goto clk_disable;
295
296 indio_dev->dev.parent = &spi->dev;
297 indio_dev->dev.of_node = spi->dev.of_node;
298 indio_dev->name = spi_get_device_id(spi)->name;
299 indio_dev->modes = INDIO_DIRECT_MODE;
300 indio_dev->info = &mcp3911_info;
301 spi_set_drvdata(spi, indio_dev);
302
303 indio_dev->channels = mcp3911_channels;
304 indio_dev->num_channels = ARRAY_SIZE(mcp3911_channels);
305
306 mutex_init(&adc->lock);
307
308 ret = iio_device_register(indio_dev);
309 if (ret)
310 goto clk_disable;
311
312 return ret;
313
314clk_disable:
315 clk_disable_unprepare(adc->clki);
316reg_disable:
317 if (adc->vref)
318 regulator_disable(adc->vref);
319
320 return ret;
321}
322
323static int mcp3911_remove(struct spi_device *spi)
324{
325 struct iio_dev *indio_dev = spi_get_drvdata(spi);
326 struct mcp3911 *adc = iio_priv(indio_dev);
327
328 iio_device_unregister(indio_dev);
329
330 clk_disable_unprepare(adc->clki);
331 if (adc->vref)
332 regulator_disable(adc->vref);
333
334 return 0;
335}
336
337static const struct of_device_id mcp3911_dt_ids[] = {
338 { .compatible = "microchip,mcp3911" },
339 { }
340};
341MODULE_DEVICE_TABLE(of, mcp3911_dt_ids);
342
343static const struct spi_device_id mcp3911_id[] = {
344 { "mcp3911", 0 },
345 { }
346};
347MODULE_DEVICE_TABLE(spi, mcp3911_id);
348
349static struct spi_driver mcp3911_driver = {
350 .driver = {
351 .name = "mcp3911",
352 .of_match_table = mcp3911_dt_ids,
353 },
354 .probe = mcp3911_probe,
355 .remove = mcp3911_remove,
356 .id_table = mcp3911_id,
357};
358module_spi_driver(mcp3911_driver);
359
360MODULE_AUTHOR("Marcus Folkesson <marcus.folkesson@gmail.com>");
361MODULE_AUTHOR("Kent Gustavsson <kent@minoris.se>");
362MODULE_DESCRIPTION("Microchip Technology MCP3911");
363MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c
index da2d16dfa63e..028ccd218f82 100644
--- a/drivers/iio/adc/meson_saradc.c
+++ b/drivers/iio/adc/meson_saradc.c
@@ -148,7 +148,6 @@
148 #define MESON_SAR_ADC_DELTA_10_TS_REVE1 BIT(26) 148 #define MESON_SAR_ADC_DELTA_10_TS_REVE1 BIT(26)
149 #define MESON_SAR_ADC_DELTA_10_CHAN1_DELTA_VALUE_MASK GENMASK(25, 16) 149 #define MESON_SAR_ADC_DELTA_10_CHAN1_DELTA_VALUE_MASK GENMASK(25, 16)
150 #define MESON_SAR_ADC_DELTA_10_TS_REVE0 BIT(15) 150 #define MESON_SAR_ADC_DELTA_10_TS_REVE0 BIT(15)
151 #define MESON_SAR_ADC_DELTA_10_TS_C_SHIFT 11
152 #define MESON_SAR_ADC_DELTA_10_TS_C_MASK GENMASK(14, 11) 151 #define MESON_SAR_ADC_DELTA_10_TS_C_MASK GENMASK(14, 11)
153 #define MESON_SAR_ADC_DELTA_10_TS_VBG_EN BIT(10) 152 #define MESON_SAR_ADC_DELTA_10_TS_VBG_EN BIT(10)
154 #define MESON_SAR_ADC_DELTA_10_CHAN0_DELTA_VALUE_MASK GENMASK(9, 0) 153 #define MESON_SAR_ADC_DELTA_10_CHAN0_DELTA_VALUE_MASK GENMASK(9, 0)
@@ -173,6 +172,7 @@
173 .type = IIO_VOLTAGE, \ 172 .type = IIO_VOLTAGE, \
174 .indexed = 1, \ 173 .indexed = 1, \
175 .channel = _chan, \ 174 .channel = _chan, \
175 .address = _chan, \
176 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 176 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
177 BIT(IIO_CHAN_INFO_AVERAGE_RAW), \ 177 BIT(IIO_CHAN_INFO_AVERAGE_RAW), \
178 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ 178 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
@@ -235,7 +235,7 @@ struct meson_sar_adc_data {
235struct meson_sar_adc_priv { 235struct meson_sar_adc_priv {
236 struct regmap *regmap; 236 struct regmap *regmap;
237 struct regulator *vref; 237 struct regulator *vref;
238 const struct meson_sar_adc_data *data; 238 const struct meson_sar_adc_param *param;
239 struct clk *clkin; 239 struct clk *clkin;
240 struct clk *core_clk; 240 struct clk *core_clk;
241 struct clk *adc_sel_clk; 241 struct clk *adc_sel_clk;
@@ -280,7 +280,7 @@ static int meson_sar_adc_calib_val(struct iio_dev *indio_dev, int val)
280 /* use val_calib = scale * val_raw + offset calibration function */ 280 /* use val_calib = scale * val_raw + offset calibration function */
281 tmp = div_s64((s64)val * priv->calibscale, MILLION) + priv->calibbias; 281 tmp = div_s64((s64)val * priv->calibscale, MILLION) + priv->calibbias;
282 282
283 return clamp(tmp, 0, (1 << priv->data->param->resolution) - 1); 283 return clamp(tmp, 0, (1 << priv->param->resolution) - 1);
284} 284}
285 285
286static int meson_sar_adc_wait_busy_clear(struct iio_dev *indio_dev) 286static int meson_sar_adc_wait_busy_clear(struct iio_dev *indio_dev)
@@ -324,15 +324,15 @@ static int meson_sar_adc_read_raw_sample(struct iio_dev *indio_dev,
324 324
325 regmap_read(priv->regmap, MESON_SAR_ADC_FIFO_RD, &regval); 325 regmap_read(priv->regmap, MESON_SAR_ADC_FIFO_RD, &regval);
326 fifo_chan = FIELD_GET(MESON_SAR_ADC_FIFO_RD_CHAN_ID_MASK, regval); 326 fifo_chan = FIELD_GET(MESON_SAR_ADC_FIFO_RD_CHAN_ID_MASK, regval);
327 if (fifo_chan != chan->channel) { 327 if (fifo_chan != chan->address) {
328 dev_err(&indio_dev->dev, 328 dev_err(&indio_dev->dev,
329 "ADC FIFO entry belongs to channel %d instead of %d\n", 329 "ADC FIFO entry belongs to channel %d instead of %lu\n",
330 fifo_chan, chan->channel); 330 fifo_chan, chan->address);
331 return -EINVAL; 331 return -EINVAL;
332 } 332 }
333 333
334 fifo_val = FIELD_GET(MESON_SAR_ADC_FIFO_RD_SAMPLE_VALUE_MASK, regval); 334 fifo_val = FIELD_GET(MESON_SAR_ADC_FIFO_RD_SAMPLE_VALUE_MASK, regval);
335 fifo_val &= GENMASK(priv->data->param->resolution - 1, 0); 335 fifo_val &= GENMASK(priv->param->resolution - 1, 0);
336 *val = meson_sar_adc_calib_val(indio_dev, fifo_val); 336 *val = meson_sar_adc_calib_val(indio_dev, fifo_val);
337 337
338 return 0; 338 return 0;
@@ -344,16 +344,16 @@ static void meson_sar_adc_set_averaging(struct iio_dev *indio_dev,
344 enum meson_sar_adc_num_samples samples) 344 enum meson_sar_adc_num_samples samples)
345{ 345{
346 struct meson_sar_adc_priv *priv = iio_priv(indio_dev); 346 struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
347 int val, channel = chan->channel; 347 int val, address = chan->address;
348 348
349 val = samples << MESON_SAR_ADC_AVG_CNTL_NUM_SAMPLES_SHIFT(channel); 349 val = samples << MESON_SAR_ADC_AVG_CNTL_NUM_SAMPLES_SHIFT(address);
350 regmap_update_bits(priv->regmap, MESON_SAR_ADC_AVG_CNTL, 350 regmap_update_bits(priv->regmap, MESON_SAR_ADC_AVG_CNTL,
351 MESON_SAR_ADC_AVG_CNTL_NUM_SAMPLES_MASK(channel), 351 MESON_SAR_ADC_AVG_CNTL_NUM_SAMPLES_MASK(address),
352 val); 352 val);
353 353
354 val = mode << MESON_SAR_ADC_AVG_CNTL_AVG_MODE_SHIFT(channel); 354 val = mode << MESON_SAR_ADC_AVG_CNTL_AVG_MODE_SHIFT(address);
355 regmap_update_bits(priv->regmap, MESON_SAR_ADC_AVG_CNTL, 355 regmap_update_bits(priv->regmap, MESON_SAR_ADC_AVG_CNTL,
356 MESON_SAR_ADC_AVG_CNTL_AVG_MODE_MASK(channel), val); 356 MESON_SAR_ADC_AVG_CNTL_AVG_MODE_MASK(address), val);
357} 357}
358 358
359static void meson_sar_adc_enable_channel(struct iio_dev *indio_dev, 359static void meson_sar_adc_enable_channel(struct iio_dev *indio_dev,
@@ -373,23 +373,23 @@ static void meson_sar_adc_enable_channel(struct iio_dev *indio_dev,
373 373
374 /* map channel index 0 to the channel which we want to read */ 374 /* map channel index 0 to the channel which we want to read */
375 regval = FIELD_PREP(MESON_SAR_ADC_CHAN_LIST_ENTRY_MASK(0), 375 regval = FIELD_PREP(MESON_SAR_ADC_CHAN_LIST_ENTRY_MASK(0),
376 chan->channel); 376 chan->address);
377 regmap_update_bits(priv->regmap, MESON_SAR_ADC_CHAN_LIST, 377 regmap_update_bits(priv->regmap, MESON_SAR_ADC_CHAN_LIST,
378 MESON_SAR_ADC_CHAN_LIST_ENTRY_MASK(0), regval); 378 MESON_SAR_ADC_CHAN_LIST_ENTRY_MASK(0), regval);
379 379
380 regval = FIELD_PREP(MESON_SAR_ADC_DETECT_IDLE_SW_DETECT_MUX_MASK, 380 regval = FIELD_PREP(MESON_SAR_ADC_DETECT_IDLE_SW_DETECT_MUX_MASK,
381 chan->channel); 381 chan->address);
382 regmap_update_bits(priv->regmap, MESON_SAR_ADC_DETECT_IDLE_SW, 382 regmap_update_bits(priv->regmap, MESON_SAR_ADC_DETECT_IDLE_SW,
383 MESON_SAR_ADC_DETECT_IDLE_SW_DETECT_MUX_MASK, 383 MESON_SAR_ADC_DETECT_IDLE_SW_DETECT_MUX_MASK,
384 regval); 384 regval);
385 385
386 regval = FIELD_PREP(MESON_SAR_ADC_DETECT_IDLE_SW_IDLE_MUX_SEL_MASK, 386 regval = FIELD_PREP(MESON_SAR_ADC_DETECT_IDLE_SW_IDLE_MUX_SEL_MASK,
387 chan->channel); 387 chan->address);
388 regmap_update_bits(priv->regmap, MESON_SAR_ADC_DETECT_IDLE_SW, 388 regmap_update_bits(priv->regmap, MESON_SAR_ADC_DETECT_IDLE_SW,
389 MESON_SAR_ADC_DETECT_IDLE_SW_IDLE_MUX_SEL_MASK, 389 MESON_SAR_ADC_DETECT_IDLE_SW_IDLE_MUX_SEL_MASK,
390 regval); 390 regval);
391 391
392 if (chan->channel == 6) 392 if (chan->address == 6)
393 regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELTA_10, 393 regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELTA_10,
394 MESON_SAR_ADC_DELTA_10_TEMP_SEL, 0); 394 MESON_SAR_ADC_DELTA_10_TEMP_SEL, 0);
395} 395}
@@ -451,7 +451,7 @@ static int meson_sar_adc_lock(struct iio_dev *indio_dev)
451 451
452 mutex_lock(&indio_dev->mlock); 452 mutex_lock(&indio_dev->mlock);
453 453
454 if (priv->data->param->has_bl30_integration) { 454 if (priv->param->has_bl30_integration) {
455 /* prevent BL30 from using the SAR ADC while we are using it */ 455 /* prevent BL30 from using the SAR ADC while we are using it */
456 regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY, 456 regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY,
457 MESON_SAR_ADC_DELAY_KERNEL_BUSY, 457 MESON_SAR_ADC_DELAY_KERNEL_BUSY,
@@ -479,7 +479,7 @@ static void meson_sar_adc_unlock(struct iio_dev *indio_dev)
479{ 479{
480 struct meson_sar_adc_priv *priv = iio_priv(indio_dev); 480 struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
481 481
482 if (priv->data->param->has_bl30_integration) 482 if (priv->param->has_bl30_integration)
483 /* allow BL30 to use the SAR ADC again */ 483 /* allow BL30 to use the SAR ADC again */
484 regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY, 484 regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY,
485 MESON_SAR_ADC_DELAY_KERNEL_BUSY, 0); 485 MESON_SAR_ADC_DELAY_KERNEL_BUSY, 0);
@@ -527,8 +527,8 @@ static int meson_sar_adc_get_sample(struct iio_dev *indio_dev,
527 527
528 if (ret) { 528 if (ret) {
529 dev_warn(indio_dev->dev.parent, 529 dev_warn(indio_dev->dev.parent,
530 "failed to read sample for channel %d: %d\n", 530 "failed to read sample for channel %lu: %d\n",
531 chan->channel, ret); 531 chan->address, ret);
532 return ret; 532 return ret;
533 } 533 }
534 534
@@ -563,7 +563,7 @@ static int meson_sar_adc_iio_info_read_raw(struct iio_dev *indio_dev,
563 } 563 }
564 564
565 *val = ret / 1000; 565 *val = ret / 1000;
566 *val2 = priv->data->param->resolution; 566 *val2 = priv->param->resolution;
567 return IIO_VAL_FRACTIONAL_LOG2; 567 return IIO_VAL_FRACTIONAL_LOG2;
568 568
569 case IIO_CHAN_INFO_CALIBBIAS: 569 case IIO_CHAN_INFO_CALIBBIAS:
@@ -636,7 +636,7 @@ static int meson_sar_adc_init(struct iio_dev *indio_dev)
636 */ 636 */
637 meson_sar_adc_set_chan7_mux(indio_dev, CHAN7_MUX_CH7_INPUT); 637 meson_sar_adc_set_chan7_mux(indio_dev, CHAN7_MUX_CH7_INPUT);
638 638
639 if (priv->data->param->has_bl30_integration) { 639 if (priv->param->has_bl30_integration) {
640 /* 640 /*
641 * leave sampling delay and the input clocks as configured by 641 * leave sampling delay and the input clocks as configured by
642 * BL30 to make sure BL30 gets the values it expects when 642 * BL30 to make sure BL30 gets the values it expects when
@@ -716,7 +716,7 @@ static int meson_sar_adc_init(struct iio_dev *indio_dev)
716 return ret; 716 return ret;
717 } 717 }
718 718
719 ret = clk_set_rate(priv->adc_clk, priv->data->param->clock_rate); 719 ret = clk_set_rate(priv->adc_clk, priv->param->clock_rate);
720 if (ret) { 720 if (ret) {
721 dev_err(indio_dev->dev.parent, 721 dev_err(indio_dev->dev.parent,
722 "failed to set adc clock rate\n"); 722 "failed to set adc clock rate\n");
@@ -729,7 +729,7 @@ static int meson_sar_adc_init(struct iio_dev *indio_dev)
729static void meson_sar_adc_set_bandgap(struct iio_dev *indio_dev, bool on_off) 729static void meson_sar_adc_set_bandgap(struct iio_dev *indio_dev, bool on_off)
730{ 730{
731 struct meson_sar_adc_priv *priv = iio_priv(indio_dev); 731 struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
732 const struct meson_sar_adc_param *param = priv->data->param; 732 const struct meson_sar_adc_param *param = priv->param;
733 u32 enable_mask; 733 u32 enable_mask;
734 734
735 if (param->bandgap_reg == MESON_SAR_ADC_REG11) 735 if (param->bandgap_reg == MESON_SAR_ADC_REG11)
@@ -849,13 +849,13 @@ static int meson_sar_adc_calib(struct iio_dev *indio_dev)
849 int ret, nominal0, nominal1, value0, value1; 849 int ret, nominal0, nominal1, value0, value1;
850 850
851 /* use points 25% and 75% for calibration */ 851 /* use points 25% and 75% for calibration */
852 nominal0 = (1 << priv->data->param->resolution) / 4; 852 nominal0 = (1 << priv->param->resolution) / 4;
853 nominal1 = (1 << priv->data->param->resolution) * 3 / 4; 853 nominal1 = (1 << priv->param->resolution) * 3 / 4;
854 854
855 meson_sar_adc_set_chan7_mux(indio_dev, CHAN7_MUX_VDD_DIV4); 855 meson_sar_adc_set_chan7_mux(indio_dev, CHAN7_MUX_VDD_DIV4);
856 usleep_range(10, 20); 856 usleep_range(10, 20);
857 ret = meson_sar_adc_get_sample(indio_dev, 857 ret = meson_sar_adc_get_sample(indio_dev,
858 &meson_sar_adc_iio_channels[7], 858 &indio_dev->channels[7],
859 MEAN_AVERAGING, EIGHT_SAMPLES, &value0); 859 MEAN_AVERAGING, EIGHT_SAMPLES, &value0);
860 if (ret < 0) 860 if (ret < 0)
861 goto out; 861 goto out;
@@ -863,7 +863,7 @@ static int meson_sar_adc_calib(struct iio_dev *indio_dev)
863 meson_sar_adc_set_chan7_mux(indio_dev, CHAN7_MUX_VDD_MUL3_DIV4); 863 meson_sar_adc_set_chan7_mux(indio_dev, CHAN7_MUX_VDD_MUL3_DIV4);
864 usleep_range(10, 20); 864 usleep_range(10, 20);
865 ret = meson_sar_adc_get_sample(indio_dev, 865 ret = meson_sar_adc_get_sample(indio_dev,
866 &meson_sar_adc_iio_channels[7], 866 &indio_dev->channels[7],
867 MEAN_AVERAGING, EIGHT_SAMPLES, &value1); 867 MEAN_AVERAGING, EIGHT_SAMPLES, &value1);
868 if (ret < 0) 868 if (ret < 0)
869 goto out; 869 goto out;
@@ -979,11 +979,11 @@ MODULE_DEVICE_TABLE(of, meson_sar_adc_of_match);
979 979
980static int meson_sar_adc_probe(struct platform_device *pdev) 980static int meson_sar_adc_probe(struct platform_device *pdev)
981{ 981{
982 const struct meson_sar_adc_data *match_data;
982 struct meson_sar_adc_priv *priv; 983 struct meson_sar_adc_priv *priv;
983 struct iio_dev *indio_dev; 984 struct iio_dev *indio_dev;
984 struct resource *res; 985 struct resource *res;
985 void __iomem *base; 986 void __iomem *base;
986 const struct of_device_id *match;
987 int irq, ret; 987 int irq, ret;
988 988
989 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*priv)); 989 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*priv));
@@ -995,15 +995,15 @@ static int meson_sar_adc_probe(struct platform_device *pdev)
995 priv = iio_priv(indio_dev); 995 priv = iio_priv(indio_dev);
996 init_completion(&priv->done); 996 init_completion(&priv->done);
997 997
998 match = of_match_device(meson_sar_adc_of_match, &pdev->dev); 998 match_data = of_device_get_match_data(&pdev->dev);
999 if (!match) { 999 if (!match_data) {
1000 dev_err(&pdev->dev, "failed to match device\n"); 1000 dev_err(&pdev->dev, "failed to get match data\n");
1001 return -ENODEV; 1001 return -ENODEV;
1002 } 1002 }
1003 1003
1004 priv->data = match->data; 1004 priv->param = match_data->param;
1005 1005
1006 indio_dev->name = priv->data->name; 1006 indio_dev->name = match_data->name;
1007 indio_dev->dev.parent = &pdev->dev; 1007 indio_dev->dev.parent = &pdev->dev;
1008 indio_dev->dev.of_node = pdev->dev.of_node; 1008 indio_dev->dev.of_node = pdev->dev.of_node;
1009 indio_dev->modes = INDIO_DIRECT_MODE; 1009 indio_dev->modes = INDIO_DIRECT_MODE;
@@ -1027,7 +1027,7 @@ static int meson_sar_adc_probe(struct platform_device *pdev)
1027 return ret; 1027 return ret;
1028 1028
1029 priv->regmap = devm_regmap_init_mmio(&pdev->dev, base, 1029 priv->regmap = devm_regmap_init_mmio(&pdev->dev, base,
1030 priv->data->param->regmap_config); 1030 priv->param->regmap_config);
1031 if (IS_ERR(priv->regmap)) 1031 if (IS_ERR(priv->regmap))
1032 return PTR_ERR(priv->regmap); 1032 return PTR_ERR(priv->regmap);
1033 1033
diff --git a/drivers/iio/adc/qcom-pm8xxx-xoadc.c b/drivers/iio/adc/qcom-pm8xxx-xoadc.c
index b093ecddf1a8..c30c002f1fef 100644
--- a/drivers/iio/adc/qcom-pm8xxx-xoadc.c
+++ b/drivers/iio/adc/qcom-pm8xxx-xoadc.c
@@ -708,8 +708,8 @@ static int pm8xxx_of_xlate(struct iio_dev *indio_dev,
708 * mux. 708 * mux.
709 */ 709 */
710 if (iiospec->args_count != 2) { 710 if (iiospec->args_count != 2) {
711 dev_err(&indio_dev->dev, "wrong number of arguments for %s need 2 got %d\n", 711 dev_err(&indio_dev->dev, "wrong number of arguments for %pOFn need 2 got %d\n",
712 iiospec->np->name, 712 iiospec->np,
713 iiospec->args_count); 713 iiospec->args_count);
714 return -EINVAL; 714 return -EINVAL;
715 } 715 }
diff --git a/drivers/iio/adc/qcom-spmi-adc5.c b/drivers/iio/adc/qcom-spmi-adc5.c
new file mode 100644
index 000000000000..f9af6b082916
--- /dev/null
+++ b/drivers/iio/adc/qcom-spmi-adc5.c
@@ -0,0 +1,793 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (c) 2018, The Linux Foundation. All rights reserved.
4 */
5
6#include <linux/bitops.h>
7#include <linux/completion.h>
8#include <linux/delay.h>
9#include <linux/err.h>
10#include <linux/iio/iio.h>
11#include <linux/interrupt.h>
12#include <linux/kernel.h>
13#include <linux/log2.h>
14#include <linux/math64.h>
15#include <linux/module.h>
16#include <linux/of.h>
17#include <linux/platform_device.h>
18#include <linux/regmap.h>
19#include <linux/slab.h>
20
21#include <dt-bindings/iio/qcom,spmi-vadc.h>
22#include "qcom-vadc-common.h"
23
24#define ADC5_USR_REVISION1 0x0
25#define ADC5_USR_STATUS1 0x8
26#define ADC5_USR_STATUS1_REQ_STS BIT(1)
27#define ADC5_USR_STATUS1_EOC BIT(0)
28#define ADC5_USR_STATUS1_REQ_STS_EOC_MASK 0x3
29
30#define ADC5_USR_STATUS2 0x9
31#define ADC5_USR_STATUS2_CONV_SEQ_MASK 0x70
32#define ADC5_USR_STATUS2_CONV_SEQ_MASK_SHIFT 0x5
33
34#define ADC5_USR_IBAT_MEAS 0xf
35#define ADC5_USR_IBAT_MEAS_SUPPORTED BIT(0)
36
37#define ADC5_USR_DIG_PARAM 0x42
38#define ADC5_USR_DIG_PARAM_CAL_VAL BIT(6)
39#define ADC5_USR_DIG_PARAM_CAL_VAL_SHIFT 6
40#define ADC5_USR_DIG_PARAM_CAL_SEL 0x30
41#define ADC5_USR_DIG_PARAM_CAL_SEL_SHIFT 4
42#define ADC5_USR_DIG_PARAM_DEC_RATIO_SEL 0xc
43#define ADC5_USR_DIG_PARAM_DEC_RATIO_SEL_SHIFT 2
44
45#define ADC5_USR_FAST_AVG_CTL 0x43
46#define ADC5_USR_FAST_AVG_CTL_EN BIT(7)
47#define ADC5_USR_FAST_AVG_CTL_SAMPLES_MASK 0x7
48
49#define ADC5_USR_CH_SEL_CTL 0x44
50
51#define ADC5_USR_DELAY_CTL 0x45
52#define ADC5_USR_HW_SETTLE_DELAY_MASK 0xf
53
54#define ADC5_USR_EN_CTL1 0x46
55#define ADC5_USR_EN_CTL1_ADC_EN BIT(7)
56
57#define ADC5_USR_CONV_REQ 0x47
58#define ADC5_USR_CONV_REQ_REQ BIT(7)
59
60#define ADC5_USR_DATA0 0x50
61
62#define ADC5_USR_DATA1 0x51
63
64#define ADC5_USR_IBAT_DATA0 0x52
65
66#define ADC5_USR_IBAT_DATA1 0x53
67
68/*
69 * Conversion time varies based on the decimation, clock rate, fast average
70 * samples and measurements queued across different VADC peripherals.
71 * Set the timeout to a max of 100ms.
72 */
73#define ADC5_CONV_TIME_MIN_US 263
74#define ADC5_CONV_TIME_MAX_US 264
75#define ADC5_CONV_TIME_RETRY 400
76#define ADC5_CONV_TIMEOUT msecs_to_jiffies(100)
77
78/* Digital version >= 5.3 supports hw_settle_2 */
79#define ADC5_HW_SETTLE_DIFF_MINOR 3
80#define ADC5_HW_SETTLE_DIFF_MAJOR 5
81
82enum adc5_cal_method {
83 ADC5_NO_CAL = 0,
84 ADC5_RATIOMETRIC_CAL,
85 ADC5_ABSOLUTE_CAL
86};
87
88enum adc5_cal_val {
89 ADC5_TIMER_CAL = 0,
90 ADC5_NEW_CAL
91};
92
93/**
94 * struct adc5_channel_prop - ADC channel property.
95 * @channel: channel number, refer to the channel list.
96 * @cal_method: calibration method.
97 * @cal_val: calibration value
98 * @decimation: sampling rate supported for the channel.
99 * @prescale: channel scaling performed on the input signal.
100 * @hw_settle_time: the time between AMUX being configured and the
101 * start of conversion.
102 * @avg_samples: ability to provide single result from the ADC
103 * that is an average of multiple measurements.
104 * @scale_fn_type: Represents the scaling function to convert voltage
105 * physical units desired by the client for the channel.
106 * @datasheet_name: Channel name used in device tree.
107 */
108struct adc5_channel_prop {
109 unsigned int channel;
110 enum adc5_cal_method cal_method;
111 enum adc5_cal_val cal_val;
112 unsigned int decimation;
113 unsigned int prescale;
114 unsigned int hw_settle_time;
115 unsigned int avg_samples;
116 enum vadc_scale_fn_type scale_fn_type;
117 const char *datasheet_name;
118};
119
120/**
121 * struct adc5_chip - ADC private structure.
122 * @regmap: SPMI ADC5 peripheral register map field.
123 * @dev: SPMI ADC5 device.
124 * @base: base address for the ADC peripheral.
125 * @nchannels: number of ADC channels.
126 * @chan_props: array of ADC channel properties.
127 * @iio_chans: array of IIO channels specification.
128 * @poll_eoc: use polling instead of interrupt.
129 * @complete: ADC result notification after interrupt is received.
130 * @lock: ADC lock for access to the peripheral.
131 * @data: software configuration data.
132 */
133struct adc5_chip {
134 struct regmap *regmap;
135 struct device *dev;
136 u16 base;
137 unsigned int nchannels;
138 struct adc5_channel_prop *chan_props;
139 struct iio_chan_spec *iio_chans;
140 bool poll_eoc;
141 struct completion complete;
142 struct mutex lock;
143 const struct adc5_data *data;
144};
145
146static const struct vadc_prescale_ratio adc5_prescale_ratios[] = {
147 {.num = 1, .den = 1},
148 {.num = 1, .den = 3},
149 {.num = 1, .den = 4},
150 {.num = 1, .den = 6},
151 {.num = 1, .den = 20},
152 {.num = 1, .den = 8},
153 {.num = 10, .den = 81},
154 {.num = 1, .den = 10},
155 {.num = 1, .den = 16}
156};
157
158static int adc5_read(struct adc5_chip *adc, u16 offset, u8 *data, int len)
159{
160 return regmap_bulk_read(adc->regmap, adc->base + offset, data, len);
161}
162
163static int adc5_write(struct adc5_chip *adc, u16 offset, u8 *data, int len)
164{
165 return regmap_bulk_write(adc->regmap, adc->base + offset, data, len);
166}
167
168static int adc5_prescaling_from_dt(u32 num, u32 den)
169{
170 unsigned int pre;
171
172 for (pre = 0; pre < ARRAY_SIZE(adc5_prescale_ratios); pre++)
173 if (adc5_prescale_ratios[pre].num == num &&
174 adc5_prescale_ratios[pre].den == den)
175 break;
176
177 if (pre == ARRAY_SIZE(adc5_prescale_ratios))
178 return -EINVAL;
179
180 return pre;
181}
182
183static int adc5_hw_settle_time_from_dt(u32 value,
184 const unsigned int *hw_settle)
185{
186 unsigned int i;
187
188 for (i = 0; i < VADC_HW_SETTLE_SAMPLES_MAX; i++) {
189 if (value == hw_settle[i])
190 return i;
191 }
192
193 return -EINVAL;
194}
195
196static int adc5_avg_samples_from_dt(u32 value)
197{
198 if (!is_power_of_2(value) || value > ADC5_AVG_SAMPLES_MAX)
199 return -EINVAL;
200
201 return __ffs(value);
202}
203
204static int adc5_decimation_from_dt(u32 value,
205 const unsigned int *decimation)
206{
207 unsigned int i;
208
209 for (i = 0; i < ADC5_DECIMATION_SAMPLES_MAX; i++) {
210 if (value == decimation[i])
211 return i;
212 }
213
214 return -EINVAL;
215}
216
217static int adc5_read_voltage_data(struct adc5_chip *adc, u16 *data)
218{
219 int ret;
220 u8 rslt_lsb, rslt_msb;
221
222 ret = adc5_read(adc, ADC5_USR_DATA0, &rslt_lsb, sizeof(rslt_lsb));
223 if (ret)
224 return ret;
225
226 ret = adc5_read(adc, ADC5_USR_DATA1, &rslt_msb, sizeof(rslt_lsb));
227 if (ret)
228 return ret;
229
230 *data = (rslt_msb << 8) | rslt_lsb;
231
232 if (*data == ADC5_USR_DATA_CHECK) {
233 pr_err("Invalid data:0x%x\n", *data);
234 return -EINVAL;
235 }
236
237 pr_debug("voltage raw code:0x%x\n", *data);
238
239 return 0;
240}
241
242static int adc5_poll_wait_eoc(struct adc5_chip *adc)
243{
244 unsigned int count, retry = ADC5_CONV_TIME_RETRY;
245 u8 status1;
246 int ret;
247
248 for (count = 0; count < retry; count++) {
249 ret = adc5_read(adc, ADC5_USR_STATUS1, &status1,
250 sizeof(status1));
251 if (ret)
252 return ret;
253
254 status1 &= ADC5_USR_STATUS1_REQ_STS_EOC_MASK;
255 if (status1 == ADC5_USR_STATUS1_EOC)
256 return 0;
257
258 usleep_range(ADC5_CONV_TIME_MIN_US, ADC5_CONV_TIME_MAX_US);
259 }
260
261 return -ETIMEDOUT;
262}
263
264static void adc5_update_dig_param(struct adc5_chip *adc,
265 struct adc5_channel_prop *prop, u8 *data)
266{
267 /* Update calibration value */
268 *data &= ~ADC5_USR_DIG_PARAM_CAL_VAL;
269 *data |= (prop->cal_val << ADC5_USR_DIG_PARAM_CAL_VAL_SHIFT);
270
271 /* Update calibration select */
272 *data &= ~ADC5_USR_DIG_PARAM_CAL_SEL;
273 *data |= (prop->cal_method << ADC5_USR_DIG_PARAM_CAL_SEL_SHIFT);
274
275 /* Update decimation ratio select */
276 *data &= ~ADC5_USR_DIG_PARAM_DEC_RATIO_SEL;
277 *data |= (prop->decimation << ADC5_USR_DIG_PARAM_DEC_RATIO_SEL_SHIFT);
278}
279
280static int adc5_configure(struct adc5_chip *adc,
281 struct adc5_channel_prop *prop)
282{
283 int ret;
284 u8 buf[6];
285
286 /* Read registers 0x42 through 0x46 */
287 ret = adc5_read(adc, ADC5_USR_DIG_PARAM, buf, sizeof(buf));
288 if (ret < 0)
289 return ret;
290
291 /* Digital param selection */
292 adc5_update_dig_param(adc, prop, &buf[0]);
293
294 /* Update fast average sample value */
295 buf[1] &= (u8) ~ADC5_USR_FAST_AVG_CTL_SAMPLES_MASK;
296 buf[1] |= prop->avg_samples;
297
298 /* Select ADC channel */
299 buf[2] = prop->channel;
300
301 /* Select HW settle delay for channel */
302 buf[3] &= (u8) ~ADC5_USR_HW_SETTLE_DELAY_MASK;
303 buf[3] |= prop->hw_settle_time;
304
305 /* Select ADC enable */
306 buf[4] |= ADC5_USR_EN_CTL1_ADC_EN;
307
308 /* Select CONV request */
309 buf[5] |= ADC5_USR_CONV_REQ_REQ;
310
311 if (!adc->poll_eoc)
312 reinit_completion(&adc->complete);
313
314 return adc5_write(adc, ADC5_USR_DIG_PARAM, buf, sizeof(buf));
315}
316
317static int adc5_do_conversion(struct adc5_chip *adc,
318 struct adc5_channel_prop *prop,
319 struct iio_chan_spec const *chan,
320 u16 *data_volt, u16 *data_cur)
321{
322 int ret;
323
324 mutex_lock(&adc->lock);
325
326 ret = adc5_configure(adc, prop);
327 if (ret) {
328 pr_err("ADC configure failed with %d\n", ret);
329 goto unlock;
330 }
331
332 if (adc->poll_eoc) {
333 ret = adc5_poll_wait_eoc(adc);
334 if (ret < 0) {
335 pr_err("EOC bit not set\n");
336 goto unlock;
337 }
338 } else {
339 ret = wait_for_completion_timeout(&adc->complete,
340 ADC5_CONV_TIMEOUT);
341 if (!ret) {
342 pr_debug("Did not get completion timeout.\n");
343 ret = adc5_poll_wait_eoc(adc);
344 if (ret < 0) {
345 pr_err("EOC bit not set\n");
346 goto unlock;
347 }
348 }
349 }
350
351 ret = adc5_read_voltage_data(adc, data_volt);
352unlock:
353 mutex_unlock(&adc->lock);
354
355 return ret;
356}
357
358static irqreturn_t adc5_isr(int irq, void *dev_id)
359{
360 struct adc5_chip *adc = dev_id;
361
362 complete(&adc->complete);
363
364 return IRQ_HANDLED;
365}
366
367static int adc5_of_xlate(struct iio_dev *indio_dev,
368 const struct of_phandle_args *iiospec)
369{
370 struct adc5_chip *adc = iio_priv(indio_dev);
371 int i;
372
373 for (i = 0; i < adc->nchannels; i++)
374 if (adc->chan_props[i].channel == iiospec->args[0])
375 return i;
376
377 return -EINVAL;
378}
379
380static int adc5_read_raw(struct iio_dev *indio_dev,
381 struct iio_chan_spec const *chan, int *val, int *val2,
382 long mask)
383{
384 struct adc5_chip *adc = iio_priv(indio_dev);
385 struct adc5_channel_prop *prop;
386 u16 adc_code_volt, adc_code_cur;
387 int ret;
388
389 prop = &adc->chan_props[chan->address];
390
391 switch (mask) {
392 case IIO_CHAN_INFO_PROCESSED:
393 ret = adc5_do_conversion(adc, prop, chan,
394 &adc_code_volt, &adc_code_cur);
395 if (ret)
396 return ret;
397
398 ret = qcom_adc5_hw_scale(prop->scale_fn_type,
399 &adc5_prescale_ratios[prop->prescale],
400 adc->data,
401 adc_code_volt, val);
402 if (ret)
403 return ret;
404
405 return IIO_VAL_INT;
406 default:
407 return -EINVAL;
408 }
409
410 return 0;
411}
412
413static const struct iio_info adc5_info = {
414 .read_raw = adc5_read_raw,
415 .of_xlate = adc5_of_xlate,
416};
417
418struct adc5_channels {
419 const char *datasheet_name;
420 unsigned int prescale_index;
421 enum iio_chan_type type;
422 long info_mask;
423 enum vadc_scale_fn_type scale_fn_type;
424};
425
426#define ADC5_CHAN(_dname, _type, _mask, _pre, _scale) \
427 { \
428 .datasheet_name = _dname, \
429 .prescale_index = _pre, \
430 .type = _type, \
431 .info_mask = _mask, \
432 .scale_fn_type = _scale, \
433 }, \
434
435#define ADC5_CHAN_TEMP(_dname, _pre, _scale) \
436 ADC5_CHAN(_dname, IIO_TEMP, \
437 BIT(IIO_CHAN_INFO_PROCESSED), \
438 _pre, _scale) \
439
440#define ADC5_CHAN_VOLT(_dname, _pre, _scale) \
441 ADC5_CHAN(_dname, IIO_VOLTAGE, \
442 BIT(IIO_CHAN_INFO_PROCESSED), \
443 _pre, _scale) \
444
445static const struct adc5_channels adc5_chans_pmic[ADC5_MAX_CHANNEL] = {
446 [ADC5_REF_GND] = ADC5_CHAN_VOLT("ref_gnd", 1,
447 SCALE_HW_CALIB_DEFAULT)
448 [ADC5_1P25VREF] = ADC5_CHAN_VOLT("vref_1p25", 1,
449 SCALE_HW_CALIB_DEFAULT)
450 [ADC5_VPH_PWR] = ADC5_CHAN_VOLT("vph_pwr", 3,
451 SCALE_HW_CALIB_DEFAULT)
452 [ADC5_VBAT_SNS] = ADC5_CHAN_VOLT("vbat_sns", 3,
453 SCALE_HW_CALIB_DEFAULT)
454 [ADC5_DIE_TEMP] = ADC5_CHAN_TEMP("die_temp", 1,
455 SCALE_HW_CALIB_PMIC_THERM)
456 [ADC5_USB_IN_I] = ADC5_CHAN_VOLT("usb_in_i_uv", 1,
457 SCALE_HW_CALIB_DEFAULT)
458 [ADC5_USB_IN_V_16] = ADC5_CHAN_VOLT("usb_in_v_div_16", 16,
459 SCALE_HW_CALIB_DEFAULT)
460 [ADC5_CHG_TEMP] = ADC5_CHAN_TEMP("chg_temp", 1,
461 SCALE_HW_CALIB_PM5_CHG_TEMP)
462 /* Charger prescales SBUx and MID_CHG to fit within 1.8V upper unit */
463 [ADC5_SBUx] = ADC5_CHAN_VOLT("chg_sbux", 3,
464 SCALE_HW_CALIB_DEFAULT)
465 [ADC5_MID_CHG_DIV6] = ADC5_CHAN_VOLT("chg_mid_chg", 6,
466 SCALE_HW_CALIB_DEFAULT)
467 [ADC5_XO_THERM_100K_PU] = ADC5_CHAN_TEMP("xo_therm", 1,
468 SCALE_HW_CALIB_XOTHERM)
469 [ADC5_AMUX_THM1_100K_PU] = ADC5_CHAN_TEMP("amux_thm1_100k_pu", 1,
470 SCALE_HW_CALIB_THERM_100K_PULLUP)
471 [ADC5_AMUX_THM2_100K_PU] = ADC5_CHAN_TEMP("amux_thm2_100k_pu", 1,
472 SCALE_HW_CALIB_THERM_100K_PULLUP)
473 [ADC5_AMUX_THM3_100K_PU] = ADC5_CHAN_TEMP("amux_thm3_100k_pu", 1,
474 SCALE_HW_CALIB_THERM_100K_PULLUP)
475 [ADC5_AMUX_THM2] = ADC5_CHAN_TEMP("amux_thm2", 1,
476 SCALE_HW_CALIB_PM5_SMB_TEMP)
477};
478
479static const struct adc5_channels adc5_chans_rev2[ADC5_MAX_CHANNEL] = {
480 [ADC5_REF_GND] = ADC5_CHAN_VOLT("ref_gnd", 1,
481 SCALE_HW_CALIB_DEFAULT)
482 [ADC5_1P25VREF] = ADC5_CHAN_VOLT("vref_1p25", 1,
483 SCALE_HW_CALIB_DEFAULT)
484 [ADC5_VPH_PWR] = ADC5_CHAN_VOLT("vph_pwr", 3,
485 SCALE_HW_CALIB_DEFAULT)
486 [ADC5_VBAT_SNS] = ADC5_CHAN_VOLT("vbat_sns", 3,
487 SCALE_HW_CALIB_DEFAULT)
488 [ADC5_VCOIN] = ADC5_CHAN_VOLT("vcoin", 3,
489 SCALE_HW_CALIB_DEFAULT)
490 [ADC5_DIE_TEMP] = ADC5_CHAN_TEMP("die_temp", 1,
491 SCALE_HW_CALIB_PMIC_THERM)
492 [ADC5_AMUX_THM1_100K_PU] = ADC5_CHAN_TEMP("amux_thm1_100k_pu", 1,
493 SCALE_HW_CALIB_THERM_100K_PULLUP)
494 [ADC5_AMUX_THM2_100K_PU] = ADC5_CHAN_TEMP("amux_thm2_100k_pu", 1,
495 SCALE_HW_CALIB_THERM_100K_PULLUP)
496 [ADC5_AMUX_THM3_100K_PU] = ADC5_CHAN_TEMP("amux_thm3_100k_pu", 1,
497 SCALE_HW_CALIB_THERM_100K_PULLUP)
498 [ADC5_AMUX_THM4_100K_PU] = ADC5_CHAN_TEMP("amux_thm4_100k_pu", 1,
499 SCALE_HW_CALIB_THERM_100K_PULLUP)
500 [ADC5_AMUX_THM5_100K_PU] = ADC5_CHAN_TEMP("amux_thm5_100k_pu", 1,
501 SCALE_HW_CALIB_THERM_100K_PULLUP)
502 [ADC5_XO_THERM_100K_PU] = ADC5_CHAN_TEMP("xo_therm_100k_pu", 1,
503 SCALE_HW_CALIB_THERM_100K_PULLUP)
504};
505
506static int adc5_get_dt_channel_data(struct adc5_chip *adc,
507 struct adc5_channel_prop *prop,
508 struct device_node *node,
509 const struct adc5_data *data)
510{
511 const char *name = node->name, *channel_name;
512 u32 chan, value, varr[2];
513 int ret;
514 struct device *dev = adc->dev;
515
516 ret = of_property_read_u32(node, "reg", &chan);
517 if (ret) {
518 dev_err(dev, "invalid channel number %s\n", name);
519 return ret;
520 }
521
522 if (chan > ADC5_PARALLEL_ISENSE_VBAT_IDATA ||
523 !data->adc_chans[chan].datasheet_name) {
524 dev_err(dev, "%s invalid channel number %d\n", name, chan);
525 return -EINVAL;
526 }
527
528 /* the channel has DT description */
529 prop->channel = chan;
530
531 channel_name = of_get_property(node,
532 "label", NULL) ? : node->name;
533 if (!channel_name) {
534 pr_err("Invalid channel name\n");
535 return -EINVAL;
536 }
537 prop->datasheet_name = channel_name;
538
539 ret = of_property_read_u32(node, "qcom,decimation", &value);
540 if (!ret) {
541 ret = adc5_decimation_from_dt(value, data->decimation);
542 if (ret < 0) {
543 dev_err(dev, "%02x invalid decimation %d\n",
544 chan, value);
545 return ret;
546 }
547 prop->decimation = ret;
548 } else {
549 prop->decimation = ADC5_DECIMATION_DEFAULT;
550 }
551
552 ret = of_property_read_u32_array(node, "qcom,pre-scaling", varr, 2);
553 if (!ret) {
554 ret = adc5_prescaling_from_dt(varr[0], varr[1]);
555 if (ret < 0) {
556 dev_err(dev, "%02x invalid pre-scaling <%d %d>\n",
557 chan, varr[0], varr[1]);
558 return ret;
559 }
560 prop->prescale = ret;
561 }
562
563 ret = of_property_read_u32(node, "qcom,hw-settle-time", &value);
564 if (!ret) {
565 u8 dig_version[2];
566
567 ret = adc5_read(adc, ADC5_USR_REVISION1, dig_version,
568 sizeof(dig_version));
569 if (ret < 0) {
570 dev_err(dev, "Invalid dig version read %d\n", ret);
571 return ret;
572 }
573
574 pr_debug("dig_ver:minor:%d, major:%d\n", dig_version[0],
575 dig_version[1]);
576 /* Digital controller >= 5.3 have hw_settle_2 option */
577 if (dig_version[0] >= ADC5_HW_SETTLE_DIFF_MINOR &&
578 dig_version[1] >= ADC5_HW_SETTLE_DIFF_MAJOR)
579 ret = adc5_hw_settle_time_from_dt(value,
580 data->hw_settle_2);
581 else
582 ret = adc5_hw_settle_time_from_dt(value,
583 data->hw_settle_1);
584
585 if (ret < 0) {
586 dev_err(dev, "%02x invalid hw-settle-time %d us\n",
587 chan, value);
588 return ret;
589 }
590 prop->hw_settle_time = ret;
591 } else {
592 prop->hw_settle_time = VADC_DEF_HW_SETTLE_TIME;
593 }
594
595 ret = of_property_read_u32(node, "qcom,avg-samples", &value);
596 if (!ret) {
597 ret = adc5_avg_samples_from_dt(value);
598 if (ret < 0) {
599 dev_err(dev, "%02x invalid avg-samples %d\n",
600 chan, value);
601 return ret;
602 }
603 prop->avg_samples = ret;
604 } else {
605 prop->avg_samples = VADC_DEF_AVG_SAMPLES;
606 }
607
608 if (of_property_read_bool(node, "qcom,ratiometric"))
609 prop->cal_method = ADC5_RATIOMETRIC_CAL;
610 else
611 prop->cal_method = ADC5_ABSOLUTE_CAL;
612
613 /*
614 * Default to using timer calibration. Using a fresh calibration value
615 * for every conversion will increase the overall time for a request.
616 */
617 prop->cal_val = ADC5_TIMER_CAL;
618
619 dev_dbg(dev, "%02x name %s\n", chan, name);
620
621 return 0;
622}
623
624static const struct adc5_data adc5_data_pmic = {
625 .full_scale_code_volt = 0x70e4,
626 .full_scale_code_cur = 0x2710,
627 .adc_chans = adc5_chans_pmic,
628 .decimation = (unsigned int [ADC5_DECIMATION_SAMPLES_MAX])
629 {250, 420, 840},
630 .hw_settle_1 = (unsigned int [VADC_HW_SETTLE_SAMPLES_MAX])
631 {15, 100, 200, 300, 400, 500, 600, 700,
632 800, 900, 1, 2, 4, 6, 8, 10},
633 .hw_settle_2 = (unsigned int [VADC_HW_SETTLE_SAMPLES_MAX])
634 {15, 100, 200, 300, 400, 500, 600, 700,
635 1, 2, 4, 8, 16, 32, 64, 128},
636};
637
638static const struct adc5_data adc5_data_pmic_rev2 = {
639 .full_scale_code_volt = 0x4000,
640 .full_scale_code_cur = 0x1800,
641 .adc_chans = adc5_chans_rev2,
642 .decimation = (unsigned int [ADC5_DECIMATION_SAMPLES_MAX])
643 {256, 512, 1024},
644 .hw_settle_1 = (unsigned int [VADC_HW_SETTLE_SAMPLES_MAX])
645 {0, 100, 200, 300, 400, 500, 600, 700,
646 800, 900, 1, 2, 4, 6, 8, 10},
647 .hw_settle_2 = (unsigned int [VADC_HW_SETTLE_SAMPLES_MAX])
648 {15, 100, 200, 300, 400, 500, 600, 700,
649 1, 2, 4, 8, 16, 32, 64, 128},
650};
651
652static const struct of_device_id adc5_match_table[] = {
653 {
654 .compatible = "qcom,spmi-adc5",
655 .data = &adc5_data_pmic,
656 },
657 {
658 .compatible = "qcom,spmi-adc-rev2",
659 .data = &adc5_data_pmic_rev2,
660 },
661 { }
662};
663
664static int adc5_get_dt_data(struct adc5_chip *adc, struct device_node *node)
665{
666 const struct adc5_channels *adc_chan;
667 struct iio_chan_spec *iio_chan;
668 struct adc5_channel_prop prop, *chan_props;
669 struct device_node *child;
670 unsigned int index = 0;
671 const struct of_device_id *id;
672 const struct adc5_data *data;
673 int ret;
674
675 adc->nchannels = of_get_available_child_count(node);
676 if (!adc->nchannels)
677 return -EINVAL;
678
679 adc->iio_chans = devm_kcalloc(adc->dev, adc->nchannels,
680 sizeof(*adc->iio_chans), GFP_KERNEL);
681 if (!adc->iio_chans)
682 return -ENOMEM;
683
684 adc->chan_props = devm_kcalloc(adc->dev, adc->nchannels,
685 sizeof(*adc->chan_props), GFP_KERNEL);
686 if (!adc->chan_props)
687 return -ENOMEM;
688
689 chan_props = adc->chan_props;
690 iio_chan = adc->iio_chans;
691 id = of_match_node(adc5_match_table, node);
692 if (id)
693 data = id->data;
694 else
695 data = &adc5_data_pmic;
696 adc->data = data;
697
698 for_each_available_child_of_node(node, child) {
699 ret = adc5_get_dt_channel_data(adc, &prop, child, data);
700 if (ret) {
701 of_node_put(child);
702 return ret;
703 }
704
705 prop.scale_fn_type =
706 data->adc_chans[prop.channel].scale_fn_type;
707 *chan_props = prop;
708 adc_chan = &data->adc_chans[prop.channel];
709
710 iio_chan->channel = prop.channel;
711 iio_chan->datasheet_name = prop.datasheet_name;
712 iio_chan->extend_name = prop.datasheet_name;
713 iio_chan->info_mask_separate = adc_chan->info_mask;
714 iio_chan->type = adc_chan->type;
715 iio_chan->address = index;
716 iio_chan++;
717 chan_props++;
718 index++;
719 }
720
721 return 0;
722}
723
724static int adc5_probe(struct platform_device *pdev)
725{
726 struct device_node *node = pdev->dev.of_node;
727 struct device *dev = &pdev->dev;
728 struct iio_dev *indio_dev;
729 struct adc5_chip *adc;
730 struct regmap *regmap;
731 int ret, irq_eoc;
732 u32 reg;
733
734 regmap = dev_get_regmap(dev->parent, NULL);
735 if (!regmap)
736 return -ENODEV;
737
738 ret = of_property_read_u32(node, "reg", &reg);
739 if (ret < 0)
740 return ret;
741
742 indio_dev = devm_iio_device_alloc(dev, sizeof(*adc));
743 if (!indio_dev)
744 return -ENOMEM;
745
746 adc = iio_priv(indio_dev);
747 adc->regmap = regmap;
748 adc->dev = dev;
749 adc->base = reg;
750 init_completion(&adc->complete);
751 mutex_init(&adc->lock);
752
753 ret = adc5_get_dt_data(adc, node);
754 if (ret) {
755 pr_err("adc get dt data failed\n");
756 return ret;
757 }
758
759 irq_eoc = platform_get_irq(pdev, 0);
760 if (irq_eoc < 0) {
761 if (irq_eoc == -EPROBE_DEFER || irq_eoc == -EINVAL)
762 return irq_eoc;
763 adc->poll_eoc = true;
764 } else {
765 ret = devm_request_irq(dev, irq_eoc, adc5_isr, 0,
766 "pm-adc5", adc);
767 if (ret)
768 return ret;
769 }
770
771 indio_dev->dev.parent = dev;
772 indio_dev->dev.of_node = node;
773 indio_dev->name = pdev->name;
774 indio_dev->modes = INDIO_DIRECT_MODE;
775 indio_dev->info = &adc5_info;
776 indio_dev->channels = adc->iio_chans;
777 indio_dev->num_channels = adc->nchannels;
778
779 return devm_iio_device_register(dev, indio_dev);
780}
781
782static struct platform_driver adc5_driver = {
783 .driver = {
784 .name = "qcom-spmi-adc5.c",
785 .of_match_table = adc5_match_table,
786 },
787 .probe = adc5_probe,
788};
789module_platform_driver(adc5_driver);
790
791MODULE_ALIAS("platform:qcom-spmi-adc5");
792MODULE_DESCRIPTION("Qualcomm Technologies Inc. PMIC5 ADC driver");
793MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/adc/qcom-vadc-common.c b/drivers/iio/adc/qcom-vadc-common.c
index fe3d7826783c..dcd7fb5b9fb2 100644
--- a/drivers/iio/adc/qcom-vadc-common.c
+++ b/drivers/iio/adc/qcom-vadc-common.c
@@ -47,8 +47,79 @@ static const struct vadc_map_pt adcmap_100k_104ef_104fb[] = {
47 {44, 125} 47 {44, 125}
48}; 48};
49 49
50/*
51 * Voltage to temperature table for 100k pull up for NTCG104EF104 with
52 * 1.875V reference.
53 */
54static const struct vadc_map_pt adcmap_100k_104ef_104fb_1875_vref[] = {
55 { 1831, -40000 },
56 { 1814, -35000 },
57 { 1791, -30000 },
58 { 1761, -25000 },
59 { 1723, -20000 },
60 { 1675, -15000 },
61 { 1616, -10000 },
62 { 1545, -5000 },
63 { 1463, 0 },
64 { 1370, 5000 },
65 { 1268, 10000 },
66 { 1160, 15000 },
67 { 1049, 20000 },
68 { 937, 25000 },
69 { 828, 30000 },
70 { 726, 35000 },
71 { 630, 40000 },
72 { 544, 45000 },
73 { 467, 50000 },
74 { 399, 55000 },
75 { 340, 60000 },
76 { 290, 65000 },
77 { 247, 70000 },
78 { 209, 75000 },
79 { 179, 80000 },
80 { 153, 85000 },
81 { 130, 90000 },
82 { 112, 95000 },
83 { 96, 100000 },
84 { 82, 105000 },
85 { 71, 110000 },
86 { 62, 115000 },
87 { 53, 120000 },
88 { 46, 125000 },
89};
90
91static int qcom_vadc_scale_hw_calib_volt(
92 const struct vadc_prescale_ratio *prescale,
93 const struct adc5_data *data,
94 u16 adc_code, int *result_uv);
95static int qcom_vadc_scale_hw_calib_therm(
96 const struct vadc_prescale_ratio *prescale,
97 const struct adc5_data *data,
98 u16 adc_code, int *result_mdec);
99static int qcom_vadc_scale_hw_smb_temp(
100 const struct vadc_prescale_ratio *prescale,
101 const struct adc5_data *data,
102 u16 adc_code, int *result_mdec);
103static int qcom_vadc_scale_hw_chg5_temp(
104 const struct vadc_prescale_ratio *prescale,
105 const struct adc5_data *data,
106 u16 adc_code, int *result_mdec);
107static int qcom_vadc_scale_hw_calib_die_temp(
108 const struct vadc_prescale_ratio *prescale,
109 const struct adc5_data *data,
110 u16 adc_code, int *result_mdec);
111
112static struct qcom_adc5_scale_type scale_adc5_fn[] = {
113 [SCALE_HW_CALIB_DEFAULT] = {qcom_vadc_scale_hw_calib_volt},
114 [SCALE_HW_CALIB_THERM_100K_PULLUP] = {qcom_vadc_scale_hw_calib_therm},
115 [SCALE_HW_CALIB_XOTHERM] = {qcom_vadc_scale_hw_calib_therm},
116 [SCALE_HW_CALIB_PMIC_THERM] = {qcom_vadc_scale_hw_calib_die_temp},
117 [SCALE_HW_CALIB_PM5_CHG_TEMP] = {qcom_vadc_scale_hw_chg5_temp},
118 [SCALE_HW_CALIB_PM5_SMB_TEMP] = {qcom_vadc_scale_hw_smb_temp},
119};
120
50static int qcom_vadc_map_voltage_temp(const struct vadc_map_pt *pts, 121static int qcom_vadc_map_voltage_temp(const struct vadc_map_pt *pts,
51 u32 tablesize, s32 input, s64 *output) 122 u32 tablesize, s32 input, int *output)
52{ 123{
53 bool descending = 1; 124 bool descending = 1;
54 u32 i = 0; 125 u32 i = 0;
@@ -128,7 +199,7 @@ static int qcom_vadc_scale_therm(const struct vadc_linear_graph *calib_graph,
128 bool absolute, u16 adc_code, 199 bool absolute, u16 adc_code,
129 int *result_mdec) 200 int *result_mdec)
130{ 201{
131 s64 voltage = 0, result = 0; 202 s64 voltage = 0;
132 int ret; 203 int ret;
133 204
134 qcom_vadc_scale_calib(calib_graph, adc_code, absolute, &voltage); 205 qcom_vadc_scale_calib(calib_graph, adc_code, absolute, &voltage);
@@ -138,12 +209,11 @@ static int qcom_vadc_scale_therm(const struct vadc_linear_graph *calib_graph,
138 209
139 ret = qcom_vadc_map_voltage_temp(adcmap_100k_104ef_104fb, 210 ret = qcom_vadc_map_voltage_temp(adcmap_100k_104ef_104fb,
140 ARRAY_SIZE(adcmap_100k_104ef_104fb), 211 ARRAY_SIZE(adcmap_100k_104ef_104fb),
141 voltage, &result); 212 voltage, result_mdec);
142 if (ret) 213 if (ret)
143 return ret; 214 return ret;
144 215
145 result *= 1000; 216 *result_mdec *= 1000;
146 *result_mdec = result;
147 217
148 return 0; 218 return 0;
149} 219}
@@ -191,6 +261,99 @@ static int qcom_vadc_scale_chg_temp(const struct vadc_linear_graph *calib_graph,
191 return 0; 261 return 0;
192} 262}
193 263
264static int qcom_vadc_scale_code_voltage_factor(u16 adc_code,
265 const struct vadc_prescale_ratio *prescale,
266 const struct adc5_data *data,
267 unsigned int factor)
268{
269 s64 voltage, temp, adc_vdd_ref_mv = 1875;
270
271 /*
272 * The normal data range is between 0V to 1.875V. On cases where
273 * we read low voltage values, the ADC code can go beyond the
274 * range and the scale result is incorrect so we clamp the values
275 * for the cases where the code represents a value below 0V
276 */
277 if (adc_code > VADC5_MAX_CODE)
278 adc_code = 0;
279
280 /* (ADC code * vref_vadc (1.875V)) / full_scale_code */
281 voltage = (s64) adc_code * adc_vdd_ref_mv * 1000;
282 voltage = div64_s64(voltage, data->full_scale_code_volt);
283 if (voltage > 0) {
284 voltage *= prescale->den;
285 temp = prescale->num * factor;
286 voltage = div64_s64(voltage, temp);
287 } else {
288 voltage = 0;
289 }
290
291 return (int) voltage;
292}
293
294static int qcom_vadc_scale_hw_calib_volt(
295 const struct vadc_prescale_ratio *prescale,
296 const struct adc5_data *data,
297 u16 adc_code, int *result_uv)
298{
299 *result_uv = qcom_vadc_scale_code_voltage_factor(adc_code,
300 prescale, data, 1);
301
302 return 0;
303}
304
305static int qcom_vadc_scale_hw_calib_therm(
306 const struct vadc_prescale_ratio *prescale,
307 const struct adc5_data *data,
308 u16 adc_code, int *result_mdec)
309{
310 int voltage;
311
312 voltage = qcom_vadc_scale_code_voltage_factor(adc_code,
313 prescale, data, 1000);
314
315 /* Map voltage to temperature from look-up table */
316 return qcom_vadc_map_voltage_temp(adcmap_100k_104ef_104fb_1875_vref,
317 ARRAY_SIZE(adcmap_100k_104ef_104fb_1875_vref),
318 voltage, result_mdec);
319}
320
321static int qcom_vadc_scale_hw_calib_die_temp(
322 const struct vadc_prescale_ratio *prescale,
323 const struct adc5_data *data,
324 u16 adc_code, int *result_mdec)
325{
326 *result_mdec = qcom_vadc_scale_code_voltage_factor(adc_code,
327 prescale, data, 2);
328 *result_mdec -= KELVINMIL_CELSIUSMIL;
329
330 return 0;
331}
332
333static int qcom_vadc_scale_hw_smb_temp(
334 const struct vadc_prescale_ratio *prescale,
335 const struct adc5_data *data,
336 u16 adc_code, int *result_mdec)
337{
338 *result_mdec = qcom_vadc_scale_code_voltage_factor(adc_code * 100,
339 prescale, data, PMIC5_SMB_TEMP_SCALE_FACTOR);
340 *result_mdec = PMIC5_SMB_TEMP_CONSTANT - *result_mdec;
341
342 return 0;
343}
344
345static int qcom_vadc_scale_hw_chg5_temp(
346 const struct vadc_prescale_ratio *prescale,
347 const struct adc5_data *data,
348 u16 adc_code, int *result_mdec)
349{
350 *result_mdec = qcom_vadc_scale_code_voltage_factor(adc_code,
351 prescale, data, 4);
352 *result_mdec = PMIC5_CHG_TEMP_SCALE_FACTOR - *result_mdec;
353
354 return 0;
355}
356
194int qcom_vadc_scale(enum vadc_scale_fn_type scaletype, 357int qcom_vadc_scale(enum vadc_scale_fn_type scaletype,
195 const struct vadc_linear_graph *calib_graph, 358 const struct vadc_linear_graph *calib_graph,
196 const struct vadc_prescale_ratio *prescale, 359 const struct vadc_prescale_ratio *prescale,
@@ -221,6 +384,22 @@ int qcom_vadc_scale(enum vadc_scale_fn_type scaletype,
221} 384}
222EXPORT_SYMBOL(qcom_vadc_scale); 385EXPORT_SYMBOL(qcom_vadc_scale);
223 386
387int qcom_adc5_hw_scale(enum vadc_scale_fn_type scaletype,
388 const struct vadc_prescale_ratio *prescale,
389 const struct adc5_data *data,
390 u16 adc_code, int *result)
391{
392 if (!(scaletype >= SCALE_HW_CALIB_DEFAULT &&
393 scaletype < SCALE_HW_CALIB_INVALID)) {
394 pr_err("Invalid scale type %d\n", scaletype);
395 return -EINVAL;
396 }
397
398 return scale_adc5_fn[scaletype].scale_fn(prescale, data,
399 adc_code, result);
400}
401EXPORT_SYMBOL(qcom_adc5_hw_scale);
402
224int qcom_vadc_decimation_from_dt(u32 value) 403int qcom_vadc_decimation_from_dt(u32 value)
225{ 404{
226 if (!is_power_of_2(value) || value < VADC_DECIMATION_MIN || 405 if (!is_power_of_2(value) || value < VADC_DECIMATION_MIN ||
diff --git a/drivers/iio/adc/qcom-vadc-common.h b/drivers/iio/adc/qcom-vadc-common.h
index 1d5354ff5c72..bbb1fa02b382 100644
--- a/drivers/iio/adc/qcom-vadc-common.h
+++ b/drivers/iio/adc/qcom-vadc-common.h
@@ -25,15 +25,31 @@
25 25
26#define VADC_DECIMATION_MIN 512 26#define VADC_DECIMATION_MIN 512
27#define VADC_DECIMATION_MAX 4096 27#define VADC_DECIMATION_MAX 4096
28#define ADC5_DEF_VBAT_PRESCALING 1 /* 1:3 */
29#define ADC5_DECIMATION_SHORT 250
30#define ADC5_DECIMATION_MEDIUM 420
31#define ADC5_DECIMATION_LONG 840
32/* Default decimation - 1024 for rev2, 840 for pmic5 */
33#define ADC5_DECIMATION_DEFAULT 2
34#define ADC5_DECIMATION_SAMPLES_MAX 3
28 35
29#define VADC_HW_SETTLE_DELAY_MAX 10000 36#define VADC_HW_SETTLE_DELAY_MAX 10000
37#define VADC_HW_SETTLE_SAMPLES_MAX 16
30#define VADC_AVG_SAMPLES_MAX 512 38#define VADC_AVG_SAMPLES_MAX 512
39#define ADC5_AVG_SAMPLES_MAX 16
31 40
32#define KELVINMIL_CELSIUSMIL 273150 41#define KELVINMIL_CELSIUSMIL 273150
42#define PMIC5_CHG_TEMP_SCALE_FACTOR 377500
43#define PMIC5_SMB_TEMP_CONSTANT 419400
44#define PMIC5_SMB_TEMP_SCALE_FACTOR 356
33 45
34#define PMI_CHG_SCALE_1 -138890 46#define PMI_CHG_SCALE_1 -138890
35#define PMI_CHG_SCALE_2 391750000000LL 47#define PMI_CHG_SCALE_2 391750000000LL
36 48
49#define VADC5_MAX_CODE 0x7fff
50#define ADC5_FULL_SCALE_CODE 0x70e4
51#define ADC5_USR_DATA_CHECK 0x8000
52
37/** 53/**
38 * struct vadc_map_pt - Map the graph representation for ADC channel 54 * struct vadc_map_pt - Map the graph representation for ADC channel
39 * @x: Represent the ADC digitized code. 55 * @x: Represent the ADC digitized code.
@@ -89,6 +105,18 @@ struct vadc_prescale_ratio {
89 * SCALE_PMIC_THERM: Returns result in milli degree's Centigrade. 105 * SCALE_PMIC_THERM: Returns result in milli degree's Centigrade.
90 * SCALE_XOTHERM: Returns XO thermistor voltage in millidegC. 106 * SCALE_XOTHERM: Returns XO thermistor voltage in millidegC.
91 * SCALE_PMI_CHG_TEMP: Conversion for PMI CHG temp 107 * SCALE_PMI_CHG_TEMP: Conversion for PMI CHG temp
108 * SCALE_HW_CALIB_DEFAULT: Default scaling to convert raw adc code to
109 * voltage (uV) with hardware applied offset/slope values to adc code.
110 * SCALE_HW_CALIB_THERM_100K_PULLUP: Returns temperature in millidegC using
111 * lookup table. The hardware applies offset/slope to adc code.
112 * SCALE_HW_CALIB_XOTHERM: Returns XO thermistor voltage in millidegC using
113 * 100k pullup. The hardware applies offset/slope to adc code.
114 * SCALE_HW_CALIB_PMIC_THERM: Returns result in milli degree's Centigrade.
115 * The hardware applies offset/slope to adc code.
116 * SCALE_HW_CALIB_PM5_CHG_TEMP: Returns result in millidegrees for PMIC5
117 * charger temperature.
118 * SCALE_HW_CALIB_PM5_SMB_TEMP: Returns result in millidegrees for PMIC5
119 * SMB1390 temperature.
92 */ 120 */
93enum vadc_scale_fn_type { 121enum vadc_scale_fn_type {
94 SCALE_DEFAULT = 0, 122 SCALE_DEFAULT = 0,
@@ -96,6 +124,22 @@ enum vadc_scale_fn_type {
96 SCALE_PMIC_THERM, 124 SCALE_PMIC_THERM,
97 SCALE_XOTHERM, 125 SCALE_XOTHERM,
98 SCALE_PMI_CHG_TEMP, 126 SCALE_PMI_CHG_TEMP,
127 SCALE_HW_CALIB_DEFAULT,
128 SCALE_HW_CALIB_THERM_100K_PULLUP,
129 SCALE_HW_CALIB_XOTHERM,
130 SCALE_HW_CALIB_PMIC_THERM,
131 SCALE_HW_CALIB_PM5_CHG_TEMP,
132 SCALE_HW_CALIB_PM5_SMB_TEMP,
133 SCALE_HW_CALIB_INVALID,
134};
135
136struct adc5_data {
137 const u32 full_scale_code_volt;
138 const u32 full_scale_code_cur;
139 const struct adc5_channels *adc_chans;
140 unsigned int *decimation;
141 unsigned int *hw_settle_1;
142 unsigned int *hw_settle_2;
99}; 143};
100 144
101int qcom_vadc_scale(enum vadc_scale_fn_type scaletype, 145int qcom_vadc_scale(enum vadc_scale_fn_type scaletype,
@@ -104,6 +148,16 @@ int qcom_vadc_scale(enum vadc_scale_fn_type scaletype,
104 bool absolute, 148 bool absolute,
105 u16 adc_code, int *result_mdec); 149 u16 adc_code, int *result_mdec);
106 150
151struct qcom_adc5_scale_type {
152 int (*scale_fn)(const struct vadc_prescale_ratio *prescale,
153 const struct adc5_data *data, u16 adc_code, int *result);
154};
155
156int qcom_adc5_hw_scale(enum vadc_scale_fn_type scaletype,
157 const struct vadc_prescale_ratio *prescale,
158 const struct adc5_data *data,
159 u16 adc_code, int *result_mdec);
160
107int qcom_vadc_decimation_from_dt(u32 value); 161int qcom_vadc_decimation_from_dt(u32 value);
108 162
109#endif /* QCOM_VADC_COMMON_H */ 163#endif /* QCOM_VADC_COMMON_H */
diff --git a/drivers/iio/adc/rcar-gyroadc.c b/drivers/iio/adc/rcar-gyroadc.c
index dcb50172186f..4e982b51bcda 100644
--- a/drivers/iio/adc/rcar-gyroadc.c
+++ b/drivers/iio/adc/rcar-gyroadc.c
@@ -343,8 +343,8 @@ static int rcar_gyroadc_parse_subdevs(struct iio_dev *indio_dev)
343 for_each_child_of_node(np, child) { 343 for_each_child_of_node(np, child) {
344 of_id = of_match_node(rcar_gyroadc_child_match, child); 344 of_id = of_match_node(rcar_gyroadc_child_match, child);
345 if (!of_id) { 345 if (!of_id) {
346 dev_err(dev, "Ignoring unsupported ADC \"%s\".", 346 dev_err(dev, "Ignoring unsupported ADC \"%pOFn\".",
347 child->name); 347 child);
348 continue; 348 continue;
349 } 349 }
350 350
@@ -381,16 +381,16 @@ static int rcar_gyroadc_parse_subdevs(struct iio_dev *indio_dev)
381 ret = of_property_read_u32(child, "reg", &reg); 381 ret = of_property_read_u32(child, "reg", &reg);
382 if (ret) { 382 if (ret) {
383 dev_err(dev, 383 dev_err(dev,
384 "Failed to get child reg property of ADC \"%s\".\n", 384 "Failed to get child reg property of ADC \"%pOFn\".\n",
385 child->name); 385 child);
386 return ret; 386 return ret;
387 } 387 }
388 388
389 /* Channel number is too high. */ 389 /* Channel number is too high. */
390 if (reg >= num_channels) { 390 if (reg >= num_channels) {
391 dev_err(dev, 391 dev_err(dev,
392 "Only %i channels supported with %s, but reg = <%i>.\n", 392 "Only %i channels supported with %pOFn, but reg = <%i>.\n",
393 num_channels, child->name, reg); 393 num_channels, child, reg);
394 return ret; 394 return ret;
395 } 395 }
396 } 396 }
diff --git a/drivers/iio/adc/sc27xx_adc.c b/drivers/iio/adc/sc27xx_adc.c
index 2b60efea0c39..7940b23dcad9 100644
--- a/drivers/iio/adc/sc27xx_adc.c
+++ b/drivers/iio/adc/sc27xx_adc.c
@@ -5,10 +5,12 @@
5#include <linux/iio/iio.h> 5#include <linux/iio/iio.h>
6#include <linux/interrupt.h> 6#include <linux/interrupt.h>
7#include <linux/module.h> 7#include <linux/module.h>
8#include <linux/nvmem-consumer.h>
8#include <linux/of.h> 9#include <linux/of.h>
9#include <linux/of_device.h> 10#include <linux/of_device.h>
10#include <linux/platform_device.h> 11#include <linux/platform_device.h>
11#include <linux/regmap.h> 12#include <linux/regmap.h>
13#include <linux/slab.h>
12 14
13/* PMIC global registers definition */ 15/* PMIC global registers definition */
14#define SC27XX_MODULE_EN 0xc08 16#define SC27XX_MODULE_EN 0xc08
@@ -87,16 +89,73 @@ struct sc27xx_adc_linear_graph {
87 * should use the small-scale graph, and if more than 1.2v, we should use the 89 * should use the small-scale graph, and if more than 1.2v, we should use the
88 * big-scale graph. 90 * big-scale graph.
89 */ 91 */
90static const struct sc27xx_adc_linear_graph big_scale_graph = { 92static struct sc27xx_adc_linear_graph big_scale_graph = {
91 4200, 3310, 93 4200, 3310,
92 3600, 2832, 94 3600, 2832,
93}; 95};
94 96
95static const struct sc27xx_adc_linear_graph small_scale_graph = { 97static struct sc27xx_adc_linear_graph small_scale_graph = {
96 1000, 3413, 98 1000, 3413,
97 100, 341, 99 100, 341,
98}; 100};
99 101
102static const struct sc27xx_adc_linear_graph big_scale_graph_calib = {
103 4200, 856,
104 3600, 733,
105};
106
107static const struct sc27xx_adc_linear_graph small_scale_graph_calib = {
108 1000, 833,
109 100, 80,
110};
111
112static int sc27xx_adc_get_calib_data(u32 calib_data, int calib_adc)
113{
114 return ((calib_data & 0xff) + calib_adc - 128) * 4;
115}
116
117static int sc27xx_adc_scale_calibration(struct sc27xx_adc_data *data,
118 bool big_scale)
119{
120 const struct sc27xx_adc_linear_graph *calib_graph;
121 struct sc27xx_adc_linear_graph *graph;
122 struct nvmem_cell *cell;
123 const char *cell_name;
124 u32 calib_data = 0;
125 void *buf;
126 size_t len;
127
128 if (big_scale) {
129 calib_graph = &big_scale_graph_calib;
130 graph = &big_scale_graph;
131 cell_name = "big_scale_calib";
132 } else {
133 calib_graph = &small_scale_graph_calib;
134 graph = &small_scale_graph;
135 cell_name = "small_scale_calib";
136 }
137
138 cell = nvmem_cell_get(data->dev, cell_name);
139 if (IS_ERR(cell))
140 return PTR_ERR(cell);
141
142 buf = nvmem_cell_read(cell, &len);
143 nvmem_cell_put(cell);
144
145 if (IS_ERR(buf))
146 return PTR_ERR(buf);
147
148 memcpy(&calib_data, buf, min(len, sizeof(u32)));
149
150 /* Only need to calibrate the adc values in the linear graph. */
151 graph->adc0 = sc27xx_adc_get_calib_data(calib_data, calib_graph->adc0);
152 graph->adc1 = sc27xx_adc_get_calib_data(calib_data >> 8,
153 calib_graph->adc1);
154
155 kfree(buf);
156 return 0;
157}
158
100static int sc27xx_adc_get_ratio(int channel, int scale) 159static int sc27xx_adc_get_ratio(int channel, int scale)
101{ 160{
102 switch (channel) { 161 switch (channel) {
@@ -209,7 +268,7 @@ static void sc27xx_adc_volt_ratio(struct sc27xx_adc_data *data,
209 *div_denominator = ratio & SC27XX_RATIO_DENOMINATOR_MASK; 268 *div_denominator = ratio & SC27XX_RATIO_DENOMINATOR_MASK;
210} 269}
211 270
212static int sc27xx_adc_to_volt(const struct sc27xx_adc_linear_graph *graph, 271static int sc27xx_adc_to_volt(struct sc27xx_adc_linear_graph *graph,
213 int raw_adc) 272 int raw_adc)
214{ 273{
215 int tmp; 274 int tmp;
@@ -273,6 +332,17 @@ static int sc27xx_adc_read_raw(struct iio_dev *indio_dev,
273 int ret, tmp; 332 int ret, tmp;
274 333
275 switch (mask) { 334 switch (mask) {
335 case IIO_CHAN_INFO_RAW:
336 mutex_lock(&indio_dev->mlock);
337 ret = sc27xx_adc_read(data, chan->channel, scale, &tmp);
338 mutex_unlock(&indio_dev->mlock);
339
340 if (ret)
341 return ret;
342
343 *val = tmp;
344 return IIO_VAL_INT;
345
276 case IIO_CHAN_INFO_PROCESSED: 346 case IIO_CHAN_INFO_PROCESSED:
277 mutex_lock(&indio_dev->mlock); 347 mutex_lock(&indio_dev->mlock);
278 ret = sc27xx_adc_read_processed(data, chan->channel, scale, 348 ret = sc27xx_adc_read_processed(data, chan->channel, scale,
@@ -315,48 +385,47 @@ static const struct iio_info sc27xx_info = {
315 .write_raw = &sc27xx_adc_write_raw, 385 .write_raw = &sc27xx_adc_write_raw,
316}; 386};
317 387
318#define SC27XX_ADC_CHANNEL(index) { \ 388#define SC27XX_ADC_CHANNEL(index, mask) { \
319 .type = IIO_VOLTAGE, \ 389 .type = IIO_VOLTAGE, \
320 .channel = index, \ 390 .channel = index, \
321 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | \ 391 .info_mask_separate = mask | BIT(IIO_CHAN_INFO_SCALE), \
322 BIT(IIO_CHAN_INFO_SCALE), \
323 .datasheet_name = "CH##index", \ 392 .datasheet_name = "CH##index", \
324 .indexed = 1, \ 393 .indexed = 1, \
325} 394}
326 395
327static const struct iio_chan_spec sc27xx_channels[] = { 396static const struct iio_chan_spec sc27xx_channels[] = {
328 SC27XX_ADC_CHANNEL(0), 397 SC27XX_ADC_CHANNEL(0, BIT(IIO_CHAN_INFO_PROCESSED)),
329 SC27XX_ADC_CHANNEL(1), 398 SC27XX_ADC_CHANNEL(1, BIT(IIO_CHAN_INFO_PROCESSED)),
330 SC27XX_ADC_CHANNEL(2), 399 SC27XX_ADC_CHANNEL(2, BIT(IIO_CHAN_INFO_PROCESSED)),
331 SC27XX_ADC_CHANNEL(3), 400 SC27XX_ADC_CHANNEL(3, BIT(IIO_CHAN_INFO_PROCESSED)),
332 SC27XX_ADC_CHANNEL(4), 401 SC27XX_ADC_CHANNEL(4, BIT(IIO_CHAN_INFO_PROCESSED)),
333 SC27XX_ADC_CHANNEL(5), 402 SC27XX_ADC_CHANNEL(5, BIT(IIO_CHAN_INFO_PROCESSED)),
334 SC27XX_ADC_CHANNEL(6), 403 SC27XX_ADC_CHANNEL(6, BIT(IIO_CHAN_INFO_PROCESSED)),
335 SC27XX_ADC_CHANNEL(7), 404 SC27XX_ADC_CHANNEL(7, BIT(IIO_CHAN_INFO_PROCESSED)),
336 SC27XX_ADC_CHANNEL(8), 405 SC27XX_ADC_CHANNEL(8, BIT(IIO_CHAN_INFO_PROCESSED)),
337 SC27XX_ADC_CHANNEL(9), 406 SC27XX_ADC_CHANNEL(9, BIT(IIO_CHAN_INFO_PROCESSED)),
338 SC27XX_ADC_CHANNEL(10), 407 SC27XX_ADC_CHANNEL(10, BIT(IIO_CHAN_INFO_PROCESSED)),
339 SC27XX_ADC_CHANNEL(11), 408 SC27XX_ADC_CHANNEL(11, BIT(IIO_CHAN_INFO_PROCESSED)),
340 SC27XX_ADC_CHANNEL(12), 409 SC27XX_ADC_CHANNEL(12, BIT(IIO_CHAN_INFO_PROCESSED)),
341 SC27XX_ADC_CHANNEL(13), 410 SC27XX_ADC_CHANNEL(13, BIT(IIO_CHAN_INFO_PROCESSED)),
342 SC27XX_ADC_CHANNEL(14), 411 SC27XX_ADC_CHANNEL(14, BIT(IIO_CHAN_INFO_PROCESSED)),
343 SC27XX_ADC_CHANNEL(15), 412 SC27XX_ADC_CHANNEL(15, BIT(IIO_CHAN_INFO_PROCESSED)),
344 SC27XX_ADC_CHANNEL(16), 413 SC27XX_ADC_CHANNEL(16, BIT(IIO_CHAN_INFO_PROCESSED)),
345 SC27XX_ADC_CHANNEL(17), 414 SC27XX_ADC_CHANNEL(17, BIT(IIO_CHAN_INFO_PROCESSED)),
346 SC27XX_ADC_CHANNEL(18), 415 SC27XX_ADC_CHANNEL(18, BIT(IIO_CHAN_INFO_PROCESSED)),
347 SC27XX_ADC_CHANNEL(19), 416 SC27XX_ADC_CHANNEL(19, BIT(IIO_CHAN_INFO_PROCESSED)),
348 SC27XX_ADC_CHANNEL(20), 417 SC27XX_ADC_CHANNEL(20, BIT(IIO_CHAN_INFO_RAW)),
349 SC27XX_ADC_CHANNEL(21), 418 SC27XX_ADC_CHANNEL(21, BIT(IIO_CHAN_INFO_PROCESSED)),
350 SC27XX_ADC_CHANNEL(22), 419 SC27XX_ADC_CHANNEL(22, BIT(IIO_CHAN_INFO_PROCESSED)),
351 SC27XX_ADC_CHANNEL(23), 420 SC27XX_ADC_CHANNEL(23, BIT(IIO_CHAN_INFO_PROCESSED)),
352 SC27XX_ADC_CHANNEL(24), 421 SC27XX_ADC_CHANNEL(24, BIT(IIO_CHAN_INFO_PROCESSED)),
353 SC27XX_ADC_CHANNEL(25), 422 SC27XX_ADC_CHANNEL(25, BIT(IIO_CHAN_INFO_PROCESSED)),
354 SC27XX_ADC_CHANNEL(26), 423 SC27XX_ADC_CHANNEL(26, BIT(IIO_CHAN_INFO_PROCESSED)),
355 SC27XX_ADC_CHANNEL(27), 424 SC27XX_ADC_CHANNEL(27, BIT(IIO_CHAN_INFO_PROCESSED)),
356 SC27XX_ADC_CHANNEL(28), 425 SC27XX_ADC_CHANNEL(28, BIT(IIO_CHAN_INFO_PROCESSED)),
357 SC27XX_ADC_CHANNEL(29), 426 SC27XX_ADC_CHANNEL(29, BIT(IIO_CHAN_INFO_PROCESSED)),
358 SC27XX_ADC_CHANNEL(30), 427 SC27XX_ADC_CHANNEL(30, BIT(IIO_CHAN_INFO_PROCESSED)),
359 SC27XX_ADC_CHANNEL(31), 428 SC27XX_ADC_CHANNEL(31, BIT(IIO_CHAN_INFO_PROCESSED)),
360}; 429};
361 430
362static int sc27xx_adc_enable(struct sc27xx_adc_data *data) 431static int sc27xx_adc_enable(struct sc27xx_adc_data *data)
@@ -380,6 +449,15 @@ static int sc27xx_adc_enable(struct sc27xx_adc_data *data)
380 if (ret) 449 if (ret)
381 goto disable_clk; 450 goto disable_clk;
382 451
452 /* ADC channel scales' calibration from nvmem device */
453 ret = sc27xx_adc_scale_calibration(data, true);
454 if (ret)
455 goto disable_clk;
456
457 ret = sc27xx_adc_scale_calibration(data, false);
458 if (ret)
459 goto disable_clk;
460
383 return 0; 461 return 0;
384 462
385disable_clk: 463disable_clk:
diff --git a/drivers/iio/adc/ti-ads7950.c b/drivers/iio/adc/ti-ads7950.c
index a5bd5944bc66..0ad63592cc3c 100644
--- a/drivers/iio/adc/ti-ads7950.c
+++ b/drivers/iio/adc/ti-ads7950.c
@@ -51,7 +51,7 @@
51 51
52struct ti_ads7950_state { 52struct ti_ads7950_state {
53 struct spi_device *spi; 53 struct spi_device *spi;
54 struct spi_transfer ring_xfer[TI_ADS7950_MAX_CHAN + 2]; 54 struct spi_transfer ring_xfer;
55 struct spi_transfer scan_single_xfer[3]; 55 struct spi_transfer scan_single_xfer[3];
56 struct spi_message ring_msg; 56 struct spi_message ring_msg;
57 struct spi_message scan_single_msg; 57 struct spi_message scan_single_msg;
@@ -65,11 +65,11 @@ struct ti_ads7950_state {
65 * DMA (thus cache coherency maintenance) requires the 65 * DMA (thus cache coherency maintenance) requires the
66 * transfer buffers to live in their own cache lines. 66 * transfer buffers to live in their own cache lines.
67 */ 67 */
68 __be16 rx_buf[TI_ADS7950_MAX_CHAN + TI_ADS7950_TIMESTAMP_SIZE] 68 u16 rx_buf[TI_ADS7950_MAX_CHAN + 2 + TI_ADS7950_TIMESTAMP_SIZE]
69 ____cacheline_aligned; 69 ____cacheline_aligned;
70 __be16 tx_buf[TI_ADS7950_MAX_CHAN]; 70 u16 tx_buf[TI_ADS7950_MAX_CHAN + 2];
71 __be16 single_tx; 71 u16 single_tx;
72 __be16 single_rx; 72 u16 single_rx;
73 73
74}; 74};
75 75
@@ -108,7 +108,7 @@ enum ti_ads7950_id {
108 .realbits = bits, \ 108 .realbits = bits, \
109 .storagebits = 16, \ 109 .storagebits = 16, \
110 .shift = 12 - (bits), \ 110 .shift = 12 - (bits), \
111 .endianness = IIO_BE, \ 111 .endianness = IIO_CPU, \
112 }, \ 112 }, \
113} 113}
114 114
@@ -249,23 +249,14 @@ static int ti_ads7950_update_scan_mode(struct iio_dev *indio_dev,
249 len = 0; 249 len = 0;
250 for_each_set_bit(i, active_scan_mask, indio_dev->num_channels) { 250 for_each_set_bit(i, active_scan_mask, indio_dev->num_channels) {
251 cmd = TI_ADS7950_CR_WRITE | TI_ADS7950_CR_CHAN(i) | st->settings; 251 cmd = TI_ADS7950_CR_WRITE | TI_ADS7950_CR_CHAN(i) | st->settings;
252 st->tx_buf[len++] = cpu_to_be16(cmd); 252 st->tx_buf[len++] = cmd;
253 } 253 }
254 254
255 /* Data for the 1st channel is not returned until the 3rd transfer */ 255 /* Data for the 1st channel is not returned until the 3rd transfer */
256 len += 2; 256 st->tx_buf[len++] = 0;
257 for (i = 0; i < len; i++) { 257 st->tx_buf[len++] = 0;
258 if ((i + 2) < len)
259 st->ring_xfer[i].tx_buf = &st->tx_buf[i];
260 if (i >= 2)
261 st->ring_xfer[i].rx_buf = &st->rx_buf[i - 2];
262 st->ring_xfer[i].len = 2;
263 st->ring_xfer[i].cs_change = 1;
264 }
265 /* make sure last transfer's cs_change is not set */
266 st->ring_xfer[len - 1].cs_change = 0;
267 258
268 spi_message_init_with_transfers(&st->ring_msg, st->ring_xfer, len); 259 st->ring_xfer.len = len * 2;
269 260
270 return 0; 261 return 0;
271} 262}
@@ -281,7 +272,7 @@ static irqreturn_t ti_ads7950_trigger_handler(int irq, void *p)
281 if (ret < 0) 272 if (ret < 0)
282 goto out; 273 goto out;
283 274
284 iio_push_to_buffers_with_timestamp(indio_dev, st->rx_buf, 275 iio_push_to_buffers_with_timestamp(indio_dev, &st->rx_buf[2],
285 iio_get_time_ns(indio_dev)); 276 iio_get_time_ns(indio_dev));
286 277
287out: 278out:
@@ -298,13 +289,13 @@ static int ti_ads7950_scan_direct(struct iio_dev *indio_dev, unsigned int ch)
298 mutex_lock(&indio_dev->mlock); 289 mutex_lock(&indio_dev->mlock);
299 290
300 cmd = TI_ADS7950_CR_WRITE | TI_ADS7950_CR_CHAN(ch) | st->settings; 291 cmd = TI_ADS7950_CR_WRITE | TI_ADS7950_CR_CHAN(ch) | st->settings;
301 st->single_tx = cpu_to_be16(cmd); 292 st->single_tx = cmd;
302 293
303 ret = spi_sync(st->spi, &st->scan_single_msg); 294 ret = spi_sync(st->spi, &st->scan_single_msg);
304 if (ret) 295 if (ret)
305 goto out; 296 goto out;
306 297
307 ret = be16_to_cpu(st->single_rx); 298 ret = st->single_rx;
308 299
309out: 300out:
310 mutex_unlock(&indio_dev->mlock); 301 mutex_unlock(&indio_dev->mlock);
@@ -378,6 +369,14 @@ static int ti_ads7950_probe(struct spi_device *spi)
378 const struct ti_ads7950_chip_info *info; 369 const struct ti_ads7950_chip_info *info;
379 int ret; 370 int ret;
380 371
372 spi->bits_per_word = 16;
373 spi->mode |= SPI_CS_WORD;
374 ret = spi_setup(spi);
375 if (ret < 0) {
376 dev_err(&spi->dev, "Error in spi setup\n");
377 return ret;
378 }
379
381 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 380 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
382 if (!indio_dev) 381 if (!indio_dev)
383 return -ENOMEM; 382 return -ENOMEM;
@@ -398,6 +397,16 @@ static int ti_ads7950_probe(struct spi_device *spi)
398 indio_dev->num_channels = info->num_channels; 397 indio_dev->num_channels = info->num_channels;
399 indio_dev->info = &ti_ads7950_info; 398 indio_dev->info = &ti_ads7950_info;
400 399
400 /* build spi ring message */
401 spi_message_init(&st->ring_msg);
402
403 st->ring_xfer.tx_buf = &st->tx_buf[0];
404 st->ring_xfer.rx_buf = &st->rx_buf[0];
405 /* len will be set later */
406 st->ring_xfer.cs_change = true;
407
408 spi_message_add_tail(&st->ring_xfer, &st->ring_msg);
409
401 /* 410 /*
402 * Setup default message. The sample is read at the end of the first 411 * Setup default message. The sample is read at the end of the first
403 * transfer, then it takes one full cycle to convert the sample and one 412 * transfer, then it takes one full cycle to convert the sample and one
diff --git a/drivers/iio/amplifiers/ad8366.c b/drivers/iio/amplifiers/ad8366.c
index 0138337aedd1..4b76b61ba4be 100644
--- a/drivers/iio/amplifiers/ad8366.c
+++ b/drivers/iio/amplifiers/ad8366.c
@@ -209,6 +209,6 @@ static struct spi_driver ad8366_driver = {
209 209
210module_spi_driver(ad8366_driver); 210module_spi_driver(ad8366_driver);
211 211
212MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 212MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
213MODULE_DESCRIPTION("Analog Devices AD8366 VGA"); 213MODULE_DESCRIPTION("Analog Devices AD8366 VGA");
214MODULE_LICENSE("GPL v2"); 214MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/chemical/bme680.h b/drivers/iio/chemical/bme680.h
index e049323f209a..0ae89b87e2d6 100644
--- a/drivers/iio/chemical/bme680.h
+++ b/drivers/iio/chemical/bme680.h
@@ -4,10 +4,10 @@
4 4
5#define BME680_REG_CHIP_I2C_ID 0xD0 5#define BME680_REG_CHIP_I2C_ID 0xD0
6#define BME680_REG_CHIP_SPI_ID 0x50 6#define BME680_REG_CHIP_SPI_ID 0x50
7#define BME680_CHIP_ID_VAL 0x61 7#define BME680_CHIP_ID_VAL 0x61
8#define BME680_REG_SOFT_RESET_I2C 0xE0 8#define BME680_REG_SOFT_RESET_I2C 0xE0
9#define BME680_REG_SOFT_RESET_SPI 0x60 9#define BME680_REG_SOFT_RESET_SPI 0x60
10#define BME680_CMD_SOFTRESET 0xB6 10#define BME680_CMD_SOFTRESET 0xB6
11#define BME680_REG_STATUS 0x73 11#define BME680_REG_STATUS 0x73
12#define BME680_SPI_MEM_PAGE_BIT BIT(4) 12#define BME680_SPI_MEM_PAGE_BIT BIT(4)
13#define BME680_SPI_MEM_PAGE_1_VAL 1 13#define BME680_SPI_MEM_PAGE_1_VAL 1
@@ -18,6 +18,7 @@
18#define BME680_REG_GAS_MSB 0x2A 18#define BME680_REG_GAS_MSB 0x2A
19#define BME680_REG_GAS_R_LSB 0x2B 19#define BME680_REG_GAS_R_LSB 0x2B
20#define BME680_GAS_STAB_BIT BIT(4) 20#define BME680_GAS_STAB_BIT BIT(4)
21#define BME680_GAS_RANGE_MASK GENMASK(3, 0)
21 22
22#define BME680_REG_CTRL_HUMIDITY 0x72 23#define BME680_REG_CTRL_HUMIDITY 0x72
23#define BME680_OSRS_HUMIDITY_MASK GENMASK(2, 0) 24#define BME680_OSRS_HUMIDITY_MASK GENMASK(2, 0)
@@ -26,9 +27,8 @@
26#define BME680_OSRS_TEMP_MASK GENMASK(7, 5) 27#define BME680_OSRS_TEMP_MASK GENMASK(7, 5)
27#define BME680_OSRS_PRESS_MASK GENMASK(4, 2) 28#define BME680_OSRS_PRESS_MASK GENMASK(4, 2)
28#define BME680_MODE_MASK GENMASK(1, 0) 29#define BME680_MODE_MASK GENMASK(1, 0)
29 30#define BME680_MODE_FORCED 1
30#define BME680_MODE_FORCED 1 31#define BME680_MODE_SLEEP 0
31#define BME680_MODE_SLEEP 0
32 32
33#define BME680_REG_CONFIG 0x75 33#define BME680_REG_CONFIG 0x75
34#define BME680_FILTER_MASK GENMASK(4, 2) 34#define BME680_FILTER_MASK GENMASK(4, 2)
@@ -39,24 +39,21 @@
39 39
40#define BME680_MAX_OVERFLOW_VAL 0x40000000 40#define BME680_MAX_OVERFLOW_VAL 0x40000000
41#define BME680_HUM_REG_SHIFT_VAL 4 41#define BME680_HUM_REG_SHIFT_VAL 4
42#define BME680_BIT_H1_DATA_MSK 0x0F 42#define BME680_BIT_H1_DATA_MASK GENMASK(3, 0)
43 43
44#define BME680_REG_RES_HEAT_RANGE 0x02 44#define BME680_REG_RES_HEAT_RANGE 0x02
45#define BME680_RHRANGE_MSK 0x30 45#define BME680_RHRANGE_MASK GENMASK(5, 4)
46#define BME680_REG_RES_HEAT_VAL 0x00 46#define BME680_REG_RES_HEAT_VAL 0x00
47#define BME680_REG_RANGE_SW_ERR 0x04 47#define BME680_REG_RANGE_SW_ERR 0x04
48#define BME680_RSERROR_MSK 0xF0 48#define BME680_RSERROR_MASK GENMASK(7, 4)
49#define BME680_REG_RES_HEAT_0 0x5A 49#define BME680_REG_RES_HEAT_0 0x5A
50#define BME680_REG_GAS_WAIT_0 0x64 50#define BME680_REG_GAS_WAIT_0 0x64
51#define BME680_GAS_RANGE_MASK 0x0F
52#define BME680_ADC_GAS_RES_SHIFT 6 51#define BME680_ADC_GAS_RES_SHIFT 6
53#define BME680_AMB_TEMP 25 52#define BME680_AMB_TEMP 25
54 53
55#define BME680_REG_CTRL_GAS_1 0x71 54#define BME680_REG_CTRL_GAS_1 0x71
56#define BME680_RUN_GAS_MASK BIT(4) 55#define BME680_RUN_GAS_MASK BIT(4)
57#define BME680_NB_CONV_MASK GENMASK(3, 0) 56#define BME680_NB_CONV_MASK GENMASK(3, 0)
58#define BME680_RUN_GAS_EN_BIT BIT(4)
59#define BME680_NB_CONV_0_VAL 0
60 57
61#define BME680_REG_MEAS_STAT_0 0x1D 58#define BME680_REG_MEAS_STAT_0 0x1D
62#define BME680_GAS_MEAS_BIT BIT(6) 59#define BME680_GAS_MEAS_BIT BIT(6)
diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c
index 7d9bb62baa3f..70c1fe4366f4 100644
--- a/drivers/iio/chemical/bme680_core.c
+++ b/drivers/iio/chemical/bme680_core.c
@@ -91,8 +91,6 @@ static const struct iio_chan_spec bme680_channels[] = {
91 }, 91 },
92}; 92};
93 93
94static const int bme680_oversampling_avail[] = { 1, 2, 4, 8, 16 };
95
96static int bme680_read_calib(struct bme680_data *data, 94static int bme680_read_calib(struct bme680_data *data,
97 struct bme680_calib *calib) 95 struct bme680_calib *calib)
98{ 96{
@@ -102,16 +100,14 @@ static int bme680_read_calib(struct bme680_data *data,
102 __le16 buf; 100 __le16 buf;
103 101
104 /* Temperature related coefficients */ 102 /* Temperature related coefficients */
105 ret = regmap_bulk_read(data->regmap, BME680_T1_LSB_REG, 103 ret = regmap_bulk_read(data->regmap, BME680_T1_LSB_REG, (u8 *) &buf, 2);
106 (u8 *) &buf, 2);
107 if (ret < 0) { 104 if (ret < 0) {
108 dev_err(dev, "failed to read BME680_T1_LSB_REG\n"); 105 dev_err(dev, "failed to read BME680_T1_LSB_REG\n");
109 return ret; 106 return ret;
110 } 107 }
111 calib->par_t1 = le16_to_cpu(buf); 108 calib->par_t1 = le16_to_cpu(buf);
112 109
113 ret = regmap_bulk_read(data->regmap, BME680_T2_LSB_REG, 110 ret = regmap_bulk_read(data->regmap, BME680_T2_LSB_REG, (u8 *) &buf, 2);
114 (u8 *) &buf, 2);
115 if (ret < 0) { 111 if (ret < 0) {
116 dev_err(dev, "failed to read BME680_T2_LSB_REG\n"); 112 dev_err(dev, "failed to read BME680_T2_LSB_REG\n");
117 return ret; 113 return ret;
@@ -126,16 +122,14 @@ static int bme680_read_calib(struct bme680_data *data,
126 calib->par_t3 = tmp; 122 calib->par_t3 = tmp;
127 123
128 /* Pressure related coefficients */ 124 /* Pressure related coefficients */
129 ret = regmap_bulk_read(data->regmap, BME680_P1_LSB_REG, 125 ret = regmap_bulk_read(data->regmap, BME680_P1_LSB_REG, (u8 *) &buf, 2);
130 (u8 *) &buf, 2);
131 if (ret < 0) { 126 if (ret < 0) {
132 dev_err(dev, "failed to read BME680_P1_LSB_REG\n"); 127 dev_err(dev, "failed to read BME680_P1_LSB_REG\n");
133 return ret; 128 return ret;
134 } 129 }
135 calib->par_p1 = le16_to_cpu(buf); 130 calib->par_p1 = le16_to_cpu(buf);
136 131
137 ret = regmap_bulk_read(data->regmap, BME680_P2_LSB_REG, 132 ret = regmap_bulk_read(data->regmap, BME680_P2_LSB_REG, (u8 *) &buf, 2);
138 (u8 *) &buf, 2);
139 if (ret < 0) { 133 if (ret < 0) {
140 dev_err(dev, "failed to read BME680_P2_LSB_REG\n"); 134 dev_err(dev, "failed to read BME680_P2_LSB_REG\n");
141 return ret; 135 return ret;
@@ -149,16 +143,14 @@ static int bme680_read_calib(struct bme680_data *data,
149 } 143 }
150 calib->par_p3 = tmp; 144 calib->par_p3 = tmp;
151 145
152 ret = regmap_bulk_read(data->regmap, BME680_P4_LSB_REG, 146 ret = regmap_bulk_read(data->regmap, BME680_P4_LSB_REG, (u8 *) &buf, 2);
153 (u8 *) &buf, 2);
154 if (ret < 0) { 147 if (ret < 0) {
155 dev_err(dev, "failed to read BME680_P4_LSB_REG\n"); 148 dev_err(dev, "failed to read BME680_P4_LSB_REG\n");
156 return ret; 149 return ret;
157 } 150 }
158 calib->par_p4 = le16_to_cpu(buf); 151 calib->par_p4 = le16_to_cpu(buf);
159 152
160 ret = regmap_bulk_read(data->regmap, BME680_P5_LSB_REG, 153 ret = regmap_bulk_read(data->regmap, BME680_P5_LSB_REG, (u8 *) &buf, 2);
161 (u8 *) &buf, 2);
162 if (ret < 0) { 154 if (ret < 0) {
163 dev_err(dev, "failed to read BME680_P5_LSB_REG\n"); 155 dev_err(dev, "failed to read BME680_P5_LSB_REG\n");
164 return ret; 156 return ret;
@@ -179,16 +171,14 @@ static int bme680_read_calib(struct bme680_data *data,
179 } 171 }
180 calib->par_p7 = tmp; 172 calib->par_p7 = tmp;
181 173
182 ret = regmap_bulk_read(data->regmap, BME680_P8_LSB_REG, 174 ret = regmap_bulk_read(data->regmap, BME680_P8_LSB_REG, (u8 *) &buf, 2);
183 (u8 *) &buf, 2);
184 if (ret < 0) { 175 if (ret < 0) {
185 dev_err(dev, "failed to read BME680_P8_LSB_REG\n"); 176 dev_err(dev, "failed to read BME680_P8_LSB_REG\n");
186 return ret; 177 return ret;
187 } 178 }
188 calib->par_p8 = le16_to_cpu(buf); 179 calib->par_p8 = le16_to_cpu(buf);
189 180
190 ret = regmap_bulk_read(data->regmap, BME680_P9_LSB_REG, 181 ret = regmap_bulk_read(data->regmap, BME680_P9_LSB_REG, (u8 *) &buf, 2);
191 (u8 *) &buf, 2);
192 if (ret < 0) { 182 if (ret < 0) {
193 dev_err(dev, "failed to read BME680_P9_LSB_REG\n"); 183 dev_err(dev, "failed to read BME680_P9_LSB_REG\n");
194 return ret; 184 return ret;
@@ -208,30 +198,26 @@ static int bme680_read_calib(struct bme680_data *data,
208 dev_err(dev, "failed to read BME680_H1_MSB_REG\n"); 198 dev_err(dev, "failed to read BME680_H1_MSB_REG\n");
209 return ret; 199 return ret;
210 } 200 }
211
212 ret = regmap_read(data->regmap, BME680_H1_LSB_REG, &tmp_lsb); 201 ret = regmap_read(data->regmap, BME680_H1_LSB_REG, &tmp_lsb);
213 if (ret < 0) { 202 if (ret < 0) {
214 dev_err(dev, "failed to read BME680_H1_LSB_REG\n"); 203 dev_err(dev, "failed to read BME680_H1_LSB_REG\n");
215 return ret; 204 return ret;
216 } 205 }
217
218 calib->par_h1 = (tmp_msb << BME680_HUM_REG_SHIFT_VAL) | 206 calib->par_h1 = (tmp_msb << BME680_HUM_REG_SHIFT_VAL) |
219 (tmp_lsb & BME680_BIT_H1_DATA_MSK); 207 (tmp_lsb & BME680_BIT_H1_DATA_MASK);
220 208
221 ret = regmap_read(data->regmap, BME680_H2_MSB_REG, &tmp_msb); 209 ret = regmap_read(data->regmap, BME680_H2_MSB_REG, &tmp_msb);
222 if (ret < 0) { 210 if (ret < 0) {
223 dev_err(dev, "failed to read BME680_H2_MSB_REG\n"); 211 dev_err(dev, "failed to read BME680_H2_MSB_REG\n");
224 return ret; 212 return ret;
225 } 213 }
226
227 ret = regmap_read(data->regmap, BME680_H2_LSB_REG, &tmp_lsb); 214 ret = regmap_read(data->regmap, BME680_H2_LSB_REG, &tmp_lsb);
228 if (ret < 0) { 215 if (ret < 0) {
229 dev_err(dev, "failed to read BME680_H2_LSB_REG\n"); 216 dev_err(dev, "failed to read BME680_H2_LSB_REG\n");
230 return ret; 217 return ret;
231 } 218 }
232
233 calib->par_h2 = (tmp_msb << BME680_HUM_REG_SHIFT_VAL) | 219 calib->par_h2 = (tmp_msb << BME680_HUM_REG_SHIFT_VAL) |
234 (tmp_lsb >> BME680_HUM_REG_SHIFT_VAL); 220 (tmp_lsb >> BME680_HUM_REG_SHIFT_VAL);
235 221
236 ret = regmap_read(data->regmap, BME680_H3_REG, &tmp); 222 ret = regmap_read(data->regmap, BME680_H3_REG, &tmp);
237 if (ret < 0) { 223 if (ret < 0) {
@@ -276,8 +262,8 @@ static int bme680_read_calib(struct bme680_data *data,
276 } 262 }
277 calib->par_gh1 = tmp; 263 calib->par_gh1 = tmp;
278 264
279 ret = regmap_bulk_read(data->regmap, BME680_GH2_LSB_REG, 265 ret = regmap_bulk_read(data->regmap, BME680_GH2_LSB_REG, (u8 *) &buf,
280 (u8 *) &buf, 2); 266 2);
281 if (ret < 0) { 267 if (ret < 0) {
282 dev_err(dev, "failed to read BME680_GH2_LSB_REG\n"); 268 dev_err(dev, "failed to read BME680_GH2_LSB_REG\n");
283 return ret; 269 return ret;
@@ -297,7 +283,7 @@ static int bme680_read_calib(struct bme680_data *data,
297 dev_err(dev, "failed to read resistance heat range\n"); 283 dev_err(dev, "failed to read resistance heat range\n");
298 return ret; 284 return ret;
299 } 285 }
300 calib->res_heat_range = (tmp & BME680_RHRANGE_MSK) / 16; 286 calib->res_heat_range = FIELD_GET(BME680_RHRANGE_MASK, tmp);
301 287
302 ret = regmap_read(data->regmap, BME680_REG_RES_HEAT_VAL, &tmp); 288 ret = regmap_read(data->regmap, BME680_REG_RES_HEAT_VAL, &tmp);
303 if (ret < 0) { 289 if (ret < 0) {
@@ -311,7 +297,7 @@ static int bme680_read_calib(struct bme680_data *data,
311 dev_err(dev, "failed to read range software error\n"); 297 dev_err(dev, "failed to read range software error\n");
312 return ret; 298 return ret;
313 } 299 }
314 calib->range_sw_err = (tmp & BME680_RSERROR_MSK) / 16; 300 calib->range_sw_err = FIELD_GET(BME680_RSERROR_MASK, tmp);
315 301
316 return 0; 302 return 0;
317} 303}
@@ -408,10 +394,7 @@ static u32 bme680_compensate_humid(struct bme680_data *data,
408 var6 = (var4 * var5) >> 1; 394 var6 = (var4 * var5) >> 1;
409 calc_hum = (((var3 + var6) >> 10) * 1000) >> 12; 395 calc_hum = (((var3 + var6) >> 10) * 1000) >> 12;
410 396
411 if (calc_hum > 100000) /* Cap at 100%rH */ 397 calc_hum = clamp(calc_hum, 0, 100000); /* clamp between 0-100 %rH */
412 calc_hum = 100000;
413 else if (calc_hum < 0)
414 calc_hum = 0;
415 398
416 return calc_hum; 399 return calc_hum;
417} 400}
@@ -518,12 +501,20 @@ static int bme680_set_mode(struct bme680_data *data, bool mode)
518 return ret; 501 return ret;
519} 502}
520 503
504static u8 bme680_oversampling_to_reg(u8 val)
505{
506 return ilog2(val) + 1;
507}
508
521static int bme680_chip_config(struct bme680_data *data) 509static int bme680_chip_config(struct bme680_data *data)
522{ 510{
523 struct device *dev = regmap_get_device(data->regmap); 511 struct device *dev = regmap_get_device(data->regmap);
524 int ret; 512 int ret;
525 u8 osrs = FIELD_PREP(BME680_OSRS_HUMIDITY_MASK, 513 u8 osrs;
526 data->oversampling_humid + 1); 514
515 osrs = FIELD_PREP(
516 BME680_OSRS_HUMIDITY_MASK,
517 bme680_oversampling_to_reg(data->oversampling_humid));
527 /* 518 /*
528 * Highly recommended to set oversampling of humidity before 519 * Highly recommended to set oversampling of humidity before
529 * temperature/pressure oversampling. 520 * temperature/pressure oversampling.
@@ -544,12 +535,12 @@ static int bme680_chip_config(struct bme680_data *data)
544 return ret; 535 return ret;
545 } 536 }
546 537
547 osrs = FIELD_PREP(BME680_OSRS_TEMP_MASK, data->oversampling_temp + 1) | 538 osrs = FIELD_PREP(BME680_OSRS_TEMP_MASK,
548 FIELD_PREP(BME680_OSRS_PRESS_MASK, data->oversampling_press + 1); 539 bme680_oversampling_to_reg(data->oversampling_temp)) |
549 540 FIELD_PREP(BME680_OSRS_PRESS_MASK,
541 bme680_oversampling_to_reg(data->oversampling_press));
550 ret = regmap_write_bits(data->regmap, BME680_REG_CTRL_MEAS, 542 ret = regmap_write_bits(data->regmap, BME680_REG_CTRL_MEAS,
551 BME680_OSRS_TEMP_MASK | 543 BME680_OSRS_TEMP_MASK | BME680_OSRS_PRESS_MASK,
552 BME680_OSRS_PRESS_MASK,
553 osrs); 544 osrs);
554 if (ret < 0) 545 if (ret < 0)
555 dev_err(dev, "failed to write ctrl_meas register\n"); 546 dev_err(dev, "failed to write ctrl_meas register\n");
@@ -577,14 +568,15 @@ static int bme680_gas_config(struct bme680_data *data)
577 /* set target heating duration */ 568 /* set target heating duration */
578 ret = regmap_write(data->regmap, BME680_REG_GAS_WAIT_0, heatr_dur); 569 ret = regmap_write(data->regmap, BME680_REG_GAS_WAIT_0, heatr_dur);
579 if (ret < 0) { 570 if (ret < 0) {
580 dev_err(dev, "failted to write gas_wait_0 register\n"); 571 dev_err(dev, "failed to write gas_wait_0 register\n");
581 return ret; 572 return ret;
582 } 573 }
583 574
584 /* Selecting the runGas and NB conversion settings for the sensor */ 575 /* Enable the gas sensor and select heater profile set-point 0 */
585 ret = regmap_update_bits(data->regmap, BME680_REG_CTRL_GAS_1, 576 ret = regmap_update_bits(data->regmap, BME680_REG_CTRL_GAS_1,
586 BME680_RUN_GAS_MASK | BME680_NB_CONV_MASK, 577 BME680_RUN_GAS_MASK | BME680_NB_CONV_MASK,
587 BME680_RUN_GAS_EN_BIT | BME680_NB_CONV_0_VAL); 578 FIELD_PREP(BME680_RUN_GAS_MASK, 1) |
579 FIELD_PREP(BME680_NB_CONV_MASK, 0));
588 if (ret < 0) 580 if (ret < 0)
589 dev_err(dev, "failed to write ctrl_gas_1 register\n"); 581 dev_err(dev, "failed to write ctrl_gas_1 register\n");
590 582
@@ -782,13 +774,13 @@ static int bme680_read_raw(struct iio_dev *indio_dev,
782 case IIO_CHAN_INFO_OVERSAMPLING_RATIO: 774 case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
783 switch (chan->type) { 775 switch (chan->type) {
784 case IIO_TEMP: 776 case IIO_TEMP:
785 *val = 1 << data->oversampling_temp; 777 *val = data->oversampling_temp;
786 return IIO_VAL_INT; 778 return IIO_VAL_INT;
787 case IIO_PRESSURE: 779 case IIO_PRESSURE:
788 *val = 1 << data->oversampling_press; 780 *val = data->oversampling_press;
789 return IIO_VAL_INT; 781 return IIO_VAL_INT;
790 case IIO_HUMIDITYRELATIVE: 782 case IIO_HUMIDITYRELATIVE:
791 *val = 1 << data->oversampling_humid; 783 *val = data->oversampling_humid;
792 return IIO_VAL_INT; 784 return IIO_VAL_INT;
793 default: 785 default:
794 return -EINVAL; 786 return -EINVAL;
@@ -798,52 +790,9 @@ static int bme680_read_raw(struct iio_dev *indio_dev,
798 } 790 }
799} 791}
800 792
801static int bme680_write_oversampling_ratio_temp(struct bme680_data *data, 793static bool bme680_is_valid_oversampling(int rate)
802 int val)
803{
804 int i;
805
806 for (i = 0; i < ARRAY_SIZE(bme680_oversampling_avail); i++) {
807 if (bme680_oversampling_avail[i] == val) {
808 data->oversampling_temp = ilog2(val);
809
810 return bme680_chip_config(data);
811 }
812 }
813
814 return -EINVAL;
815}
816
817static int bme680_write_oversampling_ratio_press(struct bme680_data *data,
818 int val)
819{
820 int i;
821
822 for (i = 0; i < ARRAY_SIZE(bme680_oversampling_avail); i++) {
823 if (bme680_oversampling_avail[i] == val) {
824 data->oversampling_press = ilog2(val);
825
826 return bme680_chip_config(data);
827 }
828 }
829
830 return -EINVAL;
831}
832
833static int bme680_write_oversampling_ratio_humid(struct bme680_data *data,
834 int val)
835{ 794{
836 int i; 795 return (rate > 0 && rate <= 16 && is_power_of_2(rate));
837
838 for (i = 0; i < ARRAY_SIZE(bme680_oversampling_avail); i++) {
839 if (bme680_oversampling_avail[i] == val) {
840 data->oversampling_humid = ilog2(val);
841
842 return bme680_chip_config(data);
843 }
844 }
845
846 return -EINVAL;
847} 796}
848 797
849static int bme680_write_raw(struct iio_dev *indio_dev, 798static int bme680_write_raw(struct iio_dev *indio_dev,
@@ -852,18 +801,31 @@ static int bme680_write_raw(struct iio_dev *indio_dev,
852{ 801{
853 struct bme680_data *data = iio_priv(indio_dev); 802 struct bme680_data *data = iio_priv(indio_dev);
854 803
804 if (val2 != 0)
805 return -EINVAL;
806
855 switch (mask) { 807 switch (mask) {
856 case IIO_CHAN_INFO_OVERSAMPLING_RATIO: 808 case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
809 {
810 if (!bme680_is_valid_oversampling(val))
811 return -EINVAL;
812
857 switch (chan->type) { 813 switch (chan->type) {
858 case IIO_TEMP: 814 case IIO_TEMP:
859 return bme680_write_oversampling_ratio_temp(data, val); 815 data->oversampling_temp = val;
816 break;
860 case IIO_PRESSURE: 817 case IIO_PRESSURE:
861 return bme680_write_oversampling_ratio_press(data, val); 818 data->oversampling_press = val;
819 break;
862 case IIO_HUMIDITYRELATIVE: 820 case IIO_HUMIDITYRELATIVE:
863 return bme680_write_oversampling_ratio_humid(data, val); 821 data->oversampling_humid = val;
822 break;
864 default: 823 default:
865 return -EINVAL; 824 return -EINVAL;
866 } 825 }
826
827 return bme680_chip_config(data);
828 }
867 default: 829 default:
868 return -EINVAL; 830 return -EINVAL;
869 } 831 }
@@ -925,9 +887,9 @@ int bme680_core_probe(struct device *dev, struct regmap *regmap,
925 indio_dev->modes = INDIO_DIRECT_MODE; 887 indio_dev->modes = INDIO_DIRECT_MODE;
926 888
927 /* default values for the sensor */ 889 /* default values for the sensor */
928 data->oversampling_humid = ilog2(2); /* 2X oversampling rate */ 890 data->oversampling_humid = 2; /* 2X oversampling rate */
929 data->oversampling_press = ilog2(4); /* 4X oversampling rate */ 891 data->oversampling_press = 4; /* 4X oversampling rate */
930 data->oversampling_temp = ilog2(8); /* 8X oversampling rate */ 892 data->oversampling_temp = 8; /* 8X oversampling rate */
931 data->heater_temp = 320; /* degree Celsius */ 893 data->heater_temp = 320; /* degree Celsius */
932 data->heater_dur = 150; /* milliseconds */ 894 data->heater_dur = 150; /* milliseconds */
933 895
diff --git a/drivers/iio/dac/Kconfig b/drivers/iio/dac/Kconfig
index 80beb64e9e0c..bb2057fd1b6f 100644
--- a/drivers/iio/dac/Kconfig
+++ b/drivers/iio/dac/Kconfig
@@ -120,6 +120,16 @@ config AD5624R_SPI
120 Say yes here to build support for Analog Devices AD5624R, AD5644R and 120 Say yes here to build support for Analog Devices AD5624R, AD5644R and
121 AD5664R converters (DAC). This driver uses the common SPI interface. 121 AD5664R converters (DAC). This driver uses the common SPI interface.
122 122
123config LTC1660
124 tristate "Linear Technology LTC1660/LTC1665 DAC SPI driver"
125 depends on SPI
126 help
127 Say yes here to build support for Linear Technology
128 LTC1660 and LTC1665 Digital to Analog Converters.
129
130 To compile this driver as a module, choose M here: the
131 module will be called ltc1660.
132
123config LTC2632 133config LTC2632
124 tristate "Linear Technology LTC2632-12/10/8 DAC spi driver" 134 tristate "Linear Technology LTC2632-12/10/8 DAC spi driver"
125 depends on SPI 135 depends on SPI
diff --git a/drivers/iio/dac/Makefile b/drivers/iio/dac/Makefile
index a1b37cf99441..2ac93cc4a389 100644
--- a/drivers/iio/dac/Makefile
+++ b/drivers/iio/dac/Makefile
@@ -29,6 +29,7 @@ obj-$(CONFIG_CIO_DAC) += cio-dac.o
29obj-$(CONFIG_DPOT_DAC) += dpot-dac.o 29obj-$(CONFIG_DPOT_DAC) += dpot-dac.o
30obj-$(CONFIG_DS4424) += ds4424.o 30obj-$(CONFIG_DS4424) += ds4424.o
31obj-$(CONFIG_LPC18XX_DAC) += lpc18xx_dac.o 31obj-$(CONFIG_LPC18XX_DAC) += lpc18xx_dac.o
32obj-$(CONFIG_LTC1660) += ltc1660.o
32obj-$(CONFIG_LTC2632) += ltc2632.o 33obj-$(CONFIG_LTC2632) += ltc2632.o
33obj-$(CONFIG_M62332) += m62332.o 34obj-$(CONFIG_M62332) += m62332.o
34obj-$(CONFIG_MAX517) += max517.o 35obj-$(CONFIG_MAX517) += max517.o
diff --git a/drivers/iio/dac/ad5064.c b/drivers/iio/dac/ad5064.c
index bf4fc40ec84d..2f98cb2a3b96 100644
--- a/drivers/iio/dac/ad5064.c
+++ b/drivers/iio/dac/ad5064.c
@@ -808,6 +808,40 @@ static int ad5064_set_config(struct ad5064_state *st, unsigned int val)
808 return ad5064_write(st, cmd, 0, val, 0); 808 return ad5064_write(st, cmd, 0, val, 0);
809} 809}
810 810
811static int ad5064_request_vref(struct ad5064_state *st, struct device *dev)
812{
813 unsigned int i;
814 int ret;
815
816 for (i = 0; i < ad5064_num_vref(st); ++i)
817 st->vref_reg[i].supply = ad5064_vref_name(st, i);
818
819 if (!st->chip_info->internal_vref)
820 return devm_regulator_bulk_get(dev, ad5064_num_vref(st),
821 st->vref_reg);
822
823 /*
824 * This assumes that when the regulator has an internal VREF
825 * there is only one external VREF connection, which is
826 * currently the case for all supported devices.
827 */
828 st->vref_reg[0].consumer = devm_regulator_get_optional(dev, "vref");
829 if (!IS_ERR(st->vref_reg[0].consumer))
830 return 0;
831
832 ret = PTR_ERR(st->vref_reg[0].consumer);
833 if (ret != -ENODEV)
834 return ret;
835
836 /* If no external regulator was supplied use the internal VREF */
837 st->use_internal_vref = true;
838 ret = ad5064_set_config(st, AD5064_CONFIG_INT_VREF_ENABLE);
839 if (ret)
840 dev_err(dev, "Failed to enable internal vref: %d\n", ret);
841
842 return ret;
843}
844
811static int ad5064_probe(struct device *dev, enum ad5064_type type, 845static int ad5064_probe(struct device *dev, enum ad5064_type type,
812 const char *name, ad5064_write_func write) 846 const char *name, ad5064_write_func write)
813{ 847{
@@ -828,22 +862,11 @@ static int ad5064_probe(struct device *dev, enum ad5064_type type,
828 st->dev = dev; 862 st->dev = dev;
829 st->write = write; 863 st->write = write;
830 864
831 for (i = 0; i < ad5064_num_vref(st); ++i) 865 ret = ad5064_request_vref(st, dev);
832 st->vref_reg[i].supply = ad5064_vref_name(st, i); 866 if (ret)
867 return ret;
833 868
834 ret = devm_regulator_bulk_get(dev, ad5064_num_vref(st), 869 if (!st->use_internal_vref) {
835 st->vref_reg);
836 if (ret) {
837 if (!st->chip_info->internal_vref)
838 return ret;
839 st->use_internal_vref = true;
840 ret = ad5064_set_config(st, AD5064_CONFIG_INT_VREF_ENABLE);
841 if (ret) {
842 dev_err(dev, "Failed to enable internal vref: %d\n",
843 ret);
844 return ret;
845 }
846 } else {
847 ret = regulator_bulk_enable(ad5064_num_vref(st), st->vref_reg); 870 ret = regulator_bulk_enable(ad5064_num_vref(st), st->vref_reg);
848 if (ret) 871 if (ret)
849 return ret; 872 return ret;
diff --git a/drivers/iio/dac/ad5446.c b/drivers/iio/dac/ad5446.c
index fd26a4272fc5..c3426708b6b5 100644
--- a/drivers/iio/dac/ad5446.c
+++ b/drivers/iio/dac/ad5446.c
@@ -628,6 +628,6 @@ static void __exit ad5446_exit(void)
628} 628}
629module_exit(ad5446_exit); 629module_exit(ad5446_exit);
630 630
631MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 631MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
632MODULE_DESCRIPTION("Analog Devices AD5444/AD5446 DAC"); 632MODULE_DESCRIPTION("Analog Devices AD5444/AD5446 DAC");
633MODULE_LICENSE("GPL v2"); 633MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/dac/ad5504.c b/drivers/iio/dac/ad5504.c
index d9037ea59168..0ae23a268017 100644
--- a/drivers/iio/dac/ad5504.c
+++ b/drivers/iio/dac/ad5504.c
@@ -369,6 +369,6 @@ static struct spi_driver ad5504_driver = {
369}; 369};
370module_spi_driver(ad5504_driver); 370module_spi_driver(ad5504_driver);
371 371
372MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 372MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
373MODULE_DESCRIPTION("Analog Devices AD5501/AD5501 DAC"); 373MODULE_DESCRIPTION("Analog Devices AD5501/AD5501 DAC");
374MODULE_LICENSE("GPL v2"); 374MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
index 2ddbfc3fdbae..0e134b13967a 100644
--- a/drivers/iio/dac/ad5686.c
+++ b/drivers/iio/dac/ad5686.c
@@ -470,6 +470,6 @@ int ad5686_remove(struct device *dev)
470} 470}
471EXPORT_SYMBOL_GPL(ad5686_remove); 471EXPORT_SYMBOL_GPL(ad5686_remove);
472 472
473MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 473MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
474MODULE_DESCRIPTION("Analog Devices AD5686/85/84 DAC"); 474MODULE_DESCRIPTION("Analog Devices AD5686/85/84 DAC");
475MODULE_LICENSE("GPL v2"); 475MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/dac/ad5758.c b/drivers/iio/dac/ad5758.c
index bd36333257af..ef41f12bf262 100644
--- a/drivers/iio/dac/ad5758.c
+++ b/drivers/iio/dac/ad5758.c
@@ -12,6 +12,7 @@
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/property.h> 13#include <linux/property.h>
14#include <linux/spi/spi.h> 14#include <linux/spi/spi.h>
15#include <linux/gpio/consumer.h>
15 16
16#include <linux/iio/iio.h> 17#include <linux/iio/iio.h>
17#include <linux/iio/sysfs.h> 18#include <linux/iio/sysfs.h>
@@ -108,6 +109,7 @@ struct ad5758_range {
108struct ad5758_state { 109struct ad5758_state {
109 struct spi_device *spi; 110 struct spi_device *spi;
110 struct mutex lock; 111 struct mutex lock;
112 struct gpio_desc *gpio_reset;
111 struct ad5758_range out_range; 113 struct ad5758_range out_range;
112 unsigned int dc_dc_mode; 114 unsigned int dc_dc_mode;
113 unsigned int dc_dc_ilim; 115 unsigned int dc_dc_ilim;
@@ -474,6 +476,21 @@ static int ad5758_internal_buffers_en(struct ad5758_state *st, bool enable)
474 AD5758_CAL_MEM_UNREFRESHED_MSK); 476 AD5758_CAL_MEM_UNREFRESHED_MSK);
475} 477}
476 478
479static int ad5758_reset(struct ad5758_state *st)
480{
481 if (st->gpio_reset) {
482 gpiod_set_value(st->gpio_reset, 0);
483 usleep_range(100, 1000);
484 gpiod_set_value(st->gpio_reset, 1);
485 usleep_range(100, 1000);
486
487 return 0;
488 } else {
489 /* Perform a software reset */
490 return ad5758_soft_reset(st);
491 }
492}
493
477static int ad5758_reg_access(struct iio_dev *indio_dev, 494static int ad5758_reg_access(struct iio_dev *indio_dev,
478 unsigned int reg, 495 unsigned int reg,
479 unsigned int writeval, 496 unsigned int writeval,
@@ -768,13 +785,18 @@ static int ad5758_init(struct ad5758_state *st)
768{ 785{
769 int regval, ret; 786 int regval, ret;
770 787
788 st->gpio_reset = devm_gpiod_get_optional(&st->spi->dev, "reset",
789 GPIOD_OUT_HIGH);
790 if (IS_ERR(st->gpio_reset))
791 return PTR_ERR(st->gpio_reset);
792
771 /* Disable CRC checks */ 793 /* Disable CRC checks */
772 ret = ad5758_crc_disable(st); 794 ret = ad5758_crc_disable(st);
773 if (ret < 0) 795 if (ret < 0)
774 return ret; 796 return ret;
775 797
776 /* Perform a software reset */ 798 /* Perform a reset */
777 ret = ad5758_soft_reset(st); 799 ret = ad5758_reset(st);
778 if (ret < 0) 800 if (ret < 0)
779 return ret; 801 return ret;
780 802
diff --git a/drivers/iio/dac/ad5791.c b/drivers/iio/dac/ad5791.c
index 7569bf6868c2..84ce5e6ecf3f 100644
--- a/drivers/iio/dac/ad5791.c
+++ b/drivers/iio/dac/ad5791.c
@@ -467,6 +467,6 @@ static struct spi_driver ad5791_driver = {
467}; 467};
468module_spi_driver(ad5791_driver); 468module_spi_driver(ad5791_driver);
469 469
470MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 470MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
471MODULE_DESCRIPTION("Analog Devices AD5760/AD5780/AD5781/AD5790/AD5791 DAC"); 471MODULE_DESCRIPTION("Analog Devices AD5760/AD5780/AD5781/AD5790/AD5791 DAC");
472MODULE_LICENSE("GPL v2"); 472MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/dac/dpot-dac.c b/drivers/iio/dac/dpot-dac.c
index aaa2103d7c2b..a791d0a09d3b 100644
--- a/drivers/iio/dac/dpot-dac.c
+++ b/drivers/iio/dac/dpot-dac.c
@@ -1,13 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * IIO DAC emulation driver using a digital potentiometer 3 * IIO DAC emulation driver using a digital potentiometer
3 * 4 *
4 * Copyright (C) 2016 Axentia Technologies AB 5 * Copyright (C) 2016 Axentia Technologies AB
5 * 6 *
6 * Author: Peter Rosin <peda@axentia.se> 7 * Author: Peter Rosin <peda@axentia.se>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */ 8 */
12 9
13/* 10/*
diff --git a/drivers/iio/dac/ltc1660.c b/drivers/iio/dac/ltc1660.c
new file mode 100644
index 000000000000..10866838c72a
--- /dev/null
+++ b/drivers/iio/dac/ltc1660.c
@@ -0,0 +1,250 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Driver for Linear Technology LTC1665/LTC1660, 8 channels DAC
4 *
5 * Copyright (C) 2018 Marcus Folkesson <marcus.folkesson@gmail.com>
6 */
7#include <linux/bitops.h>
8#include <linux/iio/iio.h>
9#include <linux/iio/sysfs.h>
10#include <linux/init.h>
11#include <linux/module.h>
12#include <linux/regulator/consumer.h>
13#include <linux/regmap.h>
14#include <linux/spi/spi.h>
15
16#define LTC1660_REG_WAKE 0x0
17#define LTC1660_REG_DAC_A 0x1
18#define LTC1660_REG_DAC_B 0x2
19#define LTC1660_REG_DAC_C 0x3
20#define LTC1660_REG_DAC_D 0x4
21#define LTC1660_REG_DAC_E 0x5
22#define LTC1660_REG_DAC_F 0x6
23#define LTC1660_REG_DAC_G 0x7
24#define LTC1660_REG_DAC_H 0x8
25#define LTC1660_REG_SLEEP 0xe
26
27#define LTC1660_NUM_CHANNELS 8
28
29static const struct regmap_config ltc1660_regmap_config = {
30 .reg_bits = 4,
31 .val_bits = 12,
32};
33
34enum ltc1660_supported_device_ids {
35 ID_LTC1660,
36 ID_LTC1665,
37};
38
39struct ltc1660_priv {
40 struct spi_device *spi;
41 struct regmap *regmap;
42 struct regulator *vref_reg;
43 unsigned int value[LTC1660_NUM_CHANNELS];
44 unsigned int vref_mv;
45};
46
47static int ltc1660_read_raw(struct iio_dev *indio_dev,
48 struct iio_chan_spec const *chan,
49 int *val,
50 int *val2,
51 long mask)
52{
53 struct ltc1660_priv *priv = iio_priv(indio_dev);
54
55 switch (mask) {
56 case IIO_CHAN_INFO_RAW:
57 *val = priv->value[chan->channel];
58 return IIO_VAL_INT;
59 case IIO_CHAN_INFO_SCALE:
60 *val = regulator_get_voltage(priv->vref_reg);
61 if (*val < 0) {
62 dev_err(&priv->spi->dev, "failed to read vref regulator: %d\n",
63 *val);
64 return *val;
65 }
66
67 /* Convert to mV */
68 *val /= 1000;
69 *val2 = chan->scan_type.realbits;
70 return IIO_VAL_FRACTIONAL_LOG2;
71 default:
72 return -EINVAL;
73 }
74}
75
76static int ltc1660_write_raw(struct iio_dev *indio_dev,
77 struct iio_chan_spec const *chan,
78 int val,
79 int val2,
80 long mask)
81{
82 struct ltc1660_priv *priv = iio_priv(indio_dev);
83 int ret;
84
85 switch (mask) {
86 case IIO_CHAN_INFO_RAW:
87 if (val2 != 0)
88 return -EINVAL;
89
90 if (val < 0 || val > GENMASK(chan->scan_type.realbits - 1, 0))
91 return -EINVAL;
92
93 ret = regmap_write(priv->regmap, chan->channel,
94 (val << chan->scan_type.shift));
95 if (!ret)
96 priv->value[chan->channel] = val;
97
98 return ret;
99 default:
100 return -EINVAL;
101 }
102}
103
104#define LTC1660_CHAN(chan, bits) { \
105 .type = IIO_VOLTAGE, \
106 .indexed = 1, \
107 .output = 1, \
108 .channel = chan, \
109 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
110 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
111 .scan_type = { \
112 .sign = 'u', \
113 .realbits = (bits), \
114 .storagebits = 16, \
115 .shift = 12 - (bits), \
116 }, \
117}
118
119#define LTC1660_OCTAL_CHANNELS(bits) { \
120 LTC1660_CHAN(LTC1660_REG_DAC_A, bits), \
121 LTC1660_CHAN(LTC1660_REG_DAC_B, bits), \
122 LTC1660_CHAN(LTC1660_REG_DAC_C, bits), \
123 LTC1660_CHAN(LTC1660_REG_DAC_D, bits), \
124 LTC1660_CHAN(LTC1660_REG_DAC_E, bits), \
125 LTC1660_CHAN(LTC1660_REG_DAC_F, bits), \
126 LTC1660_CHAN(LTC1660_REG_DAC_G, bits), \
127 LTC1660_CHAN(LTC1660_REG_DAC_H, bits), \
128}
129
130static const struct iio_chan_spec ltc1660_channels[][LTC1660_NUM_CHANNELS] = {
131 [ID_LTC1660] = LTC1660_OCTAL_CHANNELS(10),
132 [ID_LTC1665] = LTC1660_OCTAL_CHANNELS(8),
133};
134
135static const struct iio_info ltc1660_info = {
136 .read_raw = &ltc1660_read_raw,
137 .write_raw = &ltc1660_write_raw,
138};
139
140static int __maybe_unused ltc1660_suspend(struct device *dev)
141{
142 struct ltc1660_priv *priv = iio_priv(spi_get_drvdata(
143 to_spi_device(dev)));
144 return regmap_write(priv->regmap, LTC1660_REG_SLEEP, 0x00);
145}
146
147static int __maybe_unused ltc1660_resume(struct device *dev)
148{
149 struct ltc1660_priv *priv = iio_priv(spi_get_drvdata(
150 to_spi_device(dev)));
151 return regmap_write(priv->regmap, LTC1660_REG_WAKE, 0x00);
152}
153static SIMPLE_DEV_PM_OPS(ltc1660_pm_ops, ltc1660_suspend, ltc1660_resume);
154
155static int ltc1660_probe(struct spi_device *spi)
156{
157 struct iio_dev *indio_dev;
158 struct ltc1660_priv *priv;
159 const struct spi_device_id *id = spi_get_device_id(spi);
160 int ret;
161
162 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*priv));
163 if (indio_dev == NULL)
164 return -ENOMEM;
165
166 priv = iio_priv(indio_dev);
167 priv->regmap = devm_regmap_init_spi(spi, &ltc1660_regmap_config);
168 if (IS_ERR(priv->regmap)) {
169 dev_err(&spi->dev, "failed to register spi regmap %ld\n",
170 PTR_ERR(priv->regmap));
171 return PTR_ERR(priv->regmap);
172 }
173
174 priv->vref_reg = devm_regulator_get(&spi->dev, "vref");
175 if (IS_ERR(priv->vref_reg)) {
176 dev_err(&spi->dev, "vref regulator not specified\n");
177 return PTR_ERR(priv->vref_reg);
178 }
179
180 ret = regulator_enable(priv->vref_reg);
181 if (ret) {
182 dev_err(&spi->dev, "failed to enable vref regulator: %d\n",
183 ret);
184 return ret;
185 }
186
187 priv->spi = spi;
188 spi_set_drvdata(spi, indio_dev);
189 indio_dev->dev.parent = &spi->dev;
190 indio_dev->info = &ltc1660_info;
191 indio_dev->modes = INDIO_DIRECT_MODE;
192 indio_dev->channels = ltc1660_channels[id->driver_data];
193 indio_dev->num_channels = LTC1660_NUM_CHANNELS;
194 indio_dev->name = id->name;
195
196 ret = iio_device_register(indio_dev);
197 if (ret) {
198 dev_err(&spi->dev, "failed to register iio device: %d\n",
199 ret);
200 goto error_disable_reg;
201 }
202
203 return 0;
204
205error_disable_reg:
206 regulator_disable(priv->vref_reg);
207
208 return ret;
209}
210
211static int ltc1660_remove(struct spi_device *spi)
212{
213 struct iio_dev *indio_dev = spi_get_drvdata(spi);
214 struct ltc1660_priv *priv = iio_priv(indio_dev);
215
216 iio_device_unregister(indio_dev);
217 regulator_disable(priv->vref_reg);
218
219 return 0;
220}
221
222static const struct of_device_id ltc1660_dt_ids[] = {
223 { .compatible = "lltc,ltc1660", .data = (void *)ID_LTC1660 },
224 { .compatible = "lltc,ltc1665", .data = (void *)ID_LTC1665 },
225 { /* sentinel */ }
226};
227MODULE_DEVICE_TABLE(of, ltc1660_dt_ids);
228
229static const struct spi_device_id ltc1660_id[] = {
230 {"ltc1660", ID_LTC1660},
231 {"ltc1665", ID_LTC1665},
232 { /* sentinel */ }
233};
234MODULE_DEVICE_TABLE(spi, ltc1660_id);
235
236static struct spi_driver ltc1660_driver = {
237 .driver = {
238 .name = "ltc1660",
239 .of_match_table = ltc1660_dt_ids,
240 .pm = &ltc1660_pm_ops,
241 },
242 .probe = ltc1660_probe,
243 .remove = ltc1660_remove,
244 .id_table = ltc1660_id,
245};
246module_spi_driver(ltc1660_driver);
247
248MODULE_AUTHOR("Marcus Folkesson <marcus.folkesson@gmail.com>");
249MODULE_DESCRIPTION("Linear Technology LTC1660/LTC1665 DAC");
250MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/dac/max517.c b/drivers/iio/dac/max517.c
index 1d853247a205..451d10e323cf 100644
--- a/drivers/iio/dac/max517.c
+++ b/drivers/iio/dac/max517.c
@@ -113,15 +113,14 @@ static int max517_write_raw(struct iio_dev *indio_dev,
113 return ret; 113 return ret;
114} 114}
115 115
116#ifdef CONFIG_PM_SLEEP 116static int __maybe_unused max517_suspend(struct device *dev)
117static int max517_suspend(struct device *dev)
118{ 117{
119 u8 outbuf = COMMAND_PD; 118 u8 outbuf = COMMAND_PD;
120 119
121 return i2c_master_send(to_i2c_client(dev), &outbuf, 1); 120 return i2c_master_send(to_i2c_client(dev), &outbuf, 1);
122} 121}
123 122
124static int max517_resume(struct device *dev) 123static int __maybe_unused max517_resume(struct device *dev)
125{ 124{
126 u8 outbuf = 0; 125 u8 outbuf = 0;
127 126
@@ -129,10 +128,6 @@ static int max517_resume(struct device *dev)
129} 128}
130 129
131static SIMPLE_DEV_PM_OPS(max517_pm_ops, max517_suspend, max517_resume); 130static SIMPLE_DEV_PM_OPS(max517_pm_ops, max517_suspend, max517_resume);
132#define MAX517_PM_OPS (&max517_pm_ops)
133#else
134#define MAX517_PM_OPS NULL
135#endif
136 131
137static const struct iio_info max517_info = { 132static const struct iio_info max517_info = {
138 .read_raw = max517_read_raw, 133 .read_raw = max517_read_raw,
@@ -229,7 +224,7 @@ MODULE_DEVICE_TABLE(i2c, max517_id);
229static struct i2c_driver max517_driver = { 224static struct i2c_driver max517_driver = {
230 .driver = { 225 .driver = {
231 .name = MAX517_DRV_NAME, 226 .name = MAX517_DRV_NAME,
232 .pm = MAX517_PM_OPS, 227 .pm = &max517_pm_ops,
233 }, 228 },
234 .probe = max517_probe, 229 .probe = max517_probe,
235 .remove = max517_remove, 230 .remove = max517_remove,
diff --git a/drivers/iio/dac/max5821.c b/drivers/iio/dac/max5821.c
index d0ecc1fdd8fc..f0cf6903dcd2 100644
--- a/drivers/iio/dac/max5821.c
+++ b/drivers/iio/dac/max5821.c
@@ -270,8 +270,7 @@ static int max5821_write_raw(struct iio_dev *indio_dev,
270 } 270 }
271} 271}
272 272
273#ifdef CONFIG_PM_SLEEP 273static int __maybe_unused max5821_suspend(struct device *dev)
274static int max5821_suspend(struct device *dev)
275{ 274{
276 u8 outbuf[2] = { MAX5821_EXTENDED_COMMAND_MODE, 275 u8 outbuf[2] = { MAX5821_EXTENDED_COMMAND_MODE,
277 MAX5821_EXTENDED_DAC_A | 276 MAX5821_EXTENDED_DAC_A |
@@ -281,7 +280,7 @@ static int max5821_suspend(struct device *dev)
281 return i2c_master_send(to_i2c_client(dev), outbuf, 2); 280 return i2c_master_send(to_i2c_client(dev), outbuf, 2);
282} 281}
283 282
284static int max5821_resume(struct device *dev) 283static int __maybe_unused max5821_resume(struct device *dev)
285{ 284{
286 u8 outbuf[2] = { MAX5821_EXTENDED_COMMAND_MODE, 285 u8 outbuf[2] = { MAX5821_EXTENDED_COMMAND_MODE,
287 MAX5821_EXTENDED_DAC_A | 286 MAX5821_EXTENDED_DAC_A |
@@ -292,10 +291,6 @@ static int max5821_resume(struct device *dev)
292} 291}
293 292
294static SIMPLE_DEV_PM_OPS(max5821_pm_ops, max5821_suspend, max5821_resume); 293static SIMPLE_DEV_PM_OPS(max5821_pm_ops, max5821_suspend, max5821_resume);
295#define MAX5821_PM_OPS (&max5821_pm_ops)
296#else
297#define MAX5821_PM_OPS NULL
298#endif /* CONFIG_PM_SLEEP */
299 294
300static const struct iio_info max5821_info = { 295static const struct iio_info max5821_info = {
301 .read_raw = max5821_read_raw, 296 .read_raw = max5821_read_raw,
@@ -392,7 +387,7 @@ static struct i2c_driver max5821_driver = {
392 .driver = { 387 .driver = {
393 .name = "max5821", 388 .name = "max5821",
394 .of_match_table = max5821_of_match, 389 .of_match_table = max5821_of_match,
395 .pm = MAX5821_PM_OPS, 390 .pm = &max5821_pm_ops,
396 }, 391 },
397 .probe = max5821_probe, 392 .probe = max5821_probe,
398 .remove = max5821_remove, 393 .remove = max5821_remove,
diff --git a/drivers/iio/dac/mcp4725.c b/drivers/iio/dac/mcp4725.c
index 8b5aad4c32d9..6d71fd905e29 100644
--- a/drivers/iio/dac/mcp4725.c
+++ b/drivers/iio/dac/mcp4725.c
@@ -45,7 +45,7 @@ struct mcp4725_data {
45 struct regulator *vref_reg; 45 struct regulator *vref_reg;
46}; 46};
47 47
48static int mcp4725_suspend(struct device *dev) 48static int __maybe_unused mcp4725_suspend(struct device *dev)
49{ 49{
50 struct mcp4725_data *data = iio_priv(i2c_get_clientdata( 50 struct mcp4725_data *data = iio_priv(i2c_get_clientdata(
51 to_i2c_client(dev))); 51 to_i2c_client(dev)));
@@ -58,7 +58,7 @@ static int mcp4725_suspend(struct device *dev)
58 return i2c_master_send(data->client, outbuf, 2); 58 return i2c_master_send(data->client, outbuf, 2);
59} 59}
60 60
61static int mcp4725_resume(struct device *dev) 61static int __maybe_unused mcp4725_resume(struct device *dev)
62{ 62{
63 struct mcp4725_data *data = iio_priv(i2c_get_clientdata( 63 struct mcp4725_data *data = iio_priv(i2c_get_clientdata(
64 to_i2c_client(dev))); 64 to_i2c_client(dev)));
@@ -71,13 +71,7 @@ static int mcp4725_resume(struct device *dev)
71 71
72 return i2c_master_send(data->client, outbuf, 2); 72 return i2c_master_send(data->client, outbuf, 2);
73} 73}
74
75#ifdef CONFIG_PM_SLEEP
76static SIMPLE_DEV_PM_OPS(mcp4725_pm_ops, mcp4725_suspend, mcp4725_resume); 74static SIMPLE_DEV_PM_OPS(mcp4725_pm_ops, mcp4725_suspend, mcp4725_resume);
77#define MCP4725_PM_OPS (&mcp4725_pm_ops)
78#else
79#define MCP4725_PM_OPS NULL
80#endif
81 75
82static ssize_t mcp4725_store_eeprom(struct device *dev, 76static ssize_t mcp4725_store_eeprom(struct device *dev,
83 struct device_attribute *attr, const char *buf, size_t len) 77 struct device_attribute *attr, const char *buf, size_t len)
@@ -547,7 +541,7 @@ static struct i2c_driver mcp4725_driver = {
547 .driver = { 541 .driver = {
548 .name = MCP4725_DRV_NAME, 542 .name = MCP4725_DRV_NAME,
549 .of_match_table = of_match_ptr(mcp4725_of_match), 543 .of_match_table = of_match_ptr(mcp4725_of_match),
550 .pm = MCP4725_PM_OPS, 544 .pm = &mcp4725_pm_ops,
551 }, 545 },
552 .probe = mcp4725_probe, 546 .probe = mcp4725_probe,
553 .remove = mcp4725_remove, 547 .remove = mcp4725_remove,
diff --git a/drivers/iio/dac/mcp4922.c b/drivers/iio/dac/mcp4922.c
index bf9aa3fc0534..b5190d1dae8e 100644
--- a/drivers/iio/dac/mcp4922.c
+++ b/drivers/iio/dac/mcp4922.c
@@ -94,17 +94,22 @@ static int mcp4922_write_raw(struct iio_dev *indio_dev,
94 long mask) 94 long mask)
95{ 95{
96 struct mcp4922_state *state = iio_priv(indio_dev); 96 struct mcp4922_state *state = iio_priv(indio_dev);
97 int ret;
97 98
98 if (val2 != 0) 99 if (val2 != 0)
99 return -EINVAL; 100 return -EINVAL;
100 101
101 switch (mask) { 102 switch (mask) {
102 case IIO_CHAN_INFO_RAW: 103 case IIO_CHAN_INFO_RAW:
103 if (val > GENMASK(chan->scan_type.realbits-1, 0)) 104 if (val < 0 || val > GENMASK(chan->scan_type.realbits - 1, 0))
104 return -EINVAL; 105 return -EINVAL;
105 val <<= chan->scan_type.shift; 106 val <<= chan->scan_type.shift;
106 state->value[chan->channel] = val; 107
107 return mcp4922_spi_write(state, chan->channel, val); 108 ret = mcp4922_spi_write(state, chan->channel, val);
109 if (!ret)
110 state->value[chan->channel] = val;
111 return ret;
112
108 default: 113 default:
109 return -EINVAL; 114 return -EINVAL;
110 } 115 }
diff --git a/drivers/iio/dac/ti-dac5571.c b/drivers/iio/dac/ti-dac5571.c
index e39d1e901353..f6dcd8bce2b0 100644
--- a/drivers/iio/dac/ti-dac5571.c
+++ b/drivers/iio/dac/ti-dac5571.c
@@ -421,6 +421,7 @@ MODULE_DEVICE_TABLE(i2c, dac5571_id);
421static struct i2c_driver dac5571_driver = { 421static struct i2c_driver dac5571_driver = {
422 .driver = { 422 .driver = {
423 .name = "ti-dac5571", 423 .name = "ti-dac5571",
424 .of_match_table = of_match_ptr(dac5571_of_id),
424 }, 425 },
425 .probe = dac5571_probe, 426 .probe = dac5571_probe,
426 .remove = dac5571_remove, 427 .remove = dac5571_remove,
diff --git a/drivers/iio/frequency/ad9523.c b/drivers/iio/frequency/ad9523.c
index f4a508107f0d..f3f94fbdd20a 100644
--- a/drivers/iio/frequency/ad9523.c
+++ b/drivers/iio/frequency/ad9523.c
@@ -1078,6 +1078,6 @@ static struct spi_driver ad9523_driver = {
1078}; 1078};
1079module_spi_driver(ad9523_driver); 1079module_spi_driver(ad9523_driver);
1080 1080
1081MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 1081MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
1082MODULE_DESCRIPTION("Analog Devices AD9523 CLOCKDIST/PLL"); 1082MODULE_DESCRIPTION("Analog Devices AD9523 CLOCKDIST/PLL");
1083MODULE_LICENSE("GPL v2"); 1083MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/frequency/adf4350.c b/drivers/iio/frequency/adf4350.c
index 6d768431d90e..f4748ff243f7 100644
--- a/drivers/iio/frequency/adf4350.c
+++ b/drivers/iio/frequency/adf4350.c
@@ -388,7 +388,7 @@ static struct adf4350_platform_data *adf4350_parse_dt(struct device *dev)
388 if (!pdata) 388 if (!pdata)
389 return NULL; 389 return NULL;
390 390
391 strncpy(&pdata->name[0], np->name, SPI_NAME_SIZE - 1); 391 snprintf(&pdata->name[0], SPI_NAME_SIZE - 1, "%pOFn", np);
392 392
393 tmp = 10000; 393 tmp = 10000;
394 of_property_read_u32(np, "adi,channel-spacing", &tmp); 394 of_property_read_u32(np, "adi,channel-spacing", &tmp);
diff --git a/drivers/iio/health/max30102.c b/drivers/iio/health/max30102.c
index 15ccadc74891..3e29562ce374 100644
--- a/drivers/iio/health/max30102.c
+++ b/drivers/iio/health/max30102.c
@@ -282,9 +282,11 @@ static int max30102_read_measurement(struct max30102_data *data,
282 switch (measurements) { 282 switch (measurements) {
283 case 3: 283 case 3:
284 MAX30102_COPY_DATA(2); 284 MAX30102_COPY_DATA(2);
285 case 2: /* fall-through */ 285 /* fall through */
286 case 2:
286 MAX30102_COPY_DATA(1); 287 MAX30102_COPY_DATA(1);
287 case 1: /* fall-through */ 288 /* fall through */
289 case 1:
288 MAX30102_COPY_DATA(0); 290 MAX30102_COPY_DATA(0);
289 break; 291 break;
290 default: 292 default:
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index d80ef468508a..1e428c196a82 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -23,6 +23,7 @@
23#include <linux/iio/iio.h> 23#include <linux/iio/iio.h>
24#include <linux/acpi.h> 24#include <linux/acpi.h>
25#include <linux/platform_device.h> 25#include <linux/platform_device.h>
26#include <linux/regulator/consumer.h>
26#include "inv_mpu_iio.h" 27#include "inv_mpu_iio.h"
27 28
28/* 29/*
@@ -926,6 +927,39 @@ error_power_off:
926 return result; 927 return result;
927} 928}
928 929
930static int inv_mpu_core_enable_regulator(struct inv_mpu6050_state *st)
931{
932 int result;
933
934 result = regulator_enable(st->vddio_supply);
935 if (result) {
936 dev_err(regmap_get_device(st->map),
937 "Failed to enable regulator: %d\n", result);
938 } else {
939 /* Give the device a little bit of time to start up. */
940 usleep_range(35000, 70000);
941 }
942
943 return result;
944}
945
946static int inv_mpu_core_disable_regulator(struct inv_mpu6050_state *st)
947{
948 int result;
949
950 result = regulator_disable(st->vddio_supply);
951 if (result)
952 dev_err(regmap_get_device(st->map),
953 "Failed to disable regulator: %d\n", result);
954
955 return result;
956}
957
958static void inv_mpu_core_disable_regulator_action(void *_data)
959{
960 inv_mpu_core_disable_regulator(_data);
961}
962
929int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, 963int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
930 int (*inv_mpu_bus_setup)(struct iio_dev *), int chip_type) 964 int (*inv_mpu_bus_setup)(struct iio_dev *), int chip_type)
931{ 965{
@@ -992,6 +1026,28 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
992 return -EINVAL; 1026 return -EINVAL;
993 } 1027 }
994 1028
1029 st->vddio_supply = devm_regulator_get(dev, "vddio");
1030 if (IS_ERR(st->vddio_supply)) {
1031 if (PTR_ERR(st->vddio_supply) != -EPROBE_DEFER)
1032 dev_err(dev, "Failed to get vddio regulator %d\n",
1033 (int)PTR_ERR(st->vddio_supply));
1034
1035 return PTR_ERR(st->vddio_supply);
1036 }
1037
1038 result = inv_mpu_core_enable_regulator(st);
1039 if (result)
1040 return result;
1041
1042 result = devm_add_action(dev, inv_mpu_core_disable_regulator_action,
1043 st);
1044 if (result) {
1045 inv_mpu_core_disable_regulator_action(st);
1046 dev_err(dev, "Failed to setup regulator cleanup action %d\n",
1047 result);
1048 return result;
1049 }
1050
995 /* power is turned on inside check chip type*/ 1051 /* power is turned on inside check chip type*/
996 result = inv_check_and_setup_chip(st); 1052 result = inv_check_and_setup_chip(st);
997 if (result) 1053 if (result)
@@ -1051,7 +1107,12 @@ static int inv_mpu_resume(struct device *dev)
1051 int result; 1107 int result;
1052 1108
1053 mutex_lock(&st->lock); 1109 mutex_lock(&st->lock);
1110 result = inv_mpu_core_enable_regulator(st);
1111 if (result)
1112 goto out_unlock;
1113
1054 result = inv_mpu6050_set_power_itg(st, true); 1114 result = inv_mpu6050_set_power_itg(st, true);
1115out_unlock:
1055 mutex_unlock(&st->lock); 1116 mutex_unlock(&st->lock);
1056 1117
1057 return result; 1118 return result;
@@ -1064,6 +1125,7 @@ static int inv_mpu_suspend(struct device *dev)
1064 1125
1065 mutex_lock(&st->lock); 1126 mutex_lock(&st->lock);
1066 result = inv_mpu6050_set_power_itg(st, false); 1127 result = inv_mpu6050_set_power_itg(st, false);
1128 inv_mpu_core_disable_regulator(st);
1067 mutex_unlock(&st->lock); 1129 mutex_unlock(&st->lock);
1068 1130
1069 return result; 1131 return result;
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
index e69a59659dbc..6bcc11fc1b88 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
@@ -129,6 +129,7 @@ struct inv_mpu6050_hw {
129 * @chip_period: chip internal period estimation (~1kHz). 129 * @chip_period: chip internal period estimation (~1kHz).
130 * @it_timestamp: timestamp from previous interrupt. 130 * @it_timestamp: timestamp from previous interrupt.
131 * @data_timestamp: timestamp for next data sample. 131 * @data_timestamp: timestamp for next data sample.
132 * @vddio_supply voltage regulator for the chip.
132 */ 133 */
133struct inv_mpu6050_state { 134struct inv_mpu6050_state {
134 struct mutex lock; 135 struct mutex lock;
@@ -149,6 +150,7 @@ struct inv_mpu6050_state {
149 s64 chip_period; 150 s64 chip_period;
150 s64 it_timestamp; 151 s64 it_timestamp;
151 s64 data_timestamp; 152 s64 data_timestamp;
153 struct regulator *vddio_supply;
152}; 154};
153 155
154/*register and associated bit definition*/ 156/*register and associated bit definition*/
diff --git a/drivers/iio/imu/st_lsm6dsx/Kconfig b/drivers/iio/imu/st_lsm6dsx/Kconfig
index ccc817e17eb8..094fd006b63d 100644
--- a/drivers/iio/imu/st_lsm6dsx/Kconfig
+++ b/drivers/iio/imu/st_lsm6dsx/Kconfig
@@ -9,7 +9,7 @@ config IIO_ST_LSM6DSX
9 help 9 help
10 Say yes here to build support for STMicroelectronics LSM6DSx imu 10 Say yes here to build support for STMicroelectronics LSM6DSx imu
11 sensor. Supported devices: lsm6ds3, lsm6ds3h, lsm6dsl, lsm6dsm, 11 sensor. Supported devices: lsm6ds3, lsm6ds3h, lsm6dsl, lsm6dsm,
12 ism330dlc 12 ism330dlc, lsm6dso
13 13
14 To compile this driver as a module, choose M here: the module 14 To compile this driver as a module, choose M here: the module
15 will be called st_lsm6dsx. 15 will be called st_lsm6dsx.
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
index edcd838037cd..ef73519a0fb6 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
@@ -19,6 +19,7 @@
19#define ST_LSM6DSL_DEV_NAME "lsm6dsl" 19#define ST_LSM6DSL_DEV_NAME "lsm6dsl"
20#define ST_LSM6DSM_DEV_NAME "lsm6dsm" 20#define ST_LSM6DSM_DEV_NAME "lsm6dsm"
21#define ST_ISM330DLC_DEV_NAME "ism330dlc" 21#define ST_ISM330DLC_DEV_NAME "ism330dlc"
22#define ST_LSM6DSO_DEV_NAME "lsm6dso"
22 23
23enum st_lsm6dsx_hw_id { 24enum st_lsm6dsx_hw_id {
24 ST_LSM6DS3_ID, 25 ST_LSM6DS3_ID,
@@ -26,14 +27,20 @@ enum st_lsm6dsx_hw_id {
26 ST_LSM6DSL_ID, 27 ST_LSM6DSL_ID,
27 ST_LSM6DSM_ID, 28 ST_LSM6DSM_ID,
28 ST_ISM330DLC_ID, 29 ST_ISM330DLC_ID,
30 ST_LSM6DSO_ID,
29 ST_LSM6DSX_MAX_ID, 31 ST_LSM6DSX_MAX_ID,
30}; 32};
31 33
32#define ST_LSM6DSX_BUFF_SIZE 400 34#define ST_LSM6DSX_BUFF_SIZE 512
33#define ST_LSM6DSX_CHAN_SIZE 2 35#define ST_LSM6DSX_CHAN_SIZE 2
34#define ST_LSM6DSX_SAMPLE_SIZE 6 36#define ST_LSM6DSX_SAMPLE_SIZE 6
37#define ST_LSM6DSX_TAG_SIZE 1
38#define ST_LSM6DSX_TAGGED_SAMPLE_SIZE (ST_LSM6DSX_SAMPLE_SIZE + \
39 ST_LSM6DSX_TAG_SIZE)
35#define ST_LSM6DSX_MAX_WORD_LEN ((32 / ST_LSM6DSX_SAMPLE_SIZE) * \ 40#define ST_LSM6DSX_MAX_WORD_LEN ((32 / ST_LSM6DSX_SAMPLE_SIZE) * \
36 ST_LSM6DSX_SAMPLE_SIZE) 41 ST_LSM6DSX_SAMPLE_SIZE)
42#define ST_LSM6DSX_MAX_TAGGED_WORD_LEN ((32 / ST_LSM6DSX_TAGGED_SAMPLE_SIZE) \
43 * ST_LSM6DSX_TAGGED_SAMPLE_SIZE)
37#define ST_LSM6DSX_SHIFT_VAL(val, mask) (((val) << __ffs(mask)) & (mask)) 44#define ST_LSM6DSX_SHIFT_VAL(val, mask) (((val) << __ffs(mask)) & (mask))
38 45
39struct st_lsm6dsx_reg { 46struct st_lsm6dsx_reg {
@@ -41,13 +48,17 @@ struct st_lsm6dsx_reg {
41 u8 mask; 48 u8 mask;
42}; 49};
43 50
51struct st_lsm6dsx_hw;
52
44/** 53/**
45 * struct st_lsm6dsx_fifo_ops - ST IMU FIFO settings 54 * struct st_lsm6dsx_fifo_ops - ST IMU FIFO settings
55 * @read_fifo: Read FIFO callback.
46 * @fifo_th: FIFO threshold register info (addr + mask). 56 * @fifo_th: FIFO threshold register info (addr + mask).
47 * @fifo_diff: FIFO diff status register info (addr + mask). 57 * @fifo_diff: FIFO diff status register info (addr + mask).
48 * @th_wl: FIFO threshold word length. 58 * @th_wl: FIFO threshold word length.
49 */ 59 */
50struct st_lsm6dsx_fifo_ops { 60struct st_lsm6dsx_fifo_ops {
61 int (*read_fifo)(struct st_lsm6dsx_hw *hw);
51 struct { 62 struct {
52 u8 addr; 63 u8 addr;
53 u16 mask; 64 u16 mask;
@@ -79,6 +90,7 @@ struct st_lsm6dsx_hw_ts_settings {
79 * @max_fifo_size: Sensor max fifo length in FIFO words. 90 * @max_fifo_size: Sensor max fifo length in FIFO words.
80 * @id: List of hw id supported by the driver configuration. 91 * @id: List of hw id supported by the driver configuration.
81 * @decimator: List of decimator register info (addr + mask). 92 * @decimator: List of decimator register info (addr + mask).
93 * @batch: List of FIFO batching register info (addr + mask).
82 * @fifo_ops: Sensor hw FIFO parameters. 94 * @fifo_ops: Sensor hw FIFO parameters.
83 * @ts_settings: Hw timer related settings. 95 * @ts_settings: Hw timer related settings.
84 */ 96 */
@@ -87,6 +99,7 @@ struct st_lsm6dsx_settings {
87 u16 max_fifo_size; 99 u16 max_fifo_size;
88 enum st_lsm6dsx_hw_id id[ST_LSM6DSX_MAX_ID]; 100 enum st_lsm6dsx_hw_id id[ST_LSM6DSX_MAX_ID];
89 struct st_lsm6dsx_reg decimator[ST_LSM6DSX_MAX_ID]; 101 struct st_lsm6dsx_reg decimator[ST_LSM6DSX_MAX_ID];
102 struct st_lsm6dsx_reg batch[ST_LSM6DSX_MAX_ID];
90 struct st_lsm6dsx_fifo_ops fifo_ops; 103 struct st_lsm6dsx_fifo_ops fifo_ops;
91 struct st_lsm6dsx_hw_ts_settings ts_settings; 104 struct st_lsm6dsx_hw_ts_settings ts_settings;
92}; 105};
@@ -175,5 +188,8 @@ int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor,
175int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw); 188int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw);
176int st_lsm6dsx_set_fifo_mode(struct st_lsm6dsx_hw *hw, 189int st_lsm6dsx_set_fifo_mode(struct st_lsm6dsx_hw *hw,
177 enum st_lsm6dsx_fifo_mode fifo_mode); 190 enum st_lsm6dsx_fifo_mode fifo_mode);
191int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw);
192int st_lsm6dsx_read_tagged_fifo(struct st_lsm6dsx_hw *hw);
193int st_lsm6dsx_check_odr(struct st_lsm6dsx_sensor *sensor, u16 odr, u8 *val);
178 194
179#endif /* ST_LSM6DSX_H */ 195#endif /* ST_LSM6DSX_H */
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
index 631360b14ca7..b5263fc522ca 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
@@ -12,6 +12,11 @@
12 * buffer contains the data of all the enabled FIFO data sets 12 * buffer contains the data of all the enabled FIFO data sets
13 * (e.g. Gx, Gy, Gz, Ax, Ay, Az), then data are repeated depending on the 13 * (e.g. Gx, Gy, Gz, Ax, Ay, Az), then data are repeated depending on the
14 * value of the decimation factor and ODR set for each FIFO data set. 14 * value of the decimation factor and ODR set for each FIFO data set.
15 *
16 * LSM6DSO: The FIFO buffer can be configured to store data from gyroscope and
17 * accelerometer. Each sample is queued with a tag (1B) indicating data source
18 * (gyroscope, accelerometer, hw timer).
19 *
15 * FIFO supported modes: 20 * FIFO supported modes:
16 * - BYPASS: FIFO disabled 21 * - BYPASS: FIFO disabled
17 * - CONTINUOUS: FIFO enabled. When the buffer is full, the FIFO index 22 * - CONTINUOUS: FIFO enabled. When the buffer is full, the FIFO index
@@ -46,6 +51,7 @@
46#define ST_LSM6DSX_FIFO_ODR_MASK GENMASK(6, 3) 51#define ST_LSM6DSX_FIFO_ODR_MASK GENMASK(6, 3)
47#define ST_LSM6DSX_FIFO_EMPTY_MASK BIT(12) 52#define ST_LSM6DSX_FIFO_EMPTY_MASK BIT(12)
48#define ST_LSM6DSX_REG_FIFO_OUTL_ADDR 0x3e 53#define ST_LSM6DSX_REG_FIFO_OUTL_ADDR 0x3e
54#define ST_LSM6DSX_REG_FIFO_OUT_TAG_ADDR 0x78
49#define ST_LSM6DSX_REG_TS_RESET_ADDR 0x42 55#define ST_LSM6DSX_REG_TS_RESET_ADDR 0x42
50 56
51#define ST_LSM6DSX_MAX_FIFO_ODR_VAL 0x08 57#define ST_LSM6DSX_MAX_FIFO_ODR_VAL 0x08
@@ -58,6 +64,12 @@ struct st_lsm6dsx_decimator_entry {
58 u8 val; 64 u8 val;
59}; 65};
60 66
67enum st_lsm6dsx_fifo_tag {
68 ST_LSM6DSX_GYRO_TAG = 0x01,
69 ST_LSM6DSX_ACC_TAG = 0x02,
70 ST_LSM6DSX_TS_TAG = 0x04,
71};
72
61static const 73static const
62struct st_lsm6dsx_decimator_entry st_lsm6dsx_decimator_table[] = { 74struct st_lsm6dsx_decimator_entry st_lsm6dsx_decimator_table[] = {
63 { 0, 0x0 }, 75 { 0, 0x0 },
@@ -177,12 +189,34 @@ static int st_lsm6dsx_set_fifo_odr(struct st_lsm6dsx_sensor *sensor,
177 bool enable) 189 bool enable)
178{ 190{
179 struct st_lsm6dsx_hw *hw = sensor->hw; 191 struct st_lsm6dsx_hw *hw = sensor->hw;
192 const struct st_lsm6dsx_reg *batch_reg;
180 u8 data; 193 u8 data;
181 194
182 data = hw->enable_mask ? ST_LSM6DSX_MAX_FIFO_ODR_VAL : 0; 195 batch_reg = &hw->settings->batch[sensor->id];
183 return regmap_update_bits(hw->regmap, ST_LSM6DSX_REG_FIFO_MODE_ADDR, 196 if (batch_reg->addr) {
184 ST_LSM6DSX_FIFO_ODR_MASK, 197 int val;
185 FIELD_PREP(ST_LSM6DSX_FIFO_ODR_MASK, data)); 198
199 if (enable) {
200 int err;
201
202 err = st_lsm6dsx_check_odr(sensor, sensor->odr,
203 &data);
204 if (err < 0)
205 return err;
206 } else {
207 data = 0;
208 }
209 val = ST_LSM6DSX_SHIFT_VAL(data, batch_reg->mask);
210 return regmap_update_bits(hw->regmap, batch_reg->addr,
211 batch_reg->mask, val);
212 } else {
213 data = hw->enable_mask ? ST_LSM6DSX_MAX_FIFO_ODR_VAL : 0;
214 return regmap_update_bits(hw->regmap,
215 ST_LSM6DSX_REG_FIFO_MODE_ADDR,
216 ST_LSM6DSX_FIFO_ODR_MASK,
217 FIELD_PREP(ST_LSM6DSX_FIFO_ODR_MASK,
218 data));
219 }
186} 220}
187 221
188int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor, u16 watermark) 222int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor, u16 watermark)
@@ -250,21 +284,21 @@ static int st_lsm6dsx_reset_hw_ts(struct st_lsm6dsx_hw *hw)
250} 284}
251 285
252/* 286/*
253 * Set max bulk read to ST_LSM6DSX_MAX_WORD_LEN in order to avoid 287 * Set max bulk read to ST_LSM6DSX_MAX_WORD_LEN/ST_LSM6DSX_MAX_TAGGED_WORD_LEN
254 * a kmalloc for each bus access 288 * in order to avoid a kmalloc for each bus access
255 */ 289 */
256static inline int st_lsm6dsx_read_block(struct st_lsm6dsx_hw *hw, u8 *data, 290static inline int st_lsm6dsx_read_block(struct st_lsm6dsx_hw *hw, u8 addr,
257 unsigned int data_len) 291 u8 *data, unsigned int data_len,
292 unsigned int max_word_len)
258{ 293{
259 unsigned int word_len, read_len = 0; 294 unsigned int word_len, read_len = 0;
260 int err; 295 int err;
261 296
262 while (read_len < data_len) { 297 while (read_len < data_len) {
263 word_len = min_t(unsigned int, data_len - read_len, 298 word_len = min_t(unsigned int, data_len - read_len,
264 ST_LSM6DSX_MAX_WORD_LEN); 299 max_word_len);
265 err = regmap_bulk_read(hw->regmap, 300 err = regmap_bulk_read(hw->regmap, addr, data + read_len,
266 ST_LSM6DSX_REG_FIFO_OUTL_ADDR, 301 word_len);
267 data + read_len, word_len);
268 if (err < 0) 302 if (err < 0)
269 return err; 303 return err;
270 read_len += word_len; 304 read_len += word_len;
@@ -282,7 +316,7 @@ static inline int st_lsm6dsx_read_block(struct st_lsm6dsx_hw *hw, u8 *data,
282 * 316 *
283 * Return: Number of bytes read from the FIFO 317 * Return: Number of bytes read from the FIFO
284 */ 318 */
285static int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw) 319int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw)
286{ 320{
287 u16 fifo_len, pattern_len = hw->sip * ST_LSM6DSX_SAMPLE_SIZE; 321 u16 fifo_len, pattern_len = hw->sip * ST_LSM6DSX_SAMPLE_SIZE;
288 u16 fifo_diff_mask = hw->settings->fifo_ops.fifo_diff.mask; 322 u16 fifo_diff_mask = hw->settings->fifo_ops.fifo_diff.mask;
@@ -314,7 +348,9 @@ static int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw)
314 gyro_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_GYRO]); 348 gyro_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_GYRO]);
315 349
316 for (read_len = 0; read_len < fifo_len; read_len += pattern_len) { 350 for (read_len = 0; read_len < fifo_len; read_len += pattern_len) {
317 err = st_lsm6dsx_read_block(hw, hw->buff, pattern_len); 351 err = st_lsm6dsx_read_block(hw, ST_LSM6DSX_REG_FIFO_OUTL_ADDR,
352 hw->buff, pattern_len,
353 ST_LSM6DSX_MAX_WORD_LEN);
318 if (err < 0) { 354 if (err < 0) {
319 dev_err(hw->dev, 355 dev_err(hw->dev,
320 "failed to read pattern from fifo (err=%d)\n", 356 "failed to read pattern from fifo (err=%d)\n",
@@ -400,13 +436,111 @@ static int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw)
400 return read_len; 436 return read_len;
401} 437}
402 438
439/**
440 * st_lsm6dsx_read_tagged_fifo() - LSM6DSO read FIFO routine
441 * @hw: Pointer to instance of struct st_lsm6dsx_hw.
442 *
443 * Read samples from the hw FIFO and push them to IIO buffers.
444 *
445 * Return: Number of bytes read from the FIFO
446 */
447int st_lsm6dsx_read_tagged_fifo(struct st_lsm6dsx_hw *hw)
448{
449 u16 pattern_len = hw->sip * ST_LSM6DSX_TAGGED_SAMPLE_SIZE;
450 u16 fifo_len, fifo_diff_mask;
451 struct st_lsm6dsx_sensor *acc_sensor, *gyro_sensor;
452 u8 iio_buff[ST_LSM6DSX_IIO_BUFF_SIZE], tag;
453 bool reset_ts = false;
454 int i, err, read_len;
455 __le16 fifo_status;
456 s64 ts = 0;
457
458 err = regmap_bulk_read(hw->regmap,
459 hw->settings->fifo_ops.fifo_diff.addr,
460 &fifo_status, sizeof(fifo_status));
461 if (err < 0) {
462 dev_err(hw->dev, "failed to read fifo status (err=%d)\n",
463 err);
464 return err;
465 }
466
467 fifo_diff_mask = hw->settings->fifo_ops.fifo_diff.mask;
468 fifo_len = (le16_to_cpu(fifo_status) & fifo_diff_mask) *
469 ST_LSM6DSX_TAGGED_SAMPLE_SIZE;
470 if (!fifo_len)
471 return 0;
472
473 acc_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_ACC]);
474 gyro_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_GYRO]);
475
476 for (read_len = 0; read_len < fifo_len; read_len += pattern_len) {
477 err = st_lsm6dsx_read_block(hw,
478 ST_LSM6DSX_REG_FIFO_OUT_TAG_ADDR,
479 hw->buff, pattern_len,
480 ST_LSM6DSX_MAX_TAGGED_WORD_LEN);
481 if (err < 0) {
482 dev_err(hw->dev,
483 "failed to read pattern from fifo (err=%d)\n",
484 err);
485 return err;
486 }
487
488 for (i = 0; i < pattern_len;
489 i += ST_LSM6DSX_TAGGED_SAMPLE_SIZE) {
490 memcpy(iio_buff, &hw->buff[i + ST_LSM6DSX_TAG_SIZE],
491 ST_LSM6DSX_SAMPLE_SIZE);
492
493 tag = hw->buff[i] >> 3;
494 switch (tag) {
495 case ST_LSM6DSX_TS_TAG:
496 /*
497 * hw timestamp is 4B long and it is stored
498 * in FIFO according to this schema:
499 * B0 = ts[7:0], B1 = ts[15:8], B2 = ts[23:16],
500 * B3 = ts[31:24]
501 */
502 ts = le32_to_cpu(*((__le32 *)iio_buff));
503 /*
504 * check if hw timestamp engine is going to
505 * reset (the sensor generates an interrupt
506 * to signal the hw timestamp will reset in
507 * 1.638s)
508 */
509 if (!reset_ts && ts >= 0xffff0000)
510 reset_ts = true;
511 ts *= ST_LSM6DSX_TS_SENSITIVITY;
512 break;
513 case ST_LSM6DSX_GYRO_TAG:
514 iio_push_to_buffers_with_timestamp(
515 hw->iio_devs[ST_LSM6DSX_ID_GYRO],
516 iio_buff, gyro_sensor->ts_ref + ts);
517 break;
518 case ST_LSM6DSX_ACC_TAG:
519 iio_push_to_buffers_with_timestamp(
520 hw->iio_devs[ST_LSM6DSX_ID_ACC],
521 iio_buff, acc_sensor->ts_ref + ts);
522 break;
523 default:
524 break;
525 }
526 }
527 }
528
529 if (unlikely(reset_ts)) {
530 err = st_lsm6dsx_reset_hw_ts(hw);
531 if (err < 0)
532 return err;
533 }
534 return read_len;
535}
536
403int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw) 537int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw)
404{ 538{
405 int err; 539 int err;
406 540
407 mutex_lock(&hw->fifo_lock); 541 mutex_lock(&hw->fifo_lock);
408 542
409 st_lsm6dsx_read_fifo(hw); 543 hw->settings->fifo_ops.read_fifo(hw);
410 err = st_lsm6dsx_set_fifo_mode(hw, ST_LSM6DSX_FIFO_BYPASS); 544 err = st_lsm6dsx_set_fifo_mode(hw, ST_LSM6DSX_FIFO_BYPASS);
411 545
412 mutex_unlock(&hw->fifo_lock); 546 mutex_unlock(&hw->fifo_lock);
@@ -478,7 +612,7 @@ static irqreturn_t st_lsm6dsx_handler_thread(int irq, void *private)
478 int count; 612 int count;
479 613
480 mutex_lock(&hw->fifo_lock); 614 mutex_lock(&hw->fifo_lock);
481 count = st_lsm6dsx_read_fifo(hw); 615 count = hw->settings->fifo_ops.read_fifo(hw);
482 mutex_unlock(&hw->fifo_lock); 616 mutex_unlock(&hw->fifo_lock);
483 617
484 return !count ? IRQ_NONE : IRQ_HANDLED; 618 return !count ? IRQ_NONE : IRQ_HANDLED;
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index aebbe0ddd8d8..2ad3c610e4b6 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -23,6 +23,12 @@
23 * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000 23 * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000
24 * - FIFO size: 4KB 24 * - FIFO size: 4KB
25 * 25 *
26 * - LSM6DSO
27 * - Accelerometer/Gyroscope supported ODR [Hz]: 13, 26, 52, 104, 208, 416
28 * - Accelerometer supported full-scale [g]: +-2/+-4/+-8/+-16
29 * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000
30 * - FIFO size: 3KB
31 *
26 * Copyright 2016 STMicroelectronics Inc. 32 * Copyright 2016 STMicroelectronics Inc.
27 * 33 *
28 * Lorenzo Bianconi <lorenzo.bianconi@st.com> 34 * Lorenzo Bianconi <lorenzo.bianconi@st.com>
@@ -171,6 +177,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
171 }, 177 },
172 }, 178 },
173 .fifo_ops = { 179 .fifo_ops = {
180 .read_fifo = st_lsm6dsx_read_fifo,
174 .fifo_th = { 181 .fifo_th = {
175 .addr = 0x06, 182 .addr = 0x06,
176 .mask = GENMASK(11, 0), 183 .mask = GENMASK(11, 0),
@@ -217,6 +224,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
217 }, 224 },
218 }, 225 },
219 .fifo_ops = { 226 .fifo_ops = {
227 .read_fifo = st_lsm6dsx_read_fifo,
220 .fifo_th = { 228 .fifo_th = {
221 .addr = 0x06, 229 .addr = 0x06,
222 .mask = GENMASK(11, 0), 230 .mask = GENMASK(11, 0),
@@ -265,6 +273,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
265 }, 273 },
266 }, 274 },
267 .fifo_ops = { 275 .fifo_ops = {
276 .read_fifo = st_lsm6dsx_read_fifo,
268 .fifo_th = { 277 .fifo_th = {
269 .addr = 0x06, 278 .addr = 0x06,
270 .mask = GENMASK(10, 0), 279 .mask = GENMASK(10, 0),
@@ -294,6 +303,45 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
294 }, 303 },
295 }, 304 },
296 }, 305 },
306 {
307 .wai = 0x6c,
308 .max_fifo_size = 512,
309 .id = {
310 [0] = ST_LSM6DSO_ID,
311 },
312 .batch = {
313 [ST_LSM6DSX_ID_ACC] = {
314 .addr = 0x09,
315 .mask = GENMASK(3, 0),
316 },
317 [ST_LSM6DSX_ID_GYRO] = {
318 .addr = 0x09,
319 .mask = GENMASK(7, 4),
320 },
321 },
322 .fifo_ops = {
323 .read_fifo = st_lsm6dsx_read_tagged_fifo,
324 .fifo_th = {
325 .addr = 0x07,
326 .mask = GENMASK(8, 0),
327 },
328 .fifo_diff = {
329 .addr = 0x3a,
330 .mask = GENMASK(8, 0),
331 },
332 .th_wl = 1,
333 },
334 .ts_settings = {
335 .timer_en = {
336 .addr = 0x19,
337 .mask = BIT(5),
338 },
339 .decimator = {
340 .addr = 0x0a,
341 .mask = GENMASK(7, 6),
342 },
343 },
344 },
297}; 345};
298 346
299#define ST_LSM6DSX_CHANNEL(chan_type, addr, mod, scan_idx) \ 347#define ST_LSM6DSX_CHANNEL(chan_type, addr, mod, scan_idx) \
@@ -395,8 +443,7 @@ static int st_lsm6dsx_set_full_scale(struct st_lsm6dsx_sensor *sensor,
395 return 0; 443 return 0;
396} 444}
397 445
398static int st_lsm6dsx_check_odr(struct st_lsm6dsx_sensor *sensor, u16 odr, 446int st_lsm6dsx_check_odr(struct st_lsm6dsx_sensor *sensor, u16 odr, u8 *val)
399 u8 *val)
400{ 447{
401 int i; 448 int i;
402 449
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c
index 377c4e9997da..448b7bc1e578 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c
@@ -61,6 +61,10 @@ static const struct of_device_id st_lsm6dsx_i2c_of_match[] = {
61 .compatible = "st,ism330dlc", 61 .compatible = "st,ism330dlc",
62 .data = (void *)ST_ISM330DLC_ID, 62 .data = (void *)ST_ISM330DLC_ID,
63 }, 63 },
64 {
65 .compatible = "st,lsm6dso",
66 .data = (void *)ST_LSM6DSO_ID,
67 },
64 {}, 68 {},
65}; 69};
66MODULE_DEVICE_TABLE(of, st_lsm6dsx_i2c_of_match); 70MODULE_DEVICE_TABLE(of, st_lsm6dsx_i2c_of_match);
@@ -71,6 +75,7 @@ static const struct i2c_device_id st_lsm6dsx_i2c_id_table[] = {
71 { ST_LSM6DSL_DEV_NAME, ST_LSM6DSL_ID }, 75 { ST_LSM6DSL_DEV_NAME, ST_LSM6DSL_ID },
72 { ST_LSM6DSM_DEV_NAME, ST_LSM6DSM_ID }, 76 { ST_LSM6DSM_DEV_NAME, ST_LSM6DSM_ID },
73 { ST_ISM330DLC_DEV_NAME, ST_ISM330DLC_ID }, 77 { ST_ISM330DLC_DEV_NAME, ST_ISM330DLC_ID },
78 { ST_LSM6DSO_DEV_NAME, ST_LSM6DSO_ID },
74 {}, 79 {},
75}; 80};
76MODULE_DEVICE_TABLE(i2c, st_lsm6dsx_i2c_id_table); 81MODULE_DEVICE_TABLE(i2c, st_lsm6dsx_i2c_id_table);
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c
index fec5c6ce7eb7..b1df8a6973e6 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c
@@ -61,6 +61,10 @@ static const struct of_device_id st_lsm6dsx_spi_of_match[] = {
61 .compatible = "st,ism330dlc", 61 .compatible = "st,ism330dlc",
62 .data = (void *)ST_ISM330DLC_ID, 62 .data = (void *)ST_ISM330DLC_ID,
63 }, 63 },
64 {
65 .compatible = "st,lsm6dso",
66 .data = (void *)ST_LSM6DSO_ID,
67 },
64 {}, 68 {},
65}; 69};
66MODULE_DEVICE_TABLE(of, st_lsm6dsx_spi_of_match); 70MODULE_DEVICE_TABLE(of, st_lsm6dsx_spi_of_match);
@@ -71,6 +75,7 @@ static const struct spi_device_id st_lsm6dsx_spi_id_table[] = {
71 { ST_LSM6DSL_DEV_NAME, ST_LSM6DSL_ID }, 75 { ST_LSM6DSL_DEV_NAME, ST_LSM6DSL_ID },
72 { ST_LSM6DSM_DEV_NAME, ST_LSM6DSM_ID }, 76 { ST_LSM6DSM_DEV_NAME, ST_LSM6DSM_ID },
73 { ST_ISM330DLC_DEV_NAME, ST_ISM330DLC_ID }, 77 { ST_ISM330DLC_DEV_NAME, ST_ISM330DLC_ID },
78 { ST_LSM6DSO_DEV_NAME, ST_LSM6DSO_ID },
74 {}, 79 {},
75}; 80};
76MODULE_DEVICE_TABLE(spi, st_lsm6dsx_spi_id_table); 81MODULE_DEVICE_TABLE(spi, st_lsm6dsx_spi_id_table);
diff --git a/drivers/iio/light/bh1750.c b/drivers/iio/light/bh1750.c
index a814828e69f5..28347df78cff 100644
--- a/drivers/iio/light/bh1750.c
+++ b/drivers/iio/light/bh1750.c
@@ -1,12 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * ROHM BH1710/BH1715/BH1721/BH1750/BH1751 ambient light sensor driver 3 * ROHM BH1710/BH1715/BH1721/BH1750/BH1751 ambient light sensor driver
3 * 4 *
4 * Copyright (c) Tomasz Duszynski <tduszyns@gmail.com> 5 * Copyright (c) Tomasz Duszynski <tduszyns@gmail.com>
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * Data sheets: 7 * Data sheets:
11 * http://rohmfs.rohm.com/en/products/databook/datasheet/ic/sensor/light/bh1710fvc-e.pdf 8 * http://rohmfs.rohm.com/en/products/databook/datasheet/ic/sensor/light/bh1710fvc-e.pdf
12 * http://rohmfs.rohm.com/en/products/databook/datasheet/ic/sensor/light/bh1715fvc-e.pdf 9 * http://rohmfs.rohm.com/en/products/databook/datasheet/ic/sensor/light/bh1715fvc-e.pdf
@@ -281,8 +278,7 @@ static int bh1750_remove(struct i2c_client *client)
281 return 0; 278 return 0;
282} 279}
283 280
284#ifdef CONFIG_PM_SLEEP 281static int __maybe_unused bh1750_suspend(struct device *dev)
285static int bh1750_suspend(struct device *dev)
286{ 282{
287 int ret; 283 int ret;
288 struct bh1750_data *data = 284 struct bh1750_data *data =
@@ -300,10 +296,6 @@ static int bh1750_suspend(struct device *dev)
300} 296}
301 297
302static SIMPLE_DEV_PM_OPS(bh1750_pm_ops, bh1750_suspend, NULL); 298static SIMPLE_DEV_PM_OPS(bh1750_pm_ops, bh1750_suspend, NULL);
303#define BH1750_PM_OPS (&bh1750_pm_ops)
304#else
305#define BH1750_PM_OPS NULL
306#endif
307 299
308static const struct i2c_device_id bh1750_id[] = { 300static const struct i2c_device_id bh1750_id[] = {
309 { "bh1710", BH1710 }, 301 { "bh1710", BH1710 },
@@ -315,10 +307,21 @@ static const struct i2c_device_id bh1750_id[] = {
315}; 307};
316MODULE_DEVICE_TABLE(i2c, bh1750_id); 308MODULE_DEVICE_TABLE(i2c, bh1750_id);
317 309
310static const struct of_device_id bh1750_of_match[] = {
311 { .compatible = "rohm,bh1710", },
312 { .compatible = "rohm,bh1715", },
313 { .compatible = "rohm,bh1721", },
314 { .compatible = "rohm,bh1750", },
315 { .compatible = "rohm,bh1751", },
316 { }
317};
318MODULE_DEVICE_TABLE(of, bh1750_of_match);
319
318static struct i2c_driver bh1750_driver = { 320static struct i2c_driver bh1750_driver = {
319 .driver = { 321 .driver = {
320 .name = "bh1750", 322 .name = "bh1750",
321 .pm = BH1750_PM_OPS, 323 .of_match_table = bh1750_of_match,
324 .pm = &bh1750_pm_ops,
322 }, 325 },
323 .probe = bh1750_probe, 326 .probe = bh1750_probe,
324 .remove = bh1750_remove, 327 .remove = bh1750_remove,
diff --git a/drivers/iio/light/max44000.c b/drivers/iio/light/max44000.c
index 4067dff2ff6a..d3fb460cfbdc 100644
--- a/drivers/iio/light/max44000.c
+++ b/drivers/iio/light/max44000.c
@@ -99,7 +99,6 @@ static const int max44000_alspga_shift[] = {0, 2, 4, 7};
99 * Handling this internally is also required for buffer support because the 99 * Handling this internally is also required for buffer support because the
100 * channel's scan_type can't be modified dynamically. 100 * channel's scan_type can't be modified dynamically.
101 */ 101 */
102static const int max44000_alstim_shift[] = {0, 2, 4, 6};
103#define MAX44000_ALSTIM_SHIFT(alstim) (2 * (alstim)) 102#define MAX44000_ALSTIM_SHIFT(alstim) (2 * (alstim))
104 103
105/* Available integration times with pretty manual alignment: */ 104/* Available integration times with pretty manual alignment: */
diff --git a/drivers/iio/light/tsl2772.c b/drivers/iio/light/tsl2772.c
index df5b2a0da96c..83cece921843 100644
--- a/drivers/iio/light/tsl2772.c
+++ b/drivers/iio/light/tsl2772.c
@@ -20,6 +20,7 @@
20#include <linux/iio/iio.h> 20#include <linux/iio/iio.h>
21#include <linux/iio/sysfs.h> 21#include <linux/iio/sysfs.h>
22#include <linux/platform_data/tsl2772.h> 22#include <linux/platform_data/tsl2772.h>
23#include <linux/regulator/consumer.h>
23 24
24/* Cal defs */ 25/* Cal defs */
25#define PROX_STAT_CAL 0 26#define PROX_STAT_CAL 0
@@ -107,6 +108,11 @@
107#define TSL2772_ALS_GAIN_TRIM_MIN 250 108#define TSL2772_ALS_GAIN_TRIM_MIN 250
108#define TSL2772_ALS_GAIN_TRIM_MAX 4000 109#define TSL2772_ALS_GAIN_TRIM_MAX 4000
109 110
111#define TSL2772_MAX_PROX_LEDS 2
112
113#define TSL2772_BOOT_MIN_SLEEP_TIME 10000
114#define TSL2772_BOOT_MAX_SLEEP_TIME 28000
115
110/* Device family members */ 116/* Device family members */
111enum { 117enum {
112 tsl2571, 118 tsl2571,
@@ -118,7 +124,8 @@ enum {
118 tsl2672, 124 tsl2672,
119 tmd2672, 125 tmd2672,
120 tsl2772, 126 tsl2772,
121 tmd2772 127 tmd2772,
128 apds9930,
122}; 129};
123 130
124enum { 131enum {
@@ -141,11 +148,21 @@ struct tsl2772_chip_info {
141 const struct iio_info *info; 148 const struct iio_info *info;
142}; 149};
143 150
151static const int tsl2772_led_currents[][2] = {
152 { 100000, TSL2772_100_mA },
153 { 50000, TSL2772_50_mA },
154 { 25000, TSL2772_25_mA },
155 { 13000, TSL2772_13_mA },
156 { 0, 0 }
157};
158
144struct tsl2772_chip { 159struct tsl2772_chip {
145 kernel_ulong_t id; 160 kernel_ulong_t id;
146 struct mutex prox_mutex; 161 struct mutex prox_mutex;
147 struct mutex als_mutex; 162 struct mutex als_mutex;
148 struct i2c_client *client; 163 struct i2c_client *client;
164 struct regulator *vdd_supply;
165 struct regulator *vddio_supply;
149 u16 prox_data; 166 u16 prox_data;
150 struct tsl2772_als_info als_cur_info; 167 struct tsl2772_als_info als_cur_info;
151 struct tsl2772_settings settings; 168 struct tsl2772_settings settings;
@@ -197,6 +214,12 @@ static const struct tsl2772_lux tmd2x72_lux_table[TSL2772_DEF_LUX_TABLE_SZ] = {
197 { 0, 0 }, 214 { 0, 0 },
198}; 215};
199 216
217static const struct tsl2772_lux apds9930_lux_table[TSL2772_DEF_LUX_TABLE_SZ] = {
218 { 52000, 96824 },
219 { 38792, 67132 },
220 { 0, 0 },
221};
222
200static const struct tsl2772_lux *tsl2772_default_lux_table_group[] = { 223static const struct tsl2772_lux *tsl2772_default_lux_table_group[] = {
201 [tsl2571] = tsl2x71_lux_table, 224 [tsl2571] = tsl2x71_lux_table,
202 [tsl2671] = tsl2x71_lux_table, 225 [tsl2671] = tsl2x71_lux_table,
@@ -208,6 +231,7 @@ static const struct tsl2772_lux *tsl2772_default_lux_table_group[] = {
208 [tmd2672] = tmd2x72_lux_table, 231 [tmd2672] = tmd2x72_lux_table,
209 [tsl2772] = tsl2x72_lux_table, 232 [tsl2772] = tsl2x72_lux_table,
210 [tmd2772] = tmd2x72_lux_table, 233 [tmd2772] = tmd2x72_lux_table,
234 [apds9930] = apds9930_lux_table,
211}; 235};
212 236
213static const struct tsl2772_settings tsl2772_default_settings = { 237static const struct tsl2772_settings tsl2772_default_settings = {
@@ -258,6 +282,7 @@ static const int tsl2772_int_time_avail[][6] = {
258 [tmd2672] = { 0, 2730, 0, 2730, 0, 699000 }, 282 [tmd2672] = { 0, 2730, 0, 2730, 0, 699000 },
259 [tsl2772] = { 0, 2730, 0, 2730, 0, 699000 }, 283 [tsl2772] = { 0, 2730, 0, 2730, 0, 699000 },
260 [tmd2772] = { 0, 2730, 0, 2730, 0, 699000 }, 284 [tmd2772] = { 0, 2730, 0, 2730, 0, 699000 },
285 [apds9930] = { 0, 2730, 0, 2730, 0, 699000 },
261}; 286};
262 287
263static int tsl2772_int_calibscale_avail[] = { 1, 8, 16, 120 }; 288static int tsl2772_int_calibscale_avail[] = { 1, 8, 16, 120 };
@@ -283,7 +308,8 @@ static const u8 device_channel_config[] = {
283 [tsl2672] = PRX2, 308 [tsl2672] = PRX2,
284 [tmd2672] = PRX2, 309 [tmd2672] = PRX2,
285 [tsl2772] = ALSPRX2, 310 [tsl2772] = ALSPRX2,
286 [tmd2772] = ALSPRX2 311 [tmd2772] = ALSPRX2,
312 [apds9930] = ALSPRX2,
287}; 313};
288 314
289static int tsl2772_read_status(struct tsl2772_chip *chip) 315static int tsl2772_read_status(struct tsl2772_chip *chip)
@@ -497,6 +523,7 @@ static int tsl2772_get_prox(struct iio_dev *indio_dev)
497 case tmd2672: 523 case tmd2672:
498 case tsl2772: 524 case tsl2772:
499 case tmd2772: 525 case tmd2772:
526 case apds9930:
500 if (!(ret & TSL2772_STA_PRX_VALID)) { 527 if (!(ret & TSL2772_STA_PRX_VALID)) {
501 ret = -EINVAL; 528 ret = -EINVAL;
502 goto prox_poll_err; 529 goto prox_poll_err;
@@ -515,6 +542,75 @@ prox_poll_err:
515 return ret; 542 return ret;
516} 543}
517 544
545static int tsl2772_read_prox_led_current(struct tsl2772_chip *chip)
546{
547 struct device_node *of_node = chip->client->dev.of_node;
548 int ret, tmp, i;
549
550 ret = of_property_read_u32(of_node, "led-max-microamp", &tmp);
551 if (ret < 0)
552 return ret;
553
554 for (i = 0; tsl2772_led_currents[i][0] != 0; i++) {
555 if (tmp == tsl2772_led_currents[i][0]) {
556 chip->settings.prox_power = tsl2772_led_currents[i][1];
557 return 0;
558 }
559 }
560
561 dev_err(&chip->client->dev, "Invalid value %d for led-max-microamp\n",
562 tmp);
563
564 return -EINVAL;
565
566}
567
568static int tsl2772_read_prox_diodes(struct tsl2772_chip *chip)
569{
570 struct device_node *of_node = chip->client->dev.of_node;
571 int i, ret, num_leds, prox_diode_mask;
572 u32 leds[TSL2772_MAX_PROX_LEDS];
573
574 ret = of_property_count_u32_elems(of_node, "amstaos,proximity-diodes");
575 if (ret < 0)
576 return ret;
577
578 num_leds = ret;
579 if (num_leds > TSL2772_MAX_PROX_LEDS)
580 num_leds = TSL2772_MAX_PROX_LEDS;
581
582 ret = of_property_read_u32_array(of_node, "amstaos,proximity-diodes",
583 leds, num_leds);
584 if (ret < 0) {
585 dev_err(&chip->client->dev,
586 "Invalid value for amstaos,proximity-diodes: %d.\n",
587 ret);
588 return ret;
589 }
590
591 prox_diode_mask = 0;
592 for (i = 0; i < num_leds; i++) {
593 if (leds[i] == 0)
594 prox_diode_mask |= TSL2772_DIODE0;
595 else if (leds[i] == 1)
596 prox_diode_mask |= TSL2772_DIODE1;
597 else {
598 dev_err(&chip->client->dev,
599 "Invalid value %d in amstaos,proximity-diodes.\n",
600 leds[i]);
601 return -EINVAL;
602 }
603 }
604
605 return 0;
606}
607
608static void tsl2772_parse_dt(struct tsl2772_chip *chip)
609{
610 tsl2772_read_prox_led_current(chip);
611 tsl2772_read_prox_diodes(chip);
612}
613
518/** 614/**
519 * tsl2772_defaults() - Populates the device nominal operating parameters 615 * tsl2772_defaults() - Populates the device nominal operating parameters
520 * with those provided by a 'platform' data struct or 616 * with those provided by a 'platform' data struct or
@@ -541,6 +637,8 @@ static void tsl2772_defaults(struct tsl2772_chip *chip)
541 memcpy(chip->tsl2772_device_lux, 637 memcpy(chip->tsl2772_device_lux,
542 tsl2772_default_lux_table_group[chip->id], 638 tsl2772_default_lux_table_group[chip->id],
543 TSL2772_DEFAULT_TABLE_BYTES); 639 TSL2772_DEFAULT_TABLE_BYTES);
640
641 tsl2772_parse_dt(chip);
544} 642}
545 643
546/** 644/**
@@ -595,6 +693,52 @@ static int tsl2772_als_calibrate(struct iio_dev *indio_dev)
595 return ret; 693 return ret;
596} 694}
597 695
696static void tsl2772_disable_regulators_action(void *_data)
697{
698 struct tsl2772_chip *chip = _data;
699
700 regulator_disable(chip->vdd_supply);
701 regulator_disable(chip->vddio_supply);
702}
703
704static int tsl2772_enable_regulator(struct tsl2772_chip *chip,
705 struct regulator *regulator)
706{
707 int ret;
708
709 ret = regulator_enable(regulator);
710 if (ret < 0) {
711 dev_err(&chip->client->dev, "Failed to enable regulator: %d\n",
712 ret);
713 return ret;
714 }
715
716 return 0;
717}
718
719static struct regulator *tsl2772_get_regulator(struct tsl2772_chip *chip,
720 char *name)
721{
722 struct regulator *regulator;
723 int ret;
724
725 regulator = devm_regulator_get(&chip->client->dev, name);
726 if (IS_ERR(regulator)) {
727 if (PTR_ERR(regulator) != -EPROBE_DEFER)
728 dev_err(&chip->client->dev,
729 "Failed to get %s regulator %d\n",
730 name, (int)PTR_ERR(regulator));
731
732 return regulator;
733 }
734
735 ret = tsl2772_enable_regulator(chip, regulator);
736 if (ret < 0)
737 return ERR_PTR(ret);
738
739 return regulator;
740}
741
598static int tsl2772_chip_on(struct iio_dev *indio_dev) 742static int tsl2772_chip_on(struct iio_dev *indio_dev)
599{ 743{
600 struct tsl2772_chip *chip = iio_priv(indio_dev); 744 struct tsl2772_chip *chip = iio_priv(indio_dev);
@@ -1260,6 +1404,7 @@ static int tsl2772_device_id_verif(int id, int target)
1260 case tmd2672: 1404 case tmd2672:
1261 case tsl2772: 1405 case tsl2772:
1262 case tmd2772: 1406 case tmd2772:
1407 case apds9930:
1263 return (id & 0xf0) == SWORDFISH_ID; 1408 return (id & 0xf0) == SWORDFISH_ID;
1264 } 1409 }
1265 1410
@@ -1652,6 +1797,27 @@ static int tsl2772_probe(struct i2c_client *clientp,
1652 chip->client = clientp; 1797 chip->client = clientp;
1653 i2c_set_clientdata(clientp, indio_dev); 1798 i2c_set_clientdata(clientp, indio_dev);
1654 1799
1800 chip->vddio_supply = tsl2772_get_regulator(chip, "vddio");
1801 if (IS_ERR(chip->vddio_supply))
1802 return PTR_ERR(chip->vddio_supply);
1803
1804 chip->vdd_supply = tsl2772_get_regulator(chip, "vdd");
1805 if (IS_ERR(chip->vdd_supply)) {
1806 regulator_disable(chip->vddio_supply);
1807 return PTR_ERR(chip->vdd_supply);
1808 }
1809
1810 ret = devm_add_action(&clientp->dev, tsl2772_disable_regulators_action,
1811 chip);
1812 if (ret < 0) {
1813 tsl2772_disable_regulators_action(chip);
1814 dev_err(&clientp->dev, "Failed to setup regulator cleanup action %d\n",
1815 ret);
1816 return ret;
1817 }
1818
1819 usleep_range(TSL2772_BOOT_MIN_SLEEP_TIME, TSL2772_BOOT_MAX_SLEEP_TIME);
1820
1655 ret = i2c_smbus_read_byte_data(chip->client, 1821 ret = i2c_smbus_read_byte_data(chip->client,
1656 TSL2772_CMD_REG | TSL2772_CHIPID); 1822 TSL2772_CMD_REG | TSL2772_CHIPID);
1657 if (ret < 0) 1823 if (ret < 0)
@@ -1725,13 +1891,33 @@ static int tsl2772_probe(struct i2c_client *clientp,
1725static int tsl2772_suspend(struct device *dev) 1891static int tsl2772_suspend(struct device *dev)
1726{ 1892{
1727 struct iio_dev *indio_dev = dev_get_drvdata(dev); 1893 struct iio_dev *indio_dev = dev_get_drvdata(dev);
1894 struct tsl2772_chip *chip = iio_priv(indio_dev);
1895 int ret;
1896
1897 ret = tsl2772_chip_off(indio_dev);
1898 regulator_disable(chip->vdd_supply);
1899 regulator_disable(chip->vddio_supply);
1728 1900
1729 return tsl2772_chip_off(indio_dev); 1901 return ret;
1730} 1902}
1731 1903
1732static int tsl2772_resume(struct device *dev) 1904static int tsl2772_resume(struct device *dev)
1733{ 1905{
1734 struct iio_dev *indio_dev = dev_get_drvdata(dev); 1906 struct iio_dev *indio_dev = dev_get_drvdata(dev);
1907 struct tsl2772_chip *chip = iio_priv(indio_dev);
1908 int ret;
1909
1910 ret = tsl2772_enable_regulator(chip, chip->vddio_supply);
1911 if (ret < 0)
1912 return ret;
1913
1914 ret = tsl2772_enable_regulator(chip, chip->vdd_supply);
1915 if (ret < 0) {
1916 regulator_disable(chip->vddio_supply);
1917 return ret;
1918 }
1919
1920 usleep_range(TSL2772_BOOT_MIN_SLEEP_TIME, TSL2772_BOOT_MAX_SLEEP_TIME);
1735 1921
1736 return tsl2772_chip_on(indio_dev); 1922 return tsl2772_chip_on(indio_dev);
1737} 1923}
@@ -1758,6 +1944,7 @@ static const struct i2c_device_id tsl2772_idtable[] = {
1758 { "tmd2672", tmd2672 }, 1944 { "tmd2672", tmd2672 },
1759 { "tsl2772", tsl2772 }, 1945 { "tsl2772", tsl2772 },
1760 { "tmd2772", tmd2772 }, 1946 { "tmd2772", tmd2772 },
1947 { "apds9930", apds9930},
1761 {} 1948 {}
1762}; 1949};
1763 1950
@@ -1774,6 +1961,7 @@ static const struct of_device_id tsl2772_of_match[] = {
1774 { .compatible = "amstaos,tmd2672" }, 1961 { .compatible = "amstaos,tmd2672" },
1775 { .compatible = "amstaos,tsl2772" }, 1962 { .compatible = "amstaos,tsl2772" },
1776 { .compatible = "amstaos,tmd2772" }, 1963 { .compatible = "amstaos,tmd2772" },
1964 { .compatible = "avago,apds9930" },
1777 {} 1965 {}
1778}; 1966};
1779MODULE_DEVICE_TABLE(of, tsl2772_of_match); 1967MODULE_DEVICE_TABLE(of, tsl2772_of_match);
diff --git a/drivers/iio/magnetometer/hmc5843.h b/drivers/iio/magnetometer/hmc5843.h
index 76a5d7484d8d..a75224cf99df 100644
--- a/drivers/iio/magnetometer/hmc5843.h
+++ b/drivers/iio/magnetometer/hmc5843.h
@@ -31,7 +31,7 @@ enum hmc5843_ids {
31}; 31};
32 32
33/** 33/**
34 * struct hcm5843_data - device specific data 34 * struct hmc5843_data - device specific data
35 * @dev: actual device 35 * @dev: actual device
36 * @lock: update and read regmap data 36 * @lock: update and read regmap data
37 * @regmap: hardware access register maps 37 * @regmap: hardware access register maps
diff --git a/drivers/iio/multiplexer/iio-mux.c b/drivers/iio/multiplexer/iio-mux.c
index e1f44cecdef4..0422ef57914c 100644
--- a/drivers/iio/multiplexer/iio-mux.c
+++ b/drivers/iio/multiplexer/iio-mux.c
@@ -1,13 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * IIO multiplexer driver 3 * IIO multiplexer driver
3 * 4 *
4 * Copyright (C) 2017 Axentia Technologies AB 5 * Copyright (C) 2017 Axentia Technologies AB
5 * 6 *
6 * Author: Peter Rosin <peda@axentia.se> 7 * Author: Peter Rosin <peda@axentia.se>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */ 8 */
12 9
13#include <linux/err.h> 10#include <linux/err.h>
diff --git a/drivers/iio/potentiometer/max5481.c b/drivers/iio/potentiometer/max5481.c
index ffe2761333a2..6d2f13fa5662 100644
--- a/drivers/iio/potentiometer/max5481.c
+++ b/drivers/iio/potentiometer/max5481.c
@@ -137,7 +137,6 @@ static int max5481_probe(struct spi_device *spi)
137 struct iio_dev *indio_dev; 137 struct iio_dev *indio_dev;
138 struct max5481_data *data; 138 struct max5481_data *data;
139 const struct spi_device_id *id = spi_get_device_id(spi); 139 const struct spi_device_id *id = spi_get_device_id(spi);
140 const struct of_device_id *match;
141 int ret; 140 int ret;
142 141
143 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*data)); 142 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*data));
@@ -149,10 +148,8 @@ static int max5481_probe(struct spi_device *spi)
149 148
150 data->spi = spi; 149 data->spi = spi;
151 150
152 match = of_match_device(of_match_ptr(max5481_match), &spi->dev); 151 data->cfg = of_device_get_match_data(&spi->dev);
153 if (match) 152 if (!data->cfg)
154 data->cfg = of_device_get_match_data(&spi->dev);
155 else
156 data->cfg = &max5481_cfg[id->driver_data]; 153 data->cfg = &max5481_cfg[id->driver_data];
157 154
158 indio_dev->name = id->name; 155 indio_dev->name = id->name;
diff --git a/drivers/iio/potentiometer/mcp4018.c b/drivers/iio/potentiometer/mcp4018.c
index 320a7c929777..62151b2a2b12 100644
--- a/drivers/iio/potentiometer/mcp4018.c
+++ b/drivers/iio/potentiometer/mcp4018.c
@@ -147,7 +147,6 @@ static int mcp4018_probe(struct i2c_client *client)
147 struct device *dev = &client->dev; 147 struct device *dev = &client->dev;
148 struct mcp4018_data *data; 148 struct mcp4018_data *data;
149 struct iio_dev *indio_dev; 149 struct iio_dev *indio_dev;
150 const struct of_device_id *match;
151 150
152 if (!i2c_check_functionality(client->adapter, 151 if (!i2c_check_functionality(client->adapter,
153 I2C_FUNC_SMBUS_BYTE)) { 152 I2C_FUNC_SMBUS_BYTE)) {
@@ -162,10 +161,8 @@ static int mcp4018_probe(struct i2c_client *client)
162 i2c_set_clientdata(client, indio_dev); 161 i2c_set_clientdata(client, indio_dev);
163 data->client = client; 162 data->client = client;
164 163
165 match = of_match_device(of_match_ptr(mcp4018_of_match), dev); 164 data->cfg = of_device_get_match_data(dev);
166 if (match) 165 if (!data->cfg)
167 data->cfg = of_device_get_match_data(dev);
168 else
169 data->cfg = &mcp4018_cfg[i2c_match_id(mcp4018_id, client)->driver_data]; 166 data->cfg = &mcp4018_cfg[i2c_match_id(mcp4018_id, client)->driver_data];
170 167
171 indio_dev->dev.parent = dev; 168 indio_dev->dev.parent = dev;
@@ -190,4 +187,4 @@ module_i2c_driver(mcp4018_driver);
190 187
191MODULE_AUTHOR("Peter Rosin <peda@axentia.se>"); 188MODULE_AUTHOR("Peter Rosin <peda@axentia.se>");
192MODULE_DESCRIPTION("MCP4018 digital potentiometer"); 189MODULE_DESCRIPTION("MCP4018 digital potentiometer");
193MODULE_LICENSE("GPL"); 190MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/potentiometer/mcp4531.c b/drivers/iio/potentiometer/mcp4531.c
index df894af6cccb..d71a22d71a30 100644
--- a/drivers/iio/potentiometer/mcp4531.c
+++ b/drivers/iio/potentiometer/mcp4531.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Industrial I/O driver for Microchip digital potentiometers 3 * Industrial I/O driver for Microchip digital potentiometers
3 * Copyright (c) 2015 Axentia Technologies AB 4 * Copyright (c) 2015 Axentia Technologies AB
@@ -22,10 +23,6 @@
22 * mcp4652 2 257 5, 10, 50, 100 01011xx 23 * mcp4652 2 257 5, 10, 50, 100 01011xx
23 * mcp4661 2 257 5, 10, 50, 100 0101xxx 24 * mcp4661 2 257 5, 10, 50, 100 0101xxx
24 * mcp4662 2 257 5, 10, 50, 100 01011xx 25 * mcp4662 2 257 5, 10, 50, 100 01011xx
25 *
26 * This program is free software; you can redistribute it and/or modify it
27 * under the terms of the GNU General Public License version 2 as published by
28 * the Free Software Foundation.
29 */ 26 */
30 27
31#include <linux/module.h> 28#include <linux/module.h>
@@ -360,7 +357,6 @@ static int mcp4531_probe(struct i2c_client *client)
360 struct device *dev = &client->dev; 357 struct device *dev = &client->dev;
361 struct mcp4531_data *data; 358 struct mcp4531_data *data;
362 struct iio_dev *indio_dev; 359 struct iio_dev *indio_dev;
363 const struct of_device_id *match;
364 360
365 if (!i2c_check_functionality(client->adapter, 361 if (!i2c_check_functionality(client->adapter,
366 I2C_FUNC_SMBUS_WORD_DATA)) { 362 I2C_FUNC_SMBUS_WORD_DATA)) {
@@ -375,10 +371,8 @@ static int mcp4531_probe(struct i2c_client *client)
375 i2c_set_clientdata(client, indio_dev); 371 i2c_set_clientdata(client, indio_dev);
376 data->client = client; 372 data->client = client;
377 373
378 match = of_match_device(of_match_ptr(mcp4531_of_match), dev); 374 data->cfg = of_device_get_match_data(dev);
379 if (match) 375 if (!data->cfg)
380 data->cfg = of_device_get_match_data(dev);
381 else
382 data->cfg = &mcp4531_cfg[i2c_match_id(mcp4531_id, client)->driver_data]; 376 data->cfg = &mcp4531_cfg[i2c_match_id(mcp4531_id, client)->driver_data];
383 377
384 indio_dev->dev.parent = dev; 378 indio_dev->dev.parent = dev;
@@ -403,4 +397,4 @@ module_i2c_driver(mcp4531_driver);
403 397
404MODULE_AUTHOR("Peter Rosin <peda@axentia.se>"); 398MODULE_AUTHOR("Peter Rosin <peda@axentia.se>");
405MODULE_DESCRIPTION("MCP4531 digital potentiometer"); 399MODULE_DESCRIPTION("MCP4531 digital potentiometer");
406MODULE_LICENSE("GPL"); 400MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/pressure/ms5611.h b/drivers/iio/pressure/ms5611.h
index ead9e9f85894..bc06271fa38b 100644
--- a/drivers/iio/pressure/ms5611.h
+++ b/drivers/iio/pressure/ms5611.h
@@ -1,12 +1,9 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * MS5611 pressure and temperature sensor driver 3 * MS5611 pressure and temperature sensor driver
3 * 4 *
4 * Copyright (c) Tomasz Duszynski <tduszyns@gmail.com> 5 * Copyright (c) Tomasz Duszynski <tduszyns@gmail.com>
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 */ 7 */
11 8
12#ifndef _MS5611_H 9#ifndef _MS5611_H
diff --git a/drivers/iio/pressure/ms5611_core.c b/drivers/iio/pressure/ms5611_core.c
index f950cfde5db9..2f598ad91621 100644
--- a/drivers/iio/pressure/ms5611_core.c
+++ b/drivers/iio/pressure/ms5611_core.c
@@ -1,12 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * MS5611 pressure and temperature sensor driver 3 * MS5611 pressure and temperature sensor driver
3 * 4 *
4 * Copyright (c) Tomasz Duszynski <tduszyns@gmail.com> 5 * Copyright (c) Tomasz Duszynski <tduszyns@gmail.com>
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * Data sheet: 7 * Data sheet:
11 * http://www.meas-spec.com/downloads/MS5611-01BA03.pdf 8 * http://www.meas-spec.com/downloads/MS5611-01BA03.pdf
12 * http://www.meas-spec.com/downloads/MS5607-02BA03.pdf 9 * http://www.meas-spec.com/downloads/MS5607-02BA03.pdf
diff --git a/drivers/iio/pressure/ms5611_i2c.c b/drivers/iio/pressure/ms5611_i2c.c
index 55fb5fc0b6ea..8089c59adce5 100644
--- a/drivers/iio/pressure/ms5611_i2c.c
+++ b/drivers/iio/pressure/ms5611_i2c.c
@@ -1,12 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * MS5611 pressure and temperature sensor driver (I2C bus) 3 * MS5611 pressure and temperature sensor driver (I2C bus)
3 * 4 *
4 * Copyright (c) Tomasz Duszynski <tduszyns@gmail.com> 5 * Copyright (c) Tomasz Duszynski <tduszyns@gmail.com>
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * 7-bit I2C slave addresses: 7 * 7-bit I2C slave addresses:
11 * 8 *
12 * 0x77 (CSB pin low) 9 * 0x77 (CSB pin low)
@@ -117,9 +114,7 @@ static int ms5611_i2c_remove(struct i2c_client *client)
117#if defined(CONFIG_OF) 114#if defined(CONFIG_OF)
118static const struct of_device_id ms5611_i2c_matches[] = { 115static const struct of_device_id ms5611_i2c_matches[] = {
119 { .compatible = "meas,ms5611" }, 116 { .compatible = "meas,ms5611" },
120 { .compatible = "ms5611" },
121 { .compatible = "meas,ms5607" }, 117 { .compatible = "meas,ms5607" },
122 { .compatible = "ms5607" },
123 { } 118 { }
124}; 119};
125MODULE_DEVICE_TABLE(of, ms5611_i2c_matches); 120MODULE_DEVICE_TABLE(of, ms5611_i2c_matches);
diff --git a/drivers/iio/pressure/ms5611_spi.c b/drivers/iio/pressure/ms5611_spi.c
index 932e05001e1a..b463eaa799ab 100644
--- a/drivers/iio/pressure/ms5611_spi.c
+++ b/drivers/iio/pressure/ms5611_spi.c
@@ -1,12 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * MS5611 pressure and temperature sensor driver (SPI bus) 3 * MS5611 pressure and temperature sensor driver (SPI bus)
3 * 4 *
4 * Copyright (c) Tomasz Duszynski <tduszyns@gmail.com> 5 * Copyright (c) Tomasz Duszynski <tduszyns@gmail.com>
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 */ 7 */
11 8
12#include <linux/delay.h> 9#include <linux/delay.h>
@@ -119,9 +116,7 @@ static int ms5611_spi_remove(struct spi_device *spi)
119#if defined(CONFIG_OF) 116#if defined(CONFIG_OF)
120static const struct of_device_id ms5611_spi_matches[] = { 117static const struct of_device_id ms5611_spi_matches[] = {
121 { .compatible = "meas,ms5611" }, 118 { .compatible = "meas,ms5611" },
122 { .compatible = "ms5611" },
123 { .compatible = "meas,ms5607" }, 119 { .compatible = "meas,ms5607" },
124 { .compatible = "ms5607" },
125 { } 120 { }
126}; 121};
127MODULE_DEVICE_TABLE(of, ms5611_spi_matches); 122MODULE_DEVICE_TABLE(of, ms5611_spi_matches);
diff --git a/drivers/iio/proximity/Kconfig b/drivers/iio/proximity/Kconfig
index 388ef70c11d2..b99367a89f81 100644
--- a/drivers/iio/proximity/Kconfig
+++ b/drivers/iio/proximity/Kconfig
@@ -92,4 +92,15 @@ config SRF08
92 To compile this driver as a module, choose M here: the 92 To compile this driver as a module, choose M here: the
93 module will be called srf08. 93 module will be called srf08.
94 94
95config VL53L0X_I2C
96 tristate "STMicroelectronics VL53L0X ToF ranger sensor (I2C)"
97 depends on I2C
98 help
99 Say Y here to build a driver for STMicroelectronics VL53L0X
100 ToF ranger sensors with i2c interface.
101 This driver can be used to measure the distance of objects.
102
103 To compile this driver as a module, choose M here: the
104 module will be called vl53l0x-i2c.
105
95endmenu 106endmenu
diff --git a/drivers/iio/proximity/Makefile b/drivers/iio/proximity/Makefile
index cac3d7d3325e..6d031f903c4c 100644
--- a/drivers/iio/proximity/Makefile
+++ b/drivers/iio/proximity/Makefile
@@ -11,3 +11,5 @@ obj-$(CONFIG_RFD77402) += rfd77402.o
11obj-$(CONFIG_SRF04) += srf04.o 11obj-$(CONFIG_SRF04) += srf04.o
12obj-$(CONFIG_SRF08) += srf08.o 12obj-$(CONFIG_SRF08) += srf08.o
13obj-$(CONFIG_SX9500) += sx9500.o 13obj-$(CONFIG_SX9500) += sx9500.o
14obj-$(CONFIG_VL53L0X_I2C) += vl53l0x-i2c.o
15
diff --git a/drivers/iio/proximity/isl29501.c b/drivers/iio/proximity/isl29501.c
index e5e94540f404..5ae549075b27 100644
--- a/drivers/iio/proximity/isl29501.c
+++ b/drivers/iio/proximity/isl29501.c
@@ -232,7 +232,6 @@ static u32 isl29501_register_write(struct isl29501_private *isl29501,
232 u32 value) 232 u32 value)
233{ 233{
234 const struct isl29501_register_desc *reg = &isl29501_registers[name]; 234 const struct isl29501_register_desc *reg = &isl29501_registers[name];
235 u8 msb, lsb;
236 int ret; 235 int ret;
237 236
238 if (!reg->msb && value > U8_MAX) 237 if (!reg->msb && value > U8_MAX)
@@ -241,22 +240,15 @@ static u32 isl29501_register_write(struct isl29501_private *isl29501,
241 if (value > U16_MAX) 240 if (value > U16_MAX)
242 return -ERANGE; 241 return -ERANGE;
243 242
244 if (!reg->msb) {
245 lsb = value & 0xFF;
246 } else {
247 msb = (value >> 8) & 0xFF;
248 lsb = value & 0xFF;
249 }
250
251 mutex_lock(&isl29501->lock); 243 mutex_lock(&isl29501->lock);
252 if (reg->msb) { 244 if (reg->msb) {
253 ret = i2c_smbus_write_byte_data(isl29501->client, 245 ret = i2c_smbus_write_byte_data(isl29501->client,
254 reg->msb, msb); 246 reg->msb, value >> 8);
255 if (ret < 0) 247 if (ret < 0)
256 goto err; 248 goto err;
257 } 249 }
258 250
259 ret = i2c_smbus_write_byte_data(isl29501->client, reg->lsb, lsb); 251 ret = i2c_smbus_write_byte_data(isl29501->client, reg->lsb, value);
260 252
261err: 253err:
262 mutex_unlock(&isl29501->lock); 254 mutex_unlock(&isl29501->lock);
diff --git a/drivers/iio/proximity/vl53l0x-i2c.c b/drivers/iio/proximity/vl53l0x-i2c.c
new file mode 100644
index 000000000000..b48216cc1858
--- /dev/null
+++ b/drivers/iio/proximity/vl53l0x-i2c.c
@@ -0,0 +1,164 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Support for ST VL53L0X FlightSense ToF Ranging Sensor on a i2c bus.
4 *
5 * Copyright (C) 2016 STMicroelectronics Imaging Division.
6 * Copyright (C) 2018 Song Qiang <songqiang1304521@gmail.com>
7 *
8 * Datasheet available at
9 * <https://www.st.com/resource/en/datasheet/vl53l0x.pdf>
10 *
11 * Default 7-bit i2c slave address 0x29.
12 *
13 * TODO: FIFO buffer, continuous mode, interrupts, range selection,
14 * sensor ID check.
15 */
16
17#include <linux/delay.h>
18#include <linux/i2c.h>
19#include <linux/module.h>
20
21#include <linux/iio/iio.h>
22
23#define VL_REG_SYSRANGE_START 0x00
24
25#define VL_REG_SYSRANGE_MODE_MASK GENMASK(3, 0)
26#define VL_REG_SYSRANGE_MODE_SINGLESHOT 0x00
27#define VL_REG_SYSRANGE_MODE_START_STOP BIT(0)
28#define VL_REG_SYSRANGE_MODE_BACKTOBACK BIT(1)
29#define VL_REG_SYSRANGE_MODE_TIMED BIT(2)
30#define VL_REG_SYSRANGE_MODE_HISTOGRAM BIT(3)
31
32#define VL_REG_RESULT_INT_STATUS 0x13
33#define VL_REG_RESULT_RANGE_STATUS 0x14
34#define VL_REG_RESULT_RANGE_STATUS_COMPLETE BIT(0)
35
36struct vl53l0x_data {
37 struct i2c_client *client;
38};
39
40static int vl53l0x_read_proximity(struct vl53l0x_data *data,
41 const struct iio_chan_spec *chan,
42 int *val)
43{
44 struct i2c_client *client = data->client;
45 u16 tries = 20;
46 u8 buffer[12];
47 int ret;
48
49 ret = i2c_smbus_write_byte_data(client, VL_REG_SYSRANGE_START, 1);
50 if (ret < 0)
51 return ret;
52
53 do {
54 ret = i2c_smbus_read_byte_data(client,
55 VL_REG_RESULT_RANGE_STATUS);
56 if (ret < 0)
57 return ret;
58
59 if (ret & VL_REG_RESULT_RANGE_STATUS_COMPLETE)
60 break;
61
62 usleep_range(1000, 5000);
63 } while (--tries);
64 if (!tries)
65 return -ETIMEDOUT;
66
67 ret = i2c_smbus_read_i2c_block_data(client, VL_REG_RESULT_RANGE_STATUS,
68 12, buffer);
69 if (ret < 0)
70 return ret;
71 else if (ret != 12)
72 return -EREMOTEIO;
73
74 /* Values should be between 30~1200 in millimeters. */
75 *val = (buffer[10] << 8) + buffer[11];
76
77 return 0;
78}
79
80static const struct iio_chan_spec vl53l0x_channels[] = {
81 {
82 .type = IIO_DISTANCE,
83 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
84 BIT(IIO_CHAN_INFO_SCALE),
85 },
86};
87
88static int vl53l0x_read_raw(struct iio_dev *indio_dev,
89 const struct iio_chan_spec *chan,
90 int *val, int *val2, long mask)
91{
92 struct vl53l0x_data *data = iio_priv(indio_dev);
93 int ret;
94
95 if (chan->type != IIO_DISTANCE)
96 return -EINVAL;
97
98 switch (mask) {
99 case IIO_CHAN_INFO_RAW:
100 ret = vl53l0x_read_proximity(data, chan, val);
101 if (ret < 0)
102 return ret;
103
104 return IIO_VAL_INT;
105 case IIO_CHAN_INFO_SCALE:
106 *val = 0;
107 *val2 = 1000;
108
109 return IIO_VAL_INT_PLUS_MICRO;
110 default:
111 return -EINVAL;
112 }
113}
114
115static const struct iio_info vl53l0x_info = {
116 .read_raw = vl53l0x_read_raw,
117};
118
119static int vl53l0x_probe(struct i2c_client *client)
120{
121 struct vl53l0x_data *data;
122 struct iio_dev *indio_dev;
123
124 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
125 if (!indio_dev)
126 return -ENOMEM;
127
128 data = iio_priv(indio_dev);
129 data->client = client;
130 i2c_set_clientdata(client, indio_dev);
131
132 if (!i2c_check_functionality(client->adapter,
133 I2C_FUNC_SMBUS_READ_I2C_BLOCK |
134 I2C_FUNC_SMBUS_BYTE_DATA))
135 return -EOPNOTSUPP;
136
137 indio_dev->dev.parent = &client->dev;
138 indio_dev->name = "vl53l0x";
139 indio_dev->info = &vl53l0x_info;
140 indio_dev->channels = vl53l0x_channels;
141 indio_dev->num_channels = ARRAY_SIZE(vl53l0x_channels);
142 indio_dev->modes = INDIO_DIRECT_MODE;
143
144 return devm_iio_device_register(&client->dev, indio_dev);
145}
146
147static const struct of_device_id st_vl53l0x_dt_match[] = {
148 { .compatible = "st,vl53l0x", },
149 { }
150};
151MODULE_DEVICE_TABLE(of, st_vl53l0x_dt_match);
152
153static struct i2c_driver vl53l0x_driver = {
154 .driver = {
155 .name = "vl53l0x-i2c",
156 .of_match_table = st_vl53l0x_dt_match,
157 },
158 .probe_new = vl53l0x_probe,
159};
160module_i2c_driver(vl53l0x_driver);
161
162MODULE_AUTHOR("Song Qiang <songqiang1304521@gmail.com>");
163MODULE_DESCRIPTION("ST vl53l0x ToF ranging sensor driver");
164MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/trigger/iio-trig-sysfs.c b/drivers/iio/trigger/iio-trig-sysfs.c
index 3f0dc9a1a514..45c4897295d6 100644
--- a/drivers/iio/trigger/iio-trig-sysfs.c
+++ b/drivers/iio/trigger/iio-trig-sysfs.c
@@ -222,7 +222,7 @@ static void __exit iio_sysfs_trig_exit(void)
222} 222}
223module_exit(iio_sysfs_trig_exit); 223module_exit(iio_sysfs_trig_exit);
224 224
225MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 225MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
226MODULE_DESCRIPTION("Sysfs based trigger for the iio subsystem"); 226MODULE_DESCRIPTION("Sysfs based trigger for the iio subsystem");
227MODULE_LICENSE("GPL v2"); 227MODULE_LICENSE("GPL v2");
228MODULE_ALIAS("platform:iio-trig-sysfs"); 228MODULE_ALIAS("platform:iio-trig-sysfs");
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index 1abf76be2aa8..7c015536360d 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -80,8 +80,6 @@ source "drivers/staging/netlogic/Kconfig"
80 80
81source "drivers/staging/mt29f_spinand/Kconfig" 81source "drivers/staging/mt29f_spinand/Kconfig"
82 82
83source "drivers/staging/dgnc/Kconfig"
84
85source "drivers/staging/gs_fpgaboot/Kconfig" 83source "drivers/staging/gs_fpgaboot/Kconfig"
86 84
87source "drivers/staging/unisys/Kconfig" 85source "drivers/staging/unisys/Kconfig"
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index ab0cbe8815b1..a79b3fe20cf0 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -29,7 +29,6 @@ obj-$(CONFIG_STAGING_BOARD) += board/
29obj-$(CONFIG_LTE_GDM724X) += gdm724x/ 29obj-$(CONFIG_LTE_GDM724X) += gdm724x/
30obj-$(CONFIG_FIREWIRE_SERIAL) += fwserial/ 30obj-$(CONFIG_FIREWIRE_SERIAL) += fwserial/
31obj-$(CONFIG_GOLDFISH) += goldfish/ 31obj-$(CONFIG_GOLDFISH) += goldfish/
32obj-$(CONFIG_DGNC) += dgnc/
33obj-$(CONFIG_MTD_SPINAND_MT29F) += mt29f_spinand/ 32obj-$(CONFIG_MTD_SPINAND_MT29F) += mt29f_spinand/
34obj-$(CONFIG_GS_FPGABOOT) += gs_fpgaboot/ 33obj-$(CONFIG_GS_FPGABOOT) += gs_fpgaboot/
35obj-$(CONFIG_UNISYSSPAR) += unisys/ 34obj-$(CONFIG_UNISYSSPAR) += unisys/
diff --git a/drivers/staging/android/ion/ion.h b/drivers/staging/android/ion/ion.h
index 16cbd38a7160..c006fc1e5a16 100644
--- a/drivers/staging/android/ion/ion.h
+++ b/drivers/staging/android/ion/ion.h
@@ -157,8 +157,6 @@ struct ion_heap_ops {
157 * @lock: protects the free list 157 * @lock: protects the free list
158 * @waitqueue: queue to wait on from deferred free thread 158 * @waitqueue: queue to wait on from deferred free thread
159 * @task: task struct of deferred free thread 159 * @task: task struct of deferred free thread
160 * @debug_show: called when heap debug file is read to add any
161 * heap specific debug info to output
162 * 160 *
163 * Represents a pool of memory from which buffers can be made. In some 161 * Represents a pool of memory from which buffers can be made. In some
164 * systems the only heap is regular system memory allocated via vmalloc. 162 * systems the only heap is regular system memory allocated via vmalloc.
@@ -179,9 +177,6 @@ struct ion_heap {
179 spinlock_t free_lock; 177 spinlock_t free_lock;
180 wait_queue_head_t waitqueue; 178 wait_queue_head_t waitqueue;
181 struct task_struct *task; 179 struct task_struct *task;
182
183 int (*debug_show)(struct ion_heap *heap, struct seq_file *s,
184 void *unused);
185}; 180};
186 181
187/** 182/**
diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c
index 701eb9f3b0f1..548bb02c0ca6 100644
--- a/drivers/staging/android/ion/ion_system_heap.c
+++ b/drivers/staging/android/ion/ion_system_heap.c
@@ -212,29 +212,6 @@ static struct ion_heap_ops system_heap_ops = {
212 .shrink = ion_system_heap_shrink, 212 .shrink = ion_system_heap_shrink,
213}; 213};
214 214
215static int ion_system_heap_debug_show(struct ion_heap *heap, struct seq_file *s,
216 void *unused)
217{
218 struct ion_system_heap *sys_heap = container_of(heap,
219 struct ion_system_heap,
220 heap);
221 int i;
222 struct ion_page_pool *pool;
223
224 for (i = 0; i < NUM_ORDERS; i++) {
225 pool = sys_heap->pools[i];
226
227 seq_printf(s, "%d order %u highmem pages %lu total\n",
228 pool->high_count, pool->order,
229 (PAGE_SIZE << pool->order) * pool->high_count);
230 seq_printf(s, "%d order %u lowmem pages %lu total\n",
231 pool->low_count, pool->order,
232 (PAGE_SIZE << pool->order) * pool->low_count);
233 }
234
235 return 0;
236}
237
238static void ion_system_heap_destroy_pools(struct ion_page_pool **pools) 215static void ion_system_heap_destroy_pools(struct ion_page_pool **pools)
239{ 216{
240 int i; 217 int i;
@@ -281,7 +258,6 @@ static struct ion_heap *__ion_system_heap_create(void)
281 if (ion_system_heap_create_pools(heap->pools)) 258 if (ion_system_heap_create_pools(heap->pools))
282 goto free_heap; 259 goto free_heap;
283 260
284 heap->heap.debug_show = ion_system_heap_debug_show;
285 return &heap->heap; 261 return &heap->heap;
286 262
287free_heap: 263free_heap:
diff --git a/drivers/staging/axis-fifo/axis-fifo.c b/drivers/staging/axis-fifo/axis-fifo.c
index abeee0ecc122..c18bf31f55b6 100644
--- a/drivers/staging/axis-fifo/axis-fifo.c
+++ b/drivers/staging/axis-fifo/axis-fifo.c
@@ -27,8 +27,6 @@
27#include <linux/interrupt.h> 27#include <linux/interrupt.h>
28#include <linux/param.h> 28#include <linux/param.h>
29#include <linux/fs.h> 29#include <linux/fs.h>
30#include <linux/device.h>
31#include <linux/cdev.h>
32#include <linux/types.h> 30#include <linux/types.h>
33#include <linux/uaccess.h> 31#include <linux/uaccess.h>
34#include <linux/jiffies.h> 32#include <linux/jiffies.h>
@@ -364,11 +362,11 @@ static ssize_t axis_fifo_read(struct file *f, char __user *buf,
364 * if nothing is currently available 362 * if nothing is currently available
365 */ 363 */
366 spin_lock_irq(&fifo->read_queue_lock); 364 spin_lock_irq(&fifo->read_queue_lock);
367 ret = wait_event_interruptible_lock_irq_timeout( 365 ret = wait_event_interruptible_lock_irq_timeout
368 fifo->read_queue, 366 (fifo->read_queue,
369 ioread32(fifo->base_addr + XLLF_RDFO_OFFSET), 367 ioread32(fifo->base_addr + XLLF_RDFO_OFFSET),
370 fifo->read_queue_lock, 368 fifo->read_queue_lock,
371 (read_timeout >= 0) ? msecs_to_jiffies(read_timeout) : 369 (read_timeout >= 0) ? msecs_to_jiffies(read_timeout) :
372 MAX_SCHEDULE_TIMEOUT); 370 MAX_SCHEDULE_TIMEOUT);
373 spin_unlock_irq(&fifo->read_queue_lock); 371 spin_unlock_irq(&fifo->read_queue_lock);
374 372
@@ -482,12 +480,12 @@ static ssize_t axis_fifo_write(struct file *f, const char __user *buf,
482 * currently enough room in the fifo 480 * currently enough room in the fifo
483 */ 481 */
484 spin_lock_irq(&fifo->write_queue_lock); 482 spin_lock_irq(&fifo->write_queue_lock);
485 ret = wait_event_interruptible_lock_irq_timeout( 483 ret = wait_event_interruptible_lock_irq_timeout
486 fifo->write_queue, 484 (fifo->write_queue,
487 ioread32(fifo->base_addr + XLLF_TDFV_OFFSET) 485 ioread32(fifo->base_addr + XLLF_TDFV_OFFSET)
488 >= words_to_write, 486 >= words_to_write,
489 fifo->write_queue_lock, 487 fifo->write_queue_lock,
490 (write_timeout >= 0) ? msecs_to_jiffies(write_timeout) : 488 (write_timeout >= 0) ? msecs_to_jiffies(write_timeout) :
491 MAX_SCHEDULE_TIMEOUT); 489 MAX_SCHEDULE_TIMEOUT);
492 spin_unlock_irq(&fifo->write_queue_lock); 490 spin_unlock_irq(&fifo->write_queue_lock);
493 491
@@ -1089,6 +1087,8 @@ static int __init axis_fifo_init(void)
1089 pr_info("axis-fifo driver loaded with parameters read_timeout = %i, write_timeout = %i\n", 1087 pr_info("axis-fifo driver loaded with parameters read_timeout = %i, write_timeout = %i\n",
1090 read_timeout, write_timeout); 1088 read_timeout, write_timeout);
1091 axis_fifo_driver_class = class_create(THIS_MODULE, DRIVER_NAME); 1089 axis_fifo_driver_class = class_create(THIS_MODULE, DRIVER_NAME);
1090 if (IS_ERR(axis_fifo_driver_class))
1091 return PTR_ERR(axis_fifo_driver_class);
1092 return platform_driver_register(&axis_fifo_driver); 1092 return platform_driver_register(&axis_fifo_driver);
1093} 1093}
1094 1094
diff --git a/drivers/staging/clocking-wizard/clk-xlnx-clock-wizard.c b/drivers/staging/clocking-wizard/clk-xlnx-clock-wizard.c
index cae7e6e695b0..15b7a82f4b1e 100644
--- a/drivers/staging/clocking-wizard/clk-xlnx-clock-wizard.c
+++ b/drivers/staging/clocking-wizard/clk-xlnx-clock-wizard.c
@@ -199,10 +199,10 @@ static int clk_wzrd_probe(struct platform_device *pdev)
199 ret = -ENOMEM; 199 ret = -ENOMEM;
200 goto err_disable_clk; 200 goto err_disable_clk;
201 } 201 }
202 clk_wzrd->clks_internal[wzrd_clk_mul] = clk_register_fixed_factor( 202 clk_wzrd->clks_internal[wzrd_clk_mul] = clk_register_fixed_factor
203 &pdev->dev, clk_name, 203 (&pdev->dev, clk_name,
204 __clk_get_name(clk_wzrd->clk_in1), 204 __clk_get_name(clk_wzrd->clk_in1),
205 0, reg, 1); 205 0, reg, 1);
206 kfree(clk_name); 206 kfree(clk_name);
207 if (IS_ERR(clk_wzrd->clks_internal[wzrd_clk_mul])) { 207 if (IS_ERR(clk_wzrd->clks_internal[wzrd_clk_mul])) {
208 dev_err(&pdev->dev, "unable to register fixed-factor clock\n"); 208 dev_err(&pdev->dev, "unable to register fixed-factor clock\n");
@@ -219,10 +219,10 @@ static int clk_wzrd_probe(struct platform_device *pdev)
219 goto err_rm_int_clk; 219 goto err_rm_int_clk;
220 } 220 }
221 221
222 clk_wzrd->clks_internal[wzrd_clk_mul_div] = clk_register_fixed_factor( 222 clk_wzrd->clks_internal[wzrd_clk_mul_div] = clk_register_fixed_factor
223 &pdev->dev, clk_name, 223 (&pdev->dev, clk_name,
224 __clk_get_name(clk_wzrd->clks_internal[wzrd_clk_mul]), 224 __clk_get_name(clk_wzrd->clks_internal[wzrd_clk_mul]),
225 0, 1, reg); 225 0, 1, reg);
226 if (IS_ERR(clk_wzrd->clks_internal[wzrd_clk_mul_div])) { 226 if (IS_ERR(clk_wzrd->clks_internal[wzrd_clk_mul_div])) {
227 dev_err(&pdev->dev, "unable to register divider clock\n"); 227 dev_err(&pdev->dev, "unable to register divider clock\n");
228 ret = PTR_ERR(clk_wzrd->clks_internal[wzrd_clk_mul_div]); 228 ret = PTR_ERR(clk_wzrd->clks_internal[wzrd_clk_mul_div]);
@@ -243,8 +243,8 @@ static int clk_wzrd_probe(struct platform_device *pdev)
243 reg = readl(clk_wzrd->base + WZRD_CLK_CFG_REG(2) + i * 12); 243 reg = readl(clk_wzrd->base + WZRD_CLK_CFG_REG(2) + i * 12);
244 reg &= WZRD_CLKOUT_DIVIDE_MASK; 244 reg &= WZRD_CLKOUT_DIVIDE_MASK;
245 reg >>= WZRD_CLKOUT_DIVIDE_SHIFT; 245 reg >>= WZRD_CLKOUT_DIVIDE_SHIFT;
246 clk_wzrd->clkout[i] = clk_register_fixed_factor(&pdev->dev, 246 clk_wzrd->clkout[i] = clk_register_fixed_factor
247 clkout_name, clk_name, 0, 1, reg); 247 (&pdev->dev, clkout_name, clk_name, 0, 1, reg);
248 if (IS_ERR(clk_wzrd->clkout[i])) { 248 if (IS_ERR(clk_wzrd->clkout[i])) {
249 int j; 249 int j;
250 250
diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig
index 583bce9bb18e..9ab1ee7d36bf 100644
--- a/drivers/staging/comedi/Kconfig
+++ b/drivers/staging/comedi/Kconfig
@@ -1313,5 +1313,9 @@ config COMEDI_NI_LABPC_ISADMA
1313 1313
1314config COMEDI_NI_TIO 1314config COMEDI_NI_TIO
1315 tristate 1315 tristate
1316 select COMEDI_NI_ROUTING
1317
1318config COMEDI_NI_ROUTING
1319 tristate
1316 1320
1317endif # COMEDI 1321endif # COMEDI
diff --git a/drivers/staging/comedi/comedi.h b/drivers/staging/comedi/comedi.h
index bb961ac79b7e..e90b17775284 100644
--- a/drivers/staging/comedi/comedi.h
+++ b/drivers/staging/comedi/comedi.h
@@ -107,6 +107,7 @@
107#define INSN_WRITE (1 | INSN_MASK_WRITE) 107#define INSN_WRITE (1 | INSN_MASK_WRITE)
108#define INSN_BITS (2 | INSN_MASK_READ | INSN_MASK_WRITE) 108#define INSN_BITS (2 | INSN_MASK_READ | INSN_MASK_WRITE)
109#define INSN_CONFIG (3 | INSN_MASK_READ | INSN_MASK_WRITE) 109#define INSN_CONFIG (3 | INSN_MASK_READ | INSN_MASK_WRITE)
110#define INSN_DEVICE_CONFIG (INSN_CONFIG | INSN_MASK_SPECIAL)
110#define INSN_GTOD (4 | INSN_MASK_READ | INSN_MASK_SPECIAL) 111#define INSN_GTOD (4 | INSN_MASK_READ | INSN_MASK_SPECIAL)
111#define INSN_WAIT (5 | INSN_MASK_WRITE | INSN_MASK_SPECIAL) 112#define INSN_WAIT (5 | INSN_MASK_WRITE | INSN_MASK_SPECIAL)
112#define INSN_INTTRIG (6 | INSN_MASK_WRITE | INSN_MASK_SPECIAL) 113#define INSN_INTTRIG (6 | INSN_MASK_WRITE | INSN_MASK_SPECIAL)
@@ -301,6 +302,8 @@ enum comedi_io_direction {
301 * @INSN_CONFIG_PWM_SET_H_BRIDGE: Set PWM H bridge duty cycle and polarity for 302 * @INSN_CONFIG_PWM_SET_H_BRIDGE: Set PWM H bridge duty cycle and polarity for
302 * a relay simultaneously. 303 * a relay simultaneously.
303 * @INSN_CONFIG_PWM_GET_H_BRIDGE: Get PWM H bridge duty cycle and polarity. 304 * @INSN_CONFIG_PWM_GET_H_BRIDGE: Get PWM H bridge duty cycle and polarity.
305 * @INSN_CONFIG_GET_CMD_TIMING_CONSTRAINTS: Get the hardware timing restraints,
306 * regardless of trigger sources.
304 */ 307 */
305enum configuration_ids { 308enum configuration_ids {
306 INSN_CONFIG_DIO_INPUT = COMEDI_INPUT, 309 INSN_CONFIG_DIO_INPUT = COMEDI_INPUT,
@@ -344,7 +347,25 @@ enum configuration_ids {
344 INSN_CONFIG_PWM_GET_PERIOD = 5001, 347 INSN_CONFIG_PWM_GET_PERIOD = 5001,
345 INSN_CONFIG_GET_PWM_STATUS = 5002, 348 INSN_CONFIG_GET_PWM_STATUS = 5002,
346 INSN_CONFIG_PWM_SET_H_BRIDGE = 5003, 349 INSN_CONFIG_PWM_SET_H_BRIDGE = 5003,
347 INSN_CONFIG_PWM_GET_H_BRIDGE = 5004 350 INSN_CONFIG_PWM_GET_H_BRIDGE = 5004,
351 INSN_CONFIG_GET_CMD_TIMING_CONSTRAINTS = 5005,
352};
353
354/**
355 * enum device_configuration_ids - COMEDI configuration instruction codes global
356 * to an entire device.
357 * @INSN_DEVICE_CONFIG_TEST_ROUTE: Validate the possibility of a
358 * globally-named route
359 * @INSN_DEVICE_CONFIG_CONNECT_ROUTE: Connect a globally-named route
360 * @INSN_DEVICE_CONFIG_DISCONNECT_ROUTE:Disconnect a globally-named route
361 * @INSN_DEVICE_CONFIG_GET_ROUTES: Get a list of all globally-named routes
362 * that are valid for a particular device.
363 */
364enum device_config_route_ids {
365 INSN_DEVICE_CONFIG_TEST_ROUTE = 0,
366 INSN_DEVICE_CONFIG_CONNECT_ROUTE = 1,
367 INSN_DEVICE_CONFIG_DISCONNECT_ROUTE = 2,
368 INSN_DEVICE_CONFIG_GET_ROUTES = 3,
348}; 369};
349 370
350/** 371/**
@@ -928,6 +949,157 @@ enum i8254_mode {
928 I8254_BINARY = 0 949 I8254_BINARY = 0
929}; 950};
930 951
952/* *** BEGIN GLOBALLY-NAMED NI TERMINALS/SIGNALS *** */
953
954/*
955 * Common National Instruments Terminal/Signal names.
956 * Some of these have no NI_ prefix as they are useful for non-NI hardware, such
957 * as those that utilize the PXI/RTSI trigger lines.
958 *
959 * NOTE ABOUT THE CHOICE OF NAMES HERE AND THE CAMELSCRIPT:
960 * The choice to use CamelScript and the exact names below is for
961 * maintainability, clarity, similarity to manufacturer's documentation,
962 * _and_ a mitigation for confusion that has plagued the use of these drivers
963 * for years!
964 *
965 * More detail:
966 * There have been significant confusions over the past many years for users
967 * when trying to understand how to connect to/from signals and terminals on
968 * NI hardware using comedi. The major reason for this is that the actual
969 * register values were exposed and required to be used by users. Several
970 * major reasons exist why this caused major confusion for users:
971 * 1) The register values are _NOT_ in user documentation, but rather in
972 * arcane locations, such as a few register programming manuals that are
973 * increasingly hard to find and the NI MHDDK (comments in in example code).
974 * There is no one place to find the various valid values of the registers.
975 * 2) The register values are _NOT_ completely consistent. There is no way to
976 * gain any sense of intuition of which values, or even enums one should use
977 * for various registers. There was some attempt in prior use of comedi to
978 * name enums such that a user might know which enums should be used for
979 * varying purposes, but the end-user had to gain a knowledge of register
980 * values to correctly wield this approach.
981 * 3) The names for signals and registers found in the various register level
982 * programming manuals and vendor-provided documentation are _not_ even
983 * close to the same names that are in the end-user documentation.
984 *
985 * Similar, albeit less, confusion plagued NI's previous version of their own
986 * drivers. Earlier than 2003, NI greatly simplified the situation for users
987 * by releasing a new API that abstracted the names of signals/terminals to a
988 * common and intuitive set of names.
989 *
990 * The names below mirror the names chosen and well documented by NI. These
991 * names are exposed to the user via the comedilib user library. By keeping
992 * the names below, in spite of the use of CamelScript, maintenance will be
993 * greatly eased and confusion for users _and_ comedi developers will be
994 * greatly reduced.
995 */
996
997/*
998 * Base of abstracted NI names.
999 * The first 16 bits of *_arg are reserved for channel selection.
1000 * Since we only actually need the first 4 or 5 bits for all register values on
1001 * NI select registers anyways, we'll identify all values >= (1<<15) as being an
1002 * abstracted NI signal/terminal name.
1003 * These values are also used/returned by INSN_DEVICE_CONFIG_TEST_ROUTE,
1004 * INSN_DEVICE_CONFIG_CONNECT_ROUTE, INSN_DEVICE_CONFIG_DISCONNECT_ROUTE,
1005 * and INSN_DEVICE_CONFIG_GET_ROUTES.
1006 */
1007#define NI_NAMES_BASE 0x8000u
1008/*
1009 * not necessarily all allowed 64 PFIs are valid--certainly not for all devices
1010 */
1011#define NI_PFI(x) (NI_NAMES_BASE + ((x) & 0x3f))
1012/* 8 trigger lines by standard, Some devices cannot talk to all eight. */
1013#define TRIGGER_LINE(x) (NI_PFI(-1) + 1 + ((x) & 0x7))
1014/* 4 RTSI shared MUXes to route signals to/from TRIGGER_LINES on NI hardware */
1015#define NI_RTSI_BRD(x) (TRIGGER_LINE(-1) + 1 + ((x) & 0x3))
1016
1017/* *** Counter/timer names : 8 counters max *** */
1018#define NI_COUNTER_NAMES_BASE (NI_RTSI_BRD(-1) + 1)
1019#define NI_MAX_COUNTERS 7
1020#define NI_CtrSource(x) (NI_COUNTER_NAMES_BASE + ((x) & NI_MAX_COUNTERS))
1021/* Gate, Aux, A,B,Z are all treated, at times as gates */
1022#define NI_GATES_NAMES_BASE (NI_CtrSource(-1) + 1)
1023#define NI_CtrGate(x) (NI_GATES_NAMES_BASE + ((x) & NI_MAX_COUNTERS))
1024#define NI_CtrAux(x) (NI_CtrGate(-1) + 1 + ((x) & NI_MAX_COUNTERS))
1025#define NI_CtrA(x) (NI_CtrAux(-1) + 1 + ((x) & NI_MAX_COUNTERS))
1026#define NI_CtrB(x) (NI_CtrA(-1) + 1 + ((x) & NI_MAX_COUNTERS))
1027#define NI_CtrZ(x) (NI_CtrB(-1) + 1 + ((x) & NI_MAX_COUNTERS))
1028#define NI_GATES_NAMES_MAX NI_CtrZ(-1)
1029#define NI_CtrArmStartTrigger(x) (NI_CtrZ(-1) + 1 + ((x) & NI_MAX_COUNTERS))
1030#define NI_CtrInternalOutput(x) \
1031 (NI_CtrArmStartTrigger(-1) + 1 + ((x) & NI_MAX_COUNTERS))
1032/** external pin(s) labeled conveniently as Ctr<i>Out. */
1033#define NI_CtrOut(x) (NI_CtrInternalOutput(-1) + 1 + ((x) & NI_MAX_COUNTERS))
1034/** For Buffered sampling of ctr -- x series capability. */
1035#define NI_CtrSampleClock(x) (NI_CtrOut(-1) + 1 + ((x) & NI_MAX_COUNTERS))
1036#define NI_COUNTER_NAMES_MAX NI_CtrSampleClock(-1)
1037
1038enum ni_common_signal_names {
1039 /* PXI_Star: this is a non-NI-specific signal */
1040 PXI_Star = NI_COUNTER_NAMES_MAX + 1,
1041 PXI_Clk10,
1042 PXIe_Clk100,
1043 NI_AI_SampleClock,
1044 NI_AI_SampleClockTimebase,
1045 NI_AI_StartTrigger,
1046 NI_AI_ReferenceTrigger,
1047 NI_AI_ConvertClock,
1048 NI_AI_ConvertClockTimebase,
1049 NI_AI_PauseTrigger,
1050 NI_AI_HoldCompleteEvent,
1051 NI_AI_HoldComplete,
1052 NI_AI_ExternalMUXClock,
1053 NI_AI_STOP, /* pulse signal that occurs when a update is finished(?) */
1054 NI_AO_SampleClock,
1055 NI_AO_SampleClockTimebase,
1056 NI_AO_StartTrigger,
1057 NI_AO_PauseTrigger,
1058 NI_DI_SampleClock,
1059 NI_DI_SampleClockTimebase,
1060 NI_DI_StartTrigger,
1061 NI_DI_ReferenceTrigger,
1062 NI_DI_PauseTrigger,
1063 NI_DI_InputBufferFull,
1064 NI_DI_ReadyForStartEvent,
1065 NI_DI_ReadyForTransferEventBurst,
1066 NI_DI_ReadyForTransferEventPipelined,
1067 NI_DO_SampleClock,
1068 NI_DO_SampleClockTimebase,
1069 NI_DO_StartTrigger,
1070 NI_DO_PauseTrigger,
1071 NI_DO_OutputBufferFull,
1072 NI_DO_DataActiveEvent,
1073 NI_DO_ReadyForStartEvent,
1074 NI_DO_ReadyForTransferEvent,
1075 NI_MasterTimebase,
1076 NI_20MHzTimebase,
1077 NI_80MHzTimebase,
1078 NI_100MHzTimebase,
1079 NI_200MHzTimebase,
1080 NI_100kHzTimebase,
1081 NI_10MHzRefClock,
1082 NI_FrequencyOutput,
1083 NI_ChangeDetectionEvent,
1084 NI_AnalogComparisonEvent,
1085 NI_WatchdogExpiredEvent,
1086 NI_WatchdogExpirationTrigger,
1087 NI_SCXI_Trig1,
1088 NI_LogicLow,
1089 NI_LogicHigh,
1090 NI_ExternalStrobe,
1091 NI_PFI_DO,
1092 NI_CaseGround,
1093 /* special internal signal used as variable source for RTSI bus: */
1094 NI_RGOUT0,
1095
1096 /* just a name to make the next more convenient, regardless of above */
1097 _NI_NAMES_MAX_PLUS_1,
1098 NI_NUM_NAMES = _NI_NAMES_MAX_PLUS_1 - NI_NAMES_BASE,
1099};
1100
1101/* *** END GLOBALLY-NAMED NI TERMINALS/SIGNALS *** */
1102
931#define NI_USUAL_PFI_SELECT(x) (((x) < 10) ? (0x1 + (x)) : (0xb + (x))) 1103#define NI_USUAL_PFI_SELECT(x) (((x) < 10) ? (0x1 + (x)) : (0xb + (x)))
932#define NI_USUAL_RTSI_SELECT(x) (((x) < 7) ? (0xb + (x)) : 0x1b) 1104#define NI_USUAL_RTSI_SELECT(x) (((x) < 7) ? (0xb + (x)) : 0x1b)
933 1105
diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
index e18b61cdbdeb..c1c6b2b4ab91 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -1216,6 +1216,10 @@ static int check_insn_config_length(struct comedi_insn *insn,
1216 if (insn->n == 6) 1216 if (insn->n == 6)
1217 return 0; 1217 return 0;
1218 break; 1218 break;
1219 case INSN_CONFIG_GET_CMD_TIMING_CONSTRAINTS:
1220 if (insn->n >= 4)
1221 return 0;
1222 break;
1219 /* 1223 /*
1220 * by default we allow the insn since we don't have checks for 1224 * by default we allow the insn since we don't have checks for
1221 * all possible cases yet 1225 * all possible cases yet
@@ -1230,6 +1234,57 @@ static int check_insn_config_length(struct comedi_insn *insn,
1230 return -EINVAL; 1234 return -EINVAL;
1231} 1235}
1232 1236
1237static int check_insn_device_config_length(struct comedi_insn *insn,
1238 unsigned int *data)
1239{
1240 if (insn->n < 1)
1241 return -EINVAL;
1242
1243 switch (data[0]) {
1244 case INSN_DEVICE_CONFIG_TEST_ROUTE:
1245 case INSN_DEVICE_CONFIG_CONNECT_ROUTE:
1246 case INSN_DEVICE_CONFIG_DISCONNECT_ROUTE:
1247 if (insn->n == 3)
1248 return 0;
1249 break;
1250 case INSN_DEVICE_CONFIG_GET_ROUTES:
1251 /*
1252 * Big enough for config_id and the length of the userland
1253 * memory buffer. Additional length should be in factors of 2
1254 * to communicate any returned route pairs (source,destination).
1255 */
1256 if (insn->n >= 2)
1257 return 0;
1258 break;
1259 }
1260 return -EINVAL;
1261}
1262
1263/**
1264 * get_valid_routes() - Calls low-level driver get_valid_routes function to
1265 * either return a count of valid routes to user, or copy
1266 * of list of all valid device routes to buffer in
1267 * userspace.
1268 * @dev: comedi device pointer
1269 * @data: data from user insn call. The length of the data must be >= 2.
1270 * data[0] must contain the INSN_DEVICE_CONFIG config_id.
1271 * data[1](input) contains the number of _pairs_ for which memory is
1272 * allotted from the user. If the user specifies '0', then only
1273 * the number of pairs available is returned.
1274 * data[1](output) returns either the number of pairs available (if none
1275 * where requested) or the number of _pairs_ that are copied back
1276 * to the user.
1277 * data[2::2] returns each (source, destination) pair.
1278 *
1279 * Return: -EINVAL if low-level driver does not allocate and return routes as
1280 * expected. Returns 0 otherwise.
1281 */
1282static int get_valid_routes(struct comedi_device *dev, unsigned int *data)
1283{
1284 data[1] = dev->get_valid_routes(dev, data[1], data + 2);
1285 return 0;
1286}
1287
1233static int parse_insn(struct comedi_device *dev, struct comedi_insn *insn, 1288static int parse_insn(struct comedi_device *dev, struct comedi_insn *insn,
1234 unsigned int *data, void *file) 1289 unsigned int *data, void *file)
1235{ 1290{
@@ -1293,6 +1348,24 @@ static int parse_insn(struct comedi_device *dev, struct comedi_insn *insn,
1293 if (ret >= 0) 1348 if (ret >= 0)
1294 ret = 1; 1349 ret = 1;
1295 break; 1350 break;
1351 case INSN_DEVICE_CONFIG:
1352 ret = check_insn_device_config_length(insn, data);
1353 if (ret)
1354 break;
1355
1356 if (data[0] == INSN_DEVICE_CONFIG_GET_ROUTES) {
1357 /*
1358 * data[1] should be the number of _pairs_ that
1359 * the memory can hold.
1360 */
1361 data[1] = (insn->n - 2) / 2;
1362 ret = get_valid_routes(dev, data);
1363 break;
1364 }
1365
1366 /* other global device config instructions. */
1367 ret = dev->insn_device_config(dev, insn, data);
1368 break;
1296 default: 1369 default:
1297 dev_dbg(dev->class_dev, "invalid insn\n"); 1370 dev_dbg(dev->class_dev, "invalid insn\n");
1298 ret = -EINVAL; 1371 ret = -EINVAL;
diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h
index 5775a93917f4..a7d569cfca5d 100644
--- a/drivers/staging/comedi/comedidev.h
+++ b/drivers/staging/comedi/comedidev.h
@@ -516,6 +516,15 @@ struct comedi_driver {
516 * called when @use_count changes from 0 to 1. 516 * called when @use_count changes from 0 to 1.
517 * @close: Optional pointer to a function set by the low-level driver to be 517 * @close: Optional pointer to a function set by the low-level driver to be
518 * called when @use_count changed from 1 to 0. 518 * called when @use_count changed from 1 to 0.
519 * @insn_device_config: Optional pointer to a handler for all sub-instructions
520 * except %INSN_DEVICE_CONFIG_GET_ROUTES of the %INSN_DEVICE_CONFIG
521 * instruction. If this is not initialized by the low-level driver, a
522 * default handler will be set during post-configuration.
523 * @get_valid_routes: Optional pointer to a handler for the
524 * %INSN_DEVICE_CONFIG_GET_ROUTES sub-instruction of the
525 * %INSN_DEVICE_CONFIG instruction set. If this is not initialized by the
526 * low-level driver, a default handler that copies zero routes back to the
527 * user will be used.
519 * 528 *
520 * This is the main control data structure for a COMEDI device (as far as the 529 * This is the main control data structure for a COMEDI device (as far as the
521 * COMEDI core is concerned). There are two groups of COMEDI devices - 530 * COMEDI core is concerned). There are two groups of COMEDI devices -
@@ -565,6 +574,11 @@ struct comedi_device {
565 574
566 int (*open)(struct comedi_device *dev); 575 int (*open)(struct comedi_device *dev);
567 void (*close)(struct comedi_device *dev); 576 void (*close)(struct comedi_device *dev);
577 int (*insn_device_config)(struct comedi_device *dev,
578 struct comedi_insn *insn, unsigned int *data);
579 unsigned int (*get_valid_routes)(struct comedi_device *dev,
580 unsigned int n_pairs,
581 unsigned int *pair_data);
568}; 582};
569 583
570/* 584/*
diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c
index 57dd63d548b7..eefa62f42c0f 100644
--- a/drivers/staging/comedi/drivers.c
+++ b/drivers/staging/comedi/drivers.c
@@ -211,6 +211,19 @@ static int poll_invalid(struct comedi_device *dev, struct comedi_subdevice *s)
211 return -EINVAL; 211 return -EINVAL;
212} 212}
213 213
214static int insn_device_inval(struct comedi_device *dev,
215 struct comedi_insn *insn, unsigned int *data)
216{
217 return -EINVAL;
218}
219
220static unsigned int get_zero_valid_routes(struct comedi_device *dev,
221 unsigned int n_pairs,
222 unsigned int *pair_data)
223{
224 return 0;
225}
226
214int insn_inval(struct comedi_device *dev, struct comedi_subdevice *s, 227int insn_inval(struct comedi_device *dev, struct comedi_subdevice *s,
215 struct comedi_insn *insn, unsigned int *data) 228 struct comedi_insn *insn, unsigned int *data)
216{ 229{
@@ -652,6 +665,12 @@ static int __comedi_device_postconfig(struct comedi_device *dev)
652 int ret; 665 int ret;
653 int i; 666 int i;
654 667
668 if (!dev->insn_device_config)
669 dev->insn_device_config = insn_device_inval;
670
671 if (!dev->get_valid_routes)
672 dev->get_valid_routes = get_zero_valid_routes;
673
655 for (i = 0; i < dev->n_subdevices; i++) { 674 for (i = 0; i < dev->n_subdevices; i++) {
656 s = &dev->subdevices[i]; 675 s = &dev->subdevices[i];
657 676
diff --git a/drivers/staging/comedi/drivers/Makefile b/drivers/staging/comedi/drivers/Makefile
index 98b42b47dfe1..b24ac00cab73 100644
--- a/drivers/staging/comedi/drivers/Makefile
+++ b/drivers/staging/comedi/drivers/Makefile
@@ -137,6 +137,33 @@ obj-$(CONFIG_COMEDI_VMK80XX) += vmk80xx.o
137obj-$(CONFIG_COMEDI_MITE) += mite.o 137obj-$(CONFIG_COMEDI_MITE) += mite.o
138obj-$(CONFIG_COMEDI_NI_TIO) += ni_tio.o 138obj-$(CONFIG_COMEDI_NI_TIO) += ni_tio.o
139obj-$(CONFIG_COMEDI_NI_TIOCMD) += ni_tiocmd.o 139obj-$(CONFIG_COMEDI_NI_TIOCMD) += ni_tiocmd.o
140obj-$(CONFIG_COMEDI_NI_ROUTING) += ni_routing.o
141ni_routing-objs += ni_routes.o \
142 ni_routing/ni_route_values.o \
143 ni_routing/ni_route_values/ni_660x.o \
144 ni_routing/ni_route_values/ni_eseries.o \
145 ni_routing/ni_route_values/ni_mseries.o \
146 ni_routing/ni_device_routes.o \
147 ni_routing/ni_device_routes/pxi-6030e.o \
148 ni_routing/ni_device_routes/pci-6070e.o \
149 ni_routing/ni_device_routes/pci-6220.o \
150 ni_routing/ni_device_routes/pci-6221.o \
151 ni_routing/ni_device_routes/pxi-6224.o \
152 ni_routing/ni_device_routes/pxi-6225.o \
153 ni_routing/ni_device_routes/pci-6229.o \
154 ni_routing/ni_device_routes/pci-6251.o \
155 ni_routing/ni_device_routes/pxi-6251.o \
156 ni_routing/ni_device_routes/pxie-6251.o \
157 ni_routing/ni_device_routes/pci-6254.o \
158 ni_routing/ni_device_routes/pci-6259.o \
159 ni_routing/ni_device_routes/pci-6534.o \
160 ni_routing/ni_device_routes/pxie-6535.o \
161 ni_routing/ni_device_routes/pci-6602.o \
162 ni_routing/ni_device_routes/pci-6713.o \
163 ni_routing/ni_device_routes/pci-6723.o \
164 ni_routing/ni_device_routes/pci-6733.o \
165 ni_routing/ni_device_routes/pxi-6733.o \
166 ni_routing/ni_device_routes/pxie-6738.o
140obj-$(CONFIG_COMEDI_NI_LABPC) += ni_labpc_common.o 167obj-$(CONFIG_COMEDI_NI_LABPC) += ni_labpc_common.o
141obj-$(CONFIG_COMEDI_NI_LABPC_ISADMA) += ni_labpc_isadma.o 168obj-$(CONFIG_COMEDI_NI_LABPC_ISADMA) += ni_labpc_isadma.o
142 169
@@ -145,3 +172,4 @@ obj-$(CONFIG_COMEDI_8255_SA) += 8255.o
145obj-$(CONFIG_COMEDI_AMPLC_DIO200) += amplc_dio200_common.o 172obj-$(CONFIG_COMEDI_AMPLC_DIO200) += amplc_dio200_common.o
146obj-$(CONFIG_COMEDI_AMPLC_PC236) += amplc_pc236_common.o 173obj-$(CONFIG_COMEDI_AMPLC_PC236) += amplc_pc236_common.o
147obj-$(CONFIG_COMEDI_DAS08) += das08.o 174obj-$(CONFIG_COMEDI_DAS08) += das08.o
175obj-$(CONFIG_COMEDI_TESTS) += tests/
diff --git a/drivers/staging/comedi/drivers/comedi_test.c b/drivers/staging/comedi/drivers/comedi_test.c
index d437af721bd8..ef4c7c8a2b71 100644
--- a/drivers/staging/comedi/drivers/comedi_test.c
+++ b/drivers/staging/comedi/drivers/comedi_test.c
@@ -626,6 +626,48 @@ static int waveform_ao_insn_write(struct comedi_device *dev,
626 return insn->n; 626 return insn->n;
627} 627}
628 628
629static int waveform_ai_insn_config(struct comedi_device *dev,
630 struct comedi_subdevice *s,
631 struct comedi_insn *insn,
632 unsigned int *data)
633{
634 if (data[0] == INSN_CONFIG_GET_CMD_TIMING_CONSTRAINTS) {
635 /*
636 * input: data[1], data[2] : scan_begin_src, convert_src
637 * output: data[1], data[2] : scan_begin_min, convert_min
638 */
639 if (data[1] == TRIG_FOLLOW) {
640 /* exactly TRIG_FOLLOW case */
641 data[1] = 0;
642 data[2] = NSEC_PER_USEC;
643 } else {
644 data[1] = NSEC_PER_USEC;
645 if (data[2] & TRIG_TIMER)
646 data[2] = NSEC_PER_USEC;
647 else
648 data[2] = 0;
649 }
650 return 0;
651 }
652
653 return -EINVAL;
654}
655
656static int waveform_ao_insn_config(struct comedi_device *dev,
657 struct comedi_subdevice *s,
658 struct comedi_insn *insn,
659 unsigned int *data)
660{
661 if (data[0] == INSN_CONFIG_GET_CMD_TIMING_CONSTRAINTS) {
662 /* we don't care about actual channels */
663 data[1] = NSEC_PER_USEC; /* scan_begin_min */
664 data[2] = 0; /* convert_min */
665 return 0;
666 }
667
668 return -EINVAL;
669}
670
629static int waveform_common_attach(struct comedi_device *dev, 671static int waveform_common_attach(struct comedi_device *dev,
630 int amplitude, int period) 672 int amplitude, int period)
631{ 673{
@@ -658,6 +700,7 @@ static int waveform_common_attach(struct comedi_device *dev,
658 s->do_cmd = waveform_ai_cmd; 700 s->do_cmd = waveform_ai_cmd;
659 s->do_cmdtest = waveform_ai_cmdtest; 701 s->do_cmdtest = waveform_ai_cmdtest;
660 s->cancel = waveform_ai_cancel; 702 s->cancel = waveform_ai_cancel;
703 s->insn_config = waveform_ai_insn_config;
661 704
662 s = &dev->subdevices[1]; 705 s = &dev->subdevices[1];
663 dev->write_subdev = s; 706 dev->write_subdev = s;
@@ -673,6 +716,7 @@ static int waveform_common_attach(struct comedi_device *dev,
673 s->do_cmd = waveform_ao_cmd; 716 s->do_cmd = waveform_ao_cmd;
674 s->do_cmdtest = waveform_ao_cmdtest; 717 s->do_cmdtest = waveform_ao_cmdtest;
675 s->cancel = waveform_ao_cancel; 718 s->cancel = waveform_ao_cancel;
719 s->insn_config = waveform_ao_insn_config;
676 720
677 /* Our default loopback value is just a 0V flatline */ 721 /* Our default loopback value is just a 0V flatline */
678 for (i = 0; i < s->n_chan; i++) 722 for (i = 0; i < s->n_chan; i++)
diff --git a/drivers/staging/comedi/drivers/ni_660x.c b/drivers/staging/comedi/drivers/ni_660x.c
index e521ed9d0887..e70a461e723f 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -7,7 +7,7 @@
7 * Driver: ni_660x 7 * Driver: ni_660x
8 * Description: National Instruments 660x counter/timer boards 8 * Description: National Instruments 660x counter/timer boards
9 * Devices: [National Instruments] PCI-6601 (ni_660x), PCI-6602, PXI-6602, 9 * Devices: [National Instruments] PCI-6601 (ni_660x), PCI-6602, PXI-6602,
10 * PXI-6608, PCI-6624, PXI-6624 10 * PCI-6608, PXI-6608, PCI-6624, PXI-6624
11 * Author: J.P. Mellor <jpmellor@rose-hulman.edu>, 11 * Author: J.P. Mellor <jpmellor@rose-hulman.edu>,
12 * Herman.Bruyninckx@mech.kuleuven.ac.be, 12 * Herman.Bruyninckx@mech.kuleuven.ac.be,
13 * Wim.Meeussen@mech.kuleuven.ac.be, 13 * Wim.Meeussen@mech.kuleuven.ac.be,
@@ -31,6 +31,7 @@
31 31
32#include "mite.h" 32#include "mite.h"
33#include "ni_tio.h" 33#include "ni_tio.h"
34#include "ni_routes.h"
34 35
35/* See Register-Level Programmer Manual page 3.1 */ 36/* See Register-Level Programmer Manual page 3.1 */
36enum ni_660x_register { 37enum ni_660x_register {
@@ -201,6 +202,7 @@ enum ni_660x_boardid {
201 BOARD_PCI6601, 202 BOARD_PCI6601,
202 BOARD_PCI6602, 203 BOARD_PCI6602,
203 BOARD_PXI6602, 204 BOARD_PXI6602,
205 BOARD_PCI6608,
204 BOARD_PXI6608, 206 BOARD_PXI6608,
205 BOARD_PCI6624, 207 BOARD_PCI6624,
206 BOARD_PXI6624 208 BOARD_PXI6624
@@ -224,6 +226,10 @@ static const struct ni_660x_board ni_660x_boards[] = {
224 .name = "PXI-6602", 226 .name = "PXI-6602",
225 .n_chips = 2, 227 .n_chips = 2,
226 }, 228 },
229 [BOARD_PCI6608] = {
230 .name = "PCI-6608",
231 .n_chips = 2,
232 },
227 [BOARD_PXI6608] = { 233 [BOARD_PXI6608] = {
228 .name = "PXI-6608", 234 .name = "PXI-6608",
229 .n_chips = 2, 235 .n_chips = 2,
@@ -259,6 +265,7 @@ struct ni_660x_private {
259 unsigned int dma_cfg[NI660X_MAX_CHIPS]; 265 unsigned int dma_cfg[NI660X_MAX_CHIPS];
260 unsigned int io_cfg[NI660X_NUM_PFI_CHANNELS]; 266 unsigned int io_cfg[NI660X_NUM_PFI_CHANNELS];
261 u64 io_dir; 267 u64 io_dir;
268 struct ni_route_tables routing_tables;
262}; 269};
263 270
264static void ni_660x_write(struct comedi_device *dev, unsigned int chip, 271static void ni_660x_write(struct comedi_device *dev, unsigned int chip,
@@ -561,6 +568,10 @@ static void ni_660x_select_pfi_output(struct comedi_device *dev,
561 unsigned int idle_chip = 0; 568 unsigned int idle_chip = 0;
562 unsigned int bits; 569 unsigned int bits;
563 570
571 if (chan >= NI_PFI(0))
572 /* allow new and old names of pfi channels to work. */
573 chan -= NI_PFI(0);
574
564 if (board->n_chips > 1) { 575 if (board->n_chips > 1) {
565 if (out_sel == NI_660X_PFI_OUTPUT_COUNTER && 576 if (out_sel == NI_660X_PFI_OUTPUT_COUNTER &&
566 chan >= 8 && chan <= 23) { 577 chan >= 8 && chan <= 23) {
@@ -589,11 +600,54 @@ static void ni_660x_select_pfi_output(struct comedi_device *dev,
589 ni_660x_write(dev, active_chip, bits, NI660X_IO_CFG(chan)); 600 ni_660x_write(dev, active_chip, bits, NI660X_IO_CFG(chan));
590} 601}
591 602
603static void ni_660x_set_pfi_direction(struct comedi_device *dev,
604 unsigned int chan,
605 unsigned int direction)
606{
607 struct ni_660x_private *devpriv = dev->private;
608 u64 bit;
609
610 if (chan >= NI_PFI(0))
611 /* allow new and old names of pfi channels to work. */
612 chan -= NI_PFI(0);
613
614 bit = 1ULL << chan;
615
616 if (direction == COMEDI_OUTPUT) {
617 devpriv->io_dir |= bit;
618 /* reset the output to currently assigned output value */
619 ni_660x_select_pfi_output(dev, chan, devpriv->io_cfg[chan]);
620 } else {
621 devpriv->io_dir &= ~bit;
622 /* set pin to high-z; do not change currently assigned route */
623 ni_660x_select_pfi_output(dev, chan, 0);
624 }
625}
626
627static unsigned int ni_660x_get_pfi_direction(struct comedi_device *dev,
628 unsigned int chan)
629{
630 struct ni_660x_private *devpriv = dev->private;
631 u64 bit;
632
633 if (chan >= NI_PFI(0))
634 /* allow new and old names of pfi channels to work. */
635 chan -= NI_PFI(0);
636
637 bit = 1ULL << chan;
638
639 return (devpriv->io_dir & bit) ? COMEDI_OUTPUT : COMEDI_INPUT;
640}
641
592static int ni_660x_set_pfi_routing(struct comedi_device *dev, 642static int ni_660x_set_pfi_routing(struct comedi_device *dev,
593 unsigned int chan, unsigned int source) 643 unsigned int chan, unsigned int source)
594{ 644{
595 struct ni_660x_private *devpriv = dev->private; 645 struct ni_660x_private *devpriv = dev->private;
596 646
647 if (chan >= NI_PFI(0))
648 /* allow new and old names of pfi channels to work. */
649 chan -= NI_PFI(0);
650
597 switch (source) { 651 switch (source) {
598 case NI_660X_PFI_OUTPUT_COUNTER: 652 case NI_660X_PFI_OUTPUT_COUNTER:
599 if (chan < 8) 653 if (chan < 8)
@@ -607,36 +661,56 @@ static int ni_660x_set_pfi_routing(struct comedi_device *dev,
607 } 661 }
608 662
609 devpriv->io_cfg[chan] = source; 663 devpriv->io_cfg[chan] = source;
610 if (devpriv->io_dir & (1ULL << chan)) 664 if (ni_660x_get_pfi_direction(dev, chan) == COMEDI_OUTPUT)
611 ni_660x_select_pfi_output(dev, chan, devpriv->io_cfg[chan]); 665 ni_660x_select_pfi_output(dev, chan, devpriv->io_cfg[chan]);
612 return 0; 666 return 0;
613} 667}
614 668
669static int ni_660x_get_pfi_routing(struct comedi_device *dev, unsigned int chan)
670{
671 struct ni_660x_private *devpriv = dev->private;
672
673 if (chan >= NI_PFI(0))
674 /* allow new and old names of pfi channels to work. */
675 chan -= NI_PFI(0);
676
677 return devpriv->io_cfg[chan];
678}
679
680static void ni_660x_set_pfi_filter(struct comedi_device *dev,
681 unsigned int chan, unsigned int value)
682{
683 unsigned int val;
684
685 if (chan >= NI_PFI(0))
686 /* allow new and old names of pfi channels to work. */
687 chan -= NI_PFI(0);
688
689 val = ni_660x_read(dev, 0, NI660X_IO_CFG(chan));
690 val &= ~NI660X_IO_CFG_IN_SEL_MASK(chan);
691 val |= NI660X_IO_CFG_IN_SEL(chan, value);
692 ni_660x_write(dev, 0, val, NI660X_IO_CFG(chan));
693}
694
615static int ni_660x_dio_insn_config(struct comedi_device *dev, 695static int ni_660x_dio_insn_config(struct comedi_device *dev,
616 struct comedi_subdevice *s, 696 struct comedi_subdevice *s,
617 struct comedi_insn *insn, 697 struct comedi_insn *insn,
618 unsigned int *data) 698 unsigned int *data)
619{ 699{
620 struct ni_660x_private *devpriv = dev->private;
621 unsigned int chan = CR_CHAN(insn->chanspec); 700 unsigned int chan = CR_CHAN(insn->chanspec);
622 u64 bit = 1ULL << chan;
623 unsigned int val;
624 int ret; 701 int ret;
625 702
626 switch (data[0]) { 703 switch (data[0]) {
627 case INSN_CONFIG_DIO_OUTPUT: 704 case INSN_CONFIG_DIO_OUTPUT:
628 devpriv->io_dir |= bit; 705 ni_660x_set_pfi_direction(dev, chan, COMEDI_OUTPUT);
629 ni_660x_select_pfi_output(dev, chan, devpriv->io_cfg[chan]);
630 break; 706 break;
631 707
632 case INSN_CONFIG_DIO_INPUT: 708 case INSN_CONFIG_DIO_INPUT:
633 devpriv->io_dir &= ~bit; 709 ni_660x_set_pfi_direction(dev, chan, COMEDI_INPUT);
634 ni_660x_select_pfi_output(dev, chan, 0); /* high-z */
635 break; 710 break;
636 711
637 case INSN_CONFIG_DIO_QUERY: 712 case INSN_CONFIG_DIO_QUERY:
638 data[1] = (devpriv->io_dir & bit) ? COMEDI_OUTPUT 713 data[1] = ni_660x_get_pfi_direction(dev, chan);
639 : COMEDI_INPUT;
640 break; 714 break;
641 715
642 case INSN_CONFIG_SET_ROUTING: 716 case INSN_CONFIG_SET_ROUTING:
@@ -646,14 +720,11 @@ static int ni_660x_dio_insn_config(struct comedi_device *dev,
646 break; 720 break;
647 721
648 case INSN_CONFIG_GET_ROUTING: 722 case INSN_CONFIG_GET_ROUTING:
649 data[1] = devpriv->io_cfg[chan]; 723 data[1] = ni_660x_get_pfi_routing(dev, chan);
650 break; 724 break;
651 725
652 case INSN_CONFIG_FILTER: 726 case INSN_CONFIG_FILTER:
653 val = ni_660x_read(dev, 0, NI660X_IO_CFG(chan)); 727 ni_660x_set_pfi_filter(dev, chan, data[1]);
654 val &= ~NI660X_IO_CFG_IN_SEL_MASK(chan);
655 val |= NI660X_IO_CFG_IN_SEL(chan, data[1]);
656 ni_660x_write(dev, 0, val, NI660X_IO_CFG(chan));
657 break; 728 break;
658 729
659 default: 730 default:
@@ -663,6 +734,240 @@ static int ni_660x_dio_insn_config(struct comedi_device *dev,
663 return insn->n; 734 return insn->n;
664} 735}
665 736
737static unsigned int _ni_get_valid_routes(struct comedi_device *dev,
738 unsigned int n_pairs,
739 unsigned int *pair_data)
740{
741 struct ni_660x_private *devpriv = dev->private;
742
743 return ni_get_valid_routes(&devpriv->routing_tables, n_pairs,
744 pair_data);
745}
746
747/*
748 * Retrieves the current source of the output selector for the given
749 * destination. If the terminal for the destination is not already configured
750 * as an output, this function returns -EINVAL as error.
751 *
752 * Return: The register value of the destination output selector;
753 * -EINVAL if terminal is not configured for output.
754 */
755static inline int get_output_select_source(int dest, struct comedi_device *dev)
756{
757 struct ni_660x_private *devpriv = dev->private;
758 int reg = -1;
759
760 if (channel_is_pfi(dest)) {
761 if (ni_660x_get_pfi_direction(dev, dest) == COMEDI_OUTPUT)
762 reg = ni_660x_get_pfi_routing(dev, dest);
763 } else if (channel_is_rtsi(dest)) {
764 dev_dbg(dev->class_dev,
765 "%s: unhandled rtsi destination (%d) queried\n",
766 __func__, dest);
767 /*
768 * The following can be enabled when RTSI routing info is
769 * determined (not currently documented):
770 * if (ni_get_rtsi_direction(dev, dest) == COMEDI_OUTPUT) {
771 * reg = ni_get_rtsi_routing(dev, dest);
772
773 * if (reg == NI_RTSI_OUTPUT_RGOUT0) {
774 * dest = NI_RGOUT0; ** prepare for lookup below **
775 * reg = get_rgout0_reg(dev);
776 * } else if (reg >= NI_RTSI_OUTPUT_RTSI_BRD(0) &&
777 * reg <= NI_RTSI_OUTPUT_RTSI_BRD(3)) {
778 * const int i = reg - NI_RTSI_OUTPUT_RTSI_BRD(0);
779
780 * dest = NI_RTSI_BRD(i); ** prepare for lookup **
781 * reg = get_ith_rtsi_brd_reg(i, dev);
782 * }
783 * }
784 */
785 } else if (channel_is_ctr(dest)) {
786 reg = ni_tio_get_routing(devpriv->counter_dev, dest);
787 } else {
788 dev_dbg(dev->class_dev,
789 "%s: unhandled destination (%d) queried\n",
790 __func__, dest);
791 }
792
793 if (reg >= 0)
794 return ni_find_route_source(CR_CHAN(reg), dest,
795 &devpriv->routing_tables);
796 return -EINVAL;
797}
798
799/*
800 * Test a route:
801 *
802 * Return: -1 if not connectible;
803 * 0 if connectible and not connected;
804 * 1 if connectible and connected.
805 */
806static inline int test_route(unsigned int src, unsigned int dest,
807 struct comedi_device *dev)
808{
809 struct ni_660x_private *devpriv = dev->private;
810 s8 reg = ni_route_to_register(CR_CHAN(src), dest,
811 &devpriv->routing_tables);
812
813 if (reg < 0)
814 return -1;
815 if (get_output_select_source(dest, dev) != CR_CHAN(src))
816 return 0;
817 return 1;
818}
819
820/* Connect the actual route. */
821static inline int connect_route(unsigned int src, unsigned int dest,
822 struct comedi_device *dev)
823{
824 struct ni_660x_private *devpriv = dev->private;
825 s8 reg = ni_route_to_register(CR_CHAN(src), dest,
826 &devpriv->routing_tables);
827 s8 current_src;
828
829 if (reg < 0)
830 /* route is not valid */
831 return -EINVAL;
832
833 current_src = get_output_select_source(dest, dev);
834 if (current_src == CR_CHAN(src))
835 return -EALREADY;
836 if (current_src >= 0)
837 /* destination mux is already busy. complain, don't overwrite */
838 return -EBUSY;
839
840 /* The route is valid and available. Now connect... */
841 if (channel_is_pfi(CR_CHAN(dest))) {
842 /*
843 * set routing and then direction so that the output does not
844 * first get generated with the wrong pin
845 */
846 ni_660x_set_pfi_routing(dev, dest, reg);
847 ni_660x_set_pfi_direction(dev, dest, COMEDI_OUTPUT);
848 } else if (channel_is_rtsi(CR_CHAN(dest))) {
849 dev_dbg(dev->class_dev, "%s: unhandled rtsi destination (%d)\n",
850 __func__, dest);
851 return -EINVAL;
852 /*
853 * The following can be enabled when RTSI routing info is
854 * determined (not currently documented):
855 * if (reg == NI_RTSI_OUTPUT_RGOUT0) {
856 * int ret = incr_rgout0_src_use(src, dev);
857
858 * if (ret < 0)
859 * return ret;
860 * } else if (ni_rtsi_route_requires_mux(reg)) {
861 * ** Attempt to allocate and route (src->brd) **
862 * int brd = incr_rtsi_brd_src_use(src, dev);
863
864 * if (brd < 0)
865 * return brd;
866
867 * ** Now lookup the register value for (brd->dest) **
868 * reg = ni_lookup_route_register(brd, CR_CHAN(dest),
869 * &devpriv->routing_tables);
870 * }
871
872 * ni_set_rtsi_direction(dev, dest, COMEDI_OUTPUT);
873 * ni_set_rtsi_routing(dev, dest, reg);
874 */
875 } else if (channel_is_ctr(CR_CHAN(dest))) {
876 /*
877 * we are adding back the channel modifier info to set
878 * invert/edge info passed by the user
879 */
880 ni_tio_set_routing(devpriv->counter_dev, dest,
881 reg | (src & ~CR_CHAN(-1)));
882 } else {
883 return -EINVAL;
884 }
885 return 0;
886}
887
888static inline int disconnect_route(unsigned int src, unsigned int dest,
889 struct comedi_device *dev)
890{
891 struct ni_660x_private *devpriv = dev->private;
892 s8 reg = ni_route_to_register(CR_CHAN(src), CR_CHAN(dest),
893 &devpriv->routing_tables);
894
895 if (reg < 0)
896 /* route is not valid */
897 return -EINVAL;
898 if (get_output_select_source(dest, dev) != CR_CHAN(src))
899 /* cannot disconnect something not connected */
900 return -EINVAL;
901
902 /* The route is valid and is connected. Now disconnect... */
903 if (channel_is_pfi(CR_CHAN(dest))) {
904 unsigned int source = ((CR_CHAN(dest) - NI_PFI(0)) < 8)
905 ? NI_660X_PFI_OUTPUT_DIO
906 : NI_660X_PFI_OUTPUT_COUNTER;
907
908 /* set the pfi to high impedance, and disconnect */
909 ni_660x_set_pfi_direction(dev, dest, COMEDI_INPUT);
910 ni_660x_set_pfi_routing(dev, dest, source);
911 } else if (channel_is_rtsi(CR_CHAN(dest))) {
912 dev_dbg(dev->class_dev, "%s: unhandled rtsi destination (%d)\n",
913 __func__, dest);
914 return -EINVAL;
915 /*
916 * The following can be enabled when RTSI routing info is
917 * determined (not currently documented):
918 * if (reg == NI_RTSI_OUTPUT_RGOUT0) {
919 * int ret = decr_rgout0_src_use(src, dev);
920
921 * if (ret < 0)
922 * return ret;
923 * } else if (ni_rtsi_route_requires_mux(reg)) {
924 * ** find which RTSI_BRD line is source for rtsi pin **
925 * int brd = ni_find_route_source(
926 * ni_get_rtsi_routing(dev, dest), CR_CHAN(dest),
927 * &devpriv->routing_tables);
928
929 * if (brd < 0)
930 * return brd;
931
932 * ** decrement/disconnect RTSI_BRD line from source **
933 * decr_rtsi_brd_src_use(src, brd, dev);
934 * }
935
936 * ** set rtsi output selector to default state **
937 * reg = default_rtsi_routing[CR_CHAN(dest) - TRIGGER_LINE(0)];
938 * ni_set_rtsi_direction(dev, dest, COMEDI_INPUT);
939 * ni_set_rtsi_routing(dev, dest, reg);
940 */
941 } else if (channel_is_ctr(CR_CHAN(dest))) {
942 ni_tio_unset_routing(devpriv->counter_dev, dest);
943 } else {
944 return -EINVAL;
945 }
946 return 0;
947}
948
949static int ni_global_insn_config(struct comedi_device *dev,
950 struct comedi_insn *insn,
951 unsigned int *data)
952{
953 switch (data[0]) {
954 case INSN_DEVICE_CONFIG_TEST_ROUTE:
955 data[0] = test_route(data[1], data[2], dev);
956 return 2;
957 case INSN_DEVICE_CONFIG_CONNECT_ROUTE:
958 return connect_route(data[1], data[2], dev);
959 case INSN_DEVICE_CONFIG_DISCONNECT_ROUTE:
960 return disconnect_route(data[1], data[2], dev);
961 /*
962 * This case is already handled one level up.
963 * case INSN_DEVICE_CONFIG_GET_ROUTES:
964 */
965 default:
966 return -EINVAL;
967 }
968 return 1;
969}
970
666static void ni_660x_init_tio_chips(struct comedi_device *dev, 971static void ni_660x_init_tio_chips(struct comedi_device *dev,
667 unsigned int n_chips) 972 unsigned int n_chips)
668{ 973{
@@ -730,12 +1035,30 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
730 1035
731 ni_660x_init_tio_chips(dev, board->n_chips); 1036 ni_660x_init_tio_chips(dev, board->n_chips);
732 1037
1038 /* prepare the device for globally-named routes. */
1039 if (ni_assign_device_routes("ni_660x", board->name,
1040 &devpriv->routing_tables) < 0) {
1041 dev_warn(dev->class_dev, "%s: %s device has no signal routing table.\n",
1042 __func__, board->name);
1043 dev_warn(dev->class_dev, "%s: High level NI signal names will not be available for this %s board.\n",
1044 __func__, board->name);
1045 } else {
1046 /*
1047 * only(?) assign insn_device_config if we have global names for
1048 * this device.
1049 */
1050 dev->insn_device_config = ni_global_insn_config;
1051 dev->get_valid_routes = _ni_get_valid_routes;
1052 }
1053
733 n_counters = board->n_chips * NI660X_COUNTERS_PER_CHIP; 1054 n_counters = board->n_chips * NI660X_COUNTERS_PER_CHIP;
734 gpct_dev = ni_gpct_device_construct(dev, 1055 gpct_dev = ni_gpct_device_construct(dev,
735 ni_660x_gpct_write, 1056 ni_660x_gpct_write,
736 ni_660x_gpct_read, 1057 ni_660x_gpct_read,
737 ni_gpct_variant_660x, 1058 ni_gpct_variant_660x,
738 n_counters); 1059 n_counters,
1060 NI660X_COUNTERS_PER_CHIP,
1061 &devpriv->routing_tables);
739 if (!gpct_dev) 1062 if (!gpct_dev)
740 return -ENOMEM; 1063 return -ENOMEM;
741 devpriv->counter_dev = gpct_dev; 1064 devpriv->counter_dev = gpct_dev;
@@ -822,7 +1145,7 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
822 : NI_660X_PFI_OUTPUT_COUNTER; 1145 : NI_660X_PFI_OUTPUT_COUNTER;
823 1146
824 ni_660x_set_pfi_routing(dev, i, source); 1147 ni_660x_set_pfi_routing(dev, i, source);
825 ni_660x_select_pfi_output(dev, i, 0); /* high-z */ 1148 ni_660x_set_pfi_direction(dev, i, COMEDI_INPUT);/* high-z */
826 } 1149 }
827 1150
828 /* Counter subdevices (4 NI TIO General Purpose Counters per chip) */ 1151 /* Counter subdevices (4 NI TIO General Purpose Counters per chip) */
@@ -831,9 +1154,6 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
831 if (i < n_counters) { 1154 if (i < n_counters) {
832 struct ni_gpct *counter = &gpct_dev->counters[i]; 1155 struct ni_gpct *counter = &gpct_dev->counters[i];
833 1156
834 counter->chip_index = i / NI660X_COUNTERS_PER_CHIP;
835 counter->counter_index = i % NI660X_COUNTERS_PER_CHIP;
836
837 s->type = COMEDI_SUBD_COUNTER; 1157 s->type = COMEDI_SUBD_COUNTER;
838 s->subdev_flags = SDF_READABLE | SDF_WRITABLE | 1158 s->subdev_flags = SDF_READABLE | SDF_WRITABLE |
839 SDF_LSAMPL | SDF_CMD_READ; 1159 SDF_LSAMPL | SDF_CMD_READ;
@@ -915,6 +1235,7 @@ static const struct pci_device_id ni_660x_pci_table[] = {
915 { PCI_VDEVICE(NI, 0x1310), BOARD_PCI6602 }, 1235 { PCI_VDEVICE(NI, 0x1310), BOARD_PCI6602 },
916 { PCI_VDEVICE(NI, 0x1360), BOARD_PXI6602 }, 1236 { PCI_VDEVICE(NI, 0x1360), BOARD_PXI6602 },
917 { PCI_VDEVICE(NI, 0x2c60), BOARD_PCI6601 }, 1237 { PCI_VDEVICE(NI, 0x2c60), BOARD_PCI6601 },
1238 { PCI_VDEVICE(NI, 0x2db0), BOARD_PCI6608 },
918 { PCI_VDEVICE(NI, 0x2cc0), BOARD_PXI6608 }, 1239 { PCI_VDEVICE(NI, 0x2cc0), BOARD_PXI6608 },
919 { PCI_VDEVICE(NI, 0x1e30), BOARD_PCI6624 }, 1240 { PCI_VDEVICE(NI, 0x1e30), BOARD_PCI6624 },
920 { PCI_VDEVICE(NI, 0x1e40), BOARD_PXI6624 }, 1241 { PCI_VDEVICE(NI, 0x1e40), BOARD_PXI6624 },
diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c b/drivers/staging/comedi/drivers/ni_mio_common.c
index 4dee2fc37aed..2d1e0325d04d 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -351,7 +351,8 @@ static const struct mio_regmap m_series_stc_write_regmap[] = {
351 [NISTC_AO_PERSONAL_REG] = { 0x19c, 2 }, 351 [NISTC_AO_PERSONAL_REG] = { 0x19c, 2 },
352 [NISTC_RTSI_TRIGA_OUT_REG] = { 0x19e, 2 }, 352 [NISTC_RTSI_TRIGA_OUT_REG] = { 0x19e, 2 },
353 [NISTC_RTSI_TRIGB_OUT_REG] = { 0x1a0, 2 }, 353 [NISTC_RTSI_TRIGB_OUT_REG] = { 0x1a0, 2 },
354 [NISTC_RTSI_BOARD_REG] = { 0, 0 }, /* Unknown */ 354 /* doc for following line: mhddk/nimseries/ChipObjects/tMSeries.h */
355 [NISTC_RTSI_BOARD_REG] = { 0x1a2, 2 },
355 [NISTC_CFG_MEM_CLR_REG] = { 0x1a4, 2 }, 356 [NISTC_CFG_MEM_CLR_REG] = { 0x1a4, 2 },
356 [NISTC_ADC_FIFO_CLR_REG] = { 0x1a6, 2 }, 357 [NISTC_ADC_FIFO_CLR_REG] = { 0x1a6, 2 },
357 [NISTC_DAC_FIFO_CLR_REG] = { 0x1a8, 2 }, 358 [NISTC_DAC_FIFO_CLR_REG] = { 0x1a8, 2 },
@@ -2006,7 +2007,6 @@ static int ni_ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
2006 const struct ni_board_struct *board = dev->board_ptr; 2007 const struct ni_board_struct *board = dev->board_ptr;
2007 struct ni_private *devpriv = dev->private; 2008 struct ni_private *devpriv = dev->private;
2008 int err = 0; 2009 int err = 0;
2009 unsigned int tmp;
2010 unsigned int sources; 2010 unsigned int sources;
2011 2011
2012 /* Step 1 : check if triggers are trivially valid */ 2012 /* Step 1 : check if triggers are trivially valid */
@@ -2047,12 +2047,9 @@ static int ni_ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
2047 err |= comedi_check_trigger_arg_is(&cmd->start_arg, 0); 2047 err |= comedi_check_trigger_arg_is(&cmd->start_arg, 0);
2048 break; 2048 break;
2049 case TRIG_EXT: 2049 case TRIG_EXT:
2050 tmp = CR_CHAN(cmd->start_arg); 2050 err |= ni_check_trigger_arg_roffs(CR_CHAN(cmd->start_arg),
2051 2051 NI_AI_StartTrigger,
2052 if (tmp > 16) 2052 &devpriv->routing_tables, 1);
2053 tmp = 16;
2054 tmp |= (cmd->start_arg & (CR_INVERT | CR_EDGE));
2055 err |= comedi_check_trigger_arg_is(&cmd->start_arg, tmp);
2056 break; 2053 break;
2057 } 2054 }
2058 2055
@@ -2064,12 +2061,9 @@ static int ni_ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
2064 0xffffff); 2061 0xffffff);
2065 } else if (cmd->scan_begin_src == TRIG_EXT) { 2062 } else if (cmd->scan_begin_src == TRIG_EXT) {
2066 /* external trigger */ 2063 /* external trigger */
2067 unsigned int tmp = CR_CHAN(cmd->scan_begin_arg); 2064 err |= ni_check_trigger_arg_roffs(CR_CHAN(cmd->scan_begin_arg),
2068 2065 NI_AI_SampleClock,
2069 if (tmp > 16) 2066 &devpriv->routing_tables, 1);
2070 tmp = 16;
2071 tmp |= (cmd->scan_begin_arg & (CR_INVERT | CR_EDGE));
2072 err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, tmp);
2073 } else { /* TRIG_OTHER */ 2067 } else { /* TRIG_OTHER */
2074 err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, 0); 2068 err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
2075 } 2069 }
@@ -2087,12 +2081,9 @@ static int ni_ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
2087 } 2081 }
2088 } else if (cmd->convert_src == TRIG_EXT) { 2082 } else if (cmd->convert_src == TRIG_EXT) {
2089 /* external trigger */ 2083 /* external trigger */
2090 unsigned int tmp = CR_CHAN(cmd->convert_arg); 2084 err |= ni_check_trigger_arg_roffs(CR_CHAN(cmd->convert_arg),
2091 2085 NI_AI_ConvertClock,
2092 if (tmp > 16) 2086 &devpriv->routing_tables, 1);
2093 tmp = 16;
2094 tmp |= (cmd->convert_arg & (CR_ALT_FILTER | CR_INVERT));
2095 err |= comedi_check_trigger_arg_is(&cmd->convert_arg, tmp);
2096 } else if (cmd->convert_src == TRIG_NOW) { 2087 } else if (cmd->convert_src == TRIG_NOW) {
2097 err |= comedi_check_trigger_arg_is(&cmd->convert_arg, 0); 2088 err |= comedi_check_trigger_arg_is(&cmd->convert_arg, 0);
2098 } 2089 }
@@ -2118,7 +2109,7 @@ static int ni_ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
2118 /* step 4: fix up any arguments */ 2109 /* step 4: fix up any arguments */
2119 2110
2120 if (cmd->scan_begin_src == TRIG_TIMER) { 2111 if (cmd->scan_begin_src == TRIG_TIMER) {
2121 tmp = cmd->scan_begin_arg; 2112 unsigned int tmp = cmd->scan_begin_arg;
2122 cmd->scan_begin_arg = 2113 cmd->scan_begin_arg =
2123 ni_timer_to_ns(dev, ni_ns_to_timer(dev, 2114 ni_timer_to_ns(dev, ni_ns_to_timer(dev,
2124 cmd->scan_begin_arg, 2115 cmd->scan_begin_arg,
@@ -2128,7 +2119,7 @@ static int ni_ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
2128 } 2119 }
2129 if (cmd->convert_src == TRIG_TIMER) { 2120 if (cmd->convert_src == TRIG_TIMER) {
2130 if (!devpriv->is_611x && !devpriv->is_6143) { 2121 if (!devpriv->is_611x && !devpriv->is_6143) {
2131 tmp = cmd->convert_arg; 2122 unsigned int tmp = cmd->convert_arg;
2132 cmd->convert_arg = 2123 cmd->convert_arg =
2133 ni_timer_to_ns(dev, ni_ns_to_timer(dev, 2124 ni_timer_to_ns(dev, ni_ns_to_timer(dev,
2134 cmd->convert_arg, 2125 cmd->convert_arg,
@@ -2206,8 +2197,10 @@ static int ni_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
2206 NISTC_AI_TRIG_START1_SEL(0); 2197 NISTC_AI_TRIG_START1_SEL(0);
2207 break; 2198 break;
2208 case TRIG_EXT: 2199 case TRIG_EXT:
2209 ai_trig |= NISTC_AI_TRIG_START1_SEL(CR_CHAN(cmd->start_arg) + 2200 ai_trig |= NISTC_AI_TRIG_START1_SEL(
2210 1); 2201 ni_get_reg_value_roffs(CR_CHAN(cmd->start_arg),
2202 NI_AI_StartTrigger,
2203 &devpriv->routing_tables, 1));
2211 2204
2212 if (cmd->start_arg & CR_INVERT) 2205 if (cmd->start_arg & CR_INVERT)
2213 ai_trig |= NISTC_AI_TRIG_START1_POLARITY; 2206 ai_trig |= NISTC_AI_TRIG_START1_POLARITY;
@@ -2317,8 +2310,10 @@ static int ni_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
2317 (cmd->scan_begin_arg & ~CR_EDGE) != 2310 (cmd->scan_begin_arg & ~CR_EDGE) !=
2318 (cmd->convert_arg & ~CR_EDGE)) 2311 (cmd->convert_arg & ~CR_EDGE))
2319 start_stop_select |= NISTC_AI_START_SYNC; 2312 start_stop_select |= NISTC_AI_START_SYNC;
2320 start_stop_select |= 2313 start_stop_select |= NISTC_AI_START_SEL(
2321 NISTC_AI_START_SEL(1 + CR_CHAN(cmd->scan_begin_arg)); 2314 ni_get_reg_value_roffs(CR_CHAN(cmd->scan_begin_arg),
2315 NI_AI_SampleClock,
2316 &devpriv->routing_tables, 1));
2322 ni_stc_writew(dev, start_stop_select, NISTC_AI_START_STOP_REG); 2317 ni_stc_writew(dev, start_stop_select, NISTC_AI_START_STOP_REG);
2323 break; 2318 break;
2324 } 2319 }
@@ -2346,8 +2341,10 @@ static int ni_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
2346 ni_stc_writew(dev, mode2, NISTC_AI_MODE2_REG); 2341 ni_stc_writew(dev, mode2, NISTC_AI_MODE2_REG);
2347 break; 2342 break;
2348 case TRIG_EXT: 2343 case TRIG_EXT:
2349 mode1 |= NISTC_AI_MODE1_CONVERT_SRC(1 + 2344 mode1 |= NISTC_AI_MODE1_CONVERT_SRC(
2350 CR_CHAN(cmd->convert_arg)); 2345 ni_get_reg_value_roffs(CR_CHAN(cmd->convert_arg),
2346 NI_AI_ConvertClock,
2347 &devpriv->routing_tables, 1));
2351 if ((cmd->convert_arg & CR_INVERT) == 0) 2348 if ((cmd->convert_arg & CR_INVERT) == 0)
2352 mode1 |= NISTC_AI_MODE1_CONVERT_POLARITY; 2349 mode1 |= NISTC_AI_MODE1_CONVERT_POLARITY;
2353 ni_stc_writew(dev, mode1, NISTC_AI_MODE1_REG); 2350 ni_stc_writew(dev, mode1, NISTC_AI_MODE1_REG);
@@ -2464,6 +2461,7 @@ static int ni_ai_insn_config(struct comedi_device *dev,
2464 struct comedi_subdevice *s, 2461 struct comedi_subdevice *s,
2465 struct comedi_insn *insn, unsigned int *data) 2462 struct comedi_insn *insn, unsigned int *data)
2466{ 2463{
2464 const struct ni_board_struct *board = dev->board_ptr;
2467 struct ni_private *devpriv = dev->private; 2465 struct ni_private *devpriv = dev->private;
2468 2466
2469 if (insn->n < 1) 2467 if (insn->n < 1)
@@ -2498,6 +2496,15 @@ static int ni_ai_insn_config(struct comedi_device *dev,
2498 } 2496 }
2499 } 2497 }
2500 return 2; 2498 return 2;
2499 case INSN_CONFIG_GET_CMD_TIMING_CONSTRAINTS:
2500 /* we don't care about actual channels */
2501 /* data[3] : chanlist_len */
2502 data[1] = ni_min_ai_scan_period_ns(dev, data[3]);
2503 if (devpriv->is_611x || devpriv->is_6143)
2504 data[2] = 0; /* simultaneous output */
2505 else
2506 data[2] = board->ai_speed;
2507 return 0;
2501 default: 2508 default:
2502 break; 2509 break;
2503 } 2510 }
@@ -2834,6 +2841,11 @@ static int ni_ao_insn_config(struct comedi_device *dev,
2834 return 0; 2841 return 0;
2835 case INSN_CONFIG_ARM: 2842 case INSN_CONFIG_ARM:
2836 return ni_ao_arm(dev, s); 2843 return ni_ao_arm(dev, s);
2844 case INSN_CONFIG_GET_CMD_TIMING_CONSTRAINTS:
2845 /* we don't care about actual channels */
2846 data[1] = board->ao_speed;
2847 data[2] = 0;
2848 return 0;
2837 default: 2849 default:
2838 break; 2850 break;
2839 } 2851 }
@@ -2955,7 +2967,10 @@ static void ni_ao_cmd_set_trigger(struct comedi_device *dev,
2955 trigsel = NISTC_AO_TRIG_START1_EDGE | 2967 trigsel = NISTC_AO_TRIG_START1_EDGE |
2956 NISTC_AO_TRIG_START1_SYNC; 2968 NISTC_AO_TRIG_START1_SYNC;
2957 } else { /* TRIG_EXT */ 2969 } else { /* TRIG_EXT */
2958 trigsel = NISTC_AO_TRIG_START1_SEL(CR_CHAN(cmd->start_arg) + 1); 2970 trigsel = NISTC_AO_TRIG_START1_SEL(
2971 ni_get_reg_value_roffs(CR_CHAN(cmd->start_arg),
2972 NI_AO_StartTrigger,
2973 &devpriv->routing_tables, 1));
2959 /* 0=active high, 1=active low. see daq-stc 3-24 (p186) */ 2974 /* 0=active high, 1=active low. see daq-stc 3-24 (p186) */
2960 if (cmd->start_arg & CR_INVERT) 2975 if (cmd->start_arg & CR_INVERT)
2961 trigsel |= NISTC_AO_TRIG_START1_POLARITY; 2976 trigsel |= NISTC_AO_TRIG_START1_POLARITY;
@@ -3117,7 +3132,9 @@ static void ni_ao_cmd_set_update(struct comedi_device *dev,
3117 /* FIXME: assert scan_begin_arg != 0, ret failure otherwise */ 3132 /* FIXME: assert scan_begin_arg != 0, ret failure otherwise */
3118 devpriv->ao_cmd2 |= NISTC_AO_CMD2_BC_GATE_ENA; 3133 devpriv->ao_cmd2 |= NISTC_AO_CMD2_BC_GATE_ENA;
3119 devpriv->ao_mode1 |= NISTC_AO_MODE1_UPDATE_SRC( 3134 devpriv->ao_mode1 |= NISTC_AO_MODE1_UPDATE_SRC(
3120 CR_CHAN(cmd->scan_begin_arg)); 3135 ni_get_reg_value(CR_CHAN(cmd->scan_begin_arg),
3136 NI_AO_SampleClock,
3137 &devpriv->routing_tables));
3121 if (cmd->scan_begin_arg & CR_INVERT) 3138 if (cmd->scan_begin_arg & CR_INVERT)
3122 devpriv->ao_mode1 |= NISTC_AO_MODE1_UPDATE_SRC_POLARITY; 3139 devpriv->ao_mode1 |= NISTC_AO_MODE1_UPDATE_SRC_POLARITY;
3123 } 3140 }
@@ -3313,12 +3330,9 @@ static int ni_ao_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
3313 err |= comedi_check_trigger_arg_is(&cmd->start_arg, 0); 3330 err |= comedi_check_trigger_arg_is(&cmd->start_arg, 0);
3314 break; 3331 break;
3315 case TRIG_EXT: 3332 case TRIG_EXT:
3316 tmp = CR_CHAN(cmd->start_arg); 3333 err |= ni_check_trigger_arg_roffs(CR_CHAN(cmd->start_arg),
3317 3334 NI_AO_StartTrigger,
3318 if (tmp > 18) 3335 &devpriv->routing_tables, 1);
3319 tmp = 18;
3320 tmp |= (cmd->start_arg & (CR_INVERT | CR_EDGE));
3321 err |= comedi_check_trigger_arg_is(&cmd->start_arg, tmp);
3322 break; 3336 break;
3323 } 3337 }
3324 3338
@@ -3328,6 +3342,10 @@ static int ni_ao_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
3328 err |= comedi_check_trigger_arg_max(&cmd->scan_begin_arg, 3342 err |= comedi_check_trigger_arg_max(&cmd->scan_begin_arg,
3329 devpriv->clock_ns * 3343 devpriv->clock_ns *
3330 0xffffff); 3344 0xffffff);
3345 } else { /* TRIG_EXT */
3346 err |= ni_check_trigger_arg(CR_CHAN(cmd->scan_begin_arg),
3347 NI_AO_SampleClock,
3348 &devpriv->routing_tables);
3331 } 3349 }
3332 3350
3333 err |= comedi_check_trigger_arg_is(&cmd->convert_arg, 0); 3351 err |= comedi_check_trigger_arg_is(&cmd->convert_arg, 0);
@@ -3475,6 +3493,15 @@ static int ni_m_series_dio_insn_config(struct comedi_device *dev,
3475{ 3493{
3476 int ret; 3494 int ret;
3477 3495
3496 if (data[0] == INSN_CONFIG_GET_CMD_TIMING_CONSTRAINTS) {
3497 const struct ni_board_struct *board = dev->board_ptr;
3498
3499 /* we don't care about actual channels */
3500 data[1] = board->dio_speed;
3501 data[2] = 0;
3502 return 0;
3503 }
3504
3478 ret = comedi_dio_insn_config(dev, s, insn, data, 0); 3505 ret = comedi_dio_insn_config(dev, s, insn, data, 0);
3479 if (ret) 3506 if (ret)
3480 return ret; 3507 return ret;
@@ -3516,8 +3543,8 @@ static int ni_cdio_check_chanlist(struct comedi_device *dev,
3516static int ni_cdio_cmdtest(struct comedi_device *dev, 3543static int ni_cdio_cmdtest(struct comedi_device *dev,
3517 struct comedi_subdevice *s, struct comedi_cmd *cmd) 3544 struct comedi_subdevice *s, struct comedi_cmd *cmd)
3518{ 3545{
3546 struct ni_private *devpriv = dev->private;
3519 int err = 0; 3547 int err = 0;
3520 int tmp;
3521 3548
3522 /* Step 1 : check if triggers are trivially valid */ 3549 /* Step 1 : check if triggers are trivially valid */
3523 3550
@@ -3537,9 +3564,15 @@ static int ni_cdio_cmdtest(struct comedi_device *dev,
3537 3564
3538 err |= comedi_check_trigger_arg_is(&cmd->start_arg, 0); 3565 err |= comedi_check_trigger_arg_is(&cmd->start_arg, 0);
3539 3566
3540 tmp = cmd->scan_begin_arg; 3567 /*
3541 tmp &= CR_PACK_FLAGS(NI_M_CDO_MODE_SAMPLE_SRC_MASK, 0, 0, CR_INVERT); 3568 * Although NI_D[IO]_SampleClock are the same, perhaps we should still,
3542 if (tmp != cmd->scan_begin_arg) 3569 * for completeness, test whether the cmd is output or input?
3570 */
3571 err |= ni_check_trigger_arg(CR_CHAN(cmd->scan_begin_arg),
3572 NI_DO_SampleClock,
3573 &devpriv->routing_tables);
3574 if (CR_RANGE(cmd->scan_begin_arg) != 0 ||
3575 CR_AREF(cmd->scan_begin_arg) != 0)
3543 err |= -EINVAL; 3576 err |= -EINVAL;
3544 3577
3545 err |= comedi_check_trigger_arg_is(&cmd->convert_arg, 0); 3578 err |= comedi_check_trigger_arg_is(&cmd->convert_arg, 0);
@@ -3627,9 +3660,16 @@ static int ni_cdio_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
3627 int retval; 3660 int retval;
3628 3661
3629 ni_writel(dev, NI_M_CDO_CMD_RESET, NI_M_CDIO_CMD_REG); 3662 ni_writel(dev, NI_M_CDO_CMD_RESET, NI_M_CDIO_CMD_REG);
3663 /*
3664 * Although NI_D[IO]_SampleClock are the same, perhaps we should still,
3665 * for completeness, test whether the cmd is output or input(?)
3666 */
3630 cdo_mode_bits = NI_M_CDO_MODE_FIFO_MODE | 3667 cdo_mode_bits = NI_M_CDO_MODE_FIFO_MODE |
3631 NI_M_CDO_MODE_HALT_ON_ERROR | 3668 NI_M_CDO_MODE_HALT_ON_ERROR |
3632 NI_M_CDO_MODE_SAMPLE_SRC(CR_CHAN(cmd->scan_begin_arg)); 3669 NI_M_CDO_MODE_SAMPLE_SRC(
3670 ni_get_reg_value(CR_CHAN(cmd->scan_begin_arg),
3671 NI_DO_SampleClock,
3672 &devpriv->routing_tables));
3633 if (cmd->scan_begin_arg & CR_INVERT) 3673 if (cmd->scan_begin_arg & CR_INVERT)
3634 cdo_mode_bits |= NI_M_CDO_MODE_POLARITY; 3674 cdo_mode_bits |= NI_M_CDO_MODE_POLARITY;
3635 ni_writel(dev, cdo_mode_bits, NI_M_CDO_MODE_REG); 3675 ni_writel(dev, cdo_mode_bits, NI_M_CDO_MODE_REG);
@@ -4551,24 +4591,33 @@ static unsigned int ni_get_pfi_routing(struct comedi_device *dev,
4551{ 4591{
4552 struct ni_private *devpriv = dev->private; 4592 struct ni_private *devpriv = dev->private;
4553 4593
4594 if (chan >= NI_PFI(0)) {
4595 /* allow new and old names of pfi channels to work. */
4596 chan -= NI_PFI(0);
4597 }
4554 return (devpriv->is_m_series) 4598 return (devpriv->is_m_series)
4555 ? ni_m_series_get_pfi_routing(dev, chan) 4599 ? ni_m_series_get_pfi_routing(dev, chan)
4556 : ni_old_get_pfi_routing(dev, chan); 4600 : ni_old_get_pfi_routing(dev, chan);
4557} 4601}
4558 4602
4603/* Sets the output mux for the specified PFI channel. */
4559static int ni_set_pfi_routing(struct comedi_device *dev, 4604static int ni_set_pfi_routing(struct comedi_device *dev,
4560 unsigned int chan, unsigned int source) 4605 unsigned int chan, unsigned int source)
4561{ 4606{
4562 struct ni_private *devpriv = dev->private; 4607 struct ni_private *devpriv = dev->private;
4563 4608
4609 if (chan >= NI_PFI(0)) {
4610 /* allow new and old names of pfi channels to work. */
4611 chan -= NI_PFI(0);
4612 }
4564 return (devpriv->is_m_series) 4613 return (devpriv->is_m_series)
4565 ? ni_m_series_set_pfi_routing(dev, chan, source) 4614 ? ni_m_series_set_pfi_routing(dev, chan, source)
4566 : ni_old_set_pfi_routing(dev, chan, source); 4615 : ni_old_set_pfi_routing(dev, chan, source);
4567} 4616}
4568 4617
4569static int ni_config_filter(struct comedi_device *dev, 4618static int ni_config_pfi_filter(struct comedi_device *dev,
4570 unsigned int pfi_channel, 4619 unsigned int chan,
4571 enum ni_pfi_filter_select filter) 4620 enum ni_pfi_filter_select filter)
4572{ 4621{
4573 struct ni_private *devpriv = dev->private; 4622 struct ni_private *devpriv = dev->private;
4574 unsigned int bits; 4623 unsigned int bits;
@@ -4576,19 +4625,46 @@ static int ni_config_filter(struct comedi_device *dev,
4576 if (!devpriv->is_m_series) 4625 if (!devpriv->is_m_series)
4577 return -ENOTSUPP; 4626 return -ENOTSUPP;
4578 4627
4628 if (chan >= NI_PFI(0)) {
4629 /* allow new and old names of pfi channels to work. */
4630 chan -= NI_PFI(0);
4631 }
4632
4579 bits = ni_readl(dev, NI_M_PFI_FILTER_REG); 4633 bits = ni_readl(dev, NI_M_PFI_FILTER_REG);
4580 bits &= ~NI_M_PFI_FILTER_SEL_MASK(pfi_channel); 4634 bits &= ~NI_M_PFI_FILTER_SEL_MASK(chan);
4581 bits |= NI_M_PFI_FILTER_SEL(pfi_channel, filter); 4635 bits |= NI_M_PFI_FILTER_SEL(chan, filter);
4582 ni_writel(dev, bits, NI_M_PFI_FILTER_REG); 4636 ni_writel(dev, bits, NI_M_PFI_FILTER_REG);
4583 return 0; 4637 return 0;
4584} 4638}
4585 4639
4640static void ni_set_pfi_direction(struct comedi_device *dev, int chan,
4641 unsigned int direction)
4642{
4643 if (chan >= NI_PFI(0)) {
4644 /* allow new and old names of pfi channels to work. */
4645 chan -= NI_PFI(0);
4646 }
4647 direction = (direction == COMEDI_OUTPUT) ? 1u : 0u;
4648 ni_set_bits(dev, NISTC_IO_BIDIR_PIN_REG, 1 << chan, direction);
4649}
4650
4651static int ni_get_pfi_direction(struct comedi_device *dev, int chan)
4652{
4653 struct ni_private *devpriv = dev->private;
4654
4655 if (chan >= NI_PFI(0)) {
4656 /* allow new and old names of pfi channels to work. */
4657 chan -= NI_PFI(0);
4658 }
4659 return devpriv->io_bidirection_pin_reg & (1 << chan) ?
4660 COMEDI_OUTPUT : COMEDI_INPUT;
4661}
4662
4586static int ni_pfi_insn_config(struct comedi_device *dev, 4663static int ni_pfi_insn_config(struct comedi_device *dev,
4587 struct comedi_subdevice *s, 4664 struct comedi_subdevice *s,
4588 struct comedi_insn *insn, 4665 struct comedi_insn *insn,
4589 unsigned int *data) 4666 unsigned int *data)
4590{ 4667{
4591 struct ni_private *devpriv = dev->private;
4592 unsigned int chan; 4668 unsigned int chan;
4593 4669
4594 if (insn->n < 1) 4670 if (insn->n < 1)
@@ -4598,23 +4674,19 @@ static int ni_pfi_insn_config(struct comedi_device *dev,
4598 4674
4599 switch (data[0]) { 4675 switch (data[0]) {
4600 case COMEDI_OUTPUT: 4676 case COMEDI_OUTPUT:
4601 ni_set_bits(dev, NISTC_IO_BIDIR_PIN_REG, 1 << chan, 1);
4602 break;
4603 case COMEDI_INPUT: 4677 case COMEDI_INPUT:
4604 ni_set_bits(dev, NISTC_IO_BIDIR_PIN_REG, 1 << chan, 0); 4678 ni_set_pfi_direction(dev, chan, data[0]);
4605 break; 4679 break;
4606 case INSN_CONFIG_DIO_QUERY: 4680 case INSN_CONFIG_DIO_QUERY:
4607 data[1] = 4681 data[1] = ni_get_pfi_direction(dev, chan);
4608 (devpriv->io_bidirection_pin_reg & (1 << chan)) ? 4682 break;
4609 COMEDI_OUTPUT : COMEDI_INPUT;
4610 return 0;
4611 case INSN_CONFIG_SET_ROUTING: 4683 case INSN_CONFIG_SET_ROUTING:
4612 return ni_set_pfi_routing(dev, chan, data[1]); 4684 return ni_set_pfi_routing(dev, chan, data[1]);
4613 case INSN_CONFIG_GET_ROUTING: 4685 case INSN_CONFIG_GET_ROUTING:
4614 data[1] = ni_get_pfi_routing(dev, chan); 4686 data[1] = ni_get_pfi_routing(dev, chan);
4615 break; 4687 break;
4616 case INSN_CONFIG_FILTER: 4688 case INSN_CONFIG_FILTER:
4617 return ni_config_filter(dev, chan, data[1]); 4689 return ni_config_pfi_filter(dev, chan, data[1]);
4618 default: 4690 default:
4619 return -EINVAL; 4691 return -EINVAL;
4620 } 4692 }
@@ -4980,7 +5052,10 @@ static int ni_valid_rtsi_output_source(struct comedi_device *dev,
4980 case NI_RTSI_OUTPUT_G_SRC0: 5052 case NI_RTSI_OUTPUT_G_SRC0:
4981 case NI_RTSI_OUTPUT_G_GATE0: 5053 case NI_RTSI_OUTPUT_G_GATE0:
4982 case NI_RTSI_OUTPUT_RGOUT0: 5054 case NI_RTSI_OUTPUT_RGOUT0:
4983 case NI_RTSI_OUTPUT_RTSI_BRD_0: 5055 case NI_RTSI_OUTPUT_RTSI_BRD(0):
5056 case NI_RTSI_OUTPUT_RTSI_BRD(1):
5057 case NI_RTSI_OUTPUT_RTSI_BRD(2):
5058 case NI_RTSI_OUTPUT_RTSI_BRD(3):
4984 return 1; 5059 return 1;
4985 case NI_RTSI_OUTPUT_RTSI_OSC: 5060 case NI_RTSI_OUTPUT_RTSI_OSC:
4986 return (devpriv->is_m_series) ? 1 : 0; 5061 return (devpriv->is_m_series) ? 1 : 0;
@@ -4994,6 +5069,10 @@ static int ni_set_rtsi_routing(struct comedi_device *dev,
4994{ 5069{
4995 struct ni_private *devpriv = dev->private; 5070 struct ni_private *devpriv = dev->private;
4996 5071
5072 if (chan >= TRIGGER_LINE(0))
5073 /* allow new and old names of rtsi channels to work. */
5074 chan -= TRIGGER_LINE(0);
5075
4997 if (ni_valid_rtsi_output_source(dev, chan, src) == 0) 5076 if (ni_valid_rtsi_output_source(dev, chan, src) == 0)
4998 return -EINVAL; 5077 return -EINVAL;
4999 if (chan < 4) { 5078 if (chan < 4) {
@@ -5001,11 +5080,18 @@ static int ni_set_rtsi_routing(struct comedi_device *dev,
5001 devpriv->rtsi_trig_a_output_reg |= NISTC_RTSI_TRIG(chan, src); 5080 devpriv->rtsi_trig_a_output_reg |= NISTC_RTSI_TRIG(chan, src);
5002 ni_stc_writew(dev, devpriv->rtsi_trig_a_output_reg, 5081 ni_stc_writew(dev, devpriv->rtsi_trig_a_output_reg,
5003 NISTC_RTSI_TRIGA_OUT_REG); 5082 NISTC_RTSI_TRIGA_OUT_REG);
5004 } else if (chan < 8) { 5083 } else if (chan < NISTC_RTSI_TRIG_NUM_CHAN(devpriv->is_m_series)) {
5005 devpriv->rtsi_trig_b_output_reg &= ~NISTC_RTSI_TRIG_MASK(chan); 5084 devpriv->rtsi_trig_b_output_reg &= ~NISTC_RTSI_TRIG_MASK(chan);
5006 devpriv->rtsi_trig_b_output_reg |= NISTC_RTSI_TRIG(chan, src); 5085 devpriv->rtsi_trig_b_output_reg |= NISTC_RTSI_TRIG(chan, src);
5007 ni_stc_writew(dev, devpriv->rtsi_trig_b_output_reg, 5086 ni_stc_writew(dev, devpriv->rtsi_trig_b_output_reg,
5008 NISTC_RTSI_TRIGB_OUT_REG); 5087 NISTC_RTSI_TRIGB_OUT_REG);
5088 } else if (chan != NISTC_RTSI_TRIG_OLD_CLK_CHAN) {
5089 /* probably should never reach this, since the
5090 * ni_valid_rtsi_output_source above errors out if chan is too
5091 * high
5092 */
5093 dev_err(dev->class_dev, "%s: unknown rtsi channel\n", __func__);
5094 return -EINVAL;
5009 } 5095 }
5010 return 2; 5096 return 2;
5011} 5097}
@@ -5015,31 +5101,35 @@ static unsigned int ni_get_rtsi_routing(struct comedi_device *dev,
5015{ 5101{
5016 struct ni_private *devpriv = dev->private; 5102 struct ni_private *devpriv = dev->private;
5017 5103
5104 if (chan >= TRIGGER_LINE(0))
5105 /* allow new and old names of rtsi channels to work. */
5106 chan -= TRIGGER_LINE(0);
5107
5018 if (chan < 4) { 5108 if (chan < 4) {
5019 return NISTC_RTSI_TRIG_TO_SRC(chan, 5109 return NISTC_RTSI_TRIG_TO_SRC(chan,
5020 devpriv->rtsi_trig_a_output_reg); 5110 devpriv->rtsi_trig_a_output_reg);
5021 } else if (chan < NISTC_RTSI_TRIG_NUM_CHAN(devpriv->is_m_series)) { 5111 } else if (chan < NISTC_RTSI_TRIG_NUM_CHAN(devpriv->is_m_series)) {
5022 return NISTC_RTSI_TRIG_TO_SRC(chan, 5112 return NISTC_RTSI_TRIG_TO_SRC(chan,
5023 devpriv->rtsi_trig_b_output_reg); 5113 devpriv->rtsi_trig_b_output_reg);
5024 } else { 5114 } else if (chan == NISTC_RTSI_TRIG_OLD_CLK_CHAN) {
5025 if (chan == NISTC_RTSI_TRIG_OLD_CLK_CHAN) 5115 return NI_RTSI_OUTPUT_RTSI_OSC;
5026 return NI_RTSI_OUTPUT_RTSI_OSC;
5027 dev_err(dev->class_dev, "bug! should never get here?\n");
5028 return 0;
5029 } 5116 }
5117
5118 dev_err(dev->class_dev, "%s: unknown rtsi channel\n", __func__);
5119 return -EINVAL;
5030} 5120}
5031 5121
5032static int ni_rtsi_insn_config(struct comedi_device *dev, 5122static void ni_set_rtsi_direction(struct comedi_device *dev, int chan,
5033 struct comedi_subdevice *s, 5123 unsigned int direction)
5034 struct comedi_insn *insn,
5035 unsigned int *data)
5036{ 5124{
5037 struct ni_private *devpriv = dev->private; 5125 struct ni_private *devpriv = dev->private;
5038 unsigned int chan = CR_CHAN(insn->chanspec);
5039 unsigned int max_chan = NISTC_RTSI_TRIG_NUM_CHAN(devpriv->is_m_series); 5126 unsigned int max_chan = NISTC_RTSI_TRIG_NUM_CHAN(devpriv->is_m_series);
5040 5127
5041 switch (data[0]) { 5128 if (chan >= TRIGGER_LINE(0))
5042 case INSN_CONFIG_DIO_OUTPUT: 5129 /* allow new and old names of rtsi channels to work. */
5130 chan -= TRIGGER_LINE(0);
5131
5132 if (direction == COMEDI_OUTPUT) {
5043 if (chan < max_chan) { 5133 if (chan < max_chan) {
5044 devpriv->rtsi_trig_direction_reg |= 5134 devpriv->rtsi_trig_direction_reg |=
5045 NISTC_RTSI_TRIG_DIR(chan, devpriv->is_m_series); 5135 NISTC_RTSI_TRIG_DIR(chan, devpriv->is_m_series);
@@ -5047,10 +5137,7 @@ static int ni_rtsi_insn_config(struct comedi_device *dev,
5047 devpriv->rtsi_trig_direction_reg |= 5137 devpriv->rtsi_trig_direction_reg |=
5048 NISTC_RTSI_TRIG_DRV_CLK; 5138 NISTC_RTSI_TRIG_DRV_CLK;
5049 } 5139 }
5050 ni_stc_writew(dev, devpriv->rtsi_trig_direction_reg, 5140 } else {
5051 NISTC_RTSI_TRIG_DIR_REG);
5052 break;
5053 case INSN_CONFIG_DIO_INPUT:
5054 if (chan < max_chan) { 5141 if (chan < max_chan) {
5055 devpriv->rtsi_trig_direction_reg &= 5142 devpriv->rtsi_trig_direction_reg &=
5056 ~NISTC_RTSI_TRIG_DIR(chan, devpriv->is_m_series); 5143 ~NISTC_RTSI_TRIG_DIR(chan, devpriv->is_m_series);
@@ -5058,23 +5145,53 @@ static int ni_rtsi_insn_config(struct comedi_device *dev,
5058 devpriv->rtsi_trig_direction_reg &= 5145 devpriv->rtsi_trig_direction_reg &=
5059 ~NISTC_RTSI_TRIG_DRV_CLK; 5146 ~NISTC_RTSI_TRIG_DRV_CLK;
5060 } 5147 }
5061 ni_stc_writew(dev, devpriv->rtsi_trig_direction_reg, 5148 }
5062 NISTC_RTSI_TRIG_DIR_REG); 5149 ni_stc_writew(dev, devpriv->rtsi_trig_direction_reg,
5150 NISTC_RTSI_TRIG_DIR_REG);
5151}
5152
5153static int ni_get_rtsi_direction(struct comedi_device *dev, int chan)
5154{
5155 struct ni_private *devpriv = dev->private;
5156 unsigned int max_chan = NISTC_RTSI_TRIG_NUM_CHAN(devpriv->is_m_series);
5157
5158 if (chan >= TRIGGER_LINE(0))
5159 /* allow new and old names of rtsi channels to work. */
5160 chan -= TRIGGER_LINE(0);
5161
5162 if (chan < max_chan) {
5163 return (devpriv->rtsi_trig_direction_reg &
5164 NISTC_RTSI_TRIG_DIR(chan, devpriv->is_m_series))
5165 ? COMEDI_OUTPUT : COMEDI_INPUT;
5166 } else if (chan == NISTC_RTSI_TRIG_OLD_CLK_CHAN) {
5167 return (devpriv->rtsi_trig_direction_reg &
5168 NISTC_RTSI_TRIG_DRV_CLK)
5169 ? COMEDI_OUTPUT : COMEDI_INPUT;
5170 }
5171 return -EINVAL;
5172}
5173
5174static int ni_rtsi_insn_config(struct comedi_device *dev,
5175 struct comedi_subdevice *s,
5176 struct comedi_insn *insn,
5177 unsigned int *data)
5178{
5179 struct ni_private *devpriv = dev->private;
5180 unsigned int chan = CR_CHAN(insn->chanspec);
5181
5182 switch (data[0]) {
5183 case COMEDI_OUTPUT:
5184 case COMEDI_INPUT:
5185 ni_set_rtsi_direction(dev, chan, data[0]);
5063 break; 5186 break;
5064 case INSN_CONFIG_DIO_QUERY: 5187 case INSN_CONFIG_DIO_QUERY: {
5065 if (chan < max_chan) { 5188 int ret = ni_get_rtsi_direction(dev, chan);
5066 data[1] = 5189
5067 (devpriv->rtsi_trig_direction_reg & 5190 if (ret < 0)
5068 NISTC_RTSI_TRIG_DIR(chan, devpriv->is_m_series)) 5191 return ret;
5069 ? INSN_CONFIG_DIO_OUTPUT 5192 data[1] = ret;
5070 : INSN_CONFIG_DIO_INPUT;
5071 } else if (chan == NISTC_RTSI_TRIG_OLD_CLK_CHAN) {
5072 data[1] = (devpriv->rtsi_trig_direction_reg &
5073 NISTC_RTSI_TRIG_DRV_CLK)
5074 ? INSN_CONFIG_DIO_OUTPUT
5075 : INSN_CONFIG_DIO_INPUT;
5076 }
5077 return 2; 5193 return 2;
5194 }
5078 case INSN_CONFIG_SET_CLOCK_SRC: 5195 case INSN_CONFIG_SET_CLOCK_SRC:
5079 return ni_set_master_clock(dev, data[1], data[2]); 5196 return ni_set_master_clock(dev, data[1], data[2]);
5080 case INSN_CONFIG_GET_CLOCK_SRC: 5197 case INSN_CONFIG_GET_CLOCK_SRC:
@@ -5083,9 +5200,14 @@ static int ni_rtsi_insn_config(struct comedi_device *dev,
5083 return 3; 5200 return 3;
5084 case INSN_CONFIG_SET_ROUTING: 5201 case INSN_CONFIG_SET_ROUTING:
5085 return ni_set_rtsi_routing(dev, chan, data[1]); 5202 return ni_set_rtsi_routing(dev, chan, data[1]);
5086 case INSN_CONFIG_GET_ROUTING: 5203 case INSN_CONFIG_GET_ROUTING: {
5087 data[1] = ni_get_rtsi_routing(dev, chan); 5204 int ret = ni_get_rtsi_routing(dev, chan);
5205
5206 if (ret < 0)
5207 return ret;
5208 data[1] = ret;
5088 return 2; 5209 return 2;
5210 }
5089 default: 5211 default:
5090 return -EINVAL; 5212 return -EINVAL;
5091 } 5213 }
@@ -5102,9 +5224,275 @@ static int ni_rtsi_insn_bits(struct comedi_device *dev,
5102 return insn->n; 5224 return insn->n;
5103} 5225}
5104 5226
5227/*
5228 * Default routing for RTSI trigger lines.
5229 *
5230 * These values are used here in the init function, as well as in the
5231 * disconnect_route function, after a RTSI route has been disconnected.
5232 */
5233static const int default_rtsi_routing[] = {
5234 [0] = NI_RTSI_OUTPUT_ADR_START1,
5235 [1] = NI_RTSI_OUTPUT_ADR_START2,
5236 [2] = NI_RTSI_OUTPUT_SCLKG,
5237 [3] = NI_RTSI_OUTPUT_DACUPDN,
5238 [4] = NI_RTSI_OUTPUT_DA_START1,
5239 [5] = NI_RTSI_OUTPUT_G_SRC0,
5240 [6] = NI_RTSI_OUTPUT_G_GATE0,
5241 [7] = NI_RTSI_OUTPUT_RTSI_OSC,
5242};
5243
5244/*
5245 * Route signals through RGOUT0 terminal.
5246 * @reg: raw register value of RGOUT0 bits (only bit0 is important).
5247 * @dev: comedi device handle.
5248 */
5249static void set_rgout0_reg(int reg, struct comedi_device *dev)
5250{
5251 struct ni_private *devpriv = dev->private;
5252
5253 if (devpriv->is_m_series) {
5254 devpriv->rtsi_trig_direction_reg &=
5255 ~NISTC_RTSI_TRIG_DIR_SUB_SEL1;
5256 devpriv->rtsi_trig_direction_reg |=
5257 (reg << NISTC_RTSI_TRIG_DIR_SUB_SEL1_SHIFT) &
5258 NISTC_RTSI_TRIG_DIR_SUB_SEL1;
5259 ni_stc_writew(dev, devpriv->rtsi_trig_direction_reg,
5260 NISTC_RTSI_TRIG_DIR_REG);
5261 } else {
5262 devpriv->rtsi_trig_b_output_reg &= ~NISTC_RTSI_TRIGB_SUB_SEL1;
5263 devpriv->rtsi_trig_b_output_reg |=
5264 (reg << NISTC_RTSI_TRIGB_SUB_SEL1_SHIFT) &
5265 NISTC_RTSI_TRIGB_SUB_SEL1;
5266 ni_stc_writew(dev, devpriv->rtsi_trig_b_output_reg,
5267 NISTC_RTSI_TRIGB_OUT_REG);
5268 }
5269}
5270
5271static int get_rgout0_reg(struct comedi_device *dev)
5272{
5273 struct ni_private *devpriv = dev->private;
5274 int reg;
5275
5276 if (devpriv->is_m_series)
5277 reg = (devpriv->rtsi_trig_direction_reg &
5278 NISTC_RTSI_TRIG_DIR_SUB_SEL1)
5279 >> NISTC_RTSI_TRIG_DIR_SUB_SEL1_SHIFT;
5280 else
5281 reg = (devpriv->rtsi_trig_b_output_reg &
5282 NISTC_RTSI_TRIGB_SUB_SEL1)
5283 >> NISTC_RTSI_TRIGB_SUB_SEL1_SHIFT;
5284 return reg;
5285}
5286
5287static inline int get_rgout0_src(struct comedi_device *dev)
5288{
5289 struct ni_private *devpriv = dev->private;
5290 int reg = get_rgout0_reg(dev);
5291
5292 return ni_find_route_source(reg, NI_RGOUT0, &devpriv->routing_tables);
5293}
5294
5295/*
5296 * Route signals through RGOUT0 terminal and increment the RGOUT0 use for this
5297 * particular route.
5298 * @src: device-global signal name
5299 * @dev: comedi device handle
5300 *
5301 * Return: -EINVAL if the source is not valid to route to RGOUT0;
5302 * -EBUSY if the RGOUT0 is already used;
5303 * 0 if successful.
5304 */
5305static int incr_rgout0_src_use(int src, struct comedi_device *dev)
5306{
5307 struct ni_private *devpriv = dev->private;
5308 s8 reg = ni_lookup_route_register(CR_CHAN(src), NI_RGOUT0,
5309 &devpriv->routing_tables);
5310
5311 if (reg < 0)
5312 return -EINVAL;
5313
5314 if (devpriv->rgout0_usage > 0 && get_rgout0_reg(dev) != reg)
5315 return -EBUSY;
5316
5317 ++devpriv->rgout0_usage;
5318 set_rgout0_reg(reg, dev);
5319 return 0;
5320}
5321
5322/*
5323 * Unroute signals through RGOUT0 terminal and deccrement the RGOUT0 use for
5324 * this particular source. This function does not actually unroute anything
5325 * with respect to RGOUT0. It does, on the other hand, decrement the usage
5326 * counter for the current src->RGOUT0 mapping.
5327 *
5328 * Return: -EINVAL if the source is not already routed to RGOUT0 (or usage is
5329 * already at zero); 0 if successful.
5330 */
5331static int decr_rgout0_src_use(int src, struct comedi_device *dev)
5332{
5333 struct ni_private *devpriv = dev->private;
5334 s8 reg = ni_lookup_route_register(CR_CHAN(src), NI_RGOUT0,
5335 &devpriv->routing_tables);
5336
5337 if (devpriv->rgout0_usage > 0 && get_rgout0_reg(dev) == reg) {
5338 --devpriv->rgout0_usage;
5339 if (!devpriv->rgout0_usage)
5340 set_rgout0_reg(0, dev); /* ok default? */
5341 return 0;
5342 }
5343 return -EINVAL;
5344}
5345
5346/*
5347 * Route signals through given NI_RTSI_BRD mux.
5348 * @i: index of mux to route
5349 * @reg: raw register value of RTSI_BRD bits
5350 * @dev: comedi device handle
5351 */
5352static void set_ith_rtsi_brd_reg(int i, int reg, struct comedi_device *dev)
5353{
5354 struct ni_private *devpriv = dev->private;
5355 int reg_i_sz = 3; /* value for e-series */
5356 int reg_i_mask;
5357 int reg_i_shift;
5358
5359 if (devpriv->is_m_series)
5360 reg_i_sz = 4;
5361 reg_i_mask = ~((~0) << reg_i_sz);
5362 reg_i_shift = i * reg_i_sz;
5363
5364 /* clear out the current reg_i for ith brd */
5365 devpriv->rtsi_shared_mux_reg &= ~(reg_i_mask << reg_i_shift);
5366 /* (softcopy) write the new reg_i for ith brd */
5367 devpriv->rtsi_shared_mux_reg |= (reg & reg_i_mask) << reg_i_shift;
5368 /* (hardcopy) write the new reg_i for ith brd */
5369 ni_stc_writew(dev, devpriv->rtsi_shared_mux_reg, NISTC_RTSI_BOARD_REG);
5370}
5371
5372static int get_ith_rtsi_brd_reg(int i, struct comedi_device *dev)
5373{
5374 struct ni_private *devpriv = dev->private;
5375 int reg_i_sz = 3; /* value for e-series */
5376 int reg_i_mask;
5377 int reg_i_shift;
5378
5379 if (devpriv->is_m_series)
5380 reg_i_sz = 4;
5381 reg_i_mask = ~((~0) << reg_i_sz);
5382 reg_i_shift = i * reg_i_sz;
5383
5384 return (devpriv->rtsi_shared_mux_reg >> reg_i_shift) & reg_i_mask;
5385}
5386
5387static inline int get_rtsi_brd_src(int brd, struct comedi_device *dev)
5388{
5389 struct ni_private *devpriv = dev->private;
5390 int brd_index = brd;
5391 int reg;
5392
5393 if (brd >= NI_RTSI_BRD(0))
5394 brd_index = brd - NI_RTSI_BRD(0);
5395 else
5396 brd = NI_RTSI_BRD(brd);
5397 /*
5398 * And now:
5399 * brd : device-global name
5400 * brd_index : index number of RTSI_BRD mux
5401 */
5402
5403 reg = get_ith_rtsi_brd_reg(brd_index, dev);
5404
5405 return ni_find_route_source(reg, brd, &devpriv->routing_tables);
5406}
5407
5408/*
5409 * Route signals through NI_RTSI_BRD mux and increment the use counter for this
5410 * particular route.
5411 *
5412 * Return: -EINVAL if the source is not valid to route to NI_RTSI_BRD(i);
5413 * -EBUSY if all NI_RTSI_BRD muxes are already used;
5414 * NI_RTSI_BRD(i) of allocated ith mux if successful.
5415 */
5416static int incr_rtsi_brd_src_use(int src, struct comedi_device *dev)
5417{
5418 struct ni_private *devpriv = dev->private;
5419 int first_available = -1;
5420 int err = -EINVAL;
5421 s8 reg;
5422 int i;
5423
5424 /* first look for a mux that is already configured to provide src */
5425 for (i = 0; i < NUM_RTSI_SHARED_MUXS; ++i) {
5426 reg = ni_lookup_route_register(CR_CHAN(src), NI_RTSI_BRD(i),
5427 &devpriv->routing_tables);
5428
5429 if (reg < 0)
5430 continue; /* invalid route */
5431
5432 if (!devpriv->rtsi_shared_mux_usage[i]) {
5433 if (first_available < 0)
5434 /* found the first unused, but usable mux */
5435 first_available = i;
5436 } else {
5437 /*
5438 * we've seen at least one possible route, so change the
5439 * final error to -EBUSY in case there are no muxes
5440 * available.
5441 */
5442 err = -EBUSY;
5443
5444 if (get_ith_rtsi_brd_reg(i, dev) == reg) {
5445 /*
5446 * we've found a mux that is already being used
5447 * to provide the requested signal. Reuse it.
5448 */
5449 goto success;
5450 }
5451 }
5452 }
5453
5454 if (first_available < 0)
5455 return err;
5456
5457 /* we did not find a mux to reuse, but there is at least one usable */
5458 i = first_available;
5459
5460success:
5461 ++devpriv->rtsi_shared_mux_usage[i];
5462 set_ith_rtsi_brd_reg(i, reg, dev);
5463 return NI_RTSI_BRD(i);
5464}
5465
5466/*
5467 * Unroute signals through NI_RTSI_BRD mux and decrement the user counter for
5468 * this particular route.
5469 *
5470 * Return: -EINVAL if the source is not already routed to rtsi_brd(i) (or usage
5471 * is already at zero); 0 if successful.
5472 */
5473static int decr_rtsi_brd_src_use(int src, int rtsi_brd,
5474 struct comedi_device *dev)
5475{
5476 struct ni_private *devpriv = dev->private;
5477 s8 reg = ni_lookup_route_register(CR_CHAN(src), rtsi_brd,
5478 &devpriv->routing_tables);
5479 const int i = rtsi_brd - NI_RTSI_BRD(0);
5480
5481 if (devpriv->rtsi_shared_mux_usage[i] > 0 &&
5482 get_ith_rtsi_brd_reg(i, dev) == reg) {
5483 --devpriv->rtsi_shared_mux_usage[i];
5484 if (!devpriv->rtsi_shared_mux_usage[i])
5485 set_ith_rtsi_brd_reg(i, 0, dev); /* ok default? */
5486 return 0;
5487 }
5488
5489 return -EINVAL;
5490}
5491
5105static void ni_rtsi_init(struct comedi_device *dev) 5492static void ni_rtsi_init(struct comedi_device *dev)
5106{ 5493{
5107 struct ni_private *devpriv = dev->private; 5494 struct ni_private *devpriv = dev->private;
5495 int i;
5108 5496
5109 /* Initialises the RTSI bus signal switch to a default state */ 5497 /* Initialises the RTSI bus signal switch to a default state */
5110 5498
@@ -5117,28 +5505,328 @@ static void ni_rtsi_init(struct comedi_device *dev)
5117 /* Set clock mode to internal */ 5505 /* Set clock mode to internal */
5118 if (ni_set_master_clock(dev, NI_MIO_INTERNAL_CLOCK, 0) < 0) 5506 if (ni_set_master_clock(dev, NI_MIO_INTERNAL_CLOCK, 0) < 0)
5119 dev_err(dev->class_dev, "ni_set_master_clock failed, bug?\n"); 5507 dev_err(dev->class_dev, "ni_set_master_clock failed, bug?\n");
5120 /* default internal lines routing to RTSI bus lines */
5121 devpriv->rtsi_trig_a_output_reg =
5122 NISTC_RTSI_TRIG(0, NI_RTSI_OUTPUT_ADR_START1) |
5123 NISTC_RTSI_TRIG(1, NI_RTSI_OUTPUT_ADR_START2) |
5124 NISTC_RTSI_TRIG(2, NI_RTSI_OUTPUT_SCLKG) |
5125 NISTC_RTSI_TRIG(3, NI_RTSI_OUTPUT_DACUPDN);
5126 ni_stc_writew(dev, devpriv->rtsi_trig_a_output_reg,
5127 NISTC_RTSI_TRIGA_OUT_REG);
5128 devpriv->rtsi_trig_b_output_reg =
5129 NISTC_RTSI_TRIG(4, NI_RTSI_OUTPUT_DA_START1) |
5130 NISTC_RTSI_TRIG(5, NI_RTSI_OUTPUT_G_SRC0) |
5131 NISTC_RTSI_TRIG(6, NI_RTSI_OUTPUT_G_GATE0);
5132 if (devpriv->is_m_series)
5133 devpriv->rtsi_trig_b_output_reg |=
5134 NISTC_RTSI_TRIG(7, NI_RTSI_OUTPUT_RTSI_OSC);
5135 ni_stc_writew(dev, devpriv->rtsi_trig_b_output_reg,
5136 NISTC_RTSI_TRIGB_OUT_REG);
5137 5508
5509 /* default internal lines routing to RTSI bus lines */
5510 for (i = 0; i < 8; ++i) {
5511 ni_set_rtsi_direction(dev, i, COMEDI_INPUT);
5512 ni_set_rtsi_routing(dev, i, default_rtsi_routing[i]);
5513 }
5514
5515 /*
5516 * Sets the source and direction of the 4 on board lines.
5517 * This configures all board lines to be:
5518 * for e-series:
5519 * 1) inputs (not sure what "output" would mean)
5520 * 2) copying TRIGGER_LINE(0) (or RTSI0) output
5521 * for m-series:
5522 * copying NI_PFI(0) output
5523 */
5524 devpriv->rtsi_shared_mux_reg = 0;
5525 for (i = 0; i < 4; ++i)
5526 set_ith_rtsi_brd_reg(i, 0, dev);
5527 memset(devpriv->rtsi_shared_mux_usage, 0,
5528 sizeof(devpriv->rtsi_shared_mux_usage));
5529
5530 /* initialize rgout0 pin as unused. */
5531 devpriv->rgout0_usage = 0;
5532 set_rgout0_reg(0, dev);
5533}
5534
5535/* Get route of GPFO_i/CtrOut pins */
5536static inline int ni_get_gout_routing(unsigned int dest,
5537 struct comedi_device *dev)
5538{
5539 struct ni_private *devpriv = dev->private;
5540 unsigned int reg = devpriv->an_trig_etc_reg;
5541
5542 switch (dest) {
5543 case 0:
5544 if (reg & NISTC_ATRIG_ETC_GPFO_0_ENA)
5545 return NISTC_ATRIG_ETC_GPFO_0_SEL_TO_SRC(reg);
5546 break;
5547 case 1:
5548 if (reg & NISTC_ATRIG_ETC_GPFO_1_ENA)
5549 return NISTC_ATRIG_ETC_GPFO_1_SEL_TO_SRC(reg);
5550 break;
5551 }
5552
5553 return -EINVAL;
5554}
5555
5556/* Set route of GPFO_i/CtrOut pins */
5557static inline int ni_disable_gout_routing(unsigned int dest,
5558 struct comedi_device *dev)
5559{
5560 struct ni_private *devpriv = dev->private;
5561
5562 switch (dest) {
5563 case 0:
5564 devpriv->an_trig_etc_reg &= ~NISTC_ATRIG_ETC_GPFO_0_ENA;
5565 break;
5566 case 1:
5567 devpriv->an_trig_etc_reg &= ~NISTC_ATRIG_ETC_GPFO_1_ENA;
5568 break;
5569 default:
5570 return -EINVAL;
5571 }
5572
5573 ni_stc_writew(dev, devpriv->an_trig_etc_reg, NISTC_ATRIG_ETC_REG);
5574 return 0;
5575}
5576
5577/* Set route of GPFO_i/CtrOut pins */
5578static inline int ni_set_gout_routing(unsigned int src, unsigned int dest,
5579 struct comedi_device *dev)
5580{
5581 struct ni_private *devpriv = dev->private;
5582
5583 switch (dest) {
5584 case 0:
5585 /* clear reg */
5586 devpriv->an_trig_etc_reg &= ~NISTC_ATRIG_ETC_GPFO_0_SEL(-1);
5587 /* set reg */
5588 devpriv->an_trig_etc_reg |= NISTC_ATRIG_ETC_GPFO_0_ENA
5589 | NISTC_ATRIG_ETC_GPFO_0_SEL(src);
5590 break;
5591 case 1:
5592 /* clear reg */
5593 devpriv->an_trig_etc_reg &= ~NISTC_ATRIG_ETC_GPFO_1_SEL;
5594 src = src ? NISTC_ATRIG_ETC_GPFO_1_SEL : 0;
5595 /* set reg */
5596 devpriv->an_trig_etc_reg |= NISTC_ATRIG_ETC_GPFO_1_ENA | src;
5597 break;
5598 default:
5599 return -EINVAL;
5600 }
5601
5602 ni_stc_writew(dev, devpriv->an_trig_etc_reg, NISTC_ATRIG_ETC_REG);
5603 return 0;
5604}
5605
5606/*
5607 * Retrieves the current source of the output selector for the given
5608 * destination. If the terminal for the destination is not already configured
5609 * as an output, this function returns -EINVAL as error.
5610 *
5611 * Return: the register value of the destination output selector;
5612 * -EINVAL if terminal is not configured for output.
5613 */
5614static int get_output_select_source(int dest, struct comedi_device *dev)
5615{
5616 struct ni_private *devpriv = dev->private;
5617 int reg = -1;
5618
5619 if (channel_is_pfi(dest)) {
5620 if (ni_get_pfi_direction(dev, dest) == COMEDI_OUTPUT)
5621 reg = ni_get_pfi_routing(dev, dest);
5622 } else if (channel_is_rtsi(dest)) {
5623 if (ni_get_rtsi_direction(dev, dest) == COMEDI_OUTPUT) {
5624 reg = ni_get_rtsi_routing(dev, dest);
5625
5626 if (reg == NI_RTSI_OUTPUT_RGOUT0) {
5627 dest = NI_RGOUT0; /* prepare for lookup below */
5628 reg = get_rgout0_reg(dev);
5629 } else if (reg >= NI_RTSI_OUTPUT_RTSI_BRD(0) &&
5630 reg <= NI_RTSI_OUTPUT_RTSI_BRD(3)) {
5631 const int i = reg - NI_RTSI_OUTPUT_RTSI_BRD(0);
5632
5633 dest = NI_RTSI_BRD(i); /* prepare for lookup */
5634 reg = get_ith_rtsi_brd_reg(i, dev);
5635 }
5636 }
5637 } else if (dest >= NI_CtrOut(0) && dest <= NI_CtrOut(-1)) {
5638 /*
5639 * not handled by ni_tio. Only available for GPFO registers in
5640 * e/m series.
5641 */
5642 dest -= NI_CtrOut(0);
5643 if (dest > 1)
5644 /* there are only two g_out outputs. */
5645 return -EINVAL;
5646 reg = ni_get_gout_routing(dest, dev);
5647 } else if (channel_is_ctr(dest)) {
5648 reg = ni_tio_get_routing(devpriv->counter_dev, dest);
5649 } else {
5650 dev_dbg(dev->class_dev, "%s: unhandled destination (%d) queried\n",
5651 __func__, dest);
5652 }
5653
5654 if (reg >= 0)
5655 return ni_find_route_source(CR_CHAN(reg), dest,
5656 &devpriv->routing_tables);
5657 return -EINVAL;
5658}
5659
5660/*
5661 * Test a route:
5662 *
5663 * Return: -1 if not connectible;
5664 * 0 if connectible and not connected;
5665 * 1 if connectible and connected.
5666 */
5667static int test_route(unsigned int src, unsigned int dest,
5668 struct comedi_device *dev)
5669{
5670 struct ni_private *devpriv = dev->private;
5671 s8 reg = ni_route_to_register(CR_CHAN(src), dest,
5672 &devpriv->routing_tables);
5673
5674 if (reg < 0)
5675 return -1;
5676 if (get_output_select_source(dest, dev) != CR_CHAN(src))
5677 return 0;
5678 return 1;
5679}
5680
5681/* Connect the actual route. */
5682static int connect_route(unsigned int src, unsigned int dest,
5683 struct comedi_device *dev)
5684{
5685 struct ni_private *devpriv = dev->private;
5686 s8 reg = ni_route_to_register(CR_CHAN(src), dest,
5687 &devpriv->routing_tables);
5688 s8 current_src;
5689
5690 if (reg < 0)
5691 /* route is not valid */
5692 return -EINVAL;
5693
5694 current_src = get_output_select_source(dest, dev);
5695 if (current_src == CR_CHAN(src))
5696 return -EALREADY;
5697 if (current_src >= 0)
5698 /* destination mux is already busy. complain, don't overwrite */
5699 return -EBUSY;
5700
5701 /* The route is valid and available. Now connect... */
5702 if (channel_is_pfi(dest)) {
5703 /* set routing source, then open output */
5704 ni_set_pfi_routing(dev, dest, reg);
5705 ni_set_pfi_direction(dev, dest, COMEDI_OUTPUT);
5706 } else if (channel_is_rtsi(dest)) {
5707 if (reg == NI_RTSI_OUTPUT_RGOUT0) {
5708 int ret = incr_rgout0_src_use(src, dev);
5709
5710 if (ret < 0)
5711 return ret;
5712 } else if (ni_rtsi_route_requires_mux(reg)) {
5713 /* Attempt to allocate and route (src->brd) */
5714 int brd = incr_rtsi_brd_src_use(src, dev);
5715
5716 if (brd < 0)
5717 return brd;
5718
5719 /* Now lookup the register value for (brd->dest) */
5720 reg = ni_lookup_route_register(
5721 brd, dest, &devpriv->routing_tables);
5722 }
5723
5724 ni_set_rtsi_direction(dev, dest, COMEDI_OUTPUT);
5725 ni_set_rtsi_routing(dev, dest, reg);
5726 } else if (dest >= NI_CtrOut(0) && dest <= NI_CtrOut(-1)) {
5727 /*
5728 * not handled by ni_tio. Only available for GPFO registers in
5729 * e/m series.
5730 */
5731 dest -= NI_CtrOut(0);
5732 if (dest > 1)
5733 /* there are only two g_out outputs. */
5734 return -EINVAL;
5735 if (ni_set_gout_routing(src, dest, dev))
5736 return -EINVAL;
5737 } else if (channel_is_ctr(dest)) {
5738 /*
5739 * we are adding back the channel modifier info to set
5740 * invert/edge info passed by the user
5741 */
5742 ni_tio_set_routing(devpriv->counter_dev, dest,
5743 reg | (src & ~CR_CHAN(-1)));
5744 } else {
5745 return -EINVAL;
5746 }
5747 return 0;
5748}
5749
5750static int disconnect_route(unsigned int src, unsigned int dest,
5751 struct comedi_device *dev)
5752{
5753 struct ni_private *devpriv = dev->private;
5754 s8 reg = ni_route_to_register(CR_CHAN(src), dest,
5755 &devpriv->routing_tables);
5756
5757 if (reg < 0)
5758 /* route is not valid */
5759 return -EINVAL;
5760 if (get_output_select_source(dest, dev) != src)
5761 /* cannot disconnect something not connected */
5762 return -EINVAL;
5763
5764 /* The route is valid and is connected. Now disconnect... */
5765 if (channel_is_pfi(dest)) {
5766 /* set the pfi to high impedance, and disconnect */
5767 ni_set_pfi_direction(dev, dest, COMEDI_INPUT);
5768 ni_set_pfi_routing(dev, dest, NI_PFI_OUTPUT_PFI_DEFAULT);
5769 } else if (channel_is_rtsi(dest)) {
5770 if (reg == NI_RTSI_OUTPUT_RGOUT0) {
5771 int ret = decr_rgout0_src_use(src, dev);
5772
5773 if (ret < 0)
5774 return ret;
5775 } else if (ni_rtsi_route_requires_mux(reg)) {
5776 /* find which RTSI_BRD line is source for rtsi pin */
5777 int brd = ni_find_route_source(
5778 ni_get_rtsi_routing(dev, dest), dest,
5779 &devpriv->routing_tables);
5780
5781 if (brd < 0)
5782 return brd;
5783
5784 /* decrement/disconnect RTSI_BRD line from source */
5785 decr_rtsi_brd_src_use(src, brd, dev);
5786 }
5787
5788 /* set rtsi output selector to default state */
5789 reg = default_rtsi_routing[dest - TRIGGER_LINE(0)];
5790 ni_set_rtsi_direction(dev, dest, COMEDI_INPUT);
5791 ni_set_rtsi_routing(dev, dest, reg);
5792 } else if (dest >= NI_CtrOut(0) && dest <= NI_CtrOut(-1)) {
5793 /*
5794 * not handled by ni_tio. Only available for GPFO registers in
5795 * e/m series.
5796 */
5797 dest -= NI_CtrOut(0);
5798 if (dest > 1)
5799 /* there are only two g_out outputs. */
5800 return -EINVAL;
5801 reg = ni_disable_gout_routing(dest, dev);
5802 } else if (channel_is_ctr(dest)) {
5803 ni_tio_unset_routing(devpriv->counter_dev, dest);
5804 } else {
5805 return -EINVAL;
5806 }
5807 return 0;
5808}
5809
5810static int ni_global_insn_config(struct comedi_device *dev,
5811 struct comedi_insn *insn,
5812 unsigned int *data)
5813{
5814 switch (data[0]) {
5815 case INSN_DEVICE_CONFIG_TEST_ROUTE:
5816 data[0] = test_route(data[1], data[2], dev);
5817 return 2;
5818 case INSN_DEVICE_CONFIG_CONNECT_ROUTE:
5819 return connect_route(data[1], data[2], dev);
5820 case INSN_DEVICE_CONFIG_DISCONNECT_ROUTE:
5821 return disconnect_route(data[1], data[2], dev);
5138 /* 5822 /*
5139 * Sets the source and direction of the 4 on board lines 5823 * This case is already handled one level up.
5140 * ni_stc_writew(dev, 0, NISTC_RTSI_BOARD_REG); 5824 * case INSN_DEVICE_CONFIG_GET_ROUTES:
5141 */ 5825 */
5826 default:
5827 return -EINVAL;
5828 }
5829 return 1;
5142} 5830}
5143 5831
5144#ifdef PCIDMA 5832#ifdef PCIDMA
@@ -5244,6 +5932,16 @@ static int ni_alloc_private(struct comedi_device *dev)
5244 return 0; 5932 return 0;
5245} 5933}
5246 5934
5935static unsigned int _ni_get_valid_routes(struct comedi_device *dev,
5936 unsigned int n_pairs,
5937 unsigned int *pair_data)
5938{
5939 struct ni_private *devpriv = dev->private;
5940
5941 return ni_get_valid_routes(&devpriv->routing_tables, n_pairs,
5942 pair_data);
5943}
5944
5247static int ni_E_init(struct comedi_device *dev, 5945static int ni_E_init(struct comedi_device *dev,
5248 unsigned int interrupt_pin, unsigned int irq_polarity) 5946 unsigned int interrupt_pin, unsigned int irq_polarity)
5249{ 5947{
@@ -5252,6 +5950,24 @@ static int ni_E_init(struct comedi_device *dev,
5252 struct comedi_subdevice *s; 5950 struct comedi_subdevice *s;
5253 int ret; 5951 int ret;
5254 int i; 5952 int i;
5953 const char *dev_family = devpriv->is_m_series ? "ni_mseries"
5954 : "ni_eseries";
5955
5956 /* prepare the device for globally-named routes. */
5957 if (ni_assign_device_routes(dev_family, board->name,
5958 &devpriv->routing_tables) < 0) {
5959 dev_warn(dev->class_dev, "%s: %s device has no signal routing table.\n",
5960 __func__, board->name);
5961 dev_warn(dev->class_dev, "%s: High level NI signal names will not be available for this %s board.\n",
5962 __func__, board->name);
5963 } else {
5964 /*
5965 * only(?) assign insn_device_config if we have global names for
5966 * this device.
5967 */
5968 dev->insn_device_config = ni_global_insn_config;
5969 dev->get_valid_routes = _ni_get_valid_routes;
5970 }
5255 5971
5256 if (board->n_aochan > MAX_N_AO_CHAN) { 5972 if (board->n_aochan > MAX_N_AO_CHAN) {
5257 dev_err(dev->class_dev, "bug! n_aochan > MAX_N_AO_CHAN\n"); 5973 dev_err(dev->class_dev, "bug! n_aochan > MAX_N_AO_CHAN\n");
@@ -5508,7 +6224,9 @@ static int ni_E_init(struct comedi_device *dev,
5508 (devpriv->is_m_series) 6224 (devpriv->is_m_series)
5509 ? ni_gpct_variant_m_series 6225 ? ni_gpct_variant_m_series
5510 : ni_gpct_variant_e_series, 6226 : ni_gpct_variant_e_series,
5511 NUM_GPCT); 6227 NUM_GPCT,
6228 NUM_GPCT,
6229 &devpriv->routing_tables);
5512 if (!devpriv->counter_dev) 6230 if (!devpriv->counter_dev)
5513 return -ENOMEM; 6231 return -ENOMEM;
5514 6232
@@ -5517,8 +6235,6 @@ static int ni_E_init(struct comedi_device *dev,
5517 struct ni_gpct *gpct = &devpriv->counter_dev->counters[i]; 6235 struct ni_gpct *gpct = &devpriv->counter_dev->counters[i];
5518 6236
5519 /* setup and initialize the counter */ 6237 /* setup and initialize the counter */
5520 gpct->chip_index = 0;
5521 gpct->counter_index = i;
5522 ni_tio_init_counter(gpct); 6238 ni_tio_init_counter(gpct);
5523 6239
5524 s = &dev->subdevices[NI_GPCT_SUBDEV(i)]; 6240 s = &dev->subdevices[NI_GPCT_SUBDEV(i)];
@@ -5544,6 +6260,10 @@ static int ni_E_init(struct comedi_device *dev,
5544 s->private = gpct; 6260 s->private = gpct;
5545 } 6261 }
5546 6262
6263 /* Initialize GPFO_{0,1} to produce output of counters */
6264 ni_set_gout_routing(0, 0, dev); /* output of counter 0; DAQ STC, p338 */
6265 ni_set_gout_routing(0, 1, dev); /* output of counter 1; DAQ STC, p338 */
6266
5547 /* Frequency output subdevice */ 6267 /* Frequency output subdevice */
5548 s = &dev->subdevices[NI_FREQ_OUT_SUBDEV]; 6268 s = &dev->subdevices[NI_FREQ_OUT_SUBDEV];
5549 s->type = COMEDI_SUBD_COUNTER; 6269 s->type = COMEDI_SUBD_COUNTER;
diff --git a/drivers/staging/comedi/drivers/ni_pcidio.c b/drivers/staging/comedi/drivers/ni_pcidio.c
index 6692af5ff79b..b9a0dc6eac44 100644
--- a/drivers/staging/comedi/drivers/ni_pcidio.c
+++ b/drivers/staging/comedi/drivers/ni_pcidio.c
@@ -260,18 +260,22 @@ enum nidio_boardid {
260struct nidio_board { 260struct nidio_board {
261 const char *name; 261 const char *name;
262 unsigned int uses_firmware:1; 262 unsigned int uses_firmware:1;
263 unsigned int dio_speed;
263}; 264};
264 265
265static const struct nidio_board nidio_boards[] = { 266static const struct nidio_board nidio_boards[] = {
266 [BOARD_PCIDIO_32HS] = { 267 [BOARD_PCIDIO_32HS] = {
267 .name = "pci-dio-32hs", 268 .name = "pci-dio-32hs",
269 .dio_speed = 50,
268 }, 270 },
269 [BOARD_PXI6533] = { 271 [BOARD_PXI6533] = {
270 .name = "pxi-6533", 272 .name = "pxi-6533",
273 .dio_speed = 50,
271 }, 274 },
272 [BOARD_PCI6534] = { 275 [BOARD_PCI6534] = {
273 .name = "pci-6534", 276 .name = "pci-6534",
274 .uses_firmware = 1, 277 .uses_firmware = 1,
278 .dio_speed = 50,
275 }, 279 },
276}; 280};
277 281
@@ -467,6 +471,15 @@ static int ni_pcidio_insn_config(struct comedi_device *dev,
467{ 471{
468 int ret; 472 int ret;
469 473
474 if (data[0] == INSN_CONFIG_GET_CMD_TIMING_CONSTRAINTS) {
475 const struct nidio_board *board = dev->board_ptr;
476
477 /* we don't care about actual channels */
478 data[1] = board->dio_speed;
479 data[2] = 0;
480 return 0;
481 }
482
470 ret = comedi_dio_insn_config(dev, s, insn, data, 0); 483 ret = comedi_dio_insn_config(dev, s, insn, data, 0);
471 if (ret) 484 if (ret)
472 return ret; 485 return ret;
diff --git a/drivers/staging/comedi/drivers/ni_pcimio.c b/drivers/staging/comedi/drivers/ni_pcimio.c
index f9e466d18b3f..14b26fffe049 100644
--- a/drivers/staging/comedi/drivers/ni_pcimio.c
+++ b/drivers/staging/comedi/drivers/ni_pcimio.c
@@ -693,6 +693,7 @@ static const struct ni_board_struct ni_boards[] = {
693 .ai_speed = 4000, 693 .ai_speed = 4000,
694 .reg_type = ni_reg_622x, 694 .reg_type = ni_reg_622x,
695 .caldac = { caldac_none }, 695 .caldac = { caldac_none },
696 .dio_speed = 1000,
696 }, 697 },
697 [BOARD_PCI6221] = { 698 [BOARD_PCI6221] = {
698 .name = "pci-6221", 699 .name = "pci-6221",
@@ -708,6 +709,7 @@ static const struct ni_board_struct ni_boards[] = {
708 .reg_type = ni_reg_622x, 709 .reg_type = ni_reg_622x,
709 .ao_speed = 1200, 710 .ao_speed = 1200,
710 .caldac = { caldac_none }, 711 .caldac = { caldac_none },
712 .dio_speed = 1000,
711 }, 713 },
712 [BOARD_PCI6221_37PIN] = { 714 [BOARD_PCI6221_37PIN] = {
713 .name = "pci-6221_37pin", 715 .name = "pci-6221_37pin",
@@ -738,6 +740,7 @@ static const struct ni_board_struct ni_boards[] = {
738 .reg_type = ni_reg_622x, 740 .reg_type = ni_reg_622x,
739 .ao_speed = 1200, 741 .ao_speed = 1200,
740 .caldac = { caldac_none }, 742 .caldac = { caldac_none },
743 .dio_speed = 1000,
741 }, 744 },
742 [BOARD_PCI6224] = { 745 [BOARD_PCI6224] = {
743 .name = "pci-6224", 746 .name = "pci-6224",
@@ -749,6 +752,7 @@ static const struct ni_board_struct ni_boards[] = {
749 .reg_type = ni_reg_622x, 752 .reg_type = ni_reg_622x,
750 .has_32dio_chan = 1, 753 .has_32dio_chan = 1,
751 .caldac = { caldac_none }, 754 .caldac = { caldac_none },
755 .dio_speed = 1000,
752 }, 756 },
753 [BOARD_PXI6224] = { 757 [BOARD_PXI6224] = {
754 .name = "pxi-6224", 758 .name = "pxi-6224",
@@ -760,6 +764,7 @@ static const struct ni_board_struct ni_boards[] = {
760 .reg_type = ni_reg_622x, 764 .reg_type = ni_reg_622x,
761 .has_32dio_chan = 1, 765 .has_32dio_chan = 1,
762 .caldac = { caldac_none }, 766 .caldac = { caldac_none },
767 .dio_speed = 1000,
763 }, 768 },
764 [BOARD_PCI6225] = { 769 [BOARD_PCI6225] = {
765 .name = "pci-6225", 770 .name = "pci-6225",
@@ -776,6 +781,7 @@ static const struct ni_board_struct ni_boards[] = {
776 .ao_speed = 1200, 781 .ao_speed = 1200,
777 .has_32dio_chan = 1, 782 .has_32dio_chan = 1,
778 .caldac = { caldac_none }, 783 .caldac = { caldac_none },
784 .dio_speed = 1000,
779 }, 785 },
780 [BOARD_PXI6225] = { 786 [BOARD_PXI6225] = {
781 .name = "pxi-6225", 787 .name = "pxi-6225",
@@ -792,6 +798,7 @@ static const struct ni_board_struct ni_boards[] = {
792 .ao_speed = 1200, 798 .ao_speed = 1200,
793 .has_32dio_chan = 1, 799 .has_32dio_chan = 1,
794 .caldac = { caldac_none }, 800 .caldac = { caldac_none },
801 .dio_speed = 1000,
795 }, 802 },
796 [BOARD_PCI6229] = { 803 [BOARD_PCI6229] = {
797 .name = "pci-6229", 804 .name = "pci-6229",
@@ -824,6 +831,7 @@ static const struct ni_board_struct ni_boards[] = {
824 .ao_speed = 1200, 831 .ao_speed = 1200,
825 .has_32dio_chan = 1, 832 .has_32dio_chan = 1,
826 .caldac = { caldac_none }, 833 .caldac = { caldac_none },
834 .dio_speed = 1000,
827 }, 835 },
828 [BOARD_PCI6250] = { 836 [BOARD_PCI6250] = {
829 .name = "pci-6250", 837 .name = "pci-6250",
@@ -844,6 +852,7 @@ static const struct ni_board_struct ni_boards[] = {
844 .ai_speed = 800, 852 .ai_speed = 800,
845 .reg_type = ni_reg_625x, 853 .reg_type = ni_reg_625x,
846 .caldac = { caldac_none }, 854 .caldac = { caldac_none },
855 .dio_speed = 100,
847 }, 856 },
848 [BOARD_PCI6251] = { 857 [BOARD_PCI6251] = {
849 .name = "pci-6251", 858 .name = "pci-6251",
@@ -859,6 +868,7 @@ static const struct ni_board_struct ni_boards[] = {
859 .reg_type = ni_reg_625x, 868 .reg_type = ni_reg_625x,
860 .ao_speed = 350, 869 .ao_speed = 350,
861 .caldac = { caldac_none }, 870 .caldac = { caldac_none },
871 .dio_speed = 100,
862 }, 872 },
863 [BOARD_PXI6251] = { 873 [BOARD_PXI6251] = {
864 .name = "pxi-6251", 874 .name = "pxi-6251",
@@ -874,6 +884,7 @@ static const struct ni_board_struct ni_boards[] = {
874 .reg_type = ni_reg_625x, 884 .reg_type = ni_reg_625x,
875 .ao_speed = 350, 885 .ao_speed = 350,
876 .caldac = { caldac_none }, 886 .caldac = { caldac_none },
887 .dio_speed = 100,
877 }, 888 },
878 [BOARD_PCIE6251] = { 889 [BOARD_PCIE6251] = {
879 .name = "pcie-6251", 890 .name = "pcie-6251",
@@ -889,6 +900,7 @@ static const struct ni_board_struct ni_boards[] = {
889 .reg_type = ni_reg_625x, 900 .reg_type = ni_reg_625x,
890 .ao_speed = 350, 901 .ao_speed = 350,
891 .caldac = { caldac_none }, 902 .caldac = { caldac_none },
903 .dio_speed = 100,
892 }, 904 },
893 [BOARD_PXIE6251] = { 905 [BOARD_PXIE6251] = {
894 .name = "pxie-6251", 906 .name = "pxie-6251",
@@ -904,6 +916,7 @@ static const struct ni_board_struct ni_boards[] = {
904 .reg_type = ni_reg_625x, 916 .reg_type = ni_reg_625x,
905 .ao_speed = 350, 917 .ao_speed = 350,
906 .caldac = { caldac_none }, 918 .caldac = { caldac_none },
919 .dio_speed = 100,
907 }, 920 },
908 [BOARD_PCI6254] = { 921 [BOARD_PCI6254] = {
909 .name = "pci-6254", 922 .name = "pci-6254",
@@ -926,6 +939,7 @@ static const struct ni_board_struct ni_boards[] = {
926 .reg_type = ni_reg_625x, 939 .reg_type = ni_reg_625x,
927 .has_32dio_chan = 1, 940 .has_32dio_chan = 1,
928 .caldac = { caldac_none }, 941 .caldac = { caldac_none },
942 .dio_speed = 100,
929 }, 943 },
930 [BOARD_PCI6259] = { 944 [BOARD_PCI6259] = {
931 .name = "pci-6259", 945 .name = "pci-6259",
@@ -958,6 +972,7 @@ static const struct ni_board_struct ni_boards[] = {
958 .ao_speed = 350, 972 .ao_speed = 350,
959 .has_32dio_chan = 1, 973 .has_32dio_chan = 1,
960 .caldac = { caldac_none }, 974 .caldac = { caldac_none },
975 .dio_speed = 100,
961 }, 976 },
962 [BOARD_PCIE6259] = { 977 [BOARD_PCIE6259] = {
963 .name = "pcie-6259", 978 .name = "pcie-6259",
@@ -990,6 +1005,7 @@ static const struct ni_board_struct ni_boards[] = {
990 .ao_speed = 350, 1005 .ao_speed = 350,
991 .has_32dio_chan = 1, 1006 .has_32dio_chan = 1,
992 .caldac = { caldac_none }, 1007 .caldac = { caldac_none },
1008 .dio_speed = 100,
993 }, 1009 },
994 [BOARD_PCI6280] = { 1010 [BOARD_PCI6280] = {
995 .name = "pci-6280", 1011 .name = "pci-6280",
@@ -1012,6 +1028,7 @@ static const struct ni_board_struct ni_boards[] = {
1012 .ao_fifo_depth = 8191, 1028 .ao_fifo_depth = 8191,
1013 .reg_type = ni_reg_628x, 1029 .reg_type = ni_reg_628x,
1014 .caldac = { caldac_none }, 1030 .caldac = { caldac_none },
1031 .dio_speed = 100,
1015 }, 1032 },
1016 [BOARD_PCI6281] = { 1033 [BOARD_PCI6281] = {
1017 .name = "pci-6281", 1034 .name = "pci-6281",
@@ -1027,6 +1044,7 @@ static const struct ni_board_struct ni_boards[] = {
1027 .reg_type = ni_reg_628x, 1044 .reg_type = ni_reg_628x,
1028 .ao_speed = 350, 1045 .ao_speed = 350,
1029 .caldac = { caldac_none }, 1046 .caldac = { caldac_none },
1047 .dio_speed = 100,
1030 }, 1048 },
1031 [BOARD_PXI6281] = { 1049 [BOARD_PXI6281] = {
1032 .name = "pxi-6281", 1050 .name = "pxi-6281",
@@ -1042,6 +1060,7 @@ static const struct ni_board_struct ni_boards[] = {
1042 .reg_type = ni_reg_628x, 1060 .reg_type = ni_reg_628x,
1043 .ao_speed = 350, 1061 .ao_speed = 350,
1044 .caldac = { caldac_none }, 1062 .caldac = { caldac_none },
1063 .dio_speed = 100,
1045 }, 1064 },
1046 [BOARD_PCI6284] = { 1065 [BOARD_PCI6284] = {
1047 .name = "pci-6284", 1066 .name = "pci-6284",
@@ -1064,6 +1083,7 @@ static const struct ni_board_struct ni_boards[] = {
1064 .reg_type = ni_reg_628x, 1083 .reg_type = ni_reg_628x,
1065 .has_32dio_chan = 1, 1084 .has_32dio_chan = 1,
1066 .caldac = { caldac_none }, 1085 .caldac = { caldac_none },
1086 .dio_speed = 100,
1067 }, 1087 },
1068 [BOARD_PCI6289] = { 1088 [BOARD_PCI6289] = {
1069 .name = "pci-6289", 1089 .name = "pci-6289",
@@ -1096,6 +1116,7 @@ static const struct ni_board_struct ni_boards[] = {
1096 .ao_speed = 350, 1116 .ao_speed = 350,
1097 .has_32dio_chan = 1, 1117 .has_32dio_chan = 1,
1098 .caldac = { caldac_none }, 1118 .caldac = { caldac_none },
1119 .dio_speed = 100,
1099 }, 1120 },
1100 [BOARD_PCI6143] = { 1121 [BOARD_PCI6143] = {
1101 .name = "pci-6143", 1122 .name = "pci-6143",
diff --git a/drivers/staging/comedi/drivers/ni_routes.c b/drivers/staging/comedi/drivers/ni_routes.c
new file mode 100644
index 000000000000..eb61494dc2bd
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routes.c
@@ -0,0 +1,523 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routes.c
5 * Route information for NI boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21#include <linux/module.h>
22#include <linux/slab.h>
23#include <linux/bsearch.h>
24#include <linux/sort.h>
25
26#include "../comedi.h"
27
28#include "ni_routes.h"
29#include "ni_routing/ni_route_values.h"
30#include "ni_routing/ni_device_routes.h"
31
32/*
33 * This is defined in ni_routing/ni_route_values.h:
34 * #define B(x) ((x) - NI_NAMES_BASE)
35 */
36
37/*
38 * These are defined in ni_routing/ni_route_values.h to identify clearly
39 * elements of the table that were set. In other words, entries that are zero
40 * are invalid. To get the value to use for the register, one must mask out the
41 * high bit.
42 *
43 * #define V(x) ((x) | 0x80)
44 *
45 * #define UNMARK(x) ((x) & (~(0x80)))
46 *
47 */
48
49/* Helper for accessing data. */
50#define RVi(table, src, dest) ((table)[(dest) * NI_NUM_NAMES + (src)])
51
52static const size_t route_table_size = NI_NUM_NAMES * NI_NUM_NAMES;
53
54/*
55 * Find the proper route_values and ni_device_routes tables for this particular
56 * device.
57 *
58 * Return: -ENODATA if either was not found; 0 if both were found.
59 */
60static int ni_find_device_routes(const char *device_family,
61 const char *board_name,
62 struct ni_route_tables *tables)
63{
64 const struct ni_device_routes *dr = NULL;
65 const u8 *rv = NULL;
66 int i;
67
68 /* First, find the register_values table for this device family */
69 for (i = 0; ni_all_route_values[i]; ++i) {
70 if (memcmp(ni_all_route_values[i]->family, device_family,
71 strnlen(device_family, 30)) == 0) {
72 rv = &ni_all_route_values[i]->register_values[0][0];
73 break;
74 }
75 }
76
77 if (!rv)
78 return -ENODATA;
79
80 /* Second, find the set of routes valid for this device. */
81 for (i = 0; ni_device_routes_list[i]; ++i) {
82 if (memcmp(ni_device_routes_list[i]->device, board_name,
83 strnlen(board_name, 30)) == 0) {
84 dr = ni_device_routes_list[i];
85 break;
86 }
87 }
88
89 if (!dr)
90 return -ENODATA;
91
92 tables->route_values = rv;
93 tables->valid_routes = dr;
94
95 return 0;
96}
97
98/**
99 * ni_assign_device_routes() - Assign the proper lookup table for NI signal
100 * routing to the specified NI device.
101 *
102 * Return: -ENODATA if assignment was not successful; 0 if successful.
103 */
104int ni_assign_device_routes(const char *device_family,
105 const char *board_name,
106 struct ni_route_tables *tables)
107{
108 memset(tables, 0, sizeof(struct ni_route_tables));
109 return ni_find_device_routes(device_family, board_name, tables);
110}
111EXPORT_SYMBOL_GPL(ni_assign_device_routes);
112
113/**
114 * ni_count_valid_routes() - Count the number of valid routes.
115 * @tables: Routing tables for which to count all valid routes.
116 */
117unsigned int ni_count_valid_routes(const struct ni_route_tables *tables)
118{
119 int total = 0;
120 int i;
121
122 for (i = 0; i < tables->valid_routes->n_route_sets; ++i) {
123 const struct ni_route_set *R = &tables->valid_routes->routes[i];
124 int j;
125
126 for (j = 0; j < R->n_src; ++j) {
127 const int src = R->src[j];
128 const int dest = R->dest;
129 const u8 *rv = tables->route_values;
130
131 if (RVi(rv, B(src), B(dest)))
132 /* direct routing is valid */
133 ++total;
134 else if (channel_is_rtsi(dest) &&
135 (RVi(rv, B(src), B(NI_RGOUT0)) ||
136 RVi(rv, B(src), B(NI_RTSI_BRD(0))) ||
137 RVi(rv, B(src), B(NI_RTSI_BRD(1))) ||
138 RVi(rv, B(src), B(NI_RTSI_BRD(2))) ||
139 RVi(rv, B(src), B(NI_RTSI_BRD(3))))) {
140 ++total;
141 }
142 }
143 }
144 return total;
145}
146EXPORT_SYMBOL_GPL(ni_count_valid_routes);
147
148/**
149 * ni_get_valid_routes() - Implements INSN_DEVICE_CONFIG_GET_ROUTES.
150 * @tables: pointer to relevant set of routing tables.
151 * @n_pairs: Number of pairs for which memory is allocated by the user. If
152 * the user specifies '0', only the number of available pairs is
153 * returned.
154 * @pair_data: Pointer to memory allocated to return pairs back to user. Each
155 * even, odd indexed member of this array will hold source,
156 * destination of a route pair respectively.
157 *
158 * Return: the number of valid routes if n_pairs == 0; otherwise, the number of
159 * valid routes copied.
160 */
161unsigned int ni_get_valid_routes(const struct ni_route_tables *tables,
162 unsigned int n_pairs,
163 unsigned int *pair_data)
164{
165 unsigned int n_valid = ni_count_valid_routes(tables);
166 int i;
167
168 if (n_pairs == 0 || n_valid == 0)
169 return n_valid;
170
171 if (!pair_data)
172 return 0;
173
174 n_valid = 0;
175
176 for (i = 0; i < tables->valid_routes->n_route_sets; ++i) {
177 const struct ni_route_set *R = &tables->valid_routes->routes[i];
178 int j;
179
180 for (j = 0; j < R->n_src; ++j) {
181 const int src = R->src[j];
182 const int dest = R->dest;
183 bool valid = false;
184 const u8 *rv = tables->route_values;
185
186 if (RVi(rv, B(src), B(dest)))
187 /* direct routing is valid */
188 valid = true;
189 else if (channel_is_rtsi(dest) &&
190 (RVi(rv, B(src), B(NI_RGOUT0)) ||
191 RVi(rv, B(src), B(NI_RTSI_BRD(0))) ||
192 RVi(rv, B(src), B(NI_RTSI_BRD(1))) ||
193 RVi(rv, B(src), B(NI_RTSI_BRD(2))) ||
194 RVi(rv, B(src), B(NI_RTSI_BRD(3))))) {
195 /* indirect routing also valid */
196 valid = true;
197 }
198
199 if (valid) {
200 pair_data[2 * n_valid] = src;
201 pair_data[2 * n_valid + 1] = dest;
202 ++n_valid;
203 }
204
205 if (n_valid >= n_pairs)
206 return n_valid;
207 }
208 }
209 return n_valid;
210}
211EXPORT_SYMBOL_GPL(ni_get_valid_routes);
212
213/**
214 * List of NI global signal names that, as destinations, are only routeable
215 * indirectly through the *_arg elements of the comedi_cmd structure.
216 */
217static const int NI_CMD_DESTS[] = {
218 NI_AI_SampleClock,
219 NI_AI_StartTrigger,
220 NI_AI_ConvertClock,
221 NI_AO_SampleClock,
222 NI_AO_StartTrigger,
223 NI_DI_SampleClock,
224 NI_DO_SampleClock,
225};
226
227/**
228 * ni_is_cmd_dest() - Determine whether the given destination is only
229 * configurable via a comedi_cmd struct.
230 * @dest: Destination to test.
231 */
232bool ni_is_cmd_dest(int dest)
233{
234 int i;
235
236 for (i = 0; i < ARRAY_SIZE(NI_CMD_DESTS); ++i)
237 if (NI_CMD_DESTS[i] == dest)
238 return true;
239 return false;
240}
241EXPORT_SYMBOL_GPL(ni_is_cmd_dest);
242
243/* **** BEGIN Routes sort routines **** */
244static int _ni_sort_destcmp(const void *va, const void *vb)
245{
246 const struct ni_route_set *a = va;
247 const struct ni_route_set *b = vb;
248
249 if (a->dest < b->dest)
250 return -1;
251 else if (a->dest > b->dest)
252 return 1;
253 return 0;
254}
255
256static int _ni_sort_srccmp(const void *vsrc0, const void *vsrc1)
257{
258 const int *src0 = vsrc0;
259 const int *src1 = vsrc1;
260
261 if (*src0 < *src1)
262 return -1;
263 else if (*src0 > *src1)
264 return 1;
265 return 0;
266}
267
268/**
269 * ni_sort_device_routes() - Sort the list of valid device signal routes in
270 * preparation for use.
271 * @valid_routes: pointer to ni_device_routes struct to sort.
272 */
273void ni_sort_device_routes(struct ni_device_routes *valid_routes)
274{
275 unsigned int n;
276
277 /* 1. Count and set the number of ni_route_set objects. */
278 valid_routes->n_route_sets = 0;
279 while (valid_routes->routes[valid_routes->n_route_sets].dest != 0)
280 ++valid_routes->n_route_sets;
281
282 /* 2. sort all ni_route_set objects by destination. */
283 sort(valid_routes->routes, valid_routes->n_route_sets,
284 sizeof(struct ni_route_set), _ni_sort_destcmp, NULL);
285
286 /* 3. Loop through each route_set for sorting. */
287 for (n = 0; n < valid_routes->n_route_sets; ++n) {
288 struct ni_route_set *rs = &valid_routes->routes[n];
289
290 /* 3a. Count and set the number of sources. */
291 rs->n_src = 0;
292 while (rs->src[rs->n_src])
293 ++rs->n_src;
294
295 /* 3a. Sort sources. */
296 sort(valid_routes->routes[n].src, valid_routes->routes[n].n_src,
297 sizeof(int), _ni_sort_srccmp, NULL);
298 }
299}
300EXPORT_SYMBOL_GPL(ni_sort_device_routes);
301
302/* sort all valid device signal routes in prep for use */
303static void ni_sort_all_device_routes(void)
304{
305 unsigned int i;
306
307 for (i = 0; ni_device_routes_list[i]; ++i)
308 ni_sort_device_routes(ni_device_routes_list[i]);
309}
310
311/* **** BEGIN Routes search routines **** */
312static int _ni_bsearch_destcmp(const void *vkey, const void *velt)
313{
314 const int *key = vkey;
315 const struct ni_route_set *elt = velt;
316
317 if (*key < elt->dest)
318 return -1;
319 else if (*key > elt->dest)
320 return 1;
321 return 0;
322}
323
324static int _ni_bsearch_srccmp(const void *vkey, const void *velt)
325{
326 const int *key = vkey;
327 const int *elt = velt;
328
329 if (*key < *elt)
330 return -1;
331 else if (*key > *elt)
332 return 1;
333 return 0;
334}
335
336/**
337 * ni_find_route_set() - Finds the proper route set with the specified
338 * destination.
339 * @destination: Destination of which to search for the route set.
340 * @valid_routes: Pointer to device routes within which to search.
341 *
342 * Return: NULL if no route_set is found with the specified @destination;
343 * otherwise, a pointer to the route_set if found.
344 */
345const struct ni_route_set *
346ni_find_route_set(const int destination,
347 const struct ni_device_routes *valid_routes)
348{
349 return bsearch(&destination, valid_routes->routes,
350 valid_routes->n_route_sets, sizeof(struct ni_route_set),
351 _ni_bsearch_destcmp);
352}
353EXPORT_SYMBOL_GPL(ni_find_route_set);
354
355/**
356 * ni_route_set_has_source() - Determines whether the given source is in
357 * included given route_set.
358 *
359 * Return: true if found; false otherwise.
360 */
361bool ni_route_set_has_source(const struct ni_route_set *routes,
362 const int source)
363{
364 if (!bsearch(&source, routes->src, routes->n_src, sizeof(int),
365 _ni_bsearch_srccmp))
366 return false;
367 return true;
368}
369EXPORT_SYMBOL_GPL(ni_route_set_has_source);
370
371/**
372 * ni_lookup_route_register() - Look up a register value for a particular route
373 * without checking whether the route is valid for
374 * the particular device.
375 * @src: global-identifier for route source
376 * @dest: global-identifier for route destination
377 * @tables: pointer to relevant set of routing tables.
378 *
379 * Return: -EINVAL if the specified route is not valid for this device family.
380 */
381s8 ni_lookup_route_register(int src, int dest,
382 const struct ni_route_tables *tables)
383{
384 s8 regval;
385
386 /*
387 * Be sure to use the B() macro to subtract off the NI_NAMES_BASE before
388 * indexing into the route_values array.
389 */
390 src = B(src);
391 dest = B(dest);
392 if (src < 0 || src >= NI_NUM_NAMES || dest < 0 || dest >= NI_NUM_NAMES)
393 return -EINVAL;
394 regval = RVi(tables->route_values, src, dest);
395 if (!regval)
396 return -EINVAL;
397 /* mask out the valid-value marking bit */
398 return UNMARK(regval);
399}
400EXPORT_SYMBOL_GPL(ni_lookup_route_register);
401
402/**
403 * ni_route_to_register() - Validates and converts the specified signal route
404 * (src-->dest) to the value used at the appropriate
405 * register.
406 * @src: global-identifier for route source
407 * @dest: global-identifier for route destination
408 * @tables: pointer to relevant set of routing tables.
409 *
410 * Generally speaking, most routes require the first six bits and a few require
411 * 7 bits. Special handling is given for the return value when the route is to
412 * be handled by the RTSI sub-device. In this case, the returned register may
413 * not be sufficient to define the entire route path, but rather may only
414 * indicate the intermediate route. For example, if the route must go through
415 * the RGOUT0 pin, the (src->RGOUT0) register value will be returned.
416 * Similarly, if the route must go through the NI_RTSI_BRD lines, the BIT(6)
417 * will be set:
418 *
419 * if route does not need RTSI_BRD lines:
420 * bits 0:7 : register value
421 * for a route that must go through RGOUT0 pin, this will be equal
422 * to the (src->RGOUT0) register value.
423 * else: * route is (src->RTSI_BRD(x), RTSI_BRD(x)->TRIGGER_LINE(i)) *
424 * bits 0:5 : zero
425 * bits 6 : set to 1
426 * bits 7:7 : zero
427 *
428 * Return: register value to be used for source at destination with special
429 * cases given above; Otherwise, -1 if the specified route is not valid for
430 * this particular device.
431 */
432s8 ni_route_to_register(const int src, const int dest,
433 const struct ni_route_tables *tables)
434{
435 const struct ni_route_set *routes =
436 ni_find_route_set(dest, tables->valid_routes);
437 const u8 *rv;
438 s8 regval;
439
440 /* first check to see if source is listed with bunch of destinations. */
441 if (!routes)
442 return -1;
443 /* 2nd, check to see if destination is in list of source's targets. */
444 if (!ni_route_set_has_source(routes, src))
445 return -1;
446 /*
447 * finally, check to see if we know how to route...
448 * Be sure to use the B() macro to subtract off the NI_NAMES_BASE before
449 * indexing into the route_values array.
450 */
451 rv = tables->route_values;
452 regval = RVi(rv, B(src), B(dest));
453
454 /*
455 * if we did not validate the route, we'll see if we can route through
456 * one of the muxes
457 */
458 if (!regval && channel_is_rtsi(dest)) {
459 regval = RVi(rv, B(src), B(NI_RGOUT0));
460 if (!regval && (RVi(rv, B(src), B(NI_RTSI_BRD(0))) ||
461 RVi(rv, B(src), B(NI_RTSI_BRD(1))) ||
462 RVi(rv, B(src), B(NI_RTSI_BRD(2))) ||
463 RVi(rv, B(src), B(NI_RTSI_BRD(3)))))
464 regval = BIT(6);
465 }
466
467 if (!regval)
468 return -1;
469 /* mask out the valid-value marking bit */
470 return UNMARK(regval);
471}
472EXPORT_SYMBOL_GPL(ni_route_to_register);
473
474/**
475 * ni_find_route_source() - Finds the signal source corresponding to a signal
476 * route (src-->dest) of the specified routing register
477 * value and the specified route destination on the
478 * specified device.
479 *
480 * Note that this function does _not_ validate the source based on device
481 * routes.
482 *
483 * Return: The NI signal value (e.g. NI_PFI(0) or PXI_Clk10) if found.
484 * If the source was not found (i.e. the register value is not
485 * valid for any routes to the destination), -EINVAL is returned.
486 */
487int ni_find_route_source(const u8 src_sel_reg_value, int dest,
488 const struct ni_route_tables *tables)
489{
490 int src;
491
492 dest = B(dest); /* subtract NI names offset */
493 /* ensure we are not going to under/over run the route value table */
494 if (dest < 0 || dest >= NI_NUM_NAMES)
495 return -EINVAL;
496 for (src = 0; src < NI_NUM_NAMES; ++src)
497 if (RVi(tables->route_values, src, dest) ==
498 V(src_sel_reg_value))
499 return src + NI_NAMES_BASE;
500 return -EINVAL;
501}
502EXPORT_SYMBOL_GPL(ni_find_route_source);
503
504/* **** END Routes search routines **** */
505
506/* **** BEGIN simple module entry/exit functions **** */
507static int __init ni_routes_module_init(void)
508{
509 ni_sort_all_device_routes();
510 return 0;
511}
512
513static void __exit ni_routes_module_exit(void)
514{
515}
516
517module_init(ni_routes_module_init);
518module_exit(ni_routes_module_exit);
519
520MODULE_AUTHOR("Comedi http://www.comedi.org");
521MODULE_DESCRIPTION("Comedi helper for routing signals-->terminals for NI");
522MODULE_LICENSE("GPL");
523/* **** END simple module entry/exit functions **** */
diff --git a/drivers/staging/comedi/drivers/ni_routes.h b/drivers/staging/comedi/drivers/ni_routes.h
new file mode 100644
index 000000000000..3211a16adc6f
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routes.h
@@ -0,0 +1,329 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routes.h
5 * Route information for NI boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21#ifndef _COMEDI_DRIVERS_NI_ROUTES_H
22#define _COMEDI_DRIVERS_NI_ROUTES_H
23
24#include <linux/types.h>
25#include <linux/errno.h>
26
27#ifndef NI_ROUTE_VALUE_EXTERNAL_CONVERSION
28#include <linux/bitops.h>
29#endif
30
31#include "../comedi.h"
32
33/**
34 * struct ni_route_set - Set of destinations with a common source.
35 * @dest: Destination of all sources in this route set.
36 * @n_src: Number of sources for this route set.
37 * @src: List of sources that all map to the same destination.
38 */
39struct ni_route_set {
40 int dest;
41 int n_src;
42 int *src;
43};
44
45/**
46 * struct ni_device_routes - List of all src->dest sets for a particular device.
47 * @device: Name of board/device (e.g. pxi-6733).
48 * @n_route_sets: Number of route sets that are valid for this device.
49 * @routes: List of route sets that are valid for this device.
50 */
51struct ni_device_routes {
52 const char *device;
53 int n_route_sets;
54 struct ni_route_set *routes;
55};
56
57/**
58 * struct ni_route_tables - Register values and valid routes for a device.
59 * @valid_routes: Pointer to a all valid route sets for a single device.
60 * @route_values: Pointer to register values for all routes for the family to
61 * which the device belongs.
62 *
63 * Link to the valid src->dest routes and the register values used to assign
64 * such routes for that particular device.
65 */
66struct ni_route_tables {
67 const struct ni_device_routes *valid_routes;
68 const u8 *route_values;
69};
70
71/*
72 * ni_assign_device_routes() - Assign the proper lookup table for NI signal
73 * routing to the specified NI device.
74 *
75 * Return: -ENODATA if assignment was not successful; 0 if successful.
76 */
77int ni_assign_device_routes(const char *device_family,
78 const char *board_name,
79 struct ni_route_tables *tables);
80
81/*
82 * ni_find_route_set() - Finds the proper route set with the specified
83 * destination.
84 * @destination: Destination of which to search for the route set.
85 * @valid_routes: Pointer to device routes within which to search.
86 *
87 * Return: NULL if no route_set is found with the specified @destination;
88 * otherwise, a pointer to the route_set if found.
89 */
90const struct ni_route_set *
91ni_find_route_set(const int destination,
92 const struct ni_device_routes *valid_routes);
93
94/*
95 * ni_route_set_has_source() - Determines whether the given source is in
96 * included given route_set.
97 *
98 * Return: true if found; false otherwise.
99 */
100bool ni_route_set_has_source(const struct ni_route_set *routes, const int src);
101
102/*
103 * ni_route_to_register() - Validates and converts the specified signal route
104 * (src-->dest) to the value used at the appropriate
105 * register.
106 * @src: global-identifier for route source
107 * @dest: global-identifier for route destination
108 * @tables: pointer to relevant set of routing tables.
109 *
110 * Generally speaking, most routes require the first six bits and a few require
111 * 7 bits. Special handling is given for the return value when the route is to
112 * be handled by the RTSI sub-device. In this case, the returned register may
113 * not be sufficient to define the entire route path, but rather may only
114 * indicate the intermediate route. For example, if the route must go through
115 * the RGOUT0 pin, the (src->RGOUT0) register value will be returned.
116 * Similarly, if the route must go through the NI_RTSI_BRD lines, the BIT(6)
117 * will be set:
118 *
119 * if route does not need RTSI_BRD lines:
120 * bits 0:7 : register value
121 * for a route that must go through RGOUT0 pin, this will be equal
122 * to the (src->RGOUT0) register value.
123 * else: * route is (src->RTSI_BRD(x), RTSI_BRD(x)->TRIGGER_LINE(i)) *
124 * bits 0:5 : zero
125 * bits 6 : set to 1
126 * bits 7:7 : zero
127 *
128 * Return: register value to be used for source at destination with special
129 * cases given above; Otherwise, -1 if the specified route is not valid for
130 * this particular device.
131 */
132s8 ni_route_to_register(const int src, const int dest,
133 const struct ni_route_tables *tables);
134
135static inline bool ni_rtsi_route_requires_mux(s8 value)
136{
137 return value & BIT(6);
138}
139
140/*
141 * ni_lookup_route_register() - Look up a register value for a particular route
142 * without checking whether the route is valid for
143 * the particular device.
144 * @src: global-identifier for route source
145 * @dest: global-identifier for route destination
146 * @tables: pointer to relevant set of routing tables.
147 *
148 * Return: -EINVAL if the specified route is not valid for this device family.
149 */
150s8 ni_lookup_route_register(int src, int dest,
151 const struct ni_route_tables *tables);
152
153/**
154 * route_is_valid() - Determines whether the specified signal route (src-->dest)
155 * is valid for the given NI comedi_device.
156 * @src: global-identifier for route source
157 * @dest: global-identifier for route destination
158 * @tables: pointer to relevant set of routing tables.
159 *
160 * Return: True if the route is valid, otherwise false.
161 */
162static inline bool route_is_valid(const int src, const int dest,
163 const struct ni_route_tables *tables)
164{
165 return ni_route_to_register(src, dest, tables) >= 0;
166}
167
168/*
169 * ni_is_cmd_dest() - Determine whether the given destination is only
170 * configurable via a comedi_cmd struct.
171 * @dest: Destination to test.
172 */
173bool ni_is_cmd_dest(int dest);
174
175static inline bool channel_is_pfi(int channel)
176{
177 return NI_PFI(0) <= channel && channel <= NI_PFI(-1);
178}
179
180static inline bool channel_is_rtsi(int channel)
181{
182 return TRIGGER_LINE(0) <= channel && channel <= TRIGGER_LINE(-1);
183}
184
185static inline bool channel_is_ctr(int channel)
186{
187 return channel >= NI_COUNTER_NAMES_BASE &&
188 channel <= NI_COUNTER_NAMES_MAX;
189}
190
191/*
192 * ni_count_valid_routes() - Count the number of valid routes.
193 * @tables: Routing tables for which to count all valid routes.
194 */
195unsigned int ni_count_valid_routes(const struct ni_route_tables *tables);
196
197/*
198 * ni_get_valid_routes() - Implements INSN_DEVICE_CONFIG_GET_ROUTES.
199 * @tables: pointer to relevant set of routing tables.
200 * @n_pairs: Number of pairs for which memory is allocated by the user. If
201 * the user specifies '0', only the number of available pairs is
202 * returned.
203 * @pair_data: Pointer to memory allocated to return pairs back to user. Each
204 * even, odd indexed member of this array will hold source,
205 * destination of a route pair respectively.
206 *
207 * Return: the number of valid routes if n_pairs == 0; otherwise, the number of
208 * valid routes copied.
209 */
210unsigned int ni_get_valid_routes(const struct ni_route_tables *tables,
211 unsigned int n_pairs,
212 unsigned int *pair_data);
213
214/*
215 * ni_sort_device_routes() - Sort the list of valid device signal routes in
216 * preparation for use.
217 * @valid_routes: pointer to ni_device_routes struct to sort.
218 */
219void ni_sort_device_routes(struct ni_device_routes *valid_routes);
220
221/*
222 * ni_find_route_source() - Finds the signal source corresponding to a signal
223 * route (src-->dest) of the specified routing register
224 * value and the specified route destination on the
225 * specified device.
226 *
227 * Note that this function does _not_ validate the source based on device
228 * routes.
229 *
230 * Return: The NI signal value (e.g. NI_PFI(0) or PXI_Clk10) if found.
231 * If the source was not found (i.e. the register value is not
232 * valid for any routes to the destination), -EINVAL is returned.
233 */
234int ni_find_route_source(const u8 src_sel_reg_value, const int dest,
235 const struct ni_route_tables *tables);
236
237/**
238 * route_register_is_valid() - Determines whether the register value for the
239 * specified route destination on the specified
240 * device is valid.
241 */
242static inline bool route_register_is_valid(const u8 src_sel_reg_value,
243 const int dest,
244 const struct ni_route_tables *tables)
245{
246 return ni_find_route_source(src_sel_reg_value, dest, tables) >= 0;
247}
248
249/**
250 * ni_get_reg_value_roffs() - Determines the proper register value for a
251 * particular valid NI signal/terminal route.
252 * @src: Either a direct register value or one of NI_* signal names.
253 * @dest: global-identifier for route destination
254 * @tables: pointer to relevant set of routing tables.
255 * @direct_reg_offset:
256 * Compatibility compensation argument. This argument allows us to
257 * arbitrarily apply an offset to src if src is a direct register
258 * value reference. This is necessary to be compatible with
259 * definitions of register values as previously exported directly
260 * to user space.
261 *
262 * Return: the register value (>0) to be used at the destination if the src is
263 * valid for the given destination; -1 otherwise.
264 */
265static inline s8 ni_get_reg_value_roffs(int src, const int dest,
266 const struct ni_route_tables *tables,
267 const int direct_reg_offset)
268{
269 if (src < NI_NAMES_BASE) {
270 src += direct_reg_offset;
271 /*
272 * In this case, the src is expected to actually be a register
273 * value.
274 */
275 if (route_register_is_valid(src, dest, tables))
276 return src;
277 return -1;
278 }
279
280 /*
281 * Otherwise, the src is expected to be one of the abstracted NI
282 * signal/terminal names.
283 */
284 return ni_route_to_register(src, dest, tables);
285}
286
287static inline int ni_get_reg_value(const int src, const int dest,
288 const struct ni_route_tables *tables)
289{
290 return ni_get_reg_value_roffs(src, dest, tables, 0);
291}
292
293/**
294 * ni_check_trigger_arg_roffs() - Checks the trigger argument (*_arg) of an NI
295 * device to ensure that the *_arg value
296 * corresponds to _either_ a valid register value
297 * to define a trigger source, _or_ a valid NI
298 * signal/terminal name that has a valid route to
299 * the destination on the particular device.
300 * @src: Either a direct register value or one of NI_* signal names.
301 * @dest: global-identifier for route destination
302 * @tables: pointer to relevant set of routing tables.
303 * @direct_reg_offset:
304 * Compatibility compensation argument. This argument allows us to
305 * arbitrarily apply an offset to src if src is a direct register
306 * value reference. This is necessary to be compatible with
307 * definitions of register values as previously exported directly
308 * to user space.
309 *
310 * Return: 0 if the src (either register value or NI signal/terminal name) is
311 * valid for the destination; -EINVAL otherwise.
312 */
313static inline
314int ni_check_trigger_arg_roffs(int src, const int dest,
315 const struct ni_route_tables *tables,
316 const int direct_reg_offset)
317{
318 if (ni_get_reg_value_roffs(src, dest, tables, direct_reg_offset) < 0)
319 return -EINVAL;
320 return 0;
321}
322
323static inline int ni_check_trigger_arg(const int src, const int dest,
324 const struct ni_route_tables *tables)
325{
326 return ni_check_trigger_arg_roffs(src, dest, tables, 0);
327}
328
329#endif /* _COMEDI_DRIVERS_NI_ROUTES_H */
diff --git a/drivers/staging/comedi/drivers/ni_routing/README b/drivers/staging/comedi/drivers/ni_routing/README
new file mode 100644
index 000000000000..b65c4ebedbc4
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/README
@@ -0,0 +1,240 @@
1Framework for Maintaining Common National Instruments Terminal/Signal names
2
3The contents of this directory are primarily for maintaining and formatting all
4known valid signal routes for various National Instruments devices.
5
6Some background:
7 There have been significant confusions over the past many years for users
8 when trying to understand how to connect to/from signals and terminals on
9 NI hardware using comedi. The major reason for this is that the actual
10 register values were exposed and required to be used by users. Several
11 major reasons exist why this caused major confusion for users:
12
13 1) The register values are _NOT_ in user documentation, but rather in
14 arcane locations, such as a few register programming manuals that are
15 increasingly hard to find and the NI-MHDDK (comments in in example code).
16 There is no one place to find the various valid values of the registers.
17
18 2) The register values are _NOT_ completely consistent. There is no way to
19 gain any sense of intuition of which values, or even enums one should use
20 for various registers. There was some attempt in prior use of comedi to
21 name enums such that a user might know which enums should be used for
22 varying purposes, but the end-user had to gain a knowledge of register
23 values to correctly wield this approach.
24
25 3) The names for signals and registers found in the various register level
26 programming manuals and vendor-provided documentation are _not_ even
27 close to the same names that are in the end-user documentation.
28
29 4) The sets of routes that are valid are not consistent from device to device.
30 One additional major challenge is that this information does not seem to be
31 obtainable in any programmatic fashion, neither through the proprietary
32 NIDAQmx(-base) c-libraries, nor with register level programming, _nor_
33 through any documentation. In fact, the only consistent source of this
34 information is through the proprietary NI-MAX software, which currently only
35 runs on Windows platforms. A further challenge is that this information
36 cannot be exported from NI-MAX, except by screenshot.
37
38
39
40The content of this directory is part of an effort to greatly simplify the use
41of signal routing capabilities of National Instruments data-acquisition and
42control hardware. In order to facilitate the transfer of register-level
43information _and_ the knowledge of valid routes per device, a few specific
44choices were made:
45
46
471) The names of the National Instruments signals/terminals that are used in this
48 directory are chosen to be consistent with (a) the NI's user level
49 documentation, (b) NI's user-level code, (c) the information as provided by
50 the proprietary NI-MAX software, and (d) the user interface code provided by
51 the user-land comedilib library.
52
53 The impact of this choice implies that one allows the use of CamelScript names
54 in the kernel. In short, the choice to use CamelScript and the exact names
55 below is for maintainability, clarity, similarity to manufacturer's
56 documentation, _and_ a mitigation for confusion that has plagued the use of
57 these drivers for years!
58
592) The bulk of the real content for this directory is stored in two separate
60 collections (i.e. sub-directories) of tables stored in c source files:
61
62 (a) ni_route_values/ni_[series-label]series.c
63
64 This data represents all the various register values to use for the
65 multiple different signal MUXes for the specific device families.
66
67 The values are all wrapped in one of three macros to help document and
68 track which values have been implemented and tested.
69 These macros are:
70 V(<value>) : register value is valid, tested, and implemented
71 I(<value>) : register value is implemented but needs testing
72 U(<value>) : register value is not implemented
73
74 The actual function of these macros will depend on whether the code is
75 compiled in the kernel or whether it is compiled into the conversion
76 tools. For the conversion tools, it can be used to indicate the status
77 of the register value. For the kernel, V() and I() both perform the
78 same function and prepare data to be used; U() zeroes out the value to
79 ensure that it cannot be used.
80
81 *** It would be a great help for users to test these values such that
82 these files can be correctly marked/documented ***
83
84 (b) ni_device_routes/[board-name].c
85
86 This data represents the known set of valid signal routes that are
87 possible for each specific board. Although the family defines the
88 register values to use for a particular signal MUX, not all possible
89 signals are actually available on each board.
90
91 In order for a particular board to take advantage of the effort to
92 simplify/clarify signal routing on NI devices, a corresponding
93 [board-name].c file must be created. This file should reflect the known
94 valid _direct_ routing capabilities of the board.
95
96 As noted above, the only known consistent source of information for
97 valid device routes comes from the proprietary National Instruments
98 Windows software, NI-MAX. Also, as noted above, this information can
99 only be visually conveyed from NI-MAX to other media. To make this
100 easier, the naming conventions used in the [board-name].c file are
101 similar to the naming conventions as presented by NI-MAX.
102
103
1043) Two other files aggregate the above data to integrate it into comedi:
105 ni_route_values.c
106 ni_device_routes.c
107
108 When adding a new [board-name].c file, be sure to also add in the line in
109 ni_device_routes.c to include this information into comedi.
110
111
1124) Several tools have been included to convert from/to the c file formats.
113 These tools are best used/demonstrated via the included Makefile targets:
114 (a) `make csv-files`
115 Creates new csv-files using content of c-files of existing
116 ni_routing/* content. New csv files are placed in csv
117 sub-directory.
118
119 As noted above, the only consistent source of information of valid
120 device routes comes from the proprietary National Instruments Windows
121 software, NI-MAX. Also, as noted above, this information can only be
122 visually conveyed from NI-MAX to other media. This make target creates
123 spreadsheet representations of the routing data. The choice of using a
124 spreadsheet (ala CSV) to copy this information allows for easy direct
125 visual comparison to the NI-MAX "Valid Routes" tables.
126
127 Furthermore, the register-level information is much easier to identify and
128 correct when entire families of NI devices are shown side by side in table
129 format. This is made easy by using a file-storage format that can be
130 loaded into a spreadsheet application.
131
132 Finally, .csv content is very easy to edit and read using a variety of
133 tools, including spreadsheets or various other scripting languages. In
134 fact, the tools provided here enable quick conversion of the
135 spreadsheet-like .csv format to c-files that follow the kernel coding
136 conventions.
137
138
139 (b) `make c-files`
140 Creates new c-files using content of csv sub-directory. These
141 new c-files can be compared to the active content in the
142 ni_routing directory.
143 (c) `make csv-blank`
144 Create a new blank csv file. This is useful for establishing a
145 new data table for either a device family (less likely) or a
146 specific board of an existing device family (more likely).
147 (d) `make clean`
148 Remove all generated files/directories.
149 (e) `make everything`
150 Build all csv-files, then all new c-files.
151
152
153
154
155In summary, similar confusion about signal routing configuration, albeit less,
156plagued NI's previous version of their own proprietary drivers. Earlier than
1572003, NI greatly simplified the situation for users by releasing a new API that
158abstracted the names of signals/terminals to a common and intuitive set of
159names. In addition, this new API provided a much more common interface to use
160for most of NI hardware.
161
162Comedi already provides such a common interface for data-acquisition and control
163hardware. This effort complements comedi's abstraction layers by further
164abstracting much more of the use cases for NI hardware, but allowing users _and_
165developers to directly refer to NI documentation (user-level, register-level,
166and the register-level examples of the NI-MHDDK).
167
168
169
170--------------------------------------------------------------------------------
171Various naming conventions and relations:
172--------------------------------------------------------------------------------
173These are various notes that help to relate the naming conventions used in the
174NI-STC with those naming conventions used here.
175--------------------------------------------------------------------------------
176
177 Signal sources for most signals-destinations are given a specific naming
178 convention, although the register values are not consistent. This next table
179 shows the mapping between the names used in comedi for NI and those names
180 typically used within the NI-STC documentation.
181
182 (comedi) (NI-STC input or output) (NOTE)
183 ------------------------------------------------------------------------------
184 TRIGGER_LINE(i) RTSI_Trig_i_Output_Select i in range [0..7]
185 NI_AI_STOP AI_STOP
186 NI_AI_SampleClock AI_START_Select
187 NI_AI_SampleClockTimebase AI_SI If internal sample
188 clock signal is used
189 NI_AI_StartTrigger AI_START1_Select
190 NI_AI_ReferenceTrigger AI_START2_Select for pre-triggered
191 acquisition---not
192 currently supported
193 in comedi
194 NI_AI_ConvertClock AI_CONVERT_Source_Select
195 NI_AI_ConvertClockTimebase AI_SI2 If internal convert
196 signal is used
197 NI_AI_HoldCompleteEvent
198 NI_AI_PauseTrigger AI_External_Gate
199 NI_AO_SampleClock AO_UPDATE
200 NI_AO_SampleClockTimebase AO_UI
201 NI_AO_StartTrigger AO_START1
202 NI_AO_PauseTrigger AO_External_Gate
203 NI_DI_SampleClock
204 NI_DO_SampleClock
205 NI_MasterTimebase
206 NI_20MHzTimebase TIMEBASE 1 && TIMEBASE 3 if no higher clock exists
207 NI_80MHzTimebase TIMEBASE 3
208 NI_100kHzTimebase TIMEBASE 2
209 NI_10MHzRefClock
210 PXI_Clk10
211 NI_CtrOut(0) GPFO_0 external ctr0out pin
212 NI_CtrOut(1) GPFO_1 external ctr1out pin
213 NI_CtrSource(0)
214 NI_CtrSource(1)
215 NI_CtrGate(0)
216 NI_CtrGate(1)
217 NI_CtrInternalOutput(0) G_OUT0, G0_TC for Ctr1Source, Ctr1Gate
218 NI_CtrInternalOutput(1) G_OUT1, G1_TC for Ctr0Source, Ctr0Gate
219 NI_RGOUT0 RGOUT0 internal signal
220 NI_FrequencyOutput
221 #NI_FrequencyOutputTimebase
222 NI_ChangeDetectionEvent
223 NI_RTSI_BRD(0)
224 NI_RTSI_BRD(1)
225 NI_RTSI_BRD(2)
226 NI_RTSI_BRD(3)
227 #NI_SoftwareStrobe
228 NI_LogicLow
229 NI_CtrA(0) G0_A_Select see M-Series user
230 manual (371022K-01)
231 NI_CtrA(1) G1_A_Select see M-Series user
232 manual (371022K-01)
233 NI_CtrB(0) G0_B_Select, up/down see M-Series user
234 manual (371022K-01)
235 NI_CtrB(1) G1_B_Select, up/down see M-Series user
236 manual (371022K-01)
237 NI_CtrZ(0) see M-Series user
238 manual (371022K-01)
239 NI_CtrZ(1) see M-Series user
240 manual (371022K-01)
diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_device_routes.c b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes.c
new file mode 100644
index 000000000000..7b6a74dfe48b
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes.c
@@ -0,0 +1,51 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routing/ni_device_routes.c
5 * List of valid routes for specific NI boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21/*
22 * The contents of this file are generated using the tools in
23 * comedi/drivers/ni_routing/tools
24 *
25 * Please use those tools to help maintain the contents of this file.
26 */
27
28#include "ni_device_routes.h"
29#include "ni_device_routes/all.h"
30
31struct ni_device_routes *const ni_device_routes_list[] = {
32 &ni_pxi_6030e_device_routes,
33 &ni_pci_6070e_device_routes,
34 &ni_pci_6220_device_routes,
35 &ni_pci_6221_device_routes,
36 &ni_pxi_6224_device_routes,
37 &ni_pxi_6225_device_routes,
38 &ni_pci_6229_device_routes,
39 &ni_pci_6251_device_routes,
40 &ni_pxi_6251_device_routes,
41 &ni_pxie_6251_device_routes,
42 &ni_pci_6254_device_routes,
43 &ni_pci_6259_device_routes,
44 &ni_pci_6534_device_routes,
45 &ni_pci_6602_device_routes,
46 &ni_pci_6713_device_routes,
47 &ni_pci_6723_device_routes,
48 &ni_pci_6733_device_routes,
49 &ni_pxi_6733_device_routes,
50 NULL,
51};
diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_device_routes.h b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes.h
new file mode 100644
index 000000000000..b9f1c47d19e1
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes.h
@@ -0,0 +1,32 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routing/ni_device_routes.c
5 * List of valid routes for specific NI boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21/*
22 * This file is meant to be included by comedi/drivers/ni_routes.c
23 */
24
25#ifndef _COMEDI_DRIVERS_NI_ROUTINT_NI_DEVICE_ROUTES_H
26#define _COMEDI_DRIVERS_NI_ROUTINT_NI_DEVICE_ROUTES_H
27
28#include "../ni_routes.h"
29
30extern struct ni_device_routes *const ni_device_routes_list[];
31
32#endif /* _COMEDI_DRIVERS_NI_ROUTINT_NI_DEVICE_ROUTES_H */
diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/all.h b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/all.h
new file mode 100644
index 000000000000..78b24138acb7
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/all.h
@@ -0,0 +1,54 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routing/ni_device_routes/all.h
5 * List of valid routes for specific NI boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21/*
22 * The contents of this file are generated using the tools in
23 * comedi/drivers/ni_routing/tools
24 *
25 * Please use those tools to help maintain the contents of this file.
26 */
27
28#ifndef _COMEDI_DRIVERS_NI_ROUTING_NI_DEVICE_ROUTES_EXTERN_H
29#define _COMEDI_DRIVERS_NI_ROUTING_NI_DEVICE_ROUTES_EXTERN_H
30
31#include "../ni_device_routes.h"
32
33extern struct ni_device_routes ni_pxi_6030e_device_routes;
34extern struct ni_device_routes ni_pci_6070e_device_routes;
35extern struct ni_device_routes ni_pci_6220_device_routes;
36extern struct ni_device_routes ni_pci_6221_device_routes;
37extern struct ni_device_routes ni_pxi_6224_device_routes;
38extern struct ni_device_routes ni_pxi_6225_device_routes;
39extern struct ni_device_routes ni_pci_6229_device_routes;
40extern struct ni_device_routes ni_pci_6251_device_routes;
41extern struct ni_device_routes ni_pxi_6251_device_routes;
42extern struct ni_device_routes ni_pxie_6251_device_routes;
43extern struct ni_device_routes ni_pci_6254_device_routes;
44extern struct ni_device_routes ni_pci_6259_device_routes;
45extern struct ni_device_routes ni_pci_6534_device_routes;
46extern struct ni_device_routes ni_pxie_6535_device_routes;
47extern struct ni_device_routes ni_pci_6602_device_routes;
48extern struct ni_device_routes ni_pci_6713_device_routes;
49extern struct ni_device_routes ni_pci_6723_device_routes;
50extern struct ni_device_routes ni_pci_6733_device_routes;
51extern struct ni_device_routes ni_pxi_6733_device_routes;
52extern struct ni_device_routes ni_pxie_6738_device_routes;
53
54#endif //_COMEDI_DRIVERS_NI_ROUTING_NI_DEVICE_ROUTES_EXTERN_H
diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6070e.c b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6070e.c
new file mode 100644
index 000000000000..f1126a0cb285
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6070e.c
@@ -0,0 +1,639 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routing/ni_device_routes/pci-6070e.c
5 * List of valid routes for specific NI boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21/*
22 * The contents of this file are generated using the tools in
23 * comedi/drivers/ni_routing/tools
24 *
25 * Please use those tools to help maintain the contents of this file.
26 */
27
28#include "../ni_device_routes.h"
29#include "all.h"
30
31struct ni_device_routes ni_pci_6070e_device_routes = {
32 .device = "pci-6070e",
33 .routes = (struct ni_route_set[]){
34 {
35 .dest = NI_PFI(0),
36 .src = (int[]){
37 NI_AI_StartTrigger,
38 0, /* Termination */
39 }
40 },
41 {
42 .dest = NI_PFI(1),
43 .src = (int[]){
44 NI_AI_ReferenceTrigger,
45 0, /* Termination */
46 }
47 },
48 {
49 .dest = NI_PFI(2),
50 .src = (int[]){
51 NI_AI_ConvertClock,
52 0, /* Termination */
53 }
54 },
55 {
56 .dest = NI_PFI(3),
57 .src = (int[]){
58 NI_CtrSource(1),
59 0, /* Termination */
60 }
61 },
62 {
63 .dest = NI_PFI(4),
64 .src = (int[]){
65 NI_CtrGate(1),
66 0, /* Termination */
67 }
68 },
69 {
70 .dest = NI_PFI(5),
71 .src = (int[]){
72 NI_AO_SampleClock,
73 0, /* Termination */
74 }
75 },
76 {
77 .dest = NI_PFI(6),
78 .src = (int[]){
79 NI_AO_StartTrigger,
80 0, /* Termination */
81 }
82 },
83 {
84 .dest = NI_PFI(7),
85 .src = (int[]){
86 NI_AI_SampleClock,
87 0, /* Termination */
88 }
89 },
90 {
91 .dest = NI_PFI(8),
92 .src = (int[]){
93 NI_CtrSource(0),
94 0, /* Termination */
95 }
96 },
97 {
98 .dest = NI_PFI(9),
99 .src = (int[]){
100 NI_CtrGate(0),
101 0, /* Termination */
102 }
103 },
104 {
105 .dest = TRIGGER_LINE(0),
106 .src = (int[]){
107 NI_CtrSource(0),
108 NI_CtrGate(0),
109 NI_CtrInternalOutput(0),
110 NI_CtrOut(0),
111 NI_AI_SampleClock,
112 NI_AI_StartTrigger,
113 NI_AI_ReferenceTrigger,
114 NI_AI_ConvertClock,
115 NI_AO_SampleClock,
116 NI_AO_StartTrigger,
117 0, /* Termination */
118 }
119 },
120 {
121 .dest = TRIGGER_LINE(1),
122 .src = (int[]){
123 NI_CtrSource(0),
124 NI_CtrGate(0),
125 NI_CtrInternalOutput(0),
126 NI_CtrOut(0),
127 NI_AI_SampleClock,
128 NI_AI_StartTrigger,
129 NI_AI_ReferenceTrigger,
130 NI_AI_ConvertClock,
131 NI_AO_SampleClock,
132 NI_AO_StartTrigger,
133 0, /* Termination */
134 }
135 },
136 {
137 .dest = TRIGGER_LINE(2),
138 .src = (int[]){
139 NI_CtrSource(0),
140 NI_CtrGate(0),
141 NI_CtrInternalOutput(0),
142 NI_CtrOut(0),
143 NI_AI_SampleClock,
144 NI_AI_StartTrigger,
145 NI_AI_ReferenceTrigger,
146 NI_AI_ConvertClock,
147 NI_AO_SampleClock,
148 NI_AO_StartTrigger,
149 0, /* Termination */
150 }
151 },
152 {
153 .dest = TRIGGER_LINE(3),
154 .src = (int[]){
155 NI_CtrSource(0),
156 NI_CtrGate(0),
157 NI_CtrInternalOutput(0),
158 NI_CtrOut(0),
159 NI_AI_SampleClock,
160 NI_AI_StartTrigger,
161 NI_AI_ReferenceTrigger,
162 NI_AI_ConvertClock,
163 NI_AO_SampleClock,
164 NI_AO_StartTrigger,
165 0, /* Termination */
166 }
167 },
168 {
169 .dest = TRIGGER_LINE(4),
170 .src = (int[]){
171 NI_CtrSource(0),
172 NI_CtrGate(0),
173 NI_CtrInternalOutput(0),
174 NI_CtrOut(0),
175 NI_AI_SampleClock,
176 NI_AI_StartTrigger,
177 NI_AI_ReferenceTrigger,
178 NI_AI_ConvertClock,
179 NI_AO_SampleClock,
180 NI_AO_StartTrigger,
181 0, /* Termination */
182 }
183 },
184 {
185 .dest = TRIGGER_LINE(5),
186 .src = (int[]){
187 NI_CtrSource(0),
188 NI_CtrGate(0),
189 NI_CtrInternalOutput(0),
190 NI_CtrOut(0),
191 NI_AI_SampleClock,
192 NI_AI_StartTrigger,
193 NI_AI_ReferenceTrigger,
194 NI_AI_ConvertClock,
195 NI_AO_SampleClock,
196 NI_AO_StartTrigger,
197 0, /* Termination */
198 }
199 },
200 {
201 .dest = TRIGGER_LINE(6),
202 .src = (int[]){
203 NI_CtrSource(0),
204 NI_CtrGate(0),
205 NI_CtrInternalOutput(0),
206 NI_CtrOut(0),
207 NI_AI_SampleClock,
208 NI_AI_StartTrigger,
209 NI_AI_ReferenceTrigger,
210 NI_AI_ConvertClock,
211 NI_AO_SampleClock,
212 NI_AO_StartTrigger,
213 0, /* Termination */
214 }
215 },
216 {
217 .dest = TRIGGER_LINE(7),
218 .src = (int[]){
219 NI_20MHzTimebase,
220 0, /* Termination */
221 }
222 },
223 {
224 .dest = NI_CtrSource(0),
225 .src = (int[]){
226 NI_PFI(0),
227 NI_PFI(1),
228 NI_PFI(2),
229 NI_PFI(3),
230 NI_PFI(4),
231 NI_PFI(5),
232 NI_PFI(6),
233 NI_PFI(7),
234 NI_PFI(8),
235 NI_PFI(9),
236 TRIGGER_LINE(0),
237 TRIGGER_LINE(1),
238 TRIGGER_LINE(2),
239 TRIGGER_LINE(3),
240 TRIGGER_LINE(4),
241 TRIGGER_LINE(5),
242 TRIGGER_LINE(6),
243 TRIGGER_LINE(7),
244 NI_MasterTimebase,
245 NI_20MHzTimebase,
246 NI_100kHzTimebase,
247 NI_AnalogComparisonEvent,
248 0, /* Termination */
249 }
250 },
251 {
252 .dest = NI_CtrSource(1),
253 .src = (int[]){
254 NI_PFI(0),
255 NI_PFI(1),
256 NI_PFI(2),
257 NI_PFI(3),
258 NI_PFI(4),
259 NI_PFI(5),
260 NI_PFI(6),
261 NI_PFI(7),
262 NI_PFI(8),
263 NI_PFI(9),
264 TRIGGER_LINE(0),
265 TRIGGER_LINE(1),
266 TRIGGER_LINE(2),
267 TRIGGER_LINE(3),
268 TRIGGER_LINE(4),
269 TRIGGER_LINE(5),
270 TRIGGER_LINE(6),
271 TRIGGER_LINE(7),
272 NI_MasterTimebase,
273 NI_20MHzTimebase,
274 NI_100kHzTimebase,
275 NI_AnalogComparisonEvent,
276 0, /* Termination */
277 }
278 },
279 {
280 .dest = NI_CtrGate(0),
281 .src = (int[]){
282 NI_PFI(0),
283 NI_PFI(1),
284 NI_PFI(2),
285 NI_PFI(3),
286 NI_PFI(4),
287 NI_PFI(5),
288 NI_PFI(6),
289 NI_PFI(7),
290 NI_PFI(8),
291 NI_PFI(9),
292 TRIGGER_LINE(0),
293 TRIGGER_LINE(1),
294 TRIGGER_LINE(2),
295 TRIGGER_LINE(3),
296 TRIGGER_LINE(4),
297 TRIGGER_LINE(5),
298 TRIGGER_LINE(6),
299 NI_CtrInternalOutput(1),
300 NI_AI_StartTrigger,
301 NI_AI_ReferenceTrigger,
302 NI_AnalogComparisonEvent,
303 0, /* Termination */
304 }
305 },
306 {
307 .dest = NI_CtrGate(1),
308 .src = (int[]){
309 NI_PFI(0),
310 NI_PFI(1),
311 NI_PFI(2),
312 NI_PFI(3),
313 NI_PFI(4),
314 NI_PFI(5),
315 NI_PFI(6),
316 NI_PFI(7),
317 NI_PFI(8),
318 NI_PFI(9),
319 TRIGGER_LINE(0),
320 TRIGGER_LINE(1),
321 TRIGGER_LINE(2),
322 TRIGGER_LINE(3),
323 TRIGGER_LINE(4),
324 TRIGGER_LINE(5),
325 TRIGGER_LINE(6),
326 NI_CtrInternalOutput(0),
327 NI_AI_StartTrigger,
328 NI_AI_ReferenceTrigger,
329 NI_AnalogComparisonEvent,
330 0, /* Termination */
331 }
332 },
333 {
334 .dest = NI_CtrOut(0),
335 .src = (int[]){
336 TRIGGER_LINE(0),
337 TRIGGER_LINE(1),
338 TRIGGER_LINE(2),
339 TRIGGER_LINE(3),
340 TRIGGER_LINE(4),
341 TRIGGER_LINE(5),
342 TRIGGER_LINE(6),
343 NI_CtrInternalOutput(0),
344 0, /* Termination */
345 }
346 },
347 {
348 .dest = NI_CtrOut(1),
349 .src = (int[]){
350 NI_CtrInternalOutput(1),
351 0, /* Termination */
352 }
353 },
354 {
355 .dest = NI_AI_SampleClock,
356 .src = (int[]){
357 NI_PFI(0),
358 NI_PFI(1),
359 NI_PFI(2),
360 NI_PFI(3),
361 NI_PFI(4),
362 NI_PFI(5),
363 NI_PFI(6),
364 NI_PFI(7),
365 NI_PFI(8),
366 NI_PFI(9),
367 TRIGGER_LINE(0),
368 TRIGGER_LINE(1),
369 TRIGGER_LINE(2),
370 TRIGGER_LINE(3),
371 TRIGGER_LINE(4),
372 TRIGGER_LINE(5),
373 TRIGGER_LINE(6),
374 NI_CtrInternalOutput(0),
375 NI_AI_SampleClockTimebase,
376 NI_AnalogComparisonEvent,
377 0, /* Termination */
378 }
379 },
380 {
381 .dest = NI_AI_SampleClockTimebase,
382 .src = (int[]){
383 NI_PFI(0),
384 NI_PFI(1),
385 NI_PFI(2),
386 NI_PFI(3),
387 NI_PFI(4),
388 NI_PFI(5),
389 NI_PFI(6),
390 NI_PFI(7),
391 NI_PFI(8),
392 NI_PFI(9),
393 TRIGGER_LINE(0),
394 TRIGGER_LINE(1),
395 TRIGGER_LINE(2),
396 TRIGGER_LINE(3),
397 TRIGGER_LINE(4),
398 TRIGGER_LINE(5),
399 TRIGGER_LINE(6),
400 TRIGGER_LINE(7),
401 NI_MasterTimebase,
402 NI_20MHzTimebase,
403 NI_100kHzTimebase,
404 NI_AnalogComparisonEvent,
405 0, /* Termination */
406 }
407 },
408 {
409 .dest = NI_AI_StartTrigger,
410 .src = (int[]){
411 NI_PFI(0),
412 NI_PFI(1),
413 NI_PFI(2),
414 NI_PFI(3),
415 NI_PFI(4),
416 NI_PFI(5),
417 NI_PFI(6),
418 NI_PFI(7),
419 NI_PFI(8),
420 NI_PFI(9),
421 TRIGGER_LINE(0),
422 TRIGGER_LINE(1),
423 TRIGGER_LINE(2),
424 TRIGGER_LINE(3),
425 TRIGGER_LINE(4),
426 TRIGGER_LINE(5),
427 TRIGGER_LINE(6),
428 NI_CtrInternalOutput(0),
429 NI_AnalogComparisonEvent,
430 0, /* Termination */
431 }
432 },
433 {
434 .dest = NI_AI_ReferenceTrigger,
435 .src = (int[]){
436 NI_PFI(0),
437 NI_PFI(1),
438 NI_PFI(2),
439 NI_PFI(3),
440 NI_PFI(4),
441 NI_PFI(5),
442 NI_PFI(6),
443 NI_PFI(7),
444 NI_PFI(8),
445 NI_PFI(9),
446 TRIGGER_LINE(0),
447 TRIGGER_LINE(1),
448 TRIGGER_LINE(2),
449 TRIGGER_LINE(3),
450 TRIGGER_LINE(4),
451 TRIGGER_LINE(5),
452 TRIGGER_LINE(6),
453 NI_AnalogComparisonEvent,
454 0, /* Termination */
455 }
456 },
457 {
458 .dest = NI_AI_ConvertClock,
459 .src = (int[]){
460 NI_PFI(0),
461 NI_PFI(1),
462 NI_PFI(2),
463 NI_PFI(3),
464 NI_PFI(4),
465 NI_PFI(5),
466 NI_PFI(6),
467 NI_PFI(7),
468 NI_PFI(8),
469 NI_PFI(9),
470 TRIGGER_LINE(0),
471 TRIGGER_LINE(1),
472 TRIGGER_LINE(2),
473 TRIGGER_LINE(3),
474 TRIGGER_LINE(4),
475 TRIGGER_LINE(5),
476 TRIGGER_LINE(6),
477 NI_CtrInternalOutput(0),
478 NI_AI_ConvertClockTimebase,
479 NI_AnalogComparisonEvent,
480 0, /* Termination */
481 }
482 },
483 {
484 .dest = NI_AI_ConvertClockTimebase,
485 .src = (int[]){
486 TRIGGER_LINE(7),
487 NI_AI_SampleClockTimebase,
488 NI_MasterTimebase,
489 NI_20MHzTimebase,
490 0, /* Termination */
491 }
492 },
493 {
494 .dest = NI_AI_PauseTrigger,
495 .src = (int[]){
496 NI_PFI(0),
497 NI_PFI(1),
498 NI_PFI(2),
499 NI_PFI(3),
500 NI_PFI(4),
501 NI_PFI(5),
502 NI_PFI(6),
503 NI_PFI(7),
504 NI_PFI(8),
505 NI_PFI(9),
506 TRIGGER_LINE(0),
507 TRIGGER_LINE(1),
508 TRIGGER_LINE(2),
509 TRIGGER_LINE(3),
510 TRIGGER_LINE(4),
511 TRIGGER_LINE(5),
512 TRIGGER_LINE(6),
513 NI_AnalogComparisonEvent,
514 0, /* Termination */
515 }
516 },
517 {
518 .dest = NI_AI_HoldComplete,
519 .src = (int[]){
520 NI_AI_HoldCompleteEvent,
521 0, /* Termination */
522 }
523 },
524 {
525 .dest = NI_AO_SampleClock,
526 .src = (int[]){
527 NI_PFI(0),
528 NI_PFI(1),
529 NI_PFI(2),
530 NI_PFI(3),
531 NI_PFI(4),
532 NI_PFI(5),
533 NI_PFI(6),
534 NI_PFI(7),
535 NI_PFI(8),
536 NI_PFI(9),
537 TRIGGER_LINE(0),
538 TRIGGER_LINE(1),
539 TRIGGER_LINE(2),
540 TRIGGER_LINE(3),
541 TRIGGER_LINE(4),
542 TRIGGER_LINE(5),
543 TRIGGER_LINE(6),
544 NI_CtrInternalOutput(1),
545 NI_AO_SampleClockTimebase,
546 NI_AnalogComparisonEvent,
547 0, /* Termination */
548 }
549 },
550 {
551 .dest = NI_AO_SampleClockTimebase,
552 .src = (int[]){
553 NI_PFI(0),
554 NI_PFI(1),
555 NI_PFI(2),
556 NI_PFI(3),
557 NI_PFI(4),
558 NI_PFI(5),
559 NI_PFI(6),
560 NI_PFI(7),
561 NI_PFI(8),
562 NI_PFI(9),
563 TRIGGER_LINE(0),
564 TRIGGER_LINE(1),
565 TRIGGER_LINE(2),
566 TRIGGER_LINE(3),
567 TRIGGER_LINE(4),
568 TRIGGER_LINE(5),
569 TRIGGER_LINE(6),
570 TRIGGER_LINE(7),
571 NI_MasterTimebase,
572 NI_20MHzTimebase,
573 NI_100kHzTimebase,
574 NI_AnalogComparisonEvent,
575 0, /* Termination */
576 }
577 },
578 {
579 .dest = NI_AO_StartTrigger,
580 .src = (int[]){
581 NI_PFI(0),
582 NI_PFI(1),
583 NI_PFI(2),
584 NI_PFI(3),
585 NI_PFI(4),
586 NI_PFI(5),
587 NI_PFI(6),
588 NI_PFI(7),
589 NI_PFI(8),
590 NI_PFI(9),
591 TRIGGER_LINE(0),
592 TRIGGER_LINE(1),
593 TRIGGER_LINE(2),
594 TRIGGER_LINE(3),
595 TRIGGER_LINE(4),
596 TRIGGER_LINE(5),
597 TRIGGER_LINE(6),
598 NI_AI_StartTrigger,
599 NI_AnalogComparisonEvent,
600 0, /* Termination */
601 }
602 },
603 {
604 .dest = NI_AO_PauseTrigger,
605 .src = (int[]){
606 NI_PFI(0),
607 NI_PFI(1),
608 NI_PFI(2),
609 NI_PFI(3),
610 NI_PFI(4),
611 NI_PFI(5),
612 NI_PFI(6),
613 NI_PFI(7),
614 NI_PFI(8),
615 NI_PFI(9),
616 TRIGGER_LINE(0),
617 TRIGGER_LINE(1),
618 TRIGGER_LINE(2),
619 TRIGGER_LINE(3),
620 TRIGGER_LINE(4),
621 TRIGGER_LINE(5),
622 TRIGGER_LINE(6),
623 NI_AnalogComparisonEvent,
624 0, /* Termination */
625 }
626 },
627 {
628 .dest = NI_MasterTimebase,
629 .src = (int[]){
630 TRIGGER_LINE(7),
631 NI_20MHzTimebase,
632 0, /* Termination */
633 }
634 },
635 { /* Termination of list */
636 .dest = 0,
637 },
638 },
639};
diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6220.c b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6220.c
new file mode 100644
index 000000000000..74a59222963f
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6220.c
@@ -0,0 +1,1418 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routing/ni_device_routes/pci-6220.c
5 * List of valid routes for specific NI boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21/*
22 * The contents of this file are generated using the tools in
23 * comedi/drivers/ni_routing/tools
24 *
25 * Please use those tools to help maintain the contents of this file.
26 */
27
28#include "../ni_device_routes.h"
29#include "all.h"
30
31struct ni_device_routes ni_pci_6220_device_routes = {
32 .device = "pci-6220",
33 .routes = (struct ni_route_set[]){
34 {
35 .dest = NI_PFI(0),
36 .src = (int[]){
37 TRIGGER_LINE(0),
38 TRIGGER_LINE(1),
39 TRIGGER_LINE(2),
40 TRIGGER_LINE(3),
41 TRIGGER_LINE(4),
42 TRIGGER_LINE(5),
43 TRIGGER_LINE(6),
44 TRIGGER_LINE(7),
45 NI_CtrSource(0),
46 NI_CtrSource(1),
47 NI_CtrGate(0),
48 NI_CtrGate(1),
49 NI_CtrInternalOutput(0),
50 NI_CtrInternalOutput(1),
51 NI_AI_SampleClock,
52 NI_AI_StartTrigger,
53 NI_AI_ReferenceTrigger,
54 NI_AI_ConvertClock,
55 NI_DI_SampleClock,
56 NI_DO_SampleClock,
57 NI_FrequencyOutput,
58 NI_ChangeDetectionEvent,
59 0, /* Termination */
60 }
61 },
62 {
63 .dest = NI_PFI(1),
64 .src = (int[]){
65 TRIGGER_LINE(0),
66 TRIGGER_LINE(1),
67 TRIGGER_LINE(2),
68 TRIGGER_LINE(3),
69 TRIGGER_LINE(4),
70 TRIGGER_LINE(5),
71 TRIGGER_LINE(6),
72 TRIGGER_LINE(7),
73 NI_CtrSource(0),
74 NI_CtrSource(1),
75 NI_CtrGate(0),
76 NI_CtrGate(1),
77 NI_CtrInternalOutput(0),
78 NI_CtrInternalOutput(1),
79 NI_AI_SampleClock,
80 NI_AI_StartTrigger,
81 NI_AI_ReferenceTrigger,
82 NI_AI_ConvertClock,
83 NI_DI_SampleClock,
84 NI_DO_SampleClock,
85 NI_FrequencyOutput,
86 NI_ChangeDetectionEvent,
87 0, /* Termination */
88 }
89 },
90 {
91 .dest = NI_PFI(2),
92 .src = (int[]){
93 TRIGGER_LINE(0),
94 TRIGGER_LINE(1),
95 TRIGGER_LINE(2),
96 TRIGGER_LINE(3),
97 TRIGGER_LINE(4),
98 TRIGGER_LINE(5),
99 TRIGGER_LINE(6),
100 TRIGGER_LINE(7),
101 NI_CtrSource(0),
102 NI_CtrSource(1),
103 NI_CtrGate(0),
104 NI_CtrGate(1),
105 NI_CtrInternalOutput(0),
106 NI_CtrInternalOutput(1),
107 NI_AI_SampleClock,
108 NI_AI_StartTrigger,
109 NI_AI_ReferenceTrigger,
110 NI_AI_ConvertClock,
111 NI_DI_SampleClock,
112 NI_DO_SampleClock,
113 NI_FrequencyOutput,
114 NI_ChangeDetectionEvent,
115 0, /* Termination */
116 }
117 },
118 {
119 .dest = NI_PFI(3),
120 .src = (int[]){
121 TRIGGER_LINE(0),
122 TRIGGER_LINE(1),
123 TRIGGER_LINE(2),
124 TRIGGER_LINE(3),
125 TRIGGER_LINE(4),
126 TRIGGER_LINE(5),
127 TRIGGER_LINE(6),
128 TRIGGER_LINE(7),
129 NI_CtrSource(0),
130 NI_CtrSource(1),
131 NI_CtrGate(0),
132 NI_CtrGate(1),
133 NI_CtrInternalOutput(0),
134 NI_CtrInternalOutput(1),
135 NI_AI_SampleClock,
136 NI_AI_StartTrigger,
137 NI_AI_ReferenceTrigger,
138 NI_AI_ConvertClock,
139 NI_DI_SampleClock,
140 NI_DO_SampleClock,
141 NI_FrequencyOutput,
142 NI_ChangeDetectionEvent,
143 0, /* Termination */
144 }
145 },
146 {
147 .dest = NI_PFI(4),
148 .src = (int[]){
149 TRIGGER_LINE(0),
150 TRIGGER_LINE(1),
151 TRIGGER_LINE(2),
152 TRIGGER_LINE(3),
153 TRIGGER_LINE(4),
154 TRIGGER_LINE(5),
155 TRIGGER_LINE(6),
156 TRIGGER_LINE(7),
157 NI_CtrSource(0),
158 NI_CtrSource(1),
159 NI_CtrGate(0),
160 NI_CtrGate(1),
161 NI_CtrInternalOutput(0),
162 NI_CtrInternalOutput(1),
163 NI_AI_SampleClock,
164 NI_AI_StartTrigger,
165 NI_AI_ReferenceTrigger,
166 NI_AI_ConvertClock,
167 NI_DI_SampleClock,
168 NI_DO_SampleClock,
169 NI_FrequencyOutput,
170 NI_ChangeDetectionEvent,
171 0, /* Termination */
172 }
173 },
174 {
175 .dest = NI_PFI(5),
176 .src = (int[]){
177 TRIGGER_LINE(0),
178 TRIGGER_LINE(1),
179 TRIGGER_LINE(2),
180 TRIGGER_LINE(3),
181 TRIGGER_LINE(4),
182 TRIGGER_LINE(5),
183 TRIGGER_LINE(6),
184 TRIGGER_LINE(7),
185 NI_CtrSource(0),
186 NI_CtrSource(1),
187 NI_CtrGate(0),
188 NI_CtrGate(1),
189 NI_CtrInternalOutput(0),
190 NI_CtrInternalOutput(1),
191 NI_AI_SampleClock,
192 NI_AI_StartTrigger,
193 NI_AI_ReferenceTrigger,
194 NI_AI_ConvertClock,
195 NI_DI_SampleClock,
196 NI_DO_SampleClock,
197 NI_FrequencyOutput,
198 NI_ChangeDetectionEvent,
199 0, /* Termination */
200 }
201 },
202 {
203 .dest = NI_PFI(6),
204 .src = (int[]){
205 TRIGGER_LINE(0),
206 TRIGGER_LINE(1),
207 TRIGGER_LINE(2),
208 TRIGGER_LINE(3),
209 TRIGGER_LINE(4),
210 TRIGGER_LINE(5),
211 TRIGGER_LINE(6),
212 TRIGGER_LINE(7),
213 NI_CtrSource(0),
214 NI_CtrSource(1),
215 NI_CtrGate(0),
216 NI_CtrGate(1),
217 NI_CtrInternalOutput(0),
218 NI_CtrInternalOutput(1),
219 NI_AI_SampleClock,
220 NI_AI_StartTrigger,
221 NI_AI_ReferenceTrigger,
222 NI_AI_ConvertClock,
223 NI_DI_SampleClock,
224 NI_DO_SampleClock,
225 NI_FrequencyOutput,
226 NI_ChangeDetectionEvent,
227 0, /* Termination */
228 }
229 },
230 {
231 .dest = NI_PFI(7),
232 .src = (int[]){
233 TRIGGER_LINE(0),
234 TRIGGER_LINE(1),
235 TRIGGER_LINE(2),
236 TRIGGER_LINE(3),
237 TRIGGER_LINE(4),
238 TRIGGER_LINE(5),
239 TRIGGER_LINE(6),
240 TRIGGER_LINE(7),
241 NI_CtrSource(0),
242 NI_CtrSource(1),
243 NI_CtrGate(0),
244 NI_CtrGate(1),
245 NI_CtrInternalOutput(0),
246 NI_CtrInternalOutput(1),
247 NI_AI_SampleClock,
248 NI_AI_StartTrigger,
249 NI_AI_ReferenceTrigger,
250 NI_AI_ConvertClock,
251 NI_DI_SampleClock,
252 NI_DO_SampleClock,
253 NI_FrequencyOutput,
254 NI_ChangeDetectionEvent,
255 0, /* Termination */
256 }
257 },
258 {
259 .dest = NI_PFI(8),
260 .src = (int[]){
261 TRIGGER_LINE(0),
262 TRIGGER_LINE(1),
263 TRIGGER_LINE(2),
264 TRIGGER_LINE(3),
265 TRIGGER_LINE(4),
266 TRIGGER_LINE(5),
267 TRIGGER_LINE(6),
268 TRIGGER_LINE(7),
269 NI_CtrSource(0),
270 NI_CtrSource(1),
271 NI_CtrGate(0),
272 NI_CtrGate(1),
273 NI_CtrInternalOutput(0),
274 NI_CtrInternalOutput(1),
275 NI_AI_SampleClock,
276 NI_AI_StartTrigger,
277 NI_AI_ReferenceTrigger,
278 NI_AI_ConvertClock,
279 NI_DI_SampleClock,
280 NI_DO_SampleClock,
281 NI_FrequencyOutput,
282 NI_ChangeDetectionEvent,
283 0, /* Termination */
284 }
285 },
286 {
287 .dest = NI_PFI(9),
288 .src = (int[]){
289 TRIGGER_LINE(0),
290 TRIGGER_LINE(1),
291 TRIGGER_LINE(2),
292 TRIGGER_LINE(3),
293 TRIGGER_LINE(4),
294 TRIGGER_LINE(5),
295 TRIGGER_LINE(6),
296 TRIGGER_LINE(7),
297 NI_CtrSource(0),
298 NI_CtrSource(1),
299 NI_CtrGate(0),
300 NI_CtrGate(1),
301 NI_CtrInternalOutput(0),
302 NI_CtrInternalOutput(1),
303 NI_AI_SampleClock,
304 NI_AI_StartTrigger,
305 NI_AI_ReferenceTrigger,
306 NI_AI_ConvertClock,
307 NI_DI_SampleClock,
308 NI_DO_SampleClock,
309 NI_FrequencyOutput,
310 NI_ChangeDetectionEvent,
311 0, /* Termination */
312 }
313 },
314 {
315 .dest = NI_PFI(10),
316 .src = (int[]){
317 TRIGGER_LINE(0),
318 TRIGGER_LINE(1),
319 TRIGGER_LINE(2),
320 TRIGGER_LINE(3),
321 TRIGGER_LINE(4),
322 TRIGGER_LINE(5),
323 TRIGGER_LINE(6),
324 TRIGGER_LINE(7),
325 NI_CtrSource(0),
326 NI_CtrSource(1),
327 NI_CtrGate(0),
328 NI_CtrGate(1),
329 NI_CtrInternalOutput(0),
330 NI_CtrInternalOutput(1),
331 NI_AI_SampleClock,
332 NI_AI_StartTrigger,
333 NI_AI_ReferenceTrigger,
334 NI_AI_ConvertClock,
335 NI_DI_SampleClock,
336 NI_DO_SampleClock,
337 NI_FrequencyOutput,
338 NI_ChangeDetectionEvent,
339 0, /* Termination */
340 }
341 },
342 {
343 .dest = NI_PFI(11),
344 .src = (int[]){
345 TRIGGER_LINE(0),
346 TRIGGER_LINE(1),
347 TRIGGER_LINE(2),
348 TRIGGER_LINE(3),
349 TRIGGER_LINE(4),
350 TRIGGER_LINE(5),
351 TRIGGER_LINE(6),
352 TRIGGER_LINE(7),
353 NI_CtrSource(0),
354 NI_CtrSource(1),
355 NI_CtrGate(0),
356 NI_CtrGate(1),
357 NI_CtrInternalOutput(0),
358 NI_CtrInternalOutput(1),
359 NI_AI_SampleClock,
360 NI_AI_StartTrigger,
361 NI_AI_ReferenceTrigger,
362 NI_AI_ConvertClock,
363 NI_DI_SampleClock,
364 NI_DO_SampleClock,
365 NI_FrequencyOutput,
366 NI_ChangeDetectionEvent,
367 0, /* Termination */
368 }
369 },
370 {
371 .dest = NI_PFI(12),
372 .src = (int[]){
373 TRIGGER_LINE(0),
374 TRIGGER_LINE(1),
375 TRIGGER_LINE(2),
376 TRIGGER_LINE(3),
377 TRIGGER_LINE(4),
378 TRIGGER_LINE(5),
379 TRIGGER_LINE(6),
380 TRIGGER_LINE(7),
381 NI_CtrSource(0),
382 NI_CtrSource(1),
383 NI_CtrGate(0),
384 NI_CtrGate(1),
385 NI_CtrInternalOutput(0),
386 NI_CtrInternalOutput(1),
387 NI_AI_SampleClock,
388 NI_AI_StartTrigger,
389 NI_AI_ReferenceTrigger,
390 NI_AI_ConvertClock,
391 NI_DI_SampleClock,
392 NI_DO_SampleClock,
393 NI_FrequencyOutput,
394 NI_ChangeDetectionEvent,
395 0, /* Termination */
396 }
397 },
398 {
399 .dest = NI_PFI(13),
400 .src = (int[]){
401 TRIGGER_LINE(0),
402 TRIGGER_LINE(1),
403 TRIGGER_LINE(2),
404 TRIGGER_LINE(3),
405 TRIGGER_LINE(4),
406 TRIGGER_LINE(5),
407 TRIGGER_LINE(6),
408 TRIGGER_LINE(7),
409 NI_CtrSource(0),
410 NI_CtrSource(1),
411 NI_CtrGate(0),
412 NI_CtrGate(1),
413 NI_CtrInternalOutput(0),
414 NI_CtrInternalOutput(1),
415 NI_AI_SampleClock,
416 NI_AI_StartTrigger,
417 NI_AI_ReferenceTrigger,
418 NI_AI_ConvertClock,
419 NI_DI_SampleClock,
420 NI_DO_SampleClock,
421 NI_FrequencyOutput,
422 NI_ChangeDetectionEvent,
423 0, /* Termination */
424 }
425 },
426 {
427 .dest = NI_PFI(14),
428 .src = (int[]){
429 TRIGGER_LINE(0),
430 TRIGGER_LINE(1),
431 TRIGGER_LINE(2),
432 TRIGGER_LINE(3),
433 TRIGGER_LINE(4),
434 TRIGGER_LINE(5),
435 TRIGGER_LINE(6),
436 TRIGGER_LINE(7),
437 NI_CtrSource(0),
438 NI_CtrSource(1),
439 NI_CtrGate(0),
440 NI_CtrGate(1),
441 NI_CtrInternalOutput(0),
442 NI_CtrInternalOutput(1),
443 NI_AI_SampleClock,
444 NI_AI_StartTrigger,
445 NI_AI_ReferenceTrigger,
446 NI_AI_ConvertClock,
447 NI_DI_SampleClock,
448 NI_DO_SampleClock,
449 NI_FrequencyOutput,
450 NI_ChangeDetectionEvent,
451 0, /* Termination */
452 }
453 },
454 {
455 .dest = NI_PFI(15),
456 .src = (int[]){
457 TRIGGER_LINE(0),
458 TRIGGER_LINE(1),
459 TRIGGER_LINE(2),
460 TRIGGER_LINE(3),
461 TRIGGER_LINE(4),
462 TRIGGER_LINE(5),
463 TRIGGER_LINE(6),
464 TRIGGER_LINE(7),
465 NI_CtrSource(0),
466 NI_CtrSource(1),
467 NI_CtrGate(0),
468 NI_CtrGate(1),
469 NI_CtrInternalOutput(0),
470 NI_CtrInternalOutput(1),
471 NI_AI_SampleClock,
472 NI_AI_StartTrigger,
473 NI_AI_ReferenceTrigger,
474 NI_AI_ConvertClock,
475 NI_DI_SampleClock,
476 NI_DO_SampleClock,
477 NI_FrequencyOutput,
478 NI_ChangeDetectionEvent,
479 0, /* Termination */
480 }
481 },
482 {
483 .dest = TRIGGER_LINE(0),
484 .src = (int[]){
485 NI_PFI(0),
486 NI_PFI(1),
487 NI_PFI(2),
488 NI_PFI(3),
489 NI_PFI(4),
490 NI_PFI(5),
491 NI_CtrSource(0),
492 NI_CtrSource(1),
493 NI_CtrGate(0),
494 NI_CtrGate(1),
495 NI_CtrInternalOutput(0),
496 NI_CtrInternalOutput(1),
497 NI_AI_SampleClock,
498 NI_AI_StartTrigger,
499 NI_AI_ReferenceTrigger,
500 NI_AI_ConvertClock,
501 NI_AI_PauseTrigger,
502 NI_10MHzRefClock,
503 NI_FrequencyOutput,
504 NI_ChangeDetectionEvent,
505 0, /* Termination */
506 }
507 },
508 {
509 .dest = TRIGGER_LINE(1),
510 .src = (int[]){
511 NI_PFI(0),
512 NI_PFI(1),
513 NI_PFI(2),
514 NI_PFI(3),
515 NI_PFI(4),
516 NI_PFI(5),
517 NI_CtrSource(0),
518 NI_CtrSource(1),
519 NI_CtrGate(0),
520 NI_CtrGate(1),
521 NI_CtrInternalOutput(0),
522 NI_CtrInternalOutput(1),
523 NI_AI_SampleClock,
524 NI_AI_StartTrigger,
525 NI_AI_ReferenceTrigger,
526 NI_AI_ConvertClock,
527 NI_AI_PauseTrigger,
528 NI_10MHzRefClock,
529 NI_FrequencyOutput,
530 NI_ChangeDetectionEvent,
531 0, /* Termination */
532 }
533 },
534 {
535 .dest = TRIGGER_LINE(2),
536 .src = (int[]){
537 NI_PFI(0),
538 NI_PFI(1),
539 NI_PFI(2),
540 NI_PFI(3),
541 NI_PFI(4),
542 NI_PFI(5),
543 NI_CtrSource(0),
544 NI_CtrSource(1),
545 NI_CtrGate(0),
546 NI_CtrGate(1),
547 NI_CtrInternalOutput(0),
548 NI_CtrInternalOutput(1),
549 NI_AI_SampleClock,
550 NI_AI_StartTrigger,
551 NI_AI_ReferenceTrigger,
552 NI_AI_ConvertClock,
553 NI_AI_PauseTrigger,
554 NI_10MHzRefClock,
555 NI_FrequencyOutput,
556 NI_ChangeDetectionEvent,
557 0, /* Termination */
558 }
559 },
560 {
561 .dest = TRIGGER_LINE(3),
562 .src = (int[]){
563 NI_PFI(0),
564 NI_PFI(1),
565 NI_PFI(2),
566 NI_PFI(3),
567 NI_PFI(4),
568 NI_PFI(5),
569 NI_CtrSource(0),
570 NI_CtrSource(1),
571 NI_CtrGate(0),
572 NI_CtrGate(1),
573 NI_CtrInternalOutput(0),
574 NI_CtrInternalOutput(1),
575 NI_AI_SampleClock,
576 NI_AI_StartTrigger,
577 NI_AI_ReferenceTrigger,
578 NI_AI_ConvertClock,
579 NI_AI_PauseTrigger,
580 NI_10MHzRefClock,
581 NI_FrequencyOutput,
582 NI_ChangeDetectionEvent,
583 0, /* Termination */
584 }
585 },
586 {
587 .dest = TRIGGER_LINE(4),
588 .src = (int[]){
589 NI_PFI(0),
590 NI_PFI(1),
591 NI_PFI(2),
592 NI_PFI(3),
593 NI_PFI(4),
594 NI_PFI(5),
595 NI_CtrSource(0),
596 NI_CtrSource(1),
597 NI_CtrGate(0),
598 NI_CtrGate(1),
599 NI_CtrInternalOutput(0),
600 NI_CtrInternalOutput(1),
601 NI_AI_SampleClock,
602 NI_AI_StartTrigger,
603 NI_AI_ReferenceTrigger,
604 NI_AI_ConvertClock,
605 NI_AI_PauseTrigger,
606 NI_10MHzRefClock,
607 NI_FrequencyOutput,
608 NI_ChangeDetectionEvent,
609 0, /* Termination */
610 }
611 },
612 {
613 .dest = TRIGGER_LINE(5),
614 .src = (int[]){
615 NI_PFI(0),
616 NI_PFI(1),
617 NI_PFI(2),
618 NI_PFI(3),
619 NI_PFI(4),
620 NI_PFI(5),
621 NI_CtrSource(0),
622 NI_CtrSource(1),
623 NI_CtrGate(0),
624 NI_CtrGate(1),
625 NI_CtrInternalOutput(0),
626 NI_CtrInternalOutput(1),
627 NI_AI_SampleClock,
628 NI_AI_StartTrigger,
629 NI_AI_ReferenceTrigger,
630 NI_AI_ConvertClock,
631 NI_AI_PauseTrigger,
632 NI_10MHzRefClock,
633 NI_FrequencyOutput,
634 NI_ChangeDetectionEvent,
635 0, /* Termination */
636 }
637 },
638 {
639 .dest = TRIGGER_LINE(6),
640 .src = (int[]){
641 NI_PFI(0),
642 NI_PFI(1),
643 NI_PFI(2),
644 NI_PFI(3),
645 NI_PFI(4),
646 NI_PFI(5),
647 NI_CtrSource(0),
648 NI_CtrSource(1),
649 NI_CtrGate(0),
650 NI_CtrGate(1),
651 NI_CtrInternalOutput(0),
652 NI_CtrInternalOutput(1),
653 NI_AI_SampleClock,
654 NI_AI_StartTrigger,
655 NI_AI_ReferenceTrigger,
656 NI_AI_ConvertClock,
657 NI_AI_PauseTrigger,
658 NI_10MHzRefClock,
659 NI_FrequencyOutput,
660 NI_ChangeDetectionEvent,
661 0, /* Termination */
662 }
663 },
664 {
665 .dest = TRIGGER_LINE(7),
666 .src = (int[]){
667 NI_PFI(0),
668 NI_PFI(1),
669 NI_PFI(2),
670 NI_PFI(3),
671 NI_PFI(4),
672 NI_PFI(5),
673 NI_CtrSource(0),
674 NI_CtrSource(1),
675 NI_CtrGate(0),
676 NI_CtrGate(1),
677 NI_CtrInternalOutput(0),
678 NI_CtrInternalOutput(1),
679 NI_AI_SampleClock,
680 NI_AI_StartTrigger,
681 NI_AI_ReferenceTrigger,
682 NI_AI_ConvertClock,
683 NI_AI_PauseTrigger,
684 NI_10MHzRefClock,
685 NI_FrequencyOutput,
686 NI_ChangeDetectionEvent,
687 0, /* Termination */
688 }
689 },
690 {
691 .dest = NI_CtrSource(0),
692 .src = (int[]){
693 NI_PFI(0),
694 NI_PFI(1),
695 NI_PFI(2),
696 NI_PFI(3),
697 NI_PFI(4),
698 NI_PFI(5),
699 NI_PFI(6),
700 NI_PFI(7),
701 NI_PFI(8),
702 NI_PFI(9),
703 NI_PFI(10),
704 NI_PFI(11),
705 NI_PFI(12),
706 NI_PFI(13),
707 NI_PFI(14),
708 NI_PFI(15),
709 TRIGGER_LINE(0),
710 TRIGGER_LINE(1),
711 TRIGGER_LINE(2),
712 TRIGGER_LINE(3),
713 TRIGGER_LINE(4),
714 TRIGGER_LINE(5),
715 TRIGGER_LINE(6),
716 TRIGGER_LINE(7),
717 NI_CtrGate(1),
718 NI_20MHzTimebase,
719 NI_80MHzTimebase,
720 NI_100kHzTimebase,
721 0, /* Termination */
722 }
723 },
724 {
725 .dest = NI_CtrSource(1),
726 .src = (int[]){
727 NI_PFI(0),
728 NI_PFI(1),
729 NI_PFI(2),
730 NI_PFI(3),
731 NI_PFI(4),
732 NI_PFI(5),
733 NI_PFI(6),
734 NI_PFI(7),
735 NI_PFI(8),
736 NI_PFI(9),
737 NI_PFI(10),
738 NI_PFI(11),
739 NI_PFI(12),
740 NI_PFI(13),
741 NI_PFI(14),
742 NI_PFI(15),
743 TRIGGER_LINE(0),
744 TRIGGER_LINE(1),
745 TRIGGER_LINE(2),
746 TRIGGER_LINE(3),
747 TRIGGER_LINE(4),
748 TRIGGER_LINE(5),
749 TRIGGER_LINE(6),
750 TRIGGER_LINE(7),
751 NI_CtrGate(0),
752 NI_20MHzTimebase,
753 NI_80MHzTimebase,
754 NI_100kHzTimebase,
755 0, /* Termination */
756 }
757 },
758 {
759 .dest = NI_CtrGate(0),
760 .src = (int[]){
761 NI_PFI(0),
762 NI_PFI(1),
763 NI_PFI(2),
764 NI_PFI(3),
765 NI_PFI(4),
766 NI_PFI(5),
767 NI_PFI(6),
768 NI_PFI(7),
769 NI_PFI(8),
770 NI_PFI(9),
771 NI_PFI(10),
772 NI_PFI(11),
773 NI_PFI(12),
774 NI_PFI(13),
775 NI_PFI(14),
776 NI_PFI(15),
777 TRIGGER_LINE(0),
778 TRIGGER_LINE(1),
779 TRIGGER_LINE(2),
780 TRIGGER_LINE(3),
781 TRIGGER_LINE(4),
782 TRIGGER_LINE(5),
783 TRIGGER_LINE(6),
784 TRIGGER_LINE(7),
785 NI_CtrSource(1),
786 NI_CtrInternalOutput(1),
787 NI_AI_StartTrigger,
788 NI_AI_ReferenceTrigger,
789 0, /* Termination */
790 }
791 },
792 {
793 .dest = NI_CtrGate(1),
794 .src = (int[]){
795 NI_PFI(0),
796 NI_PFI(1),
797 NI_PFI(2),
798 NI_PFI(3),
799 NI_PFI(4),
800 NI_PFI(5),
801 NI_PFI(6),
802 NI_PFI(7),
803 NI_PFI(8),
804 NI_PFI(9),
805 NI_PFI(10),
806 NI_PFI(11),
807 NI_PFI(12),
808 NI_PFI(13),
809 NI_PFI(14),
810 NI_PFI(15),
811 TRIGGER_LINE(0),
812 TRIGGER_LINE(1),
813 TRIGGER_LINE(2),
814 TRIGGER_LINE(3),
815 TRIGGER_LINE(4),
816 TRIGGER_LINE(5),
817 TRIGGER_LINE(6),
818 TRIGGER_LINE(7),
819 NI_CtrSource(0),
820 NI_CtrInternalOutput(0),
821 NI_AI_StartTrigger,
822 NI_AI_ReferenceTrigger,
823 0, /* Termination */
824 }
825 },
826 {
827 .dest = NI_CtrAux(0),
828 .src = (int[]){
829 NI_PFI(0),
830 NI_PFI(1),
831 NI_PFI(2),
832 NI_PFI(3),
833 NI_PFI(4),
834 NI_PFI(5),
835 NI_PFI(6),
836 NI_PFI(7),
837 NI_PFI(8),
838 NI_PFI(9),
839 NI_PFI(10),
840 NI_PFI(11),
841 NI_PFI(12),
842 NI_PFI(13),
843 NI_PFI(14),
844 NI_PFI(15),
845 TRIGGER_LINE(0),
846 TRIGGER_LINE(1),
847 TRIGGER_LINE(2),
848 TRIGGER_LINE(3),
849 TRIGGER_LINE(4),
850 TRIGGER_LINE(5),
851 TRIGGER_LINE(6),
852 TRIGGER_LINE(7),
853 NI_CtrSource(1),
854 NI_CtrGate(0),
855 NI_CtrGate(1),
856 NI_CtrInternalOutput(1),
857 NI_AI_StartTrigger,
858 NI_AI_ReferenceTrigger,
859 0, /* Termination */
860 }
861 },
862 {
863 .dest = NI_CtrAux(1),
864 .src = (int[]){
865 NI_PFI(0),
866 NI_PFI(1),
867 NI_PFI(2),
868 NI_PFI(3),
869 NI_PFI(4),
870 NI_PFI(5),
871 NI_PFI(6),
872 NI_PFI(7),
873 NI_PFI(8),
874 NI_PFI(9),
875 NI_PFI(10),
876 NI_PFI(11),
877 NI_PFI(12),
878 NI_PFI(13),
879 NI_PFI(14),
880 NI_PFI(15),
881 TRIGGER_LINE(0),
882 TRIGGER_LINE(1),
883 TRIGGER_LINE(2),
884 TRIGGER_LINE(3),
885 TRIGGER_LINE(4),
886 TRIGGER_LINE(5),
887 TRIGGER_LINE(6),
888 TRIGGER_LINE(7),
889 NI_CtrSource(0),
890 NI_CtrGate(0),
891 NI_CtrGate(1),
892 NI_CtrInternalOutput(0),
893 NI_AI_StartTrigger,
894 NI_AI_ReferenceTrigger,
895 0, /* Termination */
896 }
897 },
898 {
899 .dest = NI_CtrA(0),
900 .src = (int[]){
901 NI_PFI(0),
902 NI_PFI(1),
903 NI_PFI(2),
904 NI_PFI(3),
905 NI_PFI(4),
906 NI_PFI(5),
907 NI_PFI(6),
908 NI_PFI(7),
909 NI_PFI(8),
910 NI_PFI(9),
911 NI_PFI(10),
912 NI_PFI(11),
913 NI_PFI(12),
914 NI_PFI(13),
915 NI_PFI(14),
916 NI_PFI(15),
917 TRIGGER_LINE(0),
918 TRIGGER_LINE(1),
919 TRIGGER_LINE(2),
920 TRIGGER_LINE(3),
921 TRIGGER_LINE(4),
922 TRIGGER_LINE(5),
923 TRIGGER_LINE(6),
924 TRIGGER_LINE(7),
925 0, /* Termination */
926 }
927 },
928 {
929 .dest = NI_CtrA(1),
930 .src = (int[]){
931 NI_PFI(0),
932 NI_PFI(1),
933 NI_PFI(2),
934 NI_PFI(3),
935 NI_PFI(4),
936 NI_PFI(5),
937 NI_PFI(6),
938 NI_PFI(7),
939 NI_PFI(8),
940 NI_PFI(9),
941 NI_PFI(10),
942 NI_PFI(11),
943 NI_PFI(12),
944 NI_PFI(13),
945 NI_PFI(14),
946 NI_PFI(15),
947 TRIGGER_LINE(0),
948 TRIGGER_LINE(1),
949 TRIGGER_LINE(2),
950 TRIGGER_LINE(3),
951 TRIGGER_LINE(4),
952 TRIGGER_LINE(5),
953 TRIGGER_LINE(6),
954 TRIGGER_LINE(7),
955 0, /* Termination */
956 }
957 },
958 {
959 .dest = NI_CtrB(0),
960 .src = (int[]){
961 NI_PFI(0),
962 NI_PFI(1),
963 NI_PFI(2),
964 NI_PFI(3),
965 NI_PFI(4),
966 NI_PFI(5),
967 NI_PFI(6),
968 NI_PFI(7),
969 NI_PFI(8),
970 NI_PFI(9),
971 NI_PFI(10),
972 NI_PFI(11),
973 NI_PFI(12),
974 NI_PFI(13),
975 NI_PFI(14),
976 NI_PFI(15),
977 TRIGGER_LINE(0),
978 TRIGGER_LINE(1),
979 TRIGGER_LINE(2),
980 TRIGGER_LINE(3),
981 TRIGGER_LINE(4),
982 TRIGGER_LINE(5),
983 TRIGGER_LINE(6),
984 TRIGGER_LINE(7),
985 0, /* Termination */
986 }
987 },
988 {
989 .dest = NI_CtrB(1),
990 .src = (int[]){
991 NI_PFI(0),
992 NI_PFI(1),
993 NI_PFI(2),
994 NI_PFI(3),
995 NI_PFI(4),
996 NI_PFI(5),
997 NI_PFI(6),
998 NI_PFI(7),
999 NI_PFI(8),
1000 NI_PFI(9),
1001 NI_PFI(10),
1002 NI_PFI(11),
1003 NI_PFI(12),
1004 NI_PFI(13),
1005 NI_PFI(14),
1006 NI_PFI(15),
1007 TRIGGER_LINE(0),
1008 TRIGGER_LINE(1),
1009 TRIGGER_LINE(2),
1010 TRIGGER_LINE(3),
1011 TRIGGER_LINE(4),
1012 TRIGGER_LINE(5),
1013 TRIGGER_LINE(6),
1014 TRIGGER_LINE(7),
1015 0, /* Termination */
1016 }
1017 },
1018 {
1019 .dest = NI_CtrZ(0),
1020 .src = (int[]){
1021 NI_PFI(0),
1022 NI_PFI(1),
1023 NI_PFI(2),
1024 NI_PFI(3),
1025 NI_PFI(4),
1026 NI_PFI(5),
1027 NI_PFI(6),
1028 NI_PFI(7),
1029 NI_PFI(8),
1030 NI_PFI(9),
1031 NI_PFI(10),
1032 NI_PFI(11),
1033 NI_PFI(12),
1034 NI_PFI(13),
1035 NI_PFI(14),
1036 NI_PFI(15),
1037 TRIGGER_LINE(0),
1038 TRIGGER_LINE(1),
1039 TRIGGER_LINE(2),
1040 TRIGGER_LINE(3),
1041 TRIGGER_LINE(4),
1042 TRIGGER_LINE(5),
1043 TRIGGER_LINE(6),
1044 TRIGGER_LINE(7),
1045 0, /* Termination */
1046 }
1047 },
1048 {
1049 .dest = NI_CtrZ(1),
1050 .src = (int[]){
1051 NI_PFI(0),
1052 NI_PFI(1),
1053 NI_PFI(2),
1054 NI_PFI(3),
1055 NI_PFI(4),
1056 NI_PFI(5),
1057 NI_PFI(6),
1058 NI_PFI(7),
1059 NI_PFI(8),
1060 NI_PFI(9),
1061 NI_PFI(10),
1062 NI_PFI(11),
1063 NI_PFI(12),
1064 NI_PFI(13),
1065 NI_PFI(14),
1066 NI_PFI(15),
1067 TRIGGER_LINE(0),
1068 TRIGGER_LINE(1),
1069 TRIGGER_LINE(2),
1070 TRIGGER_LINE(3),
1071 TRIGGER_LINE(4),
1072 TRIGGER_LINE(5),
1073 TRIGGER_LINE(6),
1074 TRIGGER_LINE(7),
1075 0, /* Termination */
1076 }
1077 },
1078 {
1079 .dest = NI_CtrArmStartTrigger(0),
1080 .src = (int[]){
1081 NI_PFI(0),
1082 NI_PFI(1),
1083 NI_PFI(2),
1084 NI_PFI(3),
1085 NI_PFI(4),
1086 NI_PFI(5),
1087 NI_PFI(6),
1088 NI_PFI(7),
1089 NI_PFI(8),
1090 NI_PFI(9),
1091 NI_PFI(10),
1092 NI_PFI(11),
1093 NI_PFI(12),
1094 NI_PFI(13),
1095 NI_PFI(14),
1096 NI_PFI(15),
1097 TRIGGER_LINE(0),
1098 TRIGGER_LINE(1),
1099 TRIGGER_LINE(2),
1100 TRIGGER_LINE(3),
1101 TRIGGER_LINE(4),
1102 TRIGGER_LINE(5),
1103 TRIGGER_LINE(6),
1104 TRIGGER_LINE(7),
1105 NI_CtrInternalOutput(1),
1106 NI_AI_StartTrigger,
1107 NI_AI_ReferenceTrigger,
1108 0, /* Termination */
1109 }
1110 },
1111 {
1112 .dest = NI_CtrArmStartTrigger(1),
1113 .src = (int[]){
1114 NI_PFI(0),
1115 NI_PFI(1),
1116 NI_PFI(2),
1117 NI_PFI(3),
1118 NI_PFI(4),
1119 NI_PFI(5),
1120 NI_PFI(6),
1121 NI_PFI(7),
1122 NI_PFI(8),
1123 NI_PFI(9),
1124 NI_PFI(10),
1125 NI_PFI(11),
1126 NI_PFI(12),
1127 NI_PFI(13),
1128 NI_PFI(14),
1129 NI_PFI(15),
1130 TRIGGER_LINE(0),
1131 TRIGGER_LINE(1),
1132 TRIGGER_LINE(2),
1133 TRIGGER_LINE(3),
1134 TRIGGER_LINE(4),
1135 TRIGGER_LINE(5),
1136 TRIGGER_LINE(6),
1137 TRIGGER_LINE(7),
1138 NI_CtrInternalOutput(0),
1139 NI_AI_StartTrigger,
1140 NI_AI_ReferenceTrigger,
1141 0, /* Termination */
1142 }
1143 },
1144 {
1145 .dest = NI_AI_SampleClock,
1146 .src = (int[]){
1147 NI_PFI(0),
1148 NI_PFI(1),
1149 NI_PFI(2),
1150 NI_PFI(3),
1151 NI_PFI(4),
1152 NI_PFI(5),
1153 NI_PFI(6),
1154 NI_PFI(7),
1155 NI_PFI(8),
1156 NI_PFI(9),
1157 NI_PFI(10),
1158 NI_PFI(11),
1159 NI_PFI(12),
1160 NI_PFI(13),
1161 NI_PFI(14),
1162 NI_PFI(15),
1163 TRIGGER_LINE(0),
1164 TRIGGER_LINE(1),
1165 TRIGGER_LINE(2),
1166 TRIGGER_LINE(3),
1167 TRIGGER_LINE(4),
1168 TRIGGER_LINE(5),
1169 TRIGGER_LINE(6),
1170 TRIGGER_LINE(7),
1171 NI_CtrInternalOutput(0),
1172 NI_CtrInternalOutput(1),
1173 NI_AI_SampleClockTimebase,
1174 0, /* Termination */
1175 }
1176 },
1177 {
1178 .dest = NI_AI_SampleClockTimebase,
1179 .src = (int[]){
1180 NI_PFI(0),
1181 NI_PFI(1),
1182 NI_PFI(2),
1183 NI_PFI(3),
1184 NI_PFI(4),
1185 NI_PFI(5),
1186 NI_PFI(6),
1187 NI_PFI(7),
1188 NI_PFI(8),
1189 NI_PFI(9),
1190 NI_PFI(10),
1191 NI_PFI(11),
1192 NI_PFI(12),
1193 NI_PFI(13),
1194 NI_PFI(14),
1195 NI_PFI(15),
1196 TRIGGER_LINE(0),
1197 TRIGGER_LINE(1),
1198 TRIGGER_LINE(2),
1199 TRIGGER_LINE(3),
1200 TRIGGER_LINE(4),
1201 TRIGGER_LINE(5),
1202 TRIGGER_LINE(6),
1203 TRIGGER_LINE(7),
1204 NI_20MHzTimebase,
1205 NI_100kHzTimebase,
1206 0, /* Termination */
1207 }
1208 },
1209 {
1210 .dest = NI_AI_StartTrigger,
1211 .src = (int[]){
1212 NI_PFI(0),
1213 NI_PFI(1),
1214 NI_PFI(2),
1215 NI_PFI(3),
1216 NI_PFI(4),
1217 NI_PFI(5),
1218 NI_PFI(6),
1219 NI_PFI(7),
1220 NI_PFI(8),
1221 NI_PFI(9),
1222 NI_PFI(10),
1223 NI_PFI(11),
1224 NI_PFI(12),
1225 NI_PFI(13),
1226 NI_PFI(14),
1227 NI_PFI(15),
1228 TRIGGER_LINE(0),
1229 TRIGGER_LINE(1),
1230 TRIGGER_LINE(2),
1231 TRIGGER_LINE(3),
1232 TRIGGER_LINE(4),
1233 TRIGGER_LINE(5),
1234 TRIGGER_LINE(6),
1235 TRIGGER_LINE(7),
1236 NI_CtrInternalOutput(0),
1237 NI_CtrInternalOutput(1),
1238 0, /* Termination */
1239 }
1240 },
1241 {
1242 .dest = NI_AI_ReferenceTrigger,
1243 .src = (int[]){
1244 NI_PFI(0),
1245 NI_PFI(1),
1246 NI_PFI(2),
1247 NI_PFI(3),
1248 NI_PFI(4),
1249 NI_PFI(5),
1250 NI_PFI(6),
1251 NI_PFI(7),
1252 NI_PFI(8),
1253 NI_PFI(9),
1254 NI_PFI(10),
1255 NI_PFI(11),
1256 NI_PFI(12),
1257 NI_PFI(13),
1258 NI_PFI(14),
1259 NI_PFI(15),
1260 TRIGGER_LINE(0),
1261 TRIGGER_LINE(1),
1262 TRIGGER_LINE(2),
1263 TRIGGER_LINE(3),
1264 TRIGGER_LINE(4),
1265 TRIGGER_LINE(5),
1266 TRIGGER_LINE(6),
1267 TRIGGER_LINE(7),
1268 0, /* Termination */
1269 }
1270 },
1271 {
1272 .dest = NI_AI_ConvertClock,
1273 .src = (int[]){
1274 NI_PFI(0),
1275 NI_PFI(1),
1276 NI_PFI(2),
1277 NI_PFI(3),
1278 NI_PFI(4),
1279 NI_PFI(5),
1280 NI_PFI(6),
1281 NI_PFI(7),
1282 NI_PFI(8),
1283 NI_PFI(9),
1284 NI_PFI(10),
1285 NI_PFI(11),
1286 NI_PFI(12),
1287 NI_PFI(13),
1288 NI_PFI(14),
1289 NI_PFI(15),
1290 TRIGGER_LINE(0),
1291 TRIGGER_LINE(1),
1292 TRIGGER_LINE(2),
1293 TRIGGER_LINE(3),
1294 TRIGGER_LINE(4),
1295 TRIGGER_LINE(5),
1296 TRIGGER_LINE(6),
1297 TRIGGER_LINE(7),
1298 NI_CtrInternalOutput(0),
1299 NI_CtrInternalOutput(1),
1300 NI_AI_ConvertClockTimebase,
1301 0, /* Termination */
1302 }
1303 },
1304 {
1305 .dest = NI_AI_ConvertClockTimebase,
1306 .src = (int[]){
1307 NI_AI_SampleClockTimebase,
1308 NI_20MHzTimebase,
1309 0, /* Termination */
1310 }
1311 },
1312 {
1313 .dest = NI_AI_PauseTrigger,
1314 .src = (int[]){
1315 NI_PFI(0),
1316 NI_PFI(1),
1317 NI_PFI(2),
1318 NI_PFI(3),
1319 NI_PFI(4),
1320 NI_PFI(5),
1321 NI_PFI(6),
1322 NI_PFI(7),
1323 NI_PFI(8),
1324 NI_PFI(9),
1325 NI_PFI(10),
1326 NI_PFI(11),
1327 NI_PFI(12),
1328 NI_PFI(13),
1329 NI_PFI(14),
1330 NI_PFI(15),
1331 TRIGGER_LINE(0),
1332 TRIGGER_LINE(1),
1333 TRIGGER_LINE(2),
1334 TRIGGER_LINE(3),
1335 TRIGGER_LINE(4),
1336 TRIGGER_LINE(5),
1337 TRIGGER_LINE(6),
1338 TRIGGER_LINE(7),
1339 0, /* Termination */
1340 }
1341 },
1342 {
1343 .dest = NI_DI_SampleClock,
1344 .src = (int[]){
1345 NI_PFI(0),
1346 NI_PFI(1),
1347 NI_PFI(2),
1348 NI_PFI(3),
1349 NI_PFI(4),
1350 NI_PFI(5),
1351 NI_PFI(6),
1352 NI_PFI(7),
1353 NI_PFI(8),
1354 NI_PFI(9),
1355 NI_PFI(10),
1356 NI_PFI(11),
1357 NI_PFI(12),
1358 NI_PFI(13),
1359 NI_PFI(14),
1360 NI_PFI(15),
1361 TRIGGER_LINE(0),
1362 TRIGGER_LINE(1),
1363 TRIGGER_LINE(2),
1364 TRIGGER_LINE(3),
1365 TRIGGER_LINE(4),
1366 TRIGGER_LINE(5),
1367 TRIGGER_LINE(6),
1368 TRIGGER_LINE(7),
1369 NI_CtrInternalOutput(0),
1370 NI_CtrInternalOutput(1),
1371 NI_AI_SampleClock,
1372 NI_AI_ConvertClock,
1373 NI_FrequencyOutput,
1374 NI_ChangeDetectionEvent,
1375 0, /* Termination */
1376 }
1377 },
1378 {
1379 .dest = NI_DO_SampleClock,
1380 .src = (int[]){
1381 NI_PFI(0),
1382 NI_PFI(1),
1383 NI_PFI(2),
1384 NI_PFI(3),
1385 NI_PFI(4),
1386 NI_PFI(5),
1387 NI_PFI(6),
1388 NI_PFI(7),
1389 NI_PFI(8),
1390 NI_PFI(9),
1391 NI_PFI(10),
1392 NI_PFI(11),
1393 NI_PFI(12),
1394 NI_PFI(13),
1395 NI_PFI(14),
1396 NI_PFI(15),
1397 TRIGGER_LINE(0),
1398 TRIGGER_LINE(1),
1399 TRIGGER_LINE(2),
1400 TRIGGER_LINE(3),
1401 TRIGGER_LINE(4),
1402 TRIGGER_LINE(5),
1403 TRIGGER_LINE(6),
1404 TRIGGER_LINE(7),
1405 NI_CtrInternalOutput(0),
1406 NI_CtrInternalOutput(1),
1407 NI_AI_SampleClock,
1408 NI_AI_ConvertClock,
1409 NI_FrequencyOutput,
1410 NI_ChangeDetectionEvent,
1411 0, /* Termination */
1412 }
1413 },
1414 { /* Termination of list */
1415 .dest = 0,
1416 },
1417 },
1418};
diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6221.c b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6221.c
new file mode 100644
index 000000000000..44dcbabf2a99
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6221.c
@@ -0,0 +1,1602 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routing/ni_device_routes/pci-6221.c
5 * List of valid routes for specific NI boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21/*
22 * The contents of this file are generated using the tools in
23 * comedi/drivers/ni_routing/tools
24 *
25 * Please use those tools to help maintain the contents of this file.
26 */
27
28#include "../ni_device_routes.h"
29#include "all.h"
30
31struct ni_device_routes ni_pci_6221_device_routes = {
32 .device = "pci-6221",
33 .routes = (struct ni_route_set[]){
34 {
35 .dest = NI_PFI(0),
36 .src = (int[]){
37 TRIGGER_LINE(0),
38 TRIGGER_LINE(1),
39 TRIGGER_LINE(2),
40 TRIGGER_LINE(3),
41 TRIGGER_LINE(4),
42 TRIGGER_LINE(5),
43 TRIGGER_LINE(6),
44 TRIGGER_LINE(7),
45 NI_CtrSource(0),
46 NI_CtrSource(1),
47 NI_CtrGate(0),
48 NI_CtrGate(1),
49 NI_CtrInternalOutput(0),
50 NI_CtrInternalOutput(1),
51 NI_AI_SampleClock,
52 NI_AI_StartTrigger,
53 NI_AI_ReferenceTrigger,
54 NI_AI_ConvertClock,
55 NI_AO_SampleClock,
56 NI_AO_StartTrigger,
57 NI_DI_SampleClock,
58 NI_DO_SampleClock,
59 NI_FrequencyOutput,
60 NI_ChangeDetectionEvent,
61 0, /* Termination */
62 }
63 },
64 {
65 .dest = NI_PFI(1),
66 .src = (int[]){
67 TRIGGER_LINE(0),
68 TRIGGER_LINE(1),
69 TRIGGER_LINE(2),
70 TRIGGER_LINE(3),
71 TRIGGER_LINE(4),
72 TRIGGER_LINE(5),
73 TRIGGER_LINE(6),
74 TRIGGER_LINE(7),
75 NI_CtrSource(0),
76 NI_CtrSource(1),
77 NI_CtrGate(0),
78 NI_CtrGate(1),
79 NI_CtrInternalOutput(0),
80 NI_CtrInternalOutput(1),
81 NI_AI_SampleClock,
82 NI_AI_StartTrigger,
83 NI_AI_ReferenceTrigger,
84 NI_AI_ConvertClock,
85 NI_AO_SampleClock,
86 NI_AO_StartTrigger,
87 NI_DI_SampleClock,
88 NI_DO_SampleClock,
89 NI_FrequencyOutput,
90 NI_ChangeDetectionEvent,
91 0, /* Termination */
92 }
93 },
94 {
95 .dest = NI_PFI(2),
96 .src = (int[]){
97 TRIGGER_LINE(0),
98 TRIGGER_LINE(1),
99 TRIGGER_LINE(2),
100 TRIGGER_LINE(3),
101 TRIGGER_LINE(4),
102 TRIGGER_LINE(5),
103 TRIGGER_LINE(6),
104 TRIGGER_LINE(7),
105 NI_CtrSource(0),
106 NI_CtrSource(1),
107 NI_CtrGate(0),
108 NI_CtrGate(1),
109 NI_CtrInternalOutput(0),
110 NI_CtrInternalOutput(1),
111 NI_AI_SampleClock,
112 NI_AI_StartTrigger,
113 NI_AI_ReferenceTrigger,
114 NI_AI_ConvertClock,
115 NI_AO_SampleClock,
116 NI_AO_StartTrigger,
117 NI_DI_SampleClock,
118 NI_DO_SampleClock,
119 NI_FrequencyOutput,
120 NI_ChangeDetectionEvent,
121 0, /* Termination */
122 }
123 },
124 {
125 .dest = NI_PFI(3),
126 .src = (int[]){
127 TRIGGER_LINE(0),
128 TRIGGER_LINE(1),
129 TRIGGER_LINE(2),
130 TRIGGER_LINE(3),
131 TRIGGER_LINE(4),
132 TRIGGER_LINE(5),
133 TRIGGER_LINE(6),
134 TRIGGER_LINE(7),
135 NI_CtrSource(0),
136 NI_CtrSource(1),
137 NI_CtrGate(0),
138 NI_CtrGate(1),
139 NI_CtrInternalOutput(0),
140 NI_CtrInternalOutput(1),
141 NI_AI_SampleClock,
142 NI_AI_StartTrigger,
143 NI_AI_ReferenceTrigger,
144 NI_AI_ConvertClock,
145 NI_AO_SampleClock,
146 NI_AO_StartTrigger,
147 NI_DI_SampleClock,
148 NI_DO_SampleClock,
149 NI_FrequencyOutput,
150 NI_ChangeDetectionEvent,
151 0, /* Termination */
152 }
153 },
154 {
155 .dest = NI_PFI(4),
156 .src = (int[]){
157 TRIGGER_LINE(0),
158 TRIGGER_LINE(1),
159 TRIGGER_LINE(2),
160 TRIGGER_LINE(3),
161 TRIGGER_LINE(4),
162 TRIGGER_LINE(5),
163 TRIGGER_LINE(6),
164 TRIGGER_LINE(7),
165 NI_CtrSource(0),
166 NI_CtrSource(1),
167 NI_CtrGate(0),
168 NI_CtrGate(1),
169 NI_CtrInternalOutput(0),
170 NI_CtrInternalOutput(1),
171 NI_AI_SampleClock,
172 NI_AI_StartTrigger,
173 NI_AI_ReferenceTrigger,
174 NI_AI_ConvertClock,
175 NI_AO_SampleClock,
176 NI_AO_StartTrigger,
177 NI_DI_SampleClock,
178 NI_DO_SampleClock,
179 NI_FrequencyOutput,
180 NI_ChangeDetectionEvent,
181 0, /* Termination */
182 }
183 },
184 {
185 .dest = NI_PFI(5),
186 .src = (int[]){
187 TRIGGER_LINE(0),
188 TRIGGER_LINE(1),
189 TRIGGER_LINE(2),
190 TRIGGER_LINE(3),
191 TRIGGER_LINE(4),
192 TRIGGER_LINE(5),
193 TRIGGER_LINE(6),
194 TRIGGER_LINE(7),
195 NI_CtrSource(0),
196 NI_CtrSource(1),
197 NI_CtrGate(0),
198 NI_CtrGate(1),
199 NI_CtrInternalOutput(0),
200 NI_CtrInternalOutput(1),
201 NI_AI_SampleClock,
202 NI_AI_StartTrigger,
203 NI_AI_ReferenceTrigger,
204 NI_AI_ConvertClock,
205 NI_AO_SampleClock,
206 NI_AO_StartTrigger,
207 NI_DI_SampleClock,
208 NI_DO_SampleClock,
209 NI_FrequencyOutput,
210 NI_ChangeDetectionEvent,
211 0, /* Termination */
212 }
213 },
214 {
215 .dest = NI_PFI(6),
216 .src = (int[]){
217 TRIGGER_LINE(0),
218 TRIGGER_LINE(1),
219 TRIGGER_LINE(2),
220 TRIGGER_LINE(3),
221 TRIGGER_LINE(4),
222 TRIGGER_LINE(5),
223 TRIGGER_LINE(6),
224 TRIGGER_LINE(7),
225 NI_CtrSource(0),
226 NI_CtrSource(1),
227 NI_CtrGate(0),
228 NI_CtrGate(1),
229 NI_CtrInternalOutput(0),
230 NI_CtrInternalOutput(1),
231 NI_AI_SampleClock,
232 NI_AI_StartTrigger,
233 NI_AI_ReferenceTrigger,
234 NI_AI_ConvertClock,
235 NI_AO_SampleClock,
236 NI_AO_StartTrigger,
237 NI_DI_SampleClock,
238 NI_DO_SampleClock,
239 NI_FrequencyOutput,
240 NI_ChangeDetectionEvent,
241 0, /* Termination */
242 }
243 },
244 {
245 .dest = NI_PFI(7),
246 .src = (int[]){
247 TRIGGER_LINE(0),
248 TRIGGER_LINE(1),
249 TRIGGER_LINE(2),
250 TRIGGER_LINE(3),
251 TRIGGER_LINE(4),
252 TRIGGER_LINE(5),
253 TRIGGER_LINE(6),
254 TRIGGER_LINE(7),
255 NI_CtrSource(0),
256 NI_CtrSource(1),
257 NI_CtrGate(0),
258 NI_CtrGate(1),
259 NI_CtrInternalOutput(0),
260 NI_CtrInternalOutput(1),
261 NI_AI_SampleClock,
262 NI_AI_StartTrigger,
263 NI_AI_ReferenceTrigger,
264 NI_AI_ConvertClock,
265 NI_AO_SampleClock,
266 NI_AO_StartTrigger,
267 NI_DI_SampleClock,
268 NI_DO_SampleClock,
269 NI_FrequencyOutput,
270 NI_ChangeDetectionEvent,
271 0, /* Termination */
272 }
273 },
274 {
275 .dest = NI_PFI(8),
276 .src = (int[]){
277 TRIGGER_LINE(0),
278 TRIGGER_LINE(1),
279 TRIGGER_LINE(2),
280 TRIGGER_LINE(3),
281 TRIGGER_LINE(4),
282 TRIGGER_LINE(5),
283 TRIGGER_LINE(6),
284 TRIGGER_LINE(7),
285 NI_CtrSource(0),
286 NI_CtrSource(1),
287 NI_CtrGate(0),
288 NI_CtrGate(1),
289 NI_CtrInternalOutput(0),
290 NI_CtrInternalOutput(1),
291 NI_AI_SampleClock,
292 NI_AI_StartTrigger,
293 NI_AI_ReferenceTrigger,
294 NI_AI_ConvertClock,
295 NI_AO_SampleClock,
296 NI_AO_StartTrigger,
297 NI_DI_SampleClock,
298 NI_DO_SampleClock,
299 NI_FrequencyOutput,
300 NI_ChangeDetectionEvent,
301 0, /* Termination */
302 }
303 },
304 {
305 .dest = NI_PFI(9),
306 .src = (int[]){
307 TRIGGER_LINE(0),
308 TRIGGER_LINE(1),
309 TRIGGER_LINE(2),
310 TRIGGER_LINE(3),
311 TRIGGER_LINE(4),
312 TRIGGER_LINE(5),
313 TRIGGER_LINE(6),
314 TRIGGER_LINE(7),
315 NI_CtrSource(0),
316 NI_CtrSource(1),
317 NI_CtrGate(0),
318 NI_CtrGate(1),
319 NI_CtrInternalOutput(0),
320 NI_CtrInternalOutput(1),
321 NI_AI_SampleClock,
322 NI_AI_StartTrigger,
323 NI_AI_ReferenceTrigger,
324 NI_AI_ConvertClock,
325 NI_AO_SampleClock,
326 NI_AO_StartTrigger,
327 NI_DI_SampleClock,
328 NI_DO_SampleClock,
329 NI_FrequencyOutput,
330 NI_ChangeDetectionEvent,
331 0, /* Termination */
332 }
333 },
334 {
335 .dest = NI_PFI(10),
336 .src = (int[]){
337 TRIGGER_LINE(0),
338 TRIGGER_LINE(1),
339 TRIGGER_LINE(2),
340 TRIGGER_LINE(3),
341 TRIGGER_LINE(4),
342 TRIGGER_LINE(5),
343 TRIGGER_LINE(6),
344 TRIGGER_LINE(7),
345 NI_CtrSource(0),
346 NI_CtrSource(1),
347 NI_CtrGate(0),
348 NI_CtrGate(1),
349 NI_CtrInternalOutput(0),
350 NI_CtrInternalOutput(1),
351 NI_AI_SampleClock,
352 NI_AI_StartTrigger,
353 NI_AI_ReferenceTrigger,
354 NI_AI_ConvertClock,
355 NI_AO_SampleClock,
356 NI_AO_StartTrigger,
357 NI_DI_SampleClock,
358 NI_DO_SampleClock,
359 NI_FrequencyOutput,
360 NI_ChangeDetectionEvent,
361 0, /* Termination */
362 }
363 },
364 {
365 .dest = NI_PFI(11),
366 .src = (int[]){
367 TRIGGER_LINE(0),
368 TRIGGER_LINE(1),
369 TRIGGER_LINE(2),
370 TRIGGER_LINE(3),
371 TRIGGER_LINE(4),
372 TRIGGER_LINE(5),
373 TRIGGER_LINE(6),
374 TRIGGER_LINE(7),
375 NI_CtrSource(0),
376 NI_CtrSource(1),
377 NI_CtrGate(0),
378 NI_CtrGate(1),
379 NI_CtrInternalOutput(0),
380 NI_CtrInternalOutput(1),
381 NI_AI_SampleClock,
382 NI_AI_StartTrigger,
383 NI_AI_ReferenceTrigger,
384 NI_AI_ConvertClock,
385 NI_AO_SampleClock,
386 NI_AO_StartTrigger,
387 NI_DI_SampleClock,
388 NI_DO_SampleClock,
389 NI_FrequencyOutput,
390 NI_ChangeDetectionEvent,
391 0, /* Termination */
392 }
393 },
394 {
395 .dest = NI_PFI(12),
396 .src = (int[]){
397 TRIGGER_LINE(0),
398 TRIGGER_LINE(1),
399 TRIGGER_LINE(2),
400 TRIGGER_LINE(3),
401 TRIGGER_LINE(4),
402 TRIGGER_LINE(5),
403 TRIGGER_LINE(6),
404 TRIGGER_LINE(7),
405 NI_CtrSource(0),
406 NI_CtrSource(1),
407 NI_CtrGate(0),
408 NI_CtrGate(1),
409 NI_CtrInternalOutput(0),
410 NI_CtrInternalOutput(1),
411 NI_AI_SampleClock,
412 NI_AI_StartTrigger,
413 NI_AI_ReferenceTrigger,
414 NI_AI_ConvertClock,
415 NI_AO_SampleClock,
416 NI_AO_StartTrigger,
417 NI_DI_SampleClock,
418 NI_DO_SampleClock,
419 NI_FrequencyOutput,
420 NI_ChangeDetectionEvent,
421 0, /* Termination */
422 }
423 },
424 {
425 .dest = NI_PFI(13),
426 .src = (int[]){
427 TRIGGER_LINE(0),
428 TRIGGER_LINE(1),
429 TRIGGER_LINE(2),
430 TRIGGER_LINE(3),
431 TRIGGER_LINE(4),
432 TRIGGER_LINE(5),
433 TRIGGER_LINE(6),
434 TRIGGER_LINE(7),
435 NI_CtrSource(0),
436 NI_CtrSource(1),
437 NI_CtrGate(0),
438 NI_CtrGate(1),
439 NI_CtrInternalOutput(0),
440 NI_CtrInternalOutput(1),
441 NI_AI_SampleClock,
442 NI_AI_StartTrigger,
443 NI_AI_ReferenceTrigger,
444 NI_AI_ConvertClock,
445 NI_AO_SampleClock,
446 NI_AO_StartTrigger,
447 NI_DI_SampleClock,
448 NI_DO_SampleClock,
449 NI_FrequencyOutput,
450 NI_ChangeDetectionEvent,
451 0, /* Termination */
452 }
453 },
454 {
455 .dest = NI_PFI(14),
456 .src = (int[]){
457 TRIGGER_LINE(0),
458 TRIGGER_LINE(1),
459 TRIGGER_LINE(2),
460 TRIGGER_LINE(3),
461 TRIGGER_LINE(4),
462 TRIGGER_LINE(5),
463 TRIGGER_LINE(6),
464 TRIGGER_LINE(7),
465 NI_CtrSource(0),
466 NI_CtrSource(1),
467 NI_CtrGate(0),
468 NI_CtrGate(1),
469 NI_CtrInternalOutput(0),
470 NI_CtrInternalOutput(1),
471 NI_AI_SampleClock,
472 NI_AI_StartTrigger,
473 NI_AI_ReferenceTrigger,
474 NI_AI_ConvertClock,
475 NI_AO_SampleClock,
476 NI_AO_StartTrigger,
477 NI_DI_SampleClock,
478 NI_DO_SampleClock,
479 NI_FrequencyOutput,
480 NI_ChangeDetectionEvent,
481 0, /* Termination */
482 }
483 },
484 {
485 .dest = NI_PFI(15),
486 .src = (int[]){
487 TRIGGER_LINE(0),
488 TRIGGER_LINE(1),
489 TRIGGER_LINE(2),
490 TRIGGER_LINE(3),
491 TRIGGER_LINE(4),
492 TRIGGER_LINE(5),
493 TRIGGER_LINE(6),
494 TRIGGER_LINE(7),
495 NI_CtrSource(0),
496 NI_CtrSource(1),
497 NI_CtrGate(0),
498 NI_CtrGate(1),
499 NI_CtrInternalOutput(0),
500 NI_CtrInternalOutput(1),
501 NI_AI_SampleClock,
502 NI_AI_StartTrigger,
503 NI_AI_ReferenceTrigger,
504 NI_AI_ConvertClock,
505 NI_AO_SampleClock,
506 NI_AO_StartTrigger,
507 NI_DI_SampleClock,
508 NI_DO_SampleClock,
509 NI_FrequencyOutput,
510 NI_ChangeDetectionEvent,
511 0, /* Termination */
512 }
513 },
514 {
515 .dest = TRIGGER_LINE(0),
516 .src = (int[]){
517 NI_PFI(0),
518 NI_PFI(1),
519 NI_PFI(2),
520 NI_PFI(3),
521 NI_PFI(4),
522 NI_PFI(5),
523 NI_CtrSource(0),
524 NI_CtrSource(1),
525 NI_CtrGate(0),
526 NI_CtrGate(1),
527 NI_CtrInternalOutput(0),
528 NI_CtrInternalOutput(1),
529 NI_AI_SampleClock,
530 NI_AI_StartTrigger,
531 NI_AI_ReferenceTrigger,
532 NI_AI_ConvertClock,
533 NI_AI_PauseTrigger,
534 NI_AO_SampleClock,
535 NI_AO_StartTrigger,
536 NI_AO_PauseTrigger,
537 NI_10MHzRefClock,
538 NI_FrequencyOutput,
539 NI_ChangeDetectionEvent,
540 0, /* Termination */
541 }
542 },
543 {
544 .dest = TRIGGER_LINE(1),
545 .src = (int[]){
546 NI_PFI(0),
547 NI_PFI(1),
548 NI_PFI(2),
549 NI_PFI(3),
550 NI_PFI(4),
551 NI_PFI(5),
552 NI_CtrSource(0),
553 NI_CtrSource(1),
554 NI_CtrGate(0),
555 NI_CtrGate(1),
556 NI_CtrInternalOutput(0),
557 NI_CtrInternalOutput(1),
558 NI_AI_SampleClock,
559 NI_AI_StartTrigger,
560 NI_AI_ReferenceTrigger,
561 NI_AI_ConvertClock,
562 NI_AI_PauseTrigger,
563 NI_AO_SampleClock,
564 NI_AO_StartTrigger,
565 NI_AO_PauseTrigger,
566 NI_10MHzRefClock,
567 NI_FrequencyOutput,
568 NI_ChangeDetectionEvent,
569 0, /* Termination */
570 }
571 },
572 {
573 .dest = TRIGGER_LINE(2),
574 .src = (int[]){
575 NI_PFI(0),
576 NI_PFI(1),
577 NI_PFI(2),
578 NI_PFI(3),
579 NI_PFI(4),
580 NI_PFI(5),
581 NI_CtrSource(0),
582 NI_CtrSource(1),
583 NI_CtrGate(0),
584 NI_CtrGate(1),
585 NI_CtrInternalOutput(0),
586 NI_CtrInternalOutput(1),
587 NI_AI_SampleClock,
588 NI_AI_StartTrigger,
589 NI_AI_ReferenceTrigger,
590 NI_AI_ConvertClock,
591 NI_AI_PauseTrigger,
592 NI_AO_SampleClock,
593 NI_AO_StartTrigger,
594 NI_AO_PauseTrigger,
595 NI_10MHzRefClock,
596 NI_FrequencyOutput,
597 NI_ChangeDetectionEvent,
598 0, /* Termination */
599 }
600 },
601 {
602 .dest = TRIGGER_LINE(3),
603 .src = (int[]){
604 NI_PFI(0),
605 NI_PFI(1),
606 NI_PFI(2),
607 NI_PFI(3),
608 NI_PFI(4),
609 NI_PFI(5),
610 NI_CtrSource(0),
611 NI_CtrSource(1),
612 NI_CtrGate(0),
613 NI_CtrGate(1),
614 NI_CtrInternalOutput(0),
615 NI_CtrInternalOutput(1),
616 NI_AI_SampleClock,
617 NI_AI_StartTrigger,
618 NI_AI_ReferenceTrigger,
619 NI_AI_ConvertClock,
620 NI_AI_PauseTrigger,
621 NI_AO_SampleClock,
622 NI_AO_StartTrigger,
623 NI_AO_PauseTrigger,
624 NI_10MHzRefClock,
625 NI_FrequencyOutput,
626 NI_ChangeDetectionEvent,
627 0, /* Termination */
628 }
629 },
630 {
631 .dest = TRIGGER_LINE(4),
632 .src = (int[]){
633 NI_PFI(0),
634 NI_PFI(1),
635 NI_PFI(2),
636 NI_PFI(3),
637 NI_PFI(4),
638 NI_PFI(5),
639 NI_CtrSource(0),
640 NI_CtrSource(1),
641 NI_CtrGate(0),
642 NI_CtrGate(1),
643 NI_CtrInternalOutput(0),
644 NI_CtrInternalOutput(1),
645 NI_AI_SampleClock,
646 NI_AI_StartTrigger,
647 NI_AI_ReferenceTrigger,
648 NI_AI_ConvertClock,
649 NI_AI_PauseTrigger,
650 NI_AO_SampleClock,
651 NI_AO_StartTrigger,
652 NI_AO_PauseTrigger,
653 NI_10MHzRefClock,
654 NI_FrequencyOutput,
655 NI_ChangeDetectionEvent,
656 0, /* Termination */
657 }
658 },
659 {
660 .dest = TRIGGER_LINE(5),
661 .src = (int[]){
662 NI_PFI(0),
663 NI_PFI(1),
664 NI_PFI(2),
665 NI_PFI(3),
666 NI_PFI(4),
667 NI_PFI(5),
668 NI_CtrSource(0),
669 NI_CtrSource(1),
670 NI_CtrGate(0),
671 NI_CtrGate(1),
672 NI_CtrInternalOutput(0),
673 NI_CtrInternalOutput(1),
674 NI_AI_SampleClock,
675 NI_AI_StartTrigger,
676 NI_AI_ReferenceTrigger,
677 NI_AI_ConvertClock,
678 NI_AI_PauseTrigger,
679 NI_AO_SampleClock,
680 NI_AO_StartTrigger,
681 NI_AO_PauseTrigger,
682 NI_10MHzRefClock,
683 NI_FrequencyOutput,
684 NI_ChangeDetectionEvent,
685 0, /* Termination */
686 }
687 },
688 {
689 .dest = TRIGGER_LINE(6),
690 .src = (int[]){
691 NI_PFI(0),
692 NI_PFI(1),
693 NI_PFI(2),
694 NI_PFI(3),
695 NI_PFI(4),
696 NI_PFI(5),
697 NI_CtrSource(0),
698 NI_CtrSource(1),
699 NI_CtrGate(0),
700 NI_CtrGate(1),
701 NI_CtrInternalOutput(0),
702 NI_CtrInternalOutput(1),
703 NI_AI_SampleClock,
704 NI_AI_StartTrigger,
705 NI_AI_ReferenceTrigger,
706 NI_AI_ConvertClock,
707 NI_AI_PauseTrigger,
708 NI_AO_SampleClock,
709 NI_AO_StartTrigger,
710 NI_AO_PauseTrigger,
711 NI_10MHzRefClock,
712 NI_FrequencyOutput,
713 NI_ChangeDetectionEvent,
714 0, /* Termination */
715 }
716 },
717 {
718 .dest = TRIGGER_LINE(7),
719 .src = (int[]){
720 NI_PFI(0),
721 NI_PFI(1),
722 NI_PFI(2),
723 NI_PFI(3),
724 NI_PFI(4),
725 NI_PFI(5),
726 NI_CtrSource(0),
727 NI_CtrSource(1),
728 NI_CtrGate(0),
729 NI_CtrGate(1),
730 NI_CtrInternalOutput(0),
731 NI_CtrInternalOutput(1),
732 NI_AI_SampleClock,
733 NI_AI_StartTrigger,
734 NI_AI_ReferenceTrigger,
735 NI_AI_ConvertClock,
736 NI_AI_PauseTrigger,
737 NI_AO_SampleClock,
738 NI_AO_StartTrigger,
739 NI_AO_PauseTrigger,
740 NI_10MHzRefClock,
741 NI_FrequencyOutput,
742 NI_ChangeDetectionEvent,
743 0, /* Termination */
744 }
745 },
746 {
747 .dest = NI_CtrSource(0),
748 .src = (int[]){
749 NI_PFI(0),
750 NI_PFI(1),
751 NI_PFI(2),
752 NI_PFI(3),
753 NI_PFI(4),
754 NI_PFI(5),
755 NI_PFI(6),
756 NI_PFI(7),
757 NI_PFI(8),
758 NI_PFI(9),
759 NI_PFI(10),
760 NI_PFI(11),
761 NI_PFI(12),
762 NI_PFI(13),
763 NI_PFI(14),
764 NI_PFI(15),
765 TRIGGER_LINE(0),
766 TRIGGER_LINE(1),
767 TRIGGER_LINE(2),
768 TRIGGER_LINE(3),
769 TRIGGER_LINE(4),
770 TRIGGER_LINE(5),
771 TRIGGER_LINE(6),
772 TRIGGER_LINE(7),
773 NI_CtrGate(1),
774 NI_20MHzTimebase,
775 NI_80MHzTimebase,
776 NI_100kHzTimebase,
777 0, /* Termination */
778 }
779 },
780 {
781 .dest = NI_CtrSource(1),
782 .src = (int[]){
783 NI_PFI(0),
784 NI_PFI(1),
785 NI_PFI(2),
786 NI_PFI(3),
787 NI_PFI(4),
788 NI_PFI(5),
789 NI_PFI(6),
790 NI_PFI(7),
791 NI_PFI(8),
792 NI_PFI(9),
793 NI_PFI(10),
794 NI_PFI(11),
795 NI_PFI(12),
796 NI_PFI(13),
797 NI_PFI(14),
798 NI_PFI(15),
799 TRIGGER_LINE(0),
800 TRIGGER_LINE(1),
801 TRIGGER_LINE(2),
802 TRIGGER_LINE(3),
803 TRIGGER_LINE(4),
804 TRIGGER_LINE(5),
805 TRIGGER_LINE(6),
806 TRIGGER_LINE(7),
807 NI_CtrGate(0),
808 NI_20MHzTimebase,
809 NI_80MHzTimebase,
810 NI_100kHzTimebase,
811 0, /* Termination */
812 }
813 },
814 {
815 .dest = NI_CtrGate(0),
816 .src = (int[]){
817 NI_PFI(0),
818 NI_PFI(1),
819 NI_PFI(2),
820 NI_PFI(3),
821 NI_PFI(4),
822 NI_PFI(5),
823 NI_PFI(6),
824 NI_PFI(7),
825 NI_PFI(8),
826 NI_PFI(9),
827 NI_PFI(10),
828 NI_PFI(11),
829 NI_PFI(12),
830 NI_PFI(13),
831 NI_PFI(14),
832 NI_PFI(15),
833 TRIGGER_LINE(0),
834 TRIGGER_LINE(1),
835 TRIGGER_LINE(2),
836 TRIGGER_LINE(3),
837 TRIGGER_LINE(4),
838 TRIGGER_LINE(5),
839 TRIGGER_LINE(6),
840 TRIGGER_LINE(7),
841 NI_CtrSource(1),
842 NI_CtrInternalOutput(1),
843 NI_AI_StartTrigger,
844 NI_AI_ReferenceTrigger,
845 0, /* Termination */
846 }
847 },
848 {
849 .dest = NI_CtrGate(1),
850 .src = (int[]){
851 NI_PFI(0),
852 NI_PFI(1),
853 NI_PFI(2),
854 NI_PFI(3),
855 NI_PFI(4),
856 NI_PFI(5),
857 NI_PFI(6),
858 NI_PFI(7),
859 NI_PFI(8),
860 NI_PFI(9),
861 NI_PFI(10),
862 NI_PFI(11),
863 NI_PFI(12),
864 NI_PFI(13),
865 NI_PFI(14),
866 NI_PFI(15),
867 TRIGGER_LINE(0),
868 TRIGGER_LINE(1),
869 TRIGGER_LINE(2),
870 TRIGGER_LINE(3),
871 TRIGGER_LINE(4),
872 TRIGGER_LINE(5),
873 TRIGGER_LINE(6),
874 TRIGGER_LINE(7),
875 NI_CtrSource(0),
876 NI_CtrInternalOutput(0),
877 NI_AI_StartTrigger,
878 NI_AI_ReferenceTrigger,
879 0, /* Termination */
880 }
881 },
882 {
883 .dest = NI_CtrAux(0),
884 .src = (int[]){
885 NI_PFI(0),
886 NI_PFI(1),
887 NI_PFI(2),
888 NI_PFI(3),
889 NI_PFI(4),
890 NI_PFI(5),
891 NI_PFI(6),
892 NI_PFI(7),
893 NI_PFI(8),
894 NI_PFI(9),
895 NI_PFI(10),
896 NI_PFI(11),
897 NI_PFI(12),
898 NI_PFI(13),
899 NI_PFI(14),
900 NI_PFI(15),
901 TRIGGER_LINE(0),
902 TRIGGER_LINE(1),
903 TRIGGER_LINE(2),
904 TRIGGER_LINE(3),
905 TRIGGER_LINE(4),
906 TRIGGER_LINE(5),
907 TRIGGER_LINE(6),
908 TRIGGER_LINE(7),
909 NI_CtrSource(1),
910 NI_CtrGate(0),
911 NI_CtrGate(1),
912 NI_CtrInternalOutput(1),
913 NI_AI_StartTrigger,
914 NI_AI_ReferenceTrigger,
915 0, /* Termination */
916 }
917 },
918 {
919 .dest = NI_CtrAux(1),
920 .src = (int[]){
921 NI_PFI(0),
922 NI_PFI(1),
923 NI_PFI(2),
924 NI_PFI(3),
925 NI_PFI(4),
926 NI_PFI(5),
927 NI_PFI(6),
928 NI_PFI(7),
929 NI_PFI(8),
930 NI_PFI(9),
931 NI_PFI(10),
932 NI_PFI(11),
933 NI_PFI(12),
934 NI_PFI(13),
935 NI_PFI(14),
936 NI_PFI(15),
937 TRIGGER_LINE(0),
938 TRIGGER_LINE(1),
939 TRIGGER_LINE(2),
940 TRIGGER_LINE(3),
941 TRIGGER_LINE(4),
942 TRIGGER_LINE(5),
943 TRIGGER_LINE(6),
944 TRIGGER_LINE(7),
945 NI_CtrSource(0),
946 NI_CtrGate(0),
947 NI_CtrGate(1),
948 NI_CtrInternalOutput(0),
949 NI_AI_StartTrigger,
950 NI_AI_ReferenceTrigger,
951 0, /* Termination */
952 }
953 },
954 {
955 .dest = NI_CtrA(0),
956 .src = (int[]){
957 NI_PFI(0),
958 NI_PFI(1),
959 NI_PFI(2),
960 NI_PFI(3),
961 NI_PFI(4),
962 NI_PFI(5),
963 NI_PFI(6),
964 NI_PFI(7),
965 NI_PFI(8),
966 NI_PFI(9),
967 NI_PFI(10),
968 NI_PFI(11),
969 NI_PFI(12),
970 NI_PFI(13),
971 NI_PFI(14),
972 NI_PFI(15),
973 TRIGGER_LINE(0),
974 TRIGGER_LINE(1),
975 TRIGGER_LINE(2),
976 TRIGGER_LINE(3),
977 TRIGGER_LINE(4),
978 TRIGGER_LINE(5),
979 TRIGGER_LINE(6),
980 TRIGGER_LINE(7),
981 0, /* Termination */
982 }
983 },
984 {
985 .dest = NI_CtrA(1),
986 .src = (int[]){
987 NI_PFI(0),
988 NI_PFI(1),
989 NI_PFI(2),
990 NI_PFI(3),
991 NI_PFI(4),
992 NI_PFI(5),
993 NI_PFI(6),
994 NI_PFI(7),
995 NI_PFI(8),
996 NI_PFI(9),
997 NI_PFI(10),
998 NI_PFI(11),
999 NI_PFI(12),
1000 NI_PFI(13),
1001 NI_PFI(14),
1002 NI_PFI(15),
1003 TRIGGER_LINE(0),
1004 TRIGGER_LINE(1),
1005 TRIGGER_LINE(2),
1006 TRIGGER_LINE(3),
1007 TRIGGER_LINE(4),
1008 TRIGGER_LINE(5),
1009 TRIGGER_LINE(6),
1010 TRIGGER_LINE(7),
1011 0, /* Termination */
1012 }
1013 },
1014 {
1015 .dest = NI_CtrB(0),
1016 .src = (int[]){
1017 NI_PFI(0),
1018 NI_PFI(1),
1019 NI_PFI(2),
1020 NI_PFI(3),
1021 NI_PFI(4),
1022 NI_PFI(5),
1023 NI_PFI(6),
1024 NI_PFI(7),
1025 NI_PFI(8),
1026 NI_PFI(9),
1027 NI_PFI(10),
1028 NI_PFI(11),
1029 NI_PFI(12),
1030 NI_PFI(13),
1031 NI_PFI(14),
1032 NI_PFI(15),
1033 TRIGGER_LINE(0),
1034 TRIGGER_LINE(1),
1035 TRIGGER_LINE(2),
1036 TRIGGER_LINE(3),
1037 TRIGGER_LINE(4),
1038 TRIGGER_LINE(5),
1039 TRIGGER_LINE(6),
1040 TRIGGER_LINE(7),
1041 0, /* Termination */
1042 }
1043 },
1044 {
1045 .dest = NI_CtrB(1),
1046 .src = (int[]){
1047 NI_PFI(0),
1048 NI_PFI(1),
1049 NI_PFI(2),
1050 NI_PFI(3),
1051 NI_PFI(4),
1052 NI_PFI(5),
1053 NI_PFI(6),
1054 NI_PFI(7),
1055 NI_PFI(8),
1056 NI_PFI(9),
1057 NI_PFI(10),
1058 NI_PFI(11),
1059 NI_PFI(12),
1060 NI_PFI(13),
1061 NI_PFI(14),
1062 NI_PFI(15),
1063 TRIGGER_LINE(0),
1064 TRIGGER_LINE(1),
1065 TRIGGER_LINE(2),
1066 TRIGGER_LINE(3),
1067 TRIGGER_LINE(4),
1068 TRIGGER_LINE(5),
1069 TRIGGER_LINE(6),
1070 TRIGGER_LINE(7),
1071 0, /* Termination */
1072 }
1073 },
1074 {
1075 .dest = NI_CtrZ(0),
1076 .src = (int[]){
1077 NI_PFI(0),
1078 NI_PFI(1),
1079 NI_PFI(2),
1080 NI_PFI(3),
1081 NI_PFI(4),
1082 NI_PFI(5),
1083 NI_PFI(6),
1084 NI_PFI(7),
1085 NI_PFI(8),
1086 NI_PFI(9),
1087 NI_PFI(10),
1088 NI_PFI(11),
1089 NI_PFI(12),
1090 NI_PFI(13),
1091 NI_PFI(14),
1092 NI_PFI(15),
1093 TRIGGER_LINE(0),
1094 TRIGGER_LINE(1),
1095 TRIGGER_LINE(2),
1096 TRIGGER_LINE(3),
1097 TRIGGER_LINE(4),
1098 TRIGGER_LINE(5),
1099 TRIGGER_LINE(6),
1100 TRIGGER_LINE(7),
1101 0, /* Termination */
1102 }
1103 },
1104 {
1105 .dest = NI_CtrZ(1),
1106 .src = (int[]){
1107 NI_PFI(0),
1108 NI_PFI(1),
1109 NI_PFI(2),
1110 NI_PFI(3),
1111 NI_PFI(4),
1112 NI_PFI(5),
1113 NI_PFI(6),
1114 NI_PFI(7),
1115 NI_PFI(8),
1116 NI_PFI(9),
1117 NI_PFI(10),
1118 NI_PFI(11),
1119 NI_PFI(12),
1120 NI_PFI(13),
1121 NI_PFI(14),
1122 NI_PFI(15),
1123 TRIGGER_LINE(0),
1124 TRIGGER_LINE(1),
1125 TRIGGER_LINE(2),
1126 TRIGGER_LINE(3),
1127 TRIGGER_LINE(4),
1128 TRIGGER_LINE(5),
1129 TRIGGER_LINE(6),
1130 TRIGGER_LINE(7),
1131 0, /* Termination */
1132 }
1133 },
1134 {
1135 .dest = NI_CtrArmStartTrigger(0),
1136 .src = (int[]){
1137 NI_PFI(0),
1138 NI_PFI(1),
1139 NI_PFI(2),
1140 NI_PFI(3),
1141 NI_PFI(4),
1142 NI_PFI(5),
1143 NI_PFI(6),
1144 NI_PFI(7),
1145 NI_PFI(8),
1146 NI_PFI(9),
1147 NI_PFI(10),
1148 NI_PFI(11),
1149 NI_PFI(12),
1150 NI_PFI(13),
1151 NI_PFI(14),
1152 NI_PFI(15),
1153 TRIGGER_LINE(0),
1154 TRIGGER_LINE(1),
1155 TRIGGER_LINE(2),
1156 TRIGGER_LINE(3),
1157 TRIGGER_LINE(4),
1158 TRIGGER_LINE(5),
1159 TRIGGER_LINE(6),
1160 TRIGGER_LINE(7),
1161 NI_CtrInternalOutput(1),
1162 NI_AI_StartTrigger,
1163 NI_AI_ReferenceTrigger,
1164 0, /* Termination */
1165 }
1166 },
1167 {
1168 .dest = NI_CtrArmStartTrigger(1),
1169 .src = (int[]){
1170 NI_PFI(0),
1171 NI_PFI(1),
1172 NI_PFI(2),
1173 NI_PFI(3),
1174 NI_PFI(4),
1175 NI_PFI(5),
1176 NI_PFI(6),
1177 NI_PFI(7),
1178 NI_PFI(8),
1179 NI_PFI(9),
1180 NI_PFI(10),
1181 NI_PFI(11),
1182 NI_PFI(12),
1183 NI_PFI(13),
1184 NI_PFI(14),
1185 NI_PFI(15),
1186 TRIGGER_LINE(0),
1187 TRIGGER_LINE(1),
1188 TRIGGER_LINE(2),
1189 TRIGGER_LINE(3),
1190 TRIGGER_LINE(4),
1191 TRIGGER_LINE(5),
1192 TRIGGER_LINE(6),
1193 TRIGGER_LINE(7),
1194 NI_CtrInternalOutput(0),
1195 NI_AI_StartTrigger,
1196 NI_AI_ReferenceTrigger,
1197 0, /* Termination */
1198 }
1199 },
1200 {
1201 .dest = NI_AI_SampleClock,
1202 .src = (int[]){
1203 NI_PFI(0),
1204 NI_PFI(1),
1205 NI_PFI(2),
1206 NI_PFI(3),
1207 NI_PFI(4),
1208 NI_PFI(5),
1209 NI_PFI(6),
1210 NI_PFI(7),
1211 NI_PFI(8),
1212 NI_PFI(9),
1213 NI_PFI(10),
1214 NI_PFI(11),
1215 NI_PFI(12),
1216 NI_PFI(13),
1217 NI_PFI(14),
1218 NI_PFI(15),
1219 TRIGGER_LINE(0),
1220 TRIGGER_LINE(1),
1221 TRIGGER_LINE(2),
1222 TRIGGER_LINE(3),
1223 TRIGGER_LINE(4),
1224 TRIGGER_LINE(5),
1225 TRIGGER_LINE(6),
1226 TRIGGER_LINE(7),
1227 NI_CtrInternalOutput(0),
1228 NI_CtrInternalOutput(1),
1229 NI_AI_SampleClockTimebase,
1230 0, /* Termination */
1231 }
1232 },
1233 {
1234 .dest = NI_AI_SampleClockTimebase,
1235 .src = (int[]){
1236 NI_PFI(0),
1237 NI_PFI(1),
1238 NI_PFI(2),
1239 NI_PFI(3),
1240 NI_PFI(4),
1241 NI_PFI(5),
1242 NI_PFI(6),
1243 NI_PFI(7),
1244 NI_PFI(8),
1245 NI_PFI(9),
1246 NI_PFI(10),
1247 NI_PFI(11),
1248 NI_PFI(12),
1249 NI_PFI(13),
1250 NI_PFI(14),
1251 NI_PFI(15),
1252 TRIGGER_LINE(0),
1253 TRIGGER_LINE(1),
1254 TRIGGER_LINE(2),
1255 TRIGGER_LINE(3),
1256 TRIGGER_LINE(4),
1257 TRIGGER_LINE(5),
1258 TRIGGER_LINE(6),
1259 TRIGGER_LINE(7),
1260 NI_20MHzTimebase,
1261 NI_100kHzTimebase,
1262 0, /* Termination */
1263 }
1264 },
1265 {
1266 .dest = NI_AI_StartTrigger,
1267 .src = (int[]){
1268 NI_PFI(0),
1269 NI_PFI(1),
1270 NI_PFI(2),
1271 NI_PFI(3),
1272 NI_PFI(4),
1273 NI_PFI(5),
1274 NI_PFI(6),
1275 NI_PFI(7),
1276 NI_PFI(8),
1277 NI_PFI(9),
1278 NI_PFI(10),
1279 NI_PFI(11),
1280 NI_PFI(12),
1281 NI_PFI(13),
1282 NI_PFI(14),
1283 NI_PFI(15),
1284 TRIGGER_LINE(0),
1285 TRIGGER_LINE(1),
1286 TRIGGER_LINE(2),
1287 TRIGGER_LINE(3),
1288 TRIGGER_LINE(4),
1289 TRIGGER_LINE(5),
1290 TRIGGER_LINE(6),
1291 TRIGGER_LINE(7),
1292 NI_CtrInternalOutput(0),
1293 NI_CtrInternalOutput(1),
1294 0, /* Termination */
1295 }
1296 },
1297 {
1298 .dest = NI_AI_ReferenceTrigger,
1299 .src = (int[]){
1300 NI_PFI(0),
1301 NI_PFI(1),
1302 NI_PFI(2),
1303 NI_PFI(3),
1304 NI_PFI(4),
1305 NI_PFI(5),
1306 NI_PFI(6),
1307 NI_PFI(7),
1308 NI_PFI(8),
1309 NI_PFI(9),
1310 NI_PFI(10),
1311 NI_PFI(11),
1312 NI_PFI(12),
1313 NI_PFI(13),
1314 NI_PFI(14),
1315 NI_PFI(15),
1316 TRIGGER_LINE(0),
1317 TRIGGER_LINE(1),
1318 TRIGGER_LINE(2),
1319 TRIGGER_LINE(3),
1320 TRIGGER_LINE(4),
1321 TRIGGER_LINE(5),
1322 TRIGGER_LINE(6),
1323 TRIGGER_LINE(7),
1324 0, /* Termination */
1325 }
1326 },
1327 {
1328 .dest = NI_AI_ConvertClock,
1329 .src = (int[]){
1330 NI_PFI(0),
1331 NI_PFI(1),
1332 NI_PFI(2),
1333 NI_PFI(3),
1334 NI_PFI(4),
1335 NI_PFI(5),
1336 NI_PFI(6),
1337 NI_PFI(7),
1338 NI_PFI(8),
1339 NI_PFI(9),
1340 NI_PFI(10),
1341 NI_PFI(11),
1342 NI_PFI(12),
1343 NI_PFI(13),
1344 NI_PFI(14),
1345 NI_PFI(15),
1346 TRIGGER_LINE(0),
1347 TRIGGER_LINE(1),
1348 TRIGGER_LINE(2),
1349 TRIGGER_LINE(3),
1350 TRIGGER_LINE(4),
1351 TRIGGER_LINE(5),
1352 TRIGGER_LINE(6),
1353 TRIGGER_LINE(7),
1354 NI_CtrInternalOutput(0),
1355 NI_CtrInternalOutput(1),
1356 NI_AI_ConvertClockTimebase,
1357 0, /* Termination */
1358 }
1359 },
1360 {
1361 .dest = NI_AI_ConvertClockTimebase,
1362 .src = (int[]){
1363 NI_AI_SampleClockTimebase,
1364 NI_20MHzTimebase,
1365 0, /* Termination */
1366 }
1367 },
1368 {
1369 .dest = NI_AI_PauseTrigger,
1370 .src = (int[]){
1371 NI_PFI(0),
1372 NI_PFI(1),
1373 NI_PFI(2),
1374 NI_PFI(3),
1375 NI_PFI(4),
1376 NI_PFI(5),
1377 NI_PFI(6),
1378 NI_PFI(7),
1379 NI_PFI(8),
1380 NI_PFI(9),
1381 NI_PFI(10),
1382 NI_PFI(11),
1383 NI_PFI(12),
1384 NI_PFI(13),
1385 NI_PFI(14),
1386 NI_PFI(15),
1387 TRIGGER_LINE(0),
1388 TRIGGER_LINE(1),
1389 TRIGGER_LINE(2),
1390 TRIGGER_LINE(3),
1391 TRIGGER_LINE(4),
1392 TRIGGER_LINE(5),
1393 TRIGGER_LINE(6),
1394 TRIGGER_LINE(7),
1395 0, /* Termination */
1396 }
1397 },
1398 {
1399 .dest = NI_AO_SampleClock,
1400 .src = (int[]){
1401 NI_PFI(0),
1402 NI_PFI(1),
1403 NI_PFI(2),
1404 NI_PFI(3),
1405 NI_PFI(4),
1406 NI_PFI(5),
1407 NI_PFI(6),
1408 NI_PFI(7),
1409 NI_PFI(8),
1410 NI_PFI(9),
1411 NI_PFI(10),
1412 NI_PFI(11),
1413 NI_PFI(12),
1414 NI_PFI(13),
1415 NI_PFI(14),
1416 NI_PFI(15),
1417 TRIGGER_LINE(0),
1418 TRIGGER_LINE(1),
1419 TRIGGER_LINE(2),
1420 TRIGGER_LINE(3),
1421 TRIGGER_LINE(4),
1422 TRIGGER_LINE(5),
1423 TRIGGER_LINE(6),
1424 TRIGGER_LINE(7),
1425 NI_CtrInternalOutput(0),
1426 NI_CtrInternalOutput(1),
1427 NI_AO_SampleClockTimebase,
1428 0, /* Termination */
1429 }
1430 },
1431 {
1432 .dest = NI_AO_SampleClockTimebase,
1433 .src = (int[]){
1434 NI_PFI(0),
1435 NI_PFI(1),
1436 NI_PFI(2),
1437 NI_PFI(3),
1438 NI_PFI(4),
1439 NI_PFI(5),
1440 NI_PFI(6),
1441 NI_PFI(7),
1442 NI_PFI(8),
1443 NI_PFI(9),
1444 NI_PFI(10),
1445 NI_PFI(11),
1446 NI_PFI(12),
1447 NI_PFI(13),
1448 NI_PFI(14),
1449 NI_PFI(15),
1450 TRIGGER_LINE(0),
1451 TRIGGER_LINE(1),
1452 TRIGGER_LINE(2),
1453 TRIGGER_LINE(3),
1454 TRIGGER_LINE(4),
1455 TRIGGER_LINE(5),
1456 TRIGGER_LINE(6),
1457 TRIGGER_LINE(7),
1458 NI_20MHzTimebase,
1459 NI_100kHzTimebase,
1460 0, /* Termination */
1461 }
1462 },
1463 {
1464 .dest = NI_AO_StartTrigger,
1465 .src = (int[]){
1466 NI_PFI(0),
1467 NI_PFI(1),
1468 NI_PFI(2),
1469 NI_PFI(3),
1470 NI_PFI(4),
1471 NI_PFI(5),
1472 NI_PFI(6),
1473 NI_PFI(7),
1474 NI_PFI(8),
1475 NI_PFI(9),
1476 NI_PFI(10),
1477 NI_PFI(11),
1478 NI_PFI(12),
1479 NI_PFI(13),
1480 NI_PFI(14),
1481 NI_PFI(15),
1482 TRIGGER_LINE(0),
1483 TRIGGER_LINE(1),
1484 TRIGGER_LINE(2),
1485 TRIGGER_LINE(3),
1486 TRIGGER_LINE(4),
1487 TRIGGER_LINE(5),
1488 TRIGGER_LINE(6),
1489 TRIGGER_LINE(7),
1490 NI_AI_StartTrigger,
1491 0, /* Termination */
1492 }
1493 },
1494 {
1495 .dest = NI_AO_PauseTrigger,
1496 .src = (int[]){
1497 NI_PFI(0),
1498 NI_PFI(1),
1499 NI_PFI(2),
1500 NI_PFI(3),
1501 NI_PFI(4),
1502 NI_PFI(5),
1503 NI_PFI(6),
1504 NI_PFI(7),
1505 NI_PFI(8),
1506 NI_PFI(9),
1507 NI_PFI(10),
1508 NI_PFI(11),
1509 NI_PFI(12),
1510 NI_PFI(13),
1511 NI_PFI(14),
1512 NI_PFI(15),
1513 TRIGGER_LINE(0),
1514 TRIGGER_LINE(1),
1515 TRIGGER_LINE(2),
1516 TRIGGER_LINE(3),
1517 TRIGGER_LINE(4),
1518 TRIGGER_LINE(5),
1519 TRIGGER_LINE(6),
1520 TRIGGER_LINE(7),
1521 0, /* Termination */
1522 }
1523 },
1524 {
1525 .dest = NI_DI_SampleClock,
1526 .src = (int[]){
1527 NI_PFI(0),
1528 NI_PFI(1),
1529 NI_PFI(2),
1530 NI_PFI(3),
1531 NI_PFI(4),
1532 NI_PFI(5),
1533 NI_PFI(6),
1534 NI_PFI(7),
1535 NI_PFI(8),
1536 NI_PFI(9),
1537 NI_PFI(10),
1538 NI_PFI(11),
1539 NI_PFI(12),
1540 NI_PFI(13),
1541 NI_PFI(14),
1542 NI_PFI(15),
1543 TRIGGER_LINE(0),
1544 TRIGGER_LINE(1),
1545 TRIGGER_LINE(2),
1546 TRIGGER_LINE(3),
1547 TRIGGER_LINE(4),
1548 TRIGGER_LINE(5),
1549 TRIGGER_LINE(6),
1550 TRIGGER_LINE(7),
1551 NI_CtrInternalOutput(0),
1552 NI_CtrInternalOutput(1),
1553 NI_AI_SampleClock,
1554 NI_AI_ConvertClock,
1555 NI_AO_SampleClock,
1556 NI_FrequencyOutput,
1557 NI_ChangeDetectionEvent,
1558 0, /* Termination */
1559 }
1560 },
1561 {
1562 .dest = NI_DO_SampleClock,
1563 .src = (int[]){
1564 NI_PFI(0),
1565 NI_PFI(1),
1566 NI_PFI(2),
1567 NI_PFI(3),
1568 NI_PFI(4),
1569 NI_PFI(5),
1570 NI_PFI(6),
1571 NI_PFI(7),
1572 NI_PFI(8),
1573 NI_PFI(9),
1574 NI_PFI(10),
1575 NI_PFI(11),
1576 NI_PFI(12),
1577 NI_PFI(13),
1578 NI_PFI(14),
1579 NI_PFI(15),
1580 TRIGGER_LINE(0),
1581 TRIGGER_LINE(1),
1582 TRIGGER_LINE(2),
1583 TRIGGER_LINE(3),
1584 TRIGGER_LINE(4),
1585 TRIGGER_LINE(5),
1586 TRIGGER_LINE(6),
1587 TRIGGER_LINE(7),
1588 NI_CtrInternalOutput(0),
1589 NI_CtrInternalOutput(1),
1590 NI_AI_SampleClock,
1591 NI_AI_ConvertClock,
1592 NI_AO_SampleClock,
1593 NI_FrequencyOutput,
1594 NI_ChangeDetectionEvent,
1595 0, /* Termination */
1596 }
1597 },
1598 { /* Termination of list */
1599 .dest = 0,
1600 },
1601 },
1602};
diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6229.c b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6229.c
new file mode 100644
index 000000000000..fa5794e4e2b3
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6229.c
@@ -0,0 +1,1602 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routing/ni_device_routes/pci-6229.c
5 * List of valid routes for specific NI boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21/*
22 * The contents of this file are generated using the tools in
23 * comedi/drivers/ni_routing/tools
24 *
25 * Please use those tools to help maintain the contents of this file.
26 */
27
28#include "../ni_device_routes.h"
29#include "all.h"
30
31struct ni_device_routes ni_pci_6229_device_routes = {
32 .device = "pci-6229",
33 .routes = (struct ni_route_set[]){
34 {
35 .dest = NI_PFI(0),
36 .src = (int[]){
37 TRIGGER_LINE(0),
38 TRIGGER_LINE(1),
39 TRIGGER_LINE(2),
40 TRIGGER_LINE(3),
41 TRIGGER_LINE(4),
42 TRIGGER_LINE(5),
43 TRIGGER_LINE(6),
44 TRIGGER_LINE(7),
45 NI_CtrSource(0),
46 NI_CtrSource(1),
47 NI_CtrGate(0),
48 NI_CtrGate(1),
49 NI_CtrInternalOutput(0),
50 NI_CtrInternalOutput(1),
51 NI_AI_SampleClock,
52 NI_AI_StartTrigger,
53 NI_AI_ReferenceTrigger,
54 NI_AI_ConvertClock,
55 NI_AO_SampleClock,
56 NI_AO_StartTrigger,
57 NI_DI_SampleClock,
58 NI_DO_SampleClock,
59 NI_FrequencyOutput,
60 NI_ChangeDetectionEvent,
61 0, /* Termination */
62 }
63 },
64 {
65 .dest = NI_PFI(1),
66 .src = (int[]){
67 TRIGGER_LINE(0),
68 TRIGGER_LINE(1),
69 TRIGGER_LINE(2),
70 TRIGGER_LINE(3),
71 TRIGGER_LINE(4),
72 TRIGGER_LINE(5),
73 TRIGGER_LINE(6),
74 TRIGGER_LINE(7),
75 NI_CtrSource(0),
76 NI_CtrSource(1),
77 NI_CtrGate(0),
78 NI_CtrGate(1),
79 NI_CtrInternalOutput(0),
80 NI_CtrInternalOutput(1),
81 NI_AI_SampleClock,
82 NI_AI_StartTrigger,
83 NI_AI_ReferenceTrigger,
84 NI_AI_ConvertClock,
85 NI_AO_SampleClock,
86 NI_AO_StartTrigger,
87 NI_DI_SampleClock,
88 NI_DO_SampleClock,
89 NI_FrequencyOutput,
90 NI_ChangeDetectionEvent,
91 0, /* Termination */
92 }
93 },
94 {
95 .dest = NI_PFI(2),
96 .src = (int[]){
97 TRIGGER_LINE(0),
98 TRIGGER_LINE(1),
99 TRIGGER_LINE(2),
100 TRIGGER_LINE(3),
101 TRIGGER_LINE(4),
102 TRIGGER_LINE(5),
103 TRIGGER_LINE(6),
104 TRIGGER_LINE(7),
105 NI_CtrSource(0),
106 NI_CtrSource(1),
107 NI_CtrGate(0),
108 NI_CtrGate(1),
109 NI_CtrInternalOutput(0),
110 NI_CtrInternalOutput(1),
111 NI_AI_SampleClock,
112 NI_AI_StartTrigger,
113 NI_AI_ReferenceTrigger,
114 NI_AI_ConvertClock,
115 NI_AO_SampleClock,
116 NI_AO_StartTrigger,
117 NI_DI_SampleClock,
118 NI_DO_SampleClock,
119 NI_FrequencyOutput,
120 NI_ChangeDetectionEvent,
121 0, /* Termination */
122 }
123 },
124 {
125 .dest = NI_PFI(3),
126 .src = (int[]){
127 TRIGGER_LINE(0),
128 TRIGGER_LINE(1),
129 TRIGGER_LINE(2),
130 TRIGGER_LINE(3),
131 TRIGGER_LINE(4),
132 TRIGGER_LINE(5),
133 TRIGGER_LINE(6),
134 TRIGGER_LINE(7),
135 NI_CtrSource(0),
136 NI_CtrSource(1),
137 NI_CtrGate(0),
138 NI_CtrGate(1),
139 NI_CtrInternalOutput(0),
140 NI_CtrInternalOutput(1),
141 NI_AI_SampleClock,
142 NI_AI_StartTrigger,
143 NI_AI_ReferenceTrigger,
144 NI_AI_ConvertClock,
145 NI_AO_SampleClock,
146 NI_AO_StartTrigger,
147 NI_DI_SampleClock,
148 NI_DO_SampleClock,
149 NI_FrequencyOutput,
150 NI_ChangeDetectionEvent,
151 0, /* Termination */
152 }
153 },
154 {
155 .dest = NI_PFI(4),
156 .src = (int[]){
157 TRIGGER_LINE(0),
158 TRIGGER_LINE(1),
159 TRIGGER_LINE(2),
160 TRIGGER_LINE(3),
161 TRIGGER_LINE(4),
162 TRIGGER_LINE(5),
163 TRIGGER_LINE(6),
164 TRIGGER_LINE(7),
165 NI_CtrSource(0),
166 NI_CtrSource(1),
167 NI_CtrGate(0),
168 NI_CtrGate(1),
169 NI_CtrInternalOutput(0),
170 NI_CtrInternalOutput(1),
171 NI_AI_SampleClock,
172 NI_AI_StartTrigger,
173 NI_AI_ReferenceTrigger,
174 NI_AI_ConvertClock,
175 NI_AO_SampleClock,
176 NI_AO_StartTrigger,
177 NI_DI_SampleClock,
178 NI_DO_SampleClock,
179 NI_FrequencyOutput,
180 NI_ChangeDetectionEvent,
181 0, /* Termination */
182 }
183 },
184 {
185 .dest = NI_PFI(5),
186 .src = (int[]){
187 TRIGGER_LINE(0),
188 TRIGGER_LINE(1),
189 TRIGGER_LINE(2),
190 TRIGGER_LINE(3),
191 TRIGGER_LINE(4),
192 TRIGGER_LINE(5),
193 TRIGGER_LINE(6),
194 TRIGGER_LINE(7),
195 NI_CtrSource(0),
196 NI_CtrSource(1),
197 NI_CtrGate(0),
198 NI_CtrGate(1),
199 NI_CtrInternalOutput(0),
200 NI_CtrInternalOutput(1),
201 NI_AI_SampleClock,
202 NI_AI_StartTrigger,
203 NI_AI_ReferenceTrigger,
204 NI_AI_ConvertClock,
205 NI_AO_SampleClock,
206 NI_AO_StartTrigger,
207 NI_DI_SampleClock,
208 NI_DO_SampleClock,
209 NI_FrequencyOutput,
210 NI_ChangeDetectionEvent,
211 0, /* Termination */
212 }
213 },
214 {
215 .dest = NI_PFI(6),
216 .src = (int[]){
217 TRIGGER_LINE(0),
218 TRIGGER_LINE(1),
219 TRIGGER_LINE(2),
220 TRIGGER_LINE(3),
221 TRIGGER_LINE(4),
222 TRIGGER_LINE(5),
223 TRIGGER_LINE(6),
224 TRIGGER_LINE(7),
225 NI_CtrSource(0),
226 NI_CtrSource(1),
227 NI_CtrGate(0),
228 NI_CtrGate(1),
229 NI_CtrInternalOutput(0),
230 NI_CtrInternalOutput(1),
231 NI_AI_SampleClock,
232 NI_AI_StartTrigger,
233 NI_AI_ReferenceTrigger,
234 NI_AI_ConvertClock,
235 NI_AO_SampleClock,
236 NI_AO_StartTrigger,
237 NI_DI_SampleClock,
238 NI_DO_SampleClock,
239 NI_FrequencyOutput,
240 NI_ChangeDetectionEvent,
241 0, /* Termination */
242 }
243 },
244 {
245 .dest = NI_PFI(7),
246 .src = (int[]){
247 TRIGGER_LINE(0),
248 TRIGGER_LINE(1),
249 TRIGGER_LINE(2),
250 TRIGGER_LINE(3),
251 TRIGGER_LINE(4),
252 TRIGGER_LINE(5),
253 TRIGGER_LINE(6),
254 TRIGGER_LINE(7),
255 NI_CtrSource(0),
256 NI_CtrSource(1),
257 NI_CtrGate(0),
258 NI_CtrGate(1),
259 NI_CtrInternalOutput(0),
260 NI_CtrInternalOutput(1),
261 NI_AI_SampleClock,
262 NI_AI_StartTrigger,
263 NI_AI_ReferenceTrigger,
264 NI_AI_ConvertClock,
265 NI_AO_SampleClock,
266 NI_AO_StartTrigger,
267 NI_DI_SampleClock,
268 NI_DO_SampleClock,
269 NI_FrequencyOutput,
270 NI_ChangeDetectionEvent,
271 0, /* Termination */
272 }
273 },
274 {
275 .dest = NI_PFI(8),
276 .src = (int[]){
277 TRIGGER_LINE(0),
278 TRIGGER_LINE(1),
279 TRIGGER_LINE(2),
280 TRIGGER_LINE(3),
281 TRIGGER_LINE(4),
282 TRIGGER_LINE(5),
283 TRIGGER_LINE(6),
284 TRIGGER_LINE(7),
285 NI_CtrSource(0),
286 NI_CtrSource(1),
287 NI_CtrGate(0),
288 NI_CtrGate(1),
289 NI_CtrInternalOutput(0),
290 NI_CtrInternalOutput(1),
291 NI_AI_SampleClock,
292 NI_AI_StartTrigger,
293 NI_AI_ReferenceTrigger,
294 NI_AI_ConvertClock,
295 NI_AO_SampleClock,
296 NI_AO_StartTrigger,
297 NI_DI_SampleClock,
298 NI_DO_SampleClock,
299 NI_FrequencyOutput,
300 NI_ChangeDetectionEvent,
301 0, /* Termination */
302 }
303 },
304 {
305 .dest = NI_PFI(9),
306 .src = (int[]){
307 TRIGGER_LINE(0),
308 TRIGGER_LINE(1),
309 TRIGGER_LINE(2),
310 TRIGGER_LINE(3),
311 TRIGGER_LINE(4),
312 TRIGGER_LINE(5),
313 TRIGGER_LINE(6),
314 TRIGGER_LINE(7),
315 NI_CtrSource(0),
316 NI_CtrSource(1),
317 NI_CtrGate(0),
318 NI_CtrGate(1),
319 NI_CtrInternalOutput(0),
320 NI_CtrInternalOutput(1),
321 NI_AI_SampleClock,
322 NI_AI_StartTrigger,
323 NI_AI_ReferenceTrigger,
324 NI_AI_ConvertClock,
325 NI_AO_SampleClock,
326 NI_AO_StartTrigger,
327 NI_DI_SampleClock,
328 NI_DO_SampleClock,
329 NI_FrequencyOutput,
330 NI_ChangeDetectionEvent,
331 0, /* Termination */
332 }
333 },
334 {
335 .dest = NI_PFI(10),
336 .src = (int[]){
337 TRIGGER_LINE(0),
338 TRIGGER_LINE(1),
339 TRIGGER_LINE(2),
340 TRIGGER_LINE(3),
341 TRIGGER_LINE(4),
342 TRIGGER_LINE(5),
343 TRIGGER_LINE(6),
344 TRIGGER_LINE(7),
345 NI_CtrSource(0),
346 NI_CtrSource(1),
347 NI_CtrGate(0),
348 NI_CtrGate(1),
349 NI_CtrInternalOutput(0),
350 NI_CtrInternalOutput(1),
351 NI_AI_SampleClock,
352 NI_AI_StartTrigger,
353 NI_AI_ReferenceTrigger,
354 NI_AI_ConvertClock,
355 NI_AO_SampleClock,
356 NI_AO_StartTrigger,
357 NI_DI_SampleClock,
358 NI_DO_SampleClock,
359 NI_FrequencyOutput,
360 NI_ChangeDetectionEvent,
361 0, /* Termination */
362 }
363 },
364 {
365 .dest = NI_PFI(11),
366 .src = (int[]){
367 TRIGGER_LINE(0),
368 TRIGGER_LINE(1),
369 TRIGGER_LINE(2),
370 TRIGGER_LINE(3),
371 TRIGGER_LINE(4),
372 TRIGGER_LINE(5),
373 TRIGGER_LINE(6),
374 TRIGGER_LINE(7),
375 NI_CtrSource(0),
376 NI_CtrSource(1),
377 NI_CtrGate(0),
378 NI_CtrGate(1),
379 NI_CtrInternalOutput(0),
380 NI_CtrInternalOutput(1),
381 NI_AI_SampleClock,
382 NI_AI_StartTrigger,
383 NI_AI_ReferenceTrigger,
384 NI_AI_ConvertClock,
385 NI_AO_SampleClock,
386 NI_AO_StartTrigger,
387 NI_DI_SampleClock,
388 NI_DO_SampleClock,
389 NI_FrequencyOutput,
390 NI_ChangeDetectionEvent,
391 0, /* Termination */
392 }
393 },
394 {
395 .dest = NI_PFI(12),
396 .src = (int[]){
397 TRIGGER_LINE(0),
398 TRIGGER_LINE(1),
399 TRIGGER_LINE(2),
400 TRIGGER_LINE(3),
401 TRIGGER_LINE(4),
402 TRIGGER_LINE(5),
403 TRIGGER_LINE(6),
404 TRIGGER_LINE(7),
405 NI_CtrSource(0),
406 NI_CtrSource(1),
407 NI_CtrGate(0),
408 NI_CtrGate(1),
409 NI_CtrInternalOutput(0),
410 NI_CtrInternalOutput(1),
411 NI_AI_SampleClock,
412 NI_AI_StartTrigger,
413 NI_AI_ReferenceTrigger,
414 NI_AI_ConvertClock,
415 NI_AO_SampleClock,
416 NI_AO_StartTrigger,
417 NI_DI_SampleClock,
418 NI_DO_SampleClock,
419 NI_FrequencyOutput,
420 NI_ChangeDetectionEvent,
421 0, /* Termination */
422 }
423 },
424 {
425 .dest = NI_PFI(13),
426 .src = (int[]){
427 TRIGGER_LINE(0),
428 TRIGGER_LINE(1),
429 TRIGGER_LINE(2),
430 TRIGGER_LINE(3),
431 TRIGGER_LINE(4),
432 TRIGGER_LINE(5),
433 TRIGGER_LINE(6),
434 TRIGGER_LINE(7),
435 NI_CtrSource(0),
436 NI_CtrSource(1),
437 NI_CtrGate(0),
438 NI_CtrGate(1),
439 NI_CtrInternalOutput(0),
440 NI_CtrInternalOutput(1),
441 NI_AI_SampleClock,
442 NI_AI_StartTrigger,
443 NI_AI_ReferenceTrigger,
444 NI_AI_ConvertClock,
445 NI_AO_SampleClock,
446 NI_AO_StartTrigger,
447 NI_DI_SampleClock,
448 NI_DO_SampleClock,
449 NI_FrequencyOutput,
450 NI_ChangeDetectionEvent,
451 0, /* Termination */
452 }
453 },
454 {
455 .dest = NI_PFI(14),
456 .src = (int[]){
457 TRIGGER_LINE(0),
458 TRIGGER_LINE(1),
459 TRIGGER_LINE(2),
460 TRIGGER_LINE(3),
461 TRIGGER_LINE(4),
462 TRIGGER_LINE(5),
463 TRIGGER_LINE(6),
464 TRIGGER_LINE(7),
465 NI_CtrSource(0),
466 NI_CtrSource(1),
467 NI_CtrGate(0),
468 NI_CtrGate(1),
469 NI_CtrInternalOutput(0),
470 NI_CtrInternalOutput(1),
471 NI_AI_SampleClock,
472 NI_AI_StartTrigger,
473 NI_AI_ReferenceTrigger,
474 NI_AI_ConvertClock,
475 NI_AO_SampleClock,
476 NI_AO_StartTrigger,
477 NI_DI_SampleClock,
478 NI_DO_SampleClock,
479 NI_FrequencyOutput,
480 NI_ChangeDetectionEvent,
481 0, /* Termination */
482 }
483 },
484 {
485 .dest = NI_PFI(15),
486 .src = (int[]){
487 TRIGGER_LINE(0),
488 TRIGGER_LINE(1),
489 TRIGGER_LINE(2),
490 TRIGGER_LINE(3),
491 TRIGGER_LINE(4),
492 TRIGGER_LINE(5),
493 TRIGGER_LINE(6),
494 TRIGGER_LINE(7),
495 NI_CtrSource(0),
496 NI_CtrSource(1),
497 NI_CtrGate(0),
498 NI_CtrGate(1),
499 NI_CtrInternalOutput(0),
500 NI_CtrInternalOutput(1),
501 NI_AI_SampleClock,
502 NI_AI_StartTrigger,
503 NI_AI_ReferenceTrigger,
504 NI_AI_ConvertClock,
505 NI_AO_SampleClock,
506 NI_AO_StartTrigger,
507 NI_DI_SampleClock,
508 NI_DO_SampleClock,
509 NI_FrequencyOutput,
510 NI_ChangeDetectionEvent,
511 0, /* Termination */
512 }
513 },
514 {
515 .dest = TRIGGER_LINE(0),
516 .src = (int[]){
517 NI_PFI(0),
518 NI_PFI(1),
519 NI_PFI(2),
520 NI_PFI(3),
521 NI_PFI(4),
522 NI_PFI(5),
523 NI_CtrSource(0),
524 NI_CtrSource(1),
525 NI_CtrGate(0),
526 NI_CtrGate(1),
527 NI_CtrInternalOutput(0),
528 NI_CtrInternalOutput(1),
529 NI_AI_SampleClock,
530 NI_AI_StartTrigger,
531 NI_AI_ReferenceTrigger,
532 NI_AI_ConvertClock,
533 NI_AI_PauseTrigger,
534 NI_AO_SampleClock,
535 NI_AO_StartTrigger,
536 NI_AO_PauseTrigger,
537 NI_10MHzRefClock,
538 NI_FrequencyOutput,
539 NI_ChangeDetectionEvent,
540 0, /* Termination */
541 }
542 },
543 {
544 .dest = TRIGGER_LINE(1),
545 .src = (int[]){
546 NI_PFI(0),
547 NI_PFI(1),
548 NI_PFI(2),
549 NI_PFI(3),
550 NI_PFI(4),
551 NI_PFI(5),
552 NI_CtrSource(0),
553 NI_CtrSource(1),
554 NI_CtrGate(0),
555 NI_CtrGate(1),
556 NI_CtrInternalOutput(0),
557 NI_CtrInternalOutput(1),
558 NI_AI_SampleClock,
559 NI_AI_StartTrigger,
560 NI_AI_ReferenceTrigger,
561 NI_AI_ConvertClock,
562 NI_AI_PauseTrigger,
563 NI_AO_SampleClock,
564 NI_AO_StartTrigger,
565 NI_AO_PauseTrigger,
566 NI_10MHzRefClock,
567 NI_FrequencyOutput,
568 NI_ChangeDetectionEvent,
569 0, /* Termination */
570 }
571 },
572 {
573 .dest = TRIGGER_LINE(2),
574 .src = (int[]){
575 NI_PFI(0),
576 NI_PFI(1),
577 NI_PFI(2),
578 NI_PFI(3),
579 NI_PFI(4),
580 NI_PFI(5),
581 NI_CtrSource(0),
582 NI_CtrSource(1),
583 NI_CtrGate(0),
584 NI_CtrGate(1),
585 NI_CtrInternalOutput(0),
586 NI_CtrInternalOutput(1),
587 NI_AI_SampleClock,
588 NI_AI_StartTrigger,
589 NI_AI_ReferenceTrigger,
590 NI_AI_ConvertClock,
591 NI_AI_PauseTrigger,
592 NI_AO_SampleClock,
593 NI_AO_StartTrigger,
594 NI_AO_PauseTrigger,
595 NI_10MHzRefClock,
596 NI_FrequencyOutput,
597 NI_ChangeDetectionEvent,
598 0, /* Termination */
599 }
600 },
601 {
602 .dest = TRIGGER_LINE(3),
603 .src = (int[]){
604 NI_PFI(0),
605 NI_PFI(1),
606 NI_PFI(2),
607 NI_PFI(3),
608 NI_PFI(4),
609 NI_PFI(5),
610 NI_CtrSource(0),
611 NI_CtrSource(1),
612 NI_CtrGate(0),
613 NI_CtrGate(1),
614 NI_CtrInternalOutput(0),
615 NI_CtrInternalOutput(1),
616 NI_AI_SampleClock,
617 NI_AI_StartTrigger,
618 NI_AI_ReferenceTrigger,
619 NI_AI_ConvertClock,
620 NI_AI_PauseTrigger,
621 NI_AO_SampleClock,
622 NI_AO_StartTrigger,
623 NI_AO_PauseTrigger,
624 NI_10MHzRefClock,
625 NI_FrequencyOutput,
626 NI_ChangeDetectionEvent,
627 0, /* Termination */
628 }
629 },
630 {
631 .dest = TRIGGER_LINE(4),
632 .src = (int[]){
633 NI_PFI(0),
634 NI_PFI(1),
635 NI_PFI(2),
636 NI_PFI(3),
637 NI_PFI(4),
638 NI_PFI(5),
639 NI_CtrSource(0),
640 NI_CtrSource(1),
641 NI_CtrGate(0),
642 NI_CtrGate(1),
643 NI_CtrInternalOutput(0),
644 NI_CtrInternalOutput(1),
645 NI_AI_SampleClock,
646 NI_AI_StartTrigger,
647 NI_AI_ReferenceTrigger,
648 NI_AI_ConvertClock,
649 NI_AI_PauseTrigger,
650 NI_AO_SampleClock,
651 NI_AO_StartTrigger,
652 NI_AO_PauseTrigger,
653 NI_10MHzRefClock,
654 NI_FrequencyOutput,
655 NI_ChangeDetectionEvent,
656 0, /* Termination */
657 }
658 },
659 {
660 .dest = TRIGGER_LINE(5),
661 .src = (int[]){
662 NI_PFI(0),
663 NI_PFI(1),
664 NI_PFI(2),
665 NI_PFI(3),
666 NI_PFI(4),
667 NI_PFI(5),
668 NI_CtrSource(0),
669 NI_CtrSource(1),
670 NI_CtrGate(0),
671 NI_CtrGate(1),
672 NI_CtrInternalOutput(0),
673 NI_CtrInternalOutput(1),
674 NI_AI_SampleClock,
675 NI_AI_StartTrigger,
676 NI_AI_ReferenceTrigger,
677 NI_AI_ConvertClock,
678 NI_AI_PauseTrigger,
679 NI_AO_SampleClock,
680 NI_AO_StartTrigger,
681 NI_AO_PauseTrigger,
682 NI_10MHzRefClock,
683 NI_FrequencyOutput,
684 NI_ChangeDetectionEvent,
685 0, /* Termination */
686 }
687 },
688 {
689 .dest = TRIGGER_LINE(6),
690 .src = (int[]){
691 NI_PFI(0),
692 NI_PFI(1),
693 NI_PFI(2),
694 NI_PFI(3),
695 NI_PFI(4),
696 NI_PFI(5),
697 NI_CtrSource(0),
698 NI_CtrSource(1),
699 NI_CtrGate(0),
700 NI_CtrGate(1),
701 NI_CtrInternalOutput(0),
702 NI_CtrInternalOutput(1),
703 NI_AI_SampleClock,
704 NI_AI_StartTrigger,
705 NI_AI_ReferenceTrigger,
706 NI_AI_ConvertClock,
707 NI_AI_PauseTrigger,
708 NI_AO_SampleClock,
709 NI_AO_StartTrigger,
710 NI_AO_PauseTrigger,
711 NI_10MHzRefClock,
712 NI_FrequencyOutput,
713 NI_ChangeDetectionEvent,
714 0, /* Termination */
715 }
716 },
717 {
718 .dest = TRIGGER_LINE(7),
719 .src = (int[]){
720 NI_PFI(0),
721 NI_PFI(1),
722 NI_PFI(2),
723 NI_PFI(3),
724 NI_PFI(4),
725 NI_PFI(5),
726 NI_CtrSource(0),
727 NI_CtrSource(1),
728 NI_CtrGate(0),
729 NI_CtrGate(1),
730 NI_CtrInternalOutput(0),
731 NI_CtrInternalOutput(1),
732 NI_AI_SampleClock,
733 NI_AI_StartTrigger,
734 NI_AI_ReferenceTrigger,
735 NI_AI_ConvertClock,
736 NI_AI_PauseTrigger,
737 NI_AO_SampleClock,
738 NI_AO_StartTrigger,
739 NI_AO_PauseTrigger,
740 NI_10MHzRefClock,
741 NI_FrequencyOutput,
742 NI_ChangeDetectionEvent,
743 0, /* Termination */
744 }
745 },
746 {
747 .dest = NI_CtrSource(0),
748 .src = (int[]){
749 NI_PFI(0),
750 NI_PFI(1),
751 NI_PFI(2),
752 NI_PFI(3),
753 NI_PFI(4),
754 NI_PFI(5),
755 NI_PFI(6),
756 NI_PFI(7),
757 NI_PFI(8),
758 NI_PFI(9),
759 NI_PFI(10),
760 NI_PFI(11),
761 NI_PFI(12),
762 NI_PFI(13),
763 NI_PFI(14),
764 NI_PFI(15),
765 TRIGGER_LINE(0),
766 TRIGGER_LINE(1),
767 TRIGGER_LINE(2),
768 TRIGGER_LINE(3),
769 TRIGGER_LINE(4),
770 TRIGGER_LINE(5),
771 TRIGGER_LINE(6),
772 TRIGGER_LINE(7),
773 NI_CtrGate(1),
774 NI_20MHzTimebase,
775 NI_80MHzTimebase,
776 NI_100kHzTimebase,
777 0, /* Termination */
778 }
779 },
780 {
781 .dest = NI_CtrSource(1),
782 .src = (int[]){
783 NI_PFI(0),
784 NI_PFI(1),
785 NI_PFI(2),
786 NI_PFI(3),
787 NI_PFI(4),
788 NI_PFI(5),
789 NI_PFI(6),
790 NI_PFI(7),
791 NI_PFI(8),
792 NI_PFI(9),
793 NI_PFI(10),
794 NI_PFI(11),
795 NI_PFI(12),
796 NI_PFI(13),
797 NI_PFI(14),
798 NI_PFI(15),
799 TRIGGER_LINE(0),
800 TRIGGER_LINE(1),
801 TRIGGER_LINE(2),
802 TRIGGER_LINE(3),
803 TRIGGER_LINE(4),
804 TRIGGER_LINE(5),
805 TRIGGER_LINE(6),
806 TRIGGER_LINE(7),
807 NI_CtrGate(0),
808 NI_20MHzTimebase,
809 NI_80MHzTimebase,
810 NI_100kHzTimebase,
811 0, /* Termination */
812 }
813 },
814 {
815 .dest = NI_CtrGate(0),
816 .src = (int[]){
817 NI_PFI(0),
818 NI_PFI(1),
819 NI_PFI(2),
820 NI_PFI(3),
821 NI_PFI(4),
822 NI_PFI(5),
823 NI_PFI(6),
824 NI_PFI(7),
825 NI_PFI(8),
826 NI_PFI(9),
827 NI_PFI(10),
828 NI_PFI(11),
829 NI_PFI(12),
830 NI_PFI(13),
831 NI_PFI(14),
832 NI_PFI(15),
833 TRIGGER_LINE(0),
834 TRIGGER_LINE(1),
835 TRIGGER_LINE(2),
836 TRIGGER_LINE(3),
837 TRIGGER_LINE(4),
838 TRIGGER_LINE(5),
839 TRIGGER_LINE(6),
840 TRIGGER_LINE(7),
841 NI_CtrSource(1),
842 NI_CtrInternalOutput(1),
843 NI_AI_StartTrigger,
844 NI_AI_ReferenceTrigger,
845 0, /* Termination */
846 }
847 },
848 {
849 .dest = NI_CtrGate(1),
850 .src = (int[]){
851 NI_PFI(0),
852 NI_PFI(1),
853 NI_PFI(2),
854 NI_PFI(3),
855 NI_PFI(4),
856 NI_PFI(5),
857 NI_PFI(6),
858 NI_PFI(7),
859 NI_PFI(8),
860 NI_PFI(9),
861 NI_PFI(10),
862 NI_PFI(11),
863 NI_PFI(12),
864 NI_PFI(13),
865 NI_PFI(14),
866 NI_PFI(15),
867 TRIGGER_LINE(0),
868 TRIGGER_LINE(1),
869 TRIGGER_LINE(2),
870 TRIGGER_LINE(3),
871 TRIGGER_LINE(4),
872 TRIGGER_LINE(5),
873 TRIGGER_LINE(6),
874 TRIGGER_LINE(7),
875 NI_CtrSource(0),
876 NI_CtrInternalOutput(0),
877 NI_AI_StartTrigger,
878 NI_AI_ReferenceTrigger,
879 0, /* Termination */
880 }
881 },
882 {
883 .dest = NI_CtrAux(0),
884 .src = (int[]){
885 NI_PFI(0),
886 NI_PFI(1),
887 NI_PFI(2),
888 NI_PFI(3),
889 NI_PFI(4),
890 NI_PFI(5),
891 NI_PFI(6),
892 NI_PFI(7),
893 NI_PFI(8),
894 NI_PFI(9),
895 NI_PFI(10),
896 NI_PFI(11),
897 NI_PFI(12),
898 NI_PFI(13),
899 NI_PFI(14),
900 NI_PFI(15),
901 TRIGGER_LINE(0),
902 TRIGGER_LINE(1),
903 TRIGGER_LINE(2),
904 TRIGGER_LINE(3),
905 TRIGGER_LINE(4),
906 TRIGGER_LINE(5),
907 TRIGGER_LINE(6),
908 TRIGGER_LINE(7),
909 NI_CtrSource(1),
910 NI_CtrGate(0),
911 NI_CtrGate(1),
912 NI_CtrInternalOutput(1),
913 NI_AI_StartTrigger,
914 NI_AI_ReferenceTrigger,
915 0, /* Termination */
916 }
917 },
918 {
919 .dest = NI_CtrAux(1),
920 .src = (int[]){
921 NI_PFI(0),
922 NI_PFI(1),
923 NI_PFI(2),
924 NI_PFI(3),
925 NI_PFI(4),
926 NI_PFI(5),
927 NI_PFI(6),
928 NI_PFI(7),
929 NI_PFI(8),
930 NI_PFI(9),
931 NI_PFI(10),
932 NI_PFI(11),
933 NI_PFI(12),
934 NI_PFI(13),
935 NI_PFI(14),
936 NI_PFI(15),
937 TRIGGER_LINE(0),
938 TRIGGER_LINE(1),
939 TRIGGER_LINE(2),
940 TRIGGER_LINE(3),
941 TRIGGER_LINE(4),
942 TRIGGER_LINE(5),
943 TRIGGER_LINE(6),
944 TRIGGER_LINE(7),
945 NI_CtrSource(0),
946 NI_CtrGate(0),
947 NI_CtrGate(1),
948 NI_CtrInternalOutput(0),
949 NI_AI_StartTrigger,
950 NI_AI_ReferenceTrigger,
951 0, /* Termination */
952 }
953 },
954 {
955 .dest = NI_CtrA(0),
956 .src = (int[]){
957 NI_PFI(0),
958 NI_PFI(1),
959 NI_PFI(2),
960 NI_PFI(3),
961 NI_PFI(4),
962 NI_PFI(5),
963 NI_PFI(6),
964 NI_PFI(7),
965 NI_PFI(8),
966 NI_PFI(9),
967 NI_PFI(10),
968 NI_PFI(11),
969 NI_PFI(12),
970 NI_PFI(13),
971 NI_PFI(14),
972 NI_PFI(15),
973 TRIGGER_LINE(0),
974 TRIGGER_LINE(1),
975 TRIGGER_LINE(2),
976 TRIGGER_LINE(3),
977 TRIGGER_LINE(4),
978 TRIGGER_LINE(5),
979 TRIGGER_LINE(6),
980 TRIGGER_LINE(7),
981 0, /* Termination */
982 }
983 },
984 {
985 .dest = NI_CtrA(1),
986 .src = (int[]){
987 NI_PFI(0),
988 NI_PFI(1),
989 NI_PFI(2),
990 NI_PFI(3),
991 NI_PFI(4),
992 NI_PFI(5),
993 NI_PFI(6),
994 NI_PFI(7),
995 NI_PFI(8),
996 NI_PFI(9),
997 NI_PFI(10),
998 NI_PFI(11),
999 NI_PFI(12),
1000 NI_PFI(13),
1001 NI_PFI(14),
1002 NI_PFI(15),
1003 TRIGGER_LINE(0),
1004 TRIGGER_LINE(1),
1005 TRIGGER_LINE(2),
1006 TRIGGER_LINE(3),
1007 TRIGGER_LINE(4),
1008 TRIGGER_LINE(5),
1009 TRIGGER_LINE(6),
1010 TRIGGER_LINE(7),
1011 0, /* Termination */
1012 }
1013 },
1014 {
1015 .dest = NI_CtrB(0),
1016 .src = (int[]){
1017 NI_PFI(0),
1018 NI_PFI(1),
1019 NI_PFI(2),
1020 NI_PFI(3),
1021 NI_PFI(4),
1022 NI_PFI(5),
1023 NI_PFI(6),
1024 NI_PFI(7),
1025 NI_PFI(8),
1026 NI_PFI(9),
1027 NI_PFI(10),
1028 NI_PFI(11),
1029 NI_PFI(12),
1030 NI_PFI(13),
1031 NI_PFI(14),
1032 NI_PFI(15),
1033 TRIGGER_LINE(0),
1034 TRIGGER_LINE(1),
1035 TRIGGER_LINE(2),
1036 TRIGGER_LINE(3),
1037 TRIGGER_LINE(4),
1038 TRIGGER_LINE(5),
1039 TRIGGER_LINE(6),
1040 TRIGGER_LINE(7),
1041 0, /* Termination */
1042 }
1043 },
1044 {
1045 .dest = NI_CtrB(1),
1046 .src = (int[]){
1047 NI_PFI(0),
1048 NI_PFI(1),
1049 NI_PFI(2),
1050 NI_PFI(3),
1051 NI_PFI(4),
1052 NI_PFI(5),
1053 NI_PFI(6),
1054 NI_PFI(7),
1055 NI_PFI(8),
1056 NI_PFI(9),
1057 NI_PFI(10),
1058 NI_PFI(11),
1059 NI_PFI(12),
1060 NI_PFI(13),
1061 NI_PFI(14),
1062 NI_PFI(15),
1063 TRIGGER_LINE(0),
1064 TRIGGER_LINE(1),
1065 TRIGGER_LINE(2),
1066 TRIGGER_LINE(3),
1067 TRIGGER_LINE(4),
1068 TRIGGER_LINE(5),
1069 TRIGGER_LINE(6),
1070 TRIGGER_LINE(7),
1071 0, /* Termination */
1072 }
1073 },
1074 {
1075 .dest = NI_CtrZ(0),
1076 .src = (int[]){
1077 NI_PFI(0),
1078 NI_PFI(1),
1079 NI_PFI(2),
1080 NI_PFI(3),
1081 NI_PFI(4),
1082 NI_PFI(5),
1083 NI_PFI(6),
1084 NI_PFI(7),
1085 NI_PFI(8),
1086 NI_PFI(9),
1087 NI_PFI(10),
1088 NI_PFI(11),
1089 NI_PFI(12),
1090 NI_PFI(13),
1091 NI_PFI(14),
1092 NI_PFI(15),
1093 TRIGGER_LINE(0),
1094 TRIGGER_LINE(1),
1095 TRIGGER_LINE(2),
1096 TRIGGER_LINE(3),
1097 TRIGGER_LINE(4),
1098 TRIGGER_LINE(5),
1099 TRIGGER_LINE(6),
1100 TRIGGER_LINE(7),
1101 0, /* Termination */
1102 }
1103 },
1104 {
1105 .dest = NI_CtrZ(1),
1106 .src = (int[]){
1107 NI_PFI(0),
1108 NI_PFI(1),
1109 NI_PFI(2),
1110 NI_PFI(3),
1111 NI_PFI(4),
1112 NI_PFI(5),
1113 NI_PFI(6),
1114 NI_PFI(7),
1115 NI_PFI(8),
1116 NI_PFI(9),
1117 NI_PFI(10),
1118 NI_PFI(11),
1119 NI_PFI(12),
1120 NI_PFI(13),
1121 NI_PFI(14),
1122 NI_PFI(15),
1123 TRIGGER_LINE(0),
1124 TRIGGER_LINE(1),
1125 TRIGGER_LINE(2),
1126 TRIGGER_LINE(3),
1127 TRIGGER_LINE(4),
1128 TRIGGER_LINE(5),
1129 TRIGGER_LINE(6),
1130 TRIGGER_LINE(7),
1131 0, /* Termination */
1132 }
1133 },
1134 {
1135 .dest = NI_CtrArmStartTrigger(0),
1136 .src = (int[]){
1137 NI_PFI(0),
1138 NI_PFI(1),
1139 NI_PFI(2),
1140 NI_PFI(3),
1141 NI_PFI(4),
1142 NI_PFI(5),
1143 NI_PFI(6),
1144 NI_PFI(7),
1145 NI_PFI(8),
1146 NI_PFI(9),
1147 NI_PFI(10),
1148 NI_PFI(11),
1149 NI_PFI(12),
1150 NI_PFI(13),
1151 NI_PFI(14),
1152 NI_PFI(15),
1153 TRIGGER_LINE(0),
1154 TRIGGER_LINE(1),
1155 TRIGGER_LINE(2),
1156 TRIGGER_LINE(3),
1157 TRIGGER_LINE(4),
1158 TRIGGER_LINE(5),
1159 TRIGGER_LINE(6),
1160 TRIGGER_LINE(7),
1161 NI_CtrInternalOutput(1),
1162 NI_AI_StartTrigger,
1163 NI_AI_ReferenceTrigger,
1164 0, /* Termination */
1165 }
1166 },
1167 {
1168 .dest = NI_CtrArmStartTrigger(1),
1169 .src = (int[]){
1170 NI_PFI(0),
1171 NI_PFI(1),
1172 NI_PFI(2),
1173 NI_PFI(3),
1174 NI_PFI(4),
1175 NI_PFI(5),
1176 NI_PFI(6),
1177 NI_PFI(7),
1178 NI_PFI(8),
1179 NI_PFI(9),
1180 NI_PFI(10),
1181 NI_PFI(11),
1182 NI_PFI(12),
1183 NI_PFI(13),
1184 NI_PFI(14),
1185 NI_PFI(15),
1186 TRIGGER_LINE(0),
1187 TRIGGER_LINE(1),
1188 TRIGGER_LINE(2),
1189 TRIGGER_LINE(3),
1190 TRIGGER_LINE(4),
1191 TRIGGER_LINE(5),
1192 TRIGGER_LINE(6),
1193 TRIGGER_LINE(7),
1194 NI_CtrInternalOutput(0),
1195 NI_AI_StartTrigger,
1196 NI_AI_ReferenceTrigger,
1197 0, /* Termination */
1198 }
1199 },
1200 {
1201 .dest = NI_AI_SampleClock,
1202 .src = (int[]){
1203 NI_PFI(0),
1204 NI_PFI(1),
1205 NI_PFI(2),
1206 NI_PFI(3),
1207 NI_PFI(4),
1208 NI_PFI(5),
1209 NI_PFI(6),
1210 NI_PFI(7),
1211 NI_PFI(8),
1212 NI_PFI(9),
1213 NI_PFI(10),
1214 NI_PFI(11),
1215 NI_PFI(12),
1216 NI_PFI(13),
1217 NI_PFI(14),
1218 NI_PFI(15),
1219 TRIGGER_LINE(0),
1220 TRIGGER_LINE(1),
1221 TRIGGER_LINE(2),
1222 TRIGGER_LINE(3),
1223 TRIGGER_LINE(4),
1224 TRIGGER_LINE(5),
1225 TRIGGER_LINE(6),
1226 TRIGGER_LINE(7),
1227 NI_CtrInternalOutput(0),
1228 NI_CtrInternalOutput(1),
1229 NI_AI_SampleClockTimebase,
1230 0, /* Termination */
1231 }
1232 },
1233 {
1234 .dest = NI_AI_SampleClockTimebase,
1235 .src = (int[]){
1236 NI_PFI(0),
1237 NI_PFI(1),
1238 NI_PFI(2),
1239 NI_PFI(3),
1240 NI_PFI(4),
1241 NI_PFI(5),
1242 NI_PFI(6),
1243 NI_PFI(7),
1244 NI_PFI(8),
1245 NI_PFI(9),
1246 NI_PFI(10),
1247 NI_PFI(11),
1248 NI_PFI(12),
1249 NI_PFI(13),
1250 NI_PFI(14),
1251 NI_PFI(15),
1252 TRIGGER_LINE(0),
1253 TRIGGER_LINE(1),
1254 TRIGGER_LINE(2),
1255 TRIGGER_LINE(3),
1256 TRIGGER_LINE(4),
1257 TRIGGER_LINE(5),
1258 TRIGGER_LINE(6),
1259 TRIGGER_LINE(7),
1260 NI_20MHzTimebase,
1261 NI_100kHzTimebase,
1262 0, /* Termination */
1263 }
1264 },
1265 {
1266 .dest = NI_AI_StartTrigger,
1267 .src = (int[]){
1268 NI_PFI(0),
1269 NI_PFI(1),
1270 NI_PFI(2),
1271 NI_PFI(3),
1272 NI_PFI(4),
1273 NI_PFI(5),
1274 NI_PFI(6),
1275 NI_PFI(7),
1276 NI_PFI(8),
1277 NI_PFI(9),
1278 NI_PFI(10),
1279 NI_PFI(11),
1280 NI_PFI(12),
1281 NI_PFI(13),
1282 NI_PFI(14),
1283 NI_PFI(15),
1284 TRIGGER_LINE(0),
1285 TRIGGER_LINE(1),
1286 TRIGGER_LINE(2),
1287 TRIGGER_LINE(3),
1288 TRIGGER_LINE(4),
1289 TRIGGER_LINE(5),
1290 TRIGGER_LINE(6),
1291 TRIGGER_LINE(7),
1292 NI_CtrInternalOutput(0),
1293 NI_CtrInternalOutput(1),
1294 0, /* Termination */
1295 }
1296 },
1297 {
1298 .dest = NI_AI_ReferenceTrigger,
1299 .src = (int[]){
1300 NI_PFI(0),
1301 NI_PFI(1),
1302 NI_PFI(2),
1303 NI_PFI(3),
1304 NI_PFI(4),
1305 NI_PFI(5),
1306 NI_PFI(6),
1307 NI_PFI(7),
1308 NI_PFI(8),
1309 NI_PFI(9),
1310 NI_PFI(10),
1311 NI_PFI(11),
1312 NI_PFI(12),
1313 NI_PFI(13),
1314 NI_PFI(14),
1315 NI_PFI(15),
1316 TRIGGER_LINE(0),
1317 TRIGGER_LINE(1),
1318 TRIGGER_LINE(2),
1319 TRIGGER_LINE(3),
1320 TRIGGER_LINE(4),
1321 TRIGGER_LINE(5),
1322 TRIGGER_LINE(6),
1323 TRIGGER_LINE(7),
1324 0, /* Termination */
1325 }
1326 },
1327 {
1328 .dest = NI_AI_ConvertClock,
1329 .src = (int[]){
1330 NI_PFI(0),
1331 NI_PFI(1),
1332 NI_PFI(2),
1333 NI_PFI(3),
1334 NI_PFI(4),
1335 NI_PFI(5),
1336 NI_PFI(6),
1337 NI_PFI(7),
1338 NI_PFI(8),
1339 NI_PFI(9),
1340 NI_PFI(10),
1341 NI_PFI(11),
1342 NI_PFI(12),
1343 NI_PFI(13),
1344 NI_PFI(14),
1345 NI_PFI(15),
1346 TRIGGER_LINE(0),
1347 TRIGGER_LINE(1),
1348 TRIGGER_LINE(2),
1349 TRIGGER_LINE(3),
1350 TRIGGER_LINE(4),
1351 TRIGGER_LINE(5),
1352 TRIGGER_LINE(6),
1353 TRIGGER_LINE(7),
1354 NI_CtrInternalOutput(0),
1355 NI_CtrInternalOutput(1),
1356 NI_AI_ConvertClockTimebase,
1357 0, /* Termination */
1358 }
1359 },
1360 {
1361 .dest = NI_AI_ConvertClockTimebase,
1362 .src = (int[]){
1363 NI_AI_SampleClockTimebase,
1364 NI_20MHzTimebase,
1365 0, /* Termination */
1366 }
1367 },
1368 {
1369 .dest = NI_AI_PauseTrigger,
1370 .src = (int[]){
1371 NI_PFI(0),
1372 NI_PFI(1),
1373 NI_PFI(2),
1374 NI_PFI(3),
1375 NI_PFI(4),
1376 NI_PFI(5),
1377 NI_PFI(6),
1378 NI_PFI(7),
1379 NI_PFI(8),
1380 NI_PFI(9),
1381 NI_PFI(10),
1382 NI_PFI(11),
1383 NI_PFI(12),
1384 NI_PFI(13),
1385 NI_PFI(14),
1386 NI_PFI(15),
1387 TRIGGER_LINE(0),
1388 TRIGGER_LINE(1),
1389 TRIGGER_LINE(2),
1390 TRIGGER_LINE(3),
1391 TRIGGER_LINE(4),
1392 TRIGGER_LINE(5),
1393 TRIGGER_LINE(6),
1394 TRIGGER_LINE(7),
1395 0, /* Termination */
1396 }
1397 },
1398 {
1399 .dest = NI_AO_SampleClock,
1400 .src = (int[]){
1401 NI_PFI(0),
1402 NI_PFI(1),
1403 NI_PFI(2),
1404 NI_PFI(3),
1405 NI_PFI(4),
1406 NI_PFI(5),
1407 NI_PFI(6),
1408 NI_PFI(7),
1409 NI_PFI(8),
1410 NI_PFI(9),
1411 NI_PFI(10),
1412 NI_PFI(11),
1413 NI_PFI(12),
1414 NI_PFI(13),
1415 NI_PFI(14),
1416 NI_PFI(15),
1417 TRIGGER_LINE(0),
1418 TRIGGER_LINE(1),
1419 TRIGGER_LINE(2),
1420 TRIGGER_LINE(3),
1421 TRIGGER_LINE(4),
1422 TRIGGER_LINE(5),
1423 TRIGGER_LINE(6),
1424 TRIGGER_LINE(7),
1425 NI_CtrInternalOutput(0),
1426 NI_CtrInternalOutput(1),
1427 NI_AO_SampleClockTimebase,
1428 0, /* Termination */
1429 }
1430 },
1431 {
1432 .dest = NI_AO_SampleClockTimebase,
1433 .src = (int[]){
1434 NI_PFI(0),
1435 NI_PFI(1),
1436 NI_PFI(2),
1437 NI_PFI(3),
1438 NI_PFI(4),
1439 NI_PFI(5),
1440 NI_PFI(6),
1441 NI_PFI(7),
1442 NI_PFI(8),
1443 NI_PFI(9),
1444 NI_PFI(10),
1445 NI_PFI(11),
1446 NI_PFI(12),
1447 NI_PFI(13),
1448 NI_PFI(14),
1449 NI_PFI(15),
1450 TRIGGER_LINE(0),
1451 TRIGGER_LINE(1),
1452 TRIGGER_LINE(2),
1453 TRIGGER_LINE(3),
1454 TRIGGER_LINE(4),
1455 TRIGGER_LINE(5),
1456 TRIGGER_LINE(6),
1457 TRIGGER_LINE(7),
1458 NI_20MHzTimebase,
1459 NI_100kHzTimebase,
1460 0, /* Termination */
1461 }
1462 },
1463 {
1464 .dest = NI_AO_StartTrigger,
1465 .src = (int[]){
1466 NI_PFI(0),
1467 NI_PFI(1),
1468 NI_PFI(2),
1469 NI_PFI(3),
1470 NI_PFI(4),
1471 NI_PFI(5),
1472 NI_PFI(6),
1473 NI_PFI(7),
1474 NI_PFI(8),
1475 NI_PFI(9),
1476 NI_PFI(10),
1477 NI_PFI(11),
1478 NI_PFI(12),
1479 NI_PFI(13),
1480 NI_PFI(14),
1481 NI_PFI(15),
1482 TRIGGER_LINE(0),
1483 TRIGGER_LINE(1),
1484 TRIGGER_LINE(2),
1485 TRIGGER_LINE(3),
1486 TRIGGER_LINE(4),
1487 TRIGGER_LINE(5),
1488 TRIGGER_LINE(6),
1489 TRIGGER_LINE(7),
1490 NI_AI_StartTrigger,
1491 0, /* Termination */
1492 }
1493 },
1494 {
1495 .dest = NI_AO_PauseTrigger,
1496 .src = (int[]){
1497 NI_PFI(0),
1498 NI_PFI(1),
1499 NI_PFI(2),
1500 NI_PFI(3),
1501 NI_PFI(4),
1502 NI_PFI(5),
1503 NI_PFI(6),
1504 NI_PFI(7),
1505 NI_PFI(8),
1506 NI_PFI(9),
1507 NI_PFI(10),
1508 NI_PFI(11),
1509 NI_PFI(12),
1510 NI_PFI(13),
1511 NI_PFI(14),
1512 NI_PFI(15),
1513 TRIGGER_LINE(0),
1514 TRIGGER_LINE(1),
1515 TRIGGER_LINE(2),
1516 TRIGGER_LINE(3),
1517 TRIGGER_LINE(4),
1518 TRIGGER_LINE(5),
1519 TRIGGER_LINE(6),
1520 TRIGGER_LINE(7),
1521 0, /* Termination */
1522 }
1523 },
1524 {
1525 .dest = NI_DI_SampleClock,
1526 .src = (int[]){
1527 NI_PFI(0),
1528 NI_PFI(1),
1529 NI_PFI(2),
1530 NI_PFI(3),
1531 NI_PFI(4),
1532 NI_PFI(5),
1533 NI_PFI(6),
1534 NI_PFI(7),
1535 NI_PFI(8),
1536 NI_PFI(9),
1537 NI_PFI(10),
1538 NI_PFI(11),
1539 NI_PFI(12),
1540 NI_PFI(13),
1541 NI_PFI(14),
1542 NI_PFI(15),
1543 TRIGGER_LINE(0),
1544 TRIGGER_LINE(1),
1545 TRIGGER_LINE(2),
1546 TRIGGER_LINE(3),
1547 TRIGGER_LINE(4),
1548 TRIGGER_LINE(5),
1549 TRIGGER_LINE(6),
1550 TRIGGER_LINE(7),
1551 NI_CtrInternalOutput(0),
1552 NI_CtrInternalOutput(1),
1553 NI_AI_SampleClock,
1554 NI_AI_ConvertClock,
1555 NI_AO_SampleClock,
1556 NI_FrequencyOutput,
1557 NI_ChangeDetectionEvent,
1558 0, /* Termination */
1559 }
1560 },
1561 {
1562 .dest = NI_DO_SampleClock,
1563 .src = (int[]){
1564 NI_PFI(0),
1565 NI_PFI(1),
1566 NI_PFI(2),
1567 NI_PFI(3),
1568 NI_PFI(4),
1569 NI_PFI(5),
1570 NI_PFI(6),
1571 NI_PFI(7),
1572 NI_PFI(8),
1573 NI_PFI(9),
1574 NI_PFI(10),
1575 NI_PFI(11),
1576 NI_PFI(12),
1577 NI_PFI(13),
1578 NI_PFI(14),
1579 NI_PFI(15),
1580 TRIGGER_LINE(0),
1581 TRIGGER_LINE(1),
1582 TRIGGER_LINE(2),
1583 TRIGGER_LINE(3),
1584 TRIGGER_LINE(4),
1585 TRIGGER_LINE(5),
1586 TRIGGER_LINE(6),
1587 TRIGGER_LINE(7),
1588 NI_CtrInternalOutput(0),
1589 NI_CtrInternalOutput(1),
1590 NI_AI_SampleClock,
1591 NI_AI_ConvertClock,
1592 NI_AO_SampleClock,
1593 NI_FrequencyOutput,
1594 NI_ChangeDetectionEvent,
1595 0, /* Termination */
1596 }
1597 },
1598 { /* Termination of list */
1599 .dest = 0,
1600 },
1601 },
1602};
diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6251.c b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6251.c
new file mode 100644
index 000000000000..645fd1cd2de4
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6251.c
@@ -0,0 +1,1652 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routing/ni_device_routes/pci-6251.c
5 * List of valid routes for specific NI boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21/*
22 * The contents of this file are generated using the tools in
23 * comedi/drivers/ni_routing/tools
24 *
25 * Please use those tools to help maintain the contents of this file.
26 */
27
28#include "../ni_device_routes.h"
29#include "all.h"
30
31struct ni_device_routes ni_pci_6251_device_routes = {
32 .device = "pci-6251",
33 .routes = (struct ni_route_set[]){
34 {
35 .dest = NI_PFI(0),
36 .src = (int[]){
37 TRIGGER_LINE(0),
38 TRIGGER_LINE(1),
39 TRIGGER_LINE(2),
40 TRIGGER_LINE(3),
41 TRIGGER_LINE(4),
42 TRIGGER_LINE(5),
43 TRIGGER_LINE(6),
44 TRIGGER_LINE(7),
45 NI_CtrSource(0),
46 NI_CtrSource(1),
47 NI_CtrGate(0),
48 NI_CtrGate(1),
49 NI_CtrInternalOutput(0),
50 NI_CtrInternalOutput(1),
51 NI_AI_SampleClock,
52 NI_AI_StartTrigger,
53 NI_AI_ReferenceTrigger,
54 NI_AI_ConvertClock,
55 NI_AO_SampleClock,
56 NI_AO_StartTrigger,
57 NI_DI_SampleClock,
58 NI_DO_SampleClock,
59 NI_FrequencyOutput,
60 NI_ChangeDetectionEvent,
61 NI_AnalogComparisonEvent,
62 0, /* Termination */
63 }
64 },
65 {
66 .dest = NI_PFI(1),
67 .src = (int[]){
68 TRIGGER_LINE(0),
69 TRIGGER_LINE(1),
70 TRIGGER_LINE(2),
71 TRIGGER_LINE(3),
72 TRIGGER_LINE(4),
73 TRIGGER_LINE(5),
74 TRIGGER_LINE(6),
75 TRIGGER_LINE(7),
76 NI_CtrSource(0),
77 NI_CtrSource(1),
78 NI_CtrGate(0),
79 NI_CtrGate(1),
80 NI_CtrInternalOutput(0),
81 NI_CtrInternalOutput(1),
82 NI_AI_SampleClock,
83 NI_AI_StartTrigger,
84 NI_AI_ReferenceTrigger,
85 NI_AI_ConvertClock,
86 NI_AO_SampleClock,
87 NI_AO_StartTrigger,
88 NI_DI_SampleClock,
89 NI_DO_SampleClock,
90 NI_FrequencyOutput,
91 NI_ChangeDetectionEvent,
92 NI_AnalogComparisonEvent,
93 0, /* Termination */
94 }
95 },
96 {
97 .dest = NI_PFI(2),
98 .src = (int[]){
99 TRIGGER_LINE(0),
100 TRIGGER_LINE(1),
101 TRIGGER_LINE(2),
102 TRIGGER_LINE(3),
103 TRIGGER_LINE(4),
104 TRIGGER_LINE(5),
105 TRIGGER_LINE(6),
106 TRIGGER_LINE(7),
107 NI_CtrSource(0),
108 NI_CtrSource(1),
109 NI_CtrGate(0),
110 NI_CtrGate(1),
111 NI_CtrInternalOutput(0),
112 NI_CtrInternalOutput(1),
113 NI_AI_SampleClock,
114 NI_AI_StartTrigger,
115 NI_AI_ReferenceTrigger,
116 NI_AI_ConvertClock,
117 NI_AO_SampleClock,
118 NI_AO_StartTrigger,
119 NI_DI_SampleClock,
120 NI_DO_SampleClock,
121 NI_FrequencyOutput,
122 NI_ChangeDetectionEvent,
123 NI_AnalogComparisonEvent,
124 0, /* Termination */
125 }
126 },
127 {
128 .dest = NI_PFI(3),
129 .src = (int[]){
130 TRIGGER_LINE(0),
131 TRIGGER_LINE(1),
132 TRIGGER_LINE(2),
133 TRIGGER_LINE(3),
134 TRIGGER_LINE(4),
135 TRIGGER_LINE(5),
136 TRIGGER_LINE(6),
137 TRIGGER_LINE(7),
138 NI_CtrSource(0),
139 NI_CtrSource(1),
140 NI_CtrGate(0),
141 NI_CtrGate(1),
142 NI_CtrInternalOutput(0),
143 NI_CtrInternalOutput(1),
144 NI_AI_SampleClock,
145 NI_AI_StartTrigger,
146 NI_AI_ReferenceTrigger,
147 NI_AI_ConvertClock,
148 NI_AO_SampleClock,
149 NI_AO_StartTrigger,
150 NI_DI_SampleClock,
151 NI_DO_SampleClock,
152 NI_FrequencyOutput,
153 NI_ChangeDetectionEvent,
154 NI_AnalogComparisonEvent,
155 0, /* Termination */
156 }
157 },
158 {
159 .dest = NI_PFI(4),
160 .src = (int[]){
161 TRIGGER_LINE(0),
162 TRIGGER_LINE(1),
163 TRIGGER_LINE(2),
164 TRIGGER_LINE(3),
165 TRIGGER_LINE(4),
166 TRIGGER_LINE(5),
167 TRIGGER_LINE(6),
168 TRIGGER_LINE(7),
169 NI_CtrSource(0),
170 NI_CtrSource(1),
171 NI_CtrGate(0),
172 NI_CtrGate(1),
173 NI_CtrInternalOutput(0),
174 NI_CtrInternalOutput(1),
175 NI_AI_SampleClock,
176 NI_AI_StartTrigger,
177 NI_AI_ReferenceTrigger,
178 NI_AI_ConvertClock,
179 NI_AO_SampleClock,
180 NI_AO_StartTrigger,
181 NI_DI_SampleClock,
182 NI_DO_SampleClock,
183 NI_FrequencyOutput,
184 NI_ChangeDetectionEvent,
185 NI_AnalogComparisonEvent,
186 0, /* Termination */
187 }
188 },
189 {
190 .dest = NI_PFI(5),
191 .src = (int[]){
192 TRIGGER_LINE(0),
193 TRIGGER_LINE(1),
194 TRIGGER_LINE(2),
195 TRIGGER_LINE(3),
196 TRIGGER_LINE(4),
197 TRIGGER_LINE(5),
198 TRIGGER_LINE(6),
199 TRIGGER_LINE(7),
200 NI_CtrSource(0),
201 NI_CtrSource(1),
202 NI_CtrGate(0),
203 NI_CtrGate(1),
204 NI_CtrInternalOutput(0),
205 NI_CtrInternalOutput(1),
206 NI_AI_SampleClock,
207 NI_AI_StartTrigger,
208 NI_AI_ReferenceTrigger,
209 NI_AI_ConvertClock,
210 NI_AO_SampleClock,
211 NI_AO_StartTrigger,
212 NI_DI_SampleClock,
213 NI_DO_SampleClock,
214 NI_FrequencyOutput,
215 NI_ChangeDetectionEvent,
216 NI_AnalogComparisonEvent,
217 0, /* Termination */
218 }
219 },
220 {
221 .dest = NI_PFI(6),
222 .src = (int[]){
223 TRIGGER_LINE(0),
224 TRIGGER_LINE(1),
225 TRIGGER_LINE(2),
226 TRIGGER_LINE(3),
227 TRIGGER_LINE(4),
228 TRIGGER_LINE(5),
229 TRIGGER_LINE(6),
230 TRIGGER_LINE(7),
231 NI_CtrSource(0),
232 NI_CtrSource(1),
233 NI_CtrGate(0),
234 NI_CtrGate(1),
235 NI_CtrInternalOutput(0),
236 NI_CtrInternalOutput(1),
237 NI_AI_SampleClock,
238 NI_AI_StartTrigger,
239 NI_AI_ReferenceTrigger,
240 NI_AI_ConvertClock,
241 NI_AO_SampleClock,
242 NI_AO_StartTrigger,
243 NI_DI_SampleClock,
244 NI_DO_SampleClock,
245 NI_FrequencyOutput,
246 NI_ChangeDetectionEvent,
247 NI_AnalogComparisonEvent,
248 0, /* Termination */
249 }
250 },
251 {
252 .dest = NI_PFI(7),
253 .src = (int[]){
254 TRIGGER_LINE(0),
255 TRIGGER_LINE(1),
256 TRIGGER_LINE(2),
257 TRIGGER_LINE(3),
258 TRIGGER_LINE(4),
259 TRIGGER_LINE(5),
260 TRIGGER_LINE(6),
261 TRIGGER_LINE(7),
262 NI_CtrSource(0),
263 NI_CtrSource(1),
264 NI_CtrGate(0),
265 NI_CtrGate(1),
266 NI_CtrInternalOutput(0),
267 NI_CtrInternalOutput(1),
268 NI_AI_SampleClock,
269 NI_AI_StartTrigger,
270 NI_AI_ReferenceTrigger,
271 NI_AI_ConvertClock,
272 NI_AO_SampleClock,
273 NI_AO_StartTrigger,
274 NI_DI_SampleClock,
275 NI_DO_SampleClock,
276 NI_FrequencyOutput,
277 NI_ChangeDetectionEvent,
278 NI_AnalogComparisonEvent,
279 0, /* Termination */
280 }
281 },
282 {
283 .dest = NI_PFI(8),
284 .src = (int[]){
285 TRIGGER_LINE(0),
286 TRIGGER_LINE(1),
287 TRIGGER_LINE(2),
288 TRIGGER_LINE(3),
289 TRIGGER_LINE(4),
290 TRIGGER_LINE(5),
291 TRIGGER_LINE(6),
292 TRIGGER_LINE(7),
293 NI_CtrSource(0),
294 NI_CtrSource(1),
295 NI_CtrGate(0),
296 NI_CtrGate(1),
297 NI_CtrInternalOutput(0),
298 NI_CtrInternalOutput(1),
299 NI_AI_SampleClock,
300 NI_AI_StartTrigger,
301 NI_AI_ReferenceTrigger,
302 NI_AI_ConvertClock,
303 NI_AO_SampleClock,
304 NI_AO_StartTrigger,
305 NI_DI_SampleClock,
306 NI_DO_SampleClock,
307 NI_FrequencyOutput,
308 NI_ChangeDetectionEvent,
309 NI_AnalogComparisonEvent,
310 0, /* Termination */
311 }
312 },
313 {
314 .dest = NI_PFI(9),
315 .src = (int[]){
316 TRIGGER_LINE(0),
317 TRIGGER_LINE(1),
318 TRIGGER_LINE(2),
319 TRIGGER_LINE(3),
320 TRIGGER_LINE(4),
321 TRIGGER_LINE(5),
322 TRIGGER_LINE(6),
323 TRIGGER_LINE(7),
324 NI_CtrSource(0),
325 NI_CtrSource(1),
326 NI_CtrGate(0),
327 NI_CtrGate(1),
328 NI_CtrInternalOutput(0),
329 NI_CtrInternalOutput(1),
330 NI_AI_SampleClock,
331 NI_AI_StartTrigger,
332 NI_AI_ReferenceTrigger,
333 NI_AI_ConvertClock,
334 NI_AO_SampleClock,
335 NI_AO_StartTrigger,
336 NI_DI_SampleClock,
337 NI_DO_SampleClock,
338 NI_FrequencyOutput,
339 NI_ChangeDetectionEvent,
340 NI_AnalogComparisonEvent,
341 0, /* Termination */
342 }
343 },
344 {
345 .dest = NI_PFI(10),
346 .src = (int[]){
347 TRIGGER_LINE(0),
348 TRIGGER_LINE(1),
349 TRIGGER_LINE(2),
350 TRIGGER_LINE(3),
351 TRIGGER_LINE(4),
352 TRIGGER_LINE(5),
353 TRIGGER_LINE(6),
354 TRIGGER_LINE(7),
355 NI_CtrSource(0),
356 NI_CtrSource(1),
357 NI_CtrGate(0),
358 NI_CtrGate(1),
359 NI_CtrInternalOutput(0),
360 NI_CtrInternalOutput(1),
361 NI_AI_SampleClock,
362 NI_AI_StartTrigger,
363 NI_AI_ReferenceTrigger,
364 NI_AI_ConvertClock,
365 NI_AO_SampleClock,
366 NI_AO_StartTrigger,
367 NI_DI_SampleClock,
368 NI_DO_SampleClock,
369 NI_FrequencyOutput,
370 NI_ChangeDetectionEvent,
371 NI_AnalogComparisonEvent,
372 0, /* Termination */
373 }
374 },
375 {
376 .dest = NI_PFI(11),
377 .src = (int[]){
378 TRIGGER_LINE(0),
379 TRIGGER_LINE(1),
380 TRIGGER_LINE(2),
381 TRIGGER_LINE(3),
382 TRIGGER_LINE(4),
383 TRIGGER_LINE(5),
384 TRIGGER_LINE(6),
385 TRIGGER_LINE(7),
386 NI_CtrSource(0),
387 NI_CtrSource(1),
388 NI_CtrGate(0),
389 NI_CtrGate(1),
390 NI_CtrInternalOutput(0),
391 NI_CtrInternalOutput(1),
392 NI_AI_SampleClock,
393 NI_AI_StartTrigger,
394 NI_AI_ReferenceTrigger,
395 NI_AI_ConvertClock,
396 NI_AO_SampleClock,
397 NI_AO_StartTrigger,
398 NI_DI_SampleClock,
399 NI_DO_SampleClock,
400 NI_FrequencyOutput,
401 NI_ChangeDetectionEvent,
402 NI_AnalogComparisonEvent,
403 0, /* Termination */
404 }
405 },
406 {
407 .dest = NI_PFI(12),
408 .src = (int[]){
409 TRIGGER_LINE(0),
410 TRIGGER_LINE(1),
411 TRIGGER_LINE(2),
412 TRIGGER_LINE(3),
413 TRIGGER_LINE(4),
414 TRIGGER_LINE(5),
415 TRIGGER_LINE(6),
416 TRIGGER_LINE(7),
417 NI_CtrSource(0),
418 NI_CtrSource(1),
419 NI_CtrGate(0),
420 NI_CtrGate(1),
421 NI_CtrInternalOutput(0),
422 NI_CtrInternalOutput(1),
423 NI_AI_SampleClock,
424 NI_AI_StartTrigger,
425 NI_AI_ReferenceTrigger,
426 NI_AI_ConvertClock,
427 NI_AO_SampleClock,
428 NI_AO_StartTrigger,
429 NI_DI_SampleClock,
430 NI_DO_SampleClock,
431 NI_FrequencyOutput,
432 NI_ChangeDetectionEvent,
433 NI_AnalogComparisonEvent,
434 0, /* Termination */
435 }
436 },
437 {
438 .dest = NI_PFI(13),
439 .src = (int[]){
440 TRIGGER_LINE(0),
441 TRIGGER_LINE(1),
442 TRIGGER_LINE(2),
443 TRIGGER_LINE(3),
444 TRIGGER_LINE(4),
445 TRIGGER_LINE(5),
446 TRIGGER_LINE(6),
447 TRIGGER_LINE(7),
448 NI_CtrSource(0),
449 NI_CtrSource(1),
450 NI_CtrGate(0),
451 NI_CtrGate(1),
452 NI_CtrInternalOutput(0),
453 NI_CtrInternalOutput(1),
454 NI_AI_SampleClock,
455 NI_AI_StartTrigger,
456 NI_AI_ReferenceTrigger,
457 NI_AI_ConvertClock,
458 NI_AO_SampleClock,
459 NI_AO_StartTrigger,
460 NI_DI_SampleClock,
461 NI_DO_SampleClock,
462 NI_FrequencyOutput,
463 NI_ChangeDetectionEvent,
464 NI_AnalogComparisonEvent,
465 0, /* Termination */
466 }
467 },
468 {
469 .dest = NI_PFI(14),
470 .src = (int[]){
471 TRIGGER_LINE(0),
472 TRIGGER_LINE(1),
473 TRIGGER_LINE(2),
474 TRIGGER_LINE(3),
475 TRIGGER_LINE(4),
476 TRIGGER_LINE(5),
477 TRIGGER_LINE(6),
478 TRIGGER_LINE(7),
479 NI_CtrSource(0),
480 NI_CtrSource(1),
481 NI_CtrGate(0),
482 NI_CtrGate(1),
483 NI_CtrInternalOutput(0),
484 NI_CtrInternalOutput(1),
485 NI_AI_SampleClock,
486 NI_AI_StartTrigger,
487 NI_AI_ReferenceTrigger,
488 NI_AI_ConvertClock,
489 NI_AO_SampleClock,
490 NI_AO_StartTrigger,
491 NI_DI_SampleClock,
492 NI_DO_SampleClock,
493 NI_FrequencyOutput,
494 NI_ChangeDetectionEvent,
495 NI_AnalogComparisonEvent,
496 0, /* Termination */
497 }
498 },
499 {
500 .dest = NI_PFI(15),
501 .src = (int[]){
502 TRIGGER_LINE(0),
503 TRIGGER_LINE(1),
504 TRIGGER_LINE(2),
505 TRIGGER_LINE(3),
506 TRIGGER_LINE(4),
507 TRIGGER_LINE(5),
508 TRIGGER_LINE(6),
509 TRIGGER_LINE(7),
510 NI_CtrSource(0),
511 NI_CtrSource(1),
512 NI_CtrGate(0),
513 NI_CtrGate(1),
514 NI_CtrInternalOutput(0),
515 NI_CtrInternalOutput(1),
516 NI_AI_SampleClock,
517 NI_AI_StartTrigger,
518 NI_AI_ReferenceTrigger,
519 NI_AI_ConvertClock,
520 NI_AO_SampleClock,
521 NI_AO_StartTrigger,
522 NI_DI_SampleClock,
523 NI_DO_SampleClock,
524 NI_FrequencyOutput,
525 NI_ChangeDetectionEvent,
526 NI_AnalogComparisonEvent,
527 0, /* Termination */
528 }
529 },
530 {
531 .dest = TRIGGER_LINE(0),
532 .src = (int[]){
533 NI_PFI(0),
534 NI_PFI(1),
535 NI_PFI(2),
536 NI_PFI(3),
537 NI_PFI(4),
538 NI_PFI(5),
539 NI_CtrSource(0),
540 NI_CtrSource(1),
541 NI_CtrGate(0),
542 NI_CtrGate(1),
543 NI_CtrInternalOutput(0),
544 NI_CtrInternalOutput(1),
545 NI_AI_SampleClock,
546 NI_AI_StartTrigger,
547 NI_AI_ReferenceTrigger,
548 NI_AI_ConvertClock,
549 NI_AI_PauseTrigger,
550 NI_AO_SampleClock,
551 NI_AO_StartTrigger,
552 NI_AO_PauseTrigger,
553 NI_10MHzRefClock,
554 NI_FrequencyOutput,
555 NI_ChangeDetectionEvent,
556 NI_AnalogComparisonEvent,
557 0, /* Termination */
558 }
559 },
560 {
561 .dest = TRIGGER_LINE(1),
562 .src = (int[]){
563 NI_PFI(0),
564 NI_PFI(1),
565 NI_PFI(2),
566 NI_PFI(3),
567 NI_PFI(4),
568 NI_PFI(5),
569 NI_CtrSource(0),
570 NI_CtrSource(1),
571 NI_CtrGate(0),
572 NI_CtrGate(1),
573 NI_CtrInternalOutput(0),
574 NI_CtrInternalOutput(1),
575 NI_AI_SampleClock,
576 NI_AI_StartTrigger,
577 NI_AI_ReferenceTrigger,
578 NI_AI_ConvertClock,
579 NI_AI_PauseTrigger,
580 NI_AO_SampleClock,
581 NI_AO_StartTrigger,
582 NI_AO_PauseTrigger,
583 NI_10MHzRefClock,
584 NI_FrequencyOutput,
585 NI_ChangeDetectionEvent,
586 NI_AnalogComparisonEvent,
587 0, /* Termination */
588 }
589 },
590 {
591 .dest = TRIGGER_LINE(2),
592 .src = (int[]){
593 NI_PFI(0),
594 NI_PFI(1),
595 NI_PFI(2),
596 NI_PFI(3),
597 NI_PFI(4),
598 NI_PFI(5),
599 NI_CtrSource(0),
600 NI_CtrSource(1),
601 NI_CtrGate(0),
602 NI_CtrGate(1),
603 NI_CtrInternalOutput(0),
604 NI_CtrInternalOutput(1),
605 NI_AI_SampleClock,
606 NI_AI_StartTrigger,
607 NI_AI_ReferenceTrigger,
608 NI_AI_ConvertClock,
609 NI_AI_PauseTrigger,
610 NI_AO_SampleClock,
611 NI_AO_StartTrigger,
612 NI_AO_PauseTrigger,
613 NI_10MHzRefClock,
614 NI_FrequencyOutput,
615 NI_ChangeDetectionEvent,
616 NI_AnalogComparisonEvent,
617 0, /* Termination */
618 }
619 },
620 {
621 .dest = TRIGGER_LINE(3),
622 .src = (int[]){
623 NI_PFI(0),
624 NI_PFI(1),
625 NI_PFI(2),
626 NI_PFI(3),
627 NI_PFI(4),
628 NI_PFI(5),
629 NI_CtrSource(0),
630 NI_CtrSource(1),
631 NI_CtrGate(0),
632 NI_CtrGate(1),
633 NI_CtrInternalOutput(0),
634 NI_CtrInternalOutput(1),
635 NI_AI_SampleClock,
636 NI_AI_StartTrigger,
637 NI_AI_ReferenceTrigger,
638 NI_AI_ConvertClock,
639 NI_AI_PauseTrigger,
640 NI_AO_SampleClock,
641 NI_AO_StartTrigger,
642 NI_AO_PauseTrigger,
643 NI_10MHzRefClock,
644 NI_FrequencyOutput,
645 NI_ChangeDetectionEvent,
646 NI_AnalogComparisonEvent,
647 0, /* Termination */
648 }
649 },
650 {
651 .dest = TRIGGER_LINE(4),
652 .src = (int[]){
653 NI_PFI(0),
654 NI_PFI(1),
655 NI_PFI(2),
656 NI_PFI(3),
657 NI_PFI(4),
658 NI_PFI(5),
659 NI_CtrSource(0),
660 NI_CtrSource(1),
661 NI_CtrGate(0),
662 NI_CtrGate(1),
663 NI_CtrInternalOutput(0),
664 NI_CtrInternalOutput(1),
665 NI_AI_SampleClock,
666 NI_AI_StartTrigger,
667 NI_AI_ReferenceTrigger,
668 NI_AI_ConvertClock,
669 NI_AI_PauseTrigger,
670 NI_AO_SampleClock,
671 NI_AO_StartTrigger,
672 NI_AO_PauseTrigger,
673 NI_10MHzRefClock,
674 NI_FrequencyOutput,
675 NI_ChangeDetectionEvent,
676 NI_AnalogComparisonEvent,
677 0, /* Termination */
678 }
679 },
680 {
681 .dest = TRIGGER_LINE(5),
682 .src = (int[]){
683 NI_PFI(0),
684 NI_PFI(1),
685 NI_PFI(2),
686 NI_PFI(3),
687 NI_PFI(4),
688 NI_PFI(5),
689 NI_CtrSource(0),
690 NI_CtrSource(1),
691 NI_CtrGate(0),
692 NI_CtrGate(1),
693 NI_CtrInternalOutput(0),
694 NI_CtrInternalOutput(1),
695 NI_AI_SampleClock,
696 NI_AI_StartTrigger,
697 NI_AI_ReferenceTrigger,
698 NI_AI_ConvertClock,
699 NI_AI_PauseTrigger,
700 NI_AO_SampleClock,
701 NI_AO_StartTrigger,
702 NI_AO_PauseTrigger,
703 NI_10MHzRefClock,
704 NI_FrequencyOutput,
705 NI_ChangeDetectionEvent,
706 NI_AnalogComparisonEvent,
707 0, /* Termination */
708 }
709 },
710 {
711 .dest = TRIGGER_LINE(6),
712 .src = (int[]){
713 NI_PFI(0),
714 NI_PFI(1),
715 NI_PFI(2),
716 NI_PFI(3),
717 NI_PFI(4),
718 NI_PFI(5),
719 NI_CtrSource(0),
720 NI_CtrSource(1),
721 NI_CtrGate(0),
722 NI_CtrGate(1),
723 NI_CtrInternalOutput(0),
724 NI_CtrInternalOutput(1),
725 NI_AI_SampleClock,
726 NI_AI_StartTrigger,
727 NI_AI_ReferenceTrigger,
728 NI_AI_ConvertClock,
729 NI_AI_PauseTrigger,
730 NI_AO_SampleClock,
731 NI_AO_StartTrigger,
732 NI_AO_PauseTrigger,
733 NI_10MHzRefClock,
734 NI_FrequencyOutput,
735 NI_ChangeDetectionEvent,
736 NI_AnalogComparisonEvent,
737 0, /* Termination */
738 }
739 },
740 {
741 .dest = TRIGGER_LINE(7),
742 .src = (int[]){
743 NI_PFI(0),
744 NI_PFI(1),
745 NI_PFI(2),
746 NI_PFI(3),
747 NI_PFI(4),
748 NI_PFI(5),
749 NI_CtrSource(0),
750 NI_CtrSource(1),
751 NI_CtrGate(0),
752 NI_CtrGate(1),
753 NI_CtrInternalOutput(0),
754 NI_CtrInternalOutput(1),
755 NI_AI_SampleClock,
756 NI_AI_StartTrigger,
757 NI_AI_ReferenceTrigger,
758 NI_AI_ConvertClock,
759 NI_AI_PauseTrigger,
760 NI_AO_SampleClock,
761 NI_AO_StartTrigger,
762 NI_AO_PauseTrigger,
763 NI_10MHzRefClock,
764 NI_FrequencyOutput,
765 NI_ChangeDetectionEvent,
766 NI_AnalogComparisonEvent,
767 0, /* Termination */
768 }
769 },
770 {
771 .dest = NI_CtrSource(0),
772 .src = (int[]){
773 NI_PFI(0),
774 NI_PFI(1),
775 NI_PFI(2),
776 NI_PFI(3),
777 NI_PFI(4),
778 NI_PFI(5),
779 NI_PFI(6),
780 NI_PFI(7),
781 NI_PFI(8),
782 NI_PFI(9),
783 NI_PFI(10),
784 NI_PFI(11),
785 NI_PFI(12),
786 NI_PFI(13),
787 NI_PFI(14),
788 NI_PFI(15),
789 TRIGGER_LINE(0),
790 TRIGGER_LINE(1),
791 TRIGGER_LINE(2),
792 TRIGGER_LINE(3),
793 TRIGGER_LINE(4),
794 TRIGGER_LINE(5),
795 TRIGGER_LINE(6),
796 TRIGGER_LINE(7),
797 NI_CtrGate(1),
798 NI_20MHzTimebase,
799 NI_80MHzTimebase,
800 NI_100kHzTimebase,
801 NI_AnalogComparisonEvent,
802 0, /* Termination */
803 }
804 },
805 {
806 .dest = NI_CtrSource(1),
807 .src = (int[]){
808 NI_PFI(0),
809 NI_PFI(1),
810 NI_PFI(2),
811 NI_PFI(3),
812 NI_PFI(4),
813 NI_PFI(5),
814 NI_PFI(6),
815 NI_PFI(7),
816 NI_PFI(8),
817 NI_PFI(9),
818 NI_PFI(10),
819 NI_PFI(11),
820 NI_PFI(12),
821 NI_PFI(13),
822 NI_PFI(14),
823 NI_PFI(15),
824 TRIGGER_LINE(0),
825 TRIGGER_LINE(1),
826 TRIGGER_LINE(2),
827 TRIGGER_LINE(3),
828 TRIGGER_LINE(4),
829 TRIGGER_LINE(5),
830 TRIGGER_LINE(6),
831 TRIGGER_LINE(7),
832 NI_CtrGate(0),
833 NI_20MHzTimebase,
834 NI_80MHzTimebase,
835 NI_100kHzTimebase,
836 NI_AnalogComparisonEvent,
837 0, /* Termination */
838 }
839 },
840 {
841 .dest = NI_CtrGate(0),
842 .src = (int[]){
843 NI_PFI(0),
844 NI_PFI(1),
845 NI_PFI(2),
846 NI_PFI(3),
847 NI_PFI(4),
848 NI_PFI(5),
849 NI_PFI(6),
850 NI_PFI(7),
851 NI_PFI(8),
852 NI_PFI(9),
853 NI_PFI(10),
854 NI_PFI(11),
855 NI_PFI(12),
856 NI_PFI(13),
857 NI_PFI(14),
858 NI_PFI(15),
859 TRIGGER_LINE(0),
860 TRIGGER_LINE(1),
861 TRIGGER_LINE(2),
862 TRIGGER_LINE(3),
863 TRIGGER_LINE(4),
864 TRIGGER_LINE(5),
865 TRIGGER_LINE(6),
866 TRIGGER_LINE(7),
867 NI_CtrSource(1),
868 NI_CtrInternalOutput(1),
869 NI_AI_StartTrigger,
870 NI_AI_ReferenceTrigger,
871 NI_AnalogComparisonEvent,
872 0, /* Termination */
873 }
874 },
875 {
876 .dest = NI_CtrGate(1),
877 .src = (int[]){
878 NI_PFI(0),
879 NI_PFI(1),
880 NI_PFI(2),
881 NI_PFI(3),
882 NI_PFI(4),
883 NI_PFI(5),
884 NI_PFI(6),
885 NI_PFI(7),
886 NI_PFI(8),
887 NI_PFI(9),
888 NI_PFI(10),
889 NI_PFI(11),
890 NI_PFI(12),
891 NI_PFI(13),
892 NI_PFI(14),
893 NI_PFI(15),
894 TRIGGER_LINE(0),
895 TRIGGER_LINE(1),
896 TRIGGER_LINE(2),
897 TRIGGER_LINE(3),
898 TRIGGER_LINE(4),
899 TRIGGER_LINE(5),
900 TRIGGER_LINE(6),
901 TRIGGER_LINE(7),
902 NI_CtrSource(0),
903 NI_CtrInternalOutput(0),
904 NI_AI_StartTrigger,
905 NI_AI_ReferenceTrigger,
906 NI_AnalogComparisonEvent,
907 0, /* Termination */
908 }
909 },
910 {
911 .dest = NI_CtrAux(0),
912 .src = (int[]){
913 NI_PFI(0),
914 NI_PFI(1),
915 NI_PFI(2),
916 NI_PFI(3),
917 NI_PFI(4),
918 NI_PFI(5),
919 NI_PFI(6),
920 NI_PFI(7),
921 NI_PFI(8),
922 NI_PFI(9),
923 NI_PFI(10),
924 NI_PFI(11),
925 NI_PFI(12),
926 NI_PFI(13),
927 NI_PFI(14),
928 NI_PFI(15),
929 TRIGGER_LINE(0),
930 TRIGGER_LINE(1),
931 TRIGGER_LINE(2),
932 TRIGGER_LINE(3),
933 TRIGGER_LINE(4),
934 TRIGGER_LINE(5),
935 TRIGGER_LINE(6),
936 TRIGGER_LINE(7),
937 NI_CtrSource(1),
938 NI_CtrGate(0),
939 NI_CtrGate(1),
940 NI_CtrInternalOutput(1),
941 NI_AI_StartTrigger,
942 NI_AI_ReferenceTrigger,
943 NI_AnalogComparisonEvent,
944 0, /* Termination */
945 }
946 },
947 {
948 .dest = NI_CtrAux(1),
949 .src = (int[]){
950 NI_PFI(0),
951 NI_PFI(1),
952 NI_PFI(2),
953 NI_PFI(3),
954 NI_PFI(4),
955 NI_PFI(5),
956 NI_PFI(6),
957 NI_PFI(7),
958 NI_PFI(8),
959 NI_PFI(9),
960 NI_PFI(10),
961 NI_PFI(11),
962 NI_PFI(12),
963 NI_PFI(13),
964 NI_PFI(14),
965 NI_PFI(15),
966 TRIGGER_LINE(0),
967 TRIGGER_LINE(1),
968 TRIGGER_LINE(2),
969 TRIGGER_LINE(3),
970 TRIGGER_LINE(4),
971 TRIGGER_LINE(5),
972 TRIGGER_LINE(6),
973 TRIGGER_LINE(7),
974 NI_CtrSource(0),
975 NI_CtrGate(0),
976 NI_CtrGate(1),
977 NI_CtrInternalOutput(0),
978 NI_AI_StartTrigger,
979 NI_AI_ReferenceTrigger,
980 NI_AnalogComparisonEvent,
981 0, /* Termination */
982 }
983 },
984 {
985 .dest = NI_CtrA(0),
986 .src = (int[]){
987 NI_PFI(0),
988 NI_PFI(1),
989 NI_PFI(2),
990 NI_PFI(3),
991 NI_PFI(4),
992 NI_PFI(5),
993 NI_PFI(6),
994 NI_PFI(7),
995 NI_PFI(8),
996 NI_PFI(9),
997 NI_PFI(10),
998 NI_PFI(11),
999 NI_PFI(12),
1000 NI_PFI(13),
1001 NI_PFI(14),
1002 NI_PFI(15),
1003 TRIGGER_LINE(0),
1004 TRIGGER_LINE(1),
1005 TRIGGER_LINE(2),
1006 TRIGGER_LINE(3),
1007 TRIGGER_LINE(4),
1008 TRIGGER_LINE(5),
1009 TRIGGER_LINE(6),
1010 TRIGGER_LINE(7),
1011 NI_AnalogComparisonEvent,
1012 0, /* Termination */
1013 }
1014 },
1015 {
1016 .dest = NI_CtrA(1),
1017 .src = (int[]){
1018 NI_PFI(0),
1019 NI_PFI(1),
1020 NI_PFI(2),
1021 NI_PFI(3),
1022 NI_PFI(4),
1023 NI_PFI(5),
1024 NI_PFI(6),
1025 NI_PFI(7),
1026 NI_PFI(8),
1027 NI_PFI(9),
1028 NI_PFI(10),
1029 NI_PFI(11),
1030 NI_PFI(12),
1031 NI_PFI(13),
1032 NI_PFI(14),
1033 NI_PFI(15),
1034 TRIGGER_LINE(0),
1035 TRIGGER_LINE(1),
1036 TRIGGER_LINE(2),
1037 TRIGGER_LINE(3),
1038 TRIGGER_LINE(4),
1039 TRIGGER_LINE(5),
1040 TRIGGER_LINE(6),
1041 TRIGGER_LINE(7),
1042 NI_AnalogComparisonEvent,
1043 0, /* Termination */
1044 }
1045 },
1046 {
1047 .dest = NI_CtrB(0),
1048 .src = (int[]){
1049 NI_PFI(0),
1050 NI_PFI(1),
1051 NI_PFI(2),
1052 NI_PFI(3),
1053 NI_PFI(4),
1054 NI_PFI(5),
1055 NI_PFI(6),
1056 NI_PFI(7),
1057 NI_PFI(8),
1058 NI_PFI(9),
1059 NI_PFI(10),
1060 NI_PFI(11),
1061 NI_PFI(12),
1062 NI_PFI(13),
1063 NI_PFI(14),
1064 NI_PFI(15),
1065 TRIGGER_LINE(0),
1066 TRIGGER_LINE(1),
1067 TRIGGER_LINE(2),
1068 TRIGGER_LINE(3),
1069 TRIGGER_LINE(4),
1070 TRIGGER_LINE(5),
1071 TRIGGER_LINE(6),
1072 TRIGGER_LINE(7),
1073 NI_AnalogComparisonEvent,
1074 0, /* Termination */
1075 }
1076 },
1077 {
1078 .dest = NI_CtrB(1),
1079 .src = (int[]){
1080 NI_PFI(0),
1081 NI_PFI(1),
1082 NI_PFI(2),
1083 NI_PFI(3),
1084 NI_PFI(4),
1085 NI_PFI(5),
1086 NI_PFI(6),
1087 NI_PFI(7),
1088 NI_PFI(8),
1089 NI_PFI(9),
1090 NI_PFI(10),
1091 NI_PFI(11),
1092 NI_PFI(12),
1093 NI_PFI(13),
1094 NI_PFI(14),
1095 NI_PFI(15),
1096 TRIGGER_LINE(0),
1097 TRIGGER_LINE(1),
1098 TRIGGER_LINE(2),
1099 TRIGGER_LINE(3),
1100 TRIGGER_LINE(4),
1101 TRIGGER_LINE(5),
1102 TRIGGER_LINE(6),
1103 TRIGGER_LINE(7),
1104 NI_AnalogComparisonEvent,
1105 0, /* Termination */
1106 }
1107 },
1108 {
1109 .dest = NI_CtrZ(0),
1110 .src = (int[]){
1111 NI_PFI(0),
1112 NI_PFI(1),
1113 NI_PFI(2),
1114 NI_PFI(3),
1115 NI_PFI(4),
1116 NI_PFI(5),
1117 NI_PFI(6),
1118 NI_PFI(7),
1119 NI_PFI(8),
1120 NI_PFI(9),
1121 NI_PFI(10),
1122 NI_PFI(11),
1123 NI_PFI(12),
1124 NI_PFI(13),
1125 NI_PFI(14),
1126 NI_PFI(15),
1127 TRIGGER_LINE(0),
1128 TRIGGER_LINE(1),
1129 TRIGGER_LINE(2),
1130 TRIGGER_LINE(3),
1131 TRIGGER_LINE(4),
1132 TRIGGER_LINE(5),
1133 TRIGGER_LINE(6),
1134 TRIGGER_LINE(7),
1135 NI_AnalogComparisonEvent,
1136 0, /* Termination */
1137 }
1138 },
1139 {
1140 .dest = NI_CtrZ(1),
1141 .src = (int[]){
1142 NI_PFI(0),
1143 NI_PFI(1),
1144 NI_PFI(2),
1145 NI_PFI(3),
1146 NI_PFI(4),
1147 NI_PFI(5),
1148 NI_PFI(6),
1149 NI_PFI(7),
1150 NI_PFI(8),
1151 NI_PFI(9),
1152 NI_PFI(10),
1153 NI_PFI(11),
1154 NI_PFI(12),
1155 NI_PFI(13),
1156 NI_PFI(14),
1157 NI_PFI(15),
1158 TRIGGER_LINE(0),
1159 TRIGGER_LINE(1),
1160 TRIGGER_LINE(2),
1161 TRIGGER_LINE(3),
1162 TRIGGER_LINE(4),
1163 TRIGGER_LINE(5),
1164 TRIGGER_LINE(6),
1165 TRIGGER_LINE(7),
1166 NI_AnalogComparisonEvent,
1167 0, /* Termination */
1168 }
1169 },
1170 {
1171 .dest = NI_CtrArmStartTrigger(0),
1172 .src = (int[]){
1173 NI_PFI(0),
1174 NI_PFI(1),
1175 NI_PFI(2),
1176 NI_PFI(3),
1177 NI_PFI(4),
1178 NI_PFI(5),
1179 NI_PFI(6),
1180 NI_PFI(7),
1181 NI_PFI(8),
1182 NI_PFI(9),
1183 NI_PFI(10),
1184 NI_PFI(11),
1185 NI_PFI(12),
1186 NI_PFI(13),
1187 NI_PFI(14),
1188 NI_PFI(15),
1189 TRIGGER_LINE(0),
1190 TRIGGER_LINE(1),
1191 TRIGGER_LINE(2),
1192 TRIGGER_LINE(3),
1193 TRIGGER_LINE(4),
1194 TRIGGER_LINE(5),
1195 TRIGGER_LINE(6),
1196 TRIGGER_LINE(7),
1197 NI_CtrInternalOutput(1),
1198 NI_AI_StartTrigger,
1199 NI_AI_ReferenceTrigger,
1200 NI_AnalogComparisonEvent,
1201 0, /* Termination */
1202 }
1203 },
1204 {
1205 .dest = NI_CtrArmStartTrigger(1),
1206 .src = (int[]){
1207 NI_PFI(0),
1208 NI_PFI(1),
1209 NI_PFI(2),
1210 NI_PFI(3),
1211 NI_PFI(4),
1212 NI_PFI(5),
1213 NI_PFI(6),
1214 NI_PFI(7),
1215 NI_PFI(8),
1216 NI_PFI(9),
1217 NI_PFI(10),
1218 NI_PFI(11),
1219 NI_PFI(12),
1220 NI_PFI(13),
1221 NI_PFI(14),
1222 NI_PFI(15),
1223 TRIGGER_LINE(0),
1224 TRIGGER_LINE(1),
1225 TRIGGER_LINE(2),
1226 TRIGGER_LINE(3),
1227 TRIGGER_LINE(4),
1228 TRIGGER_LINE(5),
1229 TRIGGER_LINE(6),
1230 TRIGGER_LINE(7),
1231 NI_CtrInternalOutput(0),
1232 NI_AI_StartTrigger,
1233 NI_AI_ReferenceTrigger,
1234 NI_AnalogComparisonEvent,
1235 0, /* Termination */
1236 }
1237 },
1238 {
1239 .dest = NI_AI_SampleClock,
1240 .src = (int[]){
1241 NI_PFI(0),
1242 NI_PFI(1),
1243 NI_PFI(2),
1244 NI_PFI(3),
1245 NI_PFI(4),
1246 NI_PFI(5),
1247 NI_PFI(6),
1248 NI_PFI(7),
1249 NI_PFI(8),
1250 NI_PFI(9),
1251 NI_PFI(10),
1252 NI_PFI(11),
1253 NI_PFI(12),
1254 NI_PFI(13),
1255 NI_PFI(14),
1256 NI_PFI(15),
1257 TRIGGER_LINE(0),
1258 TRIGGER_LINE(1),
1259 TRIGGER_LINE(2),
1260 TRIGGER_LINE(3),
1261 TRIGGER_LINE(4),
1262 TRIGGER_LINE(5),
1263 TRIGGER_LINE(6),
1264 TRIGGER_LINE(7),
1265 NI_CtrInternalOutput(0),
1266 NI_CtrInternalOutput(1),
1267 NI_AI_SampleClockTimebase,
1268 NI_AnalogComparisonEvent,
1269 0, /* Termination */
1270 }
1271 },
1272 {
1273 .dest = NI_AI_SampleClockTimebase,
1274 .src = (int[]){
1275 NI_PFI(0),
1276 NI_PFI(1),
1277 NI_PFI(2),
1278 NI_PFI(3),
1279 NI_PFI(4),
1280 NI_PFI(5),
1281 NI_PFI(6),
1282 NI_PFI(7),
1283 NI_PFI(8),
1284 NI_PFI(9),
1285 NI_PFI(10),
1286 NI_PFI(11),
1287 NI_PFI(12),
1288 NI_PFI(13),
1289 NI_PFI(14),
1290 NI_PFI(15),
1291 TRIGGER_LINE(0),
1292 TRIGGER_LINE(1),
1293 TRIGGER_LINE(2),
1294 TRIGGER_LINE(3),
1295 TRIGGER_LINE(4),
1296 TRIGGER_LINE(5),
1297 TRIGGER_LINE(6),
1298 TRIGGER_LINE(7),
1299 NI_20MHzTimebase,
1300 NI_100kHzTimebase,
1301 NI_AnalogComparisonEvent,
1302 0, /* Termination */
1303 }
1304 },
1305 {
1306 .dest = NI_AI_StartTrigger,
1307 .src = (int[]){
1308 NI_PFI(0),
1309 NI_PFI(1),
1310 NI_PFI(2),
1311 NI_PFI(3),
1312 NI_PFI(4),
1313 NI_PFI(5),
1314 NI_PFI(6),
1315 NI_PFI(7),
1316 NI_PFI(8),
1317 NI_PFI(9),
1318 NI_PFI(10),
1319 NI_PFI(11),
1320 NI_PFI(12),
1321 NI_PFI(13),
1322 NI_PFI(14),
1323 NI_PFI(15),
1324 TRIGGER_LINE(0),
1325 TRIGGER_LINE(1),
1326 TRIGGER_LINE(2),
1327 TRIGGER_LINE(3),
1328 TRIGGER_LINE(4),
1329 TRIGGER_LINE(5),
1330 TRIGGER_LINE(6),
1331 TRIGGER_LINE(7),
1332 NI_CtrInternalOutput(0),
1333 NI_CtrInternalOutput(1),
1334 NI_AnalogComparisonEvent,
1335 0, /* Termination */
1336 }
1337 },
1338 {
1339 .dest = NI_AI_ReferenceTrigger,
1340 .src = (int[]){
1341 NI_PFI(0),
1342 NI_PFI(1),
1343 NI_PFI(2),
1344 NI_PFI(3),
1345 NI_PFI(4),
1346 NI_PFI(5),
1347 NI_PFI(6),
1348 NI_PFI(7),
1349 NI_PFI(8),
1350 NI_PFI(9),
1351 NI_PFI(10),
1352 NI_PFI(11),
1353 NI_PFI(12),
1354 NI_PFI(13),
1355 NI_PFI(14),
1356 NI_PFI(15),
1357 TRIGGER_LINE(0),
1358 TRIGGER_LINE(1),
1359 TRIGGER_LINE(2),
1360 TRIGGER_LINE(3),
1361 TRIGGER_LINE(4),
1362 TRIGGER_LINE(5),
1363 TRIGGER_LINE(6),
1364 TRIGGER_LINE(7),
1365 NI_AnalogComparisonEvent,
1366 0, /* Termination */
1367 }
1368 },
1369 {
1370 .dest = NI_AI_ConvertClock,
1371 .src = (int[]){
1372 NI_PFI(0),
1373 NI_PFI(1),
1374 NI_PFI(2),
1375 NI_PFI(3),
1376 NI_PFI(4),
1377 NI_PFI(5),
1378 NI_PFI(6),
1379 NI_PFI(7),
1380 NI_PFI(8),
1381 NI_PFI(9),
1382 NI_PFI(10),
1383 NI_PFI(11),
1384 NI_PFI(12),
1385 NI_PFI(13),
1386 NI_PFI(14),
1387 NI_PFI(15),
1388 TRIGGER_LINE(0),
1389 TRIGGER_LINE(1),
1390 TRIGGER_LINE(2),
1391 TRIGGER_LINE(3),
1392 TRIGGER_LINE(4),
1393 TRIGGER_LINE(5),
1394 TRIGGER_LINE(6),
1395 TRIGGER_LINE(7),
1396 NI_CtrInternalOutput(0),
1397 NI_CtrInternalOutput(1),
1398 NI_AI_ConvertClockTimebase,
1399 NI_AnalogComparisonEvent,
1400 0, /* Termination */
1401 }
1402 },
1403 {
1404 .dest = NI_AI_ConvertClockTimebase,
1405 .src = (int[]){
1406 NI_AI_SampleClockTimebase,
1407 NI_20MHzTimebase,
1408 0, /* Termination */
1409 }
1410 },
1411 {
1412 .dest = NI_AI_PauseTrigger,
1413 .src = (int[]){
1414 NI_PFI(0),
1415 NI_PFI(1),
1416 NI_PFI(2),
1417 NI_PFI(3),
1418 NI_PFI(4),
1419 NI_PFI(5),
1420 NI_PFI(6),
1421 NI_PFI(7),
1422 NI_PFI(8),
1423 NI_PFI(9),
1424 NI_PFI(10),
1425 NI_PFI(11),
1426 NI_PFI(12),
1427 NI_PFI(13),
1428 NI_PFI(14),
1429 NI_PFI(15),
1430 TRIGGER_LINE(0),
1431 TRIGGER_LINE(1),
1432 TRIGGER_LINE(2),
1433 TRIGGER_LINE(3),
1434 TRIGGER_LINE(4),
1435 TRIGGER_LINE(5),
1436 TRIGGER_LINE(6),
1437 TRIGGER_LINE(7),
1438 NI_AnalogComparisonEvent,
1439 0, /* Termination */
1440 }
1441 },
1442 {
1443 .dest = NI_AO_SampleClock,
1444 .src = (int[]){
1445 NI_PFI(0),
1446 NI_PFI(1),
1447 NI_PFI(2),
1448 NI_PFI(3),
1449 NI_PFI(4),
1450 NI_PFI(5),
1451 NI_PFI(6),
1452 NI_PFI(7),
1453 NI_PFI(8),
1454 NI_PFI(9),
1455 NI_PFI(10),
1456 NI_PFI(11),
1457 NI_PFI(12),
1458 NI_PFI(13),
1459 NI_PFI(14),
1460 NI_PFI(15),
1461 TRIGGER_LINE(0),
1462 TRIGGER_LINE(1),
1463 TRIGGER_LINE(2),
1464 TRIGGER_LINE(3),
1465 TRIGGER_LINE(4),
1466 TRIGGER_LINE(5),
1467 TRIGGER_LINE(6),
1468 TRIGGER_LINE(7),
1469 NI_CtrInternalOutput(0),
1470 NI_CtrInternalOutput(1),
1471 NI_AO_SampleClockTimebase,
1472 NI_AnalogComparisonEvent,
1473 0, /* Termination */
1474 }
1475 },
1476 {
1477 .dest = NI_AO_SampleClockTimebase,
1478 .src = (int[]){
1479 NI_PFI(0),
1480 NI_PFI(1),
1481 NI_PFI(2),
1482 NI_PFI(3),
1483 NI_PFI(4),
1484 NI_PFI(5),
1485 NI_PFI(6),
1486 NI_PFI(7),
1487 NI_PFI(8),
1488 NI_PFI(9),
1489 NI_PFI(10),
1490 NI_PFI(11),
1491 NI_PFI(12),
1492 NI_PFI(13),
1493 NI_PFI(14),
1494 NI_PFI(15),
1495 TRIGGER_LINE(0),
1496 TRIGGER_LINE(1),
1497 TRIGGER_LINE(2),
1498 TRIGGER_LINE(3),
1499 TRIGGER_LINE(4),
1500 TRIGGER_LINE(5),
1501 TRIGGER_LINE(6),
1502 TRIGGER_LINE(7),
1503 NI_20MHzTimebase,
1504 NI_100kHzTimebase,
1505 NI_AnalogComparisonEvent,
1506 0, /* Termination */
1507 }
1508 },
1509 {
1510 .dest = NI_AO_StartTrigger,
1511 .src = (int[]){
1512 NI_PFI(0),
1513 NI_PFI(1),
1514 NI_PFI(2),
1515 NI_PFI(3),
1516 NI_PFI(4),
1517 NI_PFI(5),
1518 NI_PFI(6),
1519 NI_PFI(7),
1520 NI_PFI(8),
1521 NI_PFI(9),
1522 NI_PFI(10),
1523 NI_PFI(11),
1524 NI_PFI(12),
1525 NI_PFI(13),
1526 NI_PFI(14),
1527 NI_PFI(15),
1528 TRIGGER_LINE(0),
1529 TRIGGER_LINE(1),
1530 TRIGGER_LINE(2),
1531 TRIGGER_LINE(3),
1532 TRIGGER_LINE(4),
1533 TRIGGER_LINE(5),
1534 TRIGGER_LINE(6),
1535 TRIGGER_LINE(7),
1536 NI_AI_StartTrigger,
1537 NI_AnalogComparisonEvent,
1538 0, /* Termination */
1539 }
1540 },
1541 {
1542 .dest = NI_AO_PauseTrigger,
1543 .src = (int[]){
1544 NI_PFI(0),
1545 NI_PFI(1),
1546 NI_PFI(2),
1547 NI_PFI(3),
1548 NI_PFI(4),
1549 NI_PFI(5),
1550 NI_PFI(6),
1551 NI_PFI(7),
1552 NI_PFI(8),
1553 NI_PFI(9),
1554 NI_PFI(10),
1555 NI_PFI(11),
1556 NI_PFI(12),
1557 NI_PFI(13),
1558 NI_PFI(14),
1559 NI_PFI(15),
1560 TRIGGER_LINE(0),
1561 TRIGGER_LINE(1),
1562 TRIGGER_LINE(2),
1563 TRIGGER_LINE(3),
1564 TRIGGER_LINE(4),
1565 TRIGGER_LINE(5),
1566 TRIGGER_LINE(6),
1567 TRIGGER_LINE(7),
1568 NI_AnalogComparisonEvent,
1569 0, /* Termination */
1570 }
1571 },
1572 {
1573 .dest = NI_DI_SampleClock,
1574 .src = (int[]){
1575 NI_PFI(0),
1576 NI_PFI(1),
1577 NI_PFI(2),
1578 NI_PFI(3),
1579 NI_PFI(4),
1580 NI_PFI(5),
1581 NI_PFI(6),
1582 NI_PFI(7),
1583 NI_PFI(8),
1584 NI_PFI(9),
1585 NI_PFI(10),
1586 NI_PFI(11),
1587 NI_PFI(12),
1588 NI_PFI(13),
1589 NI_PFI(14),
1590 NI_PFI(15),
1591 TRIGGER_LINE(0),
1592 TRIGGER_LINE(1),
1593 TRIGGER_LINE(2),
1594 TRIGGER_LINE(3),
1595 TRIGGER_LINE(4),
1596 TRIGGER_LINE(5),
1597 TRIGGER_LINE(6),
1598 TRIGGER_LINE(7),
1599 NI_CtrInternalOutput(0),
1600 NI_CtrInternalOutput(1),
1601 NI_AI_SampleClock,
1602 NI_AI_ConvertClock,
1603 NI_AO_SampleClock,
1604 NI_FrequencyOutput,
1605 NI_ChangeDetectionEvent,
1606 NI_AnalogComparisonEvent,
1607 0, /* Termination */
1608 }
1609 },
1610 {
1611 .dest = NI_DO_SampleClock,
1612 .src = (int[]){
1613 NI_PFI(0),
1614 NI_PFI(1),
1615 NI_PFI(2),
1616 NI_PFI(3),
1617 NI_PFI(4),
1618 NI_PFI(5),
1619 NI_PFI(6),
1620 NI_PFI(7),
1621 NI_PFI(8),
1622 NI_PFI(9),
1623 NI_PFI(10),
1624 NI_PFI(11),
1625 NI_PFI(12),
1626 NI_PFI(13),
1627 NI_PFI(14),
1628 NI_PFI(15),
1629 TRIGGER_LINE(0),
1630 TRIGGER_LINE(1),
1631 TRIGGER_LINE(2),
1632 TRIGGER_LINE(3),
1633 TRIGGER_LINE(4),
1634 TRIGGER_LINE(5),
1635 TRIGGER_LINE(6),
1636 TRIGGER_LINE(7),
1637 NI_CtrInternalOutput(0),
1638 NI_CtrInternalOutput(1),
1639 NI_AI_SampleClock,
1640 NI_AI_ConvertClock,
1641 NI_AO_SampleClock,
1642 NI_FrequencyOutput,
1643 NI_ChangeDetectionEvent,
1644 NI_AnalogComparisonEvent,
1645 0, /* Termination */
1646 }
1647 },
1648 { /* Termination of list */
1649 .dest = 0,
1650 },
1651 },
1652};
diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6254.c b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6254.c
new file mode 100644
index 000000000000..056a240cd3a2
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6254.c
@@ -0,0 +1,1464 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routing/ni_device_routes/pci-6254.c
5 * List of valid routes for specific NI boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21/*
22 * The contents of this file are generated using the tools in
23 * comedi/drivers/ni_routing/tools
24 *
25 * Please use those tools to help maintain the contents of this file.
26 */
27
28#include "../ni_device_routes.h"
29#include "all.h"
30
31struct ni_device_routes ni_pci_6254_device_routes = {
32 .device = "pci-6254",
33 .routes = (struct ni_route_set[]){
34 {
35 .dest = NI_PFI(0),
36 .src = (int[]){
37 TRIGGER_LINE(0),
38 TRIGGER_LINE(1),
39 TRIGGER_LINE(2),
40 TRIGGER_LINE(3),
41 TRIGGER_LINE(4),
42 TRIGGER_LINE(5),
43 TRIGGER_LINE(6),
44 TRIGGER_LINE(7),
45 NI_CtrSource(0),
46 NI_CtrSource(1),
47 NI_CtrGate(0),
48 NI_CtrGate(1),
49 NI_CtrInternalOutput(0),
50 NI_CtrInternalOutput(1),
51 NI_AI_SampleClock,
52 NI_AI_StartTrigger,
53 NI_AI_ReferenceTrigger,
54 NI_AI_ConvertClock,
55 NI_DI_SampleClock,
56 NI_DO_SampleClock,
57 NI_FrequencyOutput,
58 NI_ChangeDetectionEvent,
59 NI_AnalogComparisonEvent,
60 0, /* Termination */
61 }
62 },
63 {
64 .dest = NI_PFI(1),
65 .src = (int[]){
66 TRIGGER_LINE(0),
67 TRIGGER_LINE(1),
68 TRIGGER_LINE(2),
69 TRIGGER_LINE(3),
70 TRIGGER_LINE(4),
71 TRIGGER_LINE(5),
72 TRIGGER_LINE(6),
73 TRIGGER_LINE(7),
74 NI_CtrSource(0),
75 NI_CtrSource(1),
76 NI_CtrGate(0),
77 NI_CtrGate(1),
78 NI_CtrInternalOutput(0),
79 NI_CtrInternalOutput(1),
80 NI_AI_SampleClock,
81 NI_AI_StartTrigger,
82 NI_AI_ReferenceTrigger,
83 NI_AI_ConvertClock,
84 NI_DI_SampleClock,
85 NI_DO_SampleClock,
86 NI_FrequencyOutput,
87 NI_ChangeDetectionEvent,
88 NI_AnalogComparisonEvent,
89 0, /* Termination */
90 }
91 },
92 {
93 .dest = NI_PFI(2),
94 .src = (int[]){
95 TRIGGER_LINE(0),
96 TRIGGER_LINE(1),
97 TRIGGER_LINE(2),
98 TRIGGER_LINE(3),
99 TRIGGER_LINE(4),
100 TRIGGER_LINE(5),
101 TRIGGER_LINE(6),
102 TRIGGER_LINE(7),
103 NI_CtrSource(0),
104 NI_CtrSource(1),
105 NI_CtrGate(0),
106 NI_CtrGate(1),
107 NI_CtrInternalOutput(0),
108 NI_CtrInternalOutput(1),
109 NI_AI_SampleClock,
110 NI_AI_StartTrigger,
111 NI_AI_ReferenceTrigger,
112 NI_AI_ConvertClock,
113 NI_DI_SampleClock,
114 NI_DO_SampleClock,
115 NI_FrequencyOutput,
116 NI_ChangeDetectionEvent,
117 NI_AnalogComparisonEvent,
118 0, /* Termination */
119 }
120 },
121 {
122 .dest = NI_PFI(3),
123 .src = (int[]){
124 TRIGGER_LINE(0),
125 TRIGGER_LINE(1),
126 TRIGGER_LINE(2),
127 TRIGGER_LINE(3),
128 TRIGGER_LINE(4),
129 TRIGGER_LINE(5),
130 TRIGGER_LINE(6),
131 TRIGGER_LINE(7),
132 NI_CtrSource(0),
133 NI_CtrSource(1),
134 NI_CtrGate(0),
135 NI_CtrGate(1),
136 NI_CtrInternalOutput(0),
137 NI_CtrInternalOutput(1),
138 NI_AI_SampleClock,
139 NI_AI_StartTrigger,
140 NI_AI_ReferenceTrigger,
141 NI_AI_ConvertClock,
142 NI_DI_SampleClock,
143 NI_DO_SampleClock,
144 NI_FrequencyOutput,
145 NI_ChangeDetectionEvent,
146 NI_AnalogComparisonEvent,
147 0, /* Termination */
148 }
149 },
150 {
151 .dest = NI_PFI(4),
152 .src = (int[]){
153 TRIGGER_LINE(0),
154 TRIGGER_LINE(1),
155 TRIGGER_LINE(2),
156 TRIGGER_LINE(3),
157 TRIGGER_LINE(4),
158 TRIGGER_LINE(5),
159 TRIGGER_LINE(6),
160 TRIGGER_LINE(7),
161 NI_CtrSource(0),
162 NI_CtrSource(1),
163 NI_CtrGate(0),
164 NI_CtrGate(1),
165 NI_CtrInternalOutput(0),
166 NI_CtrInternalOutput(1),
167 NI_AI_SampleClock,
168 NI_AI_StartTrigger,
169 NI_AI_ReferenceTrigger,
170 NI_AI_ConvertClock,
171 NI_DI_SampleClock,
172 NI_DO_SampleClock,
173 NI_FrequencyOutput,
174 NI_ChangeDetectionEvent,
175 NI_AnalogComparisonEvent,
176 0, /* Termination */
177 }
178 },
179 {
180 .dest = NI_PFI(5),
181 .src = (int[]){
182 TRIGGER_LINE(0),
183 TRIGGER_LINE(1),
184 TRIGGER_LINE(2),
185 TRIGGER_LINE(3),
186 TRIGGER_LINE(4),
187 TRIGGER_LINE(5),
188 TRIGGER_LINE(6),
189 TRIGGER_LINE(7),
190 NI_CtrSource(0),
191 NI_CtrSource(1),
192 NI_CtrGate(0),
193 NI_CtrGate(1),
194 NI_CtrInternalOutput(0),
195 NI_CtrInternalOutput(1),
196 NI_AI_SampleClock,
197 NI_AI_StartTrigger,
198 NI_AI_ReferenceTrigger,
199 NI_AI_ConvertClock,
200 NI_DI_SampleClock,
201 NI_DO_SampleClock,
202 NI_FrequencyOutput,
203 NI_ChangeDetectionEvent,
204 NI_AnalogComparisonEvent,
205 0, /* Termination */
206 }
207 },
208 {
209 .dest = NI_PFI(6),
210 .src = (int[]){
211 TRIGGER_LINE(0),
212 TRIGGER_LINE(1),
213 TRIGGER_LINE(2),
214 TRIGGER_LINE(3),
215 TRIGGER_LINE(4),
216 TRIGGER_LINE(5),
217 TRIGGER_LINE(6),
218 TRIGGER_LINE(7),
219 NI_CtrSource(0),
220 NI_CtrSource(1),
221 NI_CtrGate(0),
222 NI_CtrGate(1),
223 NI_CtrInternalOutput(0),
224 NI_CtrInternalOutput(1),
225 NI_AI_SampleClock,
226 NI_AI_StartTrigger,
227 NI_AI_ReferenceTrigger,
228 NI_AI_ConvertClock,
229 NI_DI_SampleClock,
230 NI_DO_SampleClock,
231 NI_FrequencyOutput,
232 NI_ChangeDetectionEvent,
233 NI_AnalogComparisonEvent,
234 0, /* Termination */
235 }
236 },
237 {
238 .dest = NI_PFI(7),
239 .src = (int[]){
240 TRIGGER_LINE(0),
241 TRIGGER_LINE(1),
242 TRIGGER_LINE(2),
243 TRIGGER_LINE(3),
244 TRIGGER_LINE(4),
245 TRIGGER_LINE(5),
246 TRIGGER_LINE(6),
247 TRIGGER_LINE(7),
248 NI_CtrSource(0),
249 NI_CtrSource(1),
250 NI_CtrGate(0),
251 NI_CtrGate(1),
252 NI_CtrInternalOutput(0),
253 NI_CtrInternalOutput(1),
254 NI_AI_SampleClock,
255 NI_AI_StartTrigger,
256 NI_AI_ReferenceTrigger,
257 NI_AI_ConvertClock,
258 NI_DI_SampleClock,
259 NI_DO_SampleClock,
260 NI_FrequencyOutput,
261 NI_ChangeDetectionEvent,
262 NI_AnalogComparisonEvent,
263 0, /* Termination */
264 }
265 },
266 {
267 .dest = NI_PFI(8),
268 .src = (int[]){
269 TRIGGER_LINE(0),
270 TRIGGER_LINE(1),
271 TRIGGER_LINE(2),
272 TRIGGER_LINE(3),
273 TRIGGER_LINE(4),
274 TRIGGER_LINE(5),
275 TRIGGER_LINE(6),
276 TRIGGER_LINE(7),
277 NI_CtrSource(0),
278 NI_CtrSource(1),
279 NI_CtrGate(0),
280 NI_CtrGate(1),
281 NI_CtrInternalOutput(0),
282 NI_CtrInternalOutput(1),
283 NI_AI_SampleClock,
284 NI_AI_StartTrigger,
285 NI_AI_ReferenceTrigger,
286 NI_AI_ConvertClock,
287 NI_DI_SampleClock,
288 NI_DO_SampleClock,
289 NI_FrequencyOutput,
290 NI_ChangeDetectionEvent,
291 NI_AnalogComparisonEvent,
292 0, /* Termination */
293 }
294 },
295 {
296 .dest = NI_PFI(9),
297 .src = (int[]){
298 TRIGGER_LINE(0),
299 TRIGGER_LINE(1),
300 TRIGGER_LINE(2),
301 TRIGGER_LINE(3),
302 TRIGGER_LINE(4),
303 TRIGGER_LINE(5),
304 TRIGGER_LINE(6),
305 TRIGGER_LINE(7),
306 NI_CtrSource(0),
307 NI_CtrSource(1),
308 NI_CtrGate(0),
309 NI_CtrGate(1),
310 NI_CtrInternalOutput(0),
311 NI_CtrInternalOutput(1),
312 NI_AI_SampleClock,
313 NI_AI_StartTrigger,
314 NI_AI_ReferenceTrigger,
315 NI_AI_ConvertClock,
316 NI_DI_SampleClock,
317 NI_DO_SampleClock,
318 NI_FrequencyOutput,
319 NI_ChangeDetectionEvent,
320 NI_AnalogComparisonEvent,
321 0, /* Termination */
322 }
323 },
324 {
325 .dest = NI_PFI(10),
326 .src = (int[]){
327 TRIGGER_LINE(0),
328 TRIGGER_LINE(1),
329 TRIGGER_LINE(2),
330 TRIGGER_LINE(3),
331 TRIGGER_LINE(4),
332 TRIGGER_LINE(5),
333 TRIGGER_LINE(6),
334 TRIGGER_LINE(7),
335 NI_CtrSource(0),
336 NI_CtrSource(1),
337 NI_CtrGate(0),
338 NI_CtrGate(1),
339 NI_CtrInternalOutput(0),
340 NI_CtrInternalOutput(1),
341 NI_AI_SampleClock,
342 NI_AI_StartTrigger,
343 NI_AI_ReferenceTrigger,
344 NI_AI_ConvertClock,
345 NI_DI_SampleClock,
346 NI_DO_SampleClock,
347 NI_FrequencyOutput,
348 NI_ChangeDetectionEvent,
349 NI_AnalogComparisonEvent,
350 0, /* Termination */
351 }
352 },
353 {
354 .dest = NI_PFI(11),
355 .src = (int[]){
356 TRIGGER_LINE(0),
357 TRIGGER_LINE(1),
358 TRIGGER_LINE(2),
359 TRIGGER_LINE(3),
360 TRIGGER_LINE(4),
361 TRIGGER_LINE(5),
362 TRIGGER_LINE(6),
363 TRIGGER_LINE(7),
364 NI_CtrSource(0),
365 NI_CtrSource(1),
366 NI_CtrGate(0),
367 NI_CtrGate(1),
368 NI_CtrInternalOutput(0),
369 NI_CtrInternalOutput(1),
370 NI_AI_SampleClock,
371 NI_AI_StartTrigger,
372 NI_AI_ReferenceTrigger,
373 NI_AI_ConvertClock,
374 NI_DI_SampleClock,
375 NI_DO_SampleClock,
376 NI_FrequencyOutput,
377 NI_ChangeDetectionEvent,
378 NI_AnalogComparisonEvent,
379 0, /* Termination */
380 }
381 },
382 {
383 .dest = NI_PFI(12),
384 .src = (int[]){
385 TRIGGER_LINE(0),
386 TRIGGER_LINE(1),
387 TRIGGER_LINE(2),
388 TRIGGER_LINE(3),
389 TRIGGER_LINE(4),
390 TRIGGER_LINE(5),
391 TRIGGER_LINE(6),
392 TRIGGER_LINE(7),
393 NI_CtrSource(0),
394 NI_CtrSource(1),
395 NI_CtrGate(0),
396 NI_CtrGate(1),
397 NI_CtrInternalOutput(0),
398 NI_CtrInternalOutput(1),
399 NI_AI_SampleClock,
400 NI_AI_StartTrigger,
401 NI_AI_ReferenceTrigger,
402 NI_AI_ConvertClock,
403 NI_DI_SampleClock,
404 NI_DO_SampleClock,
405 NI_FrequencyOutput,
406 NI_ChangeDetectionEvent,
407 NI_AnalogComparisonEvent,
408 0, /* Termination */
409 }
410 },
411 {
412 .dest = NI_PFI(13),
413 .src = (int[]){
414 TRIGGER_LINE(0),
415 TRIGGER_LINE(1),
416 TRIGGER_LINE(2),
417 TRIGGER_LINE(3),
418 TRIGGER_LINE(4),
419 TRIGGER_LINE(5),
420 TRIGGER_LINE(6),
421 TRIGGER_LINE(7),
422 NI_CtrSource(0),
423 NI_CtrSource(1),
424 NI_CtrGate(0),
425 NI_CtrGate(1),
426 NI_CtrInternalOutput(0),
427 NI_CtrInternalOutput(1),
428 NI_AI_SampleClock,
429 NI_AI_StartTrigger,
430 NI_AI_ReferenceTrigger,
431 NI_AI_ConvertClock,
432 NI_DI_SampleClock,
433 NI_DO_SampleClock,
434 NI_FrequencyOutput,
435 NI_ChangeDetectionEvent,
436 NI_AnalogComparisonEvent,
437 0, /* Termination */
438 }
439 },
440 {
441 .dest = NI_PFI(14),
442 .src = (int[]){
443 TRIGGER_LINE(0),
444 TRIGGER_LINE(1),
445 TRIGGER_LINE(2),
446 TRIGGER_LINE(3),
447 TRIGGER_LINE(4),
448 TRIGGER_LINE(5),
449 TRIGGER_LINE(6),
450 TRIGGER_LINE(7),
451 NI_CtrSource(0),
452 NI_CtrSource(1),
453 NI_CtrGate(0),
454 NI_CtrGate(1),
455 NI_CtrInternalOutput(0),
456 NI_CtrInternalOutput(1),
457 NI_AI_SampleClock,
458 NI_AI_StartTrigger,
459 NI_AI_ReferenceTrigger,
460 NI_AI_ConvertClock,
461 NI_DI_SampleClock,
462 NI_DO_SampleClock,
463 NI_FrequencyOutput,
464 NI_ChangeDetectionEvent,
465 NI_AnalogComparisonEvent,
466 0, /* Termination */
467 }
468 },
469 {
470 .dest = NI_PFI(15),
471 .src = (int[]){
472 TRIGGER_LINE(0),
473 TRIGGER_LINE(1),
474 TRIGGER_LINE(2),
475 TRIGGER_LINE(3),
476 TRIGGER_LINE(4),
477 TRIGGER_LINE(5),
478 TRIGGER_LINE(6),
479 TRIGGER_LINE(7),
480 NI_CtrSource(0),
481 NI_CtrSource(1),
482 NI_CtrGate(0),
483 NI_CtrGate(1),
484 NI_CtrInternalOutput(0),
485 NI_CtrInternalOutput(1),
486 NI_AI_SampleClock,
487 NI_AI_StartTrigger,
488 NI_AI_ReferenceTrigger,
489 NI_AI_ConvertClock,
490 NI_DI_SampleClock,
491 NI_DO_SampleClock,
492 NI_FrequencyOutput,
493 NI_ChangeDetectionEvent,
494 NI_AnalogComparisonEvent,
495 0, /* Termination */
496 }
497 },
498 {
499 .dest = TRIGGER_LINE(0),
500 .src = (int[]){
501 NI_PFI(0),
502 NI_PFI(1),
503 NI_PFI(2),
504 NI_PFI(3),
505 NI_PFI(4),
506 NI_PFI(5),
507 NI_CtrSource(0),
508 NI_CtrSource(1),
509 NI_CtrGate(0),
510 NI_CtrGate(1),
511 NI_CtrInternalOutput(0),
512 NI_CtrInternalOutput(1),
513 NI_AI_SampleClock,
514 NI_AI_StartTrigger,
515 NI_AI_ReferenceTrigger,
516 NI_AI_ConvertClock,
517 NI_AI_PauseTrigger,
518 NI_10MHzRefClock,
519 NI_FrequencyOutput,
520 NI_ChangeDetectionEvent,
521 NI_AnalogComparisonEvent,
522 0, /* Termination */
523 }
524 },
525 {
526 .dest = TRIGGER_LINE(1),
527 .src = (int[]){
528 NI_PFI(0),
529 NI_PFI(1),
530 NI_PFI(2),
531 NI_PFI(3),
532 NI_PFI(4),
533 NI_PFI(5),
534 NI_CtrSource(0),
535 NI_CtrSource(1),
536 NI_CtrGate(0),
537 NI_CtrGate(1),
538 NI_CtrInternalOutput(0),
539 NI_CtrInternalOutput(1),
540 NI_AI_SampleClock,
541 NI_AI_StartTrigger,
542 NI_AI_ReferenceTrigger,
543 NI_AI_ConvertClock,
544 NI_AI_PauseTrigger,
545 NI_10MHzRefClock,
546 NI_FrequencyOutput,
547 NI_ChangeDetectionEvent,
548 NI_AnalogComparisonEvent,
549 0, /* Termination */
550 }
551 },
552 {
553 .dest = TRIGGER_LINE(2),
554 .src = (int[]){
555 NI_PFI(0),
556 NI_PFI(1),
557 NI_PFI(2),
558 NI_PFI(3),
559 NI_PFI(4),
560 NI_PFI(5),
561 NI_CtrSource(0),
562 NI_CtrSource(1),
563 NI_CtrGate(0),
564 NI_CtrGate(1),
565 NI_CtrInternalOutput(0),
566 NI_CtrInternalOutput(1),
567 NI_AI_SampleClock,
568 NI_AI_StartTrigger,
569 NI_AI_ReferenceTrigger,
570 NI_AI_ConvertClock,
571 NI_AI_PauseTrigger,
572 NI_10MHzRefClock,
573 NI_FrequencyOutput,
574 NI_ChangeDetectionEvent,
575 NI_AnalogComparisonEvent,
576 0, /* Termination */
577 }
578 },
579 {
580 .dest = TRIGGER_LINE(3),
581 .src = (int[]){
582 NI_PFI(0),
583 NI_PFI(1),
584 NI_PFI(2),
585 NI_PFI(3),
586 NI_PFI(4),
587 NI_PFI(5),
588 NI_CtrSource(0),
589 NI_CtrSource(1),
590 NI_CtrGate(0),
591 NI_CtrGate(1),
592 NI_CtrInternalOutput(0),
593 NI_CtrInternalOutput(1),
594 NI_AI_SampleClock,
595 NI_AI_StartTrigger,
596 NI_AI_ReferenceTrigger,
597 NI_AI_ConvertClock,
598 NI_AI_PauseTrigger,
599 NI_10MHzRefClock,
600 NI_FrequencyOutput,
601 NI_ChangeDetectionEvent,
602 NI_AnalogComparisonEvent,
603 0, /* Termination */
604 }
605 },
606 {
607 .dest = TRIGGER_LINE(4),
608 .src = (int[]){
609 NI_PFI(0),
610 NI_PFI(1),
611 NI_PFI(2),
612 NI_PFI(3),
613 NI_PFI(4),
614 NI_PFI(5),
615 NI_CtrSource(0),
616 NI_CtrSource(1),
617 NI_CtrGate(0),
618 NI_CtrGate(1),
619 NI_CtrInternalOutput(0),
620 NI_CtrInternalOutput(1),
621 NI_AI_SampleClock,
622 NI_AI_StartTrigger,
623 NI_AI_ReferenceTrigger,
624 NI_AI_ConvertClock,
625 NI_AI_PauseTrigger,
626 NI_10MHzRefClock,
627 NI_FrequencyOutput,
628 NI_ChangeDetectionEvent,
629 NI_AnalogComparisonEvent,
630 0, /* Termination */
631 }
632 },
633 {
634 .dest = TRIGGER_LINE(5),
635 .src = (int[]){
636 NI_PFI(0),
637 NI_PFI(1),
638 NI_PFI(2),
639 NI_PFI(3),
640 NI_PFI(4),
641 NI_PFI(5),
642 NI_CtrSource(0),
643 NI_CtrSource(1),
644 NI_CtrGate(0),
645 NI_CtrGate(1),
646 NI_CtrInternalOutput(0),
647 NI_CtrInternalOutput(1),
648 NI_AI_SampleClock,
649 NI_AI_StartTrigger,
650 NI_AI_ReferenceTrigger,
651 NI_AI_ConvertClock,
652 NI_AI_PauseTrigger,
653 NI_10MHzRefClock,
654 NI_FrequencyOutput,
655 NI_ChangeDetectionEvent,
656 NI_AnalogComparisonEvent,
657 0, /* Termination */
658 }
659 },
660 {
661 .dest = TRIGGER_LINE(6),
662 .src = (int[]){
663 NI_PFI(0),
664 NI_PFI(1),
665 NI_PFI(2),
666 NI_PFI(3),
667 NI_PFI(4),
668 NI_PFI(5),
669 NI_CtrSource(0),
670 NI_CtrSource(1),
671 NI_CtrGate(0),
672 NI_CtrGate(1),
673 NI_CtrInternalOutput(0),
674 NI_CtrInternalOutput(1),
675 NI_AI_SampleClock,
676 NI_AI_StartTrigger,
677 NI_AI_ReferenceTrigger,
678 NI_AI_ConvertClock,
679 NI_AI_PauseTrigger,
680 NI_10MHzRefClock,
681 NI_FrequencyOutput,
682 NI_ChangeDetectionEvent,
683 NI_AnalogComparisonEvent,
684 0, /* Termination */
685 }
686 },
687 {
688 .dest = TRIGGER_LINE(7),
689 .src = (int[]){
690 NI_PFI(0),
691 NI_PFI(1),
692 NI_PFI(2),
693 NI_PFI(3),
694 NI_PFI(4),
695 NI_PFI(5),
696 NI_CtrSource(0),
697 NI_CtrSource(1),
698 NI_CtrGate(0),
699 NI_CtrGate(1),
700 NI_CtrInternalOutput(0),
701 NI_CtrInternalOutput(1),
702 NI_AI_SampleClock,
703 NI_AI_StartTrigger,
704 NI_AI_ReferenceTrigger,
705 NI_AI_ConvertClock,
706 NI_AI_PauseTrigger,
707 NI_10MHzRefClock,
708 NI_FrequencyOutput,
709 NI_ChangeDetectionEvent,
710 NI_AnalogComparisonEvent,
711 0, /* Termination */
712 }
713 },
714 {
715 .dest = NI_CtrSource(0),
716 .src = (int[]){
717 NI_PFI(0),
718 NI_PFI(1),
719 NI_PFI(2),
720 NI_PFI(3),
721 NI_PFI(4),
722 NI_PFI(5),
723 NI_PFI(6),
724 NI_PFI(7),
725 NI_PFI(8),
726 NI_PFI(9),
727 NI_PFI(10),
728 NI_PFI(11),
729 NI_PFI(12),
730 NI_PFI(13),
731 NI_PFI(14),
732 NI_PFI(15),
733 TRIGGER_LINE(0),
734 TRIGGER_LINE(1),
735 TRIGGER_LINE(2),
736 TRIGGER_LINE(3),
737 TRIGGER_LINE(4),
738 TRIGGER_LINE(5),
739 TRIGGER_LINE(6),
740 TRIGGER_LINE(7),
741 NI_CtrGate(1),
742 NI_20MHzTimebase,
743 NI_80MHzTimebase,
744 NI_100kHzTimebase,
745 NI_AnalogComparisonEvent,
746 0, /* Termination */
747 }
748 },
749 {
750 .dest = NI_CtrSource(1),
751 .src = (int[]){
752 NI_PFI(0),
753 NI_PFI(1),
754 NI_PFI(2),
755 NI_PFI(3),
756 NI_PFI(4),
757 NI_PFI(5),
758 NI_PFI(6),
759 NI_PFI(7),
760 NI_PFI(8),
761 NI_PFI(9),
762 NI_PFI(10),
763 NI_PFI(11),
764 NI_PFI(12),
765 NI_PFI(13),
766 NI_PFI(14),
767 NI_PFI(15),
768 TRIGGER_LINE(0),
769 TRIGGER_LINE(1),
770 TRIGGER_LINE(2),
771 TRIGGER_LINE(3),
772 TRIGGER_LINE(4),
773 TRIGGER_LINE(5),
774 TRIGGER_LINE(6),
775 TRIGGER_LINE(7),
776 NI_CtrGate(0),
777 NI_20MHzTimebase,
778 NI_80MHzTimebase,
779 NI_100kHzTimebase,
780 NI_AnalogComparisonEvent,
781 0, /* Termination */
782 }
783 },
784 {
785 .dest = NI_CtrGate(0),
786 .src = (int[]){
787 NI_PFI(0),
788 NI_PFI(1),
789 NI_PFI(2),
790 NI_PFI(3),
791 NI_PFI(4),
792 NI_PFI(5),
793 NI_PFI(6),
794 NI_PFI(7),
795 NI_PFI(8),
796 NI_PFI(9),
797 NI_PFI(10),
798 NI_PFI(11),
799 NI_PFI(12),
800 NI_PFI(13),
801 NI_PFI(14),
802 NI_PFI(15),
803 TRIGGER_LINE(0),
804 TRIGGER_LINE(1),
805 TRIGGER_LINE(2),
806 TRIGGER_LINE(3),
807 TRIGGER_LINE(4),
808 TRIGGER_LINE(5),
809 TRIGGER_LINE(6),
810 TRIGGER_LINE(7),
811 NI_CtrSource(1),
812 NI_CtrInternalOutput(1),
813 NI_AI_StartTrigger,
814 NI_AI_ReferenceTrigger,
815 NI_AnalogComparisonEvent,
816 0, /* Termination */
817 }
818 },
819 {
820 .dest = NI_CtrGate(1),
821 .src = (int[]){
822 NI_PFI(0),
823 NI_PFI(1),
824 NI_PFI(2),
825 NI_PFI(3),
826 NI_PFI(4),
827 NI_PFI(5),
828 NI_PFI(6),
829 NI_PFI(7),
830 NI_PFI(8),
831 NI_PFI(9),
832 NI_PFI(10),
833 NI_PFI(11),
834 NI_PFI(12),
835 NI_PFI(13),
836 NI_PFI(14),
837 NI_PFI(15),
838 TRIGGER_LINE(0),
839 TRIGGER_LINE(1),
840 TRIGGER_LINE(2),
841 TRIGGER_LINE(3),
842 TRIGGER_LINE(4),
843 TRIGGER_LINE(5),
844 TRIGGER_LINE(6),
845 TRIGGER_LINE(7),
846 NI_CtrSource(0),
847 NI_CtrInternalOutput(0),
848 NI_AI_StartTrigger,
849 NI_AI_ReferenceTrigger,
850 NI_AnalogComparisonEvent,
851 0, /* Termination */
852 }
853 },
854 {
855 .dest = NI_CtrAux(0),
856 .src = (int[]){
857 NI_PFI(0),
858 NI_PFI(1),
859 NI_PFI(2),
860 NI_PFI(3),
861 NI_PFI(4),
862 NI_PFI(5),
863 NI_PFI(6),
864 NI_PFI(7),
865 NI_PFI(8),
866 NI_PFI(9),
867 NI_PFI(10),
868 NI_PFI(11),
869 NI_PFI(12),
870 NI_PFI(13),
871 NI_PFI(14),
872 NI_PFI(15),
873 TRIGGER_LINE(0),
874 TRIGGER_LINE(1),
875 TRIGGER_LINE(2),
876 TRIGGER_LINE(3),
877 TRIGGER_LINE(4),
878 TRIGGER_LINE(5),
879 TRIGGER_LINE(6),
880 TRIGGER_LINE(7),
881 NI_CtrSource(1),
882 NI_CtrGate(0),
883 NI_CtrGate(1),
884 NI_CtrInternalOutput(1),
885 NI_AI_StartTrigger,
886 NI_AI_ReferenceTrigger,
887 NI_AnalogComparisonEvent,
888 0, /* Termination */
889 }
890 },
891 {
892 .dest = NI_CtrAux(1),
893 .src = (int[]){
894 NI_PFI(0),
895 NI_PFI(1),
896 NI_PFI(2),
897 NI_PFI(3),
898 NI_PFI(4),
899 NI_PFI(5),
900 NI_PFI(6),
901 NI_PFI(7),
902 NI_PFI(8),
903 NI_PFI(9),
904 NI_PFI(10),
905 NI_PFI(11),
906 NI_PFI(12),
907 NI_PFI(13),
908 NI_PFI(14),
909 NI_PFI(15),
910 TRIGGER_LINE(0),
911 TRIGGER_LINE(1),
912 TRIGGER_LINE(2),
913 TRIGGER_LINE(3),
914 TRIGGER_LINE(4),
915 TRIGGER_LINE(5),
916 TRIGGER_LINE(6),
917 TRIGGER_LINE(7),
918 NI_CtrSource(0),
919 NI_CtrGate(0),
920 NI_CtrGate(1),
921 NI_CtrInternalOutput(0),
922 NI_AI_StartTrigger,
923 NI_AI_ReferenceTrigger,
924 NI_AnalogComparisonEvent,
925 0, /* Termination */
926 }
927 },
928 {
929 .dest = NI_CtrA(0),
930 .src = (int[]){
931 NI_PFI(0),
932 NI_PFI(1),
933 NI_PFI(2),
934 NI_PFI(3),
935 NI_PFI(4),
936 NI_PFI(5),
937 NI_PFI(6),
938 NI_PFI(7),
939 NI_PFI(8),
940 NI_PFI(9),
941 NI_PFI(10),
942 NI_PFI(11),
943 NI_PFI(12),
944 NI_PFI(13),
945 NI_PFI(14),
946 NI_PFI(15),
947 TRIGGER_LINE(0),
948 TRIGGER_LINE(1),
949 TRIGGER_LINE(2),
950 TRIGGER_LINE(3),
951 TRIGGER_LINE(4),
952 TRIGGER_LINE(5),
953 TRIGGER_LINE(6),
954 TRIGGER_LINE(7),
955 NI_AnalogComparisonEvent,
956 0, /* Termination */
957 }
958 },
959 {
960 .dest = NI_CtrA(1),
961 .src = (int[]){
962 NI_PFI(0),
963 NI_PFI(1),
964 NI_PFI(2),
965 NI_PFI(3),
966 NI_PFI(4),
967 NI_PFI(5),
968 NI_PFI(6),
969 NI_PFI(7),
970 NI_PFI(8),
971 NI_PFI(9),
972 NI_PFI(10),
973 NI_PFI(11),
974 NI_PFI(12),
975 NI_PFI(13),
976 NI_PFI(14),
977 NI_PFI(15),
978 TRIGGER_LINE(0),
979 TRIGGER_LINE(1),
980 TRIGGER_LINE(2),
981 TRIGGER_LINE(3),
982 TRIGGER_LINE(4),
983 TRIGGER_LINE(5),
984 TRIGGER_LINE(6),
985 TRIGGER_LINE(7),
986 NI_AnalogComparisonEvent,
987 0, /* Termination */
988 }
989 },
990 {
991 .dest = NI_CtrB(0),
992 .src = (int[]){
993 NI_PFI(0),
994 NI_PFI(1),
995 NI_PFI(2),
996 NI_PFI(3),
997 NI_PFI(4),
998 NI_PFI(5),
999 NI_PFI(6),
1000 NI_PFI(7),
1001 NI_PFI(8),
1002 NI_PFI(9),
1003 NI_PFI(10),
1004 NI_PFI(11),
1005 NI_PFI(12),
1006 NI_PFI(13),
1007 NI_PFI(14),
1008 NI_PFI(15),
1009 TRIGGER_LINE(0),
1010 TRIGGER_LINE(1),
1011 TRIGGER_LINE(2),
1012 TRIGGER_LINE(3),
1013 TRIGGER_LINE(4),
1014 TRIGGER_LINE(5),
1015 TRIGGER_LINE(6),
1016 TRIGGER_LINE(7),
1017 NI_AnalogComparisonEvent,
1018 0, /* Termination */
1019 }
1020 },
1021 {
1022 .dest = NI_CtrB(1),
1023 .src = (int[]){
1024 NI_PFI(0),
1025 NI_PFI(1),
1026 NI_PFI(2),
1027 NI_PFI(3),
1028 NI_PFI(4),
1029 NI_PFI(5),
1030 NI_PFI(6),
1031 NI_PFI(7),
1032 NI_PFI(8),
1033 NI_PFI(9),
1034 NI_PFI(10),
1035 NI_PFI(11),
1036 NI_PFI(12),
1037 NI_PFI(13),
1038 NI_PFI(14),
1039 NI_PFI(15),
1040 TRIGGER_LINE(0),
1041 TRIGGER_LINE(1),
1042 TRIGGER_LINE(2),
1043 TRIGGER_LINE(3),
1044 TRIGGER_LINE(4),
1045 TRIGGER_LINE(5),
1046 TRIGGER_LINE(6),
1047 TRIGGER_LINE(7),
1048 NI_AnalogComparisonEvent,
1049 0, /* Termination */
1050 }
1051 },
1052 {
1053 .dest = NI_CtrZ(0),
1054 .src = (int[]){
1055 NI_PFI(0),
1056 NI_PFI(1),
1057 NI_PFI(2),
1058 NI_PFI(3),
1059 NI_PFI(4),
1060 NI_PFI(5),
1061 NI_PFI(6),
1062 NI_PFI(7),
1063 NI_PFI(8),
1064 NI_PFI(9),
1065 NI_PFI(10),
1066 NI_PFI(11),
1067 NI_PFI(12),
1068 NI_PFI(13),
1069 NI_PFI(14),
1070 NI_PFI(15),
1071 TRIGGER_LINE(0),
1072 TRIGGER_LINE(1),
1073 TRIGGER_LINE(2),
1074 TRIGGER_LINE(3),
1075 TRIGGER_LINE(4),
1076 TRIGGER_LINE(5),
1077 TRIGGER_LINE(6),
1078 TRIGGER_LINE(7),
1079 NI_AnalogComparisonEvent,
1080 0, /* Termination */
1081 }
1082 },
1083 {
1084 .dest = NI_CtrZ(1),
1085 .src = (int[]){
1086 NI_PFI(0),
1087 NI_PFI(1),
1088 NI_PFI(2),
1089 NI_PFI(3),
1090 NI_PFI(4),
1091 NI_PFI(5),
1092 NI_PFI(6),
1093 NI_PFI(7),
1094 NI_PFI(8),
1095 NI_PFI(9),
1096 NI_PFI(10),
1097 NI_PFI(11),
1098 NI_PFI(12),
1099 NI_PFI(13),
1100 NI_PFI(14),
1101 NI_PFI(15),
1102 TRIGGER_LINE(0),
1103 TRIGGER_LINE(1),
1104 TRIGGER_LINE(2),
1105 TRIGGER_LINE(3),
1106 TRIGGER_LINE(4),
1107 TRIGGER_LINE(5),
1108 TRIGGER_LINE(6),
1109 TRIGGER_LINE(7),
1110 NI_AnalogComparisonEvent,
1111 0, /* Termination */
1112 }
1113 },
1114 {
1115 .dest = NI_CtrArmStartTrigger(0),
1116 .src = (int[]){
1117 NI_PFI(0),
1118 NI_PFI(1),
1119 NI_PFI(2),
1120 NI_PFI(3),
1121 NI_PFI(4),
1122 NI_PFI(5),
1123 NI_PFI(6),
1124 NI_PFI(7),
1125 NI_PFI(8),
1126 NI_PFI(9),
1127 NI_PFI(10),
1128 NI_PFI(11),
1129 NI_PFI(12),
1130 NI_PFI(13),
1131 NI_PFI(14),
1132 NI_PFI(15),
1133 TRIGGER_LINE(0),
1134 TRIGGER_LINE(1),
1135 TRIGGER_LINE(2),
1136 TRIGGER_LINE(3),
1137 TRIGGER_LINE(4),
1138 TRIGGER_LINE(5),
1139 TRIGGER_LINE(6),
1140 TRIGGER_LINE(7),
1141 NI_CtrInternalOutput(1),
1142 NI_AI_StartTrigger,
1143 NI_AI_ReferenceTrigger,
1144 NI_AnalogComparisonEvent,
1145 0, /* Termination */
1146 }
1147 },
1148 {
1149 .dest = NI_CtrArmStartTrigger(1),
1150 .src = (int[]){
1151 NI_PFI(0),
1152 NI_PFI(1),
1153 NI_PFI(2),
1154 NI_PFI(3),
1155 NI_PFI(4),
1156 NI_PFI(5),
1157 NI_PFI(6),
1158 NI_PFI(7),
1159 NI_PFI(8),
1160 NI_PFI(9),
1161 NI_PFI(10),
1162 NI_PFI(11),
1163 NI_PFI(12),
1164 NI_PFI(13),
1165 NI_PFI(14),
1166 NI_PFI(15),
1167 TRIGGER_LINE(0),
1168 TRIGGER_LINE(1),
1169 TRIGGER_LINE(2),
1170 TRIGGER_LINE(3),
1171 TRIGGER_LINE(4),
1172 TRIGGER_LINE(5),
1173 TRIGGER_LINE(6),
1174 TRIGGER_LINE(7),
1175 NI_CtrInternalOutput(0),
1176 NI_AI_StartTrigger,
1177 NI_AI_ReferenceTrigger,
1178 NI_AnalogComparisonEvent,
1179 0, /* Termination */
1180 }
1181 },
1182 {
1183 .dest = NI_AI_SampleClock,
1184 .src = (int[]){
1185 NI_PFI(0),
1186 NI_PFI(1),
1187 NI_PFI(2),
1188 NI_PFI(3),
1189 NI_PFI(4),
1190 NI_PFI(5),
1191 NI_PFI(6),
1192 NI_PFI(7),
1193 NI_PFI(8),
1194 NI_PFI(9),
1195 NI_PFI(10),
1196 NI_PFI(11),
1197 NI_PFI(12),
1198 NI_PFI(13),
1199 NI_PFI(14),
1200 NI_PFI(15),
1201 TRIGGER_LINE(0),
1202 TRIGGER_LINE(1),
1203 TRIGGER_LINE(2),
1204 TRIGGER_LINE(3),
1205 TRIGGER_LINE(4),
1206 TRIGGER_LINE(5),
1207 TRIGGER_LINE(6),
1208 TRIGGER_LINE(7),
1209 NI_CtrInternalOutput(0),
1210 NI_CtrInternalOutput(1),
1211 NI_AI_SampleClockTimebase,
1212 NI_AnalogComparisonEvent,
1213 0, /* Termination */
1214 }
1215 },
1216 {
1217 .dest = NI_AI_SampleClockTimebase,
1218 .src = (int[]){
1219 NI_PFI(0),
1220 NI_PFI(1),
1221 NI_PFI(2),
1222 NI_PFI(3),
1223 NI_PFI(4),
1224 NI_PFI(5),
1225 NI_PFI(6),
1226 NI_PFI(7),
1227 NI_PFI(8),
1228 NI_PFI(9),
1229 NI_PFI(10),
1230 NI_PFI(11),
1231 NI_PFI(12),
1232 NI_PFI(13),
1233 NI_PFI(14),
1234 NI_PFI(15),
1235 TRIGGER_LINE(0),
1236 TRIGGER_LINE(1),
1237 TRIGGER_LINE(2),
1238 TRIGGER_LINE(3),
1239 TRIGGER_LINE(4),
1240 TRIGGER_LINE(5),
1241 TRIGGER_LINE(6),
1242 TRIGGER_LINE(7),
1243 NI_20MHzTimebase,
1244 NI_100kHzTimebase,
1245 NI_AnalogComparisonEvent,
1246 0, /* Termination */
1247 }
1248 },
1249 {
1250 .dest = NI_AI_StartTrigger,
1251 .src = (int[]){
1252 NI_PFI(0),
1253 NI_PFI(1),
1254 NI_PFI(2),
1255 NI_PFI(3),
1256 NI_PFI(4),
1257 NI_PFI(5),
1258 NI_PFI(6),
1259 NI_PFI(7),
1260 NI_PFI(8),
1261 NI_PFI(9),
1262 NI_PFI(10),
1263 NI_PFI(11),
1264 NI_PFI(12),
1265 NI_PFI(13),
1266 NI_PFI(14),
1267 NI_PFI(15),
1268 TRIGGER_LINE(0),
1269 TRIGGER_LINE(1),
1270 TRIGGER_LINE(2),
1271 TRIGGER_LINE(3),
1272 TRIGGER_LINE(4),
1273 TRIGGER_LINE(5),
1274 TRIGGER_LINE(6),
1275 TRIGGER_LINE(7),
1276 NI_CtrInternalOutput(0),
1277 NI_CtrInternalOutput(1),
1278 NI_AnalogComparisonEvent,
1279 0, /* Termination */
1280 }
1281 },
1282 {
1283 .dest = NI_AI_ReferenceTrigger,
1284 .src = (int[]){
1285 NI_PFI(0),
1286 NI_PFI(1),
1287 NI_PFI(2),
1288 NI_PFI(3),
1289 NI_PFI(4),
1290 NI_PFI(5),
1291 NI_PFI(6),
1292 NI_PFI(7),
1293 NI_PFI(8),
1294 NI_PFI(9),
1295 NI_PFI(10),
1296 NI_PFI(11),
1297 NI_PFI(12),
1298 NI_PFI(13),
1299 NI_PFI(14),
1300 NI_PFI(15),
1301 TRIGGER_LINE(0),
1302 TRIGGER_LINE(1),
1303 TRIGGER_LINE(2),
1304 TRIGGER_LINE(3),
1305 TRIGGER_LINE(4),
1306 TRIGGER_LINE(5),
1307 TRIGGER_LINE(6),
1308 TRIGGER_LINE(7),
1309 NI_AnalogComparisonEvent,
1310 0, /* Termination */
1311 }
1312 },
1313 {
1314 .dest = NI_AI_ConvertClock,
1315 .src = (int[]){
1316 NI_PFI(0),
1317 NI_PFI(1),
1318 NI_PFI(2),
1319 NI_PFI(3),
1320 NI_PFI(4),
1321 NI_PFI(5),
1322 NI_PFI(6),
1323 NI_PFI(7),
1324 NI_PFI(8),
1325 NI_PFI(9),
1326 NI_PFI(10),
1327 NI_PFI(11),
1328 NI_PFI(12),
1329 NI_PFI(13),
1330 NI_PFI(14),
1331 NI_PFI(15),
1332 TRIGGER_LINE(0),
1333 TRIGGER_LINE(1),
1334 TRIGGER_LINE(2),
1335 TRIGGER_LINE(3),
1336 TRIGGER_LINE(4),
1337 TRIGGER_LINE(5),
1338 TRIGGER_LINE(6),
1339 TRIGGER_LINE(7),
1340 NI_CtrInternalOutput(0),
1341 NI_CtrInternalOutput(1),
1342 NI_AI_ConvertClockTimebase,
1343 NI_AnalogComparisonEvent,
1344 0, /* Termination */
1345 }
1346 },
1347 {
1348 .dest = NI_AI_ConvertClockTimebase,
1349 .src = (int[]){
1350 NI_AI_SampleClockTimebase,
1351 NI_20MHzTimebase,
1352 0, /* Termination */
1353 }
1354 },
1355 {
1356 .dest = NI_AI_PauseTrigger,
1357 .src = (int[]){
1358 NI_PFI(0),
1359 NI_PFI(1),
1360 NI_PFI(2),
1361 NI_PFI(3),
1362 NI_PFI(4),
1363 NI_PFI(5),
1364 NI_PFI(6),
1365 NI_PFI(7),
1366 NI_PFI(8),
1367 NI_PFI(9),
1368 NI_PFI(10),
1369 NI_PFI(11),
1370 NI_PFI(12),
1371 NI_PFI(13),
1372 NI_PFI(14),
1373 NI_PFI(15),
1374 TRIGGER_LINE(0),
1375 TRIGGER_LINE(1),
1376 TRIGGER_LINE(2),
1377 TRIGGER_LINE(3),
1378 TRIGGER_LINE(4),
1379 TRIGGER_LINE(5),
1380 TRIGGER_LINE(6),
1381 TRIGGER_LINE(7),
1382 NI_AnalogComparisonEvent,
1383 0, /* Termination */
1384 }
1385 },
1386 {
1387 .dest = NI_DI_SampleClock,
1388 .src = (int[]){
1389 NI_PFI(0),
1390 NI_PFI(1),
1391 NI_PFI(2),
1392 NI_PFI(3),
1393 NI_PFI(4),
1394 NI_PFI(5),
1395 NI_PFI(6),
1396 NI_PFI(7),
1397 NI_PFI(8),
1398 NI_PFI(9),
1399 NI_PFI(10),
1400 NI_PFI(11),
1401 NI_PFI(12),
1402 NI_PFI(13),
1403 NI_PFI(14),
1404 NI_PFI(15),
1405 TRIGGER_LINE(0),
1406 TRIGGER_LINE(1),
1407 TRIGGER_LINE(2),
1408 TRIGGER_LINE(3),
1409 TRIGGER_LINE(4),
1410 TRIGGER_LINE(5),
1411 TRIGGER_LINE(6),
1412 TRIGGER_LINE(7),
1413 NI_CtrInternalOutput(0),
1414 NI_CtrInternalOutput(1),
1415 NI_AI_SampleClock,
1416 NI_AI_ConvertClock,
1417 NI_FrequencyOutput,
1418 NI_ChangeDetectionEvent,
1419 NI_AnalogComparisonEvent,
1420 0, /* Termination */
1421 }
1422 },
1423 {
1424 .dest = NI_DO_SampleClock,
1425 .src = (int[]){
1426 NI_PFI(0),
1427 NI_PFI(1),
1428 NI_PFI(2),
1429 NI_PFI(3),
1430 NI_PFI(4),
1431 NI_PFI(5),
1432 NI_PFI(6),
1433 NI_PFI(7),
1434 NI_PFI(8),
1435 NI_PFI(9),
1436 NI_PFI(10),
1437 NI_PFI(11),
1438 NI_PFI(12),
1439 NI_PFI(13),
1440 NI_PFI(14),
1441 NI_PFI(15),
1442 TRIGGER_LINE(0),
1443 TRIGGER_LINE(1),
1444 TRIGGER_LINE(2),
1445 TRIGGER_LINE(3),
1446 TRIGGER_LINE(4),
1447 TRIGGER_LINE(5),
1448 TRIGGER_LINE(6),
1449 TRIGGER_LINE(7),
1450 NI_CtrInternalOutput(0),
1451 NI_CtrInternalOutput(1),
1452 NI_AI_SampleClock,
1453 NI_AI_ConvertClock,
1454 NI_FrequencyOutput,
1455 NI_ChangeDetectionEvent,
1456 NI_AnalogComparisonEvent,
1457 0, /* Termination */
1458 }
1459 },
1460 { /* Termination of list */
1461 .dest = 0,
1462 },
1463 },
1464};
diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6259.c b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6259.c
new file mode 100644
index 000000000000..e0b5fa78c3bc
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6259.c
@@ -0,0 +1,1652 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routing/ni_device_routes/pci-6259.c
5 * List of valid routes for specific NI boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21/*
22 * The contents of this file are generated using the tools in
23 * comedi/drivers/ni_routing/tools
24 *
25 * Please use those tools to help maintain the contents of this file.
26 */
27
28#include "../ni_device_routes.h"
29#include "all.h"
30
31struct ni_device_routes ni_pci_6259_device_routes = {
32 .device = "pci-6259",
33 .routes = (struct ni_route_set[]){
34 {
35 .dest = NI_PFI(0),
36 .src = (int[]){
37 TRIGGER_LINE(0),
38 TRIGGER_LINE(1),
39 TRIGGER_LINE(2),
40 TRIGGER_LINE(3),
41 TRIGGER_LINE(4),
42 TRIGGER_LINE(5),
43 TRIGGER_LINE(6),
44 TRIGGER_LINE(7),
45 NI_CtrSource(0),
46 NI_CtrSource(1),
47 NI_CtrGate(0),
48 NI_CtrGate(1),
49 NI_CtrInternalOutput(0),
50 NI_CtrInternalOutput(1),
51 NI_AI_SampleClock,
52 NI_AI_StartTrigger,
53 NI_AI_ReferenceTrigger,
54 NI_AI_ConvertClock,
55 NI_AO_SampleClock,
56 NI_AO_StartTrigger,
57 NI_DI_SampleClock,
58 NI_DO_SampleClock,
59 NI_FrequencyOutput,
60 NI_ChangeDetectionEvent,
61 NI_AnalogComparisonEvent,
62 0, /* Termination */
63 }
64 },
65 {
66 .dest = NI_PFI(1),
67 .src = (int[]){
68 TRIGGER_LINE(0),
69 TRIGGER_LINE(1),
70 TRIGGER_LINE(2),
71 TRIGGER_LINE(3),
72 TRIGGER_LINE(4),
73 TRIGGER_LINE(5),
74 TRIGGER_LINE(6),
75 TRIGGER_LINE(7),
76 NI_CtrSource(0),
77 NI_CtrSource(1),
78 NI_CtrGate(0),
79 NI_CtrGate(1),
80 NI_CtrInternalOutput(0),
81 NI_CtrInternalOutput(1),
82 NI_AI_SampleClock,
83 NI_AI_StartTrigger,
84 NI_AI_ReferenceTrigger,
85 NI_AI_ConvertClock,
86 NI_AO_SampleClock,
87 NI_AO_StartTrigger,
88 NI_DI_SampleClock,
89 NI_DO_SampleClock,
90 NI_FrequencyOutput,
91 NI_ChangeDetectionEvent,
92 NI_AnalogComparisonEvent,
93 0, /* Termination */
94 }
95 },
96 {
97 .dest = NI_PFI(2),
98 .src = (int[]){
99 TRIGGER_LINE(0),
100 TRIGGER_LINE(1),
101 TRIGGER_LINE(2),
102 TRIGGER_LINE(3),
103 TRIGGER_LINE(4),
104 TRIGGER_LINE(5),
105 TRIGGER_LINE(6),
106 TRIGGER_LINE(7),
107 NI_CtrSource(0),
108 NI_CtrSource(1),
109 NI_CtrGate(0),
110 NI_CtrGate(1),
111 NI_CtrInternalOutput(0),
112 NI_CtrInternalOutput(1),
113 NI_AI_SampleClock,
114 NI_AI_StartTrigger,
115 NI_AI_ReferenceTrigger,
116 NI_AI_ConvertClock,
117 NI_AO_SampleClock,
118 NI_AO_StartTrigger,
119 NI_DI_SampleClock,
120 NI_DO_SampleClock,
121 NI_FrequencyOutput,
122 NI_ChangeDetectionEvent,
123 NI_AnalogComparisonEvent,
124 0, /* Termination */
125 }
126 },
127 {
128 .dest = NI_PFI(3),
129 .src = (int[]){
130 TRIGGER_LINE(0),
131 TRIGGER_LINE(1),
132 TRIGGER_LINE(2),
133 TRIGGER_LINE(3),
134 TRIGGER_LINE(4),
135 TRIGGER_LINE(5),
136 TRIGGER_LINE(6),
137 TRIGGER_LINE(7),
138 NI_CtrSource(0),
139 NI_CtrSource(1),
140 NI_CtrGate(0),
141 NI_CtrGate(1),
142 NI_CtrInternalOutput(0),
143 NI_CtrInternalOutput(1),
144 NI_AI_SampleClock,
145 NI_AI_StartTrigger,
146 NI_AI_ReferenceTrigger,
147 NI_AI_ConvertClock,
148 NI_AO_SampleClock,
149 NI_AO_StartTrigger,
150 NI_DI_SampleClock,
151 NI_DO_SampleClock,
152 NI_FrequencyOutput,
153 NI_ChangeDetectionEvent,
154 NI_AnalogComparisonEvent,
155 0, /* Termination */
156 }
157 },
158 {
159 .dest = NI_PFI(4),
160 .src = (int[]){
161 TRIGGER_LINE(0),
162 TRIGGER_LINE(1),
163 TRIGGER_LINE(2),
164 TRIGGER_LINE(3),
165 TRIGGER_LINE(4),
166 TRIGGER_LINE(5),
167 TRIGGER_LINE(6),
168 TRIGGER_LINE(7),
169 NI_CtrSource(0),
170 NI_CtrSource(1),
171 NI_CtrGate(0),
172 NI_CtrGate(1),
173 NI_CtrInternalOutput(0),
174 NI_CtrInternalOutput(1),
175 NI_AI_SampleClock,
176 NI_AI_StartTrigger,
177 NI_AI_ReferenceTrigger,
178 NI_AI_ConvertClock,
179 NI_AO_SampleClock,
180 NI_AO_StartTrigger,
181 NI_DI_SampleClock,
182 NI_DO_SampleClock,
183 NI_FrequencyOutput,
184 NI_ChangeDetectionEvent,
185 NI_AnalogComparisonEvent,
186 0, /* Termination */
187 }
188 },
189 {
190 .dest = NI_PFI(5),
191 .src = (int[]){
192 TRIGGER_LINE(0),
193 TRIGGER_LINE(1),
194 TRIGGER_LINE(2),
195 TRIGGER_LINE(3),
196 TRIGGER_LINE(4),
197 TRIGGER_LINE(5),
198 TRIGGER_LINE(6),
199 TRIGGER_LINE(7),
200 NI_CtrSource(0),
201 NI_CtrSource(1),
202 NI_CtrGate(0),
203 NI_CtrGate(1),
204 NI_CtrInternalOutput(0),
205 NI_CtrInternalOutput(1),
206 NI_AI_SampleClock,
207 NI_AI_StartTrigger,
208 NI_AI_ReferenceTrigger,
209 NI_AI_ConvertClock,
210 NI_AO_SampleClock,
211 NI_AO_StartTrigger,
212 NI_DI_SampleClock,
213 NI_DO_SampleClock,
214 NI_FrequencyOutput,
215 NI_ChangeDetectionEvent,
216 NI_AnalogComparisonEvent,
217 0, /* Termination */
218 }
219 },
220 {
221 .dest = NI_PFI(6),
222 .src = (int[]){
223 TRIGGER_LINE(0),
224 TRIGGER_LINE(1),
225 TRIGGER_LINE(2),
226 TRIGGER_LINE(3),
227 TRIGGER_LINE(4),
228 TRIGGER_LINE(5),
229 TRIGGER_LINE(6),
230 TRIGGER_LINE(7),
231 NI_CtrSource(0),
232 NI_CtrSource(1),
233 NI_CtrGate(0),
234 NI_CtrGate(1),
235 NI_CtrInternalOutput(0),
236 NI_CtrInternalOutput(1),
237 NI_AI_SampleClock,
238 NI_AI_StartTrigger,
239 NI_AI_ReferenceTrigger,
240 NI_AI_ConvertClock,
241 NI_AO_SampleClock,
242 NI_AO_StartTrigger,
243 NI_DI_SampleClock,
244 NI_DO_SampleClock,
245 NI_FrequencyOutput,
246 NI_ChangeDetectionEvent,
247 NI_AnalogComparisonEvent,
248 0, /* Termination */
249 }
250 },
251 {
252 .dest = NI_PFI(7),
253 .src = (int[]){
254 TRIGGER_LINE(0),
255 TRIGGER_LINE(1),
256 TRIGGER_LINE(2),
257 TRIGGER_LINE(3),
258 TRIGGER_LINE(4),
259 TRIGGER_LINE(5),
260 TRIGGER_LINE(6),
261 TRIGGER_LINE(7),
262 NI_CtrSource(0),
263 NI_CtrSource(1),
264 NI_CtrGate(0),
265 NI_CtrGate(1),
266 NI_CtrInternalOutput(0),
267 NI_CtrInternalOutput(1),
268 NI_AI_SampleClock,
269 NI_AI_StartTrigger,
270 NI_AI_ReferenceTrigger,
271 NI_AI_ConvertClock,
272 NI_AO_SampleClock,
273 NI_AO_StartTrigger,
274 NI_DI_SampleClock,
275 NI_DO_SampleClock,
276 NI_FrequencyOutput,
277 NI_ChangeDetectionEvent,
278 NI_AnalogComparisonEvent,
279 0, /* Termination */
280 }
281 },
282 {
283 .dest = NI_PFI(8),
284 .src = (int[]){
285 TRIGGER_LINE(0),
286 TRIGGER_LINE(1),
287 TRIGGER_LINE(2),
288 TRIGGER_LINE(3),
289 TRIGGER_LINE(4),
290 TRIGGER_LINE(5),
291 TRIGGER_LINE(6),
292 TRIGGER_LINE(7),
293 NI_CtrSource(0),
294 NI_CtrSource(1),
295 NI_CtrGate(0),
296 NI_CtrGate(1),
297 NI_CtrInternalOutput(0),
298 NI_CtrInternalOutput(1),
299 NI_AI_SampleClock,
300 NI_AI_StartTrigger,
301 NI_AI_ReferenceTrigger,
302 NI_AI_ConvertClock,
303 NI_AO_SampleClock,
304 NI_AO_StartTrigger,
305 NI_DI_SampleClock,
306 NI_DO_SampleClock,
307 NI_FrequencyOutput,
308 NI_ChangeDetectionEvent,
309 NI_AnalogComparisonEvent,
310 0, /* Termination */
311 }
312 },
313 {
314 .dest = NI_PFI(9),
315 .src = (int[]){
316 TRIGGER_LINE(0),
317 TRIGGER_LINE(1),
318 TRIGGER_LINE(2),
319 TRIGGER_LINE(3),
320 TRIGGER_LINE(4),
321 TRIGGER_LINE(5),
322 TRIGGER_LINE(6),
323 TRIGGER_LINE(7),
324 NI_CtrSource(0),
325 NI_CtrSource(1),
326 NI_CtrGate(0),
327 NI_CtrGate(1),
328 NI_CtrInternalOutput(0),
329 NI_CtrInternalOutput(1),
330 NI_AI_SampleClock,
331 NI_AI_StartTrigger,
332 NI_AI_ReferenceTrigger,
333 NI_AI_ConvertClock,
334 NI_AO_SampleClock,
335 NI_AO_StartTrigger,
336 NI_DI_SampleClock,
337 NI_DO_SampleClock,
338 NI_FrequencyOutput,
339 NI_ChangeDetectionEvent,
340 NI_AnalogComparisonEvent,
341 0, /* Termination */
342 }
343 },
344 {
345 .dest = NI_PFI(10),
346 .src = (int[]){
347 TRIGGER_LINE(0),
348 TRIGGER_LINE(1),
349 TRIGGER_LINE(2),
350 TRIGGER_LINE(3),
351 TRIGGER_LINE(4),
352 TRIGGER_LINE(5),
353 TRIGGER_LINE(6),
354 TRIGGER_LINE(7),
355 NI_CtrSource(0),
356 NI_CtrSource(1),
357 NI_CtrGate(0),
358 NI_CtrGate(1),
359 NI_CtrInternalOutput(0),
360 NI_CtrInternalOutput(1),
361 NI_AI_SampleClock,
362 NI_AI_StartTrigger,
363 NI_AI_ReferenceTrigger,
364 NI_AI_ConvertClock,
365 NI_AO_SampleClock,
366 NI_AO_StartTrigger,
367 NI_DI_SampleClock,
368 NI_DO_SampleClock,
369 NI_FrequencyOutput,
370 NI_ChangeDetectionEvent,
371 NI_AnalogComparisonEvent,
372 0, /* Termination */
373 }
374 },
375 {
376 .dest = NI_PFI(11),
377 .src = (int[]){
378 TRIGGER_LINE(0),
379 TRIGGER_LINE(1),
380 TRIGGER_LINE(2),
381 TRIGGER_LINE(3),
382 TRIGGER_LINE(4),
383 TRIGGER_LINE(5),
384 TRIGGER_LINE(6),
385 TRIGGER_LINE(7),
386 NI_CtrSource(0),
387 NI_CtrSource(1),
388 NI_CtrGate(0),
389 NI_CtrGate(1),
390 NI_CtrInternalOutput(0),
391 NI_CtrInternalOutput(1),
392 NI_AI_SampleClock,
393 NI_AI_StartTrigger,
394 NI_AI_ReferenceTrigger,
395 NI_AI_ConvertClock,
396 NI_AO_SampleClock,
397 NI_AO_StartTrigger,
398 NI_DI_SampleClock,
399 NI_DO_SampleClock,
400 NI_FrequencyOutput,
401 NI_ChangeDetectionEvent,
402 NI_AnalogComparisonEvent,
403 0, /* Termination */
404 }
405 },
406 {
407 .dest = NI_PFI(12),
408 .src = (int[]){
409 TRIGGER_LINE(0),
410 TRIGGER_LINE(1),
411 TRIGGER_LINE(2),
412 TRIGGER_LINE(3),
413 TRIGGER_LINE(4),
414 TRIGGER_LINE(5),
415 TRIGGER_LINE(6),
416 TRIGGER_LINE(7),
417 NI_CtrSource(0),
418 NI_CtrSource(1),
419 NI_CtrGate(0),
420 NI_CtrGate(1),
421 NI_CtrInternalOutput(0),
422 NI_CtrInternalOutput(1),
423 NI_AI_SampleClock,
424 NI_AI_StartTrigger,
425 NI_AI_ReferenceTrigger,
426 NI_AI_ConvertClock,
427 NI_AO_SampleClock,
428 NI_AO_StartTrigger,
429 NI_DI_SampleClock,
430 NI_DO_SampleClock,
431 NI_FrequencyOutput,
432 NI_ChangeDetectionEvent,
433 NI_AnalogComparisonEvent,
434 0, /* Termination */
435 }
436 },
437 {
438 .dest = NI_PFI(13),
439 .src = (int[]){
440 TRIGGER_LINE(0),
441 TRIGGER_LINE(1),
442 TRIGGER_LINE(2),
443 TRIGGER_LINE(3),
444 TRIGGER_LINE(4),
445 TRIGGER_LINE(5),
446 TRIGGER_LINE(6),
447 TRIGGER_LINE(7),
448 NI_CtrSource(0),
449 NI_CtrSource(1),
450 NI_CtrGate(0),
451 NI_CtrGate(1),
452 NI_CtrInternalOutput(0),
453 NI_CtrInternalOutput(1),
454 NI_AI_SampleClock,
455 NI_AI_StartTrigger,
456 NI_AI_ReferenceTrigger,
457 NI_AI_ConvertClock,
458 NI_AO_SampleClock,
459 NI_AO_StartTrigger,
460 NI_DI_SampleClock,
461 NI_DO_SampleClock,
462 NI_FrequencyOutput,
463 NI_ChangeDetectionEvent,
464 NI_AnalogComparisonEvent,
465 0, /* Termination */
466 }
467 },
468 {
469 .dest = NI_PFI(14),
470 .src = (int[]){
471 TRIGGER_LINE(0),
472 TRIGGER_LINE(1),
473 TRIGGER_LINE(2),
474 TRIGGER_LINE(3),
475 TRIGGER_LINE(4),
476 TRIGGER_LINE(5),
477 TRIGGER_LINE(6),
478 TRIGGER_LINE(7),
479 NI_CtrSource(0),
480 NI_CtrSource(1),
481 NI_CtrGate(0),
482 NI_CtrGate(1),
483 NI_CtrInternalOutput(0),
484 NI_CtrInternalOutput(1),
485 NI_AI_SampleClock,
486 NI_AI_StartTrigger,
487 NI_AI_ReferenceTrigger,
488 NI_AI_ConvertClock,
489 NI_AO_SampleClock,
490 NI_AO_StartTrigger,
491 NI_DI_SampleClock,
492 NI_DO_SampleClock,
493 NI_FrequencyOutput,
494 NI_ChangeDetectionEvent,
495 NI_AnalogComparisonEvent,
496 0, /* Termination */
497 }
498 },
499 {
500 .dest = NI_PFI(15),
501 .src = (int[]){
502 TRIGGER_LINE(0),
503 TRIGGER_LINE(1),
504 TRIGGER_LINE(2),
505 TRIGGER_LINE(3),
506 TRIGGER_LINE(4),
507 TRIGGER_LINE(5),
508 TRIGGER_LINE(6),
509 TRIGGER_LINE(7),
510 NI_CtrSource(0),
511 NI_CtrSource(1),
512 NI_CtrGate(0),
513 NI_CtrGate(1),
514 NI_CtrInternalOutput(0),
515 NI_CtrInternalOutput(1),
516 NI_AI_SampleClock,
517 NI_AI_StartTrigger,
518 NI_AI_ReferenceTrigger,
519 NI_AI_ConvertClock,
520 NI_AO_SampleClock,
521 NI_AO_StartTrigger,
522 NI_DI_SampleClock,
523 NI_DO_SampleClock,
524 NI_FrequencyOutput,
525 NI_ChangeDetectionEvent,
526 NI_AnalogComparisonEvent,
527 0, /* Termination */
528 }
529 },
530 {
531 .dest = TRIGGER_LINE(0),
532 .src = (int[]){
533 NI_PFI(0),
534 NI_PFI(1),
535 NI_PFI(2),
536 NI_PFI(3),
537 NI_PFI(4),
538 NI_PFI(5),
539 NI_CtrSource(0),
540 NI_CtrSource(1),
541 NI_CtrGate(0),
542 NI_CtrGate(1),
543 NI_CtrInternalOutput(0),
544 NI_CtrInternalOutput(1),
545 NI_AI_SampleClock,
546 NI_AI_StartTrigger,
547 NI_AI_ReferenceTrigger,
548 NI_AI_ConvertClock,
549 NI_AI_PauseTrigger,
550 NI_AO_SampleClock,
551 NI_AO_StartTrigger,
552 NI_AO_PauseTrigger,
553 NI_10MHzRefClock,
554 NI_FrequencyOutput,
555 NI_ChangeDetectionEvent,
556 NI_AnalogComparisonEvent,
557 0, /* Termination */
558 }
559 },
560 {
561 .dest = TRIGGER_LINE(1),
562 .src = (int[]){
563 NI_PFI(0),
564 NI_PFI(1),
565 NI_PFI(2),
566 NI_PFI(3),
567 NI_PFI(4),
568 NI_PFI(5),
569 NI_CtrSource(0),
570 NI_CtrSource(1),
571 NI_CtrGate(0),
572 NI_CtrGate(1),
573 NI_CtrInternalOutput(0),
574 NI_CtrInternalOutput(1),
575 NI_AI_SampleClock,
576 NI_AI_StartTrigger,
577 NI_AI_ReferenceTrigger,
578 NI_AI_ConvertClock,
579 NI_AI_PauseTrigger,
580 NI_AO_SampleClock,
581 NI_AO_StartTrigger,
582 NI_AO_PauseTrigger,
583 NI_10MHzRefClock,
584 NI_FrequencyOutput,
585 NI_ChangeDetectionEvent,
586 NI_AnalogComparisonEvent,
587 0, /* Termination */
588 }
589 },
590 {
591 .dest = TRIGGER_LINE(2),
592 .src = (int[]){
593 NI_PFI(0),
594 NI_PFI(1),
595 NI_PFI(2),
596 NI_PFI(3),
597 NI_PFI(4),
598 NI_PFI(5),
599 NI_CtrSource(0),
600 NI_CtrSource(1),
601 NI_CtrGate(0),
602 NI_CtrGate(1),
603 NI_CtrInternalOutput(0),
604 NI_CtrInternalOutput(1),
605 NI_AI_SampleClock,
606 NI_AI_StartTrigger,
607 NI_AI_ReferenceTrigger,
608 NI_AI_ConvertClock,
609 NI_AI_PauseTrigger,
610 NI_AO_SampleClock,
611 NI_AO_StartTrigger,
612 NI_AO_PauseTrigger,
613 NI_10MHzRefClock,
614 NI_FrequencyOutput,
615 NI_ChangeDetectionEvent,
616 NI_AnalogComparisonEvent,
617 0, /* Termination */
618 }
619 },
620 {
621 .dest = TRIGGER_LINE(3),
622 .src = (int[]){
623 NI_PFI(0),
624 NI_PFI(1),
625 NI_PFI(2),
626 NI_PFI(3),
627 NI_PFI(4),
628 NI_PFI(5),
629 NI_CtrSource(0),
630 NI_CtrSource(1),
631 NI_CtrGate(0),
632 NI_CtrGate(1),
633 NI_CtrInternalOutput(0),
634 NI_CtrInternalOutput(1),
635 NI_AI_SampleClock,
636 NI_AI_StartTrigger,
637 NI_AI_ReferenceTrigger,
638 NI_AI_ConvertClock,
639 NI_AI_PauseTrigger,
640 NI_AO_SampleClock,
641 NI_AO_StartTrigger,
642 NI_AO_PauseTrigger,
643 NI_10MHzRefClock,
644 NI_FrequencyOutput,
645 NI_ChangeDetectionEvent,
646 NI_AnalogComparisonEvent,
647 0, /* Termination */
648 }
649 },
650 {
651 .dest = TRIGGER_LINE(4),
652 .src = (int[]){
653 NI_PFI(0),
654 NI_PFI(1),
655 NI_PFI(2),
656 NI_PFI(3),
657 NI_PFI(4),
658 NI_PFI(5),
659 NI_CtrSource(0),
660 NI_CtrSource(1),
661 NI_CtrGate(0),
662 NI_CtrGate(1),
663 NI_CtrInternalOutput(0),
664 NI_CtrInternalOutput(1),
665 NI_AI_SampleClock,
666 NI_AI_StartTrigger,
667 NI_AI_ReferenceTrigger,
668 NI_AI_ConvertClock,
669 NI_AI_PauseTrigger,
670 NI_AO_SampleClock,
671 NI_AO_StartTrigger,
672 NI_AO_PauseTrigger,
673 NI_10MHzRefClock,
674 NI_FrequencyOutput,
675 NI_ChangeDetectionEvent,
676 NI_AnalogComparisonEvent,
677 0, /* Termination */
678 }
679 },
680 {
681 .dest = TRIGGER_LINE(5),
682 .src = (int[]){
683 NI_PFI(0),
684 NI_PFI(1),
685 NI_PFI(2),
686 NI_PFI(3),
687 NI_PFI(4),
688 NI_PFI(5),
689 NI_CtrSource(0),
690 NI_CtrSource(1),
691 NI_CtrGate(0),
692 NI_CtrGate(1),
693 NI_CtrInternalOutput(0),
694 NI_CtrInternalOutput(1),
695 NI_AI_SampleClock,
696 NI_AI_StartTrigger,
697 NI_AI_ReferenceTrigger,
698 NI_AI_ConvertClock,
699 NI_AI_PauseTrigger,
700 NI_AO_SampleClock,
701 NI_AO_StartTrigger,
702 NI_AO_PauseTrigger,
703 NI_10MHzRefClock,
704 NI_FrequencyOutput,
705 NI_ChangeDetectionEvent,
706 NI_AnalogComparisonEvent,
707 0, /* Termination */
708 }
709 },
710 {
711 .dest = TRIGGER_LINE(6),
712 .src = (int[]){
713 NI_PFI(0),
714 NI_PFI(1),
715 NI_PFI(2),
716 NI_PFI(3),
717 NI_PFI(4),
718 NI_PFI(5),
719 NI_CtrSource(0),
720 NI_CtrSource(1),
721 NI_CtrGate(0),
722 NI_CtrGate(1),
723 NI_CtrInternalOutput(0),
724 NI_CtrInternalOutput(1),
725 NI_AI_SampleClock,
726 NI_AI_StartTrigger,
727 NI_AI_ReferenceTrigger,
728 NI_AI_ConvertClock,
729 NI_AI_PauseTrigger,
730 NI_AO_SampleClock,
731 NI_AO_StartTrigger,
732 NI_AO_PauseTrigger,
733 NI_10MHzRefClock,
734 NI_FrequencyOutput,
735 NI_ChangeDetectionEvent,
736 NI_AnalogComparisonEvent,
737 0, /* Termination */
738 }
739 },
740 {
741 .dest = TRIGGER_LINE(7),
742 .src = (int[]){
743 NI_PFI(0),
744 NI_PFI(1),
745 NI_PFI(2),
746 NI_PFI(3),
747 NI_PFI(4),
748 NI_PFI(5),
749 NI_CtrSource(0),
750 NI_CtrSource(1),
751 NI_CtrGate(0),
752 NI_CtrGate(1),
753 NI_CtrInternalOutput(0),
754 NI_CtrInternalOutput(1),
755 NI_AI_SampleClock,
756 NI_AI_StartTrigger,
757 NI_AI_ReferenceTrigger,
758 NI_AI_ConvertClock,
759 NI_AI_PauseTrigger,
760 NI_AO_SampleClock,
761 NI_AO_StartTrigger,
762 NI_AO_PauseTrigger,
763 NI_10MHzRefClock,
764 NI_FrequencyOutput,
765 NI_ChangeDetectionEvent,
766 NI_AnalogComparisonEvent,
767 0, /* Termination */
768 }
769 },
770 {
771 .dest = NI_CtrSource(0),
772 .src = (int[]){
773 NI_PFI(0),
774 NI_PFI(1),
775 NI_PFI(2),
776 NI_PFI(3),
777 NI_PFI(4),
778 NI_PFI(5),
779 NI_PFI(6),
780 NI_PFI(7),
781 NI_PFI(8),
782 NI_PFI(9),
783 NI_PFI(10),
784 NI_PFI(11),
785 NI_PFI(12),
786 NI_PFI(13),
787 NI_PFI(14),
788 NI_PFI(15),
789 TRIGGER_LINE(0),
790 TRIGGER_LINE(1),
791 TRIGGER_LINE(2),
792 TRIGGER_LINE(3),
793 TRIGGER_LINE(4),
794 TRIGGER_LINE(5),
795 TRIGGER_LINE(6),
796 TRIGGER_LINE(7),
797 NI_CtrGate(1),
798 NI_20MHzTimebase,
799 NI_80MHzTimebase,
800 NI_100kHzTimebase,
801 NI_AnalogComparisonEvent,
802 0, /* Termination */
803 }
804 },
805 {
806 .dest = NI_CtrSource(1),
807 .src = (int[]){
808 NI_PFI(0),
809 NI_PFI(1),
810 NI_PFI(2),
811 NI_PFI(3),
812 NI_PFI(4),
813 NI_PFI(5),
814 NI_PFI(6),
815 NI_PFI(7),
816 NI_PFI(8),
817 NI_PFI(9),
818 NI_PFI(10),
819 NI_PFI(11),
820 NI_PFI(12),
821 NI_PFI(13),
822 NI_PFI(14),
823 NI_PFI(15),
824 TRIGGER_LINE(0),
825 TRIGGER_LINE(1),
826 TRIGGER_LINE(2),
827 TRIGGER_LINE(3),
828 TRIGGER_LINE(4),
829 TRIGGER_LINE(5),
830 TRIGGER_LINE(6),
831 TRIGGER_LINE(7),
832 NI_CtrGate(0),
833 NI_20MHzTimebase,
834 NI_80MHzTimebase,
835 NI_100kHzTimebase,
836 NI_AnalogComparisonEvent,
837 0, /* Termination */
838 }
839 },
840 {
841 .dest = NI_CtrGate(0),
842 .src = (int[]){
843 NI_PFI(0),
844 NI_PFI(1),
845 NI_PFI(2),
846 NI_PFI(3),
847 NI_PFI(4),
848 NI_PFI(5),
849 NI_PFI(6),
850 NI_PFI(7),
851 NI_PFI(8),
852 NI_PFI(9),
853 NI_PFI(10),
854 NI_PFI(11),
855 NI_PFI(12),
856 NI_PFI(13),
857 NI_PFI(14),
858 NI_PFI(15),
859 TRIGGER_LINE(0),
860 TRIGGER_LINE(1),
861 TRIGGER_LINE(2),
862 TRIGGER_LINE(3),
863 TRIGGER_LINE(4),
864 TRIGGER_LINE(5),
865 TRIGGER_LINE(6),
866 TRIGGER_LINE(7),
867 NI_CtrSource(1),
868 NI_CtrInternalOutput(1),
869 NI_AI_StartTrigger,
870 NI_AI_ReferenceTrigger,
871 NI_AnalogComparisonEvent,
872 0, /* Termination */
873 }
874 },
875 {
876 .dest = NI_CtrGate(1),
877 .src = (int[]){
878 NI_PFI(0),
879 NI_PFI(1),
880 NI_PFI(2),
881 NI_PFI(3),
882 NI_PFI(4),
883 NI_PFI(5),
884 NI_PFI(6),
885 NI_PFI(7),
886 NI_PFI(8),
887 NI_PFI(9),
888 NI_PFI(10),
889 NI_PFI(11),
890 NI_PFI(12),
891 NI_PFI(13),
892 NI_PFI(14),
893 NI_PFI(15),
894 TRIGGER_LINE(0),
895 TRIGGER_LINE(1),
896 TRIGGER_LINE(2),
897 TRIGGER_LINE(3),
898 TRIGGER_LINE(4),
899 TRIGGER_LINE(5),
900 TRIGGER_LINE(6),
901 TRIGGER_LINE(7),
902 NI_CtrSource(0),
903 NI_CtrInternalOutput(0),
904 NI_AI_StartTrigger,
905 NI_AI_ReferenceTrigger,
906 NI_AnalogComparisonEvent,
907 0, /* Termination */
908 }
909 },
910 {
911 .dest = NI_CtrAux(0),
912 .src = (int[]){
913 NI_PFI(0),
914 NI_PFI(1),
915 NI_PFI(2),
916 NI_PFI(3),
917 NI_PFI(4),
918 NI_PFI(5),
919 NI_PFI(6),
920 NI_PFI(7),
921 NI_PFI(8),
922 NI_PFI(9),
923 NI_PFI(10),
924 NI_PFI(11),
925 NI_PFI(12),
926 NI_PFI(13),
927 NI_PFI(14),
928 NI_PFI(15),
929 TRIGGER_LINE(0),
930 TRIGGER_LINE(1),
931 TRIGGER_LINE(2),
932 TRIGGER_LINE(3),
933 TRIGGER_LINE(4),
934 TRIGGER_LINE(5),
935 TRIGGER_LINE(6),
936 TRIGGER_LINE(7),
937 NI_CtrSource(1),
938 NI_CtrGate(0),
939 NI_CtrGate(1),
940 NI_CtrInternalOutput(1),
941 NI_AI_StartTrigger,
942 NI_AI_ReferenceTrigger,
943 NI_AnalogComparisonEvent,
944 0, /* Termination */
945 }
946 },
947 {
948 .dest = NI_CtrAux(1),
949 .src = (int[]){
950 NI_PFI(0),
951 NI_PFI(1),
952 NI_PFI(2),
953 NI_PFI(3),
954 NI_PFI(4),
955 NI_PFI(5),
956 NI_PFI(6),
957 NI_PFI(7),
958 NI_PFI(8),
959 NI_PFI(9),
960 NI_PFI(10),
961 NI_PFI(11),
962 NI_PFI(12),
963 NI_PFI(13),
964 NI_PFI(14),
965 NI_PFI(15),
966 TRIGGER_LINE(0),
967 TRIGGER_LINE(1),
968 TRIGGER_LINE(2),
969 TRIGGER_LINE(3),
970 TRIGGER_LINE(4),
971 TRIGGER_LINE(5),
972 TRIGGER_LINE(6),
973 TRIGGER_LINE(7),
974 NI_CtrSource(0),
975 NI_CtrGate(0),
976 NI_CtrGate(1),
977 NI_CtrInternalOutput(0),
978 NI_AI_StartTrigger,
979 NI_AI_ReferenceTrigger,
980 NI_AnalogComparisonEvent,
981 0, /* Termination */
982 }
983 },
984 {
985 .dest = NI_CtrA(0),
986 .src = (int[]){
987 NI_PFI(0),
988 NI_PFI(1),
989 NI_PFI(2),
990 NI_PFI(3),
991 NI_PFI(4),
992 NI_PFI(5),
993 NI_PFI(6),
994 NI_PFI(7),
995 NI_PFI(8),
996 NI_PFI(9),
997 NI_PFI(10),
998 NI_PFI(11),
999 NI_PFI(12),
1000 NI_PFI(13),
1001 NI_PFI(14),
1002 NI_PFI(15),
1003 TRIGGER_LINE(0),
1004 TRIGGER_LINE(1),
1005 TRIGGER_LINE(2),
1006 TRIGGER_LINE(3),
1007 TRIGGER_LINE(4),
1008 TRIGGER_LINE(5),
1009 TRIGGER_LINE(6),
1010 TRIGGER_LINE(7),
1011 NI_AnalogComparisonEvent,
1012 0, /* Termination */
1013 }
1014 },
1015 {
1016 .dest = NI_CtrA(1),
1017 .src = (int[]){
1018 NI_PFI(0),
1019 NI_PFI(1),
1020 NI_PFI(2),
1021 NI_PFI(3),
1022 NI_PFI(4),
1023 NI_PFI(5),
1024 NI_PFI(6),
1025 NI_PFI(7),
1026 NI_PFI(8),
1027 NI_PFI(9),
1028 NI_PFI(10),
1029 NI_PFI(11),
1030 NI_PFI(12),
1031 NI_PFI(13),
1032 NI_PFI(14),
1033 NI_PFI(15),
1034 TRIGGER_LINE(0),
1035 TRIGGER_LINE(1),
1036 TRIGGER_LINE(2),
1037 TRIGGER_LINE(3),
1038 TRIGGER_LINE(4),
1039 TRIGGER_LINE(5),
1040 TRIGGER_LINE(6),
1041 TRIGGER_LINE(7),
1042 NI_AnalogComparisonEvent,
1043 0, /* Termination */
1044 }
1045 },
1046 {
1047 .dest = NI_CtrB(0),
1048 .src = (int[]){
1049 NI_PFI(0),
1050 NI_PFI(1),
1051 NI_PFI(2),
1052 NI_PFI(3),
1053 NI_PFI(4),
1054 NI_PFI(5),
1055 NI_PFI(6),
1056 NI_PFI(7),
1057 NI_PFI(8),
1058 NI_PFI(9),
1059 NI_PFI(10),
1060 NI_PFI(11),
1061 NI_PFI(12),
1062 NI_PFI(13),
1063 NI_PFI(14),
1064 NI_PFI(15),
1065 TRIGGER_LINE(0),
1066 TRIGGER_LINE(1),
1067 TRIGGER_LINE(2),
1068 TRIGGER_LINE(3),
1069 TRIGGER_LINE(4),
1070 TRIGGER_LINE(5),
1071 TRIGGER_LINE(6),
1072 TRIGGER_LINE(7),
1073 NI_AnalogComparisonEvent,
1074 0, /* Termination */
1075 }
1076 },
1077 {
1078 .dest = NI_CtrB(1),
1079 .src = (int[]){
1080 NI_PFI(0),
1081 NI_PFI(1),
1082 NI_PFI(2),
1083 NI_PFI(3),
1084 NI_PFI(4),
1085 NI_PFI(5),
1086 NI_PFI(6),
1087 NI_PFI(7),
1088 NI_PFI(8),
1089 NI_PFI(9),
1090 NI_PFI(10),
1091 NI_PFI(11),
1092 NI_PFI(12),
1093 NI_PFI(13),
1094 NI_PFI(14),
1095 NI_PFI(15),
1096 TRIGGER_LINE(0),
1097 TRIGGER_LINE(1),
1098 TRIGGER_LINE(2),
1099 TRIGGER_LINE(3),
1100 TRIGGER_LINE(4),
1101 TRIGGER_LINE(5),
1102 TRIGGER_LINE(6),
1103 TRIGGER_LINE(7),
1104 NI_AnalogComparisonEvent,
1105 0, /* Termination */
1106 }
1107 },
1108 {
1109 .dest = NI_CtrZ(0),
1110 .src = (int[]){
1111 NI_PFI(0),
1112 NI_PFI(1),
1113 NI_PFI(2),
1114 NI_PFI(3),
1115 NI_PFI(4),
1116 NI_PFI(5),
1117 NI_PFI(6),
1118 NI_PFI(7),
1119 NI_PFI(8),
1120 NI_PFI(9),
1121 NI_PFI(10),
1122 NI_PFI(11),
1123 NI_PFI(12),
1124 NI_PFI(13),
1125 NI_PFI(14),
1126 NI_PFI(15),
1127 TRIGGER_LINE(0),
1128 TRIGGER_LINE(1),
1129 TRIGGER_LINE(2),
1130 TRIGGER_LINE(3),
1131 TRIGGER_LINE(4),
1132 TRIGGER_LINE(5),
1133 TRIGGER_LINE(6),
1134 TRIGGER_LINE(7),
1135 NI_AnalogComparisonEvent,
1136 0, /* Termination */
1137 }
1138 },
1139 {
1140 .dest = NI_CtrZ(1),
1141 .src = (int[]){
1142 NI_PFI(0),
1143 NI_PFI(1),
1144 NI_PFI(2),
1145 NI_PFI(3),
1146 NI_PFI(4),
1147 NI_PFI(5),
1148 NI_PFI(6),
1149 NI_PFI(7),
1150 NI_PFI(8),
1151 NI_PFI(9),
1152 NI_PFI(10),
1153 NI_PFI(11),
1154 NI_PFI(12),
1155 NI_PFI(13),
1156 NI_PFI(14),
1157 NI_PFI(15),
1158 TRIGGER_LINE(0),
1159 TRIGGER_LINE(1),
1160 TRIGGER_LINE(2),
1161 TRIGGER_LINE(3),
1162 TRIGGER_LINE(4),
1163 TRIGGER_LINE(5),
1164 TRIGGER_LINE(6),
1165 TRIGGER_LINE(7),
1166 NI_AnalogComparisonEvent,
1167 0, /* Termination */
1168 }
1169 },
1170 {
1171 .dest = NI_CtrArmStartTrigger(0),
1172 .src = (int[]){
1173 NI_PFI(0),
1174 NI_PFI(1),
1175 NI_PFI(2),
1176 NI_PFI(3),
1177 NI_PFI(4),
1178 NI_PFI(5),
1179 NI_PFI(6),
1180 NI_PFI(7),
1181 NI_PFI(8),
1182 NI_PFI(9),
1183 NI_PFI(10),
1184 NI_PFI(11),
1185 NI_PFI(12),
1186 NI_PFI(13),
1187 NI_PFI(14),
1188 NI_PFI(15),
1189 TRIGGER_LINE(0),
1190 TRIGGER_LINE(1),
1191 TRIGGER_LINE(2),
1192 TRIGGER_LINE(3),
1193 TRIGGER_LINE(4),
1194 TRIGGER_LINE(5),
1195 TRIGGER_LINE(6),
1196 TRIGGER_LINE(7),
1197 NI_CtrInternalOutput(1),
1198 NI_AI_StartTrigger,
1199 NI_AI_ReferenceTrigger,
1200 NI_AnalogComparisonEvent,
1201 0, /* Termination */
1202 }
1203 },
1204 {
1205 .dest = NI_CtrArmStartTrigger(1),
1206 .src = (int[]){
1207 NI_PFI(0),
1208 NI_PFI(1),
1209 NI_PFI(2),
1210 NI_PFI(3),
1211 NI_PFI(4),
1212 NI_PFI(5),
1213 NI_PFI(6),
1214 NI_PFI(7),
1215 NI_PFI(8),
1216 NI_PFI(9),
1217 NI_PFI(10),
1218 NI_PFI(11),
1219 NI_PFI(12),
1220 NI_PFI(13),
1221 NI_PFI(14),
1222 NI_PFI(15),
1223 TRIGGER_LINE(0),
1224 TRIGGER_LINE(1),
1225 TRIGGER_LINE(2),
1226 TRIGGER_LINE(3),
1227 TRIGGER_LINE(4),
1228 TRIGGER_LINE(5),
1229 TRIGGER_LINE(6),
1230 TRIGGER_LINE(7),
1231 NI_CtrInternalOutput(0),
1232 NI_AI_StartTrigger,
1233 NI_AI_ReferenceTrigger,
1234 NI_AnalogComparisonEvent,
1235 0, /* Termination */
1236 }
1237 },
1238 {
1239 .dest = NI_AI_SampleClock,
1240 .src = (int[]){
1241 NI_PFI(0),
1242 NI_PFI(1),
1243 NI_PFI(2),
1244 NI_PFI(3),
1245 NI_PFI(4),
1246 NI_PFI(5),
1247 NI_PFI(6),
1248 NI_PFI(7),
1249 NI_PFI(8),
1250 NI_PFI(9),
1251 NI_PFI(10),
1252 NI_PFI(11),
1253 NI_PFI(12),
1254 NI_PFI(13),
1255 NI_PFI(14),
1256 NI_PFI(15),
1257 TRIGGER_LINE(0),
1258 TRIGGER_LINE(1),
1259 TRIGGER_LINE(2),
1260 TRIGGER_LINE(3),
1261 TRIGGER_LINE(4),
1262 TRIGGER_LINE(5),
1263 TRIGGER_LINE(6),
1264 TRIGGER_LINE(7),
1265 NI_CtrInternalOutput(0),
1266 NI_CtrInternalOutput(1),
1267 NI_AI_SampleClockTimebase,
1268 NI_AnalogComparisonEvent,
1269 0, /* Termination */
1270 }
1271 },
1272 {
1273 .dest = NI_AI_SampleClockTimebase,
1274 .src = (int[]){
1275 NI_PFI(0),
1276 NI_PFI(1),
1277 NI_PFI(2),
1278 NI_PFI(3),
1279 NI_PFI(4),
1280 NI_PFI(5),
1281 NI_PFI(6),
1282 NI_PFI(7),
1283 NI_PFI(8),
1284 NI_PFI(9),
1285 NI_PFI(10),
1286 NI_PFI(11),
1287 NI_PFI(12),
1288 NI_PFI(13),
1289 NI_PFI(14),
1290 NI_PFI(15),
1291 TRIGGER_LINE(0),
1292 TRIGGER_LINE(1),
1293 TRIGGER_LINE(2),
1294 TRIGGER_LINE(3),
1295 TRIGGER_LINE(4),
1296 TRIGGER_LINE(5),
1297 TRIGGER_LINE(6),
1298 TRIGGER_LINE(7),
1299 NI_20MHzTimebase,
1300 NI_100kHzTimebase,
1301 NI_AnalogComparisonEvent,
1302 0, /* Termination */
1303 }
1304 },
1305 {
1306 .dest = NI_AI_StartTrigger,
1307 .src = (int[]){
1308 NI_PFI(0),
1309 NI_PFI(1),
1310 NI_PFI(2),
1311 NI_PFI(3),
1312 NI_PFI(4),
1313 NI_PFI(5),
1314 NI_PFI(6),
1315 NI_PFI(7),
1316 NI_PFI(8),
1317 NI_PFI(9),
1318 NI_PFI(10),
1319 NI_PFI(11),
1320 NI_PFI(12),
1321 NI_PFI(13),
1322 NI_PFI(14),
1323 NI_PFI(15),
1324 TRIGGER_LINE(0),
1325 TRIGGER_LINE(1),
1326 TRIGGER_LINE(2),
1327 TRIGGER_LINE(3),
1328 TRIGGER_LINE(4),
1329 TRIGGER_LINE(5),
1330 TRIGGER_LINE(6),
1331 TRIGGER_LINE(7),
1332 NI_CtrInternalOutput(0),
1333 NI_CtrInternalOutput(1),
1334 NI_AnalogComparisonEvent,
1335 0, /* Termination */
1336 }
1337 },
1338 {
1339 .dest = NI_AI_ReferenceTrigger,
1340 .src = (int[]){
1341 NI_PFI(0),
1342 NI_PFI(1),
1343 NI_PFI(2),
1344 NI_PFI(3),
1345 NI_PFI(4),
1346 NI_PFI(5),
1347 NI_PFI(6),
1348 NI_PFI(7),
1349 NI_PFI(8),
1350 NI_PFI(9),
1351 NI_PFI(10),
1352 NI_PFI(11),
1353 NI_PFI(12),
1354 NI_PFI(13),
1355 NI_PFI(14),
1356 NI_PFI(15),
1357 TRIGGER_LINE(0),
1358 TRIGGER_LINE(1),
1359 TRIGGER_LINE(2),
1360 TRIGGER_LINE(3),
1361 TRIGGER_LINE(4),
1362 TRIGGER_LINE(5),
1363 TRIGGER_LINE(6),
1364 TRIGGER_LINE(7),
1365 NI_AnalogComparisonEvent,
1366 0, /* Termination */
1367 }
1368 },
1369 {
1370 .dest = NI_AI_ConvertClock,
1371 .src = (int[]){
1372 NI_PFI(0),
1373 NI_PFI(1),
1374 NI_PFI(2),
1375 NI_PFI(3),
1376 NI_PFI(4),
1377 NI_PFI(5),
1378 NI_PFI(6),
1379 NI_PFI(7),
1380 NI_PFI(8),
1381 NI_PFI(9),
1382 NI_PFI(10),
1383 NI_PFI(11),
1384 NI_PFI(12),
1385 NI_PFI(13),
1386 NI_PFI(14),
1387 NI_PFI(15),
1388 TRIGGER_LINE(0),
1389 TRIGGER_LINE(1),
1390 TRIGGER_LINE(2),
1391 TRIGGER_LINE(3),
1392 TRIGGER_LINE(4),
1393 TRIGGER_LINE(5),
1394 TRIGGER_LINE(6),
1395 TRIGGER_LINE(7),
1396 NI_CtrInternalOutput(0),
1397 NI_CtrInternalOutput(1),
1398 NI_AI_ConvertClockTimebase,
1399 NI_AnalogComparisonEvent,
1400 0, /* Termination */
1401 }
1402 },
1403 {
1404 .dest = NI_AI_ConvertClockTimebase,
1405 .src = (int[]){
1406 NI_AI_SampleClockTimebase,
1407 NI_20MHzTimebase,
1408 0, /* Termination */
1409 }
1410 },
1411 {
1412 .dest = NI_AI_PauseTrigger,
1413 .src = (int[]){
1414 NI_PFI(0),
1415 NI_PFI(1),
1416 NI_PFI(2),
1417 NI_PFI(3),
1418 NI_PFI(4),
1419 NI_PFI(5),
1420 NI_PFI(6),
1421 NI_PFI(7),
1422 NI_PFI(8),
1423 NI_PFI(9),
1424 NI_PFI(10),
1425 NI_PFI(11),
1426 NI_PFI(12),
1427 NI_PFI(13),
1428 NI_PFI(14),
1429 NI_PFI(15),
1430 TRIGGER_LINE(0),
1431 TRIGGER_LINE(1),
1432 TRIGGER_LINE(2),
1433 TRIGGER_LINE(3),
1434 TRIGGER_LINE(4),
1435 TRIGGER_LINE(5),
1436 TRIGGER_LINE(6),
1437 TRIGGER_LINE(7),
1438 NI_AnalogComparisonEvent,
1439 0, /* Termination */
1440 }
1441 },
1442 {
1443 .dest = NI_AO_SampleClock,
1444 .src = (int[]){
1445 NI_PFI(0),
1446 NI_PFI(1),
1447 NI_PFI(2),
1448 NI_PFI(3),
1449 NI_PFI(4),
1450 NI_PFI(5),
1451 NI_PFI(6),
1452 NI_PFI(7),
1453 NI_PFI(8),
1454 NI_PFI(9),
1455 NI_PFI(10),
1456 NI_PFI(11),
1457 NI_PFI(12),
1458 NI_PFI(13),
1459 NI_PFI(14),
1460 NI_PFI(15),
1461 TRIGGER_LINE(0),
1462 TRIGGER_LINE(1),
1463 TRIGGER_LINE(2),
1464 TRIGGER_LINE(3),
1465 TRIGGER_LINE(4),
1466 TRIGGER_LINE(5),
1467 TRIGGER_LINE(6),
1468 TRIGGER_LINE(7),
1469 NI_CtrInternalOutput(0),
1470 NI_CtrInternalOutput(1),
1471 NI_AO_SampleClockTimebase,
1472 NI_AnalogComparisonEvent,
1473 0, /* Termination */
1474 }
1475 },
1476 {
1477 .dest = NI_AO_SampleClockTimebase,
1478 .src = (int[]){
1479 NI_PFI(0),
1480 NI_PFI(1),
1481 NI_PFI(2),
1482 NI_PFI(3),
1483 NI_PFI(4),
1484 NI_PFI(5),
1485 NI_PFI(6),
1486 NI_PFI(7),
1487 NI_PFI(8),
1488 NI_PFI(9),
1489 NI_PFI(10),
1490 NI_PFI(11),
1491 NI_PFI(12),
1492 NI_PFI(13),
1493 NI_PFI(14),
1494 NI_PFI(15),
1495 TRIGGER_LINE(0),
1496 TRIGGER_LINE(1),
1497 TRIGGER_LINE(2),
1498 TRIGGER_LINE(3),
1499 TRIGGER_LINE(4),
1500 TRIGGER_LINE(5),
1501 TRIGGER_LINE(6),
1502 TRIGGER_LINE(7),
1503 NI_20MHzTimebase,
1504 NI_100kHzTimebase,
1505 NI_AnalogComparisonEvent,
1506 0, /* Termination */
1507 }
1508 },
1509 {
1510 .dest = NI_AO_StartTrigger,
1511 .src = (int[]){
1512 NI_PFI(0),
1513 NI_PFI(1),
1514 NI_PFI(2),
1515 NI_PFI(3),
1516 NI_PFI(4),
1517 NI_PFI(5),
1518 NI_PFI(6),
1519 NI_PFI(7),
1520 NI_PFI(8),
1521 NI_PFI(9),
1522 NI_PFI(10),
1523 NI_PFI(11),
1524 NI_PFI(12),
1525 NI_PFI(13),
1526 NI_PFI(14),
1527 NI_PFI(15),
1528 TRIGGER_LINE(0),
1529 TRIGGER_LINE(1),
1530 TRIGGER_LINE(2),
1531 TRIGGER_LINE(3),
1532 TRIGGER_LINE(4),
1533 TRIGGER_LINE(5),
1534 TRIGGER_LINE(6),
1535 TRIGGER_LINE(7),
1536 NI_AI_StartTrigger,
1537 NI_AnalogComparisonEvent,
1538 0, /* Termination */
1539 }
1540 },
1541 {
1542 .dest = NI_AO_PauseTrigger,
1543 .src = (int[]){
1544 NI_PFI(0),
1545 NI_PFI(1),
1546 NI_PFI(2),
1547 NI_PFI(3),
1548 NI_PFI(4),
1549 NI_PFI(5),
1550 NI_PFI(6),
1551 NI_PFI(7),
1552 NI_PFI(8),
1553 NI_PFI(9),
1554 NI_PFI(10),
1555 NI_PFI(11),
1556 NI_PFI(12),
1557 NI_PFI(13),
1558 NI_PFI(14),
1559 NI_PFI(15),
1560 TRIGGER_LINE(0),
1561 TRIGGER_LINE(1),
1562 TRIGGER_LINE(2),
1563 TRIGGER_LINE(3),
1564 TRIGGER_LINE(4),
1565 TRIGGER_LINE(5),
1566 TRIGGER_LINE(6),
1567 TRIGGER_LINE(7),
1568 NI_AnalogComparisonEvent,
1569 0, /* Termination */
1570 }
1571 },
1572 {
1573 .dest = NI_DI_SampleClock,
1574 .src = (int[]){
1575 NI_PFI(0),
1576 NI_PFI(1),
1577 NI_PFI(2),
1578 NI_PFI(3),
1579 NI_PFI(4),
1580 NI_PFI(5),
1581 NI_PFI(6),
1582 NI_PFI(7),
1583 NI_PFI(8),
1584 NI_PFI(9),
1585 NI_PFI(10),
1586 NI_PFI(11),
1587 NI_PFI(12),
1588 NI_PFI(13),
1589 NI_PFI(14),
1590 NI_PFI(15),
1591 TRIGGER_LINE(0),
1592 TRIGGER_LINE(1),
1593 TRIGGER_LINE(2),
1594 TRIGGER_LINE(3),
1595 TRIGGER_LINE(4),
1596 TRIGGER_LINE(5),
1597 TRIGGER_LINE(6),
1598 TRIGGER_LINE(7),
1599 NI_CtrInternalOutput(0),
1600 NI_CtrInternalOutput(1),
1601 NI_AI_SampleClock,
1602 NI_AI_ConvertClock,
1603 NI_AO_SampleClock,
1604 NI_FrequencyOutput,
1605 NI_ChangeDetectionEvent,
1606 NI_AnalogComparisonEvent,
1607 0, /* Termination */
1608 }
1609 },
1610 {
1611 .dest = NI_DO_SampleClock,
1612 .src = (int[]){
1613 NI_PFI(0),
1614 NI_PFI(1),
1615 NI_PFI(2),
1616 NI_PFI(3),
1617 NI_PFI(4),
1618 NI_PFI(5),
1619 NI_PFI(6),
1620 NI_PFI(7),
1621 NI_PFI(8),
1622 NI_PFI(9),
1623 NI_PFI(10),
1624 NI_PFI(11),
1625 NI_PFI(12),
1626 NI_PFI(13),
1627 NI_PFI(14),
1628 NI_PFI(15),
1629 TRIGGER_LINE(0),
1630 TRIGGER_LINE(1),
1631 TRIGGER_LINE(2),
1632 TRIGGER_LINE(3),
1633 TRIGGER_LINE(4),
1634 TRIGGER_LINE(5),
1635 TRIGGER_LINE(6),
1636 TRIGGER_LINE(7),
1637 NI_CtrInternalOutput(0),
1638 NI_CtrInternalOutput(1),
1639 NI_AI_SampleClock,
1640 NI_AI_ConvertClock,
1641 NI_AO_SampleClock,
1642 NI_FrequencyOutput,
1643 NI_ChangeDetectionEvent,
1644 NI_AnalogComparisonEvent,
1645 0, /* Termination */
1646 }
1647 },
1648 { /* Termination of list */
1649 .dest = 0,
1650 },
1651 },
1652};
diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6534.c b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6534.c
new file mode 100644
index 000000000000..a2472ed288cf
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6534.c
@@ -0,0 +1,290 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routing/ni_device_routes/pci-6534.c
5 * List of valid routes for specific NI boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21/*
22 * The contents of this file are generated using the tools in
23 * comedi/drivers/ni_routing/tools
24 *
25 * Please use those tools to help maintain the contents of this file.
26 */
27
28#include "../ni_device_routes.h"
29#include "all.h"
30
31struct ni_device_routes ni_pci_6534_device_routes = {
32 .device = "pci-6534",
33 .routes = (struct ni_route_set[]){
34 {
35 .dest = NI_PFI(0),
36 .src = (int[]){
37 TRIGGER_LINE(0),
38 TRIGGER_LINE(1),
39 TRIGGER_LINE(2),
40 TRIGGER_LINE(3),
41 TRIGGER_LINE(4),
42 TRIGGER_LINE(5),
43 TRIGGER_LINE(6),
44 0, /* Termination */
45 }
46 },
47 {
48 .dest = NI_PFI(1),
49 .src = (int[]){
50 TRIGGER_LINE(0),
51 TRIGGER_LINE(1),
52 TRIGGER_LINE(2),
53 TRIGGER_LINE(3),
54 TRIGGER_LINE(4),
55 TRIGGER_LINE(5),
56 TRIGGER_LINE(6),
57 0, /* Termination */
58 }
59 },
60 {
61 .dest = NI_PFI(2),
62 .src = (int[]){
63 TRIGGER_LINE(0),
64 TRIGGER_LINE(1),
65 TRIGGER_LINE(2),
66 TRIGGER_LINE(3),
67 TRIGGER_LINE(4),
68 TRIGGER_LINE(5),
69 TRIGGER_LINE(6),
70 0, /* Termination */
71 }
72 },
73 {
74 .dest = NI_PFI(3),
75 .src = (int[]){
76 TRIGGER_LINE(0),
77 TRIGGER_LINE(1),
78 TRIGGER_LINE(2),
79 TRIGGER_LINE(3),
80 TRIGGER_LINE(4),
81 TRIGGER_LINE(5),
82 TRIGGER_LINE(6),
83 0, /* Termination */
84 }
85 },
86 {
87 .dest = NI_PFI(4),
88 .src = (int[]){
89 TRIGGER_LINE(0),
90 TRIGGER_LINE(1),
91 TRIGGER_LINE(2),
92 TRIGGER_LINE(3),
93 TRIGGER_LINE(4),
94 TRIGGER_LINE(5),
95 TRIGGER_LINE(6),
96 0, /* Termination */
97 }
98 },
99 {
100 .dest = NI_PFI(5),
101 .src = (int[]){
102 TRIGGER_LINE(0),
103 TRIGGER_LINE(1),
104 TRIGGER_LINE(2),
105 TRIGGER_LINE(3),
106 TRIGGER_LINE(4),
107 TRIGGER_LINE(5),
108 TRIGGER_LINE(6),
109 0, /* Termination */
110 }
111 },
112 {
113 .dest = NI_PFI(6),
114 .src = (int[]){
115 TRIGGER_LINE(0),
116 TRIGGER_LINE(1),
117 TRIGGER_LINE(2),
118 TRIGGER_LINE(3),
119 TRIGGER_LINE(4),
120 TRIGGER_LINE(5),
121 TRIGGER_LINE(6),
122 0, /* Termination */
123 }
124 },
125 {
126 .dest = NI_PFI(7),
127 .src = (int[]){
128 TRIGGER_LINE(0),
129 TRIGGER_LINE(1),
130 TRIGGER_LINE(2),
131 TRIGGER_LINE(3),
132 TRIGGER_LINE(4),
133 TRIGGER_LINE(5),
134 TRIGGER_LINE(6),
135 0, /* Termination */
136 }
137 },
138 {
139 .dest = TRIGGER_LINE(0),
140 .src = (int[]){
141 NI_PFI(0),
142 NI_PFI(1),
143 NI_PFI(2),
144 NI_PFI(3),
145 NI_PFI(4),
146 NI_PFI(5),
147 NI_PFI(6),
148 TRIGGER_LINE(1),
149 TRIGGER_LINE(2),
150 TRIGGER_LINE(3),
151 TRIGGER_LINE(4),
152 TRIGGER_LINE(5),
153 TRIGGER_LINE(6),
154 0, /* Termination */
155 }
156 },
157 {
158 .dest = TRIGGER_LINE(1),
159 .src = (int[]){
160 NI_PFI(0),
161 NI_PFI(1),
162 NI_PFI(2),
163 NI_PFI(3),
164 NI_PFI(4),
165 NI_PFI(5),
166 NI_PFI(6),
167 TRIGGER_LINE(0),
168 TRIGGER_LINE(2),
169 TRIGGER_LINE(3),
170 TRIGGER_LINE(4),
171 TRIGGER_LINE(5),
172 TRIGGER_LINE(6),
173 0, /* Termination */
174 }
175 },
176 {
177 .dest = TRIGGER_LINE(2),
178 .src = (int[]){
179 NI_PFI(0),
180 NI_PFI(1),
181 NI_PFI(2),
182 NI_PFI(3),
183 NI_PFI(4),
184 NI_PFI(5),
185 NI_PFI(6),
186 TRIGGER_LINE(0),
187 TRIGGER_LINE(1),
188 TRIGGER_LINE(3),
189 TRIGGER_LINE(4),
190 TRIGGER_LINE(5),
191 TRIGGER_LINE(6),
192 0, /* Termination */
193 }
194 },
195 {
196 .dest = TRIGGER_LINE(3),
197 .src = (int[]){
198 NI_PFI(0),
199 NI_PFI(1),
200 NI_PFI(2),
201 NI_PFI(3),
202 NI_PFI(4),
203 NI_PFI(5),
204 NI_PFI(6),
205 TRIGGER_LINE(0),
206 TRIGGER_LINE(1),
207 TRIGGER_LINE(2),
208 TRIGGER_LINE(4),
209 TRIGGER_LINE(5),
210 TRIGGER_LINE(6),
211 0, /* Termination */
212 }
213 },
214 {
215 .dest = TRIGGER_LINE(4),
216 .src = (int[]){
217 NI_PFI(0),
218 NI_PFI(1),
219 NI_PFI(2),
220 NI_PFI(3),
221 NI_PFI(4),
222 NI_PFI(5),
223 NI_PFI(6),
224 TRIGGER_LINE(0),
225 TRIGGER_LINE(1),
226 TRIGGER_LINE(2),
227 TRIGGER_LINE(3),
228 TRIGGER_LINE(5),
229 TRIGGER_LINE(6),
230 0, /* Termination */
231 }
232 },
233 {
234 .dest = TRIGGER_LINE(5),
235 .src = (int[]){
236 NI_PFI(0),
237 NI_PFI(1),
238 NI_PFI(2),
239 NI_PFI(3),
240 NI_PFI(4),
241 NI_PFI(5),
242 NI_PFI(6),
243 TRIGGER_LINE(0),
244 TRIGGER_LINE(1),
245 TRIGGER_LINE(2),
246 TRIGGER_LINE(3),
247 TRIGGER_LINE(4),
248 TRIGGER_LINE(6),
249 0, /* Termination */
250 }
251 },
252 {
253 .dest = TRIGGER_LINE(6),
254 .src = (int[]){
255 NI_PFI(0),
256 NI_PFI(1),
257 NI_PFI(2),
258 NI_PFI(3),
259 NI_PFI(4),
260 NI_PFI(5),
261 NI_PFI(6),
262 TRIGGER_LINE(0),
263 TRIGGER_LINE(1),
264 TRIGGER_LINE(2),
265 TRIGGER_LINE(3),
266 TRIGGER_LINE(4),
267 TRIGGER_LINE(5),
268 0, /* Termination */
269 }
270 },
271 {
272 .dest = TRIGGER_LINE(7),
273 .src = (int[]){
274 NI_20MHzTimebase,
275 0, /* Termination */
276 }
277 },
278 {
279 .dest = NI_MasterTimebase,
280 .src = (int[]){
281 TRIGGER_LINE(7),
282 NI_20MHzTimebase,
283 0, /* Termination */
284 }
285 },
286 { /* Termination of list */
287 .dest = 0,
288 },
289 },
290};
diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6602.c b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6602.c
new file mode 100644
index 000000000000..91de9dac2d6a
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6602.c
@@ -0,0 +1,3378 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routing/ni_device_routes/pci-6602.c
5 * List of valid routes for specific NI boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21/*
22 * The contents of this file are generated using the tools in
23 * comedi/drivers/ni_routing/tools
24 *
25 * Please use those tools to help maintain the contents of this file.
26 */
27
28#include "../ni_device_routes.h"
29#include "all.h"
30
31struct ni_device_routes ni_pci_6602_device_routes = {
32 .device = "pci-6602",
33 .routes = (struct ni_route_set[]){
34 {
35 .dest = NI_PFI(2),
36 .src = (int[]){
37 NI_80MHzTimebase,
38 0, /* Termination */
39 }
40 },
41 {
42 .dest = NI_PFI(3),
43 .src = (int[]){
44 NI_100kHzTimebase,
45 0, /* Termination */
46 }
47 },
48 {
49 .dest = NI_PFI(4),
50 .src = (int[]){
51 NI_20MHzTimebase,
52 0, /* Termination */
53 }
54 },
55 {
56 .dest = NI_PFI(6),
57 .src = (int[]){
58 NI_80MHzTimebase,
59 0, /* Termination */
60 }
61 },
62 {
63 .dest = NI_PFI(7),
64 .src = (int[]){
65 TRIGGER_LINE(7),
66 0, /* Termination */
67 }
68 },
69 {
70 .dest = NI_PFI(8),
71 .src = (int[]){
72 NI_PFI(7),
73 NI_PFI(15),
74 NI_PFI(23),
75 NI_PFI(31),
76 NI_PFI(39),
77 TRIGGER_LINE(0),
78 TRIGGER_LINE(1),
79 TRIGGER_LINE(2),
80 TRIGGER_LINE(3),
81 TRIGGER_LINE(4),
82 TRIGGER_LINE(5),
83 TRIGGER_LINE(6),
84 TRIGGER_LINE(7),
85 NI_CtrInternalOutput(0),
86 NI_CtrInternalOutput(1),
87 NI_CtrInternalOutput(2),
88 NI_CtrInternalOutput(3),
89 NI_CtrInternalOutput(4),
90 NI_CtrInternalOutput(5),
91 NI_CtrInternalOutput(6),
92 NI_CtrInternalOutput(7),
93 NI_LogicLow,
94 NI_LogicHigh,
95 0, /* Termination */
96 }
97 },
98 {
99 .dest = NI_PFI(9),
100 .src = (int[]){
101 NI_PFI(7),
102 NI_PFI(15),
103 NI_PFI(23),
104 NI_PFI(31),
105 NI_PFI(39),
106 TRIGGER_LINE(0),
107 TRIGGER_LINE(1),
108 TRIGGER_LINE(2),
109 TRIGGER_LINE(3),
110 TRIGGER_LINE(4),
111 TRIGGER_LINE(5),
112 TRIGGER_LINE(6),
113 TRIGGER_LINE(7),
114 NI_CtrInternalOutput(0),
115 NI_CtrInternalOutput(1),
116 NI_CtrInternalOutput(2),
117 NI_CtrInternalOutput(3),
118 NI_CtrInternalOutput(4),
119 NI_CtrInternalOutput(5),
120 NI_CtrInternalOutput(6),
121 NI_CtrInternalOutput(7),
122 NI_LogicLow,
123 NI_LogicHigh,
124 0, /* Termination */
125 }
126 },
127 {
128 .dest = NI_PFI(10),
129 .src = (int[]){
130 NI_CtrGate(7),
131 NI_LogicLow,
132 0, /* Termination */
133 }
134 },
135 {
136 .dest = NI_PFI(11),
137 .src = (int[]){
138 NI_CtrSource(7),
139 NI_LogicLow,
140 0, /* Termination */
141 }
142 },
143 {
144 .dest = NI_PFI(12),
145 .src = (int[]){
146 NI_PFI(6),
147 NI_PFI(14),
148 NI_PFI(22),
149 NI_PFI(30),
150 NI_PFI(38),
151 TRIGGER_LINE(0),
152 TRIGGER_LINE(1),
153 TRIGGER_LINE(2),
154 TRIGGER_LINE(3),
155 TRIGGER_LINE(4),
156 TRIGGER_LINE(5),
157 TRIGGER_LINE(6),
158 TRIGGER_LINE(7),
159 NI_CtrInternalOutput(0),
160 NI_CtrInternalOutput(1),
161 NI_CtrInternalOutput(2),
162 NI_CtrInternalOutput(3),
163 NI_CtrInternalOutput(4),
164 NI_CtrInternalOutput(5),
165 NI_CtrInternalOutput(6),
166 NI_CtrInternalOutput(7),
167 NI_LogicLow,
168 NI_LogicHigh,
169 0, /* Termination */
170 }
171 },
172 {
173 .dest = NI_PFI(13),
174 .src = (int[]){
175 NI_PFI(6),
176 NI_PFI(14),
177 NI_PFI(22),
178 NI_PFI(30),
179 NI_PFI(38),
180 TRIGGER_LINE(0),
181 TRIGGER_LINE(1),
182 TRIGGER_LINE(2),
183 TRIGGER_LINE(3),
184 TRIGGER_LINE(4),
185 TRIGGER_LINE(5),
186 TRIGGER_LINE(6),
187 TRIGGER_LINE(7),
188 NI_CtrInternalOutput(0),
189 NI_CtrInternalOutput(1),
190 NI_CtrInternalOutput(2),
191 NI_CtrInternalOutput(3),
192 NI_CtrInternalOutput(4),
193 NI_CtrInternalOutput(5),
194 NI_CtrInternalOutput(6),
195 NI_CtrInternalOutput(7),
196 NI_LogicLow,
197 NI_LogicHigh,
198 0, /* Termination */
199 }
200 },
201 {
202 .dest = NI_PFI(14),
203 .src = (int[]){
204 NI_CtrGate(6),
205 NI_LogicLow,
206 0, /* Termination */
207 }
208 },
209 {
210 .dest = NI_PFI(15),
211 .src = (int[]){
212 NI_CtrSource(6),
213 NI_LogicLow,
214 0, /* Termination */
215 }
216 },
217 {
218 .dest = NI_PFI(16),
219 .src = (int[]){
220 NI_PFI(5),
221 NI_PFI(13),
222 NI_PFI(21),
223 NI_PFI(29),
224 NI_PFI(37),
225 TRIGGER_LINE(0),
226 TRIGGER_LINE(1),
227 TRIGGER_LINE(2),
228 TRIGGER_LINE(3),
229 TRIGGER_LINE(4),
230 TRIGGER_LINE(5),
231 TRIGGER_LINE(6),
232 TRIGGER_LINE(7),
233 NI_CtrInternalOutput(0),
234 NI_CtrInternalOutput(1),
235 NI_CtrInternalOutput(2),
236 NI_CtrInternalOutput(3),
237 NI_CtrInternalOutput(4),
238 NI_CtrInternalOutput(5),
239 NI_CtrInternalOutput(6),
240 NI_CtrInternalOutput(7),
241 NI_LogicLow,
242 NI_LogicHigh,
243 0, /* Termination */
244 }
245 },
246 {
247 .dest = NI_PFI(17),
248 .src = (int[]){
249 NI_PFI(5),
250 NI_PFI(13),
251 NI_PFI(21),
252 NI_PFI(29),
253 NI_PFI(37),
254 TRIGGER_LINE(0),
255 TRIGGER_LINE(1),
256 TRIGGER_LINE(2),
257 TRIGGER_LINE(3),
258 TRIGGER_LINE(4),
259 TRIGGER_LINE(5),
260 TRIGGER_LINE(6),
261 TRIGGER_LINE(7),
262 NI_CtrInternalOutput(0),
263 NI_CtrInternalOutput(1),
264 NI_CtrInternalOutput(2),
265 NI_CtrInternalOutput(3),
266 NI_CtrInternalOutput(4),
267 NI_CtrInternalOutput(5),
268 NI_CtrInternalOutput(6),
269 NI_CtrInternalOutput(7),
270 NI_LogicLow,
271 NI_LogicHigh,
272 0, /* Termination */
273 }
274 },
275 {
276 .dest = NI_PFI(18),
277 .src = (int[]){
278 NI_CtrGate(5),
279 NI_LogicLow,
280 0, /* Termination */
281 }
282 },
283 {
284 .dest = NI_PFI(19),
285 .src = (int[]){
286 NI_CtrSource(5),
287 0, /* Termination */
288 }
289 },
290 {
291 .dest = NI_PFI(20),
292 .src = (int[]){
293 NI_PFI(4),
294 NI_PFI(12),
295 NI_PFI(28),
296 NI_PFI(36),
297 TRIGGER_LINE(0),
298 TRIGGER_LINE(1),
299 TRIGGER_LINE(2),
300 TRIGGER_LINE(3),
301 TRIGGER_LINE(4),
302 TRIGGER_LINE(5),
303 TRIGGER_LINE(6),
304 TRIGGER_LINE(7),
305 NI_CtrInternalOutput(0),
306 NI_CtrInternalOutput(1),
307 NI_CtrInternalOutput(2),
308 NI_CtrInternalOutput(3),
309 NI_CtrInternalOutput(4),
310 NI_CtrInternalOutput(5),
311 NI_CtrInternalOutput(6),
312 NI_CtrInternalOutput(7),
313 NI_LogicLow,
314 NI_LogicHigh,
315 0, /* Termination */
316 }
317 },
318 {
319 .dest = NI_PFI(21),
320 .src = (int[]){
321 NI_PFI(4),
322 NI_PFI(12),
323 NI_PFI(20),
324 NI_PFI(28),
325 NI_PFI(36),
326 TRIGGER_LINE(0),
327 TRIGGER_LINE(1),
328 TRIGGER_LINE(2),
329 TRIGGER_LINE(3),
330 TRIGGER_LINE(4),
331 TRIGGER_LINE(5),
332 TRIGGER_LINE(6),
333 TRIGGER_LINE(7),
334 NI_CtrInternalOutput(0),
335 NI_CtrInternalOutput(1),
336 NI_CtrInternalOutput(2),
337 NI_CtrInternalOutput(3),
338 NI_CtrInternalOutput(4),
339 NI_CtrInternalOutput(5),
340 NI_CtrInternalOutput(6),
341 NI_CtrInternalOutput(7),
342 NI_LogicLow,
343 NI_LogicHigh,
344 0, /* Termination */
345 }
346 },
347 {
348 .dest = NI_PFI(22),
349 .src = (int[]){
350 NI_CtrGate(4),
351 0, /* Termination */
352 }
353 },
354 {
355 .dest = NI_PFI(23),
356 .src = (int[]){
357 NI_CtrSource(4),
358 NI_LogicLow,
359 0, /* Termination */
360 }
361 },
362 {
363 .dest = NI_PFI(24),
364 .src = (int[]){
365 NI_PFI(3),
366 NI_PFI(11),
367 NI_PFI(19),
368 NI_PFI(27),
369 NI_PFI(35),
370 TRIGGER_LINE(0),
371 TRIGGER_LINE(1),
372 TRIGGER_LINE(2),
373 TRIGGER_LINE(3),
374 TRIGGER_LINE(4),
375 TRIGGER_LINE(5),
376 TRIGGER_LINE(6),
377 TRIGGER_LINE(7),
378 NI_CtrSource(3),
379 NI_CtrSource(7),
380 NI_CtrGate(3),
381 NI_CtrGate(7),
382 NI_CtrInternalOutput(0),
383 NI_CtrInternalOutput(1),
384 NI_CtrInternalOutput(2),
385 NI_CtrInternalOutput(3),
386 NI_CtrInternalOutput(4),
387 NI_CtrInternalOutput(5),
388 NI_CtrInternalOutput(6),
389 NI_CtrInternalOutput(7),
390 NI_LogicLow,
391 NI_LogicHigh,
392 0, /* Termination */
393 }
394 },
395 {
396 .dest = NI_PFI(25),
397 .src = (int[]){
398 NI_PFI(3),
399 NI_PFI(11),
400 NI_PFI(19),
401 NI_PFI(27),
402 NI_PFI(35),
403 TRIGGER_LINE(0),
404 TRIGGER_LINE(1),
405 TRIGGER_LINE(2),
406 TRIGGER_LINE(3),
407 TRIGGER_LINE(4),
408 TRIGGER_LINE(5),
409 TRIGGER_LINE(6),
410 TRIGGER_LINE(7),
411 NI_CtrSource(3),
412 NI_CtrSource(7),
413 NI_CtrGate(3),
414 NI_CtrGate(7),
415 NI_CtrInternalOutput(0),
416 NI_CtrInternalOutput(1),
417 NI_CtrInternalOutput(2),
418 NI_CtrInternalOutput(3),
419 NI_CtrInternalOutput(4),
420 NI_CtrInternalOutput(5),
421 NI_CtrInternalOutput(6),
422 NI_CtrInternalOutput(7),
423 NI_LogicLow,
424 NI_LogicHigh,
425 0, /* Termination */
426 }
427 },
428 {
429 .dest = NI_PFI(26),
430 .src = (int[]){
431 NI_CtrGate(3),
432 0, /* Termination */
433 }
434 },
435 {
436 .dest = NI_PFI(27),
437 .src = (int[]){
438 NI_CtrSource(3),
439 0, /* Termination */
440 }
441 },
442 {
443 .dest = NI_PFI(28),
444 .src = (int[]){
445 NI_PFI(2),
446 NI_PFI(10),
447 NI_PFI(18),
448 NI_PFI(26),
449 NI_PFI(34),
450 TRIGGER_LINE(0),
451 TRIGGER_LINE(1),
452 TRIGGER_LINE(2),
453 TRIGGER_LINE(3),
454 TRIGGER_LINE(4),
455 TRIGGER_LINE(5),
456 TRIGGER_LINE(6),
457 TRIGGER_LINE(7),
458 NI_CtrSource(2),
459 NI_CtrSource(6),
460 NI_CtrGate(2),
461 NI_CtrInternalOutput(0),
462 NI_CtrInternalOutput(1),
463 NI_CtrInternalOutput(2),
464 NI_CtrInternalOutput(3),
465 NI_CtrInternalOutput(4),
466 NI_CtrInternalOutput(5),
467 NI_CtrInternalOutput(6),
468 NI_CtrInternalOutput(7),
469 NI_LogicLow,
470 NI_LogicHigh,
471 0, /* Termination */
472 }
473 },
474 {
475 .dest = NI_PFI(29),
476 .src = (int[]){
477 NI_PFI(2),
478 NI_PFI(10),
479 NI_PFI(18),
480 NI_PFI(26),
481 NI_PFI(34),
482 TRIGGER_LINE(0),
483 TRIGGER_LINE(1),
484 TRIGGER_LINE(2),
485 TRIGGER_LINE(3),
486 TRIGGER_LINE(4),
487 TRIGGER_LINE(5),
488 TRIGGER_LINE(6),
489 TRIGGER_LINE(7),
490 NI_CtrSource(2),
491 NI_CtrSource(6),
492 NI_CtrGate(2),
493 NI_CtrInternalOutput(0),
494 NI_CtrInternalOutput(1),
495 NI_CtrInternalOutput(2),
496 NI_CtrInternalOutput(3),
497 NI_CtrInternalOutput(4),
498 NI_CtrInternalOutput(5),
499 NI_CtrInternalOutput(6),
500 NI_CtrInternalOutput(7),
501 NI_LogicLow,
502 NI_LogicHigh,
503 0, /* Termination */
504 }
505 },
506 {
507 .dest = NI_PFI(30),
508 .src = (int[]){
509 NI_CtrGate(2),
510 0, /* Termination */
511 }
512 },
513 {
514 .dest = NI_PFI(31),
515 .src = (int[]){
516 NI_CtrSource(2),
517 0, /* Termination */
518 }
519 },
520 {
521 .dest = NI_PFI(32),
522 .src = (int[]){
523 NI_PFI(1),
524 NI_PFI(9),
525 NI_PFI(17),
526 NI_PFI(25),
527 NI_PFI(33),
528 TRIGGER_LINE(0),
529 TRIGGER_LINE(1),
530 TRIGGER_LINE(2),
531 TRIGGER_LINE(3),
532 TRIGGER_LINE(4),
533 TRIGGER_LINE(5),
534 TRIGGER_LINE(6),
535 TRIGGER_LINE(7),
536 NI_CtrSource(1),
537 NI_CtrSource(5),
538 NI_CtrGate(1),
539 NI_CtrInternalOutput(0),
540 NI_CtrInternalOutput(1),
541 NI_CtrInternalOutput(2),
542 NI_CtrInternalOutput(3),
543 NI_CtrInternalOutput(4),
544 NI_CtrInternalOutput(5),
545 NI_CtrInternalOutput(6),
546 NI_CtrInternalOutput(7),
547 NI_LogicLow,
548 NI_LogicHigh,
549 0, /* Termination */
550 }
551 },
552 {
553 .dest = NI_PFI(33),
554 .src = (int[]){
555 NI_PFI(1),
556 NI_PFI(9),
557 NI_PFI(17),
558 NI_PFI(25),
559 TRIGGER_LINE(0),
560 TRIGGER_LINE(1),
561 TRIGGER_LINE(2),
562 TRIGGER_LINE(3),
563 TRIGGER_LINE(4),
564 TRIGGER_LINE(5),
565 TRIGGER_LINE(6),
566 TRIGGER_LINE(7),
567 NI_CtrSource(1),
568 NI_CtrSource(5),
569 NI_CtrGate(1),
570 NI_CtrInternalOutput(0),
571 NI_CtrInternalOutput(1),
572 NI_CtrInternalOutput(2),
573 NI_CtrInternalOutput(3),
574 NI_CtrInternalOutput(4),
575 NI_CtrInternalOutput(5),
576 NI_CtrInternalOutput(6),
577 NI_CtrInternalOutput(7),
578 NI_LogicLow,
579 NI_LogicHigh,
580 0, /* Termination */
581 }
582 },
583 {
584 .dest = NI_PFI(34),
585 .src = (int[]){
586 NI_CtrGate(1),
587 0, /* Termination */
588 }
589 },
590 {
591 .dest = NI_PFI(35),
592 .src = (int[]){
593 NI_CtrSource(1),
594 0, /* Termination */
595 }
596 },
597 {
598 .dest = NI_PFI(36),
599 .src = (int[]){
600 NI_PFI(0),
601 NI_PFI(1),
602 NI_PFI(2),
603 NI_PFI(3),
604 NI_PFI(4),
605 NI_PFI(5),
606 NI_PFI(6),
607 NI_PFI(7),
608 NI_PFI(8),
609 NI_PFI(9),
610 NI_PFI(10),
611 NI_PFI(11),
612 NI_PFI(12),
613 NI_PFI(13),
614 NI_PFI(14),
615 NI_PFI(15),
616 NI_PFI(16),
617 NI_PFI(17),
618 NI_PFI(18),
619 NI_PFI(19),
620 NI_PFI(20),
621 NI_PFI(21),
622 NI_PFI(22),
623 NI_PFI(23),
624 NI_PFI(24),
625 NI_PFI(25),
626 NI_PFI(26),
627 NI_PFI(27),
628 NI_PFI(28),
629 NI_PFI(29),
630 NI_PFI(30),
631 NI_PFI(31),
632 NI_PFI(32),
633 NI_PFI(33),
634 NI_PFI(34),
635 NI_PFI(35),
636 NI_PFI(37),
637 NI_PFI(38),
638 NI_PFI(39),
639 TRIGGER_LINE(0),
640 TRIGGER_LINE(1),
641 TRIGGER_LINE(2),
642 TRIGGER_LINE(3),
643 TRIGGER_LINE(4),
644 TRIGGER_LINE(5),
645 TRIGGER_LINE(6),
646 TRIGGER_LINE(7),
647 NI_CtrSource(0),
648 NI_CtrSource(5),
649 NI_CtrGate(0),
650 NI_CtrInternalOutput(0),
651 NI_CtrInternalOutput(1),
652 NI_CtrInternalOutput(2),
653 NI_CtrInternalOutput(3),
654 NI_CtrInternalOutput(4),
655 NI_CtrInternalOutput(5),
656 NI_CtrInternalOutput(6),
657 NI_CtrInternalOutput(7),
658 NI_LogicLow,
659 NI_LogicHigh,
660 0, /* Termination */
661 }
662 },
663 {
664 .dest = NI_PFI(37),
665 .src = (int[]){
666 NI_PFI(0),
667 NI_PFI(1),
668 NI_PFI(2),
669 NI_PFI(3),
670 NI_PFI(4),
671 NI_PFI(5),
672 NI_PFI(6),
673 NI_PFI(7),
674 NI_PFI(8),
675 NI_PFI(9),
676 NI_PFI(10),
677 NI_PFI(11),
678 NI_PFI(12),
679 NI_PFI(13),
680 NI_PFI(14),
681 NI_PFI(15),
682 NI_PFI(16),
683 NI_PFI(17),
684 NI_PFI(18),
685 NI_PFI(19),
686 NI_PFI(20),
687 NI_PFI(21),
688 NI_PFI(22),
689 NI_PFI(23),
690 NI_PFI(24),
691 NI_PFI(25),
692 NI_PFI(26),
693 NI_PFI(27),
694 NI_PFI(28),
695 NI_PFI(29),
696 NI_PFI(30),
697 NI_PFI(31),
698 NI_PFI(32),
699 NI_PFI(33),
700 NI_PFI(34),
701 NI_PFI(35),
702 NI_PFI(36),
703 NI_PFI(38),
704 NI_PFI(39),
705 TRIGGER_LINE(0),
706 TRIGGER_LINE(1),
707 TRIGGER_LINE(2),
708 TRIGGER_LINE(3),
709 TRIGGER_LINE(4),
710 TRIGGER_LINE(5),
711 TRIGGER_LINE(6),
712 TRIGGER_LINE(7),
713 NI_CtrSource(0),
714 NI_CtrSource(5),
715 NI_CtrGate(0),
716 NI_CtrInternalOutput(0),
717 NI_CtrInternalOutput(1),
718 NI_CtrInternalOutput(2),
719 NI_CtrInternalOutput(3),
720 NI_CtrInternalOutput(4),
721 NI_CtrInternalOutput(5),
722 NI_CtrInternalOutput(6),
723 NI_CtrInternalOutput(7),
724 NI_LogicLow,
725 NI_LogicHigh,
726 0, /* Termination */
727 }
728 },
729 {
730 .dest = NI_PFI(38),
731 .src = (int[]){
732 NI_CtrGate(0),
733 0, /* Termination */
734 }
735 },
736 {
737 .dest = NI_PFI(39),
738 .src = (int[]){
739 NI_CtrSource(0),
740 0, /* Termination */
741 }
742 },
743 {
744 .dest = TRIGGER_LINE(0),
745 .src = (int[]){
746 NI_PFI(0),
747 NI_PFI(1),
748 NI_PFI(2),
749 NI_PFI(3),
750 NI_PFI(4),
751 NI_PFI(5),
752 NI_PFI(6),
753 NI_PFI(7),
754 NI_PFI(8),
755 NI_PFI(9),
756 NI_PFI(10),
757 NI_PFI(11),
758 NI_PFI(12),
759 NI_PFI(13),
760 NI_PFI(14),
761 NI_PFI(15),
762 NI_PFI(16),
763 NI_PFI(17),
764 NI_PFI(18),
765 NI_PFI(19),
766 NI_PFI(20),
767 NI_PFI(21),
768 NI_PFI(22),
769 NI_PFI(23),
770 NI_PFI(24),
771 NI_PFI(25),
772 NI_PFI(26),
773 NI_PFI(27),
774 NI_PFI(28),
775 NI_PFI(29),
776 NI_PFI(30),
777 NI_PFI(31),
778 NI_PFI(32),
779 NI_PFI(33),
780 NI_PFI(34),
781 NI_PFI(35),
782 NI_PFI(36),
783 NI_PFI(37),
784 NI_PFI(38),
785 NI_PFI(39),
786 NI_CtrSource(0),
787 NI_CtrSource(1),
788 NI_CtrSource(2),
789 NI_CtrSource(3),
790 NI_CtrSource(4),
791 NI_CtrSource(5),
792 NI_CtrSource(6),
793 NI_CtrSource(7),
794 NI_CtrGate(0),
795 NI_CtrGate(1),
796 NI_CtrGate(2),
797 NI_CtrGate(3),
798 NI_CtrGate(4),
799 NI_CtrGate(5),
800 NI_CtrGate(6),
801 NI_CtrGate(7),
802 NI_CtrInternalOutput(0),
803 NI_CtrInternalOutput(1),
804 NI_CtrInternalOutput(2),
805 NI_CtrInternalOutput(3),
806 NI_CtrInternalOutput(4),
807 NI_CtrInternalOutput(5),
808 NI_CtrInternalOutput(6),
809 NI_CtrInternalOutput(7),
810 NI_LogicLow,
811 NI_LogicHigh,
812 0, /* Termination */
813 }
814 },
815 {
816 .dest = TRIGGER_LINE(1),
817 .src = (int[]){
818 NI_PFI(0),
819 NI_PFI(1),
820 NI_PFI(2),
821 NI_PFI(3),
822 NI_PFI(4),
823 NI_PFI(5),
824 NI_PFI(6),
825 NI_PFI(7),
826 NI_PFI(8),
827 NI_PFI(9),
828 NI_PFI(10),
829 NI_PFI(11),
830 NI_PFI(12),
831 NI_PFI(13),
832 NI_PFI(14),
833 NI_PFI(15),
834 NI_PFI(16),
835 NI_PFI(17),
836 NI_PFI(18),
837 NI_PFI(19),
838 NI_PFI(20),
839 NI_PFI(21),
840 NI_PFI(22),
841 NI_PFI(23),
842 NI_PFI(24),
843 NI_PFI(25),
844 NI_PFI(26),
845 NI_PFI(27),
846 NI_PFI(28),
847 NI_PFI(29),
848 NI_PFI(30),
849 NI_PFI(31),
850 NI_PFI(32),
851 NI_PFI(33),
852 NI_PFI(34),
853 NI_PFI(35),
854 NI_PFI(36),
855 NI_PFI(37),
856 NI_PFI(38),
857 NI_PFI(39),
858 NI_CtrSource(0),
859 NI_CtrSource(1),
860 NI_CtrSource(2),
861 NI_CtrSource(3),
862 NI_CtrSource(4),
863 NI_CtrSource(5),
864 NI_CtrSource(6),
865 NI_CtrSource(7),
866 NI_CtrGate(0),
867 NI_CtrGate(1),
868 NI_CtrGate(2),
869 NI_CtrGate(3),
870 NI_CtrGate(4),
871 NI_CtrGate(5),
872 NI_CtrGate(6),
873 NI_CtrGate(7),
874 NI_CtrInternalOutput(0),
875 NI_CtrInternalOutput(1),
876 NI_CtrInternalOutput(2),
877 NI_CtrInternalOutput(3),
878 NI_CtrInternalOutput(4),
879 NI_CtrInternalOutput(5),
880 NI_CtrInternalOutput(6),
881 NI_CtrInternalOutput(7),
882 NI_LogicLow,
883 NI_LogicHigh,
884 0, /* Termination */
885 }
886 },
887 {
888 .dest = TRIGGER_LINE(2),
889 .src = (int[]){
890 NI_PFI(0),
891 NI_PFI(1),
892 NI_PFI(2),
893 NI_PFI(3),
894 NI_PFI(4),
895 NI_PFI(5),
896 NI_PFI(6),
897 NI_PFI(7),
898 NI_PFI(8),
899 NI_PFI(9),
900 NI_PFI(10),
901 NI_PFI(11),
902 NI_PFI(12),
903 NI_PFI(13),
904 NI_PFI(14),
905 NI_PFI(15),
906 NI_PFI(16),
907 NI_PFI(17),
908 NI_PFI(18),
909 NI_PFI(19),
910 NI_PFI(20),
911 NI_PFI(21),
912 NI_PFI(22),
913 NI_PFI(23),
914 NI_PFI(24),
915 NI_PFI(25),
916 NI_PFI(26),
917 NI_PFI(27),
918 NI_PFI(28),
919 NI_PFI(29),
920 NI_PFI(30),
921 NI_PFI(31),
922 NI_PFI(32),
923 NI_PFI(33),
924 NI_PFI(34),
925 NI_PFI(35),
926 NI_PFI(36),
927 NI_PFI(37),
928 NI_PFI(38),
929 NI_PFI(39),
930 NI_CtrSource(0),
931 NI_CtrSource(1),
932 NI_CtrSource(2),
933 NI_CtrSource(3),
934 NI_CtrSource(4),
935 NI_CtrSource(5),
936 NI_CtrSource(6),
937 NI_CtrSource(7),
938 NI_CtrGate(0),
939 NI_CtrGate(1),
940 NI_CtrGate(2),
941 NI_CtrGate(3),
942 NI_CtrGate(4),
943 NI_CtrGate(5),
944 NI_CtrGate(6),
945 NI_CtrGate(7),
946 NI_CtrInternalOutput(0),
947 NI_CtrInternalOutput(1),
948 NI_CtrInternalOutput(2),
949 NI_CtrInternalOutput(3),
950 NI_CtrInternalOutput(4),
951 NI_CtrInternalOutput(5),
952 NI_CtrInternalOutput(6),
953 NI_CtrInternalOutput(7),
954 NI_LogicLow,
955 NI_LogicHigh,
956 0, /* Termination */
957 }
958 },
959 {
960 .dest = TRIGGER_LINE(3),
961 .src = (int[]){
962 NI_PFI(0),
963 NI_PFI(1),
964 NI_PFI(2),
965 NI_PFI(3),
966 NI_PFI(4),
967 NI_PFI(5),
968 NI_PFI(6),
969 NI_PFI(7),
970 NI_PFI(8),
971 NI_PFI(9),
972 NI_PFI(10),
973 NI_PFI(11),
974 NI_PFI(12),
975 NI_PFI(13),
976 NI_PFI(14),
977 NI_PFI(15),
978 NI_PFI(16),
979 NI_PFI(17),
980 NI_PFI(18),
981 NI_PFI(19),
982 NI_PFI(20),
983 NI_PFI(21),
984 NI_PFI(22),
985 NI_PFI(23),
986 NI_PFI(24),
987 NI_PFI(25),
988 NI_PFI(26),
989 NI_PFI(27),
990 NI_PFI(28),
991 NI_PFI(29),
992 NI_PFI(30),
993 NI_PFI(31),
994 NI_PFI(32),
995 NI_PFI(33),
996 NI_PFI(34),
997 NI_PFI(35),
998 NI_PFI(36),
999 NI_PFI(37),
1000 NI_PFI(38),
1001 NI_PFI(39),
1002 NI_CtrSource(0),
1003 NI_CtrSource(1),
1004 NI_CtrSource(2),
1005 NI_CtrSource(3),
1006 NI_CtrSource(4),
1007 NI_CtrSource(5),
1008 NI_CtrSource(6),
1009 NI_CtrSource(7),
1010 NI_CtrGate(0),
1011 NI_CtrGate(1),
1012 NI_CtrGate(2),
1013 NI_CtrGate(3),
1014 NI_CtrGate(4),
1015 NI_CtrGate(5),
1016 NI_CtrGate(6),
1017 NI_CtrGate(7),
1018 NI_CtrInternalOutput(0),
1019 NI_CtrInternalOutput(1),
1020 NI_CtrInternalOutput(2),
1021 NI_CtrInternalOutput(3),
1022 NI_CtrInternalOutput(4),
1023 NI_CtrInternalOutput(5),
1024 NI_CtrInternalOutput(6),
1025 NI_CtrInternalOutput(7),
1026 NI_LogicLow,
1027 NI_LogicHigh,
1028 0, /* Termination */
1029 }
1030 },
1031 {
1032 .dest = TRIGGER_LINE(4),
1033 .src = (int[]){
1034 NI_PFI(0),
1035 NI_PFI(1),
1036 NI_PFI(2),
1037 NI_PFI(3),
1038 NI_PFI(4),
1039 NI_PFI(5),
1040 NI_PFI(6),
1041 NI_PFI(7),
1042 NI_PFI(8),
1043 NI_PFI(9),
1044 NI_PFI(10),
1045 NI_PFI(11),
1046 NI_PFI(12),
1047 NI_PFI(13),
1048 NI_PFI(14),
1049 NI_PFI(15),
1050 NI_PFI(16),
1051 NI_PFI(17),
1052 NI_PFI(18),
1053 NI_PFI(19),
1054 NI_PFI(20),
1055 NI_PFI(21),
1056 NI_PFI(22),
1057 NI_PFI(23),
1058 NI_PFI(24),
1059 NI_PFI(25),
1060 NI_PFI(26),
1061 NI_PFI(27),
1062 NI_PFI(28),
1063 NI_PFI(29),
1064 NI_PFI(30),
1065 NI_PFI(31),
1066 NI_PFI(32),
1067 NI_PFI(33),
1068 NI_PFI(34),
1069 NI_PFI(35),
1070 NI_PFI(36),
1071 NI_PFI(37),
1072 NI_PFI(38),
1073 NI_PFI(39),
1074 NI_CtrSource(0),
1075 NI_CtrSource(1),
1076 NI_CtrSource(2),
1077 NI_CtrSource(3),
1078 NI_CtrSource(4),
1079 NI_CtrSource(5),
1080 NI_CtrSource(6),
1081 NI_CtrSource(7),
1082 NI_CtrGate(0),
1083 NI_CtrGate(1),
1084 NI_CtrGate(2),
1085 NI_CtrGate(3),
1086 NI_CtrGate(4),
1087 NI_CtrGate(5),
1088 NI_CtrGate(6),
1089 NI_CtrGate(7),
1090 NI_CtrInternalOutput(0),
1091 NI_CtrInternalOutput(1),
1092 NI_CtrInternalOutput(2),
1093 NI_CtrInternalOutput(3),
1094 NI_CtrInternalOutput(4),
1095 NI_CtrInternalOutput(5),
1096 NI_CtrInternalOutput(6),
1097 NI_CtrInternalOutput(7),
1098 NI_LogicLow,
1099 NI_LogicHigh,
1100 0, /* Termination */
1101 }
1102 },
1103 {
1104 .dest = TRIGGER_LINE(5),
1105 .src = (int[]){
1106 NI_PFI(0),
1107 NI_PFI(1),
1108 NI_PFI(2),
1109 NI_PFI(3),
1110 NI_PFI(4),
1111 NI_PFI(5),
1112 NI_PFI(6),
1113 NI_PFI(7),
1114 NI_PFI(8),
1115 NI_PFI(9),
1116 NI_PFI(10),
1117 NI_PFI(11),
1118 NI_PFI(12),
1119 NI_PFI(13),
1120 NI_PFI(14),
1121 NI_PFI(15),
1122 NI_PFI(16),
1123 NI_PFI(17),
1124 NI_PFI(18),
1125 NI_PFI(19),
1126 NI_PFI(20),
1127 NI_PFI(21),
1128 NI_PFI(22),
1129 NI_PFI(23),
1130 NI_PFI(24),
1131 NI_PFI(25),
1132 NI_PFI(26),
1133 NI_PFI(27),
1134 NI_PFI(28),
1135 NI_PFI(29),
1136 NI_PFI(30),
1137 NI_PFI(31),
1138 NI_PFI(32),
1139 NI_PFI(33),
1140 NI_PFI(34),
1141 NI_PFI(35),
1142 NI_PFI(36),
1143 NI_PFI(37),
1144 NI_PFI(38),
1145 NI_PFI(39),
1146 NI_CtrSource(0),
1147 NI_CtrSource(1),
1148 NI_CtrSource(2),
1149 NI_CtrSource(3),
1150 NI_CtrSource(4),
1151 NI_CtrSource(5),
1152 NI_CtrSource(6),
1153 NI_CtrSource(7),
1154 NI_CtrGate(0),
1155 NI_CtrGate(1),
1156 NI_CtrGate(2),
1157 NI_CtrGate(3),
1158 NI_CtrGate(4),
1159 NI_CtrGate(5),
1160 NI_CtrGate(6),
1161 NI_CtrGate(7),
1162 NI_CtrInternalOutput(0),
1163 NI_CtrInternalOutput(1),
1164 NI_CtrInternalOutput(2),
1165 NI_CtrInternalOutput(3),
1166 NI_CtrInternalOutput(4),
1167 NI_CtrInternalOutput(5),
1168 NI_CtrInternalOutput(6),
1169 NI_CtrInternalOutput(7),
1170 NI_LogicLow,
1171 NI_LogicHigh,
1172 0, /* Termination */
1173 }
1174 },
1175 {
1176 .dest = TRIGGER_LINE(6),
1177 .src = (int[]){
1178 NI_PFI(0),
1179 NI_PFI(1),
1180 NI_PFI(2),
1181 NI_PFI(3),
1182 NI_PFI(4),
1183 NI_PFI(5),
1184 NI_PFI(6),
1185 NI_PFI(7),
1186 NI_PFI(8),
1187 NI_PFI(9),
1188 NI_PFI(10),
1189 NI_PFI(11),
1190 NI_PFI(12),
1191 NI_PFI(13),
1192 NI_PFI(14),
1193 NI_PFI(15),
1194 NI_PFI(16),
1195 NI_PFI(17),
1196 NI_PFI(18),
1197 NI_PFI(19),
1198 NI_PFI(20),
1199 NI_PFI(21),
1200 NI_PFI(22),
1201 NI_PFI(23),
1202 NI_PFI(24),
1203 NI_PFI(25),
1204 NI_PFI(26),
1205 NI_PFI(27),
1206 NI_PFI(28),
1207 NI_PFI(29),
1208 NI_PFI(30),
1209 NI_PFI(31),
1210 NI_PFI(32),
1211 NI_PFI(33),
1212 NI_PFI(34),
1213 NI_PFI(35),
1214 NI_PFI(36),
1215 NI_PFI(37),
1216 NI_PFI(38),
1217 NI_PFI(39),
1218 NI_CtrSource(0),
1219 NI_CtrSource(1),
1220 NI_CtrSource(2),
1221 NI_CtrSource(3),
1222 NI_CtrSource(4),
1223 NI_CtrSource(5),
1224 NI_CtrSource(6),
1225 NI_CtrSource(7),
1226 NI_CtrGate(0),
1227 NI_CtrGate(1),
1228 NI_CtrGate(2),
1229 NI_CtrGate(3),
1230 NI_CtrGate(4),
1231 NI_CtrGate(5),
1232 NI_CtrGate(6),
1233 NI_CtrGate(7),
1234 NI_CtrInternalOutput(0),
1235 NI_CtrInternalOutput(1),
1236 NI_CtrInternalOutput(2),
1237 NI_CtrInternalOutput(3),
1238 NI_CtrInternalOutput(4),
1239 NI_CtrInternalOutput(5),
1240 NI_CtrInternalOutput(6),
1241 NI_CtrInternalOutput(7),
1242 NI_LogicLow,
1243 NI_LogicHigh,
1244 0, /* Termination */
1245 }
1246 },
1247 {
1248 .dest = TRIGGER_LINE(7),
1249 .src = (int[]){
1250 NI_20MHzTimebase,
1251 0, /* Termination */
1252 }
1253 },
1254 {
1255 .dest = NI_CtrSource(0),
1256 .src = (int[]){
1257 NI_PFI(0),
1258 NI_PFI(1),
1259 NI_PFI(2),
1260 NI_PFI(3),
1261 NI_PFI(4),
1262 NI_PFI(5),
1263 NI_PFI(6),
1264 NI_PFI(7),
1265 NI_PFI(8),
1266 NI_PFI(9),
1267 NI_PFI(10),
1268 NI_PFI(11),
1269 NI_PFI(12),
1270 NI_PFI(13),
1271 NI_PFI(14),
1272 NI_PFI(15),
1273 NI_PFI(16),
1274 NI_PFI(17),
1275 NI_PFI(18),
1276 NI_PFI(19),
1277 NI_PFI(20),
1278 NI_PFI(21),
1279 NI_PFI(22),
1280 NI_PFI(23),
1281 NI_PFI(24),
1282 NI_PFI(25),
1283 NI_PFI(26),
1284 NI_PFI(27),
1285 NI_PFI(28),
1286 NI_PFI(29),
1287 NI_PFI(30),
1288 NI_PFI(31),
1289 NI_PFI(32),
1290 NI_PFI(33),
1291 NI_PFI(34),
1292 NI_PFI(35),
1293 NI_PFI(36),
1294 NI_PFI(37),
1295 NI_PFI(38),
1296 NI_PFI(39),
1297 TRIGGER_LINE(0),
1298 TRIGGER_LINE(1),
1299 TRIGGER_LINE(2),
1300 TRIGGER_LINE(3),
1301 TRIGGER_LINE(4),
1302 TRIGGER_LINE(5),
1303 TRIGGER_LINE(6),
1304 TRIGGER_LINE(7),
1305 NI_CtrSource(1),
1306 NI_CtrSource(2),
1307 NI_CtrSource(3),
1308 NI_CtrGate(1),
1309 NI_CtrGate(2),
1310 NI_CtrGate(3),
1311 NI_CtrInternalOutput(1),
1312 NI_CtrInternalOutput(2),
1313 NI_CtrInternalOutput(3),
1314 NI_20MHzTimebase,
1315 NI_80MHzTimebase,
1316 NI_100kHzTimebase,
1317 NI_LogicLow,
1318 NI_LogicHigh,
1319 0, /* Termination */
1320 }
1321 },
1322 {
1323 .dest = NI_CtrSource(1),
1324 .src = (int[]){
1325 NI_PFI(0),
1326 NI_PFI(1),
1327 NI_PFI(2),
1328 NI_PFI(3),
1329 NI_PFI(4),
1330 NI_PFI(5),
1331 NI_PFI(6),
1332 NI_PFI(7),
1333 NI_PFI(8),
1334 NI_PFI(9),
1335 NI_PFI(10),
1336 NI_PFI(11),
1337 NI_PFI(12),
1338 NI_PFI(13),
1339 NI_PFI(14),
1340 NI_PFI(15),
1341 NI_PFI(16),
1342 NI_PFI(17),
1343 NI_PFI(18),
1344 NI_PFI(19),
1345 NI_PFI(20),
1346 NI_PFI(21),
1347 NI_PFI(22),
1348 NI_PFI(23),
1349 NI_PFI(24),
1350 NI_PFI(25),
1351 NI_PFI(26),
1352 NI_PFI(27),
1353 NI_PFI(28),
1354 NI_PFI(29),
1355 NI_PFI(30),
1356 NI_PFI(31),
1357 NI_PFI(32),
1358 NI_PFI(33),
1359 NI_PFI(34),
1360 NI_PFI(35),
1361 NI_PFI(36),
1362 NI_PFI(37),
1363 NI_PFI(38),
1364 NI_PFI(39),
1365 TRIGGER_LINE(0),
1366 TRIGGER_LINE(1),
1367 TRIGGER_LINE(2),
1368 TRIGGER_LINE(3),
1369 TRIGGER_LINE(4),
1370 TRIGGER_LINE(5),
1371 TRIGGER_LINE(6),
1372 TRIGGER_LINE(7),
1373 NI_CtrSource(0),
1374 NI_CtrSource(2),
1375 NI_CtrSource(3),
1376 NI_CtrGate(0),
1377 NI_CtrGate(2),
1378 NI_CtrGate(3),
1379 NI_CtrInternalOutput(0),
1380 NI_CtrInternalOutput(2),
1381 NI_CtrInternalOutput(3),
1382 NI_20MHzTimebase,
1383 NI_80MHzTimebase,
1384 NI_100kHzTimebase,
1385 NI_LogicLow,
1386 NI_LogicHigh,
1387 0, /* Termination */
1388 }
1389 },
1390 {
1391 .dest = NI_CtrSource(2),
1392 .src = (int[]){
1393 NI_PFI(0),
1394 NI_PFI(1),
1395 NI_PFI(2),
1396 NI_PFI(3),
1397 NI_PFI(4),
1398 NI_PFI(5),
1399 NI_PFI(6),
1400 NI_PFI(7),
1401 NI_PFI(8),
1402 NI_PFI(9),
1403 NI_PFI(10),
1404 NI_PFI(11),
1405 NI_PFI(12),
1406 NI_PFI(13),
1407 NI_PFI(14),
1408 NI_PFI(15),
1409 NI_PFI(16),
1410 NI_PFI(17),
1411 NI_PFI(18),
1412 NI_PFI(19),
1413 NI_PFI(20),
1414 NI_PFI(21),
1415 NI_PFI(22),
1416 NI_PFI(23),
1417 NI_PFI(24),
1418 NI_PFI(25),
1419 NI_PFI(26),
1420 NI_PFI(27),
1421 NI_PFI(28),
1422 NI_PFI(29),
1423 NI_PFI(30),
1424 NI_PFI(31),
1425 NI_PFI(32),
1426 NI_PFI(33),
1427 NI_PFI(34),
1428 NI_PFI(35),
1429 NI_PFI(36),
1430 NI_PFI(37),
1431 NI_PFI(38),
1432 NI_PFI(39),
1433 TRIGGER_LINE(0),
1434 TRIGGER_LINE(1),
1435 TRIGGER_LINE(2),
1436 TRIGGER_LINE(3),
1437 TRIGGER_LINE(4),
1438 TRIGGER_LINE(5),
1439 TRIGGER_LINE(6),
1440 TRIGGER_LINE(7),
1441 NI_CtrSource(0),
1442 NI_CtrSource(1),
1443 NI_CtrSource(3),
1444 NI_CtrGate(0),
1445 NI_CtrGate(1),
1446 NI_CtrGate(3),
1447 NI_CtrInternalOutput(0),
1448 NI_CtrInternalOutput(1),
1449 NI_CtrInternalOutput(3),
1450 NI_20MHzTimebase,
1451 NI_80MHzTimebase,
1452 NI_100kHzTimebase,
1453 NI_LogicLow,
1454 NI_LogicHigh,
1455 0, /* Termination */
1456 }
1457 },
1458 {
1459 .dest = NI_CtrSource(3),
1460 .src = (int[]){
1461 NI_PFI(0),
1462 NI_PFI(1),
1463 NI_PFI(2),
1464 NI_PFI(3),
1465 NI_PFI(4),
1466 NI_PFI(5),
1467 NI_PFI(6),
1468 NI_PFI(7),
1469 NI_PFI(8),
1470 NI_PFI(9),
1471 NI_PFI(10),
1472 NI_PFI(11),
1473 NI_PFI(12),
1474 NI_PFI(13),
1475 NI_PFI(14),
1476 NI_PFI(15),
1477 NI_PFI(16),
1478 NI_PFI(17),
1479 NI_PFI(18),
1480 NI_PFI(19),
1481 NI_PFI(20),
1482 NI_PFI(21),
1483 NI_PFI(22),
1484 NI_PFI(23),
1485 NI_PFI(24),
1486 NI_PFI(25),
1487 NI_PFI(26),
1488 NI_PFI(27),
1489 NI_PFI(28),
1490 NI_PFI(29),
1491 NI_PFI(30),
1492 NI_PFI(31),
1493 NI_PFI(32),
1494 NI_PFI(33),
1495 NI_PFI(34),
1496 NI_PFI(35),
1497 NI_PFI(36),
1498 NI_PFI(37),
1499 NI_PFI(38),
1500 NI_PFI(39),
1501 TRIGGER_LINE(0),
1502 TRIGGER_LINE(1),
1503 TRIGGER_LINE(2),
1504 TRIGGER_LINE(3),
1505 TRIGGER_LINE(4),
1506 TRIGGER_LINE(5),
1507 TRIGGER_LINE(6),
1508 TRIGGER_LINE(7),
1509 NI_CtrSource(0),
1510 NI_CtrSource(1),
1511 NI_CtrSource(2),
1512 NI_CtrGate(0),
1513 NI_CtrGate(1),
1514 NI_CtrGate(2),
1515 NI_CtrInternalOutput(0),
1516 NI_CtrInternalOutput(1),
1517 NI_CtrInternalOutput(2),
1518 NI_20MHzTimebase,
1519 NI_80MHzTimebase,
1520 NI_100kHzTimebase,
1521 NI_LogicLow,
1522 NI_LogicHigh,
1523 0, /* Termination */
1524 }
1525 },
1526 {
1527 .dest = NI_CtrSource(4),
1528 .src = (int[]){
1529 NI_PFI(0),
1530 NI_PFI(1),
1531 NI_PFI(2),
1532 NI_PFI(3),
1533 NI_PFI(4),
1534 NI_PFI(5),
1535 NI_PFI(6),
1536 NI_PFI(7),
1537 NI_PFI(8),
1538 NI_PFI(9),
1539 NI_PFI(10),
1540 NI_PFI(11),
1541 NI_PFI(12),
1542 NI_PFI(13),
1543 NI_PFI(14),
1544 NI_PFI(15),
1545 NI_PFI(16),
1546 NI_PFI(17),
1547 NI_PFI(18),
1548 NI_PFI(19),
1549 NI_PFI(20),
1550 NI_PFI(21),
1551 NI_PFI(22),
1552 NI_PFI(23),
1553 NI_PFI(24),
1554 NI_PFI(25),
1555 NI_PFI(26),
1556 NI_PFI(27),
1557 NI_PFI(28),
1558 NI_PFI(29),
1559 NI_PFI(30),
1560 NI_PFI(31),
1561 NI_PFI(32),
1562 NI_PFI(33),
1563 NI_PFI(34),
1564 NI_PFI(35),
1565 NI_PFI(36),
1566 NI_PFI(37),
1567 NI_PFI(38),
1568 NI_PFI(39),
1569 TRIGGER_LINE(0),
1570 TRIGGER_LINE(1),
1571 TRIGGER_LINE(2),
1572 TRIGGER_LINE(3),
1573 TRIGGER_LINE(4),
1574 TRIGGER_LINE(5),
1575 TRIGGER_LINE(6),
1576 TRIGGER_LINE(7),
1577 NI_CtrSource(5),
1578 NI_CtrSource(6),
1579 NI_CtrSource(7),
1580 NI_CtrGate(5),
1581 NI_CtrGate(6),
1582 NI_CtrGate(7),
1583 NI_CtrInternalOutput(5),
1584 NI_CtrInternalOutput(6),
1585 NI_CtrInternalOutput(7),
1586 NI_20MHzTimebase,
1587 NI_80MHzTimebase,
1588 NI_100kHzTimebase,
1589 NI_LogicLow,
1590 NI_LogicHigh,
1591 0, /* Termination */
1592 }
1593 },
1594 {
1595 .dest = NI_CtrSource(5),
1596 .src = (int[]){
1597 NI_PFI(0),
1598 NI_PFI(1),
1599 NI_PFI(2),
1600 NI_PFI(3),
1601 NI_PFI(4),
1602 NI_PFI(5),
1603 NI_PFI(6),
1604 NI_PFI(7),
1605 NI_PFI(8),
1606 NI_PFI(9),
1607 NI_PFI(10),
1608 NI_PFI(11),
1609 NI_PFI(12),
1610 NI_PFI(13),
1611 NI_PFI(14),
1612 NI_PFI(15),
1613 NI_PFI(16),
1614 NI_PFI(17),
1615 NI_PFI(18),
1616 NI_PFI(19),
1617 NI_PFI(20),
1618 NI_PFI(21),
1619 NI_PFI(22),
1620 NI_PFI(23),
1621 NI_PFI(24),
1622 NI_PFI(25),
1623 NI_PFI(26),
1624 NI_PFI(27),
1625 NI_PFI(28),
1626 NI_PFI(29),
1627 NI_PFI(30),
1628 NI_PFI(31),
1629 NI_PFI(32),
1630 NI_PFI(33),
1631 NI_PFI(34),
1632 NI_PFI(35),
1633 NI_PFI(36),
1634 NI_PFI(37),
1635 NI_PFI(38),
1636 NI_PFI(39),
1637 TRIGGER_LINE(0),
1638 TRIGGER_LINE(1),
1639 TRIGGER_LINE(2),
1640 TRIGGER_LINE(3),
1641 TRIGGER_LINE(4),
1642 TRIGGER_LINE(5),
1643 TRIGGER_LINE(6),
1644 TRIGGER_LINE(7),
1645 NI_CtrSource(4),
1646 NI_CtrSource(6),
1647 NI_CtrSource(7),
1648 NI_CtrGate(4),
1649 NI_CtrGate(6),
1650 NI_CtrGate(7),
1651 NI_CtrInternalOutput(4),
1652 NI_CtrInternalOutput(6),
1653 NI_CtrInternalOutput(7),
1654 NI_20MHzTimebase,
1655 NI_80MHzTimebase,
1656 NI_100kHzTimebase,
1657 NI_LogicLow,
1658 NI_LogicHigh,
1659 0, /* Termination */
1660 }
1661 },
1662 {
1663 .dest = NI_CtrSource(6),
1664 .src = (int[]){
1665 NI_PFI(0),
1666 NI_PFI(1),
1667 NI_PFI(2),
1668 NI_PFI(3),
1669 NI_PFI(4),
1670 NI_PFI(5),
1671 NI_PFI(6),
1672 NI_PFI(7),
1673 NI_PFI(8),
1674 NI_PFI(9),
1675 NI_PFI(10),
1676 NI_PFI(11),
1677 NI_PFI(12),
1678 NI_PFI(13),
1679 NI_PFI(14),
1680 NI_PFI(15),
1681 NI_PFI(16),
1682 NI_PFI(17),
1683 NI_PFI(18),
1684 NI_PFI(19),
1685 NI_PFI(20),
1686 NI_PFI(21),
1687 NI_PFI(22),
1688 NI_PFI(23),
1689 NI_PFI(24),
1690 NI_PFI(25),
1691 NI_PFI(26),
1692 NI_PFI(27),
1693 NI_PFI(28),
1694 NI_PFI(29),
1695 NI_PFI(30),
1696 NI_PFI(31),
1697 NI_PFI(32),
1698 NI_PFI(33),
1699 NI_PFI(34),
1700 NI_PFI(35),
1701 NI_PFI(36),
1702 NI_PFI(37),
1703 NI_PFI(38),
1704 NI_PFI(39),
1705 TRIGGER_LINE(0),
1706 TRIGGER_LINE(1),
1707 TRIGGER_LINE(2),
1708 TRIGGER_LINE(3),
1709 TRIGGER_LINE(4),
1710 TRIGGER_LINE(5),
1711 TRIGGER_LINE(6),
1712 TRIGGER_LINE(7),
1713 NI_CtrSource(4),
1714 NI_CtrSource(5),
1715 NI_CtrSource(7),
1716 NI_CtrGate(4),
1717 NI_CtrGate(5),
1718 NI_CtrGate(7),
1719 NI_CtrInternalOutput(4),
1720 NI_CtrInternalOutput(5),
1721 NI_CtrInternalOutput(7),
1722 NI_20MHzTimebase,
1723 NI_80MHzTimebase,
1724 NI_100kHzTimebase,
1725 NI_LogicLow,
1726 NI_LogicHigh,
1727 0, /* Termination */
1728 }
1729 },
1730 {
1731 .dest = NI_CtrSource(7),
1732 .src = (int[]){
1733 NI_PFI(0),
1734 NI_PFI(1),
1735 NI_PFI(2),
1736 NI_PFI(3),
1737 NI_PFI(4),
1738 NI_PFI(5),
1739 NI_PFI(6),
1740 NI_PFI(7),
1741 NI_PFI(8),
1742 NI_PFI(9),
1743 NI_PFI(10),
1744 NI_PFI(11),
1745 NI_PFI(12),
1746 NI_PFI(13),
1747 NI_PFI(14),
1748 NI_PFI(15),
1749 NI_PFI(16),
1750 NI_PFI(17),
1751 NI_PFI(18),
1752 NI_PFI(19),
1753 NI_PFI(20),
1754 NI_PFI(21),
1755 NI_PFI(22),
1756 NI_PFI(23),
1757 NI_PFI(24),
1758 NI_PFI(25),
1759 NI_PFI(26),
1760 NI_PFI(27),
1761 NI_PFI(28),
1762 NI_PFI(29),
1763 NI_PFI(30),
1764 NI_PFI(31),
1765 NI_PFI(32),
1766 NI_PFI(33),
1767 NI_PFI(34),
1768 NI_PFI(35),
1769 NI_PFI(36),
1770 NI_PFI(37),
1771 NI_PFI(38),
1772 NI_PFI(39),
1773 TRIGGER_LINE(0),
1774 TRIGGER_LINE(1),
1775 TRIGGER_LINE(2),
1776 TRIGGER_LINE(3),
1777 TRIGGER_LINE(4),
1778 TRIGGER_LINE(5),
1779 TRIGGER_LINE(6),
1780 TRIGGER_LINE(7),
1781 NI_CtrSource(4),
1782 NI_CtrSource(5),
1783 NI_CtrSource(6),
1784 NI_CtrGate(4),
1785 NI_CtrGate(5),
1786 NI_CtrGate(6),
1787 NI_CtrInternalOutput(4),
1788 NI_CtrInternalOutput(5),
1789 NI_CtrInternalOutput(6),
1790 NI_20MHzTimebase,
1791 NI_80MHzTimebase,
1792 NI_100kHzTimebase,
1793 NI_LogicLow,
1794 NI_LogicHigh,
1795 0, /* Termination */
1796 }
1797 },
1798 {
1799 .dest = NI_CtrGate(0),
1800 .src = (int[]){
1801 NI_PFI(0),
1802 NI_PFI(1),
1803 NI_PFI(2),
1804 NI_PFI(3),
1805 NI_PFI(4),
1806 NI_PFI(5),
1807 NI_PFI(6),
1808 NI_PFI(7),
1809 NI_PFI(8),
1810 NI_PFI(9),
1811 NI_PFI(10),
1812 NI_PFI(11),
1813 NI_PFI(12),
1814 NI_PFI(13),
1815 NI_PFI(14),
1816 NI_PFI(15),
1817 NI_PFI(16),
1818 NI_PFI(17),
1819 NI_PFI(18),
1820 NI_PFI(19),
1821 NI_PFI(20),
1822 NI_PFI(21),
1823 NI_PFI(22),
1824 NI_PFI(23),
1825 NI_PFI(24),
1826 NI_PFI(25),
1827 NI_PFI(26),
1828 NI_PFI(27),
1829 NI_PFI(28),
1830 NI_PFI(29),
1831 NI_PFI(30),
1832 NI_PFI(31),
1833 NI_PFI(32),
1834 NI_PFI(33),
1835 NI_PFI(34),
1836 NI_PFI(35),
1837 NI_PFI(36),
1838 NI_PFI(37),
1839 NI_PFI(38),
1840 NI_PFI(39),
1841 TRIGGER_LINE(0),
1842 TRIGGER_LINE(1),
1843 TRIGGER_LINE(2),
1844 TRIGGER_LINE(3),
1845 TRIGGER_LINE(4),
1846 TRIGGER_LINE(5),
1847 TRIGGER_LINE(6),
1848 TRIGGER_LINE(7),
1849 NI_CtrSource(1),
1850 NI_CtrSource(2),
1851 NI_CtrSource(3),
1852 NI_CtrGate(1),
1853 NI_CtrGate(2),
1854 NI_CtrGate(3),
1855 NI_CtrInternalOutput(1),
1856 NI_CtrInternalOutput(2),
1857 NI_CtrInternalOutput(3),
1858 NI_LogicLow,
1859 NI_LogicHigh,
1860 0, /* Termination */
1861 }
1862 },
1863 {
1864 .dest = NI_CtrGate(1),
1865 .src = (int[]){
1866 NI_PFI(0),
1867 NI_PFI(1),
1868 NI_PFI(2),
1869 NI_PFI(3),
1870 NI_PFI(4),
1871 NI_PFI(5),
1872 NI_PFI(6),
1873 NI_PFI(7),
1874 NI_PFI(8),
1875 NI_PFI(9),
1876 NI_PFI(10),
1877 NI_PFI(11),
1878 NI_PFI(12),
1879 NI_PFI(13),
1880 NI_PFI(14),
1881 NI_PFI(15),
1882 NI_PFI(16),
1883 NI_PFI(17),
1884 NI_PFI(18),
1885 NI_PFI(19),
1886 NI_PFI(20),
1887 NI_PFI(21),
1888 NI_PFI(22),
1889 NI_PFI(23),
1890 NI_PFI(24),
1891 NI_PFI(25),
1892 NI_PFI(26),
1893 NI_PFI(27),
1894 NI_PFI(28),
1895 NI_PFI(29),
1896 NI_PFI(30),
1897 NI_PFI(31),
1898 NI_PFI(32),
1899 NI_PFI(33),
1900 NI_PFI(34),
1901 NI_PFI(35),
1902 NI_PFI(36),
1903 NI_PFI(37),
1904 NI_PFI(38),
1905 NI_PFI(39),
1906 TRIGGER_LINE(0),
1907 TRIGGER_LINE(1),
1908 TRIGGER_LINE(2),
1909 TRIGGER_LINE(3),
1910 TRIGGER_LINE(4),
1911 TRIGGER_LINE(5),
1912 TRIGGER_LINE(6),
1913 TRIGGER_LINE(7),
1914 NI_CtrSource(0),
1915 NI_CtrSource(2),
1916 NI_CtrSource(3),
1917 NI_CtrGate(0),
1918 NI_CtrGate(2),
1919 NI_CtrGate(3),
1920 NI_CtrInternalOutput(0),
1921 NI_CtrInternalOutput(2),
1922 NI_CtrInternalOutput(3),
1923 NI_LogicLow,
1924 NI_LogicHigh,
1925 0, /* Termination */
1926 }
1927 },
1928 {
1929 .dest = NI_CtrGate(2),
1930 .src = (int[]){
1931 NI_PFI(0),
1932 NI_PFI(1),
1933 NI_PFI(2),
1934 NI_PFI(3),
1935 NI_PFI(4),
1936 NI_PFI(5),
1937 NI_PFI(6),
1938 NI_PFI(7),
1939 NI_PFI(8),
1940 NI_PFI(9),
1941 NI_PFI(10),
1942 NI_PFI(11),
1943 NI_PFI(12),
1944 NI_PFI(13),
1945 NI_PFI(14),
1946 NI_PFI(15),
1947 NI_PFI(16),
1948 NI_PFI(17),
1949 NI_PFI(18),
1950 NI_PFI(19),
1951 NI_PFI(20),
1952 NI_PFI(21),
1953 NI_PFI(22),
1954 NI_PFI(23),
1955 NI_PFI(24),
1956 NI_PFI(25),
1957 NI_PFI(26),
1958 NI_PFI(27),
1959 NI_PFI(28),
1960 NI_PFI(29),
1961 NI_PFI(30),
1962 NI_PFI(31),
1963 NI_PFI(32),
1964 NI_PFI(33),
1965 NI_PFI(34),
1966 NI_PFI(35),
1967 NI_PFI(36),
1968 NI_PFI(37),
1969 NI_PFI(38),
1970 NI_PFI(39),
1971 TRIGGER_LINE(0),
1972 TRIGGER_LINE(1),
1973 TRIGGER_LINE(2),
1974 TRIGGER_LINE(3),
1975 TRIGGER_LINE(4),
1976 TRIGGER_LINE(5),
1977 TRIGGER_LINE(6),
1978 TRIGGER_LINE(7),
1979 NI_CtrSource(0),
1980 NI_CtrSource(1),
1981 NI_CtrSource(3),
1982 NI_CtrGate(0),
1983 NI_CtrGate(1),
1984 NI_CtrGate(3),
1985 NI_CtrInternalOutput(0),
1986 NI_CtrInternalOutput(1),
1987 NI_CtrInternalOutput(3),
1988 NI_LogicLow,
1989 NI_LogicHigh,
1990 0, /* Termination */
1991 }
1992 },
1993 {
1994 .dest = NI_CtrGate(3),
1995 .src = (int[]){
1996 NI_PFI(0),
1997 NI_PFI(1),
1998 NI_PFI(2),
1999 NI_PFI(3),
2000 NI_PFI(4),
2001 NI_PFI(5),
2002 NI_PFI(6),
2003 NI_PFI(7),
2004 NI_PFI(8),
2005 NI_PFI(9),
2006 NI_PFI(10),
2007 NI_PFI(11),
2008 NI_PFI(12),
2009 NI_PFI(13),
2010 NI_PFI(14),
2011 NI_PFI(15),
2012 NI_PFI(16),
2013 NI_PFI(17),
2014 NI_PFI(18),
2015 NI_PFI(19),
2016 NI_PFI(20),
2017 NI_PFI(21),
2018 NI_PFI(22),
2019 NI_PFI(23),
2020 NI_PFI(24),
2021 NI_PFI(25),
2022 NI_PFI(26),
2023 NI_PFI(27),
2024 NI_PFI(28),
2025 NI_PFI(29),
2026 NI_PFI(30),
2027 NI_PFI(31),
2028 NI_PFI(32),
2029 NI_PFI(33),
2030 NI_PFI(34),
2031 NI_PFI(35),
2032 NI_PFI(36),
2033 NI_PFI(37),
2034 NI_PFI(38),
2035 NI_PFI(39),
2036 TRIGGER_LINE(0),
2037 TRIGGER_LINE(1),
2038 TRIGGER_LINE(2),
2039 TRIGGER_LINE(3),
2040 TRIGGER_LINE(4),
2041 TRIGGER_LINE(5),
2042 TRIGGER_LINE(6),
2043 TRIGGER_LINE(7),
2044 NI_CtrSource(0),
2045 NI_CtrSource(1),
2046 NI_CtrSource(2),
2047 NI_CtrGate(0),
2048 NI_CtrGate(1),
2049 NI_CtrGate(2),
2050 NI_CtrInternalOutput(0),
2051 NI_CtrInternalOutput(1),
2052 NI_CtrInternalOutput(2),
2053 NI_LogicLow,
2054 NI_LogicHigh,
2055 0, /* Termination */
2056 }
2057 },
2058 {
2059 .dest = NI_CtrGate(4),
2060 .src = (int[]){
2061 NI_PFI(0),
2062 NI_PFI(1),
2063 NI_PFI(2),
2064 NI_PFI(3),
2065 NI_PFI(4),
2066 NI_PFI(5),
2067 NI_PFI(6),
2068 NI_PFI(7),
2069 NI_PFI(8),
2070 NI_PFI(9),
2071 NI_PFI(10),
2072 NI_PFI(11),
2073 NI_PFI(12),
2074 NI_PFI(13),
2075 NI_PFI(14),
2076 NI_PFI(15),
2077 NI_PFI(16),
2078 NI_PFI(17),
2079 NI_PFI(18),
2080 NI_PFI(19),
2081 NI_PFI(20),
2082 NI_PFI(21),
2083 NI_PFI(22),
2084 NI_PFI(23),
2085 NI_PFI(24),
2086 NI_PFI(25),
2087 NI_PFI(26),
2088 NI_PFI(27),
2089 NI_PFI(28),
2090 NI_PFI(29),
2091 NI_PFI(30),
2092 NI_PFI(31),
2093 NI_PFI(32),
2094 NI_PFI(33),
2095 NI_PFI(34),
2096 NI_PFI(35),
2097 NI_PFI(36),
2098 NI_PFI(37),
2099 NI_PFI(38),
2100 NI_PFI(39),
2101 TRIGGER_LINE(0),
2102 TRIGGER_LINE(1),
2103 TRIGGER_LINE(2),
2104 TRIGGER_LINE(3),
2105 TRIGGER_LINE(4),
2106 TRIGGER_LINE(5),
2107 TRIGGER_LINE(6),
2108 TRIGGER_LINE(7),
2109 NI_CtrSource(5),
2110 NI_CtrSource(6),
2111 NI_CtrSource(7),
2112 NI_CtrGate(5),
2113 NI_CtrGate(6),
2114 NI_CtrGate(7),
2115 NI_CtrInternalOutput(5),
2116 NI_CtrInternalOutput(6),
2117 NI_CtrInternalOutput(7),
2118 NI_LogicLow,
2119 NI_LogicHigh,
2120 0, /* Termination */
2121 }
2122 },
2123 {
2124 .dest = NI_CtrGate(5),
2125 .src = (int[]){
2126 NI_PFI(0),
2127 NI_PFI(1),
2128 NI_PFI(2),
2129 NI_PFI(3),
2130 NI_PFI(4),
2131 NI_PFI(5),
2132 NI_PFI(6),
2133 NI_PFI(7),
2134 NI_PFI(8),
2135 NI_PFI(9),
2136 NI_PFI(10),
2137 NI_PFI(11),
2138 NI_PFI(12),
2139 NI_PFI(13),
2140 NI_PFI(14),
2141 NI_PFI(15),
2142 NI_PFI(16),
2143 NI_PFI(17),
2144 NI_PFI(18),
2145 NI_PFI(19),
2146 NI_PFI(20),
2147 NI_PFI(21),
2148 NI_PFI(22),
2149 NI_PFI(23),
2150 NI_PFI(24),
2151 NI_PFI(25),
2152 NI_PFI(26),
2153 NI_PFI(27),
2154 NI_PFI(28),
2155 NI_PFI(29),
2156 NI_PFI(30),
2157 NI_PFI(31),
2158 NI_PFI(32),
2159 NI_PFI(33),
2160 NI_PFI(34),
2161 NI_PFI(35),
2162 NI_PFI(36),
2163 NI_PFI(37),
2164 NI_PFI(38),
2165 NI_PFI(39),
2166 TRIGGER_LINE(0),
2167 TRIGGER_LINE(1),
2168 TRIGGER_LINE(2),
2169 TRIGGER_LINE(3),
2170 TRIGGER_LINE(4),
2171 TRIGGER_LINE(5),
2172 TRIGGER_LINE(6),
2173 TRIGGER_LINE(7),
2174 NI_CtrSource(4),
2175 NI_CtrSource(6),
2176 NI_CtrSource(7),
2177 NI_CtrGate(4),
2178 NI_CtrGate(6),
2179 NI_CtrGate(7),
2180 NI_CtrInternalOutput(4),
2181 NI_CtrInternalOutput(6),
2182 NI_CtrInternalOutput(7),
2183 NI_LogicLow,
2184 NI_LogicHigh,
2185 0, /* Termination */
2186 }
2187 },
2188 {
2189 .dest = NI_CtrGate(6),
2190 .src = (int[]){
2191 NI_PFI(0),
2192 NI_PFI(1),
2193 NI_PFI(2),
2194 NI_PFI(3),
2195 NI_PFI(4),
2196 NI_PFI(5),
2197 NI_PFI(6),
2198 NI_PFI(7),
2199 NI_PFI(8),
2200 NI_PFI(9),
2201 NI_PFI(10),
2202 NI_PFI(11),
2203 NI_PFI(12),
2204 NI_PFI(13),
2205 NI_PFI(14),
2206 NI_PFI(15),
2207 NI_PFI(16),
2208 NI_PFI(17),
2209 NI_PFI(18),
2210 NI_PFI(19),
2211 NI_PFI(20),
2212 NI_PFI(21),
2213 NI_PFI(22),
2214 NI_PFI(23),
2215 NI_PFI(24),
2216 NI_PFI(25),
2217 NI_PFI(26),
2218 NI_PFI(27),
2219 NI_PFI(28),
2220 NI_PFI(29),
2221 NI_PFI(30),
2222 NI_PFI(31),
2223 NI_PFI(32),
2224 NI_PFI(33),
2225 NI_PFI(34),
2226 NI_PFI(35),
2227 NI_PFI(36),
2228 NI_PFI(37),
2229 NI_PFI(38),
2230 NI_PFI(39),
2231 TRIGGER_LINE(0),
2232 TRIGGER_LINE(1),
2233 TRIGGER_LINE(2),
2234 TRIGGER_LINE(3),
2235 TRIGGER_LINE(4),
2236 TRIGGER_LINE(5),
2237 TRIGGER_LINE(6),
2238 TRIGGER_LINE(7),
2239 NI_CtrSource(4),
2240 NI_CtrSource(5),
2241 NI_CtrSource(7),
2242 NI_CtrGate(4),
2243 NI_CtrGate(5),
2244 NI_CtrGate(7),
2245 NI_CtrInternalOutput(4),
2246 NI_CtrInternalOutput(5),
2247 NI_CtrInternalOutput(7),
2248 NI_LogicLow,
2249 NI_LogicHigh,
2250 0, /* Termination */
2251 }
2252 },
2253 {
2254 .dest = NI_CtrGate(7),
2255 .src = (int[]){
2256 NI_PFI(0),
2257 NI_PFI(1),
2258 NI_PFI(2),
2259 NI_PFI(3),
2260 NI_PFI(4),
2261 NI_PFI(5),
2262 NI_PFI(6),
2263 NI_PFI(7),
2264 NI_PFI(8),
2265 NI_PFI(9),
2266 NI_PFI(10),
2267 NI_PFI(11),
2268 NI_PFI(12),
2269 NI_PFI(13),
2270 NI_PFI(14),
2271 NI_PFI(15),
2272 NI_PFI(16),
2273 NI_PFI(17),
2274 NI_PFI(18),
2275 NI_PFI(19),
2276 NI_PFI(20),
2277 NI_PFI(21),
2278 NI_PFI(22),
2279 NI_PFI(23),
2280 NI_PFI(24),
2281 NI_PFI(25),
2282 NI_PFI(26),
2283 NI_PFI(27),
2284 NI_PFI(28),
2285 NI_PFI(29),
2286 NI_PFI(30),
2287 NI_PFI(31),
2288 NI_PFI(32),
2289 NI_PFI(33),
2290 NI_PFI(34),
2291 NI_PFI(35),
2292 NI_PFI(36),
2293 NI_PFI(37),
2294 NI_PFI(38),
2295 NI_PFI(39),
2296 TRIGGER_LINE(0),
2297 TRIGGER_LINE(1),
2298 TRIGGER_LINE(2),
2299 TRIGGER_LINE(3),
2300 TRIGGER_LINE(4),
2301 TRIGGER_LINE(5),
2302 TRIGGER_LINE(6),
2303 TRIGGER_LINE(7),
2304 NI_CtrSource(4),
2305 NI_CtrSource(5),
2306 NI_CtrSource(6),
2307 NI_CtrGate(4),
2308 NI_CtrGate(5),
2309 NI_CtrGate(6),
2310 NI_CtrInternalOutput(4),
2311 NI_CtrInternalOutput(5),
2312 NI_CtrInternalOutput(6),
2313 NI_LogicLow,
2314 NI_LogicHigh,
2315 0, /* Termination */
2316 }
2317 },
2318 {
2319 .dest = NI_CtrAux(0),
2320 .src = (int[]){
2321 NI_PFI(0),
2322 NI_PFI(1),
2323 NI_PFI(2),
2324 NI_PFI(3),
2325 NI_PFI(4),
2326 NI_PFI(5),
2327 NI_PFI(6),
2328 NI_PFI(7),
2329 NI_PFI(8),
2330 NI_PFI(9),
2331 NI_PFI(10),
2332 NI_PFI(11),
2333 NI_PFI(12),
2334 NI_PFI(13),
2335 NI_PFI(14),
2336 NI_PFI(15),
2337 NI_PFI(16),
2338 NI_PFI(17),
2339 NI_PFI(18),
2340 NI_PFI(19),
2341 NI_PFI(20),
2342 NI_PFI(21),
2343 NI_PFI(22),
2344 NI_PFI(23),
2345 NI_PFI(24),
2346 NI_PFI(25),
2347 NI_PFI(26),
2348 NI_PFI(27),
2349 NI_PFI(28),
2350 NI_PFI(29),
2351 NI_PFI(30),
2352 NI_PFI(31),
2353 NI_PFI(32),
2354 NI_PFI(33),
2355 NI_PFI(34),
2356 NI_PFI(35),
2357 NI_PFI(36),
2358 NI_PFI(37),
2359 NI_PFI(38),
2360 NI_PFI(39),
2361 TRIGGER_LINE(0),
2362 TRIGGER_LINE(1),
2363 TRIGGER_LINE(2),
2364 TRIGGER_LINE(3),
2365 TRIGGER_LINE(4),
2366 TRIGGER_LINE(5),
2367 TRIGGER_LINE(6),
2368 TRIGGER_LINE(7),
2369 NI_CtrSource(1),
2370 NI_CtrSource(2),
2371 NI_CtrSource(3),
2372 NI_CtrGate(0),
2373 NI_CtrGate(1),
2374 NI_CtrGate(2),
2375 NI_CtrGate(3),
2376 NI_CtrInternalOutput(1),
2377 NI_CtrInternalOutput(2),
2378 NI_CtrInternalOutput(3),
2379 NI_LogicLow,
2380 NI_LogicHigh,
2381 0, /* Termination */
2382 }
2383 },
2384 {
2385 .dest = NI_CtrAux(1),
2386 .src = (int[]){
2387 NI_PFI(0),
2388 NI_PFI(1),
2389 NI_PFI(2),
2390 NI_PFI(3),
2391 NI_PFI(4),
2392 NI_PFI(5),
2393 NI_PFI(6),
2394 NI_PFI(7),
2395 NI_PFI(8),
2396 NI_PFI(9),
2397 NI_PFI(10),
2398 NI_PFI(11),
2399 NI_PFI(12),
2400 NI_PFI(13),
2401 NI_PFI(14),
2402 NI_PFI(15),
2403 NI_PFI(16),
2404 NI_PFI(17),
2405 NI_PFI(18),
2406 NI_PFI(19),
2407 NI_PFI(20),
2408 NI_PFI(21),
2409 NI_PFI(22),
2410 NI_PFI(23),
2411 NI_PFI(24),
2412 NI_PFI(25),
2413 NI_PFI(26),
2414 NI_PFI(27),
2415 NI_PFI(28),
2416 NI_PFI(29),
2417 NI_PFI(30),
2418 NI_PFI(31),
2419 NI_PFI(32),
2420 NI_PFI(33),
2421 NI_PFI(34),
2422 NI_PFI(35),
2423 NI_PFI(36),
2424 NI_PFI(37),
2425 NI_PFI(38),
2426 NI_PFI(39),
2427 TRIGGER_LINE(0),
2428 TRIGGER_LINE(1),
2429 TRIGGER_LINE(2),
2430 TRIGGER_LINE(3),
2431 TRIGGER_LINE(4),
2432 TRIGGER_LINE(5),
2433 TRIGGER_LINE(6),
2434 TRIGGER_LINE(7),
2435 NI_CtrSource(0),
2436 NI_CtrSource(2),
2437 NI_CtrSource(3),
2438 NI_CtrGate(0),
2439 NI_CtrGate(1),
2440 NI_CtrGate(2),
2441 NI_CtrGate(3),
2442 NI_CtrInternalOutput(0),
2443 NI_CtrInternalOutput(2),
2444 NI_CtrInternalOutput(3),
2445 NI_LogicLow,
2446 NI_LogicHigh,
2447 0, /* Termination */
2448 }
2449 },
2450 {
2451 .dest = NI_CtrAux(2),
2452 .src = (int[]){
2453 NI_PFI(0),
2454 NI_PFI(1),
2455 NI_PFI(2),
2456 NI_PFI(3),
2457 NI_PFI(4),
2458 NI_PFI(5),
2459 NI_PFI(6),
2460 NI_PFI(7),
2461 NI_PFI(8),
2462 NI_PFI(9),
2463 NI_PFI(10),
2464 NI_PFI(11),
2465 NI_PFI(12),
2466 NI_PFI(13),
2467 NI_PFI(14),
2468 NI_PFI(15),
2469 NI_PFI(16),
2470 NI_PFI(17),
2471 NI_PFI(18),
2472 NI_PFI(19),
2473 NI_PFI(20),
2474 NI_PFI(21),
2475 NI_PFI(22),
2476 NI_PFI(23),
2477 NI_PFI(24),
2478 NI_PFI(25),
2479 NI_PFI(26),
2480 NI_PFI(27),
2481 NI_PFI(28),
2482 NI_PFI(29),
2483 NI_PFI(30),
2484 NI_PFI(31),
2485 NI_PFI(32),
2486 NI_PFI(33),
2487 NI_PFI(34),
2488 NI_PFI(35),
2489 NI_PFI(36),
2490 NI_PFI(37),
2491 NI_PFI(38),
2492 NI_PFI(39),
2493 TRIGGER_LINE(0),
2494 TRIGGER_LINE(1),
2495 TRIGGER_LINE(2),
2496 TRIGGER_LINE(3),
2497 TRIGGER_LINE(4),
2498 TRIGGER_LINE(5),
2499 TRIGGER_LINE(6),
2500 TRIGGER_LINE(7),
2501 NI_CtrSource(0),
2502 NI_CtrSource(1),
2503 NI_CtrSource(3),
2504 NI_CtrGate(0),
2505 NI_CtrGate(1),
2506 NI_CtrGate(2),
2507 NI_CtrGate(3),
2508 NI_CtrInternalOutput(0),
2509 NI_CtrInternalOutput(1),
2510 NI_CtrInternalOutput(3),
2511 NI_LogicLow,
2512 NI_LogicHigh,
2513 0, /* Termination */
2514 }
2515 },
2516 {
2517 .dest = NI_CtrAux(3),
2518 .src = (int[]){
2519 NI_PFI(0),
2520 NI_PFI(1),
2521 NI_PFI(2),
2522 NI_PFI(3),
2523 NI_PFI(4),
2524 NI_PFI(5),
2525 NI_PFI(6),
2526 NI_PFI(7),
2527 NI_PFI(8),
2528 NI_PFI(9),
2529 NI_PFI(10),
2530 NI_PFI(11),
2531 NI_PFI(12),
2532 NI_PFI(13),
2533 NI_PFI(14),
2534 NI_PFI(15),
2535 NI_PFI(16),
2536 NI_PFI(17),
2537 NI_PFI(18),
2538 NI_PFI(19),
2539 NI_PFI(20),
2540 NI_PFI(21),
2541 NI_PFI(22),
2542 NI_PFI(23),
2543 NI_PFI(24),
2544 NI_PFI(25),
2545 NI_PFI(26),
2546 NI_PFI(27),
2547 NI_PFI(28),
2548 NI_PFI(29),
2549 NI_PFI(30),
2550 NI_PFI(31),
2551 NI_PFI(32),
2552 NI_PFI(33),
2553 NI_PFI(34),
2554 NI_PFI(35),
2555 NI_PFI(36),
2556 NI_PFI(37),
2557 NI_PFI(38),
2558 NI_PFI(39),
2559 TRIGGER_LINE(0),
2560 TRIGGER_LINE(1),
2561 TRIGGER_LINE(2),
2562 TRIGGER_LINE(3),
2563 TRIGGER_LINE(4),
2564 TRIGGER_LINE(5),
2565 TRIGGER_LINE(6),
2566 TRIGGER_LINE(7),
2567 NI_CtrSource(0),
2568 NI_CtrSource(1),
2569 NI_CtrSource(2),
2570 NI_CtrGate(0),
2571 NI_CtrGate(1),
2572 NI_CtrGate(2),
2573 NI_CtrGate(3),
2574 NI_CtrInternalOutput(0),
2575 NI_CtrInternalOutput(1),
2576 NI_CtrInternalOutput(2),
2577 NI_LogicLow,
2578 NI_LogicHigh,
2579 0, /* Termination */
2580 }
2581 },
2582 {
2583 .dest = NI_CtrAux(4),
2584 .src = (int[]){
2585 NI_PFI(0),
2586 NI_PFI(1),
2587 NI_PFI(2),
2588 NI_PFI(3),
2589 NI_PFI(4),
2590 NI_PFI(5),
2591 NI_PFI(6),
2592 NI_PFI(7),
2593 NI_PFI(8),
2594 NI_PFI(9),
2595 NI_PFI(10),
2596 NI_PFI(11),
2597 NI_PFI(12),
2598 NI_PFI(13),
2599 NI_PFI(14),
2600 NI_PFI(15),
2601 NI_PFI(16),
2602 NI_PFI(17),
2603 NI_PFI(18),
2604 NI_PFI(19),
2605 NI_PFI(20),
2606 NI_PFI(21),
2607 NI_PFI(22),
2608 NI_PFI(23),
2609 NI_PFI(24),
2610 NI_PFI(25),
2611 NI_PFI(26),
2612 NI_PFI(27),
2613 NI_PFI(28),
2614 NI_PFI(29),
2615 NI_PFI(30),
2616 NI_PFI(31),
2617 NI_PFI(32),
2618 NI_PFI(33),
2619 NI_PFI(34),
2620 NI_PFI(35),
2621 NI_PFI(36),
2622 NI_PFI(37),
2623 NI_PFI(38),
2624 NI_PFI(39),
2625 TRIGGER_LINE(0),
2626 TRIGGER_LINE(1),
2627 TRIGGER_LINE(2),
2628 TRIGGER_LINE(3),
2629 TRIGGER_LINE(4),
2630 TRIGGER_LINE(5),
2631 TRIGGER_LINE(6),
2632 TRIGGER_LINE(7),
2633 NI_CtrSource(5),
2634 NI_CtrSource(6),
2635 NI_CtrSource(7),
2636 NI_CtrGate(4),
2637 NI_CtrGate(5),
2638 NI_CtrGate(6),
2639 NI_CtrGate(7),
2640 NI_CtrInternalOutput(5),
2641 NI_CtrInternalOutput(6),
2642 NI_CtrInternalOutput(7),
2643 NI_LogicLow,
2644 NI_LogicHigh,
2645 0, /* Termination */
2646 }
2647 },
2648 {
2649 .dest = NI_CtrAux(5),
2650 .src = (int[]){
2651 NI_PFI(0),
2652 NI_PFI(1),
2653 NI_PFI(2),
2654 NI_PFI(3),
2655 NI_PFI(4),
2656 NI_PFI(5),
2657 NI_PFI(6),
2658 NI_PFI(7),
2659 NI_PFI(8),
2660 NI_PFI(9),
2661 NI_PFI(10),
2662 NI_PFI(11),
2663 NI_PFI(12),
2664 NI_PFI(13),
2665 NI_PFI(14),
2666 NI_PFI(15),
2667 NI_PFI(16),
2668 NI_PFI(17),
2669 NI_PFI(18),
2670 NI_PFI(19),
2671 NI_PFI(20),
2672 NI_PFI(21),
2673 NI_PFI(22),
2674 NI_PFI(23),
2675 NI_PFI(24),
2676 NI_PFI(25),
2677 NI_PFI(26),
2678 NI_PFI(27),
2679 NI_PFI(28),
2680 NI_PFI(29),
2681 NI_PFI(30),
2682 NI_PFI(31),
2683 NI_PFI(32),
2684 NI_PFI(33),
2685 NI_PFI(34),
2686 NI_PFI(35),
2687 NI_PFI(36),
2688 NI_PFI(37),
2689 NI_PFI(38),
2690 NI_PFI(39),
2691 TRIGGER_LINE(0),
2692 TRIGGER_LINE(1),
2693 TRIGGER_LINE(2),
2694 TRIGGER_LINE(3),
2695 TRIGGER_LINE(4),
2696 TRIGGER_LINE(5),
2697 TRIGGER_LINE(6),
2698 TRIGGER_LINE(7),
2699 NI_CtrSource(4),
2700 NI_CtrSource(6),
2701 NI_CtrSource(7),
2702 NI_CtrGate(4),
2703 NI_CtrGate(5),
2704 NI_CtrGate(6),
2705 NI_CtrGate(7),
2706 NI_CtrInternalOutput(4),
2707 NI_CtrInternalOutput(6),
2708 NI_CtrInternalOutput(7),
2709 NI_LogicLow,
2710 NI_LogicHigh,
2711 0, /* Termination */
2712 }
2713 },
2714 {
2715 .dest = NI_CtrAux(6),
2716 .src = (int[]){
2717 NI_PFI(0),
2718 NI_PFI(1),
2719 NI_PFI(2),
2720 NI_PFI(3),
2721 NI_PFI(4),
2722 NI_PFI(5),
2723 NI_PFI(6),
2724 NI_PFI(7),
2725 NI_PFI(8),
2726 NI_PFI(9),
2727 NI_PFI(10),
2728 NI_PFI(11),
2729 NI_PFI(12),
2730 NI_PFI(13),
2731 NI_PFI(14),
2732 NI_PFI(15),
2733 NI_PFI(16),
2734 NI_PFI(17),
2735 NI_PFI(18),
2736 NI_PFI(19),
2737 NI_PFI(20),
2738 NI_PFI(21),
2739 NI_PFI(22),
2740 NI_PFI(23),
2741 NI_PFI(24),
2742 NI_PFI(25),
2743 NI_PFI(26),
2744 NI_PFI(27),
2745 NI_PFI(28),
2746 NI_PFI(29),
2747 NI_PFI(30),
2748 NI_PFI(31),
2749 NI_PFI(32),
2750 NI_PFI(33),
2751 NI_PFI(34),
2752 NI_PFI(35),
2753 NI_PFI(36),
2754 NI_PFI(37),
2755 NI_PFI(38),
2756 NI_PFI(39),
2757 TRIGGER_LINE(0),
2758 TRIGGER_LINE(1),
2759 TRIGGER_LINE(2),
2760 TRIGGER_LINE(3),
2761 TRIGGER_LINE(4),
2762 TRIGGER_LINE(5),
2763 TRIGGER_LINE(6),
2764 TRIGGER_LINE(7),
2765 NI_CtrSource(4),
2766 NI_CtrSource(5),
2767 NI_CtrSource(7),
2768 NI_CtrGate(4),
2769 NI_CtrGate(5),
2770 NI_CtrGate(6),
2771 NI_CtrGate(7),
2772 NI_CtrInternalOutput(4),
2773 NI_CtrInternalOutput(5),
2774 NI_CtrInternalOutput(7),
2775 NI_LogicLow,
2776 NI_LogicHigh,
2777 0, /* Termination */
2778 }
2779 },
2780 {
2781 .dest = NI_CtrAux(7),
2782 .src = (int[]){
2783 NI_PFI(0),
2784 NI_PFI(1),
2785 NI_PFI(2),
2786 NI_PFI(3),
2787 NI_PFI(4),
2788 NI_PFI(5),
2789 NI_PFI(6),
2790 NI_PFI(7),
2791 NI_PFI(8),
2792 NI_PFI(9),
2793 NI_PFI(10),
2794 NI_PFI(11),
2795 NI_PFI(12),
2796 NI_PFI(13),
2797 NI_PFI(14),
2798 NI_PFI(15),
2799 NI_PFI(16),
2800 NI_PFI(17),
2801 NI_PFI(18),
2802 NI_PFI(19),
2803 NI_PFI(20),
2804 NI_PFI(21),
2805 NI_PFI(22),
2806 NI_PFI(23),
2807 NI_PFI(24),
2808 NI_PFI(25),
2809 NI_PFI(26),
2810 NI_PFI(27),
2811 NI_PFI(28),
2812 NI_PFI(29),
2813 NI_PFI(30),
2814 NI_PFI(31),
2815 NI_PFI(32),
2816 NI_PFI(33),
2817 NI_PFI(34),
2818 NI_PFI(35),
2819 NI_PFI(36),
2820 NI_PFI(37),
2821 NI_PFI(38),
2822 NI_PFI(39),
2823 TRIGGER_LINE(0),
2824 TRIGGER_LINE(1),
2825 TRIGGER_LINE(2),
2826 TRIGGER_LINE(3),
2827 TRIGGER_LINE(4),
2828 TRIGGER_LINE(5),
2829 TRIGGER_LINE(6),
2830 TRIGGER_LINE(7),
2831 NI_CtrSource(4),
2832 NI_CtrSource(5),
2833 NI_CtrSource(6),
2834 NI_CtrGate(4),
2835 NI_CtrGate(5),
2836 NI_CtrGate(6),
2837 NI_CtrGate(7),
2838 NI_CtrInternalOutput(4),
2839 NI_CtrInternalOutput(5),
2840 NI_CtrInternalOutput(6),
2841 NI_LogicLow,
2842 NI_LogicHigh,
2843 0, /* Termination */
2844 }
2845 },
2846 {
2847 .dest = NI_CtrArmStartTrigger(0),
2848 .src = (int[]){
2849 NI_PFI(0),
2850 NI_PFI(1),
2851 NI_PFI(2),
2852 NI_PFI(3),
2853 NI_PFI(4),
2854 NI_PFI(5),
2855 NI_PFI(6),
2856 NI_PFI(7),
2857 NI_PFI(8),
2858 NI_PFI(9),
2859 NI_PFI(10),
2860 NI_PFI(11),
2861 NI_PFI(12),
2862 NI_PFI(13),
2863 NI_PFI(14),
2864 NI_PFI(15),
2865 NI_PFI(16),
2866 NI_PFI(17),
2867 NI_PFI(18),
2868 NI_PFI(19),
2869 NI_PFI(20),
2870 NI_PFI(21),
2871 NI_PFI(22),
2872 NI_PFI(23),
2873 NI_PFI(24),
2874 NI_PFI(25),
2875 NI_PFI(26),
2876 NI_PFI(27),
2877 NI_PFI(28),
2878 NI_PFI(29),
2879 NI_PFI(30),
2880 NI_PFI(31),
2881 NI_PFI(32),
2882 NI_PFI(33),
2883 NI_PFI(34),
2884 NI_PFI(35),
2885 NI_PFI(36),
2886 NI_PFI(37),
2887 NI_PFI(38),
2888 NI_PFI(39),
2889 TRIGGER_LINE(0),
2890 TRIGGER_LINE(1),
2891 TRIGGER_LINE(2),
2892 TRIGGER_LINE(3),
2893 TRIGGER_LINE(4),
2894 TRIGGER_LINE(5),
2895 TRIGGER_LINE(6),
2896 TRIGGER_LINE(7),
2897 NI_CtrSource(1),
2898 NI_CtrSource(2),
2899 NI_CtrSource(3),
2900 NI_CtrGate(1),
2901 NI_CtrGate(2),
2902 NI_CtrGate(3),
2903 NI_CtrInternalOutput(1),
2904 NI_CtrInternalOutput(2),
2905 NI_CtrInternalOutput(3),
2906 NI_LogicLow,
2907 NI_LogicHigh,
2908 0, /* Termination */
2909 }
2910 },
2911 {
2912 .dest = NI_CtrArmStartTrigger(1),
2913 .src = (int[]){
2914 NI_PFI(0),
2915 NI_PFI(1),
2916 NI_PFI(2),
2917 NI_PFI(3),
2918 NI_PFI(4),
2919 NI_PFI(5),
2920 NI_PFI(6),
2921 NI_PFI(7),
2922 NI_PFI(8),
2923 NI_PFI(9),
2924 NI_PFI(10),
2925 NI_PFI(11),
2926 NI_PFI(12),
2927 NI_PFI(13),
2928 NI_PFI(14),
2929 NI_PFI(15),
2930 NI_PFI(16),
2931 NI_PFI(17),
2932 NI_PFI(18),
2933 NI_PFI(19),
2934 NI_PFI(20),
2935 NI_PFI(21),
2936 NI_PFI(22),
2937 NI_PFI(23),
2938 NI_PFI(24),
2939 NI_PFI(25),
2940 NI_PFI(26),
2941 NI_PFI(27),
2942 NI_PFI(28),
2943 NI_PFI(29),
2944 NI_PFI(30),
2945 NI_PFI(31),
2946 NI_PFI(32),
2947 NI_PFI(33),
2948 NI_PFI(34),
2949 NI_PFI(35),
2950 NI_PFI(36),
2951 NI_PFI(37),
2952 NI_PFI(38),
2953 NI_PFI(39),
2954 TRIGGER_LINE(0),
2955 TRIGGER_LINE(1),
2956 TRIGGER_LINE(2),
2957 TRIGGER_LINE(3),
2958 TRIGGER_LINE(4),
2959 TRIGGER_LINE(5),
2960 TRIGGER_LINE(6),
2961 TRIGGER_LINE(7),
2962 NI_CtrSource(0),
2963 NI_CtrSource(2),
2964 NI_CtrSource(3),
2965 NI_CtrGate(0),
2966 NI_CtrGate(2),
2967 NI_CtrGate(3),
2968 NI_CtrInternalOutput(0),
2969 NI_CtrInternalOutput(2),
2970 NI_CtrInternalOutput(3),
2971 NI_LogicLow,
2972 NI_LogicHigh,
2973 0, /* Termination */
2974 }
2975 },
2976 {
2977 .dest = NI_CtrArmStartTrigger(2),
2978 .src = (int[]){
2979 NI_PFI(0),
2980 NI_PFI(1),
2981 NI_PFI(2),
2982 NI_PFI(3),
2983 NI_PFI(4),
2984 NI_PFI(5),
2985 NI_PFI(6),
2986 NI_PFI(7),
2987 NI_PFI(8),
2988 NI_PFI(9),
2989 NI_PFI(10),
2990 NI_PFI(11),
2991 NI_PFI(12),
2992 NI_PFI(13),
2993 NI_PFI(14),
2994 NI_PFI(15),
2995 NI_PFI(16),
2996 NI_PFI(17),
2997 NI_PFI(18),
2998 NI_PFI(19),
2999 NI_PFI(20),
3000 NI_PFI(21),
3001 NI_PFI(22),
3002 NI_PFI(23),
3003 NI_PFI(24),
3004 NI_PFI(25),
3005 NI_PFI(26),
3006 NI_PFI(27),
3007 NI_PFI(28),
3008 NI_PFI(29),
3009 NI_PFI(30),
3010 NI_PFI(31),
3011 NI_PFI(32),
3012 NI_PFI(33),
3013 NI_PFI(34),
3014 NI_PFI(35),
3015 NI_PFI(36),
3016 NI_PFI(37),
3017 NI_PFI(38),
3018 NI_PFI(39),
3019 TRIGGER_LINE(0),
3020 TRIGGER_LINE(1),
3021 TRIGGER_LINE(2),
3022 TRIGGER_LINE(3),
3023 TRIGGER_LINE(4),
3024 TRIGGER_LINE(5),
3025 TRIGGER_LINE(6),
3026 TRIGGER_LINE(7),
3027 NI_CtrSource(0),
3028 NI_CtrSource(1),
3029 NI_CtrSource(3),
3030 NI_CtrGate(0),
3031 NI_CtrGate(1),
3032 NI_CtrGate(3),
3033 NI_CtrInternalOutput(0),
3034 NI_CtrInternalOutput(1),
3035 NI_CtrInternalOutput(3),
3036 NI_LogicLow,
3037 NI_LogicHigh,
3038 0, /* Termination */
3039 }
3040 },
3041 {
3042 .dest = NI_CtrArmStartTrigger(3),
3043 .src = (int[]){
3044 NI_PFI(0),
3045 NI_PFI(1),
3046 NI_PFI(2),
3047 NI_PFI(3),
3048 NI_PFI(4),
3049 NI_PFI(5),
3050 NI_PFI(6),
3051 NI_PFI(7),
3052 NI_PFI(8),
3053 NI_PFI(9),
3054 NI_PFI(10),
3055 NI_PFI(11),
3056 NI_PFI(12),
3057 NI_PFI(13),
3058 NI_PFI(14),
3059 NI_PFI(15),
3060 NI_PFI(16),
3061 NI_PFI(17),
3062 NI_PFI(18),
3063 NI_PFI(19),
3064 NI_PFI(20),
3065 NI_PFI(21),
3066 NI_PFI(22),
3067 NI_PFI(23),
3068 NI_PFI(24),
3069 NI_PFI(25),
3070 NI_PFI(26),
3071 NI_PFI(27),
3072 NI_PFI(28),
3073 NI_PFI(29),
3074 NI_PFI(30),
3075 NI_PFI(31),
3076 NI_PFI(32),
3077 NI_PFI(33),
3078 NI_PFI(34),
3079 NI_PFI(35),
3080 NI_PFI(36),
3081 NI_PFI(37),
3082 NI_PFI(38),
3083 NI_PFI(39),
3084 TRIGGER_LINE(0),
3085 TRIGGER_LINE(1),
3086 TRIGGER_LINE(2),
3087 TRIGGER_LINE(3),
3088 TRIGGER_LINE(4),
3089 TRIGGER_LINE(5),
3090 TRIGGER_LINE(6),
3091 TRIGGER_LINE(7),
3092 NI_CtrSource(0),
3093 NI_CtrSource(1),
3094 NI_CtrSource(2),
3095 NI_CtrGate(0),
3096 NI_CtrGate(1),
3097 NI_CtrGate(2),
3098 NI_CtrInternalOutput(0),
3099 NI_CtrInternalOutput(1),
3100 NI_CtrInternalOutput(2),
3101 NI_LogicLow,
3102 NI_LogicHigh,
3103 0, /* Termination */
3104 }
3105 },
3106 {
3107 .dest = NI_CtrArmStartTrigger(4),
3108 .src = (int[]){
3109 NI_PFI(0),
3110 NI_PFI(1),
3111 NI_PFI(2),
3112 NI_PFI(3),
3113 NI_PFI(4),
3114 NI_PFI(5),
3115 NI_PFI(6),
3116 NI_PFI(7),
3117 NI_PFI(8),
3118 NI_PFI(9),
3119 NI_PFI(10),
3120 NI_PFI(11),
3121 NI_PFI(12),
3122 NI_PFI(13),
3123 NI_PFI(14),
3124 NI_PFI(15),
3125 NI_PFI(16),
3126 NI_PFI(17),
3127 NI_PFI(18),
3128 NI_PFI(19),
3129 NI_PFI(20),
3130 NI_PFI(21),
3131 NI_PFI(22),
3132 NI_PFI(23),
3133 NI_PFI(24),
3134 NI_PFI(25),
3135 NI_PFI(26),
3136 NI_PFI(27),
3137 NI_PFI(28),
3138 NI_PFI(29),
3139 NI_PFI(30),
3140 NI_PFI(31),
3141 NI_PFI(32),
3142 NI_PFI(33),
3143 NI_PFI(34),
3144 NI_PFI(35),
3145 NI_PFI(36),
3146 NI_PFI(37),
3147 NI_PFI(38),
3148 NI_PFI(39),
3149 TRIGGER_LINE(0),
3150 TRIGGER_LINE(1),
3151 TRIGGER_LINE(2),
3152 TRIGGER_LINE(3),
3153 TRIGGER_LINE(4),
3154 TRIGGER_LINE(5),
3155 TRIGGER_LINE(6),
3156 TRIGGER_LINE(7),
3157 NI_CtrSource(5),
3158 NI_CtrSource(6),
3159 NI_CtrSource(7),
3160 NI_CtrGate(5),
3161 NI_CtrGate(6),
3162 NI_CtrGate(7),
3163 NI_CtrInternalOutput(5),
3164 NI_CtrInternalOutput(6),
3165 NI_CtrInternalOutput(7),
3166 NI_LogicLow,
3167 NI_LogicHigh,
3168 0, /* Termination */
3169 }
3170 },
3171 {
3172 .dest = NI_CtrArmStartTrigger(5),
3173 .src = (int[]){
3174 NI_PFI(0),
3175 NI_PFI(1),
3176 NI_PFI(2),
3177 NI_PFI(3),
3178 NI_PFI(4),
3179 NI_PFI(5),
3180 NI_PFI(6),
3181 NI_PFI(7),
3182 NI_PFI(8),
3183 NI_PFI(9),
3184 NI_PFI(10),
3185 NI_PFI(11),
3186 NI_PFI(12),
3187 NI_PFI(13),
3188 NI_PFI(14),
3189 NI_PFI(15),
3190 NI_PFI(16),
3191 NI_PFI(17),
3192 NI_PFI(18),
3193 NI_PFI(19),
3194 NI_PFI(20),
3195 NI_PFI(21),
3196 NI_PFI(22),
3197 NI_PFI(23),
3198 NI_PFI(24),
3199 NI_PFI(25),
3200 NI_PFI(26),
3201 NI_PFI(27),
3202 NI_PFI(28),
3203 NI_PFI(29),
3204 NI_PFI(30),
3205 NI_PFI(31),
3206 NI_PFI(32),
3207 NI_PFI(33),
3208 NI_PFI(34),
3209 NI_PFI(35),
3210 NI_PFI(36),
3211 NI_PFI(37),
3212 NI_PFI(38),
3213 NI_PFI(39),
3214 TRIGGER_LINE(0),
3215 TRIGGER_LINE(1),
3216 TRIGGER_LINE(2),
3217 TRIGGER_LINE(3),
3218 TRIGGER_LINE(4),
3219 TRIGGER_LINE(5),
3220 TRIGGER_LINE(6),
3221 TRIGGER_LINE(7),
3222 NI_CtrSource(4),
3223 NI_CtrSource(6),
3224 NI_CtrSource(7),
3225 NI_CtrGate(4),
3226 NI_CtrGate(6),
3227 NI_CtrGate(7),
3228 NI_CtrInternalOutput(4),
3229 NI_CtrInternalOutput(6),
3230 NI_CtrInternalOutput(7),
3231 NI_LogicLow,
3232 NI_LogicHigh,
3233 0, /* Termination */
3234 }
3235 },
3236 {
3237 .dest = NI_CtrArmStartTrigger(6),
3238 .src = (int[]){
3239 NI_PFI(0),
3240 NI_PFI(1),
3241 NI_PFI(2),
3242 NI_PFI(3),
3243 NI_PFI(4),
3244 NI_PFI(5),
3245 NI_PFI(6),
3246 NI_PFI(7),
3247 NI_PFI(8),
3248 NI_PFI(9),
3249 NI_PFI(10),
3250 NI_PFI(11),
3251 NI_PFI(12),
3252 NI_PFI(13),
3253 NI_PFI(14),
3254 NI_PFI(15),
3255 NI_PFI(16),
3256 NI_PFI(17),
3257 NI_PFI(18),
3258 NI_PFI(19),
3259 NI_PFI(20),
3260 NI_PFI(21),
3261 NI_PFI(22),
3262 NI_PFI(23),
3263 NI_PFI(24),
3264 NI_PFI(25),
3265 NI_PFI(26),
3266 NI_PFI(27),
3267 NI_PFI(28),
3268 NI_PFI(29),
3269 NI_PFI(30),
3270 NI_PFI(31),
3271 NI_PFI(32),
3272 NI_PFI(33),
3273 NI_PFI(34),
3274 NI_PFI(35),
3275 NI_PFI(36),
3276 NI_PFI(37),
3277 NI_PFI(38),
3278 NI_PFI(39),
3279 TRIGGER_LINE(0),
3280 TRIGGER_LINE(1),
3281 TRIGGER_LINE(2),
3282 TRIGGER_LINE(3),
3283 TRIGGER_LINE(4),
3284 TRIGGER_LINE(5),
3285 TRIGGER_LINE(6),
3286 TRIGGER_LINE(7),
3287 NI_CtrSource(4),
3288 NI_CtrSource(5),
3289 NI_CtrSource(7),
3290 NI_CtrGate(4),
3291 NI_CtrGate(5),
3292 NI_CtrGate(7),
3293 NI_CtrInternalOutput(4),
3294 NI_CtrInternalOutput(5),
3295 NI_CtrInternalOutput(7),
3296 NI_LogicLow,
3297 NI_LogicHigh,
3298 0, /* Termination */
3299 }
3300 },
3301 {
3302 .dest = NI_CtrArmStartTrigger(7),
3303 .src = (int[]){
3304 NI_PFI(0),
3305 NI_PFI(1),
3306 NI_PFI(2),
3307 NI_PFI(3),
3308 NI_PFI(4),
3309 NI_PFI(5),
3310 NI_PFI(6),
3311 NI_PFI(7),
3312 NI_PFI(8),
3313 NI_PFI(9),
3314 NI_PFI(10),
3315 NI_PFI(11),
3316 NI_PFI(12),
3317 NI_PFI(13),
3318 NI_PFI(14),
3319 NI_PFI(15),
3320 NI_PFI(16),
3321 NI_PFI(17),
3322 NI_PFI(18),
3323 NI_PFI(19),
3324 NI_PFI(20),
3325 NI_PFI(21),
3326 NI_PFI(22),
3327 NI_PFI(23),
3328 NI_PFI(24),
3329 NI_PFI(25),
3330 NI_PFI(26),
3331 NI_PFI(27),
3332 NI_PFI(28),
3333 NI_PFI(29),
3334 NI_PFI(30),
3335 NI_PFI(31),
3336 NI_PFI(32),
3337 NI_PFI(33),
3338 NI_PFI(34),
3339 NI_PFI(35),
3340 NI_PFI(36),
3341 NI_PFI(37),
3342 NI_PFI(38),
3343 NI_PFI(39),
3344 TRIGGER_LINE(0),
3345 TRIGGER_LINE(1),
3346 TRIGGER_LINE(2),
3347 TRIGGER_LINE(3),
3348 TRIGGER_LINE(4),
3349 TRIGGER_LINE(5),
3350 TRIGGER_LINE(6),
3351 TRIGGER_LINE(7),
3352 NI_CtrSource(4),
3353 NI_CtrSource(5),
3354 NI_CtrSource(6),
3355 NI_CtrGate(4),
3356 NI_CtrGate(5),
3357 NI_CtrGate(6),
3358 NI_CtrInternalOutput(4),
3359 NI_CtrInternalOutput(5),
3360 NI_CtrInternalOutput(6),
3361 NI_LogicLow,
3362 NI_LogicHigh,
3363 0, /* Termination */
3364 }
3365 },
3366 {
3367 .dest = NI_MasterTimebase,
3368 .src = (int[]){
3369 TRIGGER_LINE(7),
3370 NI_20MHzTimebase,
3371 0, /* Termination */
3372 }
3373 },
3374 { /* Termination of list */
3375 .dest = 0,
3376 },
3377 },
3378};
diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6713.c b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6713.c
new file mode 100644
index 000000000000..d378b36d2084
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6713.c
@@ -0,0 +1,400 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routing/ni_device_routes/pci-6713.c
5 * List of valid routes for specific NI boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21/*
22 * The contents of this file are generated using the tools in
23 * comedi/drivers/ni_routing/tools
24 *
25 * Please use those tools to help maintain the contents of this file.
26 */
27
28#include "../ni_device_routes.h"
29#include "all.h"
30
31struct ni_device_routes ni_pci_6713_device_routes = {
32 .device = "pci-6713",
33 .routes = (struct ni_route_set[]){
34 {
35 .dest = NI_PFI(3),
36 .src = (int[]){
37 NI_CtrSource(1),
38 0, /* Termination */
39 }
40 },
41 {
42 .dest = NI_PFI(4),
43 .src = (int[]){
44 NI_CtrGate(1),
45 0, /* Termination */
46 }
47 },
48 {
49 .dest = NI_PFI(5),
50 .src = (int[]){
51 NI_AO_SampleClock,
52 0, /* Termination */
53 }
54 },
55 {
56 .dest = NI_PFI(6),
57 .src = (int[]){
58 NI_AO_StartTrigger,
59 0, /* Termination */
60 }
61 },
62 {
63 .dest = NI_PFI(8),
64 .src = (int[]){
65 NI_CtrSource(0),
66 0, /* Termination */
67 }
68 },
69 {
70 .dest = NI_PFI(9),
71 .src = (int[]){
72 NI_CtrGate(0),
73 0, /* Termination */
74 }
75 },
76 {
77 .dest = TRIGGER_LINE(0),
78 .src = (int[]){
79 NI_CtrSource(0),
80 NI_CtrGate(0),
81 NI_CtrInternalOutput(0),
82 NI_CtrOut(0),
83 NI_AO_SampleClock,
84 NI_AO_StartTrigger,
85 0, /* Termination */
86 }
87 },
88 {
89 .dest = TRIGGER_LINE(1),
90 .src = (int[]){
91 NI_CtrSource(0),
92 NI_CtrGate(0),
93 NI_CtrInternalOutput(0),
94 NI_CtrOut(0),
95 NI_AO_SampleClock,
96 NI_AO_StartTrigger,
97 0, /* Termination */
98 }
99 },
100 {
101 .dest = TRIGGER_LINE(2),
102 .src = (int[]){
103 NI_CtrSource(0),
104 NI_CtrGate(0),
105 NI_CtrInternalOutput(0),
106 NI_CtrOut(0),
107 NI_AO_SampleClock,
108 NI_AO_StartTrigger,
109 0, /* Termination */
110 }
111 },
112 {
113 .dest = TRIGGER_LINE(3),
114 .src = (int[]){
115 NI_CtrSource(0),
116 NI_CtrGate(0),
117 NI_CtrInternalOutput(0),
118 NI_CtrOut(0),
119 NI_AO_SampleClock,
120 NI_AO_StartTrigger,
121 0, /* Termination */
122 }
123 },
124 {
125 .dest = TRIGGER_LINE(4),
126 .src = (int[]){
127 NI_CtrSource(0),
128 NI_CtrGate(0),
129 NI_CtrInternalOutput(0),
130 NI_CtrOut(0),
131 NI_AO_SampleClock,
132 NI_AO_StartTrigger,
133 0, /* Termination */
134 }
135 },
136 {
137 .dest = TRIGGER_LINE(5),
138 .src = (int[]){
139 NI_CtrSource(0),
140 NI_CtrGate(0),
141 NI_CtrInternalOutput(0),
142 NI_CtrOut(0),
143 NI_AO_SampleClock,
144 NI_AO_StartTrigger,
145 0, /* Termination */
146 }
147 },
148 {
149 .dest = TRIGGER_LINE(6),
150 .src = (int[]){
151 NI_CtrSource(0),
152 NI_CtrGate(0),
153 NI_CtrInternalOutput(0),
154 NI_CtrOut(0),
155 NI_AO_SampleClock,
156 NI_AO_StartTrigger,
157 0, /* Termination */
158 }
159 },
160 {
161 .dest = TRIGGER_LINE(7),
162 .src = (int[]){
163 NI_20MHzTimebase,
164 0, /* Termination */
165 }
166 },
167 {
168 .dest = NI_CtrSource(0),
169 .src = (int[]){
170 NI_PFI(0),
171 NI_PFI(1),
172 NI_PFI(2),
173 NI_PFI(3),
174 NI_PFI(4),
175 NI_PFI(5),
176 NI_PFI(6),
177 NI_PFI(7),
178 NI_PFI(8),
179 NI_PFI(9),
180 TRIGGER_LINE(0),
181 TRIGGER_LINE(1),
182 TRIGGER_LINE(2),
183 TRIGGER_LINE(3),
184 TRIGGER_LINE(4),
185 TRIGGER_LINE(5),
186 TRIGGER_LINE(6),
187 TRIGGER_LINE(7),
188 NI_MasterTimebase,
189 NI_20MHzTimebase,
190 NI_100kHzTimebase,
191 0, /* Termination */
192 }
193 },
194 {
195 .dest = NI_CtrSource(1),
196 .src = (int[]){
197 NI_PFI(0),
198 NI_PFI(1),
199 NI_PFI(2),
200 NI_PFI(3),
201 NI_PFI(4),
202 NI_PFI(5),
203 NI_PFI(6),
204 NI_PFI(7),
205 NI_PFI(8),
206 NI_PFI(9),
207 TRIGGER_LINE(0),
208 TRIGGER_LINE(1),
209 TRIGGER_LINE(2),
210 TRIGGER_LINE(3),
211 TRIGGER_LINE(4),
212 TRIGGER_LINE(5),
213 TRIGGER_LINE(6),
214 TRIGGER_LINE(7),
215 NI_MasterTimebase,
216 NI_20MHzTimebase,
217 NI_100kHzTimebase,
218 0, /* Termination */
219 }
220 },
221 {
222 .dest = NI_CtrGate(0),
223 .src = (int[]){
224 NI_PFI(0),
225 NI_PFI(1),
226 NI_PFI(2),
227 NI_PFI(3),
228 NI_PFI(4),
229 NI_PFI(5),
230 NI_PFI(6),
231 NI_PFI(7),
232 NI_PFI(8),
233 NI_PFI(9),
234 TRIGGER_LINE(0),
235 TRIGGER_LINE(1),
236 TRIGGER_LINE(2),
237 TRIGGER_LINE(3),
238 TRIGGER_LINE(4),
239 TRIGGER_LINE(5),
240 TRIGGER_LINE(6),
241 NI_CtrInternalOutput(1),
242 0, /* Termination */
243 }
244 },
245 {
246 .dest = NI_CtrGate(1),
247 .src = (int[]){
248 NI_PFI(0),
249 NI_PFI(1),
250 NI_PFI(2),
251 NI_PFI(3),
252 NI_PFI(4),
253 NI_PFI(5),
254 NI_PFI(6),
255 NI_PFI(7),
256 NI_PFI(8),
257 NI_PFI(9),
258 TRIGGER_LINE(0),
259 TRIGGER_LINE(1),
260 TRIGGER_LINE(2),
261 TRIGGER_LINE(3),
262 TRIGGER_LINE(4),
263 TRIGGER_LINE(5),
264 TRIGGER_LINE(6),
265 NI_CtrInternalOutput(0),
266 0, /* Termination */
267 }
268 },
269 {
270 .dest = NI_CtrOut(0),
271 .src = (int[]){
272 TRIGGER_LINE(0),
273 TRIGGER_LINE(1),
274 TRIGGER_LINE(2),
275 TRIGGER_LINE(3),
276 TRIGGER_LINE(4),
277 TRIGGER_LINE(5),
278 TRIGGER_LINE(6),
279 NI_CtrInternalOutput(0),
280 0, /* Termination */
281 }
282 },
283 {
284 .dest = NI_CtrOut(1),
285 .src = (int[]){
286 NI_CtrInternalOutput(1),
287 0, /* Termination */
288 }
289 },
290 {
291 .dest = NI_AO_SampleClock,
292 .src = (int[]){
293 NI_PFI(0),
294 NI_PFI(1),
295 NI_PFI(2),
296 NI_PFI(3),
297 NI_PFI(4),
298 NI_PFI(5),
299 NI_PFI(6),
300 NI_PFI(7),
301 NI_PFI(8),
302 NI_PFI(9),
303 TRIGGER_LINE(0),
304 TRIGGER_LINE(1),
305 TRIGGER_LINE(2),
306 TRIGGER_LINE(3),
307 TRIGGER_LINE(4),
308 TRIGGER_LINE(5),
309 TRIGGER_LINE(6),
310 NI_CtrInternalOutput(1),
311 NI_AO_SampleClockTimebase,
312 0, /* Termination */
313 }
314 },
315 {
316 .dest = NI_AO_SampleClockTimebase,
317 .src = (int[]){
318 NI_PFI(0),
319 NI_PFI(1),
320 NI_PFI(2),
321 NI_PFI(3),
322 NI_PFI(4),
323 NI_PFI(5),
324 NI_PFI(6),
325 NI_PFI(7),
326 NI_PFI(8),
327 NI_PFI(9),
328 TRIGGER_LINE(0),
329 TRIGGER_LINE(1),
330 TRIGGER_LINE(2),
331 TRIGGER_LINE(3),
332 TRIGGER_LINE(4),
333 TRIGGER_LINE(5),
334 TRIGGER_LINE(6),
335 TRIGGER_LINE(7),
336 NI_MasterTimebase,
337 NI_20MHzTimebase,
338 NI_100kHzTimebase,
339 0, /* Termination */
340 }
341 },
342 {
343 .dest = NI_AO_StartTrigger,
344 .src = (int[]){
345 NI_PFI(0),
346 NI_PFI(1),
347 NI_PFI(2),
348 NI_PFI(3),
349 NI_PFI(4),
350 NI_PFI(5),
351 NI_PFI(6),
352 NI_PFI(7),
353 NI_PFI(8),
354 NI_PFI(9),
355 TRIGGER_LINE(0),
356 TRIGGER_LINE(1),
357 TRIGGER_LINE(2),
358 TRIGGER_LINE(3),
359 TRIGGER_LINE(4),
360 TRIGGER_LINE(5),
361 TRIGGER_LINE(6),
362 0, /* Termination */
363 }
364 },
365 {
366 .dest = NI_AO_PauseTrigger,
367 .src = (int[]){
368 NI_PFI(0),
369 NI_PFI(1),
370 NI_PFI(2),
371 NI_PFI(3),
372 NI_PFI(4),
373 NI_PFI(5),
374 NI_PFI(6),
375 NI_PFI(7),
376 NI_PFI(8),
377 NI_PFI(9),
378 TRIGGER_LINE(0),
379 TRIGGER_LINE(1),
380 TRIGGER_LINE(2),
381 TRIGGER_LINE(3),
382 TRIGGER_LINE(4),
383 TRIGGER_LINE(5),
384 TRIGGER_LINE(6),
385 0, /* Termination */
386 }
387 },
388 {
389 .dest = NI_MasterTimebase,
390 .src = (int[]){
391 TRIGGER_LINE(7),
392 NI_20MHzTimebase,
393 0, /* Termination */
394 }
395 },
396 { /* Termination of list */
397 .dest = 0,
398 },
399 },
400};
diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6723.c b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6723.c
new file mode 100644
index 000000000000..e0cc57ab06e7
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6723.c
@@ -0,0 +1,400 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routing/ni_device_routes/pci-6723.c
5 * List of valid routes for specific NI boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21/*
22 * The contents of this file are generated using the tools in
23 * comedi/drivers/ni_routing/tools
24 *
25 * Please use those tools to help maintain the contents of this file.
26 */
27
28#include "../ni_device_routes.h"
29#include "all.h"
30
31struct ni_device_routes ni_pci_6723_device_routes = {
32 .device = "pci-6723",
33 .routes = (struct ni_route_set[]){
34 {
35 .dest = NI_PFI(3),
36 .src = (int[]){
37 NI_CtrSource(1),
38 0, /* Termination */
39 }
40 },
41 {
42 .dest = NI_PFI(4),
43 .src = (int[]){
44 NI_CtrGate(1),
45 0, /* Termination */
46 }
47 },
48 {
49 .dest = NI_PFI(5),
50 .src = (int[]){
51 NI_AO_SampleClock,
52 0, /* Termination */
53 }
54 },
55 {
56 .dest = NI_PFI(6),
57 .src = (int[]){
58 NI_AO_StartTrigger,
59 0, /* Termination */
60 }
61 },
62 {
63 .dest = NI_PFI(8),
64 .src = (int[]){
65 NI_CtrSource(0),
66 0, /* Termination */
67 }
68 },
69 {
70 .dest = NI_PFI(9),
71 .src = (int[]){
72 NI_CtrGate(0),
73 0, /* Termination */
74 }
75 },
76 {
77 .dest = TRIGGER_LINE(0),
78 .src = (int[]){
79 NI_CtrSource(0),
80 NI_CtrGate(0),
81 NI_CtrInternalOutput(0),
82 NI_CtrOut(0),
83 NI_AO_SampleClock,
84 NI_AO_StartTrigger,
85 0, /* Termination */
86 }
87 },
88 {
89 .dest = TRIGGER_LINE(1),
90 .src = (int[]){
91 NI_CtrSource(0),
92 NI_CtrGate(0),
93 NI_CtrInternalOutput(0),
94 NI_CtrOut(0),
95 NI_AO_SampleClock,
96 NI_AO_StartTrigger,
97 0, /* Termination */
98 }
99 },
100 {
101 .dest = TRIGGER_LINE(2),
102 .src = (int[]){
103 NI_CtrSource(0),
104 NI_CtrGate(0),
105 NI_CtrInternalOutput(0),
106 NI_CtrOut(0),
107 NI_AO_SampleClock,
108 NI_AO_StartTrigger,
109 0, /* Termination */
110 }
111 },
112 {
113 .dest = TRIGGER_LINE(3),
114 .src = (int[]){
115 NI_CtrSource(0),
116 NI_CtrGate(0),
117 NI_CtrInternalOutput(0),
118 NI_CtrOut(0),
119 NI_AO_SampleClock,
120 NI_AO_StartTrigger,
121 0, /* Termination */
122 }
123 },
124 {
125 .dest = TRIGGER_LINE(4),
126 .src = (int[]){
127 NI_CtrSource(0),
128 NI_CtrGate(0),
129 NI_CtrInternalOutput(0),
130 NI_CtrOut(0),
131 NI_AO_SampleClock,
132 NI_AO_StartTrigger,
133 0, /* Termination */
134 }
135 },
136 {
137 .dest = TRIGGER_LINE(5),
138 .src = (int[]){
139 NI_CtrSource(0),
140 NI_CtrGate(0),
141 NI_CtrInternalOutput(0),
142 NI_CtrOut(0),
143 NI_AO_SampleClock,
144 NI_AO_StartTrigger,
145 0, /* Termination */
146 }
147 },
148 {
149 .dest = TRIGGER_LINE(6),
150 .src = (int[]){
151 NI_CtrSource(0),
152 NI_CtrGate(0),
153 NI_CtrInternalOutput(0),
154 NI_CtrOut(0),
155 NI_AO_SampleClock,
156 NI_AO_StartTrigger,
157 0, /* Termination */
158 }
159 },
160 {
161 .dest = TRIGGER_LINE(7),
162 .src = (int[]){
163 NI_20MHzTimebase,
164 0, /* Termination */
165 }
166 },
167 {
168 .dest = NI_CtrSource(0),
169 .src = (int[]){
170 NI_PFI(0),
171 NI_PFI(1),
172 NI_PFI(2),
173 NI_PFI(3),
174 NI_PFI(4),
175 NI_PFI(5),
176 NI_PFI(6),
177 NI_PFI(7),
178 NI_PFI(8),
179 NI_PFI(9),
180 TRIGGER_LINE(0),
181 TRIGGER_LINE(1),
182 TRIGGER_LINE(2),
183 TRIGGER_LINE(3),
184 TRIGGER_LINE(4),
185 TRIGGER_LINE(5),
186 TRIGGER_LINE(6),
187 TRIGGER_LINE(7),
188 NI_MasterTimebase,
189 NI_20MHzTimebase,
190 NI_100kHzTimebase,
191 0, /* Termination */
192 }
193 },
194 {
195 .dest = NI_CtrSource(1),
196 .src = (int[]){
197 NI_PFI(0),
198 NI_PFI(1),
199 NI_PFI(2),
200 NI_PFI(3),
201 NI_PFI(4),
202 NI_PFI(5),
203 NI_PFI(6),
204 NI_PFI(7),
205 NI_PFI(8),
206 NI_PFI(9),
207 TRIGGER_LINE(0),
208 TRIGGER_LINE(1),
209 TRIGGER_LINE(2),
210 TRIGGER_LINE(3),
211 TRIGGER_LINE(4),
212 TRIGGER_LINE(5),
213 TRIGGER_LINE(6),
214 TRIGGER_LINE(7),
215 NI_MasterTimebase,
216 NI_20MHzTimebase,
217 NI_100kHzTimebase,
218 0, /* Termination */
219 }
220 },
221 {
222 .dest = NI_CtrGate(0),
223 .src = (int[]){
224 NI_PFI(0),
225 NI_PFI(1),
226 NI_PFI(2),
227 NI_PFI(3),
228 NI_PFI(4),
229 NI_PFI(5),
230 NI_PFI(6),
231 NI_PFI(7),
232 NI_PFI(8),
233 NI_PFI(9),
234 TRIGGER_LINE(0),
235 TRIGGER_LINE(1),
236 TRIGGER_LINE(2),
237 TRIGGER_LINE(3),
238 TRIGGER_LINE(4),
239 TRIGGER_LINE(5),
240 TRIGGER_LINE(6),
241 NI_CtrInternalOutput(1),
242 0, /* Termination */
243 }
244 },
245 {
246 .dest = NI_CtrGate(1),
247 .src = (int[]){
248 NI_PFI(0),
249 NI_PFI(1),
250 NI_PFI(2),
251 NI_PFI(3),
252 NI_PFI(4),
253 NI_PFI(5),
254 NI_PFI(6),
255 NI_PFI(7),
256 NI_PFI(8),
257 NI_PFI(9),
258 TRIGGER_LINE(0),
259 TRIGGER_LINE(1),
260 TRIGGER_LINE(2),
261 TRIGGER_LINE(3),
262 TRIGGER_LINE(4),
263 TRIGGER_LINE(5),
264 TRIGGER_LINE(6),
265 NI_CtrInternalOutput(0),
266 0, /* Termination */
267 }
268 },
269 {
270 .dest = NI_CtrOut(0),
271 .src = (int[]){
272 TRIGGER_LINE(0),
273 TRIGGER_LINE(1),
274 TRIGGER_LINE(2),
275 TRIGGER_LINE(3),
276 TRIGGER_LINE(4),
277 TRIGGER_LINE(5),
278 TRIGGER_LINE(6),
279 NI_CtrInternalOutput(0),
280 0, /* Termination */
281 }
282 },
283 {
284 .dest = NI_CtrOut(1),
285 .src = (int[]){
286 NI_CtrInternalOutput(1),
287 0, /* Termination */
288 }
289 },
290 {
291 .dest = NI_AO_SampleClock,
292 .src = (int[]){
293 NI_PFI(0),
294 NI_PFI(1),
295 NI_PFI(2),
296 NI_PFI(3),
297 NI_PFI(4),
298 NI_PFI(5),
299 NI_PFI(6),
300 NI_PFI(7),
301 NI_PFI(8),
302 NI_PFI(9),
303 TRIGGER_LINE(0),
304 TRIGGER_LINE(1),
305 TRIGGER_LINE(2),
306 TRIGGER_LINE(3),
307 TRIGGER_LINE(4),
308 TRIGGER_LINE(5),
309 TRIGGER_LINE(6),
310 NI_CtrInternalOutput(1),
311 NI_AO_SampleClockTimebase,
312 0, /* Termination */
313 }
314 },
315 {
316 .dest = NI_AO_SampleClockTimebase,
317 .src = (int[]){
318 NI_PFI(0),
319 NI_PFI(1),
320 NI_PFI(2),
321 NI_PFI(3),
322 NI_PFI(4),
323 NI_PFI(5),
324 NI_PFI(6),
325 NI_PFI(7),
326 NI_PFI(8),
327 NI_PFI(9),
328 TRIGGER_LINE(0),
329 TRIGGER_LINE(1),
330 TRIGGER_LINE(2),
331 TRIGGER_LINE(3),
332 TRIGGER_LINE(4),
333 TRIGGER_LINE(5),
334 TRIGGER_LINE(6),
335 TRIGGER_LINE(7),
336 NI_MasterTimebase,
337 NI_20MHzTimebase,
338 NI_100kHzTimebase,
339 0, /* Termination */
340 }
341 },
342 {
343 .dest = NI_AO_StartTrigger,
344 .src = (int[]){
345 NI_PFI(0),
346 NI_PFI(1),
347 NI_PFI(2),
348 NI_PFI(3),
349 NI_PFI(4),
350 NI_PFI(5),
351 NI_PFI(6),
352 NI_PFI(7),
353 NI_PFI(8),
354 NI_PFI(9),
355 TRIGGER_LINE(0),
356 TRIGGER_LINE(1),
357 TRIGGER_LINE(2),
358 TRIGGER_LINE(3),
359 TRIGGER_LINE(4),
360 TRIGGER_LINE(5),
361 TRIGGER_LINE(6),
362 0, /* Termination */
363 }
364 },
365 {
366 .dest = NI_AO_PauseTrigger,
367 .src = (int[]){
368 NI_PFI(0),
369 NI_PFI(1),
370 NI_PFI(2),
371 NI_PFI(3),
372 NI_PFI(4),
373 NI_PFI(5),
374 NI_PFI(6),
375 NI_PFI(7),
376 NI_PFI(8),
377 NI_PFI(9),
378 TRIGGER_LINE(0),
379 TRIGGER_LINE(1),
380 TRIGGER_LINE(2),
381 TRIGGER_LINE(3),
382 TRIGGER_LINE(4),
383 TRIGGER_LINE(5),
384 TRIGGER_LINE(6),
385 0, /* Termination */
386 }
387 },
388 {
389 .dest = NI_MasterTimebase,
390 .src = (int[]){
391 TRIGGER_LINE(7),
392 NI_20MHzTimebase,
393 0, /* Termination */
394 }
395 },
396 { /* Termination of list */
397 .dest = 0,
398 },
399 },
400};
diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6733.c b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6733.c
new file mode 100644
index 000000000000..f6e1e17ab854
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6733.c
@@ -0,0 +1,428 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routing/ni_device_routes/pci-6733.c
5 * List of valid routes for specific NI boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21/*
22 * The contents of this file are generated using the tools in
23 * comedi/drivers/ni_routing/tools
24 *
25 * Please use those tools to help maintain the contents of this file.
26 */
27
28#include "../ni_device_routes.h"
29#include "all.h"
30
31struct ni_device_routes ni_pci_6733_device_routes = {
32 .device = "pci-6733",
33 .routes = (struct ni_route_set[]){
34 {
35 .dest = NI_PFI(3),
36 .src = (int[]){
37 NI_CtrSource(1),
38 0, /* Termination */
39 }
40 },
41 {
42 .dest = NI_PFI(4),
43 .src = (int[]){
44 NI_CtrGate(1),
45 0, /* Termination */
46 }
47 },
48 {
49 .dest = NI_PFI(5),
50 .src = (int[]){
51 NI_AO_SampleClock,
52 0, /* Termination */
53 }
54 },
55 {
56 .dest = NI_PFI(6),
57 .src = (int[]){
58 NI_AO_StartTrigger,
59 0, /* Termination */
60 }
61 },
62 {
63 .dest = NI_PFI(8),
64 .src = (int[]){
65 NI_CtrSource(0),
66 0, /* Termination */
67 }
68 },
69 {
70 .dest = NI_PFI(9),
71 .src = (int[]){
72 NI_CtrGate(0),
73 0, /* Termination */
74 }
75 },
76 {
77 .dest = TRIGGER_LINE(0),
78 .src = (int[]){
79 NI_CtrSource(0),
80 NI_CtrGate(0),
81 NI_CtrInternalOutput(0),
82 NI_CtrOut(0),
83 NI_AO_SampleClock,
84 NI_AO_StartTrigger,
85 0, /* Termination */
86 }
87 },
88 {
89 .dest = TRIGGER_LINE(1),
90 .src = (int[]){
91 NI_CtrSource(0),
92 NI_CtrGate(0),
93 NI_CtrInternalOutput(0),
94 NI_CtrOut(0),
95 NI_AO_SampleClock,
96 NI_AO_StartTrigger,
97 0, /* Termination */
98 }
99 },
100 {
101 .dest = TRIGGER_LINE(2),
102 .src = (int[]){
103 NI_CtrSource(0),
104 NI_CtrGate(0),
105 NI_CtrInternalOutput(0),
106 NI_CtrOut(0),
107 NI_AO_SampleClock,
108 NI_AO_StartTrigger,
109 0, /* Termination */
110 }
111 },
112 {
113 .dest = TRIGGER_LINE(3),
114 .src = (int[]){
115 NI_CtrSource(0),
116 NI_CtrGate(0),
117 NI_CtrInternalOutput(0),
118 NI_CtrOut(0),
119 NI_AO_SampleClock,
120 NI_AO_StartTrigger,
121 0, /* Termination */
122 }
123 },
124 {
125 .dest = TRIGGER_LINE(4),
126 .src = (int[]){
127 NI_CtrSource(0),
128 NI_CtrGate(0),
129 NI_CtrInternalOutput(0),
130 NI_CtrOut(0),
131 NI_AO_SampleClock,
132 NI_AO_StartTrigger,
133 0, /* Termination */
134 }
135 },
136 {
137 .dest = TRIGGER_LINE(5),
138 .src = (int[]){
139 NI_CtrSource(0),
140 NI_CtrGate(0),
141 NI_CtrInternalOutput(0),
142 NI_CtrOut(0),
143 NI_AO_SampleClock,
144 NI_AO_StartTrigger,
145 0, /* Termination */
146 }
147 },
148 {
149 .dest = TRIGGER_LINE(6),
150 .src = (int[]){
151 NI_CtrSource(0),
152 NI_CtrGate(0),
153 NI_CtrInternalOutput(0),
154 NI_CtrOut(0),
155 NI_AO_SampleClock,
156 NI_AO_StartTrigger,
157 0, /* Termination */
158 }
159 },
160 {
161 .dest = TRIGGER_LINE(7),
162 .src = (int[]){
163 NI_20MHzTimebase,
164 0, /* Termination */
165 }
166 },
167 {
168 .dest = NI_CtrSource(0),
169 .src = (int[]){
170 NI_PFI(0),
171 NI_PFI(1),
172 NI_PFI(2),
173 NI_PFI(3),
174 NI_PFI(4),
175 NI_PFI(5),
176 NI_PFI(6),
177 NI_PFI(7),
178 NI_PFI(8),
179 NI_PFI(9),
180 TRIGGER_LINE(0),
181 TRIGGER_LINE(1),
182 TRIGGER_LINE(2),
183 TRIGGER_LINE(3),
184 TRIGGER_LINE(4),
185 TRIGGER_LINE(5),
186 TRIGGER_LINE(6),
187 TRIGGER_LINE(7),
188 NI_MasterTimebase,
189 NI_20MHzTimebase,
190 NI_100kHzTimebase,
191 0, /* Termination */
192 }
193 },
194 {
195 .dest = NI_CtrSource(1),
196 .src = (int[]){
197 NI_PFI(0),
198 NI_PFI(1),
199 NI_PFI(2),
200 NI_PFI(3),
201 NI_PFI(4),
202 NI_PFI(5),
203 NI_PFI(6),
204 NI_PFI(7),
205 NI_PFI(8),
206 NI_PFI(9),
207 TRIGGER_LINE(0),
208 TRIGGER_LINE(1),
209 TRIGGER_LINE(2),
210 TRIGGER_LINE(3),
211 TRIGGER_LINE(4),
212 TRIGGER_LINE(5),
213 TRIGGER_LINE(6),
214 TRIGGER_LINE(7),
215 NI_MasterTimebase,
216 NI_20MHzTimebase,
217 NI_100kHzTimebase,
218 0, /* Termination */
219 }
220 },
221 {
222 .dest = NI_CtrGate(0),
223 .src = (int[]){
224 NI_PFI(0),
225 NI_PFI(1),
226 NI_PFI(2),
227 NI_PFI(3),
228 NI_PFI(4),
229 NI_PFI(5),
230 NI_PFI(6),
231 NI_PFI(7),
232 NI_PFI(8),
233 NI_PFI(9),
234 TRIGGER_LINE(0),
235 TRIGGER_LINE(1),
236 TRIGGER_LINE(2),
237 TRIGGER_LINE(3),
238 TRIGGER_LINE(4),
239 TRIGGER_LINE(5),
240 TRIGGER_LINE(6),
241 NI_CtrInternalOutput(1),
242 0, /* Termination */
243 }
244 },
245 {
246 .dest = NI_CtrGate(1),
247 .src = (int[]){
248 NI_PFI(0),
249 NI_PFI(1),
250 NI_PFI(2),
251 NI_PFI(3),
252 NI_PFI(4),
253 NI_PFI(5),
254 NI_PFI(6),
255 NI_PFI(7),
256 NI_PFI(8),
257 NI_PFI(9),
258 TRIGGER_LINE(0),
259 TRIGGER_LINE(1),
260 TRIGGER_LINE(2),
261 TRIGGER_LINE(3),
262 TRIGGER_LINE(4),
263 TRIGGER_LINE(5),
264 TRIGGER_LINE(6),
265 NI_CtrInternalOutput(0),
266 0, /* Termination */
267 }
268 },
269 {
270 .dest = NI_CtrOut(0),
271 .src = (int[]){
272 TRIGGER_LINE(0),
273 TRIGGER_LINE(1),
274 TRIGGER_LINE(2),
275 TRIGGER_LINE(3),
276 TRIGGER_LINE(4),
277 TRIGGER_LINE(5),
278 TRIGGER_LINE(6),
279 NI_CtrInternalOutput(0),
280 0, /* Termination */
281 }
282 },
283 {
284 .dest = NI_CtrOut(1),
285 .src = (int[]){
286 NI_CtrInternalOutput(1),
287 0, /* Termination */
288 }
289 },
290 {
291 .dest = NI_AO_SampleClock,
292 .src = (int[]){
293 NI_PFI(0),
294 NI_PFI(1),
295 NI_PFI(2),
296 NI_PFI(3),
297 NI_PFI(4),
298 NI_PFI(5),
299 NI_PFI(6),
300 NI_PFI(7),
301 NI_PFI(8),
302 NI_PFI(9),
303 TRIGGER_LINE(0),
304 TRIGGER_LINE(1),
305 TRIGGER_LINE(2),
306 TRIGGER_LINE(3),
307 TRIGGER_LINE(4),
308 TRIGGER_LINE(5),
309 TRIGGER_LINE(6),
310 NI_CtrInternalOutput(1),
311 NI_AO_SampleClockTimebase,
312 0, /* Termination */
313 }
314 },
315 {
316 .dest = NI_AO_SampleClockTimebase,
317 .src = (int[]){
318 NI_PFI(0),
319 NI_PFI(1),
320 NI_PFI(2),
321 NI_PFI(3),
322 NI_PFI(4),
323 NI_PFI(5),
324 NI_PFI(6),
325 NI_PFI(7),
326 NI_PFI(8),
327 NI_PFI(9),
328 TRIGGER_LINE(0),
329 TRIGGER_LINE(1),
330 TRIGGER_LINE(2),
331 TRIGGER_LINE(3),
332 TRIGGER_LINE(4),
333 TRIGGER_LINE(5),
334 TRIGGER_LINE(6),
335 TRIGGER_LINE(7),
336 NI_MasterTimebase,
337 NI_20MHzTimebase,
338 NI_100kHzTimebase,
339 0, /* Termination */
340 }
341 },
342 {
343 .dest = NI_AO_StartTrigger,
344 .src = (int[]){
345 NI_PFI(0),
346 NI_PFI(1),
347 NI_PFI(2),
348 NI_PFI(3),
349 NI_PFI(4),
350 NI_PFI(5),
351 NI_PFI(6),
352 NI_PFI(7),
353 NI_PFI(8),
354 NI_PFI(9),
355 TRIGGER_LINE(0),
356 TRIGGER_LINE(1),
357 TRIGGER_LINE(2),
358 TRIGGER_LINE(3),
359 TRIGGER_LINE(4),
360 TRIGGER_LINE(5),
361 TRIGGER_LINE(6),
362 0, /* Termination */
363 }
364 },
365 {
366 .dest = NI_AO_PauseTrigger,
367 .src = (int[]){
368 NI_PFI(0),
369 NI_PFI(1),
370 NI_PFI(2),
371 NI_PFI(3),
372 NI_PFI(4),
373 NI_PFI(5),
374 NI_PFI(6),
375 NI_PFI(7),
376 NI_PFI(8),
377 NI_PFI(9),
378 TRIGGER_LINE(0),
379 TRIGGER_LINE(1),
380 TRIGGER_LINE(2),
381 TRIGGER_LINE(3),
382 TRIGGER_LINE(4),
383 TRIGGER_LINE(5),
384 TRIGGER_LINE(6),
385 0, /* Termination */
386 }
387 },
388 {
389 .dest = NI_DI_SampleClock,
390 .src = (int[]){
391 TRIGGER_LINE(0),
392 TRIGGER_LINE(1),
393 TRIGGER_LINE(2),
394 TRIGGER_LINE(3),
395 TRIGGER_LINE(4),
396 TRIGGER_LINE(5),
397 TRIGGER_LINE(6),
398 NI_AO_SampleClock,
399 0, /* Termination */
400 }
401 },
402 {
403 .dest = NI_DO_SampleClock,
404 .src = (int[]){
405 TRIGGER_LINE(0),
406 TRIGGER_LINE(1),
407 TRIGGER_LINE(2),
408 TRIGGER_LINE(3),
409 TRIGGER_LINE(4),
410 TRIGGER_LINE(5),
411 TRIGGER_LINE(6),
412 NI_AO_SampleClock,
413 0, /* Termination */
414 }
415 },
416 {
417 .dest = NI_MasterTimebase,
418 .src = (int[]){
419 TRIGGER_LINE(7),
420 NI_20MHzTimebase,
421 0, /* Termination */
422 }
423 },
424 { /* Termination of list */
425 .dest = 0,
426 },
427 },
428};
diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxi-6030e.c b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxi-6030e.c
new file mode 100644
index 000000000000..9978d632117f
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxi-6030e.c
@@ -0,0 +1,608 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routing/ni_device_routes/pxi-6030e.c
5 * List of valid routes for specific NI boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21/*
22 * The contents of this file are generated using the tools in
23 * comedi/drivers/ni_routing/tools
24 *
25 * Please use those tools to help maintain the contents of this file.
26 */
27
28#include "../ni_device_routes.h"
29#include "all.h"
30
31struct ni_device_routes ni_pxi_6030e_device_routes = {
32 .device = "pxi-6030e",
33 .routes = (struct ni_route_set[]){
34 {
35 .dest = NI_PFI(0),
36 .src = (int[]){
37 NI_AI_StartTrigger,
38 0, /* Termination */
39 }
40 },
41 {
42 .dest = NI_PFI(1),
43 .src = (int[]){
44 NI_AI_ReferenceTrigger,
45 0, /* Termination */
46 }
47 },
48 {
49 .dest = NI_PFI(2),
50 .src = (int[]){
51 NI_AI_ConvertClock,
52 0, /* Termination */
53 }
54 },
55 {
56 .dest = NI_PFI(3),
57 .src = (int[]){
58 NI_CtrSource(1),
59 0, /* Termination */
60 }
61 },
62 {
63 .dest = NI_PFI(4),
64 .src = (int[]){
65 NI_CtrGate(1),
66 0, /* Termination */
67 }
68 },
69 {
70 .dest = NI_PFI(5),
71 .src = (int[]){
72 NI_AO_SampleClock,
73 0, /* Termination */
74 }
75 },
76 {
77 .dest = NI_PFI(6),
78 .src = (int[]){
79 NI_AO_StartTrigger,
80 0, /* Termination */
81 }
82 },
83 {
84 .dest = NI_PFI(7),
85 .src = (int[]){
86 NI_AI_SampleClock,
87 0, /* Termination */
88 }
89 },
90 {
91 .dest = NI_PFI(8),
92 .src = (int[]){
93 NI_CtrSource(0),
94 0, /* Termination */
95 }
96 },
97 {
98 .dest = NI_PFI(9),
99 .src = (int[]){
100 NI_CtrGate(0),
101 0, /* Termination */
102 }
103 },
104 {
105 .dest = TRIGGER_LINE(0),
106 .src = (int[]){
107 NI_CtrSource(0),
108 NI_CtrGate(0),
109 NI_CtrInternalOutput(0),
110 NI_CtrOut(0),
111 NI_AI_SampleClock,
112 NI_AI_StartTrigger,
113 NI_AI_ReferenceTrigger,
114 NI_AI_ConvertClock,
115 NI_AO_SampleClock,
116 NI_AO_StartTrigger,
117 0, /* Termination */
118 }
119 },
120 {
121 .dest = TRIGGER_LINE(1),
122 .src = (int[]){
123 NI_CtrSource(0),
124 NI_CtrGate(0),
125 NI_CtrInternalOutput(0),
126 NI_CtrOut(0),
127 NI_AI_SampleClock,
128 NI_AI_StartTrigger,
129 NI_AI_ReferenceTrigger,
130 NI_AI_ConvertClock,
131 NI_AO_SampleClock,
132 NI_AO_StartTrigger,
133 0, /* Termination */
134 }
135 },
136 {
137 .dest = TRIGGER_LINE(2),
138 .src = (int[]){
139 NI_CtrSource(0),
140 NI_CtrGate(0),
141 NI_CtrInternalOutput(0),
142 NI_CtrOut(0),
143 NI_AI_SampleClock,
144 NI_AI_StartTrigger,
145 NI_AI_ReferenceTrigger,
146 NI_AI_ConvertClock,
147 NI_AO_SampleClock,
148 NI_AO_StartTrigger,
149 0, /* Termination */
150 }
151 },
152 {
153 .dest = TRIGGER_LINE(3),
154 .src = (int[]){
155 NI_CtrSource(0),
156 NI_CtrGate(0),
157 NI_CtrInternalOutput(0),
158 NI_CtrOut(0),
159 NI_AI_SampleClock,
160 NI_AI_StartTrigger,
161 NI_AI_ReferenceTrigger,
162 NI_AI_ConvertClock,
163 NI_AO_SampleClock,
164 NI_AO_StartTrigger,
165 0, /* Termination */
166 }
167 },
168 {
169 .dest = TRIGGER_LINE(4),
170 .src = (int[]){
171 NI_CtrSource(0),
172 NI_CtrGate(0),
173 NI_CtrInternalOutput(0),
174 NI_CtrOut(0),
175 NI_AI_SampleClock,
176 NI_AI_StartTrigger,
177 NI_AI_ReferenceTrigger,
178 NI_AI_ConvertClock,
179 NI_AO_SampleClock,
180 NI_AO_StartTrigger,
181 0, /* Termination */
182 }
183 },
184 {
185 .dest = TRIGGER_LINE(5),
186 .src = (int[]){
187 NI_CtrSource(0),
188 NI_CtrGate(0),
189 NI_CtrInternalOutput(0),
190 NI_CtrOut(0),
191 NI_AI_SampleClock,
192 NI_AI_StartTrigger,
193 NI_AI_ReferenceTrigger,
194 NI_AI_ConvertClock,
195 NI_AO_SampleClock,
196 NI_AO_StartTrigger,
197 0, /* Termination */
198 }
199 },
200 {
201 .dest = TRIGGER_LINE(7),
202 .src = (int[]){
203 NI_20MHzTimebase,
204 0, /* Termination */
205 }
206 },
207 {
208 .dest = NI_CtrSource(0),
209 .src = (int[]){
210 NI_PFI(0),
211 NI_PFI(1),
212 NI_PFI(2),
213 NI_PFI(3),
214 NI_PFI(4),
215 NI_PFI(5),
216 NI_PFI(6),
217 NI_PFI(7),
218 NI_PFI(8),
219 NI_PFI(9),
220 TRIGGER_LINE(0),
221 TRIGGER_LINE(1),
222 TRIGGER_LINE(2),
223 TRIGGER_LINE(3),
224 TRIGGER_LINE(4),
225 TRIGGER_LINE(5),
226 TRIGGER_LINE(7),
227 NI_MasterTimebase,
228 NI_20MHzTimebase,
229 NI_100kHzTimebase,
230 NI_AnalogComparisonEvent,
231 0, /* Termination */
232 }
233 },
234 {
235 .dest = NI_CtrSource(1),
236 .src = (int[]){
237 NI_PFI(0),
238 NI_PFI(1),
239 NI_PFI(2),
240 NI_PFI(3),
241 NI_PFI(4),
242 NI_PFI(5),
243 NI_PFI(6),
244 NI_PFI(7),
245 NI_PFI(8),
246 NI_PFI(9),
247 TRIGGER_LINE(0),
248 TRIGGER_LINE(1),
249 TRIGGER_LINE(2),
250 TRIGGER_LINE(3),
251 TRIGGER_LINE(4),
252 TRIGGER_LINE(5),
253 TRIGGER_LINE(7),
254 NI_MasterTimebase,
255 NI_20MHzTimebase,
256 NI_100kHzTimebase,
257 NI_AnalogComparisonEvent,
258 0, /* Termination */
259 }
260 },
261 {
262 .dest = NI_CtrGate(0),
263 .src = (int[]){
264 NI_PFI(0),
265 NI_PFI(1),
266 NI_PFI(2),
267 NI_PFI(3),
268 NI_PFI(4),
269 NI_PFI(5),
270 NI_PFI(6),
271 NI_PFI(7),
272 NI_PFI(8),
273 NI_PFI(9),
274 TRIGGER_LINE(0),
275 TRIGGER_LINE(1),
276 TRIGGER_LINE(2),
277 TRIGGER_LINE(3),
278 TRIGGER_LINE(4),
279 TRIGGER_LINE(5),
280 NI_CtrInternalOutput(1),
281 NI_AI_StartTrigger,
282 NI_AI_ReferenceTrigger,
283 NI_AnalogComparisonEvent,
284 0, /* Termination */
285 }
286 },
287 {
288 .dest = NI_CtrGate(1),
289 .src = (int[]){
290 NI_PFI(0),
291 NI_PFI(1),
292 NI_PFI(2),
293 NI_PFI(3),
294 NI_PFI(4),
295 NI_PFI(5),
296 NI_PFI(6),
297 NI_PFI(7),
298 NI_PFI(8),
299 NI_PFI(9),
300 TRIGGER_LINE(0),
301 TRIGGER_LINE(1),
302 TRIGGER_LINE(2),
303 TRIGGER_LINE(3),
304 TRIGGER_LINE(4),
305 TRIGGER_LINE(5),
306 NI_CtrInternalOutput(0),
307 NI_AI_StartTrigger,
308 NI_AI_ReferenceTrigger,
309 NI_AnalogComparisonEvent,
310 0, /* Termination */
311 }
312 },
313 {
314 .dest = NI_CtrOut(0),
315 .src = (int[]){
316 TRIGGER_LINE(0),
317 TRIGGER_LINE(1),
318 TRIGGER_LINE(2),
319 TRIGGER_LINE(3),
320 TRIGGER_LINE(4),
321 TRIGGER_LINE(5),
322 NI_CtrInternalOutput(0),
323 0, /* Termination */
324 }
325 },
326 {
327 .dest = NI_CtrOut(1),
328 .src = (int[]){
329 NI_CtrInternalOutput(1),
330 0, /* Termination */
331 }
332 },
333 {
334 .dest = NI_AI_SampleClock,
335 .src = (int[]){
336 NI_PFI(0),
337 NI_PFI(1),
338 NI_PFI(2),
339 NI_PFI(3),
340 NI_PFI(4),
341 NI_PFI(5),
342 NI_PFI(6),
343 NI_PFI(7),
344 NI_PFI(8),
345 NI_PFI(9),
346 TRIGGER_LINE(0),
347 TRIGGER_LINE(1),
348 TRIGGER_LINE(2),
349 TRIGGER_LINE(3),
350 TRIGGER_LINE(4),
351 TRIGGER_LINE(5),
352 NI_CtrInternalOutput(0),
353 NI_AI_SampleClockTimebase,
354 NI_AnalogComparisonEvent,
355 0, /* Termination */
356 }
357 },
358 {
359 .dest = NI_AI_SampleClockTimebase,
360 .src = (int[]){
361 NI_PFI(0),
362 NI_PFI(1),
363 NI_PFI(2),
364 NI_PFI(3),
365 NI_PFI(4),
366 NI_PFI(5),
367 NI_PFI(6),
368 NI_PFI(7),
369 NI_PFI(8),
370 NI_PFI(9),
371 TRIGGER_LINE(0),
372 TRIGGER_LINE(1),
373 TRIGGER_LINE(2),
374 TRIGGER_LINE(3),
375 TRIGGER_LINE(4),
376 TRIGGER_LINE(5),
377 TRIGGER_LINE(7),
378 NI_MasterTimebase,
379 NI_20MHzTimebase,
380 NI_100kHzTimebase,
381 NI_AnalogComparisonEvent,
382 0, /* Termination */
383 }
384 },
385 {
386 .dest = NI_AI_StartTrigger,
387 .src = (int[]){
388 NI_PFI(0),
389 NI_PFI(1),
390 NI_PFI(2),
391 NI_PFI(3),
392 NI_PFI(4),
393 NI_PFI(5),
394 NI_PFI(6),
395 NI_PFI(7),
396 NI_PFI(8),
397 NI_PFI(9),
398 TRIGGER_LINE(0),
399 TRIGGER_LINE(1),
400 TRIGGER_LINE(2),
401 TRIGGER_LINE(3),
402 TRIGGER_LINE(4),
403 TRIGGER_LINE(5),
404 NI_CtrInternalOutput(0),
405 NI_AnalogComparisonEvent,
406 0, /* Termination */
407 }
408 },
409 {
410 .dest = NI_AI_ReferenceTrigger,
411 .src = (int[]){
412 NI_PFI(0),
413 NI_PFI(1),
414 NI_PFI(2),
415 NI_PFI(3),
416 NI_PFI(4),
417 NI_PFI(5),
418 NI_PFI(6),
419 NI_PFI(7),
420 NI_PFI(8),
421 NI_PFI(9),
422 TRIGGER_LINE(0),
423 TRIGGER_LINE(1),
424 TRIGGER_LINE(2),
425 TRIGGER_LINE(3),
426 TRIGGER_LINE(4),
427 TRIGGER_LINE(5),
428 NI_AnalogComparisonEvent,
429 0, /* Termination */
430 }
431 },
432 {
433 .dest = NI_AI_ConvertClock,
434 .src = (int[]){
435 NI_PFI(0),
436 NI_PFI(1),
437 NI_PFI(2),
438 NI_PFI(3),
439 NI_PFI(4),
440 NI_PFI(5),
441 NI_PFI(6),
442 NI_PFI(7),
443 NI_PFI(8),
444 NI_PFI(9),
445 TRIGGER_LINE(0),
446 TRIGGER_LINE(1),
447 TRIGGER_LINE(2),
448 TRIGGER_LINE(3),
449 TRIGGER_LINE(4),
450 TRIGGER_LINE(5),
451 NI_CtrInternalOutput(0),
452 NI_AI_ConvertClockTimebase,
453 NI_AnalogComparisonEvent,
454 0, /* Termination */
455 }
456 },
457 {
458 .dest = NI_AI_ConvertClockTimebase,
459 .src = (int[]){
460 TRIGGER_LINE(7),
461 NI_AI_SampleClockTimebase,
462 NI_MasterTimebase,
463 NI_20MHzTimebase,
464 0, /* Termination */
465 }
466 },
467 {
468 .dest = NI_AI_PauseTrigger,
469 .src = (int[]){
470 NI_PFI(0),
471 NI_PFI(1),
472 NI_PFI(2),
473 NI_PFI(3),
474 NI_PFI(4),
475 NI_PFI(5),
476 NI_PFI(6),
477 NI_PFI(7),
478 NI_PFI(8),
479 NI_PFI(9),
480 TRIGGER_LINE(0),
481 TRIGGER_LINE(1),
482 TRIGGER_LINE(2),
483 TRIGGER_LINE(3),
484 TRIGGER_LINE(4),
485 TRIGGER_LINE(5),
486 NI_AnalogComparisonEvent,
487 0, /* Termination */
488 }
489 },
490 {
491 .dest = NI_AI_HoldComplete,
492 .src = (int[]){
493 NI_AI_HoldCompleteEvent,
494 0, /* Termination */
495 }
496 },
497 {
498 .dest = NI_AO_SampleClock,
499 .src = (int[]){
500 NI_PFI(0),
501 NI_PFI(1),
502 NI_PFI(2),
503 NI_PFI(3),
504 NI_PFI(4),
505 NI_PFI(5),
506 NI_PFI(6),
507 NI_PFI(7),
508 NI_PFI(8),
509 NI_PFI(9),
510 TRIGGER_LINE(0),
511 TRIGGER_LINE(1),
512 TRIGGER_LINE(2),
513 TRIGGER_LINE(3),
514 TRIGGER_LINE(4),
515 TRIGGER_LINE(5),
516 NI_CtrInternalOutput(1),
517 NI_AO_SampleClockTimebase,
518 NI_AnalogComparisonEvent,
519 0, /* Termination */
520 }
521 },
522 {
523 .dest = NI_AO_SampleClockTimebase,
524 .src = (int[]){
525 NI_PFI(0),
526 NI_PFI(1),
527 NI_PFI(2),
528 NI_PFI(3),
529 NI_PFI(4),
530 NI_PFI(5),
531 NI_PFI(6),
532 NI_PFI(7),
533 NI_PFI(8),
534 NI_PFI(9),
535 TRIGGER_LINE(0),
536 TRIGGER_LINE(1),
537 TRIGGER_LINE(2),
538 TRIGGER_LINE(3),
539 TRIGGER_LINE(4),
540 TRIGGER_LINE(5),
541 TRIGGER_LINE(7),
542 NI_MasterTimebase,
543 NI_20MHzTimebase,
544 NI_100kHzTimebase,
545 NI_AnalogComparisonEvent,
546 0, /* Termination */
547 }
548 },
549 {
550 .dest = NI_AO_StartTrigger,
551 .src = (int[]){
552 NI_PFI(0),
553 NI_PFI(1),
554 NI_PFI(2),
555 NI_PFI(3),
556 NI_PFI(4),
557 NI_PFI(5),
558 NI_PFI(6),
559 NI_PFI(7),
560 NI_PFI(8),
561 NI_PFI(9),
562 TRIGGER_LINE(0),
563 TRIGGER_LINE(1),
564 TRIGGER_LINE(2),
565 TRIGGER_LINE(3),
566 TRIGGER_LINE(4),
567 TRIGGER_LINE(5),
568 NI_AI_StartTrigger,
569 NI_AnalogComparisonEvent,
570 0, /* Termination */
571 }
572 },
573 {
574 .dest = NI_AO_PauseTrigger,
575 .src = (int[]){
576 NI_PFI(0),
577 NI_PFI(1),
578 NI_PFI(2),
579 NI_PFI(3),
580 NI_PFI(4),
581 NI_PFI(5),
582 NI_PFI(6),
583 NI_PFI(7),
584 NI_PFI(8),
585 NI_PFI(9),
586 TRIGGER_LINE(0),
587 TRIGGER_LINE(1),
588 TRIGGER_LINE(2),
589 TRIGGER_LINE(3),
590 TRIGGER_LINE(4),
591 TRIGGER_LINE(5),
592 NI_AnalogComparisonEvent,
593 0, /* Termination */
594 }
595 },
596 {
597 .dest = NI_MasterTimebase,
598 .src = (int[]){
599 TRIGGER_LINE(7),
600 NI_20MHzTimebase,
601 0, /* Termination */
602 }
603 },
604 { /* Termination of list */
605 .dest = 0,
606 },
607 },
608};
diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxi-6224.c b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxi-6224.c
new file mode 100644
index 000000000000..1b89e27d7aa5
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxi-6224.c
@@ -0,0 +1,1432 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routing/ni_device_routes/pxi-6224.c
5 * List of valid routes for specific NI boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21/*
22 * The contents of this file are generated using the tools in
23 * comedi/drivers/ni_routing/tools
24 *
25 * Please use those tools to help maintain the contents of this file.
26 */
27
28#include "../ni_device_routes.h"
29#include "all.h"
30
31struct ni_device_routes ni_pxi_6224_device_routes = {
32 .device = "pxi-6224",
33 .routes = (struct ni_route_set[]){
34 {
35 .dest = NI_PFI(0),
36 .src = (int[]){
37 TRIGGER_LINE(0),
38 TRIGGER_LINE(1),
39 TRIGGER_LINE(2),
40 TRIGGER_LINE(3),
41 TRIGGER_LINE(4),
42 TRIGGER_LINE(5),
43 TRIGGER_LINE(6),
44 TRIGGER_LINE(7),
45 NI_CtrSource(0),
46 NI_CtrSource(1),
47 NI_CtrGate(0),
48 NI_CtrInternalOutput(0),
49 NI_CtrInternalOutput(1),
50 NI_AI_SampleClock,
51 NI_AI_StartTrigger,
52 NI_AI_ReferenceTrigger,
53 NI_AI_ConvertClock,
54 NI_DI_SampleClock,
55 NI_DO_SampleClock,
56 NI_FrequencyOutput,
57 NI_ChangeDetectionEvent,
58 NI_AnalogComparisonEvent,
59 0, /* Termination */
60 }
61 },
62 {
63 .dest = NI_PFI(1),
64 .src = (int[]){
65 TRIGGER_LINE(0),
66 TRIGGER_LINE(1),
67 TRIGGER_LINE(2),
68 TRIGGER_LINE(3),
69 TRIGGER_LINE(4),
70 TRIGGER_LINE(5),
71 TRIGGER_LINE(6),
72 TRIGGER_LINE(7),
73 NI_CtrSource(0),
74 NI_CtrSource(1),
75 NI_CtrGate(0),
76 NI_CtrInternalOutput(0),
77 NI_CtrInternalOutput(1),
78 NI_AI_SampleClock,
79 NI_AI_StartTrigger,
80 NI_AI_ReferenceTrigger,
81 NI_AI_ConvertClock,
82 NI_DI_SampleClock,
83 NI_DO_SampleClock,
84 NI_FrequencyOutput,
85 NI_ChangeDetectionEvent,
86 NI_AnalogComparisonEvent,
87 0, /* Termination */
88 }
89 },
90 {
91 .dest = NI_PFI(2),
92 .src = (int[]){
93 TRIGGER_LINE(0),
94 TRIGGER_LINE(1),
95 TRIGGER_LINE(2),
96 TRIGGER_LINE(3),
97 TRIGGER_LINE(4),
98 TRIGGER_LINE(5),
99 TRIGGER_LINE(6),
100 TRIGGER_LINE(7),
101 NI_CtrSource(0),
102 NI_CtrSource(1),
103 NI_CtrGate(0),
104 NI_CtrInternalOutput(0),
105 NI_CtrInternalOutput(1),
106 NI_AI_SampleClock,
107 NI_AI_StartTrigger,
108 NI_AI_ReferenceTrigger,
109 NI_AI_ConvertClock,
110 NI_DI_SampleClock,
111 NI_DO_SampleClock,
112 NI_FrequencyOutput,
113 NI_ChangeDetectionEvent,
114 NI_AnalogComparisonEvent,
115 0, /* Termination */
116 }
117 },
118 {
119 .dest = NI_PFI(3),
120 .src = (int[]){
121 TRIGGER_LINE(0),
122 TRIGGER_LINE(1),
123 TRIGGER_LINE(2),
124 TRIGGER_LINE(3),
125 TRIGGER_LINE(4),
126 TRIGGER_LINE(5),
127 TRIGGER_LINE(6),
128 TRIGGER_LINE(7),
129 NI_CtrSource(0),
130 NI_CtrSource(1),
131 NI_CtrGate(0),
132 NI_CtrInternalOutput(0),
133 NI_CtrInternalOutput(1),
134 NI_AI_SampleClock,
135 NI_AI_StartTrigger,
136 NI_AI_ReferenceTrigger,
137 NI_AI_ConvertClock,
138 NI_DI_SampleClock,
139 NI_DO_SampleClock,
140 NI_FrequencyOutput,
141 NI_ChangeDetectionEvent,
142 NI_AnalogComparisonEvent,
143 0, /* Termination */
144 }
145 },
146 {
147 .dest = NI_PFI(4),
148 .src = (int[]){
149 TRIGGER_LINE(0),
150 TRIGGER_LINE(1),
151 TRIGGER_LINE(2),
152 TRIGGER_LINE(3),
153 TRIGGER_LINE(4),
154 TRIGGER_LINE(5),
155 TRIGGER_LINE(6),
156 TRIGGER_LINE(7),
157 NI_CtrSource(0),
158 NI_CtrSource(1),
159 NI_CtrGate(0),
160 NI_CtrInternalOutput(0),
161 NI_CtrInternalOutput(1),
162 NI_AI_SampleClock,
163 NI_AI_StartTrigger,
164 NI_AI_ReferenceTrigger,
165 NI_AI_ConvertClock,
166 NI_DI_SampleClock,
167 NI_DO_SampleClock,
168 NI_FrequencyOutput,
169 NI_ChangeDetectionEvent,
170 NI_AnalogComparisonEvent,
171 0, /* Termination */
172 }
173 },
174 {
175 .dest = NI_PFI(5),
176 .src = (int[]){
177 TRIGGER_LINE(0),
178 TRIGGER_LINE(1),
179 TRIGGER_LINE(2),
180 TRIGGER_LINE(3),
181 TRIGGER_LINE(4),
182 TRIGGER_LINE(5),
183 TRIGGER_LINE(6),
184 TRIGGER_LINE(7),
185 NI_CtrSource(0),
186 NI_CtrSource(1),
187 NI_CtrGate(0),
188 NI_CtrInternalOutput(0),
189 NI_CtrInternalOutput(1),
190 NI_AI_SampleClock,
191 NI_AI_StartTrigger,
192 NI_AI_ReferenceTrigger,
193 NI_AI_ConvertClock,
194 NI_DI_SampleClock,
195 NI_DO_SampleClock,
196 NI_FrequencyOutput,
197 NI_ChangeDetectionEvent,
198 NI_AnalogComparisonEvent,
199 0, /* Termination */
200 }
201 },
202 {
203 .dest = NI_PFI(6),
204 .src = (int[]){
205 TRIGGER_LINE(0),
206 TRIGGER_LINE(1),
207 TRIGGER_LINE(2),
208 TRIGGER_LINE(3),
209 TRIGGER_LINE(4),
210 TRIGGER_LINE(5),
211 TRIGGER_LINE(6),
212 TRIGGER_LINE(7),
213 NI_CtrSource(0),
214 NI_CtrSource(1),
215 NI_CtrGate(0),
216 NI_CtrInternalOutput(0),
217 NI_CtrInternalOutput(1),
218 NI_AI_SampleClock,
219 NI_AI_StartTrigger,
220 NI_AI_ReferenceTrigger,
221 NI_AI_ConvertClock,
222 NI_DI_SampleClock,
223 NI_DO_SampleClock,
224 NI_FrequencyOutput,
225 NI_ChangeDetectionEvent,
226 NI_AnalogComparisonEvent,
227 0, /* Termination */
228 }
229 },
230 {
231 .dest = NI_PFI(7),
232 .src = (int[]){
233 TRIGGER_LINE(0),
234 TRIGGER_LINE(1),
235 TRIGGER_LINE(2),
236 TRIGGER_LINE(3),
237 TRIGGER_LINE(4),
238 TRIGGER_LINE(5),
239 TRIGGER_LINE(6),
240 TRIGGER_LINE(7),
241 NI_CtrSource(0),
242 NI_CtrSource(1),
243 NI_CtrGate(0),
244 NI_CtrInternalOutput(0),
245 NI_CtrInternalOutput(1),
246 NI_AI_SampleClock,
247 NI_AI_StartTrigger,
248 NI_AI_ReferenceTrigger,
249 NI_AI_ConvertClock,
250 NI_DI_SampleClock,
251 NI_DO_SampleClock,
252 NI_FrequencyOutput,
253 NI_ChangeDetectionEvent,
254 NI_AnalogComparisonEvent,
255 0, /* Termination */
256 }
257 },
258 {
259 .dest = NI_PFI(8),
260 .src = (int[]){
261 TRIGGER_LINE(0),
262 TRIGGER_LINE(1),
263 TRIGGER_LINE(2),
264 TRIGGER_LINE(3),
265 TRIGGER_LINE(4),
266 TRIGGER_LINE(5),
267 TRIGGER_LINE(6),
268 TRIGGER_LINE(7),
269 NI_CtrSource(0),
270 NI_CtrSource(1),
271 NI_CtrGate(0),
272 NI_CtrInternalOutput(0),
273 NI_CtrInternalOutput(1),
274 NI_AI_SampleClock,
275 NI_AI_StartTrigger,
276 NI_AI_ReferenceTrigger,
277 NI_AI_ConvertClock,
278 NI_DI_SampleClock,
279 NI_DO_SampleClock,
280 NI_FrequencyOutput,
281 NI_ChangeDetectionEvent,
282 NI_AnalogComparisonEvent,
283 0, /* Termination */
284 }
285 },
286 {
287 .dest = NI_PFI(9),
288 .src = (int[]){
289 TRIGGER_LINE(0),
290 TRIGGER_LINE(1),
291 TRIGGER_LINE(2),
292 TRIGGER_LINE(3),
293 TRIGGER_LINE(4),
294 TRIGGER_LINE(5),
295 TRIGGER_LINE(6),
296 TRIGGER_LINE(7),
297 NI_CtrSource(0),
298 NI_CtrSource(1),
299 NI_CtrGate(0),
300 NI_CtrInternalOutput(0),
301 NI_CtrInternalOutput(1),
302 NI_AI_SampleClock,
303 NI_AI_StartTrigger,
304 NI_AI_ReferenceTrigger,
305 NI_AI_ConvertClock,
306 NI_DI_SampleClock,
307 NI_DO_SampleClock,
308 NI_FrequencyOutput,
309 NI_ChangeDetectionEvent,
310 NI_AnalogComparisonEvent,
311 0, /* Termination */
312 }
313 },
314 {
315 .dest = NI_PFI(10),
316 .src = (int[]){
317 TRIGGER_LINE(0),
318 TRIGGER_LINE(1),
319 TRIGGER_LINE(2),
320 TRIGGER_LINE(3),
321 TRIGGER_LINE(4),
322 TRIGGER_LINE(5),
323 TRIGGER_LINE(6),
324 TRIGGER_LINE(7),
325 NI_CtrSource(0),
326 NI_CtrSource(1),
327 NI_CtrGate(0),
328 NI_CtrInternalOutput(0),
329 NI_CtrInternalOutput(1),
330 NI_AI_SampleClock,
331 NI_AI_StartTrigger,
332 NI_AI_ReferenceTrigger,
333 NI_AI_ConvertClock,
334 NI_DI_SampleClock,
335 NI_DO_SampleClock,
336 NI_FrequencyOutput,
337 NI_ChangeDetectionEvent,
338 NI_AnalogComparisonEvent,
339 0, /* Termination */
340 }
341 },
342 {
343 .dest = NI_PFI(11),
344 .src = (int[]){
345 TRIGGER_LINE(0),
346 TRIGGER_LINE(1),
347 TRIGGER_LINE(2),
348 TRIGGER_LINE(3),
349 TRIGGER_LINE(4),
350 TRIGGER_LINE(5),
351 TRIGGER_LINE(6),
352 TRIGGER_LINE(7),
353 NI_CtrSource(0),
354 NI_CtrSource(1),
355 NI_CtrGate(0),
356 NI_CtrInternalOutput(0),
357 NI_CtrInternalOutput(1),
358 NI_AI_SampleClock,
359 NI_AI_StartTrigger,
360 NI_AI_ReferenceTrigger,
361 NI_AI_ConvertClock,
362 NI_DI_SampleClock,
363 NI_DO_SampleClock,
364 NI_FrequencyOutput,
365 NI_ChangeDetectionEvent,
366 NI_AnalogComparisonEvent,
367 0, /* Termination */
368 }
369 },
370 {
371 .dest = NI_PFI(12),
372 .src = (int[]){
373 TRIGGER_LINE(0),
374 TRIGGER_LINE(1),
375 TRIGGER_LINE(2),
376 TRIGGER_LINE(3),
377 TRIGGER_LINE(4),
378 TRIGGER_LINE(5),
379 TRIGGER_LINE(6),
380 TRIGGER_LINE(7),
381 NI_CtrSource(0),
382 NI_CtrSource(1),
383 NI_CtrGate(0),
384 NI_CtrInternalOutput(0),
385 NI_CtrInternalOutput(1),
386 NI_AI_SampleClock,
387 NI_AI_StartTrigger,
388 NI_AI_ReferenceTrigger,
389 NI_AI_ConvertClock,
390 NI_DI_SampleClock,
391 NI_DO_SampleClock,
392 NI_FrequencyOutput,
393 NI_ChangeDetectionEvent,
394 NI_AnalogComparisonEvent,
395 0, /* Termination */
396 }
397 },
398 {
399 .dest = NI_PFI(13),
400 .src = (int[]){
401 TRIGGER_LINE(0),
402 TRIGGER_LINE(1),
403 TRIGGER_LINE(2),
404 TRIGGER_LINE(3),
405 TRIGGER_LINE(4),
406 TRIGGER_LINE(5),
407 TRIGGER_LINE(6),
408 TRIGGER_LINE(7),
409 NI_CtrSource(0),
410 NI_CtrSource(1),
411 NI_CtrGate(0),
412 NI_CtrInternalOutput(0),
413 NI_CtrInternalOutput(1),
414 NI_AI_SampleClock,
415 NI_AI_StartTrigger,
416 NI_AI_ReferenceTrigger,
417 NI_AI_ConvertClock,
418 NI_DI_SampleClock,
419 NI_DO_SampleClock,
420 NI_FrequencyOutput,
421 NI_ChangeDetectionEvent,
422 NI_AnalogComparisonEvent,
423 0, /* Termination */
424 }
425 },
426 {
427 .dest = NI_PFI(14),
428 .src = (int[]){
429 TRIGGER_LINE(0),
430 TRIGGER_LINE(1),
431 TRIGGER_LINE(2),
432 TRIGGER_LINE(3),
433 TRIGGER_LINE(4),
434 TRIGGER_LINE(5),
435 TRIGGER_LINE(6),
436 TRIGGER_LINE(7),
437 NI_CtrSource(0),
438 NI_CtrSource(1),
439 NI_CtrGate(0),
440 NI_CtrInternalOutput(0),
441 NI_CtrInternalOutput(1),
442 NI_AI_SampleClock,
443 NI_AI_StartTrigger,
444 NI_AI_ReferenceTrigger,
445 NI_AI_ConvertClock,
446 NI_DI_SampleClock,
447 NI_DO_SampleClock,
448 NI_FrequencyOutput,
449 NI_ChangeDetectionEvent,
450 NI_AnalogComparisonEvent,
451 0, /* Termination */
452 }
453 },
454 {
455 .dest = NI_PFI(15),
456 .src = (int[]){
457 TRIGGER_LINE(0),
458 TRIGGER_LINE(1),
459 TRIGGER_LINE(2),
460 TRIGGER_LINE(3),
461 TRIGGER_LINE(4),
462 TRIGGER_LINE(5),
463 TRIGGER_LINE(6),
464 TRIGGER_LINE(7),
465 NI_CtrSource(0),
466 NI_CtrSource(1),
467 NI_CtrGate(0),
468 NI_CtrInternalOutput(0),
469 NI_CtrInternalOutput(1),
470 NI_AI_SampleClock,
471 NI_AI_StartTrigger,
472 NI_AI_ReferenceTrigger,
473 NI_AI_ConvertClock,
474 NI_DI_SampleClock,
475 NI_DO_SampleClock,
476 NI_FrequencyOutput,
477 NI_ChangeDetectionEvent,
478 NI_AnalogComparisonEvent,
479 0, /* Termination */
480 }
481 },
482 {
483 .dest = TRIGGER_LINE(0),
484 .src = (int[]){
485 NI_PFI(0),
486 NI_PFI(1),
487 NI_PFI(2),
488 NI_PFI(3),
489 NI_PFI(4),
490 NI_PFI(5),
491 NI_CtrSource(0),
492 NI_CtrSource(1),
493 NI_CtrGate(0),
494 NI_CtrInternalOutput(0),
495 NI_CtrInternalOutput(1),
496 NI_AI_SampleClock,
497 NI_AI_StartTrigger,
498 NI_AI_ReferenceTrigger,
499 NI_AI_ConvertClock,
500 NI_10MHzRefClock,
501 NI_FrequencyOutput,
502 NI_ChangeDetectionEvent,
503 NI_AnalogComparisonEvent,
504 0, /* Termination */
505 }
506 },
507 {
508 .dest = TRIGGER_LINE(1),
509 .src = (int[]){
510 NI_PFI(0),
511 NI_PFI(1),
512 NI_PFI(2),
513 NI_PFI(3),
514 NI_PFI(4),
515 NI_PFI(5),
516 NI_CtrSource(0),
517 NI_CtrSource(1),
518 NI_CtrGate(0),
519 NI_CtrInternalOutput(0),
520 NI_CtrInternalOutput(1),
521 NI_AI_SampleClock,
522 NI_AI_StartTrigger,
523 NI_AI_ReferenceTrigger,
524 NI_AI_ConvertClock,
525 NI_10MHzRefClock,
526 NI_FrequencyOutput,
527 NI_ChangeDetectionEvent,
528 NI_AnalogComparisonEvent,
529 0, /* Termination */
530 }
531 },
532 {
533 .dest = TRIGGER_LINE(2),
534 .src = (int[]){
535 NI_PFI(0),
536 NI_PFI(1),
537 NI_PFI(2),
538 NI_PFI(3),
539 NI_PFI(4),
540 NI_PFI(5),
541 NI_CtrSource(0),
542 NI_CtrSource(1),
543 NI_CtrGate(0),
544 NI_CtrInternalOutput(0),
545 NI_CtrInternalOutput(1),
546 NI_AI_SampleClock,
547 NI_AI_StartTrigger,
548 NI_AI_ReferenceTrigger,
549 NI_AI_ConvertClock,
550 NI_10MHzRefClock,
551 NI_FrequencyOutput,
552 NI_ChangeDetectionEvent,
553 NI_AnalogComparisonEvent,
554 0, /* Termination */
555 }
556 },
557 {
558 .dest = TRIGGER_LINE(3),
559 .src = (int[]){
560 NI_PFI(0),
561 NI_PFI(1),
562 NI_PFI(2),
563 NI_PFI(3),
564 NI_PFI(4),
565 NI_PFI(5),
566 NI_CtrSource(0),
567 NI_CtrSource(1),
568 NI_CtrGate(0),
569 NI_CtrInternalOutput(0),
570 NI_CtrInternalOutput(1),
571 NI_AI_SampleClock,
572 NI_AI_StartTrigger,
573 NI_AI_ReferenceTrigger,
574 NI_AI_ConvertClock,
575 NI_10MHzRefClock,
576 NI_FrequencyOutput,
577 NI_ChangeDetectionEvent,
578 NI_AnalogComparisonEvent,
579 0, /* Termination */
580 }
581 },
582 {
583 .dest = TRIGGER_LINE(4),
584 .src = (int[]){
585 NI_PFI(0),
586 NI_PFI(1),
587 NI_PFI(2),
588 NI_PFI(3),
589 NI_PFI(4),
590 NI_PFI(5),
591 NI_CtrSource(0),
592 NI_CtrSource(1),
593 NI_CtrGate(0),
594 NI_CtrInternalOutput(0),
595 NI_CtrInternalOutput(1),
596 NI_AI_SampleClock,
597 NI_AI_StartTrigger,
598 NI_AI_ReferenceTrigger,
599 NI_AI_ConvertClock,
600 NI_10MHzRefClock,
601 NI_FrequencyOutput,
602 NI_ChangeDetectionEvent,
603 NI_AnalogComparisonEvent,
604 0, /* Termination */
605 }
606 },
607 {
608 .dest = TRIGGER_LINE(5),
609 .src = (int[]){
610 NI_PFI(0),
611 NI_PFI(1),
612 NI_PFI(2),
613 NI_PFI(3),
614 NI_PFI(4),
615 NI_PFI(5),
616 NI_CtrSource(0),
617 NI_CtrSource(1),
618 NI_CtrGate(0),
619 NI_CtrInternalOutput(0),
620 NI_CtrInternalOutput(1),
621 NI_AI_SampleClock,
622 NI_AI_StartTrigger,
623 NI_AI_ReferenceTrigger,
624 NI_AI_ConvertClock,
625 NI_10MHzRefClock,
626 NI_FrequencyOutput,
627 NI_ChangeDetectionEvent,
628 NI_AnalogComparisonEvent,
629 0, /* Termination */
630 }
631 },
632 {
633 .dest = TRIGGER_LINE(6),
634 .src = (int[]){
635 NI_PFI(0),
636 NI_PFI(1),
637 NI_PFI(2),
638 NI_PFI(3),
639 NI_PFI(4),
640 NI_PFI(5),
641 NI_CtrSource(0),
642 NI_CtrSource(1),
643 NI_CtrGate(0),
644 NI_CtrInternalOutput(0),
645 NI_CtrInternalOutput(1),
646 NI_AI_SampleClock,
647 NI_AI_StartTrigger,
648 NI_AI_ReferenceTrigger,
649 NI_AI_ConvertClock,
650 NI_10MHzRefClock,
651 NI_FrequencyOutput,
652 NI_ChangeDetectionEvent,
653 NI_AnalogComparisonEvent,
654 0, /* Termination */
655 }
656 },
657 {
658 .dest = TRIGGER_LINE(7),
659 .src = (int[]){
660 NI_PFI(0),
661 NI_PFI(1),
662 NI_PFI(2),
663 NI_PFI(3),
664 NI_PFI(4),
665 NI_PFI(5),
666 NI_CtrSource(0),
667 NI_CtrSource(1),
668 NI_CtrGate(0),
669 NI_CtrInternalOutput(0),
670 NI_CtrInternalOutput(1),
671 NI_AI_SampleClock,
672 NI_AI_StartTrigger,
673 NI_AI_ReferenceTrigger,
674 NI_AI_ConvertClock,
675 NI_10MHzRefClock,
676 NI_FrequencyOutput,
677 NI_ChangeDetectionEvent,
678 NI_AnalogComparisonEvent,
679 0, /* Termination */
680 }
681 },
682 {
683 .dest = NI_CtrSource(0),
684 .src = (int[]){
685 NI_PFI(0),
686 NI_PFI(1),
687 NI_PFI(2),
688 NI_PFI(3),
689 NI_PFI(4),
690 NI_PFI(5),
691 NI_PFI(6),
692 NI_PFI(7),
693 NI_PFI(8),
694 NI_PFI(9),
695 NI_PFI(10),
696 NI_PFI(11),
697 NI_PFI(12),
698 NI_PFI(13),
699 NI_PFI(14),
700 NI_PFI(15),
701 TRIGGER_LINE(0),
702 TRIGGER_LINE(1),
703 TRIGGER_LINE(2),
704 TRIGGER_LINE(3),
705 TRIGGER_LINE(4),
706 TRIGGER_LINE(5),
707 TRIGGER_LINE(6),
708 TRIGGER_LINE(7),
709 PXI_Clk10,
710 NI_20MHzTimebase,
711 NI_80MHzTimebase,
712 NI_100kHzTimebase,
713 NI_AnalogComparisonEvent,
714 0, /* Termination */
715 }
716 },
717 {
718 .dest = NI_CtrSource(1),
719 .src = (int[]){
720 NI_PFI(0),
721 NI_PFI(1),
722 NI_PFI(2),
723 NI_PFI(3),
724 NI_PFI(4),
725 NI_PFI(5),
726 NI_PFI(6),
727 NI_PFI(7),
728 NI_PFI(8),
729 NI_PFI(9),
730 NI_PFI(10),
731 NI_PFI(11),
732 NI_PFI(12),
733 NI_PFI(13),
734 NI_PFI(14),
735 NI_PFI(15),
736 TRIGGER_LINE(0),
737 TRIGGER_LINE(1),
738 TRIGGER_LINE(2),
739 TRIGGER_LINE(3),
740 TRIGGER_LINE(4),
741 TRIGGER_LINE(5),
742 TRIGGER_LINE(6),
743 TRIGGER_LINE(7),
744 NI_CtrGate(0),
745 PXI_Clk10,
746 NI_20MHzTimebase,
747 NI_80MHzTimebase,
748 NI_100kHzTimebase,
749 NI_AnalogComparisonEvent,
750 0, /* Termination */
751 }
752 },
753 {
754 .dest = NI_CtrGate(0),
755 .src = (int[]){
756 NI_PFI(0),
757 NI_PFI(1),
758 NI_PFI(2),
759 NI_PFI(3),
760 NI_PFI(4),
761 NI_PFI(5),
762 NI_PFI(6),
763 NI_PFI(7),
764 NI_PFI(8),
765 NI_PFI(9),
766 NI_PFI(10),
767 NI_PFI(11),
768 NI_PFI(12),
769 NI_PFI(13),
770 NI_PFI(14),
771 NI_PFI(15),
772 TRIGGER_LINE(0),
773 TRIGGER_LINE(1),
774 TRIGGER_LINE(2),
775 TRIGGER_LINE(3),
776 TRIGGER_LINE(4),
777 TRIGGER_LINE(5),
778 TRIGGER_LINE(6),
779 TRIGGER_LINE(7),
780 NI_CtrSource(1),
781 NI_CtrInternalOutput(1),
782 NI_AI_StartTrigger,
783 NI_AI_ReferenceTrigger,
784 NI_AnalogComparisonEvent,
785 0, /* Termination */
786 }
787 },
788 {
789 .dest = NI_CtrGate(1),
790 .src = (int[]){
791 NI_PFI(0),
792 NI_PFI(1),
793 NI_PFI(2),
794 NI_PFI(3),
795 NI_PFI(4),
796 NI_PFI(5),
797 NI_PFI(6),
798 NI_PFI(7),
799 NI_PFI(8),
800 NI_PFI(9),
801 NI_PFI(10),
802 NI_PFI(11),
803 NI_PFI(12),
804 NI_PFI(13),
805 NI_PFI(14),
806 NI_PFI(15),
807 TRIGGER_LINE(0),
808 TRIGGER_LINE(1),
809 TRIGGER_LINE(2),
810 TRIGGER_LINE(3),
811 TRIGGER_LINE(4),
812 TRIGGER_LINE(5),
813 TRIGGER_LINE(6),
814 TRIGGER_LINE(7),
815 NI_CtrSource(0),
816 NI_CtrInternalOutput(0),
817 NI_AI_StartTrigger,
818 NI_AI_ReferenceTrigger,
819 NI_AnalogComparisonEvent,
820 0, /* Termination */
821 }
822 },
823 {
824 .dest = NI_CtrAux(0),
825 .src = (int[]){
826 NI_PFI(0),
827 NI_PFI(1),
828 NI_PFI(2),
829 NI_PFI(3),
830 NI_PFI(4),
831 NI_PFI(5),
832 NI_PFI(6),
833 NI_PFI(7),
834 NI_PFI(8),
835 NI_PFI(9),
836 NI_PFI(10),
837 NI_PFI(11),
838 NI_PFI(12),
839 NI_PFI(13),
840 NI_PFI(14),
841 NI_PFI(15),
842 TRIGGER_LINE(0),
843 TRIGGER_LINE(1),
844 TRIGGER_LINE(2),
845 TRIGGER_LINE(3),
846 TRIGGER_LINE(4),
847 TRIGGER_LINE(5),
848 TRIGGER_LINE(6),
849 TRIGGER_LINE(7),
850 NI_CtrSource(1),
851 NI_CtrGate(0),
852 NI_CtrInternalOutput(1),
853 NI_AI_StartTrigger,
854 NI_AI_ReferenceTrigger,
855 NI_AnalogComparisonEvent,
856 0, /* Termination */
857 }
858 },
859 {
860 .dest = NI_CtrAux(1),
861 .src = (int[]){
862 NI_PFI(0),
863 NI_PFI(1),
864 NI_PFI(2),
865 NI_PFI(3),
866 NI_PFI(4),
867 NI_PFI(5),
868 NI_PFI(6),
869 NI_PFI(7),
870 NI_PFI(8),
871 NI_PFI(9),
872 NI_PFI(10),
873 NI_PFI(11),
874 NI_PFI(12),
875 NI_PFI(13),
876 NI_PFI(14),
877 NI_PFI(15),
878 TRIGGER_LINE(0),
879 TRIGGER_LINE(1),
880 TRIGGER_LINE(2),
881 TRIGGER_LINE(3),
882 TRIGGER_LINE(4),
883 TRIGGER_LINE(5),
884 TRIGGER_LINE(6),
885 TRIGGER_LINE(7),
886 NI_CtrSource(0),
887 NI_CtrGate(0),
888 NI_CtrInternalOutput(0),
889 NI_AI_StartTrigger,
890 NI_AI_ReferenceTrigger,
891 NI_AnalogComparisonEvent,
892 0, /* Termination */
893 }
894 },
895 {
896 .dest = NI_CtrA(0),
897 .src = (int[]){
898 NI_PFI(0),
899 NI_PFI(1),
900 NI_PFI(2),
901 NI_PFI(3),
902 NI_PFI(4),
903 NI_PFI(5),
904 NI_PFI(6),
905 NI_PFI(7),
906 NI_PFI(8),
907 NI_PFI(9),
908 NI_PFI(10),
909 NI_PFI(11),
910 NI_PFI(12),
911 NI_PFI(13),
912 NI_PFI(14),
913 NI_PFI(15),
914 TRIGGER_LINE(0),
915 TRIGGER_LINE(1),
916 TRIGGER_LINE(2),
917 TRIGGER_LINE(3),
918 TRIGGER_LINE(4),
919 TRIGGER_LINE(5),
920 TRIGGER_LINE(6),
921 TRIGGER_LINE(7),
922 NI_AnalogComparisonEvent,
923 0, /* Termination */
924 }
925 },
926 {
927 .dest = NI_CtrA(1),
928 .src = (int[]){
929 NI_PFI(0),
930 NI_PFI(1),
931 NI_PFI(2),
932 NI_PFI(3),
933 NI_PFI(4),
934 NI_PFI(5),
935 NI_PFI(6),
936 NI_PFI(7),
937 NI_PFI(8),
938 NI_PFI(9),
939 NI_PFI(10),
940 NI_PFI(11),
941 NI_PFI(12),
942 NI_PFI(13),
943 NI_PFI(14),
944 NI_PFI(15),
945 TRIGGER_LINE(0),
946 TRIGGER_LINE(1),
947 TRIGGER_LINE(2),
948 TRIGGER_LINE(3),
949 TRIGGER_LINE(4),
950 TRIGGER_LINE(5),
951 TRIGGER_LINE(6),
952 TRIGGER_LINE(7),
953 NI_AnalogComparisonEvent,
954 0, /* Termination */
955 }
956 },
957 {
958 .dest = NI_CtrB(0),
959 .src = (int[]){
960 NI_PFI(0),
961 NI_PFI(1),
962 NI_PFI(2),
963 NI_PFI(3),
964 NI_PFI(4),
965 NI_PFI(5),
966 NI_PFI(6),
967 NI_PFI(7),
968 NI_PFI(8),
969 NI_PFI(9),
970 NI_PFI(10),
971 NI_PFI(11),
972 NI_PFI(12),
973 NI_PFI(13),
974 NI_PFI(14),
975 NI_PFI(15),
976 TRIGGER_LINE(0),
977 TRIGGER_LINE(1),
978 TRIGGER_LINE(2),
979 TRIGGER_LINE(3),
980 TRIGGER_LINE(4),
981 TRIGGER_LINE(5),
982 TRIGGER_LINE(6),
983 TRIGGER_LINE(7),
984 NI_AnalogComparisonEvent,
985 0, /* Termination */
986 }
987 },
988 {
989 .dest = NI_CtrB(1),
990 .src = (int[]){
991 NI_PFI(0),
992 NI_PFI(1),
993 NI_PFI(2),
994 NI_PFI(3),
995 NI_PFI(4),
996 NI_PFI(5),
997 NI_PFI(6),
998 NI_PFI(7),
999 NI_PFI(8),
1000 NI_PFI(9),
1001 NI_PFI(10),
1002 NI_PFI(11),
1003 NI_PFI(12),
1004 NI_PFI(13),
1005 NI_PFI(14),
1006 NI_PFI(15),
1007 TRIGGER_LINE(0),
1008 TRIGGER_LINE(1),
1009 TRIGGER_LINE(2),
1010 TRIGGER_LINE(3),
1011 TRIGGER_LINE(4),
1012 TRIGGER_LINE(5),
1013 TRIGGER_LINE(6),
1014 TRIGGER_LINE(7),
1015 NI_AnalogComparisonEvent,
1016 0, /* Termination */
1017 }
1018 },
1019 {
1020 .dest = NI_CtrZ(0),
1021 .src = (int[]){
1022 NI_PFI(0),
1023 NI_PFI(1),
1024 NI_PFI(2),
1025 NI_PFI(3),
1026 NI_PFI(4),
1027 NI_PFI(5),
1028 NI_PFI(6),
1029 NI_PFI(7),
1030 NI_PFI(8),
1031 NI_PFI(9),
1032 NI_PFI(10),
1033 NI_PFI(11),
1034 NI_PFI(12),
1035 NI_PFI(13),
1036 NI_PFI(14),
1037 NI_PFI(15),
1038 TRIGGER_LINE(0),
1039 TRIGGER_LINE(1),
1040 TRIGGER_LINE(2),
1041 TRIGGER_LINE(3),
1042 TRIGGER_LINE(4),
1043 TRIGGER_LINE(5),
1044 TRIGGER_LINE(6),
1045 TRIGGER_LINE(7),
1046 NI_AnalogComparisonEvent,
1047 0, /* Termination */
1048 }
1049 },
1050 {
1051 .dest = NI_CtrZ(1),
1052 .src = (int[]){
1053 NI_PFI(0),
1054 NI_PFI(1),
1055 NI_PFI(2),
1056 NI_PFI(3),
1057 NI_PFI(4),
1058 NI_PFI(5),
1059 NI_PFI(6),
1060 NI_PFI(7),
1061 NI_PFI(8),
1062 NI_PFI(9),
1063 NI_PFI(10),
1064 NI_PFI(11),
1065 NI_PFI(12),
1066 NI_PFI(13),
1067 NI_PFI(14),
1068 NI_PFI(15),
1069 TRIGGER_LINE(0),
1070 TRIGGER_LINE(1),
1071 TRIGGER_LINE(2),
1072 TRIGGER_LINE(3),
1073 TRIGGER_LINE(4),
1074 TRIGGER_LINE(5),
1075 TRIGGER_LINE(6),
1076 TRIGGER_LINE(7),
1077 NI_AnalogComparisonEvent,
1078 0, /* Termination */
1079 }
1080 },
1081 {
1082 .dest = NI_CtrArmStartTrigger(0),
1083 .src = (int[]){
1084 NI_PFI(0),
1085 NI_PFI(1),
1086 NI_PFI(2),
1087 NI_PFI(3),
1088 NI_PFI(4),
1089 NI_PFI(5),
1090 NI_PFI(6),
1091 NI_PFI(7),
1092 NI_PFI(8),
1093 NI_PFI(9),
1094 NI_PFI(10),
1095 NI_PFI(11),
1096 NI_PFI(12),
1097 NI_PFI(13),
1098 NI_PFI(14),
1099 NI_PFI(15),
1100 TRIGGER_LINE(0),
1101 TRIGGER_LINE(1),
1102 TRIGGER_LINE(2),
1103 TRIGGER_LINE(3),
1104 TRIGGER_LINE(4),
1105 TRIGGER_LINE(5),
1106 TRIGGER_LINE(6),
1107 TRIGGER_LINE(7),
1108 NI_CtrInternalOutput(1),
1109 NI_AI_StartTrigger,
1110 NI_AI_ReferenceTrigger,
1111 NI_AnalogComparisonEvent,
1112 0, /* Termination */
1113 }
1114 },
1115 {
1116 .dest = NI_CtrArmStartTrigger(1),
1117 .src = (int[]){
1118 NI_PFI(0),
1119 NI_PFI(1),
1120 NI_PFI(2),
1121 NI_PFI(3),
1122 NI_PFI(4),
1123 NI_PFI(5),
1124 NI_PFI(6),
1125 NI_PFI(7),
1126 NI_PFI(8),
1127 NI_PFI(9),
1128 NI_PFI(10),
1129 NI_PFI(11),
1130 NI_PFI(12),
1131 NI_PFI(13),
1132 NI_PFI(14),
1133 NI_PFI(15),
1134 TRIGGER_LINE(0),
1135 TRIGGER_LINE(1),
1136 TRIGGER_LINE(2),
1137 TRIGGER_LINE(3),
1138 TRIGGER_LINE(4),
1139 TRIGGER_LINE(5),
1140 TRIGGER_LINE(6),
1141 TRIGGER_LINE(7),
1142 NI_CtrInternalOutput(0),
1143 NI_AI_StartTrigger,
1144 NI_AI_ReferenceTrigger,
1145 NI_AnalogComparisonEvent,
1146 0, /* Termination */
1147 }
1148 },
1149 {
1150 .dest = NI_AI_SampleClock,
1151 .src = (int[]){
1152 NI_PFI(0),
1153 NI_PFI(1),
1154 NI_PFI(2),
1155 NI_PFI(3),
1156 NI_PFI(4),
1157 NI_PFI(5),
1158 NI_PFI(6),
1159 NI_PFI(7),
1160 NI_PFI(8),
1161 NI_PFI(9),
1162 NI_PFI(10),
1163 NI_PFI(11),
1164 NI_PFI(12),
1165 NI_PFI(13),
1166 NI_PFI(14),
1167 NI_PFI(15),
1168 TRIGGER_LINE(0),
1169 TRIGGER_LINE(1),
1170 TRIGGER_LINE(2),
1171 TRIGGER_LINE(3),
1172 TRIGGER_LINE(4),
1173 TRIGGER_LINE(5),
1174 TRIGGER_LINE(6),
1175 TRIGGER_LINE(7),
1176 NI_CtrInternalOutput(0),
1177 NI_CtrInternalOutput(1),
1178 NI_AI_SampleClockTimebase,
1179 NI_AnalogComparisonEvent,
1180 0, /* Termination */
1181 }
1182 },
1183 {
1184 .dest = NI_AI_SampleClockTimebase,
1185 .src = (int[]){
1186 NI_PFI(0),
1187 NI_PFI(1),
1188 NI_PFI(2),
1189 NI_PFI(3),
1190 NI_PFI(4),
1191 NI_PFI(5),
1192 NI_PFI(6),
1193 NI_PFI(7),
1194 NI_PFI(8),
1195 NI_PFI(9),
1196 NI_PFI(10),
1197 NI_PFI(11),
1198 NI_PFI(12),
1199 NI_PFI(13),
1200 NI_PFI(14),
1201 NI_PFI(15),
1202 TRIGGER_LINE(0),
1203 TRIGGER_LINE(1),
1204 TRIGGER_LINE(2),
1205 TRIGGER_LINE(3),
1206 TRIGGER_LINE(4),
1207 TRIGGER_LINE(5),
1208 TRIGGER_LINE(6),
1209 TRIGGER_LINE(7),
1210 PXI_Clk10,
1211 NI_20MHzTimebase,
1212 NI_100kHzTimebase,
1213 NI_AnalogComparisonEvent,
1214 0, /* Termination */
1215 }
1216 },
1217 {
1218 .dest = NI_AI_StartTrigger,
1219 .src = (int[]){
1220 NI_PFI(0),
1221 NI_PFI(1),
1222 NI_PFI(2),
1223 NI_PFI(3),
1224 NI_PFI(4),
1225 NI_PFI(5),
1226 NI_PFI(6),
1227 NI_PFI(7),
1228 NI_PFI(8),
1229 NI_PFI(9),
1230 NI_PFI(10),
1231 NI_PFI(11),
1232 NI_PFI(12),
1233 NI_PFI(13),
1234 NI_PFI(14),
1235 NI_PFI(15),
1236 TRIGGER_LINE(0),
1237 TRIGGER_LINE(1),
1238 TRIGGER_LINE(2),
1239 TRIGGER_LINE(3),
1240 TRIGGER_LINE(4),
1241 TRIGGER_LINE(5),
1242 TRIGGER_LINE(6),
1243 TRIGGER_LINE(7),
1244 NI_CtrInternalOutput(0),
1245 NI_CtrInternalOutput(1),
1246 NI_AnalogComparisonEvent,
1247 0, /* Termination */
1248 }
1249 },
1250 {
1251 .dest = NI_AI_ReferenceTrigger,
1252 .src = (int[]){
1253 NI_PFI(0),
1254 NI_PFI(1),
1255 NI_PFI(2),
1256 NI_PFI(3),
1257 NI_PFI(4),
1258 NI_PFI(5),
1259 NI_PFI(6),
1260 NI_PFI(7),
1261 NI_PFI(8),
1262 NI_PFI(9),
1263 NI_PFI(10),
1264 NI_PFI(11),
1265 NI_PFI(12),
1266 NI_PFI(13),
1267 NI_PFI(14),
1268 NI_PFI(15),
1269 TRIGGER_LINE(0),
1270 TRIGGER_LINE(1),
1271 TRIGGER_LINE(2),
1272 TRIGGER_LINE(3),
1273 TRIGGER_LINE(4),
1274 TRIGGER_LINE(5),
1275 TRIGGER_LINE(6),
1276 TRIGGER_LINE(7),
1277 NI_AnalogComparisonEvent,
1278 0, /* Termination */
1279 }
1280 },
1281 {
1282 .dest = NI_AI_ConvertClock,
1283 .src = (int[]){
1284 NI_PFI(0),
1285 NI_PFI(1),
1286 NI_PFI(2),
1287 NI_PFI(3),
1288 NI_PFI(4),
1289 NI_PFI(5),
1290 NI_PFI(6),
1291 NI_PFI(7),
1292 NI_PFI(8),
1293 NI_PFI(9),
1294 NI_PFI(10),
1295 NI_PFI(11),
1296 NI_PFI(12),
1297 NI_PFI(13),
1298 NI_PFI(14),
1299 NI_PFI(15),
1300 TRIGGER_LINE(0),
1301 TRIGGER_LINE(1),
1302 TRIGGER_LINE(2),
1303 TRIGGER_LINE(3),
1304 TRIGGER_LINE(4),
1305 TRIGGER_LINE(5),
1306 TRIGGER_LINE(6),
1307 TRIGGER_LINE(7),
1308 NI_CtrInternalOutput(0),
1309 NI_CtrInternalOutput(1),
1310 NI_AI_ConvertClockTimebase,
1311 NI_AnalogComparisonEvent,
1312 0, /* Termination */
1313 }
1314 },
1315 {
1316 .dest = NI_AI_ConvertClockTimebase,
1317 .src = (int[]){
1318 NI_AI_SampleClockTimebase,
1319 NI_20MHzTimebase,
1320 0, /* Termination */
1321 }
1322 },
1323 {
1324 .dest = NI_AI_PauseTrigger,
1325 .src = (int[]){
1326 NI_PFI(0),
1327 NI_PFI(1),
1328 NI_PFI(2),
1329 NI_PFI(3),
1330 NI_PFI(4),
1331 NI_PFI(5),
1332 NI_PFI(6),
1333 NI_PFI(7),
1334 NI_PFI(8),
1335 NI_PFI(9),
1336 NI_PFI(10),
1337 NI_PFI(11),
1338 NI_PFI(12),
1339 NI_PFI(13),
1340 NI_PFI(14),
1341 NI_PFI(15),
1342 TRIGGER_LINE(0),
1343 TRIGGER_LINE(1),
1344 TRIGGER_LINE(2),
1345 TRIGGER_LINE(3),
1346 TRIGGER_LINE(4),
1347 TRIGGER_LINE(5),
1348 TRIGGER_LINE(6),
1349 TRIGGER_LINE(7),
1350 NI_AnalogComparisonEvent,
1351 0, /* Termination */
1352 }
1353 },
1354 {
1355 .dest = NI_DI_SampleClock,
1356 .src = (int[]){
1357 NI_PFI(0),
1358 NI_PFI(1),
1359 NI_PFI(2),
1360 NI_PFI(3),
1361 NI_PFI(4),
1362 NI_PFI(5),
1363 NI_PFI(6),
1364 NI_PFI(7),
1365 NI_PFI(8),
1366 NI_PFI(9),
1367 NI_PFI(10),
1368 NI_PFI(11),
1369 NI_PFI(12),
1370 NI_PFI(13),
1371 NI_PFI(14),
1372 NI_PFI(15),
1373 TRIGGER_LINE(0),
1374 TRIGGER_LINE(1),
1375 TRIGGER_LINE(2),
1376 TRIGGER_LINE(3),
1377 TRIGGER_LINE(4),
1378 TRIGGER_LINE(5),
1379 TRIGGER_LINE(6),
1380 TRIGGER_LINE(7),
1381 NI_CtrInternalOutput(0),
1382 NI_CtrInternalOutput(1),
1383 NI_AI_SampleClock,
1384 NI_AI_ConvertClock,
1385 NI_FrequencyOutput,
1386 NI_ChangeDetectionEvent,
1387 NI_AnalogComparisonEvent,
1388 0, /* Termination */
1389 }
1390 },
1391 {
1392 .dest = NI_DO_SampleClock,
1393 .src = (int[]){
1394 NI_PFI(0),
1395 NI_PFI(1),
1396 NI_PFI(2),
1397 NI_PFI(3),
1398 NI_PFI(4),
1399 NI_PFI(5),
1400 NI_PFI(6),
1401 NI_PFI(7),
1402 NI_PFI(8),
1403 NI_PFI(9),
1404 NI_PFI(10),
1405 NI_PFI(11),
1406 NI_PFI(12),
1407 NI_PFI(13),
1408 NI_PFI(14),
1409 NI_PFI(15),
1410 TRIGGER_LINE(0),
1411 TRIGGER_LINE(1),
1412 TRIGGER_LINE(2),
1413 TRIGGER_LINE(3),
1414 TRIGGER_LINE(4),
1415 TRIGGER_LINE(5),
1416 TRIGGER_LINE(6),
1417 TRIGGER_LINE(7),
1418 NI_CtrInternalOutput(0),
1419 NI_CtrInternalOutput(1),
1420 NI_AI_SampleClock,
1421 NI_AI_ConvertClock,
1422 NI_FrequencyOutput,
1423 NI_ChangeDetectionEvent,
1424 NI_AnalogComparisonEvent,
1425 0, /* Termination */
1426 }
1427 },
1428 { /* Termination of list */
1429 .dest = 0,
1430 },
1431 },
1432};
diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxi-6225.c b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxi-6225.c
new file mode 100644
index 000000000000..10dfc34bc87c
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxi-6225.c
@@ -0,0 +1,1613 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routing/ni_device_routes/pxi-6225.c
5 * List of valid routes for specific NI boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21/*
22 * The contents of this file are generated using the tools in
23 * comedi/drivers/ni_routing/tools
24 *
25 * Please use those tools to help maintain the contents of this file.
26 */
27
28#include "../ni_device_routes.h"
29#include "all.h"
30
31struct ni_device_routes ni_pxi_6225_device_routes = {
32 .device = "pxi-6225",
33 .routes = (struct ni_route_set[]){
34 {
35 .dest = NI_PFI(0),
36 .src = (int[]){
37 TRIGGER_LINE(0),
38 TRIGGER_LINE(1),
39 TRIGGER_LINE(2),
40 TRIGGER_LINE(3),
41 TRIGGER_LINE(4),
42 TRIGGER_LINE(5),
43 TRIGGER_LINE(6),
44 TRIGGER_LINE(7),
45 NI_CtrSource(0),
46 NI_CtrSource(1),
47 NI_CtrGate(0),
48 NI_CtrInternalOutput(0),
49 NI_CtrInternalOutput(1),
50 NI_AI_SampleClock,
51 NI_AI_StartTrigger,
52 NI_AI_ReferenceTrigger,
53 NI_AI_ConvertClock,
54 NI_AO_SampleClock,
55 NI_AO_StartTrigger,
56 NI_DI_SampleClock,
57 NI_DO_SampleClock,
58 NI_FrequencyOutput,
59 NI_ChangeDetectionEvent,
60 NI_AnalogComparisonEvent,
61 0, /* Termination */
62 }
63 },
64 {
65 .dest = NI_PFI(1),
66 .src = (int[]){
67 TRIGGER_LINE(0),
68 TRIGGER_LINE(1),
69 TRIGGER_LINE(2),
70 TRIGGER_LINE(3),
71 TRIGGER_LINE(4),
72 TRIGGER_LINE(5),
73 TRIGGER_LINE(6),
74 TRIGGER_LINE(7),
75 NI_CtrSource(0),
76 NI_CtrSource(1),
77 NI_CtrGate(0),
78 NI_CtrInternalOutput(0),
79 NI_CtrInternalOutput(1),
80 NI_AI_SampleClock,
81 NI_AI_StartTrigger,
82 NI_AI_ReferenceTrigger,
83 NI_AI_ConvertClock,
84 NI_AO_SampleClock,
85 NI_AO_StartTrigger,
86 NI_DI_SampleClock,
87 NI_DO_SampleClock,
88 NI_FrequencyOutput,
89 NI_ChangeDetectionEvent,
90 NI_AnalogComparisonEvent,
91 0, /* Termination */
92 }
93 },
94 {
95 .dest = NI_PFI(2),
96 .src = (int[]){
97 TRIGGER_LINE(0),
98 TRIGGER_LINE(1),
99 TRIGGER_LINE(2),
100 TRIGGER_LINE(3),
101 TRIGGER_LINE(4),
102 TRIGGER_LINE(5),
103 TRIGGER_LINE(6),
104 TRIGGER_LINE(7),
105 NI_CtrSource(0),
106 NI_CtrSource(1),
107 NI_CtrGate(0),
108 NI_CtrInternalOutput(0),
109 NI_CtrInternalOutput(1),
110 NI_AI_SampleClock,
111 NI_AI_StartTrigger,
112 NI_AI_ReferenceTrigger,
113 NI_AI_ConvertClock,
114 NI_AO_SampleClock,
115 NI_AO_StartTrigger,
116 NI_DI_SampleClock,
117 NI_DO_SampleClock,
118 NI_FrequencyOutput,
119 NI_ChangeDetectionEvent,
120 NI_AnalogComparisonEvent,
121 0, /* Termination */
122 }
123 },
124 {
125 .dest = NI_PFI(3),
126 .src = (int[]){
127 TRIGGER_LINE(0),
128 TRIGGER_LINE(1),
129 TRIGGER_LINE(2),
130 TRIGGER_LINE(3),
131 TRIGGER_LINE(4),
132 TRIGGER_LINE(5),
133 TRIGGER_LINE(6),
134 TRIGGER_LINE(7),
135 NI_CtrSource(0),
136 NI_CtrSource(1),
137 NI_CtrGate(0),
138 NI_CtrInternalOutput(0),
139 NI_CtrInternalOutput(1),
140 NI_AI_SampleClock,
141 NI_AI_StartTrigger,
142 NI_AI_ReferenceTrigger,
143 NI_AI_ConvertClock,
144 NI_AO_SampleClock,
145 NI_AO_StartTrigger,
146 NI_DI_SampleClock,
147 NI_DO_SampleClock,
148 NI_FrequencyOutput,
149 NI_ChangeDetectionEvent,
150 NI_AnalogComparisonEvent,
151 0, /* Termination */
152 }
153 },
154 {
155 .dest = NI_PFI(4),
156 .src = (int[]){
157 TRIGGER_LINE(0),
158 TRIGGER_LINE(1),
159 TRIGGER_LINE(2),
160 TRIGGER_LINE(3),
161 TRIGGER_LINE(4),
162 TRIGGER_LINE(5),
163 TRIGGER_LINE(6),
164 TRIGGER_LINE(7),
165 NI_CtrSource(0),
166 NI_CtrSource(1),
167 NI_CtrGate(0),
168 NI_CtrInternalOutput(0),
169 NI_CtrInternalOutput(1),
170 NI_AI_SampleClock,
171 NI_AI_StartTrigger,
172 NI_AI_ReferenceTrigger,
173 NI_AI_ConvertClock,
174 NI_AO_SampleClock,
175 NI_AO_StartTrigger,
176 NI_DI_SampleClock,
177 NI_DO_SampleClock,
178 NI_FrequencyOutput,
179 NI_ChangeDetectionEvent,
180 NI_AnalogComparisonEvent,
181 0, /* Termination */
182 }
183 },
184 {
185 .dest = NI_PFI(5),
186 .src = (int[]){
187 TRIGGER_LINE(0),
188 TRIGGER_LINE(1),
189 TRIGGER_LINE(2),
190 TRIGGER_LINE(3),
191 TRIGGER_LINE(4),
192 TRIGGER_LINE(5),
193 TRIGGER_LINE(6),
194 TRIGGER_LINE(7),
195 NI_CtrSource(0),
196 NI_CtrSource(1),
197 NI_CtrGate(0),
198 NI_CtrInternalOutput(0),
199 NI_CtrInternalOutput(1),
200 NI_AI_SampleClock,
201 NI_AI_StartTrigger,
202 NI_AI_ReferenceTrigger,
203 NI_AI_ConvertClock,
204 NI_AO_SampleClock,
205 NI_AO_StartTrigger,
206 NI_DI_SampleClock,
207 NI_DO_SampleClock,
208 NI_FrequencyOutput,
209 NI_ChangeDetectionEvent,
210 NI_AnalogComparisonEvent,
211 0, /* Termination */
212 }
213 },
214 {
215 .dest = NI_PFI(6),
216 .src = (int[]){
217 TRIGGER_LINE(0),
218 TRIGGER_LINE(1),
219 TRIGGER_LINE(2),
220 TRIGGER_LINE(3),
221 TRIGGER_LINE(4),
222 TRIGGER_LINE(5),
223 TRIGGER_LINE(6),
224 TRIGGER_LINE(7),
225 NI_CtrSource(0),
226 NI_CtrSource(1),
227 NI_CtrGate(0),
228 NI_CtrInternalOutput(0),
229 NI_CtrInternalOutput(1),
230 NI_AI_SampleClock,
231 NI_AI_StartTrigger,
232 NI_AI_ReferenceTrigger,
233 NI_AI_ConvertClock,
234 NI_AO_SampleClock,
235 NI_AO_StartTrigger,
236 NI_DI_SampleClock,
237 NI_DO_SampleClock,
238 NI_FrequencyOutput,
239 NI_ChangeDetectionEvent,
240 NI_AnalogComparisonEvent,
241 0, /* Termination */
242 }
243 },
244 {
245 .dest = NI_PFI(7),
246 .src = (int[]){
247 TRIGGER_LINE(0),
248 TRIGGER_LINE(1),
249 TRIGGER_LINE(2),
250 TRIGGER_LINE(3),
251 TRIGGER_LINE(4),
252 TRIGGER_LINE(5),
253 TRIGGER_LINE(6),
254 TRIGGER_LINE(7),
255 NI_CtrSource(0),
256 NI_CtrSource(1),
257 NI_CtrGate(0),
258 NI_CtrInternalOutput(0),
259 NI_CtrInternalOutput(1),
260 NI_AI_SampleClock,
261 NI_AI_StartTrigger,
262 NI_AI_ReferenceTrigger,
263 NI_AI_ConvertClock,
264 NI_AO_SampleClock,
265 NI_AO_StartTrigger,
266 NI_DI_SampleClock,
267 NI_DO_SampleClock,
268 NI_FrequencyOutput,
269 NI_ChangeDetectionEvent,
270 NI_AnalogComparisonEvent,
271 0, /* Termination */
272 }
273 },
274 {
275 .dest = NI_PFI(8),
276 .src = (int[]){
277 TRIGGER_LINE(0),
278 TRIGGER_LINE(1),
279 TRIGGER_LINE(2),
280 TRIGGER_LINE(3),
281 TRIGGER_LINE(4),
282 TRIGGER_LINE(5),
283 TRIGGER_LINE(6),
284 TRIGGER_LINE(7),
285 NI_CtrSource(0),
286 NI_CtrSource(1),
287 NI_CtrGate(0),
288 NI_CtrInternalOutput(0),
289 NI_CtrInternalOutput(1),
290 NI_AI_SampleClock,
291 NI_AI_StartTrigger,
292 NI_AI_ReferenceTrigger,
293 NI_AI_ConvertClock,
294 NI_AO_SampleClock,
295 NI_AO_StartTrigger,
296 NI_DI_SampleClock,
297 NI_DO_SampleClock,
298 NI_FrequencyOutput,
299 NI_ChangeDetectionEvent,
300 NI_AnalogComparisonEvent,
301 0, /* Termination */
302 }
303 },
304 {
305 .dest = NI_PFI(9),
306 .src = (int[]){
307 TRIGGER_LINE(0),
308 TRIGGER_LINE(1),
309 TRIGGER_LINE(2),
310 TRIGGER_LINE(3),
311 TRIGGER_LINE(4),
312 TRIGGER_LINE(5),
313 TRIGGER_LINE(6),
314 TRIGGER_LINE(7),
315 NI_CtrSource(0),
316 NI_CtrSource(1),
317 NI_CtrGate(0),
318 NI_CtrInternalOutput(0),
319 NI_CtrInternalOutput(1),
320 NI_AI_SampleClock,
321 NI_AI_StartTrigger,
322 NI_AI_ReferenceTrigger,
323 NI_AI_ConvertClock,
324 NI_AO_SampleClock,
325 NI_AO_StartTrigger,
326 NI_DI_SampleClock,
327 NI_DO_SampleClock,
328 NI_FrequencyOutput,
329 NI_ChangeDetectionEvent,
330 NI_AnalogComparisonEvent,
331 0, /* Termination */
332 }
333 },
334 {
335 .dest = NI_PFI(10),
336 .src = (int[]){
337 TRIGGER_LINE(0),
338 TRIGGER_LINE(1),
339 TRIGGER_LINE(2),
340 TRIGGER_LINE(3),
341 TRIGGER_LINE(4),
342 TRIGGER_LINE(5),
343 TRIGGER_LINE(6),
344 TRIGGER_LINE(7),
345 NI_CtrSource(0),
346 NI_CtrSource(1),
347 NI_CtrGate(0),
348 NI_CtrInternalOutput(0),
349 NI_CtrInternalOutput(1),
350 NI_AI_SampleClock,
351 NI_AI_StartTrigger,
352 NI_AI_ReferenceTrigger,
353 NI_AI_ConvertClock,
354 NI_AO_SampleClock,
355 NI_AO_StartTrigger,
356 NI_DI_SampleClock,
357 NI_DO_SampleClock,
358 NI_FrequencyOutput,
359 NI_ChangeDetectionEvent,
360 NI_AnalogComparisonEvent,
361 0, /* Termination */
362 }
363 },
364 {
365 .dest = NI_PFI(11),
366 .src = (int[]){
367 TRIGGER_LINE(0),
368 TRIGGER_LINE(1),
369 TRIGGER_LINE(2),
370 TRIGGER_LINE(3),
371 TRIGGER_LINE(4),
372 TRIGGER_LINE(5),
373 TRIGGER_LINE(6),
374 TRIGGER_LINE(7),
375 NI_CtrSource(0),
376 NI_CtrSource(1),
377 NI_CtrGate(0),
378 NI_CtrInternalOutput(0),
379 NI_CtrInternalOutput(1),
380 NI_AI_SampleClock,
381 NI_AI_StartTrigger,
382 NI_AI_ReferenceTrigger,
383 NI_AI_ConvertClock,
384 NI_AO_SampleClock,
385 NI_AO_StartTrigger,
386 NI_DI_SampleClock,
387 NI_DO_SampleClock,
388 NI_FrequencyOutput,
389 NI_ChangeDetectionEvent,
390 NI_AnalogComparisonEvent,
391 0, /* Termination */
392 }
393 },
394 {
395 .dest = NI_PFI(12),
396 .src = (int[]){
397 TRIGGER_LINE(0),
398 TRIGGER_LINE(1),
399 TRIGGER_LINE(2),
400 TRIGGER_LINE(3),
401 TRIGGER_LINE(4),
402 TRIGGER_LINE(5),
403 TRIGGER_LINE(6),
404 TRIGGER_LINE(7),
405 NI_CtrSource(0),
406 NI_CtrSource(1),
407 NI_CtrGate(0),
408 NI_CtrInternalOutput(0),
409 NI_CtrInternalOutput(1),
410 NI_AI_SampleClock,
411 NI_AI_StartTrigger,
412 NI_AI_ReferenceTrigger,
413 NI_AI_ConvertClock,
414 NI_AO_SampleClock,
415 NI_AO_StartTrigger,
416 NI_DI_SampleClock,
417 NI_DO_SampleClock,
418 NI_FrequencyOutput,
419 NI_ChangeDetectionEvent,
420 NI_AnalogComparisonEvent,
421 0, /* Termination */
422 }
423 },
424 {
425 .dest = NI_PFI(13),
426 .src = (int[]){
427 TRIGGER_LINE(0),
428 TRIGGER_LINE(1),
429 TRIGGER_LINE(2),
430 TRIGGER_LINE(3),
431 TRIGGER_LINE(4),
432 TRIGGER_LINE(5),
433 TRIGGER_LINE(6),
434 TRIGGER_LINE(7),
435 NI_CtrSource(0),
436 NI_CtrSource(1),
437 NI_CtrGate(0),
438 NI_CtrInternalOutput(0),
439 NI_CtrInternalOutput(1),
440 NI_AI_SampleClock,
441 NI_AI_StartTrigger,
442 NI_AI_ReferenceTrigger,
443 NI_AI_ConvertClock,
444 NI_AO_SampleClock,
445 NI_AO_StartTrigger,
446 NI_DI_SampleClock,
447 NI_DO_SampleClock,
448 NI_FrequencyOutput,
449 NI_ChangeDetectionEvent,
450 NI_AnalogComparisonEvent,
451 0, /* Termination */
452 }
453 },
454 {
455 .dest = NI_PFI(14),
456 .src = (int[]){
457 TRIGGER_LINE(0),
458 TRIGGER_LINE(1),
459 TRIGGER_LINE(2),
460 TRIGGER_LINE(3),
461 TRIGGER_LINE(4),
462 TRIGGER_LINE(5),
463 TRIGGER_LINE(6),
464 TRIGGER_LINE(7),
465 NI_CtrSource(0),
466 NI_CtrSource(1),
467 NI_CtrGate(0),
468 NI_CtrInternalOutput(0),
469 NI_CtrInternalOutput(1),
470 NI_AI_SampleClock,
471 NI_AI_StartTrigger,
472 NI_AI_ReferenceTrigger,
473 NI_AI_ConvertClock,
474 NI_AO_SampleClock,
475 NI_AO_StartTrigger,
476 NI_DI_SampleClock,
477 NI_DO_SampleClock,
478 NI_FrequencyOutput,
479 NI_ChangeDetectionEvent,
480 NI_AnalogComparisonEvent,
481 0, /* Termination */
482 }
483 },
484 {
485 .dest = NI_PFI(15),
486 .src = (int[]){
487 TRIGGER_LINE(0),
488 TRIGGER_LINE(1),
489 TRIGGER_LINE(2),
490 TRIGGER_LINE(3),
491 TRIGGER_LINE(4),
492 TRIGGER_LINE(5),
493 TRIGGER_LINE(6),
494 TRIGGER_LINE(7),
495 NI_CtrSource(0),
496 NI_CtrSource(1),
497 NI_CtrGate(0),
498 NI_CtrInternalOutput(0),
499 NI_CtrInternalOutput(1),
500 NI_AI_SampleClock,
501 NI_AI_StartTrigger,
502 NI_AI_ReferenceTrigger,
503 NI_AI_ConvertClock,
504 NI_AO_SampleClock,
505 NI_AO_StartTrigger,
506 NI_DI_SampleClock,
507 NI_DO_SampleClock,
508 NI_FrequencyOutput,
509 NI_ChangeDetectionEvent,
510 NI_AnalogComparisonEvent,
511 0, /* Termination */
512 }
513 },
514 {
515 .dest = TRIGGER_LINE(0),
516 .src = (int[]){
517 NI_PFI(0),
518 NI_PFI(1),
519 NI_PFI(2),
520 NI_PFI(3),
521 NI_PFI(4),
522 NI_PFI(5),
523 NI_CtrSource(0),
524 NI_CtrSource(1),
525 NI_CtrGate(0),
526 NI_CtrInternalOutput(0),
527 NI_CtrInternalOutput(1),
528 NI_AI_SampleClock,
529 NI_AI_StartTrigger,
530 NI_AI_ReferenceTrigger,
531 NI_AI_ConvertClock,
532 NI_AO_SampleClock,
533 NI_AO_StartTrigger,
534 NI_10MHzRefClock,
535 NI_FrequencyOutput,
536 NI_ChangeDetectionEvent,
537 NI_AnalogComparisonEvent,
538 0, /* Termination */
539 }
540 },
541 {
542 .dest = TRIGGER_LINE(1),
543 .src = (int[]){
544 NI_PFI(0),
545 NI_PFI(1),
546 NI_PFI(2),
547 NI_PFI(3),
548 NI_PFI(4),
549 NI_PFI(5),
550 NI_CtrSource(0),
551 NI_CtrSource(1),
552 NI_CtrGate(0),
553 NI_CtrInternalOutput(0),
554 NI_CtrInternalOutput(1),
555 NI_AI_SampleClock,
556 NI_AI_StartTrigger,
557 NI_AI_ReferenceTrigger,
558 NI_AI_ConvertClock,
559 NI_AO_SampleClock,
560 NI_AO_StartTrigger,
561 NI_10MHzRefClock,
562 NI_FrequencyOutput,
563 NI_ChangeDetectionEvent,
564 NI_AnalogComparisonEvent,
565 0, /* Termination */
566 }
567 },
568 {
569 .dest = TRIGGER_LINE(2),
570 .src = (int[]){
571 NI_PFI(0),
572 NI_PFI(1),
573 NI_PFI(2),
574 NI_PFI(3),
575 NI_PFI(4),
576 NI_PFI(5),
577 NI_CtrSource(0),
578 NI_CtrSource(1),
579 NI_CtrGate(0),
580 NI_CtrInternalOutput(0),
581 NI_CtrInternalOutput(1),
582 NI_AI_SampleClock,
583 NI_AI_StartTrigger,
584 NI_AI_ReferenceTrigger,
585 NI_AI_ConvertClock,
586 NI_AO_SampleClock,
587 NI_AO_StartTrigger,
588 NI_10MHzRefClock,
589 NI_FrequencyOutput,
590 NI_ChangeDetectionEvent,
591 NI_AnalogComparisonEvent,
592 0, /* Termination */
593 }
594 },
595 {
596 .dest = TRIGGER_LINE(3),
597 .src = (int[]){
598 NI_PFI(0),
599 NI_PFI(1),
600 NI_PFI(2),
601 NI_PFI(3),
602 NI_PFI(4),
603 NI_PFI(5),
604 NI_CtrSource(0),
605 NI_CtrSource(1),
606 NI_CtrGate(0),
607 NI_CtrInternalOutput(0),
608 NI_CtrInternalOutput(1),
609 NI_AI_SampleClock,
610 NI_AI_StartTrigger,
611 NI_AI_ReferenceTrigger,
612 NI_AI_ConvertClock,
613 NI_AO_SampleClock,
614 NI_AO_StartTrigger,
615 NI_10MHzRefClock,
616 NI_FrequencyOutput,
617 NI_ChangeDetectionEvent,
618 NI_AnalogComparisonEvent,
619 0, /* Termination */
620 }
621 },
622 {
623 .dest = TRIGGER_LINE(4),
624 .src = (int[]){
625 NI_PFI(0),
626 NI_PFI(1),
627 NI_PFI(2),
628 NI_PFI(3),
629 NI_PFI(4),
630 NI_PFI(5),
631 NI_CtrSource(0),
632 NI_CtrSource(1),
633 NI_CtrGate(0),
634 NI_CtrInternalOutput(0),
635 NI_CtrInternalOutput(1),
636 NI_AI_SampleClock,
637 NI_AI_StartTrigger,
638 NI_AI_ReferenceTrigger,
639 NI_AI_ConvertClock,
640 NI_AO_SampleClock,
641 NI_AO_StartTrigger,
642 NI_10MHzRefClock,
643 NI_FrequencyOutput,
644 NI_ChangeDetectionEvent,
645 NI_AnalogComparisonEvent,
646 0, /* Termination */
647 }
648 },
649 {
650 .dest = TRIGGER_LINE(5),
651 .src = (int[]){
652 NI_PFI(0),
653 NI_PFI(1),
654 NI_PFI(2),
655 NI_PFI(3),
656 NI_PFI(4),
657 NI_PFI(5),
658 NI_CtrSource(0),
659 NI_CtrSource(1),
660 NI_CtrGate(0),
661 NI_CtrInternalOutput(0),
662 NI_CtrInternalOutput(1),
663 NI_AI_SampleClock,
664 NI_AI_StartTrigger,
665 NI_AI_ReferenceTrigger,
666 NI_AI_ConvertClock,
667 NI_AO_SampleClock,
668 NI_AO_StartTrigger,
669 NI_10MHzRefClock,
670 NI_FrequencyOutput,
671 NI_ChangeDetectionEvent,
672 NI_AnalogComparisonEvent,
673 0, /* Termination */
674 }
675 },
676 {
677 .dest = TRIGGER_LINE(6),
678 .src = (int[]){
679 NI_PFI(0),
680 NI_PFI(1),
681 NI_PFI(2),
682 NI_PFI(3),
683 NI_PFI(4),
684 NI_PFI(5),
685 NI_CtrSource(0),
686 NI_CtrSource(1),
687 NI_CtrGate(0),
688 NI_CtrInternalOutput(0),
689 NI_CtrInternalOutput(1),
690 NI_AI_SampleClock,
691 NI_AI_StartTrigger,
692 NI_AI_ReferenceTrigger,
693 NI_AI_ConvertClock,
694 NI_AO_SampleClock,
695 NI_AO_StartTrigger,
696 NI_10MHzRefClock,
697 NI_FrequencyOutput,
698 NI_ChangeDetectionEvent,
699 NI_AnalogComparisonEvent,
700 0, /* Termination */
701 }
702 },
703 {
704 .dest = TRIGGER_LINE(7),
705 .src = (int[]){
706 NI_PFI(0),
707 NI_PFI(1),
708 NI_PFI(2),
709 NI_PFI(3),
710 NI_PFI(4),
711 NI_PFI(5),
712 NI_CtrSource(0),
713 NI_CtrSource(1),
714 NI_CtrGate(0),
715 NI_CtrInternalOutput(0),
716 NI_CtrInternalOutput(1),
717 NI_AI_SampleClock,
718 NI_AI_StartTrigger,
719 NI_AI_ReferenceTrigger,
720 NI_AI_ConvertClock,
721 NI_AO_SampleClock,
722 NI_AO_StartTrigger,
723 NI_10MHzRefClock,
724 NI_FrequencyOutput,
725 NI_ChangeDetectionEvent,
726 NI_AnalogComparisonEvent,
727 0, /* Termination */
728 }
729 },
730 {
731 .dest = NI_CtrSource(0),
732 .src = (int[]){
733 NI_PFI(0),
734 NI_PFI(1),
735 NI_PFI(2),
736 NI_PFI(3),
737 NI_PFI(4),
738 NI_PFI(5),
739 NI_PFI(6),
740 NI_PFI(7),
741 NI_PFI(8),
742 NI_PFI(9),
743 NI_PFI(10),
744 NI_PFI(11),
745 NI_PFI(12),
746 NI_PFI(13),
747 NI_PFI(14),
748 NI_PFI(15),
749 TRIGGER_LINE(0),
750 TRIGGER_LINE(1),
751 TRIGGER_LINE(2),
752 TRIGGER_LINE(3),
753 TRIGGER_LINE(4),
754 TRIGGER_LINE(5),
755 TRIGGER_LINE(6),
756 TRIGGER_LINE(7),
757 PXI_Clk10,
758 NI_20MHzTimebase,
759 NI_80MHzTimebase,
760 NI_100kHzTimebase,
761 NI_AnalogComparisonEvent,
762 0, /* Termination */
763 }
764 },
765 {
766 .dest = NI_CtrSource(1),
767 .src = (int[]){
768 NI_PFI(0),
769 NI_PFI(1),
770 NI_PFI(2),
771 NI_PFI(3),
772 NI_PFI(4),
773 NI_PFI(5),
774 NI_PFI(6),
775 NI_PFI(7),
776 NI_PFI(8),
777 NI_PFI(9),
778 NI_PFI(10),
779 NI_PFI(11),
780 NI_PFI(12),
781 NI_PFI(13),
782 NI_PFI(14),
783 NI_PFI(15),
784 TRIGGER_LINE(0),
785 TRIGGER_LINE(1),
786 TRIGGER_LINE(2),
787 TRIGGER_LINE(3),
788 TRIGGER_LINE(4),
789 TRIGGER_LINE(5),
790 TRIGGER_LINE(6),
791 TRIGGER_LINE(7),
792 NI_CtrGate(0),
793 PXI_Clk10,
794 NI_20MHzTimebase,
795 NI_80MHzTimebase,
796 NI_100kHzTimebase,
797 NI_AnalogComparisonEvent,
798 0, /* Termination */
799 }
800 },
801 {
802 .dest = NI_CtrGate(0),
803 .src = (int[]){
804 NI_PFI(0),
805 NI_PFI(1),
806 NI_PFI(2),
807 NI_PFI(3),
808 NI_PFI(4),
809 NI_PFI(5),
810 NI_PFI(6),
811 NI_PFI(7),
812 NI_PFI(8),
813 NI_PFI(9),
814 NI_PFI(10),
815 NI_PFI(11),
816 NI_PFI(12),
817 NI_PFI(13),
818 NI_PFI(14),
819 NI_PFI(15),
820 TRIGGER_LINE(0),
821 TRIGGER_LINE(1),
822 TRIGGER_LINE(2),
823 TRIGGER_LINE(3),
824 TRIGGER_LINE(4),
825 TRIGGER_LINE(5),
826 TRIGGER_LINE(6),
827 TRIGGER_LINE(7),
828 NI_CtrSource(1),
829 NI_CtrInternalOutput(1),
830 NI_AI_StartTrigger,
831 NI_AI_ReferenceTrigger,
832 NI_AnalogComparisonEvent,
833 0, /* Termination */
834 }
835 },
836 {
837 .dest = NI_CtrGate(1),
838 .src = (int[]){
839 NI_PFI(0),
840 NI_PFI(1),
841 NI_PFI(2),
842 NI_PFI(3),
843 NI_PFI(4),
844 NI_PFI(5),
845 NI_PFI(6),
846 NI_PFI(7),
847 NI_PFI(8),
848 NI_PFI(9),
849 NI_PFI(10),
850 NI_PFI(11),
851 NI_PFI(12),
852 NI_PFI(13),
853 NI_PFI(14),
854 NI_PFI(15),
855 TRIGGER_LINE(0),
856 TRIGGER_LINE(1),
857 TRIGGER_LINE(2),
858 TRIGGER_LINE(3),
859 TRIGGER_LINE(4),
860 TRIGGER_LINE(5),
861 TRIGGER_LINE(6),
862 TRIGGER_LINE(7),
863 NI_CtrSource(0),
864 NI_CtrInternalOutput(0),
865 NI_AI_StartTrigger,
866 NI_AI_ReferenceTrigger,
867 NI_AnalogComparisonEvent,
868 0, /* Termination */
869 }
870 },
871 {
872 .dest = NI_CtrAux(0),
873 .src = (int[]){
874 NI_PFI(0),
875 NI_PFI(1),
876 NI_PFI(2),
877 NI_PFI(3),
878 NI_PFI(4),
879 NI_PFI(5),
880 NI_PFI(6),
881 NI_PFI(7),
882 NI_PFI(8),
883 NI_PFI(9),
884 NI_PFI(10),
885 NI_PFI(11),
886 NI_PFI(12),
887 NI_PFI(13),
888 NI_PFI(14),
889 NI_PFI(15),
890 TRIGGER_LINE(0),
891 TRIGGER_LINE(1),
892 TRIGGER_LINE(2),
893 TRIGGER_LINE(3),
894 TRIGGER_LINE(4),
895 TRIGGER_LINE(5),
896 TRIGGER_LINE(6),
897 TRIGGER_LINE(7),
898 NI_CtrSource(1),
899 NI_CtrGate(0),
900 NI_CtrInternalOutput(1),
901 NI_AI_StartTrigger,
902 NI_AI_ReferenceTrigger,
903 NI_AnalogComparisonEvent,
904 0, /* Termination */
905 }
906 },
907 {
908 .dest = NI_CtrAux(1),
909 .src = (int[]){
910 NI_PFI(0),
911 NI_PFI(1),
912 NI_PFI(2),
913 NI_PFI(3),
914 NI_PFI(4),
915 NI_PFI(5),
916 NI_PFI(6),
917 NI_PFI(7),
918 NI_PFI(8),
919 NI_PFI(9),
920 NI_PFI(10),
921 NI_PFI(11),
922 NI_PFI(12),
923 NI_PFI(13),
924 NI_PFI(14),
925 NI_PFI(15),
926 TRIGGER_LINE(0),
927 TRIGGER_LINE(1),
928 TRIGGER_LINE(2),
929 TRIGGER_LINE(3),
930 TRIGGER_LINE(4),
931 TRIGGER_LINE(5),
932 TRIGGER_LINE(6),
933 TRIGGER_LINE(7),
934 NI_CtrSource(0),
935 NI_CtrGate(0),
936 NI_CtrInternalOutput(0),
937 NI_AI_StartTrigger,
938 NI_AI_ReferenceTrigger,
939 NI_AnalogComparisonEvent,
940 0, /* Termination */
941 }
942 },
943 {
944 .dest = NI_CtrA(0),
945 .src = (int[]){
946 NI_PFI(0),
947 NI_PFI(1),
948 NI_PFI(2),
949 NI_PFI(3),
950 NI_PFI(4),
951 NI_PFI(5),
952 NI_PFI(6),
953 NI_PFI(7),
954 NI_PFI(8),
955 NI_PFI(9),
956 NI_PFI(10),
957 NI_PFI(11),
958 NI_PFI(12),
959 NI_PFI(13),
960 NI_PFI(14),
961 NI_PFI(15),
962 TRIGGER_LINE(0),
963 TRIGGER_LINE(1),
964 TRIGGER_LINE(2),
965 TRIGGER_LINE(3),
966 TRIGGER_LINE(4),
967 TRIGGER_LINE(5),
968 TRIGGER_LINE(6),
969 TRIGGER_LINE(7),
970 NI_AnalogComparisonEvent,
971 0, /* Termination */
972 }
973 },
974 {
975 .dest = NI_CtrA(1),
976 .src = (int[]){
977 NI_PFI(0),
978 NI_PFI(1),
979 NI_PFI(2),
980 NI_PFI(3),
981 NI_PFI(4),
982 NI_PFI(5),
983 NI_PFI(6),
984 NI_PFI(7),
985 NI_PFI(8),
986 NI_PFI(9),
987 NI_PFI(10),
988 NI_PFI(11),
989 NI_PFI(12),
990 NI_PFI(13),
991 NI_PFI(14),
992 NI_PFI(15),
993 TRIGGER_LINE(0),
994 TRIGGER_LINE(1),
995 TRIGGER_LINE(2),
996 TRIGGER_LINE(3),
997 TRIGGER_LINE(4),
998 TRIGGER_LINE(5),
999 TRIGGER_LINE(6),
1000 TRIGGER_LINE(7),
1001 NI_AnalogComparisonEvent,
1002 0, /* Termination */
1003 }
1004 },
1005 {
1006 .dest = NI_CtrB(0),
1007 .src = (int[]){
1008 NI_PFI(0),
1009 NI_PFI(1),
1010 NI_PFI(2),
1011 NI_PFI(3),
1012 NI_PFI(4),
1013 NI_PFI(5),
1014 NI_PFI(6),
1015 NI_PFI(7),
1016 NI_PFI(8),
1017 NI_PFI(9),
1018 NI_PFI(10),
1019 NI_PFI(11),
1020 NI_PFI(12),
1021 NI_PFI(13),
1022 NI_PFI(14),
1023 NI_PFI(15),
1024 TRIGGER_LINE(0),
1025 TRIGGER_LINE(1),
1026 TRIGGER_LINE(2),
1027 TRIGGER_LINE(3),
1028 TRIGGER_LINE(4),
1029 TRIGGER_LINE(5),
1030 TRIGGER_LINE(6),
1031 TRIGGER_LINE(7),
1032 NI_AnalogComparisonEvent,
1033 0, /* Termination */
1034 }
1035 },
1036 {
1037 .dest = NI_CtrB(1),
1038 .src = (int[]){
1039 NI_PFI(0),
1040 NI_PFI(1),
1041 NI_PFI(2),
1042 NI_PFI(3),
1043 NI_PFI(4),
1044 NI_PFI(5),
1045 NI_PFI(6),
1046 NI_PFI(7),
1047 NI_PFI(8),
1048 NI_PFI(9),
1049 NI_PFI(10),
1050 NI_PFI(11),
1051 NI_PFI(12),
1052 NI_PFI(13),
1053 NI_PFI(14),
1054 NI_PFI(15),
1055 TRIGGER_LINE(0),
1056 TRIGGER_LINE(1),
1057 TRIGGER_LINE(2),
1058 TRIGGER_LINE(3),
1059 TRIGGER_LINE(4),
1060 TRIGGER_LINE(5),
1061 TRIGGER_LINE(6),
1062 TRIGGER_LINE(7),
1063 NI_AnalogComparisonEvent,
1064 0, /* Termination */
1065 }
1066 },
1067 {
1068 .dest = NI_CtrZ(0),
1069 .src = (int[]){
1070 NI_PFI(0),
1071 NI_PFI(1),
1072 NI_PFI(2),
1073 NI_PFI(3),
1074 NI_PFI(4),
1075 NI_PFI(5),
1076 NI_PFI(6),
1077 NI_PFI(7),
1078 NI_PFI(8),
1079 NI_PFI(9),
1080 NI_PFI(10),
1081 NI_PFI(11),
1082 NI_PFI(12),
1083 NI_PFI(13),
1084 NI_PFI(14),
1085 NI_PFI(15),
1086 TRIGGER_LINE(0),
1087 TRIGGER_LINE(1),
1088 TRIGGER_LINE(2),
1089 TRIGGER_LINE(3),
1090 TRIGGER_LINE(4),
1091 TRIGGER_LINE(5),
1092 TRIGGER_LINE(6),
1093 TRIGGER_LINE(7),
1094 NI_AnalogComparisonEvent,
1095 0, /* Termination */
1096 }
1097 },
1098 {
1099 .dest = NI_CtrZ(1),
1100 .src = (int[]){
1101 NI_PFI(0),
1102 NI_PFI(1),
1103 NI_PFI(2),
1104 NI_PFI(3),
1105 NI_PFI(4),
1106 NI_PFI(5),
1107 NI_PFI(6),
1108 NI_PFI(7),
1109 NI_PFI(8),
1110 NI_PFI(9),
1111 NI_PFI(10),
1112 NI_PFI(11),
1113 NI_PFI(12),
1114 NI_PFI(13),
1115 NI_PFI(14),
1116 NI_PFI(15),
1117 TRIGGER_LINE(0),
1118 TRIGGER_LINE(1),
1119 TRIGGER_LINE(2),
1120 TRIGGER_LINE(3),
1121 TRIGGER_LINE(4),
1122 TRIGGER_LINE(5),
1123 TRIGGER_LINE(6),
1124 TRIGGER_LINE(7),
1125 NI_AnalogComparisonEvent,
1126 0, /* Termination */
1127 }
1128 },
1129 {
1130 .dest = NI_CtrArmStartTrigger(0),
1131 .src = (int[]){
1132 NI_PFI(0),
1133 NI_PFI(1),
1134 NI_PFI(2),
1135 NI_PFI(3),
1136 NI_PFI(4),
1137 NI_PFI(5),
1138 NI_PFI(6),
1139 NI_PFI(7),
1140 NI_PFI(8),
1141 NI_PFI(9),
1142 NI_PFI(10),
1143 NI_PFI(11),
1144 NI_PFI(12),
1145 NI_PFI(13),
1146 NI_PFI(14),
1147 NI_PFI(15),
1148 TRIGGER_LINE(0),
1149 TRIGGER_LINE(1),
1150 TRIGGER_LINE(2),
1151 TRIGGER_LINE(3),
1152 TRIGGER_LINE(4),
1153 TRIGGER_LINE(5),
1154 TRIGGER_LINE(6),
1155 TRIGGER_LINE(7),
1156 NI_CtrInternalOutput(1),
1157 NI_AI_StartTrigger,
1158 NI_AI_ReferenceTrigger,
1159 NI_AnalogComparisonEvent,
1160 0, /* Termination */
1161 }
1162 },
1163 {
1164 .dest = NI_CtrArmStartTrigger(1),
1165 .src = (int[]){
1166 NI_PFI(0),
1167 NI_PFI(1),
1168 NI_PFI(2),
1169 NI_PFI(3),
1170 NI_PFI(4),
1171 NI_PFI(5),
1172 NI_PFI(6),
1173 NI_PFI(7),
1174 NI_PFI(8),
1175 NI_PFI(9),
1176 NI_PFI(10),
1177 NI_PFI(11),
1178 NI_PFI(12),
1179 NI_PFI(13),
1180 NI_PFI(14),
1181 NI_PFI(15),
1182 TRIGGER_LINE(0),
1183 TRIGGER_LINE(1),
1184 TRIGGER_LINE(2),
1185 TRIGGER_LINE(3),
1186 TRIGGER_LINE(4),
1187 TRIGGER_LINE(5),
1188 TRIGGER_LINE(6),
1189 TRIGGER_LINE(7),
1190 NI_CtrInternalOutput(0),
1191 NI_AI_StartTrigger,
1192 NI_AI_ReferenceTrigger,
1193 NI_AnalogComparisonEvent,
1194 0, /* Termination */
1195 }
1196 },
1197 {
1198 .dest = NI_AI_SampleClock,
1199 .src = (int[]){
1200 NI_PFI(0),
1201 NI_PFI(1),
1202 NI_PFI(2),
1203 NI_PFI(3),
1204 NI_PFI(4),
1205 NI_PFI(5),
1206 NI_PFI(6),
1207 NI_PFI(7),
1208 NI_PFI(8),
1209 NI_PFI(9),
1210 NI_PFI(10),
1211 NI_PFI(11),
1212 NI_PFI(12),
1213 NI_PFI(13),
1214 NI_PFI(14),
1215 NI_PFI(15),
1216 TRIGGER_LINE(0),
1217 TRIGGER_LINE(1),
1218 TRIGGER_LINE(2),
1219 TRIGGER_LINE(3),
1220 TRIGGER_LINE(4),
1221 TRIGGER_LINE(5),
1222 TRIGGER_LINE(6),
1223 TRIGGER_LINE(7),
1224 NI_CtrInternalOutput(0),
1225 NI_CtrInternalOutput(1),
1226 NI_AI_SampleClockTimebase,
1227 NI_AnalogComparisonEvent,
1228 0, /* Termination */
1229 }
1230 },
1231 {
1232 .dest = NI_AI_SampleClockTimebase,
1233 .src = (int[]){
1234 NI_PFI(0),
1235 NI_PFI(1),
1236 NI_PFI(2),
1237 NI_PFI(3),
1238 NI_PFI(4),
1239 NI_PFI(5),
1240 NI_PFI(6),
1241 NI_PFI(7),
1242 NI_PFI(8),
1243 NI_PFI(9),
1244 NI_PFI(10),
1245 NI_PFI(11),
1246 NI_PFI(12),
1247 NI_PFI(13),
1248 NI_PFI(14),
1249 NI_PFI(15),
1250 TRIGGER_LINE(0),
1251 TRIGGER_LINE(1),
1252 TRIGGER_LINE(2),
1253 TRIGGER_LINE(3),
1254 TRIGGER_LINE(4),
1255 TRIGGER_LINE(5),
1256 TRIGGER_LINE(6),
1257 TRIGGER_LINE(7),
1258 PXI_Clk10,
1259 NI_20MHzTimebase,
1260 NI_100kHzTimebase,
1261 NI_AnalogComparisonEvent,
1262 0, /* Termination */
1263 }
1264 },
1265 {
1266 .dest = NI_AI_StartTrigger,
1267 .src = (int[]){
1268 NI_PFI(0),
1269 NI_PFI(1),
1270 NI_PFI(2),
1271 NI_PFI(3),
1272 NI_PFI(4),
1273 NI_PFI(5),
1274 NI_PFI(6),
1275 NI_PFI(7),
1276 NI_PFI(8),
1277 NI_PFI(9),
1278 NI_PFI(10),
1279 NI_PFI(11),
1280 NI_PFI(12),
1281 NI_PFI(13),
1282 NI_PFI(14),
1283 NI_PFI(15),
1284 TRIGGER_LINE(0),
1285 TRIGGER_LINE(1),
1286 TRIGGER_LINE(2),
1287 TRIGGER_LINE(3),
1288 TRIGGER_LINE(4),
1289 TRIGGER_LINE(5),
1290 TRIGGER_LINE(6),
1291 TRIGGER_LINE(7),
1292 NI_CtrInternalOutput(0),
1293 NI_CtrInternalOutput(1),
1294 NI_AnalogComparisonEvent,
1295 0, /* Termination */
1296 }
1297 },
1298 {
1299 .dest = NI_AI_ReferenceTrigger,
1300 .src = (int[]){
1301 NI_PFI(0),
1302 NI_PFI(1),
1303 NI_PFI(2),
1304 NI_PFI(3),
1305 NI_PFI(4),
1306 NI_PFI(5),
1307 NI_PFI(6),
1308 NI_PFI(7),
1309 NI_PFI(8),
1310 NI_PFI(9),
1311 NI_PFI(10),
1312 NI_PFI(11),
1313 NI_PFI(12),
1314 NI_PFI(13),
1315 NI_PFI(14),
1316 NI_PFI(15),
1317 TRIGGER_LINE(0),
1318 TRIGGER_LINE(1),
1319 TRIGGER_LINE(2),
1320 TRIGGER_LINE(3),
1321 TRIGGER_LINE(4),
1322 TRIGGER_LINE(5),
1323 TRIGGER_LINE(6),
1324 TRIGGER_LINE(7),
1325 NI_AnalogComparisonEvent,
1326 0, /* Termination */
1327 }
1328 },
1329 {
1330 .dest = NI_AI_ConvertClock,
1331 .src = (int[]){
1332 NI_PFI(0),
1333 NI_PFI(1),
1334 NI_PFI(2),
1335 NI_PFI(3),
1336 NI_PFI(4),
1337 NI_PFI(5),
1338 NI_PFI(6),
1339 NI_PFI(7),
1340 NI_PFI(8),
1341 NI_PFI(9),
1342 NI_PFI(10),
1343 NI_PFI(11),
1344 NI_PFI(12),
1345 NI_PFI(13),
1346 NI_PFI(14),
1347 NI_PFI(15),
1348 TRIGGER_LINE(0),
1349 TRIGGER_LINE(1),
1350 TRIGGER_LINE(2),
1351 TRIGGER_LINE(3),
1352 TRIGGER_LINE(4),
1353 TRIGGER_LINE(5),
1354 TRIGGER_LINE(6),
1355 TRIGGER_LINE(7),
1356 NI_CtrInternalOutput(0),
1357 NI_CtrInternalOutput(1),
1358 NI_AI_ConvertClockTimebase,
1359 NI_AnalogComparisonEvent,
1360 0, /* Termination */
1361 }
1362 },
1363 {
1364 .dest = NI_AI_ConvertClockTimebase,
1365 .src = (int[]){
1366 NI_AI_SampleClockTimebase,
1367 NI_20MHzTimebase,
1368 0, /* Termination */
1369 }
1370 },
1371 {
1372 .dest = NI_AI_PauseTrigger,
1373 .src = (int[]){
1374 NI_PFI(0),
1375 NI_PFI(1),
1376 NI_PFI(2),
1377 NI_PFI(3),
1378 NI_PFI(4),
1379 NI_PFI(5),
1380 NI_PFI(6),
1381 NI_PFI(7),
1382 NI_PFI(8),
1383 NI_PFI(9),
1384 NI_PFI(10),
1385 NI_PFI(11),
1386 NI_PFI(12),
1387 NI_PFI(13),
1388 NI_PFI(14),
1389 NI_PFI(15),
1390 TRIGGER_LINE(0),
1391 TRIGGER_LINE(1),
1392 TRIGGER_LINE(2),
1393 TRIGGER_LINE(3),
1394 TRIGGER_LINE(4),
1395 TRIGGER_LINE(5),
1396 TRIGGER_LINE(6),
1397 TRIGGER_LINE(7),
1398 NI_AnalogComparisonEvent,
1399 0, /* Termination */
1400 }
1401 },
1402 {
1403 .dest = NI_AO_SampleClock,
1404 .src = (int[]){
1405 NI_PFI(0),
1406 NI_PFI(1),
1407 NI_PFI(2),
1408 NI_PFI(3),
1409 NI_PFI(4),
1410 NI_PFI(5),
1411 NI_PFI(6),
1412 NI_PFI(7),
1413 NI_PFI(8),
1414 NI_PFI(9),
1415 NI_PFI(10),
1416 NI_PFI(11),
1417 NI_PFI(12),
1418 NI_PFI(13),
1419 NI_PFI(14),
1420 NI_PFI(15),
1421 TRIGGER_LINE(0),
1422 TRIGGER_LINE(1),
1423 TRIGGER_LINE(2),
1424 TRIGGER_LINE(3),
1425 TRIGGER_LINE(4),
1426 TRIGGER_LINE(5),
1427 TRIGGER_LINE(6),
1428 TRIGGER_LINE(7),
1429 NI_CtrInternalOutput(0),
1430 NI_CtrInternalOutput(1),
1431 NI_AO_SampleClockTimebase,
1432 NI_AnalogComparisonEvent,
1433 0, /* Termination */
1434 }
1435 },
1436 {
1437 .dest = NI_AO_SampleClockTimebase,
1438 .src = (int[]){
1439 NI_PFI(0),
1440 NI_PFI(1),
1441 NI_PFI(2),
1442 NI_PFI(3),
1443 NI_PFI(4),
1444 NI_PFI(5),
1445 NI_PFI(6),
1446 NI_PFI(7),
1447 NI_PFI(8),
1448 NI_PFI(9),
1449 NI_PFI(10),
1450 NI_PFI(11),
1451 NI_PFI(12),
1452 NI_PFI(13),
1453 NI_PFI(14),
1454 NI_PFI(15),
1455 TRIGGER_LINE(0),
1456 TRIGGER_LINE(1),
1457 TRIGGER_LINE(2),
1458 TRIGGER_LINE(3),
1459 TRIGGER_LINE(4),
1460 TRIGGER_LINE(5),
1461 TRIGGER_LINE(6),
1462 TRIGGER_LINE(7),
1463 PXI_Clk10,
1464 NI_20MHzTimebase,
1465 NI_100kHzTimebase,
1466 NI_AnalogComparisonEvent,
1467 0, /* Termination */
1468 }
1469 },
1470 {
1471 .dest = NI_AO_StartTrigger,
1472 .src = (int[]){
1473 NI_PFI(0),
1474 NI_PFI(1),
1475 NI_PFI(2),
1476 NI_PFI(3),
1477 NI_PFI(4),
1478 NI_PFI(5),
1479 NI_PFI(6),
1480 NI_PFI(7),
1481 NI_PFI(8),
1482 NI_PFI(9),
1483 NI_PFI(10),
1484 NI_PFI(11),
1485 NI_PFI(12),
1486 NI_PFI(13),
1487 NI_PFI(14),
1488 NI_PFI(15),
1489 TRIGGER_LINE(0),
1490 TRIGGER_LINE(1),
1491 TRIGGER_LINE(2),
1492 TRIGGER_LINE(3),
1493 TRIGGER_LINE(4),
1494 TRIGGER_LINE(5),
1495 TRIGGER_LINE(6),
1496 TRIGGER_LINE(7),
1497 NI_AI_StartTrigger,
1498 NI_AnalogComparisonEvent,
1499 0, /* Termination */
1500 }
1501 },
1502 {
1503 .dest = NI_AO_PauseTrigger,
1504 .src = (int[]){
1505 NI_PFI(0),
1506 NI_PFI(1),
1507 NI_PFI(2),
1508 NI_PFI(3),
1509 NI_PFI(4),
1510 NI_PFI(5),
1511 NI_PFI(6),
1512 NI_PFI(7),
1513 NI_PFI(8),
1514 NI_PFI(9),
1515 NI_PFI(10),
1516 NI_PFI(11),
1517 NI_PFI(12),
1518 NI_PFI(13),
1519 NI_PFI(14),
1520 NI_PFI(15),
1521 TRIGGER_LINE(0),
1522 TRIGGER_LINE(1),
1523 TRIGGER_LINE(2),
1524 TRIGGER_LINE(3),
1525 TRIGGER_LINE(4),
1526 TRIGGER_LINE(5),
1527 TRIGGER_LINE(6),
1528 TRIGGER_LINE(7),
1529 NI_AnalogComparisonEvent,
1530 0, /* Termination */
1531 }
1532 },
1533 {
1534 .dest = NI_DI_SampleClock,
1535 .src = (int[]){
1536 NI_PFI(0),
1537 NI_PFI(1),
1538 NI_PFI(2),
1539 NI_PFI(3),
1540 NI_PFI(4),
1541 NI_PFI(5),
1542 NI_PFI(6),
1543 NI_PFI(7),
1544 NI_PFI(8),
1545 NI_PFI(9),
1546 NI_PFI(10),
1547 NI_PFI(11),
1548 NI_PFI(12),
1549 NI_PFI(13),
1550 NI_PFI(14),
1551 NI_PFI(15),
1552 TRIGGER_LINE(0),
1553 TRIGGER_LINE(1),
1554 TRIGGER_LINE(2),
1555 TRIGGER_LINE(3),
1556 TRIGGER_LINE(4),
1557 TRIGGER_LINE(5),
1558 TRIGGER_LINE(6),
1559 TRIGGER_LINE(7),
1560 NI_CtrInternalOutput(0),
1561 NI_CtrInternalOutput(1),
1562 NI_AI_SampleClock,
1563 NI_AI_ConvertClock,
1564 NI_AO_SampleClock,
1565 NI_FrequencyOutput,
1566 NI_ChangeDetectionEvent,
1567 NI_AnalogComparisonEvent,
1568 0, /* Termination */
1569 }
1570 },
1571 {
1572 .dest = NI_DO_SampleClock,
1573 .src = (int[]){
1574 NI_PFI(0),
1575 NI_PFI(1),
1576 NI_PFI(2),
1577 NI_PFI(3),
1578 NI_PFI(4),
1579 NI_PFI(5),
1580 NI_PFI(6),
1581 NI_PFI(7),
1582 NI_PFI(8),
1583 NI_PFI(9),
1584 NI_PFI(10),
1585 NI_PFI(11),
1586 NI_PFI(12),
1587 NI_PFI(13),
1588 NI_PFI(14),
1589 NI_PFI(15),
1590 TRIGGER_LINE(0),
1591 TRIGGER_LINE(1),
1592 TRIGGER_LINE(2),
1593 TRIGGER_LINE(3),
1594 TRIGGER_LINE(4),
1595 TRIGGER_LINE(5),
1596 TRIGGER_LINE(6),
1597 TRIGGER_LINE(7),
1598 NI_CtrInternalOutput(0),
1599 NI_CtrInternalOutput(1),
1600 NI_AI_SampleClock,
1601 NI_AI_ConvertClock,
1602 NI_AO_SampleClock,
1603 NI_FrequencyOutput,
1604 NI_ChangeDetectionEvent,
1605 NI_AnalogComparisonEvent,
1606 0, /* Termination */
1607 }
1608 },
1609 { /* Termination of list */
1610 .dest = 0,
1611 },
1612 },
1613};
diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxi-6251.c b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxi-6251.c
new file mode 100644
index 000000000000..25db4b7363de
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxi-6251.c
@@ -0,0 +1,1655 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routing/ni_device_routes/pxi-6251.c
5 * List of valid routes for specific NI boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21/*
22 * The contents of this file are generated using the tools in
23 * comedi/drivers/ni_routing/tools
24 *
25 * Please use those tools to help maintain the contents of this file.
26 */
27
28#include "../ni_device_routes.h"
29#include "all.h"
30
31struct ni_device_routes ni_pxi_6251_device_routes = {
32 .device = "pxi-6251",
33 .routes = (struct ni_route_set[]){
34 {
35 .dest = NI_PFI(0),
36 .src = (int[]){
37 TRIGGER_LINE(0),
38 TRIGGER_LINE(1),
39 TRIGGER_LINE(2),
40 TRIGGER_LINE(3),
41 TRIGGER_LINE(4),
42 TRIGGER_LINE(5),
43 TRIGGER_LINE(6),
44 TRIGGER_LINE(7),
45 NI_CtrSource(0),
46 NI_CtrSource(1),
47 NI_CtrGate(0),
48 NI_CtrInternalOutput(0),
49 NI_CtrInternalOutput(1),
50 PXI_Star,
51 NI_AI_SampleClock,
52 NI_AI_StartTrigger,
53 NI_AI_ReferenceTrigger,
54 NI_AI_ConvertClock,
55 NI_AO_SampleClock,
56 NI_AO_StartTrigger,
57 NI_DI_SampleClock,
58 NI_DO_SampleClock,
59 NI_FrequencyOutput,
60 NI_ChangeDetectionEvent,
61 NI_AnalogComparisonEvent,
62 0, /* Termination */
63 }
64 },
65 {
66 .dest = NI_PFI(1),
67 .src = (int[]){
68 TRIGGER_LINE(0),
69 TRIGGER_LINE(1),
70 TRIGGER_LINE(2),
71 TRIGGER_LINE(3),
72 TRIGGER_LINE(4),
73 TRIGGER_LINE(5),
74 TRIGGER_LINE(6),
75 TRIGGER_LINE(7),
76 NI_CtrSource(0),
77 NI_CtrSource(1),
78 NI_CtrGate(0),
79 NI_CtrInternalOutput(0),
80 NI_CtrInternalOutput(1),
81 PXI_Star,
82 NI_AI_SampleClock,
83 NI_AI_StartTrigger,
84 NI_AI_ReferenceTrigger,
85 NI_AI_ConvertClock,
86 NI_AO_SampleClock,
87 NI_AO_StartTrigger,
88 NI_DI_SampleClock,
89 NI_DO_SampleClock,
90 NI_FrequencyOutput,
91 NI_ChangeDetectionEvent,
92 NI_AnalogComparisonEvent,
93 0, /* Termination */
94 }
95 },
96 {
97 .dest = NI_PFI(2),
98 .src = (int[]){
99 TRIGGER_LINE(0),
100 TRIGGER_LINE(1),
101 TRIGGER_LINE(2),
102 TRIGGER_LINE(3),
103 TRIGGER_LINE(4),
104 TRIGGER_LINE(5),
105 TRIGGER_LINE(6),
106 TRIGGER_LINE(7),
107 NI_CtrSource(0),
108 NI_CtrSource(1),
109 NI_CtrGate(0),
110 NI_CtrInternalOutput(0),
111 NI_CtrInternalOutput(1),
112 PXI_Star,
113 NI_AI_SampleClock,
114 NI_AI_StartTrigger,
115 NI_AI_ReferenceTrigger,
116 NI_AI_ConvertClock,
117 NI_AO_SampleClock,
118 NI_AO_StartTrigger,
119 NI_DI_SampleClock,
120 NI_DO_SampleClock,
121 NI_FrequencyOutput,
122 NI_ChangeDetectionEvent,
123 NI_AnalogComparisonEvent,
124 0, /* Termination */
125 }
126 },
127 {
128 .dest = NI_PFI(3),
129 .src = (int[]){
130 TRIGGER_LINE(0),
131 TRIGGER_LINE(1),
132 TRIGGER_LINE(2),
133 TRIGGER_LINE(3),
134 TRIGGER_LINE(4),
135 TRIGGER_LINE(5),
136 TRIGGER_LINE(6),
137 TRIGGER_LINE(7),
138 NI_CtrSource(0),
139 NI_CtrSource(1),
140 NI_CtrGate(0),
141 NI_CtrInternalOutput(0),
142 NI_CtrInternalOutput(1),
143 PXI_Star,
144 NI_AI_SampleClock,
145 NI_AI_StartTrigger,
146 NI_AI_ReferenceTrigger,
147 NI_AI_ConvertClock,
148 NI_AO_SampleClock,
149 NI_AO_StartTrigger,
150 NI_DI_SampleClock,
151 NI_DO_SampleClock,
152 NI_FrequencyOutput,
153 NI_ChangeDetectionEvent,
154 NI_AnalogComparisonEvent,
155 0, /* Termination */
156 }
157 },
158 {
159 .dest = NI_PFI(4),
160 .src = (int[]){
161 TRIGGER_LINE(0),
162 TRIGGER_LINE(1),
163 TRIGGER_LINE(2),
164 TRIGGER_LINE(3),
165 TRIGGER_LINE(4),
166 TRIGGER_LINE(5),
167 TRIGGER_LINE(6),
168 TRIGGER_LINE(7),
169 NI_CtrSource(0),
170 NI_CtrSource(1),
171 NI_CtrGate(0),
172 NI_CtrInternalOutput(0),
173 NI_CtrInternalOutput(1),
174 PXI_Star,
175 NI_AI_SampleClock,
176 NI_AI_StartTrigger,
177 NI_AI_ReferenceTrigger,
178 NI_AI_ConvertClock,
179 NI_AO_SampleClock,
180 NI_AO_StartTrigger,
181 NI_DI_SampleClock,
182 NI_DO_SampleClock,
183 NI_FrequencyOutput,
184 NI_ChangeDetectionEvent,
185 NI_AnalogComparisonEvent,
186 0, /* Termination */
187 }
188 },
189 {
190 .dest = NI_PFI(5),
191 .src = (int[]){
192 TRIGGER_LINE(0),
193 TRIGGER_LINE(1),
194 TRIGGER_LINE(2),
195 TRIGGER_LINE(3),
196 TRIGGER_LINE(4),
197 TRIGGER_LINE(5),
198 TRIGGER_LINE(6),
199 TRIGGER_LINE(7),
200 NI_CtrSource(0),
201 NI_CtrSource(1),
202 NI_CtrGate(0),
203 NI_CtrInternalOutput(0),
204 NI_CtrInternalOutput(1),
205 PXI_Star,
206 NI_AI_SampleClock,
207 NI_AI_StartTrigger,
208 NI_AI_ReferenceTrigger,
209 NI_AI_ConvertClock,
210 NI_AO_SampleClock,
211 NI_AO_StartTrigger,
212 NI_DI_SampleClock,
213 NI_DO_SampleClock,
214 NI_FrequencyOutput,
215 NI_ChangeDetectionEvent,
216 NI_AnalogComparisonEvent,
217 0, /* Termination */
218 }
219 },
220 {
221 .dest = NI_PFI(6),
222 .src = (int[]){
223 TRIGGER_LINE(0),
224 TRIGGER_LINE(1),
225 TRIGGER_LINE(2),
226 TRIGGER_LINE(3),
227 TRIGGER_LINE(4),
228 TRIGGER_LINE(5),
229 TRIGGER_LINE(6),
230 TRIGGER_LINE(7),
231 NI_CtrSource(0),
232 NI_CtrSource(1),
233 NI_CtrGate(0),
234 NI_CtrInternalOutput(0),
235 NI_CtrInternalOutput(1),
236 PXI_Star,
237 NI_AI_SampleClock,
238 NI_AI_StartTrigger,
239 NI_AI_ReferenceTrigger,
240 NI_AI_ConvertClock,
241 NI_AO_SampleClock,
242 NI_AO_StartTrigger,
243 NI_DI_SampleClock,
244 NI_DO_SampleClock,
245 NI_FrequencyOutput,
246 NI_ChangeDetectionEvent,
247 NI_AnalogComparisonEvent,
248 0, /* Termination */
249 }
250 },
251 {
252 .dest = NI_PFI(7),
253 .src = (int[]){
254 TRIGGER_LINE(0),
255 TRIGGER_LINE(1),
256 TRIGGER_LINE(2),
257 TRIGGER_LINE(3),
258 TRIGGER_LINE(4),
259 TRIGGER_LINE(5),
260 TRIGGER_LINE(6),
261 TRIGGER_LINE(7),
262 NI_CtrSource(0),
263 NI_CtrSource(1),
264 NI_CtrGate(0),
265 NI_CtrInternalOutput(0),
266 NI_CtrInternalOutput(1),
267 PXI_Star,
268 NI_AI_SampleClock,
269 NI_AI_StartTrigger,
270 NI_AI_ReferenceTrigger,
271 NI_AI_ConvertClock,
272 NI_AO_SampleClock,
273 NI_AO_StartTrigger,
274 NI_DI_SampleClock,
275 NI_DO_SampleClock,
276 NI_FrequencyOutput,
277 NI_ChangeDetectionEvent,
278 NI_AnalogComparisonEvent,
279 0, /* Termination */
280 }
281 },
282 {
283 .dest = NI_PFI(8),
284 .src = (int[]){
285 TRIGGER_LINE(0),
286 TRIGGER_LINE(1),
287 TRIGGER_LINE(2),
288 TRIGGER_LINE(3),
289 TRIGGER_LINE(4),
290 TRIGGER_LINE(5),
291 TRIGGER_LINE(6),
292 TRIGGER_LINE(7),
293 NI_CtrSource(0),
294 NI_CtrSource(1),
295 NI_CtrGate(0),
296 NI_CtrInternalOutput(0),
297 NI_CtrInternalOutput(1),
298 PXI_Star,
299 NI_AI_SampleClock,
300 NI_AI_StartTrigger,
301 NI_AI_ReferenceTrigger,
302 NI_AI_ConvertClock,
303 NI_AO_SampleClock,
304 NI_AO_StartTrigger,
305 NI_DI_SampleClock,
306 NI_DO_SampleClock,
307 NI_FrequencyOutput,
308 NI_ChangeDetectionEvent,
309 NI_AnalogComparisonEvent,
310 0, /* Termination */
311 }
312 },
313 {
314 .dest = NI_PFI(9),
315 .src = (int[]){
316 TRIGGER_LINE(0),
317 TRIGGER_LINE(1),
318 TRIGGER_LINE(2),
319 TRIGGER_LINE(3),
320 TRIGGER_LINE(4),
321 TRIGGER_LINE(5),
322 TRIGGER_LINE(6),
323 TRIGGER_LINE(7),
324 NI_CtrSource(0),
325 NI_CtrSource(1),
326 NI_CtrGate(0),
327 NI_CtrInternalOutput(0),
328 NI_CtrInternalOutput(1),
329 PXI_Star,
330 NI_AI_SampleClock,
331 NI_AI_StartTrigger,
332 NI_AI_ReferenceTrigger,
333 NI_AI_ConvertClock,
334 NI_AO_SampleClock,
335 NI_AO_StartTrigger,
336 NI_DI_SampleClock,
337 NI_DO_SampleClock,
338 NI_FrequencyOutput,
339 NI_ChangeDetectionEvent,
340 NI_AnalogComparisonEvent,
341 0, /* Termination */
342 }
343 },
344 {
345 .dest = NI_PFI(10),
346 .src = (int[]){
347 TRIGGER_LINE(0),
348 TRIGGER_LINE(1),
349 TRIGGER_LINE(2),
350 TRIGGER_LINE(3),
351 TRIGGER_LINE(4),
352 TRIGGER_LINE(5),
353 TRIGGER_LINE(6),
354 TRIGGER_LINE(7),
355 NI_CtrSource(0),
356 NI_CtrSource(1),
357 NI_CtrGate(0),
358 NI_CtrInternalOutput(0),
359 NI_CtrInternalOutput(1),
360 PXI_Star,
361 NI_AI_SampleClock,
362 NI_AI_StartTrigger,
363 NI_AI_ReferenceTrigger,
364 NI_AI_ConvertClock,
365 NI_AO_SampleClock,
366 NI_AO_StartTrigger,
367 NI_DI_SampleClock,
368 NI_DO_SampleClock,
369 NI_FrequencyOutput,
370 NI_ChangeDetectionEvent,
371 NI_AnalogComparisonEvent,
372 0, /* Termination */
373 }
374 },
375 {
376 .dest = NI_PFI(11),
377 .src = (int[]){
378 TRIGGER_LINE(0),
379 TRIGGER_LINE(1),
380 TRIGGER_LINE(2),
381 TRIGGER_LINE(3),
382 TRIGGER_LINE(4),
383 TRIGGER_LINE(5),
384 TRIGGER_LINE(6),
385 TRIGGER_LINE(7),
386 NI_CtrSource(0),
387 NI_CtrSource(1),
388 NI_CtrGate(0),
389 NI_CtrInternalOutput(0),
390 NI_CtrInternalOutput(1),
391 PXI_Star,
392 NI_AI_SampleClock,
393 NI_AI_StartTrigger,
394 NI_AI_ReferenceTrigger,
395 NI_AI_ConvertClock,
396 NI_AO_SampleClock,
397 NI_AO_StartTrigger,
398 NI_DI_SampleClock,
399 NI_DO_SampleClock,
400 NI_FrequencyOutput,
401 NI_ChangeDetectionEvent,
402 NI_AnalogComparisonEvent,
403 0, /* Termination */
404 }
405 },
406 {
407 .dest = NI_PFI(12),
408 .src = (int[]){
409 TRIGGER_LINE(0),
410 TRIGGER_LINE(1),
411 TRIGGER_LINE(2),
412 TRIGGER_LINE(3),
413 TRIGGER_LINE(4),
414 TRIGGER_LINE(5),
415 TRIGGER_LINE(6),
416 TRIGGER_LINE(7),
417 NI_CtrSource(0),
418 NI_CtrSource(1),
419 NI_CtrGate(0),
420 NI_CtrInternalOutput(0),
421 NI_CtrInternalOutput(1),
422 PXI_Star,
423 NI_AI_SampleClock,
424 NI_AI_StartTrigger,
425 NI_AI_ReferenceTrigger,
426 NI_AI_ConvertClock,
427 NI_AO_SampleClock,
428 NI_AO_StartTrigger,
429 NI_DI_SampleClock,
430 NI_DO_SampleClock,
431 NI_FrequencyOutput,
432 NI_ChangeDetectionEvent,
433 NI_AnalogComparisonEvent,
434 0, /* Termination */
435 }
436 },
437 {
438 .dest = NI_PFI(13),
439 .src = (int[]){
440 TRIGGER_LINE(0),
441 TRIGGER_LINE(1),
442 TRIGGER_LINE(2),
443 TRIGGER_LINE(3),
444 TRIGGER_LINE(4),
445 TRIGGER_LINE(5),
446 TRIGGER_LINE(6),
447 TRIGGER_LINE(7),
448 NI_CtrSource(0),
449 NI_CtrSource(1),
450 NI_CtrGate(0),
451 NI_CtrInternalOutput(0),
452 NI_CtrInternalOutput(1),
453 PXI_Star,
454 NI_AI_SampleClock,
455 NI_AI_StartTrigger,
456 NI_AI_ReferenceTrigger,
457 NI_AI_ConvertClock,
458 NI_AO_SampleClock,
459 NI_AO_StartTrigger,
460 NI_DI_SampleClock,
461 NI_DO_SampleClock,
462 NI_FrequencyOutput,
463 NI_ChangeDetectionEvent,
464 NI_AnalogComparisonEvent,
465 0, /* Termination */
466 }
467 },
468 {
469 .dest = NI_PFI(14),
470 .src = (int[]){
471 TRIGGER_LINE(0),
472 TRIGGER_LINE(1),
473 TRIGGER_LINE(2),
474 TRIGGER_LINE(3),
475 TRIGGER_LINE(4),
476 TRIGGER_LINE(5),
477 TRIGGER_LINE(6),
478 TRIGGER_LINE(7),
479 NI_CtrSource(0),
480 NI_CtrSource(1),
481 NI_CtrGate(0),
482 NI_CtrInternalOutput(0),
483 NI_CtrInternalOutput(1),
484 PXI_Star,
485 NI_AI_SampleClock,
486 NI_AI_StartTrigger,
487 NI_AI_ReferenceTrigger,
488 NI_AI_ConvertClock,
489 NI_AO_SampleClock,
490 NI_AO_StartTrigger,
491 NI_DI_SampleClock,
492 NI_DO_SampleClock,
493 NI_FrequencyOutput,
494 NI_ChangeDetectionEvent,
495 NI_AnalogComparisonEvent,
496 0, /* Termination */
497 }
498 },
499 {
500 .dest = NI_PFI(15),
501 .src = (int[]){
502 TRIGGER_LINE(0),
503 TRIGGER_LINE(1),
504 TRIGGER_LINE(2),
505 TRIGGER_LINE(3),
506 TRIGGER_LINE(4),
507 TRIGGER_LINE(5),
508 TRIGGER_LINE(6),
509 TRIGGER_LINE(7),
510 NI_CtrSource(0),
511 NI_CtrSource(1),
512 NI_CtrGate(0),
513 NI_CtrInternalOutput(0),
514 NI_CtrInternalOutput(1),
515 PXI_Star,
516 NI_AI_SampleClock,
517 NI_AI_StartTrigger,
518 NI_AI_ReferenceTrigger,
519 NI_AI_ConvertClock,
520 NI_AO_SampleClock,
521 NI_AO_StartTrigger,
522 NI_DI_SampleClock,
523 NI_DO_SampleClock,
524 NI_FrequencyOutput,
525 NI_ChangeDetectionEvent,
526 NI_AnalogComparisonEvent,
527 0, /* Termination */
528 }
529 },
530 {
531 .dest = TRIGGER_LINE(0),
532 .src = (int[]){
533 NI_PFI(0),
534 NI_PFI(1),
535 NI_PFI(2),
536 NI_PFI(3),
537 NI_PFI(4),
538 NI_PFI(5),
539 NI_CtrSource(0),
540 NI_CtrSource(1),
541 NI_CtrGate(0),
542 NI_CtrInternalOutput(0),
543 NI_CtrInternalOutput(1),
544 NI_AI_SampleClock,
545 NI_AI_StartTrigger,
546 NI_AI_ReferenceTrigger,
547 NI_AI_ConvertClock,
548 NI_AO_SampleClock,
549 NI_AO_StartTrigger,
550 NI_10MHzRefClock,
551 NI_FrequencyOutput,
552 NI_ChangeDetectionEvent,
553 NI_AnalogComparisonEvent,
554 0, /* Termination */
555 }
556 },
557 {
558 .dest = TRIGGER_LINE(1),
559 .src = (int[]){
560 NI_PFI(0),
561 NI_PFI(1),
562 NI_PFI(2),
563 NI_PFI(3),
564 NI_PFI(4),
565 NI_PFI(5),
566 NI_CtrSource(0),
567 NI_CtrSource(1),
568 NI_CtrGate(0),
569 NI_CtrInternalOutput(0),
570 NI_CtrInternalOutput(1),
571 NI_AI_SampleClock,
572 NI_AI_StartTrigger,
573 NI_AI_ReferenceTrigger,
574 NI_AI_ConvertClock,
575 NI_AO_SampleClock,
576 NI_AO_StartTrigger,
577 NI_10MHzRefClock,
578 NI_FrequencyOutput,
579 NI_ChangeDetectionEvent,
580 NI_AnalogComparisonEvent,
581 0, /* Termination */
582 }
583 },
584 {
585 .dest = TRIGGER_LINE(2),
586 .src = (int[]){
587 NI_PFI(0),
588 NI_PFI(1),
589 NI_PFI(2),
590 NI_PFI(3),
591 NI_PFI(4),
592 NI_PFI(5),
593 NI_CtrSource(0),
594 NI_CtrSource(1),
595 NI_CtrGate(0),
596 NI_CtrInternalOutput(0),
597 NI_CtrInternalOutput(1),
598 NI_AI_SampleClock,
599 NI_AI_StartTrigger,
600 NI_AI_ReferenceTrigger,
601 NI_AI_ConvertClock,
602 NI_AO_SampleClock,
603 NI_AO_StartTrigger,
604 NI_10MHzRefClock,
605 NI_FrequencyOutput,
606 NI_ChangeDetectionEvent,
607 NI_AnalogComparisonEvent,
608 0, /* Termination */
609 }
610 },
611 {
612 .dest = TRIGGER_LINE(3),
613 .src = (int[]){
614 NI_PFI(0),
615 NI_PFI(1),
616 NI_PFI(2),
617 NI_PFI(3),
618 NI_PFI(4),
619 NI_PFI(5),
620 NI_CtrSource(0),
621 NI_CtrSource(1),
622 NI_CtrGate(0),
623 NI_CtrInternalOutput(0),
624 NI_CtrInternalOutput(1),
625 NI_AI_SampleClock,
626 NI_AI_StartTrigger,
627 NI_AI_ReferenceTrigger,
628 NI_AI_ConvertClock,
629 NI_AO_SampleClock,
630 NI_AO_StartTrigger,
631 NI_10MHzRefClock,
632 NI_FrequencyOutput,
633 NI_ChangeDetectionEvent,
634 NI_AnalogComparisonEvent,
635 0, /* Termination */
636 }
637 },
638 {
639 .dest = TRIGGER_LINE(4),
640 .src = (int[]){
641 NI_PFI(0),
642 NI_PFI(1),
643 NI_PFI(2),
644 NI_PFI(3),
645 NI_PFI(4),
646 NI_PFI(5),
647 NI_CtrSource(0),
648 NI_CtrSource(1),
649 NI_CtrGate(0),
650 NI_CtrInternalOutput(0),
651 NI_CtrInternalOutput(1),
652 NI_AI_SampleClock,
653 NI_AI_StartTrigger,
654 NI_AI_ReferenceTrigger,
655 NI_AI_ConvertClock,
656 NI_AO_SampleClock,
657 NI_AO_StartTrigger,
658 NI_10MHzRefClock,
659 NI_FrequencyOutput,
660 NI_ChangeDetectionEvent,
661 NI_AnalogComparisonEvent,
662 0, /* Termination */
663 }
664 },
665 {
666 .dest = TRIGGER_LINE(5),
667 .src = (int[]){
668 NI_PFI(0),
669 NI_PFI(1),
670 NI_PFI(2),
671 NI_PFI(3),
672 NI_PFI(4),
673 NI_PFI(5),
674 NI_CtrSource(0),
675 NI_CtrSource(1),
676 NI_CtrGate(0),
677 NI_CtrInternalOutput(0),
678 NI_CtrInternalOutput(1),
679 NI_AI_SampleClock,
680 NI_AI_StartTrigger,
681 NI_AI_ReferenceTrigger,
682 NI_AI_ConvertClock,
683 NI_AO_SampleClock,
684 NI_AO_StartTrigger,
685 NI_10MHzRefClock,
686 NI_FrequencyOutput,
687 NI_ChangeDetectionEvent,
688 NI_AnalogComparisonEvent,
689 0, /* Termination */
690 }
691 },
692 {
693 .dest = TRIGGER_LINE(6),
694 .src = (int[]){
695 NI_PFI(0),
696 NI_PFI(1),
697 NI_PFI(2),
698 NI_PFI(3),
699 NI_PFI(4),
700 NI_PFI(5),
701 NI_CtrSource(0),
702 NI_CtrSource(1),
703 NI_CtrGate(0),
704 NI_CtrInternalOutput(0),
705 NI_CtrInternalOutput(1),
706 NI_AI_SampleClock,
707 NI_AI_StartTrigger,
708 NI_AI_ReferenceTrigger,
709 NI_AI_ConvertClock,
710 NI_AO_SampleClock,
711 NI_AO_StartTrigger,
712 NI_10MHzRefClock,
713 NI_FrequencyOutput,
714 NI_ChangeDetectionEvent,
715 NI_AnalogComparisonEvent,
716 0, /* Termination */
717 }
718 },
719 {
720 .dest = TRIGGER_LINE(7),
721 .src = (int[]){
722 NI_PFI(0),
723 NI_PFI(1),
724 NI_PFI(2),
725 NI_PFI(3),
726 NI_PFI(4),
727 NI_PFI(5),
728 NI_CtrSource(0),
729 NI_CtrSource(1),
730 NI_CtrGate(0),
731 NI_CtrInternalOutput(0),
732 NI_CtrInternalOutput(1),
733 NI_AI_SampleClock,
734 NI_AI_StartTrigger,
735 NI_AI_ReferenceTrigger,
736 NI_AI_ConvertClock,
737 NI_AO_SampleClock,
738 NI_AO_StartTrigger,
739 NI_10MHzRefClock,
740 NI_FrequencyOutput,
741 NI_ChangeDetectionEvent,
742 NI_AnalogComparisonEvent,
743 0, /* Termination */
744 }
745 },
746 {
747 .dest = NI_CtrSource(0),
748 .src = (int[]){
749 NI_PFI(0),
750 NI_PFI(1),
751 NI_PFI(2),
752 NI_PFI(3),
753 NI_PFI(4),
754 NI_PFI(5),
755 NI_PFI(6),
756 NI_PFI(7),
757 NI_PFI(8),
758 NI_PFI(9),
759 NI_PFI(10),
760 NI_PFI(11),
761 NI_PFI(12),
762 NI_PFI(13),
763 NI_PFI(14),
764 NI_PFI(15),
765 TRIGGER_LINE(0),
766 TRIGGER_LINE(1),
767 TRIGGER_LINE(2),
768 TRIGGER_LINE(3),
769 TRIGGER_LINE(4),
770 TRIGGER_LINE(5),
771 TRIGGER_LINE(6),
772 TRIGGER_LINE(7),
773 PXI_Star,
774 PXI_Clk10,
775 NI_20MHzTimebase,
776 NI_80MHzTimebase,
777 NI_100kHzTimebase,
778 NI_AnalogComparisonEvent,
779 0, /* Termination */
780 }
781 },
782 {
783 .dest = NI_CtrSource(1),
784 .src = (int[]){
785 NI_PFI(0),
786 NI_PFI(1),
787 NI_PFI(2),
788 NI_PFI(3),
789 NI_PFI(4),
790 NI_PFI(5),
791 NI_PFI(6),
792 NI_PFI(7),
793 NI_PFI(8),
794 NI_PFI(9),
795 NI_PFI(10),
796 NI_PFI(11),
797 NI_PFI(12),
798 NI_PFI(13),
799 NI_PFI(14),
800 NI_PFI(15),
801 TRIGGER_LINE(0),
802 TRIGGER_LINE(1),
803 TRIGGER_LINE(2),
804 TRIGGER_LINE(3),
805 TRIGGER_LINE(4),
806 TRIGGER_LINE(5),
807 TRIGGER_LINE(6),
808 TRIGGER_LINE(7),
809 NI_CtrGate(0),
810 PXI_Star,
811 PXI_Clk10,
812 NI_20MHzTimebase,
813 NI_80MHzTimebase,
814 NI_100kHzTimebase,
815 NI_AnalogComparisonEvent,
816 0, /* Termination */
817 }
818 },
819 {
820 .dest = NI_CtrGate(0),
821 .src = (int[]){
822 NI_PFI(0),
823 NI_PFI(1),
824 NI_PFI(2),
825 NI_PFI(3),
826 NI_PFI(4),
827 NI_PFI(5),
828 NI_PFI(6),
829 NI_PFI(7),
830 NI_PFI(8),
831 NI_PFI(9),
832 NI_PFI(10),
833 NI_PFI(11),
834 NI_PFI(12),
835 NI_PFI(13),
836 NI_PFI(14),
837 NI_PFI(15),
838 TRIGGER_LINE(0),
839 TRIGGER_LINE(1),
840 TRIGGER_LINE(2),
841 TRIGGER_LINE(3),
842 TRIGGER_LINE(4),
843 TRIGGER_LINE(5),
844 TRIGGER_LINE(6),
845 TRIGGER_LINE(7),
846 NI_CtrSource(1),
847 NI_CtrInternalOutput(1),
848 PXI_Star,
849 NI_AI_StartTrigger,
850 NI_AI_ReferenceTrigger,
851 NI_AnalogComparisonEvent,
852 0, /* Termination */
853 }
854 },
855 {
856 .dest = NI_CtrGate(1),
857 .src = (int[]){
858 NI_PFI(0),
859 NI_PFI(1),
860 NI_PFI(2),
861 NI_PFI(3),
862 NI_PFI(4),
863 NI_PFI(5),
864 NI_PFI(6),
865 NI_PFI(7),
866 NI_PFI(8),
867 NI_PFI(9),
868 NI_PFI(10),
869 NI_PFI(11),
870 NI_PFI(12),
871 NI_PFI(13),
872 NI_PFI(14),
873 NI_PFI(15),
874 TRIGGER_LINE(0),
875 TRIGGER_LINE(1),
876 TRIGGER_LINE(2),
877 TRIGGER_LINE(3),
878 TRIGGER_LINE(4),
879 TRIGGER_LINE(5),
880 TRIGGER_LINE(6),
881 TRIGGER_LINE(7),
882 NI_CtrSource(0),
883 NI_CtrInternalOutput(0),
884 PXI_Star,
885 NI_AI_StartTrigger,
886 NI_AI_ReferenceTrigger,
887 NI_AnalogComparisonEvent,
888 0, /* Termination */
889 }
890 },
891 {
892 .dest = NI_CtrAux(0),
893 .src = (int[]){
894 NI_PFI(0),
895 NI_PFI(1),
896 NI_PFI(2),
897 NI_PFI(3),
898 NI_PFI(4),
899 NI_PFI(5),
900 NI_PFI(6),
901 NI_PFI(7),
902 NI_PFI(8),
903 NI_PFI(9),
904 NI_PFI(10),
905 NI_PFI(11),
906 NI_PFI(12),
907 NI_PFI(13),
908 NI_PFI(14),
909 NI_PFI(15),
910 TRIGGER_LINE(0),
911 TRIGGER_LINE(1),
912 TRIGGER_LINE(2),
913 TRIGGER_LINE(3),
914 TRIGGER_LINE(4),
915 TRIGGER_LINE(5),
916 TRIGGER_LINE(6),
917 TRIGGER_LINE(7),
918 NI_CtrSource(1),
919 NI_CtrGate(0),
920 NI_CtrInternalOutput(1),
921 PXI_Star,
922 NI_AI_StartTrigger,
923 NI_AI_ReferenceTrigger,
924 NI_AnalogComparisonEvent,
925 0, /* Termination */
926 }
927 },
928 {
929 .dest = NI_CtrAux(1),
930 .src = (int[]){
931 NI_PFI(0),
932 NI_PFI(1),
933 NI_PFI(2),
934 NI_PFI(3),
935 NI_PFI(4),
936 NI_PFI(5),
937 NI_PFI(6),
938 NI_PFI(7),
939 NI_PFI(8),
940 NI_PFI(9),
941 NI_PFI(10),
942 NI_PFI(11),
943 NI_PFI(12),
944 NI_PFI(13),
945 NI_PFI(14),
946 NI_PFI(15),
947 TRIGGER_LINE(0),
948 TRIGGER_LINE(1),
949 TRIGGER_LINE(2),
950 TRIGGER_LINE(3),
951 TRIGGER_LINE(4),
952 TRIGGER_LINE(5),
953 TRIGGER_LINE(6),
954 TRIGGER_LINE(7),
955 NI_CtrSource(0),
956 NI_CtrGate(0),
957 NI_CtrInternalOutput(0),
958 PXI_Star,
959 NI_AI_StartTrigger,
960 NI_AI_ReferenceTrigger,
961 NI_AnalogComparisonEvent,
962 0, /* Termination */
963 }
964 },
965 {
966 .dest = NI_CtrA(0),
967 .src = (int[]){
968 NI_PFI(0),
969 NI_PFI(1),
970 NI_PFI(2),
971 NI_PFI(3),
972 NI_PFI(4),
973 NI_PFI(5),
974 NI_PFI(6),
975 NI_PFI(7),
976 NI_PFI(8),
977 NI_PFI(9),
978 NI_PFI(10),
979 NI_PFI(11),
980 NI_PFI(12),
981 NI_PFI(13),
982 NI_PFI(14),
983 NI_PFI(15),
984 TRIGGER_LINE(0),
985 TRIGGER_LINE(1),
986 TRIGGER_LINE(2),
987 TRIGGER_LINE(3),
988 TRIGGER_LINE(4),
989 TRIGGER_LINE(5),
990 TRIGGER_LINE(6),
991 TRIGGER_LINE(7),
992 PXI_Star,
993 NI_AnalogComparisonEvent,
994 0, /* Termination */
995 }
996 },
997 {
998 .dest = NI_CtrA(1),
999 .src = (int[]){
1000 NI_PFI(0),
1001 NI_PFI(1),
1002 NI_PFI(2),
1003 NI_PFI(3),
1004 NI_PFI(4),
1005 NI_PFI(5),
1006 NI_PFI(6),
1007 NI_PFI(7),
1008 NI_PFI(8),
1009 NI_PFI(9),
1010 NI_PFI(10),
1011 NI_PFI(11),
1012 NI_PFI(12),
1013 NI_PFI(13),
1014 NI_PFI(14),
1015 NI_PFI(15),
1016 TRIGGER_LINE(0),
1017 TRIGGER_LINE(1),
1018 TRIGGER_LINE(2),
1019 TRIGGER_LINE(3),
1020 TRIGGER_LINE(4),
1021 TRIGGER_LINE(5),
1022 TRIGGER_LINE(6),
1023 TRIGGER_LINE(7),
1024 PXI_Star,
1025 NI_AnalogComparisonEvent,
1026 0, /* Termination */
1027 }
1028 },
1029 {
1030 .dest = NI_CtrB(0),
1031 .src = (int[]){
1032 NI_PFI(0),
1033 NI_PFI(1),
1034 NI_PFI(2),
1035 NI_PFI(3),
1036 NI_PFI(4),
1037 NI_PFI(5),
1038 NI_PFI(6),
1039 NI_PFI(7),
1040 NI_PFI(8),
1041 NI_PFI(9),
1042 NI_PFI(10),
1043 NI_PFI(11),
1044 NI_PFI(12),
1045 NI_PFI(13),
1046 NI_PFI(14),
1047 NI_PFI(15),
1048 TRIGGER_LINE(0),
1049 TRIGGER_LINE(1),
1050 TRIGGER_LINE(2),
1051 TRIGGER_LINE(3),
1052 TRIGGER_LINE(4),
1053 TRIGGER_LINE(5),
1054 TRIGGER_LINE(6),
1055 TRIGGER_LINE(7),
1056 PXI_Star,
1057 NI_AnalogComparisonEvent,
1058 0, /* Termination */
1059 }
1060 },
1061 {
1062 .dest = NI_CtrB(1),
1063 .src = (int[]){
1064 NI_PFI(0),
1065 NI_PFI(1),
1066 NI_PFI(2),
1067 NI_PFI(3),
1068 NI_PFI(4),
1069 NI_PFI(5),
1070 NI_PFI(6),
1071 NI_PFI(7),
1072 NI_PFI(8),
1073 NI_PFI(9),
1074 NI_PFI(10),
1075 NI_PFI(11),
1076 NI_PFI(12),
1077 NI_PFI(13),
1078 NI_PFI(14),
1079 NI_PFI(15),
1080 TRIGGER_LINE(0),
1081 TRIGGER_LINE(1),
1082 TRIGGER_LINE(2),
1083 TRIGGER_LINE(3),
1084 TRIGGER_LINE(4),
1085 TRIGGER_LINE(5),
1086 TRIGGER_LINE(6),
1087 TRIGGER_LINE(7),
1088 PXI_Star,
1089 NI_AnalogComparisonEvent,
1090 0, /* Termination */
1091 }
1092 },
1093 {
1094 .dest = NI_CtrZ(0),
1095 .src = (int[]){
1096 NI_PFI(0),
1097 NI_PFI(1),
1098 NI_PFI(2),
1099 NI_PFI(3),
1100 NI_PFI(4),
1101 NI_PFI(5),
1102 NI_PFI(6),
1103 NI_PFI(7),
1104 NI_PFI(8),
1105 NI_PFI(9),
1106 NI_PFI(10),
1107 NI_PFI(11),
1108 NI_PFI(12),
1109 NI_PFI(13),
1110 NI_PFI(14),
1111 NI_PFI(15),
1112 TRIGGER_LINE(0),
1113 TRIGGER_LINE(1),
1114 TRIGGER_LINE(2),
1115 TRIGGER_LINE(3),
1116 TRIGGER_LINE(4),
1117 TRIGGER_LINE(5),
1118 TRIGGER_LINE(6),
1119 TRIGGER_LINE(7),
1120 PXI_Star,
1121 NI_AnalogComparisonEvent,
1122 0, /* Termination */
1123 }
1124 },
1125 {
1126 .dest = NI_CtrZ(1),
1127 .src = (int[]){
1128 NI_PFI(0),
1129 NI_PFI(1),
1130 NI_PFI(2),
1131 NI_PFI(3),
1132 NI_PFI(4),
1133 NI_PFI(5),
1134 NI_PFI(6),
1135 NI_PFI(7),
1136 NI_PFI(8),
1137 NI_PFI(9),
1138 NI_PFI(10),
1139 NI_PFI(11),
1140 NI_PFI(12),
1141 NI_PFI(13),
1142 NI_PFI(14),
1143 NI_PFI(15),
1144 TRIGGER_LINE(0),
1145 TRIGGER_LINE(1),
1146 TRIGGER_LINE(2),
1147 TRIGGER_LINE(3),
1148 TRIGGER_LINE(4),
1149 TRIGGER_LINE(5),
1150 TRIGGER_LINE(6),
1151 TRIGGER_LINE(7),
1152 PXI_Star,
1153 NI_AnalogComparisonEvent,
1154 0, /* Termination */
1155 }
1156 },
1157 {
1158 .dest = NI_CtrArmStartTrigger(0),
1159 .src = (int[]){
1160 NI_PFI(0),
1161 NI_PFI(1),
1162 NI_PFI(2),
1163 NI_PFI(3),
1164 NI_PFI(4),
1165 NI_PFI(5),
1166 NI_PFI(6),
1167 NI_PFI(7),
1168 NI_PFI(8),
1169 NI_PFI(9),
1170 NI_PFI(10),
1171 NI_PFI(11),
1172 NI_PFI(12),
1173 NI_PFI(13),
1174 NI_PFI(14),
1175 NI_PFI(15),
1176 TRIGGER_LINE(0),
1177 TRIGGER_LINE(1),
1178 TRIGGER_LINE(2),
1179 TRIGGER_LINE(3),
1180 TRIGGER_LINE(4),
1181 TRIGGER_LINE(5),
1182 TRIGGER_LINE(6),
1183 TRIGGER_LINE(7),
1184 NI_CtrInternalOutput(1),
1185 PXI_Star,
1186 NI_AI_StartTrigger,
1187 NI_AI_ReferenceTrigger,
1188 NI_AnalogComparisonEvent,
1189 0, /* Termination */
1190 }
1191 },
1192 {
1193 .dest = NI_CtrArmStartTrigger(1),
1194 .src = (int[]){
1195 NI_PFI(0),
1196 NI_PFI(1),
1197 NI_PFI(2),
1198 NI_PFI(3),
1199 NI_PFI(4),
1200 NI_PFI(5),
1201 NI_PFI(6),
1202 NI_PFI(7),
1203 NI_PFI(8),
1204 NI_PFI(9),
1205 NI_PFI(10),
1206 NI_PFI(11),
1207 NI_PFI(12),
1208 NI_PFI(13),
1209 NI_PFI(14),
1210 NI_PFI(15),
1211 TRIGGER_LINE(0),
1212 TRIGGER_LINE(1),
1213 TRIGGER_LINE(2),
1214 TRIGGER_LINE(3),
1215 TRIGGER_LINE(4),
1216 TRIGGER_LINE(5),
1217 TRIGGER_LINE(6),
1218 TRIGGER_LINE(7),
1219 NI_CtrInternalOutput(0),
1220 PXI_Star,
1221 NI_AI_StartTrigger,
1222 NI_AI_ReferenceTrigger,
1223 NI_AnalogComparisonEvent,
1224 0, /* Termination */
1225 }
1226 },
1227 {
1228 .dest = NI_AI_SampleClock,
1229 .src = (int[]){
1230 NI_PFI(0),
1231 NI_PFI(1),
1232 NI_PFI(2),
1233 NI_PFI(3),
1234 NI_PFI(4),
1235 NI_PFI(5),
1236 NI_PFI(6),
1237 NI_PFI(7),
1238 NI_PFI(8),
1239 NI_PFI(9),
1240 NI_PFI(10),
1241 NI_PFI(11),
1242 NI_PFI(12),
1243 NI_PFI(13),
1244 NI_PFI(14),
1245 NI_PFI(15),
1246 TRIGGER_LINE(0),
1247 TRIGGER_LINE(1),
1248 TRIGGER_LINE(2),
1249 TRIGGER_LINE(3),
1250 TRIGGER_LINE(4),
1251 TRIGGER_LINE(5),
1252 TRIGGER_LINE(6),
1253 TRIGGER_LINE(7),
1254 NI_CtrInternalOutput(0),
1255 NI_CtrInternalOutput(1),
1256 PXI_Star,
1257 NI_AI_SampleClockTimebase,
1258 NI_AnalogComparisonEvent,
1259 0, /* Termination */
1260 }
1261 },
1262 {
1263 .dest = NI_AI_SampleClockTimebase,
1264 .src = (int[]){
1265 NI_PFI(0),
1266 NI_PFI(1),
1267 NI_PFI(2),
1268 NI_PFI(3),
1269 NI_PFI(4),
1270 NI_PFI(5),
1271 NI_PFI(6),
1272 NI_PFI(7),
1273 NI_PFI(8),
1274 NI_PFI(9),
1275 NI_PFI(10),
1276 NI_PFI(11),
1277 NI_PFI(12),
1278 NI_PFI(13),
1279 NI_PFI(14),
1280 NI_PFI(15),
1281 TRIGGER_LINE(0),
1282 TRIGGER_LINE(1),
1283 TRIGGER_LINE(2),
1284 TRIGGER_LINE(3),
1285 TRIGGER_LINE(4),
1286 TRIGGER_LINE(5),
1287 TRIGGER_LINE(6),
1288 TRIGGER_LINE(7),
1289 PXI_Star,
1290 PXI_Clk10,
1291 NI_20MHzTimebase,
1292 NI_100kHzTimebase,
1293 NI_AnalogComparisonEvent,
1294 0, /* Termination */
1295 }
1296 },
1297 {
1298 .dest = NI_AI_StartTrigger,
1299 .src = (int[]){
1300 NI_PFI(0),
1301 NI_PFI(1),
1302 NI_PFI(2),
1303 NI_PFI(3),
1304 NI_PFI(4),
1305 NI_PFI(5),
1306 NI_PFI(6),
1307 NI_PFI(7),
1308 NI_PFI(8),
1309 NI_PFI(9),
1310 NI_PFI(10),
1311 NI_PFI(11),
1312 NI_PFI(12),
1313 NI_PFI(13),
1314 NI_PFI(14),
1315 NI_PFI(15),
1316 TRIGGER_LINE(0),
1317 TRIGGER_LINE(1),
1318 TRIGGER_LINE(2),
1319 TRIGGER_LINE(3),
1320 TRIGGER_LINE(4),
1321 TRIGGER_LINE(5),
1322 TRIGGER_LINE(6),
1323 TRIGGER_LINE(7),
1324 NI_CtrInternalOutput(0),
1325 NI_CtrInternalOutput(1),
1326 PXI_Star,
1327 NI_AnalogComparisonEvent,
1328 0, /* Termination */
1329 }
1330 },
1331 {
1332 .dest = NI_AI_ReferenceTrigger,
1333 .src = (int[]){
1334 NI_PFI(0),
1335 NI_PFI(1),
1336 NI_PFI(2),
1337 NI_PFI(3),
1338 NI_PFI(4),
1339 NI_PFI(5),
1340 NI_PFI(6),
1341 NI_PFI(7),
1342 NI_PFI(8),
1343 NI_PFI(9),
1344 NI_PFI(10),
1345 NI_PFI(11),
1346 NI_PFI(12),
1347 NI_PFI(13),
1348 NI_PFI(14),
1349 NI_PFI(15),
1350 TRIGGER_LINE(0),
1351 TRIGGER_LINE(1),
1352 TRIGGER_LINE(2),
1353 TRIGGER_LINE(3),
1354 TRIGGER_LINE(4),
1355 TRIGGER_LINE(5),
1356 TRIGGER_LINE(6),
1357 TRIGGER_LINE(7),
1358 PXI_Star,
1359 NI_AnalogComparisonEvent,
1360 0, /* Termination */
1361 }
1362 },
1363 {
1364 .dest = NI_AI_ConvertClock,
1365 .src = (int[]){
1366 NI_PFI(0),
1367 NI_PFI(1),
1368 NI_PFI(2),
1369 NI_PFI(3),
1370 NI_PFI(4),
1371 NI_PFI(5),
1372 NI_PFI(6),
1373 NI_PFI(7),
1374 NI_PFI(8),
1375 NI_PFI(9),
1376 NI_PFI(10),
1377 NI_PFI(11),
1378 NI_PFI(12),
1379 NI_PFI(13),
1380 NI_PFI(14),
1381 NI_PFI(15),
1382 TRIGGER_LINE(0),
1383 TRIGGER_LINE(1),
1384 TRIGGER_LINE(2),
1385 TRIGGER_LINE(3),
1386 TRIGGER_LINE(4),
1387 TRIGGER_LINE(5),
1388 TRIGGER_LINE(6),
1389 TRIGGER_LINE(7),
1390 NI_CtrInternalOutput(0),
1391 NI_CtrInternalOutput(1),
1392 PXI_Star,
1393 NI_AI_ConvertClockTimebase,
1394 NI_AnalogComparisonEvent,
1395 0, /* Termination */
1396 }
1397 },
1398 {
1399 .dest = NI_AI_ConvertClockTimebase,
1400 .src = (int[]){
1401 NI_AI_SampleClockTimebase,
1402 NI_20MHzTimebase,
1403 0, /* Termination */
1404 }
1405 },
1406 {
1407 .dest = NI_AI_PauseTrigger,
1408 .src = (int[]){
1409 NI_PFI(0),
1410 NI_PFI(1),
1411 NI_PFI(2),
1412 NI_PFI(3),
1413 NI_PFI(4),
1414 NI_PFI(5),
1415 NI_PFI(6),
1416 NI_PFI(7),
1417 NI_PFI(8),
1418 NI_PFI(9),
1419 NI_PFI(10),
1420 NI_PFI(11),
1421 NI_PFI(12),
1422 NI_PFI(13),
1423 NI_PFI(14),
1424 NI_PFI(15),
1425 TRIGGER_LINE(0),
1426 TRIGGER_LINE(1),
1427 TRIGGER_LINE(2),
1428 TRIGGER_LINE(3),
1429 TRIGGER_LINE(4),
1430 TRIGGER_LINE(5),
1431 TRIGGER_LINE(6),
1432 TRIGGER_LINE(7),
1433 PXI_Star,
1434 NI_AnalogComparisonEvent,
1435 0, /* Termination */
1436 }
1437 },
1438 {
1439 .dest = NI_AO_SampleClock,
1440 .src = (int[]){
1441 NI_PFI(0),
1442 NI_PFI(1),
1443 NI_PFI(2),
1444 NI_PFI(3),
1445 NI_PFI(4),
1446 NI_PFI(5),
1447 NI_PFI(6),
1448 NI_PFI(7),
1449 NI_PFI(8),
1450 NI_PFI(9),
1451 NI_PFI(10),
1452 NI_PFI(11),
1453 NI_PFI(12),
1454 NI_PFI(13),
1455 NI_PFI(14),
1456 NI_PFI(15),
1457 TRIGGER_LINE(0),
1458 TRIGGER_LINE(1),
1459 TRIGGER_LINE(2),
1460 TRIGGER_LINE(3),
1461 TRIGGER_LINE(4),
1462 TRIGGER_LINE(5),
1463 TRIGGER_LINE(6),
1464 TRIGGER_LINE(7),
1465 NI_CtrInternalOutput(0),
1466 NI_CtrInternalOutput(1),
1467 PXI_Star,
1468 NI_AO_SampleClockTimebase,
1469 NI_AnalogComparisonEvent,
1470 0, /* Termination */
1471 }
1472 },
1473 {
1474 .dest = NI_AO_SampleClockTimebase,
1475 .src = (int[]){
1476 NI_PFI(0),
1477 NI_PFI(1),
1478 NI_PFI(2),
1479 NI_PFI(3),
1480 NI_PFI(4),
1481 NI_PFI(5),
1482 NI_PFI(6),
1483 NI_PFI(7),
1484 NI_PFI(8),
1485 NI_PFI(9),
1486 NI_PFI(10),
1487 NI_PFI(11),
1488 NI_PFI(12),
1489 NI_PFI(13),
1490 NI_PFI(14),
1491 NI_PFI(15),
1492 TRIGGER_LINE(0),
1493 TRIGGER_LINE(1),
1494 TRIGGER_LINE(2),
1495 TRIGGER_LINE(3),
1496 TRIGGER_LINE(4),
1497 TRIGGER_LINE(5),
1498 TRIGGER_LINE(6),
1499 TRIGGER_LINE(7),
1500 PXI_Star,
1501 PXI_Clk10,
1502 NI_20MHzTimebase,
1503 NI_100kHzTimebase,
1504 NI_AnalogComparisonEvent,
1505 0, /* Termination */
1506 }
1507 },
1508 {
1509 .dest = NI_AO_StartTrigger,
1510 .src = (int[]){
1511 NI_PFI(0),
1512 NI_PFI(1),
1513 NI_PFI(2),
1514 NI_PFI(3),
1515 NI_PFI(4),
1516 NI_PFI(5),
1517 NI_PFI(6),
1518 NI_PFI(7),
1519 NI_PFI(8),
1520 NI_PFI(9),
1521 NI_PFI(10),
1522 NI_PFI(11),
1523 NI_PFI(12),
1524 NI_PFI(13),
1525 NI_PFI(14),
1526 NI_PFI(15),
1527 TRIGGER_LINE(0),
1528 TRIGGER_LINE(1),
1529 TRIGGER_LINE(2),
1530 TRIGGER_LINE(3),
1531 TRIGGER_LINE(4),
1532 TRIGGER_LINE(5),
1533 TRIGGER_LINE(6),
1534 TRIGGER_LINE(7),
1535 PXI_Star,
1536 NI_AI_StartTrigger,
1537 NI_AnalogComparisonEvent,
1538 0, /* Termination */
1539 }
1540 },
1541 {
1542 .dest = NI_AO_PauseTrigger,
1543 .src = (int[]){
1544 NI_PFI(0),
1545 NI_PFI(1),
1546 NI_PFI(2),
1547 NI_PFI(3),
1548 NI_PFI(4),
1549 NI_PFI(5),
1550 NI_PFI(6),
1551 NI_PFI(7),
1552 NI_PFI(8),
1553 NI_PFI(9),
1554 NI_PFI(10),
1555 NI_PFI(11),
1556 NI_PFI(12),
1557 NI_PFI(13),
1558 NI_PFI(14),
1559 NI_PFI(15),
1560 TRIGGER_LINE(0),
1561 TRIGGER_LINE(1),
1562 TRIGGER_LINE(2),
1563 TRIGGER_LINE(3),
1564 TRIGGER_LINE(4),
1565 TRIGGER_LINE(5),
1566 TRIGGER_LINE(6),
1567 TRIGGER_LINE(7),
1568 PXI_Star,
1569 NI_AnalogComparisonEvent,
1570 0, /* Termination */
1571 }
1572 },
1573 {
1574 .dest = NI_DI_SampleClock,
1575 .src = (int[]){
1576 NI_PFI(0),
1577 NI_PFI(1),
1578 NI_PFI(2),
1579 NI_PFI(3),
1580 NI_PFI(4),
1581 NI_PFI(5),
1582 NI_PFI(6),
1583 NI_PFI(7),
1584 NI_PFI(8),
1585 NI_PFI(9),
1586 NI_PFI(10),
1587 NI_PFI(11),
1588 NI_PFI(12),
1589 NI_PFI(13),
1590 NI_PFI(14),
1591 NI_PFI(15),
1592 TRIGGER_LINE(0),
1593 TRIGGER_LINE(1),
1594 TRIGGER_LINE(2),
1595 TRIGGER_LINE(3),
1596 TRIGGER_LINE(4),
1597 TRIGGER_LINE(5),
1598 TRIGGER_LINE(6),
1599 TRIGGER_LINE(7),
1600 NI_CtrInternalOutput(0),
1601 NI_CtrInternalOutput(1),
1602 PXI_Star,
1603 NI_AI_SampleClock,
1604 NI_AI_ConvertClock,
1605 NI_AO_SampleClock,
1606 NI_FrequencyOutput,
1607 NI_ChangeDetectionEvent,
1608 NI_AnalogComparisonEvent,
1609 0, /* Termination */
1610 }
1611 },
1612 {
1613 .dest = NI_DO_SampleClock,
1614 .src = (int[]){
1615 NI_PFI(0),
1616 NI_PFI(1),
1617 NI_PFI(2),
1618 NI_PFI(3),
1619 NI_PFI(4),
1620 NI_PFI(5),
1621 NI_PFI(6),
1622 NI_PFI(7),
1623 NI_PFI(8),
1624 NI_PFI(9),
1625 NI_PFI(10),
1626 NI_PFI(11),
1627 NI_PFI(12),
1628 NI_PFI(13),
1629 NI_PFI(14),
1630 NI_PFI(15),
1631 TRIGGER_LINE(0),
1632 TRIGGER_LINE(1),
1633 TRIGGER_LINE(2),
1634 TRIGGER_LINE(3),
1635 TRIGGER_LINE(4),
1636 TRIGGER_LINE(5),
1637 TRIGGER_LINE(6),
1638 TRIGGER_LINE(7),
1639 NI_CtrInternalOutput(0),
1640 NI_CtrInternalOutput(1),
1641 PXI_Star,
1642 NI_AI_SampleClock,
1643 NI_AI_ConvertClock,
1644 NI_AO_SampleClock,
1645 NI_FrequencyOutput,
1646 NI_ChangeDetectionEvent,
1647 NI_AnalogComparisonEvent,
1648 0, /* Termination */
1649 }
1650 },
1651 { /* Termination of list */
1652 .dest = 0,
1653 },
1654 },
1655};
diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxi-6733.c b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxi-6733.c
new file mode 100644
index 000000000000..27da4433fc4a
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxi-6733.c
@@ -0,0 +1,428 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routing/ni_device_routes/pxi-6733.c
5 * List of valid routes for specific NI boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21/*
22 * The contents of this file are generated using the tools in
23 * comedi/drivers/ni_routing/tools
24 *
25 * Please use those tools to help maintain the contents of this file.
26 */
27
28#include "../ni_device_routes.h"
29#include "all.h"
30
31struct ni_device_routes ni_pxi_6733_device_routes = {
32 .device = "pxi-6733",
33 .routes = (struct ni_route_set[]){
34 {
35 .dest = NI_PFI(3),
36 .src = (int[]){
37 NI_CtrSource(1),
38 0, /* Termination */
39 }
40 },
41 {
42 .dest = NI_PFI(4),
43 .src = (int[]){
44 NI_CtrGate(1),
45 0, /* Termination */
46 }
47 },
48 {
49 .dest = NI_PFI(5),
50 .src = (int[]){
51 NI_AO_SampleClock,
52 0, /* Termination */
53 }
54 },
55 {
56 .dest = NI_PFI(6),
57 .src = (int[]){
58 NI_AO_StartTrigger,
59 0, /* Termination */
60 }
61 },
62 {
63 .dest = NI_PFI(8),
64 .src = (int[]){
65 NI_CtrSource(0),
66 0, /* Termination */
67 }
68 },
69 {
70 .dest = NI_PFI(9),
71 .src = (int[]){
72 NI_CtrGate(0),
73 0, /* Termination */
74 }
75 },
76 {
77 .dest = TRIGGER_LINE(0),
78 .src = (int[]){
79 NI_CtrSource(0),
80 NI_CtrGate(0),
81 NI_CtrInternalOutput(0),
82 NI_CtrOut(0),
83 NI_AO_SampleClock,
84 NI_AO_StartTrigger,
85 0, /* Termination */
86 }
87 },
88 {
89 .dest = TRIGGER_LINE(1),
90 .src = (int[]){
91 NI_CtrSource(0),
92 NI_CtrGate(0),
93 NI_CtrInternalOutput(0),
94 NI_CtrOut(0),
95 NI_AO_SampleClock,
96 NI_AO_StartTrigger,
97 0, /* Termination */
98 }
99 },
100 {
101 .dest = TRIGGER_LINE(2),
102 .src = (int[]){
103 NI_CtrSource(0),
104 NI_CtrGate(0),
105 NI_CtrInternalOutput(0),
106 NI_CtrOut(0),
107 NI_AO_SampleClock,
108 NI_AO_StartTrigger,
109 0, /* Termination */
110 }
111 },
112 {
113 .dest = TRIGGER_LINE(3),
114 .src = (int[]){
115 NI_CtrSource(0),
116 NI_CtrGate(0),
117 NI_CtrInternalOutput(0),
118 NI_CtrOut(0),
119 NI_AO_SampleClock,
120 NI_AO_StartTrigger,
121 0, /* Termination */
122 }
123 },
124 {
125 .dest = TRIGGER_LINE(4),
126 .src = (int[]){
127 NI_CtrSource(0),
128 NI_CtrGate(0),
129 NI_CtrInternalOutput(0),
130 NI_CtrOut(0),
131 NI_AO_SampleClock,
132 NI_AO_StartTrigger,
133 0, /* Termination */
134 }
135 },
136 {
137 .dest = TRIGGER_LINE(5),
138 .src = (int[]){
139 NI_CtrSource(0),
140 NI_CtrGate(0),
141 NI_CtrInternalOutput(0),
142 NI_CtrOut(0),
143 NI_AO_SampleClock,
144 NI_AO_StartTrigger,
145 0, /* Termination */
146 }
147 },
148 {
149 .dest = TRIGGER_LINE(7),
150 .src = (int[]){
151 NI_20MHzTimebase,
152 0, /* Termination */
153 }
154 },
155 {
156 .dest = NI_CtrSource(0),
157 .src = (int[]){
158 NI_PFI(0),
159 NI_PFI(1),
160 NI_PFI(2),
161 NI_PFI(3),
162 NI_PFI(4),
163 NI_PFI(5),
164 NI_PFI(6),
165 NI_PFI(7),
166 NI_PFI(8),
167 NI_PFI(9),
168 TRIGGER_LINE(0),
169 TRIGGER_LINE(1),
170 TRIGGER_LINE(2),
171 TRIGGER_LINE(3),
172 TRIGGER_LINE(4),
173 TRIGGER_LINE(5),
174 TRIGGER_LINE(7),
175 PXI_Star,
176 NI_MasterTimebase,
177 NI_20MHzTimebase,
178 NI_100kHzTimebase,
179 0, /* Termination */
180 }
181 },
182 {
183 .dest = NI_CtrSource(1),
184 .src = (int[]){
185 NI_PFI(0),
186 NI_PFI(1),
187 NI_PFI(2),
188 NI_PFI(3),
189 NI_PFI(4),
190 NI_PFI(5),
191 NI_PFI(6),
192 NI_PFI(7),
193 NI_PFI(8),
194 NI_PFI(9),
195 TRIGGER_LINE(0),
196 TRIGGER_LINE(1),
197 TRIGGER_LINE(2),
198 TRIGGER_LINE(3),
199 TRIGGER_LINE(4),
200 TRIGGER_LINE(5),
201 TRIGGER_LINE(7),
202 PXI_Star,
203 NI_MasterTimebase,
204 NI_20MHzTimebase,
205 NI_100kHzTimebase,
206 0, /* Termination */
207 }
208 },
209 {
210 .dest = NI_CtrGate(0),
211 .src = (int[]){
212 NI_PFI(0),
213 NI_PFI(1),
214 NI_PFI(2),
215 NI_PFI(3),
216 NI_PFI(4),
217 NI_PFI(5),
218 NI_PFI(6),
219 NI_PFI(7),
220 NI_PFI(8),
221 NI_PFI(9),
222 TRIGGER_LINE(0),
223 TRIGGER_LINE(1),
224 TRIGGER_LINE(2),
225 TRIGGER_LINE(3),
226 TRIGGER_LINE(4),
227 TRIGGER_LINE(5),
228 NI_CtrInternalOutput(1),
229 PXI_Star,
230 0, /* Termination */
231 }
232 },
233 {
234 .dest = NI_CtrGate(1),
235 .src = (int[]){
236 NI_PFI(0),
237 NI_PFI(1),
238 NI_PFI(2),
239 NI_PFI(3),
240 NI_PFI(4),
241 NI_PFI(5),
242 NI_PFI(6),
243 NI_PFI(7),
244 NI_PFI(8),
245 NI_PFI(9),
246 TRIGGER_LINE(0),
247 TRIGGER_LINE(1),
248 TRIGGER_LINE(2),
249 TRIGGER_LINE(3),
250 TRIGGER_LINE(4),
251 TRIGGER_LINE(5),
252 NI_CtrInternalOutput(0),
253 PXI_Star,
254 0, /* Termination */
255 }
256 },
257 {
258 .dest = NI_CtrOut(0),
259 .src = (int[]){
260 TRIGGER_LINE(0),
261 TRIGGER_LINE(1),
262 TRIGGER_LINE(2),
263 TRIGGER_LINE(3),
264 TRIGGER_LINE(4),
265 TRIGGER_LINE(5),
266 NI_CtrInternalOutput(0),
267 PXI_Star,
268 0, /* Termination */
269 }
270 },
271 {
272 .dest = NI_CtrOut(1),
273 .src = (int[]){
274 NI_CtrInternalOutput(1),
275 0, /* Termination */
276 }
277 },
278 {
279 .dest = PXI_Star,
280 .src = (int[]){
281 NI_CtrSource(0),
282 NI_CtrGate(0),
283 NI_CtrInternalOutput(0),
284 NI_CtrOut(0),
285 NI_AO_SampleClock,
286 NI_AO_StartTrigger,
287 0, /* Termination */
288 }
289 },
290 {
291 .dest = NI_AO_SampleClock,
292 .src = (int[]){
293 NI_PFI(0),
294 NI_PFI(1),
295 NI_PFI(2),
296 NI_PFI(3),
297 NI_PFI(4),
298 NI_PFI(5),
299 NI_PFI(6),
300 NI_PFI(7),
301 NI_PFI(8),
302 NI_PFI(9),
303 TRIGGER_LINE(0),
304 TRIGGER_LINE(1),
305 TRIGGER_LINE(2),
306 TRIGGER_LINE(3),
307 TRIGGER_LINE(4),
308 TRIGGER_LINE(5),
309 NI_CtrInternalOutput(1),
310 PXI_Star,
311 NI_AO_SampleClockTimebase,
312 0, /* Termination */
313 }
314 },
315 {
316 .dest = NI_AO_SampleClockTimebase,
317 .src = (int[]){
318 NI_PFI(0),
319 NI_PFI(1),
320 NI_PFI(2),
321 NI_PFI(3),
322 NI_PFI(4),
323 NI_PFI(5),
324 NI_PFI(6),
325 NI_PFI(7),
326 NI_PFI(8),
327 NI_PFI(9),
328 TRIGGER_LINE(0),
329 TRIGGER_LINE(1),
330 TRIGGER_LINE(2),
331 TRIGGER_LINE(3),
332 TRIGGER_LINE(4),
333 TRIGGER_LINE(5),
334 TRIGGER_LINE(7),
335 PXI_Star,
336 NI_MasterTimebase,
337 NI_20MHzTimebase,
338 NI_100kHzTimebase,
339 0, /* Termination */
340 }
341 },
342 {
343 .dest = NI_AO_StartTrigger,
344 .src = (int[]){
345 NI_PFI(0),
346 NI_PFI(1),
347 NI_PFI(2),
348 NI_PFI(3),
349 NI_PFI(4),
350 NI_PFI(5),
351 NI_PFI(6),
352 NI_PFI(7),
353 NI_PFI(8),
354 NI_PFI(9),
355 TRIGGER_LINE(0),
356 TRIGGER_LINE(1),
357 TRIGGER_LINE(2),
358 TRIGGER_LINE(3),
359 TRIGGER_LINE(4),
360 TRIGGER_LINE(5),
361 PXI_Star,
362 0, /* Termination */
363 }
364 },
365 {
366 .dest = NI_AO_PauseTrigger,
367 .src = (int[]){
368 NI_PFI(0),
369 NI_PFI(1),
370 NI_PFI(2),
371 NI_PFI(3),
372 NI_PFI(4),
373 NI_PFI(5),
374 NI_PFI(6),
375 NI_PFI(7),
376 NI_PFI(8),
377 NI_PFI(9),
378 TRIGGER_LINE(0),
379 TRIGGER_LINE(1),
380 TRIGGER_LINE(2),
381 TRIGGER_LINE(3),
382 TRIGGER_LINE(4),
383 TRIGGER_LINE(5),
384 PXI_Star,
385 0, /* Termination */
386 }
387 },
388 {
389 .dest = NI_DI_SampleClock,
390 .src = (int[]){
391 TRIGGER_LINE(0),
392 TRIGGER_LINE(1),
393 TRIGGER_LINE(2),
394 TRIGGER_LINE(3),
395 TRIGGER_LINE(4),
396 TRIGGER_LINE(5),
397 PXI_Star,
398 NI_AO_SampleClock,
399 0, /* Termination */
400 }
401 },
402 {
403 .dest = NI_DO_SampleClock,
404 .src = (int[]){
405 TRIGGER_LINE(0),
406 TRIGGER_LINE(1),
407 TRIGGER_LINE(2),
408 TRIGGER_LINE(3),
409 TRIGGER_LINE(4),
410 TRIGGER_LINE(5),
411 PXI_Star,
412 NI_AO_SampleClock,
413 0, /* Termination */
414 }
415 },
416 {
417 .dest = NI_MasterTimebase,
418 .src = (int[]){
419 TRIGGER_LINE(7),
420 NI_20MHzTimebase,
421 0, /* Termination */
422 }
423 },
424 { /* Termination of list */
425 .dest = 0,
426 },
427 },
428};
diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxie-6251.c b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxie-6251.c
new file mode 100644
index 000000000000..8354fe971d59
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxie-6251.c
@@ -0,0 +1,1656 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routing/ni_device_routes/pxie-6251.c
5 * List of valid routes for specific NI boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21/*
22 * The contents of this file are generated using the tools in
23 * comedi/drivers/ni_routing/tools
24 *
25 * Please use those tools to help maintain the contents of this file.
26 */
27
28#include "../ni_device_routes.h"
29#include "all.h"
30
31struct ni_device_routes ni_pxie_6251_device_routes = {
32 .device = "pxie-6251",
33 .routes = (struct ni_route_set[]){
34 {
35 .dest = NI_PFI(0),
36 .src = (int[]){
37 TRIGGER_LINE(0),
38 TRIGGER_LINE(1),
39 TRIGGER_LINE(2),
40 TRIGGER_LINE(3),
41 TRIGGER_LINE(4),
42 TRIGGER_LINE(5),
43 TRIGGER_LINE(6),
44 TRIGGER_LINE(7),
45 NI_CtrSource(0),
46 NI_CtrSource(1),
47 NI_CtrGate(0),
48 NI_CtrGate(1),
49 NI_CtrInternalOutput(0),
50 NI_CtrInternalOutput(1),
51 NI_AI_SampleClock,
52 NI_AI_StartTrigger,
53 NI_AI_ReferenceTrigger,
54 NI_AI_ConvertClock,
55 NI_AO_SampleClock,
56 NI_AO_StartTrigger,
57 NI_DI_SampleClock,
58 NI_DO_SampleClock,
59 NI_FrequencyOutput,
60 NI_ChangeDetectionEvent,
61 NI_AnalogComparisonEvent,
62 0, /* Termination */
63 }
64 },
65 {
66 .dest = NI_PFI(1),
67 .src = (int[]){
68 TRIGGER_LINE(0),
69 TRIGGER_LINE(1),
70 TRIGGER_LINE(2),
71 TRIGGER_LINE(3),
72 TRIGGER_LINE(4),
73 TRIGGER_LINE(5),
74 TRIGGER_LINE(6),
75 TRIGGER_LINE(7),
76 NI_CtrSource(0),
77 NI_CtrSource(1),
78 NI_CtrGate(0),
79 NI_CtrGate(1),
80 NI_CtrInternalOutput(0),
81 NI_CtrInternalOutput(1),
82 NI_AI_SampleClock,
83 NI_AI_StartTrigger,
84 NI_AI_ReferenceTrigger,
85 NI_AI_ConvertClock,
86 NI_AO_SampleClock,
87 NI_AO_StartTrigger,
88 NI_DI_SampleClock,
89 NI_DO_SampleClock,
90 NI_FrequencyOutput,
91 NI_ChangeDetectionEvent,
92 NI_AnalogComparisonEvent,
93 0, /* Termination */
94 }
95 },
96 {
97 .dest = NI_PFI(2),
98 .src = (int[]){
99 TRIGGER_LINE(0),
100 TRIGGER_LINE(1),
101 TRIGGER_LINE(2),
102 TRIGGER_LINE(3),
103 TRIGGER_LINE(4),
104 TRIGGER_LINE(5),
105 TRIGGER_LINE(6),
106 TRIGGER_LINE(7),
107 NI_CtrSource(0),
108 NI_CtrSource(1),
109 NI_CtrGate(0),
110 NI_CtrGate(1),
111 NI_CtrInternalOutput(0),
112 NI_CtrInternalOutput(1),
113 NI_AI_SampleClock,
114 NI_AI_StartTrigger,
115 NI_AI_ReferenceTrigger,
116 NI_AI_ConvertClock,
117 NI_AO_SampleClock,
118 NI_AO_StartTrigger,
119 NI_DI_SampleClock,
120 NI_DO_SampleClock,
121 NI_FrequencyOutput,
122 NI_ChangeDetectionEvent,
123 NI_AnalogComparisonEvent,
124 0, /* Termination */
125 }
126 },
127 {
128 .dest = NI_PFI(3),
129 .src = (int[]){
130 TRIGGER_LINE(0),
131 TRIGGER_LINE(1),
132 TRIGGER_LINE(2),
133 TRIGGER_LINE(3),
134 TRIGGER_LINE(4),
135 TRIGGER_LINE(5),
136 TRIGGER_LINE(6),
137 TRIGGER_LINE(7),
138 NI_CtrSource(0),
139 NI_CtrSource(1),
140 NI_CtrGate(0),
141 NI_CtrGate(1),
142 NI_CtrInternalOutput(0),
143 NI_CtrInternalOutput(1),
144 NI_AI_SampleClock,
145 NI_AI_StartTrigger,
146 NI_AI_ReferenceTrigger,
147 NI_AI_ConvertClock,
148 NI_AO_SampleClock,
149 NI_AO_StartTrigger,
150 NI_DI_SampleClock,
151 NI_DO_SampleClock,
152 NI_FrequencyOutput,
153 NI_ChangeDetectionEvent,
154 NI_AnalogComparisonEvent,
155 0, /* Termination */
156 }
157 },
158 {
159 .dest = NI_PFI(4),
160 .src = (int[]){
161 TRIGGER_LINE(0),
162 TRIGGER_LINE(1),
163 TRIGGER_LINE(2),
164 TRIGGER_LINE(3),
165 TRIGGER_LINE(4),
166 TRIGGER_LINE(5),
167 TRIGGER_LINE(6),
168 TRIGGER_LINE(7),
169 NI_CtrSource(0),
170 NI_CtrSource(1),
171 NI_CtrGate(0),
172 NI_CtrGate(1),
173 NI_CtrInternalOutput(0),
174 NI_CtrInternalOutput(1),
175 NI_AI_SampleClock,
176 NI_AI_StartTrigger,
177 NI_AI_ReferenceTrigger,
178 NI_AI_ConvertClock,
179 NI_AO_SampleClock,
180 NI_AO_StartTrigger,
181 NI_DI_SampleClock,
182 NI_DO_SampleClock,
183 NI_FrequencyOutput,
184 NI_ChangeDetectionEvent,
185 NI_AnalogComparisonEvent,
186 0, /* Termination */
187 }
188 },
189 {
190 .dest = NI_PFI(5),
191 .src = (int[]){
192 TRIGGER_LINE(0),
193 TRIGGER_LINE(1),
194 TRIGGER_LINE(2),
195 TRIGGER_LINE(3),
196 TRIGGER_LINE(4),
197 TRIGGER_LINE(5),
198 TRIGGER_LINE(6),
199 TRIGGER_LINE(7),
200 NI_CtrSource(0),
201 NI_CtrSource(1),
202 NI_CtrGate(0),
203 NI_CtrGate(1),
204 NI_CtrInternalOutput(0),
205 NI_CtrInternalOutput(1),
206 NI_AI_SampleClock,
207 NI_AI_StartTrigger,
208 NI_AI_ReferenceTrigger,
209 NI_AI_ConvertClock,
210 NI_AO_SampleClock,
211 NI_AO_StartTrigger,
212 NI_DI_SampleClock,
213 NI_DO_SampleClock,
214 NI_FrequencyOutput,
215 NI_ChangeDetectionEvent,
216 NI_AnalogComparisonEvent,
217 0, /* Termination */
218 }
219 },
220 {
221 .dest = NI_PFI(6),
222 .src = (int[]){
223 TRIGGER_LINE(0),
224 TRIGGER_LINE(1),
225 TRIGGER_LINE(2),
226 TRIGGER_LINE(3),
227 TRIGGER_LINE(4),
228 TRIGGER_LINE(5),
229 TRIGGER_LINE(6),
230 TRIGGER_LINE(7),
231 NI_CtrSource(0),
232 NI_CtrSource(1),
233 NI_CtrGate(0),
234 NI_CtrGate(1),
235 NI_CtrInternalOutput(0),
236 NI_CtrInternalOutput(1),
237 NI_AI_SampleClock,
238 NI_AI_StartTrigger,
239 NI_AI_ReferenceTrigger,
240 NI_AI_ConvertClock,
241 NI_AO_SampleClock,
242 NI_AO_StartTrigger,
243 NI_DI_SampleClock,
244 NI_DO_SampleClock,
245 NI_FrequencyOutput,
246 NI_ChangeDetectionEvent,
247 NI_AnalogComparisonEvent,
248 0, /* Termination */
249 }
250 },
251 {
252 .dest = NI_PFI(7),
253 .src = (int[]){
254 TRIGGER_LINE(0),
255 TRIGGER_LINE(1),
256 TRIGGER_LINE(2),
257 TRIGGER_LINE(3),
258 TRIGGER_LINE(4),
259 TRIGGER_LINE(5),
260 TRIGGER_LINE(6),
261 TRIGGER_LINE(7),
262 NI_CtrSource(0),
263 NI_CtrSource(1),
264 NI_CtrGate(0),
265 NI_CtrGate(1),
266 NI_CtrInternalOutput(0),
267 NI_CtrInternalOutput(1),
268 NI_AI_SampleClock,
269 NI_AI_StartTrigger,
270 NI_AI_ReferenceTrigger,
271 NI_AI_ConvertClock,
272 NI_AO_SampleClock,
273 NI_AO_StartTrigger,
274 NI_DI_SampleClock,
275 NI_DO_SampleClock,
276 NI_FrequencyOutput,
277 NI_ChangeDetectionEvent,
278 NI_AnalogComparisonEvent,
279 0, /* Termination */
280 }
281 },
282 {
283 .dest = NI_PFI(8),
284 .src = (int[]){
285 TRIGGER_LINE(0),
286 TRIGGER_LINE(1),
287 TRIGGER_LINE(2),
288 TRIGGER_LINE(3),
289 TRIGGER_LINE(4),
290 TRIGGER_LINE(5),
291 TRIGGER_LINE(6),
292 TRIGGER_LINE(7),
293 NI_CtrSource(0),
294 NI_CtrSource(1),
295 NI_CtrGate(0),
296 NI_CtrGate(1),
297 NI_CtrInternalOutput(0),
298 NI_CtrInternalOutput(1),
299 NI_AI_SampleClock,
300 NI_AI_StartTrigger,
301 NI_AI_ReferenceTrigger,
302 NI_AI_ConvertClock,
303 NI_AO_SampleClock,
304 NI_AO_StartTrigger,
305 NI_DI_SampleClock,
306 NI_DO_SampleClock,
307 NI_FrequencyOutput,
308 NI_ChangeDetectionEvent,
309 NI_AnalogComparisonEvent,
310 0, /* Termination */
311 }
312 },
313 {
314 .dest = NI_PFI(9),
315 .src = (int[]){
316 TRIGGER_LINE(0),
317 TRIGGER_LINE(1),
318 TRIGGER_LINE(2),
319 TRIGGER_LINE(3),
320 TRIGGER_LINE(4),
321 TRIGGER_LINE(5),
322 TRIGGER_LINE(6),
323 TRIGGER_LINE(7),
324 NI_CtrSource(0),
325 NI_CtrSource(1),
326 NI_CtrGate(0),
327 NI_CtrGate(1),
328 NI_CtrInternalOutput(0),
329 NI_CtrInternalOutput(1),
330 NI_AI_SampleClock,
331 NI_AI_StartTrigger,
332 NI_AI_ReferenceTrigger,
333 NI_AI_ConvertClock,
334 NI_AO_SampleClock,
335 NI_AO_StartTrigger,
336 NI_DI_SampleClock,
337 NI_DO_SampleClock,
338 NI_FrequencyOutput,
339 NI_ChangeDetectionEvent,
340 NI_AnalogComparisonEvent,
341 0, /* Termination */
342 }
343 },
344 {
345 .dest = NI_PFI(10),
346 .src = (int[]){
347 TRIGGER_LINE(0),
348 TRIGGER_LINE(1),
349 TRIGGER_LINE(2),
350 TRIGGER_LINE(3),
351 TRIGGER_LINE(4),
352 TRIGGER_LINE(5),
353 TRIGGER_LINE(6),
354 TRIGGER_LINE(7),
355 NI_CtrSource(0),
356 NI_CtrSource(1),
357 NI_CtrGate(0),
358 NI_CtrGate(1),
359 NI_CtrInternalOutput(0),
360 NI_CtrInternalOutput(1),
361 NI_AI_SampleClock,
362 NI_AI_StartTrigger,
363 NI_AI_ReferenceTrigger,
364 NI_AI_ConvertClock,
365 NI_AO_SampleClock,
366 NI_AO_StartTrigger,
367 NI_DI_SampleClock,
368 NI_DO_SampleClock,
369 NI_FrequencyOutput,
370 NI_ChangeDetectionEvent,
371 NI_AnalogComparisonEvent,
372 0, /* Termination */
373 }
374 },
375 {
376 .dest = NI_PFI(11),
377 .src = (int[]){
378 TRIGGER_LINE(0),
379 TRIGGER_LINE(1),
380 TRIGGER_LINE(2),
381 TRIGGER_LINE(3),
382 TRIGGER_LINE(4),
383 TRIGGER_LINE(5),
384 TRIGGER_LINE(6),
385 TRIGGER_LINE(7),
386 NI_CtrSource(0),
387 NI_CtrSource(1),
388 NI_CtrGate(0),
389 NI_CtrGate(1),
390 NI_CtrInternalOutput(0),
391 NI_CtrInternalOutput(1),
392 NI_AI_SampleClock,
393 NI_AI_StartTrigger,
394 NI_AI_ReferenceTrigger,
395 NI_AI_ConvertClock,
396 NI_AO_SampleClock,
397 NI_AO_StartTrigger,
398 NI_DI_SampleClock,
399 NI_DO_SampleClock,
400 NI_FrequencyOutput,
401 NI_ChangeDetectionEvent,
402 NI_AnalogComparisonEvent,
403 0, /* Termination */
404 }
405 },
406 {
407 .dest = NI_PFI(12),
408 .src = (int[]){
409 TRIGGER_LINE(0),
410 TRIGGER_LINE(1),
411 TRIGGER_LINE(2),
412 TRIGGER_LINE(3),
413 TRIGGER_LINE(4),
414 TRIGGER_LINE(5),
415 TRIGGER_LINE(6),
416 TRIGGER_LINE(7),
417 NI_CtrSource(0),
418 NI_CtrSource(1),
419 NI_CtrGate(0),
420 NI_CtrGate(1),
421 NI_CtrInternalOutput(0),
422 NI_CtrInternalOutput(1),
423 NI_AI_SampleClock,
424 NI_AI_StartTrigger,
425 NI_AI_ReferenceTrigger,
426 NI_AI_ConvertClock,
427 NI_AO_SampleClock,
428 NI_AO_StartTrigger,
429 NI_DI_SampleClock,
430 NI_DO_SampleClock,
431 NI_FrequencyOutput,
432 NI_ChangeDetectionEvent,
433 NI_AnalogComparisonEvent,
434 0, /* Termination */
435 }
436 },
437 {
438 .dest = NI_PFI(13),
439 .src = (int[]){
440 TRIGGER_LINE(0),
441 TRIGGER_LINE(1),
442 TRIGGER_LINE(2),
443 TRIGGER_LINE(3),
444 TRIGGER_LINE(4),
445 TRIGGER_LINE(5),
446 TRIGGER_LINE(6),
447 TRIGGER_LINE(7),
448 NI_CtrSource(0),
449 NI_CtrSource(1),
450 NI_CtrGate(0),
451 NI_CtrGate(1),
452 NI_CtrInternalOutput(0),
453 NI_CtrInternalOutput(1),
454 NI_AI_SampleClock,
455 NI_AI_StartTrigger,
456 NI_AI_ReferenceTrigger,
457 NI_AI_ConvertClock,
458 NI_AO_SampleClock,
459 NI_AO_StartTrigger,
460 NI_DI_SampleClock,
461 NI_DO_SampleClock,
462 NI_FrequencyOutput,
463 NI_ChangeDetectionEvent,
464 NI_AnalogComparisonEvent,
465 0, /* Termination */
466 }
467 },
468 {
469 .dest = NI_PFI(14),
470 .src = (int[]){
471 TRIGGER_LINE(0),
472 TRIGGER_LINE(1),
473 TRIGGER_LINE(2),
474 TRIGGER_LINE(3),
475 TRIGGER_LINE(4),
476 TRIGGER_LINE(5),
477 TRIGGER_LINE(6),
478 TRIGGER_LINE(7),
479 NI_CtrSource(0),
480 NI_CtrSource(1),
481 NI_CtrGate(0),
482 NI_CtrGate(1),
483 NI_CtrInternalOutput(0),
484 NI_CtrInternalOutput(1),
485 NI_AI_SampleClock,
486 NI_AI_StartTrigger,
487 NI_AI_ReferenceTrigger,
488 NI_AI_ConvertClock,
489 NI_AO_SampleClock,
490 NI_AO_StartTrigger,
491 NI_DI_SampleClock,
492 NI_DO_SampleClock,
493 NI_FrequencyOutput,
494 NI_ChangeDetectionEvent,
495 NI_AnalogComparisonEvent,
496 0, /* Termination */
497 }
498 },
499 {
500 .dest = NI_PFI(15),
501 .src = (int[]){
502 TRIGGER_LINE(0),
503 TRIGGER_LINE(1),
504 TRIGGER_LINE(2),
505 TRIGGER_LINE(3),
506 TRIGGER_LINE(4),
507 TRIGGER_LINE(5),
508 TRIGGER_LINE(6),
509 TRIGGER_LINE(7),
510 NI_CtrSource(0),
511 NI_CtrSource(1),
512 NI_CtrGate(0),
513 NI_CtrGate(1),
514 NI_CtrInternalOutput(0),
515 NI_CtrInternalOutput(1),
516 NI_AI_SampleClock,
517 NI_AI_StartTrigger,
518 NI_AI_ReferenceTrigger,
519 NI_AI_ConvertClock,
520 NI_AO_SampleClock,
521 NI_AO_StartTrigger,
522 NI_DI_SampleClock,
523 NI_DO_SampleClock,
524 NI_FrequencyOutput,
525 NI_ChangeDetectionEvent,
526 NI_AnalogComparisonEvent,
527 0, /* Termination */
528 }
529 },
530 {
531 .dest = TRIGGER_LINE(0),
532 .src = (int[]){
533 NI_PFI(0),
534 NI_PFI(1),
535 NI_PFI(2),
536 NI_PFI(3),
537 NI_PFI(4),
538 NI_PFI(5),
539 NI_CtrSource(0),
540 NI_CtrSource(1),
541 NI_CtrGate(0),
542 NI_CtrGate(1),
543 NI_CtrInternalOutput(0),
544 NI_CtrInternalOutput(1),
545 NI_AI_SampleClock,
546 NI_AI_StartTrigger,
547 NI_AI_ReferenceTrigger,
548 NI_AI_ConvertClock,
549 NI_AI_PauseTrigger,
550 NI_AO_SampleClock,
551 NI_AO_StartTrigger,
552 NI_AO_PauseTrigger,
553 NI_10MHzRefClock,
554 NI_FrequencyOutput,
555 NI_ChangeDetectionEvent,
556 NI_AnalogComparisonEvent,
557 0, /* Termination */
558 }
559 },
560 {
561 .dest = TRIGGER_LINE(1),
562 .src = (int[]){
563 NI_PFI(0),
564 NI_PFI(1),
565 NI_PFI(2),
566 NI_PFI(3),
567 NI_PFI(4),
568 NI_PFI(5),
569 NI_CtrSource(0),
570 NI_CtrSource(1),
571 NI_CtrGate(0),
572 NI_CtrGate(1),
573 NI_CtrInternalOutput(0),
574 NI_CtrInternalOutput(1),
575 NI_AI_SampleClock,
576 NI_AI_StartTrigger,
577 NI_AI_ReferenceTrigger,
578 NI_AI_ConvertClock,
579 NI_AI_PauseTrigger,
580 NI_AO_SampleClock,
581 NI_AO_StartTrigger,
582 NI_AO_PauseTrigger,
583 NI_10MHzRefClock,
584 NI_FrequencyOutput,
585 NI_ChangeDetectionEvent,
586 NI_AnalogComparisonEvent,
587 0, /* Termination */
588 }
589 },
590 {
591 .dest = TRIGGER_LINE(2),
592 .src = (int[]){
593 NI_PFI(0),
594 NI_PFI(1),
595 NI_PFI(2),
596 NI_PFI(3),
597 NI_PFI(4),
598 NI_PFI(5),
599 NI_CtrSource(0),
600 NI_CtrSource(1),
601 NI_CtrGate(0),
602 NI_CtrGate(1),
603 NI_CtrInternalOutput(0),
604 NI_CtrInternalOutput(1),
605 NI_AI_SampleClock,
606 NI_AI_StartTrigger,
607 NI_AI_ReferenceTrigger,
608 NI_AI_ConvertClock,
609 NI_AI_PauseTrigger,
610 NI_AO_SampleClock,
611 NI_AO_StartTrigger,
612 NI_AO_PauseTrigger,
613 NI_10MHzRefClock,
614 NI_FrequencyOutput,
615 NI_ChangeDetectionEvent,
616 NI_AnalogComparisonEvent,
617 0, /* Termination */
618 }
619 },
620 {
621 .dest = TRIGGER_LINE(3),
622 .src = (int[]){
623 NI_PFI(0),
624 NI_PFI(1),
625 NI_PFI(2),
626 NI_PFI(3),
627 NI_PFI(4),
628 NI_PFI(5),
629 NI_CtrSource(0),
630 NI_CtrSource(1),
631 NI_CtrGate(0),
632 NI_CtrGate(1),
633 NI_CtrInternalOutput(0),
634 NI_CtrInternalOutput(1),
635 NI_AI_SampleClock,
636 NI_AI_StartTrigger,
637 NI_AI_ReferenceTrigger,
638 NI_AI_ConvertClock,
639 NI_AI_PauseTrigger,
640 NI_AO_SampleClock,
641 NI_AO_StartTrigger,
642 NI_AO_PauseTrigger,
643 NI_10MHzRefClock,
644 NI_FrequencyOutput,
645 NI_ChangeDetectionEvent,
646 NI_AnalogComparisonEvent,
647 0, /* Termination */
648 }
649 },
650 {
651 .dest = TRIGGER_LINE(4),
652 .src = (int[]){
653 NI_PFI(0),
654 NI_PFI(1),
655 NI_PFI(2),
656 NI_PFI(3),
657 NI_PFI(4),
658 NI_PFI(5),
659 NI_CtrSource(0),
660 NI_CtrSource(1),
661 NI_CtrGate(0),
662 NI_CtrGate(1),
663 NI_CtrInternalOutput(0),
664 NI_CtrInternalOutput(1),
665 NI_AI_SampleClock,
666 NI_AI_StartTrigger,
667 NI_AI_ReferenceTrigger,
668 NI_AI_ConvertClock,
669 NI_AI_PauseTrigger,
670 NI_AO_SampleClock,
671 NI_AO_StartTrigger,
672 NI_AO_PauseTrigger,
673 NI_10MHzRefClock,
674 NI_FrequencyOutput,
675 NI_ChangeDetectionEvent,
676 NI_AnalogComparisonEvent,
677 0, /* Termination */
678 }
679 },
680 {
681 .dest = TRIGGER_LINE(5),
682 .src = (int[]){
683 NI_PFI(0),
684 NI_PFI(1),
685 NI_PFI(2),
686 NI_PFI(3),
687 NI_PFI(4),
688 NI_PFI(5),
689 NI_CtrSource(0),
690 NI_CtrSource(1),
691 NI_CtrGate(0),
692 NI_CtrGate(1),
693 NI_CtrInternalOutput(0),
694 NI_CtrInternalOutput(1),
695 NI_AI_SampleClock,
696 NI_AI_StartTrigger,
697 NI_AI_ReferenceTrigger,
698 NI_AI_ConvertClock,
699 NI_AI_PauseTrigger,
700 NI_AO_SampleClock,
701 NI_AO_StartTrigger,
702 NI_AO_PauseTrigger,
703 NI_10MHzRefClock,
704 NI_FrequencyOutput,
705 NI_ChangeDetectionEvent,
706 NI_AnalogComparisonEvent,
707 0, /* Termination */
708 }
709 },
710 {
711 .dest = TRIGGER_LINE(6),
712 .src = (int[]){
713 NI_PFI(0),
714 NI_PFI(1),
715 NI_PFI(2),
716 NI_PFI(3),
717 NI_PFI(4),
718 NI_PFI(5),
719 NI_CtrSource(0),
720 NI_CtrSource(1),
721 NI_CtrGate(0),
722 NI_CtrGate(1),
723 NI_CtrInternalOutput(0),
724 NI_CtrInternalOutput(1),
725 NI_AI_SampleClock,
726 NI_AI_StartTrigger,
727 NI_AI_ReferenceTrigger,
728 NI_AI_ConvertClock,
729 NI_AI_PauseTrigger,
730 NI_AO_SampleClock,
731 NI_AO_StartTrigger,
732 NI_AO_PauseTrigger,
733 NI_10MHzRefClock,
734 NI_FrequencyOutput,
735 NI_ChangeDetectionEvent,
736 NI_AnalogComparisonEvent,
737 0, /* Termination */
738 }
739 },
740 {
741 .dest = TRIGGER_LINE(7),
742 .src = (int[]){
743 NI_PFI(0),
744 NI_PFI(1),
745 NI_PFI(2),
746 NI_PFI(3),
747 NI_PFI(4),
748 NI_PFI(5),
749 NI_CtrSource(0),
750 NI_CtrSource(1),
751 NI_CtrGate(0),
752 NI_CtrGate(1),
753 NI_CtrInternalOutput(0),
754 NI_CtrInternalOutput(1),
755 NI_AI_SampleClock,
756 NI_AI_StartTrigger,
757 NI_AI_ReferenceTrigger,
758 NI_AI_ConvertClock,
759 NI_AI_PauseTrigger,
760 NI_AO_SampleClock,
761 NI_AO_StartTrigger,
762 NI_AO_PauseTrigger,
763 NI_10MHzRefClock,
764 NI_FrequencyOutput,
765 NI_ChangeDetectionEvent,
766 NI_AnalogComparisonEvent,
767 0, /* Termination */
768 }
769 },
770 {
771 .dest = NI_CtrSource(0),
772 .src = (int[]){
773 NI_PFI(0),
774 NI_PFI(1),
775 NI_PFI(2),
776 NI_PFI(3),
777 NI_PFI(4),
778 NI_PFI(5),
779 NI_PFI(6),
780 NI_PFI(7),
781 NI_PFI(8),
782 NI_PFI(9),
783 NI_PFI(10),
784 NI_PFI(11),
785 NI_PFI(12),
786 NI_PFI(13),
787 NI_PFI(14),
788 NI_PFI(15),
789 TRIGGER_LINE(0),
790 TRIGGER_LINE(1),
791 TRIGGER_LINE(2),
792 TRIGGER_LINE(3),
793 TRIGGER_LINE(4),
794 TRIGGER_LINE(5),
795 TRIGGER_LINE(6),
796 TRIGGER_LINE(7),
797 NI_CtrGate(1),
798 PXI_Clk10,
799 NI_20MHzTimebase,
800 NI_80MHzTimebase,
801 NI_100kHzTimebase,
802 NI_AnalogComparisonEvent,
803 0, /* Termination */
804 }
805 },
806 {
807 .dest = NI_CtrSource(1),
808 .src = (int[]){
809 NI_PFI(0),
810 NI_PFI(1),
811 NI_PFI(2),
812 NI_PFI(3),
813 NI_PFI(4),
814 NI_PFI(5),
815 NI_PFI(6),
816 NI_PFI(7),
817 NI_PFI(8),
818 NI_PFI(9),
819 NI_PFI(10),
820 NI_PFI(11),
821 NI_PFI(12),
822 NI_PFI(13),
823 NI_PFI(14),
824 NI_PFI(15),
825 TRIGGER_LINE(0),
826 TRIGGER_LINE(1),
827 TRIGGER_LINE(2),
828 TRIGGER_LINE(3),
829 TRIGGER_LINE(4),
830 TRIGGER_LINE(5),
831 TRIGGER_LINE(6),
832 TRIGGER_LINE(7),
833 NI_CtrGate(0),
834 PXI_Clk10,
835 NI_20MHzTimebase,
836 NI_80MHzTimebase,
837 NI_100kHzTimebase,
838 NI_AnalogComparisonEvent,
839 0, /* Termination */
840 }
841 },
842 {
843 .dest = NI_CtrGate(0),
844 .src = (int[]){
845 NI_PFI(0),
846 NI_PFI(1),
847 NI_PFI(2),
848 NI_PFI(3),
849 NI_PFI(4),
850 NI_PFI(5),
851 NI_PFI(6),
852 NI_PFI(7),
853 NI_PFI(8),
854 NI_PFI(9),
855 NI_PFI(10),
856 NI_PFI(11),
857 NI_PFI(12),
858 NI_PFI(13),
859 NI_PFI(14),
860 NI_PFI(15),
861 TRIGGER_LINE(0),
862 TRIGGER_LINE(1),
863 TRIGGER_LINE(2),
864 TRIGGER_LINE(3),
865 TRIGGER_LINE(4),
866 TRIGGER_LINE(5),
867 TRIGGER_LINE(6),
868 TRIGGER_LINE(7),
869 NI_CtrSource(1),
870 NI_CtrInternalOutput(1),
871 NI_AI_StartTrigger,
872 NI_AI_ReferenceTrigger,
873 NI_AnalogComparisonEvent,
874 0, /* Termination */
875 }
876 },
877 {
878 .dest = NI_CtrGate(1),
879 .src = (int[]){
880 NI_PFI(0),
881 NI_PFI(1),
882 NI_PFI(2),
883 NI_PFI(3),
884 NI_PFI(4),
885 NI_PFI(5),
886 NI_PFI(6),
887 NI_PFI(7),
888 NI_PFI(8),
889 NI_PFI(9),
890 NI_PFI(10),
891 NI_PFI(11),
892 NI_PFI(12),
893 NI_PFI(13),
894 NI_PFI(14),
895 NI_PFI(15),
896 TRIGGER_LINE(0),
897 TRIGGER_LINE(1),
898 TRIGGER_LINE(2),
899 TRIGGER_LINE(3),
900 TRIGGER_LINE(4),
901 TRIGGER_LINE(5),
902 TRIGGER_LINE(6),
903 TRIGGER_LINE(7),
904 NI_CtrSource(0),
905 NI_CtrInternalOutput(0),
906 NI_AI_StartTrigger,
907 NI_AI_ReferenceTrigger,
908 NI_AnalogComparisonEvent,
909 0, /* Termination */
910 }
911 },
912 {
913 .dest = NI_CtrAux(0),
914 .src = (int[]){
915 NI_PFI(0),
916 NI_PFI(1),
917 NI_PFI(2),
918 NI_PFI(3),
919 NI_PFI(4),
920 NI_PFI(5),
921 NI_PFI(6),
922 NI_PFI(7),
923 NI_PFI(8),
924 NI_PFI(9),
925 NI_PFI(10),
926 NI_PFI(11),
927 NI_PFI(12),
928 NI_PFI(13),
929 NI_PFI(14),
930 NI_PFI(15),
931 TRIGGER_LINE(0),
932 TRIGGER_LINE(1),
933 TRIGGER_LINE(2),
934 TRIGGER_LINE(3),
935 TRIGGER_LINE(4),
936 TRIGGER_LINE(5),
937 TRIGGER_LINE(6),
938 TRIGGER_LINE(7),
939 NI_CtrSource(1),
940 NI_CtrGate(0),
941 NI_CtrGate(1),
942 NI_CtrInternalOutput(1),
943 NI_AI_StartTrigger,
944 NI_AI_ReferenceTrigger,
945 NI_AnalogComparisonEvent,
946 0, /* Termination */
947 }
948 },
949 {
950 .dest = NI_CtrAux(1),
951 .src = (int[]){
952 NI_PFI(0),
953 NI_PFI(1),
954 NI_PFI(2),
955 NI_PFI(3),
956 NI_PFI(4),
957 NI_PFI(5),
958 NI_PFI(6),
959 NI_PFI(7),
960 NI_PFI(8),
961 NI_PFI(9),
962 NI_PFI(10),
963 NI_PFI(11),
964 NI_PFI(12),
965 NI_PFI(13),
966 NI_PFI(14),
967 NI_PFI(15),
968 TRIGGER_LINE(0),
969 TRIGGER_LINE(1),
970 TRIGGER_LINE(2),
971 TRIGGER_LINE(3),
972 TRIGGER_LINE(4),
973 TRIGGER_LINE(5),
974 TRIGGER_LINE(6),
975 TRIGGER_LINE(7),
976 NI_CtrSource(0),
977 NI_CtrGate(0),
978 NI_CtrGate(1),
979 NI_CtrInternalOutput(0),
980 NI_AI_StartTrigger,
981 NI_AI_ReferenceTrigger,
982 NI_AnalogComparisonEvent,
983 0, /* Termination */
984 }
985 },
986 {
987 .dest = NI_CtrA(0),
988 .src = (int[]){
989 NI_PFI(0),
990 NI_PFI(1),
991 NI_PFI(2),
992 NI_PFI(3),
993 NI_PFI(4),
994 NI_PFI(5),
995 NI_PFI(6),
996 NI_PFI(7),
997 NI_PFI(8),
998 NI_PFI(9),
999 NI_PFI(10),
1000 NI_PFI(11),
1001 NI_PFI(12),
1002 NI_PFI(13),
1003 NI_PFI(14),
1004 NI_PFI(15),
1005 TRIGGER_LINE(0),
1006 TRIGGER_LINE(1),
1007 TRIGGER_LINE(2),
1008 TRIGGER_LINE(3),
1009 TRIGGER_LINE(4),
1010 TRIGGER_LINE(5),
1011 TRIGGER_LINE(6),
1012 TRIGGER_LINE(7),
1013 NI_AnalogComparisonEvent,
1014 0, /* Termination */
1015 }
1016 },
1017 {
1018 .dest = NI_CtrA(1),
1019 .src = (int[]){
1020 NI_PFI(0),
1021 NI_PFI(1),
1022 NI_PFI(2),
1023 NI_PFI(3),
1024 NI_PFI(4),
1025 NI_PFI(5),
1026 NI_PFI(6),
1027 NI_PFI(7),
1028 NI_PFI(8),
1029 NI_PFI(9),
1030 NI_PFI(10),
1031 NI_PFI(11),
1032 NI_PFI(12),
1033 NI_PFI(13),
1034 NI_PFI(14),
1035 NI_PFI(15),
1036 TRIGGER_LINE(0),
1037 TRIGGER_LINE(1),
1038 TRIGGER_LINE(2),
1039 TRIGGER_LINE(3),
1040 TRIGGER_LINE(4),
1041 TRIGGER_LINE(5),
1042 TRIGGER_LINE(6),
1043 TRIGGER_LINE(7),
1044 NI_AnalogComparisonEvent,
1045 0, /* Termination */
1046 }
1047 },
1048 {
1049 .dest = NI_CtrB(0),
1050 .src = (int[]){
1051 NI_PFI(0),
1052 NI_PFI(1),
1053 NI_PFI(2),
1054 NI_PFI(3),
1055 NI_PFI(4),
1056 NI_PFI(5),
1057 NI_PFI(6),
1058 NI_PFI(7),
1059 NI_PFI(8),
1060 NI_PFI(9),
1061 NI_PFI(10),
1062 NI_PFI(11),
1063 NI_PFI(12),
1064 NI_PFI(13),
1065 NI_PFI(14),
1066 NI_PFI(15),
1067 TRIGGER_LINE(0),
1068 TRIGGER_LINE(1),
1069 TRIGGER_LINE(2),
1070 TRIGGER_LINE(3),
1071 TRIGGER_LINE(4),
1072 TRIGGER_LINE(5),
1073 TRIGGER_LINE(6),
1074 TRIGGER_LINE(7),
1075 NI_AnalogComparisonEvent,
1076 0, /* Termination */
1077 }
1078 },
1079 {
1080 .dest = NI_CtrB(1),
1081 .src = (int[]){
1082 NI_PFI(0),
1083 NI_PFI(1),
1084 NI_PFI(2),
1085 NI_PFI(3),
1086 NI_PFI(4),
1087 NI_PFI(5),
1088 NI_PFI(6),
1089 NI_PFI(7),
1090 NI_PFI(8),
1091 NI_PFI(9),
1092 NI_PFI(10),
1093 NI_PFI(11),
1094 NI_PFI(12),
1095 NI_PFI(13),
1096 NI_PFI(14),
1097 NI_PFI(15),
1098 TRIGGER_LINE(0),
1099 TRIGGER_LINE(1),
1100 TRIGGER_LINE(2),
1101 TRIGGER_LINE(3),
1102 TRIGGER_LINE(4),
1103 TRIGGER_LINE(5),
1104 TRIGGER_LINE(6),
1105 TRIGGER_LINE(7),
1106 NI_AnalogComparisonEvent,
1107 0, /* Termination */
1108 }
1109 },
1110 {
1111 .dest = NI_CtrZ(0),
1112 .src = (int[]){
1113 NI_PFI(0),
1114 NI_PFI(1),
1115 NI_PFI(2),
1116 NI_PFI(3),
1117 NI_PFI(4),
1118 NI_PFI(5),
1119 NI_PFI(6),
1120 NI_PFI(7),
1121 NI_PFI(8),
1122 NI_PFI(9),
1123 NI_PFI(10),
1124 NI_PFI(11),
1125 NI_PFI(12),
1126 NI_PFI(13),
1127 NI_PFI(14),
1128 NI_PFI(15),
1129 TRIGGER_LINE(0),
1130 TRIGGER_LINE(1),
1131 TRIGGER_LINE(2),
1132 TRIGGER_LINE(3),
1133 TRIGGER_LINE(4),
1134 TRIGGER_LINE(5),
1135 TRIGGER_LINE(6),
1136 TRIGGER_LINE(7),
1137 NI_AnalogComparisonEvent,
1138 0, /* Termination */
1139 }
1140 },
1141 {
1142 .dest = NI_CtrZ(1),
1143 .src = (int[]){
1144 NI_PFI(0),
1145 NI_PFI(1),
1146 NI_PFI(2),
1147 NI_PFI(3),
1148 NI_PFI(4),
1149 NI_PFI(5),
1150 NI_PFI(6),
1151 NI_PFI(7),
1152 NI_PFI(8),
1153 NI_PFI(9),
1154 NI_PFI(10),
1155 NI_PFI(11),
1156 NI_PFI(12),
1157 NI_PFI(13),
1158 NI_PFI(14),
1159 NI_PFI(15),
1160 TRIGGER_LINE(0),
1161 TRIGGER_LINE(1),
1162 TRIGGER_LINE(2),
1163 TRIGGER_LINE(3),
1164 TRIGGER_LINE(4),
1165 TRIGGER_LINE(5),
1166 TRIGGER_LINE(6),
1167 TRIGGER_LINE(7),
1168 NI_AnalogComparisonEvent,
1169 0, /* Termination */
1170 }
1171 },
1172 {
1173 .dest = NI_CtrArmStartTrigger(0),
1174 .src = (int[]){
1175 NI_PFI(0),
1176 NI_PFI(1),
1177 NI_PFI(2),
1178 NI_PFI(3),
1179 NI_PFI(4),
1180 NI_PFI(5),
1181 NI_PFI(6),
1182 NI_PFI(7),
1183 NI_PFI(8),
1184 NI_PFI(9),
1185 NI_PFI(10),
1186 NI_PFI(11),
1187 NI_PFI(12),
1188 NI_PFI(13),
1189 NI_PFI(14),
1190 NI_PFI(15),
1191 TRIGGER_LINE(0),
1192 TRIGGER_LINE(1),
1193 TRIGGER_LINE(2),
1194 TRIGGER_LINE(3),
1195 TRIGGER_LINE(4),
1196 TRIGGER_LINE(5),
1197 TRIGGER_LINE(6),
1198 TRIGGER_LINE(7),
1199 NI_CtrInternalOutput(1),
1200 NI_AI_StartTrigger,
1201 NI_AI_ReferenceTrigger,
1202 NI_AnalogComparisonEvent,
1203 0, /* Termination */
1204 }
1205 },
1206 {
1207 .dest = NI_CtrArmStartTrigger(1),
1208 .src = (int[]){
1209 NI_PFI(0),
1210 NI_PFI(1),
1211 NI_PFI(2),
1212 NI_PFI(3),
1213 NI_PFI(4),
1214 NI_PFI(5),
1215 NI_PFI(6),
1216 NI_PFI(7),
1217 NI_PFI(8),
1218 NI_PFI(9),
1219 NI_PFI(10),
1220 NI_PFI(11),
1221 NI_PFI(12),
1222 NI_PFI(13),
1223 NI_PFI(14),
1224 NI_PFI(15),
1225 TRIGGER_LINE(0),
1226 TRIGGER_LINE(1),
1227 TRIGGER_LINE(2),
1228 TRIGGER_LINE(3),
1229 TRIGGER_LINE(4),
1230 TRIGGER_LINE(5),
1231 TRIGGER_LINE(6),
1232 TRIGGER_LINE(7),
1233 NI_CtrInternalOutput(0),
1234 NI_AI_StartTrigger,
1235 NI_AI_ReferenceTrigger,
1236 NI_AnalogComparisonEvent,
1237 0, /* Termination */
1238 }
1239 },
1240 {
1241 .dest = NI_AI_SampleClock,
1242 .src = (int[]){
1243 NI_PFI(0),
1244 NI_PFI(1),
1245 NI_PFI(2),
1246 NI_PFI(3),
1247 NI_PFI(4),
1248 NI_PFI(5),
1249 NI_PFI(6),
1250 NI_PFI(7),
1251 NI_PFI(8),
1252 NI_PFI(9),
1253 NI_PFI(10),
1254 NI_PFI(11),
1255 NI_PFI(12),
1256 NI_PFI(13),
1257 NI_PFI(14),
1258 NI_PFI(15),
1259 TRIGGER_LINE(0),
1260 TRIGGER_LINE(1),
1261 TRIGGER_LINE(2),
1262 TRIGGER_LINE(3),
1263 TRIGGER_LINE(4),
1264 TRIGGER_LINE(5),
1265 TRIGGER_LINE(6),
1266 TRIGGER_LINE(7),
1267 NI_CtrInternalOutput(0),
1268 NI_CtrInternalOutput(1),
1269 NI_AI_SampleClockTimebase,
1270 NI_AnalogComparisonEvent,
1271 0, /* Termination */
1272 }
1273 },
1274 {
1275 .dest = NI_AI_SampleClockTimebase,
1276 .src = (int[]){
1277 NI_PFI(0),
1278 NI_PFI(1),
1279 NI_PFI(2),
1280 NI_PFI(3),
1281 NI_PFI(4),
1282 NI_PFI(5),
1283 NI_PFI(6),
1284 NI_PFI(7),
1285 NI_PFI(8),
1286 NI_PFI(9),
1287 NI_PFI(10),
1288 NI_PFI(11),
1289 NI_PFI(12),
1290 NI_PFI(13),
1291 NI_PFI(14),
1292 NI_PFI(15),
1293 TRIGGER_LINE(0),
1294 TRIGGER_LINE(1),
1295 TRIGGER_LINE(2),
1296 TRIGGER_LINE(3),
1297 TRIGGER_LINE(4),
1298 TRIGGER_LINE(5),
1299 TRIGGER_LINE(6),
1300 TRIGGER_LINE(7),
1301 PXI_Clk10,
1302 NI_20MHzTimebase,
1303 NI_100kHzTimebase,
1304 NI_AnalogComparisonEvent,
1305 0, /* Termination */
1306 }
1307 },
1308 {
1309 .dest = NI_AI_StartTrigger,
1310 .src = (int[]){
1311 NI_PFI(0),
1312 NI_PFI(1),
1313 NI_PFI(2),
1314 NI_PFI(3),
1315 NI_PFI(4),
1316 NI_PFI(5),
1317 NI_PFI(6),
1318 NI_PFI(7),
1319 NI_PFI(8),
1320 NI_PFI(9),
1321 NI_PFI(10),
1322 NI_PFI(11),
1323 NI_PFI(12),
1324 NI_PFI(13),
1325 NI_PFI(14),
1326 NI_PFI(15),
1327 TRIGGER_LINE(0),
1328 TRIGGER_LINE(1),
1329 TRIGGER_LINE(2),
1330 TRIGGER_LINE(3),
1331 TRIGGER_LINE(4),
1332 TRIGGER_LINE(5),
1333 TRIGGER_LINE(6),
1334 TRIGGER_LINE(7),
1335 NI_CtrInternalOutput(0),
1336 NI_CtrInternalOutput(1),
1337 NI_AnalogComparisonEvent,
1338 0, /* Termination */
1339 }
1340 },
1341 {
1342 .dest = NI_AI_ReferenceTrigger,
1343 .src = (int[]){
1344 NI_PFI(0),
1345 NI_PFI(1),
1346 NI_PFI(2),
1347 NI_PFI(3),
1348 NI_PFI(4),
1349 NI_PFI(5),
1350 NI_PFI(6),
1351 NI_PFI(7),
1352 NI_PFI(8),
1353 NI_PFI(9),
1354 NI_PFI(10),
1355 NI_PFI(11),
1356 NI_PFI(12),
1357 NI_PFI(13),
1358 NI_PFI(14),
1359 NI_PFI(15),
1360 TRIGGER_LINE(0),
1361 TRIGGER_LINE(1),
1362 TRIGGER_LINE(2),
1363 TRIGGER_LINE(3),
1364 TRIGGER_LINE(4),
1365 TRIGGER_LINE(5),
1366 TRIGGER_LINE(6),
1367 TRIGGER_LINE(7),
1368 NI_AnalogComparisonEvent,
1369 0, /* Termination */
1370 }
1371 },
1372 {
1373 .dest = NI_AI_ConvertClock,
1374 .src = (int[]){
1375 NI_PFI(0),
1376 NI_PFI(1),
1377 NI_PFI(2),
1378 NI_PFI(3),
1379 NI_PFI(4),
1380 NI_PFI(5),
1381 NI_PFI(6),
1382 NI_PFI(7),
1383 NI_PFI(8),
1384 NI_PFI(9),
1385 NI_PFI(10),
1386 NI_PFI(11),
1387 NI_PFI(12),
1388 NI_PFI(13),
1389 NI_PFI(14),
1390 NI_PFI(15),
1391 TRIGGER_LINE(0),
1392 TRIGGER_LINE(1),
1393 TRIGGER_LINE(2),
1394 TRIGGER_LINE(3),
1395 TRIGGER_LINE(4),
1396 TRIGGER_LINE(5),
1397 TRIGGER_LINE(6),
1398 TRIGGER_LINE(7),
1399 NI_CtrInternalOutput(0),
1400 NI_CtrInternalOutput(1),
1401 NI_AI_ConvertClockTimebase,
1402 NI_AnalogComparisonEvent,
1403 0, /* Termination */
1404 }
1405 },
1406 {
1407 .dest = NI_AI_ConvertClockTimebase,
1408 .src = (int[]){
1409 NI_AI_SampleClockTimebase,
1410 NI_20MHzTimebase,
1411 0, /* Termination */
1412 }
1413 },
1414 {
1415 .dest = NI_AI_PauseTrigger,
1416 .src = (int[]){
1417 NI_PFI(0),
1418 NI_PFI(1),
1419 NI_PFI(2),
1420 NI_PFI(3),
1421 NI_PFI(4),
1422 NI_PFI(5),
1423 NI_PFI(6),
1424 NI_PFI(7),
1425 NI_PFI(8),
1426 NI_PFI(9),
1427 NI_PFI(10),
1428 NI_PFI(11),
1429 NI_PFI(12),
1430 NI_PFI(13),
1431 NI_PFI(14),
1432 NI_PFI(15),
1433 TRIGGER_LINE(0),
1434 TRIGGER_LINE(1),
1435 TRIGGER_LINE(2),
1436 TRIGGER_LINE(3),
1437 TRIGGER_LINE(4),
1438 TRIGGER_LINE(5),
1439 TRIGGER_LINE(6),
1440 TRIGGER_LINE(7),
1441 NI_AnalogComparisonEvent,
1442 0, /* Termination */
1443 }
1444 },
1445 {
1446 .dest = NI_AO_SampleClock,
1447 .src = (int[]){
1448 NI_PFI(0),
1449 NI_PFI(1),
1450 NI_PFI(2),
1451 NI_PFI(3),
1452 NI_PFI(4),
1453 NI_PFI(5),
1454 NI_PFI(6),
1455 NI_PFI(7),
1456 NI_PFI(8),
1457 NI_PFI(9),
1458 NI_PFI(10),
1459 NI_PFI(11),
1460 NI_PFI(12),
1461 NI_PFI(13),
1462 NI_PFI(14),
1463 NI_PFI(15),
1464 TRIGGER_LINE(0),
1465 TRIGGER_LINE(1),
1466 TRIGGER_LINE(2),
1467 TRIGGER_LINE(3),
1468 TRIGGER_LINE(4),
1469 TRIGGER_LINE(5),
1470 TRIGGER_LINE(6),
1471 TRIGGER_LINE(7),
1472 NI_CtrInternalOutput(0),
1473 NI_CtrInternalOutput(1),
1474 NI_AO_SampleClockTimebase,
1475 NI_AnalogComparisonEvent,
1476 0, /* Termination */
1477 }
1478 },
1479 {
1480 .dest = NI_AO_SampleClockTimebase,
1481 .src = (int[]){
1482 NI_PFI(0),
1483 NI_PFI(1),
1484 NI_PFI(2),
1485 NI_PFI(3),
1486 NI_PFI(4),
1487 NI_PFI(5),
1488 NI_PFI(6),
1489 NI_PFI(7),
1490 NI_PFI(8),
1491 NI_PFI(9),
1492 NI_PFI(10),
1493 NI_PFI(11),
1494 NI_PFI(12),
1495 NI_PFI(13),
1496 NI_PFI(14),
1497 NI_PFI(15),
1498 TRIGGER_LINE(0),
1499 TRIGGER_LINE(1),
1500 TRIGGER_LINE(2),
1501 TRIGGER_LINE(3),
1502 TRIGGER_LINE(4),
1503 TRIGGER_LINE(5),
1504 TRIGGER_LINE(6),
1505 TRIGGER_LINE(7),
1506 PXI_Clk10,
1507 NI_20MHzTimebase,
1508 NI_100kHzTimebase,
1509 NI_AnalogComparisonEvent,
1510 0, /* Termination */
1511 }
1512 },
1513 {
1514 .dest = NI_AO_StartTrigger,
1515 .src = (int[]){
1516 NI_PFI(0),
1517 NI_PFI(1),
1518 NI_PFI(2),
1519 NI_PFI(3),
1520 NI_PFI(4),
1521 NI_PFI(5),
1522 NI_PFI(6),
1523 NI_PFI(7),
1524 NI_PFI(8),
1525 NI_PFI(9),
1526 NI_PFI(10),
1527 NI_PFI(11),
1528 NI_PFI(12),
1529 NI_PFI(13),
1530 NI_PFI(14),
1531 NI_PFI(15),
1532 TRIGGER_LINE(0),
1533 TRIGGER_LINE(1),
1534 TRIGGER_LINE(2),
1535 TRIGGER_LINE(3),
1536 TRIGGER_LINE(4),
1537 TRIGGER_LINE(5),
1538 TRIGGER_LINE(6),
1539 TRIGGER_LINE(7),
1540 NI_AI_StartTrigger,
1541 NI_AnalogComparisonEvent,
1542 0, /* Termination */
1543 }
1544 },
1545 {
1546 .dest = NI_AO_PauseTrigger,
1547 .src = (int[]){
1548 NI_PFI(0),
1549 NI_PFI(1),
1550 NI_PFI(2),
1551 NI_PFI(3),
1552 NI_PFI(4),
1553 NI_PFI(5),
1554 NI_PFI(6),
1555 NI_PFI(7),
1556 NI_PFI(8),
1557 NI_PFI(9),
1558 NI_PFI(10),
1559 NI_PFI(11),
1560 NI_PFI(12),
1561 NI_PFI(13),
1562 NI_PFI(14),
1563 NI_PFI(15),
1564 TRIGGER_LINE(0),
1565 TRIGGER_LINE(1),
1566 TRIGGER_LINE(2),
1567 TRIGGER_LINE(3),
1568 TRIGGER_LINE(4),
1569 TRIGGER_LINE(5),
1570 TRIGGER_LINE(6),
1571 TRIGGER_LINE(7),
1572 NI_AnalogComparisonEvent,
1573 0, /* Termination */
1574 }
1575 },
1576 {
1577 .dest = NI_DI_SampleClock,
1578 .src = (int[]){
1579 NI_PFI(0),
1580 NI_PFI(1),
1581 NI_PFI(2),
1582 NI_PFI(3),
1583 NI_PFI(4),
1584 NI_PFI(5),
1585 NI_PFI(6),
1586 NI_PFI(7),
1587 NI_PFI(8),
1588 NI_PFI(9),
1589 NI_PFI(10),
1590 NI_PFI(11),
1591 NI_PFI(12),
1592 NI_PFI(13),
1593 NI_PFI(14),
1594 NI_PFI(15),
1595 TRIGGER_LINE(0),
1596 TRIGGER_LINE(1),
1597 TRIGGER_LINE(2),
1598 TRIGGER_LINE(3),
1599 TRIGGER_LINE(4),
1600 TRIGGER_LINE(5),
1601 TRIGGER_LINE(6),
1602 TRIGGER_LINE(7),
1603 NI_CtrInternalOutput(0),
1604 NI_CtrInternalOutput(1),
1605 NI_AI_SampleClock,
1606 NI_AI_ConvertClock,
1607 NI_AO_SampleClock,
1608 NI_FrequencyOutput,
1609 NI_ChangeDetectionEvent,
1610 NI_AnalogComparisonEvent,
1611 0, /* Termination */
1612 }
1613 },
1614 {
1615 .dest = NI_DO_SampleClock,
1616 .src = (int[]){
1617 NI_PFI(0),
1618 NI_PFI(1),
1619 NI_PFI(2),
1620 NI_PFI(3),
1621 NI_PFI(4),
1622 NI_PFI(5),
1623 NI_PFI(6),
1624 NI_PFI(7),
1625 NI_PFI(8),
1626 NI_PFI(9),
1627 NI_PFI(10),
1628 NI_PFI(11),
1629 NI_PFI(12),
1630 NI_PFI(13),
1631 NI_PFI(14),
1632 NI_PFI(15),
1633 TRIGGER_LINE(0),
1634 TRIGGER_LINE(1),
1635 TRIGGER_LINE(2),
1636 TRIGGER_LINE(3),
1637 TRIGGER_LINE(4),
1638 TRIGGER_LINE(5),
1639 TRIGGER_LINE(6),
1640 TRIGGER_LINE(7),
1641 NI_CtrInternalOutput(0),
1642 NI_CtrInternalOutput(1),
1643 NI_AI_SampleClock,
1644 NI_AI_ConvertClock,
1645 NI_AO_SampleClock,
1646 NI_FrequencyOutput,
1647 NI_ChangeDetectionEvent,
1648 NI_AnalogComparisonEvent,
1649 0, /* Termination */
1650 }
1651 },
1652 { /* Termination of list */
1653 .dest = 0,
1654 },
1655 },
1656};
diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxie-6535.c b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxie-6535.c
new file mode 100644
index 000000000000..2ebb679e0129
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxie-6535.c
@@ -0,0 +1,575 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routing/ni_device_routes/pxie-6535.c
5 * List of valid routes for specific NI boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21/*
22 * The contents of this file are generated using the tools in
23 * comedi/drivers/ni_routing/tools
24 *
25 * Please use those tools to help maintain the contents of this file.
26 */
27
28#include "../ni_device_routes.h"
29#include "all.h"
30
31struct ni_device_routes ni_pxie_6535_device_routes = {
32 .device = "pxie-6535",
33 .routes = (struct ni_route_set[]){
34 {
35 .dest = NI_PFI(0),
36 .src = (int[]){
37 NI_PFI(1),
38 NI_PFI(2),
39 NI_PFI(3),
40 NI_PFI(4),
41 NI_PFI(5),
42 TRIGGER_LINE(0),
43 TRIGGER_LINE(1),
44 TRIGGER_LINE(2),
45 TRIGGER_LINE(3),
46 TRIGGER_LINE(4),
47 TRIGGER_LINE(5),
48 TRIGGER_LINE(6),
49 NI_DI_StartTrigger,
50 NI_DI_ReferenceTrigger,
51 NI_DI_InputBufferFull,
52 NI_DI_ReadyForStartEvent,
53 NI_DI_ReadyForTransferEventBurst,
54 NI_DI_ReadyForTransferEventPipelined,
55 NI_DO_StartTrigger,
56 NI_DO_OutputBufferFull,
57 NI_DO_DataActiveEvent,
58 NI_DO_ReadyForStartEvent,
59 NI_DO_ReadyForTransferEvent,
60 NI_ChangeDetectionEvent,
61 0, /* Termination */
62 }
63 },
64 {
65 .dest = NI_PFI(1),
66 .src = (int[]){
67 NI_PFI(0),
68 NI_PFI(2),
69 NI_PFI(3),
70 NI_PFI(4),
71 NI_PFI(5),
72 TRIGGER_LINE(0),
73 TRIGGER_LINE(1),
74 TRIGGER_LINE(2),
75 TRIGGER_LINE(3),
76 TRIGGER_LINE(4),
77 TRIGGER_LINE(5),
78 TRIGGER_LINE(6),
79 NI_DI_StartTrigger,
80 NI_DI_ReferenceTrigger,
81 NI_DI_InputBufferFull,
82 NI_DI_ReadyForStartEvent,
83 NI_DI_ReadyForTransferEventBurst,
84 NI_DI_ReadyForTransferEventPipelined,
85 NI_DO_StartTrigger,
86 NI_DO_OutputBufferFull,
87 NI_DO_DataActiveEvent,
88 NI_DO_ReadyForStartEvent,
89 NI_DO_ReadyForTransferEvent,
90 NI_ChangeDetectionEvent,
91 0, /* Termination */
92 }
93 },
94 {
95 .dest = NI_PFI(2),
96 .src = (int[]){
97 NI_PFI(0),
98 NI_PFI(1),
99 NI_PFI(3),
100 NI_PFI(4),
101 NI_PFI(5),
102 TRIGGER_LINE(0),
103 TRIGGER_LINE(1),
104 TRIGGER_LINE(2),
105 TRIGGER_LINE(3),
106 TRIGGER_LINE(4),
107 TRIGGER_LINE(5),
108 TRIGGER_LINE(6),
109 NI_DI_StartTrigger,
110 NI_DI_ReferenceTrigger,
111 NI_DI_InputBufferFull,
112 NI_DI_ReadyForStartEvent,
113 NI_DI_ReadyForTransferEventBurst,
114 NI_DI_ReadyForTransferEventPipelined,
115 NI_DO_StartTrigger,
116 NI_DO_OutputBufferFull,
117 NI_DO_DataActiveEvent,
118 NI_DO_ReadyForStartEvent,
119 NI_DO_ReadyForTransferEvent,
120 NI_ChangeDetectionEvent,
121 0, /* Termination */
122 }
123 },
124 {
125 .dest = NI_PFI(3),
126 .src = (int[]){
127 NI_PFI(0),
128 NI_PFI(1),
129 NI_PFI(2),
130 NI_PFI(4),
131 NI_PFI(5),
132 TRIGGER_LINE(0),
133 TRIGGER_LINE(1),
134 TRIGGER_LINE(2),
135 TRIGGER_LINE(3),
136 TRIGGER_LINE(4),
137 TRIGGER_LINE(5),
138 TRIGGER_LINE(6),
139 NI_DI_StartTrigger,
140 NI_DI_ReferenceTrigger,
141 NI_DI_InputBufferFull,
142 NI_DI_ReadyForStartEvent,
143 NI_DI_ReadyForTransferEventBurst,
144 NI_DI_ReadyForTransferEventPipelined,
145 NI_DO_StartTrigger,
146 NI_DO_OutputBufferFull,
147 NI_DO_DataActiveEvent,
148 NI_DO_ReadyForStartEvent,
149 NI_DO_ReadyForTransferEvent,
150 NI_ChangeDetectionEvent,
151 0, /* Termination */
152 }
153 },
154 {
155 .dest = NI_PFI(4),
156 .src = (int[]){
157 NI_PFI(0),
158 NI_PFI(1),
159 NI_PFI(2),
160 NI_PFI(3),
161 NI_PFI(5),
162 TRIGGER_LINE(0),
163 TRIGGER_LINE(1),
164 TRIGGER_LINE(2),
165 TRIGGER_LINE(3),
166 TRIGGER_LINE(4),
167 TRIGGER_LINE(5),
168 TRIGGER_LINE(6),
169 TRIGGER_LINE(7),
170 NI_DI_StartTrigger,
171 NI_DI_ReferenceTrigger,
172 NI_DI_InputBufferFull,
173 NI_DI_ReadyForStartEvent,
174 NI_DI_ReadyForTransferEventBurst,
175 NI_DI_ReadyForTransferEventPipelined,
176 NI_DO_SampleClock,
177 NI_DO_StartTrigger,
178 NI_DO_OutputBufferFull,
179 NI_DO_DataActiveEvent,
180 NI_DO_ReadyForStartEvent,
181 NI_DO_ReadyForTransferEvent,
182 NI_ChangeDetectionEvent,
183 0, /* Termination */
184 }
185 },
186 {
187 .dest = NI_PFI(5),
188 .src = (int[]){
189 NI_PFI(0),
190 NI_PFI(1),
191 NI_PFI(2),
192 NI_PFI(3),
193 NI_PFI(4),
194 TRIGGER_LINE(0),
195 TRIGGER_LINE(1),
196 TRIGGER_LINE(2),
197 TRIGGER_LINE(3),
198 TRIGGER_LINE(4),
199 TRIGGER_LINE(5),
200 TRIGGER_LINE(6),
201 TRIGGER_LINE(7),
202 NI_DI_SampleClock,
203 NI_DI_StartTrigger,
204 NI_DI_ReferenceTrigger,
205 NI_DI_InputBufferFull,
206 NI_DI_ReadyForStartEvent,
207 NI_DI_ReadyForTransferEventBurst,
208 NI_DI_ReadyForTransferEventPipelined,
209 NI_DO_StartTrigger,
210 NI_DO_OutputBufferFull,
211 NI_DO_DataActiveEvent,
212 NI_DO_ReadyForStartEvent,
213 NI_DO_ReadyForTransferEvent,
214 NI_ChangeDetectionEvent,
215 0, /* Termination */
216 }
217 },
218 {
219 .dest = TRIGGER_LINE(0),
220 .src = (int[]){
221 NI_PFI(0),
222 NI_PFI(1),
223 NI_PFI(2),
224 NI_PFI(3),
225 NI_PFI(4),
226 NI_PFI(5),
227 TRIGGER_LINE(1),
228 TRIGGER_LINE(2),
229 TRIGGER_LINE(3),
230 TRIGGER_LINE(4),
231 TRIGGER_LINE(5),
232 TRIGGER_LINE(6),
233 NI_DI_StartTrigger,
234 NI_DI_ReferenceTrigger,
235 NI_DI_InputBufferFull,
236 NI_DI_ReadyForStartEvent,
237 NI_DI_ReadyForTransferEventBurst,
238 NI_DI_ReadyForTransferEventPipelined,
239 NI_DO_StartTrigger,
240 NI_DO_OutputBufferFull,
241 NI_DO_DataActiveEvent,
242 NI_DO_ReadyForStartEvent,
243 NI_DO_ReadyForTransferEvent,
244 NI_ChangeDetectionEvent,
245 0, /* Termination */
246 }
247 },
248 {
249 .dest = TRIGGER_LINE(1),
250 .src = (int[]){
251 NI_PFI(0),
252 NI_PFI(1),
253 NI_PFI(2),
254 NI_PFI(3),
255 NI_PFI(4),
256 NI_PFI(5),
257 TRIGGER_LINE(0),
258 TRIGGER_LINE(2),
259 TRIGGER_LINE(3),
260 TRIGGER_LINE(4),
261 TRIGGER_LINE(5),
262 TRIGGER_LINE(6),
263 NI_DI_StartTrigger,
264 NI_DI_ReferenceTrigger,
265 NI_DI_InputBufferFull,
266 NI_DI_ReadyForStartEvent,
267 NI_DI_ReadyForTransferEventBurst,
268 NI_DI_ReadyForTransferEventPipelined,
269 NI_DO_StartTrigger,
270 NI_DO_OutputBufferFull,
271 NI_DO_DataActiveEvent,
272 NI_DO_ReadyForStartEvent,
273 NI_DO_ReadyForTransferEvent,
274 NI_ChangeDetectionEvent,
275 0, /* Termination */
276 }
277 },
278 {
279 .dest = TRIGGER_LINE(2),
280 .src = (int[]){
281 NI_PFI(0),
282 NI_PFI(1),
283 NI_PFI(2),
284 NI_PFI(3),
285 NI_PFI(4),
286 NI_PFI(5),
287 TRIGGER_LINE(0),
288 TRIGGER_LINE(1),
289 TRIGGER_LINE(3),
290 TRIGGER_LINE(4),
291 TRIGGER_LINE(5),
292 TRIGGER_LINE(6),
293 NI_DI_StartTrigger,
294 NI_DI_ReferenceTrigger,
295 NI_DI_InputBufferFull,
296 NI_DI_ReadyForStartEvent,
297 NI_DI_ReadyForTransferEventBurst,
298 NI_DI_ReadyForTransferEventPipelined,
299 NI_DO_StartTrigger,
300 NI_DO_OutputBufferFull,
301 NI_DO_DataActiveEvent,
302 NI_DO_ReadyForStartEvent,
303 NI_DO_ReadyForTransferEvent,
304 NI_ChangeDetectionEvent,
305 0, /* Termination */
306 }
307 },
308 {
309 .dest = TRIGGER_LINE(3),
310 .src = (int[]){
311 NI_PFI(0),
312 NI_PFI(1),
313 NI_PFI(2),
314 NI_PFI(3),
315 NI_PFI(4),
316 NI_PFI(5),
317 TRIGGER_LINE(0),
318 TRIGGER_LINE(1),
319 TRIGGER_LINE(2),
320 TRIGGER_LINE(4),
321 TRIGGER_LINE(5),
322 TRIGGER_LINE(6),
323 NI_DI_StartTrigger,
324 NI_DI_ReferenceTrigger,
325 NI_DI_InputBufferFull,
326 NI_DI_ReadyForStartEvent,
327 NI_DI_ReadyForTransferEventBurst,
328 NI_DI_ReadyForTransferEventPipelined,
329 NI_DO_StartTrigger,
330 NI_DO_OutputBufferFull,
331 NI_DO_DataActiveEvent,
332 NI_DO_ReadyForStartEvent,
333 NI_DO_ReadyForTransferEvent,
334 NI_ChangeDetectionEvent,
335 0, /* Termination */
336 }
337 },
338 {
339 .dest = TRIGGER_LINE(4),
340 .src = (int[]){
341 NI_PFI(0),
342 NI_PFI(1),
343 NI_PFI(2),
344 NI_PFI(3),
345 NI_PFI(4),
346 NI_PFI(5),
347 TRIGGER_LINE(0),
348 TRIGGER_LINE(1),
349 TRIGGER_LINE(2),
350 TRIGGER_LINE(3),
351 TRIGGER_LINE(5),
352 TRIGGER_LINE(6),
353 NI_DI_StartTrigger,
354 NI_DI_ReferenceTrigger,
355 NI_DI_InputBufferFull,
356 NI_DI_ReadyForStartEvent,
357 NI_DI_ReadyForTransferEventBurst,
358 NI_DI_ReadyForTransferEventPipelined,
359 NI_DO_StartTrigger,
360 NI_DO_OutputBufferFull,
361 NI_DO_DataActiveEvent,
362 NI_DO_ReadyForStartEvent,
363 NI_DO_ReadyForTransferEvent,
364 NI_ChangeDetectionEvent,
365 0, /* Termination */
366 }
367 },
368 {
369 .dest = TRIGGER_LINE(5),
370 .src = (int[]){
371 NI_PFI(0),
372 NI_PFI(1),
373 NI_PFI(2),
374 NI_PFI(3),
375 NI_PFI(4),
376 NI_PFI(5),
377 TRIGGER_LINE(0),
378 TRIGGER_LINE(1),
379 TRIGGER_LINE(2),
380 TRIGGER_LINE(3),
381 TRIGGER_LINE(4),
382 TRIGGER_LINE(6),
383 NI_DI_StartTrigger,
384 NI_DI_ReferenceTrigger,
385 NI_DI_InputBufferFull,
386 NI_DI_ReadyForStartEvent,
387 NI_DI_ReadyForTransferEventBurst,
388 NI_DI_ReadyForTransferEventPipelined,
389 NI_DO_StartTrigger,
390 NI_DO_OutputBufferFull,
391 NI_DO_DataActiveEvent,
392 NI_DO_ReadyForStartEvent,
393 NI_DO_ReadyForTransferEvent,
394 NI_ChangeDetectionEvent,
395 0, /* Termination */
396 }
397 },
398 {
399 .dest = TRIGGER_LINE(6),
400 .src = (int[]){
401 NI_PFI(0),
402 NI_PFI(1),
403 NI_PFI(2),
404 NI_PFI(3),
405 NI_PFI(4),
406 NI_PFI(5),
407 TRIGGER_LINE(0),
408 TRIGGER_LINE(1),
409 TRIGGER_LINE(2),
410 TRIGGER_LINE(3),
411 TRIGGER_LINE(4),
412 TRIGGER_LINE(5),
413 NI_DI_StartTrigger,
414 NI_DI_ReferenceTrigger,
415 NI_DI_InputBufferFull,
416 NI_DI_ReadyForStartEvent,
417 NI_DI_ReadyForTransferEventBurst,
418 NI_DI_ReadyForTransferEventPipelined,
419 NI_DO_StartTrigger,
420 NI_DO_OutputBufferFull,
421 NI_DO_DataActiveEvent,
422 NI_DO_ReadyForStartEvent,
423 NI_DO_ReadyForTransferEvent,
424 NI_ChangeDetectionEvent,
425 0, /* Termination */
426 }
427 },
428 {
429 .dest = TRIGGER_LINE(7),
430 .src = (int[]){
431 NI_PFI(0),
432 NI_PFI(1),
433 NI_PFI(2),
434 NI_PFI(3),
435 NI_PFI(4),
436 NI_PFI(5),
437 TRIGGER_LINE(0),
438 TRIGGER_LINE(1),
439 TRIGGER_LINE(2),
440 TRIGGER_LINE(3),
441 TRIGGER_LINE(4),
442 TRIGGER_LINE(5),
443 TRIGGER_LINE(6),
444 NI_DI_StartTrigger,
445 NI_DI_ReferenceTrigger,
446 NI_DI_InputBufferFull,
447 NI_DI_ReadyForStartEvent,
448 NI_DI_ReadyForTransferEventBurst,
449 NI_DI_ReadyForTransferEventPipelined,
450 NI_DO_SampleClock,
451 NI_DO_StartTrigger,
452 NI_DO_OutputBufferFull,
453 NI_DO_DataActiveEvent,
454 NI_DO_ReadyForStartEvent,
455 NI_DO_ReadyForTransferEvent,
456 NI_ChangeDetectionEvent,
457 0, /* Termination */
458 }
459 },
460 {
461 .dest = NI_DI_SampleClock,
462 .src = (int[]){
463 NI_PFI(5),
464 TRIGGER_LINE(7),
465 0, /* Termination */
466 }
467 },
468 {
469 .dest = NI_DI_StartTrigger,
470 .src = (int[]){
471 NI_PFI(0),
472 NI_PFI(1),
473 NI_PFI(2),
474 NI_PFI(3),
475 NI_PFI(4),
476 NI_PFI(5),
477 TRIGGER_LINE(0),
478 TRIGGER_LINE(1),
479 TRIGGER_LINE(2),
480 TRIGGER_LINE(3),
481 TRIGGER_LINE(4),
482 TRIGGER_LINE(5),
483 TRIGGER_LINE(6),
484 0, /* Termination */
485 }
486 },
487 {
488 .dest = NI_DI_ReferenceTrigger,
489 .src = (int[]){
490 NI_PFI(0),
491 NI_PFI(1),
492 NI_PFI(2),
493 NI_PFI(3),
494 NI_PFI(4),
495 NI_PFI(5),
496 TRIGGER_LINE(0),
497 TRIGGER_LINE(1),
498 TRIGGER_LINE(2),
499 TRIGGER_LINE(3),
500 TRIGGER_LINE(4),
501 TRIGGER_LINE(5),
502 TRIGGER_LINE(6),
503 0, /* Termination */
504 }
505 },
506 {
507 .dest = NI_DI_PauseTrigger,
508 .src = (int[]){
509 NI_PFI(0),
510 NI_PFI(1),
511 NI_PFI(2),
512 NI_PFI(3),
513 NI_PFI(4),
514 NI_PFI(5),
515 TRIGGER_LINE(0),
516 TRIGGER_LINE(1),
517 TRIGGER_LINE(2),
518 TRIGGER_LINE(3),
519 TRIGGER_LINE(4),
520 TRIGGER_LINE(5),
521 TRIGGER_LINE(6),
522 0, /* Termination */
523 }
524 },
525 {
526 .dest = NI_DO_SampleClock,
527 .src = (int[]){
528 NI_PFI(4),
529 TRIGGER_LINE(7),
530 0, /* Termination */
531 }
532 },
533 {
534 .dest = NI_DO_StartTrigger,
535 .src = (int[]){
536 NI_PFI(0),
537 NI_PFI(1),
538 NI_PFI(2),
539 NI_PFI(3),
540 NI_PFI(4),
541 NI_PFI(5),
542 TRIGGER_LINE(0),
543 TRIGGER_LINE(1),
544 TRIGGER_LINE(2),
545 TRIGGER_LINE(3),
546 TRIGGER_LINE(4),
547 TRIGGER_LINE(5),
548 TRIGGER_LINE(6),
549 0, /* Termination */
550 }
551 },
552 {
553 .dest = NI_DO_PauseTrigger,
554 .src = (int[]){
555 NI_PFI(0),
556 NI_PFI(1),
557 NI_PFI(2),
558 NI_PFI(3),
559 NI_PFI(4),
560 NI_PFI(5),
561 TRIGGER_LINE(0),
562 TRIGGER_LINE(1),
563 TRIGGER_LINE(2),
564 TRIGGER_LINE(3),
565 TRIGGER_LINE(4),
566 TRIGGER_LINE(5),
567 TRIGGER_LINE(6),
568 0, /* Termination */
569 }
570 },
571 { /* Termination of list */
572 .dest = 0,
573 },
574 },
575};
diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxie-6738.c b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxie-6738.c
new file mode 100644
index 000000000000..d88504314d7f
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxie-6738.c
@@ -0,0 +1,3083 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routing/ni_device_routes/pxie-6738.c
5 * List of valid routes for specific NI boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21/*
22 * The contents of this file are generated using the tools in
23 * comedi/drivers/ni_routing/tools
24 *
25 * Please use those tools to help maintain the contents of this file.
26 */
27
28#include "../ni_device_routes.h"
29#include "all.h"
30
31struct ni_device_routes ni_pxie_6738_device_routes = {
32 .device = "pxie-6738",
33 .routes = (struct ni_route_set[]){
34 {
35 .dest = NI_PFI(0),
36 .src = (int[]){
37 TRIGGER_LINE(0),
38 TRIGGER_LINE(1),
39 TRIGGER_LINE(2),
40 TRIGGER_LINE(3),
41 TRIGGER_LINE(4),
42 TRIGGER_LINE(5),
43 TRIGGER_LINE(6),
44 TRIGGER_LINE(7),
45 NI_CtrSource(0),
46 NI_CtrSource(1),
47 NI_CtrSource(2),
48 NI_CtrSource(3),
49 NI_CtrGate(0),
50 NI_CtrGate(1),
51 NI_CtrGate(2),
52 NI_CtrGate(3),
53 NI_CtrArmStartTrigger(0),
54 NI_CtrArmStartTrigger(1),
55 NI_CtrArmStartTrigger(2),
56 NI_CtrArmStartTrigger(3),
57 NI_CtrInternalOutput(0),
58 NI_CtrInternalOutput(1),
59 NI_CtrInternalOutput(2),
60 NI_CtrInternalOutput(3),
61 NI_CtrSampleClock(0),
62 NI_CtrSampleClock(1),
63 NI_CtrSampleClock(2),
64 NI_CtrSampleClock(3),
65 NI_AO_SampleClock,
66 NI_AO_StartTrigger,
67 NI_AO_PauseTrigger,
68 NI_DI_SampleClock,
69 NI_DI_StartTrigger,
70 NI_DI_ReferenceTrigger,
71 NI_DI_PauseTrigger,
72 NI_DO_SampleClock,
73 NI_DO_StartTrigger,
74 NI_DO_PauseTrigger,
75 NI_10MHzRefClock,
76 NI_ChangeDetectionEvent,
77 NI_WatchdogExpiredEvent,
78 0, /* Termination */
79 }
80 },
81 {
82 .dest = NI_PFI(1),
83 .src = (int[]){
84 TRIGGER_LINE(0),
85 TRIGGER_LINE(1),
86 TRIGGER_LINE(2),
87 TRIGGER_LINE(3),
88 TRIGGER_LINE(4),
89 TRIGGER_LINE(5),
90 TRIGGER_LINE(6),
91 TRIGGER_LINE(7),
92 NI_CtrSource(0),
93 NI_CtrSource(1),
94 NI_CtrSource(2),
95 NI_CtrSource(3),
96 NI_CtrGate(0),
97 NI_CtrGate(1),
98 NI_CtrGate(2),
99 NI_CtrGate(3),
100 NI_CtrArmStartTrigger(0),
101 NI_CtrArmStartTrigger(1),
102 NI_CtrArmStartTrigger(2),
103 NI_CtrArmStartTrigger(3),
104 NI_CtrInternalOutput(0),
105 NI_CtrInternalOutput(1),
106 NI_CtrInternalOutput(2),
107 NI_CtrInternalOutput(3),
108 NI_CtrSampleClock(0),
109 NI_CtrSampleClock(1),
110 NI_CtrSampleClock(2),
111 NI_CtrSampleClock(3),
112 NI_AO_SampleClock,
113 NI_AO_StartTrigger,
114 NI_AO_PauseTrigger,
115 NI_DI_SampleClock,
116 NI_DI_StartTrigger,
117 NI_DI_ReferenceTrigger,
118 NI_DI_PauseTrigger,
119 NI_DO_SampleClock,
120 NI_DO_StartTrigger,
121 NI_DO_PauseTrigger,
122 NI_10MHzRefClock,
123 NI_ChangeDetectionEvent,
124 NI_WatchdogExpiredEvent,
125 0, /* Termination */
126 }
127 },
128 {
129 .dest = NI_PFI(2),
130 .src = (int[]){
131 TRIGGER_LINE(0),
132 TRIGGER_LINE(1),
133 TRIGGER_LINE(2),
134 TRIGGER_LINE(3),
135 TRIGGER_LINE(4),
136 TRIGGER_LINE(5),
137 TRIGGER_LINE(6),
138 TRIGGER_LINE(7),
139 NI_CtrSource(0),
140 NI_CtrSource(1),
141 NI_CtrSource(2),
142 NI_CtrSource(3),
143 NI_CtrGate(0),
144 NI_CtrGate(1),
145 NI_CtrGate(2),
146 NI_CtrGate(3),
147 NI_CtrArmStartTrigger(0),
148 NI_CtrArmStartTrigger(1),
149 NI_CtrArmStartTrigger(2),
150 NI_CtrArmStartTrigger(3),
151 NI_CtrInternalOutput(0),
152 NI_CtrInternalOutput(1),
153 NI_CtrInternalOutput(2),
154 NI_CtrInternalOutput(3),
155 NI_CtrSampleClock(0),
156 NI_CtrSampleClock(1),
157 NI_CtrSampleClock(2),
158 NI_CtrSampleClock(3),
159 NI_AO_SampleClock,
160 NI_AO_StartTrigger,
161 NI_AO_PauseTrigger,
162 NI_DI_SampleClock,
163 NI_DI_StartTrigger,
164 NI_DI_ReferenceTrigger,
165 NI_DI_PauseTrigger,
166 NI_DO_SampleClock,
167 NI_DO_StartTrigger,
168 NI_DO_PauseTrigger,
169 NI_10MHzRefClock,
170 NI_ChangeDetectionEvent,
171 NI_WatchdogExpiredEvent,
172 0, /* Termination */
173 }
174 },
175 {
176 .dest = NI_PFI(3),
177 .src = (int[]){
178 TRIGGER_LINE(0),
179 TRIGGER_LINE(1),
180 TRIGGER_LINE(2),
181 TRIGGER_LINE(3),
182 TRIGGER_LINE(4),
183 TRIGGER_LINE(5),
184 TRIGGER_LINE(6),
185 TRIGGER_LINE(7),
186 NI_CtrSource(0),
187 NI_CtrSource(1),
188 NI_CtrSource(2),
189 NI_CtrSource(3),
190 NI_CtrGate(0),
191 NI_CtrGate(1),
192 NI_CtrGate(2),
193 NI_CtrGate(3),
194 NI_CtrArmStartTrigger(0),
195 NI_CtrArmStartTrigger(1),
196 NI_CtrArmStartTrigger(2),
197 NI_CtrArmStartTrigger(3),
198 NI_CtrInternalOutput(0),
199 NI_CtrInternalOutput(1),
200 NI_CtrInternalOutput(2),
201 NI_CtrInternalOutput(3),
202 NI_CtrSampleClock(0),
203 NI_CtrSampleClock(1),
204 NI_CtrSampleClock(2),
205 NI_CtrSampleClock(3),
206 NI_AO_SampleClock,
207 NI_AO_StartTrigger,
208 NI_AO_PauseTrigger,
209 NI_DI_SampleClock,
210 NI_DI_StartTrigger,
211 NI_DI_ReferenceTrigger,
212 NI_DI_PauseTrigger,
213 NI_DO_SampleClock,
214 NI_DO_StartTrigger,
215 NI_DO_PauseTrigger,
216 NI_10MHzRefClock,
217 NI_ChangeDetectionEvent,
218 NI_WatchdogExpiredEvent,
219 0, /* Termination */
220 }
221 },
222 {
223 .dest = NI_PFI(4),
224 .src = (int[]){
225 TRIGGER_LINE(0),
226 TRIGGER_LINE(1),
227 TRIGGER_LINE(2),
228 TRIGGER_LINE(3),
229 TRIGGER_LINE(4),
230 TRIGGER_LINE(5),
231 TRIGGER_LINE(6),
232 TRIGGER_LINE(7),
233 NI_CtrSource(0),
234 NI_CtrSource(1),
235 NI_CtrSource(2),
236 NI_CtrSource(3),
237 NI_CtrGate(0),
238 NI_CtrGate(1),
239 NI_CtrGate(2),
240 NI_CtrGate(3),
241 NI_CtrArmStartTrigger(0),
242 NI_CtrArmStartTrigger(1),
243 NI_CtrArmStartTrigger(2),
244 NI_CtrArmStartTrigger(3),
245 NI_CtrInternalOutput(0),
246 NI_CtrInternalOutput(1),
247 NI_CtrInternalOutput(2),
248 NI_CtrInternalOutput(3),
249 NI_CtrSampleClock(0),
250 NI_CtrSampleClock(1),
251 NI_CtrSampleClock(2),
252 NI_CtrSampleClock(3),
253 NI_AO_SampleClock,
254 NI_AO_StartTrigger,
255 NI_AO_PauseTrigger,
256 NI_DI_SampleClock,
257 NI_DI_StartTrigger,
258 NI_DI_ReferenceTrigger,
259 NI_DI_PauseTrigger,
260 NI_DO_SampleClock,
261 NI_DO_StartTrigger,
262 NI_DO_PauseTrigger,
263 NI_10MHzRefClock,
264 NI_ChangeDetectionEvent,
265 NI_WatchdogExpiredEvent,
266 0, /* Termination */
267 }
268 },
269 {
270 .dest = NI_PFI(5),
271 .src = (int[]){
272 TRIGGER_LINE(0),
273 TRIGGER_LINE(1),
274 TRIGGER_LINE(2),
275 TRIGGER_LINE(3),
276 TRIGGER_LINE(4),
277 TRIGGER_LINE(5),
278 TRIGGER_LINE(6),
279 TRIGGER_LINE(7),
280 NI_CtrSource(0),
281 NI_CtrSource(1),
282 NI_CtrSource(2),
283 NI_CtrSource(3),
284 NI_CtrGate(0),
285 NI_CtrGate(1),
286 NI_CtrGate(2),
287 NI_CtrGate(3),
288 NI_CtrArmStartTrigger(0),
289 NI_CtrArmStartTrigger(1),
290 NI_CtrArmStartTrigger(2),
291 NI_CtrArmStartTrigger(3),
292 NI_CtrInternalOutput(0),
293 NI_CtrInternalOutput(1),
294 NI_CtrInternalOutput(2),
295 NI_CtrInternalOutput(3),
296 NI_CtrSampleClock(0),
297 NI_CtrSampleClock(1),
298 NI_CtrSampleClock(2),
299 NI_CtrSampleClock(3),
300 NI_AO_SampleClock,
301 NI_AO_StartTrigger,
302 NI_AO_PauseTrigger,
303 NI_DI_SampleClock,
304 NI_DI_StartTrigger,
305 NI_DI_ReferenceTrigger,
306 NI_DI_PauseTrigger,
307 NI_DO_SampleClock,
308 NI_DO_StartTrigger,
309 NI_DO_PauseTrigger,
310 NI_10MHzRefClock,
311 NI_ChangeDetectionEvent,
312 NI_WatchdogExpiredEvent,
313 0, /* Termination */
314 }
315 },
316 {
317 .dest = NI_PFI(6),
318 .src = (int[]){
319 TRIGGER_LINE(0),
320 TRIGGER_LINE(1),
321 TRIGGER_LINE(2),
322 TRIGGER_LINE(3),
323 TRIGGER_LINE(4),
324 TRIGGER_LINE(5),
325 TRIGGER_LINE(6),
326 TRIGGER_LINE(7),
327 NI_CtrSource(0),
328 NI_CtrSource(1),
329 NI_CtrSource(2),
330 NI_CtrSource(3),
331 NI_CtrGate(0),
332 NI_CtrGate(1),
333 NI_CtrGate(2),
334 NI_CtrGate(3),
335 NI_CtrArmStartTrigger(0),
336 NI_CtrArmStartTrigger(1),
337 NI_CtrArmStartTrigger(2),
338 NI_CtrArmStartTrigger(3),
339 NI_CtrInternalOutput(0),
340 NI_CtrInternalOutput(1),
341 NI_CtrInternalOutput(2),
342 NI_CtrInternalOutput(3),
343 NI_CtrSampleClock(0),
344 NI_CtrSampleClock(1),
345 NI_CtrSampleClock(2),
346 NI_CtrSampleClock(3),
347 NI_AO_SampleClock,
348 NI_AO_StartTrigger,
349 NI_AO_PauseTrigger,
350 NI_DI_SampleClock,
351 NI_DI_StartTrigger,
352 NI_DI_ReferenceTrigger,
353 NI_DI_PauseTrigger,
354 NI_DO_SampleClock,
355 NI_DO_StartTrigger,
356 NI_DO_PauseTrigger,
357 NI_10MHzRefClock,
358 NI_ChangeDetectionEvent,
359 NI_WatchdogExpiredEvent,
360 0, /* Termination */
361 }
362 },
363 {
364 .dest = NI_PFI(7),
365 .src = (int[]){
366 TRIGGER_LINE(0),
367 TRIGGER_LINE(1),
368 TRIGGER_LINE(2),
369 TRIGGER_LINE(3),
370 TRIGGER_LINE(4),
371 TRIGGER_LINE(5),
372 TRIGGER_LINE(6),
373 TRIGGER_LINE(7),
374 NI_CtrSource(0),
375 NI_CtrSource(1),
376 NI_CtrSource(2),
377 NI_CtrSource(3),
378 NI_CtrGate(0),
379 NI_CtrGate(1),
380 NI_CtrGate(2),
381 NI_CtrGate(3),
382 NI_CtrArmStartTrigger(0),
383 NI_CtrArmStartTrigger(1),
384 NI_CtrArmStartTrigger(2),
385 NI_CtrArmStartTrigger(3),
386 NI_CtrInternalOutput(0),
387 NI_CtrInternalOutput(1),
388 NI_CtrInternalOutput(2),
389 NI_CtrInternalOutput(3),
390 NI_CtrSampleClock(0),
391 NI_CtrSampleClock(1),
392 NI_CtrSampleClock(2),
393 NI_CtrSampleClock(3),
394 NI_AO_SampleClock,
395 NI_AO_StartTrigger,
396 NI_AO_PauseTrigger,
397 NI_DI_SampleClock,
398 NI_DI_StartTrigger,
399 NI_DI_ReferenceTrigger,
400 NI_DI_PauseTrigger,
401 NI_DO_SampleClock,
402 NI_DO_StartTrigger,
403 NI_DO_PauseTrigger,
404 NI_10MHzRefClock,
405 NI_ChangeDetectionEvent,
406 NI_WatchdogExpiredEvent,
407 0, /* Termination */
408 }
409 },
410 {
411 .dest = TRIGGER_LINE(0),
412 .src = (int[]){
413 NI_PFI(0),
414 NI_PFI(1),
415 NI_PFI(2),
416 NI_PFI(3),
417 NI_PFI(4),
418 NI_PFI(5),
419 NI_PFI(6),
420 NI_PFI(7),
421 NI_CtrSource(0),
422 NI_CtrSource(1),
423 NI_CtrSource(2),
424 NI_CtrSource(3),
425 NI_CtrGate(0),
426 NI_CtrGate(1),
427 NI_CtrGate(2),
428 NI_CtrGate(3),
429 NI_CtrZ(0),
430 NI_CtrZ(1),
431 NI_CtrZ(2),
432 NI_CtrZ(3),
433 NI_CtrArmStartTrigger(0),
434 NI_CtrArmStartTrigger(1),
435 NI_CtrArmStartTrigger(2),
436 NI_CtrArmStartTrigger(3),
437 NI_CtrInternalOutput(0),
438 NI_CtrInternalOutput(1),
439 NI_CtrInternalOutput(2),
440 NI_CtrInternalOutput(3),
441 NI_CtrSampleClock(0),
442 NI_CtrSampleClock(1),
443 NI_CtrSampleClock(2),
444 NI_CtrSampleClock(3),
445 NI_AO_SampleClock,
446 NI_AO_StartTrigger,
447 NI_AO_PauseTrigger,
448 NI_DI_SampleClock,
449 NI_DI_StartTrigger,
450 NI_DI_ReferenceTrigger,
451 NI_DI_PauseTrigger,
452 NI_DO_SampleClock,
453 NI_DO_StartTrigger,
454 NI_DO_PauseTrigger,
455 NI_10MHzRefClock,
456 NI_ChangeDetectionEvent,
457 NI_WatchdogExpiredEvent,
458 0, /* Termination */
459 }
460 },
461 {
462 .dest = TRIGGER_LINE(1),
463 .src = (int[]){
464 NI_PFI(0),
465 NI_PFI(1),
466 NI_PFI(2),
467 NI_PFI(3),
468 NI_PFI(4),
469 NI_PFI(5),
470 NI_PFI(6),
471 NI_PFI(7),
472 NI_CtrSource(0),
473 NI_CtrSource(1),
474 NI_CtrSource(2),
475 NI_CtrSource(3),
476 NI_CtrGate(0),
477 NI_CtrGate(1),
478 NI_CtrGate(2),
479 NI_CtrGate(3),
480 NI_CtrZ(0),
481 NI_CtrZ(1),
482 NI_CtrZ(2),
483 NI_CtrZ(3),
484 NI_CtrArmStartTrigger(0),
485 NI_CtrArmStartTrigger(1),
486 NI_CtrArmStartTrigger(2),
487 NI_CtrArmStartTrigger(3),
488 NI_CtrInternalOutput(0),
489 NI_CtrInternalOutput(1),
490 NI_CtrInternalOutput(2),
491 NI_CtrInternalOutput(3),
492 NI_CtrSampleClock(0),
493 NI_CtrSampleClock(1),
494 NI_CtrSampleClock(2),
495 NI_CtrSampleClock(3),
496 NI_AO_SampleClock,
497 NI_AO_StartTrigger,
498 NI_AO_PauseTrigger,
499 NI_DI_SampleClock,
500 NI_DI_StartTrigger,
501 NI_DI_ReferenceTrigger,
502 NI_DI_PauseTrigger,
503 NI_DO_SampleClock,
504 NI_DO_StartTrigger,
505 NI_DO_PauseTrigger,
506 NI_10MHzRefClock,
507 NI_ChangeDetectionEvent,
508 NI_WatchdogExpiredEvent,
509 0, /* Termination */
510 }
511 },
512 {
513 .dest = TRIGGER_LINE(2),
514 .src = (int[]){
515 NI_PFI(0),
516 NI_PFI(1),
517 NI_PFI(2),
518 NI_PFI(3),
519 NI_PFI(4),
520 NI_PFI(5),
521 NI_PFI(6),
522 NI_PFI(7),
523 NI_CtrSource(0),
524 NI_CtrSource(1),
525 NI_CtrSource(2),
526 NI_CtrSource(3),
527 NI_CtrGate(0),
528 NI_CtrGate(1),
529 NI_CtrGate(2),
530 NI_CtrGate(3),
531 NI_CtrZ(0),
532 NI_CtrZ(1),
533 NI_CtrZ(2),
534 NI_CtrZ(3),
535 NI_CtrArmStartTrigger(0),
536 NI_CtrArmStartTrigger(1),
537 NI_CtrArmStartTrigger(2),
538 NI_CtrArmStartTrigger(3),
539 NI_CtrInternalOutput(0),
540 NI_CtrInternalOutput(1),
541 NI_CtrInternalOutput(2),
542 NI_CtrInternalOutput(3),
543 NI_CtrSampleClock(0),
544 NI_CtrSampleClock(1),
545 NI_CtrSampleClock(2),
546 NI_CtrSampleClock(3),
547 NI_AO_SampleClock,
548 NI_AO_StartTrigger,
549 NI_AO_PauseTrigger,
550 NI_DI_SampleClock,
551 NI_DI_StartTrigger,
552 NI_DI_ReferenceTrigger,
553 NI_DI_PauseTrigger,
554 NI_DO_SampleClock,
555 NI_DO_StartTrigger,
556 NI_DO_PauseTrigger,
557 NI_10MHzRefClock,
558 NI_ChangeDetectionEvent,
559 NI_WatchdogExpiredEvent,
560 0, /* Termination */
561 }
562 },
563 {
564 .dest = TRIGGER_LINE(3),
565 .src = (int[]){
566 NI_PFI(0),
567 NI_PFI(1),
568 NI_PFI(2),
569 NI_PFI(3),
570 NI_PFI(4),
571 NI_PFI(5),
572 NI_PFI(6),
573 NI_PFI(7),
574 NI_CtrSource(0),
575 NI_CtrSource(1),
576 NI_CtrSource(2),
577 NI_CtrSource(3),
578 NI_CtrGate(0),
579 NI_CtrGate(1),
580 NI_CtrGate(2),
581 NI_CtrGate(3),
582 NI_CtrZ(0),
583 NI_CtrZ(1),
584 NI_CtrZ(2),
585 NI_CtrZ(3),
586 NI_CtrArmStartTrigger(0),
587 NI_CtrArmStartTrigger(1),
588 NI_CtrArmStartTrigger(2),
589 NI_CtrArmStartTrigger(3),
590 NI_CtrInternalOutput(0),
591 NI_CtrInternalOutput(1),
592 NI_CtrInternalOutput(2),
593 NI_CtrInternalOutput(3),
594 NI_CtrSampleClock(0),
595 NI_CtrSampleClock(1),
596 NI_CtrSampleClock(2),
597 NI_CtrSampleClock(3),
598 NI_AO_SampleClock,
599 NI_AO_StartTrigger,
600 NI_AO_PauseTrigger,
601 NI_DI_SampleClock,
602 NI_DI_StartTrigger,
603 NI_DI_ReferenceTrigger,
604 NI_DI_PauseTrigger,
605 NI_DO_SampleClock,
606 NI_DO_StartTrigger,
607 NI_DO_PauseTrigger,
608 NI_10MHzRefClock,
609 NI_ChangeDetectionEvent,
610 NI_WatchdogExpiredEvent,
611 0, /* Termination */
612 }
613 },
614 {
615 .dest = TRIGGER_LINE(4),
616 .src = (int[]){
617 NI_PFI(0),
618 NI_PFI(1),
619 NI_PFI(2),
620 NI_PFI(3),
621 NI_PFI(4),
622 NI_PFI(5),
623 NI_PFI(6),
624 NI_PFI(7),
625 NI_CtrSource(0),
626 NI_CtrSource(1),
627 NI_CtrSource(2),
628 NI_CtrSource(3),
629 NI_CtrGate(0),
630 NI_CtrGate(1),
631 NI_CtrGate(2),
632 NI_CtrGate(3),
633 NI_CtrZ(0),
634 NI_CtrZ(1),
635 NI_CtrZ(2),
636 NI_CtrZ(3),
637 NI_CtrArmStartTrigger(0),
638 NI_CtrArmStartTrigger(1),
639 NI_CtrArmStartTrigger(2),
640 NI_CtrArmStartTrigger(3),
641 NI_CtrInternalOutput(0),
642 NI_CtrInternalOutput(1),
643 NI_CtrInternalOutput(2),
644 NI_CtrInternalOutput(3),
645 NI_CtrSampleClock(0),
646 NI_CtrSampleClock(1),
647 NI_CtrSampleClock(2),
648 NI_CtrSampleClock(3),
649 NI_AO_SampleClock,
650 NI_AO_StartTrigger,
651 NI_AO_PauseTrigger,
652 NI_DI_SampleClock,
653 NI_DI_StartTrigger,
654 NI_DI_ReferenceTrigger,
655 NI_DI_PauseTrigger,
656 NI_DO_SampleClock,
657 NI_DO_StartTrigger,
658 NI_DO_PauseTrigger,
659 NI_10MHzRefClock,
660 NI_ChangeDetectionEvent,
661 NI_WatchdogExpiredEvent,
662 0, /* Termination */
663 }
664 },
665 {
666 .dest = TRIGGER_LINE(5),
667 .src = (int[]){
668 NI_PFI(0),
669 NI_PFI(1),
670 NI_PFI(2),
671 NI_PFI(3),
672 NI_PFI(4),
673 NI_PFI(5),
674 NI_PFI(6),
675 NI_PFI(7),
676 NI_CtrSource(0),
677 NI_CtrSource(1),
678 NI_CtrSource(2),
679 NI_CtrSource(3),
680 NI_CtrGate(0),
681 NI_CtrGate(1),
682 NI_CtrGate(2),
683 NI_CtrGate(3),
684 NI_CtrZ(0),
685 NI_CtrZ(1),
686 NI_CtrZ(2),
687 NI_CtrZ(3),
688 NI_CtrArmStartTrigger(0),
689 NI_CtrArmStartTrigger(1),
690 NI_CtrArmStartTrigger(2),
691 NI_CtrArmStartTrigger(3),
692 NI_CtrInternalOutput(0),
693 NI_CtrInternalOutput(1),
694 NI_CtrInternalOutput(2),
695 NI_CtrInternalOutput(3),
696 NI_CtrSampleClock(0),
697 NI_CtrSampleClock(1),
698 NI_CtrSampleClock(2),
699 NI_CtrSampleClock(3),
700 NI_AO_SampleClock,
701 NI_AO_StartTrigger,
702 NI_AO_PauseTrigger,
703 NI_DI_SampleClock,
704 NI_DI_StartTrigger,
705 NI_DI_ReferenceTrigger,
706 NI_DI_PauseTrigger,
707 NI_DO_SampleClock,
708 NI_DO_StartTrigger,
709 NI_DO_PauseTrigger,
710 NI_10MHzRefClock,
711 NI_ChangeDetectionEvent,
712 NI_WatchdogExpiredEvent,
713 0, /* Termination */
714 }
715 },
716 {
717 .dest = TRIGGER_LINE(6),
718 .src = (int[]){
719 NI_PFI(0),
720 NI_PFI(1),
721 NI_PFI(2),
722 NI_PFI(3),
723 NI_PFI(4),
724 NI_PFI(5),
725 NI_PFI(6),
726 NI_PFI(7),
727 NI_CtrSource(0),
728 NI_CtrSource(1),
729 NI_CtrSource(2),
730 NI_CtrSource(3),
731 NI_CtrGate(0),
732 NI_CtrGate(1),
733 NI_CtrGate(2),
734 NI_CtrGate(3),
735 NI_CtrZ(0),
736 NI_CtrZ(1),
737 NI_CtrZ(2),
738 NI_CtrZ(3),
739 NI_CtrArmStartTrigger(0),
740 NI_CtrArmStartTrigger(1),
741 NI_CtrArmStartTrigger(2),
742 NI_CtrArmStartTrigger(3),
743 NI_CtrInternalOutput(0),
744 NI_CtrInternalOutput(1),
745 NI_CtrInternalOutput(2),
746 NI_CtrInternalOutput(3),
747 NI_CtrSampleClock(0),
748 NI_CtrSampleClock(1),
749 NI_CtrSampleClock(2),
750 NI_CtrSampleClock(3),
751 NI_AO_SampleClock,
752 NI_AO_StartTrigger,
753 NI_AO_PauseTrigger,
754 NI_DI_SampleClock,
755 NI_DI_StartTrigger,
756 NI_DI_ReferenceTrigger,
757 NI_DI_PauseTrigger,
758 NI_DO_SampleClock,
759 NI_DO_StartTrigger,
760 NI_DO_PauseTrigger,
761 NI_10MHzRefClock,
762 NI_ChangeDetectionEvent,
763 NI_WatchdogExpiredEvent,
764 0, /* Termination */
765 }
766 },
767 {
768 .dest = TRIGGER_LINE(7),
769 .src = (int[]){
770 NI_PFI(0),
771 NI_PFI(1),
772 NI_PFI(2),
773 NI_PFI(3),
774 NI_PFI(4),
775 NI_PFI(5),
776 NI_PFI(6),
777 NI_PFI(7),
778 NI_CtrSource(0),
779 NI_CtrSource(1),
780 NI_CtrSource(2),
781 NI_CtrSource(3),
782 NI_CtrGate(0),
783 NI_CtrGate(1),
784 NI_CtrGate(2),
785 NI_CtrGate(3),
786 NI_CtrZ(0),
787 NI_CtrZ(1),
788 NI_CtrZ(2),
789 NI_CtrZ(3),
790 NI_CtrArmStartTrigger(0),
791 NI_CtrArmStartTrigger(1),
792 NI_CtrArmStartTrigger(2),
793 NI_CtrArmStartTrigger(3),
794 NI_CtrInternalOutput(0),
795 NI_CtrInternalOutput(1),
796 NI_CtrInternalOutput(2),
797 NI_CtrInternalOutput(3),
798 NI_CtrSampleClock(0),
799 NI_CtrSampleClock(1),
800 NI_CtrSampleClock(2),
801 NI_CtrSampleClock(3),
802 NI_AO_SampleClock,
803 NI_AO_StartTrigger,
804 NI_AO_PauseTrigger,
805 NI_DI_SampleClock,
806 NI_DI_StartTrigger,
807 NI_DI_ReferenceTrigger,
808 NI_DI_PauseTrigger,
809 NI_DO_SampleClock,
810 NI_DO_StartTrigger,
811 NI_DO_PauseTrigger,
812 NI_10MHzRefClock,
813 NI_ChangeDetectionEvent,
814 NI_WatchdogExpiredEvent,
815 0, /* Termination */
816 }
817 },
818 {
819 .dest = NI_CtrSource(0),
820 .src = (int[]){
821 NI_PFI(0),
822 NI_PFI(1),
823 NI_PFI(2),
824 NI_PFI(3),
825 NI_PFI(4),
826 NI_PFI(5),
827 NI_PFI(6),
828 NI_PFI(7),
829 TRIGGER_LINE(0),
830 TRIGGER_LINE(1),
831 TRIGGER_LINE(2),
832 TRIGGER_LINE(3),
833 TRIGGER_LINE(4),
834 TRIGGER_LINE(5),
835 TRIGGER_LINE(6),
836 TRIGGER_LINE(7),
837 NI_CtrSource(1),
838 NI_CtrSource(2),
839 NI_CtrSource(3),
840 NI_CtrGate(1),
841 NI_CtrGate(2),
842 NI_CtrGate(3),
843 NI_CtrArmStartTrigger(1),
844 NI_CtrArmStartTrigger(2),
845 NI_CtrArmStartTrigger(3),
846 NI_CtrInternalOutput(0),
847 NI_CtrInternalOutput(1),
848 NI_CtrInternalOutput(2),
849 NI_CtrInternalOutput(3),
850 NI_CtrSampleClock(1),
851 NI_CtrSampleClock(2),
852 NI_CtrSampleClock(3),
853 PXI_Clk10,
854 NI_AO_SampleClock,
855 NI_AO_StartTrigger,
856 NI_AO_PauseTrigger,
857 NI_DI_SampleClock,
858 NI_DI_StartTrigger,
859 NI_DI_ReferenceTrigger,
860 NI_DI_PauseTrigger,
861 NI_DO_SampleClock,
862 NI_DO_StartTrigger,
863 NI_DO_PauseTrigger,
864 NI_20MHzTimebase,
865 NI_100MHzTimebase,
866 NI_100kHzTimebase,
867 NI_10MHzRefClock,
868 NI_ChangeDetectionEvent,
869 NI_WatchdogExpiredEvent,
870 0, /* Termination */
871 }
872 },
873 {
874 .dest = NI_CtrSource(1),
875 .src = (int[]){
876 NI_PFI(0),
877 NI_PFI(1),
878 NI_PFI(2),
879 NI_PFI(3),
880 NI_PFI(4),
881 NI_PFI(5),
882 NI_PFI(6),
883 NI_PFI(7),
884 TRIGGER_LINE(0),
885 TRIGGER_LINE(1),
886 TRIGGER_LINE(2),
887 TRIGGER_LINE(3),
888 TRIGGER_LINE(4),
889 TRIGGER_LINE(5),
890 TRIGGER_LINE(6),
891 TRIGGER_LINE(7),
892 NI_CtrSource(0),
893 NI_CtrSource(2),
894 NI_CtrSource(3),
895 NI_CtrGate(0),
896 NI_CtrGate(2),
897 NI_CtrGate(3),
898 NI_CtrArmStartTrigger(0),
899 NI_CtrArmStartTrigger(2),
900 NI_CtrArmStartTrigger(3),
901 NI_CtrInternalOutput(0),
902 NI_CtrInternalOutput(1),
903 NI_CtrInternalOutput(2),
904 NI_CtrInternalOutput(3),
905 NI_CtrSampleClock(0),
906 NI_CtrSampleClock(2),
907 NI_CtrSampleClock(3),
908 PXI_Clk10,
909 NI_AO_SampleClock,
910 NI_AO_StartTrigger,
911 NI_AO_PauseTrigger,
912 NI_DI_SampleClock,
913 NI_DI_StartTrigger,
914 NI_DI_ReferenceTrigger,
915 NI_DI_PauseTrigger,
916 NI_DO_SampleClock,
917 NI_DO_StartTrigger,
918 NI_DO_PauseTrigger,
919 NI_20MHzTimebase,
920 NI_100MHzTimebase,
921 NI_100kHzTimebase,
922 NI_10MHzRefClock,
923 NI_ChangeDetectionEvent,
924 NI_WatchdogExpiredEvent,
925 0, /* Termination */
926 }
927 },
928 {
929 .dest = NI_CtrSource(2),
930 .src = (int[]){
931 NI_PFI(0),
932 NI_PFI(1),
933 NI_PFI(2),
934 NI_PFI(3),
935 NI_PFI(4),
936 NI_PFI(5),
937 NI_PFI(6),
938 NI_PFI(7),
939 TRIGGER_LINE(0),
940 TRIGGER_LINE(1),
941 TRIGGER_LINE(2),
942 TRIGGER_LINE(3),
943 TRIGGER_LINE(4),
944 TRIGGER_LINE(5),
945 TRIGGER_LINE(6),
946 TRIGGER_LINE(7),
947 NI_CtrSource(0),
948 NI_CtrSource(1),
949 NI_CtrSource(3),
950 NI_CtrGate(0),
951 NI_CtrGate(1),
952 NI_CtrGate(3),
953 NI_CtrArmStartTrigger(0),
954 NI_CtrArmStartTrigger(1),
955 NI_CtrArmStartTrigger(3),
956 NI_CtrInternalOutput(0),
957 NI_CtrInternalOutput(1),
958 NI_CtrInternalOutput(2),
959 NI_CtrInternalOutput(3),
960 NI_CtrSampleClock(0),
961 NI_CtrSampleClock(1),
962 NI_CtrSampleClock(3),
963 PXI_Clk10,
964 NI_AO_SampleClock,
965 NI_AO_StartTrigger,
966 NI_AO_PauseTrigger,
967 NI_DI_SampleClock,
968 NI_DI_StartTrigger,
969 NI_DI_ReferenceTrigger,
970 NI_DI_PauseTrigger,
971 NI_DO_SampleClock,
972 NI_DO_StartTrigger,
973 NI_DO_PauseTrigger,
974 NI_20MHzTimebase,
975 NI_100MHzTimebase,
976 NI_100kHzTimebase,
977 NI_10MHzRefClock,
978 NI_ChangeDetectionEvent,
979 NI_WatchdogExpiredEvent,
980 0, /* Termination */
981 }
982 },
983 {
984 .dest = NI_CtrSource(3),
985 .src = (int[]){
986 NI_PFI(0),
987 NI_PFI(1),
988 NI_PFI(2),
989 NI_PFI(3),
990 NI_PFI(4),
991 NI_PFI(5),
992 NI_PFI(6),
993 NI_PFI(7),
994 TRIGGER_LINE(0),
995 TRIGGER_LINE(1),
996 TRIGGER_LINE(2),
997 TRIGGER_LINE(3),
998 TRIGGER_LINE(4),
999 TRIGGER_LINE(5),
1000 TRIGGER_LINE(6),
1001 TRIGGER_LINE(7),
1002 NI_CtrSource(0),
1003 NI_CtrSource(1),
1004 NI_CtrSource(2),
1005 NI_CtrGate(0),
1006 NI_CtrGate(1),
1007 NI_CtrGate(2),
1008 NI_CtrArmStartTrigger(0),
1009 NI_CtrArmStartTrigger(1),
1010 NI_CtrArmStartTrigger(2),
1011 NI_CtrInternalOutput(0),
1012 NI_CtrInternalOutput(1),
1013 NI_CtrInternalOutput(2),
1014 NI_CtrInternalOutput(3),
1015 NI_CtrSampleClock(0),
1016 NI_CtrSampleClock(1),
1017 NI_CtrSampleClock(2),
1018 PXI_Clk10,
1019 NI_AO_SampleClock,
1020 NI_AO_StartTrigger,
1021 NI_AO_PauseTrigger,
1022 NI_DI_SampleClock,
1023 NI_DI_StartTrigger,
1024 NI_DI_ReferenceTrigger,
1025 NI_DI_PauseTrigger,
1026 NI_DO_SampleClock,
1027 NI_DO_StartTrigger,
1028 NI_DO_PauseTrigger,
1029 NI_20MHzTimebase,
1030 NI_100MHzTimebase,
1031 NI_100kHzTimebase,
1032 NI_10MHzRefClock,
1033 NI_ChangeDetectionEvent,
1034 NI_WatchdogExpiredEvent,
1035 0, /* Termination */
1036 }
1037 },
1038 {
1039 .dest = NI_CtrGate(0),
1040 .src = (int[]){
1041 NI_PFI(0),
1042 NI_PFI(1),
1043 NI_PFI(2),
1044 NI_PFI(3),
1045 NI_PFI(4),
1046 NI_PFI(5),
1047 NI_PFI(6),
1048 NI_PFI(7),
1049 TRIGGER_LINE(0),
1050 TRIGGER_LINE(1),
1051 TRIGGER_LINE(2),
1052 TRIGGER_LINE(3),
1053 TRIGGER_LINE(4),
1054 TRIGGER_LINE(5),
1055 TRIGGER_LINE(6),
1056 TRIGGER_LINE(7),
1057 NI_CtrSource(1),
1058 NI_CtrSource(2),
1059 NI_CtrSource(3),
1060 NI_CtrGate(1),
1061 NI_CtrGate(2),
1062 NI_CtrGate(3),
1063 NI_CtrArmStartTrigger(1),
1064 NI_CtrArmStartTrigger(2),
1065 NI_CtrArmStartTrigger(3),
1066 NI_CtrInternalOutput(0),
1067 NI_CtrInternalOutput(1),
1068 NI_CtrInternalOutput(2),
1069 NI_CtrInternalOutput(3),
1070 NI_CtrSampleClock(1),
1071 NI_CtrSampleClock(2),
1072 NI_CtrSampleClock(3),
1073 NI_AO_SampleClock,
1074 NI_AO_StartTrigger,
1075 NI_AO_PauseTrigger,
1076 NI_DI_SampleClock,
1077 NI_DI_StartTrigger,
1078 NI_DI_ReferenceTrigger,
1079 NI_DI_PauseTrigger,
1080 NI_DO_SampleClock,
1081 NI_DO_StartTrigger,
1082 NI_DO_PauseTrigger,
1083 NI_10MHzRefClock,
1084 NI_ChangeDetectionEvent,
1085 NI_WatchdogExpiredEvent,
1086 0, /* Termination */
1087 }
1088 },
1089 {
1090 .dest = NI_CtrGate(1),
1091 .src = (int[]){
1092 NI_PFI(0),
1093 NI_PFI(1),
1094 NI_PFI(2),
1095 NI_PFI(3),
1096 NI_PFI(4),
1097 NI_PFI(5),
1098 NI_PFI(6),
1099 NI_PFI(7),
1100 TRIGGER_LINE(0),
1101 TRIGGER_LINE(1),
1102 TRIGGER_LINE(2),
1103 TRIGGER_LINE(3),
1104 TRIGGER_LINE(4),
1105 TRIGGER_LINE(5),
1106 TRIGGER_LINE(6),
1107 TRIGGER_LINE(7),
1108 NI_CtrSource(0),
1109 NI_CtrSource(2),
1110 NI_CtrSource(3),
1111 NI_CtrGate(0),
1112 NI_CtrGate(2),
1113 NI_CtrGate(3),
1114 NI_CtrArmStartTrigger(0),
1115 NI_CtrArmStartTrigger(2),
1116 NI_CtrArmStartTrigger(3),
1117 NI_CtrInternalOutput(0),
1118 NI_CtrInternalOutput(1),
1119 NI_CtrInternalOutput(2),
1120 NI_CtrInternalOutput(3),
1121 NI_CtrSampleClock(0),
1122 NI_CtrSampleClock(2),
1123 NI_CtrSampleClock(3),
1124 NI_AO_SampleClock,
1125 NI_AO_StartTrigger,
1126 NI_AO_PauseTrigger,
1127 NI_DI_SampleClock,
1128 NI_DI_StartTrigger,
1129 NI_DI_ReferenceTrigger,
1130 NI_DI_PauseTrigger,
1131 NI_DO_SampleClock,
1132 NI_DO_StartTrigger,
1133 NI_DO_PauseTrigger,
1134 NI_10MHzRefClock,
1135 NI_ChangeDetectionEvent,
1136 NI_WatchdogExpiredEvent,
1137 0, /* Termination */
1138 }
1139 },
1140 {
1141 .dest = NI_CtrGate(2),
1142 .src = (int[]){
1143 NI_PFI(0),
1144 NI_PFI(1),
1145 NI_PFI(2),
1146 NI_PFI(3),
1147 NI_PFI(4),
1148 NI_PFI(5),
1149 NI_PFI(6),
1150 NI_PFI(7),
1151 TRIGGER_LINE(0),
1152 TRIGGER_LINE(1),
1153 TRIGGER_LINE(2),
1154 TRIGGER_LINE(3),
1155 TRIGGER_LINE(4),
1156 TRIGGER_LINE(5),
1157 TRIGGER_LINE(6),
1158 TRIGGER_LINE(7),
1159 NI_CtrSource(0),
1160 NI_CtrSource(1),
1161 NI_CtrSource(3),
1162 NI_CtrGate(0),
1163 NI_CtrGate(1),
1164 NI_CtrGate(3),
1165 NI_CtrArmStartTrigger(0),
1166 NI_CtrArmStartTrigger(1),
1167 NI_CtrArmStartTrigger(3),
1168 NI_CtrInternalOutput(0),
1169 NI_CtrInternalOutput(1),
1170 NI_CtrInternalOutput(2),
1171 NI_CtrInternalOutput(3),
1172 NI_CtrSampleClock(0),
1173 NI_CtrSampleClock(1),
1174 NI_CtrSampleClock(3),
1175 NI_AO_SampleClock,
1176 NI_AO_StartTrigger,
1177 NI_AO_PauseTrigger,
1178 NI_DI_SampleClock,
1179 NI_DI_StartTrigger,
1180 NI_DI_ReferenceTrigger,
1181 NI_DI_PauseTrigger,
1182 NI_DO_SampleClock,
1183 NI_DO_StartTrigger,
1184 NI_DO_PauseTrigger,
1185 NI_10MHzRefClock,
1186 NI_ChangeDetectionEvent,
1187 NI_WatchdogExpiredEvent,
1188 0, /* Termination */
1189 }
1190 },
1191 {
1192 .dest = NI_CtrGate(3),
1193 .src = (int[]){
1194 NI_PFI(0),
1195 NI_PFI(1),
1196 NI_PFI(2),
1197 NI_PFI(3),
1198 NI_PFI(4),
1199 NI_PFI(5),
1200 NI_PFI(6),
1201 NI_PFI(7),
1202 TRIGGER_LINE(0),
1203 TRIGGER_LINE(1),
1204 TRIGGER_LINE(2),
1205 TRIGGER_LINE(3),
1206 TRIGGER_LINE(4),
1207 TRIGGER_LINE(5),
1208 TRIGGER_LINE(6),
1209 TRIGGER_LINE(7),
1210 NI_CtrSource(0),
1211 NI_CtrSource(1),
1212 NI_CtrSource(2),
1213 NI_CtrGate(0),
1214 NI_CtrGate(1),
1215 NI_CtrGate(2),
1216 NI_CtrArmStartTrigger(0),
1217 NI_CtrArmStartTrigger(1),
1218 NI_CtrArmStartTrigger(2),
1219 NI_CtrInternalOutput(0),
1220 NI_CtrInternalOutput(1),
1221 NI_CtrInternalOutput(2),
1222 NI_CtrInternalOutput(3),
1223 NI_CtrSampleClock(0),
1224 NI_CtrSampleClock(1),
1225 NI_CtrSampleClock(2),
1226 NI_AO_SampleClock,
1227 NI_AO_StartTrigger,
1228 NI_AO_PauseTrigger,
1229 NI_DI_SampleClock,
1230 NI_DI_StartTrigger,
1231 NI_DI_ReferenceTrigger,
1232 NI_DI_PauseTrigger,
1233 NI_DO_SampleClock,
1234 NI_DO_StartTrigger,
1235 NI_DO_PauseTrigger,
1236 NI_10MHzRefClock,
1237 NI_ChangeDetectionEvent,
1238 NI_WatchdogExpiredEvent,
1239 0, /* Termination */
1240 }
1241 },
1242 {
1243 .dest = NI_CtrAux(0),
1244 .src = (int[]){
1245 NI_PFI(0),
1246 NI_PFI(1),
1247 NI_PFI(2),
1248 NI_PFI(3),
1249 NI_PFI(4),
1250 NI_PFI(5),
1251 NI_PFI(6),
1252 NI_PFI(7),
1253 TRIGGER_LINE(0),
1254 TRIGGER_LINE(1),
1255 TRIGGER_LINE(2),
1256 TRIGGER_LINE(3),
1257 TRIGGER_LINE(4),
1258 TRIGGER_LINE(5),
1259 TRIGGER_LINE(6),
1260 TRIGGER_LINE(7),
1261 NI_CtrSource(1),
1262 NI_CtrSource(2),
1263 NI_CtrSource(3),
1264 NI_CtrGate(0),
1265 NI_CtrGate(1),
1266 NI_CtrGate(2),
1267 NI_CtrGate(3),
1268 NI_CtrArmStartTrigger(1),
1269 NI_CtrArmStartTrigger(2),
1270 NI_CtrArmStartTrigger(3),
1271 NI_CtrInternalOutput(0),
1272 NI_CtrInternalOutput(1),
1273 NI_CtrInternalOutput(2),
1274 NI_CtrInternalOutput(3),
1275 NI_CtrSampleClock(1),
1276 NI_CtrSampleClock(2),
1277 NI_CtrSampleClock(3),
1278 NI_AO_SampleClock,
1279 NI_AO_StartTrigger,
1280 NI_AO_PauseTrigger,
1281 NI_DI_SampleClock,
1282 NI_DI_StartTrigger,
1283 NI_DI_ReferenceTrigger,
1284 NI_DI_PauseTrigger,
1285 NI_DO_SampleClock,
1286 NI_DO_StartTrigger,
1287 NI_DO_PauseTrigger,
1288 NI_10MHzRefClock,
1289 NI_ChangeDetectionEvent,
1290 NI_WatchdogExpiredEvent,
1291 0, /* Termination */
1292 }
1293 },
1294 {
1295 .dest = NI_CtrAux(1),
1296 .src = (int[]){
1297 NI_PFI(0),
1298 NI_PFI(1),
1299 NI_PFI(2),
1300 NI_PFI(3),
1301 NI_PFI(4),
1302 NI_PFI(5),
1303 NI_PFI(6),
1304 NI_PFI(7),
1305 TRIGGER_LINE(0),
1306 TRIGGER_LINE(1),
1307 TRIGGER_LINE(2),
1308 TRIGGER_LINE(3),
1309 TRIGGER_LINE(4),
1310 TRIGGER_LINE(5),
1311 TRIGGER_LINE(6),
1312 TRIGGER_LINE(7),
1313 NI_CtrSource(0),
1314 NI_CtrSource(2),
1315 NI_CtrSource(3),
1316 NI_CtrGate(0),
1317 NI_CtrGate(1),
1318 NI_CtrGate(2),
1319 NI_CtrGate(3),
1320 NI_CtrArmStartTrigger(0),
1321 NI_CtrArmStartTrigger(2),
1322 NI_CtrArmStartTrigger(3),
1323 NI_CtrInternalOutput(0),
1324 NI_CtrInternalOutput(1),
1325 NI_CtrInternalOutput(2),
1326 NI_CtrInternalOutput(3),
1327 NI_CtrSampleClock(0),
1328 NI_CtrSampleClock(2),
1329 NI_CtrSampleClock(3),
1330 NI_AO_SampleClock,
1331 NI_AO_StartTrigger,
1332 NI_AO_PauseTrigger,
1333 NI_DI_SampleClock,
1334 NI_DI_StartTrigger,
1335 NI_DI_ReferenceTrigger,
1336 NI_DI_PauseTrigger,
1337 NI_DO_SampleClock,
1338 NI_DO_StartTrigger,
1339 NI_DO_PauseTrigger,
1340 NI_10MHzRefClock,
1341 NI_ChangeDetectionEvent,
1342 NI_WatchdogExpiredEvent,
1343 0, /* Termination */
1344 }
1345 },
1346 {
1347 .dest = NI_CtrAux(2),
1348 .src = (int[]){
1349 NI_PFI(0),
1350 NI_PFI(1),
1351 NI_PFI(2),
1352 NI_PFI(3),
1353 NI_PFI(4),
1354 NI_PFI(5),
1355 NI_PFI(6),
1356 NI_PFI(7),
1357 TRIGGER_LINE(0),
1358 TRIGGER_LINE(1),
1359 TRIGGER_LINE(2),
1360 TRIGGER_LINE(3),
1361 TRIGGER_LINE(4),
1362 TRIGGER_LINE(5),
1363 TRIGGER_LINE(6),
1364 TRIGGER_LINE(7),
1365 NI_CtrSource(0),
1366 NI_CtrSource(1),
1367 NI_CtrSource(3),
1368 NI_CtrGate(0),
1369 NI_CtrGate(1),
1370 NI_CtrGate(2),
1371 NI_CtrGate(3),
1372 NI_CtrArmStartTrigger(0),
1373 NI_CtrArmStartTrigger(1),
1374 NI_CtrArmStartTrigger(3),
1375 NI_CtrInternalOutput(0),
1376 NI_CtrInternalOutput(1),
1377 NI_CtrInternalOutput(2),
1378 NI_CtrInternalOutput(3),
1379 NI_CtrSampleClock(0),
1380 NI_CtrSampleClock(1),
1381 NI_CtrSampleClock(3),
1382 NI_AO_SampleClock,
1383 NI_AO_StartTrigger,
1384 NI_AO_PauseTrigger,
1385 NI_DI_SampleClock,
1386 NI_DI_StartTrigger,
1387 NI_DI_ReferenceTrigger,
1388 NI_DI_PauseTrigger,
1389 NI_DO_SampleClock,
1390 NI_DO_StartTrigger,
1391 NI_DO_PauseTrigger,
1392 NI_10MHzRefClock,
1393 NI_ChangeDetectionEvent,
1394 NI_WatchdogExpiredEvent,
1395 0, /* Termination */
1396 }
1397 },
1398 {
1399 .dest = NI_CtrAux(3),
1400 .src = (int[]){
1401 NI_PFI(0),
1402 NI_PFI(1),
1403 NI_PFI(2),
1404 NI_PFI(3),
1405 NI_PFI(4),
1406 NI_PFI(5),
1407 NI_PFI(6),
1408 NI_PFI(7),
1409 TRIGGER_LINE(0),
1410 TRIGGER_LINE(1),
1411 TRIGGER_LINE(2),
1412 TRIGGER_LINE(3),
1413 TRIGGER_LINE(4),
1414 TRIGGER_LINE(5),
1415 TRIGGER_LINE(6),
1416 TRIGGER_LINE(7),
1417 NI_CtrSource(0),
1418 NI_CtrSource(1),
1419 NI_CtrSource(2),
1420 NI_CtrGate(0),
1421 NI_CtrGate(1),
1422 NI_CtrGate(2),
1423 NI_CtrGate(3),
1424 NI_CtrArmStartTrigger(0),
1425 NI_CtrArmStartTrigger(1),
1426 NI_CtrArmStartTrigger(2),
1427 NI_CtrInternalOutput(0),
1428 NI_CtrInternalOutput(1),
1429 NI_CtrInternalOutput(2),
1430 NI_CtrInternalOutput(3),
1431 NI_CtrSampleClock(0),
1432 NI_CtrSampleClock(1),
1433 NI_CtrSampleClock(2),
1434 NI_AO_SampleClock,
1435 NI_AO_StartTrigger,
1436 NI_AO_PauseTrigger,
1437 NI_DI_SampleClock,
1438 NI_DI_StartTrigger,
1439 NI_DI_ReferenceTrigger,
1440 NI_DI_PauseTrigger,
1441 NI_DO_SampleClock,
1442 NI_DO_StartTrigger,
1443 NI_DO_PauseTrigger,
1444 NI_10MHzRefClock,
1445 NI_ChangeDetectionEvent,
1446 NI_WatchdogExpiredEvent,
1447 0, /* Termination */
1448 }
1449 },
1450 {
1451 .dest = NI_CtrA(0),
1452 .src = (int[]){
1453 NI_PFI(0),
1454 NI_PFI(1),
1455 NI_PFI(2),
1456 NI_PFI(3),
1457 NI_PFI(4),
1458 NI_PFI(5),
1459 NI_PFI(6),
1460 NI_PFI(7),
1461 TRIGGER_LINE(0),
1462 TRIGGER_LINE(1),
1463 TRIGGER_LINE(2),
1464 TRIGGER_LINE(3),
1465 TRIGGER_LINE(4),
1466 TRIGGER_LINE(5),
1467 TRIGGER_LINE(6),
1468 TRIGGER_LINE(7),
1469 NI_CtrSource(1),
1470 NI_CtrSource(2),
1471 NI_CtrSource(3),
1472 NI_CtrGate(1),
1473 NI_CtrGate(2),
1474 NI_CtrGate(3),
1475 NI_CtrArmStartTrigger(1),
1476 NI_CtrArmStartTrigger(2),
1477 NI_CtrArmStartTrigger(3),
1478 NI_CtrInternalOutput(0),
1479 NI_CtrInternalOutput(1),
1480 NI_CtrInternalOutput(2),
1481 NI_CtrInternalOutput(3),
1482 NI_CtrSampleClock(1),
1483 NI_CtrSampleClock(2),
1484 NI_CtrSampleClock(3),
1485 NI_AO_SampleClock,
1486 NI_AO_StartTrigger,
1487 NI_AO_PauseTrigger,
1488 NI_DI_SampleClock,
1489 NI_DI_StartTrigger,
1490 NI_DI_ReferenceTrigger,
1491 NI_DI_PauseTrigger,
1492 NI_DO_SampleClock,
1493 NI_DO_StartTrigger,
1494 NI_DO_PauseTrigger,
1495 NI_10MHzRefClock,
1496 NI_ChangeDetectionEvent,
1497 NI_WatchdogExpiredEvent,
1498 0, /* Termination */
1499 }
1500 },
1501 {
1502 .dest = NI_CtrA(1),
1503 .src = (int[]){
1504 NI_PFI(0),
1505 NI_PFI(1),
1506 NI_PFI(2),
1507 NI_PFI(3),
1508 NI_PFI(4),
1509 NI_PFI(5),
1510 NI_PFI(6),
1511 NI_PFI(7),
1512 TRIGGER_LINE(0),
1513 TRIGGER_LINE(1),
1514 TRIGGER_LINE(2),
1515 TRIGGER_LINE(3),
1516 TRIGGER_LINE(4),
1517 TRIGGER_LINE(5),
1518 TRIGGER_LINE(6),
1519 TRIGGER_LINE(7),
1520 NI_CtrSource(0),
1521 NI_CtrSource(2),
1522 NI_CtrSource(3),
1523 NI_CtrGate(0),
1524 NI_CtrGate(2),
1525 NI_CtrGate(3),
1526 NI_CtrArmStartTrigger(0),
1527 NI_CtrArmStartTrigger(2),
1528 NI_CtrArmStartTrigger(3),
1529 NI_CtrInternalOutput(0),
1530 NI_CtrInternalOutput(1),
1531 NI_CtrInternalOutput(2),
1532 NI_CtrInternalOutput(3),
1533 NI_CtrSampleClock(0),
1534 NI_CtrSampleClock(2),
1535 NI_CtrSampleClock(3),
1536 NI_AO_SampleClock,
1537 NI_AO_StartTrigger,
1538 NI_AO_PauseTrigger,
1539 NI_DI_SampleClock,
1540 NI_DI_StartTrigger,
1541 NI_DI_ReferenceTrigger,
1542 NI_DI_PauseTrigger,
1543 NI_DO_SampleClock,
1544 NI_DO_StartTrigger,
1545 NI_DO_PauseTrigger,
1546 NI_10MHzRefClock,
1547 NI_ChangeDetectionEvent,
1548 NI_WatchdogExpiredEvent,
1549 0, /* Termination */
1550 }
1551 },
1552 {
1553 .dest = NI_CtrA(2),
1554 .src = (int[]){
1555 NI_PFI(0),
1556 NI_PFI(1),
1557 NI_PFI(2),
1558 NI_PFI(3),
1559 NI_PFI(4),
1560 NI_PFI(5),
1561 NI_PFI(6),
1562 NI_PFI(7),
1563 TRIGGER_LINE(0),
1564 TRIGGER_LINE(1),
1565 TRIGGER_LINE(2),
1566 TRIGGER_LINE(3),
1567 TRIGGER_LINE(4),
1568 TRIGGER_LINE(5),
1569 TRIGGER_LINE(6),
1570 TRIGGER_LINE(7),
1571 NI_CtrSource(0),
1572 NI_CtrSource(1),
1573 NI_CtrSource(3),
1574 NI_CtrGate(0),
1575 NI_CtrGate(1),
1576 NI_CtrGate(3),
1577 NI_CtrArmStartTrigger(0),
1578 NI_CtrArmStartTrigger(1),
1579 NI_CtrArmStartTrigger(3),
1580 NI_CtrInternalOutput(0),
1581 NI_CtrInternalOutput(1),
1582 NI_CtrInternalOutput(2),
1583 NI_CtrInternalOutput(3),
1584 NI_CtrSampleClock(0),
1585 NI_CtrSampleClock(1),
1586 NI_CtrSampleClock(3),
1587 NI_AO_SampleClock,
1588 NI_AO_StartTrigger,
1589 NI_AO_PauseTrigger,
1590 NI_DI_SampleClock,
1591 NI_DI_StartTrigger,
1592 NI_DI_ReferenceTrigger,
1593 NI_DI_PauseTrigger,
1594 NI_DO_SampleClock,
1595 NI_DO_StartTrigger,
1596 NI_DO_PauseTrigger,
1597 NI_10MHzRefClock,
1598 NI_ChangeDetectionEvent,
1599 NI_WatchdogExpiredEvent,
1600 0, /* Termination */
1601 }
1602 },
1603 {
1604 .dest = NI_CtrA(3),
1605 .src = (int[]){
1606 NI_PFI(0),
1607 NI_PFI(1),
1608 NI_PFI(2),
1609 NI_PFI(3),
1610 NI_PFI(4),
1611 NI_PFI(5),
1612 NI_PFI(6),
1613 NI_PFI(7),
1614 TRIGGER_LINE(0),
1615 TRIGGER_LINE(1),
1616 TRIGGER_LINE(2),
1617 TRIGGER_LINE(3),
1618 TRIGGER_LINE(4),
1619 TRIGGER_LINE(5),
1620 TRIGGER_LINE(6),
1621 TRIGGER_LINE(7),
1622 NI_CtrSource(0),
1623 NI_CtrSource(1),
1624 NI_CtrSource(2),
1625 NI_CtrGate(0),
1626 NI_CtrGate(1),
1627 NI_CtrGate(2),
1628 NI_CtrArmStartTrigger(0),
1629 NI_CtrArmStartTrigger(1),
1630 NI_CtrArmStartTrigger(2),
1631 NI_CtrInternalOutput(0),
1632 NI_CtrInternalOutput(1),
1633 NI_CtrInternalOutput(2),
1634 NI_CtrInternalOutput(3),
1635 NI_CtrSampleClock(0),
1636 NI_CtrSampleClock(1),
1637 NI_CtrSampleClock(2),
1638 NI_AO_SampleClock,
1639 NI_AO_StartTrigger,
1640 NI_AO_PauseTrigger,
1641 NI_DI_SampleClock,
1642 NI_DI_StartTrigger,
1643 NI_DI_ReferenceTrigger,
1644 NI_DI_PauseTrigger,
1645 NI_DO_SampleClock,
1646 NI_DO_StartTrigger,
1647 NI_DO_PauseTrigger,
1648 NI_10MHzRefClock,
1649 NI_ChangeDetectionEvent,
1650 NI_WatchdogExpiredEvent,
1651 0, /* Termination */
1652 }
1653 },
1654 {
1655 .dest = NI_CtrB(0),
1656 .src = (int[]){
1657 NI_PFI(0),
1658 NI_PFI(1),
1659 NI_PFI(2),
1660 NI_PFI(3),
1661 NI_PFI(4),
1662 NI_PFI(5),
1663 NI_PFI(6),
1664 NI_PFI(7),
1665 TRIGGER_LINE(0),
1666 TRIGGER_LINE(1),
1667 TRIGGER_LINE(2),
1668 TRIGGER_LINE(3),
1669 TRIGGER_LINE(4),
1670 TRIGGER_LINE(5),
1671 TRIGGER_LINE(6),
1672 TRIGGER_LINE(7),
1673 NI_CtrSource(1),
1674 NI_CtrSource(2),
1675 NI_CtrSource(3),
1676 NI_CtrGate(1),
1677 NI_CtrGate(2),
1678 NI_CtrGate(3),
1679 NI_CtrArmStartTrigger(1),
1680 NI_CtrArmStartTrigger(2),
1681 NI_CtrArmStartTrigger(3),
1682 NI_CtrInternalOutput(0),
1683 NI_CtrInternalOutput(1),
1684 NI_CtrInternalOutput(2),
1685 NI_CtrInternalOutput(3),
1686 NI_CtrSampleClock(1),
1687 NI_CtrSampleClock(2),
1688 NI_CtrSampleClock(3),
1689 NI_AO_SampleClock,
1690 NI_AO_StartTrigger,
1691 NI_AO_PauseTrigger,
1692 NI_DI_SampleClock,
1693 NI_DI_StartTrigger,
1694 NI_DI_ReferenceTrigger,
1695 NI_DI_PauseTrigger,
1696 NI_DO_SampleClock,
1697 NI_DO_StartTrigger,
1698 NI_DO_PauseTrigger,
1699 NI_10MHzRefClock,
1700 NI_ChangeDetectionEvent,
1701 NI_WatchdogExpiredEvent,
1702 0, /* Termination */
1703 }
1704 },
1705 {
1706 .dest = NI_CtrB(1),
1707 .src = (int[]){
1708 NI_PFI(0),
1709 NI_PFI(1),
1710 NI_PFI(2),
1711 NI_PFI(3),
1712 NI_PFI(4),
1713 NI_PFI(5),
1714 NI_PFI(6),
1715 NI_PFI(7),
1716 TRIGGER_LINE(0),
1717 TRIGGER_LINE(1),
1718 TRIGGER_LINE(2),
1719 TRIGGER_LINE(3),
1720 TRIGGER_LINE(4),
1721 TRIGGER_LINE(5),
1722 TRIGGER_LINE(6),
1723 TRIGGER_LINE(7),
1724 NI_CtrSource(0),
1725 NI_CtrSource(2),
1726 NI_CtrSource(3),
1727 NI_CtrGate(0),
1728 NI_CtrGate(2),
1729 NI_CtrGate(3),
1730 NI_CtrArmStartTrigger(0),
1731 NI_CtrArmStartTrigger(2),
1732 NI_CtrArmStartTrigger(3),
1733 NI_CtrInternalOutput(0),
1734 NI_CtrInternalOutput(1),
1735 NI_CtrInternalOutput(2),
1736 NI_CtrInternalOutput(3),
1737 NI_CtrSampleClock(0),
1738 NI_CtrSampleClock(2),
1739 NI_CtrSampleClock(3),
1740 NI_AO_SampleClock,
1741 NI_AO_StartTrigger,
1742 NI_AO_PauseTrigger,
1743 NI_DI_SampleClock,
1744 NI_DI_StartTrigger,
1745 NI_DI_ReferenceTrigger,
1746 NI_DI_PauseTrigger,
1747 NI_DO_SampleClock,
1748 NI_DO_StartTrigger,
1749 NI_DO_PauseTrigger,
1750 NI_10MHzRefClock,
1751 NI_ChangeDetectionEvent,
1752 NI_WatchdogExpiredEvent,
1753 0, /* Termination */
1754 }
1755 },
1756 {
1757 .dest = NI_CtrB(2),
1758 .src = (int[]){
1759 NI_PFI(0),
1760 NI_PFI(1),
1761 NI_PFI(2),
1762 NI_PFI(3),
1763 NI_PFI(4),
1764 NI_PFI(5),
1765 NI_PFI(6),
1766 NI_PFI(7),
1767 TRIGGER_LINE(0),
1768 TRIGGER_LINE(1),
1769 TRIGGER_LINE(2),
1770 TRIGGER_LINE(3),
1771 TRIGGER_LINE(4),
1772 TRIGGER_LINE(5),
1773 TRIGGER_LINE(6),
1774 TRIGGER_LINE(7),
1775 NI_CtrSource(0),
1776 NI_CtrSource(1),
1777 NI_CtrSource(3),
1778 NI_CtrGate(0),
1779 NI_CtrGate(1),
1780 NI_CtrGate(3),
1781 NI_CtrArmStartTrigger(0),
1782 NI_CtrArmStartTrigger(1),
1783 NI_CtrArmStartTrigger(3),
1784 NI_CtrInternalOutput(0),
1785 NI_CtrInternalOutput(1),
1786 NI_CtrInternalOutput(2),
1787 NI_CtrInternalOutput(3),
1788 NI_CtrSampleClock(0),
1789 NI_CtrSampleClock(1),
1790 NI_CtrSampleClock(3),
1791 NI_AO_SampleClock,
1792 NI_AO_StartTrigger,
1793 NI_AO_PauseTrigger,
1794 NI_DI_SampleClock,
1795 NI_DI_StartTrigger,
1796 NI_DI_ReferenceTrigger,
1797 NI_DI_PauseTrigger,
1798 NI_DO_SampleClock,
1799 NI_DO_StartTrigger,
1800 NI_DO_PauseTrigger,
1801 NI_10MHzRefClock,
1802 NI_ChangeDetectionEvent,
1803 NI_WatchdogExpiredEvent,
1804 0, /* Termination */
1805 }
1806 },
1807 {
1808 .dest = NI_CtrB(3),
1809 .src = (int[]){
1810 NI_PFI(0),
1811 NI_PFI(1),
1812 NI_PFI(2),
1813 NI_PFI(3),
1814 NI_PFI(4),
1815 NI_PFI(5),
1816 NI_PFI(6),
1817 NI_PFI(7),
1818 TRIGGER_LINE(0),
1819 TRIGGER_LINE(1),
1820 TRIGGER_LINE(2),
1821 TRIGGER_LINE(3),
1822 TRIGGER_LINE(4),
1823 TRIGGER_LINE(5),
1824 TRIGGER_LINE(6),
1825 TRIGGER_LINE(7),
1826 NI_CtrSource(0),
1827 NI_CtrSource(1),
1828 NI_CtrSource(2),
1829 NI_CtrGate(0),
1830 NI_CtrGate(1),
1831 NI_CtrGate(2),
1832 NI_CtrArmStartTrigger(0),
1833 NI_CtrArmStartTrigger(1),
1834 NI_CtrArmStartTrigger(2),
1835 NI_CtrInternalOutput(0),
1836 NI_CtrInternalOutput(1),
1837 NI_CtrInternalOutput(2),
1838 NI_CtrInternalOutput(3),
1839 NI_CtrSampleClock(0),
1840 NI_CtrSampleClock(1),
1841 NI_CtrSampleClock(2),
1842 NI_AO_SampleClock,
1843 NI_AO_StartTrigger,
1844 NI_AO_PauseTrigger,
1845 NI_DI_SampleClock,
1846 NI_DI_StartTrigger,
1847 NI_DI_ReferenceTrigger,
1848 NI_DI_PauseTrigger,
1849 NI_DO_SampleClock,
1850 NI_DO_StartTrigger,
1851 NI_DO_PauseTrigger,
1852 NI_10MHzRefClock,
1853 NI_ChangeDetectionEvent,
1854 NI_WatchdogExpiredEvent,
1855 0, /* Termination */
1856 }
1857 },
1858 {
1859 .dest = NI_CtrZ(0),
1860 .src = (int[]){
1861 NI_PFI(0),
1862 NI_PFI(1),
1863 NI_PFI(2),
1864 NI_PFI(3),
1865 NI_PFI(4),
1866 NI_PFI(5),
1867 NI_PFI(6),
1868 NI_PFI(7),
1869 TRIGGER_LINE(0),
1870 TRIGGER_LINE(1),
1871 TRIGGER_LINE(2),
1872 TRIGGER_LINE(3),
1873 TRIGGER_LINE(4),
1874 TRIGGER_LINE(5),
1875 TRIGGER_LINE(6),
1876 TRIGGER_LINE(7),
1877 NI_CtrSource(1),
1878 NI_CtrSource(2),
1879 NI_CtrSource(3),
1880 NI_CtrGate(1),
1881 NI_CtrGate(2),
1882 NI_CtrGate(3),
1883 NI_CtrArmStartTrigger(1),
1884 NI_CtrArmStartTrigger(2),
1885 NI_CtrArmStartTrigger(3),
1886 NI_CtrInternalOutput(0),
1887 NI_CtrInternalOutput(1),
1888 NI_CtrInternalOutput(2),
1889 NI_CtrInternalOutput(3),
1890 NI_CtrSampleClock(1),
1891 NI_CtrSampleClock(2),
1892 NI_CtrSampleClock(3),
1893 NI_AO_SampleClock,
1894 NI_AO_StartTrigger,
1895 NI_AO_PauseTrigger,
1896 NI_DI_SampleClock,
1897 NI_DI_StartTrigger,
1898 NI_DI_ReferenceTrigger,
1899 NI_DI_PauseTrigger,
1900 NI_DO_SampleClock,
1901 NI_DO_StartTrigger,
1902 NI_DO_PauseTrigger,
1903 NI_10MHzRefClock,
1904 NI_ChangeDetectionEvent,
1905 NI_WatchdogExpiredEvent,
1906 0, /* Termination */
1907 }
1908 },
1909 {
1910 .dest = NI_CtrZ(1),
1911 .src = (int[]){
1912 NI_PFI(0),
1913 NI_PFI(1),
1914 NI_PFI(2),
1915 NI_PFI(3),
1916 NI_PFI(4),
1917 NI_PFI(5),
1918 NI_PFI(6),
1919 NI_PFI(7),
1920 TRIGGER_LINE(0),
1921 TRIGGER_LINE(1),
1922 TRIGGER_LINE(2),
1923 TRIGGER_LINE(3),
1924 TRIGGER_LINE(4),
1925 TRIGGER_LINE(5),
1926 TRIGGER_LINE(6),
1927 TRIGGER_LINE(7),
1928 NI_CtrSource(0),
1929 NI_CtrSource(2),
1930 NI_CtrSource(3),
1931 NI_CtrGate(0),
1932 NI_CtrGate(2),
1933 NI_CtrGate(3),
1934 NI_CtrArmStartTrigger(0),
1935 NI_CtrArmStartTrigger(2),
1936 NI_CtrArmStartTrigger(3),
1937 NI_CtrInternalOutput(0),
1938 NI_CtrInternalOutput(1),
1939 NI_CtrInternalOutput(2),
1940 NI_CtrInternalOutput(3),
1941 NI_CtrSampleClock(0),
1942 NI_CtrSampleClock(2),
1943 NI_CtrSampleClock(3),
1944 NI_AO_SampleClock,
1945 NI_AO_StartTrigger,
1946 NI_AO_PauseTrigger,
1947 NI_DI_SampleClock,
1948 NI_DI_StartTrigger,
1949 NI_DI_ReferenceTrigger,
1950 NI_DI_PauseTrigger,
1951 NI_DO_SampleClock,
1952 NI_DO_StartTrigger,
1953 NI_DO_PauseTrigger,
1954 NI_10MHzRefClock,
1955 NI_ChangeDetectionEvent,
1956 NI_WatchdogExpiredEvent,
1957 0, /* Termination */
1958 }
1959 },
1960 {
1961 .dest = NI_CtrZ(2),
1962 .src = (int[]){
1963 NI_PFI(0),
1964 NI_PFI(1),
1965 NI_PFI(2),
1966 NI_PFI(3),
1967 NI_PFI(4),
1968 NI_PFI(5),
1969 NI_PFI(6),
1970 NI_PFI(7),
1971 TRIGGER_LINE(0),
1972 TRIGGER_LINE(1),
1973 TRIGGER_LINE(2),
1974 TRIGGER_LINE(3),
1975 TRIGGER_LINE(4),
1976 TRIGGER_LINE(5),
1977 TRIGGER_LINE(6),
1978 TRIGGER_LINE(7),
1979 NI_CtrSource(0),
1980 NI_CtrSource(1),
1981 NI_CtrSource(3),
1982 NI_CtrGate(0),
1983 NI_CtrGate(1),
1984 NI_CtrGate(3),
1985 NI_CtrArmStartTrigger(0),
1986 NI_CtrArmStartTrigger(1),
1987 NI_CtrArmStartTrigger(3),
1988 NI_CtrInternalOutput(0),
1989 NI_CtrInternalOutput(1),
1990 NI_CtrInternalOutput(2),
1991 NI_CtrInternalOutput(3),
1992 NI_CtrSampleClock(0),
1993 NI_CtrSampleClock(1),
1994 NI_CtrSampleClock(3),
1995 NI_AO_SampleClock,
1996 NI_AO_StartTrigger,
1997 NI_AO_PauseTrigger,
1998 NI_DI_SampleClock,
1999 NI_DI_StartTrigger,
2000 NI_DI_ReferenceTrigger,
2001 NI_DI_PauseTrigger,
2002 NI_DO_SampleClock,
2003 NI_DO_StartTrigger,
2004 NI_DO_PauseTrigger,
2005 NI_10MHzRefClock,
2006 NI_ChangeDetectionEvent,
2007 NI_WatchdogExpiredEvent,
2008 0, /* Termination */
2009 }
2010 },
2011 {
2012 .dest = NI_CtrZ(3),
2013 .src = (int[]){
2014 NI_PFI(0),
2015 NI_PFI(1),
2016 NI_PFI(2),
2017 NI_PFI(3),
2018 NI_PFI(4),
2019 NI_PFI(5),
2020 NI_PFI(6),
2021 NI_PFI(7),
2022 TRIGGER_LINE(0),
2023 TRIGGER_LINE(1),
2024 TRIGGER_LINE(2),
2025 TRIGGER_LINE(3),
2026 TRIGGER_LINE(4),
2027 TRIGGER_LINE(5),
2028 TRIGGER_LINE(6),
2029 TRIGGER_LINE(7),
2030 NI_CtrSource(0),
2031 NI_CtrSource(1),
2032 NI_CtrSource(2),
2033 NI_CtrGate(0),
2034 NI_CtrGate(1),
2035 NI_CtrGate(2),
2036 NI_CtrArmStartTrigger(0),
2037 NI_CtrArmStartTrigger(1),
2038 NI_CtrArmStartTrigger(2),
2039 NI_CtrInternalOutput(0),
2040 NI_CtrInternalOutput(1),
2041 NI_CtrInternalOutput(2),
2042 NI_CtrInternalOutput(3),
2043 NI_CtrSampleClock(0),
2044 NI_CtrSampleClock(1),
2045 NI_CtrSampleClock(2),
2046 NI_AO_SampleClock,
2047 NI_AO_StartTrigger,
2048 NI_AO_PauseTrigger,
2049 NI_DI_SampleClock,
2050 NI_DI_StartTrigger,
2051 NI_DI_ReferenceTrigger,
2052 NI_DI_PauseTrigger,
2053 NI_DO_SampleClock,
2054 NI_DO_StartTrigger,
2055 NI_DO_PauseTrigger,
2056 NI_10MHzRefClock,
2057 NI_ChangeDetectionEvent,
2058 NI_WatchdogExpiredEvent,
2059 0, /* Termination */
2060 }
2061 },
2062 {
2063 .dest = NI_CtrArmStartTrigger(0),
2064 .src = (int[]){
2065 NI_PFI(0),
2066 NI_PFI(1),
2067 NI_PFI(2),
2068 NI_PFI(3),
2069 NI_PFI(4),
2070 NI_PFI(5),
2071 NI_PFI(6),
2072 NI_PFI(7),
2073 TRIGGER_LINE(0),
2074 TRIGGER_LINE(1),
2075 TRIGGER_LINE(2),
2076 TRIGGER_LINE(3),
2077 TRIGGER_LINE(4),
2078 TRIGGER_LINE(5),
2079 TRIGGER_LINE(6),
2080 TRIGGER_LINE(7),
2081 NI_CtrSource(1),
2082 NI_CtrSource(2),
2083 NI_CtrSource(3),
2084 NI_CtrGate(1),
2085 NI_CtrGate(2),
2086 NI_CtrGate(3),
2087 NI_CtrArmStartTrigger(1),
2088 NI_CtrArmStartTrigger(2),
2089 NI_CtrArmStartTrigger(3),
2090 NI_CtrInternalOutput(0),
2091 NI_CtrInternalOutput(1),
2092 NI_CtrInternalOutput(2),
2093 NI_CtrInternalOutput(3),
2094 NI_CtrSampleClock(1),
2095 NI_CtrSampleClock(2),
2096 NI_CtrSampleClock(3),
2097 NI_AO_SampleClock,
2098 NI_AO_StartTrigger,
2099 NI_AO_PauseTrigger,
2100 NI_DI_SampleClock,
2101 NI_DI_StartTrigger,
2102 NI_DI_ReferenceTrigger,
2103 NI_DI_PauseTrigger,
2104 NI_DO_SampleClock,
2105 NI_DO_StartTrigger,
2106 NI_DO_PauseTrigger,
2107 NI_10MHzRefClock,
2108 NI_ChangeDetectionEvent,
2109 NI_WatchdogExpiredEvent,
2110 0, /* Termination */
2111 }
2112 },
2113 {
2114 .dest = NI_CtrArmStartTrigger(1),
2115 .src = (int[]){
2116 NI_PFI(0),
2117 NI_PFI(1),
2118 NI_PFI(2),
2119 NI_PFI(3),
2120 NI_PFI(4),
2121 NI_PFI(5),
2122 NI_PFI(6),
2123 NI_PFI(7),
2124 TRIGGER_LINE(0),
2125 TRIGGER_LINE(1),
2126 TRIGGER_LINE(2),
2127 TRIGGER_LINE(3),
2128 TRIGGER_LINE(4),
2129 TRIGGER_LINE(5),
2130 TRIGGER_LINE(6),
2131 TRIGGER_LINE(7),
2132 NI_CtrSource(0),
2133 NI_CtrSource(2),
2134 NI_CtrSource(3),
2135 NI_CtrGate(0),
2136 NI_CtrGate(2),
2137 NI_CtrGate(3),
2138 NI_CtrArmStartTrigger(0),
2139 NI_CtrArmStartTrigger(2),
2140 NI_CtrArmStartTrigger(3),
2141 NI_CtrInternalOutput(0),
2142 NI_CtrInternalOutput(1),
2143 NI_CtrInternalOutput(2),
2144 NI_CtrInternalOutput(3),
2145 NI_CtrSampleClock(0),
2146 NI_CtrSampleClock(2),
2147 NI_CtrSampleClock(3),
2148 NI_AO_SampleClock,
2149 NI_AO_StartTrigger,
2150 NI_AO_PauseTrigger,
2151 NI_DI_SampleClock,
2152 NI_DI_StartTrigger,
2153 NI_DI_ReferenceTrigger,
2154 NI_DI_PauseTrigger,
2155 NI_DO_SampleClock,
2156 NI_DO_StartTrigger,
2157 NI_DO_PauseTrigger,
2158 NI_10MHzRefClock,
2159 NI_ChangeDetectionEvent,
2160 NI_WatchdogExpiredEvent,
2161 0, /* Termination */
2162 }
2163 },
2164 {
2165 .dest = NI_CtrArmStartTrigger(2),
2166 .src = (int[]){
2167 NI_PFI(0),
2168 NI_PFI(1),
2169 NI_PFI(2),
2170 NI_PFI(3),
2171 NI_PFI(4),
2172 NI_PFI(5),
2173 NI_PFI(6),
2174 NI_PFI(7),
2175 TRIGGER_LINE(0),
2176 TRIGGER_LINE(1),
2177 TRIGGER_LINE(2),
2178 TRIGGER_LINE(3),
2179 TRIGGER_LINE(4),
2180 TRIGGER_LINE(5),
2181 TRIGGER_LINE(6),
2182 TRIGGER_LINE(7),
2183 NI_CtrSource(0),
2184 NI_CtrSource(1),
2185 NI_CtrSource(3),
2186 NI_CtrGate(0),
2187 NI_CtrGate(1),
2188 NI_CtrGate(3),
2189 NI_CtrArmStartTrigger(0),
2190 NI_CtrArmStartTrigger(1),
2191 NI_CtrArmStartTrigger(3),
2192 NI_CtrInternalOutput(0),
2193 NI_CtrInternalOutput(1),
2194 NI_CtrInternalOutput(2),
2195 NI_CtrInternalOutput(3),
2196 NI_CtrSampleClock(0),
2197 NI_CtrSampleClock(1),
2198 NI_CtrSampleClock(3),
2199 NI_AO_SampleClock,
2200 NI_AO_StartTrigger,
2201 NI_AO_PauseTrigger,
2202 NI_DI_SampleClock,
2203 NI_DI_StartTrigger,
2204 NI_DI_ReferenceTrigger,
2205 NI_DI_PauseTrigger,
2206 NI_DO_SampleClock,
2207 NI_DO_StartTrigger,
2208 NI_DO_PauseTrigger,
2209 NI_10MHzRefClock,
2210 NI_ChangeDetectionEvent,
2211 NI_WatchdogExpiredEvent,
2212 0, /* Termination */
2213 }
2214 },
2215 {
2216 .dest = NI_CtrArmStartTrigger(3),
2217 .src = (int[]){
2218 NI_PFI(0),
2219 NI_PFI(1),
2220 NI_PFI(2),
2221 NI_PFI(3),
2222 NI_PFI(4),
2223 NI_PFI(5),
2224 NI_PFI(6),
2225 NI_PFI(7),
2226 TRIGGER_LINE(0),
2227 TRIGGER_LINE(1),
2228 TRIGGER_LINE(2),
2229 TRIGGER_LINE(3),
2230 TRIGGER_LINE(4),
2231 TRIGGER_LINE(5),
2232 TRIGGER_LINE(6),
2233 TRIGGER_LINE(7),
2234 NI_CtrSource(0),
2235 NI_CtrSource(1),
2236 NI_CtrSource(2),
2237 NI_CtrGate(0),
2238 NI_CtrGate(1),
2239 NI_CtrGate(2),
2240 NI_CtrArmStartTrigger(0),
2241 NI_CtrArmStartTrigger(1),
2242 NI_CtrArmStartTrigger(2),
2243 NI_CtrInternalOutput(0),
2244 NI_CtrInternalOutput(1),
2245 NI_CtrInternalOutput(2),
2246 NI_CtrInternalOutput(3),
2247 NI_CtrSampleClock(0),
2248 NI_CtrSampleClock(1),
2249 NI_CtrSampleClock(2),
2250 NI_AO_SampleClock,
2251 NI_AO_StartTrigger,
2252 NI_AO_PauseTrigger,
2253 NI_DI_SampleClock,
2254 NI_DI_StartTrigger,
2255 NI_DI_ReferenceTrigger,
2256 NI_DI_PauseTrigger,
2257 NI_DO_SampleClock,
2258 NI_DO_StartTrigger,
2259 NI_DO_PauseTrigger,
2260 NI_10MHzRefClock,
2261 NI_ChangeDetectionEvent,
2262 NI_WatchdogExpiredEvent,
2263 0, /* Termination */
2264 }
2265 },
2266 {
2267 .dest = NI_CtrSampleClock(0),
2268 .src = (int[]){
2269 NI_PFI(0),
2270 NI_PFI(1),
2271 NI_PFI(2),
2272 NI_PFI(3),
2273 NI_PFI(4),
2274 NI_PFI(5),
2275 NI_PFI(6),
2276 NI_PFI(7),
2277 TRIGGER_LINE(0),
2278 TRIGGER_LINE(1),
2279 TRIGGER_LINE(2),
2280 TRIGGER_LINE(3),
2281 TRIGGER_LINE(4),
2282 TRIGGER_LINE(5),
2283 TRIGGER_LINE(6),
2284 TRIGGER_LINE(7),
2285 NI_CtrSource(1),
2286 NI_CtrSource(2),
2287 NI_CtrSource(3),
2288 NI_CtrGate(1),
2289 NI_CtrGate(2),
2290 NI_CtrGate(3),
2291 NI_CtrArmStartTrigger(1),
2292 NI_CtrArmStartTrigger(2),
2293 NI_CtrArmStartTrigger(3),
2294 NI_CtrInternalOutput(0),
2295 NI_CtrInternalOutput(1),
2296 NI_CtrInternalOutput(2),
2297 NI_CtrInternalOutput(3),
2298 NI_CtrSampleClock(1),
2299 NI_CtrSampleClock(2),
2300 NI_CtrSampleClock(3),
2301 NI_AO_SampleClock,
2302 NI_AO_StartTrigger,
2303 NI_AO_PauseTrigger,
2304 NI_DI_SampleClock,
2305 NI_DI_StartTrigger,
2306 NI_DI_ReferenceTrigger,
2307 NI_DI_PauseTrigger,
2308 NI_DO_SampleClock,
2309 NI_DO_StartTrigger,
2310 NI_DO_PauseTrigger,
2311 NI_10MHzRefClock,
2312 NI_ChangeDetectionEvent,
2313 NI_WatchdogExpiredEvent,
2314 0, /* Termination */
2315 }
2316 },
2317 {
2318 .dest = NI_CtrSampleClock(1),
2319 .src = (int[]){
2320 NI_PFI(0),
2321 NI_PFI(1),
2322 NI_PFI(2),
2323 NI_PFI(3),
2324 NI_PFI(4),
2325 NI_PFI(5),
2326 NI_PFI(6),
2327 NI_PFI(7),
2328 TRIGGER_LINE(0),
2329 TRIGGER_LINE(1),
2330 TRIGGER_LINE(2),
2331 TRIGGER_LINE(3),
2332 TRIGGER_LINE(4),
2333 TRIGGER_LINE(5),
2334 TRIGGER_LINE(6),
2335 TRIGGER_LINE(7),
2336 NI_CtrSource(0),
2337 NI_CtrSource(2),
2338 NI_CtrSource(3),
2339 NI_CtrGate(0),
2340 NI_CtrGate(2),
2341 NI_CtrGate(3),
2342 NI_CtrArmStartTrigger(0),
2343 NI_CtrArmStartTrigger(2),
2344 NI_CtrArmStartTrigger(3),
2345 NI_CtrInternalOutput(0),
2346 NI_CtrInternalOutput(1),
2347 NI_CtrInternalOutput(2),
2348 NI_CtrInternalOutput(3),
2349 NI_CtrSampleClock(0),
2350 NI_CtrSampleClock(2),
2351 NI_CtrSampleClock(3),
2352 NI_AO_SampleClock,
2353 NI_AO_StartTrigger,
2354 NI_AO_PauseTrigger,
2355 NI_DI_SampleClock,
2356 NI_DI_StartTrigger,
2357 NI_DI_ReferenceTrigger,
2358 NI_DI_PauseTrigger,
2359 NI_DO_SampleClock,
2360 NI_DO_StartTrigger,
2361 NI_DO_PauseTrigger,
2362 NI_10MHzRefClock,
2363 NI_ChangeDetectionEvent,
2364 NI_WatchdogExpiredEvent,
2365 0, /* Termination */
2366 }
2367 },
2368 {
2369 .dest = NI_CtrSampleClock(2),
2370 .src = (int[]){
2371 NI_PFI(0),
2372 NI_PFI(1),
2373 NI_PFI(2),
2374 NI_PFI(3),
2375 NI_PFI(4),
2376 NI_PFI(5),
2377 NI_PFI(6),
2378 NI_PFI(7),
2379 TRIGGER_LINE(0),
2380 TRIGGER_LINE(1),
2381 TRIGGER_LINE(2),
2382 TRIGGER_LINE(3),
2383 TRIGGER_LINE(4),
2384 TRIGGER_LINE(5),
2385 TRIGGER_LINE(6),
2386 TRIGGER_LINE(7),
2387 NI_CtrSource(0),
2388 NI_CtrSource(1),
2389 NI_CtrSource(3),
2390 NI_CtrGate(0),
2391 NI_CtrGate(1),
2392 NI_CtrGate(3),
2393 NI_CtrArmStartTrigger(0),
2394 NI_CtrArmStartTrigger(1),
2395 NI_CtrArmStartTrigger(3),
2396 NI_CtrInternalOutput(0),
2397 NI_CtrInternalOutput(1),
2398 NI_CtrInternalOutput(2),
2399 NI_CtrInternalOutput(3),
2400 NI_CtrSampleClock(0),
2401 NI_CtrSampleClock(1),
2402 NI_CtrSampleClock(3),
2403 NI_AO_SampleClock,
2404 NI_AO_StartTrigger,
2405 NI_AO_PauseTrigger,
2406 NI_DI_SampleClock,
2407 NI_DI_StartTrigger,
2408 NI_DI_ReferenceTrigger,
2409 NI_DI_PauseTrigger,
2410 NI_DO_SampleClock,
2411 NI_DO_StartTrigger,
2412 NI_DO_PauseTrigger,
2413 NI_10MHzRefClock,
2414 NI_ChangeDetectionEvent,
2415 NI_WatchdogExpiredEvent,
2416 0, /* Termination */
2417 }
2418 },
2419 {
2420 .dest = NI_CtrSampleClock(3),
2421 .src = (int[]){
2422 NI_PFI(0),
2423 NI_PFI(1),
2424 NI_PFI(2),
2425 NI_PFI(3),
2426 NI_PFI(4),
2427 NI_PFI(5),
2428 NI_PFI(6),
2429 NI_PFI(7),
2430 TRIGGER_LINE(0),
2431 TRIGGER_LINE(1),
2432 TRIGGER_LINE(2),
2433 TRIGGER_LINE(3),
2434 TRIGGER_LINE(4),
2435 TRIGGER_LINE(5),
2436 TRIGGER_LINE(6),
2437 TRIGGER_LINE(7),
2438 NI_CtrSource(0),
2439 NI_CtrSource(1),
2440 NI_CtrSource(2),
2441 NI_CtrGate(0),
2442 NI_CtrGate(1),
2443 NI_CtrGate(2),
2444 NI_CtrArmStartTrigger(0),
2445 NI_CtrArmStartTrigger(1),
2446 NI_CtrArmStartTrigger(2),
2447 NI_CtrInternalOutput(0),
2448 NI_CtrInternalOutput(1),
2449 NI_CtrInternalOutput(2),
2450 NI_CtrInternalOutput(3),
2451 NI_CtrSampleClock(0),
2452 NI_CtrSampleClock(1),
2453 NI_CtrSampleClock(2),
2454 NI_AO_SampleClock,
2455 NI_AO_StartTrigger,
2456 NI_AO_PauseTrigger,
2457 NI_DI_SampleClock,
2458 NI_DI_StartTrigger,
2459 NI_DI_ReferenceTrigger,
2460 NI_DI_PauseTrigger,
2461 NI_DO_SampleClock,
2462 NI_DO_StartTrigger,
2463 NI_DO_PauseTrigger,
2464 NI_10MHzRefClock,
2465 NI_ChangeDetectionEvent,
2466 NI_WatchdogExpiredEvent,
2467 0, /* Termination */
2468 }
2469 },
2470 {
2471 .dest = NI_AO_SampleClock,
2472 .src = (int[]){
2473 NI_PFI(0),
2474 NI_PFI(1),
2475 NI_PFI(2),
2476 NI_PFI(3),
2477 NI_PFI(4),
2478 NI_PFI(5),
2479 NI_PFI(6),
2480 NI_PFI(7),
2481 TRIGGER_LINE(0),
2482 TRIGGER_LINE(1),
2483 TRIGGER_LINE(2),
2484 TRIGGER_LINE(3),
2485 TRIGGER_LINE(4),
2486 TRIGGER_LINE(5),
2487 TRIGGER_LINE(6),
2488 TRIGGER_LINE(7),
2489 NI_CtrSource(0),
2490 NI_CtrSource(1),
2491 NI_CtrSource(2),
2492 NI_CtrSource(3),
2493 NI_CtrGate(0),
2494 NI_CtrGate(1),
2495 NI_CtrGate(2),
2496 NI_CtrGate(3),
2497 NI_CtrArmStartTrigger(0),
2498 NI_CtrArmStartTrigger(1),
2499 NI_CtrArmStartTrigger(2),
2500 NI_CtrArmStartTrigger(3),
2501 NI_CtrInternalOutput(0),
2502 NI_CtrInternalOutput(1),
2503 NI_CtrInternalOutput(2),
2504 NI_CtrInternalOutput(3),
2505 NI_CtrSampleClock(0),
2506 NI_CtrSampleClock(1),
2507 NI_CtrSampleClock(2),
2508 NI_CtrSampleClock(3),
2509 NI_AO_SampleClockTimebase,
2510 NI_DI_SampleClock,
2511 NI_DI_ReferenceTrigger,
2512 NI_DI_PauseTrigger,
2513 NI_DO_SampleClock,
2514 NI_DO_StartTrigger,
2515 NI_DO_PauseTrigger,
2516 NI_10MHzRefClock,
2517 NI_ChangeDetectionEvent,
2518 NI_WatchdogExpiredEvent,
2519 0, /* Termination */
2520 }
2521 },
2522 {
2523 .dest = NI_AO_SampleClockTimebase,
2524 .src = (int[]){
2525 NI_PFI(0),
2526 NI_PFI(1),
2527 NI_PFI(2),
2528 NI_PFI(3),
2529 NI_PFI(4),
2530 NI_PFI(5),
2531 NI_PFI(6),
2532 NI_PFI(7),
2533 TRIGGER_LINE(0),
2534 TRIGGER_LINE(1),
2535 TRIGGER_LINE(2),
2536 TRIGGER_LINE(3),
2537 TRIGGER_LINE(4),
2538 TRIGGER_LINE(5),
2539 TRIGGER_LINE(6),
2540 TRIGGER_LINE(7),
2541 PXI_Clk10,
2542 NI_20MHzTimebase,
2543 NI_100MHzTimebase,
2544 NI_100kHzTimebase,
2545 0, /* Termination */
2546 }
2547 },
2548 {
2549 .dest = NI_AO_StartTrigger,
2550 .src = (int[]){
2551 NI_PFI(0),
2552 NI_PFI(1),
2553 NI_PFI(2),
2554 NI_PFI(3),
2555 NI_PFI(4),
2556 NI_PFI(5),
2557 NI_PFI(6),
2558 NI_PFI(7),
2559 TRIGGER_LINE(0),
2560 TRIGGER_LINE(1),
2561 TRIGGER_LINE(2),
2562 TRIGGER_LINE(3),
2563 TRIGGER_LINE(4),
2564 TRIGGER_LINE(5),
2565 TRIGGER_LINE(6),
2566 TRIGGER_LINE(7),
2567 NI_CtrSource(0),
2568 NI_CtrSource(1),
2569 NI_CtrSource(2),
2570 NI_CtrSource(3),
2571 NI_CtrGate(0),
2572 NI_CtrGate(1),
2573 NI_CtrGate(2),
2574 NI_CtrGate(3),
2575 NI_CtrArmStartTrigger(0),
2576 NI_CtrArmStartTrigger(1),
2577 NI_CtrArmStartTrigger(2),
2578 NI_CtrArmStartTrigger(3),
2579 NI_CtrInternalOutput(0),
2580 NI_CtrInternalOutput(1),
2581 NI_CtrInternalOutput(2),
2582 NI_CtrInternalOutput(3),
2583 NI_CtrSampleClock(0),
2584 NI_CtrSampleClock(1),
2585 NI_CtrSampleClock(2),
2586 NI_CtrSampleClock(3),
2587 NI_DI_SampleClock,
2588 NI_DI_StartTrigger,
2589 NI_DI_ReferenceTrigger,
2590 NI_DI_PauseTrigger,
2591 NI_DO_SampleClock,
2592 NI_DO_StartTrigger,
2593 NI_DO_PauseTrigger,
2594 NI_10MHzRefClock,
2595 NI_ChangeDetectionEvent,
2596 NI_WatchdogExpiredEvent,
2597 0, /* Termination */
2598 }
2599 },
2600 {
2601 .dest = NI_AO_PauseTrigger,
2602 .src = (int[]){
2603 NI_PFI(0),
2604 NI_PFI(1),
2605 NI_PFI(2),
2606 NI_PFI(3),
2607 NI_PFI(4),
2608 NI_PFI(5),
2609 NI_PFI(6),
2610 NI_PFI(7),
2611 TRIGGER_LINE(0),
2612 TRIGGER_LINE(1),
2613 TRIGGER_LINE(2),
2614 TRIGGER_LINE(3),
2615 TRIGGER_LINE(4),
2616 TRIGGER_LINE(5),
2617 TRIGGER_LINE(6),
2618 TRIGGER_LINE(7),
2619 NI_CtrSource(0),
2620 NI_CtrSource(1),
2621 NI_CtrSource(2),
2622 NI_CtrSource(3),
2623 NI_CtrGate(0),
2624 NI_CtrGate(1),
2625 NI_CtrGate(2),
2626 NI_CtrGate(3),
2627 NI_CtrArmStartTrigger(0),
2628 NI_CtrArmStartTrigger(1),
2629 NI_CtrArmStartTrigger(2),
2630 NI_CtrArmStartTrigger(3),
2631 NI_CtrInternalOutput(0),
2632 NI_CtrInternalOutput(1),
2633 NI_CtrInternalOutput(2),
2634 NI_CtrInternalOutput(3),
2635 NI_CtrSampleClock(0),
2636 NI_CtrSampleClock(1),
2637 NI_CtrSampleClock(2),
2638 NI_CtrSampleClock(3),
2639 NI_DI_SampleClock,
2640 NI_DI_StartTrigger,
2641 NI_DI_ReferenceTrigger,
2642 NI_DI_PauseTrigger,
2643 NI_DO_SampleClock,
2644 NI_DO_StartTrigger,
2645 NI_DO_PauseTrigger,
2646 NI_10MHzRefClock,
2647 NI_ChangeDetectionEvent,
2648 NI_WatchdogExpiredEvent,
2649 0, /* Termination */
2650 }
2651 },
2652 {
2653 .dest = NI_DI_SampleClock,
2654 .src = (int[]){
2655 NI_PFI(0),
2656 NI_PFI(1),
2657 NI_PFI(2),
2658 NI_PFI(3),
2659 NI_PFI(4),
2660 NI_PFI(5),
2661 NI_PFI(6),
2662 NI_PFI(7),
2663 TRIGGER_LINE(0),
2664 TRIGGER_LINE(1),
2665 TRIGGER_LINE(2),
2666 TRIGGER_LINE(3),
2667 TRIGGER_LINE(4),
2668 TRIGGER_LINE(5),
2669 TRIGGER_LINE(6),
2670 TRIGGER_LINE(7),
2671 NI_CtrSource(0),
2672 NI_CtrSource(1),
2673 NI_CtrSource(2),
2674 NI_CtrSource(3),
2675 NI_CtrGate(0),
2676 NI_CtrGate(1),
2677 NI_CtrGate(2),
2678 NI_CtrGate(3),
2679 NI_CtrArmStartTrigger(0),
2680 NI_CtrArmStartTrigger(1),
2681 NI_CtrArmStartTrigger(2),
2682 NI_CtrArmStartTrigger(3),
2683 NI_CtrInternalOutput(0),
2684 NI_CtrInternalOutput(1),
2685 NI_CtrInternalOutput(2),
2686 NI_CtrInternalOutput(3),
2687 NI_CtrSampleClock(0),
2688 NI_CtrSampleClock(1),
2689 NI_CtrSampleClock(2),
2690 NI_CtrSampleClock(3),
2691 NI_AO_SampleClock,
2692 NI_AO_StartTrigger,
2693 NI_AO_PauseTrigger,
2694 NI_DO_SampleClock,
2695 NI_DO_StartTrigger,
2696 NI_DO_PauseTrigger,
2697 NI_10MHzRefClock,
2698 NI_ChangeDetectionEvent,
2699 NI_WatchdogExpiredEvent,
2700 0, /* Termination */
2701 }
2702 },
2703 {
2704 .dest = NI_DI_SampleClockTimebase,
2705 .src = (int[]){
2706 NI_PFI(0),
2707 NI_PFI(1),
2708 NI_PFI(2),
2709 NI_PFI(3),
2710 NI_PFI(4),
2711 NI_PFI(5),
2712 NI_PFI(6),
2713 NI_PFI(7),
2714 TRIGGER_LINE(0),
2715 TRIGGER_LINE(1),
2716 TRIGGER_LINE(2),
2717 TRIGGER_LINE(3),
2718 TRIGGER_LINE(4),
2719 TRIGGER_LINE(5),
2720 TRIGGER_LINE(6),
2721 TRIGGER_LINE(7),
2722 PXI_Clk10,
2723 NI_DI_SampleClockTimebase,
2724 NI_20MHzTimebase,
2725 NI_100MHzTimebase,
2726 NI_100kHzTimebase,
2727 0, /* Termination */
2728 }
2729 },
2730 {
2731 .dest = NI_DI_StartTrigger,
2732 .src = (int[]){
2733 NI_PFI(0),
2734 NI_PFI(1),
2735 NI_PFI(2),
2736 NI_PFI(3),
2737 NI_PFI(4),
2738 NI_PFI(5),
2739 NI_PFI(6),
2740 NI_PFI(7),
2741 TRIGGER_LINE(0),
2742 TRIGGER_LINE(1),
2743 TRIGGER_LINE(2),
2744 TRIGGER_LINE(3),
2745 TRIGGER_LINE(4),
2746 TRIGGER_LINE(5),
2747 TRIGGER_LINE(6),
2748 TRIGGER_LINE(7),
2749 NI_CtrSource(0),
2750 NI_CtrSource(1),
2751 NI_CtrSource(2),
2752 NI_CtrSource(3),
2753 NI_CtrGate(0),
2754 NI_CtrGate(1),
2755 NI_CtrGate(2),
2756 NI_CtrGate(3),
2757 NI_CtrArmStartTrigger(0),
2758 NI_CtrArmStartTrigger(1),
2759 NI_CtrArmStartTrigger(2),
2760 NI_CtrArmStartTrigger(3),
2761 NI_CtrInternalOutput(0),
2762 NI_CtrInternalOutput(1),
2763 NI_CtrInternalOutput(2),
2764 NI_CtrInternalOutput(3),
2765 NI_CtrSampleClock(0),
2766 NI_CtrSampleClock(1),
2767 NI_CtrSampleClock(2),
2768 NI_CtrSampleClock(3),
2769 NI_AO_SampleClock,
2770 NI_AO_StartTrigger,
2771 NI_AO_PauseTrigger,
2772 NI_DO_SampleClock,
2773 NI_DO_StartTrigger,
2774 NI_DO_PauseTrigger,
2775 NI_10MHzRefClock,
2776 NI_ChangeDetectionEvent,
2777 NI_WatchdogExpiredEvent,
2778 0, /* Termination */
2779 }
2780 },
2781 {
2782 .dest = NI_DI_ReferenceTrigger,
2783 .src = (int[]){
2784 NI_PFI(0),
2785 NI_PFI(1),
2786 NI_PFI(2),
2787 NI_PFI(3),
2788 NI_PFI(4),
2789 NI_PFI(5),
2790 NI_PFI(6),
2791 NI_PFI(7),
2792 TRIGGER_LINE(0),
2793 TRIGGER_LINE(1),
2794 TRIGGER_LINE(2),
2795 TRIGGER_LINE(3),
2796 TRIGGER_LINE(4),
2797 TRIGGER_LINE(5),
2798 TRIGGER_LINE(6),
2799 TRIGGER_LINE(7),
2800 NI_CtrSource(0),
2801 NI_CtrSource(1),
2802 NI_CtrSource(2),
2803 NI_CtrSource(3),
2804 NI_CtrGate(0),
2805 NI_CtrGate(1),
2806 NI_CtrGate(2),
2807 NI_CtrGate(3),
2808 NI_CtrArmStartTrigger(0),
2809 NI_CtrArmStartTrigger(1),
2810 NI_CtrArmStartTrigger(2),
2811 NI_CtrArmStartTrigger(3),
2812 NI_CtrInternalOutput(0),
2813 NI_CtrInternalOutput(1),
2814 NI_CtrInternalOutput(2),
2815 NI_CtrInternalOutput(3),
2816 NI_CtrSampleClock(0),
2817 NI_CtrSampleClock(1),
2818 NI_CtrSampleClock(2),
2819 NI_CtrSampleClock(3),
2820 NI_AO_SampleClock,
2821 NI_AO_StartTrigger,
2822 NI_AO_PauseTrigger,
2823 NI_DO_SampleClock,
2824 NI_DO_StartTrigger,
2825 NI_DO_PauseTrigger,
2826 NI_10MHzRefClock,
2827 NI_ChangeDetectionEvent,
2828 NI_WatchdogExpiredEvent,
2829 0, /* Termination */
2830 }
2831 },
2832 {
2833 .dest = NI_DI_PauseTrigger,
2834 .src = (int[]){
2835 NI_PFI(0),
2836 NI_PFI(1),
2837 NI_PFI(2),
2838 NI_PFI(3),
2839 NI_PFI(4),
2840 NI_PFI(5),
2841 NI_PFI(6),
2842 NI_PFI(7),
2843 TRIGGER_LINE(0),
2844 TRIGGER_LINE(1),
2845 TRIGGER_LINE(2),
2846 TRIGGER_LINE(3),
2847 TRIGGER_LINE(4),
2848 TRIGGER_LINE(5),
2849 TRIGGER_LINE(6),
2850 TRIGGER_LINE(7),
2851 NI_CtrSource(0),
2852 NI_CtrSource(1),
2853 NI_CtrSource(2),
2854 NI_CtrSource(3),
2855 NI_CtrGate(0),
2856 NI_CtrGate(1),
2857 NI_CtrGate(2),
2858 NI_CtrGate(3),
2859 NI_CtrArmStartTrigger(0),
2860 NI_CtrArmStartTrigger(1),
2861 NI_CtrArmStartTrigger(2),
2862 NI_CtrArmStartTrigger(3),
2863 NI_CtrInternalOutput(0),
2864 NI_CtrInternalOutput(1),
2865 NI_CtrInternalOutput(2),
2866 NI_CtrInternalOutput(3),
2867 NI_CtrSampleClock(0),
2868 NI_CtrSampleClock(1),
2869 NI_CtrSampleClock(2),
2870 NI_CtrSampleClock(3),
2871 NI_AO_SampleClock,
2872 NI_AO_StartTrigger,
2873 NI_AO_PauseTrigger,
2874 NI_DO_SampleClock,
2875 NI_DO_StartTrigger,
2876 NI_DO_PauseTrigger,
2877 NI_10MHzRefClock,
2878 NI_ChangeDetectionEvent,
2879 NI_WatchdogExpiredEvent,
2880 0, /* Termination */
2881 }
2882 },
2883 {
2884 .dest = NI_DO_SampleClock,
2885 .src = (int[]){
2886 NI_PFI(0),
2887 NI_PFI(1),
2888 NI_PFI(2),
2889 NI_PFI(3),
2890 NI_PFI(4),
2891 NI_PFI(5),
2892 NI_PFI(6),
2893 NI_PFI(7),
2894 TRIGGER_LINE(0),
2895 TRIGGER_LINE(1),
2896 TRIGGER_LINE(2),
2897 TRIGGER_LINE(3),
2898 TRIGGER_LINE(4),
2899 TRIGGER_LINE(5),
2900 TRIGGER_LINE(6),
2901 TRIGGER_LINE(7),
2902 NI_CtrSource(0),
2903 NI_CtrSource(1),
2904 NI_CtrSource(2),
2905 NI_CtrSource(3),
2906 NI_CtrGate(0),
2907 NI_CtrGate(1),
2908 NI_CtrGate(2),
2909 NI_CtrGate(3),
2910 NI_CtrArmStartTrigger(0),
2911 NI_CtrArmStartTrigger(1),
2912 NI_CtrArmStartTrigger(2),
2913 NI_CtrArmStartTrigger(3),
2914 NI_CtrInternalOutput(0),
2915 NI_CtrInternalOutput(1),
2916 NI_CtrInternalOutput(2),
2917 NI_CtrInternalOutput(3),
2918 NI_CtrSampleClock(0),
2919 NI_CtrSampleClock(1),
2920 NI_CtrSampleClock(2),
2921 NI_CtrSampleClock(3),
2922 NI_AO_SampleClock,
2923 NI_AO_StartTrigger,
2924 NI_AO_PauseTrigger,
2925 NI_DI_SampleClock,
2926 NI_DI_ReferenceTrigger,
2927 NI_DI_PauseTrigger,
2928 NI_DO_SampleClockTimebase,
2929 NI_10MHzRefClock,
2930 NI_ChangeDetectionEvent,
2931 NI_WatchdogExpiredEvent,
2932 0, /* Termination */
2933 }
2934 },
2935 {
2936 .dest = NI_DO_SampleClockTimebase,
2937 .src = (int[]){
2938 NI_PFI(0),
2939 NI_PFI(1),
2940 NI_PFI(2),
2941 NI_PFI(3),
2942 NI_PFI(4),
2943 NI_PFI(5),
2944 NI_PFI(6),
2945 NI_PFI(7),
2946 TRIGGER_LINE(0),
2947 TRIGGER_LINE(1),
2948 TRIGGER_LINE(2),
2949 TRIGGER_LINE(3),
2950 TRIGGER_LINE(4),
2951 TRIGGER_LINE(5),
2952 TRIGGER_LINE(6),
2953 TRIGGER_LINE(7),
2954 PXI_Clk10,
2955 NI_20MHzTimebase,
2956 NI_100MHzTimebase,
2957 NI_100kHzTimebase,
2958 0, /* Termination */
2959 }
2960 },
2961 {
2962 .dest = NI_DO_StartTrigger,
2963 .src = (int[]){
2964 NI_PFI(0),
2965 NI_PFI(1),
2966 NI_PFI(2),
2967 NI_PFI(3),
2968 NI_PFI(4),
2969 NI_PFI(5),
2970 NI_PFI(6),
2971 NI_PFI(7),
2972 TRIGGER_LINE(0),
2973 TRIGGER_LINE(1),
2974 TRIGGER_LINE(2),
2975 TRIGGER_LINE(3),
2976 TRIGGER_LINE(4),
2977 TRIGGER_LINE(5),
2978 TRIGGER_LINE(6),
2979 TRIGGER_LINE(7),
2980 NI_CtrSource(0),
2981 NI_CtrSource(1),
2982 NI_CtrSource(2),
2983 NI_CtrSource(3),
2984 NI_CtrGate(0),
2985 NI_CtrGate(1),
2986 NI_CtrGate(2),
2987 NI_CtrGate(3),
2988 NI_CtrArmStartTrigger(0),
2989 NI_CtrArmStartTrigger(1),
2990 NI_CtrArmStartTrigger(2),
2991 NI_CtrArmStartTrigger(3),
2992 NI_CtrInternalOutput(0),
2993 NI_CtrInternalOutput(1),
2994 NI_CtrInternalOutput(2),
2995 NI_CtrInternalOutput(3),
2996 NI_CtrSampleClock(0),
2997 NI_CtrSampleClock(1),
2998 NI_CtrSampleClock(2),
2999 NI_CtrSampleClock(3),
3000 NI_AO_SampleClock,
3001 NI_AO_StartTrigger,
3002 NI_AO_PauseTrigger,
3003 NI_DI_SampleClock,
3004 NI_DI_StartTrigger,
3005 NI_DI_ReferenceTrigger,
3006 NI_DI_PauseTrigger,
3007 NI_10MHzRefClock,
3008 NI_ChangeDetectionEvent,
3009 NI_WatchdogExpiredEvent,
3010 0, /* Termination */
3011 }
3012 },
3013 {
3014 .dest = NI_DO_PauseTrigger,
3015 .src = (int[]){
3016 NI_PFI(0),
3017 NI_PFI(1),
3018 NI_PFI(2),
3019 NI_PFI(3),
3020 NI_PFI(4),
3021 NI_PFI(5),
3022 NI_PFI(6),
3023 NI_PFI(7),
3024 TRIGGER_LINE(0),
3025 TRIGGER_LINE(1),
3026 TRIGGER_LINE(2),
3027 TRIGGER_LINE(3),
3028 TRIGGER_LINE(4),
3029 TRIGGER_LINE(5),
3030 TRIGGER_LINE(6),
3031 TRIGGER_LINE(7),
3032 NI_CtrSource(0),
3033 NI_CtrSource(1),
3034 NI_CtrSource(2),
3035 NI_CtrSource(3),
3036 NI_CtrGate(0),
3037 NI_CtrGate(1),
3038 NI_CtrGate(2),
3039 NI_CtrGate(3),
3040 NI_CtrArmStartTrigger(0),
3041 NI_CtrArmStartTrigger(1),
3042 NI_CtrArmStartTrigger(2),
3043 NI_CtrArmStartTrigger(3),
3044 NI_CtrInternalOutput(0),
3045 NI_CtrInternalOutput(1),
3046 NI_CtrInternalOutput(2),
3047 NI_CtrInternalOutput(3),
3048 NI_CtrSampleClock(0),
3049 NI_CtrSampleClock(1),
3050 NI_CtrSampleClock(2),
3051 NI_CtrSampleClock(3),
3052 NI_AO_SampleClock,
3053 NI_AO_StartTrigger,
3054 NI_AO_PauseTrigger,
3055 NI_DI_SampleClock,
3056 NI_DI_StartTrigger,
3057 NI_DI_ReferenceTrigger,
3058 NI_DI_PauseTrigger,
3059 NI_10MHzRefClock,
3060 NI_ChangeDetectionEvent,
3061 NI_WatchdogExpiredEvent,
3062 0, /* Termination */
3063 }
3064 },
3065 {
3066 .dest = NI_WatchdogExpirationTrigger,
3067 .src = (int[]){
3068 TRIGGER_LINE(0),
3069 TRIGGER_LINE(1),
3070 TRIGGER_LINE(2),
3071 TRIGGER_LINE(3),
3072 TRIGGER_LINE(4),
3073 TRIGGER_LINE(5),
3074 TRIGGER_LINE(6),
3075 TRIGGER_LINE(7),
3076 0, /* Termination */
3077 }
3078 },
3079 { /* Termination of list */
3080 .dest = 0,
3081 },
3082 },
3083};
diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_route_values.c b/drivers/staging/comedi/drivers/ni_routing/ni_route_values.c
new file mode 100644
index 000000000000..5901762734ed
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_route_values.c
@@ -0,0 +1,42 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routing/ni_route_values.c
5 * Route information for NI boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21/*
22 * This file includes the tables that are a list of all the values of various
23 * signals routes available on NI hardware. In many cases, one does not
24 * explicitly make these routes, rather one might indicate that something is
25 * used as the source of one particular trigger or another (using
26 * *_src=TRIG_EXT).
27 *
28 * The contents of this file are generated using the tools in
29 * comedi/drivers/ni_routing/tools
30 *
31 * Please use those tools to help maintain the contents of this file.
32 */
33
34#include "ni_route_values.h"
35#include "ni_route_values/all.h"
36
37const struct family_route_values *const ni_all_route_values[] = {
38 &ni_660x_route_values,
39 &ni_eseries_route_values,
40 &ni_mseries_route_values,
41 NULL,
42};
diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_route_values.h b/drivers/staging/comedi/drivers/ni_routing/ni_route_values.h
new file mode 100644
index 000000000000..80e0145fb82b
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_route_values.h
@@ -0,0 +1,98 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routing/ni_route_values.h
5 * Route information for NI boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21#ifndef _COMEDI_DRIVERS_NI_ROUTINT_NI_ROUTE_VALUES_H
22#define _COMEDI_DRIVERS_NI_ROUTINT_NI_ROUTE_VALUES_H
23
24#include "../../comedi.h"
25#include <linux/types.h>
26
27/*
28 * This file includes the tables that are a list of all the values of various
29 * signals routes available on NI hardware. In many cases, one does not
30 * explicitly make these routes, rather one might indicate that something is
31 * used as the source of one particular trigger or another (using
32 * *_src=TRIG_EXT).
33 *
34 * This file is meant to be included by comedi/drivers/ni_routes.c
35 */
36
37#define B(x) ((x) - NI_NAMES_BASE)
38
39/** Marks a register value as valid, implemented, and tested. */
40#define V(x) (((x) & 0x7f) | 0x80)
41
42#ifndef NI_ROUTE_VALUE_EXTERNAL_CONVERSION
43 /** Marks a register value as implemented but needing testing. */
44 #define I(x) V(x)
45 /** Marks a register value as not implemented. */
46 #define U(x) 0x0
47
48 typedef u8 register_type;
49#else
50 /** Marks a register value as implemented but needing testing. */
51 #define I(x) (((x) & 0x7f) | 0x100)
52 /** Marks a register value as not implemented. */
53 #define U(x) (((x) & 0x7f) | 0x200)
54
55 /** Tests whether a register is marked as valid/implemented/tested */
56 #define MARKED_V(x) (((x) & 0x80) != 0)
57 /** Tests whether a register is implemented but not tested */
58 #define MARKED_I(x) (((x) & 0x100) != 0)
59 /** Tests whether a register is not implemented */
60 #define MARKED_U(x) (((x) & 0x200) != 0)
61
62 /* need more space to store extra marks */
63 typedef u16 register_type;
64#endif
65
66/* Mask out the marking bit(s). */
67#define UNMARK(x) ((x) & 0x7f)
68
69/*
70 * Gi_SRC(x,1) implements Gi_Src_SubSelect = 1
71 *
72 * This appears to only really be a valid MUX for m-series devices.
73 */
74#define Gi_SRC(val, subsel) ((val) | ((subsel) << 6))
75
76/**
77 * struct family_route_values - Register values for all routes for a particular
78 * family.
79 * @family: lower-case string representation of a specific series or family of
80 * devices from National Instruments where each member of this family
81 * shares the same register values for the various signal MUXes. It
82 * should be noted that not all devices of any family have access to
83 * all routes defined.
84 * @register_values: Table of all register values for various signal MUXes on
85 * National Instruments devices. The first index of this table is the
86 * signal destination (i.e. identification of the signal MUX). The
87 * second index of this table is the signal source (i.e. input of the
88 * signal MUX).
89 */
90struct family_route_values {
91 const char *family;
92 const register_type register_values[NI_NUM_NAMES][NI_NUM_NAMES];
93
94};
95
96extern const struct family_route_values *const ni_all_route_values[];
97
98#endif /* _COMEDI_DRIVERS_NI_ROUTINT_NI_ROUTE_VALUES_H */
diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_route_values/all.h b/drivers/staging/comedi/drivers/ni_routing/ni_route_values/all.h
new file mode 100644
index 000000000000..7227461500b5
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_route_values/all.h
@@ -0,0 +1,37 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routing/ni_route_values/all.h
5 * List of valid routes for specific NI boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21/*
22 * The contents of this file are generated using the tools in
23 * comedi/drivers/ni_routing/tools
24 *
25 * Please use those tools to help maintain the contents of this file.
26 */
27
28#ifndef _COMEDI_DRIVERS_NI_ROUTING_NI_ROUTE_VALUES_EXTERN_H
29#define _COMEDI_DRIVERS_NI_ROUTING_NI_ROUTE_VALUES_EXTERN_H
30
31#include "../ni_route_values.h"
32
33extern const struct family_route_values ni_660x_route_values;
34extern const struct family_route_values ni_eseries_route_values;
35extern const struct family_route_values ni_mseries_route_values;
36
37#endif //_COMEDI_DRIVERS_NI_ROUTING_NI_ROUTE_VALUES_EXTERN_H
diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_route_values/ni_660x.c b/drivers/staging/comedi/drivers/ni_routing/ni_route_values/ni_660x.c
new file mode 100644
index 000000000000..f1c7e6646261
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_route_values/ni_660x.c
@@ -0,0 +1,650 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routing/ni_route_values/ni_660x.c
5 * Route information for NI_660X boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21/*
22 * This file includes a list of all the values of various signals routes
23 * available on NI 660x hardware. In many cases, one does not explicitly make
24 * these routes, rather one might indicate that something is used as the source
25 * of one particular trigger or another (using *_src=TRIG_EXT).
26 *
27 * The contents of this file can be generated using the tools in
28 * comedi/drivers/ni_routing/tools. This file also contains specific notes to
29 * this family of devices.
30 *
31 * Please use those tools to help maintain the contents of this file, but be
32 * mindful to not lose the notes already made in this file, since these notes
33 * are critical to a complete undertsanding of the register values of this
34 * family.
35 */
36
37#include "../ni_route_values.h"
38#include "all.h"
39
40const struct family_route_values ni_660x_route_values = {
41 .family = "ni_660x",
42 .register_values = {
43 /*
44 * destination = {
45 * source = register value,
46 * ...
47 * }
48 */
49 [B(NI_PFI(8))] = {
50 [B(NI_CtrInternalOutput(7))] = I(1),
51 },
52 [B(NI_PFI(10))] = {
53 [B(NI_CtrGate(7))] = I(1),
54 },
55 [B(NI_PFI(11))] = {
56 [B(NI_CtrSource(7))] = I(1),
57 },
58 [B(NI_PFI(12))] = {
59 [B(NI_CtrInternalOutput(6))] = I(1),
60 },
61 [B(NI_PFI(14))] = {
62 [B(NI_CtrGate(6))] = I(1),
63 },
64 [B(NI_PFI(15))] = {
65 [B(NI_CtrSource(6))] = I(1),
66 },
67 [B(NI_PFI(16))] = {
68 [B(NI_CtrInternalOutput(5))] = I(1),
69 },
70 [B(NI_PFI(18))] = {
71 [B(NI_CtrGate(5))] = I(1),
72 },
73 [B(NI_PFI(19))] = {
74 [B(NI_CtrSource(5))] = I(1),
75 },
76 [B(NI_PFI(20))] = {
77 [B(NI_CtrInternalOutput(4))] = I(1),
78 },
79 [B(NI_PFI(22))] = {
80 [B(NI_CtrGate(4))] = I(1),
81 },
82 [B(NI_PFI(23))] = {
83 [B(NI_CtrSource(4))] = I(1),
84 },
85 [B(NI_PFI(24))] = {
86 [B(NI_CtrInternalOutput(3))] = I(1),
87 },
88 [B(NI_PFI(26))] = {
89 [B(NI_CtrGate(3))] = I(1),
90 },
91 [B(NI_PFI(27))] = {
92 [B(NI_CtrSource(3))] = I(1),
93 },
94 [B(NI_PFI(28))] = {
95 [B(NI_CtrInternalOutput(2))] = I(1),
96 },
97 [B(NI_PFI(30))] = {
98 [B(NI_CtrGate(2))] = I(1),
99 },
100 [B(NI_PFI(31))] = {
101 [B(NI_CtrSource(2))] = I(1),
102 },
103 [B(NI_PFI(32))] = {
104 [B(NI_CtrInternalOutput(1))] = I(1),
105 },
106 [B(NI_PFI(34))] = {
107 [B(NI_CtrGate(1))] = I(1),
108 },
109 [B(NI_PFI(35))] = {
110 [B(NI_CtrSource(1))] = I(1),
111 },
112 [B(NI_PFI(36))] = {
113 [B(NI_CtrInternalOutput(0))] = I(1),
114 },
115 [B(NI_PFI(38))] = {
116 [B(NI_CtrGate(0))] = I(1),
117 },
118 [B(NI_PFI(39))] = {
119 [B(NI_CtrSource(0))] = I(1),
120 },
121 [B(NI_CtrSource(0))] = {
122 /* These are not currently implemented in ni modules */
123 [B(NI_PFI(11))] = U(9),
124 [B(NI_PFI(15))] = U(8),
125 [B(NI_PFI(19))] = U(7),
126 [B(NI_PFI(23))] = U(6),
127 [B(NI_PFI(27))] = U(5),
128 [B(NI_PFI(31))] = U(4),
129 [B(NI_PFI(35))] = U(3),
130 [B(NI_PFI(39))] = U(2 /* or 1 */),
131 [B(TRIGGER_LINE(0))] = U(11),
132 [B(TRIGGER_LINE(1))] = U(12),
133 [B(TRIGGER_LINE(2))] = U(13),
134 [B(TRIGGER_LINE(3))] = U(14),
135 [B(TRIGGER_LINE(4))] = U(15),
136 [B(TRIGGER_LINE(5))] = U(16),
137 [B(TRIGGER_LINE(6))] = U(17),
138 [B(NI_CtrGate(1))] = U(10),
139 [B(NI_20MHzTimebase)] = U(0),
140 [B(NI_80MHzTimebase)] = U(30),
141 [B(NI_100kHzTimebase)] = U(18),
142 [B(NI_LogicLow)] = U(31),
143 },
144 [B(NI_CtrSource(1))] = {
145 /* These are not currently implemented in ni modules */
146 [B(NI_PFI(11))] = U(9),
147 [B(NI_PFI(15))] = U(8),
148 [B(NI_PFI(19))] = U(7),
149 [B(NI_PFI(23))] = U(6),
150 [B(NI_PFI(27))] = U(5),
151 [B(NI_PFI(31))] = U(4),
152 [B(NI_PFI(35))] = U(3 /* or 1 */),
153 [B(NI_PFI(39))] = U(2),
154 [B(TRIGGER_LINE(0))] = U(11),
155 [B(TRIGGER_LINE(1))] = U(12),
156 [B(TRIGGER_LINE(2))] = U(13),
157 [B(TRIGGER_LINE(3))] = U(14),
158 [B(TRIGGER_LINE(4))] = U(15),
159 [B(TRIGGER_LINE(5))] = U(16),
160 [B(TRIGGER_LINE(6))] = U(17),
161 [B(NI_CtrGate(2))] = U(10),
162 [B(NI_20MHzTimebase)] = U(0),
163 [B(NI_80MHzTimebase)] = U(30),
164 [B(NI_100kHzTimebase)] = U(18),
165 [B(NI_LogicLow)] = U(31),
166 },
167 [B(NI_CtrSource(2))] = {
168 /* These are not currently implemented in ni modules */
169 [B(NI_PFI(11))] = U(9),
170 [B(NI_PFI(15))] = U(8),
171 [B(NI_PFI(19))] = U(7),
172 [B(NI_PFI(23))] = U(6),
173 [B(NI_PFI(27))] = U(5),
174 [B(NI_PFI(31))] = U(4 /* or 1 */),
175 [B(NI_PFI(35))] = U(3),
176 [B(NI_PFI(39))] = U(2),
177 [B(TRIGGER_LINE(0))] = U(11),
178 [B(TRIGGER_LINE(1))] = U(12),
179 [B(TRIGGER_LINE(2))] = U(13),
180 [B(TRIGGER_LINE(3))] = U(14),
181 [B(TRIGGER_LINE(4))] = U(15),
182 [B(TRIGGER_LINE(5))] = U(16),
183 [B(TRIGGER_LINE(6))] = U(17),
184 [B(NI_CtrGate(3))] = U(10),
185 [B(NI_20MHzTimebase)] = U(0),
186 [B(NI_80MHzTimebase)] = U(30),
187 [B(NI_100kHzTimebase)] = U(18),
188 [B(NI_LogicLow)] = U(31),
189 },
190 [B(NI_CtrSource(3))] = {
191 /* These are not currently implemented in ni modules */
192 [B(NI_PFI(11))] = U(9),
193 [B(NI_PFI(15))] = U(8),
194 [B(NI_PFI(19))] = U(7),
195 [B(NI_PFI(23))] = U(6),
196 [B(NI_PFI(27))] = U(5 /* or 1 */),
197 [B(NI_PFI(31))] = U(4),
198 [B(NI_PFI(35))] = U(3),
199 [B(NI_PFI(39))] = U(2),
200 [B(TRIGGER_LINE(0))] = U(11),
201 [B(TRIGGER_LINE(1))] = U(12),
202 [B(TRIGGER_LINE(2))] = U(13),
203 [B(TRIGGER_LINE(3))] = U(14),
204 [B(TRIGGER_LINE(4))] = U(15),
205 [B(TRIGGER_LINE(5))] = U(16),
206 [B(TRIGGER_LINE(6))] = U(17),
207 [B(NI_CtrGate(4))] = U(10),
208 [B(NI_20MHzTimebase)] = U(0),
209 [B(NI_80MHzTimebase)] = U(30),
210 [B(NI_100kHzTimebase)] = U(18),
211 [B(NI_LogicLow)] = U(31),
212 },
213 [B(NI_CtrSource(4))] = {
214 /* These are not currently implemented in ni modules */
215 [B(NI_PFI(11))] = U(9),
216 [B(NI_PFI(15))] = U(8),
217 [B(NI_PFI(19))] = U(7),
218 [B(NI_PFI(23))] = U(6 /* or 1 */),
219 [B(NI_PFI(27))] = U(5),
220 [B(NI_PFI(31))] = U(4),
221 [B(NI_PFI(35))] = U(3),
222 [B(NI_PFI(39))] = U(2),
223 [B(TRIGGER_LINE(0))] = U(11),
224 [B(TRIGGER_LINE(1))] = U(12),
225 [B(TRIGGER_LINE(2))] = U(13),
226 [B(TRIGGER_LINE(3))] = U(14),
227 [B(TRIGGER_LINE(4))] = U(15),
228 [B(TRIGGER_LINE(5))] = U(16),
229 [B(TRIGGER_LINE(6))] = U(17),
230 [B(NI_CtrGate(5))] = U(10),
231 [B(NI_20MHzTimebase)] = U(0),
232 [B(NI_80MHzTimebase)] = U(30),
233 [B(NI_100kHzTimebase)] = U(18),
234 [B(NI_LogicLow)] = U(31),
235 },
236 [B(NI_CtrSource(5))] = {
237 /* These are not currently implemented in ni modules */
238 [B(NI_PFI(11))] = U(9),
239 [B(NI_PFI(15))] = U(8),
240 [B(NI_PFI(19))] = U(7 /* or 1 */),
241 [B(NI_PFI(23))] = U(6),
242 [B(NI_PFI(27))] = U(5),
243 [B(NI_PFI(31))] = U(4),
244 [B(NI_PFI(35))] = U(3),
245 [B(NI_PFI(39))] = U(2),
246 [B(TRIGGER_LINE(0))] = U(11),
247 [B(TRIGGER_LINE(1))] = U(12),
248 [B(TRIGGER_LINE(2))] = U(13),
249 [B(TRIGGER_LINE(3))] = U(14),
250 [B(TRIGGER_LINE(4))] = U(15),
251 [B(TRIGGER_LINE(5))] = U(16),
252 [B(TRIGGER_LINE(6))] = U(17),
253 [B(NI_CtrGate(6))] = U(10),
254 [B(NI_20MHzTimebase)] = U(0),
255 [B(NI_80MHzTimebase)] = U(30),
256 [B(NI_100kHzTimebase)] = U(18),
257 [B(NI_LogicLow)] = U(31),
258 },
259 [B(NI_CtrSource(6))] = {
260 /* These are not currently implemented in ni modules */
261 [B(NI_PFI(11))] = U(9),
262 [B(NI_PFI(15))] = U(8 /* or 1 */),
263 [B(NI_PFI(19))] = U(7),
264 [B(NI_PFI(23))] = U(6),
265 [B(NI_PFI(27))] = U(5),
266 [B(NI_PFI(31))] = U(4),
267 [B(NI_PFI(35))] = U(3),
268 [B(NI_PFI(39))] = U(2),
269 [B(TRIGGER_LINE(0))] = U(11),
270 [B(TRIGGER_LINE(1))] = U(12),
271 [B(TRIGGER_LINE(2))] = U(13),
272 [B(TRIGGER_LINE(3))] = U(14),
273 [B(TRIGGER_LINE(4))] = U(15),
274 [B(TRIGGER_LINE(5))] = U(16),
275 [B(TRIGGER_LINE(6))] = U(17),
276 [B(NI_CtrGate(7))] = U(10),
277 [B(NI_20MHzTimebase)] = U(0),
278 [B(NI_80MHzTimebase)] = U(30),
279 [B(NI_100kHzTimebase)] = U(18),
280 [B(NI_LogicLow)] = U(31),
281 },
282 [B(NI_CtrSource(7))] = {
283 /* These are not currently implemented in ni modules */
284 [B(NI_PFI(11))] = U(9 /* or 1 */),
285 [B(NI_PFI(15))] = U(8),
286 [B(NI_PFI(19))] = U(7),
287 [B(NI_PFI(23))] = U(6),
288 [B(NI_PFI(27))] = U(5),
289 [B(NI_PFI(31))] = U(4),
290 [B(NI_PFI(35))] = U(3),
291 [B(NI_PFI(39))] = U(2),
292 [B(TRIGGER_LINE(0))] = U(11),
293 [B(TRIGGER_LINE(1))] = U(12),
294 [B(TRIGGER_LINE(2))] = U(13),
295 [B(TRIGGER_LINE(3))] = U(14),
296 [B(TRIGGER_LINE(4))] = U(15),
297 [B(TRIGGER_LINE(5))] = U(16),
298 [B(TRIGGER_LINE(6))] = U(17),
299 [B(NI_CtrGate(0))] = U(10),
300 [B(NI_20MHzTimebase)] = U(0),
301 [B(NI_80MHzTimebase)] = U(30),
302 [B(NI_100kHzTimebase)] = U(18),
303 [B(NI_LogicLow)] = U(31),
304 },
305 [B(NI_CtrGate(0))] = {
306 [B(NI_PFI(10))] = I(9),
307 [B(NI_PFI(14))] = I(8),
308 [B(NI_PFI(18))] = I(7),
309 [B(NI_PFI(22))] = I(6),
310 [B(NI_PFI(26))] = I(5),
311 [B(NI_PFI(30))] = I(4),
312 [B(NI_PFI(34))] = I(3),
313 [B(NI_PFI(38))] = I(2 /* or 1 */),
314 [B(NI_PFI(39))] = I(0),
315 [B(TRIGGER_LINE(0))] = I(11),
316 [B(TRIGGER_LINE(1))] = I(12),
317 [B(TRIGGER_LINE(2))] = I(13),
318 [B(TRIGGER_LINE(3))] = I(14),
319 [B(TRIGGER_LINE(4))] = I(15),
320 [B(TRIGGER_LINE(5))] = I(16),
321 [B(TRIGGER_LINE(6))] = I(17),
322 [B(NI_CtrSource(1))] = I(10),
323 [B(NI_CtrInternalOutput(1))] = I(20),
324 [B(NI_LogicLow)] = I(31 /* or 30 */),
325 },
326 [B(NI_CtrGate(1))] = {
327 [B(NI_PFI(10))] = I(9),
328 [B(NI_PFI(14))] = I(8),
329 [B(NI_PFI(18))] = I(7),
330 [B(NI_PFI(22))] = I(6),
331 [B(NI_PFI(26))] = I(5),
332 [B(NI_PFI(30))] = I(4),
333 [B(NI_PFI(34))] = I(3 /* or 1 */),
334 [B(NI_PFI(35))] = I(0),
335 [B(NI_PFI(38))] = I(2),
336 [B(TRIGGER_LINE(0))] = I(11),
337 [B(TRIGGER_LINE(1))] = I(12),
338 [B(TRIGGER_LINE(2))] = I(13),
339 [B(TRIGGER_LINE(3))] = I(14),
340 [B(TRIGGER_LINE(4))] = I(15),
341 [B(TRIGGER_LINE(5))] = I(16),
342 [B(TRIGGER_LINE(6))] = I(17),
343 [B(NI_CtrSource(2))] = I(10),
344 [B(NI_CtrInternalOutput(2))] = I(20),
345 [B(NI_LogicLow)] = I(31 /* or 30 */),
346 },
347 [B(NI_CtrGate(2))] = {
348 [B(NI_PFI(10))] = I(9),
349 [B(NI_PFI(14))] = I(8),
350 [B(NI_PFI(18))] = I(7),
351 [B(NI_PFI(22))] = I(6),
352 [B(NI_PFI(26))] = I(5),
353 [B(NI_PFI(30))] = I(4 /* or 1 */),
354 [B(NI_PFI(31))] = I(0),
355 [B(NI_PFI(34))] = I(3),
356 [B(NI_PFI(38))] = I(2),
357 [B(TRIGGER_LINE(0))] = I(11),
358 [B(TRIGGER_LINE(1))] = I(12),
359 [B(TRIGGER_LINE(2))] = I(13),
360 [B(TRIGGER_LINE(3))] = I(14),
361 [B(TRIGGER_LINE(4))] = I(15),
362 [B(TRIGGER_LINE(5))] = I(16),
363 [B(TRIGGER_LINE(6))] = I(17),
364 [B(NI_CtrSource(3))] = I(10),
365 [B(NI_CtrInternalOutput(3))] = I(20),
366 [B(NI_LogicLow)] = I(31 /* or 30 */),
367 },
368 [B(NI_CtrGate(3))] = {
369 [B(NI_PFI(10))] = I(9),
370 [B(NI_PFI(14))] = I(8),
371 [B(NI_PFI(18))] = I(7),
372 [B(NI_PFI(22))] = I(6),
373 [B(NI_PFI(26))] = I(5 /* or 1 */),
374 [B(NI_PFI(27))] = I(0),
375 [B(NI_PFI(30))] = I(4),
376 [B(NI_PFI(34))] = I(3),
377 [B(NI_PFI(38))] = I(2),
378 [B(TRIGGER_LINE(0))] = I(11),
379 [B(TRIGGER_LINE(1))] = I(12),
380 [B(TRIGGER_LINE(2))] = I(13),
381 [B(TRIGGER_LINE(3))] = I(14),
382 [B(TRIGGER_LINE(4))] = I(15),
383 [B(TRIGGER_LINE(5))] = I(16),
384 [B(TRIGGER_LINE(6))] = I(17),
385 [B(NI_CtrSource(4))] = I(10),
386 [B(NI_CtrInternalOutput(4))] = I(20),
387 [B(NI_LogicLow)] = I(31 /* or 30 */),
388 },
389 [B(NI_CtrGate(4))] = {
390 [B(NI_PFI(10))] = I(9),
391 [B(NI_PFI(14))] = I(8),
392 [B(NI_PFI(18))] = I(7),
393 [B(NI_PFI(22))] = I(6 /* or 1 */),
394 [B(NI_PFI(23))] = I(0),
395 [B(NI_PFI(26))] = I(5),
396 [B(NI_PFI(30))] = I(4),
397 [B(NI_PFI(34))] = I(3),
398 [B(NI_PFI(38))] = I(2),
399 [B(TRIGGER_LINE(0))] = I(11),
400 [B(TRIGGER_LINE(1))] = I(12),
401 [B(TRIGGER_LINE(2))] = I(13),
402 [B(TRIGGER_LINE(3))] = I(14),
403 [B(TRIGGER_LINE(4))] = I(15),
404 [B(TRIGGER_LINE(5))] = I(16),
405 [B(TRIGGER_LINE(6))] = I(17),
406 [B(NI_CtrSource(5))] = I(10),
407 [B(NI_CtrInternalOutput(5))] = I(20),
408 [B(NI_LogicLow)] = I(31 /* or 30 */),
409 },
410 [B(NI_CtrGate(5))] = {
411 [B(NI_PFI(10))] = I(9),
412 [B(NI_PFI(14))] = I(8),
413 [B(NI_PFI(18))] = I(7 /* or 1 */),
414 [B(NI_PFI(19))] = I(0),
415 [B(NI_PFI(22))] = I(6),
416 [B(NI_PFI(26))] = I(5),
417 [B(NI_PFI(30))] = I(4),
418 [B(NI_PFI(34))] = I(3),
419 [B(NI_PFI(38))] = I(2),
420 [B(TRIGGER_LINE(0))] = I(11),
421 [B(TRIGGER_LINE(1))] = I(12),
422 [B(TRIGGER_LINE(2))] = I(13),
423 [B(TRIGGER_LINE(3))] = I(14),
424 [B(TRIGGER_LINE(4))] = I(15),
425 [B(TRIGGER_LINE(5))] = I(16),
426 [B(TRIGGER_LINE(6))] = I(17),
427 [B(NI_CtrSource(6))] = I(10),
428 [B(NI_CtrInternalOutput(6))] = I(20),
429 [B(NI_LogicLow)] = I(31 /* or 30 */),
430 },
431 [B(NI_CtrGate(6))] = {
432 [B(NI_PFI(10))] = I(9),
433 [B(NI_PFI(14))] = I(8 /* or 1 */),
434 [B(NI_PFI(15))] = I(0),
435 [B(NI_PFI(18))] = I(7),
436 [B(NI_PFI(22))] = I(6),
437 [B(NI_PFI(26))] = I(5),
438 [B(NI_PFI(30))] = I(4),
439 [B(NI_PFI(34))] = I(3),
440 [B(NI_PFI(38))] = I(2),
441 [B(TRIGGER_LINE(0))] = I(11),
442 [B(TRIGGER_LINE(1))] = I(12),
443 [B(TRIGGER_LINE(2))] = I(13),
444 [B(TRIGGER_LINE(3))] = I(14),
445 [B(TRIGGER_LINE(4))] = I(15),
446 [B(TRIGGER_LINE(5))] = I(16),
447 [B(TRIGGER_LINE(6))] = I(17),
448 [B(NI_CtrSource(7))] = I(10),
449 [B(NI_CtrInternalOutput(7))] = I(20),
450 [B(NI_LogicLow)] = I(31 /* or 30 */),
451 },
452 [B(NI_CtrGate(7))] = {
453 [B(NI_PFI(10))] = I(9 /* or 1 */),
454 [B(NI_PFI(11))] = I(0),
455 [B(NI_PFI(14))] = I(8),
456 [B(NI_PFI(18))] = I(7),
457 [B(NI_PFI(22))] = I(6),
458 [B(NI_PFI(26))] = I(5),
459 [B(NI_PFI(30))] = I(4),
460 [B(NI_PFI(34))] = I(3),
461 [B(NI_PFI(38))] = I(2),
462 [B(TRIGGER_LINE(0))] = I(11),
463 [B(TRIGGER_LINE(1))] = I(12),
464 [B(TRIGGER_LINE(2))] = I(13),
465 [B(TRIGGER_LINE(3))] = I(14),
466 [B(TRIGGER_LINE(4))] = I(15),
467 [B(TRIGGER_LINE(5))] = I(16),
468 [B(TRIGGER_LINE(6))] = I(17),
469 [B(NI_CtrSource(0))] = I(10),
470 [B(NI_CtrInternalOutput(0))] = I(20),
471 [B(NI_LogicLow)] = I(31 /* or 30 */),
472 },
473 [B(NI_CtrAux(0))] = {
474 [B(NI_PFI(9))] = I(9),
475 [B(NI_PFI(13))] = I(8),
476 [B(NI_PFI(17))] = I(7),
477 [B(NI_PFI(21))] = I(6),
478 [B(NI_PFI(25))] = I(5),
479 [B(NI_PFI(29))] = I(4),
480 [B(NI_PFI(33))] = I(3),
481 [B(NI_PFI(37))] = I(2 /* or 1 */),
482 [B(NI_PFI(39))] = I(0),
483 [B(TRIGGER_LINE(0))] = I(11),
484 [B(TRIGGER_LINE(1))] = I(12),
485 [B(TRIGGER_LINE(2))] = I(13),
486 [B(TRIGGER_LINE(3))] = I(14),
487 [B(TRIGGER_LINE(4))] = I(15),
488 [B(TRIGGER_LINE(5))] = I(16),
489 [B(TRIGGER_LINE(6))] = I(17),
490 [B(NI_CtrSource(1))] = I(10),
491 [B(NI_CtrGate(1))] = I(30),
492 [B(NI_CtrInternalOutput(1))] = I(20),
493 [B(NI_LogicLow)] = I(31),
494 },
495 [B(NI_CtrAux(1))] = {
496 [B(NI_PFI(9))] = I(9),
497 [B(NI_PFI(13))] = I(8),
498 [B(NI_PFI(17))] = I(7),
499 [B(NI_PFI(21))] = I(6),
500 [B(NI_PFI(25))] = I(5),
501 [B(NI_PFI(29))] = I(4),
502 [B(NI_PFI(33))] = I(3 /* or 1 */),
503 [B(NI_PFI(35))] = I(0),
504 [B(NI_PFI(37))] = I(2),
505 [B(TRIGGER_LINE(0))] = I(11),
506 [B(TRIGGER_LINE(1))] = I(12),
507 [B(TRIGGER_LINE(2))] = I(13),
508 [B(TRIGGER_LINE(3))] = I(14),
509 [B(TRIGGER_LINE(4))] = I(15),
510 [B(TRIGGER_LINE(5))] = I(16),
511 [B(TRIGGER_LINE(6))] = I(17),
512 [B(NI_CtrSource(2))] = I(10),
513 [B(NI_CtrGate(2))] = I(30),
514 [B(NI_CtrInternalOutput(2))] = I(20),
515 [B(NI_LogicLow)] = I(31),
516 },
517 [B(NI_CtrAux(2))] = {
518 [B(NI_PFI(9))] = I(9),
519 [B(NI_PFI(13))] = I(8),
520 [B(NI_PFI(17))] = I(7),
521 [B(NI_PFI(21))] = I(6),
522 [B(NI_PFI(25))] = I(5),
523 [B(NI_PFI(29))] = I(4 /* or 1 */),
524 [B(NI_PFI(31))] = I(0),
525 [B(NI_PFI(33))] = I(3),
526 [B(NI_PFI(37))] = I(2),
527 [B(TRIGGER_LINE(0))] = I(11),
528 [B(TRIGGER_LINE(1))] = I(12),
529 [B(TRIGGER_LINE(2))] = I(13),
530 [B(TRIGGER_LINE(3))] = I(14),
531 [B(TRIGGER_LINE(4))] = I(15),
532 [B(TRIGGER_LINE(5))] = I(16),
533 [B(TRIGGER_LINE(6))] = I(17),
534 [B(NI_CtrSource(3))] = I(10),
535 [B(NI_CtrGate(3))] = I(30),
536 [B(NI_CtrInternalOutput(3))] = I(20),
537 [B(NI_LogicLow)] = I(31),
538 },
539 [B(NI_CtrAux(3))] = {
540 [B(NI_PFI(9))] = I(9),
541 [B(NI_PFI(13))] = I(8),
542 [B(NI_PFI(17))] = I(7),
543 [B(NI_PFI(21))] = I(6),
544 [B(NI_PFI(25))] = I(5 /* or 1 */),
545 [B(NI_PFI(27))] = I(0),
546 [B(NI_PFI(29))] = I(4),
547 [B(NI_PFI(33))] = I(3),
548 [B(NI_PFI(37))] = I(2),
549 [B(TRIGGER_LINE(0))] = I(11),
550 [B(TRIGGER_LINE(1))] = I(12),
551 [B(TRIGGER_LINE(2))] = I(13),
552 [B(TRIGGER_LINE(3))] = I(14),
553 [B(TRIGGER_LINE(4))] = I(15),
554 [B(TRIGGER_LINE(5))] = I(16),
555 [B(TRIGGER_LINE(6))] = I(17),
556 [B(NI_CtrSource(4))] = I(10),
557 [B(NI_CtrGate(4))] = I(30),
558 [B(NI_CtrInternalOutput(4))] = I(20),
559 [B(NI_LogicLow)] = I(31),
560 },
561 [B(NI_CtrAux(4))] = {
562 [B(NI_PFI(9))] = I(9),
563 [B(NI_PFI(13))] = I(8),
564 [B(NI_PFI(17))] = I(7),
565 [B(NI_PFI(21))] = I(6 /* or 1 */),
566 [B(NI_PFI(23))] = I(0),
567 [B(NI_PFI(25))] = I(5),
568 [B(NI_PFI(29))] = I(4),
569 [B(NI_PFI(33))] = I(3),
570 [B(NI_PFI(37))] = I(2),
571 [B(TRIGGER_LINE(0))] = I(11),
572 [B(TRIGGER_LINE(1))] = I(12),
573 [B(TRIGGER_LINE(2))] = I(13),
574 [B(TRIGGER_LINE(3))] = I(14),
575 [B(TRIGGER_LINE(4))] = I(15),
576 [B(TRIGGER_LINE(5))] = I(16),
577 [B(TRIGGER_LINE(6))] = I(17),
578 [B(NI_CtrSource(5))] = I(10),
579 [B(NI_CtrGate(5))] = I(30),
580 [B(NI_CtrInternalOutput(5))] = I(20),
581 [B(NI_LogicLow)] = I(31),
582 },
583 [B(NI_CtrAux(5))] = {
584 [B(NI_PFI(9))] = I(9),
585 [B(NI_PFI(13))] = I(8),
586 [B(NI_PFI(17))] = I(7 /* or 1 */),
587 [B(NI_PFI(19))] = I(0),
588 [B(NI_PFI(21))] = I(6),
589 [B(NI_PFI(25))] = I(5),
590 [B(NI_PFI(29))] = I(4),
591 [B(NI_PFI(33))] = I(3),
592 [B(NI_PFI(37))] = I(2),
593 [B(TRIGGER_LINE(0))] = I(11),
594 [B(TRIGGER_LINE(1))] = I(12),
595 [B(TRIGGER_LINE(2))] = I(13),
596 [B(TRIGGER_LINE(3))] = I(14),
597 [B(TRIGGER_LINE(4))] = I(15),
598 [B(TRIGGER_LINE(5))] = I(16),
599 [B(TRIGGER_LINE(6))] = I(17),
600 [B(NI_CtrSource(6))] = I(10),
601 [B(NI_CtrGate(6))] = I(30),
602 [B(NI_CtrInternalOutput(6))] = I(20),
603 [B(NI_LogicLow)] = I(31),
604 },
605 [B(NI_CtrAux(6))] = {
606 [B(NI_PFI(9))] = I(9),
607 [B(NI_PFI(13))] = I(8 /* or 1 */),
608 [B(NI_PFI(15))] = I(0),
609 [B(NI_PFI(17))] = I(7),
610 [B(NI_PFI(21))] = I(6),
611 [B(NI_PFI(25))] = I(5),
612 [B(NI_PFI(29))] = I(4),
613 [B(NI_PFI(33))] = I(3),
614 [B(NI_PFI(37))] = I(2),
615 [B(TRIGGER_LINE(0))] = I(11),
616 [B(TRIGGER_LINE(1))] = I(12),
617 [B(TRIGGER_LINE(2))] = I(13),
618 [B(TRIGGER_LINE(3))] = I(14),
619 [B(TRIGGER_LINE(4))] = I(15),
620 [B(TRIGGER_LINE(5))] = I(16),
621 [B(TRIGGER_LINE(6))] = I(17),
622 [B(NI_CtrSource(7))] = I(10),
623 [B(NI_CtrGate(7))] = I(30),
624 [B(NI_CtrInternalOutput(7))] = I(20),
625 [B(NI_LogicLow)] = I(31),
626 },
627 [B(NI_CtrAux(7))] = {
628 [B(NI_PFI(9))] = I(9 /* or 1 */),
629 [B(NI_PFI(11))] = I(0),
630 [B(NI_PFI(13))] = I(8),
631 [B(NI_PFI(17))] = I(7),
632 [B(NI_PFI(21))] = I(6),
633 [B(NI_PFI(25))] = I(5),
634 [B(NI_PFI(29))] = I(4),
635 [B(NI_PFI(33))] = I(3),
636 [B(NI_PFI(37))] = I(2),
637 [B(TRIGGER_LINE(0))] = I(11),
638 [B(TRIGGER_LINE(1))] = I(12),
639 [B(TRIGGER_LINE(2))] = I(13),
640 [B(TRIGGER_LINE(3))] = I(14),
641 [B(TRIGGER_LINE(4))] = I(15),
642 [B(TRIGGER_LINE(5))] = I(16),
643 [B(TRIGGER_LINE(6))] = I(17),
644 [B(NI_CtrSource(0))] = I(10),
645 [B(NI_CtrGate(0))] = I(30),
646 [B(NI_CtrInternalOutput(0))] = I(20),
647 [B(NI_LogicLow)] = I(31),
648 },
649 },
650};
diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_route_values/ni_eseries.c b/drivers/staging/comedi/drivers/ni_routing/ni_route_values/ni_eseries.c
new file mode 100644
index 000000000000..d1ab3c9ce585
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_route_values/ni_eseries.c
@@ -0,0 +1,602 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routing/ni_route_values/ni_eseries.c
5 * Route information for NI_ESERIES boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21/*
22 * This file includes a list of all the values of various signals routes
23 * available on NI 660x hardware. In many cases, one does not explicitly make
24 * these routes, rather one might indicate that something is used as the source
25 * of one particular trigger or another (using *_src=TRIG_EXT).
26 *
27 * The contents of this file can be generated using the tools in
28 * comedi/drivers/ni_routing/tools. This file also contains specific notes to
29 * this family of devices.
30 *
31 * Please use those tools to help maintain the contents of this file, but be
32 * mindful to not lose the notes already made in this file, since these notes
33 * are critical to a complete undertsanding of the register values of this
34 * family.
35 */
36
37#include "../ni_route_values.h"
38#include "all.h"
39
40/*
41 * Note that for e-series devices, the backplane TRIGGER_LINE(6) is generally
42 * not connected to RTSI(6).
43 */
44
45const struct family_route_values ni_eseries_route_values = {
46 .family = "ni_eseries",
47 .register_values = {
48 /*
49 * destination = {
50 * source = register value,
51 * ...
52 * }
53 */
54 [B(NI_PFI(0))] = {
55 [B(NI_AI_StartTrigger)] = I(NI_PFI_OUTPUT_AI_START1),
56 },
57 [B(NI_PFI(1))] = {
58 [B(NI_AI_ReferenceTrigger)] = I(NI_PFI_OUTPUT_AI_START2),
59 },
60 [B(NI_PFI(2))] = {
61 [B(NI_AI_ConvertClock)] = I(NI_PFI_OUTPUT_AI_CONVERT),
62 },
63 [B(NI_PFI(3))] = {
64 [B(NI_CtrSource(1))] = I(NI_PFI_OUTPUT_G_SRC1),
65 },
66 [B(NI_PFI(4))] = {
67 [B(NI_CtrGate(1))] = I(NI_PFI_OUTPUT_G_GATE1),
68 },
69 [B(NI_PFI(5))] = {
70 [B(NI_AO_SampleClock)] = I(NI_PFI_OUTPUT_AO_UPDATE_N),
71 },
72 [B(NI_PFI(6))] = {
73 [B(NI_AO_StartTrigger)] = I(NI_PFI_OUTPUT_AO_START1),
74 },
75 [B(NI_PFI(7))] = {
76 [B(NI_AI_SampleClock)] = I(NI_PFI_OUTPUT_AI_START_PULSE),
77 },
78 [B(NI_PFI(8))] = {
79 [B(NI_CtrSource(0))] = I(NI_PFI_OUTPUT_G_SRC0),
80 },
81 [B(NI_PFI(9))] = {
82 [B(NI_CtrGate(0))] = I(NI_PFI_OUTPUT_G_GATE0),
83 },
84 [B(TRIGGER_LINE(0))] = {
85 [B(NI_RTSI_BRD(0))] = I(8),
86 [B(NI_RTSI_BRD(1))] = I(9),
87 [B(NI_RTSI_BRD(2))] = I(10),
88 [B(NI_RTSI_BRD(3))] = I(11),
89 [B(NI_CtrSource(0))] = I(5),
90 [B(NI_CtrGate(0))] = I(6),
91 [B(NI_AI_StartTrigger)] = I(0),
92 [B(NI_AI_ReferenceTrigger)] = I(1),
93 [B(NI_AI_ConvertClock)] = I(2),
94 [B(NI_AO_SampleClock)] = I(3),
95 [B(NI_AO_StartTrigger)] = I(4),
96 [B(NI_RGOUT0)] = I(7),
97 },
98 [B(TRIGGER_LINE(1))] = {
99 [B(NI_RTSI_BRD(0))] = I(8),
100 [B(NI_RTSI_BRD(1))] = I(9),
101 [B(NI_RTSI_BRD(2))] = I(10),
102 [B(NI_RTSI_BRD(3))] = I(11),
103 [B(NI_CtrSource(0))] = I(5),
104 [B(NI_CtrGate(0))] = I(6),
105 [B(NI_AI_StartTrigger)] = I(0),
106 [B(NI_AI_ReferenceTrigger)] = I(1),
107 [B(NI_AI_ConvertClock)] = I(2),
108 [B(NI_AO_SampleClock)] = I(3),
109 [B(NI_AO_StartTrigger)] = I(4),
110 [B(NI_RGOUT0)] = I(7),
111 },
112 [B(TRIGGER_LINE(2))] = {
113 [B(NI_RTSI_BRD(0))] = I(8),
114 [B(NI_RTSI_BRD(1))] = I(9),
115 [B(NI_RTSI_BRD(2))] = I(10),
116 [B(NI_RTSI_BRD(3))] = I(11),
117 [B(NI_CtrSource(0))] = I(5),
118 [B(NI_CtrGate(0))] = I(6),
119 [B(NI_AI_StartTrigger)] = I(0),
120 [B(NI_AI_ReferenceTrigger)] = I(1),
121 [B(NI_AI_ConvertClock)] = I(2),
122 [B(NI_AO_SampleClock)] = I(3),
123 [B(NI_AO_StartTrigger)] = I(4),
124 [B(NI_RGOUT0)] = I(7),
125 },
126 [B(TRIGGER_LINE(3))] = {
127 [B(NI_RTSI_BRD(0))] = I(8),
128 [B(NI_RTSI_BRD(1))] = I(9),
129 [B(NI_RTSI_BRD(2))] = I(10),
130 [B(NI_RTSI_BRD(3))] = I(11),
131 [B(NI_CtrSource(0))] = I(5),
132 [B(NI_CtrGate(0))] = I(6),
133 [B(NI_AI_StartTrigger)] = I(0),
134 [B(NI_AI_ReferenceTrigger)] = I(1),
135 [B(NI_AI_ConvertClock)] = I(2),
136 [B(NI_AO_SampleClock)] = I(3),
137 [B(NI_AO_StartTrigger)] = I(4),
138 [B(NI_RGOUT0)] = I(7),
139 },
140 [B(TRIGGER_LINE(4))] = {
141 [B(NI_RTSI_BRD(0))] = I(8),
142 [B(NI_RTSI_BRD(1))] = I(9),
143 [B(NI_RTSI_BRD(2))] = I(10),
144 [B(NI_RTSI_BRD(3))] = I(11),
145 [B(NI_CtrSource(0))] = I(5),
146 [B(NI_CtrGate(0))] = I(6),
147 [B(NI_AI_StartTrigger)] = I(0),
148 [B(NI_AI_ReferenceTrigger)] = I(1),
149 [B(NI_AI_ConvertClock)] = I(2),
150 [B(NI_AO_SampleClock)] = I(3),
151 [B(NI_AO_StartTrigger)] = I(4),
152 [B(NI_RGOUT0)] = I(7),
153 },
154 [B(TRIGGER_LINE(5))] = {
155 [B(NI_RTSI_BRD(0))] = I(8),
156 [B(NI_RTSI_BRD(1))] = I(9),
157 [B(NI_RTSI_BRD(2))] = I(10),
158 [B(NI_RTSI_BRD(3))] = I(11),
159 [B(NI_CtrSource(0))] = I(5),
160 [B(NI_CtrGate(0))] = I(6),
161 [B(NI_AI_StartTrigger)] = I(0),
162 [B(NI_AI_ReferenceTrigger)] = I(1),
163 [B(NI_AI_ConvertClock)] = I(2),
164 [B(NI_AO_SampleClock)] = I(3),
165 [B(NI_AO_StartTrigger)] = I(4),
166 [B(NI_RGOUT0)] = I(7),
167 },
168 [B(TRIGGER_LINE(6))] = {
169 [B(NI_RTSI_BRD(0))] = I(8),
170 [B(NI_RTSI_BRD(1))] = I(9),
171 [B(NI_RTSI_BRD(2))] = I(10),
172 [B(NI_RTSI_BRD(3))] = I(11),
173 [B(NI_CtrSource(0))] = I(5),
174 [B(NI_CtrGate(0))] = I(6),
175 [B(NI_AI_StartTrigger)] = I(0),
176 [B(NI_AI_ReferenceTrigger)] = I(1),
177 [B(NI_AI_ConvertClock)] = I(2),
178 [B(NI_AO_SampleClock)] = I(3),
179 [B(NI_AO_StartTrigger)] = I(4),
180 [B(NI_RGOUT0)] = I(7),
181 },
182 [B(TRIGGER_LINE(7))] = {
183 [B(NI_20MHzTimebase)] = I(NI_RTSI_OUTPUT_RTSI_OSC),
184 },
185 [B(NI_RTSI_BRD(0))] = {
186 [B(TRIGGER_LINE(0))] = I(0),
187 [B(TRIGGER_LINE(1))] = I(1),
188 [B(TRIGGER_LINE(2))] = I(2),
189 [B(TRIGGER_LINE(3))] = I(3),
190 [B(TRIGGER_LINE(4))] = I(4),
191 [B(TRIGGER_LINE(5))] = I(5),
192 [B(TRIGGER_LINE(6))] = I(6),
193 [B(PXI_Star)] = I(6),
194 [B(NI_AI_STOP)] = I(7),
195 },
196 [B(NI_RTSI_BRD(1))] = {
197 [B(TRIGGER_LINE(0))] = I(0),
198 [B(TRIGGER_LINE(1))] = I(1),
199 [B(TRIGGER_LINE(2))] = I(2),
200 [B(TRIGGER_LINE(3))] = I(3),
201 [B(TRIGGER_LINE(4))] = I(4),
202 [B(TRIGGER_LINE(5))] = I(5),
203 [B(TRIGGER_LINE(6))] = I(6),
204 [B(PXI_Star)] = I(6),
205 [B(NI_AI_STOP)] = I(7),
206 },
207 [B(NI_RTSI_BRD(2))] = {
208 [B(TRIGGER_LINE(0))] = I(0),
209 [B(TRIGGER_LINE(1))] = I(1),
210 [B(TRIGGER_LINE(2))] = I(2),
211 [B(TRIGGER_LINE(3))] = I(3),
212 [B(TRIGGER_LINE(4))] = I(4),
213 [B(TRIGGER_LINE(5))] = I(5),
214 [B(TRIGGER_LINE(6))] = I(6),
215 [B(PXI_Star)] = I(6),
216 [B(NI_AI_SampleClock)] = I(7),
217 },
218 [B(NI_RTSI_BRD(3))] = {
219 [B(TRIGGER_LINE(0))] = I(0),
220 [B(TRIGGER_LINE(1))] = I(1),
221 [B(TRIGGER_LINE(2))] = I(2),
222 [B(TRIGGER_LINE(3))] = I(3),
223 [B(TRIGGER_LINE(4))] = I(4),
224 [B(TRIGGER_LINE(5))] = I(5),
225 [B(TRIGGER_LINE(6))] = I(6),
226 [B(PXI_Star)] = I(6),
227 [B(NI_AI_SampleClock)] = I(7),
228 },
229 [B(NI_CtrSource(0))] = {
230 /* These are not currently implemented in ni modules */
231 [B(NI_PFI(0))] = U(1),
232 [B(NI_PFI(1))] = U(2),
233 [B(NI_PFI(2))] = U(3),
234 [B(NI_PFI(3))] = U(4),
235 [B(NI_PFI(4))] = U(5),
236 [B(NI_PFI(5))] = U(6),
237 [B(NI_PFI(6))] = U(7),
238 [B(NI_PFI(7))] = U(8),
239 [B(NI_PFI(8))] = U(9),
240 [B(NI_PFI(9))] = U(10),
241 [B(TRIGGER_LINE(0))] = U(11),
242 [B(TRIGGER_LINE(1))] = U(12),
243 [B(TRIGGER_LINE(2))] = U(13),
244 [B(TRIGGER_LINE(3))] = U(14),
245 [B(TRIGGER_LINE(4))] = U(15),
246 [B(TRIGGER_LINE(5))] = U(16),
247 [B(TRIGGER_LINE(6))] = U(17),
248 [B(NI_CtrInternalOutput(1))] = U(19),
249 [B(PXI_Star)] = U(17),
250 [B(NI_20MHzTimebase)] = U(0),
251 [B(NI_100kHzTimebase)] = U(18),
252 [B(NI_LogicLow)] = U(31),
253 },
254 [B(NI_CtrSource(1))] = {
255 /* These are not currently implemented in ni modules */
256 [B(NI_PFI(0))] = U(1),
257 [B(NI_PFI(1))] = U(2),
258 [B(NI_PFI(2))] = U(3),
259 [B(NI_PFI(3))] = U(4),
260 [B(NI_PFI(4))] = U(5),
261 [B(NI_PFI(5))] = U(6),
262 [B(NI_PFI(6))] = U(7),
263 [B(NI_PFI(7))] = U(8),
264 [B(NI_PFI(8))] = U(9),
265 [B(NI_PFI(9))] = U(10),
266 [B(TRIGGER_LINE(0))] = U(11),
267 [B(TRIGGER_LINE(1))] = U(12),
268 [B(TRIGGER_LINE(2))] = U(13),
269 [B(TRIGGER_LINE(3))] = U(14),
270 [B(TRIGGER_LINE(4))] = U(15),
271 [B(TRIGGER_LINE(5))] = U(16),
272 [B(TRIGGER_LINE(6))] = U(17),
273 [B(NI_CtrInternalOutput(0))] = U(19),
274 [B(PXI_Star)] = U(17),
275 [B(NI_20MHzTimebase)] = U(0),
276 [B(NI_100kHzTimebase)] = U(18),
277 [B(NI_LogicLow)] = U(31),
278 },
279 [B(NI_CtrGate(0))] = {
280 [B(NI_PFI(0))] = I(1),
281 [B(NI_PFI(1))] = I(2),
282 [B(NI_PFI(2))] = I(3),
283 [B(NI_PFI(3))] = I(4),
284 [B(NI_PFI(4))] = I(5),
285 [B(NI_PFI(5))] = I(6),
286 [B(NI_PFI(6))] = I(7),
287 [B(NI_PFI(7))] = I(8),
288 [B(NI_PFI(8))] = I(9),
289 [B(NI_PFI(9))] = I(10),
290 [B(TRIGGER_LINE(0))] = I(11),
291 [B(TRIGGER_LINE(1))] = I(12),
292 [B(TRIGGER_LINE(2))] = I(13),
293 [B(TRIGGER_LINE(3))] = I(14),
294 [B(TRIGGER_LINE(4))] = I(15),
295 [B(TRIGGER_LINE(5))] = I(16),
296 [B(TRIGGER_LINE(6))] = I(17),
297 [B(NI_CtrInternalOutput(1))] = I(20),
298 [B(PXI_Star)] = I(17),
299 [B(NI_AI_StartTrigger)] = I(21),
300 [B(NI_AI_ReferenceTrigger)] = I(18),
301 [B(NI_LogicLow)] = I(31),
302 },
303 [B(NI_CtrGate(1))] = {
304 [B(NI_PFI(0))] = I(1),
305 [B(NI_PFI(1))] = I(2),
306 [B(NI_PFI(2))] = I(3),
307 [B(NI_PFI(3))] = I(4),
308 [B(NI_PFI(4))] = I(5),
309 [B(NI_PFI(5))] = I(6),
310 [B(NI_PFI(6))] = I(7),
311 [B(NI_PFI(7))] = I(8),
312 [B(NI_PFI(8))] = I(9),
313 [B(NI_PFI(9))] = I(10),
314 [B(TRIGGER_LINE(0))] = I(11),
315 [B(TRIGGER_LINE(1))] = I(12),
316 [B(TRIGGER_LINE(2))] = I(13),
317 [B(TRIGGER_LINE(3))] = I(14),
318 [B(TRIGGER_LINE(4))] = I(15),
319 [B(TRIGGER_LINE(5))] = I(16),
320 [B(TRIGGER_LINE(6))] = I(17),
321 [B(NI_CtrInternalOutput(0))] = I(20),
322 [B(PXI_Star)] = I(17),
323 [B(NI_AI_StartTrigger)] = I(21),
324 [B(NI_AI_ReferenceTrigger)] = I(18),
325 [B(NI_LogicLow)] = I(31),
326 },
327 [B(NI_CtrOut(0))] = {
328 [B(TRIGGER_LINE(0))] = I(1),
329 [B(TRIGGER_LINE(1))] = I(2),
330 [B(TRIGGER_LINE(2))] = I(3),
331 [B(TRIGGER_LINE(3))] = I(4),
332 [B(TRIGGER_LINE(4))] = I(5),
333 [B(TRIGGER_LINE(5))] = I(6),
334 [B(TRIGGER_LINE(6))] = I(7),
335 [B(NI_CtrInternalOutput(0))] = I(0),
336 [B(PXI_Star)] = I(7),
337 },
338 [B(NI_CtrOut(1))] = {
339 [B(NI_CtrInternalOutput(1))] = I(0),
340 },
341 [B(NI_AI_SampleClock)] = {
342 [B(NI_PFI(0))] = I(1),
343 [B(NI_PFI(1))] = I(2),
344 [B(NI_PFI(2))] = I(3),
345 [B(NI_PFI(3))] = I(4),
346 [B(NI_PFI(4))] = I(5),
347 [B(NI_PFI(5))] = I(6),
348 [B(NI_PFI(6))] = I(7),
349 [B(NI_PFI(7))] = I(8),
350 [B(NI_PFI(8))] = I(9),
351 [B(NI_PFI(9))] = I(10),
352 [B(TRIGGER_LINE(0))] = I(11),
353 [B(TRIGGER_LINE(1))] = I(12),
354 [B(TRIGGER_LINE(2))] = I(13),
355 [B(TRIGGER_LINE(3))] = I(14),
356 [B(TRIGGER_LINE(4))] = I(15),
357 [B(TRIGGER_LINE(5))] = I(16),
358 [B(TRIGGER_LINE(6))] = I(17),
359 [B(NI_CtrInternalOutput(0))] = I(19),
360 [B(PXI_Star)] = I(17),
361 [B(NI_AI_SampleClockTimebase)] = I(0),
362 [B(NI_LogicLow)] = I(31),
363 },
364 [B(NI_AI_SampleClockTimebase)] = {
365 /* These are not currently implemented in ni modules */
366 [B(NI_PFI(0))] = U(1),
367 [B(NI_PFI(1))] = U(2),
368 [B(NI_PFI(2))] = U(3),
369 [B(NI_PFI(3))] = U(4),
370 [B(NI_PFI(4))] = U(5),
371 [B(NI_PFI(5))] = U(6),
372 [B(NI_PFI(6))] = U(7),
373 [B(NI_PFI(7))] = U(8),
374 [B(NI_PFI(8))] = U(9),
375 [B(NI_PFI(9))] = U(10),
376 [B(TRIGGER_LINE(0))] = U(11),
377 [B(TRIGGER_LINE(1))] = U(12),
378 [B(TRIGGER_LINE(2))] = U(13),
379 [B(TRIGGER_LINE(3))] = U(14),
380 [B(TRIGGER_LINE(4))] = U(15),
381 [B(TRIGGER_LINE(5))] = U(16),
382 [B(TRIGGER_LINE(6))] = U(17),
383 [B(PXI_Star)] = U(17),
384 [B(NI_20MHzTimebase)] = U(0),
385 [B(NI_100kHzTimebase)] = U(19),
386 [B(NI_LogicLow)] = U(31),
387 },
388 [B(NI_AI_StartTrigger)] = {
389 [B(NI_PFI(0))] = I(1),
390 [B(NI_PFI(1))] = I(2),
391 [B(NI_PFI(2))] = I(3),
392 [B(NI_PFI(3))] = I(4),
393 [B(NI_PFI(4))] = I(5),
394 [B(NI_PFI(5))] = I(6),
395 [B(NI_PFI(6))] = I(7),
396 [B(NI_PFI(7))] = I(8),
397 [B(NI_PFI(8))] = I(9),
398 [B(NI_PFI(9))] = I(10),
399 [B(TRIGGER_LINE(0))] = I(11),
400 [B(TRIGGER_LINE(1))] = I(12),
401 [B(TRIGGER_LINE(2))] = I(13),
402 [B(TRIGGER_LINE(3))] = I(14),
403 [B(TRIGGER_LINE(4))] = I(15),
404 [B(TRIGGER_LINE(5))] = I(16),
405 [B(TRIGGER_LINE(6))] = I(17),
406 [B(NI_CtrInternalOutput(0))] = I(18),
407 [B(PXI_Star)] = I(17),
408 [B(NI_LogicLow)] = I(31),
409 },
410 [B(NI_AI_ReferenceTrigger)] = {
411 /* These are not currently implemented in ni modules */
412 [B(NI_PFI(0))] = U(1),
413 [B(NI_PFI(1))] = U(2),
414 [B(NI_PFI(2))] = U(3),
415 [B(NI_PFI(3))] = U(4),
416 [B(NI_PFI(4))] = U(5),
417 [B(NI_PFI(5))] = U(6),
418 [B(NI_PFI(6))] = U(7),
419 [B(NI_PFI(7))] = U(8),
420 [B(NI_PFI(8))] = U(9),
421 [B(NI_PFI(9))] = U(10),
422 [B(TRIGGER_LINE(0))] = U(11),
423 [B(TRIGGER_LINE(1))] = U(12),
424 [B(TRIGGER_LINE(2))] = U(13),
425 [B(TRIGGER_LINE(3))] = U(14),
426 [B(TRIGGER_LINE(4))] = U(15),
427 [B(TRIGGER_LINE(5))] = U(16),
428 [B(TRIGGER_LINE(6))] = U(17),
429 [B(PXI_Star)] = U(17),
430 [B(NI_LogicLow)] = U(31),
431 },
432 [B(NI_AI_ConvertClock)] = {
433 [B(NI_PFI(0))] = I(1),
434 [B(NI_PFI(1))] = I(2),
435 [B(NI_PFI(2))] = I(3),
436 [B(NI_PFI(3))] = I(4),
437 [B(NI_PFI(4))] = I(5),
438 [B(NI_PFI(5))] = I(6),
439 [B(NI_PFI(6))] = I(7),
440 [B(NI_PFI(7))] = I(8),
441 [B(NI_PFI(8))] = I(9),
442 [B(NI_PFI(9))] = I(10),
443 [B(TRIGGER_LINE(0))] = I(11),
444 [B(TRIGGER_LINE(1))] = I(12),
445 [B(TRIGGER_LINE(2))] = I(13),
446 [B(TRIGGER_LINE(3))] = I(14),
447 [B(TRIGGER_LINE(4))] = I(15),
448 [B(TRIGGER_LINE(5))] = I(16),
449 [B(TRIGGER_LINE(6))] = I(17),
450 [B(NI_CtrInternalOutput(0))] = I(19),
451 [B(PXI_Star)] = I(17),
452 [B(NI_AI_ConvertClockTimebase)] = I(0),
453 [B(NI_LogicLow)] = I(31),
454 },
455 [B(NI_AI_ConvertClockTimebase)] = {
456 /* These are not currently implemented in ni modules */
457 [B(NI_AI_SampleClockTimebase)] = U(0),
458 [B(NI_20MHzTimebase)] = U(1),
459 },
460 [B(NI_AI_PauseTrigger)] = {
461 /* These are not currently implemented in ni modules */
462 [B(NI_PFI(0))] = U(1),
463 [B(NI_PFI(1))] = U(2),
464 [B(NI_PFI(2))] = U(3),
465 [B(NI_PFI(3))] = U(4),
466 [B(NI_PFI(4))] = U(5),
467 [B(NI_PFI(5))] = U(6),
468 [B(NI_PFI(6))] = U(7),
469 [B(NI_PFI(7))] = U(8),
470 [B(NI_PFI(8))] = U(9),
471 [B(NI_PFI(9))] = U(10),
472 [B(TRIGGER_LINE(0))] = U(11),
473 [B(TRIGGER_LINE(1))] = U(12),
474 [B(TRIGGER_LINE(2))] = U(13),
475 [B(TRIGGER_LINE(3))] = U(14),
476 [B(TRIGGER_LINE(4))] = U(15),
477 [B(TRIGGER_LINE(5))] = U(16),
478 [B(TRIGGER_LINE(6))] = U(17),
479 [B(PXI_Star)] = U(17),
480 [B(NI_LogicLow)] = U(31),
481 },
482 [B(NI_AO_SampleClock)] = {
483 [B(NI_PFI(0))] = I(1),
484 [B(NI_PFI(1))] = I(2),
485 [B(NI_PFI(2))] = I(3),
486 [B(NI_PFI(3))] = I(4),
487 [B(NI_PFI(4))] = I(5),
488 [B(NI_PFI(5))] = I(6),
489 [B(NI_PFI(6))] = I(7),
490 [B(NI_PFI(7))] = I(8),
491 [B(NI_PFI(8))] = I(9),
492 [B(NI_PFI(9))] = I(10),
493 [B(TRIGGER_LINE(0))] = I(11),
494 [B(TRIGGER_LINE(1))] = I(12),
495 [B(TRIGGER_LINE(2))] = I(13),
496 [B(TRIGGER_LINE(3))] = I(14),
497 [B(TRIGGER_LINE(4))] = I(15),
498 [B(TRIGGER_LINE(5))] = I(16),
499 [B(TRIGGER_LINE(6))] = I(17),
500 [B(NI_CtrInternalOutput(1))] = I(19),
501 [B(PXI_Star)] = I(17),
502 [B(NI_AO_SampleClockTimebase)] = I(0),
503 [B(NI_LogicLow)] = I(31),
504 },
505 [B(NI_AO_SampleClockTimebase)] = {
506 /* These are not currently implemented in ni modules */
507 [B(NI_PFI(0))] = U(1),
508 [B(NI_PFI(1))] = U(2),
509 [B(NI_PFI(2))] = U(3),
510 [B(NI_PFI(3))] = U(4),
511 [B(NI_PFI(4))] = U(5),
512 [B(NI_PFI(5))] = U(6),
513 [B(NI_PFI(6))] = U(7),
514 [B(NI_PFI(7))] = U(8),
515 [B(NI_PFI(8))] = U(9),
516 [B(NI_PFI(9))] = U(10),
517 [B(TRIGGER_LINE(0))] = U(11),
518 [B(TRIGGER_LINE(1))] = U(12),
519 [B(TRIGGER_LINE(2))] = U(13),
520 [B(TRIGGER_LINE(3))] = U(14),
521 [B(TRIGGER_LINE(4))] = U(15),
522 [B(TRIGGER_LINE(5))] = U(16),
523 [B(TRIGGER_LINE(6))] = U(17),
524 [B(PXI_Star)] = U(17),
525 [B(NI_20MHzTimebase)] = U(0),
526 [B(NI_100kHzTimebase)] = U(19),
527 [B(NI_LogicLow)] = U(31),
528 },
529 [B(NI_AO_StartTrigger)] = {
530 [B(NI_PFI(0))] = I(1),
531 [B(NI_PFI(1))] = I(2),
532 [B(NI_PFI(2))] = I(3),
533 [B(NI_PFI(3))] = I(4),
534 [B(NI_PFI(4))] = I(5),
535 [B(NI_PFI(5))] = I(6),
536 [B(NI_PFI(6))] = I(7),
537 [B(NI_PFI(7))] = I(8),
538 [B(NI_PFI(8))] = I(9),
539 [B(NI_PFI(9))] = I(10),
540 [B(TRIGGER_LINE(0))] = I(11),
541 [B(TRIGGER_LINE(1))] = I(12),
542 [B(TRIGGER_LINE(2))] = I(13),
543 [B(TRIGGER_LINE(3))] = I(14),
544 [B(TRIGGER_LINE(4))] = I(15),
545 [B(TRIGGER_LINE(5))] = I(16),
546 [B(TRIGGER_LINE(6))] = I(17),
547 [B(PXI_Star)] = I(17),
548 /*
549 * for the signal route
550 * (NI_AI_StartTrigger->NI_AO_StartTrigger), MHDDK says
551 * used register value 18 and DAQ-STC says 19.
552 * Hoping that the MHDDK is correct--being a "working"
553 * example.
554 */
555 [B(NI_AI_StartTrigger)] = I(18),
556 [B(NI_LogicLow)] = I(31),
557 },
558 [B(NI_AO_PauseTrigger)] = {
559 /* These are not currently implemented in ni modules */
560 [B(NI_PFI(0))] = U(1),
561 [B(NI_PFI(1))] = U(2),
562 [B(NI_PFI(2))] = U(3),
563 [B(NI_PFI(3))] = U(4),
564 [B(NI_PFI(4))] = U(5),
565 [B(NI_PFI(5))] = U(6),
566 [B(NI_PFI(6))] = U(7),
567 [B(NI_PFI(7))] = U(8),
568 [B(NI_PFI(8))] = U(9),
569 [B(NI_PFI(9))] = U(10),
570 [B(TRIGGER_LINE(0))] = U(11),
571 [B(TRIGGER_LINE(1))] = U(12),
572 [B(TRIGGER_LINE(2))] = U(13),
573 [B(TRIGGER_LINE(3))] = U(14),
574 [B(TRIGGER_LINE(4))] = U(15),
575 [B(TRIGGER_LINE(5))] = U(16),
576 [B(TRIGGER_LINE(6))] = U(17),
577 [B(PXI_Star)] = U(17),
578 [B(NI_LogicLow)] = U(31),
579 },
580 [B(NI_MasterTimebase)] = {
581 /* These are not currently implemented in ni modules */
582 [B(TRIGGER_LINE(7))] = U(1),
583 [B(PXI_Star)] = U(2),
584 [B(PXI_Clk10)] = U(3),
585 [B(NI_10MHzRefClock)] = U(0),
586 },
587 /*
588 * This symbol is not defined and nothing for this is
589 * implemented--just including this because data was found in
590 * the NI-STC for it--can't remember where.
591 * [B(NI_FrequencyOutTimebase)] = {
592 * ** These are not currently implemented in ni modules **
593 * [B(NI_20MHzTimebase)] = U(0),
594 * [B(NI_100kHzTimebase)] = U(1),
595 * },
596 */
597 [B(NI_RGOUT0)] = {
598 [B(NI_CtrInternalOutput(0))] = I(0),
599 [B(NI_CtrOut(0))] = I(1),
600 },
601 },
602};
diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_route_values/ni_mseries.c b/drivers/staging/comedi/drivers/ni_routing/ni_route_values/ni_mseries.c
new file mode 100644
index 000000000000..c59d8afe0ae9
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_route_values/ni_mseries.c
@@ -0,0 +1,1752 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/ni_routing/ni_route_values/ni_mseries.c
5 * Route information for NI_MSERIES boards.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21/*
22 * This file includes a list of all the values of various signals routes
23 * available on NI 660x hardware. In many cases, one does not explicitly make
24 * these routes, rather one might indicate that something is used as the source
25 * of one particular trigger or another (using *_src=TRIG_EXT).
26 *
27 * The contents of this file can be generated using the tools in
28 * comedi/drivers/ni_routing/tools. This file also contains specific notes to
29 * this family of devices.
30 *
31 * Please use those tools to help maintain the contents of this file, but be
32 * mindful to not lose the notes already made in this file, since these notes
33 * are critical to a complete undertsanding of the register values of this
34 * family.
35 */
36
37#include "../ni_route_values.h"
38#include "all.h"
39
40/*
41 * GATE SELECT NOTE:
42 * CtrAux and CtrArmStartrigger register values are not documented in the
43 * DAQ-STC. There is some evidence that using CtrGate values is valid (see
44 * comedi.h). Some information and hints exist in the M-Series user manual
45 * (ni-62xx user-manual 371022K-01).
46 */
47
48const struct family_route_values ni_mseries_route_values = {
49 .family = "ni_mseries",
50 .register_values = {
51 /*
52 * destination = {
53 * source = register value,
54 * ...
55 * }
56 */
57 [B(NI_PFI(0))] = {
58 [B(TRIGGER_LINE(0))] = I(18),
59 [B(TRIGGER_LINE(1))] = I(19),
60 [B(TRIGGER_LINE(2))] = I(20),
61 [B(TRIGGER_LINE(3))] = I(21),
62 [B(TRIGGER_LINE(4))] = I(22),
63 [B(TRIGGER_LINE(5))] = I(23),
64 [B(TRIGGER_LINE(6))] = I(24),
65 [B(TRIGGER_LINE(7))] = I(25),
66 [B(NI_CtrSource(0))] = I(9),
67 [B(NI_CtrSource(1))] = I(4),
68 [B(NI_CtrGate(0))] = I(10),
69 [B(NI_CtrGate(1))] = I(5),
70 [B(NI_CtrInternalOutput(0))] = I(13),
71 [B(NI_CtrInternalOutput(1))] = I(14),
72 [B(PXI_Star)] = I(26),
73 [B(NI_AI_SampleClock)] = I(8),
74 [B(NI_AI_StartTrigger)] = I(1),
75 [B(NI_AI_ReferenceTrigger)] = I(2),
76 [B(NI_AI_ConvertClock)] = I(3),
77 [B(NI_AI_ExternalMUXClock)] = I(12),
78 [B(NI_AO_SampleClock)] = I(6),
79 [B(NI_AO_StartTrigger)] = I(7),
80 [B(NI_DI_SampleClock)] = I(29),
81 [B(NI_DO_SampleClock)] = I(30),
82 [B(NI_FrequencyOutput)] = I(15),
83 [B(NI_ChangeDetectionEvent)] = I(28),
84 [B(NI_AnalogComparisonEvent)] = I(17),
85 [B(NI_SCXI_Trig1)] = I(27),
86 [B(NI_ExternalStrobe)] = I(11),
87 [B(NI_PFI_DO)] = I(16),
88 },
89 [B(NI_PFI(1))] = {
90 [B(TRIGGER_LINE(0))] = I(18),
91 [B(TRIGGER_LINE(1))] = I(19),
92 [B(TRIGGER_LINE(2))] = I(20),
93 [B(TRIGGER_LINE(3))] = I(21),
94 [B(TRIGGER_LINE(4))] = I(22),
95 [B(TRIGGER_LINE(5))] = I(23),
96 [B(TRIGGER_LINE(6))] = I(24),
97 [B(TRIGGER_LINE(7))] = I(25),
98 [B(NI_CtrSource(0))] = I(9),
99 [B(NI_CtrSource(1))] = I(4),
100 [B(NI_CtrGate(0))] = I(10),
101 [B(NI_CtrGate(1))] = I(5),
102 [B(NI_CtrInternalOutput(0))] = I(13),
103 [B(NI_CtrInternalOutput(1))] = I(14),
104 [B(PXI_Star)] = I(26),
105 [B(NI_AI_SampleClock)] = I(8),
106 [B(NI_AI_StartTrigger)] = I(1),
107 [B(NI_AI_ReferenceTrigger)] = I(2),
108 [B(NI_AI_ConvertClock)] = I(3),
109 [B(NI_AI_ExternalMUXClock)] = I(12),
110 [B(NI_AO_SampleClock)] = I(6),
111 [B(NI_AO_StartTrigger)] = I(7),
112 [B(NI_DI_SampleClock)] = I(29),
113 [B(NI_DO_SampleClock)] = I(30),
114 [B(NI_FrequencyOutput)] = I(15),
115 [B(NI_ChangeDetectionEvent)] = I(28),
116 [B(NI_AnalogComparisonEvent)] = I(17),
117 [B(NI_SCXI_Trig1)] = I(27),
118 [B(NI_ExternalStrobe)] = I(11),
119 [B(NI_PFI_DO)] = I(16),
120 },
121 [B(NI_PFI(2))] = {
122 [B(TRIGGER_LINE(0))] = I(18),
123 [B(TRIGGER_LINE(1))] = I(19),
124 [B(TRIGGER_LINE(2))] = I(20),
125 [B(TRIGGER_LINE(3))] = I(21),
126 [B(TRIGGER_LINE(4))] = I(22),
127 [B(TRIGGER_LINE(5))] = I(23),
128 [B(TRIGGER_LINE(6))] = I(24),
129 [B(TRIGGER_LINE(7))] = I(25),
130 [B(NI_CtrSource(0))] = I(9),
131 [B(NI_CtrSource(1))] = I(4),
132 [B(NI_CtrGate(0))] = I(10),
133 [B(NI_CtrGate(1))] = I(5),
134 [B(NI_CtrInternalOutput(0))] = I(13),
135 [B(NI_CtrInternalOutput(1))] = I(14),
136 [B(PXI_Star)] = I(26),
137 [B(NI_AI_SampleClock)] = I(8),
138 [B(NI_AI_StartTrigger)] = I(1),
139 [B(NI_AI_ReferenceTrigger)] = I(2),
140 [B(NI_AI_ConvertClock)] = I(3),
141 [B(NI_AI_ExternalMUXClock)] = I(12),
142 [B(NI_AO_SampleClock)] = I(6),
143 [B(NI_AO_StartTrigger)] = I(7),
144 [B(NI_DI_SampleClock)] = I(29),
145 [B(NI_DO_SampleClock)] = I(30),
146 [B(NI_FrequencyOutput)] = I(15),
147 [B(NI_ChangeDetectionEvent)] = I(28),
148 [B(NI_AnalogComparisonEvent)] = I(17),
149 [B(NI_SCXI_Trig1)] = I(27),
150 [B(NI_ExternalStrobe)] = I(11),
151 [B(NI_PFI_DO)] = I(16),
152 },
153 [B(NI_PFI(3))] = {
154 [B(TRIGGER_LINE(0))] = I(18),
155 [B(TRIGGER_LINE(1))] = I(19),
156 [B(TRIGGER_LINE(2))] = I(20),
157 [B(TRIGGER_LINE(3))] = I(21),
158 [B(TRIGGER_LINE(4))] = I(22),
159 [B(TRIGGER_LINE(5))] = I(23),
160 [B(TRIGGER_LINE(6))] = I(24),
161 [B(TRIGGER_LINE(7))] = I(25),
162 [B(NI_CtrSource(0))] = I(9),
163 [B(NI_CtrSource(1))] = I(4),
164 [B(NI_CtrGate(0))] = I(10),
165 [B(NI_CtrGate(1))] = I(5),
166 [B(NI_CtrInternalOutput(0))] = I(13),
167 [B(NI_CtrInternalOutput(1))] = I(14),
168 [B(PXI_Star)] = I(26),
169 [B(NI_AI_SampleClock)] = I(8),
170 [B(NI_AI_StartTrigger)] = I(1),
171 [B(NI_AI_ReferenceTrigger)] = I(2),
172 [B(NI_AI_ConvertClock)] = I(3),
173 [B(NI_AI_ExternalMUXClock)] = I(12),
174 [B(NI_AO_SampleClock)] = I(6),
175 [B(NI_AO_StartTrigger)] = I(7),
176 [B(NI_DI_SampleClock)] = I(29),
177 [B(NI_DO_SampleClock)] = I(30),
178 [B(NI_FrequencyOutput)] = I(15),
179 [B(NI_ChangeDetectionEvent)] = I(28),
180 [B(NI_AnalogComparisonEvent)] = I(17),
181 [B(NI_SCXI_Trig1)] = I(27),
182 [B(NI_ExternalStrobe)] = I(11),
183 [B(NI_PFI_DO)] = I(16),
184 },
185 [B(NI_PFI(4))] = {
186 [B(TRIGGER_LINE(0))] = I(18),
187 [B(TRIGGER_LINE(1))] = I(19),
188 [B(TRIGGER_LINE(2))] = I(20),
189 [B(TRIGGER_LINE(3))] = I(21),
190 [B(TRIGGER_LINE(4))] = I(22),
191 [B(TRIGGER_LINE(5))] = I(23),
192 [B(TRIGGER_LINE(6))] = I(24),
193 [B(TRIGGER_LINE(7))] = I(25),
194 [B(NI_CtrSource(0))] = I(9),
195 [B(NI_CtrSource(1))] = I(4),
196 [B(NI_CtrGate(0))] = I(10),
197 [B(NI_CtrGate(1))] = I(5),
198 [B(NI_CtrInternalOutput(0))] = I(13),
199 [B(NI_CtrInternalOutput(1))] = I(14),
200 [B(PXI_Star)] = I(26),
201 [B(NI_AI_SampleClock)] = I(8),
202 [B(NI_AI_StartTrigger)] = I(1),
203 [B(NI_AI_ReferenceTrigger)] = I(2),
204 [B(NI_AI_ConvertClock)] = I(3),
205 [B(NI_AI_ExternalMUXClock)] = I(12),
206 [B(NI_AO_SampleClock)] = I(6),
207 [B(NI_AO_StartTrigger)] = I(7),
208 [B(NI_DI_SampleClock)] = I(29),
209 [B(NI_DO_SampleClock)] = I(30),
210 [B(NI_FrequencyOutput)] = I(15),
211 [B(NI_ChangeDetectionEvent)] = I(28),
212 [B(NI_AnalogComparisonEvent)] = I(17),
213 [B(NI_SCXI_Trig1)] = I(27),
214 [B(NI_ExternalStrobe)] = I(11),
215 [B(NI_PFI_DO)] = I(16),
216 },
217 [B(NI_PFI(5))] = {
218 [B(TRIGGER_LINE(0))] = I(18),
219 [B(TRIGGER_LINE(1))] = I(19),
220 [B(TRIGGER_LINE(2))] = I(20),
221 [B(TRIGGER_LINE(3))] = I(21),
222 [B(TRIGGER_LINE(4))] = I(22),
223 [B(TRIGGER_LINE(5))] = I(23),
224 [B(TRIGGER_LINE(6))] = I(24),
225 [B(TRIGGER_LINE(7))] = I(25),
226 [B(NI_CtrSource(0))] = I(9),
227 [B(NI_CtrSource(1))] = I(4),
228 [B(NI_CtrGate(0))] = I(10),
229 [B(NI_CtrGate(1))] = I(5),
230 [B(NI_CtrInternalOutput(0))] = I(13),
231 [B(NI_CtrInternalOutput(1))] = I(14),
232 [B(PXI_Star)] = I(26),
233 [B(NI_AI_SampleClock)] = I(8),
234 [B(NI_AI_StartTrigger)] = I(1),
235 [B(NI_AI_ReferenceTrigger)] = I(2),
236 [B(NI_AI_ConvertClock)] = I(3),
237 [B(NI_AI_ExternalMUXClock)] = I(12),
238 [B(NI_AO_SampleClock)] = I(6),
239 [B(NI_AO_StartTrigger)] = I(7),
240 [B(NI_DI_SampleClock)] = I(29),
241 [B(NI_DO_SampleClock)] = I(30),
242 [B(NI_FrequencyOutput)] = I(15),
243 [B(NI_ChangeDetectionEvent)] = I(28),
244 [B(NI_AnalogComparisonEvent)] = I(17),
245 [B(NI_SCXI_Trig1)] = I(27),
246 [B(NI_ExternalStrobe)] = I(11),
247 [B(NI_PFI_DO)] = I(16),
248 },
249 [B(NI_PFI(6))] = {
250 [B(TRIGGER_LINE(0))] = I(18),
251 [B(TRIGGER_LINE(1))] = I(19),
252 [B(TRIGGER_LINE(2))] = I(20),
253 [B(TRIGGER_LINE(3))] = I(21),
254 [B(TRIGGER_LINE(4))] = I(22),
255 [B(TRIGGER_LINE(5))] = I(23),
256 [B(TRIGGER_LINE(6))] = I(24),
257 [B(TRIGGER_LINE(7))] = I(25),
258 [B(NI_CtrSource(0))] = I(9),
259 [B(NI_CtrSource(1))] = I(4),
260 [B(NI_CtrGate(0))] = I(10),
261 [B(NI_CtrGate(1))] = I(5),
262 [B(NI_CtrInternalOutput(0))] = I(13),
263 [B(NI_CtrInternalOutput(1))] = I(14),
264 [B(PXI_Star)] = I(26),
265 [B(NI_AI_SampleClock)] = I(8),
266 [B(NI_AI_StartTrigger)] = I(1),
267 [B(NI_AI_ReferenceTrigger)] = I(2),
268 [B(NI_AI_ConvertClock)] = I(3),
269 [B(NI_AI_ExternalMUXClock)] = I(12),
270 [B(NI_AO_SampleClock)] = I(6),
271 [B(NI_AO_StartTrigger)] = I(7),
272 [B(NI_DI_SampleClock)] = I(29),
273 [B(NI_DO_SampleClock)] = I(30),
274 [B(NI_FrequencyOutput)] = I(15),
275 [B(NI_ChangeDetectionEvent)] = I(28),
276 [B(NI_AnalogComparisonEvent)] = I(17),
277 [B(NI_SCXI_Trig1)] = I(27),
278 [B(NI_ExternalStrobe)] = I(11),
279 [B(NI_PFI_DO)] = I(16),
280 },
281 [B(NI_PFI(7))] = {
282 [B(TRIGGER_LINE(0))] = I(18),
283 [B(TRIGGER_LINE(1))] = I(19),
284 [B(TRIGGER_LINE(2))] = I(20),
285 [B(TRIGGER_LINE(3))] = I(21),
286 [B(TRIGGER_LINE(4))] = I(22),
287 [B(TRIGGER_LINE(5))] = I(23),
288 [B(TRIGGER_LINE(6))] = I(24),
289 [B(TRIGGER_LINE(7))] = I(25),
290 [B(NI_CtrSource(0))] = I(9),
291 [B(NI_CtrSource(1))] = I(4),
292 [B(NI_CtrGate(0))] = I(10),
293 [B(NI_CtrGate(1))] = I(5),
294 [B(NI_CtrInternalOutput(0))] = I(13),
295 [B(NI_CtrInternalOutput(1))] = I(14),
296 [B(PXI_Star)] = I(26),
297 [B(NI_AI_SampleClock)] = I(8),
298 [B(NI_AI_StartTrigger)] = I(1),
299 [B(NI_AI_ReferenceTrigger)] = I(2),
300 [B(NI_AI_ConvertClock)] = I(3),
301 [B(NI_AI_ExternalMUXClock)] = I(12),
302 [B(NI_AO_SampleClock)] = I(6),
303 [B(NI_AO_StartTrigger)] = I(7),
304 [B(NI_DI_SampleClock)] = I(29),
305 [B(NI_DO_SampleClock)] = I(30),
306 [B(NI_FrequencyOutput)] = I(15),
307 [B(NI_ChangeDetectionEvent)] = I(28),
308 [B(NI_AnalogComparisonEvent)] = I(17),
309 [B(NI_SCXI_Trig1)] = I(27),
310 [B(NI_ExternalStrobe)] = I(11),
311 [B(NI_PFI_DO)] = I(16),
312 },
313 [B(NI_PFI(8))] = {
314 [B(TRIGGER_LINE(0))] = I(18),
315 [B(TRIGGER_LINE(1))] = I(19),
316 [B(TRIGGER_LINE(2))] = I(20),
317 [B(TRIGGER_LINE(3))] = I(21),
318 [B(TRIGGER_LINE(4))] = I(22),
319 [B(TRIGGER_LINE(5))] = I(23),
320 [B(TRIGGER_LINE(6))] = I(24),
321 [B(TRIGGER_LINE(7))] = I(25),
322 [B(NI_CtrSource(0))] = I(9),
323 [B(NI_CtrSource(1))] = I(4),
324 [B(NI_CtrGate(0))] = I(10),
325 [B(NI_CtrGate(1))] = I(5),
326 [B(NI_CtrInternalOutput(0))] = I(13),
327 [B(NI_CtrInternalOutput(1))] = I(14),
328 [B(PXI_Star)] = I(26),
329 [B(NI_AI_SampleClock)] = I(8),
330 [B(NI_AI_StartTrigger)] = I(1),
331 [B(NI_AI_ReferenceTrigger)] = I(2),
332 [B(NI_AI_ConvertClock)] = I(3),
333 [B(NI_AI_ExternalMUXClock)] = I(12),
334 [B(NI_AO_SampleClock)] = I(6),
335 [B(NI_AO_StartTrigger)] = I(7),
336 [B(NI_DI_SampleClock)] = I(29),
337 [B(NI_DO_SampleClock)] = I(30),
338 [B(NI_FrequencyOutput)] = I(15),
339 [B(NI_ChangeDetectionEvent)] = I(28),
340 [B(NI_AnalogComparisonEvent)] = I(17),
341 [B(NI_SCXI_Trig1)] = I(27),
342 [B(NI_ExternalStrobe)] = I(11),
343 [B(NI_PFI_DO)] = I(16),
344 },
345 [B(NI_PFI(9))] = {
346 [B(TRIGGER_LINE(0))] = I(18),
347 [B(TRIGGER_LINE(1))] = I(19),
348 [B(TRIGGER_LINE(2))] = I(20),
349 [B(TRIGGER_LINE(3))] = I(21),
350 [B(TRIGGER_LINE(4))] = I(22),
351 [B(TRIGGER_LINE(5))] = I(23),
352 [B(TRIGGER_LINE(6))] = I(24),
353 [B(TRIGGER_LINE(7))] = I(25),
354 [B(NI_CtrSource(0))] = I(9),
355 [B(NI_CtrSource(1))] = I(4),
356 [B(NI_CtrGate(0))] = I(10),
357 [B(NI_CtrGate(1))] = I(5),
358 [B(NI_CtrInternalOutput(0))] = I(13),
359 [B(NI_CtrInternalOutput(1))] = I(14),
360 [B(PXI_Star)] = I(26),
361 [B(NI_AI_SampleClock)] = I(8),
362 [B(NI_AI_StartTrigger)] = I(1),
363 [B(NI_AI_ReferenceTrigger)] = I(2),
364 [B(NI_AI_ConvertClock)] = I(3),
365 [B(NI_AI_ExternalMUXClock)] = I(12),
366 [B(NI_AO_SampleClock)] = I(6),
367 [B(NI_AO_StartTrigger)] = I(7),
368 [B(NI_DI_SampleClock)] = I(29),
369 [B(NI_DO_SampleClock)] = I(30),
370 [B(NI_FrequencyOutput)] = I(15),
371 [B(NI_ChangeDetectionEvent)] = I(28),
372 [B(NI_AnalogComparisonEvent)] = I(17),
373 [B(NI_SCXI_Trig1)] = I(27),
374 [B(NI_ExternalStrobe)] = I(11),
375 [B(NI_PFI_DO)] = I(16),
376 },
377 [B(NI_PFI(10))] = {
378 [B(TRIGGER_LINE(0))] = I(18),
379 [B(TRIGGER_LINE(1))] = I(19),
380 [B(TRIGGER_LINE(2))] = I(20),
381 [B(TRIGGER_LINE(3))] = I(21),
382 [B(TRIGGER_LINE(4))] = I(22),
383 [B(TRIGGER_LINE(5))] = I(23),
384 [B(TRIGGER_LINE(6))] = I(24),
385 [B(TRIGGER_LINE(7))] = I(25),
386 [B(NI_CtrSource(0))] = I(9),
387 [B(NI_CtrSource(1))] = I(4),
388 [B(NI_CtrGate(0))] = I(10),
389 [B(NI_CtrGate(1))] = I(5),
390 [B(NI_CtrInternalOutput(0))] = I(13),
391 [B(NI_CtrInternalOutput(1))] = I(14),
392 [B(PXI_Star)] = I(26),
393 [B(NI_AI_SampleClock)] = I(8),
394 [B(NI_AI_StartTrigger)] = I(1),
395 [B(NI_AI_ReferenceTrigger)] = I(2),
396 [B(NI_AI_ConvertClock)] = I(3),
397 [B(NI_AI_ExternalMUXClock)] = I(12),
398 [B(NI_AO_SampleClock)] = I(6),
399 [B(NI_AO_StartTrigger)] = I(7),
400 [B(NI_DI_SampleClock)] = I(29),
401 [B(NI_DO_SampleClock)] = I(30),
402 [B(NI_FrequencyOutput)] = I(15),
403 [B(NI_ChangeDetectionEvent)] = I(28),
404 [B(NI_AnalogComparisonEvent)] = I(17),
405 [B(NI_SCXI_Trig1)] = I(27),
406 [B(NI_ExternalStrobe)] = I(11),
407 [B(NI_PFI_DO)] = I(16),
408 },
409 [B(NI_PFI(11))] = {
410 [B(TRIGGER_LINE(0))] = I(18),
411 [B(TRIGGER_LINE(1))] = I(19),
412 [B(TRIGGER_LINE(2))] = I(20),
413 [B(TRIGGER_LINE(3))] = I(21),
414 [B(TRIGGER_LINE(4))] = I(22),
415 [B(TRIGGER_LINE(5))] = I(23),
416 [B(TRIGGER_LINE(6))] = I(24),
417 [B(TRIGGER_LINE(7))] = I(25),
418 [B(NI_CtrSource(0))] = I(9),
419 [B(NI_CtrSource(1))] = I(4),
420 [B(NI_CtrGate(0))] = I(10),
421 [B(NI_CtrGate(1))] = I(5),
422 [B(NI_CtrInternalOutput(0))] = I(13),
423 [B(NI_CtrInternalOutput(1))] = I(14),
424 [B(PXI_Star)] = I(26),
425 [B(NI_AI_SampleClock)] = I(8),
426 [B(NI_AI_StartTrigger)] = I(1),
427 [B(NI_AI_ReferenceTrigger)] = I(2),
428 [B(NI_AI_ConvertClock)] = I(3),
429 [B(NI_AI_ExternalMUXClock)] = I(12),
430 [B(NI_AO_SampleClock)] = I(6),
431 [B(NI_AO_StartTrigger)] = I(7),
432 [B(NI_DI_SampleClock)] = I(29),
433 [B(NI_DO_SampleClock)] = I(30),
434 [B(NI_FrequencyOutput)] = I(15),
435 [B(NI_ChangeDetectionEvent)] = I(28),
436 [B(NI_AnalogComparisonEvent)] = I(17),
437 [B(NI_SCXI_Trig1)] = I(27),
438 [B(NI_ExternalStrobe)] = I(11),
439 [B(NI_PFI_DO)] = I(16),
440 },
441 [B(NI_PFI(12))] = {
442 [B(TRIGGER_LINE(0))] = I(18),
443 [B(TRIGGER_LINE(1))] = I(19),
444 [B(TRIGGER_LINE(2))] = I(20),
445 [B(TRIGGER_LINE(3))] = I(21),
446 [B(TRIGGER_LINE(4))] = I(22),
447 [B(TRIGGER_LINE(5))] = I(23),
448 [B(TRIGGER_LINE(6))] = I(24),
449 [B(TRIGGER_LINE(7))] = I(25),
450 [B(NI_CtrSource(0))] = I(9),
451 [B(NI_CtrSource(1))] = I(4),
452 [B(NI_CtrGate(0))] = I(10),
453 [B(NI_CtrGate(1))] = I(5),
454 [B(NI_CtrInternalOutput(0))] = I(13),
455 [B(NI_CtrInternalOutput(1))] = I(14),
456 [B(PXI_Star)] = I(26),
457 [B(NI_AI_SampleClock)] = I(8),
458 [B(NI_AI_StartTrigger)] = I(1),
459 [B(NI_AI_ReferenceTrigger)] = I(2),
460 [B(NI_AI_ConvertClock)] = I(3),
461 [B(NI_AI_ExternalMUXClock)] = I(12),
462 [B(NI_AO_SampleClock)] = I(6),
463 [B(NI_AO_StartTrigger)] = I(7),
464 [B(NI_DI_SampleClock)] = I(29),
465 [B(NI_DO_SampleClock)] = I(30),
466 [B(NI_FrequencyOutput)] = I(15),
467 [B(NI_ChangeDetectionEvent)] = I(28),
468 [B(NI_AnalogComparisonEvent)] = I(17),
469 [B(NI_SCXI_Trig1)] = I(27),
470 [B(NI_ExternalStrobe)] = I(11),
471 [B(NI_PFI_DO)] = I(16),
472 },
473 [B(NI_PFI(13))] = {
474 [B(TRIGGER_LINE(0))] = I(18),
475 [B(TRIGGER_LINE(1))] = I(19),
476 [B(TRIGGER_LINE(2))] = I(20),
477 [B(TRIGGER_LINE(3))] = I(21),
478 [B(TRIGGER_LINE(4))] = I(22),
479 [B(TRIGGER_LINE(5))] = I(23),
480 [B(TRIGGER_LINE(6))] = I(24),
481 [B(TRIGGER_LINE(7))] = I(25),
482 [B(NI_CtrSource(0))] = I(9),
483 [B(NI_CtrSource(1))] = I(4),
484 [B(NI_CtrGate(0))] = I(10),
485 [B(NI_CtrGate(1))] = I(5),
486 [B(NI_CtrInternalOutput(0))] = I(13),
487 [B(NI_CtrInternalOutput(1))] = I(14),
488 [B(PXI_Star)] = I(26),
489 [B(NI_AI_SampleClock)] = I(8),
490 [B(NI_AI_StartTrigger)] = I(1),
491 [B(NI_AI_ReferenceTrigger)] = I(2),
492 [B(NI_AI_ConvertClock)] = I(3),
493 [B(NI_AI_ExternalMUXClock)] = I(12),
494 [B(NI_AO_SampleClock)] = I(6),
495 [B(NI_AO_StartTrigger)] = I(7),
496 [B(NI_DI_SampleClock)] = I(29),
497 [B(NI_DO_SampleClock)] = I(30),
498 [B(NI_FrequencyOutput)] = I(15),
499 [B(NI_ChangeDetectionEvent)] = I(28),
500 [B(NI_AnalogComparisonEvent)] = I(17),
501 [B(NI_SCXI_Trig1)] = I(27),
502 [B(NI_ExternalStrobe)] = I(11),
503 [B(NI_PFI_DO)] = I(16),
504 },
505 [B(NI_PFI(14))] = {
506 [B(TRIGGER_LINE(0))] = I(18),
507 [B(TRIGGER_LINE(1))] = I(19),
508 [B(TRIGGER_LINE(2))] = I(20),
509 [B(TRIGGER_LINE(3))] = I(21),
510 [B(TRIGGER_LINE(4))] = I(22),
511 [B(TRIGGER_LINE(5))] = I(23),
512 [B(TRIGGER_LINE(6))] = I(24),
513 [B(TRIGGER_LINE(7))] = I(25),
514 [B(NI_CtrSource(0))] = I(9),
515 [B(NI_CtrSource(1))] = I(4),
516 [B(NI_CtrGate(0))] = I(10),
517 [B(NI_CtrGate(1))] = I(5),
518 [B(NI_CtrInternalOutput(0))] = I(13),
519 [B(NI_CtrInternalOutput(1))] = I(14),
520 [B(PXI_Star)] = I(26),
521 [B(NI_AI_SampleClock)] = I(8),
522 [B(NI_AI_StartTrigger)] = I(1),
523 [B(NI_AI_ReferenceTrigger)] = I(2),
524 [B(NI_AI_ConvertClock)] = I(3),
525 [B(NI_AI_ExternalMUXClock)] = I(12),
526 [B(NI_AO_SampleClock)] = I(6),
527 [B(NI_AO_StartTrigger)] = I(7),
528 [B(NI_DI_SampleClock)] = I(29),
529 [B(NI_DO_SampleClock)] = I(30),
530 [B(NI_FrequencyOutput)] = I(15),
531 [B(NI_ChangeDetectionEvent)] = I(28),
532 [B(NI_AnalogComparisonEvent)] = I(17),
533 [B(NI_SCXI_Trig1)] = I(27),
534 [B(NI_ExternalStrobe)] = I(11),
535 [B(NI_PFI_DO)] = I(16),
536 },
537 [B(NI_PFI(15))] = {
538 [B(TRIGGER_LINE(0))] = I(18),
539 [B(TRIGGER_LINE(1))] = I(19),
540 [B(TRIGGER_LINE(2))] = I(20),
541 [B(TRIGGER_LINE(3))] = I(21),
542 [B(TRIGGER_LINE(4))] = I(22),
543 [B(TRIGGER_LINE(5))] = I(23),
544 [B(TRIGGER_LINE(6))] = I(24),
545 [B(TRIGGER_LINE(7))] = I(25),
546 [B(NI_CtrSource(0))] = I(9),
547 [B(NI_CtrSource(1))] = I(4),
548 [B(NI_CtrGate(0))] = I(10),
549 [B(NI_CtrGate(1))] = I(5),
550 [B(NI_CtrInternalOutput(0))] = I(13),
551 [B(NI_CtrInternalOutput(1))] = I(14),
552 [B(PXI_Star)] = I(26),
553 [B(NI_AI_SampleClock)] = I(8),
554 [B(NI_AI_StartTrigger)] = I(1),
555 [B(NI_AI_ReferenceTrigger)] = I(2),
556 [B(NI_AI_ConvertClock)] = I(3),
557 [B(NI_AI_ExternalMUXClock)] = I(12),
558 [B(NI_AO_SampleClock)] = I(6),
559 [B(NI_AO_StartTrigger)] = I(7),
560 [B(NI_DI_SampleClock)] = I(29),
561 [B(NI_DO_SampleClock)] = I(30),
562 [B(NI_FrequencyOutput)] = I(15),
563 [B(NI_ChangeDetectionEvent)] = I(28),
564 [B(NI_AnalogComparisonEvent)] = I(17),
565 [B(NI_SCXI_Trig1)] = I(27),
566 [B(NI_ExternalStrobe)] = I(11),
567 [B(NI_PFI_DO)] = I(16),
568 },
569 [B(TRIGGER_LINE(0))] = {
570 [B(NI_RTSI_BRD(0))] = I(8),
571 [B(NI_RTSI_BRD(1))] = I(9),
572 [B(NI_RTSI_BRD(2))] = I(10),
573 [B(NI_RTSI_BRD(3))] = I(11),
574 [B(NI_CtrSource(0))] = I(5),
575 [B(NI_CtrGate(0))] = I(6),
576 [B(NI_AI_StartTrigger)] = I(0),
577 [B(NI_AI_ReferenceTrigger)] = I(1),
578 [B(NI_AI_ConvertClock)] = I(2),
579 [B(NI_AO_SampleClock)] = I(3),
580 [B(NI_AO_StartTrigger)] = I(4),
581 /*
582 * for (*->TRIGGER_LINE(*)) MUX, a value of 12 should be
583 * RTSI_OSC according to MHDDK mseries source. There
584 * are hints in comedi that show that this is actually a
585 * 20MHz source for 628x cards(?)
586 */
587 [B(NI_10MHzRefClock)] = I(12),
588 [B(NI_RGOUT0)] = I(7),
589 },
590 [B(TRIGGER_LINE(1))] = {
591 [B(NI_RTSI_BRD(0))] = I(8),
592 [B(NI_RTSI_BRD(1))] = I(9),
593 [B(NI_RTSI_BRD(2))] = I(10),
594 [B(NI_RTSI_BRD(3))] = I(11),
595 [B(NI_CtrSource(0))] = I(5),
596 [B(NI_CtrGate(0))] = I(6),
597 [B(NI_AI_StartTrigger)] = I(0),
598 [B(NI_AI_ReferenceTrigger)] = I(1),
599 [B(NI_AI_ConvertClock)] = I(2),
600 [B(NI_AO_SampleClock)] = I(3),
601 [B(NI_AO_StartTrigger)] = I(4),
602 /*
603 * for (*->TRIGGER_LINE(*)) MUX, a value of 12 should be
604 * RTSI_OSC according to MHDDK mseries source. There
605 * are hints in comedi that show that this is actually a
606 * 20MHz source for 628x cards(?)
607 */
608 [B(NI_10MHzRefClock)] = I(12),
609 [B(NI_RGOUT0)] = I(7),
610 },
611 [B(TRIGGER_LINE(2))] = {
612 [B(NI_RTSI_BRD(0))] = I(8),
613 [B(NI_RTSI_BRD(1))] = I(9),
614 [B(NI_RTSI_BRD(2))] = I(10),
615 [B(NI_RTSI_BRD(3))] = I(11),
616 [B(NI_CtrSource(0))] = I(5),
617 [B(NI_CtrGate(0))] = I(6),
618 [B(NI_AI_StartTrigger)] = I(0),
619 [B(NI_AI_ReferenceTrigger)] = I(1),
620 [B(NI_AI_ConvertClock)] = I(2),
621 [B(NI_AO_SampleClock)] = I(3),
622 [B(NI_AO_StartTrigger)] = I(4),
623 /*
624 * for (*->TRIGGER_LINE(*)) MUX, a value of 12 should be
625 * RTSI_OSC according to MHDDK mseries source. There
626 * are hints in comedi that show that this is actually a
627 * 20MHz source for 628x cards(?)
628 */
629 [B(NI_10MHzRefClock)] = I(12),
630 [B(NI_RGOUT0)] = I(7),
631 },
632 [B(TRIGGER_LINE(3))] = {
633 [B(NI_RTSI_BRD(0))] = I(8),
634 [B(NI_RTSI_BRD(1))] = I(9),
635 [B(NI_RTSI_BRD(2))] = I(10),
636 [B(NI_RTSI_BRD(3))] = I(11),
637 [B(NI_CtrSource(0))] = I(5),
638 [B(NI_CtrGate(0))] = I(6),
639 [B(NI_AI_StartTrigger)] = I(0),
640 [B(NI_AI_ReferenceTrigger)] = I(1),
641 [B(NI_AI_ConvertClock)] = I(2),
642 [B(NI_AO_SampleClock)] = I(3),
643 [B(NI_AO_StartTrigger)] = I(4),
644 /*
645 * for (*->TRIGGER_LINE(*)) MUX, a value of 12 should be
646 * RTSI_OSC according to MHDDK mseries source. There
647 * are hints in comedi that show that this is actually a
648 * 20MHz source for 628x cards(?)
649 */
650 [B(NI_10MHzRefClock)] = I(12),
651 [B(NI_RGOUT0)] = I(7),
652 },
653 [B(TRIGGER_LINE(4))] = {
654 [B(NI_RTSI_BRD(0))] = I(8),
655 [B(NI_RTSI_BRD(1))] = I(9),
656 [B(NI_RTSI_BRD(2))] = I(10),
657 [B(NI_RTSI_BRD(3))] = I(11),
658 [B(NI_CtrSource(0))] = I(5),
659 [B(NI_CtrGate(0))] = I(6),
660 [B(NI_AI_StartTrigger)] = I(0),
661 [B(NI_AI_ReferenceTrigger)] = I(1),
662 [B(NI_AI_ConvertClock)] = I(2),
663 [B(NI_AO_SampleClock)] = I(3),
664 [B(NI_AO_StartTrigger)] = I(4),
665 /*
666 * for (*->TRIGGER_LINE(*)) MUX, a value of 12 should be
667 * RTSI_OSC according to MHDDK mseries source. There
668 * are hints in comedi that show that this is actually a
669 * 20MHz source for 628x cards(?)
670 */
671 [B(NI_10MHzRefClock)] = I(12),
672 [B(NI_RGOUT0)] = I(7),
673 },
674 [B(TRIGGER_LINE(5))] = {
675 [B(NI_RTSI_BRD(0))] = I(8),
676 [B(NI_RTSI_BRD(1))] = I(9),
677 [B(NI_RTSI_BRD(2))] = I(10),
678 [B(NI_RTSI_BRD(3))] = I(11),
679 [B(NI_CtrSource(0))] = I(5),
680 [B(NI_CtrGate(0))] = I(6),
681 [B(NI_AI_StartTrigger)] = I(0),
682 [B(NI_AI_ReferenceTrigger)] = I(1),
683 [B(NI_AI_ConvertClock)] = I(2),
684 [B(NI_AO_SampleClock)] = I(3),
685 [B(NI_AO_StartTrigger)] = I(4),
686 /*
687 * for (*->TRIGGER_LINE(*)) MUX, a value of 12 should be
688 * RTSI_OSC according to MHDDK mseries source. There
689 * are hints in comedi that show that this is actually a
690 * 20MHz source for 628x cards(?)
691 */
692 [B(NI_10MHzRefClock)] = I(12),
693 [B(NI_RGOUT0)] = I(7),
694 },
695 [B(TRIGGER_LINE(6))] = {
696 [B(NI_RTSI_BRD(0))] = I(8),
697 [B(NI_RTSI_BRD(1))] = I(9),
698 [B(NI_RTSI_BRD(2))] = I(10),
699 [B(NI_RTSI_BRD(3))] = I(11),
700 [B(NI_CtrSource(0))] = I(5),
701 [B(NI_CtrGate(0))] = I(6),
702 [B(NI_AI_StartTrigger)] = I(0),
703 [B(NI_AI_ReferenceTrigger)] = I(1),
704 [B(NI_AI_ConvertClock)] = I(2),
705 [B(NI_AO_SampleClock)] = I(3),
706 [B(NI_AO_StartTrigger)] = I(4),
707 /*
708 * for (*->TRIGGER_LINE(*)) MUX, a value of 12 should be
709 * RTSI_OSC according to MHDDK mseries source. There
710 * are hints in comedi that show that this is actually a
711 * 20MHz source for 628x cards(?)
712 */
713 [B(NI_10MHzRefClock)] = I(12),
714 [B(NI_RGOUT0)] = I(7),
715 },
716 [B(TRIGGER_LINE(7))] = {
717 [B(NI_RTSI_BRD(0))] = I(8),
718 [B(NI_RTSI_BRD(1))] = I(9),
719 [B(NI_RTSI_BRD(2))] = I(10),
720 [B(NI_RTSI_BRD(3))] = I(11),
721 [B(NI_CtrSource(0))] = I(5),
722 [B(NI_CtrGate(0))] = I(6),
723 [B(NI_AI_StartTrigger)] = I(0),
724 [B(NI_AI_ReferenceTrigger)] = I(1),
725 [B(NI_AI_ConvertClock)] = I(2),
726 [B(NI_AO_SampleClock)] = I(3),
727 [B(NI_AO_StartTrigger)] = I(4),
728 /*
729 * for (*->TRIGGER_LINE(*)) MUX, a value of 12 should be
730 * RTSI_OSC according to MHDDK mseries source. There
731 * are hints in comedi that show that this is actually a
732 * 20MHz source for 628x cards(?)
733 */
734 [B(NI_10MHzRefClock)] = I(12),
735 [B(NI_RGOUT0)] = I(7),
736 },
737 [B(NI_RTSI_BRD(0))] = {
738 [B(NI_PFI(0))] = I(0),
739 [B(NI_PFI(1))] = I(1),
740 [B(NI_PFI(2))] = I(2),
741 [B(NI_PFI(3))] = I(3),
742 [B(NI_PFI(4))] = I(4),
743 [B(NI_PFI(5))] = I(5),
744 [B(NI_CtrSource(1))] = I(11),
745 [B(NI_CtrGate(1))] = I(10),
746 [B(NI_CtrZ(0))] = I(13),
747 [B(NI_CtrZ(1))] = I(12),
748 [B(NI_CtrOut(1))] = I(9),
749 [B(NI_AI_SampleClock)] = I(15),
750 [B(NI_AI_PauseTrigger)] = I(7),
751 [B(NI_AO_PauseTrigger)] = I(6),
752 [B(NI_FrequencyOutput)] = I(8),
753 [B(NI_AnalogComparisonEvent)] = I(14),
754 },
755 [B(NI_RTSI_BRD(1))] = {
756 [B(NI_PFI(0))] = I(0),
757 [B(NI_PFI(1))] = I(1),
758 [B(NI_PFI(2))] = I(2),
759 [B(NI_PFI(3))] = I(3),
760 [B(NI_PFI(4))] = I(4),
761 [B(NI_PFI(5))] = I(5),
762 [B(NI_CtrSource(1))] = I(11),
763 [B(NI_CtrGate(1))] = I(10),
764 [B(NI_CtrZ(0))] = I(13),
765 [B(NI_CtrZ(1))] = I(12),
766 [B(NI_CtrOut(1))] = I(9),
767 [B(NI_AI_SampleClock)] = I(15),
768 [B(NI_AI_PauseTrigger)] = I(7),
769 [B(NI_AO_PauseTrigger)] = I(6),
770 [B(NI_FrequencyOutput)] = I(8),
771 [B(NI_AnalogComparisonEvent)] = I(14),
772 },
773 [B(NI_RTSI_BRD(2))] = {
774 [B(NI_PFI(0))] = I(0),
775 [B(NI_PFI(1))] = I(1),
776 [B(NI_PFI(2))] = I(2),
777 [B(NI_PFI(3))] = I(3),
778 [B(NI_PFI(4))] = I(4),
779 [B(NI_PFI(5))] = I(5),
780 [B(NI_CtrSource(1))] = I(11),
781 [B(NI_CtrGate(1))] = I(10),
782 [B(NI_CtrZ(0))] = I(13),
783 [B(NI_CtrZ(1))] = I(12),
784 [B(NI_CtrOut(1))] = I(9),
785 [B(NI_AI_SampleClock)] = I(15),
786 [B(NI_AI_PauseTrigger)] = I(7),
787 [B(NI_AO_PauseTrigger)] = I(6),
788 [B(NI_FrequencyOutput)] = I(8),
789 [B(NI_AnalogComparisonEvent)] = I(14),
790 },
791 [B(NI_RTSI_BRD(3))] = {
792 [B(NI_PFI(0))] = I(0),
793 [B(NI_PFI(1))] = I(1),
794 [B(NI_PFI(2))] = I(2),
795 [B(NI_PFI(3))] = I(3),
796 [B(NI_PFI(4))] = I(4),
797 [B(NI_PFI(5))] = I(5),
798 [B(NI_CtrSource(1))] = I(11),
799 [B(NI_CtrGate(1))] = I(10),
800 [B(NI_CtrZ(0))] = I(13),
801 [B(NI_CtrZ(1))] = I(12),
802 [B(NI_CtrOut(1))] = I(9),
803 [B(NI_AI_SampleClock)] = I(15),
804 [B(NI_AI_PauseTrigger)] = I(7),
805 [B(NI_AO_PauseTrigger)] = I(6),
806 [B(NI_FrequencyOutput)] = I(8),
807 [B(NI_AnalogComparisonEvent)] = I(14),
808 },
809 [B(NI_CtrSource(0))] = {
810 /* These are not currently implemented in ni modules */
811 [B(NI_PFI(0))] = U(1),
812 [B(NI_PFI(1))] = U(2),
813 [B(NI_PFI(2))] = U(3),
814 [B(NI_PFI(3))] = U(4),
815 [B(NI_PFI(4))] = U(5),
816 [B(NI_PFI(5))] = U(6),
817 [B(NI_PFI(6))] = U(7),
818 [B(NI_PFI(7))] = U(8),
819 [B(NI_PFI(8))] = U(9),
820 [B(NI_PFI(9))] = U(10),
821 [B(NI_PFI(10))] = U(21),
822 [B(NI_PFI(11))] = U(22),
823 [B(NI_PFI(12))] = U(23),
824 [B(NI_PFI(13))] = U(24),
825 [B(NI_PFI(14))] = U(25),
826 [B(NI_PFI(15))] = U(26),
827 [B(TRIGGER_LINE(0))] = U(11),
828 [B(TRIGGER_LINE(1))] = U(12),
829 [B(TRIGGER_LINE(2))] = U(13),
830 [B(TRIGGER_LINE(3))] = U(14),
831 [B(TRIGGER_LINE(4))] = U(15),
832 [B(TRIGGER_LINE(5))] = U(16),
833 [B(TRIGGER_LINE(6))] = U(17),
834 [B(TRIGGER_LINE(7))] = U(27),
835 [B(NI_CtrGate(1))] = U(Gi_SRC(20, 0)),
836 [B(NI_CtrInternalOutput(1))] = U(19),
837 [B(PXI_Star)] = U(Gi_SRC(20, 1)),
838 [B(PXI_Clk10)] = U(29),
839 [B(NI_20MHzTimebase)] = U(0),
840 [B(NI_80MHzTimebase)] = U(Gi_SRC(30, 0)),
841 [B(NI_100kHzTimebase)] = U(18),
842 [B(NI_AnalogComparisonEvent)] = U(Gi_SRC(30, 1)),
843 [B(NI_LogicLow)] = U(31),
844 },
845 [B(NI_CtrSource(1))] = {
846 /* These are not currently implemented in ni modules */
847 [B(NI_PFI(0))] = U(1),
848 [B(NI_PFI(1))] = U(2),
849 [B(NI_PFI(2))] = U(3),
850 [B(NI_PFI(3))] = U(4),
851 [B(NI_PFI(4))] = U(5),
852 [B(NI_PFI(5))] = U(6),
853 [B(NI_PFI(6))] = U(7),
854 [B(NI_PFI(7))] = U(8),
855 [B(NI_PFI(8))] = U(9),
856 [B(NI_PFI(9))] = U(10),
857 [B(NI_PFI(10))] = U(21),
858 [B(NI_PFI(11))] = U(22),
859 [B(NI_PFI(12))] = U(23),
860 [B(NI_PFI(13))] = U(24),
861 [B(NI_PFI(14))] = U(25),
862 [B(NI_PFI(15))] = U(26),
863 [B(TRIGGER_LINE(0))] = U(11),
864 [B(TRIGGER_LINE(1))] = U(12),
865 [B(TRIGGER_LINE(2))] = U(13),
866 [B(TRIGGER_LINE(3))] = U(14),
867 [B(TRIGGER_LINE(4))] = U(15),
868 [B(TRIGGER_LINE(5))] = U(16),
869 [B(TRIGGER_LINE(6))] = U(17),
870 [B(TRIGGER_LINE(7))] = U(27),
871 [B(NI_CtrGate(0))] = U(Gi_SRC(20, 0)),
872 [B(NI_CtrInternalOutput(0))] = U(19),
873 [B(PXI_Star)] = U(Gi_SRC(20, 1)),
874 [B(PXI_Clk10)] = U(29),
875 [B(NI_20MHzTimebase)] = U(0),
876 [B(NI_80MHzTimebase)] = U(Gi_SRC(30, 0)),
877 [B(NI_100kHzTimebase)] = U(18),
878 [B(NI_AnalogComparisonEvent)] = U(Gi_SRC(30, 1)),
879 [B(NI_LogicLow)] = U(31),
880 },
881 [B(NI_CtrGate(0))] = {
882 [B(NI_PFI(0))] = I(1 /* source: mhddk examples */),
883 [B(NI_PFI(1))] = I(2),
884 [B(NI_PFI(2))] = I(3),
885 [B(NI_PFI(3))] = I(4),
886 [B(NI_PFI(4))] = I(5),
887 [B(NI_PFI(5))] = I(6),
888 [B(NI_PFI(6))] = I(7),
889 [B(NI_PFI(7))] = I(8),
890 [B(NI_PFI(8))] = I(9),
891 [B(NI_PFI(9))] = I(10),
892 [B(NI_PFI(10))] = I(21),
893 [B(NI_PFI(11))] = I(22),
894 [B(NI_PFI(12))] = I(23),
895 [B(NI_PFI(13))] = I(24),
896 [B(NI_PFI(14))] = I(25),
897 [B(NI_PFI(15))] = I(26),
898 [B(TRIGGER_LINE(0))] = I(11),
899 [B(TRIGGER_LINE(1))] = I(12),
900 [B(TRIGGER_LINE(2))] = I(13),
901 [B(TRIGGER_LINE(3))] = I(14),
902 [B(TRIGGER_LINE(4))] = I(15),
903 [B(TRIGGER_LINE(5))] = I(16),
904 [B(TRIGGER_LINE(6))] = I(17),
905 [B(TRIGGER_LINE(7))] = I(27),
906 [B(NI_CtrSource(1))] = I(29),
907 /* source for following line: mhddk GP examples */
908 [B(NI_CtrInternalOutput(1))] = I(20),
909 [B(PXI_Star)] = I(19),
910 [B(NI_AI_StartTrigger)] = I(28),
911 [B(NI_AI_ReferenceTrigger)] = I(18),
912 [B(NI_AnalogComparisonEvent)] = I(30),
913 [B(NI_LogicLow)] = I(31),
914 },
915 [B(NI_CtrGate(1))] = {
916 /* source for following line: mhddk examples */
917 [B(NI_PFI(0))] = I(1),
918 [B(NI_PFI(1))] = I(2),
919 [B(NI_PFI(2))] = I(3),
920 [B(NI_PFI(3))] = I(4),
921 [B(NI_PFI(4))] = I(5),
922 [B(NI_PFI(5))] = I(6),
923 [B(NI_PFI(6))] = I(7),
924 [B(NI_PFI(7))] = I(8),
925 [B(NI_PFI(8))] = I(9),
926 [B(NI_PFI(9))] = I(10),
927 [B(NI_PFI(10))] = I(21),
928 [B(NI_PFI(11))] = I(22),
929 [B(NI_PFI(12))] = I(23),
930 [B(NI_PFI(13))] = I(24),
931 [B(NI_PFI(14))] = I(25),
932 [B(NI_PFI(15))] = I(26),
933 [B(TRIGGER_LINE(0))] = I(11),
934 [B(TRIGGER_LINE(1))] = I(12),
935 [B(TRIGGER_LINE(2))] = I(13),
936 [B(TRIGGER_LINE(3))] = I(14),
937 [B(TRIGGER_LINE(4))] = I(15),
938 [B(TRIGGER_LINE(5))] = I(16),
939 [B(TRIGGER_LINE(6))] = I(17),
940 [B(TRIGGER_LINE(7))] = I(27),
941 [B(NI_CtrSource(0))] = I(29),
942 /* source for following line: mhddk GP examples */
943 [B(NI_CtrInternalOutput(0))] = I(20),
944 [B(PXI_Star)] = I(19),
945 [B(NI_AI_StartTrigger)] = I(28),
946 [B(NI_AI_ReferenceTrigger)] = I(18),
947 [B(NI_AnalogComparisonEvent)] = I(30),
948 [B(NI_LogicLow)] = I(31),
949 },
950 [B(NI_CtrAux(0))] = {
951 /* these are just a guess; see GATE SELECT NOTE */
952 [B(NI_PFI(0))] = I(1),
953 [B(NI_PFI(1))] = I(2),
954 [B(NI_PFI(2))] = I(3),
955 [B(NI_PFI(3))] = I(4),
956 [B(NI_PFI(4))] = I(5),
957 [B(NI_PFI(5))] = I(6),
958 [B(NI_PFI(6))] = I(7),
959 [B(NI_PFI(7))] = I(8),
960 [B(NI_PFI(8))] = I(9),
961 [B(NI_PFI(9))] = I(10),
962 [B(NI_PFI(10))] = I(21),
963 [B(NI_PFI(11))] = I(22),
964 [B(NI_PFI(12))] = I(23),
965 [B(NI_PFI(13))] = I(24),
966 [B(NI_PFI(14))] = I(25),
967 [B(NI_PFI(15))] = I(26),
968 [B(TRIGGER_LINE(0))] = I(11),
969 [B(TRIGGER_LINE(1))] = I(12),
970 [B(TRIGGER_LINE(2))] = I(13),
971 [B(TRIGGER_LINE(3))] = I(14),
972 [B(TRIGGER_LINE(4))] = I(15),
973 [B(TRIGGER_LINE(5))] = I(16),
974 [B(TRIGGER_LINE(6))] = I(17),
975 [B(TRIGGER_LINE(7))] = I(27),
976 [B(NI_CtrSource(1))] = I(29),
977 /* source for following line: mhddk GP examples */
978 [B(NI_CtrInternalOutput(1))] = I(20),
979 [B(PXI_Star)] = I(19),
980 [B(NI_AI_StartTrigger)] = I(28),
981 [B(NI_AI_ReferenceTrigger)] = I(18),
982 [B(NI_AnalogComparisonEvent)] = I(30),
983 [B(NI_LogicLow)] = I(31),
984 },
985 [B(NI_CtrAux(1))] = {
986 /* these are just a guess; see GATE SELECT NOTE */
987 [B(NI_PFI(0))] = I(1),
988 [B(NI_PFI(1))] = I(2),
989 [B(NI_PFI(2))] = I(3),
990 [B(NI_PFI(3))] = I(4),
991 [B(NI_PFI(4))] = I(5),
992 [B(NI_PFI(5))] = I(6),
993 [B(NI_PFI(6))] = I(7),
994 [B(NI_PFI(7))] = I(8),
995 [B(NI_PFI(8))] = I(9),
996 [B(NI_PFI(9))] = I(10),
997 [B(NI_PFI(10))] = I(21),
998 [B(NI_PFI(11))] = I(22),
999 [B(NI_PFI(12))] = I(23),
1000 [B(NI_PFI(13))] = I(24),
1001 [B(NI_PFI(14))] = I(25),
1002 [B(NI_PFI(15))] = I(26),
1003 [B(TRIGGER_LINE(0))] = I(11),
1004 [B(TRIGGER_LINE(1))] = I(12),
1005 [B(TRIGGER_LINE(2))] = I(13),
1006 [B(TRIGGER_LINE(3))] = I(14),
1007 [B(TRIGGER_LINE(4))] = I(15),
1008 [B(TRIGGER_LINE(5))] = I(16),
1009 [B(TRIGGER_LINE(6))] = I(17),
1010 [B(TRIGGER_LINE(7))] = I(27),
1011 [B(NI_CtrSource(0))] = I(29),
1012 /* source for following line: mhddk GP examples */
1013 [B(NI_CtrInternalOutput(0))] = I(20),
1014 [B(PXI_Star)] = I(19),
1015 [B(NI_AI_StartTrigger)] = I(28),
1016 [B(NI_AI_ReferenceTrigger)] = I(18),
1017 [B(NI_AnalogComparisonEvent)] = I(30),
1018 [B(NI_LogicLow)] = I(31),
1019 },
1020 [B(NI_CtrA(0))] = {
1021 /*
1022 * See nimseries/Examples for outputs; inputs a guess
1023 * from device routes shown on NI-MAX.
1024 * see M-Series user manual (371022K-01)
1025 */
1026 [B(NI_PFI(0))] = I(1),
1027 [B(NI_PFI(1))] = I(2),
1028 [B(NI_PFI(2))] = I(3),
1029 [B(NI_PFI(3))] = I(4),
1030 [B(NI_PFI(4))] = I(5),
1031 [B(NI_PFI(5))] = I(6),
1032 [B(NI_PFI(6))] = I(7),
1033 [B(NI_PFI(7))] = I(8),
1034 [B(NI_PFI(8))] = I(9),
1035 [B(NI_PFI(9))] = I(10),
1036 [B(NI_PFI(10))] = I(21),
1037 [B(NI_PFI(11))] = I(22),
1038 [B(NI_PFI(12))] = I(23),
1039 [B(NI_PFI(13))] = I(24),
1040 [B(NI_PFI(14))] = I(25),
1041 [B(NI_PFI(15))] = I(26),
1042 [B(TRIGGER_LINE(0))] = I(11),
1043 [B(TRIGGER_LINE(1))] = I(12),
1044 [B(TRIGGER_LINE(2))] = I(13),
1045 [B(TRIGGER_LINE(3))] = I(14),
1046 [B(TRIGGER_LINE(4))] = I(15),
1047 [B(TRIGGER_LINE(5))] = I(16),
1048 [B(TRIGGER_LINE(6))] = I(17),
1049 [B(TRIGGER_LINE(7))] = I(27),
1050 [B(PXI_Star)] = I(20),
1051 [B(NI_AnalogComparisonEvent)] = I(30),
1052 [B(NI_LogicLow)] = I(31),
1053 },
1054 [B(NI_CtrA(1))] = {
1055 /*
1056 * See nimseries/Examples for outputs; inputs a guess
1057 * from device routes shown on NI-MAX.
1058 * see M-Series user manual (371022K-01)
1059 */
1060 [B(NI_PFI(0))] = I(1),
1061 [B(NI_PFI(1))] = I(2),
1062 [B(NI_PFI(2))] = I(3),
1063 [B(NI_PFI(3))] = I(4),
1064 [B(NI_PFI(4))] = I(5),
1065 [B(NI_PFI(5))] = I(6),
1066 [B(NI_PFI(6))] = I(7),
1067 [B(NI_PFI(7))] = I(8),
1068 [B(NI_PFI(8))] = I(9),
1069 [B(NI_PFI(9))] = I(10),
1070 [B(NI_PFI(10))] = I(21),
1071 [B(NI_PFI(11))] = I(22),
1072 [B(NI_PFI(12))] = I(23),
1073 [B(NI_PFI(13))] = I(24),
1074 [B(NI_PFI(14))] = I(25),
1075 [B(NI_PFI(15))] = I(26),
1076 [B(TRIGGER_LINE(0))] = I(11),
1077 [B(TRIGGER_LINE(1))] = I(12),
1078 [B(TRIGGER_LINE(2))] = I(13),
1079 [B(TRIGGER_LINE(3))] = I(14),
1080 [B(TRIGGER_LINE(4))] = I(15),
1081 [B(TRIGGER_LINE(5))] = I(16),
1082 [B(TRIGGER_LINE(6))] = I(17),
1083 [B(TRIGGER_LINE(7))] = I(27),
1084 [B(PXI_Star)] = I(20),
1085 [B(NI_AnalogComparisonEvent)] = I(30),
1086 [B(NI_LogicLow)] = I(31),
1087 },
1088 [B(NI_CtrB(0))] = {
1089 /*
1090 * See nimseries/Examples for outputs; inputs a guess
1091 * from device routes shown on NI-MAX.
1092 * see M-Series user manual (371022K-01)
1093 */
1094 [B(NI_PFI(0))] = I(1),
1095 [B(NI_PFI(1))] = I(2),
1096 [B(NI_PFI(2))] = I(3),
1097 [B(NI_PFI(3))] = I(4),
1098 [B(NI_PFI(4))] = I(5),
1099 [B(NI_PFI(5))] = I(6),
1100 [B(NI_PFI(6))] = I(7),
1101 [B(NI_PFI(7))] = I(8),
1102 [B(NI_PFI(8))] = I(9),
1103 [B(NI_PFI(9))] = I(10),
1104 [B(NI_PFI(10))] = I(21),
1105 [B(NI_PFI(11))] = I(22),
1106 [B(NI_PFI(12))] = I(23),
1107 [B(NI_PFI(13))] = I(24),
1108 [B(NI_PFI(14))] = I(25),
1109 [B(NI_PFI(15))] = I(26),
1110 [B(TRIGGER_LINE(0))] = I(11),
1111 [B(TRIGGER_LINE(1))] = I(12),
1112 [B(TRIGGER_LINE(2))] = I(13),
1113 [B(TRIGGER_LINE(3))] = I(14),
1114 [B(TRIGGER_LINE(4))] = I(15),
1115 [B(TRIGGER_LINE(5))] = I(16),
1116 [B(TRIGGER_LINE(6))] = I(17),
1117 [B(TRIGGER_LINE(7))] = I(27),
1118 [B(PXI_Star)] = I(20),
1119 [B(NI_AnalogComparisonEvent)] = I(30),
1120 [B(NI_LogicLow)] = I(31),
1121 },
1122 [B(NI_CtrB(1))] = {
1123 /*
1124 * See nimseries/Examples for outputs; inputs a guess
1125 * from device routes shown on NI-MAX.
1126 * see M-Series user manual (371022K-01)
1127 */
1128 [B(NI_PFI(0))] = I(1),
1129 [B(NI_PFI(1))] = I(2),
1130 [B(NI_PFI(2))] = I(3),
1131 [B(NI_PFI(3))] = I(4),
1132 [B(NI_PFI(4))] = I(5),
1133 [B(NI_PFI(5))] = I(6),
1134 [B(NI_PFI(6))] = I(7),
1135 [B(NI_PFI(7))] = I(8),
1136 [B(NI_PFI(8))] = I(9),
1137 [B(NI_PFI(9))] = I(10),
1138 [B(NI_PFI(10))] = I(21),
1139 [B(NI_PFI(11))] = I(22),
1140 [B(NI_PFI(12))] = I(23),
1141 [B(NI_PFI(13))] = I(24),
1142 [B(NI_PFI(14))] = I(25),
1143 [B(NI_PFI(15))] = I(26),
1144 [B(TRIGGER_LINE(0))] = I(11),
1145 [B(TRIGGER_LINE(1))] = I(12),
1146 [B(TRIGGER_LINE(2))] = I(13),
1147 [B(TRIGGER_LINE(3))] = I(14),
1148 [B(TRIGGER_LINE(4))] = I(15),
1149 [B(TRIGGER_LINE(5))] = I(16),
1150 [B(TRIGGER_LINE(6))] = I(17),
1151 [B(TRIGGER_LINE(7))] = I(27),
1152 [B(PXI_Star)] = I(20),
1153 [B(NI_AnalogComparisonEvent)] = I(30),
1154 [B(NI_LogicLow)] = I(31),
1155 },
1156 [B(NI_CtrZ(0))] = {
1157 /*
1158 * See nimseries/Examples for outputs; inputs a guess
1159 * from device routes shown on NI-MAX.
1160 * see M-Series user manual (371022K-01)
1161 */
1162 [B(NI_PFI(0))] = I(1),
1163 [B(NI_PFI(1))] = I(2),
1164 [B(NI_PFI(2))] = I(3),
1165 [B(NI_PFI(3))] = I(4),
1166 [B(NI_PFI(4))] = I(5),
1167 [B(NI_PFI(5))] = I(6),
1168 [B(NI_PFI(6))] = I(7),
1169 [B(NI_PFI(7))] = I(8),
1170 [B(NI_PFI(8))] = I(9),
1171 [B(NI_PFI(9))] = I(10),
1172 [B(NI_PFI(10))] = I(21),
1173 [B(NI_PFI(11))] = I(22),
1174 [B(NI_PFI(12))] = I(23),
1175 [B(NI_PFI(13))] = I(24),
1176 [B(NI_PFI(14))] = I(25),
1177 [B(NI_PFI(15))] = I(26),
1178 [B(TRIGGER_LINE(0))] = I(11),
1179 [B(TRIGGER_LINE(1))] = I(12),
1180 [B(TRIGGER_LINE(2))] = I(13),
1181 [B(TRIGGER_LINE(3))] = I(14),
1182 [B(TRIGGER_LINE(4))] = I(15),
1183 [B(TRIGGER_LINE(5))] = I(16),
1184 [B(TRIGGER_LINE(6))] = I(17),
1185 [B(TRIGGER_LINE(7))] = I(27),
1186 [B(PXI_Star)] = I(20),
1187 [B(NI_AnalogComparisonEvent)] = I(30),
1188 [B(NI_LogicLow)] = I(31),
1189 },
1190 [B(NI_CtrZ(1))] = {
1191 /*
1192 * See nimseries/Examples for outputs; inputs a guess
1193 * from device routes shown on NI-MAX.
1194 * see M-Series user manual (371022K-01)
1195 */
1196 [B(NI_PFI(0))] = I(1),
1197 [B(NI_PFI(1))] = I(2),
1198 [B(NI_PFI(2))] = I(3),
1199 [B(NI_PFI(3))] = I(4),
1200 [B(NI_PFI(4))] = I(5),
1201 [B(NI_PFI(5))] = I(6),
1202 [B(NI_PFI(6))] = I(7),
1203 [B(NI_PFI(7))] = I(8),
1204 [B(NI_PFI(8))] = I(9),
1205 [B(NI_PFI(9))] = I(10),
1206 [B(NI_PFI(10))] = I(21),
1207 [B(NI_PFI(11))] = I(22),
1208 [B(NI_PFI(12))] = I(23),
1209 [B(NI_PFI(13))] = I(24),
1210 [B(NI_PFI(14))] = I(25),
1211 [B(NI_PFI(15))] = I(26),
1212 [B(TRIGGER_LINE(0))] = I(11),
1213 [B(TRIGGER_LINE(1))] = I(12),
1214 [B(TRIGGER_LINE(2))] = I(13),
1215 [B(TRIGGER_LINE(3))] = I(14),
1216 [B(TRIGGER_LINE(4))] = I(15),
1217 [B(TRIGGER_LINE(5))] = I(16),
1218 [B(TRIGGER_LINE(6))] = I(17),
1219 [B(TRIGGER_LINE(7))] = I(27),
1220 [B(PXI_Star)] = I(20),
1221 [B(NI_AnalogComparisonEvent)] = I(30),
1222 [B(NI_LogicLow)] = I(31),
1223 },
1224 [B(NI_CtrArmStartTrigger(0))] = {
1225 /* these are just a guess; see GATE SELECT NOTE */
1226 [B(NI_PFI(0))] = I(1),
1227 [B(NI_PFI(1))] = I(2),
1228 [B(NI_PFI(2))] = I(3),
1229 [B(NI_PFI(3))] = I(4),
1230 [B(NI_PFI(4))] = I(5),
1231 [B(NI_PFI(5))] = I(6),
1232 [B(NI_PFI(6))] = I(7),
1233 [B(NI_PFI(7))] = I(8),
1234 [B(NI_PFI(8))] = I(9),
1235 [B(NI_PFI(9))] = I(10),
1236 [B(NI_PFI(10))] = I(21),
1237 [B(NI_PFI(11))] = I(22),
1238 [B(NI_PFI(12))] = I(23),
1239 [B(NI_PFI(13))] = I(24),
1240 [B(NI_PFI(14))] = I(25),
1241 [B(NI_PFI(15))] = I(26),
1242 [B(TRIGGER_LINE(0))] = I(11),
1243 [B(TRIGGER_LINE(1))] = I(12),
1244 [B(TRIGGER_LINE(2))] = I(13),
1245 [B(TRIGGER_LINE(3))] = I(14),
1246 [B(TRIGGER_LINE(4))] = I(15),
1247 [B(TRIGGER_LINE(5))] = I(16),
1248 [B(TRIGGER_LINE(6))] = I(17),
1249 [B(TRIGGER_LINE(7))] = I(27),
1250 [B(NI_CtrSource(1))] = I(29),
1251 /* source for following line: mhddk GP examples */
1252 [B(NI_CtrInternalOutput(1))] = I(20),
1253 [B(PXI_Star)] = I(19),
1254 [B(NI_AI_StartTrigger)] = I(28),
1255 [B(NI_AI_ReferenceTrigger)] = I(18),
1256 [B(NI_AnalogComparisonEvent)] = I(30),
1257 [B(NI_LogicLow)] = I(31),
1258 },
1259 [B(NI_CtrArmStartTrigger(1))] = {
1260 /* these are just a guess; see GATE SELECT NOTE */
1261 [B(NI_PFI(0))] = I(1),
1262 [B(NI_PFI(1))] = I(2),
1263 [B(NI_PFI(2))] = I(3),
1264 [B(NI_PFI(3))] = I(4),
1265 [B(NI_PFI(4))] = I(5),
1266 [B(NI_PFI(5))] = I(6),
1267 [B(NI_PFI(6))] = I(7),
1268 [B(NI_PFI(7))] = I(8),
1269 [B(NI_PFI(8))] = I(9),
1270 [B(NI_PFI(9))] = I(10),
1271 [B(NI_PFI(10))] = I(21),
1272 [B(NI_PFI(11))] = I(22),
1273 [B(NI_PFI(12))] = I(23),
1274 [B(NI_PFI(13))] = I(24),
1275 [B(NI_PFI(14))] = I(25),
1276 [B(NI_PFI(15))] = I(26),
1277 [B(TRIGGER_LINE(0))] = I(11),
1278 [B(TRIGGER_LINE(1))] = I(12),
1279 [B(TRIGGER_LINE(2))] = I(13),
1280 [B(TRIGGER_LINE(3))] = I(14),
1281 [B(TRIGGER_LINE(4))] = I(15),
1282 [B(TRIGGER_LINE(5))] = I(16),
1283 [B(TRIGGER_LINE(6))] = I(17),
1284 [B(TRIGGER_LINE(7))] = I(27),
1285 [B(NI_CtrSource(0))] = I(29),
1286 /* source for following line: mhddk GP examples */
1287 [B(NI_CtrInternalOutput(0))] = I(20),
1288 [B(PXI_Star)] = I(19),
1289 [B(NI_AI_StartTrigger)] = I(28),
1290 [B(NI_AI_ReferenceTrigger)] = I(18),
1291 [B(NI_AnalogComparisonEvent)] = I(30),
1292 [B(NI_LogicLow)] = I(31),
1293 },
1294 [B(NI_CtrOut(0))] = {
1295 [B(TRIGGER_LINE(0))] = I(1),
1296 [B(TRIGGER_LINE(1))] = I(2),
1297 [B(TRIGGER_LINE(2))] = I(3),
1298 [B(TRIGGER_LINE(3))] = I(4),
1299 [B(TRIGGER_LINE(4))] = I(5),
1300 [B(TRIGGER_LINE(5))] = I(6),
1301 [B(TRIGGER_LINE(6))] = I(7),
1302 [B(NI_CtrInternalOutput(0))] = I(0),
1303 },
1304 [B(NI_CtrOut(1))] = {
1305 [B(NI_CtrInternalOutput(1))] = I(0),
1306 },
1307 [B(NI_AI_SampleClock)] = {
1308 [B(NI_PFI(0))] = I(1),
1309 [B(NI_PFI(1))] = I(2),
1310 [B(NI_PFI(2))] = I(3),
1311 [B(NI_PFI(3))] = I(4),
1312 [B(NI_PFI(4))] = I(5),
1313 [B(NI_PFI(5))] = I(6),
1314 [B(NI_PFI(6))] = I(7),
1315 [B(NI_PFI(7))] = I(8),
1316 [B(NI_PFI(8))] = I(9),
1317 [B(NI_PFI(9))] = I(10),
1318 [B(NI_PFI(10))] = I(21),
1319 [B(NI_PFI(11))] = I(22),
1320 [B(NI_PFI(12))] = I(23),
1321 [B(NI_PFI(13))] = I(24),
1322 [B(NI_PFI(14))] = I(25),
1323 [B(NI_PFI(15))] = I(26),
1324 [B(TRIGGER_LINE(0))] = I(11),
1325 [B(TRIGGER_LINE(1))] = I(12),
1326 [B(TRIGGER_LINE(2))] = I(13),
1327 [B(TRIGGER_LINE(3))] = I(14),
1328 [B(TRIGGER_LINE(4))] = I(15),
1329 [B(TRIGGER_LINE(5))] = I(16),
1330 [B(TRIGGER_LINE(6))] = I(17),
1331 [B(TRIGGER_LINE(7))] = I(27),
1332 [B(NI_CtrInternalOutput(0))] = I(19),
1333 [B(NI_CtrInternalOutput(1))] = I(28),
1334 [B(PXI_Star)] = I(20),
1335 [B(NI_AI_SampleClockTimebase)] = I(0),
1336 [B(NI_AnalogComparisonEvent)] = I(30),
1337 [B(NI_SCXI_Trig1)] = I(29),
1338 [B(NI_LogicLow)] = I(31),
1339 },
1340 [B(NI_AI_SampleClockTimebase)] = {
1341 /* These are not currently implemented in ni modules */
1342 [B(NI_PFI(0))] = U(1),
1343 [B(NI_PFI(1))] = U(2),
1344 [B(NI_PFI(2))] = U(3),
1345 [B(NI_PFI(3))] = U(4),
1346 [B(NI_PFI(4))] = U(5),
1347 [B(NI_PFI(5))] = U(6),
1348 [B(NI_PFI(6))] = U(7),
1349 [B(NI_PFI(7))] = U(8),
1350 [B(NI_PFI(8))] = U(9),
1351 [B(NI_PFI(9))] = U(10),
1352 [B(NI_PFI(10))] = U(21),
1353 [B(NI_PFI(11))] = U(22),
1354 [B(NI_PFI(12))] = U(23),
1355 [B(NI_PFI(13))] = U(24),
1356 [B(NI_PFI(14))] = U(25),
1357 [B(NI_PFI(15))] = U(26),
1358 [B(TRIGGER_LINE(0))] = U(11),
1359 [B(TRIGGER_LINE(1))] = U(12),
1360 [B(TRIGGER_LINE(2))] = U(13),
1361 [B(TRIGGER_LINE(3))] = U(14),
1362 [B(TRIGGER_LINE(4))] = U(15),
1363 [B(TRIGGER_LINE(5))] = U(16),
1364 [B(TRIGGER_LINE(6))] = U(17),
1365 [B(TRIGGER_LINE(7))] = U(27),
1366 [B(PXI_Star)] = U(20),
1367 [B(PXI_Clk10)] = U(29),
1368 /*
1369 * For routes (*->NI_AI_SampleClockTimebase) and
1370 * (*->NI_AO_SampleClockTimebase), tMSeries.h of MHDDK
1371 * shows 0 value as selecting ground (case ground?) and
1372 * 28 value selecting TIMEBASE 1.
1373 */
1374 [B(NI_20MHzTimebase)] = U(28),
1375 [B(NI_100kHzTimebase)] = U(19),
1376 [B(NI_AnalogComparisonEvent)] = U(30),
1377 [B(NI_LogicLow)] = U(31),
1378 [B(NI_CaseGround)] = U(0),
1379 },
1380 [B(NI_AI_StartTrigger)] = {
1381 [B(NI_PFI(0))] = I(1),
1382 [B(NI_PFI(1))] = I(2),
1383 [B(NI_PFI(2))] = I(3),
1384 [B(NI_PFI(3))] = I(4),
1385 [B(NI_PFI(4))] = I(5),
1386 [B(NI_PFI(5))] = I(6),
1387 [B(NI_PFI(6))] = I(7),
1388 [B(NI_PFI(7))] = I(8),
1389 [B(NI_PFI(8))] = I(9),
1390 [B(NI_PFI(9))] = I(10),
1391 [B(NI_PFI(10))] = I(21),
1392 [B(NI_PFI(11))] = I(22),
1393 [B(NI_PFI(12))] = I(23),
1394 [B(NI_PFI(13))] = I(24),
1395 [B(NI_PFI(14))] = I(25),
1396 [B(NI_PFI(15))] = I(26),
1397 [B(TRIGGER_LINE(0))] = I(11),
1398 [B(TRIGGER_LINE(1))] = I(12),
1399 [B(TRIGGER_LINE(2))] = I(13),
1400 [B(TRIGGER_LINE(3))] = I(14),
1401 [B(TRIGGER_LINE(4))] = I(15),
1402 [B(TRIGGER_LINE(5))] = I(16),
1403 [B(TRIGGER_LINE(6))] = I(17),
1404 [B(TRIGGER_LINE(7))] = I(27),
1405 [B(NI_CtrInternalOutput(0))] = I(18),
1406 [B(NI_CtrInternalOutput(1))] = I(19),
1407 [B(PXI_Star)] = I(20),
1408 [B(NI_AnalogComparisonEvent)] = I(30),
1409 [B(NI_LogicLow)] = I(31),
1410 },
1411 [B(NI_AI_ReferenceTrigger)] = {
1412 /* These are not currently implemented in ni modules */
1413 [B(NI_PFI(0))] = U(1),
1414 [B(NI_PFI(1))] = U(2),
1415 [B(NI_PFI(2))] = U(3),
1416 [B(NI_PFI(3))] = U(4),
1417 [B(NI_PFI(4))] = U(5),
1418 [B(NI_PFI(5))] = U(6),
1419 [B(NI_PFI(6))] = U(7),
1420 [B(NI_PFI(7))] = U(8),
1421 [B(NI_PFI(8))] = U(9),
1422 [B(NI_PFI(9))] = U(10),
1423 [B(NI_PFI(10))] = U(21),
1424 [B(NI_PFI(11))] = U(22),
1425 [B(NI_PFI(12))] = U(23),
1426 [B(NI_PFI(13))] = U(24),
1427 [B(NI_PFI(14))] = U(25),
1428 [B(NI_PFI(15))] = U(26),
1429 [B(TRIGGER_LINE(0))] = U(11),
1430 [B(TRIGGER_LINE(1))] = U(12),
1431 [B(TRIGGER_LINE(2))] = U(13),
1432 [B(TRIGGER_LINE(3))] = U(14),
1433 [B(TRIGGER_LINE(4))] = U(15),
1434 [B(TRIGGER_LINE(5))] = U(16),
1435 [B(TRIGGER_LINE(6))] = U(17),
1436 [B(TRIGGER_LINE(7))] = U(27),
1437 [B(PXI_Star)] = U(20),
1438 [B(NI_AnalogComparisonEvent)] = U(30),
1439 [B(NI_LogicLow)] = U(31),
1440 },
1441 [B(NI_AI_ConvertClock)] = {
1442 [B(NI_PFI(0))] = I(1),
1443 [B(NI_PFI(1))] = I(2),
1444 [B(NI_PFI(2))] = I(3),
1445 [B(NI_PFI(3))] = I(4),
1446 [B(NI_PFI(4))] = I(5),
1447 [B(NI_PFI(5))] = I(6),
1448 [B(NI_PFI(6))] = I(7),
1449 [B(NI_PFI(7))] = I(8),
1450 [B(NI_PFI(8))] = I(9),
1451 [B(NI_PFI(9))] = I(10),
1452 [B(NI_PFI(10))] = I(21),
1453 [B(NI_PFI(11))] = I(22),
1454 [B(NI_PFI(12))] = I(23),
1455 [B(NI_PFI(13))] = I(24),
1456 [B(NI_PFI(14))] = I(25),
1457 [B(NI_PFI(15))] = I(26),
1458 [B(TRIGGER_LINE(0))] = I(11),
1459 [B(TRIGGER_LINE(1))] = I(12),
1460 [B(TRIGGER_LINE(2))] = I(13),
1461 [B(TRIGGER_LINE(3))] = I(14),
1462 [B(TRIGGER_LINE(4))] = I(15),
1463 [B(TRIGGER_LINE(5))] = I(16),
1464 [B(TRIGGER_LINE(6))] = I(17),
1465 [B(TRIGGER_LINE(7))] = I(27),
1466 /* source for following line: mhddk example headers */
1467 [B(NI_CtrInternalOutput(0))] = I(19),
1468 /* source for following line: mhddk example headers */
1469 [B(NI_CtrInternalOutput(1))] = I(18),
1470 [B(PXI_Star)] = I(20),
1471 [B(NI_AI_ConvertClockTimebase)] = I(0),
1472 [B(NI_AnalogComparisonEvent)] = I(30),
1473 [B(NI_LogicLow)] = I(31),
1474 },
1475 [B(NI_AI_ConvertClockTimebase)] = {
1476 /* These are not currently implemented in ni modules */
1477 [B(NI_AI_SampleClockTimebase)] = U(0),
1478 [B(NI_20MHzTimebase)] = U(1),
1479 },
1480 [B(NI_AI_PauseTrigger)] = {
1481 /* These are not currently implemented in ni modules */
1482 [B(NI_PFI(0))] = U(1),
1483 [B(NI_PFI(1))] = U(2),
1484 [B(NI_PFI(2))] = U(3),
1485 [B(NI_PFI(3))] = U(4),
1486 [B(NI_PFI(4))] = U(5),
1487 [B(NI_PFI(5))] = U(6),
1488 [B(NI_PFI(6))] = U(7),
1489 [B(NI_PFI(7))] = U(8),
1490 [B(NI_PFI(8))] = U(9),
1491 [B(NI_PFI(9))] = U(10),
1492 [B(NI_PFI(10))] = U(21),
1493 [B(NI_PFI(11))] = U(22),
1494 [B(NI_PFI(12))] = U(23),
1495 [B(NI_PFI(13))] = U(24),
1496 [B(NI_PFI(14))] = U(25),
1497 [B(NI_PFI(15))] = U(26),
1498 [B(TRIGGER_LINE(0))] = U(11),
1499 [B(TRIGGER_LINE(1))] = U(12),
1500 [B(TRIGGER_LINE(2))] = U(13),
1501 [B(TRIGGER_LINE(3))] = U(14),
1502 [B(TRIGGER_LINE(4))] = U(15),
1503 [B(TRIGGER_LINE(5))] = U(16),
1504 [B(TRIGGER_LINE(6))] = U(17),
1505 [B(TRIGGER_LINE(7))] = U(27),
1506 [B(PXI_Star)] = U(20),
1507 [B(NI_AnalogComparisonEvent)] = U(30),
1508 [B(NI_LogicLow)] = U(31),
1509 },
1510 [B(NI_AO_SampleClock)] = {
1511 [B(NI_PFI(0))] = I(1),
1512 [B(NI_PFI(1))] = I(2),
1513 [B(NI_PFI(2))] = I(3),
1514 [B(NI_PFI(3))] = I(4),
1515 [B(NI_PFI(4))] = I(5),
1516 [B(NI_PFI(5))] = I(6),
1517 [B(NI_PFI(6))] = I(7),
1518 [B(NI_PFI(7))] = I(8),
1519 [B(NI_PFI(8))] = I(9),
1520 [B(NI_PFI(9))] = I(10),
1521 [B(NI_PFI(10))] = I(21),
1522 [B(NI_PFI(11))] = I(22),
1523 [B(NI_PFI(12))] = I(23),
1524 [B(NI_PFI(13))] = I(24),
1525 [B(NI_PFI(14))] = I(25),
1526 [B(NI_PFI(15))] = I(26),
1527 [B(TRIGGER_LINE(0))] = I(11),
1528 [B(TRIGGER_LINE(1))] = I(12),
1529 [B(TRIGGER_LINE(2))] = I(13),
1530 [B(TRIGGER_LINE(3))] = I(14),
1531 [B(TRIGGER_LINE(4))] = I(15),
1532 [B(TRIGGER_LINE(5))] = I(16),
1533 [B(TRIGGER_LINE(6))] = I(17),
1534 [B(TRIGGER_LINE(7))] = I(27),
1535 [B(NI_CtrInternalOutput(0))] = I(18),
1536 [B(NI_CtrInternalOutput(1))] = I(19),
1537 [B(PXI_Star)] = I(20),
1538 [B(NI_AO_SampleClockTimebase)] = I(0),
1539 [B(NI_AnalogComparisonEvent)] = I(30),
1540 [B(NI_LogicLow)] = I(31),
1541 },
1542 [B(NI_AO_SampleClockTimebase)] = {
1543 /* These are not currently implemented in ni modules */
1544 [B(NI_PFI(0))] = U(1),
1545 [B(NI_PFI(1))] = U(2),
1546 [B(NI_PFI(2))] = U(3),
1547 [B(NI_PFI(3))] = U(4),
1548 [B(NI_PFI(4))] = U(5),
1549 [B(NI_PFI(5))] = U(6),
1550 [B(NI_PFI(6))] = U(7),
1551 [B(NI_PFI(7))] = U(8),
1552 [B(NI_PFI(8))] = U(9),
1553 [B(NI_PFI(9))] = U(10),
1554 [B(NI_PFI(10))] = U(21),
1555 [B(NI_PFI(11))] = U(22),
1556 [B(NI_PFI(12))] = U(23),
1557 [B(NI_PFI(13))] = U(24),
1558 [B(NI_PFI(14))] = U(25),
1559 [B(NI_PFI(15))] = U(26),
1560 [B(TRIGGER_LINE(0))] = U(11),
1561 [B(TRIGGER_LINE(1))] = U(12),
1562 [B(TRIGGER_LINE(2))] = U(13),
1563 [B(TRIGGER_LINE(3))] = U(14),
1564 [B(TRIGGER_LINE(4))] = U(15),
1565 [B(TRIGGER_LINE(5))] = U(16),
1566 [B(TRIGGER_LINE(6))] = U(17),
1567 [B(TRIGGER_LINE(7))] = U(27),
1568 [B(PXI_Star)] = U(20),
1569 [B(PXI_Clk10)] = U(29),
1570 /*
1571 * For routes (*->NI_AI_SampleClockTimebase) and
1572 * (*->NI_AO_SampleClockTimebase), tMSeries.h of MHDDK
1573 * shows 0 value as selecting ground (case ground?) and
1574 * 28 value selecting TIMEBASE 1.
1575 */
1576 [B(NI_20MHzTimebase)] = U(28),
1577 [B(NI_100kHzTimebase)] = U(19),
1578 [B(NI_AnalogComparisonEvent)] = U(30),
1579 [B(NI_LogicLow)] = U(31),
1580 [B(NI_CaseGround)] = U(0),
1581 },
1582 [B(NI_AO_StartTrigger)] = {
1583 [B(NI_PFI(0))] = I(1),
1584 [B(NI_PFI(1))] = I(2),
1585 [B(NI_PFI(2))] = I(3),
1586 [B(NI_PFI(3))] = I(4),
1587 [B(NI_PFI(4))] = I(5),
1588 [B(NI_PFI(5))] = I(6),
1589 [B(NI_PFI(6))] = I(7),
1590 [B(NI_PFI(7))] = I(8),
1591 [B(NI_PFI(8))] = I(9),
1592 [B(NI_PFI(9))] = I(10),
1593 [B(NI_PFI(10))] = I(21),
1594 [B(NI_PFI(11))] = I(22),
1595 [B(NI_PFI(12))] = I(23),
1596 [B(NI_PFI(13))] = I(24),
1597 [B(NI_PFI(14))] = I(25),
1598 [B(NI_PFI(15))] = I(26),
1599 [B(TRIGGER_LINE(0))] = I(11),
1600 [B(TRIGGER_LINE(1))] = I(12),
1601 [B(TRIGGER_LINE(2))] = I(13),
1602 [B(TRIGGER_LINE(3))] = I(14),
1603 [B(TRIGGER_LINE(4))] = I(15),
1604 [B(TRIGGER_LINE(5))] = I(16),
1605 [B(TRIGGER_LINE(6))] = I(17),
1606 [B(TRIGGER_LINE(7))] = I(27),
1607 [B(PXI_Star)] = I(20),
1608 /*
1609 * for the signal route
1610 * (NI_AI_StartTrigger->NI_AO_StartTrigger), DAQ-STC &
1611 * MHDDK disagreed for e-series. MHDDK for m-series
1612 * agrees with DAQ-STC description and uses the value 18
1613 * for the route
1614 * (NI_AI_ReferenceTrigger->NI_AO_StartTrigger). The
1615 * m-series devices are supposed to have DAQ-STC2.
1616 * There are no DAQ-STC2 docs to compare with.
1617 */
1618 [B(NI_AI_StartTrigger)] = I(19),
1619 [B(NI_AI_ReferenceTrigger)] = I(18),
1620 [B(NI_AnalogComparisonEvent)] = I(30),
1621 [B(NI_LogicLow)] = I(31),
1622 },
1623 [B(NI_AO_PauseTrigger)] = {
1624 /* These are not currently implemented in ni modules */
1625 [B(NI_PFI(0))] = U(1),
1626 [B(NI_PFI(1))] = U(2),
1627 [B(NI_PFI(2))] = U(3),
1628 [B(NI_PFI(3))] = U(4),
1629 [B(NI_PFI(4))] = U(5),
1630 [B(NI_PFI(5))] = U(6),
1631 [B(NI_PFI(6))] = U(7),
1632 [B(NI_PFI(7))] = U(8),
1633 [B(NI_PFI(8))] = U(9),
1634 [B(NI_PFI(9))] = U(10),
1635 [B(NI_PFI(10))] = U(21),
1636 [B(NI_PFI(11))] = U(22),
1637 [B(NI_PFI(12))] = U(23),
1638 [B(NI_PFI(13))] = U(24),
1639 [B(NI_PFI(14))] = U(25),
1640 [B(NI_PFI(15))] = U(26),
1641 [B(TRIGGER_LINE(0))] = U(11),
1642 [B(TRIGGER_LINE(1))] = U(12),
1643 [B(TRIGGER_LINE(2))] = U(13),
1644 [B(TRIGGER_LINE(3))] = U(14),
1645 [B(TRIGGER_LINE(4))] = U(15),
1646 [B(TRIGGER_LINE(5))] = U(16),
1647 [B(TRIGGER_LINE(6))] = U(17),
1648 [B(TRIGGER_LINE(7))] = U(27),
1649 [B(PXI_Star)] = U(20),
1650 [B(NI_AnalogComparisonEvent)] = U(30),
1651 [B(NI_LogicLow)] = U(31),
1652 },
1653 [B(NI_DI_SampleClock)] = {
1654 [B(NI_PFI(0))] = I(1),
1655 [B(NI_PFI(1))] = I(2),
1656 [B(NI_PFI(2))] = I(3),
1657 [B(NI_PFI(3))] = I(4),
1658 [B(NI_PFI(4))] = I(5),
1659 [B(NI_PFI(5))] = I(6),
1660 [B(NI_PFI(6))] = I(7),
1661 [B(NI_PFI(7))] = I(8),
1662 [B(NI_PFI(8))] = I(9),
1663 [B(NI_PFI(9))] = I(10),
1664 [B(NI_PFI(10))] = I(21),
1665 [B(NI_PFI(11))] = I(22),
1666 [B(NI_PFI(12))] = I(23),
1667 [B(NI_PFI(13))] = I(24),
1668 [B(NI_PFI(14))] = I(25),
1669 [B(NI_PFI(15))] = I(26),
1670 [B(TRIGGER_LINE(0))] = I(11),
1671 [B(TRIGGER_LINE(1))] = I(12),
1672 [B(TRIGGER_LINE(2))] = I(13),
1673 [B(TRIGGER_LINE(3))] = I(14),
1674 [B(TRIGGER_LINE(4))] = I(15),
1675 [B(TRIGGER_LINE(5))] = I(16),
1676 [B(TRIGGER_LINE(6))] = I(17),
1677 [B(TRIGGER_LINE(7))] = I(27),
1678 [B(NI_CtrInternalOutput(0))] = I(28),
1679 [B(NI_CtrInternalOutput(1))] = I(29),
1680 [B(PXI_Star)] = I(20),
1681 [B(NI_AI_SampleClock)] = I(18),
1682 [B(NI_AI_ConvertClock)] = I(19),
1683 [B(NI_AO_SampleClock)] = I(31),
1684 [B(NI_FrequencyOutput)] = I(32),
1685 [B(NI_ChangeDetectionEvent)] = I(33),
1686 [B(NI_CaseGround)] = I(0),
1687 },
1688 [B(NI_DO_SampleClock)] = {
1689 [B(NI_PFI(0))] = I(1),
1690 [B(NI_PFI(1))] = I(2),
1691 [B(NI_PFI(2))] = I(3),
1692 [B(NI_PFI(3))] = I(4),
1693 [B(NI_PFI(4))] = I(5),
1694 [B(NI_PFI(5))] = I(6),
1695 [B(NI_PFI(6))] = I(7),
1696 [B(NI_PFI(7))] = I(8),
1697 [B(NI_PFI(8))] = I(9),
1698 [B(NI_PFI(9))] = I(10),
1699 [B(NI_PFI(10))] = I(21),
1700 [B(NI_PFI(11))] = I(22),
1701 [B(NI_PFI(12))] = I(23),
1702 [B(NI_PFI(13))] = I(24),
1703 [B(NI_PFI(14))] = I(25),
1704 [B(NI_PFI(15))] = I(26),
1705 [B(TRIGGER_LINE(0))] = I(11),
1706 [B(TRIGGER_LINE(1))] = I(12),
1707 [B(TRIGGER_LINE(2))] = I(13),
1708 [B(TRIGGER_LINE(3))] = I(14),
1709 [B(TRIGGER_LINE(4))] = I(15),
1710 [B(TRIGGER_LINE(5))] = I(16),
1711 [B(TRIGGER_LINE(6))] = I(17),
1712 [B(TRIGGER_LINE(7))] = I(27),
1713 [B(NI_CtrInternalOutput(0))] = I(28),
1714 [B(NI_CtrInternalOutput(1))] = I(29),
1715 [B(PXI_Star)] = I(20),
1716 [B(NI_AI_SampleClock)] = I(18),
1717 [B(NI_AI_ConvertClock)] = I(19),
1718 [B(NI_AO_SampleClock)] = I(31),
1719 [B(NI_FrequencyOutput)] = I(32),
1720 [B(NI_ChangeDetectionEvent)] = I(33),
1721 [B(NI_CaseGround)] = I(0),
1722 },
1723 [B(NI_MasterTimebase)] = {
1724 /* These are not currently implemented in ni modules */
1725 [B(TRIGGER_LINE(0))] = U(11),
1726 [B(TRIGGER_LINE(1))] = U(12),
1727 [B(TRIGGER_LINE(2))] = U(13),
1728 [B(TRIGGER_LINE(3))] = U(14),
1729 [B(TRIGGER_LINE(4))] = U(15),
1730 [B(TRIGGER_LINE(5))] = U(16),
1731 [B(TRIGGER_LINE(6))] = U(17),
1732 [B(TRIGGER_LINE(7))] = U(27),
1733 [B(PXI_Star)] = U(20),
1734 [B(PXI_Clk10)] = U(29),
1735 [B(NI_10MHzRefClock)] = U(0),
1736 },
1737 /*
1738 * This symbol is not defined and nothing for this is
1739 * implemented--just including this because data was found in
1740 * the NI-STC for it--can't remember where.
1741 * [B(NI_FrequencyOutTimebase)] = {
1742 * ** These are not currently implemented in ni modules **
1743 * [B(NI_20MHzTimebase)] = U(0),
1744 * [B(NI_100kHzTimebase)] = U(1),
1745 * },
1746 */
1747 [B(NI_RGOUT0)] = {
1748 [B(NI_CtrInternalOutput(0))] = I(0),
1749 [B(NI_CtrOut(0))] = I(1),
1750 },
1751 },
1752};
diff --git a/drivers/staging/comedi/drivers/ni_routing/tools/.gitignore b/drivers/staging/comedi/drivers/ni_routing/tools/.gitignore
new file mode 100644
index 000000000000..ef38008280a9
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/tools/.gitignore
@@ -0,0 +1,7 @@
1comedi_h.py
2*.pyc
3ni_values.py
4convert_c_to_py
5c/
6csv/
7all_cfiles.c
diff --git a/drivers/staging/comedi/drivers/ni_routing/tools/Makefile b/drivers/staging/comedi/drivers/ni_routing/tools/Makefile
new file mode 100644
index 000000000000..1966850584d2
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/tools/Makefile
@@ -0,0 +1,79 @@
1# this make file is simply to help autogenerate these files:
2# ni_route_values.h
3# ni_device_routes.h
4# in order to do this, we are also generating a python representation (using
5# ctypesgen) of ../../comedi.h.
6# This allows us to sort NI signal/terminal names numerically to use a binary
7# search through the device_routes tables to find valid routes.
8
9ALL:
10 @echo Typical targets:
11 @echo "\`make csv-files\`"
12 @echo " Creates new csv-files using content of c-files of existing"
13 @echo " ni_routing/* content. New csv files are placed in csv"
14 @echo " sub-directory."
15 @echo "\`make c-files\`"
16 @echo " Creates new c-files using content of csv sub-directory. These"
17 @echo " new c-files can be compared to the active content in the"
18 @echo " ni_routing directory."
19 @echo "\`make csv-blank\`"
20 @echo " Create a new blank csv file. This is useful for establishing a"
21 @echo " new data table for either a device family \(less likely\) or a"
22 @echo " specific board of an existing device family \(more likely\)."
23 @echo "\`make clean-partial\`"
24 @echo " Remove all generated files/directories EXCEPT for csv/c files."
25 @echo "\`make clean\`"
26 @echo " Remove all generated files/directories."
27 @echo "\`make everything\`"
28 @echo " Build all csv-files, then all new c-files."
29
30everything : csv-files c-files csv-blank
31
32CPPFLAGS=-D"BIT(x)=(1UL<<(x))" -D__user=
33
34comedi_h.py : ../../../comedi.h
35 ctypesgen $< --include "sys/ioctl.h" --cpp 'gcc -E $(CPPFLAGS)' -o $@
36
37convert_c_to_py: all_cfiles.c
38 gcc -g convert_c_to_py.c -o convert_c_to_py -std=c99
39
40ni_values.py: convert_c_to_py
41 ./convert_c_to_py
42
43csv-files : ni_values.py comedi_h.py
44 ./convert_py_to_csv.py
45
46csv-blank :
47 ./make_blank_csv.py
48 @echo New blank csv signal table in csv/blank_route_table.csv
49
50c-files : comedi_h.py
51 ./convert_csv_to_c.py --route_values --device_routes
52
53ROUTE_VALUES_SRC=$(wildcard ../ni_route_values/*.c)
54DEVICE_ROUTES_SRC=$(wildcard ../ni_device_routes/*.c)
55all_cfiles.c : $(DEVICE_ROUTES_SRC) $(ROUTE_VALUES_SRC)
56 @for i in $(DEVICE_ROUTES_SRC) $(ROUTE_VALUES_SRC); do \
57 echo "#include \"$$i\"" >> all_cfiles.c; \
58 done
59
60clean-partial :
61 $(RM) -rf comedi_h.py ni_values.py convert_c_to_py all_cfiles.c *.pyc \
62 __pycache__/
63
64clean : partial_clean
65 $(RM) -rf c/ csv/
66
67# Note: One could also use ctypeslib in order to generate these files. The
68# caveat is that ctypeslib does not do a great job at handling macro functions.
69# The make rules are as follows:
70# comedi.h.xml : ../../comedi.h
71# # note that we have to use PWD here to avoid h2xml finding a system
72# # installed version of the comedilib/comedi.h file
73# h2xml ${PWD}/../../comedi.h -c -D__user="" -D"BIT(x)=(1<<(x))" \
74# -o comedi.h.xml
75#
76# comedi_h.py : comedi.h.xml
77# xml2py ./comedi.h.xml -o comedi_h.py
78# clean :
79# rm -f comedi.h.xml comedi_h.py comedi_h.pyc
diff --git a/drivers/staging/comedi/drivers/ni_routing/tools/convert_c_to_py.c b/drivers/staging/comedi/drivers/ni_routing/tools/convert_c_to_py.c
new file mode 100644
index 000000000000..dedb6f2fc678
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/tools/convert_c_to_py.c
@@ -0,0 +1,159 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3
4#include <stdint.h>
5#include <stdbool.h>
6#include <stddef.h>
7#include <errno.h>
8#include <stdlib.h>
9
10typedef uint8_t u8;
11typedef uint16_t u16;
12typedef int8_t s8;
13#define __user
14#define BIT(x) (1UL << (x))
15
16#define NI_ROUTE_VALUE_EXTERNAL_CONVERSION 1
17
18#include "../ni_route_values.c"
19#include "../ni_device_routes.c"
20#include "all_cfiles.c"
21
22#include <stdio.h>
23
24#define RVij(rv, src, dest) ((rv)->register_values[(dest)][(src)])
25
26/*
27 * write out
28 * {
29 * "family" : "<family-name>",
30 * "register_values": {
31 * <destination0>:[src0, src1, ...],
32 * <destination0>:[src0, src1, ...],
33 * ...
34 * }
35 * }
36 */
37void family_write(const struct family_route_values *rv, FILE *fp)
38{
39 fprintf(fp,
40 " \"%s\" : {\n"
41 " # dest -> {src0:val0, src1:val1, ...}\n"
42 , rv->family);
43 for (unsigned int dest = NI_NAMES_BASE;
44 dest < (NI_NAMES_BASE + NI_NUM_NAMES);
45 ++dest) {
46 unsigned int src = NI_NAMES_BASE;
47
48 for (; src < (NI_NAMES_BASE + NI_NUM_NAMES) &&
49 RVij(rv, B(src), B(dest)) == 0; ++src)
50 ;
51
52 if (src >= (NI_NAMES_BASE + NI_NUM_NAMES))
53 continue; /* no data here */
54
55 fprintf(fp, " %u : {\n", dest);
56 for (src = NI_NAMES_BASE; src < (NI_NAMES_BASE + NI_NUM_NAMES);
57 ++src) {
58 register_type r = RVij(rv, B(src), B(dest));
59 const char *M;
60
61 if (r == 0) {
62 continue;
63 } else if (MARKED_V(r)) {
64 M = "V";
65 } else if (MARKED_I(r)) {
66 M = "I";
67 } else if (MARKED_U(r)) {
68 M = "U";
69 } else {
70 fprintf(stderr,
71 "Invalid register marking %s[%u][%u] = %u\n",
72 rv->family, dest, src, r);
73 exit(1);
74 }
75
76 fprintf(fp, " %u : \"%s(%u)\",\n",
77 src, M, UNMARK(r));
78 }
79 fprintf(fp, " },\n");
80 }
81 fprintf(fp, " },\n\n");
82}
83
84bool is_valid_ni_sig(unsigned int sig)
85{
86 return (sig >= NI_NAMES_BASE) && (sig < (NI_NAMES_BASE + NI_NUM_NAMES));
87}
88
89/*
90 * write out
91 * {
92 * "family" : "<family-name>",
93 * "register_values": {
94 * <destination0>:[src0, src1, ...],
95 * <destination0>:[src0, src1, ...],
96 * ...
97 * }
98 * }
99 */
100void device_write(const struct ni_device_routes *dR, FILE *fp)
101{
102 fprintf(fp,
103 " \"%s\" : {\n"
104 " # dest -> [src0, src1, ...]\n"
105 , dR->device);
106
107 unsigned int i = 0;
108
109 while (dR->routes[i].dest != 0) {
110 if (!is_valid_ni_sig(dR->routes[i].dest)) {
111 fprintf(stderr,
112 "Invalid NI signal value [%u] for destination %s.[%u]\n",
113 dR->routes[i].dest, dR->device, i);
114 exit(1);
115 }
116
117 fprintf(fp, " %u : [", dR->routes[i].dest);
118
119 unsigned int j = 0;
120
121 while (dR->routes[i].src[j] != 0) {
122 if (!is_valid_ni_sig(dR->routes[i].src[j])) {
123 fprintf(stderr,
124 "Invalid NI signal value [%u] for source %s.[%u].[%u]\n",
125 dR->routes[i].src[j], dR->device, i, j);
126 exit(1);
127 }
128
129 fprintf(fp, "%u,", dR->routes[i].src[j]);
130
131 ++j;
132 }
133 fprintf(fp, "],\n");
134
135 ++i;
136 }
137 fprintf(fp, " },\n\n");
138}
139
140int main(void)
141{
142 FILE *fp = fopen("ni_values.py", "w");
143
144 /* write route register values */
145 fprintf(fp, "ni_route_values = {\n");
146 for (int i = 0; ni_all_route_values[i]; ++i)
147 family_write(ni_all_route_values[i], fp);
148 fprintf(fp, "}\n\n");
149
150 /* write valid device routes */
151 fprintf(fp, "ni_device_routes = {\n");
152 for (int i = 0; ni_device_routes_list[i]; ++i)
153 device_write(ni_device_routes_list[i], fp);
154 fprintf(fp, "}\n");
155
156 /* finish; close file */
157 fclose(fp);
158 return 0;
159}
diff --git a/drivers/staging/comedi/drivers/ni_routing/tools/convert_csv_to_c.py b/drivers/staging/comedi/drivers/ni_routing/tools/convert_csv_to_c.py
new file mode 100755
index 000000000000..532eb6372a5a
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/tools/convert_csv_to_c.py
@@ -0,0 +1,503 @@
1#!/usr/bin/env python3
2# SPDX-License-Identifier: GPL-2.0+
3# vim: ts=2:sw=2:et:tw=80:nowrap
4
5# This is simply to aide in creating the entries in the order of the value of
6# the device-global NI signal/terminal constants defined in comedi.h
7import comedi_h
8import os, sys, re
9from csv_collection import CSVCollection
10
11
12def c_to_o(filename, prefix='\t\t\t\t\t ni_routing/', suffix=' \\'):
13 if not filename.endswith('.c'):
14 return ''
15 return prefix + filename.rpartition('.c')[0] + '.o' + suffix
16
17
18def routedict_to_structinit_single(name, D, return_name=False):
19 Locals = dict()
20 lines = [
21 '\t.family = "{}",'.format(name),
22 '\t.register_values = {',
23 '\t\t/*',
24 '\t\t * destination = {',
25 '\t\t * source = register value,',
26 '\t\t * ...',
27 '\t\t * }',
28 '\t\t */',
29 ]
30 if (False):
31 # print table with index0:src, index1:dest
32 D0 = D # (src-> dest->reg_value)
33 #D1 : destD
34 else:
35 D0 = dict()
36 for src, destD in D.items():
37 for dest, val in destD.items():
38 D0.setdefault(dest, {})[src] = val
39
40
41 D0 = sorted(D0.items(), key=lambda i: eval(i[0], comedi_h.__dict__, Locals))
42
43 for D0_sig, D1_D in D0:
44 D1 = sorted(D1_D.items(), key=lambda i: eval(i[0], comedi_h.__dict__, Locals))
45
46 lines.append('\t\t[B({})] = {{'.format(D0_sig))
47 for D1_sig, value in D1:
48 if not re.match('[VIU]\([^)]*\)', value):
49 sys.stderr.write('Invalid register format: {}\n'.format(repr(value)))
50 sys.stderr.write(
51 'Register values should be formatted with V(),I(),or U()\n')
52 raise RuntimeError('Invalid register values format')
53 lines.append('\t\t\t[B({})]\t= {},'.format(D1_sig, value))
54 lines.append('\t\t},')
55 lines.append('\t},')
56
57 lines = '\n'.join(lines)
58 if return_name:
59 return N, lines
60 else:
61 return lines
62
63
64def routedict_to_routelist_single(name, D, indent=1):
65 Locals = dict()
66
67 indents = dict(
68 I0 = '\t'*(indent),
69 I1 = '\t'*(indent+1),
70 I2 = '\t'*(indent+2),
71 I3 = '\t'*(indent+3),
72 I4 = '\t'*(indent+4),
73 )
74
75 if (False):
76 # data is src -> dest-list
77 D0 = D
78 keyname = 'src'
79 valname = 'dest'
80 else:
81 # data is dest -> src-list
82 keyname = 'dest'
83 valname = 'src'
84 D0 = dict()
85 for src, destD in D.items():
86 for dest, val in destD.items():
87 D0.setdefault(dest, {})[src] = val
88
89 # Sort by order of device-global names (numerically)
90 D0 = sorted(D0.items(), key=lambda i: eval(i[0], comedi_h.__dict__, Locals))
91
92 lines = [ '{I0}.device = "{name}",\n'
93 '{I0}.routes = (struct ni_route_set[]){{'
94 .format(name=name, **indents) ]
95 for D0_sig, D1_D in D0:
96 D1 = [ k for k,v in D1_D.items() if v ]
97 D1.sort(key=lambda i: eval(i, comedi_h.__dict__, Locals))
98
99 lines.append('{I1}{{\n{I2}.{keyname} = {D0_sig},\n'
100 '{I2}.{valname} = (int[]){{'
101 .format(keyname=keyname, valname=valname, D0_sig=D0_sig, **indents)
102 )
103 for D1_sig in D1:
104 lines.append( '{I3}{D1_sig},'.format(D1_sig=D1_sig, **indents) )
105 lines.append( '{I3}0, /* Termination */'.format(**indents) )
106
107 lines.append('{I2}}}\n{I1}}},'.format(**indents))
108
109 lines.append('{I1}{{ /* Termination of list */\n{I2}.{keyname} = 0,\n{I1}}},'
110 .format(keyname=keyname, **indents))
111
112 lines.append('{I0}}},'.format(**indents))
113
114 return '\n'.join(lines)
115
116
117class DeviceRoutes(CSVCollection):
118 MKFILE_SEGMENTS = 'device-route.mk'
119 SET_C = 'ni_device_routes.c'
120 ITEMS_DIR = 'ni_device_routes'
121 EXTERN_H = 'all.h'
122 OUTPUT_DIR = 'c'
123
124 output_file_top = """\
125// SPDX-License-Identifier: GPL-2.0+
126/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
127/*
128 * comedi/drivers/ni_routing/{filename}
129 * List of valid routes for specific NI boards.
130 *
131 * COMEDI - Linux Control and Measurement Device Interface
132 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
133 *
134 * This program is free software; you can redistribute it and/or modify
135 * it under the terms of the GNU General Public License as published by
136 * the Free Software Foundation; either version 2 of the License, or
137 * (at your option) any later version.
138 *
139 * This program is distributed in the hope that it will be useful,
140 * but WITHOUT ANY WARRANTY; without even the implied warranty of
141 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
142 * GNU General Public License for more details.
143 */
144
145/*
146 * The contents of this file are generated using the tools in
147 * comedi/drivers/ni_routing/tools
148 *
149 * Please use those tools to help maintain the contents of this file.
150 */
151
152#include "ni_device_routes.h"
153#include "{extern_h}"\
154""".format(filename=SET_C, extern_h=os.path.join(ITEMS_DIR, EXTERN_H))
155
156 extern_header = """\
157/* SPDX-License-Identifier: GPL-2.0+ */
158/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
159/*
160 * comedi/drivers/ni_routing/{filename}
161 * List of valid routes for specific NI boards.
162 *
163 * COMEDI - Linux Control and Measurement Device Interface
164 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
165 *
166 * This program is free software; you can redistribute it and/or modify
167 * it under the terms of the GNU General Public License as published by
168 * the Free Software Foundation; either version 2 of the License, or
169 * (at your option) any later version.
170 *
171 * This program is distributed in the hope that it will be useful,
172 * but WITHOUT ANY WARRANTY; without even the implied warranty of
173 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
174 * GNU General Public License for more details.
175 */
176
177/*
178 * The contents of this file are generated using the tools in
179 * comedi/drivers/ni_routing/tools
180 *
181 * Please use those tools to help maintain the contents of this file.
182 */
183
184#ifndef _COMEDI_DRIVERS_NI_ROUTING_NI_DEVICE_ROUTES_EXTERN_H
185#define _COMEDI_DRIVERS_NI_ROUTING_NI_DEVICE_ROUTES_EXTERN_H
186
187#include "../ni_device_routes.h"
188
189{externs}
190
191#endif //_COMEDI_DRIVERS_NI_ROUTING_NI_DEVICE_ROUTES_EXTERN_H
192"""
193
194 single_output_file_top = """\
195// SPDX-License-Identifier: GPL-2.0+
196/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
197/*
198 * comedi/drivers/ni_routing/{filename}
199 * List of valid routes for specific NI boards.
200 *
201 * COMEDI - Linux Control and Measurement Device Interface
202 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
203 *
204 * This program is free software; you can redistribute it and/or modify
205 * it under the terms of the GNU General Public License as published by
206 * the Free Software Foundation; either version 2 of the License, or
207 * (at your option) any later version.
208 *
209 * This program is distributed in the hope that it will be useful,
210 * but WITHOUT ANY WARRANTY; without even the implied warranty of
211 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
212 * GNU General Public License for more details.
213 */
214
215/*
216 * The contents of this file are generated using the tools in
217 * comedi/drivers/ni_routing/tools
218 *
219 * Please use those tools to help maintain the contents of this file.
220 */
221
222#include "../ni_device_routes.h"
223#include "{extern_h}"
224
225struct ni_device_routes {table_name} = {{\
226"""
227
228 def __init__(self, pattern='csv/device_routes/*.csv'):
229 super(DeviceRoutes,self).__init__(pattern)
230
231 def to_listinit(self):
232 chunks = [ self.output_file_top,
233 '',
234 'struct ni_device_routes *const ni_device_routes_list[] = {'
235 ]
236 # put the sheets in lexical order of device numbers then bus
237 sheets = sorted(self.items(), key=lambda i : tuple(i[0].split('-')[::-1]) )
238
239 externs = []
240 objs = [c_to_o(self.SET_C)]
241
242 for sheet,D in sheets:
243 S = sheet.lower()
244 dev_table_name = 'ni_{}_device_routes'.format(S.replace('-','_'))
245 sheet_filename = os.path.join(self.ITEMS_DIR,'{}.c'.format(S))
246 externs.append('extern struct ni_device_routes {};'.format(dev_table_name))
247
248 chunks.append('\t&{},'.format(dev_table_name))
249
250 s_chunks = [
251 self.single_output_file_top.format(
252 filename = sheet_filename,
253 table_name = dev_table_name,
254 extern_h = self.EXTERN_H,
255 ),
256 routedict_to_routelist_single(S, D),
257 '};',
258 ]
259
260 objs.append(c_to_o(sheet_filename))
261
262 with open(os.path.join(self.OUTPUT_DIR, sheet_filename), 'w') as f:
263 f.write('\n'.join(s_chunks))
264 f.write('\n')
265
266 with open(os.path.join(self.OUTPUT_DIR, self.MKFILE_SEGMENTS), 'w') as f:
267 f.write('# This is the segment that should be included in comedi/drivers/Makefile\n')
268 f.write('ni_routing-objs\t\t\t\t+= \\\n')
269 f.write('\n'.join(objs))
270 f.write('\n')
271
272 EXTERN_H = os.path.join(self.ITEMS_DIR, self.EXTERN_H)
273 with open(os.path.join(self.OUTPUT_DIR, EXTERN_H), 'w') as f:
274 f.write(self.extern_header.format(
275 filename=EXTERN_H, externs='\n'.join(externs)))
276
277 chunks.append('\tNULL,') # terminate list
278 chunks.append('};')
279 return '\n'.join(chunks)
280
281 def save(self):
282 filename=os.path.join(self.OUTPUT_DIR, self.SET_C)
283
284 try:
285 os.makedirs(os.path.join(self.OUTPUT_DIR, self.ITEMS_DIR))
286 except:
287 pass
288 with open(filename,'w') as f:
289 f.write( self.to_listinit() )
290 f.write( '\n' )
291
292
293class RouteValues(CSVCollection):
294 MKFILE_SEGMENTS = 'route-values.mk'
295 SET_C = 'ni_route_values.c'
296 ITEMS_DIR = 'ni_route_values'
297 EXTERN_H = 'all.h'
298 OUTPUT_DIR = 'c'
299
300 output_file_top = """\
301// SPDX-License-Identifier: GPL-2.0+
302/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
303/*
304 * comedi/drivers/ni_routing/{filename}
305 * Route information for NI boards.
306 *
307 * COMEDI - Linux Control and Measurement Device Interface
308 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
309 *
310 * This program is free software; you can redistribute it and/or modify
311 * it under the terms of the GNU General Public License as published by
312 * the Free Software Foundation; either version 2 of the License, or
313 * (at your option) any later version.
314 *
315 * This program is distributed in the hope that it will be useful,
316 * but WITHOUT ANY WARRANTY; without even the implied warranty of
317 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
318 * GNU General Public License for more details.
319 */
320
321/*
322 * This file includes the tables that are a list of all the values of various
323 * signals routes available on NI hardware. In many cases, one does not
324 * explicitly make these routes, rather one might indicate that something is
325 * used as the source of one particular trigger or another (using
326 * *_src=TRIG_EXT).
327 *
328 * The contents of this file are generated using the tools in
329 * comedi/drivers/ni_routing/tools
330 *
331 * Please use those tools to help maintain the contents of this file.
332 */
333
334#include "ni_route_values.h"
335#include "{extern_h}"\
336""".format(filename=SET_C, extern_h=os.path.join(ITEMS_DIR, EXTERN_H))
337
338 extern_header = """\
339/* SPDX-License-Identifier: GPL-2.0+ */
340/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
341/*
342 * comedi/drivers/ni_routing/{filename}
343 * List of valid routes for specific NI boards.
344 *
345 * COMEDI - Linux Control and Measurement Device Interface
346 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
347 *
348 * This program is free software; you can redistribute it and/or modify
349 * it under the terms of the GNU General Public License as published by
350 * the Free Software Foundation; either version 2 of the License, or
351 * (at your option) any later version.
352 *
353 * This program is distributed in the hope that it will be useful,
354 * but WITHOUT ANY WARRANTY; without even the implied warranty of
355 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
356 * GNU General Public License for more details.
357 */
358
359/*
360 * The contents of this file are generated using the tools in
361 * comedi/drivers/ni_routing/tools
362 *
363 * Please use those tools to help maintain the contents of this file.
364 */
365
366#ifndef _COMEDI_DRIVERS_NI_ROUTING_NI_ROUTE_VALUES_EXTERN_H
367#define _COMEDI_DRIVERS_NI_ROUTING_NI_ROUTE_VALUES_EXTERN_H
368
369#include "../ni_route_values.h"
370
371{externs}
372
373#endif //_COMEDI_DRIVERS_NI_ROUTING_NI_ROUTE_VALUES_EXTERN_H
374"""
375
376 single_output_file_top = """\
377// SPDX-License-Identifier: GPL-2.0+
378/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
379/*
380 * comedi/drivers/ni_routing/{filename}
381 * Route information for {sheet} boards.
382 *
383 * COMEDI - Linux Control and Measurement Device Interface
384 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
385 *
386 * This program is free software; you can redistribute it and/or modify
387 * it under the terms of the GNU General Public License as published by
388 * the Free Software Foundation; either version 2 of the License, or
389 * (at your option) any later version.
390 *
391 * This program is distributed in the hope that it will be useful,
392 * but WITHOUT ANY WARRANTY; without even the implied warranty of
393 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
394 * GNU General Public License for more details.
395 */
396
397/*
398 * This file includes a list of all the values of various signals routes
399 * available on NI 660x hardware. In many cases, one does not explicitly make
400 * these routes, rather one might indicate that something is used as the source
401 * of one particular trigger or another (using *_src=TRIG_EXT).
402 *
403 * The contents of this file can be generated using the tools in
404 * comedi/drivers/ni_routing/tools. This file also contains specific notes to
405 * this family of devices.
406 *
407 * Please use those tools to help maintain the contents of this file, but be
408 * mindful to not lose the notes already made in this file, since these notes
409 * are critical to a complete undertsanding of the register values of this
410 * family.
411 */
412
413#include "../ni_route_values.h"
414#include "{extern_h}"
415
416const struct family_route_values {table_name} = {{\
417"""
418
419 def __init__(self, pattern='csv/route_values/*.csv'):
420 super(RouteValues,self).__init__(pattern)
421
422 def to_structinit(self):
423 chunks = [ self.output_file_top,
424 '',
425 'const struct family_route_values *const ni_all_route_values[] = {'
426 ]
427 # put the sheets in lexical order for consistency
428 sheets = sorted(self.items(), key=lambda i : i[0] )
429
430 externs = []
431 objs = [c_to_o(self.SET_C)]
432
433 for sheet,D in sheets:
434 S = sheet.lower()
435 fam_table_name = '{}_route_values'.format(S.replace('-','_'))
436 sheet_filename = os.path.join(self.ITEMS_DIR,'{}.c'.format(S))
437 externs.append('extern const struct family_route_values {};'.format(fam_table_name))
438
439 chunks.append('\t&{},'.format(fam_table_name))
440
441 s_chunks = [
442 self.single_output_file_top.format(
443 filename = sheet_filename,
444 sheet = sheet.upper(),
445 table_name = fam_table_name,
446 extern_h = self.EXTERN_H,
447 ),
448 routedict_to_structinit_single(S, D),
449 '};',
450 ]
451
452 objs.append(c_to_o(sheet_filename))
453
454 with open(os.path.join(self.OUTPUT_DIR, sheet_filename), 'w') as f:
455 f.write('\n'.join(s_chunks))
456 f.write( '\n' )
457
458 with open(os.path.join(self.OUTPUT_DIR, self.MKFILE_SEGMENTS), 'w') as f:
459 f.write('# This is the segment that should be included in comedi/drivers/Makefile\n')
460 f.write('ni_routing-objs\t\t\t\t+= \\\n')
461 f.write('\n'.join(objs))
462 f.write('\n')
463
464 EXTERN_H = os.path.join(self.ITEMS_DIR, self.EXTERN_H)
465 with open(os.path.join(self.OUTPUT_DIR, EXTERN_H), 'w') as f:
466 f.write(self.extern_header.format(
467 filename=EXTERN_H, externs='\n'.join(externs)))
468
469 chunks.append('\tNULL,') # terminate list
470 chunks.append('};')
471 return '\n'.join(chunks)
472
473 def save(self):
474 filename=os.path.join(self.OUTPUT_DIR, self.SET_C)
475
476 try:
477 os.makedirs(os.path.join(self.OUTPUT_DIR, self.ITEMS_DIR))
478 except:
479 pass
480 with open(filename,'w') as f:
481 f.write( self.to_structinit() )
482 f.write( '\n' )
483
484
485
486if __name__ == '__main__':
487 import argparse
488 parser = argparse.ArgumentParser()
489 parser.add_argument( '--route_values', action='store_true',
490 help='Extract route values from csv/route_values/*.csv' )
491 parser.add_argument( '--device_routes', action='store_true',
492 help='Extract route values from csv/device_routes/*.csv' )
493 args = parser.parse_args()
494 KL = list()
495 if args.route_values:
496 KL.append( RouteValues )
497 if args.device_routes:
498 KL.append( DeviceRoutes )
499 if not KL:
500 parser.error('nothing to do...')
501 for K in KL:
502 doc = K()
503 doc.save()
diff --git a/drivers/staging/comedi/drivers/ni_routing/tools/convert_py_to_csv.py b/drivers/staging/comedi/drivers/ni_routing/tools/convert_py_to_csv.py
new file mode 100755
index 000000000000..b3e6472bac22
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/tools/convert_py_to_csv.py
@@ -0,0 +1,67 @@
1#!/usr/bin/env python3
2# SPDX-License-Identifier: GPL-2.0+
3# vim: ts=2:sw=2:et:tw=80:nowrap
4
5from os import path
6import os, csv
7from itertools import chain
8
9from csv_collection import CSVCollection
10from ni_names import value_to_name
11import ni_values
12
13CSV_DIR = 'csv'
14
15def iter_src_values(D):
16 return D.items()
17
18def iter_src(D):
19 for dest in D:
20 yield dest, 1
21
22def create_csv(name, D, src_iter):
23 # have to change dest->{src:val} to src->{dest:val}
24 fieldnames = [value_to_name[i] for i in sorted(D.keys())]
25 fieldnames.insert(0, CSVCollection.source_column_name)
26
27 S = dict()
28 for dest, srcD in D.items():
29 for src,val in src_iter(srcD):
30 S.setdefault(src,{})[dest] = val
31
32 S = sorted(S.items(), key = lambda src_destD : src_destD[0])
33
34
35 csv_fname = path.join(CSV_DIR, name + '.csv')
36 with open(csv_fname, 'w') as F_csv:
37 dR = csv.DictWriter(F_csv, fieldnames, delimiter=';', quotechar='"')
38 dR.writeheader()
39
40 # now change the json back into the csv dictionaries
41 rows = [
42 dict(chain(
43 ((CSVCollection.source_column_name,value_to_name[src]),),
44 *(((value_to_name[dest],v),) for dest,v in destD.items())
45 ))
46 for src, destD in S
47 ]
48
49 dR.writerows(rows)
50
51
52def to_csv():
53 for d in ['route_values', 'device_routes']:
54 try:
55 os.makedirs(path.join(CSV_DIR,d))
56 except:
57 pass
58
59 for family, dst_src_map in ni_values.ni_route_values.items():
60 create_csv(path.join('route_values',family), dst_src_map, iter_src_values)
61
62 for device, dst_src_map in ni_values.ni_device_routes.items():
63 create_csv(path.join('device_routes',device), dst_src_map, iter_src)
64
65
66if __name__ == '__main__':
67 to_csv()
diff --git a/drivers/staging/comedi/drivers/ni_routing/tools/csv_collection.py b/drivers/staging/comedi/drivers/ni_routing/tools/csv_collection.py
new file mode 100644
index 000000000000..12617329a928
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/tools/csv_collection.py
@@ -0,0 +1,40 @@
1# SPDX-License-Identifier: GPL-2.0+
2# vim: ts=2:sw=2:et:tw=80:nowrap
3
4import os, csv, glob
5
6class CSVCollection(dict):
7 delimiter=';'
8 quotechar='"'
9 source_column_name = 'Sources / Destinations'
10
11 """
12 This class is a dictionary representation of the collection of sheets that
13 exist in a given .ODS file.
14 """
15 def __init__(self, pattern, skip_commented_lines=True, strip_lines=True):
16 super(CSVCollection, self).__init__()
17 self.pattern = pattern
18 C = '#' if skip_commented_lines else 'blahblahblah'
19
20 if strip_lines:
21 strip = lambda s:s.strip()
22 else:
23 strip = lambda s:s
24
25 # load all CSV files
26 key = self.source_column_name
27 for fname in glob.glob(pattern):
28 with open(fname) as F:
29 dR = csv.DictReader(F, delimiter=self.delimiter,
30 quotechar=self.quotechar)
31 name = os.path.basename(fname).partition('.')[0]
32 D = {
33 r[key]:{f:strip(c) for f,c in r.items()
34 if f != key and f[:1] not in ['', C] and
35 strip(c)[:1] not in ['', C]}
36 for r in dR if r[key][:1] not in ['', C]
37 }
38 # now, go back through and eliminate all empty dictionaries
39 D = {k:v for k,v in D.items() if v}
40 self[name] = D
diff --git a/drivers/staging/comedi/drivers/ni_routing/tools/make_blank_csv.py b/drivers/staging/comedi/drivers/ni_routing/tools/make_blank_csv.py
new file mode 100755
index 000000000000..89c90a0ba24d
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/tools/make_blank_csv.py
@@ -0,0 +1,32 @@
1#!/usr/bin/env python3
2# SPDX-License-Identifier: GPL-2.0+
3# vim: ts=2:sw=2:et:tw=80:nowrap
4
5from os import path
6import os, csv
7
8from csv_collection import CSVCollection
9from ni_names import value_to_name
10
11CSV_DIR = 'csv'
12
13def to_csv():
14 try:
15 os.makedirs(CSV_DIR)
16 except:
17 pass
18
19 csv_fname = path.join(CSV_DIR, 'blank_route_table.csv')
20
21 fieldnames = [sig for sig_val, sig in sorted(value_to_name.items())]
22 fieldnames.insert(0, CSVCollection.source_column_name)
23
24 with open(csv_fname, 'w') as F_csv:
25 dR = csv.DictWriter(F_csv, fieldnames, delimiter=';', quotechar='"')
26 dR.writeheader()
27
28 for sig in fieldnames[1:]:
29 dR.writerow({CSVCollection.source_column_name: sig})
30
31if __name__ == '__main__':
32 to_csv()
diff --git a/drivers/staging/comedi/drivers/ni_routing/tools/ni_names.py b/drivers/staging/comedi/drivers/ni_routing/tools/ni_names.py
new file mode 100644
index 000000000000..5f9b825968b1
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/tools/ni_names.py
@@ -0,0 +1,56 @@
1# SPDX-License-Identifier: GPL-2.0+
2# vim: ts=2:sw=2:et:tw=80:nowrap
3"""
4This file helps to extract string names of NI signals as included in comedi.h
5between NI_NAMES_BASE and NI_NAMES_BASE+NI_NUM_NAMES.
6"""
7
8# This is simply to aide in creating the entries in the order of the value of
9# the device-global NI signal/terminal constants defined in comedi.h
10import comedi_h
11
12
13ni_macros = (
14 'NI_PFI',
15 'TRIGGER_LINE',
16 'NI_RTSI_BRD',
17 'NI_CtrSource',
18 'NI_CtrGate',
19 'NI_CtrAux',
20 'NI_CtrA',
21 'NI_CtrB',
22 'NI_CtrZ',
23 'NI_CtrArmStartTrigger',
24 'NI_CtrInternalOutput',
25 'NI_CtrOut',
26 'NI_CtrSampleClock',
27)
28
29def get_ni_names():
30 name_dict = dict()
31
32 # load all the static names; start with those that do not begin with NI_
33 name_dict['PXI_Star'] = comedi_h.PXI_Star
34 name_dict['PXI_Clk10'] = comedi_h.PXI_Clk10
35
36 #load all macro values
37 for fun in ni_macros:
38 f = getattr(comedi_h, fun)
39 name_dict.update({
40 '{}({})'.format(fun,i):f(i) for i in range(1 + f(-1) - f(0))
41 })
42
43 #load everything else in ni_common_signal_names enum
44 name_dict.update({
45 k:v for k,v in comedi_h.__dict__.items()
46 if k.startswith('NI_') and (not callable(v)) and
47 comedi_h.NI_COUNTER_NAMES_MAX < v < (comedi_h.NI_NAMES_BASE + comedi_h.NI_NUM_NAMES)
48 })
49
50 # now create reverse lookup (value -> name)
51
52 val_dict = {v:k for k,v in name_dict.items()}
53
54 return name_dict, val_dict
55
56name_to_value, value_to_name = get_ni_names()
diff --git a/drivers/staging/comedi/drivers/ni_stc.h b/drivers/staging/comedi/drivers/ni_stc.h
index 831088c5cabb..6c023b40fb53 100644
--- a/drivers/staging/comedi/drivers/ni_stc.h
+++ b/drivers/staging/comedi/drivers/ni_stc.h
@@ -15,6 +15,7 @@
15#define _COMEDI_NI_STC_H 15#define _COMEDI_NI_STC_H
16 16
17#include "ni_tio.h" 17#include "ni_tio.h"
18#include "ni_routes.h"
18 19
19/* 20/*
20 * Registers in the National Instruments DAQ-STC chip 21 * Registers in the National Instruments DAQ-STC chip
@@ -253,6 +254,8 @@
253#define NISTC_RTSI_TRIG_OLD_CLK_CHAN 7 254#define NISTC_RTSI_TRIG_OLD_CLK_CHAN 7
254#define NISTC_RTSI_TRIG_NUM_CHAN(_m) ((_m) ? 8 : 7) 255#define NISTC_RTSI_TRIG_NUM_CHAN(_m) ((_m) ? 8 : 7)
255#define NISTC_RTSI_TRIG_DIR(_c, _m) ((_m) ? BIT(8 + (_c)) : BIT(7 + (_c))) 256#define NISTC_RTSI_TRIG_DIR(_c, _m) ((_m) ? BIT(8 + (_c)) : BIT(7 + (_c)))
257#define NISTC_RTSI_TRIG_DIR_SUB_SEL1 BIT(2) /* only for M-Series */
258#define NISTC_RTSI_TRIG_DIR_SUB_SEL1_SHIFT 2 /* only for M-Series */
256#define NISTC_RTSI_TRIG_USE_CLK BIT(1) 259#define NISTC_RTSI_TRIG_USE_CLK BIT(1)
257#define NISTC_RTSI_TRIG_DRV_CLK BIT(0) 260#define NISTC_RTSI_TRIG_DRV_CLK BIT(0)
258 261
@@ -281,11 +284,15 @@
281#define NISTC_ATRIG_ETC_REG 61 284#define NISTC_ATRIG_ETC_REG 61
282#define NISTC_ATRIG_ETC_GPFO_1_ENA BIT(15) 285#define NISTC_ATRIG_ETC_GPFO_1_ENA BIT(15)
283#define NISTC_ATRIG_ETC_GPFO_0_ENA BIT(14) 286#define NISTC_ATRIG_ETC_GPFO_0_ENA BIT(14)
284#define NISTC_ATRIG_ETC_GPFO_0_SEL(x) (((x) & 0x3) << 11) 287#define NISTC_ATRIG_ETC_GPFO_0_SEL(x) (((x) & 0x7) << 11)
288#define NISTC_ATRIG_ETC_GPFO_0_SEL_TO_SRC(x) (((x) >> 11) & 0x7)
285#define NISTC_ATRIG_ETC_GPFO_1_SEL BIT(7) 289#define NISTC_ATRIG_ETC_GPFO_1_SEL BIT(7)
290#define NISTC_ATRIG_ETC_GPFO_1_SEL_TO_SRC(x) (((x) >> 7) & 0x1)
286#define NISTC_ATRIG_ETC_DRV BIT(4) 291#define NISTC_ATRIG_ETC_DRV BIT(4)
287#define NISTC_ATRIG_ETC_ENA BIT(3) 292#define NISTC_ATRIG_ETC_ENA BIT(3)
288#define NISTC_ATRIG_ETC_MODE(x) (((x) & 0x7) << 0) 293#define NISTC_ATRIG_ETC_MODE(x) (((x) & 0x7) << 0)
294#define NISTC_GPFO_0_G_OUT 0 /* input to GPFO_0_SEL for Ctr0Out */
295#define NISTC_GPFO_1_G_OUT 0 /* input to GPFO_1_SEL for Ctr1Out */
289 296
290#define NISTC_AI_START_STOP_REG 62 297#define NISTC_AI_START_STOP_REG 62
291#define NISTC_AI_START_POLARITY BIT(15) 298#define NISTC_AI_START_POLARITY BIT(15)
@@ -422,6 +429,7 @@
422#define NISTC_RTSI_TRIGA_OUT_REG 79 429#define NISTC_RTSI_TRIGA_OUT_REG 79
423#define NISTC_RTSI_TRIGB_OUT_REG 80 430#define NISTC_RTSI_TRIGB_OUT_REG 80
424#define NISTC_RTSI_TRIGB_SUB_SEL1 BIT(15) /* not for M-Series */ 431#define NISTC_RTSI_TRIGB_SUB_SEL1 BIT(15) /* not for M-Series */
432#define NISTC_RTSI_TRIGB_SUB_SEL1_SHIFT 15 /* not for M-Series */
425#define NISTC_RTSI_TRIG(_c, _s) (((_s) & 0xf) << (((_c) % 4) * 4)) 433#define NISTC_RTSI_TRIG(_c, _s) (((_s) & 0xf) << (((_c) % 4) * 4))
426#define NISTC_RTSI_TRIG_MASK(_c) NISTC_RTSI_TRIG((_c), 0xf) 434#define NISTC_RTSI_TRIG_MASK(_c) NISTC_RTSI_TRIG((_c), 0xf)
427#define NISTC_RTSI_TRIG_TO_SRC(_c, _b) (((_b) >> (((_c) % 4) * 4)) & 0xf) 435#define NISTC_RTSI_TRIG_TO_SRC(_c, _b) (((_b) >> (((_c) % 4) * 4)) & 0xf)
@@ -953,6 +961,7 @@ struct ni_board_struct {
953 int reg_type; 961 int reg_type;
954 unsigned int has_8255:1; 962 unsigned int has_8255:1;
955 unsigned int has_32dio_chan:1; 963 unsigned int has_32dio_chan:1;
964 unsigned int dio_speed; /* not for e-series */
956 965
957 enum caldac_enum caldac[3]; 966 enum caldac_enum caldac[3];
958}; 967};
@@ -962,6 +971,7 @@ struct ni_board_struct {
962#define NUM_GPCT 2 971#define NUM_GPCT 2
963 972
964#define NUM_PFI_OUTPUT_SELECT_REGS 6 973#define NUM_PFI_OUTPUT_SELECT_REGS 6
974#define NUM_RTSI_SHARED_MUXS (NI_RTSI_BRD(-1) - NI_RTSI_BRD(0) + 1)
965 975
966#define M_SERIES_EEPROM_SIZE 1024 976#define M_SERIES_EEPROM_SIZE 1024
967 977
@@ -1057,6 +1067,73 @@ struct ni_private {
1057 * possible. 1067 * possible.
1058 */ 1068 */
1059 unsigned int ao_needs_arming:1; 1069 unsigned int ao_needs_arming:1;
1070
1071 /* device signal route tables */
1072 struct ni_route_tables routing_tables;
1073
1074 /*
1075 * Number of clients (RTSI lines) for current RTSI MUX source.
1076 *
1077 * This allows resource management of RTSI board/shared mux lines by
1078 * marking the RTSI line that is using a particular MUX. Currently,
1079 * these lines are only automatically allocated based on source of the
1080 * route requested. Furthermore, the only way that this auto-allocation
1081 * and configuration works is via the globally-named ni signal/terminal
1082 * names.
1083 */
1084 u8 rtsi_shared_mux_usage[NUM_RTSI_SHARED_MUXS];
1085
1086 /*
1087 * softcopy register for rtsi shared mux/board lines.
1088 * For e-series, the bit layout of this register is
1089 * (docs: mhddk/nieseries/ChipObjects/tSTC.{h,ipp},
1090 * DAQ-STC, Jan 1999, 340934B-01):
1091 * bits 0:2 -- NI_RTSI_BRD(0) source selection
1092 * bits 3:5 -- NI_RTSI_BRD(1) source selection
1093 * bits 6:8 -- NI_RTSI_BRD(2) source selection
1094 * bits 9:11 -- NI_RTSI_BRD(3) source selection
1095 * bit 12 -- NI_RTSI_BRD(0) direction, 0:input, 1:output
1096 * bit 13 -- NI_RTSI_BRD(1) direction, 0:input, 1:output
1097 * bit 14 -- NI_RTSI_BRD(2) direction, 0:input, 1:output
1098 * bit 15 -- NI_RTSI_BRD(3) direction, 0:input, 1:output
1099 * According to DAQ-STC:
1100 * RTSI Board Interface--Configured as an input, each bidirectional
1101 * RTSI_BRD pin can drive any of the seven RTSI_TRIGGER pins.
1102 * RTSI_BRD<0..1> can also be driven by AI STOP and RTSI_BRD<2..3>
1103 * can also be driven by the AI START and SCAN_IN_PROG signals.
1104 * These pins provide a mechanism for additional board-level signals
1105 * to be sent on or received from the RTSI bus.
1106 * Couple of comments:
1107 * - Neither the DAQ-STC nor the MHDDK is clear on what the direction
1108 * of the RTSI_BRD pins actually means. There does not appear to be
1109 * any clear indication on what "output" would mean, since the point
1110 * of the RTSI_BRD lines is to always drive one of the
1111 * RTSI_TRIGGER<0..6> lines.
1112 * - The DAQ-STC also indicates that the NI_RTSI_BRD lines can be
1113 * driven by any of the RTSI_TRIGGER<0..6> lines.
1114 * But, looking at valid device routes, as visually imported from
1115 * NI-MAX, there appears to be only one family (so far) that has the
1116 * ability to route a signal from one TRIGGER_LINE to another
1117 * TRIGGER_LINE: the 653x family of DIO devices.
1118 *
1119 * For m-series, the bit layout of this register is
1120 * (docs: mhddk/nimseries/ChipObjects/tMSeries.{h,ipp}):
1121 * bits 0:3 -- NI_RTSI_BRD(0) source selection
1122 * bits 4:7 -- NI_RTSI_BRD(1) source selection
1123 * bits 8:11 -- NI_RTSI_BRD(2) source selection
1124 * bits 12:15 -- NI_RTSI_BRD(3) source selection
1125 * Note: The m-series does not have any option to change direction of
1126 * NI_RTSI_BRD muxes. Furthermore, there are no register values that
1127 * indicate the ability to have TRIGGER_LINES driving the output of
1128 * the NI_RTSI_BRD muxes.
1129 */
1130 u16 rtsi_shared_mux_reg;
1131
1132 /*
1133 * Number of clients (RTSI lines) for current RGOUT0 path.
1134 * Stored in part of in RTSI_TRIG_DIR or RTSI_TRIGB registers
1135 */
1136 u8 rgout0_usage;
1060}; 1137};
1061 1138
1062static const struct comedi_lrange range_ni_E_ao_ext; 1139static const struct comedi_lrange range_ni_E_ao_ext;
diff --git a/drivers/staging/comedi/drivers/ni_tio.c b/drivers/staging/comedi/drivers/ni_tio.c
index ef919b21b7d9..0eb388c0e1f0 100644
--- a/drivers/staging/comedi/drivers/ni_tio.c
+++ b/drivers/staging/comedi/drivers/ni_tio.c
@@ -818,10 +818,79 @@ static int ni_tio_get_clock_src(struct ni_gpct *counter,
818 return 0; 818 return 0;
819} 819}
820 820
821static inline void ni_tio_set_gate_raw(struct ni_gpct *counter,
822 unsigned int gate_source)
823{
824 ni_tio_set_bits(counter, NITIO_INPUT_SEL_REG(counter->counter_index),
825 GI_GATE_SEL_MASK, GI_GATE_SEL(gate_source));
826}
827
828static inline void ni_tio_set_gate2_raw(struct ni_gpct *counter,
829 unsigned int gate_source)
830{
831 ni_tio_set_bits(counter, NITIO_GATE2_REG(counter->counter_index),
832 GI_GATE2_SEL_MASK, GI_GATE2_SEL(gate_source));
833}
834
835/* Set the mode bits for gate. */
836static inline void ni_tio_set_gate_mode(struct ni_gpct *counter,
837 unsigned int src)
838{
839 unsigned int mode_bits = 0;
840
841 if (CR_CHAN(src) & NI_GPCT_DISABLED_GATE_SELECT) {
842 /*
843 * Allowing bitwise comparison here to allow non-zero raw
844 * register value to be used for channel when disabling.
845 */
846 mode_bits = GI_GATING_DISABLED;
847 } else {
848 if (src & CR_INVERT)
849 mode_bits |= GI_GATE_POL_INVERT;
850 if (src & CR_EDGE)
851 mode_bits |= GI_RISING_EDGE_GATING;
852 else
853 mode_bits |= GI_LEVEL_GATING;
854 }
855 ni_tio_set_bits(counter, NITIO_MODE_REG(counter->counter_index),
856 GI_GATE_POL_INVERT | GI_GATING_MODE_MASK,
857 mode_bits);
858}
859
860/*
861 * Set the mode bits for gate2.
862 *
863 * Previously, the code this function represents did not actually write anything
864 * to the register. Rather, writing to this register was reserved for the code
865 * ni ni_tio_set_gate2_raw.
866 */
867static inline void ni_tio_set_gate2_mode(struct ni_gpct *counter,
868 unsigned int src)
869{
870 /*
871 * The GI_GATE2_MODE bit was previously set in the code that also sets
872 * the gate2 source.
873 * We'll set mode bits _after_ source bits now, and thus, this function
874 * will effectively enable the second gate after all bits are set.
875 */
876 unsigned int mode_bits = GI_GATE2_MODE;
877
878 if (CR_CHAN(src) & NI_GPCT_DISABLED_GATE_SELECT)
879 /*
880 * Allowing bitwise comparison here to allow non-zero raw
881 * register value to be used for channel when disabling.
882 */
883 mode_bits = GI_GATING_DISABLED;
884 if (src & CR_INVERT)
885 mode_bits |= GI_GATE2_POL_INVERT;
886
887 ni_tio_set_bits(counter, NITIO_GATE2_REG(counter->counter_index),
888 GI_GATE2_POL_INVERT | GI_GATE2_MODE, mode_bits);
889}
890
821static int ni_660x_set_gate(struct ni_gpct *counter, unsigned int gate_source) 891static int ni_660x_set_gate(struct ni_gpct *counter, unsigned int gate_source)
822{ 892{
823 unsigned int chan = CR_CHAN(gate_source); 893 unsigned int chan = CR_CHAN(gate_source);
824 unsigned int cidx = counter->counter_index;
825 unsigned int gate_sel; 894 unsigned int gate_sel;
826 unsigned int i; 895 unsigned int i;
827 896
@@ -854,15 +923,13 @@ static int ni_660x_set_gate(struct ni_gpct *counter, unsigned int gate_source)
854 break; 923 break;
855 return -EINVAL; 924 return -EINVAL;
856 } 925 }
857 ni_tio_set_bits(counter, NITIO_INPUT_SEL_REG(cidx), 926 ni_tio_set_gate_raw(counter, gate_sel);
858 GI_GATE_SEL_MASK, GI_GATE_SEL(gate_sel));
859 return 0; 927 return 0;
860} 928}
861 929
862static int ni_m_set_gate(struct ni_gpct *counter, unsigned int gate_source) 930static int ni_m_set_gate(struct ni_gpct *counter, unsigned int gate_source)
863{ 931{
864 unsigned int chan = CR_CHAN(gate_source); 932 unsigned int chan = CR_CHAN(gate_source);
865 unsigned int cidx = counter->counter_index;
866 unsigned int gate_sel; 933 unsigned int gate_sel;
867 unsigned int i; 934 unsigned int i;
868 935
@@ -896,17 +963,13 @@ static int ni_m_set_gate(struct ni_gpct *counter, unsigned int gate_source)
896 break; 963 break;
897 return -EINVAL; 964 return -EINVAL;
898 } 965 }
899 ni_tio_set_bits(counter, NITIO_INPUT_SEL_REG(cidx), 966 ni_tio_set_gate_raw(counter, gate_sel);
900 GI_GATE_SEL_MASK, GI_GATE_SEL(gate_sel));
901 return 0; 967 return 0;
902} 968}
903 969
904static int ni_660x_set_gate2(struct ni_gpct *counter, unsigned int gate_source) 970static int ni_660x_set_gate2(struct ni_gpct *counter, unsigned int gate_source)
905{ 971{
906 struct ni_gpct_device *counter_dev = counter->counter_dev;
907 unsigned int cidx = counter->counter_index;
908 unsigned int chan = CR_CHAN(gate_source); 972 unsigned int chan = CR_CHAN(gate_source);
909 unsigned int gate2_reg = NITIO_GATE2_REG(cidx);
910 unsigned int gate2_sel; 973 unsigned int gate2_sel;
911 unsigned int i; 974 unsigned int i;
912 975
@@ -940,94 +1003,106 @@ static int ni_660x_set_gate2(struct ni_gpct *counter, unsigned int gate_source)
940 break; 1003 break;
941 return -EINVAL; 1004 return -EINVAL;
942 } 1005 }
943 counter_dev->regs[gate2_reg] |= GI_GATE2_MODE; 1006 ni_tio_set_gate2_raw(counter, gate2_sel);
944 counter_dev->regs[gate2_reg] &= ~GI_GATE2_SEL_MASK;
945 counter_dev->regs[gate2_reg] |= GI_GATE2_SEL(gate2_sel);
946 ni_tio_write(counter, counter_dev->regs[gate2_reg], gate2_reg);
947 return 0; 1007 return 0;
948} 1008}
949 1009
950static int ni_m_set_gate2(struct ni_gpct *counter, unsigned int gate_source) 1010static int ni_m_set_gate2(struct ni_gpct *counter, unsigned int gate_source)
951{ 1011{
952 struct ni_gpct_device *counter_dev = counter->counter_dev;
953 unsigned int cidx = counter->counter_index;
954 unsigned int chan = CR_CHAN(gate_source);
955 unsigned int gate2_reg = NITIO_GATE2_REG(cidx);
956 unsigned int gate2_sel;
957
958 /* 1012 /*
959 * FIXME: We don't know what the m-series second gate codes are, 1013 * FIXME: We don't know what the m-series second gate codes are,
960 * so we'll just pass the bits through for now. 1014 * so we'll just pass the bits through for now.
961 */ 1015 */
962 switch (chan) { 1016 ni_tio_set_gate2_raw(counter, gate_source);
963 default: 1017 return 0;
964 gate2_sel = chan & 0x1f; 1018}
1019
1020int ni_tio_set_gate_src_raw(struct ni_gpct *counter,
1021 unsigned int gate, unsigned int src)
1022{
1023 struct ni_gpct_device *counter_dev = counter->counter_dev;
1024
1025 switch (gate) {
1026 case 0:
1027 /* 1. start by disabling gate */
1028 ni_tio_set_gate_mode(counter, NI_GPCT_DISABLED_GATE_SELECT);
1029 /* 2. set the requested gate source */
1030 ni_tio_set_gate_raw(counter, src);
1031 /* 3. reenable & set mode to starts things back up */
1032 ni_tio_set_gate_mode(counter, src);
1033 break;
1034 case 1:
1035 if (!ni_tio_has_gate2_registers(counter_dev))
1036 return -EINVAL;
1037
1038 /* 1. start by disabling gate */
1039 ni_tio_set_gate2_mode(counter, NI_GPCT_DISABLED_GATE_SELECT);
1040 /* 2. set the requested gate source */
1041 ni_tio_set_gate2_raw(counter, src);
1042 /* 3. reenable & set mode to starts things back up */
1043 ni_tio_set_gate2_mode(counter, src);
965 break; 1044 break;
1045 default:
1046 return -EINVAL;
966 } 1047 }
967 counter_dev->regs[gate2_reg] |= GI_GATE2_MODE;
968 counter_dev->regs[gate2_reg] &= ~GI_GATE2_SEL_MASK;
969 counter_dev->regs[gate2_reg] |= GI_GATE2_SEL(gate2_sel);
970 ni_tio_write(counter, counter_dev->regs[gate2_reg], gate2_reg);
971 return 0; 1048 return 0;
972} 1049}
1050EXPORT_SYMBOL_GPL(ni_tio_set_gate_src_raw);
973 1051
974int ni_tio_set_gate_src(struct ni_gpct *counter, 1052int ni_tio_set_gate_src(struct ni_gpct *counter,
975 unsigned int gate, unsigned int src) 1053 unsigned int gate, unsigned int src)
976{ 1054{
977 struct ni_gpct_device *counter_dev = counter->counter_dev; 1055 struct ni_gpct_device *counter_dev = counter->counter_dev;
978 unsigned int cidx = counter->counter_index; 1056 /*
979 unsigned int chan = CR_CHAN(src); 1057 * mask off disable flag. This high bit still passes CR_CHAN.
980 unsigned int gate2_reg = NITIO_GATE2_REG(cidx); 1058 * Doing this allows one to both set the gate as disabled, but also
981 unsigned int mode = 0; 1059 * change the route value of the gate.
1060 */
1061 int chan = CR_CHAN(src) & (~NI_GPCT_DISABLED_GATE_SELECT);
1062 int ret;
982 1063
983 switch (gate) { 1064 switch (gate) {
984 case 0: 1065 case 0:
985 if (chan == NI_GPCT_DISABLED_GATE_SELECT) { 1066 /* 1. start by disabling gate */
986 ni_tio_set_bits(counter, NITIO_MODE_REG(cidx), 1067 ni_tio_set_gate_mode(counter, NI_GPCT_DISABLED_GATE_SELECT);
987 GI_GATING_MODE_MASK, 1068 /* 2. set the requested gate source */
988 GI_GATING_DISABLED);
989 return 0;
990 }
991 if (src & CR_INVERT)
992 mode |= GI_GATE_POL_INVERT;
993 if (src & CR_EDGE)
994 mode |= GI_RISING_EDGE_GATING;
995 else
996 mode |= GI_LEVEL_GATING;
997 ni_tio_set_bits(counter, NITIO_MODE_REG(cidx),
998 GI_GATE_POL_INVERT | GI_GATING_MODE_MASK,
999 mode);
1000 switch (counter_dev->variant) { 1069 switch (counter_dev->variant) {
1001 case ni_gpct_variant_e_series: 1070 case ni_gpct_variant_e_series:
1002 case ni_gpct_variant_m_series: 1071 case ni_gpct_variant_m_series:
1003 default: 1072 ret = ni_m_set_gate(counter, chan);
1004 return ni_m_set_gate(counter, src); 1073 break;
1005 case ni_gpct_variant_660x: 1074 case ni_gpct_variant_660x:
1006 return ni_660x_set_gate(counter, src); 1075 ret = ni_660x_set_gate(counter, chan);
1076 break;
1077 default:
1078 return -EINVAL;
1007 } 1079 }
1080 if (ret)
1081 return ret;
1082 /* 3. reenable & set mode to starts things back up */
1083 ni_tio_set_gate_mode(counter, src);
1008 break; 1084 break;
1009 case 1: 1085 case 1:
1010 if (!ni_tio_has_gate2_registers(counter_dev)) 1086 if (!ni_tio_has_gate2_registers(counter_dev))
1011 return -EINVAL; 1087 return -EINVAL;
1012 1088
1013 if (chan == NI_GPCT_DISABLED_GATE_SELECT) { 1089 /* 1. start by disabling gate */
1014 counter_dev->regs[gate2_reg] &= ~GI_GATE2_MODE; 1090 ni_tio_set_gate2_mode(counter, NI_GPCT_DISABLED_GATE_SELECT);
1015 ni_tio_write(counter, counter_dev->regs[gate2_reg], 1091 /* 2. set the requested gate source */
1016 gate2_reg);
1017 return 0;
1018 }
1019 if (src & CR_INVERT)
1020 counter_dev->regs[gate2_reg] |= GI_GATE2_POL_INVERT;
1021 else
1022 counter_dev->regs[gate2_reg] &= ~GI_GATE2_POL_INVERT;
1023 switch (counter_dev->variant) { 1092 switch (counter_dev->variant) {
1024 case ni_gpct_variant_m_series: 1093 case ni_gpct_variant_m_series:
1025 return ni_m_set_gate2(counter, src); 1094 ret = ni_m_set_gate2(counter, chan);
1095 break;
1026 case ni_gpct_variant_660x: 1096 case ni_gpct_variant_660x:
1027 return ni_660x_set_gate2(counter, src); 1097 ret = ni_660x_set_gate2(counter, chan);
1098 break;
1028 default: 1099 default:
1029 return -EINVAL; 1100 return -EINVAL;
1030 } 1101 }
1102 if (ret)
1103 return ret;
1104 /* 3. reenable & set mode to starts things back up */
1105 ni_tio_set_gate2_mode(counter, src);
1031 break; 1106 break;
1032 default: 1107 default:
1033 return -EINVAL; 1108 return -EINVAL;
@@ -1047,19 +1122,21 @@ static int ni_tio_set_other_src(struct ni_gpct *counter, unsigned int index,
1047 return -EINVAL; 1122 return -EINVAL;
1048 1123
1049 abz_reg = NITIO_ABZ_REG(cidx); 1124 abz_reg = NITIO_ABZ_REG(cidx);
1050 switch (index) { 1125
1051 case NI_GPCT_SOURCE_ENCODER_A: 1126 /* allow for new device-global names */
1127 if (index == NI_GPCT_SOURCE_ENCODER_A ||
1128 (index >= NI_CtrA(0) && index <= NI_CtrA(-1))) {
1052 shift = 10; 1129 shift = 10;
1053 break; 1130 } else if (index == NI_GPCT_SOURCE_ENCODER_B ||
1054 case NI_GPCT_SOURCE_ENCODER_B: 1131 (index >= NI_CtrB(0) && index <= NI_CtrB(-1))) {
1055 shift = 5; 1132 shift = 5;
1056 break; 1133 } else if (index == NI_GPCT_SOURCE_ENCODER_Z ||
1057 case NI_GPCT_SOURCE_ENCODER_Z: 1134 (index >= NI_CtrZ(0) && index <= NI_CtrZ(-1))) {
1058 shift = 0; 1135 shift = 0;
1059 break; 1136 } else {
1060 default:
1061 return -EINVAL; 1137 return -EINVAL;
1062 } 1138 }
1139
1063 mask = 0x1f << shift; 1140 mask = 0x1f << shift;
1064 if (source > 0x1f) 1141 if (source > 0x1f)
1065 source = 0x1f; /* Disable gate */ 1142 source = 0x1f; /* Disable gate */
@@ -1070,6 +1147,39 @@ static int ni_tio_set_other_src(struct ni_gpct *counter, unsigned int index,
1070 return 0; 1147 return 0;
1071} 1148}
1072 1149
1150static int ni_tio_get_other_src(struct ni_gpct *counter, unsigned int index,
1151 unsigned int *source)
1152{
1153 struct ni_gpct_device *counter_dev = counter->counter_dev;
1154 unsigned int cidx = counter->counter_index;
1155 unsigned int abz_reg, shift, mask;
1156
1157 if (counter_dev->variant != ni_gpct_variant_m_series)
1158 /* A,B,Z only valid for m-series */
1159 return -EINVAL;
1160
1161 abz_reg = NITIO_ABZ_REG(cidx);
1162
1163 /* allow for new device-global names */
1164 if (index == NI_GPCT_SOURCE_ENCODER_A ||
1165 (index >= NI_CtrA(0) && index <= NI_CtrA(-1))) {
1166 shift = 10;
1167 } else if (index == NI_GPCT_SOURCE_ENCODER_B ||
1168 (index >= NI_CtrB(0) && index <= NI_CtrB(-1))) {
1169 shift = 5;
1170 } else if (index == NI_GPCT_SOURCE_ENCODER_Z ||
1171 (index >= NI_CtrZ(0) && index <= NI_CtrZ(-1))) {
1172 shift = 0;
1173 } else {
1174 return -EINVAL;
1175 }
1176
1177 mask = 0x1f;
1178
1179 *source = (ni_tio_get_soft_copy(counter, abz_reg) >> shift) & mask;
1180 return 0;
1181}
1182
1073static int ni_660x_gate_to_generic_gate(unsigned int gate, unsigned int *src) 1183static int ni_660x_gate_to_generic_gate(unsigned int gate, unsigned int *src)
1074{ 1184{
1075 unsigned int source; 1185 unsigned int source;
@@ -1112,7 +1222,7 @@ static int ni_660x_gate_to_generic_gate(unsigned int gate, unsigned int *src)
1112 } 1222 }
1113 *src = source; 1223 *src = source;
1114 return 0; 1224 return 0;
1115}; 1225}
1116 1226
1117static int ni_m_gate_to_generic_gate(unsigned int gate, unsigned int *src) 1227static int ni_m_gate_to_generic_gate(unsigned int gate, unsigned int *src)
1118{ 1228{
@@ -1165,7 +1275,7 @@ static int ni_m_gate_to_generic_gate(unsigned int gate, unsigned int *src)
1165 } 1275 }
1166 *src = source; 1276 *src = source;
1167 return 0; 1277 return 0;
1168}; 1278}
1169 1279
1170static int ni_660x_gate2_to_generic_gate(unsigned int gate, unsigned int *src) 1280static int ni_660x_gate2_to_generic_gate(unsigned int gate, unsigned int *src)
1171{ 1281{
@@ -1212,7 +1322,7 @@ static int ni_660x_gate2_to_generic_gate(unsigned int gate, unsigned int *src)
1212 } 1322 }
1213 *src = source; 1323 *src = source;
1214 return 0; 1324 return 0;
1215}; 1325}
1216 1326
1217static int ni_m_gate2_to_generic_gate(unsigned int gate, unsigned int *src) 1327static int ni_m_gate2_to_generic_gate(unsigned int gate, unsigned int *src)
1218{ 1328{
@@ -1222,32 +1332,60 @@ static int ni_m_gate2_to_generic_gate(unsigned int gate, unsigned int *src)
1222 */ 1332 */
1223 *src = gate; 1333 *src = gate;
1224 return 0; 1334 return 0;
1225}; 1335}
1336
1337static inline unsigned int ni_tio_get_gate_mode(struct ni_gpct *counter)
1338{
1339 unsigned int mode = ni_tio_get_soft_copy(
1340 counter, NITIO_MODE_REG(counter->counter_index));
1341 unsigned int ret = 0;
1342
1343 if ((mode & GI_GATING_MODE_MASK) == GI_GATING_DISABLED)
1344 ret |= NI_GPCT_DISABLED_GATE_SELECT;
1345 if (mode & GI_GATE_POL_INVERT)
1346 ret |= CR_INVERT;
1347 if ((mode & GI_GATING_MODE_MASK) != GI_LEVEL_GATING)
1348 ret |= CR_EDGE;
1349
1350 return ret;
1351}
1352
1353static inline unsigned int ni_tio_get_gate2_mode(struct ni_gpct *counter)
1354{
1355 unsigned int mode = ni_tio_get_soft_copy(
1356 counter, NITIO_GATE2_REG(counter->counter_index));
1357 unsigned int ret = 0;
1358
1359 if (!(mode & GI_GATE2_MODE))
1360 ret |= NI_GPCT_DISABLED_GATE_SELECT;
1361 if (mode & GI_GATE2_POL_INVERT)
1362 ret |= CR_INVERT;
1363
1364 return ret;
1365}
1366
1367static inline unsigned int ni_tio_get_gate_val(struct ni_gpct *counter)
1368{
1369 return GI_BITS_TO_GATE(ni_tio_get_soft_copy(counter,
1370 NITIO_INPUT_SEL_REG(counter->counter_index)));
1371}
1372
1373static inline unsigned int ni_tio_get_gate2_val(struct ni_gpct *counter)
1374{
1375 return GI_BITS_TO_GATE2(ni_tio_get_soft_copy(counter,
1376 NITIO_GATE2_REG(counter->counter_index)));
1377}
1226 1378
1227static int ni_tio_get_gate_src(struct ni_gpct *counter, unsigned int gate_index, 1379static int ni_tio_get_gate_src(struct ni_gpct *counter, unsigned int gate_index,
1228 unsigned int *gate_source) 1380 unsigned int *gate_source)
1229{ 1381{
1230 struct ni_gpct_device *counter_dev = counter->counter_dev;
1231 unsigned int cidx = counter->counter_index;
1232 unsigned int mode;
1233 unsigned int reg;
1234 unsigned int gate; 1382 unsigned int gate;
1235 int ret; 1383 int ret;
1236 1384
1237 mode = ni_tio_get_soft_copy(counter, NITIO_MODE_REG(cidx));
1238 if (((mode & GI_GATING_MODE_MASK) == GI_GATING_DISABLED) ||
1239 (gate_index == 1 &&
1240 !(counter_dev->regs[NITIO_GATE2_REG(cidx)] & GI_GATE2_MODE))) {
1241 *gate_source = NI_GPCT_DISABLED_GATE_SELECT;
1242 return 0;
1243 }
1244
1245 switch (gate_index) { 1385 switch (gate_index) {
1246 case 0: 1386 case 0:
1247 reg = NITIO_INPUT_SEL_REG(cidx); 1387 gate = ni_tio_get_gate_val(counter);
1248 gate = GI_BITS_TO_GATE(ni_tio_get_soft_copy(counter, reg)); 1388 switch (counter->counter_dev->variant) {
1249
1250 switch (counter_dev->variant) {
1251 case ni_gpct_variant_e_series: 1389 case ni_gpct_variant_e_series:
1252 case ni_gpct_variant_m_series: 1390 case ni_gpct_variant_m_series:
1253 default: 1391 default:
@@ -1259,16 +1397,11 @@ static int ni_tio_get_gate_src(struct ni_gpct *counter, unsigned int gate_index,
1259 } 1397 }
1260 if (ret) 1398 if (ret)
1261 return ret; 1399 return ret;
1262 if (mode & GI_GATE_POL_INVERT) 1400 *gate_source |= ni_tio_get_gate_mode(counter);
1263 *gate_source |= CR_INVERT;
1264 if ((mode & GI_GATING_MODE_MASK) != GI_LEVEL_GATING)
1265 *gate_source |= CR_EDGE;
1266 break; 1401 break;
1267 case 1: 1402 case 1:
1268 reg = NITIO_GATE2_REG(cidx); 1403 gate = ni_tio_get_gate2_val(counter);
1269 gate = GI_BITS_TO_GATE2(counter_dev->regs[reg]); 1404 switch (counter->counter_dev->variant) {
1270
1271 switch (counter_dev->variant) {
1272 case ni_gpct_variant_e_series: 1405 case ni_gpct_variant_e_series:
1273 case ni_gpct_variant_m_series: 1406 case ni_gpct_variant_m_series:
1274 default: 1407 default:
@@ -1280,11 +1413,26 @@ static int ni_tio_get_gate_src(struct ni_gpct *counter, unsigned int gate_index,
1280 } 1413 }
1281 if (ret) 1414 if (ret)
1282 return ret; 1415 return ret;
1283 if (counter_dev->regs[reg] & GI_GATE2_POL_INVERT) 1416 *gate_source |= ni_tio_get_gate2_mode(counter);
1284 *gate_source |= CR_INVERT; 1417 break;
1285 /* second gate can't have edge/level mode set independently */ 1418 default:
1286 if ((mode & GI_GATING_MODE_MASK) != GI_LEVEL_GATING) 1419 return -EINVAL;
1287 *gate_source |= CR_EDGE; 1420 }
1421 return 0;
1422}
1423
1424static int ni_tio_get_gate_src_raw(struct ni_gpct *counter,
1425 unsigned int gate_index,
1426 unsigned int *gate_source)
1427{
1428 switch (gate_index) {
1429 case 0:
1430 *gate_source = ni_tio_get_gate_mode(counter)
1431 | ni_tio_get_gate_val(counter);
1432 break;
1433 case 1:
1434 *gate_source = ni_tio_get_gate2_mode(counter)
1435 | ni_tio_get_gate2_val(counter);
1288 break; 1436 break;
1289 default: 1437 default:
1290 return -EINVAL; 1438 return -EINVAL;
@@ -1347,6 +1495,107 @@ int ni_tio_insn_config(struct comedi_device *dev,
1347} 1495}
1348EXPORT_SYMBOL_GPL(ni_tio_insn_config); 1496EXPORT_SYMBOL_GPL(ni_tio_insn_config);
1349 1497
1498/**
1499 * Retrieves the register value of the current source of the output selector for
1500 * the given destination.
1501 *
1502 * If the terminal for the destination is not already configured as an output,
1503 * this function returns -EINVAL as error.
1504 *
1505 * Return: the register value of the destination output selector;
1506 * -EINVAL if terminal is not configured for output.
1507 */
1508int ni_tio_get_routing(struct ni_gpct_device *counter_dev, unsigned int dest)
1509{
1510 /* we need to know the actual counter below... */
1511 int ctr_index = (dest - NI_COUNTER_NAMES_BASE) % NI_MAX_COUNTERS;
1512 struct ni_gpct *counter = &counter_dev->counters[ctr_index];
1513 int ret = 1;
1514 unsigned int reg;
1515
1516 if (dest >= NI_CtrA(0) && dest <= NI_CtrZ(-1)) {
1517 ret = ni_tio_get_other_src(counter, dest, &reg);
1518 } else if (dest >= NI_CtrGate(0) && dest <= NI_CtrGate(-1)) {
1519 ret = ni_tio_get_gate_src_raw(counter, 0, &reg);
1520 } else if (dest >= NI_CtrAux(0) && dest <= NI_CtrAux(-1)) {
1521 ret = ni_tio_get_gate_src_raw(counter, 1, &reg);
1522 /*
1523 * This case is not possible through this interface. A user must use
1524 * INSN_CONFIG_SET_CLOCK_SRC instead.
1525 * } else if (dest >= NI_CtrSource(0) && dest <= NI_CtrSource(-1)) {
1526 * ret = ni_tio_set_clock_src(counter, &reg, &period_ns);
1527 */
1528 }
1529
1530 if (ret)
1531 return -EINVAL;
1532
1533 return reg;
1534}
1535EXPORT_SYMBOL_GPL(ni_tio_get_routing);
1536
1537/**
1538 * Sets the register value of the selector MUX for the given destination.
1539 * @counter_dev:Pointer to general counter device.
1540 * @destination:Device-global identifier of route destination.
1541 * @register_value:
1542 * The first several bits of this value should store the desired
1543 * value to write to the register. All other bits are for
1544 * transmitting information that modify the mode of the particular
1545 * destination/gate. These mode bits might include a bitwise or of
1546 * CR_INVERT and CR_EDGE. Note that the calling function should
1547 * have already validated the correctness of this value.
1548 */
1549int ni_tio_set_routing(struct ni_gpct_device *counter_dev, unsigned int dest,
1550 unsigned int reg)
1551{
1552 /* we need to know the actual counter below... */
1553 int ctr_index = (dest - NI_COUNTER_NAMES_BASE) % NI_MAX_COUNTERS;
1554 struct ni_gpct *counter = &counter_dev->counters[ctr_index];
1555 int ret;
1556
1557 if (dest >= NI_CtrA(0) && dest <= NI_CtrZ(-1)) {
1558 ret = ni_tio_set_other_src(counter, dest, reg);
1559 } else if (dest >= NI_CtrGate(0) && dest <= NI_CtrGate(-1)) {
1560 ret = ni_tio_set_gate_src_raw(counter, 0, reg);
1561 } else if (dest >= NI_CtrAux(0) && dest <= NI_CtrAux(-1)) {
1562 ret = ni_tio_set_gate_src_raw(counter, 1, reg);
1563 /*
1564 * This case is not possible through this interface. A user must use
1565 * INSN_CONFIG_SET_CLOCK_SRC instead.
1566 * } else if (dest >= NI_CtrSource(0) && dest <= NI_CtrSource(-1)) {
1567 * ret = ni_tio_set_clock_src(counter, reg, period_ns);
1568 */
1569 } else {
1570 return -EINVAL;
1571 }
1572
1573 return ret;
1574}
1575EXPORT_SYMBOL_GPL(ni_tio_set_routing);
1576
1577/**
1578 * Sets the given destination MUX to its default value or disable it.
1579 *
1580 * Return: 0 if successful; -EINVAL if terminal is unknown.
1581 */
1582int ni_tio_unset_routing(struct ni_gpct_device *counter_dev, unsigned int dest)
1583{
1584 if (dest >= NI_GATES_NAMES_BASE && dest <= NI_GATES_NAMES_MAX)
1585 /* Disable gate (via mode bits) and set to default 0-value */
1586 return ni_tio_set_routing(counter_dev, dest,
1587 NI_GPCT_DISABLED_GATE_SELECT);
1588 /*
1589 * This case is not possible through this interface. A user must use
1590 * INSN_CONFIG_SET_CLOCK_SRC instead.
1591 * if (dest >= NI_CtrSource(0) && dest <= NI_CtrSource(-1))
1592 * return ni_tio_set_clock_src(counter, reg, period_ns);
1593 */
1594
1595 return -EINVAL;
1596}
1597EXPORT_SYMBOL_GPL(ni_tio_unset_routing);
1598
1350static unsigned int ni_tio_read_sw_save_reg(struct comedi_device *dev, 1599static unsigned int ni_tio_read_sw_save_reg(struct comedi_device *dev,
1351 struct comedi_subdevice *s) 1600 struct comedi_subdevice *s)
1352{ 1601{
@@ -1504,13 +1753,15 @@ ni_gpct_device_construct(struct comedi_device *dev,
1504 unsigned int (*read)(struct ni_gpct *counter, 1753 unsigned int (*read)(struct ni_gpct *counter,
1505 enum ni_gpct_register reg), 1754 enum ni_gpct_register reg),
1506 enum ni_gpct_variant variant, 1755 enum ni_gpct_variant variant,
1507 unsigned int num_counters) 1756 unsigned int num_counters,
1757 unsigned int counters_per_chip,
1758 const struct ni_route_tables *routing_tables)
1508{ 1759{
1509 struct ni_gpct_device *counter_dev; 1760 struct ni_gpct_device *counter_dev;
1510 struct ni_gpct *counter; 1761 struct ni_gpct *counter;
1511 unsigned int i; 1762 unsigned int i;
1512 1763
1513 if (num_counters == 0) 1764 if (num_counters == 0 || counters_per_chip == 0)
1514 return NULL; 1765 return NULL;
1515 1766
1516 counter_dev = kzalloc(sizeof(*counter_dev), GFP_KERNEL); 1767 counter_dev = kzalloc(sizeof(*counter_dev), GFP_KERNEL);
@@ -1521,6 +1772,7 @@ ni_gpct_device_construct(struct comedi_device *dev,
1521 counter_dev->write = write; 1772 counter_dev->write = write;
1522 counter_dev->read = read; 1773 counter_dev->read = read;
1523 counter_dev->variant = variant; 1774 counter_dev->variant = variant;
1775 counter_dev->routing_tables = routing_tables;
1524 1776
1525 spin_lock_init(&counter_dev->regs_lock); 1777 spin_lock_init(&counter_dev->regs_lock);
1526 1778
@@ -1534,9 +1786,12 @@ ni_gpct_device_construct(struct comedi_device *dev,
1534 for (i = 0; i < num_counters; ++i) { 1786 for (i = 0; i < num_counters; ++i) {
1535 counter = &counter_dev->counters[i]; 1787 counter = &counter_dev->counters[i];
1536 counter->counter_dev = counter_dev; 1788 counter->counter_dev = counter_dev;
1789 counter->chip_index = i / counters_per_chip;
1790 counter->counter_index = i % counters_per_chip;
1537 spin_lock_init(&counter->lock); 1791 spin_lock_init(&counter->lock);
1538 } 1792 }
1539 counter_dev->num_counters = num_counters; 1793 counter_dev->num_counters = num_counters;
1794 counter_dev->counters_per_chip = counters_per_chip;
1540 1795
1541 return counter_dev; 1796 return counter_dev;
1542} 1797}
diff --git a/drivers/staging/comedi/drivers/ni_tio.h b/drivers/staging/comedi/drivers/ni_tio.h
index 23221cead8ca..340d63c74467 100644
--- a/drivers/staging/comedi/drivers/ni_tio.h
+++ b/drivers/staging/comedi/drivers/ni_tio.h
@@ -107,8 +107,10 @@ struct ni_gpct_device {
107 enum ni_gpct_variant variant; 107 enum ni_gpct_variant variant;
108 struct ni_gpct *counters; 108 struct ni_gpct *counters;
109 unsigned int num_counters; 109 unsigned int num_counters;
110 unsigned int counters_per_chip;
110 unsigned int regs[NITIO_NUM_REGS]; 111 unsigned int regs[NITIO_NUM_REGS];
111 spinlock_t regs_lock; /* protects 'regs' */ 112 spinlock_t regs_lock; /* protects 'regs' */
113 const struct ni_route_tables *routing_tables; /* link to routes */
112}; 114};
113 115
114struct ni_gpct_device * 116struct ni_gpct_device *
@@ -119,7 +121,9 @@ ni_gpct_device_construct(struct comedi_device *dev,
119 unsigned int (*read)(struct ni_gpct *counter, 121 unsigned int (*read)(struct ni_gpct *counter,
120 enum ni_gpct_register), 122 enum ni_gpct_register),
121 enum ni_gpct_variant, 123 enum ni_gpct_variant,
122 unsigned int num_counters); 124 unsigned int num_counters,
125 unsigned int counters_per_chip,
126 const struct ni_route_tables *routing_tables);
123void ni_gpct_device_destroy(struct ni_gpct_device *counter_dev); 127void ni_gpct_device_destroy(struct ni_gpct_device *counter_dev);
124void ni_tio_init_counter(struct ni_gpct *counter); 128void ni_tio_init_counter(struct ni_gpct *counter);
125int ni_tio_insn_read(struct comedi_device *dev, struct comedi_subdevice *s, 129int ni_tio_insn_read(struct comedi_device *dev, struct comedi_subdevice *s,
@@ -138,4 +142,40 @@ void ni_tio_set_mite_channel(struct ni_gpct *counter,
138 struct mite_channel *mite_chan); 142 struct mite_channel *mite_chan);
139void ni_tio_acknowledge(struct ni_gpct *counter); 143void ni_tio_acknowledge(struct ni_gpct *counter);
140 144
145/*
146 * Retrieves the register value of the current source of the output selector for
147 * the given destination.
148 *
149 * If the terminal for the destination is not already configured as an output,
150 * this function returns -EINVAL as error.
151 *
152 * Return: the register value of the destination output selector;
153 * -EINVAL if terminal is not configured for output.
154 */
155int ni_tio_get_routing(struct ni_gpct_device *counter_dev,
156 unsigned int destination);
157
158/*
159 * Sets the register value of the selector MUX for the given destination.
160 * @counter_dev:Pointer to general counter device.
161 * @destination:Device-global identifier of route destination.
162 * @register_value:
163 * The first several bits of this value should store the desired
164 * value to write to the register. All other bits are for
165 * transmitting information that modify the mode of the particular
166 * destination/gate. These mode bits might include a bitwise or of
167 * CR_INVERT and CR_EDGE. Note that the calling function should
168 * have already validated the correctness of this value.
169 */
170int ni_tio_set_routing(struct ni_gpct_device *counter_dev,
171 unsigned int destination, unsigned int register_value);
172
173/*
174 * Sets the given destination MUX to its default value or disable it.
175 *
176 * Return: 0 if successful; -EINVAL if terminal is unknown.
177 */
178int ni_tio_unset_routing(struct ni_gpct_device *counter_dev,
179 unsigned int destination);
180
141#endif /* _COMEDI_NI_TIO_H */ 181#endif /* _COMEDI_NI_TIO_H */
diff --git a/drivers/staging/comedi/drivers/ni_tio_internal.h b/drivers/staging/comedi/drivers/ni_tio_internal.h
index f4d99d78208a..652a28990132 100644
--- a/drivers/staging/comedi/drivers/ni_tio_internal.h
+++ b/drivers/staging/comedi/drivers/ni_tio_internal.h
@@ -170,5 +170,7 @@ unsigned int ni_tio_get_soft_copy(const struct ni_gpct *counter,
170int ni_tio_arm(struct ni_gpct *counter, bool arm, unsigned int start_trigger); 170int ni_tio_arm(struct ni_gpct *counter, bool arm, unsigned int start_trigger);
171int ni_tio_set_gate_src(struct ni_gpct *counter, unsigned int gate, 171int ni_tio_set_gate_src(struct ni_gpct *counter, unsigned int gate,
172 unsigned int src); 172 unsigned int src);
173int ni_tio_set_gate_src_raw(struct ni_gpct *counter, unsigned int gate,
174 unsigned int src);
173 175
174#endif /* _COMEDI_NI_TIO_INTERNAL_H */ 176#endif /* _COMEDI_NI_TIO_INTERNAL_H */
diff --git a/drivers/staging/comedi/drivers/ni_tiocmd.c b/drivers/staging/comedi/drivers/ni_tiocmd.c
index 050bee0b9515..2a9f7e9821a7 100644
--- a/drivers/staging/comedi/drivers/ni_tiocmd.c
+++ b/drivers/staging/comedi/drivers/ni_tiocmd.c
@@ -33,6 +33,7 @@
33#include <linux/module.h> 33#include <linux/module.h>
34#include "ni_tio_internal.h" 34#include "ni_tio_internal.h"
35#include "mite.h" 35#include "mite.h"
36#include "ni_routes.h"
36 37
37static void ni_tio_configure_dma(struct ni_gpct *counter, 38static void ni_tio_configure_dma(struct ni_gpct *counter,
38 bool enable, bool read) 39 bool enable, bool read)
@@ -100,6 +101,8 @@ static int ni_tio_input_cmd(struct comedi_subdevice *s)
100{ 101{
101 struct ni_gpct *counter = s->private; 102 struct ni_gpct *counter = s->private;
102 struct ni_gpct_device *counter_dev = counter->counter_dev; 103 struct ni_gpct_device *counter_dev = counter->counter_dev;
104 const struct ni_route_tables *routing_tables =
105 counter_dev->routing_tables;
103 unsigned int cidx = counter->counter_index; 106 unsigned int cidx = counter->counter_index;
104 struct comedi_async *async = s->async; 107 struct comedi_async *async = s->async;
105 struct comedi_cmd *cmd = &async->cmd; 108 struct comedi_cmd *cmd = &async->cmd;
@@ -128,8 +131,19 @@ static int ni_tio_input_cmd(struct comedi_subdevice *s)
128 131
129 if (cmd->start_src == TRIG_NOW) 132 if (cmd->start_src == TRIG_NOW)
130 ret = ni_tio_arm(counter, true, NI_GPCT_ARM_IMMEDIATE); 133 ret = ni_tio_arm(counter, true, NI_GPCT_ARM_IMMEDIATE);
131 else if (cmd->start_src == TRIG_EXT) 134 else if (cmd->start_src == TRIG_EXT) {
132 ret = ni_tio_arm(counter, true, cmd->start_arg); 135 int reg = CR_CHAN(cmd->start_arg);
136
137 if (reg >= NI_NAMES_BASE) {
138 /* using a device-global name. lookup reg */
139 reg = ni_get_reg_value(reg,
140 NI_CtrArmStartTrigger(cidx),
141 routing_tables);
142 /* mark this as a raw register value */
143 reg |= NI_GPCT_HW_ARM;
144 }
145 ret = ni_tio_arm(counter, true, reg);
146 }
133 } 147 }
134 return ret; 148 return ret;
135} 149}
@@ -148,6 +162,8 @@ static int ni_tio_cmd_setup(struct comedi_subdevice *s)
148 struct comedi_cmd *cmd = &s->async->cmd; 162 struct comedi_cmd *cmd = &s->async->cmd;
149 struct ni_gpct *counter = s->private; 163 struct ni_gpct *counter = s->private;
150 unsigned int cidx = counter->counter_index; 164 unsigned int cidx = counter->counter_index;
165 const struct ni_route_tables *routing_tables =
166 counter->counter_dev->routing_tables;
151 int set_gate_source = 0; 167 int set_gate_source = 0;
152 unsigned int gate_source; 168 unsigned int gate_source;
153 int retval = 0; 169 int retval = 0;
@@ -159,8 +175,24 @@ static int ni_tio_cmd_setup(struct comedi_subdevice *s)
159 set_gate_source = 1; 175 set_gate_source = 1;
160 gate_source = cmd->convert_arg; 176 gate_source = cmd->convert_arg;
161 } 177 }
162 if (set_gate_source) 178 if (set_gate_source) {
163 retval = ni_tio_set_gate_src(counter, 0, gate_source); 179 if (CR_CHAN(gate_source) >= NI_NAMES_BASE) {
180 /* Lookup and use the real register values */
181 int reg = ni_get_reg_value(CR_CHAN(gate_source),
182 NI_CtrGate(cidx),
183 routing_tables);
184 if (reg < 0)
185 return -EINVAL;
186 retval = ni_tio_set_gate_src_raw(counter, 0, reg);
187 } else {
188 /*
189 * This function must be used separately since it does
190 * not expect real register values and attempts to
191 * convert these to real register values.
192 */
193 retval = ni_tio_set_gate_src(counter, 0, gate_source);
194 }
195 }
164 if (cmd->flags & CMDF_WAKE_EOS) { 196 if (cmd->flags & CMDF_WAKE_EOS) {
165 ni_tio_set_bits(counter, NITIO_INT_ENA_REG(cidx), 197 ni_tio_set_bits(counter, NITIO_INT_ENA_REG(cidx),
166 GI_GATE_INTERRUPT_ENABLE(cidx), 198 GI_GATE_INTERRUPT_ENABLE(cidx),
@@ -203,6 +235,9 @@ int ni_tio_cmdtest(struct comedi_device *dev,
203 struct comedi_cmd *cmd) 235 struct comedi_cmd *cmd)
204{ 236{
205 struct ni_gpct *counter = s->private; 237 struct ni_gpct *counter = s->private;
238 unsigned int cidx = counter->counter_index;
239 const struct ni_route_tables *routing_tables =
240 counter->counter_dev->routing_tables;
206 int err = 0; 241 int err = 0;
207 unsigned int sources; 242 unsigned int sources;
208 243
@@ -247,14 +282,37 @@ int ni_tio_cmdtest(struct comedi_device *dev,
247 break; 282 break;
248 case TRIG_EXT: 283 case TRIG_EXT:
249 /* start_arg is the start_trigger passed to ni_tio_arm() */ 284 /* start_arg is the start_trigger passed to ni_tio_arm() */
285 /*
286 * This should be done, but we don't yet know the actual
287 * register values. These should be tested and then documented
288 * in the ni_route_values/ni_*.csv files, with indication of
289 * who/when/which/how these these were tested.
290 * When at least a e/m/660x series have been tested, this code
291 * should be uncommented:
292 *
293 * err |= ni_check_trigger_arg(CR_CHAN(cmd->start_arg),
294 * NI_CtrArmStartTrigger(cidx),
295 * routing_tables);
296 */
250 break; 297 break;
251 } 298 }
252 299
300 /*
301 * It seems that convention is to allow either scan_begin_arg or
302 * convert_arg to specify the Gate source, with scan_begin_arg taking
303 * precedence.
304 */
253 if (cmd->scan_begin_src != TRIG_EXT) 305 if (cmd->scan_begin_src != TRIG_EXT)
254 err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, 0); 306 err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
307 else
308 err |= ni_check_trigger_arg(CR_CHAN(cmd->scan_begin_arg),
309 NI_CtrGate(cidx), routing_tables);
255 310
256 if (cmd->convert_src != TRIG_EXT) 311 if (cmd->convert_src != TRIG_EXT)
257 err |= comedi_check_trigger_arg_is(&cmd->convert_arg, 0); 312 err |= comedi_check_trigger_arg_is(&cmd->convert_arg, 0);
313 else
314 err |= ni_check_trigger_arg(CR_CHAN(cmd->convert_arg),
315 NI_CtrGate(cidx), routing_tables);
258 316
259 err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg, 317 err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg,
260 cmd->chanlist_len); 318 cmd->chanlist_len);
diff --git a/drivers/staging/comedi/drivers/tests/Makefile b/drivers/staging/comedi/drivers/tests/Makefile
new file mode 100644
index 000000000000..b5d8e13d4162
--- /dev/null
+++ b/drivers/staging/comedi/drivers/tests/Makefile
@@ -0,0 +1,7 @@
1# SPDX-License-Identifier: GPL-2.0
2# Makefile for comedi drivers unit tests
3#
4ccflags-$(CONFIG_COMEDI_DEBUG) := -DDEBUG
5
6obj-$(CONFIG_COMEDI_TESTS) += example_test.o ni_routes_test.o
7CFLAGS_ni_routes_test.o := -DDEBUG
diff --git a/drivers/staging/comedi/drivers/tests/example_test.c b/drivers/staging/comedi/drivers/tests/example_test.c
new file mode 100644
index 000000000000..fc65158b8e8e
--- /dev/null
+++ b/drivers/staging/comedi/drivers/tests/example_test.c
@@ -0,0 +1,72 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/tests/example_test.c
5 * Example set of unit tests.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21#include <linux/module.h>
22
23#include "unittest.h"
24
25/* *** BEGIN fake board data *** */
26struct comedi_device {
27 const char *board_name;
28 int item;
29};
30
31static struct comedi_device dev = {
32 .board_name = "fake_device",
33};
34
35/* *** END fake board data *** */
36
37/* *** BEGIN fake data init *** */
38void init_fake(void)
39{
40 dev.item = 10;
41}
42
43/* *** END fake data init *** */
44
45void test0(void)
46{
47 init_fake();
48 unittest(dev.item != 11, "negative result\n");
49 unittest(dev.item == 10, "positive result\n");
50}
51
52/* **** BEGIN simple module entry/exit functions **** */
53static int __init unittest_enter(void)
54{
55 const unittest_fptr unit_tests[] = {
56 (unittest_fptr)test0,
57 NULL,
58 };
59
60 exec_unittests("example", unit_tests);
61 return 0;
62}
63
64static void __exit unittest_exit(void) { }
65
66module_init(unittest_enter);
67module_exit(unittest_exit);
68
69MODULE_AUTHOR("Spencer Olson <olsonse@umich.edu>");
70MODULE_DESCRIPTION("Comedi unit-tests example");
71MODULE_LICENSE("GPL");
72/* **** END simple module entry/exit functions **** */
diff --git a/drivers/staging/comedi/drivers/tests/ni_routes_test.c b/drivers/staging/comedi/drivers/tests/ni_routes_test.c
new file mode 100644
index 000000000000..a1eda035f270
--- /dev/null
+++ b/drivers/staging/comedi/drivers/tests/ni_routes_test.c
@@ -0,0 +1,613 @@
1// SPDX-License-Identifier: GPL-2.0+
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/tests/ni_routes_test.c
5 * Unit tests for NI routes (ni_routes.c module).
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21#include <linux/module.h>
22
23#include "../ni_stc.h"
24#include "../ni_routes.h"
25#include "unittest.h"
26
27#define RVi(table, src, dest) ((table)[(dest) * NI_NUM_NAMES + (src)])
28#define O(x) ((x) + NI_NAMES_BASE)
29#define B(x) ((x) - NI_NAMES_BASE)
30#define V(x) ((x) | 0x80)
31
32/* *** BEGIN fake board data *** */
33static const char *pci_6070e = "pci-6070e";
34static const char *pci_6220 = "pci-6220";
35static const char *pci_fake = "pci-fake";
36
37static const char *ni_eseries = "ni_eseries";
38static const char *ni_mseries = "ni_mseries";
39
40static struct ni_board_struct board = {
41 .name = NULL,
42};
43
44static struct ni_private private = {
45 .is_m_series = 0,
46};
47
48static const int bad_dest = O(8), dest0 = O(0), desti = O(5);
49static const int ith_dest_index = 2;
50static const int no_val_dest = O(7), no_val_index = 4;
51
52/* These have to be defs to be used in init code below */
53#define rgout0_src0 (O(100))
54#define rgout0_src1 (O(101))
55#define brd0_src0 (O(110))
56#define brd0_src1 (O(111))
57#define brd1_src0 (O(120))
58#define brd1_src1 (O(121))
59#define brd2_src0 (O(130))
60#define brd2_src1 (O(131))
61#define brd3_src0 (O(140))
62#define brd3_src1 (O(141))
63
64/* I1 and I2 should not call O(...). Mostly here to shut checkpatch.pl up */
65#define I1(x1) \
66 (int[]){ \
67 x1, 0 \
68 }
69#define I2(x1, x2) \
70 (int[]){ \
71 (x1), (x2), 0 \
72 }
73#define I3(x1, x2, x3) \
74 (int[]){ \
75 (x1), (x2), (x3), 0 \
76 }
77
78/* O9 is build to call O(...) for each arg */
79#define O9(x1, x2, x3, x4, x5, x6, x7, x8, x9) \
80 (int[]){ \
81 O(x1), O(x2), O(x3), O(x4), O(x5), O(x6), O(x7), O(x8), O(x9), \
82 0 \
83 }
84
85static struct ni_device_routes DR = {
86 .device = "testdev",
87 .routes = (struct ni_route_set[]){
88 {.dest = O(0), .src = O9(/**/1, 2, 3, 4, 5, 6, 7, 8, 9)},
89 {.dest = O(1), .src = O9(0, /**/2, 3, 4, 5, 6, 7, 8, 9)},
90 /* ith route_set */
91 {.dest = O(5), .src = O9(0, 1, 2, 3, 4,/**/ 6, 7, 8, 9)},
92 {.dest = O(6), .src = O9(0, 1, 2, 3, 4, 5,/**/ 7, 8, 9)},
93 /* next one will not have valid reg values */
94 {.dest = O(7), .src = O9(0, 1, 2, 3, 4, 5, 6,/**/ 8, 9)},
95 {.dest = O(9), .src = O9(0, 1, 2, 3, 4, 5, 6, 7, 8/**/)},
96
97 /* indirect routes done through muxes */
98 {.dest = TRIGGER_LINE(0), .src = I1(rgout0_src0)},
99 {.dest = TRIGGER_LINE(1), .src = I3(rgout0_src0,
100 brd3_src0,
101 brd3_src1)},
102 {.dest = TRIGGER_LINE(2), .src = I3(rgout0_src1,
103 brd2_src0,
104 brd2_src1)},
105 {.dest = TRIGGER_LINE(3), .src = I3(rgout0_src1,
106 brd1_src0,
107 brd1_src1)},
108 {.dest = TRIGGER_LINE(4), .src = I2(brd0_src0,
109 brd0_src1)},
110 {.dest = 0},
111 },
112};
113
114#undef I1
115#undef I2
116#undef O9
117
118#define RV9(x1, x2, x3, x4, x5, x6, x7, x8, x9) \
119 [x1] = V(x1), [x2] = V(x2), [x3] = V(x3), [x4] = V(x4), \
120 [x5] = V(x5), [x6] = V(x6), [x7] = V(x7), [x8] = V(x8), \
121 [x9] = V(x9),
122
123/* This table is indexed as RV[destination][source] */
124static const u8 RV[NI_NUM_NAMES][NI_NUM_NAMES] = {
125 [0] = {RV9(/**/1, 2, 3, 4, 5, 6, 7, 8, 9)},
126 [1] = {RV9(0,/**/ 2, 3, 4, 5, 6, 7, 8, 9)},
127 [2] = {RV9(0, 1,/**/3, 4, 5, 6, 7, 8, 9)},
128 [3] = {RV9(0, 1, 2,/**/4, 5, 6, 7, 8, 9)},
129 [4] = {RV9(0, 1, 2, 3,/**/5, 6, 7, 8, 9)},
130 [5] = {RV9(0, 1, 2, 3, 4,/**/6, 7, 8, 9)},
131 [6] = {RV9(0, 1, 2, 3, 4, 5,/**/7, 8, 9)},
132 /* [7] is intentionaly left absent to test invalid routes */
133 [8] = {RV9(0, 1, 2, 3, 4, 5, 6, 7,/**/9)},
134 [9] = {RV9(0, 1, 2, 3, 4, 5, 6, 7, 8/**/)},
135 /* some tests for needing extra muxes */
136 [B(NI_RGOUT0)] = {[B(rgout0_src0)] = V(0),
137 [B(rgout0_src1)] = V(1)},
138 [B(NI_RTSI_BRD(0))] = {[B(brd0_src0)] = V(0),
139 [B(brd0_src1)] = V(1)},
140 [B(NI_RTSI_BRD(1))] = {[B(brd1_src0)] = V(0),
141 [B(brd1_src1)] = V(1)},
142 [B(NI_RTSI_BRD(2))] = {[B(brd2_src0)] = V(0),
143 [B(brd2_src1)] = V(1)},
144 [B(NI_RTSI_BRD(3))] = {[B(brd3_src0)] = V(0),
145 [B(brd3_src1)] = V(1)},
146};
147
148#undef RV9
149
150/* *** END fake board data *** */
151
152/* *** BEGIN board data initializers *** */
153static void init_private(void)
154{
155 memset(&private, 0, sizeof(struct ni_private));
156}
157
158static void init_pci_6070e(void)
159{
160 board.name = pci_6070e;
161 init_private();
162 private.is_m_series = 0;
163}
164
165static void init_pci_6220(void)
166{
167 board.name = pci_6220;
168 init_private();
169 private.is_m_series = 1;
170}
171
172static void init_pci_fake(void)
173{
174 board.name = pci_fake;
175 init_private();
176 private.routing_tables.route_values = &RV[0][0];
177 private.routing_tables.valid_routes = &DR;
178}
179
180/* *** END board data initializers *** */
181
182/* Tests that route_sets are in order of the signal destination. */
183static bool route_set_dests_in_order(const struct ni_device_routes *devroutes)
184{
185 int i;
186 int last = NI_NAMES_BASE - 1;
187
188 for (i = 0; i < devroutes->n_route_sets; ++i) {
189 if (last >= devroutes->routes[i].dest)
190 return false;
191 last = devroutes->routes[i].dest;
192 }
193 return true;
194}
195
196/* Tests that all route_set->src are in order of the signal source. */
197bool route_set_sources_in_order(const struct ni_device_routes *devroutes)
198{
199 int i;
200
201 for (i = 0; i < devroutes->n_route_sets; ++i) {
202 int j;
203 int last = NI_NAMES_BASE - 1;
204
205 for (j = 0; j < devroutes->routes[i].n_src; ++j) {
206 if (last >= devroutes->routes[i].src[j])
207 return false;
208 last = devroutes->routes[i].src[j];
209 }
210 }
211 return true;
212}
213
214void test_ni_assign_device_routes(void)
215{
216 const struct ni_device_routes *devroutes, *olddevroutes;
217 const u8 *table, *oldtable;
218
219 init_pci_6070e();
220 ni_assign_device_routes(ni_eseries, pci_6070e, &private.routing_tables);
221 devroutes = private.routing_tables.valid_routes;
222 table = private.routing_tables.route_values;
223
224 unittest(strncmp(devroutes->device, pci_6070e, 10) == 0,
225 "find device pci-6070e\n");
226 unittest(devroutes->n_route_sets == 37,
227 "number of pci-6070e route_sets == 37\n");
228 unittest(devroutes->routes->dest == NI_PFI(0),
229 "first pci-6070e route_set is for NI_PFI(0)\n");
230 unittest(devroutes->routes->n_src == 1,
231 "first pci-6070e route_set length == 1\n");
232 unittest(devroutes->routes->src[0] == NI_AI_StartTrigger,
233 "first pci-6070e route_set src. == NI_AI_StartTrigger\n");
234 unittest(devroutes->routes[10].dest == TRIGGER_LINE(0),
235 "10th pci-6070e route_set is for TRIGGER_LINE(0)\n");
236 unittest(devroutes->routes[10].n_src == 10,
237 "10th pci-6070e route_set length == 10\n");
238 unittest(devroutes->routes[10].src[0] == NI_CtrSource(0),
239 "10th pci-6070e route_set src. == NI_CtrSource(0)\n");
240 unittest(route_set_dests_in_order(devroutes),
241 "all pci-6070e route_sets in order of signal destination\n");
242 unittest(route_set_sources_in_order(devroutes),
243 "all pci-6070e route_set->src's in order of signal source\n");
244
245 unittest(
246 RVi(table, B(PXI_Star), B(NI_AI_SampleClock)) == V(17) &&
247 RVi(table, B(NI_10MHzRefClock), B(TRIGGER_LINE(0))) == 0 &&
248 RVi(table, B(NI_AI_ConvertClock), B(NI_PFI(0))) == 0 &&
249 RVi(table, B(NI_AI_ConvertClock), B(NI_PFI(2))) ==
250 V(NI_PFI_OUTPUT_AI_CONVERT),
251 "pci-6070e finds e-series route_values table\n");
252
253 olddevroutes = devroutes;
254 oldtable = table;
255 init_pci_6220();
256 ni_assign_device_routes(ni_mseries, pci_6220, &private.routing_tables);
257 devroutes = private.routing_tables.valid_routes;
258 table = private.routing_tables.route_values;
259
260 unittest(strncmp(devroutes->device, pci_6220, 10) == 0,
261 "find device pci-6220\n");
262 unittest(oldtable != table, "pci-6220 find other route_values table\n");
263
264 unittest(
265 RVi(table, B(PXI_Star), B(NI_AI_SampleClock)) == V(20) &&
266 RVi(table, B(NI_10MHzRefClock), B(TRIGGER_LINE(0))) == V(12) &&
267 RVi(table, B(NI_AI_ConvertClock), B(NI_PFI(0))) == V(3) &&
268 RVi(table, B(NI_AI_ConvertClock), B(NI_PFI(2))) == V(3),
269 "pci-6220 finds m-series route_values table\n");
270}
271
272void test_ni_sort_device_routes(void)
273{
274 /* We begin by sorting the device routes for use in later tests */
275 ni_sort_device_routes(&DR);
276 /* now we test that sorting. */
277 unittest(route_set_dests_in_order(&DR),
278 "all route_sets of fake data in order of sig. destination\n");
279 unittest(route_set_sources_in_order(&DR),
280 "all route_set->src's of fake data in order of sig. source\n");
281}
282
283void test_ni_find_route_set(void)
284{
285 unittest(ni_find_route_set(bad_dest, &DR) == NULL,
286 "check for nonexistent route_set\n");
287 unittest(ni_find_route_set(dest0, &DR) == &DR.routes[0],
288 "find first route_set\n");
289 unittest(ni_find_route_set(desti, &DR) == &DR.routes[ith_dest_index],
290 "find ith route_set\n");
291 unittest(ni_find_route_set(no_val_dest, &DR) ==
292 &DR.routes[no_val_index],
293 "find no_val route_set in spite of missing values\n");
294 unittest(ni_find_route_set(DR.routes[DR.n_route_sets - 1].dest, &DR) ==
295 &DR.routes[DR.n_route_sets - 1],
296 "find last route_set\n");
297}
298
299void test_ni_route_set_has_source(void)
300{
301 unittest(!ni_route_set_has_source(&DR.routes[0], O(0)),
302 "check for bad source\n");
303 unittest(ni_route_set_has_source(&DR.routes[0], O(1)),
304 "find first source\n");
305 unittest(ni_route_set_has_source(&DR.routes[0], O(5)),
306 "find fifth source\n");
307 unittest(ni_route_set_has_source(&DR.routes[0], O(9)),
308 "find last source\n");
309}
310
311void test_ni_route_to_register(void)
312{
313 const struct ni_route_tables *T = &private.routing_tables;
314
315 init_pci_fake();
316 unittest(ni_route_to_register(O(0), O(0), T) < 0,
317 "check for bad route 0-->0\n");
318 unittest(ni_route_to_register(O(1), O(0), T) == 1,
319 "validate first destination\n");
320 unittest(ni_route_to_register(O(6), O(5), T) == 6,
321 "validate middle destination\n");
322 unittest(ni_route_to_register(O(8), O(9), T) == 8,
323 "validate last destination\n");
324
325 /* choice of trigger line in the following is somewhat random */
326 unittest(ni_route_to_register(rgout0_src0, TRIGGER_LINE(0), T) == 0,
327 "validate indirect route through rgout0 to TRIGGER_LINE(0)\n");
328 unittest(ni_route_to_register(rgout0_src0, TRIGGER_LINE(1), T) == 0,
329 "validate indirect route through rgout0 to TRIGGER_LINE(1)\n");
330 unittest(ni_route_to_register(rgout0_src1, TRIGGER_LINE(2), T) == 1,
331 "validate indirect route through rgout0 to TRIGGER_LINE(2)\n");
332 unittest(ni_route_to_register(rgout0_src1, TRIGGER_LINE(3), T) == 1,
333 "validate indirect route through rgout0 to TRIGGER_LINE(3)\n");
334
335 unittest(ni_route_to_register(brd0_src0, TRIGGER_LINE(4), T) ==
336 BIT(6),
337 "validate indirect route through brd0 to TRIGGER_LINE(4)\n");
338 unittest(ni_route_to_register(brd0_src1, TRIGGER_LINE(4), T) ==
339 BIT(6),
340 "validate indirect route through brd0 to TRIGGER_LINE(4)\n");
341 unittest(ni_route_to_register(brd1_src0, TRIGGER_LINE(3), T) ==
342 BIT(6),
343 "validate indirect route through brd1 to TRIGGER_LINE(3)\n");
344 unittest(ni_route_to_register(brd1_src1, TRIGGER_LINE(3), T) ==
345 BIT(6),
346 "validate indirect route through brd1 to TRIGGER_LINE(3)\n");
347 unittest(ni_route_to_register(brd2_src0, TRIGGER_LINE(2), T) ==
348 BIT(6),
349 "validate indirect route through brd2 to TRIGGER_LINE(2)\n");
350 unittest(ni_route_to_register(brd2_src1, TRIGGER_LINE(2), T) ==
351 BIT(6),
352 "validate indirect route through brd2 to TRIGGER_LINE(2)\n");
353 unittest(ni_route_to_register(brd3_src0, TRIGGER_LINE(1), T) ==
354 BIT(6),
355 "validate indirect route through brd3 to TRIGGER_LINE(1)\n");
356 unittest(ni_route_to_register(brd3_src1, TRIGGER_LINE(1), T) ==
357 BIT(6),
358 "validate indirect route through brd3 to TRIGGER_LINE(1)\n");
359}
360
361void test_ni_lookup_route_register(void)
362{
363 const struct ni_route_tables *T = &private.routing_tables;
364
365 init_pci_fake();
366 unittest(ni_lookup_route_register(O(0), O(0), T) == -EINVAL,
367 "check for bad route 0-->0\n");
368 unittest(ni_lookup_route_register(O(1), O(0), T) == 1,
369 "validate first destination\n");
370 unittest(ni_lookup_route_register(O(6), O(5), T) == 6,
371 "validate middle destination\n");
372 unittest(ni_lookup_route_register(O(8), O(9), T) == 8,
373 "validate last destination\n");
374 unittest(ni_lookup_route_register(O(10), O(9), T) == -EINVAL,
375 "lookup invalid desination\n");
376
377 unittest(ni_lookup_route_register(rgout0_src0, TRIGGER_LINE(0), T) ==
378 -EINVAL,
379 "rgout0_src0: no direct lookup of indirect route\n");
380 unittest(ni_lookup_route_register(rgout0_src0, NI_RGOUT0, T) == 0,
381 "rgout0_src0: lookup indirect route register\n");
382 unittest(ni_lookup_route_register(rgout0_src1, TRIGGER_LINE(2), T) ==
383 -EINVAL,
384 "rgout0_src1: no direct lookup of indirect route\n");
385 unittest(ni_lookup_route_register(rgout0_src1, NI_RGOUT0, T) == 1,
386 "rgout0_src1: lookup indirect route register\n");
387
388 unittest(ni_lookup_route_register(brd0_src0, TRIGGER_LINE(4), T) ==
389 -EINVAL,
390 "brd0_src0: no direct lookup of indirect route\n");
391 unittest(ni_lookup_route_register(brd0_src0, NI_RTSI_BRD(0), T) == 0,
392 "brd0_src0: lookup indirect route register\n");
393 unittest(ni_lookup_route_register(brd0_src1, TRIGGER_LINE(4), T) ==
394 -EINVAL,
395 "brd0_src1: no direct lookup of indirect route\n");
396 unittest(ni_lookup_route_register(brd0_src1, NI_RTSI_BRD(0), T) == 1,
397 "brd0_src1: lookup indirect route register\n");
398}
399
400void test_route_is_valid(void)
401{
402 const struct ni_route_tables *T = &private.routing_tables;
403
404 init_pci_fake();
405 unittest(!route_is_valid(O(0), O(0), T),
406 "check for bad route 0-->0\n");
407 unittest(route_is_valid(O(0), O(1), T),
408 "validate first destination\n");
409 unittest(route_is_valid(O(5), O(6), T),
410 "validate middle destination\n");
411 unittest(route_is_valid(O(8), O(9), T),
412 "validate last destination\n");
413}
414
415void test_ni_is_cmd_dest(void)
416{
417 init_pci_fake();
418 unittest(ni_is_cmd_dest(NI_AI_SampleClock),
419 "check that AI/SampleClock is cmd destination\n");
420 unittest(ni_is_cmd_dest(NI_AI_StartTrigger),
421 "check that AI/StartTrigger is cmd destination\n");
422 unittest(ni_is_cmd_dest(NI_AI_ConvertClock),
423 "check that AI/ConvertClock is cmd destination\n");
424 unittest(ni_is_cmd_dest(NI_AO_SampleClock),
425 "check that AO/SampleClock is cmd destination\n");
426 unittest(ni_is_cmd_dest(NI_DO_SampleClock),
427 "check that DO/SampleClock is cmd destination\n");
428 unittest(!ni_is_cmd_dest(NI_AO_SampleClockTimebase),
429 "check that AO/SampleClockTimebase _not_ cmd destination\n");
430}
431
432void test_channel_is_pfi(void)
433{
434 init_pci_fake();
435 unittest(channel_is_pfi(NI_PFI(0)), "check First pfi channel\n");
436 unittest(channel_is_pfi(NI_PFI(10)), "check 10th pfi channel\n");
437 unittest(channel_is_pfi(NI_PFI(-1)), "check last pfi channel\n");
438 unittest(!channel_is_pfi(NI_PFI(-1) + 1),
439 "check first non pfi channel\n");
440}
441
442void test_channel_is_rtsi(void)
443{
444 init_pci_fake();
445 unittest(channel_is_rtsi(TRIGGER_LINE(0)),
446 "check First rtsi channel\n");
447 unittest(channel_is_rtsi(TRIGGER_LINE(3)),
448 "check 3rd rtsi channel\n");
449 unittest(channel_is_rtsi(TRIGGER_LINE(-1)),
450 "check last rtsi channel\n");
451 unittest(!channel_is_rtsi(TRIGGER_LINE(-1) + 1),
452 "check first non rtsi channel\n");
453}
454
455void test_ni_count_valid_routes(void)
456{
457 const struct ni_route_tables *T = &private.routing_tables;
458
459 init_pci_fake();
460 unittest(ni_count_valid_routes(T) == 57, "count all valid routes\n");
461}
462
463void test_ni_get_valid_routes(void)
464{
465 const struct ni_route_tables *T = &private.routing_tables;
466 unsigned int pair_data[2];
467
468 init_pci_fake();
469 unittest(ni_get_valid_routes(T, 0, NULL) == 57,
470 "count all valid routes through ni_get_valid_routes\n");
471
472 unittest(ni_get_valid_routes(T, 1, pair_data) == 1,
473 "copied first valid route from ni_get_valid_routes\n");
474 unittest(pair_data[0] == O(1),
475 "source of first valid pair from ni_get_valid_routes\n");
476 unittest(pair_data[1] == O(0),
477 "destination of first valid pair from ni_get_valid_routes\n");
478}
479
480void test_ni_find_route_source(void)
481{
482 const struct ni_route_tables *T = &private.routing_tables;
483
484 init_pci_fake();
485 unittest(ni_find_route_source(4, O(4), T) == -EINVAL,
486 "check for bad source 4-->4\n");
487 unittest(ni_find_route_source(0, O(1), T) == O(0),
488 "find first source\n");
489 unittest(ni_find_route_source(4, O(6), T) == O(4),
490 "find middle source\n");
491 unittest(ni_find_route_source(9, O(8), T) == O(9),
492 "find last source");
493 unittest(ni_find_route_source(8, O(9), T) == O(8),
494 "find invalid source (without checking device routes)\n");
495}
496
497void test_route_register_is_valid(void)
498{
499 const struct ni_route_tables *T = &private.routing_tables;
500
501 init_pci_fake();
502 unittest(route_register_is_valid(4, O(4), T) == false,
503 "check for bad source 4-->4\n");
504 unittest(route_register_is_valid(0, O(1), T) == true,
505 "find first source\n");
506 unittest(route_register_is_valid(4, O(6), T) == true,
507 "find middle source\n");
508 unittest(route_register_is_valid(9, O(8), T) == true,
509 "find last source");
510}
511
512void test_ni_check_trigger_arg(void)
513{
514 const struct ni_route_tables *T = &private.routing_tables;
515
516 init_pci_fake();
517 unittest(ni_check_trigger_arg(0, O(0), T) == -EINVAL,
518 "check bad direct trigger arg for first reg->dest\n");
519 unittest(ni_check_trigger_arg(0, O(1), T) == 0,
520 "check direct trigger arg for first reg->dest\n");
521 unittest(ni_check_trigger_arg(4, O(6), T) == 0,
522 "check direct trigger arg for middle reg->dest\n");
523 unittest(ni_check_trigger_arg(9, O(8), T) == 0,
524 "check direct trigger arg for last reg->dest\n");
525
526 unittest(ni_check_trigger_arg_roffs(-1, O(0), T, 1) == -EINVAL,
527 "check bad direct trigger arg for first reg->dest w/offs\n");
528 unittest(ni_check_trigger_arg_roffs(0, O(1), T, 0) == 0,
529 "check direct trigger arg for first reg->dest w/offs\n");
530 unittest(ni_check_trigger_arg_roffs(3, O(6), T, 1) == 0,
531 "check direct trigger arg for middle reg->dest w/offs\n");
532 unittest(ni_check_trigger_arg_roffs(7, O(8), T, 2) == 0,
533 "check direct trigger arg for last reg->dest w/offs\n");
534
535 unittest(ni_check_trigger_arg(O(0), O(0), T) == -EINVAL,
536 "check bad trigger arg for first src->dest\n");
537 unittest(ni_check_trigger_arg(O(0), O(1), T) == 0,
538 "check trigger arg for first src->dest\n");
539 unittest(ni_check_trigger_arg(O(5), O(6), T) == 0,
540 "check trigger arg for middle src->dest\n");
541 unittest(ni_check_trigger_arg(O(8), O(9), T) == 0,
542 "check trigger arg for last src->dest\n");
543}
544
545void test_ni_get_reg_value(void)
546{
547 const struct ni_route_tables *T = &private.routing_tables;
548
549 init_pci_fake();
550 unittest(ni_get_reg_value(0, O(0), T) == -1,
551 "check bad direct trigger arg for first reg->dest\n");
552 unittest(ni_get_reg_value(0, O(1), T) == 0,
553 "check direct trigger arg for first reg->dest\n");
554 unittest(ni_get_reg_value(4, O(6), T) == 4,
555 "check direct trigger arg for middle reg->dest\n");
556 unittest(ni_get_reg_value(9, O(8), T) == 9,
557 "check direct trigger arg for last reg->dest\n");
558
559 unittest(ni_get_reg_value_roffs(-1, O(0), T, 1) == -1,
560 "check bad direct trigger arg for first reg->dest w/offs\n");
561 unittest(ni_get_reg_value_roffs(0, O(1), T, 0) == 0,
562 "check direct trigger arg for first reg->dest w/offs\n");
563 unittest(ni_get_reg_value_roffs(3, O(6), T, 1) == 4,
564 "check direct trigger arg for middle reg->dest w/offs\n");
565 unittest(ni_get_reg_value_roffs(7, O(8), T, 2) == 9,
566 "check direct trigger arg for last reg->dest w/offs\n");
567
568 unittest(ni_get_reg_value(O(0), O(0), T) == -1,
569 "check bad trigger arg for first src->dest\n");
570 unittest(ni_get_reg_value(O(0), O(1), T) == 0,
571 "check trigger arg for first src->dest\n");
572 unittest(ni_get_reg_value(O(5), O(6), T) == 5,
573 "check trigger arg for middle src->dest\n");
574 unittest(ni_get_reg_value(O(8), O(9), T) == 8,
575 "check trigger arg for last src->dest\n");
576}
577
578/* **** BEGIN simple module entry/exit functions **** */
579static int __init ni_routes_unittest(void)
580{
581 const unittest_fptr unit_tests[] = {
582 (unittest_fptr)test_ni_assign_device_routes,
583 (unittest_fptr)test_ni_sort_device_routes,
584 (unittest_fptr)test_ni_find_route_set,
585 (unittest_fptr)test_ni_route_set_has_source,
586 (unittest_fptr)test_ni_route_to_register,
587 (unittest_fptr)test_ni_lookup_route_register,
588 (unittest_fptr)test_route_is_valid,
589 (unittest_fptr)test_ni_is_cmd_dest,
590 (unittest_fptr)test_channel_is_pfi,
591 (unittest_fptr)test_channel_is_rtsi,
592 (unittest_fptr)test_ni_count_valid_routes,
593 (unittest_fptr)test_ni_get_valid_routes,
594 (unittest_fptr)test_ni_find_route_source,
595 (unittest_fptr)test_route_register_is_valid,
596 (unittest_fptr)test_ni_check_trigger_arg,
597 (unittest_fptr)test_ni_get_reg_value,
598 NULL,
599 };
600
601 exec_unittests("ni_routes", unit_tests);
602 return 0;
603}
604
605static void __exit ni_routes_unittest_exit(void) { }
606
607module_init(ni_routes_unittest);
608module_exit(ni_routes_unittest_exit);
609
610MODULE_AUTHOR("Comedi http://www.comedi.org");
611MODULE_DESCRIPTION("Comedi unit-tests for ni_routes module");
612MODULE_LICENSE("GPL");
613/* **** END simple module entry/exit functions **** */
diff --git a/drivers/staging/comedi/drivers/tests/unittest.h b/drivers/staging/comedi/drivers/tests/unittest.h
new file mode 100644
index 000000000000..b8e622ea1de1
--- /dev/null
+++ b/drivers/staging/comedi/drivers/tests/unittest.h
@@ -0,0 +1,63 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
2/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
3/*
4 * comedi/drivers/tests/unittest.h
5 * Simple framework for unittests for comedi drivers.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2016 Spencer E. Olson <olsonse@umich.edu>
9 * based of parts of drivers/of/unittest.c
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 */
21
22#ifndef _COMEDI_DRIVERS_TESTS_UNITTEST_H
23#define _COMEDI_DRIVERS_TESTS_UNITTEST_H
24
25static struct unittest_results {
26 int passed;
27 int failed;
28} unittest_results;
29
30typedef void *(*unittest_fptr)(void);
31
32#define unittest(result, fmt, ...) ({ \
33 bool failed = !(result); \
34 if (failed) { \
35 ++unittest_results.failed; \
36 pr_err("FAIL %s():%i " fmt, __func__, __LINE__, \
37 ##__VA_ARGS__); \
38 } else { \
39 ++unittest_results.passed; \
40 pr_debug("pass %s():%i " fmt, __func__, __LINE__, \
41 ##__VA_ARGS__); \
42 } \
43 failed; \
44})
45
46/**
47 * Execute an array of unit tests.
48 * @name: Name of set of unit tests--will be shown at INFO log level.
49 * @unit_tests: A null-terminated list of unit tests to execute.
50 */
51static inline void exec_unittests(const char *name,
52 const unittest_fptr *unit_tests)
53{
54 pr_info("begin comedi:\"%s\" unittests\n", name);
55
56 for (; (*unit_tests) != NULL; ++unit_tests)
57 (*unit_tests)();
58
59 pr_info("end of comedi:\"%s\" unittests - %i passed, %i failed\n", name,
60 unittest_results.passed, unittest_results.failed);
61}
62
63#endif /* _COMEDI_DRIVERS_TESTS_UNITTEST_H */
diff --git a/drivers/staging/dgnc/Kconfig b/drivers/staging/dgnc/Kconfig
deleted file mode 100644
index 032c2a795238..000000000000
--- a/drivers/staging/dgnc/Kconfig
+++ /dev/null
@@ -1,6 +0,0 @@
1config DGNC
2 tristate "Digi Neo and Classic PCI Products"
3 default n
4 depends on TTY && PCI
5 ---help---
6 Driver for the Digi International Neo and Classic PCI based product line.
diff --git a/drivers/staging/dgnc/Makefile b/drivers/staging/dgnc/Makefile
deleted file mode 100644
index 49633042fcc9..000000000000
--- a/drivers/staging/dgnc/Makefile
+++ /dev/null
@@ -1,4 +0,0 @@
1obj-$(CONFIG_DGNC) += dgnc.o
2
3dgnc-objs := dgnc_cls.o dgnc_driver.o\
4 dgnc_tty.o
diff --git a/drivers/staging/dgnc/TODO b/drivers/staging/dgnc/TODO
deleted file mode 100644
index d4cc65770513..000000000000
--- a/drivers/staging/dgnc/TODO
+++ /dev/null
@@ -1,6 +0,0 @@
1* remove unnecessary comments
2* there is a lot of unnecessary code in the driver. It was
3 originally a standalone driver. Remove unneeded code.
4
5Please send patches to Greg Kroah-Hartman <greg@kroah.com> and
6Cc: Lidza Louina <lidza.louina@gmail.com>
diff --git a/drivers/staging/dgnc/dgnc_cls.c b/drivers/staging/dgnc/dgnc_cls.c
deleted file mode 100644
index 7e6cbfe4e4ee..000000000000
--- a/drivers/staging/dgnc/dgnc_cls.c
+++ /dev/null
@@ -1,1135 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2003 Digi International (www.digi.com)
4 * Scott H Kilau <Scott_Kilau at digi dot com>
5 */
6
7#include <linux/kernel.h>
8#include <linux/sched.h>
9#include <linux/interrupt.h>
10#include <linux/delay.h>
11#include <linux/io.h>
12#include <linux/serial.h>
13#include <linux/serial_reg.h>
14#include <linux/pci.h>
15
16#include "dgnc_driver.h"
17#include "dgnc_cls.h"
18#include "dgnc_tty.h"
19
20static inline void cls_set_cts_flow_control(struct channel_t *ch)
21{
22 unsigned char lcrb = readb(&ch->ch_cls_uart->lcr);
23 unsigned char ier = readb(&ch->ch_cls_uart->ier);
24 unsigned char isr_fcr = 0;
25
26 /*
27 * The Enhanced Register Set may only be accessed when
28 * the Line Control Register is set to 0xBFh.
29 */
30 writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr);
31
32 isr_fcr = readb(&ch->ch_cls_uart->isr_fcr);
33
34 /* Turn on CTS flow control, turn off IXON flow control */
35 isr_fcr |= (UART_EXAR654_EFR_ECB | UART_EXAR654_EFR_CTSDSR);
36 isr_fcr &= ~(UART_EXAR654_EFR_IXON);
37
38 writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr);
39
40 /* Write old LCR value back out, which turns enhanced access off */
41 writeb(lcrb, &ch->ch_cls_uart->lcr);
42
43 /*
44 * Enable interrupts for CTS flow, turn off interrupts for
45 * received XOFF chars
46 */
47 ier |= (UART_EXAR654_IER_CTSDSR);
48 ier &= ~(UART_EXAR654_IER_XOFF);
49 writeb(ier, &ch->ch_cls_uart->ier);
50
51 /* Set the usual FIFO values */
52 writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr);
53
54 writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_56 |
55 UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR),
56 &ch->ch_cls_uart->isr_fcr);
57
58 ch->ch_t_tlevel = 16;
59}
60
61static inline void cls_set_ixon_flow_control(struct channel_t *ch)
62{
63 unsigned char lcrb = readb(&ch->ch_cls_uart->lcr);
64 unsigned char ier = readb(&ch->ch_cls_uart->ier);
65 unsigned char isr_fcr = 0;
66
67 /*
68 * The Enhanced Register Set may only be accessed when
69 * the Line Control Register is set to 0xBFh.
70 */
71 writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr);
72
73 isr_fcr = readb(&ch->ch_cls_uart->isr_fcr);
74
75 /* Turn on IXON flow control, turn off CTS flow control */
76 isr_fcr |= (UART_EXAR654_EFR_ECB | UART_EXAR654_EFR_IXON);
77 isr_fcr &= ~(UART_EXAR654_EFR_CTSDSR);
78
79 writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr);
80
81 /* Now set our current start/stop chars while in enhanced mode */
82 writeb(ch->ch_startc, &ch->ch_cls_uart->mcr);
83 writeb(0, &ch->ch_cls_uart->lsr);
84 writeb(ch->ch_stopc, &ch->ch_cls_uart->msr);
85 writeb(0, &ch->ch_cls_uart->spr);
86
87 /* Write old LCR value back out, which turns enhanced access off */
88 writeb(lcrb, &ch->ch_cls_uart->lcr);
89
90 /*
91 * Disable interrupts for CTS flow, turn on interrupts for
92 * received XOFF chars
93 */
94 ier &= ~(UART_EXAR654_IER_CTSDSR);
95 ier |= (UART_EXAR654_IER_XOFF);
96 writeb(ier, &ch->ch_cls_uart->ier);
97
98 /* Set the usual FIFO values */
99 writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr);
100
101 writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_16 |
102 UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR),
103 &ch->ch_cls_uart->isr_fcr);
104}
105
106static inline void cls_set_no_output_flow_control(struct channel_t *ch)
107{
108 unsigned char lcrb = readb(&ch->ch_cls_uart->lcr);
109 unsigned char ier = readb(&ch->ch_cls_uart->ier);
110 unsigned char isr_fcr = 0;
111
112 /*
113 * The Enhanced Register Set may only be accessed when
114 * the Line Control Register is set to 0xBFh.
115 */
116 writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr);
117
118 isr_fcr = readb(&ch->ch_cls_uart->isr_fcr);
119
120 /* Turn off IXON flow control, turn off CTS flow control */
121 isr_fcr |= (UART_EXAR654_EFR_ECB);
122 isr_fcr &= ~(UART_EXAR654_EFR_CTSDSR | UART_EXAR654_EFR_IXON);
123
124 writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr);
125
126 /* Write old LCR value back out, which turns enhanced access off */
127 writeb(lcrb, &ch->ch_cls_uart->lcr);
128
129 /*
130 * Disable interrupts for CTS flow, turn off interrupts for
131 * received XOFF chars
132 */
133 ier &= ~(UART_EXAR654_IER_CTSDSR);
134 ier &= ~(UART_EXAR654_IER_XOFF);
135 writeb(ier, &ch->ch_cls_uart->ier);
136
137 /* Set the usual FIFO values */
138 writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr);
139
140 writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_16 |
141 UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR),
142 &ch->ch_cls_uart->isr_fcr);
143
144 ch->ch_r_watermark = 0;
145 ch->ch_t_tlevel = 16;
146 ch->ch_r_tlevel = 16;
147}
148
149static inline void cls_set_rts_flow_control(struct channel_t *ch)
150{
151 unsigned char lcrb = readb(&ch->ch_cls_uart->lcr);
152 unsigned char ier = readb(&ch->ch_cls_uart->ier);
153 unsigned char isr_fcr = 0;
154
155 /*
156 * The Enhanced Register Set may only be accessed when
157 * the Line Control Register is set to 0xBFh.
158 */
159 writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr);
160
161 isr_fcr = readb(&ch->ch_cls_uart->isr_fcr);
162
163 /* Turn on RTS flow control, turn off IXOFF flow control */
164 isr_fcr |= (UART_EXAR654_EFR_ECB | UART_EXAR654_EFR_RTSDTR);
165 isr_fcr &= ~(UART_EXAR654_EFR_IXOFF);
166
167 writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr);
168
169 /* Write old LCR value back out, which turns enhanced access off */
170 writeb(lcrb, &ch->ch_cls_uart->lcr);
171
172 /* Enable interrupts for RTS flow */
173 ier |= (UART_EXAR654_IER_RTSDTR);
174 writeb(ier, &ch->ch_cls_uart->ier);
175
176 /* Set the usual FIFO values */
177 writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr);
178
179 writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_56 |
180 UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR),
181 &ch->ch_cls_uart->isr_fcr);
182
183 ch->ch_r_watermark = 4;
184 ch->ch_r_tlevel = 8;
185}
186
187static inline void cls_set_ixoff_flow_control(struct channel_t *ch)
188{
189 unsigned char lcrb = readb(&ch->ch_cls_uart->lcr);
190 unsigned char ier = readb(&ch->ch_cls_uart->ier);
191 unsigned char isr_fcr = 0;
192
193 /*
194 * The Enhanced Register Set may only be accessed when
195 * the Line Control Register is set to 0xBFh.
196 */
197 writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr);
198
199 isr_fcr = readb(&ch->ch_cls_uart->isr_fcr);
200
201 /* Turn on IXOFF flow control, turn off RTS flow control */
202 isr_fcr |= (UART_EXAR654_EFR_ECB | UART_EXAR654_EFR_IXOFF);
203 isr_fcr &= ~(UART_EXAR654_EFR_RTSDTR);
204
205 writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr);
206
207 /* Now set our current start/stop chars while in enhanced mode */
208 writeb(ch->ch_startc, &ch->ch_cls_uart->mcr);
209 writeb(0, &ch->ch_cls_uart->lsr);
210 writeb(ch->ch_stopc, &ch->ch_cls_uart->msr);
211 writeb(0, &ch->ch_cls_uart->spr);
212
213 /* Write old LCR value back out, which turns enhanced access off */
214 writeb(lcrb, &ch->ch_cls_uart->lcr);
215
216 /* Disable interrupts for RTS flow */
217 ier &= ~(UART_EXAR654_IER_RTSDTR);
218 writeb(ier, &ch->ch_cls_uart->ier);
219
220 /* Set the usual FIFO values */
221 writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr);
222
223 writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_16 |
224 UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR),
225 &ch->ch_cls_uart->isr_fcr);
226}
227
228static inline void cls_set_no_input_flow_control(struct channel_t *ch)
229{
230 unsigned char lcrb = readb(&ch->ch_cls_uart->lcr);
231 unsigned char ier = readb(&ch->ch_cls_uart->ier);
232 unsigned char isr_fcr = 0;
233
234 /*
235 * The Enhanced Register Set may only be accessed when
236 * the Line Control Register is set to 0xBFh.
237 */
238 writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr);
239
240 isr_fcr = readb(&ch->ch_cls_uart->isr_fcr);
241
242 /* Turn off IXOFF flow control, turn off RTS flow control */
243 isr_fcr |= (UART_EXAR654_EFR_ECB);
244 isr_fcr &= ~(UART_EXAR654_EFR_RTSDTR | UART_EXAR654_EFR_IXOFF);
245
246 writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr);
247
248 /* Write old LCR value back out, which turns enhanced access off */
249 writeb(lcrb, &ch->ch_cls_uart->lcr);
250
251 /* Disable interrupts for RTS flow */
252 ier &= ~(UART_EXAR654_IER_RTSDTR);
253 writeb(ier, &ch->ch_cls_uart->ier);
254
255 /* Set the usual FIFO values */
256 writeb((UART_FCR_ENABLE_FIFO), &ch->ch_cls_uart->isr_fcr);
257
258 writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_16 |
259 UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR),
260 &ch->ch_cls_uart->isr_fcr);
261
262 ch->ch_t_tlevel = 16;
263 ch->ch_r_tlevel = 16;
264}
265
266/*
267 * Determines whether its time to shut off break condition.
268 *
269 * No locks are assumed to be held when calling this function.
270 * channel lock is held and released in this function.
271 */
272static inline void cls_clear_break(struct channel_t *ch, int force)
273{
274 unsigned long flags;
275
276 if (!ch)
277 return;
278
279 spin_lock_irqsave(&ch->ch_lock, flags);
280
281 if (!ch->ch_stop_sending_break) {
282 spin_unlock_irqrestore(&ch->ch_lock, flags);
283 return;
284 }
285
286 /* Turn break off, and unset some variables */
287 if (ch->ch_flags & CH_BREAK_SENDING) {
288 if (time_after(jiffies, ch->ch_stop_sending_break) || force) {
289 unsigned char temp = readb(&ch->ch_cls_uart->lcr);
290
291 writeb((temp & ~UART_LCR_SBC), &ch->ch_cls_uart->lcr);
292 ch->ch_flags &= ~(CH_BREAK_SENDING);
293 ch->ch_stop_sending_break = 0;
294 }
295 }
296 spin_unlock_irqrestore(&ch->ch_lock, flags);
297}
298
299static void cls_copy_data_from_uart_to_queue(struct channel_t *ch)
300{
301 int qleft = 0;
302 unsigned char linestatus = 0;
303 unsigned char error_mask = 0;
304 ushort head;
305 ushort tail;
306 unsigned long flags;
307
308 if (!ch)
309 return;
310
311 spin_lock_irqsave(&ch->ch_lock, flags);
312
313 head = ch->ch_r_head;
314 tail = ch->ch_r_tail;
315
316 qleft = tail - head - 1;
317 if (qleft < 0)
318 qleft += RQUEUEMASK + 1;
319
320 /*
321 * Create a mask to determine whether we should
322 * insert the character (if any) into our queue.
323 */
324 if (ch->ch_c_iflag & IGNBRK)
325 error_mask |= UART_LSR_BI;
326
327 while (1) {
328 linestatus = readb(&ch->ch_cls_uart->lsr);
329
330 if (!(linestatus & (UART_LSR_DR)))
331 break;
332
333 /* Discard character if we are ignoring the error mask. */
334 if (linestatus & error_mask) {
335 linestatus = 0;
336 readb(&ch->ch_cls_uart->txrx);
337 continue;
338 }
339
340 /*
341 * If our queue is full, we have no choice but to drop some
342 * data. The assumption is that HWFLOW or SWFLOW should have
343 * stopped things way way before we got to this point.
344 */
345 while (qleft < 1) {
346 tail = (tail + 1) & RQUEUEMASK;
347 ch->ch_r_tail = tail;
348 ch->ch_err_overrun++;
349 qleft++;
350 }
351
352 ch->ch_equeue[head] = linestatus & (UART_LSR_BI | UART_LSR_PE
353 | UART_LSR_FE);
354 ch->ch_rqueue[head] = readb(&ch->ch_cls_uart->txrx);
355
356 qleft--;
357
358 if (ch->ch_equeue[head] & UART_LSR_PE)
359 ch->ch_err_parity++;
360 if (ch->ch_equeue[head] & UART_LSR_BI)
361 ch->ch_err_break++;
362 if (ch->ch_equeue[head] & UART_LSR_FE)
363 ch->ch_err_frame++;
364
365 head = (head + 1) & RQUEUEMASK;
366 ch->ch_rxcount++;
367 }
368
369 ch->ch_r_head = head & RQUEUEMASK;
370 ch->ch_e_head = head & EQUEUEMASK;
371
372 spin_unlock_irqrestore(&ch->ch_lock, flags);
373}
374
375/* Make the UART raise any of the output signals we want up */
376static void cls_assert_modem_signals(struct channel_t *ch)
377{
378 unsigned char out;
379
380 if (!ch)
381 return;
382
383 out = ch->ch_mostat;
384
385 if (ch->ch_flags & CH_LOOPBACK)
386 out |= UART_MCR_LOOP;
387
388 writeb(out, &ch->ch_cls_uart->mcr);
389
390 /* Give time for the UART to actually drop the signals */
391 usleep_range(10, 20);
392}
393
394static void cls_copy_data_from_queue_to_uart(struct channel_t *ch)
395{
396 ushort head;
397 ushort tail;
398 int n;
399 int qlen;
400 uint len_written = 0;
401 unsigned long flags;
402
403 if (!ch)
404 return;
405
406 spin_lock_irqsave(&ch->ch_lock, flags);
407
408 if (ch->ch_w_tail == ch->ch_w_head)
409 goto exit_unlock;
410
411 /* If port is "stopped", don't send any data to the UART */
412 if ((ch->ch_flags & CH_FORCED_STOP) ||
413 (ch->ch_flags & CH_BREAK_SENDING))
414 goto exit_unlock;
415
416 if (!(ch->ch_flags & (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM)))
417 goto exit_unlock;
418
419 n = 32;
420
421 head = ch->ch_w_head & WQUEUEMASK;
422 tail = ch->ch_w_tail & WQUEUEMASK;
423 qlen = (head - tail) & WQUEUEMASK;
424
425 n = min(n, qlen);
426
427 while (n > 0) {
428 /*
429 * If RTS Toggle mode is on, turn on RTS now if not already set,
430 * and make sure we get an event when the data transfer has
431 * completed.
432 */
433 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) {
434 if (!(ch->ch_mostat & UART_MCR_RTS)) {
435 ch->ch_mostat |= (UART_MCR_RTS);
436 cls_assert_modem_signals(ch);
437 }
438 ch->ch_tun.un_flags |= (UN_EMPTY);
439 }
440
441 /*
442 * If DTR Toggle mode is on, turn on DTR now if not already set,
443 * and make sure we get an event when the data transfer has
444 * completed.
445 */
446 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) {
447 if (!(ch->ch_mostat & UART_MCR_DTR)) {
448 ch->ch_mostat |= (UART_MCR_DTR);
449 cls_assert_modem_signals(ch);
450 }
451 ch->ch_tun.un_flags |= (UN_EMPTY);
452 }
453 writeb(ch->ch_wqueue[ch->ch_w_tail], &ch->ch_cls_uart->txrx);
454 ch->ch_w_tail++;
455 ch->ch_w_tail &= WQUEUEMASK;
456 ch->ch_txcount++;
457 len_written++;
458 n--;
459 }
460
461 if (len_written > 0)
462 ch->ch_flags &= ~(CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
463
464exit_unlock:
465 spin_unlock_irqrestore(&ch->ch_lock, flags);
466}
467
468static void cls_parse_modem(struct channel_t *ch, unsigned char signals)
469{
470 unsigned char msignals = signals;
471 unsigned long flags;
472
473 if (!ch)
474 return;
475
476 /*
477 * Do altpin switching. Altpin switches DCD and DSR.
478 * This prolly breaks DSRPACE, so we should be more clever here.
479 */
480 spin_lock_irqsave(&ch->ch_lock, flags);
481 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
482 unsigned char mswap = signals;
483
484 if (mswap & UART_MSR_DDCD) {
485 msignals &= ~UART_MSR_DDCD;
486 msignals |= UART_MSR_DDSR;
487 }
488 if (mswap & UART_MSR_DDSR) {
489 msignals &= ~UART_MSR_DDSR;
490 msignals |= UART_MSR_DDCD;
491 }
492 if (mswap & UART_MSR_DCD) {
493 msignals &= ~UART_MSR_DCD;
494 msignals |= UART_MSR_DSR;
495 }
496 if (mswap & UART_MSR_DSR) {
497 msignals &= ~UART_MSR_DSR;
498 msignals |= UART_MSR_DCD;
499 }
500 }
501 spin_unlock_irqrestore(&ch->ch_lock, flags);
502
503 /* Scrub off lower bits. They signify delta's */
504 signals &= 0xf0;
505
506 spin_lock_irqsave(&ch->ch_lock, flags);
507 if (msignals & UART_MSR_DCD)
508 ch->ch_mistat |= UART_MSR_DCD;
509 else
510 ch->ch_mistat &= ~UART_MSR_DCD;
511
512 if (msignals & UART_MSR_DSR)
513 ch->ch_mistat |= UART_MSR_DSR;
514 else
515 ch->ch_mistat &= ~UART_MSR_DSR;
516
517 if (msignals & UART_MSR_RI)
518 ch->ch_mistat |= UART_MSR_RI;
519 else
520 ch->ch_mistat &= ~UART_MSR_RI;
521
522 if (msignals & UART_MSR_CTS)
523 ch->ch_mistat |= UART_MSR_CTS;
524 else
525 ch->ch_mistat &= ~UART_MSR_CTS;
526 spin_unlock_irqrestore(&ch->ch_lock, flags);
527}
528
529/* Parse the ISR register for the specific port */
530static inline void cls_parse_isr(struct dgnc_board *brd, uint port)
531{
532 struct channel_t *ch;
533 unsigned char isr = 0;
534 unsigned long flags;
535
536 /*
537 * No need to verify board pointer, it was already
538 * verified in the interrupt routine.
539 */
540
541 if (port >= brd->nasync)
542 return;
543
544 ch = brd->channels[port];
545
546 /* Here we try to figure out what caused the interrupt to happen */
547 while (1) {
548 isr = readb(&ch->ch_cls_uart->isr_fcr);
549
550 if (isr & UART_IIR_NO_INT)
551 break;
552
553 /* Receive Interrupt pending */
554 if (isr & (UART_IIR_RDI | UART_IIR_RDI_TIMEOUT)) {
555 cls_copy_data_from_uart_to_queue(ch);
556 dgnc_check_queue_flow_control(ch);
557 }
558
559 /* Transmit Hold register empty pending */
560 if (isr & UART_IIR_THRI) {
561 spin_lock_irqsave(&ch->ch_lock, flags);
562 ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
563 spin_unlock_irqrestore(&ch->ch_lock, flags);
564 cls_copy_data_from_queue_to_uart(ch);
565 }
566
567 cls_parse_modem(ch, readb(&ch->ch_cls_uart->msr));
568 }
569}
570
571/* Channel lock MUST be held before calling this function! */
572static void cls_flush_uart_write(struct channel_t *ch)
573{
574 if (!ch)
575 return;
576
577 writeb((UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_XMIT),
578 &ch->ch_cls_uart->isr_fcr);
579
580 /* Must use *delay family functions in atomic context */
581 udelay(10);
582
583 ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
584}
585
586/* Channel lock MUST be held before calling this function! */
587static void cls_flush_uart_read(struct channel_t *ch)
588{
589 if (!ch)
590 return;
591
592 /*
593 * For complete POSIX compatibility, we should be purging the
594 * read FIFO in the UART here.
595 *
596 * However, clearing the read FIFO (UART_FCR_CLEAR_RCVR) also
597 * incorrectly flushes write data as well as just basically trashing the
598 * FIFO.
599 *
600 * Presumably, this is a bug in this UART.
601 */
602
603 udelay(10);
604}
605
606/* Send any/all changes to the line to the UART. */
607static void cls_param(struct tty_struct *tty)
608{
609 unsigned char lcr = 0;
610 unsigned char uart_lcr = 0;
611 unsigned char ier = 0;
612 unsigned char uart_ier = 0;
613 uint baud = 9600;
614 int quot = 0;
615 struct dgnc_board *bd;
616 struct channel_t *ch;
617 struct un_t *un;
618
619 if (!tty)
620 return;
621
622 un = (struct un_t *)tty->driver_data;
623 if (!un)
624 return;
625
626 ch = un->un_ch;
627 if (!ch)
628 return;
629
630 bd = ch->ch_bd;
631 if (!bd)
632 return;
633
634 /* If baud rate is zero, flush queues, and set mval to drop DTR. */
635 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
636 ch->ch_r_head = 0;
637 ch->ch_r_tail = 0;
638 ch->ch_e_head = 0;
639 ch->ch_e_tail = 0;
640 ch->ch_w_head = 0;
641 ch->ch_w_tail = 0;
642
643 cls_flush_uart_write(ch);
644 cls_flush_uart_read(ch);
645
646 /* The baudrate is B0 so all modem lines are to be dropped. */
647 ch->ch_flags |= (CH_BAUD0);
648 ch->ch_mostat &= ~(UART_MCR_RTS | UART_MCR_DTR);
649 cls_assert_modem_signals(ch);
650 ch->ch_old_baud = 0;
651 return;
652 } else if (ch->ch_custom_speed) {
653 baud = ch->ch_custom_speed;
654 /* Handle transition from B0 */
655 if (ch->ch_flags & CH_BAUD0) {
656 ch->ch_flags &= ~(CH_BAUD0);
657
658 /*
659 * Bring back up RTS and DTR...
660 * Also handle RTS or DTR toggle if set.
661 */
662 if (!(ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE))
663 ch->ch_mostat |= (UART_MCR_RTS);
664 if (!(ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE))
665 ch->ch_mostat |= (UART_MCR_DTR);
666 }
667
668 } else {
669 int iindex = 0;
670 int jindex = 0;
671
672 ulong bauds[4][16] = {
673 { /* slowbaud */
674 0, 50, 75, 110,
675 134, 150, 200, 300,
676 600, 1200, 1800, 2400,
677 4800, 9600, 19200, 38400 },
678 { /* slowbaud & CBAUDEX */
679 0, 57600, 115200, 230400,
680 460800, 150, 200, 921600,
681 600, 1200, 1800, 2400,
682 4800, 9600, 19200, 38400 },
683 { /* fastbaud */
684 0, 57600, 76800, 115200,
685 131657, 153600, 230400, 460800,
686 921600, 1200, 1800, 2400,
687 4800, 9600, 19200, 38400 },
688 { /* fastbaud & CBAUDEX */
689 0, 57600, 115200, 230400,
690 460800, 150, 200, 921600,
691 600, 1200, 1800, 2400,
692 4800, 9600, 19200, 38400 }
693 };
694
695 /*
696 * Only use the TXPrint baud rate if the terminal
697 * unit is NOT open
698 */
699 if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
700 (un->un_type == DGNC_PRINT))
701 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
702 else
703 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
704
705 if (ch->ch_c_cflag & CBAUDEX)
706 iindex = 1;
707
708 if (ch->ch_digi.digi_flags & DIGI_FAST)
709 iindex += 2;
710
711 jindex = baud;
712
713 if ((iindex >= 0) && (iindex < 4) && (jindex >= 0) &&
714 (jindex < 16)) {
715 baud = bauds[iindex][jindex];
716 } else {
717 baud = 0;
718 }
719
720 if (baud == 0)
721 baud = 9600;
722
723 /* Handle transition from B0 */
724 if (ch->ch_flags & CH_BAUD0) {
725 ch->ch_flags &= ~(CH_BAUD0);
726
727 /*
728 * Bring back up RTS and DTR...
729 * Also handle RTS or DTR toggle if set.
730 */
731 if (!(ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE))
732 ch->ch_mostat |= (UART_MCR_RTS);
733 if (!(ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE))
734 ch->ch_mostat |= (UART_MCR_DTR);
735 }
736 }
737
738 if (ch->ch_c_cflag & PARENB)
739 lcr |= UART_LCR_PARITY;
740
741 if (!(ch->ch_c_cflag & PARODD))
742 lcr |= UART_LCR_EPAR;
743
744#ifdef CMSPAR
745 if (ch->ch_c_cflag & CMSPAR)
746 lcr |= UART_LCR_SPAR;
747#endif
748
749 if (ch->ch_c_cflag & CSTOPB)
750 lcr |= UART_LCR_STOP;
751
752 switch (ch->ch_c_cflag & CSIZE) {
753 case CS5:
754 lcr |= UART_LCR_WLEN5;
755 break;
756 case CS6:
757 lcr |= UART_LCR_WLEN6;
758 break;
759 case CS7:
760 lcr |= UART_LCR_WLEN7;
761 break;
762 case CS8:
763 default:
764 lcr |= UART_LCR_WLEN8;
765 break;
766 }
767
768 uart_ier = readb(&ch->ch_cls_uart->ier);
769 ier = uart_ier;
770 uart_lcr = readb(&ch->ch_cls_uart->lcr);
771
772 if (baud == 0)
773 baud = 9600;
774
775 quot = ch->ch_bd->bd_dividend / baud;
776
777 if (quot != 0 && ch->ch_old_baud != baud) {
778 ch->ch_old_baud = baud;
779 writeb(UART_LCR_DLAB, &ch->ch_cls_uart->lcr);
780 writeb((quot & 0xff), &ch->ch_cls_uart->txrx);
781 writeb((quot >> 8), &ch->ch_cls_uart->ier);
782 writeb(lcr, &ch->ch_cls_uart->lcr);
783 }
784
785 if (uart_lcr != lcr)
786 writeb(lcr, &ch->ch_cls_uart->lcr);
787
788 if (ch->ch_c_cflag & CREAD)
789 ier |= (UART_IER_RDI | UART_IER_RLSI);
790 else
791 ier &= ~(UART_IER_RDI | UART_IER_RLSI);
792
793 /*
794 * Have the UART interrupt on modem signal changes ONLY when
795 * we are in hardware flow control mode, or CLOCAL/FORCEDCD is not set.
796 */
797 if ((ch->ch_digi.digi_flags & CTSPACE) ||
798 (ch->ch_digi.digi_flags & RTSPACE) ||
799 (ch->ch_c_cflag & CRTSCTS) ||
800 !(ch->ch_digi.digi_flags & DIGI_FORCEDCD) ||
801 !(ch->ch_c_cflag & CLOCAL))
802 ier |= UART_IER_MSI;
803 else
804 ier &= ~UART_IER_MSI;
805
806 ier |= UART_IER_THRI;
807
808 if (ier != uart_ier)
809 writeb(ier, &ch->ch_cls_uart->ier);
810
811 if (ch->ch_digi.digi_flags & CTSPACE || ch->ch_c_cflag & CRTSCTS) {
812 cls_set_cts_flow_control(ch);
813 } else if (ch->ch_c_iflag & IXON) {
814 if ((ch->ch_startc == _POSIX_VDISABLE) ||
815 (ch->ch_stopc == _POSIX_VDISABLE))
816 cls_set_no_output_flow_control(ch);
817 else
818 cls_set_ixon_flow_control(ch);
819 } else {
820 cls_set_no_output_flow_control(ch);
821 }
822
823 if (ch->ch_digi.digi_flags & RTSPACE || ch->ch_c_cflag & CRTSCTS) {
824 cls_set_rts_flow_control(ch);
825 } else if (ch->ch_c_iflag & IXOFF) {
826 if ((ch->ch_startc == _POSIX_VDISABLE) ||
827 (ch->ch_stopc == _POSIX_VDISABLE))
828 cls_set_no_input_flow_control(ch);
829 else
830 cls_set_ixoff_flow_control(ch);
831 } else {
832 cls_set_no_input_flow_control(ch);
833 }
834
835 cls_assert_modem_signals(ch);
836
837 cls_parse_modem(ch, readb(&ch->ch_cls_uart->msr));
838}
839
840/* Board poller function. */
841static void cls_tasklet(unsigned long data)
842{
843 struct dgnc_board *bd = (struct dgnc_board *)data;
844 struct channel_t *ch;
845 unsigned long flags;
846 int i;
847 int state = 0;
848 int ports = 0;
849
850 if (!bd)
851 return;
852
853 spin_lock_irqsave(&bd->bd_lock, flags);
854 state = bd->state;
855 ports = bd->nasync;
856 spin_unlock_irqrestore(&bd->bd_lock, flags);
857
858 /*
859 * Do NOT allow the interrupt routine to read the intr registers
860 * Until we release this lock.
861 */
862 spin_lock_irqsave(&bd->bd_intr_lock, flags);
863
864 if ((state == BOARD_READY) && (ports > 0)) {
865 for (i = 0; i < ports; i++) {
866 ch = bd->channels[i];
867
868 /*
869 * NOTE: Remember you CANNOT hold any channel
870 * locks when calling input.
871 * During input processing, its possible we
872 * will call ld, which might do callbacks back
873 * into us.
874 */
875 dgnc_input(ch);
876
877 /*
878 * Channel lock is grabbed and then released
879 * inside this routine.
880 */
881 cls_copy_data_from_queue_to_uart(ch);
882 dgnc_wakeup_writes(ch);
883
884 dgnc_carrier(ch);
885
886 /*
887 * The timing check of turning off the break is done
888 * inside clear_break()
889 */
890 if (ch->ch_stop_sending_break)
891 cls_clear_break(ch, 0);
892 }
893 }
894
895 spin_unlock_irqrestore(&bd->bd_intr_lock, flags);
896}
897
898/* Classic specific interrupt handler. */
899static irqreturn_t cls_intr(int irq, void *voidbrd)
900{
901 struct dgnc_board *brd = voidbrd;
902 uint i = 0;
903 unsigned char poll_reg;
904 unsigned long flags;
905
906 if (!brd)
907 return IRQ_NONE;
908
909 spin_lock_irqsave(&brd->bd_intr_lock, flags);
910
911 poll_reg = readb(brd->re_map_membase + UART_CLASSIC_POLL_ADDR_OFFSET);
912 if (!poll_reg) {
913 spin_unlock_irqrestore(&brd->bd_intr_lock, flags);
914 return IRQ_NONE;
915 }
916
917 for (i = 0; i < brd->nasync; i++)
918 cls_parse_isr(brd, i);
919
920 tasklet_schedule(&brd->helper_tasklet);
921
922 spin_unlock_irqrestore(&brd->bd_intr_lock, flags);
923
924 return IRQ_HANDLED;
925}
926
927static void cls_disable_receiver(struct channel_t *ch)
928{
929 unsigned char tmp = readb(&ch->ch_cls_uart->ier);
930
931 tmp &= ~(UART_IER_RDI);
932 writeb(tmp, &ch->ch_cls_uart->ier);
933}
934
935static void cls_enable_receiver(struct channel_t *ch)
936{
937 unsigned char tmp = readb(&ch->ch_cls_uart->ier);
938
939 tmp |= (UART_IER_RDI);
940 writeb(tmp, &ch->ch_cls_uart->ier);
941}
942
943/*
944 * This function basically goes to sleep for seconds, or until
945 * it gets signalled that the port has fully drained.
946 */
947static int cls_drain(struct tty_struct *tty, uint seconds)
948{
949 unsigned long flags;
950 struct channel_t *ch;
951 struct un_t *un;
952
953 if (!tty)
954 return -ENXIO;
955
956 un = (struct un_t *)tty->driver_data;
957 if (!un)
958 return -ENXIO;
959
960 ch = un->un_ch;
961 if (!ch)
962 return -ENXIO;
963
964 spin_lock_irqsave(&ch->ch_lock, flags);
965 un->un_flags |= UN_EMPTY;
966 spin_unlock_irqrestore(&ch->ch_lock, flags);
967
968 /* NOTE: Do something with time passed in. */
969
970 /* If ret is non-zero, user ctrl-c'ed us */
971
972 return wait_event_interruptible(un->un_flags_wait,
973 ((un->un_flags & UN_EMPTY) == 0));
974}
975
976static void cls_send_start_character(struct channel_t *ch)
977{
978 if (!ch)
979 return;
980
981 if (ch->ch_startc != _POSIX_VDISABLE) {
982 ch->ch_xon_sends++;
983 writeb(ch->ch_startc, &ch->ch_cls_uart->txrx);
984 }
985}
986
987static void cls_send_stop_character(struct channel_t *ch)
988{
989 if (!ch)
990 return;
991
992 if (ch->ch_stopc != _POSIX_VDISABLE) {
993 ch->ch_xoff_sends++;
994 writeb(ch->ch_stopc, &ch->ch_cls_uart->txrx);
995 }
996}
997
998static void cls_uart_init(struct channel_t *ch)
999{
1000 unsigned char lcrb = readb(&ch->ch_cls_uart->lcr);
1001 unsigned char isr_fcr = 0;
1002
1003 writeb(0, &ch->ch_cls_uart->ier);
1004
1005 /*
1006 * The Enhanced Register Set may only be accessed when
1007 * the Line Control Register is set to 0xBFh.
1008 */
1009 writeb(UART_EXAR654_ENHANCED_REGISTER_SET, &ch->ch_cls_uart->lcr);
1010
1011 isr_fcr = readb(&ch->ch_cls_uart->isr_fcr);
1012
1013 /* Turn on Enhanced/Extended controls */
1014 isr_fcr |= (UART_EXAR654_EFR_ECB);
1015
1016 writeb(isr_fcr, &ch->ch_cls_uart->isr_fcr);
1017
1018 /* Write old LCR value back out, which turns enhanced access off */
1019 writeb(lcrb, &ch->ch_cls_uart->lcr);
1020
1021 /* Clear out UART and FIFO */
1022 readb(&ch->ch_cls_uart->txrx);
1023
1024 writeb(UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT,
1025 &ch->ch_cls_uart->isr_fcr);
1026 usleep_range(10, 20);
1027
1028 ch->ch_flags |= (CH_FIFO_ENABLED | CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
1029
1030 readb(&ch->ch_cls_uart->lsr);
1031 readb(&ch->ch_cls_uart->msr);
1032}
1033
1034static void cls_uart_off(struct channel_t *ch)
1035{
1036 writeb(0, &ch->ch_cls_uart->ier);
1037}
1038
1039/*
1040 * The channel lock MUST be held by the calling function.
1041 * Returns 0 is nothing left in the FIFO, returns 1 otherwise.
1042 */
1043static uint cls_get_uart_bytes_left(struct channel_t *ch)
1044{
1045 unsigned char left = 0;
1046 unsigned char lsr = 0;
1047
1048 if (!ch)
1049 return 0;
1050
1051 lsr = readb(&ch->ch_cls_uart->lsr);
1052
1053 /* Determine whether the Transmitter is empty or not */
1054 if (!(lsr & UART_LSR_TEMT)) {
1055 if (ch->ch_flags & CH_TX_FIFO_EMPTY)
1056 tasklet_schedule(&ch->ch_bd->helper_tasklet);
1057 left = 1;
1058 } else {
1059 ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
1060 left = 0;
1061 }
1062
1063 return left;
1064}
1065
1066/*
1067 * Starts sending a break thru the UART.
1068 * The channel lock MUST be held by the calling function.
1069 */
1070static void cls_send_break(struct channel_t *ch, int msecs)
1071{
1072 if (!ch)
1073 return;
1074
1075 /* If we receive a time of 0, this means turn off the break. */
1076 if (msecs == 0) {
1077 if (ch->ch_flags & CH_BREAK_SENDING) {
1078 unsigned char temp = readb(&ch->ch_cls_uart->lcr);
1079
1080 writeb((temp & ~UART_LCR_SBC), &ch->ch_cls_uart->lcr);
1081 ch->ch_flags &= ~(CH_BREAK_SENDING);
1082 ch->ch_stop_sending_break = 0;
1083 }
1084 return;
1085 }
1086
1087 /*
1088 * Set the time we should stop sending the break.
1089 * If we are already sending a break, toss away the existing
1090 * time to stop, and use this new value instead.
1091 */
1092 ch->ch_stop_sending_break = jiffies + dgnc_jiffies_from_ms(msecs);
1093
1094 /* Tell the UART to start sending the break */
1095 if (!(ch->ch_flags & CH_BREAK_SENDING)) {
1096 unsigned char temp = readb(&ch->ch_cls_uart->lcr);
1097
1098 writeb((temp | UART_LCR_SBC), &ch->ch_cls_uart->lcr);
1099 ch->ch_flags |= (CH_BREAK_SENDING);
1100 }
1101}
1102
1103/*
1104 * Sends a specific character as soon as possible to the UART,
1105 * jumping over any bytes that might be in the write queue.
1106 *
1107 * The channel lock MUST be held by the calling function.
1108 */
1109static void cls_send_immediate_char(struct channel_t *ch, unsigned char c)
1110{
1111 if (!ch)
1112 return;
1113
1114 writeb(c, &ch->ch_cls_uart->txrx);
1115}
1116
1117struct board_ops dgnc_cls_ops = {
1118 .tasklet = cls_tasklet,
1119 .intr = cls_intr,
1120 .uart_init = cls_uart_init,
1121 .uart_off = cls_uart_off,
1122 .drain = cls_drain,
1123 .param = cls_param,
1124 .assert_modem_signals = cls_assert_modem_signals,
1125 .flush_uart_write = cls_flush_uart_write,
1126 .flush_uart_read = cls_flush_uart_read,
1127 .disable_receiver = cls_disable_receiver,
1128 .enable_receiver = cls_enable_receiver,
1129 .send_break = cls_send_break,
1130 .send_start_character = cls_send_start_character,
1131 .send_stop_character = cls_send_stop_character,
1132 .copy_data_from_queue_to_uart = cls_copy_data_from_queue_to_uart,
1133 .get_uart_bytes_left = cls_get_uart_bytes_left,
1134 .send_immediate_char = cls_send_immediate_char
1135};
diff --git a/drivers/staging/dgnc/dgnc_cls.h b/drivers/staging/dgnc/dgnc_cls.h
deleted file mode 100644
index d31508542261..000000000000
--- a/drivers/staging/dgnc/dgnc_cls.h
+++ /dev/null
@@ -1,67 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Copyright 2003 Digi International (www.digi.com)
4 * Scott H Kilau <Scott_Kilau at digi dot com>
5 */
6
7#ifndef _DGNC_CLS_H
8#define _DGNC_CLS_H
9
10/**
11 * struct cls_uart_struct - Per channel/port Classic UART.
12 *
13 * key - W = read write
14 * - R = read only
15 * - U = unused
16 *
17 * @txrx: (WR) Holding Register.
18 * @ier: (WR) Interrupt Enable Register.
19 * @isr_fcr: (WR) Interrupt Status Register/Fifo Control Register.
20 * @lcr: (WR) Line Control Register.
21 * @mcr: (WR) Modem Control Register.
22 * @lsr: (WR) Line Status Register.
23 * @msr: (WR) Modem Status Register.
24 * @spr: (WR) Scratch Pad Register.
25 */
26struct cls_uart_struct {
27 u8 txrx;
28 u8 ier;
29 u8 isr_fcr;
30 u8 lcr;
31 u8 mcr;
32 u8 lsr;
33 u8 msr;
34 u8 spr;
35};
36
37/* Where to read the interrupt register (8bits) */
38#define UART_CLASSIC_POLL_ADDR_OFFSET 0x40
39
40#define UART_EXAR654_ENHANCED_REGISTER_SET 0xBF
41
42#define UART_16654_FCR_TXTRIGGER_16 0x10
43#define UART_16654_FCR_RXTRIGGER_16 0x40
44#define UART_16654_FCR_RXTRIGGER_56 0x80
45
46/* Received CTS/RTS change of state */
47#define UART_IIR_CTSRTS 0x20
48
49/* Receiver data TIMEOUT */
50#define UART_IIR_RDI_TIMEOUT 0x0C
51
52/*
53 * These are the EXTENDED definitions for the Exar 654's Interrupt
54 * Enable Register.
55 */
56#define UART_EXAR654_EFR_ECB 0x10 /* Enhanced control bit */
57#define UART_EXAR654_EFR_IXON 0x2 /* Receiver compares Xon1/Xoff1 */
58#define UART_EXAR654_EFR_IXOFF 0x8 /* Transmit Xon1/Xoff1 */
59#define UART_EXAR654_EFR_RTSDTR 0x40 /* Auto RTS/DTR Flow Control Enable */
60#define UART_EXAR654_EFR_CTSDSR 0x80 /* Auto CTS/DSR Flow Control Enable */
61#define UART_EXAR654_IER_XOFF 0x20 /* Xoff Interrupt Enable */
62#define UART_EXAR654_IER_RTSDTR 0x40 /* Output Interrupt Enable */
63#define UART_EXAR654_IER_CTSDSR 0x80 /* Input Interrupt Enable */
64
65extern struct board_ops dgnc_cls_ops;
66
67#endif /* _DGNC_CLS_H */
diff --git a/drivers/staging/dgnc/dgnc_driver.c b/drivers/staging/dgnc/dgnc_driver.c
deleted file mode 100644
index 5d8c2d995dcc..000000000000
--- a/drivers/staging/dgnc/dgnc_driver.c
+++ /dev/null
@@ -1,404 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2003 Digi International (www.digi.com)
4 * Scott H Kilau <Scott_Kilau at digi dot com>
5 */
6
7#include <linux/kernel.h>
8#include <linux/module.h>
9#include <linux/pci.h>
10#include <linux/slab.h>
11#include <linux/sched.h>
12#include "dgnc_driver.h"
13#include "dgnc_tty.h"
14#include "dgnc_cls.h"
15
16MODULE_LICENSE("GPL");
17MODULE_AUTHOR("Digi International, http://www.digi.com");
18MODULE_DESCRIPTION("Driver for the Digi International Neo and Classic PCI based product line");
19MODULE_SUPPORTED_DEVICE("dgnc");
20
21static unsigned int dgnc_num_boards;
22struct dgnc_board *dgnc_board[MAXBOARDS];
23static DEFINE_SPINLOCK(dgnc_poll_lock); /* Poll scheduling lock */
24
25static int dgnc_poll_tick = 20; /* Poll interval - 20 ms */
26static ulong dgnc_poll_time; /* Time of next poll */
27static uint dgnc_poll_stop; /* Used to tell poller to stop */
28static struct timer_list dgnc_poll_timer;
29
30#define DIGI_VID 0x114F
31#define PCI_DEVICE_CLASSIC_4_DID 0x0028
32#define PCI_DEVICE_CLASSIC_8_DID 0x0029
33#define PCI_DEVICE_CLASSIC_4_422_DID 0x00D0
34#define PCI_DEVICE_CLASSIC_8_422_DID 0x00D1
35
36#define PCI_DEVICE_CLASSIC_4_PCI_NAME "ClassicBoard 4 PCI"
37#define PCI_DEVICE_CLASSIC_8_PCI_NAME "ClassicBoard 8 PCI"
38#define PCI_DEVICE_CLASSIC_4_422_PCI_NAME "ClassicBoard 4 422 PCI"
39#define PCI_DEVICE_CLASSIC_8_422_PCI_NAME "ClassicBoard 8 422 PCI"
40
41static const struct pci_device_id dgnc_pci_tbl[] = {
42 {PCI_DEVICE(DIGI_VID, PCI_DEVICE_CLASSIC_4_DID), .driver_data = 0},
43 {PCI_DEVICE(DIGI_VID, PCI_DEVICE_CLASSIC_4_422_DID), .driver_data = 1},
44 {PCI_DEVICE(DIGI_VID, PCI_DEVICE_CLASSIC_8_DID), .driver_data = 2},
45 {PCI_DEVICE(DIGI_VID, PCI_DEVICE_CLASSIC_8_422_DID), .driver_data = 3},
46 {0,}
47};
48MODULE_DEVICE_TABLE(pci, dgnc_pci_tbl);
49
50struct board_id {
51 unsigned char *name;
52 uint maxports;
53 unsigned int is_pci_express;
54};
55
56static const struct board_id dgnc_ids[] = {
57 { PCI_DEVICE_CLASSIC_4_PCI_NAME, 4, 0 },
58 { PCI_DEVICE_CLASSIC_4_422_PCI_NAME, 4, 0 },
59 { PCI_DEVICE_CLASSIC_8_PCI_NAME, 8, 0 },
60 { PCI_DEVICE_CLASSIC_8_422_PCI_NAME, 8, 0 },
61 { NULL, 0, 0 }
62};
63
64/* Remap PCI memory. */
65static int dgnc_do_remap(struct dgnc_board *brd)
66{
67 brd->re_map_membase = ioremap(brd->membase, 0x1000);
68 if (!brd->re_map_membase)
69 return -ENOMEM;
70
71 return 0;
72}
73
74/* A board has been found, initialize it. */
75static struct dgnc_board *dgnc_found_board(struct pci_dev *pdev, int id)
76{
77 struct dgnc_board *brd;
78 unsigned int pci_irq;
79 int rc = 0;
80
81 brd = kzalloc(sizeof(*brd), GFP_KERNEL);
82 if (!brd)
83 return ERR_PTR(-ENOMEM);
84
85 /* store the info for the board we've found */
86 brd->boardnum = dgnc_num_boards;
87 brd->device = dgnc_pci_tbl[id].device;
88 brd->pdev = pdev;
89 brd->name = dgnc_ids[id].name;
90 brd->maxports = dgnc_ids[id].maxports;
91 init_waitqueue_head(&brd->state_wait);
92
93 spin_lock_init(&brd->bd_lock);
94 spin_lock_init(&brd->bd_intr_lock);
95
96 brd->state = BOARD_FOUND;
97
98 pci_irq = pdev->irq;
99 brd->irq = pci_irq;
100
101 switch (brd->device) {
102 case PCI_DEVICE_CLASSIC_4_DID:
103 case PCI_DEVICE_CLASSIC_8_DID:
104 case PCI_DEVICE_CLASSIC_4_422_DID:
105 case PCI_DEVICE_CLASSIC_8_422_DID:
106 /*
107 * For PCI ClassicBoards
108 * PCI Local Address (i.e. "resource" number) space
109 * 0 PLX Memory Mapped Config
110 * 1 PLX I/O Mapped Config
111 * 2 I/O Mapped UARTs and Status
112 * 3 Memory Mapped VPD
113 * 4 Memory Mapped UARTs and Status
114 */
115
116 brd->membase = pci_resource_start(pdev, 4);
117
118 if (!brd->membase) {
119 dev_err(&brd->pdev->dev,
120 "Card has no PCI IO resources, failing.\n");
121 rc = -ENODEV;
122 goto failed;
123 }
124
125 brd->membase_end = pci_resource_end(pdev, 4);
126
127 if (brd->membase & 1)
128 brd->membase &= ~3;
129 else
130 brd->membase &= ~15;
131
132 brd->iobase = pci_resource_start(pdev, 1);
133 brd->iobase_end = pci_resource_end(pdev, 1);
134 brd->iobase = ((unsigned int)(brd->iobase)) & 0xFFFE;
135
136 brd->bd_ops = &dgnc_cls_ops;
137
138 brd->bd_uart_offset = 0x8;
139 brd->bd_dividend = 921600;
140
141 rc = dgnc_do_remap(brd);
142 if (rc < 0)
143 goto failed;
144
145 /*
146 * Enable Local Interrupt 1 (0x1),
147 * Local Interrupt 1 Polarity Active high (0x2),
148 * Enable PCI interrupt (0x40)
149 */
150 outb(0x43, brd->iobase + 0x4c);
151
152 break;
153
154 default:
155 dev_err(&brd->pdev->dev,
156 "Didn't find any compatible Neo/Classic PCI boards.\n");
157 rc = -ENXIO;
158 goto failed;
159 }
160
161 tasklet_init(&brd->helper_tasklet,
162 brd->bd_ops->tasklet,
163 (unsigned long)brd);
164
165 wake_up_interruptible(&brd->state_wait);
166
167 return brd;
168
169failed:
170 kfree(brd);
171
172 return ERR_PTR(rc);
173}
174
175static int dgnc_request_irq(struct dgnc_board *brd)
176{
177 if (brd->irq) {
178 int rc = request_irq(brd->irq, brd->bd_ops->intr,
179 IRQF_SHARED, "DGNC", brd);
180 if (rc) {
181 dev_err(&brd->pdev->dev,
182 "Failed to hook IRQ %d\n", brd->irq);
183 brd->state = BOARD_FAILED;
184 return -ENODEV;
185 }
186 }
187 return 0;
188}
189
190static void dgnc_free_irq(struct dgnc_board *brd)
191{
192 if (brd->irq)
193 free_irq(brd->irq, brd);
194}
195
196 /*
197 * As each timer expires, it determines (a) whether the "transmit"
198 * waiter needs to be woken up, and (b) whether the poller needs to
199 * be rescheduled.
200 */
201static void dgnc_poll_handler(struct timer_list *unused)
202{
203 struct dgnc_board *brd;
204 unsigned long flags;
205 int i;
206 unsigned long new_time;
207
208 for (i = 0; i < dgnc_num_boards; i++) {
209 brd = dgnc_board[i];
210
211 spin_lock_irqsave(&brd->bd_lock, flags);
212
213 if (brd->state == BOARD_FAILED) {
214 spin_unlock_irqrestore(&brd->bd_lock, flags);
215 continue;
216 }
217
218 tasklet_schedule(&brd->helper_tasklet);
219
220 spin_unlock_irqrestore(&brd->bd_lock, flags);
221 }
222
223 /* Schedule ourself back at the nominal wakeup interval. */
224
225 spin_lock_irqsave(&dgnc_poll_lock, flags);
226 dgnc_poll_time += dgnc_jiffies_from_ms(dgnc_poll_tick);
227
228 new_time = dgnc_poll_time - jiffies;
229
230 if ((ulong)new_time >= 2 * dgnc_poll_tick)
231 dgnc_poll_time = jiffies + dgnc_jiffies_from_ms(dgnc_poll_tick);
232
233 timer_setup(&dgnc_poll_timer, dgnc_poll_handler, 0);
234 dgnc_poll_timer.expires = dgnc_poll_time;
235 spin_unlock_irqrestore(&dgnc_poll_lock, flags);
236
237 if (!dgnc_poll_stop)
238 add_timer(&dgnc_poll_timer);
239}
240
241/* returns count (>= 0), or negative on error */
242static int dgnc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
243{
244 int rc;
245 struct dgnc_board *brd;
246
247 rc = pci_enable_device(pdev);
248 if (rc)
249 return -EIO;
250
251 brd = dgnc_found_board(pdev, ent->driver_data);
252 if (IS_ERR(brd))
253 return PTR_ERR(brd);
254
255 rc = dgnc_tty_register(brd);
256 if (rc < 0) {
257 pr_err(DRVSTR ": Can't register tty devices (%d)\n", rc);
258 goto failed;
259 }
260
261 rc = dgnc_request_irq(brd);
262 if (rc < 0) {
263 pr_err(DRVSTR ": Can't finalize board init (%d)\n", rc);
264 goto unregister_tty;
265 }
266
267 rc = dgnc_tty_init(brd);
268 if (rc < 0) {
269 pr_err(DRVSTR ": Can't init tty devices (%d)\n", rc);
270 goto free_irq;
271 }
272
273 brd->state = BOARD_READY;
274
275 dgnc_board[dgnc_num_boards++] = brd;
276
277 return 0;
278
279free_irq:
280 dgnc_free_irq(brd);
281unregister_tty:
282 dgnc_tty_unregister(brd);
283failed:
284 kfree(brd);
285
286 return rc;
287}
288
289static struct pci_driver dgnc_driver = {
290 .name = "dgnc",
291 .probe = dgnc_init_one,
292 .id_table = dgnc_pci_tbl,
293};
294
295static int dgnc_start(void)
296{
297 unsigned long flags;
298
299 /* Start the poller */
300 spin_lock_irqsave(&dgnc_poll_lock, flags);
301 timer_setup(&dgnc_poll_timer, dgnc_poll_handler, 0);
302 dgnc_poll_time = jiffies + dgnc_jiffies_from_ms(dgnc_poll_tick);
303 dgnc_poll_timer.expires = dgnc_poll_time;
304 spin_unlock_irqrestore(&dgnc_poll_lock, flags);
305
306 add_timer(&dgnc_poll_timer);
307
308 return 0;
309}
310
311/* Free all the memory associated with a board */
312static void dgnc_cleanup_board(struct dgnc_board *brd)
313{
314 int i = 0;
315
316 if (!brd)
317 return;
318
319 switch (brd->device) {
320 case PCI_DEVICE_CLASSIC_4_DID:
321 case PCI_DEVICE_CLASSIC_8_DID:
322 case PCI_DEVICE_CLASSIC_4_422_DID:
323 case PCI_DEVICE_CLASSIC_8_422_DID:
324
325 /* Tell card not to interrupt anymore. */
326 outb(0, brd->iobase + 0x4c);
327 break;
328
329 default:
330 break;
331 }
332
333 if (brd->irq)
334 free_irq(brd->irq, brd);
335
336 tasklet_kill(&brd->helper_tasklet);
337
338 if (brd->re_map_membase) {
339 iounmap(brd->re_map_membase);
340 brd->re_map_membase = NULL;
341 }
342
343 for (i = 0; i < MAXPORTS ; i++) {
344 if (brd->channels[i]) {
345 kfree(brd->channels[i]->ch_rqueue);
346 kfree(brd->channels[i]->ch_equeue);
347 kfree(brd->channels[i]->ch_wqueue);
348 kfree(brd->channels[i]);
349 brd->channels[i] = NULL;
350 }
351 }
352
353 dgnc_board[brd->boardnum] = NULL;
354
355 kfree(brd);
356}
357
358/* Driver load/unload functions */
359
360static void cleanup(void)
361{
362 int i;
363 unsigned long flags;
364
365 spin_lock_irqsave(&dgnc_poll_lock, flags);
366 dgnc_poll_stop = 1;
367 spin_unlock_irqrestore(&dgnc_poll_lock, flags);
368
369 /* Turn off poller right away. */
370 del_timer_sync(&dgnc_poll_timer);
371
372 for (i = 0; i < dgnc_num_boards; ++i) {
373 dgnc_cleanup_tty(dgnc_board[i]);
374 dgnc_cleanup_board(dgnc_board[i]);
375 }
376}
377
378static void __exit dgnc_cleanup_module(void)
379{
380 cleanup();
381 pci_unregister_driver(&dgnc_driver);
382}
383
384static int __init dgnc_init_module(void)
385{
386 int rc;
387
388 /* Initialize global stuff */
389 rc = dgnc_start();
390 if (rc < 0)
391 return rc;
392
393 /* Find and configure all the cards */
394 rc = pci_register_driver(&dgnc_driver);
395 if (rc) {
396 pr_warn("WARNING: dgnc driver load failed. No Digi Neo or Classic boards found.\n");
397 cleanup();
398 return rc;
399 }
400 return 0;
401}
402
403module_init(dgnc_init_module);
404module_exit(dgnc_cleanup_module);
diff --git a/drivers/staging/dgnc/dgnc_driver.h b/drivers/staging/dgnc/dgnc_driver.h
deleted file mode 100644
index b4d9f714c60a..000000000000
--- a/drivers/staging/dgnc/dgnc_driver.h
+++ /dev/null
@@ -1,345 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Copyright 2003 Digi International (www.digi.com)
4 * Scott H Kilau <Scott_Kilau at digi dot com>
5 */
6
7#ifndef _DGNC_DRIVER_H
8#define _DGNC_DRIVER_H
9
10#include <linux/types.h>
11#include <linux/tty.h>
12#include <linux/interrupt.h>
13
14#include "digi.h" /* Digi specific ioctl header */
15
16/* Driver identification and error statements */
17#define PROCSTR "dgnc" /* /proc entries */
18#define DEVSTR "/dev/dg/dgnc" /* /dev entries */
19#define DRVSTR "dgnc" /* Driver name string */
20#define DG_PART "40002369_F" /* RPM part number */
21
22#define TRC_TO_CONSOLE 1
23
24/* Number of boards we support at once. */
25#define MAXBOARDS 20
26#define MAXPORTS 8
27#define MAXTTYNAMELEN 200
28
29/* Serial port types */
30#define DGNC_SERIAL 0
31#define DGNC_PRINT 1
32
33#define SERIAL_TYPE_NORMAL 1
34
35#define PORT_NUM(dev) ((dev) & 0x7f)
36#define IS_PRINT(dev) (((dev) & 0xff) >= 0x80)
37
38/* MAX number of stop characters sent when our read queue is getting full */
39#define MAX_STOPS_SENT 5
40
41/* 4 extra for alignment play space */
42#define WRITEBUFLEN ((4096) + 4)
43
44#define dgnc_jiffies_from_ms(a) (((a) * HZ) / 1000)
45
46#ifndef _POSIX_VDISABLE
47#define _POSIX_VDISABLE '\0'
48#endif
49
50/* All the possible states the driver can be while being loaded. */
51enum {
52 DRIVER_INITIALIZED = 0,
53 DRIVER_READY
54};
55
56/* All the possible states the board can be while booting up. */
57enum {
58 BOARD_FAILED = 0,
59 BOARD_FOUND,
60 BOARD_READY
61};
62
63struct dgnc_board;
64struct channel_t;
65
66/**
67 * struct board_ops - Per board operations.
68 */
69struct board_ops {
70 void (*tasklet)(unsigned long data);
71 irqreturn_t (*intr)(int irq, void *voidbrd);
72 void (*uart_init)(struct channel_t *ch);
73 void (*uart_off)(struct channel_t *ch);
74 int (*drain)(struct tty_struct *tty, uint seconds);
75 void (*param)(struct tty_struct *tty);
76 void (*assert_modem_signals)(struct channel_t *ch);
77 void (*flush_uart_write)(struct channel_t *ch);
78 void (*flush_uart_read)(struct channel_t *ch);
79 void (*disable_receiver)(struct channel_t *ch);
80 void (*enable_receiver)(struct channel_t *ch);
81 void (*send_break)(struct channel_t *ch, int msec);
82 void (*send_start_character)(struct channel_t *ch);
83 void (*send_stop_character)(struct channel_t *ch);
84 void (*copy_data_from_queue_to_uart)(struct channel_t *ch);
85 uint (*get_uart_bytes_left)(struct channel_t *ch);
86 void (*send_immediate_char)(struct channel_t *ch, unsigned char c);
87};
88
89/**
90 * struct dgnc_board - Per board information.
91 * @boardnum: Board number (0 - 32).
92 *
93 * @name: Product name.
94 * @pdev: Pointer to the pci_dev structure.
95 * @device: PCI device ID.
96 * @maxports: Maximum ports this board can handle.
97 * @bd_lock: Used to protect board.
98 * @bd_intr_lock: Protect poller tasklet and interrupt routine from each other.
99 * @state: State of the card.
100 * @state_wait: Queue to sleep on for state change.
101 * @helper_tasklet: Poll helper tasklet.
102 * @nasync: Number of ports on card.
103 * @irq: Interrupt request number.
104 * @membase: Start of base memory of the card.
105 * @membase_end: End of base memory of the card.
106 * @iobase: Start of IO base of the card.
107 * @iobase_end: End of IO base of the card.
108 * @bd_uart_offset: Space between each UART.
109 * @channels: array of pointers to our channels.
110 * @serial_driver: Pointer to the serial driver.
111 * @serial_name: Serial driver name.
112 * @print_dirver: Pointer to the print driver.
113 * @print_name: Print driver name.
114 * @bd_dividend: Board/UART's specific dividend.
115 * @bd_ops: Pointer to board operations structure.
116 */
117struct dgnc_board {
118 int boardnum;
119 char *name;
120 struct pci_dev *pdev;
121 u16 device;
122 uint maxports;
123
124 /* used to protect the board */
125 spinlock_t bd_lock;
126
127 /* Protect poller tasklet and interrupt routine from each other. */
128 spinlock_t bd_intr_lock;
129
130 uint state;
131 wait_queue_head_t state_wait;
132
133 struct tasklet_struct helper_tasklet;
134
135 uint nasync;
136
137 uint irq;
138
139 ulong membase;
140 ulong membase_end;
141
142 u8 __iomem *re_map_membase;
143
144 ulong iobase;
145 ulong iobase_end;
146
147 uint bd_uart_offset;
148
149 struct channel_t *channels[MAXPORTS];
150
151 struct tty_driver *serial_driver;
152 char serial_name[200];
153 struct tty_driver *print_driver;
154 char print_name[200];
155
156 uint bd_dividend;
157
158 struct board_ops *bd_ops;
159};
160
161/* Unit flag definitions for un_flags. */
162#define UN_ISOPEN 0x0001 /* Device is open */
163#define UN_CLOSING 0x0002 /* Line is being closed */
164#define UN_IMM 0x0004 /* Service immediately */
165#define UN_BUSY 0x0008 /* Some work this channel */
166#define UN_BREAKI 0x0010 /* Input break received */
167#define UN_PWAIT 0x0020 /* Printer waiting for terminal */
168#define UN_TIME 0x0040 /* Waiting on time */
169#define UN_EMPTY 0x0080 /* Waiting output queue empty */
170#define UN_LOW 0x0100 /* Waiting output low water mark*/
171#define UN_EXCL_OPEN 0x0200 /* Open for exclusive use */
172#define UN_WOPEN 0x0400 /* Device waiting for open */
173#define UN_WIOCTL 0x0800 /* Device waiting for open */
174#define UN_HANGUP 0x8000 /* Carrier lost */
175
176struct device;
177
178/**
179 * struct un_t - terminal or printer unit
180 * @un_open_count: Counter of opens to port.
181 * @un_tty: Pointer to unit tty structure.
182 * @un_flags: Unit flags.
183 * @un_flags_wait: Place to sleep to wait on unit.
184 * @un_dev: Minor device number.
185 */
186struct un_t {
187 struct channel_t *un_ch;
188 uint un_type;
189 uint un_open_count;
190 struct tty_struct *un_tty;
191 uint un_flags;
192 wait_queue_head_t un_flags_wait;
193 uint un_dev;
194 struct device *un_sysfs;
195};
196
197/* Device flag definitions for ch_flags. */
198#define CH_PRON 0x0001 /* Printer on string */
199#define CH_STOP 0x0002 /* Output is stopped */
200#define CH_STOPI 0x0004 /* Input is stopped */
201#define CH_CD 0x0008 /* Carrier is present */
202#define CH_FCAR 0x0010 /* Carrier forced on */
203#define CH_HANGUP 0x0020 /* Hangup received */
204
205#define CH_RECEIVER_OFF 0x0040 /* Receiver is off */
206#define CH_OPENING 0x0080 /* Port in fragile open state */
207#define CH_CLOSING 0x0100 /* Port in fragile close state */
208#define CH_FIFO_ENABLED 0x0200 /* Port has FIFOs enabled */
209#define CH_TX_FIFO_EMPTY 0x0400 /* TX Fifo is completely empty */
210#define CH_TX_FIFO_LWM 0x0800 /* TX Fifo is below Low Water */
211#define CH_BREAK_SENDING 0x1000 /* Break is being sent */
212#define CH_LOOPBACK 0x2000 /* Channel is in lookback mode */
213#define CH_BAUD0 0x08000 /* Used for checking B0 transitions */
214#define CH_FORCED_STOP 0x20000 /* Output is forcibly stopped */
215#define CH_FORCED_STOPI 0x40000 /* Input is forcibly stopped */
216
217/* Our Read/Error/Write queue sizes */
218#define RQUEUEMASK 0x1FFF /* 8 K - 1 */
219#define EQUEUEMASK 0x1FFF /* 8 K - 1 */
220#define WQUEUEMASK 0x0FFF /* 4 K - 1 */
221#define RQUEUESIZE (RQUEUEMASK + 1)
222#define EQUEUESIZE RQUEUESIZE
223#define WQUEUESIZE (WQUEUEMASK + 1)
224
225/**
226 * struct channel_t - Channel information.
227 * @dgnc_board: Pointer to board structure.
228 * @ch_bd: Transparent print structure.
229 * @ch_tun: Terminal unit information.
230 * @ch_pun: Printer unit information.
231 * @ch_lock: Provide for serialization.
232 * @ch_flags_wait: Channel flags wait queue.
233 * @ch_portnum: Port number, 0 offset.
234 * @ch_open_count: Open count.
235 * @ch_flags: Channel flags.
236 * @ch_close_delay: How long we should drop RTS/DTR for.
237 * @ch_cpstime: Time for CPS calculations.
238 * @ch_c_iflag: Channel iflags.
239 * @ch_c_cflag: Channel cflags.
240 * @ch_c_oflag: Channel oflags.
241 * @ch_c_lflag: Channel lflags.
242 * @ch_stopc: Stop character.
243 * @ch_startc: Start character.
244 * @ch_old_baud: Cache of the current baud rate.
245 * @ch_custom_speed: Custom baud rate, if set.
246 * @ch_wopen: Waiting for open process count.
247 * @ch_mostat: FEP output modem status.
248 * @ch_mistat: FEP input modem status.
249 * @ch_cls_uart: Pointer to the mapped cls UART struct
250 * @ch_cached_lsr: Cached value of the LSR register.
251 * @ch_rqueue: Read queue buffer, malloc'ed.
252 * @ch_r_head: Head location of the read queue.
253 * @ch_r_tail: Tail location of the read queue.
254 * @ch_equeue: Error queue buffer, malloc'ed.
255 * @ch_e_head: Head location of the error queue.
256 * @ch_e_tail: Tail location of the error queue.
257 * @ch_wqueue: Write queue buffer, malloc'ed.
258 * @ch_w_head: Head location of the write queue.
259 * @ch_w_tail: Tail location of the write queue.
260 * @ch_rxcount: Total of data received so far.
261 * @ch_txcount: Total of data transmitted so far.
262 * @ch_r_tlevel: Receive trigger level.
263 * @ch_t_tlevel: Transmit trigger level.
264 * @ch_r_watermark: Receive water mark.
265 * @ch_stop_sending_break: Time we should STOP sending a break.
266 * @ch_stops_sent: How many times I have send a stop character to try
267 * to stop the other guy sending.
268 * @ch_err_parity: Count of parity
269 * @ch_err_frame: Count of framing errors on channel.
270 * @ch_err_break: Count of breaks on channel.
271 * @ch_err_overrun: Count of overruns on channel.
272 * @ch_xon_sends: Count of xons transmitted.
273 * @ch_xoff_sends: Count of xoffs transmitted.
274 */
275struct channel_t {
276 struct dgnc_board *ch_bd;
277 struct digi_t ch_digi;
278 struct un_t ch_tun;
279 struct un_t ch_pun;
280
281 spinlock_t ch_lock; /* provide for serialization */
282 wait_queue_head_t ch_flags_wait;
283
284 uint ch_portnum;
285 uint ch_open_count;
286 uint ch_flags;
287
288 ulong ch_close_delay;
289
290 ulong ch_cpstime;
291
292 tcflag_t ch_c_iflag;
293 tcflag_t ch_c_cflag;
294 tcflag_t ch_c_oflag;
295 tcflag_t ch_c_lflag;
296 unsigned char ch_stopc;
297 unsigned char ch_startc;
298
299 uint ch_old_baud;
300 uint ch_custom_speed;
301
302 uint ch_wopen;
303
304 unsigned char ch_mostat;
305 unsigned char ch_mistat;
306
307 struct cls_uart_struct __iomem *ch_cls_uart;
308
309 unsigned char ch_cached_lsr;
310
311 unsigned char *ch_rqueue;
312 ushort ch_r_head;
313 ushort ch_r_tail;
314
315 unsigned char *ch_equeue;
316 ushort ch_e_head;
317 ushort ch_e_tail;
318
319 unsigned char *ch_wqueue;
320 ushort ch_w_head;
321 ushort ch_w_tail;
322
323 ulong ch_rxcount;
324 ulong ch_txcount;
325
326 unsigned char ch_r_tlevel;
327 unsigned char ch_t_tlevel;
328
329 unsigned char ch_r_watermark;
330
331 ulong ch_stop_sending_break;
332 uint ch_stops_sent;
333
334 ulong ch_err_parity;
335 ulong ch_err_frame;
336 ulong ch_err_break;
337 ulong ch_err_overrun;
338
339 ulong ch_xon_sends;
340 ulong ch_xoff_sends;
341};
342
343extern struct dgnc_board *dgnc_board[MAXBOARDS];/* Array of boards */
344
345#endif /* _DGNC_DRIVER_H */
diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c
deleted file mode 100644
index b8f865018950..000000000000
--- a/drivers/staging/dgnc/dgnc_tty.c
+++ /dev/null
@@ -1,2372 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2003 Digi International (www.digi.com)
4 * Scott H Kilau <Scott_Kilau at digi dot com>
5 */
6
7/*
8 * This file implements the tty driver functionality for the
9 * Neo and ClassicBoard PCI based product lines.
10 */
11
12#include <linux/kernel.h>
13#include <linux/sched/signal.h> /* For jiffies, task states, etc. */
14#include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
15#include <linux/module.h>
16#include <linux/ctype.h>
17#include <linux/tty.h>
18#include <linux/tty_flip.h>
19#include <linux/types.h>
20#include <linux/serial_reg.h>
21#include <linux/slab.h>
22#include <linux/delay.h> /* For udelay */
23#include <linux/uaccess.h> /* For copy_from_user/copy_to_user */
24#include <linux/pci.h>
25#include "dgnc_driver.h"
26#include "dgnc_tty.h"
27#include "dgnc_cls.h"
28
29/* Default transparent print information. */
30
31static const struct digi_t dgnc_digi_init = {
32 .digi_flags = DIGI_COOK, /* Flags */
33 .digi_maxcps = 100, /* Max CPS */
34 .digi_maxchar = 50, /* Max chars in print queue */
35 .digi_bufsize = 100, /* Printer buffer size */
36 .digi_onlen = 4, /* size of printer on string */
37 .digi_offlen = 4, /* size of printer off string */
38 .digi_onstr = "\033[5i", /* ANSI printer on string ] */
39 .digi_offstr = "\033[4i", /* ANSI printer off string ] */
40 .digi_term = "ansi" /* default terminal type */
41};
42
43static int dgnc_tty_open(struct tty_struct *tty, struct file *file);
44static void dgnc_tty_close(struct tty_struct *tty, struct file *file);
45static int dgnc_block_til_ready(struct tty_struct *tty, struct file *file,
46 struct channel_t *ch);
47static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
48 unsigned long arg);
49static int dgnc_tty_digigeta(struct tty_struct *tty,
50 struct digi_t __user *retinfo);
51static int dgnc_tty_digiseta(struct tty_struct *tty,
52 struct digi_t __user *new_info);
53static int dgnc_tty_write_room(struct tty_struct *tty);
54static int dgnc_tty_put_char(struct tty_struct *tty, unsigned char c);
55static int dgnc_tty_chars_in_buffer(struct tty_struct *tty);
56static void dgnc_tty_start(struct tty_struct *tty);
57static void dgnc_tty_stop(struct tty_struct *tty);
58static void dgnc_tty_throttle(struct tty_struct *tty);
59static void dgnc_tty_unthrottle(struct tty_struct *tty);
60static void dgnc_tty_flush_chars(struct tty_struct *tty);
61static void dgnc_tty_flush_buffer(struct tty_struct *tty);
62static void dgnc_tty_hangup(struct tty_struct *tty);
63static int dgnc_tty_tiocmget(struct tty_struct *tty);
64static int dgnc_tty_tiocmset(struct tty_struct *tty, unsigned int set,
65 unsigned int clear);
66static int dgnc_tty_send_break(struct tty_struct *tty, int msec);
67static void dgnc_tty_wait_until_sent(struct tty_struct *tty, int timeout);
68static int dgnc_tty_write(struct tty_struct *tty, const unsigned char *buf,
69 int count);
70static void dgnc_tty_set_termios(struct tty_struct *tty,
71 struct ktermios *old_termios);
72static void dgnc_tty_send_xchar(struct tty_struct *tty, char ch);
73static void dgnc_set_signal_low(struct channel_t *ch, const unsigned char line);
74static void dgnc_wake_up_unit(struct un_t *unit);
75
76static const struct tty_operations dgnc_tty_ops = {
77 .open = dgnc_tty_open,
78 .close = dgnc_tty_close,
79 .write = dgnc_tty_write,
80 .write_room = dgnc_tty_write_room,
81 .flush_buffer = dgnc_tty_flush_buffer,
82 .chars_in_buffer = dgnc_tty_chars_in_buffer,
83 .flush_chars = dgnc_tty_flush_chars,
84 .ioctl = dgnc_tty_ioctl,
85 .set_termios = dgnc_tty_set_termios,
86 .stop = dgnc_tty_stop,
87 .start = dgnc_tty_start,
88 .throttle = dgnc_tty_throttle,
89 .unthrottle = dgnc_tty_unthrottle,
90 .hangup = dgnc_tty_hangup,
91 .put_char = dgnc_tty_put_char,
92 .tiocmget = dgnc_tty_tiocmget,
93 .tiocmset = dgnc_tty_tiocmset,
94 .break_ctl = dgnc_tty_send_break,
95 .wait_until_sent = dgnc_tty_wait_until_sent,
96 .send_xchar = dgnc_tty_send_xchar
97};
98
99/* TTY Initialization/Cleanup Functions */
100
101static struct tty_driver *dgnc_tty_create(char *serial_name, uint maxports,
102 int major, int minor)
103{
104 int rc;
105 struct tty_driver *drv;
106
107 drv = tty_alloc_driver(maxports,
108 TTY_DRIVER_REAL_RAW |
109 TTY_DRIVER_DYNAMIC_DEV |
110 TTY_DRIVER_HARDWARE_BREAK);
111 if (IS_ERR(drv))
112 return drv;
113
114 drv->name = serial_name;
115 drv->name_base = 0;
116 drv->major = major;
117 drv->minor_start = minor;
118 drv->type = TTY_DRIVER_TYPE_SERIAL;
119 drv->subtype = SERIAL_TYPE_NORMAL;
120 drv->init_termios = tty_std_termios;
121 drv->init_termios.c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL);
122 drv->init_termios.c_ispeed = 9600;
123 drv->init_termios.c_ospeed = 9600;
124 drv->driver_name = DRVSTR;
125 /*
126 * Entry points for driver. Called by the kernel from
127 * tty_io.c and n_tty.c.
128 */
129 tty_set_operations(drv, &dgnc_tty_ops);
130 rc = tty_register_driver(drv);
131 if (rc < 0) {
132 put_tty_driver(drv);
133 return ERR_PTR(rc);
134 }
135 return drv;
136}
137
138static void dgnc_tty_free(struct tty_driver *drv)
139{
140 tty_unregister_driver(drv);
141 put_tty_driver(drv);
142}
143
144/**
145 * dgnc_tty_register() - Init the tty subsystem for this board.
146 */
147int dgnc_tty_register(struct dgnc_board *brd)
148{
149 int rc;
150
151 snprintf(brd->serial_name, MAXTTYNAMELEN, "tty_dgnc_%d_",
152 brd->boardnum);
153
154 brd->serial_driver = dgnc_tty_create(brd->serial_name,
155 brd->maxports, 0, 0);
156 if (IS_ERR(brd->serial_driver)) {
157 rc = PTR_ERR(brd->serial_driver);
158 dev_dbg(&brd->pdev->dev, "Can't register tty device (%d)\n",
159 rc);
160 return rc;
161 }
162
163 snprintf(brd->print_name, MAXTTYNAMELEN, "pr_dgnc_%d_", brd->boardnum);
164 brd->print_driver = dgnc_tty_create(brd->print_name, brd->maxports,
165 0x80,
166 brd->serial_driver->major);
167 if (IS_ERR(brd->print_driver)) {
168 rc = PTR_ERR(brd->print_driver);
169 dev_dbg(&brd->pdev->dev,
170 "Can't register Transparent Print device(%d)\n", rc);
171 dgnc_tty_free(brd->serial_driver);
172 return rc;
173 }
174 return 0;
175}
176
177void dgnc_tty_unregister(struct dgnc_board *brd)
178{
179 dgnc_tty_free(brd->print_driver);
180 dgnc_tty_free(brd->serial_driver);
181}
182
183/**
184 * dgnc_tty_init() - Initialize the tty subsystem.
185 *
186 * Called once per board after board has been downloaded and initialized.
187 */
188int dgnc_tty_init(struct dgnc_board *brd)
189{
190 int i;
191 int rc;
192 void __iomem *vaddr;
193 struct channel_t *ch;
194
195 if (!brd)
196 return -ENXIO;
197
198 /* Initialize board structure elements. */
199
200 vaddr = brd->re_map_membase;
201
202 brd->nasync = brd->maxports;
203
204 for (i = 0; i < brd->nasync; i++) {
205 brd->channels[i] = kzalloc(sizeof(*brd->channels[i]),
206 GFP_KERNEL);
207 if (!brd->channels[i]) {
208 rc = -ENOMEM;
209 goto err_free_channels;
210 }
211 }
212
213 ch = brd->channels[0];
214 vaddr = brd->re_map_membase;
215
216 /* Set up channel variables */
217 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
218 spin_lock_init(&ch->ch_lock);
219
220 ch->ch_tun.un_ch = ch;
221 ch->ch_tun.un_type = DGNC_SERIAL;
222 ch->ch_tun.un_dev = i;
223
224 ch->ch_pun.un_ch = ch;
225 ch->ch_pun.un_type = DGNC_PRINT;
226 ch->ch_pun.un_dev = i + 128;
227
228 ch->ch_cls_uart = vaddr + (brd->bd_uart_offset * i);
229
230 ch->ch_bd = brd;
231 ch->ch_portnum = i;
232 ch->ch_digi = dgnc_digi_init;
233
234 /* .25 second delay */
235 ch->ch_close_delay = 250;
236
237 init_waitqueue_head(&ch->ch_flags_wait);
238 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
239 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
240
241 {
242 struct device *classp;
243
244 classp = tty_register_device(brd->serial_driver, i,
245 &ch->ch_bd->pdev->dev);
246 ch->ch_tun.un_sysfs = classp;
247
248 classp = tty_register_device(brd->print_driver, i,
249 &ch->ch_bd->pdev->dev);
250 ch->ch_pun.un_sysfs = classp;
251 }
252 }
253
254 return 0;
255
256err_free_channels:
257 for (i = i - 1; i >= 0; --i) {
258 kfree(brd->channels[i]);
259 brd->channels[i] = NULL;
260 }
261
262 return rc;
263}
264
265/**
266 * dgnc_cleanup_tty() - Cleanup driver.
267 *
268 * Uninitialize the TTY portion of this driver. Free all memory and
269 * resources.
270 */
271void dgnc_cleanup_tty(struct dgnc_board *brd)
272{
273 int i = 0;
274
275 for (i = 0; i < brd->nasync; i++)
276 tty_unregister_device(brd->serial_driver, i);
277
278 tty_unregister_driver(brd->serial_driver);
279
280 for (i = 0; i < brd->nasync; i++)
281 tty_unregister_device(brd->print_driver, i);
282
283 tty_unregister_driver(brd->print_driver);
284
285 put_tty_driver(brd->serial_driver);
286 put_tty_driver(brd->print_driver);
287}
288
289/**
290 * dgnc_wmove() - Write data to transmit queue.
291 * @ch: Pointer to channel structure.
292 * @buf: Pointer to characters to be moved.
293 * @n: Number of characters to move.
294 */
295static void dgnc_wmove(struct channel_t *ch, char *buf, uint n)
296{
297 int remain;
298 uint head;
299
300 if (!ch)
301 return;
302
303 head = ch->ch_w_head & WQUEUEMASK;
304
305 /*
306 * If the write wraps over the top of the circular buffer,
307 * move the portion up to the wrap point, and reset the
308 * pointers to the bottom.
309 */
310 remain = WQUEUESIZE - head;
311
312 if (n >= remain) {
313 n -= remain;
314 memcpy(ch->ch_wqueue + head, buf, remain);
315 head = 0;
316 buf += remain;
317 }
318
319 if (n > 0) {
320 /* Move rest of data. */
321 remain = n;
322 memcpy(ch->ch_wqueue + head, buf, remain);
323 head += remain;
324 }
325
326 head &= WQUEUEMASK;
327 ch->ch_w_head = head;
328}
329
330/**
331 * dgnc_input() - Process received data.
332 * @ch: Pointer to channel structure.
333 */
334void dgnc_input(struct channel_t *ch)
335{
336 struct dgnc_board *bd;
337 struct tty_struct *tp;
338 struct tty_ldisc *ld = NULL;
339 uint rmask;
340 ushort head;
341 ushort tail;
342 int data_len;
343 unsigned long flags;
344 int flip_len;
345 int len = 0;
346 int n = 0;
347 int s = 0;
348 int i = 0;
349
350 if (!ch)
351 return;
352
353 tp = ch->ch_tun.un_tty;
354
355 bd = ch->ch_bd;
356 if (!bd)
357 return;
358
359 spin_lock_irqsave(&ch->ch_lock, flags);
360
361 rmask = RQUEUEMASK;
362 head = ch->ch_r_head & rmask;
363 tail = ch->ch_r_tail & rmask;
364 data_len = (head - tail) & rmask;
365
366 if (data_len == 0)
367 goto exit_unlock;
368
369 /*
370 * If the device is not open, or CREAD is off,
371 * flush input data and return immediately.
372 */
373 if (!tp ||
374 !(ch->ch_tun.un_flags & UN_ISOPEN) ||
375 !C_CREAD(tp) ||
376 (ch->ch_tun.un_flags & UN_CLOSING)) {
377 ch->ch_r_head = tail;
378
379 /* Force queue flow control to be released, if needed */
380 dgnc_check_queue_flow_control(ch);
381
382 goto exit_unlock;
383 }
384
385 if (ch->ch_flags & CH_FORCED_STOPI)
386 goto exit_unlock;
387
388 flip_len = TTY_FLIPBUF_SIZE;
389
390 len = min(data_len, flip_len);
391 len = min(len, (N_TTY_BUF_SIZE - 1));
392
393 ld = tty_ldisc_ref(tp);
394 if (!ld) {
395 len = 0;
396 } else {
397 if (!ld->ops->receive_buf) {
398 ch->ch_r_head = ch->ch_r_tail;
399 len = 0;
400 }
401 }
402
403 if (len <= 0)
404 goto exit_unlock;
405
406 /*
407 * The tty layer in the kernel has changed in 2.6.16+.
408 *
409 * The flip buffers in the tty structure are no longer exposed,
410 * and probably will be going away eventually.
411 *
412 * If we are completely raw, we don't need to go through a lot
413 * of the tty layers that exist.
414 * In this case, we take the shortest and fastest route we
415 * can to relay the data to the user.
416 *
417 * On the other hand, if we are not raw, we need to go through
418 * the new 2.6.16+ tty layer, which has its API more well defined.
419 */
420 len = tty_buffer_request_room(tp->port, len);
421 n = len;
422
423 /*
424 * n now contains the most amount of data we can copy,
425 * bounded either by how much the Linux tty layer can handle,
426 * or the amount of data the card actually has pending...
427 */
428 while (n) {
429 unsigned char *ch_pos = ch->ch_equeue + tail;
430
431 s = ((head >= tail) ? head : RQUEUESIZE) - tail;
432 s = min(s, n);
433
434 if (s <= 0)
435 break;
436
437 /*
438 * If conditions are such that ld needs to see all
439 * UART errors, we will have to walk each character
440 * and error byte and send them to the buffer one at
441 * a time.
442 */
443 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
444 for (i = 0; i < s; i++) {
445 unsigned char ch = *(ch_pos + i);
446 char flag = TTY_NORMAL;
447
448 if (ch & UART_LSR_BI)
449 flag = TTY_BREAK;
450 else if (ch & UART_LSR_PE)
451 flag = TTY_PARITY;
452 else if (ch & UART_LSR_FE)
453 flag = TTY_FRAME;
454
455 tty_insert_flip_char(tp->port, ch, flag);
456 }
457 } else {
458 tty_insert_flip_string(tp->port, ch_pos, s);
459 }
460
461 tail += s;
462 n -= s;
463 /* Flip queue if needed */
464 tail &= rmask;
465 }
466
467 ch->ch_r_tail = tail & rmask;
468 ch->ch_e_tail = tail & rmask;
469 dgnc_check_queue_flow_control(ch);
470 spin_unlock_irqrestore(&ch->ch_lock, flags);
471
472 /* Tell the tty layer its okay to "eat" the data now */
473 tty_flip_buffer_push(tp->port);
474
475 if (ld)
476 tty_ldisc_deref(ld);
477 return;
478
479exit_unlock:
480 spin_unlock_irqrestore(&ch->ch_lock, flags);
481 if (ld)
482 tty_ldisc_deref(ld);
483}
484
485/**
486 * dgnc_carrier()
487 *
488 * Determines when CARRIER changes state and takes appropriate
489 * action.
490 */
491void dgnc_carrier(struct channel_t *ch)
492{
493 int virt_carrier = 0;
494 int phys_carrier = 0;
495
496 if (!ch)
497 return;
498
499 if (ch->ch_mistat & UART_MSR_DCD)
500 phys_carrier = 1;
501
502 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD)
503 virt_carrier = 1;
504
505 if (ch->ch_c_cflag & CLOCAL)
506 virt_carrier = 1;
507
508 /* Test for a VIRTUAL carrier transition to HIGH. */
509
510 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
511 /*
512 * When carrier rises, wake any threads waiting
513 * for carrier in the open routine.
514 */
515 if (waitqueue_active(&ch->ch_flags_wait))
516 wake_up_interruptible(&ch->ch_flags_wait);
517 }
518
519 /* Test for a PHYSICAL carrier transition to HIGH. */
520
521 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
522 /*
523 * When carrier rises, wake any threads waiting
524 * for carrier in the open routine.
525 */
526 if (waitqueue_active(&ch->ch_flags_wait))
527 wake_up_interruptible(&ch->ch_flags_wait);
528 }
529
530 /*
531 * Test for a PHYSICAL transition to low, so long as we aren't
532 * currently ignoring physical transitions (which is what "virtual
533 * carrier" indicates).
534 *
535 * The transition of the virtual carrier to low really doesn't
536 * matter... it really only means "ignore carrier state", not
537 * "make pretend that carrier is there".
538 */
539 if ((virt_carrier == 0) && ((ch->ch_flags & CH_CD) != 0) &&
540 (phys_carrier == 0)) {
541 /*
542 * When carrier drops:
543 *
544 * Drop carrier on all open units.
545 *
546 * Flush queues, waking up any task waiting in the
547 * line discipline.
548 *
549 * Send a hangup to the control terminal.
550 *
551 * Enable all select calls.
552 */
553 if (waitqueue_active(&ch->ch_flags_wait))
554 wake_up_interruptible(&ch->ch_flags_wait);
555
556 if (ch->ch_tun.un_open_count > 0)
557 tty_hangup(ch->ch_tun.un_tty);
558
559 if (ch->ch_pun.un_open_count > 0)
560 tty_hangup(ch->ch_pun.un_tty);
561 }
562
563 /* Make sure that our cached values reflect the current reality. */
564
565 if (virt_carrier == 1)
566 ch->ch_flags |= CH_FCAR;
567 else
568 ch->ch_flags &= ~CH_FCAR;
569
570 if (phys_carrier == 1)
571 ch->ch_flags |= CH_CD;
572 else
573 ch->ch_flags &= ~CH_CD;
574}
575
576/* Assign the custom baud rate to the channel structure */
577static void dgnc_set_custom_speed(struct channel_t *ch, uint newrate)
578{
579 int testdiv;
580 int testrate_high;
581 int testrate_low;
582 int deltahigh;
583 int deltalow;
584
585 if (newrate <= 0) {
586 ch->ch_custom_speed = 0;
587 return;
588 }
589
590 /*
591 * Since the divisor is stored in a 16-bit integer, we make sure
592 * we don't allow any rates smaller than a 16-bit integer would allow.
593 * And of course, rates above the dividend won't fly.
594 */
595 if (newrate && newrate < ((ch->ch_bd->bd_dividend / 0xFFFF) + 1))
596 newrate = (ch->ch_bd->bd_dividend / 0xFFFF) + 1;
597
598 if (newrate && newrate > ch->ch_bd->bd_dividend)
599 newrate = ch->ch_bd->bd_dividend;
600
601 if (newrate > 0) {
602 testdiv = ch->ch_bd->bd_dividend / newrate;
603
604 /*
605 * If we try to figure out what rate the board would use
606 * with the test divisor, it will be either equal or higher
607 * than the requested baud rate. If we then determine the
608 * rate with a divisor one higher, we will get the next lower
609 * supported rate below the requested.
610 */
611 testrate_high = ch->ch_bd->bd_dividend / testdiv;
612 testrate_low = ch->ch_bd->bd_dividend / (testdiv + 1);
613
614 /*
615 * If the rate for the requested divisor is correct, just
616 * use it and be done.
617 */
618 if (testrate_high != newrate) {
619 /*
620 * Otherwise, pick the rate that is closer
621 * (i.e. whichever rate has a smaller delta).
622 */
623 deltahigh = testrate_high - newrate;
624 deltalow = newrate - testrate_low;
625
626 if (deltahigh < deltalow)
627 newrate = testrate_high;
628 else
629 newrate = testrate_low;
630 }
631 }
632
633 ch->ch_custom_speed = newrate;
634}
635
636void dgnc_check_queue_flow_control(struct channel_t *ch)
637{
638 int qleft;
639
640 qleft = ch->ch_r_tail - ch->ch_r_head - 1;
641 if (qleft < 0)
642 qleft += RQUEUEMASK + 1;
643
644 /*
645 * Check to see if we should enforce flow control on our queue because
646 * the ld (or user) isn't reading data out of our queue fast enuf.
647 *
648 * NOTE: This is done based on what the current flow control of the
649 * port is set for.
650 *
651 * 1) HWFLOW (RTS) - Turn off the UART's Receive interrupt.
652 * This will cause the UART's FIFO to back up, and force
653 * the RTS signal to be dropped.
654 * 2) SWFLOW (IXOFF) - Keep trying to send a stop character to
655 * the other side, in hopes it will stop sending data to us.
656 * 3) NONE - Nothing we can do. We will simply drop any extra data
657 * that gets sent into us when the queue fills up.
658 */
659 if (qleft < 256) {
660 /* HWFLOW */
661 if (ch->ch_digi.digi_flags & CTSPACE ||
662 ch->ch_c_cflag & CRTSCTS) {
663 if (!(ch->ch_flags & CH_RECEIVER_OFF)) {
664 ch->ch_bd->bd_ops->disable_receiver(ch);
665 ch->ch_flags |= (CH_RECEIVER_OFF);
666 }
667 }
668 /* SWFLOW */
669 else if (ch->ch_c_iflag & IXOFF) {
670 if (ch->ch_stops_sent <= MAX_STOPS_SENT) {
671 ch->ch_bd->bd_ops->send_stop_character(ch);
672 ch->ch_stops_sent++;
673 }
674 }
675 }
676
677 /*
678 * Check to see if we should unenforce flow control because
679 * ld (or user) finally read enuf data out of our queue.
680 *
681 * NOTE: This is done based on what the current flow control of the
682 * port is set for.
683 *
684 * 1) HWFLOW (RTS) - Turn back on the UART's Receive interrupt.
685 * This will cause the UART's FIFO to raise RTS back up,
686 * which will allow the other side to start sending data again.
687 * 2) SWFLOW (IXOFF) - Send a start character to
688 * the other side, so it will start sending data to us again.
689 * 3) NONE - Do nothing. Since we didn't do anything to turn off the
690 * other side, we don't need to do anything now.
691 */
692 if (qleft > (RQUEUESIZE / 2)) {
693 /* HWFLOW */
694 if (ch->ch_digi.digi_flags & RTSPACE ||
695 ch->ch_c_cflag & CRTSCTS) {
696 if (ch->ch_flags & CH_RECEIVER_OFF) {
697 ch->ch_bd->bd_ops->enable_receiver(ch);
698 ch->ch_flags &= ~(CH_RECEIVER_OFF);
699 }
700 }
701 /* SWFLOW */
702 else if (ch->ch_c_iflag & IXOFF && ch->ch_stops_sent) {
703 ch->ch_stops_sent = 0;
704 ch->ch_bd->bd_ops->send_start_character(ch);
705 }
706 }
707}
708
709static void dgnc_set_signal_low(struct channel_t *ch, const unsigned char sig)
710{
711 ch->ch_mostat &= ~(sig);
712 ch->ch_bd->bd_ops->assert_modem_signals(ch);
713}
714
715void dgnc_wakeup_writes(struct channel_t *ch)
716{
717 int qlen = 0;
718 unsigned long flags;
719
720 if (!ch)
721 return;
722
723 spin_lock_irqsave(&ch->ch_lock, flags);
724
725 /* If channel now has space, wake up anyone waiting on the condition. */
726
727 qlen = ch->ch_w_head - ch->ch_w_tail;
728 if (qlen < 0)
729 qlen += WQUEUESIZE;
730
731 if (qlen >= (WQUEUESIZE - 256)) {
732 spin_unlock_irqrestore(&ch->ch_lock, flags);
733 return;
734 }
735
736 if (ch->ch_tun.un_flags & UN_ISOPEN) {
737 tty_wakeup(ch->ch_tun.un_tty);
738
739 /*
740 * If unit is set to wait until empty, check to make sure
741 * the queue AND FIFO are both empty.
742 */
743 if (ch->ch_tun.un_flags & UN_EMPTY) {
744 if ((qlen == 0) &&
745 (ch->ch_bd->bd_ops->get_uart_bytes_left(ch) == 0)) {
746 ch->ch_tun.un_flags &= ~(UN_EMPTY);
747
748 /*
749 * If RTS Toggle mode is on, whenever
750 * the queue and UART is empty, keep RTS low.
751 */
752 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
753 dgnc_set_signal_low(ch, UART_MCR_RTS);
754
755 /*
756 * If DTR Toggle mode is on, whenever
757 * the queue and UART is empty, keep DTR low.
758 */
759 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
760 dgnc_set_signal_low(ch, UART_MCR_DTR);
761 }
762 }
763
764 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
765 }
766
767 if (ch->ch_pun.un_flags & UN_ISOPEN) {
768 tty_wakeup(ch->ch_pun.un_tty);
769
770 /*
771 * If unit is set to wait until empty, check to make sure
772 * the queue AND FIFO are both empty.
773 */
774 if (ch->ch_pun.un_flags & UN_EMPTY) {
775 if ((qlen == 0) &&
776 (ch->ch_bd->bd_ops->get_uart_bytes_left(ch) == 0))
777 ch->ch_pun.un_flags &= ~(UN_EMPTY);
778 }
779
780 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
781 }
782
783 spin_unlock_irqrestore(&ch->ch_lock, flags);
784}
785
786static struct dgnc_board *find_board_by_major(unsigned int major)
787{
788 int i;
789
790 for (i = 0; i < MAXBOARDS; i++) {
791 struct dgnc_board *brd = dgnc_board[i];
792
793 if (!brd)
794 return NULL;
795
796 if (major == brd->serial_driver->major ||
797 major == brd->print_driver->major)
798 return brd;
799 }
800
801 return NULL;
802}
803
804/* TTY Entry points and helper functions */
805
806static int dgnc_tty_open(struct tty_struct *tty, struct file *file)
807{
808 struct dgnc_board *brd;
809 struct channel_t *ch;
810 struct un_t *un;
811 uint major = 0;
812 uint minor = 0;
813 int rc = 0;
814 unsigned long flags;
815
816 rc = 0;
817
818 major = MAJOR(tty_devnum(tty));
819 minor = MINOR(tty_devnum(tty));
820
821 if (major > 255)
822 return -ENXIO;
823
824 brd = find_board_by_major(major);
825 if (!brd)
826 return -ENXIO;
827
828 rc = wait_event_interruptible(brd->state_wait,
829 (brd->state & BOARD_READY));
830 if (rc)
831 return rc;
832
833 spin_lock_irqsave(&brd->bd_lock, flags);
834
835 if (PORT_NUM(minor) >= brd->nasync) {
836 rc = -ENXIO;
837 goto err_brd_unlock;
838 }
839
840 ch = brd->channels[PORT_NUM(minor)];
841 if (!ch) {
842 rc = -ENXIO;
843 goto err_brd_unlock;
844 }
845
846 spin_unlock_irqrestore(&brd->bd_lock, flags);
847
848 spin_lock_irqsave(&ch->ch_lock, flags);
849
850 /* Figure out our type */
851 if (!IS_PRINT(minor)) {
852 un = &brd->channels[PORT_NUM(minor)]->ch_tun;
853 un->un_type = DGNC_SERIAL;
854 } else if (IS_PRINT(minor)) {
855 un = &brd->channels[PORT_NUM(minor)]->ch_pun;
856 un->un_type = DGNC_PRINT;
857 } else {
858 rc = -ENXIO;
859 goto err_ch_unlock;
860 }
861
862 /*
863 * If the port is still in a previous open, and in a state
864 * where we simply cannot safely keep going, wait until the
865 * state clears.
866 */
867 spin_unlock_irqrestore(&ch->ch_lock, flags);
868
869 rc = wait_event_interruptible(ch->ch_flags_wait,
870 ((ch->ch_flags & CH_OPENING) == 0));
871 /* If ret is non-zero, user ctrl-c'ed us */
872 if (rc)
873 return -EINTR;
874
875 /*
876 * If either unit is in the middle of the fragile part of close,
877 * we just cannot touch the channel safely.
878 * Go to sleep, knowing that when the channel can be
879 * touched safely, the close routine will signal the
880 * ch_flags_wait to wake us back up.
881 */
882 rc = wait_event_interruptible(ch->ch_flags_wait,
883 !((ch->ch_tun.un_flags |
884 ch->ch_pun.un_flags) & UN_CLOSING));
885 /* If ret is non-zero, user ctrl-c'ed us */
886 if (rc)
887 return -EINTR;
888
889 spin_lock_irqsave(&ch->ch_lock, flags);
890
891 tty->driver_data = un;
892
893 /* Initialize tty's */
894
895 if (!(un->un_flags & UN_ISOPEN)) {
896 un->un_tty = tty;
897
898 /* Maybe do something here to the TTY struct as well? */
899 }
900
901 /*
902 * Allocate channel buffers for read/write/error.
903 * Set flag, so we don't get trounced on.
904 */
905 ch->ch_flags |= (CH_OPENING);
906
907 spin_unlock_irqrestore(&ch->ch_lock, flags);
908
909 if (!ch->ch_rqueue)
910 ch->ch_rqueue = kzalloc(RQUEUESIZE, GFP_KERNEL);
911 if (!ch->ch_equeue)
912 ch->ch_equeue = kzalloc(EQUEUESIZE, GFP_KERNEL);
913 if (!ch->ch_wqueue)
914 ch->ch_wqueue = kzalloc(WQUEUESIZE, GFP_KERNEL);
915
916 if (!ch->ch_rqueue || !ch->ch_equeue || !ch->ch_wqueue) {
917 kfree(ch->ch_rqueue);
918 kfree(ch->ch_equeue);
919 kfree(ch->ch_wqueue);
920 return -ENOMEM;
921 }
922
923 spin_lock_irqsave(&ch->ch_lock, flags);
924
925 ch->ch_flags &= ~(CH_OPENING);
926 wake_up_interruptible(&ch->ch_flags_wait);
927
928 /* Initialize if neither terminal or printer is open. */
929
930 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
931 /* Flush input queues. */
932 ch->ch_r_head = 0;
933 ch->ch_r_tail = 0;
934 ch->ch_e_head = 0;
935 ch->ch_e_tail = 0;
936 ch->ch_w_head = 0;
937 ch->ch_w_tail = 0;
938
939 brd->bd_ops->flush_uart_write(ch);
940 brd->bd_ops->flush_uart_read(ch);
941
942 ch->ch_flags = 0;
943 ch->ch_cached_lsr = 0;
944 ch->ch_stop_sending_break = 0;
945 ch->ch_stops_sent = 0;
946
947 ch->ch_c_cflag = tty->termios.c_cflag;
948 ch->ch_c_iflag = tty->termios.c_iflag;
949 ch->ch_c_oflag = tty->termios.c_oflag;
950 ch->ch_c_lflag = tty->termios.c_lflag;
951 ch->ch_startc = tty->termios.c_cc[VSTART];
952 ch->ch_stopc = tty->termios.c_cc[VSTOP];
953
954 /*
955 * Bring up RTS and DTR...
956 * Also handle RTS or DTR toggle if set.
957 */
958 if (!(ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE))
959 ch->ch_mostat |= (UART_MCR_RTS);
960 if (!(ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE))
961 ch->ch_mostat |= (UART_MCR_DTR);
962
963 /* Tell UART to init itself */
964 brd->bd_ops->uart_init(ch);
965 }
966
967 brd->bd_ops->param(tty);
968
969 dgnc_carrier(ch);
970
971 spin_unlock_irqrestore(&ch->ch_lock, flags);
972
973 rc = dgnc_block_til_ready(tty, file, ch);
974
975 spin_lock_irqsave(&ch->ch_lock, flags);
976 ch->ch_open_count++;
977 un->un_open_count++;
978 un->un_flags |= (UN_ISOPEN);
979 spin_unlock_irqrestore(&ch->ch_lock, flags);
980
981 return rc;
982
983err_brd_unlock:
984 spin_unlock_irqrestore(&brd->bd_lock, flags);
985
986 return rc;
987err_ch_unlock:
988 spin_unlock_irqrestore(&ch->ch_lock, flags);
989
990 return rc;
991}
992
993/* Wait for DCD, if needed. */
994static int dgnc_block_til_ready(struct tty_struct *tty,
995 struct file *file,
996 struct channel_t *ch)
997{
998 int rc = 0;
999 struct un_t *un = tty->driver_data;
1000 unsigned long flags;
1001 uint old_flags = 0;
1002 int sleep_on_un_flags = 0;
1003
1004 if (!file)
1005 return -ENXIO;
1006
1007 spin_lock_irqsave(&ch->ch_lock, flags);
1008
1009 ch->ch_wopen++;
1010
1011 while (1) {
1012 sleep_on_un_flags = 0;
1013
1014 if (ch->ch_bd->state == BOARD_FAILED) {
1015 rc = -ENXIO;
1016 break;
1017 }
1018
1019 if (tty_hung_up_p(file)) {
1020 rc = -EAGAIN;
1021 break;
1022 }
1023
1024 /*
1025 * If either unit is in the middle of the fragile part of close,
1026 * we just cannot touch the channel safely.
1027 * Go back to sleep, knowing that when the channel can be
1028 * touched safely, the close routine will signal the
1029 * ch_wait_flags to wake us back up.
1030 */
1031 if (!((ch->ch_tun.un_flags |
1032 ch->ch_pun.un_flags) &
1033 UN_CLOSING)) {
1034 /*
1035 * Our conditions to leave cleanly and happily:
1036 * 1) NONBLOCKING on the tty is set.
1037 * 2) CLOCAL is set.
1038 * 3) DCD (fake or real) is active.
1039 */
1040
1041 if (file->f_flags & O_NONBLOCK)
1042 break;
1043
1044 if (tty_io_error(tty)) {
1045 rc = -EIO;
1046 break;
1047 }
1048
1049 if (ch->ch_flags & CH_CD)
1050 break;
1051
1052 if (ch->ch_flags & CH_FCAR)
1053 break;
1054 } else {
1055 sleep_on_un_flags = 1;
1056 }
1057
1058 /*
1059 * If there is a signal pending, the user probably
1060 * interrupted (ctrl-c) us.
1061 */
1062 if (signal_pending(current)) {
1063 rc = -ERESTARTSYS;
1064 break;
1065 }
1066
1067 if (sleep_on_un_flags)
1068 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
1069 else
1070 old_flags = ch->ch_flags;
1071
1072 /*
1073 * Let go of channel lock before calling schedule.
1074 * Our poller will get any FEP events and wake us up when DCD
1075 * eventually goes active.
1076 */
1077
1078 spin_unlock_irqrestore(&ch->ch_lock, flags);
1079
1080 /*
1081 * Wait for something in the flags to change
1082 * from the current value.
1083 */
1084 if (sleep_on_un_flags)
1085 rc = wait_event_interruptible
1086 (un->un_flags_wait,
1087 (old_flags != (ch->ch_tun.un_flags |
1088 ch->ch_pun.un_flags)));
1089 else
1090 rc = wait_event_interruptible(
1091 ch->ch_flags_wait,
1092 (old_flags != ch->ch_flags));
1093
1094 /*
1095 * We got woken up for some reason.
1096 * Before looping around, grab our channel lock.
1097 */
1098 spin_lock_irqsave(&ch->ch_lock, flags);
1099 }
1100
1101 ch->ch_wopen--;
1102
1103 spin_unlock_irqrestore(&ch->ch_lock, flags);
1104
1105 return rc;
1106}
1107
1108/* Hangup the port. Like a close, but don't wait for output to drain. */
1109static void dgnc_tty_hangup(struct tty_struct *tty)
1110{
1111 if (!tty)
1112 return;
1113
1114 /* flush the transmit queues */
1115 dgnc_tty_flush_buffer(tty);
1116}
1117
1118static void dgnc_tty_close(struct tty_struct *tty, struct file *file)
1119{
1120 struct dgnc_board *bd;
1121 struct channel_t *ch;
1122 struct un_t *un;
1123 unsigned long flags;
1124
1125 if (!tty)
1126 return;
1127
1128 un = tty->driver_data;
1129 if (!un)
1130 return;
1131
1132 ch = un->un_ch;
1133 if (!ch)
1134 return;
1135
1136 bd = ch->ch_bd;
1137 if (!bd)
1138 return;
1139
1140 spin_lock_irqsave(&ch->ch_lock, flags);
1141
1142 /*
1143 * Determine if this is the last close or not - and if we agree about
1144 * which type of close it is with the Line Discipline
1145 */
1146 if ((tty->count == 1) && (un->un_open_count != 1)) {
1147 /*
1148 * Uh, oh. tty->count is 1, which means that the tty
1149 * structure will be freed. un_open_count should always
1150 * be one in these conditions. If it's greater than
1151 * one, we've got real problems, since it means the
1152 * serial port won't be shutdown.
1153 */
1154 dev_dbg(tty->dev,
1155 "tty->count is 1, un open count is %d\n",
1156 un->un_open_count);
1157 un->un_open_count = 1;
1158 }
1159
1160 if (un->un_open_count)
1161 un->un_open_count--;
1162 else
1163 dev_dbg(tty->dev,
1164 "bad serial port open count of %d\n",
1165 un->un_open_count);
1166
1167 ch->ch_open_count--;
1168
1169 if (ch->ch_open_count && un->un_open_count) {
1170 spin_unlock_irqrestore(&ch->ch_lock, flags);
1171 return;
1172 }
1173
1174 /* OK, its the last close on the unit */
1175 un->un_flags |= UN_CLOSING;
1176
1177 tty->closing = 1;
1178
1179 /*
1180 * Only officially close channel if count is 0 and
1181 * DIGI_PRINTER bit is not set.
1182 */
1183 if ((ch->ch_open_count == 0) &&
1184 !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
1185 ch->ch_flags &= ~(CH_STOPI | CH_FORCED_STOPI);
1186
1187 /* turn off print device when closing print device. */
1188
1189 if ((un->un_type == DGNC_PRINT) && (ch->ch_flags & CH_PRON)) {
1190 dgnc_wmove(ch, ch->ch_digi.digi_offstr,
1191 (int)ch->ch_digi.digi_offlen);
1192 ch->ch_flags &= ~CH_PRON;
1193 }
1194
1195 spin_unlock_irqrestore(&ch->ch_lock, flags);
1196 /* wait for output to drain */
1197 /* This will also return if we take an interrupt */
1198
1199 bd->bd_ops->drain(tty, 0);
1200
1201 dgnc_tty_flush_buffer(tty);
1202 tty_ldisc_flush(tty);
1203
1204 spin_lock_irqsave(&ch->ch_lock, flags);
1205
1206 tty->closing = 0;
1207
1208 /* If we have HUPCL set, lower DTR and RTS */
1209
1210 if (ch->ch_c_cflag & HUPCL) {
1211 /* Drop RTS/DTR */
1212 ch->ch_mostat &= ~(UART_MCR_DTR | UART_MCR_RTS);
1213 bd->bd_ops->assert_modem_signals(ch);
1214
1215 /*
1216 * Go to sleep to ensure RTS/DTR
1217 * have been dropped for modems to see it.
1218 */
1219 if (ch->ch_close_delay) {
1220 spin_unlock_irqrestore(&ch->ch_lock,
1221 flags);
1222 msleep_interruptible(ch->ch_close_delay);
1223 spin_lock_irqsave(&ch->ch_lock, flags);
1224 }
1225 }
1226
1227 ch->ch_old_baud = 0;
1228
1229 /* Turn off UART interrupts for this port */
1230 ch->ch_bd->bd_ops->uart_off(ch);
1231 } else {
1232 /* turn off print device when closing print device. */
1233
1234 if ((un->un_type == DGNC_PRINT) && (ch->ch_flags & CH_PRON)) {
1235 dgnc_wmove(ch, ch->ch_digi.digi_offstr,
1236 (int)ch->ch_digi.digi_offlen);
1237 ch->ch_flags &= ~CH_PRON;
1238 }
1239 }
1240
1241 un->un_tty = NULL;
1242 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
1243
1244 wake_up_interruptible(&ch->ch_flags_wait);
1245 wake_up_interruptible(&un->un_flags_wait);
1246
1247 spin_unlock_irqrestore(&ch->ch_lock, flags);
1248}
1249
1250/*
1251 * Return number of characters that have not been transmitted yet.
1252 *
1253 * This routine is used by the line discipline to determine if there
1254 * is data waiting to be transmitted/drained/flushed or not.
1255 */
1256static int dgnc_tty_chars_in_buffer(struct tty_struct *tty)
1257{
1258 struct channel_t *ch = NULL;
1259 struct un_t *un = NULL;
1260 ushort thead;
1261 ushort ttail;
1262 uint tmask;
1263 uint chars;
1264 unsigned long flags;
1265
1266 if (!tty)
1267 return 0;
1268
1269 un = tty->driver_data;
1270 if (!un)
1271 return 0;
1272
1273 ch = un->un_ch;
1274 if (!ch)
1275 return 0;
1276
1277 spin_lock_irqsave(&ch->ch_lock, flags);
1278
1279 tmask = WQUEUEMASK;
1280 thead = ch->ch_w_head & tmask;
1281 ttail = ch->ch_w_tail & tmask;
1282
1283 spin_unlock_irqrestore(&ch->ch_lock, flags);
1284
1285 if (ttail == thead)
1286 chars = 0;
1287 else if (thead > ttail)
1288 chars = thead - ttail;
1289 else
1290 chars = thead - ttail + WQUEUESIZE;
1291
1292 return chars;
1293}
1294
1295/*
1296 * Reduces bytes_available to the max number of characters
1297 * that can be sent currently given the maxcps value, and
1298 * returns the new bytes_available. This only affects printer
1299 * output.
1300 */
1301static int dgnc_maxcps_room(struct channel_t *ch, int bytes_available)
1302{
1303 int rc = bytes_available;
1304
1305 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
1306 int cps_limit = 0;
1307 unsigned long current_time = jiffies;
1308 unsigned long buffer_time = current_time +
1309 (HZ * ch->ch_digi.digi_bufsize) /
1310 ch->ch_digi.digi_maxcps;
1311
1312 if (ch->ch_cpstime < current_time) {
1313 /* buffer is empty */
1314 ch->ch_cpstime = current_time; /* reset ch_cpstime */
1315 cps_limit = ch->ch_digi.digi_bufsize;
1316 } else if (ch->ch_cpstime < buffer_time) {
1317 /* still room in the buffer */
1318 cps_limit = ((buffer_time - ch->ch_cpstime) *
1319 ch->ch_digi.digi_maxcps) / HZ;
1320 } else {
1321 /* no room in the buffer */
1322 cps_limit = 0;
1323 }
1324
1325 rc = min(cps_limit, bytes_available);
1326 }
1327
1328 return rc;
1329}
1330
1331/* Return room available in Tx buffer */
1332static int dgnc_tty_write_room(struct tty_struct *tty)
1333{
1334 struct channel_t *ch = NULL;
1335 struct un_t *un = NULL;
1336 ushort head;
1337 ushort tail;
1338 ushort tmask;
1339 int room = 0;
1340 unsigned long flags;
1341
1342 if (!tty)
1343 return 0;
1344
1345 un = tty->driver_data;
1346 if (!un)
1347 return 0;
1348
1349 ch = un->un_ch;
1350 if (!ch)
1351 return 0;
1352
1353 spin_lock_irqsave(&ch->ch_lock, flags);
1354
1355 tmask = WQUEUEMASK;
1356 head = (ch->ch_w_head) & tmask;
1357 tail = (ch->ch_w_tail) & tmask;
1358
1359 room = tail - head - 1;
1360 if (room < 0)
1361 room += WQUEUESIZE;
1362
1363 /* Limit printer to maxcps */
1364 if (un->un_type != DGNC_PRINT)
1365 room = dgnc_maxcps_room(ch, room);
1366
1367 /*
1368 * If we are printer device, leave room for
1369 * possibly both the on and off strings.
1370 */
1371 if (un->un_type == DGNC_PRINT) {
1372 if (!(ch->ch_flags & CH_PRON))
1373 room -= ch->ch_digi.digi_onlen;
1374 room -= ch->ch_digi.digi_offlen;
1375 } else {
1376 if (ch->ch_flags & CH_PRON)
1377 room -= ch->ch_digi.digi_offlen;
1378 }
1379
1380 if (room < 0)
1381 room = 0;
1382
1383 spin_unlock_irqrestore(&ch->ch_lock, flags);
1384 return room;
1385}
1386
1387/*
1388 * Put a character into ch->ch_buf
1389 * Used by the line discipline for OPOST processing
1390 */
1391static int dgnc_tty_put_char(struct tty_struct *tty, unsigned char c)
1392{
1393 dgnc_tty_write(tty, &c, 1);
1394 return 1;
1395}
1396
1397/*
1398 * Take data from the user or kernel and send it out to the FEP.
1399 * In here exists all the Transparent Print magic as well.
1400 */
1401static int dgnc_tty_write(struct tty_struct *tty,
1402 const unsigned char *buf, int count)
1403{
1404 struct channel_t *ch = NULL;
1405 struct un_t *un = NULL;
1406 int bufcount = 0, n = 0;
1407 unsigned long flags;
1408 ushort head;
1409 ushort tail;
1410 ushort tmask;
1411 uint remain;
1412
1413 if (!tty)
1414 return 0;
1415
1416 un = tty->driver_data;
1417 if (!un)
1418 return 0;
1419
1420 ch = un->un_ch;
1421 if (!ch)
1422 return 0;
1423
1424 if (!count)
1425 return 0;
1426
1427 /*
1428 * Store original amount of characters passed in.
1429 * This helps to figure out if we should ask the FEP
1430 * to send us an event when it has more space available.
1431 */
1432
1433 spin_lock_irqsave(&ch->ch_lock, flags);
1434
1435 tmask = WQUEUEMASK;
1436 head = (ch->ch_w_head) & tmask;
1437 tail = (ch->ch_w_tail) & tmask;
1438
1439 bufcount = tail - head - 1;
1440 if (bufcount < 0)
1441 bufcount += WQUEUESIZE;
1442
1443 /*
1444 * Limit printer output to maxcps overall, with bursts allowed
1445 * up to bufsize characters.
1446 */
1447 if (un->un_type != DGNC_PRINT)
1448 bufcount = dgnc_maxcps_room(ch, bufcount);
1449
1450 count = min(count, bufcount);
1451 if (count <= 0)
1452 goto exit_retry;
1453
1454 /*
1455 * Output the printer ON string, if we are in terminal mode, but
1456 * need to be in printer mode.
1457 */
1458 if ((un->un_type == DGNC_PRINT) && !(ch->ch_flags & CH_PRON)) {
1459 dgnc_wmove(ch, ch->ch_digi.digi_onstr,
1460 (int)ch->ch_digi.digi_onlen);
1461 head = (ch->ch_w_head) & tmask;
1462 ch->ch_flags |= CH_PRON;
1463 }
1464
1465 /*
1466 * On the other hand, output the printer OFF string, if we are
1467 * currently in printer mode, but need to output to the terminal.
1468 */
1469 if ((un->un_type != DGNC_PRINT) && (ch->ch_flags & CH_PRON)) {
1470 dgnc_wmove(ch, ch->ch_digi.digi_offstr,
1471 (int)ch->ch_digi.digi_offlen);
1472 head = (ch->ch_w_head) & tmask;
1473 ch->ch_flags &= ~CH_PRON;
1474 }
1475
1476 n = count;
1477
1478 /*
1479 * If the write wraps over the top of the circular buffer,
1480 * move the portion up to the wrap point, and reset the
1481 * pointers to the bottom.
1482 */
1483 remain = WQUEUESIZE - head;
1484
1485 if (n >= remain) {
1486 n -= remain;
1487 memcpy(ch->ch_wqueue + head, buf, remain);
1488 head = 0;
1489 buf += remain;
1490 }
1491
1492 if (n > 0) {
1493 /* Move rest of data. */
1494 remain = n;
1495 memcpy(ch->ch_wqueue + head, buf, remain);
1496 head += remain;
1497 }
1498
1499 if (count) {
1500 head &= tmask;
1501 ch->ch_w_head = head;
1502 }
1503
1504 /* Update printer buffer empty time. */
1505 if ((un->un_type == DGNC_PRINT) && (ch->ch_digi.digi_maxcps > 0) &&
1506 (ch->ch_digi.digi_bufsize > 0)) {
1507 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
1508 }
1509
1510 spin_unlock_irqrestore(&ch->ch_lock, flags);
1511
1512 if (count)
1513 ch->ch_bd->bd_ops->copy_data_from_queue_to_uart(ch);
1514
1515 return count;
1516
1517exit_retry:
1518 spin_unlock_irqrestore(&ch->ch_lock, flags);
1519
1520 return 0;
1521}
1522
1523/* Return modem signals to ld. */
1524static int dgnc_tty_tiocmget(struct tty_struct *tty)
1525{
1526 struct channel_t *ch;
1527 struct un_t *un;
1528 int rc;
1529 unsigned char mstat = 0;
1530 unsigned long flags;
1531
1532 if (!tty)
1533 return -EIO;
1534
1535 un = tty->driver_data;
1536 if (!un)
1537 return -EIO;
1538
1539 ch = un->un_ch;
1540 if (!ch)
1541 return -EIO;
1542
1543 spin_lock_irqsave(&ch->ch_lock, flags);
1544
1545 mstat = ch->ch_mostat | ch->ch_mistat;
1546
1547 spin_unlock_irqrestore(&ch->ch_lock, flags);
1548
1549 rc = 0;
1550
1551 if (mstat & UART_MCR_DTR)
1552 rc |= TIOCM_DTR;
1553 if (mstat & UART_MCR_RTS)
1554 rc |= TIOCM_RTS;
1555 if (mstat & UART_MSR_CTS)
1556 rc |= TIOCM_CTS;
1557 if (mstat & UART_MSR_DSR)
1558 rc |= TIOCM_DSR;
1559 if (mstat & UART_MSR_RI)
1560 rc |= TIOCM_RI;
1561 if (mstat & UART_MSR_DCD)
1562 rc |= TIOCM_CD;
1563
1564 return rc;
1565}
1566
1567/* Set modem signals, called by ld. */
1568static int dgnc_tty_tiocmset(struct tty_struct *tty,
1569 unsigned int set, unsigned int clear)
1570{
1571 struct dgnc_board *bd;
1572 struct channel_t *ch;
1573 struct un_t *un;
1574 unsigned long flags;
1575
1576 if (!tty)
1577 return -EIO;
1578
1579 un = tty->driver_data;
1580 if (!un)
1581 return -EIO;
1582
1583 ch = un->un_ch;
1584 if (!ch)
1585 return -EIO;
1586
1587 bd = ch->ch_bd;
1588 if (!bd)
1589 return -EIO;
1590
1591 spin_lock_irqsave(&ch->ch_lock, flags);
1592
1593 if (set & TIOCM_RTS)
1594 ch->ch_mostat |= UART_MCR_RTS;
1595
1596 if (set & TIOCM_DTR)
1597 ch->ch_mostat |= UART_MCR_DTR;
1598
1599 if (clear & TIOCM_RTS)
1600 ch->ch_mostat &= ~(UART_MCR_RTS);
1601
1602 if (clear & TIOCM_DTR)
1603 ch->ch_mostat &= ~(UART_MCR_DTR);
1604
1605 bd->bd_ops->assert_modem_signals(ch);
1606
1607 spin_unlock_irqrestore(&ch->ch_lock, flags);
1608
1609 return 0;
1610}
1611
1612/* Send a Break, called by ld. */
1613static int dgnc_tty_send_break(struct tty_struct *tty, int msec)
1614{
1615 struct dgnc_board *bd;
1616 struct channel_t *ch;
1617 struct un_t *un;
1618 unsigned long flags;
1619
1620 if (!tty)
1621 return -EIO;
1622
1623 un = tty->driver_data;
1624 if (!un)
1625 return -EIO;
1626
1627 ch = un->un_ch;
1628 if (!ch)
1629 return -EIO;
1630
1631 bd = ch->ch_bd;
1632 if (!bd)
1633 return -EIO;
1634
1635 if (msec < 0)
1636 msec = 0xFFFF;
1637
1638 spin_lock_irqsave(&ch->ch_lock, flags);
1639
1640 bd->bd_ops->send_break(ch, msec);
1641
1642 spin_unlock_irqrestore(&ch->ch_lock, flags);
1643
1644 return 0;
1645}
1646
1647/* wait until data has been transmitted, called by ld. */
1648static void dgnc_tty_wait_until_sent(struct tty_struct *tty, int timeout)
1649{
1650 struct dgnc_board *bd;
1651 struct channel_t *ch;
1652 struct un_t *un;
1653
1654 if (!tty)
1655 return;
1656
1657 un = tty->driver_data;
1658 if (!un)
1659 return;
1660
1661 ch = un->un_ch;
1662 if (!ch)
1663 return;
1664
1665 bd = ch->ch_bd;
1666 if (!bd)
1667 return;
1668
1669 bd->bd_ops->drain(tty, 0);
1670}
1671
1672/* send a high priority character, called by ld. */
1673static void dgnc_tty_send_xchar(struct tty_struct *tty, char c)
1674{
1675 struct dgnc_board *bd;
1676 struct channel_t *ch;
1677 struct un_t *un;
1678 unsigned long flags;
1679
1680 if (!tty)
1681 return;
1682
1683 un = tty->driver_data;
1684 if (!un)
1685 return;
1686
1687 ch = un->un_ch;
1688 if (!ch)
1689 return;
1690
1691 bd = ch->ch_bd;
1692 if (!bd)
1693 return;
1694
1695 spin_lock_irqsave(&ch->ch_lock, flags);
1696 bd->bd_ops->send_immediate_char(ch, c);
1697 spin_unlock_irqrestore(&ch->ch_lock, flags);
1698}
1699
1700/* Ioctl to get the information for ditty. */
1701static int dgnc_tty_digigeta(struct tty_struct *tty,
1702 struct digi_t __user *retinfo)
1703{
1704 struct channel_t *ch;
1705 struct un_t *un;
1706 struct digi_t tmp;
1707 unsigned long flags;
1708
1709 if (!retinfo)
1710 return -EFAULT;
1711
1712 if (!tty)
1713 return -EFAULT;
1714
1715 un = tty->driver_data;
1716 if (!un)
1717 return -EFAULT;
1718
1719 ch = un->un_ch;
1720 if (!ch)
1721 return -EFAULT;
1722
1723 memset(&tmp, 0, sizeof(tmp));
1724
1725 spin_lock_irqsave(&ch->ch_lock, flags);
1726 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
1727 spin_unlock_irqrestore(&ch->ch_lock, flags);
1728
1729 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
1730 return -EFAULT;
1731
1732 return 0;
1733}
1734
1735/* Ioctl to set the information for ditty. */
1736static int dgnc_tty_digiseta(struct tty_struct *tty,
1737 struct digi_t __user *new_info)
1738{
1739 struct dgnc_board *bd;
1740 struct channel_t *ch;
1741 struct un_t *un;
1742 struct digi_t new_digi;
1743 unsigned long flags;
1744
1745 if (!tty)
1746 return -EFAULT;
1747
1748 un = tty->driver_data;
1749 if (!un)
1750 return -EFAULT;
1751
1752 ch = un->un_ch;
1753 if (!ch)
1754 return -EFAULT;
1755
1756 bd = ch->ch_bd;
1757 if (!bd)
1758 return -EFAULT;
1759
1760 if (copy_from_user(&new_digi, new_info, sizeof(new_digi)))
1761 return -EFAULT;
1762
1763 spin_lock_irqsave(&ch->ch_lock, flags);
1764
1765 /* Handle transitions to and from RTS Toggle. */
1766
1767 if (!(ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) &&
1768 (new_digi.digi_flags & DIGI_RTS_TOGGLE))
1769 ch->ch_mostat &= ~(UART_MCR_RTS);
1770 if ((ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) &&
1771 !(new_digi.digi_flags & DIGI_RTS_TOGGLE))
1772 ch->ch_mostat |= (UART_MCR_RTS);
1773
1774 /* Handle transitions to and from DTR Toggle. */
1775
1776 if (!(ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) &&
1777 (new_digi.digi_flags & DIGI_DTR_TOGGLE))
1778 ch->ch_mostat &= ~(UART_MCR_DTR);
1779 if ((ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) &&
1780 !(new_digi.digi_flags & DIGI_DTR_TOGGLE))
1781 ch->ch_mostat |= (UART_MCR_DTR);
1782
1783 memcpy(&ch->ch_digi, &new_digi, sizeof(new_digi));
1784
1785 if (ch->ch_digi.digi_maxcps < 1)
1786 ch->ch_digi.digi_maxcps = 1;
1787
1788 if (ch->ch_digi.digi_maxcps > 10000)
1789 ch->ch_digi.digi_maxcps = 10000;
1790
1791 if (ch->ch_digi.digi_bufsize < 10)
1792 ch->ch_digi.digi_bufsize = 10;
1793
1794 if (ch->ch_digi.digi_maxchar < 1)
1795 ch->ch_digi.digi_maxchar = 1;
1796
1797 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
1798 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
1799
1800 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
1801 ch->ch_digi.digi_onlen = DIGI_PLEN;
1802
1803 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
1804 ch->ch_digi.digi_offlen = DIGI_PLEN;
1805
1806 bd->bd_ops->param(tty);
1807
1808 spin_unlock_irqrestore(&ch->ch_lock, flags);
1809
1810 return 0;
1811}
1812
1813static void dgnc_tty_set_termios(struct tty_struct *tty,
1814 struct ktermios *old_termios)
1815{
1816 struct dgnc_board *bd;
1817 struct channel_t *ch;
1818 struct un_t *un;
1819 unsigned long flags;
1820
1821 if (!tty)
1822 return;
1823
1824 un = tty->driver_data;
1825 if (!un)
1826 return;
1827
1828 ch = un->un_ch;
1829 if (!ch)
1830 return;
1831
1832 bd = ch->ch_bd;
1833 if (!bd)
1834 return;
1835
1836 spin_lock_irqsave(&ch->ch_lock, flags);
1837
1838 ch->ch_c_cflag = tty->termios.c_cflag;
1839 ch->ch_c_iflag = tty->termios.c_iflag;
1840 ch->ch_c_oflag = tty->termios.c_oflag;
1841 ch->ch_c_lflag = tty->termios.c_lflag;
1842 ch->ch_startc = tty->termios.c_cc[VSTART];
1843 ch->ch_stopc = tty->termios.c_cc[VSTOP];
1844
1845 bd->bd_ops->param(tty);
1846 dgnc_carrier(ch);
1847
1848 spin_unlock_irqrestore(&ch->ch_lock, flags);
1849}
1850
1851static void dgnc_tty_throttle(struct tty_struct *tty)
1852{
1853 struct channel_t *ch;
1854 struct un_t *un;
1855 unsigned long flags;
1856
1857 if (!tty)
1858 return;
1859
1860 un = tty->driver_data;
1861 if (!un)
1862 return;
1863
1864 ch = un->un_ch;
1865 if (!ch)
1866 return;
1867
1868 spin_lock_irqsave(&ch->ch_lock, flags);
1869
1870 ch->ch_flags |= (CH_FORCED_STOPI);
1871
1872 spin_unlock_irqrestore(&ch->ch_lock, flags);
1873}
1874
1875static void dgnc_tty_unthrottle(struct tty_struct *tty)
1876{
1877 struct channel_t *ch;
1878 struct un_t *un;
1879 unsigned long flags;
1880
1881 if (!tty)
1882 return;
1883
1884 un = tty->driver_data;
1885 if (!un)
1886 return;
1887
1888 ch = un->un_ch;
1889 if (!ch)
1890 return;
1891
1892 spin_lock_irqsave(&ch->ch_lock, flags);
1893
1894 ch->ch_flags &= ~(CH_FORCED_STOPI);
1895
1896 spin_unlock_irqrestore(&ch->ch_lock, flags);
1897}
1898
1899static void dgnc_tty_start(struct tty_struct *tty)
1900{
1901 struct dgnc_board *bd;
1902 struct channel_t *ch;
1903 struct un_t *un;
1904 unsigned long flags;
1905
1906 if (!tty)
1907 return;
1908
1909 un = tty->driver_data;
1910 if (!un)
1911 return;
1912
1913 ch = un->un_ch;
1914 if (!ch)
1915 return;
1916
1917 bd = ch->ch_bd;
1918 if (!bd)
1919 return;
1920
1921 spin_lock_irqsave(&ch->ch_lock, flags);
1922
1923 ch->ch_flags &= ~(CH_FORCED_STOP);
1924
1925 spin_unlock_irqrestore(&ch->ch_lock, flags);
1926}
1927
1928static void dgnc_tty_stop(struct tty_struct *tty)
1929{
1930 struct dgnc_board *bd;
1931 struct channel_t *ch;
1932 struct un_t *un;
1933 unsigned long flags;
1934
1935 if (!tty)
1936 return;
1937
1938 un = tty->driver_data;
1939 if (!un)
1940 return;
1941
1942 ch = un->un_ch;
1943 if (!ch)
1944 return;
1945
1946 bd = ch->ch_bd;
1947 if (!bd)
1948 return;
1949
1950 spin_lock_irqsave(&ch->ch_lock, flags);
1951
1952 ch->ch_flags |= (CH_FORCED_STOP);
1953
1954 spin_unlock_irqrestore(&ch->ch_lock, flags);
1955}
1956
1957/*
1958 * Flush the cook buffer
1959 *
1960 * Note to self, and any other poor souls who venture here:
1961 *
1962 * flush in this case DOES NOT mean dispose of the data.
1963 * instead, it means "stop buffering and send it if you
1964 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
1965 *
1966 * It is also always called in interrupt context - JAR 8-Sept-99
1967 */
1968static void dgnc_tty_flush_chars(struct tty_struct *tty)
1969{
1970 struct dgnc_board *bd;
1971 struct channel_t *ch;
1972 struct un_t *un;
1973 unsigned long flags;
1974
1975 if (!tty)
1976 return;
1977
1978 un = tty->driver_data;
1979 if (!un)
1980 return;
1981
1982 ch = un->un_ch;
1983 if (!ch)
1984 return;
1985
1986 bd = ch->ch_bd;
1987 if (!bd)
1988 return;
1989
1990 spin_lock_irqsave(&ch->ch_lock, flags);
1991
1992 /* Do something maybe here */
1993
1994 spin_unlock_irqrestore(&ch->ch_lock, flags);
1995}
1996
1997/* Flush Tx buffer (make in == out) */
1998static void dgnc_tty_flush_buffer(struct tty_struct *tty)
1999{
2000 struct channel_t *ch;
2001 struct un_t *un;
2002 unsigned long flags;
2003
2004 if (!tty)
2005 return;
2006
2007 un = tty->driver_data;
2008 if (!un)
2009 return;
2010
2011 ch = un->un_ch;
2012 if (!ch)
2013 return;
2014
2015 spin_lock_irqsave(&ch->ch_lock, flags);
2016
2017 ch->ch_flags &= ~CH_STOP;
2018
2019 /* Flush our write queue */
2020 ch->ch_w_head = ch->ch_w_tail;
2021
2022 /* Flush UARTs transmit FIFO */
2023 ch->ch_bd->bd_ops->flush_uart_write(ch);
2024
2025 if (ch->ch_tun.un_flags & (UN_LOW | UN_EMPTY)) {
2026 ch->ch_tun.un_flags &= ~(UN_LOW | UN_EMPTY);
2027 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
2028 }
2029 if (ch->ch_pun.un_flags & (UN_LOW | UN_EMPTY)) {
2030 ch->ch_pun.un_flags &= ~(UN_LOW | UN_EMPTY);
2031 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
2032 }
2033
2034 spin_unlock_irqrestore(&ch->ch_lock, flags);
2035}
2036
2037/* Wakes up processes waiting in the unit's (teminal/printer) wait queue */
2038static void dgnc_wake_up_unit(struct un_t *unit)
2039{
2040 unit->un_flags &= ~(UN_LOW | UN_EMPTY);
2041 wake_up_interruptible(&unit->un_flags_wait);
2042}
2043
2044/* The IOCTL function and all of its helpers */
2045
2046/* The usual assortment of ioctl's */
2047static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
2048 unsigned long arg)
2049{
2050 struct dgnc_board *bd;
2051 struct board_ops *ch_bd_ops;
2052 struct channel_t *ch;
2053 struct un_t *un;
2054 int rc;
2055 unsigned long flags;
2056 void __user *uarg = (void __user *)arg;
2057
2058 if (!tty)
2059 return -ENODEV;
2060
2061 un = tty->driver_data;
2062 if (!un)
2063 return -ENODEV;
2064
2065 ch = un->un_ch;
2066 if (!ch)
2067 return -ENODEV;
2068
2069 bd = ch->ch_bd;
2070 if (!bd)
2071 return -ENODEV;
2072
2073 ch_bd_ops = bd->bd_ops;
2074
2075 spin_lock_irqsave(&ch->ch_lock, flags);
2076
2077 if (un->un_open_count <= 0) {
2078 rc = -EIO;
2079 goto err_unlock;
2080 }
2081
2082 switch (cmd) {
2083 /* Here are any additional ioctl's that we want to implement */
2084 case TCFLSH:
2085 /*
2086 * The linux tty driver doesn't have a flush
2087 * input routine for the driver, assuming all backed
2088 * up data is in the line disc. buffers. However,
2089 * we all know that's not the case. Here, we
2090 * act on the ioctl, but then lie and say we didn't
2091 * so the line discipline will process the flush
2092 * also.
2093 */
2094 rc = tty_check_change(tty);
2095 if (rc)
2096 goto err_unlock;
2097
2098 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
2099 ch->ch_r_head = ch->ch_r_tail;
2100 ch_bd_ops->flush_uart_read(ch);
2101 /* Force queue flow control to be released, if needed */
2102 dgnc_check_queue_flow_control(ch);
2103 }
2104
2105 if ((arg == TCOFLUSH) || (arg == TCIOFLUSH)) {
2106 if (!(un->un_type == DGNC_PRINT)) {
2107 ch->ch_w_head = ch->ch_w_tail;
2108 ch_bd_ops->flush_uart_write(ch);
2109
2110 if (ch->ch_tun.un_flags & (UN_LOW | UN_EMPTY))
2111 dgnc_wake_up_unit(&ch->ch_tun);
2112
2113 if (ch->ch_pun.un_flags & (UN_LOW | UN_EMPTY))
2114 dgnc_wake_up_unit(&ch->ch_pun);
2115 }
2116 }
2117
2118 /* pretend we didn't recognize this IOCTL */
2119 spin_unlock_irqrestore(&ch->ch_lock, flags);
2120 return -ENOIOCTLCMD;
2121 case TCSETSF:
2122 case TCSETSW:
2123 /*
2124 * The linux tty driver doesn't have a flush
2125 * input routine for the driver, assuming all backed
2126 * up data is in the line disc. buffers. However,
2127 * we all know that's not the case. Here, we
2128 * act on the ioctl, but then lie and say we didn't
2129 * so the line discipline will process the flush
2130 * also.
2131 */
2132 if (cmd == TCSETSF) {
2133 /* flush rx */
2134 ch->ch_flags &= ~CH_STOP;
2135 ch->ch_r_head = ch->ch_r_tail;
2136 ch_bd_ops->flush_uart_read(ch);
2137 /* Force queue flow control to be released, if needed */
2138 dgnc_check_queue_flow_control(ch);
2139 }
2140
2141 /* now wait for all the output to drain */
2142 spin_unlock_irqrestore(&ch->ch_lock, flags);
2143 rc = ch_bd_ops->drain(tty, 0);
2144 if (rc)
2145 return -EINTR;
2146
2147 /* pretend we didn't recognize this */
2148 return -ENOIOCTLCMD;
2149
2150 case TCSETAW:
2151
2152 spin_unlock_irqrestore(&ch->ch_lock, flags);
2153 rc = ch_bd_ops->drain(tty, 0);
2154 if (rc)
2155 return -EINTR;
2156
2157 /* pretend we didn't recognize this */
2158 return -ENOIOCTLCMD;
2159
2160 case DIGI_GETA:
2161 /* get information for ditty */
2162 spin_unlock_irqrestore(&ch->ch_lock, flags);
2163 return dgnc_tty_digigeta(tty, uarg);
2164
2165 case DIGI_SETAW:
2166 case DIGI_SETAF:
2167
2168 /* set information for ditty */
2169 if (cmd == (DIGI_SETAW)) {
2170 spin_unlock_irqrestore(&ch->ch_lock, flags);
2171 rc = ch_bd_ops->drain(tty, 0);
2172 if (rc)
2173 return -EINTR;
2174
2175 spin_lock_irqsave(&ch->ch_lock, flags);
2176 } else {
2177 tty_ldisc_flush(tty);
2178 }
2179 /* fall thru */
2180
2181 case DIGI_SETA:
2182 spin_unlock_irqrestore(&ch->ch_lock, flags);
2183 return dgnc_tty_digiseta(tty, uarg);
2184
2185 case DIGI_LOOPBACK:
2186 {
2187 uint loopback = 0;
2188 /*
2189 * Let go of locks when accessing user space,
2190 * could sleep
2191 */
2192 spin_unlock_irqrestore(&ch->ch_lock, flags);
2193 rc = get_user(loopback, (unsigned int __user *)arg);
2194 if (rc)
2195 return rc;
2196 spin_lock_irqsave(&ch->ch_lock, flags);
2197
2198 /* Enable/disable internal loopback for this port */
2199 if (loopback)
2200 ch->ch_flags |= CH_LOOPBACK;
2201 else
2202 ch->ch_flags &= ~(CH_LOOPBACK);
2203
2204 ch_bd_ops->param(tty);
2205 spin_unlock_irqrestore(&ch->ch_lock, flags);
2206 return 0;
2207 }
2208
2209 case DIGI_GETCUSTOMBAUD:
2210 spin_unlock_irqrestore(&ch->ch_lock, flags);
2211 return put_user(ch->ch_custom_speed,
2212 (unsigned int __user *)arg);
2213
2214 case DIGI_SETCUSTOMBAUD:
2215 {
2216 int new_rate;
2217
2218 spin_unlock_irqrestore(&ch->ch_lock, flags);
2219 rc = get_user(new_rate, (int __user *)arg);
2220 if (rc)
2221 return rc;
2222 spin_lock_irqsave(&ch->ch_lock, flags);
2223 dgnc_set_custom_speed(ch, new_rate);
2224 ch_bd_ops->param(tty);
2225 spin_unlock_irqrestore(&ch->ch_lock, flags);
2226 return 0;
2227 }
2228
2229 /*
2230 * This ioctl allows insertion of a character into the front
2231 * of any pending data to be transmitted.
2232 *
2233 * This ioctl is to satisfy the "Send Character Immediate"
2234 * call that the RealPort protocol spec requires.
2235 */
2236 case DIGI_REALPORT_SENDIMMEDIATE:
2237 {
2238 unsigned char c;
2239
2240 spin_unlock_irqrestore(&ch->ch_lock, flags);
2241 rc = get_user(c, (unsigned char __user *)arg);
2242 if (rc)
2243 return rc;
2244 spin_lock_irqsave(&ch->ch_lock, flags);
2245 ch_bd_ops->send_immediate_char(ch, c);
2246 spin_unlock_irqrestore(&ch->ch_lock, flags);
2247 return 0;
2248 }
2249
2250 /*
2251 * This ioctl returns all the current counts for the port.
2252 *
2253 * This ioctl is to satisfy the "Line Error Counters"
2254 * call that the RealPort protocol spec requires.
2255 */
2256 case DIGI_REALPORT_GETCOUNTERS:
2257 {
2258 struct digi_getcounter buf;
2259
2260 buf.norun = ch->ch_err_overrun;
2261 buf.noflow = 0; /* The driver doesn't keep this stat */
2262 buf.nframe = ch->ch_err_frame;
2263 buf.nparity = ch->ch_err_parity;
2264 buf.nbreak = ch->ch_err_break;
2265 buf.rbytes = ch->ch_rxcount;
2266 buf.tbytes = ch->ch_txcount;
2267
2268 spin_unlock_irqrestore(&ch->ch_lock, flags);
2269
2270 if (copy_to_user(uarg, &buf, sizeof(buf)))
2271 return -EFAULT;
2272
2273 return 0;
2274 }
2275
2276 /*
2277 * This ioctl returns all current events.
2278 *
2279 * This ioctl is to satisfy the "Event Reporting"
2280 * call that the RealPort protocol spec requires.
2281 */
2282 case DIGI_REALPORT_GETEVENTS:
2283 {
2284 unsigned int events = 0;
2285
2286 /* NOTE: MORE EVENTS NEEDS TO BE ADDED HERE */
2287 if (ch->ch_flags & CH_BREAK_SENDING)
2288 events |= EV_TXB;
2289 if ((ch->ch_flags & CH_STOP) ||
2290 (ch->ch_flags & CH_FORCED_STOP))
2291 events |= (EV_OPU | EV_OPS);
2292
2293 if ((ch->ch_flags & CH_STOPI) ||
2294 (ch->ch_flags & CH_FORCED_STOPI))
2295 events |= (EV_IPU | EV_IPS);
2296
2297 spin_unlock_irqrestore(&ch->ch_lock, flags);
2298 return put_user(events, (unsigned int __user *)arg);
2299 }
2300
2301 /*
2302 * This ioctl returns TOUT and TIN counters based
2303 * upon the values passed in by the RealPort Server.
2304 * It also passes back whether the UART Transmitter is
2305 * empty as well.
2306 */
2307 case DIGI_REALPORT_GETBUFFERS:
2308 {
2309 struct digi_getbuffer buf;
2310 int tdist;
2311 int count;
2312
2313 spin_unlock_irqrestore(&ch->ch_lock, flags);
2314
2315 if (copy_from_user(&buf, uarg, sizeof(buf)))
2316 return -EFAULT;
2317
2318 spin_lock_irqsave(&ch->ch_lock, flags);
2319
2320 /* Figure out how much data is in our RX and TX queues. */
2321
2322 buf.rxbuf = (ch->ch_r_head - ch->ch_r_tail) & RQUEUEMASK;
2323 buf.txbuf = (ch->ch_w_head - ch->ch_w_tail) & WQUEUEMASK;
2324
2325 /*
2326 * Is the UART empty?
2327 * Add that value to whats in our TX queue.
2328 */
2329
2330 count = buf.txbuf + ch_bd_ops->get_uart_bytes_left(ch);
2331
2332 /*
2333 * Figure out how much data the RealPort Server believes should
2334 * be in our TX queue.
2335 */
2336 tdist = (buf.tx_in - buf.tx_out) & 0xffff;
2337
2338 /*
2339 * If we have more data than the RealPort Server believes we
2340 * should have, reduce our count to its amount.
2341 *
2342 * This count difference CAN happen because the Linux LD can
2343 * insert more characters into our queue for OPOST processing
2344 * that the RealPort Server doesn't know about.
2345 */
2346 if (buf.txbuf > tdist)
2347 buf.txbuf = tdist;
2348
2349 /* Report whether our queue and UART TX are completely empty. */
2350
2351 if (count)
2352 buf.txdone = 0;
2353 else
2354 buf.txdone = 1;
2355
2356 spin_unlock_irqrestore(&ch->ch_lock, flags);
2357
2358 if (copy_to_user(uarg, &buf, sizeof(buf)))
2359 return -EFAULT;
2360
2361 return 0;
2362 }
2363 default:
2364 spin_unlock_irqrestore(&ch->ch_lock, flags);
2365
2366 return -ENOIOCTLCMD;
2367 }
2368err_unlock:
2369 spin_unlock_irqrestore(&ch->ch_lock, flags);
2370
2371 return rc;
2372}
diff --git a/drivers/staging/dgnc/dgnc_tty.h b/drivers/staging/dgnc/dgnc_tty.h
deleted file mode 100644
index 00e31035b83d..000000000000
--- a/drivers/staging/dgnc/dgnc_tty.h
+++ /dev/null
@@ -1,24 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Copyright 2003 Digi International (www.digi.com)
4 * Scott H Kilau <Scott_Kilau at digi dot com>
5 */
6
7#ifndef _DGNC_TTY_H
8#define _DGNC_TTY_H
9
10#include "dgnc_driver.h"
11
12int dgnc_tty_register(struct dgnc_board *brd);
13void dgnc_tty_unregister(struct dgnc_board *brd);
14
15int dgnc_tty_init(struct dgnc_board *brd);
16
17void dgnc_cleanup_tty(struct dgnc_board *brd);
18
19void dgnc_input(struct channel_t *ch);
20void dgnc_carrier(struct channel_t *ch);
21void dgnc_wakeup_writes(struct channel_t *ch);
22void dgnc_check_queue_flow_control(struct channel_t *ch);
23
24#endif /* _DGNC_TTY_H */
diff --git a/drivers/staging/dgnc/digi.h b/drivers/staging/dgnc/digi.h
deleted file mode 100644
index b414ee80db88..000000000000
--- a/drivers/staging/dgnc/digi.h
+++ /dev/null
@@ -1,128 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Copyright 2003 Digi International (www.digi.com)
4 * Scott H Kilau <Scott_Kilau at digi dot com>
5 */
6
7#ifndef _DIGI_H
8#define _DIGI_H
9
10#define DIGI_GETA (('e' << 8) | 94) /* Read params */
11#define DIGI_SETA (('e' << 8) | 95) /* Set params */
12#define DIGI_SETAW (('e' << 8) | 96) /* Drain & set params */
13#define DIGI_SETAF (('e' << 8) | 97) /* Drain, flush & set params */
14#define DIGI_LOOPBACK (('d' << 8) | 252) /* Enable/disable UART
15 * internal loopback
16 */
17#define DIGI_FAST 0x0002 /* Fast baud rates */
18#define RTSPACE 0x0004 /* RTS input flow control */
19#define CTSPACE 0x0008 /* CTS output flow control */
20#define DIGI_COOK 0x0080 /* Cooked processing done in FEP */
21#define DIGI_FORCEDCD 0x0100 /* Force carrier */
22#define DIGI_ALTPIN 0x0200 /* Alternate RJ-45 pin config */
23#define DIGI_PRINTER 0x0800 /* Hold port open for flow cntrl*/
24#define DIGI_DTR_TOGGLE 0x2000 /* Support DTR Toggle */
25#define DIGI_RTS_TOGGLE 0x8000 /* Support RTS Toggle */
26#define DIGI_PLEN 28 /* String length */
27#define DIGI_TSIZ 10 /* Terminal string len */
28
29/*
30 * Structure used with ioctl commands for DIGI parameters.
31 */
32/**
33 * struct digi_t - Ioctl commands for DIGI parameters.
34 * @digi_flags: Flags.
35 * @digi_maxcps: Maximum printer CPS.
36 * @digi_maxchar: Maximum characters in the print queue.
37 * @digi_bufsize: Buffer size.
38 * @digi_onlen: Length of ON string.
39 * @digi_offlen: Length of OFF string.
40 * @digi_onstr: Printer ON string.
41 * @digi_offstr: Printer OFF string.
42 * @digi_term: Terminal string.
43 */
44struct digi_t {
45 unsigned short digi_flags;
46 unsigned short digi_maxcps;
47 unsigned short digi_maxchar;
48 unsigned short digi_bufsize;
49 unsigned char digi_onlen;
50 unsigned char digi_offlen;
51 char digi_onstr[DIGI_PLEN];
52 char digi_offstr[DIGI_PLEN];
53 char digi_term[DIGI_TSIZ];
54};
55
56/**
57 * struct digi_getbuffer - Holds buffer use counts.
58 */
59struct digi_getbuffer {
60 unsigned long tx_in;
61 unsigned long tx_out;
62 unsigned long rxbuf;
63 unsigned long txbuf;
64 unsigned long txdone;
65};
66
67/**
68 * struct digi_getcounter
69 * @norun: Number of UART overrun errors.
70 * @noflow: Number of buffer overflow errors.
71 * @nframe: Number of framing errors.
72 * @nparity: Number of parity errors.
73 * @nbreak: Number of breaks received.
74 * @rbytes: Number of received bytes.
75 * @tbytes: Number of transmitted bytes.
76 */
77struct digi_getcounter {
78 unsigned long norun;
79 unsigned long noflow;
80 unsigned long nframe;
81 unsigned long nparity;
82 unsigned long nbreak;
83 unsigned long rbytes;
84 unsigned long tbytes;
85};
86
87#define DIGI_SETCUSTOMBAUD _IOW('e', 106, int) /* Set integer baud rate */
88#define DIGI_GETCUSTOMBAUD _IOR('e', 107, int) /* Get integer baud rate */
89
90#define DIGI_REALPORT_GETBUFFERS (('e' << 8) | 108)
91#define DIGI_REALPORT_SENDIMMEDIATE (('e' << 8) | 109)
92#define DIGI_REALPORT_GETCOUNTERS (('e' << 8) | 110)
93#define DIGI_REALPORT_GETEVENTS (('e' << 8) | 111)
94
95#define EV_OPU 0x0001 /* Output paused by client */
96#define EV_OPS 0x0002 /* Output paused by regular sw flowctrl */
97#define EV_IPU 0x0010 /* Input paused unconditionally by user */
98#define EV_IPS 0x0020 /* Input paused by high/low water marks */
99#define EV_TXB 0x0040 /* Transmit break pending */
100
101/**
102 * struct ni_info - intelligent <--> non-intelligent DPA translation.
103 */
104struct ni_info {
105 int board;
106 int channel;
107 int dtr;
108 int rts;
109 int cts;
110 int dsr;
111 int ri;
112 int dcd;
113 int curtx;
114 int currx;
115 unsigned short iflag;
116 unsigned short oflag;
117 unsigned short cflag;
118 unsigned short lflag;
119 unsigned int mstat;
120 unsigned char hflow;
121 unsigned char xmit_stopped;
122 unsigned char recv_stopped;
123 unsigned int baud;
124};
125
126#define TTY_FLIPBUF_SIZE 512
127
128#endif /* _DIGI_H */
diff --git a/drivers/staging/emxx_udc/emxx_udc.c b/drivers/staging/emxx_udc/emxx_udc.c
index 3e51476a7045..65cc3d9af972 100644
--- a/drivers/staging/emxx_udc/emxx_udc.c
+++ b/drivers/staging/emxx_udc/emxx_udc.c
@@ -1369,25 +1369,6 @@ static void _nbu2ss_set_endpoint_stall(
1369} 1369}
1370 1370
1371/*-------------------------------------------------------------------------*/ 1371/*-------------------------------------------------------------------------*/
1372/* Device Descriptor */
1373static struct usb_device_descriptor device_desc = {
1374 .bLength = sizeof(device_desc),
1375 .bDescriptorType = USB_DT_DEVICE,
1376 .bcdUSB = cpu_to_le16(0x0200),
1377 .bDeviceClass = USB_CLASS_VENDOR_SPEC,
1378 .bDeviceSubClass = 0x00,
1379 .bDeviceProtocol = 0x00,
1380 .bMaxPacketSize0 = 64,
1381 .idVendor = cpu_to_le16(0x0409),
1382 .idProduct = cpu_to_le16(0xfff0),
1383 .bcdDevice = 0xffff,
1384 .iManufacturer = 0x00,
1385 .iProduct = 0x00,
1386 .iSerialNumber = 0x00,
1387 .bNumConfigurations = 0x01,
1388};
1389
1390/*-------------------------------------------------------------------------*/
1391static void _nbu2ss_set_test_mode(struct nbu2ss_udc *udc, u32 mode) 1372static void _nbu2ss_set_test_mode(struct nbu2ss_udc *udc, u32 mode)
1392{ 1373{
1393 u32 data; 1374 u32 data;
@@ -2513,7 +2494,7 @@ static int nbu2ss_ep_enable(
2513 } 2494 }
2514 2495
2515 ep = container_of(_ep, struct nbu2ss_ep, ep); 2496 ep = container_of(_ep, struct nbu2ss_ep, ep);
2516 if ((!ep) || (!ep->udc)) { 2497 if ((!ep->udc)) {
2517 pr_err(" *** %s, ep == NULL !!\n", __func__); 2498 pr_err(" *** %s, ep == NULL !!\n", __func__);
2518 return -EINVAL; 2499 return -EINVAL;
2519 } 2500 }
@@ -2570,7 +2551,7 @@ static int nbu2ss_ep_disable(struct usb_ep *_ep)
2570 } 2551 }
2571 2552
2572 ep = container_of(_ep, struct nbu2ss_ep, ep); 2553 ep = container_of(_ep, struct nbu2ss_ep, ep);
2573 if ((!ep) || (!ep->udc)) { 2554 if (!ep->udc) {
2574 pr_err("udc: *** %s, ep == NULL !!\n", __func__); 2555 pr_err("udc: *** %s, ep == NULL !!\n", __func__);
2575 return -EINVAL; 2556 return -EINVAL;
2576 } 2557 }
@@ -2743,10 +2724,6 @@ static int nbu2ss_ep_dequeue(
2743 } 2724 }
2744 2725
2745 ep = container_of(_ep, struct nbu2ss_ep, ep); 2726 ep = container_of(_ep, struct nbu2ss_ep, ep);
2746 if (!ep) {
2747 pr_err("%s, ep == NULL !!\n", __func__);
2748 return -EINVAL;
2749 }
2750 2727
2751 udc = ep->udc; 2728 udc = ep->udc;
2752 if (!udc) 2729 if (!udc)
@@ -2787,10 +2764,6 @@ static int nbu2ss_ep_set_halt(struct usb_ep *_ep, int value)
2787 } 2764 }
2788 2765
2789 ep = container_of(_ep, struct nbu2ss_ep, ep); 2766 ep = container_of(_ep, struct nbu2ss_ep, ep);
2790 if (!ep) {
2791 pr_err("%s, bad ep\n", __func__);
2792 return -EINVAL;
2793 }
2794 2767
2795 udc = ep->udc; 2768 udc = ep->udc;
2796 if (!udc) { 2769 if (!udc) {
@@ -2839,10 +2812,6 @@ static int nbu2ss_ep_fifo_status(struct usb_ep *_ep)
2839 } 2812 }
2840 2813
2841 ep = container_of(_ep, struct nbu2ss_ep, ep); 2814 ep = container_of(_ep, struct nbu2ss_ep, ep);
2842 if (!ep) {
2843 pr_err("%s, bad ep\n", __func__);
2844 return -EINVAL;
2845 }
2846 2815
2847 udc = ep->udc; 2816 udc = ep->udc;
2848 if (!udc) { 2817 if (!udc) {
@@ -2885,10 +2854,6 @@ static void nbu2ss_ep_fifo_flush(struct usb_ep *_ep)
2885 } 2854 }
2886 2855
2887 ep = container_of(_ep, struct nbu2ss_ep, ep); 2856 ep = container_of(_ep, struct nbu2ss_ep, ep);
2888 if (!ep) {
2889 pr_err("udc: %s, bad ep\n", __func__);
2890 return;
2891 }
2892 2857
2893 udc = ep->udc; 2858 udc = ep->udc;
2894 if (!udc) { 2859 if (!udc) {
@@ -2959,10 +2924,6 @@ static int nbu2ss_gad_wakeup(struct usb_gadget *pgadget)
2959 } 2924 }
2960 2925
2961 udc = container_of(pgadget, struct nbu2ss_udc, gadget); 2926 udc = container_of(pgadget, struct nbu2ss_udc, gadget);
2962 if (!udc) {
2963 dev_err(&pgadget->dev, "%s, udc == NULL\n", __func__);
2964 return -EINVAL;
2965 }
2966 2927
2967 data = gpio_get_value(VBUS_VALUE); 2928 data = gpio_get_value(VBUS_VALUE);
2968 if (data == 0) { 2929 if (data == 0) {
diff --git a/drivers/staging/erofs/Kconfig b/drivers/staging/erofs/Kconfig
index 663b755bf2fb..c8521d71039b 100644
--- a/drivers/staging/erofs/Kconfig
+++ b/drivers/staging/erofs/Kconfig
@@ -78,6 +78,15 @@ config EROFS_FAULT_INJECTION
78 Test EROFS to inject faults such as ENOMEM, EIO, and so on. 78 Test EROFS to inject faults such as ENOMEM, EIO, and so on.
79 If unsure, say N. 79 If unsure, say N.
80 80
81config EROFS_FS_IO_MAX_RETRIES
82 int "EROFS IO Maximum Retries"
83 depends on EROFS_FS
84 default "5"
85 help
86 Maximum retry count of IO Errors.
87
88 If unsure, leave the default value (5 retries, 6 IOs at most).
89
81config EROFS_FS_ZIP 90config EROFS_FS_ZIP
82 bool "EROFS Data Compresssion Support" 91 bool "EROFS Data Compresssion Support"
83 depends on EROFS_FS 92 depends on EROFS_FS
diff --git a/drivers/staging/erofs/data.c b/drivers/staging/erofs/data.c
index ac263a180253..6384f73e5418 100644
--- a/drivers/staging/erofs/data.c
+++ b/drivers/staging/erofs/data.c
@@ -25,7 +25,7 @@ static inline void read_endio(struct bio *bio)
25 struct page *page = bvec->bv_page; 25 struct page *page = bvec->bv_page;
26 26
27 /* page is already locked */ 27 /* page is already locked */
28 BUG_ON(PageUptodate(page)); 28 DBG_BUGON(PageUptodate(page));
29 29
30 if (unlikely(err)) 30 if (unlikely(err))
31 SetPageError(page); 31 SetPageError(page);
@@ -39,38 +39,50 @@ static inline void read_endio(struct bio *bio)
39} 39}
40 40
41/* prio -- true is used for dir */ 41/* prio -- true is used for dir */
42struct page *erofs_get_meta_page(struct super_block *sb, 42struct page *__erofs_get_meta_page(struct super_block *sb,
43 erofs_blk_t blkaddr, bool prio) 43 erofs_blk_t blkaddr, bool prio, bool nofail)
44{ 44{
45 struct inode *bd_inode = sb->s_bdev->bd_inode; 45 struct inode *const bd_inode = sb->s_bdev->bd_inode;
46 struct address_space *mapping = bd_inode->i_mapping; 46 struct address_space *const mapping = bd_inode->i_mapping;
47 /* prefer retrying in the allocator to blindly looping below */
48 const gfp_t gfp = mapping_gfp_constraint(mapping, ~__GFP_FS) |
49 (nofail ? __GFP_NOFAIL : 0);
50 unsigned int io_retries = nofail ? EROFS_IO_MAX_RETRIES_NOFAIL : 0;
47 struct page *page; 51 struct page *page;
52 int err;
48 53
49repeat: 54repeat:
50 page = find_or_create_page(mapping, blkaddr, 55 page = find_or_create_page(mapping, blkaddr, gfp);
51 /* 56 if (unlikely(page == NULL)) {
52 * Prefer looping in the allocator rather than here, 57 DBG_BUGON(nofail);
53 * at least that code knows what it's doing. 58 return ERR_PTR(-ENOMEM);
54 */ 59 }
55 mapping_gfp_constraint(mapping, ~__GFP_FS) | __GFP_NOFAIL); 60 DBG_BUGON(!PageLocked(page));
56
57 BUG_ON(!page || !PageLocked(page));
58 61
59 if (!PageUptodate(page)) { 62 if (!PageUptodate(page)) {
60 struct bio *bio; 63 struct bio *bio;
61 int err;
62 64
63 bio = prepare_bio(sb, blkaddr, 1, read_endio); 65 bio = erofs_grab_bio(sb, blkaddr, 1, read_endio, nofail);
66 if (IS_ERR(bio)) {
67 DBG_BUGON(nofail);
68 err = PTR_ERR(bio);
69 goto err_out;
70 }
71
64 err = bio_add_page(bio, page, PAGE_SIZE, 0); 72 err = bio_add_page(bio, page, PAGE_SIZE, 0);
65 BUG_ON(err != PAGE_SIZE); 73 if (unlikely(err != PAGE_SIZE)) {
74 err = -EFAULT;
75 goto err_out;
76 }
66 77
67 __submit_bio(bio, REQ_OP_READ, 78 __submit_bio(bio, REQ_OP_READ,
68 REQ_META | (prio ? REQ_PRIO : 0)); 79 REQ_META | (prio ? REQ_PRIO : 0));
69 80
70 lock_page(page); 81 lock_page(page);
71 82
72 /* the page has been truncated by others? */ 83 /* this page has been truncated by others */
73 if (unlikely(page->mapping != mapping)) { 84 if (unlikely(page->mapping != mapping)) {
85unlock_repeat:
74 unlock_page(page); 86 unlock_page(page);
75 put_page(page); 87 put_page(page);
76 goto repeat; 88 goto repeat;
@@ -78,25 +90,32 @@ repeat:
78 90
79 /* more likely a read error */ 91 /* more likely a read error */
80 if (unlikely(!PageUptodate(page))) { 92 if (unlikely(!PageUptodate(page))) {
81 unlock_page(page); 93 if (io_retries) {
82 put_page(page); 94 --io_retries;
83 95 goto unlock_repeat;
84 page = ERR_PTR(-EIO); 96 }
97 err = -EIO;
98 goto err_out;
85 } 99 }
86 } 100 }
87 return page; 101 return page;
102
103err_out:
104 unlock_page(page);
105 put_page(page);
106 return ERR_PTR(err);
88} 107}
89 108
90static int erofs_map_blocks_flatmode(struct inode *inode, 109static int erofs_map_blocks_flatmode(struct inode *inode,
91 struct erofs_map_blocks *map, 110 struct erofs_map_blocks *map,
92 int flags) 111 int flags)
93{ 112{
113 int err = 0;
94 erofs_blk_t nblocks, lastblk; 114 erofs_blk_t nblocks, lastblk;
95 u64 offset = map->m_la; 115 u64 offset = map->m_la;
96 struct erofs_vnode *vi = EROFS_V(inode); 116 struct erofs_vnode *vi = EROFS_V(inode);
97 117
98 trace_erofs_map_blocks_flatmode_enter(inode, map, flags); 118 trace_erofs_map_blocks_flatmode_enter(inode, map, flags);
99 BUG_ON(is_inode_layout_compression(inode));
100 119
101 nblocks = DIV_ROUND_UP(inode->i_size, PAGE_SIZE); 120 nblocks = DIV_ROUND_UP(inode->i_size, PAGE_SIZE);
102 lastblk = nblocks - is_inode_layout_inline(inode); 121 lastblk = nblocks - is_inode_layout_inline(inode);
@@ -123,18 +142,27 @@ static int erofs_map_blocks_flatmode(struct inode *inode,
123 map->m_plen = inode->i_size - offset; 142 map->m_plen = inode->i_size - offset;
124 143
125 /* inline data should locate in one meta block */ 144 /* inline data should locate in one meta block */
126 BUG_ON(erofs_blkoff(map->m_pa) + map->m_plen > PAGE_SIZE); 145 if (erofs_blkoff(map->m_pa) + map->m_plen > PAGE_SIZE) {
146 DBG_BUGON(1);
147 err = -EIO;
148 goto err_out;
149 }
150
127 map->m_flags |= EROFS_MAP_META; 151 map->m_flags |= EROFS_MAP_META;
128 } else { 152 } else {
129 errln("internal error @ nid: %llu (size %llu), m_la 0x%llx", 153 errln("internal error @ nid: %llu (size %llu), m_la 0x%llx",
130 vi->nid, inode->i_size, map->m_la); 154 vi->nid, inode->i_size, map->m_la);
131 BUG(); 155 DBG_BUGON(1);
156 err = -EIO;
157 goto err_out;
132 } 158 }
133 159
134out: 160out:
135 map->m_llen = map->m_plen; 161 map->m_llen = map->m_plen;
162
163err_out:
136 trace_erofs_map_blocks_flatmode_exit(inode, map, flags, 0); 164 trace_erofs_map_blocks_flatmode_exit(inode, map, flags, 0);
137 return 0; 165 return err;
138} 166}
139 167
140#ifdef CONFIG_EROFS_FS_ZIP 168#ifdef CONFIG_EROFS_FS_ZIP
@@ -183,14 +211,14 @@ static inline struct bio *erofs_read_raw_page(
183 struct address_space *mapping, 211 struct address_space *mapping,
184 struct page *page, 212 struct page *page,
185 erofs_off_t *last_block, 213 erofs_off_t *last_block,
186 unsigned nblocks, 214 unsigned int nblocks,
187 bool ra) 215 bool ra)
188{ 216{
189 struct inode *inode = mapping->host; 217 struct inode *inode = mapping->host;
190 erofs_off_t current_block = (erofs_off_t)page->index; 218 erofs_off_t current_block = (erofs_off_t)page->index;
191 int err; 219 int err;
192 220
193 BUG_ON(!nblocks); 221 DBG_BUGON(!nblocks);
194 222
195 if (PageUptodate(page)) { 223 if (PageUptodate(page)) {
196 err = 0; 224 err = 0;
@@ -217,7 +245,7 @@ submit_bio_retry:
217 .m_la = blknr_to_addr(current_block), 245 .m_la = blknr_to_addr(current_block),
218 }; 246 };
219 erofs_blk_t blknr; 247 erofs_blk_t blknr;
220 unsigned blkoff; 248 unsigned int blkoff;
221 249
222 err = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW); 250 err = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW);
223 if (unlikely(err)) 251 if (unlikely(err))
@@ -233,7 +261,7 @@ submit_bio_retry:
233 } 261 }
234 262
235 /* for RAW access mode, m_plen must be equal to m_llen */ 263 /* for RAW access mode, m_plen must be equal to m_llen */
236 BUG_ON(map.m_plen != map.m_llen); 264 DBG_BUGON(map.m_plen != map.m_llen);
237 265
238 blknr = erofs_blknr(map.m_pa); 266 blknr = erofs_blknr(map.m_pa);
239 blkoff = erofs_blkoff(map.m_pa); 267 blkoff = erofs_blkoff(map.m_pa);
@@ -243,7 +271,7 @@ submit_bio_retry:
243 void *vsrc, *vto; 271 void *vsrc, *vto;
244 struct page *ipage; 272 struct page *ipage;
245 273
246 BUG_ON(map.m_plen > PAGE_SIZE); 274 DBG_BUGON(map.m_plen > PAGE_SIZE);
247 275
248 ipage = erofs_get_meta_page(inode->i_sb, blknr, 0); 276 ipage = erofs_get_meta_page(inode->i_sb, blknr, 0);
249 277
@@ -270,7 +298,7 @@ submit_bio_retry:
270 } 298 }
271 299
272 /* pa must be block-aligned for raw reading */ 300 /* pa must be block-aligned for raw reading */
273 BUG_ON(erofs_blkoff(map.m_pa) != 0); 301 DBG_BUGON(erofs_blkoff(map.m_pa));
274 302
275 /* max # of continuous pages */ 303 /* max # of continuous pages */
276 if (nblocks > DIV_ROUND_UP(map.m_plen, PAGE_SIZE)) 304 if (nblocks > DIV_ROUND_UP(map.m_plen, PAGE_SIZE))
@@ -278,7 +306,14 @@ submit_bio_retry:
278 if (nblocks > BIO_MAX_PAGES) 306 if (nblocks > BIO_MAX_PAGES)
279 nblocks = BIO_MAX_PAGES; 307 nblocks = BIO_MAX_PAGES;
280 308
281 bio = prepare_bio(inode->i_sb, blknr, nblocks, read_endio); 309 bio = erofs_grab_bio(inode->i_sb,
310 blknr, nblocks, read_endio, false);
311
312 if (IS_ERR(bio)) {
313 err = PTR_ERR(bio);
314 bio = NULL;
315 goto err_out;
316 }
282 } 317 }
283 318
284 err = bio_add_page(bio, page, PAGE_SIZE, 0); 319 err = bio_add_page(bio, page, PAGE_SIZE, 0);
@@ -331,13 +366,13 @@ static int erofs_raw_access_readpage(struct file *file, struct page *page)
331 if (IS_ERR(bio)) 366 if (IS_ERR(bio))
332 return PTR_ERR(bio); 367 return PTR_ERR(bio);
333 368
334 BUG_ON(bio != NULL); /* since we have only one bio -- must be NULL */ 369 DBG_BUGON(bio); /* since we have only one bio -- must be NULL */
335 return 0; 370 return 0;
336} 371}
337 372
338static int erofs_raw_access_readpages(struct file *filp, 373static int erofs_raw_access_readpages(struct file *filp,
339 struct address_space *mapping, 374 struct address_space *mapping,
340 struct list_head *pages, unsigned nr_pages) 375 struct list_head *pages, unsigned int nr_pages)
341{ 376{
342 erofs_off_t last_block; 377 erofs_off_t last_block;
343 struct bio *bio = NULL; 378 struct bio *bio = NULL;
@@ -369,7 +404,7 @@ static int erofs_raw_access_readpages(struct file *filp,
369 /* pages could still be locked */ 404 /* pages could still be locked */
370 put_page(page); 405 put_page(page);
371 } 406 }
372 BUG_ON(!list_empty(pages)); 407 DBG_BUGON(!list_empty(pages));
373 408
374 /* the rare case (end in gaps) */ 409 /* the rare case (end in gaps) */
375 if (unlikely(bio != NULL)) 410 if (unlikely(bio != NULL))
diff --git a/drivers/staging/erofs/dir.c b/drivers/staging/erofs/dir.c
index be6ae3b1bdbe..d1cb0d78ab84 100644
--- a/drivers/staging/erofs/dir.c
+++ b/drivers/staging/erofs/dir.c
@@ -24,8 +24,8 @@ static const unsigned char erofs_filetype_table[EROFS_FT_MAX] = {
24}; 24};
25 25
26static int erofs_fill_dentries(struct dir_context *ctx, 26static int erofs_fill_dentries(struct dir_context *ctx,
27 void *dentry_blk, unsigned *ofs, 27 void *dentry_blk, unsigned int *ofs,
28 unsigned nameoff, unsigned maxsize) 28 unsigned int nameoff, unsigned int maxsize)
29{ 29{
30 struct erofs_dirent *de = dentry_blk; 30 struct erofs_dirent *de = dentry_blk;
31 const struct erofs_dirent *end = dentry_blk + nameoff; 31 const struct erofs_dirent *end = dentry_blk + nameoff;
@@ -36,7 +36,7 @@ static int erofs_fill_dentries(struct dir_context *ctx,
36 int de_namelen; 36 int de_namelen;
37 unsigned char d_type; 37 unsigned char d_type;
38#ifdef CONFIG_EROFS_FS_DEBUG 38#ifdef CONFIG_EROFS_FS_DEBUG
39 unsigned dbg_namelen; 39 unsigned int dbg_namelen;
40 unsigned char dbg_namebuf[EROFS_NAME_LEN]; 40 unsigned char dbg_namebuf[EROFS_NAME_LEN];
41#endif 41#endif
42 42
@@ -81,15 +81,15 @@ static int erofs_readdir(struct file *f, struct dir_context *ctx)
81 struct inode *dir = file_inode(f); 81 struct inode *dir = file_inode(f);
82 struct address_space *mapping = dir->i_mapping; 82 struct address_space *mapping = dir->i_mapping;
83 const size_t dirsize = i_size_read(dir); 83 const size_t dirsize = i_size_read(dir);
84 unsigned i = ctx->pos / EROFS_BLKSIZ; 84 unsigned int i = ctx->pos / EROFS_BLKSIZ;
85 unsigned ofs = ctx->pos % EROFS_BLKSIZ; 85 unsigned int ofs = ctx->pos % EROFS_BLKSIZ;
86 int err = 0; 86 int err = 0;
87 bool initial = true; 87 bool initial = true;
88 88
89 while (ctx->pos < dirsize) { 89 while (ctx->pos < dirsize) {
90 struct page *dentry_page; 90 struct page *dentry_page;
91 struct erofs_dirent *de; 91 struct erofs_dirent *de;
92 unsigned nameoff, maxsize; 92 unsigned int nameoff, maxsize;
93 93
94 dentry_page = read_mapping_page(mapping, i, NULL); 94 dentry_page = read_mapping_page(mapping, i, NULL);
95 if (IS_ERR(dentry_page)) 95 if (IS_ERR(dentry_page))
@@ -109,7 +109,8 @@ static int erofs_readdir(struct file *f, struct dir_context *ctx)
109 goto skip_this; 109 goto skip_this;
110 } 110 }
111 111
112 maxsize = min_t(unsigned, dirsize - ctx->pos + ofs, PAGE_SIZE); 112 maxsize = min_t(unsigned int,
113 dirsize - ctx->pos + ofs, PAGE_SIZE);
113 114
114 /* search dirents at the arbitrary position */ 115 /* search dirents at the arbitrary position */
115 if (unlikely(initial)) { 116 if (unlikely(initial)) {
diff --git a/drivers/staging/erofs/erofs_fs.h b/drivers/staging/erofs/erofs_fs.h
index 2f8e2bf70941..d4bffa2852b3 100644
--- a/drivers/staging/erofs/erofs_fs.h
+++ b/drivers/staging/erofs/erofs_fs.h
@@ -202,6 +202,14 @@ struct erofs_extent_header {
202 * di_u.delta[1] = distance to its corresponding tail cluster 202 * di_u.delta[1] = distance to its corresponding tail cluster
203 * (di_advise could be 0, 1 or 2) 203 * (di_advise could be 0, 1 or 2)
204 */ 204 */
205enum {
206 Z_EROFS_VLE_CLUSTER_TYPE_PLAIN,
207 Z_EROFS_VLE_CLUSTER_TYPE_HEAD,
208 Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD,
209 Z_EROFS_VLE_CLUSTER_TYPE_RESERVED,
210 Z_EROFS_VLE_CLUSTER_TYPE_MAX
211};
212
205#define Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS 2 213#define Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS 2
206#define Z_EROFS_VLE_DI_CLUSTER_TYPE_BIT 0 214#define Z_EROFS_VLE_DI_CLUSTER_TYPE_BIT 0
207 215
@@ -260,6 +268,9 @@ static inline void erofs_check_ondisk_layout_definitions(void)
260 BUILD_BUG_ON(sizeof(struct erofs_extent_header) != 16); 268 BUILD_BUG_ON(sizeof(struct erofs_extent_header) != 16);
261 BUILD_BUG_ON(sizeof(struct z_erofs_vle_decompressed_index) != 8); 269 BUILD_BUG_ON(sizeof(struct z_erofs_vle_decompressed_index) != 8);
262 BUILD_BUG_ON(sizeof(struct erofs_dirent) != 12); 270 BUILD_BUG_ON(sizeof(struct erofs_dirent) != 12);
271
272 BUILD_BUG_ON(BIT(Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS) <
273 Z_EROFS_VLE_CLUSTER_TYPE_MAX - 1);
263} 274}
264 275
265#endif 276#endif
diff --git a/drivers/staging/erofs/include/trace/events/erofs.h b/drivers/staging/erofs/include/trace/events/erofs.h
index 5aead93a762f..660c92fc1803 100644
--- a/drivers/staging/erofs/include/trace/events/erofs.h
+++ b/drivers/staging/erofs/include/trace/events/erofs.h
@@ -162,7 +162,8 @@ DECLARE_EVENT_CLASS(erofs__map_blocks_enter,
162 162
163 TP_printk("dev = (%d,%d), nid = %llu, la %llu llen %llu flags %s", 163 TP_printk("dev = (%d,%d), nid = %llu, la %llu llen %llu flags %s",
164 show_dev_nid(__entry), 164 show_dev_nid(__entry),
165 __entry->la, __entry->llen, show_map_flags(__entry->flags)) 165 __entry->la, __entry->llen,
166 __entry->flags ? show_map_flags(__entry->flags) : "NULL")
166); 167);
167 168
168DEFINE_EVENT(erofs__map_blocks_enter, erofs_map_blocks_flatmode_enter, 169DEFINE_EVENT(erofs__map_blocks_enter, erofs_map_blocks_flatmode_enter,
@@ -172,6 +173,13 @@ DEFINE_EVENT(erofs__map_blocks_enter, erofs_map_blocks_flatmode_enter,
172 TP_ARGS(inode, map, flags) 173 TP_ARGS(inode, map, flags)
173); 174);
174 175
176DEFINE_EVENT(erofs__map_blocks_enter, z_erofs_map_blocks_iter_enter,
177 TP_PROTO(struct inode *inode, struct erofs_map_blocks *map,
178 unsigned int flags),
179
180 TP_ARGS(inode, map, flags)
181);
182
175DECLARE_EVENT_CLASS(erofs__map_blocks_exit, 183DECLARE_EVENT_CLASS(erofs__map_blocks_exit,
176 TP_PROTO(struct inode *inode, struct erofs_map_blocks *map, 184 TP_PROTO(struct inode *inode, struct erofs_map_blocks *map,
177 unsigned int flags, int ret), 185 unsigned int flags, int ret),
@@ -204,7 +212,8 @@ DECLARE_EVENT_CLASS(erofs__map_blocks_exit,
204 212
205 TP_printk("dev = (%d,%d), nid = %llu, flags %s " 213 TP_printk("dev = (%d,%d), nid = %llu, flags %s "
206 "la %llu pa %llu llen %llu plen %llu mflags %s ret %d", 214 "la %llu pa %llu llen %llu plen %llu mflags %s ret %d",
207 show_dev_nid(__entry), show_map_flags(__entry->flags), 215 show_dev_nid(__entry),
216 __entry->flags ? show_map_flags(__entry->flags) : "NULL",
208 __entry->la, __entry->pa, __entry->llen, __entry->plen, 217 __entry->la, __entry->pa, __entry->llen, __entry->plen,
209 show_mflags(__entry->mflags), __entry->ret) 218 show_mflags(__entry->mflags), __entry->ret)
210); 219);
@@ -216,6 +225,13 @@ DEFINE_EVENT(erofs__map_blocks_exit, erofs_map_blocks_flatmode_exit,
216 TP_ARGS(inode, map, flags, ret) 225 TP_ARGS(inode, map, flags, ret)
217); 226);
218 227
228DEFINE_EVENT(erofs__map_blocks_exit, z_erofs_map_blocks_iter_exit,
229 TP_PROTO(struct inode *inode, struct erofs_map_blocks *map,
230 unsigned int flags, int ret),
231
232 TP_ARGS(inode, map, flags, ret)
233);
234
219TRACE_EVENT(erofs_destroy_inode, 235TRACE_EVENT(erofs_destroy_inode,
220 TP_PROTO(struct inode *inode), 236 TP_PROTO(struct inode *inode),
221 237
diff --git a/drivers/staging/erofs/inode.c b/drivers/staging/erofs/inode.c
index fbf6ff25cd1b..04c61a9d7b76 100644
--- a/drivers/staging/erofs/inode.c
+++ b/drivers/staging/erofs/inode.c
@@ -19,7 +19,7 @@ static int read_inode(struct inode *inode, void *data)
19{ 19{
20 struct erofs_vnode *vi = EROFS_V(inode); 20 struct erofs_vnode *vi = EROFS_V(inode);
21 struct erofs_inode_v1 *v1 = data; 21 struct erofs_inode_v1 *v1 = data;
22 const unsigned advise = le16_to_cpu(v1->i_advise); 22 const unsigned int advise = le16_to_cpu(v1->i_advise);
23 23
24 vi->data_mapping_mode = __inode_data_mapping(advise); 24 vi->data_mapping_mode = __inode_data_mapping(advise);
25 25
@@ -112,7 +112,8 @@ static int read_inode(struct inode *inode, void *data)
112 * try_lock since it takes no much overhead and 112 * try_lock since it takes no much overhead and
113 * will success immediately. 113 * will success immediately.
114 */ 114 */
115static int fill_inline_data(struct inode *inode, void *data, unsigned m_pofs) 115static int fill_inline_data(struct inode *inode, void *data,
116 unsigned int m_pofs)
116{ 117{
117 struct erofs_vnode *vi = EROFS_V(inode); 118 struct erofs_vnode *vi = EROFS_V(inode);
118 struct erofs_sb_info *sbi = EROFS_I_SB(inode); 119 struct erofs_sb_info *sbi = EROFS_I_SB(inode);
@@ -152,7 +153,7 @@ static int fill_inode(struct inode *inode, int isdir)
152 void *data; 153 void *data;
153 int err; 154 int err;
154 erofs_blk_t blkaddr; 155 erofs_blk_t blkaddr;
155 unsigned ofs; 156 unsigned int ofs;
156 157
157 trace_erofs_fill_inode(inode, isdir); 158 trace_erofs_fill_inode(inode, isdir);
158 159
@@ -231,10 +232,45 @@ out_unlock:
231 return err; 232 return err;
232} 233}
233 234
235/*
236 * erofs nid is 64bits, but i_ino is 'unsigned long', therefore
237 * we should do more for 32-bit platform to find the right inode.
238 */
239#if BITS_PER_LONG == 32
240static int erofs_ilookup_test_actor(struct inode *inode, void *opaque)
241{
242 const erofs_nid_t nid = *(erofs_nid_t *)opaque;
243
244 return EROFS_V(inode)->nid == nid;
245}
246
247static int erofs_iget_set_actor(struct inode *inode, void *opaque)
248{
249 const erofs_nid_t nid = *(erofs_nid_t *)opaque;
250
251 inode->i_ino = erofs_inode_hash(nid);
252 return 0;
253}
254#endif
255
256static inline struct inode *erofs_iget_locked(struct super_block *sb,
257 erofs_nid_t nid)
258{
259 const unsigned long hashval = erofs_inode_hash(nid);
260
261#if BITS_PER_LONG >= 64
262 /* it is safe to use iget_locked for >= 64-bit platform */
263 return iget_locked(sb, hashval);
264#else
265 return iget5_locked(sb, hashval, erofs_ilookup_test_actor,
266 erofs_iget_set_actor, &nid);
267#endif
268}
269
234struct inode *erofs_iget(struct super_block *sb, 270struct inode *erofs_iget(struct super_block *sb,
235 erofs_nid_t nid, bool isdir) 271 erofs_nid_t nid, bool isdir)
236{ 272{
237 struct inode *inode = iget_locked(sb, nid); 273 struct inode *inode = erofs_iget_locked(sb, nid);
238 274
239 if (unlikely(inode == NULL)) 275 if (unlikely(inode == NULL))
240 return ERR_PTR(-ENOMEM); 276 return ERR_PTR(-ENOMEM);
@@ -259,22 +295,16 @@ struct inode *erofs_iget(struct super_block *sb,
259const struct inode_operations erofs_generic_xattr_iops = { 295const struct inode_operations erofs_generic_xattr_iops = {
260 .listxattr = erofs_listxattr, 296 .listxattr = erofs_listxattr,
261}; 297};
262#endif
263 298
264#ifdef CONFIG_EROFS_FS_XATTR
265const struct inode_operations erofs_symlink_xattr_iops = { 299const struct inode_operations erofs_symlink_xattr_iops = {
266 .get_link = page_get_link, 300 .get_link = page_get_link,
267 .listxattr = erofs_listxattr, 301 .listxattr = erofs_listxattr,
268}; 302};
269#endif
270 303
271const struct inode_operations erofs_special_inode_operations = { 304const struct inode_operations erofs_special_inode_operations = {
272#ifdef CONFIG_EROFS_FS_XATTR
273 .listxattr = erofs_listxattr, 305 .listxattr = erofs_listxattr,
274#endif
275}; 306};
276 307
277#ifdef CONFIG_EROFS_FS_XATTR
278const struct inode_operations erofs_fast_symlink_xattr_iops = { 308const struct inode_operations erofs_fast_symlink_xattr_iops = {
279 .get_link = simple_get_link, 309 .get_link = simple_get_link,
280 .listxattr = erofs_listxattr, 310 .listxattr = erofs_listxattr,
diff --git a/drivers/staging/erofs/internal.h b/drivers/staging/erofs/internal.h
index 367b39fe46e5..57575c7f5635 100644
--- a/drivers/staging/erofs/internal.h
+++ b/drivers/staging/erofs/internal.h
@@ -42,12 +42,12 @@
42#define DBG_BUGON(...) ((void)0) 42#define DBG_BUGON(...) ((void)0)
43#endif 43#endif
44 44
45#ifdef CONFIG_EROFS_FAULT_INJECTION
46enum { 45enum {
47 FAULT_KMALLOC, 46 FAULT_KMALLOC,
48 FAULT_MAX, 47 FAULT_MAX,
49}; 48};
50 49
50#ifdef CONFIG_EROFS_FAULT_INJECTION
51extern char *erofs_fault_name[FAULT_MAX]; 51extern char *erofs_fault_name[FAULT_MAX];
52#define IS_FAULT_SET(fi, type) ((fi)->inject_type & (1 << (type))) 52#define IS_FAULT_SET(fi, type) ((fi)->inject_type & (1 << (type)))
53 53
@@ -95,6 +95,9 @@ struct erofs_sb_info {
95 /* the dedicated workstation for compression */ 95 /* the dedicated workstation for compression */
96 struct radix_tree_root workstn_tree; 96 struct radix_tree_root workstn_tree;
97 97
98 /* threshold for decompression synchronously */
99 unsigned int max_sync_decompress_pages;
100
98#ifdef EROFS_FS_HAS_MANAGED_CACHE 101#ifdef EROFS_FS_HAS_MANAGED_CACHE
99 struct inode *managed_cache; 102 struct inode *managed_cache;
100#endif 103#endif
@@ -143,17 +146,24 @@ static inline bool time_to_inject(struct erofs_sb_info *sbi, int type)
143 } 146 }
144 return false; 147 return false;
145} 148}
149#else
150static inline bool time_to_inject(struct erofs_sb_info *sbi, int type)
151{
152 return false;
153}
154
155static inline void erofs_show_injection_info(int type)
156{
157}
146#endif 158#endif
147 159
148static inline void *erofs_kmalloc(struct erofs_sb_info *sbi, 160static inline void *erofs_kmalloc(struct erofs_sb_info *sbi,
149 size_t size, gfp_t flags) 161 size_t size, gfp_t flags)
150{ 162{
151#ifdef CONFIG_EROFS_FAULT_INJECTION
152 if (time_to_inject(sbi, FAULT_KMALLOC)) { 163 if (time_to_inject(sbi, FAULT_KMALLOC)) {
153 erofs_show_injection_info(FAULT_KMALLOC); 164 erofs_show_injection_info(FAULT_KMALLOC);
154 return NULL; 165 return NULL;
155 } 166 }
156#endif
157 return kmalloc(size, flags); 167 return kmalloc(size, flags);
158} 168}
159 169
@@ -266,6 +276,20 @@ extern int erofs_try_to_free_cached_page(struct address_space *mapping,
266 struct page *page); 276 struct page *page);
267#endif 277#endif
268 278
279#define DEFAULT_MAX_SYNC_DECOMPRESS_PAGES 3
280
281static inline bool __should_decompress_synchronously(struct erofs_sb_info *sbi,
282 unsigned int nr)
283{
284 return nr <= sbi->max_sync_decompress_pages;
285}
286
287int __init z_erofs_init_zip_subsystem(void);
288void z_erofs_exit_zip_subsystem(void);
289#else
290/* dummy initializer/finalizer for the decompression subsystem */
291static inline int z_erofs_init_zip_subsystem(void) { return 0; }
292static inline void z_erofs_exit_zip_subsystem(void) {}
269#endif 293#endif
270 294
271/* we strictly follow PAGE_SIZE and no buffer head yet */ 295/* we strictly follow PAGE_SIZE and no buffer head yet */
@@ -420,30 +444,30 @@ struct erofs_map_blocks {
420#define EROFS_GET_BLOCKS_RAW 0x0001 444#define EROFS_GET_BLOCKS_RAW 0x0001
421 445
422/* data.c */ 446/* data.c */
423static inline struct bio *prepare_bio( 447static inline struct bio *
424 struct super_block *sb, 448erofs_grab_bio(struct super_block *sb,
425 erofs_blk_t blkaddr, unsigned nr_pages, 449 erofs_blk_t blkaddr, unsigned int nr_pages,
426 bio_end_io_t endio) 450 bio_end_io_t endio, bool nofail)
427{ 451{
428 gfp_t gfp = GFP_NOIO; 452 const gfp_t gfp = GFP_NOIO;
429 struct bio *bio = bio_alloc(gfp, nr_pages); 453 struct bio *bio;
430 454
431 if (unlikely(bio == NULL) && 455 do {
432 (current->flags & PF_MEMALLOC)) { 456 if (nr_pages == 1) {
433 do { 457 bio = bio_alloc(gfp | (nofail ? __GFP_NOFAIL : 0), 1);
434 nr_pages /= 2; 458 if (unlikely(bio == NULL)) {
435 if (unlikely(!nr_pages)) { 459 DBG_BUGON(nofail);
436 bio = bio_alloc(gfp | __GFP_NOFAIL, 1); 460 return ERR_PTR(-ENOMEM);
437 BUG_ON(bio == NULL);
438 break;
439 } 461 }
440 bio = bio_alloc(gfp, nr_pages); 462 break;
441 } while (bio == NULL); 463 }
442 } 464 bio = bio_alloc(gfp, nr_pages);
465 nr_pages /= 2;
466 } while (unlikely(bio == NULL));
443 467
444 bio->bi_end_io = endio; 468 bio->bi_end_io = endio;
445 bio_set_dev(bio, sb->s_bdev); 469 bio_set_dev(bio, sb->s_bdev);
446 bio->bi_iter.bi_sector = blkaddr << LOG_SECTORS_PER_BLOCK; 470 bio->bi_iter.bi_sector = (sector_t)blkaddr << LOG_SECTORS_PER_BLOCK;
447 return bio; 471 return bio;
448} 472}
449 473
@@ -453,8 +477,27 @@ static inline void __submit_bio(struct bio *bio, unsigned op, unsigned op_flags)
453 submit_bio(bio); 477 submit_bio(bio);
454} 478}
455 479
456extern struct page *erofs_get_meta_page(struct super_block *sb, 480#ifndef CONFIG_EROFS_FS_IO_MAX_RETRIES
457 erofs_blk_t blkaddr, bool prio); 481#define EROFS_IO_MAX_RETRIES_NOFAIL 0
482#else
483#define EROFS_IO_MAX_RETRIES_NOFAIL CONFIG_EROFS_FS_IO_MAX_RETRIES
484#endif
485
486extern struct page *__erofs_get_meta_page(struct super_block *sb,
487 erofs_blk_t blkaddr, bool prio, bool nofail);
488
489static inline struct page *erofs_get_meta_page(struct super_block *sb,
490 erofs_blk_t blkaddr, bool prio)
491{
492 return __erofs_get_meta_page(sb, blkaddr, prio, false);
493}
494
495static inline struct page *erofs_get_meta_page_nofail(struct super_block *sb,
496 erofs_blk_t blkaddr, bool prio)
497{
498 return __erofs_get_meta_page(sb, blkaddr, prio, true);
499}
500
458extern int erofs_map_blocks(struct inode *, struct erofs_map_blocks *, int); 501extern int erofs_map_blocks(struct inode *, struct erofs_map_blocks *, int);
459extern int erofs_map_blocks_iter(struct inode *, struct erofs_map_blocks *, 502extern int erofs_map_blocks_iter(struct inode *, struct erofs_map_blocks *,
460 struct page **, int); 503 struct page **, int);
@@ -465,14 +508,24 @@ struct erofs_map_blocks_iter {
465}; 508};
466 509
467 510
468static inline struct page *erofs_get_inline_page(struct inode *inode, 511static inline struct page *
469 erofs_blk_t blkaddr) 512erofs_get_inline_page(struct inode *inode,
513 erofs_blk_t blkaddr)
470{ 514{
471 return erofs_get_meta_page(inode->i_sb, 515 return erofs_get_meta_page(inode->i_sb,
472 blkaddr, S_ISDIR(inode->i_mode)); 516 blkaddr, S_ISDIR(inode->i_mode));
473} 517}
474 518
475/* inode.c */ 519/* inode.c */
520static inline unsigned long erofs_inode_hash(erofs_nid_t nid)
521{
522#if BITS_PER_LONG == 32
523 return (nid >> 32) ^ (nid & 0xffffffff);
524#else
525 return nid;
526#endif
527}
528
476extern struct inode *erofs_iget(struct super_block *sb, 529extern struct inode *erofs_iget(struct super_block *sb,
477 erofs_nid_t nid, bool dir); 530 erofs_nid_t nid, bool dir);
478 531
@@ -480,13 +533,11 @@ extern struct inode *erofs_iget(struct super_block *sb,
480int erofs_namei(struct inode *dir, struct qstr *name, 533int erofs_namei(struct inode *dir, struct qstr *name,
481 erofs_nid_t *nid, unsigned *d_type); 534 erofs_nid_t *nid, unsigned *d_type);
482 535
483/* xattr.c */
484#ifdef CONFIG_EROFS_FS_XATTR 536#ifdef CONFIG_EROFS_FS_XATTR
537/* xattr.c */
485extern const struct xattr_handler *erofs_xattr_handlers[]; 538extern const struct xattr_handler *erofs_xattr_handlers[];
486#endif
487 539
488/* symlink */ 540/* symlink and special inode */
489#ifdef CONFIG_EROFS_FS_XATTR
490extern const struct inode_operations erofs_symlink_xattr_iops; 541extern const struct inode_operations erofs_symlink_xattr_iops;
491extern const struct inode_operations erofs_fast_symlink_xattr_iops; 542extern const struct inode_operations erofs_fast_symlink_xattr_iops;
492extern const struct inode_operations erofs_special_inode_operations; 543extern const struct inode_operations erofs_special_inode_operations;
diff --git a/drivers/staging/erofs/namei.c b/drivers/staging/erofs/namei.c
index 8cf0617d4ea0..5596c52e246d 100644
--- a/drivers/staging/erofs/namei.c
+++ b/drivers/staging/erofs/namei.c
@@ -17,9 +17,9 @@
17 17
18/* based on the value of qn->len is accurate */ 18/* based on the value of qn->len is accurate */
19static inline int dirnamecmp(struct qstr *qn, 19static inline int dirnamecmp(struct qstr *qn,
20 struct qstr *qd, unsigned *matched) 20 struct qstr *qd, unsigned int *matched)
21{ 21{
22 unsigned i = *matched, len = min(qn->len, qd->len); 22 unsigned int i = *matched, len = min(qn->len, qd->len);
23loop: 23loop:
24 if (unlikely(i >= len)) { 24 if (unlikely(i >= len)) {
25 *matched = i; 25 *matched = i;
@@ -46,8 +46,8 @@ static struct erofs_dirent *find_target_dirent(
46 struct qstr *name, 46 struct qstr *name,
47 u8 *data, int maxsize) 47 u8 *data, int maxsize)
48{ 48{
49 unsigned ndirents, head, back; 49 unsigned int ndirents, head, back;
50 unsigned startprfx, endprfx; 50 unsigned int startprfx, endprfx;
51 struct erofs_dirent *const de = (struct erofs_dirent *)data; 51 struct erofs_dirent *const de = (struct erofs_dirent *)data;
52 52
53 /* make sure that maxsize is valid */ 53 /* make sure that maxsize is valid */
@@ -63,9 +63,9 @@ static struct erofs_dirent *find_target_dirent(
63 startprfx = endprfx = 0; 63 startprfx = endprfx = 0;
64 64
65 while (head <= back) { 65 while (head <= back) {
66 unsigned mid = head + (back - head) / 2; 66 unsigned int mid = head + (back - head) / 2;
67 unsigned nameoff = le16_to_cpu(de[mid].nameoff); 67 unsigned int nameoff = le16_to_cpu(de[mid].nameoff);
68 unsigned matched = min(startprfx, endprfx); 68 unsigned int matched = min(startprfx, endprfx);
69 69
70 struct qstr dname = QSTR_INIT(data + nameoff, 70 struct qstr dname = QSTR_INIT(data + nameoff,
71 unlikely(mid >= ndirents - 1) ? 71 unlikely(mid >= ndirents - 1) ?
@@ -95,8 +95,8 @@ static struct page *find_target_block_classic(
95 struct inode *dir, 95 struct inode *dir,
96 struct qstr *name, int *_diff) 96 struct qstr *name, int *_diff)
97{ 97{
98 unsigned startprfx, endprfx; 98 unsigned int startprfx, endprfx;
99 unsigned head, back; 99 unsigned int head, back;
100 struct address_space *const mapping = dir->i_mapping; 100 struct address_space *const mapping = dir->i_mapping;
101 struct page *candidate = ERR_PTR(-ENOENT); 101 struct page *candidate = ERR_PTR(-ENOENT);
102 102
@@ -105,7 +105,7 @@ static struct page *find_target_block_classic(
105 back = inode_datablocks(dir) - 1; 105 back = inode_datablocks(dir) - 1;
106 106
107 while (head <= back) { 107 while (head <= back) {
108 unsigned mid = head + (back - head) / 2; 108 unsigned int mid = head + (back - head) / 2;
109 struct page *page = read_mapping_page(mapping, mid, NULL); 109 struct page *page = read_mapping_page(mapping, mid, NULL);
110 110
111 if (IS_ERR(page)) { 111 if (IS_ERR(page)) {
@@ -115,10 +115,10 @@ exact_out:
115 return page; 115 return page;
116 } else { 116 } else {
117 int diff; 117 int diff;
118 unsigned ndirents, matched; 118 unsigned int ndirents, matched;
119 struct qstr dname; 119 struct qstr dname;
120 struct erofs_dirent *de = kmap_atomic(page); 120 struct erofs_dirent *de = kmap_atomic(page);
121 unsigned nameoff = le16_to_cpu(de->nameoff); 121 unsigned int nameoff = le16_to_cpu(de->nameoff);
122 122
123 ndirents = nameoff / sizeof(*de); 123 ndirents = nameoff / sizeof(*de);
124 124
@@ -164,7 +164,7 @@ exact_out:
164 164
165int erofs_namei(struct inode *dir, 165int erofs_namei(struct inode *dir,
166 struct qstr *name, 166 struct qstr *name,
167 erofs_nid_t *nid, unsigned *d_type) 167 erofs_nid_t *nid, unsigned int *d_type)
168{ 168{
169 int diff; 169 int diff;
170 struct page *page; 170 struct page *page;
@@ -204,7 +204,7 @@ static struct dentry *erofs_lookup(struct inode *dir,
204{ 204{
205 int err; 205 int err;
206 erofs_nid_t nid; 206 erofs_nid_t nid;
207 unsigned d_type; 207 unsigned int d_type;
208 struct inode *inode; 208 struct inode *inode;
209 209
210 DBG_BUGON(!d_really_is_negative(dentry)); 210 DBG_BUGON(!d_really_is_negative(dentry));
diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index 2df9768edac9..f69e619807a1 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -29,7 +29,7 @@ static void init_once(void *ptr)
29 inode_init_once(&vi->vfs_inode); 29 inode_init_once(&vi->vfs_inode);
30} 30}
31 31
32static int erofs_init_inode_cache(void) 32static int __init erofs_init_inode_cache(void)
33{ 33{
34 erofs_inode_cachep = kmem_cache_create("erofs_inode", 34 erofs_inode_cachep = kmem_cache_create("erofs_inode",
35 sizeof(struct erofs_vnode), 0, 35 sizeof(struct erofs_vnode), 0,
@@ -81,7 +81,7 @@ static int superblock_read(struct super_block *sb)
81 struct erofs_sb_info *sbi; 81 struct erofs_sb_info *sbi;
82 struct buffer_head *bh; 82 struct buffer_head *bh;
83 struct erofs_super_block *layout; 83 struct erofs_super_block *layout;
84 unsigned blkszbits; 84 unsigned int blkszbits;
85 int ret; 85 int ret;
86 86
87 bh = sb_bread(sb, 0); 87 bh = sb_bread(sb, 0);
@@ -116,9 +116,10 @@ static int superblock_read(struct super_block *sb)
116#endif 116#endif
117 sbi->islotbits = ffs(sizeof(struct erofs_inode_v1)) - 1; 117 sbi->islotbits = ffs(sizeof(struct erofs_inode_v1)) - 1;
118#ifdef CONFIG_EROFS_FS_ZIP 118#ifdef CONFIG_EROFS_FS_ZIP
119 sbi->clusterbits = 12; 119 /* TODO: clusterbits should be related to inode */
120 sbi->clusterbits = blkszbits;
120 121
121 if (1 << (sbi->clusterbits - 12) > Z_EROFS_CLUSTER_MAX_PAGES) 122 if (1 << (sbi->clusterbits - PAGE_SHIFT) > Z_EROFS_CLUSTER_MAX_PAGES)
122 errln("clusterbits %u is not supported on this kernel", 123 errln("clusterbits %u is not supported on this kernel",
123 sbi->clusterbits); 124 sbi->clusterbits);
124#endif 125#endif
@@ -144,8 +145,8 @@ char *erofs_fault_name[FAULT_MAX] = {
144 [FAULT_KMALLOC] = "kmalloc", 145 [FAULT_KMALLOC] = "kmalloc",
145}; 146};
146 147
147static void erofs_build_fault_attr(struct erofs_sb_info *sbi, 148static void __erofs_build_fault_attr(struct erofs_sb_info *sbi,
148 unsigned int rate) 149 unsigned int rate)
149{ 150{
150 struct erofs_fault_info *ffi = &sbi->fault_info; 151 struct erofs_fault_info *ffi = &sbi->fault_info;
151 152
@@ -156,11 +157,52 @@ static void erofs_build_fault_attr(struct erofs_sb_info *sbi,
156 } else { 157 } else {
157 memset(ffi, 0, sizeof(struct erofs_fault_info)); 158 memset(ffi, 0, sizeof(struct erofs_fault_info));
158 } 159 }
160
161 set_opt(sbi, FAULT_INJECTION);
162}
163
164static int erofs_build_fault_attr(struct erofs_sb_info *sbi,
165 substring_t *args)
166{
167 int rate = 0;
168
169 if (args->from && match_int(args, &rate))
170 return -EINVAL;
171
172 __erofs_build_fault_attr(sbi, rate);
173 return 0;
174}
175
176static unsigned int erofs_get_fault_rate(struct erofs_sb_info *sbi)
177{
178 return sbi->fault_info.inject_rate;
179}
180#else
181static void __erofs_build_fault_attr(struct erofs_sb_info *sbi,
182 unsigned int rate)
183{
184}
185
186static int erofs_build_fault_attr(struct erofs_sb_info *sbi,
187 substring_t *args)
188{
189 infoln("fault_injection options not supported");
190 return 0;
191}
192
193static unsigned int erofs_get_fault_rate(struct erofs_sb_info *sbi)
194{
195 return 0;
159} 196}
160#endif 197#endif
161 198
162static void default_options(struct erofs_sb_info *sbi) 199static void default_options(struct erofs_sb_info *sbi)
163{ 200{
201 /* set up some FS parameters */
202#ifdef CONFIG_EROFS_FS_ZIP
203 sbi->max_sync_decompress_pages = DEFAULT_MAX_SYNC_DECOMPRESS_PAGES;
204#endif
205
164#ifdef CONFIG_EROFS_FS_XATTR 206#ifdef CONFIG_EROFS_FS_XATTR
165 set_opt(sbi, XATTR_USER); 207 set_opt(sbi, XATTR_USER);
166#endif 208#endif
@@ -192,7 +234,7 @@ static int parse_options(struct super_block *sb, char *options)
192{ 234{
193 substring_t args[MAX_OPT_ARGS]; 235 substring_t args[MAX_OPT_ARGS];
194 char *p; 236 char *p;
195 int arg = 0; 237 int err;
196 238
197 if (!options) 239 if (!options)
198 return 0; 240 return 0;
@@ -238,15 +280,11 @@ static int parse_options(struct super_block *sb, char *options)
238 break; 280 break;
239#endif 281#endif
240 case Opt_fault_injection: 282 case Opt_fault_injection:
241 if (args->from && match_int(args, &arg)) 283 err = erofs_build_fault_attr(EROFS_SB(sb), args);
242 return -EINVAL; 284 if (err)
243#ifdef CONFIG_EROFS_FAULT_INJECTION 285 return err;
244 erofs_build_fault_attr(EROFS_SB(sb), arg);
245 set_opt(EROFS_SB(sb), FAULT_INJECTION);
246#else
247 infoln("FAULT_INJECTION was not selected");
248#endif
249 break; 286 break;
287
250 default: 288 default:
251 errln("Unrecognized mount option \"%s\" " 289 errln("Unrecognized mount option \"%s\" "
252 "or missing value", p); 290 "or missing value", p);
@@ -521,11 +559,6 @@ static struct file_system_type erofs_fs_type = {
521}; 559};
522MODULE_ALIAS_FS("erofs"); 560MODULE_ALIAS_FS("erofs");
523 561
524#ifdef CONFIG_EROFS_FS_ZIP
525extern int z_erofs_init_zip_subsystem(void);
526extern void z_erofs_exit_zip_subsystem(void);
527#endif
528
529static int __init erofs_module_init(void) 562static int __init erofs_module_init(void)
530{ 563{
531 int err; 564 int err;
@@ -541,11 +574,9 @@ static int __init erofs_module_init(void)
541 if (err) 574 if (err)
542 goto shrinker_err; 575 goto shrinker_err;
543 576
544#ifdef CONFIG_EROFS_FS_ZIP
545 err = z_erofs_init_zip_subsystem(); 577 err = z_erofs_init_zip_subsystem();
546 if (err) 578 if (err)
547 goto zip_err; 579 goto zip_err;
548#endif
549 580
550 err = register_filesystem(&erofs_fs_type); 581 err = register_filesystem(&erofs_fs_type);
551 if (err) 582 if (err)
@@ -555,10 +586,8 @@ static int __init erofs_module_init(void)
555 return 0; 586 return 0;
556 587
557fs_err: 588fs_err:
558#ifdef CONFIG_EROFS_FS_ZIP
559 z_erofs_exit_zip_subsystem(); 589 z_erofs_exit_zip_subsystem();
560zip_err: 590zip_err:
561#endif
562 unregister_shrinker(&erofs_shrinker_info); 591 unregister_shrinker(&erofs_shrinker_info);
563shrinker_err: 592shrinker_err:
564 erofs_exit_inode_cache(); 593 erofs_exit_inode_cache();
@@ -569,9 +598,7 @@ icache_err:
569static void __exit erofs_module_exit(void) 598static void __exit erofs_module_exit(void)
570{ 599{
571 unregister_filesystem(&erofs_fs_type); 600 unregister_filesystem(&erofs_fs_type);
572#ifdef CONFIG_EROFS_FS_ZIP
573 z_erofs_exit_zip_subsystem(); 601 z_erofs_exit_zip_subsystem();
574#endif
575 unregister_shrinker(&erofs_shrinker_info); 602 unregister_shrinker(&erofs_shrinker_info);
576 erofs_exit_inode_cache(); 603 erofs_exit_inode_cache();
577 infoln("successfully finalize erofs"); 604 infoln("successfully finalize erofs");
@@ -615,20 +642,31 @@ static int erofs_show_options(struct seq_file *seq, struct dentry *root)
615 else 642 else
616 seq_puts(seq, ",noacl"); 643 seq_puts(seq, ",noacl");
617#endif 644#endif
618#ifdef CONFIG_EROFS_FAULT_INJECTION
619 if (test_opt(sbi, FAULT_INJECTION)) 645 if (test_opt(sbi, FAULT_INJECTION))
620 seq_printf(seq, ",fault_injection=%u", 646 seq_printf(seq, ",fault_injection=%u",
621 sbi->fault_info.inject_rate); 647 erofs_get_fault_rate(sbi));
622#endif
623 return 0; 648 return 0;
624} 649}
625 650
626static int erofs_remount(struct super_block *sb, int *flags, char *data) 651static int erofs_remount(struct super_block *sb, int *flags, char *data)
627{ 652{
653 struct erofs_sb_info *sbi = EROFS_SB(sb);
654 unsigned int org_mnt_opt = sbi->mount_opt;
655 unsigned int org_inject_rate = erofs_get_fault_rate(sbi);
656 int err;
657
628 BUG_ON(!sb_rdonly(sb)); 658 BUG_ON(!sb_rdonly(sb));
659 err = parse_options(sb, data);
660 if (err)
661 goto out;
629 662
630 *flags |= SB_RDONLY; 663 *flags |= SB_RDONLY;
631 return 0; 664 return 0;
665out:
666 __erofs_build_fault_attr(sbi, org_inject_rate);
667 sbi->mount_opt = org_mnt_opt;
668
669 return err;
632} 670}
633 671
634const struct super_operations erofs_sops = { 672const struct super_operations erofs_sops = {
diff --git a/drivers/staging/erofs/unzip_vle.c b/drivers/staging/erofs/unzip_vle.c
index 8721f0a41d15..79d3ba62b298 100644
--- a/drivers/staging/erofs/unzip_vle.c
+++ b/drivers/staging/erofs/unzip_vle.c
@@ -13,6 +13,8 @@
13#include "unzip_vle.h" 13#include "unzip_vle.h"
14#include <linux/prefetch.h> 14#include <linux/prefetch.h>
15 15
16#include <trace/events/erofs.h>
17
16static struct workqueue_struct *z_erofs_workqueue __read_mostly; 18static struct workqueue_struct *z_erofs_workqueue __read_mostly;
17static struct kmem_cache *z_erofs_workgroup_cachep __read_mostly; 19static struct kmem_cache *z_erofs_workgroup_cachep __read_mostly;
18 20
@@ -27,7 +29,7 @@ void z_erofs_exit_zip_subsystem(void)
27 29
28static inline int init_unzip_workqueue(void) 30static inline int init_unzip_workqueue(void)
29{ 31{
30 const unsigned onlinecpus = num_possible_cpus(); 32 const unsigned int onlinecpus = num_possible_cpus();
31 33
32 /* 34 /*
33 * we don't need too many threads, limiting threads 35 * we don't need too many threads, limiting threads
@@ -40,7 +42,7 @@ static inline int init_unzip_workqueue(void)
40 return z_erofs_workqueue != NULL ? 0 : -ENOMEM; 42 return z_erofs_workqueue != NULL ? 0 : -ENOMEM;
41} 43}
42 44
43int z_erofs_init_zip_subsystem(void) 45int __init z_erofs_init_zip_subsystem(void)
44{ 46{
45 z_erofs_workgroup_cachep = 47 z_erofs_workgroup_cachep =
46 kmem_cache_create("erofs_compress", 48 kmem_cache_create("erofs_compress",
@@ -89,7 +91,7 @@ struct z_erofs_vle_work_builder {
89 91
90 /* pages used for reading the compressed data */ 92 /* pages used for reading the compressed data */
91 struct page **compressed_pages; 93 struct page **compressed_pages;
92 unsigned compressed_deficit; 94 unsigned int compressed_deficit;
93}; 95};
94 96
95#define VLE_WORK_BUILDER_INIT() \ 97#define VLE_WORK_BUILDER_INIT() \
@@ -232,7 +234,7 @@ static int z_erofs_vle_work_add_page(
232 234
233 ret = z_erofs_pagevec_ctor_enqueue(&builder->vector, 235 ret = z_erofs_pagevec_ctor_enqueue(&builder->vector,
234 page, type, &occupied); 236 page, type, &occupied);
235 builder->work->vcnt += (unsigned)ret; 237 builder->work->vcnt += (unsigned int)ret;
236 238
237 return ret ? 0 : -EAGAIN; 239 return ret ? 0 : -EAGAIN;
238} 240}
@@ -271,36 +273,39 @@ retry:
271 return true; /* lucky, I am the followee :) */ 273 return true; /* lucky, I am the followee :) */
272} 274}
273 275
276struct z_erofs_vle_work_finder {
277 struct super_block *sb;
278 pgoff_t idx;
279 unsigned int pageofs;
280
281 struct z_erofs_vle_workgroup **grp_ret;
282 enum z_erofs_vle_work_role *role;
283 z_erofs_vle_owned_workgrp_t *owned_head;
284 bool *hosted;
285};
286
274static struct z_erofs_vle_work * 287static struct z_erofs_vle_work *
275z_erofs_vle_work_lookup(struct super_block *sb, 288z_erofs_vle_work_lookup(const struct z_erofs_vle_work_finder *f)
276 pgoff_t idx, unsigned pageofs,
277 struct z_erofs_vle_workgroup **grp_ret,
278 enum z_erofs_vle_work_role *role,
279 z_erofs_vle_owned_workgrp_t *owned_head,
280 bool *hosted)
281{ 289{
282 bool tag, primary; 290 bool tag, primary;
283 struct erofs_workgroup *egrp; 291 struct erofs_workgroup *egrp;
284 struct z_erofs_vle_workgroup *grp; 292 struct z_erofs_vle_workgroup *grp;
285 struct z_erofs_vle_work *work; 293 struct z_erofs_vle_work *work;
286 294
287 egrp = erofs_find_workgroup(sb, idx, &tag); 295 egrp = erofs_find_workgroup(f->sb, f->idx, &tag);
288 if (egrp == NULL) { 296 if (egrp == NULL) {
289 *grp_ret = NULL; 297 *f->grp_ret = NULL;
290 return NULL; 298 return NULL;
291 } 299 }
292 300
293 *grp_ret = grp = container_of(egrp, 301 grp = container_of(egrp, struct z_erofs_vle_workgroup, obj);
294 struct z_erofs_vle_workgroup, obj); 302 *f->grp_ret = grp;
295 303
296#ifndef CONFIG_EROFS_FS_ZIP_MULTIREF 304 work = z_erofs_vle_grab_work(grp, f->pageofs);
297 work = z_erofs_vle_grab_work(grp, pageofs); 305 /* if multiref is disabled, `primary' is always true */
298 primary = true; 306 primary = true;
299#else
300 BUG();
301#endif
302 307
303 DBG_BUGON(work->pageofs != pageofs); 308 DBG_BUGON(work->pageofs != f->pageofs);
304 309
305 /* 310 /*
306 * lock must be taken first to avoid grp->next == NIL between 311 * lock must be taken first to avoid grp->next == NIL between
@@ -340,43 +345,35 @@ z_erofs_vle_work_lookup(struct super_block *sb,
340 */ 345 */
341 mutex_lock(&work->lock); 346 mutex_lock(&work->lock);
342 347
343 *hosted = false; 348 *f->hosted = false;
344 if (!primary) 349 if (!primary)
345 *role = Z_EROFS_VLE_WORK_SECONDARY; 350 *f->role = Z_EROFS_VLE_WORK_SECONDARY;
346 /* claim the workgroup if possible */ 351 /* claim the workgroup if possible */
347 else if (try_to_claim_workgroup(grp, owned_head, hosted)) 352 else if (try_to_claim_workgroup(grp, f->owned_head, f->hosted))
348 *role = Z_EROFS_VLE_WORK_PRIMARY_FOLLOWED; 353 *f->role = Z_EROFS_VLE_WORK_PRIMARY_FOLLOWED;
349 else 354 else
350 *role = Z_EROFS_VLE_WORK_PRIMARY; 355 *f->role = Z_EROFS_VLE_WORK_PRIMARY;
351 356
352 return work; 357 return work;
353} 358}
354 359
355static struct z_erofs_vle_work * 360static struct z_erofs_vle_work *
356z_erofs_vle_work_register(struct super_block *sb, 361z_erofs_vle_work_register(const struct z_erofs_vle_work_finder *f,
357 struct z_erofs_vle_workgroup **grp_ret, 362 struct erofs_map_blocks *map)
358 struct erofs_map_blocks *map,
359 pgoff_t index, unsigned pageofs,
360 enum z_erofs_vle_work_role *role,
361 z_erofs_vle_owned_workgrp_t *owned_head,
362 bool *hosted)
363{ 363{
364 bool newgrp = false; 364 bool gnew = false;
365 struct z_erofs_vle_workgroup *grp = *grp_ret; 365 struct z_erofs_vle_workgroup *grp = *f->grp_ret;
366 struct z_erofs_vle_work *work; 366 struct z_erofs_vle_work *work;
367 367
368#ifndef CONFIG_EROFS_FS_ZIP_MULTIREF 368 /* if multiref is disabled, grp should never be nullptr */
369 BUG_ON(grp != NULL); 369 BUG_ON(grp != NULL);
370#else 370
371 if (grp != NULL)
372 goto skip;
373#endif
374 /* no available workgroup, let's allocate one */ 371 /* no available workgroup, let's allocate one */
375 grp = kmem_cache_zalloc(z_erofs_workgroup_cachep, GFP_NOFS); 372 grp = kmem_cache_zalloc(z_erofs_workgroup_cachep, GFP_NOFS);
376 if (unlikely(grp == NULL)) 373 if (unlikely(grp == NULL))
377 return ERR_PTR(-ENOMEM); 374 return ERR_PTR(-ENOMEM);
378 375
379 grp->obj.index = index; 376 grp->obj.index = f->idx;
380 grp->llen = map->m_llen; 377 grp->llen = map->m_llen;
381 378
382 z_erofs_vle_set_workgrp_fmt(grp, 379 z_erofs_vle_set_workgrp_fmt(grp,
@@ -386,26 +383,20 @@ z_erofs_vle_work_register(struct super_block *sb,
386 atomic_set(&grp->obj.refcount, 1); 383 atomic_set(&grp->obj.refcount, 1);
387 384
388 /* new workgrps have been claimed as type 1 */ 385 /* new workgrps have been claimed as type 1 */
389 WRITE_ONCE(grp->next, *owned_head); 386 WRITE_ONCE(grp->next, *f->owned_head);
390 /* primary and followed work for all new workgrps */ 387 /* primary and followed work for all new workgrps */
391 *role = Z_EROFS_VLE_WORK_PRIMARY_FOLLOWED; 388 *f->role = Z_EROFS_VLE_WORK_PRIMARY_FOLLOWED;
392 /* it should be submitted by ourselves */ 389 /* it should be submitted by ourselves */
393 *hosted = true; 390 *f->hosted = true;
394 391
395 newgrp = true; 392 gnew = true;
396#ifdef CONFIG_EROFS_FS_ZIP_MULTIREF
397skip:
398 /* currently unimplemented */
399 BUG();
400#else
401 work = z_erofs_vle_grab_primary_work(grp); 393 work = z_erofs_vle_grab_primary_work(grp);
402#endif 394 work->pageofs = f->pageofs;
403 work->pageofs = pageofs;
404 395
405 mutex_init(&work->lock); 396 mutex_init(&work->lock);
406 397
407 if (newgrp) { 398 if (gnew) {
408 int err = erofs_register_workgroup(sb, &grp->obj, 0); 399 int err = erofs_register_workgroup(f->sb, &grp->obj, 0);
409 400
410 if (err) { 401 if (err) {
411 kmem_cache_free(z_erofs_workgroup_cachep, grp); 402 kmem_cache_free(z_erofs_workgroup_cachep, grp);
@@ -413,24 +404,12 @@ skip:
413 } 404 }
414 } 405 }
415 406
416 *owned_head = *grp_ret = grp; 407 *f->owned_head = *f->grp_ret = grp;
417 408
418 mutex_lock(&work->lock); 409 mutex_lock(&work->lock);
419 return work; 410 return work;
420} 411}
421 412
422static inline void __update_workgrp_llen(struct z_erofs_vle_workgroup *grp,
423 unsigned int llen)
424{
425 while (1) {
426 unsigned int orig_llen = grp->llen;
427
428 if (orig_llen >= llen || orig_llen ==
429 cmpxchg(&grp->llen, orig_llen, llen))
430 break;
431 }
432}
433
434#define builder_is_followed(builder) \ 413#define builder_is_followed(builder) \
435 ((builder)->role >= Z_EROFS_VLE_WORK_PRIMARY_FOLLOWED) 414 ((builder)->role >= Z_EROFS_VLE_WORK_PRIMARY_FOLLOWED)
436 415
@@ -439,10 +418,17 @@ static int z_erofs_vle_work_iter_begin(struct z_erofs_vle_work_builder *builder,
439 struct erofs_map_blocks *map, 418 struct erofs_map_blocks *map,
440 z_erofs_vle_owned_workgrp_t *owned_head) 419 z_erofs_vle_owned_workgrp_t *owned_head)
441{ 420{
442 const unsigned clusterpages = erofs_clusterpages(EROFS_SB(sb)); 421 const unsigned int clusterpages = erofs_clusterpages(EROFS_SB(sb));
443 const erofs_blk_t index = erofs_blknr(map->m_pa);
444 const unsigned pageofs = map->m_la & ~PAGE_MASK;
445 struct z_erofs_vle_workgroup *grp; 422 struct z_erofs_vle_workgroup *grp;
423 const struct z_erofs_vle_work_finder finder = {
424 .sb = sb,
425 .idx = erofs_blknr(map->m_pa),
426 .pageofs = map->m_la & ~PAGE_MASK,
427 .grp_ret = &grp,
428 .role = &builder->role,
429 .owned_head = owned_head,
430 .hosted = &builder->hosted
431 };
446 struct z_erofs_vle_work *work; 432 struct z_erofs_vle_work *work;
447 433
448 DBG_BUGON(builder->work != NULL); 434 DBG_BUGON(builder->work != NULL);
@@ -454,16 +440,19 @@ static int z_erofs_vle_work_iter_begin(struct z_erofs_vle_work_builder *builder,
454 DBG_BUGON(erofs_blkoff(map->m_pa)); 440 DBG_BUGON(erofs_blkoff(map->m_pa));
455 441
456repeat: 442repeat:
457 work = z_erofs_vle_work_lookup(sb, index, 443 work = z_erofs_vle_work_lookup(&finder);
458 pageofs, &grp, &builder->role, owned_head, &builder->hosted);
459 if (work != NULL) { 444 if (work != NULL) {
460 __update_workgrp_llen(grp, map->m_llen); 445 unsigned int orig_llen;
446
447 /* increase workgroup `llen' if needed */
448 while ((orig_llen = READ_ONCE(grp->llen)) < map->m_llen &&
449 orig_llen != cmpxchg_relaxed(&grp->llen,
450 orig_llen, map->m_llen))
451 cpu_relax();
461 goto got_it; 452 goto got_it;
462 } 453 }
463 454
464 work = z_erofs_vle_work_register(sb, &grp, map, index, pageofs, 455 work = z_erofs_vle_work_register(&finder, map);
465 &builder->role, owned_head, &builder->hosted);
466
467 if (unlikely(work == ERR_PTR(-EAGAIN))) 456 if (unlikely(work == ERR_PTR(-EAGAIN)))
468 goto repeat; 457 goto repeat;
469 458
@@ -605,8 +594,10 @@ static int z_erofs_do_read_page(struct z_erofs_vle_frontend *fe,
605#endif 594#endif
606 595
607 enum z_erofs_page_type page_type; 596 enum z_erofs_page_type page_type;
608 unsigned cur, end, spiltted, index; 597 unsigned int cur, end, spiltted, index;
609 int err; 598 int err = 0;
599
600 trace_erofs_readpage(page, false);
610 601
611 /* register locked file pages as online pages in pack */ 602 /* register locked file pages as online pages in pack */
612 z_erofs_onlinepage_init(page); 603 z_erofs_onlinepage_init(page);
@@ -624,7 +615,7 @@ repeat:
624 /* go ahead the next map_blocks */ 615 /* go ahead the next map_blocks */
625 debugln("%s: [out-of-range] pos %llu", __func__, offset + cur); 616 debugln("%s: [out-of-range] pos %llu", __func__, offset + cur);
626 617
627 if (!z_erofs_vle_work_iter_end(builder)) 618 if (z_erofs_vle_work_iter_end(builder))
628 fe->initial = false; 619 fe->initial = false;
629 620
630 map->m_la = offset + cur; 621 map->m_la = offset + cur;
@@ -633,12 +624,11 @@ repeat:
633 if (unlikely(err)) 624 if (unlikely(err))
634 goto err_out; 625 goto err_out;
635 626
636 /* deal with hole (FIXME! broken now) */
637 if (unlikely(!(map->m_flags & EROFS_MAP_MAPPED))) 627 if (unlikely(!(map->m_flags & EROFS_MAP_MAPPED)))
638 goto hitted; 628 goto hitted;
639 629
640 DBG_BUGON(map->m_plen != 1 << sbi->clusterbits); 630 DBG_BUGON(map->m_plen != 1 << sbi->clusterbits);
641 BUG_ON(erofs_blkoff(map->m_pa)); 631 DBG_BUGON(erofs_blkoff(map->m_pa));
642 632
643 err = z_erofs_vle_work_iter_begin(builder, sb, map, &fe->owned_head); 633 err = z_erofs_vle_work_iter_begin(builder, sb, map, &fe->owned_head);
644 if (unlikely(err)) 634 if (unlikely(err))
@@ -662,7 +652,7 @@ repeat:
662 tight &= builder_is_followed(builder); 652 tight &= builder_is_followed(builder);
663 work = builder->work; 653 work = builder->work;
664hitted: 654hitted:
665 cur = end - min_t(unsigned, offset + end - map->m_la, end); 655 cur = end - min_t(unsigned int, offset + end - map->m_la, end);
666 if (unlikely(!(map->m_flags & EROFS_MAP_MAPPED))) { 656 if (unlikely(!(map->m_flags & EROFS_MAP_MAPPED))) {
667 zero_user_segment(page, cur, end); 657 zero_user_segment(page, cur, end);
668 goto next_part; 658 goto next_part;
@@ -683,7 +673,7 @@ retry:
683 673
684 err = z_erofs_vle_work_add_page(builder, 674 err = z_erofs_vle_work_add_page(builder,
685 newpage, Z_EROFS_PAGE_TYPE_EXCLUSIVE); 675 newpage, Z_EROFS_PAGE_TYPE_EXCLUSIVE);
686 if (!err) 676 if (likely(!err))
687 goto retry; 677 goto retry;
688 } 678 }
689 679
@@ -694,9 +684,10 @@ retry:
694 684
695 /* FIXME! avoid the last relundant fixup & endio */ 685 /* FIXME! avoid the last relundant fixup & endio */
696 z_erofs_onlinepage_fixup(page, index, true); 686 z_erofs_onlinepage_fixup(page, index, true);
697 ++spiltted;
698 687
699 /* also update nr_pages and increase queued_pages */ 688 /* bump up the number of spiltted parts of a page */
689 ++spiltted;
690 /* also update nr_pages */
700 work->nr_pages = max_t(pgoff_t, work->nr_pages, index + 1); 691 work->nr_pages = max_t(pgoff_t, work->nr_pages, index + 1);
701next_part: 692next_part:
702 /* can be used for verification */ 693 /* can be used for verification */
@@ -706,16 +697,18 @@ next_part:
706 if (end > 0) 697 if (end > 0)
707 goto repeat; 698 goto repeat;
708 699
700out:
709 /* FIXME! avoid the last relundant fixup & endio */ 701 /* FIXME! avoid the last relundant fixup & endio */
710 z_erofs_onlinepage_endio(page); 702 z_erofs_onlinepage_endio(page);
711 703
712 debugln("%s, finish page: %pK spiltted: %u map->m_llen %llu", 704 debugln("%s, finish page: %pK spiltted: %u map->m_llen %llu",
713 __func__, page, spiltted, map->m_llen); 705 __func__, page, spiltted, map->m_llen);
714 return 0; 706 return err;
715 707
708 /* if some error occurred while processing this page */
716err_out: 709err_out:
717 /* TODO: the missing error handing cases */ 710 SetPageError(page);
718 return err; 711 goto out;
719} 712}
720 713
721static void z_erofs_vle_unzip_kickoff(void *ptr, int bios) 714static void z_erofs_vle_unzip_kickoff(void *ptr, int bios)
@@ -736,7 +729,7 @@ static void z_erofs_vle_unzip_kickoff(void *ptr, int bios)
736static inline void z_erofs_vle_read_endio(struct bio *bio) 729static inline void z_erofs_vle_read_endio(struct bio *bio)
737{ 730{
738 const blk_status_t err = bio->bi_status; 731 const blk_status_t err = bio->bi_status;
739 unsigned i; 732 unsigned int i;
740 struct bio_vec *bvec; 733 struct bio_vec *bvec;
741#ifdef EROFS_FS_HAS_MANAGED_CACHE 734#ifdef EROFS_FS_HAS_MANAGED_CACHE
742 struct address_space *mngda = NULL; 735 struct address_space *mngda = NULL;
@@ -788,16 +781,14 @@ static int z_erofs_vle_unzip(struct super_block *sb,
788#ifdef EROFS_FS_HAS_MANAGED_CACHE 781#ifdef EROFS_FS_HAS_MANAGED_CACHE
789 struct address_space *const mngda = sbi->managed_cache->i_mapping; 782 struct address_space *const mngda = sbi->managed_cache->i_mapping;
790#endif 783#endif
791 const unsigned clusterpages = erofs_clusterpages(sbi); 784 const unsigned int clusterpages = erofs_clusterpages(sbi);
792 785
793 struct z_erofs_pagevec_ctor ctor; 786 struct z_erofs_pagevec_ctor ctor;
794 unsigned nr_pages; 787 unsigned int nr_pages;
795#ifndef CONFIG_EROFS_FS_ZIP_MULTIREF 788 unsigned int sparsemem_pages = 0;
796 unsigned sparsemem_pages = 0;
797#endif
798 struct page *pages_onstack[Z_EROFS_VLE_VMAP_ONSTACK_PAGES]; 789 struct page *pages_onstack[Z_EROFS_VLE_VMAP_ONSTACK_PAGES];
799 struct page **pages, **compressed_pages, *page; 790 struct page **pages, **compressed_pages, *page;
800 unsigned i, llen; 791 unsigned int i, llen;
801 792
802 enum z_erofs_page_type page_type; 793 enum z_erofs_page_type page_type;
803 bool overlapped; 794 bool overlapped;
@@ -806,11 +797,7 @@ static int z_erofs_vle_unzip(struct super_block *sb,
806 int err; 797 int err;
807 798
808 might_sleep(); 799 might_sleep();
809#ifndef CONFIG_EROFS_FS_ZIP_MULTIREF
810 work = z_erofs_vle_grab_primary_work(grp); 800 work = z_erofs_vle_grab_primary_work(grp);
811#else
812 BUG();
813#endif
814 BUG_ON(!READ_ONCE(work->nr_pages)); 801 BUG_ON(!READ_ONCE(work->nr_pages));
815 802
816 mutex_lock(&work->lock); 803 mutex_lock(&work->lock);
@@ -844,7 +831,7 @@ repeat:
844 Z_EROFS_VLE_INLINE_PAGEVECS, work->pagevec, 0); 831 Z_EROFS_VLE_INLINE_PAGEVECS, work->pagevec, 0);
845 832
846 for (i = 0; i < work->vcnt; ++i) { 833 for (i = 0; i < work->vcnt; ++i) {
847 unsigned pagenr; 834 unsigned int pagenr;
848 835
849 page = z_erofs_pagevec_ctor_dequeue(&ctor, &page_type); 836 page = z_erofs_pagevec_ctor_dequeue(&ctor, &page_type);
850 837
@@ -861,13 +848,11 @@ repeat:
861 pagenr = z_erofs_onlinepage_index(page); 848 pagenr = z_erofs_onlinepage_index(page);
862 849
863 BUG_ON(pagenr >= nr_pages); 850 BUG_ON(pagenr >= nr_pages);
864
865#ifndef CONFIG_EROFS_FS_ZIP_MULTIREF
866 BUG_ON(pages[pagenr] != NULL); 851 BUG_ON(pages[pagenr] != NULL);
867 ++sparsemem_pages; 852
868#endif
869 pages[pagenr] = page; 853 pages[pagenr] = page;
870 } 854 }
855 sparsemem_pages = i;
871 856
872 z_erofs_pagevec_ctor_exit(&ctor, true); 857 z_erofs_pagevec_ctor_exit(&ctor, true);
873 858
@@ -875,7 +860,7 @@ repeat:
875 compressed_pages = grp->compressed_pages; 860 compressed_pages = grp->compressed_pages;
876 861
877 for (i = 0; i < clusterpages; ++i) { 862 for (i = 0; i < clusterpages; ++i) {
878 unsigned pagenr; 863 unsigned int pagenr;
879 864
880 page = compressed_pages[i]; 865 page = compressed_pages[i];
881 866
@@ -897,10 +882,8 @@ repeat:
897 pagenr = z_erofs_onlinepage_index(page); 882 pagenr = z_erofs_onlinepage_index(page);
898 883
899 BUG_ON(pagenr >= nr_pages); 884 BUG_ON(pagenr >= nr_pages);
900#ifndef CONFIG_EROFS_FS_ZIP_MULTIREF
901 BUG_ON(pages[pagenr] != NULL); 885 BUG_ON(pages[pagenr] != NULL);
902 ++sparsemem_pages; 886 ++sparsemem_pages;
903#endif
904 pages[pagenr] = page; 887 pages[pagenr] = page;
905 888
906 overlapped = true; 889 overlapped = true;
@@ -926,12 +909,10 @@ repeat:
926 if (err != -ENOTSUPP) 909 if (err != -ENOTSUPP)
927 goto out_percpu; 910 goto out_percpu;
928 911
929#ifndef CONFIG_EROFS_FS_ZIP_MULTIREF
930 if (sparsemem_pages >= nr_pages) { 912 if (sparsemem_pages >= nr_pages) {
931 BUG_ON(sparsemem_pages > nr_pages); 913 BUG_ON(sparsemem_pages > nr_pages);
932 goto skip_allocpage; 914 goto skip_allocpage;
933 } 915 }
934#endif
935 916
936 for (i = 0; i < nr_pages; ++i) { 917 for (i = 0; i < nr_pages; ++i) {
937 if (pages[i] != NULL) 918 if (pages[i] != NULL)
@@ -940,9 +921,7 @@ repeat:
940 pages[i] = __stagingpage_alloc(page_pool, GFP_NOFS); 921 pages[i] = __stagingpage_alloc(page_pool, GFP_NOFS);
941 } 922 }
942 923
943#ifndef CONFIG_EROFS_FS_ZIP_MULTIREF
944skip_allocpage: 924skip_allocpage:
945#endif
946 vout = erofs_vmap(pages, nr_pages); 925 vout = erofs_vmap(pages, nr_pages);
947 926
948 err = z_erofs_vle_unzip_vmap(compressed_pages, 927 err = z_erofs_vle_unzip_vmap(compressed_pages,
@@ -1100,7 +1079,7 @@ static bool z_erofs_vle_submit_all(struct super_block *sb,
1100 bool force_fg) 1079 bool force_fg)
1101{ 1080{
1102 struct erofs_sb_info *const sbi = EROFS_SB(sb); 1081 struct erofs_sb_info *const sbi = EROFS_SB(sb);
1103 const unsigned clusterpages = erofs_clusterpages(sbi); 1082 const unsigned int clusterpages = erofs_clusterpages(sbi);
1104 const gfp_t gfp = GFP_NOFS; 1083 const gfp_t gfp = GFP_NOFS;
1105#ifdef EROFS_FS_HAS_MANAGED_CACHE 1084#ifdef EROFS_FS_HAS_MANAGED_CACHE
1106 struct address_space *const mngda = sbi->managed_cache->i_mapping; 1085 struct address_space *const mngda = sbi->managed_cache->i_mapping;
@@ -1112,7 +1091,7 @@ static bool z_erofs_vle_submit_all(struct super_block *sb,
1112 /* since bio will be NULL, no need to initialize last_index */ 1091 /* since bio will be NULL, no need to initialize last_index */
1113 pgoff_t uninitialized_var(last_index); 1092 pgoff_t uninitialized_var(last_index);
1114 bool force_submit = false; 1093 bool force_submit = false;
1115 unsigned nr_bios; 1094 unsigned int nr_bios;
1116 1095
1117 if (unlikely(owned_head == Z_EROFS_VLE_WORKGRP_TAIL)) 1096 if (unlikely(owned_head == Z_EROFS_VLE_WORKGRP_TAIL))
1118 return false; 1097 return false;
@@ -1144,7 +1123,7 @@ static bool z_erofs_vle_submit_all(struct super_block *sb,
1144 struct z_erofs_vle_workgroup *grp; 1123 struct z_erofs_vle_workgroup *grp;
1145 struct page **compressed_pages, *oldpage, *page; 1124 struct page **compressed_pages, *oldpage, *page;
1146 pgoff_t first_index; 1125 pgoff_t first_index;
1147 unsigned i = 0; 1126 unsigned int i = 0;
1148#ifdef EROFS_FS_HAS_MANAGED_CACHE 1127#ifdef EROFS_FS_HAS_MANAGED_CACHE
1149 unsigned int noio = 0; 1128 unsigned int noio = 0;
1150 bool cachemngd; 1129 bool cachemngd;
@@ -1213,8 +1192,8 @@ submit_bio_retry:
1213 } 1192 }
1214 1193
1215 if (bio == NULL) { 1194 if (bio == NULL) {
1216 bio = prepare_bio(sb, first_index + i, 1195 bio = erofs_grab_bio(sb, first_index + i,
1217 BIO_MAX_PAGES, z_erofs_vle_read_endio); 1196 BIO_MAX_PAGES, z_erofs_vle_read_endio, true);
1218 bio->bi_private = tagptr_cast_ptr(bi_private); 1197 bio->bi_private = tagptr_cast_ptr(bi_private);
1219 1198
1220 ++nr_bios; 1199 ++nr_bios;
@@ -1309,7 +1288,7 @@ static int z_erofs_vle_normalaccess_readpage(struct file *file,
1309 LIST_HEAD(pagepool); 1288 LIST_HEAD(pagepool);
1310 1289
1311#if (EROFS_FS_ZIP_CACHE_LVL >= 2) 1290#if (EROFS_FS_ZIP_CACHE_LVL >= 2)
1312 f.cachedzone_la = page->index << PAGE_SHIFT; 1291 f.cachedzone_la = (erofs_off_t)page->index << PAGE_SHIFT;
1313#endif 1292#endif
1314 err = z_erofs_do_read_page(&f, page, &pagepool); 1293 err = z_erofs_do_read_page(&f, page, &pagepool);
1315 (void)z_erofs_vle_work_iter_end(&f.builder); 1294 (void)z_erofs_vle_work_iter_end(&f.builder);
@@ -1329,20 +1308,25 @@ out:
1329 return 0; 1308 return 0;
1330} 1309}
1331 1310
1332static inline int __z_erofs_vle_normalaccess_readpages( 1311static int z_erofs_vle_normalaccess_readpages(struct file *filp,
1333 struct file *filp, 1312 struct address_space *mapping,
1334 struct address_space *mapping, 1313 struct list_head *pages,
1335 struct list_head *pages, unsigned nr_pages, bool sync) 1314 unsigned int nr_pages)
1336{ 1315{
1337 struct inode *const inode = mapping->host; 1316 struct inode *const inode = mapping->host;
1317 struct erofs_sb_info *const sbi = EROFS_I_SB(inode);
1318 const bool sync = __should_decompress_synchronously(sbi, nr_pages);
1338 1319
1339 struct z_erofs_vle_frontend f = VLE_FRONTEND_INIT(inode); 1320 struct z_erofs_vle_frontend f = VLE_FRONTEND_INIT(inode);
1340 gfp_t gfp = mapping_gfp_constraint(mapping, GFP_KERNEL); 1321 gfp_t gfp = mapping_gfp_constraint(mapping, GFP_KERNEL);
1341 struct page *head = NULL; 1322 struct page *head = NULL;
1342 LIST_HEAD(pagepool); 1323 LIST_HEAD(pagepool);
1343 1324
1325 trace_erofs_readpages(mapping->host, lru_to_page(pages),
1326 nr_pages, false);
1327
1344#if (EROFS_FS_ZIP_CACHE_LVL >= 2) 1328#if (EROFS_FS_ZIP_CACHE_LVL >= 2)
1345 f.cachedzone_la = lru_to_page(pages)->index << PAGE_SHIFT; 1329 f.cachedzone_la = (erofs_off_t)lru_to_page(pages)->index << PAGE_SHIFT;
1346#endif 1330#endif
1347 for (; nr_pages; --nr_pages) { 1331 for (; nr_pages; --nr_pages) {
1348 struct page *page = lru_to_page(pages); 1332 struct page *page = lru_to_page(pages);
@@ -1390,56 +1374,45 @@ static inline int __z_erofs_vle_normalaccess_readpages(
1390 return 0; 1374 return 0;
1391} 1375}
1392 1376
1393static int z_erofs_vle_normalaccess_readpages(
1394 struct file *filp,
1395 struct address_space *mapping,
1396 struct list_head *pages, unsigned nr_pages)
1397{
1398 return __z_erofs_vle_normalaccess_readpages(filp,
1399 mapping, pages, nr_pages,
1400 nr_pages < 4 /* sync */);
1401}
1402
1403const struct address_space_operations z_erofs_vle_normalaccess_aops = { 1377const struct address_space_operations z_erofs_vle_normalaccess_aops = {
1404 .readpage = z_erofs_vle_normalaccess_readpage, 1378 .readpage = z_erofs_vle_normalaccess_readpage,
1405 .readpages = z_erofs_vle_normalaccess_readpages, 1379 .readpages = z_erofs_vle_normalaccess_readpages,
1406}; 1380};
1407 1381
1382/*
1383 * Variable-sized Logical Extent (Fixed Physical Cluster) Compression Mode
1384 * ---
1385 * VLE compression mode attempts to compress a number of logical data into
1386 * a physical cluster with a fixed size.
1387 * VLE compression mode uses "struct z_erofs_vle_decompressed_index".
1388 */
1408#define __vle_cluster_advise(x, bit, bits) \ 1389#define __vle_cluster_advise(x, bit, bits) \
1409 ((le16_to_cpu(x) >> (bit)) & ((1 << (bits)) - 1)) 1390 ((le16_to_cpu(x) >> (bit)) & ((1 << (bits)) - 1))
1410 1391
1411#define __vle_cluster_type(advise) __vle_cluster_advise(advise, \ 1392#define __vle_cluster_type(advise) __vle_cluster_advise(advise, \
1412 Z_EROFS_VLE_DI_CLUSTER_TYPE_BIT, Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS) 1393 Z_EROFS_VLE_DI_CLUSTER_TYPE_BIT, Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS)
1413 1394
1414enum {
1415 Z_EROFS_VLE_CLUSTER_TYPE_PLAIN,
1416 Z_EROFS_VLE_CLUSTER_TYPE_HEAD,
1417 Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD,
1418 Z_EROFS_VLE_CLUSTER_TYPE_RESERVED,
1419 Z_EROFS_VLE_CLUSTER_TYPE_MAX
1420};
1421
1422#define vle_cluster_type(di) \ 1395#define vle_cluster_type(di) \
1423 __vle_cluster_type((di)->di_advise) 1396 __vle_cluster_type((di)->di_advise)
1424 1397
1425static inline unsigned 1398static int
1426vle_compressed_index_clusterofs(unsigned clustersize, 1399vle_decompressed_index_clusterofs(unsigned int *clusterofs,
1427 struct z_erofs_vle_decompressed_index *di) 1400 unsigned int clustersize,
1401 struct z_erofs_vle_decompressed_index *di)
1428{ 1402{
1429 debugln("%s, vle=%pK, advise=%x (type %u), clusterofs=%x blkaddr=%x",
1430 __func__, di, di->di_advise, vle_cluster_type(di),
1431 di->di_clusterofs, di->di_u.blkaddr);
1432
1433 switch (vle_cluster_type(di)) { 1403 switch (vle_cluster_type(di)) {
1434 case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD: 1404 case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD:
1405 *clusterofs = clustersize;
1435 break; 1406 break;
1436 case Z_EROFS_VLE_CLUSTER_TYPE_PLAIN: 1407 case Z_EROFS_VLE_CLUSTER_TYPE_PLAIN:
1437 case Z_EROFS_VLE_CLUSTER_TYPE_HEAD: 1408 case Z_EROFS_VLE_CLUSTER_TYPE_HEAD:
1438 return di->di_clusterofs; 1409 *clusterofs = le16_to_cpu(di->di_clusterofs);
1410 break;
1439 default: 1411 default:
1440 BUG_ON(1); 1412 DBG_BUGON(1);
1413 return -EIO;
1441 } 1414 }
1442 return clustersize; 1415 return 0;
1443} 1416}
1444 1417
1445static inline erofs_blk_t 1418static inline erofs_blk_t
@@ -1448,7 +1421,7 @@ vle_extent_blkaddr(struct inode *inode, pgoff_t index)
1448 struct erofs_sb_info *sbi = EROFS_I_SB(inode); 1421 struct erofs_sb_info *sbi = EROFS_I_SB(inode);
1449 struct erofs_vnode *vi = EROFS_V(inode); 1422 struct erofs_vnode *vi = EROFS_V(inode);
1450 1423
1451 unsigned ofs = Z_EROFS_VLE_EXTENT_ALIGN(vi->inode_isize + 1424 unsigned int ofs = Z_EROFS_VLE_EXTENT_ALIGN(vi->inode_isize +
1452 vi->xattr_isize) + sizeof(struct erofs_extent_header) + 1425 vi->xattr_isize) + sizeof(struct erofs_extent_header) +
1453 index * sizeof(struct z_erofs_vle_decompressed_index); 1426 index * sizeof(struct z_erofs_vle_decompressed_index);
1454 1427
@@ -1461,95 +1434,117 @@ vle_extent_blkoff(struct inode *inode, pgoff_t index)
1461 struct erofs_sb_info *sbi = EROFS_I_SB(inode); 1434 struct erofs_sb_info *sbi = EROFS_I_SB(inode);
1462 struct erofs_vnode *vi = EROFS_V(inode); 1435 struct erofs_vnode *vi = EROFS_V(inode);
1463 1436
1464 unsigned ofs = Z_EROFS_VLE_EXTENT_ALIGN(vi->inode_isize + 1437 unsigned int ofs = Z_EROFS_VLE_EXTENT_ALIGN(vi->inode_isize +
1465 vi->xattr_isize) + sizeof(struct erofs_extent_header) + 1438 vi->xattr_isize) + sizeof(struct erofs_extent_header) +
1466 index * sizeof(struct z_erofs_vle_decompressed_index); 1439 index * sizeof(struct z_erofs_vle_decompressed_index);
1467 1440
1468 return erofs_blkoff(iloc(sbi, vi->nid) + ofs); 1441 return erofs_blkoff(iloc(sbi, vi->nid) + ofs);
1469} 1442}
1470 1443
1471/* 1444struct vle_map_blocks_iter_ctx {
1472 * Variable-sized Logical Extent (Fixed Physical Cluster) Compression Mode 1445 struct inode *inode;
1473 * --- 1446 struct super_block *sb;
1474 * VLE compression mode attempts to compress a number of logical data into 1447 unsigned int clusterbits;
1475 * a physical cluster with a fixed size. 1448
1476 * VLE compression mode uses "struct z_erofs_vle_decompressed_index". 1449 struct page **mpage_ret;
1477 */ 1450 void **kaddr_ret;
1478static erofs_off_t vle_get_logical_extent_head( 1451};
1479 struct inode *inode, 1452
1480 struct page **page_iter, 1453static int
1481 void **kaddr_iter, 1454vle_get_logical_extent_head(const struct vle_map_blocks_iter_ctx *ctx,
1482 unsigned lcn, /* logical cluster number */ 1455 unsigned int lcn, /* logical cluster number */
1483 erofs_blk_t *pcn, 1456 unsigned long long *ofs,
1484 unsigned *flags) 1457 erofs_blk_t *pblk,
1458 unsigned int *flags)
1485{ 1459{
1486 /* for extent meta */ 1460 const unsigned int clustersize = 1 << ctx->clusterbits;
1487 struct page *page = *page_iter; 1461 const erofs_blk_t mblk = vle_extent_blkaddr(ctx->inode, lcn);
1488 erofs_blk_t blkaddr = vle_extent_blkaddr(inode, lcn); 1462 struct page *mpage = *ctx->mpage_ret; /* extent metapage */
1463
1489 struct z_erofs_vle_decompressed_index *di; 1464 struct z_erofs_vle_decompressed_index *di;
1490 unsigned long long ofs; 1465 unsigned int cluster_type, delta0;
1491 const unsigned int clusterbits = EROFS_SB(inode->i_sb)->clusterbits;
1492 const unsigned int clustersize = 1 << clusterbits;
1493 1466
1494 if (page->index != blkaddr) { 1467 if (mpage->index != mblk) {
1495 kunmap_atomic(*kaddr_iter); 1468 kunmap_atomic(*ctx->kaddr_ret);
1496 unlock_page(page); 1469 unlock_page(mpage);
1497 put_page(page); 1470 put_page(mpage);
1498 1471
1499 *page_iter = page = erofs_get_meta_page(inode->i_sb, 1472 mpage = erofs_get_meta_page(ctx->sb, mblk, false);
1500 blkaddr, false); 1473 if (IS_ERR(mpage)) {
1501 *kaddr_iter = kmap_atomic(page); 1474 *ctx->mpage_ret = NULL;
1475 return PTR_ERR(mpage);
1476 }
1477 *ctx->mpage_ret = mpage;
1478 *ctx->kaddr_ret = kmap_atomic(mpage);
1502 } 1479 }
1503 1480
1504 di = *kaddr_iter + vle_extent_blkoff(inode, lcn); 1481 di = *ctx->kaddr_ret + vle_extent_blkoff(ctx->inode, lcn);
1505 switch (vle_cluster_type(di)) {
1506 case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD:
1507 BUG_ON(!di->di_u.delta[0]);
1508 BUG_ON(lcn < di->di_u.delta[0]);
1509 1482
1510 ofs = vle_get_logical_extent_head(inode, 1483 cluster_type = vle_cluster_type(di);
1511 page_iter, kaddr_iter, 1484 switch (cluster_type) {
1512 lcn - di->di_u.delta[0], pcn, flags); 1485 case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD:
1513 break; 1486 delta0 = le16_to_cpu(di->di_u.delta[0]);
1487 if (unlikely(!delta0 || delta0 > lcn)) {
1488 errln("invalid NONHEAD dl0 %u at lcn %u of nid %llu",
1489 delta0, lcn, EROFS_V(ctx->inode)->nid);
1490 DBG_BUGON(1);
1491 return -EIO;
1492 }
1493 return vle_get_logical_extent_head(ctx,
1494 lcn - delta0, ofs, pblk, flags);
1514 case Z_EROFS_VLE_CLUSTER_TYPE_PLAIN: 1495 case Z_EROFS_VLE_CLUSTER_TYPE_PLAIN:
1515 *flags ^= EROFS_MAP_ZIPPED; 1496 *flags ^= EROFS_MAP_ZIPPED;
1497 /* fallthrough */
1516 case Z_EROFS_VLE_CLUSTER_TYPE_HEAD: 1498 case Z_EROFS_VLE_CLUSTER_TYPE_HEAD:
1517 /* clustersize should be a power of two */ 1499 /* clustersize should be a power of two */
1518 ofs = ((unsigned long long)lcn << clusterbits) + 1500 *ofs = ((u64)lcn << ctx->clusterbits) +
1519 (le16_to_cpu(di->di_clusterofs) & (clustersize - 1)); 1501 (le16_to_cpu(di->di_clusterofs) & (clustersize - 1));
1520 *pcn = le32_to_cpu(di->di_u.blkaddr); 1502 *pblk = le32_to_cpu(di->di_u.blkaddr);
1521 break; 1503 break;
1522 default: 1504 default:
1523 BUG_ON(1); 1505 errln("unknown cluster type %u at lcn %u of nid %llu",
1506 cluster_type, lcn, EROFS_V(ctx->inode)->nid);
1507 DBG_BUGON(1);
1508 return -EIO;
1524 } 1509 }
1525 return ofs; 1510 return 0;
1526} 1511}
1527 1512
1528int z_erofs_map_blocks_iter(struct inode *inode, 1513int z_erofs_map_blocks_iter(struct inode *inode,
1529 struct erofs_map_blocks *map, 1514 struct erofs_map_blocks *map,
1530 struct page **mpage_ret, int flags) 1515 struct page **mpage_ret, int flags)
1531{ 1516{
1517 void *kaddr;
1518 const struct vle_map_blocks_iter_ctx ctx = {
1519 .inode = inode,
1520 .sb = inode->i_sb,
1521 .clusterbits = EROFS_I_SB(inode)->clusterbits,
1522 .mpage_ret = mpage_ret,
1523 .kaddr_ret = &kaddr
1524 };
1525 const unsigned int clustersize = 1 << ctx.clusterbits;
1526 /* if both m_(l,p)len are 0, regularize l_lblk, l_lofs, etc... */
1527 const bool initial = !map->m_llen;
1528
1532 /* logicial extent (start, end) offset */ 1529 /* logicial extent (start, end) offset */
1533 unsigned long long ofs, end; 1530 unsigned long long ofs, end;
1534 struct z_erofs_vle_decompressed_index *di; 1531 unsigned int lcn;
1535 erofs_blk_t e_blkaddr, pcn;
1536 unsigned lcn, logical_cluster_ofs, cluster_type;
1537 u32 ofs_rem; 1532 u32 ofs_rem;
1533
1534 /* initialize `pblk' to keep gcc from printing foolish warnings */
1535 erofs_blk_t mblk, pblk = 0;
1538 struct page *mpage = *mpage_ret; 1536 struct page *mpage = *mpage_ret;
1539 void *kaddr; 1537 struct z_erofs_vle_decompressed_index *di;
1540 bool initial; 1538 unsigned int cluster_type, logical_cluster_ofs;
1541 const unsigned int clusterbits = EROFS_SB(inode->i_sb)->clusterbits;
1542 const unsigned int clustersize = 1 << clusterbits;
1543 int err = 0; 1539 int err = 0;
1544 1540
1545 /* if both m_(l,p)len are 0, regularize l_lblk, l_lofs, etc... */ 1541 trace_z_erofs_map_blocks_iter_enter(inode, map, flags);
1546 initial = !map->m_llen;
1547 1542
1548 /* when trying to read beyond EOF, leave it unmapped */ 1543 /* when trying to read beyond EOF, leave it unmapped */
1549 if (unlikely(map->m_la >= inode->i_size)) { 1544 if (unlikely(map->m_la >= inode->i_size)) {
1550 BUG_ON(!initial); 1545 DBG_BUGON(!initial);
1551 map->m_llen = map->m_la + 1 - inode->i_size; 1546 map->m_llen = map->m_la + 1 - inode->i_size;
1552 map->m_la = inode->i_size - 1; 1547 map->m_la = inode->i_size;
1553 map->m_flags = 0; 1548 map->m_flags = 0;
1554 goto out; 1549 goto out;
1555 } 1550 }
@@ -1560,16 +1555,20 @@ int z_erofs_map_blocks_iter(struct inode *inode,
1560 ofs = map->m_la + map->m_llen; 1555 ofs = map->m_la + map->m_llen;
1561 1556
1562 /* clustersize should be power of two */ 1557 /* clustersize should be power of two */
1563 lcn = ofs >> clusterbits; 1558 lcn = ofs >> ctx.clusterbits;
1564 ofs_rem = ofs & (clustersize - 1); 1559 ofs_rem = ofs & (clustersize - 1);
1565 1560
1566 e_blkaddr = vle_extent_blkaddr(inode, lcn); 1561 mblk = vle_extent_blkaddr(inode, lcn);
1567 1562
1568 if (mpage == NULL || mpage->index != e_blkaddr) { 1563 if (!mpage || mpage->index != mblk) {
1569 if (mpage != NULL) 1564 if (mpage != NULL)
1570 put_page(mpage); 1565 put_page(mpage);
1571 1566
1572 mpage = erofs_get_meta_page(inode->i_sb, e_blkaddr, false); 1567 mpage = erofs_get_meta_page(ctx.sb, mblk, false);
1568 if (IS_ERR(mpage)) {
1569 err = PTR_ERR(mpage);
1570 goto out;
1571 }
1573 *mpage_ret = mpage; 1572 *mpage_ret = mpage;
1574 } else { 1573 } else {
1575 lock_page(mpage); 1574 lock_page(mpage);
@@ -1579,10 +1578,14 @@ int z_erofs_map_blocks_iter(struct inode *inode,
1579 kaddr = kmap_atomic(mpage); 1578 kaddr = kmap_atomic(mpage);
1580 di = kaddr + vle_extent_blkoff(inode, lcn); 1579 di = kaddr + vle_extent_blkoff(inode, lcn);
1581 1580
1582 debugln("%s, lcn %u e_blkaddr %u e_blkoff %u", __func__, lcn, 1581 debugln("%s, lcn %u mblk %u e_blkoff %u", __func__, lcn,
1583 e_blkaddr, vle_extent_blkoff(inode, lcn)); 1582 mblk, vle_extent_blkoff(inode, lcn));
1583
1584 err = vle_decompressed_index_clusterofs(&logical_cluster_ofs,
1585 clustersize, di);
1586 if (unlikely(err))
1587 goto unmap_out;
1584 1588
1585 logical_cluster_ofs = vle_compressed_index_clusterofs(clustersize, di);
1586 if (!initial) { 1589 if (!initial) {
1587 /* [walking mode] 'map' has been already initialized */ 1590 /* [walking mode] 'map' has been already initialized */
1588 map->m_llen += logical_cluster_ofs; 1591 map->m_llen += logical_cluster_ofs;
@@ -1592,7 +1595,7 @@ int z_erofs_map_blocks_iter(struct inode *inode,
1592 /* by default, compressed */ 1595 /* by default, compressed */
1593 map->m_flags |= EROFS_MAP_ZIPPED; 1596 map->m_flags |= EROFS_MAP_ZIPPED;
1594 1597
1595 end = (u64)(lcn + 1) * clustersize; 1598 end = ((u64)lcn + 1) * clustersize;
1596 1599
1597 cluster_type = vle_cluster_type(di); 1600 cluster_type = vle_cluster_type(di);
1598 1601
@@ -1603,13 +1606,13 @@ int z_erofs_map_blocks_iter(struct inode *inode,
1603 /* fallthrough */ 1606 /* fallthrough */
1604 case Z_EROFS_VLE_CLUSTER_TYPE_HEAD: 1607 case Z_EROFS_VLE_CLUSTER_TYPE_HEAD:
1605 if (ofs_rem == logical_cluster_ofs) { 1608 if (ofs_rem == logical_cluster_ofs) {
1606 pcn = le32_to_cpu(di->di_u.blkaddr); 1609 pblk = le32_to_cpu(di->di_u.blkaddr);
1607 goto exact_hitted; 1610 goto exact_hitted;
1608 } 1611 }
1609 1612
1610 if (ofs_rem > logical_cluster_ofs) { 1613 if (ofs_rem > logical_cluster_ofs) {
1611 ofs = lcn * clustersize | logical_cluster_ofs; 1614 ofs = (u64)lcn * clustersize | logical_cluster_ofs;
1612 pcn = le32_to_cpu(di->di_u.blkaddr); 1615 pblk = le32_to_cpu(di->di_u.blkaddr);
1613 break; 1616 break;
1614 } 1617 }
1615 1618
@@ -1620,13 +1623,19 @@ int z_erofs_map_blocks_iter(struct inode *inode,
1620 err = -EIO; 1623 err = -EIO;
1621 goto unmap_out; 1624 goto unmap_out;
1622 } 1625 }
1623 end = (lcn-- * clustersize) | logical_cluster_ofs; 1626 end = ((u64)lcn-- * clustersize) | logical_cluster_ofs;
1624 /* fallthrough */ 1627 /* fallthrough */
1625 case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD: 1628 case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD:
1626 /* get the correspoinding first chunk */ 1629 /* get the correspoinding first chunk */
1627 ofs = vle_get_logical_extent_head(inode, mpage_ret, 1630 err = vle_get_logical_extent_head(&ctx, lcn, &ofs,
1628 &kaddr, lcn, &pcn, &map->m_flags); 1631 &pblk, &map->m_flags);
1629 mpage = *mpage_ret; 1632 mpage = *mpage_ret;
1633
1634 if (unlikely(err)) {
1635 if (mpage)
1636 goto unmap_out;
1637 goto out;
1638 }
1630 break; 1639 break;
1631 default: 1640 default:
1632 errln("unknown cluster type %u at offset %llu of nid %llu", 1641 errln("unknown cluster type %u at offset %llu of nid %llu",
@@ -1639,7 +1648,7 @@ int z_erofs_map_blocks_iter(struct inode *inode,
1639exact_hitted: 1648exact_hitted:
1640 map->m_llen = end - ofs; 1649 map->m_llen = end - ofs;
1641 map->m_plen = clustersize; 1650 map->m_plen = clustersize;
1642 map->m_pa = blknr_to_addr(pcn); 1651 map->m_pa = blknr_to_addr(pblk);
1643 map->m_flags |= EROFS_MAP_MAPPED; 1652 map->m_flags |= EROFS_MAP_MAPPED;
1644unmap_out: 1653unmap_out:
1645 kunmap_atomic(kaddr); 1654 kunmap_atomic(kaddr);
@@ -1649,8 +1658,10 @@ out:
1649 __func__, map->m_la, map->m_pa, 1658 __func__, map->m_la, map->m_pa,
1650 map->m_llen, map->m_plen, map->m_flags); 1659 map->m_llen, map->m_plen, map->m_flags);
1651 1660
1661 trace_z_erofs_map_blocks_iter_exit(inode, map, flags, err);
1662
1652 /* aggressively BUG_ON iff CONFIG_EROFS_FS_DEBUG is on */ 1663 /* aggressively BUG_ON iff CONFIG_EROFS_FS_DEBUG is on */
1653 DBG_BUGON(err < 0); 1664 DBG_BUGON(err < 0 && err != -ENOMEM);
1654 return err; 1665 return err;
1655} 1666}
1656 1667
diff --git a/drivers/staging/erofs/unzip_vle.h b/drivers/staging/erofs/unzip_vle.h
index 393998500865..3316bc36965d 100644
--- a/drivers/staging/erofs/unzip_vle.h
+++ b/drivers/staging/erofs/unzip_vle.h
@@ -47,13 +47,6 @@ static inline bool z_erofs_gather_if_stagingpage(struct list_head *page_pool,
47#define Z_EROFS_VLE_INLINE_PAGEVECS 3 47#define Z_EROFS_VLE_INLINE_PAGEVECS 3
48 48
49struct z_erofs_vle_work { 49struct z_erofs_vle_work {
50 /* struct z_erofs_vle_work *left, *right; */
51
52#ifdef CONFIG_EROFS_FS_ZIP_MULTIREF
53 struct list_head list;
54
55 atomic_t refcount;
56#endif
57 struct mutex lock; 50 struct mutex lock;
58 51
59 /* I: decompression offset in page */ 52 /* I: decompression offset in page */
@@ -107,10 +100,8 @@ static inline void z_erofs_vle_set_workgrp_fmt(
107 grp->flags = fmt | (grp->flags & ~Z_EROFS_VLE_WORKGRP_FMT_MASK); 100 grp->flags = fmt | (grp->flags & ~Z_EROFS_VLE_WORKGRP_FMT_MASK);
108} 101}
109 102
110#ifdef CONFIG_EROFS_FS_ZIP_MULTIREF
111#error multiref decompression is unimplemented yet
112#else
113 103
104/* definitions if multiref is disabled */
114#define z_erofs_vle_grab_primary_work(grp) (&(grp)->work) 105#define z_erofs_vle_grab_primary_work(grp) (&(grp)->work)
115#define z_erofs_vle_grab_work(grp, pageofs) (&(grp)->work) 106#define z_erofs_vle_grab_work(grp, pageofs) (&(grp)->work)
116#define z_erofs_vle_work_workgroup(wrk, primary) \ 107#define z_erofs_vle_work_workgroup(wrk, primary) \
@@ -118,7 +109,6 @@ static inline void z_erofs_vle_set_workgrp_fmt(
118 struct z_erofs_vle_workgroup, work) : \ 109 struct z_erofs_vle_workgroup, work) : \
119 ({ BUG(); (void *)NULL; })) 110 ({ BUG(); (void *)NULL; }))
120 111
121#endif
122 112
123#define Z_EROFS_WORKGROUP_SIZE sizeof(struct z_erofs_vle_workgroup) 113#define Z_EROFS_WORKGROUP_SIZE sizeof(struct z_erofs_vle_workgroup)
124 114
diff --git a/drivers/staging/erofs/unzip_vle_lz4.c b/drivers/staging/erofs/unzip_vle_lz4.c
index f5b665f15be5..1a428658cbea 100644
--- a/drivers/staging/erofs/unzip_vle_lz4.c
+++ b/drivers/staging/erofs/unzip_vle_lz4.c
@@ -23,14 +23,14 @@ static struct {
23} erofs_pcpubuf[NR_CPUS]; 23} erofs_pcpubuf[NR_CPUS];
24 24
25int z_erofs_vle_plain_copy(struct page **compressed_pages, 25int z_erofs_vle_plain_copy(struct page **compressed_pages,
26 unsigned clusterpages, 26 unsigned int clusterpages,
27 struct page **pages, 27 struct page **pages,
28 unsigned nr_pages, 28 unsigned int nr_pages,
29 unsigned short pageofs) 29 unsigned short pageofs)
30{ 30{
31 unsigned i, j; 31 unsigned int i, j;
32 void *src = NULL; 32 void *src = NULL;
33 const unsigned righthalf = PAGE_SIZE - pageofs; 33 const unsigned int righthalf = PAGE_SIZE - pageofs;
34 char *percpu_data; 34 char *percpu_data;
35 bool mirrored[Z_EROFS_CLUSTER_MAX_PAGES] = { 0 }; 35 bool mirrored[Z_EROFS_CLUSTER_MAX_PAGES] = { 0 };
36 36
@@ -42,8 +42,8 @@ int z_erofs_vle_plain_copy(struct page **compressed_pages,
42 struct page *page = pages[i]; 42 struct page *page = pages[i];
43 void *dst; 43 void *dst;
44 44
45 if (page == NULL) { 45 if (!page) {
46 if (src != NULL) { 46 if (src) {
47 if (!mirrored[j]) 47 if (!mirrored[j])
48 kunmap_atomic(src); 48 kunmap_atomic(src);
49 src = NULL; 49 src = NULL;
@@ -64,14 +64,14 @@ int z_erofs_vle_plain_copy(struct page **compressed_pages,
64 } 64 }
65 65
66 if (i) { 66 if (i) {
67 if (src == NULL) 67 if (!src)
68 src = mirrored[i-1] ? 68 src = mirrored[i - 1] ?
69 percpu_data + (i-1) * PAGE_SIZE : 69 percpu_data + (i - 1) * PAGE_SIZE :
70 kmap_atomic(compressed_pages[i-1]); 70 kmap_atomic(compressed_pages[i - 1]);
71 71
72 memcpy(dst, src + righthalf, pageofs); 72 memcpy(dst, src + righthalf, pageofs);
73 73
74 if (!mirrored[i-1]) 74 if (!mirrored[i - 1])
75 kunmap_atomic(src); 75 kunmap_atomic(src);
76 76
77 if (unlikely(i >= clusterpages)) { 77 if (unlikely(i >= clusterpages)) {
@@ -80,9 +80,9 @@ int z_erofs_vle_plain_copy(struct page **compressed_pages,
80 } 80 }
81 } 81 }
82 82
83 if (!righthalf) 83 if (!righthalf) {
84 src = NULL; 84 src = NULL;
85 else { 85 } else {
86 src = mirrored[i] ? percpu_data + i * PAGE_SIZE : 86 src = mirrored[i] ? percpu_data + i * PAGE_SIZE :
87 kmap_atomic(compressed_pages[i]); 87 kmap_atomic(compressed_pages[i]);
88 88
@@ -92,7 +92,7 @@ int z_erofs_vle_plain_copy(struct page **compressed_pages,
92 kunmap_atomic(dst); 92 kunmap_atomic(dst);
93 } 93 }
94 94
95 if (src != NULL && !mirrored[j]) 95 if (src && !mirrored[j])
96 kunmap_atomic(src); 96 kunmap_atomic(src);
97 97
98 preempt_enable(); 98 preempt_enable();
@@ -102,14 +102,14 @@ int z_erofs_vle_plain_copy(struct page **compressed_pages,
102extern int z_erofs_unzip_lz4(void *in, void *out, size_t inlen, size_t outlen); 102extern int z_erofs_unzip_lz4(void *in, void *out, size_t inlen, size_t outlen);
103 103
104int z_erofs_vle_unzip_fast_percpu(struct page **compressed_pages, 104int z_erofs_vle_unzip_fast_percpu(struct page **compressed_pages,
105 unsigned clusterpages, 105 unsigned int clusterpages,
106 struct page **pages, 106 struct page **pages,
107 unsigned outlen, 107 unsigned int outlen,
108 unsigned short pageofs, 108 unsigned short pageofs,
109 void (*endio)(struct page *)) 109 void (*endio)(struct page *))
110{ 110{
111 void *vin, *vout; 111 void *vin, *vout;
112 unsigned nr_pages, i, j; 112 unsigned int nr_pages, i, j;
113 int ret; 113 int ret;
114 114
115 if (outlen + pageofs > EROFS_PERCPU_NR_PAGES * PAGE_SIZE) 115 if (outlen + pageofs > EROFS_PERCPU_NR_PAGES * PAGE_SIZE)
@@ -126,7 +126,7 @@ int z_erofs_vle_unzip_fast_percpu(struct page **compressed_pages,
126 vout = erofs_pcpubuf[smp_processor_id()].data; 126 vout = erofs_pcpubuf[smp_processor_id()].data;
127 127
128 ret = z_erofs_unzip_lz4(vin, vout + pageofs, 128 ret = z_erofs_unzip_lz4(vin, vout + pageofs,
129 clusterpages * PAGE_SIZE, outlen); 129 clusterpages * PAGE_SIZE, outlen);
130 130
131 if (ret >= 0) { 131 if (ret >= 0) {
132 outlen = ret; 132 outlen = ret;
@@ -134,14 +134,15 @@ int z_erofs_vle_unzip_fast_percpu(struct page **compressed_pages,
134 } 134 }
135 135
136 for (i = 0; i < nr_pages; ++i) { 136 for (i = 0; i < nr_pages; ++i) {
137 j = min((unsigned)PAGE_SIZE - pageofs, outlen); 137 j = min((unsigned int)PAGE_SIZE - pageofs, outlen);
138 138
139 if (pages[i] != NULL) { 139 if (pages[i]) {
140 if (ret < 0) 140 if (ret < 0) {
141 SetPageError(pages[i]); 141 SetPageError(pages[i]);
142 else if (clusterpages == 1 && pages[i] == compressed_pages[0]) 142 } else if (clusterpages == 1 &&
143 pages[i] == compressed_pages[0]) {
143 memcpy(vin + pageofs, vout + pageofs, j); 144 memcpy(vin + pageofs, vout + pageofs, j);
144 else { 145 } else {
145 void *dst = kmap_atomic(pages[i]); 146 void *dst = kmap_atomic(pages[i]);
146 147
147 memcpy(dst + pageofs, vout + pageofs, j); 148 memcpy(dst + pageofs, vout + pageofs, j);
@@ -164,14 +165,14 @@ int z_erofs_vle_unzip_fast_percpu(struct page **compressed_pages,
164} 165}
165 166
166int z_erofs_vle_unzip_vmap(struct page **compressed_pages, 167int z_erofs_vle_unzip_vmap(struct page **compressed_pages,
167 unsigned clusterpages, 168 unsigned int clusterpages,
168 void *vout, 169 void *vout,
169 unsigned llen, 170 unsigned int llen,
170 unsigned short pageofs, 171 unsigned short pageofs,
171 bool overlapped) 172 bool overlapped)
172{ 173{
173 void *vin; 174 void *vin;
174 unsigned i; 175 unsigned int i;
175 int ret; 176 int ret;
176 177
177 if (overlapped) { 178 if (overlapped) {
@@ -181,29 +182,27 @@ int z_erofs_vle_unzip_vmap(struct page **compressed_pages,
181 for (i = 0; i < clusterpages; ++i) { 182 for (i = 0; i < clusterpages; ++i) {
182 void *t = kmap_atomic(compressed_pages[i]); 183 void *t = kmap_atomic(compressed_pages[i]);
183 184
184 memcpy(vin + PAGE_SIZE *i, t, PAGE_SIZE); 185 memcpy(vin + PAGE_SIZE * i, t, PAGE_SIZE);
185 kunmap_atomic(t); 186 kunmap_atomic(t);
186 } 187 }
187 } else if (clusterpages == 1) 188 } else if (clusterpages == 1) {
188 vin = kmap_atomic(compressed_pages[0]); 189 vin = kmap_atomic(compressed_pages[0]);
189 else { 190 } else {
190 vin = erofs_vmap(compressed_pages, clusterpages); 191 vin = erofs_vmap(compressed_pages, clusterpages);
191 } 192 }
192 193
193 ret = z_erofs_unzip_lz4(vin, vout + pageofs, 194 ret = z_erofs_unzip_lz4(vin, vout + pageofs,
194 clusterpages * PAGE_SIZE, llen); 195 clusterpages * PAGE_SIZE, llen);
195 if (ret > 0) 196 if (ret > 0)
196 ret = 0; 197 ret = 0;
197 198
198 if (!overlapped) { 199 if (!overlapped) {
199 if (clusterpages == 1) 200 if (clusterpages == 1)
200 kunmap_atomic(vin); 201 kunmap_atomic(vin);
201 else { 202 else
202 erofs_vunmap(vin, clusterpages); 203 erofs_vunmap(vin, clusterpages);
203 } 204 } else {
204 } else
205 preempt_enable(); 205 preempt_enable();
206 206 }
207 return ret; 207 return ret;
208} 208}
209
diff --git a/drivers/staging/erofs/utils.c b/drivers/staging/erofs/utils.c
index bdee9bd09f11..ea8a962e5c95 100644
--- a/drivers/staging/erofs/utils.c
+++ b/drivers/staging/erofs/utils.c
@@ -116,7 +116,7 @@ unsigned long erofs_shrink_workstation(struct erofs_sb_info *sbi,
116{ 116{
117 pgoff_t first_index = 0; 117 pgoff_t first_index = 0;
118 void *batch[PAGEVEC_SIZE]; 118 void *batch[PAGEVEC_SIZE];
119 unsigned freed = 0; 119 unsigned int freed = 0;
120 120
121 int i, found; 121 int i, found;
122repeat: 122repeat:
diff --git a/drivers/staging/erofs/xattr.c b/drivers/staging/erofs/xattr.c
index 0e9cfeccdf99..80dca6a4adbe 100644
--- a/drivers/staging/erofs/xattr.c
+++ b/drivers/staging/erofs/xattr.c
@@ -19,41 +19,53 @@ struct xattr_iter {
19 void *kaddr; 19 void *kaddr;
20 20
21 erofs_blk_t blkaddr; 21 erofs_blk_t blkaddr;
22 unsigned ofs; 22 unsigned int ofs;
23}; 23};
24 24
25static inline void xattr_iter_end(struct xattr_iter *it, bool atomic) 25static inline void xattr_iter_end(struct xattr_iter *it, bool atomic)
26{ 26{
27 /* only init_inode_xattrs use non-atomic once */ 27 /* the only user of kunmap() is 'init_inode_xattrs' */
28 if (unlikely(!atomic)) 28 if (unlikely(!atomic))
29 kunmap(it->page); 29 kunmap(it->page);
30 else 30 else
31 kunmap_atomic(it->kaddr); 31 kunmap_atomic(it->kaddr);
32
32 unlock_page(it->page); 33 unlock_page(it->page);
33 put_page(it->page); 34 put_page(it->page);
34} 35}
35 36
36static void init_inode_xattrs(struct inode *inode) 37static inline void xattr_iter_end_final(struct xattr_iter *it)
38{
39 if (it->page == NULL)
40 return;
41
42 xattr_iter_end(it, true);
43}
44
45static int init_inode_xattrs(struct inode *inode)
37{ 46{
38 struct xattr_iter it; 47 struct xattr_iter it;
39 unsigned i; 48 unsigned int i;
40 struct erofs_xattr_ibody_header *ih; 49 struct erofs_xattr_ibody_header *ih;
50 struct super_block *sb;
41 struct erofs_sb_info *sbi; 51 struct erofs_sb_info *sbi;
42 struct erofs_vnode *vi; 52 struct erofs_vnode *vi;
43 bool atomic_map; 53 bool atomic_map;
44 54
45 if (likely(inode_has_inited_xattr(inode))) 55 if (likely(inode_has_inited_xattr(inode)))
46 return; 56 return 0;
47 57
48 vi = EROFS_V(inode); 58 vi = EROFS_V(inode);
49 BUG_ON(!vi->xattr_isize); 59 BUG_ON(!vi->xattr_isize);
50 60
51 sbi = EROFS_I_SB(inode); 61 sb = inode->i_sb;
62 sbi = EROFS_SB(sb);
52 it.blkaddr = erofs_blknr(iloc(sbi, vi->nid) + vi->inode_isize); 63 it.blkaddr = erofs_blknr(iloc(sbi, vi->nid) + vi->inode_isize);
53 it.ofs = erofs_blkoff(iloc(sbi, vi->nid) + vi->inode_isize); 64 it.ofs = erofs_blkoff(iloc(sbi, vi->nid) + vi->inode_isize);
54 65
55 it.page = erofs_get_inline_page(inode, it.blkaddr); 66 it.page = erofs_get_inline_page(inode, it.blkaddr);
56 BUG_ON(IS_ERR(it.page)); 67 if (IS_ERR(it.page))
68 return PTR_ERR(it.page);
57 69
58 /* read in shared xattr array (non-atomic, see kmalloc below) */ 70 /* read in shared xattr array (non-atomic, see kmalloc below) */
59 it.kaddr = kmap(it.page); 71 it.kaddr = kmap(it.page);
@@ -62,9 +74,12 @@ static void init_inode_xattrs(struct inode *inode)
62 ih = (struct erofs_xattr_ibody_header *)(it.kaddr + it.ofs); 74 ih = (struct erofs_xattr_ibody_header *)(it.kaddr + it.ofs);
63 75
64 vi->xattr_shared_count = ih->h_shared_count; 76 vi->xattr_shared_count = ih->h_shared_count;
65 vi->xattr_shared_xattrs = (unsigned *)kmalloc_array( 77 vi->xattr_shared_xattrs = kmalloc_array(vi->xattr_shared_count,
66 vi->xattr_shared_count, sizeof(unsigned), 78 sizeof(uint), GFP_KERNEL);
67 GFP_KERNEL | __GFP_NOFAIL); 79 if (vi->xattr_shared_xattrs == NULL) {
80 xattr_iter_end(&it, atomic_map);
81 return -ENOMEM;
82 }
68 83
69 /* let's skip ibody header */ 84 /* let's skip ibody header */
70 it.ofs += sizeof(struct erofs_xattr_ibody_header); 85 it.ofs += sizeof(struct erofs_xattr_ibody_header);
@@ -75,9 +90,10 @@ static void init_inode_xattrs(struct inode *inode)
75 BUG_ON(it.ofs != EROFS_BLKSIZ); 90 BUG_ON(it.ofs != EROFS_BLKSIZ);
76 xattr_iter_end(&it, atomic_map); 91 xattr_iter_end(&it, atomic_map);
77 92
78 it.page = erofs_get_meta_page(inode->i_sb, 93 it.page = erofs_get_meta_page(sb,
79 ++it.blkaddr, S_ISDIR(inode->i_mode)); 94 ++it.blkaddr, S_ISDIR(inode->i_mode));
80 BUG_ON(IS_ERR(it.page)); 95 if (IS_ERR(it.page))
96 return PTR_ERR(it.page);
81 97
82 it.kaddr = kmap_atomic(it.page); 98 it.kaddr = kmap_atomic(it.page);
83 atomic_map = true; 99 atomic_map = true;
@@ -90,27 +106,43 @@ static void init_inode_xattrs(struct inode *inode)
90 xattr_iter_end(&it, atomic_map); 106 xattr_iter_end(&it, atomic_map);
91 107
92 inode_set_inited_xattr(inode); 108 inode_set_inited_xattr(inode);
109 return 0;
93} 110}
94 111
112/*
113 * the general idea for these return values is
114 * if 0 is returned, go on processing the current xattr;
115 * 1 (> 0) is returned, skip this round to process the next xattr;
116 * -err (< 0) is returned, an error (maybe ENOXATTR) occurred
117 * and need to be handled
118 */
95struct xattr_iter_handlers { 119struct xattr_iter_handlers {
96 int (*entry)(struct xattr_iter *, struct erofs_xattr_entry *); 120 int (*entry)(struct xattr_iter *, struct erofs_xattr_entry *);
97 int (*name)(struct xattr_iter *, unsigned, char *, unsigned); 121 int (*name)(struct xattr_iter *, unsigned int, char *, unsigned int);
98 int (*alloc_buffer)(struct xattr_iter *, unsigned); 122 int (*alloc_buffer)(struct xattr_iter *, unsigned int);
99 void (*value)(struct xattr_iter *, unsigned, char *, unsigned); 123 void (*value)(struct xattr_iter *, unsigned int, char *, unsigned int);
100}; 124};
101 125
102static void xattr_iter_fixup(struct xattr_iter *it) 126static inline int xattr_iter_fixup(struct xattr_iter *it)
103{ 127{
104 if (unlikely(it->ofs >= EROFS_BLKSIZ)) { 128 if (it->ofs < EROFS_BLKSIZ)
105 xattr_iter_end(it, true); 129 return 0;
130
131 xattr_iter_end(it, true);
132
133 it->blkaddr += erofs_blknr(it->ofs);
106 134
107 it->blkaddr += erofs_blknr(it->ofs); 135 it->page = erofs_get_meta_page(it->sb, it->blkaddr, false);
108 it->page = erofs_get_meta_page(it->sb, it->blkaddr, false); 136 if (IS_ERR(it->page)) {
109 BUG_ON(IS_ERR(it->page)); 137 int err = PTR_ERR(it->page);
110 138
111 it->kaddr = kmap_atomic(it->page); 139 it->page = NULL;
112 it->ofs = erofs_blkoff(it->ofs); 140 return err;
113 } 141 }
142
143 it->kaddr = kmap_atomic(it->page);
144 it->ofs = erofs_blkoff(it->ofs);
145 return 0;
114} 146}
115 147
116static int inline_xattr_iter_begin(struct xattr_iter *it, 148static int inline_xattr_iter_begin(struct xattr_iter *it,
@@ -118,7 +150,7 @@ static int inline_xattr_iter_begin(struct xattr_iter *it,
118{ 150{
119 struct erofs_vnode *const vi = EROFS_V(inode); 151 struct erofs_vnode *const vi = EROFS_V(inode);
120 struct erofs_sb_info *const sbi = EROFS_SB(inode->i_sb); 152 struct erofs_sb_info *const sbi = EROFS_SB(inode->i_sb);
121 unsigned xattr_header_sz, inline_xattr_ofs; 153 unsigned int xattr_header_sz, inline_xattr_ofs;
122 154
123 xattr_header_sz = inlinexattr_header_size(inode); 155 xattr_header_sz = inlinexattr_header_size(inode);
124 if (unlikely(xattr_header_sz >= vi->xattr_isize)) { 156 if (unlikely(xattr_header_sz >= vi->xattr_isize)) {
@@ -132,21 +164,28 @@ static int inline_xattr_iter_begin(struct xattr_iter *it,
132 it->ofs = erofs_blkoff(iloc(sbi, vi->nid) + inline_xattr_ofs); 164 it->ofs = erofs_blkoff(iloc(sbi, vi->nid) + inline_xattr_ofs);
133 165
134 it->page = erofs_get_inline_page(inode, it->blkaddr); 166 it->page = erofs_get_inline_page(inode, it->blkaddr);
135 BUG_ON(IS_ERR(it->page)); 167 if (IS_ERR(it->page))
136 it->kaddr = kmap_atomic(it->page); 168 return PTR_ERR(it->page);
137 169
170 it->kaddr = kmap_atomic(it->page);
138 return vi->xattr_isize - xattr_header_sz; 171 return vi->xattr_isize - xattr_header_sz;
139} 172}
140 173
174/*
175 * Regardless of success or failure, `xattr_foreach' will end up with
176 * `ofs' pointing to the next xattr item rather than an arbitrary position.
177 */
141static int xattr_foreach(struct xattr_iter *it, 178static int xattr_foreach(struct xattr_iter *it,
142 struct xattr_iter_handlers *op, unsigned *tlimit) 179 const struct xattr_iter_handlers *op, unsigned int *tlimit)
143{ 180{
144 struct erofs_xattr_entry entry; 181 struct erofs_xattr_entry entry;
145 unsigned value_sz, processed, slice; 182 unsigned int value_sz, processed, slice;
146 int err; 183 int err;
147 184
148 /* 0. fixup blkaddr, ofs, ipage */ 185 /* 0. fixup blkaddr, ofs, ipage */
149 xattr_iter_fixup(it); 186 err = xattr_iter_fixup(it);
187 if (err)
188 return err;
150 189
151 /* 190 /*
152 * 1. read xattr entry to the memory, 191 * 1. read xattr entry to the memory,
@@ -155,7 +194,7 @@ static int xattr_foreach(struct xattr_iter *it,
155 */ 194 */
156 entry = *(struct erofs_xattr_entry *)(it->kaddr + it->ofs); 195 entry = *(struct erofs_xattr_entry *)(it->kaddr + it->ofs);
157 if (tlimit != NULL) { 196 if (tlimit != NULL) {
158 unsigned entry_sz = EROFS_XATTR_ENTRY_SIZE(&entry); 197 unsigned int entry_sz = EROFS_XATTR_ENTRY_SIZE(&entry);
159 198
160 BUG_ON(*tlimit < entry_sz); 199 BUG_ON(*tlimit < entry_sz);
161 *tlimit -= entry_sz; 200 *tlimit -= entry_sz;
@@ -178,12 +217,14 @@ static int xattr_foreach(struct xattr_iter *it,
178 if (it->ofs >= EROFS_BLKSIZ) { 217 if (it->ofs >= EROFS_BLKSIZ) {
179 BUG_ON(it->ofs > EROFS_BLKSIZ); 218 BUG_ON(it->ofs > EROFS_BLKSIZ);
180 219
181 xattr_iter_fixup(it); 220 err = xattr_iter_fixup(it);
221 if (err)
222 goto out;
182 it->ofs = 0; 223 it->ofs = 0;
183 } 224 }
184 225
185 slice = min_t(unsigned, PAGE_SIZE - it->ofs, 226 slice = min_t(unsigned int, PAGE_SIZE - it->ofs,
186 entry.e_name_len - processed); 227 entry.e_name_len - processed);
187 228
188 /* handle name */ 229 /* handle name */
189 err = op->name(it, processed, it->kaddr + it->ofs, slice); 230 err = op->name(it, processed, it->kaddr + it->ofs, slice);
@@ -210,21 +251,24 @@ static int xattr_foreach(struct xattr_iter *it,
210 while (processed < value_sz) { 251 while (processed < value_sz) {
211 if (it->ofs >= EROFS_BLKSIZ) { 252 if (it->ofs >= EROFS_BLKSIZ) {
212 BUG_ON(it->ofs > EROFS_BLKSIZ); 253 BUG_ON(it->ofs > EROFS_BLKSIZ);
213 xattr_iter_fixup(it); 254
255 err = xattr_iter_fixup(it);
256 if (err)
257 goto out;
214 it->ofs = 0; 258 it->ofs = 0;
215 } 259 }
216 260
217 slice = min_t(unsigned, PAGE_SIZE - it->ofs, 261 slice = min_t(unsigned int, PAGE_SIZE - it->ofs,
218 value_sz - processed); 262 value_sz - processed);
219 op->value(it, processed, it->kaddr + it->ofs, slice); 263 op->value(it, processed, it->kaddr + it->ofs, slice);
220 it->ofs += slice; 264 it->ofs += slice;
221 processed += slice; 265 processed += slice;
222 } 266 }
223 267
224out: 268out:
225 /* we assume that ofs is aligned with 4 bytes */ 269 /* xattrs should be 4-byte aligned (on-disk constraint) */
226 it->ofs = EROFS_XATTR_ALIGN(it->ofs); 270 it->ofs = EROFS_XATTR_ALIGN(it->ofs);
227 return err; 271 return err < 0 ? err : 0;
228} 272}
229 273
230struct getxattr_iter { 274struct getxattr_iter {
@@ -245,7 +289,7 @@ static int xattr_entrymatch(struct xattr_iter *_it,
245} 289}
246 290
247static int xattr_namematch(struct xattr_iter *_it, 291static int xattr_namematch(struct xattr_iter *_it,
248 unsigned processed, char *buf, unsigned len) 292 unsigned int processed, char *buf, unsigned int len)
249{ 293{
250 struct getxattr_iter *it = container_of(_it, struct getxattr_iter, it); 294 struct getxattr_iter *it = container_of(_it, struct getxattr_iter, it);
251 295
@@ -253,7 +297,7 @@ static int xattr_namematch(struct xattr_iter *_it,
253} 297}
254 298
255static int xattr_checkbuffer(struct xattr_iter *_it, 299static int xattr_checkbuffer(struct xattr_iter *_it,
256 unsigned value_sz) 300 unsigned int value_sz)
257{ 301{
258 struct getxattr_iter *it = container_of(_it, struct getxattr_iter, it); 302 struct getxattr_iter *it = container_of(_it, struct getxattr_iter, it);
259 int err = it->buffer_size < value_sz ? -ERANGE : 0; 303 int err = it->buffer_size < value_sz ? -ERANGE : 0;
@@ -263,14 +307,14 @@ static int xattr_checkbuffer(struct xattr_iter *_it,
263} 307}
264 308
265static void xattr_copyvalue(struct xattr_iter *_it, 309static void xattr_copyvalue(struct xattr_iter *_it,
266 unsigned processed, char *buf, unsigned len) 310 unsigned int processed, char *buf, unsigned int len)
267{ 311{
268 struct getxattr_iter *it = container_of(_it, struct getxattr_iter, it); 312 struct getxattr_iter *it = container_of(_it, struct getxattr_iter, it);
269 313
270 memcpy(it->buffer + processed, buf, len); 314 memcpy(it->buffer + processed, buf, len);
271} 315}
272 316
273static struct xattr_iter_handlers find_xattr_handlers = { 317static const struct xattr_iter_handlers find_xattr_handlers = {
274 .entry = xattr_entrymatch, 318 .entry = xattr_entrymatch,
275 .name = xattr_namematch, 319 .name = xattr_namematch,
276 .alloc_buffer = xattr_checkbuffer, 320 .alloc_buffer = xattr_checkbuffer,
@@ -280,7 +324,7 @@ static struct xattr_iter_handlers find_xattr_handlers = {
280static int inline_getxattr(struct inode *inode, struct getxattr_iter *it) 324static int inline_getxattr(struct inode *inode, struct getxattr_iter *it)
281{ 325{
282 int ret; 326 int ret;
283 unsigned remaining; 327 unsigned int remaining;
284 328
285 ret = inline_xattr_iter_begin(&it->it, inode); 329 ret = inline_xattr_iter_begin(&it->it, inode);
286 if (ret < 0) 330 if (ret < 0)
@@ -289,19 +333,20 @@ static int inline_getxattr(struct inode *inode, struct getxattr_iter *it)
289 remaining = ret; 333 remaining = ret;
290 while (remaining) { 334 while (remaining) {
291 ret = xattr_foreach(&it->it, &find_xattr_handlers, &remaining); 335 ret = xattr_foreach(&it->it, &find_xattr_handlers, &remaining);
292 if (ret >= 0) 336 if (ret != -ENOATTR)
293 break; 337 break;
294 } 338 }
295 xattr_iter_end(&it->it, true); 339 xattr_iter_end_final(&it->it);
296 340
297 return ret < 0 ? ret : it->buffer_size; 341 return ret ? ret : it->buffer_size;
298} 342}
299 343
300static int shared_getxattr(struct inode *inode, struct getxattr_iter *it) 344static int shared_getxattr(struct inode *inode, struct getxattr_iter *it)
301{ 345{
302 struct erofs_vnode *const vi = EROFS_V(inode); 346 struct erofs_vnode *const vi = EROFS_V(inode);
303 struct erofs_sb_info *const sbi = EROFS_SB(inode->i_sb); 347 struct super_block *const sb = inode->i_sb;
304 unsigned i; 348 struct erofs_sb_info *const sbi = EROFS_SB(sb);
349 unsigned int i;
305 int ret = -ENOATTR; 350 int ret = -ENOATTR;
306 351
307 for (i = 0; i < vi->xattr_shared_count; ++i) { 352 for (i = 0; i < vi->xattr_shared_count; ++i) {
@@ -314,21 +359,22 @@ static int shared_getxattr(struct inode *inode, struct getxattr_iter *it)
314 if (i) 359 if (i)
315 xattr_iter_end(&it->it, true); 360 xattr_iter_end(&it->it, true);
316 361
317 it->it.page = erofs_get_meta_page(inode->i_sb, 362 it->it.page = erofs_get_meta_page(sb, blkaddr, false);
318 blkaddr, false); 363 if (IS_ERR(it->it.page))
319 BUG_ON(IS_ERR(it->it.page)); 364 return PTR_ERR(it->it.page);
365
320 it->it.kaddr = kmap_atomic(it->it.page); 366 it->it.kaddr = kmap_atomic(it->it.page);
321 it->it.blkaddr = blkaddr; 367 it->it.blkaddr = blkaddr;
322 } 368 }
323 369
324 ret = xattr_foreach(&it->it, &find_xattr_handlers, NULL); 370 ret = xattr_foreach(&it->it, &find_xattr_handlers, NULL);
325 if (ret >= 0) 371 if (ret != -ENOATTR)
326 break; 372 break;
327 } 373 }
328 if (vi->xattr_shared_count) 374 if (vi->xattr_shared_count)
329 xattr_iter_end(&it->it, true); 375 xattr_iter_end_final(&it->it);
330 376
331 return ret < 0 ? ret : it->buffer_size; 377 return ret ? ret : it->buffer_size;
332} 378}
333 379
334static bool erofs_xattr_user_list(struct dentry *dentry) 380static bool erofs_xattr_user_list(struct dentry *dentry)
@@ -351,7 +397,9 @@ int erofs_getxattr(struct inode *inode, int index,
351 if (unlikely(name == NULL)) 397 if (unlikely(name == NULL))
352 return -EINVAL; 398 return -EINVAL;
353 399
354 init_inode_xattrs(inode); 400 ret = init_inode_xattrs(inode);
401 if (ret)
402 return ret;
355 403
356 it.index = index; 404 it.index = index;
357 405
@@ -446,7 +494,7 @@ static int xattr_entrylist(struct xattr_iter *_it,
446{ 494{
447 struct listxattr_iter *it = 495 struct listxattr_iter *it =
448 container_of(_it, struct listxattr_iter, it); 496 container_of(_it, struct listxattr_iter, it);
449 unsigned prefix_len; 497 unsigned int prefix_len;
450 const char *prefix; 498 const char *prefix;
451 499
452 const struct xattr_handler *h = 500 const struct xattr_handler *h =
@@ -474,7 +522,7 @@ static int xattr_entrylist(struct xattr_iter *_it,
474} 522}
475 523
476static int xattr_namelist(struct xattr_iter *_it, 524static int xattr_namelist(struct xattr_iter *_it,
477 unsigned processed, char *buf, unsigned len) 525 unsigned int processed, char *buf, unsigned int len)
478{ 526{
479 struct listxattr_iter *it = 527 struct listxattr_iter *it =
480 container_of(_it, struct listxattr_iter, it); 528 container_of(_it, struct listxattr_iter, it);
@@ -485,7 +533,7 @@ static int xattr_namelist(struct xattr_iter *_it,
485} 533}
486 534
487static int xattr_skipvalue(struct xattr_iter *_it, 535static int xattr_skipvalue(struct xattr_iter *_it,
488 unsigned value_sz) 536 unsigned int value_sz)
489{ 537{
490 struct listxattr_iter *it = 538 struct listxattr_iter *it =
491 container_of(_it, struct listxattr_iter, it); 539 container_of(_it, struct listxattr_iter, it);
@@ -494,7 +542,7 @@ static int xattr_skipvalue(struct xattr_iter *_it,
494 return 1; 542 return 1;
495} 543}
496 544
497static struct xattr_iter_handlers list_xattr_handlers = { 545static const struct xattr_iter_handlers list_xattr_handlers = {
498 .entry = xattr_entrylist, 546 .entry = xattr_entrylist,
499 .name = xattr_namelist, 547 .name = xattr_namelist,
500 .alloc_buffer = xattr_skipvalue, 548 .alloc_buffer = xattr_skipvalue,
@@ -504,7 +552,7 @@ static struct xattr_iter_handlers list_xattr_handlers = {
504static int inline_listxattr(struct listxattr_iter *it) 552static int inline_listxattr(struct listxattr_iter *it)
505{ 553{
506 int ret; 554 int ret;
507 unsigned remaining; 555 unsigned int remaining;
508 556
509 ret = inline_xattr_iter_begin(&it->it, d_inode(it->dentry)); 557 ret = inline_xattr_iter_begin(&it->it, d_inode(it->dentry));
510 if (ret < 0) 558 if (ret < 0)
@@ -513,19 +561,20 @@ static int inline_listxattr(struct listxattr_iter *it)
513 remaining = ret; 561 remaining = ret;
514 while (remaining) { 562 while (remaining) {
515 ret = xattr_foreach(&it->it, &list_xattr_handlers, &remaining); 563 ret = xattr_foreach(&it->it, &list_xattr_handlers, &remaining);
516 if (ret < 0) 564 if (ret)
517 break; 565 break;
518 } 566 }
519 xattr_iter_end(&it->it, true); 567 xattr_iter_end_final(&it->it);
520 return ret < 0 ? ret : it->buffer_ofs; 568 return ret ? ret : it->buffer_ofs;
521} 569}
522 570
523static int shared_listxattr(struct listxattr_iter *it) 571static int shared_listxattr(struct listxattr_iter *it)
524{ 572{
525 struct inode *const inode = d_inode(it->dentry); 573 struct inode *const inode = d_inode(it->dentry);
526 struct erofs_vnode *const vi = EROFS_V(inode); 574 struct erofs_vnode *const vi = EROFS_V(inode);
527 struct erofs_sb_info *const sbi = EROFS_I_SB(inode); 575 struct super_block *const sb = inode->i_sb;
528 unsigned i; 576 struct erofs_sb_info *const sbi = EROFS_SB(sb);
577 unsigned int i;
529 int ret = 0; 578 int ret = 0;
530 579
531 for (i = 0; i < vi->xattr_shared_count; ++i) { 580 for (i = 0; i < vi->xattr_shared_count; ++i) {
@@ -537,21 +586,22 @@ static int shared_listxattr(struct listxattr_iter *it)
537 if (i) 586 if (i)
538 xattr_iter_end(&it->it, true); 587 xattr_iter_end(&it->it, true);
539 588
540 it->it.page = erofs_get_meta_page(inode->i_sb, 589 it->it.page = erofs_get_meta_page(sb, blkaddr, false);
541 blkaddr, false); 590 if (IS_ERR(it->it.page))
542 BUG_ON(IS_ERR(it->it.page)); 591 return PTR_ERR(it->it.page);
592
543 it->it.kaddr = kmap_atomic(it->it.page); 593 it->it.kaddr = kmap_atomic(it->it.page);
544 it->it.blkaddr = blkaddr; 594 it->it.blkaddr = blkaddr;
545 } 595 }
546 596
547 ret = xattr_foreach(&it->it, &list_xattr_handlers, NULL); 597 ret = xattr_foreach(&it->it, &list_xattr_handlers, NULL);
548 if (ret < 0) 598 if (ret)
549 break; 599 break;
550 } 600 }
551 if (vi->xattr_shared_count) 601 if (vi->xattr_shared_count)
552 xattr_iter_end(&it->it, true); 602 xattr_iter_end_final(&it->it);
553 603
554 return ret < 0 ? ret : it->buffer_ofs; 604 return ret ? ret : it->buffer_ofs;
555} 605}
556 606
557ssize_t erofs_listxattr(struct dentry *dentry, 607ssize_t erofs_listxattr(struct dentry *dentry,
@@ -560,7 +610,9 @@ ssize_t erofs_listxattr(struct dentry *dentry,
560 int ret; 610 int ret;
561 struct listxattr_iter it; 611 struct listxattr_iter it;
562 612
563 init_inode_xattrs(d_inode(dentry)); 613 ret = init_inode_xattrs(d_inode(dentry));
614 if (ret)
615 return ret;
564 616
565 it.dentry = dentry; 617 it.dentry = dentry;
566 it.buffer = buffer; 618 it.buffer = buffer;
diff --git a/drivers/staging/fbtft/fbtft.h b/drivers/staging/fbtft/fbtft.h
index 798a8fe98e95..ac427baa464a 100644
--- a/drivers/staging/fbtft/fbtft.h
+++ b/drivers/staging/fbtft/fbtft.h
@@ -232,7 +232,7 @@ struct fbtft_par {
232 bool polarity; 232 bool polarity;
233}; 233};
234 234
235#define NUMARGS(...) (sizeof((int[]){__VA_ARGS__})/sizeof(int)) 235#define NUMARGS(...) (sizeof((int[]){__VA_ARGS__}) / sizeof(int))
236 236
237#define write_reg(par, ...) \ 237#define write_reg(par, ...) \
238 ((par)->fbtftops.write_register(par, NUMARGS(__VA_ARGS__), __VA_ARGS__)) 238 ((par)->fbtftops.write_register(par, NUMARGS(__VA_ARGS__), __VA_ARGS__))
@@ -355,39 +355,39 @@ module_exit(fbtft_driver_module_exit);
355#define DEBUG_LEVEL_6 (DEBUG_LEVEL_4 | DEBUG_LEVEL_5) 355#define DEBUG_LEVEL_6 (DEBUG_LEVEL_4 | DEBUG_LEVEL_5)
356#define DEBUG_LEVEL_7 0xFFFFFFFF 356#define DEBUG_LEVEL_7 0xFFFFFFFF
357 357
358#define DEBUG_DRIVER_INIT_FUNCTIONS (1<<3) 358#define DEBUG_DRIVER_INIT_FUNCTIONS BIT(3)
359#define DEBUG_TIME_FIRST_UPDATE (1<<4) 359#define DEBUG_TIME_FIRST_UPDATE BIT(4)
360#define DEBUG_TIME_EACH_UPDATE (1<<5) 360#define DEBUG_TIME_EACH_UPDATE BIT(5)
361#define DEBUG_DEFERRED_IO (1<<6) 361#define DEBUG_DEFERRED_IO BIT(6)
362#define DEBUG_FBTFT_INIT_FUNCTIONS (1<<7) 362#define DEBUG_FBTFT_INIT_FUNCTIONS BIT(7)
363 363
364/* fbops */ 364/* fbops */
365#define DEBUG_FB_READ (1<<8) 365#define DEBUG_FB_READ BIT(8)
366#define DEBUG_FB_WRITE (1<<9) 366#define DEBUG_FB_WRITE BIT(9)
367#define DEBUG_FB_FILLRECT (1<<10) 367#define DEBUG_FB_FILLRECT BIT(10)
368#define DEBUG_FB_COPYAREA (1<<11) 368#define DEBUG_FB_COPYAREA BIT(11)
369#define DEBUG_FB_IMAGEBLIT (1<<12) 369#define DEBUG_FB_IMAGEBLIT BIT(12)
370#define DEBUG_FB_SETCOLREG (1<<13) 370#define DEBUG_FB_SETCOLREG BIT(13)
371#define DEBUG_FB_BLANK (1<<14) 371#define DEBUG_FB_BLANK BIT(14)
372 372
373#define DEBUG_SYSFS (1<<16) 373#define DEBUG_SYSFS BIT(16)
374 374
375/* fbtftops */ 375/* fbtftops */
376#define DEBUG_BACKLIGHT (1<<17) 376#define DEBUG_BACKLIGHT BIT(17)
377#define DEBUG_READ (1<<18) 377#define DEBUG_READ BIT(18)
378#define DEBUG_WRITE (1<<19) 378#define DEBUG_WRITE BIT(19)
379#define DEBUG_WRITE_VMEM (1<<20) 379#define DEBUG_WRITE_VMEM BIT(20)
380#define DEBUG_WRITE_REGISTER (1<<21) 380#define DEBUG_WRITE_REGISTER BIT(21)
381#define DEBUG_SET_ADDR_WIN (1<<22) 381#define DEBUG_SET_ADDR_WIN BIT(22)
382#define DEBUG_RESET (1<<23) 382#define DEBUG_RESET BIT(23)
383#define DEBUG_MKDIRTY (1<<24) 383#define DEBUG_MKDIRTY BIT(24)
384#define DEBUG_UPDATE_DISPLAY (1<<25) 384#define DEBUG_UPDATE_DISPLAY BIT(25)
385#define DEBUG_INIT_DISPLAY (1<<26) 385#define DEBUG_INIT_DISPLAY BIT(26)
386#define DEBUG_BLANK (1<<27) 386#define DEBUG_BLANK BIT(27)
387#define DEBUG_REQUEST_GPIOS (1<<28) 387#define DEBUG_REQUEST_GPIOS BIT(28)
388#define DEBUG_FREE_GPIOS (1<<29) 388#define DEBUG_FREE_GPIOS BIT(29)
389#define DEBUG_REQUEST_GPIOS_MATCH (1<<30) 389#define DEBUG_REQUEST_GPIOS_MATCH BIT(30)
390#define DEBUG_VERIFY_GPIOS (1<<31) 390#define DEBUG_VERIFY_GPIOS BIT(31)
391 391
392#define fbtft_init_dbg(dev, format, arg...) \ 392#define fbtft_init_dbg(dev, format, arg...) \
393do { \ 393do { \
diff --git a/drivers/staging/fsl-dpaa2/ethsw/ethsw.c b/drivers/staging/fsl-dpaa2/ethsw/ethsw.c
index ecdd3d84f956..7a7ca67822c5 100644
--- a/drivers/staging/fsl-dpaa2/ethsw/ethsw.c
+++ b/drivers/staging/fsl-dpaa2/ethsw/ethsw.c
@@ -717,7 +717,7 @@ static int port_vlans_add(struct net_device *netdev,
717 struct switchdev_trans *trans) 717 struct switchdev_trans *trans)
718{ 718{
719 struct ethsw_port_priv *port_priv = netdev_priv(netdev); 719 struct ethsw_port_priv *port_priv = netdev_priv(netdev);
720 int vid, err; 720 int vid, err = 0;
721 721
722 if (netif_is_bridge_master(vlan->obj.orig_dev)) 722 if (netif_is_bridge_master(vlan->obj.orig_dev))
723 return -EOPNOTSUPP; 723 return -EOPNOTSUPP;
@@ -872,7 +872,7 @@ static int port_vlans_del(struct net_device *netdev,
872 const struct switchdev_obj_port_vlan *vlan) 872 const struct switchdev_obj_port_vlan *vlan)
873{ 873{
874 struct ethsw_port_priv *port_priv = netdev_priv(netdev); 874 struct ethsw_port_priv *port_priv = netdev_priv(netdev);
875 int vid, err; 875 int vid, err = 0;
876 876
877 if (netif_is_bridge_master(vlan->obj.orig_dev)) 877 if (netif_is_bridge_master(vlan->obj.orig_dev))
878 return -EOPNOTSUPP; 878 return -EOPNOTSUPP;
@@ -1014,10 +1014,8 @@ static void ethsw_switchdev_event_work(struct work_struct *work)
1014 container_of(work, struct ethsw_switchdev_event_work, work); 1014 container_of(work, struct ethsw_switchdev_event_work, work);
1015 struct net_device *dev = switchdev_work->dev; 1015 struct net_device *dev = switchdev_work->dev;
1016 struct switchdev_notifier_fdb_info *fdb_info; 1016 struct switchdev_notifier_fdb_info *fdb_info;
1017 struct ethsw_port_priv *port_priv;
1018 1017
1019 rtnl_lock(); 1018 rtnl_lock();
1020 port_priv = netdev_priv(dev);
1021 fdb_info = &switchdev_work->fdb_info; 1019 fdb_info = &switchdev_work->fdb_info;
1022 1020
1023 switch (switchdev_work->event) { 1021 switch (switchdev_work->event) {
diff --git a/drivers/staging/gasket/Kconfig b/drivers/staging/gasket/Kconfig
index 970e299046c3..e82b85541f7e 100644
--- a/drivers/staging/gasket/Kconfig
+++ b/drivers/staging/gasket/Kconfig
@@ -14,8 +14,9 @@ config STAGING_APEX_DRIVER
14 tristate "Apex Driver" 14 tristate "Apex Driver"
15 depends on STAGING_GASKET_FRAMEWORK 15 depends on STAGING_GASKET_FRAMEWORK
16 help 16 help
17 This driver supports the Apex device. Say Y if you want to 17 This driver supports the Apex Edge TPU device. See
18 include this driver in the kernel. 18 https://cloud.google.com/edge-tpu/ for more information.
19 Say Y if you want to include this driver in the kernel.
19 20
20 To compile this driver as a module, choose M here. The module 21 To compile this driver as a module, choose M here. The module
21 will be called "apex". 22 will be called "apex".
diff --git a/drivers/staging/gasket/apex_driver.c b/drivers/staging/gasket/apex_driver.c
index c747e9ca4518..0578bf1ba1e9 100644
--- a/drivers/staging/gasket/apex_driver.c
+++ b/drivers/staging/gasket/apex_driver.c
@@ -138,9 +138,6 @@ static const struct gasket_mappable_region mappable_regions[NUM_REGIONS] = {
138 { 0x48000, 0x1000 }, 138 { 0x48000, 0x1000 },
139}; 139};
140 140
141static const struct gasket_mappable_region cm_mappable_regions[1] = { { 0x0,
142 APEX_CH_MEM_BYTES } };
143
144/* Gasket device interrupts enums must be dense (i.e., no empty slots). */ 141/* Gasket device interrupts enums must be dense (i.e., no empty slots). */
145enum apex_interrupt { 142enum apex_interrupt {
146 APEX_INTERRUPT_INSTR_QUEUE = 0, 143 APEX_INTERRUPT_INSTR_QUEUE = 0,
@@ -228,7 +225,6 @@ static struct gasket_interrupt_desc apex_interrupts[] = {
228 }, 225 },
229}; 226};
230 227
231
232/* Allows device to enter power save upon driver close(). */ 228/* Allows device to enter power save upon driver close(). */
233static int allow_power_save = 1; 229static int allow_power_save = 1;
234 230
@@ -529,7 +525,7 @@ static ssize_t sysfs_show(struct device *device, struct device_attribute *attr,
529 return -ENODEV; 525 return -ENODEV;
530 } 526 }
531 527
532 type = (enum sysfs_attribute_type)gasket_sysfs_get_attr(device, attr); 528 type = (enum sysfs_attribute_type)gasket_attr->data.attr_type;
533 switch (type) { 529 switch (type) {
534 case ATTR_KERNEL_HIB_PAGE_TABLE_SIZE: 530 case ATTR_KERNEL_HIB_PAGE_TABLE_SIZE:
535 ret = scnprintf(buf, PAGE_SIZE, "%u\n", 531 ret = scnprintf(buf, PAGE_SIZE, "%u\n",
diff --git a/drivers/staging/gasket/gasket_core.c b/drivers/staging/gasket/gasket_core.c
index d12ab560411f..a445d58fb399 100644
--- a/drivers/staging/gasket/gasket_core.c
+++ b/drivers/staging/gasket/gasket_core.c
@@ -109,8 +109,6 @@ check_and_invoke_callback(struct gasket_dev *gasket_dev,
109{ 109{
110 int ret = 0; 110 int ret = 0;
111 111
112 dev_dbg(gasket_dev->dev, "check_and_invoke_callback %p\n",
113 cb_function);
114 if (cb_function) { 112 if (cb_function) {
115 mutex_lock(&gasket_dev->mutex); 113 mutex_lock(&gasket_dev->mutex);
116 ret = cb_function(gasket_dev); 114 ret = cb_function(gasket_dev);
@@ -126,11 +124,8 @@ gasket_check_and_invoke_callback_nolock(struct gasket_dev *gasket_dev,
126{ 124{
127 int ret = 0; 125 int ret = 0;
128 126
129 if (cb_function) { 127 if (cb_function)
130 dev_dbg(gasket_dev->dev,
131 "Invoking device-specific callback.\n");
132 ret = cb_function(gasket_dev); 128 ret = cb_function(gasket_dev);
133 }
134 return ret; 129 return ret;
135} 130}
136 131
@@ -189,26 +184,26 @@ static int gasket_find_dev_slot(struct gasket_internal_desc *internal_desc,
189 * Returns 0 if successful, a negative error code otherwise. 184 * Returns 0 if successful, a negative error code otherwise.
190 */ 185 */
191static int gasket_alloc_dev(struct gasket_internal_desc *internal_desc, 186static int gasket_alloc_dev(struct gasket_internal_desc *internal_desc,
192 struct device *parent, struct gasket_dev **pdev, 187 struct device *parent, struct gasket_dev **pdev)
193 const char *kobj_name)
194{ 188{
195 int dev_idx; 189 int dev_idx;
196 const struct gasket_driver_desc *driver_desc = 190 const struct gasket_driver_desc *driver_desc =
197 internal_desc->driver_desc; 191 internal_desc->driver_desc;
198 struct gasket_dev *gasket_dev; 192 struct gasket_dev *gasket_dev;
199 struct gasket_cdev_info *dev_info; 193 struct gasket_cdev_info *dev_info;
194 const char *parent_name = dev_name(parent);
200 195
201 pr_debug("Allocating a Gasket device %s.\n", kobj_name); 196 pr_debug("Allocating a Gasket device, parent %s.\n", parent_name);
202 197
203 *pdev = NULL; 198 *pdev = NULL;
204 199
205 dev_idx = gasket_find_dev_slot(internal_desc, kobj_name); 200 dev_idx = gasket_find_dev_slot(internal_desc, parent_name);
206 if (dev_idx < 0) 201 if (dev_idx < 0)
207 return dev_idx; 202 return dev_idx;
208 203
209 gasket_dev = *pdev = kzalloc(sizeof(*gasket_dev), GFP_KERNEL); 204 gasket_dev = *pdev = kzalloc(sizeof(*gasket_dev), GFP_KERNEL);
210 if (!gasket_dev) { 205 if (!gasket_dev) {
211 pr_err("no memory for device %s\n", kobj_name); 206 pr_err("no memory for device, parent %s\n", parent_name);
212 return -ENOMEM; 207 return -ENOMEM;
213 } 208 }
214 internal_desc->devs[dev_idx] = gasket_dev; 209 internal_desc->devs[dev_idx] = gasket_dev;
@@ -217,7 +212,7 @@ static int gasket_alloc_dev(struct gasket_internal_desc *internal_desc,
217 212
218 gasket_dev->internal_desc = internal_desc; 213 gasket_dev->internal_desc = internal_desc;
219 gasket_dev->dev_idx = dev_idx; 214 gasket_dev->dev_idx = dev_idx;
220 snprintf(gasket_dev->kobj_name, GASKET_NAME_MAX, "%s", kobj_name); 215 snprintf(gasket_dev->kobj_name, GASKET_NAME_MAX, "%s", parent_name);
221 gasket_dev->dev = get_device(parent); 216 gasket_dev->dev = get_device(parent);
222 /* gasket_bar_data is uninitialized. */ 217 /* gasket_bar_data is uninitialized. */
223 gasket_dev->num_page_tables = driver_desc->num_page_tables; 218 gasket_dev->num_page_tables = driver_desc->num_page_tables;
@@ -231,10 +226,9 @@ static int gasket_alloc_dev(struct gasket_internal_desc *internal_desc,
231 dev_info->devt = 226 dev_info->devt =
232 MKDEV(driver_desc->major, driver_desc->minor + 227 MKDEV(driver_desc->major, driver_desc->minor +
233 gasket_dev->dev_idx); 228 gasket_dev->dev_idx);
234 dev_info->device = device_create(internal_desc->class, parent, 229 dev_info->device =
235 dev_info->devt, gasket_dev, dev_info->name); 230 device_create(internal_desc->class, parent, dev_info->devt,
236 231 gasket_dev, dev_info->name);
237 dev_dbg(dev_info->device, "Gasket device allocated.\n");
238 232
239 /* cdev has not yet been added; cdev_added is 0 */ 233 /* cdev has not yet been added; cdev_added is 0 */
240 dev_info->gasket_dev_ptr = gasket_dev; 234 dev_info->gasket_dev_ptr = gasket_dev;
@@ -652,13 +646,13 @@ void gasket_disable_device(struct gasket_dev *gasket_dev)
652EXPORT_SYMBOL(gasket_disable_device); 646EXPORT_SYMBOL(gasket_disable_device);
653 647
654/* 648/*
655 * Registered descriptor lookup. 649 * Registered driver descriptor lookup for PCI devices.
656 * 650 *
657 * Precondition: Called with g_mutex held (to avoid a race on return). 651 * Precondition: Called with g_mutex held (to avoid a race on return).
658 * Returns NULL if no matching device was found. 652 * Returns NULL if no matching device was found.
659 */ 653 */
660static struct gasket_internal_desc * 654static struct gasket_internal_desc *
661lookup_internal_desc(struct pci_dev *pci_dev) 655lookup_pci_internal_desc(struct pci_dev *pci_dev)
662{ 656{
663 int i; 657 int i;
664 658
@@ -1358,13 +1352,7 @@ int gasket_enable_device(struct gasket_dev *gasket_dev)
1358 const struct gasket_driver_desc *driver_desc = 1352 const struct gasket_driver_desc *driver_desc =
1359 gasket_dev->internal_desc->driver_desc; 1353 gasket_dev->internal_desc->driver_desc;
1360 1354
1361 ret = gasket_interrupt_init(gasket_dev, driver_desc->name, 1355 ret = gasket_interrupt_init(gasket_dev);
1362 driver_desc->interrupt_type,
1363 driver_desc->interrupts,
1364 driver_desc->num_interrupts,
1365 driver_desc->interrupt_pack_width,
1366 driver_desc->interrupt_bar_index,
1367 driver_desc->wire_interrupt_offsets);
1368 if (ret) { 1356 if (ret) {
1369 dev_err(gasket_dev->dev, 1357 dev_err(gasket_dev->dev,
1370 "Critical failure to allocate interrupts: %d\n", ret); 1358 "Critical failure to allocate interrupts: %d\n", ret);
@@ -1420,6 +1408,56 @@ int gasket_enable_device(struct gasket_dev *gasket_dev)
1420} 1408}
1421EXPORT_SYMBOL(gasket_enable_device); 1409EXPORT_SYMBOL(gasket_enable_device);
1422 1410
1411static int __gasket_add_device(struct device *parent_dev,
1412 struct gasket_internal_desc *internal_desc,
1413 struct gasket_dev **gasket_devp)
1414{
1415 int ret;
1416 struct gasket_dev *gasket_dev;
1417 const struct gasket_driver_desc *driver_desc =
1418 internal_desc->driver_desc;
1419
1420 ret = gasket_alloc_dev(internal_desc, parent_dev, &gasket_dev);
1421 if (ret)
1422 return ret;
1423 if (IS_ERR(gasket_dev->dev_info.device)) {
1424 dev_err(parent_dev, "Cannot create %s device %s [ret = %ld]\n",
1425 driver_desc->name, gasket_dev->dev_info.name,
1426 PTR_ERR(gasket_dev->dev_info.device));
1427 ret = -ENODEV;
1428 goto free_gasket_dev;
1429 }
1430
1431 ret = gasket_sysfs_create_mapping(gasket_dev->dev_info.device,
1432 gasket_dev);
1433 if (ret)
1434 goto remove_device;
1435
1436 ret = gasket_sysfs_create_entries(gasket_dev->dev_info.device,
1437 gasket_sysfs_generic_attrs);
1438 if (ret)
1439 goto remove_sysfs_mapping;
1440
1441 *gasket_devp = gasket_dev;
1442 return 0;
1443
1444remove_sysfs_mapping:
1445 gasket_sysfs_remove_mapping(gasket_dev->dev_info.device);
1446remove_device:
1447 device_destroy(internal_desc->class, gasket_dev->dev_info.devt);
1448free_gasket_dev:
1449 gasket_free_dev(gasket_dev);
1450 return ret;
1451}
1452
1453static void __gasket_remove_device(struct gasket_internal_desc *internal_desc,
1454 struct gasket_dev *gasket_dev)
1455{
1456 gasket_sysfs_remove_mapping(gasket_dev->dev_info.device);
1457 device_destroy(internal_desc->class, gasket_dev->dev_info.devt);
1458 gasket_free_dev(gasket_dev);
1459}
1460
1423/* 1461/*
1424 * Add PCI gasket device. 1462 * Add PCI gasket device.
1425 * 1463 *
@@ -1432,16 +1470,14 @@ int gasket_pci_add_device(struct pci_dev *pci_dev,
1432 struct gasket_dev **gasket_devp) 1470 struct gasket_dev **gasket_devp)
1433{ 1471{
1434 int ret; 1472 int ret;
1435 const char *kobj_name = dev_name(&pci_dev->dev);
1436 struct gasket_internal_desc *internal_desc; 1473 struct gasket_internal_desc *internal_desc;
1437 struct gasket_dev *gasket_dev; 1474 struct gasket_dev *gasket_dev;
1438 const struct gasket_driver_desc *driver_desc;
1439 struct device *parent; 1475 struct device *parent;
1440 1476
1441 pr_debug("add PCI device %s\n", kobj_name); 1477 dev_dbg(&pci_dev->dev, "add PCI gasket device\n");
1442 1478
1443 mutex_lock(&g_mutex); 1479 mutex_lock(&g_mutex);
1444 internal_desc = lookup_internal_desc(pci_dev); 1480 internal_desc = lookup_pci_internal_desc(pci_dev);
1445 mutex_unlock(&g_mutex); 1481 mutex_unlock(&g_mutex);
1446 if (!internal_desc) { 1482 if (!internal_desc) {
1447 dev_err(&pci_dev->dev, 1483 dev_err(&pci_dev->dev,
@@ -1449,29 +1485,15 @@ int gasket_pci_add_device(struct pci_dev *pci_dev,
1449 return -ENODEV; 1485 return -ENODEV;
1450 } 1486 }
1451 1487
1452 driver_desc = internal_desc->driver_desc;
1453
1454 parent = &pci_dev->dev; 1488 parent = &pci_dev->dev;
1455 ret = gasket_alloc_dev(internal_desc, parent, &gasket_dev, kobj_name); 1489 ret = __gasket_add_device(parent, internal_desc, &gasket_dev);
1456 if (ret) 1490 if (ret)
1457 return ret; 1491 return ret;
1458 gasket_dev->pci_dev = pci_dev;
1459 if (IS_ERR_OR_NULL(gasket_dev->dev_info.device)) {
1460 pr_err("Cannot create %s device %s [ret = %ld]\n",
1461 driver_desc->name, gasket_dev->dev_info.name,
1462 PTR_ERR(gasket_dev->dev_info.device));
1463 ret = -ENODEV;
1464 goto fail1;
1465 }
1466 1492
1493 gasket_dev->pci_dev = pci_dev;
1467 ret = gasket_setup_pci(pci_dev, gasket_dev); 1494 ret = gasket_setup_pci(pci_dev, gasket_dev);
1468 if (ret) 1495 if (ret)
1469 goto fail2; 1496 goto cleanup_pci;
1470
1471 ret = gasket_sysfs_create_mapping(gasket_dev->dev_info.device,
1472 gasket_dev);
1473 if (ret)
1474 goto fail3;
1475 1497
1476 /* 1498 /*
1477 * Once we've created the mapping structures successfully, attempt to 1499 * Once we've created the mapping structures successfully, attempt to
@@ -1482,24 +1504,15 @@ int gasket_pci_add_device(struct pci_dev *pci_dev,
1482 if (ret) { 1504 if (ret) {
1483 dev_err(gasket_dev->dev, 1505 dev_err(gasket_dev->dev,
1484 "Cannot create sysfs pci link: %d\n", ret); 1506 "Cannot create sysfs pci link: %d\n", ret);
1485 goto fail3; 1507 goto cleanup_pci;
1486 } 1508 }
1487 ret = gasket_sysfs_create_entries(gasket_dev->dev_info.device,
1488 gasket_sysfs_generic_attrs);
1489 if (ret)
1490 goto fail4;
1491 1509
1492 *gasket_devp = gasket_dev; 1510 *gasket_devp = gasket_dev;
1493 return 0; 1511 return 0;
1494 1512
1495fail4: 1513cleanup_pci:
1496fail3:
1497 gasket_sysfs_remove_mapping(gasket_dev->dev_info.device);
1498fail2:
1499 gasket_cleanup_pci(gasket_dev); 1514 gasket_cleanup_pci(gasket_dev);
1500 device_destroy(internal_desc->class, gasket_dev->dev_info.devt); 1515 __gasket_remove_device(internal_desc, gasket_dev);
1501fail1:
1502 gasket_free_dev(gasket_dev);
1503 return ret; 1516 return ret;
1504} 1517}
1505EXPORT_SYMBOL(gasket_pci_add_device); 1518EXPORT_SYMBOL(gasket_pci_add_device);
@@ -1510,18 +1523,15 @@ void gasket_pci_remove_device(struct pci_dev *pci_dev)
1510 int i; 1523 int i;
1511 struct gasket_internal_desc *internal_desc; 1524 struct gasket_internal_desc *internal_desc;
1512 struct gasket_dev *gasket_dev = NULL; 1525 struct gasket_dev *gasket_dev = NULL;
1513 const struct gasket_driver_desc *driver_desc;
1514 /* Find the device desc. */ 1526 /* Find the device desc. */
1515 mutex_lock(&g_mutex); 1527 mutex_lock(&g_mutex);
1516 internal_desc = lookup_internal_desc(pci_dev); 1528 internal_desc = lookup_pci_internal_desc(pci_dev);
1517 if (!internal_desc) { 1529 if (!internal_desc) {
1518 mutex_unlock(&g_mutex); 1530 mutex_unlock(&g_mutex);
1519 return; 1531 return;
1520 } 1532 }
1521 mutex_unlock(&g_mutex); 1533 mutex_unlock(&g_mutex);
1522 1534
1523 driver_desc = internal_desc->driver_desc;
1524
1525 /* Now find the specific device */ 1535 /* Now find the specific device */
1526 mutex_lock(&internal_desc->mutex); 1536 mutex_lock(&internal_desc->mutex);
1527 for (i = 0; i < GASKET_DEV_MAX; i++) { 1537 for (i = 0; i < GASKET_DEV_MAX; i++) {
@@ -1540,10 +1550,7 @@ void gasket_pci_remove_device(struct pci_dev *pci_dev)
1540 internal_desc->driver_desc->name); 1550 internal_desc->driver_desc->name);
1541 1551
1542 gasket_cleanup_pci(gasket_dev); 1552 gasket_cleanup_pci(gasket_dev);
1543 1553 __gasket_remove_device(internal_desc, gasket_dev);
1544 gasket_sysfs_remove_mapping(gasket_dev->dev_info.device);
1545 device_destroy(internal_desc->class, gasket_dev->dev_info.devt);
1546 gasket_free_dev(gasket_dev);
1547} 1554}
1548EXPORT_SYMBOL(gasket_pci_remove_device); 1555EXPORT_SYMBOL(gasket_pci_remove_device);
1549 1556
@@ -1791,7 +1798,6 @@ static int __init gasket_init(void)
1791{ 1798{
1792 int i; 1799 int i;
1793 1800
1794 pr_debug("%s\n", __func__);
1795 mutex_lock(&g_mutex); 1801 mutex_lock(&g_mutex);
1796 for (i = 0; i < GASKET_FRAMEWORK_DESC_MAX; i++) { 1802 for (i = 0; i < GASKET_FRAMEWORK_DESC_MAX; i++) {
1797 g_descs[i].driver_desc = NULL; 1803 g_descs[i].driver_desc = NULL;
@@ -1804,13 +1810,8 @@ static int __init gasket_init(void)
1804 return 0; 1810 return 0;
1805} 1811}
1806 1812
1807static void __exit gasket_exit(void)
1808{
1809 pr_debug("%s\n", __func__);
1810}
1811MODULE_DESCRIPTION("Google Gasket driver framework"); 1813MODULE_DESCRIPTION("Google Gasket driver framework");
1812MODULE_VERSION(GASKET_FRAMEWORK_VERSION); 1814MODULE_VERSION(GASKET_FRAMEWORK_VERSION);
1813MODULE_LICENSE("GPL v2"); 1815MODULE_LICENSE("GPL v2");
1814MODULE_AUTHOR("Rob Springer <rspringer@google.com>"); 1816MODULE_AUTHOR("Rob Springer <rspringer@google.com>");
1815module_init(gasket_init); 1817module_init(gasket_init);
1816module_exit(gasket_exit);
diff --git a/drivers/staging/gasket/gasket_core.h b/drivers/staging/gasket/gasket_core.h
index 275fd0b345b6..be44ac1e3118 100644
--- a/drivers/staging/gasket/gasket_core.h
+++ b/drivers/staging/gasket/gasket_core.h
@@ -50,8 +50,6 @@ enum gasket_interrupt_packing {
50/* Type of the interrupt supported by the device. */ 50/* Type of the interrupt supported by the device. */
51enum gasket_interrupt_type { 51enum gasket_interrupt_type {
52 PCI_MSIX = 0, 52 PCI_MSIX = 0,
53 PCI_MSI = 1,
54 PLATFORM_WIRE = 2,
55}; 53};
56 54
57/* 55/*
@@ -69,12 +67,6 @@ struct gasket_interrupt_desc {
69 int packing; 67 int packing;
70}; 68};
71 69
72/* Offsets to the wire interrupt handling registers */
73struct gasket_wire_interrupt_offsets {
74 u64 pending_bit_array;
75 u64 mask_array;
76};
77
78/* 70/*
79 * This enum is used to identify memory regions being part of the physical 71 * This enum is used to identify memory regions being part of the physical
80 * memory that belongs to a device. 72 * memory that belongs to a device.
@@ -231,7 +223,7 @@ struct gasket_coherent_buffer_desc {
231/* Coherent buffer structure. */ 223/* Coherent buffer structure. */
232struct gasket_coherent_buffer { 224struct gasket_coherent_buffer {
233 /* Virtual base address. */ 225 /* Virtual base address. */
234 u8 __iomem *virt_base; 226 u8 *virt_base;
235 227
236 /* Physical base address. */ 228 /* Physical base address. */
237 ulong phys_base; 229 ulong phys_base;
@@ -384,9 +376,6 @@ struct gasket_driver_desc {
384 */ 376 */
385 struct gasket_coherent_buffer_desc coherent_buffer_description; 377 struct gasket_coherent_buffer_desc coherent_buffer_description;
386 378
387 /* Offset of wire interrupt registers. */
388 const struct gasket_wire_interrupt_offsets *wire_interrupt_offsets;
389
390 /* Interrupt type. (One of gasket_interrupt_type). */ 379 /* Interrupt type. (One of gasket_interrupt_type). */
391 int interrupt_type; 380 int interrupt_type;
392 381
@@ -590,25 +579,25 @@ const char *gasket_num_name_lookup(uint num,
590static inline ulong gasket_dev_read_64(struct gasket_dev *gasket_dev, int bar, 579static inline ulong gasket_dev_read_64(struct gasket_dev *gasket_dev, int bar,
591 ulong location) 580 ulong location)
592{ 581{
593 return readq(&gasket_dev->bar_data[bar].virt_base[location]); 582 return readq_relaxed(&gasket_dev->bar_data[bar].virt_base[location]);
594} 583}
595 584
596static inline void gasket_dev_write_64(struct gasket_dev *dev, u64 value, 585static inline void gasket_dev_write_64(struct gasket_dev *dev, u64 value,
597 int bar, ulong location) 586 int bar, ulong location)
598{ 587{
599 writeq(value, &dev->bar_data[bar].virt_base[location]); 588 writeq_relaxed(value, &dev->bar_data[bar].virt_base[location]);
600} 589}
601 590
602static inline void gasket_dev_write_32(struct gasket_dev *dev, u32 value, 591static inline void gasket_dev_write_32(struct gasket_dev *dev, u32 value,
603 int bar, ulong location) 592 int bar, ulong location)
604{ 593{
605 writel(value, &dev->bar_data[bar].virt_base[location]); 594 writel_relaxed(value, &dev->bar_data[bar].virt_base[location]);
606} 595}
607 596
608static inline u32 gasket_dev_read_32(struct gasket_dev *dev, int bar, 597static inline u32 gasket_dev_read_32(struct gasket_dev *dev, int bar,
609 ulong location) 598 ulong location)
610{ 599{
611 return readl(&dev->bar_data[bar].virt_base[location]); 600 return readl_relaxed(&dev->bar_data[bar].virt_base[location]);
612} 601}
613 602
614static inline void gasket_read_modify_write_64(struct gasket_dev *dev, int bar, 603static inline void gasket_read_modify_write_64(struct gasket_dev *dev, int bar,
diff --git a/drivers/staging/gasket/gasket_interrupt.c b/drivers/staging/gasket/gasket_interrupt.c
index 1cfbc120f228..49d47afad64f 100644
--- a/drivers/staging/gasket/gasket_interrupt.c
+++ b/drivers/staging/gasket/gasket_interrupt.c
@@ -45,9 +45,6 @@ struct gasket_interrupt_data {
45 /* The width of a single interrupt in a packed interrupt register. */ 45 /* The width of a single interrupt in a packed interrupt register. */
46 int pack_width; 46 int pack_width;
47 47
48 /* offset of wire interrupt registers */
49 const struct gasket_wire_interrupt_offsets *wire_interrupt_offsets;
50
51 /* 48 /*
52 * Design-wise, these elements should be bundled together, but 49 * Design-wise, these elements should be bundled together, but
53 * pci_enable_msix's interface requires that they be managed 50 * pci_enable_msix's interface requires that they be managed
@@ -92,19 +89,6 @@ static void gasket_interrupt_setup(struct gasket_dev *gasket_dev)
92 89
93 dev_dbg(gasket_dev->dev, "Running interrupt setup\n"); 90 dev_dbg(gasket_dev->dev, "Running interrupt setup\n");
94 91
95 if (interrupt_data->type == PLATFORM_WIRE ||
96 interrupt_data->type == PCI_MSI) {
97 /* Nothing needs to be done for platform or PCI devices. */
98 return;
99 }
100
101 if (interrupt_data->type != PCI_MSIX) {
102 dev_dbg(gasket_dev->dev,
103 "Cannot handle unsupported interrupt type %d\n",
104 interrupt_data->type);
105 return;
106 }
107
108 /* Setup the MSIX table. */ 92 /* Setup the MSIX table. */
109 93
110 for (i = 0; i < interrupt_data->num_interrupts; i++) { 94 for (i = 0; i < interrupt_data->num_interrupts; i++) {
@@ -157,9 +141,22 @@ static void gasket_interrupt_setup(struct gasket_dev *gasket_dev)
157 } 141 }
158} 142}
159 143
160static irqreturn_t gasket_msix_interrupt_handler(int irq, void *dev_id) 144static void
145gasket_handle_interrupt(struct gasket_interrupt_data *interrupt_data,
146 int interrupt_index)
161{ 147{
162 struct eventfd_ctx *ctx; 148 struct eventfd_ctx *ctx;
149
150 trace_gasket_interrupt_event(interrupt_data->name, interrupt_index);
151 ctx = interrupt_data->eventfd_ctxs[interrupt_index];
152 if (ctx)
153 eventfd_signal(ctx, 1);
154
155 ++(interrupt_data->interrupt_counts[interrupt_index]);
156}
157
158static irqreturn_t gasket_msix_interrupt_handler(int irq, void *dev_id)
159{
163 struct gasket_interrupt_data *interrupt_data = dev_id; 160 struct gasket_interrupt_data *interrupt_data = dev_id;
164 int interrupt = -1; 161 int interrupt = -1;
165 int i; 162 int i;
@@ -175,14 +172,7 @@ static irqreturn_t gasket_msix_interrupt_handler(int irq, void *dev_id)
175 pr_err("Received unknown irq %d\n", irq); 172 pr_err("Received unknown irq %d\n", irq);
176 return IRQ_HANDLED; 173 return IRQ_HANDLED;
177 } 174 }
178 trace_gasket_interrupt_event(interrupt_data->name, interrupt); 175 gasket_handle_interrupt(interrupt_data, interrupt);
179
180 ctx = interrupt_data->eventfd_ctxs[interrupt];
181 if (ctx)
182 eventfd_signal(ctx, 1);
183
184 ++(interrupt_data->interrupt_counts[interrupt]);
185
186 return IRQ_HANDLED; 176 return IRQ_HANDLED;
187} 177}
188 178
@@ -192,6 +182,12 @@ gasket_interrupt_msix_init(struct gasket_interrupt_data *interrupt_data)
192 int ret = 1; 182 int ret = 1;
193 int i; 183 int i;
194 184
185 interrupt_data->msix_entries =
186 kcalloc(interrupt_data->num_interrupts,
187 sizeof(struct msix_entry), GFP_KERNEL);
188 if (!interrupt_data->msix_entries)
189 return -ENOMEM;
190
195 for (i = 0; i < interrupt_data->num_interrupts; i++) { 191 for (i = 0; i < interrupt_data->num_interrupts; i++) {
196 interrupt_data->msix_entries[i].entry = i; 192 interrupt_data->msix_entries[i].entry = i;
197 interrupt_data->msix_entries[i].vector = 0; 193 interrupt_data->msix_entries[i].vector = 0;
@@ -319,54 +315,40 @@ static struct gasket_sysfs_attribute interrupt_sysfs_attrs[] = {
319 GASKET_END_OF_ATTR_ARRAY, 315 GASKET_END_OF_ATTR_ARRAY,
320}; 316};
321 317
322int gasket_interrupt_init(struct gasket_dev *gasket_dev, const char *name, 318int gasket_interrupt_init(struct gasket_dev *gasket_dev)
323 int type,
324 const struct gasket_interrupt_desc *interrupts,
325 int num_interrupts, int pack_width, int bar_index,
326 const struct gasket_wire_interrupt_offsets *wire_int_offsets)
327{ 319{
328 int ret; 320 int ret;
329 struct gasket_interrupt_data *interrupt_data; 321 struct gasket_interrupt_data *interrupt_data;
322 const struct gasket_driver_desc *driver_desc =
323 gasket_get_driver_desc(gasket_dev);
330 324
331 interrupt_data = kzalloc(sizeof(struct gasket_interrupt_data), 325 interrupt_data = kzalloc(sizeof(struct gasket_interrupt_data),
332 GFP_KERNEL); 326 GFP_KERNEL);
333 if (!interrupt_data) 327 if (!interrupt_data)
334 return -ENOMEM; 328 return -ENOMEM;
335 gasket_dev->interrupt_data = interrupt_data; 329 gasket_dev->interrupt_data = interrupt_data;
336 interrupt_data->name = name; 330 interrupt_data->name = driver_desc->name;
337 interrupt_data->type = type; 331 interrupt_data->type = driver_desc->interrupt_type;
338 interrupt_data->pci_dev = gasket_dev->pci_dev; 332 interrupt_data->pci_dev = gasket_dev->pci_dev;
339 interrupt_data->num_interrupts = num_interrupts; 333 interrupt_data->num_interrupts = driver_desc->num_interrupts;
340 interrupt_data->interrupts = interrupts; 334 interrupt_data->interrupts = driver_desc->interrupts;
341 interrupt_data->interrupt_bar_index = bar_index; 335 interrupt_data->interrupt_bar_index = driver_desc->interrupt_bar_index;
342 interrupt_data->pack_width = pack_width; 336 interrupt_data->pack_width = driver_desc->interrupt_pack_width;
343 interrupt_data->num_configured = 0; 337 interrupt_data->num_configured = 0;
344 interrupt_data->wire_interrupt_offsets = wire_int_offsets;
345 338
346 /* Allocate all dynamic structures. */ 339 interrupt_data->eventfd_ctxs = kcalloc(driver_desc->num_interrupts,
347 interrupt_data->msix_entries = kcalloc(num_interrupts,
348 sizeof(struct msix_entry),
349 GFP_KERNEL);
350 if (!interrupt_data->msix_entries) {
351 kfree(interrupt_data);
352 return -ENOMEM;
353 }
354
355 interrupt_data->eventfd_ctxs = kcalloc(num_interrupts,
356 sizeof(struct eventfd_ctx *), 340 sizeof(struct eventfd_ctx *),
357 GFP_KERNEL); 341 GFP_KERNEL);
358 if (!interrupt_data->eventfd_ctxs) { 342 if (!interrupt_data->eventfd_ctxs) {
359 kfree(interrupt_data->msix_entries);
360 kfree(interrupt_data); 343 kfree(interrupt_data);
361 return -ENOMEM; 344 return -ENOMEM;
362 } 345 }
363 346
364 interrupt_data->interrupt_counts = kcalloc(num_interrupts, 347 interrupt_data->interrupt_counts = kcalloc(driver_desc->num_interrupts,
365 sizeof(ulong), 348 sizeof(ulong),
366 GFP_KERNEL); 349 GFP_KERNEL);
367 if (!interrupt_data->interrupt_counts) { 350 if (!interrupt_data->interrupt_counts) {
368 kfree(interrupt_data->eventfd_ctxs); 351 kfree(interrupt_data->eventfd_ctxs);
369 kfree(interrupt_data->msix_entries);
370 kfree(interrupt_data); 352 kfree(interrupt_data);
371 return -ENOMEM; 353 return -ENOMEM;
372 } 354 }
@@ -379,12 +361,7 @@ int gasket_interrupt_init(struct gasket_dev *gasket_dev, const char *name,
379 force_msix_interrupt_unmasking(gasket_dev); 361 force_msix_interrupt_unmasking(gasket_dev);
380 break; 362 break;
381 363
382 case PCI_MSI:
383 case PLATFORM_WIRE:
384 default: 364 default:
385 dev_err(gasket_dev->dev,
386 "Cannot handle unsupported interrupt type %d\n",
387 interrupt_data->type);
388 ret = -EINVAL; 365 ret = -EINVAL;
389 } 366 }
390 367
@@ -417,6 +394,7 @@ gasket_interrupt_msix_cleanup(struct gasket_interrupt_data *interrupt_data)
417 if (interrupt_data->msix_configured) 394 if (interrupt_data->msix_configured)
418 pci_disable_msix(interrupt_data->pci_dev); 395 pci_disable_msix(interrupt_data->pci_dev);
419 interrupt_data->msix_configured = 0; 396 interrupt_data->msix_configured = 0;
397 kfree(interrupt_data->msix_entries);
420} 398}
421 399
422int gasket_interrupt_reinit(struct gasket_dev *gasket_dev) 400int gasket_interrupt_reinit(struct gasket_dev *gasket_dev)
@@ -438,20 +416,16 @@ int gasket_interrupt_reinit(struct gasket_dev *gasket_dev)
438 force_msix_interrupt_unmasking(gasket_dev); 416 force_msix_interrupt_unmasking(gasket_dev);
439 break; 417 break;
440 418
441 case PCI_MSI:
442 case PLATFORM_WIRE:
443 default: 419 default:
444 dev_dbg(gasket_dev->dev,
445 "Cannot handle unsupported interrupt type %d\n",
446 gasket_dev->interrupt_data->type);
447 ret = -EINVAL; 420 ret = -EINVAL;
448 } 421 }
449 422
450 if (ret) { 423 if (ret) {
451 /* Failing to setup MSIx will cause the device 424 /* Failing to setup interrupts will cause the device
452 * to report GASKET_STATUS_LAMED, but is not fatal. 425 * to report GASKET_STATUS_LAMED, but is not fatal.
453 */ 426 */
454 dev_warn(gasket_dev->dev, "Couldn't init msix: %d\n", ret); 427 dev_warn(gasket_dev->dev, "Couldn't reinit interrupts: %d\n",
428 ret);
455 return 0; 429 return 0;
456 } 430 }
457 431
@@ -487,17 +461,12 @@ void gasket_interrupt_cleanup(struct gasket_dev *gasket_dev)
487 gasket_interrupt_msix_cleanup(interrupt_data); 461 gasket_interrupt_msix_cleanup(interrupt_data);
488 break; 462 break;
489 463
490 case PCI_MSI:
491 case PLATFORM_WIRE:
492 default: 464 default:
493 dev_dbg(gasket_dev->dev, 465 break;
494 "Cannot handle unsupported interrupt type %d\n",
495 interrupt_data->type);
496 } 466 }
497 467
498 kfree(interrupt_data->interrupt_counts); 468 kfree(interrupt_data->interrupt_counts);
499 kfree(interrupt_data->eventfd_ctxs); 469 kfree(interrupt_data->eventfd_ctxs);
500 kfree(interrupt_data->msix_entries);
501 kfree(interrupt_data); 470 kfree(interrupt_data);
502 gasket_dev->interrupt_data = NULL; 471 gasket_dev->interrupt_data = NULL;
503} 472}
@@ -509,11 +478,6 @@ int gasket_interrupt_system_status(struct gasket_dev *gasket_dev)
509 return GASKET_STATUS_DEAD; 478 return GASKET_STATUS_DEAD;
510 } 479 }
511 480
512 if (!gasket_dev->interrupt_data->msix_configured) {
513 dev_dbg(gasket_dev->dev, "Interrupt not initialized\n");
514 return GASKET_STATUS_LAMED;
515 }
516
517 if (gasket_dev->interrupt_data->num_configured != 481 if (gasket_dev->interrupt_data->num_configured !=
518 gasket_dev->interrupt_data->num_interrupts) { 482 gasket_dev->interrupt_data->num_interrupts) {
519 dev_dbg(gasket_dev->dev, 483 dev_dbg(gasket_dev->dev,
diff --git a/drivers/staging/gasket/gasket_interrupt.h b/drivers/staging/gasket/gasket_interrupt.h
index 835af439e96a..85526a1374a1 100644
--- a/drivers/staging/gasket/gasket_interrupt.h
+++ b/drivers/staging/gasket/gasket_interrupt.h
@@ -24,30 +24,8 @@ struct gasket_interrupt_data;
24/* 24/*
25 * Initialize the interrupt module. 25 * Initialize the interrupt module.
26 * @gasket_dev: The Gasket device structure for the device to be initted. 26 * @gasket_dev: The Gasket device structure for the device to be initted.
27 * @type: Type of the interrupt. (See gasket_interrupt_type).
28 * @name: The name to associate with these interrupts.
29 * @interrupts: An array of all interrupt descriptions for this device.
30 * @num_interrupts: The length of the @interrupts array.
31 * @pack_width: The width, in bits, of a single field in a packed interrupt reg.
32 * @bar_index: The bar containing all interrupt registers.
33 *
34 * Allocates and initializes data to track interrupt state for a device.
35 * After this call, no interrupts will be configured/delivered; call
36 * gasket_interrupt_set_vector[_packed] to associate each interrupt with an
37 * __iomem location, then gasket_interrupt_set_eventfd to associate an eventfd
38 * with an interrupt.
39 *
40 * If num_interrupts interrupts are not available, this call will return a
41 * negative error code. In that case, gasket_interrupt_cleanup should still be
42 * called. Returns 0 on success (which can include a device where interrupts
43 * are not possible to set up, but is otherwise OK; that device will report
44 * status LAMED.)
45 */ 27 */
46int gasket_interrupt_init(struct gasket_dev *gasket_dev, const char *name, 28int gasket_interrupt_init(struct gasket_dev *gasket_dev);
47 int type,
48 const struct gasket_interrupt_desc *interrupts,
49 int num_interrupts, int pack_width, int bar_index,
50 const struct gasket_wire_interrupt_offsets *wire_int_offsets);
51 29
52/* 30/*
53 * Clean up a device's interrupt structure. 31 * Clean up a device's interrupt structure.
diff --git a/drivers/staging/gasket/gasket_page_table.c b/drivers/staging/gasket/gasket_page_table.c
index d4c5f8aa7dd3..b7d460cf15fb 100644
--- a/drivers/staging/gasket/gasket_page_table.c
+++ b/drivers/staging/gasket/gasket_page_table.c
@@ -10,10 +10,18 @@
10 * 10 *
11 * This file assumes 4kB pages throughout; can be factored out when necessary. 11 * This file assumes 4kB pages throughout; can be factored out when necessary.
12 * 12 *
13 * Address format is as follows: 13 * There is a configurable number of page table entries, as well as a
14 * configurable bit index for the extended address flag. Both of these are
15 * specified in gasket_page_table_init through the page_table_config parameter.
16 *
17 * The following example assumes:
18 * page_table_config->total_entries = 8192
19 * page_table_config->extended_bit = 63
20 *
21 * Address format:
14 * Simple addresses - those whose containing pages are directly placed in the 22 * Simple addresses - those whose containing pages are directly placed in the
15 * device's address translation registers - are laid out as: 23 * device's address translation registers - are laid out as:
16 * [ 63 - 40: Unused | 39 - 28: 0 | 27 - 12: page index | 11 - 0: page offset ] 24 * [ 63 - 25: 0 | 24 - 12: page index | 11 - 0: page offset ]
17 * page index: The index of the containing page in the device's address 25 * page index: The index of the containing page in the device's address
18 * translation registers. 26 * translation registers.
19 * page offset: The index of the address into the containing page. 27 * page offset: The index of the address into the containing page.
@@ -21,7 +29,7 @@
21 * Extended address - those whose containing pages are contained in a second- 29 * Extended address - those whose containing pages are contained in a second-
22 * level page table whose address is present in the device's address translation 30 * level page table whose address is present in the device's address translation
23 * registers - are laid out as: 31 * registers - are laid out as:
24 * [ 63 - 40: Unused | 39: flag | 38 - 37: 0 | 36 - 21: dev/level 0 index | 32 * [ 63: flag | 62 - 34: 0 | 33 - 21: dev/level 0 index |
25 * 20 - 12: host/level 1 index | 11 - 0: page offset ] 33 * 20 - 12: host/level 1 index | 11 - 0: page offset ]
26 * flag: Marker indicating that this is an extended address. Always 1. 34 * flag: Marker indicating that this is an extended address. Always 1.
27 * dev index: The index of the first-level page in the device's extended 35 * dev index: The index of the first-level page in the device's extended
@@ -103,12 +111,6 @@ struct gasket_page_table_entry {
103 /* The status of this entry/slot: free or in use. */ 111 /* The status of this entry/slot: free or in use. */
104 enum pte_status status; 112 enum pte_status status;
105 113
106 /* Address of the page in DMA space. */
107 dma_addr_t dma_addr;
108
109 /* Linux page descriptor for the page described by this structure. */
110 struct page *page;
111
112 /* 114 /*
113 * Index for alignment into host vaddrs. 115 * Index for alignment into host vaddrs.
114 * When a user specifies a host address for a mapping, that address may 116 * When a user specifies a host address for a mapping, that address may
@@ -119,6 +121,12 @@ struct gasket_page_table_entry {
119 */ 121 */
120 int offset; 122 int offset;
121 123
124 /* Address of the page in DMA space. */
125 dma_addr_t dma_addr;
126
127 /* Linux page descriptor for the page described by this structure. */
128 struct page *page;
129
122 /* 130 /*
123 * If this is an extended and first-level entry, sublevel points 131 * If this is an extended and first-level entry, sublevel points
124 * to the second-level entries underneath this entry. 132 * to the second-level entries underneath this entry.
@@ -317,12 +325,10 @@ static void gasket_free_extended_subtable(struct gasket_page_table *pg_tbl,
317 325
318 /* Release the page table from the device */ 326 /* Release the page table from the device */
319 writeq(0, slot); 327 writeq(0, slot);
320 /* Force sync around the address release. */
321 mb();
322 328
323 if (pte->dma_addr) 329 if (pte->dma_addr)
324 dma_unmap_page(pg_tbl->device, pte->dma_addr, PAGE_SIZE, 330 dma_unmap_page(pg_tbl->device, pte->dma_addr, PAGE_SIZE,
325 DMA_BIDIRECTIONAL); 331 DMA_TO_DEVICE);
326 332
327 vfree(pte->sublevel); 333 vfree(pte->sublevel);
328 334
@@ -435,6 +441,19 @@ static int is_coherent(struct gasket_page_table *pg_tbl, ulong host_addr)
435 return min <= host_addr && host_addr < max; 441 return min <= host_addr && host_addr < max;
436} 442}
437 443
444/* Safely return a page to the OS. */
445static bool gasket_release_page(struct page *page)
446{
447 if (!page)
448 return false;
449
450 if (!PageReserved(page))
451 SetPageDirty(page);
452 put_page(page);
453
454 return true;
455}
456
438/* 457/*
439 * Get and map last level page table buffers. 458 * Get and map last level page table buffers.
440 * 459 *
@@ -458,7 +477,6 @@ static int gasket_perform_mapping(struct gasket_page_table *pg_tbl,
458 for (i = 0; i < num_pages; i++) { 477 for (i = 0; i < num_pages; i++) {
459 page_addr = host_addr + i * PAGE_SIZE; 478 page_addr = host_addr + i * PAGE_SIZE;
460 offset = page_addr & (PAGE_SIZE - 1); 479 offset = page_addr & (PAGE_SIZE - 1);
461 dev_dbg(pg_tbl->device, "%s i %d\n", __func__, i);
462 if (is_coherent(pg_tbl, host_addr)) { 480 if (is_coherent(pg_tbl, host_addr)) {
463 u64 off = 481 u64 off =
464 (u64)host_addr - 482 (u64)host_addr -
@@ -487,24 +505,16 @@ static int gasket_perform_mapping(struct gasket_page_table *pg_tbl,
487 ptes[i].dma_addr = 505 ptes[i].dma_addr =
488 dma_map_page(pg_tbl->device, page, 0, PAGE_SIZE, 506 dma_map_page(pg_tbl->device, page, 0, PAGE_SIZE,
489 DMA_BIDIRECTIONAL); 507 DMA_BIDIRECTIONAL);
490 dev_dbg(pg_tbl->device, 508
491 "%s i %d pte %p pfn %p -> mapped %llx\n", 509 if (dma_mapping_error(pg_tbl->device,
492 __func__, i, &ptes[i], 510 ptes[i].dma_addr)) {
493 (void *)page_to_pfn(page), 511 if (gasket_release_page(ptes[i].page))
494 (unsigned long long)ptes[i].dma_addr); 512 --pg_tbl->num_active_pages;
495 513
496 if (ptes[i].dma_addr == -1) { 514 memset(&ptes[i], 0,
497 dev_dbg(pg_tbl->device, 515 sizeof(struct gasket_page_table_entry));
498 "%s i %d -> fail to map page %llx " 516 return -EINVAL;
499 "[pfn %p ohys %p]\n",
500 __func__, i,
501 (unsigned long long)ptes[i].dma_addr,
502 (void *)page_to_pfn(page),
503 (void *)page_to_phys(page));
504 return -1;
505 } 517 }
506 /* Wait until the page is mapped. */
507 mb();
508 } 518 }
509 519
510 /* Make the DMA-space address available to the device. */ 520 /* Make the DMA-space address available to the device. */
@@ -545,7 +555,7 @@ static ulong gasket_extended_lvl0_page_idx(struct gasket_page_table *pg_tbl,
545 ulong dev_addr) 555 ulong dev_addr)
546{ 556{
547 return (dev_addr >> GASKET_EXTENDED_LVL0_SHIFT) & 557 return (dev_addr >> GASKET_EXTENDED_LVL0_SHIFT) &
548 ((1 << GASKET_EXTENDED_LVL0_WIDTH) - 1); 558 (pg_tbl->config.total_entries - 1);
549} 559}
550 560
551/* 561/*
@@ -574,19 +584,6 @@ static int gasket_alloc_simple_entries(struct gasket_page_table *pg_tbl,
574 return 0; 584 return 0;
575} 585}
576 586
577/* Safely return a page to the OS. */
578static bool gasket_release_page(struct page *page)
579{
580 if (!page)
581 return false;
582
583 if (!PageReserved(page))
584 SetPageDirty(page);
585 put_page(page);
586
587 return true;
588}
589
590/* 587/*
591 * Unmap and release mapped pages. 588 * Unmap and release mapped pages.
592 * The page table mutex must be held by the caller. 589 * The page table mutex must be held by the caller.
@@ -603,23 +600,23 @@ static void gasket_perform_unmapping(struct gasket_page_table *pg_tbl,
603 */ 600 */
604 for (i = 0; i < num_pages; i++) { 601 for (i = 0; i < num_pages; i++) {
605 /* release the address from the device, */ 602 /* release the address from the device, */
606 if (is_simple_mapping || ptes[i].status == PTE_INUSE) 603 if (is_simple_mapping || ptes[i].status == PTE_INUSE) {
607 writeq(0, &slots[i]); 604 writeq(0, &slots[i]);
608 else 605 } else {
609 ((u64 __force *)slots)[i] = 0; 606 ((u64 __force *)slots)[i] = 0;
610 /* Force sync around the address release. */ 607 /* sync above PTE update before updating mappings */
611 mb(); 608 wmb();
609 }
612 610
613 /* release the address from the driver, */ 611 /* release the address from the driver, */
614 if (ptes[i].status == PTE_INUSE) { 612 if (ptes[i].status == PTE_INUSE) {
615 if (ptes[i].dma_addr) { 613 if (ptes[i].page && ptes[i].dma_addr) {
616 dma_unmap_page(pg_tbl->device, ptes[i].dma_addr, 614 dma_unmap_page(pg_tbl->device, ptes[i].dma_addr,
617 PAGE_SIZE, DMA_FROM_DEVICE); 615 PAGE_SIZE, DMA_BIDIRECTIONAL);
618 } 616 }
619 if (gasket_release_page(ptes[i].page)) 617 if (gasket_release_page(ptes[i].page))
620 --pg_tbl->num_active_pages; 618 --pg_tbl->num_active_pages;
621 } 619 }
622 ptes[i].status = PTE_FREE;
623 620
624 /* and clear the PTE. */ 621 /* and clear the PTE. */
625 memset(&ptes[i], 0, sizeof(struct gasket_page_table_entry)); 622 memset(&ptes[i], 0, sizeof(struct gasket_page_table_entry));
@@ -684,38 +681,21 @@ static inline bool gasket_addr_is_simple(struct gasket_page_table *pg_tbl,
684 * Convert (simple, page, offset) into a device address. 681 * Convert (simple, page, offset) into a device address.
685 * Examples: 682 * Examples:
686 * Simple page 0, offset 32: 683 * Simple page 0, offset 32:
687 * Input (0, 0, 32), Output 0x20 684 * Input (1, 0, 32), Output 0x20
688 * Simple page 1000, offset 511: 685 * Simple page 1000, offset 511:
689 * Input (0, 1000, 512), Output 0x3E81FF 686 * Input (1, 1000, 511), Output 0x3E81FF
690 * Extended page 0, offset 32: 687 * Extended page 0, offset 32:
691 * Input (0, 0, 32), Output 0x8000000020 688 * Input (0, 0, 32), Output 0x8000000020
692 * Extended page 1000, offset 511: 689 * Extended page 1000, offset 511:
693 * Input (1, 1000, 512), Output 0x8003E81FF 690 * Input (0, 1000, 511), Output 0x8003E81FF
694 */ 691 */
695static ulong gasket_components_to_dev_address(struct gasket_page_table *pg_tbl, 692static ulong gasket_components_to_dev_address(struct gasket_page_table *pg_tbl,
696 int is_simple, uint page_index, 693 int is_simple, uint page_index,
697 uint offset) 694 uint offset)
698{ 695{
699 ulong lvl0_index, lvl1_index; 696 ulong dev_addr = (page_index << GASKET_SIMPLE_PAGE_SHIFT) | offset;
700
701 if (is_simple) {
702 /* Return simple addresses directly. */
703 lvl0_index = page_index & (pg_tbl->config.total_entries - 1);
704 return (lvl0_index << GASKET_SIMPLE_PAGE_SHIFT) | offset;
705 }
706 697
707 /* 698 return is_simple ? dev_addr : (pg_tbl->extended_flag | dev_addr);
708 * This could be compressed into fewer statements, but
709 * A) the compiler should optimize it
710 * B) this is not slow
711 * C) this is an uncommon operation
712 * D) this is actually readable this way.
713 */
714 lvl0_index = page_index / GASKET_PAGES_PER_SUBTABLE;
715 lvl1_index = page_index & (GASKET_PAGES_PER_SUBTABLE - 1);
716 return (pg_tbl)->extended_flag |
717 (lvl0_index << GASKET_EXTENDED_LVL0_SHIFT) |
718 (lvl1_index << GASKET_EXTENDED_LVL1_SHIFT) | offset;
719} 699}
720 700
721/* 701/*
@@ -896,9 +876,13 @@ static int gasket_alloc_extended_subtable(struct gasket_page_table *pg_tbl,
896 876
897 /* Map the page into DMA space. */ 877 /* Map the page into DMA space. */
898 pte->dma_addr = dma_map_page(pg_tbl->device, pte->page, 0, PAGE_SIZE, 878 pte->dma_addr = dma_map_page(pg_tbl->device, pte->page, 0, PAGE_SIZE,
899 DMA_BIDIRECTIONAL); 879 DMA_TO_DEVICE);
900 /* Wait until the page is mapped. */ 880 if (dma_mapping_error(pg_tbl->device, pte->dma_addr)) {
901 mb(); 881 free_page(page_addr);
882 vfree(pte->sublevel);
883 memset(pte, 0, sizeof(struct gasket_page_table_entry));
884 return -ENOMEM;
885 }
902 886
903 /* make the addresses available to the device */ 887 /* make the addresses available to the device */
904 dma_addr = (pte->dma_addr + pte->offset) | GASKET_VALID_SLOT_FLAG; 888 dma_addr = (pte->dma_addr + pte->offset) | GASKET_VALID_SLOT_FLAG;
@@ -1047,11 +1031,6 @@ int gasket_page_table_map(struct gasket_page_table *pg_tbl, ulong host_addr,
1047 } 1031 }
1048 1032
1049 mutex_unlock(&pg_tbl->mutex); 1033 mutex_unlock(&pg_tbl->mutex);
1050
1051 dev_dbg(pg_tbl->device,
1052 "%s done: ha %llx daddr %llx num %d, ret %d\n",
1053 __func__, (unsigned long long)host_addr,
1054 (unsigned long long)dev_addr, num_pages, ret);
1055 return ret; 1034 return ret;
1056} 1035}
1057EXPORT_SYMBOL(gasket_page_table_map); 1036EXPORT_SYMBOL(gasket_page_table_map);
@@ -1151,7 +1130,7 @@ fail:
1151 *ppage = NULL; 1130 *ppage = NULL;
1152 *poffset = 0; 1131 *poffset = 0;
1153 mutex_unlock(&pg_tbl->mutex); 1132 mutex_unlock(&pg_tbl->mutex);
1154 return -1; 1133 return -EINVAL;
1155} 1134}
1156 1135
1157/* See gasket_page_table.h for description. */ 1136/* See gasket_page_table.h for description. */
@@ -1291,7 +1270,7 @@ int gasket_alloc_coherent_memory(struct gasket_dev *gasket_dev, u64 size,
1291 return -EINVAL; 1270 return -EINVAL;
1292 1271
1293 mem = dma_alloc_coherent(gasket_get_device(gasket_dev), 1272 mem = dma_alloc_coherent(gasket_get_device(gasket_dev),
1294 num_pages * PAGE_SIZE, &handle, 0); 1273 num_pages * PAGE_SIZE, &handle, GFP_KERNEL);
1295 if (!mem) 1274 if (!mem)
1296 goto nomem; 1275 goto nomem;
1297 1276
@@ -1303,7 +1282,6 @@ int gasket_alloc_coherent_memory(struct gasket_dev *gasket_dev, u64 size,
1303 GFP_KERNEL); 1282 GFP_KERNEL);
1304 if (!gasket_dev->page_table[index]->coherent_pages) 1283 if (!gasket_dev->page_table[index]->coherent_pages)
1305 goto nomem; 1284 goto nomem;
1306 *dma_address = 0;
1307 1285
1308 gasket_dev->coherent_buffer.length_bytes = 1286 gasket_dev->coherent_buffer.length_bytes =
1309 PAGE_SIZE * (num_pages); 1287 PAGE_SIZE * (num_pages);
@@ -1318,20 +1296,19 @@ int gasket_alloc_coherent_memory(struct gasket_dev *gasket_dev, u64 size,
1318 (u64)mem + j * PAGE_SIZE; 1296 (u64)mem + j * PAGE_SIZE;
1319 } 1297 }
1320 1298
1321 if (*dma_address == 0)
1322 goto nomem;
1323 return 0; 1299 return 0;
1324 1300
1325nomem: 1301nomem:
1326 if (mem) { 1302 if (mem) {
1327 dma_free_coherent(gasket_get_device(gasket_dev), 1303 dma_free_coherent(gasket_get_device(gasket_dev),
1328 num_pages * PAGE_SIZE, mem, handle); 1304 num_pages * PAGE_SIZE, mem, handle);
1305 gasket_dev->coherent_buffer.length_bytes = 0;
1306 gasket_dev->coherent_buffer.virt_base = NULL;
1307 gasket_dev->coherent_buffer.phys_base = 0;
1329 } 1308 }
1330 1309
1331 if (gasket_dev->page_table[index]->coherent_pages) { 1310 kfree(gasket_dev->page_table[index]->coherent_pages);
1332 kfree(gasket_dev->page_table[index]->coherent_pages); 1311 gasket_dev->page_table[index]->coherent_pages = NULL;
1333 gasket_dev->page_table[index]->coherent_pages = NULL;
1334 }
1335 gasket_dev->page_table[index]->num_coherent_pages = 0; 1312 gasket_dev->page_table[index]->num_coherent_pages = 0;
1336 return -ENOMEM; 1313 return -ENOMEM;
1337} 1314}
@@ -1359,6 +1336,11 @@ int gasket_free_coherent_memory(struct gasket_dev *gasket_dev, u64 size,
1359 gasket_dev->coherent_buffer.virt_base = NULL; 1336 gasket_dev->coherent_buffer.virt_base = NULL;
1360 gasket_dev->coherent_buffer.phys_base = 0; 1337 gasket_dev->coherent_buffer.phys_base = 0;
1361 } 1338 }
1339
1340 kfree(gasket_dev->page_table[index]->coherent_pages);
1341 gasket_dev->page_table[index]->coherent_pages = NULL;
1342 gasket_dev->page_table[index]->num_coherent_pages = 0;
1343
1362 return 0; 1344 return 0;
1363} 1345}
1364 1346
diff --git a/drivers/staging/gasket/gasket_sysfs.h b/drivers/staging/gasket/gasket_sysfs.h
index f32eaf89e056..151e8edd28ea 100644
--- a/drivers/staging/gasket/gasket_sysfs.h
+++ b/drivers/staging/gasket/gasket_sysfs.h
@@ -152,8 +152,8 @@ void gasket_sysfs_put_device_data(struct device *device,
152 * Returns the Gasket sysfs attribute associated with the kernel device 152 * Returns the Gasket sysfs attribute associated with the kernel device
153 * attribute and device structure itself. Upon success, this call will take a 153 * attribute and device structure itself. Upon success, this call will take a
154 * reference to internal sysfs data that must be released with a call to 154 * reference to internal sysfs data that must be released with a call to
155 * gasket_sysfs_get_device_data. While this reference is held, the underlying 155 * gasket_sysfs_put_attr. While this reference is held, the underlying device
156 * device sysfs information/structure will remain valid/will not be deleted. 156 * sysfs information/structure will remain valid/will not be deleted.
157 */ 157 */
158struct gasket_sysfs_attribute * 158struct gasket_sysfs_attribute *
159gasket_sysfs_get_attr(struct device *device, struct device_attribute *attr); 159gasket_sysfs_get_attr(struct device *device, struct device_attribute *attr);
diff --git a/drivers/staging/greybus/audio_codec.c b/drivers/staging/greybus/audio_codec.c
index 35acd55ca5ab..08746c85dea6 100644
--- a/drivers/staging/greybus/audio_codec.c
+++ b/drivers/staging/greybus/audio_codec.c
@@ -1087,7 +1087,6 @@ static const struct of_device_id greybus_asoc_machine_of_match[] = {
1087static struct platform_driver gbaudio_codec_driver = { 1087static struct platform_driver gbaudio_codec_driver = {
1088 .driver = { 1088 .driver = {
1089 .name = "apb-dummy-codec", 1089 .name = "apb-dummy-codec",
1090 .owner = THIS_MODULE,
1091#ifdef CONFIG_PM 1090#ifdef CONFIG_PM
1092 .pm = &gbaudio_codec_pm_ops, 1091 .pm = &gbaudio_codec_pm_ops,
1093#endif 1092#endif
diff --git a/drivers/staging/greybus/loopback.c b/drivers/staging/greybus/loopback.c
index 42f6f3de967c..7080294f705c 100644
--- a/drivers/staging/greybus/loopback.c
+++ b/drivers/staging/greybus/loopback.c
@@ -97,7 +97,6 @@ struct gb_loopback {
97 u32 timeout_min; 97 u32 timeout_min;
98 u32 timeout_max; 98 u32 timeout_max;
99 u32 outstanding_operations_max; 99 u32 outstanding_operations_max;
100 u32 lbid;
101 u64 elapsed_nsecs; 100 u64 elapsed_nsecs;
102 u32 apbridge_latency_ts; 101 u32 apbridge_latency_ts;
103 u32 gbphy_latency_ts; 102 u32 gbphy_latency_ts;
@@ -1014,16 +1013,9 @@ static int gb_loopback_bus_id_compare(void *priv, struct list_head *lha,
1014 1013
1015static void gb_loopback_insert_id(struct gb_loopback *gb) 1014static void gb_loopback_insert_id(struct gb_loopback *gb)
1016{ 1015{
1017 struct gb_loopback *gb_list;
1018 u32 new_lbid = 0;
1019
1020 /* perform an insertion sort */ 1016 /* perform an insertion sort */
1021 list_add_tail(&gb->entry, &gb_dev.list); 1017 list_add_tail(&gb->entry, &gb_dev.list);
1022 list_sort(NULL, &gb_dev.list, gb_loopback_bus_id_compare); 1018 list_sort(NULL, &gb_dev.list, gb_loopback_bus_id_compare);
1023 list_for_each_entry(gb_list, &gb_dev.list, entry) {
1024 gb_list->lbid = 1 << new_lbid;
1025 new_lbid++;
1026 }
1027} 1019}
1028 1020
1029#define DEBUGFS_NAMELEN 32 1021#define DEBUGFS_NAMELEN 32
diff --git a/drivers/staging/greybus/tools/README.loopback b/drivers/staging/greybus/tools/README.loopback
index 845b08dc4696..070a510cbe7c 100644
--- a/drivers/staging/greybus/tools/README.loopback
+++ b/drivers/staging/greybus/tools/README.loopback
@@ -79,7 +79,7 @@ Here is the summary of the available options:
79 -t must be one of the test names - sink, transfer or ping 79 -t must be one of the test names - sink, transfer or ping
80 -i iteration count - the number of iterations to run the test over 80 -i iteration count - the number of iterations to run the test over
81 Optional arguments 81 Optional arguments
82 -S sysfs location - location for greybus 'endo' entires default /sys/bus/greybus/devices/ 82 -S sysfs location - location for greybus 'endo' entries default /sys/bus/greybus/devices/
83 -D debugfs location - location for loopback debugfs entries default /sys/kernel/debug/gb_loopback/ 83 -D debugfs location - location for loopback debugfs entries default /sys/kernel/debug/gb_loopback/
84 -s size of data packet to send during test - defaults to zero 84 -s size of data packet to send during test - defaults to zero
85 -m mask - a bit mask of connections to include example: -m 8 = 4th connection -m 9 = 1st and 4th connection etc 85 -m mask - a bit mask of connections to include example: -m 8 = 4th connection -m 9 = 1st and 4th connection etc
diff --git a/drivers/staging/greybus/tools/loopback_test.c b/drivers/staging/greybus/tools/loopback_test.c
index b82e2befe935..2fa88092514d 100644
--- a/drivers/staging/greybus/tools/loopback_test.c
+++ b/drivers/staging/greybus/tools/loopback_test.c
@@ -192,7 +192,7 @@ void usage(void)
192 " -t must be one of the test names - sink, transfer or ping\n" 192 " -t must be one of the test names - sink, transfer or ping\n"
193 " -i iteration count - the number of iterations to run the test over\n" 193 " -i iteration count - the number of iterations to run the test over\n"
194 " Optional arguments\n" 194 " Optional arguments\n"
195 " -S sysfs location - location for greybus 'endo' entires default /sys/bus/greybus/devices/\n" 195 " -S sysfs location - location for greybus 'endo' entries default /sys/bus/greybus/devices/\n"
196 " -D debugfs location - location for loopback debugfs entries default /sys/kernel/debug/gb_loopback/\n" 196 " -D debugfs location - location for loopback debugfs entries default /sys/kernel/debug/gb_loopback/\n"
197 " -s size of data packet to send during test - defaults to zero\n" 197 " -s size of data packet to send during test - defaults to zero\n"
198 " -m mask - a bit mask of connections to include example: -m 8 = 4th connection -m 9 = 1st and 4th connection etc\n" 198 " -m mask - a bit mask of connections to include example: -m 8 = 4th connection -m 9 = 1st and 4th connection etc\n"
diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index e17efb03bac0..9d3062a07460 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -11,7 +11,7 @@ config AD7606
11 select IIO_TRIGGERED_BUFFER 11 select IIO_TRIGGERED_BUFFER
12 help 12 help
13 Say yes here to build support for Analog Devices: 13 Say yes here to build support for Analog Devices:
14 ad7606, ad7606-6, ad7606-4 analog to digital converters (ADC). 14 ad7605-4, ad7606, ad7606-6, ad7606-4 analog to digital converters (ADC).
15 15
16 To compile this driver as a module, choose M here: the 16 To compile this driver as a module, choose M here: the
17 module will be called ad7606. 17 module will be called ad7606.
diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c
index df0499fc4802..acdbc07fd259 100644
--- a/drivers/staging/iio/adc/ad7192.c
+++ b/drivers/staging/iio/adc/ad7192.c
@@ -761,6 +761,6 @@ static struct spi_driver ad7192_driver = {
761}; 761};
762module_spi_driver(ad7192_driver); 762module_spi_driver(ad7192_driver);
763 763
764MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 764MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
765MODULE_DESCRIPTION("Analog Devices AD7190, AD7192, AD7193, AD7195 ADC"); 765MODULE_DESCRIPTION("Analog Devices AD7190, AD7192, AD7193, AD7195 ADC");
766MODULE_LICENSE("GPL v2"); 766MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c
index b736275c10f5..58420dcb406d 100644
--- a/drivers/staging/iio/adc/ad7280a.c
+++ b/drivers/staging/iio/adc/ad7280a.c
@@ -987,6 +987,6 @@ static struct spi_driver ad7280_driver = {
987}; 987};
988module_spi_driver(ad7280_driver); 988module_spi_driver(ad7280_driver);
989 989
990MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 990MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
991MODULE_DESCRIPTION("Analog Devices AD7280A"); 991MODULE_DESCRIPTION("Analog Devices AD7280A");
992MODULE_LICENSE("GPL v2"); 992MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
index b7810b1aad07..048c205b979e 100644
--- a/drivers/staging/iio/adc/ad7606.c
+++ b/drivers/staging/iio/adc/ad7606.c
@@ -26,9 +26,12 @@
26 26
27#include "ad7606.h" 27#include "ad7606.h"
28 28
29/* Scales are computed as 2.5/2**16 and 5/2**16 respectively */ 29/*
30 * Scales are computed as 5000/32768 and 10000/32768 respectively,
31 * so that when applied to the raw values they provide mV values
32 */
30static const unsigned int scale_avail[2][2] = { 33static const unsigned int scale_avail[2][2] = {
31 {0, 38147}, {0, 76294} 34 {0, 152588}, {0, 305176}
32}; 35};
33 36
34static int ad7606_reset(struct ad7606_state *st) 37static int ad7606_reset(struct ad7606_state *st)
@@ -271,7 +274,7 @@ static const struct attribute_group ad7606_attribute_group_range = {
271 .attrs = ad7606_attributes_range, 274 .attrs = ad7606_attributes_range,
272}; 275};
273 276
274#define AD7606_CHANNEL(num) \ 277#define AD760X_CHANNEL(num, mask) \
275 { \ 278 { \
276 .type = IIO_VOLTAGE, \ 279 .type = IIO_VOLTAGE, \
277 .indexed = 1, \ 280 .indexed = 1, \
@@ -279,8 +282,7 @@ static const struct attribute_group ad7606_attribute_group_range = {
279 .address = num, \ 282 .address = num, \
280 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 283 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
281 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),\ 284 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),\
282 .info_mask_shared_by_all = \ 285 .info_mask_shared_by_all = mask, \
283 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \
284 .scan_index = num, \ 286 .scan_index = num, \
285 .scan_type = { \ 287 .scan_type = { \
286 .sign = 's', \ 288 .sign = 's', \
@@ -290,6 +292,20 @@ static const struct attribute_group ad7606_attribute_group_range = {
290 }, \ 292 }, \
291 } 293 }
292 294
295#define AD7605_CHANNEL(num) \
296 AD760X_CHANNEL(num, 0)
297
298#define AD7606_CHANNEL(num) \
299 AD760X_CHANNEL(num, BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO))
300
301static const struct iio_chan_spec ad7605_channels[] = {
302 IIO_CHAN_SOFT_TIMESTAMP(4),
303 AD7605_CHANNEL(0),
304 AD7605_CHANNEL(1),
305 AD7605_CHANNEL(2),
306 AD7605_CHANNEL(3),
307};
308
293static const struct iio_chan_spec ad7606_channels[] = { 309static const struct iio_chan_spec ad7606_channels[] = {
294 IIO_CHAN_SOFT_TIMESTAMP(8), 310 IIO_CHAN_SOFT_TIMESTAMP(8),
295 AD7606_CHANNEL(0), 311 AD7606_CHANNEL(0),
@@ -306,17 +322,24 @@ static const struct ad7606_chip_info ad7606_chip_info_tbl[] = {
306 /* 322 /*
307 * More devices added in future 323 * More devices added in future
308 */ 324 */
325 [ID_AD7605_4] = {
326 .channels = ad7605_channels,
327 .num_channels = 5,
328 },
309 [ID_AD7606_8] = { 329 [ID_AD7606_8] = {
310 .channels = ad7606_channels, 330 .channels = ad7606_channels,
311 .num_channels = 9, 331 .num_channels = 9,
332 .has_oversampling = true,
312 }, 333 },
313 [ID_AD7606_6] = { 334 [ID_AD7606_6] = {
314 .channels = ad7606_channels, 335 .channels = ad7606_channels,
315 .num_channels = 7, 336 .num_channels = 7,
337 .has_oversampling = true,
316 }, 338 },
317 [ID_AD7606_4] = { 339 [ID_AD7606_4] = {
318 .channels = ad7606_channels, 340 .channels = ad7606_channels,
319 .num_channels = 5, 341 .num_channels = 5,
342 .has_oversampling = true,
320 }, 343 },
321}; 344};
322 345
@@ -347,6 +370,9 @@ static int ad7606_request_gpios(struct ad7606_state *st)
347 if (IS_ERR(st->gpio_frstdata)) 370 if (IS_ERR(st->gpio_frstdata))
348 return PTR_ERR(st->gpio_frstdata); 371 return PTR_ERR(st->gpio_frstdata);
349 372
373 if (!st->chip_info->has_oversampling)
374 return 0;
375
350 st->gpio_os = devm_gpiod_get_array_optional(dev, "oversampling-ratio", 376 st->gpio_os = devm_gpiod_get_array_optional(dev, "oversampling-ratio",
351 GPIOD_OUT_LOW); 377 GPIOD_OUT_LOW);
352 return PTR_ERR_OR_ZERO(st->gpio_os); 378 return PTR_ERR_OR_ZERO(st->gpio_os);
@@ -425,12 +451,12 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
425 return ret; 451 return ret;
426 } 452 }
427 453
454 st->chip_info = &ad7606_chip_info_tbl[id];
455
428 ret = ad7606_request_gpios(st); 456 ret = ad7606_request_gpios(st);
429 if (ret) 457 if (ret)
430 goto error_disable_reg; 458 goto error_disable_reg;
431 459
432 st->chip_info = &ad7606_chip_info_tbl[id];
433
434 indio_dev->dev.parent = dev; 460 indio_dev->dev.parent = dev;
435 if (st->gpio_os) { 461 if (st->gpio_os) {
436 if (st->gpio_range) 462 if (st->gpio_range)
@@ -532,6 +558,6 @@ EXPORT_SYMBOL_GPL(ad7606_pm_ops);
532 558
533#endif 559#endif
534 560
535MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 561MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
536MODULE_DESCRIPTION("Analog Devices AD7606 ADC"); 562MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
537MODULE_LICENSE("GPL v2"); 563MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/adc/ad7606.h b/drivers/staging/iio/adc/ad7606.h
index 9716ee9d94a7..86188054b60b 100644
--- a/drivers/staging/iio/adc/ad7606.h
+++ b/drivers/staging/iio/adc/ad7606.h
@@ -11,20 +11,40 @@
11 11
12/** 12/**
13 * struct ad7606_chip_info - chip specific information 13 * struct ad7606_chip_info - chip specific information
14 * @name: identification string for chip
15 * @channels: channel specification 14 * @channels: channel specification
16 * @num_channels: number of channels 15 * @num_channels: number of channels
17 * @lock protect sensor state 16 * @has_oversampling: whether the device has oversampling support
18 */ 17 */
19 18
20struct ad7606_chip_info { 19struct ad7606_chip_info {
21 const struct iio_chan_spec *channels; 20 const struct iio_chan_spec *channels;
22 unsigned int num_channels; 21 unsigned int num_channels;
22 bool has_oversampling;
23}; 23};
24 24
25/** 25/**
26 * struct ad7606_state - driver instance specific data 26 * struct ad7606_state - driver instance specific data
27 * @lock protect sensor state 27 * @dev pointer to kernel device
28 * @chip_info entry in the table of chips that describes this device
29 * @reg regulator info for the the power supply of the device
30 * @poll_work work struct for continuously reading data from the device
31 * into an IIO triggered buffer
32 * @wq_data_avail wait queue struct for buffer mode
33 * @bops bus operations (SPI or parallel)
34 * @range voltage range selection, selects which scale to apply
35 * @oversampling oversampling selection
36 * @done marks whether reading data is done
37 * @base_address address from where to read data in parallel operation
38 * @lock protect sensor state from concurrent accesses to GPIOs
39 * @gpio_convst GPIO descriptor for conversion start signal (CONVST)
40 * @gpio_reset GPIO descriptor for device hard-reset
41 * @gpio_range GPIO descriptor for range selection
42 * @gpio_standby GPIO descriptor for stand-by signal (STBY),
43 * controls power-down mode of device
44 * @gpio_frstdata GPIO descriptor for reading from device when data
45 * is being read on the first channel
46 * @gpio_os GPIO descriptors to control oversampling on the device
47 * @data buffer for reading data from the device
28 */ 48 */
29 49
30struct ad7606_state { 50struct ad7606_state {
@@ -55,6 +75,10 @@ struct ad7606_state {
55 unsigned short data[12] ____cacheline_aligned; 75 unsigned short data[12] ____cacheline_aligned;
56}; 76};
57 77
78/**
79 * struct ad7606_bus_ops - driver bus operations
80 * @read_block function pointer for reading blocks of data
81 */
58struct ad7606_bus_ops { 82struct ad7606_bus_ops {
59 /* more methods added in future? */ 83 /* more methods added in future? */
60 int (*read_block)(struct device *dev, int num, void *data); 84 int (*read_block)(struct device *dev, int num, void *data);
@@ -66,6 +90,7 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
66int ad7606_remove(struct device *dev, int irq); 90int ad7606_remove(struct device *dev, int irq);
67 91
68enum ad7606_supported_device_ids { 92enum ad7606_supported_device_ids {
93 ID_AD7605_4,
69 ID_AD7606_8, 94 ID_AD7606_8,
70 ID_AD7606_6, 95 ID_AD7606_6,
71 ID_AD7606_4 96 ID_AD7606_4
diff --git a/drivers/staging/iio/adc/ad7606_par.c b/drivers/staging/iio/adc/ad7606_par.c
index a34c2a1d5373..8bd86e727b02 100644
--- a/drivers/staging/iio/adc/ad7606_par.c
+++ b/drivers/staging/iio/adc/ad7606_par.c
@@ -79,6 +79,9 @@ static int ad7606_par_remove(struct platform_device *pdev)
79 79
80static const struct platform_device_id ad7606_driver_ids[] = { 80static const struct platform_device_id ad7606_driver_ids[] = {
81 { 81 {
82 .name = "ad7605-4",
83 .driver_data = ID_AD7605_4,
84 }, {
82 .name = "ad7606-8", 85 .name = "ad7606-8",
83 .driver_data = ID_AD7606_8, 86 .driver_data = ID_AD7606_8,
84 }, { 87 }, {
@@ -105,6 +108,6 @@ static struct platform_driver ad7606_driver = {
105 108
106module_platform_driver(ad7606_driver); 109module_platform_driver(ad7606_driver);
107 110
108MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 111MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
109MODULE_DESCRIPTION("Analog Devices AD7606 ADC"); 112MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
110MODULE_LICENSE("GPL v2"); 113MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/adc/ad7606_spi.c b/drivers/staging/iio/adc/ad7606_spi.c
index c9b1f26685f4..b76ca5a8c059 100644
--- a/drivers/staging/iio/adc/ad7606_spi.c
+++ b/drivers/staging/iio/adc/ad7606_spi.c
@@ -55,6 +55,7 @@ static int ad7606_spi_remove(struct spi_device *spi)
55} 55}
56 56
57static const struct spi_device_id ad7606_id[] = { 57static const struct spi_device_id ad7606_id[] = {
58 {"ad7605-4", ID_AD7605_4},
58 {"ad7606-8", ID_AD7606_8}, 59 {"ad7606-8", ID_AD7606_8},
59 {"ad7606-6", ID_AD7606_6}, 60 {"ad7606-6", ID_AD7606_6},
60 {"ad7606-4", ID_AD7606_4}, 61 {"ad7606-4", ID_AD7606_4},
@@ -73,6 +74,6 @@ static struct spi_driver ad7606_driver = {
73}; 74};
74module_spi_driver(ad7606_driver); 75module_spi_driver(ad7606_driver);
75 76
76MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 77MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
77MODULE_DESCRIPTION("Analog Devices AD7606 ADC"); 78MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
78MODULE_LICENSE("GPL v2"); 79MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c
index 16d72072c076..b67412db0318 100644
--- a/drivers/staging/iio/adc/ad7780.c
+++ b/drivers/staging/iio/adc/ad7780.c
@@ -260,6 +260,6 @@ static struct spi_driver ad7780_driver = {
260}; 260};
261module_spi_driver(ad7780_driver); 261module_spi_driver(ad7780_driver);
262 262
263MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 263MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
264MODULE_DESCRIPTION("Analog Devices AD7780 and similar ADCs"); 264MODULE_DESCRIPTION("Analog Devices AD7780 and similar ADCs");
265MODULE_LICENSE("GPL v2"); 265MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/cdc/ad7746.c b/drivers/staging/iio/cdc/ad7746.c
index f53612a6461d..0eb28fea876e 100644
--- a/drivers/staging/iio/cdc/ad7746.c
+++ b/drivers/staging/iio/cdc/ad7746.c
@@ -758,6 +758,6 @@ static struct i2c_driver ad7746_driver = {
758}; 758};
759module_i2c_driver(ad7746_driver); 759module_i2c_driver(ad7746_driver);
760 760
761MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 761MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
762MODULE_DESCRIPTION("Analog Devices AD7746/5/7 capacitive sensor driver"); 762MODULE_DESCRIPTION("Analog Devices AD7746/5/7 capacitive sensor driver");
763MODULE_LICENSE("GPL v2"); 763MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/frequency/ad9832.c b/drivers/staging/iio/frequency/ad9832.c
index c73eff1f8d73..a3ce50427724 100644
--- a/drivers/staging/iio/frequency/ad9832.c
+++ b/drivers/staging/iio/frequency/ad9832.c
@@ -454,6 +454,6 @@ static struct spi_driver ad9832_driver = {
454}; 454};
455module_spi_driver(ad9832_driver); 455module_spi_driver(ad9832_driver);
456 456
457MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 457MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
458MODULE_DESCRIPTION("Analog Devices AD9832/AD9835 DDS"); 458MODULE_DESCRIPTION("Analog Devices AD9832/AD9835 DDS");
459MODULE_LICENSE("GPL v2"); 459MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/frequency/ad9834.c b/drivers/staging/iio/frequency/ad9834.c
index 4c6d4043903e..1e977014fe5f 100644
--- a/drivers/staging/iio/frequency/ad9834.c
+++ b/drivers/staging/iio/frequency/ad9834.c
@@ -526,6 +526,6 @@ static struct spi_driver ad9834_driver = {
526}; 526};
527module_spi_driver(ad9834_driver); 527module_spi_driver(ad9834_driver);
528 528
529MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 529MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
530MODULE_DESCRIPTION("Analog Devices AD9833/AD9834/AD9837/AD9838 DDS"); 530MODULE_DESCRIPTION("Analog Devices AD9833/AD9834/AD9837/AD9838 DDS");
531MODULE_LICENSE("GPL v2"); 531MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c
index 14df89510396..a2370dd1e1a8 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -797,6 +797,6 @@ static struct i2c_driver ad5933_driver = {
797}; 797};
798module_i2c_driver(ad5933_driver); 798module_i2c_driver(ad5933_driver);
799 799
800MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 800MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
801MODULE_DESCRIPTION("Analog Devices AD5933 Impedance Conv. Network Analyzer"); 801MODULE_DESCRIPTION("Analog Devices AD5933 Impedance Conv. Network Analyzer");
802MODULE_LICENSE("GPL v2"); 802MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/ks7010/ks_hostif.c b/drivers/staging/ks7010/ks_hostif.c
index 0e554e3359b5..065bce193fac 100644
--- a/drivers/staging/ks7010/ks_hostif.c
+++ b/drivers/staging/ks7010/ks_hostif.c
@@ -191,7 +191,6 @@ static u8 read_ie(unsigned char *bp, u8 max, u8 *body)
191 return size; 191 return size;
192} 192}
193 193
194
195static 194static
196int get_ap_information(struct ks_wlan_private *priv, struct ap_info *ap_info, 195int get_ap_information(struct ks_wlan_private *priv, struct ap_info *ap_info,
197 struct local_ap *ap) 196 struct local_ap *ap)
@@ -1023,8 +1022,8 @@ int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *skb)
1023 priv->wpa.mic_failure.stop) { 1022 priv->wpa.mic_failure.stop) {
1024 if (netif_queue_stopped(priv->net_dev)) 1023 if (netif_queue_stopped(priv->net_dev))
1025 netif_wake_queue(priv->net_dev); 1024 netif_wake_queue(priv->net_dev);
1026 if (skb) 1025
1027 dev_kfree_skb(skb); 1026 dev_kfree_skb(skb);
1028 1027
1029 return 0; 1028 return 0;
1030 } 1029 }
diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipe.c b/drivers/staging/media/davinci_vpfe/dm365_ipipe.c
index 95942768639c..4d09e8141fed 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_ipipe.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipe.c
@@ -695,21 +695,21 @@ static int ipipe_get_gamma_params(struct vpfe_ipipe_device *ipipe, void *param)
695 695
696 if (!gamma->bypass_r) { 696 if (!gamma->bypass_r) {
697 dev_err(dev, 697 dev_err(dev,
698 "ipipe_get_gamma_params: table ptr empty for R\n"); 698 "%s: table ptr empty for R\n", __func__);
699 return -EINVAL; 699 return -EINVAL;
700 } 700 }
701 memcpy(gamma_param->table_r, gamma->table_r, 701 memcpy(gamma_param->table_r, gamma->table_r,
702 (table_size * sizeof(struct vpfe_ipipe_gamma_entry))); 702 (table_size * sizeof(struct vpfe_ipipe_gamma_entry)));
703 703
704 if (!gamma->bypass_g) { 704 if (!gamma->bypass_g) {
705 dev_err(dev, "ipipe_get_gamma_params: table ptr empty for G\n"); 705 dev_err(dev, "%s: table ptr empty for G\n", __func__);
706 return -EINVAL; 706 return -EINVAL;
707 } 707 }
708 memcpy(gamma_param->table_g, gamma->table_g, 708 memcpy(gamma_param->table_g, gamma->table_g,
709 (table_size * sizeof(struct vpfe_ipipe_gamma_entry))); 709 (table_size * sizeof(struct vpfe_ipipe_gamma_entry)));
710 710
711 if (!gamma->bypass_b) { 711 if (!gamma->bypass_b) {
712 dev_err(dev, "ipipe_get_gamma_params: table ptr empty for B\n"); 712 dev_err(dev, "%s: table ptr empty for B\n", __func__);
713 return -EINVAL; 713 return -EINVAL;
714 } 714 }
715 memcpy(gamma_param->table_b, gamma->table_b, 715 memcpy(gamma_param->table_b, gamma->table_b,
diff --git a/drivers/staging/media/davinci_vpfe/dm365_resizer.c b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
index 2b797474a344..6c5fcd6c691a 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_resizer.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
@@ -499,7 +499,7 @@ resizer_configure_in_continuous_mode(struct vpfe_resizer_device *resizer)
499 configure_resizer_out_params(resizer, RSZ_A, 499 configure_resizer_out_params(resizer, RSZ_A,
500 &cont_config->output1, 1, 0); 500 &cont_config->output1, 1, 0);
501 param->rsz_en[RSZ_B] = DISABLE; 501 param->rsz_en[RSZ_B] = DISABLE;
502 param->oper_mode = RESIZER_MODE_CONTINIOUS; 502 param->oper_mode = RESIZER_MODE_CONTINUOUS;
503 503
504 if (resizer->resizer_b.output == RESIZER_OUTPUT_MEMORY) { 504 if (resizer->resizer_b.output == RESIZER_OUTPUT_MEMORY) {
505 struct v4l2_mbus_framefmt *outformat2; 505 struct v4l2_mbus_framefmt *outformat2;
diff --git a/drivers/staging/media/davinci_vpfe/dm365_resizer.h b/drivers/staging/media/davinci_vpfe/dm365_resizer.h
index 00e64b0d0295..cf560a33d862 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_resizer.h
+++ b/drivers/staging/media/davinci_vpfe/dm365_resizer.h
@@ -23,7 +23,7 @@
23#define _DAVINCI_VPFE_DM365_RESIZER_H 23#define _DAVINCI_VPFE_DM365_RESIZER_H
24 24
25enum resizer_oper_mode { 25enum resizer_oper_mode {
26 RESIZER_MODE_CONTINIOUS = 0, 26 RESIZER_MODE_CONTINUOUS = 0,
27 RESIZER_MODE_ONE_SHOT = 1, 27 RESIZER_MODE_ONE_SHOT = 1,
28}; 28};
29 29
diff --git a/drivers/staging/media/imx/imx-media-dev.c b/drivers/staging/media/imx/imx-media-dev.c
index b0be80f05767..3f48f5ceb6ea 100644
--- a/drivers/staging/media/imx/imx-media-dev.c
+++ b/drivers/staging/media/imx/imx-media-dev.c
@@ -89,8 +89,12 @@ int imx_media_add_async_subdev(struct imx_media_dev *imxmd,
89 89
90 /* return -EEXIST if this asd already added */ 90 /* return -EEXIST if this asd already added */
91 if (find_async_subdev(imxmd, fwnode, devname)) { 91 if (find_async_subdev(imxmd, fwnode, devname)) {
92 dev_dbg(imxmd->md.dev, "%s: already added %s\n", 92 if (np)
93 __func__, np ? np->name : devname); 93 dev_dbg(imxmd->md.dev, "%s: already added %pOFn\n",
94 __func__, np);
95 else
96 dev_dbg(imxmd->md.dev, "%s: already added %s\n",
97 __func__, devname);
94 ret = -EEXIST; 98 ret = -EEXIST;
95 goto out; 99 goto out;
96 } 100 }
@@ -105,19 +109,20 @@ int imx_media_add_async_subdev(struct imx_media_dev *imxmd,
105 if (fwnode) { 109 if (fwnode) {
106 asd->match_type = V4L2_ASYNC_MATCH_FWNODE; 110 asd->match_type = V4L2_ASYNC_MATCH_FWNODE;
107 asd->match.fwnode = fwnode; 111 asd->match.fwnode = fwnode;
112 dev_dbg(imxmd->md.dev, "%s: added %pOFn, match type FWNODE\n",
113 __func__, np);
108 } else { 114 } else {
109 asd->match_type = V4L2_ASYNC_MATCH_DEVNAME; 115 asd->match_type = V4L2_ASYNC_MATCH_DEVNAME;
110 asd->match.device_name = devname; 116 asd->match.device_name = devname;
111 imxasd->pdev = pdev; 117 imxasd->pdev = pdev;
118 dev_dbg(imxmd->md.dev, "%s: added %s, match type DEVNAME\n",
119 __func__, devname);
112 } 120 }
113 121
114 list_add_tail(&imxasd->list, &imxmd->asd_list); 122 list_add_tail(&imxasd->list, &imxmd->asd_list);
115 123
116 imxmd->subdev_notifier.num_subdevs++; 124 imxmd->subdev_notifier.num_subdevs++;
117 125
118 dev_dbg(imxmd->md.dev, "%s: added %s, match type %s\n",
119 __func__, np ? np->name : devname, np ? "FWNODE" : "DEVNAME");
120
121out: 126out:
122 mutex_unlock(&imxmd->mutex); 127 mutex_unlock(&imxmd->mutex);
123 return ret; 128 return ret;
diff --git a/drivers/staging/media/imx/imx-media-of.c b/drivers/staging/media/imx/imx-media-of.c
index acde372c6795..163437e421c5 100644
--- a/drivers/staging/media/imx/imx-media-of.c
+++ b/drivers/staging/media/imx/imx-media-of.c
@@ -79,8 +79,8 @@ of_parse_subdev(struct imx_media_dev *imxmd, struct device_node *sd_np,
79 int i, num_ports, ret; 79 int i, num_ports, ret;
80 80
81 if (!of_device_is_available(sd_np)) { 81 if (!of_device_is_available(sd_np)) {
82 dev_dbg(imxmd->md.dev, "%s: %s not enabled\n", __func__, 82 dev_dbg(imxmd->md.dev, "%s: %pOFn not enabled\n", __func__,
83 sd_np->name); 83 sd_np);
84 /* unavailable is not an error */ 84 /* unavailable is not an error */
85 return 0; 85 return 0;
86 } 86 }
diff --git a/drivers/staging/most/cdev/cdev.c b/drivers/staging/most/cdev/cdev.c
index 4569838f27a0..ea64aabda94e 100644
--- a/drivers/staging/most/cdev/cdev.c
+++ b/drivers/staging/most/cdev/cdev.c
@@ -447,7 +447,7 @@ static int comp_probe(struct most_interface *iface, int channel_id,
447 c = kzalloc(sizeof(*c), GFP_KERNEL); 447 c = kzalloc(sizeof(*c), GFP_KERNEL);
448 if (!c) { 448 if (!c) {
449 retval = -ENOMEM; 449 retval = -ENOMEM;
450 goto error_alloc_channel; 450 goto err_remove_ida;
451 } 451 }
452 452
453 c->devno = MKDEV(comp.major, current_minor); 453 c->devno = MKDEV(comp.major, current_minor);
@@ -463,7 +463,7 @@ static int comp_probe(struct most_interface *iface, int channel_id,
463 retval = kfifo_alloc(&c->fifo, cfg->num_buffers, GFP_KERNEL); 463 retval = kfifo_alloc(&c->fifo, cfg->num_buffers, GFP_KERNEL);
464 if (retval) { 464 if (retval) {
465 pr_info("failed to alloc channel kfifo"); 465 pr_info("failed to alloc channel kfifo");
466 goto error_alloc_kfifo; 466 goto err_del_cdev_and_free_channel;
467 } 467 }
468 init_waitqueue_head(&c->wq); 468 init_waitqueue_head(&c->wq);
469 mutex_init(&c->io_mutex); 469 mutex_init(&c->io_mutex);
@@ -475,18 +475,18 @@ static int comp_probe(struct most_interface *iface, int channel_id,
475 if (IS_ERR(c->dev)) { 475 if (IS_ERR(c->dev)) {
476 retval = PTR_ERR(c->dev); 476 retval = PTR_ERR(c->dev);
477 pr_info("failed to create new device node %s\n", name); 477 pr_info("failed to create new device node %s\n", name);
478 goto error_create_device; 478 goto err_free_kfifo_and_del_list;
479 } 479 }
480 kobject_uevent(&c->dev->kobj, KOBJ_ADD); 480 kobject_uevent(&c->dev->kobj, KOBJ_ADD);
481 return 0; 481 return 0;
482 482
483error_create_device: 483err_free_kfifo_and_del_list:
484 kfifo_free(&c->fifo); 484 kfifo_free(&c->fifo);
485 list_del(&c->list); 485 list_del(&c->list);
486error_alloc_kfifo: 486err_del_cdev_and_free_channel:
487 cdev_del(&c->cdev); 487 cdev_del(&c->cdev);
488 kfree(c); 488 kfree(c);
489error_alloc_channel: 489err_remove_ida:
490 ida_simple_remove(&comp.minor_id, current_minor); 490 ida_simple_remove(&comp.minor_id, current_minor);
491 return retval; 491 return retval;
492} 492}
diff --git a/drivers/staging/most/core.c b/drivers/staging/most/core.c
index f4c464625a67..6a18cf73c85e 100644
--- a/drivers/staging/most/core.c
+++ b/drivers/staging/most/core.c
@@ -442,6 +442,24 @@ static ssize_t set_dbr_size_store(struct device *dev,
442 return count; 442 return count;
443} 443}
444 444
445#define to_dev_attr(a) container_of(a, struct device_attribute, attr)
446static umode_t channel_attr_is_visible(struct kobject *kobj,
447 struct attribute *attr, int index)
448{
449 struct device_attribute *dev_attr = to_dev_attr(attr);
450 struct device *dev = kobj_to_dev(kobj);
451 struct most_channel *c = to_channel(dev);
452
453 if (!strcmp(dev_attr->attr.name, "set_dbr_size") &&
454 (c->iface->interface != ITYPE_MEDIALB_DIM2))
455 return 0;
456 if (!strcmp(dev_attr->attr.name, "set_packets_per_xact") &&
457 (c->iface->interface != ITYPE_USB))
458 return 0;
459
460 return attr->mode;
461}
462
445#define DEV_ATTR(_name) (&dev_attr_##_name.attr) 463#define DEV_ATTR(_name) (&dev_attr_##_name.attr)
446 464
447static DEVICE_ATTR_RO(available_directions); 465static DEVICE_ATTR_RO(available_directions);
@@ -479,6 +497,7 @@ static struct attribute *channel_attrs[] = {
479 497
480static struct attribute_group channel_attr_group = { 498static struct attribute_group channel_attr_group = {
481 .attrs = channel_attrs, 499 .attrs = channel_attrs,
500 .is_visible = channel_attr_is_visible,
482}; 501};
483 502
484static const struct attribute_group *channel_attr_groups[] = { 503static const struct attribute_group *channel_attr_groups[] = {
@@ -1216,7 +1235,7 @@ int most_start_channel(struct most_interface *iface, int id,
1216 if (c->iface->configure(c->iface, c->channel_id, &c->cfg)) { 1235 if (c->iface->configure(c->iface, c->channel_id, &c->cfg)) {
1217 pr_info("channel configuration failed. Go check settings...\n"); 1236 pr_info("channel configuration failed. Go check settings...\n");
1218 ret = -EINVAL; 1237 ret = -EINVAL;
1219 goto error; 1238 goto err_put_module;
1220 } 1239 }
1221 1240
1222 init_waitqueue_head(&c->hdm_fifo_wq); 1241 init_waitqueue_head(&c->hdm_fifo_wq);
@@ -1229,12 +1248,12 @@ int most_start_channel(struct most_interface *iface, int id,
1229 most_write_completion); 1248 most_write_completion);
1230 if (unlikely(!num_buffer)) { 1249 if (unlikely(!num_buffer)) {
1231 ret = -ENOMEM; 1250 ret = -ENOMEM;
1232 goto error; 1251 goto err_put_module;
1233 } 1252 }
1234 1253
1235 ret = run_enqueue_thread(c, id); 1254 ret = run_enqueue_thread(c, id);
1236 if (ret) 1255 if (ret)
1237 goto error; 1256 goto err_put_module;
1238 1257
1239 c->is_starving = 0; 1258 c->is_starving = 0;
1240 c->pipe0.num_buffers = c->cfg.num_buffers / 2; 1259 c->pipe0.num_buffers = c->cfg.num_buffers / 2;
@@ -1249,7 +1268,7 @@ out:
1249 mutex_unlock(&c->start_mutex); 1268 mutex_unlock(&c->start_mutex);
1250 return 0; 1269 return 0;
1251 1270
1252error: 1271err_put_module:
1253 module_put(iface->mod); 1272 module_put(iface->mod);
1254 mutex_unlock(&c->start_mutex); 1273 mutex_unlock(&c->start_mutex);
1255 return ret; 1274 return ret;
@@ -1430,7 +1449,7 @@ int most_register_interface(struct most_interface *iface)
1430 1449
1431 c = kzalloc(sizeof(*c), GFP_KERNEL); 1450 c = kzalloc(sizeof(*c), GFP_KERNEL);
1432 if (!c) 1451 if (!c)
1433 goto free_instance; 1452 goto err_free_resources;
1434 if (!name_suffix) 1453 if (!name_suffix)
1435 snprintf(c->name, STRING_SIZE, "ch%d", i); 1454 snprintf(c->name, STRING_SIZE, "ch%d", i);
1436 else 1455 else
@@ -1439,10 +1458,6 @@ int most_register_interface(struct most_interface *iface)
1439 c->dev.parent = &iface->dev; 1458 c->dev.parent = &iface->dev;
1440 c->dev.groups = channel_attr_groups; 1459 c->dev.groups = channel_attr_groups;
1441 c->dev.release = release_channel; 1460 c->dev.release = release_channel;
1442 if (device_register(&c->dev)) {
1443 pr_err("registering c->dev failed\n");
1444 goto free_instance_nodev;
1445 }
1446 iface->p->channel[i] = c; 1461 iface->p->channel[i] = c;
1447 c->is_starving = 0; 1462 c->is_starving = 0;
1448 c->iface = iface; 1463 c->iface = iface;
@@ -1465,15 +1480,19 @@ int most_register_interface(struct most_interface *iface)
1465 mutex_init(&c->start_mutex); 1480 mutex_init(&c->start_mutex);
1466 mutex_init(&c->nq_mutex); 1481 mutex_init(&c->nq_mutex);
1467 list_add_tail(&c->list, &iface->p->channel_list); 1482 list_add_tail(&c->list, &iface->p->channel_list);
1483 if (device_register(&c->dev)) {
1484 pr_err("registering c->dev failed\n");
1485 goto err_free_most_channel;
1486 }
1468 } 1487 }
1469 pr_info("registered new device mdev%d (%s)\n", 1488 pr_info("registered new device mdev%d (%s)\n",
1470 id, iface->description); 1489 id, iface->description);
1471 return 0; 1490 return 0;
1472 1491
1473free_instance_nodev: 1492err_free_most_channel:
1474 kfree(c); 1493 kfree(c);
1475 1494
1476free_instance: 1495err_free_resources:
1477 while (i > 0) { 1496 while (i > 0) {
1478 c = iface->p->channel[--i]; 1497 c = iface->p->channel[--i];
1479 device_unregister(&c->dev); 1498 device_unregister(&c->dev);
@@ -1594,20 +1613,20 @@ static int __init most_init(void)
1594 err = driver_register(&mc.drv); 1613 err = driver_register(&mc.drv);
1595 if (err) { 1614 if (err) {
1596 pr_info("Cannot register core driver\n"); 1615 pr_info("Cannot register core driver\n");
1597 goto exit_bus; 1616 goto err_unregister_bus;
1598 } 1617 }
1599 mc.dev.init_name = "most_bus"; 1618 mc.dev.init_name = "most_bus";
1600 mc.dev.release = release_most_sub; 1619 mc.dev.release = release_most_sub;
1601 if (device_register(&mc.dev)) { 1620 if (device_register(&mc.dev)) {
1602 err = -ENOMEM; 1621 err = -ENOMEM;
1603 goto exit_driver; 1622 goto err_unregister_driver;
1604 } 1623 }
1605 1624
1606 return 0; 1625 return 0;
1607 1626
1608exit_driver: 1627err_unregister_driver:
1609 driver_unregister(&mc.drv); 1628 driver_unregister(&mc.drv);
1610exit_bus: 1629err_unregister_bus:
1611 bus_unregister(&mc.bus); 1630 bus_unregister(&mc.bus);
1612 return err; 1631 return err;
1613} 1632}
diff --git a/drivers/staging/most/net/net.c b/drivers/staging/most/net/net.c
index 30d816b7e165..e20584b1b112 100644
--- a/drivers/staging/most/net/net.c
+++ b/drivers/staging/most/net/net.c
@@ -75,7 +75,7 @@ static struct core_component comp;
75static int skb_to_mamac(const struct sk_buff *skb, struct mbo *mbo) 75static int skb_to_mamac(const struct sk_buff *skb, struct mbo *mbo)
76{ 76{
77 u8 *buff = mbo->virt_address; 77 u8 *buff = mbo->virt_address;
78 const u8 broadcast[] = { 0x03, 0xFF }; 78 static const u8 broadcast[] = { 0x03, 0xFF };
79 const u8 *dest_addr = skb->data + 4; 79 const u8 *dest_addr = skb->data + 4;
80 const u8 *eth_type = skb->data + 12; 80 const u8 *eth_type = skb->data + 12;
81 unsigned int payload_len = skb->len - ETH_HLEN; 81 unsigned int payload_len = skb->len - ETH_HLEN;
diff --git a/drivers/staging/most/usb/usb.c b/drivers/staging/most/usb/usb.c
index bc820f90bcb1..c0293d8d5934 100644
--- a/drivers/staging/most/usb/usb.c
+++ b/drivers/staging/most/usb/usb.c
@@ -568,19 +568,19 @@ static int hdm_enqueue(struct most_interface *iface, int channel,
568 mutex_lock(&mdev->io_mutex); 568 mutex_lock(&mdev->io_mutex);
569 if (!mdev->usb_device) { 569 if (!mdev->usb_device) {
570 retval = -ENODEV; 570 retval = -ENODEV;
571 goto _exit; 571 goto unlock_io_mutex;
572 } 572 }
573 573
574 urb = usb_alloc_urb(NO_ISOCHRONOUS_URB, GFP_ATOMIC); 574 urb = usb_alloc_urb(NO_ISOCHRONOUS_URB, GFP_ATOMIC);
575 if (!urb) { 575 if (!urb) {
576 retval = -ENOMEM; 576 retval = -ENOMEM;
577 goto _exit; 577 goto unlock_io_mutex;
578 } 578 }
579 579
580 if ((conf->direction & MOST_CH_TX) && mdev->padding_active[channel] && 580 if ((conf->direction & MOST_CH_TX) && mdev->padding_active[channel] &&
581 hdm_add_padding(mdev, channel, mbo)) { 581 hdm_add_padding(mdev, channel, mbo)) {
582 retval = -EIO; 582 retval = -EIO;
583 goto _error; 583 goto err_free_urb;
584 } 584 }
585 585
586 urb->transfer_dma = mbo->bus_address; 586 urb->transfer_dma = mbo->bus_address;
@@ -615,15 +615,15 @@ static int hdm_enqueue(struct most_interface *iface, int channel,
615 if (retval) { 615 if (retval) {
616 dev_err(&mdev->usb_device->dev, 616 dev_err(&mdev->usb_device->dev,
617 "URB submit failed with error %d.\n", retval); 617 "URB submit failed with error %d.\n", retval);
618 goto _error_1; 618 goto err_unanchor_urb;
619 } 619 }
620 goto _exit; 620 goto unlock_io_mutex;
621 621
622_error_1: 622err_unanchor_urb:
623 usb_unanchor_urb(urb); 623 usb_unanchor_urb(urb);
624_error: 624err_free_urb:
625 usb_free_urb(urb); 625 usb_free_urb(urb);
626_exit: 626unlock_io_mutex:
627 mutex_unlock(&mdev->io_mutex); 627 mutex_unlock(&mdev->io_mutex);
628 return retval; 628 return retval;
629} 629}
@@ -1015,6 +1015,13 @@ static const struct attribute_group *dci_attr_groups[] = {
1015 NULL, 1015 NULL,
1016}; 1016};
1017 1017
1018static void release_dci(struct device *dev)
1019{
1020 struct most_dci_obj *dci = to_dci_obj(dev);
1021
1022 kfree(dci);
1023}
1024
1018/** 1025/**
1019 * hdm_probe - probe function of USB device driver 1026 * hdm_probe - probe function of USB device driver
1020 * @interface: Interface of the attached USB device 1027 * @interface: Interface of the attached USB device
@@ -1041,7 +1048,7 @@ hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)
1041 int ret = 0; 1048 int ret = 0;
1042 1049
1043 if (!mdev) 1050 if (!mdev)
1044 goto exit_ENOMEM; 1051 goto err_out_of_memory;
1045 1052
1046 usb_set_intfdata(interface, mdev); 1053 usb_set_intfdata(interface, mdev);
1047 num_endpoints = usb_iface_desc->desc.bNumEndpoints; 1054 num_endpoints = usb_iface_desc->desc.bNumEndpoints;
@@ -1073,22 +1080,22 @@ hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)
1073 1080
1074 mdev->conf = kcalloc(num_endpoints, sizeof(*mdev->conf), GFP_KERNEL); 1081 mdev->conf = kcalloc(num_endpoints, sizeof(*mdev->conf), GFP_KERNEL);
1075 if (!mdev->conf) 1082 if (!mdev->conf)
1076 goto exit_free; 1083 goto err_free_mdev;
1077 1084
1078 mdev->cap = kcalloc(num_endpoints, sizeof(*mdev->cap), GFP_KERNEL); 1085 mdev->cap = kcalloc(num_endpoints, sizeof(*mdev->cap), GFP_KERNEL);
1079 if (!mdev->cap) 1086 if (!mdev->cap)
1080 goto exit_free1; 1087 goto err_free_conf;
1081 1088
1082 mdev->iface.channel_vector = mdev->cap; 1089 mdev->iface.channel_vector = mdev->cap;
1083 mdev->ep_address = 1090 mdev->ep_address =
1084 kcalloc(num_endpoints, sizeof(*mdev->ep_address), GFP_KERNEL); 1091 kcalloc(num_endpoints, sizeof(*mdev->ep_address), GFP_KERNEL);
1085 if (!mdev->ep_address) 1092 if (!mdev->ep_address)
1086 goto exit_free2; 1093 goto err_free_cap;
1087 1094
1088 mdev->busy_urbs = 1095 mdev->busy_urbs =
1089 kcalloc(num_endpoints, sizeof(*mdev->busy_urbs), GFP_KERNEL); 1096 kcalloc(num_endpoints, sizeof(*mdev->busy_urbs), GFP_KERNEL);
1090 if (!mdev->busy_urbs) 1097 if (!mdev->busy_urbs)
1091 goto exit_free3; 1098 goto err_free_ep_address;
1092 1099
1093 tmp_cap = mdev->cap; 1100 tmp_cap = mdev->cap;
1094 for (i = 0; i < num_endpoints; i++) { 1101 for (i = 0; i < num_endpoints; i++) {
@@ -1129,7 +1136,7 @@ hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)
1129 1136
1130 ret = most_register_interface(&mdev->iface); 1137 ret = most_register_interface(&mdev->iface);
1131 if (ret) 1138 if (ret)
1132 goto exit_free4; 1139 goto err_free_busy_urbs;
1133 1140
1134 mutex_lock(&mdev->io_mutex); 1141 mutex_lock(&mdev->io_mutex);
1135 if (le16_to_cpu(usb_dev->descriptor.idProduct) == USB_DEV_ID_OS81118 || 1142 if (le16_to_cpu(usb_dev->descriptor.idProduct) == USB_DEV_ID_OS81118 ||
@@ -1140,35 +1147,36 @@ hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)
1140 mutex_unlock(&mdev->io_mutex); 1147 mutex_unlock(&mdev->io_mutex);
1141 most_deregister_interface(&mdev->iface); 1148 most_deregister_interface(&mdev->iface);
1142 ret = -ENOMEM; 1149 ret = -ENOMEM;
1143 goto exit_free4; 1150 goto err_free_busy_urbs;
1144 } 1151 }
1145 1152
1146 mdev->dci->dev.init_name = "dci"; 1153 mdev->dci->dev.init_name = "dci";
1147 mdev->dci->dev.parent = &mdev->iface.dev; 1154 mdev->dci->dev.parent = &mdev->iface.dev;
1148 mdev->dci->dev.groups = dci_attr_groups; 1155 mdev->dci->dev.groups = dci_attr_groups;
1156 mdev->dci->dev.release = release_dci;
1149 if (device_register(&mdev->dci->dev)) { 1157 if (device_register(&mdev->dci->dev)) {
1150 mutex_unlock(&mdev->io_mutex); 1158 mutex_unlock(&mdev->io_mutex);
1151 most_deregister_interface(&mdev->iface); 1159 most_deregister_interface(&mdev->iface);
1152 ret = -ENOMEM; 1160 ret = -ENOMEM;
1153 goto exit_free5; 1161 goto err_free_dci;
1154 } 1162 }
1155 mdev->dci->usb_device = mdev->usb_device; 1163 mdev->dci->usb_device = mdev->usb_device;
1156 } 1164 }
1157 mutex_unlock(&mdev->io_mutex); 1165 mutex_unlock(&mdev->io_mutex);
1158 return 0; 1166 return 0;
1159exit_free5: 1167err_free_dci:
1160 kfree(mdev->dci); 1168 kfree(mdev->dci);
1161exit_free4: 1169err_free_busy_urbs:
1162 kfree(mdev->busy_urbs); 1170 kfree(mdev->busy_urbs);
1163exit_free3: 1171err_free_ep_address:
1164 kfree(mdev->ep_address); 1172 kfree(mdev->ep_address);
1165exit_free2: 1173err_free_cap:
1166 kfree(mdev->cap); 1174 kfree(mdev->cap);
1167exit_free1: 1175err_free_conf:
1168 kfree(mdev->conf); 1176 kfree(mdev->conf);
1169exit_free: 1177err_free_mdev:
1170 kfree(mdev); 1178 kfree(mdev);
1171exit_ENOMEM: 1179err_out_of_memory:
1172 if (ret == 0 || ret == -ENOMEM) { 1180 if (ret == 0 || ret == -ENOMEM) {
1173 ret = -ENOMEM; 1181 ret = -ENOMEM;
1174 dev_err(dev, "out of memory\n"); 1182 dev_err(dev, "out of memory\n");
@@ -1198,7 +1206,6 @@ static void hdm_disconnect(struct usb_interface *interface)
1198 cancel_work_sync(&mdev->poll_work_obj); 1206 cancel_work_sync(&mdev->poll_work_obj);
1199 1207
1200 device_unregister(&mdev->dci->dev); 1208 device_unregister(&mdev->dci->dev);
1201 kfree(mdev->dci);
1202 most_deregister_interface(&mdev->iface); 1209 most_deregister_interface(&mdev->iface);
1203 1210
1204 kfree(mdev->busy_urbs); 1211 kfree(mdev->busy_urbs);
diff --git a/drivers/staging/most/video/video.c b/drivers/staging/most/video/video.c
index cf342eb58e10..ad7e28ab9a4f 100644
--- a/drivers/staging/most/video/video.c
+++ b/drivers/staging/most/video/video.c
@@ -530,7 +530,7 @@ static int comp_disconnect_channel(struct most_interface *iface,
530 return 0; 530 return 0;
531} 531}
532 532
533static struct core_component comp_info = { 533static struct core_component comp = {
534 .name = "video", 534 .name = "video",
535 .probe_channel = comp_probe_channel, 535 .probe_channel = comp_probe_channel,
536 .disconnect_channel = comp_disconnect_channel, 536 .disconnect_channel = comp_disconnect_channel,
@@ -565,7 +565,7 @@ static void __exit comp_exit(void)
565 } 565 }
566 spin_unlock_irq(&list_lock); 566 spin_unlock_irq(&list_lock);
567 567
568 most_deregister_component(&comp_info); 568 most_deregister_component(&comp);
569 BUG_ON(!list_empty(&video_devices)); 569 BUG_ON(!list_empty(&video_devices));
570} 570}
571 571
diff --git a/drivers/staging/mt7621-dma/ralink-gdma.c b/drivers/staging/mt7621-dma/ralink-gdma.c
index 6d9fe175ea52..73dbc7fe38a2 100644
--- a/drivers/staging/mt7621-dma/ralink-gdma.c
+++ b/drivers/staging/mt7621-dma/ralink-gdma.c
@@ -47,7 +47,6 @@
47#define GDMA_REG_CTRL1_REQ_MASK 0x3f 47#define GDMA_REG_CTRL1_REQ_MASK 0x3f
48#define GDMA_REG_CTRL1_SRC_REQ_SHIFT 16 48#define GDMA_REG_CTRL1_SRC_REQ_SHIFT 16
49#define GDMA_REG_CTRL1_DST_REQ_SHIFT 8 49#define GDMA_REG_CTRL1_DST_REQ_SHIFT 8
50#define GDMA_REG_CTRL1_CONTINOUS BIT(14)
51#define GDMA_REG_CTRL1_NEXT_MASK 0x1f 50#define GDMA_REG_CTRL1_NEXT_MASK 0x1f
52#define GDMA_REG_CTRL1_NEXT_SHIFT 3 51#define GDMA_REG_CTRL1_NEXT_SHIFT 3
53#define GDMA_REG_CTRL1_COHERENT BIT(2) 52#define GDMA_REG_CTRL1_COHERENT BIT(2)
diff --git a/drivers/staging/mt7621-eth/gsw_mt7621.c b/drivers/staging/mt7621-eth/gsw_mt7621.c
index 2c07b559bed7..53767b17bad9 100644
--- a/drivers/staging/mt7621-eth/gsw_mt7621.c
+++ b/drivers/staging/mt7621-eth/gsw_mt7621.c
@@ -286,7 +286,6 @@ static struct platform_driver gsw_driver = {
286 .remove = mt7621_gsw_remove, 286 .remove = mt7621_gsw_remove,
287 .driver = { 287 .driver = {
288 .name = "mt7621-gsw", 288 .name = "mt7621-gsw",
289 .owner = THIS_MODULE,
290 .of_match_table = mediatek_gsw_match, 289 .of_match_table = mediatek_gsw_match,
291 }, 290 },
292}; 291};
diff --git a/drivers/staging/mt7621-eth/mdio.c b/drivers/staging/mt7621-eth/mdio.c
index 2c6e1800a3fd..ee851281b657 100644
--- a/drivers/staging/mt7621-eth/mdio.c
+++ b/drivers/staging/mt7621-eth/mdio.c
@@ -70,7 +70,7 @@ int mtk_connect_phy_node(struct mtk_eth *eth, struct mtk_mac *mac,
70 _port = of_get_property(phy_node, "reg", NULL); 70 _port = of_get_property(phy_node, "reg", NULL);
71 71
72 if (!_port || (be32_to_cpu(*_port) >= 0x20)) { 72 if (!_port || (be32_to_cpu(*_port) >= 0x20)) {
73 pr_err("%s: invalid port id\n", phy_node->name); 73 pr_err("%pOFn: invalid port id\n", phy_node);
74 return -EINVAL; 74 return -EINVAL;
75 } 75 }
76 port = be32_to_cpu(*_port); 76 port = be32_to_cpu(*_port);
@@ -249,7 +249,7 @@ int mtk_mdio_init(struct mtk_eth *eth)
249 eth->mii_bus->priv = eth; 249 eth->mii_bus->priv = eth;
250 eth->mii_bus->parent = eth->dev; 250 eth->mii_bus->parent = eth->dev;
251 251
252 snprintf(eth->mii_bus->id, MII_BUS_ID_SIZE, "%s", mii_np->name); 252 snprintf(eth->mii_bus->id, MII_BUS_ID_SIZE, "%pOFn", mii_np);
253 err = of_mdiobus_register(eth->mii_bus, mii_np); 253 err = of_mdiobus_register(eth->mii_bus, mii_np);
254 if (err) 254 if (err)
255 goto err_free_bus; 255 goto err_free_bus;
diff --git a/drivers/staging/mt7621-eth/mtk_eth_soc.c b/drivers/staging/mt7621-eth/mtk_eth_soc.c
index 713507558568..363d3c978e02 100644
--- a/drivers/staging/mt7621-eth/mtk_eth_soc.c
+++ b/drivers/staging/mt7621-eth/mtk_eth_soc.c
@@ -2167,7 +2167,6 @@ static struct platform_driver mtk_driver = {
2167 .remove = mtk_remove, 2167 .remove = mtk_remove,
2168 .driver = { 2168 .driver = {
2169 .name = "mtk_soc_eth", 2169 .name = "mtk_soc_eth",
2170 .owner = THIS_MODULE,
2171 .of_match_table = of_mtk_match, 2170 .of_match_table = of_mtk_match,
2172 }, 2171 },
2173}; 2172};
diff --git a/drivers/staging/mt7621-mmc/dbg.c b/drivers/staging/mt7621-mmc/dbg.c
index 6e518dce9029..829d3d0e895e 100644
--- a/drivers/staging/mt7621-mmc/dbg.c
+++ b/drivers/staging/mt7621-mmc/dbg.c
@@ -5,7 +5,8 @@
5 * is confidential and proprietary to MediaTek Inc. and/or its licensors. 5 * is confidential and proprietary to MediaTek Inc. and/or its licensors.
6 * Without the prior written permission of MediaTek inc. and/or its licensors, 6 * Without the prior written permission of MediaTek inc. and/or its licensors,
7 * any reproduction, modification, use or disclosure of MediaTek Software, 7 * any reproduction, modification, use or disclosure of MediaTek Software,
8 * and information contained herein, in whole or in part, shall be strictly prohibited. 8 * and information contained herein, in whole or in part, shall be strictly
9 * prohibited.
9 * 10 *
10 * MediaTek Inc. (C) 2010. All rights reserved. 11 * MediaTek Inc. (C) 2010. All rights reserved.
11 * 12 *
@@ -17,20 +18,22 @@
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
18 * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE 19 * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
19 * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR 20 * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
20 * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH 21 * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO
21 * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES 22 * SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY
22 * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES 23 * ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY
23 * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK 24 * THIRD PARTY ALL PROPER LICENSES CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK
24 * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR 25 * SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO
25 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND 26 * RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN
26 * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, 27 * FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
27 * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, 28 * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED
28 * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO 29 * HEREUNDER WILL BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK
29 * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 30 * SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE
31 * PAID BY RECEIVER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
30 * 32 *
31 * The following software/firmware and/or related documentation ("MediaTek Software") 33 * The following software/firmware and/or related documentation
32 * have been modified by MediaTek Inc. All revisions are subject to any receiver's 34 * ("MediaTek Software") have been modified by MediaTek Inc. All revisions
33 * applicable license agreements with MediaTek Inc. 35 * are subject to any receiver's applicable license agreements with MediaTek
36 * Inc.
34 */ 37 */
35 38
36#include <linux/version.h> 39#include <linux/version.h>
@@ -66,23 +69,6 @@ u32 sdio_pro_enable; /* make sure gpt is enabled */
66u32 sdio_pro_time; /* no more than 30s */ 69u32 sdio_pro_time; /* no more than 30s */
67struct sdio_profile sdio_perfomance = {0}; 70struct sdio_profile sdio_perfomance = {0};
68 71
69#if 0 /* --- chhung */
70void msdc_init_gpt(void)
71{
72 GPT_CONFIG config;
73
74 config.num = GPT6;
75 config.mode = GPT_FREE_RUN;
76 config.clkSrc = GPT_CLK_SRC_SYS;
77 config.clkDiv = GPT_CLK_DIV_1; /* 13MHz GPT6 */
78
79 if (GPT_Config(config) == FALSE)
80 return;
81
82 GPT_Start(GPT6);
83}
84#endif /* end of --- */
85
86u32 msdc_time_calc(u32 old_L32, u32 old_H32, u32 new_L32, u32 new_H32) 72u32 msdc_time_calc(u32 old_L32, u32 old_H32, u32 new_L32, u32 new_H32)
87{ 73{
88 u32 ret = 0; 74 u32 ret = 0;
@@ -91,7 +77,8 @@ u32 msdc_time_calc(u32 old_L32, u32 old_H32, u32 new_L32, u32 new_H32)
91 ret = new_L32 - old_L32; 77 ret = new_L32 - old_L32;
92 } else if (new_H32 == (old_H32 + 1)) { 78 } else if (new_H32 == (old_H32 + 1)) {
93 if (new_L32 > old_L32) 79 if (new_L32 > old_L32)
94 pr_debug("msdc old_L<0x%x> new_L<0x%x>\n", old_L32, new_L32); 80 pr_debug("msdc old_L<0x%x> new_L<0x%x>\n",
81 old_L32, new_L32);
95 ret = (0xffffffff - old_L32); 82 ret = (0xffffffff - old_L32);
96 ret += new_L32; 83 ret += new_L32;
97 } else { 84 } else {
@@ -113,27 +100,33 @@ void msdc_sdio_profile(struct sdio_profile *result)
113 100
114 /* CMD52 Dump */ 101 /* CMD52 Dump */
115 cmd = &result->cmd52_rx; 102 cmd = &result->cmd52_rx;
116 pr_debug("sdio === CMD52 Rx <%d>times tick<%d> Max<%d> Min<%d> Aver<%d>\n", cmd->count, cmd->tot_tc, 103 pr_debug("sdio === CMD52 Rx <%d>times tick<%d> Max<%d> Min<%d> Aver<%d>\n",
117 cmd->max_tc, cmd->min_tc, cmd->tot_tc / cmd->count); 104 cmd->count, cmd->tot_tc, cmd->max_tc, cmd->min_tc,
105 cmd->tot_tc / cmd->count);
118 cmd = &result->cmd52_tx; 106 cmd = &result->cmd52_tx;
119 pr_debug("sdio === CMD52 Tx <%d>times tick<%d> Max<%d> Min<%d> Aver<%d>\n", cmd->count, cmd->tot_tc, 107 pr_debug("sdio === CMD52 Tx <%d>times tick<%d> Max<%d> Min<%d> Aver<%d>\n",
120 cmd->max_tc, cmd->min_tc, cmd->tot_tc / cmd->count); 108 cmd->count, cmd->tot_tc, cmd->max_tc, cmd->min_tc,
109 cmd->tot_tc / cmd->count);
121 110
122 /* CMD53 Rx bytes + block mode */ 111 /* CMD53 Rx bytes + block mode */
123 for (i = 0; i < 512; i++) { 112 for (i = 0; i < 512; i++) {
124 cmd = &result->cmd53_rx_byte[i]; 113 cmd = &result->cmd53_rx_byte[i];
125 if (cmd->count) { 114 if (cmd->count) {
126 pr_debug("sdio<%6d><%3dB>_Rx_<%9d><%9d><%6d><%6d>_<%9dB><%2dM>\n", cmd->count, i, cmd->tot_tc, 115 pr_debug("sdio<%6d><%3dB>_Rx_<%9d><%9d><%6d><%6d>_<%9dB><%2dM>\n",
127 cmd->max_tc, cmd->min_tc, cmd->tot_tc / cmd->count, 116 cmd->count, i, cmd->tot_tc, cmd->max_tc,
128 cmd->tot_bytes, (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10)); 117 cmd->min_tc, cmd->tot_tc / cmd->count,
118 cmd->tot_bytes,
119 (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10));
129 } 120 }
130 } 121 }
131 for (i = 0; i < 100; i++) { 122 for (i = 0; i < 100; i++) {
132 cmd = &result->cmd53_rx_blk[i]; 123 cmd = &result->cmd53_rx_blk[i];
133 if (cmd->count) { 124 if (cmd->count) {
134 pr_debug("sdio<%6d><%3d>B_Rx_<%9d><%9d><%6d><%6d>_<%9dB><%2dM>\n", cmd->count, i, cmd->tot_tc, 125 pr_debug("sdio<%6d><%3d>B_Rx_<%9d><%9d><%6d><%6d>_<%9dB><%2dM>\n",
135 cmd->max_tc, cmd->min_tc, cmd->tot_tc / cmd->count, 126 cmd->count, i, cmd->tot_tc, cmd->max_tc,
136 cmd->tot_bytes, (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10)); 127 cmd->min_tc, cmd->tot_tc / cmd->count,
128 cmd->tot_bytes,
129 (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10));
137 } 130 }
138 } 131 }
139 132
@@ -141,17 +134,21 @@ void msdc_sdio_profile(struct sdio_profile *result)
141 for (i = 0; i < 512; i++) { 134 for (i = 0; i < 512; i++) {
142 cmd = &result->cmd53_tx_byte[i]; 135 cmd = &result->cmd53_tx_byte[i];
143 if (cmd->count) { 136 if (cmd->count) {
144 pr_debug("sdio<%6d><%3dB>_Tx_<%9d><%9d><%6d><%6d>_<%9dB><%2dM>\n", cmd->count, i, cmd->tot_tc, 137 pr_debug("sdio<%6d><%3dB>_Tx_<%9d><%9d><%6d><%6d>_<%9dB><%2dM>\n",
145 cmd->max_tc, cmd->min_tc, cmd->tot_tc / cmd->count, 138 cmd->count, i, cmd->tot_tc, cmd->max_tc,
146 cmd->tot_bytes, (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10)); 139 cmd->min_tc, cmd->tot_tc / cmd->count,
140 cmd->tot_bytes,
141 (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10));
147 } 142 }
148 } 143 }
149 for (i = 0; i < 100; i++) { 144 for (i = 0; i < 100; i++) {
150 cmd = &result->cmd53_tx_blk[i]; 145 cmd = &result->cmd53_tx_blk[i];
151 if (cmd->count) { 146 if (cmd->count) {
152 pr_debug("sdio<%6d><%3d>B_Tx_<%9d><%9d><%6d><%6d>_<%9dB><%2dM>\n", cmd->count, i, cmd->tot_tc, 147 pr_debug("sdio<%6d><%3d>B_Tx_<%9d><%9d><%6d><%6d>_<%9dB><%2dM>\n",
153 cmd->max_tc, cmd->min_tc, cmd->tot_tc / cmd->count, 148 cmd->count, i, cmd->tot_tc, cmd->max_tc,
154 cmd->tot_bytes, (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10)); 149 cmd->min_tc, cmd->tot_tc / cmd->count,
150 cmd->tot_bytes,
151 (cmd->tot_bytes / 10) * 13 / (cmd->tot_tc / 10));
155 } 152 }
156 } 153 }
157 154
@@ -222,7 +219,8 @@ static int msdc_debug_proc_read(struct seq_file *s, void *p)
222 219
223 seq_puts(s, "Index<3> + SDIO_PROFILE + TIME\n"); 220 seq_puts(s, "Index<3> + SDIO_PROFILE + TIME\n");
224 seq_puts(s, "-> echo 3 1 0x1E >msdc_bebug -> enable sdio_profile, 30s\n"); 221 seq_puts(s, "-> echo 3 1 0x1E >msdc_bebug -> enable sdio_profile, 30s\n");
225 seq_printf(s, "-> SDIO_PROFILE<%d> TIME<%ds>\n", sdio_pro_enable, sdio_pro_time); 222 seq_printf(s, "-> SDIO_PROFILE<%d> TIME<%ds>\n",
223 sdio_pro_enable, sdio_pro_time);
226 seq_puts(s, "=========================================\n\n"); 224 seq_puts(s, "=========================================\n\n");
227 225
228 return 0; 226 return 0;
@@ -249,7 +247,9 @@ static ssize_t msdc_debug_proc_write(struct file *file,
249 cmd_buf[count] = '\0'; 247 cmd_buf[count] = '\0';
250 pr_debug("msdc Write %s\n", cmd_buf); 248 pr_debug("msdc Write %s\n", cmd_buf);
251 249
252 sscanf(cmd_buf, "%x %x %x", &cmd, &p1, &p2); 250 ret = sscanf(cmd_buf, "%x %x %x", &cmd, &p1, &p2);
251 if (ret != 3)
252 return -EINVAL;
253 253
254 if (cmd == SD_TOOL_ZONE) { 254 if (cmd == SD_TOOL_ZONE) {
255 id = p1; 255 id = p1;
@@ -266,10 +266,8 @@ static ssize_t msdc_debug_proc_write(struct file *file,
266 } 266 }
267 } else if (cmd == SD_TOOL_SDIO_PROFILE) { 267 } else if (cmd == SD_TOOL_SDIO_PROFILE) {
268 if (p1 == 1) { /* enable profile */ 268 if (p1 == 1) { /* enable profile */
269 if (gpt_enable == 0) { 269 if (gpt_enable == 0)
270 // msdc_init_gpt(); /* --- by chhung */
271 gpt_enable = 1; 270 gpt_enable = 1;
272 }
273 sdio_pro_enable = 1; 271 sdio_pro_enable = 1;
274 if (p2 == 0) 272 if (p2 == 0)
275 p2 = 1; 273 p2 = 1;
diff --git a/drivers/staging/mt7621-mmc/dbg.h b/drivers/staging/mt7621-mmc/dbg.h
index 2f2c56b73987..2d447b2d92ae 100644
--- a/drivers/staging/mt7621-mmc/dbg.h
+++ b/drivers/staging/mt7621-mmc/dbg.h
@@ -5,7 +5,8 @@
5 * is confidential and proprietary to MediaTek Inc. and/or its licensors. 5 * is confidential and proprietary to MediaTek Inc. and/or its licensors.
6 * Without the prior written permission of MediaTek inc. and/or its licensors, 6 * Without the prior written permission of MediaTek inc. and/or its licensors,
7 * any reproduction, modification, use or disclosure of MediaTek Software, 7 * any reproduction, modification, use or disclosure of MediaTek Software,
8 * and information contained herein, in whole or in part, shall be strictly prohibited. 8 * and information contained herein, in whole or in part, shall be strictly
9 * prohibited.
9 * 10 *
10 * MediaTek Inc. (C) 2010. All rights reserved. 11 * MediaTek Inc. (C) 2010. All rights reserved.
11 * 12 *
@@ -18,19 +19,20 @@
18 * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE 19 * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
19 * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR 20 * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
20 * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH 21 * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
21 * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES 22 * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY
22 * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES 23 * ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY
23 * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK 24 * THIRD PARTY ALL PROPER LICENSES CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK
24 * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR 25 * SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO
25 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND 26 * RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN
26 * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, 27 * FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
27 * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, 28 * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED
28 * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO 29 * HEREUNDER WILL BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK
29 * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 30 * SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE
31 * PAID BY RECEIVER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
30 * 32 *
31 * The following software/firmware and/or related documentation ("MediaTek Software") 33 * The following software/firmware and/or related documentation
32 * have been modified by MediaTek Inc. All revisions are subject to any receiver's 34 * ("MediaTek Software") have been modified by MediaTek Inc. All revisions are
33 * applicable license agreements with MediaTek Inc. 35 * subject to any receiver's applicable license agreements with MediaTek Inc.
34 */ 36 */
35#ifndef __MT_MSDC_DEUBG__ 37#ifndef __MT_MSDC_DEUBG__
36#define __MT_MSDC_DEUBG__ 38#define __MT_MSDC_DEUBG__
@@ -74,75 +76,25 @@ enum msdc_dbg {
74}; 76};
75 77
76/* Debug message event */ 78/* Debug message event */
77#define DBG_EVT_NONE (0) /* No event */ 79#define DBG_EVT_NONE (0) /* No event */
78#define DBG_EVT_DMA (1 << 0) /* DMA related event */ 80#define DBG_EVT_DMA BIT(0) /* DMA related event */
79#define DBG_EVT_CMD (1 << 1) /* MSDC CMD related event */ 81#define DBG_EVT_CMD BIT(1) /* MSDC CMD related event */
80#define DBG_EVT_RSP (1 << 2) /* MSDC CMD RSP related event */ 82#define DBG_EVT_RSP BIT(2) /* MSDC CMD RSP related event */
81#define DBG_EVT_INT (1 << 3) /* MSDC INT event */ 83#define DBG_EVT_INT BIT(3) /* MSDC INT event */
82#define DBG_EVT_CFG (1 << 4) /* MSDC CFG event */ 84#define DBG_EVT_CFG BIT(4) /* MSDC CFG event */
83#define DBG_EVT_FUC (1 << 5) /* Function event */ 85#define DBG_EVT_FUC BIT(5) /* Function event */
84#define DBG_EVT_OPS (1 << 6) /* Read/Write operation event */ 86#define DBG_EVT_OPS BIT(6) /* Read/Write operation event */
85#define DBG_EVT_FIO (1 << 7) /* FIFO operation event */ 87#define DBG_EVT_FIO BIT(7) /* FIFO operation event */
86#define DBG_EVT_WRN (1 << 8) /* Warning event */ 88#define DBG_EVT_WRN BIT(8) /* Warning event */
87#define DBG_EVT_PWR (1 << 9) /* Power event */ 89#define DBG_EVT_PWR BIT(9) /* Power event */
88#define DBG_EVT_ALL (0xffffffff) 90#define DBG_EVT_ALL (0xffffffff)
89 91
90#define DBG_EVT_MASK (DBG_EVT_ALL) 92#define DBG_EVT_MASK (DBG_EVT_ALL)
91 93
92extern unsigned int sd_debug_zone[4]; 94extern unsigned int sd_debug_zone[4];
93#define TAG "msdc" 95#define TAG "msdc"
94#if 0 /* +++ chhung */
95#define BUG_ON(x) \
96do { \
97 if (x) { \
98 printk("[BUG] %s LINE:%d FILE:%s\n", #x, __LINE__, __FILE__); \
99 while (1) \
100 ; \
101 } \
102} while (0)
103#endif /* end of +++ */
104
105#define N_MSG(evt, fmt, args...)
106/*
107do { \
108 if ((DBG_EVT_##evt) & sd_debug_zone[host->id]) { \
109 printk(KERN_ERR TAG"%d -> "fmt" <- %s() : L<%d> PID<%s><0x%x>\n", \
110 host->id, ##args , __FUNCTION__, __LINE__, current->comm, current->pid); \
111 } \
112} while(0)
113*/
114
115#define ERR_MSG(fmt, args...) \
116do { \
117 printk(KERN_ERR TAG"%d -> "fmt" <- %s() : L<%d> PID<%s><0x%x>\n", \
118 host->id, ##args, __FUNCTION__, __LINE__, current->comm, current->pid); \
119} while (0);
120
121#if 1
122//defined CONFIG_MTK_MMC_CD_POLL
123#define INIT_MSG(fmt, args...)
124#define IRQ_MSG(fmt, args...)
125#else
126#define INIT_MSG(fmt, args...) \
127do { \
128 printk(KERN_ERR TAG"%d -> "fmt" <- %s() : L<%d> PID<%s><0x%x>\n", \
129 host->id, ##args, __FUNCTION__, __LINE__, current->comm, current->pid); \
130} while (0);
131
132/* PID in ISR in not corrent */
133#define IRQ_MSG(fmt, args...) \
134do { \
135 printk(KERN_ERR TAG"%d -> "fmt" <- %s() : L<%d>\n", \
136 host->id, ##args, __FUNCTION__, __LINE__); \
137} while (0);
138#endif
139
140void msdc_debug_proc_init(void); 96void msdc_debug_proc_init(void);
141 97
142#if 0 /* --- chhung */
143void msdc_init_gpt(void);
144extern void GPT_GetCounter64(UINT32 *cntL32, UINT32 *cntH32);
145#endif /* end of --- */
146u32 msdc_time_calc(u32 old_L32, u32 old_H32, u32 new_L32, u32 new_H32); 98u32 msdc_time_calc(u32 old_L32, u32 old_H32, u32 new_L32, u32 new_H32);
147void msdc_performance(u32 opcode, u32 sizes, u32 bRx, u32 ticks); 99void msdc_performance(u32 opcode, u32 sizes, u32 bRx, u32 ticks);
148 100
diff --git a/drivers/staging/mt7621-mmc/sd.c b/drivers/staging/mt7621-mmc/sd.c
index 04d23cc7cd4a..0379f9c96f2a 100644
--- a/drivers/staging/mt7621-mmc/sd.c
+++ b/drivers/staging/mt7621-mmc/sd.c
@@ -72,11 +72,6 @@
72#define GPIO_PULL_DOWN (0) 72#define GPIO_PULL_DOWN (0)
73#define GPIO_PULL_UP (1) 73#define GPIO_PULL_UP (1)
74 74
75#if 0 /* --- by chhung */
76#define MSDC_CLKSRC_REG (0xf100000C)
77#define PDN_REG (0xF1000010)
78#endif /* end of --- */
79
80#define DEFAULT_DEBOUNCE (8) /* 8 cycles */ 75#define DEFAULT_DEBOUNCE (8) /* 8 cycles */
81#define DEFAULT_DTOC (40) /* data timeout counter. 65536x40 sclk. */ 76#define DEFAULT_DTOC (40) /* data timeout counter. 65536x40 sclk. */
82 77
@@ -100,26 +95,6 @@ static int cd_active_low = 1;
100//#define PERI_MSDC2_PDN (17) 95//#define PERI_MSDC2_PDN (17)
101//#define PERI_MSDC3_PDN (18) 96//#define PERI_MSDC3_PDN (18)
102 97
103#if 0 /* --- by chhung */
104/* gate means clock power down */
105static int g_clk_gate = 0;
106#define msdc_gate_clock(id) \
107 do { \
108 g_clk_gate &= ~(1 << ((id) + PERI_MSDC0_PDN)); \
109 } while (0)
110/* not like power down register. 1 means clock on. */
111#define msdc_ungate_clock(id) \
112 do { \
113 g_clk_gate |= 1 << ((id) + PERI_MSDC0_PDN); \
114 } while (0)
115
116// do we need sync object or not
117void msdc_clk_status(int *status)
118{
119 *status = g_clk_gate;
120}
121#endif /* end of --- */
122
123/* +++ by chhung */ 98/* +++ by chhung */
124struct msdc_hw msdc0_hw = { 99struct msdc_hw msdc0_hw = {
125 .clk_src = 0, 100 .clk_src = 0,
@@ -169,11 +144,6 @@ static void msdc_clr_fifo(struct msdc_host *host)
169 sdr_clr_bits(host->base + MSDC_INTEN, val); \ 144 sdr_clr_bits(host->base + MSDC_INTEN, val); \
170 } while (0) 145 } while (0)
171 146
172#define msdc_irq_restore(val) \
173 do { \
174 sdr_set_bits(host->base + MSDC_INTEN, val); \
175 } while (0)
176
177/* clock source for host: global */ 147/* clock source for host: global */
178#if defined(CONFIG_SOC_MT7620) 148#if defined(CONFIG_SOC_MT7620)
179static u32 hclks[] = {48000000}; /* +/- by chhung */ 149static u32 hclks[] = {48000000}; /* +/- by chhung */
@@ -181,34 +151,6 @@ static u32 hclks[] = {48000000}; /* +/- by chhung */
181static u32 hclks[] = {50000000}; /* +/- by chhung */ 151static u32 hclks[] = {50000000}; /* +/- by chhung */
182#endif 152#endif
183 153
184//============================================
185// the power for msdc host controller: global
186// always keep the VMC on.
187//============================================
188#define msdc_vcore_on(host) \
189 do { \
190 INIT_MSG("[+]VMC ref. count<%d>", ++host->pwr_ref); \
191 (void)hwPowerOn(MT65XX_POWER_LDO_VMC, VOL_3300, "SD"); \
192 } while (0)
193#define msdc_vcore_off(host) \
194 do { \
195 INIT_MSG("[-]VMC ref. count<%d>", --host->pwr_ref); \
196 (void)hwPowerDown(MT65XX_POWER_LDO_VMC, "SD"); \
197 } while (0)
198
199//====================================
200// the vdd output for card: global
201// always keep the VMCH on.
202//====================================
203#define msdc_vdd_on(host) \
204 do { \
205 (void)hwPowerOn(MT65XX_POWER_LDO_VMCH, VOL_3300, "SD"); \
206 } while (0)
207#define msdc_vdd_off(host) \
208 do { \
209 (void)hwPowerDown(MT65XX_POWER_LDO_VMCH, "SD"); \
210 } while (0)
211
212#define sdc_is_busy() (readl(host->base + SDC_STS) & SDC_STS_SDCBUSY) 154#define sdc_is_busy() (readl(host->base + SDC_STS) & SDC_STS_SDCBUSY)
213#define sdc_is_cmd_busy() (readl(host->base + SDC_STS) & SDC_STS_CMDBUSY) 155#define sdc_is_cmd_busy() (readl(host->base + SDC_STS) & SDC_STS_CMDBUSY)
214 156
@@ -232,144 +174,6 @@ static unsigned int msdc_do_command(struct msdc_host *host,
232 174
233static int msdc_tune_cmdrsp(struct msdc_host *host, struct mmc_command *cmd); 175static int msdc_tune_cmdrsp(struct msdc_host *host, struct mmc_command *cmd);
234 176
235#ifdef MT6575_SD_DEBUG
236static void msdc_dump_card_status(struct msdc_host *host, u32 status)
237{
238/* N_MSG is currently a no-op */
239#if 0
240 static char *state[] = {
241 "Idle", /* 0 */
242 "Ready", /* 1 */
243 "Ident", /* 2 */
244 "Stby", /* 3 */
245 "Tran", /* 4 */
246 "Data", /* 5 */
247 "Rcv", /* 6 */
248 "Prg", /* 7 */
249 "Dis", /* 8 */
250 "Reserved", /* 9 */
251 "Reserved", /* 10 */
252 "Reserved", /* 11 */
253 "Reserved", /* 12 */
254 "Reserved", /* 13 */
255 "Reserved", /* 14 */
256 "I/O mode", /* 15 */
257 };
258#endif
259 if (status & R1_OUT_OF_RANGE)
260 N_MSG(RSP, "[CARD_STATUS] Out of Range");
261 if (status & R1_ADDRESS_ERROR)
262 N_MSG(RSP, "[CARD_STATUS] Address Error");
263 if (status & R1_BLOCK_LEN_ERROR)
264 N_MSG(RSP, "[CARD_STATUS] Block Len Error");
265 if (status & R1_ERASE_SEQ_ERROR)
266 N_MSG(RSP, "[CARD_STATUS] Erase Seq Error");
267 if (status & R1_ERASE_PARAM)
268 N_MSG(RSP, "[CARD_STATUS] Erase Param");
269 if (status & R1_WP_VIOLATION)
270 N_MSG(RSP, "[CARD_STATUS] WP Violation");
271 if (status & R1_CARD_IS_LOCKED)
272 N_MSG(RSP, "[CARD_STATUS] Card is Locked");
273 if (status & R1_LOCK_UNLOCK_FAILED)
274 N_MSG(RSP, "[CARD_STATUS] Lock/Unlock Failed");
275 if (status & R1_COM_CRC_ERROR)
276 N_MSG(RSP, "[CARD_STATUS] Command CRC Error");
277 if (status & R1_ILLEGAL_COMMAND)
278 N_MSG(RSP, "[CARD_STATUS] Illegal Command");
279 if (status & R1_CARD_ECC_FAILED)
280 N_MSG(RSP, "[CARD_STATUS] Card ECC Failed");
281 if (status & R1_CC_ERROR)
282 N_MSG(RSP, "[CARD_STATUS] CC Error");
283 if (status & R1_ERROR)
284 N_MSG(RSP, "[CARD_STATUS] Error");
285 if (status & R1_UNDERRUN)
286 N_MSG(RSP, "[CARD_STATUS] Underrun");
287 if (status & R1_OVERRUN)
288 N_MSG(RSP, "[CARD_STATUS] Overrun");
289 if (status & R1_CID_CSD_OVERWRITE)
290 N_MSG(RSP, "[CARD_STATUS] CID/CSD Overwrite");
291 if (status & R1_WP_ERASE_SKIP)
292 N_MSG(RSP, "[CARD_STATUS] WP Eraser Skip");
293 if (status & R1_CARD_ECC_DISABLED)
294 N_MSG(RSP, "[CARD_STATUS] Card ECC Disabled");
295 if (status & R1_ERASE_RESET)
296 N_MSG(RSP, "[CARD_STATUS] Erase Reset");
297 if (status & R1_READY_FOR_DATA)
298 N_MSG(RSP, "[CARD_STATUS] Ready for Data");
299 if (status & R1_SWITCH_ERROR)
300 N_MSG(RSP, "[CARD_STATUS] Switch error");
301 if (status & R1_APP_CMD)
302 N_MSG(RSP, "[CARD_STATUS] App Command");
303
304 N_MSG(RSP, "[CARD_STATUS] '%s' State", state[R1_CURRENT_STATE(status)]);
305}
306
307static void msdc_dump_ocr_reg(struct msdc_host *host, u32 resp)
308{
309 if (resp & (1 << 7))
310 N_MSG(RSP, "[OCR] Low Voltage Range");
311 if (resp & (1 << 15))
312 N_MSG(RSP, "[OCR] 2.7-2.8 volt");
313 if (resp & (1 << 16))
314 N_MSG(RSP, "[OCR] 2.8-2.9 volt");
315 if (resp & (1 << 17))
316 N_MSG(RSP, "[OCR] 2.9-3.0 volt");
317 if (resp & (1 << 18))
318 N_MSG(RSP, "[OCR] 3.0-3.1 volt");
319 if (resp & (1 << 19))
320 N_MSG(RSP, "[OCR] 3.1-3.2 volt");
321 if (resp & (1 << 20))
322 N_MSG(RSP, "[OCR] 3.2-3.3 volt");
323 if (resp & (1 << 21))
324 N_MSG(RSP, "[OCR] 3.3-3.4 volt");
325 if (resp & (1 << 22))
326 N_MSG(RSP, "[OCR] 3.4-3.5 volt");
327 if (resp & (1 << 23))
328 N_MSG(RSP, "[OCR] 3.5-3.6 volt");
329 if (resp & (1 << 24))
330 N_MSG(RSP, "[OCR] Switching to 1.8V Accepted (S18A)");
331 if (resp & (1 << 30))
332 N_MSG(RSP, "[OCR] Card Capacity Status (CCS)");
333 if (resp & (1 << 31))
334 N_MSG(RSP, "[OCR] Card Power Up Status (Idle)");
335 else
336 N_MSG(RSP, "[OCR] Card Power Up Status (Busy)");
337}
338
339static void msdc_dump_rca_resp(struct msdc_host *host, u32 resp)
340{
341 u32 status = (((resp >> 15) & 0x1) << 23) |
342 (((resp >> 14) & 0x1) << 22) |
343 (((resp >> 13) & 0x1) << 19) |
344 (resp & 0x1fff);
345
346 N_MSG(RSP, "[RCA] 0x%.4x", resp >> 16);
347 msdc_dump_card_status(host, status);
348}
349
350static void msdc_dump_io_resp(struct msdc_host *host, u32 resp)
351{
352 u32 flags = (resp >> 8) & 0xFF;
353#if 0
354 char *state[] = {"DIS", "CMD", "TRN", "RFU"};
355#endif
356 if (flags & (1 << 7))
357 N_MSG(RSP, "[IO] COM_CRC_ERR");
358 if (flags & (1 << 6))
359 N_MSG(RSP, "[IO] Illegal command");
360 if (flags & (1 << 3))
361 N_MSG(RSP, "[IO] Error");
362 if (flags & (1 << 2))
363 N_MSG(RSP, "[IO] RFU");
364 if (flags & (1 << 1))
365 N_MSG(RSP, "[IO] Function number error");
366 if (flags & (1 << 0))
367 N_MSG(RSP, "[IO] Out of range");
368
369 N_MSG(RSP, "[IO] State: %s, Data:0x%x", state[(resp >> 12) & 0x3], resp & 0xFF);
370}
371#endif
372
373static void msdc_set_timeout(struct msdc_host *host, u32 ns, u32 clks) 177static void msdc_set_timeout(struct msdc_host *host, u32 ns, u32 clks)
374{ 178{
375 u32 timeout, clk_ns; 179 u32 timeout, clk_ns;
@@ -384,9 +188,6 @@ static void msdc_set_timeout(struct msdc_host *host, u32 ns, u32 clks)
384 timeout = timeout > 255 ? 255 : timeout; 188 timeout = timeout > 255 ? 255 : timeout;
385 189
386 sdr_set_field(host->base + SDC_CFG, SDC_CFG_DTOC, timeout); 190 sdr_set_field(host->base + SDC_CFG, SDC_CFG_DTOC, timeout);
387
388 N_MSG(OPS, "Set read data timeout: %dns %dclks -> %d x 65536 cycles",
389 ns, clks, timeout + 1);
390} 191}
391 192
392static void msdc_tasklet_card(struct work_struct *work) 193static void msdc_tasklet_card(struct work_struct *work)
@@ -395,7 +196,6 @@ static void msdc_tasklet_card(struct work_struct *work)
395 struct msdc_host, card_delaywork.work); 196 struct msdc_host, card_delaywork.work);
396 u32 inserted; 197 u32 inserted;
397 u32 status = 0; 198 u32 status = 0;
398 //u32 change = 0;
399 199
400 spin_lock(&host->lock); 200 spin_lock(&host->lock);
401 201
@@ -405,16 +205,7 @@ static void msdc_tasklet_card(struct work_struct *work)
405 else 205 else
406 inserted = (status & MSDC_PS_CDSTS) ? 1 : 0; 206 inserted = (status & MSDC_PS_CDSTS) ? 1 : 0;
407 207
408#if 0 208 /* Make sure: handle the last interrupt */
409 change = host->card_inserted ^ inserted;
410 host->card_inserted = inserted;
411
412 if (change && !host->suspend) {
413 if (inserted)
414 host->mmc->f_max = HOST_MAX_MCLK; // work around
415 mmc_detect_change(host->mmc, msecs_to_jiffies(20));
416 }
417#else /* Make sure: handle the last interrupt */
418 host->card_inserted = inserted; 209 host->card_inserted = inserted;
419 210
420 if (!host->suspend) { 211 if (!host->suspend) {
@@ -422,24 +213,14 @@ static void msdc_tasklet_card(struct work_struct *work)
422 mmc_detect_change(host->mmc, msecs_to_jiffies(20)); 213 mmc_detect_change(host->mmc, msecs_to_jiffies(20));
423 } 214 }
424 215
425 IRQ_MSG("card found<%s>", inserted ? "inserted" : "removed");
426#endif
427
428 spin_unlock(&host->lock); 216 spin_unlock(&host->lock);
429} 217}
430 218
431#if 0 /* --- by chhung */
432/* For E2 only */
433static u8 clk_src_bit[4] = {
434 0, 3, 5, 7
435};
436
437static void msdc_select_clksrc(struct msdc_host *host, unsigned char clksrc) 219static void msdc_select_clksrc(struct msdc_host *host, unsigned char clksrc)
438{ 220{
439 u32 val; 221 u32 val;
440 222
441 BUG_ON(clksrc > 3); 223 BUG_ON(clksrc > 3);
442 INIT_MSG("set clock source to <%d>", clksrc);
443 224
444 val = readl(host->base + MSDC_CLKSRC_REG); 225 val = readl(host->base + MSDC_CLKSRC_REG);
445 if (readl(host->base + MSDC_ECO_VER) >= 4) { 226 if (readl(host->base + MSDC_ECO_VER) >= 4) {
@@ -466,7 +247,6 @@ static void msdc_set_mclk(struct msdc_host *host, int ddr, unsigned int hz)
466 //u8 clksrc = hw->clk_src; 247 //u8 clksrc = hw->clk_src;
467 248
468 if (!hz) { // set mmc system clock to 0 ? 249 if (!hz) { // set mmc system clock to 0 ?
469 //ERR_MSG("set mclk to 0!!!");
470 msdc_reset_hw(host); 250 msdc_reset_hw(host);
471 return; 251 return;
472 } 252 }
@@ -509,11 +289,7 @@ static void msdc_set_mclk(struct msdc_host *host, int ddr, unsigned int hz)
509 host->mclk = hz; 289 host->mclk = hz;
510 msdc_set_timeout(host, host->timeout_ns, host->timeout_clks); // need? 290 msdc_set_timeout(host, host->timeout_ns, host->timeout_clks); // need?
511 291
512 INIT_MSG("================"); 292 sdr_set_bits(host->base + MSDC_INTEN, flags);
513 INIT_MSG("!!! Set<%dKHz> Source<%dKHz> -> sclk<%dKHz>", hz / 1000, hclk / 1000, sclk / 1000);
514 INIT_MSG("================");
515
516 msdc_irq_restore(flags);
517} 293}
518 294
519/* Fix me. when need to abort */ 295/* Fix me. when need to abort */
@@ -521,7 +297,7 @@ static void msdc_abort_data(struct msdc_host *host)
521{ 297{
522 struct mmc_command *stop = host->mrq->stop; 298 struct mmc_command *stop = host->mrq->stop;
523 299
524 ERR_MSG("Need to Abort."); 300 dev_err(mmc_dev(host->mmc), "%d -> Need to Abort.\n", host->id);
525 301
526 msdc_reset_hw(host); 302 msdc_reset_hw(host);
527 msdc_clr_fifo(host); 303 msdc_clr_fifo(host);
@@ -530,7 +306,8 @@ static void msdc_abort_data(struct msdc_host *host)
530 // need to check FIFO count 0 ? 306 // need to check FIFO count 0 ?
531 307
532 if (stop) { /* try to stop, but may not success */ 308 if (stop) { /* try to stop, but may not success */
533 ERR_MSG("stop when abort CMD<%d>", stop->opcode); 309 dev_err(mmc_dev(host->mmc), "%d -> stop when abort CMD<%d>\n",
310 host->id, stop->opcode);
534 (void)msdc_do_command(host, stop, 0, CMD_TIMEOUT); 311 (void)msdc_do_command(host, stop, 0, CMD_TIMEOUT);
535 } 312 }
536 313
@@ -539,126 +316,6 @@ static void msdc_abort_data(struct msdc_host *host)
539 //} 316 //}
540} 317}
541 318
542#if 0 /* --- by chhung */
543static void msdc_pin_config(struct msdc_host *host, int mode)
544{
545 struct msdc_hw *hw = host->hw;
546 int pull = (mode == MSDC_PIN_PULL_UP) ? GPIO_PULL_UP : GPIO_PULL_DOWN;
547
548 /* Config WP pin */
549 if (hw->flags & MSDC_WP_PIN_EN) {
550 if (hw->config_gpio_pin) /* NULL */
551 hw->config_gpio_pin(MSDC_WP_PIN, pull);
552 }
553
554 switch (mode) {
555 case MSDC_PIN_PULL_UP:
556 //sdr_set_field(MSDC_PAD_CTL0, MSDC_PAD_CTL0_CLKPU, 1); /* Check & FIXME */
557 //sdr_set_field(MSDC_PAD_CTL0, MSDC_PAD_CTL0_CLKPD, 0); /* Check & FIXME */
558 sdr_set_field(host->base + MSDC_PAD_CTL1, MSDC_PAD_CTL1_CMDPU, 1);
559 sdr_set_field(host->base + MSDC_PAD_CTL1, MSDC_PAD_CTL1_CMDPD, 0);
560 sdr_set_field(host->base + MSDC_PAD_CTL2, MSDC_PAD_CTL2_DATPU, 1);
561 sdr_set_field(host->base + MSDC_PAD_CTL2, MSDC_PAD_CTL2_DATPD, 0);
562 break;
563 case MSDC_PIN_PULL_DOWN:
564 //sdr_set_field(MSDC_PAD_CTL0, MSDC_PAD_CTL0_CLKPU, 0); /* Check & FIXME */
565 //sdr_set_field(MSDC_PAD_CTL0, MSDC_PAD_CTL0_CLKPD, 1); /* Check & FIXME */
566 sdr_set_field(host->base + MSDC_PAD_CTL1, MSDC_PAD_CTL1_CMDPU, 0);
567 sdr_set_field(host->base + MSDC_PAD_CTL1, MSDC_PAD_CTL1_CMDPD, 1);
568 sdr_set_field(host->base + MSDC_PAD_CTL2, MSDC_PAD_CTL2_DATPU, 0);
569 sdr_set_field(host->base + MSDC_PAD_CTL2, MSDC_PAD_CTL2_DATPD, 1);
570 break;
571 case MSDC_PIN_PULL_NONE:
572 default:
573 //sdr_set_field(MSDC_PAD_CTL0, MSDC_PAD_CTL0_CLKPU, 0); /* Check & FIXME */
574 //sdr_set_field(MSDC_PAD_CTL0, MSDC_PAD_CTL0_CLKPD, 0); /* Check & FIXME */
575 sdr_set_field(host->base + MSDC_PAD_CTL1, MSDC_PAD_CTL1_CMDPU, 0);
576 sdr_set_field(host->base + MSDC_PAD_CTL1, MSDC_PAD_CTL1_CMDPD, 0);
577 sdr_set_field(host->base + MSDC_PAD_CTL2, MSDC_PAD_CTL2_DATPU, 0);
578 sdr_set_field(host->base + MSDC_PAD_CTL2, MSDC_PAD_CTL2_DATPD, 0);
579 break;
580 }
581
582 N_MSG(CFG, "Pins mode(%d), down(%d), up(%d)",
583 mode, MSDC_PIN_PULL_DOWN, MSDC_PIN_PULL_UP);
584}
585
586void msdc_pin_reset(struct msdc_host *host, int mode)
587{
588 struct msdc_hw *hw = (struct msdc_hw *)host->hw;
589 int pull = (mode == MSDC_PIN_PULL_UP) ? GPIO_PULL_UP : GPIO_PULL_DOWN;
590
591 /* Config reset pin */
592 if (hw->flags & MSDC_RST_PIN_EN) {
593 if (hw->config_gpio_pin) /* NULL */
594 hw->config_gpio_pin(MSDC_RST_PIN, pull);
595
596 if (mode == MSDC_PIN_PULL_UP)
597 sdr_clr_bits(host->base + EMMC_IOCON, EMMC_IOCON_BOOTRST);
598 else
599 sdr_set_bits(host->base + EMMC_IOCON, EMMC_IOCON_BOOTRST);
600 }
601}
602
603static void msdc_core_power(struct msdc_host *host, int on)
604{
605 N_MSG(CFG, "Turn %s %s power (copower: %d -> %d)",
606 on ? "on" : "off", "core", host->core_power, on);
607
608 if (on && host->core_power == 0) {
609 msdc_vcore_on(host);
610 host->core_power = 1;
611 msleep(1);
612 } else if (!on && host->core_power == 1) {
613 msdc_vcore_off(host);
614 host->core_power = 0;
615 msleep(1);
616 }
617}
618
619static void msdc_host_power(struct msdc_host *host, int on)
620{
621 N_MSG(CFG, "Turn %s %s power ", on ? "on" : "off", "host");
622
623 if (on) {
624 //msdc_core_power(host, 1); // need do card detection.
625 msdc_pin_reset(host, MSDC_PIN_PULL_UP);
626 } else {
627 msdc_pin_reset(host, MSDC_PIN_PULL_DOWN);
628 //msdc_core_power(host, 0);
629 }
630}
631
632static void msdc_card_power(struct msdc_host *host, int on)
633{
634 N_MSG(CFG, "Turn %s %s power ", on ? "on" : "off", "card");
635
636 if (on) {
637 msdc_pin_config(host, MSDC_PIN_PULL_UP);
638 //msdc_vdd_on(host); // need todo card detection.
639 msleep(1);
640 } else {
641 //msdc_vdd_off(host);
642 msdc_pin_config(host, MSDC_PIN_PULL_DOWN);
643 msleep(1);
644 }
645}
646
647static void msdc_set_power_mode(struct msdc_host *host, u8 mode)
648{
649 N_MSG(CFG, "Set power mode(%d)", mode);
650
651 if (host->power_mode == MMC_POWER_OFF && mode != MMC_POWER_OFF) {
652 msdc_host_power(host, 1);
653 msdc_card_power(host, 1);
654 } else if (host->power_mode != MMC_POWER_OFF && mode == MMC_POWER_OFF) {
655 msdc_card_power(host, 0);
656 msdc_host_power(host, 0);
657 }
658 host->power_mode = mode;
659}
660#endif /* end of --- */
661
662#ifdef CONFIG_PM 319#ifdef CONFIG_PM
663/* 320/*
664 register as callback function of WIFI(combo_sdio_register_pm) . 321 register as callback function of WIFI(combo_sdio_register_pm) .
@@ -669,12 +326,6 @@ static void msdc_pm(pm_message_t state, void *data)
669 struct msdc_host *host = (struct msdc_host *)data; 326 struct msdc_host *host = (struct msdc_host *)data;
670 int evt = state.event; 327 int evt = state.event;
671 328
672 if (evt == PM_EVENT_USER_RESUME || evt == PM_EVENT_USER_SUSPEND) {
673 INIT_MSG("USR_%s: suspend<%d> power<%d>",
674 evt == PM_EVENT_USER_RESUME ? "EVENT_USER_RESUME" : "EVENT_USER_SUSPEND",
675 host->suspend, host->power_mode);
676 }
677
678 if (evt == PM_EVENT_SUSPEND || evt == PM_EVENT_USER_SUSPEND) { 329 if (evt == PM_EVENT_SUSPEND || evt == PM_EVENT_USER_SUSPEND) {
679 if (host->suspend) /* already suspend */ /* default 0*/ 330 if (host->suspend) /* already suspend */ /* default 0*/
680 return; 331 return;
@@ -687,14 +338,14 @@ static void msdc_pm(pm_message_t state, void *data)
687 host->pm_state = state; /* default PMSG_RESUME */ 338 host->pm_state = state; /* default PMSG_RESUME */
688 339
689 } else if (evt == PM_EVENT_RESUME || evt == PM_EVENT_USER_RESUME) { 340 } else if (evt == PM_EVENT_RESUME || evt == PM_EVENT_USER_RESUME) {
690 if (!host->suspend) { 341 if (!host->suspend)
691 //ERR_MSG("warning: already resume");
692 return; 342 return;
693 }
694 343
695 /* No PM resume when USR suspend */ 344 /* No PM resume when USR suspend */
696 if (evt == PM_EVENT_RESUME && host->pm_state.event == PM_EVENT_USER_SUSPEND) { 345 if (evt == PM_EVENT_RESUME && host->pm_state.event == PM_EVENT_USER_SUSPEND) {
697 ERR_MSG("PM Resume when in USR Suspend"); /* won't happen. */ 346 dev_err(mmc_dev(host->mmc),
347 "%d -> PM Resume when in USR Suspend\n",
348 host->id); /* won't happen. */
698 return; 349 return;
699 } 350 }
700 351
@@ -802,8 +453,6 @@ static unsigned int msdc_command_start(struct msdc_host *host,
802 rawcmd &= ~(0x0FFF << 16); 453 rawcmd &= ~(0x0FFF << 16);
803 } 454 }
804 455
805 N_MSG(CMD, "CMD<%d><0x%.8x> Arg<0x%.8x>", opcode, rawcmd, cmd->arg);
806
807 tmo = jiffies + timeout; 456 tmo = jiffies + timeout;
808 457
809 if (opcode == MMC_SEND_STATUS) { 458 if (opcode == MMC_SEND_STATUS) {
@@ -812,7 +461,9 @@ static unsigned int msdc_command_start(struct msdc_host *host,
812 break; 461 break;
813 462
814 if (time_after(jiffies, tmo)) { 463 if (time_after(jiffies, tmo)) {
815 ERR_MSG("XXX cmd_busy timeout: before CMD<%d>", opcode); 464 dev_err(mmc_dev(host->mmc),
465 "%d -> XXX cmd_busy timeout: before CMD<%d>\n",
466 host->id, opcode);
816 cmd->error = -ETIMEDOUT; 467 cmd->error = -ETIMEDOUT;
817 msdc_reset_hw(host); 468 msdc_reset_hw(host);
818 goto end; 469 goto end;
@@ -823,7 +474,9 @@ static unsigned int msdc_command_start(struct msdc_host *host,
823 if (!sdc_is_busy()) 474 if (!sdc_is_busy())
824 break; 475 break;
825 if (time_after(jiffies, tmo)) { 476 if (time_after(jiffies, tmo)) {
826 ERR_MSG("XXX sdc_busy timeout: before CMD<%d>", opcode); 477 dev_err(mmc_dev(host->mmc),
478 "%d -> XXX sdc_busy timeout: before CMD<%d>\n",
479 host->id, opcode);
827 cmd->error = -ETIMEDOUT; 480 cmd->error = -ETIMEDOUT;
828 msdc_reset_hw(host); 481 msdc_reset_hw(host);
829 goto end; 482 goto end;
@@ -862,7 +515,9 @@ static unsigned int msdc_command_resp(struct msdc_host *host,
862 515
863 spin_unlock(&host->lock); 516 spin_unlock(&host->lock);
864 if (!wait_for_completion_timeout(&host->cmd_done, 10 * timeout)) { 517 if (!wait_for_completion_timeout(&host->cmd_done, 10 * timeout)) {
865 ERR_MSG("XXX CMD<%d> wait_for_completion timeout ARG<0x%.8x>", opcode, cmd->arg); 518 dev_err(mmc_dev(host->mmc),
519 "%d -> XXX CMD<%d> wait_for_completion timeout ARG<0x%.8x>\n",
520 host->id, opcode, cmd->arg);
866 cmd->error = -ETIMEDOUT; 521 cmd->error = -ETIMEDOUT;
867 msdc_reset_hw(host); 522 msdc_reset_hw(host);
868 } 523 }
@@ -872,40 +527,6 @@ static unsigned int msdc_command_resp(struct msdc_host *host,
872 host->cmd = NULL; 527 host->cmd = NULL;
873 528
874//end: 529//end:
875#ifdef MT6575_SD_DEBUG
876 switch (resp) {
877 case RESP_NONE:
878 N_MSG(RSP, "CMD_RSP(%d): %d RSP(%d)", opcode, cmd->error, resp);
879 break;
880 case RESP_R2:
881 N_MSG(RSP, "CMD_RSP(%d): %d RSP(%d)= %.8x %.8x %.8x %.8x",
882 opcode, cmd->error, resp, cmd->resp[0], cmd->resp[1],
883 cmd->resp[2], cmd->resp[3]);
884 break;
885 default: /* Response types 1, 3, 4, 5, 6, 7(1b) */
886 N_MSG(RSP, "CMD_RSP(%d): %d RSP(%d)= 0x%.8x",
887 opcode, cmd->error, resp, cmd->resp[0]);
888 if (cmd->error == 0) {
889 switch (resp) {
890 case RESP_R1:
891 case RESP_R1B:
892 msdc_dump_card_status(host, cmd->resp[0]);
893 break;
894 case RESP_R3:
895 msdc_dump_ocr_reg(host, cmd->resp[0]);
896 break;
897 case RESP_R5:
898 msdc_dump_io_resp(host, cmd->resp[0]);
899 break;
900 case RESP_R6:
901 msdc_dump_rca_resp(host, cmd->resp[0]);
902 break;
903 }
904 }
905 break;
906 }
907#endif
908
909 /* do we need to save card's RCA when SD_SEND_RELATIVE_ADDR */ 530 /* do we need to save card's RCA when SD_SEND_RELATIVE_ADDR */
910 531
911 if (!tune) 532 if (!tune)
@@ -947,20 +568,9 @@ static unsigned int msdc_do_command(struct msdc_host *host,
947 568
948end: 569end:
949 570
950 N_MSG(CMD, " return<%d> resp<0x%.8x>", cmd->error, cmd->resp[0]);
951 return cmd->error; 571 return cmd->error;
952} 572}
953 573
954#if 0 /* --- by chhung */
955// DMA resume / start / stop
956static void msdc_dma_resume(struct msdc_host *host)
957{
958 sdr_set_field(host->base + MSDC_DMA_CTRL, MSDC_DMA_CTRL_RESUME, 1);
959
960 N_MSG(DMA, "DMA resume");
961}
962#endif /* end of --- */
963
964static void msdc_dma_start(struct msdc_host *host) 574static void msdc_dma_start(struct msdc_host *host)
965{ 575{
966 u32 wints = MSDC_INTEN_XFER_COMPL | MSDC_INTEN_DATTMO | MSDC_INTEN_DATCRCERR; 576 u32 wints = MSDC_INTEN_XFER_COMPL | MSDC_INTEN_DATTMO | MSDC_INTEN_DATCRCERR;
@@ -968,8 +578,6 @@ static void msdc_dma_start(struct msdc_host *host)
968 sdr_set_bits(host->base + MSDC_INTEN, wints); 578 sdr_set_bits(host->base + MSDC_INTEN, wints);
969 //dsb(); /* --- by chhung */ 579 //dsb(); /* --- by chhung */
970 sdr_set_field(host->base + MSDC_DMA_CTRL, MSDC_DMA_CTRL_START, 1); 580 sdr_set_field(host->base + MSDC_DMA_CTRL, MSDC_DMA_CTRL_START, 1);
971
972 N_MSG(DMA, "DMA start");
973} 581}
974 582
975static void msdc_dma_stop(struct msdc_host *host) 583static void msdc_dma_stop(struct msdc_host *host)
@@ -977,7 +585,6 @@ static void msdc_dma_stop(struct msdc_host *host)
977 //u32 retries=500; 585 //u32 retries=500;
978 u32 wints = MSDC_INTEN_XFER_COMPL | MSDC_INTEN_DATTMO | MSDC_INTEN_DATCRCERR; 586 u32 wints = MSDC_INTEN_XFER_COMPL | MSDC_INTEN_DATTMO | MSDC_INTEN_DATCRCERR;
979 587
980 N_MSG(DMA, "DMA status: 0x%.8x", readl(host->base + MSDC_DMA_CFG));
981 //while (readl(host->base + MSDC_DMA_CFG) & MSDC_DMA_CFG_STS); 588 //while (readl(host->base + MSDC_DMA_CFG) & MSDC_DMA_CFG_STS);
982 589
983 sdr_set_field(host->base + MSDC_DMA_CTRL, MSDC_DMA_CTRL_STOP, 1); 590 sdr_set_field(host->base + MSDC_DMA_CTRL, MSDC_DMA_CTRL_STOP, 1);
@@ -986,8 +593,6 @@ static void msdc_dma_stop(struct msdc_host *host)
986 593
987 //dsb(); /* --- by chhung */ 594 //dsb(); /* --- by chhung */
988 sdr_clr_bits(host->base + MSDC_INTEN, wints); /* Not just xfer_comp */ 595 sdr_clr_bits(host->base + MSDC_INTEN, wints); /* Not just xfer_comp */
989
990 N_MSG(DMA, "DMA stop");
991} 596}
992 597
993/* calc checksum */ 598/* calc checksum */
@@ -1010,8 +615,6 @@ static void msdc_dma_setup(struct msdc_host *host, struct msdc_dma *dma,
1010 615
1011 BUG_ON(sglen > MAX_BD_NUM); /* not support currently */ 616 BUG_ON(sglen > MAX_BD_NUM); /* not support currently */
1012 617
1013 N_MSG(DMA, "DMA sglen<%d> xfersz<%d>", sglen, host->xfer_size);
1014
1015 gpd = dma->gpd; 618 gpd = dma->gpd;
1016 bd = dma->bd; 619 bd = dma->bd;
1017 620
@@ -1044,10 +647,6 @@ static void msdc_dma_setup(struct msdc_host *host, struct msdc_dma *dma,
1044 sdr_set_field(host->base + MSDC_DMA_CTRL, MSDC_DMA_CTRL_MODE, 1); 647 sdr_set_field(host->base + MSDC_DMA_CTRL, MSDC_DMA_CTRL_MODE, 1);
1045 648
1046 writel(PHYSADDR((u32)dma->gpd_addr), host->base + MSDC_DMA_SA); 649 writel(PHYSADDR((u32)dma->gpd_addr), host->base + MSDC_DMA_SA);
1047
1048 N_MSG(DMA, "DMA_CTRL = 0x%x", readl(host->base + MSDC_DMA_CTRL));
1049 N_MSG(DMA, "DMA_CFG = 0x%x", readl(host->base + MSDC_DMA_CFG));
1050 N_MSG(DMA, "DMA_SA = 0x%x", readl(host->base + MSDC_DMA_SA));
1051} 650}
1052 651
1053static int msdc_do_request(struct mmc_host *mmc, struct mmc_request *mrq) 652static int msdc_do_request(struct mmc_host *mmc, struct mmc_request *mrq)
@@ -1062,21 +661,14 @@ static int msdc_do_request(struct mmc_host *mmc, struct mmc_request *mrq)
1062#define SND_DAT 0 661#define SND_DAT 0
1063#define SND_CMD 1 662#define SND_CMD 1
1064 663
1065 BUG_ON(mmc == NULL); 664 BUG_ON(!mmc);
1066 BUG_ON(mrq == NULL); 665 BUG_ON(!mrq);
1067 666
1068 host->error = 0; 667 host->error = 0;
1069 668
1070 cmd = mrq->cmd; 669 cmd = mrq->cmd;
1071 data = mrq->cmd->data; 670 data = mrq->cmd->data;
1072 671
1073#if 0 /* --- by chhung */
1074 //if(host->id ==1){
1075 N_MSG(OPS, "enable clock!");
1076 msdc_ungate_clock(host->id);
1077 //}
1078#endif /* end of --- */
1079
1080 if (!data) { 672 if (!data) {
1081 send_type = SND_CMD; 673 send_type = SND_CMD;
1082 if (msdc_do_command(host, cmd, 1, CMD_TIMEOUT) != 0) 674 if (msdc_do_command(host, cmd, 1, CMD_TIMEOUT) != 0)
@@ -1125,15 +717,22 @@ static int msdc_do_request(struct mmc_host *mmc, struct mmc_request *mrq)
1125 717
1126 spin_unlock(&host->lock); 718 spin_unlock(&host->lock);
1127 if (!wait_for_completion_timeout(&host->xfer_done, DAT_TIMEOUT)) { 719 if (!wait_for_completion_timeout(&host->xfer_done, DAT_TIMEOUT)) {
1128 ERR_MSG("XXX CMD<%d> wait xfer_done<%d> timeout!!", cmd->opcode, data->blocks * data->blksz); 720 dev_err(mmc_dev(host->mmc),
1129 ERR_MSG(" DMA_SA = 0x%x", 721 "%d -> XXX CMD<%d> wait xfer_done<%d> timeout!!\n",
1130 readl(host->base + MSDC_DMA_SA)); 722 host->id, cmd->opcode,
1131 ERR_MSG(" DMA_CA = 0x%x", 723 data->blocks * data->blksz);
1132 readl(host->base + MSDC_DMA_CA)); 724 dev_err(mmc_dev(host->mmc),
1133 ERR_MSG(" DMA_CTRL = 0x%x", 725 "%d -> DMA_SA = 0x%x\n",
1134 readl(host->base + MSDC_DMA_CTRL)); 726 host->id, readl(host->base + MSDC_DMA_SA));
1135 ERR_MSG(" DMA_CFG = 0x%x", 727 dev_err(mmc_dev(host->mmc),
1136 readl(host->base + MSDC_DMA_CFG)); 728 "%d -> DMA_CA = 0x%x\n",
729 host->id, readl(host->base + MSDC_DMA_CA));
730 dev_err(mmc_dev(host->mmc),
731 "%d -> DMA_CTRL = 0x%x\n",
732 host->id, readl(host->base + MSDC_DMA_CTRL));
733 dev_err(mmc_dev(host->mmc),
734 "%d -> DMA_CFG = 0x%x\n",
735 host->id, readl(host->base + MSDC_DMA_CFG));
1137 data->error = -ETIMEDOUT; 736 data->error = -ETIMEDOUT;
1138 737
1139 msdc_reset_hw(host); 738 msdc_reset_hw(host);
@@ -1151,48 +750,13 @@ static int msdc_do_request(struct mmc_host *mmc, struct mmc_request *mrq)
1151 } 750 }
1152 751
1153done: 752done:
1154 if (data != NULL) { 753 if (data) {
1155 host->data = NULL; 754 host->data = NULL;
1156 dma_unmap_sg(mmc_dev(mmc), data->sg, data->sg_len, 755 dma_unmap_sg(mmc_dev(mmc), data->sg, data->sg_len,
1157 mmc_get_dma_dir(data)); 756 mmc_get_dma_dir(data));
1158 host->blksz = 0; 757 host->blksz = 0;
1159
1160#if 0 // don't stop twice!
1161 if (host->hw->flags & MSDC_REMOVABLE && data->error) {
1162 msdc_abort_data(host);
1163 /* reset in IRQ, stop command has issued. -> No need */
1164 }
1165#endif
1166
1167 N_MSG(OPS, "CMD<%d> data<%s %s> blksz<%d> block<%d> error<%d>", cmd->opcode, (dma ? "dma" : "pio"),
1168 (read ? "read " : "write"), data->blksz, data->blocks, data->error);
1169 } 758 }
1170 759
1171#if 0 /* --- by chhung */
1172#if 1
1173 //if(host->id==1) {
1174 if (send_type == SND_CMD) {
1175 if (cmd->opcode == MMC_SEND_STATUS) {
1176 if ((cmd->resp[0] & CARD_READY_FOR_DATA) || (CARD_CURRENT_STATE(cmd->resp[0]) != 7)) {
1177 N_MSG(OPS, "disable clock, CMD13 IDLE");
1178 msdc_gate_clock(host->id);
1179 }
1180 } else {
1181 N_MSG(OPS, "disable clock, CMD<%d>", cmd->opcode);
1182 msdc_gate_clock(host->id);
1183 }
1184 } else {
1185 if (read) {
1186 N_MSG(OPS, "disable clock!!! Read CMD<%d>", cmd->opcode);
1187 msdc_gate_clock(host->id);
1188 }
1189 }
1190 //}
1191#else
1192 msdc_gate_clock(host->id);
1193#endif
1194#endif /* end of --- */
1195
1196 if (mrq->cmd->error) 760 if (mrq->cmd->error)
1197 host->error = 0x001; 761 host->error = 0x001;
1198 if (mrq->data && mrq->data->error) 762 if (mrq->data && mrq->data->error)
@@ -1200,8 +764,6 @@ done:
1200 if (mrq->stop && mrq->stop->error) 764 if (mrq->stop && mrq->stop->error)
1201 host->error |= 0x100; 765 host->error |= 0x100;
1202 766
1203 //if (host->error) ERR_MSG("host->error<%d>", host->error);
1204
1205 return host->error; 767 return host->error;
1206} 768}
1207 769
@@ -1213,11 +775,7 @@ static int msdc_app_cmd(struct mmc_host *mmc, struct msdc_host *host)
1213 775
1214 memset(&cmd, 0, sizeof(struct mmc_command)); 776 memset(&cmd, 0, sizeof(struct mmc_command));
1215 cmd.opcode = MMC_APP_CMD; 777 cmd.opcode = MMC_APP_CMD;
1216#if 0 /* bug: we meet mmc->card is null when ACMD6 */
1217 cmd.arg = mmc->card->rca << 16;
1218#else
1219 cmd.arg = host->app_cmd_arg; 778 cmd.arg = host->app_cmd_arg;
1220#endif
1221 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC; 779 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
1222 780
1223 memset(&mrq, 0, sizeof(struct mmc_request)); 781 memset(&mrq, 0, sizeof(struct mmc_request));
@@ -1260,19 +818,27 @@ static int msdc_tune_cmdrsp(struct msdc_host *host, struct mmc_command *cmd)
1260 if (host->app_cmd) { 818 if (host->app_cmd) {
1261 result = msdc_app_cmd(host->mmc, host); 819 result = msdc_app_cmd(host->mmc, host);
1262 if (result) { 820 if (result) {
1263 ERR_MSG("TUNE_CMD app_cmd<%d> failed: RESP_RXDLY<%d>,R_SMPL<%d>", 821 dev_err(mmc_dev(host->mmc),
1264 host->mrq->cmd->opcode, cur_rrdly, cur_rsmpl); 822 "%d -> TUNE_CMD app_cmd<%d> failed: RESP_RXDLY<%d>,R_SMPL<%d>\n",
823 host->id,
824 host->mrq->cmd->opcode,
825 cur_rrdly, cur_rsmpl);
1265 continue; 826 continue;
1266 } 827 }
1267 } 828 }
1268 result = msdc_do_command(host, cmd, 0, CMD_TIMEOUT); // not tune. 829 result = msdc_do_command(host, cmd, 0, CMD_TIMEOUT); // not tune.
1269 ERR_MSG("TUNE_CMD<%d> %s PAD_CMD_RESP_RXDLY[26:22]<%d> R_SMPL[1]<%d>", cmd->opcode, 830 dev_err(mmc_dev(host->mmc),
1270 (result == 0) ? "PASS" : "FAIL", cur_rrdly, cur_rsmpl); 831 "%d -> TUNE_CMD<%d> %s PAD_CMD_RESP_RXDLY[26:22]<%d> R_SMPL[1]<%d>\n",
832 host->id, cmd->opcode,
833 (result == 0) ? "PASS" : "FAIL", cur_rrdly,
834 cur_rsmpl);
1271 835
1272 if (result == 0) 836 if (result == 0)
1273 return 0; 837 return 0;
1274 if (result != -EIO) { 838 if (result != -EIO) {
1275 ERR_MSG("TUNE_CMD<%d> Error<%d> not -EIO", cmd->opcode, result); 839 dev_err(mmc_dev(host->mmc),
840 "%d -> TUNE_CMD<%d> Error<%d> not -EIO\n",
841 host->id, cmd->opcode, result);
1276 return result; 842 return result;
1277 } 843 }
1278 844
@@ -1325,7 +891,10 @@ static int msdc_tune_bread(struct mmc_host *mmc, struct mmc_request *mrq)
1325 if (host->app_cmd) { 891 if (host->app_cmd) {
1326 result = msdc_app_cmd(host->mmc, host); 892 result = msdc_app_cmd(host->mmc, host);
1327 if (result) { 893 if (result) {
1328 ERR_MSG("TUNE_BREAD app_cmd<%d> failed", host->mrq->cmd->opcode); 894 dev_err(mmc_dev(host->mmc),
895 "%d -> TUNE_BREAD app_cmd<%d> failed\n",
896 host->id,
897 host->mrq->cmd->opcode);
1329 continue; 898 continue;
1330 } 899 }
1331 } 900 }
@@ -1336,10 +905,13 @@ static int msdc_tune_bread(struct mmc_host *mmc, struct mmc_request *mrq)
1336 &dcrc); /* RO */ 905 &dcrc); /* RO */
1337 if (!ddr) 906 if (!ddr)
1338 dcrc &= ~SDC_DCRC_STS_NEG; 907 dcrc &= ~SDC_DCRC_STS_NEG;
1339 ERR_MSG("TUNE_BREAD<%s> dcrc<0x%x> DATRDDLY0/1<0x%x><0x%x> dsmpl<0x%x>", 908 dev_err(mmc_dev(host->mmc),
1340 (result == 0 && dcrc == 0) ? "PASS" : "FAIL", dcrc, 909 "%d -> TUNE_BREAD<%s> dcrc<0x%x> DATRDDLY0/1<0x%x><0x%x> dsmpl<0x%x>\n",
1341 readl(host->base + MSDC_DAT_RDDLY0), 910 host->id,
1342 readl(host->base + MSDC_DAT_RDDLY1), cur_dsmpl); 911 (result == 0 && dcrc == 0) ? "PASS" : "FAIL",
912 dcrc, readl(host->base + MSDC_DAT_RDDLY0),
913 readl(host->base + MSDC_DAT_RDDLY1),
914 cur_dsmpl);
1343 915
1344 /* Fix me: result is 0, but dcrc is still exist */ 916 /* Fix me: result is 0, but dcrc is still exist */
1345 if (result == 0 && dcrc == 0) { 917 if (result == 0 && dcrc == 0) {
@@ -1348,8 +920,11 @@ static int msdc_tune_bread(struct mmc_host *mmc, struct mmc_request *mrq)
1348 /* there is a case: command timeout, and data phase not processed */ 920 /* there is a case: command timeout, and data phase not processed */
1349 if (mrq->data->error != 0 && 921 if (mrq->data->error != 0 &&
1350 mrq->data->error != -EIO) { 922 mrq->data->error != -EIO) {
1351 ERR_MSG("TUNE_READ: result<0x%x> cmd_error<%d> data_error<%d>", 923 dev_err(mmc_dev(host->mmc),
1352 result, mrq->cmd->error, mrq->data->error); 924 "%d -> TUNE_READ: result<0x%x> cmd_error<%d> data_error<%d>\n",
925 host->id, result,
926 mrq->cmd->error,
927 mrq->data->error);
1353 goto done; 928 goto done;
1354 } 929 }
1355 } 930 }
@@ -1458,13 +1033,18 @@ static int msdc_tune_bwrite(struct mmc_host *mmc, struct mmc_request *mrq)
1458 if (host->app_cmd) { 1033 if (host->app_cmd) {
1459 result = msdc_app_cmd(host->mmc, host); 1034 result = msdc_app_cmd(host->mmc, host);
1460 if (result) { 1035 if (result) {
1461 ERR_MSG("TUNE_BWRITE app_cmd<%d> failed", host->mrq->cmd->opcode); 1036 dev_err(mmc_dev(host->mmc),
1037 "%d -> TUNE_BWRITE app_cmd<%d> failed\n",
1038 host->id,
1039 host->mrq->cmd->opcode);
1462 continue; 1040 continue;
1463 } 1041 }
1464 } 1042 }
1465 result = msdc_do_request(mmc, mrq); 1043 result = msdc_do_request(mmc, mrq);
1466 1044
1467 ERR_MSG("TUNE_BWRITE<%s> DSPL<%d> DATWRDLY<%d> MSDC_DAT_RDDLY0<0x%x>", 1045 dev_err(mmc_dev(host->mmc),
1046 "%d -> TUNE_BWRITE<%s> DSPL<%d> DATWRDLY<%d> MSDC_DAT_RDDLY0<0x%x>\n",
1047 host->id,
1468 result == 0 ? "PASS" : "FAIL", 1048 result == 0 ? "PASS" : "FAIL",
1469 cur_dsmpl, cur_wrrdly, cur_rxdly0); 1049 cur_dsmpl, cur_wrrdly, cur_rxdly0);
1470 1050
@@ -1473,8 +1053,11 @@ static int msdc_tune_bwrite(struct mmc_host *mmc, struct mmc_request *mrq)
1473 } else { 1053 } else {
1474 /* there is a case: command timeout, and data phase not processed */ 1054 /* there is a case: command timeout, and data phase not processed */
1475 if (mrq->data->error != -EIO) { 1055 if (mrq->data->error != -EIO) {
1476 ERR_MSG("TUNE_READ: result<0x%x> cmd_error<%d> data_error<%d>", 1056 dev_err(mmc_dev(host->mmc),
1477 result, mrq->cmd->error, mrq->data->error); 1057 "%d -> TUNE_READ: result<0x%x> cmd_error<%d> data_error<%d>\n",
1058 host->id, result,
1059 mrq->cmd->error,
1060 mrq->data->error);
1478 goto done; 1061 goto done;
1479 } 1062 }
1480 } 1063 }
@@ -1508,7 +1091,8 @@ static int msdc_get_card_status(struct mmc_host *mmc, struct msdc_host *host, u3
1508 if (mmc->card) { 1091 if (mmc->card) {
1509 cmd.arg = mmc->card->rca << 16; 1092 cmd.arg = mmc->card->rca << 16;
1510 } else { 1093 } else {
1511 ERR_MSG("cmd13 mmc card is null"); 1094 dev_err(mmc_dev(host->mmc), "%d -> cmd13 mmc card is null\n",
1095 host->id);
1512 cmd.arg = host->app_cmd_arg; 1096 cmd.arg = host->app_cmd_arg;
1513 } 1097 }
1514 cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC; 1098 cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC;
@@ -1535,7 +1119,8 @@ static int msdc_check_busy(struct mmc_host *mmc, struct msdc_host *host)
1535 if (err) 1119 if (err)
1536 return err; 1120 return err;
1537 /* need cmd12? */ 1121 /* need cmd12? */
1538 ERR_MSG("cmd<13> resp<0x%x>", status); 1122 dev_err(mmc_dev(host->mmc), "%d -> cmd<13> resp<0x%x>\n",
1123 host->id, status);
1539 } while (R1_CURRENT_STATE(status) == 7); 1124 } while (R1_CURRENT_STATE(status) == 7);
1540 1125
1541 return err; 1126 return err;
@@ -1559,7 +1144,9 @@ static int msdc_tune_request(struct mmc_host *mmc, struct mmc_request *mrq)
1559 } else { 1144 } else {
1560 ret = msdc_check_busy(mmc, host); 1145 ret = msdc_check_busy(mmc, host);
1561 if (ret) { 1146 if (ret) {
1562 ERR_MSG("XXX cmd13 wait program done failed"); 1147 dev_err(mmc_dev(host->mmc),
1148 "%d -> XXX cmd13 wait program done failed\n",
1149 host->id);
1563 return ret; 1150 return ret;
1564 } 1151 }
1565 /* CRC and TO */ 1152 /* CRC and TO */
@@ -1575,22 +1162,10 @@ static void msdc_ops_request(struct mmc_host *mmc, struct mmc_request *mrq)
1575{ 1162{
1576 struct msdc_host *host = mmc_priv(mmc); 1163 struct msdc_host *host = mmc_priv(mmc);
1577 1164
1578 //=== for sdio profile ===
1579#if 0 /* --- by chhung */
1580 u32 old_H32, old_L32, new_H32, new_L32;
1581 u32 ticks = 0, opcode = 0, sizes = 0, bRx = 0;
1582#endif /* end of --- */
1583
1584 WARN_ON(host->mrq); 1165 WARN_ON(host->mrq);
1585 1166
1586 /* start to process */ 1167 /* start to process */
1587 spin_lock(&host->lock); 1168 spin_lock(&host->lock);
1588#if 0 /* --- by chhung */
1589 if (sdio_pro_enable) { //=== for sdio profile ===
1590 if (mrq->cmd->opcode == 52 || mrq->cmd->opcode == 53)
1591 GPT_GetCounter64(&old_L32, &old_H32);
1592 }
1593#endif /* end of --- */
1594 1169
1595 host->mrq = mrq; 1170 host->mrq = mrq;
1596 1171
@@ -1610,26 +1185,6 @@ static void msdc_ops_request(struct mmc_host *mmc, struct mmc_request *mrq)
1610 1185
1611 host->mrq = NULL; 1186 host->mrq = NULL;
1612 1187
1613#if 0 /* --- by chhung */
1614 //=== for sdio profile ===
1615 if (sdio_pro_enable) {
1616 if (mrq->cmd->opcode == 52 || mrq->cmd->opcode == 53) {
1617 GPT_GetCounter64(&new_L32, &new_H32);
1618 ticks = msdc_time_calc(old_L32, old_H32, new_L32, new_H32);
1619
1620 opcode = mrq->cmd->opcode;
1621 if (mrq->cmd->data) {
1622 sizes = mrq->cmd->data->blocks * mrq->cmd->data->blksz;
1623 bRx = mrq->cmd->data->flags & MMC_DATA_READ ? 1 : 0;
1624 } else {
1625 bRx = mrq->cmd->arg & 0x80000000 ? 1 : 0;
1626 }
1627
1628 if (!mrq->cmd->error)
1629 msdc_performance(opcode, sizes, bRx, ticks);
1630 }
1631 }
1632#endif /* end of --- */
1633 spin_unlock(&host->lock); 1188 spin_unlock(&host->lock);
1634 1189
1635 mmc_request_done(mmc, mrq); 1190 mmc_request_done(mmc, mrq);
@@ -1659,8 +1214,6 @@ static void msdc_set_buswidth(struct msdc_host *host, u32 width)
1659 } 1214 }
1660 1215
1661 writel(val, host->base + SDC_CFG); 1216 writel(val, host->base + SDC_CFG);
1662
1663 N_MSG(CFG, "Bus Width = %d", width);
1664} 1217}
1665 1218
1666/* ops.set_ios */ 1219/* ops.set_ios */
@@ -1698,7 +1251,6 @@ static void msdc_ops_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1698 switch (ios->power_mode) { 1251 switch (ios->power_mode) {
1699 case MMC_POWER_OFF: 1252 case MMC_POWER_OFF:
1700 case MMC_POWER_UP: 1253 case MMC_POWER_UP:
1701 // msdc_set_power_mode(host, ios->power_mode); /* --- by chhung */
1702 break; 1254 break;
1703 case MMC_POWER_ON: 1255 case MMC_POWER_ON:
1704 host->power_mode = MMC_POWER_ON; 1256 host->power_mode = MMC_POWER_ON;
@@ -1711,7 +1263,6 @@ static void msdc_ops_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1711 if (host->mclk != ios->clock) { 1263 if (host->mclk != ios->clock) {
1712 if (ios->clock > 25000000) { 1264 if (ios->clock > 25000000) {
1713 //if (!(host->hw->flags & MSDC_REMOVABLE)) { 1265 //if (!(host->hw->flags & MSDC_REMOVABLE)) {
1714 INIT_MSG("SD data latch edge<%d>", MSDC_SMPL_FALLING);
1715 sdr_set_field(host->base + MSDC_IOCON, MSDC_IOCON_RSPL, 1266 sdr_set_field(host->base + MSDC_IOCON, MSDC_IOCON_RSPL,
1716 MSDC_SMPL_FALLING); 1267 MSDC_SMPL_FALLING);
1717 sdr_set_field(host->base + MSDC_IOCON, MSDC_IOCON_DSPL, 1268 sdr_set_field(host->base + MSDC_IOCON, MSDC_IOCON_DSPL,
@@ -1764,7 +1315,6 @@ static int msdc_ops_get_cd(struct mmc_host *mmc)
1764 return 1; 1315 return 1;
1765#else 1316#else
1766 host->card_inserted = (host->pm_state.event == PM_EVENT_USER_RESUME) ? 1 : 0; 1317 host->card_inserted = (host->pm_state.event == PM_EVENT_USER_RESUME) ? 1 : 0;
1767 INIT_MSG("sdio ops_get_cd<%d>", host->card_inserted);
1768 return host->card_inserted; 1318 return host->card_inserted;
1769#endif 1319#endif
1770 } 1320 }
@@ -1772,9 +1322,6 @@ static int msdc_ops_get_cd(struct mmc_host *mmc)
1772 /* MSDC_CD_PIN_EN set for card */ 1322 /* MSDC_CD_PIN_EN set for card */
1773 if (host->hw->flags & MSDC_CD_PIN_EN) { 1323 if (host->hw->flags & MSDC_CD_PIN_EN) {
1774 spin_lock_irqsave(&host->lock, flags); 1324 spin_lock_irqsave(&host->lock, flags);
1775#if 0
1776 present = host->card_inserted; /* why not read from H/W: Fix me*/
1777#else
1778 // CD 1325 // CD
1779 present = readl(host->base + MSDC_PS) & MSDC_PS_CDSTS; 1326 present = readl(host->base + MSDC_PS) & MSDC_PS_CDSTS;
1780 if (cd_active_low) 1327 if (cd_active_low)
@@ -1782,13 +1329,11 @@ static int msdc_ops_get_cd(struct mmc_host *mmc)
1782 else 1329 else
1783 present = present ? 1 : 0; 1330 present = present ? 1 : 0;
1784 host->card_inserted = present; 1331 host->card_inserted = present;
1785#endif
1786 spin_unlock_irqrestore(&host->lock, flags); 1332 spin_unlock_irqrestore(&host->lock, flags);
1787 } else { 1333 } else {
1788 present = 0; /* TODO? Check DAT3 pins for card detection */ 1334 present = 0; /* TODO? Check DAT3 pins for card detection */
1789 } 1335 }
1790 1336
1791 INIT_MSG("ops_get_cd return<%d>", present);
1792 return present; 1337 return present;
1793} 1338}
1794 1339
@@ -1823,19 +1368,12 @@ static irqreturn_t msdc_irq(int irq, void *dev_id)
1823 if (intsts & MSDC_INT_CDSC) { 1368 if (intsts & MSDC_INT_CDSC) {
1824 if (host->mmc->caps & MMC_CAP_NEEDS_POLL) 1369 if (host->mmc->caps & MMC_CAP_NEEDS_POLL)
1825 return IRQ_HANDLED; 1370 return IRQ_HANDLED;
1826 IRQ_MSG("MSDC_INT_CDSC irq<0x%.8x>", intsts);
1827 schedule_delayed_work(&host->card_delaywork, HZ); 1371 schedule_delayed_work(&host->card_delaywork, HZ);
1828 /* tuning when plug card ? */ 1372 /* tuning when plug card ? */
1829 } 1373 }
1830 1374
1831 /* sdio interrupt */
1832 if (intsts & MSDC_INT_SDIOIRQ) {
1833 IRQ_MSG("XXX MSDC_INT_SDIOIRQ"); /* seems not sdio irq */
1834 //mmc_signal_sdio_irq(host->mmc);
1835 }
1836
1837 /* transfer complete interrupt */ 1375 /* transfer complete interrupt */
1838 if (data != NULL) { 1376 if (data) {
1839 if (inten & MSDC_INT_XFER_COMPL) { 1377 if (inten & MSDC_INT_XFER_COMPL) {
1840 data->bytes_xfered = host->xfer_size; 1378 data->bytes_xfered = host->xfer_size;
1841 complete(&host->xfer_done); 1379 complete(&host->xfer_done);
@@ -1847,13 +1385,10 @@ static irqreturn_t msdc_irq(int irq, void *dev_id)
1847 msdc_clr_fifo(host); 1385 msdc_clr_fifo(host);
1848 msdc_clr_int(); 1386 msdc_clr_int();
1849 1387
1850 if (intsts & MSDC_INT_DATTMO) { 1388 if (intsts & MSDC_INT_DATTMO)
1851 IRQ_MSG("XXX CMD<%d> MSDC_INT_DATTMO", host->mrq->cmd->opcode);
1852 data->error = -ETIMEDOUT; 1389 data->error = -ETIMEDOUT;
1853 } else if (intsts & MSDC_INT_DATCRCERR) { 1390 else if (intsts & MSDC_INT_DATCRCERR)
1854 IRQ_MSG("XXX CMD<%d> MSDC_INT_DATCRCERR, SDC_DCRC_STS<0x%x>", host->mrq->cmd->opcode, readl(host->base + SDC_DCRC_STS));
1855 data->error = -EIO; 1391 data->error = -EIO;
1856 }
1857 1392
1858 //if(readl(MSDC_INTEN) & MSDC_INT_XFER_COMPL) { 1393 //if(readl(MSDC_INTEN) & MSDC_INT_XFER_COMPL) {
1859 complete(&host->xfer_done); /* Read CRC come fast, XFER_COMPL not enabled */ 1394 complete(&host->xfer_done); /* Read CRC come fast, XFER_COMPL not enabled */
@@ -1861,7 +1396,7 @@ static irqreturn_t msdc_irq(int irq, void *dev_id)
1861 } 1396 }
1862 1397
1863 /* command interrupts */ 1398 /* command interrupts */
1864 if ((cmd != NULL) && (intsts & cmdsts)) { 1399 if (cmd && (intsts & cmdsts)) {
1865 if ((intsts & MSDC_INT_CMDRDY) || (intsts & MSDC_INT_ACMDRDY) || 1400 if ((intsts & MSDC_INT_CMDRDY) || (intsts & MSDC_INT_ACMDRDY) ||
1866 (intsts & MSDC_INT_ACMD19_DONE)) { 1401 (intsts & MSDC_INT_ACMD19_DONE)) {
1867 u32 *rsp = &cmd->resp[0]; 1402 u32 *rsp = &cmd->resp[0];
@@ -1883,16 +1418,8 @@ static irqreturn_t msdc_irq(int irq, void *dev_id)
1883 break; 1418 break;
1884 } 1419 }
1885 } else if ((intsts & MSDC_INT_RSPCRCERR) || (intsts & MSDC_INT_ACMDCRCERR)) { 1420 } else if ((intsts & MSDC_INT_RSPCRCERR) || (intsts & MSDC_INT_ACMDCRCERR)) {
1886 if (intsts & MSDC_INT_ACMDCRCERR)
1887 IRQ_MSG("XXX CMD<%d> MSDC_INT_ACMDCRCERR", cmd->opcode);
1888 else
1889 IRQ_MSG("XXX CMD<%d> MSDC_INT_RSPCRCERR", cmd->opcode);
1890 cmd->error = -EIO; 1421 cmd->error = -EIO;
1891 } else if ((intsts & MSDC_INT_CMDTMO) || (intsts & MSDC_INT_ACMDTMO)) { 1422 } else if ((intsts & MSDC_INT_CMDTMO) || (intsts & MSDC_INT_ACMDTMO)) {
1892 if (intsts & MSDC_INT_ACMDTMO)
1893 IRQ_MSG("XXX CMD<%d> MSDC_INT_ACMDTMO", cmd->opcode);
1894 else
1895 IRQ_MSG("XXX CMD<%d> MSDC_INT_CMDTMO", cmd->opcode);
1896 cmd->error = -ETIMEDOUT; 1423 cmd->error = -ETIMEDOUT;
1897 msdc_reset_hw(host); 1424 msdc_reset_hw(host);
1898 msdc_clr_fifo(host); 1425 msdc_clr_fifo(host);
@@ -1903,36 +1430,8 @@ static irqreturn_t msdc_irq(int irq, void *dev_id)
1903 1430
1904 /* mmc irq interrupts */ 1431 /* mmc irq interrupts */
1905 if (intsts & MSDC_INT_MMCIRQ) 1432 if (intsts & MSDC_INT_MMCIRQ)
1906 printk(KERN_INFO "msdc[%d] MMCIRQ: SDC_CSTS=0x%.8x\r\n", 1433 dev_info(mmc_dev(host->mmc), "msdc[%d] MMCIRQ: SDC_CSTS=0x%.8x\r\n",
1907 host->id, readl(host->base + SDC_CSTS)); 1434 host->id, readl(host->base + SDC_CSTS));
1908
1909#ifdef MT6575_SD_DEBUG
1910 {
1911/* msdc_int_reg *int_reg = (msdc_int_reg*)&intsts;*/
1912 N_MSG(INT, "IRQ_EVT(0x%x): MMCIRQ(%d) CDSC(%d), ACRDY(%d), ACTMO(%d), ACCRE(%d) AC19DN(%d)",
1913 intsts,
1914 int_reg->mmcirq,
1915 int_reg->cdsc,
1916 int_reg->atocmdrdy,
1917 int_reg->atocmdtmo,
1918 int_reg->atocmdcrc,
1919 int_reg->atocmd19done);
1920 N_MSG(INT, "IRQ_EVT(0x%x): SDIO(%d) CMDRDY(%d), CMDTMO(%d), RSPCRC(%d), CSTA(%d)",
1921 intsts,
1922 int_reg->sdioirq,
1923 int_reg->cmdrdy,
1924 int_reg->cmdtmo,
1925 int_reg->rspcrc,
1926 int_reg->csta);
1927 N_MSG(INT, "IRQ_EVT(0x%x): XFCMP(%d) DXDONE(%d), DATTMO(%d), DATCRC(%d), DMAEMP(%d)",
1928 intsts,
1929 int_reg->xfercomp,
1930 int_reg->dxferdone,
1931 int_reg->dattmo,
1932 int_reg->datcrc,
1933 int_reg->dmaqempty);
1934 }
1935#endif
1936 1435
1937 return IRQ_HANDLED; 1436 return IRQ_HANDLED;
1938} 1437}
@@ -1958,14 +1457,11 @@ static void msdc_enable_cd_irq(struct msdc_host *host, int enable)
1958 return; 1457 return;
1959 } 1458 }
1960 1459
1961 N_MSG(CFG, "CD IRQ Enable(%d)", enable);
1962
1963 if (enable) { 1460 if (enable) {
1964 /* card detection circuit relies on the core power so that the core power 1461 /* card detection circuit relies on the core power so that the core power
1965 * shouldn't be turned off. Here adds a reference count to keep 1462 * shouldn't be turned off. Here adds a reference count to keep
1966 * the core power alive. 1463 * the core power alive.
1967 */ 1464 */
1968 //msdc_vcore_on(host); //did in msdc_init_hw()
1969 1465
1970 if (hw->config_gpio_pin) /* NULL */ 1466 if (hw->config_gpio_pin) /* NULL */
1971 hw->config_gpio_pin(MSDC_CD_PIN, GPIO_PULL_UP); 1467 hw->config_gpio_pin(MSDC_CD_PIN, GPIO_PULL_UP);
@@ -1988,7 +1484,6 @@ static void msdc_enable_cd_irq(struct msdc_host *host, int enable)
1988 /* Here decreases a reference count to core power since card 1484 /* Here decreases a reference count to core power since card
1989 * detection circuit is shutdown. 1485 * detection circuit is shutdown.
1990 */ 1486 */
1991 //msdc_vcore_off(host);
1992 } 1487 }
1993} 1488}
1994 1489
@@ -1996,14 +1491,6 @@ static void msdc_enable_cd_irq(struct msdc_host *host, int enable)
1996static void msdc_init_hw(struct msdc_host *host) 1491static void msdc_init_hw(struct msdc_host *host)
1997{ 1492{
1998 1493
1999 /* Power on */
2000#if 0 /* --- by chhung */
2001 msdc_vcore_on(host);
2002 msdc_pin_reset(host, MSDC_PIN_PULL_UP);
2003 msdc_select_clksrc(host, hw->clk_src);
2004 enable_clock(PERI_MSDC0_PDN + host->id, "SD");
2005 msdc_vdd_on(host);
2006#endif /* end of --- */
2007 /* Configure to MMC/SD mode */ 1494 /* Configure to MMC/SD mode */
2008 sdr_set_field(host->base + MSDC_CFG, MSDC_CFG_MODE, MSDC_SDMMC); 1495 sdr_set_field(host->base + MSDC_CFG, MSDC_CFG_MODE, MSDC_SDMMC);
2009 1496
@@ -2035,10 +1522,6 @@ static void msdc_init_hw(struct msdc_host *host)
2035 1522
2036 writel(0x00000000, host->base + MSDC_DAT_RDDLY1); 1523 writel(0x00000000, host->base + MSDC_DAT_RDDLY1);
2037 writel(0x00000000, host->base + MSDC_IOCON); 1524 writel(0x00000000, host->base + MSDC_IOCON);
2038#if 0 // use MT7620 default value: 0x403c004f
2039 /* bit0 modified: Rx Data Clock Source: 1 -> 2.0*/
2040 writel(0x003C000F, host->base + MSDC_PATCH_BIT0);
2041#endif
2042 1525
2043 if (readl(host->base + MSDC_ECO_VER) >= 4) { 1526 if (readl(host->base + MSDC_ECO_VER) >= 4) {
2044 if (host->id == 1) { 1527 if (host->id == 1) {
@@ -2094,8 +1577,6 @@ static void msdc_init_hw(struct msdc_host *host)
2094 sdr_set_field(host->base + SDC_CFG, SDC_CFG_DTOC, DEFAULT_DTOC); 1577 sdr_set_field(host->base + SDC_CFG, SDC_CFG_DTOC, DEFAULT_DTOC);
2095 1578
2096 msdc_set_buswidth(host, MMC_BUS_WIDTH_1); 1579 msdc_set_buswidth(host, MMC_BUS_WIDTH_1);
2097
2098 N_MSG(FUC, "init hardware done!");
2099} 1580}
2100 1581
2101/* called by msdc_drv_remove */ 1582/* called by msdc_drv_remove */
@@ -2107,7 +1588,6 @@ static void msdc_deinit_hw(struct msdc_host *host)
2107 1588
2108 /* Disable card detection */ 1589 /* Disable card detection */
2109 msdc_enable_cd_irq(host, 0); 1590 msdc_enable_cd_irq(host, 0);
2110 // msdc_set_power_mode(host, MMC_POWER_OFF); /* make sure power down */ /* --- by chhung */
2111} 1591}
2112 1592
2113/* init gpd and bd list in msdc_drv_probe */ 1593/* init gpd and bd list in msdc_drv_probe */
@@ -2289,7 +1769,8 @@ static int msdc_drv_remove(struct platform_device *pdev)
2289 host = mmc_priv(mmc); 1769 host = mmc_priv(mmc);
2290 BUG_ON(!host); 1770 BUG_ON(!host);
2291 1771
2292 ERR_MSG("removed !!!"); 1772 dev_err(mmc_dev(host->mmc), "%d -> removed !!!\n",
1773 host->id);
2293 1774
2294 platform_set_drvdata(pdev, NULL); 1775 platform_set_drvdata(pdev, NULL);
2295 mmc_remove_host(host->mmc); 1776 mmc_remove_host(host->mmc);
@@ -2313,6 +1794,7 @@ static int msdc_drv_remove(struct platform_device *pdev)
2313static void msdc_drv_pm(struct platform_device *pdev, pm_message_t state) 1794static void msdc_drv_pm(struct platform_device *pdev, pm_message_t state)
2314{ 1795{
2315 struct mmc_host *mmc = platform_get_drvdata(pdev); 1796 struct mmc_host *mmc = platform_get_drvdata(pdev);
1797
2316 if (mmc) { 1798 if (mmc) {
2317 struct msdc_host *host = mmc_priv(mmc); 1799 struct msdc_host *host = mmc_priv(mmc);
2318 msdc_pm(state, (void *)host); 1800 msdc_pm(state, (void *)host);
@@ -2370,7 +1852,7 @@ static int __init mt_msdc_init(void)
2370 1852
2371 ret = platform_driver_register(&mt_msdc_driver); 1853 ret = platform_driver_register(&mt_msdc_driver);
2372 if (ret) { 1854 if (ret) {
2373 printk(KERN_ERR DRV_NAME ": Can't register driver"); 1855 pr_err("%s: Can't register driver", DRV_NAME);
2374 return ret; 1856 return ret;
2375 } 1857 }
2376 1858
diff --git a/drivers/staging/mt7621-pci/pci-mt7621.c b/drivers/staging/mt7621-pci/pci-mt7621.c
index a49e2795af6b..8371a9cdb164 100644
--- a/drivers/staging/mt7621-pci/pci-mt7621.c
+++ b/drivers/staging/mt7621-pci/pci-mt7621.c
@@ -122,7 +122,7 @@
122#define RALINK_PCIE_CLK_EN BIT(21) 122#define RALINK_PCIE_CLK_EN BIT(21)
123 123
124#define MEMORY_BASE 0x0 124#define MEMORY_BASE 0x0
125static int pcie_link_status = 0; 125static int pcie_link_status;
126 126
127/** 127/**
128 * struct mt7621_pcie_port - PCIe port information 128 * struct mt7621_pcie_port - PCIe port information
@@ -214,7 +214,7 @@ write_config(struct mt7621_pcie *pcie, unsigned int dev, u32 reg, u32 val)
214 pcie_write(pcie, val, RALINK_PCI_CONFIG_DATA); 214 pcie_write(pcie, val, RALINK_PCI_CONFIG_DATA);
215} 215}
216 216
217void 217static void
218set_pcie_phy(struct mt7621_pcie *pcie, u32 offset, 218set_pcie_phy(struct mt7621_pcie *pcie, u32 offset,
219 int start_b, int bits, int val) 219 int start_b, int bits, int val)
220{ 220{
@@ -225,7 +225,7 @@ set_pcie_phy(struct mt7621_pcie *pcie, u32 offset,
225 pcie_write(pcie, reg, offset); 225 pcie_write(pcie, reg, offset);
226} 226}
227 227
228void 228static void
229bypass_pipe_rst(struct mt7621_pcie *pcie) 229bypass_pipe_rst(struct mt7621_pcie *pcie)
230{ 230{
231 /* PCIe Port 0 */ 231 /* PCIe Port 0 */
@@ -239,7 +239,7 @@ bypass_pipe_rst(struct mt7621_pcie *pcie)
239 set_pcie_phy(pcie, (RALINK_PCIEPHY_P2_CTL_OFFSET + 0x02c), 4, 1, 0x01); // rg_pe1_pipe_cmd_frc[4] 239 set_pcie_phy(pcie, (RALINK_PCIEPHY_P2_CTL_OFFSET + 0x02c), 4, 1, 0x01); // rg_pe1_pipe_cmd_frc[4]
240} 240}
241 241
242void 242static void
243set_phy_for_ssc(struct mt7621_pcie *pcie) 243set_phy_for_ssc(struct mt7621_pcie *pcie)
244{ 244{
245 unsigned long reg = rt_sysc_r32(SYSC_REG_SYSTEM_CONFIG0); 245 unsigned long reg = rt_sysc_r32(SYSC_REG_SYSTEM_CONFIG0);
@@ -387,15 +387,8 @@ static int mt7621_pcie_parse_dt(struct mt7621_pcie *pcie)
387 struct device *dev = pcie->dev; 387 struct device *dev = pcie->dev;
388 struct device_node *node = dev->of_node; 388 struct device_node *node = dev->of_node;
389 struct resource regs; 389 struct resource regs;
390 const char *type;
391 int err; 390 int err;
392 391
393 type = of_get_property(node, "device_type", NULL);
394 if (!type || strcmp(type, "pci") != 0) {
395 dev_err(dev, "invalid \"device_type\" %s\n", type);
396 return -EINVAL;
397 }
398
399 err = of_address_to_resource(node, 0, &regs); 392 err = of_address_to_resource(node, 0, &regs);
400 if (err) { 393 if (err) {
401 dev_err(dev, "missing \"reg\" property\n"); 394 dev_err(dev, "missing \"reg\" property\n");
@@ -481,12 +474,12 @@ static int mt7621_pci_probe(struct platform_device *pdev)
481 474
482 ASSERT_SYSRST_PCIE(RALINK_PCIE0_RST | RALINK_PCIE1_RST | RALINK_PCIE2_RST); 475 ASSERT_SYSRST_PCIE(RALINK_PCIE0_RST | RALINK_PCIE1_RST | RALINK_PCIE2_RST);
483 476
484 *(unsigned int *)(0xbe000060) &= ~(0x3<<10 | 0x3<<3); 477 *(unsigned int *)(0xbe000060) &= ~(0x3 << 10 | 0x3 << 3);
485 *(unsigned int *)(0xbe000060) |= 0x1<<10 | 0x1<<3; 478 *(unsigned int *)(0xbe000060) |= BIT(10) | BIT(3);
486 mdelay(100); 479 mdelay(100);
487 *(unsigned int *)(0xbe000600) |= 0x1<<19 | 0x1<<8 | 0x1<<7; // use GPIO19/GPIO8/GPIO7 (PERST_N/UART_RXD3/UART_TXD3) 480 *(unsigned int *)(0xbe000600) |= BIT(19) | BIT(8) | BIT(7); // use GPIO19/GPIO8/GPIO7 (PERST_N/UART_RXD3/UART_TXD3)
488 mdelay(100); 481 mdelay(100);
489 *(unsigned int *)(0xbe000620) &= ~(0x1<<19 | 0x1<<8 | 0x1<<7); // clear DATA 482 *(unsigned int *)(0xbe000620) &= ~(BIT(19) | BIT(8) | BIT(7)); // clear DATA
490 483
491 mdelay(100); 484 mdelay(100);
492 485
@@ -496,18 +489,15 @@ static int mt7621_pci_probe(struct platform_device *pdev)
496 489
497 DEASSERT_SYSRST_PCIE(val); 490 DEASSERT_SYSRST_PCIE(val);
498 491
499 if ((*(unsigned int *)(0xbe00000c)&0xFFFF) == 0x0101) // MT7621 E2 492 if ((*(unsigned int *)(0xbe00000c) & 0xFFFF) == 0x0101) // MT7621 E2
500 bypass_pipe_rst(pcie); 493 bypass_pipe_rst(pcie);
501 set_phy_for_ssc(pcie); 494 set_phy_for_ssc(pcie);
502 495
503 val = read_config(pcie, 0, 0x70c); 496 list_for_each_entry_safe(port, tmp, &pcie->ports, list) {
504 printk("Port 0 N_FTS = %x\n", (unsigned int)val); 497 u32 slot = port->slot;
505 498 val = read_config(pcie, slot, 0x70c);
506 val = read_config(pcie, 1, 0x70c); 499 dev_info(dev, "Port %d N_FTS = %x\n", (unsigned int)val, slot);
507 printk("Port 1 N_FTS = %x\n", (unsigned int)val); 500 }
508
509 val = read_config(pcie, 2, 0x70c);
510 printk("Port 2 N_FTS = %x\n", (unsigned int)val);
511 501
512 rt_sysc_m32(0, RALINK_PCIE_RST, RALINK_RSTCTRL); 502 rt_sysc_m32(0, RALINK_PCIE_RST, RALINK_RSTCTRL);
513 rt_sysc_m32(0x30, 2 << 4, SYSC_REG_SYSTEM_CONFIG1); 503 rt_sysc_m32(0x30, 2 << 4, SYSC_REG_SYSTEM_CONFIG1);
@@ -520,18 +510,18 @@ static int mt7621_pci_probe(struct platform_device *pdev)
520 rt_sysc_m32(RALINK_PCIE_RST, 0, RALINK_RSTCTRL); 510 rt_sysc_m32(RALINK_PCIE_RST, 0, RALINK_RSTCTRL);
521 511
522 /* Use GPIO control instead of PERST_N */ 512 /* Use GPIO control instead of PERST_N */
523 *(unsigned int *)(0xbe000620) |= 0x1<<19 | 0x1<<8 | 0x1<<7; // set DATA 513 *(unsigned int *)(0xbe000620) |= BIT(19) | BIT(8) | BIT(7); // set DATA
524 mdelay(1000); 514 mdelay(1000);
525 515
526 if ((pcie_read(pcie, RT6855_PCIE0_OFFSET + RALINK_PCI_STATUS) & 0x1) == 0) { 516 if ((pcie_read(pcie, RT6855_PCIE0_OFFSET + RALINK_PCI_STATUS) & 0x1) == 0) {
527 printk("PCIE0 no card, disable it(RST&CLK)\n"); 517 printk("PCIE0 no card, disable it(RST&CLK)\n");
528 ASSERT_SYSRST_PCIE(RALINK_PCIE0_RST); 518 ASSERT_SYSRST_PCIE(RALINK_PCIE0_RST);
529 rt_sysc_m32(RALINK_PCIE0_CLK_EN, 0, RALINK_CLKCFG1); 519 rt_sysc_m32(RALINK_PCIE0_CLK_EN, 0, RALINK_CLKCFG1);
530 pcie_link_status &= ~(1<<0); 520 pcie_link_status &= ~(BIT(0));
531 } else { 521 } else {
532 pcie_link_status |= 1<<0; 522 pcie_link_status |= BIT(0);
533 val = pcie_read(pcie, RALINK_PCI_PCIMSK_ADDR); 523 val = pcie_read(pcie, RALINK_PCI_PCIMSK_ADDR);
534 val |= (1<<20); // enable pcie1 interrupt 524 val |= BIT(20); // enable pcie1 interrupt
535 pcie_write(pcie, val, RALINK_PCI_PCIMSK_ADDR); 525 pcie_write(pcie, val, RALINK_PCI_PCIMSK_ADDR);
536 } 526 }
537 527
@@ -539,11 +529,11 @@ static int mt7621_pci_probe(struct platform_device *pdev)
539 printk("PCIE1 no card, disable it(RST&CLK)\n"); 529 printk("PCIE1 no card, disable it(RST&CLK)\n");
540 ASSERT_SYSRST_PCIE(RALINK_PCIE1_RST); 530 ASSERT_SYSRST_PCIE(RALINK_PCIE1_RST);
541 rt_sysc_m32(RALINK_PCIE1_CLK_EN, 0, RALINK_CLKCFG1); 531 rt_sysc_m32(RALINK_PCIE1_CLK_EN, 0, RALINK_CLKCFG1);
542 pcie_link_status &= ~(1<<1); 532 pcie_link_status &= ~(BIT(1));
543 } else { 533 } else {
544 pcie_link_status |= 1<<1; 534 pcie_link_status |= BIT(1);
545 val = pcie_read(pcie, RALINK_PCI_PCIMSK_ADDR); 535 val = pcie_read(pcie, RALINK_PCI_PCIMSK_ADDR);
546 val |= (1<<21); // enable pcie1 interrupt 536 val |= BIT(21); // enable pcie1 interrupt
547 pcie_write(pcie, val, RALINK_PCI_PCIMSK_ADDR); 537 pcie_write(pcie, val, RALINK_PCI_PCIMSK_ADDR);
548 } 538 }
549 539
@@ -551,11 +541,11 @@ static int mt7621_pci_probe(struct platform_device *pdev)
551 printk("PCIE2 no card, disable it(RST&CLK)\n"); 541 printk("PCIE2 no card, disable it(RST&CLK)\n");
552 ASSERT_SYSRST_PCIE(RALINK_PCIE2_RST); 542 ASSERT_SYSRST_PCIE(RALINK_PCIE2_RST);
553 rt_sysc_m32(RALINK_PCIE2_CLK_EN, 0, RALINK_CLKCFG1); 543 rt_sysc_m32(RALINK_PCIE2_CLK_EN, 0, RALINK_CLKCFG1);
554 pcie_link_status &= ~(1<<2); 544 pcie_link_status &= ~(BIT(2));
555 } else { 545 } else {
556 pcie_link_status |= 1<<2; 546 pcie_link_status |= BIT(2);
557 val = pcie_read(pcie, RALINK_PCI_PCIMSK_ADDR); 547 val = pcie_read(pcie, RALINK_PCI_PCIMSK_ADDR);
558 val |= (1<<22); // enable pcie2 interrupt 548 val |= BIT(22); // enable pcie2 interrupt
559 pcie_write(pcie, val, RALINK_PCI_PCIMSK_ADDR); 549 pcie_write(pcie, val, RALINK_PCI_PCIMSK_ADDR);
560 } 550 }
561 551
@@ -654,26 +644,26 @@ pcie(2/1/0) link status pcie2_num pcie1_num pcie0_num
654 switch (pcie_link_status) { 644 switch (pcie_link_status) {
655 case 7: 645 case 7:
656 val = read_config(pcie, 2, 0x4); 646 val = read_config(pcie, 2, 0x4);
657 write_config(pcie, 2, 0x4, val|0x4); 647 write_config(pcie, 2, 0x4, val | 0x4);
658 val = read_config(pcie, 2, 0x70c); 648 val = read_config(pcie, 2, 0x70c);
659 val &= ~(0xff)<<8; 649 val &= ~(0xff) << 8;
660 val |= 0x50<<8; 650 val |= 0x50 << 8;
661 write_config(pcie, 2, 0x70c, val); 651 write_config(pcie, 2, 0x70c, val);
662 case 3: 652 case 3:
663 case 5: 653 case 5:
664 case 6: 654 case 6:
665 val = read_config(pcie, 1, 0x4); 655 val = read_config(pcie, 1, 0x4);
666 write_config(pcie, 1, 0x4, val|0x4); 656 write_config(pcie, 1, 0x4, val | 0x4);
667 val = read_config(pcie, 1, 0x70c); 657 val = read_config(pcie, 1, 0x70c);
668 val &= ~(0xff)<<8; 658 val &= ~(0xff) << 8;
669 val |= 0x50<<8; 659 val |= 0x50 << 8;
670 write_config(pcie, 1, 0x70c, val); 660 write_config(pcie, 1, 0x70c, val);
671 default: 661 default:
672 val = read_config(pcie, 0, 0x4); 662 val = read_config(pcie, 0, 0x4);
673 write_config(pcie, 0, 0x4, val|0x4); //bus master enable 663 write_config(pcie, 0, 0x4, val | 0x4); //bus master enable
674 val = read_config(pcie, 0, 0x70c); 664 val = read_config(pcie, 0, 0x70c);
675 val &= ~(0xff)<<8; 665 val &= ~(0xff) << 8;
676 val |= 0x50<<8; 666 val |= 0x50 << 8;
677 write_config(pcie, 0, 0x70c, val); 667 write_config(pcie, 0, 0x70c, val);
678 } 668 }
679 669
diff --git a/drivers/staging/octeon-usb/octeon-hcd.c b/drivers/staging/octeon-usb/octeon-hcd.c
index cff5e790b196..9c766f5b812f 100644
--- a/drivers/staging/octeon-usb/octeon-hcd.c
+++ b/drivers/staging/octeon-usb/octeon-hcd.c
@@ -377,29 +377,6 @@ struct octeon_hcd {
377 struct cvmx_usb_tx_fifo nonperiodic; 377 struct cvmx_usb_tx_fifo nonperiodic;
378}; 378};
379 379
380/* This macro spins on a register waiting for it to reach a condition. */
381#define CVMX_WAIT_FOR_FIELD32(address, _union, cond, timeout_usec) \
382 ({int result; \
383 do { \
384 u64 done = cvmx_get_cycle() + (u64)timeout_usec * \
385 octeon_get_clock_rate() / 1000000; \
386 union _union c; \
387 \
388 while (1) { \
389 c.u32 = cvmx_usb_read_csr32(usb, address); \
390 \
391 if (cond) { \
392 result = 0; \
393 break; \
394 } else if (cvmx_get_cycle() > done) { \
395 result = -1; \
396 break; \
397 } else \
398 __delay(100); \
399 } \
400 } while (0); \
401 result; })
402
403/* 380/*
404 * This macro logically sets a single field in a CSR. It does the sequence 381 * This macro logically sets a single field in a CSR. It does the sequence
405 * read, modify, and write 382 * read, modify, and write
@@ -593,6 +570,33 @@ static inline int cvmx_usb_get_data_pid(struct cvmx_usb_pipe *pipe)
593 return 0; /* Data0 */ 570 return 0; /* Data0 */
594} 571}
595 572
573/* Loops through register until txfflsh or rxfflsh become zero.*/
574static int cvmx_wait_tx_rx(struct octeon_hcd *usb, int fflsh_type)
575{
576 int result;
577 u64 address = CVMX_USBCX_GRSTCTL(usb->index);
578 u64 done = cvmx_get_cycle() + 100 *
579 (u64)octeon_get_clock_rate / 1000000;
580 union cvmx_usbcx_grstctl c;
581
582 while (1) {
583 c.u32 = cvmx_usb_read_csr32(usb, address);
584 if (fflsh_type == 0 && c.s.txfflsh == 0) {
585 result = 0;
586 break;
587 } else if (fflsh_type == 1 && c.s.rxfflsh == 0) {
588 result = 0;
589 break;
590 } else if (cvmx_get_cycle() > done) {
591 result = -1;
592 break;
593 }
594
595 __delay(100);
596 }
597 return result;
598}
599
596static void cvmx_fifo_setup(struct octeon_hcd *usb) 600static void cvmx_fifo_setup(struct octeon_hcd *usb)
597{ 601{
598 union cvmx_usbcx_ghwcfg3 usbcx_ghwcfg3; 602 union cvmx_usbcx_ghwcfg3 usbcx_ghwcfg3;
@@ -634,12 +638,10 @@ static void cvmx_fifo_setup(struct octeon_hcd *usb)
634 cvmx_usbcx_grstctl, txfnum, 0x10); 638 cvmx_usbcx_grstctl, txfnum, 0x10);
635 USB_SET_FIELD32(CVMX_USBCX_GRSTCTL(usb->index), 639 USB_SET_FIELD32(CVMX_USBCX_GRSTCTL(usb->index),
636 cvmx_usbcx_grstctl, txfflsh, 1); 640 cvmx_usbcx_grstctl, txfflsh, 1);
637 CVMX_WAIT_FOR_FIELD32(CVMX_USBCX_GRSTCTL(usb->index), 641 cvmx_wait_tx_rx(usb, 0);
638 cvmx_usbcx_grstctl, c.s.txfflsh == 0, 100);
639 USB_SET_FIELD32(CVMX_USBCX_GRSTCTL(usb->index), 642 USB_SET_FIELD32(CVMX_USBCX_GRSTCTL(usb->index),
640 cvmx_usbcx_grstctl, rxfflsh, 1); 643 cvmx_usbcx_grstctl, rxfflsh, 1);
641 CVMX_WAIT_FOR_FIELD32(CVMX_USBCX_GRSTCTL(usb->index), 644 cvmx_wait_tx_rx(usb, 1);
642 cvmx_usbcx_grstctl, c.s.rxfflsh == 0, 100);
643} 645}
644 646
645/** 647/**
@@ -2768,7 +2770,7 @@ static int cvmx_usb_poll_channel(struct octeon_hcd *usb, int channel)
2768 (pipe->transfer_dir == CVMX_USB_DIRECTION_OUT)) 2770 (pipe->transfer_dir == CVMX_USB_DIRECTION_OUT))
2769 pipe->flags |= CVMX_USB_PIPE_FLAGS_NEED_PING; 2771 pipe->flags |= CVMX_USB_PIPE_FLAGS_NEED_PING;
2770 2772
2771 if (unlikely(WARN_ON_ONCE(bytes_this_transfer < 0))) { 2773 if (WARN_ON_ONCE(bytes_this_transfer < 0)) {
2772 /* 2774 /*
2773 * In some rare cases the DMA engine seems to get stuck and 2775 * In some rare cases the DMA engine seems to get stuck and
2774 * keeps substracting same byte count over and over again. In 2776 * keeps substracting same byte count over and over again. In
diff --git a/drivers/staging/olpc_dcon/Kconfig b/drivers/staging/olpc_dcon/Kconfig
index c91a56f77bcb..192cc8d0853f 100644
--- a/drivers/staging/olpc_dcon/Kconfig
+++ b/drivers/staging/olpc_dcon/Kconfig
@@ -2,6 +2,7 @@ config FB_OLPC_DCON
2 tristate "One Laptop Per Child Display CONtroller support" 2 tristate "One Laptop Per Child Display CONtroller support"
3 depends on OLPC && FB 3 depends on OLPC && FB
4 depends on I2C 4 depends on I2C
5 depends on BACKLIGHT_LCD_SUPPORT
5 depends on (GPIO_CS5535 || GPIO_CS5535=n) 6 depends on (GPIO_CS5535 || GPIO_CS5535=n)
6 select BACKLIGHT_CLASS_DEVICE 7 select BACKLIGHT_CLASS_DEVICE
7 help 8 help
diff --git a/drivers/staging/olpc_dcon/olpc_dcon.c b/drivers/staging/olpc_dcon/olpc_dcon.c
index 2744c9f0920e..6b714f740ac3 100644
--- a/drivers/staging/olpc_dcon/olpc_dcon.c
+++ b/drivers/staging/olpc_dcon/olpc_dcon.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Mainly by David Woodhouse, somewhat modified by Jordan Crouse 3 * Mainly by David Woodhouse, somewhat modified by Jordan Crouse
3 * 4 *
@@ -5,10 +6,6 @@
5 * Copyright © 2006-2007 Advanced Micro Devices, Inc. 6 * Copyright © 2006-2007 Advanced Micro Devices, Inc.
6 * Copyright © 2009 VIA Technology, Inc. 7 * Copyright © 2009 VIA Technology, Inc.
7 * Copyright (c) 2010-2011 Andres Salomon <dilinger@queued.net> 8 * Copyright (c) 2010-2011 Andres Salomon <dilinger@queued.net>
8 *
9 * This program is free software. You can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
12 */ 9 */
13 10
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 11#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
diff --git a/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c b/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c
index 633c58ce24ee..ff145d493e1b 100644
--- a/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c
+++ b/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Mainly by David Woodhouse, somewhat modified by Jordan Crouse 3 * Mainly by David Woodhouse, somewhat modified by Jordan Crouse
3 * 4 *
@@ -5,10 +6,6 @@
5 * Copyright © 2006-2007 Advanced Micro Devices, Inc. 6 * Copyright © 2006-2007 Advanced Micro Devices, Inc.
6 * Copyright © 2009 VIA Technology, Inc. 7 * Copyright © 2009 VIA Technology, Inc.
7 * Copyright (c) 2010 Andres Salomon <dilinger@queued.net> 8 * Copyright (c) 2010 Andres Salomon <dilinger@queued.net>
8 *
9 * This program is free software. You can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
12 */ 9 */
13 10
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 11#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
diff --git a/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c b/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c
index 64584425b01c..838daa2be3ef 100644
--- a/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c
+++ b/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c
@@ -1,9 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (c) 2009,2010 One Laptop per Child 3 * Copyright (c) 2009,2010 One Laptop per Child
3 *
4 * This program is free software. You can redistribute it and/or
5 * modify it under the terms of version 2 of the GNU General Public
6 * License as published by the Free Software Foundation.
7 */ 4 */
8 5
9#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 6#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
diff --git a/drivers/staging/pi433/rf69.c b/drivers/staging/pi433/rf69.c
index 085272fb393f..4fa6c0237e59 100644
--- a/drivers/staging/pi433/rf69.c
+++ b/drivers/staging/pi433/rf69.c
@@ -853,7 +853,6 @@ int rf69_write_fifo(struct spi_device *spi, u8 *buffer, unsigned int size)
853#ifdef DEBUG_FIFO_ACCESS 853#ifdef DEBUG_FIFO_ACCESS
854 int i; 854 int i;
855#endif 855#endif
856 char spi_address = REG_FIFO | WRITE_BIT;
857 u8 local_buffer[FIFO_SIZE + 1]; 856 u8 local_buffer[FIFO_SIZE + 1];
858 857
859 if (size > FIFO_SIZE) { 858 if (size > FIFO_SIZE) {
@@ -862,7 +861,7 @@ int rf69_write_fifo(struct spi_device *spi, u8 *buffer, unsigned int size)
862 return -EMSGSIZE; 861 return -EMSGSIZE;
863 } 862 }
864 863
865 local_buffer[0] = spi_address; 864 local_buffer[0] = REG_FIFO | WRITE_BIT;
866 memcpy(&local_buffer[1], buffer, size); 865 memcpy(&local_buffer[1], buffer, size);
867 866
868#ifdef DEBUG_FIFO_ACCESS 867#ifdef DEBUG_FIFO_ACCESS
diff --git a/drivers/staging/rtl8188eu/Makefile b/drivers/staging/rtl8188eu/Makefile
index 4e606b03ec03..7da911c2ab89 100644
--- a/drivers/staging/rtl8188eu/Makefile
+++ b/drivers/staging/rtl8188eu/Makefile
@@ -28,7 +28,7 @@ r8188eu-y := \
28 hal/hal_intf.o \ 28 hal/hal_intf.o \
29 hal/hal_com.o \ 29 hal/hal_com.o \
30 hal/odm.o \ 30 hal/odm.o \
31 hal/odm_HWConfig.o \ 31 hal/odm_hwconfig.o \
32 hal/odm_rtl8188e.o \ 32 hal/odm_rtl8188e.o \
33 hal/rtl8188e_cmd.o \ 33 hal/rtl8188e_cmd.o \
34 hal/rtl8188e_dm.o \ 34 hal/rtl8188e_dm.o \
diff --git a/drivers/staging/rtl8188eu/TODO b/drivers/staging/rtl8188eu/TODO
index 7581e25f231d..5faa0a9bba25 100644
--- a/drivers/staging/rtl8188eu/TODO
+++ b/drivers/staging/rtl8188eu/TODO
@@ -1,5 +1,5 @@
1TODO: 1TODO:
2- find and remove remaining code valid only for 5 HGz. Most of the obvious 2- find and remove remaining code valid only for 5 GHz. Most of the obvious
3 ones have been removed, but things like channel > 14 still exist. 3 ones have been removed, but things like channel > 14 still exist.
4- find and remove any code for other chips that is left over 4- find and remove any code for other chips that is left over
5- convert any remaining unusual variable types 5- convert any remaining unusual variable types
diff --git a/drivers/staging/rtl8188eu/core/rtw_ap.c b/drivers/staging/rtl8188eu/core/rtw_ap.c
index 676d549ef786..1c319c2ca86d 100644
--- a/drivers/staging/rtl8188eu/core/rtw_ap.c
+++ b/drivers/staging/rtl8188eu/core/rtw_ap.c
@@ -36,7 +36,7 @@ void free_mlme_ap_info(struct adapter *padapter)
36 struct sta_priv *pstapriv = &padapter->stapriv; 36 struct sta_priv *pstapriv = &padapter->stapriv;
37 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 37 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
38 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 38 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
39 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); 39 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
40 40
41 pmlmepriv->update_bcn = false; 41 pmlmepriv->update_bcn = false;
42 pmlmeext->bstart_bss = false; 42 pmlmeext->bstart_bss = false;
@@ -337,8 +337,6 @@ void add_RATid(struct adapter *padapter, struct sta_info *psta, u8 rssi_level)
337 unsigned char sta_band = 0, raid, shortGIrate = false; 337 unsigned char sta_band = 0, raid, shortGIrate = false;
338 unsigned int tx_ra_bitmap = 0; 338 unsigned int tx_ra_bitmap = 0;
339 struct ht_priv *psta_ht = NULL; 339 struct ht_priv *psta_ht = NULL;
340 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
341 struct wlan_bssid_ex *pcur_network = (struct wlan_bssid_ex *)&pmlmepriv->cur_network.network;
342 340
343 if (psta) 341 if (psta)
344 psta_ht = &psta->htpriv; 342 psta_ht = &psta->htpriv;
@@ -363,20 +361,13 @@ void add_RATid(struct adapter *padapter, struct sta_info *psta, u8 rssi_level)
363 shortGIrate = psta_ht->sgi; 361 shortGIrate = psta_ht->sgi;
364 } 362 }
365 363
366 if (pcur_network->Configuration.DSConfig > 14) { 364 if (tx_ra_bitmap & 0xffff000)
367 /* 5G band */ 365 sta_band |= WIRELESS_11_24N | WIRELESS_11G | WIRELESS_11B;
368 if (tx_ra_bitmap & 0xffff000) 366 else if (tx_ra_bitmap & 0xff0)
369 sta_band |= WIRELESS_11_5N | WIRELESS_11A; 367 sta_band |= WIRELESS_11G | WIRELESS_11B;
370 else 368 else
371 sta_band |= WIRELESS_11A; 369 sta_band |= WIRELESS_11B;
372 } else { 370
373 if (tx_ra_bitmap & 0xffff000)
374 sta_band |= WIRELESS_11_24N | WIRELESS_11G | WIRELESS_11B;
375 else if (tx_ra_bitmap & 0xff0)
376 sta_band |= WIRELESS_11G | WIRELESS_11B;
377 else
378 sta_band |= WIRELESS_11B;
379 }
380 371
381 psta->wireless_mode = sta_band; 372 psta->wireless_mode = sta_band;
382 373
diff --git a/drivers/staging/rtl8188eu/core/rtw_cmd.c b/drivers/staging/rtl8188eu/core/rtw_cmd.c
index 59039211dad2..9b2a497aa413 100644
--- a/drivers/staging/rtl8188eu/core/rtw_cmd.c
+++ b/drivers/staging/rtl8188eu/core/rtw_cmd.c
@@ -243,11 +243,11 @@ u8 rtw_sitesurvey_cmd(struct adapter *padapter, struct ndis_802_11_ssid *ssid,
243 if (check_fwstate(pmlmepriv, _FW_LINKED) == true) 243 if (check_fwstate(pmlmepriv, _FW_LINKED) == true)
244 rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_SCAN, 1); 244 rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_SCAN, 1);
245 245
246 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC); 246 ph2c = kzalloc(sizeof(*ph2c), GFP_ATOMIC);
247 if (!ph2c) 247 if (!ph2c)
248 return _FAIL; 248 return _FAIL;
249 249
250 psurveyPara = kzalloc(sizeof(struct sitesurvey_parm), GFP_ATOMIC); 250 psurveyPara = kzalloc(sizeof(*psurveyPara), GFP_ATOMIC);
251 if (!psurveyPara) { 251 if (!psurveyPara) {
252 kfree(ph2c); 252 kfree(ph2c);
253 return _FAIL; 253 return _FAIL;
@@ -325,7 +325,7 @@ u8 rtw_createbss_cmd(struct adapter *padapter)
325 else 325 else
326 RT_TRACE(_module_rtl871x_cmd_c_, _drv_info_, (" createbss for SSid:%s\n", pmlmepriv->assoc_ssid.Ssid)); 326 RT_TRACE(_module_rtl871x_cmd_c_, _drv_info_, (" createbss for SSid:%s\n", pmlmepriv->assoc_ssid.Ssid));
327 327
328 pcmd = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC); 328 pcmd = kzalloc(sizeof(*pcmd), GFP_ATOMIC);
329 if (!pcmd) { 329 if (!pcmd) {
330 res = _FAIL; 330 res = _FAIL;
331 goto exit; 331 goto exit;
@@ -367,7 +367,7 @@ u8 rtw_joinbss_cmd(struct adapter *padapter, struct wlan_network *pnetwork)
367 else 367 else
368 RT_TRACE(_module_rtl871x_cmd_c_, _drv_notice_, ("+Join cmd: SSid =[%s]\n", pmlmepriv->assoc_ssid.Ssid)); 368 RT_TRACE(_module_rtl871x_cmd_c_, _drv_notice_, ("+Join cmd: SSid =[%s]\n", pmlmepriv->assoc_ssid.Ssid));
369 369
370 pcmd = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC); 370 pcmd = kzalloc(sizeof(*pcmd), GFP_ATOMIC);
371 if (!pcmd) { 371 if (!pcmd) {
372 res = _FAIL; 372 res = _FAIL;
373 goto exit; 373 goto exit;
@@ -527,8 +527,8 @@ u8 rtw_setopmode_cmd(struct adapter *padapter, enum ndis_802_11_network_infra n
527 527
528 struct cmd_priv *pcmdpriv = &padapter->cmdpriv; 528 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
529 529
530 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); 530 ph2c = kzalloc(sizeof(*ph2c), GFP_KERNEL);
531 psetop = kzalloc(sizeof(struct setopmode_parm), GFP_KERNEL); 531 psetop = kzalloc(sizeof(*psetop), GFP_KERNEL);
532 if (!ph2c || !psetop) { 532 if (!ph2c || !psetop) {
533 kfree(ph2c); 533 kfree(ph2c);
534 kfree(psetop); 534 kfree(psetop);
@@ -552,9 +552,9 @@ u8 rtw_setstakey_cmd(struct adapter *padapter, u8 *psta, u8 unicast_key)
552 struct security_priv *psecuritypriv = &padapter->securitypriv; 552 struct security_priv *psecuritypriv = &padapter->securitypriv;
553 struct sta_info *sta = (struct sta_info *)psta; 553 struct sta_info *sta = (struct sta_info *)psta;
554 554
555 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); 555 ph2c = kzalloc(sizeof(*ph2c), GFP_KERNEL);
556 psetstakey_para = kzalloc(sizeof(struct set_stakey_parm), GFP_KERNEL); 556 psetstakey_para = kzalloc(sizeof(*psetstakey_para), GFP_KERNEL);
557 psetstakey_rsp = kzalloc(sizeof(struct set_stakey_rsp), GFP_KERNEL); 557 psetstakey_rsp = kzalloc(sizeof(*psetstakey_rsp), GFP_KERNEL);
558 558
559 if (!ph2c || !psetstakey_para || !psetstakey_rsp) { 559 if (!ph2c || !psetstakey_para || !psetstakey_rsp) {
560 kfree(ph2c); 560 kfree(ph2c);
@@ -597,20 +597,20 @@ u8 rtw_clearstakey_cmd(struct adapter *padapter, u8 *psta, u8 entry, u8 enqueue)
597 if (!enqueue) { 597 if (!enqueue) {
598 clear_cam_entry(padapter, entry); 598 clear_cam_entry(padapter, entry);
599 } else { 599 } else {
600 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC); 600 ph2c = kzalloc(sizeof(*ph2c), GFP_ATOMIC);
601 if (!ph2c) { 601 if (!ph2c) {
602 res = _FAIL; 602 res = _FAIL;
603 goto exit; 603 goto exit;
604 } 604 }
605 605
606 psetstakey_para = kzalloc(sizeof(struct set_stakey_parm), GFP_ATOMIC); 606 psetstakey_para = kzalloc(sizeof(*psetstakey_para), GFP_ATOMIC);
607 if (!psetstakey_para) { 607 if (!psetstakey_para) {
608 kfree(ph2c); 608 kfree(ph2c);
609 res = _FAIL; 609 res = _FAIL;
610 goto exit; 610 goto exit;
611 } 611 }
612 612
613 psetstakey_rsp = kzalloc(sizeof(struct set_stakey_rsp), GFP_ATOMIC); 613 psetstakey_rsp = kzalloc(sizeof(*psetstakey_rsp), GFP_ATOMIC);
614 if (!psetstakey_rsp) { 614 if (!psetstakey_rsp) {
615 kfree(ph2c); 615 kfree(ph2c);
616 kfree(psetstakey_para); 616 kfree(psetstakey_para);
@@ -642,13 +642,13 @@ u8 rtw_addbareq_cmd(struct adapter *padapter, u8 tid, u8 *addr)
642 struct addBaReq_parm *paddbareq_parm; 642 struct addBaReq_parm *paddbareq_parm;
643 u8 res = _SUCCESS; 643 u8 res = _SUCCESS;
644 644
645 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC); 645 ph2c = kzalloc(sizeof(*ph2c), GFP_ATOMIC);
646 if (!ph2c) { 646 if (!ph2c) {
647 res = _FAIL; 647 res = _FAIL;
648 goto exit; 648 goto exit;
649 } 649 }
650 650
651 paddbareq_parm = kzalloc(sizeof(struct addBaReq_parm), GFP_ATOMIC); 651 paddbareq_parm = kzalloc(sizeof(*paddbareq_parm), GFP_ATOMIC);
652 if (!paddbareq_parm) { 652 if (!paddbareq_parm) {
653 kfree(ph2c); 653 kfree(ph2c);
654 res = _FAIL; 654 res = _FAIL;
@@ -677,13 +677,13 @@ u8 rtw_dynamic_chk_wk_cmd(struct adapter *padapter)
677 struct cmd_priv *pcmdpriv = &padapter->cmdpriv; 677 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
678 u8 res = _SUCCESS; 678 u8 res = _SUCCESS;
679 679
680 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC); 680 ph2c = kzalloc(sizeof(*ph2c), GFP_ATOMIC);
681 if (!ph2c) { 681 if (!ph2c) {
682 res = _FAIL; 682 res = _FAIL;
683 goto exit; 683 goto exit;
684 } 684 }
685 685
686 pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_ATOMIC); 686 pdrvextra_cmd_parm = kzalloc(sizeof(*pdrvextra_cmd_parm), GFP_ATOMIC);
687 if (!pdrvextra_cmd_parm) { 687 if (!pdrvextra_cmd_parm) {
688 kfree(ph2c); 688 kfree(ph2c);
689 res = _FAIL; 689 res = _FAIL;
@@ -719,7 +719,7 @@ u8 rtw_set_chplan_cmd(struct adapter *padapter, u8 chplan, u8 enqueue)
719 } 719 }
720 720
721 /* prepare cmd parameter */ 721 /* prepare cmd parameter */
722 setChannelPlan_param = kzalloc(sizeof(struct SetChannelPlan_param), GFP_KERNEL); 722 setChannelPlan_param = kzalloc(sizeof(*setChannelPlan_param), GFP_KERNEL);
723 if (!setChannelPlan_param) { 723 if (!setChannelPlan_param) {
724 res = _FAIL; 724 res = _FAIL;
725 goto exit; 725 goto exit;
@@ -728,7 +728,7 @@ u8 rtw_set_chplan_cmd(struct adapter *padapter, u8 chplan, u8 enqueue)
728 728
729 if (enqueue) { 729 if (enqueue) {
730 /* need enqueue, prepare cmd_obj and enqueue */ 730 /* need enqueue, prepare cmd_obj and enqueue */
731 pcmdobj = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); 731 pcmdobj = kzalloc(sizeof(*pcmdobj), GFP_KERNEL);
732 if (!pcmdobj) { 732 if (!pcmdobj) {
733 kfree(setChannelPlan_param); 733 kfree(setChannelPlan_param);
734 res = _FAIL; 734 res = _FAIL;
@@ -745,7 +745,6 @@ u8 rtw_set_chplan_cmd(struct adapter *padapter, u8 chplan, u8 enqueue)
745 kfree(setChannelPlan_param); 745 kfree(setChannelPlan_param);
746 } 746 }
747 747
748 /* do something based on res... */
749 if (res == _SUCCESS) 748 if (res == _SUCCESS)
750 padapter->mlmepriv.ChannelPlan = chplan; 749 padapter->mlmepriv.ChannelPlan = chplan;
751 750
@@ -884,13 +883,13 @@ u8 rtw_lps_ctrl_wk_cmd(struct adapter *padapter, u8 lps_ctrl_type, u8 enqueue)
884 u8 res = _SUCCESS; 883 u8 res = _SUCCESS;
885 884
886 if (enqueue) { 885 if (enqueue) {
887 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC); 886 ph2c = kzalloc(sizeof(*ph2c), GFP_ATOMIC);
888 if (!ph2c) { 887 if (!ph2c) {
889 res = _FAIL; 888 res = _FAIL;
890 goto exit; 889 goto exit;
891 } 890 }
892 891
893 pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_ATOMIC); 892 pdrvextra_cmd_parm = kzalloc(sizeof(*pdrvextra_cmd_parm), GFP_ATOMIC);
894 if (!pdrvextra_cmd_parm) { 893 if (!pdrvextra_cmd_parm) {
895 kfree(ph2c); 894 kfree(ph2c);
896 res = _FAIL; 895 res = _FAIL;
@@ -926,13 +925,13 @@ u8 rtw_rpt_timer_cfg_cmd(struct adapter *padapter, u16 min_time)
926 925
927 u8 res = _SUCCESS; 926 u8 res = _SUCCESS;
928 927
929 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC); 928 ph2c = kzalloc(sizeof(*ph2c), GFP_ATOMIC);
930 if (!ph2c) { 929 if (!ph2c) {
931 res = _FAIL; 930 res = _FAIL;
932 goto exit; 931 goto exit;
933 } 932 }
934 933
935 pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_ATOMIC); 934 pdrvextra_cmd_parm = kzalloc(sizeof(*pdrvextra_cmd_parm), GFP_ATOMIC);
936 if (!pdrvextra_cmd_parm) { 935 if (!pdrvextra_cmd_parm) {
937 kfree(ph2c); 936 kfree(ph2c);
938 res = _FAIL; 937 res = _FAIL;
@@ -967,13 +966,13 @@ u8 rtw_antenna_select_cmd(struct adapter *padapter, u8 antenna, u8 enqueue)
967 return res; 966 return res;
968 967
969 if (enqueue) { 968 if (enqueue) {
970 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); 969 ph2c = kzalloc(sizeof(*ph2c), GFP_KERNEL);
971 if (!ph2c) { 970 if (!ph2c) {
972 res = _FAIL; 971 res = _FAIL;
973 goto exit; 972 goto exit;
974 } 973 }
975 974
976 pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_KERNEL); 975 pdrvextra_cmd_parm = kzalloc(sizeof(*pdrvextra_cmd_parm), GFP_KERNEL);
977 if (!pdrvextra_cmd_parm) { 976 if (!pdrvextra_cmd_parm) {
978 kfree(ph2c); 977 kfree(ph2c);
979 res = _FAIL; 978 res = _FAIL;
@@ -1000,8 +999,8 @@ u8 rtw_ps_cmd(struct adapter *padapter)
1000 struct drvextra_cmd_parm *pdrvextra_cmd_parm; 999 struct drvextra_cmd_parm *pdrvextra_cmd_parm;
1001 struct cmd_priv *pcmdpriv = &padapter->cmdpriv; 1000 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1002 1001
1003 ppscmd = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC); 1002 ppscmd = kzalloc(sizeof(*ppscmd), GFP_ATOMIC);
1004 pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_ATOMIC); 1003 pdrvextra_cmd_parm = kzalloc(sizeof(*pdrvextra_cmd_parm), GFP_ATOMIC);
1005 if (!ppscmd || !pdrvextra_cmd_parm) { 1004 if (!ppscmd || !pdrvextra_cmd_parm) {
1006 kfree(ppscmd); 1005 kfree(ppscmd);
1007 kfree(pdrvextra_cmd_parm); 1006 kfree(pdrvextra_cmd_parm);
@@ -1064,13 +1063,13 @@ u8 rtw_chk_hi_queue_cmd(struct adapter *padapter)
1064 struct cmd_priv *pcmdpriv = &padapter->cmdpriv; 1063 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1065 u8 res = _SUCCESS; 1064 u8 res = _SUCCESS;
1066 1065
1067 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); 1066 ph2c = kzalloc(sizeof(*ph2c), GFP_ATOMIC);
1068 if (!ph2c) { 1067 if (!ph2c) {
1069 res = _FAIL; 1068 res = _FAIL;
1070 goto exit; 1069 goto exit;
1071 } 1070 }
1072 1071
1073 pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_KERNEL); 1072 pdrvextra_cmd_parm = kzalloc(sizeof(*pdrvextra_cmd_parm), GFP_ATOMIC);
1074 if (!pdrvextra_cmd_parm) { 1073 if (!pdrvextra_cmd_parm) {
1075 kfree(ph2c); 1074 kfree(ph2c);
1076 res = _FAIL; 1075 res = _FAIL;
diff --git a/drivers/staging/rtl8188eu/core/rtw_debug.c b/drivers/staging/rtl8188eu/core/rtw_debug.c
index 67461fdf315c..6c2fe1a112ac 100644
--- a/drivers/staging/rtl8188eu/core/rtw_debug.c
+++ b/drivers/staging/rtl8188eu/core/rtw_debug.c
@@ -153,13 +153,11 @@ int proc_get_best_channel(char *page, char **start,
153 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); 153 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
154 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 154 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
155 int len = 0; 155 int len = 0;
156 u32 i, best_channel_24G = 1, best_channel_5G = 36, index_24G = 0, index_5G = 0; 156 u32 i, best_channel_24G = 1, index_24G = 0;
157 157
158 for (i = 0; pmlmeext->channel_set[i].ChannelNum != 0; i++) { 158 for (i = 0; pmlmeext->channel_set[i].ChannelNum != 0; i++) {
159 if (pmlmeext->channel_set[i].ChannelNum == 1) 159 if (pmlmeext->channel_set[i].ChannelNum == 1)
160 index_24G = i; 160 index_24G = i;
161 if (pmlmeext->channel_set[i].ChannelNum == 36)
162 index_5G = i;
163 } 161 }
164 162
165 for (i = 0; pmlmeext->channel_set[i].ChannelNum != 0; i++) { 163 for (i = 0; pmlmeext->channel_set[i].ChannelNum != 0; i++) {
@@ -171,32 +169,11 @@ int proc_get_best_channel(char *page, char **start,
171 } 169 }
172 } 170 }
173 171
174 /* 5G */
175 if (pmlmeext->channel_set[i].ChannelNum >= 36 &&
176 pmlmeext->channel_set[i].ChannelNum < 140) {
177 /* Find primary channel */
178 if (((pmlmeext->channel_set[i].ChannelNum - 36) % 8 == 0) &&
179 (pmlmeext->channel_set[i].rx_count < pmlmeext->channel_set[index_5G].rx_count)) {
180 index_5G = i;
181 best_channel_5G = pmlmeext->channel_set[i].ChannelNum;
182 }
183 }
184
185 if (pmlmeext->channel_set[i].ChannelNum >= 149 &&
186 pmlmeext->channel_set[i].ChannelNum < 165) {
187 /* find primary channel */
188 if (((pmlmeext->channel_set[i].ChannelNum - 149) % 8 == 0) &&
189 (pmlmeext->channel_set[i].rx_count < pmlmeext->channel_set[index_5G].rx_count)) {
190 index_5G = i;
191 best_channel_5G = pmlmeext->channel_set[i].ChannelNum;
192 }
193 }
194 /* debug */ 172 /* debug */
195 len += snprintf(page + len, count - len, "The rx cnt of channel %3d = %d\n", 173 len += snprintf(page + len, count - len, "The rx cnt of channel %3d = %d\n",
196 pmlmeext->channel_set[i].ChannelNum, pmlmeext->channel_set[i].rx_count); 174 pmlmeext->channel_set[i].ChannelNum, pmlmeext->channel_set[i].rx_count);
197 } 175 }
198 176
199 len += snprintf(page + len, count - len, "best_channel_5G = %d\n", best_channel_5G);
200 len += snprintf(page + len, count - len, "best_channel_24G = %d\n", best_channel_24G); 177 len += snprintf(page + len, count - len, "best_channel_24G = %d\n", best_channel_24G);
201 178
202 *eof = 1; 179 *eof = 1;
diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c b/drivers/staging/rtl8188eu/core/rtw_efuse.c
index 0fd306a808c4..b7be71f904ed 100644
--- a/drivers/staging/rtl8188eu/core/rtw_efuse.c
+++ b/drivers/staging/rtl8188eu/core/rtw_efuse.c
@@ -22,13 +22,9 @@ enum{
22 }; 22 };
23 23
24/* 24/*
25 * Function: efuse_power_switch 25 * When we want to enable write operation, we should change to pwr on state.
26 * 26 * When we stop write, we should switch to 500k mode and disable LDO 2.5V.
27 * Overview: When we want to enable write operation, we should change to
28 * pwr on state. When we stop write, we should switch to 500k mode
29 * and disable LDO 2.5V.
30 */ 27 */
31
32void efuse_power_switch(struct adapter *pAdapter, u8 write, u8 pwrstate) 28void efuse_power_switch(struct adapter *pAdapter, u8 write, u8 pwrstate)
33{ 29{
34 u8 tempval; 30 u8 tempval;
@@ -41,7 +37,7 @@ void efuse_power_switch(struct adapter *pAdapter, u8 write, u8 pwrstate)
41 tmpv16 = usb_read16(pAdapter, REG_SYS_ISO_CTRL); 37 tmpv16 = usb_read16(pAdapter, REG_SYS_ISO_CTRL);
42 if (!(tmpv16 & PWC_EV12V)) { 38 if (!(tmpv16 & PWC_EV12V)) {
43 tmpv16 |= PWC_EV12V; 39 tmpv16 |= PWC_EV12V;
44 usb_write16(pAdapter, REG_SYS_ISO_CTRL, tmpv16); 40 usb_write16(pAdapter, REG_SYS_ISO_CTRL, tmpv16);
45 } 41 }
46 /* Reset: 0x0000h[28], default valid */ 42 /* Reset: 0x0000h[28], default valid */
47 tmpv16 = usb_read16(pAdapter, REG_SYS_FUNC_EN); 43 tmpv16 = usb_read16(pAdapter, REG_SYS_FUNC_EN);
@@ -86,16 +82,20 @@ efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf)
86 u16 **eFuseWord = NULL; 82 u16 **eFuseWord = NULL;
87 u16 efuse_utilized = 0; 83 u16 efuse_utilized = 0;
88 u8 u1temp = 0; 84 u8 u1temp = 0;
85 void **tmp = NULL;
89 86
90 efuseTbl = kzalloc(EFUSE_MAP_LEN_88E, GFP_KERNEL); 87 efuseTbl = kzalloc(EFUSE_MAP_LEN_88E, GFP_KERNEL);
91 if (!efuseTbl) 88 if (!efuseTbl)
92 return; 89 return;
93 90
94 eFuseWord = (u16 **)rtw_malloc2d(EFUSE_MAX_SECTION_88E, EFUSE_MAX_WORD_UNIT, sizeof(u16)); 91 tmp = kzalloc(EFUSE_MAX_SECTION_88E * (sizeof(void *) + EFUSE_MAX_WORD_UNIT * sizeof(u16)), GFP_KERNEL);
95 if (!eFuseWord) { 92 if (!tmp) {
96 DBG_88E("%s: alloc eFuseWord fail!\n", __func__); 93 DBG_88E("%s: alloc eFuseWord fail!\n", __func__);
97 goto eFuseWord_failed; 94 goto eFuseWord_failed;
98 } 95 }
96 for (i = 0; i < EFUSE_MAX_SECTION_88E; i++)
97 tmp[i] = ((char *)(tmp + EFUSE_MAX_SECTION_88E)) + i * EFUSE_MAX_WORD_UNIT * sizeof(u16);
98 eFuseWord = (u16 **)tmp;
99 99
100 /* 0. Refresh efuse init map as all oxFF. */ 100 /* 0. Refresh efuse init map as all oxFF. */
101 for (i = 0; i < EFUSE_MAX_SECTION_88E; i++) 101 for (i = 0; i < EFUSE_MAX_SECTION_88E; i++)
@@ -360,15 +360,13 @@ u8 Efuse_WordEnableDataWrite(struct adapter *pAdapter, u16 efuse_addr, u8 word_e
360 360
361static u16 Efuse_GetCurrentSize(struct adapter *pAdapter) 361static u16 Efuse_GetCurrentSize(struct adapter *pAdapter)
362{ 362{
363 int bContinual = true;
364 u16 efuse_addr = 0; 363 u16 efuse_addr = 0;
365 u8 hoffset = 0, hworden = 0; 364 u8 hoffset = 0, hworden = 0;
366 u8 efuse_data, word_cnts = 0; 365 u8 efuse_data, word_cnts = 0;
367 366
368 rtw_hal_get_hwreg(pAdapter, HW_VAR_EFUSE_BYTES, (u8 *)&efuse_addr); 367 rtw_hal_get_hwreg(pAdapter, HW_VAR_EFUSE_BYTES, (u8 *)&efuse_addr);
369 368
370 while (bContinual && 369 while (efuse_OneByteRead(pAdapter, efuse_addr, &efuse_data) &&
371 efuse_OneByteRead(pAdapter, efuse_addr, &efuse_data) &&
372 AVAILABLE_EFUSE_ADDR(efuse_addr)) { 370 AVAILABLE_EFUSE_ADDR(efuse_addr)) {
373 if (efuse_data != 0xFF) { 371 if (efuse_data != 0xFF) {
374 if ((efuse_data&0x1F) == 0x0F) { /* extended header */ 372 if ((efuse_data&0x1F) == 0x0F) { /* extended header */
@@ -390,7 +388,7 @@ static u16 Efuse_GetCurrentSize(struct adapter *pAdapter)
390 /* read next header */ 388 /* read next header */
391 efuse_addr = efuse_addr + (word_cnts*2)+1; 389 efuse_addr = efuse_addr + (word_cnts*2)+1;
392 } else { 390 } else {
393 bContinual = false; 391 break;
394 } 392 }
395 } 393 }
396 394
@@ -453,7 +451,7 @@ int Efuse_PgPacketRead(struct adapter *pAdapter, u8 offset, u8 *data)
453 bDataEmpty = false; 451 bDataEmpty = false;
454 } 452 }
455 } 453 }
456 if (bDataEmpty == false) { 454 if (!bDataEmpty) {
457 ReadState = PG_STATE_DATA; 455 ReadState = PG_STATE_DATA;
458 } else {/* read next header */ 456 } else {/* read next header */
459 efuse_addr = efuse_addr + (word_cnts*2)+1; 457 efuse_addr = efuse_addr + (word_cnts*2)+1;
@@ -512,7 +510,7 @@ static bool hal_EfuseFixHeaderProcess(struct adapter *pAdapter, u8 efuseType, st
512 510
513static bool hal_EfusePgPacketWrite2ByteHeader(struct adapter *pAdapter, u8 efuseType, u16 *pAddr, struct pgpkt *pTargetPkt) 511static bool hal_EfusePgPacketWrite2ByteHeader(struct adapter *pAdapter, u8 efuseType, u16 *pAddr, struct pgpkt *pTargetPkt)
514{ 512{
515 bool bRet = false; 513 bool ret = false;
516 u16 efuse_addr = *pAddr; 514 u16 efuse_addr = *pAddr;
517 u16 efuse_max_available_len = 515 u16 efuse_max_available_len =
518 EFUSE_REAL_CONTENT_LEN_88E - EFUSE_OOB_PROTECT_BYTES_88E; 516 EFUSE_REAL_CONTENT_LEN_88E - EFUSE_OOB_PROTECT_BYTES_88E;
@@ -564,7 +562,7 @@ static bool hal_EfusePgPacketWrite2ByteHeader(struct adapter *pAdapter, u8 efuse
564 if (!hal_EfuseFixHeaderProcess(pAdapter, efuseType, &fixPkt, &efuse_addr)) 562 if (!hal_EfuseFixHeaderProcess(pAdapter, efuseType, &fixPkt, &efuse_addr))
565 return false; 563 return false;
566 } else { 564 } else {
567 bRet = true; 565 ret = true;
568 break; 566 break;
569 } 567 }
570 } else if ((tmp_header & 0x1F) == 0x0F) { /* wrong extended header */ 568 } else if ((tmp_header & 0x1F) == 0x0F) { /* wrong extended header */
@@ -574,12 +572,12 @@ static bool hal_EfusePgPacketWrite2ByteHeader(struct adapter *pAdapter, u8 efuse
574 } 572 }
575 573
576 *pAddr = efuse_addr; 574 *pAddr = efuse_addr;
577 return bRet; 575 return ret;
578} 576}
579 577
580static bool hal_EfusePgPacketWrite1ByteHeader(struct adapter *pAdapter, u8 efuseType, u16 *pAddr, struct pgpkt *pTargetPkt) 578static bool hal_EfusePgPacketWrite1ByteHeader(struct adapter *pAdapter, u8 efuseType, u16 *pAddr, struct pgpkt *pTargetPkt)
581{ 579{
582 bool bRet = false; 580 bool ret = false;
583 u8 pg_header = 0, tmp_header = 0; 581 u8 pg_header = 0, tmp_header = 0;
584 u16 efuse_addr = *pAddr; 582 u16 efuse_addr = *pAddr;
585 u8 repeatcnt = 0; 583 u8 repeatcnt = 0;
@@ -597,7 +595,7 @@ static bool hal_EfusePgPacketWrite1ByteHeader(struct adapter *pAdapter, u8 efuse
597 } 595 }
598 596
599 if (pg_header == tmp_header) { 597 if (pg_header == tmp_header) {
600 bRet = true; 598 ret = true;
601 } else { 599 } else {
602 struct pgpkt fixPkt; 600 struct pgpkt fixPkt;
603 601
@@ -609,7 +607,7 @@ static bool hal_EfusePgPacketWrite1ByteHeader(struct adapter *pAdapter, u8 efuse
609 } 607 }
610 608
611 *pAddr = efuse_addr; 609 *pAddr = efuse_addr;
612 return bRet; 610 return ret;
613} 611}
614 612
615static bool hal_EfusePgPacketWriteData(struct adapter *pAdapter, u8 efuseType, u16 *pAddr, struct pgpkt *pTargetPkt) 613static bool hal_EfusePgPacketWriteData(struct adapter *pAdapter, u8 efuseType, u16 *pAddr, struct pgpkt *pTargetPkt)
@@ -639,14 +637,14 @@ hal_EfusePgPacketWriteHeader(
639 u16 *pAddr, 637 u16 *pAddr,
640 struct pgpkt *pTargetPkt) 638 struct pgpkt *pTargetPkt)
641{ 639{
642 bool bRet = false; 640 bool ret = false;
643 641
644 if (pTargetPkt->offset >= EFUSE_MAX_SECTION_BASE) 642 if (pTargetPkt->offset >= EFUSE_MAX_SECTION_BASE)
645 bRet = hal_EfusePgPacketWrite2ByteHeader(pAdapter, efuseType, pAddr, pTargetPkt); 643 ret = hal_EfusePgPacketWrite2ByteHeader(pAdapter, efuseType, pAddr, pTargetPkt);
646 else 644 else
647 bRet = hal_EfusePgPacketWrite1ByteHeader(pAdapter, efuseType, pAddr, pTargetPkt); 645 ret = hal_EfusePgPacketWrite1ByteHeader(pAdapter, efuseType, pAddr, pTargetPkt);
648 646
649 return bRet; 647 return ret;
650} 648}
651 649
652static bool wordEnMatched(struct pgpkt *pTargetPkt, struct pgpkt *pCurPkt, 650static bool wordEnMatched(struct pgpkt *pTargetPkt, struct pgpkt *pCurPkt,
@@ -678,19 +676,19 @@ static bool wordEnMatched(struct pgpkt *pTargetPkt, struct pgpkt *pCurPkt,
678 676
679static bool hal_EfuseCheckIfDatafollowed(struct adapter *pAdapter, u8 word_cnts, u16 startAddr) 677static bool hal_EfuseCheckIfDatafollowed(struct adapter *pAdapter, u8 word_cnts, u16 startAddr)
680{ 678{
681 bool bRet = false; 679 bool ret = false;
682 u8 i, efuse_data; 680 u8 i, efuse_data;
683 681
684 for (i = 0; i < (word_cnts*2); i++) { 682 for (i = 0; i < (word_cnts*2); i++) {
685 if (efuse_OneByteRead(pAdapter, (startAddr+i), &efuse_data) && (efuse_data != 0xFF)) 683 if (efuse_OneByteRead(pAdapter, (startAddr+i), &efuse_data) && (efuse_data != 0xFF))
686 bRet = true; 684 ret = true;
687 } 685 }
688 return bRet; 686 return ret;
689} 687}
690 688
691static bool hal_EfusePartialWriteCheck(struct adapter *pAdapter, u8 efuseType, u16 *pAddr, struct pgpkt *pTargetPkt) 689static bool hal_EfusePartialWriteCheck(struct adapter *pAdapter, u8 efuseType, u16 *pAddr, struct pgpkt *pTargetPkt)
692{ 690{
693 bool bRet = false; 691 bool ret = false;
694 u8 i, efuse_data = 0, cur_header = 0; 692 u8 i, efuse_data = 0, cur_header = 0;
695 u8 matched_wden = 0, badworden = 0; 693 u8 matched_wden = 0, badworden = 0;
696 u16 startAddr = 0; 694 u16 startAddr = 0;
@@ -703,7 +701,7 @@ static bool hal_EfusePartialWriteCheck(struct adapter *pAdapter, u8 efuseType, u
703 701
704 while (1) { 702 while (1) {
705 if (startAddr >= efuse_max_available_len) { 703 if (startAddr >= efuse_max_available_len) {
706 bRet = false; 704 ret = false;
707 break; 705 break;
708 } 706 }
709 707
@@ -713,7 +711,7 @@ static bool hal_EfusePartialWriteCheck(struct adapter *pAdapter, u8 efuseType, u
713 startAddr++; 711 startAddr++;
714 efuse_OneByteRead(pAdapter, startAddr, &efuse_data); 712 efuse_OneByteRead(pAdapter, startAddr, &efuse_data);
715 if (ALL_WORDS_DISABLED(efuse_data)) { 713 if (ALL_WORDS_DISABLED(efuse_data)) {
716 bRet = false; 714 ret = false;
717 break; 715 break;
718 } else { 716 } else {
719 curPkt.offset = ((cur_header & 0xE0) >> 5) | ((efuse_data & 0xF0) >> 1); 717 curPkt.offset = ((cur_header & 0xE0) >> 5) | ((efuse_data & 0xF0) >> 1);
@@ -740,7 +738,7 @@ static bool hal_EfusePartialWriteCheck(struct adapter *pAdapter, u8 efuseType, u
740 PgWriteSuccess = Efuse_PgPacketWrite(pAdapter, pTargetPkt->offset, badworden, pTargetPkt->data); 738 PgWriteSuccess = Efuse_PgPacketWrite(pAdapter, pTargetPkt->offset, badworden, pTargetPkt->data);
741 739
742 if (!PgWriteSuccess) { 740 if (!PgWriteSuccess) {
743 bRet = false; /* write fail, return */ 741 ret = false; /* write fail, return */
744 break; 742 break;
745 } 743 }
746 } 744 }
@@ -756,11 +754,11 @@ static bool hal_EfusePartialWriteCheck(struct adapter *pAdapter, u8 efuseType, u
756 } else { 754 } else {
757 /* not used header, 0xff */ 755 /* not used header, 0xff */
758 *pAddr = startAddr; 756 *pAddr = startAddr;
759 bRet = true; 757 ret = true;
760 break; 758 break;
761 } 759 }
762 } 760 }
763 return bRet; 761 return ret;
764} 762}
765 763
766static bool 764static bool
@@ -868,9 +866,7 @@ u8 efuse_OneByteWrite(struct adapter *pAdapter, u16 addr, u8 data)
868 return result; 866 return result;
869} 867}
870 868
871/* 869/* Read allowed word in current efuse section data. */
872 * Overview: Read allowed word in current efuse section data.
873 */
874void efuse_WordEnableDataRead(u8 word_en, u8 *sourdata, u8 *targetdata) 870void efuse_WordEnableDataRead(u8 word_en, u8 *sourdata, u8 *targetdata)
875{ 871{
876 if (!(word_en & BIT(0))) { 872 if (!(word_en & BIT(0))) {
@@ -891,9 +887,7 @@ void efuse_WordEnableDataRead(u8 word_en, u8 *sourdata, u8 *targetdata)
891 } 887 }
892} 888}
893 889
894/* 890/* Read All Efuse content */
895 * Overview: Read All Efuse content
896 */
897static void Efuse_ReadAllMap(struct adapter *pAdapter, u8 efuseType, u8 *Efuse) 891static void Efuse_ReadAllMap(struct adapter *pAdapter, u8 efuseType, u8 *Efuse)
898{ 892{
899 efuse_power_switch(pAdapter, false, true); 893 efuse_power_switch(pAdapter, false, true);
@@ -903,12 +897,8 @@ static void Efuse_ReadAllMap(struct adapter *pAdapter, u8 efuseType, u8 *Efuse)
903 efuse_power_switch(pAdapter, false, false); 897 efuse_power_switch(pAdapter, false, false);
904} 898}
905 899
906/* 900/* Transfer current EFUSE content to shadow init and modify map. */
907 * Overview: Transfer current EFUSE content to shadow init and modify map. 901void EFUSE_ShadowMapUpdate(struct adapter *pAdapter, u8 efuseType)
908 */
909void EFUSE_ShadowMapUpdate(
910 struct adapter *pAdapter,
911 u8 efuseType)
912{ 902{
913 struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter); 903 struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
914 904
diff --git a/drivers/staging/rtl8188eu/core/rtw_ieee80211.c b/drivers/staging/rtl8188eu/core/rtw_ieee80211.c
index 7d5cbaf50f1c..5c4ff81987bd 100644
--- a/drivers/staging/rtl8188eu/core/rtw_ieee80211.c
+++ b/drivers/staging/rtl8188eu/core/rtw_ieee80211.c
@@ -100,19 +100,13 @@ bool rtw_is_cckratesonly_included(u8 *rate)
100 100
101int rtw_check_network_type(unsigned char *rate, int ratelen, int channel) 101int rtw_check_network_type(unsigned char *rate, int ratelen, int channel)
102{ 102{
103 if (channel > 14) { 103 /* could be pure B, pure G, or B/G */
104 if (rtw_is_cckrates_included(rate)) 104 if (rtw_is_cckratesonly_included(rate))
105 return WIRELESS_INVALID; 105 return WIRELESS_11B;
106 else 106 else if (rtw_is_cckrates_included(rate))
107 return WIRELESS_11A; 107 return WIRELESS_11BG;
108 } else { /* could be pure B, pure G, or B/G */ 108 else
109 if (rtw_is_cckratesonly_included(rate)) 109 return WIRELESS_11G;
110 return WIRELESS_11B;
111 else if (rtw_is_cckrates_included(rate))
112 return WIRELESS_11BG;
113 else
114 return WIRELESS_11G;
115 }
116} 110}
117 111
118u8 *rtw_set_fixed_ie(void *pbuf, unsigned int len, void *source, 112u8 *rtw_set_fixed_ie(void *pbuf, unsigned int len, void *source,
@@ -252,7 +246,7 @@ int rtw_generate_ie(struct registry_priv *pregistrypriv)
252 wireless_mode = pregistrypriv->wireless_mode; 246 wireless_mode = pregistrypriv->wireless_mode;
253 } 247 }
254 248
255 rtw_set_supported_rate(pdev_network->SupportedRates, wireless_mode); 249 rtw_set_supported_rate(pdev_network->SupportedRates, wireless_mode);
256 250
257 rateLen = rtw_get_rateset_len(pdev_network->SupportedRates); 251 rateLen = rtw_get_rateset_len(pdev_network->SupportedRates);
258 252
@@ -290,7 +284,7 @@ unsigned char *rtw_get_wpa_ie(unsigned char *pie, uint *wpa_ie_len, int limit)
290 284
291 if (pbuf) { 285 if (pbuf) {
292 /* check if oui matches... */ 286 /* check if oui matches... */
293 if (!memcmp((pbuf + 2), wpa_oui_type, sizeof(wpa_oui_type)) == false) 287 if (memcmp((pbuf + 2), wpa_oui_type, sizeof(wpa_oui_type)))
294 goto check_next_ie; 288 goto check_next_ie;
295 289
296 /* check version... */ 290 /* check version... */
diff --git a/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
index c040f185074b..0b3eb0b40975 100644
--- a/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
+++ b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
@@ -17,11 +17,11 @@ u8 rtw_do_join(struct adapter *padapter)
17{ 17{
18 struct list_head *plist, *phead; 18 struct list_head *plist, *phead;
19 u8 *pibss = NULL; 19 u8 *pibss = NULL;
20 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 20 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
21 struct __queue *queue = &(pmlmepriv->scanned_queue); 21 struct __queue *queue = &pmlmepriv->scanned_queue;
22 u8 ret = _SUCCESS; 22 u8 ret = _SUCCESS;
23 23
24 spin_lock_bh(&(pmlmepriv->scanned_queue.lock)); 24 spin_lock_bh(&pmlmepriv->scanned_queue.lock);
25 phead = get_list_head(queue); 25 phead = get_list_head(queue);
26 plist = phead->next; 26 plist = phead->next;
27 27
@@ -36,7 +36,7 @@ u8 rtw_do_join(struct adapter *padapter)
36 pmlmepriv->to_join = true; 36 pmlmepriv->to_join = true;
37 37
38 if (list_empty(&queue->queue)) { 38 if (list_empty(&queue->queue)) {
39 spin_unlock_bh(&(pmlmepriv->scanned_queue.lock)); 39 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
40 _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING); 40 _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
41 41
42 /* when set_ssid/set_bssid for rtw_do_join(), but scanning queue is empty */ 42 /* when set_ssid/set_bssid for rtw_do_join(), but scanning queue is empty */
@@ -60,18 +60,18 @@ u8 rtw_do_join(struct adapter *padapter)
60 } else { 60 } else {
61 int select_ret; 61 int select_ret;
62 62
63 spin_unlock_bh(&(pmlmepriv->scanned_queue.lock)); 63 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
64 select_ret = rtw_select_and_join_from_scanned_queue(pmlmepriv); 64 select_ret = rtw_select_and_join_from_scanned_queue(pmlmepriv);
65 if (select_ret == _SUCCESS) { 65 if (select_ret == _SUCCESS) {
66 pmlmepriv->to_join = false; 66 pmlmepriv->to_join = false;
67 mod_timer(&pmlmepriv->assoc_timer, 67 mod_timer(&pmlmepriv->assoc_timer,
68 jiffies + msecs_to_jiffies(MAX_JOIN_TIMEOUT)); 68 jiffies + msecs_to_jiffies(MAX_JOIN_TIMEOUT));
69 } else { 69 } else {
70 if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true) { 70 if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) {
71 /* submit createbss_cmd to change to a ADHOC_MASTER */ 71 /* submit createbss_cmd to change to a ADHOC_MASTER */
72 72
73 /* pmlmepriv->lock has been acquired by caller... */ 73 /* pmlmepriv->lock has been acquired by caller... */
74 struct wlan_bssid_ex *pdev_network = &(padapter->registrypriv.dev_network); 74 struct wlan_bssid_ex *pdev_network = &padapter->registrypriv.dev_network;
75 75
76 pmlmepriv->fw_state = WIFI_ADHOC_MASTER_STATE; 76 pmlmepriv->fw_state = WIFI_ADHOC_MASTER_STATE;
77 77
@@ -136,16 +136,16 @@ u8 rtw_set_802_11_bssid(struct adapter *padapter, u8 *bssid)
136 spin_lock_bh(&pmlmepriv->lock); 136 spin_lock_bh(&pmlmepriv->lock);
137 137
138 DBG_88E("Set BSSID under fw_state = 0x%08x\n", get_fwstate(pmlmepriv)); 138 DBG_88E("Set BSSID under fw_state = 0x%08x\n", get_fwstate(pmlmepriv));
139 if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == true) 139 if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY))
140 goto handle_tkip_countermeasure; 140 goto handle_tkip_countermeasure;
141 else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING)) 141 else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING))
142 goto release_mlme_lock; 142 goto release_mlme_lock;
143 143
144 if (check_fwstate(pmlmepriv, _FW_LINKED|WIFI_ADHOC_MASTER_STATE)) { 144 if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE)) {
145 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_, ("set_bssid: _FW_LINKED||WIFI_ADHOC_MASTER_STATE\n")); 145 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_, ("set_bssid: _FW_LINKED||WIFI_ADHOC_MASTER_STATE\n"));
146 146
147 if (!memcmp(&pmlmepriv->cur_network.network.MacAddress, bssid, ETH_ALEN)) { 147 if (!memcmp(&pmlmepriv->cur_network.network.MacAddress, bssid, ETH_ALEN)) {
148 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == false) 148 if (!check_fwstate(pmlmepriv, WIFI_STATION_STATE))
149 goto release_mlme_lock;/* it means driver is in WIFI_ADHOC_MASTER_STATE, we needn't create bss again. */ 149 goto release_mlme_lock;/* it means driver is in WIFI_ADHOC_MASTER_STATE, we needn't create bss again. */
150 } else { 150 } else {
151 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_, ("Set BSSID not the same bssid\n")); 151 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_, ("Set BSSID not the same bssid\n"));
@@ -154,12 +154,12 @@ u8 rtw_set_802_11_bssid(struct adapter *padapter, u8 *bssid)
154 154
155 rtw_disassoc_cmd(padapter, 0, true); 155 rtw_disassoc_cmd(padapter, 0, true);
156 156
157 if (check_fwstate(pmlmepriv, _FW_LINKED) == true) 157 if (check_fwstate(pmlmepriv, _FW_LINKED))
158 rtw_indicate_disconnect(padapter); 158 rtw_indicate_disconnect(padapter);
159 159
160 rtw_free_assoc_resources(padapter); 160 rtw_free_assoc_resources(padapter);
161 161
162 if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true)) { 162 if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
163 _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE); 163 _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
164 set_fwstate(pmlmepriv, WIFI_ADHOC_STATE); 164 set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
165 } 165 }
@@ -172,7 +172,7 @@ handle_tkip_countermeasure:
172 if (padapter->securitypriv.btkip_countermeasure) { 172 if (padapter->securitypriv.btkip_countermeasure) {
173 cur_time = jiffies; 173 cur_time = jiffies;
174 174
175 if ((cur_time - padapter->securitypriv.btkip_countermeasure_time) > 60 * HZ) { 175 if (cur_time - padapter->securitypriv.btkip_countermeasure_time > 60 * HZ) {
176 padapter->securitypriv.btkip_countermeasure = false; 176 padapter->securitypriv.btkip_countermeasure = false;
177 padapter->securitypriv.btkip_countermeasure_time = 0; 177 padapter->securitypriv.btkip_countermeasure_time = 0;
178 } else { 178 } else {
@@ -220,18 +220,18 @@ u8 rtw_set_802_11_ssid(struct adapter *padapter, struct ndis_802_11_ssid *ssid)
220 spin_lock_bh(&pmlmepriv->lock); 220 spin_lock_bh(&pmlmepriv->lock);
221 221
222 DBG_88E("Set SSID under fw_state = 0x%08x\n", get_fwstate(pmlmepriv)); 222 DBG_88E("Set SSID under fw_state = 0x%08x\n", get_fwstate(pmlmepriv));
223 if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == true) 223 if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY))
224 goto handle_tkip_countermeasure; 224 goto handle_tkip_countermeasure;
225 else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == true) 225 else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING))
226 goto release_mlme_lock; 226 goto release_mlme_lock;
227 227
228 if (check_fwstate(pmlmepriv, _FW_LINKED|WIFI_ADHOC_MASTER_STATE)) { 228 if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE)) {
229 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_, 229 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_,
230 ("set_ssid: _FW_LINKED||WIFI_ADHOC_MASTER_STATE\n")); 230 ("set_ssid: _FW_LINKED||WIFI_ADHOC_MASTER_STATE\n"));
231 231
232 if ((pmlmepriv->assoc_ssid.SsidLength == ssid->SsidLength) && 232 if (pmlmepriv->assoc_ssid.SsidLength == ssid->SsidLength &&
233 (!memcmp(&pmlmepriv->assoc_ssid.Ssid, ssid->Ssid, ssid->SsidLength))) { 233 !memcmp(&pmlmepriv->assoc_ssid.Ssid, ssid->Ssid, ssid->SsidLength)) {
234 if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == false)) { 234 if (!check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
235 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_err_, 235 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_err_,
236 ("Set SSID is the same ssid, fw_state = 0x%08x\n", 236 ("Set SSID is the same ssid, fw_state = 0x%08x\n",
237 get_fwstate(pmlmepriv))); 237 get_fwstate(pmlmepriv)));
@@ -240,12 +240,12 @@ u8 rtw_set_802_11_ssid(struct adapter *padapter, struct ndis_802_11_ssid *ssid)
240 /* if in WIFI_ADHOC_MASTER_STATE | WIFI_ADHOC_STATE, create bss or rejoin again */ 240 /* if in WIFI_ADHOC_MASTER_STATE | WIFI_ADHOC_STATE, create bss or rejoin again */
241 rtw_disassoc_cmd(padapter, 0, true); 241 rtw_disassoc_cmd(padapter, 0, true);
242 242
243 if (check_fwstate(pmlmepriv, _FW_LINKED) == true) 243 if (check_fwstate(pmlmepriv, _FW_LINKED))
244 rtw_indicate_disconnect(padapter); 244 rtw_indicate_disconnect(padapter);
245 245
246 rtw_free_assoc_resources(padapter); 246 rtw_free_assoc_resources(padapter);
247 247
248 if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true) { 248 if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
249 _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE); 249 _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
250 set_fwstate(pmlmepriv, WIFI_ADHOC_STATE); 250 set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
251 } 251 }
@@ -262,12 +262,12 @@ u8 rtw_set_802_11_ssid(struct adapter *padapter, struct ndis_802_11_ssid *ssid)
262 262
263 rtw_disassoc_cmd(padapter, 0, true); 263 rtw_disassoc_cmd(padapter, 0, true);
264 264
265 if (check_fwstate(pmlmepriv, _FW_LINKED) == true) 265 if (check_fwstate(pmlmepriv, _FW_LINKED))
266 rtw_indicate_disconnect(padapter); 266 rtw_indicate_disconnect(padapter);
267 267
268 rtw_free_assoc_resources(padapter); 268 rtw_free_assoc_resources(padapter);
269 269
270 if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true) { 270 if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
271 _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE); 271 _clr_fwstate_(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
272 set_fwstate(pmlmepriv, WIFI_ADHOC_STATE); 272 set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
273 } 273 }
@@ -279,7 +279,7 @@ handle_tkip_countermeasure:
279 if (padapter->securitypriv.btkip_countermeasure) { 279 if (padapter->securitypriv.btkip_countermeasure) {
280 cur_time = jiffies; 280 cur_time = jiffies;
281 281
282 if ((cur_time - padapter->securitypriv.btkip_countermeasure_time) > 60 * HZ) { 282 if (cur_time - padapter->securitypriv.btkip_countermeasure_time > 60 * HZ) {
283 padapter->securitypriv.btkip_countermeasure = false; 283 padapter->securitypriv.btkip_countermeasure = false;
284 padapter->securitypriv.btkip_countermeasure_time = 0; 284 padapter->securitypriv.btkip_countermeasure_time = 0;
285 } else { 285 } else {
@@ -291,7 +291,7 @@ handle_tkip_countermeasure:
291 memcpy(&pmlmepriv->assoc_ssid, ssid, sizeof(struct ndis_802_11_ssid)); 291 memcpy(&pmlmepriv->assoc_ssid, ssid, sizeof(struct ndis_802_11_ssid));
292 pmlmepriv->assoc_by_bssid = false; 292 pmlmepriv->assoc_by_bssid = false;
293 293
294 if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == true) 294 if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY))
295 pmlmepriv->to_join = true; 295 pmlmepriv->to_join = true;
296 else 296 else
297 status = rtw_do_join(padapter); 297 status = rtw_do_join(padapter);
@@ -308,9 +308,9 @@ exit:
308u8 rtw_set_802_11_infrastructure_mode(struct adapter *padapter, 308u8 rtw_set_802_11_infrastructure_mode(struct adapter *padapter,
309 enum ndis_802_11_network_infra networktype) 309 enum ndis_802_11_network_infra networktype)
310{ 310{
311 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 311 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
312 struct wlan_network *cur_network = &pmlmepriv->cur_network; 312 struct wlan_network *cur_network = &pmlmepriv->cur_network;
313 enum ndis_802_11_network_infra *pold_state = &(cur_network->network.InfrastructureMode); 313 enum ndis_802_11_network_infra *pold_state = &cur_network->network.InfrastructureMode;
314 314
315 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_notice_, 315 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_notice_,
316 ("+rtw_set_802_11_infrastructure_mode: old =%d new =%d fw_state = 0x%08x\n", 316 ("+rtw_set_802_11_infrastructure_mode: old =%d new =%d fw_state = 0x%08x\n",
@@ -331,16 +331,17 @@ u8 rtw_set_802_11_infrastructure_mode(struct adapter *padapter,
331#endif 331#endif
332 } 332 }
333 333
334 if ((check_fwstate(pmlmepriv, _FW_LINKED)) || 334 if (check_fwstate(pmlmepriv, _FW_LINKED) ||
335 (*pold_state == Ndis802_11IBSS)) 335 *pold_state == Ndis802_11IBSS)
336 rtw_disassoc_cmd(padapter, 0, true); 336 rtw_disassoc_cmd(padapter, 0, true);
337 337
338 if ((check_fwstate(pmlmepriv, _FW_LINKED)) || 338 if (check_fwstate(pmlmepriv, _FW_LINKED) ||
339 (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE))) 339 check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE))
340 rtw_free_assoc_resources(padapter); 340 rtw_free_assoc_resources(padapter);
341 341
342 if ((*pold_state == Ndis802_11Infrastructure) || (*pold_state == Ndis802_11IBSS)) { 342 if (*pold_state == Ndis802_11Infrastructure ||
343 if (check_fwstate(pmlmepriv, _FW_LINKED) == true) 343 *pold_state == Ndis802_11IBSS) {
344 if (check_fwstate(pmlmepriv, _FW_LINKED))
344 rtw_indicate_disconnect(padapter); /* will clr Linked_state; before this function, we must have checked whether issue dis-assoc_cmd or not */ 345 rtw_indicate_disconnect(padapter); /* will clr Linked_state; before this function, we must have checked whether issue dis-assoc_cmd or not */
345 } 346 }
346 347
@@ -394,8 +395,8 @@ u8 rtw_set_802_11_disassociate(struct adapter *padapter)
394 395
395u8 rtw_set_802_11_bssid_list_scan(struct adapter *padapter, struct ndis_802_11_ssid *pssid, int ssid_max_num) 396u8 rtw_set_802_11_bssid_list_scan(struct adapter *padapter, struct ndis_802_11_ssid *pssid, int ssid_max_num)
396{ 397{
397 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 398 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
398 u8 res = true; 399 u8 res = true;
399 400
400 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_err_, ("+%s(), fw_state =%x\n", __func__, get_fwstate(pmlmepriv))); 401 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_err_, ("+%s(), fw_state =%x\n", __func__, get_fwstate(pmlmepriv)));
401 402
@@ -409,14 +410,14 @@ u8 rtw_set_802_11_bssid_list_scan(struct adapter *padapter, struct ndis_802_11_s
409 goto exit; 410 goto exit;
410 } 411 }
411 412
412 if ((check_fwstate(pmlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING)) || 413 if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY | _FW_UNDER_LINKING) ||
413 (pmlmepriv->LinkDetectInfo.bBusyTraffic)) { 414 pmlmepriv->LinkDetectInfo.bBusyTraffic) {
414 /* Scan or linking is in progress, do nothing. */ 415 /* Scan or linking is in progress, do nothing. */
415 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_err_, ("%s fail since fw_state = %x\n", __func__, get_fwstate(pmlmepriv))); 416 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_err_, ("%s fail since fw_state = %x\n", __func__, get_fwstate(pmlmepriv)));
416 res = true; 417 res = true;
417 418
418 if (check_fwstate(pmlmepriv, 419 if (check_fwstate(pmlmepriv,
419 (_FW_UNDER_SURVEY|_FW_UNDER_LINKING)) == true) 420 _FW_UNDER_SURVEY | _FW_UNDER_LINKING))
420 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_err_, ("\n###_FW_UNDER_SURVEY|_FW_UNDER_LINKING\n\n")); 421 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_err_, ("\n###_FW_UNDER_SURVEY|_FW_UNDER_LINKING\n\n"));
421 else 422 else
422 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_err_, ("\n###pmlmepriv->sitesurveyctrl.traffic_busy == true\n\n")); 423 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_err_, ("\n###pmlmepriv->sitesurveyctrl.traffic_busy == true\n\n"));
@@ -444,7 +445,8 @@ u8 rtw_set_802_11_authentication_mode(struct adapter *padapter, enum ndis_802_11
444 int res; 445 int res;
445 u8 ret; 446 u8 ret;
446 447
447 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_, ("set_802_11_auth.mode(): mode =%x\n", authmode)); 448 RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_,
449 ("set_802_11_auth.mode(): mode =%x\n", authmode));
448 450
449 psecuritypriv->ndisauthtype = authmode; 451 psecuritypriv->ndisauthtype = authmode;
450 452
@@ -467,9 +469,9 @@ u8 rtw_set_802_11_authentication_mode(struct adapter *padapter, enum ndis_802_11
467 469
468u8 rtw_set_802_11_add_wep(struct adapter *padapter, struct ndis_802_11_wep *wep) 470u8 rtw_set_802_11_add_wep(struct adapter *padapter, struct ndis_802_11_wep *wep)
469{ 471{
470 int keyid, res; 472 int keyid, res;
471 struct security_priv *psecuritypriv = &(padapter->securitypriv); 473 struct security_priv *psecuritypriv = &padapter->securitypriv;
472 u8 ret = _SUCCESS; 474 u8 ret = _SUCCESS;
473 475
474 keyid = wep->KeyIndex & 0x3fffffff; 476 keyid = wep->KeyIndex & 0x3fffffff;
475 477
@@ -497,7 +499,8 @@ u8 rtw_set_802_11_add_wep(struct adapter *padapter, struct ndis_802_11_wep *wep)
497 ("rtw_set_802_11_add_wep:before memcpy, wep->KeyLength = 0x%x wep->KeyIndex = 0x%x keyid =%x\n", 499 ("rtw_set_802_11_add_wep:before memcpy, wep->KeyLength = 0x%x wep->KeyIndex = 0x%x keyid =%x\n",
498 wep->KeyLength, wep->KeyIndex, keyid)); 500 wep->KeyLength, wep->KeyIndex, keyid));
499 501
500 memcpy(&(psecuritypriv->dot11DefKey[keyid].skey[0]), &(wep->KeyMaterial), wep->KeyLength); 502 memcpy(&psecuritypriv->dot11DefKey[keyid].skey[0],
503 &wep->KeyMaterial, wep->KeyLength);
501 504
502 psecuritypriv->dot11DefKeylen[keyid] = wep->KeyLength; 505 psecuritypriv->dot11DefKeylen[keyid] = wep->KeyLength;
503 506
@@ -527,31 +530,27 @@ exit:
527 return ret; 530 return ret;
528} 531}
529 532
530/* 533/* Return 0 or 100Kbps */
531* rtw_get_cur_max_rate -
532* @adapter: pointer to struct adapter structure
533*
534* Return 0 or 100Kbps
535*/
536u16 rtw_get_cur_max_rate(struct adapter *adapter) 534u16 rtw_get_cur_max_rate(struct adapter *adapter)
537{ 535{
538 int i = 0; 536 int i = 0;
539 u8 *p; 537 u8 *p;
540 u16 rate = 0, max_rate = 0; 538 u16 rate = 0, max_rate = 0;
541 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv; 539 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
542 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); 540 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
543 struct registry_priv *pregistrypriv = &adapter->registrypriv; 541 struct registry_priv *pregistrypriv = &adapter->registrypriv;
544 struct mlme_priv *pmlmepriv = &adapter->mlmepriv; 542 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
545 struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network; 543 struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
546 u8 bw_40MHz = 0, short_GI_20 = 0, short_GI_40 = 0; 544 u8 bw_40MHz = 0, short_GI_20 = 0, short_GI_40 = 0;
547 u32 ht_ielen = 0; 545 u32 ht_ielen = 0;
548 546
549 if ((!check_fwstate(pmlmepriv, _FW_LINKED)) && 547 if (!check_fwstate(pmlmepriv, _FW_LINKED) &&
550 (!check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE))) 548 !check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE))
551 return 0; 549 return 0;
552 550
553 if (pmlmeext->cur_wireless_mode & (WIRELESS_11_24N|WIRELESS_11_5N)) { 551 if (pmlmeext->cur_wireless_mode & (WIRELESS_11_24N | WIRELESS_11_5N)) {
554 p = rtw_get_ie(&pcur_bss->ies[12], _HT_CAPABILITY_IE_, &ht_ielen, pcur_bss->ie_length-12); 552 p = rtw_get_ie(&pcur_bss->ies[12], _HT_CAPABILITY_IE_,
553 &ht_ielen, pcur_bss->ie_length - 12);
555 if (p && ht_ielen > 0) { 554 if (p && ht_ielen > 0) {
556 /* cur_bwmod is updated by beacon, pmlmeinfo is updated by association response */ 555 /* cur_bwmod is updated by beacon, pmlmeinfo is updated by association response */
557 bw_40MHz = (pmlmeext->cur_bwmode && (HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH & pmlmeinfo->HT_info.infos[0])) ? 1 : 0; 556 bw_40MHz = (pmlmeext->cur_bwmode && (HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH & pmlmeinfo->HT_info.infos[0])) ? 1 : 0;
@@ -561,33 +560,28 @@ u16 rtw_get_cur_max_rate(struct adapter *adapter)
561 560
562 max_rate = rtw_mcs_rate( 561 max_rate = rtw_mcs_rate(
563 RF_1T1R, 562 RF_1T1R,
564 bw_40MHz & (pregistrypriv->cbw40_enable), 563 bw_40MHz & pregistrypriv->cbw40_enable,
565 short_GI_20, 564 short_GI_20,
566 short_GI_40, 565 short_GI_40,
567 pmlmeinfo->HT_caps.mcs.rx_mask 566 pmlmeinfo->HT_caps.mcs.rx_mask
568 ); 567 );
569 } 568 }
570 } else { 569 } else {
571 while ((pcur_bss->SupportedRates[i] != 0) && (pcur_bss->SupportedRates[i] != 0xFF)) { 570 while (pcur_bss->SupportedRates[i] != 0 &&
572 rate = pcur_bss->SupportedRates[i]&0x7F; 571 pcur_bss->SupportedRates[i] != 0xFF) {
572 rate = pcur_bss->SupportedRates[i] & 0x7F;
573 if (rate > max_rate) 573 if (rate > max_rate)
574 max_rate = rate; 574 max_rate = rate;
575 i++; 575 i++;
576 } 576 }
577 577
578 max_rate = max_rate*10/2; 578 max_rate *= 5;
579 } 579 }
580 580
581 return max_rate; 581 return max_rate;
582} 582}
583 583
584/* 584/* Return _SUCCESS or _FAIL */
585* rtw_set_country -
586* @adapter: pointer to struct adapter structure
587* @country_code: string of country code
588*
589* Return _SUCCESS or _FAIL
590*/
591int rtw_set_country(struct adapter *adapter, const char *country_code) 585int rtw_set_country(struct adapter *adapter, const char *country_code)
592{ 586{
593 int i; 587 int i;
diff --git a/drivers/staging/rtl8188eu/core/rtw_led.c b/drivers/staging/rtl8188eu/core/rtw_led.c
index cbef871a7679..a2e7789aecbd 100644
--- a/drivers/staging/rtl8188eu/core/rtw_led.c
+++ b/drivers/staging/rtl8188eu/core/rtw_led.c
@@ -18,7 +18,7 @@ static void BlinkTimerCallback(struct timer_list *t)
18 struct LED_871x *pLed = from_timer(pLed, t, BlinkTimer); 18 struct LED_871x *pLed = from_timer(pLed, t, BlinkTimer);
19 struct adapter *padapter = pLed->padapter; 19 struct adapter *padapter = pLed->padapter;
20 20
21 if ((padapter->bSurpriseRemoved) || (padapter->bDriverStopped)) 21 if (padapter->bSurpriseRemoved || padapter->bDriverStopped)
22 return; 22 return;
23 23
24 schedule_work(&pLed->BlinkWorkItem); 24 schedule_work(&pLed->BlinkWorkItem);
@@ -95,10 +95,12 @@ static void SwLedBlink1(struct LED_871x *pLed)
95 /* Change LED according to BlinkingLedState specified. */ 95 /* Change LED according to BlinkingLedState specified. */
96 if (pLed->BlinkingLedState == RTW_LED_ON) { 96 if (pLed->BlinkingLedState == RTW_LED_ON) {
97 SwLedOn(padapter, pLed); 97 SwLedOn(padapter, pLed);
98 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn on\n", pLed->BlinkTimes)); 98 RT_TRACE(_module_rtl8712_led_c_, _drv_info_,
99 ("Blinktimes (%d): turn on\n", pLed->BlinkTimes));
99 } else { 100 } else {
100 SwLedOff(padapter, pLed); 101 SwLedOff(padapter, pLed);
101 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn off\n", pLed->BlinkTimes)); 102 RT_TRACE(_module_rtl8712_led_c_, _drv_info_,
103 ("Blinktimes (%d): turn off\n", pLed->BlinkTimes));
102 } 104 }
103 105
104 if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) { 106 if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
@@ -245,131 +247,134 @@ static void SwLedControlMode1(struct adapter *padapter, enum LED_CTL_MODE LedAct
245 case LED_CTL_POWER_ON: 247 case LED_CTL_POWER_ON:
246 case LED_CTL_START_TO_LINK: 248 case LED_CTL_START_TO_LINK:
247 case LED_CTL_NO_LINK: 249 case LED_CTL_NO_LINK:
248 if (!pLed->bLedNoLinkBlinkInProgress) { 250 if (pLed->bLedNoLinkBlinkInProgress)
249 if (pLed->CurrLedState == LED_BLINK_SCAN || IS_LED_WPS_BLINKING(pLed)) 251 break;
250 return; 252 if (pLed->CurrLedState == LED_BLINK_SCAN ||
251 if (pLed->bLedLinkBlinkInProgress) { 253 IS_LED_WPS_BLINKING(pLed))
252 del_timer_sync(&pLed->BlinkTimer); 254 return;
253 pLed->bLedLinkBlinkInProgress = false; 255 if (pLed->bLedLinkBlinkInProgress) {
254 } 256 del_timer_sync(&pLed->BlinkTimer);
255 if (pLed->bLedBlinkInProgress) { 257 pLed->bLedLinkBlinkInProgress = false;
256 del_timer_sync(&pLed->BlinkTimer); 258 }
257 pLed->bLedBlinkInProgress = false; 259 if (pLed->bLedBlinkInProgress) {
258 } 260 del_timer_sync(&pLed->BlinkTimer);
259 261 pLed->bLedBlinkInProgress = false;
260 pLed->bLedNoLinkBlinkInProgress = true;
261 pLed->CurrLedState = LED_BLINK_SLOWLY;
262 if (pLed->bLedOn)
263 pLed->BlinkingLedState = RTW_LED_OFF;
264 else
265 pLed->BlinkingLedState = RTW_LED_ON;
266 mod_timer(&pLed->BlinkTimer, jiffies +
267 msecs_to_jiffies(LED_BLINK_NO_LINK_INTERVAL_ALPHA));
268 } 262 }
263 pLed->bLedNoLinkBlinkInProgress = true;
264 pLed->CurrLedState = LED_BLINK_SLOWLY;
265 if (pLed->bLedOn)
266 pLed->BlinkingLedState = RTW_LED_OFF;
267 else
268 pLed->BlinkingLedState = RTW_LED_ON;
269 mod_timer(&pLed->BlinkTimer, jiffies +
270 msecs_to_jiffies(LED_BLINK_NO_LINK_INTERVAL_ALPHA));
269 break; 271 break;
270 case LED_CTL_LINK: 272 case LED_CTL_LINK:
271 if (!pLed->bLedLinkBlinkInProgress) { 273 if (pLed->bLedLinkBlinkInProgress)
272 if (pLed->CurrLedState == LED_BLINK_SCAN || IS_LED_WPS_BLINKING(pLed)) 274 break;
273 return; 275 if (pLed->CurrLedState == LED_BLINK_SCAN ||
274 if (pLed->bLedNoLinkBlinkInProgress) { 276 IS_LED_WPS_BLINKING(pLed))
275 del_timer_sync(&pLed->BlinkTimer); 277 return;
276 pLed->bLedNoLinkBlinkInProgress = false; 278 if (pLed->bLedNoLinkBlinkInProgress) {
277 } 279 del_timer_sync(&pLed->BlinkTimer);
278 if (pLed->bLedBlinkInProgress) { 280 pLed->bLedNoLinkBlinkInProgress = false;
279 del_timer_sync(&pLed->BlinkTimer); 281 }
280 pLed->bLedBlinkInProgress = false; 282 if (pLed->bLedBlinkInProgress) {
281 } 283 del_timer_sync(&pLed->BlinkTimer);
282 pLed->bLedLinkBlinkInProgress = true; 284 pLed->bLedBlinkInProgress = false;
283 pLed->CurrLedState = LED_BLINK_NORMAL;
284 if (pLed->bLedOn)
285 pLed->BlinkingLedState = RTW_LED_OFF;
286 else
287 pLed->BlinkingLedState = RTW_LED_ON;
288 mod_timer(&pLed->BlinkTimer, jiffies +
289 msecs_to_jiffies(LED_BLINK_LINK_INTERVAL_ALPHA));
290 } 285 }
286 pLed->bLedLinkBlinkInProgress = true;
287 pLed->CurrLedState = LED_BLINK_NORMAL;
288 if (pLed->bLedOn)
289 pLed->BlinkingLedState = RTW_LED_OFF;
290 else
291 pLed->BlinkingLedState = RTW_LED_ON;
292 mod_timer(&pLed->BlinkTimer, jiffies +
293 msecs_to_jiffies(LED_BLINK_LINK_INTERVAL_ALPHA));
291 break; 294 break;
292 case LED_CTL_SITE_SURVEY: 295 case LED_CTL_SITE_SURVEY:
293 if ((pmlmepriv->LinkDetectInfo.bBusyTraffic) && (check_fwstate(pmlmepriv, _FW_LINKED))) { 296 if (pmlmepriv->LinkDetectInfo.bBusyTraffic &&
294 ; 297 check_fwstate(pmlmepriv, _FW_LINKED))
295 } else if (!pLed->bLedScanBlinkInProgress) { 298 break;
296 if (IS_LED_WPS_BLINKING(pLed)) 299 if (pLed->bLedScanBlinkInProgress)
297 return; 300 break;
298 if (pLed->bLedNoLinkBlinkInProgress) { 301 if (IS_LED_WPS_BLINKING(pLed))
299 del_timer_sync(&pLed->BlinkTimer); 302 return;
300 pLed->bLedNoLinkBlinkInProgress = false; 303 if (pLed->bLedNoLinkBlinkInProgress) {
301 } 304 del_timer_sync(&pLed->BlinkTimer);
302 if (pLed->bLedLinkBlinkInProgress) { 305 pLed->bLedNoLinkBlinkInProgress = false;
303 del_timer_sync(&pLed->BlinkTimer); 306 }
304 pLed->bLedLinkBlinkInProgress = false; 307 if (pLed->bLedLinkBlinkInProgress) {
305 } 308 del_timer_sync(&pLed->BlinkTimer);
306 if (pLed->bLedBlinkInProgress) { 309 pLed->bLedLinkBlinkInProgress = false;
307 del_timer_sync(&pLed->BlinkTimer); 310 }
308 pLed->bLedBlinkInProgress = false; 311 if (pLed->bLedBlinkInProgress) {
309 } 312 del_timer_sync(&pLed->BlinkTimer);
310 pLed->bLedScanBlinkInProgress = true; 313 pLed->bLedBlinkInProgress = false;
311 pLed->CurrLedState = LED_BLINK_SCAN;
312 pLed->BlinkTimes = 24;
313 if (pLed->bLedOn)
314 pLed->BlinkingLedState = RTW_LED_OFF;
315 else
316 pLed->BlinkingLedState = RTW_LED_ON;
317 mod_timer(&pLed->BlinkTimer, jiffies +
318 msecs_to_jiffies(LED_BLINK_SCAN_INTERVAL_ALPHA));
319 } 314 }
315 pLed->bLedScanBlinkInProgress = true;
316 pLed->CurrLedState = LED_BLINK_SCAN;
317 pLed->BlinkTimes = 24;
318 if (pLed->bLedOn)
319 pLed->BlinkingLedState = RTW_LED_OFF;
320 else
321 pLed->BlinkingLedState = RTW_LED_ON;
322 mod_timer(&pLed->BlinkTimer, jiffies +
323 msecs_to_jiffies(LED_BLINK_SCAN_INTERVAL_ALPHA));
320 break; 324 break;
321 case LED_CTL_TX: 325 case LED_CTL_TX:
322 case LED_CTL_RX: 326 case LED_CTL_RX:
323 if (!pLed->bLedBlinkInProgress) { 327 if (pLed->bLedBlinkInProgress)
324 if (pLed->CurrLedState == LED_BLINK_SCAN || IS_LED_WPS_BLINKING(pLed)) 328 break;
325 return; 329 if (pLed->CurrLedState == LED_BLINK_SCAN ||
326 if (pLed->bLedNoLinkBlinkInProgress) { 330 IS_LED_WPS_BLINKING(pLed))
327 del_timer_sync(&pLed->BlinkTimer); 331 return;
328 pLed->bLedNoLinkBlinkInProgress = false; 332 if (pLed->bLedNoLinkBlinkInProgress) {
329 } 333 del_timer_sync(&pLed->BlinkTimer);
330 if (pLed->bLedLinkBlinkInProgress) { 334 pLed->bLedNoLinkBlinkInProgress = false;
331 del_timer_sync(&pLed->BlinkTimer); 335 }
332 pLed->bLedLinkBlinkInProgress = false; 336 if (pLed->bLedLinkBlinkInProgress) {
333 } 337 del_timer_sync(&pLed->BlinkTimer);
334 pLed->bLedBlinkInProgress = true; 338 pLed->bLedLinkBlinkInProgress = false;
335 pLed->CurrLedState = LED_BLINK_TXRX;
336 pLed->BlinkTimes = 2;
337 if (pLed->bLedOn)
338 pLed->BlinkingLedState = RTW_LED_OFF;
339 else
340 pLed->BlinkingLedState = RTW_LED_ON;
341 mod_timer(&pLed->BlinkTimer, jiffies +
342 msecs_to_jiffies(LED_BLINK_FASTER_INTERVAL_ALPHA));
343 } 339 }
340 pLed->bLedBlinkInProgress = true;
341 pLed->CurrLedState = LED_BLINK_TXRX;
342 pLed->BlinkTimes = 2;
343 if (pLed->bLedOn)
344 pLed->BlinkingLedState = RTW_LED_OFF;
345 else
346 pLed->BlinkingLedState = RTW_LED_ON;
347 mod_timer(&pLed->BlinkTimer, jiffies +
348 msecs_to_jiffies(LED_BLINK_FASTER_INTERVAL_ALPHA));
344 break; 349 break;
345 case LED_CTL_START_WPS: /* wait until xinpin finish */ 350 case LED_CTL_START_WPS: /* wait until xinpin finish */
346 case LED_CTL_START_WPS_BOTTON: 351 case LED_CTL_START_WPS_BOTTON:
347 if (!pLed->bLedWPSBlinkInProgress) { 352 if (pLed->bLedWPSBlinkInProgress)
348 if (pLed->bLedNoLinkBlinkInProgress) { 353 break;
349 del_timer_sync(&pLed->BlinkTimer); 354 if (pLed->bLedNoLinkBlinkInProgress) {
350 pLed->bLedNoLinkBlinkInProgress = false; 355 del_timer_sync(&pLed->BlinkTimer);
351 } 356 pLed->bLedNoLinkBlinkInProgress = false;
352 if (pLed->bLedLinkBlinkInProgress) { 357 }
353 del_timer_sync(&pLed->BlinkTimer); 358 if (pLed->bLedLinkBlinkInProgress) {
354 pLed->bLedLinkBlinkInProgress = false; 359 del_timer_sync(&pLed->BlinkTimer);
355 } 360 pLed->bLedLinkBlinkInProgress = false;
356 if (pLed->bLedBlinkInProgress) {
357 del_timer_sync(&pLed->BlinkTimer);
358 pLed->bLedBlinkInProgress = false;
359 }
360 if (pLed->bLedScanBlinkInProgress) {
361 del_timer_sync(&pLed->BlinkTimer);
362 pLed->bLedScanBlinkInProgress = false;
363 }
364 pLed->bLedWPSBlinkInProgress = true;
365 pLed->CurrLedState = LED_BLINK_WPS;
366 if (pLed->bLedOn)
367 pLed->BlinkingLedState = RTW_LED_OFF;
368 else
369 pLed->BlinkingLedState = RTW_LED_ON;
370 mod_timer(&pLed->BlinkTimer, jiffies +
371 msecs_to_jiffies(LED_BLINK_SCAN_INTERVAL_ALPHA));
372 } 361 }
362 if (pLed->bLedBlinkInProgress) {
363 del_timer_sync(&pLed->BlinkTimer);
364 pLed->bLedBlinkInProgress = false;
365 }
366 if (pLed->bLedScanBlinkInProgress) {
367 del_timer_sync(&pLed->BlinkTimer);
368 pLed->bLedScanBlinkInProgress = false;
369 }
370 pLed->bLedWPSBlinkInProgress = true;
371 pLed->CurrLedState = LED_BLINK_WPS;
372 if (pLed->bLedOn)
373 pLed->BlinkingLedState = RTW_LED_OFF;
374 else
375 pLed->BlinkingLedState = RTW_LED_ON;
376 mod_timer(&pLed->BlinkTimer, jiffies +
377 msecs_to_jiffies(LED_BLINK_SCAN_INTERVAL_ALPHA));
373 break; 378 break;
374 case LED_CTL_STOP_WPS: 379 case LED_CTL_STOP_WPS:
375 if (pLed->bLedNoLinkBlinkInProgress) { 380 if (pLed->bLedNoLinkBlinkInProgress) {
@@ -378,7 +383,7 @@ static void SwLedControlMode1(struct adapter *padapter, enum LED_CTL_MODE LedAct
378 } 383 }
379 if (pLed->bLedLinkBlinkInProgress) { 384 if (pLed->bLedLinkBlinkInProgress) {
380 del_timer_sync(&pLed->BlinkTimer); 385 del_timer_sync(&pLed->BlinkTimer);
381 pLed->bLedLinkBlinkInProgress = false; 386 pLed->bLedLinkBlinkInProgress = false;
382 } 387 }
383 if (pLed->bLedBlinkInProgress) { 388 if (pLed->bLedBlinkInProgress) {
384 del_timer_sync(&pLed->BlinkTimer); 389 del_timer_sync(&pLed->BlinkTimer);
@@ -446,7 +451,8 @@ static void SwLedControlMode1(struct adapter *padapter, enum LED_CTL_MODE LedAct
446 break; 451 break;
447 } 452 }
448 453
449 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Led %d\n", pLed->CurrLedState)); 454 RT_TRACE(_module_rtl8712_led_c_, _drv_info_,
455 ("Led %d\n", pLed->CurrLedState));
450} 456}
451 457
452/* */ 458/* */
@@ -457,7 +463,7 @@ void BlinkHandler(struct LED_871x *pLed)
457{ 463{
458 struct adapter *padapter = pLed->padapter; 464 struct adapter *padapter = pLed->padapter;
459 465
460 if ((padapter->bSurpriseRemoved) || (padapter->bDriverStopped)) 466 if (padapter->bSurpriseRemoved || padapter->bDriverStopped)
461 return; 467 return;
462 468
463 SwLedBlink1(pLed); 469 SwLedBlink1(pLed);
@@ -465,8 +471,8 @@ void BlinkHandler(struct LED_871x *pLed)
465 471
466void LedControl8188eu(struct adapter *padapter, enum LED_CTL_MODE LedAction) 472void LedControl8188eu(struct adapter *padapter, enum LED_CTL_MODE LedAction)
467{ 473{
468 if ((padapter->bSurpriseRemoved) || (padapter->bDriverStopped) || 474 if (padapter->bSurpriseRemoved || padapter->bDriverStopped ||
469 (!padapter->hw_init_completed)) 475 !padapter->hw_init_completed)
470 return; 476 return;
471 477
472 if ((padapter->pwrctrlpriv.rf_pwrstate != rf_on && 478 if ((padapter->pwrctrlpriv.rf_pwrstate != rf_on &&
diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme.c b/drivers/staging/rtl8188eu/core/rtw_mlme.c
index eca06f05c0c4..b9bd864f323c 100644
--- a/drivers/staging/rtl8188eu/core/rtw_mlme.c
+++ b/drivers/staging/rtl8188eu/core/rtw_mlme.c
@@ -20,7 +20,7 @@
20#include <rtw_ioctl_set.h> 20#include <rtw_ioctl_set.h>
21#include <linux/vmalloc.h> 21#include <linux/vmalloc.h>
22 22
23extern unsigned char MCS_rate_1R[16]; 23extern const u8 MCS_rate_1R[16];
24 24
25int rtw_init_mlme_priv(struct adapter *padapter) 25int rtw_init_mlme_priv(struct adapter *padapter)
26{ 26{
@@ -228,7 +228,7 @@ int rtw_if_up(struct adapter *padapter)
228 int res; 228 int res;
229 229
230 if (padapter->bDriverStopped || padapter->bSurpriseRemoved || 230 if (padapter->bDriverStopped || padapter->bSurpriseRemoved ||
231 (check_fwstate(&padapter->mlmepriv, _FW_LINKED) == false)) { 231 !check_fwstate(&padapter->mlmepriv, _FW_LINKED)) {
232 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, 232 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
233 ("rtw_if_up:bDriverStopped(%d) OR bSurpriseRemoved(%d)", 233 ("rtw_if_up:bDriverStopped(%d) OR bSurpriseRemoved(%d)",
234 padapter->bDriverStopped, padapter->bSurpriseRemoved)); 234 padapter->bDriverStopped, padapter->bSurpriseRemoved));
@@ -305,7 +305,7 @@ static int is_same_ess(struct wlan_bssid_ex *a, struct wlan_bssid_ex *b)
305 305
306int is_same_network(struct wlan_bssid_ex *src, struct wlan_bssid_ex *dst) 306int is_same_network(struct wlan_bssid_ex *src, struct wlan_bssid_ex *dst)
307{ 307{
308 u16 s_cap, d_cap; 308 u16 s_cap, d_cap;
309 __le16 le_scap, le_dcap; 309 __le16 le_scap, le_dcap;
310 310
311 memcpy((u8 *)&le_scap, rtw_get_capability_from_ie(src->ies), 2); 311 memcpy((u8 *)&le_scap, rtw_get_capability_from_ie(src->ies), 2);
@@ -540,7 +540,7 @@ static int rtw_is_desired_network(struct adapter *adapter, struct wlan_network *
540/* TODO: Perry: For Power Management */ 540/* TODO: Perry: For Power Management */
541void rtw_atimdone_event_callback(struct adapter *adapter, u8 *pbuf) 541void rtw_atimdone_event_callback(struct adapter *adapter, u8 *pbuf)
542{ 542{
543 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("receive atimdone_evet\n")); 543 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("receive atimdone_event\n"));
544} 544}
545 545
546void rtw_survey_event_callback(struct adapter *adapter, u8 *pbuf) 546void rtw_survey_event_callback(struct adapter *adapter, u8 *pbuf)
@@ -578,7 +578,7 @@ void rtw_survey_event_callback(struct adapter *adapter, u8 *pbuf)
578 } 578 }
579 579
580 /* lock pmlmepriv->lock when you accessing network_q */ 580 /* lock pmlmepriv->lock when you accessing network_q */
581 if ((check_fwstate(pmlmepriv, _FW_UNDER_LINKING)) == false) { 581 if (!check_fwstate(pmlmepriv, _FW_UNDER_LINKING)) {
582 if (pnetwork->Ssid.Ssid[0] == 0) 582 if (pnetwork->Ssid.Ssid[0] == 0)
583 pnetwork->Ssid.SsidLength = 0; 583 pnetwork->Ssid.SsidLength = 0;
584 rtw_add_network(adapter, pnetwork); 584 rtw_add_network(adapter, pnetwork);
@@ -615,7 +615,7 @@ void rtw_surveydone_event_callback(struct adapter *adapter, u8 *pbuf)
615 615
616 if (pmlmepriv->to_join) { 616 if (pmlmepriv->to_join) {
617 if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true)) { 617 if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true)) {
618 if (check_fwstate(pmlmepriv, _FW_LINKED) == false) { 618 if (!check_fwstate(pmlmepriv, _FW_LINKED)) {
619 set_fwstate(pmlmepriv, _FW_UNDER_LINKING); 619 set_fwstate(pmlmepriv, _FW_UNDER_LINKING);
620 620
621 if (rtw_select_and_join_from_scanned_queue(pmlmepriv) == _SUCCESS) { 621 if (rtw_select_and_join_from_scanned_queue(pmlmepriv) == _SUCCESS) {
@@ -828,29 +828,6 @@ inline void rtw_indicate_scan_done(struct adapter *padapter, bool aborted)
828 rtw_os_indicate_scan_done(padapter, aborted); 828 rtw_os_indicate_scan_done(padapter, aborted);
829} 829}
830 830
831void rtw_scan_abort(struct adapter *adapter)
832{
833 unsigned long start;
834 struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
835 struct mlme_ext_priv *pmlmeext = &(adapter->mlmeextpriv);
836
837 start = jiffies;
838 pmlmeext->scan_abort = true;
839 while (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) &&
840 jiffies_to_msecs(jiffies - start) <= 200) {
841 if (adapter->bDriverStopped || adapter->bSurpriseRemoved)
842 break;
843 DBG_88E(FUNC_NDEV_FMT"fw_state=_FW_UNDER_SURVEY!\n", FUNC_NDEV_ARG(adapter->pnetdev));
844 msleep(20);
845 }
846 if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY)) {
847 if (!adapter->bDriverStopped && !adapter->bSurpriseRemoved)
848 DBG_88E(FUNC_NDEV_FMT"waiting for scan_abort time out!\n", FUNC_NDEV_ARG(adapter->pnetdev));
849 rtw_indicate_scan_done(adapter, true);
850 }
851 pmlmeext->scan_abort = false;
852}
853
854static struct sta_info *rtw_joinbss_update_stainfo(struct adapter *padapter, struct wlan_network *pnetwork) 831static struct sta_info *rtw_joinbss_update_stainfo(struct adapter *padapter, struct wlan_network *pnetwork)
855{ 832{
856 int i; 833 int i;
@@ -865,7 +842,7 @@ static struct sta_info *rtw_joinbss_update_stainfo(struct adapter *padapter, str
865 if (psta) { /* update ptarget_sta */ 842 if (psta) { /* update ptarget_sta */
866 DBG_88E("%s\n", __func__); 843 DBG_88E("%s\n", __func__);
867 psta->aid = pnetwork->join_res; 844 psta->aid = pnetwork->join_res;
868 psta->mac_id = 0; 845 psta->mac_id = 0;
869 /* sta mode */ 846 /* sta mode */
870 rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, true); 847 rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, true);
871 /* security related */ 848 /* security related */
@@ -1061,12 +1038,12 @@ void rtw_joinbss_event_prehandle(struct adapter *adapter, u8 *pbuf)
1061 } 1038 }
1062 1039
1063 /* s4. indicate connect */ 1040 /* s4. indicate connect */
1064 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true) { 1041 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true) {
1065 rtw_indicate_connect(adapter); 1042 rtw_indicate_connect(adapter);
1066 } else { 1043 } else {
1067 /* adhoc mode will rtw_indicate_connect when rtw_stassoc_event_callback */ 1044 /* adhoc mode will rtw_indicate_connect when rtw_stassoc_event_callback */
1068 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("adhoc mode, fw_state:%x", get_fwstate(pmlmepriv))); 1045 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("adhoc mode, fw_state:%x", get_fwstate(pmlmepriv)));
1069 } 1046 }
1070 1047
1071 /* s5. Cancel assoc_timer */ 1048 /* s5. Cancel assoc_timer */
1072 del_timer_sync(&pmlmepriv->assoc_timer); 1049 del_timer_sync(&pmlmepriv->assoc_timer);
@@ -1161,7 +1138,7 @@ void rtw_stassoc_event_callback(struct adapter *adapter, u8 *pbuf)
1161 struct wlan_network *cur_network = &(pmlmepriv->cur_network); 1138 struct wlan_network *cur_network = &(pmlmepriv->cur_network);
1162 struct wlan_network *ptarget_wlan = NULL; 1139 struct wlan_network *ptarget_wlan = NULL;
1163 1140
1164 if (rtw_access_ctrl(adapter, pstassoc->macaddr) == false) 1141 if (!rtw_access_ctrl(adapter, pstassoc->macaddr))
1165 return; 1142 return;
1166 1143
1167#if defined(CONFIG_88EU_AP_MODE) 1144#if defined(CONFIG_88EU_AP_MODE)
@@ -1437,17 +1414,17 @@ static int rtw_check_join_candidate(struct mlme_priv *pmlmepriv
1437 /* check ssid, if needed */ 1414 /* check ssid, if needed */
1438 if (pmlmepriv->assoc_ssid.SsidLength) { 1415 if (pmlmepriv->assoc_ssid.SsidLength) {
1439 if (competitor->network.Ssid.SsidLength != pmlmepriv->assoc_ssid.SsidLength || 1416 if (competitor->network.Ssid.SsidLength != pmlmepriv->assoc_ssid.SsidLength ||
1440 !memcmp(competitor->network.Ssid.Ssid, pmlmepriv->assoc_ssid.Ssid, pmlmepriv->assoc_ssid.SsidLength) == false) 1417 memcmp(competitor->network.Ssid.Ssid, pmlmepriv->assoc_ssid.Ssid, pmlmepriv->assoc_ssid.SsidLength))
1441 goto exit; 1418 goto exit;
1442 } 1419 }
1443 1420
1444 if (rtw_is_desired_network(adapter, competitor) == false) 1421 if (!rtw_is_desired_network(adapter, competitor))
1445 goto exit; 1422 goto exit;
1446 1423
1447 if (pmlmepriv->to_roaming) { 1424 if (pmlmepriv->to_roaming) {
1448 since_scan = jiffies - competitor->last_scanned; 1425 since_scan = jiffies - competitor->last_scanned;
1449 if (jiffies_to_msecs(since_scan) >= RTW_SCAN_RESULT_EXPIRE || 1426 if (jiffies_to_msecs(since_scan) >= RTW_SCAN_RESULT_EXPIRE ||
1450 is_same_ess(&competitor->network, &pmlmepriv->cur_network.network) == false) 1427 !is_same_ess(&competitor->network, &pmlmepriv->cur_network.network))
1451 goto exit; 1428 goto exit;
1452 } 1429 }
1453 1430
@@ -1819,18 +1796,8 @@ void rtw_update_registrypriv_dev_network(struct adapter *adapter)
1819 case WIRELESS_11BG_24N: 1796 case WIRELESS_11BG_24N:
1820 pdev_network->NetworkTypeInUse = Ndis802_11OFDM24; 1797 pdev_network->NetworkTypeInUse = Ndis802_11OFDM24;
1821 break; 1798 break;
1822 case WIRELESS_11A:
1823 case WIRELESS_11A_5N:
1824 pdev_network->NetworkTypeInUse = Ndis802_11OFDM5;
1825 break;
1826 case WIRELESS_11ABGN:
1827 if (pregistrypriv->channel > 14)
1828 pdev_network->NetworkTypeInUse = Ndis802_11OFDM5;
1829 else
1830 pdev_network->NetworkTypeInUse = Ndis802_11OFDM24;
1831 break;
1832 default: 1799 default:
1833 /* TODO */ 1800 pdev_network->NetworkTypeInUse = Ndis802_11OFDM24;
1834 break; 1801 break;
1835 } 1802 }
1836 1803
diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
index 1115050077e4..6790b840aef8 100644
--- a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
+++ b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
@@ -39,7 +39,10 @@ extern unsigned char REALTEK_96B_IE[];
39/******************************************************** 39/********************************************************
40MCS rate definitions 40MCS rate definitions
41*********************************************************/ 41*********************************************************/
42unsigned char MCS_rate_1R[16] = {0xff, 0x00, 0x0, 0x0, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; 42const u8 MCS_rate_1R[16] = {
43 0xff, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
44 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
45};
43 46
44/******************************************************** 47/********************************************************
45ChannelPlan definitions 48ChannelPlan definitions
@@ -1513,7 +1516,7 @@ static int issue_deauth_ex(struct adapter *padapter, u8 *da,
1513 break; 1516 break;
1514 1517
1515 if (i < try_cnt && wait_ms > 0 && ret == _FAIL) 1518 if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
1516 msleep(wait_ms); 1519 mdelay(wait_ms);
1517 } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0))); 1520 } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0)));
1518 1521
1519 if (ret != _FAIL) { 1522 if (ret != _FAIL) {
@@ -2401,10 +2404,7 @@ static void process_80211d(struct adapter *padapter, struct wlan_bssid_ex *bssid
2401 p++; 2404 p++;
2402 2405
2403 for (j = 0; j < noc; j++) { 2406 for (j = 0; j < noc; j++) {
2404 if (fcn <= 14) 2407 channel = fcn + j;
2405 channel = fcn + j; /* 2.4 GHz */
2406 else
2407 channel = fcn + j*4; /* 5 GHz */
2408 2408
2409 chplan_ap.Channel[i++] = channel; 2409 chplan_ap.Channel[i++] = channel;
2410 } 2410 }
@@ -2481,14 +2481,6 @@ static void process_80211d(struct adapter *padapter, struct wlan_bssid_ex *bssid
2481 j++; 2481 j++;
2482 } 2482 }
2483 2483
2484 /* keep original STA 5G channel plan */
2485 while ((i < MAX_CHANNEL_NUM) && (chplan_sta[i].ChannelNum != 0)) {
2486 chplan_new[k].ChannelNum = chplan_sta[i].ChannelNum;
2487 chplan_new[k].ScanType = chplan_sta[i].ScanType;
2488 i++;
2489 k++;
2490 }
2491
2492 pmlmeext->update_channel_plan_by_ap_done = 1; 2484 pmlmeext->update_channel_plan_by_ap_done = 1;
2493 } 2485 }
2494 2486
@@ -2982,11 +2974,11 @@ static unsigned int OnAssocReq(struct adapter *padapter,
2982 /* checking SSID */ 2974 /* checking SSID */
2983 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, _SSID_IE_, &ie_len, 2975 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, _SSID_IE_, &ie_len,
2984 pkt_len - WLAN_HDR_A3_LEN - ie_offset); 2976 pkt_len - WLAN_HDR_A3_LEN - ie_offset);
2985 if (!p)
2986 status = _STATS_FAILURE_;
2987 2977
2988 if (ie_len == 0) { /* broadcast ssid, however it is not allowed in assocreq */ 2978 if (!p || ie_len == 0) {
2979 /* broadcast ssid, however it is not allowed in assocreq */
2989 status = _STATS_FAILURE_; 2980 status = _STATS_FAILURE_;
2981 goto OnAssocReqFail;
2990 } else { 2982 } else {
2991 /* check if ssid match */ 2983 /* check if ssid match */
2992 if (memcmp((void *)(p+2), cur->Ssid.Ssid, cur->Ssid.SsidLength)) 2984 if (memcmp((void *)(p+2), cur->Ssid.Ssid, cur->Ssid.SsidLength))
@@ -3844,24 +3836,20 @@ Following are the initialization functions for WiFi MLME
3844*****************************************************************************/ 3836*****************************************************************************/
3845 3837
3846static struct mlme_handler mlme_sta_tbl[] = { 3838static struct mlme_handler mlme_sta_tbl[] = {
3847 {WIFI_ASSOCREQ, "OnAssocReq", &OnAssocReq}, 3839 {WIFI_ASSOCREQ, "OnAssocReq", &OnAssocReq},
3848 {WIFI_ASSOCRSP, "OnAssocRsp", &OnAssocRsp}, 3840 {WIFI_ASSOCRSP, "OnAssocRsp", &OnAssocRsp},
3849 {WIFI_REASSOCREQ, "OnReAssocReq", &OnAssocReq}, 3841 {WIFI_REASSOCREQ, "OnReAssocReq", &OnAssocReq},
3850 {WIFI_REASSOCRSP, "OnReAssocRsp", &OnAssocRsp}, 3842 {WIFI_REASSOCRSP, "OnReAssocRsp", &OnAssocRsp},
3851 {WIFI_PROBEREQ, "OnProbeReq", &OnProbeReq}, 3843 {WIFI_PROBEREQ, "OnProbeReq", &OnProbeReq},
3852 {WIFI_PROBERSP, "OnProbeRsp", &OnProbeRsp}, 3844 {WIFI_PROBERSP, "OnProbeRsp", &OnProbeRsp},
3853 3845 {0, "DoReserved", &DoReserved},
3854 /*---------------------------------------------------------- 3846 {0, "DoReserved", &DoReserved},
3855 below 2 are reserved 3847 {WIFI_BEACON, "OnBeacon", &OnBeacon},
3856 -----------------------------------------------------------*/ 3848 {WIFI_ATIM, "OnATIM", &OnAtim},
3857 {0, "DoReserved", &DoReserved}, 3849 {WIFI_DISASSOC, "OnDisassoc", &OnDisassoc},
3858 {0, "DoReserved", &DoReserved}, 3850 {WIFI_AUTH, "OnAuth", &OnAuthClient},
3859 {WIFI_BEACON, "OnBeacon", &OnBeacon}, 3851 {WIFI_DEAUTH, "OnDeAuth", &OnDeAuth},
3860 {WIFI_ATIM, "OnATIM", &OnAtim}, 3852 {WIFI_ACTION, "OnAction", &OnAction},
3861 {WIFI_DISASSOC, "OnDisassoc", &OnDisassoc},
3862 {WIFI_AUTH, "OnAuth", &OnAuthClient},
3863 {WIFI_DEAUTH, "OnDeAuth", &OnDeAuth},
3864 {WIFI_ACTION, "OnAction", &OnAction},
3865}; 3853};
3866 3854
3867int init_hw_mlme_ext(struct adapter *padapter) 3855int init_hw_mlme_ext(struct adapter *padapter)
@@ -3969,7 +3957,7 @@ static void init_channel_list(struct adapter *padapter,
3969 if (!has_channel(channel_set, chanset_size, ch)) 3957 if (!has_channel(channel_set, chanset_size, ch))
3970 continue; 3958 continue;
3971 3959
3972 if ((0 == padapter->registrypriv.ht_enable) && (8 == o->inc)) 3960 if (!padapter->registrypriv.ht_enable && o->inc == 8)
3973 continue; 3961 continue;
3974 3962
3975 if ((0 == (padapter->registrypriv.cbw40_enable & BIT(1))) && 3963 if ((0 == (padapter->registrypriv.cbw40_enable & BIT(1))) &&
diff --git a/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c b/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c
index 5ab6fc22a156..9764e85c000c 100644
--- a/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c
+++ b/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c
@@ -292,7 +292,7 @@ void rtw_set_rpwm(struct adapter *padapter, u8 pslv)
292 pslv = PS_STATE_S3; 292 pslv = PS_STATE_S3;
293 } 293 }
294 294
295 if ((pwrpriv->rpwm == pslv)) { 295 if (pwrpriv->rpwm == pslv) {
296 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_err_, 296 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_err_,
297 ("%s: Already set rpwm[0x%02X], new=0x%02X!\n", __func__, pwrpriv->rpwm, pslv)); 297 ("%s: Already set rpwm[0x%02X], new=0x%02X!\n", __func__, pwrpriv->rpwm, pslv));
298 return; 298 return;
@@ -344,7 +344,7 @@ static u8 PS_RDY_CHECK(struct adapter *padapter)
344 if (delta_time < LPS_DELAY_TIME) 344 if (delta_time < LPS_DELAY_TIME)
345 return false; 345 return false;
346 346
347 if ((check_fwstate(pmlmepriv, _FW_LINKED) == false) || 347 if ((!check_fwstate(pmlmepriv, _FW_LINKED)) ||
348 (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY)) || 348 (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY)) ||
349 (check_fwstate(pmlmepriv, WIFI_AP_STATE)) || 349 (check_fwstate(pmlmepriv, WIFI_AP_STATE)) ||
350 (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) || 350 (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) ||
@@ -352,7 +352,8 @@ static u8 PS_RDY_CHECK(struct adapter *padapter)
352 return false; 352 return false;
353 if (pwrpriv->bInSuspend) 353 if (pwrpriv->bInSuspend)
354 return false; 354 return false;
355 if ((padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) && (padapter->securitypriv.binstallGrpkey == false)) { 355 if (padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X &&
356 !padapter->securitypriv.binstallGrpkey) {
356 DBG_88E("Group handshake still in progress !!!\n"); 357 DBG_88E("Group handshake still in progress !!!\n");
357 return false; 358 return false;
358 } 359 }
@@ -438,7 +439,7 @@ void LPS_Enter(struct adapter *padapter)
438{ 439{
439 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv; 440 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
440 441
441 if (PS_RDY_CHECK(padapter) == false) 442 if (!PS_RDY_CHECK(padapter))
442 return; 443 return;
443 444
444 if (pwrpriv->bLeisurePs) { 445 if (pwrpriv->bLeisurePs) {
diff --git a/drivers/staging/rtl8188eu/core/rtw_recv.c b/drivers/staging/rtl8188eu/core/rtw_recv.c
index 17b4b9257b49..dc447cc78c32 100644
--- a/drivers/staging/rtl8188eu/core/rtw_recv.c
+++ b/drivers/staging/rtl8188eu/core/rtw_recv.c
@@ -233,7 +233,7 @@ static int recvframe_chkmic(struct adapter *adapter,
233 233
234 /* calculate mic code */ 234 /* calculate mic code */
235 if (stainfo) { 235 if (stainfo) {
236 if (IS_MCAST(prxattrib->ra)) { 236 if (is_multicast_ether_addr(prxattrib->ra)) {
237 if (!psecuritypriv) { 237 if (!psecuritypriv) {
238 res = _FAIL; 238 res = _FAIL;
239 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, 239 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
@@ -321,11 +321,11 @@ static int recvframe_chkmic(struct adapter *adapter,
321 321
322 /* double check key_index for some timing issue , */ 322 /* double check key_index for some timing issue , */
323 /* cannot compare with psecuritypriv->dot118021XGrpKeyid also cause timing issue */ 323 /* cannot compare with psecuritypriv->dot118021XGrpKeyid also cause timing issue */
324 if ((IS_MCAST(prxattrib->ra) == true) && (prxattrib->key_index != pmlmeinfo->key_index)) 324 if (is_multicast_ether_addr(prxattrib->ra) && prxattrib->key_index != pmlmeinfo->key_index)
325 brpt_micerror = false; 325 brpt_micerror = false;
326 326
327 if ((prxattrib->bdecrypted) && (brpt_micerror)) { 327 if ((prxattrib->bdecrypted) && (brpt_micerror)) {
328 rtw_handle_tkip_mic_err(adapter, (u8)IS_MCAST(prxattrib->ra)); 328 rtw_handle_tkip_mic_err(adapter, (u8)is_multicast_ether_addr(prxattrib->ra));
329 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" mic error :prxattrib->bdecrypted=%d ", prxattrib->bdecrypted)); 329 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" mic error :prxattrib->bdecrypted=%d ", prxattrib->bdecrypted));
330 DBG_88E(" mic error :prxattrib->bdecrypted=%d\n", prxattrib->bdecrypted); 330 DBG_88E(" mic error :prxattrib->bdecrypted=%d\n", prxattrib->bdecrypted);
331 } else { 331 } else {
@@ -335,7 +335,7 @@ static int recvframe_chkmic(struct adapter *adapter,
335 res = _FAIL; 335 res = _FAIL;
336 } else { 336 } else {
337 /* mic checked ok */ 337 /* mic checked ok */
338 if ((!psecuritypriv->bcheck_grpkey) && (IS_MCAST(prxattrib->ra))) { 338 if (!psecuritypriv->bcheck_grpkey && is_multicast_ether_addr(prxattrib->ra)) {
339 psecuritypriv->bcheck_grpkey = true; 339 psecuritypriv->bcheck_grpkey = true;
340 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("psecuritypriv->bcheck_grpkey = true")); 340 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("psecuritypriv->bcheck_grpkey = true"));
341 } 341 }
@@ -488,7 +488,7 @@ static struct recv_frame *portctrl(struct adapter *adapter,
488 prtnframe = precv_frame; 488 prtnframe = precv_frame;
489 } 489 }
490 490
491 return prtnframe; 491 return prtnframe;
492} 492}
493 493
494static int recv_decache(struct recv_frame *precv_frame, u8 bretry, 494static int recv_decache(struct recv_frame *precv_frame, u8 bretry,
@@ -648,7 +648,7 @@ int sta2sta_data_frame(struct adapter *adapter, struct recv_frame *precv_frame,
648 u8 *mybssid = get_bssid(pmlmepriv); 648 u8 *mybssid = get_bssid(pmlmepriv);
649 u8 *myhwaddr = myid(&adapter->eeprompriv); 649 u8 *myhwaddr = myid(&adapter->eeprompriv);
650 u8 *sta_addr = NULL; 650 u8 *sta_addr = NULL;
651 int bmcast = IS_MCAST(pattrib->dst); 651 bool mcast = is_multicast_ether_addr(pattrib->dst);
652 652
653 if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true) || 653 if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true) ||
654 (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true)) { 654 (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true)) {
@@ -659,7 +659,7 @@ int sta2sta_data_frame(struct adapter *adapter, struct recv_frame *precv_frame,
659 goto exit; 659 goto exit;
660 } 660 }
661 661
662 if ((memcmp(myhwaddr, pattrib->dst, ETH_ALEN)) && (!bmcast)) { 662 if (memcmp(myhwaddr, pattrib->dst, ETH_ALEN) && !mcast) {
663 ret = _FAIL; 663 ret = _FAIL;
664 goto exit; 664 goto exit;
665 } 665 }
@@ -681,9 +681,9 @@ int sta2sta_data_frame(struct adapter *adapter, struct recv_frame *precv_frame,
681 } 681 }
682 sta_addr = pattrib->bssid; 682 sta_addr = pattrib->bssid;
683 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { 683 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
684 if (bmcast) { 684 if (mcast) {
685 /* For AP mode, if DA == MCAST, then BSSID should be also MCAST */ 685 /* For AP mode, if DA == MCAST, then BSSID should be also MCAST */
686 if (!IS_MCAST(pattrib->bssid)) { 686 if (!is_multicast_ether_addr(pattrib->bssid)) {
687 ret = _FAIL; 687 ret = _FAIL;
688 goto exit; 688 goto exit;
689 } 689 }
@@ -700,7 +700,7 @@ int sta2sta_data_frame(struct adapter *adapter, struct recv_frame *precv_frame,
700 ret = _FAIL; 700 ret = _FAIL;
701 } 701 }
702 702
703 if (bmcast) 703 if (mcast)
704 *psta = rtw_get_bcmc_stainfo(adapter); 704 *psta = rtw_get_bcmc_stainfo(adapter);
705 else 705 else
706 *psta = rtw_get_stainfo(pstapriv, sta_addr); /* get ap_info */ 706 *psta = rtw_get_stainfo(pstapriv, sta_addr); /* get ap_info */
@@ -727,7 +727,7 @@ static int ap2sta_data_frame(
727 struct mlme_priv *pmlmepriv = &adapter->mlmepriv; 727 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
728 u8 *mybssid = get_bssid(pmlmepriv); 728 u8 *mybssid = get_bssid(pmlmepriv);
729 u8 *myhwaddr = myid(&adapter->eeprompriv); 729 u8 *myhwaddr = myid(&adapter->eeprompriv);
730 int bmcast = IS_MCAST(pattrib->dst); 730 bool mcast = is_multicast_ether_addr(pattrib->dst);
731 731
732 if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true) && 732 if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true) &&
733 (check_fwstate(pmlmepriv, _FW_LINKED) == true || 733 (check_fwstate(pmlmepriv, _FW_LINKED) == true ||
@@ -740,7 +740,7 @@ static int ap2sta_data_frame(
740 } 740 }
741 741
742 /* da should be for me */ 742 /* da should be for me */
743 if ((memcmp(myhwaddr, pattrib->dst, ETH_ALEN)) && (!bmcast)) { 743 if (memcmp(myhwaddr, pattrib->dst, ETH_ALEN) && !mcast) {
744 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, 744 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
745 (" %s: compare DA fail; DA=%pM\n", __func__, (pattrib->dst))); 745 (" %s: compare DA fail; DA=%pM\n", __func__, (pattrib->dst)));
746 ret = _FAIL; 746 ret = _FAIL;
@@ -755,7 +755,7 @@ static int ap2sta_data_frame(
755 (" %s: compare BSSID fail ; BSSID=%pM\n", __func__, (pattrib->bssid))); 755 (" %s: compare BSSID fail ; BSSID=%pM\n", __func__, (pattrib->bssid)));
756 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("mybssid=%pM\n", (mybssid))); 756 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("mybssid=%pM\n", (mybssid)));
757 757
758 if (!bmcast) { 758 if (!mcast) {
759 DBG_88E("issue_deauth to the nonassociated ap=%pM for the reason(7)\n", (pattrib->bssid)); 759 DBG_88E("issue_deauth to the nonassociated ap=%pM for the reason(7)\n", (pattrib->bssid));
760 issue_deauth(adapter, pattrib->bssid, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA); 760 issue_deauth(adapter, pattrib->bssid, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
761 } 761 }
@@ -764,7 +764,7 @@ static int ap2sta_data_frame(
764 goto exit; 764 goto exit;
765 } 765 }
766 766
767 if (bmcast) 767 if (mcast)
768 *psta = rtw_get_bcmc_stainfo(adapter); 768 *psta = rtw_get_bcmc_stainfo(adapter);
769 else 769 else
770 *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get ap_info */ 770 *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get ap_info */
@@ -789,7 +789,7 @@ static int ap2sta_data_frame(
789 ret = RTW_RX_HANDLED; 789 ret = RTW_RX_HANDLED;
790 goto exit; 790 goto exit;
791 } else { 791 } else {
792 if (!memcmp(myhwaddr, pattrib->dst, ETH_ALEN) && (!bmcast)) { 792 if (!memcmp(myhwaddr, pattrib->dst, ETH_ALEN) && !mcast) {
793 *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get sta_info */ 793 *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get sta_info */
794 if (*psta == NULL) { 794 if (*psta == NULL) {
795 DBG_88E("issue_deauth to the ap =%pM for the reason(7)\n", (pattrib->bssid)); 795 DBG_88E("issue_deauth to the ap =%pM for the reason(7)\n", (pattrib->bssid));
@@ -1129,9 +1129,9 @@ static int validate_recv_data_frame(struct adapter *adapter,
1129 1129
1130 if (pattrib->privacy) { 1130 if (pattrib->privacy) {
1131 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("%s:pattrib->privacy=%x\n", __func__, pattrib->privacy)); 1131 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("%s:pattrib->privacy=%x\n", __func__, pattrib->privacy));
1132 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n ^^^^^^^^^^^IS_MCAST(pattrib->ra(0x%02x))=%d^^^^^^^^^^^^^^^6\n", pattrib->ra[0], IS_MCAST(pattrib->ra))); 1132 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n ^^^^^^^^^^^is_multicast_ether_addr(pattrib->ra(0x%02x))=%d^^^^^^^^^^^^^^^6\n", pattrib->ra[0], is_multicast_ether_addr(pattrib->ra)));
1133 1133
1134 GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, IS_MCAST(pattrib->ra)); 1134 GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, is_multicast_ether_addr(pattrib->ra));
1135 1135
1136 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n pattrib->encrypt=%d\n", pattrib->encrypt)); 1136 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n pattrib->encrypt=%d\n", pattrib->encrypt));
1137 1137
@@ -1283,8 +1283,8 @@ static int wlanhdr_to_ethhdr(struct recv_frame *precvframe)
1283 psnap_type = ptr+pattrib->hdrlen + pattrib->iv_len+SNAP_SIZE; 1283 psnap_type = ptr+pattrib->hdrlen + pattrib->iv_len+SNAP_SIZE;
1284 /* convert hdr + possible LLC headers into Ethernet header */ 1284 /* convert hdr + possible LLC headers into Ethernet header */
1285 if ((!memcmp(psnap, rtw_rfc1042_header, SNAP_SIZE) && 1285 if ((!memcmp(psnap, rtw_rfc1042_header, SNAP_SIZE) &&
1286 (!memcmp(psnap_type, SNAP_ETH_TYPE_IPX, 2) == false) && 1286 memcmp(psnap_type, SNAP_ETH_TYPE_IPX, 2) &&
1287 (!memcmp(psnap_type, SNAP_ETH_TYPE_APPLETALK_AARP, 2) == false)) || 1287 memcmp(psnap_type, SNAP_ETH_TYPE_APPLETALK_AARP, 2)) ||
1288 !memcmp(psnap, rtw_bridge_tunnel_header, SNAP_SIZE)) { 1288 !memcmp(psnap, rtw_bridge_tunnel_header, SNAP_SIZE)) {
1289 /* remove RFC1042 or Bridge-Tunnel encapsulation and replace EtherType */ 1289 /* remove RFC1042 or Bridge-Tunnel encapsulation and replace EtherType */
1290 bsnaphdr = true; 1290 bsnaphdr = true;
@@ -1971,7 +1971,8 @@ static int recv_func(struct adapter *padapter, struct recv_frame *rframe)
1971 if (ret == _SUCCESS) { 1971 if (ret == _SUCCESS) {
1972 /* check if need to enqueue into uc_swdec_pending_queue*/ 1972 /* check if need to enqueue into uc_swdec_pending_queue*/
1973 if (check_fwstate(mlmepriv, WIFI_STATION_STATE) && 1973 if (check_fwstate(mlmepriv, WIFI_STATION_STATE) &&
1974 !IS_MCAST(prxattrib->ra) && prxattrib->encrypt > 0 && 1974 !is_multicast_ether_addr(prxattrib->ra) &&
1975 prxattrib->encrypt > 0 &&
1975 prxattrib->bdecrypted == 0 && 1976 prxattrib->bdecrypted == 0 &&
1976 !is_wep_enc(psecuritypriv->dot11PrivacyAlgrthm) && 1977 !is_wep_enc(psecuritypriv->dot11PrivacyAlgrthm) &&
1977 !psecuritypriv->busetkipkey) { 1978 !psecuritypriv->busetkipkey) {
@@ -2041,7 +2042,7 @@ static void rtw_signal_stat_timer_hdl(struct timer_list *t)
2041 } 2042 }
2042 2043
2043 /* update value of signal_strength, rssi, signal_qual */ 2044 /* update value of signal_strength, rssi, signal_qual */
2044 if (check_fwstate(&adapter->mlmepriv, _FW_UNDER_SURVEY) == false) { 2045 if (!check_fwstate(&adapter->mlmepriv, _FW_UNDER_SURVEY)) {
2045 tmp_s = avg_signal_strength + 2046 tmp_s = avg_signal_strength +
2046 (_alpha - 1) * recvpriv->signal_strength; 2047 (_alpha - 1) * recvpriv->signal_strength;
2047 tmp_s = DIV_ROUND_UP(tmp_s, _alpha); 2048 tmp_s = DIV_ROUND_UP(tmp_s, _alpha);
diff --git a/drivers/staging/rtl8188eu/core/rtw_security.c b/drivers/staging/rtl8188eu/core/rtw_security.c
index 2a48b09ea9ae..f7407632e80b 100644
--- a/drivers/staging/rtl8188eu/core/rtw_security.c
+++ b/drivers/staging/rtl8188eu/core/rtw_security.c
@@ -353,7 +353,7 @@ void rtw_seccalctkipmic(u8 *key, u8 *header, u8 *data, u32 data_len, u8 *mic_cod
353 353
354 /* Michael MIC pseudo header: DA, SA, 3 x 0, Priority */ 354 /* Michael MIC pseudo header: DA, SA, 3 x 0, Priority */
355 if (header[1]&1) { /* ToDS == 1 */ 355 if (header[1]&1) { /* ToDS == 1 */
356 rtw_secmicappend(&micdata, &header[16], 6); /* DA */ 356 rtw_secmicappend(&micdata, &header[16], 6); /* DA */
357 if (header[1]&2) /* From Ds == 1 */ 357 if (header[1]&2) /* From Ds == 1 */
358 rtw_secmicappend(&micdata, &header[24], 6); 358 rtw_secmicappend(&micdata, &header[24], 6);
359 else 359 else
@@ -608,7 +608,7 @@ u32 rtw_tkip_encrypt(struct adapter *padapter, u8 *pxmitframe)
608 if (stainfo != NULL) { 608 if (stainfo != NULL) {
609 RT_TRACE(_module_rtl871x_security_c_, _drv_err_, ("%s: stainfo!= NULL!!!\n", __func__)); 609 RT_TRACE(_module_rtl871x_security_c_, _drv_err_, ("%s: stainfo!= NULL!!!\n", __func__));
610 610
611 if (IS_MCAST(pattrib->ra)) 611 if (is_multicast_ether_addr(pattrib->ra))
612 prwskey = psecuritypriv->dot118021XGrpKey[psecuritypriv->dot118021XGrpKeyid].skey; 612 prwskey = psecuritypriv->dot118021XGrpKey[psecuritypriv->dot118021XGrpKeyid].skey;
613 else 613 else
614 prwskey = &stainfo->dot118021x_UncstKey.skey[0]; 614 prwskey = &stainfo->dot118021x_UncstKey.skey[0];
@@ -678,7 +678,7 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe)
678 if (prxattrib->encrypt == _TKIP_) { 678 if (prxattrib->encrypt == _TKIP_) {
679 stainfo = rtw_get_stainfo(&padapter->stapriv, &prxattrib->ta[0]); 679 stainfo = rtw_get_stainfo(&padapter->stapriv, &prxattrib->ta[0]);
680 if (stainfo) { 680 if (stainfo) {
681 if (IS_MCAST(prxattrib->ra)) { 681 if (is_multicast_ether_addr(prxattrib->ra)) {
682 if (!psecuritypriv->binstallGrpkey) { 682 if (!psecuritypriv->binstallGrpkey) {
683 res = _FAIL; 683 res = _FAIL;
684 DBG_88E("%s:rx bc/mc packets, but didn't install group key!!!!!!!!!!\n", __func__); 684 DBG_88E("%s:rx bc/mc packets, but didn't install group key!!!!!!!!!!\n", __func__);
@@ -1250,7 +1250,7 @@ u32 rtw_aes_encrypt(struct adapter *padapter, u8 *pxmitframe)
1250 if (stainfo) { 1250 if (stainfo) {
1251 RT_TRACE(_module_rtl871x_security_c_, _drv_err_, ("%s: stainfo!= NULL!!!\n", __func__)); 1251 RT_TRACE(_module_rtl871x_security_c_, _drv_err_, ("%s: stainfo!= NULL!!!\n", __func__));
1252 1252
1253 if (IS_MCAST(pattrib->ra)) 1253 if (is_multicast_ether_addr(pattrib->ra))
1254 prwskey = psecuritypriv->dot118021XGrpKey[psecuritypriv->dot118021XGrpKeyid].skey; 1254 prwskey = psecuritypriv->dot118021XGrpKey[psecuritypriv->dot118021XGrpKeyid].skey;
1255 else 1255 else
1256 prwskey = &stainfo->dot118021x_UncstKey.skey[0]; 1256 prwskey = &stainfo->dot118021x_UncstKey.skey[0];
@@ -1273,8 +1273,7 @@ u32 rtw_aes_encrypt(struct adapter *padapter, u8 *pxmitframe)
1273 } 1273 }
1274 } 1274 }
1275 1275
1276 1276 return res;
1277 return res;
1278} 1277}
1279 1278
1280u32 rtw_aes_decrypt(struct adapter *padapter, u8 *precvframe) 1279u32 rtw_aes_decrypt(struct adapter *padapter, u8 *precvframe)
@@ -1296,7 +1295,7 @@ u32 rtw_aes_decrypt(struct adapter *padapter, u8 *precvframe)
1296 struct security_priv *psecuritypriv = &padapter->securitypriv; 1295 struct security_priv *psecuritypriv = &padapter->securitypriv;
1297 char iv[8], icv[8]; 1296 char iv[8], icv[8];
1298 1297
1299 if (IS_MCAST(prxattrib->ra)) { 1298 if (is_multicast_ether_addr(prxattrib->ra)) {
1300 /* in concurrent we should use sw descrypt in group key, so we remove this message */ 1299 /* in concurrent we should use sw descrypt in group key, so we remove this message */
1301 if (!psecuritypriv->binstallGrpkey) { 1300 if (!psecuritypriv->binstallGrpkey) {
1302 res = _FAIL; 1301 res = _FAIL;
diff --git a/drivers/staging/rtl8188eu/core/rtw_wlan_util.c b/drivers/staging/rtl8188eu/core/rtw_wlan_util.c
index b9406583e501..3e05e2c7f61b 100644
--- a/drivers/staging/rtl8188eu/core/rtw_wlan_util.c
+++ b/drivers/staging/rtl8188eu/core/rtw_wlan_util.c
@@ -107,26 +107,20 @@ unsigned char networktype_to_raid(unsigned char network_type)
107u8 judge_network_type(struct adapter *padapter, unsigned char *rate, int ratelen) 107u8 judge_network_type(struct adapter *padapter, unsigned char *rate, int ratelen)
108{ 108{
109 u8 network_type = 0; 109 u8 network_type = 0;
110 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 110 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
111 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); 111 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
112 112
113 if (pmlmeext->cur_channel > 14) { 113 if (pmlmeinfo->HT_enable)
114 if (pmlmeinfo->HT_enable) 114 network_type = WIRELESS_11_24N;
115 network_type = WIRELESS_11_5N;
116 115
117 network_type |= WIRELESS_11A; 116 if (cckratesonly_included(rate, ratelen))
118 } else { 117 network_type |= WIRELESS_11B;
119 if (pmlmeinfo->HT_enable) 118 else if (cckrates_included(rate, ratelen))
120 network_type = WIRELESS_11_24N; 119 network_type |= WIRELESS_11BG;
121 120 else
122 if ((cckratesonly_included(rate, ratelen)) == true) 121 network_type |= WIRELESS_11G;
123 network_type |= WIRELESS_11B; 122
124 else if ((cckrates_included(rate, ratelen)) == true) 123 return network_type;
125 network_type |= WIRELESS_11BG;
126 else
127 network_type |= WIRELESS_11G;
128 }
129 return network_type;
130} 124}
131 125
132static unsigned char ratetbl_val_2wifirate(unsigned char rate) 126static unsigned char ratetbl_val_2wifirate(unsigned char rate)
@@ -460,9 +454,9 @@ void write_cam(struct adapter *padapter, u8 entry, u16 ctrl, u8 *mac, u8 *key)
460 454
461void clear_cam_entry(struct adapter *padapter, u8 entry) 455void clear_cam_entry(struct adapter *padapter, u8 entry)
462{ 456{
463 unsigned char null_sta[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 457 u8 null_sta[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
464 unsigned char null_key[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 458 u8 null_key[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
465 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 459 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
466 460
467 write_cam(padapter, entry, 0, null_sta, null_key); 461 write_cam(padapter, entry, 0, null_sta, null_key);
468} 462}
@@ -852,7 +846,7 @@ int rtw_check_bcn_info(struct adapter *Adapter, u8 *pframe, u32 packet_len)
852 unsigned char ht_info_infos_0; 846 unsigned char ht_info_infos_0;
853 int ssid_len; 847 int ssid_len;
854 848
855 if (is_client_associated_to_ap(Adapter) == false) 849 if (!is_client_associated_to_ap(Adapter))
856 return true; 850 return true;
857 851
858 len = packet_len - sizeof(struct ieee80211_hdr_3addr); 852 len = packet_len - sizeof(struct ieee80211_hdr_3addr);
@@ -862,7 +856,7 @@ int rtw_check_bcn_info(struct adapter *Adapter, u8 *pframe, u32 packet_len)
862 return _FAIL; 856 return _FAIL;
863 } 857 }
864 858
865 if (!memcmp(cur_network->network.MacAddress, pbssid, 6) == false) { 859 if (memcmp(cur_network->network.MacAddress, pbssid, 6)) {
866 DBG_88E("Oops: rtw_check_network_encrypt linked but recv other bssid bcn\n%pM %pM\n", 860 DBG_88E("Oops: rtw_check_network_encrypt linked but recv other bssid bcn\n%pM %pM\n",
867 (pbssid), (cur_network->network.MacAddress)); 861 (pbssid), (cur_network->network.MacAddress));
868 return true; 862 return true;
@@ -1419,32 +1413,25 @@ void update_wireless_mode(struct adapter *padapter)
1419{ 1413{
1420 int ratelen, network_type = 0; 1414 int ratelen, network_type = 0;
1421 u32 SIFS_Timer; 1415 u32 SIFS_Timer;
1422 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 1416 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1423 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); 1417 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1424 struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network); 1418 struct wlan_bssid_ex *cur_network = &pmlmeinfo->network;
1425 unsigned char *rate = cur_network->SupportedRates; 1419 unsigned char *rate = cur_network->SupportedRates;
1426 1420
1427 ratelen = rtw_get_rateset_len(cur_network->SupportedRates); 1421 ratelen = rtw_get_rateset_len(cur_network->SupportedRates);
1428 1422
1429 if ((pmlmeinfo->HT_info_enable) && (pmlmeinfo->HT_caps_enable)) 1423 if (pmlmeinfo->HT_info_enable && pmlmeinfo->HT_caps_enable)
1430 pmlmeinfo->HT_enable = 1; 1424 pmlmeinfo->HT_enable = 1;
1431 1425
1432 if (pmlmeext->cur_channel > 14) { 1426 if (pmlmeinfo->HT_enable)
1433 if (pmlmeinfo->HT_enable) 1427 network_type = WIRELESS_11_24N;
1434 network_type = WIRELESS_11_5N;
1435 1428
1436 network_type |= WIRELESS_11A; 1429 if (cckratesonly_included(rate, ratelen))
1437 } else { 1430 network_type |= WIRELESS_11B;
1438 if (pmlmeinfo->HT_enable) 1431 else if (cckrates_included(rate, ratelen))
1439 network_type = WIRELESS_11_24N; 1432 network_type |= WIRELESS_11BG;
1440 1433 else
1441 if ((cckratesonly_included(rate, ratelen)) == true) 1434 network_type |= WIRELESS_11G;
1442 network_type |= WIRELESS_11B;
1443 else if ((cckrates_included(rate, ratelen)) == true)
1444 network_type |= WIRELESS_11BG;
1445 else
1446 network_type |= WIRELESS_11G;
1447 }
1448 1435
1449 pmlmeext->cur_wireless_mode = network_type & padapter->registrypriv.wireless_mode; 1436 pmlmeext->cur_wireless_mode = network_type & padapter->registrypriv.wireless_mode;
1450 1437
diff --git a/drivers/staging/rtl8188eu/core/rtw_xmit.c b/drivers/staging/rtl8188eu/core/rtw_xmit.c
index 2130d78e0d9f..0a3e710590ed 100644
--- a/drivers/staging/rtl8188eu/core/rtw_xmit.c
+++ b/drivers/staging/rtl8188eu/core/rtw_xmit.c
@@ -77,8 +77,6 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)
77 goto exit; 77 goto exit;
78 } 78 }
79 pxmitpriv->pxmit_frame_buf = PTR_ALIGN(pxmitpriv->pallocated_frame_buf, 4); 79 pxmitpriv->pxmit_frame_buf = PTR_ALIGN(pxmitpriv->pallocated_frame_buf, 4);
80 /* pxmitpriv->pxmit_frame_buf = pxmitpriv->pallocated_frame_buf + 4 - */
81 /* ((size_t) (pxmitpriv->pallocated_frame_buf) &3); */
82 80
83 pxframe = (struct xmit_frame *)pxmitpriv->pxmit_frame_buf; 81 pxframe = (struct xmit_frame *)pxmitpriv->pxmit_frame_buf;
84 82
@@ -115,8 +113,6 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)
115 } 113 }
116 114
117 pxmitpriv->pxmitbuf = PTR_ALIGN(pxmitpriv->pallocated_xmitbuf, 4); 115 pxmitpriv->pxmitbuf = PTR_ALIGN(pxmitpriv->pallocated_xmitbuf, 4);
118 /* pxmitpriv->pxmitbuf = pxmitpriv->pallocated_xmitbuf + 4 - */
119 /* ((size_t) (pxmitpriv->pallocated_xmitbuf) &3); */
120 116
121 pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmitbuf; 117 pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmitbuf;
122 118
@@ -254,10 +250,12 @@ static void update_attrib_vcs_info(struct adapter *padapter, struct xmit_frame *
254 else /* no frag */ 250 else /* no frag */
255 sz = pattrib->last_txcmdsz; 251 sz = pattrib->last_txcmdsz;
256 252
257 /* (1) RTS_Threshold is compared to the MPDU, not MSDU. */ 253 /* (1) RTS_Threshold is compared to the MPDU, not MSDU.
258 /* (2) If there are more than one frag in this MSDU, only the first frag uses protection frame. */ 254 * (2) If there are more than one frag in this MSDU,
259 /* Other fragments are protected by previous fragment. */ 255 * only the first frag uses protection frame.
260 /* So we only need to check the length of first fragment. */ 256 * Other fragments are protected by previous fragment.
257 * So we only need to check the length of first fragment.
258 */
261 if (pmlmeext->cur_wireless_mode < WIRELESS_11_24N || padapter->registrypriv.wifi_spec) { 259 if (pmlmeext->cur_wireless_mode < WIRELESS_11_24N || padapter->registrypriv.wifi_spec) {
262 if (sz > padapter->registrypriv.rts_thresh) { 260 if (sz > padapter->registrypriv.rts_thresh) {
263 pattrib->vcs_mode = RTS_CTS; 261 pattrib->vcs_mode = RTS_CTS;
@@ -321,13 +319,6 @@ static void update_attrib_vcs_info(struct adapter *padapter, struct xmit_frame *
321 319
322static void update_attrib_phy_info(struct pkt_attrib *pattrib, struct sta_info *psta) 320static void update_attrib_phy_info(struct pkt_attrib *pattrib, struct sta_info *psta)
323{ 321{
324 /*if (psta->rtsen)
325 pattrib->vcs_mode = RTS_CTS;
326 else if (psta->cts2self)
327 pattrib->vcs_mode = CTS_TO_SELF;
328 else
329 pattrib->vcs_mode = NONE_VCS;*/
330
331 pattrib->mdata = 0; 322 pattrib->mdata = 0;
332 pattrib->eosp = 0; 323 pattrib->eosp = 0;
333 pattrib->triggered = 0; 324 pattrib->triggered = 0;
@@ -344,9 +335,9 @@ static void update_attrib_phy_info(struct pkt_attrib *pattrib, struct sta_info *
344 pattrib->retry_ctrl = false; 335 pattrib->retry_ctrl = false;
345} 336}
346 337
347u8 qos_acm(u8 acm_mask, u8 priority) 338u8 qos_acm(u8 acm_mask, u8 priority)
348{ 339{
349 u8 change_priority = priority; 340 u8 change_priority = priority;
350 341
351 switch (priority) { 342 switch (priority) {
352 case 0: 343 case 0:
@@ -368,7 +359,8 @@ u8 qos_acm(u8 acm_mask, u8 priority)
368 change_priority = 5; 359 change_priority = 5;
369 break; 360 break;
370 default: 361 default:
371 DBG_88E("qos_acm(): invalid pattrib->priority: %d!!!\n", priority); 362 DBG_88E("%s(): invalid pattrib->priority: %d!!!\n",
363 __func__, priority);
372 break; 364 break;
373 } 365 }
374 366
@@ -383,8 +375,10 @@ static void set_qos(struct sk_buff *skb, struct pkt_attrib *pattrib)
383 skb_copy_bits(skb, ETH_HLEN, &ip_hdr, sizeof(ip_hdr)); 375 skb_copy_bits(skb, ETH_HLEN, &ip_hdr, sizeof(ip_hdr));
384 pattrib->priority = ip_hdr.tos >> 5; 376 pattrib->priority = ip_hdr.tos >> 5;
385 } else if (pattrib->ether_type == ETH_P_PAE) { 377 } else if (pattrib->ether_type == ETH_P_PAE) {
386 /* "When priority processing of data frames is supported, */ 378 /* When priority processing of data frames is supported,
387 /* a STA's SME should send EAPOL-Key frames at the highest priority." */ 379 * a STA's SME should send EAPOL-Key frames at the highest
380 * priority.
381 */
388 pattrib->priority = 7; 382 pattrib->priority = 7;
389 } else { 383 } else {
390 pattrib->priority = 0; 384 pattrib->priority = 0;
@@ -399,7 +393,7 @@ static s32 update_attrib(struct adapter *padapter, struct sk_buff *pkt, struct p
399 struct sta_info *psta = NULL; 393 struct sta_info *psta = NULL;
400 struct ethhdr etherhdr; 394 struct ethhdr etherhdr;
401 395
402 int bmcast; 396 bool mcast;
403 struct sta_priv *pstapriv = &padapter->stapriv; 397 struct sta_priv *pstapriv = &padapter->stapriv;
404 struct security_priv *psecuritypriv = &padapter->securitypriv; 398 struct security_priv *psecuritypriv = &padapter->securitypriv;
405 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 399 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
@@ -430,8 +424,10 @@ static s32 update_attrib(struct adapter *padapter, struct sk_buff *pkt, struct p
430 pattrib->pktlen = pkt->len - ETH_HLEN; 424 pattrib->pktlen = pkt->len - ETH_HLEN;
431 425
432 if (pattrib->ether_type == ETH_P_IP) { 426 if (pattrib->ether_type == ETH_P_IP) {
433 /* The following is for DHCP and ARP packet, we use cck1M to tx these packets and let LPS awake some time */ 427 /* The following is for DHCP and ARP packet, we use
434 /* to prevent DHCP protocol fail */ 428 * cck1M to tx these packets and let LPS awake some
429 * time to prevent DHCP protocol fail.
430 */
435 u8 tmp[24]; 431 u8 tmp[24];
436 432
437 skb_copy_bits(pkt, ETH_HLEN, tmp, 24); 433 skb_copy_bits(pkt, ETH_HLEN, tmp, 24);
@@ -460,10 +456,10 @@ static s32 update_attrib(struct adapter *padapter, struct sk_buff *pkt, struct p
460 if ((pattrib->ether_type == ETH_P_ARP) || (pattrib->ether_type == ETH_P_PAE) || (pattrib->dhcp_pkt == 1)) 456 if ((pattrib->ether_type == ETH_P_ARP) || (pattrib->ether_type == ETH_P_PAE) || (pattrib->dhcp_pkt == 1))
461 rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_SPECIAL_PACKET, 1); 457 rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_SPECIAL_PACKET, 1);
462 458
463 bmcast = IS_MCAST(pattrib->ra); 459 mcast = is_multicast_ether_addr(pattrib->ra);
464 460
465 /* get sta_info */ 461 /* get sta_info */
466 if (bmcast) { 462 if (mcast) {
467 psta = rtw_get_bcmc_stainfo(padapter); 463 psta = rtw_get_bcmc_stainfo(padapter);
468 } else { 464 } else {
469 psta = rtw_get_stainfo(pstapriv, pattrib->ra); 465 psta = rtw_get_stainfo(pstapriv, pattrib->ra);
@@ -494,7 +490,8 @@ static s32 update_attrib(struct adapter *padapter, struct sk_buff *pkt, struct p
494 pattrib->subtype = WIFI_DATA_TYPE; 490 pattrib->subtype = WIFI_DATA_TYPE;
495 pattrib->priority = 0; 491 pattrib->priority = 0;
496 492
497 if (check_fwstate(pmlmepriv, WIFI_AP_STATE|WIFI_ADHOC_STATE|WIFI_ADHOC_MASTER_STATE)) { 493 if (check_fwstate(pmlmepriv, WIFI_AP_STATE |
494 WIFI_ADHOC_STATE | WIFI_ADHOC_MASTER_STATE)) {
498 if (psta->qos_option) 495 if (psta->qos_option)
499 set_qos(pkt, pattrib); 496 set_qos(pkt, pattrib);
500 } else { 497 } else {
@@ -517,7 +514,7 @@ static s32 update_attrib(struct adapter *padapter, struct sk_buff *pkt, struct p
517 goto exit; 514 goto exit;
518 } 515 }
519 } else { 516 } else {
520 GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, bmcast); 517 GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, mcast);
521 518
522 switch (psecuritypriv->dot11AuthAlgrthm) { 519 switch (psecuritypriv->dot11AuthAlgrthm) {
523 case dot11AuthAlgrthm_Open: 520 case dot11AuthAlgrthm_Open:
@@ -526,7 +523,7 @@ static s32 update_attrib(struct adapter *padapter, struct sk_buff *pkt, struct p
526 pattrib->key_idx = (u8)psecuritypriv->dot11PrivacyKeyIndex; 523 pattrib->key_idx = (u8)psecuritypriv->dot11PrivacyKeyIndex;
527 break; 524 break;
528 case dot11AuthAlgrthm_8021X: 525 case dot11AuthAlgrthm_8021X:
529 if (bmcast) 526 if (mcast)
530 pattrib->key_idx = (u8)psecuritypriv->dot118021XGrpKeyid; 527 pattrib->key_idx = (u8)psecuritypriv->dot118021XGrpKeyid;
531 else 528 else
532 pattrib->key_idx = 0; 529 pattrib->key_idx = 0;
@@ -596,7 +593,6 @@ static s32 xmitframe_addmic(struct adapter *padapter, struct xmit_frame *pxmitfr
596 struct xmit_priv *pxmitpriv = &padapter->xmitpriv; 593 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
597 u8 priority[4] = {0x0, 0x0, 0x0, 0x0}; 594 u8 priority[4] = {0x0, 0x0, 0x0, 0x0};
598 u8 hw_hdr_offset = 0; 595 u8 hw_hdr_offset = 0;
599 int bmcst = IS_MCAST(pattrib->ra);
600 596
601 if (pattrib->psta) 597 if (pattrib->psta)
602 stainfo = pattrib->psta; 598 stainfo = pattrib->psta;
@@ -605,7 +601,7 @@ static s32 xmitframe_addmic(struct adapter *padapter, struct xmit_frame *pxmitfr
605 601
606 hw_hdr_offset = TXDESC_SIZE + (pxmitframe->pkt_offset * PACKET_OFFSET_SZ); 602 hw_hdr_offset = TXDESC_SIZE + (pxmitframe->pkt_offset * PACKET_OFFSET_SZ);
607 603
608 if (pattrib->encrypt == _TKIP_) {/* if (psecuritypriv->dot11PrivacyAlgrthm == _TKIP_PRIVACY_) */ 604 if (pattrib->encrypt == _TKIP_) {
609 /* encode mic code */ 605 /* encode mic code */
610 if (stainfo) { 606 if (stainfo) {
611 u8 null_key[16] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 607 u8 null_key[16] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
@@ -614,30 +610,27 @@ static s32 xmitframe_addmic(struct adapter *padapter, struct xmit_frame *pxmitfr
614 610
615 pframe = pxmitframe->buf_addr + hw_hdr_offset; 611 pframe = pxmitframe->buf_addr + hw_hdr_offset;
616 612
617 if (bmcst) { 613 if (is_multicast_ether_addr(pattrib->ra)) {
618 if (!memcmp(psecuritypriv->dot118021XGrptxmickey[psecuritypriv->dot118021XGrpKeyid].skey, null_key, 16)) 614 if (!memcmp(psecuritypriv->dot118021XGrptxmickey[psecuritypriv->dot118021XGrpKeyid].skey, null_key, 16))
619 return _FAIL; 615 return _FAIL;
620 /* start to calculate the mic code */ 616 /* start to calculate the mic code */
621 rtw_secmicsetkey(&micdata, psecuritypriv->dot118021XGrptxmickey[psecuritypriv->dot118021XGrpKeyid].skey); 617 rtw_secmicsetkey(&micdata, psecuritypriv->dot118021XGrptxmickey[psecuritypriv->dot118021XGrpKeyid].skey);
622 } else { 618 } else {
623 if (!memcmp(&stainfo->dot11tkiptxmickey.skey[0], null_key, 16)) { 619 if (!memcmp(&stainfo->dot11tkiptxmickey.skey[0], null_key, 16))
624 /* DbgPrint("\nxmitframe_addmic:stainfo->dot11tkiptxmickey == 0\n"); */
625 /* msleep(10); */
626 return _FAIL; 620 return _FAIL;
627 }
628 /* start to calculate the mic code */ 621 /* start to calculate the mic code */
629 rtw_secmicsetkey(&micdata, &stainfo->dot11tkiptxmickey.skey[0]); 622 rtw_secmicsetkey(&micdata, &stainfo->dot11tkiptxmickey.skey[0]);
630 } 623 }
631 624
632 if (pframe[1]&1) { /* ToDS == 1 */ 625 if (pframe[1] & 1) { /* ToDS == 1 */
633 rtw_secmicappend(&micdata, &pframe[16], 6); /* DA */ 626 rtw_secmicappend(&micdata, &pframe[16], 6); /* DA */
634 if (pframe[1]&2) /* From Ds == 1 */ 627 if (pframe[1] & 2) /* From Ds == 1 */
635 rtw_secmicappend(&micdata, &pframe[24], 6); 628 rtw_secmicappend(&micdata, &pframe[24], 6);
636 else 629 else
637 rtw_secmicappend(&micdata, &pframe[10], 6); 630 rtw_secmicappend(&micdata, &pframe[10], 6);
638 } else { /* ToDS == 0 */ 631 } else { /* ToDS == 0 */
639 rtw_secmicappend(&micdata, &pframe[4], 6); /* DA */ 632 rtw_secmicappend(&micdata, &pframe[4], 6); /* DA */
640 if (pframe[1]&2) /* From Ds == 1 */ 633 if (pframe[1] & 2) /* From Ds == 1 */
641 rtw_secmicappend(&micdata, &pframe[16], 6); 634 rtw_secmicappend(&micdata, &pframe[16], 6);
642 else 635 else
643 rtw_secmicappend(&micdata, &pframe[10], 6); 636 rtw_secmicappend(&micdata, &pframe[10], 6);
@@ -654,23 +647,31 @@ static s32 xmitframe_addmic(struct adapter *padapter, struct xmit_frame *pxmitfr
654 payload = (u8 *)round_up((size_t)(payload), 4); 647 payload = (u8 *)round_up((size_t)(payload), 4);
655 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, 648 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
656 ("=== curfragnum=%d, pframe = 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x,!!!\n", 649 ("=== curfragnum=%d, pframe = 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x,!!!\n",
657 curfragnum, *payload, *(payload+1), 650 curfragnum, *payload, *(payload + 1),
658 *(payload+2), *(payload+3), 651 *(payload + 2), *(payload + 3),
659 *(payload+4), *(payload+5), 652 *(payload + 4), *(payload + 5),
660 *(payload+6), *(payload+7))); 653 *(payload + 6), *(payload + 7)));
661 654
662 payload = payload+pattrib->hdrlen+pattrib->iv_len; 655 payload += pattrib->hdrlen + pattrib->iv_len;
663 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, 656 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
664 ("curfragnum=%d pattrib->hdrlen=%d pattrib->iv_len=%d", 657 ("curfragnum=%d pattrib->hdrlen=%d pattrib->iv_len=%d",
665 curfragnum, pattrib->hdrlen, pattrib->iv_len)); 658 curfragnum, pattrib->hdrlen, pattrib->iv_len));
666 if ((curfragnum+1) == pattrib->nr_frags) { 659 if (curfragnum + 1 == pattrib->nr_frags) {
667 length = pattrib->last_txcmdsz-pattrib->hdrlen-pattrib->iv_len-((pattrib->bswenc) ? pattrib->icv_len : 0); 660 length = pattrib->last_txcmdsz -
661 pattrib->hdrlen -
662 pattrib->iv_len -
663 ((pattrib->bswenc) ?
664 pattrib->icv_len : 0);
668 rtw_secmicappend(&micdata, payload, length); 665 rtw_secmicappend(&micdata, payload, length);
669 payload = payload+length; 666 payload += length;
670 } else { 667 } else {
671 length = pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-((pattrib->bswenc) ? pattrib->icv_len : 0); 668 length = pxmitpriv->frag_len -
669 pattrib->hdrlen -
670 pattrib->iv_len -
671 ((pattrib->bswenc) ?
672 pattrib->icv_len : 0);
672 rtw_secmicappend(&micdata, payload, length); 673 rtw_secmicappend(&micdata, payload, length);
673 payload = payload+length+pattrib->icv_len; 674 payload += length + pattrib->icv_len;
674 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("curfragnum=%d length=%d pattrib->icv_len=%d", curfragnum, length, pattrib->icv_len)); 675 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("curfragnum=%d length=%d pattrib->icv_len=%d", curfragnum, length, pattrib->icv_len));
675 } 676 }
676 } 677 }
@@ -686,8 +687,8 @@ static s32 xmitframe_addmic(struct adapter *padapter, struct xmit_frame *pxmitfr
686 pattrib->last_txcmdsz += 8; 687 pattrib->last_txcmdsz += 8;
687 688
688 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("\n ======== last pkt ========\n")); 689 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("\n ======== last pkt ========\n"));
689 payload = payload-pattrib->last_txcmdsz+8; 690 payload -= pattrib->last_txcmdsz + 8;
690 for (curfragnum = 0; curfragnum < pattrib->last_txcmdsz; curfragnum = curfragnum+8) 691 for (curfragnum = 0; curfragnum < pattrib->last_txcmdsz; curfragnum += 8)
691 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, 692 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
692 (" %.2x, %.2x, %.2x, %.2x, %.2x, %.2x, %.2x, %.2x ", 693 (" %.2x, %.2x, %.2x, %.2x, %.2x, %.2x, %.2x, %.2x ",
693 *(payload + curfragnum), *(payload + curfragnum + 1), 694 *(payload + curfragnum), *(payload + curfragnum + 1),
@@ -743,12 +744,10 @@ s32 rtw_make_wlanhdr(struct adapter *padapter, u8 *hdr, struct pkt_attrib *pattr
743 744
744 struct sta_info *psta; 745 struct sta_info *psta;
745 746
746 int bmcst = IS_MCAST(pattrib->ra);
747
748 if (pattrib->psta) { 747 if (pattrib->psta) {
749 psta = pattrib->psta; 748 psta = pattrib->psta;
750 } else { 749 } else {
751 if (bmcst) 750 if (is_multicast_ether_addr(pattrib->ra))
752 psta = rtw_get_bcmc_stainfo(padapter); 751 psta = rtw_get_bcmc_stainfo(padapter);
753 else 752 else
754 psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra); 753 psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra);
@@ -836,11 +835,11 @@ s32 rtw_make_wlanhdr(struct adapter *padapter, u8 *hdr, struct pkt_attrib *pattr
836 if (SN_LESS(pattrib->seqnum, tx_seq)) { 835 if (SN_LESS(pattrib->seqnum, tx_seq)) {
837 pattrib->ampdu_en = false;/* AGG BK */ 836 pattrib->ampdu_en = false;/* AGG BK */
838 } else if (SN_EQUAL(pattrib->seqnum, tx_seq)) { 837 } else if (SN_EQUAL(pattrib->seqnum, tx_seq)) {
839 psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq+1)&0xfff; 838 psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq + 1) & 0xfff;
840 839
841 pattrib->ampdu_en = true;/* AGG EN */ 840 pattrib->ampdu_en = true;/* AGG EN */
842 } else { 841 } else {
843 psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum+1)&0xfff; 842 psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum + 1) & 0xfff;
844 pattrib->ampdu_en = true;/* AGG EN */ 843 pattrib->ampdu_en = true;/* AGG EN */
845 } 844 }
846 } 845 }
@@ -856,9 +855,9 @@ s32 rtw_txframes_pending(struct adapter *padapter)
856 struct xmit_priv *pxmitpriv = &padapter->xmitpriv; 855 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
857 856
858 return (!list_empty(&pxmitpriv->be_pending.queue) || 857 return (!list_empty(&pxmitpriv->be_pending.queue) ||
859 !list_empty(&pxmitpriv->bk_pending.queue) || 858 !list_empty(&pxmitpriv->bk_pending.queue) ||
860 !list_empty(&pxmitpriv->vi_pending.queue) || 859 !list_empty(&pxmitpriv->vi_pending.queue) ||
861 !list_empty(&pxmitpriv->vo_pending.queue)); 860 !list_empty(&pxmitpriv->vo_pending.queue));
862} 861}
863 862
864s32 rtw_txframes_sta_ac_pending(struct adapter *padapter, struct pkt_attrib *pattrib) 863s32 rtw_txframes_sta_ac_pending(struct adapter *padapter, struct pkt_attrib *pattrib)
@@ -914,7 +913,7 @@ s32 rtw_xmitframe_coalesce(struct adapter *padapter, struct sk_buff *pkt, struct
914 struct xmit_priv *pxmitpriv = &padapter->xmitpriv; 913 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
915 struct pkt_attrib *pattrib = &pxmitframe->attrib; 914 struct pkt_attrib *pattrib = &pxmitframe->attrib;
916 u8 *pbuf_start; 915 u8 *pbuf_start;
917 s32 bmcst = IS_MCAST(pattrib->ra); 916 bool mcast = is_multicast_ether_addr(pattrib->ra);
918 s32 res = _SUCCESS; 917 s32 res = _SUCCESS;
919 size_t remainder = pkt->len - ETH_HLEN; 918 size_t remainder = pkt->len - ETH_HLEN;
920 919
@@ -964,13 +963,13 @@ s32 rtw_xmitframe_coalesce(struct adapter *padapter, struct sk_buff *pkt, struct
964 WEP_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx); 963 WEP_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx);
965 break; 964 break;
966 case _TKIP_: 965 case _TKIP_:
967 if (bmcst) 966 if (mcast)
968 TKIP_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx); 967 TKIP_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx);
969 else 968 else
970 TKIP_IV(pattrib->iv, psta->dot11txpn, 0); 969 TKIP_IV(pattrib->iv, psta->dot11txpn, 0);
971 break; 970 break;
972 case _AES_: 971 case _AES_:
973 if (bmcst) 972 if (mcast)
974 AES_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx); 973 AES_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx);
975 else 974 else
976 AES_IV(pattrib->iv, psta->dot11txpn, 0); 975 AES_IV(pattrib->iv, psta->dot11txpn, 0);
@@ -981,7 +980,10 @@ s32 rtw_xmitframe_coalesce(struct adapter *padapter, struct sk_buff *pkt, struct
981 980
982 RT_TRACE(_module_rtl871x_xmit_c_, _drv_notice_, 981 RT_TRACE(_module_rtl871x_xmit_c_, _drv_notice_,
983 ("%s: keyid=%d pattrib->iv[3]=%.2x pframe=%.2x %.2x %.2x %.2x\n", 982 ("%s: keyid=%d pattrib->iv[3]=%.2x pframe=%.2x %.2x %.2x %.2x\n",
984 __func__, padapter->securitypriv.dot11PrivacyKeyIndex, pattrib->iv[3], *pframe, *(pframe+1), *(pframe+2), *(pframe+3))); 983 __func__,
984 padapter->securitypriv.dot11PrivacyKeyIndex,
985 pattrib->iv[3], *pframe, *(pframe + 1),
986 *(pframe + 2), *(pframe + 3)));
985 987
986 pframe += pattrib->iv_len; 988 pframe += pattrib->iv_len;
987 989
@@ -997,7 +999,7 @@ s32 rtw_xmitframe_coalesce(struct adapter *padapter, struct sk_buff *pkt, struct
997 if ((pattrib->icv_len > 0) && (pattrib->bswenc)) 999 if ((pattrib->icv_len > 0) && (pattrib->bswenc))
998 mpdu_len -= pattrib->icv_len; 1000 mpdu_len -= pattrib->icv_len;
999 1001
1000 mem_sz = min_t(size_t, bmcst ? pattrib->pktlen : mpdu_len, remainder); 1002 mem_sz = min_t(size_t, mcast ? pattrib->pktlen : mpdu_len, remainder);
1001 skb_copy_bits(pkt, pkt->len - remainder, pframe, mem_sz); 1003 skb_copy_bits(pkt, pkt->len - remainder, pframe, mem_sz);
1002 remainder -= mem_sz; 1004 remainder -= mem_sz;
1003 1005
@@ -1010,7 +1012,7 @@ s32 rtw_xmitframe_coalesce(struct adapter *padapter, struct sk_buff *pkt, struct
1010 1012
1011 frg_inx++; 1013 frg_inx++;
1012 1014
1013 if (bmcst || remainder == 0) { 1015 if (mcast || remainder == 0) {
1014 pattrib->nr_frags = frg_inx; 1016 pattrib->nr_frags = frg_inx;
1015 1017
1016 pattrib->last_txcmdsz = pattrib->hdrlen + pattrib->iv_len + ((pattrib->nr_frags == 1) ? llc_sz : 0) + 1018 pattrib->last_txcmdsz = pattrib->hdrlen + pattrib->iv_len + ((pattrib->nr_frags == 1) ? llc_sz : 0) +
@@ -1041,7 +1043,7 @@ s32 rtw_xmitframe_coalesce(struct adapter *padapter, struct sk_buff *pkt, struct
1041 1043
1042 xmitframe_swencrypt(padapter, pxmitframe); 1044 xmitframe_swencrypt(padapter, pxmitframe);
1043 1045
1044 if (!bmcst) 1046 if (!mcast)
1045 update_attrib_vcs_info(padapter, pxmitframe); 1047 update_attrib_vcs_info(padapter, pxmitframe);
1046 else 1048 else
1047 pattrib->vcs_mode = NONE_VCS; 1049 pattrib->vcs_mode = NONE_VCS;
@@ -1121,7 +1123,7 @@ void rtw_count_tx_stats(struct adapter *padapter, struct xmit_frame *pxmitframe,
1121 struct xmit_priv *pxmitpriv = &padapter->xmitpriv; 1123 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1122 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 1124 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1123 1125
1124 if ((pxmitframe->frame_tag&0x0f) == DATA_FRAMETAG) { 1126 if ((pxmitframe->frame_tag & 0x0f) == DATA_FRAMETAG) {
1125 pxmitpriv->tx_bytes += sz; 1127 pxmitpriv->tx_bytes += sz;
1126 pmlmepriv->LinkDetectInfo.NumTxOkInPeriod += pxmitframe->agg_num; 1128 pmlmepriv->LinkDetectInfo.NumTxOkInPeriod += pxmitframe->agg_num;
1127 1129
@@ -1147,7 +1149,6 @@ struct xmit_buf *rtw_alloc_xmitbuf_ext(struct xmit_priv *pxmitpriv)
1147 list_del_init(&pxmitbuf->list); 1149 list_del_init(&pxmitbuf->list);
1148 pxmitpriv->free_xmit_extbuf_cnt--; 1150 pxmitpriv->free_xmit_extbuf_cnt--;
1149 pxmitbuf->priv_data = NULL; 1151 pxmitbuf->priv_data = NULL;
1150 /* pxmitbuf->ext_tag = true; */
1151 if (pxmitbuf->sctx) { 1152 if (pxmitbuf->sctx) {
1152 DBG_88E("%s pxmitbuf->sctx is not NULL\n", __func__); 1153 DBG_88E("%s pxmitbuf->sctx is not NULL\n", __func__);
1153 rtw_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_ALLOC); 1154 rtw_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_ALLOC);
@@ -1184,8 +1185,6 @@ struct xmit_buf *rtw_alloc_xmitbuf(struct xmit_priv *pxmitpriv)
1184 struct xmit_buf *pxmitbuf; 1185 struct xmit_buf *pxmitbuf;
1185 struct __queue *pfree_xmitbuf_queue = &pxmitpriv->free_xmitbuf_queue; 1186 struct __queue *pfree_xmitbuf_queue = &pxmitpriv->free_xmitbuf_queue;
1186 1187
1187 /* DBG_88E("+rtw_alloc_xmitbuf\n"); */
1188
1189 spin_lock_irqsave(&pfree_xmitbuf_queue->lock, irql); 1188 spin_lock_irqsave(&pfree_xmitbuf_queue->lock, irql);
1190 pxmitbuf = list_first_entry_or_null(&pfree_xmitbuf_queue->queue, 1189 pxmitbuf = list_first_entry_or_null(&pfree_xmitbuf_queue->queue,
1191 struct xmit_buf, list); 1190 struct xmit_buf, list);
@@ -1276,7 +1275,6 @@ struct xmit_frame *rtw_alloc_xmitframe(struct xmit_priv *pxmitpriv)
1276 pxframe->pxmitbuf = NULL; 1275 pxframe->pxmitbuf = NULL;
1277 1276
1278 memset(&pxframe->attrib, 0, sizeof(struct pkt_attrib)); 1277 memset(&pxframe->attrib, 0, sizeof(struct pkt_attrib));
1279 /* pxframe->attrib.psta = NULL; */
1280 1278
1281 pxframe->frame_tag = DATA_FRAMETAG; 1279 pxframe->frame_tag = DATA_FRAMETAG;
1282 1280
@@ -1350,7 +1348,6 @@ s32 rtw_xmitframe_enqueue(struct adapter *padapter, struct xmit_frame *pxmitfram
1350 if (rtw_xmit_classifier(padapter, pxmitframe) == _FAIL) { 1348 if (rtw_xmit_classifier(padapter, pxmitframe) == _FAIL) {
1351 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, 1349 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
1352 ("%s: drop xmit pkt for classifier fail\n", __func__)); 1350 ("%s: drop xmit pkt for classifier fail\n", __func__));
1353/* pxmitframe->pkt = NULL; */
1354 return _FAIL; 1351 return _FAIL;
1355 } 1352 }
1356 1353
@@ -1429,7 +1426,8 @@ exit:
1429 return pxmitframe; 1426 return pxmitframe;
1430} 1427}
1431 1428
1432struct tx_servq *rtw_get_sta_pending(struct adapter *padapter, struct sta_info *psta, int up, u8 *ac) 1429struct tx_servq *rtw_get_sta_pending(struct adapter *padapter,
1430 struct sta_info *psta, int up, u8 *ac)
1433{ 1431{
1434 struct tx_servq *ptxservq; 1432 struct tx_servq *ptxservq;
1435 1433
@@ -1438,26 +1436,30 @@ struct tx_servq *rtw_get_sta_pending(struct adapter *padapter, struct sta_info *
1438 case 2: 1436 case 2:
1439 ptxservq = &psta->sta_xmitpriv.bk_q; 1437 ptxservq = &psta->sta_xmitpriv.bk_q;
1440 *(ac) = 3; 1438 *(ac) = 3;
1441 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("%s : BK\n", __func__)); 1439 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
1440 ("%s : BK\n", __func__));
1442 break; 1441 break;
1443 case 4: 1442 case 4:
1444 case 5: 1443 case 5:
1445 ptxservq = &psta->sta_xmitpriv.vi_q; 1444 ptxservq = &psta->sta_xmitpriv.vi_q;
1446 *(ac) = 1; 1445 *(ac) = 1;
1447 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("%s : VI\n", __func__)); 1446 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
1447 ("%s : VI\n", __func__));
1448 break; 1448 break;
1449 case 6: 1449 case 6:
1450 case 7: 1450 case 7:
1451 ptxservq = &psta->sta_xmitpriv.vo_q; 1451 ptxservq = &psta->sta_xmitpriv.vo_q;
1452 *(ac) = 0; 1452 *(ac) = 0;
1453 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("%s : VO\n", __func__)); 1453 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
1454 ("%s : VO\n", __func__));
1454 break; 1455 break;
1455 case 0: 1456 case 0:
1456 case 3: 1457 case 3:
1457 default: 1458 default:
1458 ptxservq = &psta->sta_xmitpriv.be_q; 1459 ptxservq = &psta->sta_xmitpriv.be_q;
1459 *(ac) = 2; 1460 *(ac) = 2;
1460 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("%s : BE\n", __func__)); 1461 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
1462 ("%s : BE\n", __func__));
1461 break; 1463 break;
1462 } 1464 }
1463 1465
@@ -1617,7 +1619,7 @@ s32 rtw_xmit(struct adapter *padapter, struct sk_buff **ppkt)
1617 spin_unlock_bh(&pxmitpriv->lock); 1619 spin_unlock_bh(&pxmitpriv->lock);
1618#endif 1620#endif
1619 1621
1620 if (rtw_hal_xmit(padapter, pxmitframe) == false) 1622 if (!rtw_hal_xmit(padapter, pxmitframe))
1621 return 1; 1623 return 1;
1622 1624
1623 return 0; 1625 return 0;
@@ -1632,9 +1634,9 @@ int xmitframe_enqueue_for_sleeping_sta(struct adapter *padapter, struct xmit_fra
1632 struct sta_priv *pstapriv = &padapter->stapriv; 1634 struct sta_priv *pstapriv = &padapter->stapriv;
1633 struct pkt_attrib *pattrib = &pxmitframe->attrib; 1635 struct pkt_attrib *pattrib = &pxmitframe->attrib;
1634 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 1636 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1635 int bmcst = IS_MCAST(pattrib->ra); 1637 bool mcast = is_multicast_ether_addr(pattrib->ra);
1636 1638
1637 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == false) 1639 if (!check_fwstate(pmlmepriv, WIFI_AP_STATE))
1638 return ret; 1640 return ret;
1639 1641
1640 if (pattrib->psta) 1642 if (pattrib->psta)
@@ -1646,12 +1648,12 @@ int xmitframe_enqueue_for_sleeping_sta(struct adapter *padapter, struct xmit_fra
1646 return ret; 1648 return ret;
1647 1649
1648 if (pattrib->triggered == 1) { 1650 if (pattrib->triggered == 1) {
1649 if (bmcst) 1651 if (mcast)
1650 pattrib->qsel = 0x11;/* HIQ */ 1652 pattrib->qsel = 0x11;/* HIQ */
1651 return ret; 1653 return ret;
1652 } 1654 }
1653 1655
1654 if (bmcst) { 1656 if (mcast) {
1655 spin_lock_bh(&psta->sleep_q.lock); 1657 spin_lock_bh(&psta->sleep_q.lock);
1656 1658
1657 if (pstapriv->sta_dz_bitmap) {/* if any one sta is in ps mode */ 1659 if (pstapriv->sta_dz_bitmap) {/* if any one sta is in ps mode */
@@ -1676,10 +1678,10 @@ int xmitframe_enqueue_for_sleeping_sta(struct adapter *padapter, struct xmit_fra
1676 1678
1677 spin_lock_bh(&psta->sleep_q.lock); 1679 spin_lock_bh(&psta->sleep_q.lock);
1678 1680
1679 if (psta->state&WIFI_SLEEP_STATE) { 1681 if (psta->state & WIFI_SLEEP_STATE) {
1680 u8 wmmps_ac = 0; 1682 u8 wmmps_ac = 0;
1681 1683
1682 if (pstapriv->sta_dz_bitmap&BIT(psta->aid)) { 1684 if (pstapriv->sta_dz_bitmap & BIT(psta->aid)) {
1683 list_del_init(&pxmitframe->list); 1685 list_del_init(&pxmitframe->list);
1684 1686
1685 list_add_tail(&pxmitframe->list, get_list_head(&psta->sleep_q)); 1687 list_add_tail(&pxmitframe->list, get_list_head(&psta->sleep_q));
@@ -1773,21 +1775,26 @@ void stop_sta_xmit(struct adapter *padapter, struct sta_info *psta)
1773 1775
1774 pstapriv->sta_dz_bitmap |= BIT(psta->aid); 1776 pstapriv->sta_dz_bitmap |= BIT(psta->aid);
1775 1777
1776 dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->vo_q.sta_pending); 1778 dequeue_xmitframes_to_sleeping_queue(padapter, psta,
1779 &pstaxmitpriv->vo_q.sta_pending);
1777 list_del_init(&pstaxmitpriv->vo_q.tx_pending); 1780 list_del_init(&pstaxmitpriv->vo_q.tx_pending);
1778 1781
1779 dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->vi_q.sta_pending); 1782 dequeue_xmitframes_to_sleeping_queue(padapter, psta,
1783 &pstaxmitpriv->vi_q.sta_pending);
1780 list_del_init(&pstaxmitpriv->vi_q.tx_pending); 1784 list_del_init(&pstaxmitpriv->vi_q.tx_pending);
1781 1785
1782 dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->be_q.sta_pending); 1786 dequeue_xmitframes_to_sleeping_queue(padapter, psta,
1787 &pstaxmitpriv->be_q.sta_pending);
1783 list_del_init(&pstaxmitpriv->be_q.tx_pending); 1788 list_del_init(&pstaxmitpriv->be_q.tx_pending);
1784 1789
1785 dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->bk_q.sta_pending); 1790 dequeue_xmitframes_to_sleeping_queue(padapter, psta,
1791 &pstaxmitpriv->bk_q.sta_pending);
1786 list_del_init(&pstaxmitpriv->bk_q.tx_pending); 1792 list_del_init(&pstaxmitpriv->bk_q.tx_pending);
1787 1793
1788 /* for BC/MC Frames */ 1794 /* for BC/MC Frames */
1789 pstaxmitpriv = &psta_bmc->sta_xmitpriv; 1795 pstaxmitpriv = &psta_bmc->sta_xmitpriv;
1790 dequeue_xmitframes_to_sleeping_queue(padapter, psta_bmc, &pstaxmitpriv->be_q.sta_pending); 1796 dequeue_xmitframes_to_sleeping_queue(padapter, psta_bmc,
1797 &pstaxmitpriv->be_q.sta_pending);
1791 list_del_init(&pstaxmitpriv->be_q.tx_pending); 1798 list_del_init(&pstaxmitpriv->be_q.tx_pending);
1792 1799
1793 spin_unlock_bh(&pxmitpriv->lock); 1800 spin_unlock_bh(&pxmitpriv->lock);
@@ -1863,7 +1870,7 @@ void wakeup_sta_to_xmit(struct adapter *padapter, struct sta_info *psta)
1863 1870
1864 update_mask = BIT(0); 1871 update_mask = BIT(0);
1865 1872
1866 if (psta->state&WIFI_SLEEP_STATE) 1873 if (psta->state & WIFI_SLEEP_STATE)
1867 psta->state ^= WIFI_SLEEP_STATE; 1874 psta->state ^= WIFI_SLEEP_STATE;
1868 1875
1869 if (psta->state & WIFI_STA_ALIVE_CHK_STATE) { 1876 if (psta->state & WIFI_STA_ALIVE_CHK_STATE) {
@@ -1881,7 +1888,7 @@ void wakeup_sta_to_xmit(struct adapter *padapter, struct sta_info *psta)
1881 if (!psta_bmc) 1888 if (!psta_bmc)
1882 return; 1889 return;
1883 1890
1884 if ((pstapriv->sta_dz_bitmap&0xfffe) == 0x0) { /* no any sta in ps mode */ 1891 if ((pstapriv->sta_dz_bitmap & 0xfffe) == 0x0) { /* no any sta in ps mode */
1885 spin_lock_bh(&psta_bmc->sleep_q.lock); 1892 spin_lock_bh(&psta_bmc->sleep_q.lock);
1886 1893
1887 xmitframe_phead = get_list_head(&psta_bmc->sleep_q); 1894 xmitframe_phead = get_list_head(&psta_bmc->sleep_q);
diff --git a/drivers/staging/rtl8188eu/hal/bb_cfg.c b/drivers/staging/rtl8188eu/hal/bb_cfg.c
index 1862c1396c85..11e0bb9c67d7 100644
--- a/drivers/staging/rtl8188eu/hal/bb_cfg.c
+++ b/drivers/staging/rtl8188eu/hal/bb_cfg.c
@@ -1,9 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0
2/****************************************************************************** 2/******************************************************************************
3* 3 *
4* Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5* 5 *
6******************************************************************************/ 6 ******************************************************************************/
7 7
8#include "odm_precomp.h" 8#include "odm_precomp.h"
9 9
diff --git a/drivers/staging/rtl8188eu/hal/fw.c b/drivers/staging/rtl8188eu/hal/fw.c
index 1b8341f40995..486ee4bd4744 100644
--- a/drivers/staging/rtl8188eu/hal/fw.c
+++ b/drivers/staging/rtl8188eu/hal/fw.c
@@ -98,9 +98,9 @@ static void rtl88e_firmware_selfreset(struct adapter *adapt)
98{ 98{
99 u8 u1b_tmp; 99 u8 u1b_tmp;
100 100
101 u1b_tmp = usb_read8(adapt, REG_SYS_FUNC_EN+1); 101 u1b_tmp = usb_read8(adapt, REG_SYS_FUNC_EN + 1);
102 usb_write8(adapt, REG_SYS_FUNC_EN+1, (u1b_tmp & (~BIT(2)))); 102 usb_write8(adapt, REG_SYS_FUNC_EN + 1, (u1b_tmp & (~BIT(2))));
103 usb_write8(adapt, REG_SYS_FUNC_EN+1, (u1b_tmp | BIT(2))); 103 usb_write8(adapt, REG_SYS_FUNC_EN + 1, (u1b_tmp | BIT(2)));
104} 104}
105 105
106static int _rtl88e_fw_free_to_go(struct adapter *adapt) 106static int _rtl88e_fw_free_to_go(struct adapter *adapt)
diff --git a/drivers/staging/rtl8188eu/hal/hal8188e_rate_adaptive.c b/drivers/staging/rtl8188eu/hal/hal8188e_rate_adaptive.c
index 464c11710398..6dbd7d261f1e 100644
--- a/drivers/staging/rtl8188eu/hal/hal8188e_rate_adaptive.c
+++ b/drivers/staging/rtl8188eu/hal/hal8188e_rate_adaptive.c
@@ -418,14 +418,16 @@ static int odm_ARFBRefresh_8188E(struct odm_dm_struct *dm_odm, struct odm_ra_inf
418 } else { 418 } else {
419 pRaInfo->LowestRate = 0; 419 pRaInfo->LowestRate = 0;
420 } 420 }
421 if (pRaInfo->HighestRate > 0x13) 421
422 pRaInfo->PTModeSS = 3; 422 if (pRaInfo->HighestRate > 0x13)
423 else if (pRaInfo->HighestRate > 0x0b) 423 pRaInfo->PTModeSS = 3;
424 pRaInfo->PTModeSS = 2; 424 else if (pRaInfo->HighestRate > 0x0b)
425 else if (pRaInfo->HighestRate > 0x0b) 425 pRaInfo->PTModeSS = 2;
426 pRaInfo->PTModeSS = 1; 426 else if (pRaInfo->HighestRate > 0x0b)
427 else 427 pRaInfo->PTModeSS = 1;
428 pRaInfo->PTModeSS = 0; 428 else
429 pRaInfo->PTModeSS = 0;
430
429 ODM_RT_TRACE(dm_odm, ODM_COMP_RATE_ADAPTIVE, ODM_DBG_LOUD, 431 ODM_RT_TRACE(dm_odm, ODM_COMP_RATE_ADAPTIVE, ODM_DBG_LOUD,
430 ("ODM_ARFBRefresh_8188E(): PTModeSS =%d\n", pRaInfo->PTModeSS)); 432 ("ODM_ARFBRefresh_8188E(): PTModeSS =%d\n", pRaInfo->PTModeSS));
431 433
diff --git a/drivers/staging/rtl8188eu/hal/hal_com.c b/drivers/staging/rtl8188eu/hal/hal_com.c
index 7202e1767fc0..ff481fbd074c 100644
--- a/drivers/staging/rtl8188eu/hal/hal_com.c
+++ b/drivers/staging/rtl8188eu/hal/hal_com.c
@@ -45,9 +45,8 @@ void dump_chip_info(struct HAL_VERSION chip_vers)
45#define CHAN_PLAN_HW 0x80 45#define CHAN_PLAN_HW 0x80
46 46
47/* return the final channel plan decision */ 47/* return the final channel plan decision */
48u8 hal_com_get_channel_plan(struct adapter *padapter, u8 hw_channel_plan, 48u8 hal_com_get_channel_plan(u8 hw_channel_plan, u8 sw_channel_plan,
49 u8 sw_channel_plan, u8 def_channel_plan, 49 u8 def_channel_plan, bool load_fail)
50 bool load_fail)
51{ 50{
52 u8 sw_cfg; 51 u8 sw_cfg;
53 u8 chnlplan; 52 u8 chnlplan;
@@ -119,7 +118,7 @@ u8 MRateToHwRate(u8 rate)
119 return ret; 118 return ret;
120} 119}
121 120
122void HalSetBrateCfg(struct adapter *adapt, u8 *brates, u16 *rate_cfg) 121void hal_set_brate_cfg(u8 *brates, u16 *rate_cfg)
123{ 122{
124 u8 i, is_brate, brate; 123 u8 i, is_brate, brate;
125 124
@@ -263,10 +262,10 @@ static void three_out_pipe(struct adapter *adapter, bool wifi_cfg)
263 } 262 }
264} 263}
265 264
266bool Hal_MappingOutPipe(struct adapter *adapter, u8 numoutpipe) 265bool hal_mapping_out_pipe(struct adapter *adapter, u8 numoutpipe)
267{ 266{
268 struct registry_priv *pregistrypriv = &adapter->registrypriv; 267 struct registry_priv *pregistrypriv = &adapter->registrypriv;
269 bool wifi_cfg = (pregistrypriv->wifi_spec) ? true : false; 268 bool wifi_cfg = (pregistrypriv->wifi_spec) ? true : false;
270 bool result = true; 269 bool result = true;
271 270
272 switch (numoutpipe) { 271 switch (numoutpipe) {
diff --git a/drivers/staging/rtl8188eu/hal/odm.c b/drivers/staging/rtl8188eu/hal/odm.c
index 9d567838a43a..4ab490c1c13b 100644
--- a/drivers/staging/rtl8188eu/hal/odm.c
+++ b/drivers/staging/rtl8188eu/hal/odm.c
@@ -418,7 +418,7 @@ void odm_DIG(struct odm_dm_struct *pDM_Odm)
418 418
419 /* 1 Modify DIG lower bound, deal with abnormally large false alarm */ 419 /* 1 Modify DIG lower bound, deal with abnormally large false alarm */
420 if (pFalseAlmCnt->Cnt_all > 10000) { 420 if (pFalseAlmCnt->Cnt_all > 10000) {
421 ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("dm_DIG(): Abnornally false alarm case.\n")); 421 ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("dm_DIG(): Abnormally false alarm case.\n"));
422 422
423 if (pDM_DigTable->LargeFAHit != 3) 423 if (pDM_DigTable->LargeFAHit != 3)
424 pDM_DigTable->LargeFAHit++; 424 pDM_DigTable->LargeFAHit++;
@@ -768,22 +768,7 @@ u32 ODM_Get_Rate_Bitmap(struct odm_dm_struct *pDM_Odm, u32 macid, u32 ra_mask, u
768 return rate_bitmap; 768 return rate_bitmap;
769} 769}
770 770
771/*----------------------------------------------------------------------------- 771/* Update rate table mask according to rssi */
772 * Function: odm_RefreshRateAdaptiveMask()
773 *
774 * Overview: Update rate table mask according to rssi
775 *
776 * Input: NONE
777 *
778 * Output: NONE
779 *
780 * Return: NONE
781 *
782 * Revised History:
783 * When Who Remark
784 * 05/27/2009 hpfan Create Version 0.
785 *
786 *---------------------------------------------------------------------------*/
787void odm_RefreshRateAdaptiveMask(struct odm_dm_struct *pDM_Odm) 772void odm_RefreshRateAdaptiveMask(struct odm_dm_struct *pDM_Odm)
788{ 773{
789 if (!(pDM_Odm->SupportAbility & ODM_BB_RA_MASK)) 774 if (!(pDM_Odm->SupportAbility & ODM_BB_RA_MASK))
@@ -1074,7 +1059,7 @@ void odm_EdcaTurboCheckCE(struct odm_dm_struct *pDM_Odm)
1074 struct mlme_ext_priv *pmlmeext = &(Adapter->mlmeextpriv); 1059 struct mlme_ext_priv *pmlmeext = &(Adapter->mlmeextpriv);
1075 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); 1060 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1076 1061
1077 if ((pregpriv->wifi_spec == 1))/* (pmlmeinfo->HT_enable == 0)) */ 1062 if (pregpriv->wifi_spec == 1) /* (pmlmeinfo->HT_enable == 0)) */
1078 goto dm_CheckEdcaTurbo_EXIT; 1063 goto dm_CheckEdcaTurbo_EXIT;
1079 1064
1080 if (pmlmeinfo->assoc_AP_vendor >= HT_IOT_PEER_MAX) 1065 if (pmlmeinfo->assoc_AP_vendor >= HT_IOT_PEER_MAX)
diff --git a/drivers/staging/rtl8188eu/hal/odm_HWConfig.c b/drivers/staging/rtl8188eu/hal/odm_hwconfig.c
index 0464dc41f860..82d6b2e18b29 100644
--- a/drivers/staging/rtl8188eu/hal/odm_HWConfig.c
+++ b/drivers/staging/rtl8188eu/hal/odm_hwconfig.c
@@ -14,52 +14,48 @@
14#define READ_AND_CONFIG_MP(ic, txt) (ODM_ReadAndConfig##txt##ic(dm_odm)) 14#define READ_AND_CONFIG_MP(ic, txt) (ODM_ReadAndConfig##txt##ic(dm_odm))
15#define READ_AND_CONFIG_TC(ic, txt) (ODM_ReadAndConfig_TC##txt##ic(dm_odm)) 15#define READ_AND_CONFIG_TC(ic, txt) (ODM_ReadAndConfig_TC##txt##ic(dm_odm))
16 16
17static u8 odm_QueryRxPwrPercentage(s8 AntPower) 17static u8 odm_query_rxpwrpercentage(s8 antpower)
18{ 18{
19 if ((AntPower <= -100) || (AntPower >= 20)) 19 if ((antpower <= -100) || (antpower >= 20))
20 return 0; 20 return 0;
21 else if (AntPower >= 0) 21 else if (antpower >= 0)
22 return 100; 22 return 100;
23 else 23 else
24 return 100+AntPower; 24 return 100 + antpower;
25} 25}
26 26
27/* 2012/01/12 MH MOve some signal strength smooth method to MP HAL layer. */ 27/* 2012/01/12 MH MOve some signal strength smooth method to MP HAL layer. */
28/* IF other SW team do not support the feature, remove this section.?? */ 28/* IF other SW team do not support the feature, remove this section.?? */
29static s32 odm_SignalScaleMapping_92CSeries(struct odm_dm_struct *dm_odm, s32 CurrSig) 29static s32 odm_signal_scale_mapping(struct odm_dm_struct *dm_odm, s32 currsig)
30{ 30{
31 s32 RetSig = 0; 31 s32 retsig = 0;
32 32
33 if (CurrSig >= 51 && CurrSig <= 100) 33 if (currsig >= 51 && currsig <= 100)
34 RetSig = 100; 34 retsig = 100;
35 else if (CurrSig >= 41 && CurrSig <= 50) 35 else if (currsig >= 41 && currsig <= 50)
36 RetSig = 80 + ((CurrSig - 40)*2); 36 retsig = 80 + ((currsig - 40) * 2);
37 else if (CurrSig >= 31 && CurrSig <= 40) 37 else if (currsig >= 31 && currsig <= 40)
38 RetSig = 66 + (CurrSig - 30); 38 retsig = 66 + (currsig - 30);
39 else if (CurrSig >= 21 && CurrSig <= 30) 39 else if (currsig >= 21 && currsig <= 30)
40 RetSig = 54 + (CurrSig - 20); 40 retsig = 54 + (currsig - 20);
41 else if (CurrSig >= 10 && CurrSig <= 20) 41 else if (currsig >= 10 && currsig <= 20)
42 RetSig = 42 + (((CurrSig - 10) * 2) / 3); 42 retsig = 42 + (((currsig - 10) * 2) / 3);
43 else if (CurrSig >= 5 && CurrSig <= 9) 43 else if (currsig >= 5 && currsig <= 9)
44 RetSig = 22 + (((CurrSig - 5) * 3) / 2); 44 retsig = 22 + (((currsig - 5) * 3) / 2);
45 else if (CurrSig >= 1 && CurrSig <= 4) 45 else if (currsig >= 1 && currsig <= 4)
46 RetSig = 6 + (((CurrSig - 1) * 3) / 2); 46 retsig = 6 + (((currsig - 1) * 3) / 2);
47 else 47 else
48 RetSig = CurrSig; 48 retsig = currsig;
49 return RetSig;
50}
51 49
52static s32 odm_SignalScaleMapping(struct odm_dm_struct *dm_odm, s32 CurrSig) 50 return retsig;
53{
54 return odm_SignalScaleMapping_92CSeries(dm_odm, CurrSig);
55} 51}
56 52
57static u8 odm_EVMdbToPercentage(s8 Value) 53static u8 odm_evm_db_to_percentage(s8 value)
58{ 54{
59 /* -33dB~0dB to 0%~99% */ 55 /* -33dB~0dB to 0%~99% */
60 s8 ret_val; 56 s8 ret_val;
61 57
62 ret_val = Value; 58 ret_val = value;
63 59
64 if (ret_val >= 0) 60 if (ret_val >= 0)
65 ret_val = 0; 61 ret_val = 0;
@@ -115,42 +111,42 @@ static void odm_RxPhyStatus92CSeries_Parsing(struct odm_dm_struct *dm_odm,
115 switch (LNA_idx) { 111 switch (LNA_idx) {
116 case 7: 112 case 7:
117 if (VGA_idx <= 27) 113 if (VGA_idx <= 27)
118 rx_pwr_all = -100 + 2*(27-VGA_idx); /* VGA_idx = 27~2 */ 114 rx_pwr_all = -100 + 2 * (27-VGA_idx); /* VGA_idx = 27~2 */
119 else 115 else
120 rx_pwr_all = -100; 116 rx_pwr_all = -100;
121 break; 117 break;
122 case 6: 118 case 6:
123 rx_pwr_all = -48 + 2*(2-VGA_idx); /* VGA_idx = 2~0 */ 119 rx_pwr_all = -48 + 2 * (2-VGA_idx); /* VGA_idx = 2~0 */
124 break; 120 break;
125 case 5: 121 case 5:
126 rx_pwr_all = -42 + 2*(7-VGA_idx); /* VGA_idx = 7~5 */ 122 rx_pwr_all = -42 + 2 * (7-VGA_idx); /* VGA_idx = 7~5 */
127 break; 123 break;
128 case 4: 124 case 4:
129 rx_pwr_all = -36 + 2*(7-VGA_idx); /* VGA_idx = 7~4 */ 125 rx_pwr_all = -36 + 2 * (7-VGA_idx); /* VGA_idx = 7~4 */
130 break; 126 break;
131 case 3: 127 case 3:
132 rx_pwr_all = -24 + 2*(7-VGA_idx); /* VGA_idx = 7~0 */ 128 rx_pwr_all = -24 + 2 * (7-VGA_idx); /* VGA_idx = 7~0 */
133 break; 129 break;
134 case 2: 130 case 2:
135 if (cck_highpwr) 131 if (cck_highpwr)
136 rx_pwr_all = -12 + 2*(5-VGA_idx); /* VGA_idx = 5~0 */ 132 rx_pwr_all = -12 + 2 * (5-VGA_idx); /* VGA_idx = 5~0 */
137 else 133 else
138 rx_pwr_all = -6 + 2*(5-VGA_idx); 134 rx_pwr_all = -6 + 2 * (5-VGA_idx);
139 break; 135 break;
140 case 1: 136 case 1:
141 rx_pwr_all = 8-2*VGA_idx; 137 rx_pwr_all = 8-2 * VGA_idx;
142 break; 138 break;
143 case 0: 139 case 0:
144 rx_pwr_all = 14-2*VGA_idx; 140 rx_pwr_all = 14-2 * VGA_idx;
145 break; 141 break;
146 default: 142 default:
147 break; 143 break;
148 } 144 }
149 rx_pwr_all += 6; 145 rx_pwr_all += 6;
150 PWDB_ALL = odm_QueryRxPwrPercentage(rx_pwr_all); 146 PWDB_ALL = odm_query_rxpwrpercentage(rx_pwr_all);
151 if (!cck_highpwr) { 147 if (!cck_highpwr) {
152 if (PWDB_ALL >= 80) 148 if (PWDB_ALL >= 80)
153 PWDB_ALL = ((PWDB_ALL-80)<<1)+((PWDB_ALL-80)>>1)+80; 149 PWDB_ALL = ((PWDB_ALL-80)<<1) + ((PWDB_ALL-80)>>1) + 80;
154 else if ((PWDB_ALL <= 78) && (PWDB_ALL >= 20)) 150 else if ((PWDB_ALL <= 78) && (PWDB_ALL >= 20))
155 PWDB_ALL += 3; 151 PWDB_ALL += 3;
156 if (PWDB_ALL > 100) 152 if (PWDB_ALL > 100)
@@ -185,17 +181,17 @@ static void odm_RxPhyStatus92CSeries_Parsing(struct odm_dm_struct *dm_odm,
185 181
186 /* (1)Get RSSI for HT rate */ 182 /* (1)Get RSSI for HT rate */
187 183
188 for (i = RF_PATH_A; i < RF_PATH_MAX; i++) { 184 for (i = RF_PATH_A; i < RF_PATH_MAX; i++) {
189 /* 2008/01/30 MH we will judge RF RX path now. */ 185 /* 2008/01/30 MH we will judge RF RX path now. */
190 if (dm_odm->RFPathRxEnable & BIT(i)) 186 if (dm_odm->RFPathRxEnable & BIT(i))
191 rf_rx_num++; 187 rf_rx_num++;
192 188
193 rx_pwr[i] = ((pPhyStaRpt->path_agc[i].gain & 0x3F)*2) - 110; 189 rx_pwr[i] = ((pPhyStaRpt->path_agc[i].gain & 0x3F) * 2) - 110;
194 190
195 pPhyInfo->RxPwr[i] = rx_pwr[i]; 191 pPhyInfo->RxPwr[i] = rx_pwr[i];
196 192
197 /* Translate DBM to percentage. */ 193 /* Translate DBM to percentage. */
198 RSSI = odm_QueryRxPwrPercentage(rx_pwr[i]); 194 RSSI = odm_query_rxpwrpercentage(rx_pwr[i]);
199 total_rssi += RSSI; 195 total_rssi += RSSI;
200 196
201 /* Modification for ext-LNA board */ 197 /* Modification for ext-LNA board */
@@ -218,7 +214,7 @@ static void odm_RxPhyStatus92CSeries_Parsing(struct odm_dm_struct *dm_odm,
218 /* (2)PWDB, Average PWDB calculated by hardware (for rate adaptive) */ 214 /* (2)PWDB, Average PWDB calculated by hardware (for rate adaptive) */
219 rx_pwr_all = (((pPhyStaRpt->cck_sig_qual_ofdm_pwdb_all) >> 1) & 0x7f) - 110; 215 rx_pwr_all = (((pPhyStaRpt->cck_sig_qual_ofdm_pwdb_all) >> 1) & 0x7f) - 110;
220 216
221 PWDB_ALL = odm_QueryRxPwrPercentage(rx_pwr_all); 217 PWDB_ALL = odm_query_rxpwrpercentage(rx_pwr_all);
222 PWDB_ALL_BT = PWDB_ALL; 218 PWDB_ALL_BT = PWDB_ALL;
223 219
224 pPhyInfo->RxPWDBAll = PWDB_ALL; 220 pPhyInfo->RxPWDBAll = PWDB_ALL;
@@ -236,7 +232,7 @@ static void odm_RxPhyStatus92CSeries_Parsing(struct odm_dm_struct *dm_odm,
236 /* Do not use shift operation like "rx_evmX >>= 1" because the compilor of free build environment */ 232 /* Do not use shift operation like "rx_evmX >>= 1" because the compilor of free build environment */
237 /* fill most significant bit to "zero" when doing shifting operation which may change a negative */ 233 /* fill most significant bit to "zero" when doing shifting operation which may change a negative */
238 /* value to positive one, then the dbm value (which is supposed to be negative) is not correct anymore. */ 234 /* value to positive one, then the dbm value (which is supposed to be negative) is not correct anymore. */
239 EVM = odm_EVMdbToPercentage((pPhyStaRpt->stream_rxevm[i])); /* dbm */ 235 EVM = odm_evm_db_to_percentage((pPhyStaRpt->stream_rxevm[i])); /* dbm */
240 236
241 if (pPktinfo->bPacketMatchBSSID) { 237 if (pPktinfo->bPacketMatchBSSID) {
242 if (i == RF_PATH_A) /* Fill value in RFD, Get the first spatial stream only */ 238 if (i == RF_PATH_A) /* Fill value in RFD, Get the first spatial stream only */
@@ -248,10 +244,10 @@ static void odm_RxPhyStatus92CSeries_Parsing(struct odm_dm_struct *dm_odm,
248 /* UI BSS List signal strength(in percentage), make it good looking, from 0~100. */ 244 /* UI BSS List signal strength(in percentage), make it good looking, from 0~100. */
249 /* It is assigned to the BSS List in GetValueFromBeaconOrProbeRsp(). */ 245 /* It is assigned to the BSS List in GetValueFromBeaconOrProbeRsp(). */
250 if (isCCKrate) { 246 if (isCCKrate) {
251 pPhyInfo->SignalStrength = (u8)(odm_SignalScaleMapping(dm_odm, PWDB_ALL));/* PWDB_ALL; */ 247 pPhyInfo->SignalStrength = (u8)(odm_signal_scale_mapping(dm_odm, PWDB_ALL));/* PWDB_ALL; */
252 } else { 248 } else {
253 if (rf_rx_num != 0) 249 if (rf_rx_num != 0)
254 pPhyInfo->SignalStrength = (u8)(odm_SignalScaleMapping(dm_odm, total_rssi /= rf_rx_num)); 250 pPhyInfo->SignalStrength = (u8)(odm_signal_scale_mapping(dm_odm, total_rssi /= rf_rx_num));
255 } 251 }
256 252
257 /* For 92C/92D HW (Hybrid) Antenna Diversity */ 253 /* For 92C/92D HW (Hybrid) Antenna Diversity */
@@ -339,12 +335,12 @@ static void odm_Process_RSSIForDM(struct odm_dm_struct *dm_odm,
339 } else { 335 } else {
340 if (pPhyInfo->RxPWDBAll > (u32)UndecoratedSmoothedOFDM) { 336 if (pPhyInfo->RxPWDBAll > (u32)UndecoratedSmoothedOFDM) {
341 UndecoratedSmoothedOFDM = 337 UndecoratedSmoothedOFDM =
342 (((UndecoratedSmoothedOFDM)*(Rx_Smooth_Factor-1)) + 338 (((UndecoratedSmoothedOFDM) * (Rx_Smooth_Factor-1)) +
343 (RSSI_Ave)) / (Rx_Smooth_Factor); 339 (RSSI_Ave)) / (Rx_Smooth_Factor);
344 UndecoratedSmoothedOFDM = UndecoratedSmoothedOFDM + 1; 340 UndecoratedSmoothedOFDM = UndecoratedSmoothedOFDM + 1;
345 } else { 341 } else {
346 UndecoratedSmoothedOFDM = 342 UndecoratedSmoothedOFDM =
347 (((UndecoratedSmoothedOFDM)*(Rx_Smooth_Factor-1)) + 343 (((UndecoratedSmoothedOFDM) * (Rx_Smooth_Factor-1)) +
348 (RSSI_Ave)) / (Rx_Smooth_Factor); 344 (RSSI_Ave)) / (Rx_Smooth_Factor);
349 } 345 }
350 } 346 }
@@ -382,7 +378,7 @@ static void odm_Process_RSSIForDM(struct odm_dm_struct *dm_odm,
382 378
383 if (pEntry->rssi_stat.ValidBit == 64) { 379 if (pEntry->rssi_stat.ValidBit == 64) {
384 Weighting = min_t(u32, OFDM_pkt << 4, 64); 380 Weighting = min_t(u32, OFDM_pkt << 4, 64);
385 UndecoratedSmoothedPWDB = (Weighting*UndecoratedSmoothedOFDM+(64-Weighting)*UndecoratedSmoothedCCK)>>6; 381 UndecoratedSmoothedPWDB = (Weighting * UndecoratedSmoothedOFDM + (64-Weighting) * UndecoratedSmoothedCCK)>>6;
386 } else { 382 } else {
387 if (pEntry->rssi_stat.ValidBit != 0) 383 if (pEntry->rssi_stat.ValidBit != 0)
388 UndecoratedSmoothedPWDB = (OFDM_pkt * UndecoratedSmoothedOFDM + 384 UndecoratedSmoothedPWDB = (OFDM_pkt * UndecoratedSmoothedOFDM +
diff --git a/drivers/staging/rtl8188eu/hal/odm_rtl8188e.c b/drivers/staging/rtl8188eu/hal/odm_rtl8188e.c
index d5001920f77c..251bd8aba3b1 100644
--- a/drivers/staging/rtl8188eu/hal/odm_rtl8188e.c
+++ b/drivers/staging/rtl8188eu/hal/odm_rtl8188e.c
@@ -13,7 +13,7 @@ static void dm_rx_hw_antena_div_init(struct odm_dm_struct *dm_odm)
13 struct adapter *adapter = dm_odm->Adapter; 13 struct adapter *adapter = dm_odm->Adapter;
14 u32 value32; 14 u32 value32;
15 15
16 if (*(dm_odm->mp_mode) == 1) { 16 if (*dm_odm->mp_mode == 1) {
17 dm_odm->AntDivType = CGCS_RX_SW_ANTDIV; 17 dm_odm->AntDivType = CGCS_RX_SW_ANTDIV;
18 phy_set_bb_reg(adapter, ODM_REG_IGI_A_11N, BIT(7), 0); 18 phy_set_bb_reg(adapter, ODM_REG_IGI_A_11N, BIT(7), 0);
19 phy_set_bb_reg(adapter, ODM_REG_LNA_SWITCH_11N, BIT(31), 1); 19 phy_set_bb_reg(adapter, ODM_REG_LNA_SWITCH_11N, BIT(31), 1);
@@ -23,7 +23,7 @@ static void dm_rx_hw_antena_div_init(struct odm_dm_struct *dm_odm)
23 /* MAC Setting */ 23 /* MAC Setting */
24 value32 = phy_query_bb_reg(adapter, ODM_REG_ANTSEL_PIN_11N, bMaskDWord); 24 value32 = phy_query_bb_reg(adapter, ODM_REG_ANTSEL_PIN_11N, bMaskDWord);
25 phy_set_bb_reg(adapter, ODM_REG_ANTSEL_PIN_11N, bMaskDWord, 25 phy_set_bb_reg(adapter, ODM_REG_ANTSEL_PIN_11N, bMaskDWord,
26 value32|(BIT(23) | BIT(25))); 26 value32 | (BIT(23) | BIT(25)));
27 /* Pin Settings */ 27 /* Pin Settings */
28 phy_set_bb_reg(adapter, ODM_REG_PIN_CTRL_11N, BIT(9) | BIT(8), 0); 28 phy_set_bb_reg(adapter, ODM_REG_PIN_CTRL_11N, BIT(9) | BIT(8), 0);
29 phy_set_bb_reg(adapter, ODM_REG_RX_ANT_CTRL_11N, BIT(10), 0); 29 phy_set_bb_reg(adapter, ODM_REG_RX_ANT_CTRL_11N, BIT(10), 0);
@@ -44,7 +44,7 @@ static void dm_trx_hw_antenna_div_init(struct odm_dm_struct *dm_odm)
44 struct adapter *adapter = dm_odm->Adapter; 44 struct adapter *adapter = dm_odm->Adapter;
45 u32 value32; 45 u32 value32;
46 46
47 if (*(dm_odm->mp_mode) == 1) { 47 if (*dm_odm->mp_mode == 1) {
48 dm_odm->AntDivType = CGCS_RX_SW_ANTDIV; 48 dm_odm->AntDivType = CGCS_RX_SW_ANTDIV;
49 phy_set_bb_reg(adapter, ODM_REG_IGI_A_11N, BIT(7), 0); 49 phy_set_bb_reg(adapter, ODM_REG_IGI_A_11N, BIT(7), 0);
50 phy_set_bb_reg(adapter, ODM_REG_RX_ANT_CTRL_11N, 50 phy_set_bb_reg(adapter, ODM_REG_RX_ANT_CTRL_11N,
@@ -55,7 +55,7 @@ static void dm_trx_hw_antenna_div_init(struct odm_dm_struct *dm_odm)
55 /* MAC Setting */ 55 /* MAC Setting */
56 value32 = phy_query_bb_reg(adapter, ODM_REG_ANTSEL_PIN_11N, bMaskDWord); 56 value32 = phy_query_bb_reg(adapter, ODM_REG_ANTSEL_PIN_11N, bMaskDWord);
57 phy_set_bb_reg(adapter, ODM_REG_ANTSEL_PIN_11N, bMaskDWord, 57 phy_set_bb_reg(adapter, ODM_REG_ANTSEL_PIN_11N, bMaskDWord,
58 value32|(BIT(23) | BIT(25))); 58 value32 | (BIT(23) | BIT(25)));
59 /* Pin Settings */ 59 /* Pin Settings */
60 phy_set_bb_reg(adapter, ODM_REG_PIN_CTRL_11N, BIT(9) | BIT(8), 0); 60 phy_set_bb_reg(adapter, ODM_REG_PIN_CTRL_11N, BIT(9) | BIT(8), 0);
61 phy_set_bb_reg(adapter, ODM_REG_RX_ANT_CTRL_11N, BIT(10), 0); 61 phy_set_bb_reg(adapter, ODM_REG_RX_ANT_CTRL_11N, BIT(10), 0);
@@ -88,11 +88,9 @@ static void dm_fast_training_init(struct odm_dm_struct *dm_odm)
88 struct adapter *adapter = dm_odm->Adapter; 88 struct adapter *adapter = dm_odm->Adapter;
89 u32 value32, i; 89 u32 value32, i;
90 struct fast_ant_train *dm_fat_tbl = &dm_odm->DM_FatTable; 90 struct fast_ant_train *dm_fat_tbl = &dm_odm->DM_FatTable;
91 u32 AntCombination = 2;
92 91
93 if (*(dm_odm->mp_mode) == 1) { 92 if (*dm_odm->mp_mode == 1)
94 return; 93 return;
95 }
96 94
97 for (i = 0; i < 6; i++) { 95 for (i = 0; i < 6; i++) {
98 dm_fat_tbl->Bssid[i] = 0; 96 dm_fat_tbl->Bssid[i] = 0;
@@ -105,9 +103,11 @@ static void dm_fast_training_init(struct odm_dm_struct *dm_odm)
105 103
106 /* MAC Setting */ 104 /* MAC Setting */
107 value32 = phy_query_bb_reg(adapter, 0x4c, bMaskDWord); 105 value32 = phy_query_bb_reg(adapter, 0x4c, bMaskDWord);
108 phy_set_bb_reg(adapter, 0x4c, bMaskDWord, value32|(BIT(23) | BIT(25))); 106 phy_set_bb_reg(adapter, 0x4c, bMaskDWord,
107 value32 | (BIT(23) | BIT(25)));
109 value32 = phy_query_bb_reg(adapter, 0x7B4, bMaskDWord); 108 value32 = phy_query_bb_reg(adapter, 0x7B4, bMaskDWord);
110 phy_set_bb_reg(adapter, 0x7b4, bMaskDWord, value32|(BIT(16) | BIT(17))); 109 phy_set_bb_reg(adapter, 0x7b4, bMaskDWord,
110 value32 | (BIT(16) | BIT(17)));
111 111
112 /* Match MAC ADDR */ 112 /* Match MAC ADDR */
113 phy_set_bb_reg(adapter, 0x7b4, 0xFFFF, 0); 113 phy_set_bb_reg(adapter, 0x7b4, 0xFFFF, 0);
@@ -120,35 +120,12 @@ static void dm_fast_training_init(struct odm_dm_struct *dm_odm)
120 phy_set_bb_reg(adapter, 0xca4, bMaskDWord, 0x000000a0); 120 phy_set_bb_reg(adapter, 0xca4, bMaskDWord, 0x000000a0);
121 121
122 /* antenna mapping table */ 122 /* antenna mapping table */
123 if (AntCombination == 2) { 123 if (!dm_odm->bIsMPChip) { /* testchip */
124 if (!dm_odm->bIsMPChip) { /* testchip */ 124 phy_set_bb_reg(adapter, 0x858, BIT(10) | BIT(9) | BIT(8), 1);
125 phy_set_bb_reg(adapter, 0x858, BIT(10) | BIT(9) | BIT(8), 1); 125 phy_set_bb_reg(adapter, 0x858, BIT(13) | BIT(12) | BIT(11), 2);
126 phy_set_bb_reg(adapter, 0x858, BIT(13) | BIT(12) | BIT(11), 2); 126 } else { /* MPchip */
127 } else { /* MPchip */ 127 phy_set_bb_reg(adapter, 0x914, bMaskByte0, 1);
128 phy_set_bb_reg(adapter, 0x914, bMaskByte0, 1); 128 phy_set_bb_reg(adapter, 0x914, bMaskByte1, 2);
129 phy_set_bb_reg(adapter, 0x914, bMaskByte1, 2);
130 }
131 } else if (AntCombination == 7) {
132 if (!dm_odm->bIsMPChip) { /* testchip */
133 phy_set_bb_reg(adapter, 0x858, BIT(10) | BIT(9) | BIT(8), 0);
134 phy_set_bb_reg(adapter, 0x858, BIT(13) | BIT(12) | BIT(11), 1);
135 phy_set_bb_reg(adapter, 0x878, BIT(16), 0);
136 phy_set_bb_reg(adapter, 0x858, BIT(15) | BIT(14), 2);
137 phy_set_bb_reg(adapter, 0x878, BIT(19) | BIT(18) | BIT(17), 3);
138 phy_set_bb_reg(adapter, 0x878, BIT(22) | BIT(21) | BIT(20), 4);
139 phy_set_bb_reg(adapter, 0x878, BIT(25) | BIT(24) | BIT(23), 5);
140 phy_set_bb_reg(adapter, 0x878, BIT(28) | BIT(27) | BIT(26), 6);
141 phy_set_bb_reg(adapter, 0x878, BIT(31) | BIT(30) | BIT(29), 7);
142 } else { /* MPchip */
143 phy_set_bb_reg(adapter, 0x914, bMaskByte0, 0);
144 phy_set_bb_reg(adapter, 0x914, bMaskByte1, 1);
145 phy_set_bb_reg(adapter, 0x914, bMaskByte2, 2);
146 phy_set_bb_reg(adapter, 0x914, bMaskByte3, 3);
147 phy_set_bb_reg(adapter, 0x918, bMaskByte0, 4);
148 phy_set_bb_reg(adapter, 0x918, bMaskByte1, 5);
149 phy_set_bb_reg(adapter, 0x918, bMaskByte2, 6);
150 phy_set_bb_reg(adapter, 0x918, bMaskByte3, 7);
151 }
152 } 129 }
153 130
154 /* Default Ant Setting when no fast training */ 131 /* Default Ant Setting when no fast training */
@@ -157,7 +134,7 @@ static void dm_fast_training_init(struct odm_dm_struct *dm_odm)
157 phy_set_bb_reg(adapter, 0x864, BIT(8) | BIT(7) | BIT(6), 1); 134 phy_set_bb_reg(adapter, 0x864, BIT(8) | BIT(7) | BIT(6), 1);
158 135
159 /* Enter Traing state */ 136 /* Enter Traing state */
160 phy_set_bb_reg(adapter, 0x864, BIT(2) | BIT(1) | BIT(0), (AntCombination-1)); 137 phy_set_bb_reg(adapter, 0x864, BIT(2) | BIT(1) | BIT(0), 1);
161 phy_set_bb_reg(adapter, 0xc50, BIT(7), 1); 138 phy_set_bb_reg(adapter, 0xc50, BIT(7), 1);
162} 139}
163 140
@@ -219,8 +196,8 @@ static void update_tx_ant_88eu(struct odm_dm_struct *dm_odm, u8 ant, u32 mac_id)
219 else 196 else
220 target_ant = AUX_ANT_CG_TRX; 197 target_ant = AUX_ANT_CG_TRX;
221 dm_fat_tbl->antsel_a[mac_id] = target_ant & BIT(0); 198 dm_fat_tbl->antsel_a[mac_id] = target_ant & BIT(0);
222 dm_fat_tbl->antsel_b[mac_id] = (target_ant & BIT(1))>>1; 199 dm_fat_tbl->antsel_b[mac_id] = (target_ant & BIT(1)) >> 1;
223 dm_fat_tbl->antsel_c[mac_id] = (target_ant & BIT(2))>>2; 200 dm_fat_tbl->antsel_c[mac_id] = (target_ant & BIT(2)) >> 2;
224} 201}
225 202
226void rtl88eu_dm_set_tx_ant_by_tx_info(struct odm_dm_struct *dm_odm, 203void rtl88eu_dm_set_tx_ant_by_tx_info(struct odm_dm_struct *dm_odm,
@@ -273,11 +250,13 @@ static void rtl88eu_dm_hw_ant_div(struct odm_dm_struct *dm_odm)
273 for (i = 0; i < ODM_ASSOCIATE_ENTRY_NUM; i++) { 250 for (i = 0; i < ODM_ASSOCIATE_ENTRY_NUM; i++) {
274 entry = dm_odm->pODM_StaInfo[i]; 251 entry = dm_odm->pODM_StaInfo[i];
275 if (IS_STA_VALID(entry)) { 252 if (IS_STA_VALID(entry)) {
276 /* 2 Caculate RSSI per Antenna */ 253 /* 2 Calculate RSSI per Antenna */
277 main_rssi = (dm_fat_tbl->MainAnt_Cnt[i] != 0) ? 254 main_rssi = (dm_fat_tbl->MainAnt_Cnt[i] != 0) ?
278 (dm_fat_tbl->MainAnt_Sum[i]/dm_fat_tbl->MainAnt_Cnt[i]) : 0; 255 (dm_fat_tbl->MainAnt_Sum[i] /
256 dm_fat_tbl->MainAnt_Cnt[i]) : 0;
279 aux_rssi = (dm_fat_tbl->AuxAnt_Cnt[i] != 0) ? 257 aux_rssi = (dm_fat_tbl->AuxAnt_Cnt[i] != 0) ?
280 (dm_fat_tbl->AuxAnt_Sum[i]/dm_fat_tbl->AuxAnt_Cnt[i]) : 0; 258 (dm_fat_tbl->AuxAnt_Sum[i] /
259 dm_fat_tbl->AuxAnt_Cnt[i]) : 0;
281 target_ant = (main_rssi >= aux_rssi) ? MAIN_ANT : AUX_ANT; 260 target_ant = (main_rssi >= aux_rssi) ? MAIN_ANT : AUX_ANT;
282 /* 2 Select max_rssi for DIG */ 261 /* 2 Select max_rssi for DIG */
283 local_max_rssi = max(main_rssi, aux_rssi); 262 local_max_rssi = max(main_rssi, aux_rssi);
diff --git a/drivers/staging/rtl8188eu/hal/phy.c b/drivers/staging/rtl8188eu/hal/phy.c
index 3c7cf8720df8..482d48e003b7 100644
--- a/drivers/staging/rtl8188eu/hal/phy.c
+++ b/drivers/staging/rtl8188eu/hal/phy.c
@@ -298,25 +298,6 @@ void rtw_hal_set_chan(struct adapter *adapt, u8 channel)
298 298
299#define ODM_TXPWRTRACK_MAX_IDX_88E 6 299#define ODM_TXPWRTRACK_MAX_IDX_88E 6
300 300
301static u8 get_right_chnl_for_iqk(u8 chnl)
302{
303 u8 place;
304 u8 channel_all[ODM_TARGET_CHNL_NUM_2G_5G] = {
305 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64,
306 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122,
307 124, 126, 128, 130, 132, 134, 136, 138, 140, 149, 151, 153,
308 155, 157, 159, 161, 163, 165
309 };
310
311 if (chnl > 14) {
312 for (place = 0; place < sizeof(channel_all); place++) {
313 if (channel_all[place] == chnl)
314 return ++place;
315 }
316 }
317 return 0;
318}
319
320void rtl88eu_dm_txpower_track_adjust(struct odm_dm_struct *dm_odm, u8 type, 301void rtl88eu_dm_txpower_track_adjust(struct odm_dm_struct *dm_odm, u8 type,
321 u8 *direction, u32 *out_write_val) 302 u8 *direction, u32 *out_write_val)
322{ 303{
@@ -1215,7 +1196,7 @@ void rtl88eu_phy_iq_calibrate(struct adapter *adapt, bool recovery)
1215{ 1196{
1216 struct odm_dm_struct *dm_odm = &adapt->HalData->odmpriv; 1197 struct odm_dm_struct *dm_odm = &adapt->HalData->odmpriv;
1217 s32 result[4][8]; 1198 s32 result[4][8];
1218 u8 i, final, chn_index; 1199 u8 i, final;
1219 bool pathaok, pathbok; 1200 bool pathaok, pathbok;
1220 s32 reg_e94, reg_e9c, reg_ea4, reg_eb4, reg_ebc, reg_ec4; 1201 s32 reg_e94, reg_e9c, reg_ea4, reg_eb4, reg_ebc, reg_ec4;
1221 bool is12simular, is13simular, is23simular; 1202 bool is12simular, is13simular, is23simular;
@@ -1324,12 +1305,10 @@ void rtl88eu_phy_iq_calibrate(struct adapter *adapt, bool recovery)
1324 (reg_ec4 == 0)); 1305 (reg_ec4 == 0));
1325 } 1306 }
1326 1307
1327 chn_index = get_right_chnl_for_iqk(adapt->HalData->CurrentChannel);
1328
1329 if (final < 4) { 1308 if (final < 4) {
1330 for (i = 0; i < IQK_Matrix_REG_NUM; i++) 1309 for (i = 0; i < IQK_Matrix_REG_NUM; i++)
1331 dm_odm->RFCalibrateInfo.IQKMatrixRegSetting[chn_index].Value[0][i] = result[final][i]; 1310 dm_odm->RFCalibrateInfo.IQKMatrixRegSetting[0].Value[0][i] = result[final][i];
1332 dm_odm->RFCalibrateInfo.IQKMatrixRegSetting[chn_index].bIQKDone = true; 1311 dm_odm->RFCalibrateInfo.IQKMatrixRegSetting[0].bIQKDone = true;
1333 } 1312 }
1334 1313
1335 save_adda_registers(adapt, iqk_bb_reg_92c, 1314 save_adda_registers(adapt, iqk_bb_reg_92c,
diff --git a/drivers/staging/rtl8188eu/hal/pwrseq.c b/drivers/staging/rtl8188eu/hal/pwrseq.c
index 4aa1dec0b5e4..f7890a8f4673 100644
--- a/drivers/staging/rtl8188eu/hal/pwrseq.c
+++ b/drivers/staging/rtl8188eu/hal/pwrseq.c
@@ -8,9 +8,8 @@
8#include "pwrseq.h" 8#include "pwrseq.h"
9#include <rtl8188e_hal.h> 9#include <rtl8188e_hal.h>
10 10
11/* 11/* drivers should parse below arrays and do the corresponding actions */
12 drivers should parse below arrays and do the corresponding actions 12
13*/
14/* 3 Power on Array */ 13/* 3 Power on Array */
15struct wl_pwr_cfg rtl8188E_power_on_flow[RTL8188E_TRANS_CARDEMU_TO_ACT_STEPS + 14struct wl_pwr_cfg rtl8188E_power_on_flow[RTL8188E_TRANS_CARDEMU_TO_ACT_STEPS +
16 RTL8188E_TRANS_END_STEPS] = { 15 RTL8188E_TRANS_END_STEPS] = {
diff --git a/drivers/staging/rtl8188eu/hal/rf_cfg.c b/drivers/staging/rtl8188eu/hal/rf_cfg.c
index 0700d8bd448d..02aeb12c9870 100644
--- a/drivers/staging/rtl8188eu/hal/rf_cfg.c
+++ b/drivers/staging/rtl8188eu/hal/rf_cfg.c
@@ -177,7 +177,7 @@ static void rtl8188e_config_rf_reg(struct adapter *adapt,
177 u32 content = 0x1000; /*RF Content: radio_a_txt*/ 177 u32 content = 0x1000; /*RF Content: radio_a_txt*/
178 u32 maskforphyset = content & 0xE000; 178 u32 maskforphyset = content & 0xE000;
179 179
180 rtl_rfreg_delay(adapt, RF90_PATH_A, addr | maskforphyset, 180 rtl_rfreg_delay(adapt, RF_PATH_A, addr | maskforphyset,
181 RFREG_OFFSET_MASK, 181 RFREG_OFFSET_MASK,
182 data); 182 data);
183} 183}
diff --git a/drivers/staging/rtl8188eu/hal/rtl8188e_hal_init.c b/drivers/staging/rtl8188eu/hal/rtl8188e_hal_init.c
index 607170775fa5..31e80d693f32 100644
--- a/drivers/staging/rtl8188eu/hal/rtl8188e_hal_init.c
+++ b/drivers/staging/rtl8188eu/hal/rtl8188e_hal_init.c
@@ -240,8 +240,7 @@ s32 InitLLTTable(struct adapter *padapter, u8 txpktbuf_bndy)
240 return status; 240 return status;
241} 241}
242 242
243void 243void Hal_InitPGData88E(struct adapter *padapter)
244Hal_InitPGData88E(struct adapter *padapter)
245{ 244{
246 struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter); 245 struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
247 246
@@ -258,11 +257,7 @@ Hal_InitPGData88E(struct adapter *padapter)
258 } 257 }
259} 258}
260 259
261void 260void Hal_EfuseParseIDCode88E(struct adapter *padapter, u8 *hwinfo)
262Hal_EfuseParseIDCode88E(
263 struct adapter *padapter,
264 u8 *hwinfo
265 )
266{ 261{
267 struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter); 262 struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
268 u16 EEPROMId; 263 u16 EEPROMId;
@@ -378,58 +373,20 @@ static void Hal_ReadPowerValueFromPROM_8188E(struct txpowerinfo24g *pwrInfo24G,
378 } 373 }
379} 374}
380 375
381static u8 Hal_GetChnlGroup88E(u8 chnl, u8 *pGroup) 376static void Hal_GetChnlGroup88E(u8 chnl, u8 *group)
382{ 377{
383 u8 bIn24G = true; 378 if (chnl < 3) /* Channel 1-2 */
384 379 *group = 0;
385 if (chnl <= 14) { 380 else if (chnl < 6) /* Channel 3-5 */
386 bIn24G = true; 381 *group = 1;
387 382 else if (chnl < 9) /* Channel 6-8 */
388 if (chnl < 3) /* Channel 1-2 */ 383 *group = 2;
389 *pGroup = 0; 384 else if (chnl < 12) /* Channel 9-11 */
390 else if (chnl < 6) /* Channel 3-5 */ 385 *group = 3;
391 *pGroup = 1; 386 else if (chnl < 14) /* Channel 12-13 */
392 else if (chnl < 9) /* Channel 6-8 */ 387 *group = 4;
393 *pGroup = 2; 388 else if (chnl == 14) /* Channel 14 */
394 else if (chnl < 12) /* Channel 9-11 */ 389 *group = 5;
395 *pGroup = 3;
396 else if (chnl < 14) /* Channel 12-13 */
397 *pGroup = 4;
398 else if (chnl == 14) /* Channel 14 */
399 *pGroup = 5;
400 } else {
401 /* probably, this branch is suitable only for 5 GHz */
402
403 bIn24G = false;
404
405 if (chnl <= 40)
406 *pGroup = 0;
407 else if (chnl <= 48)
408 *pGroup = 1;
409 else if (chnl <= 56)
410 *pGroup = 2;
411 else if (chnl <= 64)
412 *pGroup = 3;
413 else if (chnl <= 104)
414 *pGroup = 4;
415 else if (chnl <= 112)
416 *pGroup = 5;
417 else if (chnl <= 120)
418 *pGroup = 5;
419 else if (chnl <= 128)
420 *pGroup = 6;
421 else if (chnl <= 136)
422 *pGroup = 7;
423 else if (chnl <= 144)
424 *pGroup = 8;
425 else if (chnl <= 153)
426 *pGroup = 9;
427 else if (chnl <= 161)
428 *pGroup = 10;
429 else if (chnl <= 177)
430 *pGroup = 11;
431 }
432 return bIn24G;
433} 390}
434 391
435void Hal_ReadPowerSavingMode88E(struct adapter *padapter, u8 *hwinfo, bool AutoLoadFail) 392void Hal_ReadPowerSavingMode88E(struct adapter *padapter, u8 *hwinfo, bool AutoLoadFail)
@@ -461,7 +418,7 @@ void Hal_ReadTxPowerInfo88E(struct adapter *padapter, u8 *PROMContent, bool Auto
461 struct hal_data_8188e *pHalData = padapter->HalData; 418 struct hal_data_8188e *pHalData = padapter->HalData;
462 struct txpowerinfo24g pwrInfo24G; 419 struct txpowerinfo24g pwrInfo24G;
463 u8 ch, group; 420 u8 ch, group;
464 u8 bIn24G, TxCount; 421 u8 TxCount;
465 422
466 Hal_ReadPowerValueFromPROM_8188E(&pwrInfo24G, PROMContent, AutoLoadFail); 423 Hal_ReadPowerValueFromPROM_8188E(&pwrInfo24G, PROMContent, AutoLoadFail);
467 424
@@ -469,19 +426,16 @@ void Hal_ReadTxPowerInfo88E(struct adapter *padapter, u8 *PROMContent, bool Auto
469 pHalData->bTXPowerDataReadFromEEPORM = true; 426 pHalData->bTXPowerDataReadFromEEPORM = true;
470 427
471 for (ch = 0; ch < CHANNEL_MAX_NUMBER; ch++) { 428 for (ch = 0; ch < CHANNEL_MAX_NUMBER; ch++) {
472 bIn24G = Hal_GetChnlGroup88E(ch, &group); 429 Hal_GetChnlGroup88E(ch, &group);
473 if (bIn24G) { 430 pHalData->Index24G_CCK_Base[0][ch] = pwrInfo24G.IndexCCK_Base[0][group];
474 pHalData->Index24G_CCK_Base[0][ch] = pwrInfo24G.IndexCCK_Base[0][group]; 431 if (ch == 14)
475 if (ch == 14) 432 pHalData->Index24G_BW40_Base[0][ch] = pwrInfo24G.IndexBW40_Base[0][4];
476 pHalData->Index24G_BW40_Base[0][ch] = pwrInfo24G.IndexBW40_Base[0][4]; 433 else
477 else 434 pHalData->Index24G_BW40_Base[0][ch] = pwrInfo24G.IndexBW40_Base[0][group];
478 pHalData->Index24G_BW40_Base[0][ch] = pwrInfo24G.IndexBW40_Base[0][group]; 435
479 } 436 DBG_88E("======= Path %d, Channel %d =======\n", 0, ch);
480 if (bIn24G) { 437 DBG_88E("Index24G_CCK_Base[%d][%d] = 0x%x\n", 0, ch, pHalData->Index24G_CCK_Base[0][ch]);
481 DBG_88E("======= Path %d, Channel %d =======\n", 0, ch); 438 DBG_88E("Index24G_BW40_Base[%d][%d] = 0x%x\n", 0, ch, pHalData->Index24G_BW40_Base[0][ch]);
482 DBG_88E("Index24G_CCK_Base[%d][%d] = 0x%x\n", 0, ch, pHalData->Index24G_CCK_Base[0][ch]);
483 DBG_88E("Index24G_BW40_Base[%d][%d] = 0x%x\n", 0, ch, pHalData->Index24G_BW40_Base[0][ch]);
484 }
485 } 439 }
486 for (TxCount = 0; TxCount < MAX_TX_COUNT; TxCount++) { 440 for (TxCount = 0; TxCount < MAX_TX_COUNT; TxCount++) {
487 pHalData->CCK_24G_Diff[0][TxCount] = pwrInfo24G.CCK_Diff[0][TxCount]; 441 pHalData->CCK_24G_Diff[0][TxCount] = pwrInfo24G.CCK_Diff[0][TxCount];
@@ -551,8 +505,7 @@ void Hal_EfuseParseEEPROMVer88E(struct adapter *padapter, u8 *hwinfo, bool AutoL
551void rtl8188e_EfuseParseChnlPlan(struct adapter *padapter, u8 *hwinfo, bool AutoLoadFail) 505void rtl8188e_EfuseParseChnlPlan(struct adapter *padapter, u8 *hwinfo, bool AutoLoadFail)
552{ 506{
553 padapter->mlmepriv.ChannelPlan = 507 padapter->mlmepriv.ChannelPlan =
554 hal_com_get_channel_plan(padapter, 508 hal_com_get_channel_plan(hwinfo ? hwinfo[EEPROM_ChannelPlan_88E] : 0xFF,
555 hwinfo ? hwinfo[EEPROM_ChannelPlan_88E] : 0xFF,
556 padapter->registrypriv.channel_plan, 509 padapter->registrypriv.channel_plan,
557 RT_CHANNEL_DOMAIN_WORLD_WIDE_13, AutoLoadFail); 510 RT_CHANNEL_DOMAIN_WORLD_WIDE_13, AutoLoadFail);
558 511
diff --git a/drivers/staging/rtl8188eu/hal/usb_halinit.c b/drivers/staging/rtl8188eu/hal/usb_halinit.c
index 12864b648fa8..70c02c49b177 100644
--- a/drivers/staging/rtl8188eu/hal/usb_halinit.c
+++ b/drivers/staging/rtl8188eu/hal/usb_halinit.c
@@ -52,7 +52,7 @@ static bool HalUsbSetQueuePipeMapping8188EUsb(struct adapter *adapt, u8 NumInPip
52 52
53 /* All config other than above support one Bulk IN and one Interrupt IN. */ 53 /* All config other than above support one Bulk IN and one Interrupt IN. */
54 54
55 result = Hal_MappingOutPipe(adapt, NumOutPipe); 55 result = hal_mapping_out_pipe(adapt, NumOutPipe);
56 56
57 return result; 57 return result;
58} 58}
@@ -785,13 +785,13 @@ u32 rtl8188eu_hal_init(struct adapter *Adapter)
785 haldata->RfRegChnlVal[0] = rtw_hal_read_rfreg(Adapter, (enum rf_radio_path)0, RF_CHNLBW, bRFRegOffsetMask); 785 haldata->RfRegChnlVal[0] = rtw_hal_read_rfreg(Adapter, (enum rf_radio_path)0, RF_CHNLBW, bRFRegOffsetMask);
786 haldata->RfRegChnlVal[1] = rtw_hal_read_rfreg(Adapter, (enum rf_radio_path)1, RF_CHNLBW, bRFRegOffsetMask); 786 haldata->RfRegChnlVal[1] = rtw_hal_read_rfreg(Adapter, (enum rf_radio_path)1, RF_CHNLBW, bRFRegOffsetMask);
787 787
788HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_TURN_ON_BLOCK); 788 HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_TURN_ON_BLOCK);
789 _BBTurnOnBlock(Adapter); 789 _BBTurnOnBlock(Adapter);
790 790
791HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_INIT_SECURITY); 791 HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_INIT_SECURITY);
792 invalidate_cam_all(Adapter); 792 invalidate_cam_all(Adapter);
793 793
794HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_MISC11); 794 HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_MISC11);
795 /* 2010/12/17 MH We need to set TX power according to EFUSE content at first. */ 795 /* 2010/12/17 MH We need to set TX power according to EFUSE content at first. */
796 phy_set_tx_power_level(Adapter, haldata->CurrentChannel); 796 phy_set_tx_power_level(Adapter, haldata->CurrentChannel);
797 797
@@ -816,7 +816,7 @@ HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_MISC11);
816 /* Nav limit , suggest by scott */ 816 /* Nav limit , suggest by scott */
817 usb_write8(Adapter, 0x652, 0x0); 817 usb_write8(Adapter, 0x652, 0x0);
818 818
819HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_INIT_HAL_DM); 819 HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_INIT_HAL_DM);
820 rtl8188e_InitHalDm(Adapter); 820 rtl8188e_InitHalDm(Adapter);
821 821
822 /* 2010/08/11 MH Merge from 8192SE for Minicard init. We need to confirm current radio status */ 822 /* 2010/08/11 MH Merge from 8192SE for Minicard init. We need to confirm current radio status */
@@ -840,8 +840,8 @@ HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_INIT_HAL_DM);
840 /* enable tx DMA to drop the redundate data of packet */ 840 /* enable tx DMA to drop the redundate data of packet */
841 usb_write16(Adapter, REG_TXDMA_OFFSET_CHK, (usb_read16(Adapter, REG_TXDMA_OFFSET_CHK) | DROP_DATA_EN)); 841 usb_write16(Adapter, REG_TXDMA_OFFSET_CHK, (usb_read16(Adapter, REG_TXDMA_OFFSET_CHK) | DROP_DATA_EN));
842 842
843HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_IQK); 843 HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_IQK);
844 /* 2010/08/26 MH Merge from 8192CE. */ 844 /* 2010/08/26 MH Merge from 8192CE. */
845 if (pwrctrlpriv->rf_pwrstate == rf_on) { 845 if (pwrctrlpriv->rf_pwrstate == rf_on) {
846 if (haldata->odmpriv.RFCalibrateInfo.bIQKInitialized) { 846 if (haldata->odmpriv.RFCalibrateInfo.bIQKInitialized) {
847 rtl88eu_phy_iq_calibrate(Adapter, true); 847 rtl88eu_phy_iq_calibrate(Adapter, true);
@@ -850,12 +850,12 @@ HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_IQK);
850 haldata->odmpriv.RFCalibrateInfo.bIQKInitialized = true; 850 haldata->odmpriv.RFCalibrateInfo.bIQKInitialized = true;
851 } 851 }
852 852
853HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_PW_TRACK); 853 HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_PW_TRACK);
854 854
855 ODM_TXPowerTrackingCheck(&haldata->odmpriv); 855 ODM_TXPowerTrackingCheck(&haldata->odmpriv);
856 856
857HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_LCK); 857 HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_LCK);
858 rtl88eu_phy_lc_calibrate(Adapter); 858 rtl88eu_phy_lc_calibrate(Adapter);
859 } 859 }
860 860
861/* HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_INIT_PABIAS); */ 861/* HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_INIT_PABIAS); */
@@ -866,7 +866,7 @@ HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_LCK);
866 usb_write32(Adapter, REG_FWHW_TXQ_CTRL, usb_read32(Adapter, REG_FWHW_TXQ_CTRL) | BIT(12)); 866 usb_write32(Adapter, REG_FWHW_TXQ_CTRL, usb_read32(Adapter, REG_FWHW_TXQ_CTRL) | BIT(12));
867 867
868exit: 868exit:
869HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_END); 869 HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_END);
870 870
871 DBG_88E("%s in %dms\n", __func__, 871 DBG_88E("%s in %dms\n", __func__,
872 jiffies_to_msecs(jiffies - init_start_time)); 872 jiffies_to_msecs(jiffies - init_start_time));
@@ -980,7 +980,7 @@ u32 rtw_hal_inirp_init(struct adapter *Adapter)
980 /* issue Rx irp to receive data */ 980 /* issue Rx irp to receive data */
981 precvbuf = precvpriv->precv_buf; 981 precvbuf = precvpriv->precv_buf;
982 for (i = 0; i < NR_RECVBUFF; i++) { 982 for (i = 0; i < NR_RECVBUFF; i++) {
983 if (usb_read_port(Adapter, RECV_BULK_IN_ADDR, precvbuf) == false) { 983 if (!usb_read_port(Adapter, RECV_BULK_IN_ADDR, precvbuf)) {
984 RT_TRACE(_module_hci_hal_init_c_, _drv_err_, ("usb_rx_init: usb_read_port error\n")); 984 RT_TRACE(_module_hci_hal_init_c_, _drv_err_, ("usb_rx_init: usb_read_port error\n"));
985 status = _FAIL; 985 status = _FAIL;
986 goto exit; 986 goto exit;
@@ -1267,7 +1267,7 @@ void rtw_hal_set_hwreg(struct adapter *Adapter, u8 variable, u8 *val)
1267 /* Select RRSR (in Legacy-OFDM and CCK) */ 1267 /* Select RRSR (in Legacy-OFDM and CCK) */
1268 /* For 8190, we select only 24M, 12M, 6M, 11M, 5.5M, 2M, and 1M from the Basic rate. */ 1268 /* For 8190, we select only 24M, 12M, 6M, 11M, 5.5M, 2M, and 1M from the Basic rate. */
1269 /* We do not use other rates. */ 1269 /* We do not use other rates. */
1270 HalSetBrateCfg(Adapter, val, &BrateCfg); 1270 hal_set_brate_cfg(val, &BrateCfg);
1271 DBG_88E("HW_VAR_BASIC_RATE: BrateCfg(%#x)\n", BrateCfg); 1271 DBG_88E("HW_VAR_BASIC_RATE: BrateCfg(%#x)\n", BrateCfg);
1272 1272
1273 /* 2011.03.30 add by Luke Lee */ 1273 /* 2011.03.30 add by Luke Lee */
diff --git a/drivers/staging/rtl8188eu/include/drv_types.h b/drivers/staging/rtl8188eu/include/drv_types.h
index 4ae095837bef..35c0946bc65d 100644
--- a/drivers/staging/rtl8188eu/include/drv_types.h
+++ b/drivers/staging/rtl8188eu/include/drv_types.h
@@ -24,11 +24,16 @@
24#include <rtw_recv.h> 24#include <rtw_recv.h>
25#include <hal_intf.h> 25#include <hal_intf.h>
26#include <hal_com.h> 26#include <hal_com.h>
27#include <rtw_qos.h>
28#include <rtw_security.h> 27#include <rtw_security.h>
29#include <rtw_pwrctrl.h> 28#include <rtw_pwrctrl.h>
30#include <rtw_eeprom.h> 29#include <rtw_eeprom.h>
31#include <sta_info.h> 30#include <sta_info.h>
31
32struct qos_priv {
33 /* bit mask option: u-apsd, s-apsd, ts, block ack... */
34 unsigned int qos_option;
35};
36
32#include <rtw_mlme.h> 37#include <rtw_mlme.h>
33#include <rtw_debug.h> 38#include <rtw_debug.h>
34#include <rtw_rf.h> 39#include <rtw_rf.h>
diff --git a/drivers/staging/rtl8188eu/include/hal_com.h b/drivers/staging/rtl8188eu/include/hal_com.h
index 428a2a92820e..2f7bdade40a5 100644
--- a/drivers/staging/rtl8188eu/include/hal_com.h
+++ b/drivers/staging/rtl8188eu/include/hal_com.h
@@ -139,18 +139,14 @@ void dump_chip_info(struct HAL_VERSION ChipVersion);
139 139
140 140
141/* return the final channel plan decision */ 141/* return the final channel plan decision */
142u8 hal_com_get_channel_plan(struct adapter *padapter, 142u8 hal_com_get_channel_plan(u8 hw_channel_plan, u8 sw_channel_plan,
143 u8 hw_channel_plan, 143 u8 def_channel_plan, bool load_fail);
144 u8 sw_channel_plan,
145 u8 def_channel_plan,
146 bool AutoLoadFail
147);
148 144
149u8 MRateToHwRate(u8 rate); 145u8 MRateToHwRate(u8 rate);
150 146
151void HalSetBrateCfg(struct adapter *Adapter, u8 *mBratesOS, u16 *pBrateCfg); 147void hal_set_brate_cfg(u8 *brates, u16 *rate_cfg);
152 148
153bool Hal_MappingOutPipe(struct adapter *pAdapter, u8 NumOutPipe); 149bool hal_mapping_out_pipe(struct adapter *adapter, u8 numoutpipe);
154 150
155void hal_init_macaddr(struct adapter *adapter); 151void hal_init_macaddr(struct adapter *adapter);
156#endif /* __HAL_COMMON_H__ */ 152#endif /* __HAL_COMMON_H__ */
diff --git a/drivers/staging/rtl8188eu/include/odm_HWConfig.h b/drivers/staging/rtl8188eu/include/odm_hwconfig.h
index 8cef32dc6350..8cef32dc6350 100644
--- a/drivers/staging/rtl8188eu/include/odm_HWConfig.h
+++ b/drivers/staging/rtl8188eu/include/odm_hwconfig.h
diff --git a/drivers/staging/rtl8188eu/include/odm_precomp.h b/drivers/staging/rtl8188eu/include/odm_precomp.h
index 658a938df4c1..6efddc8f1675 100644
--- a/drivers/staging/rtl8188eu/include/odm_precomp.h
+++ b/drivers/staging/rtl8188eu/include/odm_precomp.h
@@ -22,14 +22,14 @@
22/* 2 OutSrc Header Files */ 22/* 2 OutSrc Header Files */
23 23
24#include "odm.h" 24#include "odm.h"
25#include "odm_HWConfig.h" 25#include "odm_hwconfig.h"
26#include "odm_debug.h" 26#include "odm_debug.h"
27#include "../../rtlwifi/phydm/phydm_regdefine11n.h" 27#include "../../rtlwifi/phydm/phydm_regdefine11n.h"
28 28
29#include "hal8188e_rate_adaptive.h" /* for RA,Power training */ 29#include "hal8188e_rate_adaptive.h" /* for RA,Power training */
30#include "rtl8188e_hal.h" 30#include "rtl8188e_hal.h"
31 31
32#include "odm_reg.h" 32#include "../../rtlwifi/phydm/phydm_reg.h"
33 33
34#include "odm_rtl8188e.h" 34#include "odm_rtl8188e.h"
35 35
diff --git a/drivers/staging/rtl8188eu/include/odm_reg.h b/drivers/staging/rtl8188eu/include/odm_reg.h
deleted file mode 100644
index b56549ba1256..000000000000
--- a/drivers/staging/rtl8188eu/include/odm_reg.h
+++ /dev/null
@@ -1,106 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/******************************************************************************
3 *
4 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5 *
6 ******************************************************************************/
7/* */
8/* File Name: odm_reg.h */
9/* */
10/* Description: */
11/* */
12/* This file is for general register definition. */
13/* */
14/* */
15/* */
16#ifndef __HAL_ODM_REG_H__
17#define __HAL_ODM_REG_H__
18
19/* */
20/* Register Definition */
21/* */
22
23/* MAC REG */
24#define ODM_BB_RESET 0x002
25#define ODM_DUMMY 0x4fe
26#define ODM_EDCA_VO_PARAM 0x500
27#define ODM_EDCA_VI_PARAM 0x504
28#define ODM_EDCA_BE_PARAM 0x508
29#define ODM_EDCA_BK_PARAM 0x50C
30#define ODM_TXPAUSE 0x522
31
32/* BB REG */
33#define ODM_FPGA_PHY0_PAGE8 0x800
34#define ODM_PSD_SETTING 0x808
35#define ODM_AFE_SETTING 0x818
36#define ODM_TXAGC_B_6_18 0x830
37#define ODM_TXAGC_B_24_54 0x834
38#define ODM_TXAGC_B_MCS32_5 0x838
39#define ODM_TXAGC_B_MCS0_MCS3 0x83c
40#define ODM_TXAGC_B_MCS4_MCS7 0x848
41#define ODM_TXAGC_B_MCS8_MCS11 0x84c
42#define ODM_ANALOG_REGISTER 0x85c
43#define ODM_RF_INTERFACE_OUTPUT 0x860
44#define ODM_TXAGC_B_MCS12_MCS15 0x868
45#define ODM_TXAGC_B_11_A_2_11 0x86c
46#define ODM_AD_DA_LSB_MASK 0x874
47#define ODM_ENABLE_3_WIRE 0x88c
48#define ODM_PSD_REPORT 0x8b4
49#define ODM_R_ANT_SELECT 0x90c
50#define ODM_CCK_ANT_SELECT 0xa07
51#define ODM_CCK_PD_THRESH 0xa0a
52#define ODM_CCK_RF_REG1 0xa11
53#define ODM_CCK_MATCH_FILTER 0xa20
54#define ODM_CCK_RAKE_MAC 0xa2e
55#define ODM_CCK_CNT_RESET 0xa2d
56#define ODM_CCK_TX_DIVERSITY 0xa2f
57#define ODM_CCK_FA_CNT_MSB 0xa5b
58#define ODM_CCK_FA_CNT_LSB 0xa5c
59#define ODM_CCK_NEW_FUNCTION 0xa75
60#define ODM_OFDM_PHY0_PAGE_C 0xc00
61#define ODM_OFDM_RX_ANT 0xc04
62#define ODM_R_A_RXIQI 0xc14
63#define ODM_R_A_AGC_CORE1 0xc50
64#define ODM_R_A_AGC_CORE2 0xc54
65#define ODM_R_B_AGC_CORE1 0xc58
66#define ODM_R_AGC_PAR 0xc70
67#define ODM_R_HTSTF_AGC_PAR 0xc7c
68#define ODM_TX_PWR_TRAINING_A 0xc90
69#define ODM_TX_PWR_TRAINING_B 0xc98
70#define ODM_OFDM_FA_CNT1 0xcf0
71#define ODM_OFDM_PHY0_PAGE_D 0xd00
72#define ODM_OFDM_FA_CNT2 0xda0
73#define ODM_OFDM_FA_CNT3 0xda4
74#define ODM_OFDM_FA_CNT4 0xda8
75#define ODM_TXAGC_A_6_18 0xe00
76#define ODM_TXAGC_A_24_54 0xe04
77#define ODM_TXAGC_A_1_MCS32 0xe08
78#define ODM_TXAGC_A_MCS0_MCS3 0xe10
79#define ODM_TXAGC_A_MCS4_MCS7 0xe14
80#define ODM_TXAGC_A_MCS8_MCS11 0xe18
81#define ODM_TXAGC_A_MCS12_MCS15 0xe1c
82
83/* RF REG */
84#define ODM_GAIN_SETTING 0x00
85#define ODM_CHANNEL 0x18
86
87/* Ant Detect Reg */
88#define ODM_DPDT 0x300
89
90/* PSD Init */
91#define ODM_PSDREG 0x808
92
93/* 92D Path Div */
94#define PATHDIV_REG 0xB30
95#define PATHDIV_TRI 0xBA0
96
97
98/* */
99/* Bitmap Definition */
100/* */
101
102#define BIT_FA_RESET BIT(0)
103
104
105
106#endif
diff --git a/drivers/staging/rtl8188eu/include/osdep_service.h b/drivers/staging/rtl8188eu/include/osdep_service.h
index fbcba79a0927..cfe5698fbbb1 100644
--- a/drivers/staging/rtl8188eu/include/osdep_service.h
+++ b/drivers/staging/rtl8188eu/include/osdep_service.h
@@ -64,8 +64,6 @@ static inline int rtw_netif_queue_stopped(struct net_device *pnetdev)
64u8 *_rtw_malloc(u32 sz); 64u8 *_rtw_malloc(u32 sz);
65#define rtw_malloc(sz) _rtw_malloc((sz)) 65#define rtw_malloc(sz) _rtw_malloc((sz))
66 66
67void *rtw_malloc2d(int h, int w, int size);
68
69void _rtw_init_queue(struct __queue *pqueue); 67void _rtw_init_queue(struct __queue *pqueue);
70 68
71struct rtw_netdev_priv_indicator { 69struct rtw_netdev_priv_indicator {
diff --git a/drivers/staging/rtl8188eu/include/phy.h b/drivers/staging/rtl8188eu/include/phy.h
index e99ac3910787..40901d6dcaf5 100644
--- a/drivers/staging/rtl8188eu/include/phy.h
+++ b/drivers/staging/rtl8188eu/include/phy.h
@@ -4,7 +4,6 @@
4#define IQK_DELAY_TIME_88E 10 4#define IQK_DELAY_TIME_88E 10
5#define index_mapping_NUM_88E 15 5#define index_mapping_NUM_88E 15
6#define AVG_THERMAL_NUM_88E 4 6#define AVG_THERMAL_NUM_88E 4
7#define ODM_TARGET_CHNL_NUM_2G_5G 59
8 7
9bool rtl88eu_phy_mac_config(struct adapter *adapt); 8bool rtl88eu_phy_mac_config(struct adapter *adapt);
10bool rtl88eu_phy_rf_config(struct adapter *adapt); 9bool rtl88eu_phy_rf_config(struct adapter *adapt);
diff --git a/drivers/staging/rtl8188eu/include/rtw_mlme.h b/drivers/staging/rtl8188eu/include/rtw_mlme.h
index 35997c521c35..8d9d663f0645 100644
--- a/drivers/staging/rtl8188eu/include/rtw_mlme.h
+++ b/drivers/staging/rtl8188eu/include/rtw_mlme.h
@@ -214,7 +214,7 @@ void hostapd_mode_unload(struct adapter *padapter);
214extern unsigned char WPA_TKIP_CIPHER[4]; 214extern unsigned char WPA_TKIP_CIPHER[4];
215extern unsigned char RSN_TKIP_CIPHER[4]; 215extern unsigned char RSN_TKIP_CIPHER[4];
216extern unsigned char REALTEK_96B_IE[]; 216extern unsigned char REALTEK_96B_IE[];
217extern unsigned char MCS_rate_1R[16]; 217extern const u8 MCS_rate_1R[16];
218 218
219void rtw_joinbss_event_prehandle(struct adapter *adapter, u8 *pbuf); 219void rtw_joinbss_event_prehandle(struct adapter *adapter, u8 *pbuf);
220void rtw_survey_event_callback(struct adapter *adapter, u8 *pbuf); 220void rtw_survey_event_callback(struct adapter *adapter, u8 *pbuf);
@@ -311,7 +311,6 @@ void rtw_free_assoc_resources_locked(struct adapter *adapter);
311void rtw_indicate_disconnect(struct adapter *adapter); 311void rtw_indicate_disconnect(struct adapter *adapter);
312void rtw_indicate_connect(struct adapter *adapter); 312void rtw_indicate_connect(struct adapter *adapter);
313void rtw_indicate_scan_done(struct adapter *padapter, bool aborted); 313void rtw_indicate_scan_done(struct adapter *padapter, bool aborted);
314void rtw_scan_abort(struct adapter *adapter);
315 314
316int rtw_restruct_sec_ie(struct adapter *adapter, u8 *in_ie, u8 *out_ie, 315int rtw_restruct_sec_ie(struct adapter *adapter, u8 *in_ie, u8 *out_ie,
317 uint in_len); 316 uint in_len);
diff --git a/drivers/staging/rtl8188eu/include/rtw_mlme_ext.h b/drivers/staging/rtl8188eu/include/rtw_mlme_ext.h
index ade68af15e04..9526da3efcc4 100644
--- a/drivers/staging/rtl8188eu/include/rtw_mlme_ext.h
+++ b/drivers/staging/rtl8188eu/include/rtw_mlme_ext.h
@@ -231,22 +231,22 @@ enum SCAN_STATE {
231}; 231};
232 232
233struct mlme_handler { 233struct mlme_handler {
234 unsigned int num; 234 unsigned int num;
235 char *str; 235 const char *str;
236 unsigned int (*func)(struct adapter *adapt, struct recv_frame *frame); 236 unsigned int (*func)(struct adapter *adapt, struct recv_frame *frame);
237}; 237};
238 238
239struct action_handler { 239struct action_handler {
240 unsigned int num; 240 unsigned int num;
241 char *str; 241 const char *str;
242 unsigned int (*func)(struct adapter *adapt, struct recv_frame *frame); 242 unsigned int (*func)(struct adapter *adapt, struct recv_frame *frame);
243}; 243};
244 244
245struct ss_res { 245struct ss_res {
246 int state; 246 int state;
247 int bss_cnt; 247 int bss_cnt;
248 int channel_idx; 248 int channel_idx;
249 int scan_mode; 249 int scan_mode;
250 u8 ssid_num; 250 u8 ssid_num;
251 u8 ch_num; 251 u8 ch_num;
252 struct ndis_802_11_ssid ssid[RTW_SSID_SCAN_AMOUNT]; 252 struct ndis_802_11_ssid ssid[RTW_SSID_SCAN_AMOUNT];
diff --git a/drivers/staging/rtl8188eu/include/rtw_qos.h b/drivers/staging/rtl8188eu/include/rtw_qos.h
deleted file mode 100644
index bf617da3cd6c..000000000000
--- a/drivers/staging/rtl8188eu/include/rtw_qos.h
+++ /dev/null
@@ -1,18 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/******************************************************************************
3 *
4 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5 *
6 ******************************************************************************/
7#ifndef _RTW_QOS_H_
8#define _RTW_QOS_H_
9
10#include <osdep_service.h>
11
12struct qos_priv {
13 unsigned int qos_option; /* bit mask option: u-apsd,
14 * s-apsd, ts, block ack...
15 */
16};
17
18#endif /* _RTL871X_QOS_H_ */
diff --git a/drivers/staging/rtl8188eu/include/wifi.h b/drivers/staging/rtl8188eu/include/wifi.h
index 259bf2cce2d5..0664d5f30a96 100644
--- a/drivers/staging/rtl8188eu/include/wifi.h
+++ b/drivers/staging/rtl8188eu/include/wifi.h
@@ -257,14 +257,6 @@ enum WIFI_REG_DOMAIN {
257 257
258#define GetAddr4Ptr(pbuf) ((unsigned char *)((size_t)(pbuf) + 24)) 258#define GetAddr4Ptr(pbuf) ((unsigned char *)((size_t)(pbuf) + 24))
259 259
260static inline int IS_MCAST(unsigned char *da)
261{
262 if ((*da) & 0x01)
263 return true;
264 else
265 return false;
266}
267
268static inline unsigned char *get_da(unsigned char *pframe) 260static inline unsigned char *get_da(unsigned char *pframe)
269{ 261{
270 unsigned char *da; 262 unsigned char *da;
diff --git a/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c b/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c
index bee3c3a7a7a9..4ecd2ff48c41 100644
--- a/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c
@@ -421,7 +421,7 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
421 ret = -EOPNOTSUPP; 421 ret = -EOPNOTSUPP;
422 goto exit; 422 goto exit;
423 } 423 }
424 memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), pwep->KeyMaterial, pwep->KeyLength); 424 memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), pwep->KeyMaterial, pwep->KeyLength);
425 psecuritypriv->dot11DefKeylen[wep_key_idx] = pwep->KeyLength; 425 psecuritypriv->dot11DefKeylen[wep_key_idx] = pwep->KeyLength;
426 rtw_set_key(padapter, psecuritypriv, wep_key_idx, 0); 426 rtw_set_key(padapter, psecuritypriv, wep_key_idx, 0);
427 } 427 }
@@ -737,7 +737,7 @@ static int rtw_wx_set_mode(struct net_device *dev, struct iw_request_info *a,
737 RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_err_, ("\n Mode: %s is not supported\n", iw_operation_mode[wrqu->mode])); 737 RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_err_, ("\n Mode: %s is not supported\n", iw_operation_mode[wrqu->mode]));
738 goto exit; 738 goto exit;
739 } 739 }
740 if (rtw_set_802_11_infrastructure_mode(padapter, networkType) == false) { 740 if (!rtw_set_802_11_infrastructure_mode(padapter, networkType)) {
741 ret = -EPERM; 741 ret = -EPERM;
742 goto exit; 742 goto exit;
743 } 743 }
@@ -1000,8 +1000,7 @@ static int rtw_wx_set_wap(struct net_device *dev,
1000 spin_unlock_bh(&queue->lock); 1000 spin_unlock_bh(&queue->lock);
1001 1001
1002 rtw_set_802_11_authentication_mode(padapter, authmode); 1002 rtw_set_802_11_authentication_mode(padapter, authmode);
1003 /* set_802_11_encryption_mode(padapter, padapter->securitypriv.ndisencryptstatus); */ 1003 if (!rtw_set_802_11_bssid(padapter, temp->sa_data)) {
1004 if (rtw_set_802_11_bssid(padapter, temp->sa_data) == false) {
1005 ret = -1; 1004 ret = -1;
1006 goto exit; 1005 goto exit;
1007 } 1006 }
@@ -1317,8 +1316,8 @@ static int rtw_wx_set_essid(struct net_device *dev,
1317 1316
1318 RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_, ("rtw_wx_set_essid: ssid =[%s]\n", src_ssid)); 1317 RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_, ("rtw_wx_set_essid: ssid =[%s]\n", src_ssid));
1319 spin_lock_bh(&queue->lock); 1318 spin_lock_bh(&queue->lock);
1320 phead = get_list_head(queue); 1319 phead = get_list_head(queue);
1321 pmlmepriv->pscanned = phead->next; 1320 pmlmepriv->pscanned = phead->next;
1322 1321
1323 while (phead != pmlmepriv->pscanned) { 1322 while (phead != pmlmepriv->pscanned) {
1324 pnetwork = container_of(pmlmepriv->pscanned, struct wlan_network, list); 1323 pnetwork = container_of(pmlmepriv->pscanned, struct wlan_network, list);
@@ -1354,7 +1353,7 @@ static int rtw_wx_set_essid(struct net_device *dev,
1354 RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_, 1353 RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_,
1355 ("set ssid: set_802_11_auth. mode =%d\n", authmode)); 1354 ("set ssid: set_802_11_auth. mode =%d\n", authmode));
1356 rtw_set_802_11_authentication_mode(padapter, authmode); 1355 rtw_set_802_11_authentication_mode(padapter, authmode);
1357 if (rtw_set_802_11_ssid(padapter, &ndis_ssid) == false) { 1356 if (!rtw_set_802_11_ssid(padapter, &ndis_ssid)) {
1358 ret = -1; 1357 ret = -1;
1359 goto exit; 1358 goto exit;
1360 } 1359 }
@@ -1370,7 +1369,7 @@ static int rtw_wx_get_essid(struct net_device *dev,
1370 struct iw_request_info *a, 1369 struct iw_request_info *a,
1371 union iwreq_data *wrqu, char *extra) 1370 union iwreq_data *wrqu, char *extra)
1372{ 1371{
1373 u32 len, ret = 0; 1372 u32 len;
1374 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); 1373 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1375 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 1374 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
1376 struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network; 1375 struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
@@ -1388,7 +1387,7 @@ static int rtw_wx_get_essid(struct net_device *dev,
1388 wrqu->essid.length = len; 1387 wrqu->essid.length = len;
1389 wrqu->essid.flags = 1; 1388 wrqu->essid.flags = 1;
1390 1389
1391 return ret; 1390 return 0;
1392} 1391}
1393 1392
1394static int rtw_wx_set_rate(struct net_device *dev, 1393static int rtw_wx_set_rate(struct net_device *dev,
@@ -1400,7 +1399,7 @@ static int rtw_wx_set_rate(struct net_device *dev,
1400 u32 target_rate = wrqu->bitrate.value; 1399 u32 target_rate = wrqu->bitrate.value;
1401 u32 fixed = wrqu->bitrate.fixed; 1400 u32 fixed = wrqu->bitrate.fixed;
1402 u32 ratevalue = 0; 1401 u32 ratevalue = 0;
1403 u8 mpdatarate[NumRates] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0xff}; 1402 u8 mpdatarate[NumRates] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0xff};
1404 1403
1405 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, (" rtw_wx_set_rate\n")); 1404 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, (" rtw_wx_set_rate\n"));
1406 RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_, ("target_rate = %d, fixed = %d\n", target_rate, fixed)); 1405 RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_, ("target_rate = %d, fixed = %d\n", target_rate, fixed));
@@ -1673,7 +1672,7 @@ static int rtw_wx_set_enc(struct net_device *dev,
1673 1672
1674 memcpy(wep.KeyMaterial, keybuf, wep.KeyLength); 1673 memcpy(wep.KeyMaterial, keybuf, wep.KeyLength);
1675 1674
1676 if (rtw_set_802_11_add_wep(padapter, &wep) == false) { 1675 if (!rtw_set_802_11_add_wep(padapter, &wep)) {
1677 if (rf_on == pwrpriv->rf_pwrstate) 1676 if (rf_on == pwrpriv->rf_pwrstate)
1678 ret = -EOPNOTSUPP; 1677 ret = -EOPNOTSUPP;
1679 goto exit; 1678 goto exit;
@@ -2278,7 +2277,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param,
2278 /* don't update "psecuritypriv->dot11PrivacyAlgrthm" and */ 2277 /* don't update "psecuritypriv->dot11PrivacyAlgrthm" and */
2279 /* psecuritypriv->dot11PrivacyKeyIndex = keyid", but can rtw_set_key to cam */ 2278 /* psecuritypriv->dot11PrivacyKeyIndex = keyid", but can rtw_set_key to cam */
2280 2279
2281 memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), pwep->KeyMaterial, pwep->KeyLength); 2280 memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), pwep->KeyMaterial, pwep->KeyLength);
2282 2281
2283 psecuritypriv->dot11DefKeylen[wep_key_idx] = pwep->KeyLength; 2282 psecuritypriv->dot11DefKeylen[wep_key_idx] = pwep->KeyLength;
2284 2283
@@ -2496,7 +2495,7 @@ static int rtw_add_sta(struct net_device *dev, struct ieee_param *param)
2496 psta->htpriv.ht_option = false; 2495 psta->htpriv.ht_option = false;
2497 } 2496 }
2498 2497
2499 if (pmlmepriv->htpriv.ht_option == false) 2498 if (!pmlmepriv->htpriv.ht_option)
2500 psta->htpriv.ht_option = false; 2499 psta->htpriv.ht_option = false;
2501 2500
2502 update_sta_info_apmode(padapter, psta); 2501 update_sta_info_apmode(padapter, psta);
diff --git a/drivers/staging/rtl8188eu/os_dep/mlme_linux.c b/drivers/staging/rtl8188eu/os_dep/mlme_linux.c
index 238c1d9cdc7b..d5ceb3beabbc 100644
--- a/drivers/staging/rtl8188eu/os_dep/mlme_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/mlme_linux.c
@@ -78,7 +78,7 @@ void rtw_os_indicate_disconnect(struct adapter *adapter)
78{ 78{
79 netif_carrier_off(adapter->pnetdev); /* Do it first for tx broadcast pkt after disconnection issue! */ 79 netif_carrier_off(adapter->pnetdev); /* Do it first for tx broadcast pkt after disconnection issue! */
80 rtw_indicate_wx_disassoc_event(adapter); 80 rtw_indicate_wx_disassoc_event(adapter);
81 rtw_reset_securitypriv(adapter); 81 rtw_reset_securitypriv(adapter);
82} 82}
83 83
84void rtw_report_sec_ie(struct adapter *adapter, u8 authmode, u8 *sec_ie) 84void rtw_report_sec_ie(struct adapter *adapter, u8 authmode, u8 *sec_ie)
diff --git a/drivers/staging/rtl8188eu/os_dep/os_intfs.c b/drivers/staging/rtl8188eu/os_dep/os_intfs.c
index 0a9877d85c79..dac9f98b4808 100644
--- a/drivers/staging/rtl8188eu/os_dep/os_intfs.c
+++ b/drivers/staging/rtl8188eu/os_dep/os_intfs.c
@@ -643,7 +643,7 @@ int ips_netdrv_open(struct adapter *padapter)
643 mod_timer(&padapter->mlmepriv.dynamic_chk_timer, 643 mod_timer(&padapter->mlmepriv.dynamic_chk_timer,
644 jiffies + msecs_to_jiffies(5000)); 644 jiffies + msecs_to_jiffies(5000));
645 645
646 return _SUCCESS; 646 return _SUCCESS;
647 647
648netdev_open_error: 648netdev_open_error:
649 DBG_88E("-ips_netdrv_open - drv_open failure, bup =%d\n", padapter->bup); 649 DBG_88E("-ips_netdrv_open - drv_open failure, bup =%d\n", padapter->bup);
diff --git a/drivers/staging/rtl8188eu/os_dep/osdep_service.c b/drivers/staging/rtl8188eu/os_dep/osdep_service.c
index 78daef6704ac..105f3f21bdea 100644
--- a/drivers/staging/rtl8188eu/os_dep/osdep_service.c
+++ b/drivers/staging/rtl8188eu/os_dep/osdep_service.c
@@ -18,20 +18,6 @@ u8 *_rtw_malloc(u32 sz)
18 return kmalloc(sz, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL); 18 return kmalloc(sz, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
19} 19}
20 20
21void *rtw_malloc2d(int h, int w, int size)
22{
23 int j;
24 void **a = kzalloc(h * sizeof(void *) + h * w * size, GFP_KERNEL);
25
26 if (!a)
27 goto out;
28
29 for (j = 0; j < h; j++)
30 a[j] = ((char *)(a + h)) + j * w * size;
31out:
32 return a;
33}
34
35void _rtw_init_queue(struct __queue *pqueue) 21void _rtw_init_queue(struct __queue *pqueue)
36{ 22{
37 INIT_LIST_HEAD(&pqueue->queue); 23 INIT_LIST_HEAD(&pqueue->queue);
diff --git a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
index 5ddfc2ead127..d6a499692e96 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
@@ -84,7 +84,7 @@ static int recvbuf2recvframe(struct adapter *adapt, struct sk_buff *pskb)
84 84
85 if ((pattrib->pkt_len <= 0) || (pkt_offset > transfer_len)) { 85 if ((pattrib->pkt_len <= 0) || (pkt_offset > transfer_len)) {
86 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("recvbuf2recvframe: pkt_len<=0\n")); 86 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("recvbuf2recvframe: pkt_len<=0\n"));
87 DBG_88E("%s()-%d: RX Warning!,pkt_len<=0 or pkt_offset> transfoer_len\n", __func__, __LINE__); 87 DBG_88E("%s()-%d: RX Warning!,pkt_len<=0 or pkt_offset> transfer_len\n", __func__, __LINE__);
88 rtw_free_recvframe(precvframe, pfree_recv_queue); 88 rtw_free_recvframe(precvframe, pfree_recv_queue);
89 goto _exit_recvbuf2recvframe; 89 goto _exit_recvbuf2recvframe;
90 } 90 }
@@ -606,7 +606,7 @@ static void usb_write_port_complete(struct urb *purb, struct pt_regs *regs)
606 if ((purb->status == -EPIPE) || (purb->status == -EPROTO)) { 606 if ((purb->status == -EPIPE) || (purb->status == -EPROTO)) {
607 sreset_set_wifi_error_status(padapter, USB_WRITE_PORT_FAIL); 607 sreset_set_wifi_error_status(padapter, USB_WRITE_PORT_FAIL);
608 } else if (purb->status == -EINPROGRESS) { 608 } else if (purb->status == -EINPROGRESS) {
609 RT_TRACE(_module_hci_ops_os_c_, _drv_err_, ("usb_write_port_complete: EINPROGESS\n")); 609 RT_TRACE(_module_hci_ops_os_c_, _drv_err_, ("usb_write_port_complete: EINPROGRESS\n"));
610 goto check_completion; 610 goto check_completion;
611 } else if (purb->status == -ENOENT) { 611 } else if (purb->status == -ENOENT) {
612 DBG_88E("%s: -ENOENT\n", __func__); 612 DBG_88E("%s: -ENOENT\n", __func__);
diff --git a/drivers/staging/rtl8188eu/os_dep/xmit_linux.c b/drivers/staging/rtl8188eu/os_dep/xmit_linux.c
index d8ef9b5d81a8..017e1d628461 100644
--- a/drivers/staging/rtl8188eu/os_dep/xmit_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/xmit_linux.c
@@ -14,7 +14,8 @@
14#include <xmit_osdep.h> 14#include <xmit_osdep.h>
15#include <osdep_intf.h> 15#include <osdep_intf.h>
16 16
17int rtw_os_xmit_resource_alloc(struct adapter *padapter, struct xmit_buf *pxmitbuf, u32 alloc_sz) 17int rtw_os_xmit_resource_alloc(struct adapter *padapter,
18 struct xmit_buf *pxmitbuf, u32 alloc_sz)
18{ 19{
19 int i; 20 int i;
20 21
@@ -45,11 +46,11 @@ void rtw_os_xmit_resource_free(struct xmit_buf *pxmitbuf)
45 kfree(pxmitbuf->pallocated_buf); 46 kfree(pxmitbuf->pallocated_buf);
46} 47}
47 48
48#define WMM_XMIT_THRESHOLD (NR_XMITFRAME*2/5) 49#define WMM_XMIT_THRESHOLD (NR_XMITFRAME * 2 / 5)
49 50
50void rtw_os_pkt_complete(struct adapter *padapter, struct sk_buff *pkt) 51void rtw_os_pkt_complete(struct adapter *padapter, struct sk_buff *pkt)
51{ 52{
52 u16 queue; 53 u16 queue;
53 struct xmit_priv *pxmitpriv = &padapter->xmitpriv; 54 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
54 55
55 queue = skb_get_queue_mapping(pkt); 56 queue = skb_get_queue_mapping(pkt);
@@ -89,10 +90,11 @@ void rtw_os_xmit_schedule(struct adapter *padapter)
89 spin_unlock_bh(&pxmitpriv->lock); 90 spin_unlock_bh(&pxmitpriv->lock);
90} 91}
91 92
92static void rtw_check_xmit_resource(struct adapter *padapter, struct sk_buff *pkt) 93static void rtw_check_xmit_resource(struct adapter *padapter,
94 struct sk_buff *pkt)
93{ 95{
94 struct xmit_priv *pxmitpriv = &padapter->xmitpriv; 96 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
95 u16 queue; 97 u16 queue;
96 98
97 queue = skb_get_queue_mapping(pkt); 99 queue = skb_get_queue_mapping(pkt);
98 if (padapter->registrypriv.wifi_spec) { 100 if (padapter->registrypriv.wifi_spec) {
@@ -109,12 +111,12 @@ static void rtw_check_xmit_resource(struct adapter *padapter, struct sk_buff *pk
109 111
110static int rtw_mlcst2unicst(struct adapter *padapter, struct sk_buff *skb) 112static int rtw_mlcst2unicst(struct adapter *padapter, struct sk_buff *skb)
111{ 113{
112 struct sta_priv *pstapriv = &padapter->stapriv; 114 struct sta_priv *pstapriv = &padapter->stapriv;
113 struct xmit_priv *pxmitpriv = &padapter->xmitpriv; 115 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
114 struct list_head *phead, *plist; 116 struct list_head *phead, *plist;
115 struct sk_buff *newskb; 117 struct sk_buff *newskb;
116 struct sta_info *psta = NULL; 118 struct sta_info *psta = NULL;
117 s32 res; 119 s32 res;
118 120
119 spin_lock_bh(&pstapriv->asoc_list_lock); 121 spin_lock_bh(&pstapriv->asoc_list_lock);
120 phead = &pstapriv->asoc_list; 122 phead = &pstapriv->asoc_list;
@@ -126,7 +128,7 @@ static int rtw_mlcst2unicst(struct adapter *padapter, struct sk_buff *skb)
126 128
127 plist = plist->next; 129 plist = plist->next;
128 130
129 /* avoid come from STA1 and send back STA1 */ 131 /* avoid come from STA1 and send back STA1 */
130 if (!memcmp(psta->hwaddr, &skb->data[6], 6)) 132 if (!memcmp(psta->hwaddr, &skb->data[6], 6))
131 continue; 133 continue;
132 134
@@ -136,18 +138,24 @@ static int rtw_mlcst2unicst(struct adapter *padapter, struct sk_buff *skb)
136 memcpy(newskb->data, psta->hwaddr, 6); 138 memcpy(newskb->data, psta->hwaddr, 6);
137 res = rtw_xmit(padapter, &newskb); 139 res = rtw_xmit(padapter, &newskb);
138 if (res < 0) { 140 if (res < 0) {
139 DBG_88E("%s()-%d: rtw_xmit() return error!\n", __func__, __LINE__); 141 DBG_88E("%s()-%d: rtw_xmit() return error!\n",
142 __func__, __LINE__);
140 pxmitpriv->tx_drop++; 143 pxmitpriv->tx_drop++;
141 dev_kfree_skb_any(newskb); 144 dev_kfree_skb_any(newskb);
142 } else { 145 } else {
143 pxmitpriv->tx_pkts++; 146 pxmitpriv->tx_pkts++;
144 } 147 }
145 } else { 148 } else {
146 DBG_88E("%s-%d: skb_copy() failed!\n", __func__, __LINE__); 149 DBG_88E("%s-%d: skb_copy() failed!\n",
150 __func__, __LINE__);
147 pxmitpriv->tx_drop++; 151 pxmitpriv->tx_drop++;
148 152
149 spin_unlock_bh(&pstapriv->asoc_list_lock); 153 spin_unlock_bh(&pstapriv->asoc_list_lock);
150 return false; /* Caller shall tx this multicast frame via normal way. */ 154
155 /* Caller shall tx this multicast frame
156 * via normal way.
157 */
158 return false;
151 } 159 }
152 } 160 }
153 161
@@ -156,17 +164,18 @@ static int rtw_mlcst2unicst(struct adapter *padapter, struct sk_buff *skb)
156 return true; 164 return true;
157} 165}
158 166
159int rtw_xmit_entry(struct sk_buff *pkt, struct net_device *pnetdev) 167int rtw_xmit_entry(struct sk_buff *pkt, struct net_device *pnetdev)
160{ 168{
161 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(pnetdev); 169 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(pnetdev);
162 struct xmit_priv *pxmitpriv = &padapter->xmitpriv; 170 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
163 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 171 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
164 s32 res = 0; 172 s32 res = 0;
165 173
166 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("+xmit_enry\n")); 174 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("+xmit_enry\n"));
167 175
168 if (rtw_if_up(padapter) == false) { 176 if (!rtw_if_up(padapter)) {
169 RT_TRACE(_module_xmit_osdep_c_, _drv_err_, ("rtw_xmit_entry: rtw_if_up fail\n")); 177 RT_TRACE(_module_xmit_osdep_c_, _drv_err_,
178 ("%s: rtw_if_up fail\n", __func__));
170 goto drop_packet; 179 goto drop_packet;
171 } 180 }
172 181
@@ -175,7 +184,7 @@ int rtw_xmit_entry(struct sk_buff *pkt, struct net_device *pnetdev)
175 if (!rtw_mc2u_disable && check_fwstate(pmlmepriv, WIFI_AP_STATE) && 184 if (!rtw_mc2u_disable && check_fwstate(pmlmepriv, WIFI_AP_STATE) &&
176 (IP_MCAST_MAC(pkt->data) || ICMPV6_MCAST_MAC(pkt->data)) && 185 (IP_MCAST_MAC(pkt->data) || ICMPV6_MCAST_MAC(pkt->data)) &&
177 (padapter->registrypriv.wifi_spec == 0)) { 186 (padapter->registrypriv.wifi_spec == 0)) {
178 if (pxmitpriv->free_xmitframe_cnt > (NR_XMITFRAME/4)) { 187 if (pxmitpriv->free_xmitframe_cnt > NR_XMITFRAME / 4) {
179 res = rtw_mlcst2unicst(padapter, pkt); 188 res = rtw_mlcst2unicst(padapter, pkt);
180 if (res) 189 if (res)
181 goto exit; 190 goto exit;
@@ -187,13 +196,15 @@ int rtw_xmit_entry(struct sk_buff *pkt, struct net_device *pnetdev)
187 goto drop_packet; 196 goto drop_packet;
188 197
189 pxmitpriv->tx_pkts++; 198 pxmitpriv->tx_pkts++;
190 RT_TRACE(_module_xmit_osdep_c_, _drv_info_, ("rtw_xmit_entry: tx_pkts=%d\n", (u32)pxmitpriv->tx_pkts)); 199 RT_TRACE(_module_xmit_osdep_c_, _drv_info_,
200 ("%s: tx_pkts=%d\n", __func__, (u32)pxmitpriv->tx_pkts));
191 goto exit; 201 goto exit;
192 202
193drop_packet: 203drop_packet:
194 pxmitpriv->tx_drop++; 204 pxmitpriv->tx_drop++;
195 dev_kfree_skb_any(pkt); 205 dev_kfree_skb_any(pkt);
196 RT_TRACE(_module_xmit_osdep_c_, _drv_notice_, ("rtw_xmit_entry: drop, tx_drop=%d\n", (u32)pxmitpriv->tx_drop)); 206 RT_TRACE(_module_xmit_osdep_c_, _drv_notice_,
207 ("%s: drop, tx_drop=%d\n", __func__, (u32)pxmitpriv->tx_drop));
197 208
198exit: 209exit:
199 return 0; 210 return 0;
diff --git a/drivers/staging/rtl8192e/rtllib_softmac.c b/drivers/staging/rtl8192e/rtllib_softmac.c
index 919231fec09c..287d0c11fa38 100644
--- a/drivers/staging/rtl8192e/rtllib_softmac.c
+++ b/drivers/staging/rtl8192e/rtllib_softmac.c
@@ -1680,19 +1680,19 @@ inline void rtllib_softmac_new_net(struct rtllib_device *ieee,
1680 (ssidbroad && !ssidset) || (!ssidbroad && ssidset))) || 1680 (ssidbroad && !ssidset) || (!ssidbroad && ssidset))) ||
1681 (!apset && ssidset && ssidbroad && ssidmatch) || 1681 (!apset && ssidset && ssidbroad && ssidmatch) ||
1682 (ieee->is_roaming && ssidset && ssidbroad && ssidmatch)) { 1682 (ieee->is_roaming && ssidset && ssidbroad && ssidmatch)) {
1683 /* if the essid is hidden replace it with the 1683 /* Save the essid so that if it is hidden, it is
1684 * essid provided by the user. 1684 * replaced with the essid provided by the user.
1685 */ 1685 */
1686 if (!ssidbroad) { 1686 if (!ssidbroad) {
1687 strncpy(tmp_ssid, ieee->current_network.ssid, 1687 memcpy(tmp_ssid, ieee->current_network.ssid,
1688 IW_ESSID_MAX_SIZE); 1688 ieee->current_network.ssid_len);
1689 tmp_ssid_len = ieee->current_network.ssid_len; 1689 tmp_ssid_len = ieee->current_network.ssid_len;
1690 } 1690 }
1691 memcpy(&ieee->current_network, net, 1691 memcpy(&ieee->current_network, net,
1692 sizeof(struct rtllib_network)); 1692 sizeof(ieee->current_network));
1693 if (!ssidbroad) { 1693 if (!ssidbroad) {
1694 strncpy(ieee->current_network.ssid, tmp_ssid, 1694 memcpy(ieee->current_network.ssid, tmp_ssid,
1695 IW_ESSID_MAX_SIZE); 1695 tmp_ssid_len);
1696 ieee->current_network.ssid_len = tmp_ssid_len; 1696 ieee->current_network.ssid_len = tmp_ssid_len;
1697 } 1697 }
1698 netdev_info(ieee->dev, 1698 netdev_info(ieee->dev,
diff --git a/drivers/staging/rtl8192u/ieee80211/dot11d.c b/drivers/staging/rtl8192u/ieee80211/dot11d.c
index 2fb575a2b6ab..130ddfe9868f 100644
--- a/drivers/staging/rtl8192u/ieee80211/dot11d.c
+++ b/drivers/staging/rtl8192u/ieee80211/dot11d.c
@@ -3,42 +3,42 @@
3 3
4#include "dot11d.h" 4#include "dot11d.h"
5 5
6void Dot11d_Init(struct ieee80211_device *ieee) 6void rtl8192u_dot11d_init(struct ieee80211_device *ieee)
7{ 7{
8 struct rt_dot11d_info *pDot11dInfo = GET_DOT11D_INFO(ieee); 8 struct rt_dot11d_info *dot11d_info = GET_DOT11D_INFO(ieee);
9 9
10 pDot11dInfo->enabled = false; 10 dot11d_info->dot11d_enabled = false;
11 11
12 pDot11dInfo->state = DOT11D_STATE_NONE; 12 dot11d_info->state = DOT11D_STATE_NONE;
13 pDot11dInfo->country_ie_len = 0; 13 dot11d_info->country_ie_len = 0;
14 memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER + 1); 14 memset(dot11d_info->channel_map, 0, MAX_CHANNEL_NUMBER + 1);
15 memset(pDot11dInfo->max_tx_pwr_dbm_list, 0xFF, MAX_CHANNEL_NUMBER+1); 15 memset(dot11d_info->max_tx_pwr_dbm_list, 0xFF, MAX_CHANNEL_NUMBER+1);
16 RESET_CIE_WATCHDOG(ieee); 16 RESET_CIE_WATCHDOG(ieee);
17 17
18 netdev_info(ieee->dev, "Dot11d_Init()\n"); 18 netdev_info(ieee->dev, "rtl8192u_dot11d_init()\n");
19} 19}
20EXPORT_SYMBOL(Dot11d_Init); 20EXPORT_SYMBOL(rtl8192u_dot11d_init);
21 21
22/* Reset to the state as we are just entering a regulatory domain. */ 22/* Reset to the state as we are just entering a regulatory domain. */
23void Dot11d_Reset(struct ieee80211_device *ieee) 23void dot11d_reset(struct ieee80211_device *ieee)
24{ 24{
25 u32 i; 25 u32 i;
26 struct rt_dot11d_info *pDot11dInfo = GET_DOT11D_INFO(ieee); 26 struct rt_dot11d_info *dot11d_info = GET_DOT11D_INFO(ieee);
27 /* Clear old channel map */ 27 /* Clear old channel map */
28 memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER+1); 28 memset(dot11d_info->channel_map, 0, MAX_CHANNEL_NUMBER+1);
29 memset(pDot11dInfo->max_tx_pwr_dbm_list, 0xFF, MAX_CHANNEL_NUMBER+1); 29 memset(dot11d_info->max_tx_pwr_dbm_list, 0xFF, MAX_CHANNEL_NUMBER+1);
30 /* Set new channel map */ 30 /* Set new channel map */
31 for (i = 1; i <= 11; i++) 31 for (i = 1; i <= 11; i++)
32 (pDot11dInfo->channel_map)[i] = 1; 32 (dot11d_info->channel_map)[i] = 1;
33 33
34 for (i = 12; i <= 14; i++) 34 for (i = 12; i <= 14; i++)
35 (pDot11dInfo->channel_map)[i] = 2; 35 (dot11d_info->channel_map)[i] = 2;
36 36
37 pDot11dInfo->state = DOT11D_STATE_NONE; 37 dot11d_info->state = DOT11D_STATE_NONE;
38 pDot11dInfo->country_ie_len = 0; 38 dot11d_info->country_ie_len = 0;
39 RESET_CIE_WATCHDOG(ieee); 39 RESET_CIE_WATCHDOG(ieee);
40} 40}
41EXPORT_SYMBOL(Dot11d_Reset); 41EXPORT_SYMBOL(dot11d_reset);
42 42
43/* 43/*
44 * Update country IE from Beacon or Probe Resopnse and configure PHY for 44 * Update country IE from Beacon or Probe Resopnse and configure PHY for
@@ -49,15 +49,15 @@ EXPORT_SYMBOL(Dot11d_Reset);
49 * 1. IS_DOT11D_ENABLE() is TRUE. 49 * 1. IS_DOT11D_ENABLE() is TRUE.
50 * 2. Input IE is an valid one. 50 * 2. Input IE is an valid one.
51 */ 51 */
52void Dot11d_UpdateCountryIe(struct ieee80211_device *dev, u8 *pTaddr, 52void dot11d_update_country_ie(struct ieee80211_device *dev, u8 *pTaddr,
53 u16 CoutryIeLen, u8 *pCoutryIe) 53 u16 CoutryIeLen, u8 *pCoutryIe)
54{ 54{
55 struct rt_dot11d_info *pDot11dInfo = GET_DOT11D_INFO(dev); 55 struct rt_dot11d_info *dot11d_info = GET_DOT11D_INFO(dev);
56 u8 i, j, NumTriples, MaxChnlNum; 56 u8 i, j, NumTriples, MaxChnlNum;
57 struct chnl_txpower_triple *pTriple; 57 struct chnl_txpower_triple *pTriple;
58 58
59 memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER+1); 59 memset(dot11d_info->channel_map, 0, MAX_CHANNEL_NUMBER+1);
60 memset(pDot11dInfo->max_tx_pwr_dbm_list, 0xFF, MAX_CHANNEL_NUMBER+1); 60 memset(dot11d_info->max_tx_pwr_dbm_list, 0xFF, MAX_CHANNEL_NUMBER+1);
61 MaxChnlNum = 0; 61 MaxChnlNum = 0;
62 NumTriples = (CoutryIeLen - 3) / 3; /* skip 3-byte country string. */ 62 NumTriples = (CoutryIeLen - 3) / 3; /* skip 3-byte country string. */
63 pTriple = (struct chnl_txpower_triple *)(pCoutryIe + 3); 63 pTriple = (struct chnl_txpower_triple *)(pCoutryIe + 3);
@@ -66,20 +66,20 @@ void Dot11d_UpdateCountryIe(struct ieee80211_device *dev, u8 *pTaddr,
66 /* It is not in a monotonically increasing order, so 66 /* It is not in a monotonically increasing order, so
67 * stop processing. 67 * stop processing.
68 */ 68 */
69 netdev_err(dev->dev, "Dot11d_UpdateCountryIe(): Invalid country IE, skip it........1\n"); 69 netdev_err(dev->dev, "dot11d_update_country_ie(): Invalid country IE, skip it........1\n");
70 return; 70 return;
71 } 71 }
72 if (MAX_CHANNEL_NUMBER < (pTriple->first_channel + pTriple->num_channels)) { 72 if (MAX_CHANNEL_NUMBER < (pTriple->first_channel + pTriple->num_channels)) {
73 /* It is not a valid set of channel id, so stop 73 /* It is not a valid set of channel id, so stop
74 * processing. 74 * processing.
75 */ 75 */
76 netdev_err(dev->dev, "Dot11d_UpdateCountryIe(): Invalid country IE, skip it........2\n"); 76 netdev_err(dev->dev, "dot11d_update_country_ie(): Invalid country IE, skip it........2\n");
77 return; 77 return;
78 } 78 }
79 79
80 for (j = 0; j < pTriple->num_channels; j++) { 80 for (j = 0; j < pTriple->num_channels; j++) {
81 pDot11dInfo->channel_map[pTriple->first_channel + j] = 1; 81 dot11d_info->channel_map[pTriple->first_channel + j] = 1;
82 pDot11dInfo->max_tx_pwr_dbm_list[pTriple->first_channel + j] = pTriple->max_tx_pwr_dbm; 82 dot11d_info->max_tx_pwr_dbm_list[pTriple->first_channel + j] = pTriple->max_tx_pwr_dbm;
83 MaxChnlNum = pTriple->first_channel + j; 83 MaxChnlNum = pTriple->first_channel + j;
84 } 84 }
85 85
@@ -87,90 +87,90 @@ void Dot11d_UpdateCountryIe(struct ieee80211_device *dev, u8 *pTaddr,
87 } 87 }
88 netdev_info(dev->dev, "Channel List:"); 88 netdev_info(dev->dev, "Channel List:");
89 for (i = 1; i <= MAX_CHANNEL_NUMBER; i++) 89 for (i = 1; i <= MAX_CHANNEL_NUMBER; i++)
90 if (pDot11dInfo->channel_map[i] > 0) 90 if (dot11d_info->channel_map[i] > 0)
91 netdev_info(dev->dev, " %d", i); 91 netdev_info(dev->dev, " %d", i);
92 netdev_info(dev->dev, "\n"); 92 netdev_info(dev->dev, "\n");
93 93
94 UPDATE_CIE_SRC(dev, pTaddr); 94 UPDATE_CIE_SRC(dev, pTaddr);
95 95
96 pDot11dInfo->country_ie_len = CoutryIeLen; 96 dot11d_info->country_ie_len = CoutryIeLen;
97 memcpy(pDot11dInfo->country_ie_buf, pCoutryIe, CoutryIeLen); 97 memcpy(dot11d_info->country_ie_buf, pCoutryIe, CoutryIeLen);
98 pDot11dInfo->state = DOT11D_STATE_LEARNED; 98 dot11d_info->state = DOT11D_STATE_LEARNED;
99} 99}
100EXPORT_SYMBOL(Dot11d_UpdateCountryIe); 100EXPORT_SYMBOL(dot11d_update_country_ie);
101 101
102u8 DOT11D_GetMaxTxPwrInDbm(struct ieee80211_device *dev, u8 Channel) 102u8 dot11d_get_max_tx_pwr_in_dbm(struct ieee80211_device *dev, u8 Channel)
103{ 103{
104 struct rt_dot11d_info *pDot11dInfo = GET_DOT11D_INFO(dev); 104 struct rt_dot11d_info *dot11d_info = GET_DOT11D_INFO(dev);
105 u8 MaxTxPwrInDbm = 255; 105 u8 MaxTxPwrInDbm = 255;
106 106
107 if (Channel > MAX_CHANNEL_NUMBER) { 107 if (Channel > MAX_CHANNEL_NUMBER) {
108 netdev_err(dev->dev, "DOT11D_GetMaxTxPwrInDbm(): Invalid Channel\n"); 108 netdev_err(dev->dev, "dot11d_get_max_tx_pwr_in_dbm(): Invalid Channel\n");
109 return MaxTxPwrInDbm; 109 return MaxTxPwrInDbm;
110 } 110 }
111 if (pDot11dInfo->channel_map[Channel]) 111 if (dot11d_info->channel_map[Channel])
112 MaxTxPwrInDbm = pDot11dInfo->max_tx_pwr_dbm_list[Channel]; 112 MaxTxPwrInDbm = dot11d_info->max_tx_pwr_dbm_list[Channel];
113 113
114 return MaxTxPwrInDbm; 114 return MaxTxPwrInDbm;
115} 115}
116EXPORT_SYMBOL(DOT11D_GetMaxTxPwrInDbm); 116EXPORT_SYMBOL(dot11d_get_max_tx_pwr_in_dbm);
117 117
118void DOT11D_ScanComplete(struct ieee80211_device *dev) 118void dot11d_scan_complete(struct ieee80211_device *dev)
119{ 119{
120 struct rt_dot11d_info *pDot11dInfo = GET_DOT11D_INFO(dev); 120 struct rt_dot11d_info *dot11d_info = GET_DOT11D_INFO(dev);
121 121
122 switch (pDot11dInfo->state) { 122 switch (dot11d_info->state) {
123 case DOT11D_STATE_LEARNED: 123 case DOT11D_STATE_LEARNED:
124 pDot11dInfo->state = DOT11D_STATE_DONE; 124 dot11d_info->state = DOT11D_STATE_DONE;
125 break; 125 break;
126 126
127 case DOT11D_STATE_DONE: 127 case DOT11D_STATE_DONE:
128 if (GET_CIE_WATCHDOG(dev) == 0) { 128 if (GET_CIE_WATCHDOG(dev) == 0) {
129 /* Reset country IE if previous one is gone. */ 129 /* Reset country IE if previous one is gone. */
130 Dot11d_Reset(dev); 130 dot11d_reset(dev);
131 } 131 }
132 break; 132 break;
133 case DOT11D_STATE_NONE: 133 case DOT11D_STATE_NONE:
134 break; 134 break;
135 } 135 }
136} 136}
137EXPORT_SYMBOL(DOT11D_ScanComplete); 137EXPORT_SYMBOL(dot11d_scan_complete);
138 138
139int IsLegalChannel(struct ieee80211_device *dev, u8 channel) 139int is_legal_channel(struct ieee80211_device *dev, u8 channel)
140{ 140{
141 struct rt_dot11d_info *pDot11dInfo = GET_DOT11D_INFO(dev); 141 struct rt_dot11d_info *dot11d_info = GET_DOT11D_INFO(dev);
142 142
143 if (channel > MAX_CHANNEL_NUMBER) { 143 if (channel > MAX_CHANNEL_NUMBER) {
144 netdev_err(dev->dev, "IsLegalChannel(): Invalid Channel\n"); 144 netdev_err(dev->dev, "is_legal_channel(): Invalid Channel\n");
145 return 0; 145 return 0;
146 } 146 }
147 if (pDot11dInfo->channel_map[channel] > 0) 147 if (dot11d_info->channel_map[channel] > 0)
148 return 1; 148 return 1;
149 return 0; 149 return 0;
150} 150}
151EXPORT_SYMBOL(IsLegalChannel); 151EXPORT_SYMBOL(is_legal_channel);
152 152
153int ToLegalChannel(struct ieee80211_device *dev, u8 channel) 153int to_legal_channel(struct ieee80211_device *dev, u8 channel)
154{ 154{
155 struct rt_dot11d_info *pDot11dInfo = GET_DOT11D_INFO(dev); 155 struct rt_dot11d_info *dot11d_info = GET_DOT11D_INFO(dev);
156 u8 default_chn = 0; 156 u8 default_chn = 0;
157 u32 i = 0; 157 u32 i = 0;
158 158
159 for (i = 1; i <= MAX_CHANNEL_NUMBER; i++) { 159 for (i = 1; i <= MAX_CHANNEL_NUMBER; i++) {
160 if (pDot11dInfo->channel_map[i] > 0) { 160 if (dot11d_info->channel_map[i] > 0) {
161 default_chn = i; 161 default_chn = i;
162 break; 162 break;
163 } 163 }
164 } 164 }
165 165
166 if (channel > MAX_CHANNEL_NUMBER) { 166 if (channel > MAX_CHANNEL_NUMBER) {
167 netdev_err(dev->dev, "IsLegalChannel(): Invalid Channel\n"); 167 netdev_err(dev->dev, "is_legal_channel(): Invalid Channel\n");
168 return default_chn; 168 return default_chn;
169 } 169 }
170 170
171 if (pDot11dInfo->channel_map[channel] > 0) 171 if (dot11d_info->channel_map[channel] > 0)
172 return channel; 172 return channel;
173 173
174 return default_chn; 174 return default_chn;
175} 175}
176EXPORT_SYMBOL(ToLegalChannel); 176EXPORT_SYMBOL(to_legal_channel);
diff --git a/drivers/staging/rtl8192u/ieee80211/dot11d.h b/drivers/staging/rtl8192u/ieee80211/dot11d.h
index 363a6bed18dd..8b485fa18089 100644
--- a/drivers/staging/rtl8192u/ieee80211/dot11d.h
+++ b/drivers/staging/rtl8192u/ieee80211/dot11d.h
@@ -17,74 +17,41 @@ enum dot11d_state {
17}; 17};
18 18
19struct rt_dot11d_info { 19struct rt_dot11d_info {
20 bool enabled; /* dot11MultiDomainCapabilityEnabled */
21
22 u16 country_ie_len; /* > 0 if country_ie_buf[] contains valid country information element. */ 20 u16 country_ie_len; /* > 0 if country_ie_buf[] contains valid country information element. */
21
22 /* country_ie_src_addr u16 aligned for comparison and copy */
23 u8 country_ie_src_addr[ETH_ALEN]; /* Source AP of the country IE. */
23 u8 country_ie_buf[MAX_IE_LEN]; 24 u8 country_ie_buf[MAX_IE_LEN];
24 u8 country_ie_src_addr[6]; /* Source AP of the country IE. */
25 u8 country_ie_watchdog; 25 u8 country_ie_watchdog;
26 26
27 u8 channel_map[MAX_CHANNEL_NUMBER + 1]; /* !Value 0: Invalid, 1: Valid (active scan), 2: Valid (passive scan) */ 27 u8 channel_map[MAX_CHANNEL_NUMBER + 1]; /* !Value 0: Invalid, 1: Valid (active scan), 2: Valid (passive scan) */
28 u8 max_tx_pwr_dbm_list[MAX_CHANNEL_NUMBER + 1]; 28 u8 max_tx_pwr_dbm_list[MAX_CHANNEL_NUMBER + 1];
29 29
30 enum dot11d_state state; 30 enum dot11d_state state;
31 u8 dot11d_enabled; /* dot11MultiDomainCapabilityEnabled */
31}; 32};
32 33
33#define eqMacAddr(a, b) (((a)[0] == (b)[0] && \ 34#define GET_DOT11D_INFO(ieee_dev) ((struct rt_dot11d_info *)((ieee_dev)->dot11d_info))
34 (a)[1] == (b)[1] && (a)[2] == (b)[2] && (a)[3] == (b)[3] && \
35 (a)[4] == (b)[4] && (a)[5] == (b)[5]) ? 1 : 0)
36#define cpMacAddr(des, src) ((des)[0] = (src)[0], \
37 (des)[1] = (src)[1], (des)[2] = (src)[2], \
38 (des)[3] = (src)[3], (des)[4] = (src)[4], \
39 (des)[5] = (src)[5])
40#define GET_DOT11D_INFO(__pIeeeDev) ((struct rt_dot11d_info *)((__pIeeeDev)->pDot11dInfo))
41
42#define IS_DOT11D_ENABLE(__pIeeeDev) (GET_DOT11D_INFO(__pIeeeDev)->enabled)
43#define IS_COUNTRY_IE_VALID(__pIeeeDev) (GET_DOT11D_INFO(__pIeeeDev)->country_ie_len > 0)
44
45#define IS_EQUAL_CIE_SRC(__pIeeeDev, __pTa) eqMacAddr(GET_DOT11D_INFO(__pIeeeDev)->country_ie_src_addr, __pTa)
46#define UPDATE_CIE_SRC(__pIeeeDev, __pTa) cpMacAddr(GET_DOT11D_INFO(__pIeeeDev)->country_ie_src_addr, __pTa)
47
48#define GET_CIE_WATCHDOG(__pIeeeDev) (GET_DOT11D_INFO(__pIeeeDev)->country_ie_watchdog)
49#define RESET_CIE_WATCHDOG(__pIeeeDev) (GET_CIE_WATCHDOG(__pIeeeDev) = 0)
50#define UPDATE_CIE_WATCHDOG(__pIeeeDev) (++GET_CIE_WATCHDOG(__pIeeeDev))
51
52void
53Dot11d_Init(
54 struct ieee80211_device *dev
55 );
56
57void
58Dot11d_Reset(
59 struct ieee80211_device *dev
60 );
61 35
62void 36#define IS_DOT11D_ENABLE(ieee_dev) (GET_DOT11D_INFO(ieee_dev)->dot11d_enabled)
63Dot11d_UpdateCountryIe( 37#define IS_COUNTRY_IE_VALID(ieee_dev) (GET_DOT11D_INFO(ieee_dev)->country_ie_len > 0)
64 struct ieee80211_device *dev,
65 u8 *pTaddr,
66 u16 CoutryIeLen,
67 u8 *pCoutryIe
68 );
69 38
70u8 39#define IS_EQUAL_CIE_SRC(ieee_dev, addr) ether_addr_equal(GET_DOT11D_INFO(ieee_dev)->country_ie_src_addr, addr)
71DOT11D_GetMaxTxPwrInDbm( 40#define UPDATE_CIE_SRC(ieee_dev, addr) ether_addr_copy(GET_DOT11D_INFO(ieee_dev)->country_ie_src_addr, addr)
72 struct ieee80211_device *dev,
73 u8 Channel
74 );
75 41
76void 42#define GET_CIE_WATCHDOG(ieee_dev) (GET_DOT11D_INFO(ieee_dev)->country_ie_watchdog)
77DOT11D_ScanComplete( 43#define RESET_CIE_WATCHDOG(ieee_dev) (GET_CIE_WATCHDOG(ieee_dev) = 0)
78 struct ieee80211_device *dev 44#define UPDATE_CIE_WATCHDOG(ieee_dev) (++GET_CIE_WATCHDOG(ieee_dev))
79 );
80 45
81int IsLegalChannel( 46void rtl8192u_dot11d_init(struct ieee80211_device *dev);
82 struct ieee80211_device *dev, 47void dot11d_reset(struct ieee80211_device *dev);
83 u8 channel 48void dot11d_update_country_ie(struct ieee80211_device *dev,
84); 49 u8 *addr,
50 u16 coutry_ie_len,
51 u8 *coutry_ie);
52u8 dot11d_get_max_tx_pwr_in_dbm(struct ieee80211_device *dev, u8 channel);
53void dot11d_scan_complete(struct ieee80211_device *dev);
54int is_legal_channel(struct ieee80211_device *dev, u8 channel);
55int to_legal_channel(struct ieee80211_device *dev, u8 channel);
85 56
86int ToLegalChannel(
87 struct ieee80211_device *dev,
88 u8 channel
89);
90#endif /* #ifndef __INC_DOT11D_H */ 57#endif /* #ifndef __INC_DOT11D_H */
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211.h b/drivers/staging/rtl8192u/ieee80211/ieee80211.h
index 3cfeac0d7214..8aa536d79900 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211.h
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211.h
@@ -1329,8 +1329,13 @@ typedef enum _erp_t {
1329 1329
1330struct ieee80211_network { 1330struct ieee80211_network {
1331 /* These entries are used to identify a unique network */ 1331 /* These entries are used to identify a unique network */
1332 u8 bssid[ETH_ALEN]; 1332 u8 bssid[ETH_ALEN]; /* u16 aligned! */
1333 u8 channel; 1333 u8 channel;
1334
1335 // CCXv4 S59, MBSSID.
1336 bool bMBssidValid;
1337 u8 MBssid[ETH_ALEN]; /* u16 aligned! */
1338 u8 MBssidMask;
1334 /* Ensure null-terminated for any debug msgs */ 1339 /* Ensure null-terminated for any debug msgs */
1335 u8 ssid[IW_ESSID_MAX_SIZE + 1]; 1340 u8 ssid[IW_ESSID_MAX_SIZE + 1];
1336 u8 ssid_len; 1341 u8 ssid_len;
@@ -1341,10 +1346,6 @@ struct ieee80211_network {
1341 bool bCkipSupported; 1346 bool bCkipSupported;
1342 bool bCcxRmEnable; 1347 bool bCcxRmEnable;
1343 u16 CcxRmState[2]; 1348 u16 CcxRmState[2];
1344 // CCXv4 S59, MBSSID.
1345 bool bMBssidValid;
1346 u8 MBssidMask;
1347 u8 MBssid[6];
1348 // CCX 2 S38, WLAN Device Version Number element. Annie, 2006-08-20. 1349 // CCX 2 S38, WLAN Device Version Number element. Annie, 2006-08-20.
1349 bool bWithCcxVerNum; 1350 bool bWithCcxVerNum;
1350 u8 BssCcxVerNumber; 1351 u8 BssCcxVerNumber;
@@ -1771,7 +1772,7 @@ struct ieee80211_device {
1771 1772
1772 /* map of allowed channels. 0 is dummy */ 1773 /* map of allowed channels. 0 is dummy */
1773 // FIXME: remember to default to a basic channel plan depending of the PHY type 1774 // FIXME: remember to default to a basic channel plan depending of the PHY type
1774 void *pDot11dInfo; 1775 void *dot11d_info;
1775 bool bGlobalDomain; 1776 bool bGlobalDomain;
1776 int rate; /* current rate */ 1777 int rate; /* current rate */
1777 int basic_rate; 1778 int basic_rate;
@@ -2378,11 +2379,8 @@ u8 HTGetHighestMCSRate(struct ieee80211_device *ieee,
2378extern u8 MCS_FILTER_ALL[]; 2379extern u8 MCS_FILTER_ALL[];
2379extern u16 MCS_DATA_RATE[2][2][77]; 2380extern u16 MCS_DATA_RATE[2][2][77];
2380u8 HTCCheck(struct ieee80211_device *ieee, u8 *pFrame); 2381u8 HTCCheck(struct ieee80211_device *ieee, u8 *pFrame);
2381//extern void HTSetConnectBwModeCallback(unsigned long data);
2382void HTResetIOTSetting(PRT_HIGH_THROUGHPUT pHTInfo); 2382void HTResetIOTSetting(PRT_HIGH_THROUGHPUT pHTInfo);
2383bool IsHTHalfNmodeAPs(struct ieee80211_device *ieee); 2383bool IsHTHalfNmodeAPs(struct ieee80211_device *ieee);
2384u16 HTHalfMcsToDataRate(struct ieee80211_device *ieee, u8 nMcsRate);
2385u16 HTMcsToDataRate(struct ieee80211_device *ieee, u8 nMcsRate);
2386u16 TxCountToDataRate(struct ieee80211_device *ieee, u8 nDataRate); 2384u16 TxCountToDataRate(struct ieee80211_device *ieee, u8 nDataRate);
2387//function in BAPROC.c 2385//function in BAPROC.c
2388int ieee80211_rx_ADDBAReq(struct ieee80211_device *ieee, struct sk_buff *skb); 2386int ieee80211_rx_ADDBAReq(struct ieee80211_device *ieee, struct sk_buff *skb);
@@ -2395,7 +2393,7 @@ void TsInitDelBA(struct ieee80211_device *ieee,
2395void BaSetupTimeOut(struct timer_list *t); 2393void BaSetupTimeOut(struct timer_list *t);
2396void TxBaInactTimeout(struct timer_list *t); 2394void TxBaInactTimeout(struct timer_list *t);
2397void RxBaInactTimeout(struct timer_list *t); 2395void RxBaInactTimeout(struct timer_list *t);
2398void ResetBaEntry(PBA_RECORD pBA); 2396void ResetBaEntry(struct ba_record *pBA);
2399//function in TS.c 2397//function in TS.c
2400bool GetTs( 2398bool GetTs(
2401 struct ieee80211_device *ieee, 2399 struct ieee80211_device *ieee,
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
index 90a097f2cd4e..d7975aa335b2 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/******************************************************************************* 2/*******************************************************************************
2 * 3 *
3 * Copyright(c) 2004 Intel Corporation. All rights reserved. 4 * Copyright(c) 2004 Intel Corporation. All rights reserved.
@@ -28,10 +29,9 @@
28 * James P. Ketrenos <ipw2100-admin@linux.intel.com> 29 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 30 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 * 31 *
31 *******************************************************************************/ 32 ******************************************************************************/
32 33
33#include <linux/compiler.h> 34#include <linux/compiler.h>
34/* #include <linux/config.h> */
35#include <linux/errno.h> 35#include <linux/errno.h>
36#include <linux/if_arp.h> 36#include <linux/if_arp.h>
37#include <linux/in6.h> 37#include <linux/in6.h>
@@ -64,9 +64,9 @@ static inline int ieee80211_networks_allocate(struct ieee80211_device *ieee)
64 if (ieee->networks) 64 if (ieee->networks)
65 return 0; 65 return 0;
66 66
67 ieee->networks = kcalloc( 67 ieee->networks = kcalloc(MAX_NETWORK_COUNT,
68 MAX_NETWORK_COUNT, sizeof(struct ieee80211_network), 68 sizeof(struct ieee80211_network),
69 GFP_KERNEL); 69 GFP_KERNEL);
70 if (!ieee->networks) { 70 if (!ieee->networks) {
71 printk(KERN_WARNING "%s: Out of memory allocating beacons\n", 71 printk(KERN_WARNING "%s: Out of memory allocating beacons\n",
72 ieee->dev->name); 72 ieee->dev->name);
@@ -94,7 +94,6 @@ static inline void ieee80211_networks_initialize(struct ieee80211_device *ieee)
94 list_add_tail(&ieee->networks[i].list, &ieee->network_free_list); 94 list_add_tail(&ieee->networks[i].list, &ieee->network_free_list);
95} 95}
96 96
97
98struct net_device *alloc_ieee80211(int sizeof_priv) 97struct net_device *alloc_ieee80211(int sizeof_priv)
99{ 98{
100 struct ieee80211_device *ieee; 99 struct ieee80211_device *ieee;
@@ -110,7 +109,7 @@ struct net_device *alloc_ieee80211(int sizeof_priv)
110 } 109 }
111 110
112 ieee = netdev_priv(dev); 111 ieee = netdev_priv(dev);
113 memset(ieee, 0, sizeof(struct ieee80211_device)+sizeof_priv); 112 memset(ieee, 0, sizeof(struct ieee80211_device) + sizeof_priv);
114 ieee->dev = dev; 113 ieee->dev = dev;
115 114
116 err = ieee80211_networks_allocate(ieee); 115 err = ieee80211_networks_allocate(ieee);
@@ -121,7 +120,6 @@ struct net_device *alloc_ieee80211(int sizeof_priv)
121 } 120 }
122 ieee80211_networks_initialize(ieee); 121 ieee80211_networks_initialize(ieee);
123 122
124
125 /* Default fragmentation threshold is maximum payload size */ 123 /* Default fragmentation threshold is maximum payload size */
126 ieee->fts = DEFAULT_FTS; 124 ieee->fts = DEFAULT_FTS;
127 ieee->scan_age = DEFAULT_MAX_SCAN_AGE; 125 ieee->scan_age = DEFAULT_MAX_SCAN_AGE;
@@ -159,6 +157,11 @@ struct net_device *alloc_ieee80211(int sizeof_priv)
159 ieee->pHTInfo = kzalloc(sizeof(RT_HIGH_THROUGHPUT), GFP_KERNEL); 157 ieee->pHTInfo = kzalloc(sizeof(RT_HIGH_THROUGHPUT), GFP_KERNEL);
160 if (ieee->pHTInfo == NULL) { 158 if (ieee->pHTInfo == NULL) {
161 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't alloc memory for HTInfo\n"); 159 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't alloc memory for HTInfo\n");
160
161 /* By this point in code ieee80211_networks_allocate() has been
162 * successfully called so the memory allocated should be freed
163 */
164 ieee80211_networks_free(ieee);
162 goto failed; 165 goto failed;
163 } 166 }
164 HTUpdateDefaultSetting(ieee); 167 HTUpdateDefaultSetting(ieee);
@@ -169,9 +172,9 @@ struct net_device *alloc_ieee80211(int sizeof_priv)
169 INIT_LIST_HEAD(&ieee->ibss_mac_hash[i]); 172 INIT_LIST_HEAD(&ieee->ibss_mac_hash[i]);
170 173
171 for (i = 0; i < 17; i++) { 174 for (i = 0; i < 17; i++) {
172 ieee->last_rxseq_num[i] = -1; 175 ieee->last_rxseq_num[i] = -1;
173 ieee->last_rxfrag_num[i] = -1; 176 ieee->last_rxfrag_num[i] = -1;
174 ieee->last_packet_time[i] = 0; 177 ieee->last_packet_time[i] = 0;
175 } 178 }
176 179
177/* These function were added to load crypte module autoly */ 180/* These function were added to load crypte module autoly */
@@ -186,7 +189,6 @@ struct net_device *alloc_ieee80211(int sizeof_priv)
186 return NULL; 189 return NULL;
187} 190}
188 191
189
190void free_ieee80211(struct net_device *dev) 192void free_ieee80211(struct net_device *dev)
191{ 193{
192 struct ieee80211_device *ieee = netdev_priv(dev); 194 struct ieee80211_device *ieee = netdev_priv(dev);
@@ -202,6 +204,7 @@ void free_ieee80211(struct net_device *dev)
202 204
203 for (i = 0; i < WEP_KEYS; i++) { 205 for (i = 0; i < WEP_KEYS; i++) {
204 struct ieee80211_crypt_data *crypt = ieee->crypt[i]; 206 struct ieee80211_crypt_data *crypt = ieee->crypt[i];
207
205 if (crypt) { 208 if (crypt) {
206 if (crypt->ops) 209 if (crypt->ops)
207 crypt->ops->deinit(crypt->priv); 210 crypt->ops->deinit(crypt->priv);
@@ -217,8 +220,7 @@ void free_ieee80211(struct net_device *dev)
217#ifdef CONFIG_IEEE80211_DEBUG 220#ifdef CONFIG_IEEE80211_DEBUG
218 221
219u32 ieee80211_debug_level; 222u32 ieee80211_debug_level;
220static int debug = \ 223static int debug = // IEEE80211_DL_INFO |
221 // IEEE80211_DL_INFO |
222 // IEEE80211_DL_WX | 224 // IEEE80211_DL_WX |
223 // IEEE80211_DL_SCAN | 225 // IEEE80211_DL_SCAN |
224 // IEEE80211_DL_STATE | 226 // IEEE80211_DL_STATE |
@@ -247,10 +249,11 @@ static int show_debug_level(struct seq_file *m, void *v)
247} 249}
248 250
249static ssize_t write_debug_level(struct file *file, const char __user *buffer, 251static ssize_t write_debug_level(struct file *file, const char __user *buffer,
250 size_t count, loff_t *ppos) 252 size_t count, loff_t *ppos)
251{ 253{
252 unsigned long val; 254 unsigned long val;
253 int err = kstrtoul_from_user(buffer, count, 0, &val); 255 int err = kstrtoul_from_user(buffer, count, 0, &val);
256
254 if (err) 257 if (err)
255 return err; 258 return err;
256 ieee80211_debug_level = val; 259 ieee80211_debug_level = val;
@@ -277,7 +280,7 @@ int __init ieee80211_debug_init(void)
277 ieee80211_debug_level = debug; 280 ieee80211_debug_level = debug;
278 281
279 ieee80211_proc = proc_mkdir(DRV_NAME, init_net.proc_net); 282 ieee80211_proc = proc_mkdir(DRV_NAME, init_net.proc_net);
280 if (ieee80211_proc == NULL) { 283 if (!ieee80211_proc) {
281 IEEE80211_ERROR("Unable to create " DRV_NAME 284 IEEE80211_ERROR("Unable to create " DRV_NAME
282 " proc directory\n"); 285 " proc directory\n");
283 return -EIO; 286 return -EIO;
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
index 28cae82d795c..5147f7c01e31 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
@@ -794,7 +794,7 @@ static u8 parse_subframe(struct sk_buff *skb,
794 } 794 }
795 795
796 if (rx_stats->bContainHTC) { 796 if (rx_stats->bContainHTC) {
797 LLCOffset += sHTCLng; 797 LLCOffset += HTCLNG;
798 } 798 }
799 // Null packet, don't indicate it to upper layer 799 // Null packet, don't indicate it to upper layer
800 ChkLength = LLCOffset;/* + (Frame_WEP(frame)!=0 ?Adapter->MgntInfo.SecurityInfo.EncryptionHeadOverhead:0);*/ 800 ChkLength = LLCOffset;/* + (Frame_WEP(frame)!=0 ?Adapter->MgntInfo.SecurityInfo.EncryptionHeadOverhead:0);*/
@@ -1582,7 +1582,7 @@ static inline void ieee80211_extract_country_ie(
1582 1582
1583 if (!IS_COUNTRY_IE_VALID(ieee)) 1583 if (!IS_COUNTRY_IE_VALID(ieee))
1584 { 1584 {
1585 Dot11d_UpdateCountryIe(ieee, addr2, info_element->len, info_element->data); 1585 dot11d_update_country_ie(ieee, addr2, info_element->len, info_element->data);
1586 } 1586 }
1587 } 1587 }
1588 1588
@@ -1944,7 +1944,7 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee,
1944 { 1944 {
1945 network->bMBssidValid = true; 1945 network->bMBssidValid = true;
1946 network->MBssidMask = 0xff << (network->MBssidMask); 1946 network->MBssidMask = 0xff << (network->MBssidMask);
1947 cpMacAddr(network->MBssid, network->bssid); 1947 ether_addr_copy(network->MBssid, network->bssid);
1948 network->MBssid[5] &= network->MBssidMask; 1948 network->MBssid[5] &= network->MBssidMask;
1949 } 1949 }
1950 else 1950 else
@@ -2439,7 +2439,7 @@ static inline void ieee80211_process_probe_response(
2439 // then wireless adapter should do active scan from ch1~11 and 2439 // then wireless adapter should do active scan from ch1~11 and
2440 // passive scan from ch12~14 2440 // passive scan from ch12~14
2441 2441
2442 if (!IsLegalChannel(ieee, network->channel)) 2442 if (!is_legal_channel(ieee, network->channel))
2443 goto out; 2443 goto out;
2444 if (ieee->bGlobalDomain) 2444 if (ieee->bGlobalDomain)
2445 { 2445 {
@@ -2448,7 +2448,7 @@ static inline void ieee80211_process_probe_response(
2448 // Case 1: Country code 2448 // Case 1: Country code
2449 if(IS_COUNTRY_IE_VALID(ieee) ) 2449 if(IS_COUNTRY_IE_VALID(ieee) )
2450 { 2450 {
2451 if (!IsLegalChannel(ieee, network->channel)) { 2451 if (!is_legal_channel(ieee, network->channel)) {
2452 printk("GetScanInfo(): For Country code, filter probe response at channel(%d).\n", network->channel); 2452 printk("GetScanInfo(): For Country code, filter probe response at channel(%d).\n", network->channel);
2453 goto out; 2453 goto out;
2454 } 2454 }
@@ -2469,7 +2469,7 @@ static inline void ieee80211_process_probe_response(
2469 // Case 1: Country code 2469 // Case 1: Country code
2470 if(IS_COUNTRY_IE_VALID(ieee) ) 2470 if(IS_COUNTRY_IE_VALID(ieee) )
2471 { 2471 {
2472 if (!IsLegalChannel(ieee, network->channel)) { 2472 if (!is_legal_channel(ieee, network->channel)) {
2473 printk("GetScanInfo(): For Country code, filter beacon at channel(%d).\n",network->channel); 2473 printk("GetScanInfo(): For Country code, filter beacon at channel(%d).\n",network->channel);
2474 goto out; 2474 goto out;
2475 } 2475 }
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
index 212cc9ccbb96..8635faf84316 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
@@ -464,7 +464,7 @@ out:
464 } else { 464 } else {
465 ieee->sync_scan_hurryup = 0; 465 ieee->sync_scan_hurryup = 0;
466 if (IS_DOT11D_ENABLE(ieee)) 466 if (IS_DOT11D_ENABLE(ieee))
467 DOT11D_ScanComplete(ieee); 467 dot11d_scan_complete(ieee);
468 mutex_unlock(&ieee->scan_mutex); 468 mutex_unlock(&ieee->scan_mutex);
469 } 469 }
470} 470}
@@ -504,7 +504,7 @@ static void ieee80211_softmac_scan_wq(struct work_struct *work)
504 return; 504 return;
505out: 505out:
506 if (IS_DOT11D_ENABLE(ieee)) 506 if (IS_DOT11D_ENABLE(ieee))
507 DOT11D_ScanComplete(ieee); 507 dot11d_scan_complete(ieee);
508 ieee->actscanning = false; 508 ieee->actscanning = false;
509 watchdog = 0; 509 watchdog = 0;
510 ieee->scanning = 0; 510 ieee->scanning = 0;
@@ -2357,7 +2357,7 @@ void ieee80211_disassociate(struct ieee80211_device *ieee)
2357 if (ieee->data_hard_stop) 2357 if (ieee->data_hard_stop)
2358 ieee->data_hard_stop(ieee->dev); 2358 ieee->data_hard_stop(ieee->dev);
2359 if (IS_DOT11D_ENABLE(ieee)) 2359 if (IS_DOT11D_ENABLE(ieee))
2360 Dot11d_Reset(ieee); 2360 dot11d_reset(ieee);
2361 ieee->state = IEEE80211_NOLINK; 2361 ieee->state = IEEE80211_NOLINK;
2362 ieee->is_set_key = false; 2362 ieee->is_set_key = false;
2363 ieee->link_change(ieee->dev); 2363 ieee->link_change(ieee->dev);
@@ -2542,8 +2542,8 @@ void ieee80211_softmac_init(struct ieee80211_device *ieee)
2542 for (i = 0; i < 5; i++) 2542 for (i = 0; i < 5; i++)
2543 ieee->seq_ctrl[i] = 0; 2543 ieee->seq_ctrl[i] = 0;
2544 2544
2545 ieee->pDot11dInfo = kzalloc(sizeof(struct rt_dot11d_info), GFP_KERNEL); 2545 ieee->dot11d_info = kzalloc(sizeof(struct rt_dot11d_info), GFP_KERNEL);
2546 if (!ieee->pDot11dInfo) 2546 if (!ieee->dot11d_info)
2547 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't alloc memory for DOT11D\n"); 2547 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't alloc memory for DOT11D\n");
2548 //added for AP roaming 2548 //added for AP roaming
2549 ieee->LinkDetectInfo.SlotNum = 2; 2549 ieee->LinkDetectInfo.SlotNum = 2;
@@ -2603,8 +2603,8 @@ void ieee80211_softmac_init(struct ieee80211_device *ieee)
2603void ieee80211_softmac_free(struct ieee80211_device *ieee) 2603void ieee80211_softmac_free(struct ieee80211_device *ieee)
2604{ 2604{
2605 mutex_lock(&ieee->wx_mutex); 2605 mutex_lock(&ieee->wx_mutex);
2606 kfree(ieee->pDot11dInfo); 2606 kfree(ieee->dot11d_info);
2607 ieee->pDot11dInfo = NULL; 2607 ieee->dot11d_info = NULL;
2608 del_timer_sync(&ieee->associate_timer); 2608 del_timer_sync(&ieee->associate_timer);
2609 2609
2610 cancel_delayed_work(&ieee->associate_retry_wq); 2610 cancel_delayed_work(&ieee->associate_retry_wq);
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
index cc4049de975d..024fa2702546 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
@@ -335,14 +335,14 @@ static void ieee80211_tx_query_agg_cap(struct ieee80211_device *ieee,
335 printk("===>can't get TS\n"); 335 printk("===>can't get TS\n");
336 return; 336 return;
337 } 337 }
338 if (!pTxTs->tx_admitted_ba_record.bValid) 338 if (!pTxTs->tx_admitted_ba_record.valid)
339 { 339 {
340 TsStartAddBaProcess(ieee, pTxTs); 340 TsStartAddBaProcess(ieee, pTxTs);
341 goto FORCED_AGG_SETTING; 341 goto FORCED_AGG_SETTING;
342 } 342 }
343 else if (!pTxTs->using_ba) 343 else if (!pTxTs->using_ba)
344 { 344 {
345 if (SN_LESS(pTxTs->tx_admitted_ba_record.BaStartSeqCtrl.field.SeqNum, (pTxTs->tx_cur_seq + 1) % 4096)) 345 if (SN_LESS(pTxTs->tx_admitted_ba_record.start_seq_ctrl.field.seq_num, (pTxTs->tx_cur_seq + 1) % 4096))
346 pTxTs->using_ba = true; 346 pTxTs->using_ba = true;
347 else 347 else
348 goto FORCED_AGG_SETTING; 348 goto FORCED_AGG_SETTING;
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c
index f2fcdec9bd17..fa59c712c74b 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c
@@ -147,13 +147,13 @@ static inline char *rtl819x_translate_scan(struct ieee80211_device *ieee,
147 147
148 if (network->mode >= IEEE_N_24G)//add N rate here; 148 if (network->mode >= IEEE_N_24G)//add N rate here;
149 { 149 {
150 PHT_CAPABILITY_ELE ht_cap = NULL; 150 struct ht_capability_ele *ht_cap = NULL;
151 bool is40M = false, isShortGI = false; 151 bool is40M = false, isShortGI = false;
152 u8 max_mcs = 0; 152 u8 max_mcs = 0;
153 if (!memcmp(network->bssht.bdHTCapBuf, EWC11NHTCap, 4)) 153 if (!memcmp(network->bssht.bdHTCapBuf, EWC11NHTCap, 4))
154 ht_cap = (PHT_CAPABILITY_ELE)&network->bssht.bdHTCapBuf[4]; 154 ht_cap = (struct ht_capability_ele *)&network->bssht.bdHTCapBuf[4];
155 else 155 else
156 ht_cap = (PHT_CAPABILITY_ELE)&network->bssht.bdHTCapBuf[0]; 156 ht_cap = (struct ht_capability_ele *)&network->bssht.bdHTCapBuf[0];
157 is40M = (ht_cap->ChlWidth)?1:0; 157 is40M = (ht_cap->ChlWidth)?1:0;
158 isShortGI = (ht_cap->ChlWidth)? 158 isShortGI = (ht_cap->ChlWidth)?
159 ((ht_cap->ShortGI40Mhz)?1:0): 159 ((ht_cap->ShortGI40Mhz)?1:0):
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_BA.h b/drivers/staging/rtl8192u/ieee80211/rtl819x_BA.h
index b6a76aae4832..1a727856ba53 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_BA.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_BA.h
@@ -2,67 +2,53 @@
2#ifndef _BATYPE_H_ 2#ifndef _BATYPE_H_
3#define _BATYPE_H_ 3#define _BATYPE_H_
4 4
5#define TOTAL_TXBA_NUM 16 5#define BA_SETUP_TIMEOUT 200
6#define TOTAL_RXBA_NUM 16
7 6
8#define BA_SETUP_TIMEOUT 200 7#define BA_POLICY_DELAYED 0
9#define BA_INACT_TIMEOUT 60000 8#define BA_POLICY_IMMEDIATE 1
10 9
11#define BA_POLICY_DELAYED 0 10#define ADDBA_STATUS_SUCCESS 0
12#define BA_POLICY_IMMEDIATE 1
13
14#define ADDBA_STATUS_SUCCESS 0
15#define ADDBA_STATUS_REFUSED 37 11#define ADDBA_STATUS_REFUSED 37
16#define ADDBA_STATUS_INVALID_PARAM 38 12#define ADDBA_STATUS_INVALID_PARAM 38
17 13
18#define DELBA_REASON_QSTA_LEAVING 36 14#define DELBA_REASON_END_BA 37
19#define DELBA_REASON_END_BA 37 15#define DELBA_REASON_UNKNOWN_BA 38
20#define DELBA_REASON_UNKNOWN_BA 38 16#define DELBA_REASON_TIMEOUT 39
21#define DELBA_REASON_TIMEOUT 39 17
22/* whether need define BA Action frames here? 18union sequence_control {
23struct ieee80211_ADDBA_Req{ 19 u16 short_data;
24 struct ieee80211_header_data header;
25 u8 category;
26 u8
27} __attribute__ ((packed));
28*/
29//Is this need?I put here just to make it easier to define structure BA_RECORD //WB
30typedef union _SEQUENCE_CONTROL{
31 u16 ShortData;
32 struct { 20 struct {
33 u16 FragNum:4; 21 u16 frag_num:4;
34 u16 SeqNum:12; 22 u16 seq_num:12;
35 } field; 23 } field;
36} SEQUENCE_CONTROL, *PSEQUENCE_CONTROL; 24};
37 25
38typedef union _BA_PARAM_SET { 26union ba_param_set {
39 u8 charData[2]; 27 u16 short_data;
40 u16 shortData;
41 struct { 28 struct {
42 u16 AMSDU_Support:1; 29 u16 amsdu_support:1;
43 u16 BAPolicy:1; 30 u16 ba_policy:1;
44 u16 TID:4; 31 u16 tid:4;
45 u16 BufferSize:10; 32 u16 buffer_size:10;
46 } field; 33 } field;
47} BA_PARAM_SET, *PBA_PARAM_SET; 34};
48 35
49typedef union _DELBA_PARAM_SET { 36union delba_param_set {
50 u8 charData[2]; 37 u16 short_data;
51 u16 shortData;
52 struct { 38 struct {
53 u16 Reserved:11; 39 u16 reserved:11;
54 u16 Initiator:1; 40 u16 initiator:1;
55 u16 TID:4; 41 u16 tid:4;
56 } field; 42 } field;
57} DELBA_PARAM_SET, *PDELBA_PARAM_SET; 43};
58 44
59typedef struct _BA_RECORD { 45struct ba_record {
60 struct timer_list Timer; 46 struct timer_list timer;
61 u8 bValid; 47 u8 valid;
62 u8 DialogToken; 48 u8 dialog_token;
63 BA_PARAM_SET BaParamSet; 49 union ba_param_set param_set;
64 u16 BaTimeoutValue; 50 u16 timeout_value;
65 SEQUENCE_CONTROL BaStartSeqCtrl; 51 union sequence_control start_seq_ctrl;
66} BA_RECORD, *PBA_RECORD; 52};
67 53
68#endif //end _BATYPE_H_ 54#endif //end _BATYPE_H_
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c b/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c
index 01b631c2a180..109445407cec 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c
@@ -12,26 +12,26 @@
12 12
13/******************************************************************************************************************** 13/********************************************************************************************************************
14 *function: Activate BA entry. And if Time is nozero, start timer. 14 *function: Activate BA entry. And if Time is nozero, start timer.
15 * input: PBA_RECORD pBA //BA entry to be enabled 15 * input: struct ba_record *pBA //BA entry to be enabled
16 * u16 Time //indicate time delay. 16 * u16 Time //indicate time delay.
17 * output: none 17 * output: none
18 ********************************************************************************************************************/ 18 ********************************************************************************************************************/
19static void ActivateBAEntry(struct ieee80211_device *ieee, PBA_RECORD pBA, u16 Time) 19static void ActivateBAEntry(struct ieee80211_device *ieee, struct ba_record *pBA, u16 Time)
20{ 20{
21 pBA->bValid = true; 21 pBA->valid = true;
22 if (Time != 0) 22 if (Time != 0)
23 mod_timer(&pBA->Timer, jiffies + msecs_to_jiffies(Time)); 23 mod_timer(&pBA->timer, jiffies + msecs_to_jiffies(Time));
24} 24}
25 25
26/******************************************************************************************************************** 26/********************************************************************************************************************
27 *function: deactivate BA entry, including its timer. 27 *function: deactivate BA entry, including its timer.
28 * input: PBA_RECORD pBA //BA entry to be disabled 28 * input: struct ba_record *pBA //BA entry to be disabled
29 * output: none 29 * output: none
30 ********************************************************************************************************************/ 30 ********************************************************************************************************************/
31static void DeActivateBAEntry(struct ieee80211_device *ieee, PBA_RECORD pBA) 31static void DeActivateBAEntry(struct ieee80211_device *ieee, struct ba_record *pBA)
32{ 32{
33 pBA->bValid = false; 33 pBA->valid = false;
34 del_timer_sync(&pBA->Timer); 34 del_timer_sync(&pBA->timer);
35} 35}
36/******************************************************************************************************************** 36/********************************************************************************************************************
37 *function: deactivete BA entry in Tx Ts, and send DELBA. 37 *function: deactivete BA entry in Tx Ts, and send DELBA.
@@ -42,18 +42,18 @@ static void DeActivateBAEntry(struct ieee80211_device *ieee, PBA_RECORD pBA)
42 ********************************************************************************************************************/ 42 ********************************************************************************************************************/
43static u8 TxTsDeleteBA(struct ieee80211_device *ieee, struct tx_ts_record *pTxTs) 43static u8 TxTsDeleteBA(struct ieee80211_device *ieee, struct tx_ts_record *pTxTs)
44{ 44{
45 PBA_RECORD pAdmittedBa = &pTxTs->tx_admitted_ba_record; //These two BA entries must exist in TS structure 45 struct ba_record *pAdmittedBa = &pTxTs->tx_admitted_ba_record; //These two BA entries must exist in TS structure
46 PBA_RECORD pPendingBa = &pTxTs->tx_pending_ba_record; 46 struct ba_record *pPendingBa = &pTxTs->tx_pending_ba_record;
47 u8 bSendDELBA = false; 47 u8 bSendDELBA = false;
48 48
49 // Delete pending BA 49 // Delete pending BA
50 if (pPendingBa->bValid) { 50 if (pPendingBa->valid) {
51 DeActivateBAEntry(ieee, pPendingBa); 51 DeActivateBAEntry(ieee, pPendingBa);
52 bSendDELBA = true; 52 bSendDELBA = true;
53 } 53 }
54 54
55 // Delete admitted BA 55 // Delete admitted BA
56 if (pAdmittedBa->bValid) { 56 if (pAdmittedBa->valid) {
57 DeActivateBAEntry(ieee, pAdmittedBa); 57 DeActivateBAEntry(ieee, pAdmittedBa);
58 bSendDELBA = true; 58 bSendDELBA = true;
59 } 59 }
@@ -70,10 +70,10 @@ static u8 TxTsDeleteBA(struct ieee80211_device *ieee, struct tx_ts_record *pTxTs
70 ********************************************************************************************************************/ 70 ********************************************************************************************************************/
71static u8 RxTsDeleteBA(struct ieee80211_device *ieee, struct rx_ts_record *pRxTs) 71static u8 RxTsDeleteBA(struct ieee80211_device *ieee, struct rx_ts_record *pRxTs)
72{ 72{
73 PBA_RECORD pBa = &pRxTs->rx_admitted_ba_record; 73 struct ba_record *pBa = &pRxTs->rx_admitted_ba_record;
74 u8 bSendDELBA = false; 74 u8 bSendDELBA = false;
75 75
76 if (pBa->bValid) { 76 if (pBa->valid) {
77 DeActivateBAEntry(ieee, pBa); 77 DeActivateBAEntry(ieee, pBa);
78 bSendDELBA = true; 78 bSendDELBA = true;
79 } 79 }
@@ -84,28 +84,28 @@ static u8 RxTsDeleteBA(struct ieee80211_device *ieee, struct rx_ts_record *pRxTs
84/******************************************************************************************************************** 84/********************************************************************************************************************
85 *function: reset BA entry 85 *function: reset BA entry
86 * input: 86 * input:
87 * PBA_RECORD pBA //entry to be reset 87 * struct ba_record *pBA //entry to be reset
88 * output: none 88 * output: none
89 ********************************************************************************************************************/ 89 ********************************************************************************************************************/
90void ResetBaEntry(PBA_RECORD pBA) 90void ResetBaEntry(struct ba_record *pBA)
91{ 91{
92 pBA->bValid = false; 92 pBA->valid = false;
93 pBA->BaParamSet.shortData = 0; 93 pBA->param_set.short_data = 0;
94 pBA->BaTimeoutValue = 0; 94 pBA->timeout_value = 0;
95 pBA->DialogToken = 0; 95 pBA->dialog_token = 0;
96 pBA->BaStartSeqCtrl.ShortData = 0; 96 pBA->start_seq_ctrl.short_data = 0;
97} 97}
98//These functions need porting here or not? 98//These functions need porting here or not?
99/******************************************************************************************************************************* 99/*******************************************************************************************************************************
100 *function: construct ADDBAREQ and ADDBARSP frame here together. 100 *function: construct ADDBAREQ and ADDBARSP frame here together.
101 * input: u8* Dst //ADDBA frame's destination 101 * input: u8* Dst //ADDBA frame's destination
102 * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA. 102 * struct ba_record *pBA //BA_RECORD entry which stores the necessary information for BA.
103 * u16 StatusCode //status code in RSP and I will use it to indicate whether it's RSP or REQ(will I?) 103 * u16 StatusCode //status code in RSP and I will use it to indicate whether it's RSP or REQ(will I?)
104 * u8 type //indicate whether it's RSP(ACT_ADDBARSP) ow REQ(ACT_ADDBAREQ) 104 * u8 type //indicate whether it's RSP(ACT_ADDBARSP) ow REQ(ACT_ADDBAREQ)
105 * output: none 105 * output: none
106 * return: sk_buff* skb //return constructed skb to xmit 106 * return: sk_buff* skb //return constructed skb to xmit
107 *******************************************************************************************************************************/ 107 *******************************************************************************************************************************/
108static struct sk_buff *ieee80211_ADDBA(struct ieee80211_device *ieee, u8 *Dst, PBA_RECORD pBA, u16 StatusCode, u8 type) 108static struct sk_buff *ieee80211_ADDBA(struct ieee80211_device *ieee, u8 *Dst, struct ba_record *pBA, u16 StatusCode, u8 type)
109{ 109{
110 struct sk_buff *skb = NULL; 110 struct sk_buff *skb = NULL;
111 struct rtl_80211_hdr_3addr *BAReq = NULL; 111 struct rtl_80211_hdr_3addr *BAReq = NULL;
@@ -140,7 +140,7 @@ static struct sk_buff *ieee80211_ADDBA(struct ieee80211_device *ieee, u8 *Dst, P
140 *tag++ = ACT_CAT_BA; 140 *tag++ = ACT_CAT_BA;
141 *tag++ = type; 141 *tag++ = type;
142 // Dialog Token 142 // Dialog Token
143 *tag++ = pBA->DialogToken; 143 *tag++ = pBA->dialog_token;
144 144
145 if (ACT_ADDBARSP == type) { 145 if (ACT_ADDBARSP == type) {
146 // Status Code 146 // Status Code
@@ -151,16 +151,16 @@ static struct sk_buff *ieee80211_ADDBA(struct ieee80211_device *ieee, u8 *Dst, P
151 } 151 }
152 // BA Parameter Set 152 // BA Parameter Set
153 153
154 put_unaligned_le16(pBA->BaParamSet.shortData, tag); 154 put_unaligned_le16(pBA->param_set.short_data, tag);
155 tag += 2; 155 tag += 2;
156 // BA Timeout Value 156 // BA Timeout Value
157 157
158 put_unaligned_le16(pBA->BaTimeoutValue, tag); 158 put_unaligned_le16(pBA->timeout_value, tag);
159 tag += 2; 159 tag += 2;
160 160
161 if (ACT_ADDBAREQ == type) { 161 if (ACT_ADDBAREQ == type) {
162 // BA Start SeqCtrl 162 // BA Start SeqCtrl
163 memcpy(tag, (u8 *)&(pBA->BaStartSeqCtrl), 2); 163 memcpy(tag, (u8 *)&(pBA->start_seq_ctrl), 2);
164 tag += 2; 164 tag += 2;
165 } 165 }
166 166
@@ -173,7 +173,7 @@ static struct sk_buff *ieee80211_ADDBA(struct ieee80211_device *ieee, u8 *Dst, P
173/******************************************************************************************************************** 173/********************************************************************************************************************
174 *function: construct DELBA frame 174 *function: construct DELBA frame
175 * input: u8* dst //DELBA frame's destination 175 * input: u8* dst //DELBA frame's destination
176 * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA 176 * struct ba_record *pBA //BA_RECORD entry which stores the necessary information for BA
177 * enum tr_select TxRxSelect //TX RX direction 177 * enum tr_select TxRxSelect //TX RX direction
178 * u16 ReasonCode //status code. 178 * u16 ReasonCode //status code.
179 * output: none 179 * output: none
@@ -182,12 +182,12 @@ static struct sk_buff *ieee80211_ADDBA(struct ieee80211_device *ieee, u8 *Dst, P
182static struct sk_buff *ieee80211_DELBA( 182static struct sk_buff *ieee80211_DELBA(
183 struct ieee80211_device *ieee, 183 struct ieee80211_device *ieee,
184 u8 *dst, 184 u8 *dst,
185 PBA_RECORD pBA, 185 struct ba_record *pBA,
186 enum tr_select TxRxSelect, 186 enum tr_select TxRxSelect,
187 u16 ReasonCode 187 u16 ReasonCode
188 ) 188 )
189{ 189{
190 DELBA_PARAM_SET DelbaParamSet; 190 union delba_param_set DelbaParamSet;
191 struct sk_buff *skb = NULL; 191 struct sk_buff *skb = NULL;
192 struct rtl_80211_hdr_3addr *Delba = NULL; 192 struct rtl_80211_hdr_3addr *Delba = NULL;
193 u8 *tag = NULL; 193 u8 *tag = NULL;
@@ -201,8 +201,8 @@ static struct sk_buff *ieee80211_DELBA(
201 201
202 memset(&DelbaParamSet, 0, 2); 202 memset(&DelbaParamSet, 0, 2);
203 203
204 DelbaParamSet.field.Initiator = (TxRxSelect == TX_DIR) ? 1 : 0; 204 DelbaParamSet.field.initiator = (TxRxSelect == TX_DIR) ? 1 : 0;
205 DelbaParamSet.field.TID = pBA->BaParamSet.field.TID; 205 DelbaParamSet.field.tid = pBA->param_set.field.tid;
206 206
207 skb = dev_alloc_skb(len + sizeof(struct rtl_80211_hdr_3addr)); //need to add something others? FIXME 207 skb = dev_alloc_skb(len + sizeof(struct rtl_80211_hdr_3addr)); //need to add something others? FIXME
208 if (!skb) { 208 if (!skb) {
@@ -226,7 +226,7 @@ static struct sk_buff *ieee80211_DELBA(
226 226
227 // DELBA Parameter Set 227 // DELBA Parameter Set
228 228
229 put_unaligned_le16(DelbaParamSet.shortData, tag); 229 put_unaligned_le16(DelbaParamSet.short_data, tag);
230 tag += 2; 230 tag += 2;
231 // Reason Code 231 // Reason Code
232 232
@@ -243,12 +243,12 @@ static struct sk_buff *ieee80211_DELBA(
243/******************************************************************************************************************** 243/********************************************************************************************************************
244 *function: send ADDBAReq frame out 244 *function: send ADDBAReq frame out
245 * input: u8* dst //ADDBAReq frame's destination 245 * input: u8* dst //ADDBAReq frame's destination
246 * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA 246 * struct ba_record *pBA //BA_RECORD entry which stores the necessary information for BA
247 * output: none 247 * output: none
248 * notice: If any possible, please hide pBA in ieee. And temporarily use Manage Queue as softmac_mgmt_xmit() usually does 248 * notice: If any possible, please hide pBA in ieee. And temporarily use Manage Queue as softmac_mgmt_xmit() usually does
249 ********************************************************************************************************************/ 249 ********************************************************************************************************************/
250static void ieee80211_send_ADDBAReq(struct ieee80211_device *ieee, 250static void ieee80211_send_ADDBAReq(struct ieee80211_device *ieee,
251 u8 *dst, PBA_RECORD pBA) 251 u8 *dst, struct ba_record *pBA)
252{ 252{
253 struct sk_buff *skb; 253 struct sk_buff *skb;
254 skb = ieee80211_ADDBA(ieee, dst, pBA, 0, ACT_ADDBAREQ); //construct ACT_ADDBAREQ frames so set statuscode zero. 254 skb = ieee80211_ADDBA(ieee, dst, pBA, 0, ACT_ADDBAREQ); //construct ACT_ADDBAREQ frames so set statuscode zero.
@@ -266,13 +266,13 @@ static void ieee80211_send_ADDBAReq(struct ieee80211_device *ieee,
266/******************************************************************************************************************** 266/********************************************************************************************************************
267 *function: send ADDBARSP frame out 267 *function: send ADDBARSP frame out
268 * input: u8* dst //DELBA frame's destination 268 * input: u8* dst //DELBA frame's destination
269 * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA 269 * struct ba_record *pBA //BA_RECORD entry which stores the necessary information for BA
270 * u16 StatusCode //RSP StatusCode 270 * u16 StatusCode //RSP StatusCode
271 * output: none 271 * output: none
272 * notice: If any possible, please hide pBA in ieee. And temporarily use Manage Queue as softmac_mgmt_xmit() usually does 272 * notice: If any possible, please hide pBA in ieee. And temporarily use Manage Queue as softmac_mgmt_xmit() usually does
273 ********************************************************************************************************************/ 273 ********************************************************************************************************************/
274static void ieee80211_send_ADDBARsp(struct ieee80211_device *ieee, u8 *dst, 274static void ieee80211_send_ADDBARsp(struct ieee80211_device *ieee, u8 *dst,
275 PBA_RECORD pBA, u16 StatusCode) 275 struct ba_record *pBA, u16 StatusCode)
276{ 276{
277 struct sk_buff *skb; 277 struct sk_buff *skb;
278 skb = ieee80211_ADDBA(ieee, dst, pBA, StatusCode, ACT_ADDBARSP); //construct ACT_ADDBARSP frames 278 skb = ieee80211_ADDBA(ieee, dst, pBA, StatusCode, ACT_ADDBARSP); //construct ACT_ADDBARSP frames
@@ -289,7 +289,7 @@ static void ieee80211_send_ADDBARsp(struct ieee80211_device *ieee, u8 *dst,
289/******************************************************************************************************************** 289/********************************************************************************************************************
290 *function: send ADDBARSP frame out 290 *function: send ADDBARSP frame out
291 * input: u8* dst //DELBA frame's destination 291 * input: u8* dst //DELBA frame's destination
292 * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA 292 * struct ba_record *pBA //BA_RECORD entry which stores the necessary information for BA
293 * enum tr_select TxRxSelect //TX or RX 293 * enum tr_select TxRxSelect //TX or RX
294 * u16 ReasonCode //DEL ReasonCode 294 * u16 ReasonCode //DEL ReasonCode
295 * output: none 295 * output: none
@@ -297,7 +297,7 @@ static void ieee80211_send_ADDBARsp(struct ieee80211_device *ieee, u8 *dst,
297 ********************************************************************************************************************/ 297 ********************************************************************************************************************/
298 298
299static void ieee80211_send_DELBA(struct ieee80211_device *ieee, u8 *dst, 299static void ieee80211_send_DELBA(struct ieee80211_device *ieee, u8 *dst,
300 PBA_RECORD pBA, enum tr_select TxRxSelect, 300 struct ba_record *pBA, enum tr_select TxRxSelect,
301 u16 ReasonCode) 301 u16 ReasonCode)
302{ 302{
303 struct sk_buff *skb; 303 struct sk_buff *skb;
@@ -321,10 +321,10 @@ int ieee80211_rx_ADDBAReq(struct ieee80211_device *ieee, struct sk_buff *skb)
321 struct rtl_80211_hdr_3addr *req = NULL; 321 struct rtl_80211_hdr_3addr *req = NULL;
322 u16 rc = 0; 322 u16 rc = 0;
323 u8 *dst = NULL, *pDialogToken = NULL, *tag = NULL; 323 u8 *dst = NULL, *pDialogToken = NULL, *tag = NULL;
324 PBA_RECORD pBA = NULL; 324 struct ba_record *pBA = NULL;
325 PBA_PARAM_SET pBaParamSet = NULL; 325 union ba_param_set *pBaParamSet = NULL;
326 u16 *pBaTimeoutVal = NULL; 326 u16 *pBaTimeoutVal = NULL;
327 PSEQUENCE_CONTROL pBaStartSeqCtrl = NULL; 327 union sequence_control *pBaStartSeqCtrl = NULL;
328 struct rx_ts_record *pTS = NULL; 328 struct rx_ts_record *pTS = NULL;
329 329
330 if (skb->len < sizeof(struct rtl_80211_hdr_3addr) + 9) { 330 if (skb->len < sizeof(struct rtl_80211_hdr_3addr) + 9) {
@@ -342,9 +342,9 @@ int ieee80211_rx_ADDBAReq(struct ieee80211_device *ieee, struct sk_buff *skb)
342 dst = &req->addr2[0]; 342 dst = &req->addr2[0];
343 tag += sizeof(struct rtl_80211_hdr_3addr); 343 tag += sizeof(struct rtl_80211_hdr_3addr);
344 pDialogToken = tag + 2; //category+action 344 pDialogToken = tag + 2; //category+action
345 pBaParamSet = (PBA_PARAM_SET)(tag + 3); //+DialogToken 345 pBaParamSet = (union ba_param_set *)(tag + 3); //+DialogToken
346 pBaTimeoutVal = (u16 *)(tag + 5); 346 pBaTimeoutVal = (u16 *)(tag + 5);
347 pBaStartSeqCtrl = (PSEQUENCE_CONTROL)(req + 7); 347 pBaStartSeqCtrl = (union sequence_control *)(req + 7);
348 348
349 netdev_info(ieee->dev, "====================>rx ADDBAREQ from :%pM\n", dst); 349 netdev_info(ieee->dev, "====================>rx ADDBAREQ from :%pM\n", dst);
350//some other capability is not ready now. 350//some other capability is not ready now.
@@ -362,7 +362,7 @@ int ieee80211_rx_ADDBAReq(struct ieee80211_device *ieee, struct sk_buff *skb)
362 ieee, 362 ieee,
363 (struct ts_common_info **)(&pTS), 363 (struct ts_common_info **)(&pTS),
364 dst, 364 dst,
365 (u8)(pBaParamSet->field.TID), 365 (u8)(pBaParamSet->field.tid),
366 RX_DIR, 366 RX_DIR,
367 true)) { 367 true)) {
368 rc = ADDBA_STATUS_REFUSED; 368 rc = ADDBA_STATUS_REFUSED;
@@ -371,10 +371,10 @@ int ieee80211_rx_ADDBAReq(struct ieee80211_device *ieee, struct sk_buff *skb)
371 } 371 }
372 pBA = &pTS->rx_admitted_ba_record; 372 pBA = &pTS->rx_admitted_ba_record;
373 // To Determine the ADDBA Req content 373 // To Determine the ADDBA Req content
374 // We can do much more check here, including BufferSize, AMSDU_Support, Policy, StartSeqCtrl... 374 // We can do much more check here, including buffer_size, AMSDU_Support, Policy, StartSeqCtrl...
375 // I want to check StartSeqCtrl to make sure when we start aggregation!!! 375 // I want to check StartSeqCtrl to make sure when we start aggregation!!!
376 // 376 //
377 if (pBaParamSet->field.BAPolicy == BA_POLICY_DELAYED) { 377 if (pBaParamSet->field.ba_policy == BA_POLICY_DELAYED) {
378 rc = ADDBA_STATUS_INVALID_PARAM; 378 rc = ADDBA_STATUS_INVALID_PARAM;
379 IEEE80211_DEBUG(IEEE80211_DL_ERR, "BA Policy is not correct in %s()\n", __func__); 379 IEEE80211_DEBUG(IEEE80211_DL_ERR, "BA Policy is not correct in %s()\n", __func__);
380 goto OnADDBAReq_Fail; 380 goto OnADDBAReq_Fail;
@@ -382,16 +382,16 @@ int ieee80211_rx_ADDBAReq(struct ieee80211_device *ieee, struct sk_buff *skb)
382 // Admit the ADDBA Request 382 // Admit the ADDBA Request
383 // 383 //
384 DeActivateBAEntry(ieee, pBA); 384 DeActivateBAEntry(ieee, pBA);
385 pBA->DialogToken = *pDialogToken; 385 pBA->dialog_token = *pDialogToken;
386 pBA->BaParamSet = *pBaParamSet; 386 pBA->param_set = *pBaParamSet;
387 pBA->BaTimeoutValue = *pBaTimeoutVal; 387 pBA->timeout_value = *pBaTimeoutVal;
388 pBA->BaStartSeqCtrl = *pBaStartSeqCtrl; 388 pBA->start_seq_ctrl = *pBaStartSeqCtrl;
389 //for half N mode we only aggregate 1 frame 389 //for half N mode we only aggregate 1 frame
390 if (ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) 390 if (ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev))
391 pBA->BaParamSet.field.BufferSize = 1; 391 pBA->param_set.field.buffer_size = 1;
392 else 392 else
393 pBA->BaParamSet.field.BufferSize = 32; 393 pBA->param_set.field.buffer_size = 32;
394 ActivateBAEntry(ieee, pBA, pBA->BaTimeoutValue); 394 ActivateBAEntry(ieee, pBA, pBA->timeout_value);
395 ieee80211_send_ADDBARsp(ieee, dst, pBA, ADDBA_STATUS_SUCCESS); 395 ieee80211_send_ADDBARsp(ieee, dst, pBA, ADDBA_STATUS_SUCCESS);
396 396
397 // End of procedure. 397 // End of procedure.
@@ -399,11 +399,11 @@ int ieee80211_rx_ADDBAReq(struct ieee80211_device *ieee, struct sk_buff *skb)
399 399
400OnADDBAReq_Fail: 400OnADDBAReq_Fail:
401 { 401 {
402 BA_RECORD BA; 402 struct ba_record BA;
403 BA.BaParamSet = *pBaParamSet; 403 BA.param_set = *pBaParamSet;
404 BA.BaTimeoutValue = *pBaTimeoutVal; 404 BA.timeout_value = *pBaTimeoutVal;
405 BA.DialogToken = *pDialogToken; 405 BA.dialog_token = *pDialogToken;
406 BA.BaParamSet.field.BAPolicy = BA_POLICY_IMMEDIATE; 406 BA.param_set.field.ba_policy = BA_POLICY_IMMEDIATE;
407 ieee80211_send_ADDBARsp(ieee, dst, &BA, rc); 407 ieee80211_send_ADDBARsp(ieee, dst, &BA, rc);
408 return 0; //we send RSP out. 408 return 0; //we send RSP out.
409 } 409 }
@@ -419,11 +419,11 @@ OnADDBAReq_Fail:
419int ieee80211_rx_ADDBARsp(struct ieee80211_device *ieee, struct sk_buff *skb) 419int ieee80211_rx_ADDBARsp(struct ieee80211_device *ieee, struct sk_buff *skb)
420{ 420{
421 struct rtl_80211_hdr_3addr *rsp = NULL; 421 struct rtl_80211_hdr_3addr *rsp = NULL;
422 PBA_RECORD pPendingBA, pAdmittedBA; 422 struct ba_record *pPendingBA, *pAdmittedBA;
423 struct tx_ts_record *pTS = NULL; 423 struct tx_ts_record *pTS = NULL;
424 u8 *dst = NULL, *pDialogToken = NULL, *tag = NULL; 424 u8 *dst = NULL, *pDialogToken = NULL, *tag = NULL;
425 u16 *pStatusCode = NULL, *pBaTimeoutVal = NULL; 425 u16 *pStatusCode = NULL, *pBaTimeoutVal = NULL;
426 PBA_PARAM_SET pBaParamSet = NULL; 426 union ba_param_set *pBaParamSet = NULL;
427 u16 ReasonCode; 427 u16 ReasonCode;
428 428
429 if (skb->len < sizeof(struct rtl_80211_hdr_3addr) + 9) { 429 if (skb->len < sizeof(struct rtl_80211_hdr_3addr) + 9) {
@@ -439,7 +439,7 @@ int ieee80211_rx_ADDBARsp(struct ieee80211_device *ieee, struct sk_buff *skb)
439 tag += sizeof(struct rtl_80211_hdr_3addr); 439 tag += sizeof(struct rtl_80211_hdr_3addr);
440 pDialogToken = tag + 2; 440 pDialogToken = tag + 2;
441 pStatusCode = (u16 *)(tag + 3); 441 pStatusCode = (u16 *)(tag + 3);
442 pBaParamSet = (PBA_PARAM_SET)(tag + 5); 442 pBaParamSet = (union ba_param_set *)(tag + 5);
443 pBaTimeoutVal = (u16 *)(tag + 7); 443 pBaTimeoutVal = (u16 *)(tag + 7);
444 444
445 // Check the capability 445 // Check the capability
@@ -461,7 +461,7 @@ int ieee80211_rx_ADDBARsp(struct ieee80211_device *ieee, struct sk_buff *skb)
461 ieee, 461 ieee,
462 (struct ts_common_info **)(&pTS), 462 (struct ts_common_info **)(&pTS),
463 dst, 463 dst,
464 (u8)(pBaParamSet->field.TID), 464 (u8)(pBaParamSet->field.tid),
465 TX_DIR, 465 TX_DIR,
466 false)) { 466 false)) {
467 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't get TS in %s()\n", __func__); 467 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't get TS in %s()\n", __func__);
@@ -478,11 +478,11 @@ int ieee80211_rx_ADDBARsp(struct ieee80211_device *ieee, struct sk_buff *skb)
478 // Check if related BA is waiting for setup. 478 // Check if related BA is waiting for setup.
479 // If not, reject by sending DELBA frame. 479 // If not, reject by sending DELBA frame.
480 // 480 //
481 if (pAdmittedBA->bValid) { 481 if (pAdmittedBA->valid) {
482 // Since BA is already setup, we ignore all other ADDBA Response. 482 // Since BA is already setup, we ignore all other ADDBA Response.
483 IEEE80211_DEBUG(IEEE80211_DL_BA, "OnADDBARsp(): Recv ADDBA Rsp. Drop because already admit it! \n"); 483 IEEE80211_DEBUG(IEEE80211_DL_BA, "OnADDBARsp(): Recv ADDBA Rsp. Drop because already admit it! \n");
484 return -1; 484 return -1;
485 } else if ((!pPendingBA->bValid) || (*pDialogToken != pPendingBA->DialogToken)) { 485 } else if ((!pPendingBA->valid) || (*pDialogToken != pPendingBA->dialog_token)) {
486 IEEE80211_DEBUG(IEEE80211_DL_ERR, "OnADDBARsp(): Recv ADDBA Rsp. BA invalid, DELBA! \n"); 486 IEEE80211_DEBUG(IEEE80211_DL_ERR, "OnADDBARsp(): Recv ADDBA Rsp. BA invalid, DELBA! \n");
487 ReasonCode = DELBA_REASON_UNKNOWN_BA; 487 ReasonCode = DELBA_REASON_UNKNOWN_BA;
488 goto OnADDBARsp_Reject; 488 goto OnADDBARsp_Reject;
@@ -498,7 +498,7 @@ int ieee80211_rx_ADDBARsp(struct ieee80211_device *ieee, struct sk_buff *skb)
498 // We can compare the value of BA parameter set that Peer returned and Self sent. 498 // We can compare the value of BA parameter set that Peer returned and Self sent.
499 // If it is OK, then admitted. Or we can send DELBA to cancel BA mechanism. 499 // If it is OK, then admitted. Or we can send DELBA to cancel BA mechanism.
500 // 500 //
501 if (pBaParamSet->field.BAPolicy == BA_POLICY_DELAYED) { 501 if (pBaParamSet->field.ba_policy == BA_POLICY_DELAYED) {
502 // Since this is a kind of ADDBA failed, we delay next ADDBA process. 502 // Since this is a kind of ADDBA failed, we delay next ADDBA process.
503 pTS->add_ba_req_delayed = true; 503 pTS->add_ba_req_delayed = true;
504 DeActivateBAEntry(ieee, pAdmittedBA); 504 DeActivateBAEntry(ieee, pAdmittedBA);
@@ -510,10 +510,10 @@ int ieee80211_rx_ADDBARsp(struct ieee80211_device *ieee, struct sk_buff *skb)
510 // 510 //
511 // Admitted condition 511 // Admitted condition
512 // 512 //
513 pAdmittedBA->DialogToken = *pDialogToken; 513 pAdmittedBA->dialog_token = *pDialogToken;
514 pAdmittedBA->BaTimeoutValue = *pBaTimeoutVal; 514 pAdmittedBA->timeout_value = *pBaTimeoutVal;
515 pAdmittedBA->BaStartSeqCtrl = pPendingBA->BaStartSeqCtrl; 515 pAdmittedBA->start_seq_ctrl = pPendingBA->start_seq_ctrl;
516 pAdmittedBA->BaParamSet = *pBaParamSet; 516 pAdmittedBA->param_set = *pBaParamSet;
517 DeActivateBAEntry(ieee, pAdmittedBA); 517 DeActivateBAEntry(ieee, pAdmittedBA);
518 ActivateBAEntry(ieee, pAdmittedBA, *pBaTimeoutVal); 518 ActivateBAEntry(ieee, pAdmittedBA, *pBaTimeoutVal);
519 } else { 519 } else {
@@ -526,8 +526,8 @@ int ieee80211_rx_ADDBARsp(struct ieee80211_device *ieee, struct sk_buff *skb)
526 526
527OnADDBARsp_Reject: 527OnADDBARsp_Reject:
528 { 528 {
529 BA_RECORD BA; 529 struct ba_record BA;
530 BA.BaParamSet = *pBaParamSet; 530 BA.param_set = *pBaParamSet;
531 ieee80211_send_DELBA(ieee, dst, &BA, TX_DIR, ReasonCode); 531 ieee80211_send_DELBA(ieee, dst, &BA, TX_DIR, ReasonCode);
532 return 0; 532 return 0;
533 } 533 }
@@ -543,7 +543,7 @@ OnADDBARsp_Reject:
543int ieee80211_rx_DELBA(struct ieee80211_device *ieee, struct sk_buff *skb) 543int ieee80211_rx_DELBA(struct ieee80211_device *ieee, struct sk_buff *skb)
544{ 544{
545 struct rtl_80211_hdr_3addr *delba = NULL; 545 struct rtl_80211_hdr_3addr *delba = NULL;
546 PDELBA_PARAM_SET pDelBaParamSet = NULL; 546 union delba_param_set *pDelBaParamSet = NULL;
547 u8 *dst = NULL; 547 u8 *dst = NULL;
548 548
549 if (skb->len < sizeof(struct rtl_80211_hdr_3addr) + 6) { 549 if (skb->len < sizeof(struct rtl_80211_hdr_3addr) + 6) {
@@ -563,16 +563,16 @@ int ieee80211_rx_DELBA(struct ieee80211_device *ieee, struct sk_buff *skb)
563 IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA|IEEE80211_DL_BA, skb->data, skb->len); 563 IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA|IEEE80211_DL_BA, skb->data, skb->len);
564 delba = (struct rtl_80211_hdr_3addr *)skb->data; 564 delba = (struct rtl_80211_hdr_3addr *)skb->data;
565 dst = &delba->addr2[0]; 565 dst = &delba->addr2[0];
566 pDelBaParamSet = (PDELBA_PARAM_SET)&delba->payload[2]; 566 pDelBaParamSet = (union delba_param_set *)&delba->payload[2];
567 567
568 if (pDelBaParamSet->field.Initiator == 1) { 568 if (pDelBaParamSet->field.initiator == 1) {
569 struct rx_ts_record *pRxTs; 569 struct rx_ts_record *pRxTs;
570 570
571 if (!GetTs( 571 if (!GetTs(
572 ieee, 572 ieee,
573 (struct ts_common_info **)&pRxTs, 573 (struct ts_common_info **)&pRxTs,
574 dst, 574 dst,
575 (u8)pDelBaParamSet->field.TID, 575 (u8)pDelBaParamSet->field.tid,
576 RX_DIR, 576 RX_DIR,
577 false)) { 577 false)) {
578 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't get TS for RXTS in %s()\n", __func__); 578 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't get TS for RXTS in %s()\n", __func__);
@@ -587,7 +587,7 @@ int ieee80211_rx_DELBA(struct ieee80211_device *ieee, struct sk_buff *skb)
587 ieee, 587 ieee,
588 (struct ts_common_info **)&pTxTs, 588 (struct ts_common_info **)&pTxTs,
589 dst, 589 dst,
590 (u8)pDelBaParamSet->field.TID, 590 (u8)pDelBaParamSet->field.tid,
591 TX_DIR, 591 TX_DIR,
592 false)) { 592 false)) {
593 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't get TS for TXTS in %s()\n", __func__); 593 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't get TS for TXTS in %s()\n", __func__);
@@ -615,22 +615,22 @@ TsInitAddBA(
615 u8 bOverwritePending 615 u8 bOverwritePending
616 ) 616 )
617{ 617{
618 PBA_RECORD pBA = &pTS->tx_pending_ba_record; 618 struct ba_record *pBA = &pTS->tx_pending_ba_record;
619 619
620 if (pBA->bValid && !bOverwritePending) 620 if (pBA->valid && !bOverwritePending)
621 return; 621 return;
622 622
623 // Set parameters to "Pending" variable set 623 // Set parameters to "Pending" variable set
624 DeActivateBAEntry(ieee, pBA); 624 DeActivateBAEntry(ieee, pBA);
625 625
626 pBA->DialogToken++; // DialogToken: Only keep the latest dialog token 626 pBA->dialog_token++; // DialogToken: Only keep the latest dialog token
627 pBA->BaParamSet.field.AMSDU_Support = 0; // Do not support A-MSDU with A-MPDU now!! 627 pBA->param_set.field.amsdu_support = 0; // Do not support A-MSDU with A-MPDU now!!
628 pBA->BaParamSet.field.BAPolicy = Policy; // Policy: Delayed or Immediate 628 pBA->param_set.field.ba_policy = Policy; // Policy: Delayed or Immediate
629 pBA->BaParamSet.field.TID = pTS->ts_common_info.t_spec.ts_info.uc_tsid; // TID 629 pBA->param_set.field.tid = pTS->ts_common_info.t_spec.ts_info.uc_tsid; // TID
630 // BufferSize: This need to be set according to A-MPDU vector 630 // buffer_size: This need to be set according to A-MPDU vector
631 pBA->BaParamSet.field.BufferSize = 32; // BufferSize: This need to be set according to A-MPDU vector 631 pBA->param_set.field.buffer_size = 32; // buffer_size: This need to be set according to A-MPDU vector
632 pBA->BaTimeoutValue = 0; // Timeout value: Set 0 to disable Timer 632 pBA->timeout_value = 0; // Timeout value: Set 0 to disable Timer
633 pBA->BaStartSeqCtrl.field.SeqNum = (pTS->tx_cur_seq + 3) % 4096; // Block Ack will start after 3 packets later. 633 pBA->start_seq_ctrl.field.seq_num = (pTS->tx_cur_seq + 3) % 4096; // Block Ack will start after 3 packets later.
634 634
635 ActivateBAEntry(ieee, pBA, BA_SETUP_TIMEOUT); 635 ActivateBAEntry(ieee, pBA, BA_SETUP_TIMEOUT);
636 636
@@ -647,7 +647,7 @@ TsInitDelBA(struct ieee80211_device *ieee, struct ts_common_info *pTsCommonInfo,
647 ieee80211_send_DELBA( 647 ieee80211_send_DELBA(
648 ieee, 648 ieee,
649 pTsCommonInfo->addr, 649 pTsCommonInfo->addr,
650 (pTxTs->tx_admitted_ba_record.bValid)?(&pTxTs->tx_admitted_ba_record):(&pTxTs->tx_pending_ba_record), 650 (pTxTs->tx_admitted_ba_record.valid)?(&pTxTs->tx_admitted_ba_record):(&pTxTs->tx_pending_ba_record),
651 TxRxSelect, 651 TxRxSelect,
652 DELBA_REASON_END_BA); 652 DELBA_REASON_END_BA);
653 } else if (TxRxSelect == RX_DIR) { 653 } else if (TxRxSelect == RX_DIR) {
@@ -669,16 +669,16 @@ TsInitDelBA(struct ieee80211_device *ieee, struct ts_common_info *pTsCommonInfo,
669 ********************************************************************************************************************/ 669 ********************************************************************************************************************/
670void BaSetupTimeOut(struct timer_list *t) 670void BaSetupTimeOut(struct timer_list *t)
671{ 671{
672 struct tx_ts_record *pTxTs = from_timer(pTxTs, t, tx_pending_ba_record.Timer); 672 struct tx_ts_record *pTxTs = from_timer(pTxTs, t, tx_pending_ba_record.timer);
673 673
674 pTxTs->add_ba_req_in_progress = false; 674 pTxTs->add_ba_req_in_progress = false;
675 pTxTs->add_ba_req_delayed = true; 675 pTxTs->add_ba_req_delayed = true;
676 pTxTs->tx_pending_ba_record.bValid = false; 676 pTxTs->tx_pending_ba_record.valid = false;
677} 677}
678 678
679void TxBaInactTimeout(struct timer_list *t) 679void TxBaInactTimeout(struct timer_list *t)
680{ 680{
681 struct tx_ts_record *pTxTs = from_timer(pTxTs, t, tx_admitted_ba_record.Timer); 681 struct tx_ts_record *pTxTs = from_timer(pTxTs, t, tx_admitted_ba_record.timer);
682 struct ieee80211_device *ieee = container_of(pTxTs, struct ieee80211_device, TxTsRecord[pTxTs->num]); 682 struct ieee80211_device *ieee = container_of(pTxTs, struct ieee80211_device, TxTsRecord[pTxTs->num]);
683 TxTsDeleteBA(ieee, pTxTs); 683 TxTsDeleteBA(ieee, pTxTs);
684 ieee80211_send_DELBA( 684 ieee80211_send_DELBA(
@@ -691,7 +691,7 @@ void TxBaInactTimeout(struct timer_list *t)
691 691
692void RxBaInactTimeout(struct timer_list *t) 692void RxBaInactTimeout(struct timer_list *t)
693{ 693{
694 struct rx_ts_record *pRxTs = from_timer(pRxTs, t, rx_admitted_ba_record.Timer); 694 struct rx_ts_record *pRxTs = from_timer(pRxTs, t, rx_admitted_ba_record.timer);
695 struct ieee80211_device *ieee = container_of(pRxTs, struct ieee80211_device, RxTsRecord[pRxTs->num]); 695 struct ieee80211_device *ieee = container_of(pRxTs, struct ieee80211_device, RxTsRecord[pRxTs->num]);
696 696
697 RxTsDeleteBA(ieee, pRxTs); 697 RxTsDeleteBA(ieee, pRxTs);
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_HT.h b/drivers/staging/rtl8192u/ieee80211/rtl819x_HT.h
index 7d54a7cd9514..64d5359cf7e2 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_HT.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_HT.h
@@ -2,40 +2,34 @@
2#ifndef _RTL819XU_HTTYPE_H_ 2#ifndef _RTL819XU_HTTYPE_H_
3#define _RTL819XU_HTTYPE_H_ 3#define _RTL819XU_HTTYPE_H_
4 4
5//------------------------------------------------------------ 5/*
6// The HT Capability element is present in beacons, association request, 6 * The HT Capability element is present in beacons, association request,
7// reassociation request and probe response frames 7 * reassociation request and probe response frames
8//------------------------------------------------------------ 8 */
9
10//
11// MIMO Power Save Settings
12//
13#define MIMO_PS_STATIC 0
14
15//
16// There should be 128 bits to cover all of the MCS rates. However, since
17// 8190 does not support too much rates, one integer is quite enough.
18//
19
20#define sHTCLng 4
21 9
10/*
11 * MIMO Power Save Settings
12 */
13#define MIMO_PS_STATIC 0
22 14
23#define HT_SUPPORTED_MCS_1SS_BITMAP 0x000000ff 15/*
24#define HT_SUPPORTED_MCS_2SS_BITMAP 0x0000ff00 16 * There should be 128 bits to cover all of the MCS rates. However, since
25#define HT_SUPPORTED_MCS_1SS_2SS_BITMAP HT_MCS_1SS_BITMAP|HT_MCS_1SS_2SS_BITMAP 17 * 8190 does not support too much rates, one integer is quite enough.
18 */
19#define HTCLNG 4
26 20
27// 21/*
28// Represent Channel Width in HT Capabilities 22 * Represent Channel Width in HT Capabilities
29// 23 */
30enum ht_channel_width { 24enum ht_channel_width {
31 HT_CHANNEL_WIDTH_20 = 0, 25 HT_CHANNEL_WIDTH_20 = 0,
32 HT_CHANNEL_WIDTH_20_40 = 1, 26 HT_CHANNEL_WIDTH_20_40 = 1,
33}; 27};
34 28
35// 29/*
36// Represent Extension Channel Offset in HT Capabilities 30 * Represent Extension Channel Offset in HT Capabilities
37// This is available only in 40Mhz mode. 31 * This is available only in 40Mhz mode.
38// 32 */
39enum ht_extension_chan_offset { 33enum ht_extension_chan_offset {
40 HT_EXTCHNL_OFFSET_NO_EXT = 0, 34 HT_EXTCHNL_OFFSET_NO_EXT = 0,
41 HT_EXTCHNL_OFFSET_UPPER = 1, 35 HT_EXTCHNL_OFFSET_UPPER = 1,
@@ -43,53 +37,7 @@ enum ht_extension_chan_offset {
43 HT_EXTCHNL_OFFSET_LOWER = 3, 37 HT_EXTCHNL_OFFSET_LOWER = 3,
44}; 38};
45 39
46typedef enum _CHNLOP { 40struct ht_capability_ele {
47 CHNLOP_NONE = 0, // No Action now
48 CHNLOP_SCAN = 1, // Scan in progress
49 CHNLOP_SWBW = 2, // Bandwidth switching in progress
50 CHNLOP_SWCHNL = 3, // Software Channel switching in progress
51} CHNLOP, *PCHNLOP;
52
53// Determine if the Channel Operation is in progress
54#define CHHLOP_IN_PROGRESS(_pHTInfo) \
55 ((_pHTInfo)->ChnlOp > CHNLOP_NONE) ? TRUE : FALSE
56
57/*
58typedef union _HT_CAPABILITY{
59 u16 ShortData;
60 u8 CharData[2];
61 struct
62 {
63 u16 AdvCoding:1;
64 u16 ChlWidth:1;
65 u16 MimoPwrSave:2;
66 u16 GreenField:1;
67 u16 ShortGI20Mhz:1;
68 u16 ShortGI40Mhz:1;
69 u16 STBC:1;
70 u16 BeamForm:1;
71 u16 DelayBA:1;
72 u16 MaxAMSDUSize:1;
73 u16 DssCCk:1;
74 u16 PSMP:1;
75 u16 Rsvd:3;
76 }Field;
77}HT_CAPABILITY, *PHT_CAPABILITY;
78
79typedef union _HT_CAPABILITY_MACPARA{
80 u8 ShortData;
81 u8 CharData[1];
82 struct
83 {
84 u8 MaxRxAMPDU:2;
85 u8 MPDUDensity:2;
86 u8 Rsvd:4;
87 }Field;
88}HT_CAPABILITY_MACPARA, *PHT_CAPABILITY_MACPARA;
89*/
90
91typedef struct _HT_CAPABILITY_ELE {
92
93 //HT capability info 41 //HT capability info
94 u8 AdvCoding:1; 42 u8 AdvCoding:1;
95 u8 ChlWidth:1; 43 u8 ChlWidth:1;
@@ -114,7 +62,6 @@ typedef struct _HT_CAPABILITY_ELE {
114 //Supported MCS set 62 //Supported MCS set
115 u8 MCS[16]; 63 u8 MCS[16];
116 64
117
118 //Extended HT Capability Info 65 //Extended HT Capability Info
119 u16 ExtHTCapInfo; 66 u16 ExtHTCapInfo;
120 67
@@ -124,13 +71,12 @@ typedef struct _HT_CAPABILITY_ELE {
124 //Antenna Selection Capabilities 71 //Antenna Selection Capabilities
125 u8 ASCap; 72 u8 ASCap;
126 73
127} __attribute__ ((packed)) HT_CAPABILITY_ELE, *PHT_CAPABILITY_ELE; 74} __packed;
128
129//------------------------------------------------------------
130// The HT Information element is present in beacons
131// Only AP is required to include this element
132//------------------------------------------------------------
133 75
76/*
77 * The HT Information element is present in beacons
78 * Only AP is required to include this element
79 */
134typedef struct _HT_INFORMATION_ELE { 80typedef struct _HT_INFORMATION_ELE {
135 u8 ControlChl; 81 u8 ControlChl;
136 82
@@ -169,12 +115,11 @@ typedef enum _HT_AGGRE_MODE_E {
169 HT_AGG_FORCE_DISABLE = 2, 115 HT_AGG_FORCE_DISABLE = 2,
170}HT_AGGRE_MODE_E, *PHT_AGGRE_MODE_E; 116}HT_AGGRE_MODE_E, *PHT_AGGRE_MODE_E;
171 117
172//------------------------------------------------------------ 118/*
173// The Data structure is used to keep HT related variables when card is 119 * The Data structure is used to keep HT related variables when card is
174// configured as non-AP STA mode. **Note** Current_xxx should be set 120 * configured as non-AP STA mode. **Note** Current_xxx should be set
175// to default value in HTInitializeHTInfo() 121 * to default value in HTInitializeHTInfo()
176//------------------------------------------------------------ 122 */
177
178typedef struct _RT_HIGH_THROUGHPUT { 123typedef struct _RT_HIGH_THROUGHPUT {
179 u8 bEnableHT; 124 u8 bEnableHT;
180 u8 bCurrentHTSupport; 125 u8 bCurrentHTSupport;
@@ -194,23 +139,20 @@ typedef struct _RT_HIGH_THROUGHPUT {
194 // 802.11n spec version for "peer" 139 // 802.11n spec version for "peer"
195 HT_SPEC_VER ePeerHTSpecVer; 140 HT_SPEC_VER ePeerHTSpecVer;
196 141
197
198 // HT related information for "Self" 142 // HT related information for "Self"
199 HT_CAPABILITY_ELE SelfHTCap; // This is HT cap element sent to peer STA, which also indicate HT Rx capabilities. 143 struct ht_capability_ele SelfHTCap; // This is HT cap element sent to peer STA, which also indicate HT Rx capabilities.
200 HT_INFORMATION_ELE SelfHTInfo; // This is HT info element sent to peer STA, which also indicate HT Rx capabilities. 144 HT_INFORMATION_ELE SelfHTInfo; // This is HT info element sent to peer STA, which also indicate HT Rx capabilities.
201 145
202 // HT related information for "Peer" 146 // HT related information for "Peer"
203 u8 PeerHTCapBuf[32]; 147 u8 PeerHTCapBuf[32];
204 u8 PeerHTInfoBuf[32]; 148 u8 PeerHTInfoBuf[32];
205 149
206
207 // A-MSDU related 150 // A-MSDU related
208 u8 bAMSDU_Support; // This indicates Tx A-MSDU capability 151 u8 bAMSDU_Support; // This indicates Tx A-MSDU capability
209 u16 nAMSDU_MaxSize; // This indicates Tx A-MSDU capability 152 u16 nAMSDU_MaxSize; // This indicates Tx A-MSDU capability
210 u8 bCurrent_AMSDU_Support; // This indicates Tx A-MSDU capability 153 u8 bCurrent_AMSDU_Support; // This indicates Tx A-MSDU capability
211 u16 nCurrent_AMSDU_MaxSize; // This indicates Tx A-MSDU capability 154 u16 nCurrent_AMSDU_MaxSize; // This indicates Tx A-MSDU capability
212 155
213
214 // AMPDU related <2006.08.10 Emily> 156 // AMPDU related <2006.08.10 Emily>
215 u8 bAMPDUEnable; // This indicate Tx A-MPDU capability 157 u8 bAMPDUEnable; // This indicate Tx A-MPDU capability
216 u8 bCurrentAMPDUEnable; // This indicate Tx A-MPDU capability 158 u8 bCurrentAMPDUEnable; // This indicate Tx A-MPDU capability
@@ -243,7 +185,6 @@ typedef struct _RT_HIGH_THROUGHPUT {
243 185
244 // For Bandwidth Switching 186 // For Bandwidth Switching
245 u8 bSwBwInProgress; 187 u8 bSwBwInProgress;
246 CHNLOP ChnlOp; // software switching channel in progress. By Bruce, 2008-02-15.
247 u8 SwBwStep; 188 u8 SwBwStep;
248 //struct timer_list SwBwTimer; //moved to ieee80211_device. as timer_list need include some header file here. 189 //struct timer_list SwBwTimer; //moved to ieee80211_device. as timer_list need include some header file here.
249 190
@@ -278,13 +219,11 @@ typedef struct _RT_HIGH_THROUGHPUT {
278 u32 IOTAction; 219 u32 IOTAction;
279} __attribute__ ((packed)) RT_HIGH_THROUGHPUT, *PRT_HIGH_THROUGHPUT; 220} __attribute__ ((packed)) RT_HIGH_THROUGHPUT, *PRT_HIGH_THROUGHPUT;
280 221
281//------------------------------------------------------------ 222/*
282// The Data structure is used to keep HT related variable for "each AP" 223 * The Data structure is used to keep HT related variable for "each AP"
283// when card is configured as "STA mode" 224 * when card is configured as "STA mode"
284//------------------------------------------------------------ 225 */
285
286typedef struct _BSS_HT { 226typedef struct _BSS_HT {
287
288 u8 bdSupportHT; 227 u8 bdSupportHT;
289 228
290 // HT related elements 229 // HT related elements
@@ -294,7 +233,7 @@ typedef struct _BSS_HT {
294 u16 bdHTInfoLen; 233 u16 bdHTInfoLen;
295 234
296 HT_SPEC_VER bdHTSpecVer; 235 HT_SPEC_VER bdHTSpecVer;
297 //HT_CAPABILITY_ELE bdHTCapEle; 236 //struct ht_capability_ele bdHTCapEle;
298 //HT_INFORMATION_ELE bdHTInfoEle; 237 //HT_INFORMATION_ELE bdHTInfoEle;
299 238
300 u8 bdRT2RTAggregation; 239 u8 bdRT2RTAggregation;
@@ -304,27 +243,27 @@ typedef struct _BSS_HT {
304extern u8 MCS_FILTER_ALL[16]; 243extern u8 MCS_FILTER_ALL[16];
305extern u8 MCS_FILTER_1SS[16]; 244extern u8 MCS_FILTER_1SS[16];
306 245
307/* 2007/07/11 MH Modify the macro. Becaus STA may link with a N-AP. If we set 246/*
308 STA in A/B/G mode and AP is still in N mode. The macro will be wrong. We have 247 * 2007/07/11 MH Modify the macro. Becaus STA may link with a N-AP. If we set
309 to add a macro to judge wireless mode. */ 248 * STA in A/B/G mode and AP is still in N mode. The macro will be wrong. We have
249 * to add a macro to judge wireless mode.
250 */
310#define PICK_RATE(_nLegacyRate, _nMcsRate) \ 251#define PICK_RATE(_nLegacyRate, _nMcsRate) \
311 (_nMcsRate==0)?(_nLegacyRate&0x7f):(_nMcsRate) 252 (_nMcsRate == 0) ? (_nLegacyRate & 0x7f) : (_nMcsRate)
312/* 2007/07/12 MH We only define legacy and HT wireless mode now. */ 253/* 2007/07/12 MH We only define legacy and HT wireless mode now. */
313#define LEGACY_WIRELESS_MODE IEEE_MODE_MASK 254#define LEGACY_WIRELESS_MODE IEEE_MODE_MASK
314 255
315#define CURRENT_RATE(WirelessMode, LegacyRate, HTRate) \ 256#define CURRENT_RATE(WirelessMode, LegacyRate, HTRate) \
316 ((WirelessMode & (LEGACY_WIRELESS_MODE))!=0)?\ 257 ((WirelessMode & (LEGACY_WIRELESS_MODE)) != 0) ?\
317 (LegacyRate):\ 258 (LegacyRate) :\
318 (PICK_RATE(LegacyRate, HTRate)) 259 (PICK_RATE(LegacyRate, HTRate))
319 260
320
321
322// MCS Bw 40 {1~7, 12~15,32} 261// MCS Bw 40 {1~7, 12~15,32}
323#define RATE_ADPT_1SS_MASK 0xFF 262#define RATE_ADPT_1SS_MASK 0xFF
324#define RATE_ADPT_2SS_MASK 0xF0 //Skip MCS8~11 because mcs7 > mcs6, 9, 10, 11. 2007.01.16 by Emily 263#define RATE_ADPT_2SS_MASK 0xF0 //Skip MCS8~11 because mcs7 > mcs6, 9, 10, 11. 2007.01.16 by Emily
325#define RATE_ADPT_MCS32_MASK 0x01 264#define RATE_ADPT_MCS32_MASK 0x01
326 265
327#define IS_11N_MCS_RATE(rate) (rate&0x80) 266#define IS_11N_MCS_RATE(rate) (rate & 0x80)
328 267
329typedef enum _HT_AGGRE_SIZE { 268typedef enum _HT_AGGRE_SIZE {
330 HT_AGG_SIZE_8K = 0, 269 HT_AGG_SIZE_8K = 0,
@@ -341,13 +280,13 @@ typedef enum _HT_IOT_PEER
341 HT_IOT_PEER_BROADCOM = 2, 280 HT_IOT_PEER_BROADCOM = 2,
342 HT_IOT_PEER_RALINK = 3, 281 HT_IOT_PEER_RALINK = 3,
343 HT_IOT_PEER_ATHEROS = 4, 282 HT_IOT_PEER_ATHEROS = 4,
344 HT_IOT_PEER_CISCO= 5, 283 HT_IOT_PEER_CISCO = 5,
345 HT_IOT_PEER_MAX = 6 284 HT_IOT_PEER_MAX = 6
346}HT_IOT_PEER_E, *PHTIOT_PEER_E; 285}HT_IOT_PEER_E, *PHTIOT_PEER_E;
347 286
348// 287/*
349// IOT Action for different AP 288 * IOT Action for different AP
350// 289 */
351typedef enum _HT_IOT_ACTION { 290typedef enum _HT_IOT_ACTION {
352 HT_IOT_ACT_TX_USE_AMSDU_4K = 0x00000001, 291 HT_IOT_ACT_TX_USE_AMSDU_4K = 0x00000001,
353 HT_IOT_ACT_TX_USE_AMSDU_8K = 0x00000002, 292 HT_IOT_ACT_TX_USE_AMSDU_8K = 0x00000002,
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c b/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c
index b948eae5909d..c73a8058cf87 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c
@@ -130,15 +130,15 @@ void HTUpdateDefaultSetting(struct ieee80211_device *ieee)
130 */ 130 */
131void HTDebugHTCapability(u8 *CapIE, u8 *TitleString) 131void HTDebugHTCapability(u8 *CapIE, u8 *TitleString)
132{ 132{
133 static u8 EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33}; // For 11n EWC definition, 2007.07.17, by Emily 133 static u8 EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33}; // For 11n EWC definition, 2007.07.17, by Emily
134 PHT_CAPABILITY_ELE pCapELE; 134 struct ht_capability_ele *pCapELE;
135 135
136 if (!memcmp(CapIE, EWC11NHTCap, sizeof(EWC11NHTCap))) { 136 if (!memcmp(CapIE, EWC11NHTCap, sizeof(EWC11NHTCap))) {
137 //EWC IE 137 //EWC IE
138 IEEE80211_DEBUG(IEEE80211_DL_HT, "EWC IE in %s()\n", __func__); 138 IEEE80211_DEBUG(IEEE80211_DL_HT, "EWC IE in %s()\n", __func__);
139 pCapELE = (PHT_CAPABILITY_ELE)(&CapIE[4]); 139 pCapELE = (struct ht_capability_ele *)(&CapIE[4]);
140 } else { 140 } else {
141 pCapELE = (PHT_CAPABILITY_ELE)(&CapIE[0]); 141 pCapELE = (struct ht_capability_ele *)(&CapIE[0]);
142 } 142 }
143 IEEE80211_DEBUG(IEEE80211_DL_HT, "<Log HT Capability>. Called by %s\n", TitleString); 143 IEEE80211_DEBUG(IEEE80211_DL_HT, "<Log HT Capability>. Called by %s\n", TitleString);
144 144
@@ -216,64 +216,7 @@ void HTDebugHTInfo(u8 *InfoIE, u8 *TitleString)
216 pHTInfoEle->BasicMSC[1], pHTInfoEle->BasicMSC[2], pHTInfoEle->BasicMSC[3], pHTInfoEle->BasicMSC[4]); 216 pHTInfoEle->BasicMSC[1], pHTInfoEle->BasicMSC[2], pHTInfoEle->BasicMSC[3], pHTInfoEle->BasicMSC[4]);
217} 217}
218 218
219/* 219static u16 HTMcsToDataRate(struct ieee80211_device *ieee, u8 nMcsRate)
220 * Return: true if station in half n mode and AP supports 40 bw
221 */
222static bool IsHTHalfNmode40Bandwidth(struct ieee80211_device *ieee)
223{
224 bool retValue = false;
225 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
226
227 if (!pHTInfo->bCurrentHTSupport) // wireless is n mode
228 retValue = false;
229 else if (!pHTInfo->bRegBW40MHz) // station supports 40 bw
230 retValue = false;
231 else if (!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) // station in half n mode
232 retValue = false;
233 else if (((PHT_CAPABILITY_ELE)(pHTInfo->PeerHTCapBuf))->ChlWidth) // ap support 40 bw
234 retValue = true;
235 else
236 retValue = false;
237
238 return retValue;
239}
240
241static bool IsHTHalfNmodeSGI(struct ieee80211_device *ieee, bool is40MHz)
242{
243 bool retValue = false;
244 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
245
246 if (!pHTInfo->bCurrentHTSupport) // wireless is n mode
247 retValue = false;
248 else if (!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) // station in half n mode
249 retValue = false;
250 else if (is40MHz) { // ap support 40 bw
251 if (((PHT_CAPABILITY_ELE)(pHTInfo->PeerHTCapBuf))->ShortGI40Mhz) // ap support 40 bw short GI
252 retValue = true;
253 else
254 retValue = false;
255 } else {
256 if (((PHT_CAPABILITY_ELE)(pHTInfo->PeerHTCapBuf))->ShortGI20Mhz) // ap support 40 bw short GI
257 retValue = true;
258 else
259 retValue = false;
260 }
261
262 return retValue;
263}
264
265u16 HTHalfMcsToDataRate(struct ieee80211_device *ieee, u8 nMcsRate)
266{
267 u8 is40MHz;
268 u8 isShortGI;
269
270 is40MHz = (IsHTHalfNmode40Bandwidth(ieee)) ? 1 : 0;
271 isShortGI = (IsHTHalfNmodeSGI(ieee, is40MHz)) ? 1 : 0;
272
273 return MCS_DATA_RATE[is40MHz][isShortGI][(nMcsRate & 0x7f)];
274}
275
276u16 HTMcsToDataRate(struct ieee80211_device *ieee, u8 nMcsRate)
277{ 220{
278 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo; 221 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
279 222
@@ -530,7 +473,7 @@ void HTResetIOTSetting(PRT_HIGH_THROUGHPUT pHTInfo)
530void HTConstructCapabilityElement(struct ieee80211_device *ieee, u8 *posHTCap, u8 *len, u8 IsEncrypt) 473void HTConstructCapabilityElement(struct ieee80211_device *ieee, u8 *posHTCap, u8 *len, u8 IsEncrypt)
531{ 474{
532 PRT_HIGH_THROUGHPUT pHT = ieee->pHTInfo; 475 PRT_HIGH_THROUGHPUT pHT = ieee->pHTInfo;
533 PHT_CAPABILITY_ELE pCapELE = NULL; 476 struct ht_capability_ele *pCapELE = NULL;
534 //u8 bIsDeclareMCS13; 477 //u8 bIsDeclareMCS13;
535 478
536 if (!posHTCap || !pHT) { 479 if (!posHTCap || !pHT) {
@@ -544,9 +487,9 @@ void HTConstructCapabilityElement(struct ieee80211_device *ieee, u8 *posHTCap, u
544 u8 EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33}; // For 11n EWC definition, 2007.07.17, by Emily 487 u8 EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33}; // For 11n EWC definition, 2007.07.17, by Emily
545 488
546 memcpy(posHTCap, EWC11NHTCap, sizeof(EWC11NHTCap)); 489 memcpy(posHTCap, EWC11NHTCap, sizeof(EWC11NHTCap));
547 pCapELE = (PHT_CAPABILITY_ELE)&posHTCap[4]; 490 pCapELE = (struct ht_capability_ele *)&posHTCap[4];
548 } else { 491 } else {
549 pCapELE = (PHT_CAPABILITY_ELE)posHTCap; 492 pCapELE = (struct ht_capability_ele *)posHTCap;
550 } 493 }
551 494
552 //HT capability info 495 //HT capability info
@@ -894,11 +837,10 @@ static u8 HTFilterMCSRate(struct ieee80211_device *ieee, u8 *pSupportMCS,
894 return true; 837 return true;
895} 838}
896 839
897void HTSetConnectBwMode(struct ieee80211_device *ieee, enum ht_channel_width Bandwidth, enum ht_extension_chan_offset Offset);
898void HTOnAssocRsp(struct ieee80211_device *ieee) 840void HTOnAssocRsp(struct ieee80211_device *ieee)
899{ 841{
900 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo; 842 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
901 PHT_CAPABILITY_ELE pPeerHTCap = NULL; 843 struct ht_capability_ele *pPeerHTCap = NULL;
902 PHT_INFORMATION_ELE pPeerHTInfo = NULL; 844 PHT_INFORMATION_ELE pPeerHTInfo = NULL;
903 u16 nMaxAMSDUSize = 0; 845 u16 nMaxAMSDUSize = 0;
904 u8 *pMcsFilter = NULL; 846 u8 *pMcsFilter = NULL;
@@ -913,16 +855,16 @@ void HTOnAssocRsp(struct ieee80211_device *ieee)
913 return; 855 return;
914 } 856 }
915 IEEE80211_DEBUG(IEEE80211_DL_HT, "===> HTOnAssocRsp_wq(): HT_ENABLE\n"); 857 IEEE80211_DEBUG(IEEE80211_DL_HT, "===> HTOnAssocRsp_wq(): HT_ENABLE\n");
916// IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, pHTInfo->PeerHTCapBuf, sizeof(HT_CAPABILITY_ELE)); 858// IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, pHTInfo->PeerHTCapBuf, sizeof(struct ht_capability_ele));
917// IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, pHTInfo->PeerHTInfoBuf, sizeof(HT_INFORMATION_ELE)); 859// IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, pHTInfo->PeerHTInfoBuf, sizeof(HT_INFORMATION_ELE));
918 860
919// HTDebugHTCapability(pHTInfo->PeerHTCapBuf,"HTOnAssocRsp_wq"); 861// HTDebugHTCapability(pHTInfo->PeerHTCapBuf,"HTOnAssocRsp_wq");
920// HTDebugHTInfo(pHTInfo->PeerHTInfoBuf,"HTOnAssocRsp_wq"); 862// HTDebugHTInfo(pHTInfo->PeerHTInfoBuf,"HTOnAssocRsp_wq");
921 // 863 //
922 if (!memcmp(pHTInfo->PeerHTCapBuf, EWC11NHTCap, sizeof(EWC11NHTCap))) 864 if (!memcmp(pHTInfo->PeerHTCapBuf, EWC11NHTCap, sizeof(EWC11NHTCap)))
923 pPeerHTCap = (PHT_CAPABILITY_ELE)(&pHTInfo->PeerHTCapBuf[4]); 865 pPeerHTCap = (struct ht_capability_ele *)(&pHTInfo->PeerHTCapBuf[4]);
924 else 866 else
925 pPeerHTCap = (PHT_CAPABILITY_ELE)(pHTInfo->PeerHTCapBuf); 867 pPeerHTCap = (struct ht_capability_ele *)(pHTInfo->PeerHTCapBuf);
926 868
927 if (!memcmp(pHTInfo->PeerHTInfoBuf, EWC11NHTInfo, sizeof(EWC11NHTInfo))) 869 if (!memcmp(pHTInfo->PeerHTInfoBuf, EWC11NHTInfo, sizeof(EWC11NHTInfo)))
928 pPeerHTInfo = (PHT_INFORMATION_ELE)(&pHTInfo->PeerHTInfoBuf[4]); 870 pPeerHTInfo = (PHT_INFORMATION_ELE)(&pHTInfo->PeerHTInfoBuf[4]);
@@ -932,7 +874,7 @@ void HTOnAssocRsp(struct ieee80211_device *ieee)
932 //////////////////////////////////////////////////////// 874 ////////////////////////////////////////////////////////
933 // Configurations: 875 // Configurations:
934 //////////////////////////////////////////////////////// 876 ////////////////////////////////////////////////////////
935 IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA | IEEE80211_DL_HT, pPeerHTCap, sizeof(HT_CAPABILITY_ELE)); 877 IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA | IEEE80211_DL_HT, pPeerHTCap, sizeof(struct ht_capability_ele));
936// IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA|IEEE80211_DL_HT, pPeerHTInfo, sizeof(HT_INFORMATION_ELE)); 878// IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA|IEEE80211_DL_HT, pPeerHTInfo, sizeof(HT_INFORMATION_ELE));
937 // Config Supported Channel Width setting 879 // Config Supported Channel Width setting
938 // 880 //
@@ -1069,7 +1011,6 @@ void HTOnAssocRsp(struct ieee80211_device *ieee)
1069 pHTInfo->CurrentOpMode = pPeerHTInfo->OptMode; 1011 pHTInfo->CurrentOpMode = pPeerHTInfo->OptMode;
1070} 1012}
1071 1013
1072void HTSetConnectBwModeCallback(struct ieee80211_device *ieee);
1073/* 1014/*
1074 *function: initialize HT info(struct PRT_HIGH_THROUGHPUT) 1015 *function: initialize HT info(struct PRT_HIGH_THROUGHPUT)
1075 * input: struct ieee80211_device* ieee 1016 * input: struct ieee80211_device* ieee
@@ -1122,7 +1063,6 @@ void HTInitializeHTInfo(struct ieee80211_device *ieee)
1122 memset(&pHTInfo->PeerHTInfoBuf, 0, sizeof(pHTInfo->PeerHTInfoBuf)); 1063 memset(&pHTInfo->PeerHTInfoBuf, 0, sizeof(pHTInfo->PeerHTInfoBuf));
1123 1064
1124 pHTInfo->bSwBwInProgress = false; 1065 pHTInfo->bSwBwInProgress = false;
1125 pHTInfo->ChnlOp = CHNLOP_NONE;
1126 1066
1127 // Set default IEEE spec for Draft N 1067 // Set default IEEE spec for Draft N
1128 pHTInfo->ePeerHTSpecVer = HT_SPEC_VER_IEEE; 1068 pHTInfo->ePeerHTSpecVer = HT_SPEC_VER_IEEE;
@@ -1177,7 +1117,7 @@ void HTResetSelfAndSavePeerSetting(struct ieee80211_device *ieee, struct ieee802
1177{ 1117{
1178 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo; 1118 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
1179// u16 nMaxAMSDUSize; 1119// u16 nMaxAMSDUSize;
1180// PHT_CAPABILITY_ELE pPeerHTCap = (PHT_CAPABILITY_ELE)pNetwork->bssht.bdHTCapBuf; 1120// struct ht_capability_ele *pPeerHTCap = (struct ht_capability_ele *)pNetwork->bssht.bdHTCapBuf;
1181// PHT_INFORMATION_ELE pPeerHTInfo = (PHT_INFORMATION_ELE)pNetwork->bssht.bdHTInfoBuf; 1121// PHT_INFORMATION_ELE pPeerHTInfo = (PHT_INFORMATION_ELE)pNetwork->bssht.bdHTInfoBuf;
1182// u8* pMcsFilter; 1122// u8* pMcsFilter;
1183 u8 bIOTAction = 0; 1123 u8 bIOTAction = 0;
@@ -1250,8 +1190,8 @@ void HTResetSelfAndSavePeerSetting(struct ieee80211_device *ieee, struct ieee802
1250 1190
1251void HTUpdateSelfAndPeerSetting(struct ieee80211_device *ieee, struct ieee80211_network *pNetwork) 1191void HTUpdateSelfAndPeerSetting(struct ieee80211_device *ieee, struct ieee80211_network *pNetwork)
1252{ 1192{
1253 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo; 1193 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
1254// PHT_CAPABILITY_ELE pPeerHTCap = (PHT_CAPABILITY_ELE)pNetwork->bssht.bdHTCapBuf; 1194// struct ht_capability_ele *pPeerHTCap = (struct ht_capability_ele *)pNetwork->bssht.bdHTCapBuf;
1255 PHT_INFORMATION_ELE pPeerHTInfo = (PHT_INFORMATION_ELE)pNetwork->bssht.bdHTInfoBuf; 1195 PHT_INFORMATION_ELE pPeerHTInfo = (PHT_INFORMATION_ELE)pNetwork->bssht.bdHTInfoBuf;
1256 1196
1257 if (pHTInfo->bCurrentHTSupport) { 1197 if (pHTInfo->bCurrentHTSupport) {
@@ -1287,6 +1227,29 @@ u8 HTCCheck(struct ieee80211_device *ieee, u8 *pFrame)
1287 return false; 1227 return false;
1288} 1228}
1289 1229
1230static void HTSetConnectBwModeCallback(struct ieee80211_device *ieee)
1231{
1232 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
1233
1234 IEEE80211_DEBUG(IEEE80211_DL_HT, "======>%s()\n", __func__);
1235
1236 if (pHTInfo->bCurBW40MHz) {
1237 if (pHTInfo->CurSTAExtChnlOffset == HT_EXTCHNL_OFFSET_UPPER)
1238 ieee->set_chan(ieee->dev, ieee->current_network.channel + 2);
1239 else if (pHTInfo->CurSTAExtChnlOffset == HT_EXTCHNL_OFFSET_LOWER)
1240 ieee->set_chan(ieee->dev, ieee->current_network.channel - 2);
1241 else
1242 ieee->set_chan(ieee->dev, ieee->current_network.channel);
1243
1244 ieee->SetBWModeHandler(ieee->dev, HT_CHANNEL_WIDTH_20_40, pHTInfo->CurSTAExtChnlOffset);
1245 } else {
1246 ieee->set_chan(ieee->dev, ieee->current_network.channel);
1247 ieee->SetBWModeHandler(ieee->dev, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT);
1248 }
1249
1250 pHTInfo->bSwBwInProgress = false;
1251}
1252
1290/* 1253/*
1291 * This function set bandwidth mode in protocol layer. 1254 * This function set bandwidth mode in protocol layer.
1292 */ 1255 */
@@ -1337,26 +1300,3 @@ void HTSetConnectBwMode(struct ieee80211_device *ieee, enum ht_channel_width Ban
1337 1300
1338// spin_unlock_irqrestore(&(ieee->bw_spinlock), flags); 1301// spin_unlock_irqrestore(&(ieee->bw_spinlock), flags);
1339} 1302}
1340
1341void HTSetConnectBwModeCallback(struct ieee80211_device *ieee)
1342{
1343 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
1344
1345 IEEE80211_DEBUG(IEEE80211_DL_HT, "======>%s()\n", __func__);
1346
1347 if (pHTInfo->bCurBW40MHz) {
1348 if (pHTInfo->CurSTAExtChnlOffset == HT_EXTCHNL_OFFSET_UPPER)
1349 ieee->set_chan(ieee->dev, ieee->current_network.channel + 2);
1350 else if (pHTInfo->CurSTAExtChnlOffset == HT_EXTCHNL_OFFSET_LOWER)
1351 ieee->set_chan(ieee->dev, ieee->current_network.channel - 2);
1352 else
1353 ieee->set_chan(ieee->dev, ieee->current_network.channel);
1354
1355 ieee->SetBWModeHandler(ieee->dev, HT_CHANNEL_WIDTH_20_40, pHTInfo->CurSTAExtChnlOffset);
1356 } else {
1357 ieee->set_chan(ieee->dev, ieee->current_network.channel);
1358 ieee->SetBWModeHandler(ieee->dev, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT);
1359 }
1360
1361 pHTInfo->bSwBwInProgress = false;
1362}
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_TS.h b/drivers/staging/rtl8192u/ieee80211/rtl819x_TS.h
index 924d4b373099..7ed140009760 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_TS.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_TS.h
@@ -78,8 +78,8 @@ struct ts_common_info {
78struct tx_ts_record { 78struct tx_ts_record {
79 struct ts_common_info ts_common_info; 79 struct ts_common_info ts_common_info;
80 u16 tx_cur_seq; 80 u16 tx_cur_seq;
81 BA_RECORD tx_pending_ba_record; 81 struct ba_record tx_pending_ba_record;
82 BA_RECORD tx_admitted_ba_record; 82 struct ba_record tx_admitted_ba_record;
83 u8 add_ba_req_in_progress; 83 u8 add_ba_req_in_progress;
84 u8 add_ba_req_delayed; 84 u8 add_ba_req_delayed;
85 u8 using_ba; 85 u8 using_ba;
@@ -93,7 +93,7 @@ struct rx_ts_record {
93 u16 rx_timeout_indicate_seq; 93 u16 rx_timeout_indicate_seq;
94 struct list_head rx_pending_pkt_list; 94 struct list_head rx_pending_pkt_list;
95 struct timer_list rx_pkt_pending_timer; 95 struct timer_list rx_pkt_pending_timer;
96 BA_RECORD rx_admitted_ba_record; 96 struct ba_record rx_admitted_ba_record;
97 u16 rx_last_seq_num; 97 u16 rx_last_seq_num;
98 u8 rx_last_frag_num; 98 u8 rx_last_frag_num;
99 u8 num; 99 u8 num;
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
index d46d8f468671..c76715ffa08b 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
@@ -36,11 +36,11 @@ static void RxPktPendingTimeout(struct timer_list *t)
36 bool bPktInBuf = false; 36 bool bPktInBuf = false;
37 37
38 spin_lock_irqsave(&(ieee->reorder_spinlock), flags); 38 spin_lock_irqsave(&(ieee->reorder_spinlock), flags);
39 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"==================>%s()\n",__func__); 39 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "==================>%s()\n", __func__);
40 if(pRxTs->rx_timeout_indicate_seq != 0xffff) { 40 if(pRxTs->rx_timeout_indicate_seq != 0xffff) {
41 // Indicate the pending packets sequentially according to SeqNum until meet the gap. 41 // Indicate the pending packets sequentially according to SeqNum until meet the gap.
42 while(!list_empty(&pRxTs->rx_pending_pkt_list)) { 42 while(!list_empty(&pRxTs->rx_pending_pkt_list)) {
43 pReorderEntry = (PRX_REORDER_ENTRY)list_entry(pRxTs->rx_pending_pkt_list.prev,RX_REORDER_ENTRY,List); 43 pReorderEntry = (PRX_REORDER_ENTRY)list_entry(pRxTs->rx_pending_pkt_list.prev, RX_REORDER_ENTRY, List);
44 if(index == 0) 44 if(index == 0)
45 pRxTs->rx_indicate_seq = pReorderEntry->SeqNum; 45 pRxTs->rx_indicate_seq = pReorderEntry->SeqNum;
46 46
@@ -51,7 +51,7 @@ static void RxPktPendingTimeout(struct timer_list *t)
51 if(SN_EQUAL(pReorderEntry->SeqNum, pRxTs->rx_indicate_seq)) 51 if(SN_EQUAL(pReorderEntry->SeqNum, pRxTs->rx_indicate_seq))
52 pRxTs->rx_indicate_seq = (pRxTs->rx_indicate_seq + 1) % 4096; 52 pRxTs->rx_indicate_seq = (pRxTs->rx_indicate_seq + 1) % 4096;
53 53
54 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"RxPktPendingTimeout(): IndicateSeq: %d\n", pReorderEntry->SeqNum); 54 IEEE80211_DEBUG(IEEE80211_DL_REORDER, "RxPktPendingTimeout(): IndicateSeq: %d\n", pReorderEntry->SeqNum);
55 ieee->stats_IndicateArray[index] = pReorderEntry->prxb; 55 ieee->stats_IndicateArray[index] = pReorderEntry->prxb;
56 index++; 56 index++;
57 57
@@ -151,9 +151,9 @@ void TSInitialize(struct ieee80211_device *ieee)
151 timer_setup(&pTxTS->ts_common_info.inact_timer, TsInactTimeout, 151 timer_setup(&pTxTS->ts_common_info.inact_timer, TsInactTimeout,
152 0); 152 0);
153 timer_setup(&pTxTS->ts_add_ba_timer, TsAddBaProcess, 0); 153 timer_setup(&pTxTS->ts_add_ba_timer, TsAddBaProcess, 0);
154 timer_setup(&pTxTS->tx_pending_ba_record.Timer, BaSetupTimeOut, 154 timer_setup(&pTxTS->tx_pending_ba_record.timer, BaSetupTimeOut,
155 0); 155 0);
156 timer_setup(&pTxTS->tx_admitted_ba_record.Timer, 156 timer_setup(&pTxTS->tx_admitted_ba_record.timer,
157 TxBaInactTimeout, 0); 157 TxBaInactTimeout, 0);
158 ResetTxTsEntry(pTxTS); 158 ResetTxTsEntry(pTxTS);
159 list_add_tail(&pTxTS->ts_common_info.list, &ieee->Tx_TS_Unused_List); 159 list_add_tail(&pTxTS->ts_common_info.list, &ieee->Tx_TS_Unused_List);
@@ -171,7 +171,7 @@ void TSInitialize(struct ieee80211_device *ieee)
171 0); 171 0);
172 timer_setup(&pRxTS->ts_common_info.inact_timer, TsInactTimeout, 172 timer_setup(&pRxTS->ts_common_info.inact_timer, TsInactTimeout,
173 0); 173 0);
174 timer_setup(&pRxTS->rx_admitted_ba_record.Timer, 174 timer_setup(&pRxTS->rx_admitted_ba_record.timer,
175 RxBaInactTimeout, 0); 175 RxBaInactTimeout, 0);
176 timer_setup(&pRxTS->rx_pkt_pending_timer, RxPktPendingTimeout, 0); 176 timer_setup(&pRxTS->rx_pkt_pending_timer, RxPktPendingTimeout, 0);
177 ResetRxTsEntry(pRxTS); 177 ResetRxTsEntry(pRxTS);
@@ -426,7 +426,7 @@ static void RemoveTsEntry(struct ieee80211_device *ieee, struct ts_common_info *
426 while(!list_empty(&pRxTS->rx_pending_pkt_list)) { 426 while(!list_empty(&pRxTS->rx_pending_pkt_list)) {
427 spin_lock_irqsave(&(ieee->reorder_spinlock), flags); 427 spin_lock_irqsave(&(ieee->reorder_spinlock), flags);
428 //pRxReorderEntry = list_entry(&pRxTS->rx_pending_pkt_list.prev,RX_REORDER_ENTRY,List); 428 //pRxReorderEntry = list_entry(&pRxTS->rx_pending_pkt_list.prev,RX_REORDER_ENTRY,List);
429 pRxReorderEntry = (PRX_REORDER_ENTRY)list_entry(pRxTS->rx_pending_pkt_list.prev,RX_REORDER_ENTRY,List); 429 pRxReorderEntry = (PRX_REORDER_ENTRY)list_entry(pRxTS->rx_pending_pkt_list.prev, RX_REORDER_ENTRY, List);
430 list_del_init(&pRxReorderEntry->List); 430 list_del_init(&pRxReorderEntry->List);
431 { 431 {
432 int i = 0; 432 int i = 0;
@@ -529,7 +529,7 @@ void TsStartAddBaProcess(struct ieee80211_device *ieee, struct tx_ts_record *pTx
529 mod_timer(&pTxTS->ts_add_ba_timer, 529 mod_timer(&pTxTS->ts_add_ba_timer,
530 jiffies + msecs_to_jiffies(TS_ADDBA_DELAY)); 530 jiffies + msecs_to_jiffies(TS_ADDBA_DELAY));
531 } else { 531 } else {
532 IEEE80211_DEBUG(IEEE80211_DL_BA,"TsStartAddBaProcess(): Immediately Start ADDBA now!!\n"); 532 IEEE80211_DEBUG(IEEE80211_DL_BA, "TsStartAddBaProcess(): Immediately Start ADDBA now!!\n");
533 mod_timer(&pTxTS->ts_add_ba_timer, jiffies+10); //set 10 ticks 533 mod_timer(&pTxTS->ts_add_ba_timer, jiffies+10); //set 10 ticks
534 } 534 }
535 } else { 535 } else {
diff --git a/drivers/staging/rtl8192u/r8180_93cx6.h b/drivers/staging/rtl8192u/r8180_93cx6.h
index 643d465e7105..0cdd00a4f7b8 100644
--- a/drivers/staging/rtl8192u/r8180_93cx6.h
+++ b/drivers/staging/rtl8192u/r8180_93cx6.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * This is part of rtl8187 OpenSource driver 3 * This is part of rtl8187 OpenSource driver
3 * Copyright (C) Andrea Merello 2004-2005 <andrea.merello@gmail.com> 4 * Copyright (C) Andrea Merello 2004-2005 <andrea.merello@gmail.com>
@@ -21,22 +22,4 @@
21 22
22#define EPROM_DELAY 10 23#define EPROM_DELAY 10
23 24
24#define EPROM_ANAPARAM_ADDRLWORD 0xd
25#define EPROM_ANAPARAM_ADDRHWORD 0xe
26
27#define EPROM_RFCHIPID 0x6
28#define EPROM_TXPW_BASE 0x05
29#define EPROM_RFCHIPID_RTL8225U 5
30#define EPROM_RF_PARAM 0x4
31#define EPROM_CONFIG2 0xc
32
33#define EPROM_VERSION 0x1E
34#define MAC_ADR 0x7
35
36#define CIS 0x18
37
38#define EPROM_TXPW0 0x16
39#define EPROM_TXPW2 0x1b
40#define EPROM_TXPW1 0x3d
41
42int eprom_read(struct net_device *dev, u32 addr); /* reads a 16 bits word */ 25int eprom_read(struct net_device *dev, u32 addr); /* reads a 16 bits word */
diff --git a/drivers/staging/rtl8192u/r8190_rtl8256.c b/drivers/staging/rtl8192u/r8190_rtl8256.c
index 9b7f822e9762..a8c8e8c0660d 100644
--- a/drivers/staging/rtl8192u/r8190_rtl8256.c
+++ b/drivers/staging/rtl8192u/r8190_rtl8256.c
@@ -14,6 +14,11 @@
14#include "r819xU_phy.h" 14#include "r819xU_phy.h"
15#include "r8190_rtl8256.h" 15#include "r8190_rtl8256.h"
16 16
17/*
18 * Forward declaration of local functions
19 */
20static void phy_rf8256_config_para_file(struct net_device *dev);
21
17/*-------------------------------------------------------------------------- 22/*--------------------------------------------------------------------------
18 * Overview: set RF band width (20M or 40M) 23 * Overview: set RF band width (20M or 40M)
19 * Input: struct net_device* dev 24 * Input: struct net_device* dev
@@ -23,7 +28,7 @@
23 * Note: 8226 support both 20M and 40 MHz 28 * Note: 8226 support both 20M and 40 MHz
24 *-------------------------------------------------------------------------- 29 *--------------------------------------------------------------------------
25 */ 30 */
26void PHY_SetRF8256Bandwidth(struct net_device *dev, enum ht_channel_width Bandwidth) 31void phy_set_rf8256_bandwidth(struct net_device *dev, enum ht_channel_width Bandwidth)
27{ 32{
28 u8 eRFPath; 33 u8 eRFPath;
29 struct r8192_priv *priv = ieee80211_priv(dev); 34 struct r8192_priv *priv = ieee80211_priv(dev);
@@ -37,9 +42,9 @@ void PHY_SetRF8256Bandwidth(struct net_device *dev, enum ht_channel_width Bandwi
37 42
38 switch (Bandwidth) { 43 switch (Bandwidth) {
39 case HT_CHANNEL_WIDTH_20: 44 case HT_CHANNEL_WIDTH_20:
40 if (priv->card_8192_version == VERSION_819xU_A 45 if (priv->card_8192_version == VERSION_819XU_A
41 || priv->card_8192_version 46 || priv->card_8192_version
42 == VERSION_819xU_B) { /* 8256 D-cut, E-cut, xiong: consider it later! */ 47 == VERSION_819XU_B) { /* 8256 D-cut, E-cut, xiong: consider it later! */
43 rtl8192_phy_SetRFReg(dev, 48 rtl8192_phy_SetRFReg(dev,
44 (enum rf90_radio_path_e)eRFPath, 49 (enum rf90_radio_path_e)eRFPath,
45 0x0b, bMask12Bits, 0x100); /* phy para:1ba */ 50 0x0b, bMask12Bits, 0x100); /* phy para:1ba */
@@ -53,11 +58,11 @@ void PHY_SetRF8256Bandwidth(struct net_device *dev, enum ht_channel_width Bandwi
53 (enum rf90_radio_path_e)eRFPath, 58 (enum rf90_radio_path_e)eRFPath,
54 0x14, bMask12Bits, 0x5ab); 59 0x14, bMask12Bits, 0x5ab);
55 } else { 60 } else {
56 RT_TRACE(COMP_ERR, "PHY_SetRF8256Bandwidth(): unknown hardware version\n"); 61 RT_TRACE(COMP_ERR, "phy_set_rf8256_bandwidth(): unknown hardware version\n");
57 } 62 }
58 break; 63 break;
59 case HT_CHANNEL_WIDTH_20_40: 64 case HT_CHANNEL_WIDTH_20_40:
60 if (priv->card_8192_version == VERSION_819xU_A || priv->card_8192_version == VERSION_819xU_B) { /* 8256 D-cut, E-cut, xiong: consider it later! */ 65 if (priv->card_8192_version == VERSION_819XU_A || priv->card_8192_version == VERSION_819XU_B) { /* 8256 D-cut, E-cut, xiong: consider it later! */
61 rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path_e)eRFPath, 0x0b, bMask12Bits, 0x300); /* phy para:3ba */ 66 rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path_e)eRFPath, 0x0b, bMask12Bits, 0x300); /* phy para:3ba */
62 rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path_e)eRFPath, 0x2c, bMask12Bits, 0x3df); 67 rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path_e)eRFPath, 0x2c, bMask12Bits, 0x3df);
63 rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path_e)eRFPath, 0x0e, bMask12Bits, 0x0a1); 68 rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path_e)eRFPath, 0x0e, bMask12Bits, 0x0a1);
@@ -68,11 +73,11 @@ void PHY_SetRF8256Bandwidth(struct net_device *dev, enum ht_channel_width Bandwi
68 else 73 else
69 rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path_e)eRFPath, 0x14, bMask12Bits, 0x5ab); 74 rtl8192_phy_SetRFReg(dev, (enum rf90_radio_path_e)eRFPath, 0x14, bMask12Bits, 0x5ab);
70 } else { 75 } else {
71 RT_TRACE(COMP_ERR, "PHY_SetRF8256Bandwidth(): unknown hardware version\n"); 76 RT_TRACE(COMP_ERR, "phy_set_rf8256_bandwidth(): unknown hardware version\n");
72 } 77 }
73 break; 78 break;
74 default: 79 default:
75 RT_TRACE(COMP_ERR, "PHY_SetRF8256Bandwidth(): unknown Bandwidth: %#X\n", Bandwidth); 80 RT_TRACE(COMP_ERR, "phy_set_rf8256_bandwidth(): unknown Bandwidth: %#X\n", Bandwidth);
76 break; 81 break;
77 82
78 } 83 }
@@ -85,7 +90,7 @@ void PHY_SetRF8256Bandwidth(struct net_device *dev, enum ht_channel_width Bandwi
85 * Return: NONE 90 * Return: NONE
86 *-------------------------------------------------------------------------- 91 *--------------------------------------------------------------------------
87 */ 92 */
88void PHY_RF8256_Config(struct net_device *dev) 93void phy_rf8256_config(struct net_device *dev)
89{ 94{
90 struct r8192_priv *priv = ieee80211_priv(dev); 95 struct r8192_priv *priv = ieee80211_priv(dev);
91 /* Initialize general global value 96 /* Initialize general global value
@@ -94,7 +99,7 @@ void PHY_RF8256_Config(struct net_device *dev)
94 */ 99 */
95 priv->NumTotalRFPath = RTL819X_TOTAL_RF_PATH; 100 priv->NumTotalRFPath = RTL819X_TOTAL_RF_PATH;
96 /* Config BB and RF */ 101 /* Config BB and RF */
97 phy_RF8256_Config_ParaFile(dev); 102 phy_rf8256_config_para_file(dev);
98} 103}
99/*-------------------------------------------------------------------------- 104/*--------------------------------------------------------------------------
100 * Overview: Interface to config 8256 105 * Overview: Interface to config 8256
@@ -103,7 +108,7 @@ void PHY_RF8256_Config(struct net_device *dev)
103 * Return: NONE 108 * Return: NONE
104 *-------------------------------------------------------------------------- 109 *--------------------------------------------------------------------------
105 */ 110 */
106void phy_RF8256_Config_ParaFile(struct net_device *dev) 111static void phy_rf8256_config_para_file(struct net_device *dev)
107{ 112{
108 u32 u4RegValue = 0; 113 u32 u4RegValue = 0;
109 u8 eRFPath; 114 u8 eRFPath;
@@ -152,7 +157,7 @@ void phy_RF8256_Config_ParaFile(struct net_device *dev)
152 * TODO: this function should be removed on ASIC , Emily 2007.2.2 157 * TODO: this function should be removed on ASIC , Emily 2007.2.2
153 */ 158 */
154 if (rtl8192_phy_checkBBAndRF(dev, HW90_BLOCK_RF, (enum rf90_radio_path_e)eRFPath)) { 159 if (rtl8192_phy_checkBBAndRF(dev, HW90_BLOCK_RF, (enum rf90_radio_path_e)eRFPath)) {
155 RT_TRACE(COMP_ERR, "PHY_RF8256_Config():Check Radio[%d] Fail!!\n", eRFPath); 160 RT_TRACE(COMP_ERR, "phy_rf8256_config():Check Radio[%d] Fail!!\n", eRFPath);
156 goto phy_RF8256_Config_ParaFile_Fail; 161 goto phy_RF8256_Config_ParaFile_Fail;
157 } 162 }
158 163
@@ -207,7 +212,7 @@ void phy_RF8256_Config_ParaFile(struct net_device *dev)
207 } 212 }
208 213
209 if (ret) { 214 if (ret) {
210 RT_TRACE(COMP_ERR, "phy_RF8256_Config_ParaFile():Radio[%d] Fail!!", eRFPath); 215 RT_TRACE(COMP_ERR, "phy_rf8256_config_para_file():Radio[%d] Fail!!", eRFPath);
211 goto phy_RF8256_Config_ParaFile_Fail; 216 goto phy_RF8256_Config_ParaFile_Fail;
212 } 217 }
213 218
@@ -221,7 +226,7 @@ phy_RF8256_Config_ParaFile_Fail:
221} 226}
222 227
223 228
224void PHY_SetRF8256CCKTxPower(struct net_device *dev, u8 powerlevel) 229void phy_set_rf8256_cck_tx_power(struct net_device *dev, u8 powerlevel)
225{ 230{
226 u32 TxAGC = 0; 231 u32 TxAGC = 0;
227 struct r8192_priv *priv = ieee80211_priv(dev); 232 struct r8192_priv *priv = ieee80211_priv(dev);
@@ -240,7 +245,7 @@ void PHY_SetRF8256CCKTxPower(struct net_device *dev, u8 powerlevel)
240} 245}
241 246
242 247
243void PHY_SetRF8256OFDMTxPower(struct net_device *dev, u8 powerlevel) 248void phy_set_rf8256_ofdm_tx_power(struct net_device *dev, u8 powerlevel)
244{ 249{
245 struct r8192_priv *priv = ieee80211_priv(dev); 250 struct r8192_priv *priv = ieee80211_priv(dev);
246 /* Joseph TxPower for 8192 testing */ 251 /* Joseph TxPower for 8192 testing */
diff --git a/drivers/staging/rtl8192u/r8190_rtl8256.h b/drivers/staging/rtl8192u/r8190_rtl8256.h
index 29b926cad14b..9ea67f86f911 100644
--- a/drivers/staging/rtl8192u/r8190_rtl8256.h
+++ b/drivers/staging/rtl8192u/r8190_rtl8256.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * This is part of the rtl8180-sa2400 driver 3 * This is part of the rtl8180-sa2400 driver
3 * released under the GPL (See file COPYING for details). 4 * released under the GPL (See file COPYING for details).
@@ -14,10 +15,10 @@
14#define RTL8225H 15#define RTL8225H
15 16
16#define RTL819X_TOTAL_RF_PATH 2 /* for 8192U */ 17#define RTL819X_TOTAL_RF_PATH 2 /* for 8192U */
17void PHY_SetRF8256Bandwidth(struct net_device *dev, enum ht_channel_width Bandwidth); 18void phy_set_rf8256_bandwidth(struct net_device *dev,
18void PHY_RF8256_Config(struct net_device *dev); 19 enum ht_channel_width bandwidth);
19void phy_RF8256_Config_ParaFile(struct net_device *dev); 20void phy_rf8256_config(struct net_device *dev);
20void PHY_SetRF8256CCKTxPower(struct net_device *dev, u8 powerlevel); 21void phy_set_rf8256_cck_tx_power(struct net_device *dev, u8 powerlevel);
21void PHY_SetRF8256OFDMTxPower(struct net_device *dev, u8 powerlevel); 22void phy_set_rf8256_ofdm_tx_power(struct net_device *dev, u8 powerlevel);
22 23
23#endif 24#endif
diff --git a/drivers/staging/rtl8192u/r8192U.h b/drivers/staging/rtl8192u/r8192U.h
index 94a148994069..e65a893fd084 100644
--- a/drivers/staging/rtl8192u/r8192U.h
+++ b/drivers/staging/rtl8192u/r8192U.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * This is part of rtl8187 OpenSource driver. 3 * This is part of rtl8187 OpenSource driver.
3 * Copyright (C) Andrea Merello 2004-2005 <andrea.merello@gmail.com> 4 * Copyright (C) Andrea Merello 2004-2005 <andrea.merello@gmail.com>
@@ -39,19 +40,19 @@
39#include "ieee80211/ieee80211.h" 40#include "ieee80211/ieee80211.h"
40 41
41#define RTL8192U 42#define RTL8192U
42#define RTL819xU_MODULE_NAME "rtl819xU" 43#define RTL819XU_MODULE_NAME "rtl819xU"
43/* HW security */ 44/* HW security */
44#define MAX_KEY_LEN 61 45#define MAX_KEY_LEN 61
45#define KEY_BUF_SIZE 5 46#define KEY_BUF_SIZE 5
46 47
47#define Rx_Smooth_Factor 20 48#define RX_SMOOTH_FACTOR 20
48#define DMESG(x, a...) 49#define DMESG(x, a...)
49#define DMESGW(x, a...) 50#define DMESGW(x, a...)
50#define DMESGE(x, a...) 51#define DMESGE(x, a...)
51extern u32 rt_global_debug_component; 52extern u32 rt_global_debug_component;
52#define RT_TRACE(component, x, args...) \ 53#define RT_TRACE(component, x, args...) \
53 do { \ 54 do { \
54 if (rt_global_debug_component & component) \ 55 if (rt_global_debug_component & (component)) \
55 pr_debug("RTL8192U: " x "\n", ##args); \ 56 pr_debug("RTL8192U: " x "\n", ##args); \
56 } while (0) 57 } while (0)
57 58
@@ -111,7 +112,7 @@ extern u32 rt_global_debug_component;
111 do { \ 112 do { \
112 if ((rt_global_debug_component & (level)) == (level)) { \ 113 if ((rt_global_debug_component & (level)) == (level)) { \
113 int i; \ 114 int i; \
114 u8 *pdata = (u8 *) data; \ 115 u8 *pdata = (u8 *)data; \
115 pr_debug("RTL8192U: %s()\n", __func__); \ 116 pr_debug("RTL8192U: %s()\n", __func__); \
116 for (i = 0; i < (int)(datalen); i++) { \ 117 for (i = 0; i < (int)(datalen); i++) { \
117 printk("%2x ", pdata[i]); \ 118 printk("%2x ", pdata[i]); \
@@ -798,6 +799,18 @@ typedef enum _tag_TxCmd_Config_Index {
798 TXCMD_XXXX_CTRL, 799 TXCMD_XXXX_CTRL,
799} DCMD_TXCMD_OP; 800} DCMD_TXCMD_OP;
800 801
802enum version_819xu {
803 VERSION_819XU_A, // A-cut
804 VERSION_819XU_B, // B-cut
805 VERSION_819XU_C,// C-cut
806};
807
808//added for different RF type
809enum rt_rf_type {
810 RF_1T2R = 0,
811 RF_2T4R,
812};
813
801typedef struct r8192_priv { 814typedef struct r8192_priv {
802 struct usb_device *udev; 815 struct usb_device *udev;
803 /* For maintain info from eeprom */ 816 /* For maintain info from eeprom */
@@ -815,7 +828,7 @@ typedef struct r8192_priv {
815 /* O: rtl8192, 1: rtl8185 V B/C, 2: rtl8185 V D */ 828 /* O: rtl8192, 1: rtl8185 V B/C, 2: rtl8185 V D */
816 short card_8192; 829 short card_8192;
817 /* If TCR reports card V B/C, this discriminates */ 830 /* If TCR reports card V B/C, this discriminates */
818 u8 card_8192_version; 831 enum version_819xu card_8192_version;
819 short enable_gpio0; 832 short enable_gpio0;
820 enum card_type { 833 enum card_type {
821 PCI, MINIPCI, CARDBUS, USB 834 PCI, MINIPCI, CARDBUS, USB
@@ -838,7 +851,7 @@ typedef struct r8192_priv {
838 851
839 struct mutex wx_mutex; 852 struct mutex wx_mutex;
840 853
841 u8 rf_type; /* 0: 1T2R, 1: 2T4R */ 854 enum rt_rf_type rf_type; /* 0: 1T2R, 1: 2T4R */
842 RT_RF_TYPE_819xU rf_chip; 855 RT_RF_TYPE_819xU rf_chip;
843 856
844 short (*rf_set_sens)(struct net_device *dev, short sens); 857 short (*rf_set_sens)(struct net_device *dev, short sens);
@@ -864,9 +877,9 @@ typedef struct r8192_priv {
864 int rx_inx; 877 int rx_inx;
865#endif 878#endif
866 879
867 struct sk_buff_head rx_queue; 880 struct sk_buff_head rx_queue;
868 struct sk_buff_head skb_queue; 881 struct sk_buff_head skb_queue;
869 struct work_struct qos_activate; 882 struct work_struct qos_activate;
870 short tx_urb_index; 883 short tx_urb_index;
871 atomic_t tx_pending[0x10]; /* UART_PRIORITY + 1 */ 884 atomic_t tx_pending[0x10]; /* UART_PRIORITY + 1 */
872 885
@@ -1014,7 +1027,7 @@ typedef struct r8192_priv {
1014 u8 nrxAMPDU_aggr_num; 1027 u8 nrxAMPDU_aggr_num;
1015 1028
1016 /* For gpio */ 1029 /* For gpio */
1017 bool bHwRadioOff; 1030 bool bHwRadioOff;
1018 1031
1019 u32 reset_count; 1032 u32 reset_count;
1020 bool bpbc_pressed; 1033 bool bpbc_pressed;
@@ -1079,9 +1092,6 @@ bool init_firmware(struct net_device *dev);
1079short rtl819xU_tx_cmd(struct net_device *dev, struct sk_buff *skb); 1092short rtl819xU_tx_cmd(struct net_device *dev, struct sk_buff *skb);
1080short rtl8192_tx(struct net_device *dev, struct sk_buff *skb); 1093short rtl8192_tx(struct net_device *dev, struct sk_buff *skb);
1081 1094
1082u32 read_cam(struct net_device *dev, u8 addr);
1083void write_cam(struct net_device *dev, u8 addr, u32 data);
1084
1085int read_nic_byte(struct net_device *dev, int x, u8 *data); 1095int read_nic_byte(struct net_device *dev, int x, u8 *data);
1086int read_nic_byte_E(struct net_device *dev, int x, u8 *data); 1096int read_nic_byte_E(struct net_device *dev, int x, u8 *data);
1087int read_nic_dword(struct net_device *dev, int x, u32 *data); 1097int read_nic_dword(struct net_device *dev, int x, u32 *data);
@@ -1094,22 +1104,12 @@ void force_pci_posting(struct net_device *dev);
1094 1104
1095void rtl8192_rtx_disable(struct net_device *dev); 1105void rtl8192_rtx_disable(struct net_device *dev);
1096void rtl8192_rx_enable(struct net_device *dev); 1106void rtl8192_rx_enable(struct net_device *dev);
1097void rtl8192_tx_enable(struct net_device *dev);
1098
1099void rtl8192_disassociate(struct net_device *dev);
1100void rtl8185_set_rf_pins_enable(struct net_device *dev, u32 a);
1101 1107
1102void rtl8192_set_anaparam(struct net_device *dev, u32 a);
1103void rtl8185_set_anaparam2(struct net_device *dev, u32 a);
1104void rtl8192_update_msr(struct net_device *dev); 1108void rtl8192_update_msr(struct net_device *dev);
1105int rtl8192_down(struct net_device *dev); 1109int rtl8192_down(struct net_device *dev);
1106int rtl8192_up(struct net_device *dev); 1110int rtl8192_up(struct net_device *dev);
1107void rtl8192_commit(struct net_device *dev); 1111void rtl8192_commit(struct net_device *dev);
1108void rtl8192_set_chan(struct net_device *dev, short ch); 1112void rtl8192_set_chan(struct net_device *dev, short ch);
1109void write_phy(struct net_device *dev, u8 adr, u8 data);
1110void write_phy_cck(struct net_device *dev, u8 adr, u32 data);
1111void write_phy_ofdm(struct net_device *dev, u8 adr, u32 data);
1112void rtl8185_tx_antenna(struct net_device *dev, u8 ant);
1113void rtl8192_set_rxconf(struct net_device *dev); 1113void rtl8192_set_rxconf(struct net_device *dev);
1114void rtl819xusb_beacon_tx(struct net_device *dev, u16 tx_rate); 1114void rtl819xusb_beacon_tx(struct net_device *dev, u16 tx_rate);
1115 1115
diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c
index e218b5c20642..0ac0bbf7d923 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -128,7 +128,7 @@ static void rtl8192_usb_disconnect(struct usb_interface *intf);
128 128
129 129
130static struct usb_driver rtl8192_usb_driver = { 130static struct usb_driver rtl8192_usb_driver = {
131 .name = RTL819xU_MODULE_NAME, /* Driver name */ 131 .name = RTL819XU_MODULE_NAME, /* Driver name */
132 .id_table = rtl8192_usb_id_tbl, /* PCI_ID table */ 132 .id_table = rtl8192_usb_id_tbl, /* PCI_ID table */
133 .probe = rtl8192_usb_probe, /* probe fn */ 133 .probe = rtl8192_usb_probe, /* probe fn */
134 .disconnect = rtl8192_usb_disconnect, /* remove fn */ 134 .disconnect = rtl8192_usb_disconnect, /* remove fn */
@@ -183,7 +183,7 @@ static void rtl819x_set_channel_map(u8 channel_plan, struct r8192_priv *priv)
183 case COUNTRY_CODE_ISRAEL: 183 case COUNTRY_CODE_ISRAEL:
184 case COUNTRY_CODE_TELEC: 184 case COUNTRY_CODE_TELEC:
185 case COUNTRY_CODE_MIC: 185 case COUNTRY_CODE_MIC:
186 Dot11d_Init(ieee); 186 rtl8192u_dot11d_init(ieee);
187 ieee->bGlobalDomain = false; 187 ieee->bGlobalDomain = false;
188 /* actually 8225 & 8256 rf chips only support B,G,24N mode */ 188 /* actually 8225 & 8256 rf chips only support B,G,24N mode */
189 if ((priv->rf_chip == RF_8225) || (priv->rf_chip == RF_8256)) { 189 if ((priv->rf_chip == RF_8225) || (priv->rf_chip == RF_8256)) {
@@ -211,8 +211,8 @@ static void rtl819x_set_channel_map(u8 channel_plan, struct r8192_priv *priv)
211 /* this flag enabled to follow 11d country IE setting, 211 /* this flag enabled to follow 11d country IE setting,
212 * otherwise, it shall follow global domain settings. 212 * otherwise, it shall follow global domain settings.
213 */ 213 */
214 GET_DOT11D_INFO(ieee)->enabled = 0; 214 GET_DOT11D_INFO(ieee)->dot11d_enabled = 0;
215 Dot11d_Reset(ieee); 215 dot11d_reset(ieee);
216 ieee->bGlobalDomain = true; 216 ieee->bGlobalDomain = true;
217 break; 217 break;
218 218
@@ -237,22 +237,6 @@ static void CamResetAllEntry(struct net_device *dev)
237 write_nic_dword(dev, RWCAM, ulcommand); 237 write_nic_dword(dev, RWCAM, ulcommand);
238} 238}
239 239
240
241void write_cam(struct net_device *dev, u8 addr, u32 data)
242{
243 write_nic_dword(dev, WCAMI, data);
244 write_nic_dword(dev, RWCAM, BIT(31) | BIT(16) | (addr & 0xff));
245}
246
247u32 read_cam(struct net_device *dev, u8 addr)
248{
249 u32 data;
250
251 write_nic_dword(dev, RWCAM, 0x80000000 | (addr & 0xff));
252 read_nic_dword(dev, 0xa8, &data);
253 return data;
254}
255
256int write_nic_byte_E(struct net_device *dev, int indx, u8 data) 240int write_nic_byte_E(struct net_device *dev, int indx, u8 data)
257{ 241{
258 int status; 242 int status;
@@ -643,7 +627,7 @@ static int __maybe_unused proc_get_stats_rx(struct seq_file *m, void *v)
643static void rtl8192_proc_module_init(void) 627static void rtl8192_proc_module_init(void)
644{ 628{
645 RT_TRACE(COMP_INIT, "Initializing proc filesystem"); 629 RT_TRACE(COMP_INIT, "Initializing proc filesystem");
646 rtl8192_proc = proc_mkdir(RTL819xU_MODULE_NAME, init_net.proc_net); 630 rtl8192_proc = proc_mkdir(RTL819XU_MODULE_NAME, init_net.proc_net);
647} 631}
648 632
649static void rtl8192_proc_init_one(struct net_device *dev) 633static void rtl8192_proc_init_one(struct net_device *dev)
@@ -846,13 +830,6 @@ void rtl8192_rx_enable(struct net_device *dev)
846 rtl8192_rx_initiate(dev); 830 rtl8192_rx_initiate(dev);
847} 831}
848 832
849
850void rtl8192_tx_enable(struct net_device *dev)
851{
852}
853
854
855
856void rtl8192_rtx_disable(struct net_device *dev) 833void rtl8192_rtx_disable(struct net_device *dev)
857{ 834{
858 u8 cmd; 835 u8 cmd;
@@ -1997,7 +1974,7 @@ static void rtl8192_update_ratr_table(struct net_device *dev)
1997 break; 1974 break;
1998 case IEEE_N_24G: 1975 case IEEE_N_24G:
1999 case IEEE_N_5G: 1976 case IEEE_N_5G:
2000 if (ieee->pHTInfo->PeerMimoPs == 0) { /* MIMO_PS_STATIC */ 1977 if (ieee->pHTInfo->PeerMimoPs == MIMO_PS_STATIC) {
2001 ratr_value &= 0x0007F007; 1978 ratr_value &= 0x0007F007;
2002 } else { 1979 } else {
2003 if (priv->rf_type == RF_1T2R) 1980 if (priv->rf_type == RF_1T2R)
@@ -2382,20 +2359,20 @@ static int rtl8192_read_eeprom_info(struct net_device *dev)
2382 if (ret < 0) 2359 if (ret < 0)
2383 return ret; 2360 return ret;
2384 priv->eeprom_pid = (u16)ret; 2361 priv->eeprom_pid = (u16)ret;
2385 ret = eprom_read(dev, EEPROM_ChannelPlan >> 1); 2362 ret = eprom_read(dev, EEPROM_CHANNEL_PLAN >> 1);
2386 if (ret < 0) 2363 if (ret < 0)
2387 return ret; 2364 return ret;
2388 tmpValue = (u16)ret; 2365 tmpValue = (u16)ret;
2389 priv->eeprom_ChannelPlan = (tmpValue & 0xff00) >> 8; 2366 priv->eeprom_ChannelPlan = (tmpValue & 0xff00) >> 8;
2390 priv->btxpowerdata_readfromEEPORM = true; 2367 priv->btxpowerdata_readfromEEPORM = true;
2391 ret = eprom_read(dev, (EEPROM_Customer_ID >> 1)) >> 8; 2368 ret = eprom_read(dev, (EEPROM_CUSTOMER_ID >> 1)) >> 8;
2392 if (ret < 0) 2369 if (ret < 0)
2393 return ret; 2370 return ret;
2394 priv->eeprom_CustomerID = (u16)ret; 2371 priv->eeprom_CustomerID = (u16)ret;
2395 } else { 2372 } else {
2396 priv->eeprom_vid = 0; 2373 priv->eeprom_vid = 0;
2397 priv->eeprom_pid = 0; 2374 priv->eeprom_pid = 0;
2398 priv->card_8192_version = VERSION_819xU_B; 2375 priv->card_8192_version = VERSION_819XU_B;
2399 priv->eeprom_ChannelPlan = 0; 2376 priv->eeprom_ChannelPlan = 0;
2400 priv->eeprom_CustomerID = 0; 2377 priv->eeprom_CustomerID = 0;
2401 } 2378 }
@@ -2422,48 +2399,48 @@ static int rtl8192_read_eeprom_info(struct net_device *dev)
2422 priv->rf_type = RTL819X_DEFAULT_RF_TYPE; /* default 1T2R */ 2399 priv->rf_type = RTL819X_DEFAULT_RF_TYPE; /* default 1T2R */
2423 priv->rf_chip = RF_8256; 2400 priv->rf_chip = RF_8256;
2424 2401
2425 if (priv->card_8192_version == (u8)VERSION_819xU_A) { 2402 if (priv->card_8192_version == VERSION_819XU_A) {
2426 /* read Tx power gain offset of legacy OFDM to HT rate */ 2403 /* read Tx power gain offset of legacy OFDM to HT rate */
2427 if (bLoad_From_EEPOM) { 2404 if (bLoad_From_EEPOM) {
2428 ret = eprom_read(dev, (EEPROM_TxPowerDiff >> 1)); 2405 ret = eprom_read(dev, (EEPROM_TX_POWER_DIFF >> 1));
2429 if (ret < 0) 2406 if (ret < 0)
2430 return ret; 2407 return ret;
2431 priv->EEPROMTxPowerDiff = ((u16)ret & 0xff00) >> 8; 2408 priv->EEPROMTxPowerDiff = ((u16)ret & 0xff00) >> 8;
2432 } else 2409 } else
2433 priv->EEPROMTxPowerDiff = EEPROM_Default_TxPower; 2410 priv->EEPROMTxPowerDiff = EEPROM_DEFAULT_TX_POWER;
2434 RT_TRACE(COMP_EPROM, "TxPowerDiff:%d\n", priv->EEPROMTxPowerDiff); 2411 RT_TRACE(COMP_EPROM, "TxPowerDiff:%d\n", priv->EEPROMTxPowerDiff);
2435 /* read ThermalMeter from EEPROM */ 2412 /* read ThermalMeter from EEPROM */
2436 if (bLoad_From_EEPOM) { 2413 if (bLoad_From_EEPOM) {
2437 ret = eprom_read(dev, (EEPROM_ThermalMeter >> 1)); 2414 ret = eprom_read(dev, (EEPROM_THERMAL_METER >> 1));
2438 if (ret < 0) 2415 if (ret < 0)
2439 return ret; 2416 return ret;
2440 priv->EEPROMThermalMeter = (u8)((u16)ret & 0x00ff); 2417 priv->EEPROMThermalMeter = (u8)((u16)ret & 0x00ff);
2441 } else 2418 } else
2442 priv->EEPROMThermalMeter = EEPROM_Default_ThermalMeter; 2419 priv->EEPROMThermalMeter = EEPROM_DEFAULT_THERNAL_METER;
2443 RT_TRACE(COMP_EPROM, "ThermalMeter:%d\n", priv->EEPROMThermalMeter); 2420 RT_TRACE(COMP_EPROM, "ThermalMeter:%d\n", priv->EEPROMThermalMeter);
2444 /* for tx power track */ 2421 /* for tx power track */
2445 priv->TSSI_13dBm = priv->EEPROMThermalMeter * 100; 2422 priv->TSSI_13dBm = priv->EEPROMThermalMeter * 100;
2446 /* read antenna tx power offset of B/C/D to A from EEPROM */ 2423 /* read antenna tx power offset of B/C/D to A from EEPROM */
2447 if (bLoad_From_EEPOM) { 2424 if (bLoad_From_EEPOM) {
2448 ret = eprom_read(dev, (EEPROM_PwDiff >> 1)); 2425 ret = eprom_read(dev, (EEPROM_PW_DIFF >> 1));
2449 if (ret < 0) 2426 if (ret < 0)
2450 return ret; 2427 return ret;
2451 priv->EEPROMPwDiff = ((u16)ret & 0x0f00) >> 8; 2428 priv->EEPROMPwDiff = ((u16)ret & 0x0f00) >> 8;
2452 } else 2429 } else
2453 priv->EEPROMPwDiff = EEPROM_Default_PwDiff; 2430 priv->EEPROMPwDiff = EEPROM_DEFAULT_PW_DIFF;
2454 RT_TRACE(COMP_EPROM, "TxPwDiff:%d\n", priv->EEPROMPwDiff); 2431 RT_TRACE(COMP_EPROM, "TxPwDiff:%d\n", priv->EEPROMPwDiff);
2455 /* Read CrystalCap from EEPROM */ 2432 /* Read CrystalCap from EEPROM */
2456 if (bLoad_From_EEPOM) { 2433 if (bLoad_From_EEPOM) {
2457 ret = eprom_read(dev, (EEPROM_CrystalCap >> 1)); 2434 ret = eprom_read(dev, (EEPROM_CRYSTAL_CAP >> 1));
2458 if (ret < 0) 2435 if (ret < 0)
2459 return ret; 2436 return ret;
2460 priv->EEPROMCrystalCap = (u16)ret & 0x0f; 2437 priv->EEPROMCrystalCap = (u16)ret & 0x0f;
2461 } else 2438 } else
2462 priv->EEPROMCrystalCap = EEPROM_Default_CrystalCap; 2439 priv->EEPROMCrystalCap = EEPROM_DEFAULT_CRYSTAL_CAP;
2463 RT_TRACE(COMP_EPROM, "CrystalCap = %d\n", priv->EEPROMCrystalCap); 2440 RT_TRACE(COMP_EPROM, "CrystalCap = %d\n", priv->EEPROMCrystalCap);
2464 /* get per-channel Tx power level */ 2441 /* get per-channel Tx power level */
2465 if (bLoad_From_EEPOM) { 2442 if (bLoad_From_EEPOM) {
2466 ret = eprom_read(dev, (EEPROM_TxPwIndex_Ver >> 1)); 2443 ret = eprom_read(dev, (EEPROM_TX_PW_INDEX_VER >> 1));
2467 if (ret < 0) 2444 if (ret < 0)
2468 return ret; 2445 return ret;
2469 priv->EEPROM_Def_Ver = ((u16)ret & 0xff00) >> 8; 2446 priv->EEPROM_Def_Ver = ((u16)ret & 0xff00) >> 8;
@@ -2474,7 +2451,7 @@ static int rtl8192_read_eeprom_info(struct net_device *dev)
2474 int i; 2451 int i;
2475 2452
2476 if (bLoad_From_EEPOM) { 2453 if (bLoad_From_EEPOM) {
2477 ret = eprom_read(dev, (EEPROM_TxPwIndex_CCK >> 1)); 2454 ret = eprom_read(dev, (EEPROM_TX_PW_INDEX_CCK >> 1));
2478 if (ret < 0) 2455 if (ret < 0)
2479 return ret; 2456 return ret;
2480 priv->EEPROMTxPowerLevelCCK = ((u16)ret & 0xff) >> 8; 2457 priv->EEPROMTxPowerLevelCCK = ((u16)ret & 0xff) >> 8;
@@ -2483,10 +2460,10 @@ static int rtl8192_read_eeprom_info(struct net_device *dev)
2483 RT_TRACE(COMP_EPROM, "CCK Tx Power Levl: 0x%02x\n", priv->EEPROMTxPowerLevelCCK); 2460 RT_TRACE(COMP_EPROM, "CCK Tx Power Levl: 0x%02x\n", priv->EEPROMTxPowerLevelCCK);
2484 for (i = 0; i < 3; i++) { 2461 for (i = 0; i < 3; i++) {
2485 if (bLoad_From_EEPOM) { 2462 if (bLoad_From_EEPOM) {
2486 ret = eprom_read(dev, (EEPROM_TxPwIndex_OFDM_24G + i) >> 1); 2463 ret = eprom_read(dev, (EEPROM_TX_PW_INDEX_OFDM_24G + i) >> 1);
2487 if (ret < 0) 2464 if (ret < 0)
2488 return ret; 2465 return ret;
2489 if (((EEPROM_TxPwIndex_OFDM_24G + i) % 2) == 0) 2466 if (((EEPROM_TX_PW_INDEX_OFDM_24G + i) % 2) == 0)
2490 tmpValue = (u16)ret & 0x00ff; 2467 tmpValue = (u16)ret & 0x00ff;
2491 else 2468 else
2492 tmpValue = ((u16)ret & 0xff00) >> 8; 2469 tmpValue = ((u16)ret & 0xff00) >> 8;
@@ -2498,7 +2475,7 @@ static int rtl8192_read_eeprom_info(struct net_device *dev)
2498 } 2475 }
2499 } else if (priv->EEPROM_Def_Ver == 1) { 2476 } else if (priv->EEPROM_Def_Ver == 1) {
2500 if (bLoad_From_EEPOM) { 2477 if (bLoad_From_EEPOM) {
2501 ret = eprom_read(dev, EEPROM_TxPwIndex_CCK_V1 >> 1); 2478 ret = eprom_read(dev, EEPROM_TX_PW_INDEX_CCK_V1 >> 1);
2502 if (ret < 0) 2479 if (ret < 0)
2503 return ret; 2480 return ret;
2504 tmpValue = ((u16)ret & 0xff00) >> 8; 2481 tmpValue = ((u16)ret & 0xff00) >> 8;
@@ -2508,7 +2485,7 @@ static int rtl8192_read_eeprom_info(struct net_device *dev)
2508 priv->EEPROMTxPowerLevelCCK_V1[0] = (u8)tmpValue; 2485 priv->EEPROMTxPowerLevelCCK_V1[0] = (u8)tmpValue;
2509 2486
2510 if (bLoad_From_EEPOM) { 2487 if (bLoad_From_EEPOM) {
2511 ret = eprom_read(dev, (EEPROM_TxPwIndex_CCK_V1 + 2) >> 1); 2488 ret = eprom_read(dev, (EEPROM_TX_PW_INDEX_CCK_V1 + 2) >> 1);
2512 if (ret < 0) 2489 if (ret < 0)
2513 return ret; 2490 return ret;
2514 tmpValue = (u16)ret; 2491 tmpValue = (u16)ret;
@@ -2517,12 +2494,12 @@ static int rtl8192_read_eeprom_info(struct net_device *dev)
2517 *((u16 *)(&priv->EEPROMTxPowerLevelCCK_V1[1])) = tmpValue; 2494 *((u16 *)(&priv->EEPROMTxPowerLevelCCK_V1[1])) = tmpValue;
2518 if (bLoad_From_EEPOM) 2495 if (bLoad_From_EEPOM)
2519 tmpValue = eprom_read(dev, 2496 tmpValue = eprom_read(dev,
2520 EEPROM_TxPwIndex_OFDM_24G_V1 >> 1); 2497 EEPROM_TX_PW_INDEX_OFDM_24G_V1 >> 1);
2521 else 2498 else
2522 tmpValue = 0x1010; 2499 tmpValue = 0x1010;
2523 *((u16 *)(&priv->EEPROMTxPowerLevelOFDM24G[0])) = tmpValue; 2500 *((u16 *)(&priv->EEPROMTxPowerLevelOFDM24G[0])) = tmpValue;
2524 if (bLoad_From_EEPOM) 2501 if (bLoad_From_EEPOM)
2525 tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_OFDM_24G_V1 + 2) >> 1); 2502 tmpValue = eprom_read(dev, (EEPROM_TX_PW_INDEX_OFDM_24G_V1 + 2) >> 1);
2526 else 2503 else
2527 tmpValue = 0x10; 2504 tmpValue = 0x10;
2528 priv->EEPROMTxPowerLevelOFDM24G[2] = (u8)tmpValue; 2505 priv->EEPROMTxPowerLevelOFDM24G[2] = (u8)tmpValue;
@@ -2567,7 +2544,7 @@ static int rtl8192_read_eeprom_info(struct net_device *dev)
2567 * 92U does not enable TX power tracking. 2544 * 92U does not enable TX power tracking.
2568 */ 2545 */
2569 priv->ThermalMeter[0] = priv->EEPROMThermalMeter; 2546 priv->ThermalMeter[0] = priv->EEPROMThermalMeter;
2570 } /* end if VersionID == VERSION_819xU_A */ 2547 } /* end if VersionID == VERSION_819XU_A */
2571 2548
2572 /* for dlink led */ 2549 /* for dlink led */
2573 switch (priv->eeprom_CustomerID) { 2550 switch (priv->eeprom_CustomerID) {
@@ -2872,7 +2849,7 @@ static bool rtl8192_adapter_start(struct net_device *dev)
2872 2849
2873 rtl8192_phy_configmac(dev); 2850 rtl8192_phy_configmac(dev);
2874 2851
2875 if (priv->card_8192_version == (u8)VERSION_819xU_A) { 2852 if (priv->card_8192_version == VERSION_819XU_A) {
2876 rtl8192_phy_getTxPower(dev); 2853 rtl8192_phy_getTxPower(dev);
2877 rtl8192_phy_setTxPower(dev, priv->chan); 2854 rtl8192_phy_setTxPower(dev, priv->chan);
2878 } 2855 }
@@ -3998,13 +3975,13 @@ static void rtl8192_process_phyinfo(struct r8192_priv *priv, u8 *buffer,
3998 pprevious_stats->RxMIMOSignalStrength[rfpath]; 3975 pprevious_stats->RxMIMOSignalStrength[rfpath];
3999 if (pprevious_stats->RxMIMOSignalStrength[rfpath] > priv->stats.rx_rssi_percentage[rfpath]) { 3976 if (pprevious_stats->RxMIMOSignalStrength[rfpath] > priv->stats.rx_rssi_percentage[rfpath]) {
4000 priv->stats.rx_rssi_percentage[rfpath] = 3977 priv->stats.rx_rssi_percentage[rfpath] =
4001 ((priv->stats.rx_rssi_percentage[rfpath] * (Rx_Smooth_Factor - 1)) + 3978 ((priv->stats.rx_rssi_percentage[rfpath] * (RX_SMOOTH_FACTOR - 1)) +
4002 (pprevious_stats->RxMIMOSignalStrength[rfpath])) / (Rx_Smooth_Factor); 3979 (pprevious_stats->RxMIMOSignalStrength[rfpath])) / (RX_SMOOTH_FACTOR);
4003 priv->stats.rx_rssi_percentage[rfpath] = priv->stats.rx_rssi_percentage[rfpath] + 1; 3980 priv->stats.rx_rssi_percentage[rfpath] = priv->stats.rx_rssi_percentage[rfpath] + 1;
4004 } else { 3981 } else {
4005 priv->stats.rx_rssi_percentage[rfpath] = 3982 priv->stats.rx_rssi_percentage[rfpath] =
4006 ((priv->stats.rx_rssi_percentage[rfpath] * (Rx_Smooth_Factor - 1)) + 3983 ((priv->stats.rx_rssi_percentage[rfpath] * (RX_SMOOTH_FACTOR - 1)) +
4007 (pprevious_stats->RxMIMOSignalStrength[rfpath])) / (Rx_Smooth_Factor); 3984 (pprevious_stats->RxMIMOSignalStrength[rfpath])) / (RX_SMOOTH_FACTOR);
4008 } 3985 }
4009 RT_TRACE(COMP_DBG, 3986 RT_TRACE(COMP_DBG,
4010 "priv->stats.rx_rssi_percentage[rfPath] = %d\n", 3987 "priv->stats.rx_rssi_percentage[rfPath] = %d\n",
@@ -4049,13 +4026,13 @@ static void rtl8192_process_phyinfo(struct r8192_priv *priv, u8 *buffer,
4049 pprevious_stats->RxPWDBAll; 4026 pprevious_stats->RxPWDBAll;
4050 if (pprevious_stats->RxPWDBAll > (u32)priv->undecorated_smoothed_pwdb) { 4027 if (pprevious_stats->RxPWDBAll > (u32)priv->undecorated_smoothed_pwdb) {
4051 priv->undecorated_smoothed_pwdb = 4028 priv->undecorated_smoothed_pwdb =
4052 (((priv->undecorated_smoothed_pwdb) * (Rx_Smooth_Factor - 1)) + 4029 (((priv->undecorated_smoothed_pwdb) * (RX_SMOOTH_FACTOR - 1)) +
4053 (pprevious_stats->RxPWDBAll)) / (Rx_Smooth_Factor); 4030 (pprevious_stats->RxPWDBAll)) / (RX_SMOOTH_FACTOR);
4054 priv->undecorated_smoothed_pwdb = priv->undecorated_smoothed_pwdb + 1; 4031 priv->undecorated_smoothed_pwdb = priv->undecorated_smoothed_pwdb + 1;
4055 } else { 4032 } else {
4056 priv->undecorated_smoothed_pwdb = 4033 priv->undecorated_smoothed_pwdb =
4057 (((priv->undecorated_smoothed_pwdb) * (Rx_Smooth_Factor - 1)) + 4034 (((priv->undecorated_smoothed_pwdb) * (RX_SMOOTH_FACTOR - 1)) +
4058 (pprevious_stats->RxPWDBAll)) / (Rx_Smooth_Factor); 4035 (pprevious_stats->RxPWDBAll)) / (RX_SMOOTH_FACTOR);
4059 } 4036 }
4060 } 4037 }
4061 4038
@@ -4098,8 +4075,8 @@ static void rtl8192_process_phyinfo(struct r8192_priv *priv, u8 *buffer,
4098 if (priv->stats.rx_evm_percentage[nspatial_stream] == 0) /* initialize */ 4075 if (priv->stats.rx_evm_percentage[nspatial_stream] == 0) /* initialize */
4099 priv->stats.rx_evm_percentage[nspatial_stream] = pprevious_stats->RxMIMOSignalQuality[nspatial_stream]; 4076 priv->stats.rx_evm_percentage[nspatial_stream] = pprevious_stats->RxMIMOSignalQuality[nspatial_stream];
4100 priv->stats.rx_evm_percentage[nspatial_stream] = 4077 priv->stats.rx_evm_percentage[nspatial_stream] =
4101 ((priv->stats.rx_evm_percentage[nspatial_stream] * (Rx_Smooth_Factor - 1)) + 4078 ((priv->stats.rx_evm_percentage[nspatial_stream] * (RX_SMOOTH_FACTOR - 1)) +
4102 (pprevious_stats->RxMIMOSignalQuality[nspatial_stream] * 1)) / (Rx_Smooth_Factor); 4079 (pprevious_stats->RxMIMOSignalQuality[nspatial_stream] * 1)) / (RX_SMOOTH_FACTOR);
4103 } 4080 }
4104 } 4081 }
4105 } 4082 }
@@ -4460,15 +4437,15 @@ static void TranslateRxSignalStuff819xUsb(struct sk_buff *skb,
4460 4437
4461 /* Check if the received packet is acceptable. */ 4438 /* Check if the received packet is acceptable. */
4462 bpacket_match_bssid = (type != IEEE80211_FTYPE_CTL) && 4439 bpacket_match_bssid = (type != IEEE80211_FTYPE_CTL) &&
4463 (eqMacAddr(priv->ieee80211->current_network.bssid, (fc & IEEE80211_FCTL_TODS) ? hdr->addr1 : (fc & IEEE80211_FCTL_FROMDS) ? hdr->addr2 : hdr->addr3)) 4440 (ether_addr_equal(priv->ieee80211->current_network.bssid, (fc & IEEE80211_FCTL_TODS) ? hdr->addr1 : (fc & IEEE80211_FCTL_FROMDS) ? hdr->addr2 : hdr->addr3))
4464 && (!pstats->bHwError) && (!pstats->bCRC) && (!pstats->bICV); 4441 && (!pstats->bHwError) && (!pstats->bCRC) && (!pstats->bICV);
4465 bpacket_toself = bpacket_match_bssid & 4442 bpacket_toself = bpacket_match_bssid &
4466 (eqMacAddr(praddr, priv->ieee80211->dev->dev_addr)); 4443 (ether_addr_equal(praddr, priv->ieee80211->dev->dev_addr));
4467 4444
4468 if (WLAN_FC_GET_FRAMETYPE(fc) == IEEE80211_STYPE_BEACON) 4445 if (WLAN_FC_GET_FRAMETYPE(fc) == IEEE80211_STYPE_BEACON)
4469 bPacketBeacon = true; 4446 bPacketBeacon = true;
4470 if (WLAN_FC_GET_FRAMETYPE(fc) == IEEE80211_STYPE_BLOCKACK) { 4447 if (WLAN_FC_GET_FRAMETYPE(fc) == IEEE80211_STYPE_BLOCKACK) {
4471 if ((eqMacAddr(praddr, dev->dev_addr))) 4448 if ((ether_addr_equal(praddr, dev->dev_addr)))
4472 bToSelfBA = true; 4449 bToSelfBA = true;
4473 } 4450 }
4474 4451
diff --git a/drivers/staging/rtl8192u/r8192U_hw.h b/drivers/staging/rtl8192u/r8192U_hw.h
index 00a123d44207..5a958335681d 100644
--- a/drivers/staging/rtl8192u/r8192U_hw.h
+++ b/drivers/staging/rtl8192u/r8192U_hw.h
@@ -20,24 +20,6 @@
20#ifndef R8192_HW 20#ifndef R8192_HW
21#define R8192_HW 21#define R8192_HW
22 22
23typedef enum _VERSION_819xU {
24 VERSION_819xU_A, // A-cut
25 VERSION_819xU_B, // B-cut
26 VERSION_819xU_C,// C-cut
27} VERSION_819xU, *PVERSION_819xU;
28//added for different RF type
29typedef enum _RT_RF_TYPE_DEF {
30 RF_1T2R = 0,
31 RF_2T4R,
32
33 RF_819X_MAX_TYPE
34} RT_RF_TYPE_DEF;
35
36
37typedef enum _BaseBand_Config_Type {
38 BaseBand_Config_PHY_REG = 0, //Radio Path A
39 BaseBand_Config_AGC_TAB = 1, //Radio Path B
40} BaseBand_Config_Type, *PBaseBand_Config_Type;
41#define RTL8187_REQT_READ 0xc0 23#define RTL8187_REQT_READ 0xc0
42#define RTL8187_REQT_WRITE 0x40 24#define RTL8187_REQT_WRITE 0x40
43#define RTL8187_REQ_GET_REGS 0x05 25#define RTL8187_REQ_GET_REGS 0x05
@@ -47,58 +29,33 @@ typedef enum _BaseBand_Config_Type {
47#define MAX_RX_URB 16 29#define MAX_RX_URB 16
48 30
49#define R8180_MAX_RETRY 255 31#define R8180_MAX_RETRY 255
50//#define MAX_RX_NORMAL_URB 3
51//#define MAX_RX_COMMAND_URB 2
52#define RX_URB_SIZE 9100
53
54#define BB_ANTATTEN_CHAN14 0x0c
55#define BB_ANTENNA_B 0x40
56 32
57#define BB_HOST_BANG BIT(30) 33#define RX_URB_SIZE 9100
58#define BB_HOST_BANG_EN BIT(2)
59#define BB_HOST_BANG_CLK BIT(1)
60#define BB_HOST_BANG_RW BIT(3)
61#define BB_HOST_BANG_DATA 1
62 34
63//#if (RTL819X_FPGA_VER & RTL819X_FPGA_VIVI_070920)
64#define AFR 0x010
65#define AFR_CardBEn BIT(0)
66#define AFR_CLKRUN_SEL BIT(1)
67#define AFR_FuncRegEn BIT(2)
68#define RTL8190_EEPROM_ID 0x8129 35#define RTL8190_EEPROM_ID 0x8129
69#define EEPROM_VID 0x02 36#define EEPROM_VID 0x02
70#define EEPROM_PID 0x04 37#define EEPROM_PID 0x04
71#define EEPROM_NODE_ADDRESS_BYTE_0 0x0C 38#define EEPROM_NODE_ADDRESS_BYTE_0 0x0C
72 39
73#define EEPROM_TxPowerDiff 0x1F 40#define EEPROM_TX_POWER_DIFF 0x1F
74#define EEPROM_ThermalMeter 0x20 41#define EEPROM_THERMAL_METER 0x20
75#define EEPROM_PwDiff 0x21 //0x21 42#define EEPROM_PW_DIFF 0x21 //0x21
76#define EEPROM_CrystalCap 0x22 //0x22 43#define EEPROM_CRYSTAL_CAP 0x22 //0x22
77 44
78#define EEPROM_TxPwIndex_CCK 0x23 //0x23 45#define EEPROM_TX_PW_INDEX_CCK 0x23 //0x23
79#define EEPROM_TxPwIndex_OFDM_24G 0x24 //0x24~0x26 46#define EEPROM_TX_PW_INDEX_OFDM_24G 0x24 //0x24~0x26
80#define EEPROM_TxPwIndex_CCK_V1 0x29 //0x29~0x2B 47#define EEPROM_TX_PW_INDEX_CCK_V1 0x29 //0x29~0x2B
81#define EEPROM_TxPwIndex_OFDM_24G_V1 0x2C //0x2C~0x2E 48#define EEPROM_TX_PW_INDEX_OFDM_24G_V1 0x2C //0x2C~0x2E
82#define EEPROM_TxPwIndex_Ver 0x27 //0x27 49#define EEPROM_TX_PW_INDEX_VER 0x27 //0x27
83 50
84#define EEPROM_Default_TxPowerDiff 0x0 51#define EEPROM_DEFAULT_THERNAL_METER 0x7
85#define EEPROM_Default_ThermalMeter 0x7 52#define EEPROM_DEFAULT_PW_DIFF 0x4
86#define EEPROM_Default_PwDiff 0x4 53#define EEPROM_DEFAULT_CRYSTAL_CAP 0x5
87#define EEPROM_Default_CrystalCap 0x5 54#define EEPROM_DEFAULT_TX_POWER 0x1010
88#define EEPROM_Default_TxPower 0x1010 55#define EEPROM_CUSTOMER_ID 0x7B //0x7B:CustomerID
89#define EEPROM_Customer_ID 0x7B //0x7B:CustomerID 56#define EEPROM_CHANNEL_PLAN 0x16 //0x7C
90#define EEPROM_ChannelPlan 0x16 //0x7C
91#define EEPROM_IC_VER 0x7d //0x7D
92#define EEPROM_CRC 0x7e //0x7E~0x7F
93 57
94#define EEPROM_CID_DEFAULT 0x0
95#define EEPROM_CID_CAMEO 0x1
96#define EEPROM_CID_RUNTOP 0x2 58#define EEPROM_CID_RUNTOP 0x2
97#define EEPROM_CID_Senao 0x3
98#define EEPROM_CID_TOSHIBA 0x4 // Toshiba setting, Merge by Jacken, 2008/01/31
99#define EEPROM_CID_NetCore 0x5
100#define EEPROM_CID_Nettronix 0x6
101#define EEPROM_CID_Pronet 0x7
102#define EEPROM_CID_DLINK 0x8 59#define EEPROM_CID_DLINK 0x8
103 60
104#define AC_PARAM_TXOP_LIMIT_OFFSET 16 61#define AC_PARAM_TXOP_LIMIT_OFFSET 16
@@ -108,18 +65,16 @@ typedef enum _BaseBand_Config_Type {
108 65
109//#endif 66//#endif
110enum _RTL8192Usb_HW { 67enum _RTL8192Usb_HW {
68 MAC0 = 0x000,
69 MAC4 = 0x004,
111 70
112 PCIF = 0x009, // PCI Function Register 0x0009h~0x000bh
113#define BB_GLOBAL_RESET_BIT 0x1 71#define BB_GLOBAL_RESET_BIT 0x1
114 BB_GLOBAL_RESET = 0x020, // BasebandGlobal Reset Register 72 BB_GLOBAL_RESET = 0x020, // BasebandGlobal Reset Register
115 BSSIDR = 0x02E, // BSSID Register 73 BSSIDR = 0x02E, // BSSID Register
116 CMDR = 0x037, // Command register 74 CMDR = 0x037, // Command register
117#define CR_RST 0x10
118#define CR_RE 0x08 75#define CR_RE 0x08
119#define CR_TE 0x04 76#define CR_TE 0x04
120#define CR_MulRW 0x01
121 SIFS = 0x03E, // SIFS register 77 SIFS = 0x03E, // SIFS register
122 TCR = 0x040, // Transmit Configuration Register
123 78
124#define TCR_MXDMA_2048 7 79#define TCR_MXDMA_2048 7
125#define TCR_LRL_OFFSET 0 80#define TCR_LRL_OFFSET 0
@@ -132,26 +87,16 @@ enum _RTL8192Usb_HW {
132 BIT(22) | BIT(23)) 87 BIT(22) | BIT(23))
133#define RX_FIFO_THRESHOLD_MASK (BIT(13) | BIT(14) | BIT(15)) 88#define RX_FIFO_THRESHOLD_MASK (BIT(13) | BIT(14) | BIT(15))
134#define RX_FIFO_THRESHOLD_SHIFT 13 89#define RX_FIFO_THRESHOLD_SHIFT 13
135#define RX_FIFO_THRESHOLD_128 3
136#define RX_FIFO_THRESHOLD_256 4
137#define RX_FIFO_THRESHOLD_512 5
138#define RX_FIFO_THRESHOLD_1024 6
139#define RX_FIFO_THRESHOLD_NONE 7 90#define RX_FIFO_THRESHOLD_NONE 7
140#define MAX_RX_DMA_MASK (BIT(8) | BIT(9) | BIT(10)) 91#define MAX_RX_DMA_MASK (BIT(8) | BIT(9) | BIT(10))
141#define RCR_MXDMA_OFFSET 8 92#define RCR_MXDMA_OFFSET 8
142#define RCR_FIFO_OFFSET 13 93#define RCR_FIFO_OFFSET 13
143#define RCR_ONLYERLPKT BIT(31) // Early Receiving based on Packet Size. 94#define RCR_ONLYERLPKT BIT(31) // Early Receiving based on Packet Size.
144#define RCR_ENCS2 BIT(30) // Enable Carrier Sense Detection Method 2
145#define RCR_ENCS1 BIT(29) // Enable Carrier Sense Detection Method 1
146#define RCR_ENMBID BIT(27) // Enable Multiple BssId.
147#define RCR_ACKTXBW (BIT(24) | BIT(25)) // TXBW Setting of ACK frames
148#define RCR_CBSSID BIT(23) // Accept BSSID match packet 95#define RCR_CBSSID BIT(23) // Accept BSSID match packet
149#define RCR_APWRMGT BIT(22) // Accept power management packet 96#define RCR_APWRMGT BIT(22) // Accept power management packet
150#define RCR_ADD3 BIT(21) // Accept address 3 match packet
151#define RCR_AMF BIT(20) // Accept management type frame 97#define RCR_AMF BIT(20) // Accept management type frame
152#define RCR_ACF BIT(19) // Accept control type frame 98#define RCR_ACF BIT(19) // Accept control type frame
153#define RCR_ADF BIT(18) // Accept data type frame 99#define RCR_ADF BIT(18) // Accept data type frame
154#define RCR_RXFTH BIT(13) // Rx FIFO Threshold
155#define RCR_AICV BIT(12) // Accept ICV error packet 100#define RCR_AICV BIT(12) // Accept ICV error packet
156#define RCR_ACRC32 BIT(5) // Accept CRC32 error packet 101#define RCR_ACRC32 BIT(5) // Accept CRC32 error packet
157#define RCR_AB BIT(3) // Accept broadcast packet 102#define RCR_AB BIT(3) // Accept broadcast packet
@@ -160,14 +105,10 @@ enum _RTL8192Usb_HW {
160#define RCR_AAP BIT(0) // Accept all unicast packet 105#define RCR_AAP BIT(0) // Accept all unicast packet
161 SLOT_TIME = 0x049, // Slot Time Register 106 SLOT_TIME = 0x049, // Slot Time Register
162 ACK_TIMEOUT = 0x04c, // Ack Timeout Register 107 ACK_TIMEOUT = 0x04c, // Ack Timeout Register
163 PIFS_TIME = 0x04d, // PIFS time
164 USTIME = 0x04e, // Microsecond Tuning Register, Sets the microsecond time unit used by MAC clock.
165 EDCAPARA_BE = 0x050, // EDCA Parameter of AC BE 108 EDCAPARA_BE = 0x050, // EDCA Parameter of AC BE
166 EDCAPARA_BK = 0x054, // EDCA Parameter of AC BK 109 EDCAPARA_BK = 0x054, // EDCA Parameter of AC BK
167 EDCAPARA_VO = 0x058, // EDCA Parameter of AC VO 110 EDCAPARA_VO = 0x058, // EDCA Parameter of AC VO
168 EDCAPARA_VI = 0x05C, // EDCA Parameter of AC VI 111 EDCAPARA_VI = 0x05C, // EDCA Parameter of AC VI
169 RFPC = 0x05F, // Rx FIFO Packet Count
170 CWRR = 0x060, // Contention Window Report Register
171 BCN_TCFG = 0x062, // Beacon Time Configuration 112 BCN_TCFG = 0x062, // Beacon Time Configuration
172#define BCN_TCFG_CW_SHIFT 8 113#define BCN_TCFG_CW_SHIFT 8
173#define BCN_TCFG_IFS 0 114#define BCN_TCFG_IFS 0
@@ -178,7 +119,6 @@ enum _RTL8192Usb_HW {
178 BCN_ERR_THRESH = 0x078, // Beacon Error Threshold 119 BCN_ERR_THRESH = 0x078, // Beacon Error Threshold
179 RWCAM = 0x0A0, //IN 8190 Data Sheet is called CAMcmd 120 RWCAM = 0x0A0, //IN 8190 Data Sheet is called CAMcmd
180 WCAMI = 0x0A4, // Software write CAM input content 121 WCAMI = 0x0A4, // Software write CAM input content
181 RCAMO = 0x0A8, // Software read/write CAM config
182 SECR = 0x0B0, //Security Configuration Register 122 SECR = 0x0B0, //Security Configuration Register
183#define SCR_TxUseDK BIT(0) //Force Tx Use Default Key 123#define SCR_TxUseDK BIT(0) //Force Tx Use Default Key
184#define SCR_RxUseDK BIT(1) //Force Rx Use Default Key 124#define SCR_RxUseDK BIT(1) //Force Rx Use Default Key
@@ -186,21 +126,6 @@ enum _RTL8192Usb_HW {
186#define SCR_RxDecEnable BIT(3) //Enable Rx Decryption 126#define SCR_RxDecEnable BIT(3) //Enable Rx Decryption
187#define SCR_SKByA2 BIT(4) //Search kEY BY A2 127#define SCR_SKByA2 BIT(4) //Search kEY BY A2
188#define SCR_NoSKMC BIT(5) //No Key Search for Multicast 128#define SCR_NoSKMC BIT(5) //No Key Search for Multicast
189#define SCR_UseDK 0x01
190#define SCR_TxSecEnable 0x02
191#define SCR_RxSecEnable 0x04
192 TPPoll = 0x0fd, // Transmit priority polling register
193 PSR = 0x0ff, // Page Select Register
194#define CPU_CCK_LOOPBACK 0x00030000
195#define CPU_GEN_SYSTEM_RESET 0x00000001
196#define CPU_GEN_FIRMWARE_RESET 0x00000008
197#define CPU_GEN_BOOT_RDY 0x00000010
198#define CPU_GEN_FIRM_RDY 0x00000020
199#define CPU_GEN_PUT_CODE_OK 0x00000080
200#define CPU_GEN_BB_RST 0x00000100
201#define CPU_GEN_PWR_STB_CPU 0x00000004
202#define CPU_GEN_NO_LOOPBACK_MSK 0xFFF8FFFF // Set bit18,17,16 to 0. Set bit19
203#define CPU_GEN_NO_LOOPBACK_SET 0x00080000 // Set BIT19 to 1
204 129
205//---------------------------------------------------------------------------- 130//----------------------------------------------------------------------------
206// 8190 CPU General Register (offset 0x100, 4 byte) 131// 8190 CPU General Register (offset 0x100, 4 byte)
@@ -216,72 +141,20 @@ enum _RTL8192Usb_HW {
216#define CPU_GEN_NO_LOOPBACK_MSK 0xFFF8FFFF // Set bit18,17,16 to 0. Set bit19 141#define CPU_GEN_NO_LOOPBACK_MSK 0xFFF8FFFF // Set bit18,17,16 to 0. Set bit19
217#define CPU_GEN_NO_LOOPBACK_SET 0x00080000 // Set BIT19 to 1 142#define CPU_GEN_NO_LOOPBACK_SET 0x00080000 // Set BIT19 to 1
218 CPU_GEN = 0x100, // CPU Reset Register 143 CPU_GEN = 0x100, // CPU Reset Register
219 LED1Cfg = 0x154,// LED1 Configuration Register
220 LED0Cfg = 0x155,// LED0 Configuration Register
221 144
222 AcmAvg = 0x170, // ACM Average Period Register
223 AcmHwCtrl = 0x171, // ACM Hardware Control Register 145 AcmHwCtrl = 0x171, // ACM Hardware Control Register
224//---------------------------------------------------------------------------- 146//----------------------------------------------------------------------------
225//// 147////
226//// 8190 AcmHwCtrl bits (offset 0x171, 1 byte) 148//// 8190 AcmHwCtrl bits (offset 0x171, 1 byte)
227////---------------------------------------------------------------------------- 149////----------------------------------------------------------------------------
228// 150//
229#define AcmHw_HwEn BIT(0)
230#define AcmHw_BeqEn BIT(1) 151#define AcmHw_BeqEn BIT(1)
231#define AcmHw_ViqEn BIT(2)
232#define AcmHw_VoqEn BIT(3)
233#define AcmHw_BeqStatus BIT(4)
234#define AcmHw_ViqStatus BIT(5)
235#define AcmHw_VoqStatus BIT(6)
236 152
237 AcmFwCtrl = 0x172, // ACM Firmware Control Register
238 AES_11N_FIX = 0x173,
239 VOAdmTime = 0x174, // VO Queue Admitted Time Register
240 VIAdmTime = 0x178, // VI Queue Admitted Time Register
241 BEAdmTime = 0x17C, // BE Queue Admitted Time Register
242 RQPN1 = 0x180, // Reserved Queue Page Number , Vo Vi, Be, Bk 153 RQPN1 = 0x180, // Reserved Queue Page Number , Vo Vi, Be, Bk
243 RQPN2 = 0x184, // Reserved Queue Page Number, HCCA, Cmd, Mgnt, High 154 RQPN2 = 0x184, // Reserved Queue Page Number, HCCA, Cmd, Mgnt, High
244 RQPN3 = 0x188, // Reserved Queue Page Number, Bcn, Public, 155 RQPN3 = 0x188, // Reserved Queue Page Number, Bcn, Public,
245// QPRR = 0x1E0, // Queue Page Report per TID
246 QPNR = 0x1D0, //0x1F0, // Queue Packet Number report per TID 156 QPNR = 0x1D0, //0x1F0, // Queue Packet Number report per TID
247 BQDA = 0x200, // Beacon Queue Descriptor Address
248 HQDA = 0x204, // High Priority Queue Descriptor Address
249 CQDA = 0x208, // Command Queue Descriptor Address
250 MQDA = 0x20C, // Management Queue Descriptor Address
251 HCCAQDA = 0x210, // HCCA Queue Descriptor Address
252 VOQDA = 0x214, // VO Queue Descriptor Address
253 VIQDA = 0x218, // VI Queue Descriptor Address
254 BEQDA = 0x21C, // BE Queue Descriptor Address
255 BKQDA = 0x220, // BK Queue Descriptor Address
256 RCQDA = 0x224, // Receive command Queue Descriptor Address
257 RDQDA = 0x228, // Receive Queue Descriptor Start Address
258
259 MAR0 = 0x240, // Multicast filter.
260 MAR4 = 0x244,
261
262 CCX_PERIOD = 0x250, // CCX Measurement Period Register, in unit of TU.
263 CLM_RESULT = 0x251, // CCA Busy fraction register.
264 NHM_PERIOD = 0x252, // NHM Measurement Period register, in unit of TU.
265 157
266 NHM_THRESHOLD0 = 0x253, // Noise Histogram Meashorement0.
267 NHM_THRESHOLD1 = 0x254, // Noise Histogram Meashorement1.
268 NHM_THRESHOLD2 = 0x255, // Noise Histogram Meashorement2.
269 NHM_THRESHOLD3 = 0x256, // Noise Histogram Meashorement3.
270 NHM_THRESHOLD4 = 0x257, // Noise Histogram Meashorement4.
271 NHM_THRESHOLD5 = 0x258, // Noise Histogram Meashorement5.
272 NHM_THRESHOLD6 = 0x259, // Noise Histogram Meashorement6
273
274 MCTRL = 0x25A, // Measurement Control
275
276 NHM_RPI_COUNTER0 = 0x264, // Noise Histogram RPI counter0, the fraction of signal strength < NHM_THRESHOLD0.
277 NHM_RPI_COUNTER1 = 0x265, // Noise Histogram RPI counter1, the fraction of signal strength in (NHM_THRESHOLD0, NHM_THRESHOLD1].
278 NHM_RPI_COUNTER2 = 0x266, // Noise Histogram RPI counter2, the fraction of signal strength in (NHM_THRESHOLD1, NHM_THRESHOLD2].
279 NHM_RPI_COUNTER3 = 0x267, // Noise Histogram RPI counter3, the fraction of signal strength in (NHM_THRESHOLD2, NHM_THRESHOLD3].
280 NHM_RPI_COUNTER4 = 0x268, // Noise Histogram RPI counter4, the fraction of signal strength in (NHM_THRESHOLD3, NHM_THRESHOLD4].
281 NHM_RPI_COUNTER5 = 0x269, // Noise Histogram RPI counter5, the fraction of signal strength in (NHM_THRESHOLD4, NHM_THRESHOLD5].
282 NHM_RPI_COUNTER6 = 0x26A, // Noise Histogram RPI counter6, the fraction of signal strength in (NHM_THRESHOLD5, NHM_THRESHOLD6].
283 NHM_RPI_COUNTER7 = 0x26B, // Noise Histogram RPI counter7, the fraction of signal strength in (NHM_THRESHOLD6, NHM_THRESHOLD7].
284#define BW_OPMODE_11J BIT(0)
285#define BW_OPMODE_5G BIT(1) 158#define BW_OPMODE_5G BIT(1)
286#define BW_OPMODE_20MHZ BIT(2) 159#define BW_OPMODE_20MHZ BIT(2)
287 BW_OPMODE = 0x300, // Bandwidth operation mode 160 BW_OPMODE = 0x300, // Bandwidth operation mode
@@ -292,18 +165,10 @@ enum _RTL8192Usb_HW {
292#define MSR_LINK_SHIFT 0 165#define MSR_LINK_SHIFT 0
293#define MSR_LINK_ADHOC 1 166#define MSR_LINK_ADHOC 1
294#define MSR_LINK_MASTER 3 167#define MSR_LINK_MASTER 3
295#define MSR_LINK_ENEDCA BIT(4)
296 RETRY_LIMIT = 0x304, // Retry Limit [15:8]-short, [7:0]-long 168 RETRY_LIMIT = 0x304, // Retry Limit [15:8]-short, [7:0]-long
297#define RETRY_LIMIT_SHORT_SHIFT 8 169#define RETRY_LIMIT_SHORT_SHIFT 8
298#define RETRY_LIMIT_LONG_SHIFT 0 170#define RETRY_LIMIT_LONG_SHIFT 0
299 TSFR = 0x308,
300 RRSR = 0x310, // Response Rate Set 171 RRSR = 0x310, // Response Rate Set
301#define RRSR_RSC_OFFSET 21
302#define RRSR_SHORT_OFFSET 23
303#define RRSR_RSC_DUPLICATE 0x600000
304#define RRSR_RSC_LOWSUBCHNL 0x400000
305#define RRSR_RSC_UPSUBCHANL 0x200000
306#define RRSR_SHORT 0x800000
307#define RRSR_1M BIT(0) 172#define RRSR_1M BIT(0)
308#define RRSR_2M BIT(1) 173#define RRSR_2M BIT(1)
309#define RRSR_5_5M BIT(2) 174#define RRSR_5_5M BIT(2)
@@ -316,17 +181,9 @@ enum _RTL8192Usb_HW {
316#define RRSR_36M BIT(9) 181#define RRSR_36M BIT(9)
317#define RRSR_48M BIT(10) 182#define RRSR_48M BIT(10)
318#define RRSR_54M BIT(11) 183#define RRSR_54M BIT(11)
319#define RRSR_MCS0 BIT(12)
320#define RRSR_MCS1 BIT(13)
321#define RRSR_MCS2 BIT(14)
322#define RRSR_MCS3 BIT(15)
323#define RRSR_MCS4 BIT(16)
324#define RRSR_MCS5 BIT(17)
325#define RRSR_MCS6 BIT(18)
326#define RRSR_MCS7 BIT(19)
327#define BRSR_AckShortPmb BIT(23) // CCK ACK: use Short Preamble or not. 184#define BRSR_AckShortPmb BIT(23) // CCK ACK: use Short Preamble or not.
328 RATR0 = 0x320, // Rate Adaptive Table register1
329 UFWP = 0x318, 185 UFWP = 0x318,
186 RATR0 = 0x320, // Rate Adaptive Table register1
330 DRIVER_RSSI = 0x32c, // Driver tell Firmware current RSSI 187 DRIVER_RSSI = 0x32c, // Driver tell Firmware current RSSI
331//---------------------------------------------------------------------------- 188//----------------------------------------------------------------------------
332// 8190 Rate Adaptive Table Register (offset 0x320, 4 byte) 189// 8190 Rate Adaptive Table Register (offset 0x320, 4 byte)
@@ -372,41 +229,18 @@ enum _RTL8192Usb_HW {
372#define RATE_ALL_OFDM_2SS RATR_MCS8|RATR_MCS9 |RATR_MCS10|RATR_MCS11| \ 229#define RATE_ALL_OFDM_2SS RATR_MCS8|RATR_MCS9 |RATR_MCS10|RATR_MCS11| \
373 RATR_MCS12|RATR_MCS13|RATR_MCS14|RATR_MCS15 230 RATR_MCS12|RATR_MCS13|RATR_MCS14|RATR_MCS15
374 231
375 MCS_TXAGC = 0x340, // MCS AGC
376 CCK_TXAGC = 0x348, // CCK AGC
377// ISR = 0x350, // Interrupt Status Register
378// IMR = 0x354, // Interrupt Mask Register
379// IMR_POLL = 0x360,
380 MacBlkCtrl = 0x403, // Mac block on/off control register
381
382 EPROM_CMD = 0xfe58, 232 EPROM_CMD = 0xfe58,
383#define Cmd9346CR_9356SEL BIT(4) 233#define Cmd9346CR_9356SEL BIT(4)
384#define EPROM_CMD_RESERVED_MASK BIT(5)
385#define EPROM_CMD_OPERATING_MODE_SHIFT 6 234#define EPROM_CMD_OPERATING_MODE_SHIFT 6
386#define EPROM_CMD_OPERATING_MODE_MASK (BIT(7) | BIT(6))
387#define EPROM_CMD_CONFIG 0x3
388#define EPROM_CMD_NORMAL 0 235#define EPROM_CMD_NORMAL 0
389#define EPROM_CMD_LOAD 1
390#define EPROM_CMD_PROGRAM 2 236#define EPROM_CMD_PROGRAM 2
391#define EPROM_CS_BIT BIT(3) 237#define EPROM_CS_BIT BIT(3)
392#define EPROM_CK_BIT BIT(2) 238#define EPROM_CK_BIT BIT(2)
393#define EPROM_W_BIT BIT(1) 239#define EPROM_W_BIT BIT(1)
394#define EPROM_R_BIT BIT(0) 240#define EPROM_R_BIT BIT(0)
395
396 MAC0 = 0x000,
397 MAC1 = 0x001,
398 MAC2 = 0x002,
399 MAC3 = 0x003,
400 MAC4 = 0x004,
401 MAC5 = 0x005,
402
403}; 241};
404//---------------------------------------------------------------------------- 242//----------------------------------------------------------------------------
405// 818xB AnaParm & AnaParm2 Register 243// 818xB AnaParm & AnaParm2 Register
406//---------------------------------------------------------------------------- 244//----------------------------------------------------------------------------
407//#define ANAPARM_ASIC_ON 0x45090658
408//#define ANAPARM2_ASIC_ON 0x727f3f52
409#define GPI 0x108 245#define GPI 0x108
410#define GPO 0x109
411#define GPE 0x10a
412#endif 246#endif
diff --git a/drivers/staging/rtl8192u/r819xU_firmware.c b/drivers/staging/rtl8192u/r819xU_firmware.c
index 9c7e19aedff1..c3ea906f3af3 100644
--- a/drivers/staging/rtl8192u/r819xU_firmware.c
+++ b/drivers/staging/rtl8192u/r819xU_firmware.c
@@ -208,8 +208,8 @@ bool init_firmware(struct net_device *dev)
208 u32 file_length = 0; 208 u32 file_length = 0;
209 u8 *mapped_file = NULL; 209 u8 *mapped_file = NULL;
210 u32 init_step = 0; 210 u32 init_step = 0;
211 opt_rst_type_e rst_opt = OPT_SYSTEM_RESET; 211 enum opt_rst_type_e rst_opt = OPT_SYSTEM_RESET;
212 firmware_init_step_e starting_state = FW_INIT_STEP0_BOOT; 212 enum firmware_init_step_e starting_state = FW_INIT_STEP0_BOOT;
213 213
214 rt_firmware *pfirmware = priv->pFirmware; 214 rt_firmware *pfirmware = priv->pFirmware;
215 const struct firmware *fw_entry; 215 const struct firmware *fw_entry;
diff --git a/drivers/staging/rtl8192u/r819xU_firmware.h b/drivers/staging/rtl8192u/r819xU_firmware.h
index cccd1c82ffe0..b84344c1e62b 100644
--- a/drivers/staging/rtl8192u/r819xU_firmware.h
+++ b/drivers/staging/rtl8192u/r819xU_firmware.h
@@ -2,19 +2,18 @@
2#ifndef __INC_FIRMWARE_H 2#ifndef __INC_FIRMWARE_H
3#define __INC_FIRMWARE_H 3#define __INC_FIRMWARE_H
4 4
5#define RTL8190_CPU_START_OFFSET 0x80
6#define GET_COMMAND_PACKET_FRAG_THRESHOLD(v) \ 5#define GET_COMMAND_PACKET_FRAG_THRESHOLD(v) \
7 (4*(v/4) - 8 - USB_HWDESC_HEADER_LEN) 6 (4 * ((v) / 4) - 8 - USB_HWDESC_HEADER_LEN)
8 7
9typedef enum _firmware_init_step { 8enum firmware_init_step_e {
10 FW_INIT_STEP0_BOOT = 0, 9 FW_INIT_STEP0_BOOT = 0,
11 FW_INIT_STEP1_MAIN = 1, 10 FW_INIT_STEP1_MAIN = 1,
12 FW_INIT_STEP2_DATA = 2, 11 FW_INIT_STEP2_DATA = 2,
13} firmware_init_step_e; 12};
14 13
15typedef enum _opt_rst_type { 14enum opt_rst_type_e {
16 OPT_SYSTEM_RESET = 0, 15 OPT_SYSTEM_RESET = 0,
17 OPT_FIRMWARE_RESET = 1, 16 OPT_FIRMWARE_RESET = 1,
18} opt_rst_type_e; 17};
19 18
20#endif 19#endif
diff --git a/drivers/staging/rtl8192u/r819xU_phy.c b/drivers/staging/rtl8192u/r819xU_phy.c
index 7ee10d49894b..5f04afe53d69 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.c
+++ b/drivers/staging/rtl8192u/r819xU_phy.c
@@ -511,7 +511,8 @@ void rtl8192_phy_configmac(struct net_device *dev)
511 * notice: BB parameters may change all the time, so please make 511 * notice: BB parameters may change all the time, so please make
512 * sure it has been synced with the newest. 512 * sure it has been synced with the newest.
513 *****************************************************************************/ 513 *****************************************************************************/
514void rtl8192_phyConfigBB(struct net_device *dev, u8 ConfigType) 514static void rtl8192_phyConfigBB(struct net_device *dev,
515 enum baseband_config_type ConfigType)
515{ 516{
516 u32 i; 517 u32 i;
517 518
@@ -525,7 +526,7 @@ void rtl8192_phyConfigBB(struct net_device *dev, u8 ConfigType)
525 Rtl8190AGCTAB_Array_Table = Rtl819XAGCTAB_ArrayDTM; 526 Rtl8190AGCTAB_Array_Table = Rtl819XAGCTAB_ArrayDTM;
526 } 527 }
527#endif 528#endif
528 if (ConfigType == BaseBand_Config_PHY_REG) { 529 if (ConfigType == BASEBAND_CONFIG_PHY_REG) {
529 for (i = 0; i < PHY_REG_1T2RArrayLength; i += 2) { 530 for (i = 0; i < PHY_REG_1T2RArrayLength; i += 2) {
530 rtl8192_setBBreg(dev, Rtl8192UsbPHY_REG_1T2RArray[i], 531 rtl8192_setBBreg(dev, Rtl8192UsbPHY_REG_1T2RArray[i],
531 bMaskDWord, 532 bMaskDWord,
@@ -535,7 +536,7 @@ void rtl8192_phyConfigBB(struct net_device *dev, u8 ConfigType)
535 i, Rtl8192UsbPHY_REG_1T2RArray[i], 536 i, Rtl8192UsbPHY_REG_1T2RArray[i],
536 Rtl8192UsbPHY_REG_1T2RArray[i+1]); 537 Rtl8192UsbPHY_REG_1T2RArray[i+1]);
537 } 538 }
538 } else if (ConfigType == BaseBand_Config_AGC_TAB) { 539 } else if (ConfigType == BASEBAND_CONFIG_AGC_TAB) {
539 for (i = 0; i < AGCTAB_ArrayLength; i += 2) { 540 for (i = 0; i < AGCTAB_ArrayLength; i += 2) {
540 rtl8192_setBBreg(dev, Rtl8192UsbAGCTAB_Array[i], 541 rtl8192_setBBreg(dev, Rtl8192UsbAGCTAB_Array[i],
541 bMaskDWord, Rtl8192UsbAGCTAB_Array[i+1]); 542 bMaskDWord, Rtl8192UsbAGCTAB_Array[i+1]);
@@ -793,7 +794,7 @@ static void rtl8192_BB_Config_ParaFile(struct net_device *dev)
793 (enum rf90_radio_path_e)0); 794 (enum rf90_radio_path_e)0);
794 if (status != 0) { 795 if (status != 0) {
795 RT_TRACE((COMP_ERR | COMP_PHY), 796 RT_TRACE((COMP_ERR | COMP_PHY),
796 "PHY_RF8256_Config(): Check PHY%d Fail!!\n", 797 "phy_rf8256_config(): Check PHY%d Fail!!\n",
797 eCheckItem-1); 798 eCheckItem-1);
798 return; 799 return;
799 } 800 }
@@ -802,7 +803,7 @@ static void rtl8192_BB_Config_ParaFile(struct net_device *dev)
802 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bCCKEn|bOFDMEn, 0x0); 803 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bCCKEn|bOFDMEn, 0x0);
803 /* ----BB Register Initilazation---- */ 804 /* ----BB Register Initilazation---- */
804 /* ==m==>Set PHY REG From Header<==m== */ 805 /* ==m==>Set PHY REG From Header<==m== */
805 rtl8192_phyConfigBB(dev, BaseBand_Config_PHY_REG); 806 rtl8192_phyConfigBB(dev, BASEBAND_CONFIG_PHY_REG);
806 807
807 /* ----Set BB reset de-Active---- */ 808 /* ----Set BB reset de-Active---- */
808 read_nic_dword(dev, CPU_GEN, &reg_u32); 809 read_nic_dword(dev, CPU_GEN, &reg_u32);
@@ -810,11 +811,11 @@ static void rtl8192_BB_Config_ParaFile(struct net_device *dev)
810 811
811 /* ----BB AGC table Initialization---- */ 812 /* ----BB AGC table Initialization---- */
812 /* ==m==>Set PHY REG From Header<==m== */ 813 /* ==m==>Set PHY REG From Header<==m== */
813 rtl8192_phyConfigBB(dev, BaseBand_Config_AGC_TAB); 814 rtl8192_phyConfigBB(dev, BASEBAND_CONFIG_AGC_TAB);
814 815
815 /* ----Enable XSTAL ---- */ 816 /* ----Enable XSTAL ---- */
816 write_nic_byte_E(dev, 0x5e, 0x00); 817 write_nic_byte_E(dev, 0x5e, 0x00);
817 if (priv->card_8192_version == (u8)VERSION_819xU_A) { 818 if (priv->card_8192_version == VERSION_819XU_A) {
818 /* Antenna gain offset from B/C/D to A */ 819 /* Antenna gain offset from B/C/D to A */
819 reg_u32 = priv->AntennaTxPwDiff[1]<<4 | 820 reg_u32 = priv->AntennaTxPwDiff[1]<<4 |
820 priv->AntennaTxPwDiff[0]; 821 priv->AntennaTxPwDiff[0];
@@ -917,8 +918,8 @@ void rtl8192_phy_setTxPower(struct net_device *dev, u8 channel)
917 switch (priv->rf_chip) { 918 switch (priv->rf_chip) {
918 case RF_8256: 919 case RF_8256:
919 /* need further implement */ 920 /* need further implement */
920 PHY_SetRF8256CCKTxPower(dev, powerlevel); 921 phy_set_rf8256_cck_tx_power(dev, powerlevel);
921 PHY_SetRF8256OFDMTxPower(dev, powerlevelOFDM24G); 922 phy_set_rf8256_ofdm_tx_power(dev, powerlevelOFDM24G);
922 break; 923 break;
923 default: 924 default:
924 RT_TRACE((COMP_PHY|COMP_ERR), 925 RT_TRACE((COMP_PHY|COMP_ERR),
@@ -940,7 +941,7 @@ void rtl8192_phy_RFConfig(struct net_device *dev)
940 941
941 switch (priv->rf_chip) { 942 switch (priv->rf_chip) {
942 case RF_8256: 943 case RF_8256:
943 PHY_RF8256_Config(dev); 944 phy_rf8256_config(dev);
944 break; 945 break;
945 default: 946 default:
946 RT_TRACE(COMP_ERR, "error chip id\n"); 947 RT_TRACE(COMP_ERR, "error chip id\n");
@@ -1065,8 +1066,8 @@ static void rtl8192_SetTxPowerLevel(struct net_device *dev, u8 channel)
1065 break; 1066 break;
1066 1067
1067 case RF_8256: 1068 case RF_8256:
1068 PHY_SetRF8256CCKTxPower(dev, powerlevel); 1069 phy_set_rf8256_cck_tx_power(dev, powerlevel);
1069 PHY_SetRF8256OFDMTxPower(dev, powerlevelOFDM24G); 1070 phy_set_rf8256_ofdm_tx_power(dev, powerlevelOFDM24G);
1070 break; 1071 break;
1071 1072
1072 case RF_8258: 1073 case RF_8258:
@@ -1271,7 +1272,7 @@ static u8 rtl8192_phy_SwChnlStepByStep(struct net_device *dev, u8 channel,
1271 1272
1272 RT_TRACE(COMP_CH, "%s() stage: %d, step: %d, channel: %d\n", 1273 RT_TRACE(COMP_CH, "%s() stage: %d, step: %d, channel: %d\n",
1273 __func__, *stage, *step, channel); 1274 __func__, *stage, *step, channel);
1274 if (!IsLegalChannel(priv->ieee80211, channel)) { 1275 if (!is_legal_channel(priv->ieee80211, channel)) {
1275 RT_TRACE(COMP_ERR, "set to illegal channel: %d\n", channel); 1276 RT_TRACE(COMP_ERR, "set to illegal channel: %d\n", channel);
1276 /* return true to tell upper caller function this channel 1277 /* return true to tell upper caller function this channel
1277 * setting is finished! Or it will in while loop. 1278 * setting is finished! Or it will in while loop.
@@ -1367,7 +1368,7 @@ static u8 rtl8192_phy_SwChnlStepByStep(struct net_device *dev, u8 channel,
1367 1368
1368 switch (CurrentCmd->cmd_id) { 1369 switch (CurrentCmd->cmd_id) {
1369 case CMD_ID_SET_TX_PWR_LEVEL: 1370 case CMD_ID_SET_TX_PWR_LEVEL:
1370 if (priv->card_8192_version == (u8)VERSION_819xU_A) 1371 if (priv->card_8192_version == VERSION_819XU_A)
1371 /* consider it later! */ 1372 /* consider it later! */
1372 rtl8192_SetTxPowerLevel(dev, channel); 1373 rtl8192_SetTxPowerLevel(dev, channel);
1373 break; 1374 break;
@@ -1633,7 +1634,7 @@ void rtl8192_SetBWModeWorkItem(struct net_device *dev)
1633 break; 1634 break;
1634 1635
1635 case RF_8256: 1636 case RF_8256:
1636 PHY_SetRF8256Bandwidth(dev, priv->CurrentChannelBW); 1637 phy_set_rf8256_bandwidth(dev, priv->CurrentChannelBW);
1637 break; 1638 break;
1638 1639
1639 case RF_8258: 1640 case RF_8258:
diff --git a/drivers/staging/rtl8192u/r819xU_phy.h b/drivers/staging/rtl8192u/r819xU_phy.h
index c7ec3182857f..8c2933264407 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.h
+++ b/drivers/staging/rtl8192u/r819xU_phy.h
@@ -7,6 +7,11 @@
7#define MAX_RFDEPENDCMD_CNT 16 7#define MAX_RFDEPENDCMD_CNT 16
8#define MAX_POSTCMD_CNT 16 8#define MAX_POSTCMD_CNT 16
9 9
10enum baseband_config_type {
11 BASEBAND_CONFIG_PHY_REG = 0, //Radio Path A
12 BASEBAND_CONFIG_AGC_TAB = 1, //Radio Path B
13};
14
10enum switch_chan_cmd_id { 15enum switch_chan_cmd_id {
11 CMD_ID_END, 16 CMD_ID_END,
12 CMD_ID_SET_TX_PWR_LEVEL, 17 CMD_ID_SET_TX_PWR_LEVEL,
@@ -52,7 +57,6 @@ u32 rtl8192_phy_QueryRFReg(struct net_device *dev,
52 enum rf90_radio_path_e e_rfpath, 57 enum rf90_radio_path_e e_rfpath,
53 u32 reg_addr, u32 bitmask); 58 u32 reg_addr, u32 bitmask);
54void rtl8192_phy_configmac(struct net_device *dev); 59void rtl8192_phy_configmac(struct net_device *dev);
55void rtl8192_phyConfigBB(struct net_device *dev, u8 ConfigType);
56u8 rtl8192_phy_checkBBAndRF(struct net_device *dev, 60u8 rtl8192_phy_checkBBAndRF(struct net_device *dev,
57 enum hw90_block_e CheckBlock, 61 enum hw90_block_e CheckBlock,
58 enum rf90_radio_path_e e_rfpath); 62 enum rf90_radio_path_e e_rfpath);
diff --git a/drivers/staging/rtl8712/basic_types.h b/drivers/staging/rtl8712/basic_types.h
index f5c0231891b1..4ad7f35b1644 100644
--- a/drivers/staging/rtl8712/basic_types.h
+++ b/drivers/staging/rtl8712/basic_types.h
@@ -1,16 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
15 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
16 * 8 *
diff --git a/drivers/staging/rtl8712/drv_types.h b/drivers/staging/rtl8712/drv_types.h
index ede99e96984f..48d62fe6c8d4 100644
--- a/drivers/staging/rtl8712/drv_types.h
+++ b/drivers/staging/rtl8712/drv_types.h
@@ -1,16 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
15 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
16 * 8 *
diff --git a/drivers/staging/rtl8712/ethernet.h b/drivers/staging/rtl8712/ethernet.h
index 039da36fad3d..4b9b8a97a0bc 100644
--- a/drivers/staging/rtl8712/ethernet.h
+++ b/drivers/staging/rtl8712/ethernet.h
@@ -1,16 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
15 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
16 * 8 *
diff --git a/drivers/staging/rtl8712/hal_init.c b/drivers/staging/rtl8712/hal_init.c
index 2a3f0746ee2c..7cdd609cab6c 100644
--- a/drivers/staging/rtl8712/hal_init.c
+++ b/drivers/staging/rtl8712/hal_init.c
@@ -1,18 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/****************************************************************************** 2/******************************************************************************
2 * hal_init.c 3 * hal_init.c
3 * 4 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU 6 * Linux device driver for RTL8192SU
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * Modifications for inclusion into the Linux staging tree are 8 * Modifications for inclusion into the Linux staging tree are
17 * Copyright(c) 2010 Larry Finger. All rights reserved. 9 * Copyright(c) 2010 Larry Finger. All rights reserved.
18 * 10 *
diff --git a/drivers/staging/rtl8712/ieee80211.c b/drivers/staging/rtl8712/ieee80211.c
index 7a4c00e49a88..bb4f56a5fb01 100644
--- a/drivers/staging/rtl8712/ieee80211.c
+++ b/drivers/staging/rtl8712/ieee80211.c
@@ -1,18 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/****************************************************************************** 2/******************************************************************************
2 * ieee80211.c 3 * ieee80211.c
3 * 4 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU 6 * Linux device driver for RTL8192SU
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * Modifications for inclusion into the Linux staging tree are 8 * Modifications for inclusion into the Linux staging tree are
17 * Copyright(c) 2010 Larry Finger. All rights reserved. 9 * Copyright(c) 2010 Larry Finger. All rights reserved.
18 * 10 *
diff --git a/drivers/staging/rtl8712/ieee80211.h b/drivers/staging/rtl8712/ieee80211.h
index d605dfd02200..1470771daa62 100644
--- a/drivers/staging/rtl8712/ieee80211.h
+++ b/drivers/staging/rtl8712/ieee80211.h
@@ -1,19 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, see <http://www.gnu.org/licenses/>.
16 *
17 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
18 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
19 * 8 *
diff --git a/drivers/staging/rtl8712/mlme_linux.c b/drivers/staging/rtl8712/mlme_linux.c
index baaa52f04560..9d156efbc9ed 100644
--- a/drivers/staging/rtl8712/mlme_linux.c
+++ b/drivers/staging/rtl8712/mlme_linux.c
@@ -1,22 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/****************************************************************************** 2/******************************************************************************
2 * mlme_linux.c 3 * mlme_linux.c
3 * 4 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU 6 * Linux device driver for RTL8192SU
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * Modifications for inclusion into the Linux staging tree are 8 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved. 9 * Copyright(c) 2010 Larry Finger. All rights reserved.
22 * 10 *
diff --git a/drivers/staging/rtl8712/mlme_osdep.h b/drivers/staging/rtl8712/mlme_osdep.h
index a20fe81f921f..9eaf94f072ff 100644
--- a/drivers/staging/rtl8712/mlme_osdep.h
+++ b/drivers/staging/rtl8712/mlme_osdep.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/mp_custom_oid.h b/drivers/staging/rtl8712/mp_custom_oid.h
index 40510089b781..a9fac87fcabc 100644
--- a/drivers/staging/rtl8712/mp_custom_oid.h
+++ b/drivers/staging/rtl8712/mp_custom_oid.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/os_intfs.c b/drivers/staging/rtl8712/os_intfs.c
index ff4e451c10f9..2d3f38007299 100644
--- a/drivers/staging/rtl8712/os_intfs.c
+++ b/drivers/staging/rtl8712/os_intfs.c
@@ -1,18 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/****************************************************************************** 2/******************************************************************************
2 * os_intfs.c 3 * os_intfs.c
3 * 4 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU 6 * Linux device driver for RTL8192SU
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * Modifications for inclusion into the Linux staging tree are 8 * Modifications for inclusion into the Linux staging tree are
17 * Copyright(c) 2010 Larry Finger. All rights reserved. 9 * Copyright(c) 2010 Larry Finger. All rights reserved.
18 * 10 *
diff --git a/drivers/staging/rtl8712/osdep_intf.h b/drivers/staging/rtl8712/osdep_intf.h
index 5d37e1f951cf..2cc25db1a91d 100644
--- a/drivers/staging/rtl8712/osdep_intf.h
+++ b/drivers/staging/rtl8712/osdep_intf.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/osdep_service.h b/drivers/staging/rtl8712/osdep_service.h
index 5d33020554cd..e939c4a954b3 100644
--- a/drivers/staging/rtl8712/osdep_service.h
+++ b/drivers/staging/rtl8712/osdep_service.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/recv_linux.c b/drivers/staging/rtl8712/recv_linux.c
index 8cf4286f6318..4e20cbafa9fb 100644
--- a/drivers/staging/rtl8712/recv_linux.c
+++ b/drivers/staging/rtl8712/recv_linux.c
@@ -1,22 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/****************************************************************************** 2/******************************************************************************
2 * recv_linux.c 3 * recv_linux.c
3 * 4 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU 6 * Linux device driver for RTL8192SU
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * Modifications for inclusion into the Linux staging tree are 8 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved. 9 * Copyright(c) 2010 Larry Finger. All rights reserved.
22 * 10 *
diff --git a/drivers/staging/rtl8712/recv_osdep.h b/drivers/staging/rtl8712/recv_osdep.h
index 1f4986e940a3..dcd3b484c793 100644
--- a/drivers/staging/rtl8712/recv_osdep.h
+++ b/drivers/staging/rtl8712/recv_osdep.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl8712_bitdef.h b/drivers/staging/rtl8712/rtl8712_bitdef.h
index dee35fe2587a..a4a687dcc2e7 100644
--- a/drivers/staging/rtl8712/rtl8712_bitdef.h
+++ b/drivers/staging/rtl8712/rtl8712_bitdef.h
@@ -1,21 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 *
19 ******************************************************************************/ 6 ******************************************************************************/
20 7
21#ifndef __RTL8712_BITDEF_H__ 8#ifndef __RTL8712_BITDEF_H__
diff --git a/drivers/staging/rtl8712/rtl8712_cmd.c b/drivers/staging/rtl8712/rtl8712_cmd.c
index b1dfe9f46619..1920d02f7c9f 100644
--- a/drivers/staging/rtl8712/rtl8712_cmd.c
+++ b/drivers/staging/rtl8712/rtl8712_cmd.c
@@ -1,22 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/****************************************************************************** 2/******************************************************************************
2 * rtl8712_cmd.c 3 * rtl8712_cmd.c
3 * 4 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU 6 * Linux device driver for RTL8192SU
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * Modifications for inclusion into the Linux staging tree are 8 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved. 9 * Copyright(c) 2010 Larry Finger. All rights reserved.
22 * 10 *
diff --git a/drivers/staging/rtl8712/rtl8712_cmd.h b/drivers/staging/rtl8712/rtl8712_cmd.h
index 9181bb6b04c3..92fb77666d44 100644
--- a/drivers/staging/rtl8712/rtl8712_cmd.h
+++ b/drivers/staging/rtl8712/rtl8712_cmd.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl8712_cmdctrl_bitdef.h b/drivers/staging/rtl8712/rtl8712_cmdctrl_bitdef.h
index 4b8985d50098..e125c7222ab5 100644
--- a/drivers/staging/rtl8712/rtl8712_cmdctrl_bitdef.h
+++ b/drivers/staging/rtl8712/rtl8712_cmdctrl_bitdef.h
@@ -1,21 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 *
19 ******************************************************************************/ 6 ******************************************************************************/
20#ifndef __RTL8712_CMDCTRL_BITDEF_H__ 7#ifndef __RTL8712_CMDCTRL_BITDEF_H__
21#define __RTL8712_CMDCTRL_BITDEF_H__ 8#define __RTL8712_CMDCTRL_BITDEF_H__
diff --git a/drivers/staging/rtl8712/rtl8712_cmdctrl_regdef.h b/drivers/staging/rtl8712/rtl8712_cmdctrl_regdef.h
index 8df42a70399f..fc67771c89b7 100644
--- a/drivers/staging/rtl8712/rtl8712_cmdctrl_regdef.h
+++ b/drivers/staging/rtl8712/rtl8712_cmdctrl_regdef.h
@@ -1,21 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 *
19 ******************************************************************************/ 6 ******************************************************************************/
20#ifndef __RTL8712_CMDCTRL_REGDEF_H__ 7#ifndef __RTL8712_CMDCTRL_REGDEF_H__
21#define __RTL8712_CMDCTRL_REGDEF_H__ 8#define __RTL8712_CMDCTRL_REGDEF_H__
diff --git a/drivers/staging/rtl8712/rtl8712_debugctrl_bitdef.h b/drivers/staging/rtl8712/rtl8712_debugctrl_bitdef.h
index 4b3436795cb1..bb3863467f0d 100644
--- a/drivers/staging/rtl8712/rtl8712_debugctrl_bitdef.h
+++ b/drivers/staging/rtl8712/rtl8712_debugctrl_bitdef.h
@@ -1,21 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 *
19 ******************************************************************************/ 6 ******************************************************************************/
20#ifndef __RTL8712_DEBUGCTRL_BITDEF_H__ 7#ifndef __RTL8712_DEBUGCTRL_BITDEF_H__
21#define __RTL8712_DEBUGCTRL_BITDEF_H__ 8#define __RTL8712_DEBUGCTRL_BITDEF_H__
diff --git a/drivers/staging/rtl8712/rtl8712_debugctrl_regdef.h b/drivers/staging/rtl8712/rtl8712_debugctrl_regdef.h
index d7c964d436a1..319220e9d53d 100644
--- a/drivers/staging/rtl8712/rtl8712_debugctrl_regdef.h
+++ b/drivers/staging/rtl8712/rtl8712_debugctrl_regdef.h
@@ -1,21 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 *
19 ******************************************************************************/ 6 ******************************************************************************/
20#ifndef __RTL8712_DEBUGCTRL_REGDEF_H__ 7#ifndef __RTL8712_DEBUGCTRL_REGDEF_H__
21#define __RTL8712_DEBUGCTRL_REGDEF_H__ 8#define __RTL8712_DEBUGCTRL_REGDEF_H__
diff --git a/drivers/staging/rtl8712/rtl8712_edcasetting_bitdef.h b/drivers/staging/rtl8712/rtl8712_edcasetting_bitdef.h
index 32dab81f1767..9048d6a65296 100644
--- a/drivers/staging/rtl8712/rtl8712_edcasetting_bitdef.h
+++ b/drivers/staging/rtl8712/rtl8712_edcasetting_bitdef.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl8712_edcasetting_regdef.h b/drivers/staging/rtl8712/rtl8712_edcasetting_regdef.h
index d992cb8b1c73..02ec9f3bba66 100644
--- a/drivers/staging/rtl8712/rtl8712_edcasetting_regdef.h
+++ b/drivers/staging/rtl8712/rtl8712_edcasetting_regdef.h
@@ -1,21 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 *
19 ******************************************************************************/ 6 ******************************************************************************/
20#ifndef __RTL8712_EDCASETTING_REGDEF_H__ 7#ifndef __RTL8712_EDCASETTING_REGDEF_H__
21#define __RTL8712_EDCASETTING_REGDEF_H__ 8#define __RTL8712_EDCASETTING_REGDEF_H__
diff --git a/drivers/staging/rtl8712/rtl8712_efuse.c b/drivers/staging/rtl8712/rtl8712_efuse.c
index d90213eb5e20..8bc45ffd3029 100644
--- a/drivers/staging/rtl8712/rtl8712_efuse.c
+++ b/drivers/staging/rtl8712/rtl8712_efuse.c
@@ -1,22 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * rtl8712_efuse.c 3 * rtl8712_efuse.c
3 * 4 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU 6 * Linux device driver for RTL8192SU
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * Modifications for inclusion into the Linux staging tree are 8 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved. 9 * Copyright(c) 2010 Larry Finger. All rights reserved.
22 * 10 *
diff --git a/drivers/staging/rtl8712/rtl8712_event.h b/drivers/staging/rtl8712/rtl8712_event.h
index cad7085c3f8a..0d3e5feadcc0 100644
--- a/drivers/staging/rtl8712/rtl8712_event.h
+++ b/drivers/staging/rtl8712/rtl8712_event.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl8712_fifoctrl_bitdef.h b/drivers/staging/rtl8712/rtl8712_fifoctrl_bitdef.h
index bd8240476d71..f09645fa1886 100644
--- a/drivers/staging/rtl8712/rtl8712_fifoctrl_bitdef.h
+++ b/drivers/staging/rtl8712/rtl8712_fifoctrl_bitdef.h
@@ -1,21 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 *
19 ******************************************************************************/ 6 ******************************************************************************/
20#ifndef __RTL8712_FIFOCTRL_BITDEF_H__ 7#ifndef __RTL8712_FIFOCTRL_BITDEF_H__
21#define __RTL8712_FIFOCTRL_BITDEF_H__ 8#define __RTL8712_FIFOCTRL_BITDEF_H__
diff --git a/drivers/staging/rtl8712/rtl8712_fifoctrl_regdef.h b/drivers/staging/rtl8712/rtl8712_fifoctrl_regdef.h
index 6d527380fd29..189fdeb16d7d 100644
--- a/drivers/staging/rtl8712/rtl8712_fifoctrl_regdef.h
+++ b/drivers/staging/rtl8712/rtl8712_fifoctrl_regdef.h
@@ -1,21 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 *
19 ******************************************************************************/ 6 ******************************************************************************/
20#ifndef __RTL8712_FIFOCTRL_REGDEF_H__ 7#ifndef __RTL8712_FIFOCTRL_REGDEF_H__
21#define __RTL8712_FIFOCTRL_REGDEF_H__ 8#define __RTL8712_FIFOCTRL_REGDEF_H__
diff --git a/drivers/staging/rtl8712/rtl8712_gp_bitdef.h b/drivers/staging/rtl8712/rtl8712_gp_bitdef.h
index 66c35c990983..ee651fb3fde3 100644
--- a/drivers/staging/rtl8712/rtl8712_gp_bitdef.h
+++ b/drivers/staging/rtl8712/rtl8712_gp_bitdef.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl8712_gp_regdef.h b/drivers/staging/rtl8712/rtl8712_gp_regdef.h
index a0379360d0a3..892a7fb13923 100644
--- a/drivers/staging/rtl8712/rtl8712_gp_regdef.h
+++ b/drivers/staging/rtl8712/rtl8712_gp_regdef.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl8712_hal.h b/drivers/staging/rtl8712/rtl8712_hal.h
index 84456bb560ef..42f519739128 100644
--- a/drivers/staging/rtl8712/rtl8712_hal.h
+++ b/drivers/staging/rtl8712/rtl8712_hal.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl8712_interrupt_bitdef.h b/drivers/staging/rtl8712/rtl8712_interrupt_bitdef.h
index 2a561d2862e0..e9732a1bcd7e 100644
--- a/drivers/staging/rtl8712/rtl8712_interrupt_bitdef.h
+++ b/drivers/staging/rtl8712/rtl8712_interrupt_bitdef.h
@@ -1,21 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 *
19 ******************************************************************************/ 6 ******************************************************************************/
20#ifndef __RTL8712_INTERRUPT_BITDEF_H__ 7#ifndef __RTL8712_INTERRUPT_BITDEF_H__
21#define __RTL8712_INTERRUPT_BITDEF_H__ 8#define __RTL8712_INTERRUPT_BITDEF_H__
diff --git a/drivers/staging/rtl8712/rtl8712_io.c b/drivers/staging/rtl8712/rtl8712_io.c
index 391eff37f573..8eb79f73c014 100644
--- a/drivers/staging/rtl8712/rtl8712_io.c
+++ b/drivers/staging/rtl8712/rtl8712_io.c
@@ -1,22 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/****************************************************************************** 2/******************************************************************************
2 * rtl8712_io.c 3 * rtl8712_io.c
3 * 4 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU 6 * Linux device driver for RTL8192SU
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * Modifications for inclusion into the Linux staging tree are 8 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved. 9 * Copyright(c) 2010 Larry Finger. All rights reserved.
22 * 10 *
diff --git a/drivers/staging/rtl8712/rtl8712_led.c b/drivers/staging/rtl8712/rtl8712_led.c
index 0aa97c9dcced..5b1004b2df47 100644
--- a/drivers/staging/rtl8712/rtl8712_led.c
+++ b/drivers/staging/rtl8712/rtl8712_led.c
@@ -1,22 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/****************************************************************************** 2/******************************************************************************
2 * rtl8712_led.c 3 * rtl8712_led.c
3 * 4 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU 6 * Linux device driver for RTL8192SU
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * Modifications for inclusion into the Linux staging tree are 8 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved. 9 * Copyright(c) 2010 Larry Finger. All rights reserved.
22 * 10 *
diff --git a/drivers/staging/rtl8712/rtl8712_macsetting_bitdef.h b/drivers/staging/rtl8712/rtl8712_macsetting_bitdef.h
index 28e0a7ebcad7..3d9f40fa8469 100644
--- a/drivers/staging/rtl8712/rtl8712_macsetting_bitdef.h
+++ b/drivers/staging/rtl8712/rtl8712_macsetting_bitdef.h
@@ -1,21 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 *
19 ******************************************************************************/ 6 ******************************************************************************/
20#ifndef __RTL8712_MACSETTING_BITDEF_H__ 7#ifndef __RTL8712_MACSETTING_BITDEF_H__
21#define __RTL8712_MACSETTING_BITDEF_H__ 8#define __RTL8712_MACSETTING_BITDEF_H__
diff --git a/drivers/staging/rtl8712/rtl8712_macsetting_regdef.h b/drivers/staging/rtl8712/rtl8712_macsetting_regdef.h
index ced0da9332d5..e8cb2eee9294 100644
--- a/drivers/staging/rtl8712/rtl8712_macsetting_regdef.h
+++ b/drivers/staging/rtl8712/rtl8712_macsetting_regdef.h
@@ -1,21 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 *
19 ******************************************************************************/ 6 ******************************************************************************/
20#ifndef __RTL8712_MACSETTING_REGDEF_H__ 7#ifndef __RTL8712_MACSETTING_REGDEF_H__
21#define __RTL8712_MACSETTING_REGDEF_H__ 8#define __RTL8712_MACSETTING_REGDEF_H__
diff --git a/drivers/staging/rtl8712/rtl8712_powersave_bitdef.h b/drivers/staging/rtl8712/rtl8712_powersave_bitdef.h
index 8fc689416519..53e0d6b440f3 100644
--- a/drivers/staging/rtl8712/rtl8712_powersave_bitdef.h
+++ b/drivers/staging/rtl8712/rtl8712_powersave_bitdef.h
@@ -1,21 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 *
19 ******************************************************************************/ 6 ******************************************************************************/
20#ifndef __RTL8712_POWERSAVE_BITDEF_H__ 7#ifndef __RTL8712_POWERSAVE_BITDEF_H__
21#define __RTL8712_POWERSAVE_BITDEF_H__ 8#define __RTL8712_POWERSAVE_BITDEF_H__
diff --git a/drivers/staging/rtl8712/rtl8712_powersave_regdef.h b/drivers/staging/rtl8712/rtl8712_powersave_regdef.h
index 4632ddd5d1f7..1bcfde4b1c11 100644
--- a/drivers/staging/rtl8712/rtl8712_powersave_regdef.h
+++ b/drivers/staging/rtl8712/rtl8712_powersave_regdef.h
@@ -1,21 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 *
19 ******************************************************************************/ 6 ******************************************************************************/
20#ifndef __RTL8712_POWERSAVE_REGDEF_H__ 7#ifndef __RTL8712_POWERSAVE_REGDEF_H__
21#define __RTL8712_POWERSAVE_REGDEF_H__ 8#define __RTL8712_POWERSAVE_REGDEF_H__
diff --git a/drivers/staging/rtl8712/rtl8712_ratectrl_bitdef.h b/drivers/staging/rtl8712/rtl8712_ratectrl_bitdef.h
index 6d3d6e8522fb..1de51c48f9c1 100644
--- a/drivers/staging/rtl8712/rtl8712_ratectrl_bitdef.h
+++ b/drivers/staging/rtl8712/rtl8712_ratectrl_bitdef.h
@@ -1,21 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 *
19 ******************************************************************************/ 6 ******************************************************************************/
20#ifndef __RTL8712_RATECTRL_BITDEF_H__ 7#ifndef __RTL8712_RATECTRL_BITDEF_H__
21#define __RTL8712_RATECTRL_BITDEF_H__ 8#define __RTL8712_RATECTRL_BITDEF_H__
diff --git a/drivers/staging/rtl8712/rtl8712_ratectrl_regdef.h b/drivers/staging/rtl8712/rtl8712_ratectrl_regdef.h
index 73dfc3610154..a3eaee0e1b69 100644
--- a/drivers/staging/rtl8712/rtl8712_ratectrl_regdef.h
+++ b/drivers/staging/rtl8712/rtl8712_ratectrl_regdef.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl8712_recv.c b/drivers/staging/rtl8712/rtl8712_recv.c
index 4264cd341f03..5bf9070b7a28 100644
--- a/drivers/staging/rtl8712/rtl8712_recv.c
+++ b/drivers/staging/rtl8712/rtl8712_recv.c
@@ -1,22 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/****************************************************************************** 2/******************************************************************************
2 * rtl8712_recv.c 3 * rtl8712_recv.c
3 * 4 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU 6 * Linux device driver for RTL8192SU
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * Modifications for inclusion into the Linux staging tree are 8 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved. 9 * Copyright(c) 2010 Larry Finger. All rights reserved.
22 * 10 *
diff --git a/drivers/staging/rtl8712/rtl8712_recv.h b/drivers/staging/rtl8712/rtl8712_recv.h
index 0352e6fafd90..6954c5bfbcaf 100644
--- a/drivers/staging/rtl8712/rtl8712_recv.h
+++ b/drivers/staging/rtl8712/rtl8712_recv.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl8712_regdef.h b/drivers/staging/rtl8712/rtl8712_regdef.h
index e7bca55b59d0..28aec9aa539f 100644
--- a/drivers/staging/rtl8712/rtl8712_regdef.h
+++ b/drivers/staging/rtl8712/rtl8712_regdef.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl8712_security_bitdef.h b/drivers/staging/rtl8712/rtl8712_security_bitdef.h
index 05dafa0c3333..1c26a7eca64a 100644
--- a/drivers/staging/rtl8712/rtl8712_security_bitdef.h
+++ b/drivers/staging/rtl8712/rtl8712_security_bitdef.h
@@ -1,21 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 *
19 ******************************************************************************/ 6 ******************************************************************************/
20#ifndef __RTL8712_SECURITY_BITDEF_H__ 7#ifndef __RTL8712_SECURITY_BITDEF_H__
21#define __RTL8712_SECURITY_BITDEF_H__ 8#define __RTL8712_SECURITY_BITDEF_H__
diff --git a/drivers/staging/rtl8712/rtl8712_spec.h b/drivers/staging/rtl8712/rtl8712_spec.h
index 51e042815cc9..c0bab4c49ae9 100644
--- a/drivers/staging/rtl8712/rtl8712_spec.h
+++ b/drivers/staging/rtl8712/rtl8712_spec.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl8712_syscfg_bitdef.h b/drivers/staging/rtl8712/rtl8712_syscfg_bitdef.h
index 2e66d28d6918..a328ca9b340c 100644
--- a/drivers/staging/rtl8712/rtl8712_syscfg_bitdef.h
+++ b/drivers/staging/rtl8712/rtl8712_syscfg_bitdef.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl8712_syscfg_regdef.h b/drivers/staging/rtl8712/rtl8712_syscfg_regdef.h
index 767dfdf8d83f..e95eb5832ec4 100644
--- a/drivers/staging/rtl8712/rtl8712_syscfg_regdef.h
+++ b/drivers/staging/rtl8712/rtl8712_syscfg_regdef.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl8712_timectrl_bitdef.h b/drivers/staging/rtl8712/rtl8712_timectrl_bitdef.h
index 724421582421..1af5f1dd3c20 100644
--- a/drivers/staging/rtl8712/rtl8712_timectrl_bitdef.h
+++ b/drivers/staging/rtl8712/rtl8712_timectrl_bitdef.h
@@ -1,21 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 *
19 ******************************************************************************/ 6 ******************************************************************************/
20#ifndef __RTL8712_TIMECTRL_BITDEF_H__ 7#ifndef __RTL8712_TIMECTRL_BITDEF_H__
21#define __RTL8712_TIMECTRL_BITDEF_H__ 8#define __RTL8712_TIMECTRL_BITDEF_H__
diff --git a/drivers/staging/rtl8712/rtl8712_timectrl_regdef.h b/drivers/staging/rtl8712/rtl8712_timectrl_regdef.h
index 106916c7e310..b51603f1b880 100644
--- a/drivers/staging/rtl8712/rtl8712_timectrl_regdef.h
+++ b/drivers/staging/rtl8712/rtl8712_timectrl_regdef.h
@@ -1,21 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 *
19 ******************************************************************************/ 6 ******************************************************************************/
20#ifndef __RTL8712_TIMECTRL_REGDEF_H__ 7#ifndef __RTL8712_TIMECTRL_REGDEF_H__
21#define __RTL8712_TIMECTRL_REGDEF_H__ 8#define __RTL8712_TIMECTRL_REGDEF_H__
diff --git a/drivers/staging/rtl8712/rtl8712_wmac_bitdef.h b/drivers/staging/rtl8712/rtl8712_wmac_bitdef.h
index 61a3603aa587..d3b45c6cd855 100644
--- a/drivers/staging/rtl8712/rtl8712_wmac_bitdef.h
+++ b/drivers/staging/rtl8712/rtl8712_wmac_bitdef.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl8712_wmac_regdef.h b/drivers/staging/rtl8712/rtl8712_wmac_regdef.h
index d9f8347ab461..662383fe7a8d 100644
--- a/drivers/staging/rtl8712/rtl8712_wmac_regdef.h
+++ b/drivers/staging/rtl8712/rtl8712_wmac_regdef.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl8712_xmit.c b/drivers/staging/rtl8712/rtl8712_xmit.c
index fb64c2891e22..aa6fb516f398 100644
--- a/drivers/staging/rtl8712/rtl8712_xmit.c
+++ b/drivers/staging/rtl8712/rtl8712_xmit.c
@@ -1,22 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/****************************************************************************** 2/******************************************************************************
2 * rtl8712_xmit.c 3 * rtl8712_xmit.c
3 * 4 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU 6 * Linux device driver for RTL8192SU
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * Modifications for inclusion into the Linux staging tree are 8 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved. 9 * Copyright(c) 2010 Larry Finger. All rights reserved.
22 * 10 *
diff --git a/drivers/staging/rtl8712/rtl8712_xmit.h b/drivers/staging/rtl8712/rtl8712_xmit.h
index 02b1593ada01..9be8fb70c92e 100644
--- a/drivers/staging/rtl8712/rtl8712_xmit.h
+++ b/drivers/staging/rtl8712/rtl8712_xmit.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl871x_cmd.c b/drivers/staging/rtl8712/rtl871x_cmd.c
index 620cee8b8514..05a78ac24987 100644
--- a/drivers/staging/rtl8712/rtl871x_cmd.c
+++ b/drivers/staging/rtl8712/rtl871x_cmd.c
@@ -1,22 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/****************************************************************************** 2/******************************************************************************
2 * rtl871x_cmd.c 3 * rtl871x_cmd.c
3 * 4 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU 6 * Linux device driver for RTL8192SU
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * Modifications for inclusion into the Linux staging tree are 8 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved. 9 * Copyright(c) 2010 Larry Finger. All rights reserved.
22 * 10 *
diff --git a/drivers/staging/rtl8712/rtl871x_cmd.h b/drivers/staging/rtl8712/rtl871x_cmd.h
index 24da2ccea04f..75a126d8e26c 100644
--- a/drivers/staging/rtl8712/rtl871x_cmd.h
+++ b/drivers/staging/rtl8712/rtl871x_cmd.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl871x_debug.h b/drivers/staging/rtl8712/rtl871x_debug.h
index 74468b058258..a427547c02ba 100644
--- a/drivers/staging/rtl8712/rtl871x_debug.h
+++ b/drivers/staging/rtl8712/rtl871x_debug.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl871x_eeprom.c b/drivers/staging/rtl8712/rtl871x_eeprom.c
index 4e713610ad8b..948bd0c757b5 100644
--- a/drivers/staging/rtl8712/rtl871x_eeprom.c
+++ b/drivers/staging/rtl8712/rtl871x_eeprom.c
@@ -1,22 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/****************************************************************************** 2/******************************************************************************
2 * rtl871x_eeprom.c 3 * rtl871x_eeprom.c
3 * 4 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU 6 * Linux device driver for RTL8192SU
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * Modifications for inclusion into the Linux staging tree are 8 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved. 9 * Copyright(c) 2010 Larry Finger. All rights reserved.
22 * 10 *
diff --git a/drivers/staging/rtl8712/rtl871x_eeprom.h b/drivers/staging/rtl8712/rtl871x_eeprom.h
index 497276e53bbe..7bdeb2aaa025 100644
--- a/drivers/staging/rtl8712/rtl871x_eeprom.h
+++ b/drivers/staging/rtl8712/rtl871x_eeprom.h
@@ -1,21 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 *
19 ******************************************************************************/ 6 ******************************************************************************/
20#ifndef __RTL871X_EEPROM_H__ 7#ifndef __RTL871X_EEPROM_H__
21#define __RTL871X_EEPROM_H__ 8#define __RTL871X_EEPROM_H__
diff --git a/drivers/staging/rtl8712/rtl871x_event.h b/drivers/staging/rtl8712/rtl871x_event.h
index 517137906e6c..d9a5476d2426 100644
--- a/drivers/staging/rtl8712/rtl871x_event.h
+++ b/drivers/staging/rtl8712/rtl871x_event.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl871x_ht.h b/drivers/staging/rtl8712/rtl871x_ht.h
index 513f458ea07c..ebd78665775d 100644
--- a/drivers/staging/rtl8712/rtl871x_ht.h
+++ b/drivers/staging/rtl8712/rtl871x_ht.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl871x_io.c b/drivers/staging/rtl8712/rtl871x_io.c
index 3a10940db9b7..17dafeffd6f4 100644
--- a/drivers/staging/rtl8712/rtl871x_io.c
+++ b/drivers/staging/rtl8712/rtl871x_io.c
@@ -1,22 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/****************************************************************************** 2/******************************************************************************
2 * rtl871x_io.c 3 * rtl871x_io.c
3 * 4 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU 6 * Linux device driver for RTL8192SU
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * Modifications for inclusion into the Linux staging tree are 8 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved. 9 * Copyright(c) 2010 Larry Finger. All rights reserved.
22 * 10 *
@@ -68,7 +56,7 @@ static uint _init_intf_hdl(struct _adapter *padapter,
68 set_intf_option(&pintf_hdl->intf_option); 56 set_intf_option(&pintf_hdl->intf_option);
69 set_intf_funs(pintf_hdl); 57 set_intf_funs(pintf_hdl);
70 set_intf_ops(&pintf_hdl->io_ops); 58 set_intf_ops(&pintf_hdl->io_ops);
71 pintf_priv->intf_dev = (u8 *)&(padapter->dvobjpriv); 59 pintf_priv->intf_dev = (u8 *)&padapter->dvobjpriv;
72 if (init_intf_priv(pintf_priv) == _FAIL) 60 if (init_intf_priv(pintf_priv) == _FAIL)
73 goto _init_intf_hdl_fail; 61 goto _init_intf_hdl_fail;
74 return _SUCCESS; 62 return _SUCCESS;
@@ -92,7 +80,7 @@ static uint register_intf_hdl(u8 *dev, struct intf_hdl *pintfhdl)
92 80
93 pintfhdl->intf_option = 0; 81 pintfhdl->intf_option = 0;
94 pintfhdl->adapter = dev; 82 pintfhdl->adapter = dev;
95 pintfhdl->intf_dev = (u8 *)&(adapter->dvobjpriv); 83 pintfhdl->intf_dev = (u8 *)&adapter->dvobjpriv;
96 if (!_init_intf_hdl(adapter, pintfhdl)) 84 if (!_init_intf_hdl(adapter, pintfhdl))
97 goto register_intf_hdl_fail; 85 goto register_intf_hdl_fail;
98 return _SUCCESS; 86 return _SUCCESS;
@@ -135,7 +123,7 @@ uint r8712_alloc_io_queue(struct _adapter *adapter)
135 list_add_tail(&pio_req->list, &pio_queue->free_ioreqs); 123 list_add_tail(&pio_req->list, &pio_queue->free_ioreqs);
136 pio_req++; 124 pio_req++;
137 } 125 }
138 if ((register_intf_hdl((u8 *)adapter, &(pio_queue->intf))) == _FAIL) 126 if ((register_intf_hdl((u8 *)adapter, &pio_queue->intf)) == _FAIL)
139 goto alloc_io_queue_fail; 127 goto alloc_io_queue_fail;
140 adapter->pio_queue = pio_queue; 128 adapter->pio_queue = pio_queue;
141 return _SUCCESS; 129 return _SUCCESS;
diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
index dd054d7367b3..28941423b7ed 100644
--- a/drivers/staging/rtl8712/rtl871x_io.h
+++ b/drivers/staging/rtl8712/rtl871x_io.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
index c3ff7c3e6681..e723357ac8c0 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
+++ b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
@@ -1,22 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/****************************************************************************** 2/******************************************************************************
2 * rtl871x_ioctl_linux.c 3 * rtl871x_ioctl_linux.c
3 * 4 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU 6 * Linux device driver for RTL8192SU
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * Modifications for inclusion into the Linux staging tree are 8 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved. 9 * Copyright(c) 2010 Larry Finger. All rights reserved.
22 * 10 *
@@ -67,11 +55,6 @@ static const long ieee80211_wlan_frequencies[] = {
67 2472, 2484 55 2472, 2484
68}; 56};
69 57
70static const char * const iw_operation_mode[] = {
71 "Auto", "Ad-Hoc", "Managed", "Master", "Repeater", "Secondary",
72 "Monitor"
73};
74
75void r8712_indicate_wx_assoc_event(struct _adapter *padapter) 58void r8712_indicate_wx_assoc_event(struct _adapter *padapter)
76{ 59{
77 union iwreq_data wrqu; 60 union iwreq_data wrqu;
@@ -1789,7 +1772,7 @@ static int r871x_wx_set_enc_ext(struct net_device *dev,
1789 return -ENOMEM; 1772 return -ENOMEM;
1790 param->cmd = IEEE_CMD_SET_ENCRYPTION; 1773 param->cmd = IEEE_CMD_SET_ENCRYPTION;
1791 eth_broadcast_addr(param->sta_addr); 1774 eth_broadcast_addr(param->sta_addr);
1792 strncpy((char *)param->u.crypt.alg, alg_name, IEEE_CRYPT_ALG_NAME_LEN); 1775 strlcpy((char *)param->u.crypt.alg, alg_name, IEEE_CRYPT_ALG_NAME_LEN);
1793 if (pext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) 1776 if (pext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
1794 param->u.crypt.set_tx = 0; 1777 param->u.crypt.set_tx = 0;
1795 if (pext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) 1778 if (pext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_rtl.c b/drivers/staging/rtl8712/rtl871x_ioctl_rtl.c
index ca769f781e96..2dc20da21679 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl_rtl.c
+++ b/drivers/staging/rtl8712/rtl871x_ioctl_rtl.c
@@ -1,22 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/****************************************************************************** 2/******************************************************************************
2 * rtl871x_ioctl_rtl.c 3 * rtl871x_ioctl_rtl.c
3 * 4 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU 6 * Linux device driver for RTL8192SU
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * Modifications for inclusion into the Linux staging tree are 8 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved. 9 * Copyright(c) 2010 Larry Finger. All rights reserved.
22 * 10 *
diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_rtl.h b/drivers/staging/rtl8712/rtl871x_ioctl_rtl.h
index 3bcceae3cbeb..7c0b880ac686 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl_rtl.h
+++ b/drivers/staging/rtl8712/rtl871x_ioctl_rtl.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_set.c b/drivers/staging/rtl8712/rtl871x_ioctl_set.c
index f4a53df7f2c1..2622d5e3bff9 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl_set.c
+++ b/drivers/staging/rtl8712/rtl871x_ioctl_set.c
@@ -1,22 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/****************************************************************************** 2/******************************************************************************
2 * rtl871x_ioctl_set.c 3 * rtl871x_ioctl_set.c
3 * 4 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU 6 * Linux device driver for RTL8192SU
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * Modifications for inclusion into the Linux staging tree are 8 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved. 9 * Copyright(c) 2010 Larry Finger. All rights reserved.
22 * 10 *
diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_set.h b/drivers/staging/rtl8712/rtl871x_ioctl_set.h
index 2c94cd151c96..8b1085aea962 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl_set.h
+++ b/drivers/staging/rtl8712/rtl871x_ioctl_set.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl871x_led.h b/drivers/staging/rtl8712/rtl871x_led.h
index adfbc400a18d..ee19c873cf01 100644
--- a/drivers/staging/rtl8712/rtl871x_led.h
+++ b/drivers/staging/rtl8712/rtl871x_led.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl871x_mlme.c b/drivers/staging/rtl8712/rtl871x_mlme.c
index ac547ddd72d1..a7374006a9fb 100644
--- a/drivers/staging/rtl8712/rtl871x_mlme.c
+++ b/drivers/staging/rtl8712/rtl871x_mlme.c
@@ -1,22 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/****************************************************************************** 2/******************************************************************************
2 * rtl871x_mlme.c 3 * rtl871x_mlme.c
3 * 4 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU 6 * Linux device driver for RTL8192SU
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * Modifications for inclusion into the Linux staging tree are 8 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved. 9 * Copyright(c) 2010 Larry Finger. All rights reserved.
22 * 10 *
diff --git a/drivers/staging/rtl8712/rtl871x_mlme.h b/drivers/staging/rtl8712/rtl871x_mlme.h
index 918947f38151..8a54181f4816 100644
--- a/drivers/staging/rtl8712/rtl871x_mlme.h
+++ b/drivers/staging/rtl8712/rtl871x_mlme.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl871x_mp.c b/drivers/staging/rtl8712/rtl871x_mp.c
index ba208a2e1e4e..1d5364f5a518 100644
--- a/drivers/staging/rtl8712/rtl871x_mp.c
+++ b/drivers/staging/rtl8712/rtl871x_mp.c
@@ -1,20 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl871x_mp.h b/drivers/staging/rtl8712/rtl871x_mp.h
index 8df452e3e3ce..e79a67676469 100644
--- a/drivers/staging/rtl8712/rtl871x_mp.h
+++ b/drivers/staging/rtl8712/rtl871x_mp.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl871x_mp_ioctl.c b/drivers/staging/rtl8712/rtl871x_mp_ioctl.c
index 6e264a8d0087..588346da1412 100644
--- a/drivers/staging/rtl8712/rtl871x_mp_ioctl.c
+++ b/drivers/staging/rtl8712/rtl871x_mp_ioctl.c
@@ -1,22 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/****************************************************************************** 2/******************************************************************************
2 * rtl871x_mp_ioctl.c 3 * rtl871x_mp_ioctl.c
3 * 4 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU 6 * Linux device driver for RTL8192SU
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * Modifications for inclusion into the Linux staging tree are 8 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved. 9 * Copyright(c) 2010 Larry Finger. All rights reserved.
22 * 10 *
diff --git a/drivers/staging/rtl8712/rtl871x_mp_ioctl.h b/drivers/staging/rtl8712/rtl871x_mp_ioctl.h
index 741006f1e45a..44cd911f2aa1 100644
--- a/drivers/staging/rtl8712/rtl871x_mp_ioctl.h
+++ b/drivers/staging/rtl8712/rtl871x_mp_ioctl.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl871x_pwrctrl.c b/drivers/staging/rtl8712/rtl871x_pwrctrl.c
index ae4c9567bb55..351984fe254e 100644
--- a/drivers/staging/rtl8712/rtl871x_pwrctrl.c
+++ b/drivers/staging/rtl8712/rtl871x_pwrctrl.c
@@ -1,22 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/****************************************************************************** 2/******************************************************************************
2 * rtl871x_pwrctrl.c 3 * rtl871x_pwrctrl.c
3 * 4 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU 6 * Linux device driver for RTL8192SU
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * Modifications for inclusion into the Linux staging tree are 8 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved. 9 * Copyright(c) 2010 Larry Finger. All rights reserved.
22 * 10 *
diff --git a/drivers/staging/rtl8712/rtl871x_pwrctrl.h b/drivers/staging/rtl8712/rtl871x_pwrctrl.h
index bd2c3a2df48b..11b5034f203d 100644
--- a/drivers/staging/rtl8712/rtl871x_pwrctrl.h
+++ b/drivers/staging/rtl8712/rtl871x_pwrctrl.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl871x_recv.c b/drivers/staging/rtl8712/rtl871x_recv.c
index 2ef31a4e9a6b..f10896df094b 100644
--- a/drivers/staging/rtl8712/rtl871x_recv.c
+++ b/drivers/staging/rtl8712/rtl871x_recv.c
@@ -1,22 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/****************************************************************************** 2/******************************************************************************
2 * rtl871x_recv.c 3 * rtl871x_recv.c
3 * 4 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU 6 * Linux device driver for RTL8192SU
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * Modifications for inclusion into the Linux staging tree are 8 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved. 9 * Copyright(c) 2010 Larry Finger. All rights reserved.
22 * 10 *
diff --git a/drivers/staging/rtl8712/rtl871x_rf.h b/drivers/staging/rtl8712/rtl871x_rf.h
index 133ed6462928..cc54453cd424 100644
--- a/drivers/staging/rtl8712/rtl871x_rf.h
+++ b/drivers/staging/rtl8712/rtl871x_rf.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl871x_security.c b/drivers/staging/rtl8712/rtl871x_security.c
index 1075eacdb441..f82645011d02 100644
--- a/drivers/staging/rtl8712/rtl871x_security.c
+++ b/drivers/staging/rtl8712/rtl871x_security.c
@@ -1,22 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/****************************************************************************** 2/******************************************************************************
2 * rtl871x_security.c 3 * rtl871x_security.c
3 * 4 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU 6 * Linux device driver for RTL8192SU
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * Modifications for inclusion into the Linux staging tree are 8 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved. 9 * Copyright(c) 2010 Larry Finger. All rights reserved.
22 * 10 *
diff --git a/drivers/staging/rtl8712/rtl871x_security.h b/drivers/staging/rtl8712/rtl871x_security.h
index 46b88a41d236..25b4d379766d 100644
--- a/drivers/staging/rtl8712/rtl871x_security.h
+++ b/drivers/staging/rtl8712/rtl871x_security.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl871x_sta_mgt.c b/drivers/staging/rtl8712/rtl871x_sta_mgt.c
index e2d75e4c473f..9648ee15b40e 100644
--- a/drivers/staging/rtl8712/rtl871x_sta_mgt.c
+++ b/drivers/staging/rtl8712/rtl871x_sta_mgt.c
@@ -1,22 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/****************************************************************************** 2/******************************************************************************
2 * rtl871x_sta_mgt.c 3 * rtl871x_sta_mgt.c
3 * 4 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU 6 * Linux device driver for RTL8192SU
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * Modifications for inclusion into the Linux staging tree are 8 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved. 9 * Copyright(c) 2010 Larry Finger. All rights reserved.
22 * 10 *
diff --git a/drivers/staging/rtl8712/rtl871x_wlan_sme.h b/drivers/staging/rtl8712/rtl871x_wlan_sme.h
index 44924d5de217..97ea1451426c 100644
--- a/drivers/staging/rtl8712/rtl871x_wlan_sme.h
+++ b/drivers/staging/rtl8712/rtl871x_wlan_sme.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/rtl871x_xmit.c b/drivers/staging/rtl8712/rtl871x_xmit.c
index a8ae14ce6613..5c7dc9c6f76b 100644
--- a/drivers/staging/rtl8712/rtl871x_xmit.c
+++ b/drivers/staging/rtl8712/rtl871x_xmit.c
@@ -1,22 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/****************************************************************************** 2/******************************************************************************
2 * rtl871x_xmit.c 3 * rtl871x_xmit.c
3 * 4 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU 6 * Linux device driver for RTL8192SU
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * Modifications for inclusion into the Linux staging tree are 8 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved. 9 * Copyright(c) 2010 Larry Finger. All rights reserved.
22 * 10 *
@@ -433,7 +421,7 @@ static sint xmitframe_addmic(struct _adapter *padapter,
433 r8712_secmicappend(&micdata, payload, 421 r8712_secmicappend(&micdata, payload,
434 length); 422 length);
435 payload = payload + length; 423 payload = payload + length;
436 } else{ 424 } else {
437 length = pxmitpriv->frag_len - 425 length = pxmitpriv->frag_len -
438 pattrib->hdrlen - pattrib->iv_len - 426 pattrib->hdrlen - pattrib->iv_len -
439 ((psecuritypriv->sw_encrypt) ? 427 ((psecuritypriv->sw_encrypt) ?
diff --git a/drivers/staging/rtl8712/rtl871x_xmit.h b/drivers/staging/rtl8712/rtl871x_xmit.h
index 40927277f498..3bea2e374f13 100644
--- a/drivers/staging/rtl8712/rtl871x_xmit.h
+++ b/drivers/staging/rtl8712/rtl871x_xmit.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/sta_info.h b/drivers/staging/rtl8712/sta_info.h
index 742dfa0ca817..45dbed10295f 100644
--- a/drivers/staging/rtl8712/sta_info.h
+++ b/drivers/staging/rtl8712/sta_info.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/usb_halinit.c b/drivers/staging/rtl8712/usb_halinit.c
index 0b159850f5a2..02e73c2412d4 100644
--- a/drivers/staging/rtl8712/usb_halinit.c
+++ b/drivers/staging/rtl8712/usb_halinit.c
@@ -1,22 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/****************************************************************************** 2/******************************************************************************
2 * usb_halinit.c 3 * usb_halinit.c
3 * 4 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU 6 * Linux device driver for RTL8192SU
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * Modifications for inclusion into the Linux staging tree are 8 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved. 9 * Copyright(c) 2010 Larry Finger. All rights reserved.
22 * 10 *
diff --git a/drivers/staging/rtl8712/usb_intf.c b/drivers/staging/rtl8712/usb_intf.c
index 85eadddfaf06..92d75d7c51ae 100644
--- a/drivers/staging/rtl8712/usb_intf.c
+++ b/drivers/staging/rtl8712/usb_intf.c
@@ -1,22 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/****************************************************************************** 2/******************************************************************************
2 * usb_intf.c 3 * usb_intf.c
3 * 4 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU 6 * Linux device driver for RTL8192SU
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * Modifications for inclusion into the Linux staging tree are 8 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved. 9 * Copyright(c) 2010 Larry Finger. All rights reserved.
22 * 10 *
diff --git a/drivers/staging/rtl8712/usb_ops.c b/drivers/staging/rtl8712/usb_ops.c
index 332e2e51d778..eef52d5c730a 100644
--- a/drivers/staging/rtl8712/usb_ops.c
+++ b/drivers/staging/rtl8712/usb_ops.c
@@ -1,22 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/****************************************************************************** 2/******************************************************************************
2 * usb_ops.c 3 * usb_ops.c
3 * 4 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU 6 * Linux device driver for RTL8192SU
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * Modifications for inclusion into the Linux staging tree are 8 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved. 9 * Copyright(c) 2010 Larry Finger. All rights reserved.
22 * 10 *
diff --git a/drivers/staging/rtl8712/usb_ops.h b/drivers/staging/rtl8712/usb_ops.h
index 78e775a46364..d62975447d29 100644
--- a/drivers/staging/rtl8712/usb_ops.h
+++ b/drivers/staging/rtl8712/usb_ops.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/usb_ops_linux.c b/drivers/staging/rtl8712/usb_ops_linux.c
index 6d12a96fa65f..ee5968808332 100644
--- a/drivers/staging/rtl8712/usb_ops_linux.c
+++ b/drivers/staging/rtl8712/usb_ops_linux.c
@@ -1,22 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/****************************************************************************** 2/******************************************************************************
2 * usb_ops_linux.c 3 * usb_ops_linux.c
3 * 4 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU 6 * Linux device driver for RTL8192SU
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * Modifications for inclusion into the Linux staging tree are 8 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved. 9 * Copyright(c) 2010 Larry Finger. All rights reserved.
22 * 10 *
diff --git a/drivers/staging/rtl8712/usb_osintf.h b/drivers/staging/rtl8712/usb_osintf.h
index 609f9210cc46..ddfa405d0c9b 100644
--- a/drivers/staging/rtl8712/usb_osintf.h
+++ b/drivers/staging/rtl8712/usb_osintf.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/wifi.h b/drivers/staging/rtl8712/wifi.h
index 00a4302e9983..77346debea03 100644
--- a/drivers/staging/rtl8712/wifi.h
+++ b/drivers/staging/rtl8712/wifi.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/wlan_bssdef.h b/drivers/staging/rtl8712/wlan_bssdef.h
index 9dc9ce5a2ccc..b54ccaacc527 100644
--- a/drivers/staging/rtl8712/wlan_bssdef.h
+++ b/drivers/staging/rtl8712/wlan_bssdef.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8712/xmit_linux.c b/drivers/staging/rtl8712/xmit_linux.c
index 4ee4136b5c28..8bcb0775411f 100644
--- a/drivers/staging/rtl8712/xmit_linux.c
+++ b/drivers/staging/rtl8712/xmit_linux.c
@@ -1,22 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/****************************************************************************** 2/******************************************************************************
2 * xmit_linux.c 3 * xmit_linux.c
3 * 4 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU 6 * Linux device driver for RTL8192SU
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * Modifications for inclusion into the Linux staging tree are 8 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved. 9 * Copyright(c) 2010 Larry Finger. All rights reserved.
22 * 10 *
diff --git a/drivers/staging/rtl8712/xmit_osdep.h b/drivers/staging/rtl8712/xmit_osdep.h
index 8eba7ca0ddef..21f6b31e0f50 100644
--- a/drivers/staging/rtl8712/xmit_osdep.h
+++ b/drivers/staging/rtl8712/xmit_osdep.h
@@ -1,20 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/****************************************************************************** 2/******************************************************************************
2 * 3 *
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved. 4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * Modifications for inclusion into the Linux staging tree are 6 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved. 7 * Copyright(c) 2010 Larry Finger. All rights reserved.
20 * 8 *
diff --git a/drivers/staging/rtl8723bs/core/rtw_ap.c b/drivers/staging/rtl8723bs/core/rtw_ap.c
index faf4b4158cfa..2691241bfd84 100644
--- a/drivers/staging/rtl8723bs/core/rtw_ap.c
+++ b/drivers/staging/rtl8723bs/core/rtw_ap.c
@@ -861,7 +861,7 @@ void start_bss_network(struct adapter *padapter, u8 *pbuf)
861 update_hw_ht_param(padapter); 861 update_hw_ht_param(padapter);
862 } 862 }
863 863
864 if (pmlmepriv->cur_network.join_res != true) { /* setting only at first time */ 864 if (!pmlmepriv->cur_network.join_res) { /* setting only at first time */
865 865
866 /* WEP Key will be set before this function, do not clear CAM. */ 866 /* WEP Key will be set before this function, do not clear CAM. */
867 if ( 867 if (
@@ -899,7 +899,7 @@ void start_bss_network(struct adapter *padapter, u8 *pbuf)
899 899
900 rtw_hal_set_hwreg(padapter, HW_VAR_DO_IQK, NULL); 900 rtw_hal_set_hwreg(padapter, HW_VAR_DO_IQK, NULL);
901 901
902 if (pmlmepriv->cur_network.join_res != true) { /* setting only at first time */ 902 if (!pmlmepriv->cur_network.join_res) { /* setting only at first time */
903 903
904 /* u32 initialgain; */ 904 /* u32 initialgain; */
905 905
@@ -992,7 +992,7 @@ void start_bss_network(struct adapter *padapter, u8 *pbuf)
992 ); 992 );
993 993
994 994
995 if (true == pmlmeext->bstart_bss) { 995 if (pmlmeext->bstart_bss) {
996 996
997 update_beacon(padapter, _TIM_IE_, NULL, true); 997 update_beacon(padapter, _TIM_IE_, NULL, true);
998 998
@@ -1047,7 +1047,7 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len)
1047 1047
1048 DBG_871X("%s, len =%d\n", __func__, len); 1048 DBG_871X("%s, len =%d\n", __func__, len);
1049 1049
1050 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != true) 1050 if (!check_fwstate(pmlmepriv, WIFI_AP_STATE))
1051 return _FAIL; 1051 return _FAIL;
1052 1052
1053 1053
@@ -1379,7 +1379,7 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len)
1379 } 1379 }
1380 1380
1381 /* ht_cap */ 1381 /* ht_cap */
1382 if (pregistrypriv->ht_enable && ht_cap == true) { 1382 if (pregistrypriv->ht_enable && ht_cap) {
1383 1383
1384 pmlmepriv->htpriv.ht_option = true; 1384 pmlmepriv->htpriv.ht_option = true;
1385 pmlmepriv->qospriv.qos_option = 1; 1385 pmlmepriv->qospriv.qos_option = 1;
@@ -1482,7 +1482,7 @@ int rtw_acl_add_sta(struct adapter *padapter, u8 *addr)
1482 spin_unlock_bh(&(pacl_node_q->lock)); 1482 spin_unlock_bh(&(pacl_node_q->lock));
1483 1483
1484 1484
1485 if (added == true) 1485 if (added)
1486 return ret; 1486 return ret;
1487 1487
1488 1488
@@ -1492,7 +1492,7 @@ int rtw_acl_add_sta(struct adapter *padapter, u8 *addr)
1492 1492
1493 paclnode = &pacl_list->aclnode[i]; 1493 paclnode = &pacl_list->aclnode[i];
1494 1494
1495 if (paclnode->valid == false) { 1495 if (!paclnode->valid) {
1496 1496
1497 INIT_LIST_HEAD(&paclnode->list); 1497 INIT_LIST_HEAD(&paclnode->list);
1498 1498
@@ -1547,7 +1547,7 @@ int rtw_acl_remove_sta(struct adapter *padapter, u8 *addr)
1547 !memcmp(baddr, addr, ETH_ALEN) 1547 !memcmp(baddr, addr, ETH_ALEN)
1548 ) { 1548 ) {
1549 1549
1550 if (paclnode->valid == true) { 1550 if (paclnode->valid) {
1551 1551
1552 paclnode->valid = false; 1552 paclnode->valid = false;
1553 1553
@@ -1912,7 +1912,7 @@ void update_beacon(struct adapter *padapter, u8 ie_id, u8 *oui, u8 tx)
1912 pmlmeext = &(padapter->mlmeextpriv); 1912 pmlmeext = &(padapter->mlmeextpriv);
1913 /* pmlmeinfo = &(pmlmeext->mlmext_info); */ 1913 /* pmlmeinfo = &(pmlmeext->mlmext_info); */
1914 1914
1915 if (false == pmlmeext->bstart_bss) 1915 if (!pmlmeext->bstart_bss)
1916 return; 1916 return;
1917 1917
1918 spin_lock_bh(&pmlmepriv->bcn_update_lock); 1918 spin_lock_bh(&pmlmepriv->bcn_update_lock);
@@ -1998,7 +1998,7 @@ static int rtw_ht_operation_update(struct adapter *padapter)
1998 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 1998 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
1999 struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv; 1999 struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
2000 2000
2001 if (pmlmepriv->htpriv.ht_option == true) 2001 if (pmlmepriv->htpriv.ht_option)
2002 return 0; 2002 return 0;
2003 2003
2004 /* if (!iface->conf->ieee80211n || iface->conf->ht_op_mode_fixed) */ 2004 /* if (!iface->conf->ieee80211n || iface->conf->ht_op_mode_fixed) */
@@ -2066,7 +2066,7 @@ static int rtw_ht_operation_update(struct adapter *padapter)
2066void associated_clients_update(struct adapter *padapter, u8 updated) 2066void associated_clients_update(struct adapter *padapter, u8 updated)
2067{ 2067{
2068 /* update associcated stations cap. */ 2068 /* update associcated stations cap. */
2069 if (updated == true) { 2069 if (updated) {
2070 2070
2071 struct list_head *phead, *plist; 2071 struct list_head *phead, *plist;
2072 struct sta_info *psta = NULL; 2072 struct sta_info *psta = NULL;
@@ -2458,7 +2458,7 @@ void sta_info_update(struct adapter *padapter, struct sta_info *psta)
2458 psta->htpriv.ht_option = false; 2458 psta->htpriv.ht_option = false;
2459 } 2459 }
2460 2460
2461 if (pmlmepriv->htpriv.ht_option == false) 2461 if (!pmlmepriv->htpriv.ht_option)
2462 psta->htpriv.ht_option = false; 2462 psta->htpriv.ht_option = false;
2463 2463
2464 update_sta_info_apmode(padapter, psta); 2464 update_sta_info_apmode(padapter, psta);
diff --git a/drivers/staging/rtl8723bs/core/rtw_debug.c b/drivers/staging/rtl8723bs/core/rtw_debug.c
index f852fde47350..a2a2cefd1786 100644
--- a/drivers/staging/rtl8723bs/core/rtw_debug.c
+++ b/drivers/staging/rtl8723bs/core/rtw_debug.c
@@ -657,7 +657,7 @@ int proc_get_suspend_resume_info(struct seq_file *m, void *v)
657 DBG_871X_SEL_NL(m, "dbg_enwow_dload_fw_fail_cnt =%d\n", pdbgpriv->dbg_enwow_dload_fw_fail_cnt); 657 DBG_871X_SEL_NL(m, "dbg_enwow_dload_fw_fail_cnt =%d\n", pdbgpriv->dbg_enwow_dload_fw_fail_cnt);
658 DBG_871X_SEL_NL(m, "dbg_ips_drvopen_fail_cnt =%d\n", pdbgpriv->dbg_ips_drvopen_fail_cnt); 658 DBG_871X_SEL_NL(m, "dbg_ips_drvopen_fail_cnt =%d\n", pdbgpriv->dbg_ips_drvopen_fail_cnt);
659 DBG_871X_SEL_NL(m, "dbg_poll_fail_cnt =%d\n", pdbgpriv->dbg_poll_fail_cnt); 659 DBG_871X_SEL_NL(m, "dbg_poll_fail_cnt =%d\n", pdbgpriv->dbg_poll_fail_cnt);
660 DBG_871X_SEL_NL(m, "dbg_rpwm_toogle_cnt =%d\n", pdbgpriv->dbg_rpwm_toogle_cnt); 660 DBG_871X_SEL_NL(m, "dbg_rpwm_toggle_cnt =%d\n", pdbgpriv->dbg_rpwm_toggle_cnt);
661 DBG_871X_SEL_NL(m, "dbg_rpwm_timeout_fail_cnt =%d\n", pdbgpriv->dbg_rpwm_timeout_fail_cnt); 661 DBG_871X_SEL_NL(m, "dbg_rpwm_timeout_fail_cnt =%d\n", pdbgpriv->dbg_rpwm_timeout_fail_cnt);
662 662
663 return 0; 663 return 0;
diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme.c b/drivers/staging/rtl8723bs/core/rtw_mlme.c
index f9392b8db49b..4c5d5cf9dfe0 100644
--- a/drivers/staging/rtl8723bs/core/rtw_mlme.c
+++ b/drivers/staging/rtl8723bs/core/rtw_mlme.c
@@ -802,7 +802,7 @@ int rtw_is_desired_network(struct adapter *adapter, struct wlan_network *pnetwor
802/* TODO: Perry : For Power Management */ 802/* TODO: Perry : For Power Management */
803void rtw_atimdone_event_callback(struct adapter *adapter, u8 *pbuf) 803void rtw_atimdone_event_callback(struct adapter *adapter, u8 *pbuf)
804{ 804{
805 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("receive atimdone_evet\n")); 805 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("receive atimdone_event\n"));
806} 806}
807 807
808 808
diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
index 0952d15f6d40..69c7abc0e3a5 100644
--- a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
+++ b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
@@ -1267,13 +1267,12 @@ unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
1267 /* checking SSID */ 1267 /* checking SSID */
1268 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, _SSID_IE_, &ie_len, 1268 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, _SSID_IE_, &ie_len,
1269 pkt_len - WLAN_HDR_A3_LEN - ie_offset); 1269 pkt_len - WLAN_HDR_A3_LEN - ie_offset);
1270 if (p == NULL) {
1271 status = _STATS_FAILURE_;
1272 }
1273 1270
1274 if (ie_len == 0) /* broadcast ssid, however it is not allowed in assocreq */ 1271 if (!p || ie_len == 0) {
1272 /* broadcast ssid, however it is not allowed in assocreq */
1275 status = _STATS_FAILURE_; 1273 status = _STATS_FAILURE_;
1276 else { 1274 goto OnAssocReqFail;
1275 } else {
1277 /* check if ssid match */ 1276 /* check if ssid match */
1278 if (memcmp((void *)(p+2), cur->Ssid.Ssid, cur->Ssid.SsidLength)) 1277 if (memcmp((void *)(p+2), cur->Ssid.Ssid, cur->Ssid.SsidLength))
1279 status = _STATS_FAILURE_; 1278 status = _STATS_FAILURE_;
@@ -3796,7 +3795,7 @@ int issue_deauth_ex(struct adapter *padapter, u8 *da, unsigned short reason, int
3796 break; 3795 break;
3797 3796
3798 if (i < try_cnt && wait_ms > 0 && ret == _FAIL) 3797 if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
3799 msleep(wait_ms); 3798 mdelay(wait_ms);
3800 3799
3801 } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0))); 3800 } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0)));
3802 3801
diff --git a/drivers/staging/rtl8723bs/core/rtw_pwrctrl.c b/drivers/staging/rtl8723bs/core/rtw_pwrctrl.c
index 110bbe340b78..59a667753266 100644
--- a/drivers/staging/rtl8723bs/core/rtw_pwrctrl.c
+++ b/drivers/staging/rtl8723bs/core/rtw_pwrctrl.c
@@ -1232,7 +1232,7 @@ int _rtw_pwr_wakeup(struct adapter *padapter, u32 ips_deffer_ms, const char *cal
1232 if (pwrpriv->ps_processing) { 1232 if (pwrpriv->ps_processing) {
1233 DBG_871X("%s wait ps_processing...\n", __func__); 1233 DBG_871X("%s wait ps_processing...\n", __func__);
1234 while (pwrpriv->ps_processing && jiffies_to_msecs(jiffies - start) <= 3000) 1234 while (pwrpriv->ps_processing && jiffies_to_msecs(jiffies - start) <= 3000)
1235 msleep(10); 1235 mdelay(10);
1236 if (pwrpriv->ps_processing) 1236 if (pwrpriv->ps_processing)
1237 DBG_871X("%s wait ps_processing timeout\n", __func__); 1237 DBG_871X("%s wait ps_processing timeout\n", __func__);
1238 else 1238 else
@@ -1244,7 +1244,7 @@ int _rtw_pwr_wakeup(struct adapter *padapter, u32 ips_deffer_ms, const char *cal
1244 while (pwrpriv->bInSuspend 1244 while (pwrpriv->bInSuspend
1245 && jiffies_to_msecs(jiffies - start) <= 3000 1245 && jiffies_to_msecs(jiffies - start) <= 3000
1246 ) { 1246 ) {
1247 msleep(10); 1247 mdelay(10);
1248 } 1248 }
1249 if (pwrpriv->bInSuspend) 1249 if (pwrpriv->bInSuspend)
1250 DBG_871X("%s wait bInSuspend timeout\n", __func__); 1250 DBG_871X("%s wait bInSuspend timeout\n", __func__);
diff --git a/drivers/staging/rtl8723bs/core/rtw_security.c b/drivers/staging/rtl8723bs/core/rtw_security.c
index 6c8ac9e86c9f..240818b4a2c9 100644
--- a/drivers/staging/rtl8723bs/core/rtw_security.c
+++ b/drivers/staging/rtl8723bs/core/rtw_security.c
@@ -1543,7 +1543,7 @@ u32 rtw_aes_encrypt(struct adapter *padapter, u8 *pxmitframe)
1543 pframe = ((struct xmit_frame *)pxmitframe)->buf_addr + hw_hdr_offset; 1543 pframe = ((struct xmit_frame *)pxmitframe)->buf_addr + hw_hdr_offset;
1544 1544
1545 /* 4 start to encrypt each fragment */ 1545 /* 4 start to encrypt each fragment */
1546 if ((pattrib->encrypt == _AES_)) { 1546 if (pattrib->encrypt == _AES_) {
1547 RT_TRACE(_module_rtl871x_security_c_, _drv_err_, ("rtw_aes_encrypt: stainfo!= NULL!!!\n")); 1547 RT_TRACE(_module_rtl871x_security_c_, _drv_err_, ("rtw_aes_encrypt: stainfo!= NULL!!!\n"));
1548 1548
1549 if (IS_MCAST(pattrib->ra)) 1549 if (IS_MCAST(pattrib->ra))
@@ -1866,8 +1866,7 @@ u32 rtw_aes_decrypt(struct adapter *padapter, u8 *precvframe)
1866 1866
1867 pframe = (unsigned char *)((union recv_frame *)precvframe)->u.hdr.rx_data; 1867 pframe = (unsigned char *)((union recv_frame *)precvframe)->u.hdr.rx_data;
1868 /* 4 start to encrypt each fragment */ 1868 /* 4 start to encrypt each fragment */
1869 if ((prxattrib->encrypt == _AES_)) { 1869 if (prxattrib->encrypt == _AES_) {
1870
1871 stainfo = rtw_get_stainfo(&padapter->stapriv, &prxattrib->ta[0]); 1870 stainfo = rtw_get_stainfo(&padapter->stapriv, &prxattrib->ta[0]);
1872 if (stainfo != NULL) { 1871 if (stainfo != NULL) {
1873 RT_TRACE(_module_rtl871x_security_c_, _drv_err_, ("rtw_aes_decrypt: stainfo!= NULL!!!\n")); 1872 RT_TRACE(_module_rtl871x_security_c_, _drv_err_, ("rtw_aes_decrypt: stainfo!= NULL!!!\n"));
diff --git a/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c b/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c
index 0d2c61b67d0e..12c1cd590056 100644
--- a/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c
+++ b/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c
@@ -2919,7 +2919,6 @@ int PHY_ConfigRFWithTxPwrTrackParaFile(struct adapter *Adapter, char *pFileName)
2919 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); 2919 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
2920 int rlen = 0, rtStatus = _FAIL; 2920 int rlen = 0, rtStatus = _FAIL;
2921 char *szLine, *ptmp; 2921 char *szLine, *ptmp;
2922 u32 i = 0;
2923 2922
2924 if (!(Adapter->registrypriv.load_phy_file & LOAD_RF_TXPWR_TRACK_PARA_FILE)) 2923 if (!(Adapter->registrypriv.load_phy_file & LOAD_RF_TXPWR_TRACK_PARA_FILE))
2925 return rtStatus; 2924 return rtStatus;
@@ -2958,8 +2957,10 @@ int PHY_ConfigRFWithTxPwrTrackParaFile(struct adapter *Adapter, char *pFileName)
2958 char band[5] = "", path[5] = "", sign[5] = ""; 2957 char band[5] = "", path[5] = "", sign[5] = "";
2959 char chnl[5] = "", rate[10] = ""; 2958 char chnl[5] = "", rate[10] = "";
2960 char data[300] = ""; /* 100 is too small */ 2959 char data[300] = ""; /* 100 is too small */
2960 const int len = strlen(szLine);
2961 int i;
2961 2962
2962 if (strlen(szLine) < 10 || szLine[0] != '[') 2963 if (len < 10 || szLine[0] != '[')
2963 continue; 2964 continue;
2964 2965
2965 strncpy(band, szLine+1, 2); 2966 strncpy(band, szLine+1, 2);
@@ -2973,7 +2974,7 @@ int PHY_ConfigRFWithTxPwrTrackParaFile(struct adapter *Adapter, char *pFileName)
2973 if (!ParseQualifiedString(szLine, &i, chnl, '[', ']')) { 2974 if (!ParseQualifiedString(szLine, &i, chnl, '[', ']')) {
2974 /* DBG_871X("Fail to parse channel group!\n"); */ 2975 /* DBG_871X("Fail to parse channel group!\n"); */
2975 } 2976 }
2976 while (szLine[i] != '{' && i < strlen(szLine)) 2977 while (i < len && szLine[i] != '{')
2977 i++; 2978 i++;
2978 if (!ParseQualifiedString(szLine, &i, data, '{', '}')) { 2979 if (!ParseQualifiedString(szLine, &i, data, '{', '}')) {
2979 /* DBG_871X("Fail to parse data!\n"); */ 2980 /* DBG_871X("Fail to parse data!\n"); */
@@ -3083,7 +3084,7 @@ static int phy_ParsePowerLimitTableFile(struct adapter *Adapter, char *buffer)
3083 3084
3084 if (colNum > TXPWR_LMT_MAX_REGULATION_NUM) { 3085 if (colNum > TXPWR_LMT_MAX_REGULATION_NUM) {
3085 DBG_871X( 3086 DBG_871X(
3086 "unvalid col number %d (greater than max %d)\n", 3087 "invalid col number %d (greater than max %d)\n",
3087 colNum, TXPWR_LMT_MAX_REGULATION_NUM 3088 colNum, TXPWR_LMT_MAX_REGULATION_NUM
3088 ); 3089 );
3089 return _FAIL; 3090 return _FAIL;
@@ -3101,7 +3102,7 @@ static int phy_ParsePowerLimitTableFile(struct adapter *Adapter, char *buffer)
3101 /* DBG_871X("regulation %s!\n", regulation[forCnt]); */ 3102 /* DBG_871X("regulation %s!\n", regulation[forCnt]); */
3102 3103
3103 if (regulation_name_cnt == 0) { 3104 if (regulation_name_cnt == 0) {
3104 DBG_871X("unvalid number of regulation!\n"); 3105 DBG_871X("invalid number of regulation!\n");
3105 return _FAIL; 3106 return _FAIL;
3106 } 3107 }
3107 } 3108 }
diff --git a/drivers/staging/rtl8723bs/hal/odm_DIG.c b/drivers/staging/rtl8723bs/hal/odm_DIG.c
index a12fdce77eae..4fa6cd315cf7 100644
--- a/drivers/staging/rtl8723bs/hal/odm_DIG.c
+++ b/drivers/staging/rtl8723bs/hal/odm_DIG.c
@@ -655,7 +655,7 @@ void odm_DIG(void *pDM_VOID)
655 ODM_COMP_DIG, 655 ODM_COMP_DIG,
656 ODM_DBG_LOUD, 656 ODM_DBG_LOUD,
657 ( 657 (
658 "odm_DIG(): Abnrormal #beacon (%d) case in STA mode: Force lower bound to 0x%x !!!!!!\n\n", 658 "odm_DIG(): Abnormal #beacon (%d) case in STA mode: Force lower bound to 0x%x !!!!!!\n\n",
659 pDM_Odm->PhyDbgInfo.NumQryBeaconPkt, 659 pDM_Odm->PhyDbgInfo.NumQryBeaconPkt,
660 pDM_DigTable->rx_gain_range_min 660 pDM_DigTable->rx_gain_range_min
661 ) 661 )
@@ -671,7 +671,7 @@ void odm_DIG(void *pDM_VOID)
671 ODM_COMP_DIG, 671 ODM_COMP_DIG,
672 ODM_DBG_LOUD, 672 ODM_DBG_LOUD,
673 ( 673 (
674 "odm_DIG(): Abnrormal lower bound case: Force lower bound to 0x%x !!!!!!\n\n", 674 "odm_DIG(): Abnormal lower bound case: Force lower bound to 0x%x !!!!!!\n\n",
675 pDM_DigTable->rx_gain_range_min 675 pDM_DigTable->rx_gain_range_min
676 ) 676 )
677 ); 677 );
diff --git a/drivers/staging/rtl8723bs/hal/odm_EdcaTurboCheck.c b/drivers/staging/rtl8723bs/hal/odm_EdcaTurboCheck.c
index acc64fa8f166..0e674f39ef03 100644
--- a/drivers/staging/rtl8723bs/hal/odm_EdcaTurboCheck.c
+++ b/drivers/staging/rtl8723bs/hal/odm_EdcaTurboCheck.c
@@ -97,7 +97,7 @@ void odm_EdcaTurboCheckCE(void *pDM_VOID)
97 return; 97 return;
98 } 98 }
99 99
100 if ((pregpriv->wifi_spec == 1)) { 100 if (pregpriv->wifi_spec == 1) {
101 precvpriv->bIsAnyNonBEPkts = false; 101 precvpriv->bIsAnyNonBEPkts = false;
102 return; 102 return;
103 } 103 }
diff --git a/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c b/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c
index 592917fc00aa..c7e55618b9a8 100644
--- a/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c
+++ b/drivers/staging/rtl8723bs/hal/rtl8723b_hal_init.c
@@ -3348,7 +3348,7 @@ static void hw_var_set_opmode(struct adapter *padapter, u8 variable, u8 *val)
3348 /* disable atim wnd */ 3348 /* disable atim wnd */
3349 rtw_write8(padapter, REG_BCN_CTRL, DIS_TSF_UDT|EN_BCN_FUNCTION|DIS_ATIM); 3349 rtw_write8(padapter, REG_BCN_CTRL, DIS_TSF_UDT|EN_BCN_FUNCTION|DIS_ATIM);
3350 /* rtw_write8(padapter, REG_BCN_CTRL, 0x18); */ 3350 /* rtw_write8(padapter, REG_BCN_CTRL, 0x18); */
3351 } else if ((mode == _HW_STATE_ADHOC_) /*|| (mode == _HW_STATE_AP_)*/) { 3351 } else if (mode == _HW_STATE_ADHOC_) {
3352 ResumeTxBeacon(padapter); 3352 ResumeTxBeacon(padapter);
3353 rtw_write8(padapter, REG_BCN_CTRL, DIS_TSF_UDT|EN_BCN_FUNCTION|DIS_BCNQ_SUB); 3353 rtw_write8(padapter, REG_BCN_CTRL, DIS_TSF_UDT|EN_BCN_FUNCTION|DIS_BCNQ_SUB);
3354 } else if (mode == _HW_STATE_AP_) { 3354 } else if (mode == _HW_STATE_AP_) {
diff --git a/drivers/staging/rtl8723bs/include/drv_types.h b/drivers/staging/rtl8723bs/include/drv_types.h
index c57f290f605a..062fda9962be 100644
--- a/drivers/staging/rtl8723bs/include/drv_types.h
+++ b/drivers/staging/rtl8723bs/include/drv_types.h
@@ -381,7 +381,7 @@ struct debug_priv {
381 u32 dbg_enwow_dload_fw_fail_cnt; 381 u32 dbg_enwow_dload_fw_fail_cnt;
382 u32 dbg_ips_drvopen_fail_cnt; 382 u32 dbg_ips_drvopen_fail_cnt;
383 u32 dbg_poll_fail_cnt; 383 u32 dbg_poll_fail_cnt;
384 u32 dbg_rpwm_toogle_cnt; 384 u32 dbg_rpwm_toggle_cnt;
385 u32 dbg_rpwm_timeout_fail_cnt; 385 u32 dbg_rpwm_timeout_fail_cnt;
386 u64 dbg_rx_fifo_last_overflow; 386 u64 dbg_rx_fifo_last_overflow;
387 u64 dbg_rx_fifo_curr_overflow; 387 u64 dbg_rx_fifo_curr_overflow;
diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
index c38298d960ff..28bfdbdc6e76 100644
--- a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
+++ b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
@@ -209,9 +209,9 @@ static char *translate_scan(struct adapter *padapter,
209 i++; 209 i++;
210 } 210 }
211 211
212 if (vht_cap == true) { 212 if (vht_cap) {
213 max_rate = vht_data_rate; 213 max_rate = vht_data_rate;
214 } else if (ht_cap == true) { 214 } else if (ht_cap) {
215 if (mcs_rate&0x8000) { /* MCS15 */ 215 if (mcs_rate&0x8000) { /* MCS15 */
216 max_rate = (bw_40MHz) ? ((short_GI)?300:270):((short_GI)?144:130); 216 max_rate = (bw_40MHz) ? ((short_GI)?300:270):((short_GI)?144:130);
217 } else if (mcs_rate&0x0080) { /* MCS7 */ 217 } else if (mcs_rate&0x0080) { /* MCS7 */
@@ -337,7 +337,7 @@ static char *translate_scan(struct adapter *padapter,
337 337
338 338
339 #ifdef CONFIG_SIGNAL_DISPLAY_DBM 339 #ifdef CONFIG_SIGNAL_DISPLAY_DBM
340 iwe.u.qual.level = (u8) translate_percentage_to_dbm(ss);/* dbm */ 340 iwe.u.qual.level = (u8)translate_percentage_to_dbm(ss);/* dbm */
341 #else 341 #else
342 #ifdef CONFIG_SKIP_SIGNAL_SCALE_MAPPING 342 #ifdef CONFIG_SKIP_SIGNAL_SCALE_MAPPING
343 { 343 {
@@ -392,7 +392,7 @@ exit:
392 392
393static int wpa_set_auth_algs(struct net_device *dev, u32 value) 393static int wpa_set_auth_algs(struct net_device *dev, u32 value)
394{ 394{
395 struct adapter *padapter = (struct adapter *) rtw_netdev_priv(dev); 395 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
396 int ret = 0; 396 int ret = 0;
397 397
398 if ((value & WLAN_AUTH_SHARED_KEY) && (value & WLAN_AUTH_OPEN)) { 398 if ((value & WLAN_AUTH_SHARED_KEY) && (value & WLAN_AUTH_OPEN)) {
@@ -436,7 +436,7 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
436 param->u.crypt.err = 0; 436 param->u.crypt.err = 0;
437 param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0'; 437 param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
438 438
439 if (param_len < (u32) ((u8 *) param->u.crypt.key - (u8 *) param) + param->u.crypt.key_len) { 439 if (param_len < (u32)((u8 *)param->u.crypt.key - (u8 *)param) + param->u.crypt.key_len) {
440 ret = -EINVAL; 440 ret = -EINVAL;
441 goto exit; 441 goto exit;
442 } 442 }
@@ -528,8 +528,8 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
528 } 528 }
529 529
530 if (padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) { /* 802_1x */ 530 if (padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) { /* 802_1x */
531 struct sta_info * psta,*pbcmc_sta; 531 struct sta_info *psta, *pbcmc_sta;
532 struct sta_priv * pstapriv = &padapter->stapriv; 532 struct sta_priv *pstapriv = &padapter->stapriv;
533 533
534 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_MP_STATE) == true) { /* sta mode */ 534 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_MP_STATE) == true) { /* sta mode */
535 psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv)); 535 psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv));
@@ -862,7 +862,7 @@ static int rtw_wx_set_mode(struct net_device *dev, struct iw_request_info *a,
862 goto exit; 862 goto exit;
863 } 863 }
864 864
865 if (padapter->hw_init_completed ==false) { 865 if (!padapter->hw_init_completed) {
866 ret = -EPERM; 866 ret = -EPERM;
867 goto exit; 867 goto exit;
868 } 868 }
@@ -946,7 +946,7 @@ static int rtw_wx_set_pmkid(struct net_device *dev,
946 u8 j, blInserted = false; 946 u8 j, blInserted = false;
947 int intReturn = false; 947 int intReturn = false;
948 struct security_priv *psecuritypriv = &padapter->securitypriv; 948 struct security_priv *psecuritypriv = &padapter->securitypriv;
949 struct iw_pmksa* pPMK = (struct iw_pmksa*) extra; 949 struct iw_pmksa* pPMK = (struct iw_pmksa*)extra;
950 u8 strZeroMacAddress[ ETH_ALEN ] = { 0x00 }; 950 u8 strZeroMacAddress[ ETH_ALEN ] = { 0x00 };
951 u8 strIssueBssid[ ETH_ALEN ] = { 0x00 }; 951 u8 strIssueBssid[ ETH_ALEN ] = { 0x00 };
952 952
@@ -1236,7 +1236,7 @@ static int rtw_wx_set_mlme(struct net_device *dev,
1236 int ret = 0; 1236 int ret = 0;
1237 u16 reason; 1237 u16 reason;
1238 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); 1238 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1239 struct iw_mlme *mlme = (struct iw_mlme *) extra; 1239 struct iw_mlme *mlme = (struct iw_mlme *)extra;
1240 1240
1241 1241
1242 if (mlme == NULL) 1242 if (mlme == NULL)
@@ -1295,7 +1295,7 @@ static int rtw_wx_set_scan(struct net_device *dev, struct iw_request_info *a,
1295 goto exit; 1295 goto exit;
1296 } 1296 }
1297 1297
1298 if (padapter->hw_init_completed ==false) { 1298 if (!padapter->hw_init_completed ) {
1299 ret = -1; 1299 ret = -1;
1300 goto exit; 1300 goto exit;
1301 } 1301 }
@@ -1303,7 +1303,7 @@ static int rtw_wx_set_scan(struct net_device *dev, struct iw_request_info *a,
1303 /* When Busy Traffic, driver do not site survey. So driver return success. */ 1303 /* When Busy Traffic, driver do not site survey. So driver return success. */
1304 /* wpa_supplicant will not issue SIOCSIWSCAN cmd again after scan timeout. */ 1304 /* wpa_supplicant will not issue SIOCSIWSCAN cmd again after scan timeout. */
1305 /* modify by thomas 2011-02-22. */ 1305 /* modify by thomas 2011-02-22. */
1306 if (pmlmepriv->LinkDetectInfo.bBusyTraffic == true) { 1306 if (pmlmepriv->LinkDetectInfo.bBusyTraffic) {
1307 indicate_wx_scan_complete_event(padapter); 1307 indicate_wx_scan_complete_event(padapter);
1308 goto exit; 1308 goto exit;
1309 } 1309 }
@@ -2390,7 +2390,7 @@ static int rtw_wx_set_channel_plan(struct net_device *dev,
2390 union iwreq_data *wrqu, char *extra) 2390 union iwreq_data *wrqu, char *extra)
2391{ 2391{
2392 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); 2392 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2393 u8 channel_plan_req = (u8) (*((int *)wrqu)); 2393 u8 channel_plan_req = (u8)(*((int *)wrqu));
2394 2394
2395 if (_SUCCESS == rtw_set_chplan_cmd(padapter, channel_plan_req, 1, 1)) 2395 if (_SUCCESS == rtw_set_chplan_cmd(padapter, channel_plan_req, 1, 1))
2396 DBG_871X("%s set channel_plan = 0x%02X\n", __func__, channel_plan_req); 2396 DBG_871X("%s set channel_plan = 0x%02X\n", __func__, channel_plan_req);
@@ -2584,7 +2584,7 @@ static int rtw_wps_start(struct net_device *dev,
2584 goto exit; 2584 goto exit;
2585 } 2585 }
2586 2586
2587 uintRet = copy_from_user((void*) &u32wps_start, pdata->pointer, 4); 2587 uintRet = copy_from_user((void*)&u32wps_start, pdata->pointer, 4);
2588 if (u32wps_start == 0) 2588 if (u32wps_start == 0)
2589 u32wps_start = *extra; 2589 u32wps_start = *extra;
2590 2590
@@ -4229,7 +4229,7 @@ static int rtw_hostapd_ioctl(struct net_device *dev, struct iw_point *p)
4229 * so, we just check hw_init_completed 4229 * so, we just check hw_init_completed
4230 */ 4230 */
4231 4231
4232 if (padapter->hw_init_completed ==false) { 4232 if (!padapter->hw_init_completed) {
4233 ret = -EPERM; 4233 ret = -EPERM;
4234 goto out; 4234 goto out;
4235 } 4235 }
diff --git a/drivers/staging/rtl8723bs/os_dep/sdio_intf.c b/drivers/staging/rtl8723bs/os_dep/sdio_intf.c
index 6d02904de63f..7c03b69b8ed3 100644
--- a/drivers/staging/rtl8723bs/os_dep/sdio_intf.c
+++ b/drivers/staging/rtl8723bs/os_dep/sdio_intf.c
@@ -22,7 +22,7 @@ static const struct sdio_device_id sdio_ids[] =
22 { SDIO_DEVICE(0x024c, 0xb723), }, 22 { SDIO_DEVICE(0x024c, 0xb723), },
23 { /* end: all zeroes */ }, 23 { /* end: all zeroes */ },
24}; 24};
25static const struct acpi_device_id acpi_ids[] = { 25static const struct acpi_device_id acpi_ids[] __used = {
26 {"OBDA8723", 0x0000}, 26 {"OBDA8723", 0x0000},
27 {} 27 {}
28}; 28};
diff --git a/drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.c b/drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.c
index 4d1f9bf53c53..24e19ffd4431 100644
--- a/drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.c
+++ b/drivers/staging/rtlwifi/btcoexist/halbtcoutsrc.c
@@ -281,11 +281,9 @@ bool halbtc_send_bt_mp_operation(struct btc_coexist *btcoexist, u8 op_code,
281static void halbtc_leave_lps(struct btc_coexist *btcoexist) 281static void halbtc_leave_lps(struct btc_coexist *btcoexist)
282{ 282{
283 struct rtl_priv *rtlpriv; 283 struct rtl_priv *rtlpriv;
284 struct rtl_ps_ctl *ppsc;
285 bool ap_enable = false; 284 bool ap_enable = false;
286 285
287 rtlpriv = btcoexist->adapter; 286 rtlpriv = btcoexist->adapter;
288 ppsc = rtl_psc(rtlpriv);
289 287
290 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, 288 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
291 &ap_enable); 289 &ap_enable);
@@ -304,11 +302,9 @@ static void halbtc_leave_lps(struct btc_coexist *btcoexist)
304static void halbtc_enter_lps(struct btc_coexist *btcoexist) 302static void halbtc_enter_lps(struct btc_coexist *btcoexist)
305{ 303{
306 struct rtl_priv *rtlpriv; 304 struct rtl_priv *rtlpriv;
307 struct rtl_ps_ctl *ppsc;
308 bool ap_enable = false; 305 bool ap_enable = false;
309 306
310 rtlpriv = btcoexist->adapter; 307 rtlpriv = btcoexist->adapter;
311 ppsc = rtl_psc(rtlpriv);
312 308
313 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, 309 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
314 &ap_enable); 310 &ap_enable);
@@ -1261,13 +1257,13 @@ bool exhalbtc_initlize_variables_wifi_only(struct rtl_priv *rtlpriv)
1261 1257
1262 switch (rtlpriv->rtlhal.interface) { 1258 switch (rtlpriv->rtlhal.interface) {
1263 case INTF_PCI: 1259 case INTF_PCI:
1264 wifionly_cfg->chip_interface = BTC_INTF_PCI; 1260 wifionly_cfg->chip_interface = WIFIONLY_INTF_PCI;
1265 break; 1261 break;
1266 case INTF_USB: 1262 case INTF_USB:
1267 wifionly_cfg->chip_interface = BTC_INTF_USB; 1263 wifionly_cfg->chip_interface = WIFIONLY_INTF_USB;
1268 break; 1264 break;
1269 default: 1265 default:
1270 wifionly_cfg->chip_interface = BTC_INTF_UNKNOWN; 1266 wifionly_cfg->chip_interface = WIFIONLY_INTF_UNKNOWN;
1271 break; 1267 break;
1272 } 1268 }
1273 1269
diff --git a/drivers/staging/rtlwifi/efuse.c b/drivers/staging/rtlwifi/efuse.c
index 1dc71455f270..abb0f720cf21 100644
--- a/drivers/staging/rtlwifi/efuse.c
+++ b/drivers/staging/rtlwifi/efuse.c
@@ -245,7 +245,8 @@ void read_efuse(struct ieee80211_hw *hw, u16 _offset, u16 _size_byte, u8 *pbuf)
245 if (!efuse_word) 245 if (!efuse_word)
246 goto out; 246 goto out;
247 for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++) { 247 for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++) {
248 efuse_word[i] = kcalloc(efuse_max_section, sizeof(u16), GFP_ATOMIC); 248 efuse_word[i] = kcalloc(efuse_max_section, sizeof(u16),
249 GFP_ATOMIC);
249 if (!efuse_word[i]) 250 if (!efuse_word[i])
250 goto done; 251 goto done;
251 } 252 }
diff --git a/drivers/staging/rtlwifi/halmac/rtl_halmac.c b/drivers/staging/rtlwifi/halmac/rtl_halmac.c
index f0c6fc8c6aca..7bfc9620479a 100644
--- a/drivers/staging/rtlwifi/halmac/rtl_halmac.c
+++ b/drivers/staging/rtlwifi/halmac/rtl_halmac.c
@@ -209,7 +209,7 @@ static int init_halmac_event_with_waittime(struct rtl_priv *rtlpriv,
209 if (!rtlpriv->halmac.indicator[id].comp) { 209 if (!rtlpriv->halmac.indicator[id].comp) {
210 comp = kzalloc(sizeof(*comp), GFP_KERNEL); 210 comp = kzalloc(sizeof(*comp), GFP_KERNEL);
211 if (!comp) 211 if (!comp)
212 return -1; 212 return -ENOMEM;
213 } else { 213 } else {
214 RT_TRACE(rtlpriv, COMP_HALMAC, DBG_LOUD, 214 RT_TRACE(rtlpriv, COMP_HALMAC, DBG_LOUD,
215 "%s: <WARN> id(%d) sctx is not NULL!!\n", __func__, 215 "%s: <WARN> id(%d) sctx is not NULL!!\n", __func__,
@@ -359,7 +359,7 @@ static int init_priv(struct rtl_halmac *halmac)
359 size = sizeof(*indicator) * count; 359 size = sizeof(*indicator) * count;
360 indicator = kzalloc(size, GFP_KERNEL); 360 indicator = kzalloc(size, GFP_KERNEL);
361 if (!indicator) 361 if (!indicator)
362 return -1; 362 return -ENOMEM;
363 halmac->indicator = indicator; 363 halmac->indicator = indicator;
364 364
365 return 0; 365 return 0;
diff --git a/drivers/staging/rtlwifi/phydm/phydm_adc_sampling.c b/drivers/staging/rtlwifi/phydm/phydm_adc_sampling.c
index 42020101380a..d6cea73fa185 100644
--- a/drivers/staging/rtlwifi/phydm/phydm_adc_sampling.c
+++ b/drivers/staging/rtlwifi/phydm/phydm_adc_sampling.c
@@ -555,7 +555,7 @@ void phydm_lamode_trigger_setting(void *dm_void, char input[][16], u32 *_used,
555 output + used, out_len - used, 555 output + used, out_len - used,
556 "{En} {0:BB,1:BB_MAC,2:RF0,3:RF1,4:MAC}\n {BB:dbg_port[bit],BB_MAC:0-ok/1-fail/2-cca,MAC:ref} {DMA type} {TrigTime}\n {polling_time/ref_mask} {dbg_port} {0:P_Edge, 1:N_Edge} {SpRate:0-80M,1-40M,2-20M} {Capture num}\n"); 556 "{En} {0:BB,1:BB_MAC,2:RF0,3:RF1,4:MAC}\n {BB:dbg_port[bit],BB_MAC:0-ok/1-fail/2-cca,MAC:ref} {DMA type} {TrigTime}\n {polling_time/ref_mask} {dbg_port} {0:P_Edge, 1:N_Edge} {SpRate:0-80M,1-40M,2-20M} {Capture num}\n");
557 /**/ 557 /**/
558 } else if ((is_enable_la_mode == 1)) { 558 } else if (is_enable_la_mode == 1) {
559 PHYDM_SSCANF(input[2], DCMD_DECIMAL, &var1[1]); 559 PHYDM_SSCANF(input[2], DCMD_DECIMAL, &var1[1]);
560 560
561 trig_mode = (u8)var1[1]; 561 trig_mode = (u8)var1[1];
diff --git a/drivers/staging/rtlwifi/phydm/phydm_dig.c b/drivers/staging/rtlwifi/phydm/phydm_dig.c
index 3115e7bdc749..f10776fbe2d9 100644
--- a/drivers/staging/rtlwifi/phydm/phydm_dig.c
+++ b/drivers/staging/rtlwifi/phydm/phydm_dig.c
@@ -813,7 +813,7 @@ void odm_DIG(void *dm_void)
813 dig_tab->rx_gain_range_min = 0x1c; 813 dig_tab->rx_gain_range_min = 0x1c;
814 ODM_RT_TRACE( 814 ODM_RT_TRACE(
815 dm, ODM_COMP_DIG, 815 dm, ODM_COMP_DIG,
816 "DIG: Abnrormal #beacon (%d) case in STA mode: Force lower bound to 0x%x\n", 816 "DIG: Abnormal #beacon (%d) case in STA mode: Force lower bound to 0x%x\n",
817 dm->phy_dbg_info.num_qry_beacon_pkt, 817 dm->phy_dbg_info.num_qry_beacon_pkt,
818 dig_tab->rx_gain_range_min); 818 dig_tab->rx_gain_range_min);
819 } 819 }
@@ -824,7 +824,7 @@ void odm_DIG(void *dm_void)
824 dig_tab->rx_gain_range_min = dig_tab->rx_gain_range_max; 824 dig_tab->rx_gain_range_min = dig_tab->rx_gain_range_max;
825 ODM_RT_TRACE( 825 ODM_RT_TRACE(
826 dm, ODM_COMP_DIG, 826 dm, ODM_COMP_DIG,
827 "DIG: Abnrormal lower bound case: Force lower bound to 0x%x\n", 827 "DIG: Abnormal lower bound case: Force lower bound to 0x%x\n",
828 dig_tab->rx_gain_range_min); 828 dig_tab->rx_gain_range_min);
829 } 829 }
830 830
diff --git a/drivers/staging/rtlwifi/regd.c b/drivers/staging/rtlwifi/regd.c
index 3afd206ce4b1..5213ca771175 100644
--- a/drivers/staging/rtlwifi/regd.c
+++ b/drivers/staging/rtlwifi/regd.c
@@ -410,7 +410,7 @@ int rtl_regd_init(struct ieee80211_hw *hw,
410 struct wiphy *wiphy = hw->wiphy; 410 struct wiphy *wiphy = hw->wiphy;
411 struct country_code_to_enum_rd *country = NULL; 411 struct country_code_to_enum_rd *country = NULL;
412 412
413 if (!wiphy || !&rtlpriv->regd) 413 if (!wiphy)
414 return -EINVAL; 414 return -EINVAL;
415 415
416 /* init country_code from efuse channel plan */ 416 /* init country_code from efuse channel plan */
diff --git a/drivers/staging/rtlwifi/wifi.h b/drivers/staging/rtlwifi/wifi.h
index a45f0eb69d3f..9cb6c7906213 100644
--- a/drivers/staging/rtlwifi/wifi.h
+++ b/drivers/staging/rtlwifi/wifi.h
@@ -1840,10 +1840,6 @@ struct rtl_efuse {
1840 u8 efuse_map[2][EFUSE_MAX_LOGICAL_SIZE]; 1840 u8 efuse_map[2][EFUSE_MAX_LOGICAL_SIZE];
1841 u16 efuse_usedbytes; 1841 u16 efuse_usedbytes;
1842 u8 efuse_usedpercentage; 1842 u8 efuse_usedpercentage;
1843#ifdef EFUSE_REPG_WORKAROUND
1844 bool efuse_re_pg_sec1flag;
1845 u8 efuse_re_pg_data[8];
1846#endif
1847 1843
1848 u8 autoload_failflag; 1844 u8 autoload_failflag;
1849 u8 autoload_status; 1845 u8 autoload_status;
diff --git a/drivers/staging/rts5208/ms.c b/drivers/staging/rts5208/ms.c
index 3a71dbb6d24a..f53adf15c685 100644
--- a/drivers/staging/rts5208/ms.c
+++ b/drivers/staging/rts5208/ms.c
@@ -111,9 +111,8 @@ static int ms_transfer_data(struct rtsx_chip *chip, u8 trans_mode,
111 u8 val, err_code = 0; 111 u8 val, err_code = 0;
112 enum dma_data_direction dir; 112 enum dma_data_direction dir;
113 113
114 if (!buf || !buf_len) { 114 if (!buf || !buf_len)
115 return STATUS_FAIL; 115 return STATUS_FAIL;
116 }
117 116
118 if (trans_mode == MS_TM_AUTO_READ) { 117 if (trans_mode == MS_TM_AUTO_READ) {
119 dir = DMA_FROM_DEVICE; 118 dir = DMA_FROM_DEVICE;
@@ -162,12 +161,11 @@ static int ms_transfer_data(struct rtsx_chip *chip, u8 trans_mode,
162 } 161 }
163 162
164 retval = rtsx_read_register(chip, MS_TRANS_CFG, &val); 163 retval = rtsx_read_register(chip, MS_TRANS_CFG, &val);
165 if (retval) { 164 if (retval)
166 return retval; 165 return retval;
167 } 166
168 if (val & (MS_INT_CMDNK | MS_INT_ERR | MS_CRC16_ERR | MS_RDY_TIMEOUT)) { 167 if (val & (MS_INT_CMDNK | MS_INT_ERR | MS_CRC16_ERR | MS_RDY_TIMEOUT))
169 return STATUS_FAIL; 168 return STATUS_FAIL;
170 }
171 169
172 return STATUS_SUCCESS; 170 return STATUS_SUCCESS;
173} 171}
@@ -178,9 +176,8 @@ static int ms_write_bytes(struct rtsx_chip *chip,
178 struct ms_info *ms_card = &chip->ms_card; 176 struct ms_info *ms_card = &chip->ms_card;
179 int retval, i; 177 int retval, i;
180 178
181 if (!data || (data_len < cnt)) { 179 if (!data || (data_len < cnt))
182 return STATUS_ERROR; 180 return STATUS_ERROR;
183 }
184 181
185 rtsx_init_cmd(chip); 182 rtsx_init_cmd(chip);
186 183
@@ -244,9 +241,8 @@ static int ms_read_bytes(struct rtsx_chip *chip,
244 int retval, i; 241 int retval, i;
245 u8 *ptr; 242 u8 *ptr;
246 243
247 if (!data) { 244 if (!data)
248 return STATUS_ERROR; 245 return STATUS_ERROR;
249 }
250 246
251 rtsx_init_cmd(chip); 247 rtsx_init_cmd(chip);
252 248
@@ -371,14 +367,12 @@ static int ms_set_init_para(struct rtsx_chip *chip)
371 } 367 }
372 368
373 retval = switch_clock(chip, ms_card->ms_clock); 369 retval = switch_clock(chip, ms_card->ms_clock);
374 if (retval != STATUS_SUCCESS) { 370 if (retval != STATUS_SUCCESS)
375 return STATUS_FAIL; 371 return STATUS_FAIL;
376 }
377 372
378 retval = select_card(chip, MS_CARD); 373 retval = select_card(chip, MS_CARD);
379 if (retval != STATUS_SUCCESS) { 374 if (retval != STATUS_SUCCESS)
380 return STATUS_FAIL; 375 return STATUS_FAIL;
381 }
382 376
383 return STATUS_SUCCESS; 377 return STATUS_SUCCESS;
384} 378}
@@ -389,14 +383,12 @@ static int ms_switch_clock(struct rtsx_chip *chip)
389 int retval; 383 int retval;
390 384
391 retval = select_card(chip, MS_CARD); 385 retval = select_card(chip, MS_CARD);
392 if (retval != STATUS_SUCCESS) { 386 if (retval != STATUS_SUCCESS)
393 return STATUS_FAIL; 387 return STATUS_FAIL;
394 }
395 388
396 retval = switch_clock(chip, ms_card->ms_clock); 389 retval = switch_clock(chip, ms_card->ms_clock);
397 if (retval != STATUS_SUCCESS) { 390 if (retval != STATUS_SUCCESS)
398 return STATUS_FAIL; 391 return STATUS_FAIL;
399 }
400 392
401 return STATUS_SUCCESS; 393 return STATUS_SUCCESS;
402} 394}
@@ -409,60 +401,59 @@ static int ms_pull_ctl_disable(struct rtsx_chip *chip)
409 retval = rtsx_write_register(chip, CARD_PULL_CTL1, 0xFF, 401 retval = rtsx_write_register(chip, CARD_PULL_CTL1, 0xFF,
410 MS_D1_PD | MS_D2_PD | MS_CLK_PD | 402 MS_D1_PD | MS_D2_PD | MS_CLK_PD |
411 MS_D6_PD); 403 MS_D6_PD);
412 if (retval) { 404 if (retval)
413 return retval; 405 return retval;
414 } 406
415 retval = rtsx_write_register(chip, CARD_PULL_CTL2, 0xFF, 407 retval = rtsx_write_register(chip, CARD_PULL_CTL2, 0xFF,
416 MS_D3_PD | MS_D0_PD | MS_BS_PD | 408 MS_D3_PD | MS_D0_PD | MS_BS_PD |
417 XD_D4_PD); 409 XD_D4_PD);
418 if (retval) { 410 if (retval)
419 return retval; 411 return retval;
420 } 412
421 retval = rtsx_write_register(chip, CARD_PULL_CTL3, 0xFF, 413 retval = rtsx_write_register(chip, CARD_PULL_CTL3, 0xFF,
422 MS_D7_PD | XD_CE_PD | XD_CLE_PD | 414 MS_D7_PD | XD_CE_PD | XD_CLE_PD |
423 XD_CD_PU); 415 XD_CD_PU);
424 if (retval) { 416 if (retval)
425 return retval; 417 return retval;
426 } 418
427 retval = rtsx_write_register(chip, CARD_PULL_CTL4, 0xFF, 419 retval = rtsx_write_register(chip, CARD_PULL_CTL4, 0xFF,
428 XD_RDY_PD | SD_D3_PD | SD_D2_PD | 420 XD_RDY_PD | SD_D3_PD | SD_D2_PD |
429 XD_ALE_PD); 421 XD_ALE_PD);
430 if (retval) { 422 if (retval)
431 return retval; 423 return retval;
432 } 424
433 retval = rtsx_write_register(chip, CARD_PULL_CTL5, 0xFF, 425 retval = rtsx_write_register(chip, CARD_PULL_CTL5, 0xFF,
434 MS_INS_PU | SD_WP_PD | SD_CD_PU | 426 MS_INS_PU | SD_WP_PD | SD_CD_PU |
435 SD_CMD_PD); 427 SD_CMD_PD);
436 if (retval) { 428 if (retval)
437 return retval; 429 return retval;
438 } 430
439 retval = rtsx_write_register(chip, CARD_PULL_CTL6, 0xFF, 431 retval = rtsx_write_register(chip, CARD_PULL_CTL6, 0xFF,
440 MS_D5_PD | MS_D4_PD); 432 MS_D5_PD | MS_D4_PD);
441 if (retval) { 433 if (retval)
442 return retval; 434 return retval;
443 } 435
444 } else if (CHECK_PID(chip, 0x5288)) { 436 } else if (CHECK_PID(chip, 0x5288)) {
445 if (CHECK_BARO_PKG(chip, QFN)) { 437 if (CHECK_BARO_PKG(chip, QFN)) {
446 retval = rtsx_write_register(chip, CARD_PULL_CTL1, 438 retval = rtsx_write_register(chip, CARD_PULL_CTL1,
447 0xFF, 0x55); 439 0xFF, 0x55);
448 if (retval) { 440 if (retval)
449 return retval; 441 return retval;
450 } 442
451 retval = rtsx_write_register(chip, CARD_PULL_CTL2, 443 retval = rtsx_write_register(chip, CARD_PULL_CTL2,
452 0xFF, 0x55); 444 0xFF, 0x55);
453 if (retval) { 445 if (retval)
454 return retval; 446 return retval;
455 } 447
456 retval = rtsx_write_register(chip, CARD_PULL_CTL3, 448 retval = rtsx_write_register(chip, CARD_PULL_CTL3,
457 0xFF, 0x4B); 449 0xFF, 0x4B);
458 if (retval) { 450 if (retval)
459 return retval; 451 return retval;
460 } 452
461 retval = rtsx_write_register(chip, CARD_PULL_CTL4, 453 retval = rtsx_write_register(chip, CARD_PULL_CTL4,
462 0xFF, 0x69); 454 0xFF, 0x69);
463 if (retval) { 455 if (retval)
464 return retval; 456 return retval;
465 }
466 } 457 }
467 } 458 }
468 459
@@ -502,9 +493,8 @@ static int ms_pull_ctl_enable(struct rtsx_chip *chip)
502 } 493 }
503 494
504 retval = rtsx_send_cmd(chip, MS_CARD, 100); 495 retval = rtsx_send_cmd(chip, MS_CARD, 100);
505 if (retval < 0) { 496 if (retval < 0)
506 return STATUS_FAIL; 497 return STATUS_FAIL;
507 }
508 498
509 return STATUS_SUCCESS; 499 return STATUS_SUCCESS;
510} 500}
@@ -523,36 +513,31 @@ static int ms_prepare_reset(struct rtsx_chip *chip)
523 ms_card->pro_under_formatting = 0; 513 ms_card->pro_under_formatting = 0;
524 514
525 retval = ms_power_off_card3v3(chip); 515 retval = ms_power_off_card3v3(chip);
526 if (retval != STATUS_SUCCESS) { 516 if (retval != STATUS_SUCCESS)
527 return STATUS_FAIL; 517 return STATUS_FAIL;
528 }
529 518
530 if (!chip->ft2_fast_mode) 519 if (!chip->ft2_fast_mode)
531 wait_timeout(250); 520 wait_timeout(250);
532 521
533 retval = enable_card_clock(chip, MS_CARD); 522 retval = enable_card_clock(chip, MS_CARD);
534 if (retval != STATUS_SUCCESS) { 523 if (retval != STATUS_SUCCESS)
535 return STATUS_FAIL; 524 return STATUS_FAIL;
536 }
537 525
538 if (chip->asic_code) { 526 if (chip->asic_code) {
539 retval = ms_pull_ctl_enable(chip); 527 retval = ms_pull_ctl_enable(chip);
540 if (retval != STATUS_SUCCESS) { 528 if (retval != STATUS_SUCCESS)
541 return STATUS_FAIL; 529 return STATUS_FAIL;
542 }
543 } else { 530 } else {
544 retval = rtsx_write_register(chip, FPGA_PULL_CTL, 531 retval = rtsx_write_register(chip, FPGA_PULL_CTL,
545 FPGA_MS_PULL_CTL_BIT | 0x20, 0); 532 FPGA_MS_PULL_CTL_BIT | 0x20, 0);
546 if (retval) { 533 if (retval)
547 return retval; 534 return retval;
548 }
549 } 535 }
550 536
551 if (!chip->ft2_fast_mode) { 537 if (!chip->ft2_fast_mode) {
552 retval = card_power_on(chip, MS_CARD); 538 retval = card_power_on(chip, MS_CARD);
553 if (retval != STATUS_SUCCESS) { 539 if (retval != STATUS_SUCCESS)
554 return STATUS_FAIL; 540 return STATUS_FAIL;
555 }
556 541
557 wait_timeout(150); 542 wait_timeout(150);
558 543
@@ -572,9 +557,8 @@ static int ms_prepare_reset(struct rtsx_chip *chip)
572 557
573 retval = rtsx_write_register(chip, CARD_OE, MS_OUTPUT_EN, 558 retval = rtsx_write_register(chip, CARD_OE, MS_OUTPUT_EN,
574 MS_OUTPUT_EN); 559 MS_OUTPUT_EN);
575 if (retval) { 560 if (retval)
576 return retval; 561 return retval;
577 }
578 562
579 if (chip->asic_code) { 563 if (chip->asic_code) {
580 retval = rtsx_write_register(chip, MS_CFG, 0xFF, 564 retval = rtsx_write_register(chip, MS_CFG, 0xFF,
@@ -582,34 +566,31 @@ static int ms_prepare_reset(struct rtsx_chip *chip)
582 PUSH_TIME_DEFAULT | 566 PUSH_TIME_DEFAULT |
583 NO_EXTEND_TOGGLE | 567 NO_EXTEND_TOGGLE |
584 MS_BUS_WIDTH_1); 568 MS_BUS_WIDTH_1);
585 if (retval) { 569 if (retval)
586 return retval; 570 return retval;
587 } 571
588 } else { 572 } else {
589 retval = rtsx_write_register(chip, MS_CFG, 0xFF, 573 retval = rtsx_write_register(chip, MS_CFG, 0xFF,
590 SAMPLE_TIME_FALLING | 574 SAMPLE_TIME_FALLING |
591 PUSH_TIME_DEFAULT | 575 PUSH_TIME_DEFAULT |
592 NO_EXTEND_TOGGLE | 576 NO_EXTEND_TOGGLE |
593 MS_BUS_WIDTH_1); 577 MS_BUS_WIDTH_1);
594 if (retval) { 578 if (retval)
595 return retval; 579 return retval;
596 }
597 } 580 }
598 retval = rtsx_write_register(chip, MS_TRANS_CFG, 0xFF, 581 retval = rtsx_write_register(chip, MS_TRANS_CFG, 0xFF,
599 NO_WAIT_INT | NO_AUTO_READ_INT_REG); 582 NO_WAIT_INT | NO_AUTO_READ_INT_REG);
600 if (retval) { 583 if (retval)
601 return retval; 584 return retval;
602 } 585
603 retval = rtsx_write_register(chip, CARD_STOP, MS_STOP | MS_CLR_ERR, 586 retval = rtsx_write_register(chip, CARD_STOP, MS_STOP | MS_CLR_ERR,
604 MS_STOP | MS_CLR_ERR); 587 MS_STOP | MS_CLR_ERR);
605 if (retval) { 588 if (retval)
606 return retval; 589 return retval;
607 }
608 590
609 retval = ms_set_init_para(chip); 591 retval = ms_set_init_para(chip);
610 if (retval != STATUS_SUCCESS) { 592 if (retval != STATUS_SUCCESS)
611 return STATUS_FAIL; 593 return STATUS_FAIL;
612 }
613 594
614 return STATUS_SUCCESS; 595 return STATUS_SUCCESS;
615} 596}
@@ -621,9 +602,8 @@ static int ms_identify_media_type(struct rtsx_chip *chip, int switch_8bit_bus)
621 u8 val; 602 u8 val;
622 603
623 retval = ms_set_rw_reg_addr(chip, Pro_StatusReg, 6, SystemParm, 1); 604 retval = ms_set_rw_reg_addr(chip, Pro_StatusReg, 6, SystemParm, 1);
624 if (retval != STATUS_SUCCESS) { 605 if (retval != STATUS_SUCCESS)
625 return STATUS_FAIL; 606 return STATUS_FAIL;
626 }
627 607
628 for (i = 0; i < MS_MAX_RETRY_COUNT; i++) { 608 for (i = 0; i < MS_MAX_RETRY_COUNT; i++) {
629 retval = ms_transfer_tpc(chip, MS_TM_READ_BYTES, READ_REG, 609 retval = ms_transfer_tpc(chip, MS_TM_READ_BYTES, READ_REG,
@@ -631,14 +611,13 @@ static int ms_identify_media_type(struct rtsx_chip *chip, int switch_8bit_bus)
631 if (retval == STATUS_SUCCESS) 611 if (retval == STATUS_SUCCESS)
632 break; 612 break;
633 } 613 }
634 if (i == MS_MAX_RETRY_COUNT) { 614 if (i == MS_MAX_RETRY_COUNT)
635 return STATUS_FAIL; 615 return STATUS_FAIL;
636 }
637 616
638 retval = rtsx_read_register(chip, PPBUF_BASE2 + 2, &val); 617 retval = rtsx_read_register(chip, PPBUF_BASE2 + 2, &val);
639 if (retval) { 618 if (retval)
640 return retval; 619 return retval;
641 } 620
642 dev_dbg(rtsx_dev(chip), "Type register: 0x%x\n", val); 621 dev_dbg(rtsx_dev(chip), "Type register: 0x%x\n", val);
643 if (val != 0x01) { 622 if (val != 0x01) {
644 if (val != 0x02) 623 if (val != 0x02)
@@ -648,9 +627,9 @@ static int ms_identify_media_type(struct rtsx_chip *chip, int switch_8bit_bus)
648 } 627 }
649 628
650 retval = rtsx_read_register(chip, PPBUF_BASE2 + 4, &val); 629 retval = rtsx_read_register(chip, PPBUF_BASE2 + 4, &val);
651 if (retval) { 630 if (retval)
652 return retval; 631 return retval;
653 } 632
654 dev_dbg(rtsx_dev(chip), "Category register: 0x%x\n", val); 633 dev_dbg(rtsx_dev(chip), "Category register: 0x%x\n", val);
655 if (val != 0) { 634 if (val != 0) {
656 ms_card->check_ms_flow = 1; 635 ms_card->check_ms_flow = 1;
@@ -658,15 +637,15 @@ static int ms_identify_media_type(struct rtsx_chip *chip, int switch_8bit_bus)
658 } 637 }
659 638
660 retval = rtsx_read_register(chip, PPBUF_BASE2 + 5, &val); 639 retval = rtsx_read_register(chip, PPBUF_BASE2 + 5, &val);
661 if (retval) { 640 if (retval)
662 return retval; 641 return retval;
663 } 642
664 dev_dbg(rtsx_dev(chip), "Class register: 0x%x\n", val); 643 dev_dbg(rtsx_dev(chip), "Class register: 0x%x\n", val);
665 if (val == 0) { 644 if (val == 0) {
666 retval = rtsx_read_register(chip, PPBUF_BASE2, &val); 645 retval = rtsx_read_register(chip, PPBUF_BASE2, &val);
667 if (retval) { 646 if (retval)
668 return retval; 647 return retval;
669 } 648
670 if (val & WRT_PRTCT) 649 if (val & WRT_PRTCT)
671 chip->card_wp |= MS_CARD; 650 chip->card_wp |= MS_CARD;
672 else 651 else
@@ -682,9 +661,9 @@ static int ms_identify_media_type(struct rtsx_chip *chip, int switch_8bit_bus)
682 ms_card->ms_type |= TYPE_MSPRO; 661 ms_card->ms_type |= TYPE_MSPRO;
683 662
684 retval = rtsx_read_register(chip, PPBUF_BASE2 + 3, &val); 663 retval = rtsx_read_register(chip, PPBUF_BASE2 + 3, &val);
685 if (retval) { 664 if (retval)
686 return retval; 665 return retval;
687 } 666
688 dev_dbg(rtsx_dev(chip), "IF Mode register: 0x%x\n", val); 667 dev_dbg(rtsx_dev(chip), "IF Mode register: 0x%x\n", val);
689 if (val == 0) { 668 if (val == 0) {
690 ms_card->ms_type &= 0x0F; 669 ms_card->ms_type &= 0x0F;
@@ -720,13 +699,11 @@ static int ms_confirm_cpu_startup(struct rtsx_chip *chip)
720 if (retval == STATUS_SUCCESS) 699 if (retval == STATUS_SUCCESS)
721 break; 700 break;
722 } 701 }
723 if (i == MS_MAX_RETRY_COUNT) { 702 if (i == MS_MAX_RETRY_COUNT)
724 return STATUS_FAIL; 703 return STATUS_FAIL;
725 }
726 704
727 if (k > 100) { 705 if (k > 100)
728 return STATUS_FAIL; 706 return STATUS_FAIL;
729 }
730 707
731 k++; 708 k++;
732 wait_timeout(100); 709 wait_timeout(100);
@@ -737,16 +714,14 @@ static int ms_confirm_cpu_startup(struct rtsx_chip *chip)
737 if (retval == STATUS_SUCCESS) 714 if (retval == STATUS_SUCCESS)
738 break; 715 break;
739 } 716 }
740 if (i == MS_MAX_RETRY_COUNT) { 717 if (i == MS_MAX_RETRY_COUNT)
741 return STATUS_FAIL; 718 return STATUS_FAIL;
742 }
743 719
744 if (val & INT_REG_ERR) { 720 if (val & INT_REG_ERR) {
745 if (val & INT_REG_CMDNK) { 721 if (val & INT_REG_CMDNK)
746 chip->card_wp |= (MS_CARD); 722 chip->card_wp |= (MS_CARD);
747 } else { 723 else
748 return STATUS_FAIL; 724 return STATUS_FAIL;
749 }
750 } 725 }
751 /* -- end confirm CPU startup */ 726 /* -- end confirm CPU startup */
752 727
@@ -766,9 +741,8 @@ static int ms_switch_parallel_bus(struct rtsx_chip *chip)
766 if (retval == STATUS_SUCCESS) 741 if (retval == STATUS_SUCCESS)
767 break; 742 break;
768 } 743 }
769 if (retval != STATUS_SUCCESS) { 744 if (retval != STATUS_SUCCESS)
770 return STATUS_FAIL; 745 return STATUS_FAIL;
771 }
772 746
773 return STATUS_SUCCESS; 747 return STATUS_SUCCESS;
774} 748}
@@ -787,27 +761,24 @@ static int ms_switch_8bit_bus(struct rtsx_chip *chip)
787 if (retval == STATUS_SUCCESS) 761 if (retval == STATUS_SUCCESS)
788 break; 762 break;
789 } 763 }
790 if (retval != STATUS_SUCCESS) { 764 if (retval != STATUS_SUCCESS)
791 return STATUS_FAIL; 765 return STATUS_FAIL;
792 }
793 766
794 retval = rtsx_write_register(chip, MS_CFG, 0x98, 767 retval = rtsx_write_register(chip, MS_CFG, 0x98,
795 MS_BUS_WIDTH_8 | SAMPLE_TIME_FALLING); 768 MS_BUS_WIDTH_8 | SAMPLE_TIME_FALLING);
796 if (retval) { 769 if (retval)
797 return retval; 770 return retval;
798 } 771
799 ms_card->ms_type |= MS_8BIT; 772 ms_card->ms_type |= MS_8BIT;
800 retval = ms_set_init_para(chip); 773 retval = ms_set_init_para(chip);
801 if (retval != STATUS_SUCCESS) { 774 if (retval != STATUS_SUCCESS)
802 return STATUS_FAIL; 775 return STATUS_FAIL;
803 }
804 776
805 for (i = 0; i < MS_MAX_RETRY_COUNT; i++) { 777 for (i = 0; i < MS_MAX_RETRY_COUNT; i++) {
806 retval = ms_transfer_tpc(chip, MS_TM_READ_BYTES, GET_INT, 778 retval = ms_transfer_tpc(chip, MS_TM_READ_BYTES, GET_INT,
807 1, NO_WAIT_INT); 779 1, NO_WAIT_INT);
808 if (retval != STATUS_SUCCESS) { 780 if (retval != STATUS_SUCCESS)
809 return STATUS_FAIL; 781 return STATUS_FAIL;
810 }
811 } 782 }
812 783
813 return STATUS_SUCCESS; 784 return STATUS_SUCCESS;
@@ -820,19 +791,16 @@ static int ms_pro_reset_flow(struct rtsx_chip *chip, int switch_8bit_bus)
820 791
821 for (i = 0; i < 3; i++) { 792 for (i = 0; i < 3; i++) {
822 retval = ms_prepare_reset(chip); 793 retval = ms_prepare_reset(chip);
823 if (retval != STATUS_SUCCESS) { 794 if (retval != STATUS_SUCCESS)
824 return STATUS_FAIL; 795 return STATUS_FAIL;
825 }
826 796
827 retval = ms_identify_media_type(chip, switch_8bit_bus); 797 retval = ms_identify_media_type(chip, switch_8bit_bus);
828 if (retval != STATUS_SUCCESS) { 798 if (retval != STATUS_SUCCESS)
829 return STATUS_FAIL; 799 return STATUS_FAIL;
830 }
831 800
832 retval = ms_confirm_cpu_startup(chip); 801 retval = ms_confirm_cpu_startup(chip);
833 if (retval != STATUS_SUCCESS) { 802 if (retval != STATUS_SUCCESS)
834 return STATUS_FAIL; 803 return STATUS_FAIL;
835 }
836 804
837 retval = ms_switch_parallel_bus(chip); 805 retval = ms_switch_parallel_bus(chip);
838 if (retval != STATUS_SUCCESS) { 806 if (retval != STATUS_SUCCESS) {
@@ -846,25 +814,22 @@ static int ms_pro_reset_flow(struct rtsx_chip *chip, int switch_8bit_bus)
846 } 814 }
847 } 815 }
848 816
849 if (retval != STATUS_SUCCESS) { 817 if (retval != STATUS_SUCCESS)
850 return STATUS_FAIL; 818 return STATUS_FAIL;
851 }
852 819
853 /* Switch MS-PRO into Parallel mode */ 820 /* Switch MS-PRO into Parallel mode */
854 retval = rtsx_write_register(chip, MS_CFG, 0x18, MS_BUS_WIDTH_4); 821 retval = rtsx_write_register(chip, MS_CFG, 0x18, MS_BUS_WIDTH_4);
855 if (retval) { 822 if (retval)
856 return retval; 823 return retval;
857 } 824
858 retval = rtsx_write_register(chip, MS_CFG, PUSH_TIME_ODD, 825 retval = rtsx_write_register(chip, MS_CFG, PUSH_TIME_ODD,
859 PUSH_TIME_ODD); 826 PUSH_TIME_ODD);
860 if (retval) { 827 if (retval)
861 return retval; 828 return retval;
862 }
863 829
864 retval = ms_set_init_para(chip); 830 retval = ms_set_init_para(chip);
865 if (retval != STATUS_SUCCESS) { 831 if (retval != STATUS_SUCCESS)
866 return STATUS_FAIL; 832 return STATUS_FAIL;
867 }
868 833
869 /* If MSPro HG Card, We shall try to switch to 8-bit bus */ 834 /* If MSPro HG Card, We shall try to switch to 8-bit bus */
870 if (CHK_MSHG(ms_card) && chip->support_ms_8bit && switch_8bit_bus) { 835 if (CHK_MSHG(ms_card) && chip->support_ms_8bit && switch_8bit_bus) {
@@ -887,9 +852,8 @@ static int msxc_change_power(struct rtsx_chip *chip, u8 mode)
887 ms_cleanup_work(chip); 852 ms_cleanup_work(chip);
888 853
889 retval = ms_set_rw_reg_addr(chip, 0, 0, Pro_DataCount1, 6); 854 retval = ms_set_rw_reg_addr(chip, 0, 0, Pro_DataCount1, 6);
890 if (retval != STATUS_SUCCESS) { 855 if (retval != STATUS_SUCCESS)
891 return STATUS_FAIL; 856 return STATUS_FAIL;
892 }
893 857
894 buf[0] = 0; 858 buf[0] = 0;
895 buf[1] = mode; 859 buf[1] = mode;
@@ -899,22 +863,19 @@ static int msxc_change_power(struct rtsx_chip *chip, u8 mode)
899 buf[5] = 0; 863 buf[5] = 0;
900 864
901 retval = ms_write_bytes(chip, PRO_WRITE_REG, 6, NO_WAIT_INT, buf, 6); 865 retval = ms_write_bytes(chip, PRO_WRITE_REG, 6, NO_WAIT_INT, buf, 6);
902 if (retval != STATUS_SUCCESS) { 866 if (retval != STATUS_SUCCESS)
903 return STATUS_FAIL; 867 return STATUS_FAIL;
904 }
905 868
906 retval = ms_send_cmd(chip, XC_CHG_POWER, WAIT_INT); 869 retval = ms_send_cmd(chip, XC_CHG_POWER, WAIT_INT);
907 if (retval != STATUS_SUCCESS) { 870 if (retval != STATUS_SUCCESS)
908 return STATUS_FAIL; 871 return STATUS_FAIL;
909 }
910 872
911 retval = rtsx_read_register(chip, MS_TRANS_CFG, buf); 873 retval = rtsx_read_register(chip, MS_TRANS_CFG, buf);
912 if (retval) { 874 if (retval)
913 return retval; 875 return retval;
914 } 876
915 if (buf[0] & (MS_INT_CMDNK | MS_INT_ERR)) { 877 if (buf[0] & (MS_INT_CMDNK | MS_INT_ERR))
916 return STATUS_FAIL; 878 return STATUS_FAIL;
917 }
918 879
919 return STATUS_SUCCESS; 880 return STATUS_SUCCESS;
920} 881}
@@ -936,9 +897,8 @@ static int ms_read_attribute_info(struct rtsx_chip *chip)
936#endif 897#endif
937 898
938 retval = ms_set_rw_reg_addr(chip, Pro_IntReg, 2, Pro_SystemParm, 7); 899 retval = ms_set_rw_reg_addr(chip, Pro_IntReg, 2, Pro_SystemParm, 7);
939 if (retval != STATUS_SUCCESS) { 900 if (retval != STATUS_SUCCESS)
940 return STATUS_FAIL; 901 return STATUS_FAIL;
941 }
942 902
943 if (CHK_MS8BIT(ms_card)) 903 if (CHK_MS8BIT(ms_card))
944 data[0] = PARALLEL_8BIT_IF; 904 data[0] = PARALLEL_8BIT_IF;
@@ -960,14 +920,12 @@ static int ms_read_attribute_info(struct rtsx_chip *chip)
960 if (retval == STATUS_SUCCESS) 920 if (retval == STATUS_SUCCESS)
961 break; 921 break;
962 } 922 }
963 if (retval != STATUS_SUCCESS) { 923 if (retval != STATUS_SUCCESS)
964 return STATUS_FAIL; 924 return STATUS_FAIL;
965 }
966 925
967 buf = kmalloc(64 * 512, GFP_KERNEL); 926 buf = kmalloc(64 * 512, GFP_KERNEL);
968 if (!buf) { 927 if (!buf)
969 return STATUS_ERROR; 928 return STATUS_ERROR;
970 }
971 929
972 for (i = 0; i < MS_MAX_RETRY_COUNT; i++) { 930 for (i = 0; i < MS_MAX_RETRY_COUNT; i++) {
973 retval = ms_send_cmd(chip, PRO_READ_ATRB, WAIT_INT); 931 retval = ms_send_cmd(chip, PRO_READ_ATRB, WAIT_INT);
@@ -1150,18 +1108,15 @@ static int ms_read_attribute_info(struct rtsx_chip *chip)
1150 1108
1151#ifdef SUPPORT_MSXC 1109#ifdef SUPPORT_MSXC
1152 if (CHK_MSXC(ms_card)) { 1110 if (CHK_MSXC(ms_card)) {
1153 if (class_code != 0x03) { 1111 if (class_code != 0x03)
1154 return STATUS_FAIL; 1112 return STATUS_FAIL;
1155 }
1156 } else { 1113 } else {
1157 if (class_code != 0x02) { 1114 if (class_code != 0x02)
1158 return STATUS_FAIL; 1115 return STATUS_FAIL;
1159 }
1160 } 1116 }
1161#else 1117#else
1162 if (class_code != 0x02) { 1118 if (class_code != 0x02)
1163 return STATUS_FAIL; 1119 return STATUS_FAIL;
1164 }
1165#endif 1120#endif
1166 1121
1167 if (device_type != 0x00) { 1122 if (device_type != 0x00) {
@@ -1173,9 +1128,8 @@ static int ms_read_attribute_info(struct rtsx_chip *chip)
1173 } 1128 }
1174 } 1129 }
1175 1130
1176 if (sub_class & 0xC0) { 1131 if (sub_class & 0xC0)
1177 return STATUS_FAIL; 1132 return STATUS_FAIL;
1178 }
1179 1133
1180 dev_dbg(rtsx_dev(chip), "class_code: 0x%x, device_type: 0x%x, sub_class: 0x%x\n", 1134 dev_dbg(rtsx_dev(chip), "class_code: 0x%x, device_type: 0x%x, sub_class: 0x%x\n",
1181 class_code, device_type, sub_class); 1135 class_code, device_type, sub_class);
@@ -1223,18 +1177,16 @@ retry:
1223 if (retval != STATUS_SUCCESS) { 1177 if (retval != STATUS_SUCCESS) {
1224 if (ms_card->switch_8bit_fail) { 1178 if (ms_card->switch_8bit_fail) {
1225 retval = ms_pro_reset_flow(chip, 0); 1179 retval = ms_pro_reset_flow(chip, 0);
1226 if (retval != STATUS_SUCCESS) { 1180 if (retval != STATUS_SUCCESS)
1227 return STATUS_FAIL; 1181 return STATUS_FAIL;
1228 }
1229 } else { 1182 } else {
1230 return STATUS_FAIL; 1183 return STATUS_FAIL;
1231 } 1184 }
1232 } 1185 }
1233 1186
1234 retval = ms_read_attribute_info(chip); 1187 retval = ms_read_attribute_info(chip);
1235 if (retval != STATUS_SUCCESS) { 1188 if (retval != STATUS_SUCCESS)
1236 return STATUS_FAIL; 1189 return STATUS_FAIL;
1237 }
1238 1190
1239#ifdef XC_POWERCLASS 1191#ifdef XC_POWERCLASS
1240 if (CHK_HG8BIT(ms_card)) 1192 if (CHK_HG8BIT(ms_card))
@@ -1274,9 +1226,8 @@ retry:
1274 1226
1275#ifdef SUPPORT_MAGIC_GATE 1227#ifdef SUPPORT_MAGIC_GATE
1276 retval = mg_set_tpc_para_sub(chip, 0, 0); 1228 retval = mg_set_tpc_para_sub(chip, 0, 0);
1277 if (retval != STATUS_SUCCESS) { 1229 if (retval != STATUS_SUCCESS)
1278 return STATUS_FAIL; 1230 return STATUS_FAIL;
1279 }
1280#endif 1231#endif
1281 1232
1282 if (CHK_HG8BIT(ms_card)) 1233 if (CHK_HG8BIT(ms_card))
@@ -1293,14 +1244,12 @@ static int ms_read_status_reg(struct rtsx_chip *chip)
1293 u8 val[2]; 1244 u8 val[2];
1294 1245
1295 retval = ms_set_rw_reg_addr(chip, StatusReg0, 2, 0, 0); 1246 retval = ms_set_rw_reg_addr(chip, StatusReg0, 2, 0, 0);
1296 if (retval != STATUS_SUCCESS) { 1247 if (retval != STATUS_SUCCESS)
1297 return STATUS_FAIL; 1248 return STATUS_FAIL;
1298 }
1299 1249
1300 retval = ms_read_bytes(chip, READ_REG, 2, NO_WAIT_INT, val, 2); 1250 retval = ms_read_bytes(chip, READ_REG, 2, NO_WAIT_INT, val, 2);
1301 if (retval != STATUS_SUCCESS) { 1251 if (retval != STATUS_SUCCESS)
1302 return STATUS_FAIL; 1252 return STATUS_FAIL;
1303 }
1304 1253
1305 if (val[1] & (STS_UCDT | STS_UCEX | STS_UCFG)) { 1254 if (val[1] & (STS_UCDT | STS_UCEX | STS_UCFG)) {
1306 ms_set_err_code(chip, MS_FLASH_READ_ERROR); 1255 ms_set_err_code(chip, MS_FLASH_READ_ERROR);
@@ -1319,9 +1268,8 @@ static int ms_read_extra_data(struct rtsx_chip *chip,
1319 1268
1320 retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE, 1269 retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE,
1321 SystemParm, 6); 1270 SystemParm, 6);
1322 if (retval != STATUS_SUCCESS) { 1271 if (retval != STATUS_SUCCESS)
1323 return STATUS_FAIL; 1272 return STATUS_FAIL;
1324 }
1325 1273
1326 if (CHK_MS4BIT(ms_card)) { 1274 if (CHK_MS4BIT(ms_card)) {
1327 /* Parallel interface */ 1275 /* Parallel interface */
@@ -1342,9 +1290,8 @@ static int ms_read_extra_data(struct rtsx_chip *chip,
1342 if (retval == STATUS_SUCCESS) 1290 if (retval == STATUS_SUCCESS)
1343 break; 1291 break;
1344 } 1292 }
1345 if (i == MS_MAX_RETRY_COUNT) { 1293 if (i == MS_MAX_RETRY_COUNT)
1346 return STATUS_FAIL; 1294 return STATUS_FAIL;
1347 }
1348 1295
1349 ms_set_err_code(chip, MS_NO_ERROR); 1296 ms_set_err_code(chip, MS_NO_ERROR);
1350 1297
@@ -1353,15 +1300,13 @@ static int ms_read_extra_data(struct rtsx_chip *chip,
1353 if (retval == STATUS_SUCCESS) 1300 if (retval == STATUS_SUCCESS)
1354 break; 1301 break;
1355 } 1302 }
1356 if (i == MS_MAX_RETRY_COUNT) { 1303 if (i == MS_MAX_RETRY_COUNT)
1357 return STATUS_FAIL; 1304 return STATUS_FAIL;
1358 }
1359 1305
1360 ms_set_err_code(chip, MS_NO_ERROR); 1306 ms_set_err_code(chip, MS_NO_ERROR);
1361 retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1); 1307 retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1);
1362 if (retval != STATUS_SUCCESS) { 1308 if (retval != STATUS_SUCCESS)
1363 return STATUS_FAIL; 1309 return STATUS_FAIL;
1364 }
1365 1310
1366 if (val & INT_REG_CMDNK) { 1311 if (val & INT_REG_CMDNK) {
1367 ms_set_err_code(chip, MS_CMD_NK); 1312 ms_set_err_code(chip, MS_CMD_NK);
@@ -1370,24 +1315,21 @@ static int ms_read_extra_data(struct rtsx_chip *chip,
1370 if (val & INT_REG_CED) { 1315 if (val & INT_REG_CED) {
1371 if (val & INT_REG_ERR) { 1316 if (val & INT_REG_ERR) {
1372 retval = ms_read_status_reg(chip); 1317 retval = ms_read_status_reg(chip);
1373 if (retval != STATUS_SUCCESS) { 1318 if (retval != STATUS_SUCCESS)
1374 return STATUS_FAIL; 1319 return STATUS_FAIL;
1375 }
1376 1320
1377 retval = ms_set_rw_reg_addr(chip, OverwriteFlag, 1321 retval = ms_set_rw_reg_addr(chip, OverwriteFlag,
1378 MS_EXTRA_SIZE, SystemParm, 1322 MS_EXTRA_SIZE, SystemParm,
1379 6); 1323 6);
1380 if (retval != STATUS_SUCCESS) { 1324 if (retval != STATUS_SUCCESS)
1381 return STATUS_FAIL; 1325 return STATUS_FAIL;
1382 }
1383 } 1326 }
1384 } 1327 }
1385 1328
1386 retval = ms_read_bytes(chip, READ_REG, MS_EXTRA_SIZE, NO_WAIT_INT, 1329 retval = ms_read_bytes(chip, READ_REG, MS_EXTRA_SIZE, NO_WAIT_INT,
1387 data, MS_EXTRA_SIZE); 1330 data, MS_EXTRA_SIZE);
1388 if (retval != STATUS_SUCCESS) { 1331 if (retval != STATUS_SUCCESS)
1389 return STATUS_FAIL; 1332 return STATUS_FAIL;
1390 }
1391 1333
1392 if (buf && buf_len) { 1334 if (buf && buf_len) {
1393 if (buf_len > MS_EXTRA_SIZE) 1335 if (buf_len > MS_EXTRA_SIZE)
@@ -1405,15 +1347,13 @@ static int ms_write_extra_data(struct rtsx_chip *chip, u16 block_addr,
1405 int retval, i; 1347 int retval, i;
1406 u8 val, data[16]; 1348 u8 val, data[16];
1407 1349
1408 if (!buf || (buf_len < MS_EXTRA_SIZE)) { 1350 if (!buf || (buf_len < MS_EXTRA_SIZE))
1409 return STATUS_FAIL; 1351 return STATUS_FAIL;
1410 }
1411 1352
1412 retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE, 1353 retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE,
1413 SystemParm, 6 + MS_EXTRA_SIZE); 1354 SystemParm, 6 + MS_EXTRA_SIZE);
1414 if (retval != STATUS_SUCCESS) { 1355 if (retval != STATUS_SUCCESS)
1415 return STATUS_FAIL; 1356 return STATUS_FAIL;
1416 }
1417 1357
1418 if (CHK_MS4BIT(ms_card)) 1358 if (CHK_MS4BIT(ms_card))
1419 data[0] = 0x88; 1359 data[0] = 0x88;
@@ -1431,20 +1371,17 @@ static int ms_write_extra_data(struct rtsx_chip *chip, u16 block_addr,
1431 1371
1432 retval = ms_write_bytes(chip, WRITE_REG, (6 + MS_EXTRA_SIZE), 1372 retval = ms_write_bytes(chip, WRITE_REG, (6 + MS_EXTRA_SIZE),
1433 NO_WAIT_INT, data, 16); 1373 NO_WAIT_INT, data, 16);
1434 if (retval != STATUS_SUCCESS) { 1374 if (retval != STATUS_SUCCESS)
1435 return STATUS_FAIL; 1375 return STATUS_FAIL;
1436 }
1437 1376
1438 retval = ms_send_cmd(chip, BLOCK_WRITE, WAIT_INT); 1377 retval = ms_send_cmd(chip, BLOCK_WRITE, WAIT_INT);
1439 if (retval != STATUS_SUCCESS) { 1378 if (retval != STATUS_SUCCESS)
1440 return STATUS_FAIL; 1379 return STATUS_FAIL;
1441 }
1442 1380
1443 ms_set_err_code(chip, MS_NO_ERROR); 1381 ms_set_err_code(chip, MS_NO_ERROR);
1444 retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1); 1382 retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1);
1445 if (retval != STATUS_SUCCESS) { 1383 if (retval != STATUS_SUCCESS)
1446 return STATUS_FAIL; 1384 return STATUS_FAIL;
1447 }
1448 1385
1449 if (val & INT_REG_CMDNK) { 1386 if (val & INT_REG_CMDNK) {
1450 ms_set_err_code(chip, MS_CMD_NK); 1387 ms_set_err_code(chip, MS_CMD_NK);
@@ -1468,9 +1405,8 @@ static int ms_read_page(struct rtsx_chip *chip, u16 block_addr, u8 page_num)
1468 1405
1469 retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE, 1406 retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE,
1470 SystemParm, 6); 1407 SystemParm, 6);
1471 if (retval != STATUS_SUCCESS) { 1408 if (retval != STATUS_SUCCESS)
1472 return STATUS_FAIL; 1409 return STATUS_FAIL;
1473 }
1474 1410
1475 if (CHK_MS4BIT(ms_card)) 1411 if (CHK_MS4BIT(ms_card))
1476 data[0] = 0x88; 1412 data[0] = 0x88;
@@ -1484,20 +1420,17 @@ static int ms_read_page(struct rtsx_chip *chip, u16 block_addr, u8 page_num)
1484 data[5] = page_num; 1420 data[5] = page_num;
1485 1421
1486 retval = ms_write_bytes(chip, WRITE_REG, 6, NO_WAIT_INT, data, 6); 1422 retval = ms_write_bytes(chip, WRITE_REG, 6, NO_WAIT_INT, data, 6);
1487 if (retval != STATUS_SUCCESS) { 1423 if (retval != STATUS_SUCCESS)
1488 return STATUS_FAIL; 1424 return STATUS_FAIL;
1489 }
1490 1425
1491 retval = ms_send_cmd(chip, BLOCK_READ, WAIT_INT); 1426 retval = ms_send_cmd(chip, BLOCK_READ, WAIT_INT);
1492 if (retval != STATUS_SUCCESS) { 1427 if (retval != STATUS_SUCCESS)
1493 return STATUS_FAIL; 1428 return STATUS_FAIL;
1494 }
1495 1429
1496 ms_set_err_code(chip, MS_NO_ERROR); 1430 ms_set_err_code(chip, MS_NO_ERROR);
1497 retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1); 1431 retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1);
1498 if (retval != STATUS_SUCCESS) { 1432 if (retval != STATUS_SUCCESS)
1499 return STATUS_FAIL; 1433 return STATUS_FAIL;
1500 }
1501 1434
1502 if (val & INT_REG_CMDNK) { 1435 if (val & INT_REG_CMDNK) {
1503 ms_set_err_code(chip, MS_CMD_NK); 1436 ms_set_err_code(chip, MS_CMD_NK);
@@ -1524,13 +1457,11 @@ static int ms_read_page(struct rtsx_chip *chip, u16 block_addr, u8 page_num)
1524 1457
1525 retval = ms_transfer_tpc(chip, MS_TM_NORMAL_READ, READ_PAGE_DATA, 1458 retval = ms_transfer_tpc(chip, MS_TM_NORMAL_READ, READ_PAGE_DATA,
1526 0, NO_WAIT_INT); 1459 0, NO_WAIT_INT);
1527 if (retval != STATUS_SUCCESS) { 1460 if (retval != STATUS_SUCCESS)
1528 return STATUS_FAIL; 1461 return STATUS_FAIL;
1529 }
1530 1462
1531 if (ms_check_err_code(chip, MS_FLASH_WRITE_ERROR)) { 1463 if (ms_check_err_code(chip, MS_FLASH_WRITE_ERROR))
1532 return STATUS_FAIL; 1464 return STATUS_FAIL;
1533 }
1534 1465
1535 return STATUS_SUCCESS; 1466 return STATUS_SUCCESS;
1536} 1467}
@@ -1542,15 +1473,13 @@ static int ms_set_bad_block(struct rtsx_chip *chip, u16 phy_blk)
1542 u8 val, data[8], extra[MS_EXTRA_SIZE]; 1473 u8 val, data[8], extra[MS_EXTRA_SIZE];
1543 1474
1544 retval = ms_read_extra_data(chip, phy_blk, 0, extra, MS_EXTRA_SIZE); 1475 retval = ms_read_extra_data(chip, phy_blk, 0, extra, MS_EXTRA_SIZE);
1545 if (retval != STATUS_SUCCESS) { 1476 if (retval != STATUS_SUCCESS)
1546 return STATUS_FAIL; 1477 return STATUS_FAIL;
1547 }
1548 1478
1549 retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE, 1479 retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE,
1550 SystemParm, 7); 1480 SystemParm, 7);
1551 if (retval != STATUS_SUCCESS) { 1481 if (retval != STATUS_SUCCESS)
1552 return STATUS_FAIL; 1482 return STATUS_FAIL;
1553 }
1554 1483
1555 ms_set_err_code(chip, MS_NO_ERROR); 1484 ms_set_err_code(chip, MS_NO_ERROR);
1556 1485
@@ -1568,20 +1497,17 @@ static int ms_set_bad_block(struct rtsx_chip *chip, u16 phy_blk)
1568 data[7] = 0xFF; 1497 data[7] = 0xFF;
1569 1498
1570 retval = ms_write_bytes(chip, WRITE_REG, 7, NO_WAIT_INT, data, 7); 1499 retval = ms_write_bytes(chip, WRITE_REG, 7, NO_WAIT_INT, data, 7);
1571 if (retval != STATUS_SUCCESS) { 1500 if (retval != STATUS_SUCCESS)
1572 return STATUS_FAIL; 1501 return STATUS_FAIL;
1573 }
1574 1502
1575 retval = ms_send_cmd(chip, BLOCK_WRITE, WAIT_INT); 1503 retval = ms_send_cmd(chip, BLOCK_WRITE, WAIT_INT);
1576 if (retval != STATUS_SUCCESS) { 1504 if (retval != STATUS_SUCCESS)
1577 return STATUS_FAIL; 1505 return STATUS_FAIL;
1578 }
1579 1506
1580 ms_set_err_code(chip, MS_NO_ERROR); 1507 ms_set_err_code(chip, MS_NO_ERROR);
1581 retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1); 1508 retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1);
1582 if (retval != STATUS_SUCCESS) { 1509 if (retval != STATUS_SUCCESS)
1583 return STATUS_FAIL; 1510 return STATUS_FAIL;
1584 }
1585 1511
1586 if (val & INT_REG_CMDNK) { 1512 if (val & INT_REG_CMDNK) {
1587 ms_set_err_code(chip, MS_CMD_NK); 1513 ms_set_err_code(chip, MS_CMD_NK);
@@ -1606,9 +1532,8 @@ static int ms_erase_block(struct rtsx_chip *chip, u16 phy_blk)
1606 1532
1607 retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE, 1533 retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE,
1608 SystemParm, 6); 1534 SystemParm, 6);
1609 if (retval != STATUS_SUCCESS) { 1535 if (retval != STATUS_SUCCESS)
1610 return STATUS_FAIL; 1536 return STATUS_FAIL;
1611 }
1612 1537
1613 ms_set_err_code(chip, MS_NO_ERROR); 1538 ms_set_err_code(chip, MS_NO_ERROR);
1614 1539
@@ -1624,21 +1549,18 @@ static int ms_erase_block(struct rtsx_chip *chip, u16 phy_blk)
1624 data[5] = 0; 1549 data[5] = 0;
1625 1550
1626 retval = ms_write_bytes(chip, WRITE_REG, 6, NO_WAIT_INT, data, 6); 1551 retval = ms_write_bytes(chip, WRITE_REG, 6, NO_WAIT_INT, data, 6);
1627 if (retval != STATUS_SUCCESS) { 1552 if (retval != STATUS_SUCCESS)
1628 return STATUS_FAIL; 1553 return STATUS_FAIL;
1629 }
1630 1554
1631ERASE_RTY: 1555ERASE_RTY:
1632 retval = ms_send_cmd(chip, BLOCK_ERASE, WAIT_INT); 1556 retval = ms_send_cmd(chip, BLOCK_ERASE, WAIT_INT);
1633 if (retval != STATUS_SUCCESS) { 1557 if (retval != STATUS_SUCCESS)
1634 return STATUS_FAIL; 1558 return STATUS_FAIL;
1635 }
1636 1559
1637 ms_set_err_code(chip, MS_NO_ERROR); 1560 ms_set_err_code(chip, MS_NO_ERROR);
1638 retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1); 1561 retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1);
1639 if (retval != STATUS_SUCCESS) { 1562 if (retval != STATUS_SUCCESS)
1640 return STATUS_FAIL; 1563 return STATUS_FAIL;
1641 }
1642 1564
1643 if (val & INT_REG_CMDNK) { 1565 if (val & INT_REG_CMDNK) {
1644 if (i < 3) { 1566 if (i < 3) {
@@ -1701,9 +1623,8 @@ static int ms_init_page(struct rtsx_chip *chip, u16 phy_blk, u16 log_blk,
1701 1623
1702 retval = ms_write_extra_data(chip, phy_blk, i, 1624 retval = ms_write_extra_data(chip, phy_blk, i,
1703 extra, MS_EXTRA_SIZE); 1625 extra, MS_EXTRA_SIZE);
1704 if (retval != STATUS_SUCCESS) { 1626 if (retval != STATUS_SUCCESS)
1705 return STATUS_FAIL; 1627 return STATUS_FAIL;
1706 }
1707 } 1628 }
1708 1629
1709 return STATUS_SUCCESS; 1630 return STATUS_SUCCESS;
@@ -1723,30 +1644,25 @@ static int ms_copy_page(struct rtsx_chip *chip, u16 old_blk, u16 new_blk,
1723 start_page, end_page); 1644 start_page, end_page);
1724 1645
1725 retval = ms_read_extra_data(chip, new_blk, 0, extra, MS_EXTRA_SIZE); 1646 retval = ms_read_extra_data(chip, new_blk, 0, extra, MS_EXTRA_SIZE);
1726 if (retval != STATUS_SUCCESS) { 1647 if (retval != STATUS_SUCCESS)
1727 return STATUS_FAIL; 1648 return STATUS_FAIL;
1728 }
1729 1649
1730 retval = ms_read_status_reg(chip); 1650 retval = ms_read_status_reg(chip);
1731 if (retval != STATUS_SUCCESS) { 1651 if (retval != STATUS_SUCCESS)
1732 return STATUS_FAIL; 1652 return STATUS_FAIL;
1733 }
1734 1653
1735 retval = rtsx_read_register(chip, PPBUF_BASE2, &val); 1654 retval = rtsx_read_register(chip, PPBUF_BASE2, &val);
1736 if (retval) { 1655 if (retval)
1737 return retval; 1656 return retval;
1738 }
1739 1657
1740 if (val & BUF_FULL) { 1658 if (val & BUF_FULL) {
1741 retval = ms_send_cmd(chip, CLEAR_BUF, WAIT_INT); 1659 retval = ms_send_cmd(chip, CLEAR_BUF, WAIT_INT);
1742 if (retval != STATUS_SUCCESS) { 1660 if (retval != STATUS_SUCCESS)
1743 return STATUS_FAIL; 1661 return STATUS_FAIL;
1744 }
1745 1662
1746 retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1); 1663 retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1);
1747 if (retval != STATUS_SUCCESS) { 1664 if (retval != STATUS_SUCCESS)
1748 return STATUS_FAIL; 1665 return STATUS_FAIL;
1749 }
1750 1666
1751 if (!(val & INT_REG_CED)) { 1667 if (!(val & INT_REG_CED)) {
1752 ms_set_err_code(chip, MS_FLASH_WRITE_ERROR); 1668 ms_set_err_code(chip, MS_FLASH_WRITE_ERROR);
@@ -1764,9 +1680,8 @@ static int ms_copy_page(struct rtsx_chip *chip, u16 old_blk, u16 new_blk,
1764 1680
1765 retval = ms_set_rw_reg_addr(chip, OverwriteFlag, 1681 retval = ms_set_rw_reg_addr(chip, OverwriteFlag,
1766 MS_EXTRA_SIZE, SystemParm, 6); 1682 MS_EXTRA_SIZE, SystemParm, 6);
1767 if (retval != STATUS_SUCCESS) { 1683 if (retval != STATUS_SUCCESS)
1768 return STATUS_FAIL; 1684 return STATUS_FAIL;
1769 }
1770 1685
1771 ms_set_err_code(chip, MS_NO_ERROR); 1686 ms_set_err_code(chip, MS_NO_ERROR);
1772 1687
@@ -1783,20 +1698,17 @@ static int ms_copy_page(struct rtsx_chip *chip, u16 old_blk, u16 new_blk,
1783 1698
1784 retval = ms_write_bytes(chip, WRITE_REG, 6, NO_WAIT_INT, 1699 retval = ms_write_bytes(chip, WRITE_REG, 6, NO_WAIT_INT,
1785 data, 6); 1700 data, 6);
1786 if (retval != STATUS_SUCCESS) { 1701 if (retval != STATUS_SUCCESS)
1787 return STATUS_FAIL; 1702 return STATUS_FAIL;
1788 }
1789 1703
1790 retval = ms_send_cmd(chip, BLOCK_READ, WAIT_INT); 1704 retval = ms_send_cmd(chip, BLOCK_READ, WAIT_INT);
1791 if (retval != STATUS_SUCCESS) { 1705 if (retval != STATUS_SUCCESS)
1792 return STATUS_FAIL; 1706 return STATUS_FAIL;
1793 }
1794 1707
1795 ms_set_err_code(chip, MS_NO_ERROR); 1708 ms_set_err_code(chip, MS_NO_ERROR);
1796 retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1); 1709 retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1);
1797 if (retval != STATUS_SUCCESS) { 1710 if (retval != STATUS_SUCCESS)
1798 return STATUS_FAIL; 1711 return STATUS_FAIL;
1799 }
1800 1712
1801 if (val & INT_REG_CMDNK) { 1713 if (val & INT_REG_CMDNK) {
1802 ms_set_err_code(chip, MS_CMD_NK); 1714 ms_set_err_code(chip, MS_CMD_NK);
@@ -1817,9 +1729,8 @@ static int ms_copy_page(struct rtsx_chip *chip, u16 old_blk, u16 new_blk,
1817 MS_TM_NORMAL_READ, 1729 MS_TM_NORMAL_READ,
1818 READ_PAGE_DATA, 1730 READ_PAGE_DATA,
1819 0, NO_WAIT_INT); 1731 0, NO_WAIT_INT);
1820 if (retval != STATUS_SUCCESS) { 1732 if (retval != STATUS_SUCCESS)
1821 return STATUS_FAIL; 1733 return STATUS_FAIL;
1822 }
1823 1734
1824 if (uncorrect_flag) { 1735 if (uncorrect_flag) {
1825 ms_set_page_status(log_blk, setPS_NG, 1736 ms_set_page_status(log_blk, setPS_NG,
@@ -1854,9 +1765,8 @@ static int ms_copy_page(struct rtsx_chip *chip, u16 old_blk, u16 new_blk,
1854 if (retval == STATUS_SUCCESS) 1765 if (retval == STATUS_SUCCESS)
1855 break; 1766 break;
1856 } 1767 }
1857 if (rty_cnt == MS_MAX_RETRY_COUNT) { 1768 if (rty_cnt == MS_MAX_RETRY_COUNT)
1858 return STATUS_FAIL; 1769 return STATUS_FAIL;
1859 }
1860 } 1770 }
1861 1771
1862 if (!(val & INT_REG_BREQ)) { 1772 if (!(val & INT_REG_BREQ)) {
@@ -1895,20 +1805,17 @@ static int ms_copy_page(struct rtsx_chip *chip, u16 old_blk, u16 new_blk,
1895 1805
1896 retval = ms_write_bytes(chip, WRITE_REG, (6 + MS_EXTRA_SIZE), 1806 retval = ms_write_bytes(chip, WRITE_REG, (6 + MS_EXTRA_SIZE),
1897 NO_WAIT_INT, data, 16); 1807 NO_WAIT_INT, data, 16);
1898 if (retval != STATUS_SUCCESS) { 1808 if (retval != STATUS_SUCCESS)
1899 return STATUS_FAIL; 1809 return STATUS_FAIL;
1900 }
1901 1810
1902 retval = ms_send_cmd(chip, BLOCK_WRITE, WAIT_INT); 1811 retval = ms_send_cmd(chip, BLOCK_WRITE, WAIT_INT);
1903 if (retval != STATUS_SUCCESS) { 1812 if (retval != STATUS_SUCCESS)
1904 return STATUS_FAIL; 1813 return STATUS_FAIL;
1905 }
1906 1814
1907 ms_set_err_code(chip, MS_NO_ERROR); 1815 ms_set_err_code(chip, MS_NO_ERROR);
1908 retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1); 1816 retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1);
1909 if (retval != STATUS_SUCCESS) { 1817 if (retval != STATUS_SUCCESS)
1910 return STATUS_FAIL; 1818 return STATUS_FAIL;
1911 }
1912 1819
1913 if (val & INT_REG_CMDNK) { 1820 if (val & INT_REG_CMDNK) {
1914 ms_set_err_code(chip, MS_CMD_NK); 1821 ms_set_err_code(chip, MS_CMD_NK);
@@ -1926,9 +1833,8 @@ static int ms_copy_page(struct rtsx_chip *chip, u16 old_blk, u16 new_blk,
1926 retval = ms_set_rw_reg_addr(chip, OverwriteFlag, 1833 retval = ms_set_rw_reg_addr(chip, OverwriteFlag,
1927 MS_EXTRA_SIZE, SystemParm, 1834 MS_EXTRA_SIZE, SystemParm,
1928 7); 1835 7);
1929 if (retval != STATUS_SUCCESS) { 1836 if (retval != STATUS_SUCCESS)
1930 return STATUS_FAIL; 1837 return STATUS_FAIL;
1931 }
1932 1838
1933 ms_set_err_code(chip, MS_NO_ERROR); 1839 ms_set_err_code(chip, MS_NO_ERROR);
1934 1840
@@ -1947,21 +1853,18 @@ static int ms_copy_page(struct rtsx_chip *chip, u16 old_blk, u16 new_blk,
1947 1853
1948 retval = ms_write_bytes(chip, WRITE_REG, 7, 1854 retval = ms_write_bytes(chip, WRITE_REG, 7,
1949 NO_WAIT_INT, data, 8); 1855 NO_WAIT_INT, data, 8);
1950 if (retval != STATUS_SUCCESS) { 1856 if (retval != STATUS_SUCCESS)
1951 return STATUS_FAIL; 1857 return STATUS_FAIL;
1952 }
1953 1858
1954 retval = ms_send_cmd(chip, BLOCK_WRITE, WAIT_INT); 1859 retval = ms_send_cmd(chip, BLOCK_WRITE, WAIT_INT);
1955 if (retval != STATUS_SUCCESS) { 1860 if (retval != STATUS_SUCCESS)
1956 return STATUS_FAIL; 1861 return STATUS_FAIL;
1957 }
1958 1862
1959 ms_set_err_code(chip, MS_NO_ERROR); 1863 ms_set_err_code(chip, MS_NO_ERROR);
1960 retval = ms_read_bytes(chip, GET_INT, 1, 1864 retval = ms_read_bytes(chip, GET_INT, 1,
1961 NO_WAIT_INT, &val, 1); 1865 NO_WAIT_INT, &val, 1);
1962 if (retval != STATUS_SUCCESS) { 1866 if (retval != STATUS_SUCCESS)
1963 return STATUS_FAIL; 1867 return STATUS_FAIL;
1964 }
1965 1868
1966 if (val & INT_REG_CMDNK) { 1869 if (val & INT_REG_CMDNK) {
1967 ms_set_err_code(chip, MS_CMD_NK); 1870 ms_set_err_code(chip, MS_CMD_NK);
@@ -1992,26 +1895,23 @@ static int reset_ms(struct rtsx_chip *chip)
1992#endif 1895#endif
1993 1896
1994 retval = ms_prepare_reset(chip); 1897 retval = ms_prepare_reset(chip);
1995 if (retval != STATUS_SUCCESS) { 1898 if (retval != STATUS_SUCCESS)
1996 return STATUS_FAIL; 1899 return STATUS_FAIL;
1997 }
1998 1900
1999 ms_card->ms_type |= TYPE_MS; 1901 ms_card->ms_type |= TYPE_MS;
2000 1902
2001 retval = ms_send_cmd(chip, MS_RESET, NO_WAIT_INT); 1903 retval = ms_send_cmd(chip, MS_RESET, NO_WAIT_INT);
2002 if (retval != STATUS_SUCCESS) { 1904 if (retval != STATUS_SUCCESS)
2003 return STATUS_FAIL; 1905 return STATUS_FAIL;
2004 }
2005 1906
2006 retval = ms_read_status_reg(chip); 1907 retval = ms_read_status_reg(chip);
2007 if (retval != STATUS_SUCCESS) { 1908 if (retval != STATUS_SUCCESS)
2008 return STATUS_FAIL; 1909 return STATUS_FAIL;
2009 }
2010 1910
2011 retval = rtsx_read_register(chip, PPBUF_BASE2, &val); 1911 retval = rtsx_read_register(chip, PPBUF_BASE2, &val);
2012 if (retval) { 1912 if (retval)
2013 return retval; 1913 return retval;
2014 } 1914
2015 if (val & WRT_PRTCT) 1915 if (val & WRT_PRTCT)
2016 chip->card_wp |= MS_CARD; 1916 chip->card_wp |= MS_CARD;
2017 else 1917 else
@@ -2059,9 +1959,8 @@ RE_SEARCH:
2059 } 1959 }
2060 1960
2061 retval = ms_read_page(chip, ms_card->boot_block, 0); 1961 retval = ms_read_page(chip, ms_card->boot_block, 0);
2062 if (retval != STATUS_SUCCESS) { 1962 if (retval != STATUS_SUCCESS)
2063 return STATUS_FAIL; 1963 return STATUS_FAIL;
2064 }
2065 1964
2066 /* Read MS system information as sys_info */ 1965 /* Read MS system information as sys_info */
2067 rtsx_init_cmd(chip); 1966 rtsx_init_cmd(chip);
@@ -2070,9 +1969,8 @@ RE_SEARCH:
2070 rtsx_add_cmd(chip, READ_REG_CMD, PPBUF_BASE2 + 0x1A0 + i, 0, 0); 1969 rtsx_add_cmd(chip, READ_REG_CMD, PPBUF_BASE2 + 0x1A0 + i, 0, 0);
2071 1970
2072 retval = rtsx_send_cmd(chip, MS_CARD, 100); 1971 retval = rtsx_send_cmd(chip, MS_CARD, 100);
2073 if (retval < 0) { 1972 if (retval < 0)
2074 return STATUS_FAIL; 1973 return STATUS_FAIL;
2075 }
2076 1974
2077 ptr = rtsx_get_cmd_data(chip); 1975 ptr = rtsx_get_cmd_data(chip);
2078 memcpy(ms_card->raw_sys_info, ptr, 96); 1976 memcpy(ms_card->raw_sys_info, ptr, 96);
@@ -2094,9 +1992,8 @@ RE_SEARCH:
2094 rtsx_add_cmd(chip, READ_REG_CMD, MS_4bit_Support, 0, 0); 1992 rtsx_add_cmd(chip, READ_REG_CMD, MS_4bit_Support, 0, 0);
2095 1993
2096 retval = rtsx_send_cmd(chip, MS_CARD, 100); 1994 retval = rtsx_send_cmd(chip, MS_CARD, 100);
2097 if (retval < 0) { 1995 if (retval < 0)
2098 return STATUS_FAIL; 1996 return STATUS_FAIL;
2099 }
2100 1997
2101 ptr = rtsx_get_cmd_data(chip); 1998 ptr = rtsx_get_cmd_data(chip);
2102 1999
@@ -2169,33 +2066,29 @@ RE_SEARCH:
2169 /* Switch I/F Mode */ 2066 /* Switch I/F Mode */
2170 if (ptr[15]) { 2067 if (ptr[15]) {
2171 retval = ms_set_rw_reg_addr(chip, 0, 0, SystemParm, 1); 2068 retval = ms_set_rw_reg_addr(chip, 0, 0, SystemParm, 1);
2172 if (retval != STATUS_SUCCESS) { 2069 if (retval != STATUS_SUCCESS)
2173 return STATUS_FAIL; 2070 return STATUS_FAIL;
2174 }
2175 2071
2176 retval = rtsx_write_register(chip, PPBUF_BASE2, 0xFF, 0x88); 2072 retval = rtsx_write_register(chip, PPBUF_BASE2, 0xFF, 0x88);
2177 if (retval) { 2073 if (retval)
2178 return retval; 2074 return retval;
2179 } 2075
2180 retval = rtsx_write_register(chip, PPBUF_BASE2 + 1, 0xFF, 0); 2076 retval = rtsx_write_register(chip, PPBUF_BASE2 + 1, 0xFF, 0);
2181 if (retval) { 2077 if (retval)
2182 return retval; 2078 return retval;
2183 }
2184 2079
2185 retval = ms_transfer_tpc(chip, MS_TM_WRITE_BYTES, WRITE_REG, 1, 2080 retval = ms_transfer_tpc(chip, MS_TM_WRITE_BYTES, WRITE_REG, 1,
2186 NO_WAIT_INT); 2081 NO_WAIT_INT);
2187 if (retval != STATUS_SUCCESS) { 2082 if (retval != STATUS_SUCCESS)
2188 return STATUS_FAIL; 2083 return STATUS_FAIL;
2189 }
2190 2084
2191 retval = rtsx_write_register(chip, MS_CFG, 2085 retval = rtsx_write_register(chip, MS_CFG,
2192 0x58 | MS_NO_CHECK_INT, 2086 0x58 | MS_NO_CHECK_INT,
2193 MS_BUS_WIDTH_4 | 2087 MS_BUS_WIDTH_4 |
2194 PUSH_TIME_ODD | 2088 PUSH_TIME_ODD |
2195 MS_NO_CHECK_INT); 2089 MS_NO_CHECK_INT);
2196 if (retval) { 2090 if (retval)
2197 return retval; 2091 return retval;
2198 }
2199 2092
2200 ms_card->ms_type |= MS_4BIT; 2093 ms_card->ms_type |= MS_4BIT;
2201 } 2094 }
@@ -2221,28 +2114,24 @@ static int ms_init_l2p_tbl(struct rtsx_chip *chip)
2221 2114
2222 size = ms_card->segment_cnt * sizeof(struct zone_entry); 2115 size = ms_card->segment_cnt * sizeof(struct zone_entry);
2223 ms_card->segment = vzalloc(size); 2116 ms_card->segment = vzalloc(size);
2224 if (!ms_card->segment) { 2117 if (!ms_card->segment)
2225 return STATUS_FAIL; 2118 return STATUS_FAIL;
2226 }
2227 2119
2228 retval = ms_read_page(chip, ms_card->boot_block, 1); 2120 retval = ms_read_page(chip, ms_card->boot_block, 1);
2229 if (retval != STATUS_SUCCESS) { 2121 if (retval != STATUS_SUCCESS)
2230 goto INIT_FAIL; 2122 goto INIT_FAIL;
2231 }
2232 2123
2233 reg_addr = PPBUF_BASE2; 2124 reg_addr = PPBUF_BASE2;
2234 for (i = 0; i < (((ms_card->total_block >> 9) * 10) + 1); i++) { 2125 for (i = 0; i < (((ms_card->total_block >> 9) * 10) + 1); i++) {
2235 int block_no; 2126 int block_no;
2236 2127
2237 retval = rtsx_read_register(chip, reg_addr++, &val1); 2128 retval = rtsx_read_register(chip, reg_addr++, &val1);
2238 if (retval != STATUS_SUCCESS) { 2129 if (retval != STATUS_SUCCESS)
2239 goto INIT_FAIL; 2130 goto INIT_FAIL;
2240 }
2241 2131
2242 retval = rtsx_read_register(chip, reg_addr++, &val2); 2132 retval = rtsx_read_register(chip, reg_addr++, &val2);
2243 if (retval != STATUS_SUCCESS) { 2133 if (retval != STATUS_SUCCESS)
2244 goto INIT_FAIL; 2134 goto INIT_FAIL;
2245 }
2246 2135
2247 defect_block = ((u16)val1 << 8) | val2; 2136 defect_block = ((u16)val1 << 8) | val2;
2248 if (defect_block == 0xFFFF) 2137 if (defect_block == 0xFFFF)
@@ -2403,9 +2292,8 @@ static int ms_build_l2p_tbl(struct rtsx_chip *chip, int seg_no)
2403 2292
2404 if (!ms_card->segment) { 2293 if (!ms_card->segment) {
2405 retval = ms_init_l2p_tbl(chip); 2294 retval = ms_init_l2p_tbl(chip);
2406 if (retval != STATUS_SUCCESS) { 2295 if (retval != STATUS_SUCCESS)
2407 return retval; 2296 return retval;
2408 }
2409 } 2297 }
2410 2298
2411 if (ms_card->segment[seg_no].build_flag) { 2299 if (ms_card->segment[seg_no].build_flag) {
@@ -2423,17 +2311,15 @@ static int ms_build_l2p_tbl(struct rtsx_chip *chip, int seg_no)
2423 2311
2424 if (!segment->l2p_table) { 2312 if (!segment->l2p_table) {
2425 segment->l2p_table = vmalloc(array_size(table_size, 2)); 2313 segment->l2p_table = vmalloc(array_size(table_size, 2));
2426 if (!segment->l2p_table) { 2314 if (!segment->l2p_table)
2427 goto BUILD_FAIL; 2315 goto BUILD_FAIL;
2428 }
2429 } 2316 }
2430 memset((u8 *)(segment->l2p_table), 0xff, table_size * 2); 2317 memset((u8 *)(segment->l2p_table), 0xff, table_size * 2);
2431 2318
2432 if (!segment->free_table) { 2319 if (!segment->free_table) {
2433 segment->free_table = vmalloc(MS_FREE_TABLE_CNT * 2); 2320 segment->free_table = vmalloc(MS_FREE_TABLE_CNT * 2);
2434 if (!segment->free_table) { 2321 if (!segment->free_table)
2435 goto BUILD_FAIL; 2322 goto BUILD_FAIL;
2436 }
2437 } 2323 }
2438 memset((u8 *)(segment->free_table), 0xff, MS_FREE_TABLE_CNT * 2); 2324 memset((u8 *)(segment->free_table), 0xff, MS_FREE_TABLE_CNT * 2);
2439 2325
@@ -2558,9 +2444,8 @@ static int ms_build_l2p_tbl(struct rtsx_chip *chip, int seg_no)
2558 return STATUS_SUCCESS; 2444 return STATUS_SUCCESS;
2559 } 2445 }
2560 retval = ms_init_page(chip, phy_blk, log_blk, 0, 1); 2446 retval = ms_init_page(chip, phy_blk, log_blk, 0, 1);
2561 if (retval != STATUS_SUCCESS) { 2447 if (retval != STATUS_SUCCESS)
2562 goto BUILD_FAIL; 2448 goto BUILD_FAIL;
2563 }
2564 2449
2565 segment->l2p_table[idx] = phy_blk; 2450 segment->l2p_table[idx] = phy_blk;
2566 if (seg_no == ms_card->segment_cnt - 1) { 2451 if (seg_no == ms_card->segment_cnt - 1) {
@@ -2591,16 +2476,14 @@ static int ms_build_l2p_tbl(struct rtsx_chip *chip, int seg_no)
2591 retval = ms_copy_page(chip, tmp_blk, phy_blk, 2476 retval = ms_copy_page(chip, tmp_blk, phy_blk,
2592 log_blk, 0, 2477 log_blk, 0,
2593 ms_card->page_off + 1); 2478 ms_card->page_off + 1);
2594 if (retval != STATUS_SUCCESS) { 2479 if (retval != STATUS_SUCCESS)
2595 return STATUS_FAIL; 2480 return STATUS_FAIL;
2596 }
2597 2481
2598 segment->l2p_table[log_blk] = phy_blk; 2482 segment->l2p_table[log_blk] = phy_blk;
2599 2483
2600 retval = ms_set_bad_block(chip, tmp_blk); 2484 retval = ms_set_bad_block(chip, tmp_blk);
2601 if (retval != STATUS_SUCCESS) { 2485 if (retval != STATUS_SUCCESS)
2602 return STATUS_FAIL; 2486 return STATUS_FAIL;
2603 }
2604 } 2487 }
2605 } 2488 }
2606 } 2489 }
@@ -2626,14 +2509,12 @@ int reset_ms_card(struct rtsx_chip *chip)
2626 memset(ms_card, 0, sizeof(struct ms_info)); 2509 memset(ms_card, 0, sizeof(struct ms_info));
2627 2510
2628 retval = enable_card_clock(chip, MS_CARD); 2511 retval = enable_card_clock(chip, MS_CARD);
2629 if (retval != STATUS_SUCCESS) { 2512 if (retval != STATUS_SUCCESS)
2630 return STATUS_FAIL; 2513 return STATUS_FAIL;
2631 }
2632 2514
2633 retval = select_card(chip, MS_CARD); 2515 retval = select_card(chip, MS_CARD);
2634 if (retval != STATUS_SUCCESS) { 2516 if (retval != STATUS_SUCCESS)
2635 return STATUS_FAIL; 2517 return STATUS_FAIL;
2636 }
2637 2518
2638 ms_card->ms_type = 0; 2519 ms_card->ms_type = 0;
2639 2520
@@ -2641,27 +2522,24 @@ int reset_ms_card(struct rtsx_chip *chip)
2641 if (retval != STATUS_SUCCESS) { 2522 if (retval != STATUS_SUCCESS) {
2642 if (ms_card->check_ms_flow) { 2523 if (ms_card->check_ms_flow) {
2643 retval = reset_ms(chip); 2524 retval = reset_ms(chip);
2644 if (retval != STATUS_SUCCESS) { 2525 if (retval != STATUS_SUCCESS)
2645 return STATUS_FAIL; 2526 return STATUS_FAIL;
2646 }
2647 } else { 2527 } else {
2648 return STATUS_FAIL; 2528 return STATUS_FAIL;
2649 } 2529 }
2650 } 2530 }
2651 2531
2652 retval = ms_set_init_para(chip); 2532 retval = ms_set_init_para(chip);
2653 if (retval != STATUS_SUCCESS) { 2533 if (retval != STATUS_SUCCESS)
2654 return STATUS_FAIL; 2534 return STATUS_FAIL;
2655 }
2656 2535
2657 if (!CHK_MSPRO(ms_card)) { 2536 if (!CHK_MSPRO(ms_card)) {
2658 /* Build table for the last segment, 2537 /* Build table for the last segment,
2659 * to check if L2P table block exists, erasing it 2538 * to check if L2P table block exists, erasing it
2660 */ 2539 */
2661 retval = ms_build_l2p_tbl(chip, seg_no); 2540 retval = ms_build_l2p_tbl(chip, seg_no);
2662 if (retval != STATUS_SUCCESS) { 2541 if (retval != STATUS_SUCCESS)
2663 return STATUS_FAIL; 2542 return STATUS_FAIL;
2664 }
2665 } 2543 }
2666 2544
2667 dev_dbg(rtsx_dev(chip), "ms_card->ms_type = 0x%x\n", ms_card->ms_type); 2545 dev_dbg(rtsx_dev(chip), "ms_card->ms_type = 0x%x\n", ms_card->ms_type);
@@ -2690,9 +2568,8 @@ static int mspro_set_rw_cmd(struct rtsx_chip *chip,
2690 if (retval == STATUS_SUCCESS) 2568 if (retval == STATUS_SUCCESS)
2691 break; 2569 break;
2692 } 2570 }
2693 if (i == MS_MAX_RETRY_COUNT) { 2571 if (i == MS_MAX_RETRY_COUNT)
2694 return STATUS_FAIL; 2572 return STATUS_FAIL;
2695 }
2696 2573
2697 return STATUS_SUCCESS; 2574 return STATUS_SUCCESS;
2698} 2575}
@@ -2731,9 +2608,8 @@ static inline int ms_auto_tune_clock(struct rtsx_chip *chip)
2731 } 2608 }
2732 2609
2733 retval = ms_switch_clock(chip); 2610 retval = ms_switch_clock(chip);
2734 if (retval != STATUS_SUCCESS) { 2611 if (retval != STATUS_SUCCESS)
2735 return STATUS_FAIL; 2612 return STATUS_FAIL;
2736 }
2737 2613
2738 return STATUS_SUCCESS; 2614 return STATUS_SUCCESS;
2739} 2615}
@@ -2782,9 +2658,8 @@ static int mspro_rw_multi_sector(struct scsi_cmnd *srb,
2782 } 2658 }
2783 2659
2784 retval = ms_switch_clock(chip); 2660 retval = ms_switch_clock(chip);
2785 if (retval != STATUS_SUCCESS) { 2661 if (retval != STATUS_SUCCESS)
2786 return STATUS_FAIL; 2662 return STATUS_FAIL;
2787 }
2788 2663
2789 if (srb->sc_data_direction == DMA_FROM_DEVICE) 2664 if (srb->sc_data_direction == DMA_FROM_DEVICE)
2790 trans_mode = MS_TM_AUTO_READ; 2665 trans_mode = MS_TM_AUTO_READ;
@@ -2792,9 +2667,8 @@ static int mspro_rw_multi_sector(struct scsi_cmnd *srb,
2792 trans_mode = MS_TM_AUTO_WRITE; 2667 trans_mode = MS_TM_AUTO_WRITE;
2793 2668
2794 retval = rtsx_read_register(chip, MS_TRANS_CFG, &val); 2669 retval = rtsx_read_register(chip, MS_TRANS_CFG, &val);
2795 if (retval) { 2670 if (retval)
2796 return retval; 2671 return retval;
2797 }
2798 2672
2799 if (ms_card->seq_mode) { 2673 if (ms_card->seq_mode) {
2800 if ((ms_card->pre_dir != srb->sc_data_direction) || 2674 if ((ms_card->pre_dir != srb->sc_data_direction) ||
@@ -2808,9 +2682,8 @@ static int mspro_rw_multi_sector(struct scsi_cmnd *srb,
2808 ms_card->total_sec_cnt = 0; 2682 ms_card->total_sec_cnt = 0;
2809 if (val & MS_INT_BREQ) { 2683 if (val & MS_INT_BREQ) {
2810 retval = ms_send_cmd(chip, PRO_STOP, WAIT_INT); 2684 retval = ms_send_cmd(chip, PRO_STOP, WAIT_INT);
2811 if (retval != STATUS_SUCCESS) { 2685 if (retval != STATUS_SUCCESS)
2812 return STATUS_FAIL; 2686 return STATUS_FAIL;
2813 }
2814 2687
2815 rtsx_write_register(chip, RBCTL, RB_FLUSH, 2688 rtsx_write_register(chip, RBCTL, RB_FLUSH,
2816 RB_FLUSH); 2689 RB_FLUSH);
@@ -3019,14 +2892,12 @@ int mspro_format(struct scsi_cmnd *srb, struct rtsx_chip *chip,
3019 u16 para; 2892 u16 para;
3020 2893
3021 retval = ms_switch_clock(chip); 2894 retval = ms_switch_clock(chip);
3022 if (retval != STATUS_SUCCESS) { 2895 if (retval != STATUS_SUCCESS)
3023 return STATUS_FAIL; 2896 return STATUS_FAIL;
3024 }
3025 2897
3026 retval = ms_set_rw_reg_addr(chip, 0x00, 0x00, Pro_TPCParm, 0x01); 2898 retval = ms_set_rw_reg_addr(chip, 0x00, 0x00, Pro_TPCParm, 0x01);
3027 if (retval != STATUS_SUCCESS) { 2899 if (retval != STATUS_SUCCESS)
3028 return STATUS_FAIL; 2900 return STATUS_FAIL;
3029 }
3030 2901
3031 memset(buf, 0, 2); 2902 memset(buf, 0, 2);
3032 switch (short_data_len) { 2903 switch (short_data_len) {
@@ -3051,9 +2922,8 @@ int mspro_format(struct scsi_cmnd *srb, struct rtsx_chip *chip,
3051 if (retval == STATUS_SUCCESS) 2922 if (retval == STATUS_SUCCESS)
3052 break; 2923 break;
3053 } 2924 }
3054 if (i == MS_MAX_RETRY_COUNT) { 2925 if (i == MS_MAX_RETRY_COUNT)
3055 return STATUS_FAIL; 2926 return STATUS_FAIL;
3056 }
3057 2927
3058 if (quick_format) 2928 if (quick_format)
3059 para = 0x0000; 2929 para = 0x0000;
@@ -3061,18 +2931,15 @@ int mspro_format(struct scsi_cmnd *srb, struct rtsx_chip *chip,
3061 para = 0x0001; 2931 para = 0x0001;
3062 2932
3063 retval = mspro_set_rw_cmd(chip, 0, para, PRO_FORMAT); 2933 retval = mspro_set_rw_cmd(chip, 0, para, PRO_FORMAT);
3064 if (retval != STATUS_SUCCESS) { 2934 if (retval != STATUS_SUCCESS)
3065 return STATUS_FAIL; 2935 return STATUS_FAIL;
3066 }
3067 2936
3068 retval = rtsx_read_register(chip, MS_TRANS_CFG, &tmp); 2937 retval = rtsx_read_register(chip, MS_TRANS_CFG, &tmp);
3069 if (retval) { 2938 if (retval)
3070 return retval; 2939 return retval;
3071 }
3072 2940
3073 if (tmp & (MS_INT_CMDNK | MS_INT_ERR)) { 2941 if (tmp & (MS_INT_CMDNK | MS_INT_ERR))
3074 return STATUS_FAIL; 2942 return STATUS_FAIL;
3075 }
3076 2943
3077 if ((tmp & (MS_INT_BREQ | MS_INT_CED)) == MS_INT_BREQ) { 2944 if ((tmp & (MS_INT_BREQ | MS_INT_CED)) == MS_INT_BREQ) {
3078 ms_card->pro_under_formatting = 1; 2945 ms_card->pro_under_formatting = 1;
@@ -3113,9 +2980,8 @@ static int ms_read_multiple_pages(struct rtsx_chip *chip, u16 phy_blk,
3113 2980
3114 retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE, 2981 retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE,
3115 SystemParm, 6); 2982 SystemParm, 6);
3116 if (retval != STATUS_SUCCESS) { 2983 if (retval != STATUS_SUCCESS)
3117 return STATUS_FAIL; 2984 return STATUS_FAIL;
3118 }
3119 2985
3120 if (CHK_MS4BIT(ms_card)) 2986 if (CHK_MS4BIT(ms_card))
3121 data[0] = 0x88; 2987 data[0] = 0x88;
@@ -3134,16 +3000,14 @@ static int ms_read_multiple_pages(struct rtsx_chip *chip, u16 phy_blk,
3134 if (retval == STATUS_SUCCESS) 3000 if (retval == STATUS_SUCCESS)
3135 break; 3001 break;
3136 } 3002 }
3137 if (i == MS_MAX_RETRY_COUNT) { 3003 if (i == MS_MAX_RETRY_COUNT)
3138 return STATUS_FAIL; 3004 return STATUS_FAIL;
3139 }
3140 3005
3141 ms_set_err_code(chip, MS_NO_ERROR); 3006 ms_set_err_code(chip, MS_NO_ERROR);
3142 3007
3143 retval = ms_send_cmd(chip, BLOCK_READ, WAIT_INT); 3008 retval = ms_send_cmd(chip, BLOCK_READ, WAIT_INT);
3144 if (retval != STATUS_SUCCESS) { 3009 if (retval != STATUS_SUCCESS)
3145 return STATUS_FAIL; 3010 return STATUS_FAIL;
3146 }
3147 3011
3148 ptr = buf; 3012 ptr = buf;
3149 3013
@@ -3156,9 +3020,8 @@ static int ms_read_multiple_pages(struct rtsx_chip *chip, u16 phy_blk,
3156 } 3020 }
3157 3021
3158 retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1); 3022 retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1);
3159 if (retval != STATUS_SUCCESS) { 3023 if (retval != STATUS_SUCCESS)
3160 return STATUS_FAIL; 3024 return STATUS_FAIL;
3161 }
3162 3025
3163 if (val & INT_REG_CMDNK) { 3026 if (val & INT_REG_CMDNK) {
3164 ms_set_err_code(chip, MS_CMD_NK); 3027 ms_set_err_code(chip, MS_CMD_NK);
@@ -3197,16 +3060,14 @@ static int ms_read_multiple_pages(struct rtsx_chip *chip, u16 phy_blk,
3197 if (page_addr == (end_page - 1)) { 3060 if (page_addr == (end_page - 1)) {
3198 if (!(val & INT_REG_CED)) { 3061 if (!(val & INT_REG_CED)) {
3199 retval = ms_send_cmd(chip, BLOCK_END, WAIT_INT); 3062 retval = ms_send_cmd(chip, BLOCK_END, WAIT_INT);
3200 if (retval != STATUS_SUCCESS) { 3063 if (retval != STATUS_SUCCESS)
3201 return STATUS_FAIL; 3064 return STATUS_FAIL;
3202 }
3203 } 3065 }
3204 3066
3205 retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, 3067 retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT,
3206 &val, 1); 3068 &val, 1);
3207 if (retval != STATUS_SUCCESS) { 3069 if (retval != STATUS_SUCCESS)
3208 return STATUS_FAIL; 3070 return STATUS_FAIL;
3209 }
3210 3071
3211 if (!(val & INT_REG_CED)) { 3072 if (!(val & INT_REG_CED)) {
3212 ms_set_err_code(chip, MS_FLASH_READ_ERROR); 3073 ms_set_err_code(chip, MS_FLASH_READ_ERROR);
@@ -3280,9 +3141,8 @@ static int ms_write_multiple_pages(struct rtsx_chip *chip, u16 old_blk,
3280 if (!start_page) { 3141 if (!start_page) {
3281 retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE, 3142 retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE,
3282 SystemParm, 7); 3143 SystemParm, 7);
3283 if (retval != STATUS_SUCCESS) { 3144 if (retval != STATUS_SUCCESS)
3284 return STATUS_FAIL; 3145 return STATUS_FAIL;
3285 }
3286 3146
3287 if (CHK_MS4BIT(ms_card)) 3147 if (CHK_MS4BIT(ms_card))
3288 data[0] = 0x88; 3148 data[0] = 0x88;
@@ -3299,28 +3159,24 @@ static int ms_write_multiple_pages(struct rtsx_chip *chip, u16 old_blk,
3299 3159
3300 retval = ms_write_bytes(chip, WRITE_REG, 7, NO_WAIT_INT, 3160 retval = ms_write_bytes(chip, WRITE_REG, 7, NO_WAIT_INT,
3301 data, 8); 3161 data, 8);
3302 if (retval != STATUS_SUCCESS) { 3162 if (retval != STATUS_SUCCESS)
3303 return STATUS_FAIL; 3163 return STATUS_FAIL;
3304 }
3305 3164
3306 retval = ms_send_cmd(chip, BLOCK_WRITE, WAIT_INT); 3165 retval = ms_send_cmd(chip, BLOCK_WRITE, WAIT_INT);
3307 if (retval != STATUS_SUCCESS) { 3166 if (retval != STATUS_SUCCESS)
3308 return STATUS_FAIL; 3167 return STATUS_FAIL;
3309 }
3310 3168
3311 ms_set_err_code(chip, MS_NO_ERROR); 3169 ms_set_err_code(chip, MS_NO_ERROR);
3312 retval = ms_transfer_tpc(chip, MS_TM_READ_BYTES, GET_INT, 1, 3170 retval = ms_transfer_tpc(chip, MS_TM_READ_BYTES, GET_INT, 1,
3313 NO_WAIT_INT); 3171 NO_WAIT_INT);
3314 if (retval != STATUS_SUCCESS) { 3172 if (retval != STATUS_SUCCESS)
3315 return STATUS_FAIL; 3173 return STATUS_FAIL;
3316 }
3317 } 3174 }
3318 3175
3319 retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE, 3176 retval = ms_set_rw_reg_addr(chip, OverwriteFlag, MS_EXTRA_SIZE,
3320 SystemParm, (6 + MS_EXTRA_SIZE)); 3177 SystemParm, (6 + MS_EXTRA_SIZE));
3321 if (retval != STATUS_SUCCESS) { 3178 if (retval != STATUS_SUCCESS)
3322 return STATUS_FAIL; 3179 return STATUS_FAIL;
3323 }
3324 3180
3325 ms_set_err_code(chip, MS_NO_ERROR); 3181 ms_set_err_code(chip, MS_NO_ERROR);
3326 3182
@@ -3352,23 +3208,20 @@ static int ms_write_multiple_pages(struct rtsx_chip *chip, u16 old_blk,
3352 if (retval == STATUS_SUCCESS) 3208 if (retval == STATUS_SUCCESS)
3353 break; 3209 break;
3354 } 3210 }
3355 if (i == MS_MAX_RETRY_COUNT) { 3211 if (i == MS_MAX_RETRY_COUNT)
3356 return STATUS_FAIL; 3212 return STATUS_FAIL;
3357 }
3358 3213
3359 for (i = 0; i < MS_MAX_RETRY_COUNT; i++) { 3214 for (i = 0; i < MS_MAX_RETRY_COUNT; i++) {
3360 retval = ms_send_cmd(chip, BLOCK_WRITE, WAIT_INT); 3215 retval = ms_send_cmd(chip, BLOCK_WRITE, WAIT_INT);
3361 if (retval == STATUS_SUCCESS) 3216 if (retval == STATUS_SUCCESS)
3362 break; 3217 break;
3363 } 3218 }
3364 if (i == MS_MAX_RETRY_COUNT) { 3219 if (i == MS_MAX_RETRY_COUNT)
3365 return STATUS_FAIL; 3220 return STATUS_FAIL;
3366 }
3367 3221
3368 retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1); 3222 retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1);
3369 if (retval != STATUS_SUCCESS) { 3223 if (retval != STATUS_SUCCESS)
3370 return STATUS_FAIL; 3224 return STATUS_FAIL;
3371 }
3372 3225
3373 ptr = buf; 3226 ptr = buf;
3374 for (page_addr = start_page; page_addr < end_page; page_addr++) { 3227 for (page_addr = start_page; page_addr < end_page; page_addr++) {
@@ -3421,16 +3274,14 @@ static int ms_write_multiple_pages(struct rtsx_chip *chip, u16 old_blk,
3421 ms_set_err_code(chip, MS_TO_ERROR); 3274 ms_set_err_code(chip, MS_TO_ERROR);
3422 rtsx_clear_ms_error(chip); 3275 rtsx_clear_ms_error(chip);
3423 3276
3424 if (retval == -ETIMEDOUT) { 3277 if (retval == -ETIMEDOUT)
3425 return STATUS_TIMEDOUT; 3278 return STATUS_TIMEDOUT;
3426 }
3427 return STATUS_FAIL; 3279 return STATUS_FAIL;
3428 } 3280 }
3429 3281
3430 retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1); 3282 retval = ms_read_bytes(chip, GET_INT, 1, NO_WAIT_INT, &val, 1);
3431 if (retval != STATUS_SUCCESS) { 3283 if (retval != STATUS_SUCCESS)
3432 return STATUS_FAIL; 3284 return STATUS_FAIL;
3433 }
3434 3285
3435 if ((end_page - start_page) == 1) { 3286 if ((end_page - start_page) == 1) {
3436 if (!(val & INT_REG_CED)) { 3287 if (!(val & INT_REG_CED)) {
@@ -3442,16 +3293,14 @@ static int ms_write_multiple_pages(struct rtsx_chip *chip, u16 old_blk,
3442 if (!(val & INT_REG_CED)) { 3293 if (!(val & INT_REG_CED)) {
3443 retval = ms_send_cmd(chip, BLOCK_END, 3294 retval = ms_send_cmd(chip, BLOCK_END,
3444 WAIT_INT); 3295 WAIT_INT);
3445 if (retval != STATUS_SUCCESS) { 3296 if (retval != STATUS_SUCCESS)
3446 return STATUS_FAIL; 3297 return STATUS_FAIL;
3447 }
3448 } 3298 }
3449 3299
3450 retval = ms_read_bytes(chip, GET_INT, 1, 3300 retval = ms_read_bytes(chip, GET_INT, 1,
3451 NO_WAIT_INT, &val, 1); 3301 NO_WAIT_INT, &val, 1);
3452 if (retval != STATUS_SUCCESS) { 3302 if (retval != STATUS_SUCCESS)
3453 return STATUS_FAIL; 3303 return STATUS_FAIL;
3454 }
3455 } 3304 }
3456 3305
3457 if ((page_addr == (end_page - 1)) || 3306 if ((page_addr == (end_page - 1)) ||
@@ -3479,9 +3328,8 @@ static int ms_finish_write(struct rtsx_chip *chip, u16 old_blk, u16 new_blk,
3479 3328
3480 retval = ms_copy_page(chip, old_blk, new_blk, log_blk, 3329 retval = ms_copy_page(chip, old_blk, new_blk, log_blk,
3481 page_off, ms_card->page_off + 1); 3330 page_off, ms_card->page_off + 1);
3482 if (retval != STATUS_SUCCESS) { 3331 if (retval != STATUS_SUCCESS)
3483 return STATUS_FAIL; 3332 return STATUS_FAIL;
3484 }
3485 3333
3486 seg_no = old_blk >> 9; 3334 seg_no = old_blk >> 9;
3487 3335
@@ -3507,9 +3355,8 @@ static int ms_prepare_write(struct rtsx_chip *chip, u16 old_blk, u16 new_blk,
3507 if (start_page) { 3355 if (start_page) {
3508 retval = ms_copy_page(chip, old_blk, new_blk, log_blk, 3356 retval = ms_copy_page(chip, old_blk, new_blk, log_blk,
3509 0, start_page); 3357 0, start_page);
3510 if (retval != STATUS_SUCCESS) { 3358 if (retval != STATUS_SUCCESS)
3511 return STATUS_FAIL; 3359 return STATUS_FAIL;
3512 }
3513 } 3360 }
3514 3361
3515 return STATUS_SUCCESS; 3362 return STATUS_SUCCESS;
@@ -3524,9 +3371,8 @@ int ms_delay_write(struct rtsx_chip *chip)
3524 3371
3525 if (delay_write->delay_write_flag) { 3372 if (delay_write->delay_write_flag) {
3526 retval = ms_set_init_para(chip); 3373 retval = ms_set_init_para(chip);
3527 if (retval != STATUS_SUCCESS) { 3374 if (retval != STATUS_SUCCESS)
3528 return STATUS_FAIL; 3375 return STATUS_FAIL;
3529 }
3530 3376
3531 delay_write->delay_write_flag = 0; 3377 delay_write->delay_write_flag = 0;
3532 retval = ms_finish_write(chip, 3378 retval = ms_finish_write(chip,
@@ -3534,9 +3380,8 @@ int ms_delay_write(struct rtsx_chip *chip)
3534 delay_write->new_phyblock, 3380 delay_write->new_phyblock,
3535 delay_write->logblock, 3381 delay_write->logblock,
3536 delay_write->pageoff); 3382 delay_write->pageoff);
3537 if (retval != STATUS_SUCCESS) { 3383 if (retval != STATUS_SUCCESS)
3538 return STATUS_FAIL; 3384 return STATUS_FAIL;
3539 }
3540 } 3385 }
3541 3386
3542 return STATUS_SUCCESS; 3387 return STATUS_SUCCESS;
@@ -3850,14 +3695,12 @@ static int ms_poll_int(struct rtsx_chip *chip)
3850 rtsx_add_cmd(chip, CHECK_REG_CMD, MS_TRANS_CFG, MS_INT_CED, MS_INT_CED); 3695 rtsx_add_cmd(chip, CHECK_REG_CMD, MS_TRANS_CFG, MS_INT_CED, MS_INT_CED);
3851 3696
3852 retval = rtsx_send_cmd(chip, MS_CARD, 5000); 3697 retval = rtsx_send_cmd(chip, MS_CARD, 5000);
3853 if (retval != STATUS_SUCCESS) { 3698 if (retval != STATUS_SUCCESS)
3854 return STATUS_FAIL; 3699 return STATUS_FAIL;
3855 }
3856 3700
3857 val = *rtsx_get_cmd_data(chip); 3701 val = *rtsx_get_cmd_data(chip);
3858 if (val & MS_INT_ERR) { 3702 if (val & MS_INT_ERR)
3859 return STATUS_FAIL; 3703 return STATUS_FAIL;
3860 }
3861 3704
3862 return STATUS_SUCCESS; 3705 return STATUS_SUCCESS;
3863} 3706}
@@ -3920,9 +3763,8 @@ static int mg_send_ex_cmd(struct rtsx_chip *chip, u8 cmd, u8 entry_num)
3920 if (retval == STATUS_SUCCESS) 3763 if (retval == STATUS_SUCCESS)
3921 break; 3764 break;
3922 } 3765 }
3923 if (i == MS_MAX_RETRY_COUNT) { 3766 if (i == MS_MAX_RETRY_COUNT)
3924 return STATUS_FAIL; 3767 return STATUS_FAIL;
3925 }
3926 3768
3927 if (check_ms_err(chip)) { 3769 if (check_ms_err(chip)) {
3928 rtsx_clear_ms_error(chip); 3770 rtsx_clear_ms_error(chip);
@@ -3943,9 +3785,8 @@ static int mg_set_tpc_para_sub(struct rtsx_chip *chip, int type,
3943 else 3785 else
3944 retval = ms_set_rw_reg_addr(chip, 0, 0, Pro_DataCount1, 6); 3786 retval = ms_set_rw_reg_addr(chip, 0, 0, Pro_DataCount1, 6);
3945 3787
3946 if (retval != STATUS_SUCCESS) { 3788 if (retval != STATUS_SUCCESS)
3947 return STATUS_FAIL; 3789 return STATUS_FAIL;
3948 }
3949 3790
3950 buf[0] = 0; 3791 buf[0] = 0;
3951 buf[1] = 0; 3792 buf[1] = 0;
@@ -3957,9 +3798,8 @@ static int mg_set_tpc_para_sub(struct rtsx_chip *chip, int type,
3957 } 3798 }
3958 retval = ms_write_bytes(chip, PRO_WRITE_REG, (type == 0) ? 1 : 6, 3799 retval = ms_write_bytes(chip, PRO_WRITE_REG, (type == 0) ? 1 : 6,
3959 NO_WAIT_INT, buf, 6); 3800 NO_WAIT_INT, buf, 6);
3960 if (retval != STATUS_SUCCESS) { 3801 if (retval != STATUS_SUCCESS)
3961 return STATUS_FAIL; 3802 return STATUS_FAIL;
3962 }
3963 3803
3964 return STATUS_SUCCESS; 3804 return STATUS_SUCCESS;
3965} 3805}
@@ -3979,9 +3819,8 @@ int mg_set_leaf_id(struct scsi_cmnd *srb, struct rtsx_chip *chip)
3979 ms_cleanup_work(chip); 3819 ms_cleanup_work(chip);
3980 3820
3981 retval = ms_switch_clock(chip); 3821 retval = ms_switch_clock(chip);
3982 if (retval != STATUS_SUCCESS) { 3822 if (retval != STATUS_SUCCESS)
3983 return STATUS_FAIL; 3823 return STATUS_FAIL;
3984 }
3985 3824
3986 retval = mg_send_ex_cmd(chip, MG_SET_LID, 0); 3825 retval = mg_send_ex_cmd(chip, MG_SET_LID, 0);
3987 if (retval != STATUS_SUCCESS) { 3826 if (retval != STATUS_SUCCESS) {
@@ -4019,14 +3858,12 @@ int mg_get_local_EKB(struct scsi_cmnd *srb, struct rtsx_chip *chip)
4019 ms_cleanup_work(chip); 3858 ms_cleanup_work(chip);
4020 3859
4021 retval = ms_switch_clock(chip); 3860 retval = ms_switch_clock(chip);
4022 if (retval != STATUS_SUCCESS) { 3861 if (retval != STATUS_SUCCESS)
4023 return STATUS_FAIL; 3862 return STATUS_FAIL;
4024 }
4025 3863
4026 buf = kmalloc(1540, GFP_KERNEL); 3864 buf = kmalloc(1540, GFP_KERNEL);
4027 if (!buf) { 3865 if (!buf)
4028 return STATUS_ERROR; 3866 return STATUS_ERROR;
4029 }
4030 3867
4031 buf[0] = 0x04; 3868 buf[0] = 0x04;
4032 buf[1] = 0x1A; 3869 buf[1] = 0x1A;
@@ -4073,9 +3910,8 @@ int mg_chg(struct scsi_cmnd *srb, struct rtsx_chip *chip)
4073 ms_cleanup_work(chip); 3910 ms_cleanup_work(chip);
4074 3911
4075 retval = ms_switch_clock(chip); 3912 retval = ms_switch_clock(chip);
4076 if (retval != STATUS_SUCCESS) { 3913 if (retval != STATUS_SUCCESS)
4077 return STATUS_FAIL; 3914 return STATUS_FAIL;
4078 }
4079 3915
4080 retval = mg_send_ex_cmd(chip, MG_GET_ID, 0); 3916 retval = mg_send_ex_cmd(chip, MG_GET_ID, 0);
4081 if (retval != STATUS_SUCCESS) { 3917 if (retval != STATUS_SUCCESS) {
@@ -4148,9 +3984,8 @@ int mg_get_rsp_chg(struct scsi_cmnd *srb, struct rtsx_chip *chip)
4148 ms_cleanup_work(chip); 3984 ms_cleanup_work(chip);
4149 3985
4150 retval = ms_switch_clock(chip); 3986 retval = ms_switch_clock(chip);
4151 if (retval != STATUS_SUCCESS) { 3987 if (retval != STATUS_SUCCESS)
4152 return STATUS_FAIL; 3988 return STATUS_FAIL;
4153 }
4154 3989
4155 retval = mg_send_ex_cmd(chip, MG_MAKE_RMS, 0); 3990 retval = mg_send_ex_cmd(chip, MG_MAKE_RMS, 0);
4156 if (retval != STATUS_SUCCESS) { 3991 if (retval != STATUS_SUCCESS) {
@@ -4204,9 +4039,8 @@ int mg_rsp(struct scsi_cmnd *srb, struct rtsx_chip *chip)
4204 ms_cleanup_work(chip); 4039 ms_cleanup_work(chip);
4205 4040
4206 retval = ms_switch_clock(chip); 4041 retval = ms_switch_clock(chip);
4207 if (retval != STATUS_SUCCESS) { 4042 if (retval != STATUS_SUCCESS)
4208 return STATUS_FAIL; 4043 return STATUS_FAIL;
4209 }
4210 4044
4211 retval = mg_send_ex_cmd(chip, MG_MAKE_KSE, 0); 4045 retval = mg_send_ex_cmd(chip, MG_MAKE_KSE, 0);
4212 if (retval != STATUS_SUCCESS) { 4046 if (retval != STATUS_SUCCESS) {
@@ -4251,14 +4085,12 @@ int mg_get_ICV(struct scsi_cmnd *srb, struct rtsx_chip *chip)
4251 ms_cleanup_work(chip); 4085 ms_cleanup_work(chip);
4252 4086
4253 retval = ms_switch_clock(chip); 4087 retval = ms_switch_clock(chip);
4254 if (retval != STATUS_SUCCESS) { 4088 if (retval != STATUS_SUCCESS)
4255 return STATUS_FAIL; 4089 return STATUS_FAIL;
4256 }
4257 4090
4258 buf = kmalloc(1028, GFP_KERNEL); 4091 buf = kmalloc(1028, GFP_KERNEL);
4259 if (!buf) { 4092 if (!buf)
4260 return STATUS_ERROR; 4093 return STATUS_ERROR;
4261 }
4262 4094
4263 buf[0] = 0x04; 4095 buf[0] = 0x04;
4264 buf[1] = 0x02; 4096 buf[1] = 0x02;
@@ -4307,14 +4139,12 @@ int mg_set_ICV(struct scsi_cmnd *srb, struct rtsx_chip *chip)
4307 ms_cleanup_work(chip); 4139 ms_cleanup_work(chip);
4308 4140
4309 retval = ms_switch_clock(chip); 4141 retval = ms_switch_clock(chip);
4310 if (retval != STATUS_SUCCESS) { 4142 if (retval != STATUS_SUCCESS)
4311 return STATUS_FAIL; 4143 return STATUS_FAIL;
4312 }
4313 4144
4314 buf = kmalloc(1028, GFP_KERNEL); 4145 buf = kmalloc(1028, GFP_KERNEL);
4315 if (!buf) { 4146 if (!buf)
4316 return STATUS_ERROR; 4147 return STATUS_ERROR;
4317 }
4318 4148
4319 bufflen = min_t(int, 1028, scsi_bufflen(srb)); 4149 bufflen = min_t(int, 1028, scsi_bufflen(srb));
4320 rtsx_stor_get_xfer_buf(buf, bufflen, srb); 4150 rtsx_stor_get_xfer_buf(buf, bufflen, srb);
@@ -4433,32 +4263,28 @@ int ms_power_off_card3v3(struct rtsx_chip *chip)
4433 int retval; 4263 int retval;
4434 4264
4435 retval = disable_card_clock(chip, MS_CARD); 4265 retval = disable_card_clock(chip, MS_CARD);
4436 if (retval != STATUS_SUCCESS) { 4266 if (retval != STATUS_SUCCESS)
4437 return STATUS_FAIL; 4267 return STATUS_FAIL;
4438 }
4439 4268
4440 if (chip->asic_code) { 4269 if (chip->asic_code) {
4441 retval = ms_pull_ctl_disable(chip); 4270 retval = ms_pull_ctl_disable(chip);
4442 if (retval != STATUS_SUCCESS) { 4271 if (retval != STATUS_SUCCESS)
4443 return STATUS_FAIL; 4272 return STATUS_FAIL;
4444 }
4445 } else { 4273 } else {
4446 retval = rtsx_write_register(chip, FPGA_PULL_CTL, 4274 retval = rtsx_write_register(chip, FPGA_PULL_CTL,
4447 FPGA_MS_PULL_CTL_BIT | 0x20, 4275 FPGA_MS_PULL_CTL_BIT | 0x20,
4448 FPGA_MS_PULL_CTL_BIT); 4276 FPGA_MS_PULL_CTL_BIT);
4449 if (retval) { 4277 if (retval)
4450 return retval; 4278 return retval;
4451 }
4452 } 4279 }
4453 retval = rtsx_write_register(chip, CARD_OE, MS_OUTPUT_EN, 0); 4280 retval = rtsx_write_register(chip, CARD_OE, MS_OUTPUT_EN, 0);
4454 if (retval) { 4281 if (retval)
4455 return retval; 4282 return retval;
4456 } 4283
4457 if (!chip->ft2_fast_mode) { 4284 if (!chip->ft2_fast_mode) {
4458 retval = card_power_off(chip, MS_CARD); 4285 retval = card_power_off(chip, MS_CARD);
4459 if (retval != STATUS_SUCCESS) { 4286 if (retval != STATUS_SUCCESS)
4460 return STATUS_FAIL; 4287 return STATUS_FAIL;
4461 }
4462 } 4288 }
4463 4289
4464 return STATUS_SUCCESS; 4290 return STATUS_SUCCESS;
@@ -4486,9 +4312,8 @@ int release_ms_card(struct rtsx_chip *chip)
4486#endif 4312#endif
4487 4313
4488 retval = ms_power_off_card3v3(chip); 4314 retval = ms_power_off_card3v3(chip);
4489 if (retval != STATUS_SUCCESS) { 4315 if (retval != STATUS_SUCCESS)
4490 return STATUS_FAIL; 4316 return STATUS_FAIL;
4491 }
4492 4317
4493 return STATUS_SUCCESS; 4318 return STATUS_SUCCESS;
4494} 4319}
diff --git a/drivers/staging/rts5208/rtsx_card.c b/drivers/staging/rts5208/rtsx_card.c
index d26a8e372fce..6dc541e06fb9 100644
--- a/drivers/staging/rts5208/rtsx_card.c
+++ b/drivers/staging/rts5208/rtsx_card.c
@@ -647,9 +647,8 @@ int switch_ssc_clock(struct rtsx_chip *chip, int clk)
647 dev_dbg(rtsx_dev(chip), "Switch SSC clock to %dMHz (cur_clk = %d)\n", 647 dev_dbg(rtsx_dev(chip), "Switch SSC clock to %dMHz (cur_clk = %d)\n",
648 clk, chip->cur_clk); 648 clk, chip->cur_clk);
649 649
650 if ((clk <= 2) || (n > max_n)) { 650 if ((clk <= 2) || (n > max_n))
651 return STATUS_FAIL; 651 return STATUS_FAIL;
652 }
653 652
654 mcu_cnt = (u8)(125 / clk + 3); 653 mcu_cnt = (u8)(125 / clk + 3);
655 if (mcu_cnt > 7) 654 if (mcu_cnt > 7)
@@ -688,15 +687,13 @@ int switch_ssc_clock(struct rtsx_chip *chip, int clk)
688 } 687 }
689 688
690 retval = rtsx_send_cmd(chip, 0, WAIT_TIME); 689 retval = rtsx_send_cmd(chip, 0, WAIT_TIME);
691 if (retval < 0) { 690 if (retval < 0)
692 return STATUS_ERROR; 691 return STATUS_ERROR;
693 }
694 692
695 udelay(10); 693 udelay(10);
696 retval = rtsx_write_register(chip, CLK_CTL, CLK_LOW_FREQ, 0); 694 retval = rtsx_write_register(chip, CLK_CTL, CLK_LOW_FREQ, 0);
697 if (retval) { 695 if (retval)
698 return retval; 696 return retval;
699 }
700 697
701 chip->cur_clk = clk; 698 chip->cur_clk = clk;
702 699
@@ -790,49 +787,41 @@ int switch_normal_clock(struct rtsx_chip *chip, int clk)
790 } 787 }
791 788
792 retval = rtsx_write_register(chip, CLK_CTL, 0xFF, CLK_LOW_FREQ); 789 retval = rtsx_write_register(chip, CLK_CTL, 0xFF, CLK_LOW_FREQ);
793 if (retval) { 790 if (retval)
794 return retval; 791 return retval;
795 }
796 if (sd_vpclk_phase_reset) { 792 if (sd_vpclk_phase_reset) {
797 retval = rtsx_write_register(chip, SD_VPCLK0_CTL, 793 retval = rtsx_write_register(chip, SD_VPCLK0_CTL,
798 PHASE_NOT_RESET, 0); 794 PHASE_NOT_RESET, 0);
799 if (retval) { 795 if (retval)
800 return retval; 796 return retval;
801 }
802 retval = rtsx_write_register(chip, SD_VPCLK1_CTL, 797 retval = rtsx_write_register(chip, SD_VPCLK1_CTL,
803 PHASE_NOT_RESET, 0); 798 PHASE_NOT_RESET, 0);
804 if (retval) { 799 if (retval)
805 return retval; 800 return retval;
806 }
807 } 801 }
808 retval = rtsx_write_register(chip, CLK_DIV, 0xFF, 802 retval = rtsx_write_register(chip, CLK_DIV, 0xFF,
809 (div << 4) | mcu_cnt); 803 (div << 4) | mcu_cnt);
810 if (retval) { 804 if (retval)
811 return retval; 805 return retval;
812 }
813 retval = rtsx_write_register(chip, CLK_SEL, 0xFF, sel); 806 retval = rtsx_write_register(chip, CLK_SEL, 0xFF, sel);
814 if (retval) { 807 if (retval)
815 return retval; 808 return retval;
816 }
817 809
818 if (sd_vpclk_phase_reset) { 810 if (sd_vpclk_phase_reset) {
819 udelay(200); 811 udelay(200);
820 retval = rtsx_write_register(chip, SD_VPCLK0_CTL, 812 retval = rtsx_write_register(chip, SD_VPCLK0_CTL,
821 PHASE_NOT_RESET, PHASE_NOT_RESET); 813 PHASE_NOT_RESET, PHASE_NOT_RESET);
822 if (retval) { 814 if (retval)
823 return retval; 815 return retval;
824 }
825 retval = rtsx_write_register(chip, SD_VPCLK1_CTL, 816 retval = rtsx_write_register(chip, SD_VPCLK1_CTL,
826 PHASE_NOT_RESET, PHASE_NOT_RESET); 817 PHASE_NOT_RESET, PHASE_NOT_RESET);
827 if (retval) { 818 if (retval)
828 return retval; 819 return retval;
829 }
830 udelay(200); 820 udelay(200);
831 } 821 }
832 retval = rtsx_write_register(chip, CLK_CTL, 0xFF, 0); 822 retval = rtsx_write_register(chip, CLK_CTL, 0xFF, 0);
833 if (retval) { 823 if (retval)
834 return retval; 824 return retval;
835 }
836 825
837 chip->cur_clk = clk; 826 chip->cur_clk = clk;
838 827
@@ -878,9 +867,8 @@ int enable_card_clock(struct rtsx_chip *chip, u8 card)
878 clk_en |= MS_CLK_EN; 867 clk_en |= MS_CLK_EN;
879 868
880 retval = rtsx_write_register(chip, CARD_CLK_EN, clk_en, clk_en); 869 retval = rtsx_write_register(chip, CARD_CLK_EN, clk_en, clk_en);
881 if (retval) { 870 if (retval)
882 return retval; 871 return retval;
883 }
884 872
885 return STATUS_SUCCESS; 873 return STATUS_SUCCESS;
886} 874}
@@ -898,9 +886,8 @@ int disable_card_clock(struct rtsx_chip *chip, u8 card)
898 clk_en |= MS_CLK_EN; 886 clk_en |= MS_CLK_EN;
899 887
900 retval = rtsx_write_register(chip, CARD_CLK_EN, clk_en, 0); 888 retval = rtsx_write_register(chip, CARD_CLK_EN, clk_en, 0);
901 if (retval) { 889 if (retval)
902 return retval; 890 return retval;
903 }
904 891
905 return STATUS_SUCCESS; 892 return STATUS_SUCCESS;
906} 893}
@@ -924,9 +911,8 @@ int card_power_on(struct rtsx_chip *chip, u8 card)
924 rtsx_add_cmd(chip, WRITE_REG_CMD, CARD_PWR_CTL, mask, val1); 911 rtsx_add_cmd(chip, WRITE_REG_CMD, CARD_PWR_CTL, mask, val1);
925 912
926 retval = rtsx_send_cmd(chip, 0, 100); 913 retval = rtsx_send_cmd(chip, 0, 100);
927 if (retval != STATUS_SUCCESS) { 914 if (retval != STATUS_SUCCESS)
928 return STATUS_FAIL; 915 return STATUS_FAIL;
929 }
930 916
931 udelay(chip->pmos_pwr_on_interval); 917 udelay(chip->pmos_pwr_on_interval);
932 918
@@ -934,9 +920,8 @@ int card_power_on(struct rtsx_chip *chip, u8 card)
934 rtsx_add_cmd(chip, WRITE_REG_CMD, CARD_PWR_CTL, mask, val2); 920 rtsx_add_cmd(chip, WRITE_REG_CMD, CARD_PWR_CTL, mask, val2);
935 921
936 retval = rtsx_send_cmd(chip, 0, 100); 922 retval = rtsx_send_cmd(chip, 0, 100);
937 if (retval != STATUS_SUCCESS) { 923 if (retval != STATUS_SUCCESS)
938 return STATUS_FAIL; 924 return STATUS_FAIL;
939 }
940 925
941 return STATUS_SUCCESS; 926 return STATUS_SUCCESS;
942} 927}
@@ -955,9 +940,8 @@ int card_power_off(struct rtsx_chip *chip, u8 card)
955 } 940 }
956 941
957 retval = rtsx_write_register(chip, CARD_PWR_CTL, mask, val); 942 retval = rtsx_write_register(chip, CARD_PWR_CTL, mask, val);
958 if (retval) { 943 if (retval)
959 return retval; 944 return retval;
960 }
961 945
962 return STATUS_SUCCESS; 946 return STATUS_SUCCESS;
963} 947}
@@ -969,9 +953,8 @@ int card_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip,
969 unsigned int lun = SCSI_LUN(srb); 953 unsigned int lun = SCSI_LUN(srb);
970 int i; 954 int i;
971 955
972 if (!chip->rw_card[lun]) { 956 if (!chip->rw_card[lun])
973 return STATUS_FAIL; 957 return STATUS_FAIL;
974 }
975 958
976 for (i = 0; i < 3; i++) { 959 for (i = 0; i < 3; i++) {
977 chip->rw_need_retry = 0; 960 chip->rw_need_retry = 0;
@@ -1009,36 +992,33 @@ int card_share_mode(struct rtsx_chip *chip, int card)
1009 992
1010 if (CHECK_PID(chip, 0x5208)) { 993 if (CHECK_PID(chip, 0x5208)) {
1011 mask = CARD_SHARE_MASK; 994 mask = CARD_SHARE_MASK;
1012 if (card == SD_CARD) { 995 if (card == SD_CARD)
1013 value = CARD_SHARE_48_SD; 996 value = CARD_SHARE_48_SD;
1014 } else if (card == MS_CARD) { 997 else if (card == MS_CARD)
1015 value = CARD_SHARE_48_MS; 998 value = CARD_SHARE_48_MS;
1016 } else if (card == XD_CARD) { 999 else if (card == XD_CARD)
1017 value = CARD_SHARE_48_XD; 1000 value = CARD_SHARE_48_XD;
1018 } else { 1001 else
1019 return STATUS_FAIL; 1002 return STATUS_FAIL;
1020 }
1021 1003
1022 } else if (CHECK_PID(chip, 0x5288)) { 1004 } else if (CHECK_PID(chip, 0x5288)) {
1023 mask = 0x03; 1005 mask = 0x03;
1024 if (card == SD_CARD) { 1006 if (card == SD_CARD)
1025 value = CARD_SHARE_BAROSSA_SD; 1007 value = CARD_SHARE_BAROSSA_SD;
1026 } else if (card == MS_CARD) { 1008 else if (card == MS_CARD)
1027 value = CARD_SHARE_BAROSSA_MS; 1009 value = CARD_SHARE_BAROSSA_MS;
1028 } else if (card == XD_CARD) { 1010 else if (card == XD_CARD)
1029 value = CARD_SHARE_BAROSSA_XD; 1011 value = CARD_SHARE_BAROSSA_XD;
1030 } else { 1012 else
1031 return STATUS_FAIL; 1013 return STATUS_FAIL;
1032 }
1033 1014
1034 } else { 1015 } else {
1035 return STATUS_FAIL; 1016 return STATUS_FAIL;
1036 } 1017 }
1037 1018
1038 retval = rtsx_write_register(chip, CARD_SHARE_MODE, mask, value); 1019 retval = rtsx_write_register(chip, CARD_SHARE_MODE, mask, value);
1039 if (retval) { 1020 if (retval)
1040 return retval; 1021 return retval;
1041 }
1042 1022
1043 return STATUS_SUCCESS; 1023 return STATUS_SUCCESS;
1044} 1024}
@@ -1050,28 +1030,25 @@ int select_card(struct rtsx_chip *chip, int card)
1050 if (chip->cur_card != card) { 1030 if (chip->cur_card != card) {
1051 u8 mod; 1031 u8 mod;
1052 1032
1053 if (card == SD_CARD) { 1033 if (card == SD_CARD)
1054 mod = SD_MOD_SEL; 1034 mod = SD_MOD_SEL;
1055 } else if (card == MS_CARD) { 1035 else if (card == MS_CARD)
1056 mod = MS_MOD_SEL; 1036 mod = MS_MOD_SEL;
1057 } else if (card == XD_CARD) { 1037 else if (card == XD_CARD)
1058 mod = XD_MOD_SEL; 1038 mod = XD_MOD_SEL;
1059 } else if (card == SPI_CARD) { 1039 else if (card == SPI_CARD)
1060 mod = SPI_MOD_SEL; 1040 mod = SPI_MOD_SEL;
1061 } else { 1041 else
1062 return STATUS_FAIL; 1042 return STATUS_FAIL;
1063 }
1064 1043
1065 retval = rtsx_write_register(chip, CARD_SELECT, 0x07, mod); 1044 retval = rtsx_write_register(chip, CARD_SELECT, 0x07, mod);
1066 if (retval) { 1045 if (retval)
1067 return retval; 1046 return retval;
1068 }
1069 chip->cur_card = card; 1047 chip->cur_card = card;
1070 1048
1071 retval = card_share_mode(chip, card); 1049 retval = card_share_mode(chip, card);
1072 if (retval != STATUS_SUCCESS) { 1050 if (retval != STATUS_SUCCESS)
1073 return STATUS_FAIL; 1051 return STATUS_FAIL;
1074 }
1075 } 1052 }
1076 1053
1077 return STATUS_SUCCESS; 1054 return STATUS_SUCCESS;
@@ -1120,9 +1097,8 @@ int detect_card_cd(struct rtsx_chip *chip, int card)
1120 } 1097 }
1121 1098
1122 status = rtsx_readl(chip, RTSX_BIPR); 1099 status = rtsx_readl(chip, RTSX_BIPR);
1123 if (!(status & card_cd)) { 1100 if (!(status & card_cd))
1124 return STATUS_FAIL; 1101 return STATUS_FAIL;
1125 }
1126 1102
1127 return STATUS_SUCCESS; 1103 return STATUS_SUCCESS;
1128} 1104}
diff --git a/drivers/staging/rts5208/rtsx_card.h b/drivers/staging/rts5208/rtsx_card.h
index ac165d8a081c..820b1113ea89 100644
--- a/drivers/staging/rts5208/rtsx_card.h
+++ b/drivers/staging/rts5208/rtsx_card.h
@@ -1062,9 +1062,8 @@ static inline int card_power_off_all(struct rtsx_chip *chip)
1062 int retval; 1062 int retval;
1063 1063
1064 retval = rtsx_write_register(chip, CARD_PWR_CTL, 0x0F, 0x0F); 1064 retval = rtsx_write_register(chip, CARD_PWR_CTL, 0x0F, 0x0F);
1065 if (retval) { 1065 if (retval)
1066 return retval; 1066 return retval;
1067 }
1068 1067
1069 return STATUS_SUCCESS; 1068 return STATUS_SUCCESS;
1070} 1069}
diff --git a/drivers/staging/rts5208/rtsx_chip.c b/drivers/staging/rts5208/rtsx_chip.c
index 6b1234bff09c..94fb35429bf1 100644
--- a/drivers/staging/rts5208/rtsx_chip.c
+++ b/drivers/staging/rts5208/rtsx_chip.c
@@ -116,34 +116,29 @@ static int rtsx_pre_handle_sdio_old(struct rtsx_chip *chip)
116 0xFF, 116 0xFF,
117 MS_INS_PU | SD_WP_PU | 117 MS_INS_PU | SD_WP_PU |
118 SD_CD_PU | SD_CMD_PU); 118 SD_CD_PU | SD_CMD_PU);
119 if (retval) { 119 if (retval)
120 return retval; 120 return retval;
121 }
122 } else { 121 } else {
123 retval = rtsx_write_register(chip, FPGA_PULL_CTL, 122 retval = rtsx_write_register(chip, FPGA_PULL_CTL,
124 0xFF, 123 0xFF,
125 FPGA_SD_PULL_CTL_EN); 124 FPGA_SD_PULL_CTL_EN);
126 if (retval) { 125 if (retval)
127 return retval; 126 return retval;
128 }
129 } 127 }
130 retval = rtsx_write_register(chip, CARD_SHARE_MODE, 0xFF, 128 retval = rtsx_write_register(chip, CARD_SHARE_MODE, 0xFF,
131 CARD_SHARE_48_SD); 129 CARD_SHARE_48_SD);
132 if (retval) { 130 if (retval)
133 return retval; 131 return retval;
134 }
135 132
136 /* Enable SDIO internal clock */ 133 /* Enable SDIO internal clock */
137 retval = rtsx_write_register(chip, 0xFF2C, 0x01, 0x01); 134 retval = rtsx_write_register(chip, 0xFF2C, 0x01, 0x01);
138 if (retval) { 135 if (retval)
139 return retval; 136 return retval;
140 }
141 137
142 retval = rtsx_write_register(chip, SDIO_CTRL, 0xFF, 138 retval = rtsx_write_register(chip, SDIO_CTRL, 0xFF,
143 SDIO_BUS_CTRL | SDIO_CD_CTRL); 139 SDIO_BUS_CTRL | SDIO_CD_CTRL);
144 if (retval) { 140 if (retval)
145 return retval; 141 return retval;
146 }
147 142
148 chip->sd_int = 1; 143 chip->sd_int = 1;
149 chip->sd_io = 1; 144 chip->sd_io = 1;
@@ -164,16 +159,14 @@ static int rtsx_pre_handle_sdio_new(struct rtsx_chip *chip)
164 if (chip->driver_first_load) { 159 if (chip->driver_first_load) {
165 if (CHECK_PID(chip, 0x5288)) { 160 if (CHECK_PID(chip, 0x5288)) {
166 retval = rtsx_read_register(chip, 0xFE5A, &tmp); 161 retval = rtsx_read_register(chip, 0xFE5A, &tmp);
167 if (retval) { 162 if (retval)
168 return retval; 163 return retval;
169 }
170 if (tmp & 0x08) 164 if (tmp & 0x08)
171 sw_bypass_sd = true; 165 sw_bypass_sd = true;
172 } else if (CHECK_PID(chip, 0x5208)) { 166 } else if (CHECK_PID(chip, 0x5208)) {
173 retval = rtsx_read_register(chip, 0xFE70, &tmp); 167 retval = rtsx_read_register(chip, 0xFE70, &tmp);
174 if (retval) { 168 if (retval)
175 return retval; 169 return retval;
176 }
177 if (tmp & 0x80) 170 if (tmp & 0x80)
178 sw_bypass_sd = true; 171 sw_bypass_sd = true;
179 } 172 }
@@ -192,9 +185,8 @@ static int rtsx_pre_handle_sdio_new(struct rtsx_chip *chip)
192 u8 cd_toggle_mask = 0; 185 u8 cd_toggle_mask = 0;
193 186
194 retval = rtsx_read_register(chip, TLPTISTAT, &tmp); 187 retval = rtsx_read_register(chip, TLPTISTAT, &tmp);
195 if (retval) { 188 if (retval)
196 return retval; 189 return retval;
197 }
198 cd_toggle_mask = 0x08; 190 cd_toggle_mask = 0x08;
199 191
200 if (tmp & cd_toggle_mask) { 192 if (tmp & cd_toggle_mask) {
@@ -202,22 +194,19 @@ static int rtsx_pre_handle_sdio_new(struct rtsx_chip *chip)
202 if (CHECK_PID(chip, 0x5288)) { 194 if (CHECK_PID(chip, 0x5288)) {
203 retval = rtsx_write_register(chip, 0xFE5A, 195 retval = rtsx_write_register(chip, 0xFE5A,
204 0x08, 0x00); 196 0x08, 0x00);
205 if (retval) { 197 if (retval)
206 return retval; 198 return retval;
207 }
208 } else if (CHECK_PID(chip, 0x5208)) { 199 } else if (CHECK_PID(chip, 0x5208)) {
209 retval = rtsx_write_register(chip, 0xFE70, 200 retval = rtsx_write_register(chip, 0xFE70,
210 0x80, 0x00); 201 0x80, 0x00);
211 if (retval) { 202 if (retval)
212 return retval; 203 return retval;
213 }
214 } 204 }
215 205
216 retval = rtsx_write_register(chip, TLPTISTAT, 0xFF, 206 retval = rtsx_write_register(chip, TLPTISTAT, 0xFF,
217 tmp); 207 tmp);
218 if (retval) { 208 if (retval)
219 return retval; 209 return retval;
220 }
221 210
222 chip->need_reset |= SD_CARD; 211 chip->need_reset |= SD_CARD;
223 } else { 212 } else {
@@ -225,36 +214,31 @@ static int rtsx_pre_handle_sdio_new(struct rtsx_chip *chip)
225 214
226 if (chip->asic_code) { 215 if (chip->asic_code) {
227 retval = sd_pull_ctl_enable(chip); 216 retval = sd_pull_ctl_enable(chip);
228 if (retval != STATUS_SUCCESS) { 217 if (retval != STATUS_SUCCESS)
229 return STATUS_FAIL; 218 return STATUS_FAIL;
230 }
231 } else { 219 } else {
232 retval = rtsx_write_register 220 retval = rtsx_write_register
233 (chip, FPGA_PULL_CTL, 221 (chip, FPGA_PULL_CTL,
234 FPGA_SD_PULL_CTL_BIT | 0x20, 222 FPGA_SD_PULL_CTL_BIT | 0x20,
235 0); 223 0);
236 if (retval) { 224 if (retval)
237 return retval; 225 return retval;
238 }
239 } 226 }
240 retval = card_share_mode(chip, SD_CARD); 227 retval = card_share_mode(chip, SD_CARD);
241 if (retval != STATUS_SUCCESS) { 228 if (retval != STATUS_SUCCESS)
242 return STATUS_FAIL; 229 return STATUS_FAIL;
243 }
244 230
245 /* Enable sdio_bus_auto_switch */ 231 /* Enable sdio_bus_auto_switch */
246 if (CHECK_PID(chip, 0x5288)) { 232 if (CHECK_PID(chip, 0x5288)) {
247 retval = rtsx_write_register(chip, 0xFE5A, 233 retval = rtsx_write_register(chip, 0xFE5A,
248 0x08, 0x08); 234 0x08, 0x08);
249 if (retval) { 235 if (retval)
250 return retval; 236 return retval;
251 }
252 } else if (CHECK_PID(chip, 0x5208)) { 237 } else if (CHECK_PID(chip, 0x5208)) {
253 retval = rtsx_write_register(chip, 0xFE70, 238 retval = rtsx_write_register(chip, 0xFE70,
254 0x80, 0x80); 239 0x80, 0x80);
255 if (retval) { 240 if (retval)
256 return retval; 241 return retval;
257 }
258 } 242 }
259 243
260 chip->chip_insert_with_sdio = 1; 244 chip->chip_insert_with_sdio = 1;
@@ -262,9 +246,8 @@ static int rtsx_pre_handle_sdio_new(struct rtsx_chip *chip)
262 } 246 }
263 } else { 247 } else {
264 retval = rtsx_write_register(chip, TLPTISTAT, 0x08, 0x08); 248 retval = rtsx_write_register(chip, TLPTISTAT, 0x08, 0x08);
265 if (retval) { 249 if (retval)
266 return retval; 250 return retval;
267 }
268 251
269 chip->need_reset |= SD_CARD; 252 chip->need_reset |= SD_CARD;
270 } 253 }
@@ -283,32 +266,28 @@ static int rtsx_reset_aspm(struct rtsx_chip *chip)
283 266
284 ret = rtsx_write_cfg_dw(chip, 2, 0xC0, 0xFF, 267 ret = rtsx_write_cfg_dw(chip, 2, 0xC0, 0xFF,
285 chip->aspm_l0s_l1_en); 268 chip->aspm_l0s_l1_en);
286 if (ret != STATUS_SUCCESS) { 269 if (ret != STATUS_SUCCESS)
287 return STATUS_FAIL; 270 return STATUS_FAIL;
288 }
289 271
290 return STATUS_SUCCESS; 272 return STATUS_SUCCESS;
291 } 273 }
292 274
293 if (CHECK_PID(chip, 0x5208)) { 275 if (CHECK_PID(chip, 0x5208)) {
294 ret = rtsx_write_register(chip, ASPM_FORCE_CTL, 0xFF, 0x3F); 276 ret = rtsx_write_register(chip, ASPM_FORCE_CTL, 0xFF, 0x3F);
295 if (ret) { 277 if (ret)
296 return ret; 278 return ret;
297 }
298 } 279 }
299 ret = rtsx_write_config_byte(chip, LCTLR, chip->aspm_l0s_l1_en); 280 ret = rtsx_write_config_byte(chip, LCTLR, chip->aspm_l0s_l1_en);
300 if (ret != STATUS_SUCCESS) { 281 if (ret != STATUS_SUCCESS)
301 return STATUS_FAIL; 282 return STATUS_FAIL;
302 }
303 283
304 chip->aspm_level[0] = chip->aspm_l0s_l1_en; 284 chip->aspm_level[0] = chip->aspm_l0s_l1_en;
305 if (CHK_SDIO_EXIST(chip)) { 285 if (CHK_SDIO_EXIST(chip)) {
306 chip->aspm_level[1] = chip->aspm_l0s_l1_en; 286 chip->aspm_level[1] = chip->aspm_l0s_l1_en;
307 ret = rtsx_write_cfg_dw(chip, CHECK_PID(chip, 0x5288) ? 2 : 1, 287 ret = rtsx_write_cfg_dw(chip, CHECK_PID(chip, 0x5288) ? 2 : 1,
308 0xC0, 0xFF, chip->aspm_l0s_l1_en); 288 0xC0, 0xFF, chip->aspm_l0s_l1_en);
309 if (ret != STATUS_SUCCESS) { 289 if (ret != STATUS_SUCCESS)
310 return STATUS_FAIL; 290 return STATUS_FAIL;
311 }
312 } 291 }
313 292
314 chip->aspm_enabled = 1; 293 chip->aspm_enabled = 1;
@@ -327,9 +306,8 @@ static int rtsx_enable_pcie_intr(struct rtsx_chip *chip)
327 306
328 if (chip->phy_debug_mode) { 307 if (chip->phy_debug_mode) {
329 ret = rtsx_write_register(chip, CDRESUMECTL, 0x77, 0); 308 ret = rtsx_write_register(chip, CDRESUMECTL, 0x77, 0);
330 if (ret) { 309 if (ret)
331 return ret; 310 return ret;
332 }
333 rtsx_disable_bus_int(chip); 311 rtsx_disable_bus_int(chip);
334 } else { 312 } else {
335 rtsx_enable_bus_int(chip); 313 rtsx_enable_bus_int(chip);
@@ -339,27 +317,23 @@ static int rtsx_enable_pcie_intr(struct rtsx_chip *chip)
339 u16 reg; 317 u16 reg;
340 318
341 ret = rtsx_read_phy_register(chip, 0x00, &reg); 319 ret = rtsx_read_phy_register(chip, 0x00, &reg);
342 if (ret != STATUS_SUCCESS) { 320 if (ret != STATUS_SUCCESS)
343 return STATUS_FAIL; 321 return STATUS_FAIL;
344 }
345 322
346 reg &= 0xFE7F; 323 reg &= 0xFE7F;
347 reg |= 0x80; 324 reg |= 0x80;
348 ret = rtsx_write_phy_register(chip, 0x00, reg); 325 ret = rtsx_write_phy_register(chip, 0x00, reg);
349 if (ret != STATUS_SUCCESS) { 326 if (ret != STATUS_SUCCESS)
350 return STATUS_FAIL; 327 return STATUS_FAIL;
351 }
352 328
353 ret = rtsx_read_phy_register(chip, 0x1C, &reg); 329 ret = rtsx_read_phy_register(chip, 0x1C, &reg);
354 if (ret != STATUS_SUCCESS) { 330 if (ret != STATUS_SUCCESS)
355 return STATUS_FAIL; 331 return STATUS_FAIL;
356 }
357 332
358 reg &= 0xFFF7; 333 reg &= 0xFFF7;
359 ret = rtsx_write_phy_register(chip, 0x1C, reg); 334 ret = rtsx_write_phy_register(chip, 0x1C, reg);
360 if (ret != STATUS_SUCCESS) { 335 if (ret != STATUS_SUCCESS)
361 return STATUS_FAIL; 336 return STATUS_FAIL;
362 }
363 } 337 }
364 338
365 if (chip->driver_first_load && (chip->ic_version < IC_VER_C)) 339 if (chip->driver_first_load && (chip->ic_version < IC_VER_C))
@@ -377,100 +351,85 @@ int rtsx_reset_chip(struct rtsx_chip *chip)
377 rtsx_disable_aspm(chip); 351 rtsx_disable_aspm(chip);
378 352
379 retval = rtsx_write_register(chip, HOST_SLEEP_STATE, 0x03, 0x00); 353 retval = rtsx_write_register(chip, HOST_SLEEP_STATE, 0x03, 0x00);
380 if (retval) { 354 if (retval)
381 return retval; 355 return retval;
382 }
383 356
384 /* Disable card clock */ 357 /* Disable card clock */
385 retval = rtsx_write_register(chip, CARD_CLK_EN, 0x1E, 0); 358 retval = rtsx_write_register(chip, CARD_CLK_EN, 0x1E, 0);
386 if (retval) { 359 if (retval)
387 return retval; 360 return retval;
388 }
389 361
390#ifdef SUPPORT_OCP 362#ifdef SUPPORT_OCP
391 /* SSC power on, OCD power on */ 363 /* SSC power on, OCD power on */
392 if (CHECK_LUN_MODE(chip, SD_MS_2LUN)) { 364 if (CHECK_LUN_MODE(chip, SD_MS_2LUN)) {
393 retval = rtsx_write_register(chip, FPDCTL, OC_POWER_DOWN, 0); 365 retval = rtsx_write_register(chip, FPDCTL, OC_POWER_DOWN, 0);
394 if (retval) { 366 if (retval)
395 return retval; 367 return retval;
396 }
397 } else { 368 } else {
398 retval = rtsx_write_register(chip, FPDCTL, OC_POWER_DOWN, 369 retval = rtsx_write_register(chip, FPDCTL, OC_POWER_DOWN,
399 MS_OC_POWER_DOWN); 370 MS_OC_POWER_DOWN);
400 if (retval) { 371 if (retval)
401 return retval; 372 return retval;
402 }
403 } 373 }
404 374
405 retval = rtsx_write_register(chip, OCPPARA1, OCP_TIME_MASK, 375 retval = rtsx_write_register(chip, OCPPARA1, OCP_TIME_MASK,
406 OCP_TIME_800); 376 OCP_TIME_800);
407 if (retval) { 377 if (retval)
408 return retval; 378 return retval;
409 }
410 retval = rtsx_write_register(chip, OCPPARA2, OCP_THD_MASK, 379 retval = rtsx_write_register(chip, OCPPARA2, OCP_THD_MASK,
411 OCP_THD_244_946); 380 OCP_THD_244_946);
412 if (retval) { 381 if (retval)
413 return retval; 382 return retval;
414 }
415 retval = rtsx_write_register(chip, OCPCTL, 0xFF, 383 retval = rtsx_write_register(chip, OCPCTL, 0xFF,
416 CARD_OC_INT_EN | CARD_DETECT_EN); 384 CARD_OC_INT_EN | CARD_DETECT_EN);
417 if (retval) { 385 if (retval)
418 return retval; 386 return retval;
419 }
420#else 387#else
421 /* OC power down */ 388 /* OC power down */
422 retval = rtsx_write_register(chip, FPDCTL, OC_POWER_DOWN, 389 retval = rtsx_write_register(chip, FPDCTL, OC_POWER_DOWN,
423 OC_POWER_DOWN); 390 OC_POWER_DOWN);
424 if (retval) { 391 if (retval)
425 return retval; 392 return retval;
426 }
427#endif 393#endif
428 394
429 if (!CHECK_PID(chip, 0x5288)) { 395 if (!CHECK_PID(chip, 0x5288)) {
430 retval = rtsx_write_register(chip, CARD_GPIO_DIR, 0xFF, 0x03); 396 retval = rtsx_write_register(chip, CARD_GPIO_DIR, 0xFF, 0x03);
431 if (retval) { 397 if (retval)
432 return retval; 398 return retval;
433 }
434 } 399 }
435 400
436 /* Turn off LED */ 401 /* Turn off LED */
437 retval = rtsx_write_register(chip, CARD_GPIO, 0xFF, 0x03); 402 retval = rtsx_write_register(chip, CARD_GPIO, 0xFF, 0x03);
438 if (retval) { 403 if (retval)
439 return retval; 404 return retval;
440 }
441 405
442 /* Reset delink mode */ 406 /* Reset delink mode */
443 retval = rtsx_write_register(chip, CHANGE_LINK_STATE, 0x0A, 0); 407 retval = rtsx_write_register(chip, CHANGE_LINK_STATE, 0x0A, 0);
444 if (retval) { 408 if (retval)
445 return retval; 409 return retval;
446 }
447 410
448 /* Card driving select */ 411 /* Card driving select */
449 retval = rtsx_write_register(chip, CARD_DRIVE_SEL, 0xFF, 412 retval = rtsx_write_register(chip, CARD_DRIVE_SEL, 0xFF,
450 chip->card_drive_sel); 413 chip->card_drive_sel);
451 if (retval) { 414 if (retval)
452 return retval; 415 return retval;
453 }
454 416
455#ifdef LED_AUTO_BLINK 417#ifdef LED_AUTO_BLINK
456 retval = rtsx_write_register(chip, CARD_AUTO_BLINK, 0xFF, 418 retval = rtsx_write_register(chip, CARD_AUTO_BLINK, 0xFF,
457 LED_BLINK_SPEED | BLINK_EN | LED_GPIO0); 419 LED_BLINK_SPEED | BLINK_EN | LED_GPIO0);
458 if (retval) { 420 if (retval)
459 return retval; 421 return retval;
460 }
461#endif 422#endif
462 423
463 if (chip->asic_code) { 424 if (chip->asic_code) {
464 /* Enable SSC Clock */ 425 /* Enable SSC Clock */
465 retval = rtsx_write_register(chip, SSC_CTL1, 0xFF, 426 retval = rtsx_write_register(chip, SSC_CTL1, 0xFF,
466 SSC_8X_EN | SSC_SEL_4M); 427 SSC_8X_EN | SSC_SEL_4M);
467 if (retval) { 428 if (retval)
468 return retval; 429 return retval;
469 }
470 retval = rtsx_write_register(chip, SSC_CTL2, 0xFF, 0x12); 430 retval = rtsx_write_register(chip, SSC_CTL2, 0xFF, 0x12);
471 if (retval) { 431 if (retval)
472 return retval; 432 return retval;
473 }
474 } 433 }
475 434
476 /* 435 /*
@@ -482,72 +441,61 @@ int rtsx_reset_chip(struct rtsx_chip *chip)
482 * bit[4] u_non_sticky_rst_n_dbg rst_value = 0 441 * bit[4] u_non_sticky_rst_n_dbg rst_value = 0
483 */ 442 */
484 retval = rtsx_write_register(chip, CHANGE_LINK_STATE, 0x16, 0x10); 443 retval = rtsx_write_register(chip, CHANGE_LINK_STATE, 0x16, 0x10);
485 if (retval) { 444 if (retval)
486 return retval; 445 return retval;
487 }
488 446
489 /* Enable ASPM */ 447 /* Enable ASPM */
490 if (chip->aspm_l0s_l1_en) { 448 if (chip->aspm_l0s_l1_en) {
491 retval = rtsx_reset_aspm(chip); 449 retval = rtsx_reset_aspm(chip);
492 if (retval != STATUS_SUCCESS) { 450 if (retval != STATUS_SUCCESS)
493 return STATUS_FAIL; 451 return STATUS_FAIL;
494 }
495 } else { 452 } else {
496 if (chip->asic_code && CHECK_PID(chip, 0x5208)) { 453 if (chip->asic_code && CHECK_PID(chip, 0x5208)) {
497 retval = rtsx_write_phy_register(chip, 0x07, 0x0129); 454 retval = rtsx_write_phy_register(chip, 0x07, 0x0129);
498 if (retval != STATUS_SUCCESS) { 455 if (retval != STATUS_SUCCESS)
499 return STATUS_FAIL; 456 return STATUS_FAIL;
500 }
501 } 457 }
502 retval = rtsx_write_config_byte(chip, LCTLR, 458 retval = rtsx_write_config_byte(chip, LCTLR,
503 chip->aspm_l0s_l1_en); 459 chip->aspm_l0s_l1_en);
504 if (retval != STATUS_SUCCESS) { 460 if (retval != STATUS_SUCCESS)
505 return STATUS_FAIL; 461 return STATUS_FAIL;
506 }
507 } 462 }
508 463
509 retval = rtsx_write_config_byte(chip, 0x81, 1); 464 retval = rtsx_write_config_byte(chip, 0x81, 1);
510 if (retval != STATUS_SUCCESS) { 465 if (retval != STATUS_SUCCESS)
511 return STATUS_FAIL; 466 return STATUS_FAIL;
512 }
513 467
514 if (CHK_SDIO_EXIST(chip)) { 468 if (CHK_SDIO_EXIST(chip)) {
515 retval = rtsx_write_cfg_dw(chip, 469 retval = rtsx_write_cfg_dw(chip,
516 CHECK_PID(chip, 0x5288) ? 2 : 1, 470 CHECK_PID(chip, 0x5288) ? 2 : 1,
517 0xC0, 0xFF00, 0x0100); 471 0xC0, 0xFF00, 0x0100);
518 472
519 if (retval != STATUS_SUCCESS) { 473 if (retval != STATUS_SUCCESS)
520 return STATUS_FAIL; 474 return STATUS_FAIL;
521 }
522 } 475 }
523 476
524 if (CHECK_PID(chip, 0x5288) && !CHK_SDIO_EXIST(chip)) { 477 if (CHECK_PID(chip, 0x5288) && !CHK_SDIO_EXIST(chip)) {
525 retval = rtsx_write_cfg_dw(chip, 2, 0xC0, 0xFFFF, 0x0103); 478 retval = rtsx_write_cfg_dw(chip, 2, 0xC0, 0xFFFF, 0x0103);
526 if (retval != STATUS_SUCCESS) { 479 if (retval != STATUS_SUCCESS)
527 return STATUS_FAIL; 480 return STATUS_FAIL;
528 }
529 481
530 retval = rtsx_write_cfg_dw(chip, 2, 0x84, 0xFF, 0x03); 482 retval = rtsx_write_cfg_dw(chip, 2, 0x84, 0xFF, 0x03);
531 if (retval != STATUS_SUCCESS) { 483 if (retval != STATUS_SUCCESS)
532 return STATUS_FAIL; 484 return STATUS_FAIL;
533 }
534 } 485 }
535 486
536 retval = rtsx_write_register(chip, IRQSTAT0, LINK_RDY_INT, 487 retval = rtsx_write_register(chip, IRQSTAT0, LINK_RDY_INT,
537 LINK_RDY_INT); 488 LINK_RDY_INT);
538 if (retval) { 489 if (retval)
539 return retval; 490 return retval;
540 }
541 491
542 retval = rtsx_write_register(chip, PERST_GLITCH_WIDTH, 0xFF, 0x80); 492 retval = rtsx_write_register(chip, PERST_GLITCH_WIDTH, 0xFF, 0x80);
543 if (retval) { 493 if (retval)
544 return retval; 494 return retval;
545 }
546 495
547 retval = rtsx_enable_pcie_intr(chip); 496 retval = rtsx_enable_pcie_intr(chip);
548 if (retval != STATUS_SUCCESS) { 497 if (retval != STATUS_SUCCESS)
549 return STATUS_FAIL; 498 return STATUS_FAIL;
550 }
551 499
552 chip->need_reset = 0; 500 chip->need_reset = 0;
553 501
@@ -569,17 +517,15 @@ int rtsx_reset_chip(struct rtsx_chip *chip)
569#else /* HW_AUTO_SWITCH_SD_BUS */ 517#else /* HW_AUTO_SWITCH_SD_BUS */
570 retval = rtsx_pre_handle_sdio_old(chip); 518 retval = rtsx_pre_handle_sdio_old(chip);
571#endif /* HW_AUTO_SWITCH_SD_BUS */ 519#endif /* HW_AUTO_SWITCH_SD_BUS */
572 if (retval != STATUS_SUCCESS) { 520 if (retval != STATUS_SUCCESS)
573 return STATUS_FAIL; 521 return STATUS_FAIL;
574 }
575 522
576 } else { 523 } else {
577 chip->sd_io = 0; 524 chip->sd_io = 0;
578 retval = rtsx_write_register(chip, SDIO_CTRL, 525 retval = rtsx_write_register(chip, SDIO_CTRL,
579 SDIO_BUS_CTRL | SDIO_CD_CTRL, 0); 526 SDIO_BUS_CTRL | SDIO_CD_CTRL, 0);
580 if (retval) { 527 if (retval)
581 return retval; 528 return retval;
582 }
583 } 529 }
584 530
585nextcard: 531nextcard:
@@ -590,78 +536,67 @@ nextcard:
590 if (chip->int_reg & CARD_EXIST) { 536 if (chip->int_reg & CARD_EXIST) {
591 retval = rtsx_write_register(chip, SSC_CTL1, SSC_RSTB, 537 retval = rtsx_write_register(chip, SSC_CTL1, SSC_RSTB,
592 SSC_RSTB); 538 SSC_RSTB);
593 if (retval) { 539 if (retval)
594 return retval; 540 return retval;
595 }
596 } 541 }
597 542
598 dev_dbg(rtsx_dev(chip), "In %s, chip->need_reset = 0x%x\n", __func__, 543 dev_dbg(rtsx_dev(chip), "In %s, chip->need_reset = 0x%x\n", __func__,
599 (unsigned int)(chip->need_reset)); 544 (unsigned int)(chip->need_reset));
600 545
601 retval = rtsx_write_register(chip, RCCTL, 0x01, 0x00); 546 retval = rtsx_write_register(chip, RCCTL, 0x01, 0x00);
602 if (retval) { 547 if (retval)
603 return retval; 548 return retval;
604 }
605 549
606 if (CHECK_PID(chip, 0x5208) || CHECK_PID(chip, 0x5288)) { 550 if (CHECK_PID(chip, 0x5208) || CHECK_PID(chip, 0x5288)) {
607 /* Turn off main power when entering S3/S4 state */ 551 /* Turn off main power when entering S3/S4 state */
608 retval = rtsx_write_register(chip, MAIN_PWR_OFF_CTL, 0x03, 552 retval = rtsx_write_register(chip, MAIN_PWR_OFF_CTL, 0x03,
609 0x03); 553 0x03);
610 if (retval) { 554 if (retval)
611 return retval; 555 return retval;
612 }
613 } 556 }
614 557
615 if (chip->remote_wakeup_en && !chip->auto_delink_en) { 558 if (chip->remote_wakeup_en && !chip->auto_delink_en) {
616 retval = rtsx_write_register(chip, WAKE_SEL_CTL, 0x07, 0x07); 559 retval = rtsx_write_register(chip, WAKE_SEL_CTL, 0x07, 0x07);
617 if (retval) { 560 if (retval)
618 return retval; 561 return retval;
619 }
620 if (chip->aux_pwr_exist) { 562 if (chip->aux_pwr_exist) {
621 retval = rtsx_write_register(chip, PME_FORCE_CTL, 563 retval = rtsx_write_register(chip, PME_FORCE_CTL,
622 0xFF, 0x33); 564 0xFF, 0x33);
623 if (retval) { 565 if (retval)
624 return retval; 566 return retval;
625 }
626 } 567 }
627 } else { 568 } else {
628 retval = rtsx_write_register(chip, WAKE_SEL_CTL, 0x07, 0x04); 569 retval = rtsx_write_register(chip, WAKE_SEL_CTL, 0x07, 0x04);
629 if (retval) { 570 if (retval)
630 return retval; 571 return retval;
631 }
632 retval = rtsx_write_register(chip, PME_FORCE_CTL, 0xFF, 0x30); 572 retval = rtsx_write_register(chip, PME_FORCE_CTL, 0xFF, 0x30);
633 if (retval) { 573 if (retval)
634 return retval; 574 return retval;
635 }
636 } 575 }
637 576
638 if (CHECK_PID(chip, 0x5208) && (chip->ic_version >= IC_VER_D)) { 577 if (CHECK_PID(chip, 0x5208) && (chip->ic_version >= IC_VER_D)) {
639 retval = rtsx_write_register(chip, PETXCFG, 0x1C, 0x14); 578 retval = rtsx_write_register(chip, PETXCFG, 0x1C, 0x14);
640 if (retval) { 579 if (retval)
641 return retval; 580 return retval;
642 }
643 } 581 }
644 582
645 if (chip->asic_code && CHECK_PID(chip, 0x5208)) { 583 if (chip->asic_code && CHECK_PID(chip, 0x5208)) {
646 retval = rtsx_clr_phy_reg_bit(chip, 0x1C, 2); 584 retval = rtsx_clr_phy_reg_bit(chip, 0x1C, 2);
647 if (retval != STATUS_SUCCESS) { 585 if (retval != STATUS_SUCCESS)
648 return STATUS_FAIL; 586 return STATUS_FAIL;
649 }
650 } 587 }
651 588
652 if (chip->ft2_fast_mode) { 589 if (chip->ft2_fast_mode) {
653 retval = rtsx_write_register(chip, CARD_PWR_CTL, 0xFF, 590 retval = rtsx_write_register(chip, CARD_PWR_CTL, 0xFF,
654 MS_PARTIAL_POWER_ON | 591 MS_PARTIAL_POWER_ON |
655 SD_PARTIAL_POWER_ON); 592 SD_PARTIAL_POWER_ON);
656 if (retval) { 593 if (retval)
657 return retval; 594 return retval;
658 }
659 udelay(chip->pmos_pwr_on_interval); 595 udelay(chip->pmos_pwr_on_interval);
660 retval = rtsx_write_register(chip, CARD_PWR_CTL, 0xFF, 596 retval = rtsx_write_register(chip, CARD_PWR_CTL, 0xFF,
661 MS_POWER_ON | SD_POWER_ON); 597 MS_POWER_ON | SD_POWER_ON);
662 if (retval) { 598 if (retval)
663 return retval; 599 return retval;
664 }
665 600
666 wait_timeout(200); 601 wait_timeout(200);
667 } 602 }
@@ -715,20 +650,17 @@ static int rts5208_init(struct rtsx_chip *chip)
715 u8 val = 0; 650 u8 val = 0;
716 651
717 retval = rtsx_write_register(chip, CLK_SEL, 0x03, 0x03); 652 retval = rtsx_write_register(chip, CLK_SEL, 0x03, 0x03);
718 if (retval) { 653 if (retval)
719 return retval; 654 return retval;
720 }
721 retval = rtsx_read_register(chip, CLK_SEL, &val); 655 retval = rtsx_read_register(chip, CLK_SEL, &val);
722 if (retval) { 656 if (retval)
723 return retval; 657 return retval;
724 }
725 chip->asic_code = val == 0 ? 1 : 0; 658 chip->asic_code = val == 0 ? 1 : 0;
726 659
727 if (chip->asic_code) { 660 if (chip->asic_code) {
728 retval = rtsx_read_phy_register(chip, 0x1C, &reg); 661 retval = rtsx_read_phy_register(chip, 0x1C, &reg);
729 if (retval != STATUS_SUCCESS) { 662 if (retval != STATUS_SUCCESS)
730 return STATUS_FAIL; 663 return STATUS_FAIL;
731 }
732 664
733 dev_dbg(rtsx_dev(chip), "Value of phy register 0x1C is 0x%x\n", 665 dev_dbg(rtsx_dev(chip), "Value of phy register 0x1C is 0x%x\n",
734 reg); 666 reg);
@@ -737,24 +669,21 @@ static int rts5208_init(struct rtsx_chip *chip)
737 669
738 } else { 670 } else {
739 retval = rtsx_read_register(chip, 0xFE80, &val); 671 retval = rtsx_read_register(chip, 0xFE80, &val);
740 if (retval) { 672 if (retval)
741 return retval; 673 return retval;
742 }
743 chip->ic_version = val; 674 chip->ic_version = val;
744 chip->phy_debug_mode = 0; 675 chip->phy_debug_mode = 0;
745 } 676 }
746 677
747 retval = rtsx_read_register(chip, PDINFO, &val); 678 retval = rtsx_read_register(chip, PDINFO, &val);
748 if (retval) { 679 if (retval)
749 return retval; 680 return retval;
750 }
751 dev_dbg(rtsx_dev(chip), "PDINFO: 0x%x\n", val); 681 dev_dbg(rtsx_dev(chip), "PDINFO: 0x%x\n", val);
752 chip->aux_pwr_exist = val & AUX_PWR_DETECTED ? 1 : 0; 682 chip->aux_pwr_exist = val & AUX_PWR_DETECTED ? 1 : 0;
753 683
754 retval = rtsx_read_register(chip, 0xFE50, &val); 684 retval = rtsx_read_register(chip, 0xFE50, &val);
755 if (retval) { 685 if (retval)
756 return retval; 686 return retval;
757 }
758 chip->hw_bypass_sd = val & 0x01 ? 1 : 0; 687 chip->hw_bypass_sd = val & 0x01 ? 1 : 0;
759 688
760 rtsx_read_config_byte(chip, 0x0E, &val); 689 rtsx_read_config_byte(chip, 0x0E, &val);
@@ -765,9 +694,8 @@ static int rts5208_init(struct rtsx_chip *chip)
765 694
766 if (chip->use_hw_setting) { 695 if (chip->use_hw_setting) {
767 retval = rtsx_read_register(chip, CHANGE_LINK_STATE, &val); 696 retval = rtsx_read_register(chip, CHANGE_LINK_STATE, &val);
768 if (retval) { 697 if (retval)
769 return retval; 698 return retval;
770 }
771 chip->auto_delink_en = val & 0x80 ? 1 : 0; 699 chip->auto_delink_en = val & 0x80 ? 1 : 0;
772 } 700 }
773 701
@@ -781,42 +709,36 @@ static int rts5288_init(struct rtsx_chip *chip)
781 u32 lval = 0; 709 u32 lval = 0;
782 710
783 retval = rtsx_write_register(chip, CLK_SEL, 0x03, 0x03); 711 retval = rtsx_write_register(chip, CLK_SEL, 0x03, 0x03);
784 if (retval) { 712 if (retval)
785 return retval; 713 return retval;
786 }
787 retval = rtsx_read_register(chip, CLK_SEL, &val); 714 retval = rtsx_read_register(chip, CLK_SEL, &val);
788 if (retval) { 715 if (retval)
789 return retval; 716 return retval;
790 }
791 chip->asic_code = val == 0 ? 1 : 0; 717 chip->asic_code = val == 0 ? 1 : 0;
792 718
793 chip->ic_version = 0; 719 chip->ic_version = 0;
794 chip->phy_debug_mode = 0; 720 chip->phy_debug_mode = 0;
795 721
796 retval = rtsx_read_register(chip, PDINFO, &val); 722 retval = rtsx_read_register(chip, PDINFO, &val);
797 if (retval) { 723 if (retval)
798 return retval; 724 return retval;
799 }
800 dev_dbg(rtsx_dev(chip), "PDINFO: 0x%x\n", val); 725 dev_dbg(rtsx_dev(chip), "PDINFO: 0x%x\n", val);
801 chip->aux_pwr_exist = val & AUX_PWR_DETECTED ? 1 : 0; 726 chip->aux_pwr_exist = val & AUX_PWR_DETECTED ? 1 : 0;
802 727
803 retval = rtsx_read_register(chip, CARD_SHARE_MODE, &val); 728 retval = rtsx_read_register(chip, CARD_SHARE_MODE, &val);
804 if (retval) { 729 if (retval)
805 return retval; 730 return retval;
806 }
807 dev_dbg(rtsx_dev(chip), "CARD_SHARE_MODE: 0x%x\n", val); 731 dev_dbg(rtsx_dev(chip), "CARD_SHARE_MODE: 0x%x\n", val);
808 chip->baro_pkg = val & 0x04 ? QFN : LQFP; 732 chip->baro_pkg = val & 0x04 ? QFN : LQFP;
809 733
810 retval = rtsx_read_register(chip, 0xFE5A, &val); 734 retval = rtsx_read_register(chip, 0xFE5A, &val);
811 if (retval) { 735 if (retval)
812 return retval; 736 return retval;
813 }
814 chip->hw_bypass_sd = val & 0x10 ? 1 : 0; 737 chip->hw_bypass_sd = val & 0x10 ? 1 : 0;
815 738
816 retval = rtsx_read_cfg_dw(chip, 0, 0x718, &lval); 739 retval = rtsx_read_cfg_dw(chip, 0, 0x718, &lval);
817 if (retval != STATUS_SUCCESS) { 740 if (retval != STATUS_SUCCESS)
818 return STATUS_FAIL; 741 return STATUS_FAIL;
819 }
820 742
821 max_func = (u8)((lval >> 29) & 0x07); 743 max_func = (u8)((lval >> 29) & 0x07);
822 dev_dbg(rtsx_dev(chip), "Max function number: %d\n", max_func); 744 dev_dbg(rtsx_dev(chip), "Max function number: %d\n", max_func);
@@ -827,9 +749,8 @@ static int rts5288_init(struct rtsx_chip *chip)
827 749
828 if (chip->use_hw_setting) { 750 if (chip->use_hw_setting) {
829 retval = rtsx_read_register(chip, CHANGE_LINK_STATE, &val); 751 retval = rtsx_read_register(chip, CHANGE_LINK_STATE, &val);
830 if (retval) { 752 if (retval)
831 return retval; 753 return retval;
832 }
833 chip->auto_delink_en = val & 0x80 ? 1 : 0; 754 chip->auto_delink_en = val & 0x80 ? 1 : 0;
834 755
835 if (CHECK_BARO_PKG(chip, LQFP)) 756 if (CHECK_BARO_PKG(chip, LQFP))
@@ -905,28 +826,24 @@ int rtsx_init_chip(struct rtsx_chip *chip)
905 chip->mmc_ddr_tx_phase = 0; 826 chip->mmc_ddr_tx_phase = 0;
906 827
907 retval = rtsx_write_register(chip, FPDCTL, SSC_POWER_DOWN, 0); 828 retval = rtsx_write_register(chip, FPDCTL, SSC_POWER_DOWN, 0);
908 if (retval) { 829 if (retval)
909 return retval; 830 return retval;
910 }
911 wait_timeout(200); 831 wait_timeout(200);
912 retval = rtsx_write_register(chip, CLK_DIV, 0x07, 0x07); 832 retval = rtsx_write_register(chip, CLK_DIV, 0x07, 0x07);
913 if (retval) { 833 if (retval)
914 return retval; 834 return retval;
915 }
916 dev_dbg(rtsx_dev(chip), "chip->use_hw_setting = %d\n", 835 dev_dbg(rtsx_dev(chip), "chip->use_hw_setting = %d\n",
917 chip->use_hw_setting); 836 chip->use_hw_setting);
918 837
919 if (CHECK_PID(chip, 0x5208)) { 838 if (CHECK_PID(chip, 0x5208)) {
920 retval = rts5208_init(chip); 839 retval = rts5208_init(chip);
921 if (retval != STATUS_SUCCESS) { 840 if (retval != STATUS_SUCCESS)
922 return STATUS_FAIL; 841 return STATUS_FAIL;
923 }
924 842
925 } else if (CHECK_PID(chip, 0x5288)) { 843 } else if (CHECK_PID(chip, 0x5288)) {
926 retval = rts5288_init(chip); 844 retval = rts5288_init(chip);
927 if (retval != STATUS_SUCCESS) { 845 if (retval != STATUS_SUCCESS)
928 return STATUS_FAIL; 846 return STATUS_FAIL;
929 }
930 } 847 }
931 848
932 if (chip->ss_en == 2) 849 if (chip->ss_en == 2)
@@ -973,9 +890,8 @@ int rtsx_init_chip(struct rtsx_chip *chip)
973 } 890 }
974 891
975 retval = rtsx_reset_chip(chip); 892 retval = rtsx_reset_chip(chip);
976 if (retval != STATUS_SUCCESS) { 893 if (retval != STATUS_SUCCESS)
977 return STATUS_FAIL; 894 return STATUS_FAIL;
978 }
979 895
980 return STATUS_SUCCESS; 896 return STATUS_SUCCESS;
981} 897}
@@ -1403,9 +1319,8 @@ int rtsx_write_register(struct rtsx_chip *chip, u16 addr, u8 mask, u8 data)
1403 for (i = 0; i < MAX_RW_REG_CNT; i++) { 1319 for (i = 0; i < MAX_RW_REG_CNT; i++) {
1404 val = rtsx_readl(chip, RTSX_HAIMR); 1320 val = rtsx_readl(chip, RTSX_HAIMR);
1405 if ((val & BIT(31)) == 0) { 1321 if ((val & BIT(31)) == 0) {
1406 if (data != (u8)val) { 1322 if (data != (u8)val)
1407 return STATUS_FAIL; 1323 return STATUS_FAIL;
1408 }
1409 1324
1410 return STATUS_SUCCESS; 1325 return STATUS_SUCCESS;
1411 } 1326 }
@@ -1432,9 +1347,8 @@ int rtsx_read_register(struct rtsx_chip *chip, u16 addr, u8 *data)
1432 break; 1347 break;
1433 } 1348 }
1434 1349
1435 if (i >= MAX_RW_REG_CNT) { 1350 if (i >= MAX_RW_REG_CNT)
1436 return STATUS_TIMEDOUT; 1351 return STATUS_TIMEDOUT;
1437 }
1438 1352
1439 if (data) 1353 if (data)
1440 *data = (u8)(val & 0xFF); 1354 *data = (u8)(val & 0xFF);
@@ -1454,9 +1368,8 @@ int rtsx_write_cfg_dw(struct rtsx_chip *chip, u8 func_no, u16 addr, u32 mask,
1454 retval = rtsx_write_register(chip, CFGDATA0 + i, 1368 retval = rtsx_write_register(chip, CFGDATA0 + i,
1455 0xFF, 1369 0xFF,
1456 (u8)(val & mask & 0xFF)); 1370 (u8)(val & mask & 0xFF));
1457 if (retval) { 1371 if (retval)
1458 return retval; 1372 return retval;
1459 }
1460 mode |= (1 << i); 1373 mode |= (1 << i);
1461 } 1374 }
1462 mask >>= 8; 1375 mask >>= 8;
@@ -1465,27 +1378,23 @@ int rtsx_write_cfg_dw(struct rtsx_chip *chip, u8 func_no, u16 addr, u32 mask,
1465 1378
1466 if (mode) { 1379 if (mode) {
1467 retval = rtsx_write_register(chip, CFGADDR0, 0xFF, (u8)addr); 1380 retval = rtsx_write_register(chip, CFGADDR0, 0xFF, (u8)addr);
1468 if (retval) { 1381 if (retval)
1469 return retval; 1382 return retval;
1470 }
1471 retval = rtsx_write_register(chip, CFGADDR1, 0xFF, 1383 retval = rtsx_write_register(chip, CFGADDR1, 0xFF,
1472 (u8)(addr >> 8)); 1384 (u8)(addr >> 8));
1473 if (retval) { 1385 if (retval)
1474 return retval; 1386 return retval;
1475 }
1476 1387
1477 retval = rtsx_write_register(chip, CFGRWCTL, 0xFF, 1388 retval = rtsx_write_register(chip, CFGRWCTL, 0xFF,
1478 0x80 | mode | 1389 0x80 | mode |
1479 ((func_no & 0x03) << 4)); 1390 ((func_no & 0x03) << 4));
1480 if (retval) { 1391 if (retval)
1481 return retval; 1392 return retval;
1482 }
1483 1393
1484 for (i = 0; i < MAX_RW_REG_CNT; i++) { 1394 for (i = 0; i < MAX_RW_REG_CNT; i++) {
1485 retval = rtsx_read_register(chip, CFGRWCTL, &tmp); 1395 retval = rtsx_read_register(chip, CFGRWCTL, &tmp);
1486 if (retval) { 1396 if (retval)
1487 return retval; 1397 return retval;
1488 }
1489 if ((tmp & 0x80) == 0) 1398 if ((tmp & 0x80) == 0)
1490 break; 1399 break;
1491 } 1400 }
@@ -1502,33 +1411,28 @@ int rtsx_read_cfg_dw(struct rtsx_chip *chip, u8 func_no, u16 addr, u32 *val)
1502 u32 data = 0; 1411 u32 data = 0;
1503 1412
1504 retval = rtsx_write_register(chip, CFGADDR0, 0xFF, (u8)addr); 1413 retval = rtsx_write_register(chip, CFGADDR0, 0xFF, (u8)addr);
1505 if (retval) { 1414 if (retval)
1506 return retval; 1415 return retval;
1507 }
1508 retval = rtsx_write_register(chip, CFGADDR1, 0xFF, (u8)(addr >> 8)); 1416 retval = rtsx_write_register(chip, CFGADDR1, 0xFF, (u8)(addr >> 8));
1509 if (retval) { 1417 if (retval)
1510 return retval; 1418 return retval;
1511 }
1512 retval = rtsx_write_register(chip, CFGRWCTL, 0xFF, 1419 retval = rtsx_write_register(chip, CFGRWCTL, 0xFF,
1513 0x80 | ((func_no & 0x03) << 4)); 1420 0x80 | ((func_no & 0x03) << 4));
1514 if (retval) { 1421 if (retval)
1515 return retval; 1422 return retval;
1516 }
1517 1423
1518 for (i = 0; i < MAX_RW_REG_CNT; i++) { 1424 for (i = 0; i < MAX_RW_REG_CNT; i++) {
1519 retval = rtsx_read_register(chip, CFGRWCTL, &tmp); 1425 retval = rtsx_read_register(chip, CFGRWCTL, &tmp);
1520 if (retval) { 1426 if (retval)
1521 return retval; 1427 return retval;
1522 }
1523 if ((tmp & 0x80) == 0) 1428 if ((tmp & 0x80) == 0)
1524 break; 1429 break;
1525 } 1430 }
1526 1431
1527 for (i = 0; i < 4; i++) { 1432 for (i = 0; i < 4; i++) {
1528 retval = rtsx_read_register(chip, CFGDATA0 + i, &tmp); 1433 retval = rtsx_read_register(chip, CFGDATA0 + i, &tmp);
1529 if (retval) { 1434 if (retval)
1530 return retval; 1435 return retval;
1531 }
1532 data |= (u32)tmp << (i * 8); 1436 data |= (u32)tmp << (i * 8);
1533 } 1437 }
1534 1438
@@ -1547,9 +1451,8 @@ int rtsx_write_cfg_seq(struct rtsx_chip *chip, u8 func, u16 addr, u8 *buf,
1547 int dw_len, i, j; 1451 int dw_len, i, j;
1548 int retval; 1452 int retval;
1549 1453
1550 if (!buf) { 1454 if (!buf)
1551 return STATUS_NOMEM; 1455 return STATUS_NOMEM;
1552 }
1553 1456
1554 if ((len + offset) % 4) 1457 if ((len + offset) % 4)
1555 dw_len = (len + offset) / 4 + 1; 1458 dw_len = (len + offset) / 4 + 1;
@@ -1559,9 +1462,8 @@ int rtsx_write_cfg_seq(struct rtsx_chip *chip, u8 func, u16 addr, u8 *buf,
1559 dev_dbg(rtsx_dev(chip), "dw_len = %d\n", dw_len); 1462 dev_dbg(rtsx_dev(chip), "dw_len = %d\n", dw_len);
1560 1463
1561 data = vzalloc(array_size(dw_len, 4)); 1464 data = vzalloc(array_size(dw_len, 4));
1562 if (!data) { 1465 if (!data)
1563 return STATUS_NOMEM; 1466 return STATUS_NOMEM;
1564 }
1565 1467
1566 mask = vzalloc(array_size(dw_len, 4)); 1468 mask = vzalloc(array_size(dw_len, 4));
1567 if (!mask) { 1469 if (!mask) {
@@ -1617,9 +1519,8 @@ int rtsx_read_cfg_seq(struct rtsx_chip *chip, u8 func, u16 addr, u8 *buf,
1617 dev_dbg(rtsx_dev(chip), "dw_len = %d\n", dw_len); 1519 dev_dbg(rtsx_dev(chip), "dw_len = %d\n", dw_len);
1618 1520
1619 data = vmalloc(array_size(dw_len, 4)); 1521 data = vmalloc(array_size(dw_len, 4));
1620 if (!data) { 1522 if (!data)
1621 return STATUS_NOMEM; 1523 return STATUS_NOMEM;
1622 }
1623 1524
1624 for (i = 0; i < dw_len; i++) { 1525 for (i = 0; i < dw_len; i++) {
1625 retval = rtsx_read_cfg_dw(chip, func, aligned_addr + i * 4, 1526 retval = rtsx_read_cfg_dw(chip, func, aligned_addr + i * 4,
@@ -1655,36 +1556,30 @@ int rtsx_write_phy_register(struct rtsx_chip *chip, u8 addr, u16 val)
1655 u8 tmp; 1556 u8 tmp;
1656 1557
1657 retval = rtsx_write_register(chip, PHYDATA0, 0xFF, (u8)val); 1558 retval = rtsx_write_register(chip, PHYDATA0, 0xFF, (u8)val);
1658 if (retval) { 1559 if (retval)
1659 return retval; 1560 return retval;
1660 }
1661 retval = rtsx_write_register(chip, PHYDATA1, 0xFF, (u8)(val >> 8)); 1561 retval = rtsx_write_register(chip, PHYDATA1, 0xFF, (u8)(val >> 8));
1662 if (retval) { 1562 if (retval)
1663 return retval; 1563 return retval;
1664 }
1665 retval = rtsx_write_register(chip, PHYADDR, 0xFF, addr); 1564 retval = rtsx_write_register(chip, PHYADDR, 0xFF, addr);
1666 if (retval) { 1565 if (retval)
1667 return retval; 1566 return retval;
1668 }
1669 retval = rtsx_write_register(chip, PHYRWCTL, 0xFF, 0x81); 1567 retval = rtsx_write_register(chip, PHYRWCTL, 0xFF, 0x81);
1670 if (retval) { 1568 if (retval)
1671 return retval; 1569 return retval;
1672 }
1673 1570
1674 for (i = 0; i < 100000; i++) { 1571 for (i = 0; i < 100000; i++) {
1675 retval = rtsx_read_register(chip, PHYRWCTL, &tmp); 1572 retval = rtsx_read_register(chip, PHYRWCTL, &tmp);
1676 if (retval) { 1573 if (retval)
1677 return retval; 1574 return retval;
1678 }
1679 if (!(tmp & 0x80)) { 1575 if (!(tmp & 0x80)) {
1680 finished = true; 1576 finished = true;
1681 break; 1577 break;
1682 } 1578 }
1683 } 1579 }
1684 1580
1685 if (!finished) { 1581 if (!finished)
1686 return STATUS_FAIL; 1582 return STATUS_FAIL;
1687 }
1688 1583
1689 return STATUS_SUCCESS; 1584 return STATUS_SUCCESS;
1690} 1585}
@@ -1698,38 +1593,32 @@ int rtsx_read_phy_register(struct rtsx_chip *chip, u8 addr, u16 *val)
1698 u8 tmp; 1593 u8 tmp;
1699 1594
1700 retval = rtsx_write_register(chip, PHYADDR, 0xFF, addr); 1595 retval = rtsx_write_register(chip, PHYADDR, 0xFF, addr);
1701 if (retval) { 1596 if (retval)
1702 return retval; 1597 return retval;
1703 }
1704 retval = rtsx_write_register(chip, PHYRWCTL, 0xFF, 0x80); 1598 retval = rtsx_write_register(chip, PHYRWCTL, 0xFF, 0x80);
1705 if (retval) { 1599 if (retval)
1706 return retval; 1600 return retval;
1707 }
1708 1601
1709 for (i = 0; i < 100000; i++) { 1602 for (i = 0; i < 100000; i++) {
1710 retval = rtsx_read_register(chip, PHYRWCTL, &tmp); 1603 retval = rtsx_read_register(chip, PHYRWCTL, &tmp);
1711 if (retval) { 1604 if (retval)
1712 return retval; 1605 return retval;
1713 }
1714 if (!(tmp & 0x80)) { 1606 if (!(tmp & 0x80)) {
1715 finished = true; 1607 finished = true;
1716 break; 1608 break;
1717 } 1609 }
1718 } 1610 }
1719 1611
1720 if (!finished) { 1612 if (!finished)
1721 return STATUS_FAIL; 1613 return STATUS_FAIL;
1722 }
1723 1614
1724 retval = rtsx_read_register(chip, PHYDATA0, &tmp); 1615 retval = rtsx_read_register(chip, PHYDATA0, &tmp);
1725 if (retval) { 1616 if (retval)
1726 return retval; 1617 return retval;
1727 }
1728 data = tmp; 1618 data = tmp;
1729 retval = rtsx_read_register(chip, PHYDATA1, &tmp); 1619 retval = rtsx_read_register(chip, PHYDATA1, &tmp);
1730 if (retval) { 1620 if (retval)
1731 return retval; 1621 return retval;
1732 }
1733 data |= (u16)tmp << 8; 1622 data |= (u16)tmp << 8;
1734 1623
1735 if (val) 1624 if (val)
@@ -1745,28 +1634,24 @@ int rtsx_read_efuse(struct rtsx_chip *chip, u8 addr, u8 *val)
1745 u8 data = 0; 1634 u8 data = 0;
1746 1635
1747 retval = rtsx_write_register(chip, EFUSE_CTRL, 0xFF, 0x80 | addr); 1636 retval = rtsx_write_register(chip, EFUSE_CTRL, 0xFF, 0x80 | addr);
1748 if (retval) { 1637 if (retval)
1749 return retval; 1638 return retval;
1750 }
1751 1639
1752 for (i = 0; i < 100; i++) { 1640 for (i = 0; i < 100; i++) {
1753 retval = rtsx_read_register(chip, EFUSE_CTRL, &data); 1641 retval = rtsx_read_register(chip, EFUSE_CTRL, &data);
1754 if (retval) { 1642 if (retval)
1755 return retval; 1643 return retval;
1756 }
1757 if (!(data & 0x80)) 1644 if (!(data & 0x80))
1758 break; 1645 break;
1759 udelay(1); 1646 udelay(1);
1760 } 1647 }
1761 1648
1762 if (data & 0x80) { 1649 if (data & 0x80)
1763 return STATUS_TIMEDOUT; 1650 return STATUS_TIMEDOUT;
1764 }
1765 1651
1766 retval = rtsx_read_register(chip, EFUSE_DATA, &data); 1652 retval = rtsx_read_register(chip, EFUSE_DATA, &data);
1767 if (retval) { 1653 if (retval)
1768 return retval; 1654 return retval;
1769 }
1770 if (val) 1655 if (val)
1771 *val = data; 1656 *val = data;
1772 1657
@@ -1787,28 +1672,24 @@ int rtsx_write_efuse(struct rtsx_chip *chip, u8 addr, u8 val)
1787 dev_dbg(rtsx_dev(chip), "Write 0x%x to 0x%x\n", tmp, addr); 1672 dev_dbg(rtsx_dev(chip), "Write 0x%x to 0x%x\n", tmp, addr);
1788 1673
1789 retval = rtsx_write_register(chip, EFUSE_DATA, 0xFF, tmp); 1674 retval = rtsx_write_register(chip, EFUSE_DATA, 0xFF, tmp);
1790 if (retval) { 1675 if (retval)
1791 return retval; 1676 return retval;
1792 }
1793 retval = rtsx_write_register(chip, EFUSE_CTRL, 0xFF, 1677 retval = rtsx_write_register(chip, EFUSE_CTRL, 0xFF,
1794 0xA0 | addr); 1678 0xA0 | addr);
1795 if (retval) { 1679 if (retval)
1796 return retval; 1680 return retval;
1797 }
1798 1681
1799 for (j = 0; j < 100; j++) { 1682 for (j = 0; j < 100; j++) {
1800 retval = rtsx_read_register(chip, EFUSE_CTRL, &data); 1683 retval = rtsx_read_register(chip, EFUSE_CTRL, &data);
1801 if (retval) { 1684 if (retval)
1802 return retval; 1685 return retval;
1803 }
1804 if (!(data & 0x80)) 1686 if (!(data & 0x80))
1805 break; 1687 break;
1806 wait_timeout(3); 1688 wait_timeout(3);
1807 } 1689 }
1808 1690
1809 if (data & 0x80) { 1691 if (data & 0x80)
1810 return STATUS_TIMEDOUT; 1692 return STATUS_TIMEDOUT;
1811 }
1812 1693
1813 wait_timeout(5); 1694 wait_timeout(5);
1814 } 1695 }
@@ -1822,16 +1703,14 @@ int rtsx_clr_phy_reg_bit(struct rtsx_chip *chip, u8 reg, u8 bit)
1822 u16 value; 1703 u16 value;
1823 1704
1824 retval = rtsx_read_phy_register(chip, reg, &value); 1705 retval = rtsx_read_phy_register(chip, reg, &value);
1825 if (retval != STATUS_SUCCESS) { 1706 if (retval != STATUS_SUCCESS)
1826 return STATUS_FAIL; 1707 return STATUS_FAIL;
1827 }
1828 1708
1829 if (value & (1 << bit)) { 1709 if (value & (1 << bit)) {
1830 value &= ~(1 << bit); 1710 value &= ~(1 << bit);
1831 retval = rtsx_write_phy_register(chip, reg, value); 1711 retval = rtsx_write_phy_register(chip, reg, value);
1832 if (retval != STATUS_SUCCESS) { 1712 if (retval != STATUS_SUCCESS)
1833 return STATUS_FAIL; 1713 return STATUS_FAIL;
1834 }
1835 } 1714 }
1836 1715
1837 return STATUS_SUCCESS; 1716 return STATUS_SUCCESS;
@@ -1843,16 +1722,14 @@ int rtsx_set_phy_reg_bit(struct rtsx_chip *chip, u8 reg, u8 bit)
1843 u16 value; 1722 u16 value;
1844 1723
1845 retval = rtsx_read_phy_register(chip, reg, &value); 1724 retval = rtsx_read_phy_register(chip, reg, &value);
1846 if (retval != STATUS_SUCCESS) { 1725 if (retval != STATUS_SUCCESS)
1847 return STATUS_FAIL; 1726 return STATUS_FAIL;
1848 }
1849 1727
1850 if ((value & (1 << bit)) == 0) { 1728 if ((value & (1 << bit)) == 0) {
1851 value |= (1 << bit); 1729 value |= (1 << bit);
1852 retval = rtsx_write_phy_register(chip, reg, value); 1730 retval = rtsx_write_phy_register(chip, reg, value);
1853 if (retval != STATUS_SUCCESS) { 1731 if (retval != STATUS_SUCCESS)
1854 return STATUS_FAIL; 1732 return STATUS_FAIL;
1855 }
1856 } 1733 }
1857 1734
1858 return STATUS_SUCCESS; 1735 return STATUS_SUCCESS;
@@ -2153,9 +2030,8 @@ int rtsx_read_ppbuf(struct rtsx_chip *chip, u8 *buf, int buf_len)
2153 u16 reg_addr; 2030 u16 reg_addr;
2154 u8 *ptr; 2031 u8 *ptr;
2155 2032
2156 if (!buf) { 2033 if (!buf)
2157 return STATUS_ERROR; 2034 return STATUS_ERROR;
2158 }
2159 2035
2160 ptr = buf; 2036 ptr = buf;
2161 reg_addr = PPBUF_BASE2; 2037 reg_addr = PPBUF_BASE2;
@@ -2166,9 +2042,8 @@ int rtsx_read_ppbuf(struct rtsx_chip *chip, u8 *buf, int buf_len)
2166 rtsx_add_cmd(chip, READ_REG_CMD, reg_addr++, 0, 0); 2042 rtsx_add_cmd(chip, READ_REG_CMD, reg_addr++, 0, 0);
2167 2043
2168 retval = rtsx_send_cmd(chip, 0, 250); 2044 retval = rtsx_send_cmd(chip, 0, 250);
2169 if (retval < 0) { 2045 if (retval < 0)
2170 return STATUS_FAIL; 2046 return STATUS_FAIL;
2171 }
2172 2047
2173 memcpy(ptr, rtsx_get_cmd_data(chip), 256); 2048 memcpy(ptr, rtsx_get_cmd_data(chip), 256);
2174 ptr += 256; 2049 ptr += 256;
@@ -2181,9 +2056,8 @@ int rtsx_read_ppbuf(struct rtsx_chip *chip, u8 *buf, int buf_len)
2181 rtsx_add_cmd(chip, READ_REG_CMD, reg_addr++, 0, 0); 2056 rtsx_add_cmd(chip, READ_REG_CMD, reg_addr++, 0, 0);
2182 2057
2183 retval = rtsx_send_cmd(chip, 0, 250); 2058 retval = rtsx_send_cmd(chip, 0, 250);
2184 if (retval < 0) { 2059 if (retval < 0)
2185 return STATUS_FAIL; 2060 return STATUS_FAIL;
2186 }
2187 } 2061 }
2188 2062
2189 memcpy(ptr, rtsx_get_cmd_data(chip), buf_len % 256); 2063 memcpy(ptr, rtsx_get_cmd_data(chip), buf_len % 256);
@@ -2198,9 +2072,8 @@ int rtsx_write_ppbuf(struct rtsx_chip *chip, u8 *buf, int buf_len)
2198 u16 reg_addr; 2072 u16 reg_addr;
2199 u8 *ptr; 2073 u8 *ptr;
2200 2074
2201 if (!buf) { 2075 if (!buf)
2202 return STATUS_ERROR; 2076 return STATUS_ERROR;
2203 }
2204 2077
2205 ptr = buf; 2078 ptr = buf;
2206 reg_addr = PPBUF_BASE2; 2079 reg_addr = PPBUF_BASE2;
@@ -2214,9 +2087,8 @@ int rtsx_write_ppbuf(struct rtsx_chip *chip, u8 *buf, int buf_len)
2214 } 2087 }
2215 2088
2216 retval = rtsx_send_cmd(chip, 0, 250); 2089 retval = rtsx_send_cmd(chip, 0, 250);
2217 if (retval < 0) { 2090 if (retval < 0)
2218 return STATUS_FAIL; 2091 return STATUS_FAIL;
2219 }
2220 } 2092 }
2221 2093
2222 if (buf_len % 256) { 2094 if (buf_len % 256) {
@@ -2229,9 +2101,8 @@ int rtsx_write_ppbuf(struct rtsx_chip *chip, u8 *buf, int buf_len)
2229 } 2101 }
2230 2102
2231 retval = rtsx_send_cmd(chip, 0, 250); 2103 retval = rtsx_send_cmd(chip, 0, 250);
2232 if (retval < 0) { 2104 if (retval < 0)
2233 return STATUS_FAIL; 2105 return STATUS_FAIL;
2234 }
2235 } 2106 }
2236 2107
2237 return STATUS_SUCCESS; 2108 return STATUS_SUCCESS;
@@ -2239,9 +2110,8 @@ int rtsx_write_ppbuf(struct rtsx_chip *chip, u8 *buf, int buf_len)
2239 2110
2240int rtsx_check_chip_exist(struct rtsx_chip *chip) 2111int rtsx_check_chip_exist(struct rtsx_chip *chip)
2241{ 2112{
2242 if (rtsx_readl(chip, 0) == 0xFFFFFFFF) { 2113 if (rtsx_readl(chip, 0) == 0xFFFFFFFF)
2243 return STATUS_FAIL; 2114 return STATUS_FAIL;
2244 }
2245 2115
2246 return STATUS_SUCCESS; 2116 return STATUS_SUCCESS;
2247} 2117}
@@ -2264,9 +2134,8 @@ int rtsx_force_power_on(struct rtsx_chip *chip, u8 ctl)
2264 2134
2265 if (mask) { 2135 if (mask) {
2266 retval = rtsx_write_register(chip, FPDCTL, mask, 0); 2136 retval = rtsx_write_register(chip, FPDCTL, mask, 0);
2267 if (retval != STATUS_SUCCESS) { 2137 if (retval != STATUS_SUCCESS)
2268 return STATUS_FAIL; 2138 return STATUS_FAIL;
2269 }
2270 2139
2271 if (CHECK_PID(chip, 0x5288)) 2140 if (CHECK_PID(chip, 0x5288))
2272 wait_timeout(200); 2141 wait_timeout(200);
@@ -2294,9 +2163,8 @@ int rtsx_force_power_down(struct rtsx_chip *chip, u8 ctl)
2294 if (mask) { 2163 if (mask) {
2295 val = mask; 2164 val = mask;
2296 retval = rtsx_write_register(chip, FPDCTL, mask, val); 2165 retval = rtsx_write_register(chip, FPDCTL, mask, val);
2297 if (retval != STATUS_SUCCESS) { 2166 if (retval != STATUS_SUCCESS)
2298 return STATUS_FAIL; 2167 return STATUS_FAIL;
2299 }
2300 } 2168 }
2301 2169
2302 return STATUS_SUCCESS; 2170 return STATUS_SUCCESS;
diff --git a/drivers/staging/rts5208/rtsx_scsi.c b/drivers/staging/rts5208/rtsx_scsi.c
index c9a6d97938f6..9c594a778425 100644
--- a/drivers/staging/rts5208/rtsx_scsi.c
+++ b/drivers/staging/rts5208/rtsx_scsi.c
@@ -507,9 +507,8 @@ static int inquiry(struct scsi_cmnd *srb, struct rtsx_chip *chip)
507 } 507 }
508 508
509 buf = vmalloc(scsi_bufflen(srb)); 509 buf = vmalloc(scsi_bufflen(srb));
510 if (!buf) { 510 if (!buf)
511 return TRANSPORT_ERROR; 511 return TRANSPORT_ERROR;
512 }
513 512
514#ifdef SUPPORT_MAGIC_GATE 513#ifdef SUPPORT_MAGIC_GATE
515 if ((chip->mspro_formatter_enable) && 514 if ((chip->mspro_formatter_enable) &&
@@ -637,9 +636,8 @@ static int request_sense(struct scsi_cmnd *srb, struct rtsx_chip *chip)
637 } 636 }
638 637
639 buf = vmalloc(scsi_bufflen(srb)); 638 buf = vmalloc(scsi_bufflen(srb));
640 if (!buf) { 639 if (!buf)
641 return TRANSPORT_ERROR; 640 return TRANSPORT_ERROR;
642 }
643 641
644 tmp = (unsigned char *)sense; 642 tmp = (unsigned char *)sense;
645 memcpy(buf, tmp, scsi_bufflen(srb)); 643 memcpy(buf, tmp, scsi_bufflen(srb));
@@ -783,9 +781,8 @@ static int mode_sense(struct scsi_cmnd *srb, struct rtsx_chip *chip)
783#endif 781#endif
784 782
785 buf = kmalloc(data_size, GFP_KERNEL); 783 buf = kmalloc(data_size, GFP_KERNEL);
786 if (!buf) { 784 if (!buf)
787 return TRANSPORT_ERROR; 785 return TRANSPORT_ERROR;
788 }
789 786
790 page_code = srb->cmnd[2] & 0x3f; 787 page_code = srb->cmnd[2] & 0x3f;
791 788
@@ -999,9 +996,8 @@ static int read_format_capacity(struct scsi_cmnd *srb, struct rtsx_chip *chip)
999 buf_len = (scsi_bufflen(srb) > 12) ? 0x14 : 12; 996 buf_len = (scsi_bufflen(srb) > 12) ? 0x14 : 12;
1000 997
1001 buf = kmalloc(buf_len, GFP_KERNEL); 998 buf = kmalloc(buf_len, GFP_KERNEL);
1002 if (!buf) { 999 if (!buf)
1003 return TRANSPORT_ERROR; 1000 return TRANSPORT_ERROR;
1004 }
1005 1001
1006 buf[i++] = 0; 1002 buf[i++] = 0;
1007 buf[i++] = 0; 1003 buf[i++] = 0;
@@ -1076,9 +1072,8 @@ static int read_capacity(struct scsi_cmnd *srb, struct rtsx_chip *chip)
1076 } 1072 }
1077 1073
1078 buf = kmalloc(8, GFP_KERNEL); 1074 buf = kmalloc(8, GFP_KERNEL);
1079 if (!buf) { 1075 if (!buf)
1080 return TRANSPORT_ERROR; 1076 return TRANSPORT_ERROR;
1081 }
1082 1077
1083 card_size = get_card_size(chip, lun); 1078 card_size = get_card_size(chip, lun);
1084 buf[0] = (unsigned char)((card_size - 1) >> 24); 1079 buf[0] = (unsigned char)((card_size - 1) >> 24);
@@ -1116,9 +1111,8 @@ static int read_eeprom(struct scsi_cmnd *srb, struct rtsx_chip *chip)
1116 len = ((u16)srb->cmnd[4] << 8) | srb->cmnd[5]; 1111 len = ((u16)srb->cmnd[4] << 8) | srb->cmnd[5];
1117 1112
1118 buf = vmalloc(len); 1113 buf = vmalloc(len);
1119 if (!buf) { 1114 if (!buf)
1120 return TRANSPORT_ERROR; 1115 return TRANSPORT_ERROR;
1121 }
1122 1116
1123 retval = rtsx_force_power_on(chip, SSC_PDCTL); 1117 retval = rtsx_force_power_on(chip, SSC_PDCTL);
1124 if (retval != STATUS_SUCCESS) { 1118 if (retval != STATUS_SUCCESS) {
@@ -1180,9 +1174,8 @@ static int write_eeprom(struct scsi_cmnd *srb, struct rtsx_chip *chip)
1180 len = (unsigned short)min_t(unsigned int, scsi_bufflen(srb), 1174 len = (unsigned short)min_t(unsigned int, scsi_bufflen(srb),
1181 len); 1175 len);
1182 buf = vmalloc(len); 1176 buf = vmalloc(len);
1183 if (!buf) { 1177 if (!buf)
1184 return TRANSPORT_ERROR; 1178 return TRANSPORT_ERROR;
1185 }
1186 1179
1187 rtsx_stor_get_xfer_buf(buf, len, srb); 1180 rtsx_stor_get_xfer_buf(buf, len, srb);
1188 scsi_set_resid(srb, scsi_bufflen(srb) - len); 1181 scsi_set_resid(srb, scsi_bufflen(srb) - len);
@@ -1227,9 +1220,8 @@ static int read_mem(struct scsi_cmnd *srb, struct rtsx_chip *chip)
1227 } 1220 }
1228 1221
1229 buf = vmalloc(len); 1222 buf = vmalloc(len);
1230 if (!buf) { 1223 if (!buf)
1231 return TRANSPORT_ERROR; 1224 return TRANSPORT_ERROR;
1232 }
1233 1225
1234 retval = rtsx_force_power_on(chip, SSC_PDCTL); 1226 retval = rtsx_force_power_on(chip, SSC_PDCTL);
1235 if (retval != STATUS_SUCCESS) { 1227 if (retval != STATUS_SUCCESS) {
@@ -1282,9 +1274,8 @@ static int write_mem(struct scsi_cmnd *srb, struct rtsx_chip *chip)
1282 1274
1283 len = (unsigned short)min_t(unsigned int, scsi_bufflen(srb), len); 1275 len = (unsigned short)min_t(unsigned int, scsi_bufflen(srb), len);
1284 buf = vmalloc(len); 1276 buf = vmalloc(len);
1285 if (!buf) { 1277 if (!buf)
1286 return TRANSPORT_ERROR; 1278 return TRANSPORT_ERROR;
1287 }
1288 1279
1289 rtsx_stor_get_xfer_buf(buf, len, srb); 1280 rtsx_stor_get_xfer_buf(buf, len, srb);
1290 scsi_set_resid(srb, scsi_bufflen(srb) - len); 1281 scsi_set_resid(srb, scsi_bufflen(srb) - len);
@@ -1702,41 +1693,35 @@ static int set_chip_mode(struct scsi_cmnd *srb, struct rtsx_chip *chip)
1702 if (phy_debug_mode) { 1693 if (phy_debug_mode) {
1703 chip->phy_debug_mode = 1; 1694 chip->phy_debug_mode = 1;
1704 retval = rtsx_write_register(chip, CDRESUMECTL, 0x77, 0); 1695 retval = rtsx_write_register(chip, CDRESUMECTL, 0x77, 0);
1705 if (retval != STATUS_SUCCESS) { 1696 if (retval != STATUS_SUCCESS)
1706 return TRANSPORT_FAILED; 1697 return TRANSPORT_FAILED;
1707 }
1708 1698
1709 rtsx_disable_bus_int(chip); 1699 rtsx_disable_bus_int(chip);
1710 1700
1711 retval = rtsx_read_phy_register(chip, 0x1C, &reg); 1701 retval = rtsx_read_phy_register(chip, 0x1C, &reg);
1712 if (retval != STATUS_SUCCESS) { 1702 if (retval != STATUS_SUCCESS)
1713 return TRANSPORT_FAILED; 1703 return TRANSPORT_FAILED;
1714 }
1715 1704
1716 reg |= 0x0001; 1705 reg |= 0x0001;
1717 retval = rtsx_write_phy_register(chip, 0x1C, reg); 1706 retval = rtsx_write_phy_register(chip, 0x1C, reg);
1718 if (retval != STATUS_SUCCESS) { 1707 if (retval != STATUS_SUCCESS)
1719 return TRANSPORT_FAILED; 1708 return TRANSPORT_FAILED;
1720 }
1721 } else { 1709 } else {
1722 chip->phy_debug_mode = 0; 1710 chip->phy_debug_mode = 0;
1723 retval = rtsx_write_register(chip, CDRESUMECTL, 0x77, 0x77); 1711 retval = rtsx_write_register(chip, CDRESUMECTL, 0x77, 0x77);
1724 if (retval != STATUS_SUCCESS) { 1712 if (retval != STATUS_SUCCESS)
1725 return TRANSPORT_FAILED; 1713 return TRANSPORT_FAILED;
1726 }
1727 1714
1728 rtsx_enable_bus_int(chip); 1715 rtsx_enable_bus_int(chip);
1729 1716
1730 retval = rtsx_read_phy_register(chip, 0x1C, &reg); 1717 retval = rtsx_read_phy_register(chip, 0x1C, &reg);
1731 if (retval != STATUS_SUCCESS) { 1718 if (retval != STATUS_SUCCESS)
1732 return TRANSPORT_FAILED; 1719 return TRANSPORT_FAILED;
1733 }
1734 1720
1735 reg &= 0xFFFE; 1721 reg &= 0xFFFE;
1736 retval = rtsx_write_phy_register(chip, 0x1C, reg); 1722 retval = rtsx_write_phy_register(chip, 0x1C, reg);
1737 if (retval != STATUS_SUCCESS) { 1723 if (retval != STATUS_SUCCESS)
1738 return TRANSPORT_FAILED; 1724 return TRANSPORT_FAILED;
1739 }
1740 } 1725 }
1741 1726
1742 return TRANSPORT_GOOD; 1727 return TRANSPORT_GOOD;
@@ -1840,9 +1825,8 @@ static int read_phy_register(struct scsi_cmnd *srb, struct rtsx_chip *chip)
1840 1825
1841 if (len) { 1826 if (len) {
1842 buf = vmalloc(len); 1827 buf = vmalloc(len);
1843 if (!buf) { 1828 if (!buf)
1844 return TRANSPORT_ERROR; 1829 return TRANSPORT_ERROR;
1845 }
1846 1830
1847 retval = rtsx_force_power_on(chip, SSC_PDCTL); 1831 retval = rtsx_force_power_on(chip, SSC_PDCTL);
1848 if (retval != STATUS_SUCCESS) { 1832 if (retval != STATUS_SUCCESS) {
@@ -1903,9 +1887,8 @@ static int write_phy_register(struct scsi_cmnd *srb, struct rtsx_chip *chip)
1903 len); 1887 len);
1904 1888
1905 buf = vmalloc(len); 1889 buf = vmalloc(len);
1906 if (!buf) { 1890 if (!buf)
1907 return TRANSPORT_ERROR; 1891 return TRANSPORT_ERROR;
1908 }
1909 1892
1910 rtsx_stor_get_xfer_buf(buf, len, srb); 1893 rtsx_stor_get_xfer_buf(buf, len, srb);
1911 scsi_set_resid(srb, scsi_bufflen(srb) - len); 1894 scsi_set_resid(srb, scsi_bufflen(srb) - len);
@@ -1999,9 +1982,8 @@ static int read_eeprom2(struct scsi_cmnd *srb, struct rtsx_chip *chip)
1999 len = ((u16)srb->cmnd[6] << 8) | srb->cmnd[7]; 1982 len = ((u16)srb->cmnd[6] << 8) | srb->cmnd[7];
2000 1983
2001 buf = vmalloc(len); 1984 buf = vmalloc(len);
2002 if (!buf) { 1985 if (!buf)
2003 return TRANSPORT_ERROR; 1986 return TRANSPORT_ERROR;
2004 }
2005 1987
2006 retval = rtsx_force_power_on(chip, SSC_PDCTL); 1988 retval = rtsx_force_power_on(chip, SSC_PDCTL);
2007 if (retval != STATUS_SUCCESS) { 1989 if (retval != STATUS_SUCCESS) {
@@ -2049,9 +2031,8 @@ static int write_eeprom2(struct scsi_cmnd *srb, struct rtsx_chip *chip)
2049 2031
2050 len = (unsigned short)min_t(unsigned int, scsi_bufflen(srb), len); 2032 len = (unsigned short)min_t(unsigned int, scsi_bufflen(srb), len);
2051 buf = vmalloc(len); 2033 buf = vmalloc(len);
2052 if (!buf) { 2034 if (!buf)
2053 return TRANSPORT_ERROR; 2035 return TRANSPORT_ERROR;
2054 }
2055 2036
2056 rtsx_stor_get_xfer_buf(buf, len, srb); 2037 rtsx_stor_get_xfer_buf(buf, len, srb);
2057 scsi_set_resid(srb, scsi_bufflen(srb) - len); 2038 scsi_set_resid(srb, scsi_bufflen(srb) - len);
@@ -2096,9 +2077,8 @@ static int read_efuse(struct scsi_cmnd *srb, struct rtsx_chip *chip)
2096 len = srb->cmnd[5]; 2077 len = srb->cmnd[5];
2097 2078
2098 buf = vmalloc(len); 2079 buf = vmalloc(len);
2099 if (!buf) { 2080 if (!buf)
2100 return TRANSPORT_ERROR; 2081 return TRANSPORT_ERROR;
2101 }
2102 2082
2103 retval = rtsx_force_power_on(chip, SSC_PDCTL); 2083 retval = rtsx_force_power_on(chip, SSC_PDCTL);
2104 if (retval != STATUS_SUCCESS) { 2084 if (retval != STATUS_SUCCESS) {
@@ -2147,9 +2127,8 @@ static int write_efuse(struct scsi_cmnd *srb, struct rtsx_chip *chip)
2147 2127
2148 len = (u8)min_t(unsigned int, scsi_bufflen(srb), len); 2128 len = (u8)min_t(unsigned int, scsi_bufflen(srb), len);
2149 buf = vmalloc(len); 2129 buf = vmalloc(len);
2150 if (!buf) { 2130 if (!buf)
2151 return TRANSPORT_ERROR; 2131 return TRANSPORT_ERROR;
2152 }
2153 2132
2154 rtsx_stor_get_xfer_buf(buf, len, srb); 2133 rtsx_stor_get_xfer_buf(buf, len, srb);
2155 scsi_set_resid(srb, scsi_bufflen(srb) - len); 2134 scsi_set_resid(srb, scsi_bufflen(srb) - len);
@@ -2215,29 +2194,25 @@ exit:
2215 vfree(buf); 2194 vfree(buf);
2216 2195
2217 retval = card_power_off(chip, SPI_CARD); 2196 retval = card_power_off(chip, SPI_CARD);
2218 if (retval != STATUS_SUCCESS) { 2197 if (retval != STATUS_SUCCESS)
2219 return TRANSPORT_ERROR; 2198 return TRANSPORT_ERROR;
2220 }
2221 2199
2222 if (chip->asic_code) { 2200 if (chip->asic_code) {
2223 retval = rtsx_write_register(chip, PWR_GATE_CTRL, 2201 retval = rtsx_write_register(chip, PWR_GATE_CTRL,
2224 LDO3318_PWR_MASK, LDO_OFF); 2202 LDO3318_PWR_MASK, LDO_OFF);
2225 if (retval != STATUS_SUCCESS) { 2203 if (retval != STATUS_SUCCESS)
2226 return TRANSPORT_ERROR; 2204 return TRANSPORT_ERROR;
2227 }
2228 2205
2229 wait_timeout(600); 2206 wait_timeout(600);
2230 2207
2231 retval = rtsx_write_phy_register(chip, 0x08, val); 2208 retval = rtsx_write_phy_register(chip, 0x08, val);
2232 if (retval != STATUS_SUCCESS) { 2209 if (retval != STATUS_SUCCESS)
2233 return TRANSPORT_ERROR; 2210 return TRANSPORT_ERROR;
2234 }
2235 2211
2236 retval = rtsx_write_register(chip, PWR_GATE_CTRL, 2212 retval = rtsx_write_register(chip, PWR_GATE_CTRL,
2237 LDO3318_PWR_MASK, LDO_ON); 2213 LDO3318_PWR_MASK, LDO_ON);
2238 if (retval != STATUS_SUCCESS) { 2214 if (retval != STATUS_SUCCESS)
2239 return TRANSPORT_ERROR; 2215 return TRANSPORT_ERROR;
2240 }
2241 } 2216 }
2242 2217
2243 return result; 2218 return result;
@@ -2278,9 +2253,8 @@ static int read_cfg_byte(struct scsi_cmnd *srb, struct rtsx_chip *chip)
2278 } 2253 }
2279 2254
2280 buf = vmalloc(len); 2255 buf = vmalloc(len);
2281 if (!buf) { 2256 if (!buf)
2282 return TRANSPORT_ERROR; 2257 return TRANSPORT_ERROR;
2283 }
2284 2258
2285 retval = rtsx_read_cfg_seq(chip, func, addr, buf, len); 2259 retval = rtsx_read_cfg_seq(chip, func, addr, buf, len);
2286 if (retval != STATUS_SUCCESS) { 2260 if (retval != STATUS_SUCCESS) {
@@ -2335,9 +2309,8 @@ static int write_cfg_byte(struct scsi_cmnd *srb, struct rtsx_chip *chip)
2335 2309
2336 len = (unsigned short)min_t(unsigned int, scsi_bufflen(srb), len); 2310 len = (unsigned short)min_t(unsigned int, scsi_bufflen(srb), len);
2337 buf = vmalloc(len); 2311 buf = vmalloc(len);
2338 if (!buf) { 2312 if (!buf)
2339 return TRANSPORT_ERROR; 2313 return TRANSPORT_ERROR;
2340 }
2341 2314
2342 rtsx_stor_get_xfer_buf(buf, len, srb); 2315 rtsx_stor_get_xfer_buf(buf, len, srb);
2343 scsi_set_resid(srb, scsi_bufflen(srb) - len); 2316 scsi_set_resid(srb, scsi_bufflen(srb) - len);
@@ -2657,9 +2630,8 @@ static int spi_vendor_cmd(struct scsi_cmnd *srb, struct rtsx_chip *chip)
2657 2630
2658 rtsx_write_register(chip, CARD_GPIO_DIR, 0x07, gpio_dir); 2631 rtsx_write_register(chip, CARD_GPIO_DIR, 0x07, gpio_dir);
2659 2632
2660 if (result != STATUS_SUCCESS) { 2633 if (result != STATUS_SUCCESS)
2661 return TRANSPORT_FAILED; 2634 return TRANSPORT_FAILED;
2662 }
2663 2635
2664 return TRANSPORT_GOOD; 2636 return TRANSPORT_GOOD;
2665} 2637}
@@ -2849,9 +2821,8 @@ static int get_ms_information(struct scsi_cmnd *srb, struct rtsx_chip *chip)
2849 } 2821 }
2850 2822
2851 buf = kmalloc(buf_len, GFP_KERNEL); 2823 buf = kmalloc(buf_len, GFP_KERNEL);
2852 if (!buf) { 2824 if (!buf)
2853 return TRANSPORT_ERROR; 2825 return TRANSPORT_ERROR;
2854 }
2855 2826
2856 i = 0; 2827 i = 0;
2857 /* GET Memory Stick Media Information Response Header */ 2828 /* GET Memory Stick Media Information Response Header */
@@ -3025,9 +2996,8 @@ static int mg_report_key(struct scsi_cmnd *srb, struct rtsx_chip *chip)
3025 (srb->cmnd[8] == 0x04) && 2996 (srb->cmnd[8] == 0x04) &&
3026 (srb->cmnd[9] == 0x1C)) { 2997 (srb->cmnd[9] == 0x1C)) {
3027 retval = mg_get_local_EKB(srb, chip); 2998 retval = mg_get_local_EKB(srb, chip);
3028 if (retval != STATUS_SUCCESS) { 2999 if (retval != STATUS_SUCCESS)
3029 return TRANSPORT_FAILED; 3000 return TRANSPORT_FAILED;
3030 }
3031 3001
3032 } else { 3002 } else {
3033 set_sense_type(chip, lun, 3003 set_sense_type(chip, lun,
@@ -3041,9 +3011,8 @@ static int mg_report_key(struct scsi_cmnd *srb, struct rtsx_chip *chip)
3041 (srb->cmnd[8] == 0x00) && 3011 (srb->cmnd[8] == 0x00) &&
3042 (srb->cmnd[9] == 0x24)) { 3012 (srb->cmnd[9] == 0x24)) {
3043 retval = mg_get_rsp_chg(srb, chip); 3013 retval = mg_get_rsp_chg(srb, chip);
3044 if (retval != STATUS_SUCCESS) { 3014 if (retval != STATUS_SUCCESS)
3045 return TRANSPORT_FAILED; 3015 return TRANSPORT_FAILED;
3046 }
3047 3016
3048 } else { 3017 } else {
3049 set_sense_type(chip, lun, 3018 set_sense_type(chip, lun,
@@ -3062,9 +3031,8 @@ static int mg_report_key(struct scsi_cmnd *srb, struct rtsx_chip *chip)
3062 (srb->cmnd[4] == 0x00) && 3031 (srb->cmnd[4] == 0x00) &&
3063 (srb->cmnd[5] < 32)) { 3032 (srb->cmnd[5] < 32)) {
3064 retval = mg_get_ICV(srb, chip); 3033 retval = mg_get_ICV(srb, chip);
3065 if (retval != STATUS_SUCCESS) { 3034 if (retval != STATUS_SUCCESS)
3066 return TRANSPORT_FAILED; 3035 return TRANSPORT_FAILED;
3067 }
3068 3036
3069 } else { 3037 } else {
3070 set_sense_type(chip, lun, 3038 set_sense_type(chip, lun,
@@ -3131,9 +3099,8 @@ static int mg_send_key(struct scsi_cmnd *srb, struct rtsx_chip *chip)
3131 (srb->cmnd[8] == 0x00) && 3099 (srb->cmnd[8] == 0x00) &&
3132 (srb->cmnd[9] == 0x0C)) { 3100 (srb->cmnd[9] == 0x0C)) {
3133 retval = mg_set_leaf_id(srb, chip); 3101 retval = mg_set_leaf_id(srb, chip);
3134 if (retval != STATUS_SUCCESS) { 3102 if (retval != STATUS_SUCCESS)
3135 return TRANSPORT_FAILED; 3103 return TRANSPORT_FAILED;
3136 }
3137 3104
3138 } else { 3105 } else {
3139 set_sense_type(chip, lun, 3106 set_sense_type(chip, lun,
@@ -3147,9 +3114,8 @@ static int mg_send_key(struct scsi_cmnd *srb, struct rtsx_chip *chip)
3147 (srb->cmnd[8] == 0x00) && 3114 (srb->cmnd[8] == 0x00) &&
3148 (srb->cmnd[9] == 0x0C)) { 3115 (srb->cmnd[9] == 0x0C)) {
3149 retval = mg_chg(srb, chip); 3116 retval = mg_chg(srb, chip);
3150 if (retval != STATUS_SUCCESS) { 3117 if (retval != STATUS_SUCCESS)
3151 return TRANSPORT_FAILED; 3118 return TRANSPORT_FAILED;
3152 }
3153 3119
3154 } else { 3120 } else {
3155 set_sense_type(chip, lun, 3121 set_sense_type(chip, lun,
@@ -3163,9 +3129,8 @@ static int mg_send_key(struct scsi_cmnd *srb, struct rtsx_chip *chip)
3163 (srb->cmnd[8] == 0x00) && 3129 (srb->cmnd[8] == 0x00) &&
3164 (srb->cmnd[9] == 0x0C)) { 3130 (srb->cmnd[9] == 0x0C)) {
3165 retval = mg_rsp(srb, chip); 3131 retval = mg_rsp(srb, chip);
3166 if (retval != STATUS_SUCCESS) { 3132 if (retval != STATUS_SUCCESS)
3167 return TRANSPORT_FAILED; 3133 return TRANSPORT_FAILED;
3168 }
3169 3134
3170 } else { 3135 } else {
3171 set_sense_type(chip, lun, 3136 set_sense_type(chip, lun,
@@ -3184,9 +3149,8 @@ static int mg_send_key(struct scsi_cmnd *srb, struct rtsx_chip *chip)
3184 (srb->cmnd[4] == 0x00) && 3149 (srb->cmnd[4] == 0x00) &&
3185 (srb->cmnd[5] < 32)) { 3150 (srb->cmnd[5] < 32)) {
3186 retval = mg_set_ICV(srb, chip); 3151 retval = mg_set_ICV(srb, chip);
3187 if (retval != STATUS_SUCCESS) { 3152 if (retval != STATUS_SUCCESS)
3188 return TRANSPORT_FAILED; 3153 return TRANSPORT_FAILED;
3189 }
3190 3154
3191 } else { 3155 } else {
3192 set_sense_type(chip, lun, 3156 set_sense_type(chip, lun,
diff --git a/drivers/staging/rts5208/sd.c b/drivers/staging/rts5208/sd.c
index e7efa34195c7..ff1a9aa152ce 100644
--- a/drivers/staging/rts5208/sd.c
+++ b/drivers/staging/rts5208/sd.c
@@ -109,9 +109,8 @@ static int sd_check_data0_status(struct rtsx_chip *chip)
109 u8 stat; 109 u8 stat;
110 110
111 retval = rtsx_read_register(chip, REG_SD_STAT1, &stat); 111 retval = rtsx_read_register(chip, REG_SD_STAT1, &stat);
112 if (retval) { 112 if (retval)
113 return retval; 113 return retval;
114 }
115 114
116 if (!(stat & SD_DAT0_STATUS)) { 115 if (!(stat & SD_DAT0_STATUS)) {
117 sd_set_err_code(chip, SD_BUSY); 116 sd_set_err_code(chip, SD_BUSY);
@@ -234,9 +233,8 @@ RTY_SEND_CMD:
234 if ((cmd_idx != SEND_RELATIVE_ADDR) && 233 if ((cmd_idx != SEND_RELATIVE_ADDR) &&
235 (cmd_idx != SEND_IF_COND)) { 234 (cmd_idx != SEND_IF_COND)) {
236 if (cmd_idx != STOP_TRANSMISSION) { 235 if (cmd_idx != STOP_TRANSMISSION) {
237 if (ptr[1] & 0x80) { 236 if (ptr[1] & 0x80)
238 return STATUS_FAIL; 237 return STATUS_FAIL;
239 }
240 } 238 }
241#ifdef SUPPORT_SD_LOCK 239#ifdef SUPPORT_SD_LOCK
242 if (ptr[1] & 0x7D) { 240 if (ptr[1] & 0x7D) {
@@ -284,9 +282,8 @@ static int sd_read_data(struct rtsx_chip *chip,
284 if (!buf) 282 if (!buf)
285 buf_len = 0; 283 buf_len = 0;
286 284
287 if (buf_len > 512) { 285 if (buf_len > 512)
288 return STATUS_FAIL; 286 return STATUS_FAIL;
289 }
290 287
291 rtsx_init_cmd(chip); 288 rtsx_init_cmd(chip);
292 289
@@ -331,9 +328,8 @@ static int sd_read_data(struct rtsx_chip *chip,
331 328
332 if (buf && buf_len) { 329 if (buf && buf_len) {
333 retval = rtsx_read_ppbuf(chip, buf, buf_len); 330 retval = rtsx_read_ppbuf(chip, buf, buf_len);
334 if (retval != STATUS_SUCCESS) { 331 if (retval != STATUS_SUCCESS)
335 return STATUS_FAIL; 332 return STATUS_FAIL;
336 }
337 } 333 }
338 334
339 return STATUS_SUCCESS; 335 return STATUS_SUCCESS;
@@ -359,9 +355,8 @@ static int sd_write_data(struct rtsx_chip *chip, u8 trans_mode,
359 355
360 if (buf && buf_len) { 356 if (buf && buf_len) {
361 retval = rtsx_write_ppbuf(chip, buf, buf_len); 357 retval = rtsx_write_ppbuf(chip, buf, buf_len);
362 if (retval != STATUS_SUCCESS) { 358 if (retval != STATUS_SUCCESS)
363 return STATUS_FAIL; 359 return STATUS_FAIL;
364 }
365 } 360 }
366 361
367 rtsx_init_cmd(chip); 362 rtsx_init_cmd(chip);
@@ -426,9 +421,8 @@ static int sd_check_csd(struct rtsx_chip *chip, char check_wp)
426 break; 421 break;
427 } 422 }
428 423
429 if (i == 6) { 424 if (i == 6)
430 return STATUS_FAIL; 425 return STATUS_FAIL;
431 }
432 426
433 memcpy(sd_card->raw_csd, rsp + 1, 15); 427 memcpy(sd_card->raw_csd, rsp + 1, 15);
434 428
@@ -543,9 +537,8 @@ static int sd_set_sample_push_timing(struct rtsx_chip *chip)
543 } 537 }
544 538
545 retval = rtsx_write_register(chip, REG_SD_CFG1, 0x1C, val); 539 retval = rtsx_write_register(chip, REG_SD_CFG1, 0x1C, val);
546 if (retval) { 540 if (retval)
547 return retval; 541 return retval;
548 }
549 542
550 return STATUS_SUCCESS; 543 return STATUS_SUCCESS;
551} 544}
@@ -606,9 +599,8 @@ static int sd_set_clock_divider(struct rtsx_chip *chip, u8 clk_div)
606 val = 0x20; 599 val = 0x20;
607 600
608 retval = rtsx_write_register(chip, REG_SD_CFG1, mask, val); 601 retval = rtsx_write_register(chip, REG_SD_CFG1, mask, val);
609 if (retval) { 602 if (retval)
610 return retval; 603 return retval;
611 }
612 604
613 return STATUS_SUCCESS; 605 return STATUS_SUCCESS;
614} 606}
@@ -619,16 +611,14 @@ static int sd_set_init_para(struct rtsx_chip *chip)
619 int retval; 611 int retval;
620 612
621 retval = sd_set_sample_push_timing(chip); 613 retval = sd_set_sample_push_timing(chip);
622 if (retval != STATUS_SUCCESS) { 614 if (retval != STATUS_SUCCESS)
623 return STATUS_FAIL; 615 return STATUS_FAIL;
624 }
625 616
626 sd_choose_proper_clock(chip); 617 sd_choose_proper_clock(chip);
627 618
628 retval = switch_clock(chip, sd_card->sd_clock); 619 retval = switch_clock(chip, sd_card->sd_clock);
629 if (retval != STATUS_SUCCESS) { 620 if (retval != STATUS_SUCCESS)
630 return STATUS_FAIL; 621 return STATUS_FAIL;
631 }
632 622
633 return STATUS_SUCCESS; 623 return STATUS_SUCCESS;
634} 624}
@@ -651,9 +641,8 @@ int sd_select_card(struct rtsx_chip *chip, int select)
651 } 641 }
652 642
653 retval = sd_send_cmd_get_rsp(chip, cmd_idx, addr, cmd_type, NULL, 0); 643 retval = sd_send_cmd_get_rsp(chip, cmd_idx, addr, cmd_type, NULL, 0);
654 if (retval != STATUS_SUCCESS) { 644 if (retval != STATUS_SUCCESS)
655 return STATUS_FAIL; 645 return STATUS_FAIL;
656 }
657 646
658 return STATUS_SUCCESS; 647 return STATUS_SUCCESS;
659} 648}
@@ -667,9 +656,8 @@ static int sd_update_lock_status(struct rtsx_chip *chip)
667 656
668 retval = sd_send_cmd_get_rsp(chip, SEND_STATUS, sd_card->sd_addr, 657 retval = sd_send_cmd_get_rsp(chip, SEND_STATUS, sd_card->sd_addr,
669 SD_RSP_TYPE_R1, rsp, 5); 658 SD_RSP_TYPE_R1, rsp, 5);
670 if (retval != STATUS_SUCCESS) { 659 if (retval != STATUS_SUCCESS)
671 return STATUS_FAIL; 660 return STATUS_FAIL;
672 }
673 661
674 if (rsp[1] & 0x02) 662 if (rsp[1] & 0x02)
675 sd_card->sd_lock_status |= SD_LOCKED; 663 sd_card->sd_lock_status |= SD_LOCKED;
@@ -679,9 +667,8 @@ static int sd_update_lock_status(struct rtsx_chip *chip)
679 dev_dbg(rtsx_dev(chip), "sd_card->sd_lock_status = 0x%x\n", 667 dev_dbg(rtsx_dev(chip), "sd_card->sd_lock_status = 0x%x\n",
680 sd_card->sd_lock_status); 668 sd_card->sd_lock_status);
681 669
682 if (rsp[1] & 0x01) { 670 if (rsp[1] & 0x01)
683 return STATUS_FAIL; 671 return STATUS_FAIL;
684 }
685 672
686 return STATUS_SUCCESS; 673 return STATUS_SUCCESS;
687} 674}
@@ -698,9 +685,8 @@ static int sd_wait_state_data_ready(struct rtsx_chip *chip, u8 state,
698 retval = sd_send_cmd_get_rsp(chip, SEND_STATUS, 685 retval = sd_send_cmd_get_rsp(chip, SEND_STATUS,
699 sd_card->sd_addr, SD_RSP_TYPE_R1, 686 sd_card->sd_addr, SD_RSP_TYPE_R1,
700 rsp, 5); 687 rsp, 5);
701 if (retval != STATUS_SUCCESS) { 688 if (retval != STATUS_SUCCESS)
702 return STATUS_FAIL; 689 return STATUS_FAIL;
703 }
704 690
705 if (((rsp[3] & 0x1E) == state) && 691 if (((rsp[3] & 0x1E) == state) &&
706 ((rsp[3] & 0x01) == data_ready)) 692 ((rsp[3] & 0x01) == data_ready))
@@ -719,31 +705,27 @@ static int sd_change_bank_voltage(struct rtsx_chip *chip, u8 voltage)
719 retval = rtsx_write_phy_register(chip, 0x08, 705 retval = rtsx_write_phy_register(chip, 0x08,
720 0x4FC0 | 706 0x4FC0 |
721 chip->phy_voltage); 707 chip->phy_voltage);
722 if (retval != STATUS_SUCCESS) { 708 if (retval != STATUS_SUCCESS)
723 return STATUS_FAIL; 709 return STATUS_FAIL;
724 }
725 } else { 710 } else {
726 retval = rtsx_write_register(chip, SD_PAD_CTL, 711 retval = rtsx_write_register(chip, SD_PAD_CTL,
727 SD_IO_USING_1V8, 0); 712 SD_IO_USING_1V8, 0);
728 if (retval) { 713 if (retval)
729 return retval; 714 return retval;
730 }
731 } 715 }
732 } else if (voltage == SD_IO_1V8) { 716 } else if (voltage == SD_IO_1V8) {
733 if (chip->asic_code) { 717 if (chip->asic_code) {
734 retval = rtsx_write_phy_register(chip, 0x08, 718 retval = rtsx_write_phy_register(chip, 0x08,
735 0x4C40 | 719 0x4C40 |
736 chip->phy_voltage); 720 chip->phy_voltage);
737 if (retval != STATUS_SUCCESS) { 721 if (retval != STATUS_SUCCESS)
738 return STATUS_FAIL; 722 return STATUS_FAIL;
739 }
740 } else { 723 } else {
741 retval = rtsx_write_register(chip, SD_PAD_CTL, 724 retval = rtsx_write_register(chip, SD_PAD_CTL,
742 SD_IO_USING_1V8, 725 SD_IO_USING_1V8,
743 SD_IO_USING_1V8); 726 SD_IO_USING_1V8);
744 if (retval) { 727 if (retval)
745 return retval; 728 return retval;
746 }
747 } 729 }
748 } else { 730 } else {
749 return STATUS_FAIL; 731 return STATUS_FAIL;
@@ -760,22 +742,19 @@ static int sd_voltage_switch(struct rtsx_chip *chip)
760 retval = rtsx_write_register(chip, SD_BUS_STAT, 742 retval = rtsx_write_register(chip, SD_BUS_STAT,
761 SD_CLK_TOGGLE_EN | SD_CLK_FORCE_STOP, 743 SD_CLK_TOGGLE_EN | SD_CLK_FORCE_STOP,
762 SD_CLK_TOGGLE_EN); 744 SD_CLK_TOGGLE_EN);
763 if (retval) { 745 if (retval)
764 return retval; 746 return retval;
765 }
766 747
767 retval = sd_send_cmd_get_rsp(chip, VOLTAGE_SWITCH, 0, SD_RSP_TYPE_R1, 748 retval = sd_send_cmd_get_rsp(chip, VOLTAGE_SWITCH, 0, SD_RSP_TYPE_R1,
768 NULL, 0); 749 NULL, 0);
769 if (retval != STATUS_SUCCESS) { 750 if (retval != STATUS_SUCCESS)
770 return STATUS_FAIL; 751 return STATUS_FAIL;
771 }
772 752
773 udelay(chip->sd_voltage_switch_delay); 753 udelay(chip->sd_voltage_switch_delay);
774 754
775 retval = rtsx_read_register(chip, SD_BUS_STAT, &stat); 755 retval = rtsx_read_register(chip, SD_BUS_STAT, &stat);
776 if (retval) { 756 if (retval)
777 return retval; 757 return retval;
778 }
779 if (stat & (SD_CMD_STATUS | SD_DAT3_STATUS | SD_DAT2_STATUS | 758 if (stat & (SD_CMD_STATUS | SD_DAT3_STATUS | SD_DAT2_STATUS |
780 SD_DAT1_STATUS | SD_DAT0_STATUS)) { 759 SD_DAT1_STATUS | SD_DAT0_STATUS)) {
781 return STATUS_FAIL; 760 return STATUS_FAIL;
@@ -783,27 +762,23 @@ static int sd_voltage_switch(struct rtsx_chip *chip)
783 762
784 retval = rtsx_write_register(chip, SD_BUS_STAT, 0xFF, 763 retval = rtsx_write_register(chip, SD_BUS_STAT, 0xFF,
785 SD_CLK_FORCE_STOP); 764 SD_CLK_FORCE_STOP);
786 if (retval) { 765 if (retval)
787 return retval; 766 return retval;
788 }
789 retval = sd_change_bank_voltage(chip, SD_IO_1V8); 767 retval = sd_change_bank_voltage(chip, SD_IO_1V8);
790 if (retval != STATUS_SUCCESS) { 768 if (retval != STATUS_SUCCESS)
791 return STATUS_FAIL; 769 return STATUS_FAIL;
792 }
793 770
794 wait_timeout(50); 771 wait_timeout(50);
795 772
796 retval = rtsx_write_register(chip, SD_BUS_STAT, 0xFF, 773 retval = rtsx_write_register(chip, SD_BUS_STAT, 0xFF,
797 SD_CLK_TOGGLE_EN); 774 SD_CLK_TOGGLE_EN);
798 if (retval) { 775 if (retval)
799 return retval; 776 return retval;
800 }
801 wait_timeout(10); 777 wait_timeout(10);
802 778
803 retval = rtsx_read_register(chip, SD_BUS_STAT, &stat); 779 retval = rtsx_read_register(chip, SD_BUS_STAT, &stat);
804 if (retval) { 780 if (retval)
805 return retval; 781 return retval;
806 }
807 if ((stat & (SD_CMD_STATUS | SD_DAT3_STATUS | SD_DAT2_STATUS | 782 if ((stat & (SD_CMD_STATUS | SD_DAT3_STATUS | SD_DAT2_STATUS |
808 SD_DAT1_STATUS | SD_DAT0_STATUS)) != 783 SD_DAT1_STATUS | SD_DAT0_STATUS)) !=
809 (SD_CMD_STATUS | SD_DAT3_STATUS | SD_DAT2_STATUS | 784 (SD_CMD_STATUS | SD_DAT3_STATUS | SD_DAT2_STATUS |
@@ -817,9 +792,8 @@ static int sd_voltage_switch(struct rtsx_chip *chip)
817 792
818 retval = rtsx_write_register(chip, SD_BUS_STAT, 793 retval = rtsx_write_register(chip, SD_BUS_STAT,
819 SD_CLK_TOGGLE_EN | SD_CLK_FORCE_STOP, 0); 794 SD_CLK_TOGGLE_EN | SD_CLK_FORCE_STOP, 0);
820 if (retval) { 795 if (retval)
821 return retval; 796 return retval;
822 }
823 797
824 return STATUS_SUCCESS; 798 return STATUS_SUCCESS;
825} 799}
@@ -831,23 +805,19 @@ static int sd_reset_dcm(struct rtsx_chip *chip, u8 tune_dir)
831 if (tune_dir == TUNE_RX) { 805 if (tune_dir == TUNE_RX) {
832 retval = rtsx_write_register(chip, DCM_DRP_CTL, 0xFF, 806 retval = rtsx_write_register(chip, DCM_DRP_CTL, 0xFF,
833 DCM_RESET | DCM_RX); 807 DCM_RESET | DCM_RX);
834 if (retval) { 808 if (retval)
835 return retval; 809 return retval;
836 }
837 retval = rtsx_write_register(chip, DCM_DRP_CTL, 0xFF, DCM_RX); 810 retval = rtsx_write_register(chip, DCM_DRP_CTL, 0xFF, DCM_RX);
838 if (retval) { 811 if (retval)
839 return retval; 812 return retval;
840 }
841 } else { 813 } else {
842 retval = rtsx_write_register(chip, DCM_DRP_CTL, 0xFF, 814 retval = rtsx_write_register(chip, DCM_DRP_CTL, 0xFF,
843 DCM_RESET | DCM_TX); 815 DCM_RESET | DCM_TX);
844 if (retval) { 816 if (retval)
845 return retval; 817 return retval;
846 }
847 retval = rtsx_write_register(chip, DCM_DRP_CTL, 0xFF, DCM_TX); 818 retval = rtsx_write_register(chip, DCM_DRP_CTL, 0xFF, DCM_TX);
848 if (retval) { 819 if (retval)
849 return retval; 820 return retval;
850 }
851 } 821 }
852 822
853 return STATUS_SUCCESS; 823 return STATUS_SUCCESS;
@@ -877,28 +847,23 @@ static int sd_change_phase(struct rtsx_chip *chip, u8 sample_point, u8 tune_dir)
877 if (chip->asic_code) { 847 if (chip->asic_code) {
878 retval = rtsx_write_register(chip, CLK_CTL, CHANGE_CLK, 848 retval = rtsx_write_register(chip, CLK_CTL, CHANGE_CLK,
879 CHANGE_CLK); 849 CHANGE_CLK);
880 if (retval) { 850 if (retval)
881 return retval; 851 return retval;
882 }
883 retval = rtsx_write_register(chip, SD_VP_CTL, 0x1F, 852 retval = rtsx_write_register(chip, SD_VP_CTL, 0x1F,
884 sample_point); 853 sample_point);
885 if (retval) { 854 if (retval)
886 return retval; 855 return retval;
887 }
888 retval = rtsx_write_register(chip, SD_VPCLK0_CTL, 856 retval = rtsx_write_register(chip, SD_VPCLK0_CTL,
889 PHASE_NOT_RESET, 0); 857 PHASE_NOT_RESET, 0);
890 if (retval) { 858 if (retval)
891 return retval; 859 return retval;
892 }
893 retval = rtsx_write_register(chip, SD_VPCLK0_CTL, 860 retval = rtsx_write_register(chip, SD_VPCLK0_CTL,
894 PHASE_NOT_RESET, PHASE_NOT_RESET); 861 PHASE_NOT_RESET, PHASE_NOT_RESET);
895 if (retval) { 862 if (retval)
896 return retval; 863 return retval;
897 }
898 retval = rtsx_write_register(chip, CLK_CTL, CHANGE_CLK, 0); 864 retval = rtsx_write_register(chip, CLK_CTL, CHANGE_CLK, 0);
899 if (retval) { 865 if (retval)
900 return retval; 866 return retval;
901 }
902 } else { 867 } else {
903 rtsx_read_register(chip, SD_VP_CTL, &val); 868 rtsx_read_register(chip, SD_VP_CTL, &val);
904 dev_dbg(rtsx_dev(chip), "SD_VP_CTL: 0x%x\n", val); 869 dev_dbg(rtsx_dev(chip), "SD_VP_CTL: 0x%x\n", val);
@@ -909,30 +874,26 @@ static int sd_change_phase(struct rtsx_chip *chip, u8 sample_point, u8 tune_dir)
909 retval = rtsx_write_register(chip, SD_VP_CTL, 874 retval = rtsx_write_register(chip, SD_VP_CTL,
910 PHASE_CHANGE, 875 PHASE_CHANGE,
911 PHASE_CHANGE); 876 PHASE_CHANGE);
912 if (retval) { 877 if (retval)
913 return retval; 878 return retval;
914 }
915 udelay(50); 879 udelay(50);
916 retval = rtsx_write_register(chip, SD_VP_CTL, 0xFF, 880 retval = rtsx_write_register(chip, SD_VP_CTL, 0xFF,
917 PHASE_CHANGE | 881 PHASE_CHANGE |
918 PHASE_NOT_RESET | 882 PHASE_NOT_RESET |
919 sample_point); 883 sample_point);
920 if (retval) { 884 if (retval)
921 return retval; 885 return retval;
922 }
923 } else { 886 } else {
924 retval = rtsx_write_register(chip, CLK_CTL, 887 retval = rtsx_write_register(chip, CLK_CTL,
925 CHANGE_CLK, CHANGE_CLK); 888 CHANGE_CLK, CHANGE_CLK);
926 if (retval) { 889 if (retval)
927 return retval; 890 return retval;
928 }
929 udelay(50); 891 udelay(50);
930 retval = rtsx_write_register(chip, SD_VP_CTL, 0xFF, 892 retval = rtsx_write_register(chip, SD_VP_CTL, 0xFF,
931 PHASE_NOT_RESET | 893 PHASE_NOT_RESET |
932 sample_point); 894 sample_point);
933 if (retval) { 895 if (retval)
934 return retval; 896 return retval;
935 }
936 } 897 }
937 udelay(100); 898 udelay(100);
938 899
@@ -942,45 +903,38 @@ static int sd_change_phase(struct rtsx_chip *chip, u8 sample_point, u8 tune_dir)
942 rtsx_add_cmd(chip, CHECK_REG_CMD, SD_DCMPS_CTL, 903 rtsx_add_cmd(chip, CHECK_REG_CMD, SD_DCMPS_CTL,
943 DCMPS_CHANGE_DONE, DCMPS_CHANGE_DONE); 904 DCMPS_CHANGE_DONE, DCMPS_CHANGE_DONE);
944 retval = rtsx_send_cmd(chip, SD_CARD, 100); 905 retval = rtsx_send_cmd(chip, SD_CARD, 100);
945 if (retval != STATUS_SUCCESS) { 906 if (retval != STATUS_SUCCESS)
946 goto fail; 907 goto fail;
947 }
948 908
949 val = *rtsx_get_cmd_data(chip); 909 val = *rtsx_get_cmd_data(chip);
950 if (val & DCMPS_ERROR) { 910 if (val & DCMPS_ERROR)
951 goto fail; 911 goto fail;
952 }
953 912
954 if ((val & DCMPS_CURRENT_PHASE) != sample_point) { 913 if ((val & DCMPS_CURRENT_PHASE) != sample_point)
955 goto fail; 914 goto fail;
956 }
957 915
958 retval = rtsx_write_register(chip, SD_DCMPS_CTL, 916 retval = rtsx_write_register(chip, SD_DCMPS_CTL,
959 DCMPS_CHANGE, 0); 917 DCMPS_CHANGE, 0);
960 if (retval) { 918 if (retval)
961 return retval; 919 return retval;
962 }
963 if (ddr_rx) { 920 if (ddr_rx) {
964 retval = rtsx_write_register(chip, SD_VP_CTL, 921 retval = rtsx_write_register(chip, SD_VP_CTL,
965 PHASE_CHANGE, 0); 922 PHASE_CHANGE, 0);
966 if (retval) { 923 if (retval)
967 return retval; 924 return retval;
968 }
969 } else { 925 } else {
970 retval = rtsx_write_register(chip, CLK_CTL, 926 retval = rtsx_write_register(chip, CLK_CTL,
971 CHANGE_CLK, 0); 927 CHANGE_CLK, 0);
972 if (retval) { 928 if (retval)
973 return retval; 929 return retval;
974 }
975 } 930 }
976 931
977 udelay(50); 932 udelay(50);
978 } 933 }
979 934
980 retval = rtsx_write_register(chip, SD_CFG1, SD_ASYNC_FIFO_NOT_RST, 0); 935 retval = rtsx_write_register(chip, SD_CFG1, SD_ASYNC_FIFO_NOT_RST, 0);
981 if (retval) { 936 if (retval)
982 return retval; 937 return retval;
983 }
984 938
985 return STATUS_SUCCESS; 939 return STATUS_SUCCESS;
986 940
@@ -1005,9 +959,8 @@ static int sd_check_spec(struct rtsx_chip *chip, u8 bus_width)
1005 959
1006 retval = sd_send_cmd_get_rsp(chip, APP_CMD, sd_card->sd_addr, 960 retval = sd_send_cmd_get_rsp(chip, APP_CMD, sd_card->sd_addr,
1007 SD_RSP_TYPE_R1, NULL, 0); 961 SD_RSP_TYPE_R1, NULL, 0);
1008 if (retval != STATUS_SUCCESS) { 962 if (retval != STATUS_SUCCESS)
1009 return STATUS_FAIL; 963 return STATUS_FAIL;
1010 }
1011 964
1012 cmd[0] = 0x40 | SEND_SCR; 965 cmd[0] = 0x40 | SEND_SCR;
1013 cmd[1] = 0; 966 cmd[1] = 0;
@@ -1024,9 +977,8 @@ static int sd_check_spec(struct rtsx_chip *chip, u8 bus_width)
1024 977
1025 memcpy(sd_card->raw_scr, buf, 8); 978 memcpy(sd_card->raw_scr, buf, 8);
1026 979
1027 if ((buf[0] & 0x0F) == 0) { 980 if ((buf[0] & 0x0F) == 0)
1028 return STATUS_FAIL; 981 return STATUS_FAIL;
1029 }
1030 982
1031 return STATUS_SUCCESS; 983 return STATUS_SUCCESS;
1032} 984}
@@ -1207,29 +1159,25 @@ static int sd_check_switch_mode(struct rtsx_chip *chip, u8 mode, u8 func_group,
1207 1159
1208 dev_dbg(rtsx_dev(chip), "Maximum current consumption: %dmA\n", 1160 dev_dbg(rtsx_dev(chip), "Maximum current consumption: %dmA\n",
1209 cc); 1161 cc);
1210 if ((cc == 0) || (cc > 800)) { 1162 if ((cc == 0) || (cc > 800))
1211 return STATUS_FAIL; 1163 return STATUS_FAIL;
1212 }
1213 1164
1214 retval = sd_query_switch_result(chip, func_group, 1165 retval = sd_query_switch_result(chip, func_group,
1215 func_to_switch, buf, 64); 1166 func_to_switch, buf, 64);
1216 if (retval != STATUS_SUCCESS) { 1167 if (retval != STATUS_SUCCESS)
1217 return STATUS_FAIL; 1168 return STATUS_FAIL;
1218 }
1219 1169
1220 if ((cc > 400) || (func_to_switch > CURRENT_LIMIT_400)) { 1170 if ((cc > 400) || (func_to_switch > CURRENT_LIMIT_400)) {
1221 retval = rtsx_write_register(chip, OCPPARA2, 1171 retval = rtsx_write_register(chip, OCPPARA2,
1222 SD_OCP_THD_MASK, 1172 SD_OCP_THD_MASK,
1223 chip->sd_800mA_ocp_thd); 1173 chip->sd_800mA_ocp_thd);
1224 if (retval) { 1174 if (retval)
1225 return retval; 1175 return retval;
1226 }
1227 retval = rtsx_write_register(chip, CARD_PWR_CTL, 1176 retval = rtsx_write_register(chip, CARD_PWR_CTL,
1228 PMOS_STRG_MASK, 1177 PMOS_STRG_MASK,
1229 PMOS_STRG_800mA); 1178 PMOS_STRG_800mA);
1230 if (retval) { 1179 if (retval)
1231 return retval; 1180 return retval;
1232 }
1233 } 1181 }
1234 } 1182 }
1235 1183
@@ -1278,9 +1226,8 @@ static int sd_check_switch(struct rtsx_chip *chip,
1278 } 1226 }
1279 1227
1280 retval = rtsx_read_register(chip, SD_STAT1, &stat); 1228 retval = rtsx_read_register(chip, SD_STAT1, &stat);
1281 if (retval) { 1229 if (retval)
1282 return retval; 1230 return retval;
1283 }
1284 if (stat & SD_CRC16_ERR) { 1231 if (stat & SD_CRC16_ERR) {
1285 dev_dbg(rtsx_dev(chip), "SD CRC16 error when switching mode\n"); 1232 dev_dbg(rtsx_dev(chip), "SD CRC16 error when switching mode\n");
1286 return STATUS_FAIL; 1233 return STATUS_FAIL;
@@ -1293,9 +1240,8 @@ static int sd_check_switch(struct rtsx_chip *chip,
1293 wait_timeout(20); 1240 wait_timeout(20);
1294 } 1241 }
1295 1242
1296 if (!switch_good) { 1243 if (!switch_good)
1297 return STATUS_FAIL; 1244 return STATUS_FAIL;
1298 }
1299 1245
1300 return STATUS_SUCCESS; 1246 return STATUS_SUCCESS;
1301} 1247}
@@ -1310,9 +1256,8 @@ static int sd_switch_function(struct rtsx_chip *chip, u8 bus_width)
1310 /* Get supported functions */ 1256 /* Get supported functions */
1311 retval = sd_check_switch_mode(chip, SD_CHECK_MODE, NO_ARGUMENT, 1257 retval = sd_check_switch_mode(chip, SD_CHECK_MODE, NO_ARGUMENT,
1312 NO_ARGUMENT, bus_width); 1258 NO_ARGUMENT, bus_width);
1313 if (retval != STATUS_SUCCESS) { 1259 if (retval != STATUS_SUCCESS)
1314 return STATUS_FAIL; 1260 return STATUS_FAIL;
1315 }
1316 1261
1317 sd_card->func_group1_mask &= ~(sd_card->sd_switch_fail); 1262 sd_card->func_group1_mask &= ~(sd_card->sd_switch_fail);
1318 1263
@@ -1394,13 +1339,11 @@ static int sd_switch_function(struct rtsx_chip *chip, u8 bus_width)
1394 if (CHK_SD_DDR50(sd_card)) { 1339 if (CHK_SD_DDR50(sd_card)) {
1395 retval = rtsx_write_register(chip, SD_PUSH_POINT_CTL, 0x06, 1340 retval = rtsx_write_register(chip, SD_PUSH_POINT_CTL, 0x06,
1396 0x04); 1341 0x04);
1397 if (retval) { 1342 if (retval)
1398 return retval; 1343 return retval;
1399 }
1400 retval = sd_set_sample_push_timing(chip); 1344 retval = sd_set_sample_push_timing(chip);
1401 if (retval != STATUS_SUCCESS) { 1345 if (retval != STATUS_SUCCESS)
1402 return STATUS_FAIL; 1346 return STATUS_FAIL;
1403 }
1404 } 1347 }
1405 1348
1406 if (!func_to_switch || (func_to_switch == HS_SUPPORT)) { 1349 if (!func_to_switch || (func_to_switch == HS_SUPPORT)) {
@@ -1454,9 +1397,8 @@ static int sd_switch_function(struct rtsx_chip *chip, u8 bus_width)
1454 retval = sd_check_switch(chip, SD_FUNC_GROUP_4, func_to_switch, 1397 retval = sd_check_switch(chip, SD_FUNC_GROUP_4, func_to_switch,
1455 bus_width); 1398 bus_width);
1456 if (retval != STATUS_SUCCESS) { 1399 if (retval != STATUS_SUCCESS) {
1457 if (sd_check_err_code(chip, SD_NO_CARD)) { 1400 if (sd_check_err_code(chip, SD_NO_CARD))
1458 return STATUS_FAIL; 1401 return STATUS_FAIL;
1459 }
1460 } 1402 }
1461 dev_dbg(rtsx_dev(chip), "Switch current limit finished! (%d)\n", 1403 dev_dbg(rtsx_dev(chip), "Switch current limit finished! (%d)\n",
1462 retval); 1404 retval);
@@ -1464,9 +1406,8 @@ static int sd_switch_function(struct rtsx_chip *chip, u8 bus_width)
1464 1406
1465 if (CHK_SD_DDR50(sd_card)) { 1407 if (CHK_SD_DDR50(sd_card)) {
1466 retval = rtsx_write_register(chip, SD_PUSH_POINT_CTL, 0x06, 0); 1408 retval = rtsx_write_register(chip, SD_PUSH_POINT_CTL, 0x06, 0);
1467 if (retval) { 1409 if (retval)
1468 return retval; 1410 return retval;
1469 }
1470 } 1411 }
1471 1412
1472 return STATUS_SUCCESS; 1413 return STATUS_SUCCESS;
@@ -1480,9 +1421,8 @@ static int sd_wait_data_idle(struct rtsx_chip *chip)
1480 1421
1481 for (i = 0; i < 100; i++) { 1422 for (i = 0; i < 100; i++) {
1482 retval = rtsx_read_register(chip, SD_DATA_STATE, &val); 1423 retval = rtsx_read_register(chip, SD_DATA_STATE, &val);
1483 if (retval) { 1424 if (retval)
1484 return retval; 1425 return retval;
1485 }
1486 if (val & SD_DATA_IDLE) { 1426 if (val & SD_DATA_IDLE) {
1487 retval = STATUS_SUCCESS; 1427 retval = STATUS_SUCCESS;
1488 break; 1428 break;
@@ -1500,9 +1440,8 @@ static int sd_sdr_tuning_rx_cmd(struct rtsx_chip *chip, u8 sample_point)
1500 u8 cmd[5]; 1440 u8 cmd[5];
1501 1441
1502 retval = sd_change_phase(chip, sample_point, TUNE_RX); 1442 retval = sd_change_phase(chip, sample_point, TUNE_RX);
1503 if (retval != STATUS_SUCCESS) { 1443 if (retval != STATUS_SUCCESS)
1504 return STATUS_FAIL; 1444 return STATUS_FAIL;
1505 }
1506 1445
1507 cmd[0] = 0x40 | SEND_TUNING_PATTERN; 1446 cmd[0] = 0x40 | SEND_TUNING_PATTERN;
1508 cmd[1] = 0; 1447 cmd[1] = 0;
@@ -1529,17 +1468,15 @@ static int sd_ddr_tuning_rx_cmd(struct rtsx_chip *chip, u8 sample_point)
1529 u8 cmd[5]; 1468 u8 cmd[5];
1530 1469
1531 retval = sd_change_phase(chip, sample_point, TUNE_RX); 1470 retval = sd_change_phase(chip, sample_point, TUNE_RX);
1532 if (retval != STATUS_SUCCESS) { 1471 if (retval != STATUS_SUCCESS)
1533 return STATUS_FAIL; 1472 return STATUS_FAIL;
1534 }
1535 1473
1536 dev_dbg(rtsx_dev(chip), "sd ddr tuning rx\n"); 1474 dev_dbg(rtsx_dev(chip), "sd ddr tuning rx\n");
1537 1475
1538 retval = sd_send_cmd_get_rsp(chip, APP_CMD, sd_card->sd_addr, 1476 retval = sd_send_cmd_get_rsp(chip, APP_CMD, sd_card->sd_addr,
1539 SD_RSP_TYPE_R1, NULL, 0); 1477 SD_RSP_TYPE_R1, NULL, 0);
1540 if (retval != STATUS_SUCCESS) { 1478 if (retval != STATUS_SUCCESS)
1541 return STATUS_FAIL; 1479 return STATUS_FAIL;
1542 }
1543 1480
1544 cmd[0] = 0x40 | SD_STATUS; 1481 cmd[0] = 0x40 | SD_STATUS;
1545 cmd[1] = 0; 1482 cmd[1] = 0;
@@ -1573,9 +1510,8 @@ static int mmc_ddr_tuning_rx_cmd(struct rtsx_chip *chip, u8 sample_point)
1573 bus_width = SD_BUS_WIDTH_1; 1510 bus_width = SD_BUS_WIDTH_1;
1574 1511
1575 retval = sd_change_phase(chip, sample_point, TUNE_RX); 1512 retval = sd_change_phase(chip, sample_point, TUNE_RX);
1576 if (retval != STATUS_SUCCESS) { 1513 if (retval != STATUS_SUCCESS)
1577 return STATUS_FAIL; 1514 return STATUS_FAIL;
1578 }
1579 1515
1580 dev_dbg(rtsx_dev(chip), "mmc ddr tuning rx\n"); 1516 dev_dbg(rtsx_dev(chip), "mmc ddr tuning rx\n");
1581 1517
@@ -1603,15 +1539,13 @@ static int sd_sdr_tuning_tx_cmd(struct rtsx_chip *chip, u8 sample_point)
1603 int retval; 1539 int retval;
1604 1540
1605 retval = sd_change_phase(chip, sample_point, TUNE_TX); 1541 retval = sd_change_phase(chip, sample_point, TUNE_TX);
1606 if (retval != STATUS_SUCCESS) { 1542 if (retval != STATUS_SUCCESS)
1607 return STATUS_FAIL; 1543 return STATUS_FAIL;
1608 }
1609 1544
1610 retval = rtsx_write_register(chip, SD_CFG3, SD_RSP_80CLK_TIMEOUT_EN, 1545 retval = rtsx_write_register(chip, SD_CFG3, SD_RSP_80CLK_TIMEOUT_EN,
1611 SD_RSP_80CLK_TIMEOUT_EN); 1546 SD_RSP_80CLK_TIMEOUT_EN);
1612 if (retval) { 1547 if (retval)
1613 return retval; 1548 return retval;
1614 }
1615 1549
1616 retval = sd_send_cmd_get_rsp(chip, SEND_STATUS, sd_card->sd_addr, 1550 retval = sd_send_cmd_get_rsp(chip, SEND_STATUS, sd_card->sd_addr,
1617 SD_RSP_TYPE_R1, NULL, 0); 1551 SD_RSP_TYPE_R1, NULL, 0);
@@ -1625,9 +1559,8 @@ static int sd_sdr_tuning_tx_cmd(struct rtsx_chip *chip, u8 sample_point)
1625 1559
1626 retval = rtsx_write_register(chip, SD_CFG3, SD_RSP_80CLK_TIMEOUT_EN, 1560 retval = rtsx_write_register(chip, SD_CFG3, SD_RSP_80CLK_TIMEOUT_EN,
1627 0); 1561 0);
1628 if (retval) { 1562 if (retval)
1629 return retval; 1563 return retval;
1630 }
1631 1564
1632 return STATUS_SUCCESS; 1565 return STATUS_SUCCESS;
1633} 1566}
@@ -1639,9 +1572,8 @@ static int sd_ddr_tuning_tx_cmd(struct rtsx_chip *chip, u8 sample_point)
1639 u8 cmd[5], bus_width; 1572 u8 cmd[5], bus_width;
1640 1573
1641 retval = sd_change_phase(chip, sample_point, TUNE_TX); 1574 retval = sd_change_phase(chip, sample_point, TUNE_TX);
1642 if (retval != STATUS_SUCCESS) { 1575 if (retval != STATUS_SUCCESS)
1643 return STATUS_FAIL; 1576 return STATUS_FAIL;
1644 }
1645 1577
1646 if (CHK_SD(sd_card)) { 1578 if (CHK_SD(sd_card)) {
1647 bus_width = SD_BUS_WIDTH_4; 1579 bus_width = SD_BUS_WIDTH_4;
@@ -1655,15 +1587,13 @@ static int sd_ddr_tuning_tx_cmd(struct rtsx_chip *chip, u8 sample_point)
1655 } 1587 }
1656 1588
1657 retval = sd_wait_state_data_ready(chip, 0x08, 1, 1000); 1589 retval = sd_wait_state_data_ready(chip, 0x08, 1, 1000);
1658 if (retval != STATUS_SUCCESS) { 1590 if (retval != STATUS_SUCCESS)
1659 return STATUS_FAIL; 1591 return STATUS_FAIL;
1660 }
1661 1592
1662 retval = rtsx_write_register(chip, SD_CFG3, SD_RSP_80CLK_TIMEOUT_EN, 1593 retval = rtsx_write_register(chip, SD_CFG3, SD_RSP_80CLK_TIMEOUT_EN,
1663 SD_RSP_80CLK_TIMEOUT_EN); 1594 SD_RSP_80CLK_TIMEOUT_EN);
1664 if (retval) { 1595 if (retval)
1665 return retval; 1596 return retval;
1666 }
1667 1597
1668 cmd[0] = 0x40 | PROGRAM_CSD; 1598 cmd[0] = 0x40 | PROGRAM_CSD;
1669 cmd[1] = 0; 1599 cmd[1] = 0;
@@ -1681,9 +1611,8 @@ static int sd_ddr_tuning_tx_cmd(struct rtsx_chip *chip, u8 sample_point)
1681 1611
1682 retval = rtsx_write_register(chip, SD_CFG3, SD_RSP_80CLK_TIMEOUT_EN, 1612 retval = rtsx_write_register(chip, SD_CFG3, SD_RSP_80CLK_TIMEOUT_EN,
1683 0); 1613 0);
1684 if (retval) { 1614 if (retval)
1685 return retval; 1615 return retval;
1686 }
1687 1616
1688 sd_send_cmd_get_rsp(chip, SEND_STATUS, sd_card->sd_addr, SD_RSP_TYPE_R1, 1617 sd_send_cmd_get_rsp(chip, SEND_STATUS, sd_card->sd_addr, SD_RSP_TYPE_R1,
1689 NULL, 0); 1618 NULL, 0);
@@ -1826,11 +1755,10 @@ static int sd_tuning_rx(struct rtsx_chip *chip)
1826 tuning_cmd = sd_sdr_tuning_rx_cmd; 1755 tuning_cmd = sd_sdr_tuning_rx_cmd;
1827 1756
1828 } else { 1757 } else {
1829 if (CHK_MMC_DDR52(sd_card)) { 1758 if (CHK_MMC_DDR52(sd_card))
1830 tuning_cmd = mmc_ddr_tuning_rx_cmd; 1759 tuning_cmd = mmc_ddr_tuning_rx_cmd;
1831 } else { 1760 else
1832 return STATUS_FAIL; 1761 return STATUS_FAIL;
1833 }
1834 } 1762 }
1835 1763
1836 for (i = 0; i < 3; i++) { 1764 for (i = 0; i < 3; i++) {
@@ -1855,14 +1783,12 @@ static int sd_tuning_rx(struct rtsx_chip *chip)
1855 dev_dbg(rtsx_dev(chip), "RX phase_map = 0x%08x\n", phase_map); 1783 dev_dbg(rtsx_dev(chip), "RX phase_map = 0x%08x\n", phase_map);
1856 1784
1857 final_phase = sd_search_final_phase(chip, phase_map, TUNE_RX); 1785 final_phase = sd_search_final_phase(chip, phase_map, TUNE_RX);
1858 if (final_phase == 0xFF) { 1786 if (final_phase == 0xFF)
1859 return STATUS_FAIL; 1787 return STATUS_FAIL;
1860 }
1861 1788
1862 retval = sd_change_phase(chip, final_phase, TUNE_RX); 1789 retval = sd_change_phase(chip, final_phase, TUNE_RX);
1863 if (retval != STATUS_SUCCESS) { 1790 if (retval != STATUS_SUCCESS)
1864 return STATUS_FAIL; 1791 return STATUS_FAIL;
1865 }
1866 1792
1867 return STATUS_SUCCESS; 1793 return STATUS_SUCCESS;
1868} 1794}
@@ -1877,9 +1803,8 @@ static int sd_ddr_pre_tuning_tx(struct rtsx_chip *chip)
1877 1803
1878 retval = rtsx_write_register(chip, SD_CFG3, SD_RSP_80CLK_TIMEOUT_EN, 1804 retval = rtsx_write_register(chip, SD_CFG3, SD_RSP_80CLK_TIMEOUT_EN,
1879 SD_RSP_80CLK_TIMEOUT_EN); 1805 SD_RSP_80CLK_TIMEOUT_EN);
1880 if (retval) { 1806 if (retval)
1881 return retval; 1807 return retval;
1882 }
1883 1808
1884 phase_map = 0; 1809 phase_map = 0;
1885 for (i = MAX_PHASE; i >= 0; i--) { 1810 for (i = MAX_PHASE; i >= 0; i--) {
@@ -1904,22 +1829,19 @@ static int sd_ddr_pre_tuning_tx(struct rtsx_chip *chip)
1904 1829
1905 retval = rtsx_write_register(chip, SD_CFG3, SD_RSP_80CLK_TIMEOUT_EN, 1830 retval = rtsx_write_register(chip, SD_CFG3, SD_RSP_80CLK_TIMEOUT_EN,
1906 0); 1831 0);
1907 if (retval) { 1832 if (retval)
1908 return retval; 1833 return retval;
1909 }
1910 1834
1911 dev_dbg(rtsx_dev(chip), "DDR TX pre tune phase_map = 0x%08x\n", 1835 dev_dbg(rtsx_dev(chip), "DDR TX pre tune phase_map = 0x%08x\n",
1912 phase_map); 1836 phase_map);
1913 1837
1914 final_phase = sd_search_final_phase(chip, phase_map, TUNE_TX); 1838 final_phase = sd_search_final_phase(chip, phase_map, TUNE_TX);
1915 if (final_phase == 0xFF) { 1839 if (final_phase == 0xFF)
1916 return STATUS_FAIL; 1840 return STATUS_FAIL;
1917 }
1918 1841
1919 retval = sd_change_phase(chip, final_phase, TUNE_TX); 1842 retval = sd_change_phase(chip, final_phase, TUNE_TX);
1920 if (retval != STATUS_SUCCESS) { 1843 if (retval != STATUS_SUCCESS)
1921 return STATUS_FAIL; 1844 return STATUS_FAIL;
1922 }
1923 1845
1924 dev_dbg(rtsx_dev(chip), "DDR TX pre tune phase: %d\n", 1846 dev_dbg(rtsx_dev(chip), "DDR TX pre tune phase: %d\n",
1925 (int)final_phase); 1847 (int)final_phase);
@@ -1943,11 +1865,10 @@ static int sd_tuning_tx(struct rtsx_chip *chip)
1943 tuning_cmd = sd_sdr_tuning_tx_cmd; 1865 tuning_cmd = sd_sdr_tuning_tx_cmd;
1944 1866
1945 } else { 1867 } else {
1946 if (CHK_MMC_DDR52(sd_card)) { 1868 if (CHK_MMC_DDR52(sd_card))
1947 tuning_cmd = sd_ddr_tuning_tx_cmd; 1869 tuning_cmd = sd_ddr_tuning_tx_cmd;
1948 } else { 1870 else
1949 return STATUS_FAIL; 1871 return STATUS_FAIL;
1950 }
1951 } 1872 }
1952 1873
1953 for (i = 0; i < 3; i++) { 1874 for (i = 0; i < 3; i++) {
@@ -1974,14 +1895,12 @@ static int sd_tuning_tx(struct rtsx_chip *chip)
1974 dev_dbg(rtsx_dev(chip), "TX phase_map = 0x%08x\n", phase_map); 1895 dev_dbg(rtsx_dev(chip), "TX phase_map = 0x%08x\n", phase_map);
1975 1896
1976 final_phase = sd_search_final_phase(chip, phase_map, TUNE_TX); 1897 final_phase = sd_search_final_phase(chip, phase_map, TUNE_TX);
1977 if (final_phase == 0xFF) { 1898 if (final_phase == 0xFF)
1978 return STATUS_FAIL; 1899 return STATUS_FAIL;
1979 }
1980 1900
1981 retval = sd_change_phase(chip, final_phase, TUNE_TX); 1901 retval = sd_change_phase(chip, final_phase, TUNE_TX);
1982 if (retval != STATUS_SUCCESS) { 1902 if (retval != STATUS_SUCCESS)
1983 return STATUS_FAIL; 1903 return STATUS_FAIL;
1984 }
1985 1904
1986 return STATUS_SUCCESS; 1905 return STATUS_SUCCESS;
1987} 1906}
@@ -1991,14 +1910,12 @@ static int sd_sdr_tuning(struct rtsx_chip *chip)
1991 int retval; 1910 int retval;
1992 1911
1993 retval = sd_tuning_tx(chip); 1912 retval = sd_tuning_tx(chip);
1994 if (retval != STATUS_SUCCESS) { 1913 if (retval != STATUS_SUCCESS)
1995 return STATUS_FAIL; 1914 return STATUS_FAIL;
1996 }
1997 1915
1998 retval = sd_tuning_rx(chip); 1916 retval = sd_tuning_rx(chip);
1999 if (retval != STATUS_SUCCESS) { 1917 if (retval != STATUS_SUCCESS)
2000 return STATUS_FAIL; 1918 return STATUS_FAIL;
2001 }
2002 1919
2003 return STATUS_SUCCESS; 1920 return STATUS_SUCCESS;
2004} 1921}
@@ -2009,27 +1926,23 @@ static int sd_ddr_tuning(struct rtsx_chip *chip)
2009 1926
2010 if (!(chip->sd_ctl & SD_DDR_TX_PHASE_SET_BY_USER)) { 1927 if (!(chip->sd_ctl & SD_DDR_TX_PHASE_SET_BY_USER)) {
2011 retval = sd_ddr_pre_tuning_tx(chip); 1928 retval = sd_ddr_pre_tuning_tx(chip);
2012 if (retval != STATUS_SUCCESS) { 1929 if (retval != STATUS_SUCCESS)
2013 return STATUS_FAIL; 1930 return STATUS_FAIL;
2014 }
2015 } else { 1931 } else {
2016 retval = sd_change_phase(chip, (u8)chip->sd_ddr_tx_phase, 1932 retval = sd_change_phase(chip, (u8)chip->sd_ddr_tx_phase,
2017 TUNE_TX); 1933 TUNE_TX);
2018 if (retval != STATUS_SUCCESS) { 1934 if (retval != STATUS_SUCCESS)
2019 return STATUS_FAIL; 1935 return STATUS_FAIL;
2020 }
2021 } 1936 }
2022 1937
2023 retval = sd_tuning_rx(chip); 1938 retval = sd_tuning_rx(chip);
2024 if (retval != STATUS_SUCCESS) { 1939 if (retval != STATUS_SUCCESS)
2025 return STATUS_FAIL; 1940 return STATUS_FAIL;
2026 }
2027 1941
2028 if (!(chip->sd_ctl & SD_DDR_TX_PHASE_SET_BY_USER)) { 1942 if (!(chip->sd_ctl & SD_DDR_TX_PHASE_SET_BY_USER)) {
2029 retval = sd_tuning_tx(chip); 1943 retval = sd_tuning_tx(chip);
2030 if (retval != STATUS_SUCCESS) { 1944 if (retval != STATUS_SUCCESS)
2031 return STATUS_FAIL; 1945 return STATUS_FAIL;
2032 }
2033 } 1946 }
2034 1947
2035 return STATUS_SUCCESS; 1948 return STATUS_SUCCESS;
@@ -2041,27 +1954,23 @@ static int mmc_ddr_tuning(struct rtsx_chip *chip)
2041 1954
2042 if (!(chip->sd_ctl & MMC_DDR_TX_PHASE_SET_BY_USER)) { 1955 if (!(chip->sd_ctl & MMC_DDR_TX_PHASE_SET_BY_USER)) {
2043 retval = sd_ddr_pre_tuning_tx(chip); 1956 retval = sd_ddr_pre_tuning_tx(chip);
2044 if (retval != STATUS_SUCCESS) { 1957 if (retval != STATUS_SUCCESS)
2045 return STATUS_FAIL; 1958 return STATUS_FAIL;
2046 }
2047 } else { 1959 } else {
2048 retval = sd_change_phase(chip, (u8)chip->mmc_ddr_tx_phase, 1960 retval = sd_change_phase(chip, (u8)chip->mmc_ddr_tx_phase,
2049 TUNE_TX); 1961 TUNE_TX);
2050 if (retval != STATUS_SUCCESS) { 1962 if (retval != STATUS_SUCCESS)
2051 return STATUS_FAIL; 1963 return STATUS_FAIL;
2052 }
2053 } 1964 }
2054 1965
2055 retval = sd_tuning_rx(chip); 1966 retval = sd_tuning_rx(chip);
2056 if (retval != STATUS_SUCCESS) { 1967 if (retval != STATUS_SUCCESS)
2057 return STATUS_FAIL; 1968 return STATUS_FAIL;
2058 }
2059 1969
2060 if (!(chip->sd_ctl & MMC_DDR_TX_PHASE_SET_BY_USER)) { 1970 if (!(chip->sd_ctl & MMC_DDR_TX_PHASE_SET_BY_USER)) {
2061 retval = sd_tuning_tx(chip); 1971 retval = sd_tuning_tx(chip);
2062 if (retval != STATUS_SUCCESS) { 1972 if (retval != STATUS_SUCCESS)
2063 return STATUS_FAIL; 1973 return STATUS_FAIL;
2064 }
2065 } 1974 }
2066 1975
2067 return STATUS_SUCCESS; 1976 return STATUS_SUCCESS;
@@ -2074,14 +1983,12 @@ int sd_switch_clock(struct rtsx_chip *chip)
2074 int re_tuning = 0; 1983 int re_tuning = 0;
2075 1984
2076 retval = select_card(chip, SD_CARD); 1985 retval = select_card(chip, SD_CARD);
2077 if (retval != STATUS_SUCCESS) { 1986 if (retval != STATUS_SUCCESS)
2078 return STATUS_FAIL; 1987 return STATUS_FAIL;
2079 }
2080 1988
2081 retval = switch_clock(chip, sd_card->sd_clock); 1989 retval = switch_clock(chip, sd_card->sd_clock);
2082 if (retval != STATUS_SUCCESS) { 1990 if (retval != STATUS_SUCCESS)
2083 return STATUS_FAIL; 1991 return STATUS_FAIL;
2084 }
2085 1992
2086 if (re_tuning) { 1993 if (re_tuning) {
2087 if (CHK_SD(sd_card)) { 1994 if (CHK_SD(sd_card)) {
@@ -2094,9 +2001,8 @@ int sd_switch_clock(struct rtsx_chip *chip)
2094 retval = mmc_ddr_tuning(chip); 2001 retval = mmc_ddr_tuning(chip);
2095 } 2002 }
2096 2003
2097 if (retval != STATUS_SUCCESS) { 2004 if (retval != STATUS_SUCCESS)
2098 return STATUS_FAIL; 2005 return STATUS_FAIL;
2099 }
2100 } 2006 }
2101 2007
2102 return STATUS_SUCCESS; 2008 return STATUS_SUCCESS;
@@ -2126,25 +2032,21 @@ static int sd_prepare_reset(struct rtsx_chip *chip)
2126 chip->sd_io = 0; 2032 chip->sd_io = 0;
2127 2033
2128 retval = sd_set_init_para(chip); 2034 retval = sd_set_init_para(chip);
2129 if (retval != STATUS_SUCCESS) { 2035 if (retval != STATUS_SUCCESS)
2130 return retval; 2036 return retval;
2131 }
2132 2037
2133 retval = rtsx_write_register(chip, REG_SD_CFG1, 0xFF, 0x40); 2038 retval = rtsx_write_register(chip, REG_SD_CFG1, 0xFF, 0x40);
2134 if (retval) { 2039 if (retval)
2135 return retval; 2040 return retval;
2136 }
2137 2041
2138 retval = rtsx_write_register(chip, CARD_STOP, SD_STOP | SD_CLR_ERR, 2042 retval = rtsx_write_register(chip, CARD_STOP, SD_STOP | SD_CLR_ERR,
2139 SD_STOP | SD_CLR_ERR); 2043 SD_STOP | SD_CLR_ERR);
2140 if (retval) { 2044 if (retval)
2141 return retval; 2045 return retval;
2142 }
2143 2046
2144 retval = select_card(chip, SD_CARD); 2047 retval = select_card(chip, SD_CARD);
2145 if (retval != STATUS_SUCCESS) { 2048 if (retval != STATUS_SUCCESS)
2146 return STATUS_FAIL; 2049 return STATUS_FAIL;
2147 }
2148 2050
2149 return STATUS_SUCCESS; 2051 return STATUS_SUCCESS;
2150} 2052}
@@ -2157,60 +2059,50 @@ static int sd_pull_ctl_disable(struct rtsx_chip *chip)
2157 retval = rtsx_write_register(chip, CARD_PULL_CTL1, 0xFF, 2059 retval = rtsx_write_register(chip, CARD_PULL_CTL1, 0xFF,
2158 XD_D3_PD | SD_D7_PD | SD_CLK_PD | 2060 XD_D3_PD | SD_D7_PD | SD_CLK_PD |
2159 SD_D5_PD); 2061 SD_D5_PD);
2160 if (retval) { 2062 if (retval)
2161 return retval; 2063 return retval;
2162 }
2163 retval = rtsx_write_register(chip, CARD_PULL_CTL2, 0xFF, 2064 retval = rtsx_write_register(chip, CARD_PULL_CTL2, 0xFF,
2164 SD_D6_PD | SD_D0_PD | SD_D1_PD | 2065 SD_D6_PD | SD_D0_PD | SD_D1_PD |
2165 XD_D5_PD); 2066 XD_D5_PD);
2166 if (retval) { 2067 if (retval)
2167 return retval; 2068 return retval;
2168 }
2169 retval = rtsx_write_register(chip, CARD_PULL_CTL3, 0xFF, 2069 retval = rtsx_write_register(chip, CARD_PULL_CTL3, 0xFF,
2170 SD_D4_PD | XD_CE_PD | XD_CLE_PD | 2070 SD_D4_PD | XD_CE_PD | XD_CLE_PD |
2171 XD_CD_PU); 2071 XD_CD_PU);
2172 if (retval) { 2072 if (retval)
2173 return retval; 2073 return retval;
2174 }
2175 retval = rtsx_write_register(chip, CARD_PULL_CTL4, 0xFF, 2074 retval = rtsx_write_register(chip, CARD_PULL_CTL4, 0xFF,
2176 XD_RDY_PD | SD_D3_PD | SD_D2_PD | 2075 XD_RDY_PD | SD_D3_PD | SD_D2_PD |
2177 XD_ALE_PD); 2076 XD_ALE_PD);
2178 if (retval) { 2077 if (retval)
2179 return retval; 2078 return retval;
2180 }
2181 retval = rtsx_write_register(chip, CARD_PULL_CTL5, 0xFF, 2079 retval = rtsx_write_register(chip, CARD_PULL_CTL5, 0xFF,
2182 MS_INS_PU | SD_WP_PD | SD_CD_PU | 2080 MS_INS_PU | SD_WP_PD | SD_CD_PU |
2183 SD_CMD_PD); 2081 SD_CMD_PD);
2184 if (retval) { 2082 if (retval)
2185 return retval; 2083 return retval;
2186 }
2187 retval = rtsx_write_register(chip, CARD_PULL_CTL6, 0xFF, 2084 retval = rtsx_write_register(chip, CARD_PULL_CTL6, 0xFF,
2188 MS_D5_PD | MS_D4_PD); 2085 MS_D5_PD | MS_D4_PD);
2189 if (retval) { 2086 if (retval)
2190 return retval; 2087 return retval;
2191 }
2192 } else if (CHECK_PID(chip, 0x5288)) { 2088 } else if (CHECK_PID(chip, 0x5288)) {
2193 if (CHECK_BARO_PKG(chip, QFN)) { 2089 if (CHECK_BARO_PKG(chip, QFN)) {
2194 retval = rtsx_write_register(chip, CARD_PULL_CTL1, 2090 retval = rtsx_write_register(chip, CARD_PULL_CTL1,
2195 0xFF, 0x55); 2091 0xFF, 0x55);
2196 if (retval) { 2092 if (retval)
2197 return retval; 2093 return retval;
2198 }
2199 retval = rtsx_write_register(chip, CARD_PULL_CTL2, 2094 retval = rtsx_write_register(chip, CARD_PULL_CTL2,
2200 0xFF, 0x55); 2095 0xFF, 0x55);
2201 if (retval) { 2096 if (retval)
2202 return retval; 2097 return retval;
2203 }
2204 retval = rtsx_write_register(chip, CARD_PULL_CTL3, 2098 retval = rtsx_write_register(chip, CARD_PULL_CTL3,
2205 0xFF, 0x4B); 2099 0xFF, 0x4B);
2206 if (retval) { 2100 if (retval)
2207 return retval; 2101 return retval;
2208 }
2209 retval = rtsx_write_register(chip, CARD_PULL_CTL4, 2102 retval = rtsx_write_register(chip, CARD_PULL_CTL4,
2210 0xFF, 0x69); 2103 0xFF, 0x69);
2211 if (retval) { 2104 if (retval)
2212 return retval; 2105 return retval;
2213 }
2214 } 2106 }
2215 } 2107 }
2216 2108
@@ -2250,9 +2142,8 @@ int sd_pull_ctl_enable(struct rtsx_chip *chip)
2250 } 2142 }
2251 2143
2252 retval = rtsx_send_cmd(chip, SD_CARD, 100); 2144 retval = rtsx_send_cmd(chip, SD_CARD, 100);
2253 if (retval < 0) { 2145 if (retval < 0)
2254 return STATUS_FAIL; 2146 return STATUS_FAIL;
2255 }
2256 2147
2257 return STATUS_SUCCESS; 2148 return STATUS_SUCCESS;
2258} 2149}
@@ -2262,36 +2153,31 @@ static int sd_init_power(struct rtsx_chip *chip)
2262 int retval; 2153 int retval;
2263 2154
2264 retval = sd_power_off_card3v3(chip); 2155 retval = sd_power_off_card3v3(chip);
2265 if (retval != STATUS_SUCCESS) { 2156 if (retval != STATUS_SUCCESS)
2266 return STATUS_FAIL; 2157 return STATUS_FAIL;
2267 }
2268 2158
2269 if (!chip->ft2_fast_mode) 2159 if (!chip->ft2_fast_mode)
2270 wait_timeout(250); 2160 wait_timeout(250);
2271 2161
2272 retval = enable_card_clock(chip, SD_CARD); 2162 retval = enable_card_clock(chip, SD_CARD);
2273 if (retval != STATUS_SUCCESS) { 2163 if (retval != STATUS_SUCCESS)
2274 return STATUS_FAIL; 2164 return STATUS_FAIL;
2275 }
2276 2165
2277 if (chip->asic_code) { 2166 if (chip->asic_code) {
2278 retval = sd_pull_ctl_enable(chip); 2167 retval = sd_pull_ctl_enable(chip);
2279 if (retval != STATUS_SUCCESS) { 2168 if (retval != STATUS_SUCCESS)
2280 return STATUS_FAIL; 2169 return STATUS_FAIL;
2281 }
2282 } else { 2170 } else {
2283 retval = rtsx_write_register(chip, FPGA_PULL_CTL, 2171 retval = rtsx_write_register(chip, FPGA_PULL_CTL,
2284 FPGA_SD_PULL_CTL_BIT | 0x20, 0); 2172 FPGA_SD_PULL_CTL_BIT | 0x20, 0);
2285 if (retval) { 2173 if (retval)
2286 return retval; 2174 return retval;
2287 }
2288 } 2175 }
2289 2176
2290 if (!chip->ft2_fast_mode) { 2177 if (!chip->ft2_fast_mode) {
2291 retval = card_power_on(chip, SD_CARD); 2178 retval = card_power_on(chip, SD_CARD);
2292 if (retval != STATUS_SUCCESS) { 2179 if (retval != STATUS_SUCCESS)
2293 return STATUS_FAIL; 2180 return STATUS_FAIL;
2294 }
2295 2181
2296 wait_timeout(260); 2182 wait_timeout(260);
2297 2183
@@ -2306,9 +2192,8 @@ static int sd_init_power(struct rtsx_chip *chip)
2306 2192
2307 retval = rtsx_write_register(chip, CARD_OE, SD_OUTPUT_EN, 2193 retval = rtsx_write_register(chip, CARD_OE, SD_OUTPUT_EN,
2308 SD_OUTPUT_EN); 2194 SD_OUTPUT_EN);
2309 if (retval) { 2195 if (retval)
2310 return retval; 2196 return retval;
2311 }
2312 2197
2313 return STATUS_SUCCESS; 2198 return STATUS_SUCCESS;
2314} 2199}
@@ -2318,14 +2203,12 @@ static int sd_dummy_clock(struct rtsx_chip *chip)
2318 int retval; 2203 int retval;
2319 2204
2320 retval = rtsx_write_register(chip, REG_SD_CFG3, 0x01, 0x01); 2205 retval = rtsx_write_register(chip, REG_SD_CFG3, 0x01, 0x01);
2321 if (retval) { 2206 if (retval)
2322 return retval; 2207 return retval;
2323 }
2324 wait_timeout(5); 2208 wait_timeout(5);
2325 retval = rtsx_write_register(chip, REG_SD_CFG3, 0x01, 0); 2209 retval = rtsx_write_register(chip, REG_SD_CFG3, 0x01, 0);
2326 if (retval) { 2210 if (retval)
2327 return retval; 2211 return retval;
2328 }
2329 2212
2330 return STATUS_SUCCESS; 2213 return STATUS_SUCCESS;
2331} 2214}
@@ -2373,9 +2256,8 @@ static int sd_check_wp_state(struct rtsx_chip *chip)
2373 2256
2374 retval = sd_send_cmd_get_rsp(chip, APP_CMD, sd_card->sd_addr, 2257 retval = sd_send_cmd_get_rsp(chip, APP_CMD, sd_card->sd_addr,
2375 SD_RSP_TYPE_R1, NULL, 0); 2258 SD_RSP_TYPE_R1, NULL, 0);
2376 if (retval != STATUS_SUCCESS) { 2259 if (retval != STATUS_SUCCESS)
2377 return STATUS_FAIL; 2260 return STATUS_FAIL;
2378 }
2379 2261
2380 cmd[0] = 0x40 | SD_STATUS; 2262 cmd[0] = 0x40 | SD_STATUS;
2381 cmd[1] = 0; 2263 cmd[1] = 0;
@@ -2689,9 +2571,8 @@ SD_UNLOCK_ENTRY:
2689 2571
2690 retval = rtsx_write_register(chip, SD30_DRIVE_SEL, 0x07, 2572 retval = rtsx_write_register(chip, SD30_DRIVE_SEL, 0x07,
2691 chip->sd30_drive_sel_1v8); 2573 chip->sd30_drive_sel_1v8);
2692 if (retval) { 2574 if (retval)
2693 return retval; 2575 return retval;
2694 }
2695 2576
2696 retval = sd_set_init_para(chip); 2577 retval = sd_set_init_para(chip);
2697 if (retval != STATUS_SUCCESS) 2578 if (retval != STATUS_SUCCESS)
@@ -2753,14 +2634,12 @@ SD_UNLOCK_ENTRY:
2753 if (sd_card->sd_lock_status & SD_UNLOCK_POW_ON) { 2634 if (sd_card->sd_lock_status & SD_UNLOCK_POW_ON) {
2754 retval = rtsx_write_register(chip, REG_SD_BLOCK_CNT_H, 0xFF, 2635 retval = rtsx_write_register(chip, REG_SD_BLOCK_CNT_H, 0xFF,
2755 0x02); 2636 0x02);
2756 if (retval) { 2637 if (retval)
2757 return retval; 2638 return retval;
2758 }
2759 retval = rtsx_write_register(chip, REG_SD_BLOCK_CNT_L, 0xFF, 2639 retval = rtsx_write_register(chip, REG_SD_BLOCK_CNT_L, 0xFF,
2760 0x00); 2640 0x00);
2761 if (retval) { 2641 if (retval)
2762 return retval; 2642 return retval;
2763 }
2764 } 2643 }
2765#endif 2644#endif
2766 2645
@@ -2780,9 +2659,8 @@ static int mmc_test_switch_bus(struct rtsx_chip *chip, u8 width)
2780 2659
2781 retval = sd_send_cmd_get_rsp(chip, BUSTEST_W, 0, SD_RSP_TYPE_R1, NULL, 2660 retval = sd_send_cmd_get_rsp(chip, BUSTEST_W, 0, SD_RSP_TYPE_R1, NULL,
2782 0); 2661 0);
2783 if (retval != STATUS_SUCCESS) { 2662 if (retval != STATUS_SUCCESS)
2784 return SWITCH_FAIL; 2663 return SWITCH_FAIL;
2785 }
2786 2664
2787 if (width == MMC_8BIT_BUS) { 2665 if (width == MMC_8BIT_BUS) {
2788 buf[0] = 0x55; 2666 buf[0] = 0x55;
@@ -2798,9 +2676,8 @@ static int mmc_test_switch_bus(struct rtsx_chip *chip, u8 width)
2798 } 2676 }
2799 2677
2800 retval = rtsx_write_register(chip, REG_SD_CFG3, 0x02, 0x02); 2678 retval = rtsx_write_register(chip, REG_SD_CFG3, 0x02, 0x02);
2801 if (retval != STATUS_SUCCESS) { 2679 if (retval != STATUS_SUCCESS)
2802 return SWITCH_ERR; 2680 return SWITCH_ERR;
2803 }
2804 2681
2805 retval = sd_write_data(chip, SD_TM_AUTO_WRITE_3, NULL, 0, byte_cnt, 1, 2682 retval = sd_write_data(chip, SD_TM_AUTO_WRITE_3, NULL, 0, byte_cnt, 1,
2806 bus_width, buf, len, 100); 2683 bus_width, buf, len, 100);
@@ -2811,9 +2688,8 @@ static int mmc_test_switch_bus(struct rtsx_chip *chip, u8 width)
2811 } 2688 }
2812 2689
2813 retval = rtsx_write_register(chip, REG_SD_CFG3, 0x02, 0); 2690 retval = rtsx_write_register(chip, REG_SD_CFG3, 0x02, 0);
2814 if (retval != STATUS_SUCCESS) { 2691 if (retval != STATUS_SUCCESS)
2815 return SWITCH_ERR; 2692 return SWITCH_ERR;
2816 }
2817 2693
2818 dev_dbg(rtsx_dev(chip), "SD/MMC CMD %d\n", BUSTEST_R); 2694 dev_dbg(rtsx_dev(chip), "SD/MMC CMD %d\n", BUSTEST_R);
2819 2695
@@ -2979,9 +2855,8 @@ static int mmc_switch_timing_bus(struct rtsx_chip *chip, bool switch_ddr)
2979 2855
2980 sd_choose_proper_clock(chip); 2856 sd_choose_proper_clock(chip);
2981 retval = switch_clock(chip, sd_card->sd_clock); 2857 retval = switch_clock(chip, sd_card->sd_clock);
2982 if (retval != STATUS_SUCCESS) { 2858 if (retval != STATUS_SUCCESS)
2983 return STATUS_FAIL; 2859 return STATUS_FAIL;
2984 }
2985 2860
2986 /* Test Bus Procedure */ 2861 /* Test Bus Procedure */
2987 retval = mmc_test_switch_bus(chip, MMC_8BIT_BUS); 2862 retval = mmc_test_switch_bus(chip, MMC_8BIT_BUS);
@@ -3028,18 +2903,16 @@ static int reset_mmc(struct rtsx_chip *chip)
3028 2903
3029switch_fail: 2904switch_fail:
3030 retval = sd_prepare_reset(chip); 2905 retval = sd_prepare_reset(chip);
3031 if (retval != STATUS_SUCCESS) { 2906 if (retval != STATUS_SUCCESS)
3032 return retval; 2907 return retval;
3033 }
3034 2908
3035 SET_MMC(sd_card); 2909 SET_MMC(sd_card);
3036 2910
3037RTY_MMC_RST: 2911RTY_MMC_RST:
3038 retval = sd_send_cmd_get_rsp(chip, GO_IDLE_STATE, 0, SD_RSP_TYPE_R0, 2912 retval = sd_send_cmd_get_rsp(chip, GO_IDLE_STATE, 0, SD_RSP_TYPE_R0,
3039 NULL, 0); 2913 NULL, 0);
3040 if (retval != STATUS_SUCCESS) { 2914 if (retval != STATUS_SUCCESS)
3041 return STATUS_FAIL; 2915 return STATUS_FAIL;
3042 }
3043 2916
3044 do { 2917 do {
3045 if (detect_card_cd(chip, SD_CARD) != STATUS_SUCCESS) { 2918 if (detect_card_cd(chip, SD_CARD) != STATUS_SUCCESS) {
@@ -3075,9 +2948,8 @@ RTY_MMC_RST:
3075 i++; 2948 i++;
3076 } while (!(rsp[1] & 0x80) && (i < 255)); 2949 } while (!(rsp[1] & 0x80) && (i < 255));
3077 2950
3078 if (i == 255) { 2951 if (i == 255)
3079 return STATUS_FAIL; 2952 return STATUS_FAIL;
3080 }
3081 2953
3082 if ((rsp[1] & 0x60) == 0x40) 2954 if ((rsp[1] & 0x60) == 0x40)
3083 SET_MMC_SECTOR_MODE(sd_card); 2955 SET_MMC_SECTOR_MODE(sd_card);
@@ -3086,47 +2958,40 @@ RTY_MMC_RST:
3086 2958
3087 retval = sd_send_cmd_get_rsp(chip, ALL_SEND_CID, 0, SD_RSP_TYPE_R2, 2959 retval = sd_send_cmd_get_rsp(chip, ALL_SEND_CID, 0, SD_RSP_TYPE_R2,
3088 NULL, 0); 2960 NULL, 0);
3089 if (retval != STATUS_SUCCESS) { 2961 if (retval != STATUS_SUCCESS)
3090 return STATUS_FAIL; 2962 return STATUS_FAIL;
3091 }
3092 2963
3093 sd_card->sd_addr = 0x00100000; 2964 sd_card->sd_addr = 0x00100000;
3094 retval = sd_send_cmd_get_rsp(chip, SET_RELATIVE_ADDR, sd_card->sd_addr, 2965 retval = sd_send_cmd_get_rsp(chip, SET_RELATIVE_ADDR, sd_card->sd_addr,
3095 SD_RSP_TYPE_R6, rsp, 5); 2966 SD_RSP_TYPE_R6, rsp, 5);
3096 if (retval != STATUS_SUCCESS) { 2967 if (retval != STATUS_SUCCESS)
3097 return STATUS_FAIL; 2968 return STATUS_FAIL;
3098 }
3099 2969
3100 retval = sd_check_csd(chip, 1); 2970 retval = sd_check_csd(chip, 1);
3101 if (retval != STATUS_SUCCESS) { 2971 if (retval != STATUS_SUCCESS)
3102 return STATUS_FAIL; 2972 return STATUS_FAIL;
3103 }
3104 2973
3105 spec_ver = (sd_card->raw_csd[0] & 0x3C) >> 2; 2974 spec_ver = (sd_card->raw_csd[0] & 0x3C) >> 2;
3106 2975
3107 retval = sd_select_card(chip, 1); 2976 retval = sd_select_card(chip, 1);
3108 if (retval != STATUS_SUCCESS) { 2977 if (retval != STATUS_SUCCESS)
3109 return STATUS_FAIL; 2978 return STATUS_FAIL;
3110 }
3111 2979
3112 retval = sd_send_cmd_get_rsp(chip, SET_BLOCKLEN, 0x200, SD_RSP_TYPE_R1, 2980 retval = sd_send_cmd_get_rsp(chip, SET_BLOCKLEN, 0x200, SD_RSP_TYPE_R1,
3113 NULL, 0); 2981 NULL, 0);
3114 if (retval != STATUS_SUCCESS) { 2982 if (retval != STATUS_SUCCESS)
3115 return STATUS_FAIL; 2983 return STATUS_FAIL;
3116 }
3117 2984
3118#ifdef SUPPORT_SD_LOCK 2985#ifdef SUPPORT_SD_LOCK
3119MMC_UNLOCK_ENTRY: 2986MMC_UNLOCK_ENTRY:
3120 retval = sd_update_lock_status(chip); 2987 retval = sd_update_lock_status(chip);
3121 if (retval != STATUS_SUCCESS) { 2988 if (retval != STATUS_SUCCESS)
3122 return STATUS_FAIL; 2989 return STATUS_FAIL;
3123 }
3124#endif 2990#endif
3125 2991
3126 retval = sd_set_clock_divider(chip, SD_CLK_DIVIDE_0); 2992 retval = sd_set_clock_divider(chip, SD_CLK_DIVIDE_0);
3127 if (retval != STATUS_SUCCESS) { 2993 if (retval != STATUS_SUCCESS)
3128 return STATUS_FAIL; 2994 return STATUS_FAIL;
3129 }
3130 2995
3131 chip->card_bus_width[chip->card2lun[SD_CARD]] = 1; 2996 chip->card_bus_width[chip->card2lun[SD_CARD]] = 1;
3132 2997
@@ -3136,30 +3001,26 @@ MMC_UNLOCK_ENTRY:
3136 retval = mmc_switch_timing_bus(chip, switch_ddr); 3001 retval = mmc_switch_timing_bus(chip, switch_ddr);
3137 if (retval != STATUS_SUCCESS) { 3002 if (retval != STATUS_SUCCESS) {
3138 retval = sd_init_power(chip); 3003 retval = sd_init_power(chip);
3139 if (retval != STATUS_SUCCESS) { 3004 if (retval != STATUS_SUCCESS)
3140 return STATUS_FAIL; 3005 return STATUS_FAIL;
3141 }
3142 sd_card->mmc_dont_switch_bus = 1; 3006 sd_card->mmc_dont_switch_bus = 1;
3143 goto switch_fail; 3007 goto switch_fail;
3144 } 3008 }
3145 } 3009 }
3146 3010
3147 if (CHK_MMC_SECTOR_MODE(sd_card) && (sd_card->capacity == 0)) { 3011 if (CHK_MMC_SECTOR_MODE(sd_card) && (sd_card->capacity == 0))
3148 return STATUS_FAIL; 3012 return STATUS_FAIL;
3149 }
3150 3013
3151 if (switch_ddr && CHK_MMC_DDR52(sd_card)) { 3014 if (switch_ddr && CHK_MMC_DDR52(sd_card)) {
3152 retval = sd_set_init_para(chip); 3015 retval = sd_set_init_para(chip);
3153 if (retval != STATUS_SUCCESS) { 3016 if (retval != STATUS_SUCCESS)
3154 return STATUS_FAIL; 3017 return STATUS_FAIL;
3155 }
3156 3018
3157 retval = mmc_ddr_tuning(chip); 3019 retval = mmc_ddr_tuning(chip);
3158 if (retval != STATUS_SUCCESS) { 3020 if (retval != STATUS_SUCCESS) {
3159 retval = sd_init_power(chip); 3021 retval = sd_init_power(chip);
3160 if (retval != STATUS_SUCCESS) { 3022 if (retval != STATUS_SUCCESS)
3161 return STATUS_FAIL; 3023 return STATUS_FAIL;
3162 }
3163 3024
3164 switch_ddr = false; 3025 switch_ddr = false;
3165 goto switch_fail; 3026 goto switch_fail;
@@ -3170,9 +3031,8 @@ MMC_UNLOCK_ENTRY:
3170 retval = sd_read_lba0(chip); 3031 retval = sd_read_lba0(chip);
3171 if (retval != STATUS_SUCCESS) { 3032 if (retval != STATUS_SUCCESS) {
3172 retval = sd_init_power(chip); 3033 retval = sd_init_power(chip);
3173 if (retval != STATUS_SUCCESS) { 3034 if (retval != STATUS_SUCCESS)
3174 return STATUS_FAIL; 3035 return STATUS_FAIL;
3175 }
3176 3036
3177 switch_ddr = false; 3037 switch_ddr = false;
3178 goto switch_fail; 3038 goto switch_fail;
@@ -3185,14 +3045,12 @@ MMC_UNLOCK_ENTRY:
3185 if (sd_card->sd_lock_status & SD_UNLOCK_POW_ON) { 3045 if (sd_card->sd_lock_status & SD_UNLOCK_POW_ON) {
3186 retval = rtsx_write_register(chip, REG_SD_BLOCK_CNT_H, 0xFF, 3046 retval = rtsx_write_register(chip, REG_SD_BLOCK_CNT_H, 0xFF,
3187 0x02); 3047 0x02);
3188 if (retval) { 3048 if (retval)
3189 return retval; 3049 return retval;
3190 }
3191 retval = rtsx_write_register(chip, REG_SD_BLOCK_CNT_L, 0xFF, 3050 retval = rtsx_write_register(chip, REG_SD_BLOCK_CNT_L, 0xFF,
3192 0x00); 3051 0x00);
3193 if (retval) { 3052 if (retval)
3194 return retval; 3053 return retval;
3195 }
3196 } 3054 }
3197#endif 3055#endif
3198 3056
@@ -3214,88 +3072,74 @@ int reset_sd_card(struct rtsx_chip *chip)
3214 chip->capacity[chip->card2lun[SD_CARD]] = 0; 3072 chip->capacity[chip->card2lun[SD_CARD]] = 0;
3215 3073
3216 retval = enable_card_clock(chip, SD_CARD); 3074 retval = enable_card_clock(chip, SD_CARD);
3217 if (retval != STATUS_SUCCESS) { 3075 if (retval != STATUS_SUCCESS)
3218 return STATUS_FAIL; 3076 return STATUS_FAIL;
3219 }
3220 3077
3221 if (chip->ignore_sd && CHK_SDIO_EXIST(chip) && 3078 if (chip->ignore_sd && CHK_SDIO_EXIST(chip) &&
3222 !CHK_SDIO_IGNORED(chip)) { 3079 !CHK_SDIO_IGNORED(chip)) {
3223 if (chip->asic_code) { 3080 if (chip->asic_code) {
3224 retval = sd_pull_ctl_enable(chip); 3081 retval = sd_pull_ctl_enable(chip);
3225 if (retval != STATUS_SUCCESS) { 3082 if (retval != STATUS_SUCCESS)
3226 return STATUS_FAIL; 3083 return STATUS_FAIL;
3227 }
3228 } else { 3084 } else {
3229 retval = rtsx_write_register(chip, FPGA_PULL_CTL, 3085 retval = rtsx_write_register(chip, FPGA_PULL_CTL,
3230 FPGA_SD_PULL_CTL_BIT | 3086 FPGA_SD_PULL_CTL_BIT |
3231 0x20, 0); 3087 0x20, 0);
3232 if (retval != STATUS_SUCCESS) { 3088 if (retval != STATUS_SUCCESS)
3233 return STATUS_FAIL; 3089 return STATUS_FAIL;
3234 }
3235 } 3090 }
3236 retval = card_share_mode(chip, SD_CARD); 3091 retval = card_share_mode(chip, SD_CARD);
3237 if (retval != STATUS_SUCCESS) { 3092 if (retval != STATUS_SUCCESS)
3238 return STATUS_FAIL; 3093 return STATUS_FAIL;
3239 }
3240 3094
3241 chip->sd_io = 1; 3095 chip->sd_io = 1;
3242 return STATUS_FAIL; 3096 return STATUS_FAIL;
3243 } 3097 }
3244 3098
3245 retval = sd_init_power(chip); 3099 retval = sd_init_power(chip);
3246 if (retval != STATUS_SUCCESS) { 3100 if (retval != STATUS_SUCCESS)
3247 return STATUS_FAIL; 3101 return STATUS_FAIL;
3248 }
3249 3102
3250 if (chip->sd_ctl & RESET_MMC_FIRST) { 3103 if (chip->sd_ctl & RESET_MMC_FIRST) {
3251 retval = reset_mmc(chip); 3104 retval = reset_mmc(chip);
3252 if (retval != STATUS_SUCCESS) { 3105 if (retval != STATUS_SUCCESS) {
3253 if (sd_check_err_code(chip, SD_NO_CARD)) { 3106 if (sd_check_err_code(chip, SD_NO_CARD))
3254 return STATUS_FAIL; 3107 return STATUS_FAIL;
3255 }
3256 3108
3257 retval = reset_sd(chip); 3109 retval = reset_sd(chip);
3258 if (retval != STATUS_SUCCESS) { 3110 if (retval != STATUS_SUCCESS)
3259 return STATUS_FAIL; 3111 return STATUS_FAIL;
3260 }
3261 } 3112 }
3262 } else { 3113 } else {
3263 retval = reset_sd(chip); 3114 retval = reset_sd(chip);
3264 if (retval != STATUS_SUCCESS) { 3115 if (retval != STATUS_SUCCESS) {
3265 if (sd_check_err_code(chip, SD_NO_CARD)) { 3116 if (sd_check_err_code(chip, SD_NO_CARD))
3266 return STATUS_FAIL; 3117 return STATUS_FAIL;
3267 }
3268 3118
3269 if (chip->sd_io) { 3119 if (chip->sd_io)
3270 return STATUS_FAIL; 3120 return STATUS_FAIL;
3271 }
3272 retval = reset_mmc(chip); 3121 retval = reset_mmc(chip);
3273 if (retval != STATUS_SUCCESS) { 3122 if (retval != STATUS_SUCCESS)
3274 return STATUS_FAIL; 3123 return STATUS_FAIL;
3275 }
3276 } 3124 }
3277 } 3125 }
3278 3126
3279 retval = sd_set_clock_divider(chip, SD_CLK_DIVIDE_0); 3127 retval = sd_set_clock_divider(chip, SD_CLK_DIVIDE_0);
3280 if (retval != STATUS_SUCCESS) { 3128 if (retval != STATUS_SUCCESS)
3281 return STATUS_FAIL; 3129 return STATUS_FAIL;
3282 }
3283 3130
3284 retval = rtsx_write_register(chip, REG_SD_BYTE_CNT_L, 0xFF, 0); 3131 retval = rtsx_write_register(chip, REG_SD_BYTE_CNT_L, 0xFF, 0);
3285 if (retval) { 3132 if (retval)
3286 return retval; 3133 return retval;
3287 }
3288 retval = rtsx_write_register(chip, REG_SD_BYTE_CNT_H, 0xFF, 2); 3134 retval = rtsx_write_register(chip, REG_SD_BYTE_CNT_H, 0xFF, 2);
3289 if (retval) { 3135 if (retval)
3290 return retval; 3136 return retval;
3291 }
3292 3137
3293 chip->capacity[chip->card2lun[SD_CARD]] = sd_card->capacity; 3138 chip->capacity[chip->card2lun[SD_CARD]] = sd_card->capacity;
3294 3139
3295 retval = sd_set_init_para(chip); 3140 retval = sd_set_init_para(chip);
3296 if (retval != STATUS_SUCCESS) { 3141 if (retval != STATUS_SUCCESS)
3297 return STATUS_FAIL; 3142 return STATUS_FAIL;
3298 }
3299 3143
3300 dev_dbg(rtsx_dev(chip), "sd_card->sd_type = 0x%x\n", sd_card->sd_type); 3144 dev_dbg(rtsx_dev(chip), "sd_card->sd_type = 0x%x\n", sd_card->sd_type);
3301 3145
@@ -3321,40 +3165,33 @@ static int reset_mmc_only(struct rtsx_chip *chip)
3321 chip->capacity[chip->card2lun[SD_CARD]] = sd_card->capacity = 0; 3165 chip->capacity[chip->card2lun[SD_CARD]] = sd_card->capacity = 0;
3322 3166
3323 retval = enable_card_clock(chip, SD_CARD); 3167 retval = enable_card_clock(chip, SD_CARD);
3324 if (retval != STATUS_SUCCESS) { 3168 if (retval != STATUS_SUCCESS)
3325 return STATUS_FAIL; 3169 return STATUS_FAIL;
3326 }
3327 3170
3328 retval = sd_init_power(chip); 3171 retval = sd_init_power(chip);
3329 if (retval != STATUS_SUCCESS) { 3172 if (retval != STATUS_SUCCESS)
3330 return STATUS_FAIL; 3173 return STATUS_FAIL;
3331 }
3332 3174
3333 retval = reset_mmc(chip); 3175 retval = reset_mmc(chip);
3334 if (retval != STATUS_SUCCESS) { 3176 if (retval != STATUS_SUCCESS)
3335 return STATUS_FAIL; 3177 return STATUS_FAIL;
3336 }
3337 3178
3338 retval = sd_set_clock_divider(chip, SD_CLK_DIVIDE_0); 3179 retval = sd_set_clock_divider(chip, SD_CLK_DIVIDE_0);
3339 if (retval != STATUS_SUCCESS) { 3180 if (retval != STATUS_SUCCESS)
3340 return STATUS_FAIL; 3181 return STATUS_FAIL;
3341 }
3342 3182
3343 retval = rtsx_write_register(chip, REG_SD_BYTE_CNT_L, 0xFF, 0); 3183 retval = rtsx_write_register(chip, REG_SD_BYTE_CNT_L, 0xFF, 0);
3344 if (retval) { 3184 if (retval)
3345 return retval; 3185 return retval;
3346 }
3347 retval = rtsx_write_register(chip, REG_SD_BYTE_CNT_H, 0xFF, 2); 3186 retval = rtsx_write_register(chip, REG_SD_BYTE_CNT_H, 0xFF, 2);
3348 if (retval) { 3187 if (retval)
3349 return retval; 3188 return retval;
3350 }
3351 3189
3352 chip->capacity[chip->card2lun[SD_CARD]] = sd_card->capacity; 3190 chip->capacity[chip->card2lun[SD_CARD]] = sd_card->capacity;
3353 3191
3354 retval = sd_set_init_para(chip); 3192 retval = sd_set_init_para(chip);
3355 if (retval != STATUS_SUCCESS) { 3193 if (retval != STATUS_SUCCESS)
3356 return STATUS_FAIL; 3194 return STATUS_FAIL;
3357 }
3358 3195
3359 dev_dbg(rtsx_dev(chip), "In %s, sd_card->sd_type = 0x%x\n", 3196 dev_dbg(rtsx_dev(chip), "In %s, sd_card->sd_type = 0x%x\n",
3360 __func__, sd_card->sd_type); 3197 __func__, sd_card->sd_type);
@@ -3380,9 +3217,8 @@ static int wait_data_buf_ready(struct rtsx_chip *chip)
3380 retval = sd_send_cmd_get_rsp(chip, SEND_STATUS, 3217 retval = sd_send_cmd_get_rsp(chip, SEND_STATUS,
3381 sd_card->sd_addr, SD_RSP_TYPE_R1, 3218 sd_card->sd_addr, SD_RSP_TYPE_R1,
3382 NULL, 0); 3219 NULL, 0);
3383 if (retval != STATUS_SUCCESS) { 3220 if (retval != STATUS_SUCCESS)
3384 return STATUS_FAIL; 3221 return STATUS_FAIL;
3385 }
3386 3222
3387 if (sd_card->sd_data_buf_ready) { 3223 if (sd_card->sd_data_buf_ready) {
3388 return sd_send_cmd_get_rsp(chip, SEND_STATUS, 3224 return sd_send_cmd_get_rsp(chip, SEND_STATUS,
@@ -3460,9 +3296,8 @@ static inline int sd_auto_tune_clock(struct rtsx_chip *chip)
3460 } 3296 }
3461 3297
3462 retval = sd_switch_clock(chip); 3298 retval = sd_switch_clock(chip);
3463 if (retval != STATUS_SUCCESS) { 3299 if (retval != STATUS_SUCCESS)
3464 return STATUS_FAIL; 3300 return STATUS_FAIL;
3465 }
3466 3301
3467 return STATUS_SUCCESS; 3302 return STATUS_SUCCESS;
3468} 3303}
@@ -3819,9 +3654,8 @@ RTY_SEND_CMD:
3819 3654
3820 if (rsp_type & SD_WAIT_BUSY_END) { 3655 if (rsp_type & SD_WAIT_BUSY_END) {
3821 retval = sd_check_data0_status(chip); 3656 retval = sd_check_data0_status(chip);
3822 if (retval != STATUS_SUCCESS) { 3657 if (retval != STATUS_SUCCESS)
3823 return retval; 3658 return retval;
3824 }
3825 } else { 3659 } else {
3826 sd_set_err_code(chip, SD_TO_ERR); 3660 sd_set_err_code(chip, SD_TO_ERR);
3827 } 3661 }
@@ -3859,9 +3693,8 @@ RTY_SEND_CMD:
3859 if ((cmd_idx == SELECT_CARD) || (cmd_idx == APP_CMD) || 3693 if ((cmd_idx == SELECT_CARD) || (cmd_idx == APP_CMD) ||
3860 (cmd_idx == SEND_STATUS) || (cmd_idx == STOP_TRANSMISSION)) { 3694 (cmd_idx == SEND_STATUS) || (cmd_idx == STOP_TRANSMISSION)) {
3861 if ((cmd_idx != STOP_TRANSMISSION) && !special_check) { 3695 if ((cmd_idx != STOP_TRANSMISSION) && !special_check) {
3862 if (ptr[1] & 0x80) { 3696 if (ptr[1] & 0x80)
3863 return STATUS_FAIL; 3697 return STATUS_FAIL;
3864 }
3865 } 3698 }
3866#ifdef SUPPORT_SD_LOCK 3699#ifdef SUPPORT_SD_LOCK
3867 if (ptr[1] & 0x7D) { 3700 if (ptr[1] & 0x7D) {
@@ -3870,15 +3703,13 @@ RTY_SEND_CMD:
3870#endif 3703#endif
3871 return STATUS_FAIL; 3704 return STATUS_FAIL;
3872 } 3705 }
3873 if (ptr[2] & 0xF8) { 3706 if (ptr[2] & 0xF8)
3874 return STATUS_FAIL; 3707 return STATUS_FAIL;
3875 }
3876 3708
3877 if (cmd_idx == SELECT_CARD) { 3709 if (cmd_idx == SELECT_CARD) {
3878 if (rsp_type == SD_RSP_TYPE_R2) { 3710 if (rsp_type == SD_RSP_TYPE_R2) {
3879 if ((ptr[3] & 0x1E) != 0x04) { 3711 if ((ptr[3] & 0x1E) != 0x04)
3880 return STATUS_FAIL; 3712 return STATUS_FAIL;
3881 }
3882 } 3713 }
3883 } 3714 }
3884 } 3715 }
@@ -3915,9 +3746,8 @@ int ext_sd_get_rsp(struct rtsx_chip *chip, int len, u8 *rsp, u8 rsp_type)
3915 rtsx_add_cmd(chip, READ_REG_CMD, REG_SD_CMD5, 0xFF, 0); 3746 rtsx_add_cmd(chip, READ_REG_CMD, REG_SD_CMD5, 0xFF, 0);
3916 3747
3917 retval = rtsx_send_cmd(chip, SD_CARD, 100); 3748 retval = rtsx_send_cmd(chip, SD_CARD, 100);
3918 if (retval != STATUS_SUCCESS) { 3749 if (retval != STATUS_SUCCESS)
3919 return STATUS_FAIL; 3750 return STATUS_FAIL;
3920 }
3921 3751
3922 if (rsp) { 3752 if (rsp) {
3923 int min_len = (rsp_len < len) ? rsp_len : len; 3753 int min_len = (rsp_len < len) ? rsp_len : len;
@@ -4057,9 +3887,8 @@ int sd_execute_no_data(struct scsi_cmnd *srb, struct rtsx_chip *chip)
4057 } 3887 }
4058 3888
4059 retval = sd_switch_clock(chip); 3889 retval = sd_switch_clock(chip);
4060 if (retval != STATUS_SUCCESS) { 3890 if (retval != STATUS_SUCCESS)
4061 return TRANSPORT_FAILED; 3891 return TRANSPORT_FAILED;
4062 }
4063 3892
4064 if (sd_card->pre_cmd_err) { 3893 if (sd_card->pre_cmd_err) {
4065 sd_card->pre_cmd_err = 0; 3894 sd_card->pre_cmd_err = 0;
@@ -4085,39 +3914,34 @@ int sd_execute_no_data(struct scsi_cmnd *srb, struct rtsx_chip *chip)
4085 sd_card->last_rsp_type = rsp_type; 3914 sd_card->last_rsp_type = rsp_type;
4086 3915
4087 retval = sd_switch_clock(chip); 3916 retval = sd_switch_clock(chip);
4088 if (retval != STATUS_SUCCESS) { 3917 if (retval != STATUS_SUCCESS)
4089 return TRANSPORT_FAILED; 3918 return TRANSPORT_FAILED;
4090 }
4091 3919
4092#ifdef SUPPORT_SD_LOCK 3920#ifdef SUPPORT_SD_LOCK
4093 if ((sd_card->sd_lock_status & SD_LOCK_1BIT_MODE) == 0) { 3921 if ((sd_card->sd_lock_status & SD_LOCK_1BIT_MODE) == 0) {
4094 if (CHK_MMC_8BIT(sd_card)) { 3922 if (CHK_MMC_8BIT(sd_card)) {
4095 retval = rtsx_write_register(chip, REG_SD_CFG1, 0x03, 3923 retval = rtsx_write_register(chip, REG_SD_CFG1, 0x03,
4096 SD_BUS_WIDTH_8); 3924 SD_BUS_WIDTH_8);
4097 if (retval != STATUS_SUCCESS) { 3925 if (retval != STATUS_SUCCESS)
4098 return TRANSPORT_FAILED; 3926 return TRANSPORT_FAILED;
4099 }
4100 3927
4101 } else if (CHK_SD(sd_card) || CHK_MMC_4BIT(sd_card)) { 3928 } else if (CHK_SD(sd_card) || CHK_MMC_4BIT(sd_card)) {
4102 retval = rtsx_write_register(chip, REG_SD_CFG1, 0x03, 3929 retval = rtsx_write_register(chip, REG_SD_CFG1, 0x03,
4103 SD_BUS_WIDTH_4); 3930 SD_BUS_WIDTH_4);
4104 if (retval != STATUS_SUCCESS) { 3931 if (retval != STATUS_SUCCESS)
4105 return TRANSPORT_FAILED; 3932 return TRANSPORT_FAILED;
4106 }
4107 } 3933 }
4108 } 3934 }
4109#else 3935#else
4110 retval = rtsx_write_register(chip, REG_SD_CFG1, 0x03, SD_BUS_WIDTH_4); 3936 retval = rtsx_write_register(chip, REG_SD_CFG1, 0x03, SD_BUS_WIDTH_4);
4111 if (retval != STATUS_SUCCESS) { 3937 if (retval != STATUS_SUCCESS)
4112 return TRANSPORT_FAILED; 3938 return TRANSPORT_FAILED;
4113 }
4114#endif 3939#endif
4115 3940
4116 if (standby) { 3941 if (standby) {
4117 retval = sd_select_card(chip, 0); 3942 retval = sd_select_card(chip, 0);
4118 if (retval != STATUS_SUCCESS) { 3943 if (retval != STATUS_SUCCESS)
4119 goto sd_execute_cmd_failed; 3944 goto sd_execute_cmd_failed;
4120 }
4121 } 3945 }
4122 3946
4123 if (acmd) { 3947 if (acmd) {
@@ -4125,29 +3949,25 @@ int sd_execute_no_data(struct scsi_cmnd *srb, struct rtsx_chip *chip)
4125 sd_card->sd_addr, 3949 sd_card->sd_addr,
4126 SD_RSP_TYPE_R1, NULL, 0, 3950 SD_RSP_TYPE_R1, NULL, 0,
4127 false); 3951 false);
4128 if (retval != STATUS_SUCCESS) { 3952 if (retval != STATUS_SUCCESS)
4129 goto sd_execute_cmd_failed; 3953 goto sd_execute_cmd_failed;
4130 }
4131 } 3954 }
4132 3955
4133 retval = ext_sd_send_cmd_get_rsp(chip, cmd_idx, arg, rsp_type, 3956 retval = ext_sd_send_cmd_get_rsp(chip, cmd_idx, arg, rsp_type,
4134 sd_card->rsp, rsp_len, false); 3957 sd_card->rsp, rsp_len, false);
4135 if (retval != STATUS_SUCCESS) { 3958 if (retval != STATUS_SUCCESS)
4136 goto sd_execute_cmd_failed; 3959 goto sd_execute_cmd_failed;
4137 }
4138 3960
4139 if (standby) { 3961 if (standby) {
4140 retval = sd_select_card(chip, 1); 3962 retval = sd_select_card(chip, 1);
4141 if (retval != STATUS_SUCCESS) { 3963 if (retval != STATUS_SUCCESS)
4142 goto sd_execute_cmd_failed; 3964 goto sd_execute_cmd_failed;
4143 }
4144 } 3965 }
4145 3966
4146#ifdef SUPPORT_SD_LOCK 3967#ifdef SUPPORT_SD_LOCK
4147 retval = sd_update_lock_status(chip); 3968 retval = sd_update_lock_status(chip);
4148 if (retval != STATUS_SUCCESS) { 3969 if (retval != STATUS_SUCCESS)
4149 goto sd_execute_cmd_failed; 3970 goto sd_execute_cmd_failed;
4150 }
4151#endif 3971#endif
4152 3972
4153 scsi_set_resid(srb, 0); 3973 scsi_set_resid(srb, 0);
@@ -4186,9 +4006,8 @@ int sd_execute_read_data(struct scsi_cmnd *srb, struct rtsx_chip *chip)
4186 } 4006 }
4187 4007
4188 retval = sd_switch_clock(chip); 4008 retval = sd_switch_clock(chip);
4189 if (retval != STATUS_SUCCESS) { 4009 if (retval != STATUS_SUCCESS)
4190 return TRANSPORT_FAILED; 4010 return TRANSPORT_FAILED;
4191 }
4192 4011
4193 cmd_idx = srb->cmnd[2] & 0x3F; 4012 cmd_idx = srb->cmnd[2] & 0x3F;
4194 if (srb->cmnd[1] & 0x04) 4013 if (srb->cmnd[1] & 0x04)
@@ -4211,9 +4030,8 @@ int sd_execute_read_data(struct scsi_cmnd *srb, struct rtsx_chip *chip)
4211 sd_card->last_rsp_type = rsp_type; 4030 sd_card->last_rsp_type = rsp_type;
4212 4031
4213 retval = sd_switch_clock(chip); 4032 retval = sd_switch_clock(chip);
4214 if (retval != STATUS_SUCCESS) { 4033 if (retval != STATUS_SUCCESS)
4215 return TRANSPORT_FAILED; 4034 return TRANSPORT_FAILED;
4216 }
4217 4035
4218#ifdef SUPPORT_SD_LOCK 4036#ifdef SUPPORT_SD_LOCK
4219 if ((sd_card->sd_lock_status & SD_LOCK_1BIT_MODE) == 0) { 4037 if ((sd_card->sd_lock_status & SD_LOCK_1BIT_MODE) == 0) {
@@ -4235,16 +4053,14 @@ int sd_execute_read_data(struct scsi_cmnd *srb, struct rtsx_chip *chip)
4235 retval = ext_sd_send_cmd_get_rsp(chip, SET_BLOCKLEN, data_len, 4053 retval = ext_sd_send_cmd_get_rsp(chip, SET_BLOCKLEN, data_len,
4236 SD_RSP_TYPE_R1, NULL, 0, 4054 SD_RSP_TYPE_R1, NULL, 0,
4237 false); 4055 false);
4238 if (retval != STATUS_SUCCESS) { 4056 if (retval != STATUS_SUCCESS)
4239 goto sd_execute_read_cmd_failed; 4057 goto sd_execute_read_cmd_failed;
4240 }
4241 } 4058 }
4242 4059
4243 if (standby) { 4060 if (standby) {
4244 retval = sd_select_card(chip, 0); 4061 retval = sd_select_card(chip, 0);
4245 if (retval != STATUS_SUCCESS) { 4062 if (retval != STATUS_SUCCESS)
4246 goto sd_execute_read_cmd_failed; 4063 goto sd_execute_read_cmd_failed;
4247 }
4248 } 4064 }
4249 4065
4250 if (acmd) { 4066 if (acmd) {
@@ -4252,9 +4068,8 @@ int sd_execute_read_data(struct scsi_cmnd *srb, struct rtsx_chip *chip)
4252 sd_card->sd_addr, 4068 sd_card->sd_addr,
4253 SD_RSP_TYPE_R1, NULL, 0, 4069 SD_RSP_TYPE_R1, NULL, 0,
4254 false); 4070 false);
4255 if (retval != STATUS_SUCCESS) { 4071 if (retval != STATUS_SUCCESS)
4256 goto sd_execute_read_cmd_failed; 4072 goto sd_execute_read_cmd_failed;
4257 }
4258 } 4073 }
4259 4074
4260 if (data_len <= 512) { 4075 if (data_len <= 512) {
@@ -4273,9 +4088,8 @@ int sd_execute_read_data(struct scsi_cmnd *srb, struct rtsx_chip *chip)
4273 cmd[4] = srb->cmnd[6]; 4088 cmd[4] = srb->cmnd[6];
4274 4089
4275 buf = kmalloc(data_len, GFP_KERNEL); 4090 buf = kmalloc(data_len, GFP_KERNEL);
4276 if (!buf) { 4091 if (!buf)
4277 return TRANSPORT_ERROR; 4092 return TRANSPORT_ERROR;
4278 }
4279 4093
4280 retval = sd_read_data(chip, SD_TM_NORMAL_READ, cmd, 5, byte_cnt, 4094 retval = sd_read_data(chip, SD_TM_NORMAL_READ, cmd, 5, byte_cnt,
4281 blk_cnt, bus_width, buf, data_len, 2000); 4095 blk_cnt, bus_width, buf, data_len, 2000);
@@ -4340,43 +4154,37 @@ int sd_execute_read_data(struct scsi_cmnd *srb, struct rtsx_chip *chip)
4340 } 4154 }
4341 4155
4342 retval = ext_sd_get_rsp(chip, rsp_len, sd_card->rsp, rsp_type); 4156 retval = ext_sd_get_rsp(chip, rsp_len, sd_card->rsp, rsp_type);
4343 if (retval != STATUS_SUCCESS) { 4157 if (retval != STATUS_SUCCESS)
4344 goto sd_execute_read_cmd_failed; 4158 goto sd_execute_read_cmd_failed;
4345 }
4346 4159
4347 if (standby) { 4160 if (standby) {
4348 retval = sd_select_card(chip, 1); 4161 retval = sd_select_card(chip, 1);
4349 if (retval != STATUS_SUCCESS) { 4162 if (retval != STATUS_SUCCESS)
4350 goto sd_execute_read_cmd_failed; 4163 goto sd_execute_read_cmd_failed;
4351 }
4352 } 4164 }
4353 4165
4354 if (send_cmd12) { 4166 if (send_cmd12) {
4355 retval = ext_sd_send_cmd_get_rsp(chip, STOP_TRANSMISSION, 0, 4167 retval = ext_sd_send_cmd_get_rsp(chip, STOP_TRANSMISSION, 0,
4356 SD_RSP_TYPE_R1b, NULL, 0, 4168 SD_RSP_TYPE_R1b, NULL, 0,
4357 false); 4169 false);
4358 if (retval != STATUS_SUCCESS) { 4170 if (retval != STATUS_SUCCESS)
4359 goto sd_execute_read_cmd_failed; 4171 goto sd_execute_read_cmd_failed;
4360 }
4361 } 4172 }
4362 4173
4363 if (data_len < 512) { 4174 if (data_len < 512) {
4364 retval = ext_sd_send_cmd_get_rsp(chip, SET_BLOCKLEN, 0x200, 4175 retval = ext_sd_send_cmd_get_rsp(chip, SET_BLOCKLEN, 0x200,
4365 SD_RSP_TYPE_R1, NULL, 0, 4176 SD_RSP_TYPE_R1, NULL, 0,
4366 false); 4177 false);
4367 if (retval != STATUS_SUCCESS) { 4178 if (retval != STATUS_SUCCESS)
4368 goto sd_execute_read_cmd_failed; 4179 goto sd_execute_read_cmd_failed;
4369 }
4370 4180
4371 retval = rtsx_write_register(chip, SD_BYTE_CNT_H, 0xFF, 0x02); 4181 retval = rtsx_write_register(chip, SD_BYTE_CNT_H, 0xFF, 0x02);
4372 if (retval != STATUS_SUCCESS) { 4182 if (retval != STATUS_SUCCESS)
4373 goto sd_execute_read_cmd_failed; 4183 goto sd_execute_read_cmd_failed;
4374 }
4375 4184
4376 retval = rtsx_write_register(chip, SD_BYTE_CNT_L, 0xFF, 0x00); 4185 retval = rtsx_write_register(chip, SD_BYTE_CNT_L, 0xFF, 0x00);
4377 if (retval != STATUS_SUCCESS) { 4186 if (retval != STATUS_SUCCESS)
4378 goto sd_execute_read_cmd_failed; 4187 goto sd_execute_read_cmd_failed;
4379 }
4380 } 4188 }
4381 4189
4382 if ((srb->cmnd[1] & 0x02) || (srb->cmnd[1] & 0x04)) 4190 if ((srb->cmnd[1] & 0x02) || (srb->cmnd[1] & 0x04))
@@ -4390,9 +4198,8 @@ int sd_execute_read_data(struct scsi_cmnd *srb, struct rtsx_chip *chip)
4390 if (retval == STATUS_SUCCESS) 4198 if (retval == STATUS_SUCCESS)
4391 break; 4199 break;
4392 } 4200 }
4393 if (retval != STATUS_SUCCESS) { 4201 if (retval != STATUS_SUCCESS)
4394 goto sd_execute_read_cmd_failed; 4202 goto sd_execute_read_cmd_failed;
4395 }
4396 4203
4397 scsi_set_resid(srb, 0); 4204 scsi_set_resid(srb, 0);
4398 return TRANSPORT_GOOD; 4205 return TRANSPORT_GOOD;
@@ -4438,9 +4245,8 @@ int sd_execute_write_data(struct scsi_cmnd *srb, struct rtsx_chip *chip)
4438 } 4245 }
4439 4246
4440 retval = sd_switch_clock(chip); 4247 retval = sd_switch_clock(chip);
4441 if (retval != STATUS_SUCCESS) { 4248 if (retval != STATUS_SUCCESS)
4442 return TRANSPORT_FAILED; 4249 return TRANSPORT_FAILED;
4443 }
4444 4250
4445 cmd_idx = srb->cmnd[2] & 0x3F; 4251 cmd_idx = srb->cmnd[2] & 0x3F;
4446 if (srb->cmnd[1] & 0x04) 4252 if (srb->cmnd[1] & 0x04)
@@ -4472,48 +4278,42 @@ int sd_execute_write_data(struct scsi_cmnd *srb, struct rtsx_chip *chip)
4472 sd_card->last_rsp_type = rsp_type; 4278 sd_card->last_rsp_type = rsp_type;
4473 4279
4474 retval = sd_switch_clock(chip); 4280 retval = sd_switch_clock(chip);
4475 if (retval != STATUS_SUCCESS) { 4281 if (retval != STATUS_SUCCESS)
4476 return TRANSPORT_FAILED; 4282 return TRANSPORT_FAILED;
4477 }
4478 4283
4479#ifdef SUPPORT_SD_LOCK 4284#ifdef SUPPORT_SD_LOCK
4480 if ((sd_card->sd_lock_status & SD_LOCK_1BIT_MODE) == 0) { 4285 if ((sd_card->sd_lock_status & SD_LOCK_1BIT_MODE) == 0) {
4481 if (CHK_MMC_8BIT(sd_card)) { 4286 if (CHK_MMC_8BIT(sd_card)) {
4482 retval = rtsx_write_register(chip, REG_SD_CFG1, 0x03, 4287 retval = rtsx_write_register(chip, REG_SD_CFG1, 0x03,
4483 SD_BUS_WIDTH_8); 4288 SD_BUS_WIDTH_8);
4484 if (retval != STATUS_SUCCESS) { 4289 if (retval != STATUS_SUCCESS)
4485 return TRANSPORT_FAILED; 4290 return TRANSPORT_FAILED;
4486 }
4487 4291
4488 } else if (CHK_SD(sd_card) || CHK_MMC_4BIT(sd_card)) { 4292 } else if (CHK_SD(sd_card) || CHK_MMC_4BIT(sd_card)) {
4489 retval = rtsx_write_register(chip, REG_SD_CFG1, 0x03, 4293 retval = rtsx_write_register(chip, REG_SD_CFG1, 0x03,
4490 SD_BUS_WIDTH_4); 4294 SD_BUS_WIDTH_4);
4491 if (retval != STATUS_SUCCESS) { 4295 if (retval != STATUS_SUCCESS)
4492 return TRANSPORT_FAILED; 4296 return TRANSPORT_FAILED;
4493 }
4494 } 4297 }
4495 } 4298 }
4496#else 4299#else
4497 retval = rtsx_write_register(chip, REG_SD_CFG1, 0x03, SD_BUS_WIDTH_4); 4300 retval = rtsx_write_register(chip, REG_SD_CFG1, 0x03, SD_BUS_WIDTH_4);
4498 if (retval != STATUS_SUCCESS) { 4301 if (retval != STATUS_SUCCESS)
4499 return TRANSPORT_FAILED; 4302 return TRANSPORT_FAILED;
4500 }
4501#endif 4303#endif
4502 4304
4503 if (data_len < 512) { 4305 if (data_len < 512) {
4504 retval = ext_sd_send_cmd_get_rsp(chip, SET_BLOCKLEN, data_len, 4306 retval = ext_sd_send_cmd_get_rsp(chip, SET_BLOCKLEN, data_len,
4505 SD_RSP_TYPE_R1, NULL, 0, 4307 SD_RSP_TYPE_R1, NULL, 0,
4506 false); 4308 false);
4507 if (retval != STATUS_SUCCESS) { 4309 if (retval != STATUS_SUCCESS)
4508 goto sd_execute_write_cmd_failed; 4310 goto sd_execute_write_cmd_failed;
4509 }
4510 } 4311 }
4511 4312
4512 if (standby) { 4313 if (standby) {
4513 retval = sd_select_card(chip, 0); 4314 retval = sd_select_card(chip, 0);
4514 if (retval != STATUS_SUCCESS) { 4315 if (retval != STATUS_SUCCESS)
4515 goto sd_execute_write_cmd_failed; 4316 goto sd_execute_write_cmd_failed;
4516 }
4517 } 4317 }
4518 4318
4519 if (acmd) { 4319 if (acmd) {
@@ -4521,25 +4321,22 @@ int sd_execute_write_data(struct scsi_cmnd *srb, struct rtsx_chip *chip)
4521 sd_card->sd_addr, 4321 sd_card->sd_addr,
4522 SD_RSP_TYPE_R1, NULL, 0, 4322 SD_RSP_TYPE_R1, NULL, 0,
4523 false); 4323 false);
4524 if (retval != STATUS_SUCCESS) { 4324 if (retval != STATUS_SUCCESS)
4525 goto sd_execute_write_cmd_failed; 4325 goto sd_execute_write_cmd_failed;
4526 }
4527 } 4326 }
4528 4327
4529 retval = ext_sd_send_cmd_get_rsp(chip, cmd_idx, arg, rsp_type, 4328 retval = ext_sd_send_cmd_get_rsp(chip, cmd_idx, arg, rsp_type,
4530 sd_card->rsp, rsp_len, false); 4329 sd_card->rsp, rsp_len, false);
4531 if (retval != STATUS_SUCCESS) { 4330 if (retval != STATUS_SUCCESS)
4532 goto sd_execute_write_cmd_failed; 4331 goto sd_execute_write_cmd_failed;
4533 }
4534 4332
4535 if (data_len <= 512) { 4333 if (data_len <= 512) {
4536 u16 i; 4334 u16 i;
4537 u8 *buf; 4335 u8 *buf;
4538 4336
4539 buf = kmalloc(data_len, GFP_KERNEL); 4337 buf = kmalloc(data_len, GFP_KERNEL);
4540 if (!buf) { 4338 if (!buf)
4541 return TRANSPORT_ERROR; 4339 return TRANSPORT_ERROR;
4542 }
4543 4340
4544 rtsx_stor_get_xfer_buf(buf, data_len, srb); 4341 rtsx_stor_get_xfer_buf(buf, data_len, srb);
4545 4342
@@ -4663,37 +4460,32 @@ int sd_execute_write_data(struct scsi_cmnd *srb, struct rtsx_chip *chip)
4663 4460
4664 if (standby) { 4461 if (standby) {
4665 retval = sd_select_card(chip, 1); 4462 retval = sd_select_card(chip, 1);
4666 if (retval != STATUS_SUCCESS) { 4463 if (retval != STATUS_SUCCESS)
4667 goto sd_execute_write_cmd_failed; 4464 goto sd_execute_write_cmd_failed;
4668 }
4669 } 4465 }
4670 4466
4671 if (send_cmd12) { 4467 if (send_cmd12) {
4672 retval = ext_sd_send_cmd_get_rsp(chip, STOP_TRANSMISSION, 0, 4468 retval = ext_sd_send_cmd_get_rsp(chip, STOP_TRANSMISSION, 0,
4673 SD_RSP_TYPE_R1b, NULL, 0, 4469 SD_RSP_TYPE_R1b, NULL, 0,
4674 false); 4470 false);
4675 if (retval != STATUS_SUCCESS) { 4471 if (retval != STATUS_SUCCESS)
4676 goto sd_execute_write_cmd_failed; 4472 goto sd_execute_write_cmd_failed;
4677 }
4678 } 4473 }
4679 4474
4680 if (data_len < 512) { 4475 if (data_len < 512) {
4681 retval = ext_sd_send_cmd_get_rsp(chip, SET_BLOCKLEN, 0x200, 4476 retval = ext_sd_send_cmd_get_rsp(chip, SET_BLOCKLEN, 0x200,
4682 SD_RSP_TYPE_R1, NULL, 0, 4477 SD_RSP_TYPE_R1, NULL, 0,
4683 false); 4478 false);
4684 if (retval != STATUS_SUCCESS) { 4479 if (retval != STATUS_SUCCESS)
4685 goto sd_execute_write_cmd_failed; 4480 goto sd_execute_write_cmd_failed;
4686 }
4687 4481
4688 retval = rtsx_write_register(chip, SD_BYTE_CNT_H, 0xFF, 0x02); 4482 retval = rtsx_write_register(chip, SD_BYTE_CNT_H, 0xFF, 0x02);
4689 if (retval != STATUS_SUCCESS) { 4483 if (retval != STATUS_SUCCESS)
4690 goto sd_execute_write_cmd_failed; 4484 goto sd_execute_write_cmd_failed;
4691 }
4692 4485
4693 retval = rtsx_write_register(chip, SD_BYTE_CNT_L, 0xFF, 0x00); 4486 retval = rtsx_write_register(chip, SD_BYTE_CNT_L, 0xFF, 0x00);
4694 if (retval != STATUS_SUCCESS) { 4487 if (retval != STATUS_SUCCESS)
4695 goto sd_execute_write_cmd_failed; 4488 goto sd_execute_write_cmd_failed;
4696 }
4697 } 4489 }
4698 4490
4699 if ((srb->cmnd[1] & 0x02) || (srb->cmnd[1] & 0x04)) 4491 if ((srb->cmnd[1] & 0x02) || (srb->cmnd[1] & 0x04))
@@ -4707,9 +4499,8 @@ int sd_execute_write_data(struct scsi_cmnd *srb, struct rtsx_chip *chip)
4707 if (retval == STATUS_SUCCESS) 4499 if (retval == STATUS_SUCCESS)
4708 break; 4500 break;
4709 } 4501 }
4710 if (retval != STATUS_SUCCESS) { 4502 if (retval != STATUS_SUCCESS)
4711 goto sd_execute_write_cmd_failed; 4503 goto sd_execute_write_cmd_failed;
4712 }
4713 4504
4714#ifdef SUPPORT_SD_LOCK 4505#ifdef SUPPORT_SD_LOCK
4715 if (cmd_idx == LOCK_UNLOCK) { 4506 if (cmd_idx == LOCK_UNLOCK) {
@@ -4888,36 +4679,31 @@ int sd_power_off_card3v3(struct rtsx_chip *chip)
4888 int retval; 4679 int retval;
4889 4680
4890 retval = disable_card_clock(chip, SD_CARD); 4681 retval = disable_card_clock(chip, SD_CARD);
4891 if (retval != STATUS_SUCCESS) { 4682 if (retval != STATUS_SUCCESS)
4892 return STATUS_FAIL; 4683 return STATUS_FAIL;
4893 }
4894 4684
4895 retval = rtsx_write_register(chip, CARD_OE, SD_OUTPUT_EN, 0); 4685 retval = rtsx_write_register(chip, CARD_OE, SD_OUTPUT_EN, 0);
4896 if (retval) { 4686 if (retval)
4897 return retval; 4687 return retval;
4898 }
4899 4688
4900 if (!chip->ft2_fast_mode) { 4689 if (!chip->ft2_fast_mode) {
4901 retval = card_power_off(chip, SD_CARD); 4690 retval = card_power_off(chip, SD_CARD);
4902 if (retval != STATUS_SUCCESS) { 4691 if (retval != STATUS_SUCCESS)
4903 return STATUS_FAIL; 4692 return STATUS_FAIL;
4904 }
4905 4693
4906 mdelay(50); 4694 mdelay(50);
4907 } 4695 }
4908 4696
4909 if (chip->asic_code) { 4697 if (chip->asic_code) {
4910 retval = sd_pull_ctl_disable(chip); 4698 retval = sd_pull_ctl_disable(chip);
4911 if (retval != STATUS_SUCCESS) { 4699 if (retval != STATUS_SUCCESS)
4912 return STATUS_FAIL; 4700 return STATUS_FAIL;
4913 }
4914 } else { 4701 } else {
4915 retval = rtsx_write_register(chip, FPGA_PULL_CTL, 4702 retval = rtsx_write_register(chip, FPGA_PULL_CTL,
4916 FPGA_SD_PULL_CTL_BIT | 0x20, 4703 FPGA_SD_PULL_CTL_BIT | 0x20,
4917 FPGA_SD_PULL_CTL_BIT); 4704 FPGA_SD_PULL_CTL_BIT);
4918 if (retval) { 4705 if (retval)
4919 return retval; 4706 return retval;
4920 }
4921 } 4707 }
4922 4708
4923 return STATUS_SUCCESS; 4709 return STATUS_SUCCESS;
@@ -4944,9 +4730,8 @@ int release_sd_card(struct rtsx_chip *chip)
4944 memset(sd_card->raw_scr, 0, 8); 4730 memset(sd_card->raw_scr, 0, 8);
4945 4731
4946 retval = sd_power_off_card3v3(chip); 4732 retval = sd_power_off_card3v3(chip);
4947 if (retval != STATUS_SUCCESS) { 4733 if (retval != STATUS_SUCCESS)
4948 return STATUS_FAIL; 4734 return STATUS_FAIL;
4949 }
4950 4735
4951 return STATUS_SUCCESS; 4736 return STATUS_SUCCESS;
4952} 4737}
diff --git a/drivers/staging/rts5208/spi.c b/drivers/staging/rts5208/spi.c
index 4675668ad977..110cb9093f30 100644
--- a/drivers/staging/rts5208/spi.c
+++ b/drivers/staging/rts5208/spi.c
@@ -41,14 +41,12 @@ static int spi_init(struct rtsx_chip *chip)
41 retval = rtsx_write_register(chip, SPI_CONTROL, 0xFF, 41 retval = rtsx_write_register(chip, SPI_CONTROL, 0xFF,
42 CS_POLARITY_LOW | DTO_MSB_FIRST 42 CS_POLARITY_LOW | DTO_MSB_FIRST
43 | SPI_MASTER | SPI_MODE0 | SPI_AUTO); 43 | SPI_MASTER | SPI_MODE0 | SPI_AUTO);
44 if (retval) { 44 if (retval)
45 return retval; 45 return retval;
46 }
47 retval = rtsx_write_register(chip, SPI_TCTL, EDO_TIMING_MASK, 46 retval = rtsx_write_register(chip, SPI_TCTL, EDO_TIMING_MASK,
48 SAMPLE_DELAY_HALF); 47 SAMPLE_DELAY_HALF);
49 if (retval) { 48 if (retval)
50 return retval; 49 return retval;
51 }
52 50
53 return STATUS_SUCCESS; 51 return STATUS_SUCCESS;
54} 52}
@@ -60,42 +58,35 @@ static int spi_set_init_para(struct rtsx_chip *chip)
60 58
61 retval = rtsx_write_register(chip, SPI_CLK_DIVIDER1, 0xFF, 59 retval = rtsx_write_register(chip, SPI_CLK_DIVIDER1, 0xFF,
62 (u8)(spi->clk_div >> 8)); 60 (u8)(spi->clk_div >> 8));
63 if (retval) { 61 if (retval)
64 return retval; 62 return retval;
65 }
66 retval = rtsx_write_register(chip, SPI_CLK_DIVIDER0, 0xFF, 63 retval = rtsx_write_register(chip, SPI_CLK_DIVIDER0, 0xFF,
67 (u8)(spi->clk_div)); 64 (u8)(spi->clk_div));
68 if (retval) { 65 if (retval)
69 return retval; 66 return retval;
70 }
71 67
72 retval = switch_clock(chip, spi->spi_clock); 68 retval = switch_clock(chip, spi->spi_clock);
73 if (retval != STATUS_SUCCESS) { 69 if (retval != STATUS_SUCCESS)
74 return STATUS_FAIL; 70 return STATUS_FAIL;
75 }
76 71
77 retval = select_card(chip, SPI_CARD); 72 retval = select_card(chip, SPI_CARD);
78 if (retval != STATUS_SUCCESS) { 73 if (retval != STATUS_SUCCESS)
79 return STATUS_FAIL; 74 return STATUS_FAIL;
80 }
81 75
82 retval = rtsx_write_register(chip, CARD_CLK_EN, SPI_CLK_EN, 76 retval = rtsx_write_register(chip, CARD_CLK_EN, SPI_CLK_EN,
83 SPI_CLK_EN); 77 SPI_CLK_EN);
84 if (retval) { 78 if (retval)
85 return retval; 79 return retval;
86 }
87 retval = rtsx_write_register(chip, CARD_OE, SPI_OUTPUT_EN, 80 retval = rtsx_write_register(chip, CARD_OE, SPI_OUTPUT_EN,
88 SPI_OUTPUT_EN); 81 SPI_OUTPUT_EN);
89 if (retval) { 82 if (retval)
90 return retval; 83 return retval;
91 }
92 84
93 wait_timeout(10); 85 wait_timeout(10);
94 86
95 retval = spi_init(chip); 87 retval = spi_init(chip);
96 if (retval != STATUS_SUCCESS) { 88 if (retval != STATUS_SUCCESS)
97 return STATUS_FAIL; 89 return STATUS_FAIL;
98 }
99 90
100 return STATUS_SUCCESS; 91 return STATUS_SUCCESS;
101} 92}
@@ -247,47 +238,39 @@ static int spi_init_eeprom(struct rtsx_chip *chip)
247 clk = CLK_30; 238 clk = CLK_30;
248 239
249 retval = rtsx_write_register(chip, SPI_CLK_DIVIDER1, 0xFF, 0x00); 240 retval = rtsx_write_register(chip, SPI_CLK_DIVIDER1, 0xFF, 0x00);
250 if (retval) { 241 if (retval)
251 return retval; 242 return retval;
252 }
253 retval = rtsx_write_register(chip, SPI_CLK_DIVIDER0, 0xFF, 0x27); 243 retval = rtsx_write_register(chip, SPI_CLK_DIVIDER0, 0xFF, 0x27);
254 if (retval) { 244 if (retval)
255 return retval; 245 return retval;
256 }
257 246
258 retval = switch_clock(chip, clk); 247 retval = switch_clock(chip, clk);
259 if (retval != STATUS_SUCCESS) { 248 if (retval != STATUS_SUCCESS)
260 return STATUS_FAIL; 249 return STATUS_FAIL;
261 }
262 250
263 retval = select_card(chip, SPI_CARD); 251 retval = select_card(chip, SPI_CARD);
264 if (retval != STATUS_SUCCESS) { 252 if (retval != STATUS_SUCCESS)
265 return STATUS_FAIL; 253 return STATUS_FAIL;
266 }
267 254
268 retval = rtsx_write_register(chip, CARD_CLK_EN, SPI_CLK_EN, 255 retval = rtsx_write_register(chip, CARD_CLK_EN, SPI_CLK_EN,
269 SPI_CLK_EN); 256 SPI_CLK_EN);
270 if (retval) { 257 if (retval)
271 return retval; 258 return retval;
272 }
273 retval = rtsx_write_register(chip, CARD_OE, SPI_OUTPUT_EN, 259 retval = rtsx_write_register(chip, CARD_OE, SPI_OUTPUT_EN,
274 SPI_OUTPUT_EN); 260 SPI_OUTPUT_EN);
275 if (retval) { 261 if (retval)
276 return retval; 262 return retval;
277 }
278 263
279 wait_timeout(10); 264 wait_timeout(10);
280 265
281 retval = rtsx_write_register(chip, SPI_CONTROL, 0xFF, 266 retval = rtsx_write_register(chip, SPI_CONTROL, 0xFF,
282 CS_POLARITY_HIGH | SPI_EEPROM_AUTO); 267 CS_POLARITY_HIGH | SPI_EEPROM_AUTO);
283 if (retval) { 268 if (retval)
284 return retval; 269 return retval;
285 }
286 retval = rtsx_write_register(chip, SPI_TCTL, EDO_TIMING_MASK, 270 retval = rtsx_write_register(chip, SPI_TCTL, EDO_TIMING_MASK,
287 SAMPLE_DELAY_HALF); 271 SAMPLE_DELAY_HALF);
288 if (retval) { 272 if (retval)
289 return retval; 273 return retval;
290 }
291 274
292 return STATUS_SUCCESS; 275 return STATUS_SUCCESS;
293} 276}
@@ -306,9 +289,8 @@ static int spi_eeprom_program_enable(struct rtsx_chip *chip)
306 SPI_TRANSFER0_END); 289 SPI_TRANSFER0_END);
307 290
308 retval = rtsx_send_cmd(chip, 0, 100); 291 retval = rtsx_send_cmd(chip, 0, 100);
309 if (retval < 0) { 292 if (retval < 0)
310 return STATUS_FAIL; 293 return STATUS_FAIL;
311 }
312 294
313 return STATUS_SUCCESS; 295 return STATUS_SUCCESS;
314} 296}
@@ -318,14 +300,12 @@ int spi_erase_eeprom_chip(struct rtsx_chip *chip)
318 int retval; 300 int retval;
319 301
320 retval = spi_init_eeprom(chip); 302 retval = spi_init_eeprom(chip);
321 if (retval != STATUS_SUCCESS) { 303 if (retval != STATUS_SUCCESS)
322 return STATUS_FAIL; 304 return STATUS_FAIL;
323 }
324 305
325 retval = spi_eeprom_program_enable(chip); 306 retval = spi_eeprom_program_enable(chip);
326 if (retval != STATUS_SUCCESS) { 307 if (retval != STATUS_SUCCESS)
327 return STATUS_FAIL; 308 return STATUS_FAIL;
328 }
329 309
330 rtsx_init_cmd(chip); 310 rtsx_init_cmd(chip);
331 311
@@ -339,14 +319,12 @@ int spi_erase_eeprom_chip(struct rtsx_chip *chip)
339 SPI_TRANSFER0_END); 319 SPI_TRANSFER0_END);
340 320
341 retval = rtsx_send_cmd(chip, 0, 100); 321 retval = rtsx_send_cmd(chip, 0, 100);
342 if (retval < 0) { 322 if (retval < 0)
343 return STATUS_FAIL; 323 return STATUS_FAIL;
344 }
345 324
346 retval = rtsx_write_register(chip, CARD_GPIO_DIR, 0x01, 0x01); 325 retval = rtsx_write_register(chip, CARD_GPIO_DIR, 0x01, 0x01);
347 if (retval) { 326 if (retval)
348 return retval; 327 return retval;
349 }
350 328
351 return STATUS_SUCCESS; 329 return STATUS_SUCCESS;
352} 330}
@@ -356,14 +334,12 @@ int spi_erase_eeprom_byte(struct rtsx_chip *chip, u16 addr)
356 int retval; 334 int retval;
357 335
358 retval = spi_init_eeprom(chip); 336 retval = spi_init_eeprom(chip);
359 if (retval != STATUS_SUCCESS) { 337 if (retval != STATUS_SUCCESS)
360 return STATUS_FAIL; 338 return STATUS_FAIL;
361 }
362 339
363 retval = spi_eeprom_program_enable(chip); 340 retval = spi_eeprom_program_enable(chip);
364 if (retval != STATUS_SUCCESS) { 341 if (retval != STATUS_SUCCESS)
365 return STATUS_FAIL; 342 return STATUS_FAIL;
366 }
367 343
368 rtsx_init_cmd(chip); 344 rtsx_init_cmd(chip);
369 345
@@ -379,14 +355,12 @@ int spi_erase_eeprom_byte(struct rtsx_chip *chip, u16 addr)
379 SPI_TRANSFER0_END); 355 SPI_TRANSFER0_END);
380 356
381 retval = rtsx_send_cmd(chip, 0, 100); 357 retval = rtsx_send_cmd(chip, 0, 100);
382 if (retval < 0) { 358 if (retval < 0)
383 return STATUS_FAIL; 359 return STATUS_FAIL;
384 }
385 360
386 retval = rtsx_write_register(chip, CARD_GPIO_DIR, 0x01, 0x01); 361 retval = rtsx_write_register(chip, CARD_GPIO_DIR, 0x01, 0x01);
387 if (retval) { 362 if (retval)
388 return retval; 363 return retval;
389 }
390 364
391 return STATUS_SUCCESS; 365 return STATUS_SUCCESS;
392} 366}
@@ -397,9 +371,8 @@ int spi_read_eeprom(struct rtsx_chip *chip, u16 addr, u8 *val)
397 u8 data; 371 u8 data;
398 372
399 retval = spi_init_eeprom(chip); 373 retval = spi_init_eeprom(chip);
400 if (retval != STATUS_SUCCESS) { 374 if (retval != STATUS_SUCCESS)
401 return STATUS_FAIL; 375 return STATUS_FAIL;
402 }
403 376
404 rtsx_init_cmd(chip); 377 rtsx_init_cmd(chip);
405 378
@@ -416,23 +389,20 @@ int spi_read_eeprom(struct rtsx_chip *chip, u16 addr, u8 *val)
416 SPI_TRANSFER0_END); 389 SPI_TRANSFER0_END);
417 390
418 retval = rtsx_send_cmd(chip, 0, 100); 391 retval = rtsx_send_cmd(chip, 0, 100);
419 if (retval < 0) { 392 if (retval < 0)
420 return STATUS_FAIL; 393 return STATUS_FAIL;
421 }
422 394
423 wait_timeout(5); 395 wait_timeout(5);
424 retval = rtsx_read_register(chip, SPI_DATA, &data); 396 retval = rtsx_read_register(chip, SPI_DATA, &data);
425 if (retval) { 397 if (retval)
426 return retval; 398 return retval;
427 }
428 399
429 if (val) 400 if (val)
430 *val = data; 401 *val = data;
431 402
432 retval = rtsx_write_register(chip, CARD_GPIO_DIR, 0x01, 0x01); 403 retval = rtsx_write_register(chip, CARD_GPIO_DIR, 0x01, 0x01);
433 if (retval) { 404 if (retval)
434 return retval; 405 return retval;
435 }
436 406
437 return STATUS_SUCCESS; 407 return STATUS_SUCCESS;
438} 408}
@@ -442,14 +412,12 @@ int spi_write_eeprom(struct rtsx_chip *chip, u16 addr, u8 val)
442 int retval; 412 int retval;
443 413
444 retval = spi_init_eeprom(chip); 414 retval = spi_init_eeprom(chip);
445 if (retval != STATUS_SUCCESS) { 415 if (retval != STATUS_SUCCESS)
446 return STATUS_FAIL; 416 return STATUS_FAIL;
447 }
448 417
449 retval = spi_eeprom_program_enable(chip); 418 retval = spi_eeprom_program_enable(chip);
450 if (retval != STATUS_SUCCESS) { 419 if (retval != STATUS_SUCCESS)
451 return STATUS_FAIL; 420 return STATUS_FAIL;
452 }
453 421
454 rtsx_init_cmd(chip); 422 rtsx_init_cmd(chip);
455 423
@@ -466,14 +434,12 @@ int spi_write_eeprom(struct rtsx_chip *chip, u16 addr, u8 val)
466 SPI_TRANSFER0_END); 434 SPI_TRANSFER0_END);
467 435
468 retval = rtsx_send_cmd(chip, 0, 100); 436 retval = rtsx_send_cmd(chip, 0, 100);
469 if (retval < 0) { 437 if (retval < 0)
470 return STATUS_FAIL; 438 return STATUS_FAIL;
471 }
472 439
473 retval = rtsx_write_register(chip, CARD_GPIO_DIR, 0x01, 0x01); 440 retval = rtsx_write_register(chip, CARD_GPIO_DIR, 0x01, 0x01);
474 if (retval) { 441 if (retval)
475 return retval; 442 return retval;
476 }
477 443
478 return STATUS_SUCCESS; 444 return STATUS_SUCCESS;
479} 445}
@@ -577,9 +543,8 @@ int spi_read_flash_id(struct scsi_cmnd *srb, struct rtsx_chip *chip)
577 543
578 if (len) { 544 if (len) {
579 buf = kmalloc(len, GFP_KERNEL); 545 buf = kmalloc(len, GFP_KERNEL);
580 if (!buf) { 546 if (!buf)
581 return STATUS_ERROR; 547 return STATUS_ERROR;
582 }
583 548
584 retval = rtsx_read_ppbuf(chip, buf, len); 549 retval = rtsx_read_ppbuf(chip, buf, len);
585 if (retval != STATUS_SUCCESS) { 550 if (retval != STATUS_SUCCESS) {
@@ -621,9 +586,8 @@ int spi_read_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip)
621 } 586 }
622 587
623 buf = kmalloc(SF_PAGE_LEN, GFP_KERNEL); 588 buf = kmalloc(SF_PAGE_LEN, GFP_KERNEL);
624 if (!buf) { 589 if (!buf)
625 return STATUS_ERROR; 590 return STATUS_ERROR;
626 }
627 591
628 while (len) { 592 while (len) {
629 u16 pagelen = SF_PAGE_LEN - (u8)addr; 593 u16 pagelen = SF_PAGE_LEN - (u8)addr;
@@ -716,9 +680,8 @@ int spi_write_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip)
716 680
717 if (program_mode == BYTE_PROGRAM) { 681 if (program_mode == BYTE_PROGRAM) {
718 buf = kmalloc(4, GFP_KERNEL); 682 buf = kmalloc(4, GFP_KERNEL);
719 if (!buf) { 683 if (!buf)
720 return STATUS_ERROR; 684 return STATUS_ERROR;
721 }
722 685
723 while (len) { 686 while (len) {
724 retval = sf_enable_write(chip, SPI_WREN); 687 retval = sf_enable_write(chip, SPI_WREN);
@@ -762,14 +725,12 @@ int spi_write_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip)
762 int first_byte = 1; 725 int first_byte = 1;
763 726
764 retval = sf_enable_write(chip, SPI_WREN); 727 retval = sf_enable_write(chip, SPI_WREN);
765 if (retval != STATUS_SUCCESS) { 728 if (retval != STATUS_SUCCESS)
766 return STATUS_FAIL; 729 return STATUS_FAIL;
767 }
768 730
769 buf = kmalloc(4, GFP_KERNEL); 731 buf = kmalloc(4, GFP_KERNEL);
770 if (!buf) { 732 if (!buf)
771 return STATUS_ERROR; 733 return STATUS_ERROR;
772 }
773 734
774 while (len) { 735 while (len) {
775 rtsx_stor_access_xfer_buf(buf, 1, srb, &index, &offset, 736 rtsx_stor_access_xfer_buf(buf, 1, srb, &index, &offset,
@@ -808,19 +769,16 @@ int spi_write_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip)
808 kfree(buf); 769 kfree(buf);
809 770
810 retval = sf_disable_write(chip, SPI_WRDI); 771 retval = sf_disable_write(chip, SPI_WRDI);
811 if (retval != STATUS_SUCCESS) { 772 if (retval != STATUS_SUCCESS)
812 return STATUS_FAIL; 773 return STATUS_FAIL;
813 }
814 774
815 retval = sf_polling_status(chip, 100); 775 retval = sf_polling_status(chip, 100);
816 if (retval != STATUS_SUCCESS) { 776 if (retval != STATUS_SUCCESS)
817 return STATUS_FAIL; 777 return STATUS_FAIL;
818 }
819 } else if (program_mode == PAGE_PROGRAM) { 778 } else if (program_mode == PAGE_PROGRAM) {
820 buf = kmalloc(SF_PAGE_LEN, GFP_KERNEL); 779 buf = kmalloc(SF_PAGE_LEN, GFP_KERNEL);
821 if (!buf) { 780 if (!buf)
822 return STATUS_NOMEM; 781 return STATUS_NOMEM;
823 }
824 782
825 while (len) { 783 while (len) {
826 u16 pagelen = SF_PAGE_LEN - (u8)addr; 784 u16 pagelen = SF_PAGE_LEN - (u8)addr;
@@ -893,24 +851,20 @@ int spi_erase_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip)
893 851
894 if (erase_mode == PAGE_ERASE) { 852 if (erase_mode == PAGE_ERASE) {
895 retval = sf_enable_write(chip, SPI_WREN); 853 retval = sf_enable_write(chip, SPI_WREN);
896 if (retval != STATUS_SUCCESS) { 854 if (retval != STATUS_SUCCESS)
897 return STATUS_FAIL; 855 return STATUS_FAIL;
898 }
899 856
900 retval = sf_erase(chip, ins, 1, addr); 857 retval = sf_erase(chip, ins, 1, addr);
901 if (retval != STATUS_SUCCESS) { 858 if (retval != STATUS_SUCCESS)
902 return STATUS_FAIL; 859 return STATUS_FAIL;
903 }
904 } else if (erase_mode == CHIP_ERASE) { 860 } else if (erase_mode == CHIP_ERASE) {
905 retval = sf_enable_write(chip, SPI_WREN); 861 retval = sf_enable_write(chip, SPI_WREN);
906 if (retval != STATUS_SUCCESS) { 862 if (retval != STATUS_SUCCESS)
907 return STATUS_FAIL; 863 return STATUS_FAIL;
908 }
909 864
910 retval = sf_erase(chip, ins, 0, 0); 865 retval = sf_erase(chip, ins, 0, 0);
911 if (retval != STATUS_SUCCESS) { 866 if (retval != STATUS_SUCCESS)
912 return STATUS_FAIL; 867 return STATUS_FAIL;
913 }
914 } else { 868 } else {
915 spi_set_err_code(chip, SPI_INVALID_COMMAND); 869 spi_set_err_code(chip, SPI_INVALID_COMMAND);
916 return STATUS_FAIL; 870 return STATUS_FAIL;
@@ -935,9 +889,8 @@ int spi_write_flash_status(struct scsi_cmnd *srb, struct rtsx_chip *chip)
935 } 889 }
936 890
937 retval = sf_enable_write(chip, ewsr); 891 retval = sf_enable_write(chip, ewsr);
938 if (retval != STATUS_SUCCESS) { 892 if (retval != STATUS_SUCCESS)
939 return STATUS_FAIL; 893 return STATUS_FAIL;
940 }
941 894
942 rtsx_init_cmd(chip); 895 rtsx_init_cmd(chip);
943 896
diff --git a/drivers/staging/rts5208/xd.c b/drivers/staging/rts5208/xd.c
index 261d868a3072..d71f19ceb6fa 100644
--- a/drivers/staging/rts5208/xd.c
+++ b/drivers/staging/rts5208/xd.c
@@ -60,9 +60,8 @@ static int xd_set_init_para(struct rtsx_chip *chip)
60 xd_card->xd_clock = CLK_50; 60 xd_card->xd_clock = CLK_50;
61 61
62 retval = switch_clock(chip, xd_card->xd_clock); 62 retval = switch_clock(chip, xd_card->xd_clock);
63 if (retval != STATUS_SUCCESS) { 63 if (retval != STATUS_SUCCESS)
64 return STATUS_FAIL; 64 return STATUS_FAIL;
65 }
66 65
67 return STATUS_SUCCESS; 66 return STATUS_SUCCESS;
68} 67}
@@ -73,14 +72,12 @@ static int xd_switch_clock(struct rtsx_chip *chip)
73 int retval; 72 int retval;
74 73
75 retval = select_card(chip, XD_CARD); 74 retval = select_card(chip, XD_CARD);
76 if (retval != STATUS_SUCCESS) { 75 if (retval != STATUS_SUCCESS)
77 return STATUS_FAIL; 76 return STATUS_FAIL;
78 }
79 77
80 retval = switch_clock(chip, xd_card->xd_clock); 78 retval = switch_clock(chip, xd_card->xd_clock);
81 if (retval != STATUS_SUCCESS) { 79 if (retval != STATUS_SUCCESS)
82 return STATUS_FAIL; 80 return STATUS_FAIL;
83 }
84 81
85 return STATUS_SUCCESS; 82 return STATUS_SUCCESS;
86} 83}
@@ -102,9 +99,8 @@ static int xd_read_id(struct rtsx_chip *chip, u8 id_cmd, u8 *id_buf, u8 buf_len)
102 rtsx_add_cmd(chip, READ_REG_CMD, (u16)(XD_ADDRESS1 + i), 0, 0); 99 rtsx_add_cmd(chip, READ_REG_CMD, (u16)(XD_ADDRESS1 + i), 0, 0);
103 100
104 retval = rtsx_send_cmd(chip, XD_CARD, 20); 101 retval = rtsx_send_cmd(chip, XD_CARD, 20);
105 if (retval < 0) { 102 if (retval < 0)
106 return STATUS_FAIL; 103 return STATUS_FAIL;
107 }
108 104
109 ptr = rtsx_get_cmd_data(chip) + 1; 105 ptr = rtsx_get_cmd_data(chip) + 1;
110 if (id_buf && buf_len) { 106 if (id_buf && buf_len) {
@@ -173,9 +169,8 @@ static int xd_read_redundant(struct rtsx_chip *chip, u32 page_addr,
173 rtsx_add_cmd(chip, READ_REG_CMD, XD_PARITY, 0, 0); 169 rtsx_add_cmd(chip, READ_REG_CMD, XD_PARITY, 0, 0);
174 170
175 retval = rtsx_send_cmd(chip, XD_CARD, 500); 171 retval = rtsx_send_cmd(chip, XD_CARD, 500);
176 if (retval < 0) { 172 if (retval < 0)
177 return STATUS_FAIL; 173 return STATUS_FAIL;
178 }
179 174
180 if (buf && buf_len) { 175 if (buf && buf_len) {
181 u8 *ptr = rtsx_get_cmd_data(chip) + 1; 176 u8 *ptr = rtsx_get_cmd_data(chip) + 1;
@@ -193,9 +188,8 @@ static int xd_read_data_from_ppb(struct rtsx_chip *chip, int offset,
193{ 188{
194 int retval, i; 189 int retval, i;
195 190
196 if (!buf || (buf_len < 0)) { 191 if (!buf || (buf_len < 0))
197 return STATUS_FAIL; 192 return STATUS_FAIL;
198 }
199 193
200 rtsx_init_cmd(chip); 194 rtsx_init_cmd(chip);
201 195
@@ -220,9 +214,8 @@ static int xd_read_cis(struct rtsx_chip *chip, u32 page_addr, u8 *buf,
220 int retval; 214 int retval;
221 u8 reg; 215 u8 reg;
222 216
223 if (!buf || (buf_len < 10)) { 217 if (!buf || (buf_len < 10))
224 return STATUS_FAIL; 218 return STATUS_FAIL;
225 }
226 219
227 rtsx_init_cmd(chip); 220 rtsx_init_cmd(chip);
228 221
@@ -246,36 +239,31 @@ static int xd_read_cis(struct rtsx_chip *chip, u32 page_addr, u8 *buf,
246 } 239 }
247 240
248 retval = rtsx_read_register(chip, XD_PAGE_STATUS, &reg); 241 retval = rtsx_read_register(chip, XD_PAGE_STATUS, &reg);
249 if (retval) { 242 if (retval)
250 return retval; 243 return retval;
251 }
252 if (reg != XD_GPG) { 244 if (reg != XD_GPG) {
253 rtsx_clear_xd_error(chip); 245 rtsx_clear_xd_error(chip);
254 return STATUS_FAIL; 246 return STATUS_FAIL;
255 } 247 }
256 248
257 retval = rtsx_read_register(chip, XD_CTL, &reg); 249 retval = rtsx_read_register(chip, XD_CTL, &reg);
258 if (retval) { 250 if (retval)
259 return retval; 251 return retval;
260 }
261 if (!(reg & XD_ECC1_ERROR) || !(reg & XD_ECC1_UNCORRECTABLE)) { 252 if (!(reg & XD_ECC1_ERROR) || !(reg & XD_ECC1_UNCORRECTABLE)) {
262 retval = xd_read_data_from_ppb(chip, 0, buf, buf_len); 253 retval = xd_read_data_from_ppb(chip, 0, buf, buf_len);
263 if (retval != STATUS_SUCCESS) { 254 if (retval != STATUS_SUCCESS)
264 return STATUS_FAIL; 255 return STATUS_FAIL;
265 }
266 if (reg & XD_ECC1_ERROR) { 256 if (reg & XD_ECC1_ERROR) {
267 u8 ecc_bit, ecc_byte; 257 u8 ecc_bit, ecc_byte;
268 258
269 retval = rtsx_read_register(chip, XD_ECC_BIT1, 259 retval = rtsx_read_register(chip, XD_ECC_BIT1,
270 &ecc_bit); 260 &ecc_bit);
271 if (retval) { 261 if (retval)
272 return retval; 262 return retval;
273 }
274 retval = rtsx_read_register(chip, XD_ECC_BYTE1, 263 retval = rtsx_read_register(chip, XD_ECC_BYTE1,
275 &ecc_byte); 264 &ecc_byte);
276 if (retval) { 265 if (retval)
277 return retval; 266 return retval;
278 }
279 267
280 dev_dbg(rtsx_dev(chip), "ECC_BIT1 = 0x%x, ECC_BYTE1 = 0x%x\n", 268 dev_dbg(rtsx_dev(chip), "ECC_BIT1 = 0x%x, ECC_BYTE1 = 0x%x\n",
281 ecc_bit, ecc_byte); 269 ecc_bit, ecc_byte);
@@ -291,22 +279,19 @@ static int xd_read_cis(struct rtsx_chip *chip, u32 page_addr, u8 *buf,
291 rtsx_clear_xd_error(chip); 279 rtsx_clear_xd_error(chip);
292 280
293 retval = xd_read_data_from_ppb(chip, 256, buf, buf_len); 281 retval = xd_read_data_from_ppb(chip, 256, buf, buf_len);
294 if (retval != STATUS_SUCCESS) { 282 if (retval != STATUS_SUCCESS)
295 return STATUS_FAIL; 283 return STATUS_FAIL;
296 }
297 if (reg & XD_ECC2_ERROR) { 284 if (reg & XD_ECC2_ERROR) {
298 u8 ecc_bit, ecc_byte; 285 u8 ecc_bit, ecc_byte;
299 286
300 retval = rtsx_read_register(chip, XD_ECC_BIT2, 287 retval = rtsx_read_register(chip, XD_ECC_BIT2,
301 &ecc_bit); 288 &ecc_bit);
302 if (retval) { 289 if (retval)
303 return retval; 290 return retval;
304 }
305 retval = rtsx_read_register(chip, XD_ECC_BYTE2, 291 retval = rtsx_read_register(chip, XD_ECC_BYTE2,
306 &ecc_byte); 292 &ecc_byte);
307 if (retval) { 293 if (retval)
308 return retval; 294 return retval;
309 }
310 295
311 dev_dbg(rtsx_dev(chip), "ECC_BIT2 = 0x%x, ECC_BYTE2 = 0x%x\n", 296 dev_dbg(rtsx_dev(chip), "ECC_BIT2 = 0x%x, ECC_BYTE2 = 0x%x\n",
312 ecc_bit, ecc_byte); 297 ecc_bit, ecc_byte);
@@ -404,68 +389,58 @@ static int xd_pull_ctl_disable(struct rtsx_chip *chip)
404 XD_D2_PD | 389 XD_D2_PD |
405 XD_D1_PD | 390 XD_D1_PD |
406 XD_D0_PD); 391 XD_D0_PD);
407 if (retval) { 392 if (retval)
408 return retval; 393 return retval;
409 }
410 retval = rtsx_write_register(chip, CARD_PULL_CTL2, 0xFF, 394 retval = rtsx_write_register(chip, CARD_PULL_CTL2, 0xFF,
411 XD_D7_PD | 395 XD_D7_PD |
412 XD_D6_PD | 396 XD_D6_PD |
413 XD_D5_PD | 397 XD_D5_PD |
414 XD_D4_PD); 398 XD_D4_PD);
415 if (retval) { 399 if (retval)
416 return retval; 400 return retval;
417 }
418 retval = rtsx_write_register(chip, CARD_PULL_CTL3, 0xFF, 401 retval = rtsx_write_register(chip, CARD_PULL_CTL3, 0xFF,
419 XD_WP_PD | 402 XD_WP_PD |
420 XD_CE_PD | 403 XD_CE_PD |
421 XD_CLE_PD | 404 XD_CLE_PD |
422 XD_CD_PU); 405 XD_CD_PU);
423 if (retval) { 406 if (retval)
424 return retval; 407 return retval;
425 }
426 retval = rtsx_write_register(chip, CARD_PULL_CTL4, 0xFF, 408 retval = rtsx_write_register(chip, CARD_PULL_CTL4, 0xFF,
427 XD_RDY_PD | 409 XD_RDY_PD |
428 XD_WE_PD | 410 XD_WE_PD |
429 XD_RE_PD | 411 XD_RE_PD |
430 XD_ALE_PD); 412 XD_ALE_PD);
431 if (retval) { 413 if (retval)
432 return retval; 414 return retval;
433 }
434 retval = rtsx_write_register(chip, CARD_PULL_CTL5, 0xFF, 415 retval = rtsx_write_register(chip, CARD_PULL_CTL5, 0xFF,
435 MS_INS_PU | 416 MS_INS_PU |
436 SD_WP_PD | 417 SD_WP_PD |
437 SD_CD_PU | 418 SD_CD_PU |
438 SD_CMD_PD); 419 SD_CMD_PD);
439 if (retval) { 420 if (retval)
440 return retval; 421 return retval;
441 }
442 retval = rtsx_write_register(chip, CARD_PULL_CTL6, 0xFF, 422 retval = rtsx_write_register(chip, CARD_PULL_CTL6, 0xFF,
443 MS_D5_PD | MS_D4_PD); 423 MS_D5_PD | MS_D4_PD);
444 if (retval) { 424 if (retval)
445 return retval; 425 return retval;
446 }
447 } else if (CHECK_PID(chip, 0x5288)) { 426 } else if (CHECK_PID(chip, 0x5288)) {
448 if (CHECK_BARO_PKG(chip, QFN)) { 427 if (CHECK_BARO_PKG(chip, QFN)) {
449 retval = rtsx_write_register(chip, CARD_PULL_CTL1, 428 retval = rtsx_write_register(chip, CARD_PULL_CTL1,
450 0xFF, 0x55); 429 0xFF, 0x55);
451 if (retval) { 430 if (retval)
452 return retval; 431 return retval;
453 }
454 retval = rtsx_write_register(chip, CARD_PULL_CTL2, 432 retval = rtsx_write_register(chip, CARD_PULL_CTL2,
455 0xFF, 0x55); 433 0xFF, 0x55);
456 if (retval) { 434 if (retval)
457 return retval; 435 return retval;
458 }
459 retval = rtsx_write_register(chip, CARD_PULL_CTL3, 436 retval = rtsx_write_register(chip, CARD_PULL_CTL3,
460 0xFF, 0x4B); 437 0xFF, 0x4B);
461 if (retval) { 438 if (retval)
462 return retval; 439 return retval;
463 }
464 retval = rtsx_write_register(chip, CARD_PULL_CTL4, 440 retval = rtsx_write_register(chip, CARD_PULL_CTL4,
465 0xFF, 0x69); 441 0xFF, 0x69);
466 if (retval) { 442 if (retval)
467 return retval; 443 return retval;
468 }
469 } 444 }
470 } 445 }
471 446
@@ -479,9 +454,8 @@ static int reset_xd(struct rtsx_chip *chip)
479 u8 *ptr, id_buf[4], redunt[11]; 454 u8 *ptr, id_buf[4], redunt[11];
480 455
481 retval = select_card(chip, XD_CARD); 456 retval = select_card(chip, XD_CARD);
482 if (retval != STATUS_SUCCESS) { 457 if (retval != STATUS_SUCCESS)
483 return STATUS_FAIL; 458 return STATUS_FAIL;
484 }
485 459
486 rtsx_init_cmd(chip); 460 rtsx_init_cmd(chip);
487 461
@@ -505,15 +479,13 @@ static int reset_xd(struct rtsx_chip *chip)
505 rtsx_add_cmd(chip, WRITE_REG_CMD, CARD_OE, XD_OUTPUT_EN, 0); 479 rtsx_add_cmd(chip, WRITE_REG_CMD, CARD_OE, XD_OUTPUT_EN, 0);
506 480
507 retval = rtsx_send_cmd(chip, XD_CARD, 100); 481 retval = rtsx_send_cmd(chip, XD_CARD, 100);
508 if (retval < 0) { 482 if (retval < 0)
509 return STATUS_FAIL; 483 return STATUS_FAIL;
510 }
511 484
512 if (!chip->ft2_fast_mode) { 485 if (!chip->ft2_fast_mode) {
513 retval = card_power_off(chip, XD_CARD); 486 retval = card_power_off(chip, XD_CARD);
514 if (retval != STATUS_SUCCESS) { 487 if (retval != STATUS_SUCCESS)
515 return STATUS_FAIL; 488 return STATUS_FAIL;
516 }
517 489
518 wait_timeout(250); 490 wait_timeout(250);
519 491
@@ -529,14 +501,12 @@ static int reset_xd(struct rtsx_chip *chip)
529 } 501 }
530 502
531 retval = rtsx_send_cmd(chip, XD_CARD, 100); 503 retval = rtsx_send_cmd(chip, XD_CARD, 100);
532 if (retval < 0) { 504 if (retval < 0)
533 return STATUS_FAIL; 505 return STATUS_FAIL;
534 }
535 506
536 retval = card_power_on(chip, XD_CARD); 507 retval = card_power_on(chip, XD_CARD);
537 if (retval != STATUS_SUCCESS) { 508 if (retval != STATUS_SUCCESS)
538 return STATUS_FAIL; 509 return STATUS_FAIL;
539 }
540 510
541#ifdef SUPPORT_OCP 511#ifdef SUPPORT_OCP
542 wait_timeout(50); 512 wait_timeout(50);
@@ -565,17 +535,15 @@ static int reset_xd(struct rtsx_chip *chip)
565 rtsx_add_cmd(chip, WRITE_REG_CMD, XD_CTL, XD_CE_DISEN, XD_CE_DISEN); 535 rtsx_add_cmd(chip, WRITE_REG_CMD, XD_CTL, XD_CE_DISEN, XD_CE_DISEN);
566 536
567 retval = rtsx_send_cmd(chip, XD_CARD, 100); 537 retval = rtsx_send_cmd(chip, XD_CARD, 100);
568 if (retval < 0) { 538 if (retval < 0)
569 return STATUS_FAIL; 539 return STATUS_FAIL;
570 }
571 540
572 if (!chip->ft2_fast_mode) 541 if (!chip->ft2_fast_mode)
573 wait_timeout(200); 542 wait_timeout(200);
574 543
575 retval = xd_set_init_para(chip); 544 retval = xd_set_init_para(chip);
576 if (retval != STATUS_SUCCESS) { 545 if (retval != STATUS_SUCCESS)
577 return STATUS_FAIL; 546 return STATUS_FAIL;
578 }
579 547
580 /* Read ID to check if the timing setting is right */ 548 /* Read ID to check if the timing setting is right */
581 for (i = 0; i < 4; i++) { 549 for (i = 0; i < 4; i++) {
@@ -598,9 +566,8 @@ static int reset_xd(struct rtsx_chip *chip)
598 rtsx_add_cmd(chip, READ_REG_CMD, XD_CTL, 0, 0); 566 rtsx_add_cmd(chip, READ_REG_CMD, XD_CTL, 0, 0);
599 567
600 retval = rtsx_send_cmd(chip, XD_CARD, 100); 568 retval = rtsx_send_cmd(chip, XD_CARD, 100);
601 if (retval < 0) { 569 if (retval < 0)
602 return STATUS_FAIL; 570 return STATUS_FAIL;
603 }
604 571
605 ptr = rtsx_get_cmd_data(chip) + 1; 572 ptr = rtsx_get_cmd_data(chip) + 1;
606 573
@@ -612,9 +579,8 @@ static int reset_xd(struct rtsx_chip *chip)
612 continue; 579 continue;
613 580
614 retval = xd_read_id(chip, READ_ID, id_buf, 4); 581 retval = xd_read_id(chip, READ_ID, id_buf, 4);
615 if (retval != STATUS_SUCCESS) { 582 if (retval != STATUS_SUCCESS)
616 return STATUS_FAIL; 583 return STATUS_FAIL;
617 }
618 584
619 dev_dbg(rtsx_dev(chip), "READ_ID: 0x%x 0x%x 0x%x 0x%x\n", 585 dev_dbg(rtsx_dev(chip), "READ_ID: 0x%x 0x%x 0x%x 0x%x\n",
620 id_buf[0], id_buf[1], id_buf[2], id_buf[3]); 586 id_buf[0], id_buf[1], id_buf[2], id_buf[3]);
@@ -694,9 +660,8 @@ static int reset_xd(struct rtsx_chip *chip)
694 /* Confirm timing setting */ 660 /* Confirm timing setting */
695 for (j = 0; j < 10; j++) { 661 for (j = 0; j < 10; j++) {
696 retval = xd_read_id(chip, READ_ID, id_buf, 4); 662 retval = xd_read_id(chip, READ_ID, id_buf, 4);
697 if (retval != STATUS_SUCCESS) { 663 if (retval != STATUS_SUCCESS)
698 return STATUS_FAIL; 664 return STATUS_FAIL;
699 }
700 665
701 if (id_buf[1] != xd_card->device_code) 666 if (id_buf[1] != xd_card->device_code)
702 break; 667 break;
@@ -716,22 +681,19 @@ static int reset_xd(struct rtsx_chip *chip)
716 } 681 }
717 682
718 retval = xd_read_id(chip, READ_xD_ID, id_buf, 4); 683 retval = xd_read_id(chip, READ_xD_ID, id_buf, 4);
719 if (retval != STATUS_SUCCESS) { 684 if (retval != STATUS_SUCCESS)
720 return STATUS_FAIL; 685 return STATUS_FAIL;
721 }
722 dev_dbg(rtsx_dev(chip), "READ_xD_ID: 0x%x 0x%x 0x%x 0x%x\n", 686 dev_dbg(rtsx_dev(chip), "READ_xD_ID: 0x%x 0x%x 0x%x 0x%x\n",
723 id_buf[0], id_buf[1], id_buf[2], id_buf[3]); 687 id_buf[0], id_buf[1], id_buf[2], id_buf[3]);
724 if (id_buf[2] != XD_ID_CODE) { 688 if (id_buf[2] != XD_ID_CODE)
725 return STATUS_FAIL; 689 return STATUS_FAIL;
726 }
727 690
728 /* Search CIS block */ 691 /* Search CIS block */
729 for (i = 0; i < 24; i++) { 692 for (i = 0; i < 24; i++) {
730 u32 page_addr; 693 u32 page_addr;
731 694
732 if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) { 695 if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS)
733 return STATUS_FAIL; 696 return STATUS_FAIL;
734 }
735 697
736 page_addr = (u32)i << xd_card->block_shift; 698 page_addr = (u32)i << xd_card->block_shift;
737 699
@@ -769,9 +731,8 @@ static int reset_xd(struct rtsx_chip *chip)
769 page_addr += j; 731 page_addr += j;
770 732
771 retval = xd_read_cis(chip, page_addr, buf, 10); 733 retval = xd_read_cis(chip, page_addr, buf, 10);
772 if (retval != STATUS_SUCCESS) { 734 if (retval != STATUS_SUCCESS)
773 return STATUS_FAIL; 735 return STATUS_FAIL;
774 }
775 736
776 if ((buf[0] == 0x01) && (buf[1] == 0x03) && 737 if ((buf[0] == 0x01) && (buf[1] == 0x03) &&
777 (buf[2] == 0xD9) && 738 (buf[2] == 0xD9) &&
@@ -841,17 +802,15 @@ static int xd_init_l2p_tbl(struct rtsx_chip *chip)
841 dev_dbg(rtsx_dev(chip), "%s: zone_cnt = %d\n", __func__, 802 dev_dbg(rtsx_dev(chip), "%s: zone_cnt = %d\n", __func__,
842 xd_card->zone_cnt); 803 xd_card->zone_cnt);
843 804
844 if (xd_card->zone_cnt < 1) { 805 if (xd_card->zone_cnt < 1)
845 return STATUS_FAIL; 806 return STATUS_FAIL;
846 }
847 807
848 size = xd_card->zone_cnt * sizeof(struct zone_entry); 808 size = xd_card->zone_cnt * sizeof(struct zone_entry);
849 dev_dbg(rtsx_dev(chip), "Buffer size for l2p table is %d\n", size); 809 dev_dbg(rtsx_dev(chip), "Buffer size for l2p table is %d\n", size);
850 810
851 xd_card->zone = vmalloc(size); 811 xd_card->zone = vmalloc(size);
852 if (!xd_card->zone) { 812 if (!xd_card->zone)
853 return STATUS_ERROR; 813 return STATUS_ERROR;
854 }
855 814
856 for (i = 0; i < xd_card->zone_cnt; i++) { 815 for (i = 0; i < xd_card->zone_cnt; i++) {
857 xd_card->zone[i].build_flag = 0; 816 xd_card->zone[i].build_flag = 0;
@@ -1028,19 +987,16 @@ int reset_xd_card(struct rtsx_chip *chip)
1028 xd_card->delay_write.delay_write_flag = 0; 987 xd_card->delay_write.delay_write_flag = 0;
1029 988
1030 retval = enable_card_clock(chip, XD_CARD); 989 retval = enable_card_clock(chip, XD_CARD);
1031 if (retval != STATUS_SUCCESS) { 990 if (retval != STATUS_SUCCESS)
1032 return STATUS_FAIL; 991 return STATUS_FAIL;
1033 }
1034 992
1035 retval = reset_xd(chip); 993 retval = reset_xd(chip);
1036 if (retval != STATUS_SUCCESS) { 994 if (retval != STATUS_SUCCESS)
1037 return STATUS_FAIL; 995 return STATUS_FAIL;
1038 }
1039 996
1040 retval = xd_init_l2p_tbl(chip); 997 retval = xd_init_l2p_tbl(chip);
1041 if (retval != STATUS_SUCCESS) { 998 if (retval != STATUS_SUCCESS)
1042 return STATUS_FAIL; 999 return STATUS_FAIL;
1043 }
1044 1000
1045 return STATUS_SUCCESS; 1001 return STATUS_SUCCESS;
1046} 1002}
@@ -1054,9 +1010,8 @@ static int xd_mark_bad_block(struct rtsx_chip *chip, u32 phy_blk)
1054 1010
1055 dev_dbg(rtsx_dev(chip), "mark block 0x%x as bad block\n", phy_blk); 1011 dev_dbg(rtsx_dev(chip), "mark block 0x%x as bad block\n", phy_blk);
1056 1012
1057 if (phy_blk == BLK_NOT_FOUND) { 1013 if (phy_blk == BLK_NOT_FOUND)
1058 return STATUS_FAIL; 1014 return STATUS_FAIL;
1059 }
1060 1015
1061 rtsx_init_cmd(chip); 1016 rtsx_init_cmd(chip);
1062 1017
@@ -1107,12 +1062,10 @@ static int xd_init_page(struct rtsx_chip *chip, u32 phy_blk,
1107 1062
1108 dev_dbg(rtsx_dev(chip), "Init block 0x%x\n", phy_blk); 1063 dev_dbg(rtsx_dev(chip), "Init block 0x%x\n", phy_blk);
1109 1064
1110 if (start_page > end_page) { 1065 if (start_page > end_page)
1111 return STATUS_FAIL; 1066 return STATUS_FAIL;
1112 } 1067 if (phy_blk == BLK_NOT_FOUND)
1113 if (phy_blk == BLK_NOT_FOUND) {
1114 return STATUS_FAIL; 1068 return STATUS_FAIL;
1115 }
1116 1069
1117 rtsx_init_cmd(chip); 1070 rtsx_init_cmd(chip);
1118 1071
@@ -1164,13 +1117,11 @@ static int xd_copy_page(struct rtsx_chip *chip, u32 old_blk, u32 new_blk,
1164 dev_dbg(rtsx_dev(chip), "Copy page from block 0x%x to block 0x%x\n", 1117 dev_dbg(rtsx_dev(chip), "Copy page from block 0x%x to block 0x%x\n",
1165 old_blk, new_blk); 1118 old_blk, new_blk);
1166 1119
1167 if (start_page > end_page) { 1120 if (start_page > end_page)
1168 return STATUS_FAIL; 1121 return STATUS_FAIL;
1169 }
1170 1122
1171 if ((old_blk == BLK_NOT_FOUND) || (new_blk == BLK_NOT_FOUND)) { 1123 if ((old_blk == BLK_NOT_FOUND) || (new_blk == BLK_NOT_FOUND))
1172 return STATUS_FAIL; 1124 return STATUS_FAIL;
1173 }
1174 1125
1175 old_page = (old_blk << xd_card->block_shift) + start_page; 1126 old_page = (old_blk << xd_card->block_shift) + start_page;
1176 new_page = (new_blk << xd_card->block_shift) + start_page; 1127 new_page = (new_blk << xd_card->block_shift) + start_page;
@@ -1179,9 +1130,8 @@ static int xd_copy_page(struct rtsx_chip *chip, u32 old_blk, u32 new_blk,
1179 1130
1180 retval = rtsx_write_register(chip, CARD_DATA_SOURCE, 0x01, 1131 retval = rtsx_write_register(chip, CARD_DATA_SOURCE, 0x01,
1181 PINGPONG_BUFFER); 1132 PINGPONG_BUFFER);
1182 if (retval) { 1133 if (retval)
1183 return retval; 1134 return retval;
1184 }
1185 1135
1186 for (i = start_page; i < end_page; i++) { 1136 for (i = start_page; i < end_page; i++) {
1187 if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) { 1137 if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) {
@@ -1287,9 +1237,8 @@ static int xd_reset_cmd(struct rtsx_chip *chip)
1287 rtsx_add_cmd(chip, READ_REG_CMD, XD_CTL, 0, 0); 1237 rtsx_add_cmd(chip, READ_REG_CMD, XD_CTL, 0, 0);
1288 1238
1289 retval = rtsx_send_cmd(chip, XD_CARD, 100); 1239 retval = rtsx_send_cmd(chip, XD_CARD, 100);
1290 if (retval < 0) { 1240 if (retval < 0)
1291 return STATUS_FAIL; 1241 return STATUS_FAIL;
1292 }
1293 1242
1294 ptr = rtsx_get_cmd_data(chip) + 1; 1243 ptr = rtsx_get_cmd_data(chip) + 1;
1295 if (((ptr[0] & READY_FLAG) == READY_STATE) && (ptr[1] & XD_RDY)) 1244 if (((ptr[0] & READY_FLAG) == READY_STATE) && (ptr[1] & XD_RDY))
@@ -1305,9 +1254,8 @@ static int xd_erase_block(struct rtsx_chip *chip, u32 phy_blk)
1305 u8 reg = 0, *ptr; 1254 u8 reg = 0, *ptr;
1306 int i, retval; 1255 int i, retval;
1307 1256
1308 if (phy_blk == BLK_NOT_FOUND) { 1257 if (phy_blk == BLK_NOT_FOUND)
1309 return STATUS_FAIL; 1258 return STATUS_FAIL;
1310 }
1311 1259
1312 page_addr = phy_blk << xd_card->block_shift; 1260 page_addr = phy_blk << xd_card->block_shift;
1313 1261
@@ -1333,9 +1281,8 @@ static int xd_erase_block(struct rtsx_chip *chip, u32 phy_blk)
1333 } 1281 }
1334 xd_set_err_code(chip, XD_ERASE_FAIL); 1282 xd_set_err_code(chip, XD_ERASE_FAIL);
1335 retval = xd_reset_cmd(chip); 1283 retval = xd_reset_cmd(chip);
1336 if (retval != STATUS_SUCCESS) { 1284 if (retval != STATUS_SUCCESS)
1337 return STATUS_FAIL; 1285 return STATUS_FAIL;
1338 }
1339 continue; 1286 continue;
1340 } 1287 }
1341 1288
@@ -1382,17 +1329,15 @@ static int xd_build_l2p_tbl(struct rtsx_chip *chip, int zone_no)
1382 1329
1383 if (!zone->l2p_table) { 1330 if (!zone->l2p_table) {
1384 zone->l2p_table = vmalloc(2000); 1331 zone->l2p_table = vmalloc(2000);
1385 if (!zone->l2p_table) { 1332 if (!zone->l2p_table)
1386 goto build_fail; 1333 goto build_fail;
1387 }
1388 } 1334 }
1389 memset((u8 *)(zone->l2p_table), 0xff, 2000); 1335 memset((u8 *)(zone->l2p_table), 0xff, 2000);
1390 1336
1391 if (!zone->free_table) { 1337 if (!zone->free_table) {
1392 zone->free_table = vmalloc(XD_FREE_TABLE_CNT * 2); 1338 zone->free_table = vmalloc(XD_FREE_TABLE_CNT * 2);
1393 if (!zone->free_table) { 1339 if (!zone->free_table)
1394 goto build_fail; 1340 goto build_fail;
1395 }
1396 } 1341 }
1397 memset((u8 *)(zone->free_table), 0xff, XD_FREE_TABLE_CNT * 2); 1342 memset((u8 *)(zone->free_table), 0xff, XD_FREE_TABLE_CNT * 2);
1398 1343
@@ -1555,9 +1500,8 @@ static int xd_send_cmd(struct rtsx_chip *chip, u8 cmd)
1555 XD_TRANSFER_END, XD_TRANSFER_END); 1500 XD_TRANSFER_END, XD_TRANSFER_END);
1556 1501
1557 retval = rtsx_send_cmd(chip, XD_CARD, 200); 1502 retval = rtsx_send_cmd(chip, XD_CARD, 200);
1558 if (retval < 0) { 1503 if (retval < 0)
1559 return STATUS_FAIL; 1504 return STATUS_FAIL;
1560 }
1561 1505
1562 return STATUS_SUCCESS; 1506 return STATUS_SUCCESS;
1563} 1507}
@@ -1636,17 +1580,15 @@ static int xd_read_multiple_pages(struct rtsx_chip *chip, u32 phy_blk,
1636 1580
1637fail: 1581fail:
1638 retval = rtsx_read_register(chip, XD_PAGE_STATUS, &reg_val); 1582 retval = rtsx_read_register(chip, XD_PAGE_STATUS, &reg_val);
1639 if (retval) { 1583 if (retval)
1640 return retval; 1584 return retval;
1641 }
1642 1585
1643 if (reg_val != XD_GPG) 1586 if (reg_val != XD_GPG)
1644 xd_set_err_code(chip, XD_PRG_ERROR); 1587 xd_set_err_code(chip, XD_PRG_ERROR);
1645 1588
1646 retval = rtsx_read_register(chip, XD_CTL, &reg_val); 1589 retval = rtsx_read_register(chip, XD_CTL, &reg_val);
1647 if (retval) { 1590 if (retval)
1648 return retval; 1591 return retval;
1649 }
1650 1592
1651 if (((reg_val & (XD_ECC1_ERROR | XD_ECC1_UNCORRECTABLE)) == 1593 if (((reg_val & (XD_ECC1_ERROR | XD_ECC1_UNCORRECTABLE)) ==
1652 (XD_ECC1_ERROR | XD_ECC1_UNCORRECTABLE)) || 1594 (XD_ECC1_ERROR | XD_ECC1_UNCORRECTABLE)) ||
@@ -1702,9 +1644,8 @@ static int xd_finish_write(struct rtsx_chip *chip,
1702 dev_dbg(rtsx_dev(chip), "new_blk = 0x%x, ", new_blk); 1644 dev_dbg(rtsx_dev(chip), "new_blk = 0x%x, ", new_blk);
1703 dev_dbg(rtsx_dev(chip), "log_blk = 0x%x\n", log_blk); 1645 dev_dbg(rtsx_dev(chip), "log_blk = 0x%x\n", log_blk);
1704 1646
1705 if (page_off > xd_card->page_off) { 1647 if (page_off > xd_card->page_off)
1706 return STATUS_FAIL; 1648 return STATUS_FAIL;
1707 }
1708 1649
1709 zone_no = (int)(log_blk / 1000); 1650 zone_no = (int)(log_blk / 1000);
1710 log_off = (u16)(log_blk % 1000); 1651 log_off = (u16)(log_blk % 1000);
@@ -1760,9 +1701,8 @@ static int xd_prepare_write(struct rtsx_chip *chip,
1760 1701
1761 if (page_off) { 1702 if (page_off) {
1762 retval = xd_copy_page(chip, old_blk, new_blk, 0, page_off); 1703 retval = xd_copy_page(chip, old_blk, new_blk, 0, page_off);
1763 if (retval != STATUS_SUCCESS) { 1704 if (retval != STATUS_SUCCESS)
1764 return STATUS_FAIL; 1705 return STATUS_FAIL;
1765 }
1766 } 1706 }
1767 1707
1768 return STATUS_SUCCESS; 1708 return STATUS_SUCCESS;
@@ -1858,9 +1798,8 @@ static int xd_write_multiple_pages(struct rtsx_chip *chip, u32 old_blk,
1858 1798
1859fail: 1799fail:
1860 retval = rtsx_read_register(chip, XD_DAT, &reg_val); 1800 retval = rtsx_read_register(chip, XD_DAT, &reg_val);
1861 if (retval) { 1801 if (retval)
1862 return retval; 1802 return retval;
1863 }
1864 if (reg_val & PROGRAM_ERROR) { 1803 if (reg_val & PROGRAM_ERROR) {
1865 xd_set_err_code(chip, XD_PRG_ERROR); 1804 xd_set_err_code(chip, XD_PRG_ERROR);
1866 xd_mark_bad_block(chip, new_blk); 1805 xd_mark_bad_block(chip, new_blk);
@@ -1880,9 +1819,8 @@ int xd_delay_write(struct rtsx_chip *chip)
1880 if (delay_write->delay_write_flag) { 1819 if (delay_write->delay_write_flag) {
1881 dev_dbg(rtsx_dev(chip), "%s\n", __func__); 1820 dev_dbg(rtsx_dev(chip), "%s\n", __func__);
1882 retval = xd_switch_clock(chip); 1821 retval = xd_switch_clock(chip);
1883 if (retval != STATUS_SUCCESS) { 1822 if (retval != STATUS_SUCCESS)
1884 return STATUS_FAIL; 1823 return STATUS_FAIL;
1885 }
1886 1824
1887 delay_write->delay_write_flag = 0; 1825 delay_write->delay_write_flag = 0;
1888 retval = xd_finish_write(chip, 1826 retval = xd_finish_write(chip,
@@ -1890,9 +1828,8 @@ int xd_delay_write(struct rtsx_chip *chip)
1890 delay_write->new_phyblock, 1828 delay_write->new_phyblock,
1891 delay_write->logblock, 1829 delay_write->logblock,
1892 delay_write->pageoff); 1830 delay_write->pageoff);
1893 if (retval != STATUS_SUCCESS) { 1831 if (retval != STATUS_SUCCESS)
1894 return STATUS_FAIL; 1832 return STATUS_FAIL;
1895 }
1896 } 1833 }
1897 1834
1898 return STATUS_SUCCESS; 1835 return STATUS_SUCCESS;
@@ -1924,9 +1861,8 @@ int xd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip,
1924 ptr = (u8 *)scsi_sglist(srb); 1861 ptr = (u8 *)scsi_sglist(srb);
1925 1862
1926 retval = xd_switch_clock(chip); 1863 retval = xd_switch_clock(chip);
1927 if (retval != STATUS_SUCCESS) { 1864 if (retval != STATUS_SUCCESS)
1928 return STATUS_FAIL; 1865 return STATUS_FAIL;
1929 }
1930 1866
1931 if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) { 1867 if (detect_card_cd(chip, XD_CARD) != STATUS_SUCCESS) {
1932 chip->card_fail |= XD_CARD; 1868 chip->card_fail |= XD_CARD;
@@ -2180,34 +2116,29 @@ int xd_power_off_card3v3(struct rtsx_chip *chip)
2180 int retval; 2116 int retval;
2181 2117
2182 retval = disable_card_clock(chip, XD_CARD); 2118 retval = disable_card_clock(chip, XD_CARD);
2183 if (retval != STATUS_SUCCESS) { 2119 if (retval != STATUS_SUCCESS)
2184 return STATUS_FAIL; 2120 return STATUS_FAIL;
2185 }
2186 2121
2187 retval = rtsx_write_register(chip, CARD_OE, XD_OUTPUT_EN, 0); 2122 retval = rtsx_write_register(chip, CARD_OE, XD_OUTPUT_EN, 0);
2188 if (retval) { 2123 if (retval)
2189 return retval; 2124 return retval;
2190 }
2191 2125
2192 if (!chip->ft2_fast_mode) { 2126 if (!chip->ft2_fast_mode) {
2193 retval = card_power_off(chip, XD_CARD); 2127 retval = card_power_off(chip, XD_CARD);
2194 if (retval != STATUS_SUCCESS) { 2128 if (retval != STATUS_SUCCESS)
2195 return STATUS_FAIL; 2129 return STATUS_FAIL;
2196 }
2197 2130
2198 wait_timeout(50); 2131 wait_timeout(50);
2199 } 2132 }
2200 2133
2201 if (chip->asic_code) { 2134 if (chip->asic_code) {
2202 retval = xd_pull_ctl_disable(chip); 2135 retval = xd_pull_ctl_disable(chip);
2203 if (retval != STATUS_SUCCESS) { 2136 if (retval != STATUS_SUCCESS)
2204 return STATUS_FAIL; 2137 return STATUS_FAIL;
2205 }
2206 } else { 2138 } else {
2207 retval = rtsx_write_register(chip, FPGA_PULL_CTL, 0xFF, 0xDF); 2139 retval = rtsx_write_register(chip, FPGA_PULL_CTL, 0xFF, 0xDF);
2208 if (retval) { 2140 if (retval)
2209 return retval; 2141 return retval;
2210 }
2211 } 2142 }
2212 2143
2213 return STATUS_SUCCESS; 2144 return STATUS_SUCCESS;
@@ -2227,9 +2158,8 @@ int release_xd_card(struct rtsx_chip *chip)
2227 xd_free_l2p_tbl(chip); 2158 xd_free_l2p_tbl(chip);
2228 2159
2229 retval = xd_power_off_card3v3(chip); 2160 retval = xd_power_off_card3v3(chip);
2230 if (retval != STATUS_SUCCESS) { 2161 if (retval != STATUS_SUCCESS)
2231 return STATUS_FAIL; 2162 return STATUS_FAIL;
2232 }
2233 2163
2234 return STATUS_SUCCESS; 2164 return STATUS_SUCCESS;
2235} 2165}
diff --git a/drivers/staging/sm750fb/ddk750_mode.c b/drivers/staging/sm750fb/ddk750_mode.c
index 7e22d093b091..4dac691ad1b1 100644
--- a/drivers/staging/sm750fb/ddk750_mode.c
+++ b/drivers/staging/sm750fb/ddk750_mode.c
@@ -131,7 +131,7 @@ static int programModeRegisters(struct mode_parameter *pModeParam,
131 DISPLAY_CTRL_HSYNC_PHASE | 131 DISPLAY_CTRL_HSYNC_PHASE |
132 DISPLAY_CTRL_TIMING | DISPLAY_CTRL_PLANE); 132 DISPLAY_CTRL_TIMING | DISPLAY_CTRL_PLANE);
133 133
134 poke32(CRT_DISPLAY_CTRL, tmp | reg); 134 poke32(CRT_DISPLAY_CTRL, tmp | reg);
135 } 135 }
136 136
137 } else if (pll->clockType == PRIMARY_PLL) { 137 } else if (pll->clockType == PRIMARY_PLL) {
diff --git a/drivers/staging/sm750fb/ddk750_sii164.c b/drivers/staging/sm750fb/ddk750_sii164.c
index 4b34a083f5cf..8391f57d5383 100644
--- a/drivers/staging/sm750fb/ddk750_sii164.c
+++ b/drivers/staging/sm750fb/ddk750_sii164.c
@@ -39,8 +39,8 @@ unsigned short sii164GetVendorID(void)
39{ 39{
40 unsigned short vendorID; 40 unsigned short vendorID;
41 41
42 vendorID = ((unsigned short) i2cReadReg(SII164_I2C_ADDRESS, SII164_VENDOR_ID_HIGH) << 8) | 42 vendorID = ((unsigned short)i2cReadReg(SII164_I2C_ADDRESS, SII164_VENDOR_ID_HIGH) << 8) |
43 (unsigned short) i2cReadReg(SII164_I2C_ADDRESS, SII164_VENDOR_ID_LOW); 43 (unsigned short)i2cReadReg(SII164_I2C_ADDRESS, SII164_VENDOR_ID_LOW);
44 44
45 return vendorID; 45 return vendorID;
46} 46}
@@ -56,8 +56,8 @@ unsigned short sii164GetDeviceID(void)
56{ 56{
57 unsigned short deviceID; 57 unsigned short deviceID;
58 58
59 deviceID = ((unsigned short) i2cReadReg(SII164_I2C_ADDRESS, SII164_DEVICE_ID_HIGH) << 8) | 59 deviceID = ((unsigned short)i2cReadReg(SII164_I2C_ADDRESS, SII164_DEVICE_ID_HIGH) << 8) |
60 (unsigned short) i2cReadReg(SII164_I2C_ADDRESS, SII164_DEVICE_ID_LOW); 60 (unsigned short)i2cReadReg(SII164_I2C_ADDRESS, SII164_DEVICE_ID_LOW);
61 61
62 return deviceID; 62 return deviceID;
63} 63}
diff --git a/drivers/staging/sm750fb/sm750.c b/drivers/staging/sm750fb/sm750.c
index 846d7d243994..e9f10c2669ea 100644
--- a/drivers/staging/sm750fb/sm750.c
+++ b/drivers/staging/sm750fb/sm750.c
@@ -1007,7 +1007,7 @@ NO_PARAM:
1007 } 1007 }
1008} 1008}
1009 1009
1010static void sm750fb_frambuffer_release(struct sm750_dev *sm750_dev) 1010static void sm750fb_framebuffer_release(struct sm750_dev *sm750_dev)
1011{ 1011{
1012 struct fb_info *fb_info; 1012 struct fb_info *fb_info;
1013 1013
@@ -1019,7 +1019,7 @@ static void sm750fb_frambuffer_release(struct sm750_dev *sm750_dev)
1019 } 1019 }
1020} 1020}
1021 1021
1022static int sm750fb_frambuffer_alloc(struct sm750_dev *sm750_dev, int fbidx) 1022static int sm750fb_framebuffer_alloc(struct sm750_dev *sm750_dev, int fbidx)
1023{ 1023{
1024 struct fb_info *fb_info; 1024 struct fb_info *fb_info;
1025 struct lynxfb_par *par; 1025 struct lynxfb_par *par;
@@ -1137,7 +1137,7 @@ static int lynxfb_pci_probe(struct pci_dev *pdev,
1137 /* allocate frame buffer info structures according to g_dualview */ 1137 /* allocate frame buffer info structures according to g_dualview */
1138 max_fb = g_dualview ? 2 : 1; 1138 max_fb = g_dualview ? 2 : 1;
1139 for (fbidx = 0; fbidx < max_fb; fbidx++) { 1139 for (fbidx = 0; fbidx < max_fb; fbidx++) {
1140 err = sm750fb_frambuffer_alloc(sm750_dev, fbidx); 1140 err = sm750fb_framebuffer_alloc(sm750_dev, fbidx);
1141 if (err) 1141 if (err)
1142 goto release_fb; 1142 goto release_fb;
1143 } 1143 }
@@ -1145,7 +1145,7 @@ static int lynxfb_pci_probe(struct pci_dev *pdev,
1145 return 0; 1145 return 0;
1146 1146
1147release_fb: 1147release_fb:
1148 sm750fb_frambuffer_release(sm750_dev); 1148 sm750fb_framebuffer_release(sm750_dev);
1149 return err; 1149 return err;
1150} 1150}
1151 1151
@@ -1155,7 +1155,7 @@ static void lynxfb_pci_remove(struct pci_dev *pdev)
1155 1155
1156 sm750_dev = pci_get_drvdata(pdev); 1156 sm750_dev = pci_get_drvdata(pdev);
1157 1157
1158 sm750fb_frambuffer_release(sm750_dev); 1158 sm750fb_framebuffer_release(sm750_dev);
1159 arch_phys_wc_del(sm750_dev->mtrr.vram); 1159 arch_phys_wc_del(sm750_dev->mtrr.vram);
1160 1160
1161 iounmap(sm750_dev->pvReg); 1161 iounmap(sm750_dev->pvReg);
diff --git a/drivers/staging/speakup/spk_ttyio.c b/drivers/staging/speakup/spk_ttyio.c
index eac63aab8162..979e3ae249c1 100644
--- a/drivers/staging/speakup/spk_ttyio.c
+++ b/drivers/staging/speakup/spk_ttyio.c
@@ -227,9 +227,9 @@ static int spk_ttyio_out_unicode(struct spk_synth *in_synth, u16 ch)
227{ 227{
228 int ret; 228 int ret;
229 229
230 if (ch < 0x80) 230 if (ch < 0x80) {
231 ret = spk_ttyio_out(in_synth, ch); 231 ret = spk_ttyio_out(in_synth, ch);
232 else if (ch < 0x800) { 232 } else if (ch < 0x800) {
233 ret = spk_ttyio_out(in_synth, 0xc0 | (ch >> 6)); 233 ret = spk_ttyio_out(in_synth, 0xc0 | (ch >> 6));
234 ret &= spk_ttyio_out(in_synth, 0x80 | (ch & 0x3f)); 234 ret &= spk_ttyio_out(in_synth, 0x80 | (ch & 0x3f));
235 } else { 235 } else {
diff --git a/drivers/staging/vboxvideo/TODO b/drivers/staging/vboxvideo/TODO
index 468eea856ca6..2e0f99c3f10c 100644
--- a/drivers/staging/vboxvideo/TODO
+++ b/drivers/staging/vboxvideo/TODO
@@ -1,5 +1,4 @@
1TODO: 1TODO:
2-Move the driver over to the atomic API
3-Get a full review from the drm-maintainers on dri-devel done on this driver 2-Get a full review from the drm-maintainers on dri-devel done on this driver
4-Extend this TODO with the results of that review 3-Extend this TODO with the results of that review
5 4
diff --git a/drivers/staging/vboxvideo/vbox_drv.c b/drivers/staging/vboxvideo/vbox_drv.c
index 69cc508af1bc..257030460fb6 100644
--- a/drivers/staging/vboxvideo/vbox_drv.c
+++ b/drivers/staging/vboxvideo/vbox_drv.c
@@ -49,139 +49,140 @@ static const struct pci_device_id pciidlist[] = {
49}; 49};
50MODULE_DEVICE_TABLE(pci, pciidlist); 50MODULE_DEVICE_TABLE(pci, pciidlist);
51 51
52static struct drm_fb_helper_funcs vbox_fb_helper_funcs = {
53 .fb_probe = vboxfb_create,
54};
55
52static int vbox_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 56static int vbox_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
53{ 57{
54 struct drm_device *dev = NULL; 58 struct vbox_private *vbox;
55 int ret = 0; 59 int ret = 0;
56 60
57 dev = drm_dev_alloc(&driver, &pdev->dev); 61 if (!vbox_check_supported(VBE_DISPI_ID_HGSMI))
58 if (IS_ERR(dev)) { 62 return -ENODEV;
59 ret = PTR_ERR(dev); 63
60 goto err_drv_alloc; 64 vbox = kzalloc(sizeof(*vbox), GFP_KERNEL);
65 if (!vbox)
66 return -ENOMEM;
67
68 ret = drm_dev_init(&vbox->ddev, &driver, &pdev->dev);
69 if (ret) {
70 kfree(vbox);
71 return ret;
61 } 72 }
62 73
74 vbox->ddev.pdev = pdev;
75 vbox->ddev.dev_private = vbox;
76 pci_set_drvdata(pdev, vbox);
77 mutex_init(&vbox->hw_mutex);
78
63 ret = pci_enable_device(pdev); 79 ret = pci_enable_device(pdev);
64 if (ret) 80 if (ret)
65 goto err_pci_enable; 81 goto err_dev_put;
66
67 dev->pdev = pdev;
68 pci_set_drvdata(pdev, dev);
69 82
70 ret = vbox_driver_load(dev); 83 ret = vbox_hw_init(vbox);
71 if (ret) 84 if (ret)
72 goto err_vbox_driver_load; 85 goto err_pci_disable;
73 86
74 ret = drm_dev_register(dev, 0); 87 ret = vbox_mm_init(vbox);
75 if (ret) 88 if (ret)
76 goto err_drv_dev_register; 89 goto err_hw_fini;
77
78 return ret;
79
80 err_drv_dev_register:
81 vbox_driver_unload(dev);
82 err_vbox_driver_load:
83 pci_disable_device(pdev);
84 err_pci_enable:
85 drm_dev_put(dev);
86 err_drv_alloc:
87 return ret;
88}
89
90static void vbox_pci_remove(struct pci_dev *pdev)
91{
92 struct drm_device *dev = pci_get_drvdata(pdev);
93
94 drm_dev_unregister(dev);
95 vbox_driver_unload(dev);
96 drm_dev_put(dev);
97}
98 90
99static int vbox_drm_freeze(struct drm_device *dev) 91 ret = vbox_mode_init(vbox);
100{ 92 if (ret)
101 struct vbox_private *vbox = dev->dev_private; 93 goto err_mm_fini;
102 94
103 drm_kms_helper_poll_disable(dev); 95 ret = vbox_irq_init(vbox);
96 if (ret)
97 goto err_mode_fini;
104 98
105 pci_save_state(dev->pdev); 99 ret = drm_fb_helper_fbdev_setup(&vbox->ddev, &vbox->fb_helper,
100 &vbox_fb_helper_funcs, 32,
101 vbox->num_crtcs);
102 if (ret)
103 goto err_irq_fini;
106 104
107 drm_fb_helper_set_suspend_unlocked(&vbox->fbdev->helper, true); 105 ret = drm_dev_register(&vbox->ddev, 0);
106 if (ret)
107 goto err_fbdev_fini;
108 108
109 return 0; 109 return 0;
110}
111
112static int vbox_drm_thaw(struct drm_device *dev)
113{
114 struct vbox_private *vbox = dev->dev_private;
115
116 drm_mode_config_reset(dev);
117 drm_helper_resume_force_mode(dev);
118 drm_fb_helper_set_suspend_unlocked(&vbox->fbdev->helper, false);
119 110
120 return 0; 111err_fbdev_fini:
112 vbox_fbdev_fini(vbox);
113err_irq_fini:
114 vbox_irq_fini(vbox);
115err_mode_fini:
116 vbox_mode_fini(vbox);
117err_mm_fini:
118 vbox_mm_fini(vbox);
119err_hw_fini:
120 vbox_hw_fini(vbox);
121err_pci_disable:
122 pci_disable_device(pdev);
123err_dev_put:
124 drm_dev_put(&vbox->ddev);
125 return ret;
121} 126}
122 127
123static int vbox_drm_resume(struct drm_device *dev) 128static void vbox_pci_remove(struct pci_dev *pdev)
124{ 129{
125 int ret; 130 struct vbox_private *vbox = pci_get_drvdata(pdev);
126 131
127 if (pci_enable_device(dev->pdev)) 132 drm_dev_unregister(&vbox->ddev);
128 return -EIO; 133 vbox_fbdev_fini(vbox);
129 134 vbox_irq_fini(vbox);
130 ret = vbox_drm_thaw(dev); 135 vbox_mode_fini(vbox);
131 if (ret) 136 vbox_mm_fini(vbox);
132 return ret; 137 vbox_hw_fini(vbox);
133 138 drm_dev_put(&vbox->ddev);
134 drm_kms_helper_poll_enable(dev);
135
136 return 0;
137} 139}
138 140
139static int vbox_pm_suspend(struct device *dev) 141static int vbox_pm_suspend(struct device *dev)
140{ 142{
141 struct pci_dev *pdev = to_pci_dev(dev); 143 struct vbox_private *vbox = dev_get_drvdata(dev);
142 struct drm_device *ddev = pci_get_drvdata(pdev);
143 int error; 144 int error;
144 145
145 error = vbox_drm_freeze(ddev); 146 error = drm_mode_config_helper_suspend(&vbox->ddev);
146 if (error) 147 if (error)
147 return error; 148 return error;
148 149
149 pci_disable_device(pdev); 150 pci_save_state(vbox->ddev.pdev);
150 pci_set_power_state(pdev, PCI_D3hot); 151 pci_disable_device(vbox->ddev.pdev);
152 pci_set_power_state(vbox->ddev.pdev, PCI_D3hot);
151 153
152 return 0; 154 return 0;
153} 155}
154 156
155static int vbox_pm_resume(struct device *dev) 157static int vbox_pm_resume(struct device *dev)
156{ 158{
157 struct drm_device *ddev = pci_get_drvdata(to_pci_dev(dev)); 159 struct vbox_private *vbox = dev_get_drvdata(dev);
160
161 if (pci_enable_device(vbox->ddev.pdev))
162 return -EIO;
158 163
159 return vbox_drm_resume(ddev); 164 return drm_mode_config_helper_resume(&vbox->ddev);
160} 165}
161 166
162static int vbox_pm_freeze(struct device *dev) 167static int vbox_pm_freeze(struct device *dev)
163{ 168{
164 struct pci_dev *pdev = to_pci_dev(dev); 169 struct vbox_private *vbox = dev_get_drvdata(dev);
165 struct drm_device *ddev = pci_get_drvdata(pdev);
166
167 if (!ddev || !ddev->dev_private)
168 return -ENODEV;
169 170
170 return vbox_drm_freeze(ddev); 171 return drm_mode_config_helper_suspend(&vbox->ddev);
171} 172}
172 173
173static int vbox_pm_thaw(struct device *dev) 174static int vbox_pm_thaw(struct device *dev)
174{ 175{
175 struct drm_device *ddev = pci_get_drvdata(to_pci_dev(dev)); 176 struct vbox_private *vbox = dev_get_drvdata(dev);
176 177
177 return vbox_drm_thaw(ddev); 178 return drm_mode_config_helper_resume(&vbox->ddev);
178} 179}
179 180
180static int vbox_pm_poweroff(struct device *dev) 181static int vbox_pm_poweroff(struct device *dev)
181{ 182{
182 struct drm_device *ddev = pci_get_drvdata(to_pci_dev(dev)); 183 struct vbox_private *vbox = dev_get_drvdata(dev);
183 184
184 return vbox_drm_freeze(ddev); 185 return drm_mode_config_helper_suspend(&vbox->ddev);
185} 186}
186 187
187static const struct dev_pm_ops vbox_pm_ops = { 188static const struct dev_pm_ops vbox_pm_ops = {
@@ -259,10 +260,10 @@ static void vbox_master_drop(struct drm_device *dev, struct drm_file *file_priv)
259static struct drm_driver driver = { 260static struct drm_driver driver = {
260 .driver_features = 261 .driver_features =
261 DRIVER_MODESET | DRIVER_GEM | DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | 262 DRIVER_MODESET | DRIVER_GEM | DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED |
262 DRIVER_PRIME, 263 DRIVER_PRIME | DRIVER_ATOMIC,
263 .dev_priv_size = 0, 264 .dev_priv_size = 0,
264 265
265 .lastclose = vbox_driver_lastclose, 266 .lastclose = drm_fb_helper_lastclose,
266 .master_set = vbox_master_set, 267 .master_set = vbox_master_set,
267 .master_drop = vbox_master_drop, 268 .master_drop = vbox_master_drop,
268 269
diff --git a/drivers/staging/vboxvideo/vbox_drv.h b/drivers/staging/vboxvideo/vbox_drv.h
index 594f84272957..73395a7536c5 100644
--- a/drivers/staging/vboxvideo/vbox_drv.h
+++ b/drivers/staging/vboxvideo/vbox_drv.h
@@ -72,10 +72,16 @@
72 sizeof(struct hgsmi_host_flags)) 72 sizeof(struct hgsmi_host_flags))
73#define HOST_FLAGS_OFFSET GUEST_HEAP_USABLE_SIZE 73#define HOST_FLAGS_OFFSET GUEST_HEAP_USABLE_SIZE
74 74
75struct vbox_fbdev; 75struct vbox_framebuffer {
76 struct drm_framebuffer base;
77 struct drm_gem_object *obj;
78};
76 79
77struct vbox_private { 80struct vbox_private {
78 struct drm_device *dev; 81 /* Must be first; or we must define our own release callback */
82 struct drm_device ddev;
83 struct drm_fb_helper fb_helper;
84 struct vbox_framebuffer afb;
79 85
80 u8 __iomem *guest_heap; 86 u8 __iomem *guest_heap;
81 u8 __iomem *vbva_buffers; 87 u8 __iomem *vbva_buffers;
@@ -90,8 +96,6 @@ struct vbox_private {
90 /** Array of structures for receiving mode hints. */ 96 /** Array of structures for receiving mode hints. */
91 struct vbva_modehint *last_mode_hints; 97 struct vbva_modehint *last_mode_hints;
92 98
93 struct vbox_fbdev *fbdev;
94
95 int fb_mtrr; 99 int fb_mtrr;
96 100
97 struct { 101 struct {
@@ -115,21 +119,12 @@ struct vbox_private {
115 * encompassing all screen ones or is the fbdev console active? 119 * encompassing all screen ones or is the fbdev console active?
116 */ 120 */
117 bool single_framebuffer; 121 bool single_framebuffer;
118 u32 cursor_width;
119 u32 cursor_height;
120 u32 cursor_hot_x;
121 u32 cursor_hot_y;
122 size_t cursor_data_size;
123 u8 cursor_data[CURSOR_DATA_SIZE]; 122 u8 cursor_data[CURSOR_DATA_SIZE];
124}; 123};
125 124
126#undef CURSOR_PIXEL_COUNT 125#undef CURSOR_PIXEL_COUNT
127#undef CURSOR_DATA_SIZE 126#undef CURSOR_DATA_SIZE
128 127
129int vbox_driver_load(struct drm_device *dev);
130void vbox_driver_unload(struct drm_device *dev);
131void vbox_driver_lastclose(struct drm_device *dev);
132
133struct vbox_gem_object; 128struct vbox_gem_object;
134 129
135struct vbox_connector { 130struct vbox_connector {
@@ -145,43 +140,51 @@ struct vbox_connector {
145 140
146struct vbox_crtc { 141struct vbox_crtc {
147 struct drm_crtc base; 142 struct drm_crtc base;
148 bool blanked;
149 bool disconnected; 143 bool disconnected;
150 unsigned int crtc_id; 144 unsigned int crtc_id;
151 u32 fb_offset; 145 u32 fb_offset;
152 bool cursor_enabled; 146 bool cursor_enabled;
153 u32 x_hint; 147 u32 x_hint;
154 u32 y_hint; 148 u32 y_hint;
149 /*
150 * When setting a mode we not only pass the mode to the hypervisor,
151 * but also information on how to map / translate input coordinates
152 * for the emulated USB tablet. This input-mapping may change when
153 * the mode on *another* crtc changes.
154 *
155 * This means that sometimes we must do a modeset on other crtc-s then
156 * the one being changed to update the input-mapping. Including crtc-s
157 * which may be disabled inside the guest (shown as a black window
158 * on the host unless closed by the user).
159 *
160 * With atomic modesetting the mode-info of disabled crtcs gets zeroed
161 * yet we need it when updating the input-map to avoid resizing the
162 * window as a side effect of a mode_set on another crtc. Therefor we
163 * cache the info of the last mode below.
164 */
165 u32 width;
166 u32 height;
167 u32 x;
168 u32 y;
155}; 169};
156 170
157struct vbox_encoder { 171struct vbox_encoder {
158 struct drm_encoder base; 172 struct drm_encoder base;
159}; 173};
160 174
161struct vbox_framebuffer {
162 struct drm_framebuffer base;
163 struct drm_gem_object *obj;
164};
165
166struct vbox_fbdev {
167 struct drm_fb_helper helper;
168 struct vbox_framebuffer afb;
169 int size;
170 struct ttm_bo_kmap_obj mapping;
171 int x1, y1, x2, y2; /* dirty rect */
172 spinlock_t dirty_lock;
173};
174
175#define to_vbox_crtc(x) container_of(x, struct vbox_crtc, base) 175#define to_vbox_crtc(x) container_of(x, struct vbox_crtc, base)
176#define to_vbox_connector(x) container_of(x, struct vbox_connector, base) 176#define to_vbox_connector(x) container_of(x, struct vbox_connector, base)
177#define to_vbox_encoder(x) container_of(x, struct vbox_encoder, base) 177#define to_vbox_encoder(x) container_of(x, struct vbox_encoder, base)
178#define to_vbox_framebuffer(x) container_of(x, struct vbox_framebuffer, base) 178#define to_vbox_framebuffer(x) container_of(x, struct vbox_framebuffer, base)
179 179
180int vbox_mode_init(struct drm_device *dev); 180bool vbox_check_supported(u16 id);
181void vbox_mode_fini(struct drm_device *dev); 181int vbox_hw_init(struct vbox_private *vbox);
182void vbox_hw_fini(struct vbox_private *vbox);
183
184int vbox_mode_init(struct vbox_private *vbox);
185void vbox_mode_fini(struct vbox_private *vbox);
182 186
183#define DRM_MODE_FB_CMD drm_mode_fb_cmd2 187#define DRM_MODE_FB_CMD drm_mode_fb_cmd2
184#define CRTC_FB(crtc) ((crtc)->primary->fb)
185 188
186void vbox_enable_accel(struct vbox_private *vbox); 189void vbox_enable_accel(struct vbox_private *vbox);
187void vbox_disable_accel(struct vbox_private *vbox); 190void vbox_disable_accel(struct vbox_private *vbox);
@@ -191,14 +194,14 @@ void vbox_framebuffer_dirty_rectangles(struct drm_framebuffer *fb,
191 struct drm_clip_rect *rects, 194 struct drm_clip_rect *rects,
192 unsigned int num_rects); 195 unsigned int num_rects);
193 196
194int vbox_framebuffer_init(struct drm_device *dev, 197int vbox_framebuffer_init(struct vbox_private *vbox,
195 struct vbox_framebuffer *vbox_fb, 198 struct vbox_framebuffer *vbox_fb,
196 const struct DRM_MODE_FB_CMD *mode_cmd, 199 const struct DRM_MODE_FB_CMD *mode_cmd,
197 struct drm_gem_object *obj); 200 struct drm_gem_object *obj);
198 201
199int vbox_fbdev_init(struct drm_device *dev); 202int vboxfb_create(struct drm_fb_helper *helper,
200void vbox_fbdev_fini(struct drm_device *dev); 203 struct drm_fb_helper_surface_size *sizes);
201void vbox_fbdev_set_base(struct vbox_private *vbox, unsigned long gpu_addr); 204void vbox_fbdev_fini(struct vbox_private *vbox);
202 205
203struct vbox_bo { 206struct vbox_bo {
204 struct ttm_buffer_object bo; 207 struct ttm_buffer_object bo;
@@ -218,6 +221,11 @@ static inline struct vbox_bo *vbox_bo(struct ttm_buffer_object *bo)
218 221
219#define to_vbox_obj(x) container_of(x, struct vbox_gem_object, base) 222#define to_vbox_obj(x) container_of(x, struct vbox_gem_object, base)
220 223
224static inline u64 vbox_bo_gpu_offset(struct vbox_bo *bo)
225{
226 return bo->bo.offset;
227}
228
221int vbox_dumb_create(struct drm_file *file, 229int vbox_dumb_create(struct drm_file *file,
222 struct drm_device *dev, 230 struct drm_device *dev,
223 struct drm_mode_create_dumb *args); 231 struct drm_mode_create_dumb *args);
@@ -232,13 +240,13 @@ int vbox_dumb_mmap_offset(struct drm_file *file,
232int vbox_mm_init(struct vbox_private *vbox); 240int vbox_mm_init(struct vbox_private *vbox);
233void vbox_mm_fini(struct vbox_private *vbox); 241void vbox_mm_fini(struct vbox_private *vbox);
234 242
235int vbox_bo_create(struct drm_device *dev, int size, int align, 243int vbox_bo_create(struct vbox_private *vbox, int size, int align,
236 u32 flags, struct vbox_bo **pvboxbo); 244 u32 flags, struct vbox_bo **pvboxbo);
237 245
238int vbox_gem_create(struct drm_device *dev, 246int vbox_gem_create(struct vbox_private *vbox,
239 u32 size, bool iskernel, struct drm_gem_object **obj); 247 u32 size, bool iskernel, struct drm_gem_object **obj);
240 248
241int vbox_bo_pin(struct vbox_bo *bo, u32 pl_flag, u64 *gpu_addr); 249int vbox_bo_pin(struct vbox_bo *bo, u32 pl_flag);
242int vbox_bo_unpin(struct vbox_bo *bo); 250int vbox_bo_unpin(struct vbox_bo *bo);
243 251
244static inline int vbox_bo_reserve(struct vbox_bo *bo, bool no_wait) 252static inline int vbox_bo_reserve(struct vbox_bo *bo, bool no_wait)
@@ -262,6 +270,8 @@ static inline void vbox_bo_unreserve(struct vbox_bo *bo)
262void vbox_ttm_placement(struct vbox_bo *bo, int domain); 270void vbox_ttm_placement(struct vbox_bo *bo, int domain);
263int vbox_bo_push_sysram(struct vbox_bo *bo); 271int vbox_bo_push_sysram(struct vbox_bo *bo);
264int vbox_mmap(struct file *filp, struct vm_area_struct *vma); 272int vbox_mmap(struct file *filp, struct vm_area_struct *vma);
273void *vbox_bo_kmap(struct vbox_bo *bo);
274void vbox_bo_kunmap(struct vbox_bo *bo);
265 275
266/* vbox_prime.c */ 276/* vbox_prime.c */
267int vbox_gem_prime_pin(struct drm_gem_object *obj); 277int vbox_gem_prime_pin(struct drm_gem_object *obj);
diff --git a/drivers/staging/vboxvideo/vbox_fb.c b/drivers/staging/vboxvideo/vbox_fb.c
index 034f8ffa8f20..d1a1f74c8de3 100644
--- a/drivers/staging/vboxvideo/vbox_fb.c
+++ b/drivers/staging/vboxvideo/vbox_fb.c
@@ -66,38 +66,19 @@ static struct fb_ops vboxfb_ops = {
66 .fb_debug_leave = drm_fb_helper_debug_leave, 66 .fb_debug_leave = drm_fb_helper_debug_leave,
67}; 67};
68 68
69static int vboxfb_create_object(struct vbox_fbdev *fbdev, 69int vboxfb_create(struct drm_fb_helper *helper,
70 struct DRM_MODE_FB_CMD *mode_cmd, 70 struct drm_fb_helper_surface_size *sizes)
71 struct drm_gem_object **gobj_p)
72{ 71{
73 struct drm_device *dev = fbdev->helper.dev; 72 struct vbox_private *vbox =
74 u32 size; 73 container_of(helper, struct vbox_private, fb_helper);
75 struct drm_gem_object *gobj; 74 struct pci_dev *pdev = vbox->ddev.pdev;
76 u32 pitch = mode_cmd->pitches[0];
77 int ret;
78
79 size = pitch * mode_cmd->height;
80 ret = vbox_gem_create(dev, size, true, &gobj);
81 if (ret)
82 return ret;
83
84 *gobj_p = gobj;
85
86 return 0;
87}
88
89static int vboxfb_create(struct drm_fb_helper *helper,
90 struct drm_fb_helper_surface_size *sizes)
91{
92 struct vbox_fbdev *fbdev =
93 container_of(helper, struct vbox_fbdev, helper);
94 struct drm_device *dev = fbdev->helper.dev;
95 struct DRM_MODE_FB_CMD mode_cmd; 75 struct DRM_MODE_FB_CMD mode_cmd;
96 struct drm_framebuffer *fb; 76 struct drm_framebuffer *fb;
97 struct fb_info *info; 77 struct fb_info *info;
98 struct drm_gem_object *gobj; 78 struct drm_gem_object *gobj;
99 struct vbox_bo *bo; 79 struct vbox_bo *bo;
100 int size, ret; 80 int size, ret;
81 u64 gpu_addr;
101 u32 pitch; 82 u32 pitch;
102 83
103 mode_cmd.width = sizes->surface_width; 84 mode_cmd.width = sizes->surface_width;
@@ -109,45 +90,35 @@ static int vboxfb_create(struct drm_fb_helper *helper,
109 90
110 size = pitch * mode_cmd.height; 91 size = pitch * mode_cmd.height;
111 92
112 ret = vboxfb_create_object(fbdev, &mode_cmd, &gobj); 93 ret = vbox_gem_create(vbox, size, true, &gobj);
113 if (ret) { 94 if (ret) {
114 DRM_ERROR("failed to create fbcon backing object %d\n", ret); 95 DRM_ERROR("failed to create fbcon backing object %d\n", ret);
115 return ret; 96 return ret;
116 } 97 }
117 98
118 ret = vbox_framebuffer_init(dev, &fbdev->afb, &mode_cmd, gobj); 99 ret = vbox_framebuffer_init(vbox, &vbox->afb, &mode_cmd, gobj);
119 if (ret) 100 if (ret)
120 return ret; 101 return ret;
121 102
122 bo = gem_to_vbox_bo(gobj); 103 bo = gem_to_vbox_bo(gobj);
123 104
124 ret = vbox_bo_reserve(bo, false); 105 ret = vbox_bo_pin(bo, TTM_PL_FLAG_VRAM);
125 if (ret) 106 if (ret)
126 return ret; 107 return ret;
127 108
128 ret = vbox_bo_pin(bo, TTM_PL_FLAG_VRAM, NULL);
129 if (ret) {
130 vbox_bo_unreserve(bo);
131 return ret;
132 }
133
134 ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &bo->kmap);
135 vbox_bo_unreserve(bo);
136 if (ret) {
137 DRM_ERROR("failed to kmap fbcon\n");
138 return ret;
139 }
140
141 info = drm_fb_helper_alloc_fbi(helper); 109 info = drm_fb_helper_alloc_fbi(helper);
142 if (IS_ERR(info)) 110 if (IS_ERR(info))
143 return -PTR_ERR(info); 111 return PTR_ERR(info);
144 112
145 info->par = fbdev; 113 info->screen_size = size;
114 info->screen_base = (char __iomem *)vbox_bo_kmap(bo);
115 if (IS_ERR(info->screen_base))
116 return PTR_ERR(info->screen_base);
146 117
147 fbdev->size = size; 118 info->par = helper;
148 119
149 fb = &fbdev->afb.base; 120 fb = &vbox->afb.base;
150 fbdev->helper.fb = fb; 121 helper->fb = fb;
151 122
152 strcpy(info->fix.id, "vboxdrmfb"); 123 strcpy(info->fix.id, "vboxdrmfb");
153 124
@@ -162,15 +133,16 @@ static int vboxfb_create(struct drm_fb_helper *helper,
162 * This seems to be done for safety checking that the framebuffer 133 * This seems to be done for safety checking that the framebuffer
163 * is not registered twice by different drivers. 134 * is not registered twice by different drivers.
164 */ 135 */
165 info->apertures->ranges[0].base = pci_resource_start(dev->pdev, 0); 136 info->apertures->ranges[0].base = pci_resource_start(pdev, 0);
166 info->apertures->ranges[0].size = pci_resource_len(dev->pdev, 0); 137 info->apertures->ranges[0].size = pci_resource_len(pdev, 0);
167 138
168 drm_fb_helper_fill_fix(info, fb->pitches[0], fb->format->depth); 139 drm_fb_helper_fill_fix(info, fb->pitches[0], fb->format->depth);
169 drm_fb_helper_fill_var(info, &fbdev->helper, sizes->fb_width, 140 drm_fb_helper_fill_var(info, helper, sizes->fb_width,
170 sizes->fb_height); 141 sizes->fb_height);
171 142
172 info->screen_base = (char __iomem *)bo->kmap.virtual; 143 gpu_addr = vbox_bo_gpu_offset(bo);
173 info->screen_size = size; 144 info->fix.smem_start = info->apertures->ranges[0].base + gpu_addr;
145 info->fix.smem_len = vbox->available_vram_size - gpu_addr;
174 146
175#ifdef CONFIG_DRM_KMS_FB_HELPER 147#ifdef CONFIG_DRM_KMS_FB_HELPER
176 info->fbdefio = &vbox_defio; 148 info->fbdefio = &vbox_defio;
@@ -184,86 +156,30 @@ static int vboxfb_create(struct drm_fb_helper *helper,
184 return 0; 156 return 0;
185} 157}
186 158
187static struct drm_fb_helper_funcs vbox_fb_helper_funcs = { 159void vbox_fbdev_fini(struct vbox_private *vbox)
188 .fb_probe = vboxfb_create,
189};
190
191void vbox_fbdev_fini(struct drm_device *dev)
192{ 160{
193 struct vbox_private *vbox = dev->dev_private; 161 struct vbox_framebuffer *afb = &vbox->afb;
194 struct vbox_fbdev *fbdev = vbox->fbdev;
195 struct vbox_framebuffer *afb = &fbdev->afb;
196 162
197#ifdef CONFIG_DRM_KMS_FB_HELPER 163#ifdef CONFIG_DRM_KMS_FB_HELPER
198 if (fbdev->helper.fbdev && fbdev->helper.fbdev->fbdefio) 164 if (vbox->fb_helper.fbdev && vbox->fb_helper.fbdev->fbdefio)
199 fb_deferred_io_cleanup(fbdev->helper.fbdev); 165 fb_deferred_io_cleanup(vbox->fb_helper.fbdev);
200#endif 166#endif
201 167
202 drm_fb_helper_unregister_fbi(&fbdev->helper); 168 drm_fb_helper_unregister_fbi(&vbox->fb_helper);
203 169
204 if (afb->obj) { 170 if (afb->obj) {
205 struct vbox_bo *bo = gem_to_vbox_bo(afb->obj); 171 struct vbox_bo *bo = gem_to_vbox_bo(afb->obj);
206 172
207 if (!vbox_bo_reserve(bo, false)) { 173 vbox_bo_kunmap(bo);
208 if (bo->kmap.virtual) 174
209 ttm_bo_kunmap(&bo->kmap); 175 if (bo->pin_count)
210 /* 176 vbox_bo_unpin(bo);
211 * QXL does this, but is it really needed before 177
212 * freeing?
213 */
214 if (bo->pin_count)
215 vbox_bo_unpin(bo);
216 vbox_bo_unreserve(bo);
217 }
218 drm_gem_object_put_unlocked(afb->obj); 178 drm_gem_object_put_unlocked(afb->obj);
219 afb->obj = NULL; 179 afb->obj = NULL;
220 } 180 }
221 drm_fb_helper_fini(&fbdev->helper); 181 drm_fb_helper_fini(&vbox->fb_helper);
222 182
223 drm_framebuffer_unregister_private(&afb->base); 183 drm_framebuffer_unregister_private(&afb->base);
224 drm_framebuffer_cleanup(&afb->base); 184 drm_framebuffer_cleanup(&afb->base);
225} 185}
226
227int vbox_fbdev_init(struct drm_device *dev)
228{
229 struct vbox_private *vbox = dev->dev_private;
230 struct vbox_fbdev *fbdev;
231 int ret;
232
233 fbdev = devm_kzalloc(dev->dev, sizeof(*fbdev), GFP_KERNEL);
234 if (!fbdev)
235 return -ENOMEM;
236
237 vbox->fbdev = fbdev;
238 spin_lock_init(&fbdev->dirty_lock);
239
240 drm_fb_helper_prepare(dev, &fbdev->helper, &vbox_fb_helper_funcs);
241 ret = drm_fb_helper_init(dev, &fbdev->helper, vbox->num_crtcs);
242 if (ret)
243 return ret;
244
245 ret = drm_fb_helper_single_add_all_connectors(&fbdev->helper);
246 if (ret)
247 goto err_fini;
248
249 /* disable all the possible outputs/crtcs before entering KMS mode */
250 drm_helper_disable_unused_functions(dev);
251
252 ret = drm_fb_helper_initial_config(&fbdev->helper, 32);
253 if (ret)
254 goto err_fini;
255
256 return 0;
257
258err_fini:
259 drm_fb_helper_fini(&fbdev->helper);
260 return ret;
261}
262
263void vbox_fbdev_set_base(struct vbox_private *vbox, unsigned long gpu_addr)
264{
265 struct fb_info *fbdev = vbox->fbdev->helper.fbdev;
266
267 fbdev->fix.smem_start = fbdev->apertures->ranges[0].base + gpu_addr;
268 fbdev->fix.smem_len = vbox->available_vram_size - gpu_addr;
269}
diff --git a/drivers/staging/vboxvideo/vbox_irq.c b/drivers/staging/vboxvideo/vbox_irq.c
index 74abdf02d9fd..09f858ec1369 100644
--- a/drivers/staging/vboxvideo/vbox_irq.c
+++ b/drivers/staging/vboxvideo/vbox_irq.c
@@ -123,7 +123,7 @@ static void validate_or_set_position_hints(struct vbox_private *vbox)
123 */ 123 */
124static void vbox_update_mode_hints(struct vbox_private *vbox) 124static void vbox_update_mode_hints(struct vbox_private *vbox)
125{ 125{
126 struct drm_device *dev = vbox->dev; 126 struct drm_device *dev = &vbox->ddev;
127 struct drm_connector *connector; 127 struct drm_connector *connector;
128 struct vbox_connector *vbox_conn; 128 struct vbox_connector *vbox_conn;
129 struct vbva_modehint *hints; 129 struct vbva_modehint *hints;
@@ -179,7 +179,7 @@ static void vbox_hotplug_worker(struct work_struct *work)
179 hotplug_work); 179 hotplug_work);
180 180
181 vbox_update_mode_hints(vbox); 181 vbox_update_mode_hints(vbox);
182 drm_kms_helper_hotplug_event(vbox->dev); 182 drm_kms_helper_hotplug_event(&vbox->ddev);
183} 183}
184 184
185int vbox_irq_init(struct vbox_private *vbox) 185int vbox_irq_init(struct vbox_private *vbox)
@@ -187,11 +187,11 @@ int vbox_irq_init(struct vbox_private *vbox)
187 INIT_WORK(&vbox->hotplug_work, vbox_hotplug_worker); 187 INIT_WORK(&vbox->hotplug_work, vbox_hotplug_worker);
188 vbox_update_mode_hints(vbox); 188 vbox_update_mode_hints(vbox);
189 189
190 return drm_irq_install(vbox->dev, vbox->dev->pdev->irq); 190 return drm_irq_install(&vbox->ddev, vbox->ddev.pdev->irq);
191} 191}
192 192
193void vbox_irq_fini(struct vbox_private *vbox) 193void vbox_irq_fini(struct vbox_private *vbox)
194{ 194{
195 drm_irq_uninstall(vbox->dev); 195 drm_irq_uninstall(&vbox->ddev);
196 flush_work(&vbox->hotplug_work); 196 flush_work(&vbox->hotplug_work);
197} 197}
diff --git a/drivers/staging/vboxvideo/vbox_main.c b/drivers/staging/vboxvideo/vbox_main.c
index 429f6a453619..7466c1103ff6 100644
--- a/drivers/staging/vboxvideo/vbox_main.c
+++ b/drivers/staging/vboxvideo/vbox_main.c
@@ -102,24 +102,30 @@ void vbox_framebuffer_dirty_rectangles(struct drm_framebuffer *fb,
102 unsigned int num_rects) 102 unsigned int num_rects)
103{ 103{
104 struct vbox_private *vbox = fb->dev->dev_private; 104 struct vbox_private *vbox = fb->dev->dev_private;
105 struct drm_display_mode *mode;
105 struct drm_crtc *crtc; 106 struct drm_crtc *crtc;
107 int crtc_x, crtc_y;
106 unsigned int i; 108 unsigned int i;
107 109
108 mutex_lock(&vbox->hw_mutex); 110 mutex_lock(&vbox->hw_mutex);
109 list_for_each_entry(crtc, &fb->dev->mode_config.crtc_list, head) { 111 list_for_each_entry(crtc, &fb->dev->mode_config.crtc_list, head) {
110 if (CRTC_FB(crtc) != fb) 112 if (crtc->primary->state->fb != fb)
111 continue; 113 continue;
112 114
115 mode = &crtc->state->mode;
116 crtc_x = crtc->primary->state->src_x >> 16;
117 crtc_y = crtc->primary->state->src_y >> 16;
118
113 vbox_enable_accel(vbox); 119 vbox_enable_accel(vbox);
114 120
115 for (i = 0; i < num_rects; ++i) { 121 for (i = 0; i < num_rects; ++i) {
116 struct vbva_cmd_hdr cmd_hdr; 122 struct vbva_cmd_hdr cmd_hdr;
117 unsigned int crtc_id = to_vbox_crtc(crtc)->crtc_id; 123 unsigned int crtc_id = to_vbox_crtc(crtc)->crtc_id;
118 124
119 if ((rects[i].x1 > crtc->x + crtc->hwmode.hdisplay) || 125 if ((rects[i].x1 > crtc_x + mode->hdisplay) ||
120 (rects[i].y1 > crtc->y + crtc->hwmode.vdisplay) || 126 (rects[i].y1 > crtc_y + mode->vdisplay) ||
121 (rects[i].x2 < crtc->x) || 127 (rects[i].x2 < crtc_x) ||
122 (rects[i].y2 < crtc->y)) 128 (rects[i].y2 < crtc_y))
123 continue; 129 continue;
124 130
125 cmd_hdr.x = (s16)rects[i].x1; 131 cmd_hdr.x = (s16)rects[i].x1;
@@ -155,16 +161,16 @@ static const struct drm_framebuffer_funcs vbox_fb_funcs = {
155 .dirty = vbox_user_framebuffer_dirty, 161 .dirty = vbox_user_framebuffer_dirty,
156}; 162};
157 163
158int vbox_framebuffer_init(struct drm_device *dev, 164int vbox_framebuffer_init(struct vbox_private *vbox,
159 struct vbox_framebuffer *vbox_fb, 165 struct vbox_framebuffer *vbox_fb,
160 const struct DRM_MODE_FB_CMD *mode_cmd, 166 const struct DRM_MODE_FB_CMD *mode_cmd,
161 struct drm_gem_object *obj) 167 struct drm_gem_object *obj)
162{ 168{
163 int ret; 169 int ret;
164 170
165 drm_helper_mode_fill_fb_struct(dev, &vbox_fb->base, mode_cmd); 171 drm_helper_mode_fill_fb_struct(&vbox->ddev, &vbox_fb->base, mode_cmd);
166 vbox_fb->obj = obj; 172 vbox_fb->obj = obj;
167 ret = drm_framebuffer_init(dev, &vbox_fb->base, &vbox_fb_funcs); 173 ret = drm_framebuffer_init(&vbox->ddev, &vbox_fb->base, &vbox_fb_funcs);
168 if (ret) { 174 if (ret) {
169 DRM_ERROR("framebuffer init failed %d\n", ret); 175 DRM_ERROR("framebuffer init failed %d\n", ret);
170 return ret; 176 return ret;
@@ -173,45 +179,11 @@ int vbox_framebuffer_init(struct drm_device *dev,
173 return 0; 179 return 0;
174} 180}
175 181
176static struct drm_framebuffer *vbox_user_framebuffer_create(
177 struct drm_device *dev,
178 struct drm_file *filp,
179 const struct drm_mode_fb_cmd2 *mode_cmd)
180{
181 struct drm_gem_object *obj;
182 struct vbox_framebuffer *vbox_fb;
183 int ret = -ENOMEM;
184
185 obj = drm_gem_object_lookup(filp, mode_cmd->handles[0]);
186 if (!obj)
187 return ERR_PTR(-ENOENT);
188
189 vbox_fb = kzalloc(sizeof(*vbox_fb), GFP_KERNEL);
190 if (!vbox_fb)
191 goto err_unref_obj;
192
193 ret = vbox_framebuffer_init(dev, vbox_fb, mode_cmd, obj);
194 if (ret)
195 goto err_free_vbox_fb;
196
197 return &vbox_fb->base;
198
199err_free_vbox_fb:
200 kfree(vbox_fb);
201err_unref_obj:
202 drm_gem_object_put_unlocked(obj);
203 return ERR_PTR(ret);
204}
205
206static const struct drm_mode_config_funcs vbox_mode_funcs = {
207 .fb_create = vbox_user_framebuffer_create,
208};
209
210static int vbox_accel_init(struct vbox_private *vbox) 182static int vbox_accel_init(struct vbox_private *vbox)
211{ 183{
212 unsigned int i; 184 unsigned int i;
213 185
214 vbox->vbva_info = devm_kcalloc(vbox->dev->dev, vbox->num_crtcs, 186 vbox->vbva_info = devm_kcalloc(vbox->ddev.dev, vbox->num_crtcs,
215 sizeof(*vbox->vbva_info), GFP_KERNEL); 187 sizeof(*vbox->vbva_info), GFP_KERNEL);
216 if (!vbox->vbva_info) 188 if (!vbox->vbva_info)
217 return -ENOMEM; 189 return -ENOMEM;
@@ -219,7 +191,7 @@ static int vbox_accel_init(struct vbox_private *vbox)
219 /* Take a command buffer for each screen from the end of usable VRAM. */ 191 /* Take a command buffer for each screen from the end of usable VRAM. */
220 vbox->available_vram_size -= vbox->num_crtcs * VBVA_MIN_BUFFER_SIZE; 192 vbox->available_vram_size -= vbox->num_crtcs * VBVA_MIN_BUFFER_SIZE;
221 193
222 vbox->vbva_buffers = pci_iomap_range(vbox->dev->pdev, 0, 194 vbox->vbva_buffers = pci_iomap_range(vbox->ddev.pdev, 0,
223 vbox->available_vram_size, 195 vbox->available_vram_size,
224 vbox->num_crtcs * 196 vbox->num_crtcs *
225 VBVA_MIN_BUFFER_SIZE); 197 VBVA_MIN_BUFFER_SIZE);
@@ -238,7 +210,7 @@ static int vbox_accel_init(struct vbox_private *vbox)
238static void vbox_accel_fini(struct vbox_private *vbox) 210static void vbox_accel_fini(struct vbox_private *vbox)
239{ 211{
240 vbox_disable_accel(vbox); 212 vbox_disable_accel(vbox);
241 pci_iounmap(vbox->dev->pdev, vbox->vbva_buffers); 213 pci_iounmap(vbox->ddev.pdev, vbox->vbva_buffers);
242} 214}
243 215
244/** Do we support the 4.3 plus mode hint reporting interface? */ 216/** Do we support the 4.3 plus mode hint reporting interface? */
@@ -262,7 +234,7 @@ static bool have_hgsmi_mode_hints(struct vbox_private *vbox)
262 return have_hints == VINF_SUCCESS && have_cursor == VINF_SUCCESS; 234 return have_hints == VINF_SUCCESS && have_cursor == VINF_SUCCESS;
263} 235}
264 236
265static bool vbox_check_supported(u16 id) 237bool vbox_check_supported(u16 id)
266{ 238{
267 u16 dispi_id; 239 u16 dispi_id;
268 240
@@ -276,7 +248,7 @@ static bool vbox_check_supported(u16 id)
276 * Set up our heaps and data exchange buffers in VRAM before handing the rest 248 * Set up our heaps and data exchange buffers in VRAM before handing the rest
277 * to the memory manager. 249 * to the memory manager.
278 */ 250 */
279static int vbox_hw_init(struct vbox_private *vbox) 251int vbox_hw_init(struct vbox_private *vbox)
280{ 252{
281 int ret = -ENOMEM; 253 int ret = -ENOMEM;
282 254
@@ -287,7 +259,7 @@ static int vbox_hw_init(struct vbox_private *vbox)
287 259
288 /* Map guest-heap at end of vram */ 260 /* Map guest-heap at end of vram */
289 vbox->guest_heap = 261 vbox->guest_heap =
290 pci_iomap_range(vbox->dev->pdev, 0, GUEST_HEAP_OFFSET(vbox), 262 pci_iomap_range(vbox->ddev.pdev, 0, GUEST_HEAP_OFFSET(vbox),
291 GUEST_HEAP_SIZE); 263 GUEST_HEAP_SIZE);
292 if (!vbox->guest_heap) 264 if (!vbox->guest_heap)
293 return -ENOMEM; 265 return -ENOMEM;
@@ -322,7 +294,7 @@ static int vbox_hw_init(struct vbox_private *vbox)
322 goto err_destroy_guest_pool; 294 goto err_destroy_guest_pool;
323 } 295 }
324 296
325 vbox->last_mode_hints = devm_kcalloc(vbox->dev->dev, vbox->num_crtcs, 297 vbox->last_mode_hints = devm_kcalloc(vbox->ddev.dev, vbox->num_crtcs,
326 sizeof(struct vbva_modehint), 298 sizeof(struct vbva_modehint),
327 GFP_KERNEL); 299 GFP_KERNEL);
328 if (!vbox->last_mode_hints) { 300 if (!vbox->last_mode_hints) {
@@ -339,102 +311,18 @@ static int vbox_hw_init(struct vbox_private *vbox)
339err_destroy_guest_pool: 311err_destroy_guest_pool:
340 gen_pool_destroy(vbox->guest_pool); 312 gen_pool_destroy(vbox->guest_pool);
341err_unmap_guest_heap: 313err_unmap_guest_heap:
342 pci_iounmap(vbox->dev->pdev, vbox->guest_heap); 314 pci_iounmap(vbox->ddev.pdev, vbox->guest_heap);
343 return ret; 315 return ret;
344} 316}
345 317
346static void vbox_hw_fini(struct vbox_private *vbox) 318void vbox_hw_fini(struct vbox_private *vbox)
347{ 319{
348 vbox_accel_fini(vbox); 320 vbox_accel_fini(vbox);
349 gen_pool_destroy(vbox->guest_pool); 321 gen_pool_destroy(vbox->guest_pool);
350 pci_iounmap(vbox->dev->pdev, vbox->guest_heap); 322 pci_iounmap(vbox->ddev.pdev, vbox->guest_heap);
351}
352
353int vbox_driver_load(struct drm_device *dev)
354{
355 struct vbox_private *vbox;
356 int ret = 0;
357
358 if (!vbox_check_supported(VBE_DISPI_ID_HGSMI))
359 return -ENODEV;
360
361 vbox = devm_kzalloc(dev->dev, sizeof(*vbox), GFP_KERNEL);
362 if (!vbox)
363 return -ENOMEM;
364
365 dev->dev_private = vbox;
366 vbox->dev = dev;
367
368 mutex_init(&vbox->hw_mutex);
369
370 ret = vbox_hw_init(vbox);
371 if (ret)
372 return ret;
373
374 ret = vbox_mm_init(vbox);
375 if (ret)
376 goto err_hw_fini;
377
378 drm_mode_config_init(dev);
379
380 dev->mode_config.funcs = (void *)&vbox_mode_funcs;
381 dev->mode_config.min_width = 64;
382 dev->mode_config.min_height = 64;
383 dev->mode_config.preferred_depth = 24;
384 dev->mode_config.max_width = VBE_DISPI_MAX_XRES;
385 dev->mode_config.max_height = VBE_DISPI_MAX_YRES;
386
387 ret = vbox_mode_init(dev);
388 if (ret)
389 goto err_drm_mode_cleanup;
390
391 ret = vbox_irq_init(vbox);
392 if (ret)
393 goto err_mode_fini;
394
395 ret = vbox_fbdev_init(dev);
396 if (ret)
397 goto err_irq_fini;
398
399 return 0;
400
401err_irq_fini:
402 vbox_irq_fini(vbox);
403err_mode_fini:
404 vbox_mode_fini(dev);
405err_drm_mode_cleanup:
406 drm_mode_config_cleanup(dev);
407 vbox_mm_fini(vbox);
408err_hw_fini:
409 vbox_hw_fini(vbox);
410 return ret;
411}
412
413void vbox_driver_unload(struct drm_device *dev)
414{
415 struct vbox_private *vbox = dev->dev_private;
416
417 vbox_fbdev_fini(dev);
418 vbox_irq_fini(vbox);
419 vbox_mode_fini(dev);
420 drm_mode_config_cleanup(dev);
421 vbox_mm_fini(vbox);
422 vbox_hw_fini(vbox);
423} 323}
424 324
425/** 325int vbox_gem_create(struct vbox_private *vbox,
426 * @note this is described in the DRM framework documentation. AST does not
427 * have it, but we get an oops on driver unload if it is not present.
428 */
429void vbox_driver_lastclose(struct drm_device *dev)
430{
431 struct vbox_private *vbox = dev->dev_private;
432
433 if (vbox->fbdev)
434 drm_fb_helper_restore_fbdev_mode_unlocked(&vbox->fbdev->helper);
435}
436
437int vbox_gem_create(struct drm_device *dev,
438 u32 size, bool iskernel, struct drm_gem_object **obj) 326 u32 size, bool iskernel, struct drm_gem_object **obj)
439{ 327{
440 struct vbox_bo *vboxbo; 328 struct vbox_bo *vboxbo;
@@ -446,7 +334,7 @@ int vbox_gem_create(struct drm_device *dev,
446 if (size == 0) 334 if (size == 0)
447 return -EINVAL; 335 return -EINVAL;
448 336
449 ret = vbox_bo_create(dev, size, 0, 0, &vboxbo); 337 ret = vbox_bo_create(vbox, size, 0, 0, &vboxbo);
450 if (ret) { 338 if (ret) {
451 if (ret != -ERESTARTSYS) 339 if (ret != -ERESTARTSYS)
452 DRM_ERROR("failed to allocate GEM object\n"); 340 DRM_ERROR("failed to allocate GEM object\n");
@@ -461,14 +349,16 @@ int vbox_gem_create(struct drm_device *dev,
461int vbox_dumb_create(struct drm_file *file, 349int vbox_dumb_create(struct drm_file *file,
462 struct drm_device *dev, struct drm_mode_create_dumb *args) 350 struct drm_device *dev, struct drm_mode_create_dumb *args)
463{ 351{
464 int ret; 352 struct vbox_private *vbox =
353 container_of(dev, struct vbox_private, ddev);
465 struct drm_gem_object *gobj; 354 struct drm_gem_object *gobj;
466 u32 handle; 355 u32 handle;
356 int ret;
467 357
468 args->pitch = args->width * ((args->bpp + 7) / 8); 358 args->pitch = args->width * ((args->bpp + 7) / 8);
469 args->size = args->pitch * args->height; 359 args->size = args->pitch * args->height;
470 360
471 ret = vbox_gem_create(dev, args->size, false, &gobj); 361 ret = vbox_gem_create(vbox, args->size, false, &gobj);
472 if (ret) 362 if (ret)
473 return ret; 363 return ret;
474 364
@@ -482,24 +372,11 @@ int vbox_dumb_create(struct drm_file *file,
482 return 0; 372 return 0;
483} 373}
484 374
485static void vbox_bo_unref(struct vbox_bo **bo)
486{
487 struct ttm_buffer_object *tbo;
488
489 if ((*bo) == NULL)
490 return;
491
492 tbo = &((*bo)->bo);
493 ttm_bo_unref(&tbo);
494 if (!tbo)
495 *bo = NULL;
496}
497
498void vbox_gem_free_object(struct drm_gem_object *obj) 375void vbox_gem_free_object(struct drm_gem_object *obj)
499{ 376{
500 struct vbox_bo *vbox_bo = gem_to_vbox_bo(obj); 377 struct vbox_bo *vbox_bo = gem_to_vbox_bo(obj);
501 378
502 vbox_bo_unref(&vbox_bo); 379 ttm_bo_put(&vbox_bo->bo);
503} 380}
504 381
505static inline u64 vbox_bo_mmap_offset(struct vbox_bo *bo) 382static inline u64 vbox_bo_mmap_offset(struct vbox_bo *bo)
diff --git a/drivers/staging/vboxvideo/vbox_mode.c b/drivers/staging/vboxvideo/vbox_mode.c
index 79836c8fb909..6acc965247ff 100644
--- a/drivers/staging/vboxvideo/vbox_mode.c
+++ b/drivers/staging/vboxvideo/vbox_mode.c
@@ -32,25 +32,22 @@
32 * Hans de Goede <hdegoede@redhat.com> 32 * Hans de Goede <hdegoede@redhat.com>
33 */ 33 */
34#include <linux/export.h> 34#include <linux/export.h>
35#include <drm/drm_atomic.h>
35#include <drm/drm_crtc_helper.h> 36#include <drm/drm_crtc_helper.h>
36#include <drm/drm_plane_helper.h> 37#include <drm/drm_plane_helper.h>
38#include <drm/drm_atomic_helper.h>
37 39
38#include "vbox_drv.h" 40#include "vbox_drv.h"
39#include "vboxvideo.h" 41#include "vboxvideo.h"
40#include "hgsmi_channels.h" 42#include "hgsmi_channels.h"
41 43
42static int vbox_cursor_set2(struct drm_crtc *crtc, struct drm_file *file_priv,
43 u32 handle, u32 width, u32 height,
44 s32 hot_x, s32 hot_y);
45static int vbox_cursor_move(struct drm_crtc *crtc, int x, int y);
46
47/** 44/**
48 * Set a graphics mode. Poke any required values into registers, do an HGSMI 45 * Set a graphics mode. Poke any required values into registers, do an HGSMI
49 * mode set and tell the host we support advanced graphics functions. 46 * mode set and tell the host we support advanced graphics functions.
50 */ 47 */
51static void vbox_do_modeset(struct drm_crtc *crtc, 48static void vbox_do_modeset(struct drm_crtc *crtc)
52 const struct drm_display_mode *mode)
53{ 49{
50 struct drm_framebuffer *fb = crtc->primary->state->fb;
54 struct vbox_crtc *vbox_crtc = to_vbox_crtc(crtc); 51 struct vbox_crtc *vbox_crtc = to_vbox_crtc(crtc);
55 struct vbox_private *vbox; 52 struct vbox_private *vbox;
56 int width, height, bpp, pitch; 53 int width, height, bpp, pitch;
@@ -58,12 +55,12 @@ static void vbox_do_modeset(struct drm_crtc *crtc,
58 s32 x_offset, y_offset; 55 s32 x_offset, y_offset;
59 56
60 vbox = crtc->dev->dev_private; 57 vbox = crtc->dev->dev_private;
61 width = mode->hdisplay ? mode->hdisplay : 640; 58 width = vbox_crtc->width ? vbox_crtc->width : 640;
62 height = mode->vdisplay ? mode->vdisplay : 480; 59 height = vbox_crtc->height ? vbox_crtc->height : 480;
63 bpp = crtc->enabled ? CRTC_FB(crtc)->format->cpp[0] * 8 : 32; 60 bpp = fb ? fb->format->cpp[0] * 8 : 32;
64 pitch = crtc->enabled ? CRTC_FB(crtc)->pitches[0] : width * bpp / 8; 61 pitch = fb ? fb->pitches[0] : width * bpp / 8;
65 x_offset = vbox->single_framebuffer ? crtc->x : vbox_crtc->x_hint; 62 x_offset = vbox->single_framebuffer ? vbox_crtc->x : vbox_crtc->x_hint;
66 y_offset = vbox->single_framebuffer ? crtc->y : vbox_crtc->y_hint; 63 y_offset = vbox->single_framebuffer ? vbox_crtc->y : vbox_crtc->y_hint;
67 64
68 /* 65 /*
69 * This is the old way of setting graphics modes. It assumed one screen 66 * This is the old way of setting graphics modes. It assumed one screen
@@ -71,31 +68,29 @@ static void vbox_do_modeset(struct drm_crtc *crtc,
71 * VirtualBox, certain parts of the code still assume that the first 68 * VirtualBox, certain parts of the code still assume that the first
72 * screen is programmed this way, so try to fake it. 69 * screen is programmed this way, so try to fake it.
73 */ 70 */
74 if (vbox_crtc->crtc_id == 0 && crtc->enabled && 71 if (vbox_crtc->crtc_id == 0 && fb &&
75 vbox_crtc->fb_offset / pitch < 0xffff - crtc->y && 72 vbox_crtc->fb_offset / pitch < 0xffff - crtc->y &&
76 vbox_crtc->fb_offset % (bpp / 8) == 0) { 73 vbox_crtc->fb_offset % (bpp / 8) == 0) {
77 vbox_write_ioport(VBE_DISPI_INDEX_XRES, width); 74 vbox_write_ioport(VBE_DISPI_INDEX_XRES, width);
78 vbox_write_ioport(VBE_DISPI_INDEX_YRES, height); 75 vbox_write_ioport(VBE_DISPI_INDEX_YRES, height);
79 vbox_write_ioport(VBE_DISPI_INDEX_VIRT_WIDTH, pitch * 8 / bpp); 76 vbox_write_ioport(VBE_DISPI_INDEX_VIRT_WIDTH, pitch * 8 / bpp);
80 vbox_write_ioport(VBE_DISPI_INDEX_BPP, 77 vbox_write_ioport(VBE_DISPI_INDEX_BPP, bpp);
81 CRTC_FB(crtc)->format->cpp[0] * 8);
82 vbox_write_ioport(VBE_DISPI_INDEX_ENABLE, VBE_DISPI_ENABLED); 78 vbox_write_ioport(VBE_DISPI_INDEX_ENABLE, VBE_DISPI_ENABLED);
83 vbox_write_ioport( 79 vbox_write_ioport(
84 VBE_DISPI_INDEX_X_OFFSET, 80 VBE_DISPI_INDEX_X_OFFSET,
85 vbox_crtc->fb_offset % pitch / bpp * 8 + crtc->x); 81 vbox_crtc->fb_offset % pitch / bpp * 8 + vbox_crtc->x);
86 vbox_write_ioport(VBE_DISPI_INDEX_Y_OFFSET, 82 vbox_write_ioport(VBE_DISPI_INDEX_Y_OFFSET,
87 vbox_crtc->fb_offset / pitch + crtc->y); 83 vbox_crtc->fb_offset / pitch + vbox_crtc->y);
88 } 84 }
89 85
90 flags = VBVA_SCREEN_F_ACTIVE; 86 flags = VBVA_SCREEN_F_ACTIVE;
91 flags |= (crtc->enabled && !vbox_crtc->blanked) ? 87 flags |= (fb && crtc->state->active) ? 0 : VBVA_SCREEN_F_BLANK;
92 0 : VBVA_SCREEN_F_BLANK;
93 flags |= vbox_crtc->disconnected ? VBVA_SCREEN_F_DISABLED : 0; 88 flags |= vbox_crtc->disconnected ? VBVA_SCREEN_F_DISABLED : 0;
94 hgsmi_process_display_info(vbox->guest_pool, vbox_crtc->crtc_id, 89 hgsmi_process_display_info(vbox->guest_pool, vbox_crtc->crtc_id,
95 x_offset, y_offset, 90 x_offset, y_offset,
96 crtc->x * bpp / 8 + crtc->y * pitch, 91 vbox_crtc->x * bpp / 8 +
97 pitch, width, height, 92 vbox_crtc->y * pitch,
98 vbox_crtc->blanked ? 0 : bpp, flags); 93 pitch, width, height, bpp, flags);
99} 94}
100 95
101static int vbox_set_view(struct drm_crtc *crtc) 96static int vbox_set_view(struct drm_crtc *crtc)
@@ -132,34 +127,6 @@ static int vbox_set_view(struct drm_crtc *crtc)
132 return 0; 127 return 0;
133} 128}
134 129
135static void vbox_crtc_dpms(struct drm_crtc *crtc, int mode)
136{
137 struct vbox_crtc *vbox_crtc = to_vbox_crtc(crtc);
138 struct vbox_private *vbox = crtc->dev->dev_private;
139
140 switch (mode) {
141 case DRM_MODE_DPMS_ON:
142 vbox_crtc->blanked = false;
143 break;
144 case DRM_MODE_DPMS_STANDBY:
145 case DRM_MODE_DPMS_SUSPEND:
146 case DRM_MODE_DPMS_OFF:
147 vbox_crtc->blanked = true;
148 break;
149 }
150
151 mutex_lock(&vbox->hw_mutex);
152 vbox_do_modeset(crtc, &crtc->hwmode);
153 mutex_unlock(&vbox->hw_mutex);
154}
155
156static bool vbox_crtc_mode_fixup(struct drm_crtc *crtc,
157 const struct drm_display_mode *mode,
158 struct drm_display_mode *adjusted_mode)
159{
160 return true;
161}
162
163/* 130/*
164 * Try to map the layout of virtual screens to the range of the input device. 131 * Try to map the layout of virtual screens to the range of the input device.
165 * Return true if we need to re-set the crtc modes due to screen offset 132 * Return true if we need to re-set the crtc modes due to screen offset
@@ -169,7 +136,7 @@ static bool vbox_set_up_input_mapping(struct vbox_private *vbox)
169{ 136{
170 struct drm_crtc *crtci; 137 struct drm_crtc *crtci;
171 struct drm_connector *connectori; 138 struct drm_connector *connectori;
172 struct drm_framebuffer *fb1 = NULL; 139 struct drm_framebuffer *fb, *fb1 = NULL;
173 bool single_framebuffer = true; 140 bool single_framebuffer = true;
174 bool old_single_framebuffer = vbox->single_framebuffer; 141 bool old_single_framebuffer = vbox->single_framebuffer;
175 u16 width = 0, height = 0; 142 u16 width = 0, height = 0;
@@ -179,30 +146,30 @@ static bool vbox_set_up_input_mapping(struct vbox_private *vbox)
179 * If so then screen layout can be deduced from the crtc offsets. 146 * If so then screen layout can be deduced from the crtc offsets.
180 * Same fall-back if this is the fbdev frame-buffer. 147 * Same fall-back if this is the fbdev frame-buffer.
181 */ 148 */
182 list_for_each_entry(crtci, &vbox->dev->mode_config.crtc_list, head) { 149 list_for_each_entry(crtci, &vbox->ddev.mode_config.crtc_list, head) {
150 fb = crtci->primary->state->fb;
151 if (!fb)
152 continue;
153
183 if (!fb1) { 154 if (!fb1) {
184 fb1 = CRTC_FB(crtci); 155 fb1 = fb;
185 if (to_vbox_framebuffer(fb1) == &vbox->fbdev->afb) 156 if (to_vbox_framebuffer(fb1) == &vbox->afb)
186 break; 157 break;
187 } else if (CRTC_FB(crtci) && fb1 != CRTC_FB(crtci)) { 158 } else if (fb != fb1) {
188 single_framebuffer = false; 159 single_framebuffer = false;
189 } 160 }
190 } 161 }
191 if (single_framebuffer) { 162 if (!fb1)
192 list_for_each_entry(crtci, &vbox->dev->mode_config.crtc_list, 163 return false;
193 head) {
194 if (to_vbox_crtc(crtci)->crtc_id != 0)
195 continue;
196 164
197 vbox->single_framebuffer = true; 165 if (single_framebuffer) {
198 vbox->input_mapping_width = CRTC_FB(crtci)->width; 166 vbox->single_framebuffer = true;
199 vbox->input_mapping_height = CRTC_FB(crtci)->height; 167 vbox->input_mapping_width = fb1->width;
200 return old_single_framebuffer != 168 vbox->input_mapping_height = fb1->height;
201 vbox->single_framebuffer; 169 return old_single_framebuffer != vbox->single_framebuffer;
202 }
203 } 170 }
204 /* Otherwise calculate the total span of all screens. */ 171 /* Otherwise calculate the total span of all screens. */
205 list_for_each_entry(connectori, &vbox->dev->mode_config.connector_list, 172 list_for_each_entry(connectori, &vbox->ddev.mode_config.connector_list,
206 head) { 173 head) {
207 struct vbox_connector *vbox_connector = 174 struct vbox_connector *vbox_connector =
208 to_vbox_connector(connectori); 175 to_vbox_connector(connectori);
@@ -221,180 +188,462 @@ static bool vbox_set_up_input_mapping(struct vbox_private *vbox)
221 return old_single_framebuffer != vbox->single_framebuffer; 188 return old_single_framebuffer != vbox->single_framebuffer;
222} 189}
223 190
224static int vbox_crtc_do_set_base(struct drm_crtc *crtc, 191static void vbox_crtc_set_base_and_mode(struct drm_crtc *crtc,
225 struct drm_framebuffer *old_fb, 192 struct drm_framebuffer *fb,
226 struct drm_framebuffer *new_fb, 193 struct drm_display_mode *mode,
227 int x, int y) 194 int x, int y)
228{ 195{
196 struct vbox_bo *bo = gem_to_vbox_bo(to_vbox_framebuffer(fb)->obj);
229 struct vbox_private *vbox = crtc->dev->dev_private; 197 struct vbox_private *vbox = crtc->dev->dev_private;
230 struct vbox_crtc *vbox_crtc = to_vbox_crtc(crtc); 198 struct vbox_crtc *vbox_crtc = to_vbox_crtc(crtc);
231 struct drm_gem_object *obj; 199 bool needs_modeset = drm_atomic_crtc_needs_modeset(crtc->state);
232 struct vbox_framebuffer *vbox_fb; 200
233 struct vbox_bo *bo; 201 mutex_lock(&vbox->hw_mutex);
234 int ret;
235 u64 gpu_addr;
236
237 /* Unpin the previous fb. */
238 if (old_fb) {
239 vbox_fb = to_vbox_framebuffer(old_fb);
240 obj = vbox_fb->obj;
241 bo = gem_to_vbox_bo(obj);
242 ret = vbox_bo_reserve(bo, false);
243 if (ret)
244 return ret;
245 202
246 vbox_bo_unpin(bo); 203 vbox_crtc->width = mode->hdisplay;
247 vbox_bo_unreserve(bo); 204 vbox_crtc->height = mode->vdisplay;
205 vbox_crtc->x = x;
206 vbox_crtc->y = y;
207 vbox_crtc->fb_offset = vbox_bo_gpu_offset(bo);
208
209 /* vbox_do_modeset() checks vbox->single_framebuffer so update it now */
210 if (needs_modeset && vbox_set_up_input_mapping(vbox)) {
211 struct drm_crtc *crtci;
212
213 list_for_each_entry(crtci, &vbox->ddev.mode_config.crtc_list,
214 head) {
215 if (crtci == crtc)
216 continue;
217 vbox_do_modeset(crtci);
218 }
248 } 219 }
249 220
250 vbox_fb = to_vbox_framebuffer(new_fb); 221 vbox_set_view(crtc);
251 obj = vbox_fb->obj; 222 vbox_do_modeset(crtc);
252 bo = gem_to_vbox_bo(obj);
253 223
254 ret = vbox_bo_reserve(bo, false); 224 if (needs_modeset)
255 if (ret) 225 hgsmi_update_input_mapping(vbox->guest_pool, 0, 0,
256 return ret; 226 vbox->input_mapping_width,
227 vbox->input_mapping_height);
257 228
258 ret = vbox_bo_pin(bo, TTM_PL_FLAG_VRAM, &gpu_addr); 229 mutex_unlock(&vbox->hw_mutex);
259 if (ret) { 230}
260 vbox_bo_unreserve(bo); 231
261 return ret; 232static void vbox_crtc_atomic_enable(struct drm_crtc *crtc,
233 struct drm_crtc_state *old_crtc_state)
234{
235}
236
237static void vbox_crtc_atomic_disable(struct drm_crtc *crtc,
238 struct drm_crtc_state *old_crtc_state)
239{
240}
241
242static void vbox_crtc_atomic_flush(struct drm_crtc *crtc,
243 struct drm_crtc_state *old_crtc_state)
244{
245 struct drm_pending_vblank_event *event;
246 unsigned long flags;
247
248 if (crtc->state && crtc->state->event) {
249 event = crtc->state->event;
250 crtc->state->event = NULL;
251
252 spin_lock_irqsave(&crtc->dev->event_lock, flags);
253 drm_crtc_send_vblank_event(crtc, event);
254 spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
262 } 255 }
256}
263 257
264 if (&vbox->fbdev->afb == vbox_fb) 258static const struct drm_crtc_helper_funcs vbox_crtc_helper_funcs = {
265 vbox_fbdev_set_base(vbox, gpu_addr); 259 .atomic_enable = vbox_crtc_atomic_enable,
266 vbox_bo_unreserve(bo); 260 .atomic_disable = vbox_crtc_atomic_disable,
261 .atomic_flush = vbox_crtc_atomic_flush,
262};
267 263
268 /* vbox_set_start_address_crt1(crtc, (u32)gpu_addr); */ 264static void vbox_crtc_destroy(struct drm_crtc *crtc)
269 vbox_crtc->fb_offset = gpu_addr; 265{
270 if (vbox_set_up_input_mapping(vbox)) { 266 drm_crtc_cleanup(crtc);
271 struct drm_crtc *crtci; 267 kfree(crtc);
268}
272 269
273 list_for_each_entry(crtci, &vbox->dev->mode_config.crtc_list, 270static const struct drm_crtc_funcs vbox_crtc_funcs = {
274 head) { 271 .set_config = drm_atomic_helper_set_config,
275 vbox_set_view(crtc); 272 .page_flip = drm_atomic_helper_page_flip,
276 vbox_do_modeset(crtci, &crtci->mode); 273 /* .gamma_set = vbox_crtc_gamma_set, */
277 } 274 .destroy = vbox_crtc_destroy,
275 .reset = drm_atomic_helper_crtc_reset,
276 .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
277 .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
278};
279
280static int vbox_primary_atomic_check(struct drm_plane *plane,
281 struct drm_plane_state *new_state)
282{
283 struct drm_crtc_state *crtc_state = NULL;
284
285 if (new_state->crtc) {
286 crtc_state = drm_atomic_get_existing_crtc_state(
287 new_state->state, new_state->crtc);
288 if (WARN_ON(!crtc_state))
289 return -EINVAL;
278 } 290 }
279 291
280 return 0; 292 return drm_atomic_helper_check_plane_state(new_state, crtc_state,
293 DRM_PLANE_HELPER_NO_SCALING,
294 DRM_PLANE_HELPER_NO_SCALING,
295 false, true);
281} 296}
282 297
283static int vbox_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, 298static void vbox_primary_atomic_update(struct drm_plane *plane,
284 struct drm_framebuffer *old_fb) 299 struct drm_plane_state *old_state)
285{ 300{
286 return vbox_crtc_do_set_base(crtc, old_fb, CRTC_FB(crtc), x, y); 301 struct drm_crtc *crtc = plane->state->crtc;
302 struct drm_framebuffer *fb = plane->state->fb;
303
304 vbox_crtc_set_base_and_mode(crtc, fb, &crtc->state->mode,
305 plane->state->src_x >> 16,
306 plane->state->src_y >> 16);
287} 307}
288 308
289static int vbox_crtc_mode_set(struct drm_crtc *crtc, 309static void vbox_primary_atomic_disable(struct drm_plane *plane,
290 struct drm_display_mode *mode, 310 struct drm_plane_state *old_state)
291 struct drm_display_mode *adjusted_mode,
292 int x, int y, struct drm_framebuffer *old_fb)
293{ 311{
294 struct vbox_private *vbox = crtc->dev->dev_private; 312 struct drm_crtc *crtc = old_state->crtc;
313
314 /* vbox_do_modeset checks plane->state->fb and will disable if NULL */
315 vbox_crtc_set_base_and_mode(crtc, old_state->fb, &crtc->state->mode,
316 old_state->src_x >> 16,
317 old_state->src_y >> 16);
318}
319
320static int vbox_primary_prepare_fb(struct drm_plane *plane,
321 struct drm_plane_state *new_state)
322{
323 struct vbox_bo *bo;
295 int ret; 324 int ret;
296 325
297 vbox_crtc_mode_set_base(crtc, x, y, old_fb); 326 if (!new_state->fb)
327 return 0;
298 328
299 mutex_lock(&vbox->hw_mutex); 329 bo = gem_to_vbox_bo(to_vbox_framebuffer(new_state->fb)->obj);
300 ret = vbox_set_view(crtc); 330 ret = vbox_bo_pin(bo, TTM_PL_FLAG_VRAM);
301 if (!ret) 331 if (ret)
302 vbox_do_modeset(crtc, mode); 332 DRM_WARN("Error %d pinning new fb, out of video mem?\n", ret);
303 hgsmi_update_input_mapping(vbox->guest_pool, 0, 0,
304 vbox->input_mapping_width,
305 vbox->input_mapping_height);
306 mutex_unlock(&vbox->hw_mutex);
307 333
308 return ret; 334 return ret;
309} 335}
310 336
311static int vbox_crtc_page_flip(struct drm_crtc *crtc, 337static void vbox_primary_cleanup_fb(struct drm_plane *plane,
312 struct drm_framebuffer *fb, 338 struct drm_plane_state *old_state)
313 struct drm_pending_vblank_event *event,
314 uint32_t page_flip_flags,
315 struct drm_modeset_acquire_ctx *ctx)
316{ 339{
317 struct vbox_private *vbox = crtc->dev->dev_private; 340 struct vbox_bo *bo;
318 struct drm_device *drm = vbox->dev;
319 unsigned long flags;
320 int rc;
321 341
322 rc = vbox_crtc_do_set_base(crtc, CRTC_FB(crtc), fb, 0, 0); 342 if (!old_state->fb)
323 if (rc) 343 return;
324 return rc;
325 344
326 mutex_lock(&vbox->hw_mutex); 345 bo = gem_to_vbox_bo(to_vbox_framebuffer(old_state->fb)->obj);
327 vbox_set_view(crtc); 346 vbox_bo_unpin(bo);
328 vbox_do_modeset(crtc, &crtc->mode); 347}
329 mutex_unlock(&vbox->hw_mutex);
330 348
331 spin_lock_irqsave(&drm->event_lock, flags); 349static int vbox_cursor_atomic_check(struct drm_plane *plane,
350 struct drm_plane_state *new_state)
351{
352 struct drm_crtc_state *crtc_state = NULL;
353 u32 width = new_state->crtc_w;
354 u32 height = new_state->crtc_h;
355 int ret;
332 356
333 if (event) 357 if (new_state->crtc) {
334 drm_crtc_send_vblank_event(crtc, event); 358 crtc_state = drm_atomic_get_existing_crtc_state(
359 new_state->state, new_state->crtc);
360 if (WARN_ON(!crtc_state))
361 return -EINVAL;
362 }
335 363
336 spin_unlock_irqrestore(&drm->event_lock, flags); 364 ret = drm_atomic_helper_check_plane_state(new_state, crtc_state,
365 DRM_PLANE_HELPER_NO_SCALING,
366 DRM_PLANE_HELPER_NO_SCALING,
367 true, true);
368 if (ret)
369 return ret;
370
371 if (!new_state->fb)
372 return 0;
373
374 if (width > VBOX_MAX_CURSOR_WIDTH || height > VBOX_MAX_CURSOR_HEIGHT ||
375 width == 0 || height == 0)
376 return -EINVAL;
337 377
338 return 0; 378 return 0;
339} 379}
340 380
341static void vbox_crtc_disable(struct drm_crtc *crtc) 381/**
382 * Copy the ARGB image and generate the mask, which is needed in case the host
383 * does not support ARGB cursors. The mask is a 1BPP bitmap with the bit set
384 * if the corresponding alpha value in the ARGB image is greater than 0xF0.
385 */
386static void copy_cursor_image(u8 *src, u8 *dst, u32 width, u32 height,
387 size_t mask_size)
342{ 388{
389 size_t line_size = (width + 7) / 8;
390 u32 i, j;
391
392 memcpy(dst + mask_size, src, width * height * 4);
393 for (i = 0; i < height; ++i)
394 for (j = 0; j < width; ++j)
395 if (((u32 *)src)[i * width + j] > 0xf0000000)
396 dst[i * line_size + j / 8] |= (0x80 >> (j % 8));
343} 397}
344 398
345static void vbox_crtc_prepare(struct drm_crtc *crtc) 399static void vbox_cursor_atomic_update(struct drm_plane *plane,
400 struct drm_plane_state *old_state)
346{ 401{
402 struct vbox_private *vbox =
403 container_of(plane->dev, struct vbox_private, ddev);
404 struct vbox_crtc *vbox_crtc = to_vbox_crtc(plane->state->crtc);
405 struct drm_framebuffer *fb = plane->state->fb;
406 struct vbox_bo *bo = gem_to_vbox_bo(to_vbox_framebuffer(fb)->obj);
407 u32 width = plane->state->crtc_w;
408 u32 height = plane->state->crtc_h;
409 size_t data_size, mask_size;
410 u32 flags;
411 u8 *src;
412
413 /*
414 * VirtualBox uses the host windowing system to draw the cursor so
415 * moves are a no-op, we only need to upload new cursor sprites.
416 */
417 if (fb == old_state->fb)
418 return;
419
420 mutex_lock(&vbox->hw_mutex);
421
422 vbox_crtc->cursor_enabled = true;
423
424 /* pinning is done in prepare/cleanup framebuffer */
425 src = vbox_bo_kmap(bo);
426 if (IS_ERR(src)) {
427 mutex_unlock(&vbox->hw_mutex);
428 DRM_WARN("Could not kmap cursor bo, skipping update\n");
429 return;
430 }
431
432 /*
433 * The mask must be calculated based on the alpha
434 * channel, one bit per ARGB word, and must be 32-bit
435 * padded.
436 */
437 mask_size = ((width + 7) / 8 * height + 3) & ~3;
438 data_size = width * height * 4 + mask_size;
439
440 copy_cursor_image(src, vbox->cursor_data, width, height, mask_size);
441 vbox_bo_kunmap(bo);
442
443 flags = VBOX_MOUSE_POINTER_VISIBLE | VBOX_MOUSE_POINTER_SHAPE |
444 VBOX_MOUSE_POINTER_ALPHA;
445 hgsmi_update_pointer_shape(vbox->guest_pool, flags,
446 min_t(u32, max(fb->hot_x, 0), width),
447 min_t(u32, max(fb->hot_y, 0), height),
448 width, height, vbox->cursor_data, data_size);
449
450 mutex_unlock(&vbox->hw_mutex);
347} 451}
348 452
349static void vbox_crtc_commit(struct drm_crtc *crtc) 453static void vbox_cursor_atomic_disable(struct drm_plane *plane,
454 struct drm_plane_state *old_state)
350{ 455{
351} 456 struct vbox_private *vbox =
457 container_of(plane->dev, struct vbox_private, ddev);
458 struct vbox_crtc *vbox_crtc = to_vbox_crtc(old_state->crtc);
459 bool cursor_enabled = false;
460 struct drm_crtc *crtci;
352 461
353static const struct drm_crtc_helper_funcs vbox_crtc_helper_funcs = { 462 mutex_lock(&vbox->hw_mutex);
354 .dpms = vbox_crtc_dpms,
355 .mode_fixup = vbox_crtc_mode_fixup,
356 .mode_set = vbox_crtc_mode_set,
357 /* .mode_set_base = vbox_crtc_mode_set_base, */
358 .disable = vbox_crtc_disable,
359 .prepare = vbox_crtc_prepare,
360 .commit = vbox_crtc_commit,
361};
362 463
363static void vbox_crtc_reset(struct drm_crtc *crtc) 464 vbox_crtc->cursor_enabled = false;
465
466 list_for_each_entry(crtci, &vbox->ddev.mode_config.crtc_list, head) {
467 if (to_vbox_crtc(crtci)->cursor_enabled)
468 cursor_enabled = true;
469 }
470
471 if (!cursor_enabled)
472 hgsmi_update_pointer_shape(vbox->guest_pool, 0, 0, 0,
473 0, 0, NULL, 0);
474
475 mutex_unlock(&vbox->hw_mutex);
476}
477
478static int vbox_cursor_prepare_fb(struct drm_plane *plane,
479 struct drm_plane_state *new_state)
364{ 480{
481 struct vbox_bo *bo;
482
483 if (!new_state->fb)
484 return 0;
485
486 bo = gem_to_vbox_bo(to_vbox_framebuffer(new_state->fb)->obj);
487 return vbox_bo_pin(bo, TTM_PL_FLAG_SYSTEM);
365} 488}
366 489
367static void vbox_crtc_destroy(struct drm_crtc *crtc) 490static void vbox_cursor_cleanup_fb(struct drm_plane *plane,
491 struct drm_plane_state *old_state)
368{ 492{
369 drm_crtc_cleanup(crtc); 493 struct vbox_bo *bo;
370 kfree(crtc); 494
495 if (!plane->state->fb)
496 return;
497
498 bo = gem_to_vbox_bo(to_vbox_framebuffer(plane->state->fb)->obj);
499 vbox_bo_unpin(bo);
371} 500}
372 501
373static const struct drm_crtc_funcs vbox_crtc_funcs = { 502static const uint32_t vbox_cursor_plane_formats[] = {
374 .cursor_move = vbox_cursor_move, 503 DRM_FORMAT_ARGB8888,
375 .cursor_set2 = vbox_cursor_set2,
376 .reset = vbox_crtc_reset,
377 .set_config = drm_crtc_helper_set_config,
378 /* .gamma_set = vbox_crtc_gamma_set, */
379 .page_flip = vbox_crtc_page_flip,
380 .destroy = vbox_crtc_destroy,
381}; 504};
382 505
506static const struct drm_plane_helper_funcs vbox_cursor_helper_funcs = {
507 .atomic_check = vbox_cursor_atomic_check,
508 .atomic_update = vbox_cursor_atomic_update,
509 .atomic_disable = vbox_cursor_atomic_disable,
510 .prepare_fb = vbox_cursor_prepare_fb,
511 .cleanup_fb = vbox_cursor_cleanup_fb,
512};
513
514static const struct drm_plane_funcs vbox_cursor_plane_funcs = {
515 .update_plane = drm_atomic_helper_update_plane,
516 .disable_plane = drm_atomic_helper_disable_plane,
517 .destroy = drm_primary_helper_destroy,
518 .reset = drm_atomic_helper_plane_reset,
519 .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
520 .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
521};
522
523static const uint32_t vbox_primary_plane_formats[] = {
524 DRM_FORMAT_XRGB8888,
525 DRM_FORMAT_ARGB8888,
526};
527
528static const struct drm_plane_helper_funcs vbox_primary_helper_funcs = {
529 .atomic_check = vbox_primary_atomic_check,
530 .atomic_update = vbox_primary_atomic_update,
531 .atomic_disable = vbox_primary_atomic_disable,
532 .prepare_fb = vbox_primary_prepare_fb,
533 .cleanup_fb = vbox_primary_cleanup_fb,
534};
535
536static const struct drm_plane_funcs vbox_primary_plane_funcs = {
537 .update_plane = drm_atomic_helper_update_plane,
538 .disable_plane = drm_atomic_helper_disable_plane,
539 .destroy = drm_primary_helper_destroy,
540 .reset = drm_atomic_helper_plane_reset,
541 .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
542 .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
543};
544
545static struct drm_plane *vbox_create_plane(struct vbox_private *vbox,
546 unsigned int possible_crtcs,
547 enum drm_plane_type type)
548{
549 const struct drm_plane_helper_funcs *helper_funcs = NULL;
550 const struct drm_plane_funcs *funcs;
551 struct drm_plane *plane;
552 const uint32_t *formats;
553 int num_formats;
554 int err;
555
556 if (type == DRM_PLANE_TYPE_PRIMARY) {
557 funcs = &vbox_primary_plane_funcs;
558 formats = vbox_primary_plane_formats;
559 helper_funcs = &vbox_primary_helper_funcs;
560 num_formats = ARRAY_SIZE(vbox_primary_plane_formats);
561 } else if (type == DRM_PLANE_TYPE_CURSOR) {
562 funcs = &vbox_cursor_plane_funcs;
563 formats = vbox_cursor_plane_formats;
564 helper_funcs = &vbox_cursor_helper_funcs;
565 num_formats = ARRAY_SIZE(vbox_cursor_plane_formats);
566 } else {
567 return ERR_PTR(-EINVAL);
568 }
569
570 plane = kzalloc(sizeof(*plane), GFP_KERNEL);
571 if (!plane)
572 return ERR_PTR(-ENOMEM);
573
574 err = drm_universal_plane_init(&vbox->ddev, plane, possible_crtcs,
575 funcs, formats, num_formats,
576 NULL, type, NULL);
577 if (err)
578 goto free_plane;
579
580 drm_plane_helper_add(plane, helper_funcs);
581
582 return plane;
583
584free_plane:
585 kfree(plane);
586 return ERR_PTR(-EINVAL);
587}
588
383static struct vbox_crtc *vbox_crtc_init(struct drm_device *dev, unsigned int i) 589static struct vbox_crtc *vbox_crtc_init(struct drm_device *dev, unsigned int i)
384{ 590{
591 struct vbox_private *vbox =
592 container_of(dev, struct vbox_private, ddev);
593 struct drm_plane *cursor = NULL;
385 struct vbox_crtc *vbox_crtc; 594 struct vbox_crtc *vbox_crtc;
595 struct drm_plane *primary;
596 u32 caps = 0;
597 int ret;
598
599 ret = hgsmi_query_conf(vbox->guest_pool,
600 VBOX_VBVA_CONF32_CURSOR_CAPABILITIES, &caps);
601 if (ret)
602 return ERR_PTR(ret);
386 603
387 vbox_crtc = kzalloc(sizeof(*vbox_crtc), GFP_KERNEL); 604 vbox_crtc = kzalloc(sizeof(*vbox_crtc), GFP_KERNEL);
388 if (!vbox_crtc) 605 if (!vbox_crtc)
389 return NULL; 606 return ERR_PTR(-ENOMEM);
607
608 primary = vbox_create_plane(vbox, 1 << i, DRM_PLANE_TYPE_PRIMARY);
609 if (IS_ERR(primary)) {
610 ret = PTR_ERR(primary);
611 goto free_mem;
612 }
613
614 if ((caps & VBOX_VBVA_CURSOR_CAPABILITY_HARDWARE)) {
615 cursor = vbox_create_plane(vbox, 1 << i, DRM_PLANE_TYPE_CURSOR);
616 if (IS_ERR(cursor)) {
617 ret = PTR_ERR(cursor);
618 goto clean_primary;
619 }
620 } else {
621 DRM_WARN("VirtualBox host is too old, no cursor support\n");
622 }
390 623
391 vbox_crtc->crtc_id = i; 624 vbox_crtc->crtc_id = i;
392 625
393 drm_crtc_init(dev, &vbox_crtc->base, &vbox_crtc_funcs); 626 ret = drm_crtc_init_with_planes(dev, &vbox_crtc->base, primary, cursor,
627 &vbox_crtc_funcs, NULL);
628 if (ret)
629 goto clean_cursor;
630
394 drm_mode_crtc_set_gamma_size(&vbox_crtc->base, 256); 631 drm_mode_crtc_set_gamma_size(&vbox_crtc->base, 256);
395 drm_crtc_helper_add(&vbox_crtc->base, &vbox_crtc_helper_funcs); 632 drm_crtc_helper_add(&vbox_crtc->base, &vbox_crtc_helper_funcs);
396 633
397 return vbox_crtc; 634 return vbox_crtc;
635
636clean_cursor:
637 if (cursor) {
638 drm_plane_cleanup(cursor);
639 kfree(cursor);
640 }
641clean_primary:
642 drm_plane_cleanup(primary);
643 kfree(primary);
644free_mem:
645 kfree(vbox_crtc);
646 return ERR_PTR(ret);
398} 647}
399 648
400static void vbox_encoder_destroy(struct drm_encoder *encoder) 649static void vbox_encoder_destroy(struct drm_encoder *encoder)
@@ -403,55 +652,10 @@ static void vbox_encoder_destroy(struct drm_encoder *encoder)
403 kfree(encoder); 652 kfree(encoder);
404} 653}
405 654
406static struct drm_encoder *vbox_best_single_encoder(struct drm_connector
407 *connector)
408{
409 int enc_id = connector->encoder_ids[0];
410
411 /* pick the encoder ids */
412 if (enc_id)
413 return drm_encoder_find(connector->dev, NULL, enc_id);
414
415 return NULL;
416}
417
418static const struct drm_encoder_funcs vbox_enc_funcs = { 655static const struct drm_encoder_funcs vbox_enc_funcs = {
419 .destroy = vbox_encoder_destroy, 656 .destroy = vbox_encoder_destroy,
420}; 657};
421 658
422static void vbox_encoder_dpms(struct drm_encoder *encoder, int mode)
423{
424}
425
426static bool vbox_mode_fixup(struct drm_encoder *encoder,
427 const struct drm_display_mode *mode,
428 struct drm_display_mode *adjusted_mode)
429{
430 return true;
431}
432
433static void vbox_encoder_mode_set(struct drm_encoder *encoder,
434 struct drm_display_mode *mode,
435 struct drm_display_mode *adjusted_mode)
436{
437}
438
439static void vbox_encoder_prepare(struct drm_encoder *encoder)
440{
441}
442
443static void vbox_encoder_commit(struct drm_encoder *encoder)
444{
445}
446
447static const struct drm_encoder_helper_funcs vbox_enc_helper_funcs = {
448 .dpms = vbox_encoder_dpms,
449 .mode_fixup = vbox_mode_fixup,
450 .prepare = vbox_encoder_prepare,
451 .commit = vbox_encoder_commit,
452 .mode_set = vbox_encoder_mode_set,
453};
454
455static struct drm_encoder *vbox_encoder_init(struct drm_device *dev, 659static struct drm_encoder *vbox_encoder_init(struct drm_device *dev,
456 unsigned int i) 660 unsigned int i)
457{ 661{
@@ -463,7 +667,6 @@ static struct drm_encoder *vbox_encoder_init(struct drm_device *dev,
463 667
464 drm_encoder_init(dev, &vbox_encoder->base, &vbox_enc_funcs, 668 drm_encoder_init(dev, &vbox_encoder->base, &vbox_enc_funcs,
465 DRM_MODE_ENCODER_DAC, NULL); 669 DRM_MODE_ENCODER_DAC, NULL);
466 drm_encoder_helper_add(&vbox_encoder->base, &vbox_enc_helper_funcs);
467 670
468 vbox_encoder->base.possible_crtcs = 1 << i; 671 vbox_encoder->base.possible_crtcs = 1 << i;
469 return &vbox_encoder->base; 672 return &vbox_encoder->base;
@@ -589,29 +792,23 @@ static int vbox_get_modes(struct drm_connector *connector)
589 792
590 if (vbox_connector->vbox_crtc->x_hint != -1) 793 if (vbox_connector->vbox_crtc->x_hint != -1)
591 drm_object_property_set_value(&connector->base, 794 drm_object_property_set_value(&connector->base,
592 vbox->dev->mode_config.suggested_x_property, 795 vbox->ddev.mode_config.suggested_x_property,
593 vbox_connector->vbox_crtc->x_hint); 796 vbox_connector->vbox_crtc->x_hint);
594 else 797 else
595 drm_object_property_set_value(&connector->base, 798 drm_object_property_set_value(&connector->base,
596 vbox->dev->mode_config.suggested_x_property, 0); 799 vbox->ddev.mode_config.suggested_x_property, 0);
597 800
598 if (vbox_connector->vbox_crtc->y_hint != -1) 801 if (vbox_connector->vbox_crtc->y_hint != -1)
599 drm_object_property_set_value(&connector->base, 802 drm_object_property_set_value(&connector->base,
600 vbox->dev->mode_config.suggested_y_property, 803 vbox->ddev.mode_config.suggested_y_property,
601 vbox_connector->vbox_crtc->y_hint); 804 vbox_connector->vbox_crtc->y_hint);
602 else 805 else
603 drm_object_property_set_value(&connector->base, 806 drm_object_property_set_value(&connector->base,
604 vbox->dev->mode_config.suggested_y_property, 0); 807 vbox->ddev.mode_config.suggested_y_property, 0);
605 808
606 return num_modes; 809 return num_modes;
607} 810}
608 811
609static enum drm_mode_status vbox_mode_valid(struct drm_connector *connector,
610 struct drm_display_mode *mode)
611{
612 return MODE_OK;
613}
614
615static void vbox_connector_destroy(struct drm_connector *connector) 812static void vbox_connector_destroy(struct drm_connector *connector)
616{ 813{
617 drm_connector_unregister(connector); 814 drm_connector_unregister(connector);
@@ -648,16 +845,16 @@ static int vbox_fill_modes(struct drm_connector *connector, u32 max_x,
648} 845}
649 846
650static const struct drm_connector_helper_funcs vbox_connector_helper_funcs = { 847static const struct drm_connector_helper_funcs vbox_connector_helper_funcs = {
651 .mode_valid = vbox_mode_valid,
652 .get_modes = vbox_get_modes, 848 .get_modes = vbox_get_modes,
653 .best_encoder = vbox_best_single_encoder,
654}; 849};
655 850
656static const struct drm_connector_funcs vbox_connector_funcs = { 851static const struct drm_connector_funcs vbox_connector_funcs = {
657 .dpms = drm_helper_connector_dpms,
658 .detect = vbox_connector_detect, 852 .detect = vbox_connector_detect,
659 .fill_modes = vbox_fill_modes, 853 .fill_modes = vbox_fill_modes,
660 .destroy = vbox_connector_destroy, 854 .destroy = vbox_connector_destroy,
855 .reset = drm_atomic_helper_connector_reset,
856 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
857 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
661}; 858};
662 859
663static int vbox_connector_init(struct drm_device *dev, 860static int vbox_connector_init(struct drm_device *dev,
@@ -686,225 +883,92 @@ static int vbox_connector_init(struct drm_device *dev,
686 dev->mode_config.suggested_x_property, 0); 883 dev->mode_config.suggested_x_property, 0);
687 drm_object_attach_property(&connector->base, 884 drm_object_attach_property(&connector->base,
688 dev->mode_config.suggested_y_property, 0); 885 dev->mode_config.suggested_y_property, 0);
689 drm_connector_register(connector);
690 886
691 drm_connector_attach_encoder(connector, encoder); 887 drm_connector_attach_encoder(connector, encoder);
692 888
693 return 0; 889 return 0;
694} 890}
695 891
696int vbox_mode_init(struct drm_device *dev) 892static struct drm_framebuffer *vbox_user_framebuffer_create(
893 struct drm_device *dev,
894 struct drm_file *filp,
895 const struct drm_mode_fb_cmd2 *mode_cmd)
697{ 896{
698 struct vbox_private *vbox = dev->dev_private; 897 struct vbox_private *vbox =
699 struct drm_encoder *encoder; 898 container_of(dev, struct vbox_private, ddev);
700 struct vbox_crtc *vbox_crtc; 899 struct drm_gem_object *obj;
701 unsigned int i; 900 struct vbox_framebuffer *vbox_fb;
702 int ret; 901 int ret = -ENOMEM;
703 902
704 /* vbox_cursor_init(dev); */ 903 obj = drm_gem_object_lookup(filp, mode_cmd->handles[0]);
705 for (i = 0; i < vbox->num_crtcs; ++i) { 904 if (!obj)
706 vbox_crtc = vbox_crtc_init(dev, i); 905 return ERR_PTR(-ENOENT);
707 if (!vbox_crtc)
708 return -ENOMEM;
709 encoder = vbox_encoder_init(dev, i);
710 if (!encoder)
711 return -ENOMEM;
712 ret = vbox_connector_init(dev, vbox_crtc, encoder);
713 if (ret)
714 return ret;
715 }
716 906
717 return 0; 907 vbox_fb = kzalloc(sizeof(*vbox_fb), GFP_KERNEL);
718} 908 if (!vbox_fb)
909 goto err_unref_obj;
719 910
720void vbox_mode_fini(struct drm_device *dev) 911 ret = vbox_framebuffer_init(vbox, vbox_fb, mode_cmd, obj);
721{ 912 if (ret)
722 /* vbox_cursor_fini(dev); */ 913 goto err_free_vbox_fb;
723}
724 914
725/** 915 return &vbox_fb->base;
726 * Copy the ARGB image and generate the mask, which is needed in case the host
727 * does not support ARGB cursors. The mask is a 1BPP bitmap with the bit set
728 * if the corresponding alpha value in the ARGB image is greater than 0xF0.
729 */
730static void copy_cursor_image(u8 *src, u8 *dst, u32 width, u32 height,
731 size_t mask_size)
732{
733 size_t line_size = (width + 7) / 8;
734 u32 i, j;
735 916
736 memcpy(dst + mask_size, src, width * height * 4); 917err_free_vbox_fb:
737 for (i = 0; i < height; ++i) 918 kfree(vbox_fb);
738 for (j = 0; j < width; ++j) 919err_unref_obj:
739 if (((u32 *)src)[i * width + j] > 0xf0000000) 920 drm_gem_object_put_unlocked(obj);
740 dst[i * line_size + j / 8] |= (0x80 >> (j % 8)); 921 return ERR_PTR(ret);
741} 922}
742 923
743static int vbox_cursor_set2(struct drm_crtc *crtc, struct drm_file *file_priv, 924static const struct drm_mode_config_funcs vbox_mode_funcs = {
744 u32 handle, u32 width, u32 height, 925 .fb_create = vbox_user_framebuffer_create,
745 s32 hot_x, s32 hot_y) 926 .atomic_check = drm_atomic_helper_check,
927 .atomic_commit = drm_atomic_helper_commit,
928};
929
930int vbox_mode_init(struct vbox_private *vbox)
746{ 931{
747 struct vbox_private *vbox = crtc->dev->dev_private; 932 struct drm_device *dev = &vbox->ddev;
748 struct vbox_crtc *vbox_crtc = to_vbox_crtc(crtc); 933 struct drm_encoder *encoder;
749 struct ttm_bo_kmap_obj uobj_map; 934 struct vbox_crtc *vbox_crtc;
750 size_t data_size, mask_size; 935 unsigned int i;
751 struct drm_gem_object *obj;
752 u32 flags, caps = 0;
753 struct vbox_bo *bo;
754 bool src_isiomem;
755 u8 *dst = NULL;
756 u8 *src;
757 int ret; 936 int ret;
758 937
759 /* 938 drm_mode_config_init(dev);
760 * Re-set this regularly as in 5.0.20 and earlier the information was
761 * lost on save and restore.
762 */
763 hgsmi_update_input_mapping(vbox->guest_pool, 0, 0,
764 vbox->input_mapping_width,
765 vbox->input_mapping_height);
766 if (!handle) {
767 bool cursor_enabled = false;
768 struct drm_crtc *crtci;
769
770 /* Hide cursor. */
771 vbox_crtc->cursor_enabled = false;
772 list_for_each_entry(crtci, &vbox->dev->mode_config.crtc_list,
773 head) {
774 if (to_vbox_crtc(crtci)->cursor_enabled)
775 cursor_enabled = true;
776 }
777
778 if (!cursor_enabled)
779 hgsmi_update_pointer_shape(vbox->guest_pool, 0, 0, 0,
780 0, 0, NULL, 0);
781 return 0;
782 }
783
784 vbox_crtc->cursor_enabled = true;
785
786 if (width > VBOX_MAX_CURSOR_WIDTH || height > VBOX_MAX_CURSOR_HEIGHT ||
787 width == 0 || height == 0)
788 return -EINVAL;
789
790 ret = hgsmi_query_conf(vbox->guest_pool,
791 VBOX_VBVA_CONF32_CURSOR_CAPABILITIES, &caps);
792 if (ret)
793 return ret;
794
795 if (!(caps & VBOX_VBVA_CURSOR_CAPABILITY_HARDWARE)) {
796 /*
797 * -EINVAL means cursor_set2() not supported, -EAGAIN means
798 * retry at once.
799 */
800 return -EBUSY;
801 }
802
803 obj = drm_gem_object_lookup(file_priv, handle);
804 if (!obj) {
805 DRM_ERROR("Cannot find cursor object %x for crtc\n", handle);
806 return -ENOENT;
807 }
808 939
809 bo = gem_to_vbox_bo(obj); 940 dev->mode_config.funcs = (void *)&vbox_mode_funcs;
810 ret = vbox_bo_reserve(bo, false); 941 dev->mode_config.min_width = 0;
811 if (ret) 942 dev->mode_config.min_height = 0;
812 goto out_unref_obj; 943 dev->mode_config.preferred_depth = 24;
944 dev->mode_config.max_width = VBE_DISPI_MAX_XRES;
945 dev->mode_config.max_height = VBE_DISPI_MAX_YRES;
813 946
814 /* 947 for (i = 0; i < vbox->num_crtcs; ++i) {
815 * The mask must be calculated based on the alpha 948 vbox_crtc = vbox_crtc_init(dev, i);
816 * channel, one bit per ARGB word, and must be 32-bit 949 if (IS_ERR(vbox_crtc)) {
817 * padded. 950 ret = PTR_ERR(vbox_crtc);
818 */ 951 goto err_drm_mode_cleanup;
819 mask_size = ((width + 7) / 8 * height + 3) & ~3; 952 }
820 data_size = width * height * 4 + mask_size; 953 encoder = vbox_encoder_init(dev, i);
821 vbox->cursor_hot_x = min_t(u32, max(hot_x, 0), width); 954 if (!encoder) {
822 vbox->cursor_hot_y = min_t(u32, max(hot_y, 0), height); 955 ret = -ENOMEM;
823 vbox->cursor_width = width; 956 goto err_drm_mode_cleanup;
824 vbox->cursor_height = height; 957 }
825 vbox->cursor_data_size = data_size; 958 ret = vbox_connector_init(dev, vbox_crtc, encoder);
826 dst = vbox->cursor_data; 959 if (ret)
827 960 goto err_drm_mode_cleanup;
828 ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &uobj_map);
829 if (ret) {
830 vbox->cursor_data_size = 0;
831 goto out_unreserve_bo;
832 }
833
834 src = ttm_kmap_obj_virtual(&uobj_map, &src_isiomem);
835 if (src_isiomem) {
836 DRM_ERROR("src cursor bo not in main memory\n");
837 ret = -EIO;
838 goto out_unmap_bo;
839 } 961 }
840 962
841 copy_cursor_image(src, dst, width, height, mask_size); 963 drm_mode_config_reset(dev);
842 964 return 0;
843 flags = VBOX_MOUSE_POINTER_VISIBLE | VBOX_MOUSE_POINTER_SHAPE |
844 VBOX_MOUSE_POINTER_ALPHA;
845 ret = hgsmi_update_pointer_shape(vbox->guest_pool, flags,
846 vbox->cursor_hot_x, vbox->cursor_hot_y,
847 width, height, dst, data_size);
848out_unmap_bo:
849 ttm_bo_kunmap(&uobj_map);
850out_unreserve_bo:
851 vbox_bo_unreserve(bo);
852out_unref_obj:
853 drm_gem_object_put_unlocked(obj);
854 965
966err_drm_mode_cleanup:
967 drm_mode_config_cleanup(dev);
855 return ret; 968 return ret;
856} 969}
857 970
858static int vbox_cursor_move(struct drm_crtc *crtc, int x, int y) 971void vbox_mode_fini(struct vbox_private *vbox)
859{ 972{
860 struct vbox_private *vbox = crtc->dev->dev_private; 973 drm_mode_config_cleanup(&vbox->ddev);
861 u32 flags = VBOX_MOUSE_POINTER_VISIBLE |
862 VBOX_MOUSE_POINTER_SHAPE | VBOX_MOUSE_POINTER_ALPHA;
863 s32 crtc_x =
864 vbox->single_framebuffer ? crtc->x : to_vbox_crtc(crtc)->x_hint;
865 s32 crtc_y =
866 vbox->single_framebuffer ? crtc->y : to_vbox_crtc(crtc)->y_hint;
867 u32 host_x, host_y;
868 u32 hot_x = 0;
869 u32 hot_y = 0;
870 int ret;
871
872 /*
873 * We compare these to unsigned later and don't
874 * need to handle negative.
875 */
876 if (x + crtc_x < 0 || y + crtc_y < 0 || vbox->cursor_data_size == 0)
877 return 0;
878
879 ret = hgsmi_cursor_position(vbox->guest_pool, true, x + crtc_x,
880 y + crtc_y, &host_x, &host_y);
881
882 /*
883 * The only reason we have vbox_cursor_move() is that some older clients
884 * might use DRM_IOCTL_MODE_CURSOR instead of DRM_IOCTL_MODE_CURSOR2 and
885 * use DRM_MODE_CURSOR_MOVE to set the hot-spot.
886 *
887 * However VirtualBox 5.0.20 and earlier has a bug causing it to return
888 * 0,0 as host cursor location after a save and restore.
889 *
890 * To work around this we ignore a 0, 0 return, since missing the odd
891 * time when it legitimately happens is not going to hurt much.
892 */
893 if (ret || (host_x == 0 && host_y == 0))
894 return ret;
895
896 if (x + crtc_x < host_x)
897 hot_x = min(host_x - x - crtc_x, vbox->cursor_width);
898 if (y + crtc_y < host_y)
899 hot_y = min(host_y - y - crtc_y, vbox->cursor_height);
900
901 if (hot_x == vbox->cursor_hot_x && hot_y == vbox->cursor_hot_y)
902 return 0;
903
904 vbox->cursor_hot_x = hot_x;
905 vbox->cursor_hot_y = hot_y;
906
907 return hgsmi_update_pointer_shape(vbox->guest_pool, flags,
908 hot_x, hot_y, vbox->cursor_width, vbox->cursor_height,
909 vbox->cursor_data, vbox->cursor_data_size);
910} 974}
diff --git a/drivers/staging/vboxvideo/vbox_ttm.c b/drivers/staging/vboxvideo/vbox_ttm.c
index 548edb7c494b..5ecfa7629173 100644
--- a/drivers/staging/vboxvideo/vbox_ttm.c
+++ b/drivers/staging/vboxvideo/vbox_ttm.c
@@ -169,7 +169,7 @@ static int vbox_ttm_io_mem_reserve(struct ttm_bo_device *bdev,
169 return 0; 169 return 0;
170 case TTM_PL_VRAM: 170 case TTM_PL_VRAM:
171 mem->bus.offset = mem->start << PAGE_SHIFT; 171 mem->bus.offset = mem->start << PAGE_SHIFT;
172 mem->bus.base = pci_resource_start(vbox->dev->pdev, 0); 172 mem->bus.base = pci_resource_start(vbox->ddev.pdev, 0);
173 mem->bus.is_iomem = true; 173 mem->bus.is_iomem = true;
174 break; 174 break;
175 default: 175 default:
@@ -224,7 +224,7 @@ static struct ttm_bo_driver vbox_bo_driver = {
224int vbox_mm_init(struct vbox_private *vbox) 224int vbox_mm_init(struct vbox_private *vbox)
225{ 225{
226 int ret; 226 int ret;
227 struct drm_device *dev = vbox->dev; 227 struct drm_device *dev = &vbox->ddev;
228 struct ttm_bo_device *bdev = &vbox->ttm.bdev; 228 struct ttm_bo_device *bdev = &vbox->ttm.bdev;
229 229
230 ret = vbox_ttm_global_init(vbox); 230 ret = vbox_ttm_global_init(vbox);
@@ -269,8 +269,8 @@ void vbox_mm_fini(struct vbox_private *vbox)
269{ 269{
270#ifdef DRM_MTRR_WC 270#ifdef DRM_MTRR_WC
271 drm_mtrr_del(vbox->fb_mtrr, 271 drm_mtrr_del(vbox->fb_mtrr,
272 pci_resource_start(vbox->dev->pdev, 0), 272 pci_resource_start(vbox->ddev.pdev, 0),
273 pci_resource_len(vbox->dev->pdev, 0), DRM_MTRR_WC); 273 pci_resource_len(vbox->ddev.pdev, 0), DRM_MTRR_WC);
274#else 274#else
275 arch_phys_wc_del(vbox->fb_mtrr); 275 arch_phys_wc_del(vbox->fb_mtrr);
276#endif 276#endif
@@ -305,10 +305,9 @@ void vbox_ttm_placement(struct vbox_bo *bo, int domain)
305 } 305 }
306} 306}
307 307
308int vbox_bo_create(struct drm_device *dev, int size, int align, 308int vbox_bo_create(struct vbox_private *vbox, int size, int align,
309 u32 flags, struct vbox_bo **pvboxbo) 309 u32 flags, struct vbox_bo **pvboxbo)
310{ 310{
311 struct vbox_private *vbox = dev->dev_private;
312 struct vbox_bo *vboxbo; 311 struct vbox_bo *vboxbo;
313 size_t acc_size; 312 size_t acc_size;
314 int ret; 313 int ret;
@@ -317,7 +316,7 @@ int vbox_bo_create(struct drm_device *dev, int size, int align,
317 if (!vboxbo) 316 if (!vboxbo)
318 return -ENOMEM; 317 return -ENOMEM;
319 318
320 ret = drm_gem_object_init(dev, &vboxbo->gem, size); 319 ret = drm_gem_object_init(&vbox->ddev, &vboxbo->gem, size);
321 if (ret) 320 if (ret)
322 goto err_free_vboxbo; 321 goto err_free_vboxbo;
323 322
@@ -344,39 +343,32 @@ err_free_vboxbo:
344 return ret; 343 return ret;
345} 344}
346 345
347static inline u64 vbox_bo_gpu_offset(struct vbox_bo *bo) 346int vbox_bo_pin(struct vbox_bo *bo, u32 pl_flag)
348{
349 return bo->bo.offset;
350}
351
352int vbox_bo_pin(struct vbox_bo *bo, u32 pl_flag, u64 *gpu_addr)
353{ 347{
354 struct ttm_operation_ctx ctx = { false, false }; 348 struct ttm_operation_ctx ctx = { false, false };
355 int i, ret; 349 int i, ret;
356 350
357 if (bo->pin_count) { 351 if (bo->pin_count) {
358 bo->pin_count++; 352 bo->pin_count++;
359 if (gpu_addr)
360 *gpu_addr = vbox_bo_gpu_offset(bo);
361
362 return 0; 353 return 0;
363 } 354 }
364 355
356 ret = vbox_bo_reserve(bo, false);
357 if (ret)
358 return ret;
359
365 vbox_ttm_placement(bo, pl_flag); 360 vbox_ttm_placement(bo, pl_flag);
366 361
367 for (i = 0; i < bo->placement.num_placement; i++) 362 for (i = 0; i < bo->placement.num_placement; i++)
368 bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT; 363 bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT;
369 364
370 ret = ttm_bo_validate(&bo->bo, &bo->placement, &ctx); 365 ret = ttm_bo_validate(&bo->bo, &bo->placement, &ctx);
371 if (ret) 366 if (ret == 0)
372 return ret; 367 bo->pin_count = 1;
373
374 bo->pin_count = 1;
375 368
376 if (gpu_addr) 369 vbox_bo_unreserve(bo);
377 *gpu_addr = vbox_bo_gpu_offset(bo);
378 370
379 return 0; 371 return ret;
380} 372}
381 373
382int vbox_bo_unpin(struct vbox_bo *bo) 374int vbox_bo_unpin(struct vbox_bo *bo)
@@ -392,14 +384,20 @@ int vbox_bo_unpin(struct vbox_bo *bo)
392 if (bo->pin_count) 384 if (bo->pin_count)
393 return 0; 385 return 0;
394 386
387 ret = vbox_bo_reserve(bo, false);
388 if (ret) {
389 DRM_ERROR("Error %d reserving bo, leaving it pinned\n", ret);
390 return ret;
391 }
392
395 for (i = 0; i < bo->placement.num_placement; i++) 393 for (i = 0; i < bo->placement.num_placement; i++)
396 bo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT; 394 bo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT;
397 395
398 ret = ttm_bo_validate(&bo->bo, &bo->placement, &ctx); 396 ret = ttm_bo_validate(&bo->bo, &bo->placement, &ctx);
399 if (ret)
400 return ret;
401 397
402 return 0; 398 vbox_bo_unreserve(bo);
399
400 return ret;
403} 401}
404 402
405/* 403/*
@@ -420,8 +418,10 @@ int vbox_bo_push_sysram(struct vbox_bo *bo)
420 if (bo->pin_count) 418 if (bo->pin_count)
421 return 0; 419 return 0;
422 420
423 if (bo->kmap.virtual) 421 if (bo->kmap.virtual) {
424 ttm_bo_kunmap(&bo->kmap); 422 ttm_bo_kunmap(&bo->kmap);
423 bo->kmap.virtual = NULL;
424 }
425 425
426 vbox_ttm_placement(bo, TTM_PL_FLAG_SYSTEM); 426 vbox_ttm_placement(bo, TTM_PL_FLAG_SYSTEM);
427 427
@@ -450,3 +450,27 @@ int vbox_mmap(struct file *filp, struct vm_area_struct *vma)
450 450
451 return ttm_bo_mmap(filp, vma, &vbox->ttm.bdev); 451 return ttm_bo_mmap(filp, vma, &vbox->ttm.bdev);
452} 452}
453
454void *vbox_bo_kmap(struct vbox_bo *bo)
455{
456 int ret;
457
458 if (bo->kmap.virtual)
459 return bo->kmap.virtual;
460
461 ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &bo->kmap);
462 if (ret) {
463 DRM_ERROR("Error kmapping bo: %d\n", ret);
464 return NULL;
465 }
466
467 return bo->kmap.virtual;
468}
469
470void vbox_bo_kunmap(struct vbox_bo *bo)
471{
472 if (bo->kmap.virtual) {
473 ttm_bo_kunmap(&bo->kmap);
474 bo->kmap.virtual = NULL;
475 }
476}
diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-ctl.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-ctl.c
index ec468d5719b1..a6ec72a5f0be 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-ctl.c
+++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-ctl.c
@@ -1,23 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0
2/* Copyright 2011 Broadcom Corporation. All rights reserved. */ 2/* Copyright 2011 Broadcom Corporation. All rights reserved. */
3 3
4#include <linux/platform_device.h>
5#include <linux/init.h>
6#include <linux/io.h>
7#include <linux/jiffies.h>
8#include <linux/slab.h>
9#include <linux/time.h>
10#include <linux/wait.h>
11#include <linux/delay.h>
12#include <linux/moduleparam.h>
13#include <linux/sched.h>
14
15#include <sound/core.h> 4#include <sound/core.h>
16#include <sound/control.h> 5#include <sound/control.h>
17#include <sound/pcm.h>
18#include <sound/pcm_params.h>
19#include <sound/rawmidi.h>
20#include <sound/initval.h>
21#include <sound/tlv.h> 6#include <sound/tlv.h>
22#include <sound/asoundef.h> 7#include <sound/asoundef.h>
23 8
@@ -27,6 +12,21 @@
27#define CTRL_VOL_MAX 400 12#define CTRL_VOL_MAX 400
28#define CTRL_VOL_MIN -10239 /* originally -10240 */ 13#define CTRL_VOL_MIN -10239 /* originally -10240 */
29 14
15static int bcm2835_audio_set_chip_ctls(struct bcm2835_chip *chip)
16{
17 int i, err = 0;
18
19 /* change ctls for all substreams */
20 for (i = 0; i < MAX_SUBSTREAMS; i++) {
21 if (chip->alsa_stream[i]) {
22 err = bcm2835_audio_set_ctls(chip->alsa_stream[i]);
23 if (err < 0)
24 break;
25 }
26 }
27 return err;
28}
29
30static int snd_bcm2835_ctl_info(struct snd_kcontrol *kcontrol, 30static int snd_bcm2835_ctl_info(struct snd_kcontrol *kcontrol,
31 struct snd_ctl_elem_info *uinfo) 31 struct snd_ctl_elem_info *uinfo)
32{ 32{
@@ -49,41 +49,15 @@ static int snd_bcm2835_ctl_info(struct snd_kcontrol *kcontrol,
49 return 0; 49 return 0;
50} 50}
51 51
52/* toggles mute on or off depending on the value of nmute, and returns
53 * 1 if the mute value was changed, otherwise 0
54 */
55static int toggle_mute(struct bcm2835_chip *chip, int nmute)
56{
57 /* if settings are ok, just return 0 */
58 if (chip->mute == nmute)
59 return 0;
60
61 /* if the sound is muted then we need to unmute */
62 if (chip->mute == CTRL_VOL_MUTE) {
63 chip->volume = chip->old_volume; /* copy the old volume back */
64 audio_info("Unmuting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
65 } else /* otherwise we mute */ {
66 chip->old_volume = chip->volume;
67 chip->volume = 26214; /* set volume to minimum level AKA mute */
68 audio_info("Muting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
69 }
70
71 chip->mute = nmute;
72 return 1;
73}
74
75static int snd_bcm2835_ctl_get(struct snd_kcontrol *kcontrol, 52static int snd_bcm2835_ctl_get(struct snd_kcontrol *kcontrol,
76 struct snd_ctl_elem_value *ucontrol) 53 struct snd_ctl_elem_value *ucontrol)
77{ 54{
78 struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol); 55 struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
79 56
80 if (mutex_lock_interruptible(&chip->audio_mutex)) 57 mutex_lock(&chip->audio_mutex);
81 return -EINTR;
82
83 BUG_ON(!chip && !(chip->avail_substreams & AVAIL_SUBSTREAMS_MASK));
84 58
85 if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) 59 if (kcontrol->private_value == PCM_PLAYBACK_VOLUME)
86 ucontrol->value.integer.value[0] = chip2alsa(chip->volume); 60 ucontrol->value.integer.value[0] = chip->volume;
87 else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) 61 else if (kcontrol->private_value == PCM_PLAYBACK_MUTE)
88 ucontrol->value.integer.value[0] = chip->mute; 62 ucontrol->value.integer.value[0] = chip->mute;
89 else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) 63 else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE)
@@ -97,79 +71,60 @@ static int snd_bcm2835_ctl_put(struct snd_kcontrol *kcontrol,
97 struct snd_ctl_elem_value *ucontrol) 71 struct snd_ctl_elem_value *ucontrol)
98{ 72{
99 struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol); 73 struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
74 int val, *valp;
100 int changed = 0; 75 int changed = 0;
101 76
102 if (mutex_lock_interruptible(&chip->audio_mutex)) 77 if (kcontrol->private_value == PCM_PLAYBACK_VOLUME)
103 return -EINTR; 78 valp = &chip->volume;
104 79 else if (kcontrol->private_value == PCM_PLAYBACK_MUTE)
105 if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) { 80 valp = &chip->mute;
106 audio_info("Volume change attempted.. volume = %d new_volume = %d\n", chip->volume, (int)ucontrol->value.integer.value[0]); 81 else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE)
107 if (chip->mute == CTRL_VOL_MUTE) { 82 valp = &chip->dest;
108 /* changed = toggle_mute(chip, CTRL_VOL_UNMUTE); */ 83 else
109 changed = 1; /* should return 0 to signify no change but the mixer takes this as the opposite sign (no idea why) */ 84 return -EINVAL;
110 goto unlock; 85
111 } 86 val = ucontrol->value.integer.value[0];
112 if (changed || (ucontrol->value.integer.value[0] != chip2alsa(chip->volume))) { 87 mutex_lock(&chip->audio_mutex);
113 chip->volume = alsa2chip(ucontrol->value.integer.value[0]); 88 if (val != *valp) {
114 changed = 1; 89 *valp = val;
115 } 90 changed = 1;
116 91 if (bcm2835_audio_set_chip_ctls(chip))
117 } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) { 92 dev_err(chip->card->dev, "Failed to set ALSA controls..\n");
118 /* Now implemented */
119 audio_info(" Mute attempted\n");
120 changed = toggle_mute(chip, ucontrol->value.integer.value[0]);
121
122 } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) {
123 if (ucontrol->value.integer.value[0] != chip->dest) {
124 chip->dest = ucontrol->value.integer.value[0];
125 changed = 1;
126 }
127 } 93 }
128
129 if (changed && bcm2835_audio_set_ctls(chip))
130 dev_err(chip->card->dev, "Failed to set ALSA controls..\n");
131
132unlock:
133 mutex_unlock(&chip->audio_mutex); 94 mutex_unlock(&chip->audio_mutex);
134 return changed; 95 return changed;
135} 96}
136 97
137static DECLARE_TLV_DB_SCALE(snd_bcm2835_db_scale, CTRL_VOL_MIN, 1, 1); 98static DECLARE_TLV_DB_SCALE(snd_bcm2835_db_scale, CTRL_VOL_MIN, 1, 1);
138 99
139static struct snd_kcontrol_new snd_bcm2835_ctl[] = { 100static const struct snd_kcontrol_new snd_bcm2835_ctl[] = {
140 { 101 {
141 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 102 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
142 .name = "PCM Playback Volume", 103 .name = "PCM Playback Volume",
143 .index = 0,
144 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, 104 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
145 .private_value = PCM_PLAYBACK_VOLUME, 105 .private_value = PCM_PLAYBACK_VOLUME,
146 .info = snd_bcm2835_ctl_info, 106 .info = snd_bcm2835_ctl_info,
147 .get = snd_bcm2835_ctl_get, 107 .get = snd_bcm2835_ctl_get,
148 .put = snd_bcm2835_ctl_put, 108 .put = snd_bcm2835_ctl_put,
149 .count = 1,
150 .tlv = {.p = snd_bcm2835_db_scale} 109 .tlv = {.p = snd_bcm2835_db_scale}
151 }, 110 },
152 { 111 {
153 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 112 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
154 .name = "PCM Playback Switch", 113 .name = "PCM Playback Switch",
155 .index = 0,
156 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, 114 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
157 .private_value = PCM_PLAYBACK_MUTE, 115 .private_value = PCM_PLAYBACK_MUTE,
158 .info = snd_bcm2835_ctl_info, 116 .info = snd_bcm2835_ctl_info,
159 .get = snd_bcm2835_ctl_get, 117 .get = snd_bcm2835_ctl_get,
160 .put = snd_bcm2835_ctl_put, 118 .put = snd_bcm2835_ctl_put,
161 .count = 1,
162 }, 119 },
163 { 120 {
164 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 121 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
165 .name = "PCM Playback Route", 122 .name = "PCM Playback Route",
166 .index = 0,
167 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, 123 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
168 .private_value = PCM_PLAYBACK_DEVICE, 124 .private_value = PCM_PLAYBACK_DEVICE,
169 .info = snd_bcm2835_ctl_info, 125 .info = snd_bcm2835_ctl_info,
170 .get = snd_bcm2835_ctl_get, 126 .get = snd_bcm2835_ctl_get,
171 .put = snd_bcm2835_ctl_put, 127 .put = snd_bcm2835_ctl_put,
172 .count = 1,
173 }, 128 },
174}; 129};
175 130
@@ -187,8 +142,7 @@ static int snd_bcm2835_spdif_default_get(struct snd_kcontrol *kcontrol,
187 struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol); 142 struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
188 int i; 143 int i;
189 144
190 if (mutex_lock_interruptible(&chip->audio_mutex)) 145 mutex_lock(&chip->audio_mutex);
191 return -EINTR;
192 146
193 for (i = 0; i < 4; i++) 147 for (i = 0; i < 4; i++)
194 ucontrol->value.iec958.status[i] = 148 ucontrol->value.iec958.status[i] =
@@ -205,8 +159,7 @@ static int snd_bcm2835_spdif_default_put(struct snd_kcontrol *kcontrol,
205 unsigned int val = 0; 159 unsigned int val = 0;
206 int i, change; 160 int i, change;
207 161
208 if (mutex_lock_interruptible(&chip->audio_mutex)) 162 mutex_lock(&chip->audio_mutex);
209 return -EINTR;
210 163
211 for (i = 0; i < 4; i++) 164 for (i = 0; i < 4; i++)
212 val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8); 165 val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8);
@@ -237,51 +190,7 @@ static int snd_bcm2835_spdif_mask_get(struct snd_kcontrol *kcontrol,
237 return 0; 190 return 0;
238} 191}
239 192
240static int snd_bcm2835_spdif_stream_info(struct snd_kcontrol *kcontrol, 193static const struct snd_kcontrol_new snd_bcm2835_spdif[] = {
241 struct snd_ctl_elem_info *uinfo)
242{
243 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
244 uinfo->count = 1;
245 return 0;
246}
247
248static int snd_bcm2835_spdif_stream_get(struct snd_kcontrol *kcontrol,
249 struct snd_ctl_elem_value *ucontrol)
250{
251 struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
252 int i;
253
254 if (mutex_lock_interruptible(&chip->audio_mutex))
255 return -EINTR;
256
257 for (i = 0; i < 4; i++)
258 ucontrol->value.iec958.status[i] =
259 (chip->spdif_status >> (i * 8)) & 0xff;
260
261 mutex_unlock(&chip->audio_mutex);
262 return 0;
263}
264
265static int snd_bcm2835_spdif_stream_put(struct snd_kcontrol *kcontrol,
266 struct snd_ctl_elem_value *ucontrol)
267{
268 struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
269 unsigned int val = 0;
270 int i, change;
271
272 if (mutex_lock_interruptible(&chip->audio_mutex))
273 return -EINTR;
274
275 for (i = 0; i < 4; i++)
276 val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8);
277 change = val != chip->spdif_status;
278 chip->spdif_status = val;
279
280 mutex_unlock(&chip->audio_mutex);
281 return change;
282}
283
284static struct snd_kcontrol_new snd_bcm2835_spdif[] = {
285 { 194 {
286 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 195 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
287 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT), 196 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
@@ -296,39 +205,34 @@ static struct snd_kcontrol_new snd_bcm2835_spdif[] = {
296 .info = snd_bcm2835_spdif_mask_info, 205 .info = snd_bcm2835_spdif_mask_info,
297 .get = snd_bcm2835_spdif_mask_get, 206 .get = snd_bcm2835_spdif_mask_get,
298 }, 207 },
299 {
300 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
301 SNDRV_CTL_ELEM_ACCESS_INACTIVE,
302 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
303 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM),
304 .info = snd_bcm2835_spdif_stream_info,
305 .get = snd_bcm2835_spdif_stream_get,
306 .put = snd_bcm2835_spdif_stream_put,
307 },
308}; 208};
309 209
310int snd_bcm2835_new_ctl(struct bcm2835_chip *chip) 210static int create_ctls(struct bcm2835_chip *chip, size_t size,
211 const struct snd_kcontrol_new *kctls)
311{ 212{
312 int err; 213 int i, err;
313 unsigned int idx;
314 214
315 strcpy(chip->card->mixername, "Broadcom Mixer"); 215 for (i = 0; i < size; i++) {
316 for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_ctl); idx++) { 216 err = snd_ctl_add(chip->card, snd_ctl_new1(&kctls[i], chip));
317 err = snd_ctl_add(chip->card,
318 snd_ctl_new1(&snd_bcm2835_ctl[idx], chip));
319 if (err < 0)
320 return err;
321 }
322 for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_spdif); idx++) {
323 err = snd_ctl_add(chip->card,
324 snd_ctl_new1(&snd_bcm2835_spdif[idx], chip));
325 if (err < 0) 217 if (err < 0)
326 return err; 218 return err;
327 } 219 }
328 return 0; 220 return 0;
329} 221}
330 222
331static struct snd_kcontrol_new snd_bcm2835_headphones_ctl[] = { 223int snd_bcm2835_new_ctl(struct bcm2835_chip *chip)
224{
225 int err;
226
227 strcpy(chip->card->mixername, "Broadcom Mixer");
228 err = create_ctls(chip, ARRAY_SIZE(snd_bcm2835_ctl), snd_bcm2835_ctl);
229 if (err < 0)
230 return err;
231 return create_ctls(chip, ARRAY_SIZE(snd_bcm2835_spdif),
232 snd_bcm2835_spdif);
233}
234
235static const struct snd_kcontrol_new snd_bcm2835_headphones_ctl[] = {
332 { 236 {
333 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 237 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
334 .name = "Headphone Playback Volume", 238 .name = "Headphone Playback Volume",
@@ -357,21 +261,12 @@ static struct snd_kcontrol_new snd_bcm2835_headphones_ctl[] = {
357 261
358int snd_bcm2835_new_headphones_ctl(struct bcm2835_chip *chip) 262int snd_bcm2835_new_headphones_ctl(struct bcm2835_chip *chip)
359{ 263{
360 int err;
361 unsigned int idx;
362
363 strcpy(chip->card->mixername, "Broadcom Mixer"); 264 strcpy(chip->card->mixername, "Broadcom Mixer");
364 for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_headphones_ctl); idx++) { 265 return create_ctls(chip, ARRAY_SIZE(snd_bcm2835_headphones_ctl),
365 err = snd_ctl_add(chip->card, 266 snd_bcm2835_headphones_ctl);
366 snd_ctl_new1(&snd_bcm2835_headphones_ctl[idx],
367 chip));
368 if (err)
369 return err;
370 }
371 return 0;
372} 267}
373 268
374static struct snd_kcontrol_new snd_bcm2835_hdmi[] = { 269static const struct snd_kcontrol_new snd_bcm2835_hdmi[] = {
375 { 270 {
376 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 271 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
377 .name = "HDMI Playback Volume", 272 .name = "HDMI Playback Volume",
@@ -400,16 +295,8 @@ static struct snd_kcontrol_new snd_bcm2835_hdmi[] = {
400 295
401int snd_bcm2835_new_hdmi_ctl(struct bcm2835_chip *chip) 296int snd_bcm2835_new_hdmi_ctl(struct bcm2835_chip *chip)
402{ 297{
403 int err;
404 unsigned int idx;
405
406 strcpy(chip->card->mixername, "Broadcom Mixer"); 298 strcpy(chip->card->mixername, "Broadcom Mixer");
407 for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_hdmi); idx++) { 299 return create_ctls(chip, ARRAY_SIZE(snd_bcm2835_hdmi),
408 err = snd_ctl_add(chip->card, 300 snd_bcm2835_hdmi);
409 snd_ctl_new1(&snd_bcm2835_hdmi[idx], chip));
410 if (err)
411 return err;
412 }
413 return 0;
414} 301}
415 302
diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c
index 8359cf881bef..e66da11af5cf 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c
+++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c
@@ -11,7 +11,8 @@
11/* hardware definition */ 11/* hardware definition */
12static const struct snd_pcm_hardware snd_bcm2835_playback_hw = { 12static const struct snd_pcm_hardware snd_bcm2835_playback_hw = {
13 .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | 13 .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
14 SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID), 14 SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
15 SNDRV_PCM_INFO_DRAIN_TRIGGER | SNDRV_PCM_INFO_SYNC_APPLPTR),
15 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE, 16 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
16 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, 17 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
17 .rate_min = 8000, 18 .rate_min = 8000,
@@ -27,7 +28,8 @@ static const struct snd_pcm_hardware snd_bcm2835_playback_hw = {
27 28
28static const struct snd_pcm_hardware snd_bcm2835_playback_spdif_hw = { 29static const struct snd_pcm_hardware snd_bcm2835_playback_spdif_hw = {
29 .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | 30 .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
30 SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID), 31 SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
32 SNDRV_PCM_INFO_DRAIN_TRIGGER | SNDRV_PCM_INFO_SYNC_APPLPTR),
31 .formats = SNDRV_PCM_FMTBIT_S16_LE, 33 .formats = SNDRV_PCM_FMTBIT_S16_LE,
32 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_44100 | 34 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_44100 |
33 SNDRV_PCM_RATE_48000, 35 SNDRV_PCM_RATE_48000,
@@ -44,48 +46,37 @@ static const struct snd_pcm_hardware snd_bcm2835_playback_spdif_hw = {
44 46
45static void snd_bcm2835_playback_free(struct snd_pcm_runtime *runtime) 47static void snd_bcm2835_playback_free(struct snd_pcm_runtime *runtime)
46{ 48{
47 audio_info("Freeing up alsa stream here ..\n");
48 kfree(runtime->private_data); 49 kfree(runtime->private_data);
49 runtime->private_data = NULL;
50} 50}
51 51
52void bcm2835_playback_fifo(struct bcm2835_alsa_stream *alsa_stream) 52void bcm2835_playback_fifo(struct bcm2835_alsa_stream *alsa_stream,
53 unsigned int bytes)
53{ 54{
54 unsigned int consumed = 0; 55 struct snd_pcm_substream *substream = alsa_stream->substream;
55 int new_period = 0; 56 unsigned int pos;
56 57
57 audio_info("alsa_stream=%p substream=%p\n", alsa_stream, 58 if (!alsa_stream->period_size)
58 alsa_stream ? alsa_stream->substream : 0); 59 return;
59 60
60 if (alsa_stream->open) 61 if (bytes >= alsa_stream->buffer_size) {
61 consumed = bcm2835_audio_retrieve_buffers(alsa_stream); 62 snd_pcm_stream_lock(substream);
62 63 snd_pcm_stop(substream,
63 /* We get called only if playback was triggered, So, the number of buffers we retrieve in 64 alsa_stream->draining ?
64 * each iteration are the buffers that have been played out already 65 SNDRV_PCM_STATE_SETUP :
65 */ 66 SNDRV_PCM_STATE_XRUN);
66 67 snd_pcm_stream_unlock(substream);
67 if (alsa_stream->period_size) { 68 return;
68 if ((alsa_stream->pos / alsa_stream->period_size) !=
69 ((alsa_stream->pos + consumed) / alsa_stream->period_size))
70 new_period = 1;
71 }
72 audio_debug("updating pos cur: %d + %d max:%d period_bytes:%d, hw_ptr: %d new_period:%d\n",
73 alsa_stream->pos,
74 consumed,
75 alsa_stream->buffer_size,
76 (int) (alsa_stream->period_size * alsa_stream->substream->runtime->periods),
77 frames_to_bytes(alsa_stream->substream->runtime, alsa_stream->substream->runtime->status->hw_ptr),
78 new_period);
79 if (alsa_stream->buffer_size) {
80 alsa_stream->pos += consumed & ~(1 << 30);
81 alsa_stream->pos %= alsa_stream->buffer_size;
82 } 69 }
83 70
84 if (alsa_stream->substream) { 71 pos = atomic_read(&alsa_stream->pos);
85 if (new_period) 72 pos += bytes;
86 snd_pcm_period_elapsed(alsa_stream->substream); 73 pos %= alsa_stream->buffer_size;
87 } else { 74 atomic_set(&alsa_stream->pos, pos);
88 audio_warning(" unexpected NULL substream\n"); 75
76 alsa_stream->period_offset += bytes;
77 if (alsa_stream->period_offset >= alsa_stream->period_size) {
78 alsa_stream->period_offset %= alsa_stream->period_size;
79 snd_pcm_period_elapsed(substream);
89 } 80 }
90} 81}
91 82
@@ -99,11 +90,7 @@ static int snd_bcm2835_playback_open_generic(
99 int idx; 90 int idx;
100 int err; 91 int err;
101 92
102 if (mutex_lock_interruptible(&chip->audio_mutex)) { 93 mutex_lock(&chip->audio_mutex);
103 audio_error("Interrupted whilst waiting for lock\n");
104 return -EINTR;
105 }
106 audio_info("Alsa open (%d)\n", substream->number);
107 idx = substream->number; 94 idx = substream->number;
108 95
109 if (spdif && chip->opened) { 96 if (spdif && chip->opened) {
@@ -114,21 +101,13 @@ static int snd_bcm2835_playback_open_generic(
114 goto out; 101 goto out;
115 } 102 }
116 if (idx >= MAX_SUBSTREAMS) { 103 if (idx >= MAX_SUBSTREAMS) {
117 audio_error 104 dev_err(chip->dev,
118 ("substream(%d) device doesn't exist max(%d) substreams allowed\n", 105 "substream(%d) device doesn't exist max(%d) substreams allowed\n",
119 idx, MAX_SUBSTREAMS); 106 idx, MAX_SUBSTREAMS);
120 err = -ENODEV; 107 err = -ENODEV;
121 goto out; 108 goto out;
122 } 109 }
123 110
124 /* Check if we are ready */
125 if (!(chip->avail_substreams & (1 << idx))) {
126 /* We are not ready yet */
127 audio_error("substream(%d) device is not ready yet\n", idx);
128 err = -EAGAIN;
129 goto out;
130 }
131
132 alsa_stream = kzalloc(sizeof(*alsa_stream), GFP_KERNEL); 111 alsa_stream = kzalloc(sizeof(*alsa_stream), GFP_KERNEL);
133 if (!alsa_stream) { 112 if (!alsa_stream) {
134 err = -ENOMEM; 113 err = -ENOMEM;
@@ -140,8 +119,6 @@ static int snd_bcm2835_playback_open_generic(
140 alsa_stream->substream = substream; 119 alsa_stream->substream = substream;
141 alsa_stream->idx = idx; 120 alsa_stream->idx = idx;
142 121
143 spin_lock_init(&alsa_stream->lock);
144
145 err = bcm2835_audio_open(alsa_stream); 122 err = bcm2835_audio_open(alsa_stream);
146 if (err) { 123 if (err) {
147 kfree(alsa_stream); 124 kfree(alsa_stream);
@@ -162,11 +139,14 @@ static int snd_bcm2835_playback_open_generic(
162 SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 139 SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
163 16); 140 16);
164 141
142 /* position update is in 10ms order */
143 snd_pcm_hw_constraint_minmax(runtime,
144 SNDRV_PCM_HW_PARAM_PERIOD_TIME,
145 10 * 1000, UINT_MAX);
146
165 chip->alsa_stream[idx] = alsa_stream; 147 chip->alsa_stream[idx] = alsa_stream;
166 148
167 chip->opened |= (1 << idx); 149 chip->opened |= (1 << idx);
168 alsa_stream->open = 1;
169 alsa_stream->draining = 1;
170 150
171out: 151out:
172 mutex_unlock(&chip->audio_mutex); 152 mutex_unlock(&chip->audio_mutex);
@@ -194,37 +174,15 @@ static int snd_bcm2835_playback_close(struct snd_pcm_substream *substream)
194 struct bcm2835_alsa_stream *alsa_stream; 174 struct bcm2835_alsa_stream *alsa_stream;
195 175
196 chip = snd_pcm_substream_chip(substream); 176 chip = snd_pcm_substream_chip(substream);
197 if (mutex_lock_interruptible(&chip->audio_mutex)) { 177 mutex_lock(&chip->audio_mutex);
198 audio_error("Interrupted whilst waiting for lock\n");
199 return -EINTR;
200 }
201 runtime = substream->runtime; 178 runtime = substream->runtime;
202 alsa_stream = runtime->private_data; 179 alsa_stream = runtime->private_data;
203 180
204 audio_info("Alsa close\n");
205
206 /*
207 * Call stop if it's still running. This happens when app
208 * is force killed and we don't get a stop trigger.
209 */
210 if (alsa_stream->running) {
211 int err;
212
213 err = bcm2835_audio_stop(alsa_stream);
214 alsa_stream->running = 0;
215 if (err)
216 audio_error(" Failed to STOP alsa device\n");
217 }
218
219 alsa_stream->period_size = 0; 181 alsa_stream->period_size = 0;
220 alsa_stream->buffer_size = 0; 182 alsa_stream->buffer_size = 0;
221 183
222 if (alsa_stream->open) { 184 bcm2835_audio_close(alsa_stream);
223 alsa_stream->open = 0; 185 alsa_stream->chip->alsa_stream[alsa_stream->idx] = NULL;
224 bcm2835_audio_close(alsa_stream);
225 }
226 if (alsa_stream->chip)
227 alsa_stream->chip->alsa_stream[alsa_stream->idx] = NULL;
228 /* 186 /*
229 * Do not free up alsa_stream here, it will be freed up by 187 * Do not free up alsa_stream here, it will be freed up by
230 * runtime->private_free callback we registered in *_open above 188 * runtime->private_free callback we registered in *_open above
@@ -241,22 +199,7 @@ static int snd_bcm2835_playback_close(struct snd_pcm_substream *substream)
241static int snd_bcm2835_pcm_hw_params(struct snd_pcm_substream *substream, 199static int snd_bcm2835_pcm_hw_params(struct snd_pcm_substream *substream,
242 struct snd_pcm_hw_params *params) 200 struct snd_pcm_hw_params *params)
243{ 201{
244 struct snd_pcm_runtime *runtime = substream->runtime; 202 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
245 struct bcm2835_alsa_stream *alsa_stream = runtime->private_data;
246 int err;
247
248 err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
249 if (err < 0) {
250 audio_error
251 (" pcm_lib_malloc failed to allocated pages for buffers\n");
252 return err;
253 }
254
255 alsa_stream->channels = params_channels(params);
256 alsa_stream->params_rate = params_rate(params);
257 alsa_stream->pcm_format_width = snd_pcm_format_width(params_format(params));
258
259 return err;
260} 203}
261 204
262/* hw_free callback */ 205/* hw_free callback */
@@ -274,9 +217,6 @@ static int snd_bcm2835_pcm_prepare(struct snd_pcm_substream *substream)
274 int channels; 217 int channels;
275 int err; 218 int err;
276 219
277 if (mutex_lock_interruptible(&chip->audio_mutex))
278 return -EINTR;
279
280 /* notify the vchiq that it should enter spdif passthrough mode by 220 /* notify the vchiq that it should enter spdif passthrough mode by
281 * setting channels=0 (see 221 * setting channels=0 (see
282 * https://github.com/raspberrypi/linux/issues/528) 222 * https://github.com/raspberrypi/linux/issues/528)
@@ -284,18 +224,13 @@ static int snd_bcm2835_pcm_prepare(struct snd_pcm_substream *substream)
284 if (chip->spdif_status & IEC958_AES0_NONAUDIO) 224 if (chip->spdif_status & IEC958_AES0_NONAUDIO)
285 channels = 0; 225 channels = 0;
286 else 226 else
287 channels = alsa_stream->channels; 227 channels = runtime->channels;
288 228
289 err = bcm2835_audio_set_params(alsa_stream, channels, 229 err = bcm2835_audio_set_params(alsa_stream, channels,
290 alsa_stream->params_rate, 230 runtime->rate,
291 alsa_stream->pcm_format_width); 231 snd_pcm_format_width(runtime->format));
292 if (err < 0) 232 if (err < 0)
293 audio_error(" error setting hw params\n"); 233 return err;
294
295 bcm2835_audio_setup(alsa_stream);
296
297 /* in preparation of the stream, set the controls (volume level) of the stream */
298 bcm2835_audio_set_ctls(alsa_stream->chip);
299 234
300 memset(&alsa_stream->pcm_indirect, 0, sizeof(alsa_stream->pcm_indirect)); 235 memset(&alsa_stream->pcm_indirect, 0, sizeof(alsa_stream->pcm_indirect));
301 236
@@ -305,13 +240,10 @@ static int snd_bcm2835_pcm_prepare(struct snd_pcm_substream *substream)
305 240
306 alsa_stream->buffer_size = snd_pcm_lib_buffer_bytes(substream); 241 alsa_stream->buffer_size = snd_pcm_lib_buffer_bytes(substream);
307 alsa_stream->period_size = snd_pcm_lib_period_bytes(substream); 242 alsa_stream->period_size = snd_pcm_lib_period_bytes(substream);
308 alsa_stream->pos = 0; 243 atomic_set(&alsa_stream->pos, 0);
309 244 alsa_stream->period_offset = 0;
310 audio_debug("buffer_size=%d, period_size=%d pos=%d frame_bits=%d\n", 245 alsa_stream->draining = false;
311 alsa_stream->buffer_size, alsa_stream->period_size,
312 alsa_stream->pos, runtime->frame_bits);
313 246
314 mutex_unlock(&chip->audio_mutex);
315 return 0; 247 return 0;
316} 248}
317 249
@@ -321,12 +253,8 @@ static void snd_bcm2835_pcm_transfer(struct snd_pcm_substream *substream,
321 struct snd_pcm_runtime *runtime = substream->runtime; 253 struct snd_pcm_runtime *runtime = substream->runtime;
322 struct bcm2835_alsa_stream *alsa_stream = runtime->private_data; 254 struct bcm2835_alsa_stream *alsa_stream = runtime->private_data;
323 void *src = (void *) (substream->runtime->dma_area + rec->sw_data); 255 void *src = (void *) (substream->runtime->dma_area + rec->sw_data);
324 int err;
325
326 err = bcm2835_audio_write(alsa_stream, bytes, src);
327 if (err)
328 audio_error(" Failed to transfer to alsa device (%d)\n", err);
329 256
257 bcm2835_audio_write(alsa_stream, bytes, src);
330} 258}
331 259
332static int snd_bcm2835_pcm_ack(struct snd_pcm_substream *substream) 260static int snd_bcm2835_pcm_ack(struct snd_pcm_substream *substream)
@@ -335,7 +263,6 @@ static int snd_bcm2835_pcm_ack(struct snd_pcm_substream *substream)
335 struct bcm2835_alsa_stream *alsa_stream = runtime->private_data; 263 struct bcm2835_alsa_stream *alsa_stream = runtime->private_data;
336 struct snd_pcm_indirect *pcm_indirect = &alsa_stream->pcm_indirect; 264 struct snd_pcm_indirect *pcm_indirect = &alsa_stream->pcm_indirect;
337 265
338 pcm_indirect->hw_queue_size = runtime->hw.buffer_bytes_max;
339 return snd_pcm_indirect_playback_transfer(substream, pcm_indirect, 266 return snd_pcm_indirect_playback_transfer(substream, pcm_indirect,
340 snd_bcm2835_pcm_transfer); 267 snd_bcm2835_pcm_transfer);
341} 268}
@@ -345,50 +272,18 @@ static int snd_bcm2835_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
345{ 272{
346 struct snd_pcm_runtime *runtime = substream->runtime; 273 struct snd_pcm_runtime *runtime = substream->runtime;
347 struct bcm2835_alsa_stream *alsa_stream = runtime->private_data; 274 struct bcm2835_alsa_stream *alsa_stream = runtime->private_data;
348 int err = 0;
349 275
350 switch (cmd) { 276 switch (cmd) {
351 case SNDRV_PCM_TRIGGER_START: 277 case SNDRV_PCM_TRIGGER_START:
352 audio_debug("bcm2835_AUDIO_TRIGGER_START running=%d\n", 278 return bcm2835_audio_start(alsa_stream);
353 alsa_stream->running); 279 case SNDRV_PCM_TRIGGER_DRAIN:
354 if (!alsa_stream->running) { 280 alsa_stream->draining = true;
355 err = bcm2835_audio_start(alsa_stream); 281 return bcm2835_audio_drain(alsa_stream);
356 if (!err) {
357 alsa_stream->pcm_indirect.hw_io =
358 alsa_stream->pcm_indirect.hw_data =
359 bytes_to_frames(runtime,
360 alsa_stream->pos);
361 substream->ops->ack(substream);
362 alsa_stream->running = 1;
363 alsa_stream->draining = 1;
364 } else {
365 audio_error(" Failed to START alsa device (%d)\n", err);
366 }
367 }
368 break;
369 case SNDRV_PCM_TRIGGER_STOP: 282 case SNDRV_PCM_TRIGGER_STOP:
370 audio_debug 283 return bcm2835_audio_stop(alsa_stream);
371 ("bcm2835_AUDIO_TRIGGER_STOP running=%d draining=%d\n",
372 alsa_stream->running, runtime->status->state == SNDRV_PCM_STATE_DRAINING);
373 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
374 audio_info("DRAINING\n");
375 alsa_stream->draining = 1;
376 } else {
377 audio_info("DROPPING\n");
378 alsa_stream->draining = 0;
379 }
380 if (alsa_stream->running) {
381 err = bcm2835_audio_stop(alsa_stream);
382 if (err != 0)
383 audio_error(" Failed to STOP alsa device (%d)\n", err);
384 alsa_stream->running = 0;
385 }
386 break;
387 default: 284 default:
388 err = -EINVAL; 285 return -EINVAL;
389 } 286 }
390
391 return err;
392} 287}
393 288
394/* pointer callback */ 289/* pointer callback */
@@ -398,31 +293,16 @@ snd_bcm2835_pcm_pointer(struct snd_pcm_substream *substream)
398 struct snd_pcm_runtime *runtime = substream->runtime; 293 struct snd_pcm_runtime *runtime = substream->runtime;
399 struct bcm2835_alsa_stream *alsa_stream = runtime->private_data; 294 struct bcm2835_alsa_stream *alsa_stream = runtime->private_data;
400 295
401 audio_debug("pcm_pointer... (%d) hwptr=%d appl=%d pos=%d\n", 0,
402 frames_to_bytes(runtime, runtime->status->hw_ptr),
403 frames_to_bytes(runtime, runtime->control->appl_ptr),
404 alsa_stream->pos);
405
406 return snd_pcm_indirect_playback_pointer(substream, 296 return snd_pcm_indirect_playback_pointer(substream,
407 &alsa_stream->pcm_indirect, 297 &alsa_stream->pcm_indirect,
408 alsa_stream->pos); 298 atomic_read(&alsa_stream->pos));
409}
410
411static int snd_bcm2835_pcm_lib_ioctl(struct snd_pcm_substream *substream,
412 unsigned int cmd, void *arg)
413{
414 int ret = snd_pcm_lib_ioctl(substream, cmd, arg);
415
416 audio_info(" .. substream=%p, cmd=%d, arg=%p (%x) ret=%d\n", substream,
417 cmd, arg, arg ? *(unsigned int *)arg : 0, ret);
418 return ret;
419} 299}
420 300
421/* operators */ 301/* operators */
422static const struct snd_pcm_ops snd_bcm2835_playback_ops = { 302static const struct snd_pcm_ops snd_bcm2835_playback_ops = {
423 .open = snd_bcm2835_playback_open, 303 .open = snd_bcm2835_playback_open,
424 .close = snd_bcm2835_playback_close, 304 .close = snd_bcm2835_playback_close,
425 .ioctl = snd_bcm2835_pcm_lib_ioctl, 305 .ioctl = snd_pcm_lib_ioctl,
426 .hw_params = snd_bcm2835_pcm_hw_params, 306 .hw_params = snd_bcm2835_pcm_hw_params,
427 .hw_free = snd_bcm2835_pcm_hw_free, 307 .hw_free = snd_bcm2835_pcm_hw_free,
428 .prepare = snd_bcm2835_pcm_prepare, 308 .prepare = snd_bcm2835_pcm_prepare,
@@ -434,7 +314,7 @@ static const struct snd_pcm_ops snd_bcm2835_playback_ops = {
434static const struct snd_pcm_ops snd_bcm2835_playback_spdif_ops = { 314static const struct snd_pcm_ops snd_bcm2835_playback_spdif_ops = {
435 .open = snd_bcm2835_playback_spdif_open, 315 .open = snd_bcm2835_playback_spdif_open,
436 .close = snd_bcm2835_playback_close, 316 .close = snd_bcm2835_playback_close,
437 .ioctl = snd_bcm2835_pcm_lib_ioctl, 317 .ioctl = snd_pcm_lib_ioctl,
438 .hw_params = snd_bcm2835_pcm_hw_params, 318 .hw_params = snd_bcm2835_pcm_hw_params,
439 .hw_free = snd_bcm2835_pcm_hw_free, 319 .hw_free = snd_bcm2835_pcm_hw_free,
440 .prepare = snd_bcm2835_pcm_prepare, 320 .prepare = snd_bcm2835_pcm_prepare,
@@ -444,104 +324,36 @@ static const struct snd_pcm_ops snd_bcm2835_playback_spdif_ops = {
444}; 324};
445 325
446/* create a pcm device */ 326/* create a pcm device */
447int snd_bcm2835_new_pcm(struct bcm2835_chip *chip, u32 numchannels) 327int snd_bcm2835_new_pcm(struct bcm2835_chip *chip, const char *name,
448{ 328 int idx, enum snd_bcm2835_route route,
449 struct snd_pcm *pcm; 329 u32 numchannels, bool spdif)
450 int err;
451
452 mutex_init(&chip->audio_mutex);
453 if (mutex_lock_interruptible(&chip->audio_mutex)) {
454 audio_error("Interrupted whilst waiting for lock\n");
455 return -EINTR;
456 }
457 err = snd_pcm_new(chip->card, "bcm2835 ALSA", 0, numchannels, 0, &pcm);
458 if (err < 0)
459 goto out;
460 pcm->private_data = chip;
461 strcpy(pcm->name, "bcm2835 ALSA");
462 chip->pcm = pcm;
463 chip->dest = AUDIO_DEST_AUTO;
464 chip->volume = alsa2chip(0);
465 chip->mute = CTRL_VOL_UNMUTE; /*disable mute on startup */
466 /* set operators */
467 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
468 &snd_bcm2835_playback_ops);
469
470 /* pre-allocation of buffers */
471 /* NOTE: this may fail */
472 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
473 snd_dma_continuous_data(GFP_KERNEL),
474 snd_bcm2835_playback_hw.buffer_bytes_max,
475 snd_bcm2835_playback_hw.buffer_bytes_max);
476
477out:
478 mutex_unlock(&chip->audio_mutex);
479
480 return 0;
481}
482
483int snd_bcm2835_new_spdif_pcm(struct bcm2835_chip *chip)
484{ 330{
485 struct snd_pcm *pcm; 331 struct snd_pcm *pcm;
486 int err; 332 int err;
487 333
488 if (mutex_lock_interruptible(&chip->audio_mutex)) { 334 err = snd_pcm_new(chip->card, name, idx, numchannels, 0, &pcm);
489 audio_error("Interrupted whilst waiting for lock\n");
490 return -EINTR;
491 }
492 err = snd_pcm_new(chip->card, "bcm2835 ALSA", 1, 1, 0, &pcm);
493 if (err < 0)
494 goto out;
495
496 pcm->private_data = chip;
497 strcpy(pcm->name, "bcm2835 IEC958/HDMI");
498 chip->pcm_spdif = pcm;
499 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
500 &snd_bcm2835_playback_spdif_ops);
501
502 /* pre-allocation of buffers */
503 /* NOTE: this may fail */
504 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
505 snd_dma_continuous_data(GFP_KERNEL),
506 snd_bcm2835_playback_spdif_hw.buffer_bytes_max, snd_bcm2835_playback_spdif_hw.buffer_bytes_max);
507out:
508 mutex_unlock(&chip->audio_mutex);
509
510 return 0;
511}
512
513int snd_bcm2835_new_simple_pcm(struct bcm2835_chip *chip,
514 const char *name,
515 enum snd_bcm2835_route route,
516 u32 numchannels)
517{
518 struct snd_pcm *pcm;
519 int err;
520
521 mutex_init(&chip->audio_mutex);
522
523 err = snd_pcm_new(chip->card, name, 0, numchannels,
524 0, &pcm);
525 if (err) 335 if (err)
526 return err; 336 return err;
527 337
528 pcm->private_data = chip; 338 pcm->private_data = chip;
339 pcm->nonatomic = true;
529 strcpy(pcm->name, name); 340 strcpy(pcm->name, name);
530 chip->pcm = pcm; 341 if (!spdif) {
531 chip->dest = route; 342 chip->dest = route;
532 chip->volume = alsa2chip(0); 343 chip->volume = 0;
533 chip->mute = CTRL_VOL_UNMUTE; 344 chip->mute = CTRL_VOL_UNMUTE;
345 }
534 346
535 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, 347 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
348 spdif ? &snd_bcm2835_playback_spdif_ops :
536 &snd_bcm2835_playback_ops); 349 &snd_bcm2835_playback_ops);
537 350
538 snd_pcm_lib_preallocate_pages_for_all( 351 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
539 pcm, 352 chip->card->dev, 128 * 1024, 128 * 1024);
540 SNDRV_DMA_TYPE_CONTINUOUS,
541 snd_dma_continuous_data(GFP_KERNEL),
542 snd_bcm2835_playback_hw.buffer_bytes_max,
543 snd_bcm2835_playback_hw.buffer_bytes_max);
544 353
354 if (spdif)
355 chip->pcm_spdif = pcm;
356 else
357 chip->pcm = pcm;
545 return 0; 358 return 0;
546} 359}
547
diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c
index 868e2d6aaf1b..781754f36da7 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c
+++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c
@@ -1,190 +1,99 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0
2/* Copyright 2011 Broadcom Corporation. All rights reserved. */ 2/* Copyright 2011 Broadcom Corporation. All rights reserved. */
3 3
4#include <linux/device.h>
5#include <sound/core.h>
6#include <sound/initval.h>
7#include <sound/pcm.h>
8#include <linux/io.h>
9#include <linux/interrupt.h>
10#include <linux/fs.h>
11#include <linux/file.h>
12#include <linux/mm.h>
13#include <linux/syscalls.h>
14#include <linux/uaccess.h>
15#include <linux/slab.h> 4#include <linux/slab.h>
16#include <linux/delay.h>
17#include <linux/atomic.h>
18#include <linux/module.h> 5#include <linux/module.h>
19#include <linux/completion.h> 6#include <linux/completion.h>
20
21#include "bcm2835.h" 7#include "bcm2835.h"
22
23/* ---- Include Files -------------------------------------------------------- */
24
25#include "vc_vchi_audioserv_defs.h" 8#include "vc_vchi_audioserv_defs.h"
26 9
27/* ---- Private Constants and Types ------------------------------------------ */
28
29#define BCM2835_AUDIO_STOP 0
30#define BCM2835_AUDIO_START 1
31#define BCM2835_AUDIO_WRITE 2
32
33/* Logging macros (for remapping to other logging mechanisms, i.e., printf) */
34#ifdef AUDIO_DEBUG_ENABLE
35#define LOG_ERR(fmt, arg...) pr_err("%s:%d " fmt, __func__, __LINE__, ##arg)
36#define LOG_WARN(fmt, arg...) pr_info("%s:%d " fmt, __func__, __LINE__, ##arg)
37#define LOG_INFO(fmt, arg...) pr_info("%s:%d " fmt, __func__, __LINE__, ##arg)
38#define LOG_DBG(fmt, arg...) pr_info("%s:%d " fmt, __func__, __LINE__, ##arg)
39#else
40#define LOG_ERR(fmt, arg...) pr_err("%s:%d " fmt, __func__, __LINE__, ##arg)
41#define LOG_WARN(fmt, arg...) no_printk(fmt, ##arg)
42#define LOG_INFO(fmt, arg...) no_printk(fmt, ##arg)
43#define LOG_DBG(fmt, arg...) no_printk(fmt, ##arg)
44#endif
45
46struct bcm2835_audio_instance { 10struct bcm2835_audio_instance {
47 unsigned int num_connections; 11 struct device *dev;
48 VCHI_SERVICE_HANDLE_T vchi_handle[VCHI_MAX_NUM_CONNECTIONS]; 12 VCHI_SERVICE_HANDLE_T vchi_handle;
49 struct completion msg_avail_comp; 13 struct completion msg_avail_comp;
50 struct mutex vchi_mutex; 14 struct mutex vchi_mutex;
51 struct bcm2835_alsa_stream *alsa_stream; 15 struct bcm2835_alsa_stream *alsa_stream;
52 int result; 16 int result;
17 unsigned int max_packet;
53 short peer_version; 18 short peer_version;
54}; 19};
55 20
56static bool force_bulk; 21static bool force_bulk;
22module_param(force_bulk, bool, 0444);
23MODULE_PARM_DESC(force_bulk, "Force use of vchiq bulk for audio");
57 24
58/* ---- Private Variables ---------------------------------------------------- */ 25static void bcm2835_audio_lock(struct bcm2835_audio_instance *instance)
59
60/* ---- Private Function Prototypes ------------------------------------------ */
61
62/* ---- Private Functions ---------------------------------------------------- */
63
64static int bcm2835_audio_stop_worker(struct bcm2835_alsa_stream *alsa_stream);
65static int bcm2835_audio_start_worker(struct bcm2835_alsa_stream *alsa_stream);
66static int bcm2835_audio_write_worker(struct bcm2835_alsa_stream *alsa_stream,
67 unsigned int count, void *src);
68
69// Routine to send a message across a service
70
71static int
72bcm2835_vchi_msg_queue(VCHI_SERVICE_HANDLE_T handle,
73 void *data,
74 unsigned int size)
75{ 26{
76 return vchi_queue_kernel_message(handle, 27 mutex_lock(&instance->vchi_mutex);
77 data, 28 vchi_service_use(instance->vchi_handle);
78 size);
79} 29}
80 30
81static const u32 BCM2835_AUDIO_WRITE_COOKIE1 = ('B' << 24 | 'C' << 16 | 31static void bcm2835_audio_unlock(struct bcm2835_audio_instance *instance)
82 'M' << 8 | 'A');
83static const u32 BCM2835_AUDIO_WRITE_COOKIE2 = ('D' << 24 | 'A' << 16 |
84 'T' << 8 | 'A');
85
86struct bcm2835_audio_work {
87 struct work_struct my_work;
88 struct bcm2835_alsa_stream *alsa_stream;
89 int cmd;
90 void *src;
91 unsigned int count;
92};
93
94static void my_wq_function(struct work_struct *work)
95{ 32{
96 struct bcm2835_audio_work *w = 33 vchi_service_release(instance->vchi_handle);
97 container_of(work, struct bcm2835_audio_work, my_work); 34 mutex_unlock(&instance->vchi_mutex);
98 int ret = -9;
99
100 switch (w->cmd) {
101 case BCM2835_AUDIO_START:
102 ret = bcm2835_audio_start_worker(w->alsa_stream);
103 break;
104 case BCM2835_AUDIO_STOP:
105 ret = bcm2835_audio_stop_worker(w->alsa_stream);
106 break;
107 case BCM2835_AUDIO_WRITE:
108 ret = bcm2835_audio_write_worker(w->alsa_stream, w->count,
109 w->src);
110 break;
111 default:
112 LOG_ERR(" Unexpected work: %p:%d\n", w->alsa_stream, w->cmd);
113 break;
114 }
115 kfree((void *)work);
116} 35}
117 36
118int bcm2835_audio_start(struct bcm2835_alsa_stream *alsa_stream) 37static int bcm2835_audio_send_msg_locked(struct bcm2835_audio_instance *instance,
38 struct vc_audio_msg *m, bool wait)
119{ 39{
120 struct bcm2835_audio_work *work; 40 int status;
121 41
122 work = kmalloc(sizeof(*work), GFP_ATOMIC); 42 if (wait) {
123 /*--- Queue some work (item 1) ---*/ 43 instance->result = -1;
124 if (!work) { 44 init_completion(&instance->msg_avail_comp);
125 LOG_ERR(" .. Error: NULL work kmalloc\n");
126 return -ENOMEM;
127 } 45 }
128 INIT_WORK(&work->my_work, my_wq_function);
129 work->alsa_stream = alsa_stream;
130 work->cmd = BCM2835_AUDIO_START;
131 if (!queue_work(alsa_stream->my_wq, &work->my_work)) {
132 kfree(work);
133 return -EBUSY;
134 }
135 return 0;
136}
137
138int bcm2835_audio_stop(struct bcm2835_alsa_stream *alsa_stream)
139{
140 struct bcm2835_audio_work *work;
141 46
142 work = kmalloc(sizeof(*work), GFP_ATOMIC); 47 status = vchi_queue_kernel_message(instance->vchi_handle,
143 /*--- Queue some work (item 1) ---*/ 48 m, sizeof(*m));
144 if (!work) { 49 if (status) {
145 LOG_ERR(" .. Error: NULL work kmalloc\n"); 50 dev_err(instance->dev,
146 return -ENOMEM; 51 "vchi message queue failed: %d, msg=%d\n",
52 status, m->type);
53 return -EIO;
147 } 54 }
148 INIT_WORK(&work->my_work, my_wq_function); 55
149 work->alsa_stream = alsa_stream; 56 if (wait) {
150 work->cmd = BCM2835_AUDIO_STOP; 57 if (!wait_for_completion_timeout(&instance->msg_avail_comp,
151 if (!queue_work(alsa_stream->my_wq, &work->my_work)) { 58 msecs_to_jiffies(10 * 1000))) {
152 kfree(work); 59 dev_err(instance->dev,
153 return -EBUSY; 60 "vchi message timeout, msg=%d\n", m->type);
61 return -ETIMEDOUT;
62 } else if (instance->result) {
63 dev_err(instance->dev,
64 "vchi message response error:%d, msg=%d\n",
65 instance->result, m->type);
66 return -EIO;
67 }
154 } 68 }
69
155 return 0; 70 return 0;
156} 71}
157 72
158int bcm2835_audio_write(struct bcm2835_alsa_stream *alsa_stream, 73static int bcm2835_audio_send_msg(struct bcm2835_audio_instance *instance,
159 unsigned int count, void *src) 74 struct vc_audio_msg *m, bool wait)
160{ 75{
161 struct bcm2835_audio_work *work; 76 int err;
162 77
163 work = kmalloc(sizeof(*work), GFP_ATOMIC); 78 bcm2835_audio_lock(instance);
164 /*--- Queue some work (item 1) ---*/ 79 err = bcm2835_audio_send_msg_locked(instance, m, wait);
165 if (!work) { 80 bcm2835_audio_unlock(instance);
166 LOG_ERR(" .. Error: NULL work kmalloc\n"); 81 return err;
167 return -ENOMEM;
168 }
169 INIT_WORK(&work->my_work, my_wq_function);
170 work->alsa_stream = alsa_stream;
171 work->cmd = BCM2835_AUDIO_WRITE;
172 work->src = src;
173 work->count = count;
174 if (!queue_work(alsa_stream->my_wq, &work->my_work)) {
175 kfree(work);
176 return -EBUSY;
177 }
178 return 0;
179} 82}
180 83
181static void my_workqueue_quit(struct bcm2835_alsa_stream *alsa_stream) 84static int bcm2835_audio_send_simple(struct bcm2835_audio_instance *instance,
85 int type, bool wait)
182{ 86{
183 flush_workqueue(alsa_stream->my_wq); 87 struct vc_audio_msg m = { .type = type };
184 destroy_workqueue(alsa_stream->my_wq); 88
185 alsa_stream->my_wq = NULL; 89 return bcm2835_audio_send_msg(instance, &m, wait);
186} 90}
187 91
92static const u32 BCM2835_AUDIO_WRITE_COOKIE1 = ('B' << 24 | 'C' << 16 |
93 'M' << 8 | 'A');
94static const u32 BCM2835_AUDIO_WRITE_COOKIE2 = ('D' << 24 | 'A' << 16 |
95 'T' << 8 | 'A');
96
188static void audio_vchi_callback(void *param, 97static void audio_vchi_callback(void *param,
189 const VCHI_CALLBACK_REASON_T reason, 98 const VCHI_CALLBACK_REASON_T reason,
190 void *msg_handle) 99 void *msg_handle)
@@ -197,172 +106,87 @@ static void audio_vchi_callback(void *param,
197 if (reason != VCHI_CALLBACK_MSG_AVAILABLE) 106 if (reason != VCHI_CALLBACK_MSG_AVAILABLE)
198 return; 107 return;
199 108
200 if (!instance) { 109 status = vchi_msg_dequeue(instance->vchi_handle,
201 LOG_ERR(" .. instance is null\n");
202 BUG();
203 return;
204 }
205 if (!instance->vchi_handle[0]) {
206 LOG_ERR(" .. instance->vchi_handle[0] is null\n");
207 BUG();
208 return;
209 }
210 status = vchi_msg_dequeue(instance->vchi_handle[0],
211 &m, sizeof(m), &msg_len, VCHI_FLAGS_NONE); 110 &m, sizeof(m), &msg_len, VCHI_FLAGS_NONE);
212 if (m.type == VC_AUDIO_MSG_TYPE_RESULT) { 111 if (m.type == VC_AUDIO_MSG_TYPE_RESULT) {
213 LOG_DBG(" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_RESULT, success=%d\n",
214 instance, m.u.result.success);
215 instance->result = m.u.result.success; 112 instance->result = m.u.result.success;
216 complete(&instance->msg_avail_comp); 113 complete(&instance->msg_avail_comp);
217 } else if (m.type == VC_AUDIO_MSG_TYPE_COMPLETE) { 114 } else if (m.type == VC_AUDIO_MSG_TYPE_COMPLETE) {
218 struct bcm2835_alsa_stream *alsa_stream = instance->alsa_stream;
219
220 LOG_DBG(" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_COMPLETE, complete=%d\n",
221 instance, m.u.complete.count);
222 if (m.u.complete.cookie1 != BCM2835_AUDIO_WRITE_COOKIE1 || 115 if (m.u.complete.cookie1 != BCM2835_AUDIO_WRITE_COOKIE1 ||
223 m.u.complete.cookie2 != BCM2835_AUDIO_WRITE_COOKIE2) 116 m.u.complete.cookie2 != BCM2835_AUDIO_WRITE_COOKIE2)
224 LOG_ERR(" .. response is corrupt\n"); 117 dev_err(instance->dev, "invalid cookie\n");
225 else if (alsa_stream) { 118 else
226 atomic_add(m.u.complete.count, 119 bcm2835_playback_fifo(instance->alsa_stream,
227 &alsa_stream->retrieved); 120 m.u.complete.count);
228 bcm2835_playback_fifo(alsa_stream);
229 } else {
230 LOG_ERR(" .. unexpected alsa_stream=%p\n",
231 alsa_stream);
232 }
233 } else { 121 } else {
234 LOG_ERR(" .. unexpected m.type=%d\n", m.type); 122 dev_err(instance->dev, "unexpected callback type=%d\n", m.type);
235 } 123 }
236} 124}
237 125
238static struct bcm2835_audio_instance * 126static int
239vc_vchi_audio_init(VCHI_INSTANCE_T vchi_instance, 127vc_vchi_audio_init(VCHI_INSTANCE_T vchi_instance,
240 VCHI_CONNECTION_T **vchi_connections, 128 struct bcm2835_audio_instance *instance)
241 unsigned int num_connections)
242{ 129{
243 unsigned int i; 130 SERVICE_CREATION_T params = {
244 struct bcm2835_audio_instance *instance; 131 .version = VCHI_VERSION_EX(VC_AUDIOSERV_VER, VC_AUDIOSERV_MIN_VER),
132 .service_id = VC_AUDIO_SERVER_NAME,
133 .callback = audio_vchi_callback,
134 .callback_param = instance,
135 };
245 int status; 136 int status;
246 int ret;
247
248 LOG_DBG("%s: start", __func__);
249 137
250 if (num_connections > VCHI_MAX_NUM_CONNECTIONS) {
251 LOG_ERR("%s: unsupported number of connections %u (max=%u)\n",
252 __func__, num_connections, VCHI_MAX_NUM_CONNECTIONS);
253
254 return ERR_PTR(-EINVAL);
255 }
256 /* Allocate memory for this instance */
257 instance = kzalloc(sizeof(*instance), GFP_KERNEL);
258 if (!instance)
259 return ERR_PTR(-ENOMEM);
260
261 instance->num_connections = num_connections;
262
263 /* Create a lock for exclusive, serialized VCHI connection access */
264 mutex_init(&instance->vchi_mutex);
265 /* Open the VCHI service connections */ 138 /* Open the VCHI service connections */
266 for (i = 0; i < num_connections; i++) { 139 status = vchi_service_open(vchi_instance, &params,
267 SERVICE_CREATION_T params = { 140 &instance->vchi_handle);
268 .version = VCHI_VERSION_EX(VC_AUDIOSERV_VER, VC_AUDIOSERV_MIN_VER),
269 .service_id = VC_AUDIO_SERVER_NAME,
270 .connection = vchi_connections[i],
271 .rx_fifo_size = 0,
272 .tx_fifo_size = 0,
273 .callback = audio_vchi_callback,
274 .callback_param = instance,
275 .want_unaligned_bulk_rx = 1, //TODO: remove VCOS_FALSE
276 .want_unaligned_bulk_tx = 1, //TODO: remove VCOS_FALSE
277 .want_crc = 0
278 };
279
280 LOG_DBG("%s: about to open %i\n", __func__, i);
281 status = vchi_service_open(vchi_instance, &params,
282 &instance->vchi_handle[i]);
283
284 LOG_DBG("%s: opened %i: %p=%d\n", __func__, i, instance->vchi_handle[i], status);
285 if (status) {
286 LOG_ERR("%s: failed to open VCHI service connection (status=%d)\n",
287 __func__, status);
288 ret = -EPERM;
289 goto err_close_services;
290 }
291 /* Finished with the service for now */
292 vchi_service_release(instance->vchi_handle[i]);
293 }
294
295 LOG_DBG("%s: okay\n", __func__);
296 return instance;
297 141
298err_close_services: 142 if (status) {
299 for (i = 0; i < instance->num_connections; i++) { 143 dev_err(instance->dev,
300 LOG_ERR("%s: closing %i: %p\n", __func__, i, instance->vchi_handle[i]); 144 "failed to open VCHI service connection (status=%d)\n",
301 if (instance->vchi_handle[i]) 145 status);
302 vchi_service_close(instance->vchi_handle[i]); 146 kfree(instance);
147 return -EPERM;
303 } 148 }
304 149
305 kfree(instance); 150 /* Finished with the service for now */
306 LOG_ERR("%s: error\n", __func__); 151 vchi_service_release(instance->vchi_handle);
307 152
308 return ERR_PTR(ret); 153 return 0;
309} 154}
310 155
311static int vc_vchi_audio_deinit(struct bcm2835_audio_instance *instance) 156static void vc_vchi_audio_deinit(struct bcm2835_audio_instance *instance)
312{ 157{
313 unsigned int i; 158 int status;
314
315 if (!instance) {
316 LOG_ERR("%s: invalid handle %p\n", __func__, instance);
317
318 return -1;
319 }
320 159
321 LOG_DBG(" .. about to lock (%d)\n", instance->num_connections); 160 mutex_lock(&instance->vchi_mutex);
322 if (mutex_lock_interruptible(&instance->vchi_mutex)) { 161 vchi_service_use(instance->vchi_handle);
323 LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",
324 instance->num_connections);
325 return -EINTR;
326 }
327 162
328 /* Close all VCHI service connections */ 163 /* Close all VCHI service connections */
329 for (i = 0; i < instance->num_connections; i++) { 164 status = vchi_service_close(instance->vchi_handle);
330 int status; 165 if (status) {
331 166 dev_err(instance->dev,
332 LOG_DBG(" .. %i:closing %p\n", i, instance->vchi_handle[i]); 167 "failed to close VCHI service connection (status=%d)\n",
333 vchi_service_use(instance->vchi_handle[i]); 168 status);
334
335 status = vchi_service_close(instance->vchi_handle[i]);
336 if (status) {
337 LOG_DBG("%s: failed to close VCHI service connection (status=%d)\n",
338 __func__, status);
339 }
340 } 169 }
341 170
342 mutex_unlock(&instance->vchi_mutex); 171 mutex_unlock(&instance->vchi_mutex);
343
344 kfree(instance);
345
346 return 0;
347} 172}
348 173
349int bcm2835_new_vchi_ctx(struct bcm2835_vchi_ctx *vchi_ctx) 174int bcm2835_new_vchi_ctx(struct device *dev, struct bcm2835_vchi_ctx *vchi_ctx)
350{ 175{
351 int ret; 176 int ret;
352 177
353 /* Initialize and create a VCHI connection */ 178 /* Initialize and create a VCHI connection */
354 ret = vchi_initialise(&vchi_ctx->vchi_instance); 179 ret = vchi_initialise(&vchi_ctx->vchi_instance);
355 if (ret) { 180 if (ret) {
356 LOG_ERR("%s: failed to initialise VCHI instance (ret=%d)\n", 181 dev_err(dev, "failed to initialise VCHI instance (ret=%d)\n",
357 __func__, ret); 182 ret);
358
359 return -EIO; 183 return -EIO;
360 } 184 }
361 185
362 ret = vchi_connect(NULL, 0, vchi_ctx->vchi_instance); 186 ret = vchi_connect(vchi_ctx->vchi_instance);
363 if (ret) { 187 if (ret) {
364 LOG_ERR("%s: failed to connect VCHI instance (ret=%d)\n", 188 dev_dbg(dev, "failed to connect VCHI instance (ret=%d)\n",
365 __func__, ret); 189 ret);
366 190
367 kfree(vchi_ctx->vchi_instance); 191 kfree(vchi_ctx->vchi_instance);
368 vchi_ctx->vchi_instance = NULL; 192 vchi_ctx->vchi_instance = NULL;
@@ -381,473 +205,170 @@ void bcm2835_free_vchi_ctx(struct bcm2835_vchi_ctx *vchi_ctx)
381 vchi_ctx->vchi_instance = NULL; 205 vchi_ctx->vchi_instance = NULL;
382} 206}
383 207
384static int bcm2835_audio_open_connection(struct bcm2835_alsa_stream *alsa_stream)
385{
386 struct bcm2835_audio_instance *instance =
387 (struct bcm2835_audio_instance *)alsa_stream->instance;
388 struct bcm2835_vchi_ctx *vhci_ctx = alsa_stream->chip->vchi_ctx;
389
390 LOG_INFO("%s: start\n", __func__);
391 BUG_ON(instance);
392 if (instance) {
393 LOG_ERR("%s: VCHI instance already open (%p)\n",
394 __func__, instance);
395 instance->alsa_stream = alsa_stream;
396 alsa_stream->instance = instance;
397 return 0;
398 }
399
400 /* Initialize an instance of the audio service */
401 instance = vc_vchi_audio_init(vhci_ctx->vchi_instance,
402 &vhci_ctx->vchi_connection, 1);
403
404 if (IS_ERR(instance)) {
405 LOG_ERR("%s: failed to initialize audio service\n", __func__);
406
407 /* vchi_instance is retained for use the next time. */
408 return PTR_ERR(instance);
409 }
410
411 instance->alsa_stream = alsa_stream;
412 alsa_stream->instance = instance;
413
414 LOG_DBG(" success !\n");
415
416 return 0;
417}
418
419int bcm2835_audio_open(struct bcm2835_alsa_stream *alsa_stream) 208int bcm2835_audio_open(struct bcm2835_alsa_stream *alsa_stream)
420{ 209{
210 struct bcm2835_vchi_ctx *vchi_ctx = alsa_stream->chip->vchi_ctx;
421 struct bcm2835_audio_instance *instance; 211 struct bcm2835_audio_instance *instance;
422 struct vc_audio_msg m; 212 int err;
423 int status;
424 int ret;
425 213
426 alsa_stream->my_wq = alloc_workqueue("my_queue", WQ_HIGHPRI, 1); 214 /* Allocate memory for this instance */
427 if (!alsa_stream->my_wq) 215 instance = kzalloc(sizeof(*instance), GFP_KERNEL);
216 if (!instance)
428 return -ENOMEM; 217 return -ENOMEM;
218 mutex_init(&instance->vchi_mutex);
219 instance->dev = alsa_stream->chip->dev;
220 instance->alsa_stream = alsa_stream;
221 alsa_stream->instance = instance;
429 222
430 ret = bcm2835_audio_open_connection(alsa_stream); 223 err = vc_vchi_audio_init(vchi_ctx->vchi_instance,
431 if (ret) 224 instance);
432 goto free_wq; 225 if (err < 0)
433 226 goto free_instance;
434 instance = alsa_stream->instance;
435 LOG_DBG(" instance (%p)\n", instance);
436
437 if (mutex_lock_interruptible(&instance->vchi_mutex)) {
438 LOG_DBG("Interrupted whilst waiting for lock on (%d)\n", instance->num_connections);
439 ret = -EINTR;
440 goto free_wq;
441 }
442 vchi_service_use(instance->vchi_handle[0]);
443
444 m.type = VC_AUDIO_MSG_TYPE_OPEN;
445
446 /* Send the message to the videocore */
447 status = bcm2835_vchi_msg_queue(instance->vchi_handle[0],
448 &m, sizeof(m));
449
450 if (status) {
451 LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
452 __func__, status);
453
454 ret = -1;
455 goto unlock;
456 }
457 227
458 ret = 0; 228 err = bcm2835_audio_send_simple(instance, VC_AUDIO_MSG_TYPE_OPEN,
229 false);
230 if (err < 0)
231 goto deinit;
459 232
460unlock: 233 bcm2835_audio_lock(instance);
461 vchi_service_release(instance->vchi_handle[0]); 234 vchi_get_peer_version(instance->vchi_handle, &instance->peer_version);
462 mutex_unlock(&instance->vchi_mutex); 235 bcm2835_audio_unlock(instance);
236 if (instance->peer_version < 2 || force_bulk)
237 instance->max_packet = 0; /* bulk transfer */
238 else
239 instance->max_packet = 4000;
463 240
464free_wq: 241 return 0;
465 if (ret)
466 destroy_workqueue(alsa_stream->my_wq);
467 242
468 return ret; 243 deinit:
244 vc_vchi_audio_deinit(instance);
245 free_instance:
246 alsa_stream->instance = NULL;
247 kfree(instance);
248 return err;
469} 249}
470 250
471static int bcm2835_audio_set_ctls_chan(struct bcm2835_alsa_stream *alsa_stream, 251int bcm2835_audio_set_ctls(struct bcm2835_alsa_stream *alsa_stream)
472 struct bcm2835_chip *chip)
473{ 252{
474 struct vc_audio_msg m; 253 struct bcm2835_chip *chip = alsa_stream->chip;
475 struct bcm2835_audio_instance *instance = alsa_stream->instance; 254 struct vc_audio_msg m = {};
476 int status;
477 int ret;
478
479 LOG_INFO(" Setting ALSA dest(%d), volume(%d)\n",
480 chip->dest, chip->volume);
481
482 if (mutex_lock_interruptible(&instance->vchi_mutex)) {
483 LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",
484 instance->num_connections);
485 return -EINTR;
486 }
487 vchi_service_use(instance->vchi_handle[0]);
488
489 instance->result = -1;
490 255
491 m.type = VC_AUDIO_MSG_TYPE_CONTROL; 256 m.type = VC_AUDIO_MSG_TYPE_CONTROL;
492 m.u.control.dest = chip->dest; 257 m.u.control.dest = chip->dest;
493 m.u.control.volume = chip->volume; 258 if (!chip->mute)
259 m.u.control.volume = CHIP_MIN_VOLUME;
260 else
261 m.u.control.volume = alsa2chip(chip->volume);
494 262
495 /* Create the message available completion */ 263 return bcm2835_audio_send_msg(alsa_stream->instance, &m, true);
496 init_completion(&instance->msg_avail_comp);
497
498 /* Send the message to the videocore */
499 status = bcm2835_vchi_msg_queue(instance->vchi_handle[0],
500 &m, sizeof(m));
501
502 if (status) {
503 LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
504 __func__, status);
505
506 ret = -1;
507 goto unlock;
508 }
509
510 /* We are expecting a reply from the videocore */
511 wait_for_completion(&instance->msg_avail_comp);
512
513 if (instance->result) {
514 LOG_ERR("%s: result=%d\n", __func__, instance->result);
515
516 ret = -1;
517 goto unlock;
518 }
519
520 ret = 0;
521
522unlock:
523 vchi_service_release(instance->vchi_handle[0]);
524 mutex_unlock(&instance->vchi_mutex);
525
526 return ret;
527}
528
529int bcm2835_audio_set_ctls(struct bcm2835_chip *chip)
530{
531 int i;
532 int ret = 0;
533
534 LOG_DBG(" Setting ALSA dest(%d), volume(%d)\n", chip->dest, chip->volume);
535
536 /* change ctls for all substreams */
537 for (i = 0; i < MAX_SUBSTREAMS; i++) {
538 if (chip->avail_substreams & (1 << i)) {
539 if (!chip->alsa_stream[i]) {
540 LOG_DBG(" No ALSA stream available?! %i:%p (%x)\n", i, chip->alsa_stream[i], chip->avail_substreams);
541 ret = 0;
542 } else if (bcm2835_audio_set_ctls_chan(chip->alsa_stream[i], chip) != 0) {
543 LOG_ERR("Couldn't set the controls for stream %d\n", i);
544 ret = -1;
545 } else {
546 LOG_DBG(" Controls set for stream %d\n", i);
547 }
548 }
549 }
550 return ret;
551} 264}
552 265
553int bcm2835_audio_set_params(struct bcm2835_alsa_stream *alsa_stream, 266int bcm2835_audio_set_params(struct bcm2835_alsa_stream *alsa_stream,
554 unsigned int channels, unsigned int samplerate, 267 unsigned int channels, unsigned int samplerate,
555 unsigned int bps) 268 unsigned int bps)
556{ 269{
557 struct vc_audio_msg m; 270 struct vc_audio_msg m = {
558 struct bcm2835_audio_instance *instance = alsa_stream->instance; 271 .type = VC_AUDIO_MSG_TYPE_CONFIG,
559 int status; 272 .u.config.channels = channels,
560 int ret; 273 .u.config.samplerate = samplerate,
561 274 .u.config.bps = bps,
562 LOG_INFO(" Setting ALSA channels(%d), samplerate(%d), bits-per-sample(%d)\n", 275 };
563 channels, samplerate, bps); 276 int err;
564 277
565 /* resend ctls - alsa_stream may not have been open when first send */ 278 /* resend ctls - alsa_stream may not have been open when first send */
566 ret = bcm2835_audio_set_ctls_chan(alsa_stream, alsa_stream->chip); 279 err = bcm2835_audio_set_ctls(alsa_stream);
567 if (ret) { 280 if (err)
568 LOG_ERR(" Alsa controls not supported\n"); 281 return err;
569 return -EINVAL;
570 }
571
572 if (mutex_lock_interruptible(&instance->vchi_mutex)) {
573 LOG_DBG("Interrupted whilst waiting for lock on (%d)\n", instance->num_connections);
574 return -EINTR;
575 }
576 vchi_service_use(instance->vchi_handle[0]);
577
578 instance->result = -1;
579 282
580 m.type = VC_AUDIO_MSG_TYPE_CONFIG; 283 return bcm2835_audio_send_msg(alsa_stream->instance, &m, true);
581 m.u.config.channels = channels;
582 m.u.config.samplerate = samplerate;
583 m.u.config.bps = bps;
584
585 /* Create the message available completion */
586 init_completion(&instance->msg_avail_comp);
587
588 /* Send the message to the videocore */
589 status = bcm2835_vchi_msg_queue(instance->vchi_handle[0],
590 &m, sizeof(m));
591
592 if (status) {
593 LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
594 __func__, status);
595
596 ret = -1;
597 goto unlock;
598 }
599
600 /* We are expecting a reply from the videocore */
601 wait_for_completion(&instance->msg_avail_comp);
602
603 if (instance->result) {
604 LOG_ERR("%s: result=%d", __func__, instance->result);
605
606 ret = -1;
607 goto unlock;
608 }
609
610 ret = 0;
611
612unlock:
613 vchi_service_release(instance->vchi_handle[0]);
614 mutex_unlock(&instance->vchi_mutex);
615
616 return ret;
617} 284}
618 285
619int bcm2835_audio_setup(struct bcm2835_alsa_stream *alsa_stream) 286int bcm2835_audio_start(struct bcm2835_alsa_stream *alsa_stream)
620{ 287{
621 288 return bcm2835_audio_send_simple(alsa_stream->instance,
622 return 0; 289 VC_AUDIO_MSG_TYPE_START, false);
623} 290}
624 291
625static int bcm2835_audio_start_worker(struct bcm2835_alsa_stream *alsa_stream) 292int bcm2835_audio_stop(struct bcm2835_alsa_stream *alsa_stream)
626{ 293{
627 struct vc_audio_msg m; 294 return bcm2835_audio_send_simple(alsa_stream->instance,
628 struct bcm2835_audio_instance *instance = alsa_stream->instance; 295 VC_AUDIO_MSG_TYPE_STOP, false);
629 int status;
630 int ret;
631
632 if (mutex_lock_interruptible(&instance->vchi_mutex)) {
633 LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",
634 instance->num_connections);
635 return -EINTR;
636 }
637 vchi_service_use(instance->vchi_handle[0]);
638
639 m.type = VC_AUDIO_MSG_TYPE_START;
640
641 /* Send the message to the videocore */
642 status = bcm2835_vchi_msg_queue(instance->vchi_handle[0],
643 &m, sizeof(m));
644
645 if (status) {
646 LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
647 __func__, status);
648
649 ret = -1;
650 goto unlock;
651 }
652
653 ret = 0;
654
655unlock:
656 vchi_service_release(instance->vchi_handle[0]);
657 mutex_unlock(&instance->vchi_mutex);
658 return ret;
659} 296}
660 297
661static int bcm2835_audio_stop_worker(struct bcm2835_alsa_stream *alsa_stream) 298int bcm2835_audio_drain(struct bcm2835_alsa_stream *alsa_stream)
662{ 299{
663 struct vc_audio_msg m; 300 struct vc_audio_msg m = {
664 struct bcm2835_audio_instance *instance = alsa_stream->instance; 301 .type = VC_AUDIO_MSG_TYPE_STOP,
665 int status; 302 .u.stop.draining = 1,
666 int ret; 303 };
667
668 if (mutex_lock_interruptible(&instance->vchi_mutex)) {
669 LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",
670 instance->num_connections);
671 return -EINTR;
672 }
673 vchi_service_use(instance->vchi_handle[0]);
674
675 m.type = VC_AUDIO_MSG_TYPE_STOP;
676 m.u.stop.draining = alsa_stream->draining;
677
678 /* Send the message to the videocore */
679 status = bcm2835_vchi_msg_queue(instance->vchi_handle[0],
680 &m, sizeof(m));
681
682 if (status) {
683 LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
684 __func__, status);
685 304
686 ret = -1; 305 return bcm2835_audio_send_msg(alsa_stream->instance, &m, false);
687 goto unlock;
688 }
689
690 ret = 0;
691
692unlock:
693 vchi_service_release(instance->vchi_handle[0]);
694 mutex_unlock(&instance->vchi_mutex);
695 return ret;
696} 306}
697 307
698int bcm2835_audio_close(struct bcm2835_alsa_stream *alsa_stream) 308int bcm2835_audio_close(struct bcm2835_alsa_stream *alsa_stream)
699{ 309{
700 struct vc_audio_msg m;
701 struct bcm2835_audio_instance *instance = alsa_stream->instance; 310 struct bcm2835_audio_instance *instance = alsa_stream->instance;
702 int status; 311 int err;
703 int ret;
704 312
705 my_workqueue_quit(alsa_stream); 313 err = bcm2835_audio_send_simple(alsa_stream->instance,
706 314 VC_AUDIO_MSG_TYPE_CLOSE, true);
707 if (mutex_lock_interruptible(&instance->vchi_mutex)) {
708 LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",
709 instance->num_connections);
710 return -EINTR;
711 }
712 vchi_service_use(instance->vchi_handle[0]);
713
714 m.type = VC_AUDIO_MSG_TYPE_CLOSE;
715
716 /* Create the message available completion */
717 init_completion(&instance->msg_avail_comp);
718
719 /* Send the message to the videocore */
720 status = bcm2835_vchi_msg_queue(instance->vchi_handle[0],
721 &m, sizeof(m));
722
723 if (status) {
724 LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
725 __func__, status);
726 ret = -1;
727 goto unlock;
728 }
729
730 /* We are expecting a reply from the videocore */
731 wait_for_completion(&instance->msg_avail_comp);
732
733 if (instance->result) {
734 LOG_ERR("%s: failed result (result=%d)\n",
735 __func__, instance->result);
736
737 ret = -1;
738 goto unlock;
739 }
740
741 ret = 0;
742
743unlock:
744 vchi_service_release(instance->vchi_handle[0]);
745 mutex_unlock(&instance->vchi_mutex);
746 315
747 /* Stop the audio service */ 316 /* Stop the audio service */
748 vc_vchi_audio_deinit(instance); 317 vc_vchi_audio_deinit(instance);
749 alsa_stream->instance = NULL; 318 alsa_stream->instance = NULL;
319 kfree(instance);
750 320
751 return ret; 321 return err;
752} 322}
753 323
754static int bcm2835_audio_write_worker(struct bcm2835_alsa_stream *alsa_stream, 324int bcm2835_audio_write(struct bcm2835_alsa_stream *alsa_stream,
755 unsigned int count, void *src) 325 unsigned int size, void *src)
756{ 326{
757 struct vc_audio_msg m;
758 struct bcm2835_audio_instance *instance = alsa_stream->instance; 327 struct bcm2835_audio_instance *instance = alsa_stream->instance;
759 int status; 328 struct vc_audio_msg m = {
760 int ret; 329 .type = VC_AUDIO_MSG_TYPE_WRITE,
761 330 .u.write.count = size,
762 LOG_INFO(" Writing %d bytes from %p\n", count, src); 331 .u.write.max_packet = instance->max_packet,
763 332 .u.write.cookie1 = BCM2835_AUDIO_WRITE_COOKIE1,
764 if (mutex_lock_interruptible(&instance->vchi_mutex)) { 333 .u.write.cookie2 = BCM2835_AUDIO_WRITE_COOKIE2,
765 LOG_DBG("Interrupted whilst waiting for lock on (%d)\n", 334 };
766 instance->num_connections); 335 unsigned int count;
767 return -EINTR; 336 int err, status;
768 }
769 vchi_service_use(instance->vchi_handle[0]);
770
771 if (instance->peer_version == 0 &&
772 vchi_get_peer_version(instance->vchi_handle[0], &instance->peer_version) == 0)
773 LOG_DBG("%s: client version %d connected\n", __func__, instance->peer_version);
774
775 m.type = VC_AUDIO_MSG_TYPE_WRITE;
776 m.u.write.count = count;
777 // old version uses bulk, new version uses control
778 m.u.write.max_packet = instance->peer_version < 2 || force_bulk ? 0 : 4000;
779 m.u.write.cookie1 = BCM2835_AUDIO_WRITE_COOKIE1;
780 m.u.write.cookie2 = BCM2835_AUDIO_WRITE_COOKIE2;
781 m.u.write.silence = src == NULL;
782
783 /* Send the message to the videocore */
784 status = bcm2835_vchi_msg_queue(instance->vchi_handle[0],
785 &m, sizeof(m));
786 337
787 if (status) { 338 if (!size)
788 LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n", 339 return 0;
789 __func__, status);
790 340
791 ret = -1; 341 bcm2835_audio_lock(instance);
342 err = bcm2835_audio_send_msg_locked(instance, &m, false);
343 if (err < 0)
792 goto unlock; 344 goto unlock;
793 }
794 if (!m.u.write.silence) {
795 if (!m.u.write.max_packet) {
796 /* Send the message to the videocore */
797 status = vchi_bulk_queue_transmit(instance->vchi_handle[0],
798 src, count,
799 0 * VCHI_FLAGS_BLOCK_UNTIL_QUEUED
800 +
801 1 * VCHI_FLAGS_BLOCK_UNTIL_DATA_READ,
802 NULL);
803 } else {
804 while (count > 0) {
805 int bytes = min_t(int, m.u.write.max_packet, count);
806
807 status = bcm2835_vchi_msg_queue(instance->vchi_handle[0],
808 src, bytes);
809 src = (char *)src + bytes;
810 count -= bytes;
811 }
812 }
813 if (status) {
814 LOG_ERR("%s: failed on vchi_bulk_queue_transmit (status=%d)\n",
815 __func__, status);
816 345
817 ret = -1; 346 count = size;
818 goto unlock; 347 if (!instance->max_packet) {
348 /* Send the message to the videocore */
349 status = vchi_bulk_queue_transmit(instance->vchi_handle,
350 src, count,
351 VCHI_FLAGS_BLOCK_UNTIL_DATA_READ,
352 NULL);
353 } else {
354 while (count > 0) {
355 int bytes = min(instance->max_packet, count);
356
357 status = vchi_queue_kernel_message(instance->vchi_handle,
358 src, bytes);
359 src += bytes;
360 count -= bytes;
819 } 361 }
820 } 362 }
821 ret = 0;
822
823unlock:
824 vchi_service_release(instance->vchi_handle[0]);
825 mutex_unlock(&instance->vchi_mutex);
826 return ret;
827}
828
829/**
830 * Returns all buffers from arm->vc
831 */
832void bcm2835_audio_flush_buffers(struct bcm2835_alsa_stream *alsa_stream)
833{
834}
835
836/**
837 * Forces VC to flush(drop) its filled playback buffers and
838 * return them the us. (VC->ARM)
839 */
840void bcm2835_audio_flush_playback_buffers(struct bcm2835_alsa_stream *alsa_stream)
841{
842}
843 363
844unsigned int bcm2835_audio_retrieve_buffers(struct bcm2835_alsa_stream *alsa_stream) 364 if (status) {
845{ 365 dev_err(instance->dev,
846 unsigned int count = atomic_read(&alsa_stream->retrieved); 366 "failed on %d bytes transfer (status=%d)\n",
367 size, status);
368 err = -EIO;
369 }
847 370
848 atomic_sub(count, &alsa_stream->retrieved); 371 unlock:
849 return count; 372 bcm2835_audio_unlock(instance);
373 return err;
850} 374}
851
852module_param(force_bulk, bool, 0444);
853MODULE_PARM_DESC(force_bulk, "Force use of vchiq bulk for audio");
diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
index da0fa34501fa..87d56ab1ffa0 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
+++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
@@ -22,38 +22,6 @@ module_param(enable_compat_alsa, bool, 0444);
22MODULE_PARM_DESC(enable_compat_alsa, 22MODULE_PARM_DESC(enable_compat_alsa,
23 "Enables ALSA compatibility virtual audio device"); 23 "Enables ALSA compatibility virtual audio device");
24 24
25static void snd_devm_unregister_child(struct device *dev, void *res)
26{
27 struct device *childdev = *(struct device **)res;
28 struct bcm2835_chip *chip = dev_get_drvdata(childdev);
29 struct snd_card *card = chip->card;
30
31 snd_card_free(card);
32
33 device_unregister(childdev);
34}
35
36static int snd_devm_add_child(struct device *dev, struct device *child)
37{
38 struct device **dr;
39 int ret;
40
41 dr = devres_alloc(snd_devm_unregister_child, sizeof(*dr), GFP_KERNEL);
42 if (!dr)
43 return -ENOMEM;
44
45 ret = device_add(child);
46 if (ret) {
47 devres_free(dr);
48 return ret;
49 }
50
51 *dr = child;
52 devres_add(dev, dr);
53
54 return 0;
55}
56
57static void bcm2835_devm_free_vchi_ctx(struct device *dev, void *res) 25static void bcm2835_devm_free_vchi_ctx(struct device *dev, void *res)
58{ 26{
59 struct bcm2835_vchi_ctx *vchi_ctx = res; 27 struct bcm2835_vchi_ctx *vchi_ctx = res;
@@ -73,7 +41,7 @@ static int bcm2835_devm_add_vchi_ctx(struct device *dev)
73 41
74 memset(vchi_ctx, 0, sizeof(*vchi_ctx)); 42 memset(vchi_ctx, 0, sizeof(*vchi_ctx));
75 43
76 ret = bcm2835_new_vchi_ctx(vchi_ctx); 44 ret = bcm2835_new_vchi_ctx(dev, vchi_ctx);
77 if (ret) { 45 if (ret) {
78 devres_free(vchi_ctx); 46 devres_free(vchi_ctx);
79 return ret; 47 return ret;
@@ -84,101 +52,6 @@ static int bcm2835_devm_add_vchi_ctx(struct device *dev)
84 return 0; 52 return 0;
85} 53}
86 54
87static void snd_bcm2835_release(struct device *dev)
88{
89 struct bcm2835_chip *chip = dev_get_drvdata(dev);
90
91 kfree(chip);
92}
93
94static struct device *
95snd_create_device(struct device *parent,
96 struct device_driver *driver,
97 const char *name)
98{
99 struct device *device;
100 int ret;
101
102 device = devm_kzalloc(parent, sizeof(*device), GFP_KERNEL);
103 if (!device)
104 return ERR_PTR(-ENOMEM);
105
106 device_initialize(device);
107 device->parent = parent;
108 device->driver = driver;
109 device->release = snd_bcm2835_release;
110
111 dev_set_name(device, "%s", name);
112
113 ret = snd_devm_add_child(parent, device);
114 if (ret)
115 return ERR_PTR(ret);
116
117 return device;
118}
119
120/* component-destructor
121 * (see "Management of Cards and Components")
122 */
123static int snd_bcm2835_dev_free(struct snd_device *device)
124{
125 struct bcm2835_chip *chip = device->device_data;
126 struct snd_card *card = chip->card;
127
128 snd_device_free(card, chip);
129
130 return 0;
131}
132
133/* chip-specific constructor
134 * (see "Management of Cards and Components")
135 */
136static int snd_bcm2835_create(struct snd_card *card,
137 struct bcm2835_chip **rchip)
138{
139 struct bcm2835_chip *chip;
140 int err;
141 static struct snd_device_ops ops = {
142 .dev_free = snd_bcm2835_dev_free,
143 };
144
145 *rchip = NULL;
146
147 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
148 if (!chip)
149 return -ENOMEM;
150
151 chip->card = card;
152
153 chip->vchi_ctx = devres_find(card->dev->parent,
154 bcm2835_devm_free_vchi_ctx, NULL, NULL);
155 if (!chip->vchi_ctx) {
156 kfree(chip);
157 return -ENODEV;
158 }
159
160 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
161 if (err) {
162 kfree(chip);
163 return err;
164 }
165
166 *rchip = chip;
167 return 0;
168}
169
170static struct snd_card *snd_bcm2835_card_new(struct device *dev)
171{
172 struct snd_card *card;
173 int ret;
174
175 ret = snd_card_new(dev, -1, NULL, THIS_MODULE, 0, &card);
176 if (ret)
177 return ERR_PTR(ret);
178
179 return card;
180}
181
182typedef int (*bcm2835_audio_newpcm_func)(struct bcm2835_chip *chip, 55typedef int (*bcm2835_audio_newpcm_func)(struct bcm2835_chip *chip,
183 const char *name, 56 const char *name,
184 enum snd_bcm2835_route route, 57 enum snd_bcm2835_route route,
@@ -203,17 +76,26 @@ static int bcm2835_audio_alsa_newpcm(struct bcm2835_chip *chip,
203{ 76{
204 int err; 77 int err;
205 78
206 err = snd_bcm2835_new_pcm(chip, numchannels - 1); 79 err = snd_bcm2835_new_pcm(chip, "bcm2835 ALSA", 0, AUDIO_DEST_AUTO,
80 numchannels - 1, false);
207 if (err) 81 if (err)
208 return err; 82 return err;
209 83
210 err = snd_bcm2835_new_spdif_pcm(chip); 84 err = snd_bcm2835_new_pcm(chip, "bcm2835 IEC958/HDMI", 1, 0, 1, true);
211 if (err) 85 if (err)
212 return err; 86 return err;
213 87
214 return 0; 88 return 0;
215} 89}
216 90
91static int bcm2835_audio_simple_newpcm(struct bcm2835_chip *chip,
92 const char *name,
93 enum snd_bcm2835_route route,
94 u32 numchannels)
95{
96 return snd_bcm2835_new_pcm(chip, name, 0, route, numchannels, false);
97}
98
217static struct bcm2835_audio_driver bcm2835_audio_alsa = { 99static struct bcm2835_audio_driver bcm2835_audio_alsa = {
218 .driver = { 100 .driver = {
219 .name = "bcm2835_alsa", 101 .name = "bcm2835_alsa",
@@ -234,7 +116,7 @@ static struct bcm2835_audio_driver bcm2835_audio_hdmi = {
234 .shortname = "bcm2835 HDMI", 116 .shortname = "bcm2835 HDMI",
235 .longname = "bcm2835 HDMI", 117 .longname = "bcm2835 HDMI",
236 .minchannels = 1, 118 .minchannels = 1,
237 .newpcm = snd_bcm2835_new_simple_pcm, 119 .newpcm = bcm2835_audio_simple_newpcm,
238 .newctl = snd_bcm2835_new_hdmi_ctl, 120 .newctl = snd_bcm2835_new_hdmi_ctl,
239 .route = AUDIO_DEST_HDMI 121 .route = AUDIO_DEST_HDMI
240}; 122};
@@ -247,7 +129,7 @@ static struct bcm2835_audio_driver bcm2835_audio_headphones = {
247 .shortname = "bcm2835 Headphones", 129 .shortname = "bcm2835 Headphones",
248 .longname = "bcm2835 Headphones", 130 .longname = "bcm2835 Headphones",
249 .minchannels = 1, 131 .minchannels = 1,
250 .newpcm = snd_bcm2835_new_simple_pcm, 132 .newpcm = bcm2835_audio_simple_newpcm,
251 .newctl = snd_bcm2835_new_headphones_ctl, 133 .newctl = snd_bcm2835_new_headphones_ctl,
252 .route = AUDIO_DEST_HEADPHONES 134 .route = AUDIO_DEST_HEADPHONES
253}; 135};
@@ -272,71 +154,75 @@ static struct bcm2835_audio_drivers children_devices[] = {
272 }, 154 },
273}; 155};
274 156
275static int snd_add_child_device(struct device *device, 157static void bcm2835_card_free(void *data)
158{
159 snd_card_free(data);
160}
161
162static int snd_add_child_device(struct device *dev,
276 struct bcm2835_audio_driver *audio_driver, 163 struct bcm2835_audio_driver *audio_driver,
277 u32 numchans) 164 u32 numchans)
278{ 165{
279 struct snd_card *card; 166 struct snd_card *card;
280 struct device *child;
281 struct bcm2835_chip *chip; 167 struct bcm2835_chip *chip;
282 int err, i; 168 int err;
283 169
284 child = snd_create_device(device, &audio_driver->driver, 170 err = snd_card_new(dev, -1, NULL, THIS_MODULE, sizeof(*chip), &card);
285 audio_driver->driver.name); 171 if (err < 0) {
286 if (IS_ERR(child)) { 172 dev_err(dev, "Failed to create card");
287 dev_err(device, 173 return err;
288 "Unable to create child device %p, error %ld",
289 audio_driver->driver.name,
290 PTR_ERR(child));
291 return PTR_ERR(child);
292 } 174 }
293 175
294 card = snd_bcm2835_card_new(child); 176 chip = card->private_data;
295 if (IS_ERR(card)) { 177 chip->card = card;
296 dev_err(child, "Failed to create card"); 178 chip->dev = dev;
297 return PTR_ERR(card); 179 mutex_init(&chip->audio_mutex);
180
181 chip->vchi_ctx = devres_find(dev,
182 bcm2835_devm_free_vchi_ctx, NULL, NULL);
183 if (!chip->vchi_ctx) {
184 err = -ENODEV;
185 goto error;
298 } 186 }
299 187
300 snd_card_set_dev(card, child);
301 strcpy(card->driver, audio_driver->driver.name); 188 strcpy(card->driver, audio_driver->driver.name);
302 strcpy(card->shortname, audio_driver->shortname); 189 strcpy(card->shortname, audio_driver->shortname);
303 strcpy(card->longname, audio_driver->longname); 190 strcpy(card->longname, audio_driver->longname);
304 191
305 err = snd_bcm2835_create(card, &chip);
306 if (err) {
307 dev_err(child, "Failed to create chip, error %d\n", err);
308 return err;
309 }
310
311 chip->dev = child;
312
313 err = audio_driver->newpcm(chip, audio_driver->shortname, 192 err = audio_driver->newpcm(chip, audio_driver->shortname,
314 audio_driver->route, 193 audio_driver->route,
315 numchans); 194 numchans);
316 if (err) { 195 if (err) {
317 dev_err(child, "Failed to create pcm, error %d\n", err); 196 dev_err(dev, "Failed to create pcm, error %d\n", err);
318 return err; 197 goto error;
319 } 198 }
320 199
321 err = audio_driver->newctl(chip); 200 err = audio_driver->newctl(chip);
322 if (err) { 201 if (err) {
323 dev_err(child, "Failed to create controls, error %d\n", err); 202 dev_err(dev, "Failed to create controls, error %d\n", err);
324 return err; 203 goto error;
325 } 204 }
326 205
327 for (i = 0; i < numchans; i++)
328 chip->avail_substreams |= (1 << i);
329
330 err = snd_card_register(card); 206 err = snd_card_register(card);
331 if (err) { 207 if (err) {
332 dev_err(child, "Failed to register card, error %d\n", err); 208 dev_err(dev, "Failed to register card, error %d\n", err);
333 return err; 209 goto error;
334 } 210 }
335 211
336 dev_set_drvdata(child, chip); 212 dev_set_drvdata(dev, chip);
337 dev_info(child, "card created with %d channels\n", numchans); 213
214 err = devm_add_action(dev, bcm2835_card_free, card);
215 if (err < 0) {
216 dev_err(dev, "Failed to add devm action, err %d\n", err);
217 goto error;
218 }
338 219
220 dev_info(dev, "card created with %d channels\n", numchans);
339 return 0; 221 return 0;
222
223 error:
224 snd_card_free(card);
225 return err;
340} 226}
341 227
342static int snd_add_child_devices(struct device *device, u32 numchans) 228static int snd_add_child_devices(struct device *device, u32 numchans)
diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h
index 5dc427240a1d..34a0125ce646 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h
+++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h
@@ -5,59 +5,12 @@
5#define __SOUND_ARM_BCM2835_H 5#define __SOUND_ARM_BCM2835_H
6 6
7#include <linux/device.h> 7#include <linux/device.h>
8#include <linux/list.h>
9#include <linux/interrupt.h>
10#include <linux/wait.h> 8#include <linux/wait.h>
11#include <sound/core.h> 9#include <sound/core.h>
12#include <sound/initval.h>
13#include <sound/pcm.h> 10#include <sound/pcm.h>
14#include <sound/pcm_params.h>
15#include <sound/pcm-indirect.h> 11#include <sound/pcm-indirect.h>
16#include <linux/workqueue.h>
17
18#include "interface/vchi/vchi.h" 12#include "interface/vchi/vchi.h"
19 13
20/*
21 * #define AUDIO_DEBUG_ENABLE
22 * #define AUDIO_VERBOSE_DEBUG_ENABLE
23 */
24
25/* Debug macros */
26
27#ifdef AUDIO_DEBUG_ENABLE
28#ifdef AUDIO_VERBOSE_DEBUG_ENABLE
29
30#define audio_debug(fmt, arg...) \
31 pr_info("%s:%d " fmt, __func__, __LINE__, ##arg)
32
33#define audio_info(fmt, arg...) \
34 pr_info("%s:%d " fmt, __func__, __LINE__, ##arg)
35
36#else
37
38#define audio_debug(fmt, arg...)
39
40#define audio_info(fmt, arg...)
41
42#endif /* AUDIO_VERBOSE_DEBUG_ENABLE */
43
44#else
45
46#define audio_debug(fmt, arg...)
47
48#define audio_info(fmt, arg...)
49
50#endif /* AUDIO_DEBUG_ENABLE */
51
52#define audio_error(fmt, arg...) \
53 pr_err("%s:%d " fmt, __func__, __LINE__, ##arg)
54
55#define audio_warning(fmt, arg...) \
56 pr_warn("%s:%d " fmt, __func__, __LINE__, ##arg)
57
58#define audio_alert(fmt, arg...) \
59 pr_alert("%s:%d " fmt, __func__, __LINE__, ##arg)
60
61#define MAX_SUBSTREAMS (8) 14#define MAX_SUBSTREAMS (8)
62#define AVAIL_SUBSTREAMS_MASK (0xff) 15#define AVAIL_SUBSTREAMS_MASK (0xff)
63 16
@@ -74,6 +27,8 @@ enum {
74// convert chip to alsa volume 27// convert chip to alsa volume
75#define chip2alsa(vol) -(((vol) * 100) >> 8) 28#define chip2alsa(vol) -(((vol) * 100) >> 8)
76 29
30#define CHIP_MIN_VOLUME 26214 /* minimum level aka mute */
31
77/* Some constants for values .. */ 32/* Some constants for values .. */
78enum snd_bcm2835_route { 33enum snd_bcm2835_route {
79 AUDIO_DEST_AUTO = 0, 34 AUDIO_DEST_AUTO = 0,
@@ -90,7 +45,6 @@ enum snd_bcm2835_ctrl {
90 45
91struct bcm2835_vchi_ctx { 46struct bcm2835_vchi_ctx {
92 VCHI_INSTANCE_T vchi_instance; 47 VCHI_INSTANCE_T vchi_instance;
93 VCHI_CONNECTION_T *vchi_connection;
94}; 48};
95 49
96/* definition of the chip-specific record */ 50/* definition of the chip-specific record */
@@ -98,13 +52,10 @@ struct bcm2835_chip {
98 struct snd_card *card; 52 struct snd_card *card;
99 struct snd_pcm *pcm; 53 struct snd_pcm *pcm;
100 struct snd_pcm *pcm_spdif; 54 struct snd_pcm *pcm_spdif;
101 /* Bitmat for valid reg_base and irq numbers */
102 unsigned int avail_substreams;
103 struct device *dev; 55 struct device *dev;
104 struct bcm2835_alsa_stream *alsa_stream[MAX_SUBSTREAMS]; 56 struct bcm2835_alsa_stream *alsa_stream[MAX_SUBSTREAMS];
105 57
106 int volume; 58 int volume;
107 int old_volume; /* stores the volume value whist muted */
108 int dest; 59 int dest;
109 int mute; 60 int mute;
110 61
@@ -120,38 +71,26 @@ struct bcm2835_alsa_stream {
120 struct snd_pcm_substream *substream; 71 struct snd_pcm_substream *substream;
121 struct snd_pcm_indirect pcm_indirect; 72 struct snd_pcm_indirect pcm_indirect;
122 73
123 spinlock_t lock;
124
125 int open;
126 int running;
127 int draining; 74 int draining;
128 75
129 int channels; 76 atomic_t pos;
130 int params_rate; 77 unsigned int period_offset;
131 int pcm_format_width;
132
133 unsigned int pos;
134 unsigned int buffer_size; 78 unsigned int buffer_size;
135 unsigned int period_size; 79 unsigned int period_size;
136 80
137 atomic_t retrieved;
138 struct bcm2835_audio_instance *instance; 81 struct bcm2835_audio_instance *instance;
139 struct workqueue_struct *my_wq;
140 int idx; 82 int idx;
141}; 83};
142 84
143int snd_bcm2835_new_ctl(struct bcm2835_chip *chip); 85int snd_bcm2835_new_ctl(struct bcm2835_chip *chip);
144int snd_bcm2835_new_pcm(struct bcm2835_chip *chip, u32 numchannels); 86int snd_bcm2835_new_pcm(struct bcm2835_chip *chip, const char *name,
145int snd_bcm2835_new_spdif_pcm(struct bcm2835_chip *chip); 87 int idx, enum snd_bcm2835_route route,
146int snd_bcm2835_new_simple_pcm(struct bcm2835_chip *chip, 88 u32 numchannels, bool spdif);
147 const char *name,
148 enum snd_bcm2835_route route,
149 u32 numchannels);
150 89
151int snd_bcm2835_new_hdmi_ctl(struct bcm2835_chip *chip); 90int snd_bcm2835_new_hdmi_ctl(struct bcm2835_chip *chip);
152int snd_bcm2835_new_headphones_ctl(struct bcm2835_chip *chip); 91int snd_bcm2835_new_headphones_ctl(struct bcm2835_chip *chip);
153 92
154int bcm2835_new_vchi_ctx(struct bcm2835_vchi_ctx *vchi_ctx); 93int bcm2835_new_vchi_ctx(struct device *dev, struct bcm2835_vchi_ctx *vchi_ctx);
155void bcm2835_free_vchi_ctx(struct bcm2835_vchi_ctx *vchi_ctx); 94void bcm2835_free_vchi_ctx(struct bcm2835_vchi_ctx *vchi_ctx);
156 95
157int bcm2835_audio_open(struct bcm2835_alsa_stream *alsa_stream); 96int bcm2835_audio_open(struct bcm2835_alsa_stream *alsa_stream);
@@ -159,16 +98,15 @@ int bcm2835_audio_close(struct bcm2835_alsa_stream *alsa_stream);
159int bcm2835_audio_set_params(struct bcm2835_alsa_stream *alsa_stream, 98int bcm2835_audio_set_params(struct bcm2835_alsa_stream *alsa_stream,
160 unsigned int channels, unsigned int samplerate, 99 unsigned int channels, unsigned int samplerate,
161 unsigned int bps); 100 unsigned int bps);
162int bcm2835_audio_setup(struct bcm2835_alsa_stream *alsa_stream);
163int bcm2835_audio_start(struct bcm2835_alsa_stream *alsa_stream); 101int bcm2835_audio_start(struct bcm2835_alsa_stream *alsa_stream);
164int bcm2835_audio_stop(struct bcm2835_alsa_stream *alsa_stream); 102int bcm2835_audio_stop(struct bcm2835_alsa_stream *alsa_stream);
165int bcm2835_audio_set_ctls(struct bcm2835_chip *chip); 103int bcm2835_audio_drain(struct bcm2835_alsa_stream *alsa_stream);
104int bcm2835_audio_set_ctls(struct bcm2835_alsa_stream *alsa_stream);
166int bcm2835_audio_write(struct bcm2835_alsa_stream *alsa_stream, 105int bcm2835_audio_write(struct bcm2835_alsa_stream *alsa_stream,
167 unsigned int count, 106 unsigned int count,
168 void *src); 107 void *src);
169void bcm2835_playback_fifo(struct bcm2835_alsa_stream *alsa_stream); 108void bcm2835_playback_fifo(struct bcm2835_alsa_stream *alsa_stream,
109 unsigned int size);
170unsigned int bcm2835_audio_retrieve_buffers(struct bcm2835_alsa_stream *alsa_stream); 110unsigned int bcm2835_audio_retrieve_buffers(struct bcm2835_alsa_stream *alsa_stream);
171void bcm2835_audio_flush_buffers(struct bcm2835_alsa_stream *alsa_stream);
172void bcm2835_audio_flush_playback_buffers(struct bcm2835_alsa_stream *alsa_stream);
173 111
174#endif /* __SOUND_ARM_BCM2835_H */ 112#endif /* __SOUND_ARM_BCM2835_H */
diff --git a/drivers/staging/vc04_services/bcm2835-camera/TODO b/drivers/staging/vc04_services/bcm2835-camera/TODO
index cefce72d814f..6c2b4ffe4996 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/TODO
+++ b/drivers/staging/vc04_services/bcm2835-camera/TODO
@@ -15,9 +15,3 @@ padding in the V4L2 spec, but that padding doesn't match what the
15hardware can do. If we exposed the native padding requirements 15hardware can do. If we exposed the native padding requirements
16through the V4L2 "multiplanar" formats, the firmware would have one 16through the V4L2 "multiplanar" formats, the firmware would have one
17less copy it needed to do. 17less copy it needed to do.
18
193) Port to ARM64
20
21The bulk_receive() does some manual cache flushing that are 32-bit ARM
22only, which we should convert to proper cross-platform APIs.
23
diff --git a/drivers/staging/vc04_services/bcm2835-camera/controls.c b/drivers/staging/vc04_services/bcm2835-camera/controls.c
index cff7b1e07153..a2c55cb2192a 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/controls.c
+++ b/drivers/staging/vc04_services/bcm2835-camera/controls.c
@@ -1106,7 +1106,7 @@ static const struct bm2835_mmal_v4l2_ctrl v4l2_ctrls[V4L2_CTRL_COUNT] = {
1106 { 1106 {
1107 V4L2_CID_POWER_LINE_FREQUENCY, MMAL_CONTROL_TYPE_STD_MENU, 1107 V4L2_CID_POWER_LINE_FREQUENCY, MMAL_CONTROL_TYPE_STD_MENU,
1108 0, ARRAY_SIZE(mains_freq_qmenu) - 1, 1108 0, ARRAY_SIZE(mains_freq_qmenu) - 1,
1109 1, 1, NULL, 1109 1, 1, mains_freq_qmenu,
1110 MMAL_PARAMETER_FLICKER_AVOID, 1110 MMAL_PARAMETER_FLICKER_AVOID,
1111 &ctrl_set_flicker_avoidance, 1111 &ctrl_set_flicker_avoidance,
1112 false 1112 false
diff --git a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
index 51e5b04ff0f5..cc2d9933b969 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
+++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
@@ -21,7 +21,6 @@
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/completion.h> 22#include <linux/completion.h>
23#include <linux/vmalloc.h> 23#include <linux/vmalloc.h>
24#include <asm/cacheflush.h>
25#include <media/videobuf2-vmalloc.h> 24#include <media/videobuf2-vmalloc.h>
26 25
27#include "mmal-common.h" 26#include "mmal-common.h"
@@ -1803,19 +1802,12 @@ int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
1803{ 1802{
1804 int status; 1803 int status;
1805 struct vchiq_mmal_instance *instance; 1804 struct vchiq_mmal_instance *instance;
1806 static VCHI_CONNECTION_T *vchi_connection;
1807 static VCHI_INSTANCE_T vchi_instance; 1805 static VCHI_INSTANCE_T vchi_instance;
1808 SERVICE_CREATION_T params = { 1806 SERVICE_CREATION_T params = {
1809 .version = VCHI_VERSION_EX(VC_MMAL_VER, VC_MMAL_MIN_VER), 1807 .version = VCHI_VERSION_EX(VC_MMAL_VER, VC_MMAL_MIN_VER),
1810 .service_id = VC_MMAL_SERVER_NAME, 1808 .service_id = VC_MMAL_SERVER_NAME,
1811 .connection = vchi_connection,
1812 .rx_fifo_size = 0,
1813 .tx_fifo_size = 0,
1814 .callback = service_callback, 1809 .callback = service_callback,
1815 .callback_param = NULL, 1810 .callback_param = NULL,
1816 .want_unaligned_bulk_rx = 1,
1817 .want_unaligned_bulk_tx = 1,
1818 .want_crc = 0
1819 }; 1811 };
1820 1812
1821 /* compile time checks to ensure structure size as they are 1813 /* compile time checks to ensure structure size as they are
@@ -1839,7 +1831,7 @@ int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
1839 return -EIO; 1831 return -EIO;
1840 } 1832 }
1841 1833
1842 status = vchi_connect(NULL, 0, vchi_instance); 1834 status = vchi_connect(vchi_instance);
1843 if (status) { 1835 if (status) {
1844 pr_err("Failed to connect VCHI instance (status=%d)\n", status); 1836 pr_err("Failed to connect VCHI instance (status=%d)\n", status);
1845 return -EIO; 1837 return -EIO;
diff --git a/drivers/staging/vc04_services/interface/vchi/connections/connection.h b/drivers/staging/vc04_services/interface/vchi/connections/connection.h
deleted file mode 100644
index 67c84386c65a..000000000000
--- a/drivers/staging/vc04_services/interface/vchi/connections/connection.h
+++ /dev/null
@@ -1,324 +0,0 @@
1/**
2 * Copyright (c) 2010-2012 Broadcom. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions, and the following disclaimer,
9 * without modification.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The names of the above-listed copyright holders may not be used
14 * to endorse or promote products derived from this software without
15 * specific prior written permission.
16 *
17 * ALTERNATIVELY, this software may be distributed under the terms of the
18 * GNU General Public License ("GPL") version 2, as published by the Free
19 * Software Foundation.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#ifndef CONNECTION_H_
35#define CONNECTION_H_
36
37#include <linux/kernel.h>
38#include <linux/types.h>
39#include <linux/semaphore.h>
40
41#include "interface/vchi/vchi_cfg_internal.h"
42#include "interface/vchi/vchi_common.h"
43#include "interface/vchi/message_drivers/message.h"
44
45/******************************************************************************
46 Global defs
47 *****************************************************************************/
48
49// Opaque handle for a connection / service pair
50typedef struct opaque_vchi_connection_connected_service_handle_t *VCHI_CONNECTION_SERVICE_HANDLE_T;
51
52// opaque handle to the connection state information
53typedef struct opaque_vchi_connection_info_t VCHI_CONNECTION_STATE_T;
54
55typedef struct vchi_connection_t VCHI_CONNECTION_T;
56
57/******************************************************************************
58 API
59 *****************************************************************************/
60
61// Routine to init a connection with a particular low level driver
62typedef VCHI_CONNECTION_STATE_T * (*VCHI_CONNECTION_INIT_T)( struct vchi_connection_t * connection,
63 const VCHI_MESSAGE_DRIVER_T * driver );
64
65// Routine to control CRC enabling at a connection level
66typedef int32_t (*VCHI_CONNECTION_CRC_CONTROL_T)( VCHI_CONNECTION_STATE_T *state_handle,
67 VCHI_CRC_CONTROL_T control );
68
69// Routine to create a service
70typedef int32_t (*VCHI_CONNECTION_SERVICE_CONNECT_T)( VCHI_CONNECTION_STATE_T *state_handle,
71 int32_t service_id,
72 uint32_t rx_fifo_size,
73 uint32_t tx_fifo_size,
74 int server,
75 VCHI_CALLBACK_T callback,
76 void *callback_param,
77 int32_t want_crc,
78 int32_t want_unaligned_bulk_rx,
79 int32_t want_unaligned_bulk_tx,
80 VCHI_CONNECTION_SERVICE_HANDLE_T *service_handle );
81
82// Routine to close a service
83typedef int32_t (*VCHI_CONNECTION_SERVICE_DISCONNECT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle );
84
85// Routine to queue a message
86typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
87 const void *data,
88 uint32_t data_size,
89 VCHI_FLAGS_T flags,
90 void *msg_handle );
91
92// scatter-gather (vector) message queueing
93typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
94 VCHI_MSG_VECTOR_T *vector,
95 uint32_t count,
96 VCHI_FLAGS_T flags,
97 void *msg_handle );
98
99// Routine to dequeue a message
100typedef int32_t (*VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
101 void *data,
102 uint32_t max_data_size_to_read,
103 uint32_t *actual_msg_size,
104 VCHI_FLAGS_T flags );
105
106// Routine to peek at a message
107typedef int32_t (*VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
108 void **data,
109 uint32_t *msg_size,
110 VCHI_FLAGS_T flags );
111
112// Routine to hold a message
113typedef int32_t (*VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
114 void **data,
115 uint32_t *msg_size,
116 VCHI_FLAGS_T flags,
117 void **message_handle );
118
119// Routine to initialise a received message iterator
120typedef int32_t (*VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
121 VCHI_MSG_ITER_T *iter,
122 VCHI_FLAGS_T flags );
123
124// Routine to release a held message
125typedef int32_t (*VCHI_CONNECTION_HELD_MSG_RELEASE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
126 void *message_handle );
127
128// Routine to get info on a held message
129typedef int32_t (*VCHI_CONNECTION_HELD_MSG_INFO_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
130 void *message_handle,
131 void **data,
132 int32_t *msg_size,
133 uint32_t *tx_timestamp,
134 uint32_t *rx_timestamp );
135
136// Routine to check whether the iterator has a next message
137typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
138 const VCHI_MSG_ITER_T *iter );
139
140// Routine to advance the iterator
141typedef int32_t (*VCHI_CONNECTION_MSG_ITER_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
142 VCHI_MSG_ITER_T *iter,
143 void **data,
144 uint32_t *msg_size );
145
146// Routine to remove the last message returned by the iterator
147typedef int32_t (*VCHI_CONNECTION_MSG_ITER_REMOVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
148 VCHI_MSG_ITER_T *iter );
149
150// Routine to hold the last message returned by the iterator
151typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HOLD_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
152 VCHI_MSG_ITER_T *iter,
153 void **msg_handle );
154
155// Routine to transmit bulk data
156typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
157 const void *data_src,
158 uint32_t data_size,
159 VCHI_FLAGS_T flags,
160 void *bulk_handle );
161
162// Routine to receive data
163typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
164 void *data_dst,
165 uint32_t data_size,
166 VCHI_FLAGS_T flags,
167 void *bulk_handle );
168
169// Routine to report if a server is available
170typedef int32_t (*VCHI_CONNECTION_SERVER_PRESENT)( VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t peer_flags );
171
172// Routine to report the number of RX slots available
173typedef int (*VCHI_CONNECTION_RX_SLOTS_AVAILABLE)( const VCHI_CONNECTION_STATE_T *state );
174
175// Routine to report the RX slot size
176typedef uint32_t (*VCHI_CONNECTION_RX_SLOT_SIZE)( const VCHI_CONNECTION_STATE_T *state );
177
178// Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO
179typedef void (*VCHI_CONNECTION_RX_BULK_BUFFER_ADDED)(VCHI_CONNECTION_STATE_T *state,
180 int32_t service,
181 uint32_t length,
182 MESSAGE_TX_CHANNEL_T channel,
183 uint32_t channel_params,
184 uint32_t data_length,
185 uint32_t data_offset);
186
187// Callback to inform a service that a Xon or Xoff message has been received
188typedef void (*VCHI_CONNECTION_FLOW_CONTROL)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t xoff);
189
190// Callback to inform a service that a server available reply message has been received
191typedef void (*VCHI_CONNECTION_SERVER_AVAILABLE_REPLY)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, uint32_t flags);
192
193// Callback to indicate that bulk auxiliary messages have arrived
194typedef void (*VCHI_CONNECTION_BULK_AUX_RECEIVED)(VCHI_CONNECTION_STATE_T *state);
195
196// Callback to indicate that bulk auxiliary messages have arrived
197typedef void (*VCHI_CONNECTION_BULK_AUX_TRANSMITTED)(VCHI_CONNECTION_STATE_T *state, void *handle);
198
199// Callback with all the connection info you require
200typedef void (*VCHI_CONNECTION_INFO)(VCHI_CONNECTION_STATE_T *state, uint32_t protocol_version, uint32_t slot_size, uint32_t num_slots, uint32_t min_bulk_size);
201
202// Callback to inform of a disconnect
203typedef void (*VCHI_CONNECTION_DISCONNECT)(VCHI_CONNECTION_STATE_T *state, uint32_t flags);
204
205// Callback to inform of a power control request
206typedef void (*VCHI_CONNECTION_POWER_CONTROL)(VCHI_CONNECTION_STATE_T *state, MESSAGE_TX_CHANNEL_T channel, int32_t enable);
207
208// allocate memory suitably aligned for this connection
209typedef void * (*VCHI_BUFFER_ALLOCATE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, uint32_t * length);
210
211// free memory allocated by buffer_allocate
212typedef void (*VCHI_BUFFER_FREE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, void * address);
213
214/******************************************************************************
215 System driver struct
216 *****************************************************************************/
217
218struct opaque_vchi_connection_api_t {
219 // Routine to init the connection
220 VCHI_CONNECTION_INIT_T init;
221
222 // Connection-level CRC control
223 VCHI_CONNECTION_CRC_CONTROL_T crc_control;
224
225 // Routine to connect to or create service
226 VCHI_CONNECTION_SERVICE_CONNECT_T service_connect;
227
228 // Routine to disconnect from a service
229 VCHI_CONNECTION_SERVICE_DISCONNECT_T service_disconnect;
230
231 // Routine to queue a message
232 VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T service_queue_msg;
233
234 // scatter-gather (vector) message queue
235 VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T service_queue_msgv;
236
237 // Routine to dequeue a message
238 VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T service_dequeue_msg;
239
240 // Routine to peek at a message
241 VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T service_peek_msg;
242
243 // Routine to hold a message
244 VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T service_hold_msg;
245
246 // Routine to initialise a received message iterator
247 VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T service_look_ahead_msg;
248
249 // Routine to release a message
250 VCHI_CONNECTION_HELD_MSG_RELEASE_T held_msg_release;
251
252 // Routine to get information on a held message
253 VCHI_CONNECTION_HELD_MSG_INFO_T held_msg_info;
254
255 // Routine to check for next message on iterator
256 VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T msg_iter_has_next;
257
258 // Routine to get next message on iterator
259 VCHI_CONNECTION_MSG_ITER_NEXT_T msg_iter_next;
260
261 // Routine to remove the last message returned by iterator
262 VCHI_CONNECTION_MSG_ITER_REMOVE_T msg_iter_remove;
263
264 // Routine to hold the last message returned by iterator
265 VCHI_CONNECTION_MSG_ITER_HOLD_T msg_iter_hold;
266
267 // Routine to transmit bulk data
268 VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T bulk_queue_transmit;
269
270 // Routine to receive data
271 VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T bulk_queue_receive;
272
273 // Routine to report the available servers
274 VCHI_CONNECTION_SERVER_PRESENT server_present;
275
276 // Routine to report the number of RX slots available
277 VCHI_CONNECTION_RX_SLOTS_AVAILABLE connection_rx_slots_available;
278
279 // Routine to report the RX slot size
280 VCHI_CONNECTION_RX_SLOT_SIZE connection_rx_slot_size;
281
282 // Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO
283 VCHI_CONNECTION_RX_BULK_BUFFER_ADDED rx_bulk_buffer_added;
284
285 // Callback to inform a service that a Xon or Xoff message has been received
286 VCHI_CONNECTION_FLOW_CONTROL flow_control;
287
288 // Callback to inform a service that a server available reply message has been received
289 VCHI_CONNECTION_SERVER_AVAILABLE_REPLY server_available_reply;
290
291 // Callback to indicate that bulk auxiliary messages have arrived
292 VCHI_CONNECTION_BULK_AUX_RECEIVED bulk_aux_received;
293
294 // Callback to indicate that a bulk auxiliary message has been transmitted
295 VCHI_CONNECTION_BULK_AUX_TRANSMITTED bulk_aux_transmitted;
296
297 // Callback to provide information about the connection
298 VCHI_CONNECTION_INFO connection_info;
299
300 // Callback to notify that peer has requested disconnect
301 VCHI_CONNECTION_DISCONNECT disconnect;
302
303 // Callback to notify that peer has requested power change
304 VCHI_CONNECTION_POWER_CONTROL power_control;
305
306 // allocate memory suitably aligned for this connection
307 VCHI_BUFFER_ALLOCATE buffer_allocate;
308
309 // free memory allocated by buffer_allocate
310 VCHI_BUFFER_FREE buffer_free;
311
312};
313
314struct vchi_connection_t {
315 const VCHI_CONNECTION_API_T *api;
316 VCHI_CONNECTION_STATE_T *state;
317#ifdef VCHI_COARSE_LOCKING
318 struct semaphore sem;
319#endif
320};
321
322#endif /* CONNECTION_H_ */
323
324/****************************** End of file **********************************/
diff --git a/drivers/staging/vc04_services/interface/vchi/message_drivers/message.h b/drivers/staging/vc04_services/interface/vchi/message_drivers/message.h
deleted file mode 100644
index 834263f278cf..000000000000
--- a/drivers/staging/vc04_services/interface/vchi/message_drivers/message.h
+++ /dev/null
@@ -1,196 +0,0 @@
1/**
2 * Copyright (c) 2010-2012 Broadcom. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions, and the following disclaimer,
9 * without modification.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The names of the above-listed copyright holders may not be used
14 * to endorse or promote products derived from this software without
15 * specific prior written permission.
16 *
17 * ALTERNATIVELY, this software may be distributed under the terms of the
18 * GNU General Public License ("GPL") version 2, as published by the Free
19 * Software Foundation.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#ifndef _VCHI_MESSAGE_H_
35#define _VCHI_MESSAGE_H_
36
37#include <linux/kernel.h>
38#include <linux/types.h>
39#include <linux/semaphore.h>
40
41#include "interface/vchi/vchi_cfg_internal.h"
42#include "interface/vchi/vchi_common.h"
43
44typedef enum message_event_type {
45 MESSAGE_EVENT_NONE,
46 MESSAGE_EVENT_NOP,
47 MESSAGE_EVENT_MESSAGE,
48 MESSAGE_EVENT_SLOT_COMPLETE,
49 MESSAGE_EVENT_RX_BULK_PAUSED,
50 MESSAGE_EVENT_RX_BULK_COMPLETE,
51 MESSAGE_EVENT_TX_COMPLETE,
52 MESSAGE_EVENT_MSG_DISCARDED
53} MESSAGE_EVENT_TYPE_T;
54
55typedef enum vchi_msg_flags {
56 VCHI_MSG_FLAGS_NONE = 0x0,
57 VCHI_MSG_FLAGS_TERMINATE_DMA = 0x1
58} VCHI_MSG_FLAGS_T;
59
60typedef enum message_tx_channel {
61 MESSAGE_TX_CHANNEL_MESSAGE = 0,
62 MESSAGE_TX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
63} MESSAGE_TX_CHANNEL_T;
64
65// Macros used for cycling through bulk channels
66#define MESSAGE_TX_CHANNEL_BULK_PREV(c) (MESSAGE_TX_CHANNEL_BULK+((c)-MESSAGE_TX_CHANNEL_BULK+VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION-1)%VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION)
67#define MESSAGE_TX_CHANNEL_BULK_NEXT(c) (MESSAGE_TX_CHANNEL_BULK+((c)-MESSAGE_TX_CHANNEL_BULK+1)%VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION)
68
69typedef enum message_rx_channel {
70 MESSAGE_RX_CHANNEL_MESSAGE = 0,
71 MESSAGE_RX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
72} MESSAGE_RX_CHANNEL_T;
73
74// Message receive slot information
75typedef struct rx_msg_slot_info {
76
77 struct rx_msg_slot_info *next;
78 //struct slot_info *prev;
79#if !defined VCHI_COARSE_LOCKING
80 struct semaphore sem;
81#endif
82
83 uint8_t *addr; // base address of slot
84 uint32_t len; // length of slot in bytes
85
86 uint32_t write_ptr; // hardware causes this to advance
87 uint32_t read_ptr; // this module does the reading
88 int active; // is this slot in the hardware dma fifo?
89 uint32_t msgs_parsed; // count how many messages are in this slot
90 uint32_t msgs_released; // how many messages have been released
91 void *state; // connection state information
92 uint8_t ref_count[VCHI_MAX_SERVICES_PER_CONNECTION]; // reference count for slots held by services
93} RX_MSG_SLOTINFO_T;
94
95// The message driver no longer needs to know about the fields of RX_BULK_SLOTINFO_T - sort this out.
96// In particular, it mustn't use addr and len - they're the client buffer, but the message
97// driver will be tasked with sending the aligned core section.
98typedef struct rx_bulk_slotinfo_t {
99 struct rx_bulk_slotinfo_t *next;
100
101 struct semaphore *blocking;
102
103 // needed by DMA
104 void *addr;
105 uint32_t len;
106
107 // needed for the callback
108 void *service;
109 void *handle;
110 VCHI_FLAGS_T flags;
111} RX_BULK_SLOTINFO_T;
112
113/* ----------------------------------------------------------------------
114 * each connection driver will have a pool of the following struct.
115 *
116 * the pool will be managed by vchi_qman_*
117 * this means there will be multiple queues (single linked lists)
118 * a given struct message_info will be on exactly one of these queues
119 * at any one time
120 * -------------------------------------------------------------------- */
121typedef struct rx_message_info {
122
123 struct message_info *next;
124 //struct message_info *prev;
125
126 uint8_t *addr;
127 uint32_t len;
128 RX_MSG_SLOTINFO_T *slot; // points to whichever slot contains this message
129 uint32_t tx_timestamp;
130 uint32_t rx_timestamp;
131
132} RX_MESSAGE_INFO_T;
133
134typedef struct {
135 MESSAGE_EVENT_TYPE_T type;
136
137 struct {
138 // for messages
139 void *addr; // address of message
140 uint16_t slot_delta; // whether this message indicated slot delta
141 uint32_t len; // length of message
142 RX_MSG_SLOTINFO_T *slot; // slot this message is in
143 int32_t service; // service id this message is destined for
144 uint32_t tx_timestamp; // timestamp from the header
145 uint32_t rx_timestamp; // timestamp when we parsed it
146 } message;
147
148 // FIXME: cleanup slot reporting...
149 RX_MSG_SLOTINFO_T *rx_msg;
150 RX_BULK_SLOTINFO_T *rx_bulk;
151 void *tx_handle;
152 MESSAGE_TX_CHANNEL_T tx_channel;
153
154} MESSAGE_EVENT_T;
155
156// callbacks
157typedef void VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T( void *state );
158
159typedef struct {
160 VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T *event_callback;
161} VCHI_MESSAGE_DRIVER_OPEN_T;
162
163// handle to this instance of message driver (as returned by ->open)
164typedef struct opaque_mhandle_t *VCHI_MDRIVER_HANDLE_T;
165
166struct opaque_vchi_message_driver_t {
167 VCHI_MDRIVER_HANDLE_T *(*open)( VCHI_MESSAGE_DRIVER_OPEN_T *params, void *state );
168 int32_t (*suspending)( VCHI_MDRIVER_HANDLE_T *handle );
169 int32_t (*resumed)( VCHI_MDRIVER_HANDLE_T *handle );
170 int32_t (*power_control)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T, int32_t enable );
171 int32_t (*add_msg_rx_slot)( VCHI_MDRIVER_HANDLE_T *handle, RX_MSG_SLOTINFO_T *slot ); // rx message
172 int32_t (*add_bulk_rx)( VCHI_MDRIVER_HANDLE_T *handle, void *data, uint32_t len, RX_BULK_SLOTINFO_T *slot ); // rx data (bulk)
173 int32_t (*send)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel, const void *data, uint32_t len, VCHI_MSG_FLAGS_T flags, void *send_handle ); // tx (message & bulk)
174 void (*next_event)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_EVENT_T *event ); // get the next event from message_driver
175 int32_t (*enable)( VCHI_MDRIVER_HANDLE_T *handle );
176 int32_t (*form_message)( VCHI_MDRIVER_HANDLE_T *handle, int32_t service_id, VCHI_MSG_VECTOR_T *vector, uint32_t count, void
177 *address, uint32_t length_avail, uint32_t max_total_length, int32_t pad_to_fill, int32_t allow_partial );
178
179 int32_t (*update_message)( VCHI_MDRIVER_HANDLE_T *handle, void *dest, int16_t *slot_count );
180 int32_t (*buffer_aligned)( VCHI_MDRIVER_HANDLE_T *handle, int tx, int uncached, const void *address, const uint32_t length );
181 void * (*allocate_buffer)( VCHI_MDRIVER_HANDLE_T *handle, uint32_t *length );
182 void (*free_buffer)( VCHI_MDRIVER_HANDLE_T *handle, void *address );
183 int (*rx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
184 int (*tx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
185
186 int32_t (*tx_supports_terminate)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
187 uint32_t (*tx_bulk_chunk_size)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
188 int (*tx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
189 int (*rx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_RX_CHANNEL_T channel );
190 void (*form_bulk_aux)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel, const void *data, uint32_t len, uint32_t chunk_size, const void **aux_data, int32_t *aux_len );
191 void (*debug)( VCHI_MDRIVER_HANDLE_T *handle );
192};
193
194#endif // _VCHI_MESSAGE_H_
195
196/****************************** End of file ***********************************/
diff --git a/drivers/staging/vc04_services/interface/vchi/vchi.h b/drivers/staging/vc04_services/interface/vchi/vchi.h
index 66a3a060fad2..01381904775d 100644
--- a/drivers/staging/vc04_services/interface/vchi/vchi.h
+++ b/drivers/staging/vc04_services/interface/vchi/vchi.h
@@ -36,7 +36,6 @@
36 36
37#include "interface/vchi/vchi_cfg.h" 37#include "interface/vchi/vchi_cfg.h"
38#include "interface/vchi/vchi_common.h" 38#include "interface/vchi/vchi_common.h"
39#include "interface/vchi/connections/connection.h"
40#include "vchi_mh.h" 39#include "vchi_mh.h"
41 40
42/****************************************************************************** 41/******************************************************************************
@@ -60,46 +59,8 @@ struct vchi_version {
60#define VCHI_VERSION(v_) { v_, v_ } 59#define VCHI_VERSION(v_) { v_, v_ }
61#define VCHI_VERSION_EX(v_, m_) { v_, m_ } 60#define VCHI_VERSION_EX(v_, m_) { v_, m_ }
62 61
63typedef enum {
64 VCHI_VEC_POINTER,
65 VCHI_VEC_HANDLE,
66 VCHI_VEC_LIST
67} VCHI_MSG_VECTOR_TYPE_T;
68
69typedef struct vchi_msg_vector_ex {
70
71 VCHI_MSG_VECTOR_TYPE_T type;
72 union {
73 // a memory handle
74 struct {
75 VCHI_MEM_HANDLE_T handle;
76 uint32_t offset;
77 int32_t vec_len;
78 } handle;
79
80 // an ordinary data pointer
81 struct {
82 const void *vec_base;
83 int32_t vec_len;
84 } ptr;
85
86 // a nested vector list
87 struct {
88 struct vchi_msg_vector_ex *vec;
89 uint32_t vec_len;
90 } list;
91 } u;
92} VCHI_MSG_VECTOR_EX_T;
93
94// Construct an entry in a msg vector for a pointer (p) of length (l)
95#define VCHI_VEC_POINTER(p,l) VCHI_VEC_POINTER, { { (VCHI_MEM_HANDLE_T)(p), (l) } }
96
97// Construct an entry in a msg vector for a message handle (h), starting at offset (o) of length (l)
98#define VCHI_VEC_HANDLE(h,o,l) VCHI_VEC_HANDLE, { { (h), (o), (l) } }
99
100// Macros to manipulate 'FOURCC' values 62// Macros to manipulate 'FOURCC' values
101#define MAKE_FOURCC(x) ((int32_t)( (x[0] << 24) | (x[1] << 16) | (x[2] << 8) | x[3] )) 63#define MAKE_FOURCC(x) ((int32_t)((x[0] << 24) | (x[1] << 16) | (x[2] << 8) | x[3]))
102#define FOURCC_TO_CHAR(x) (x >> 24) & 0xFF,(x >> 16) & 0xFF,(x >> 8) & 0xFF, x & 0xFF
103 64
104// Opaque service information 65// Opaque service information
105struct opaque_vchi_service_t; 66struct opaque_vchi_service_t;
@@ -115,20 +76,8 @@ typedef struct {
115typedef struct { 76typedef struct {
116 struct vchi_version version; 77 struct vchi_version version;
117 int32_t service_id; 78 int32_t service_id;
118 VCHI_CONNECTION_T *connection;
119 uint32_t rx_fifo_size;
120 uint32_t tx_fifo_size;
121 VCHI_CALLBACK_T callback; 79 VCHI_CALLBACK_T callback;
122 void *callback_param; 80 void *callback_param;
123 /* client intends to receive bulk transfers of
124 odd lengths or into unaligned buffers */
125 int32_t want_unaligned_bulk_rx;
126 /* client intends to transmit bulk transfers of
127 odd lengths or out of unaligned buffers */
128 int32_t want_unaligned_bulk_tx;
129 /* client wants to check CRCs on (bulk) xfers.
130 Only needs to be set at 1 end - will do both directions. */
131 int32_t want_crc;
132} SERVICE_CREATION_T; 81} SERVICE_CREATION_T;
133 82
134// Opaque handle for a VCHI instance 83// Opaque handle for a VCHI instance
@@ -137,15 +86,6 @@ typedef struct opaque_vchi_instance_handle_t *VCHI_INSTANCE_T;
137// Opaque handle for a server or client 86// Opaque handle for a server or client
138typedef struct opaque_vchi_service_handle_t *VCHI_SERVICE_HANDLE_T; 87typedef struct opaque_vchi_service_handle_t *VCHI_SERVICE_HANDLE_T;
139 88
140// Service registration & startup
141typedef void (*VCHI_SERVICE_INIT)(VCHI_INSTANCE_T initialise_instance, VCHI_CONNECTION_T **connections, uint32_t num_connections);
142
143typedef struct service_info_tag {
144 const char * const vll_filename; /* VLL to load to start this service. This is an empty string if VLL is "static" */
145 VCHI_SERVICE_INIT init; /* Service initialisation function */
146 void *vll_handle; /* VLL handle; NULL when unloaded or a "static VLL" in build */
147} SERVICE_INFO_T;
148
149/****************************************************************************** 89/******************************************************************************
150 Global funcs - implementation is specific to which side you are on (local / remote) 90 Global funcs - implementation is specific to which side you are on (local / remote)
151 *****************************************************************************/ 91 *****************************************************************************/
@@ -154,28 +94,19 @@ typedef struct service_info_tag {
154extern "C" { 94extern "C" {
155#endif 95#endif
156 96
157extern /*@observer@*/ VCHI_CONNECTION_T * vchi_create_connection( const VCHI_CONNECTION_API_T * function_table,
158 const VCHI_MESSAGE_DRIVER_T * low_level);
159
160// Routine used to initialise the vchi on both local + remote connections 97// Routine used to initialise the vchi on both local + remote connections
161extern int32_t vchi_initialise( VCHI_INSTANCE_T *instance_handle ); 98extern int32_t vchi_initialise(VCHI_INSTANCE_T *instance_handle);
162 99
163extern int32_t vchi_exit( void ); 100extern int32_t vchi_exit(void);
164 101
165extern int32_t vchi_connect( VCHI_CONNECTION_T **connections, 102extern int32_t vchi_connect(VCHI_INSTANCE_T instance_handle);
166 const uint32_t num_connections,
167 VCHI_INSTANCE_T instance_handle );
168 103
169//When this is called, ensure that all services have no data pending. 104//When this is called, ensure that all services have no data pending.
170//Bulk transfers can remain 'queued' 105//Bulk transfers can remain 'queued'
171extern int32_t vchi_disconnect( VCHI_INSTANCE_T instance_handle ); 106extern int32_t vchi_disconnect(VCHI_INSTANCE_T instance_handle);
172
173// Global control over bulk CRC checking
174extern int32_t vchi_crc_control( VCHI_CONNECTION_T *connection,
175 VCHI_CRC_CONTROL_T control );
176 107
177// helper functions 108// helper functions
178extern void * vchi_allocate_buffer(VCHI_SERVICE_HANDLE_T handle, uint32_t *length); 109extern void *vchi_allocate_buffer(VCHI_SERVICE_HANDLE_T handle, uint32_t *length);
179extern void vchi_free_buffer(VCHI_SERVICE_HANDLE_T handle, void *address); 110extern void vchi_free_buffer(VCHI_SERVICE_HANDLE_T handle, void *address);
180extern uint32_t vchi_current_time(VCHI_INSTANCE_T instance_handle); 111extern uint32_t vchi_current_time(VCHI_INSTANCE_T instance_handle);
181 112
@@ -183,32 +114,32 @@ extern uint32_t vchi_current_time(VCHI_INSTANCE_T instance_handle);
183 Global service API 114 Global service API
184 *****************************************************************************/ 115 *****************************************************************************/
185// Routine to create a named service 116// Routine to create a named service
186extern int32_t vchi_service_create( VCHI_INSTANCE_T instance_handle, 117extern int32_t vchi_service_create(VCHI_INSTANCE_T instance_handle,
187 SERVICE_CREATION_T *setup, 118 SERVICE_CREATION_T *setup,
188 VCHI_SERVICE_HANDLE_T *handle ); 119 VCHI_SERVICE_HANDLE_T *handle);
189 120
190// Routine to destroy a service 121// Routine to destroy a service
191extern int32_t vchi_service_destroy( const VCHI_SERVICE_HANDLE_T handle ); 122extern int32_t vchi_service_destroy(const VCHI_SERVICE_HANDLE_T handle);
192 123
193// Routine to open a named service 124// Routine to open a named service
194extern int32_t vchi_service_open( VCHI_INSTANCE_T instance_handle, 125extern int32_t vchi_service_open(VCHI_INSTANCE_T instance_handle,
195 SERVICE_CREATION_T *setup, 126 SERVICE_CREATION_T *setup,
196 VCHI_SERVICE_HANDLE_T *handle); 127 VCHI_SERVICE_HANDLE_T *handle);
197 128
198extern int32_t vchi_get_peer_version( const VCHI_SERVICE_HANDLE_T handle, 129extern int32_t vchi_get_peer_version(const VCHI_SERVICE_HANDLE_T handle,
199 short *peer_version ); 130 short *peer_version);
200 131
201// Routine to close a named service 132// Routine to close a named service
202extern int32_t vchi_service_close( const VCHI_SERVICE_HANDLE_T handle ); 133extern int32_t vchi_service_close(const VCHI_SERVICE_HANDLE_T handle);
203 134
204// Routine to increment ref count on a named service 135// Routine to increment ref count on a named service
205extern int32_t vchi_service_use( const VCHI_SERVICE_HANDLE_T handle ); 136extern int32_t vchi_service_use(const VCHI_SERVICE_HANDLE_T handle);
206 137
207// Routine to decrement ref count on a named service 138// Routine to decrement ref count on a named service
208extern int32_t vchi_service_release( const VCHI_SERVICE_HANDLE_T handle ); 139extern int32_t vchi_service_release(const VCHI_SERVICE_HANDLE_T handle);
209 140
210// Routine to set a control option for a named service 141// Routine to set a control option for a named service
211extern int32_t vchi_service_set_option( const VCHI_SERVICE_HANDLE_T handle, 142extern int32_t vchi_service_set_option(const VCHI_SERVICE_HANDLE_T handle,
212 VCHI_SERVICE_OPTION_T option, 143 VCHI_SERVICE_OPTION_T option,
213 int value); 144 int value);
214 145
@@ -226,128 +157,120 @@ vchi_queue_user_message(VCHI_SERVICE_HANDLE_T handle,
226 157
227// Routine to receive a msg from a service 158// Routine to receive a msg from a service
228// Dequeue is equivalent to hold, copy into client buffer, release 159// Dequeue is equivalent to hold, copy into client buffer, release
229extern int32_t vchi_msg_dequeue( VCHI_SERVICE_HANDLE_T handle, 160extern int32_t vchi_msg_dequeue(VCHI_SERVICE_HANDLE_T handle,
230 void *data, 161 void *data,
231 uint32_t max_data_size_to_read, 162 uint32_t max_data_size_to_read,
232 uint32_t *actual_msg_size, 163 uint32_t *actual_msg_size,
233 VCHI_FLAGS_T flags ); 164 VCHI_FLAGS_T flags);
234 165
235// Routine to look at a message in place. 166// Routine to look at a message in place.
236// The message is not dequeued, so a subsequent call to peek or dequeue 167// The message is not dequeued, so a subsequent call to peek or dequeue
237// will return the same message. 168// will return the same message.
238extern int32_t vchi_msg_peek( VCHI_SERVICE_HANDLE_T handle, 169extern int32_t vchi_msg_peek(VCHI_SERVICE_HANDLE_T handle,
239 void **data, 170 void **data,
240 uint32_t *msg_size, 171 uint32_t *msg_size,
241 VCHI_FLAGS_T flags ); 172 VCHI_FLAGS_T flags);
242 173
243// Routine to remove a message after it has been read in place with peek 174// Routine to remove a message after it has been read in place with peek
244// The first message on the queue is dequeued. 175// The first message on the queue is dequeued.
245extern int32_t vchi_msg_remove( VCHI_SERVICE_HANDLE_T handle ); 176extern int32_t vchi_msg_remove(VCHI_SERVICE_HANDLE_T handle);
246 177
247// Routine to look at a message in place. 178// Routine to look at a message in place.
248// The message is dequeued, so the caller is left holding it; the descriptor is 179// The message is dequeued, so the caller is left holding it; the descriptor is
249// filled in and must be released when the user has finished with the message. 180// filled in and must be released when the user has finished with the message.
250extern int32_t vchi_msg_hold( VCHI_SERVICE_HANDLE_T handle, 181extern int32_t vchi_msg_hold(VCHI_SERVICE_HANDLE_T handle,
251 void **data, // } may be NULL, as info can be 182 void **data, // } may be NULL, as info can be
252 uint32_t *msg_size, // } obtained from HELD_MSG_T 183 uint32_t *msg_size, // } obtained from HELD_MSG_T
253 VCHI_FLAGS_T flags, 184 VCHI_FLAGS_T flags,
254 VCHI_HELD_MSG_T *message_descriptor ); 185 VCHI_HELD_MSG_T *message_descriptor);
255 186
256// Initialise an iterator to look through messages in place 187// Initialise an iterator to look through messages in place
257extern int32_t vchi_msg_look_ahead( VCHI_SERVICE_HANDLE_T handle, 188extern int32_t vchi_msg_look_ahead(VCHI_SERVICE_HANDLE_T handle,
258 VCHI_MSG_ITER_T *iter, 189 VCHI_MSG_ITER_T *iter,
259 VCHI_FLAGS_T flags ); 190 VCHI_FLAGS_T flags);
260 191
261/****************************************************************************** 192/******************************************************************************
262 Global service support API - operations on held messages and message iterators 193 Global service support API - operations on held messages and message iterators
263 *****************************************************************************/ 194 *****************************************************************************/
264 195
265// Routine to get the address of a held message 196// Routine to get the address of a held message
266extern void *vchi_held_msg_ptr( const VCHI_HELD_MSG_T *message ); 197extern void *vchi_held_msg_ptr(const VCHI_HELD_MSG_T *message);
267 198
268// Routine to get the size of a held message 199// Routine to get the size of a held message
269extern int32_t vchi_held_msg_size( const VCHI_HELD_MSG_T *message ); 200extern int32_t vchi_held_msg_size(const VCHI_HELD_MSG_T *message);
270 201
271// Routine to get the transmit timestamp as written into the header by the peer 202// Routine to get the transmit timestamp as written into the header by the peer
272extern uint32_t vchi_held_msg_tx_timestamp( const VCHI_HELD_MSG_T *message ); 203extern uint32_t vchi_held_msg_tx_timestamp(const VCHI_HELD_MSG_T *message);
273 204
274// Routine to get the reception timestamp, written as we parsed the header 205// Routine to get the reception timestamp, written as we parsed the header
275extern uint32_t vchi_held_msg_rx_timestamp( const VCHI_HELD_MSG_T *message ); 206extern uint32_t vchi_held_msg_rx_timestamp(const VCHI_HELD_MSG_T *message);
276 207
277// Routine to release a held message after it has been processed 208// Routine to release a held message after it has been processed
278extern int32_t vchi_held_msg_release( VCHI_HELD_MSG_T *message ); 209extern int32_t vchi_held_msg_release(VCHI_HELD_MSG_T *message);
279 210
280// Indicates whether the iterator has a next message. 211// Indicates whether the iterator has a next message.
281extern int32_t vchi_msg_iter_has_next( const VCHI_MSG_ITER_T *iter ); 212extern int32_t vchi_msg_iter_has_next(const VCHI_MSG_ITER_T *iter);
282 213
283// Return the pointer and length for the next message and advance the iterator. 214// Return the pointer and length for the next message and advance the iterator.
284extern int32_t vchi_msg_iter_next( VCHI_MSG_ITER_T *iter, 215extern int32_t vchi_msg_iter_next(VCHI_MSG_ITER_T *iter,
285 void **data, 216 void **data,
286 uint32_t *msg_size ); 217 uint32_t *msg_size);
287 218
288// Remove the last message returned by vchi_msg_iter_next. 219// Remove the last message returned by vchi_msg_iter_next.
289// Can only be called once after each call to vchi_msg_iter_next. 220// Can only be called once after each call to vchi_msg_iter_next.
290extern int32_t vchi_msg_iter_remove( VCHI_MSG_ITER_T *iter ); 221extern int32_t vchi_msg_iter_remove(VCHI_MSG_ITER_T *iter);
291 222
292// Hold the last message returned by vchi_msg_iter_next. 223// Hold the last message returned by vchi_msg_iter_next.
293// Can only be called once after each call to vchi_msg_iter_next. 224// Can only be called once after each call to vchi_msg_iter_next.
294extern int32_t vchi_msg_iter_hold( VCHI_MSG_ITER_T *iter, 225extern int32_t vchi_msg_iter_hold(VCHI_MSG_ITER_T *iter,
295 VCHI_HELD_MSG_T *message ); 226 VCHI_HELD_MSG_T *message);
296 227
297// Return information for the next message, and hold it, advancing the iterator. 228// Return information for the next message, and hold it, advancing the iterator.
298extern int32_t vchi_msg_iter_hold_next( VCHI_MSG_ITER_T *iter, 229extern int32_t vchi_msg_iter_hold_next(VCHI_MSG_ITER_T *iter,
299 void **data, // } may be NULL 230 void **data, // } may be NULL
300 uint32_t *msg_size, // } 231 uint32_t *msg_size, // }
301 VCHI_HELD_MSG_T *message ); 232 VCHI_HELD_MSG_T *message);
302 233
303/****************************************************************************** 234/******************************************************************************
304 Global bulk API 235 Global bulk API
305 *****************************************************************************/ 236 *****************************************************************************/
306 237
307// Routine to prepare interface for a transfer from the other side 238// Routine to prepare interface for a transfer from the other side
308extern int32_t vchi_bulk_queue_receive( VCHI_SERVICE_HANDLE_T handle, 239extern int32_t vchi_bulk_queue_receive(VCHI_SERVICE_HANDLE_T handle,
309 void *data_dst, 240 void *data_dst,
310 uint32_t data_size, 241 uint32_t data_size,
311 VCHI_FLAGS_T flags, 242 VCHI_FLAGS_T flags,
312 void *transfer_handle ); 243 void *transfer_handle);
313 244
314// Prepare interface for a transfer from the other side into relocatable memory. 245// Prepare interface for a transfer from the other side into relocatable memory.
315int32_t vchi_bulk_queue_receive_reloc( const VCHI_SERVICE_HANDLE_T handle, 246int32_t vchi_bulk_queue_receive_reloc(const VCHI_SERVICE_HANDLE_T handle,
316 VCHI_MEM_HANDLE_T h_dst, 247 VCHI_MEM_HANDLE_T h_dst,
317 uint32_t offset, 248 uint32_t offset,
318 uint32_t data_size, 249 uint32_t data_size,
319 const VCHI_FLAGS_T flags, 250 const VCHI_FLAGS_T flags,
320 void * const bulk_handle ); 251 void * const bulk_handle);
321 252
322// Routine to queue up data ready for transfer to the other (once they have signalled they are ready) 253// Routine to queue up data ready for transfer to the other (once they have signalled they are ready)
323extern int32_t vchi_bulk_queue_transmit( VCHI_SERVICE_HANDLE_T handle, 254extern int32_t vchi_bulk_queue_transmit(VCHI_SERVICE_HANDLE_T handle,
324 const void *data_src, 255 const void *data_src,
325 uint32_t data_size, 256 uint32_t data_size,
326 VCHI_FLAGS_T flags, 257 VCHI_FLAGS_T flags,
327 void *transfer_handle ); 258 void *transfer_handle);
328 259
329/****************************************************************************** 260/******************************************************************************
330 Configuration plumbing 261 Configuration plumbing
331 *****************************************************************************/ 262 *****************************************************************************/
332 263
333// function prototypes for the different mid layers (the state info gives the different physical connections)
334extern const VCHI_CONNECTION_API_T *single_get_func_table( void );
335//extern const VCHI_CONNECTION_API_T *local_server_get_func_table( void );
336//extern const VCHI_CONNECTION_API_T *local_client_get_func_table( void );
337
338// declare all message drivers here
339const VCHI_MESSAGE_DRIVER_T *vchi_mphi_message_driver_func_table( void );
340
341#ifdef __cplusplus 264#ifdef __cplusplus
342} 265}
343#endif 266#endif
344 267
345extern int32_t vchi_bulk_queue_transmit_reloc( VCHI_SERVICE_HANDLE_T handle, 268extern int32_t vchi_bulk_queue_transmit_reloc(VCHI_SERVICE_HANDLE_T handle,
346 VCHI_MEM_HANDLE_T h_src, 269 VCHI_MEM_HANDLE_T h_src,
347 uint32_t offset, 270 uint32_t offset,
348 uint32_t data_size, 271 uint32_t data_size,
349 VCHI_FLAGS_T flags, 272 VCHI_FLAGS_T flags,
350 void *transfer_handle ); 273 void *transfer_handle);
351#endif /* VCHI_H_ */ 274#endif /* VCHI_H_ */
352 275
353/****************************** End of file **********************************/ 276/****************************** End of file **********************************/
diff --git a/drivers/staging/vc04_services/interface/vchi/vchi_cfg.h b/drivers/staging/vc04_services/interface/vchi/vchi_cfg.h
index b6f42b86f206..0d3c468c3504 100644
--- a/drivers/staging/vc04_services/interface/vchi/vchi_cfg.h
+++ b/drivers/staging/vc04_services/interface/vchi/vchi_cfg.h
@@ -138,7 +138,7 @@
138 * can guarantee this by enabling unaligned transmits). 138 * can guarantee this by enabling unaligned transmits).
139 * Not API. */ 139 * Not API. */
140#ifndef VCHI_MIN_BULK_SIZE 140#ifndef VCHI_MIN_BULK_SIZE
141# define VCHI_MIN_BULK_SIZE ( VCHI_MAX_MSG_SIZE / 2 < 4096 ? VCHI_MAX_MSG_SIZE / 2 : 4096 ) 141# define VCHI_MIN_BULK_SIZE (VCHI_MAX_MSG_SIZE / 2 < 4096 ? VCHI_MAX_MSG_SIZE / 2 : 4096)
142#endif 142#endif
143 143
144/* Maximum size of bulk transmission chunks, for each interface type. A trade-off between 144/* Maximum size of bulk transmission chunks, for each interface type. A trade-off between
diff --git a/drivers/staging/vc04_services/interface/vchi/vchi_cfg_internal.h b/drivers/staging/vc04_services/interface/vchi/vchi_cfg_internal.h
deleted file mode 100644
index 35dcba4837d4..000000000000
--- a/drivers/staging/vc04_services/interface/vchi/vchi_cfg_internal.h
+++ /dev/null
@@ -1,71 +0,0 @@
1/**
2 * Copyright (c) 2010-2012 Broadcom. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions, and the following disclaimer,
9 * without modification.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The names of the above-listed copyright holders may not be used
14 * to endorse or promote products derived from this software without
15 * specific prior written permission.
16 *
17 * ALTERNATIVELY, this software may be distributed under the terms of the
18 * GNU General Public License ("GPL") version 2, as published by the Free
19 * Software Foundation.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#ifndef VCHI_CFG_INTERNAL_H_
35#define VCHI_CFG_INTERNAL_H_
36
37/****************************************************************************************
38 * Control optimisation attempts.
39 ***************************************************************************************/
40
41// Don't use lots of short-term locks - use great long ones, reducing the overall locks-per-second
42#define VCHI_COARSE_LOCKING
43
44// Avoid lock then unlock on exit from blocking queue operations (msg tx, bulk rx/tx)
45// (only relevant if VCHI_COARSE_LOCKING)
46#define VCHI_ELIDE_BLOCK_EXIT_LOCK
47
48// Avoid lock on non-blocking peek
49// (only relevant if VCHI_COARSE_LOCKING)
50#define VCHI_AVOID_PEEK_LOCK
51
52// Use one slot-handler thread per connection, rather than 1 thread dealing with all connections in rotation.
53#define VCHI_MULTIPLE_HANDLER_THREADS
54
55// Put free descriptors onto the head of the free queue, rather than the tail, so that we don't thrash
56// our way through the pool of descriptors.
57#define VCHI_PUSH_FREE_DESCRIPTORS_ONTO_HEAD
58
59// Don't issue a MSG_AVAILABLE callback for every single message. Possibly only safe if VCHI_COARSE_LOCKING.
60#define VCHI_FEWER_MSG_AVAILABLE_CALLBACKS
61
62// Don't use message descriptors for TX messages that don't need them
63#define VCHI_MINIMISE_TX_MSG_DESCRIPTORS
64
65// Nano-locks for multiqueue
66//#define VCHI_MQUEUE_NANOLOCKS
67
68// Lock-free(er) dequeuing
69//#define VCHI_RX_NANOLOCKS
70
71#endif /*VCHI_CFG_INTERNAL_H_*/
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
index e76720903064..83d740feab96 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
@@ -109,7 +109,8 @@ free_pagelist(struct vchiq_pagelist_info *pagelistinfo,
109int vchiq_platform_init(struct platform_device *pdev, VCHIQ_STATE_T *state) 109int vchiq_platform_init(struct platform_device *pdev, VCHIQ_STATE_T *state)
110{ 110{
111 struct device *dev = &pdev->dev; 111 struct device *dev = &pdev->dev;
112 struct rpi_firmware *fw = platform_get_drvdata(pdev); 112 struct vchiq_drvdata *drvdata = platform_get_drvdata(pdev);
113 struct rpi_firmware *fw = drvdata->fw;
113 VCHIQ_SLOT_ZERO_T *vchiq_slot_zero; 114 VCHIQ_SLOT_ZERO_T *vchiq_slot_zero;
114 struct resource *res; 115 struct resource *res;
115 void *slot_mem; 116 void *slot_mem;
@@ -127,6 +128,7 @@ int vchiq_platform_init(struct platform_device *pdev, VCHIQ_STATE_T *state)
127 if (err < 0) 128 if (err < 0)
128 return err; 129 return err;
129 130
131 g_cache_line_size = drvdata->cache_line_size;
130 g_fragments_size = 2 * g_cache_line_size; 132 g_fragments_size = 2 * g_cache_line_size;
131 133
132 /* Allocate space for the channels in coherent memory */ 134 /* Allocate space for the channels in coherent memory */
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
index bc05c69383b8..ea789376de0f 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
@@ -170,6 +170,14 @@ static struct device *vchiq_dev;
170static DEFINE_SPINLOCK(msg_queue_spinlock); 170static DEFINE_SPINLOCK(msg_queue_spinlock);
171static struct platform_device *bcm2835_camera; 171static struct platform_device *bcm2835_camera;
172 172
173static struct vchiq_drvdata bcm2835_drvdata = {
174 .cache_line_size = 32,
175};
176
177static struct vchiq_drvdata bcm2836_drvdata = {
178 .cache_line_size = 64,
179};
180
173static const char *const ioctl_names[] = { 181static const char *const ioctl_names[] = {
174 "CONNECT", 182 "CONNECT",
175 "SHUTDOWN", 183 "SHUTDOWN",
@@ -3573,12 +3581,25 @@ void vchiq_platform_conn_state_changed(VCHIQ_STATE_T *state,
3573 } 3581 }
3574} 3582}
3575 3583
3584static const struct of_device_id vchiq_of_match[] = {
3585 { .compatible = "brcm,bcm2835-vchiq", .data = &bcm2835_drvdata },
3586 { .compatible = "brcm,bcm2836-vchiq", .data = &bcm2836_drvdata },
3587 {},
3588};
3589MODULE_DEVICE_TABLE(of, vchiq_of_match);
3590
3576static int vchiq_probe(struct platform_device *pdev) 3591static int vchiq_probe(struct platform_device *pdev)
3577{ 3592{
3578 struct device_node *fw_node; 3593 struct device_node *fw_node;
3579 struct rpi_firmware *fw; 3594 const struct of_device_id *of_id;
3595 struct vchiq_drvdata *drvdata;
3580 int err; 3596 int err;
3581 3597
3598 of_id = of_match_node(vchiq_of_match, pdev->dev.of_node);
3599 drvdata = (struct vchiq_drvdata *)of_id->data;
3600 if (!drvdata)
3601 return -EINVAL;
3602
3582 fw_node = of_find_compatible_node(NULL, NULL, 3603 fw_node = of_find_compatible_node(NULL, NULL,
3583 "raspberrypi,bcm2835-firmware"); 3604 "raspberrypi,bcm2835-firmware");
3584 if (!fw_node) { 3605 if (!fw_node) {
@@ -3586,12 +3607,12 @@ static int vchiq_probe(struct platform_device *pdev)
3586 return -ENOENT; 3607 return -ENOENT;
3587 } 3608 }
3588 3609
3589 fw = rpi_firmware_get(fw_node); 3610 drvdata->fw = rpi_firmware_get(fw_node);
3590 of_node_put(fw_node); 3611 of_node_put(fw_node);
3591 if (!fw) 3612 if (!drvdata->fw)
3592 return -EPROBE_DEFER; 3613 return -EPROBE_DEFER;
3593 3614
3594 platform_set_drvdata(pdev, fw); 3615 platform_set_drvdata(pdev, drvdata);
3595 3616
3596 err = vchiq_platform_init(pdev, &g_state); 3617 err = vchiq_platform_init(pdev, &g_state);
3597 if (err != 0) 3618 if (err != 0)
@@ -3661,12 +3682,6 @@ static int vchiq_remove(struct platform_device *pdev)
3661 return 0; 3682 return 0;
3662} 3683}
3663 3684
3664static const struct of_device_id vchiq_of_match[] = {
3665 { .compatible = "brcm,bcm2835-vchiq", },
3666 {},
3667};
3668MODULE_DEVICE_TABLE(of, vchiq_of_match);
3669
3670static struct platform_driver vchiq_driver = { 3685static struct platform_driver vchiq_driver = {
3671 .driver = { 3686 .driver = {
3672 .name = "bcm2835_vchiq", 3687 .name = "bcm2835_vchiq",
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h
index 40bb0c63b1a9..2f3ebc99cbcf 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h
@@ -123,6 +123,11 @@ typedef struct vchiq_arm_state_struct {
123 123
124} VCHIQ_ARM_STATE_T; 124} VCHIQ_ARM_STATE_T;
125 125
126struct vchiq_drvdata {
127 const unsigned int cache_line_size;
128 struct rpi_firmware *fw;
129};
130
126extern int vchiq_arm_log_level; 131extern int vchiq_arm_log_level;
127extern int vchiq_susp_log_level; 132extern int vchiq_susp_log_level;
128 133
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_genversion b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_genversion
deleted file mode 100644
index dd1f324a8654..000000000000
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_genversion
+++ /dev/null
@@ -1,88 +0,0 @@
1#!/usr/bin/perl -w
2# SPDX-License-Identifier: GPL-2.0
3
4use strict;
5
6#
7# Generate a version from available information
8#
9
10my $prefix = shift @ARGV;
11my $root = shift @ARGV;
12
13
14if ( not defined $root ) {
15 die "usage: $0 prefix root-dir\n";
16}
17
18if ( ! -d $root ) {
19 die "root directory $root not found\n";
20}
21
22my $version = "unknown";
23my $tainted = "";
24
25if ( -d "$root/.git" ) {
26 # attempt to work out git version. only do so
27 # on a linux build host, as cygwin builds are
28 # already slow enough
29
30 if ( -f "/usr/bin/git" || -f "/usr/local/bin/git" ) {
31 if (not open(F, "git --git-dir $root/.git rev-parse --verify HEAD|")) {
32 $version = "no git version";
33 }
34 else {
35 $version = <F>;
36 $version =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
37 $version =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
38 }
39
40 if (open(G, "git --git-dir $root/.git status --porcelain|")) {
41 $tainted = <G>;
42 $tainted =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
43 $tainted =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
44 if (length $tainted) {
45 $version = join ' ', $version, "(tainted)";
46 }
47 else {
48 $version = join ' ', $version, "(clean)";
49 }
50 }
51 }
52}
53
54my $hostname = `hostname`;
55$hostname =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
56$hostname =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
57
58
59print STDERR "Version $version\n";
60print <<EOF;
61#include "${prefix}_build_info.h"
62#include <linux/broadcom/vc_debug_sym.h>
63
64VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_hostname, "$hostname" );
65VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_version, "$version" );
66VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_time, __TIME__ );
67VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_date, __DATE__ );
68
69const char *vchiq_get_build_hostname( void )
70{
71 return vchiq_build_hostname;
72}
73
74const char *vchiq_get_build_version( void )
75{
76 return vchiq_build_version;
77}
78
79const char *vchiq_get_build_date( void )
80{
81 return vchiq_build_date;
82}
83
84const char *vchiq_get_build_time( void )
85{
86 return vchiq_build_time;
87}
88EOF
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_shim.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_shim.c
index dddc828390d0..c3223fcdaf87 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_shim.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_shim.c
@@ -50,33 +50,6 @@ struct shim_service {
50 void *callback_param; 50 void *callback_param;
51}; 51};
52 52
53/* ----------------------------------------------------------------------
54 * return pointer to the mphi message driver function table
55 * -------------------------------------------------------------------- */
56const VCHI_MESSAGE_DRIVER_T *
57vchi_mphi_message_driver_func_table(void)
58{
59 return NULL;
60}
61
62/* ----------------------------------------------------------------------
63 * return a pointer to the 'single' connection driver fops
64 * -------------------------------------------------------------------- */
65const VCHI_CONNECTION_API_T *
66single_get_func_table(void)
67{
68 return NULL;
69}
70
71VCHI_CONNECTION_T *vchi_create_connection(
72 const VCHI_CONNECTION_API_T *function_table,
73 const VCHI_MESSAGE_DRIVER_T *low_level)
74{
75 (void)function_table;
76 (void)low_level;
77 return NULL;
78}
79
80/*********************************************************** 53/***********************************************************
81 * Name: vchi_msg_peek 54 * Name: vchi_msg_peek
82 * 55 *
@@ -517,9 +490,7 @@ EXPORT_SYMBOL(vchi_initialise);
517/*********************************************************** 490/***********************************************************
518 * Name: vchi_connect 491 * Name: vchi_connect
519 * 492 *
520 * Arguments: VCHI_CONNECTION_T **connections 493 * Arguments: VCHI_INSTANCE_T instance_handle
521 * const uint32_t num_connections
522 * VCHI_INSTANCE_T instance_handle)
523 * 494 *
524 * Description: Starts the command service on each connection, 495 * Description: Starts the command service on each connection,
525 * causing INIT messages to be pinged back and forth 496 * causing INIT messages to be pinged back and forth
@@ -527,15 +498,10 @@ EXPORT_SYMBOL(vchi_initialise);
527 * Returns: 0 if successful, failure otherwise 498 * Returns: 0 if successful, failure otherwise
528 * 499 *
529 ***********************************************************/ 500 ***********************************************************/
530int32_t vchi_connect(VCHI_CONNECTION_T **connections, 501int32_t vchi_connect(VCHI_INSTANCE_T instance_handle)
531 const uint32_t num_connections,
532 VCHI_INSTANCE_T instance_handle)
533{ 502{
534 VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle; 503 VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
535 504
536 (void)connections;
537 (void)num_connections;
538
539 return vchiq_connect(instance); 505 return vchiq_connect(instance);
540} 506}
541EXPORT_SYMBOL(vchi_connect); 507EXPORT_SYMBOL(vchi_connect);
diff --git a/drivers/staging/vt6655/rxtx.c b/drivers/staging/vt6655/rxtx.c
index 9c4a5325afc7..a7c1e46a953e 100644
--- a/drivers/staging/vt6655/rxtx.c
+++ b/drivers/staging/vt6655/rxtx.c
@@ -65,6 +65,7 @@ static const unsigned short wFB_Opt0[2][5] = {
65 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, /* fallback_rate0 */ 65 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, /* fallback_rate0 */
66 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, /* fallback_rate1 */ 66 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, /* fallback_rate1 */
67}; 67};
68
68static const unsigned short wFB_Opt1[2][5] = { 69static const unsigned short wFB_Opt1[2][5] = {
69 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, /* fallback_rate0 */ 70 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, /* fallback_rate0 */
70 {RATE_6M, RATE_6M, RATE_12M, RATE_12M, RATE_18M}, /* fallback_rate1 */ 71 {RATE_6M, RATE_6M, RATE_12M, RATE_12M, RATE_18M}, /* fallback_rate1 */
@@ -212,12 +213,12 @@ s_uGetRTSCTSRsvTime(
212 } else if (byRTSRsvType == 3) { /* CTSTxRrvTime_ba, only in 2.4GHZ */ 213 } else if (byRTSRsvType == 3) { /* CTSTxRrvTime_ba, only in 2.4GHZ */
213 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate); 214 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
214 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate); 215 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
215 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS; 216 uRrvTime = uCTSTime + uAckTime + uDataTime + 2 * pDevice->uSIFS;
216 return cpu_to_le16((u16)uRrvTime); 217 return cpu_to_le16((u16)uRrvTime);
217 } 218 }
218 219
219 /* RTSRrvTime */ 220 /* RTSRrvTime */
220 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS; 221 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3 * pDevice->uSIFS;
221 return cpu_to_le16((u16)uRrvTime); 222 return cpu_to_le16((u16)uRrvTime);
222} 223}
223 224
@@ -240,7 +241,7 @@ s_uGetDataDuration(
240 bool bLastFrag = false; 241 bool bLastFrag = false;
241 unsigned int uAckTime = 0, uNextPktTime = 0; 242 unsigned int uAckTime = 0, uNextPktTime = 0;
242 243
243 if (uFragIdx == (uMACfragNum-1)) 244 if (uFragIdx == (uMACfragNum - 1))
244 bLastFrag = true; 245 bLastFrag = true;
245 246
246 switch (byDurType) { 247 switch (byDurType) {
@@ -253,7 +254,7 @@ s_uGetDataDuration(
253 return 0; 254 return 0;
254 } 255 }
255 } else {/* First Frag or Mid Frag */ 256 } else {/* First Frag or Mid Frag */
256 if (uFragIdx == (uMACfragNum-2)) 257 if (uFragIdx == (uMACfragNum - 2))
257 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); 258 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
258 else 259 else
259 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck); 260 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
@@ -276,7 +277,7 @@ s_uGetDataDuration(
276 return 0; 277 return 0;
277 } 278 }
278 } else {/* First Frag or Mid Frag */ 279 } else {/* First Frag or Mid Frag */
279 if (uFragIdx == (uMACfragNum-2)) 280 if (uFragIdx == (uMACfragNum - 2))
280 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck); 281 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
281 else 282 else
282 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck); 283 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
@@ -305,7 +306,7 @@ s_uGetDataDuration(
305 else if (wRate > RATE_54M) 306 else if (wRate > RATE_54M)
306 wRate = RATE_54M; 307 wRate = RATE_54M;
307 308
308 if (uFragIdx == (uMACfragNum-2)) 309 if (uFragIdx == (uMACfragNum - 2))
309 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck); 310 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
310 else 311 else
311 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck); 312 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
@@ -316,7 +317,7 @@ s_uGetDataDuration(
316 else if (wRate > RATE_54M) 317 else if (wRate > RATE_54M)
317 wRate = RATE_54M; 318 wRate = RATE_54M;
318 319
319 if (uFragIdx == (uMACfragNum-2)) 320 if (uFragIdx == (uMACfragNum - 2))
320 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck); 321 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
321 else 322 else
322 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck); 323 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
@@ -346,7 +347,7 @@ s_uGetDataDuration(
346 else if (wRate > RATE_54M) 347 else if (wRate > RATE_54M)
347 wRate = RATE_54M; 348 wRate = RATE_54M;
348 349
349 if (uFragIdx == (uMACfragNum-2)) 350 if (uFragIdx == (uMACfragNum - 2))
350 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck); 351 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
351 else 352 else
352 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck); 353 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
@@ -357,7 +358,7 @@ s_uGetDataDuration(
357 else if (wRate > RATE_54M) 358 else if (wRate > RATE_54M)
358 wRate = RATE_54M; 359 wRate = RATE_54M;
359 360
360 if (uFragIdx == (uMACfragNum-2)) 361 if (uFragIdx == (uMACfragNum - 2))
361 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck); 362 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
362 else 363 else
363 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck); 364 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
@@ -1093,7 +1094,7 @@ s_cbFillTxBufHead(struct vnt_private *pDevice, unsigned char byPktType,
1093 sizeof(struct vnt_tx_datahead_g); 1094 sizeof(struct vnt_tx_datahead_g);
1094 } else { /* RTS_needless */ 1095 } else { /* RTS_needless */
1095 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize); 1096 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1096 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts)); 1097 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts));
1097 pvRTS = NULL; 1098 pvRTS = NULL;
1098 pvCTS = (void *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR); 1099 pvCTS = (void *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
1099 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize + 1100 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize +
@@ -1105,7 +1106,7 @@ s_cbFillTxBufHead(struct vnt_private *pDevice, unsigned char byPktType,
1105 /* Auto Fall Back */ 1106 /* Auto Fall Back */
1106 if (bRTS) {/* RTS_need */ 1107 if (bRTS) {/* RTS_need */
1107 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize); 1108 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1108 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts)); 1109 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts));
1109 pvRTS = (void *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts) + cbMICHDR); 1110 pvRTS = (void *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
1110 pvCTS = NULL; 1111 pvCTS = NULL;
1111 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts) + 1112 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
@@ -1114,7 +1115,7 @@ s_cbFillTxBufHead(struct vnt_private *pDevice, unsigned char byPktType,
1114 cbMICHDR + sizeof(struct vnt_rts_g_fb) + sizeof(struct vnt_tx_datahead_g_fb); 1115 cbMICHDR + sizeof(struct vnt_rts_g_fb) + sizeof(struct vnt_tx_datahead_g_fb);
1115 } else { /* RTS_needless */ 1116 } else { /* RTS_needless */
1116 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize); 1117 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1117 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts)); 1118 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts));
1118 pvRTS = NULL; 1119 pvRTS = NULL;
1119 pvCTS = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR); 1120 pvCTS = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
1120 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts) + 1121 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
@@ -1128,7 +1129,7 @@ s_cbFillTxBufHead(struct vnt_private *pDevice, unsigned char byPktType,
1128 if (byFBOption == AUTO_FB_NONE) { 1129 if (byFBOption == AUTO_FB_NONE) {
1129 if (bRTS) { 1130 if (bRTS) {
1130 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize); 1131 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1131 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab)); 1132 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab));
1132 pvRTS = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR); 1133 pvRTS = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
1133 pvCTS = NULL; 1134 pvCTS = NULL;
1134 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize + 1135 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize +
@@ -1137,7 +1138,7 @@ s_cbFillTxBufHead(struct vnt_private *pDevice, unsigned char byPktType,
1137 cbMICHDR + sizeof(struct vnt_rts_ab) + sizeof(struct vnt_tx_datahead_ab); 1138 cbMICHDR + sizeof(struct vnt_rts_ab) + sizeof(struct vnt_tx_datahead_ab);
1138 } else { /* RTS_needless, need MICHDR */ 1139 } else { /* RTS_needless, need MICHDR */
1139 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize); 1140 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1140 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab)); 1141 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab));
1141 pvRTS = NULL; 1142 pvRTS = NULL;
1142 pvCTS = NULL; 1143 pvCTS = NULL;
1143 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR); 1144 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
diff --git a/drivers/staging/wilc1000/Kconfig b/drivers/staging/wilc1000/Kconfig
index 73f7fefd3bc3..f9d3ad41c862 100644
--- a/drivers/staging/wilc1000/Kconfig
+++ b/drivers/staging/wilc1000/Kconfig
@@ -1,13 +1,13 @@
1config WILC1000 1config WILC1000
2 tristate 2 tristate
3 ---help--- 3 help
4 This module only support IEEE 802.11n WiFi. 4 This module only support IEEE 802.11n WiFi.
5 5
6config WILC1000_SDIO 6config WILC1000_SDIO
7 tristate "Atmel WILC1000 SDIO (WiFi only)" 7 tristate "Atmel WILC1000 SDIO (WiFi only)"
8 depends on CFG80211 && INET && MMC 8 depends on CFG80211 && INET && MMC
9 select WILC1000 9 select WILC1000
10 ---help--- 10 help
11 This module adds support for the SDIO interface of adapters using 11 This module adds support for the SDIO interface of adapters using
12 WILC1000 chipset. The Atmel WILC1000 SDIO is a full speed interface. 12 WILC1000 chipset. The Atmel WILC1000 SDIO is a full speed interface.
13 It meets SDIO card specification version 2.0. The interface supports 13 It meets SDIO card specification version 2.0. The interface supports
@@ -21,7 +21,7 @@ config WILC1000_SPI
21 tristate "Atmel WILC1000 SPI (WiFi only)" 21 tristate "Atmel WILC1000 SPI (WiFi only)"
22 depends on CFG80211 && INET && SPI 22 depends on CFG80211 && INET && SPI
23 select WILC1000 23 select WILC1000
24 ---help--- 24 help
25 This module adds support for the SPI interface of adapters using 25 This module adds support for the SPI interface of adapters using
26 WILC1000 chipset. The Atmel WILC1000 has a Serial Peripheral 26 WILC1000 chipset. The Atmel WILC1000 has a Serial Peripheral
27 Interface (SPI) that operates as a SPI slave. This SPI interface can 27 Interface (SPI) that operates as a SPI slave. This SPI interface can
@@ -34,7 +34,7 @@ config WILC1000_HW_OOB_INTR
34 bool "WILC1000 out of band interrupt" 34 bool "WILC1000 out of band interrupt"
35 depends on WILC1000_SDIO 35 depends on WILC1000_SDIO
36 default n 36 default n
37 ---help--- 37 help
38 This option enables out-of-band interrupt support for the WILC1000 38 This option enables out-of-band interrupt support for the WILC1000
39 chipset. This OOB interrupt is intended to provide a faster interrupt 39 chipset. This OOB interrupt is intended to provide a faster interrupt
40 mechanism for SDIO host controllers that don't support SDIO interrupt. 40 mechanism for SDIO host controllers that don't support SDIO interrupt.
diff --git a/drivers/staging/wilc1000/Makefile b/drivers/staging/wilc1000/Makefile
index ee7e26b886a5..37e8560e501e 100644
--- a/drivers/staging/wilc1000/Makefile
+++ b/drivers/staging/wilc1000/Makefile
@@ -4,12 +4,9 @@ obj-$(CONFIG_WILC1000) += wilc1000.o
4ccflags-y += -DFIRMWARE_1002=\"atmel/wilc1002_firmware.bin\" \ 4ccflags-y += -DFIRMWARE_1002=\"atmel/wilc1002_firmware.bin\" \
5 -DFIRMWARE_1003=\"atmel/wilc1003_firmware.bin\" 5 -DFIRMWARE_1003=\"atmel/wilc1003_firmware.bin\"
6 6
7ccflags-y += -I$(src)/ -DWILC_ASIC_A0 -DWILC_DEBUGFS
8
9wilc1000-objs := wilc_wfi_cfgoperations.o linux_wlan.o linux_mon.o \ 7wilc1000-objs := wilc_wfi_cfgoperations.o linux_wlan.o linux_mon.o \
10 coreconfigurator.o host_interface.o \ 8 coreconfigurator.o host_interface.o \
11 wilc_wlan_cfg.o wilc_debugfs.o \ 9 wilc_wlan_cfg.o wilc_wlan.o
12 wilc_wlan.o
13 10
14obj-$(CONFIG_WILC1000_SDIO) += wilc1000-sdio.o 11obj-$(CONFIG_WILC1000_SDIO) += wilc1000-sdio.o
15wilc1000-sdio-objs += wilc_sdio.o 12wilc1000-sdio-objs += wilc_sdio.o
diff --git a/drivers/staging/wilc1000/coreconfigurator.c b/drivers/staging/wilc1000/coreconfigurator.c
index e5420676afb3..d6d3a971be43 100644
--- a/drivers/staging/wilc1000/coreconfigurator.c
+++ b/drivers/staging/wilc1000/coreconfigurator.c
@@ -116,7 +116,7 @@ static inline void get_address3(u8 *msa, u8 *addr)
116 memcpy(addr, msa + 16, 6); 116 memcpy(addr, msa + 16, 6);
117} 117}
118 118
119static inline void get_BSSID(u8 *data, u8 *bssid) 119static inline void get_bssid(u8 *data, u8 *bssid)
120{ 120{
121 if (get_from_ds(data) == 1) 121 if (get_from_ds(data) == 1)
122 get_address2(data, bssid); 122 get_address2(data, bssid);
@@ -233,7 +233,7 @@ s32 wilc_parse_network_info(u8 *msg_buffer,
233 network_info->tsf_hi = tsf_lo | ((u64)tsf_hi << 32); 233 network_info->tsf_hi = tsf_lo | ((u64)tsf_hi << 32);
234 234
235 get_ssid(msa, network_info->ssid, &network_info->ssid_len); 235 get_ssid(msa, network_info->ssid, &network_info->ssid_len);
236 get_BSSID(msa, network_info->bssid); 236 get_bssid(msa, network_info->bssid);
237 237
238 network_info->ch = get_current_channel_802_11n(msa, rx_len 238 network_info->ch = get_current_channel_802_11n(msa, rx_len
239 + FCS_LEN); 239 + FCS_LEN);
diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index 42d8accb1f60..01db8999335e 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -90,6 +90,7 @@ struct beacon_attr {
90struct set_multicast { 90struct set_multicast {
91 bool enabled; 91 bool enabled;
92 u32 cnt; 92 u32 cnt;
93 u8 *mc_list;
93}; 94};
94 95
95struct del_all_sta { 96struct del_all_sta {
@@ -186,23 +187,7 @@ struct join_bss_param {
186}; 187};
187 188
188static struct host_if_drv *terminated_handle; 189static struct host_if_drv *terminated_handle;
189bool wilc_optaining_ip;
190static u8 p2p_listen_state;
191static struct workqueue_struct *hif_workqueue;
192static struct completion hif_driver_comp;
193static struct mutex hif_deinit_lock; 190static struct mutex hif_deinit_lock;
194static struct timer_list periodic_rssi;
195static struct wilc_vif *periodic_rssi_vif;
196
197u8 wilc_multicast_mac_addr_list[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN];
198
199static u8 rcv_assoc_resp[MAX_ASSOC_RESP_FRAME_SIZE];
200
201static u8 set_ip[2][4];
202static u8 get_ip[2][4];
203static u32 clients_count;
204
205static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx);
206 191
207/* 'msg' should be free by the caller for syc */ 192/* 'msg' should be free by the caller for syc */
208static struct host_if_msg* 193static struct host_if_msg*
@@ -229,7 +214,11 @@ wilc_alloc_work(struct wilc_vif *vif, void (*work_fun)(struct work_struct *),
229static int wilc_enqueue_work(struct host_if_msg *msg) 214static int wilc_enqueue_work(struct host_if_msg *msg)
230{ 215{
231 INIT_WORK(&msg->work, msg->fn); 216 INIT_WORK(&msg->work, msg->fn);
232 if (!hif_workqueue || !queue_work(hif_workqueue, &msg->work)) 217
218 if (!msg->vif || !msg->vif->wilc || !msg->vif->wilc->hif_workqueue)
219 return -EINVAL;
220
221 if (!queue_work(msg->vif->wilc->hif_workqueue, &msg->work))
233 return -EINVAL; 222 return -EINVAL;
234 223
235 return 0; 224 return 0;
@@ -320,10 +309,12 @@ static void handle_set_wfi_drv_handler(struct work_struct *work)
320 if (ret) 309 if (ret)
321 netdev_err(vif->ndev, "Failed to set driver handler\n"); 310 netdev_err(vif->ndev, "Failed to set driver handler\n");
322 311
323 complete(&hif_driver_comp);
324 kfree(buffer); 312 kfree(buffer);
325 313
326free_msg: 314free_msg:
315 if (msg->is_sync)
316 complete(&msg->work_comp);
317
327 kfree(msg); 318 kfree(msg);
328} 319}
329 320
@@ -343,73 +334,12 @@ static void handle_set_operation_mode(struct work_struct *work)
343 ret = wilc_send_config_pkt(vif, SET_CFG, &wid, 1, 334 ret = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
344 wilc_get_vif_idx(vif)); 335 wilc_get_vif_idx(vif));
345 336
346 if (hif_op_mode->mode == IDLE_MODE)
347 complete(&hif_driver_comp);
348
349 if (ret) 337 if (ret)
350 netdev_err(vif->ndev, "Failed to set operation mode\n"); 338 netdev_err(vif->ndev, "Failed to set operation mode\n");
351 339
352 kfree(msg); 340 kfree(msg);
353} 341}
354 342
355static void handle_set_ip_address(struct work_struct *work)
356{
357 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
358 struct wilc_vif *vif = msg->vif;
359 u8 *ip_addr = msg->body.ip_info.ip_addr;
360 u8 idx = msg->body.ip_info.idx;
361 int ret;
362 struct wid wid;
363 char firmware_ip_addr[4] = {0};
364
365 if (ip_addr[0] < 192)
366 ip_addr[0] = 0;
367
368 memcpy(set_ip[idx], ip_addr, IP_ALEN);
369
370 wid.id = WID_IP_ADDRESS;
371 wid.type = WID_STR;
372 wid.val = ip_addr;
373 wid.size = IP_ALEN;
374
375 ret = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
376 wilc_get_vif_idx(vif));
377
378 host_int_get_ipaddress(vif, firmware_ip_addr, idx);
379
380 if (ret)
381 netdev_err(vif->ndev, "Failed to set IP address\n");
382 kfree(msg);
383}
384
385static void handle_get_ip_address(struct work_struct *work)
386{
387 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
388 struct wilc_vif *vif = msg->vif;
389 u8 idx = msg->body.ip_info.idx;
390 int ret;
391 struct wid wid;
392
393 wid.id = WID_IP_ADDRESS;
394 wid.type = WID_STR;
395 wid.val = kmalloc(IP_ALEN, GFP_KERNEL);
396 wid.size = IP_ALEN;
397
398 ret = wilc_send_config_pkt(vif, GET_CFG, &wid, 1,
399 wilc_get_vif_idx(vif));
400
401 memcpy(get_ip[idx], wid.val, IP_ALEN);
402
403 kfree(wid.val);
404
405 if (memcmp(get_ip[idx], set_ip[idx], IP_ALEN) != 0)
406 wilc_setup_ipaddress(vif, set_ip[idx], idx);
407
408 if (ret)
409 netdev_err(vif->ndev, "Failed to get IP address\n");
410 kfree(msg);
411}
412
413static void handle_get_mac_address(struct work_struct *work) 343static void handle_get_mac_address(struct work_struct *work)
414{ 344{
415 struct host_if_msg *msg = container_of(work, struct host_if_msg, work); 345 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
@@ -791,7 +721,7 @@ static void handle_scan(struct work_struct *work)
791 goto error; 721 goto error;
792 } 722 }
793 723
794 if (wilc_optaining_ip || wilc_connecting) { 724 if (vif->obtaining_ip || vif->connecting) {
795 netdev_err(vif->ndev, "Don't do obss scan\n"); 725 netdev_err(vif->ndev, "Don't do obss scan\n");
796 result = -EBUSY; 726 result = -EBUSY;
797 goto error; 727 goto error;
@@ -883,7 +813,6 @@ error:
883 kfree(msg); 813 kfree(msg);
884} 814}
885 815
886u8 wilc_connected_ssid[6] = {0};
887static void handle_connect(struct work_struct *work) 816static void handle_connect(struct work_struct *work)
888{ 817{
889 struct host_if_msg *msg = container_of(work, struct host_if_msg, work); 818 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
@@ -905,11 +834,6 @@ static void handle_connect(struct work_struct *work)
905 return; 834 return;
906 } 835 }
907 836
908 if (memcmp(conn_attr->bssid, wilc_connected_ssid, ETH_ALEN) == 0) {
909 netdev_err(vif->ndev, "Discard connect request\n");
910 goto error;
911 }
912
913 bss_param = conn_attr->params; 837 bss_param = conn_attr->params;
914 if (!bss_param) { 838 if (!bss_param) {
915 netdev_err(vif->ndev, "Required BSSID not found\n"); 839 netdev_err(vif->ndev, "Required BSSID not found\n");
@@ -1089,10 +1013,6 @@ static void handle_connect(struct work_struct *work)
1089 cur_byte = wid_list[wid_cnt].val; 1013 cur_byte = wid_list[wid_cnt].val;
1090 wid_cnt++; 1014 wid_cnt++;
1091 1015
1092 if (conn_attr->bssid)
1093 memcpy(wilc_connected_ssid,
1094 conn_attr->bssid, ETH_ALEN);
1095
1096 result = wilc_send_config_pkt(vif, SET_CFG, wid_list, 1016 result = wilc_send_config_pkt(vif, SET_CFG, wid_list,
1097 wid_cnt, 1017 wid_cnt,
1098 wilc_get_vif_idx(vif)); 1018 wilc_get_vif_idx(vif));
@@ -1215,8 +1135,6 @@ static void handle_connect_timeout(struct work_struct *work)
1215 kfree(hif_drv->usr_conn_req.ies); 1135 kfree(hif_drv->usr_conn_req.ies);
1216 hif_drv->usr_conn_req.ies = NULL; 1136 hif_drv->usr_conn_req.ies = NULL;
1217 1137
1218 eth_zero_addr(wilc_connected_ssid);
1219
1220out: 1138out:
1221 kfree(msg); 1139 kfree(msg);
1222} 1140}
@@ -1456,10 +1374,10 @@ done:
1456 kfree(msg); 1374 kfree(msg);
1457} 1375}
1458 1376
1459static s32 host_int_get_assoc_res_info(struct wilc_vif *vif, 1377static void host_int_get_assoc_res_info(struct wilc_vif *vif,
1460 u8 *assoc_resp_info, 1378 u8 *assoc_resp_info,
1461 u32 max_assoc_resp_info_len, 1379 u32 max_assoc_resp_info_len,
1462 u32 *rcvd_assoc_resp_info_len) 1380 u32 *rcvd_assoc_resp_info_len)
1463{ 1381{
1464 int result; 1382 int result;
1465 struct wid wid; 1383 struct wid wid;
@@ -1474,11 +1392,10 @@ static s32 host_int_get_assoc_res_info(struct wilc_vif *vif,
1474 if (result) { 1392 if (result) {
1475 *rcvd_assoc_resp_info_len = 0; 1393 *rcvd_assoc_resp_info_len = 0;
1476 netdev_err(vif->ndev, "Failed to send association response\n"); 1394 netdev_err(vif->ndev, "Failed to send association response\n");
1477 return -EINVAL; 1395 return;
1478 } 1396 }
1479 1397
1480 *rcvd_assoc_resp_info_len = wid.size; 1398 *rcvd_assoc_resp_info_len = wid.size;
1481 return result;
1482} 1399}
1483 1400
1484static inline void host_int_free_user_conn_req(struct host_if_drv *hif_drv) 1401static inline void host_int_free_user_conn_req(struct host_if_drv *hif_drv)
@@ -1504,16 +1421,16 @@ static inline void host_int_parse_assoc_resp_info(struct wilc_vif *vif,
1504 if (mac_status == MAC_STATUS_CONNECTED) { 1421 if (mac_status == MAC_STATUS_CONNECTED) {
1505 u32 assoc_resp_info_len; 1422 u32 assoc_resp_info_len;
1506 1423
1507 memset(rcv_assoc_resp, 0, MAX_ASSOC_RESP_FRAME_SIZE); 1424 memset(hif_drv->assoc_resp, 0, MAX_ASSOC_RESP_FRAME_SIZE);
1508 1425
1509 host_int_get_assoc_res_info(vif, rcv_assoc_resp, 1426 host_int_get_assoc_res_info(vif, hif_drv->assoc_resp,
1510 MAX_ASSOC_RESP_FRAME_SIZE, 1427 MAX_ASSOC_RESP_FRAME_SIZE,
1511 &assoc_resp_info_len); 1428 &assoc_resp_info_len);
1512 1429
1513 if (assoc_resp_info_len != 0) { 1430 if (assoc_resp_info_len != 0) {
1514 s32 err = 0; 1431 s32 err = 0;
1515 1432
1516 err = wilc_parse_assoc_resp_info(rcv_assoc_resp, 1433 err = wilc_parse_assoc_resp_info(hif_drv->assoc_resp,
1517 assoc_resp_info_len, 1434 assoc_resp_info_len,
1518 &conn_info); 1435 &conn_info);
1519 if (err) 1436 if (err)
@@ -1523,16 +1440,6 @@ static inline void host_int_parse_assoc_resp_info(struct wilc_vif *vif,
1523 } 1440 }
1524 } 1441 }
1525 1442
1526 if (mac_status == MAC_STATUS_CONNECTED &&
1527 conn_info.status != WLAN_STATUS_SUCCESS) {
1528 netdev_err(vif->ndev,
1529 "Received MAC status is MAC_STATUS_CONNECTED, Assoc Resp is not SUCCESS\n");
1530 eth_zero_addr(wilc_connected_ssid);
1531 } else if (mac_status == MAC_STATUS_DISCONNECTED) {
1532 netdev_err(vif->ndev, "Received MAC status is MAC_STATUS_DISCONNECTED\n");
1533 eth_zero_addr(wilc_connected_ssid);
1534 }
1535
1536 if (hif_drv->usr_conn_req.bssid) { 1443 if (hif_drv->usr_conn_req.bssid) {
1537 memcpy(conn_info.bssid, hif_drv->usr_conn_req.bssid, 6); 1444 memcpy(conn_info.bssid, hif_drv->usr_conn_req.bssid, 6);
1538 1445
@@ -1562,8 +1469,8 @@ static inline void host_int_parse_assoc_resp_info(struct wilc_vif *vif,
1562 1469
1563 hif_drv->hif_state = HOST_IF_CONNECTED; 1470 hif_drv->hif_state = HOST_IF_CONNECTED;
1564 1471
1565 wilc_optaining_ip = true; 1472 vif->obtaining_ip = true;
1566 mod_timer(&wilc_during_ip_timer, 1473 mod_timer(&vif->during_ip_timer,
1567 jiffies + msecs_to_jiffies(10000)); 1474 jiffies + msecs_to_jiffies(10000));
1568 } else { 1475 } else {
1569 hif_drv->hif_state = HOST_IF_IDLE; 1476 hif_drv->hif_state = HOST_IF_IDLE;
@@ -1595,7 +1502,7 @@ static inline void host_int_handle_disconnect(struct wilc_vif *vif)
1595 disconn_info.ie_len = 0; 1502 disconn_info.ie_len = 0;
1596 1503
1597 if (conn_result) { 1504 if (conn_result) {
1598 wilc_optaining_ip = false; 1505 vif->obtaining_ip = false;
1599 wilc_set_power_mgmt(vif, 0, 0); 1506 wilc_set_power_mgmt(vif, 0, 0);
1600 1507
1601 conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF, NULL, 0, 1508 conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF, NULL, 0,
@@ -1942,11 +1849,9 @@ static void handle_disconnect(struct work_struct *work)
1942 wid.val = (s8 *)&dummy_reason_code; 1849 wid.val = (s8 *)&dummy_reason_code;
1943 wid.size = sizeof(char); 1850 wid.size = sizeof(char);
1944 1851
1945 wilc_optaining_ip = false; 1852 vif->obtaining_ip = false;
1946 wilc_set_power_mgmt(vif, 0, 0); 1853 wilc_set_power_mgmt(vif, 0, 0);
1947 1854
1948 eth_zero_addr(wilc_connected_ssid);
1949
1950 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1, 1855 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
1951 wilc_get_vif_idx(vif)); 1856 wilc_get_vif_idx(vif));
1952 1857
@@ -2076,9 +1981,9 @@ static void handle_get_statistics(struct work_struct *work)
2076 1981
2077 if (stats->link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH && 1982 if (stats->link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH &&
2078 stats->link_speed != DEFAULT_LINK_SPEED) 1983 stats->link_speed != DEFAULT_LINK_SPEED)
2079 wilc_enable_tcp_ack_filter(true); 1984 wilc_enable_tcp_ack_filter(vif, true);
2080 else if (stats->link_speed != DEFAULT_LINK_SPEED) 1985 else if (stats->link_speed != DEFAULT_LINK_SPEED)
2081 wilc_enable_tcp_ack_filter(false); 1986 wilc_enable_tcp_ack_filter(vif, false);
2082 1987
2083 /* free 'msg' for async command, for sync caller will free it */ 1988 /* free 'msg' for async command, for sync caller will free it */
2084 if (msg->is_sync) 1989 if (msg->is_sync)
@@ -2397,7 +2302,7 @@ static int handle_remain_on_chan(struct wilc_vif *vif,
2397 goto error; 2302 goto error;
2398 } 2303 }
2399 2304
2400 if (wilc_optaining_ip || wilc_connecting) { 2305 if (vif->obtaining_ip || vif->connecting) {
2401 result = -EBUSY; 2306 result = -EBUSY;
2402 goto error; 2307 goto error;
2403 } 2308 }
@@ -2422,7 +2327,6 @@ static int handle_remain_on_chan(struct wilc_vif *vif,
2422 netdev_err(vif->ndev, "Failed to set remain on channel\n"); 2327 netdev_err(vif->ndev, "Failed to set remain on channel\n");
2423 2328
2424error: 2329error:
2425 p2p_listen_state = 1;
2426 hif_drv->remain_on_ch_timer_vif = vif; 2330 hif_drv->remain_on_ch_timer_vif = vif;
2427 mod_timer(&hif_drv->remain_on_ch_timer, 2331 mod_timer(&hif_drv->remain_on_ch_timer,
2428 jiffies + msecs_to_jiffies(hif_remain_ch->duration)); 2332 jiffies + msecs_to_jiffies(hif_remain_ch->duration));
@@ -2478,8 +2382,9 @@ static void handle_listen_state_expired(struct work_struct *work)
2478 struct wid wid; 2382 struct wid wid;
2479 int result; 2383 int result;
2480 struct host_if_drv *hif_drv = vif->hif_drv; 2384 struct host_if_drv *hif_drv = vif->hif_drv;
2385 struct wilc_priv *priv = wdev_priv(vif->ndev->ieee80211_ptr);
2481 2386
2482 if (p2p_listen_state) { 2387 if (priv->p2p_listen_state) {
2483 remain_on_chan_flag = false; 2388 remain_on_chan_flag = false;
2484 wid.id = WID_REMAIN_ON_CHAN; 2389 wid.id = WID_REMAIN_ON_CHAN;
2485 wid.type = WID_STR; 2390 wid.type = WID_STR;
@@ -2504,7 +2409,6 @@ static void handle_listen_state_expired(struct work_struct *work)
2504 hif_drv->remain_on_ch.expired(hif_drv->remain_on_ch.arg, 2409 hif_drv->remain_on_ch.expired(hif_drv->remain_on_ch.arg,
2505 hif_remain_ch->id); 2410 hif_remain_ch->id);
2506 } 2411 }
2507 p2p_listen_state = 0;
2508 } else { 2412 } else {
2509 netdev_dbg(vif->ndev, "Not in listen state\n"); 2413 netdev_dbg(vif->ndev, "Not in listen state\n");
2510 } 2414 }
@@ -2589,8 +2493,8 @@ static void handle_set_mcast_filter(struct work_struct *work)
2589 *cur_byte++ = ((hif_set_mc->cnt >> 16) & 0xFF); 2493 *cur_byte++ = ((hif_set_mc->cnt >> 16) & 0xFF);
2590 *cur_byte++ = ((hif_set_mc->cnt >> 24) & 0xFF); 2494 *cur_byte++ = ((hif_set_mc->cnt >> 24) & 0xFF);
2591 2495
2592 if (hif_set_mc->cnt > 0) 2496 if (hif_set_mc->cnt > 0 && hif_set_mc->mc_list)
2593 memcpy(cur_byte, wilc_multicast_mac_addr_list, 2497 memcpy(cur_byte, hif_set_mc->mc_list,
2594 ((hif_set_mc->cnt) * ETH_ALEN)); 2498 ((hif_set_mc->cnt) * ETH_ALEN));
2595 2499
2596 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1, 2500 result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
@@ -2599,6 +2503,7 @@ static void handle_set_mcast_filter(struct work_struct *work)
2599 netdev_err(vif->ndev, "Failed to send setup multicast\n"); 2503 netdev_err(vif->ndev, "Failed to send setup multicast\n");
2600 2504
2601error: 2505error:
2506 kfree(hif_set_mc->mc_list);
2602 kfree(wid.val); 2507 kfree(wid.val);
2603 kfree(msg); 2508 kfree(msg);
2604} 2509}
@@ -2661,14 +2566,6 @@ static void handle_remain_on_chan_work(struct work_struct *work)
2661 kfree(msg); 2566 kfree(msg);
2662} 2567}
2663 2568
2664static void handle_hif_exit_work(struct work_struct *work)
2665{
2666 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
2667
2668 /* free 'msg' data in caller */
2669 complete(&msg->work_comp);
2670}
2671
2672static void handle_scan_complete(struct work_struct *work) 2569static void handle_scan_complete(struct work_struct *work)
2673{ 2570{
2674 struct host_if_msg *msg = container_of(work, struct host_if_msg, work); 2571 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
@@ -3195,12 +3092,12 @@ int wilc_set_mac_chnl_num(struct wilc_vif *vif, u8 channel)
3195} 3092}
3196 3093
3197int wilc_set_wfi_drv_handler(struct wilc_vif *vif, int index, u8 mode, 3094int wilc_set_wfi_drv_handler(struct wilc_vif *vif, int index, u8 mode,
3198 u8 ifc_id) 3095 u8 ifc_id, bool is_sync)
3199{ 3096{
3200 int result; 3097 int result;
3201 struct host_if_msg *msg; 3098 struct host_if_msg *msg;
3202 3099
3203 msg = wilc_alloc_work(vif, handle_set_wfi_drv_handler, false); 3100 msg = wilc_alloc_work(vif, handle_set_wfi_drv_handler, is_sync);
3204 if (IS_ERR(msg)) 3101 if (IS_ERR(msg))
3205 return PTR_ERR(msg); 3102 return PTR_ERR(msg);
3206 3103
@@ -3212,8 +3109,12 @@ int wilc_set_wfi_drv_handler(struct wilc_vif *vif, int index, u8 mode,
3212 if (result) { 3109 if (result) {
3213 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__); 3110 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
3214 kfree(msg); 3111 kfree(msg);
3112 return result;
3215 } 3113 }
3216 3114
3115 if (is_sync)
3116 wait_for_completion(&msg->work_comp);
3117
3217 return result; 3118 return result;
3218} 3119}
3219 3120
@@ -3421,9 +3322,9 @@ int wilc_hif_set_cfg(struct wilc_vif *vif,
3421 return result; 3322 return result;
3422} 3323}
3423 3324
3424static void get_periodic_rssi(struct timer_list *unused) 3325static void get_periodic_rssi(struct timer_list *t)
3425{ 3326{
3426 struct wilc_vif *vif = periodic_rssi_vif; 3327 struct wilc_vif *vif = from_timer(vif, t, periodic_rssi);
3427 3328
3428 if (!vif->hif_drv) { 3329 if (!vif->hif_drv) {
3429 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__); 3330 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
@@ -3431,9 +3332,9 @@ static void get_periodic_rssi(struct timer_list *unused)
3431 } 3332 }
3432 3333
3433 if (vif->hif_drv->hif_state == HOST_IF_CONNECTED) 3334 if (vif->hif_drv->hif_state == HOST_IF_CONNECTED)
3434 wilc_get_statistics(vif, &vif->wilc->dummy_statistics, false); 3335 wilc_get_statistics(vif, &vif->periodic_stat, false);
3435 3336
3436 mod_timer(&periodic_rssi, jiffies + msecs_to_jiffies(5000)); 3337 mod_timer(&vif->periodic_rssi, jiffies + msecs_to_jiffies(5000));
3437} 3338}
3438 3339
3439int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler) 3340int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
@@ -3455,25 +3356,13 @@ int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
3455 break; 3356 break;
3456 } 3357 }
3457 3358
3458 wilc_optaining_ip = false; 3359 vif->obtaining_ip = false;
3459 3360
3460 if (clients_count == 0) { 3361 if (wilc->clients_count == 0)
3461 init_completion(&hif_driver_comp);
3462 mutex_init(&hif_deinit_lock); 3362 mutex_init(&hif_deinit_lock);
3463 }
3464 3363
3465 if (clients_count == 0) { 3364 timer_setup(&vif->periodic_rssi, get_periodic_rssi, 0);
3466 hif_workqueue = create_singlethread_workqueue("WILC_wq"); 3365 mod_timer(&vif->periodic_rssi, jiffies + msecs_to_jiffies(5000));
3467 if (!hif_workqueue) {
3468 netdev_err(vif->ndev, "Failed to create workqueue\n");
3469 kfree(hif_drv);
3470 return -ENOMEM;
3471 }
3472
3473 periodic_rssi_vif = vif;
3474 timer_setup(&periodic_rssi, get_periodic_rssi, 0);
3475 mod_timer(&periodic_rssi, jiffies + msecs_to_jiffies(5000));
3476 }
3477 3366
3478 timer_setup(&hif_drv->scan_timer, timer_scan_cb, 0); 3367 timer_setup(&hif_drv->scan_timer, timer_scan_cb, 0);
3479 timer_setup(&hif_drv->connect_timer, timer_connect_cb, 0); 3368 timer_setup(&hif_drv->connect_timer, timer_connect_cb, 0);
@@ -3493,7 +3382,7 @@ int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
3493 3382
3494 mutex_unlock(&hif_drv->cfg_values_lock); 3383 mutex_unlock(&hif_drv->cfg_values_lock);
3495 3384
3496 clients_count++; 3385 wilc->clients_count++;
3497 3386
3498 return 0; 3387 return 0;
3499} 3388}
@@ -3514,11 +3403,10 @@ int wilc_deinit(struct wilc_vif *vif)
3514 3403
3515 del_timer_sync(&hif_drv->scan_timer); 3404 del_timer_sync(&hif_drv->scan_timer);
3516 del_timer_sync(&hif_drv->connect_timer); 3405 del_timer_sync(&hif_drv->connect_timer);
3517 del_timer_sync(&periodic_rssi); 3406 del_timer_sync(&vif->periodic_rssi);
3518 del_timer_sync(&hif_drv->remain_on_ch_timer); 3407 del_timer_sync(&hif_drv->remain_on_ch_timer);
3519 3408
3520 wilc_set_wfi_drv_handler(vif, 0, 0, 0); 3409 wilc_set_wfi_drv_handler(vif, 0, 0, 0, true);
3521 wait_for_completion(&hif_driver_comp);
3522 3410
3523 if (hif_drv->usr_scan_req.scan_result) { 3411 if (hif_drv->usr_scan_req.scan_result) {
3524 hif_drv->usr_scan_req.scan_result(SCAN_EVENT_ABORTED, NULL, 3412 hif_drv->usr_scan_req.scan_result(SCAN_EVENT_ABORTED, NULL,
@@ -3529,25 +3417,9 @@ int wilc_deinit(struct wilc_vif *vif)
3529 3417
3530 hif_drv->hif_state = HOST_IF_IDLE; 3418 hif_drv->hif_state = HOST_IF_IDLE;
3531 3419
3532 if (clients_count == 1) {
3533 struct host_if_msg *msg;
3534
3535 msg = wilc_alloc_work(vif, handle_hif_exit_work, true);
3536 if (!IS_ERR(msg)) {
3537 result = wilc_enqueue_work(msg);
3538 if (result)
3539 netdev_err(vif->ndev, "deinit : Error(%d)\n",
3540 result);
3541 else
3542 wait_for_completion(&msg->work_comp);
3543 kfree(msg);
3544 }
3545 destroy_workqueue(hif_workqueue);
3546 }
3547
3548 kfree(hif_drv); 3420 kfree(hif_drv);
3549 3421
3550 clients_count--; 3422 vif->wilc->clients_count--;
3551 terminated_handle = NULL; 3423 terminated_handle = NULL;
3552 mutex_unlock(&hif_deinit_lock); 3424 mutex_unlock(&hif_deinit_lock);
3553 return result; 3425 return result;
@@ -3743,14 +3615,14 @@ int wilc_listen_state_expired(struct wilc_vif *vif, u32 session_id)
3743 return result; 3615 return result;
3744} 3616}
3745 3617
3746int wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg) 3618void wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg)
3747{ 3619{
3748 int result; 3620 int result;
3749 struct host_if_msg *msg; 3621 struct host_if_msg *msg;
3750 3622
3751 msg = wilc_alloc_work(vif, handle_register_frame, false); 3623 msg = wilc_alloc_work(vif, handle_register_frame, false);
3752 if (IS_ERR(msg)) 3624 if (IS_ERR(msg))
3753 return PTR_ERR(msg); 3625 return;
3754 3626
3755 switch (frame_type) { 3627 switch (frame_type) {
3756 case ACTION: 3628 case ACTION:
@@ -3772,8 +3644,6 @@ int wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg)
3772 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__); 3644 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
3773 kfree(msg); 3645 kfree(msg);
3774 } 3646 }
3775
3776 return result;
3777} 3647}
3778 3648
3779int wilc_add_beacon(struct wilc_vif *vif, u32 interval, u32 dtim_period, 3649int wilc_add_beacon(struct wilc_vif *vif, u32 interval, u32 dtim_period,
@@ -3992,8 +3862,8 @@ int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout)
3992 return result; 3862 return result;
3993} 3863}
3994 3864
3995int wilc_setup_multicast_filter(struct wilc_vif *vif, bool enabled, 3865int wilc_setup_multicast_filter(struct wilc_vif *vif, bool enabled, u32 count,
3996 u32 count) 3866 u8 *mc_list)
3997{ 3867{
3998 int result; 3868 int result;
3999 struct host_if_msg *msg; 3869 struct host_if_msg *msg;
@@ -4004,6 +3874,7 @@ int wilc_setup_multicast_filter(struct wilc_vif *vif, bool enabled,
4004 3874
4005 msg->body.multicast_info.enabled = enabled; 3875 msg->body.multicast_info.enabled = enabled;
4006 msg->body.multicast_info.cnt = count; 3876 msg->body.multicast_info.cnt = count;
3877 msg->body.multicast_info.mc_list = mc_list;
4007 3878
4008 result = wilc_enqueue_work(msg); 3879 result = wilc_enqueue_work(msg);
4009 if (result) { 3880 if (result) {
@@ -4013,48 +3884,6 @@ int wilc_setup_multicast_filter(struct wilc_vif *vif, bool enabled,
4013 return result; 3884 return result;
4014} 3885}
4015 3886
4016int wilc_setup_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx)
4017{
4018 int result;
4019 struct host_if_msg *msg;
4020
4021 msg = wilc_alloc_work(vif, handle_set_ip_address, false);
4022 if (IS_ERR(msg))
4023 return PTR_ERR(msg);
4024
4025 msg->body.ip_info.ip_addr = ip_addr;
4026 msg->body.ip_info.idx = idx;
4027
4028 result = wilc_enqueue_work(msg);
4029 if (result) {
4030 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
4031 kfree(msg);
4032 }
4033
4034 return result;
4035}
4036
4037static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx)
4038{
4039 int result;
4040 struct host_if_msg *msg;
4041
4042 msg = wilc_alloc_work(vif, handle_get_ip_address, false);
4043 if (IS_ERR(msg))
4044 return PTR_ERR(msg);
4045
4046 msg->body.ip_info.ip_addr = ip_addr;
4047 msg->body.ip_info.idx = idx;
4048
4049 result = wilc_enqueue_work(msg);
4050 if (result) {
4051 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
4052 kfree(msg);
4053 }
4054
4055 return result;
4056}
4057
4058int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power) 3887int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power)
4059{ 3888{
4060 int ret; 3889 int ret;
diff --git a/drivers/staging/wilc1000/host_interface.h b/drivers/staging/wilc1000/host_interface.h
index 84866a62a4d4..33fb7318734b 100644
--- a/drivers/staging/wilc1000/host_interface.h
+++ b/drivers/staging/wilc1000/host_interface.h
@@ -9,8 +9,6 @@
9#include <linux/ieee80211.h> 9#include <linux/ieee80211.h>
10#include "coreconfigurator.h" 10#include "coreconfigurator.h"
11 11
12#define IP_ALEN 4
13
14#define IDLE_MODE 0x00 12#define IDLE_MODE 0x00
15#define AP_MODE 0x01 13#define AP_MODE 0x01
16#define STATION_MODE 0x02 14#define STATION_MODE 0x02
@@ -284,6 +282,7 @@ struct host_if_drv {
284 282
285 bool ifc_up; 283 bool ifc_up;
286 int driver_handler_id; 284 int driver_handler_id;
285 u8 assoc_resp[MAX_ASSOC_RESP_FRAME_SIZE];
287}; 286};
288 287
289struct add_sta_param { 288struct add_sta_param {
@@ -341,18 +340,17 @@ int wilc_del_station(struct wilc_vif *vif, const u8 *mac_addr);
341int wilc_edit_station(struct wilc_vif *vif, 340int wilc_edit_station(struct wilc_vif *vif,
342 struct add_sta_param *sta_param); 341 struct add_sta_param *sta_param);
343int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout); 342int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout);
344int wilc_setup_multicast_filter(struct wilc_vif *vif, bool enabled, 343int wilc_setup_multicast_filter(struct wilc_vif *vif, bool enabled, u32 count,
345 u32 count); 344 u8 *mc_list);
346int wilc_setup_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx);
347int wilc_remain_on_channel(struct wilc_vif *vif, u32 session_id, 345int wilc_remain_on_channel(struct wilc_vif *vif, u32 session_id,
348 u32 duration, u16 chan, 346 u32 duration, u16 chan,
349 wilc_remain_on_chan_expired expired, 347 wilc_remain_on_chan_expired expired,
350 wilc_remain_on_chan_ready ready, 348 wilc_remain_on_chan_ready ready,
351 void *user_arg); 349 void *user_arg);
352int wilc_listen_state_expired(struct wilc_vif *vif, u32 session_id); 350int wilc_listen_state_expired(struct wilc_vif *vif, u32 session_id);
353int wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg); 351void wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg);
354int wilc_set_wfi_drv_handler(struct wilc_vif *vif, int index, u8 mode, 352int wilc_set_wfi_drv_handler(struct wilc_vif *vif, int index, u8 mode,
355 u8 ifc_id); 353 u8 ifc_id, bool is_sync);
356int wilc_set_operation_mode(struct wilc_vif *vif, u32 mode); 354int wilc_set_operation_mode(struct wilc_vif *vif, u32 mode);
357int wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats, 355int wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats,
358 bool is_sync); 356 bool is_sync);
@@ -361,11 +359,4 @@ int wilc_get_vif_idx(struct wilc_vif *vif);
361int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power); 359int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power);
362int wilc_get_tx_power(struct wilc_vif *vif, u8 *tx_power); 360int wilc_get_tx_power(struct wilc_vif *vif, u8 *tx_power);
363 361
364extern bool wilc_optaining_ip;
365extern u8 wilc_connected_ssid[6];
366extern u8 wilc_multicast_mac_addr_list[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN];
367
368extern int wilc_connecting;
369extern struct timer_list wilc_during_ip_timer;
370
371#endif 362#endif
diff --git a/drivers/staging/wilc1000/linux_mon.c b/drivers/staging/wilc1000/linux_mon.c
index 1afdb9e86bc1..a63446818eac 100644
--- a/drivers/staging/wilc1000/linux_mon.c
+++ b/drivers/staging/wilc1000/linux_mon.c
@@ -253,7 +253,7 @@ struct net_device *wilc_wfi_init_mon_interface(const char *name,
253 return wilc_wfi_mon; 253 return wilc_wfi_mon;
254} 254}
255 255
256int wilc_wfi_deinit_mon_interface(void) 256void wilc_wfi_deinit_mon_interface(void)
257{ 257{
258 bool rollback_lock = false; 258 bool rollback_lock = false;
259 259
@@ -270,5 +270,4 @@ int wilc_wfi_deinit_mon_interface(void)
270 } 270 }
271 wilc_wfi_mon = NULL; 271 wilc_wfi_mon = NULL;
272 } 272 }
273 return 0;
274} 273}
diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c
index 3b8d237decbf..76c901235e93 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -12,8 +12,6 @@
12 12
13#include "wilc_wfi_cfgoperations.h" 13#include "wilc_wfi_cfgoperations.h"
14 14
15bool wilc_enable_ps = true;
16
17static int dev_state_ev_handler(struct notifier_block *this, 15static int dev_state_ev_handler(struct notifier_block *this,
18 unsigned long event, void *ptr) 16 unsigned long event, void *ptr)
19{ 17{
@@ -50,11 +48,11 @@ static int dev_state_ev_handler(struct notifier_block *this,
50 case NETDEV_UP: 48 case NETDEV_UP:
51 if (vif->iftype == STATION_MODE || vif->iftype == CLIENT_MODE) { 49 if (vif->iftype == STATION_MODE || vif->iftype == CLIENT_MODE) {
52 hif_drv->ifc_up = 1; 50 hif_drv->ifc_up = 1;
53 wilc_optaining_ip = false; 51 vif->obtaining_ip = false;
54 del_timer(&wilc_during_ip_timer); 52 del_timer(&vif->during_ip_timer);
55 } 53 }
56 54
57 if (wilc_enable_ps) 55 if (vif->wilc->enable_ps)
58 wilc_set_power_mgmt(vif, 1, 0); 56 wilc_set_power_mgmt(vif, 1, 0);
59 57
60 netdev_dbg(dev, "[%s] Up IP\n", dev_iface->ifa_label); 58 netdev_dbg(dev, "[%s] Up IP\n", dev_iface->ifa_label);
@@ -63,14 +61,13 @@ static int dev_state_ev_handler(struct notifier_block *this,
63 netdev_dbg(dev, "IP add=%d:%d:%d:%d\n", 61 netdev_dbg(dev, "IP add=%d:%d:%d:%d\n",
64 ip_addr_buf[0], ip_addr_buf[1], 62 ip_addr_buf[0], ip_addr_buf[1],
65 ip_addr_buf[2], ip_addr_buf[3]); 63 ip_addr_buf[2], ip_addr_buf[3]);
66 wilc_setup_ipaddress(vif, ip_addr_buf, vif->idx);
67 64
68 break; 65 break;
69 66
70 case NETDEV_DOWN: 67 case NETDEV_DOWN:
71 if (vif->iftype == STATION_MODE || vif->iftype == CLIENT_MODE) { 68 if (vif->iftype == STATION_MODE || vif->iftype == CLIENT_MODE) {
72 hif_drv->ifc_up = 0; 69 hif_drv->ifc_up = 0;
73 wilc_optaining_ip = false; 70 vif->obtaining_ip = false;
74 } 71 }
75 72
76 if (memcmp(dev_iface->ifa_label, wlan_dev_name, 5) == 0) 73 if (memcmp(dev_iface->ifa_label, wlan_dev_name, 5) == 0)
@@ -85,8 +82,6 @@ static int dev_state_ev_handler(struct notifier_block *this,
85 ip_addr_buf[0], ip_addr_buf[1], 82 ip_addr_buf[0], ip_addr_buf[1],
86 ip_addr_buf[2], ip_addr_buf[3]); 83 ip_addr_buf[2], ip_addr_buf[3]);
87 84
88 wilc_setup_ipaddress(vif, ip_addr_buf, vif->idx);
89
90 break; 85 break;
91 86
92 default: 87 default:
@@ -164,9 +159,9 @@ static void deinit_irq(struct net_device *dev)
164 159
165void wilc_mac_indicate(struct wilc *wilc) 160void wilc_mac_indicate(struct wilc *wilc)
166{ 161{
167 int status; 162 s8 status;
168 163
169 wilc_wlan_cfg_get_val(WID_STATUS, (unsigned char *)&status, 4); 164 wilc_wlan_cfg_get_val(wilc, WID_STATUS, &status, 1);
170 if (wilc->mac_status == MAC_STATUS_INIT) { 165 if (wilc->mac_status == MAC_STATUS_INIT) {
171 wilc->mac_status = status; 166 wilc->mac_status = status;
172 complete(&wilc->sync_event); 167 complete(&wilc->sync_event);
@@ -197,14 +192,12 @@ static struct net_device *get_if_handler(struct wilc *wilc, u8 *mac_header)
197 return NULL; 192 return NULL;
198} 193}
199 194
200int wilc_wlan_set_bssid(struct net_device *wilc_netdev, u8 *bssid, u8 mode) 195void wilc_wlan_set_bssid(struct net_device *wilc_netdev, u8 *bssid, u8 mode)
201{ 196{
202 struct wilc_vif *vif = netdev_priv(wilc_netdev); 197 struct wilc_vif *vif = netdev_priv(wilc_netdev);
203 198
204 memcpy(vif->bssid, bssid, 6); 199 memcpy(vif->bssid, bssid, 6);
205 vif->mode = mode; 200 vif->mode = mode;
206
207 return 0;
208} 201}
209 202
210int wilc_wlan_get_num_conn_ifcs(struct wilc *wilc) 203int wilc_wlan_get_num_conn_ifcs(struct wilc *wilc)
@@ -269,9 +262,6 @@ static int wilc_wlan_get_firmware(struct net_device *dev)
269 262
270 netdev_info(dev, "loading firmware %s\n", firmware); 263 netdev_info(dev, "loading firmware %s\n", firmware);
271 264
272 if (!(&vif->ndev->dev))
273 goto fail;
274
275 if (request_firmware(&wilc_firmware, firmware, wilc->dev) != 0) { 265 if (request_firmware(&wilc_firmware, firmware, wilc->dev) != 0) {
276 netdev_err(dev, "%s - firmware not available\n", firmware); 266 netdev_err(dev, "%s - firmware not available\n", firmware);
277 ret = -1; 267 ret = -1;
@@ -532,7 +522,7 @@ fail:
532 return -1; 522 return -1;
533} 523}
534 524
535static int wlan_deinit_locks(struct net_device *dev) 525static void wlan_deinit_locks(struct net_device *dev)
536{ 526{
537 struct wilc_vif *vif = netdev_priv(dev); 527 struct wilc_vif *vif = netdev_priv(dev);
538 struct wilc *wilc = vif->wilc; 528 struct wilc *wilc = vif->wilc;
@@ -540,8 +530,6 @@ static int wlan_deinit_locks(struct net_device *dev)
540 mutex_destroy(&wilc->hif_cs); 530 mutex_destroy(&wilc->hif_cs);
541 mutex_destroy(&wilc->rxq_cs); 531 mutex_destroy(&wilc->rxq_cs);
542 mutex_destroy(&wilc->txq_add_to_head_cs); 532 mutex_destroy(&wilc->txq_add_to_head_cs);
543
544 return 0;
545} 533}
546 534
547static void wlan_deinitialize_threads(struct net_device *dev) 535static void wlan_deinitialize_threads(struct net_device *dev)
@@ -595,7 +583,7 @@ static void wilc_wlan_deinitialize(struct net_device *dev)
595 } 583 }
596} 584}
597 585
598static int wlan_init_locks(struct net_device *dev) 586static void wlan_init_locks(struct net_device *dev)
599{ 587{
600 struct wilc_vif *vif = netdev_priv(dev); 588 struct wilc_vif *vif = netdev_priv(dev);
601 struct wilc *wl = vif->wilc; 589 struct wilc *wl = vif->wilc;
@@ -611,8 +599,6 @@ static int wlan_init_locks(struct net_device *dev)
611 init_completion(&wl->cfg_event); 599 init_completion(&wl->cfg_event);
612 init_completion(&wl->sync_event); 600 init_completion(&wl->sync_event);
613 init_completion(&wl->txq_thread_started); 601 init_completion(&wl->txq_thread_started);
614
615 return 0;
616} 602}
617 603
618static int wlan_initialize_threads(struct net_device *dev) 604static int wlan_initialize_threads(struct net_device *dev)
@@ -688,7 +674,7 @@ static int wilc_wlan_initialize(struct net_device *dev, struct wilc_vif *vif)
688 int size; 674 int size;
689 char firmware_ver[20]; 675 char firmware_ver[20];
690 676
691 size = wilc_wlan_cfg_get_val(WID_FIRMWARE_VERSION, 677 size = wilc_wlan_cfg_get_val(wl, WID_FIRMWARE_VERSION,
692 firmware_ver, 678 firmware_ver,
693 sizeof(firmware_ver)); 679 sizeof(firmware_ver));
694 firmware_ver[size] = '\0'; 680 firmware_ver[size] = '\0';
@@ -740,6 +726,7 @@ static int wilc_mac_open(struct net_device *ndev)
740{ 726{
741 struct wilc_vif *vif = netdev_priv(ndev); 727 struct wilc_vif *vif = netdev_priv(ndev);
742 struct wilc *wl = vif->wilc; 728 struct wilc *wl = vif->wilc;
729 struct wilc_priv *priv = wdev_priv(vif->ndev->ieee80211_ptr);
743 unsigned char mac_add[ETH_ALEN] = {0}; 730 unsigned char mac_add[ETH_ALEN] = {0};
744 int ret = 0; 731 int ret = 0;
745 int i = 0; 732 int i = 0;
@@ -764,7 +751,8 @@ static int wilc_mac_open(struct net_device *ndev)
764 for (i = 0; i < wl->vif_num; i++) { 751 for (i = 0; i < wl->vif_num; i++) {
765 if (ndev == wl->vif[i]->ndev) { 752 if (ndev == wl->vif[i]->ndev) {
766 wilc_set_wfi_drv_handler(vif, wilc_get_vif_idx(vif), 753 wilc_set_wfi_drv_handler(vif, wilc_get_vif_idx(vif),
767 vif->iftype, vif->ifc_id); 754 vif->iftype, vif->ifc_id,
755 false);
768 wilc_set_operation_mode(vif, vif->iftype); 756 wilc_set_operation_mode(vif, vif->iftype);
769 break; 757 break;
770 } 758 }
@@ -792,6 +780,7 @@ static int wilc_mac_open(struct net_device *ndev)
792 vif->frame_reg[1].reg); 780 vif->frame_reg[1].reg);
793 netif_wake_queue(ndev); 781 netif_wake_queue(ndev);
794 wl->open_ifcs++; 782 wl->open_ifcs++;
783 priv->p2p.local_random = 0x01;
795 vif->mac_opened = 1; 784 vif->mac_opened = 1;
796 return 0; 785 return 0;
797} 786}
@@ -807,35 +796,39 @@ static void wilc_set_multicast_list(struct net_device *dev)
807{ 796{
808 struct netdev_hw_addr *ha; 797 struct netdev_hw_addr *ha;
809 struct wilc_vif *vif = netdev_priv(dev); 798 struct wilc_vif *vif = netdev_priv(dev);
810 int i = 0; 799 int i;
800 u8 *mc_list;
801 u8 *cur_mc;
811 802
812 if (dev->flags & IFF_PROMISC) 803 if (dev->flags & IFF_PROMISC)
813 return; 804 return;
814 805
815 if (dev->flags & IFF_ALLMULTI || 806 if (dev->flags & IFF_ALLMULTI ||
816 dev->mc.count > WILC_MULTICAST_TABLE_SIZE) { 807 dev->mc.count > WILC_MULTICAST_TABLE_SIZE) {
817 wilc_setup_multicast_filter(vif, false, 0); 808 wilc_setup_multicast_filter(vif, false, 0, NULL);
818 return; 809 return;
819 } 810 }
820 811
821 if (dev->mc.count == 0) { 812 if (dev->mc.count == 0) {
822 wilc_setup_multicast_filter(vif, true, 0); 813 wilc_setup_multicast_filter(vif, true, 0, NULL);
823 return; 814 return;
824 } 815 }
825 816
817 mc_list = kmalloc_array(dev->mc.count, ETH_ALEN, GFP_KERNEL);
818 if (!mc_list)
819 return;
820
821 cur_mc = mc_list;
822 i = 0;
826 netdev_for_each_mc_addr(ha, dev) { 823 netdev_for_each_mc_addr(ha, dev) {
827 memcpy(wilc_multicast_mac_addr_list[i], ha->addr, ETH_ALEN); 824 memcpy(cur_mc, ha->addr, ETH_ALEN);
828 netdev_dbg(dev, "Entry[%d]: %x:%x:%x:%x:%x:%x\n", i, 825 netdev_dbg(dev, "Entry[%d]: %pM\n", i, cur_mc);
829 wilc_multicast_mac_addr_list[i][0],
830 wilc_multicast_mac_addr_list[i][1],
831 wilc_multicast_mac_addr_list[i][2],
832 wilc_multicast_mac_addr_list[i][3],
833 wilc_multicast_mac_addr_list[i][4],
834 wilc_multicast_mac_addr_list[i][5]);
835 i++; 826 i++;
827 cur_mc += ETH_ALEN;
836 } 828 }
837 829
838 wilc_setup_multicast_filter(vif, true, (dev->mc.count)); 830 if (wilc_setup_multicast_filter(vif, true, dev->mc.count, mc_list))
831 kfree(mc_list);
839} 832}
840 833
841static void linux_wlan_tx_complete(void *priv, int status) 834static void linux_wlan_tx_complete(void *priv, int status)
@@ -1016,15 +1009,18 @@ void wilc_netdev_cleanup(struct wilc *wilc)
1016{ 1009{
1017 int i; 1010 int i;
1018 1011
1019 if (wilc && (wilc->vif[0]->ndev || wilc->vif[1]->ndev)) 1012 if (!wilc)
1013 return;
1014
1015 if (wilc->vif[0]->ndev || wilc->vif[1]->ndev)
1020 unregister_inetaddr_notifier(&g_dev_notifier); 1016 unregister_inetaddr_notifier(&g_dev_notifier);
1021 1017
1022 if (wilc && wilc->firmware) { 1018 if (wilc->firmware) {
1023 release_firmware(wilc->firmware); 1019 release_firmware(wilc->firmware);
1024 wilc->firmware = NULL; 1020 wilc->firmware = NULL;
1025 } 1021 }
1026 1022
1027 if (wilc && (wilc->vif[0]->ndev || wilc->vif[1]->ndev)) { 1023 if (wilc->vif[0]->ndev || wilc->vif[1]->ndev) {
1028 for (i = 0; i < NUM_CONCURRENT_IFC; i++) 1024 for (i = 0; i < NUM_CONCURRENT_IFC; i++)
1029 if (wilc->vif[i]->ndev) 1025 if (wilc->vif[i]->ndev)
1030 if (wilc->vif[i]->mac_opened) 1026 if (wilc->vif[i]->mac_opened)
@@ -1037,6 +1033,10 @@ void wilc_netdev_cleanup(struct wilc *wilc)
1037 } 1033 }
1038 } 1034 }
1039 1035
1036 flush_workqueue(wilc->hif_workqueue);
1037 destroy_workqueue(wilc->hif_workqueue);
1038 wilc_wlan_cfg_deinit(wilc);
1039 kfree(wilc->bus_data);
1040 kfree(wilc); 1040 kfree(wilc);
1041} 1041}
1042EXPORT_SYMBOL_GPL(wilc_netdev_cleanup); 1042EXPORT_SYMBOL_GPL(wilc_netdev_cleanup);
@@ -1062,20 +1062,34 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
1062 if (!wl) 1062 if (!wl)
1063 return -ENOMEM; 1063 return -ENOMEM;
1064 1064
1065 ret = wilc_wlan_cfg_init(wl);
1066 if (ret)
1067 goto free_wl;
1068
1065 *wilc = wl; 1069 *wilc = wl;
1066 wl->io_type = io_type; 1070 wl->io_type = io_type;
1067 wl->hif_func = ops; 1071 wl->hif_func = ops;
1072 wl->enable_ps = true;
1073 wl->chip_ps_state = CHIP_WAKEDUP;
1068 INIT_LIST_HEAD(&wl->txq_head.list); 1074 INIT_LIST_HEAD(&wl->txq_head.list);
1069 INIT_LIST_HEAD(&wl->rxq_head.list); 1075 INIT_LIST_HEAD(&wl->rxq_head.list);
1070 1076
1077 wl->hif_workqueue = create_singlethread_workqueue("WILC_wq");
1078 if (!wl->hif_workqueue) {
1079 ret = -ENOMEM;
1080 goto free_cfg;
1081 }
1082
1071 register_inetaddr_notifier(&g_dev_notifier); 1083 register_inetaddr_notifier(&g_dev_notifier);
1072 1084
1073 for (i = 0; i < NUM_CONCURRENT_IFC; i++) { 1085 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
1074 struct wireless_dev *wdev; 1086 struct wireless_dev *wdev;
1075 1087
1076 ndev = alloc_etherdev(sizeof(struct wilc_vif)); 1088 ndev = alloc_etherdev(sizeof(struct wilc_vif));
1077 if (!ndev) 1089 if (!ndev) {
1078 return -ENOMEM; 1090 ret = -ENOMEM;
1091 goto free_ndev;
1092 }
1079 1093
1080 vif = netdev_priv(ndev); 1094 vif = netdev_priv(ndev);
1081 memset(vif, 0, sizeof(struct wilc_vif)); 1095 memset(vif, 0, sizeof(struct wilc_vif));
@@ -1096,15 +1110,14 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
1096 ndev->netdev_ops = &wilc_netdev_ops; 1110 ndev->netdev_ops = &wilc_netdev_ops;
1097 1111
1098 wdev = wilc_create_wiphy(ndev, dev); 1112 wdev = wilc_create_wiphy(ndev, dev);
1099
1100 if (dev)
1101 SET_NETDEV_DEV(ndev, dev);
1102
1103 if (!wdev) { 1113 if (!wdev) {
1104 netdev_err(ndev, "Can't register WILC Wiphy\n"); 1114 netdev_err(ndev, "Can't register WILC Wiphy\n");
1105 return -1; 1115 ret = -ENOMEM;
1116 goto free_ndev;
1106 } 1117 }
1107 1118
1119 SET_NETDEV_DEV(ndev, dev);
1120
1108 vif->ndev->ieee80211_ptr = wdev; 1121 vif->ndev->ieee80211_ptr = wdev;
1109 vif->ndev->ml_priv = vif; 1122 vif->ndev->ml_priv = vif;
1110 wdev->netdev = vif->ndev; 1123 wdev->netdev = vif->ndev;
@@ -1115,13 +1128,33 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
1115 1128
1116 ret = register_netdev(ndev); 1129 ret = register_netdev(ndev);
1117 if (ret) 1130 if (ret)
1118 return ret; 1131 goto free_ndev;
1119 1132
1120 vif->iftype = STATION_MODE; 1133 vif->iftype = STATION_MODE;
1121 vif->mac_opened = 0; 1134 vif->mac_opened = 0;
1122 } 1135 }
1123 1136
1124 return 0; 1137 return 0;
1138
1139free_ndev:
1140 for (; i >= 0; i--) {
1141 if (wl->vif[i]) {
1142 if (wl->vif[i]->iftype == STATION_MODE)
1143 unregister_netdev(wl->vif[i]->ndev);
1144
1145 if (wl->vif[i]->ndev) {
1146 wilc_free_wiphy(wl->vif[i]->ndev);
1147 free_netdev(wl->vif[i]->ndev);
1148 }
1149 }
1150 }
1151 unregister_inetaddr_notifier(&g_dev_notifier);
1152 destroy_workqueue(wl->hif_workqueue);
1153free_cfg:
1154 wilc_wlan_cfg_deinit(wl);
1155free_wl:
1156 kfree(wl);
1157 return ret;
1125} 1158}
1126EXPORT_SYMBOL_GPL(wilc_netdev_init); 1159EXPORT_SYMBOL_GPL(wilc_netdev_init);
1127 1160
diff --git a/drivers/staging/wilc1000/wilc_debugfs.c b/drivers/staging/wilc1000/wilc_debugfs.c
deleted file mode 100644
index 8001df66b8c2..000000000000
--- a/drivers/staging/wilc1000/wilc_debugfs.c
+++ /dev/null
@@ -1,115 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
4 * All rights reserved.
5 */
6
7#if defined(WILC_DEBUGFS)
8#include <linux/module.h>
9#include <linux/debugfs.h>
10
11#include "wilc_wlan_if.h"
12
13static struct dentry *wilc_dir;
14
15#define DEBUG BIT(0)
16#define INFO BIT(1)
17#define WRN BIT(2)
18#define ERR BIT(3)
19
20#define DBG_LEVEL_ALL (DEBUG | INFO | WRN | ERR)
21static atomic_t WILC_DEBUG_LEVEL = ATOMIC_INIT(ERR);
22EXPORT_SYMBOL_GPL(WILC_DEBUG_LEVEL);
23
24static ssize_t wilc_debug_level_read(struct file *file, char __user *userbuf,
25 size_t count, loff_t *ppos)
26{
27 char buf[128];
28 int res = 0;
29
30 /* only allow read from start */
31 if (*ppos > 0)
32 return 0;
33
34 res = scnprintf(buf, sizeof(buf), "Debug Level: %x\n",
35 atomic_read(&WILC_DEBUG_LEVEL));
36
37 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
38}
39
40static ssize_t wilc_debug_level_write(struct file *filp,
41 const char __user *buf, size_t count,
42 loff_t *ppos)
43{
44 int flag = 0;
45 int ret;
46
47 ret = kstrtouint_from_user(buf, count, 16, &flag);
48 if (ret)
49 return ret;
50
51 if (flag > DBG_LEVEL_ALL) {
52 pr_info("%s, value (0x%08x) is out of range, stay previous flag (0x%08x)\n",
53 __func__, flag, atomic_read(&WILC_DEBUG_LEVEL));
54 return -EINVAL;
55 }
56
57 atomic_set(&WILC_DEBUG_LEVEL, (int)flag);
58
59 if (flag == 0)
60 pr_info("Debug-level disabled\n");
61 else
62 pr_info("Debug-level enabled\n");
63
64 return count;
65}
66
67#define FOPS(_open, _read, _write, _poll) { \
68 .owner = THIS_MODULE, \
69 .open = (_open), \
70 .read = (_read), \
71 .write = (_write), \
72 .poll = (_poll), \
73}
74
75struct wilc_debugfs_info_t {
76 const char *name;
77 int perm;
78 unsigned int data;
79 const struct file_operations fops;
80};
81
82static struct wilc_debugfs_info_t debugfs_info[] = {
83 {
84 "wilc_debug_level",
85 0666,
86 (DEBUG | ERR),
87 FOPS(NULL, wilc_debug_level_read, wilc_debug_level_write, NULL),
88 },
89};
90
91static int __init wilc_debugfs_init(void)
92{
93 int i;
94 struct wilc_debugfs_info_t *info;
95
96 wilc_dir = debugfs_create_dir("wilc_wifi", NULL);
97 for (i = 0; i < ARRAY_SIZE(debugfs_info); i++) {
98 info = &debugfs_info[i];
99 debugfs_create_file(info->name,
100 info->perm,
101 wilc_dir,
102 &info->data,
103 &info->fops);
104 }
105 return 0;
106}
107module_init(wilc_debugfs_init);
108
109static void __exit wilc_debugfs_remove(void)
110{
111 debugfs_remove_recursive(wilc_dir);
112}
113module_exit(wilc_debugfs_remove);
114
115#endif
diff --git a/drivers/staging/wilc1000/wilc_sdio.c b/drivers/staging/wilc1000/wilc_sdio.c
index b2080d8b801f..ca351c950344 100644
--- a/drivers/staging/wilc1000/wilc_sdio.c
+++ b/drivers/staging/wilc1000/wilc_sdio.c
@@ -30,7 +30,6 @@ struct wilc_sdio {
30 int has_thrpt_enh3; 30 int has_thrpt_enh3;
31}; 31};
32 32
33static struct wilc_sdio g_sdio;
34static const struct wilc_hif_func wilc_hif_sdio; 33static const struct wilc_hif_func wilc_hif_sdio;
35 34
36static int sdio_write_reg(struct wilc *wilc, u32 addr, u32 data); 35static int sdio_write_reg(struct wilc *wilc, u32 addr, u32 data);
@@ -109,6 +108,11 @@ static int linux_sdio_probe(struct sdio_func *func,
109 struct wilc *wilc; 108 struct wilc *wilc;
110 int ret; 109 int ret;
111 struct gpio_desc *gpio = NULL; 110 struct gpio_desc *gpio = NULL;
111 struct wilc_sdio *sdio_priv;
112
113 sdio_priv = kzalloc(sizeof(*sdio_priv), GFP_KERNEL);
114 if (!sdio_priv)
115 return -ENOMEM;
112 116
113 if (IS_ENABLED(CONFIG_WILC1000_HW_OOB_INTR)) { 117 if (IS_ENABLED(CONFIG_WILC1000_HW_OOB_INTR)) {
114 gpio = gpiod_get(&func->dev, "irq", GPIOD_IN); 118 gpio = gpiod_get(&func->dev, "irq", GPIOD_IN);
@@ -124,9 +128,11 @@ static int linux_sdio_probe(struct sdio_func *func,
124 ret = wilc_netdev_init(&wilc, &func->dev, HIF_SDIO, &wilc_hif_sdio); 128 ret = wilc_netdev_init(&wilc, &func->dev, HIF_SDIO, &wilc_hif_sdio);
125 if (ret) { 129 if (ret) {
126 dev_err(&func->dev, "Couldn't initialize netdev\n"); 130 dev_err(&func->dev, "Couldn't initialize netdev\n");
131 kfree(sdio_priv);
127 return ret; 132 return ret;
128 } 133 }
129 sdio_set_drvdata(func, wilc); 134 sdio_set_drvdata(func, wilc);
135 wilc->bus_data = sdio_priv;
130 wilc->dev = &func->dev; 136 wilc->dev = &func->dev;
131 wilc->gpio_irq = gpio; 137 wilc->gpio_irq = gpio;
132 138
@@ -381,6 +387,7 @@ fail:
381static int sdio_write_reg(struct wilc *wilc, u32 addr, u32 data) 387static int sdio_write_reg(struct wilc *wilc, u32 addr, u32 data)
382{ 388{
383 struct sdio_func *func = dev_to_sdio_func(wilc->dev); 389 struct sdio_func *func = dev_to_sdio_func(wilc->dev);
390 struct wilc_sdio *sdio_priv = wilc->bus_data;
384 int ret; 391 int ret;
385 392
386 cpu_to_le32s(&data); 393 cpu_to_le32s(&data);
@@ -415,7 +422,7 @@ static int sdio_write_reg(struct wilc *wilc, u32 addr, u32 data)
415 cmd.increment = 1; 422 cmd.increment = 1;
416 cmd.count = 4; 423 cmd.count = 4;
417 cmd.buffer = (u8 *)&data; 424 cmd.buffer = (u8 *)&data;
418 cmd.block_size = g_sdio.block_size; 425 cmd.block_size = sdio_priv->block_size;
419 ret = wilc_sdio_cmd53(wilc, &cmd); 426 ret = wilc_sdio_cmd53(wilc, &cmd);
420 if (ret) { 427 if (ret) {
421 dev_err(&func->dev, 428 dev_err(&func->dev,
@@ -434,7 +441,8 @@ fail:
434static int sdio_write(struct wilc *wilc, u32 addr, u8 *buf, u32 size) 441static int sdio_write(struct wilc *wilc, u32 addr, u8 *buf, u32 size)
435{ 442{
436 struct sdio_func *func = dev_to_sdio_func(wilc->dev); 443 struct sdio_func *func = dev_to_sdio_func(wilc->dev);
437 u32 block_size = g_sdio.block_size; 444 struct wilc_sdio *sdio_priv = wilc->bus_data;
445 u32 block_size = sdio_priv->block_size;
438 struct sdio_cmd53 cmd; 446 struct sdio_cmd53 cmd;
439 int nblk, nleft, ret; 447 int nblk, nleft, ret;
440 448
@@ -523,6 +531,7 @@ fail:
523static int sdio_read_reg(struct wilc *wilc, u32 addr, u32 *data) 531static int sdio_read_reg(struct wilc *wilc, u32 addr, u32 *data)
524{ 532{
525 struct sdio_func *func = dev_to_sdio_func(wilc->dev); 533 struct sdio_func *func = dev_to_sdio_func(wilc->dev);
534 struct wilc_sdio *sdio_priv = wilc->bus_data;
526 int ret; 535 int ret;
527 536
528 if (addr >= 0xf0 && addr <= 0xff) { 537 if (addr >= 0xf0 && addr <= 0xff) {
@@ -553,7 +562,7 @@ static int sdio_read_reg(struct wilc *wilc, u32 addr, u32 *data)
553 cmd.count = 4; 562 cmd.count = 4;
554 cmd.buffer = (u8 *)data; 563 cmd.buffer = (u8 *)data;
555 564
556 cmd.block_size = g_sdio.block_size; 565 cmd.block_size = sdio_priv->block_size;
557 ret = wilc_sdio_cmd53(wilc, &cmd); 566 ret = wilc_sdio_cmd53(wilc, &cmd);
558 if (ret) { 567 if (ret) {
559 dev_err(&func->dev, 568 dev_err(&func->dev,
@@ -574,7 +583,8 @@ fail:
574static int sdio_read(struct wilc *wilc, u32 addr, u8 *buf, u32 size) 583static int sdio_read(struct wilc *wilc, u32 addr, u8 *buf, u32 size)
575{ 584{
576 struct sdio_func *func = dev_to_sdio_func(wilc->dev); 585 struct sdio_func *func = dev_to_sdio_func(wilc->dev);
577 u32 block_size = g_sdio.block_size; 586 struct wilc_sdio *sdio_priv = wilc->bus_data;
587 u32 block_size = sdio_priv->block_size;
578 struct sdio_cmd53 cmd; 588 struct sdio_cmd53 cmd;
579 int nblk, nleft, ret; 589 int nblk, nleft, ret;
580 590
@@ -674,14 +684,13 @@ static int sdio_deinit(struct wilc *wilc)
674static int sdio_init(struct wilc *wilc, bool resume) 684static int sdio_init(struct wilc *wilc, bool resume)
675{ 685{
676 struct sdio_func *func = dev_to_sdio_func(wilc->dev); 686 struct sdio_func *func = dev_to_sdio_func(wilc->dev);
687 struct wilc_sdio *sdio_priv = wilc->bus_data;
677 struct sdio_cmd52 cmd; 688 struct sdio_cmd52 cmd;
678 int loop, ret; 689 int loop, ret;
679 u32 chipid; 690 u32 chipid;
680 691
681 if (!resume) { 692 if (!resume)
682 memset(&g_sdio, 0, sizeof(struct wilc_sdio)); 693 sdio_priv->irq_gpio = wilc->dev_irq_num;
683 g_sdio.irq_gpio = wilc->dev_irq_num;
684 }
685 694
686 /** 695 /**
687 * function 0 csa enable 696 * function 0 csa enable
@@ -704,7 +713,7 @@ static int sdio_init(struct wilc *wilc, bool resume)
704 dev_err(&func->dev, "Fail cmd 52, set func 0 block size...\n"); 713 dev_err(&func->dev, "Fail cmd 52, set func 0 block size...\n");
705 goto fail; 714 goto fail;
706 } 715 }
707 g_sdio.block_size = WILC_SDIO_BLOCK_SIZE; 716 sdio_priv->block_size = WILC_SDIO_BLOCK_SIZE;
708 717
709 /** 718 /**
710 * enable func1 IO 719 * enable func1 IO
@@ -778,11 +787,11 @@ static int sdio_init(struct wilc *wilc, bool resume)
778 } 787 }
779 dev_err(&func->dev, "chipid (%08x)\n", chipid); 788 dev_err(&func->dev, "chipid (%08x)\n", chipid);
780 if ((chipid & 0xfff) > 0x2a0) 789 if ((chipid & 0xfff) > 0x2a0)
781 g_sdio.has_thrpt_enh3 = 1; 790 sdio_priv->has_thrpt_enh3 = 1;
782 else 791 else
783 g_sdio.has_thrpt_enh3 = 0; 792 sdio_priv->has_thrpt_enh3 = 0;
784 dev_info(&func->dev, "has_thrpt_enh3 = %d...\n", 793 dev_info(&func->dev, "has_thrpt_enh3 = %d...\n",
785 g_sdio.has_thrpt_enh3); 794 sdio_priv->has_thrpt_enh3);
786 } 795 }
787 796
788 return 1; 797 return 1;
@@ -820,6 +829,7 @@ static int sdio_read_size(struct wilc *wilc, u32 *size)
820static int sdio_read_int(struct wilc *wilc, u32 *int_status) 829static int sdio_read_int(struct wilc *wilc, u32 *int_status)
821{ 830{
822 struct sdio_func *func = dev_to_sdio_func(wilc->dev); 831 struct sdio_func *func = dev_to_sdio_func(wilc->dev);
832 struct wilc_sdio *sdio_priv = wilc->bus_data;
823 u32 tmp; 833 u32 tmp;
824 struct sdio_cmd52 cmd; 834 struct sdio_cmd52 cmd;
825 835
@@ -828,7 +838,7 @@ static int sdio_read_int(struct wilc *wilc, u32 *int_status)
828 /** 838 /**
829 * Read IRQ flags 839 * Read IRQ flags
830 **/ 840 **/
831 if (!g_sdio.irq_gpio) { 841 if (!sdio_priv->irq_gpio) {
832 int i; 842 int i;
833 843
834 cmd.function = 1; 844 cmd.function = 1;
@@ -848,7 +858,7 @@ static int sdio_read_int(struct wilc *wilc, u32 *int_status)
848 tmp |= INT_4; 858 tmp |= INT_4;
849 if (cmd.data & BIT(6)) 859 if (cmd.data & BIT(6))
850 tmp |= INT_5; 860 tmp |= INT_5;
851 for (i = g_sdio.nint; i < MAX_NUM_INT; i++) { 861 for (i = sdio_priv->nint; i < MAX_NUM_INT; i++) {
852 if ((tmp >> (IRG_FLAGS_OFFSET + i)) & 0x1) { 862 if ((tmp >> (IRG_FLAGS_OFFSET + i)) & 0x1) {
853 dev_err(&func->dev, 863 dev_err(&func->dev,
854 "Unexpected interrupt (1) : tmp=%x, data=%x\n", 864 "Unexpected interrupt (1) : tmp=%x, data=%x\n",
@@ -877,13 +887,14 @@ static int sdio_read_int(struct wilc *wilc, u32 *int_status)
877static int sdio_clear_int_ext(struct wilc *wilc, u32 val) 887static int sdio_clear_int_ext(struct wilc *wilc, u32 val)
878{ 888{
879 struct sdio_func *func = dev_to_sdio_func(wilc->dev); 889 struct sdio_func *func = dev_to_sdio_func(wilc->dev);
890 struct wilc_sdio *sdio_priv = wilc->bus_data;
880 int ret; 891 int ret;
881 int vmm_ctl; 892 int vmm_ctl;
882 893
883 if (g_sdio.has_thrpt_enh3) { 894 if (sdio_priv->has_thrpt_enh3) {
884 u32 reg; 895 u32 reg;
885 896
886 if (g_sdio.irq_gpio) { 897 if (sdio_priv->irq_gpio) {
887 u32 flags; 898 u32 flags;
888 899
889 flags = val & (BIT(MAX_NUN_INT_THRPT_ENH2) - 1); 900 flags = val & (BIT(MAX_NUN_INT_THRPT_ENH2) - 1);
@@ -919,7 +930,7 @@ static int sdio_clear_int_ext(struct wilc *wilc, u32 val)
919 } 930 }
920 return 1; 931 return 1;
921 } 932 }
922 if (g_sdio.irq_gpio) { 933 if (sdio_priv->irq_gpio) {
923 /* has_thrpt_enh2 uses register 0xf8 to clear interrupts. */ 934 /* has_thrpt_enh2 uses register 0xf8 to clear interrupts. */
924 /* 935 /*
925 * Cannot clear multiple interrupts. 936 * Cannot clear multiple interrupts.
@@ -932,7 +943,7 @@ static int sdio_clear_int_ext(struct wilc *wilc, u32 val)
932 int i; 943 int i;
933 944
934 ret = 1; 945 ret = 1;
935 for (i = 0; i < g_sdio.nint; i++) { 946 for (i = 0; i < sdio_priv->nint; i++) {
936 if (flags & 1) { 947 if (flags & 1) {
937 struct sdio_cmd52 cmd; 948 struct sdio_cmd52 cmd;
938 949
@@ -956,7 +967,7 @@ static int sdio_clear_int_ext(struct wilc *wilc, u32 val)
956 } 967 }
957 if (!ret) 968 if (!ret)
958 goto fail; 969 goto fail;
959 for (i = g_sdio.nint; i < MAX_NUM_INT; i++) { 970 for (i = sdio_priv->nint; i < MAX_NUM_INT; i++) {
960 if (flags & 1) 971 if (flags & 1)
961 dev_err(&func->dev, 972 dev_err(&func->dev,
962 "Unexpected interrupt cleared %d...\n", 973 "Unexpected interrupt cleared %d...\n",
@@ -1001,6 +1012,7 @@ fail:
1001static int sdio_sync_ext(struct wilc *wilc, int nint) 1012static int sdio_sync_ext(struct wilc *wilc, int nint)
1002{ 1013{
1003 struct sdio_func *func = dev_to_sdio_func(wilc->dev); 1014 struct sdio_func *func = dev_to_sdio_func(wilc->dev);
1015 struct wilc_sdio *sdio_priv = wilc->bus_data;
1004 u32 reg; 1016 u32 reg;
1005 1017
1006 if (nint > MAX_NUM_INT) { 1018 if (nint > MAX_NUM_INT) {
@@ -1013,7 +1025,7 @@ static int sdio_sync_ext(struct wilc *wilc, int nint)
1013 return 0; 1025 return 0;
1014 } 1026 }
1015 1027
1016 g_sdio.nint = nint; 1028 sdio_priv->nint = nint;
1017 1029
1018 /** 1030 /**
1019 * Disable power sequencer 1031 * Disable power sequencer
@@ -1029,7 +1041,7 @@ static int sdio_sync_ext(struct wilc *wilc, int nint)
1029 return 0; 1041 return 0;
1030 } 1042 }
1031 1043
1032 if (g_sdio.irq_gpio) { 1044 if (sdio_priv->irq_gpio) {
1033 u32 reg; 1045 u32 reg;
1034 int ret, i; 1046 int ret, i;
1035 1047
diff --git a/drivers/staging/wilc1000/wilc_spi.c b/drivers/staging/wilc1000/wilc_spi.c
index 5517477d875a..cef127b249fb 100644
--- a/drivers/staging/wilc1000/wilc_spi.c
+++ b/drivers/staging/wilc1000/wilc_spi.c
@@ -14,7 +14,6 @@ struct wilc_spi {
14 int has_thrpt_enh; 14 int has_thrpt_enh;
15}; 15};
16 16
17static struct wilc_spi g_spi;
18static const struct wilc_hif_func wilc_hif_spi; 17static const struct wilc_hif_func wilc_hif_spi;
19 18
20/******************************************** 19/********************************************
@@ -107,6 +106,11 @@ static int wilc_bus_probe(struct spi_device *spi)
107 int ret; 106 int ret;
108 struct wilc *wilc; 107 struct wilc *wilc;
109 struct gpio_desc *gpio; 108 struct gpio_desc *gpio;
109 struct wilc_spi *spi_priv;
110
111 spi_priv = kzalloc(sizeof(*spi_priv), GFP_KERNEL);
112 if (!spi_priv)
113 return -ENOMEM;
110 114
111 gpio = gpiod_get(&spi->dev, "irq", GPIOD_IN); 115 gpio = gpiod_get(&spi->dev, "irq", GPIOD_IN);
112 if (IS_ERR(gpio)) { 116 if (IS_ERR(gpio)) {
@@ -117,11 +121,14 @@ static int wilc_bus_probe(struct spi_device *spi)
117 } 121 }
118 122
119 ret = wilc_netdev_init(&wilc, NULL, HIF_SPI, &wilc_hif_spi); 123 ret = wilc_netdev_init(&wilc, NULL, HIF_SPI, &wilc_hif_spi);
120 if (ret) 124 if (ret) {
125 kfree(spi_priv);
121 return ret; 126 return ret;
127 }
122 128
123 spi_set_drvdata(spi, wilc); 129 spi_set_drvdata(spi, wilc);
124 wilc->dev = &spi->dev; 130 wilc->dev = &spi->dev;
131 wilc->bus_data = spi_priv;
125 wilc->gpio_irq = gpio; 132 wilc->gpio_irq = gpio;
126 133
127 return 0; 134 return 0;
@@ -275,6 +282,7 @@ static int spi_cmd_complete(struct wilc *wilc, u8 cmd, u32 adr, u8 *b, u32 sz,
275 u8 clockless) 282 u8 clockless)
276{ 283{
277 struct spi_device *spi = to_spi_device(wilc->dev); 284 struct spi_device *spi = to_spi_device(wilc->dev);
285 struct wilc_spi *spi_priv = wilc->bus_data;
278 u8 wb[32], rb[32]; 286 u8 wb[32], rb[32];
279 u8 wix, rix; 287 u8 wix, rix;
280 u32 len2; 288 u32 len2;
@@ -375,7 +383,7 @@ static int spi_cmd_complete(struct wilc *wilc, u8 cmd, u32 adr, u8 *b, u32 sz,
375 if (result != N_OK) 383 if (result != N_OK)
376 return result; 384 return result;
377 385
378 if (!g_spi.crc_off) 386 if (!spi_priv->crc_off)
379 wb[len - 1] = (crc7(0x7f, (const u8 *)&wb[0], len - 1)) << 1; 387 wb[len - 1] = (crc7(0x7f, (const u8 *)&wb[0], len - 1)) << 1;
380 else 388 else
381 len -= 1; 389 len -= 1;
@@ -393,7 +401,7 @@ static int spi_cmd_complete(struct wilc *wilc, u8 cmd, u32 adr, u8 *b, u32 sz,
393 } else if (cmd == CMD_INTERNAL_READ || cmd == CMD_SINGLE_READ) { 401 } else if (cmd == CMD_INTERNAL_READ || cmd == CMD_SINGLE_READ) {
394 int tmp = NUM_RSP_BYTES + NUM_DATA_HDR_BYTES + NUM_DATA_BYTES 402 int tmp = NUM_RSP_BYTES + NUM_DATA_HDR_BYTES + NUM_DATA_BYTES
395 + NUM_DUMMY_BYTES; 403 + NUM_DUMMY_BYTES;
396 if (!g_spi.crc_off) 404 if (!spi_priv->crc_off)
397 len2 = len + tmp + NUM_CRC_BYTES; 405 len2 = len + tmp + NUM_CRC_BYTES;
398 else 406 else
399 len2 = len + tmp; 407 len2 = len + tmp;
@@ -485,7 +493,7 @@ static int spi_cmd_complete(struct wilc *wilc, u8 cmd, u32 adr, u8 *b, u32 sz,
485 return N_FAIL; 493 return N_FAIL;
486 } 494 }
487 495
488 if (!g_spi.crc_off) { 496 if (!spi_priv->crc_off) {
489 /* 497 /*
490 * Read Crc 498 * Read Crc
491 */ 499 */
@@ -527,7 +535,7 @@ static int spi_cmd_complete(struct wilc *wilc, u8 cmd, u32 adr, u8 *b, u32 sz,
527 /* 535 /*
528 * Read Crc 536 * Read Crc
529 */ 537 */
530 if (!g_spi.crc_off && wilc_spi_rx(wilc, crc, 2)) { 538 if (!spi_priv->crc_off && wilc_spi_rx(wilc, crc, 2)) {
531 dev_err(&spi->dev, 539 dev_err(&spi->dev,
532 "Failed block crc read, bus err\n"); 540 "Failed block crc read, bus err\n");
533 return N_FAIL; 541 return N_FAIL;
@@ -585,7 +593,7 @@ static int spi_cmd_complete(struct wilc *wilc, u8 cmd, u32 adr, u8 *b, u32 sz,
585 /* 593 /*
586 * Read Crc 594 * Read Crc
587 */ 595 */
588 if (!g_spi.crc_off && wilc_spi_rx(wilc, crc, 2)) { 596 if (!spi_priv->crc_off && wilc_spi_rx(wilc, crc, 2)) {
589 dev_err(&spi->dev, 597 dev_err(&spi->dev,
590 "Failed block crc read, bus err\n"); 598 "Failed block crc read, bus err\n");
591 result = N_FAIL; 599 result = N_FAIL;
@@ -602,6 +610,7 @@ static int spi_cmd_complete(struct wilc *wilc, u8 cmd, u32 adr, u8 *b, u32 sz,
602static int spi_data_write(struct wilc *wilc, u8 *b, u32 sz) 610static int spi_data_write(struct wilc *wilc, u8 *b, u32 sz)
603{ 611{
604 struct spi_device *spi = to_spi_device(wilc->dev); 612 struct spi_device *spi = to_spi_device(wilc->dev);
613 struct wilc_spi *spi_priv = wilc->bus_data;
605 int ix, nbytes; 614 int ix, nbytes;
606 int result = 1; 615 int result = 1;
607 u8 cmd, order, crc[2] = {0}; 616 u8 cmd, order, crc[2] = {0};
@@ -648,7 +657,7 @@ static int spi_data_write(struct wilc *wilc, u8 *b, u32 sz)
648 /* 657 /*
649 * Write Crc 658 * Write Crc
650 */ 659 */
651 if (!g_spi.crc_off) { 660 if (!spi_priv->crc_off) {
652 if (wilc_spi_tx(wilc, crc, 2)) { 661 if (wilc_spi_tx(wilc, crc, 2)) {
653 dev_err(&spi->dev, "Failed data block crc write, bus error...\n"); 662 dev_err(&spi->dev, "Failed data block crc write, bus error...\n");
654 result = N_FAIL; 663 result = N_FAIL;
@@ -816,6 +825,7 @@ static int _wilc_spi_deinit(struct wilc *wilc)
816static int wilc_spi_init(struct wilc *wilc, bool resume) 825static int wilc_spi_init(struct wilc *wilc, bool resume)
817{ 826{
818 struct spi_device *spi = to_spi_device(wilc->dev); 827 struct spi_device *spi = to_spi_device(wilc->dev);
828 struct wilc_spi *spi_priv = wilc->bus_data;
819 u32 reg; 829 u32 reg;
820 u32 chipid; 830 u32 chipid;
821 static int isinit; 831 static int isinit;
@@ -828,12 +838,9 @@ static int wilc_spi_init(struct wilc *wilc, bool resume)
828 return 1; 838 return 1;
829 } 839 }
830 840
831 memset(&g_spi, 0, sizeof(struct wilc_spi));
832
833 /* 841 /*
834 * configure protocol 842 * configure protocol
835 */ 843 */
836 g_spi.crc_off = 0;
837 844
838 /* 845 /*
839 * TODO: We can remove the CRC trials if there is a definite 846 * TODO: We can remove the CRC trials if there is a definite
@@ -845,7 +852,7 @@ static int wilc_spi_init(struct wilc *wilc, bool resume)
845 * Read failed. Try with CRC off. This might happen when module 852 * Read failed. Try with CRC off. This might happen when module
846 * is removed but chip isn't reset 853 * is removed but chip isn't reset
847 */ 854 */
848 g_spi.crc_off = 1; 855 spi_priv->crc_off = 1;
849 dev_err(&spi->dev, 856 dev_err(&spi->dev,
850 "Failed read with CRC on, retrying with CRC off\n"); 857 "Failed read with CRC on, retrying with CRC off\n");
851 if (!spi_internal_read(wilc, WILC_SPI_PROTOCOL_OFFSET, &reg)) { 858 if (!spi_internal_read(wilc, WILC_SPI_PROTOCOL_OFFSET, &reg)) {
@@ -857,7 +864,7 @@ static int wilc_spi_init(struct wilc *wilc, bool resume)
857 return 0; 864 return 0;
858 } 865 }
859 } 866 }
860 if (g_spi.crc_off == 0) { 867 if (spi_priv->crc_off == 0) {
861 reg &= ~0xc; /* disable crc checking */ 868 reg &= ~0xc; /* disable crc checking */
862 reg &= ~0x70; 869 reg &= ~0x70;
863 reg |= (0x5 << 4); 870 reg |= (0x5 << 4);
@@ -867,7 +874,7 @@ static int wilc_spi_init(struct wilc *wilc, bool resume)
867 __LINE__); 874 __LINE__);
868 return 0; 875 return 0;
869 } 876 }
870 g_spi.crc_off = 1; 877 spi_priv->crc_off = 1;
871 } 878 }
872 879
873 /* 880 /*
@@ -878,7 +885,7 @@ static int wilc_spi_init(struct wilc *wilc, bool resume)
878 return 0; 885 return 0;
879 } 886 }
880 887
881 g_spi.has_thrpt_enh = 1; 888 spi_priv->has_thrpt_enh = 1;
882 889
883 isinit = 1; 890 isinit = 1;
884 891
@@ -888,9 +895,10 @@ static int wilc_spi_init(struct wilc *wilc, bool resume)
888static int wilc_spi_read_size(struct wilc *wilc, u32 *size) 895static int wilc_spi_read_size(struct wilc *wilc, u32 *size)
889{ 896{
890 struct spi_device *spi = to_spi_device(wilc->dev); 897 struct spi_device *spi = to_spi_device(wilc->dev);
898 struct wilc_spi *spi_priv = wilc->bus_data;
891 int ret; 899 int ret;
892 900
893 if (g_spi.has_thrpt_enh) { 901 if (spi_priv->has_thrpt_enh) {
894 ret = spi_internal_read(wilc, 0xe840 - WILC_SPI_REG_BASE, 902 ret = spi_internal_read(wilc, 0xe840 - WILC_SPI_REG_BASE,
895 size); 903 size);
896 *size = *size & IRQ_DMA_WD_CNT_MASK; 904 *size = *size & IRQ_DMA_WD_CNT_MASK;
@@ -915,6 +923,7 @@ static int wilc_spi_read_size(struct wilc *wilc, u32 *size)
915static int wilc_spi_read_int(struct wilc *wilc, u32 *int_status) 923static int wilc_spi_read_int(struct wilc *wilc, u32 *int_status)
916{ 924{
917 struct spi_device *spi = to_spi_device(wilc->dev); 925 struct spi_device *spi = to_spi_device(wilc->dev);
926 struct wilc_spi *spi_priv = wilc->bus_data;
918 int ret; 927 int ret;
919 u32 tmp; 928 u32 tmp;
920 u32 byte_cnt; 929 u32 byte_cnt;
@@ -923,7 +932,7 @@ static int wilc_spi_read_int(struct wilc *wilc, u32 *int_status)
923 u32 irq_flags; 932 u32 irq_flags;
924 int k = IRG_FLAGS_OFFSET + 5; 933 int k = IRG_FLAGS_OFFSET + 5;
925 934
926 if (g_spi.has_thrpt_enh) { 935 if (spi_priv->has_thrpt_enh) {
927 ret = spi_internal_read(wilc, 0xe840 - WILC_SPI_REG_BASE, 936 ret = spi_internal_read(wilc, 0xe840 - WILC_SPI_REG_BASE,
928 int_status); 937 int_status);
929 return ret; 938 return ret;
@@ -943,12 +952,12 @@ static int wilc_spi_read_int(struct wilc *wilc, u32 *int_status)
943 wilc_spi_read_reg(wilc, 0x1a90, &irq_flags); 952 wilc_spi_read_reg(wilc, 0x1a90, &irq_flags);
944 tmp |= ((irq_flags >> 27) << IRG_FLAGS_OFFSET); 953 tmp |= ((irq_flags >> 27) << IRG_FLAGS_OFFSET);
945 954
946 if (g_spi.nint > 5) { 955 if (spi_priv->nint > 5) {
947 wilc_spi_read_reg(wilc, 0x1a94, &irq_flags); 956 wilc_spi_read_reg(wilc, 0x1a94, &irq_flags);
948 tmp |= (((irq_flags >> 0) & 0x7) << k); 957 tmp |= (((irq_flags >> 0) & 0x7) << k);
949 } 958 }
950 959
951 unknown_mask = ~((1ul << g_spi.nint) - 1); 960 unknown_mask = ~((1ul << spi_priv->nint) - 1);
952 961
953 if ((tmp >> IRG_FLAGS_OFFSET) & unknown_mask) { 962 if ((tmp >> IRG_FLAGS_OFFSET) & unknown_mask) {
954 dev_err(&spi->dev, 963 dev_err(&spi->dev,
@@ -968,11 +977,12 @@ static int wilc_spi_read_int(struct wilc *wilc, u32 *int_status)
968static int wilc_spi_clear_int_ext(struct wilc *wilc, u32 val) 977static int wilc_spi_clear_int_ext(struct wilc *wilc, u32 val)
969{ 978{
970 struct spi_device *spi = to_spi_device(wilc->dev); 979 struct spi_device *spi = to_spi_device(wilc->dev);
980 struct wilc_spi *spi_priv = wilc->bus_data;
971 int ret; 981 int ret;
972 u32 flags; 982 u32 flags;
973 u32 tbl_ctl; 983 u32 tbl_ctl;
974 984
975 if (g_spi.has_thrpt_enh) { 985 if (spi_priv->has_thrpt_enh) {
976 ret = spi_internal_write(wilc, 0xe844 - WILC_SPI_REG_BASE, 986 ret = spi_internal_write(wilc, 0xe844 - WILC_SPI_REG_BASE,
977 val); 987 val);
978 return ret; 988 return ret;
@@ -983,7 +993,7 @@ static int wilc_spi_clear_int_ext(struct wilc *wilc, u32 val)
983 int i; 993 int i;
984 994
985 ret = 1; 995 ret = 1;
986 for (i = 0; i < g_spi.nint; i++) { 996 for (i = 0; i < spi_priv->nint; i++) {
987 /* 997 /*
988 * No matter what you write 1 or 0, 998 * No matter what you write 1 or 0,
989 * it will clear interrupt. 999 * it will clear interrupt.
@@ -1001,7 +1011,7 @@ static int wilc_spi_clear_int_ext(struct wilc *wilc, u32 val)
1001 0x10c8 + i * 4); 1011 0x10c8 + i * 4);
1002 return ret; 1012 return ret;
1003 } 1013 }
1004 for (i = g_spi.nint; i < MAX_NUM_INT; i++) { 1014 for (i = spi_priv->nint; i < MAX_NUM_INT; i++) {
1005 if (flags & 1) 1015 if (flags & 1)
1006 dev_err(&spi->dev, 1016 dev_err(&spi->dev,
1007 "Unexpected interrupt cleared %d...\n", 1017 "Unexpected interrupt cleared %d...\n",
@@ -1041,6 +1051,7 @@ static int wilc_spi_clear_int_ext(struct wilc *wilc, u32 val)
1041static int wilc_spi_sync_ext(struct wilc *wilc, int nint) 1051static int wilc_spi_sync_ext(struct wilc *wilc, int nint)
1042{ 1052{
1043 struct spi_device *spi = to_spi_device(wilc->dev); 1053 struct spi_device *spi = to_spi_device(wilc->dev);
1054 struct wilc_spi *spi_priv = wilc->bus_data;
1044 u32 reg; 1055 u32 reg;
1045 int ret, i; 1056 int ret, i;
1046 1057
@@ -1049,7 +1060,7 @@ static int wilc_spi_sync_ext(struct wilc *wilc, int nint)
1049 return 0; 1060 return 0;
1050 } 1061 }
1051 1062
1052 g_spi.nint = nint; 1063 spi_priv->nint = nint;
1053 1064
1054 /* 1065 /*
1055 * interrupt pin mux select 1066 * interrupt pin mux select
diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
index 7cd033004651..4fbbbbd5a64b 100644
--- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
+++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
@@ -82,12 +82,6 @@ static const struct wiphy_wowlan_support wowlan_support = {
82 .flags = WIPHY_WOWLAN_ANY 82 .flags = WIPHY_WOWLAN_ANY
83}; 83};
84 84
85static struct network_info last_scanned_shadow[MAX_NUM_SCANNED_NETWORKS_SHADOW];
86static u32 last_scanned_cnt;
87struct timer_list wilc_during_ip_timer;
88static struct timer_list aging_timer;
89static u8 op_ifcs;
90
91#define CHAN2G(_channel, _freq, _flags) { \ 85#define CHAN2G(_channel, _freq, _flags) { \
92 .band = NL80211_BAND_2GHZ, \ 86 .band = NL80211_BAND_2GHZ, \
93 .center_freq = (_freq), \ 87 .center_freq = (_freq), \
@@ -143,10 +137,7 @@ struct p2p_mgmt_data {
143static u8 wlan_channel = INVALID_CHANNEL; 137static u8 wlan_channel = INVALID_CHANNEL;
144static u8 curr_channel; 138static u8 curr_channel;
145static u8 p2p_oui[] = {0x50, 0x6f, 0x9A, 0x09}; 139static u8 p2p_oui[] = {0x50, 0x6f, 0x9A, 0x09};
146static u8 p2p_local_random = 0x01;
147static u8 p2p_recv_random;
148static u8 p2p_vendor_spec[] = {0xdd, 0x05, 0x00, 0x08, 0x40, 0x03}; 140static u8 p2p_vendor_spec[] = {0xdd, 0x05, 0x00, 0x08, 0x40, 0x03};
149static bool wilc_ie;
150 141
151static struct ieee80211_supported_band wilc_band_2ghz = { 142static struct ieee80211_supported_band wilc_band_2ghz = {
152 .channels = ieee80211_2ghz_channels, 143 .channels = ieee80211_2ghz_channels,
@@ -158,25 +149,18 @@ static struct ieee80211_supported_band wilc_band_2ghz = {
158#define AGING_TIME (9 * 1000) 149#define AGING_TIME (9 * 1000)
159#define DURING_IP_TIME_OUT 15000 150#define DURING_IP_TIME_OUT 15000
160 151
161static void clear_shadow_scan(void) 152static void clear_shadow_scan(struct wilc_priv *priv)
162{ 153{
163 int i; 154 int i;
164 155
165 if (op_ifcs != 0) 156 for (i = 0; i < priv->scanned_cnt; i++) {
166 return; 157 kfree(priv->scanned_shadow[i].ies);
167 158 priv->scanned_shadow[i].ies = NULL;
168 del_timer_sync(&aging_timer);
169 159
170 for (i = 0; i < last_scanned_cnt; i++) { 160 kfree(priv->scanned_shadow[i].join_params);
171 if (last_scanned_shadow[last_scanned_cnt].ies) { 161 priv->scanned_shadow[i].join_params = NULL;
172 kfree(last_scanned_shadow[i].ies);
173 last_scanned_shadow[last_scanned_cnt].ies = NULL;
174 }
175
176 kfree(last_scanned_shadow[i].join_params);
177 last_scanned_shadow[i].join_params = NULL;
178 } 162 }
179 last_scanned_cnt = 0; 163 priv->scanned_cnt = 0;
180} 164}
181 165
182static u32 get_rssi_avg(struct network_info *network_info) 166static u32 get_rssi_avg(struct network_info *network_info)
@@ -198,14 +182,14 @@ static void refresh_scan(struct wilc_priv *priv, bool direct_scan)
198 struct wiphy *wiphy = priv->dev->ieee80211_ptr->wiphy; 182 struct wiphy *wiphy = priv->dev->ieee80211_ptr->wiphy;
199 int i; 183 int i;
200 184
201 for (i = 0; i < last_scanned_cnt; i++) { 185 for (i = 0; i < priv->scanned_cnt; i++) {
202 struct network_info *network_info; 186 struct network_info *network_info;
203 s32 freq; 187 s32 freq;
204 struct ieee80211_channel *channel; 188 struct ieee80211_channel *channel;
205 int rssi; 189 int rssi;
206 struct cfg80211_bss *bss; 190 struct cfg80211_bss *bss;
207 191
208 network_info = &last_scanned_shadow[i]; 192 network_info = &priv->scanned_shadow[i];
209 193
210 if (!memcmp("DIRECT-", network_info->ssid, 7) && !direct_scan) 194 if (!memcmp("DIRECT-", network_info->ssid, 7) && !direct_scan)
211 continue; 195 continue;
@@ -229,62 +213,68 @@ static void refresh_scan(struct wilc_priv *priv, bool direct_scan)
229 } 213 }
230} 214}
231 215
232static void reset_shadow_found(void) 216static void reset_shadow_found(struct wilc_priv *priv)
233{ 217{
234 int i; 218 int i;
235 219
236 for (i = 0; i < last_scanned_cnt; i++) 220 for (i = 0; i < priv->scanned_cnt; i++)
237 last_scanned_shadow[i].found = 0; 221 priv->scanned_shadow[i].found = 0;
238} 222}
239 223
240static void update_scan_time(void) 224static void update_scan_time(struct wilc_priv *priv)
241{ 225{
242 int i; 226 int i;
243 227
244 for (i = 0; i < last_scanned_cnt; i++) 228 for (i = 0; i < priv->scanned_cnt; i++)
245 last_scanned_shadow[i].time_scan = jiffies; 229 priv->scanned_shadow[i].time_scan = jiffies;
246} 230}
247 231
248static void remove_network_from_shadow(struct timer_list *unused) 232static void remove_network_from_shadow(struct timer_list *t)
249{ 233{
234 struct wilc_priv *priv = from_timer(priv, t, aging_timer);
250 unsigned long now = jiffies; 235 unsigned long now = jiffies;
251 int i, j; 236 int i, j;
252 237
253 for (i = 0; i < last_scanned_cnt; i++) { 238 for (i = 0; i < priv->scanned_cnt; i++) {
254 if (!time_after(now, last_scanned_shadow[i].time_scan + 239 if (!time_after(now, priv->scanned_shadow[i].time_scan +
255 (unsigned long)(SCAN_RESULT_EXPIRE))) 240 (unsigned long)(SCAN_RESULT_EXPIRE)))
256 continue; 241 continue;
257 kfree(last_scanned_shadow[i].ies); 242 kfree(priv->scanned_shadow[i].ies);
258 last_scanned_shadow[i].ies = NULL; 243 priv->scanned_shadow[i].ies = NULL;
259 244
260 kfree(last_scanned_shadow[i].join_params); 245 kfree(priv->scanned_shadow[i].join_params);
261 246
262 for (j = i; (j < last_scanned_cnt - 1); j++) 247 for (j = i; (j < priv->scanned_cnt - 1); j++)
263 last_scanned_shadow[j] = last_scanned_shadow[j + 1]; 248 priv->scanned_shadow[j] = priv->scanned_shadow[j + 1];
264 249
265 last_scanned_cnt--; 250 priv->scanned_cnt--;
266 } 251 }
267 252
268 if (last_scanned_cnt != 0) 253 if (priv->scanned_cnt != 0)
269 mod_timer(&aging_timer, jiffies + msecs_to_jiffies(AGING_TIME)); 254 mod_timer(&priv->aging_timer,
255 jiffies + msecs_to_jiffies(AGING_TIME));
270} 256}
271 257
272static void clear_during_ip(struct timer_list *unused) 258static void clear_during_ip(struct timer_list *t)
273{ 259{
274 wilc_optaining_ip = false; 260 struct wilc_vif *vif = from_timer(vif, t, during_ip_timer);
261
262 vif->obtaining_ip = false;
275} 263}
276 264
277static int is_network_in_shadow(struct network_info *nw_info, void *user_void) 265static int is_network_in_shadow(struct network_info *nw_info,
266 struct wilc_priv *priv)
278{ 267{
279 int state = -1; 268 int state = -1;
280 int i; 269 int i;
281 270
282 if (last_scanned_cnt == 0) { 271 if (priv->scanned_cnt == 0) {
283 mod_timer(&aging_timer, jiffies + msecs_to_jiffies(AGING_TIME)); 272 mod_timer(&priv->aging_timer,
273 jiffies + msecs_to_jiffies(AGING_TIME));
284 state = -1; 274 state = -1;
285 } else { 275 } else {
286 for (i = 0; i < last_scanned_cnt; i++) { 276 for (i = 0; i < priv->scanned_cnt; i++) {
287 if (memcmp(last_scanned_shadow[i].bssid, 277 if (memcmp(priv->scanned_shadow[i].bssid,
288 nw_info->bssid, 6) == 0) { 278 nw_info->bssid, 6) == 0) {
289 state = i; 279 state = i;
290 break; 280 break;
@@ -295,23 +285,23 @@ static int is_network_in_shadow(struct network_info *nw_info, void *user_void)
295} 285}
296 286
297static void add_network_to_shadow(struct network_info *nw_info, 287static void add_network_to_shadow(struct network_info *nw_info,
298 void *user_void, void *join_params) 288 struct wilc_priv *priv, void *join_params)
299{ 289{
300 int ap_found = is_network_in_shadow(nw_info, user_void); 290 int ap_found = is_network_in_shadow(nw_info, priv);
301 u32 ap_index = 0; 291 u32 ap_index = 0;
302 u8 rssi_index = 0; 292 u8 rssi_index = 0;
303 struct network_info *shadow_nw_info; 293 struct network_info *shadow_nw_info;
304 294
305 if (last_scanned_cnt >= MAX_NUM_SCANNED_NETWORKS_SHADOW) 295 if (priv->scanned_cnt >= MAX_NUM_SCANNED_NETWORKS_SHADOW)
306 return; 296 return;
307 297
308 if (ap_found == -1) { 298 if (ap_found == -1) {
309 ap_index = last_scanned_cnt; 299 ap_index = priv->scanned_cnt;
310 last_scanned_cnt++; 300 priv->scanned_cnt++;
311 } else { 301 } else {
312 ap_index = ap_found; 302 ap_index = ap_found;
313 } 303 }
314 shadow_nw_info = &last_scanned_shadow[ap_index]; 304 shadow_nw_info = &priv->scanned_shadow[ap_index];
315 rssi_index = shadow_nw_info->rssi_history.index; 305 rssi_index = shadow_nw_info->rssi_history.index;
316 shadow_nw_info->rssi_history.samples[rssi_index++] = nw_info->rssi; 306 shadow_nw_info->rssi_history.samples[rssi_index++] = nw_info->rssi;
317 if (rssi_index == NUM_RSSI) { 307 if (rssi_index == NUM_RSSI) {
@@ -403,7 +393,7 @@ static void cfg_scan_result(enum scan_event scan_event,
403 u32 i; 393 u32 i;
404 394
405 for (i = 0; i < priv->rcvd_ch_cnt; i++) { 395 for (i = 0; i < priv->rcvd_ch_cnt; i++) {
406 if (memcmp(last_scanned_shadow[i].bssid, 396 if (memcmp(priv->scanned_shadow[i].bssid,
407 network_info->bssid, 6) == 0) 397 network_info->bssid, 6) == 0)
408 break; 398 break;
409 } 399 }
@@ -411,8 +401,8 @@ static void cfg_scan_result(enum scan_event scan_event,
411 if (i >= priv->rcvd_ch_cnt) 401 if (i >= priv->rcvd_ch_cnt)
412 return; 402 return;
413 403
414 last_scanned_shadow[i].rssi = network_info->rssi; 404 priv->scanned_shadow[i].rssi = network_info->rssi;
415 last_scanned_shadow[i].time_scan = jiffies; 405 priv->scanned_shadow[i].time_scan = jiffies;
416 } 406 }
417 } else if (scan_event == SCAN_EVENT_DONE) { 407 } else if (scan_event == SCAN_EVENT_DONE) {
418 refresh_scan(priv, false); 408 refresh_scan(priv, false);
@@ -438,7 +428,7 @@ static void cfg_scan_result(enum scan_event scan_event,
438 .aborted = false, 428 .aborted = false,
439 }; 429 };
440 430
441 update_scan_time(); 431 update_scan_time(priv);
442 refresh_scan(priv, false); 432 refresh_scan(priv, false);
443 433
444 cfg80211_scan_done(priv->scan_req, &info); 434 cfg80211_scan_done(priv->scan_req, &info);
@@ -449,19 +439,17 @@ static void cfg_scan_result(enum scan_event scan_event,
449 } 439 }
450} 440}
451 441
452static inline bool wilc_wfi_cfg_scan_time_expired(int i) 442static inline bool wilc_cfg_scan_time_expired(struct wilc_priv *priv, int i)
453{ 443{
454 unsigned long now = jiffies; 444 unsigned long now = jiffies;
455 445
456 if (time_after(now, last_scanned_shadow[i].time_scan_cached + 446 if (time_after(now, priv->scanned_shadow[i].time_scan_cached +
457 (unsigned long)(nl80211_SCAN_RESULT_EXPIRE - (1 * HZ)))) 447 (unsigned long)(nl80211_SCAN_RESULT_EXPIRE - (1 * HZ))))
458 return true; 448 return true;
459 else 449 else
460 return false; 450 return false;
461} 451}
462 452
463int wilc_connecting;
464
465static void cfg_connect_result(enum conn_event conn_disconn_evt, 453static void cfg_connect_result(enum conn_event conn_disconn_evt,
466 struct connect_info *conn_info, 454 struct connect_info *conn_info,
467 u8 mac_status, 455 u8 mac_status,
@@ -475,7 +463,7 @@ static void cfg_connect_result(enum conn_event conn_disconn_evt,
475 struct host_if_drv *wfi_drv = priv->hif_drv; 463 struct host_if_drv *wfi_drv = priv->hif_drv;
476 u8 null_bssid[ETH_ALEN] = {0}; 464 u8 null_bssid[ETH_ALEN] = {0};
477 465
478 wilc_connecting = 0; 466 vif->connecting = false;
479 467
480 if (conn_disconn_evt == CONN_DISCONN_EVENT_CONN_RESP) { 468 if (conn_disconn_evt == CONN_DISCONN_EVENT_CONN_RESP) {
481 u16 connect_status; 469 u16 connect_status;
@@ -487,7 +475,6 @@ static void cfg_connect_result(enum conn_event conn_disconn_evt,
487 connect_status = WLAN_STATUS_UNSPECIFIED_FAILURE; 475 connect_status = WLAN_STATUS_UNSPECIFIED_FAILURE;
488 wilc_wlan_set_bssid(priv->dev, null_bssid, 476 wilc_wlan_set_bssid(priv->dev, null_bssid,
489 STATION_MODE); 477 STATION_MODE);
490 eth_zero_addr(wilc_connected_ssid);
491 478
492 if (!wfi_drv->p2p_connect) 479 if (!wfi_drv->p2p_connect)
493 wlan_channel = INVALID_CHANNEL; 480 wlan_channel = INVALID_CHANNEL;
@@ -502,11 +489,11 @@ static void cfg_connect_result(enum conn_event conn_disconn_evt,
502 memcpy(priv->associated_bss, conn_info->bssid, 489 memcpy(priv->associated_bss, conn_info->bssid,
503 ETH_ALEN); 490 ETH_ALEN);
504 491
505 for (i = 0; i < last_scanned_cnt; i++) { 492 for (i = 0; i < priv->scanned_cnt; i++) {
506 if (memcmp(last_scanned_shadow[i].bssid, 493 if (memcmp(priv->scanned_shadow[i].bssid,
507 conn_info->bssid, 494 conn_info->bssid,
508 ETH_ALEN) == 0) { 495 ETH_ALEN) == 0) {
509 if (wilc_wfi_cfg_scan_time_expired(i)) 496 if (wilc_cfg_scan_time_expired(priv, i))
510 scan_refresh = true; 497 scan_refresh = true;
511 498
512 break; 499 break;
@@ -524,13 +511,12 @@ static void cfg_connect_result(enum conn_event conn_disconn_evt,
524 conn_info->resp_ies_len, connect_status, 511 conn_info->resp_ies_len, connect_status,
525 GFP_KERNEL); 512 GFP_KERNEL);
526 } else if (conn_disconn_evt == CONN_DISCONN_EVENT_DISCONN_NOTIF) { 513 } else if (conn_disconn_evt == CONN_DISCONN_EVENT_DISCONN_NOTIF) {
527 wilc_optaining_ip = false; 514 vif->obtaining_ip = false;
528 p2p_local_random = 0x01; 515 priv->p2p.local_random = 0x01;
529 p2p_recv_random = 0x00; 516 priv->p2p.recv_random = 0x00;
530 wilc_ie = false; 517 priv->p2p.is_wilc_ie = false;
531 eth_zero_addr(priv->associated_bss); 518 eth_zero_addr(priv->associated_bss);
532 wilc_wlan_set_bssid(priv->dev, null_bssid, STATION_MODE); 519 wilc_wlan_set_bssid(priv->dev, null_bssid, STATION_MODE);
533 eth_zero_addr(wilc_connected_ssid);
534 520
535 if (!wfi_drv->p2p_connect) 521 if (!wfi_drv->p2p_connect)
536 wlan_channel = INVALID_CHANNEL; 522 wlan_channel = INVALID_CHANNEL;
@@ -620,7 +606,7 @@ static int scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
620 606
621 priv->rcvd_ch_cnt = 0; 607 priv->rcvd_ch_cnt = 0;
622 608
623 reset_shadow_found(); 609 reset_shadow_found(priv);
624 610
625 priv->cfg_scanning = true; 611 priv->cfg_scanning = true;
626 if (request->n_channels <= MAX_NUM_SCANNED_NETWORKS) { 612 if (request->n_channels <= MAX_NUM_SCANNED_NETWORKS) {
@@ -673,25 +659,25 @@ static int connect(struct wiphy *wiphy, struct net_device *dev,
673 enum authtype auth_type = ANY; 659 enum authtype auth_type = ANY;
674 u32 cipher_group; 660 u32 cipher_group;
675 661
676 wilc_connecting = 1; 662 vif->connecting = true;
677 663
678 if (!(strncmp(sme->ssid, "DIRECT-", 7))) 664 if (!(strncmp(sme->ssid, "DIRECT-", 7)))
679 wfi_drv->p2p_connect = 1; 665 wfi_drv->p2p_connect = 1;
680 else 666 else
681 wfi_drv->p2p_connect = 0; 667 wfi_drv->p2p_connect = 0;
682 668
683 for (i = 0; i < last_scanned_cnt; i++) { 669 for (i = 0; i < priv->scanned_cnt; i++) {
684 if (sme->ssid_len == last_scanned_shadow[i].ssid_len && 670 if (sme->ssid_len == priv->scanned_shadow[i].ssid_len &&
685 memcmp(last_scanned_shadow[i].ssid, 671 memcmp(priv->scanned_shadow[i].ssid,
686 sme->ssid, 672 sme->ssid,
687 sme->ssid_len) == 0) { 673 sme->ssid_len) == 0) {
688 if (!sme->bssid) { 674 if (!sme->bssid) {
689 if (sel_bssi_idx == UINT_MAX || 675 if (sel_bssi_idx == UINT_MAX ||
690 last_scanned_shadow[i].rssi > 676 priv->scanned_shadow[i].rssi >
691 last_scanned_shadow[sel_bssi_idx].rssi) 677 priv->scanned_shadow[sel_bssi_idx].rssi)
692 sel_bssi_idx = i; 678 sel_bssi_idx = i;
693 } else { 679 } else {
694 if (memcmp(last_scanned_shadow[i].bssid, 680 if (memcmp(priv->scanned_shadow[i].bssid,
695 sme->bssid, 681 sme->bssid,
696 ETH_ALEN) == 0) { 682 ETH_ALEN) == 0) {
697 sel_bssi_idx = i; 683 sel_bssi_idx = i;
@@ -701,12 +687,16 @@ static int connect(struct wiphy *wiphy, struct net_device *dev,
701 } 687 }
702 } 688 }
703 689
704 if (sel_bssi_idx < last_scanned_cnt) { 690 if (sel_bssi_idx < priv->scanned_cnt) {
705 nw_info = &last_scanned_shadow[sel_bssi_idx]; 691 nw_info = &priv->scanned_shadow[sel_bssi_idx];
706 } else { 692 } else {
707 ret = -ENOENT; 693 ret = -ENOENT;
708 wilc_connecting = 0; 694 goto out_error;
709 return ret; 695 }
696
697 if (ether_addr_equal_unaligned(vif->bssid, nw_info->bssid)) {
698 ret = -EALREADY;
699 goto out_error;
710 } 700 }
711 701
712 memset(priv->wep_key, 0, sizeof(priv->wep_key)); 702 memset(priv->wep_key, 0, sizeof(priv->wep_key));
@@ -748,8 +738,7 @@ static int connect(struct wiphy *wiphy, struct net_device *dev,
748 ret = -ENOTSUPP; 738 ret = -ENOTSUPP;
749 netdev_err(dev, "%s: Unsupported cipher\n", 739 netdev_err(dev, "%s: Unsupported cipher\n",
750 __func__); 740 __func__);
751 wilc_connecting = 0; 741 goto out_error;
752 return ret;
753 } 742 }
754 } 743 }
755 744
@@ -796,13 +785,18 @@ static int connect(struct wiphy *wiphy, struct net_device *dev,
796 security, auth_type, 785 security, auth_type,
797 nw_info->ch, 786 nw_info->ch,
798 nw_info->join_params); 787 nw_info->join_params);
799 if (ret != 0) { 788 if (ret) {
789 u8 null_bssid[ETH_ALEN] = {0};
790
800 netdev_err(dev, "wilc_set_join_req(): Error\n"); 791 netdev_err(dev, "wilc_set_join_req(): Error\n");
801 ret = -ENOENT; 792 ret = -ENOENT;
802 wilc_connecting = 0; 793 wilc_wlan_set_bssid(dev, null_bssid, STATION_MODE);
803 return ret; 794 goto out_error;
804 } 795 }
796 return 0;
805 797
798out_error:
799 vif->connecting = false;
806 return ret; 800 return ret;
807} 801}
808 802
@@ -816,7 +810,7 @@ static int disconnect(struct wiphy *wiphy, struct net_device *dev,
816 int ret; 810 int ret;
817 u8 null_bssid[ETH_ALEN] = {0}; 811 u8 null_bssid[ETH_ALEN] = {0};
818 812
819 wilc_connecting = 0; 813 vif->connecting = false;
820 814
821 if (!wilc) 815 if (!wilc)
822 return -EIO; 816 return -EIO;
@@ -832,9 +826,9 @@ static int disconnect(struct wiphy *wiphy, struct net_device *dev,
832 wlan_channel = INVALID_CHANNEL; 826 wlan_channel = INVALID_CHANNEL;
833 wilc_wlan_set_bssid(priv->dev, null_bssid, STATION_MODE); 827 wilc_wlan_set_bssid(priv->dev, null_bssid, STATION_MODE);
834 828
835 p2p_local_random = 0x01; 829 priv->p2p.local_random = 0x01;
836 p2p_recv_random = 0x00; 830 priv->p2p.recv_random = 0x00;
837 wilc_ie = false; 831 priv->p2p.is_wilc_ie = false;
838 wfi_drv->p2p_timeout = 0; 832 wfi_drv->p2p_timeout = 0;
839 833
840 ret = wilc_disconnect(vif, reason_code); 834 ret = wilc_disconnect(vif, reason_code);
@@ -1132,9 +1126,9 @@ static int get_station(struct wiphy *wiphy, struct net_device *dev,
1132 1126
1133 if (stats.link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH && 1127 if (stats.link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH &&
1134 stats.link_speed != DEFAULT_LINK_SPEED) 1128 stats.link_speed != DEFAULT_LINK_SPEED)
1135 wilc_enable_tcp_ack_filter(true); 1129 wilc_enable_tcp_ack_filter(vif, true);
1136 else if (stats.link_speed != DEFAULT_LINK_SPEED) 1130 else if (stats.link_speed != DEFAULT_LINK_SPEED)
1137 wilc_enable_tcp_ack_filter(false); 1131 wilc_enable_tcp_ack_filter(vif, false);
1138 } 1132 }
1139 return 0; 1133 return 0;
1140} 1134}
@@ -1333,20 +1327,21 @@ static void wilc_wfi_cfg_parse_rx_vendor_spec(struct wilc_priv *priv, u8 *buff,
1333 struct wilc_vif *vif = netdev_priv(priv->dev); 1327 struct wilc_vif *vif = netdev_priv(priv->dev);
1334 1328
1335 subtype = buff[P2P_PUB_ACTION_SUBTYPE]; 1329 subtype = buff[P2P_PUB_ACTION_SUBTYPE];
1336 if ((subtype == GO_NEG_REQ || subtype == GO_NEG_RSP) && !wilc_ie) { 1330 if ((subtype == GO_NEG_REQ || subtype == GO_NEG_RSP) &&
1331 !priv->p2p.is_wilc_ie) {
1337 for (i = P2P_PUB_ACTION_SUBTYPE; i < size; i++) { 1332 for (i = P2P_PUB_ACTION_SUBTYPE; i < size; i++) {
1338 if (!memcmp(p2p_vendor_spec, &buff[i], 6)) { 1333 if (!memcmp(p2p_vendor_spec, &buff[i], 6)) {
1339 p2p_recv_random = buff[i + 6]; 1334 priv->p2p.recv_random = buff[i + 6];
1340 wilc_ie = true; 1335 priv->p2p.is_wilc_ie = true;
1341 break; 1336 break;
1342 } 1337 }
1343 } 1338 }
1344 } 1339 }
1345 1340
1346 if (p2p_local_random <= p2p_recv_random) { 1341 if (priv->p2p.local_random <= priv->p2p.recv_random) {
1347 netdev_dbg(vif->ndev, 1342 netdev_dbg(vif->ndev,
1348 "PEER WILL BE GO LocaRand=%02x RecvRand %02x\n", 1343 "PEER WILL BE GO LocaRand=%02x RecvRand %02x\n",
1349 p2p_local_random, p2p_recv_random); 1344 priv->p2p.local_random, priv->p2p.recv_random);
1350 return; 1345 return;
1351 } 1346 }
1352 1347
@@ -1414,7 +1409,7 @@ void wilc_wfi_p2p_rx(struct net_device *dev, u8 *buff, u32 size)
1414 size); 1409 size);
1415 1410
1416 if ((subtype == GO_NEG_REQ || subtype == GO_NEG_RSP) && 1411 if ((subtype == GO_NEG_REQ || subtype == GO_NEG_RSP) &&
1417 wilc_ie) 1412 priv->p2p.is_wilc_ie)
1418 size -= 7; 1413 size -= 7;
1419 1414
1420 break; 1415 break;
@@ -1506,7 +1501,8 @@ static int cancel_remain_on_channel(struct wiphy *wiphy,
1506 priv->remain_on_ch_params.listen_session_id); 1501 priv->remain_on_ch_params.listen_session_id);
1507} 1502}
1508 1503
1509static void wilc_wfi_cfg_tx_vendor_spec(struct p2p_mgmt_data *mgmt_tx, 1504static void wilc_wfi_cfg_tx_vendor_spec(struct wilc_priv *priv,
1505 struct p2p_mgmt_data *mgmt_tx,
1510 struct cfg80211_mgmt_tx_params *params, 1506 struct cfg80211_mgmt_tx_params *params,
1511 u8 iftype, u32 buf_len) 1507 u8 iftype, u32 buf_len)
1512{ 1508{
@@ -1516,17 +1512,16 @@ static void wilc_wfi_cfg_tx_vendor_spec(struct p2p_mgmt_data *mgmt_tx,
1516 u8 subtype = buf[P2P_PUB_ACTION_SUBTYPE]; 1512 u8 subtype = buf[P2P_PUB_ACTION_SUBTYPE];
1517 1513
1518 if (subtype == GO_NEG_REQ || subtype == GO_NEG_RSP) { 1514 if (subtype == GO_NEG_REQ || subtype == GO_NEG_RSP) {
1519 if (p2p_local_random == 1 && 1515 if (priv->p2p.local_random == 1 &&
1520 p2p_recv_random < p2p_local_random) { 1516 priv->p2p.recv_random < priv->p2p.local_random) {
1521 get_random_bytes(&p2p_local_random, 1); 1517 get_random_bytes(&priv->p2p.local_random, 1);
1522 p2p_local_random++; 1518 priv->p2p.local_random++;
1523 } 1519 }
1524 } 1520 }
1525 1521
1526 if (p2p_local_random <= p2p_recv_random || !(subtype == GO_NEG_REQ || 1522 if (priv->p2p.local_random <= priv->p2p.recv_random ||
1527 subtype == GO_NEG_RSP || 1523 !(subtype == GO_NEG_REQ || subtype == GO_NEG_RSP ||
1528 subtype == P2P_INV_REQ || 1524 subtype == P2P_INV_REQ || subtype == P2P_INV_RSP))
1529 subtype == P2P_INV_RSP))
1530 return; 1525 return;
1531 1526
1532 for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < len; i++) { 1527 for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < len; i++) {
@@ -1550,7 +1545,7 @@ static void wilc_wfi_cfg_tx_vendor_spec(struct p2p_mgmt_data *mgmt_tx,
1550 1545
1551 memcpy(&mgmt_tx->buff[len], p2p_vendor_spec, 1546 memcpy(&mgmt_tx->buff[len], p2p_vendor_spec,
1552 vendor_spec_len); 1547 vendor_spec_len);
1553 mgmt_tx->buff[len + vendor_spec_len] = p2p_local_random; 1548 mgmt_tx->buff[len + vendor_spec_len] = priv->p2p.local_random;
1554 mgmt_tx->size = buf_len; 1549 mgmt_tx->size = buf_len;
1555 } 1550 }
1556} 1551}
@@ -1569,7 +1564,7 @@ static int mgmt_tx(struct wiphy *wiphy,
1569 struct wilc_priv *priv = wiphy_priv(wiphy); 1564 struct wilc_priv *priv = wiphy_priv(wiphy);
1570 struct host_if_drv *wfi_drv = priv->hif_drv; 1565 struct host_if_drv *wfi_drv = priv->hif_drv;
1571 struct wilc_vif *vif = netdev_priv(wdev->netdev); 1566 struct wilc_vif *vif = netdev_priv(wdev->netdev);
1572 u32 buf_len = len + sizeof(p2p_vendor_spec) + sizeof(p2p_local_random); 1567 u32 buf_len = len + sizeof(p2p_vendor_spec) + sizeof(priv->p2p.local_random);
1573 int ret = 0; 1568 int ret = 0;
1574 1569
1575 *cookie = (unsigned long)buf; 1570 *cookie = (unsigned long)buf;
@@ -1617,8 +1612,8 @@ static int mgmt_tx(struct wiphy *wiphy,
1617 1612
1618 case PUBLIC_ACT_VENDORSPEC: 1613 case PUBLIC_ACT_VENDORSPEC:
1619 if (!memcmp(p2p_oui, &buf[ACTION_SUBTYPE_ID + 1], 4)) 1614 if (!memcmp(p2p_oui, &buf[ACTION_SUBTYPE_ID + 1], 4))
1620 wilc_wfi_cfg_tx_vendor_spec(mgmt_tx, params, 1615 wilc_wfi_cfg_tx_vendor_spec(priv, mgmt_tx,
1621 vif->iftype, 1616 params, vif->iftype,
1622 buf_len); 1617 buf_len);
1623 else 1618 else
1624 netdev_dbg(vif->ndev, 1619 netdev_dbg(vif->ndev,
@@ -1732,7 +1727,7 @@ static int set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1732 if (!priv->hif_drv) 1727 if (!priv->hif_drv)
1733 return -EIO; 1728 return -EIO;
1734 1729
1735 if (wilc_enable_ps) 1730 if (vif->wilc->enable_ps)
1736 wilc_set_power_mgmt(vif, enabled, timeout); 1731 wilc_set_power_mgmt(vif, enabled, timeout);
1737 1732
1738 return 0; 1733 return 0;
@@ -1746,15 +1741,15 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
1746 struct wilc_vif *vif = netdev_priv(dev); 1741 struct wilc_vif *vif = netdev_priv(dev);
1747 struct wilc *wl = vif->wilc; 1742 struct wilc *wl = vif->wilc;
1748 1743
1749 p2p_local_random = 0x01; 1744 priv->p2p.local_random = 0x01;
1750 p2p_recv_random = 0x00; 1745 priv->p2p.recv_random = 0x00;
1751 wilc_ie = false; 1746 priv->p2p.is_wilc_ie = false;
1752 wilc_optaining_ip = false; 1747 vif->obtaining_ip = false;
1753 del_timer(&wilc_during_ip_timer); 1748 del_timer(&vif->during_ip_timer);
1754 1749
1755 switch (type) { 1750 switch (type) {
1756 case NL80211_IFTYPE_STATION: 1751 case NL80211_IFTYPE_STATION:
1757 wilc_connecting = 0; 1752 vif->connecting = false;
1758 dev->ieee80211_ptr->iftype = type; 1753 dev->ieee80211_ptr->iftype = type;
1759 priv->wdev->iftype = type; 1754 priv->wdev->iftype = type;
1760 vif->monitor_flag = 0; 1755 vif->monitor_flag = 0;
@@ -1764,46 +1759,46 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
1764 memset(priv->assoc_stainfo.sta_associated_bss, 0, 1759 memset(priv->assoc_stainfo.sta_associated_bss, 0,
1765 MAX_NUM_STA * ETH_ALEN); 1760 MAX_NUM_STA * ETH_ALEN);
1766 1761
1767 wilc_enable_ps = true; 1762 wl->enable_ps = true;
1768 wilc_set_power_mgmt(vif, 1, 0); 1763 wilc_set_power_mgmt(vif, 1, 0);
1769 break; 1764 break;
1770 1765
1771 case NL80211_IFTYPE_P2P_CLIENT: 1766 case NL80211_IFTYPE_P2P_CLIENT:
1772 wilc_connecting = 0; 1767 vif->connecting = false;
1773 dev->ieee80211_ptr->iftype = type; 1768 dev->ieee80211_ptr->iftype = type;
1774 priv->wdev->iftype = type; 1769 priv->wdev->iftype = type;
1775 vif->monitor_flag = 0; 1770 vif->monitor_flag = 0;
1776 vif->iftype = CLIENT_MODE; 1771 vif->iftype = CLIENT_MODE;
1777 wilc_set_operation_mode(vif, STATION_MODE); 1772 wilc_set_operation_mode(vif, STATION_MODE);
1778 1773
1779 wilc_enable_ps = false; 1774 wl->enable_ps = false;
1780 wilc_set_power_mgmt(vif, 0, 0); 1775 wilc_set_power_mgmt(vif, 0, 0);
1781 break; 1776 break;
1782 1777
1783 case NL80211_IFTYPE_AP: 1778 case NL80211_IFTYPE_AP:
1784 wilc_enable_ps = false; 1779 wl->enable_ps = false;
1785 dev->ieee80211_ptr->iftype = type; 1780 dev->ieee80211_ptr->iftype = type;
1786 priv->wdev->iftype = type; 1781 priv->wdev->iftype = type;
1787 vif->iftype = AP_MODE; 1782 vif->iftype = AP_MODE;
1788 1783
1789 if (wl->initialized) { 1784 if (wl->initialized) {
1790 wilc_set_wfi_drv_handler(vif, wilc_get_vif_idx(vif), 1785 wilc_set_wfi_drv_handler(vif, wilc_get_vif_idx(vif),
1791 0, vif->ifc_id); 1786 0, vif->ifc_id, false);
1792 wilc_set_operation_mode(vif, AP_MODE); 1787 wilc_set_operation_mode(vif, AP_MODE);
1793 wilc_set_power_mgmt(vif, 0, 0); 1788 wilc_set_power_mgmt(vif, 0, 0);
1794 } 1789 }
1795 break; 1790 break;
1796 1791
1797 case NL80211_IFTYPE_P2P_GO: 1792 case NL80211_IFTYPE_P2P_GO:
1798 wilc_optaining_ip = true; 1793 vif->obtaining_ip = true;
1799 mod_timer(&wilc_during_ip_timer, 1794 mod_timer(&vif->during_ip_timer,
1800 jiffies + msecs_to_jiffies(DURING_IP_TIME_OUT)); 1795 jiffies + msecs_to_jiffies(DURING_IP_TIME_OUT));
1801 wilc_set_operation_mode(vif, AP_MODE); 1796 wilc_set_operation_mode(vif, AP_MODE);
1802 dev->ieee80211_ptr->iftype = type; 1797 dev->ieee80211_ptr->iftype = type;
1803 priv->wdev->iftype = type; 1798 priv->wdev->iftype = type;
1804 vif->iftype = GO_MODE; 1799 vif->iftype = GO_MODE;
1805 1800
1806 wilc_enable_ps = false; 1801 wl->enable_ps = false;
1807 wilc_set_power_mgmt(vif, 0, 0); 1802 wilc_set_power_mgmt(vif, 0, 0);
1808 break; 1803 break;
1809 1804
@@ -2154,8 +2149,12 @@ struct wireless_dev *wilc_create_wiphy(struct net_device *net,
2154 set_wiphy_dev(wdev->wiphy, dev); 2149 set_wiphy_dev(wdev->wiphy, dev);
2155 2150
2156 ret = wiphy_register(wdev->wiphy); 2151 ret = wiphy_register(wdev->wiphy);
2157 if (ret) 2152 if (ret) {
2158 netdev_err(net, "Cannot register wiphy device\n"); 2153 netdev_err(net, "Cannot register wiphy device\n");
2154 wiphy_free(wdev->wiphy);
2155 kfree(wdev);
2156 return NULL;
2157 }
2159 2158
2160 priv->dev = net; 2159 priv->dev = net;
2161 return wdev; 2160 return wdev;
@@ -2165,12 +2164,10 @@ int wilc_init_host_int(struct net_device *net)
2165{ 2164{
2166 int ret; 2165 int ret;
2167 struct wilc_priv *priv = wdev_priv(net->ieee80211_ptr); 2166 struct wilc_priv *priv = wdev_priv(net->ieee80211_ptr);
2167 struct wilc_vif *vif = netdev_priv(priv->dev);
2168 2168
2169 if (op_ifcs == 0) { 2169 timer_setup(&priv->aging_timer, remove_network_from_shadow, 0);
2170 timer_setup(&aging_timer, remove_network_from_shadow, 0); 2170 timer_setup(&vif->during_ip_timer, clear_during_ip, 0);
2171 timer_setup(&wilc_during_ip_timer, clear_during_ip, 0);
2172 }
2173 op_ifcs++;
2174 2171
2175 priv->p2p_listen_state = false; 2172 priv->p2p_listen_state = false;
2176 2173
@@ -2182,7 +2179,7 @@ int wilc_init_host_int(struct net_device *net)
2182 return ret; 2179 return ret;
2183} 2180}
2184 2181
2185int wilc_deinit_host_int(struct net_device *net) 2182void wilc_deinit_host_int(struct net_device *net)
2186{ 2183{
2187 int ret; 2184 int ret;
2188 struct wilc_priv *priv = wdev_priv(net->ieee80211_ptr); 2185 struct wilc_priv *priv = wdev_priv(net->ieee80211_ptr);
@@ -2190,19 +2187,15 @@ int wilc_deinit_host_int(struct net_device *net)
2190 2187
2191 priv->p2p_listen_state = false; 2188 priv->p2p_listen_state = false;
2192 2189
2193 op_ifcs--;
2194
2195 mutex_destroy(&priv->scan_req_lock); 2190 mutex_destroy(&priv->scan_req_lock);
2196 ret = wilc_deinit(vif); 2191 ret = wilc_deinit(vif);
2197 2192
2198 clear_shadow_scan(); 2193 del_timer_sync(&priv->aging_timer);
2199 if (op_ifcs == 0) 2194 clear_shadow_scan(priv);
2200 del_timer_sync(&wilc_during_ip_timer); 2195 del_timer_sync(&vif->during_ip_timer);
2201 2196
2202 if (ret) 2197 if (ret)
2203 netdev_err(net, "Error while deinitializing host interface\n"); 2198 netdev_err(net, "Error while deinitializing host interface\n");
2204
2205 return ret;
2206} 2199}
2207 2200
2208void wilc_free_wiphy(struct net_device *net) 2201void wilc_free_wiphy(struct net_device *net)
diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.h b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.h
index be412b65926c..4812c8e2c79b 100644
--- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.h
+++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.h
@@ -11,10 +11,10 @@
11struct wireless_dev *wilc_create_wiphy(struct net_device *net, 11struct wireless_dev *wilc_create_wiphy(struct net_device *net,
12 struct device *dev); 12 struct device *dev);
13void wilc_free_wiphy(struct net_device *net); 13void wilc_free_wiphy(struct net_device *net);
14int wilc_deinit_host_int(struct net_device *net); 14void wilc_deinit_host_int(struct net_device *net);
15int wilc_init_host_int(struct net_device *net); 15int wilc_init_host_int(struct net_device *net);
16void wilc_wfi_monitor_rx(u8 *buff, u32 size); 16void wilc_wfi_monitor_rx(u8 *buff, u32 size);
17int wilc_wfi_deinit_mon_interface(void); 17void wilc_wfi_deinit_mon_interface(void);
18struct net_device *wilc_wfi_init_mon_interface(const char *name, 18struct net_device *wilc_wfi_init_mon_interface(const char *name,
19 struct net_device *real_dev); 19 struct net_device *real_dev);
20void wilc_mgmt_frame_register(struct wiphy *wiphy, struct wireless_dev *wdev, 20void wilc_mgmt_frame_register(struct wiphy *wiphy, struct wireless_dev *wdev,
diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index b7eee772f3fe..4f05a16c778e 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -16,6 +16,7 @@
16 16
17#include "host_interface.h" 17#include "host_interface.h"
18#include "wilc_wlan.h" 18#include "wilc_wlan.h"
19#include "wilc_wlan_cfg.h"
19 20
20#define FLOW_CONTROL_LOWER_THRESHOLD 128 21#define FLOW_CONTROL_LOWER_THRESHOLD 128
21#define FLOW_CONTROL_UPPER_THRESHOLD 256 22#define FLOW_CONTROL_UPPER_THRESHOLD 256
@@ -68,6 +69,12 @@ struct wilc_wfi_p2p_listen_params {
68 u32 listen_session_id; 69 u32 listen_session_id;
69}; 70};
70 71
72struct wilc_p2p_var {
73 u8 local_random;
74 u8 recv_random;
75 bool is_wilc_ie;
76};
77
71struct wilc_priv { 78struct wilc_priv {
72 struct wireless_dev *wdev; 79 struct wireless_dev *wdev;
73 struct cfg80211_scan_request *scan_req; 80 struct cfg80211_scan_request *scan_req;
@@ -94,7 +101,10 @@ struct wilc_priv {
94 /* mutexes */ 101 /* mutexes */
95 struct mutex scan_req_lock; 102 struct mutex scan_req_lock;
96 bool p2p_listen_state; 103 bool p2p_listen_state;
97 104 struct timer_list aging_timer;
105 struct network_info scanned_shadow[MAX_NUM_SCANNED_NETWORKS_SHADOW];
106 int scanned_cnt;
107 struct wilc_p2p_var p2p;
98}; 108};
99 109
100struct frame_reg { 110struct frame_reg {
@@ -102,6 +112,32 @@ struct frame_reg {
102 bool reg; 112 bool reg;
103}; 113};
104 114
115#define MAX_TCP_SESSION 25
116#define MAX_PENDING_ACKS 256
117
118struct ack_session_info {
119 u32 seq_num;
120 u32 bigger_ack_num;
121 u16 src_port;
122 u16 dst_port;
123 u16 status;
124};
125
126struct pending_acks {
127 u32 ack_num;
128 u32 session_index;
129 struct txq_entry_t *txqe;
130};
131
132struct tcp_ack_filter {
133 struct ack_session_info ack_session_info[2 * MAX_TCP_SESSION];
134 struct pending_acks pending_acks[MAX_PENDING_ACKS];
135 u32 pending_base;
136 u32 tcp_session;
137 u32 pending_acks_idx;
138 bool enabled;
139};
140
105struct wilc_vif { 141struct wilc_vif {
106 u8 idx; 142 u8 idx;
107 u8 iftype; 143 u8 iftype;
@@ -116,12 +152,18 @@ struct wilc_vif {
116 struct net_device *ndev; 152 struct net_device *ndev;
117 u8 mode; 153 u8 mode;
118 u8 ifc_id; 154 u8 ifc_id;
155 struct timer_list during_ip_timer;
156 bool obtaining_ip;
157 struct timer_list periodic_rssi;
158 struct rf_info periodic_stat;
159 struct tcp_ack_filter ack_filter;
160 bool connecting;
119}; 161};
120 162
121struct wilc { 163struct wilc {
122 const struct wilc_hif_func *hif_func; 164 const struct wilc_hif_func *hif_func;
123 int io_type; 165 int io_type;
124 int mac_status; 166 s8 mac_status;
125 struct gpio_desc *gpio_irq; 167 struct gpio_desc *gpio_irq;
126 bool initialized; 168 bool initialized;
127 int dev_irq_num; 169 int dev_irq_num;
@@ -165,7 +207,12 @@ struct wilc {
165 struct device *dev; 207 struct device *dev;
166 bool suspend_event; 208 bool suspend_event;
167 209
168 struct rf_info dummy_statistics; 210 bool enable_ps;
211 int clients_count;
212 struct workqueue_struct *hif_workqueue;
213 enum chip_ps_states chip_ps_state;
214 struct wilc_cfg cfg;
215 void *bus_data;
169}; 216};
170 217
171struct wilc_wfi_mon_priv { 218struct wilc_wfi_mon_priv {
@@ -178,6 +225,6 @@ void wilc_netdev_cleanup(struct wilc *wilc);
178int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type, 225int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
179 const struct wilc_hif_func *ops); 226 const struct wilc_hif_func *ops);
180void wilc_wfi_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size); 227void wilc_wfi_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size);
181int wilc_wlan_set_bssid(struct net_device *wilc_netdev, u8 *bssid, u8 mode); 228void wilc_wlan_set_bssid(struct net_device *wilc_netdev, u8 *bssid, u8 mode);
182 229
183#endif 230#endif
diff --git a/drivers/staging/wilc1000/wilc_wlan.c b/drivers/staging/wilc1000/wilc_wlan.c
index 8b184aa30d25..a48c906b2443 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -9,8 +9,6 @@
9#include "wilc_wfi_netdevice.h" 9#include "wilc_wfi_netdevice.h"
10#include "wilc_wlan_cfg.h" 10#include "wilc_wlan_cfg.h"
11 11
12static enum chip_ps_states chip_ps_state = CHIP_WAKEDUP;
13
14static inline bool is_wilc1000(u32 id) 12static inline bool is_wilc1000(u32 id)
15{ 13{
16 return ((id & 0xfffff000) == 0x100000 ? true : false); 14 return ((id & 0xfffff000) == 0x100000 ? true : false);
@@ -73,8 +71,8 @@ static void wilc_wlan_txq_add_to_tail(struct net_device *dev,
73 complete(&wilc->txq_event); 71 complete(&wilc->txq_event);
74} 72}
75 73
76static int wilc_wlan_txq_add_to_head(struct wilc_vif *vif, 74static void wilc_wlan_txq_add_to_head(struct wilc_vif *vif,
77 struct txq_entry_t *tqe) 75 struct txq_entry_t *tqe)
78{ 76{
79 unsigned long flags; 77 unsigned long flags;
80 struct wilc *wilc = vif->wilc; 78 struct wilc *wilc = vif->wilc;
@@ -89,69 +87,47 @@ static int wilc_wlan_txq_add_to_head(struct wilc_vif *vif,
89 spin_unlock_irqrestore(&wilc->txq_spinlock, flags); 87 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
90 mutex_unlock(&wilc->txq_add_to_head_cs); 88 mutex_unlock(&wilc->txq_add_to_head_cs);
91 complete(&wilc->txq_event); 89 complete(&wilc->txq_event);
92
93 return 0;
94} 90}
95 91
96struct ack_session_info;
97struct ack_session_info {
98 u32 seq_num;
99 u32 bigger_ack_num;
100 u16 src_port;
101 u16 dst_port;
102 u16 status;
103};
104
105struct pending_acks_info {
106 u32 ack_num;
107 u32 session_index;
108 struct txq_entry_t *txqe;
109};
110
111#define NOT_TCP_ACK (-1) 92#define NOT_TCP_ACK (-1)
112 93
113#define MAX_TCP_SESSION 25 94static inline void add_tcp_session(struct wilc_vif *vif, u32 src_prt,
114#define MAX_PENDING_ACKS 256 95 u32 dst_prt, u32 seq)
115static struct ack_session_info ack_session_info[2 * MAX_TCP_SESSION];
116static struct pending_acks_info pending_acks_info[MAX_PENDING_ACKS];
117
118static u32 pending_base;
119static u32 tcp_session;
120static u32 pending_acks;
121
122static inline int add_tcp_session(u32 src_prt, u32 dst_prt, u32 seq)
123{ 96{
124 if (tcp_session < 2 * MAX_TCP_SESSION) { 97 struct tcp_ack_filter *f = &vif->ack_filter;
125 ack_session_info[tcp_session].seq_num = seq; 98
126 ack_session_info[tcp_session].bigger_ack_num = 0; 99 if (f->tcp_session < 2 * MAX_TCP_SESSION) {
127 ack_session_info[tcp_session].src_port = src_prt; 100 f->ack_session_info[f->tcp_session].seq_num = seq;
128 ack_session_info[tcp_session].dst_port = dst_prt; 101 f->ack_session_info[f->tcp_session].bigger_ack_num = 0;
129 tcp_session++; 102 f->ack_session_info[f->tcp_session].src_port = src_prt;
103 f->ack_session_info[f->tcp_session].dst_port = dst_prt;
104 f->tcp_session++;
130 } 105 }
131 return 0;
132} 106}
133 107
134static inline int update_tcp_session(u32 index, u32 ack) 108static inline void update_tcp_session(struct wilc_vif *vif, u32 index, u32 ack)
135{ 109{
110 struct tcp_ack_filter *f = &vif->ack_filter;
111
136 if (index < 2 * MAX_TCP_SESSION && 112 if (index < 2 * MAX_TCP_SESSION &&
137 ack > ack_session_info[index].bigger_ack_num) 113 ack > f->ack_session_info[index].bigger_ack_num)
138 ack_session_info[index].bigger_ack_num = ack; 114 f->ack_session_info[index].bigger_ack_num = ack;
139 return 0;
140} 115}
141 116
142static inline int add_tcp_pending_ack(u32 ack, u32 session_index, 117static inline void add_tcp_pending_ack(struct wilc_vif *vif, u32 ack,
143 struct txq_entry_t *txqe) 118 u32 session_index,
119 struct txq_entry_t *txqe)
144{ 120{
145 u32 i = pending_base + pending_acks; 121 struct tcp_ack_filter *f = &vif->ack_filter;
122 u32 i = f->pending_base + f->pending_acks_idx;
146 123
147 if (i < MAX_PENDING_ACKS) { 124 if (i < MAX_PENDING_ACKS) {
148 pending_acks_info[i].ack_num = ack; 125 f->pending_acks[i].ack_num = ack;
149 pending_acks_info[i].txqe = txqe; 126 f->pending_acks[i].txqe = txqe;
150 pending_acks_info[i].session_index = session_index; 127 f->pending_acks[i].session_index = session_index;
151 txqe->tcp_pending_ack_idx = i; 128 txqe->ack_idx = i;
152 pending_acks++; 129 f->pending_acks_idx++;
153 } 130 }
154 return 0;
155} 131}
156 132
157static inline void tcp_process(struct net_device *dev, struct txq_entry_t *tqe) 133static inline void tcp_process(struct net_device *dev, struct txq_entry_t *tqe)
@@ -162,72 +138,79 @@ static inline void tcp_process(struct net_device *dev, struct txq_entry_t *tqe)
162 unsigned long flags; 138 unsigned long flags;
163 struct wilc_vif *vif = netdev_priv(dev); 139 struct wilc_vif *vif = netdev_priv(dev);
164 struct wilc *wilc = vif->wilc; 140 struct wilc *wilc = vif->wilc;
141 struct tcp_ack_filter *f = &vif->ack_filter;
142 const struct iphdr *ip_hdr_ptr;
143 const struct tcphdr *tcp_hdr_ptr;
144 u32 ihl, total_length, data_offset;
165 145
166 spin_lock_irqsave(&wilc->txq_spinlock, flags); 146 spin_lock_irqsave(&wilc->txq_spinlock, flags);
167 147
168 if (eth_hdr_ptr->h_proto == htons(ETH_P_IP)) { 148 if (eth_hdr_ptr->h_proto != htons(ETH_P_IP))
169 const struct iphdr *ip_hdr_ptr = buffer + ETH_HLEN; 149 goto out;
170 150
171 if (ip_hdr_ptr->protocol == IPPROTO_TCP) { 151 ip_hdr_ptr = buffer + ETH_HLEN;
172 const struct tcphdr *tcp_hdr_ptr;
173 u32 IHL, total_length, data_offset;
174 152
175 IHL = ip_hdr_ptr->ihl << 2; 153 if (ip_hdr_ptr->protocol != IPPROTO_TCP)
176 tcp_hdr_ptr = buffer + ETH_HLEN + IHL; 154 goto out;
177 total_length = ntohs(ip_hdr_ptr->tot_len);
178 155
179 data_offset = tcp_hdr_ptr->doff << 2; 156 ihl = ip_hdr_ptr->ihl << 2;
180 if (total_length == (IHL + data_offset)) { 157 tcp_hdr_ptr = buffer + ETH_HLEN + ihl;
181 u32 seq_no, ack_no; 158 total_length = ntohs(ip_hdr_ptr->tot_len);
182 159
183 seq_no = ntohl(tcp_hdr_ptr->seq); 160 data_offset = tcp_hdr_ptr->doff << 2;
184 ack_no = ntohl(tcp_hdr_ptr->ack_seq); 161 if (total_length == (ihl + data_offset)) {
185 for (i = 0; i < tcp_session; i++) { 162 u32 seq_no, ack_no;
186 u32 j = ack_session_info[i].seq_num;
187 163
188 if (i < 2 * MAX_TCP_SESSION && 164 seq_no = ntohl(tcp_hdr_ptr->seq);
189 j == seq_no) { 165 ack_no = ntohl(tcp_hdr_ptr->ack_seq);
190 update_tcp_session(i, ack_no); 166 for (i = 0; i < f->tcp_session; i++) {
191 break; 167 u32 j = f->ack_session_info[i].seq_num;
192 }
193 }
194 if (i == tcp_session)
195 add_tcp_session(0, 0, seq_no);
196 168
197 add_tcp_pending_ack(ack_no, i, tqe); 169 if (i < 2 * MAX_TCP_SESSION &&
170 j == seq_no) {
171 update_tcp_session(vif, i, ack_no);
172 break;
198 } 173 }
199 } 174 }
175 if (i == f->tcp_session)
176 add_tcp_session(vif, 0, 0, seq_no);
177
178 add_tcp_pending_ack(vif, ack_no, i, tqe);
200 } 179 }
180
181out:
201 spin_unlock_irqrestore(&wilc->txq_spinlock, flags); 182 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
202} 183}
203 184
204static int wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev) 185static void wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev)
205{ 186{
206 struct wilc_vif *vif = netdev_priv(dev); 187 struct wilc_vif *vif = netdev_priv(dev);
207 struct wilc *wilc = vif->wilc; 188 struct wilc *wilc = vif->wilc;
189 struct tcp_ack_filter *f = &vif->ack_filter;
208 u32 i = 0; 190 u32 i = 0;
209 u32 dropped = 0; 191 u32 dropped = 0;
210 unsigned long flags; 192 unsigned long flags;
211 193
212 spin_lock_irqsave(&wilc->txq_spinlock, flags); 194 spin_lock_irqsave(&wilc->txq_spinlock, flags);
213 for (i = pending_base; i < (pending_base + pending_acks); i++) { 195 for (i = f->pending_base;
214 u32 session_index; 196 i < (f->pending_base + f->pending_acks_idx); i++) {
197 u32 index;
215 u32 bigger_ack_num; 198 u32 bigger_ack_num;
216 199
217 if (i >= MAX_PENDING_ACKS) 200 if (i >= MAX_PENDING_ACKS)
218 break; 201 break;
219 202
220 session_index = pending_acks_info[i].session_index; 203 index = f->pending_acks[i].session_index;
221 204
222 if (session_index >= 2 * MAX_TCP_SESSION) 205 if (index >= 2 * MAX_TCP_SESSION)
223 break; 206 break;
224 207
225 bigger_ack_num = ack_session_info[session_index].bigger_ack_num; 208 bigger_ack_num = f->ack_session_info[index].bigger_ack_num;
226 209
227 if (pending_acks_info[i].ack_num < bigger_ack_num) { 210 if (f->pending_acks[i].ack_num < bigger_ack_num) {
228 struct txq_entry_t *tqe; 211 struct txq_entry_t *tqe;
229 212
230 tqe = pending_acks_info[i].txqe; 213 tqe = f->pending_acks[i].txqe;
231 if (tqe) { 214 if (tqe) {
232 wilc_wlan_txq_remove(wilc, tqe); 215 wilc_wlan_txq_remove(wilc, tqe);
233 tqe->status = 1; 216 tqe->status = 1;
@@ -239,13 +222,13 @@ static int wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev)
239 } 222 }
240 } 223 }
241 } 224 }
242 pending_acks = 0; 225 f->pending_acks_idx = 0;
243 tcp_session = 0; 226 f->tcp_session = 0;
244 227
245 if (pending_base == 0) 228 if (f->pending_base == 0)
246 pending_base = MAX_TCP_SESSION; 229 f->pending_base = MAX_TCP_SESSION;
247 else 230 else
248 pending_base = 0; 231 f->pending_base = 0;
249 232
250 spin_unlock_irqrestore(&wilc->txq_spinlock, flags); 233 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
251 234
@@ -254,15 +237,11 @@ static int wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev)
254 msecs_to_jiffies(1)); 237 msecs_to_jiffies(1));
255 dropped--; 238 dropped--;
256 } 239 }
257
258 return 1;
259} 240}
260 241
261static bool enabled; 242void wilc_enable_tcp_ack_filter(struct wilc_vif *vif, bool value)
262
263void wilc_enable_tcp_ack_filter(bool value)
264{ 243{
265 enabled = value; 244 vif->ack_filter.enabled = value;
266} 245}
267 246
268static int wilc_wlan_txq_add_cfg_pkt(struct wilc_vif *vif, u8 *buffer, 247static int wilc_wlan_txq_add_cfg_pkt(struct wilc_vif *vif, u8 *buffer,
@@ -287,12 +266,9 @@ static int wilc_wlan_txq_add_cfg_pkt(struct wilc_vif *vif, u8 *buffer,
287 tqe->buffer_size = buffer_size; 266 tqe->buffer_size = buffer_size;
288 tqe->tx_complete_func = NULL; 267 tqe->tx_complete_func = NULL;
289 tqe->priv = NULL; 268 tqe->priv = NULL;
290 tqe->tcp_pending_ack_idx = NOT_TCP_ACK; 269 tqe->ack_idx = NOT_TCP_ACK;
291 270
292 if (wilc_wlan_txq_add_to_head(vif, tqe)) { 271 wilc_wlan_txq_add_to_head(vif, tqe);
293 kfree(tqe);
294 return 0;
295 }
296 272
297 return 1; 273 return 1;
298} 274}
@@ -319,8 +295,8 @@ int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
319 tqe->tx_complete_func = func; 295 tqe->tx_complete_func = func;
320 tqe->priv = priv; 296 tqe->priv = priv;
321 297
322 tqe->tcp_pending_ack_idx = NOT_TCP_ACK; 298 tqe->ack_idx = NOT_TCP_ACK;
323 if (enabled) 299 if (vif->ack_filter.enabled)
324 tcp_process(dev, tqe); 300 tcp_process(dev, tqe);
325 wilc_wlan_txq_add_to_tail(dev, tqe); 301 wilc_wlan_txq_add_to_tail(dev, tqe);
326 return wilc->txq_entries; 302 return wilc->txq_entries;
@@ -347,7 +323,7 @@ int wilc_wlan_txq_add_mgmt_pkt(struct net_device *dev, void *priv, u8 *buffer,
347 tqe->buffer_size = buffer_size; 323 tqe->buffer_size = buffer_size;
348 tqe->tx_complete_func = func; 324 tqe->tx_complete_func = func;
349 tqe->priv = priv; 325 tqe->priv = priv;
350 tqe->tcp_pending_ack_idx = NOT_TCP_ACK; 326 tqe->ack_idx = NOT_TCP_ACK;
351 wilc_wlan_txq_add_to_tail(dev, tqe); 327 wilc_wlan_txq_add_to_tail(dev, tqe);
352 return 1; 328 return 1;
353} 329}
@@ -436,7 +412,7 @@ void chip_wakeup(struct wilc *wilc)
436 } while (wilc_get_chipid(wilc, true) == 0); 412 } while (wilc_get_chipid(wilc, true) == 0);
437 } else if ((wilc->io_type & 0x1) == HIF_SDIO) { 413 } else if ((wilc->io_type & 0x1) == HIF_SDIO) {
438 wilc->hif_func->hif_write_reg(wilc, 0xfa, 1); 414 wilc->hif_func->hif_write_reg(wilc, 0xfa, 1);
439 udelay(200); 415 usleep_range(200, 400);
440 wilc->hif_func->hif_read_reg(wilc, 0xf0, &reg); 416 wilc->hif_func->hif_read_reg(wilc, 0xf0, &reg);
441 do { 417 do {
442 wilc->hif_func->hif_write_reg(wilc, 0xf0, 418 wilc->hif_func->hif_write_reg(wilc, 0xf0,
@@ -457,7 +433,7 @@ void chip_wakeup(struct wilc *wilc)
457 } while ((clk_status_reg & 0x1) == 0); 433 } while ((clk_status_reg & 0x1) == 0);
458 } 434 }
459 435
460 if (chip_ps_state == CHIP_SLEEPING_MANUAL) { 436 if (wilc->chip_ps_state == CHIP_SLEEPING_MANUAL) {
461 if (wilc_get_chipid(wilc, false) < 0x1002b0) { 437 if (wilc_get_chipid(wilc, false) < 0x1002b0) {
462 u32 val32; 438 u32 val32;
463 439
@@ -470,20 +446,20 @@ void chip_wakeup(struct wilc *wilc)
470 wilc->hif_func->hif_write_reg(wilc, 0x1e9c, val32); 446 wilc->hif_func->hif_write_reg(wilc, 0x1e9c, val32);
471 } 447 }
472 } 448 }
473 chip_ps_state = CHIP_WAKEDUP; 449 wilc->chip_ps_state = CHIP_WAKEDUP;
474} 450}
475EXPORT_SYMBOL_GPL(chip_wakeup); 451EXPORT_SYMBOL_GPL(chip_wakeup);
476 452
477void wilc_chip_sleep_manually(struct wilc *wilc) 453void wilc_chip_sleep_manually(struct wilc *wilc)
478{ 454{
479 if (chip_ps_state != CHIP_WAKEDUP) 455 if (wilc->chip_ps_state != CHIP_WAKEDUP)
480 return; 456 return;
481 acquire_bus(wilc, ACQUIRE_ONLY); 457 acquire_bus(wilc, ACQUIRE_ONLY);
482 458
483 chip_allow_sleep(wilc); 459 chip_allow_sleep(wilc);
484 wilc->hif_func->hif_write_reg(wilc, 0x10a8, 1); 460 wilc->hif_func->hif_write_reg(wilc, 0x10a8, 1);
485 461
486 chip_ps_state = CHIP_SLEEPING_MANUAL; 462 wilc->chip_ps_state = CHIP_SLEEPING_MANUAL;
487 release_bus(wilc, RELEASE_ONLY); 463 release_bus(wilc, RELEASE_ONLY);
488} 464}
489EXPORT_SYMBOL_GPL(wilc_chip_sleep_manually); 465EXPORT_SYMBOL_GPL(wilc_chip_sleep_manually);
@@ -685,9 +661,9 @@ int wilc_wlan_handle_txq(struct net_device *dev, u32 *txq_count)
685 tqe->status = 1; 661 tqe->status = 1;
686 if (tqe->tx_complete_func) 662 if (tqe->tx_complete_func)
687 tqe->tx_complete_func(tqe->priv, tqe->status); 663 tqe->tx_complete_func(tqe->priv, tqe->status);
688 if (tqe->tcp_pending_ack_idx != NOT_TCP_ACK && 664 if (tqe->ack_idx != NOT_TCP_ACK &&
689 tqe->tcp_pending_ack_idx < MAX_PENDING_ACKS) 665 tqe->ack_idx < MAX_PENDING_ACKS)
690 pending_acks_info[tqe->tcp_pending_ack_idx].txqe = NULL; 666 vif->ack_filter.pending_acks[tqe->ack_idx].txqe = NULL;
691 kfree(tqe); 667 kfree(tqe);
692 } while (--entries); 668 } while (--entries);
693 669
@@ -1218,9 +1194,9 @@ int wilc_wlan_cfg_get(struct wilc_vif *vif, int start, u16 wid, int commit,
1218 return ret_size; 1194 return ret_size;
1219} 1195}
1220 1196
1221int wilc_wlan_cfg_get_val(u16 wid, u8 *buffer, u32 buffer_size) 1197int wilc_wlan_cfg_get_val(struct wilc *wl, u16 wid, u8 *buffer, u32 buffer_size)
1222{ 1198{
1223 return wilc_wlan_cfg_get_wid_value(wid, buffer, buffer_size); 1199 return wilc_wlan_cfg_get_wid_value(wl, wid, buffer, buffer_size);
1224} 1200}
1225 1201
1226int wilc_send_config_pkt(struct wilc_vif *vif, u8 mode, struct wid *wids, 1202int wilc_send_config_pkt(struct wilc_vif *vif, u8 mode, struct wid *wids,
@@ -1240,7 +1216,8 @@ int wilc_send_config_pkt(struct wilc_vif *vif, u8 mode, struct wid *wids,
1240 } 1216 }
1241 } 1217 }
1242 for (i = 0; i < count; i++) { 1218 for (i = 0; i < count; i++) {
1243 wids[i].size = wilc_wlan_cfg_get_val(wids[i].id, 1219 wids[i].size = wilc_wlan_cfg_get_val(vif->wilc,
1220 wids[i].id,
1244 wids[i].val, 1221 wids[i].val,
1245 wids[i].size); 1222 wids[i].size);
1246 } 1223 }
@@ -1339,11 +1316,6 @@ int wilc_wlan_init(struct net_device *dev)
1339 goto fail; 1316 goto fail;
1340 } 1317 }
1341 1318
1342 if (!wilc_wlan_cfg_init()) {
1343 ret = -ENOBUFS;
1344 goto fail;
1345 }
1346
1347 if (!wilc->tx_buffer) 1319 if (!wilc->tx_buffer)
1348 wilc->tx_buffer = kmalloc(LINUX_TX_SIZE, GFP_KERNEL); 1320 wilc->tx_buffer = kmalloc(LINUX_TX_SIZE, GFP_KERNEL);
1349 1321
diff --git a/drivers/staging/wilc1000/wilc_wlan.h b/drivers/staging/wilc1000/wilc_wlan.h
index 7467188dbf2f..27667131de1a 100644
--- a/drivers/staging/wilc1000/wilc_wlan.h
+++ b/drivers/staging/wilc1000/wilc_wlan.h
@@ -212,7 +212,7 @@
212struct txq_entry_t { 212struct txq_entry_t {
213 struct list_head list; 213 struct list_head list;
214 int type; 214 int type;
215 int tcp_pending_ack_idx; 215 int ack_idx;
216 u8 *buffer; 216 u8 *buffer;
217 int buffer_size; 217 int buffer_size;
218 void *priv; 218 void *priv;
@@ -277,19 +277,19 @@ int wilc_wlan_cfg_set(struct wilc_vif *vif, int start, u16 wid, u8 *buffer,
277 u32 buffer_size, int commit, u32 drv_handler); 277 u32 buffer_size, int commit, u32 drv_handler);
278int wilc_wlan_cfg_get(struct wilc_vif *vif, int start, u16 wid, int commit, 278int wilc_wlan_cfg_get(struct wilc_vif *vif, int start, u16 wid, int commit,
279 u32 drv_handler); 279 u32 drv_handler);
280int wilc_wlan_cfg_get_val(u16 wid, u8 *buffer, u32 buffer_size); 280int wilc_wlan_cfg_get_val(struct wilc *wl, u16 wid, u8 *buffer,
281 u32 buffer_size);
281int wilc_wlan_txq_add_mgmt_pkt(struct net_device *dev, void *priv, u8 *buffer, 282int wilc_wlan_txq_add_mgmt_pkt(struct net_device *dev, void *priv, u8 *buffer,
282 u32 buffer_size, wilc_tx_complete_func_t func); 283 u32 buffer_size, wilc_tx_complete_func_t func);
283void wilc_chip_sleep_manually(struct wilc *wilc); 284void wilc_chip_sleep_manually(struct wilc *wilc);
284 285
285void wilc_enable_tcp_ack_filter(bool value); 286void wilc_enable_tcp_ack_filter(struct wilc_vif *vif, bool value);
286int wilc_wlan_get_num_conn_ifcs(struct wilc *wilc); 287int wilc_wlan_get_num_conn_ifcs(struct wilc *wilc);
287netdev_tx_t wilc_mac_xmit(struct sk_buff *skb, struct net_device *dev); 288netdev_tx_t wilc_mac_xmit(struct sk_buff *skb, struct net_device *dev);
288 289
289void wilc_wfi_p2p_rx(struct net_device *dev, u8 *buff, u32 size); 290void wilc_wfi_p2p_rx(struct net_device *dev, u8 *buff, u32 size);
290void host_wakeup_notify(struct wilc *wilc); 291void host_wakeup_notify(struct wilc *wilc);
291void host_sleep_notify(struct wilc *wilc); 292void host_sleep_notify(struct wilc *wilc);
292extern bool wilc_enable_ps;
293void chip_allow_sleep(struct wilc *wilc); 293void chip_allow_sleep(struct wilc *wilc);
294void chip_wakeup(struct wilc *wilc); 294void chip_wakeup(struct wilc *wilc);
295int wilc_send_config_pkt(struct wilc_vif *vif, u8 mode, struct wid *wids, 295int wilc_send_config_pkt(struct wilc_vif *vif, u8 mode, struct wid *wids,
diff --git a/drivers/staging/wilc1000/wilc_wlan_cfg.c b/drivers/staging/wilc1000/wilc_wlan_cfg.c
index 421576386ab4..faa001c75681 100644
--- a/drivers/staging/wilc1000/wilc_wlan_cfg.c
+++ b/drivers/staging/wilc1000/wilc_wlan_cfg.c
@@ -8,6 +8,7 @@
8#include "wilc_wlan.h" 8#include "wilc_wlan.h"
9#include "wilc_wlan_cfg.h" 9#include "wilc_wlan_cfg.h"
10#include "coreconfigurator.h" 10#include "coreconfigurator.h"
11#include "wilc_wfi_netdevice.h"
11 12
12enum cfg_cmd_type { 13enum cfg_cmd_type {
13 CFG_BYTE_CMD = 0, 14 CFG_BYTE_CMD = 0,
@@ -17,134 +18,30 @@ enum cfg_cmd_type {
17 CFG_BIN_CMD = 4 18 CFG_BIN_CMD = 4
18}; 19};
19 20
20struct wilc_mac_cfg { 21static const struct wilc_cfg_byte g_cfg_byte[] = {
21 int mac_status;
22 u8 mac_address[7];
23 u8 ip_address[5];
24 u8 bssid[7];
25 u8 ssid[34];
26 u8 firmware_version[129];
27 u8 supp_rate[24];
28 u8 wep_key[28];
29 u8 i_psk[66];
30 u8 hw_product_version[33];
31 u8 phyversion[17];
32 u8 supp_username[21];
33 u8 supp_password[64];
34 u8 assoc_req[256];
35 u8 assoc_rsp[256];
36 u8 firmware_info[8];
37 u8 scan_result[256];
38 u8 scan_result1[256];
39};
40
41static struct wilc_mac_cfg g_mac;
42
43static struct wilc_cfg_byte g_cfg_byte[] = {
44 {WID_BSS_TYPE, 0},
45 {WID_CURRENT_TX_RATE, 0},
46 {WID_CURRENT_CHANNEL, 0},
47 {WID_PREAMBLE, 0},
48 {WID_11G_OPERATING_MODE, 0},
49 {WID_STATUS, 0}, 22 {WID_STATUS, 0},
50 {WID_SCAN_TYPE, 0},
51 {WID_KEY_ID, 0},
52 {WID_QOS_ENABLE, 0},
53 {WID_POWER_MANAGEMENT, 0},
54 {WID_11I_MODE, 0},
55 {WID_AUTH_TYPE, 0},
56 {WID_SITE_SURVEY, 0},
57 {WID_LISTEN_INTERVAL, 0},
58 {WID_DTIM_PERIOD, 0},
59 {WID_ACK_POLICY, 0},
60 {WID_BCAST_SSID, 0},
61 {WID_REKEY_POLICY, 0},
62 {WID_SHORT_SLOT_ALLOWED, 0},
63 {WID_START_SCAN_REQ, 0},
64 {WID_RSSI, 0}, 23 {WID_RSSI, 0},
65 {WID_LINKSPEED, 0}, 24 {WID_LINKSPEED, 0},
66 {WID_AUTO_RX_SENSITIVITY, 0},
67 {WID_DATAFLOW_CONTROL, 0},
68 {WID_SCAN_FILTER, 0},
69 {WID_11N_PROT_MECH, 0},
70 {WID_11N_ERP_PROT_TYPE, 0},
71 {WID_11N_ENABLE, 0},
72 {WID_11N_OPERATING_MODE, 0},
73 {WID_11N_OBSS_NONHT_DETECTION, 0},
74 {WID_11N_HT_PROT_TYPE, 0},
75 {WID_11N_RIFS_PROT_ENABLE, 0},
76 {WID_11N_SMPS_MODE, 0},
77 {WID_11N_CURRENT_TX_MCS, 0},
78 {WID_11N_SHORT_GI_ENABLE, 0},
79 {WID_RIFS_MODE, 0},
80 {WID_TX_ABORT_CONFIG, 0},
81 {WID_11N_IMMEDIATE_BA_ENABLED, 0},
82 {WID_11N_TXOP_PROT_DISABLE, 0},
83 {WID_NIL, 0} 25 {WID_NIL, 0}
84}; 26};
85 27
86static struct wilc_cfg_hword g_cfg_hword[] = { 28static const struct wilc_cfg_hword g_cfg_hword[] = {
87 {WID_LINK_LOSS_THRESHOLD, 0},
88 {WID_RTS_THRESHOLD, 0},
89 {WID_FRAG_THRESHOLD, 0},
90 {WID_SHORT_RETRY_LIMIT, 0},
91 {WID_LONG_RETRY_LIMIT, 0},
92 {WID_BEACON_INTERVAL, 0},
93 {WID_RX_SENSE, 0},
94 {WID_ACTIVE_SCAN_TIME, 0},
95 {WID_PASSIVE_SCAN_TIME, 0},
96 {WID_SITE_SURVEY_SCAN_TIME, 0},
97 {WID_JOIN_START_TIMEOUT, 0},
98 {WID_AUTH_TIMEOUT, 0},
99 {WID_ASOC_TIMEOUT, 0},
100 {WID_11I_PROTOCOL_TIMEOUT, 0},
101 {WID_EAPOL_RESPONSE_TIMEOUT, 0},
102 {WID_11N_SIG_QUAL_VAL, 0},
103 {WID_CCA_THRESHOLD, 0},
104 {WID_NIL, 0} 29 {WID_NIL, 0}
105}; 30};
106 31
107static struct wilc_cfg_word g_cfg_word[] = { 32static const struct wilc_cfg_word g_cfg_word[] = {
108 {WID_FAILED_COUNT, 0}, 33 {WID_FAILED_COUNT, 0},
109 {WID_RETRY_COUNT, 0},
110 {WID_MULTIPLE_RETRY_COUNT, 0},
111 {WID_FRAME_DUPLICATE_COUNT, 0},
112 {WID_ACK_FAILURE_COUNT, 0},
113 {WID_RECEIVED_FRAGMENT_COUNT, 0}, 34 {WID_RECEIVED_FRAGMENT_COUNT, 0},
114 {WID_MCAST_RECEIVED_FRAME_COUNT, 0},
115 {WID_FCS_ERROR_COUNT, 0},
116 {WID_SUCCESS_FRAME_COUNT, 0}, 35 {WID_SUCCESS_FRAME_COUNT, 0},
117 {WID_TX_FRAGMENT_COUNT, 0},
118 {WID_TX_MULTICAST_FRAME_COUNT, 0},
119 {WID_RTS_SUCCESS_COUNT, 0},
120 {WID_RTS_FAILURE_COUNT, 0},
121 {WID_WEP_UNDECRYPTABLE_COUNT, 0},
122 {WID_REKEY_PERIOD, 0},
123 {WID_REKEY_PACKET_COUNT, 0},
124 {WID_HW_RX_COUNT, 0},
125 {WID_GET_INACTIVE_TIME, 0}, 36 {WID_GET_INACTIVE_TIME, 0},
126 {WID_NIL, 0} 37 {WID_NIL, 0}
127 38
128}; 39};
129 40
130static struct wilc_cfg_str g_cfg_str[] = { 41static const struct wilc_cfg_str g_cfg_str[] = {
131 {WID_SSID, g_mac.ssid}, /* 33 + 1 bytes */ 42 {WID_FIRMWARE_VERSION, NULL},
132 {WID_FIRMWARE_VERSION, g_mac.firmware_version}, 43 {WID_MAC_ADDR, NULL},
133 {WID_OPERATIONAL_RATE_SET, g_mac.supp_rate}, 44 {WID_ASSOC_RES_INFO, NULL},
134 {WID_BSSID, g_mac.bssid}, /* 6 bytes */
135 {WID_WEP_KEY_VALUE, g_mac.wep_key}, /* 27 bytes */
136 {WID_11I_PSK, g_mac.i_psk}, /* 65 bytes */
137 {WID_HARDWARE_VERSION, g_mac.hw_product_version},
138 {WID_MAC_ADDR, g_mac.mac_address},
139 {WID_PHY_VERSION, g_mac.phyversion},
140 {WID_SUPP_USERNAME, g_mac.supp_username},
141 {WID_SUPP_PASSWORD, g_mac.supp_password},
142 {WID_SITE_SURVEY_RESULTS, g_mac.scan_result},
143 {WID_SITE_SURVEY_RESULTS, g_mac.scan_result1},
144 {WID_ASSOC_REQ_INFO, g_mac.assoc_req},
145 {WID_ASSOC_RES_INFO, g_mac.assoc_rsp},
146 {WID_FIRMWARE_INFO, g_mac.firmware_version},
147 {WID_IP_ADDRESS, g_mac.ip_address},
148 {WID_NIL, NULL} 45 {WID_NIL, NULL}
149}; 46};
150 47
@@ -265,7 +162,7 @@ static int wilc_wlan_cfg_set_bin(u8 *frame, u32 offset, u16 id, u8 *b, u32 size)
265 ********************************************/ 162 ********************************************/
266 163
267#define GET_WID_TYPE(wid) (((wid) >> 12) & 0x7) 164#define GET_WID_TYPE(wid) (((wid) >> 12) & 0x7)
268static void wilc_wlan_parse_response_frame(u8 *info, int size) 165static void wilc_wlan_parse_response_frame(struct wilc *wl, u8 *info, int size)
269{ 166{
270 u16 wid; 167 u16 wid;
271 u32 len = 0, i = 0; 168 u32 len = 0, i = 0;
@@ -277,11 +174,11 @@ static void wilc_wlan_parse_response_frame(u8 *info, int size)
277 switch (GET_WID_TYPE(wid)) { 174 switch (GET_WID_TYPE(wid)) {
278 case WID_CHAR: 175 case WID_CHAR:
279 do { 176 do {
280 if (g_cfg_byte[i].id == WID_NIL) 177 if (wl->cfg.b[i].id == WID_NIL)
281 break; 178 break;
282 179
283 if (g_cfg_byte[i].id == wid) { 180 if (wl->cfg.b[i].id == wid) {
284 g_cfg_byte[i].val = info[4]; 181 wl->cfg.b[i].val = info[4];
285 break; 182 break;
286 } 183 }
287 i++; 184 i++;
@@ -291,12 +188,12 @@ static void wilc_wlan_parse_response_frame(u8 *info, int size)
291 188
292 case WID_SHORT: 189 case WID_SHORT:
293 do { 190 do {
294 if (g_cfg_hword[i].id == WID_NIL) 191 if (wl->cfg.hw[i].id == WID_NIL)
295 break; 192 break;
296 193
297 if (g_cfg_hword[i].id == wid) { 194 if (wl->cfg.hw[i].id == wid) {
298 g_cfg_hword[i].val = (info[4] | 195 wl->cfg.hw[i].val = (info[4] |
299 (info[5] << 8)); 196 (info[5] << 8));
300 break; 197 break;
301 } 198 }
302 i++; 199 i++;
@@ -306,14 +203,14 @@ static void wilc_wlan_parse_response_frame(u8 *info, int size)
306 203
307 case WID_INT: 204 case WID_INT:
308 do { 205 do {
309 if (g_cfg_word[i].id == WID_NIL) 206 if (wl->cfg.w[i].id == WID_NIL)
310 break; 207 break;
311 208
312 if (g_cfg_word[i].id == wid) { 209 if (wl->cfg.w[i].id == wid) {
313 g_cfg_word[i].val = (info[4] | 210 wl->cfg.w[i].val = (info[4] |
314 (info[5] << 8) | 211 (info[5] << 8) |
315 (info[6] << 16) | 212 (info[6] << 16) |
316 (info[7] << 24)); 213 (info[7] << 24));
317 break; 214 break;
318 } 215 }
319 i++; 216 i++;
@@ -323,17 +220,11 @@ static void wilc_wlan_parse_response_frame(u8 *info, int size)
323 220
324 case WID_STR: 221 case WID_STR:
325 do { 222 do {
326 if (g_cfg_str[i].id == WID_NIL) 223 if (wl->cfg.s[i].id == WID_NIL)
327 break; 224 break;
328 225
329 if (g_cfg_str[i].id == wid) { 226 if (wl->cfg.s[i].id == wid) {
330 if (wid == WID_SITE_SURVEY_RESULTS) { 227 memcpy(wl->cfg.s[i].str, &info[2],
331 static int toggle;
332
333 i += toggle;
334 toggle ^= 1;
335 }
336 memcpy(g_cfg_str[i].str, &info[2],
337 (info[2] + 2)); 228 (info[2] + 2));
338 break; 229 break;
339 } 230 }
@@ -350,22 +241,28 @@ static void wilc_wlan_parse_response_frame(u8 *info, int size)
350 } 241 }
351} 242}
352 243
353static int wilc_wlan_parse_info_frame(u8 *info, int size) 244static void wilc_wlan_parse_info_frame(struct wilc *wl, u8 *info)
354{ 245{
355 struct wilc_mac_cfg *pd = &g_mac;
356 u32 wid, len; 246 u32 wid, len;
357 int type = WILC_CFG_RSP_STATUS;
358 247
359 wid = info[0] | (info[1] << 8); 248 wid = info[0] | (info[1] << 8);
360 249
361 len = info[2]; 250 len = info[2];
362 251
363 if (len == 1 && wid == WID_STATUS) { 252 if (len == 1 && wid == WID_STATUS) {
364 pd->mac_status = info[3]; 253 int i = 0;
365 type = WILC_CFG_RSP_STATUS;
366 }
367 254
368 return type; 255 do {
256 if (wl->cfg.b[i].id == WID_NIL)
257 break;
258
259 if (wl->cfg.b[i].id == wid) {
260 wl->cfg.b[i].val = info[3];
261 break;
262 }
263 i++;
264 } while (1);
265 }
369} 266}
370 267
371/******************************************** 268/********************************************
@@ -424,24 +321,20 @@ int wilc_wlan_cfg_get_wid(u8 *frame, u32 offset, u16 id)
424 return 2; 321 return 2;
425} 322}
426 323
427int wilc_wlan_cfg_get_wid_value(u16 wid, u8 *buffer, u32 buffer_size) 324int wilc_wlan_cfg_get_wid_value(struct wilc *wl, u16 wid, u8 *buffer,
325 u32 buffer_size)
428{ 326{
429 u32 type = (wid >> 12) & 0xf; 327 u32 type = (wid >> 12) & 0xf;
430 int i, ret = 0; 328 int i, ret = 0;
431 329
432 if (wid == WID_STATUS) {
433 *((u32 *)buffer) = g_mac.mac_status;
434 return 4;
435 }
436
437 i = 0; 330 i = 0;
438 if (type == CFG_BYTE_CMD) { 331 if (type == CFG_BYTE_CMD) {
439 do { 332 do {
440 if (g_cfg_byte[i].id == WID_NIL) 333 if (wl->cfg.b[i].id == WID_NIL)
441 break; 334 break;
442 335
443 if (g_cfg_byte[i].id == wid) { 336 if (wl->cfg.b[i].id == wid) {
444 memcpy(buffer, &g_cfg_byte[i].val, 1); 337 memcpy(buffer, &wl->cfg.b[i].val, 1);
445 ret = 1; 338 ret = 1;
446 break; 339 break;
447 } 340 }
@@ -449,11 +342,11 @@ int wilc_wlan_cfg_get_wid_value(u16 wid, u8 *buffer, u32 buffer_size)
449 } while (1); 342 } while (1);
450 } else if (type == CFG_HWORD_CMD) { 343 } else if (type == CFG_HWORD_CMD) {
451 do { 344 do {
452 if (g_cfg_hword[i].id == WID_NIL) 345 if (wl->cfg.hw[i].id == WID_NIL)
453 break; 346 break;
454 347
455 if (g_cfg_hword[i].id == wid) { 348 if (wl->cfg.hw[i].id == wid) {
456 memcpy(buffer, &g_cfg_hword[i].val, 2); 349 memcpy(buffer, &wl->cfg.hw[i].val, 2);
457 ret = 2; 350 ret = 2;
458 break; 351 break;
459 } 352 }
@@ -461,11 +354,11 @@ int wilc_wlan_cfg_get_wid_value(u16 wid, u8 *buffer, u32 buffer_size)
461 } while (1); 354 } while (1);
462 } else if (type == CFG_WORD_CMD) { 355 } else if (type == CFG_WORD_CMD) {
463 do { 356 do {
464 if (g_cfg_word[i].id == WID_NIL) 357 if (wl->cfg.w[i].id == WID_NIL)
465 break; 358 break;
466 359
467 if (g_cfg_word[i].id == wid) { 360 if (wl->cfg.w[i].id == wid) {
468 memcpy(buffer, &g_cfg_word[i].val, 4); 361 memcpy(buffer, &wl->cfg.w[i].val, 4);
469 ret = 4; 362 ret = 4;
470 break; 363 break;
471 } 364 }
@@ -473,23 +366,17 @@ int wilc_wlan_cfg_get_wid_value(u16 wid, u8 *buffer, u32 buffer_size)
473 } while (1); 366 } while (1);
474 } else if (type == CFG_STR_CMD) { 367 } else if (type == CFG_STR_CMD) {
475 do { 368 do {
476 u32 id = g_cfg_str[i].id; 369 u32 id = wl->cfg.s[i].id;
477 370
478 if (id == WID_NIL) 371 if (id == WID_NIL)
479 break; 372 break;
480 373
481 if (id == wid) { 374 if (id == wid) {
482 u32 size = g_cfg_str[i].str[0] | 375 u32 size = (wl->cfg.s[i].str[0] |
483 (g_cfg_str[i].str[1] << 8); 376 (wl->cfg.s[i].str[1] << 8));
484 377
485 if (buffer_size >= size) { 378 if (buffer_size >= size) {
486 if (id == WID_SITE_SURVEY_RESULTS) { 379 memcpy(buffer, &wl->cfg.s[i].str[2],
487 static int toggle;
488
489 i += toggle;
490 toggle ^= 1;
491 }
492 memcpy(buffer, &g_cfg_str[i].str[2],
493 size); 380 size);
494 ret = size; 381 ret = size;
495 } 382 }
@@ -498,14 +385,12 @@ int wilc_wlan_cfg_get_wid_value(u16 wid, u8 *buffer, u32 buffer_size)
498 i++; 385 i++;
499 } while (1); 386 } while (1);
500 } 387 }
501
502 return ret; 388 return ret;
503} 389}
504 390
505int wilc_wlan_cfg_indicate_rx(struct wilc *wilc, u8 *frame, int size, 391void wilc_wlan_cfg_indicate_rx(struct wilc *wilc, u8 *frame, int size,
506 struct wilc_cfg_rsp *rsp) 392 struct wilc_cfg_rsp *rsp)
507{ 393{
508 int ret = 1;
509 u8 msg_type; 394 u8 msg_type;
510 u8 msg_id; 395 u8 msg_id;
511 396
@@ -513,6 +398,7 @@ int wilc_wlan_cfg_indicate_rx(struct wilc *wilc, u8 *frame, int size,
513 msg_id = frame[1]; /* seq no */ 398 msg_id = frame[1]; /* seq no */
514 frame += 4; 399 frame += 4;
515 size -= 4; 400 size -= 4;
401 rsp->type = 0;
516 402
517 /* 403 /*
518 * The valid types of response messages are 404 * The valid types of response messages are
@@ -523,13 +409,14 @@ int wilc_wlan_cfg_indicate_rx(struct wilc *wilc, u8 *frame, int size,
523 409
524 switch (msg_type) { 410 switch (msg_type) {
525 case 'R': 411 case 'R':
526 wilc_wlan_parse_response_frame(frame, size); 412 wilc_wlan_parse_response_frame(wilc, frame, size);
527 rsp->type = WILC_CFG_RSP; 413 rsp->type = WILC_CFG_RSP;
528 rsp->seq_no = msg_id; 414 rsp->seq_no = msg_id;
529 break; 415 break;
530 416
531 case 'I': 417 case 'I':
532 rsp->type = wilc_wlan_parse_info_frame(frame, size); 418 wilc_wlan_parse_info_frame(wilc, frame);
419 rsp->type = WILC_CFG_RSP_STATUS;
533 rsp->seq_no = msg_id; 420 rsp->seq_no = msg_id;
534 /*call host interface info parse as well*/ 421 /*call host interface info parse as well*/
535 wilc_gnrl_async_info_received(wilc, frame - 4, size + 4); 422 wilc_gnrl_async_info_received(wilc, frame - 4, size + 4);
@@ -537,7 +424,6 @@ int wilc_wlan_cfg_indicate_rx(struct wilc *wilc, u8 *frame, int size,
537 424
538 case 'N': 425 case 'N':
539 wilc_network_info_received(wilc, frame - 4, size + 4); 426 wilc_network_info_received(wilc, frame - 4, size + 4);
540 rsp->type = 0;
541 break; 427 break;
542 428
543 case 'S': 429 case 'S':
@@ -545,17 +431,67 @@ int wilc_wlan_cfg_indicate_rx(struct wilc *wilc, u8 *frame, int size,
545 break; 431 break;
546 432
547 default: 433 default:
548 rsp->type = 0;
549 rsp->seq_no = msg_id; 434 rsp->seq_no = msg_id;
550 ret = 0;
551 break; 435 break;
552 } 436 }
437}
553 438
554 return ret; 439int wilc_wlan_cfg_init(struct wilc *wl)
440{
441 struct wilc_cfg_str_vals *str_vals;
442 int i = 0;
443
444 wl->cfg.b = kmemdup(g_cfg_byte, sizeof(g_cfg_byte), GFP_KERNEL);
445 if (!wl->cfg.b)
446 return -ENOMEM;
447
448 wl->cfg.hw = kmemdup(g_cfg_hword, sizeof(g_cfg_hword), GFP_KERNEL);
449 if (!wl->cfg.hw)
450 goto out_b;
451
452 wl->cfg.w = kmemdup(g_cfg_word, sizeof(g_cfg_word), GFP_KERNEL);
453 if (!wl->cfg.w)
454 goto out_hw;
455
456 wl->cfg.s = kmemdup(g_cfg_str, sizeof(g_cfg_str), GFP_KERNEL);
457 if (!wl->cfg.s)
458 goto out_w;
459
460 str_vals = kzalloc(sizeof(*str_vals), GFP_KERNEL);
461 if (!str_vals)
462 goto out_s;
463
464 wl->cfg.str_vals = str_vals;
465 /* store the string cfg parameters */
466 wl->cfg.s[i].id = WID_FIRMWARE_VERSION;
467 wl->cfg.s[i].str = str_vals->firmware_version;
468 i++;
469 wl->cfg.s[i].id = WID_MAC_ADDR;
470 wl->cfg.s[i].str = str_vals->mac_address;
471 i++;
472 wl->cfg.s[i].id = WID_ASSOC_RES_INFO;
473 wl->cfg.s[i].str = str_vals->assoc_rsp;
474 i++;
475 wl->cfg.s[i].id = WID_NIL;
476 wl->cfg.s[i].str = NULL;
477 return 0;
478
479out_s:
480 kfree(wl->cfg.s);
481out_w:
482 kfree(wl->cfg.w);
483out_hw:
484 kfree(wl->cfg.hw);
485out_b:
486 kfree(wl->cfg.b);
487 return -ENOMEM;
555} 488}
556 489
557int wilc_wlan_cfg_init(void) 490void wilc_wlan_cfg_deinit(struct wilc *wl)
558{ 491{
559 memset((void *)&g_mac, 0, sizeof(struct wilc_mac_cfg)); 492 kfree(wl->cfg.b);
560 return 1; 493 kfree(wl->cfg.hw);
494 kfree(wl->cfg.w);
495 kfree(wl->cfg.s);
496 kfree(wl->cfg.str_vals);
561} 497}
diff --git a/drivers/staging/wilc1000/wilc_wlan_cfg.h b/drivers/staging/wilc1000/wilc_wlan_cfg.h
index 0c649d1f6f11..e5ca6cea0682 100644
--- a/drivers/staging/wilc1000/wilc_wlan_cfg.h
+++ b/drivers/staging/wilc1000/wilc_wlan_cfg.h
@@ -9,7 +9,7 @@
9 9
10struct wilc_cfg_byte { 10struct wilc_cfg_byte {
11 u16 id; 11 u16 id;
12 u16 val; 12 u8 val;
13}; 13};
14 14
15struct wilc_cfg_hword { 15struct wilc_cfg_hword {
@@ -27,12 +27,28 @@ struct wilc_cfg_str {
27 u8 *str; 27 u8 *str;
28}; 28};
29 29
30struct wilc_cfg_str_vals {
31 u8 mac_address[7];
32 u8 firmware_version[129];
33 u8 assoc_rsp[256];
34};
35
36struct wilc_cfg {
37 struct wilc_cfg_byte *b;
38 struct wilc_cfg_hword *hw;
39 struct wilc_cfg_word *w;
40 struct wilc_cfg_str *s;
41 struct wilc_cfg_str_vals *str_vals;
42};
43
30struct wilc; 44struct wilc;
31int wilc_wlan_cfg_set_wid(u8 *frame, u32 offset, u16 id, u8 *buf, int size); 45int wilc_wlan_cfg_set_wid(u8 *frame, u32 offset, u16 id, u8 *buf, int size);
32int wilc_wlan_cfg_get_wid(u8 *frame, u32 offset, u16 id); 46int wilc_wlan_cfg_get_wid(u8 *frame, u32 offset, u16 id);
33int wilc_wlan_cfg_get_wid_value(u16 wid, u8 *buffer, u32 buffer_size); 47int wilc_wlan_cfg_get_wid_value(struct wilc *wl, u16 wid, u8 *buffer,
34int wilc_wlan_cfg_indicate_rx(struct wilc *wilc, u8 *frame, int size, 48 u32 buffer_size);
35 struct wilc_cfg_rsp *rsp); 49void wilc_wlan_cfg_indicate_rx(struct wilc *wilc, u8 *frame, int size,
36int wilc_wlan_cfg_init(void); 50 struct wilc_cfg_rsp *rsp);
51int wilc_wlan_cfg_init(struct wilc *wl);
52void wilc_wlan_cfg_deinit(struct wilc *wl);
37 53
38#endif 54#endif
diff --git a/drivers/staging/wilc1000/wilc_wlan_if.h b/drivers/staging/wilc1000/wilc_wlan_if.h
index b81a73b9bd67..ce2066b74287 100644
--- a/drivers/staging/wilc1000/wilc_wlan_if.h
+++ b/drivers/staging/wilc1000/wilc_wlan_if.h
@@ -204,10 +204,6 @@ enum wid_type {
204 WID_STR = 3, 204 WID_STR = 3,
205 WID_BIN_DATA = 4, 205 WID_BIN_DATA = 4,
206 WID_BIN = 5, 206 WID_BIN = 5,
207 WID_IP = 6,
208 WID_ADR = 7,
209 WID_UNDEF = 8,
210 WID_TYPE_FORCE_32BIT = 0xFFFFFFFF
211}; 207};
212 208
213struct wid { 209struct wid {
diff --git a/drivers/staging/wlan-ng/cfg80211.c b/drivers/staging/wlan-ng/cfg80211.c
index d4cf09b11e33..47f2ee926a77 100644
--- a/drivers/staging/wlan-ng/cfg80211.c
+++ b/drivers/staging/wlan-ng/cfg80211.c
@@ -76,7 +76,7 @@ static int prism2_domibset_uint32(struct wlandevice *wlandev, u32 did, u32 data)
76 struct p80211item_uint32 *mibitem = 76 struct p80211item_uint32 *mibitem =
77 (struct p80211item_uint32 *)&msg.mibattribute.data; 77 (struct p80211item_uint32 *)&msg.mibattribute.data;
78 78
79 msg.msgcode = DIDmsg_dot11req_mibset; 79 msg.msgcode = DIDMSG_DOT11REQ_MIBSET;
80 mibitem->did = did; 80 mibitem->did = did;
81 mibitem->data = data; 81 mibitem->data = data;
82 82
@@ -90,7 +90,7 @@ static int prism2_domibset_pstr32(struct wlandevice *wlandev,
90 struct p80211item_pstr32 *mibitem = 90 struct p80211item_pstr32 *mibitem =
91 (struct p80211item_pstr32 *)&msg.mibattribute.data; 91 (struct p80211item_pstr32 *)&msg.mibattribute.data;
92 92
93 msg.msgcode = DIDmsg_dot11req_mibset; 93 msg.msgcode = DIDMSG_DOT11REQ_MIBSET;
94 mibitem->did = did; 94 mibitem->did = did;
95 mibitem->data.len = len; 95 mibitem->data.len = len;
96 memcpy(mibitem->data.data, data, len); 96 memcpy(mibitem->data.data, data, len);
@@ -129,7 +129,7 @@ static int prism2_change_virtual_intf(struct wiphy *wiphy,
129 129
130 /* Set Operation mode to the PORT TYPE RID */ 130 /* Set Operation mode to the PORT TYPE RID */
131 result = prism2_domibset_uint32(wlandev, 131 result = prism2_domibset_uint32(wlandev,
132 DIDmib_p2_p2Static_p2CnfPortType, 132 DIDMIB_P2_STATIC_CNFPORTTYPE,
133 data); 133 data);
134 134
135 if (result) 135 if (result)
@@ -158,12 +158,12 @@ static int prism2_add_key(struct wiphy *wiphy, struct net_device *dev,
158 } 158 }
159 159
160 if (prism2_domibset_uint32(wlandev, 160 if (prism2_domibset_uint32(wlandev,
161 DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID, 161 DIDMIB_DOT11SMT_PRIVACYTABLE_WEPDEFAULTKEYID,
162 key_index)) 162 key_index))
163 return -EFAULT; 163 return -EFAULT;
164 164
165 /* send key to driver */ 165 /* send key to driver */
166 did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(key_index + 1); 166 did = didmib_dot11smt_wepdefaultkeystable_key(key_index + 1);
167 167
168 if (prism2_domibset_pstr32(wlandev, did, params->key_len, params->key)) 168 if (prism2_domibset_pstr32(wlandev, did, params->key_len, params->key))
169 return -EFAULT; 169 return -EFAULT;
@@ -216,7 +216,7 @@ static int prism2_del_key(struct wiphy *wiphy, struct net_device *dev,
216 return -EINVAL; 216 return -EINVAL;
217 217
218 /* send key to driver */ 218 /* send key to driver */
219 did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(key_index + 1); 219 did = didmib_dot11smt_wepdefaultkeystable_key(key_index + 1);
220 result = prism2_domibset_pstr32(wlandev, did, 13, "0000000000000"); 220 result = prism2_domibset_pstr32(wlandev, did, 13, "0000000000000");
221 221
222 if (result) 222 if (result)
@@ -234,7 +234,7 @@ static int prism2_set_default_key(struct wiphy *wiphy, struct net_device *dev,
234 int result = 0; 234 int result = 0;
235 235
236 result = prism2_domibset_uint32(wlandev, 236 result = prism2_domibset_uint32(wlandev,
237 DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID, 237 DIDMIB_DOT11SMT_PRIVACYTABLE_WEPDEFAULTKEYID,
238 key_index); 238 key_index);
239 239
240 if (result) 240 if (result)
@@ -256,7 +256,7 @@ static int prism2_get_station(struct wiphy *wiphy, struct net_device *dev,
256 return -EOPNOTSUPP; 256 return -EOPNOTSUPP;
257 257
258 /* build request message */ 258 /* build request message */
259 quality.msgcode = DIDmsg_lnxreq_commsquality; 259 quality.msgcode = DIDMSG_LNXREQ_COMMSQUALITY;
260 quality.dbm.data = P80211ENUM_truth_true; 260 quality.dbm.data = P80211ENUM_truth_true;
261 quality.dbm.status = P80211ENUM_msgitem_status_data_ok; 261 quality.dbm.status = P80211ENUM_msgitem_status_data_ok;
262 262
@@ -311,7 +311,7 @@ static int prism2_scan(struct wiphy *wiphy,
311 priv->scan_request = request; 311 priv->scan_request = request;
312 312
313 memset(&msg1, 0x00, sizeof(msg1)); 313 memset(&msg1, 0x00, sizeof(msg1));
314 msg1.msgcode = DIDmsg_dot11req_scan; 314 msg1.msgcode = DIDMSG_DOT11REQ_SCAN;
315 msg1.bsstype.data = P80211ENUM_bsstype_any; 315 msg1.bsstype.data = P80211ENUM_bsstype_any;
316 316
317 memset(&msg1.bssid.data.data, 0xFF, sizeof(msg1.bssid.data.data)); 317 memset(&msg1.bssid.data.data, 0xFF, sizeof(msg1.bssid.data.data));
@@ -350,7 +350,7 @@ static int prism2_scan(struct wiphy *wiphy,
350 int freq; 350 int freq;
351 351
352 memset(&msg2, 0, sizeof(msg2)); 352 memset(&msg2, 0, sizeof(msg2));
353 msg2.msgcode = DIDmsg_dot11req_scan_results; 353 msg2.msgcode = DIDMSG_DOT11REQ_SCAN_RESULTS;
354 msg2.bssindex.data = i; 354 msg2.bssindex.data = i;
355 355
356 result = p80211req_dorequest(wlandev, (u8 *)&msg2); 356 result = p80211req_dorequest(wlandev, (u8 *)&msg2);
@@ -410,7 +410,7 @@ static int prism2_set_wiphy_params(struct wiphy *wiphy, u32 changed)
410 data = wiphy->rts_threshold; 410 data = wiphy->rts_threshold;
411 411
412 result = prism2_domibset_uint32(wlandev, 412 result = prism2_domibset_uint32(wlandev,
413 DIDmib_dot11mac_dot11OperationTable_dot11RTSThreshold, 413 DIDMIB_DOT11MAC_OPERATIONTABLE_RTSTHRESHOLD,
414 data); 414 data);
415 if (result) { 415 if (result) {
416 err = -EFAULT; 416 err = -EFAULT;
@@ -425,7 +425,7 @@ static int prism2_set_wiphy_params(struct wiphy *wiphy, u32 changed)
425 data = wiphy->frag_threshold; 425 data = wiphy->frag_threshold;
426 426
427 result = prism2_domibset_uint32(wlandev, 427 result = prism2_domibset_uint32(wlandev,
428 DIDmib_dot11mac_dot11OperationTable_dot11FragmentationThreshold, 428 DIDMIB_DOT11MAC_OPERATIONTABLE_FRAGMENTATIONTHRESHOLD,
429 data); 429 data);
430 if (result) { 430 if (result) {
431 err = -EFAULT; 431 err = -EFAULT;
@@ -455,7 +455,7 @@ static int prism2_connect(struct wiphy *wiphy, struct net_device *dev,
455 if (channel) { 455 if (channel) {
456 chan = ieee80211_frequency_to_channel(channel->center_freq); 456 chan = ieee80211_frequency_to_channel(channel->center_freq);
457 result = prism2_domibset_uint32(wlandev, 457 result = prism2_domibset_uint32(wlandev,
458 DIDmib_dot11phy_dot11PhyDSSSTable_dot11CurrentChannel, 458 DIDMIB_DOT11PHY_DSSSTABLE_CURRENTCHANNEL,
459 chan); 459 chan);
460 if (result) 460 if (result)
461 goto exit; 461 goto exit;
@@ -482,13 +482,13 @@ static int prism2_connect(struct wiphy *wiphy, struct net_device *dev,
482 } 482 }
483 483
484 result = prism2_domibset_uint32(wlandev, 484 result = prism2_domibset_uint32(wlandev,
485 DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID, 485 DIDMIB_DOT11SMT_PRIVACYTABLE_WEPDEFAULTKEYID,
486 sme->key_idx); 486 sme->key_idx);
487 if (result) 487 if (result)
488 goto exit; 488 goto exit;
489 489
490 /* send key to driver */ 490 /* send key to driver */
491 did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_key( 491 did = didmib_dot11smt_wepdefaultkeystable_key(
492 sme->key_idx + 1); 492 sme->key_idx + 1);
493 result = prism2_domibset_pstr32(wlandev, 493 result = prism2_domibset_pstr32(wlandev,
494 did, sme->key_len, 494 did, sme->key_len,
@@ -502,13 +502,13 @@ static int prism2_connect(struct wiphy *wiphy, struct net_device *dev,
502 * seems reasonable anyways 502 * seems reasonable anyways
503 */ 503 */
504 result = prism2_domibset_uint32(wlandev, 504 result = prism2_domibset_uint32(wlandev,
505 DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked, 505 DIDMIB_DOT11SMT_PRIVACYTABLE_PRIVACYINVOKED,
506 P80211ENUM_truth_true); 506 P80211ENUM_truth_true);
507 if (result) 507 if (result)
508 goto exit; 508 goto exit;
509 509
510 result = prism2_domibset_uint32(wlandev, 510 result = prism2_domibset_uint32(wlandev,
511 DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted, 511 DIDMIB_DOT11SMT_PRIVACYTABLE_EXCLUDEUNENCRYPTED,
512 P80211ENUM_truth_true); 512 P80211ENUM_truth_true);
513 if (result) 513 if (result)
514 goto exit; 514 goto exit;
@@ -518,13 +518,13 @@ static int prism2_connect(struct wiphy *wiphy, struct net_device *dev,
518 * and exclude unencrypted 518 * and exclude unencrypted
519 */ 519 */
520 result = prism2_domibset_uint32(wlandev, 520 result = prism2_domibset_uint32(wlandev,
521 DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked, 521 DIDMIB_DOT11SMT_PRIVACYTABLE_PRIVACYINVOKED,
522 P80211ENUM_truth_false); 522 P80211ENUM_truth_false);
523 if (result) 523 if (result)
524 goto exit; 524 goto exit;
525 525
526 result = prism2_domibset_uint32(wlandev, 526 result = prism2_domibset_uint32(wlandev,
527 DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted, 527 DIDMIB_DOT11SMT_PRIVACYTABLE_EXCLUDEUNENCRYPTED,
528 P80211ENUM_truth_false); 528 P80211ENUM_truth_false);
529 if (result) 529 if (result)
530 goto exit; 530 goto exit;
@@ -533,7 +533,7 @@ static int prism2_connect(struct wiphy *wiphy, struct net_device *dev,
533 /* Now do the actual join. Note there is no way that I can 533 /* Now do the actual join. Note there is no way that I can
534 * see to request a specific bssid 534 * see to request a specific bssid
535 */ 535 */
536 msg_join.msgcode = DIDmsg_lnxreq_autojoin; 536 msg_join.msgcode = DIDMSG_LNXREQ_AUTOJOIN;
537 537
538 memcpy(msg_join.ssid.data.data, sme->ssid, length); 538 memcpy(msg_join.ssid.data.data, sme->ssid, length);
539 msg_join.ssid.data.len = length; 539 msg_join.ssid.data.len = length;
@@ -556,7 +556,7 @@ static int prism2_disconnect(struct wiphy *wiphy, struct net_device *dev,
556 int err = 0; 556 int err = 0;
557 557
558 /* Do a join, with a bogus ssid. Thats the only way I can think of */ 558 /* Do a join, with a bogus ssid. Thats the only way I can think of */
559 msg_join.msgcode = DIDmsg_lnxreq_autojoin; 559 msg_join.msgcode = DIDMSG_LNXREQ_AUTOJOIN;
560 560
561 memcpy(msg_join.ssid.data.data, "---", 3); 561 memcpy(msg_join.ssid.data.data, "---", 3);
562 msg_join.ssid.data.len = 3; 562 msg_join.ssid.data.len = 3;
@@ -595,7 +595,7 @@ static int prism2_set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
595 data = MBM_TO_DBM(mbm); 595 data = MBM_TO_DBM(mbm);
596 596
597 result = prism2_domibset_uint32(wlandev, 597 result = prism2_domibset_uint32(wlandev,
598 DIDmib_dot11phy_dot11PhyTxPowerTable_dot11CurrentTxPowerLevel, 598 DIDMIB_DOT11PHY_TXPOWERTABLE_CURRENTTXPOWERLEVEL,
599 data); 599 data);
600 600
601 if (result) { 601 if (result) {
@@ -618,9 +618,8 @@ static int prism2_get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
618 int err = 0; 618 int err = 0;
619 619
620 mibitem = (struct p80211item_uint32 *)&msg.mibattribute.data; 620 mibitem = (struct p80211item_uint32 *)&msg.mibattribute.data;
621 msg.msgcode = DIDmsg_dot11req_mibget; 621 msg.msgcode = DIDMSG_DOT11REQ_MIBGET;
622 mibitem->did = 622 mibitem->did = DIDMIB_DOT11PHY_TXPOWERTABLE_CURRENTTXPOWERLEVEL;
623 DIDmib_dot11phy_dot11PhyTxPowerTable_dot11CurrentTxPowerLevel;
624 623
625 result = p80211req_dorequest(wlandev, (u8 *)&msg); 624 result = p80211req_dorequest(wlandev, (u8 *)&msg);
626 625
diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
index 16f7dd266e3b..6261881e9bcd 100644
--- a/drivers/staging/wlan-ng/hfa384x_usb.c
+++ b/drivers/staging/wlan-ng/hfa384x_usb.c
@@ -3605,36 +3605,32 @@ static void hfa384x_usbout_callback(struct urb *urb)
3605 prism2sta_ev_alloc(wlandev); 3605 prism2sta_ev_alloc(wlandev);
3606 break; 3606 break;
3607 3607
3608 case -EPIPE: 3608 case -EPIPE: {
3609 { 3609 struct hfa384x *hw = wlandev->priv;
3610 struct hfa384x *hw = wlandev->priv;
3611 3610
3612 netdev_warn(hw->wlandev->netdev, 3611 netdev_warn(hw->wlandev->netdev,
3613 "%s tx pipe stalled: requesting reset\n", 3612 "%s tx pipe stalled: requesting reset\n",
3614 wlandev->netdev->name); 3613 wlandev->netdev->name);
3615 if (!test_and_set_bit 3614 if (!test_and_set_bit(WORK_TX_HALT, &hw->usb_flags))
3616 (WORK_TX_HALT, &hw->usb_flags)) 3615 schedule_work(&hw->usb_work);
3617 schedule_work(&hw->usb_work); 3616 wlandev->netdev->stats.tx_errors++;
3618 wlandev->netdev->stats.tx_errors++; 3617 break;
3619 break; 3618 }
3620 }
3621 3619
3622 case -EPROTO: 3620 case -EPROTO:
3623 case -ETIMEDOUT: 3621 case -ETIMEDOUT:
3624 case -EILSEQ: 3622 case -EILSEQ: {
3625 { 3623 struct hfa384x *hw = wlandev->priv;
3626 struct hfa384x *hw = wlandev->priv; 3624
3627 3625 if (!test_and_set_bit(THROTTLE_TX, &hw->usb_flags) &&
3628 if (!test_and_set_bit 3626 !timer_pending(&hw->throttle)) {
3629 (THROTTLE_TX, &hw->usb_flags) && 3627 mod_timer(&hw->throttle,
3630 !timer_pending(&hw->throttle)) { 3628 jiffies + THROTTLE_JIFFIES);
3631 mod_timer(&hw->throttle,
3632 jiffies + THROTTLE_JIFFIES);
3633 }
3634 wlandev->netdev->stats.tx_errors++;
3635 netif_stop_queue(wlandev->netdev);
3636 break;
3637 } 3629 }
3630 wlandev->netdev->stats.tx_errors++;
3631 netif_stop_queue(wlandev->netdev);
3632 break;
3633 }
3638 3634
3639 case -ENOENT: 3635 case -ENOENT:
3640 case -ESHUTDOWN: 3636 case -ESHUTDOWN:
diff --git a/drivers/staging/wlan-ng/p80211conv.c b/drivers/staging/wlan-ng/p80211conv.c
index 91debcf20646..0ff5fda81b05 100644
--- a/drivers/staging/wlan-ng/p80211conv.c
+++ b/drivers/staging/wlan-ng/p80211conv.c
@@ -430,7 +430,7 @@ int skb_p80211_to_ether(struct wlandevice *wlandev, u32 ethconv,
430 /* A bogus length ethfrm has been sent. */ 430 /* A bogus length ethfrm has been sent. */
431 /* Is someone trying an oflow attack? */ 431 /* Is someone trying an oflow attack? */
432 netdev_err(netdev, "DIXII frame too large (%ld > %d)\n", 432 netdev_err(netdev, "DIXII frame too large (%ld > %d)\n",
433 (long int)(payload_length - 433 (long)(payload_length -
434 sizeof(struct wlan_llc) - 434 sizeof(struct wlan_llc) -
435 sizeof(struct wlan_snap)), netdev->mtu); 435 sizeof(struct wlan_snap)), netdev->mtu);
436 return 1; 436 return 1;
diff --git a/drivers/staging/wlan-ng/p80211metadef.h b/drivers/staging/wlan-ng/p80211metadef.h
index e63b4b557d0a..1b91b64c12ed 100644
--- a/drivers/staging/wlan-ng/p80211metadef.h
+++ b/drivers/staging/wlan-ng/p80211metadef.h
@@ -1,6 +1,5 @@
1/* SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) */ 1/* SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) */
2/* This file is GENERATED AUTOMATICALLY. DO NOT EDIT OR MODIFY. 2/* --------------------------------------------------------------------
3 * --------------------------------------------------------------------
4 * 3 *
5 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved. 4 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
6 * -------------------------------------------------------------------- 5 * --------------------------------------------------------------------
@@ -48,201 +47,201 @@
48#ifndef _P80211MKMETADEF_H 47#ifndef _P80211MKMETADEF_H
49#define _P80211MKMETADEF_H 48#define _P80211MKMETADEF_H
50 49
51#define DIDmsg_dot11req_mibget \ 50#define DIDMSG_DOT11REQ_MIBGET \
52 (P80211DID_MKSECTION(1) | \ 51 (P80211DID_MKSECTION(1) | \
53 P80211DID_MKGROUP(1)) 52 P80211DID_MKGROUP(1))
54#define DIDmsg_dot11req_mibget_mibattribute \ 53#define DIDMSG_DOT11REQ_MIBGET_MIBATTRIBUTE \
55 (P80211DID_MKSECTION(1) | \ 54 (P80211DID_MKSECTION(1) | \
56 P80211DID_MKGROUP(1) | \ 55 P80211DID_MKGROUP(1) | \
57 P80211DID_MKITEM(1) | 0x00000000) 56 P80211DID_MKITEM(1) | 0x00000000)
58#define DIDmsg_dot11req_mibget_resultcode \ 57#define DIDMSG_DOT11REQ_MIBGET_RESULTCODE \
59 (P80211DID_MKSECTION(1) | \ 58 (P80211DID_MKSECTION(1) | \
60 P80211DID_MKGROUP(1) | \ 59 P80211DID_MKGROUP(1) | \
61 P80211DID_MKITEM(2) | 0x00000000) 60 P80211DID_MKITEM(2) | 0x00000000)
62#define DIDmsg_dot11req_mibset \ 61#define DIDMSG_DOT11REQ_MIBSET \
63 (P80211DID_MKSECTION(1) | \ 62 (P80211DID_MKSECTION(1) | \
64 P80211DID_MKGROUP(2)) 63 P80211DID_MKGROUP(2))
65#define DIDmsg_dot11req_mibset_mibattribute \ 64#define DIDMSG_DOT11REQ_MIBSET_MIBATTRIBUTE \
66 (P80211DID_MKSECTION(1) | \ 65 (P80211DID_MKSECTION(1) | \
67 P80211DID_MKGROUP(2) | \ 66 P80211DID_MKGROUP(2) | \
68 P80211DID_MKITEM(1) | 0x00000000) 67 P80211DID_MKITEM(1) | 0x00000000)
69#define DIDmsg_dot11req_mibset_resultcode \ 68#define DIDMSG_DOT11REQ_MIBSET_RESULTCODE \
70 (P80211DID_MKSECTION(1) | \ 69 (P80211DID_MKSECTION(1) | \
71 P80211DID_MKGROUP(2) | \ 70 P80211DID_MKGROUP(2) | \
72 P80211DID_MKITEM(2) | 0x00000000) 71 P80211DID_MKITEM(2) | 0x00000000)
73#define DIDmsg_dot11req_scan \ 72#define DIDMSG_DOT11REQ_SCAN \
74 (P80211DID_MKSECTION(1) | \ 73 (P80211DID_MKSECTION(1) | \
75 P80211DID_MKGROUP(4)) 74 P80211DID_MKGROUP(4))
76#define DIDmsg_dot11req_scan_results \ 75#define DIDMSG_DOT11REQ_SCAN_RESULTS \
77 (P80211DID_MKSECTION(1) | \ 76 (P80211DID_MKSECTION(1) | \
78 P80211DID_MKGROUP(5)) 77 P80211DID_MKGROUP(5))
79#define DIDmsg_dot11req_start \ 78#define DIDMSG_DOT11REQ_START \
80 (P80211DID_MKSECTION(1) | \ 79 (P80211DID_MKSECTION(1) | \
81 P80211DID_MKGROUP(13)) 80 P80211DID_MKGROUP(13))
82#define DIDmsg_dot11ind_authenticate \ 81#define DIDMSG_DOT11IND_AUTHENTICATE \
83 (P80211DID_MKSECTION(2) | \ 82 (P80211DID_MKSECTION(2) | \
84 P80211DID_MKGROUP(1)) 83 P80211DID_MKGROUP(1))
85#define DIDmsg_dot11ind_associate \ 84#define DIDMSG_DOT11IND_ASSOCIATE \
86 (P80211DID_MKSECTION(2) | \ 85 (P80211DID_MKSECTION(2) | \
87 P80211DID_MKGROUP(3)) 86 P80211DID_MKGROUP(3))
88#define DIDmsg_lnxreq_ifstate \ 87#define DIDMSG_LNXREQ_IFSTATE \
89 (P80211DID_MKSECTION(3) | \ 88 (P80211DID_MKSECTION(3) | \
90 P80211DID_MKGROUP(1)) 89 P80211DID_MKGROUP(1))
91#define DIDmsg_lnxreq_wlansniff \ 90#define DIDMSG_LNXREQ_WLANSNIFF \
92 (P80211DID_MKSECTION(3) | \ 91 (P80211DID_MKSECTION(3) | \
93 P80211DID_MKGROUP(2)) 92 P80211DID_MKGROUP(2))
94#define DIDmsg_lnxreq_hostwep \ 93#define DIDMSG_LNXREQ_HOSTWEP \
95 (P80211DID_MKSECTION(3) | \ 94 (P80211DID_MKSECTION(3) | \
96 P80211DID_MKGROUP(3)) 95 P80211DID_MKGROUP(3))
97#define DIDmsg_lnxreq_commsquality \ 96#define DIDMSG_LNXREQ_COMMSQUALITY \
98 (P80211DID_MKSECTION(3) | \ 97 (P80211DID_MKSECTION(3) | \
99 P80211DID_MKGROUP(4)) 98 P80211DID_MKGROUP(4))
100#define DIDmsg_lnxreq_autojoin \ 99#define DIDMSG_LNXREQ_AUTOJOIN \
101 (P80211DID_MKSECTION(3) | \ 100 (P80211DID_MKSECTION(3) | \
102 P80211DID_MKGROUP(5)) 101 P80211DID_MKGROUP(5))
103#define DIDmsg_p2req_readpda \ 102#define DIDMSG_P2REQ_READPDA \
104 (P80211DID_MKSECTION(5) | \ 103 (P80211DID_MKSECTION(5) | \
105 P80211DID_MKGROUP(2)) 104 P80211DID_MKGROUP(2))
106#define DIDmsg_p2req_readpda_pda \ 105#define DIDMSG_P2REQ_READPDA_PDA \
107 (P80211DID_MKSECTION(5) | \ 106 (P80211DID_MKSECTION(5) | \
108 P80211DID_MKGROUP(2) | \ 107 P80211DID_MKGROUP(2) | \
109 P80211DID_MKITEM(1) | 0x00000000) 108 P80211DID_MKITEM(1) | 0x00000000)
110#define DIDmsg_p2req_readpda_resultcode \ 109#define DIDMSG_P2REQ_READPDA_RESULTCODE \
111 (P80211DID_MKSECTION(5) | \ 110 (P80211DID_MKSECTION(5) | \
112 P80211DID_MKGROUP(2) | \ 111 P80211DID_MKGROUP(2) | \
113 P80211DID_MKITEM(2) | 0x00000000) 112 P80211DID_MKITEM(2) | 0x00000000)
114#define DIDmsg_p2req_ramdl_state \ 113#define DIDMSG_P2REQ_RAMDL_STATE \
115 (P80211DID_MKSECTION(5) | \ 114 (P80211DID_MKSECTION(5) | \
116 P80211DID_MKGROUP(11)) 115 P80211DID_MKGROUP(11))
117#define DIDmsg_p2req_ramdl_state_enable \ 116#define DIDMSG_P2REQ_RAMDL_STATE_ENABLE \
118 (P80211DID_MKSECTION(5) | \ 117 (P80211DID_MKSECTION(5) | \
119 P80211DID_MKGROUP(11) | \ 118 P80211DID_MKGROUP(11) | \
120 P80211DID_MKITEM(1) | 0x00000000) 119 P80211DID_MKITEM(1) | 0x00000000)
121#define DIDmsg_p2req_ramdl_state_exeaddr \ 120#define DIDMSG_P2REQ_RAMDL_STATE_EXEADDR \
122 (P80211DID_MKSECTION(5) | \ 121 (P80211DID_MKSECTION(5) | \
123 P80211DID_MKGROUP(11) | \ 122 P80211DID_MKGROUP(11) | \
124 P80211DID_MKITEM(2) | 0x00000000) 123 P80211DID_MKITEM(2) | 0x00000000)
125#define DIDmsg_p2req_ramdl_state_resultcode \ 124#define DIDMSG_P2REQ_RAMDL_STATE_RESULTCODE \
126 (P80211DID_MKSECTION(5) | \ 125 (P80211DID_MKSECTION(5) | \
127 P80211DID_MKGROUP(11) | \ 126 P80211DID_MKGROUP(11) | \
128 P80211DID_MKITEM(3) | 0x00000000) 127 P80211DID_MKITEM(3) | 0x00000000)
129#define DIDmsg_p2req_ramdl_write \ 128#define DIDMSG_P2REQ_RAMDL_WRITE \
130 (P80211DID_MKSECTION(5) | \ 129 (P80211DID_MKSECTION(5) | \
131 P80211DID_MKGROUP(12)) 130 P80211DID_MKGROUP(12))
132#define DIDmsg_p2req_ramdl_write_addr \ 131#define DIDMSG_P2REQ_RAMDL_WRITE_ADDR \
133 (P80211DID_MKSECTION(5) | \ 132 (P80211DID_MKSECTION(5) | \
134 P80211DID_MKGROUP(12) | \ 133 P80211DID_MKGROUP(12) | \
135 P80211DID_MKITEM(1) | 0x00000000) 134 P80211DID_MKITEM(1) | 0x00000000)
136#define DIDmsg_p2req_ramdl_write_len \ 135#define DIDMSG_P2REQ_RAMDL_WRITE_LEN \
137 (P80211DID_MKSECTION(5) | \ 136 (P80211DID_MKSECTION(5) | \
138 P80211DID_MKGROUP(12) | \ 137 P80211DID_MKGROUP(12) | \
139 P80211DID_MKITEM(2) | 0x00000000) 138 P80211DID_MKITEM(2) | 0x00000000)
140#define DIDmsg_p2req_ramdl_write_data \ 139#define DIDMSG_P2REQ_RAMDL_WRITE_DATA \
141 (P80211DID_MKSECTION(5) | \ 140 (P80211DID_MKSECTION(5) | \
142 P80211DID_MKGROUP(12) | \ 141 P80211DID_MKGROUP(12) | \
143 P80211DID_MKITEM(3) | 0x00000000) 142 P80211DID_MKITEM(3) | 0x00000000)
144#define DIDmsg_p2req_ramdl_write_resultcode \ 143#define DIDMSG_P2REQ_RAMDL_WRITE_RESULTCODE \
145 (P80211DID_MKSECTION(5) | \ 144 (P80211DID_MKSECTION(5) | \
146 P80211DID_MKGROUP(12) | \ 145 P80211DID_MKGROUP(12) | \
147 P80211DID_MKITEM(4) | 0x00000000) 146 P80211DID_MKITEM(4) | 0x00000000)
148#define DIDmsg_p2req_flashdl_state \ 147#define DIDMSG_P2REQ_FLASHDL_STATE \
149 (P80211DID_MKSECTION(5) | \ 148 (P80211DID_MKSECTION(5) | \
150 P80211DID_MKGROUP(13)) 149 P80211DID_MKGROUP(13))
151#define DIDmsg_p2req_flashdl_write \ 150#define DIDMSG_P2REQ_FLASHDL_WRITE \
152 (P80211DID_MKSECTION(5) | \ 151 (P80211DID_MKSECTION(5) | \
153 P80211DID_MKGROUP(14)) 152 P80211DID_MKGROUP(14))
154#define DIDmib_cat_dot11smt \ 153#define DIDMIB_CAT_DOT11SMT \
155 P80211DID_MKSECTION(1) 154 P80211DID_MKSECTION(1)
156#define DIDmib_dot11smt_dot11WEPDefaultKeysTable \ 155#define DIDMIB_DOT11SMT_WEPDEFAULTKEYSTABLE \
157 (P80211DID_MKSECTION(1) | \ 156 (P80211DID_MKSECTION(1) | \
158 P80211DID_MKGROUP(4)) 157 P80211DID_MKGROUP(4))
159#define DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(_i) \ 158#define didmib_dot11smt_wepdefaultkeystable_key(_i) \
160 (DIDmib_dot11smt_dot11WEPDefaultKeysTable | \ 159 (DIDMIB_DOT11SMT_WEPDEFAULTKEYSTABLE | \
161 P80211DID_MKITEM(_i) | 0x0c000000) 160 P80211DID_MKITEM(_i) | 0x0c000000)
162#define DIDmib_dot11smt_dot11PrivacyTable \ 161#define DIDMIB_DOT11SMT_PRIVACYTABLE \
163 (P80211DID_MKSECTION(1) | \ 162 (P80211DID_MKSECTION(1) | \
164 P80211DID_MKGROUP(6)) 163 P80211DID_MKGROUP(6))
165#define DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked \ 164#define DIDMIB_DOT11SMT_PRIVACYTABLE_PRIVACYINVOKED \
166 (P80211DID_MKSECTION(1) | \ 165 (P80211DID_MKSECTION(1) | \
167 P80211DID_MKGROUP(6) | \ 166 P80211DID_MKGROUP(6) | \
168 P80211DID_MKITEM(1) | 0x18000000) 167 P80211DID_MKITEM(1) | 0x18000000)
169#define DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID \ 168#define DIDMIB_DOT11SMT_PRIVACYTABLE_WEPDEFAULTKEYID \
170 (P80211DID_MKSECTION(1) | \ 169 (P80211DID_MKSECTION(1) | \
171 P80211DID_MKGROUP(6) | \ 170 P80211DID_MKGROUP(6) | \
172 P80211DID_MKITEM(2) | 0x18000000) 171 P80211DID_MKITEM(2) | 0x18000000)
173#define DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted \ 172#define DIDMIB_DOT11SMT_PRIVACYTABLE_EXCLUDEUNENCRYPTED \
174 (P80211DID_MKSECTION(1) | \ 173 (P80211DID_MKSECTION(1) | \
175 P80211DID_MKGROUP(6) | \ 174 P80211DID_MKGROUP(6) | \
176 P80211DID_MKITEM(4) | 0x18000000) 175 P80211DID_MKITEM(4) | 0x18000000)
177#define DIDmib_dot11mac_dot11OperationTable \ 176#define DIDMIB_DOT11MAC_OPERATIONTABLE \
178 (P80211DID_MKSECTION(2) | \ 177 (P80211DID_MKSECTION(2) | \
179 P80211DID_MKGROUP(1)) 178 P80211DID_MKGROUP(1))
180#define DIDmib_dot11mac_dot11OperationTable_dot11MACAddress \ 179#define DIDMIB_DOT11MAC_OPERATIONTABLE_MACADDRESS \
181 (P80211DID_MKSECTION(2) | \ 180 (P80211DID_MKSECTION(2) | \
182 P80211DID_MKGROUP(1) | \ 181 P80211DID_MKGROUP(1) | \
183 P80211DID_MKITEM(1) | 0x18000000) 182 P80211DID_MKITEM(1) | 0x18000000)
184#define DIDmib_dot11mac_dot11OperationTable_dot11RTSThreshold \ 183#define DIDMIB_DOT11MAC_OPERATIONTABLE_RTSTHRESHOLD \
185 (P80211DID_MKSECTION(2) | \ 184 (P80211DID_MKSECTION(2) | \
186 P80211DID_MKGROUP(1) | \ 185 P80211DID_MKGROUP(1) | \
187 P80211DID_MKITEM(2) | 0x18000000) 186 P80211DID_MKITEM(2) | 0x18000000)
188#define DIDmib_dot11mac_dot11OperationTable_dot11ShortRetryLimit \ 187#define DIDMIB_DOT11MAC_OPERATIONTABLE_SHORTRETRYLIMIT \
189 (P80211DID_MKSECTION(2) | \ 188 (P80211DID_MKSECTION(2) | \
190 P80211DID_MKGROUP(1) | \ 189 P80211DID_MKGROUP(1) | \
191 P80211DID_MKITEM(3) | 0x10000000) 190 P80211DID_MKITEM(3) | 0x10000000)
192#define DIDmib_dot11mac_dot11OperationTable_dot11LongRetryLimit \ 191#define DIDMIB_DOT11MAC_OPERATIONTABLE_LONGRETRYLIMIT \
193 (P80211DID_MKSECTION(2) | \ 192 (P80211DID_MKSECTION(2) | \
194 P80211DID_MKGROUP(1) | \ 193 P80211DID_MKGROUP(1) | \
195 P80211DID_MKITEM(4) | 0x10000000) 194 P80211DID_MKITEM(4) | 0x10000000)
196#define DIDmib_dot11mac_dot11OperationTable_dot11FragmentationThreshold \ 195#define DIDMIB_DOT11MAC_OPERATIONTABLE_FRAGMENTATIONTHRESHOLD \
197 (P80211DID_MKSECTION(2) | \ 196 (P80211DID_MKSECTION(2) | \
198 P80211DID_MKGROUP(1) | \ 197 P80211DID_MKGROUP(1) | \
199 P80211DID_MKITEM(5) | 0x18000000) 198 P80211DID_MKITEM(5) | 0x18000000)
200#define DIDmib_dot11mac_dot11OperationTable_dot11MaxTransmitMSDULifetime \ 199#define DIDMIB_DOT11MAC_OPERATIONTABLE_MAXTRANSMITMSDULIFETIME \
201 (P80211DID_MKSECTION(2) | \ 200 (P80211DID_MKSECTION(2) | \
202 P80211DID_MKGROUP(1) | \ 201 P80211DID_MKGROUP(1) | \
203 P80211DID_MKITEM(6) | 0x10000000) 202 P80211DID_MKITEM(6) | 0x10000000)
204#define DIDmib_cat_dot11phy \ 203#define DIDMIB_CAT_DOT11PHY \
205 P80211DID_MKSECTION(3) 204 P80211DID_MKSECTION(3)
206#define DIDmib_dot11phy_dot11PhyOperationTable \ 205#define DIDMIB_DOT11PHY_OPERATIONTABLE \
207 (P80211DID_MKSECTION(3) | \ 206 (P80211DID_MKSECTION(3) | \
208 P80211DID_MKGROUP(1)) 207 P80211DID_MKGROUP(1))
209#define DIDmib_dot11phy_dot11PhyTxPowerTable_dot11CurrentTxPowerLevel \ 208#define DIDMIB_DOT11PHY_TXPOWERTABLE_CURRENTTXPOWERLEVEL \
210 (P80211DID_MKSECTION(3) | \ 209 (P80211DID_MKSECTION(3) | \
211 P80211DID_MKGROUP(3) | \ 210 P80211DID_MKGROUP(3) | \
212 P80211DID_MKITEM(10) | 0x18000000) 211 P80211DID_MKITEM(10) | 0x18000000)
213#define DIDmib_dot11phy_dot11PhyDSSSTable \ 212#define DIDMIB_DOT11PHY_DSSSTABLE \
214 (P80211DID_MKSECTION(3) | \ 213 (P80211DID_MKSECTION(3) | \
215 P80211DID_MKGROUP(5)) 214 P80211DID_MKGROUP(5))
216#define DIDmib_dot11phy_dot11PhyDSSSTable_dot11CurrentChannel \ 215#define DIDMIB_DOT11PHY_DSSSTABLE_CURRENTCHANNEL \
217 (P80211DID_MKSECTION(3) | \ 216 (P80211DID_MKSECTION(3) | \
218 P80211DID_MKGROUP(5) | \ 217 P80211DID_MKGROUP(5) | \
219 P80211DID_MKITEM(1) | 0x10000000) 218 P80211DID_MKITEM(1) | 0x10000000)
220#define DIDmib_cat_lnx \ 219#define DIDMIB_CAT_LNX \
221 P80211DID_MKSECTION(4) 220 P80211DID_MKSECTION(4)
222#define DIDmib_lnx_lnxConfigTable \ 221#define DIDMIB_LNX_CONFIGTABLE \
223 (P80211DID_MKSECTION(4) | \ 222 (P80211DID_MKSECTION(4) | \
224 P80211DID_MKGROUP(1)) 223 P80211DID_MKGROUP(1))
225#define DIDmib_lnx_lnxConfigTable_lnxRSNAIE \ 224#define DIDMIB_LNX_CONFIGTABLE_RSNAIE \
226 (P80211DID_MKSECTION(4) | \ 225 (P80211DID_MKSECTION(4) | \
227 P80211DID_MKGROUP(1) | \ 226 P80211DID_MKGROUP(1) | \
228 P80211DID_MKITEM(1) | 0x18000000) 227 P80211DID_MKITEM(1) | 0x18000000)
229#define DIDmib_cat_p2 \ 228#define DIDMIB_CAT_P2 \
230 P80211DID_MKSECTION(5) 229 P80211DID_MKSECTION(5)
231#define DIDmib_p2_p2Static \ 230#define DIDMIB_P2_STATIC \
232 (P80211DID_MKSECTION(5) | \ 231 (P80211DID_MKSECTION(5) | \
233 P80211DID_MKGROUP(2)) 232 P80211DID_MKGROUP(2))
234#define DIDmib_p2_p2Static_p2CnfPortType \ 233#define DIDMIB_P2_STATIC_CNFPORTTYPE \
235 (P80211DID_MKSECTION(5) | \ 234 (P80211DID_MKSECTION(5) | \
236 P80211DID_MKGROUP(2) | \ 235 P80211DID_MKGROUP(2) | \
237 P80211DID_MKITEM(1) | 0x18000000) 236 P80211DID_MKITEM(1) | 0x18000000)
238#define DIDmib_p2_p2NIC_p2PRISupRange \ 237#define DIDMIB_P2_NIC_PRISUPRANGE \
239 (P80211DID_MKSECTION(5) | \ 238 (P80211DID_MKSECTION(5) | \
240 P80211DID_MKGROUP(5) | \ 239 P80211DID_MKGROUP(5) | \
241 P80211DID_MKITEM(6) | 0x10000000) 240 P80211DID_MKITEM(6) | 0x10000000)
242#define DIDmib_p2_p2MAC \ 241#define DIDMIB_P2_MAC \
243 (P80211DID_MKSECTION(5) | \ 242 (P80211DID_MKSECTION(5) | \
244 P80211DID_MKGROUP(6)) 243 P80211DID_MKGROUP(6))
245#define DIDmib_p2_p2MAC_p2CurrentTxRate \ 244#define DIDMIB_P2_MAC_CURRENTTXRATE \
246 (P80211DID_MKSECTION(5) | \ 245 (P80211DID_MKSECTION(5) | \
247 P80211DID_MKGROUP(6) | \ 246 P80211DID_MKGROUP(6) | \
248 P80211DID_MKITEM(12) | 0x10000000) 247 P80211DID_MKITEM(12) | 0x10000000)
diff --git a/drivers/staging/wlan-ng/p80211metastruct.h b/drivers/staging/wlan-ng/p80211metastruct.h
index 5602ec606074..4adc64580185 100644
--- a/drivers/staging/wlan-ng/p80211metastruct.h
+++ b/drivers/staging/wlan-ng/p80211metastruct.h
@@ -1,6 +1,5 @@
1/* SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) */ 1/* SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) */
2/* This file is GENERATED AUTOMATICALLY. DO NOT EDIT OR MODIFY. 2/* --------------------------------------------------------------------
3 * --------------------------------------------------------------------
4 * 3 *
5 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved. 4 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
6 * -------------------------------------------------------------------- 5 * --------------------------------------------------------------------
diff --git a/drivers/staging/wlan-ng/p80211netdev.c b/drivers/staging/wlan-ng/p80211netdev.c
index 8258cb5a335d..a70fb84f38f1 100644
--- a/drivers/staging/wlan-ng/p80211netdev.c
+++ b/drivers/staging/wlan-ng/p80211netdev.c
@@ -638,25 +638,25 @@ static int p80211knetdev_set_mac_address(struct net_device *dev, void *addr)
638 638
639 /* Set up a dot11req_mibset */ 639 /* Set up a dot11req_mibset */
640 memset(&dot11req, 0, sizeof(dot11req)); 640 memset(&dot11req, 0, sizeof(dot11req));
641 dot11req.msgcode = DIDmsg_dot11req_mibset; 641 dot11req.msgcode = DIDMSG_DOT11REQ_MIBSET;
642 dot11req.msglen = sizeof(dot11req); 642 dot11req.msglen = sizeof(dot11req);
643 memcpy(dot11req.devname, 643 memcpy(dot11req.devname,
644 ((struct wlandevice *)dev->ml_priv)->name, 644 ((struct wlandevice *)dev->ml_priv)->name,
645 WLAN_DEVNAMELEN_MAX - 1); 645 WLAN_DEVNAMELEN_MAX - 1);
646 646
647 /* Set up the mibattribute argument */ 647 /* Set up the mibattribute argument */
648 mibattr->did = DIDmsg_dot11req_mibset_mibattribute; 648 mibattr->did = DIDMSG_DOT11REQ_MIBSET_MIBATTRIBUTE;
649 mibattr->status = P80211ENUM_msgitem_status_data_ok; 649 mibattr->status = P80211ENUM_msgitem_status_data_ok;
650 mibattr->len = sizeof(mibattr->data); 650 mibattr->len = sizeof(mibattr->data);
651 651
652 macaddr->did = DIDmib_dot11mac_dot11OperationTable_dot11MACAddress; 652 macaddr->did = DIDMIB_DOT11MAC_OPERATIONTABLE_MACADDRESS;
653 macaddr->status = P80211ENUM_msgitem_status_data_ok; 653 macaddr->status = P80211ENUM_msgitem_status_data_ok;
654 macaddr->len = sizeof(macaddr->data); 654 macaddr->len = sizeof(macaddr->data);
655 macaddr->data.len = ETH_ALEN; 655 macaddr->data.len = ETH_ALEN;
656 memcpy(&macaddr->data.data, new_addr->sa_data, ETH_ALEN); 656 memcpy(&macaddr->data.data, new_addr->sa_data, ETH_ALEN);
657 657
658 /* Set up the resultcode argument */ 658 /* Set up the resultcode argument */
659 resultcode->did = DIDmsg_dot11req_mibset_resultcode; 659 resultcode->did = DIDMSG_DOT11REQ_MIBSET_RESULTCODE;
660 resultcode->status = P80211ENUM_msgitem_status_no_value; 660 resultcode->status = P80211ENUM_msgitem_status_no_value;
661 resultcode->len = sizeof(resultcode->data); 661 resultcode->len = sizeof(resultcode->data);
662 resultcode->data = 0; 662 resultcode->data = 0;
@@ -927,10 +927,6 @@ static int p80211_rx_typedrop(struct wlandevice *wlandev, u16 fc)
927 /* Classify frame, increment counter */ 927 /* Classify frame, increment counter */
928 ftype = WLAN_GET_FC_FTYPE(fc); 928 ftype = WLAN_GET_FC_FTYPE(fc);
929 fstype = WLAN_GET_FC_FSTYPE(fc); 929 fstype = WLAN_GET_FC_FSTYPE(fc);
930#if 0
931 netdev_dbg(wlandev->netdev, "rx_typedrop : ftype=%d fstype=%d.\n",
932 ftype, fstype);
933#endif
934 switch (ftype) { 930 switch (ftype) {
935 case WLAN_FTYPE_MGMT: 931 case WLAN_FTYPE_MGMT:
936 if ((wlandev->netdev->flags & IFF_PROMISC) || 932 if ((wlandev->netdev->flags & IFF_PROMISC) ||
diff --git a/drivers/staging/wlan-ng/p80211req.c b/drivers/staging/wlan-ng/p80211req.c
index c36d01469afc..9f5c1267d829 100644
--- a/drivers/staging/wlan-ng/p80211req.c
+++ b/drivers/staging/wlan-ng/p80211req.c
@@ -117,7 +117,7 @@ int p80211req_dorequest(struct wlandevice *wlandev, u8 *msgbuf)
117 117
118 /* Check to make sure the MSD is running */ 118 /* Check to make sure the MSD is running */
119 if (!((wlandev->msdstate == WLAN_MSD_HWPRESENT && 119 if (!((wlandev->msdstate == WLAN_MSD_HWPRESENT &&
120 msg->msgcode == DIDmsg_lnxreq_ifstate) || 120 msg->msgcode == DIDMSG_LNXREQ_IFSTATE) ||
121 wlandev->msdstate == WLAN_MSD_RUNNING || 121 wlandev->msdstate == WLAN_MSD_RUNNING ||
122 wlandev->msdstate == WLAN_MSD_FWLOAD)) { 122 wlandev->msdstate == WLAN_MSD_FWLOAD)) {
123 return -ENODEV; 123 return -ENODEV;
@@ -125,7 +125,7 @@ int p80211req_dorequest(struct wlandevice *wlandev, u8 *msgbuf)
125 125
126 /* Check Permissions */ 126 /* Check Permissions */
127 if (!capable(CAP_NET_ADMIN) && 127 if (!capable(CAP_NET_ADMIN) &&
128 (msg->msgcode != DIDmsg_dot11req_mibget)) { 128 (msg->msgcode != DIDMSG_DOT11REQ_MIBGET)) {
129 netdev_err(wlandev->netdev, 129 netdev_err(wlandev->netdev,
130 "%s: only dot11req_mibget allowed for non-root.\n", 130 "%s: only dot11req_mibget allowed for non-root.\n",
131 wlandev->name); 131 wlandev->name);
@@ -172,7 +172,7 @@ static void p80211req_handlemsg(struct wlandevice *wlandev,
172 struct p80211msg *msg) 172 struct p80211msg *msg)
173{ 173{
174 switch (msg->msgcode) { 174 switch (msg->msgcode) {
175 case DIDmsg_lnxreq_hostwep:{ 175 case DIDMSG_LNXREQ_HOSTWEP: {
176 struct p80211msg_lnxreq_hostwep *req = 176 struct p80211msg_lnxreq_hostwep *req =
177 (struct p80211msg_lnxreq_hostwep *)msg; 177 (struct p80211msg_lnxreq_hostwep *)msg;
178 wlandev->hostwep &= 178 wlandev->hostwep &=
@@ -182,15 +182,15 @@ static void p80211req_handlemsg(struct wlandevice *wlandev,
182 if (req->encrypt.data == P80211ENUM_truth_true) 182 if (req->encrypt.data == P80211ENUM_truth_true)
183 wlandev->hostwep |= HOSTWEP_ENCRYPT; 183 wlandev->hostwep |= HOSTWEP_ENCRYPT;
184 184
185 break; 185 break;
186 } 186 }
187 case DIDmsg_dot11req_mibget: 187 case DIDMSG_DOT11REQ_MIBGET:
188 case DIDmsg_dot11req_mibset:{ 188 case DIDMSG_DOT11REQ_MIBSET: {
189 int isget = (msg->msgcode == DIDmsg_dot11req_mibget); 189 int isget = (msg->msgcode == DIDMSG_DOT11REQ_MIBGET);
190 struct p80211msg_dot11req_mibget *mib_msg = 190 struct p80211msg_dot11req_mibget *mib_msg =
191 (struct p80211msg_dot11req_mibget *)msg; 191 (struct p80211msg_dot11req_mibget *)msg;
192 p80211req_mibset_mibget(wlandev, mib_msg, isget); 192 p80211req_mibset_mibget(wlandev, mib_msg, isget);
193 break; 193 break;
194 } 194 }
195 } /* switch msg->msgcode */ 195 } /* switch msg->msgcode */
196} 196}
@@ -205,17 +205,17 @@ static void p80211req_mibset_mibget(struct wlandevice *wlandev,
205 u8 *key = mibitem->data + sizeof(struct p80211pstrd); 205 u8 *key = mibitem->data + sizeof(struct p80211pstrd);
206 206
207 switch (mibitem->did) { 207 switch (mibitem->did) {
208 case DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(1): 208 case didmib_dot11smt_wepdefaultkeystable_key(1):
209 case DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(2): 209 case didmib_dot11smt_wepdefaultkeystable_key(2):
210 case DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(3): 210 case didmib_dot11smt_wepdefaultkeystable_key(3):
211 case DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(4): 211 case didmib_dot11smt_wepdefaultkeystable_key(4):
212 if (!isget) 212 if (!isget)
213 wep_change_key(wlandev, 213 wep_change_key(wlandev,
214 P80211DID_ITEM(mibitem->did) - 1, 214 P80211DID_ITEM(mibitem->did) - 1,
215 key, pstr->len); 215 key, pstr->len);
216 break; 216 break;
217 217
218 case DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID:{ 218 case DIDMIB_DOT11SMT_PRIVACYTABLE_WEPDEFAULTKEYID: {
219 u32 *data = (u32 *)mibitem->data; 219 u32 *data = (u32 *)mibitem->data;
220 220
221 if (isget) { 221 if (isget) {
@@ -224,21 +224,21 @@ static void p80211req_mibset_mibget(struct wlandevice *wlandev,
224 wlandev->hostwep &= ~(HOSTWEP_DEFAULTKEY_MASK); 224 wlandev->hostwep &= ~(HOSTWEP_DEFAULTKEY_MASK);
225 wlandev->hostwep |= (*data & HOSTWEP_DEFAULTKEY_MASK); 225 wlandev->hostwep |= (*data & HOSTWEP_DEFAULTKEY_MASK);
226 } 226 }
227 break; 227 break;
228 } 228 }
229 case DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked:{ 229 case DIDMIB_DOT11SMT_PRIVACYTABLE_PRIVACYINVOKED: {
230 u32 *data = (u32 *)mibitem->data; 230 u32 *data = (u32 *)mibitem->data;
231 231
232 p80211req_handle_action(wlandev, data, isget, 232 p80211req_handle_action(wlandev, data, isget,
233 HOSTWEP_PRIVACYINVOKED); 233 HOSTWEP_PRIVACYINVOKED);
234 break; 234 break;
235 } 235 }
236 case DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted:{ 236 case DIDMIB_DOT11SMT_PRIVACYTABLE_EXCLUDEUNENCRYPTED: {
237 u32 *data = (u32 *)mibitem->data; 237 u32 *data = (u32 *)mibitem->data;
238 238
239 p80211req_handle_action(wlandev, data, isget, 239 p80211req_handle_action(wlandev, data, isget,
240 HOSTWEP_EXCLUDEUNENCRYPTED); 240 HOSTWEP_EXCLUDEUNENCRYPTED);
241 break; 241 break;
242 } 242 }
243 } 243 }
244} 244}
diff --git a/drivers/staging/wlan-ng/prism2fw.c b/drivers/staging/wlan-ng/prism2fw.c
index 4fb91294570d..f99626ca6bdc 100644
--- a/drivers/staging/wlan-ng/prism2fw.c
+++ b/drivers/staging/wlan-ng/prism2fw.c
@@ -294,17 +294,17 @@ static int prism2_fwapply(const struct ihex_binrec *rfptr,
294 294
295 /* read the card's PRI-SUP */ 295 /* read the card's PRI-SUP */
296 memset(&getmsg, 0, sizeof(getmsg)); 296 memset(&getmsg, 0, sizeof(getmsg));
297 getmsg.msgcode = DIDmsg_dot11req_mibget; 297 getmsg.msgcode = DIDMSG_DOT11REQ_MIBGET;
298 getmsg.msglen = sizeof(getmsg); 298 getmsg.msglen = sizeof(getmsg);
299 strcpy(getmsg.devname, wlandev->name); 299 strcpy(getmsg.devname, wlandev->name);
300 300
301 getmsg.mibattribute.did = DIDmsg_dot11req_mibget_mibattribute; 301 getmsg.mibattribute.did = DIDMSG_DOT11REQ_MIBGET_MIBATTRIBUTE;
302 getmsg.mibattribute.status = P80211ENUM_msgitem_status_data_ok; 302 getmsg.mibattribute.status = P80211ENUM_msgitem_status_data_ok;
303 getmsg.resultcode.did = DIDmsg_dot11req_mibget_resultcode; 303 getmsg.resultcode.did = DIDMSG_DOT11REQ_MIBGET_RESULTCODE;
304 getmsg.resultcode.status = P80211ENUM_msgitem_status_no_value; 304 getmsg.resultcode.status = P80211ENUM_msgitem_status_no_value;
305 305
306 item = (struct p80211itemd *)getmsg.mibattribute.data; 306 item = (struct p80211itemd *)getmsg.mibattribute.data;
307 item->did = DIDmib_p2_p2NIC_p2PRISupRange; 307 item->did = DIDMIB_P2_NIC_PRISUPRANGE;
308 item->status = P80211ENUM_msgitem_status_no_value; 308 item->status = P80211ENUM_msgitem_status_no_value;
309 309
310 data = (u32 *)item->data; 310 data = (u32 *)item->data;
@@ -706,7 +706,7 @@ static int plugimage(struct imgchunk *fchunk, unsigned int nfchunks,
706 pr_warn("warning: Failed to find PDR for plugrec 0x%04x.\n", 706 pr_warn("warning: Failed to find PDR for plugrec 0x%04x.\n",
707 s3plug[i].itemcode); 707 s3plug[i].itemcode);
708 continue; /* and move on to the next PDR */ 708 continue; /* and move on to the next PDR */
709#if 0 709
710 /* MSM: They swear that unless it's the MAC address, 710 /* MSM: They swear that unless it's the MAC address,
711 * the serial number, or the TX calibration records, 711 * the serial number, or the TX calibration records,
712 * then there's reasonable defaults in the f/w 712 * then there's reasonable defaults in the f/w
@@ -714,9 +714,6 @@ static int plugimage(struct imgchunk *fchunk, unsigned int nfchunks,
714 * should only be a warning, not fatal. 714 * should only be a warning, not fatal.
715 * TODO: add fatals for the PDRs mentioned above. 715 * TODO: add fatals for the PDRs mentioned above.
716 */ 716 */
717 result = 1;
718 continue;
719#endif
720 } 717 }
721 718
722 /* Validate plug len against PDR len */ 719 /* Validate plug len against PDR len */
@@ -790,13 +787,13 @@ static int read_cardpda(struct pda *pda, struct wlandevice *wlandev)
790 return -ENOMEM; 787 return -ENOMEM;
791 788
792 /* set up the msg */ 789 /* set up the msg */
793 msg->msgcode = DIDmsg_p2req_readpda; 790 msg->msgcode = DIDMSG_P2REQ_READPDA;
794 msg->msglen = sizeof(msg); 791 msg->msglen = sizeof(msg);
795 strcpy(msg->devname, wlandev->name); 792 strcpy(msg->devname, wlandev->name);
796 msg->pda.did = DIDmsg_p2req_readpda_pda; 793 msg->pda.did = DIDMSG_P2REQ_READPDA_PDA;
797 msg->pda.len = HFA384x_PDA_LEN_MAX; 794 msg->pda.len = HFA384x_PDA_LEN_MAX;
798 msg->pda.status = P80211ENUM_msgitem_status_no_value; 795 msg->pda.status = P80211ENUM_msgitem_status_no_value;
799 msg->resultcode.did = DIDmsg_p2req_readpda_resultcode; 796 msg->resultcode.did = DIDMSG_P2REQ_READPDA_RESULTCODE;
800 msg->resultcode.len = sizeof(u32); 797 msg->resultcode.len = sizeof(u32);
801 msg->resultcode.status = P80211ENUM_msgitem_status_no_value; 798 msg->resultcode.status = P80211ENUM_msgitem_status_no_value;
802 799
@@ -1024,11 +1021,11 @@ static int writeimage(struct wlandevice *wlandev, struct imgchunk *fchunk,
1024 1021
1025 /* Initialize the messages */ 1022 /* Initialize the messages */
1026 strcpy(rstmsg->devname, wlandev->name); 1023 strcpy(rstmsg->devname, wlandev->name);
1027 rstmsg->msgcode = DIDmsg_p2req_ramdl_state; 1024 rstmsg->msgcode = DIDMSG_P2REQ_RAMDL_STATE;
1028 rstmsg->msglen = sizeof(*rstmsg); 1025 rstmsg->msglen = sizeof(*rstmsg);
1029 rstmsg->enable.did = DIDmsg_p2req_ramdl_state_enable; 1026 rstmsg->enable.did = DIDMSG_P2REQ_RAMDL_STATE_ENABLE;
1030 rstmsg->exeaddr.did = DIDmsg_p2req_ramdl_state_exeaddr; 1027 rstmsg->exeaddr.did = DIDMSG_P2REQ_RAMDL_STATE_EXEADDR;
1031 rstmsg->resultcode.did = DIDmsg_p2req_ramdl_state_resultcode; 1028 rstmsg->resultcode.did = DIDMSG_P2REQ_RAMDL_STATE_RESULTCODE;
1032 rstmsg->enable.status = P80211ENUM_msgitem_status_data_ok; 1029 rstmsg->enable.status = P80211ENUM_msgitem_status_data_ok;
1033 rstmsg->exeaddr.status = P80211ENUM_msgitem_status_data_ok; 1030 rstmsg->exeaddr.status = P80211ENUM_msgitem_status_data_ok;
1034 rstmsg->resultcode.status = P80211ENUM_msgitem_status_no_value; 1031 rstmsg->resultcode.status = P80211ENUM_msgitem_status_no_value;
@@ -1037,12 +1034,12 @@ static int writeimage(struct wlandevice *wlandev, struct imgchunk *fchunk,
1037 rstmsg->resultcode.len = sizeof(u32); 1034 rstmsg->resultcode.len = sizeof(u32);
1038 1035
1039 strcpy(rwrmsg->devname, wlandev->name); 1036 strcpy(rwrmsg->devname, wlandev->name);
1040 rwrmsg->msgcode = DIDmsg_p2req_ramdl_write; 1037 rwrmsg->msgcode = DIDMSG_P2REQ_RAMDL_WRITE;
1041 rwrmsg->msglen = sizeof(*rwrmsg); 1038 rwrmsg->msglen = sizeof(*rwrmsg);
1042 rwrmsg->addr.did = DIDmsg_p2req_ramdl_write_addr; 1039 rwrmsg->addr.did = DIDMSG_P2REQ_RAMDL_WRITE_ADDR;
1043 rwrmsg->len.did = DIDmsg_p2req_ramdl_write_len; 1040 rwrmsg->len.did = DIDMSG_P2REQ_RAMDL_WRITE_LEN;
1044 rwrmsg->data.did = DIDmsg_p2req_ramdl_write_data; 1041 rwrmsg->data.did = DIDMSG_P2REQ_RAMDL_WRITE_DATA;
1045 rwrmsg->resultcode.did = DIDmsg_p2req_ramdl_write_resultcode; 1042 rwrmsg->resultcode.did = DIDMSG_P2REQ_RAMDL_WRITE_RESULTCODE;
1046 rwrmsg->addr.status = P80211ENUM_msgitem_status_data_ok; 1043 rwrmsg->addr.status = P80211ENUM_msgitem_status_data_ok;
1047 rwrmsg->len.status = P80211ENUM_msgitem_status_data_ok; 1044 rwrmsg->len.status = P80211ENUM_msgitem_status_data_ok;
1048 rwrmsg->data.status = P80211ENUM_msgitem_status_data_ok; 1045 rwrmsg->data.status = P80211ENUM_msgitem_status_data_ok;
diff --git a/drivers/staging/wlan-ng/prism2mib.c b/drivers/staging/wlan-ng/prism2mib.c
index e88baf715cec..5c0dad42f523 100644
--- a/drivers/staging/wlan-ng/prism2mib.c
+++ b/drivers/staging/wlan-ng/prism2mib.c
@@ -148,89 +148,89 @@ static int prism2mib_priv(struct mibrec *mib,
148 148
149static struct mibrec mibtab[] = { 149static struct mibrec mibtab[] = {
150 /* dot11smt MIB's */ 150 /* dot11smt MIB's */
151 {DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(1), 151 {didmib_dot11smt_wepdefaultkeystable_key(1),
152 F_STA | F_WRITE, 152 F_STA | F_WRITE,
153 HFA384x_RID_CNFWEPDEFAULTKEY0, 0, 0, 153 HFA384x_RID_CNFWEPDEFAULTKEY0, 0, 0,
154 prism2mib_wepdefaultkey}, 154 prism2mib_wepdefaultkey},
155 {DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(2), 155 {didmib_dot11smt_wepdefaultkeystable_key(2),
156 F_STA | F_WRITE, 156 F_STA | F_WRITE,
157 HFA384x_RID_CNFWEPDEFAULTKEY1, 0, 0, 157 HFA384x_RID_CNFWEPDEFAULTKEY1, 0, 0,
158 prism2mib_wepdefaultkey}, 158 prism2mib_wepdefaultkey},
159 {DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(3), 159 {didmib_dot11smt_wepdefaultkeystable_key(3),
160 F_STA | F_WRITE, 160 F_STA | F_WRITE,
161 HFA384x_RID_CNFWEPDEFAULTKEY2, 0, 0, 161 HFA384x_RID_CNFWEPDEFAULTKEY2, 0, 0,
162 prism2mib_wepdefaultkey}, 162 prism2mib_wepdefaultkey},
163 {DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(4), 163 {didmib_dot11smt_wepdefaultkeystable_key(4),
164 F_STA | F_WRITE, 164 F_STA | F_WRITE,
165 HFA384x_RID_CNFWEPDEFAULTKEY3, 0, 0, 165 HFA384x_RID_CNFWEPDEFAULTKEY3, 0, 0,
166 prism2mib_wepdefaultkey}, 166 prism2mib_wepdefaultkey},
167 {DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked, 167 {DIDMIB_DOT11SMT_PRIVACYTABLE_PRIVACYINVOKED,
168 F_STA | F_READ | F_WRITE, 168 F_STA | F_READ | F_WRITE,
169 HFA384x_RID_CNFWEPFLAGS, HFA384x_WEPFLAGS_PRIVINVOKED, 0, 169 HFA384x_RID_CNFWEPFLAGS, HFA384x_WEPFLAGS_PRIVINVOKED, 0,
170 prism2mib_privacyinvoked}, 170 prism2mib_privacyinvoked},
171 {DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID, 171 {DIDMIB_DOT11SMT_PRIVACYTABLE_WEPDEFAULTKEYID,
172 F_STA | F_READ | F_WRITE, 172 F_STA | F_READ | F_WRITE,
173 HFA384x_RID_CNFWEPDEFAULTKEYID, 0, 0, 173 HFA384x_RID_CNFWEPDEFAULTKEYID, 0, 0,
174 prism2mib_uint32}, 174 prism2mib_uint32},
175 {DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted, 175 {DIDMIB_DOT11SMT_PRIVACYTABLE_EXCLUDEUNENCRYPTED,
176 F_STA | F_READ | F_WRITE, 176 F_STA | F_READ | F_WRITE,
177 HFA384x_RID_CNFWEPFLAGS, HFA384x_WEPFLAGS_EXCLUDE, 0, 177 HFA384x_RID_CNFWEPFLAGS, HFA384x_WEPFLAGS_EXCLUDE, 0,
178 prism2mib_excludeunencrypted}, 178 prism2mib_excludeunencrypted},
179 179
180 /* dot11mac MIB's */ 180 /* dot11mac MIB's */
181 181
182 {DIDmib_dot11mac_dot11OperationTable_dot11MACAddress, 182 {DIDMIB_DOT11MAC_OPERATIONTABLE_MACADDRESS,
183 F_STA | F_READ | F_WRITE, 183 F_STA | F_READ | F_WRITE,
184 HFA384x_RID_CNFOWNMACADDR, HFA384x_RID_CNFOWNMACADDR_LEN, 0, 184 HFA384x_RID_CNFOWNMACADDR, HFA384x_RID_CNFOWNMACADDR_LEN, 0,
185 prism2mib_bytearea2pstr}, 185 prism2mib_bytearea2pstr},
186 {DIDmib_dot11mac_dot11OperationTable_dot11RTSThreshold, 186 {DIDMIB_DOT11MAC_OPERATIONTABLE_RTSTHRESHOLD,
187 F_STA | F_READ | F_WRITE, 187 F_STA | F_READ | F_WRITE,
188 HFA384x_RID_RTSTHRESH, 0, 0, 188 HFA384x_RID_RTSTHRESH, 0, 0,
189 prism2mib_uint32}, 189 prism2mib_uint32},
190 {DIDmib_dot11mac_dot11OperationTable_dot11ShortRetryLimit, 190 {DIDMIB_DOT11MAC_OPERATIONTABLE_SHORTRETRYLIMIT,
191 F_STA | F_READ, 191 F_STA | F_READ,
192 HFA384x_RID_SHORTRETRYLIMIT, 0, 0, 192 HFA384x_RID_SHORTRETRYLIMIT, 0, 0,
193 prism2mib_uint32}, 193 prism2mib_uint32},
194 {DIDmib_dot11mac_dot11OperationTable_dot11LongRetryLimit, 194 {DIDMIB_DOT11MAC_OPERATIONTABLE_LONGRETRYLIMIT,
195 F_STA | F_READ, 195 F_STA | F_READ,
196 HFA384x_RID_LONGRETRYLIMIT, 0, 0, 196 HFA384x_RID_LONGRETRYLIMIT, 0, 0,
197 prism2mib_uint32}, 197 prism2mib_uint32},
198 {DIDmib_dot11mac_dot11OperationTable_dot11FragmentationThreshold, 198 {DIDMIB_DOT11MAC_OPERATIONTABLE_FRAGMENTATIONTHRESHOLD,
199 F_STA | F_READ | F_WRITE, 199 F_STA | F_READ | F_WRITE,
200 HFA384x_RID_FRAGTHRESH, 0, 0, 200 HFA384x_RID_FRAGTHRESH, 0, 0,
201 prism2mib_fragmentationthreshold}, 201 prism2mib_fragmentationthreshold},
202 {DIDmib_dot11mac_dot11OperationTable_dot11MaxTransmitMSDULifetime, 202 {DIDMIB_DOT11MAC_OPERATIONTABLE_MAXTRANSMITMSDULIFETIME,
203 F_STA | F_READ, 203 F_STA | F_READ,
204 HFA384x_RID_MAXTXLIFETIME, 0, 0, 204 HFA384x_RID_MAXTXLIFETIME, 0, 0,
205 prism2mib_uint32}, 205 prism2mib_uint32},
206 206
207 /* dot11phy MIB's */ 207 /* dot11phy MIB's */
208 208
209 {DIDmib_dot11phy_dot11PhyDSSSTable_dot11CurrentChannel, 209 {DIDMIB_DOT11PHY_DSSSTABLE_CURRENTCHANNEL,
210 F_STA | F_READ, 210 F_STA | F_READ,
211 HFA384x_RID_CURRENTCHANNEL, 0, 0, 211 HFA384x_RID_CURRENTCHANNEL, 0, 0,
212 prism2mib_uint32}, 212 prism2mib_uint32},
213 {DIDmib_dot11phy_dot11PhyTxPowerTable_dot11CurrentTxPowerLevel, 213 {DIDMIB_DOT11PHY_TXPOWERTABLE_CURRENTTXPOWERLEVEL,
214 F_STA | F_READ | F_WRITE, 214 F_STA | F_READ | F_WRITE,
215 HFA384x_RID_TXPOWERMAX, 0, 0, 215 HFA384x_RID_TXPOWERMAX, 0, 0,
216 prism2mib_uint32}, 216 prism2mib_uint32},
217 217
218 /* p2Static MIB's */ 218 /* p2Static MIB's */
219 219
220 {DIDmib_p2_p2Static_p2CnfPortType, 220 {DIDMIB_P2_STATIC_CNFPORTTYPE,
221 F_STA | F_READ | F_WRITE, 221 F_STA | F_READ | F_WRITE,
222 HFA384x_RID_CNFPORTTYPE, 0, 0, 222 HFA384x_RID_CNFPORTTYPE, 0, 0,
223 prism2mib_uint32}, 223 prism2mib_uint32},
224 224
225 /* p2MAC MIB's */ 225 /* p2MAC MIB's */
226 226
227 {DIDmib_p2_p2MAC_p2CurrentTxRate, 227 {DIDMIB_P2_MAC_CURRENTTXRATE,
228 F_STA | F_READ, 228 F_STA | F_READ,
229 HFA384x_RID_CURRENTTXRATE, 0, 0, 229 HFA384x_RID_CURRENTTXRATE, 0, 0,
230 prism2mib_uint32}, 230 prism2mib_uint32},
231 231
232 /* And finally, lnx mibs */ 232 /* And finally, lnx mibs */
233 {DIDmib_lnx_lnxConfigTable_lnxRSNAIE, 233 {DIDMIB_LNX_CONFIGTABLE_RSNAIE,
234 F_STA | F_READ | F_WRITE, 234 F_STA | F_READ | F_WRITE,
235 HFA384x_RID_CNFWPADATA, 0, 0, 235 HFA384x_RID_CNFWPADATA, 0, 0,
236 prism2mib_priv}, 236 prism2mib_priv},
@@ -301,7 +301,7 @@ int prism2mgmt_mibset_mibget(struct wlandevice *wlandev, void *msgp)
301 ** this is a "mibset" so make make sure that the MIB may be written. 301 ** this is a "mibset" so make make sure that the MIB may be written.
302 */ 302 */
303 303
304 isget = (msg->msgcode == DIDmsg_dot11req_mibget); 304 isget = (msg->msgcode == DIDMSG_DOT11REQ_MIBGET);
305 305
306 if (isget) { 306 if (isget) {
307 if (!(mib->flag & F_READ)) { 307 if (!(mib->flag & F_READ)) {
@@ -707,27 +707,27 @@ static int prism2mib_priv(struct mibrec *mib,
707 struct p80211pstrd *pstr = data; 707 struct p80211pstrd *pstr = data;
708 708
709 switch (mib->did) { 709 switch (mib->did) {
710 case DIDmib_lnx_lnxConfigTable_lnxRSNAIE:{ 710 case DIDMIB_LNX_CONFIGTABLE_RSNAIE: {
711 struct hfa384x_wpa_data wpa; 711 struct hfa384x_wpa_data wpa;
712 712
713 if (isget) { 713 if (isget) {
714 hfa384x_drvr_getconfig(hw, 714 hfa384x_drvr_getconfig(hw,
715 HFA384x_RID_CNFWPADATA, 715 HFA384x_RID_CNFWPADATA,
716 (u8 *)&wpa, 716 (u8 *)&wpa,
717 sizeof(wpa)); 717 sizeof(wpa));
718 pstr->len = le16_to_cpu(wpa.datalen); 718 pstr->len = le16_to_cpu(wpa.datalen);
719 memcpy(pstr->data, wpa.data, pstr->len); 719 memcpy(pstr->data, wpa.data, pstr->len);
720 } else { 720 } else {
721 wpa.datalen = cpu_to_le16(pstr->len); 721 wpa.datalen = cpu_to_le16(pstr->len);
722 memcpy(wpa.data, pstr->data, pstr->len); 722 memcpy(wpa.data, pstr->data, pstr->len);
723 723
724 hfa384x_drvr_setconfig(hw, 724 hfa384x_drvr_setconfig(hw,
725 HFA384x_RID_CNFWPADATA, 725 HFA384x_RID_CNFWPADATA,
726 (u8 *)&wpa, 726 (u8 *)&wpa,
727 sizeof(wpa)); 727 sizeof(wpa));
728 }
729 break;
730 } 728 }
729 break;
730 }
731 default: 731 default:
732 netdev_err(wlandev->netdev, "Unhandled DID 0x%08x\n", mib->did); 732 netdev_err(wlandev->netdev, "Unhandled DID 0x%08x\n", mib->did);
733 } 733 }
diff --git a/drivers/staging/wlan-ng/prism2sta.c b/drivers/staging/wlan-ng/prism2sta.c
index 914970249680..fb5441399131 100644
--- a/drivers/staging/wlan-ng/prism2sta.c
+++ b/drivers/staging/wlan-ng/prism2sta.c
@@ -288,99 +288,93 @@ static int prism2sta_mlmerequest(struct wlandevice *wlandev,
288 int result = 0; 288 int result = 0;
289 289
290 switch (msg->msgcode) { 290 switch (msg->msgcode) {
291 case DIDmsg_dot11req_mibget: 291 case DIDMSG_DOT11REQ_MIBGET:
292 pr_debug("Received mibget request\n"); 292 pr_debug("Received mibget request\n");
293 result = prism2mgmt_mibset_mibget(wlandev, msg); 293 result = prism2mgmt_mibset_mibget(wlandev, msg);
294 break; 294 break;
295 case DIDmsg_dot11req_mibset: 295 case DIDMSG_DOT11REQ_MIBSET:
296 pr_debug("Received mibset request\n"); 296 pr_debug("Received mibset request\n");
297 result = prism2mgmt_mibset_mibget(wlandev, msg); 297 result = prism2mgmt_mibset_mibget(wlandev, msg);
298 break; 298 break;
299 case DIDmsg_dot11req_scan: 299 case DIDMSG_DOT11REQ_SCAN:
300 pr_debug("Received scan request\n"); 300 pr_debug("Received scan request\n");
301 result = prism2mgmt_scan(wlandev, msg); 301 result = prism2mgmt_scan(wlandev, msg);
302 break; 302 break;
303 case DIDmsg_dot11req_scan_results: 303 case DIDMSG_DOT11REQ_SCAN_RESULTS:
304 pr_debug("Received scan_results request\n"); 304 pr_debug("Received scan_results request\n");
305 result = prism2mgmt_scan_results(wlandev, msg); 305 result = prism2mgmt_scan_results(wlandev, msg);
306 break; 306 break;
307 case DIDmsg_dot11req_start: 307 case DIDMSG_DOT11REQ_START:
308 pr_debug("Received mlme start request\n"); 308 pr_debug("Received mlme start request\n");
309 result = prism2mgmt_start(wlandev, msg); 309 result = prism2mgmt_start(wlandev, msg);
310 break; 310 break;
311 /* 311 /*
312 * Prism2 specific messages 312 * Prism2 specific messages
313 */ 313 */
314 case DIDmsg_p2req_readpda: 314 case DIDMSG_P2REQ_READPDA:
315 pr_debug("Received mlme readpda request\n"); 315 pr_debug("Received mlme readpda request\n");
316 result = prism2mgmt_readpda(wlandev, msg); 316 result = prism2mgmt_readpda(wlandev, msg);
317 break; 317 break;
318 case DIDmsg_p2req_ramdl_state: 318 case DIDMSG_P2REQ_RAMDL_STATE:
319 pr_debug("Received mlme ramdl_state request\n"); 319 pr_debug("Received mlme ramdl_state request\n");
320 result = prism2mgmt_ramdl_state(wlandev, msg); 320 result = prism2mgmt_ramdl_state(wlandev, msg);
321 break; 321 break;
322 case DIDmsg_p2req_ramdl_write: 322 case DIDMSG_P2REQ_RAMDL_WRITE:
323 pr_debug("Received mlme ramdl_write request\n"); 323 pr_debug("Received mlme ramdl_write request\n");
324 result = prism2mgmt_ramdl_write(wlandev, msg); 324 result = prism2mgmt_ramdl_write(wlandev, msg);
325 break; 325 break;
326 case DIDmsg_p2req_flashdl_state: 326 case DIDMSG_P2REQ_FLASHDL_STATE:
327 pr_debug("Received mlme flashdl_state request\n"); 327 pr_debug("Received mlme flashdl_state request\n");
328 result = prism2mgmt_flashdl_state(wlandev, msg); 328 result = prism2mgmt_flashdl_state(wlandev, msg);
329 break; 329 break;
330 case DIDmsg_p2req_flashdl_write: 330 case DIDMSG_P2REQ_FLASHDL_WRITE:
331 pr_debug("Received mlme flashdl_write request\n"); 331 pr_debug("Received mlme flashdl_write request\n");
332 result = prism2mgmt_flashdl_write(wlandev, msg); 332 result = prism2mgmt_flashdl_write(wlandev, msg);
333 break; 333 break;
334 /* 334 /*
335 * Linux specific messages 335 * Linux specific messages
336 */ 336 */
337 case DIDmsg_lnxreq_hostwep: 337 case DIDMSG_LNXREQ_HOSTWEP:
338 break; /* ignore me. */ 338 break; /* ignore me. */
339 case DIDmsg_lnxreq_ifstate: 339 case DIDMSG_LNXREQ_IFSTATE: {
340 { 340 struct p80211msg_lnxreq_ifstate *ifstatemsg;
341 struct p80211msg_lnxreq_ifstate *ifstatemsg; 341
342 342 pr_debug("Received mlme ifstate request\n");
343 pr_debug("Received mlme ifstate request\n"); 343 ifstatemsg = (struct p80211msg_lnxreq_ifstate *)msg;
344 ifstatemsg = (struct p80211msg_lnxreq_ifstate *)msg; 344 result = prism2sta_ifstate(wlandev,
345 result = 345 ifstatemsg->ifstate.data);
346 prism2sta_ifstate(wlandev, 346 ifstatemsg->resultcode.status =
347 ifstatemsg->ifstate.data); 347 P80211ENUM_msgitem_status_data_ok;
348 ifstatemsg->resultcode.status = 348 ifstatemsg->resultcode.data = result;
349 P80211ENUM_msgitem_status_data_ok; 349 result = 0;
350 ifstatemsg->resultcode.data = result;
351 result = 0;
352 }
353 break; 350 break;
354 case DIDmsg_lnxreq_wlansniff: 351 }
352 case DIDMSG_LNXREQ_WLANSNIFF:
355 pr_debug("Received mlme wlansniff request\n"); 353 pr_debug("Received mlme wlansniff request\n");
356 result = prism2mgmt_wlansniff(wlandev, msg); 354 result = prism2mgmt_wlansniff(wlandev, msg);
357 break; 355 break;
358 case DIDmsg_lnxreq_autojoin: 356 case DIDMSG_LNXREQ_AUTOJOIN:
359 pr_debug("Received mlme autojoin request\n"); 357 pr_debug("Received mlme autojoin request\n");
360 result = prism2mgmt_autojoin(wlandev, msg); 358 result = prism2mgmt_autojoin(wlandev, msg);
361 break; 359 break;
362 case DIDmsg_lnxreq_commsquality:{ 360 case DIDMSG_LNXREQ_COMMSQUALITY: {
363 struct p80211msg_lnxreq_commsquality *qualmsg; 361 struct p80211msg_lnxreq_commsquality *qualmsg;
364 362
365 pr_debug("Received commsquality request\n"); 363 pr_debug("Received commsquality request\n");
366 364
367 qualmsg = (struct p80211msg_lnxreq_commsquality *)msg; 365 qualmsg = (struct p80211msg_lnxreq_commsquality *)msg;
368 366
369 qualmsg->link.status = 367 qualmsg->link.status = P80211ENUM_msgitem_status_data_ok;
370 P80211ENUM_msgitem_status_data_ok; 368 qualmsg->level.status = P80211ENUM_msgitem_status_data_ok;
371 qualmsg->level.status = 369 qualmsg->noise.status = P80211ENUM_msgitem_status_data_ok;
372 P80211ENUM_msgitem_status_data_ok;
373 qualmsg->noise.status =
374 P80211ENUM_msgitem_status_data_ok;
375 370
376 qualmsg->link.data = le16_to_cpu(hw->qual.cq_curr_bss); 371 qualmsg->link.data = le16_to_cpu(hw->qual.cq_curr_bss);
377 qualmsg->level.data = 372 qualmsg->level.data = le16_to_cpu(hw->qual.asl_curr_bss);
378 le16_to_cpu(hw->qual.asl_curr_bss); 373 qualmsg->noise.data = le16_to_cpu(hw->qual.anl_curr_fc);
379 qualmsg->noise.data = le16_to_cpu(hw->qual.anl_curr_fc); 374 qualmsg->txrate.data = hw->txrate;
380 qualmsg->txrate.data = hw->txrate;
381 375
382 break; 376 break;
383 } 377 }
384 default: 378 default:
385 netdev_warn(wlandev->netdev, 379 netdev_warn(wlandev->netdev,
386 "Unknown mgmt request message 0x%08x", 380 "Unknown mgmt request message 0x%08x",
@@ -1949,8 +1943,8 @@ void prism2sta_commsqual_defer(struct work_struct *data)
1949 } 1943 }
1950 1944
1951 /* Get the signal rate */ 1945 /* Get the signal rate */
1952 msg.msgcode = DIDmsg_dot11req_mibget; 1946 msg.msgcode = DIDMSG_DOT11REQ_MIBGET;
1953 mibitem->did = DIDmib_p2_p2MAC_p2CurrentTxRate; 1947 mibitem->did = DIDMIB_P2_MAC_CURRENTTXRATE;
1954 result = p80211req_dorequest(wlandev, (u8 *)&msg); 1948 result = p80211req_dorequest(wlandev, (u8 *)&msg);
1955 1949
1956 if (result) { 1950 if (result) {
diff --git a/include/dt-bindings/iio/qcom,spmi-vadc.h b/include/dt-bindings/iio/qcom,spmi-vadc.h
index 42121fa238fa..61d556db1542 100644
--- a/include/dt-bindings/iio/qcom,spmi-vadc.h
+++ b/include/dt-bindings/iio/qcom,spmi-vadc.h
@@ -1,14 +1,6 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Copyright (c) 2012-2014, The Linux Foundation. All rights reserved. 3 * Copyright (c) 2012-2014,2018 The Linux Foundation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */ 4 */
13 5
14#ifndef _DT_BINDINGS_QCOM_SPMI_VADC_H 6#ifndef _DT_BINDINGS_QCOM_SPMI_VADC_H
@@ -116,4 +108,117 @@
116#define VADC_LR_MUX10_PU1_PU2_AMUX_USB_ID 0xf9 108#define VADC_LR_MUX10_PU1_PU2_AMUX_USB_ID 0xf9
117#define VADC_LR_MUX3_BUF_PU1_PU2_XO_THERM 0xfc 109#define VADC_LR_MUX3_BUF_PU1_PU2_XO_THERM 0xfc
118 110
111/* ADC channels for SPMI PMIC5 */
112
113#define ADC5_REF_GND 0x00
114#define ADC5_1P25VREF 0x01
115#define ADC5_VREF_VADC 0x02
116#define ADC5_VREF_VADC5_DIV_3 0x82
117#define ADC5_VPH_PWR 0x83
118#define ADC5_VBAT_SNS 0x84
119#define ADC5_VCOIN 0x85
120#define ADC5_DIE_TEMP 0x06
121#define ADC5_USB_IN_I 0x07
122#define ADC5_USB_IN_V_16 0x08
123#define ADC5_CHG_TEMP 0x09
124#define ADC5_BAT_THERM 0x0a
125#define ADC5_BAT_ID 0x0b
126#define ADC5_XO_THERM 0x0c
127#define ADC5_AMUX_THM1 0x0d
128#define ADC5_AMUX_THM2 0x0e
129#define ADC5_AMUX_THM3 0x0f
130#define ADC5_AMUX_THM4 0x10
131#define ADC5_AMUX_THM5 0x11
132#define ADC5_GPIO1 0x12
133#define ADC5_GPIO2 0x13
134#define ADC5_GPIO3 0x14
135#define ADC5_GPIO4 0x15
136#define ADC5_GPIO5 0x16
137#define ADC5_GPIO6 0x17
138#define ADC5_GPIO7 0x18
139#define ADC5_SBUx 0x99
140#define ADC5_MID_CHG_DIV6 0x1e
141#define ADC5_OFF 0xff
142
143/* 30k pull-up1 */
144#define ADC5_BAT_THERM_30K_PU 0x2a
145#define ADC5_BAT_ID_30K_PU 0x2b
146#define ADC5_XO_THERM_30K_PU 0x2c
147#define ADC5_AMUX_THM1_30K_PU 0x2d
148#define ADC5_AMUX_THM2_30K_PU 0x2e
149#define ADC5_AMUX_THM3_30K_PU 0x2f
150#define ADC5_AMUX_THM4_30K_PU 0x30
151#define ADC5_AMUX_THM5_30K_PU 0x31
152#define ADC5_GPIO1_30K_PU 0x32
153#define ADC5_GPIO2_30K_PU 0x33
154#define ADC5_GPIO3_30K_PU 0x34
155#define ADC5_GPIO4_30K_PU 0x35
156#define ADC5_GPIO5_30K_PU 0x36
157#define ADC5_GPIO6_30K_PU 0x37
158#define ADC5_GPIO7_30K_PU 0x38
159#define ADC5_SBUx_30K_PU 0x39
160
161/* 100k pull-up2 */
162#define ADC5_BAT_THERM_100K_PU 0x4a
163#define ADC5_BAT_ID_100K_PU 0x4b
164#define ADC5_XO_THERM_100K_PU 0x4c
165#define ADC5_AMUX_THM1_100K_PU 0x4d
166#define ADC5_AMUX_THM2_100K_PU 0x4e
167#define ADC5_AMUX_THM3_100K_PU 0x4f
168#define ADC5_AMUX_THM4_100K_PU 0x50
169#define ADC5_AMUX_THM5_100K_PU 0x51
170#define ADC5_GPIO1_100K_PU 0x52
171#define ADC5_GPIO2_100K_PU 0x53
172#define ADC5_GPIO3_100K_PU 0x54
173#define ADC5_GPIO4_100K_PU 0x55
174#define ADC5_GPIO5_100K_PU 0x56
175#define ADC5_GPIO6_100K_PU 0x57
176#define ADC5_GPIO7_100K_PU 0x58
177#define ADC5_SBUx_100K_PU 0x59
178
179/* 400k pull-up3 */
180#define ADC5_BAT_THERM_400K_PU 0x6a
181#define ADC5_BAT_ID_400K_PU 0x6b
182#define ADC5_XO_THERM_400K_PU 0x6c
183#define ADC5_AMUX_THM1_400K_PU 0x6d
184#define ADC5_AMUX_THM2_400K_PU 0x6e
185#define ADC5_AMUX_THM3_400K_PU 0x6f
186#define ADC5_AMUX_THM4_400K_PU 0x70
187#define ADC5_AMUX_THM5_400K_PU 0x71
188#define ADC5_GPIO1_400K_PU 0x72
189#define ADC5_GPIO2_400K_PU 0x73
190#define ADC5_GPIO3_400K_PU 0x74
191#define ADC5_GPIO4_400K_PU 0x75
192#define ADC5_GPIO5_400K_PU 0x76
193#define ADC5_GPIO6_400K_PU 0x77
194#define ADC5_GPIO7_400K_PU 0x78
195#define ADC5_SBUx_400K_PU 0x79
196
197/* 1/3 Divider */
198#define ADC5_GPIO1_DIV3 0x92
199#define ADC5_GPIO2_DIV3 0x93
200#define ADC5_GPIO3_DIV3 0x94
201#define ADC5_GPIO4_DIV3 0x95
202#define ADC5_GPIO5_DIV3 0x96
203#define ADC5_GPIO6_DIV3 0x97
204#define ADC5_GPIO7_DIV3 0x98
205#define ADC5_SBUx_DIV3 0x99
206
207/* Current and combined current/voltage channels */
208#define ADC5_INT_EXT_ISENSE 0xa1
209#define ADC5_PARALLEL_ISENSE 0xa5
210#define ADC5_CUR_REPLICA_VDS 0xa7
211#define ADC5_CUR_SENS_BATFET_VDS_OFFSET 0xa9
212#define ADC5_CUR_SENS_REPLICA_VDS_OFFSET 0xab
213#define ADC5_EXT_SENS_OFFSET 0xad
214
215#define ADC5_INT_EXT_ISENSE_VBAT_VDATA 0xb0
216#define ADC5_INT_EXT_ISENSE_VBAT_IDATA 0xb1
217#define ADC5_EXT_ISENSE_VBAT_VDATA 0xb2
218#define ADC5_EXT_ISENSE_VBAT_IDATA 0xb3
219#define ADC5_PARALLEL_ISENSE_VBAT_VDATA 0xb4
220#define ADC5_PARALLEL_ISENSE_VBAT_IDATA 0xb5
221
222#define ADC5_MAX_CHANNEL 0xc0
223
119#endif /* _DT_BINDINGS_QCOM_SPMI_VADC_H */ 224#endif /* _DT_BINDINGS_QCOM_SPMI_VADC_H */